Noeud:Taking Control of the Running Program - Breakpoints, Noeud « Next »:One Step at a Time - Step+Next, Noeud « Previous »:Running the Executable, Noeud « Up »:An example debugging session using gdb
Breakpoints are special markers the debugger uses to tell it where to stop. When a breakpoint is set on a particular line of code, then the program is allowed to run at normal speed until it reaches that line, then it is stopped and the debugger takes over. It puts up the prompt and allows you to control the program however you like.
Since this program is so short, we will place a breakpoint on the main()
function, so we take control as soon as the program starts.
gdb
understands a number of ways to specify where to place a breakpoint, such as a line number, or a function name, or a certain number of lines forwards or backwards from the current position. We want to stop on entry to main
so we'll use break main
.
(gdb) break main Breakpoint 1 at 0x8048496: file ecount1.c, line 13. (gdb) run example Starting program: /home/paul/gnuprog2/src/debugging/ecount1 example Breakpoint 1, main (argc=2, argv=0xbffff914) at ecount1.c:13 13 char *buf=NULL; (gdb)
gdb
is now stopped at the beginning of main waiting for us to tell it what to do.Notice that the breakpoint was actually set at line 13, which is the first line of actual code in the program. gdb
cannot set a breakpoint on lines where nothing is actually executed (comments, function declarations etc.). If you ask it to, then it will place it at the next available location.