【发布时间】:2014-03-11 08:20:46
【问题描述】:
我有以下问题。我运行了一个创建了多个线程的程序。 Gdb 输出以下线程:
(gdb) info thread
Id Target Id Frame
3 LWP 23941 0x00007f5fc327c2d4 in ?? ()
2 LWP 22925 0x00007f5fc327e420 in ?? ()
* 1 LWP 23934 0x00007f5fc2779475 in ?? ()
第二个线程的回溯如下:
(gdb) thread 2
[Switching to thread 2 (LWP 22925)]
#0 0x00007f5fc327e420 in ?? ()
(gdb) bt
#0 0x00007f5fc327e420 in ?? ()
#1 0x00007f5fb406f300 in ?? ()
#2 0x0000000000439021 in AaSemWait (semPtr=0x7f5fb406f300) at ../bm/testing/unit/src/ccs/AaSem.cpp:97
#3 0x00000000004197d5 in bm_semaphore_base::wait (this=0x7fff75b01db8) at /home/michaelfrysztacki/bm_local_build2/BTS_SC_BM/bm/interface/framework/bm_semaphore.h:174
#4 0x0000000000500e1c in radio::thread_synchroniser::wait (this=0x7fff75b01c00) at /home/michaelfrysztacki/bm_local_build2/BTS_SC_BM/bm/radio/testing/stubs/radio_module_receiver.h:107
#5 0x00000000005034a5 in radio::mt_radio_service::send_messages (this=0x7f5fb406d140) at ../bm/radio/testing/unit/mt_radio_service.cpp:236
#6 0x0000000000503010 in radio::mt_radio_service::simulate_radio_modules (this=0x7f5fb406d140, set_timeoff_test=false) at ../bm/radio/testing/unit/mt_radio_service.cpp:189
#7 0x00000000004fde77 in radio::mt_radio_service_module_test_sending_message_and_receive_from_radio_service_Test::TestBody (this=0x7f5fb406d140) at ../bm/radio/testing/unit/mt_radio_service.cpp:347
#8 0x000000000069cab1 in void testing::internal::HandleSehExceptionsInMethodIfSupported<testing::Test, void>(testing::Test*, void (testing::Test::*)(), char const*) ()
....
这个回溯让我很满意,因为我知道程序在哪里停止。 我对第一次回溯感到困惑:
(gdb) thread 1
[Switching to thread 1 (LWP 23934)]
#0 0x00007f5fc2779475 in ?? ()
(gdb) bt
#0 0x00007f5fc2779475 in ?? ()
#1 0x00007f5fc277c675 in ?? ()
#2 0x0000000000000000 in ?? ()
也许这个线程运行到一个共享库中,我没有调试符号和源,我可以接受。我想知道我的程序从哪里调用了共享库方法。我无法用这个回溯来确定它。我可以下载一些带有调试符号的共享库,但我怎么知道哪个共享库进入了我的线程?或者也许这是使用 pthread 启动线程的入口点?为什么这个回溯这么差?最后我不完全确定这是否是一个共享库,我怎样才能得到它?
(gdb) info sharedlibrary
warning: Can't read pathname for load map: Input/output error.
From To Syms Read Shared Object Library
No /lib/x86_64-linux-gnu/librt.so.1
No /lib/x86_64-linux-gnu/libexpat.so.1
No /usr/lib/libboost_thread.so.1.49.0
No /usr/lib/libboost_system.so.1.49.0
No /usr/local/lib/libprotobuf.so.8
No /lib/x86_64-linux-gnu/libpthread.so.0
No /usr/lib/x86_64-linux-gnu/libstdc++.so.6
No /lib/x86_64-linux-gnu/libm.so.6
No /lib/x86_64-linux-gnu/libgcc_s.so.1
No /lib/x86_64-linux-gnu/libc.so.6
No /lib64/ld-linux-x86-64.so.2
“info sharedlibrary”命令列出了我没有调试符号的共享库。我怎样才能得到图书馆,例如/usr/lib/libboost_thread.so.1.49.0 带有调试符号(和源代码)?
【问题讨论】:
-
您是否使用调试信息构建了您的应用程序?与调试库(如果可用)链接?那么这就是你所能做的。如果调试器在没有任何调试信息的代码上停止,则很可能是在没有信息的库中,您所能做的就是将调用堆栈
up遍历到您的代码(问题最有可能出现的地方)。 -
在我的 ubuntu 上,调试 pthread 库位于
/usr/lib/debug/lib/x86_64-linux-gnulibpthread-2.11.1.so,请确保您使用的是类似的 -
第二个线程的回溯已经告诉我们,我的应用程序是用调试符号构建的。我在第一篇文章中添加了一些关于上面缺少共享库调试符号的信息。
-
一种可能性是它(意思是你的代码:))已经破坏了另一个线程的堆栈跟踪。可能我会首先怀疑我的代码,除非我使用的是非常无保证的第 3 部分库。
标签: c++ gdb shared-libraries