unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Early backtrace.
@ 2022-01-10 20:34 Alan Mackenzie
  2022-01-10 21:54 ` Stefan Monnier
  0 siblings, 1 reply; 4+ messages in thread
From: Alan Mackenzie @ 2022-01-10 20:34 UTC (permalink / raw)
  To: emacs-devel

Hello, Emacs.

In the course of debugging a recent bug, I found myself needing to get a
Lisp backtrace.  This was early on in the bootstrap process, where the
standard backtrace.el cannot work, since it requires several files.el
which are only loaded later.

So I came up with the following, which has no Lisp dependencies.  That
is, absolutely none.  I have used it as the first Lisp file loaded,
immediately before byte-run.el.

So, how about including this file in Emacs, amending eval.c to use it if
backtrace.el isn't yet avaiable?  Comments and criticism are welcome.

lisp/emacs-lisp/early-debug.el:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defalias 'early-backtrace
  #'(lambda ()
  "Print a trace of Lisp function calls currently active.
The output stream used is the value of `standard-output'.

This is a simplified version of the standard `backtrace'
function, intended for use in debugging the early parts
of the build process."
  (princ "\n")
  (mapbacktrace
   #'(lambda (evald func args _flags)
       (let ((args args))
	 (if evald
	     (progn
	       (princ "  ")
	       (prin1 func)
	       (princ " (")
	       (while args
		 (prin1 (car args))
		 (setq args (cdr args))
		 (if args
		     (princ " ")))
	       (princ ")\n"))
	   (while args
	     (princ "  ")
	     (prin1 (car args))
	     (princ "\n")
	     (setq args (cdr args)))))))))

(defalias 'early-debug
  #'(lambda (&rest args)
  "Print a trace of Lisp function calls currently active.
The output stream used is the value of `standard-output'.

There should be two ARGS, the symbol `error' and a cons of
the error symbol and its data.

This is a simplified version of `debug', intended for use
in debugging the early parts of the build process."
  (princ "\nError: ")
  (prin1 (car (car (cdr args))))	; The error symbol.
  (princ " ")
  (prin1 (cdr (car (cdr args))))	; The error data.
  (early-backtrace)))

(setq debugger #'early-debug)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

-- 
Alan Mackenzie (Nuremberg, Germany).



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Early backtrace.
  2022-01-10 20:34 Early backtrace Alan Mackenzie
@ 2022-01-10 21:54 ` Stefan Monnier
  2022-01-11 11:36   ` Alan Mackenzie
  0 siblings, 1 reply; 4+ messages in thread
From: Stefan Monnier @ 2022-01-10 21:54 UTC (permalink / raw)
  To: Alan Mackenzie; +Cc: emacs-devel

> So I came up with the following, which has no Lisp dependencies.  That
> is, absolutely none.  I have used it as the first Lisp file loaded,
> immediately before byte-run.el.

I have a similar hack here for the same reason ;-)
So a +1 from me (tho I'd recommend using the `debugger-` namespace
rather than `early-`).

> So, how about including this file in Emacs, amending eval.c to use it if
> backtrace.el isn't yet avaiable?  Comments and criticism are welcome.

I don't see any need for a change to `eval.c`.  Just put the

    (setq debugger #'early-debug)

and

    (setq debugger #'debug)

at the appropriate places inside `loadup.el`.


        Stefan




^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Early backtrace.
  2022-01-10 21:54 ` Stefan Monnier
@ 2022-01-11 11:36   ` Alan Mackenzie
  2022-01-11 14:47     ` Stefan Monnier
  0 siblings, 1 reply; 4+ messages in thread
From: Alan Mackenzie @ 2022-01-11 11:36 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: emacs-devel

Hello, Stefan.

On Mon, Jan 10, 2022 at 16:54:16 -0500, Stefan Monnier wrote:
> > So I came up with the following, which has no Lisp dependencies.  That
> > is, absolutely none.  I have used it as the first Lisp file loaded,
> > immediately before byte-run.el.

> I have a similar hack here for the same reason ;-)
> So a +1 from me (tho I'd recommend using the `debugger-` namespace
> rather than `early-`).

Thanks!  Maybe `debug-early' and `backtrace-early' would do for the two
functions?  There isn't really a debugger- prefix that early in the
bootstrap.

> > So, how about including this file in Emacs, amending eval.c to use it if
> > backtrace.el isn't yet avaiable?  Comments and criticism are welcome.

> I don't see any need for a change to `eval.c`.  Just put the

>     (setq debugger #'early-debug)

> and

>     (setq debugger #'debug)

> at the appropriate places inside `loadup.el`.

No, inside signal_or_quit, Vdebugger gets bound to Qdebug, so as to
bypass the setting made in ERT.  Also it is filtered out by checking for
not being in dump or bootstrap.  Instead, we should check Ffboundp
(Qdebug) || Ffboundp (Qdebug_early).  Not difficult to do.

>         Stefan

-- 
Alan Mackenzie (Nuremberg, Germany).



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Early backtrace.
  2022-01-11 11:36   ` Alan Mackenzie
@ 2022-01-11 14:47     ` Stefan Monnier
  0 siblings, 0 replies; 4+ messages in thread
From: Stefan Monnier @ 2022-01-11 14:47 UTC (permalink / raw)
  To: Alan Mackenzie; +Cc: emacs-devel

>> I have a similar hack here for the same reason ;-)
>> So a +1 from me (tho I'd recommend using the `debugger-` namespace
>> rather than `early-`).
>
> Thanks!  Maybe `debug-early' and `backtrace-early' would do for the two
> functions?  There isn't really a debugger- prefix that early in the
> bootstrap.

Namespace prefixes don't need to be created before we use them.
The point is just that `debugger-` is already used by definitions (in
`debug.el`) so we can reuse that space instead of messing up pristine
real estate.

> No, inside signal_or_quit, Vdebugger gets bound to Qdebug, so as to
> bypass the setting made in ERT.  Also it is filtered out by checking for
> not being in dump or bootstrap.  Instead, we should check Ffboundp
> (Qdebug) || Ffboundp (Qdebug_early).  Not difficult to do.

Oh, god, I didn't know (or forgot) about that horror.
We should throw it out: your code should make it obsolete.
E.g. we can take your new code as the default value of `debugger` and
only replace it with `#'debugger` when an interactive frame
is available.


        Stefan




^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-01-11 14:47 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-10 20:34 Early backtrace Alan Mackenzie
2022-01-10 21:54 ` Stefan Monnier
2022-01-11 11:36   ` Alan Mackenzie
2022-01-11 14:47     ` Stefan Monnier

Code repositories for project(s) associated with this inbox:

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).