| An Introduction to GCC - for the GNU compilers gcc and g++ by Brian J. Gough, foreword by Richard M. Stallman Paperback (6"x9"), 144 pages ISBN 0954161793 RRP £12.95 ($19.95) "An excellent introduction... fills a much-needed niche in the marketplace" --- Association of C and C++ Users book review (Issue 16-4, August 2004) Get a printed copy>>> |
5.3 Setting a breakpoint
A breakpoint stops the execution of a program and returns control
to the debugger, where its variables and memory can be examined before
continuing. Breakpoints can be set for specific functions, lines or
memory locations with the break command.
To set a breakpoint on a specific function, use the command break
function-name. For example, the following command sets a
breakpoint at the start of the main function in the program
above:
$ gdb a.out (gdb) break main Breakpoint 1 at 0x80483c6: file null.c, line 6.
The debugger will now take control of the program when the function
main is called. Since the main function is the first
function to be executed in a C program the program will stop immediately
when it is run:
(gdb) run Starting program: a.out Breakpoint 1, main () at null.c:6 6 int *p = 0; /* null pointer */ (gdb)
The display shows the line that will be executed next (the line number
is shown on the left). The breakpoint stops the program before
the line is executed, so at this stage the pointer p is
undefined and has not yet been set to zero.
| ISBN 0954161793 | An Introduction to GCC - for the GNU compilers gcc and g++ | See the print edition |