Debug Tutorial: How to Set a Breakpoint
Command syntax:
stop [ context ] [ in | at ]
{ line_num | procedure }
[ ,count | if condition ]
stop [ context ] { rw | w }
{ expression | data_address }
[ ,count | if condition ]
stopi [ context ] [ at ] text_address
[ ,count | if condition ]
trace [ context ] [ in | at ]
{ line_num | procedure }
[ ,count | if condition ]
tracei [ context ] [ at ] text_address
[ ,count | if condition ]
delete [ context ] { all | bkpt_num }
status [ context ] [ >filename ]
Breakpoints force execution of a program to stop at points of interest to allow
examination of data, registers, stack, and message queues.
A code breakpoint
is placed on an instruction address. Execution is stopped before that
instruction is executed. A data breakpoint, which is referred to here as
a watchpoint, is placed on a data address. In this case, execution stops
after that address has been accessed.
- stop followed by a line number sets a code breakpoint at the
start of that source line. Note: Do not set a breakpoint on a loop statement
and expect it to be hit while the loop is executed. Specify the first line
within the loop instead.
- stop followed by a procedure name sets a code breakpoint after
the preamble of that procedure. Procedure parameters are therefore defined
when execution stops. An attempt to set a breakpoint at the line number
that corresponds to this location will fail.
- stop with a -rw or -w switch sets a watchpoint on
the variable or address specified. The size of a watchpoint object is currently
always assumed to be 4 bytes.
Note: The process command's location field indicates the next
instruction to be executed. Thus, watchpoints which fire at the very end of
a source line will appear with the line number of the next source line to be
executed rather than the source line on which the watchpoint occurred.
- Watchpoints are set using hardware registers which makes them fast, but
limits their number to 4.
- ,count or if condition can be specified to delay
the reported occurrence of a breakpoint or watchpoint until the condition is
met. The count option results in the breakpoint or watchpoint being reported
after every count times it is encountered. A condition is a
simple expression that evaluates to True (non-zero) or False (0). The breakpoint
or watchpoint is only reported when the condition evaluates to True. A
condition consists of equivalence operators and logical operators.
The syntax used must be the same as that of the program under debug,
e.g. > for C and .GT. for Fortran.
- stopi sets a code breakpoint on an instruction address.
- trace and tracei are similar to code breakpoints. When they
are encountered a message is printed and execution continues.
- delete removes breakpoints, watchpoints, and tracepoints.
- status lists breakpoints, watchpoints, and tracepoints along with
their associated number. If the redirection option is specified (>) a file
containing these breakpoints, watchpoints, and tracepoints is created. They
are written to the file in the form of debug commands suitable for use as
a startup file or source command input file.
Examples:
(0) > stop 10
(0) > stop one
(0) > stop 25,2
(0) > stop -rw myvar if myvar < 0
(0) > stop -w one`i
(0) > status
( 1) stop at line 10:hello.c:one():(0)
( 2) stop in one():hello.c:one():(0)
( 3) stop at line 25:hello.c:main():(0)
( 4) stop if access myvar:::(0)
( 5) stop if write i:hello.c:one():(0)
(0) > delete all