HP gnu source-level debugger 5992-4701 manual Stops your program only if the value

Models: gnu source-level debugger 5992-4701

1 369
Download 369 pages 58.54 Kb
Page 60
Image 60

say, to just set a watchpoint on a variable name, and specify a condition that tests whether the new value is an interesting one.

Break conditions can have side effects, and may even call functions in your program. This can be useful, for example, to activate functions that log program progress, or to use your own print functions to format special data structures. The effects are completely predictable unless there is another enabled breakpoint at the same address. (In that case, GDB might see the other breakpoint first and stop your program without checking the condition of this one.) Note that breakpoint commands are usually more convenient and flexible than break conditions for the purpose of performing side effects when a breakpoint is reached (see “Breakpoint command lists” (page 61)).

Break conditions can be specified when a breakpoint is set, by using 'if' in the arguments to the break command. See “Setting breakpoints” (page 52). They can also be changed at any time with the condition command.

You can also use the if keyword with the watch command. The catch command does not recognize the if keyword; condition is the only way to impose a further condition on a catchpoint.

condition bnum expression

Specify expression as the break condition for

 

breakpoint, watchpoint, or catchpoint number

 

bnum. After you set a condition, breakpoint bnum

 

stops your program only if the value of

 

expression is true (nonzero, in C). When you

 

use condition, GDB checks expression

 

immediately for syntactic correctness, and to

 

determine whether symbols in it have referents

 

in the context of your breakpoint. If expression

 

uses symbols not referenced in the context of the

 

breakpoint, GDB prints an error message:

 

No symbol "foo" in current context.

 

GDB does not actually evaluate expression at the

 

time the condition command (or a command

 

that sets a breakpoint with a condition, like break

 

if ...) is given, however. See “Expressions”

 

(page 83).

condition bnum

Remove the condition from breakpoint number

 

bnum. It becomes an ordinary unconditional

 

breakpoint.

A special case of a breakpoint condition is to stop only when the breakpoint has been reached a certain number of times. This is so useful that there is a special way to do it, using the ignore count of the breakpoint. Every breakpoint has an ignore count, which is an integer. Most of the time, the ignore count is zero, and therefore has no effect. But if your program reaches a breakpoint whose ignore count is positive, then

60 Stopping and Continuing

Page 60
Image 60
HP gnu source-level debugger 5992-4701 manual Stops your program only if the value, Use condition, GDB checks expression