emacs-devel
[Top][All Lists]
Advanced

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

Re: Why is it so difficult to get a Lisp backtrace?


From: Alan Mackenzie
Subject: Re: Why is it so difficult to get a Lisp backtrace?
Date: Sat, 25 Jun 2022 15:26:02 +0000

Hello, again.

On Sat, Jun 25, 2022 at 13:42:04 +0000, Alan Mackenzie wrote:
> (setq debug-on-error t) ought to be useful to get backtraces.  It is,
> sometimes, but far from always.

> There seem to be three use cases for debug-on-error:
> (i) The vast bulk of users, who are barely, if at all, aware of its
>   existence.  They will enable it on request from a maintainer to help
>   debug a bug.
> (ii) Hard-core maintainers, who run with it enabled constantly.  Here
>   debug-ignored-errors helps suppress certain unhelpful errors which
>   would otherwise occur too often and irritate.
> (iii) Those maintainers who run with it disabled, but when an error
>   occurs, want to be able to repeat that error and get a backtrace.

> This third group of users is poorly catered for by the current collection
> of mechanisms.  See also bug #56201, with thanks to Andreas and Lars who
> helped me get to the bottom of it.  To be reasonably sure of getting a
> backtrace, it seems one needs to do all of the following:
> (i) (setq debug-on-error t).
> (ii) (setq debug-on-signal t).
> (iii) Bind debug-ignored-errors to nil.
> (iv) Pray.
> (v) Execute the erring command again.

> I put it to people that we need a new command or variable not called
> something like `backtrace-next-and-I-really-mean-it' which would allow
> step (v) to generate the desired backtrace without having to go through
> steps (i) to (iv) individually.  The lack of such a command/variable is
> making (at least) my Emacs development less pleasant than it might
> otherwise be.

I mean something like the following, which to a first approximation,
works.  To use it, do M-x debug-next-command and the execute the command
expected to give errors:


;; -*- lexical-binding: t -*-

(defvar debug-next-command-save-debug-on-error nil)
(defvar debug-next-command-save-debug-on-signal nil)
(defvar debug-next-command-save-debug-on-quit nil)
(defvar debug-next-command-save-debug-ignored-errors nil)

(defvar debug-next-command-stay-on-post-command nil)

(defun debug-next-command-end ()
  "Undo the effects of debug-next-command."
  (if debug-next-command-stay-on-post-command
      (setq debug-next-command-stay-on-post-command nil)
    (setq debug-on-error debug-next-command-save-debug-on-error
          debug-on-signal debug-next-command-save-debug-on-signal
          debug-on-quit debug-next-command-save-debug-on-quit
          debug-ignored-errors debug-next-command-save-debug-ignored-errors)
    (remove-hook 'post-command-hook #'debug-next-command-end)))

(defun debug-next-command ()
  "Produce a bactrace in the next command should an error occur."
  (interactive)
  (setq debug-next-command-save-debug-on-error debug-on-error
        debug-next-command-save-debug-on-signal debug-on-signal
        debug-next-command-save-debug-on-quit debug-on-quit
        debug-next-command-save-debug-ignored-errors debug-ignored-errors)
  (setq debug-on-error t
        debug-on-signal t
        debug-on-quit t
        debug-ignored-errors nil)
  (setq debug-next-command-stay-on-post-command t)
  (add-hook 'post-command-hook #'debug-next-command-end))

-- 
Alan Mackenzie (Nuremberg, Germany).



reply via email to

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