summaryrefslogtreecommitdiffstats
path: root/share
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2019-04-29 06:48:00 -0700
committerKaz Kylheku <kaz@kylheku.com>2019-04-29 06:48:00 -0700
commit06d0ada8a9ff7078f8ab89d5b4ce36f04587dc62 (patch)
treea1a2ce6b398183fd9a3fff1ef789b6e71cfe4535 /share
parent37e9a5d1f8ec90c2fe1cddd0546655ad2afc1dac (diff)
downloadtxr-06d0ada8a9ff7078f8ab89d5b4ce36f04587dc62.tar.gz
txr-06d0ada8a9ff7078f8ab89d5b4ce36f04587dc62.tar.bz2
txr-06d0ada8a9ff7078f8ab89d5b4ce36f04587dc62.zip
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.
Diffstat (limited to 'share')
-rw-r--r--share/txr/stdlib/debugger.tl11
1 files changed, 10 insertions, 1 deletions
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