如何将调试器附加到正在运行的 Perl 进程? [英] How can I attach a debugger to a running Perl process?

查看:15
本文介绍了如何将调试器附加到正在运行的 Perl 进程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个正在运行的 Perl 进程卡住了,我想用调试器戳进去看看有什么问题.我无法重新启动该过程.我可以将调试器附加到正在运行的进程吗?我知道我可以执行 gdb -p,但 gdb 对我没有帮助.我试过 Enbugger,但失败了:

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 process? I know I can do gdb -p, but gdb does not help me. I’ve tried Enbugger, but failed:

$ 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?

附:如果您认为自己可以从附加到正在运行的进程的调试器中受益,则可以插入由 SIGUSR1 触发的调试器后门:

P.S. 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:

use Enbugger::OnError 'USR1';

然后您可以简单地kill -USR1 pid,您的进程将跳转到调试器.

Then you can simply kill -USR1 pid and your process will jump into the debugger.

推荐答案

首先,如果你想用 gdb 检查它,请使用 DEBUGGING perl.

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

请定义卡住".忙或不忙等待(高或低CPU),吃内存与否?使用 while 1 它正忙于等待.自 5.15 以来,我通常忙于等待 Perl_hfree_next_entry() 中的 HV 损坏(无休止的循环).非忙等待通常是等待阻塞的 IO 读取.

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.

我猜对了:

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

并且可以检查所有内容,这比使用简单的 perl 调试器要多得多.使用非线程 perl,您必须输入更少的内容.

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)`

等等.

如果你必须使用 perl:在 pp_stub 函数内部进入 Enbugger 运行循环不是一个好主意,你应该在 dump.c 的主运行循环中.为显示的行设置断点.

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 听起来像是上下文中的内部损坏,因此您应该查看 cx 和堆栈指针.可能是因为你是在糟糕的环境中开始的.

"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.

这篇关于如何将调试器附加到正在运行的 Perl 进程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆