暂停进程以让调试器有时间附加 [英] Pause process to allow time for debugger to attach

查看:14
本文介绍了暂停进程以让调试器有时间附加的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将 gdb 附加到我无法轻松控制进程启动的进程,因为它是从 inetd 运行的,并且该进程完成得太快,一旦启动就无法附加到它.

I'd like to attach gdb to a process where I can't easily control the startup of the process because it is run from inetd and where the process completes too fast to be able to attach to it once it starts.

我想做的是在我想要开始调试的特定点插入一些代码.理想情况下,该代码将等待调试器附加,然后继续.我已经尝试过睡眠,但是很难选择足够长的延迟,以便我有时间抓住它,但又要足够短,以免在附加 gdb 后等待它过去.

What I'd like to do is insert a bit of code at the particular point that I want to start debugging. That code would ideally wait for the debugger to attach and then continue. I've tried with a sleep but it is then tricky to choose a delay long enough that I have time to catch it but short enough not to be a nuisance waiting for it to elapse after gdb is attached.

是否有更好的选择来插入或调用用于此目的的代码?

Is there any better choices of code to insert or to call for this purpose?

推荐答案

我想做的是在我想开始调试的特定点插入一些代码.

What I'd like to do is insert a bit of code at the particular point that I want to start debugging.

我通常这样做:

volatile int done = 0;
while (!done) sleep(1);

附加 GDB(您将进入 sleep).执行 finish,然后 set var done = 1,然后享受剩下的调试会话 ;-)

Attach GDB (you'll be inside sleep). Do finish, then set var done = 1, and enjoy the rest of your debugging session ;-)

这篇关于暂停进程以让调试器有时间附加的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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