ryfjwr
ryfjwr

Reputation: 21

why does not created gdb symbols when I compiled with -g option

To know how unix command works, I build procps.

Here is my procedure,

$ git clone [email protected]:soarpenguin/procps-3.0.5.git
$ cd procps-3.0.5

before

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

after

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

after that

   $ 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

Question

Somehow I add -g option, gdb can't read symbol, why?
especialy 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.

my environment

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

Upvotes: 1

Views: 100

Answers (2)

Employed Russian
Employed Russian

Reputation: 213636

sudo make install DESTDIR=/tmp/sample

It is very common for make install to strip the binaries that are installed.

install -D --owner 0 --group 0 --mode a=rx --strip top

And that's exactly what happened here (note the --strip above).

You can either debug the original executable:

gdb ./top

or debug the installed /tmp/sample/usr/bin/top while using the original binary as symbol file:

gdb /tmp/sample/usr/bin/top
(gdb) symbol-file ./top
(gdb) run

Upvotes: 0

HenryGiraldo
HenryGiraldo

Reputation: 415

strip option discards all symbols from object files. It is used for production objects to be light weight.

To ensure that it is the strip option, run the gdb before installing it.

Upvotes: 1

Related Questions