JavaScript is required to for searching.
Skip Navigation Links
Exit Print View
Oracle Solaris Studio 12.3: Debugging a Program With dbx     Oracle Solaris Studio 12.3 Information Library
search filter icon
search icon

Document Information


1.  Getting Started With dbx

2.  Starting dbx

3.  Customizing dbx

4.  Viewing and Navigating To Code

5.  Controlling Program Execution

6.  Setting Breakpoints and Traces

7.  Using the Call Stack

8.  Evaluating and Displaying Data

9.  Using Runtime Checking

10.  Fixing and Continuing

11.  Debugging Multithreaded Applications

12.  Debugging Child Processes

13.  Debugging OpenMP Programs

14.  Working With Signals

15.  Debugging C++ With dbx

16.  Debugging Fortran Using dbx

17.  Debugging a Java Application With dbx

18.  Debugging at the Machine-Instruction Level

19.  Using dbx With the Korn Shell

20.  Debugging Shared Libraries

A.  Modifying a Program State

B.  Event Management

Event Handlers

Event Safety

Creating Event Handlers

Manipulating Event Handlers

Using Event Counters

Setting Event Specifications

Breakpoint Event Specifications

in function

at [filename:]line_number

at address_expression

infile filename

infunction function

inmember function inmethod function

inclass classname [-recurse | -norecurse]

inobject object-expression [-recurse | -norecurse]

Data Change Event Specifications

access mode address-expression [, byte-size-expression]

change variable

cond condition-expression

System Event Specifications

dlopen [ lib-path ] dlclose [ lib-path ]

fault fault


sig signal

sig signal sub-code

sysin code | name

sysout code | name

sysin | sysout

Execution Progress Event Specifications

exit exitcode



returns function


Other Event Specifications









thr_create [thread_id]



throw type

throw -unhandled

throw -unexpected

timer seconds

Event Specification Modifiers

-if condition


-in function


-count n-count infinity



-thread thread_id

-lwp lwp_id



Parsing and Ambiguity

Using Predefined Variables

Variables Valid for when Command


Variables Valid for when Command and Specific Events

Event Handler Examples

Setting a Breakpoint for Store to an Array Member

Implementing a Simple Trace

Enabling a Handler While Within a Function (in function)

Determining the Number of Lines Executed

Determining the Number of Instructions Executed by a Source Line

Enabling a Breakpoint After an Event Occurs

Resetting Application Files for replay

Checking Program Status

Catch Floating Point Exceptions

C.  Macros

D.  Command Reference


Event Handler Examples

The following are some examples of setting event handlers.

Setting a Breakpoint for Store to an Array Member

To set a data change breakpoint on array[99], type:

(dbx) stop access w &array[99]
(2) stop access w &array[99], 4
(dbx) run
Running: watch.x2
watchpoint array[99] (0x2ca88[4]) at line 22 in file "watch.c"    
   22    array[i] = i;

Implementing a Simple Trace

To implement a simple trace, type:

(dbx) when step { echo at line $lineno; }

Enabling a Handler While Within a Function (in function)

To enable a handler while within a function, type:

<dbx> trace step -in foo

This is equivalent to:

    # create handler in disabled state
    when step -disable { echo Stepped to $line; }
    t=$newhandlerid    # remember handler id
    when in foo {
    # when entered foo enable the trace
    handler -enable "$t"
    # arrange so that upon returning from foo,
    # the trace is disabled.
    when returns { handler -disable "$t"; };

Determining the Number of Lines Executed

To see how many lines have been executed in a small program, type:

(dbx) stop step -count infinity     # step and stop when count=inf
(2) stop step -count 0/infinity
(dbx) run
(dbx) status
(2) stop step -count 133/infinity

The program never stops, the program terminates. The number of lines executed is 133. This process is very slow. It is most useful with breakpoints on functions that are called many times.

Determining the Number of Instructions Executed by a Source Line

To count how many instructions a line of code executes, type:

(dbx) ...                        # get to the line in question
(dbx) stop step -instr -count infinity
(dbx) step ...
(dbx) status
(3) stop step -count 48/infinity # 48 instructions were executed

If the line you are stepping over makes a function call, the lines in the function are counted as well. You can use the next event instead of step to count instructions, excluding called functions.

Enabling a Breakpoint After an Event Occurs

Enable a breakpoint only after another event has occurred. For example, if your program begins to execute incorrectly in function hash, but only after the 1300’th symbol lookup, you would type:

(dbx) when in lookup -count 1300 {
    stop in hash
    when proc_gone -temp { delete $hash_bpt; }

Note - $newhandlerid is referring to the just executed stop incommand.

Resetting Application Files for replay

If your application processes files that need to be reset during a replay, you can write a handler to do that each time you run the program:

(dbx) when sync { sh regen ./database; }
(dbx) run < ./database... # during which database gets clobbered
(dbx) save
...              # implies a RUN, which implies the SYNC event which
(dbx) restore # causes regen to run

Checking Program Status

To see quickly where the program is while it is running, type:

(dbx) ignore sigint
(dbx) when sig sigint { where; cancel; }

Then type ^C to see a stack trace of the program without stopping it.

This is basically what the collector hand sample mode does (and more). Use SIGQUIT (^\) to interrupt the program because ^C is now used up.

Catch Floating Point Exceptions

To catch only specific floating point exceptions, for example, IEEE underflow, type:

(dbx) ignore FPE               # turn off default handler
(dbx) help signals | grep FPE  # can’t remember the subcode name
(dbx) stop sig fpe FPE_FLTUND