SBCL error messages: Any way to improve?

I have been developing with Common Lisp for almost a year now and it is really starting to get nervous. I started programming CL using CLISP, but later switched to SBCL for speed. I do a lot of pretty low-level things, so I need to interact with a lot of C code. I really like the incremental aspect of CL development (I don't use Emacs, however - I run SLIMV in Vim), but I'm in development slower than in Python , Perl, C, or even NASM. The root of the problem is the SBCL error messages. Once I had to look for almost 500 lines of code because SBCL decided to give me ERROR: Invalid number of arguments on foreign function #< some memory address > . It was not indicated which function was called, line number, nothing. More recently, I was pleased to receive The loaded code expects an incompatible layout for class SB-PRETTY:PRETTY-STREAM. randomly. The code runs FINE on CLISP, but just fails with obscure errors on SBCL. Is there a way to make these messages somewhat more informative? I have been writing C and assembly for almost 6 years now, and even they will give you the line number. The only valid SBCL errors that I saw were reader errors, which are almost useless as they usually make up the missing bracket. Again, is there an ad / command line switch that you can use to change it? I would not be mistaken writing my own error printer at this point.

EDIT: For example, with (sb-ext:restrict-compiler-policy 'debug 3) in my ~ / .sbclrc (using --load, not a script, so the .sbclrc file is loaded)

 debugger invoked on a SB-INT:SIMPLE-PROGRAM-ERROR in thread #<THREAD "main thread" RUNNING {AB09931}>: invalid number of arguments: 0 Type HELP for debugger help, or (SB-EXT:EXIT) to exit from SBCL. restarts (invokable by number or by possibly-abbreviated name): 0: [ABORT] Exit debugger, returning to top level. (SB-KERNEL::INVALID-ARG-COUNT-ERROR-HANDLER #<unavailable argument> #.(SB-SYS:INT-SAP #XB78CDAE0) #<SB-ALIEN-INTERNALS:ALIEN-VALUE :SAP #XB78CD7DC :TYPE (* (STRUCT SB-VM::OS-CONTEXT-T-STRUCT))> (79)) 0] print (SB-KERNEL::INVALID-ARG-COUNT-ERROR-HANDLER #<unavailable argument> #.(SB-SYS:INT-SAP #XB78CDAE0) #<SB-ALIEN-INTERNALS:ALIEN-VALUE :SAP #XB78CD7DC :TYPE (* (STRUCT SB-VM::OS-CONTEXT-T-STRUCT))> (79)) 0] down (SB-KERNEL:INTERNAL-ERROR #.(SB-SYS:INT-SAP #XB78CD7DC) #<unavailable argument>) 1] down ("foreign function: #x805FCBB") 2] down Bottom of stack. 

Not entirely informative.

+7
source share
5 answers

This is a common problem with distributions that "customize" the construction of the script; Arch Linux is a common criminal. Installing binaries from sbcl.org is the most reliable method. This is pretty easy to build from source if you want the latest version.

+4
source

I think what you are looking for: (sb-ext:restrict-compiler-policy 'debug 3)

You can put it in your ~/.sbclrc or in your REPL, and the SBCL debugger (especially in SLIME) will give much more useful results.

+5
source

One more thing I learned recently, and this may be useful in your situation:

  • Be sure to compile everything with a sufficient level of debugging.
  • Wrap the code you suspect in the form (step ...) . From there, you can follow the reboots that you recognize as very similar to GDB and other debugging indents (you can step by step, step by step, step by step and step by step) from there. It can be a little tedious to get to the function you need, if you absolutely do not know where it comes from, but if you use it as a methodology and check small code fragments, this helps.

Additional information: http://www.sbcl.org/manual/#Single-Stepping

+2
source

If you get a runtime error (I suspect that invalid number of arguments falls into this category), you should go into the debugger (unless you explicitly disabled it), and the backtrack will probably show you exactly where it was a call is made.

loaded code expects a different layout... indicates that you are viewing two parts of compiled code compiled at different points in time, or code that connects too much to internal elements. First, force recompile all your code and see if the warning disappears.

+1
source

I’ve been almost 7 years late, but I’ll add some useful tips. After I was tired of seeing errors in the mucus and only knowing what function they were in, but without a line number or anything else, I found this question. It didn’t help much, so I finally read the slime manual. https://common-lisp.net/project/slime/#documentation

Not sure if this would help the original poster, but when an error pops up and you are in the slime debugger, pressing 'v' (in emacs, not sure about vim) will show you the source code where the error occurs, you can also go to others entries in the stack trace and press "v".

There are other helpful tips in the mucus manual in the debugging section. It is very nice to be able to evaluate expressions in the same frame frame where the error occurred.

0
source

All Articles