Debugging a Program With dbx

Creating Event Handlers

The commands when, stop, and trace are used to create event handlers. An event-spec is a specification of an event as documented later in this chapter.

Every command returns a number known as a handler id (hid). This number can be accessed via the predefined variable $newhandlerid.

An attempt has been made to make the stop and when commands conform to the handler model. However, backward compatibility with previous dbx releases forces some deviations.

For example, the following samples from an earlier dbx release are equivalent.

Old 

New 

when cond body

when step -if cond body

when cond in func body

when next -if cond -in func body

These samples illustrate that cond is not a pure event; there is no internal handler for conditions.

when

When the event specified by the when command specified event occurs, the cmds are executed. Once the commands have all executed, the process is automatically continued.


when event-specification [ modifier 
] { cmds ... ; 
}

stop

When the event specified by the stop command occurs, the process is stopped.


stop event-specification
 [ modifier]

stop is shorthand for a common when idiom:


when event-specification { stop -update;
whereami; }

trace

When the event specified by the trace command oc


trace event-specification

curs, a trace message is printed:

Most of the trace commands can be hand-crafted by using the when command, ksh functionality, and event variables. This is especially useful if you want stylized tracing output.