while (…) { Read the next line of the program Is there a breakpoint on this line? Yes, stop and print a prompt Execute this instruction }
gcc -c -g program.c gcc program.o -o program
$ gdb GNU gdb 6.3.50-20050815 (Apple version gdb-573) (Fri Oct 20 15:54:33 GMT 2006) Copyright 2004 Free Software Foundation, Inc. GDB is free software, covered by the GNU General Public License, and you are welcome to change it and/or distribute copies of it under certain conditions. Type "show copying" to see the conditions. There is absolutely no warranty for GDB. Type "show warranty" for details. This GDB was configured as "powerpc-apple-darwin". (gdb)
(gdb) break main Breakpoint 1 at 0x229c (gdb) run Starting program: program Breakpoint 1, 0x229c in main () (gdb)
$ program < test-input
$ gdb program < test-input
$ gdb program (gdb) run < test-input
$ program Segmentation fault (core dumped) $ gdb program core
1: main() { 2: int i; 3: i = 2; 4: func(4); 5: } 6: 7: func (int i) { 8: … 9: } |
(gdb) backtrace #0 func (i=4) at main.c:8 #1 0x22b0 in main() at main.c:4 (gdb) print i 4 (gdb) frame 1 #1 0x22b0 in main () at main.c:4 (gdb) print i 2 |
list filename:number list number — list specified line in current file