How do I debug/trace all function calls line-by-line ( rather function
call by function call) in Steel Bank Common Lisp
> How do I debug/trace all function calls line-by-line ( rather function
> call by function call) in Steel Bank Common Lisp
Perhaps this what you're looking for:
<http://www.sbcl.org/manual/Single-Stepping.html>
--
Luís Oliveira
http://student.dei.uc.pt/~lmoliv/
In addition to the answer from Luis, there are a few things that a
different in 'Lisp' that make stepping a bit difficult.
a) there are no lines in source code, not really. Lisp uses the
function (READ) to read an s-expression and it returns a Lisp data
structure and this does not include any line numbers. A compiler may
or may not record line information for COMPILE-FILE. Additionally
parts of the code might not come from line-oriented input. For example
a macro generates code, but the generated code is just data. Another
option is that parts of the code were typed at the REPL.
b) Common Lisp is often compiled. The usual default is that most
source informations (minus variable names, argument lists, ...) are
gone in compiled code. So, stepping in compiled code is not that easy.
So you need to either tell the compiler to record the necessary
information (like SBCL) or you need to use the interpreter.
c) macros complicate the code since they generate code that the users
usually not sees and is not supposed to see with all kinds of internal
strangeness
so, be prepared that stepping is not as easy as in a language that is
line oriented and where the implementation is based on an interpreter
Thanks you Luis and Reiner:
Let me ask with a practical example:
In SBCL I defined a naive factorial and did step:
* (defun factorial (n) (if (< n 2) 1 (* n (factorial (1- n)))))
FACTORIAL
* (step (factorial 10))
; Evaluating call:
; (FACTORIAL 10)
; With arguments:
; 10
1]
Now what do I do to single-step step by step further?
* (defun factorial (n)
(declare (optimize (speed 0) (space 1) (compilation-speed 0) (debug
3)))
(if (< n 2) 1 (* n (factorial (1- n)))))
FACTORIAL
* (step (factorial 10))
; Evaluating call:
; (FACTORIAL 10)
; With arguments:
; 10
1] step
; Evaluating call:
; (< N 2)
; With unknown arguments
0] step
; Evaluating call:
; (- N 1)
; With unknown arguments
0] step
; Evaluating call:
; (FACTORIAL (1- N))
; With arguments:
; 9
1]
> * (defun factorial (n) (if (< n 2) 1 (* n (factorial (1- n)))))
> FACTORIAL
> * (step (factorial 10))
> ; Evaluating call:
> ; (FACTORIAL 10)
> ; With arguments:
> ; 10
> 1]
> Now what do I do to single-step step by step further?
SBCL itself will print an answer to this question if you enter one
of:
:h
:he
:hel
:help
?
h
he
hel
help
By the way, the factorial of a negative number is not 1.
---Vassil.
--
"Even when the muse is posting on Usenet, Alexander Sergeevich?"
Also you might want to take a look at MzScheme.