8.5 Debugger commands

8.5.7 An example debugging session

To better understand how the debugger may be used in the debugging of your programs, try working through the following example session. If you have been testing the keywords described above, you should exit the debugger to return to the top level of the listener.

Firstly, define a routine which calculates factorial numbers, and then call it erroneously with a string argument.

CL-USER 1 > (defun fac (m)
              (if (= n 1) 1
                (* n (fac (- n 1)))))
FAC

CL-USER 2 > (fac "turtle")

Error: Arithmetic-error in = of ("turtle" 1): Arguments must be real numbers
  1 (abort) return to level 0.
  2 return to top loop level 0.

Type :c followed by a number to proceed

The environment notices the error: the arguments of = should be numbers, and one of them is not.

You are presented with several continuation options, to help you try to find out how the problem arose. Ask for a quick backtrace, and then investigate a smaller section in more detail. You will finally locate the problem to the call to fac. Note that the calls to *%apply-interpreted-function in the backtrace occur because fac is being interpreted.

CL-USER 3 : 1 > :bq

INVOKE-DEBUGGER <- NUMBERS::NUMERIC-ARG-ERROR <- = 
<- FAC <- CCL::DO-EVALUATION <- CCL:%TOP-LEVEL 
<- CCL::LISTENER-TOP-LEVEL 
<- LISPWORKS-TOOLS::RUN-LISTENER-TOP-LEVEL 
<- LISPWORKS-TOOLS::START-LISPWORKS-TOOLS-WITH-HANDLER 
<- COMMON-LISP::MAIN 
<- COMMON-LISP::FUNCALL-SETTING-MSW-REGS 
<- MEMORY-MANAGER::INIT-WORLD

CL-USER 4 : 1 > 

Next, make the call to fac the current frame and display the information in that stack frame

CL-USER 4 : 1 > :n fac
Interpreted call to FAC

CL-USER 5 : 1 > :v
Interpreted call to FAC:
 .. Var 0 (N): "turtle"

CL-USER 6 : 1 >

fac has been called with an argument which was a string, and immediately followed with a call to the function =, which insists on numeric arguments.

You wanted to call fac with the length of the string, not the string itself, so quit the debugger, and call fac again with a new argument, but this time type the word length incorrectly.

CL-USER 4 : 1 > :a

CL-USER 5 > (fac (legnth "turtle"))

Error: the function LEGNTH applied to arguments ("turtle") is undefined.
  1  (continue) Try calling LEGNTH again
  2  Return a value from the call to LEGNTH
  3  Try calling a different function instead of LEGNTH with the same arguments
  4  Set the symbol-function of LEGNTH to another function
  5  (abort) return to level 0.
  6  return to top level loop 0.

Type :c followed by a number to proceed

CL-USER 6 : 1 > 

You can spot immediately what has gone wrong here, so just return a value to use.

CL-USER 6 : 1 > :c 2 type a form to be evaluated: 6 720 CL-USER 7 >

Having returned the correct value from (length "turtle"), fac is called with the correct argument and returns the value 720.


FreeLisp User's Guide - 5 FEB 1996

Generated with Harlequin WebMaker