Linux what are debugging symbols

What is Linux native debugging symbols format?

GCC documentation says that the -g option produces debugging information in the operating system’s native format (stabs, COFF, XCOFF, or DWARF 2). So, what is Linux native debugging symbols format? What is it called? Update: I’ve just found a 15-year old gcc mailing list discussion where it was said that the native format at that point was stabs and then they were considering to switch to DWARF2. But it was 15 years ago. Any updates? =)

According to the DWARF page on wikipedia, «Linux followed suit, and DWARF-2 did not become the default until the late 1990s.». I’d like to see a more authoritative source though.

1 Answer 1

On Linux the default is now Dwarf 2 and/or 4. To see this, run readelf —debug-dump=info on a binary containing debug symbols (or stripped symbols); for example, on Fedora, with glibc-debuginfo installed, running readelf —debug-dump=info /usr/lib/debug/bin/gencat.debug will give you something like

 : Abbrev Number: 0 Compilation Unit @ offset 0xeb: Length: 0x5c (32-bit) Version: 2 Abbrev Offset: 0x52 Pointer Size: 8 : Abbrev Number: 1 (DW_TAG_compile_unit) DW_AT_stmt_list : 0x83 DW_AT_ranges : 0x0 DW_AT_name : ../sysdeps/x86_64/crti.S DW_AT_comp_dir : /usr/src/debug////////glibc-2.21/csu DW_AT_producer : GNU AS 2.25 DW_AT_language : 32769 (MIPS assembler) 

This is a set of Dwarf 2 information (see the Version: header for version information; the same binary includes Dwarf 2 and Dwarf 4 sections).

Читайте также:  Php running linux commands

Источник

What do debugging symbols look like?

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:

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,

Источник

GDB debugging basics

GDB is a debugger for executables “objects” on Linux. It will use source code and “debug symbols” if available:

  • source code to display the code ie. corresponding to a specific frame at runtime,
  • debug symbols to display variables and functions names like in the code.

What’s the relation between security and GDB ? Well it will help finding security bugs which may be vulnerabilities to buffer overflow.

Debugging with sources and debug symbols

Consider the following C source code example for hello world:

 #include   int YourGlobalVariable;   main()    int YourLocalVariable;   printf("Hello World\n");   return 0;  >

Compile with debug symbols with -ggdb :

Now you can easely debug with gdb :

$ gdb main GNU gdb (GDB) 7.7 Copyright (C) 2014 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later 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-unknown-linux-gnu". Type "show configuration" for configuration details. For bug reporting instructions, please see: . Find the GDB manual and other documentation resources online at: . For help, type "help". Type "apropos word" to search for commands related to "word". Reading symbols from main. done. 

List source files with (gdb) info sources

(gdb) info sources Source files for which symbols have been read in: /home/jpic/main.c Source files for which symbols will be read in on demand: 

Show variables with (gdb) info variables

(gdb) info variables All defined variables: File main.c: int YourGlobalVariable; Non-debugging symbols: 0x00000000004005b0 _IO_stdin_used 0x00000000004006e8 __FRAME_END__ 0x00000000006006f0 __frame_dummy_init_array_entry 0x00000000006006f0 __init_array_start 0x00000000006006f8 __do_global_dtors_aux_fini_array_entry 0x00000000006006f8 __init_array_end 0x0000000000600700 __JCR_END__ 0x0000000000600700 __JCR_LIST__ 0x0000000000600708 _DYNAMIC 0x00000000006008e0 _GLOBAL_OFFSET_TABLE_ 0x0000000000600910 __data_start 0x0000000000600910 data_start 0x0000000000600918 __dso_handle 0x0000000000600920 __TMC_END__ 0x0000000000600920 __bss_start 0x0000000000600920 _edata 0x0000000000600920 completed 0x0000000000600928 _end 

Show functions with (gdb) info functions

(gdb) info functions All defined functions: File main.c: int main(); Non-debugging symbols: 0x00000000004003a8 _init 0x00000000004003e0 printf@plt 0x00000000004003f0 __libc_start_main@plt 0x0000000000400400 __gmon_start__@plt 0x0000000000400410 _start 0x0000000000400440 deregister_tm_clones 0x0000000000400470 register_tm_clones 0x00000000004004b0 __do_global_dtors_aux 0x00000000004004d0 frame_dummy 0x0000000000400530 __libc_csu_init 0x00000000004005a0 __libc_csu_fini 0x00000000004005a4 _fini 

Show local variables with (gdb) info scope

(gdb) info scope main Scope for main: Symbol YourLocalVariable is a complex DWARF expression: 0: DW_OP_fbreg -20 , length 4. 

Break on a function with (gdb) b

(gdb) b main Breakpoint 1 at 0x400505: file main.c, line 7. 

Run the object in gdb with (gdb) run

Run the object, it will break on main() (see above):

(gdb) run Starting program: /home/jpic/main warning: Could not load shared library symbols for linux-vdso.so.1. Do you need "set solib-search-path" or "set sysroot"? Breakpoint 1, main () at main.c:7 7 int YourLocalVariable=6; 

Continue to next line on break with (gdb) n

(gdb) n 9 printf("Hello %i World\n", YourLocalVariable); 
(gdb) print YourLocalVariable $1 = 6 

Continuing normal execution with (gdb) c

(gdb) c Continuing. Hello 6 World [Inferior 1 (process 17984) exited normally] (gdb) 

Debugging without debugging symbols

Without debugging symbols, gcc does not know where a function is defined:

(gdb) info functions All defined functions: Non-debugging symbols: 0x00000000004003a8 _init 0x00000000004003e0 puts@plt 0x00000000004003f0 __libc_start_main@plt 0x0000000000400400 __gmon_start__@plt 0x0000000000400410 _start 0x0000000000400440 deregister_tm_clones 0x0000000000400470 register_tm_clones 0x00000000004004b0 __do_global_dtors_aux 0x00000000004004d0 frame_dummy 0x00000000004004fd main 0x0000000000400520 __libc_csu_init 0x0000000000400590 __libc_csu_fini 0x0000000000400594 _fini 

Debugging without source code

Listing the source code does not work:

(gdb) list No symbol table is loaded. Use the "file" command. 

Further reading

They trust us

Contact

YourLabs Business Service © 2012-2023

Источник

Оцените статью
Adblock
detector