emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: bug#24514: 24.5; Lispy backtraces


From: Clément Pit--Claudel
Subject: Re: bug#24514: 24.5; Lispy backtraces
Date: Thu, 1 Dec 2016 20:23:50 -0500
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.4.0

Hi emacs-devel,

The discussion below seems to indicate that there's very little missing at the 
Lisp level to be able to implement `backtrace' in Lisp; is that right?

The documentation for backtrace states:

     It is written in C, since it must have
     access to the stack to determine which function calls are active.
     The return value is always ‘nil’.

But the existence of backtrace-frame seems to (partially) contradict this; or 
am I misunderstanding?

The context is that I need to capture backtraces on an Emacs server, and that I 
have no way (AFAICT) to know, when my debugger gets invoked, whether the error 
will then be handled by a condition-case block; thus I end up recording too 
much and my program ends up spending 95% of its time capturing useless 
backtraces.  

Instead, recording a sequence of backtrace-frame seems fast (thanks Vasilij!).  
But then, if an unhandled exception occurs, I need to actually format the 
recorded stack frames; which seems to be what `backtrace' does, only at the C 
level.

Cheers
Clément. 

On 2016-12-01 19:52, Vasilij Schneidermann wrote:
>> Thinking more about this, isn't this enough to implement `backtrace' in Lisp?
> 
> Not quite.  If you look at backtraces, you'll notice they are constantly
> prefixed with two spaces.  This prefix is conditional and can be
> replaced with an asterisk and a space to indicate where you currently
> are when stepping through the backtrace.  From what I can tell, there is
> no way to retrieve that information when relying on `backtrace-frame'
> only.
> 
> If you ignore that part, it's not too hard to write a replacement:
> 
> (with-output-to-string
>   (let ((print-level (or print-level 8))
>         (i 0)
>         frame)
>     (while (setq frame (backtrace-frame i))
>       (princ "  ")
>       (if (not (car frame))
>           (prin1 (cdr frame))
>         (prin1 (cadr frame))
>         (prin1 (cddr frame)))
>       (terpri)
>       (setq i (1+ i)))))
> 
> How faithful that one is, I don't know.  Perhaps this is a discussion better
> held on emacs-devel?
> 

Attachment: signature.asc
Description: OpenPGP digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]