1
我想創建一個核心轉儲並使用gdb進行分析。這是我爲創建核心轉儲而寫的代碼。爲什麼gdb -s選項不加載符號文件?
#include <iostream>
void bar()
{
char *p = (char *) 123;
std::cout << "bar start\n";
std::cout << *p << "\n";
std::cout << "bar end\n";
}
void foo()
{
std::cout << "foo start\n";
bar();
std::cout << "foo end\n";
}
int main()
{
foo();
}
這是我的Makefile。
all:
g++ -g foo.cc -o foo
objcopy --only-keep-debug foo foo.dbg
objcopy --strip-debug foo
clean:
rm -rf core* foo
運行make
和./foo
之後,這是我的目錄樣子。
# ls
core.28091 foo foo.cc foo.dbg Makefile
我能夠像這樣分析核心轉儲。我通過指定可執行文件和核心文件作爲命令行參數來啓動gdb。然後我用symbol-file foo.dbg
命令加載foo.dbg中的符號。
[[email protected] crash]# gdb foo core.28091
GNU gdb (GDB) Red Hat Enterprise Linux (7.2-60.el6_4.1)
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/>...
Reading symbols from /root/lab/crash/foo...(no debugging symbols found)...done.
[New Thread 28091]
Missing separate debuginfo for
Try: yum --disablerepo='*' --enablerepo='*-debug*' install /usr/lib/debug/.build-id/81/a81be2e44c93640adedb62adc93a47f4a09dd1
Reading symbols from /usr/lib64/libstdc++.so.6...(no debugging symbols found)...done.
Loaded symbols for /usr/lib64/libstdc++.so.6
Reading symbols from /lib64/libm.so.6...(no debugging symbols found)...done.
Loaded symbols for /lib64/libm.so.6
Reading symbols from /lib64/libgcc_s.so.1...(no debugging symbols found)...done.
Loaded symbols for /lib64/libgcc_s.so.1
Reading symbols from /lib64/libc.so.6...(no debugging symbols found)...done.
Loaded symbols for /lib64/libc.so.6
Reading symbols from /lib64/ld-linux-x86-64.so.2...(no debugging symbols found)...done.
Loaded symbols for /lib64/ld-linux-x86-64.so.2
Core was generated by `./foo'.
Program terminated with signal 11, Segmentation fault.
#0 0x000000000040076f in bar()()
Missing separate debuginfos, use: debuginfo-install glibc-2.12-1.132.el6.x86_64 libgcc-4.4.7-4.el6.x86_64 libstdc++-4.4.7-4.el6.x86_64
(gdb) symbol-file foo.dbg
Reading symbols from /root/lab/crash/foo.dbg...done.
(gdb) bt
#0 0x000000000040076f in bar() at foo.cc:8
#1 0x00000000004007b7 in foo() at foo.cc:15
#2 0x00000000004007d1 in main() at foo.cc:21
(gdb) list
12 void foo()
13 {
14 std::cout << "foo start\n";
15 bar();
16 std::cout << "foo end\n";
17 }
18
19 int main()
20 {
21 foo();
(gdb)
但是,我想在命令行參數中指定符號文件名。但它似乎並不奏效。請參閱下面的輸出。
[[email protected] crash]# gdb -s foo.dbg foo core.28091
GNU gdb (GDB) Red Hat Enterprise Linux (7.2-60.el6_4.1)
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/>...
Reading symbols from /root/lab/crash/foo...(no debugging symbols found)...done.
[New Thread 28091]
Missing separate debuginfo for
Try: yum --disablerepo='*' --enablerepo='*-debug*' install /usr/lib/debug/.build-id/81/a81be2e44c93640adedb62adc93a47f4a09dd1
Reading symbols from /usr/lib64/libstdc++.so.6...(no debugging symbols found)...done.
Loaded symbols for /usr/lib64/libstdc++.so.6
Reading symbols from /lib64/libm.so.6...(no debugging symbols found)...done.
Loaded symbols for /lib64/libm.so.6
Reading symbols from /lib64/libgcc_s.so.1...(no debugging symbols found)...done.
Loaded symbols for /lib64/libgcc_s.so.1
Reading symbols from /lib64/libc.so.6...(no debugging symbols found)...done.
Loaded symbols for /lib64/libc.so.6
Reading symbols from /lib64/ld-linux-x86-64.so.2...(no debugging symbols found)...done.
Loaded symbols for /lib64/ld-linux-x86-64.so.2
Core was generated by `./foo'.
Program terminated with signal 11, Segmentation fault.
#0 0x000000000040076f in bar()()
Missing separate debuginfos, use: debuginfo-install glibc-2.12-1.132.el6.x86_64 libgcc-4.4.7-4.el6.x86_64 libstdc++-4.4.7-4.el6.x86_64
(gdb) bt
#0 0x000000000040076f in bar()()
#1 0x00000000004007b7 in foo()()
#2 0x00000000004007d1 in main()
(gdb) list
No symbol table is loaded. Use the "file" command.
爲什麼它說,即使我已指定它作爲參數傳遞給-s
選項沒有符號表已經被加載?
很好找。我希望你打算打開一個錯誤報告(在https://sourceware.org/bugzilla/),然後在那裏提出一個補丁,或者在其他地方提出補丁。 – dbrank0 2014-09-03 10:03:22
我打開了一個錯誤報告。 https://sourceware.org/bugzilla/show_bug.cgi?id=17349 – 2014-09-03 17:51:10