Stepping in sbcl from within the debugger
Asked Answered
T

2

7

I am trying to figure out how to step through code in sbcl and Slime after invoking the debugger with something like break. I do not want to have to start stepping from the beginning. For example if I have the following code:

(defun fib (n)
  (when (eql n 2)
    (break))
  (if (<= 0 n 1)
      n
      (+ (fib (- n 1))
         (fib (- n 2)))))

After the break point is hit, I want to be able to start stepping through the code. The only way I have found to do this, is to go over the frame in Slime, use the "Return From Frame" (R) feature, and type in (step (fib 2)).

When I try to use the "Step" (s) feature, instead of actually stepping, I am given this:

Evaluating call:
  (CONTINUE)
With arguments:
   [Condition of type STEP-FORM-CONDITION]

Restarts:
 0: [STEP-CONTINUE] Resume normal execution
 1: [STEP-OUT] Resume stepping after returning from this function
 2: [STEP-NEXT] Step over call
 3: [STEP-INTO] Step into call
 4: [ABORT] Return to sldb level 1.
 5: [CONTINUE] Return from BREAK.
 --more--

Backtrace:
  0: (SWANK:SLDB-STEP 0)
  1: (SB-INT:SIMPLE-EVAL-IN-LEXENV (SWANK:SLDB-STEP 0) #<NULL-LEXENV>)
  2: (EVAL (SWANK:SLDB-STEP 0))
  3: (SWANK:EVAL-FOR-EMACS (SWANK:SLDB-STEP 0) "COMMON-LISP-USER" 122)
  4: ((FLET #:FORM-FUN-7055 :IN SWANK::SLDB-LOOP))
  5: (SWANK::SLDB-LOOP 1)
  6: ((LAMBDA NIL :IN SWANK::DEBUG-IN-EMACS))
  7: ((FLET SWANK/BACKEND:CALL-WITH-DEBUGGING-ENVIRONMENT :IN "/home/michael/slime/swank/sbcl.lisp") #<FUNCTION (LAMBDA NIL :IN SWANK::DEBUG-IN-EMACS) {1003DB44CB}>)

What I am looking for should be possible. From the sbcl manual stepping

can be invoked via the step macro, or from within the debugger.

I am running sbcl 1.2.5 with Slime 2.12 and my optimization qualities are all 1 except for safety and debug which are both 3.

Tortuosity answered 11/1, 2015 at 17:29 Comment(1)
This is really out of context here, it sounds like a bug or a support request. Have you tried asking in the IRC #lisp channel at freenode or SLIME's mailing list? It doesn't seem directly about SBCL, as it doesn't seem you've tried stepping in it without SLIME.Kirbie
T
2

I had compiled swank with debug set to 3. Because of this, when I would step after the break it would then step into swank, giving the weird behavior described.

Tortuosity answered 21/1, 2015 at 17:7 Comment(0)
I
3

I have been struggling with trying to make the step debugging work since I started to learn common lisp. After reading this beautiful tutorial debugging with slime I thought of giving the step debugger another chance... This is what I did to recompile swank (read until the end before trying yourself):

Started a new sbcl session in a terminal:

rlwrap sbcl
ran the following
(declaim (optimize (debug 0)))
(asdf:load-system :swank :force t)
; then i noticed in the messages that it doesn't compile all the files
; compiling file "/home/smokeink/quicklisp/dists/quicklisp/software/slime-2.14/swank-loader.lisp"
; /home/smokeink/.cache/common-lisp/sbcl-1.3.0-linux-x64/home/smokeink/quicklisp/dists/quicklisp/software/slime-2.14/swank-loader-TMP.fasl written
; then i tried:
(compile-file "~/.emacs.d/elpa/slime-20150623.821/swank.lisp")
; compiling...
; ~/.emacs.d/elpa/slime-20150623.821/swank.fasl written

That DID NOT work, so I went for another approach, I added this to swank.lisp:

; ...
(in-package :swank)
; added the following line
(declaim (optimize (debug 0)))
; ...

Restarted slime, it recompiled a few files, and THEN IT WORKED as expected.

(note that before doing the above, I had also changed

(declaim (optimize (debug 2)
                   (sb-c::insert-step-conditions 0)
                   (sb-c::insert-debug-catch 0)))
to
(declaim (optimize (debug 0)
                   (sb-c::insert-step-conditions 0)
                   (sb-c::insert-debug-catch 0)))

in swank/sbcl.lisp, but this change had no effect on the step-debugging problem) (I had also tried to set (declaim (optimize (debug 0))) in .sbclrc and then to restart slime but as far as I can remember, that did not work.)

Update:

"After the break point is hit, I want to be able to start stepping through the code. The only way I have found to do this, is to go over the frame in Slime, use the "Return From Frame" (R) feature, and type in (step (fib 2))."

You can actually proceed directly by pressing s ! No need to Return From Frame, just press s after the break took place. Note that for that to work you must have (proclaim (optimize (debug 3))) in your initialization file ( ex. .sbclrc)

Icao answered 19/2, 2016 at 13:22 Comment(0)
T
2

I had compiled swank with debug set to 3. Because of this, when I would step after the break it would then step into swank, giving the weird behavior described.

Tortuosity answered 21/1, 2015 at 17:7 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.