From: Karol Skocik
Subject: *debugger-hook* misunderstanding
Date: 
Message-ID: <94418a21-4c48-4d22-aa00-11e8a4810970@40g2000prx.googlegroups.com>
Hi,
  I want this piece of code to do:
1. print backtrace (that would normally be sent over socket)
2. enter the debugger like step 1. did not happen

so I made this:

(let ((*debugger-hook* (lambda (condition hook)
                                  (print hook)
                                  (print (with-output-to-string (s)
                                           (backtrace-with-extra-info
                                            :start 0 :end 30 :stream
s)))
                                  (let ((*debugger-hook* nil))
                                    (invoke-debugger condition)))))
          (+ 3 'a))

step 1. is OK, but instead of landing in debugger in step 2., I see
just:

debugger invoked on a TYPE-ERROR in thread #<THREAD "repl-thread"
RUNNING {1002BEC4B1}>:
  The value A is not of type NUMBER.

on place where normal output goes, and there it hangs (I won't get
REPL until I press C-c C-c)

This all is on SBCL/Linux with SLIME, but I guess it's not important
much since I think that just don't understand what *debugger-hook*
does.

Could you please enlighten me what's wrong?

Thanks a lot,
  Karol

From: Helmut Eller
Subject: Re: *debugger-hook* misunderstanding
Date: 
Message-ID: <m21vvhlhdo.fsf@common-lisp.net>
* Karol Skocik [2009-01-05 18:40+0100] writes:

> Hi,
>   I want this piece of code to do:
> 1. print backtrace (that would normally be sent over socket)
> 2. enter the debugger like step 1. did not happen

I think this could be done with HANDLER-BIND alone (without *debugger-hook*).

> so I made this:
>
> (let ((*debugger-hook* (lambda (condition hook)
>                                   (print hook)
>                                   (print (with-output-to-string (s)
>                                            (backtrace-with-extra-info
>                                             :start 0 :end 30 :stream
> s)))
>                                   (let ((*debugger-hook* nil))
>                                     (invoke-debugger condition)))))
>           (+ 3 'a))
>
> step 1. is OK, but instead of landing in debugger in step 2., I see
> just:
>
> debugger invoked on a TYPE-ERROR in thread #<THREAD "repl-thread"
> RUNNING {1002BEC4B1}>:
>   The value A is not of type NUMBER.

This is the message created by SBCL's debugger.

>
> on place where normal output goes, and there it hangs (I won't get
> REPL until I press C-c C-c)
>
> This all is on SBCL/Linux with SLIME, but I guess it's not important
> much since I think that just don't understand what *debugger-hook*
> does.
>
> Could you please enlighten me what's wrong?

SBCL's debugger wants to have a lock for the "session".  That is
intended to stop multiple threads from reading from the same terminal.
Usually, the initial threads holds that lock and you can type
(sb-thread:release-foreground) in the *inferior-lisp* buffer to release
it.  The repl-thread should then grab the lock and continue with the
debugger loop.  I think the SBCL manual contains some info about session
management.

The session management in SBCL is IMHO only a of prototype quality
(since 5 years or so).

Helmut.
From: Andy Chambers
Subject: Re: *debugger-hook* misunderstanding
Date: 
Message-ID: <bc5814f8-4925-4c06-bf3a-3d20f18a2208@z28g2000prd.googlegroups.com>
On Jan 5, 6:47 pm, Helmut Eller <······@common-lisp.net> wrote:
> * Karol Skocik [2009-01-05 18:40+0100] writes:
>
> > Hi,
> >   I want this piece of code to do:
> > 1. print backtrace (that would normally be sent over socket)
> > 2. enter the debugger like step 1. did not happen
>
> I think this could be done with HANDLER-BIND alone (without *debugger-hook*).
>

Somewhat related to this, I saw a blog post by someone a few months
ago that
showed how to customize what the debugger displayed.  Unfortunately,
I've lost
the link and am unable to find it again using google.  Can anyone
round here
remember writing/reading something like that?

Cheers,
Andy
From: billc
Subject: Re: *debugger-hook* misunderstanding
Date: 
Message-ID: <38aa42ad-37ea-42bc-95a9-82bd370ee462@r15g2000prd.googlegroups.com>
On Jan 5, 4:19 pm, Andy Chambers <··············@googlemail.com>
wrote:
> On Jan 5, 6:47 pm, Helmut Eller <······@common-lisp.net> wrote:
>
> > * Karol Skocik [2009-01-05 18:40+0100] writes:
>
> > > Hi,
> > >   I want this piece of code to do:
> > > 1. print backtrace (that would normally be sent over socket)
> > > 2. enter the debugger like step 1. did not happen
>
> > I think this could be done with HANDLER-BIND alone (without *debugger-hook*).
>
> Somewhat related to this, I saw a blog post by someone a few months
> ago that
> showed how to customize what the debugger displayed.  Unfortunately,
> I've lost
> the link and am unable to find it again using google.  Can anyone
> round here
> remember writing/reading something like that?

You might be thinking of Juho Snellman's "Pretty SBCL Backtraces"
post:
http://jsnell.iki.fi/blog/archive/2007-12-19-pretty-sbcl-backtraces.html

--
Bill Clementson
From: Andy Chambers
Subject: Re: *debugger-hook* misunderstanding
Date: 
Message-ID: <9b2c6bd0-2b2e-47dc-a2c2-35ecf00694b4@t26g2000prh.googlegroups.com>
On Jan 6, 6:10 pm, billc <········@gmail.com> wrote:
> On Jan 5, 4:19 pm, Andy Chambers <··············@googlemail.com>
> wrote:
>
>
>
> > On Jan 5, 6:47 pm, Helmut Eller <······@common-lisp.net> wrote:
>
> > > * Karol Skocik [2009-01-05 18:40+0100] writes:
>
> > > > Hi,
> > > >   I want this piece of code to do:
> > > > 1. print backtrace (that would normally be sent over socket)
> > > > 2. enter the debugger like step 1. did not happen
>
> > > I think this could be done with HANDLER-BIND alone (without *debugger-hook*).
>
> > Somewhat related to this, I saw a blog post by someone a few months
> > ago that
> > showed how to customize what the debugger displayed.  Unfortunately,
> > I've lost
> > the link and am unable to find it again using google.  Can anyone
> > round here
> > remember writing/reading something like that?
>
> You might be thinking of Juho Snellman's "Pretty SBCL Backtraces"
> post:http://jsnell.iki.fi/blog/archive/2007-12-19-pretty-sbcl-backtraces.html

Yup.  That's the one.  Thanks a lot.

--
Andy
From: Tim Bradshaw
Subject: Re: *debugger-hook* misunderstanding
Date: 
Message-ID: <e4372f3c-9d29-4628-93a2-3ebb91a243bc@b38g2000prf.googlegroups.com>
On Jan 5, 6:47 pm, Helmut Eller <······@common-lisp.net> wrote:

> I think this could be done with HANDLER-BIND alone (without *debugger-hook*).

It could, and it would be better: just do whatever you want in the
handler but decline to handle the condition (ie do not transfer
control from the handler).