[Sbcl-help] Fwd: Basic SBCL debugging

78 views
Skip to first unread message

Stavros Macrakis (Σταῦρος Μακράκης)

unread,
Feb 24, 2018, 1:10:42 PM2/24/18
to sbcl...@lists.sourceforge.net
Hi, I'm trying to debug some Maxima code. I'm running Maxima 5.41.0a_dirty, SBCL 1.3.12., in shell mode in Emacs on Windows 10.

I have some very very basic questions that I can't find the answers for in the manual:

* How do I invoke backtrace programmatically (not from the debugger command line)?

* How can I interrupt an infinite loop?
​ 
^C^C
​doesn't do anything
, and ^C^D
​terminates
 both SBCL and the shell
​ when it eventually gets read.​

​* I don't understand the :print option in trace -- how do I get at the function's parameters and return value? This works:

(defun foo (x) (+ x 3))
(trace foo :print 99)
(foo 10) =>
0: (FOO 10)
  0: 99 = 99 
  0: FOO returned 13
13

But this doesn't:

(trace foo :print x)   << undefined variable erro
​r​

​The doc for trace says:

:condition, :break and :print forms are evaluated in a context which mocks up the lexical environment of the called function, so that sb-debug:var and sb-debug:arg can be used.

and the doc for var says:

This function returns the value of the variable in the current frame with the specified name. 

​but when I try

(trace foo :print (sb-debug:var 'x))

and then call foo, I get the error
​ "
The value
  NIL  is not of type   SB-DI:FRAME
​".​


* Is there some way to turn off the warning messages when I set a new variable using setq interactively? It's annoying to have to remember to use defvar the first time I setq, and setq for subsequent times.
​ Similarly, how do I re-load a file after editing it without getting "function redefined" warnings?

​* Reading a non-existent package name kills sbcl, e.g.
sdfsdf:sdfsdf
​debugger invoked on a SB-INT:SIMPLE-READER-PACKAGE-ERROR in thread
#<THREAD "main thread" RUNNING {252E78F9}>:
​   then SBCL becomes unresponsive. How do I get out of this?​ If I enter C-c C-d, it continues:
 Package SDFSDF does not exist.
    File-Position: 50
    Stream: #<SYNONYM-STREAM :SYMBOL SB-SYS:*STDIN* {22436489}>
​  then enters the debugger and quits the process.



​Specific to Maxima:​

* How do I start bare SBCL in the Maxima installation? Running bin/sbcl.exe gives the error "can't find core file at xxx". There is an sbcl.core file in bin/; I suppose there are some environment variables I need to set?

* When in Lisp mode, when I exit the debugger, how do I return to the Lisp to_lisp() level instead of the Maxima (to-maxima) level?

* Why does *debugger-hook* get reset to its default when I go back to Maxima level?


Matt Kaufmann

unread,
Feb 24, 2018, 1:24:15 PM2/24/18
to Stavros Macrakis, sbcl...@lists.sourceforge.net
Hi --

Good questions, but I can only help on maybe a couple of them. (I
hope others answer the rest.)

The following seems to work in SBCL 1.4.2:

(defun foo (x) (+ x 3))

(trace foo :print (car sb-debug::args))
; and then:

* (foo 10)
0: (FOO 10)
0: (CAR SB-DEBUG::ARGS) = 10


0: FOO returned 13
13

*

As for interrupting in an Emacs shell: I've had various levels of
success over the years with various lisps. Sometimes ^Q^C<RETURN>
works; sometimes meta-x comint-interrupt-subjob works.

Regards,
Matt
Stavros Macrakis (Σταῦρος Μακράκης) <macr...@alum.mit.edu> writes:

> [1:multipart/alternative Hide]
>
>
> [1/1:text/plain Hide]

> [1/2:text/html Show]
>
>
> [2:text/plain Hide]
>
> ------------------------------------------------------------------------------
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
>
> [3:text/plain Hide]
>
> _______________________________________________
> Sbcl-help mailing list
> Sbcl...@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/sbcl-help

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Sbcl-help mailing list
Sbcl...@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sbcl-help

Stavros Macrakis (Σταῦρος Μακράκης)

unread,
Feb 24, 2018, 2:22:51 PM2/24/18
to Matt Kaufmann, sbcl...@lists.sourceforge.net
On Sat, Feb 24, 2018 at 1:23 PM, Matt Kaufmann <kauf...@cs.utexas.edu> wrote:
​​
(defun foo (x) (+ x 3))
(trace foo :print (car sb-debug::args))

​Thanks! Where do I find documentation for things like this? I don't see the sb-debug::args function in ​the SBCL manual.

As for interrupting in an Emacs shell: I've had various levels of
success over the years with various lisps.  Sometimes ^Q^C<RETURN>
works; sometimes meta-x comint-interrupt-subjob works.

​Thanks!

            -s​

Stas Boukarev

unread,
Feb 24, 2018, 3:11:33 PM2/24/18
to Stavros Macrakis (Σταῦρος Μακράκης), sbcl...@lists.sourceforge.net
On Sat, Feb 24, 2018 at 9:11 PM Stavros Macrakis (Σταῦρος Μακράκης) <macr...@alum.mit.edu> wrote:
Hi, I'm trying to debug some Maxima code. I'm running Maxima 5.41.0a_dirty, SBCL 1.3.12., in shell mode in Emacs on Windows 10.

I have some very very basic questions that I can't find the answers for in the manual:

* How do I invoke backtrace programmatically (not from the debugger command line)?
SB-DEBUG:PRINT-BACKTRACE 

Matt Kaufmann

unread,
Feb 24, 2018, 3:39:15 PM2/24/18
to Stavros Macrakis, sbcl...@lists.sourceforge.net
Sorry, I have no idea where to find such documentation. You mentioned
sb-debug:arg, and from that I made a lucky guess. I hope someone
gives you a better answer; I think that the fact that I needed two
colons, i.e. sb-debug::args rather than sb-debug:args, means that this
feature isn't officially supported and could go away in future
releases.

Note by the way that I supplied sb-debug::args as a variable, not (as
you mentioned) a function.

-- Matt
=?UTF-8?B?U3RhdnJvcyBNYWNyYWtpcyAozqPPhM6x4b+mz4HOv8+CIM6czrHOus+BzqzOus63z4Ip?=
<macr...@alum.mit.edu> writes:

> --001a1149a0bce87d950565fa31cc
> Content-Type: text/plain; charset="UTF-8"
> Content-Transfer-Encoding: quoted-printable
>
> On Sat, Feb 24, 2018 at 1:23 PM, Matt Kaufmann <kauf...@cs.utexas.edu>
> wrote:
>
>> =E2=80=8B=E2=80=8B
>> (defun foo (x) (+ x 3))
>> (trace foo :print (car sb-debug::args))
>>
>
> =E2=80=8BThanks! Where do I find documentation for things like this? I don'=
> t see
> the sb-debug::args function in =E2=80=8Bthe SBCL manual
> <http://www.sbcl.org/manual/>.
>
> As for interrupting in an Emacs shell: I've had various levels of
>> success over the years with various lisps. Sometimes ^Q^C<RETURN>
>> works; sometimes meta-x comint-interrupt-subjob works.
>>
>
> =E2=80=8BThanks!
>
> -s=E2=80=8B
>
> --001a1149a0bce87d950565fa31cc
> Content-Type: text/html; charset="UTF-8"
> Content-Transfer-Encoding: quoted-printable
>
> <div dir=3D"ltr"><div class=3D"gmail_default" style=3D"font-family:georgia,=
> serif;font-size:small;color:#330000"><span style=3D"font-family:arial,sans-=
> serif;color:rgb(34,34,34)">On Sat, Feb 24, 2018 at 1:23 PM, Matt Kaufmann <=
> /span><span dir=3D"ltr" style=3D"font-family:arial,sans-serif;color:rgb(34,=
> 34,34)">&lt;<a href=3D"mailto:kauf...@cs.utexas.edu" target=3D"_blank">kau=
> fm...@cs.utexas.edu</a>&gt;</span><span style=3D"font-family:arial,sans-ser=
> if;color:rgb(34,34,34)"> wrote:</span><br></div><div class=3D"gmail_extra">=
> <div class=3D"gmail_quote"><blockquote class=3D"gmail_quote" style=3D"margi=
> n:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class=3D"">=
> <div class=3D"gmail_default" style=3D"font-family:georgia,serif;font-size:s=
> mall;color:rgb(51,0,0);display:inline">=E2=80=8B=E2=80=8B</div>(defun foo (=
> x) (+ x 3))<br>
> </span>(trace foo :print (car sb-debug::args))<br>
> </blockquote><div><br></div><div><div class=3D"gmail_default" style=3D"font=
> -family:georgia,serif;font-size:small;color:rgb(51,0,0)">=E2=80=8BThanks! W=
> here do I find documentation for things like this? I don&#39;t see the sb-d=
> ebug::args function in =E2=80=8Bthe <a href=3D"http://www.sbcl.org/manual/"=
>>SBCL manual</a>.</div></div><div><br></div><blockquote class=3D"gmail_quot=
> e" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
> As for interrupting in an Emacs shell: I&#39;ve had various levels of<br>
> success over the years with various lisps.=C2=A0 Sometimes ^Q^C&lt;RETURN&g=
> t;<br>
> works; sometimes meta-x comint-interrupt-subjob works.<br></blockquote><div=
>><br></div><div class=3D"gmail_default" style=3D"font-family:georgia,serif;=
> font-size:small;color:rgb(51,0,0)">=E2=80=8BThanks!</div><div class=3D"gmai=
> l_default" style=3D"font-family:georgia,serif;font-size:small;color:rgb(51,=
> 0,0)"><br></div><div class=3D"gmail_default" style=3D"font-family:georgia,s=
> erif;font-size:small;color:rgb(51,0,0)">=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
> =C2=A0 -s=E2=80=8B</div></div><br></div></div>
>
> --001a1149a0bce87d950565fa31cc--
Reply all
Reply to author
Forward
0 new messages