为什么gdb -s选项不加载符号文件? [英] Why doesn't the gdb -s option load the symbol file?

查看:204
本文介绍了为什么gdb -s选项不加载符号文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个核心转储,并使用gdb对其进行分析.这是我编写的用于创建核心转储的代码.

I am trying to create a core dump and analyze it with gdb. This is the code I wrote to create a core dump.

#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.

This is my 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之后,这就是我的目录.

After running make and ./foo, this is what my directory looks like.

# ls
core.28091  foo  foo.cc  foo.dbg  Makefile

我能够像这样分析核心转储.我通过将可执行文件和核心文件指定为命令行参数来启动gdb.然后,使用symbol-file foo.dbg命令从foo.dbg中加载符号.

I am able to analyze the core dump like this. I launch gdb by specifying the executable and the core file as command line arguments. Then I load the symbols from foo.dbg with the symbol-file foo.dbg command.

[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)

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

However, I want to specify the symbol file name in the command line argument as well. But it doesn't seem to work. See the output below.

[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选项的参数,它也没有加载符号表?

Why does it say no symbol table has been loaded even though I have specified it as an argument to the -s option?

推荐答案

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

It looks like a bug in gdb. gdb sets symarg to the argument that follows -s, but then later in the code, it unconditionally sets symarg to the executable's name. Proposed minimal diff follows:

$ 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];

这篇关于为什么gdb -s选项不加载符号文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆