Variable Access - SBCL 1.0.31 User Manual
Description: SBCL 1.0.31 User Manual

Next: Source Location Printing, Previous: Stack Frames, Up: Debugger

### 5.4 Variable Access

There are two ways to access the current frame's local variables in the debugger: `list-locals` and `sb-debug:var`.

The debugger doesn't really understand lexical scoping; it has just one namespace for all the variables in the current stack frame. If a symbol is the name of multiple variables in the same function, then the reference appears ambiguous, even though lexical scoping specifies which value is visible at any given source location. If the scopes of the two variables are not nested, then the debugger can resolve the ambiguity by observing that only one variable is accessible.

When there are ambiguous variables, the evaluator assigns each one a small integer identifier. The `sb-debug:var` function uses this identifier to distinguish between ambiguous variables. The `list-locals` command prints the identifier. In the following example, there are two variables named `X`. The first one has identifier 0 (which is not printed), the second one has identifier 1.

         X  =  1
         X#1  =  2

— Debugger Command: list-locals [prefix]

> This command prints the name and value of all variables in the current frame whose name has the specified prefix. prefix may be a string or a symbol. If no prefix is given, then all available variables are printed. If a variable has a potentially ambiguous name, then the name is printed with a “`#`identifier” suffix, where identifier is the small integer used to make the name unique.

— Function: sb-debug:var name &optional identifier

> This function returns the value of the variable in the current frame with the specified name. If supplied, identifier determines which value to return when there are ambiguous variables.

> When name is a symbol, it is interpreted as the symbol name of the variable, i.e. the package is significant. If name is an uninterned symbol (gensym), then return the value of the uninterned variable with the same name. If name is a string, `sb-debug:var` interprets it as the prefix of a variable name that must unambiguously complete to the name of a valid variable.

> identifier is used to disambiguate the variable name; use `list-locals` to find out the identifiers.