3.3 Using Debugger commands

3.3.5 Examining and modifying local variables

You can inspect, modify, and print variables that are bound locally within the function that you are debugging. The following commands examine and modify local variables:

The following example defines a function namedsample-function that makes a call to the functionerror when the sum of its two arguments is less than or equal to 15:

> (defun sample-function (x y)
    (if (> (+ x y) 15)
        (+ x y)
        (error "The sum of x and y must be greater than 15")))
SAMPLE-FUNCTION

If you call the function with arguments whose sum is less than or equal to 15, an error is signaled and you enter the Debugger:

> (sample-function 3 6)
>>Error: The sum of x and y must be greater than 15
SAMPLE-FUNCTION:
Original code: (NAMED-LAMBDA SAMPLE-FUNCTION (X Y) 
(BLOCK SAMPLE-FUNCTION (IF # # #)))
   Required arg 0 (X): 3
   Required arg 1 (Y): 6
:A  0: Abort to Lisp Top Level
-> 

You can use either of the commands:i or:l to examine the values of the local variables. The command:i invokes the Inspector on a specified variable. The Inspector allows you to examine a data structure; it is fully described in Chapter 4, "Debugging Tools". The command:q exits the Inspector and returns you to the Debugger.

The command:l prints the current value of a specified variable. You can select a variable by using its index number, which is shown in the Debugger display.

For interpreted functions or for functions that have been compiled in the development mode of the Compiler, you can also select a variable by using its name.

To print the current values of the variablesx andy, use the:l command. Becausesample-function is an interpreted function, you can select a local variable either by name or by number, as follows:

-> :l 0
3
-> y
6
-> (+ x y)
9
-> 

To change the values of the arguments, use the:s command. This command allows you to specify both an expression to be evaluated and a local variable in which the result of the evaluation is stored. The following example assignsx the lexical value 12 and assignsy the lexical value 8:

-> :s 0 12
-> (setq y 8)
8
-> (+ x y)
20
-> 

Note that when these new values are established by the:s command, the prompt for the current Debugger level reappears without a value being returned by Lisp.

Redisplay the current frame by using the:d command to show the new values that have been established forx andy:

-> :d
>>Error: The sum of x and y must be greater than 15
SAMPLE-FUNCTION:
Original code: (NAMED-LAMBDA SAMPLE-FUNCTION (X Y) 
(BLOCK SAMPLE-FUNCTION (IF # # #)))
   Required arg 0 (X): 12
   Required arg 1 (Y): 8
:A  0: Abort to Lisp Top Level
-> 
To reexecute the current frame and continue the evaluation, use the:f command. This command displays the proposed evaluation and prompts for confirmation. After you confirm the evaluation,sample-function is reexecuted with the new values forx andy, and a value is returned.

-> :f
Re-executing (SAMPLE-FUNCTION 12 8), OK? (Y or N): y
20
> 


The User's Guide - 9 SEP 1996

Generated with Harlequin WebMaker