我用-g选项编译时为什么不创建gdb符号

时间:2017-05-17 17:11:23

标签: c linux unix gdb

要了解unix命令的工作原理,我构建了procps

这是我的程序,

$ git clone git@github.com:soarpenguin/procps-3.0.5.git
$ cd procps-3.0.5
  • 然后,我修改了Makefile this line
  • 刚刚更改了选项-g3 => -g

CFLAGS := -D_GNU_SOURCE -O2 -g3 -fno-common -ffast-math -I proc

CFLAGS := -D_GNU_SOURCE -O2 -g -fno-common -ffast-math -I proc

之后

   $ mkdir /tmp/sample
   $ make 
   $ sudo make install DESTDIR=/tmp/sample
   install -D --owner 0 --group 0 --mode a=rx --strip top 
   /tmp/sample/usr/bin/top
   $ ls /tmp/sample/usr/bin/ |grep top
   top

问题

不知怎的,我添加-g选项,gdb无法读取符号,为什么?
特别是no debugging symbols found

$ gdb /tmp/sample/usr/bin/top
GNU gdb (GDB) Red Hat Enterprise Linux (7.2-92.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/>...
Reading symbols from /tmp/sample/usr/bin/top...(no debugging symbols found)...done.

我的环境

$ cat /etc/system-release
CentOS release 6.9 (Final)

$ gdb -v
GNU gdb (GDB) Red Hat Enterprise Linux (7.2-92.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/>.

2 个答案:

答案 0 :(得分:1)

strip选项会丢弃目标文件中的所有符号。它用于生产对象,重量轻。

要确保它是strip选项,请在安装之前运行gdb。

答案 1 :(得分:0)

  

img

sudo make install DESTDIR=/tmp/sample删除已安装的二进制文件非常常见。

  

make install

这就是这里发生的事情(请注意上面的install -D --owner 0 --group 0 --mode a=rx --strip top)。

您可以调试原始可执行文件:

--strip

或使用原始二进制文件作为符号文件调试已安装的gdb ./top

/tmp/sample/usr/bin/top
相关问题