Monday, April 20, 2015

Gcc GDB

@ Compile Option
 -g : Add debugging info into executable file

# gcc -g main.c

# gdb a.out
GNU gdb (GDB) 7.2-ubuntu
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 "i686-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /root/debug2/test2...done.
(gdb) 

@ Command Examples
(gdb) run
(gdb) break 12 // b 12
(gdb) break 20
(gdb) break 99
(gdb) delete 99 // d 99
(gdb) info break // show break info
Num     Type           Disp Enb Address    What
1       breakpoint     keep y   0x08048411 in main at test2.c:12
2       breakpoint     keep y   0x0804847c in sum at test2.c:20

(gdb) continue // c, continue to next break
(gdb) next // n, move to next line (not into a function)
(gdb) step // s, step into a function
(gdb) print i // p i, print value of 'i'
(gdb) list // l, list source code around current line

(gdb) x $pc // show the value of register, $pc
(gdb) x 0x8048445 // show the value of address, 0x8048445
(gdb) info reg // show register info

(gdb) quit

No comments:

Post a Comment