4 ms·
I like Lisp but I've had one perpetual problem with debugging it that makes me feel like I'm doing something wrong. Once I've hit a breakpoint, and SLIME or wha
by superdisk 4y ago
I like Lisp but I've had one perpetual problem with debugging it that makes me feel like I'm doing something wrong. Once I've hit a breakpoint, and SLIME or whatever presents its options, HOW can I get into a REPL in the context of the stack frame, so I can eval expressions that reference variables in scope there? The best I can find is pressing `e` over the stack frame to evaluate one expression, but that's garbage compared to the full repl (and hotkeys that send expressions to it like C-c C-e).
I feel like there must be some way to do this that I just haven't found yet.
- vindarel 4y agoI think you are doing it right, I don't know if it's possible to get a REPL in the context of the stack frame either. It would be handy and the workflow would resemble other ecosystems'.
- taeric 4y agoI suspect the main blocker here is that it wouldn't know which "frame" to eval in. Since, from the debugger, you can eval in any frame on the stack?
- lispm 4y agoThat'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 ago
- agumonkey 4y agoIf it's not done it would be a worthy addition.