help-gnu-emacs
[Top][All Lists]
Advanced

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

Re: Getting stack traces without entering the debugger


From: Michael Heerdegen
Subject: Re: Getting stack traces without entering the debugger
Date: Wed, 19 Feb 2014 18:13:11 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux)

E Sabof <esabof@gmail.com> writes:

> I'm trying to investigate an isearch-related issue, where a function
> gets called twice, instead of once.

Why don't you just `debug-on-entry' that function?

> Is there a way to get a stack trace and save it to a variable, without
> calling the debugger?

You can use `backtrace' (which is actually called by the debugger to
fill the *Backtrace* buffer) and use some temp buffer as
`standard-output'.

In recent Emacs version, there's also `macroexp--backtrace', a little
helper in macroexp.el that returns a backtrace as a lisp expression.
Even in older version, the simple definition should still work:

(defun macroexp--backtrace ()
  "Return the Elisp backtrace, more recent frames first."
  (let ((bt ())
        (i 0))
    (while
        (let ((frame (backtrace-frame i)))
          (when frame
            (push frame bt)
            (setq i (1+ i)))))
    (nreverse bt)))

Unlike `backtrace', the result is complete, there are no parts that are
replaced with ellipses by the printer.  Of course, parts can still be
omitted when you print the result.   `pp' should work fine.

The doc of `backtrace-frame' describes the format of the backtrace
frames returned.

Michael.




reply via email to

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