4 ms·
That's SLIME specific. SBCL's own REPL has it. * (defun foo (x) (declare (optimize (debug 3))) (let ((n 10)) (break) (* x n)))
by lispm 4y ago
That's SLIME specific. SBCL's own REPL has it.
* (defun foo (x)
(declare (optimize (debug 3)))
(let ((n 10))
(break)
(* x n)))
FOO
* (foo 3) ; calling foo
(foo 3)
We get a break repl:
debugger invoked on a SIMPLE-CONDITION
restarts (invokable by number or by possibly-abbreviated name):
0: [CONTINUE] Return from BREAK.
1: [ABORT ] Exit debugger, returning to top level.
(FOO 3)
source: (BREAK)
Let's change the local variable N of the running function FOO:
0] (setf n 12)
(setf n 12)
12
Return from the break:
0] 0 ; restart 0
0
36
Note that you may want to reduce the optimization level of SBCL, since by default everything is compiled, and its optimizing compiler might get rid of a few of the variables during compilation. For example the compiler might detect that N's literal value 10 is not changed in the function and replace the variable access to N with the compile-time value. That's why I used the DEBUG quality 3 (highest) to tell the compiler to not optimize the code.
- kagevf 4y ago> We get a break repl: How? I ran the same function, brought up the debugger, if I try to type something emacs says the buffer is read-only. Was I supposed to push e first?
- superdisk 4y agoFair enough, and I've done it just in SBCL like that before, but everyone always sings the praises of Lisp's (+ SLIME's) amazing debugging, and without the ability to stop at a certain stack frame and explore, I feel like I'm debugging with a blindfold on at all times.
- lispm 4y agoone of the reasons SLIME is not my favorite dev environment
- Jtsummers 4y agoIt actually can be done in SLIME's debugger but it's hard to discover especially if you don't guess that `h` is the correct key (I tried `?` first) to bring up a list of bindings. `e` will let you enter an expression in the emacs mini buffer to evaluate in the selected frame.
- tmtvl 4y agoSuperdisk's original comment mentions, and I agree, that pressing "e" on a frame to evaluate a single expression is bad UX. A relevant issue on GH* mentions that you can keep evaluating in the SLIME REPL, but I just tried and it doesn't seem to work poperly, the frame locals not being available in the REPL. Sly also doesn't seem to do it. * https://github.com/slime/slime/issues/581 https://github.com/slime/slime/issues/581