Debugging a Program With dbx

Visiting Code

You can visit code elsewhere in the program any time the program is not running. You can visit any function or file that is part of the program.

Visiting a File

You can visit any file dbx recognizes as part of the program (even if a module or file was not compiled with the -g option.) Visiting a file does not change the current function. To visit a file:


pathmap [-c] filename

Using the file command by itself echoes the file you are currently visiting:


file

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


file filename ; list line_number

Visiting Functions

You can use the func command to visit a function. To visit a function, type the command func followed by the function name. The func command by itself echoes the currently visited function. For example:


(dbx) func adjust_speed

Selecting from a List of C++ Ambiguous Function Names

If you try to visit a C++ member function with an ambiguous name or an overloaded function name, a list is displayed, showing all functions with the overloaded name.

If the specified function is ambiguous, type the number of the function you want to visit. If you know which specific class a function belong to, you can type:


(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 block::block
Class block has more than one function member named block.

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 merely echoes the name.

Remember that the which command tells you which symbol dbx would pick. In the case of ambiguous names, the overload display list indicates that dbx does not yet know which occurrence of two or more names it would use. dbx lists the possibilities and waits for you to choose one.

Printing a Source Listing

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


list [-i | -instr] [+] [-] number
 [ function | filename
 ]

Walking the Call Stack to Visit Code

Another way to visit code when a live process exists is to "walk the call stack," using the stack commands to view functions currently on the stack.

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.