EmbLogic's Blog

Seeing Dubugging symbols which are added by gcc using -g option

A Debugging Symbol Table maps instructions in the compiled binary program to their corresponding variable, function, or line in the source code. This mapping could be something like:

  • Program instruction => item name, item type, original file, line number defined.

Symbol tables may be embedded into the program, or stored as a separate file. So if you plan to debug your program then it is required to create Symbol table which will have required information to debug the program.

We can infer a few facts about symbol tables:

  • A symbol table works for a particular version of the program –if the program changes, a new table must be made.
  • Debug builds are often larger and slower than retail (non-debug) builds; debug builds contain the symbol table and other ancillary information.
  • If you wish to debug a binary program you did not compile yourself, you must get the symbol tables from the author.

First when you write your c, c++ program your symbol table shows as :-

gcc -c hello1 hello.c

objdump -t hello.o  //  objdump command analysis object file and -t is a option to show symbol table.

hello.o:     file format elf32-i386

SYMBOL TABLE:
00000000 l    df *ABS*    00000000 hello.c
00000000 l    d  .text    00000000 .text
00000000 l    d  .data    00000000 .data
00000000 l    d  .bss    00000000 .bss
00000000 l    d  .rodata    00000000 .rodata
00000000 l    d  .note.GNU-stack    00000000 .note.GNU-stack
00000000 l    d  .comment    00000000 .comment
00000000 g     F .text    00000054 main
00000000         *UND*    00000000 printf

When you add -g option for de bugging in you program like:-

gcc -g -c hello hello.c

symbol table looks as :-

objdump -t hello.o

hello.o:     file format elf32-i386

SYMBOL TABLE:
00000000 l    df *ABS*    00000000 hello.c
00000000 l    d  .text    00000000 .text
00000000 l    d  .data    00000000 .data
00000000 l    d  .bss    00000000 .bss
00000000 l    d  .debug_abbrev    00000000 .debug_abbrev
00000000 l    d  .debug_info    00000000 .debug_info
00000000 l    d  .debug_line    00000000 .debug_line
00000000 l    d  .rodata    00000000 .rodata
00000000 l    d  .debug_frame    00000000 .debug_frame
00000000 l    d  .debug_loc    00000000 .debug_loc
00000000 l    d  .debug_pubnames    00000000 .debug_pubnames
00000000 l    d  .debug_aranges    00000000 .debug_aranges
00000000 l    d  .debug_str    00000000 .debug_str
00000000 l    d  .note.GNU-stack    00000000 .note.GNU-stack
00000000 l    d  .comment    00000000 .comment
00000000 g     F .text    00000054 main
00000000         *UND*    00000000 printf

One Response to Seeing Dubugging symbols which are added by gcc using -g option

  1. Manish says:

    dmesg is used to examine or control the kernel ring buffer.The program helps users to print out their bootup messages.

    dmesg -c :Clear the ring buffer contents after printing.

    #dmesg -c && dmesg
    # (that means buffer clear)

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>