我正嘗試調試使用GDB從大量共享庫構建的應用程序。無法使用GDB步入共享庫中的函數
啓動gdb的:
prompt$ gdb
GNU gdb (GDB) Red Hat Enterprise Linux (7.2-50.el6)
Copyright (C) 2010 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-redhat-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
告訴GDB程序調試:
(gdb) file /home/me/build-path/my-program
Reading symbols from /home/me/build-path/my-program...done.
設置應用程序中的斷點:
(gdb) my-program-src.cpp:57
breakpoint 1 at 0x819df9b: file src/my-program-src.cpp, line 57
運行程序:
(gdb) run
Starting program: /home/me/build-path/my-program
程序在斷點處停止,符合市場預期:
Breakpoint 1 MyClass:func(this-0xffffc1c0) at src/my-program-src.cpp:235
線my-program-src.cpp
235是一個構造函數調用的class Derived
這是MySharedLib1.so
。
「類派生」從「類基地」,這是在MySharedLib2.so
如果我現在步驟,裏面的程序退出衍生`MySharedLib2.so」與SIG SEGV(這是我試圖調試),即:
Program received signal SIGSEGV, Segmentation fault.
0x0024c2fa in osal::MsgQMsg::id(unsigned int)() from /home/me/build-path/lib/libMySharedLib2.so
GDB沒有進入任何一個共享庫。
bt
給出現問題的函數的名稱,但list
顯示my-program-src.cpp
代碼的所有代碼與下面的選項編譯:
gcc -MD -D__LINUX__ -g -Wall -Wextra -Iinc -m32 -fpic -I../../public_inc /home/me/src/file.c -o /home/me/build-path/obj/file.o
共享庫與以下鏈接選項:
gcc -o /home/me/build-path/lib/libMySharedLib1.so -shared /home/me/build-path/obj/file.o -L/home/me/build-path/lib/ -m32
如果我更改Makefiles以便構建存檔庫(即.a
)我可以按照預期進入功能。
更多信息:
如果我嘗試手動從共享庫,我得到以下添加符號:
(gdb) add-symbol-file /home/me/build-path/lib/libMySharedLib2.so
The address where /home/me/build-path/lib/libMySharedLib2.so has been loaded is missing
(注:我從add-symbol-file
相同的反應,一旦斷點已經點擊)
如果我可以在共享庫中的函數中設置斷點,GDB按預期中斷,但是如果我輸入list
GDB在主應用程序代碼中顯示調用行(即調用函數不在共享庫中)。 GDB不會抱怨找不到源文件。
爲什麼我不能進入我的共享庫?
爲什麼我無法逐步瀏覽共享庫中的代碼?
GDB不會在構造函數中的一步。你有沒有嘗試加入共享庫中的其他功能?還有你用-g選項編譯共享庫嗎? –
所有代碼都使用'-g'選項進行編譯並且不進行優化。 GDB不會進入共享庫中的任何函數。它將在共享庫中設置的斷點處停止,但我無法列出源代碼行,並且我無法查看GDB停止的類/函數本地的任何變量。 – mark
這可能是一個32/64位的問題。您正在調試64位版本的GDB的32位程序。 GDB並不是世界上最穩定的軟件,也有錯誤。嘗試使用GDB的32位版本。 –