Debugging a Program With dbx

Setting Breakpoint Filters

In dbx, most of the event management commands also support an optional event filter modifier statement. The simplest filter instructs dbx to test for a condition after the program arrives at a breakpoint or trace handler, or after a watch condition occurs.

If this filter condition evaluates to true (non 0), the event command applies. If the condition evaluates to false (0), dbx continues program execution as if the event never happened.

To set a breakpoint at a line or in a function that includes a conditional filter, add an optional -if condition modifier statement to the end of a stop or trace command.

The condition can be any valid expression, including function calls, returning Boolean or integer in the language current at the time the command is entered.


Note -

With location-based breakpoints like in or at, the scope is that of the breakpoint location. Otherwise, the scope of the condition is the scope at the time of entry, not at the time of the event. You may have to use syntax to specify the scope precisely.


These two filters are not the same:


stop in foo -if a>5
stop cond a>5

The former will breakpoint at foo and test the condition. The latter automatically single-steps and tests for the condition.

This point is emphasized because new users sometimes confuse setting a conditional event command (a watch-type command) with using filters. Conceptually, "watching" creates a precondition that must be checked before each line of code executes (within the scope of the watch). But even a breakpoint command with a conditional trigger can also have a filter attached to it.

Consider this example:


(dbx) stop modify &speed -if speed==fast_enough

This command instructs dbx to monitor the variable, speed; if the variable speed is written to (the "watch" part), then the -if filter goes into effect. dbx checks to see if the new value of speed is equal to fast_enough. If it is not, the program continues on, "ignoring" the stop.

In dbx syntax, the filter is represented in the form of an [-if condition] statement at the end of the formula:


stop in function [-if condition
]