2

With emacs if there is a backtrace buffer open, new backtrace is ignored. I find it is unconvenient when I am trying to find out which function/hook changes a variable. I use debug-watch as described in https://stackoverflow.com/questions/62579200/find-out-when-a-variable-is-changed-in-emacs The problem is the variable changes happens after a backtrace buffer popup is impossible to know because of the backtrace blocking described above.

(debug-watch VARIABLE)

How can I make emacs popup as many backtrace buffers as possible or log the backtraces to a file?

2
  • I am not sure what you mean with 'new backtrace is ignored' but you can exit the debugger and continue by pressing c (see the section debugger commands in the elisp manual). Commented May 25, 2022 at 11:47
  • It takes time between debugger popping up and me pressing c, during that time, there is possible other backtraces buried without notice. I have come across this situation. :-(
    – godblessfq
    Commented May 26, 2022 at 2:54

2 Answers 2

0

I'm not sure whether this helps answer your request, but you can use function backtrace directly, to print a backtrace at any time to standard-output (which you can bind to a buffer etc.). C-h f backtrace:

backtrace is a compiled Lisp function in subr.el.

`(backtrace)1

Print a trace of Lisp function calls currently active.

Output stream used is value of standard-output.

See the Elisp manual, node Internals of Debugger, for more info about this, including and example information about variable debugger-stack-frame-as-list.

7
  • It surely helps in debugging one specific package. But often we don't know where is the problem. Like bookmark+ changing buffer local outline-regex and comment-start when saving bookmarks, while making outline-minor-mode crazy.
    – godblessfq
    Commented May 26, 2022 at 2:58
  • Sorry, but I don't recognize anything you say in your comment about Bookmark+ saving bookmarks. If you think you've found bugs, please report them specifically. AFAIK, Bookmark+ does nothing wrt out-line-* or comment-start when saving bookmarks or any other time. The only occurrence of outline-* in its code is in the doc string for bookmark-after-jump-hook, where it just suggests, as an example, that you can use the hook to unhide text in outline-mode. And there are no occurrences of comment-start in the code.
    – Drew
    Commented May 26, 2022 at 14:34
  • Bookmark+ seems to open the bookmark file in the background, and during processing of the file, it enables other mode that changes those variables. I disabled bookmark+ and everything is good now. I will look into it further later.
    – godblessfq
    Commented May 27, 2022 at 0:36
  • I think I have got the backtrace: gist.github.com/QiangF/706e6b103c668e87b8ae79fdc76700ea
    – godblessfq
    Commented May 27, 2022 at 0:44
  • Thanks, but I can't do anything with that really. You seem to have a lot of stuff going on, and it's not clear what - option customizations, key bindings, hydras, etc. Please (1) use M-x bmkp-send-bug-report to report the problem. But (2) do so with a minimal recipe, starting from emacs -Q to repro it.
    – Drew
    Commented May 27, 2022 at 1:28
0

Enable debug-on-error and use at your own risk; I've given it the most rudimentary of testing, but wouldn't have the foggiest idea how robust this would be.

(defun my-debug-to-file (&rest _args)
  (let ((inhibit-debugger t)
        (backtrace (backtrace-get-frames 'debug))
        (print-length nil))
    (with-temp-buffer
      (insert (backtrace-to-string backtrace))
      (insert "\n------------------------------------------------------\n\n")
      (append-to-file nil nil "/tmp/backtrace.log"))))

(advice-add 'debug :override #'my-debug-to-file)
;; (advice-remove 'debug #'my-debug-to-file)
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.