Sun Studio 12 Update 1: Debugging a Program With dbx

Navigating To Code

When a program is stopped, you can navigate to code elsewhere in the program. You can navigate to any function or file that is part of the program. Navigating sets the current scope (see Program Scope). It is useful for determining when and at what source line you want to set a stop at breakpoint.

Navigating To a File

You can navigate to any file dbx recognizes as part of the program (even if a module or file was not compiled with the -g option). To navigate to a file:

(dbx) file filename

Using the file command without arguments echoes the file name of the file you are currently navigating.

(dbx) file

dbx displays the file from its first line unless you specify a line number.

(dbx) file filename ; list line_number

For information on setting a stop at breakpoint at a line of source code, see Setting a stop Breakpoint at a Line of Source Code.

Navigating To Functions

You can use the func command to navigate to a function. To navigate to a function, type the command func followed by the function name. For example:

(dbx) func adjust_speed

The func command by itself echoes the current function.

For more information, see func Command

Selecting From a List of C++ Ambiguous Function Names

If you try to navigate to a C++ member function with an ambiguous name or an overloaded function name, a list is displayed, showing all functions with the overloaded name. Type the number of the function you want to navigate. If you know which specific class a function belongs to, you can type the class name and function name. For example:

(dbx) func block::block

Choosing Among Multiple Occurrences

If multiple symbols are accessible from the same scope level, dbx prints a message reporting the ambiguity.

(dbx) func main
(dbx) which C::foo
More than one identifier ’foo’.
Select one of the following:
 0) Cancel
 1) ”a.out””C::foo(int)
 2) ”a.out””C::foo()

In the context of the which command, choosing from the list of occurrences does not affect the state of dbx or the program. Whichever occurrence you choose, dbx echoes the name.

Printing a Source Listing

Use the list command to print the source listing for a file or function. Once you navigate through a file, the list command prints number lines from the top. Once you navigate through a function, the list command prints its lines.

For detailed information on the list command, see list Command.

Walking the Call Stack to Navigate To Code

Another way to navigate to code when a live process exists is to “walk the call stack,” using the stack commands to view functions currently on the call stack, which represent all currently active routines. Walking the stack causes the current function and file to change each time you display a stack function. The stop location is considered to be at the “bottom” of the stack, so to move away from it, use the up command, that is, move toward the main or begin function. Use the down command to move toward the current frame.

For more information on walking the call stack, see Walking the Stack and Returning Home.