Thursday, July 2, 2015
gdb
1. Start gdb on an executable file:$ gdb abc // file "abc" is an executable file or a core file.
OR
$ gdb
(gdb) file abc // open executable file "abc"
2. Configuration of gdb: (gdb) set linesize 30 // Set number of lines displayed by list command.
(gdb) set prompt (gdb)$ // set gdb prompt instead of default (gdb)
(gdb) show commands // Show last 10 commands in history
(gdb) show commands 30 // Show last 10 commands around line 30 in history
(gdb) show commands + // Show next 10 commands.
3. Use shell commands: Only cd, pwd and make can be used directly in gdb, rest of commands should
be prefixed with shell.
(gdb) cd aFolder
(gdb) pwd
(gdb) make
(gdb) shell ls // Run ls command
4. GDB commands for debugging purpose. a) Run:
(gdb) run // Run program
(gdb) run arg1 arg2 // Run program with arguments
b) Set Breakpoint/Stop Sign:
(gdb) b location // Set a stop sign at aLocation.
(gdb) watch theVar // watch is a special stop sign. Stops when theVar's value is changing.
(gdb) rwatch theVar // Stops when theVar is read from.
(gdb) awatch theVar // Stops when theVar is read from or written to.
(gdb) advance aLocation // Continue to this temporary aLocation.
c) Examine variables:
(gdb) p theVar // Display value of theVar.
(gdb) disp theVar // Display value of theVar EACH TIME program STOPs.
(gdb) info disp // For instance, find display# for theVar is 3.
(gdb) undisp 3 // Remove display of theVar whose display# is 3.
(gdb) set variable theVar = 100 // Change theValue's value to 100.
(gdb) set (theVar = 100) // Change theValue's value to 100.
d) Stop and Go.
<<STOPS>>
(gdb) when arriaved at a stop sign // Pause the execution of program.
(gdb) b 17 // Set a stop sign at line 17.
(gdb) i b // List all the stop signs.
(gdb) CTRL-C // Pause the execution of program.
// If followed by "bt" command, you will know where you are.
<<GOES>>
(gdb) next // Move on to the next statement treating a function as one statement.
(gdb) step // Move on to the next statement treating a function as multiple statements.
(gdb) finish // Exit a function body but NOT resume the execution.
(gdb) continue // Resume the execution of program at the current place.
(gdb) jump aLocation // Resume execution at aLocation. (similar to GOTO)
e) Stack (function stack)
(gdb) bt // Print all the frames in stack.
// Also tells which function you are in (where you are.).
(gdb) up // Go to one-level outer function.
(gdb) down // Go to one-level inner function.
(gdb) frame 3 // Go to frame 3
(gdb) info args // Display args for the current frame/function.
(gdb) info locals // Display local variables for the current frame/function.
(gdb) info reg // Display register
(gdb) info all-reg // Display all registers
(gdb) info reg general // Display general register
(gdb) info reg float // Display float register
(gdb) info reg // Display local variables for the current frame/function.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment