为什么gdb会挂起? [英] Why would gdb hang?

查看:113
本文介绍了为什么gdb会挂起?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个正在调试的应用程序,试图了解gdb的工作原理以及为什么有时无法逐步浏览该应用程序.我遇到的问题是,当我单步执行程序时,gdb会挂起,并且附加到该进程的进程将进入无效状态. gdb挂起后,我必须杀死它以释放终端(ctrl-C不起作用,我必须从其他终端窗口中执行此操作,方法是获取该gdb会话的进程ID并使用kill -9).

I have an application that I am debugging and I'm trying to understand how gdb works and why I am not able to step through the application sometimes. The problem that I am experiencing is that gdb will hang and the process it is attached to will enter a defunct state when I am stepping through the program. After gdb hangs and I have to kill it to free the terminal (ctrl-C does not work, I have to do this from a different terminal window by getting the process id for that gdb session and using kill -9).

我猜测gdb正在挂起,因为它正在等待应用程序在下一条指令处停止,并且应用程序以某种方式完成了执行,而gdb并未识别出这条指令.但这只是我到目前为止所观察到的行为的推测.因此,我的问题是,是否有人以前曾见过这种类型的行为和/或可以提出原因?我认为这可能会帮助我改善调试策略.

I'm guessing that gdb is hanging because it's waiting for the application to stop at the next instruction and somehow the application finished execution without gdb identifying this. But that's just speculation on my part from the behavior I've observed thus far. So my question is if anyone has seen this type of behavior before and/or could suggest what the cause might be. I think that might help me improve my debugging strategy.

如果有问题,我将使用在Ubuntu 10.04 x86_64上运行的g ++ 4.4.3,gdb 7.1.

In case it matters I'm using g++ 4.4.3, gdb 7.1, running on Ubuntu 10.04 x86_64.

推荐答案

我想说,如果这是挂起的原因,则调试后的进程不会处于闲置状态. GDB每次完成一个步骤时,都必须更新您需要打印的所有表达式.它可能包括跟随指针,因此,在某些情况下,它可能会失败(尽管我没有想到真正的挂起").它还通常尝试更新您的堆栈跟踪.如果堆栈跟踪已损坏并且不再连贯,则可能会陷入无限循环.将gdb附加到strace以便查看挂起期间正在进行的活动可能是进一步解决该问题的好方法.

I'd say the debugged process wouldn't sit idle if it was the cause of the hang. Every time GDB has completed a step, it has to update any expressions you required to print. It may include following pointers and so, and in some case, it may fail there (although I don't remind of a real "hang"). It also typically try to update your stack trace. If the stack trace has been corrupted and is no longer coherent, it could be trapped into an endless loop. Attaching gdb to strace to see what kind of activity is going on during the hang could be a good way to go one step further into figuring out the problem.

(例如,通过不再工作的NFS/SSHFS挂载访问源是gdb挂起的最常见原因之一,在这里:P)

(e.g. accessing sources through a no-longer-working NFS/SSHFS mount is one of the most frequent reason for gdb to hang, here :P)

这篇关于为什么gdb会挂起?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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