|Debugging with GDB|
The simplest sort of tracepoint collects data every time your program reaches a specified place. You can also specify a condition for a tracepoint. A condition is just a Boolean expression in your programming language (see Expressions). A tracepoint with a condition evaluates the expression each time your program reaches it, and data collection happens only if the condition is true.
Tracepoint conditions can be specified when a tracepoint is set, by
using ‘if’ in the arguments to the
See Setting Tracepoints. They can
also be set or changed at any time with the
just as with breakpoints.
Unlike breakpoint conditions, gdb does not actually evaluate the conditional expression itself. Instead, gdb encodes the expression into an agent expression (see Agent Expressions) suitable for execution on the target, independently of gdb. Global variables become raw memory locations, locals become stack accesses, and so forth.
For instance, suppose you have a function that is usually called frequently, but should not be called after an error has occurred. You could use the following tracepoint command to collect data about calls of that function that happen while the error code is propagating through the program; an unconditional tracepoint could end up collecting thousands of useless trace frames that you would have to search through.
(gdb) trace normal_operation if errcode > 0