Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What do debugging symbols look like?

Tags:

c

debugging

gdb

gcc (GCC) 4.6.0 GNU gdb (GDB) Fedora (7.2.90.20110525-38.fc15)

I recently had a problem when I was trying to debug my problem using gdb. When I loaded my binary the gdb complained "No debugging symbols were found"

So when I did the following:

nm ass1

I got the following output (only sample)

00000000006026e0 t __init_array_end
00000000006026d0 t __init_array_start
00000000004020e0 T __libc_csu_fini
0000000000402050 T __libc_csu_init
                 U __libc_start_main@@GLIBC_2.2.5
00000000006029ec A _edata
0000000000602b28 A _end
000000000040212c T _fini
0000000000401420 T _init
0000000000401610 T _start
                 U atoi@@GLIBC_2.2.5
000000000040163c t call_gmon_start
0000000000602b10 b completed.5886
00000000006029e8 W data_start
0000000000602b18 b dtor_idx.5888
00000000004016d0 t frame_dummy
00000000004016f4 T main

The problem was I forgot to add the -g. So I decided to compile with -g and ran nm again. I got a simliar output, this contains the debug symbols as I used -g, and gdb didn't complain this time:

                 U __libc_start_main@@GLIBC_2.2.5
00000000006029ec A _edata
0000000000602b28 A _end
000000000040212c T _fini
0000000000401420 T _init
0000000000401610 T _start
                 U atoi@@GLIBC_2.2.5
000000000040163c t call_gmon_start
0000000000602b10 b completed.5886
00000000006029e8 W data_start
0000000000602b18 b dtor_idx.5888
00000000004016d0 t frame_dummy
00000000004016f4 T main
                 w pthread_cancel

Apart from the binary being bigger in size. I could notice any different using nm. I am wondering what should I be looking for? What do the debug symbols look like?

Many thanks for any suggestions,

like image 420
ant2009 Avatar asked Jun 18 '11 17:06

ant2009


1 Answers

nm hides the debug symbols by default. Use the -a option to show them.

Modern systems often don't use debug symbols per se. The stabs debug format was developed for use with a.out format executables, which can only represent a limited amount of internal structure; this led to hiding quite a lot of stuff in the symbol table, such as the debug symbols and initializers/constructors. The COFF (now mostly obsolete) and ELF file formats allow the use of arbitrary sections, and most modern Linux distributions configure gcc to use DWARF 2 debugging information. You should be able to use GNU objdump to examine that information.

(I don't appear to have access to a machine whose binutils will generate stabs or the GNU stabs+ format, so I'll defer to Google for the details.)

like image 175
geekosaur Avatar answered Sep 28 '22 12:09

geekosaur