Debugging a Program With dbx

Qualifying Symbols with Scope Resolution Operators

When using func or file, you may need to use scope resolution operators to qualify the names of the functions that you give as targets.

dbx provides three scope resolution operators with which to qualify symbols: the backquote operator (`), the C++ double colon operator (::), and the block local operator (:lineno). You use them separately, or in some cases, together.

In addition to qualifying file and function names when visiting code, symbol name qualifying is also necessary for printing and displaying out-of-scope variables and expressions, and for displaying type and class declarations (whatis command). The symbol qualifying rules are the same in all cases; this section covers the rules for all types of symbol name qualifying.

Backquote Operator

The backquote character(`) can be used to find a variable of global scope:


(dbx) print `item

A program may use the same function name in two different files (or compilation modules). In this case, you must also qualify the function name to dbx so that it knows which function you mean to visit. To qualify a function name with respect to its filename, use the general purpose backquote (`) scope resolution operator:


(dbx) func `file_name`function_name

C++ Double Colon Scope Resolution Operator

Use the double colon operator (::) to qualify a C++ member function or top level function with:

You may want to qualify an overloaded function name. If you do not qualify it, dbx pops up an overload display list for you to choose which function you mean to visit. If you know the function class name, you can use it with the double colon scope resolution operator to qualify the name.


(dbx) func class::function_name
 (args)

For example, if hand is the class name and draw is the function name:


(dbx) func hand::draw

Block Local Operator

The block local operator (:lineno) is used in conjunction with the backquote operator. It identifies the line number of an expression that references the instance you're interested in.

In the following example, :230 is the block local operator:


(dbx) stop in `animate.o`change_glyph:230`item

Linker Names

dbx provides a special syntax for looking up symbols by their linker names (mangled names in C++). You prefix the symbol name with a # (pound sign) character (use the ksh escape character \ (backslash) before any $ (dollar sign) characters), as in these examples:


(dbx) stop in #.mul
(dbx) whatis #\$FEcopyPc
(dbx) print `foo.c`#staticvar

Scope Resolution Search Path

When you issue a debugging command with a symbol target name, the search order is as follows:

  1. dbx first searches within the scope of the current function. If the program is stopped in a nested block, dbx searches within that block, then in the scope of all enclosing blocks.

  2. For C++ only: class members of the current function`s class and its base class.

  3. The immediately enclosing "compilation unit," generally, the file containing the current function.

  4. The LoadObject scope.

  5. The global scope.

  6. If none of the above searches are successful, dbx assumes you are referencing a private, or file static, variable or function. dbx optionally searches for a file static symbol in every compilation unit depending on the value of the dbxenv setting scope_look_aside.

dbx uses whichever occurrence of the symbol it first finds along this search path. If dbx cannot find a variable, it reports an error.