GDB print variable inside breakpoint
If you want to print value each time breakpoint is hit you can use command inside gdb.
// main.c #includeint main() { for(int i=0;i<10;i++) { int b = i; // we want to print this value each time gdb hits the line } }
we have to compile the code
gcc -g -o main main.c
and use gdb
gdb main (gdb) list 1 #include2 3 int main() { 4 int i; 5 int b; 6 for(i=0;i<10;i++) { 7 int b = i; // we want to print this value each time gdb hits the line 8 } 9 } 10 (gdb) break 7 Breakpoint 1 at 0x100000f1d: file main.c, line 7. (gdb) command Type commands for when breakpoint 1 is hit, one per line. End with a line saying just "end". >print i >cont >end (gdb) run Starting program: /Users/michalo/test/main Reading symbols for shared libraries +............................. done Breakpoint 1, main () at main.c:7 7 int b = i; // we want to print this value each time gdb hits the line $1 = 0 Breakpoint 1, main () at main.c:7 7 int b = i; // we want to print this value each time gdb hits the line $2 = 1 Breakpoint 1, main () at main.c:7 7 int b = i; // we want to print this value each time gdb hits the line $3 = 2 ... ...
June 11th, 2013 in
main entries