[GDB] 載入某個 library 的 symbol file

[GDB] 載入某個 library 的 symbol file

今天用 gdb debug 一個 crash dump,backtrace 裡什麼都看不到:

(gdb) bt
#0  0x00007f4d3fbb23e2 in ?? ()
#1  0x000000000298f970 in ?? ()
#2  0x000000000298f97c in ?? ()
#3  0x000000000298f978 in ?? ()
#4  0x0000000000000000 in ?? ()

 

想想應該是因為程式裡用到的 share library 的 debug symbol 被我們拔掉了~

先用 info sharedlibrary 查一下各個 library 的載入位址,

如本例中的 ../libmy.so 是在 0x00007f4d3fb942b0:

(gdb) info sharedlibrary
From                To                  Syms Read   Shared Object Library
0x00007f4d3fff9670  0x00007f4d40002ae8  No          /lib64/lib7zip.so.0
0x00007f4d3fdd48a0  0x00007f4d3fddf514  No          /lib64/libpthread.so.0
0x00007f4d3fb942b0  0x00007f4d3fbb5604  No          ../libmy.so
0x00007f4d3f8ab510  0x00007f4d3f91259a  No          /lib64/libstdc++.so.6
0x00007f4d3f5534b0  0x00007f4d3f5bd9e8  No          /lib64/libm.so.6
0x00007f4d3f33aaf0  0x00007f4d3f34a298  No          /lib64/libgcc_s.so.1
0x00007f4d3ef963e0  0x00007f4d3f0d9ba0  No          /lib64/libc.so.6
0x00007f4d4020aae0  0x00007f4d4022527a  No          /lib64/ld-linux-x86-64.so.2
0x00007f4d3ed73ed0  0x00007f4d3ed749d0  No          /lib64/libdl.so.2
0x00007f4d3aadf570  0x00007f4d3aae0018  No          /usr/lib64/gconv/ISO8859-1.so

 

接著就可以用 add-symbol-file 指令,直接指定 symbol file 要載入到哪個位址去:

(gdb) add-symbol-file ../libmy.so.dbg 0x00007f4d3fb942b0
add symbol table from file "../libmy.so.dbg" at
.text_addr = 0x7f4d3fb942b0
(y or n) y
Reading symbols from /tmp/libmy.so.dbg...done.

 

載入好後,backtrace 就可以看到 shared library 的 symbol 囉:

(gdb) bt
#0  0x00007f4d3fbb23e2 in NormalizeFileType (this=<error reading variable: can't compute CFA for this frame>, 
nFileType=<error reading variable: can't compute CFA for this frame>) at ./Manager.cpp:12
#1  0x00007f4d3fb9fb17 in AddFile (this=<error reading variable: can't compute CFA for this frame>,
pFileName=<error reading variable: can't compute CFA for this frame>) at ./Scan.cpp:638
#2  0x000000000042093e in ?? ()
#3  0x00007ffd3ea26328 in ?? ()
#4  0x0000000000000000 in ?? ()

 

(本頁面已被瀏覽過 4,828 次)

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *

這個網站採用 Akismet 服務減少垃圾留言。進一步了解 Akismet 如何處理網站訪客的留言資料