Oracle® Solaris Studio 12.4: Debugging a Program With dbx

Exit Print View

Updated: January 2015
 
 

Setting Data Change Breakpoints (Watchpoints)

You can use data change breakpoints, otherwise known as watchpoints, in dbx to note when the value of a variable or expression has changed.

Stopping Execution When an Address Is Accessed

Use the stop access command to stop execution when a memory address has been accessed:

(dbx) stop access mode address-expression [, byte-size-expression]

mode specifies how the memory was accessed. The valid mode options are:

r

The memory at the specified address has been read.

w

The memory has been written to.

x

The memory has been executed.

mode can also contain either of the following:

a

Stops the process after the access (default).

b

Stops the process before the access.

In both cases the program counter will point at the accessing instruction. The “before” and “after” refer to the side effect.

address-expression is any expression that can be evaluated to produce an address. If you provide a symbolic expression, the size of the region to be watched is automatically deduced. You can override it by specifying byte-size-expression. You can also use nonsymbolic, typeless address expressions in which case, the size is mandatory.

In the following example, the command will stop execution after any of the four bytes after the memory address 0x4762 has been read.

(dbx) stop access r 0x4762, 4

In the following example, execution will stop before the variable speed has be written to:

(dbx) stop access wb &speed

    Keep these points in mind when using the stop access command:

  • The event occurs when a variable is written to even if it is the same value.

  • By default, the event occurs after execution of the instruction that wrote to the variable. You can indicate that you want the event to occur before the instruction is executed by specifying the mode as b.

For more information on specifying an access event, see access Event Specification and stop Command.

Stopping Execution When Variables Change

Use the stop change command to stop program execution if the value of a specified variable has changed:

(dbx) stop change variable

    Keep these points in mind when using the stop change command:

  • dbx stops the program at the line after the line that caused a change in the value of the specified variable.

  • If variable is local to a function, the variable is considered to have changed when the function is first entered and storage for variable is allocated. The same is true with respect to parameters.

  • The command does not work with multithreaded applications.

For more information on specifying a change event, see change Event Specification and stop Command.

dbx implements stop change by causing automatic single-stepping together with a check on the value at each step. Stepping skips over library calls if the library was not compiled with the -g option. So, if control flows in the following manner, dbx does not trace the nested user_routine2 because tracing skips the library call and the nested call to user_routine2.

   user_routine calls
      library_routine, which calls
        user_routine2, which changes variable

The change in the value of variable appears to have occurred after the return from the library call, not in the middle of user_routine2.

dbx cannot set a breakpoint for a change in a block local variable (a variable nested in {}). If you try to set a breakpoint or trace in a block local nested variable, dbx issues an error informing you that it cannot perform this operation.


Note -  Watching data changes is faster using the access event than the change event. Instead of automatically single-stepping the program, the access event uses hardware or OS services that are much faster.

Stopping Execution on a Condition

Use thestop cond command to stop program execution if a conditional statement evaluates to true:

(dbx) stop cond condition

The program stops executing when the condition occurs.

    Keep these points in mind when using the stop cond command:

  • dbx stops the program at the line after the line that caused the condition to evaluate to true.

  • The command does not work with multithreaded applications.

For more information about specifying a condition event, see cond Event Specification and stop Command.