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

Exit Print View

Updated: June 2016

Program Scope

A scope is a subset of the program defined in terms of the visibility of a variable or function. A symbol is said to be “in scope” if its name is visible at a given point of execution. In C, functions can have global or file-static scope; variables can have global, file-static, function, or block scope.

Variables That Reflect the Current Scope

The following variables always reflect the current program counter of the current thread or LWP, and are not affected by the various commands that change the visiting scope:


Scope of the current program counter


Current line number


Current function


Class to which $func belongs


Current source file


Current load object

These variables are only useful during a live process.

Visiting Scope

When you inspect various elements of your program with dbx, you modify the visiting scope. dbx uses the visiting scope during expression evaluation for purposes such as resolving ambiguous symbols. For example, if you type the following command, dbx uses the visiting scope to determine which i to print:

(dbx) print i

Each thread or LWP has its own visiting scope. When you switch between threads, each thread returns its visiting scope.

Components of the Visiting Scope

Some of the components of the visiting scope are visible in the following predefined ksh variables:


Current visiting scope


Current visiting load object


Current visiting file


Current visiting line number


Class to which $vfunc belongs


Current visiting function

All of the components of the current visiting scope stay compatible with one another. For example, if you visit a file that contains no functions, the current visiting source file is updated to the new file name and the current visiting function is updated to NULL.

Changing the Visiting Scope

    The following commands are the most common ways of changing the visiting scope:

  • func

  • file

  • up

  • down

  • frame number

  • pop

  • list procedure

The debug command and the attach command set the initial visiting scope.

When you hit a breakpoint, dbx sets the visiting scope to the current location. If the stack-find-source environment variable set to on, dbx attempts to find and make active a stack frame that has source code.

When you use the up command, the down command, the frame command, or the pop command to change the current stack frame, dbx sets the visiting scope according to the program counter from the new stack frame.

The line number location used by the list command changes the visiting scope only if you use the list command. When the visiting scope is set, the line number location for the list command is set to the first line number of the visiting scope. When you subsequently use the list command, the current line number location for the list command is updated, but as long as you are listing lines in the current file, the visiting scope does not change. For example, the following command causes dbx to list the start of the source for my-func and change the visiting scope to my-func.

(dbx) list my-func

The following command causes dbx to list line 127 in the current source file and does not change the visiting scope.

(dbx) list 127

When you use the file command or the func command to change the current file or the current function, the visiting scope is updated accordingly.