3

我会尽量做到具体,但到目前为止,我对这个问题的措辞非常糟糕,以至于谷歌未能返回任何有用的结果(因此我的问题在这里)。

我将 gdb 附加到多线程 c++ 服务器进程。我只能说,在尝试执行通常的 set-breakpoint-break-investigate 时发生了奇怪的事情。

首先,在等待断点被击中时(在“继续”模式下),我突然返回 (gdb) 提示符并显示以下消息:

继续。
[线程 0x54d5b940 (LWP 28503) 已退出]
[新线程 0x54d5b940 (LWP 28726)]
无法获取线程事件消息:调试器服务失败

其次,同样在等待断点被击中时,我突然被告知程序已收到 SIGSEGV 并 - 返回到 (gdb) 提示符 - 回溯告诉我 pthread_cancel() 中发生了段错误。请注意,正在调查的进程通常不会出现段错误。

我显然缺乏关于 gdb 如何工作的足够信息,甚至无法开始猜测正在发生的事情。我做错什么了吗?我每次采取的步骤都是一样的:

  1. gdb 附加
  2. 打破'MyFunction()'
  3. 继续

想法?谢谢。

4

1 回答 1

4

I fought with similar gdb issues for a while. My case was having lots of threads spawned that executed few functions and then exited.

It appears if a thread exits too fast and there's lots of these happening sometimes gdb cannot keep up and when it fails, it fails with style as in crashes :) I think it tries to attach to a thread that is already done as per the error message.

I see this as an issue in gdb 6.5 to 7.6 and still happening. Did not try with older versions.

My advice is look for this use case or similar. Once I changed my design to have a thread serving a queue of requests gdb works flawlessly.

Design wise is healthier to have already created threads that digest actions than always spawning new threads.

Still same code debugs without a problem on Visual Studio so I do have to say that is a small disappointment to me with regards to gdb.

I use Eclipse and looking at the GDB traces (usually enabled by default) will give you a better hint of where GDB fails. One of the buttons on the console shows you the GDB trace.

于 2013-11-16T15:35:27.183 回答