【问题标题】:Why doesn't the gdb -s option load the symbol file?为什么 gdb -s 选项不加载符号文件?
【发布时间】:2014-10-26 19:44:58
【问题描述】:

我正在尝试创建核心转储并使用 gdb 对其进行分析。这是我为创建核心转储而编写的代码。

#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 加载符号。

[root@centos 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)

但是,我也想在命令行参数中指定符号文件名。但这似乎不起作用。请参阅下面的输出。

[root@centos 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 选项的参数,它仍说未加载符号表?

【问题讨论】:

    标签: gdb


    【解决方案1】:

    它看起来像 gdb 中的一个错误。 gdb 将symarg 设置为-s 后面的参数,但随后在代码中,它无条件地将symarg 设置为可执行文件的名称。建议的最小差异如下:

    $ diff -C 1 main.c.orig main.c
    *** main.c.orig 2014-07-29 08:37:42.000000000 -0400
    --- main.c      2014-09-02 16:27:54.079039046 -0400
    ***************
    *** 864,866 ****
            }
    !       symarg = argv[optind];
            execarg = argv[optind];
    --- 864,866 ----
            }
    !       if (symarg == NULL) symarg = argv[optind];
            execarg = argv[optind];
    ***************
    *** 877,879 ****
            {
    !         symarg = argv[optind];
              execarg = argv[optind];
    --- 877,879 ----
            {
    !         if (symarg == NULL) symarg = argv[optind];
              execarg = argv[optind];
    

    【讨论】:

    • 不错的发现。我希望你计划打开一个错误报告(sourceware.org/bugzilla)并在那里提出一个补丁或者在上游获取它。
    猜你喜欢
    • 1970-01-01
    • 2012-08-09
    • 1970-01-01
    • 1970-01-01
    • 2013-12-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-20
    相关资源
    最近更新 更多