How can I attach a debugger to a running Perl process?

前端 未结 3 949
萌比男神i
萌比男神i 2021-02-06 22:53

I have a running Perl process that’s stuck, I’d like to poke inside with a debugger to see what’s wrong. I can’t restart the process. Can I attach the debugger to the running pr

相关标签:
3条回答
  • 2021-02-06 23:39

    First, please use a DEBUGGING perl, if you want to inspect it with gdb.

    Please define "stuck". Busy or non-busy waiting (high or low CPU), eating memory or not? With while 1 it is busy waiting. I usually get busy waiting (endless cycles) on HV corruption in Perl_hfree_next_entry() since 5.15. Non-busy waiting is usually waiting on a blocking IO read.

    I get the correct:

    `0x00007fba15ab35c1 in Perl_runops_debug () at dump.c:2266`
    `2266       } while ((PL_op = PL_op->op_ppaddr(aTHX)));`
    

    and can inspect everything, much more than with a simple perl debugger. With a non-threaded perl you have to type less.

    `(gdb) p Perl_op_dump(PL_op)`
    

    and so on.

    If you have to do with perl: Inside the pp_stub function it is not a good idea to enter the Enbugger runloop, you should be in the main runloop in dump.c. Set a breakpoint to the shown line.

    "error for object 0x3" on eval sound like internal corruption in the context, so you should look at the cx and stack pointers. Probably because you started it in a bad context.

    0 讨论(0)
  • 2021-02-06 23:39

    I've never used gdb, but maybe you could get something useful out of strace?

    strace -f -s512 -p <PID>
    
    0 讨论(0)
  • 2021-02-06 23:47

    http://metacpan.org/pod/App::Stacktrace “perl-stacktrace prints Perl stack traces of Perl threads for a given Perl process. For each Perl frame, the full file name and line number are printed.”

    0 讨论(0)
提交回复
热议问题