From 06d0ada8a9ff7078f8ab89d5b4ce36f04587dc62 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Mon, 29 Apr 2019 06:48:00 -0700 Subject: debugger: expand frames. This patch adds special unwind frames for backtracing expansions. With this, we can get rid of the global variable last_form_expanded, since to get the last form expanded, we just search for the most enclosing expand frame. * eval.c (last_form_expanded): Global variable removed. (error_trace): Use uw_last_form_expanded() instead of last_form_expanded. (expand_eval): No need to save and restore last_form_expanded any more. (expand_lisp_setq, expand_setqf, expand_lisp1, do_expand): Use uw_last_form_expanded(). (expand, do_macroexpand_1): Push and pop expand frame. This fixes a bug: do_macroexpand_1 was not recording last_form_expanded. Evaluation of top-level forms uses explicit macroexpansion, therefore top-level evaluation was neglecting to set last_form_expanded. This explains weird behavior I saw in the listener from time to time, when errors would report against the expansion of the wrong form. (eval_init): Remove reference to last_form_expanded variable. * eval.h (last_form_expanded): Declaration removed. * share/txr/stdlib/debug.tl (expand-frame print-trace, expand-frame loc): New methods. (print-backtrace): Include uw-expand frames in the backtrace. * unwind.c (expand_frame_type): New static variable. (uw_find_frames_by_mask): Handle UW_EXPAND. (uw_last_form_expanded, uw_push_expand): New functions. (uw_late_init): Register expand-frame struct type. * unwind.h (enum uw_frtype): New enum member, UW_EXPAND. (uw_last_form_expanded, uw_push_expand): Declared. --- share/txr/stdlib/debugger.tl | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'share') diff --git a/share/txr/stdlib/debugger.tl b/share/txr/stdlib/debugger.tl index 8eeb9ce2..26f30741 100644 --- a/share/txr/stdlib/debugger.tl +++ b/share/txr/stdlib/debugger.tl @@ -78,6 +78,15 @@ ^[,(cadr form)] ^(,sym))))))) +(defmeth expand-frame print-trace (fr pr-fr nx-fr prefix) + (let* ((form fr.form) + (loc (source-loc-str form))) + (put-string `@prefix X:@(if loc `(@loc):`)`) + (prinl form))) + +(defmeth expand-frame loc (fr) + (source-loc-str fr.form)) + (defun print-backtrace (: (*stdout* *stdout*) (prefix "")) (with-resources ((imode (set-indent-mode *stdout* indent-foff) (set-indent-mode *stdout* imode)) @@ -86,7 +95,7 @@ (length (set-max-length *stdout* 10) (set-max-length *stdout* length))) (window-map 1 nil (lambda (pr el nx) el.(print-trace pr nx prefix)) - (find-frames-by-mask (logior uw-fcall uw-eval))))) + (find-frames-by-mask (logior uw-fcall uw-eval uw-expand))))) (defun debugger () (with-disabled-debugging -- cgit v1.2.3