简体   繁体   English

如何将调试器附加到正在运行的 Perl 进程?

[英]How can I attach a debugger to a running Perl process?

I have a running Perl process that's stuck, I'd like to poke inside with a debugger to see what's wrong.我有一个正在运行的 Perl 进程卡住了,我想用调试器戳进去看看有什么问题。 I can't restart the process.我无法重新启动该过程。 Can I attach the debugger to the running process?我可以将调试器附加到正在运行的进程吗? I know I can do gdb -p , but gdb does not help me.我知道我可以做gdb -p ,但是gdb对我没有帮助。 I've tried Enbugger , but failed:我试过Enbugger ,但失败了:

$ perl -e 'while (1) {}'&
[1] 86836
$ gdb -p 86836
…
Attaching to process 86836.
Reading symbols for shared libraries . done
Reading symbols for shared libraries ............................. done
Reading symbols for shared libraries + done
0x000000010c1694c6 in Perl_pp_stub ()
(gdb) call (void*)Perl_eval_pv("require Enbugger;Enbugger->stop;",0)
perl(86836) malloc: *** error for object 0x3: pointer being realloc'd was not allocated
*** set a breakpoint in malloc_error_break to debug

Program received signal SIGABRT, Aborted.
0x00007fff8269d82a in __kill ()
The program being debugged was signaled while in a function called from GDB.
GDB remains in the frame where the signal was received.
To change this behavior use "set unwindonsignal on"
Evaluation of the expression containing the function (Perl_eval_pv) will be abandoned.
(gdb) 

Am I doing it wrong?我做错了吗? Are there other options?还有其他选择吗?


PS If you think you could benefit from a debugger attached to a running process yourself, you can insert a debugger back door triggered by SIGUSR1: PS 如果您认为自己可以从附加到正在运行的进程的调试器中受益,您可以插入由 SIGUSR1 触发的调试器后门:

use Enbugger::OnError 'USR1';

Then you can simply kill -USR1 pid and your process will jump into the debugger.然后您可以简单地kill -USR1 pid ,您的进程将跳转到调试器。

First, please use a DEBUGGING perl, if you want to inspect it with gdb. 首先,如果你想用gdb检查它,请使用DEBUGGING perl。

Please define "stuck". 请定义“卡住”。 Busy or non-busy waiting (high or low CPU), eating memory or not? 忙碌或非忙碌等待(CPU高或低),是否吃东西? With while 1 it is busy waiting. 在1时它正忙着等待。 I usually get busy waiting (endless cycles) on HV corruption in Perl_hfree_next_entry() since 5.15. 从5.15开始,我经常在Perl_hfree_next_entry()中的HV损坏等待(无休止的循环)。 Non-busy waiting is usually waiting on a blocking IO read. 非忙等待通常等待阻塞IO读取。

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. 并且可以检查所有内容,而不仅仅是使用简单的perl调试器。 With a non-threaded perl you have to type less. 使用非线程perl,您必须输入更少。

`(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. 如果你必须使用perl:在pp_stub函数中输入Enbugger runloop不是一个好主意,你应该在dump.c中的主runloop中。 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. eval声音中的“对象0x3的错误”就像上下文中的内部损坏一样,所以你应该看一下cx和堆栈指针。 Probably because you started it in a bad context. 可能是因为你在糟糕的环境中开始了它。

http://metacpan.org/pod/App::Stacktrace “perl-stacktrace prints Perl stack traces of Perl threads for a given Perl process. http://metacpan.org/pod/App::Stacktrace“perl-stacktrace为给定的Perl进程打印Perl线程的Perl堆栈跟踪。 For each Perl frame, the full file name and line number are printed.” 对于每个Perl帧,将打印完整的文件名和行号。“

我从来没有使用过gdb,但也许你可以从strace中得到一些有用的东西?

strace -f -s512 -p <PID>

The documentation for Enbugger contains specific instructions for doing this from gdb: Enbugger 的文档包含来自 gdb 的具体说明:

https://metacpan.org/dist/Enbugger/view/lib/Enbugger.pod#From-gdb https://metacpan.org/dist/Enbugger/view/lib/Enbugger.pod#From-gdb

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM