1)
$gdb
* Open gdb
2)
(gdb) attach [process-id]
* Attach to a process
* Detach process from GDB before quiting GDB.
(gdb) detach [process-id]
(gdb) quit
3)
(gdb) info files
4)
(gdb) info function
5)
(gdb) b FlowEntry::DoPolicy
* Add breakpoint
6)
(gdb) info breakpoints
(gdb) info break
* A backtrace is a summary of how your program got where it is. It shows one line per frame, for many frames, starting with the currently executing frame (frame zero), followed by its caller (frame one), and on up the stack.
* https://sourceware.org/gdb/onlinedocs/gdb/Backtrace.html
7)
(gdb) del 2
* Delete a breakpoint
8)
(gdb) run/r
* Let it run and stop at breakpoint.
9)
(gdb) bt
OR
(gdb) backtrace
* Print the location
10)
(gdb) next
* If you want to execute the entire function with one keypress, type "next" or "n".
11)
(gdb) step
* To execute one line of code, type "step" or "s". If the line to be executed is a function call, gdb will step into that function and start executing its code one line at a time.
12)
* Print variable
(gdb) p var1
(gdb) print var1
* Run following command to format the print output
(gdb) set print pretty
13)
* Print current line and line number with few lines before and after
(gdb) list *$rip
14)
* Print current line
(gdb) frame
15)
* Print current line and more info with the function name
(gdb) where
16)
* Display a few lines of your source program around the current location
(gdb) l
OR
(gdb) list
17)
* print the data type of a variable
* You can even use ptype to look at structures
(gdb) ptype var1
OR
(gdb) pt var1
$gdb
* Open gdb
2)
(gdb) attach [process-id]
* Attach to a process
* Detach process from GDB before quiting GDB.
(gdb) detach [process-id]
(gdb) quit
3)
(gdb) info files
4)
(gdb) info function
5)
(gdb) b FlowEntry::DoPolicy
* Add breakpoint
6)
(gdb) info breakpoints
(gdb) info break
* A backtrace is a summary of how your program got where it is. It shows one line per frame, for many frames, starting with the currently executing frame (frame zero), followed by its caller (frame one), and on up the stack.
* https://sourceware.org/gdb/onlinedocs/gdb/Backtrace.html
7)
(gdb) del 2
* Delete a breakpoint
8)
(gdb) run/r
* Let it run and stop at breakpoint.
9)
(gdb) bt
OR
(gdb) backtrace
* Print the location
10)
(gdb) next
* If you want to execute the entire function with one keypress, type "next" or "n".
11)
(gdb) step
* To execute one line of code, type "step" or "s". If the line to be executed is a function call, gdb will step into that function and start executing its code one line at a time.
12)
* Print variable
(gdb) p var1
(gdb) print var1
* Run following command to format the print output
(gdb) set print pretty
13)
* Print current line and line number with few lines before and after
(gdb) list *$rip
14)
* Print current line
(gdb) frame
15)
* Print current line and more info with the function name
(gdb) where
16)
* Display a few lines of your source program around the current location
(gdb) l
OR
(gdb) list
17)
* print the data type of a variable
* You can even use ptype to look at structures
(gdb) ptype var1
OR
(gdb) pt var1
a)
ReplyDeleteTo See Source code
>Ctrl + x + 1
b)
To see both source and assembly
>Ctrl + x + 2
Stepping And Resuming
ReplyDeletehttp://www.dirac.org/linux/gdb/05-Stepping_And_Resuming.php
Debugging A Running Process
ReplyDeletehttp://www.dirac.org/linux/gdb/06-Debugging_A_Running_Process.php
Debugging sample Program
ReplyDeletehttp://www.dirac.org/linux/gdb/07-Debugging_Ncurses_Programs.php
Debugging sample Program 2
ReplyDeletehttps://sourceware.org/gdb/onlinedocs/gdb/Sample-Session.html
Debugging sample Program 3
ReplyDeletehttp://www.cprogramming.com/gdb.html
Debugging sample Program 4
ReplyDeletehttps://people.gnome.org/~newren/tutorials/developing-with-gnome/html/ch03.html
http://www.ibm.com/developerworks/library/l-gdb/
Debugging sample Program 5
ReplyDeletehttp://betterexplained.com/articles/debugging-with-gdb/