Go to main content
Oracle® Developer Studio 12.5: Debugging a Program with dbx

Exit Print View

Updated: June 2016

Navigating To Code

Each time the program you are debugging stops, dbx prints the source line associated with the stop location. At each program stop, dbx resets the value of the current function to the function in which the program is stopped. Before the program starts running and when it is stopped, you can move to, or navigate through, functions and files 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 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 more information, see Setting a Breakpoint at a Line of Source Code.

Navigating To Functions

You can use the func command 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

When 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”t.cc”C::foo(int)
 2) ”a.out”t.cc”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. The default is 10 lines. Once you navigate through a function, the list command prints its lines.

For detailed information, 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 that 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 see Walking the Stack and Returning Home.