gpt4 book ai didi

c - 为什么在使用 -g 选项编译时没有创建 gdb 符号

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:39:54 27 4
gpt4 key购买 nike

为了了解 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无法读取符号,为什么?
特别是 找不到调试符号

$ 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/>.

最佳答案

strip 选项丢弃目标文件中的所有符号。用于生产 object 轻量化。

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

关于c - 为什么在使用 -g 选项编译时没有创建 gdb 符号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44031072/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com