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. --- unwind.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'unwind.h') diff --git a/unwind.h b/unwind.h index 1a122ebd..30ab70c2 100644 --- a/unwind.h +++ b/unwind.h @@ -30,7 +30,7 @@ typedef enum uw_frtype { UW_BLOCK, UW_CAPTURED_BLOCK, UW_MENV, UW_CATCH, UW_HANDLE, UW_CONT_COPY, UW_GUARD, #if CONFIG_DEBUG_SUPPORT - UW_FCALL, UW_EVAL + UW_FCALL, UW_EVAL, UW_EXPAND #endif } uw_frtype_t; @@ -146,6 +146,7 @@ void uw_push_handler(uw_frame_t *, val matches, val fun); #if CONFIG_DEBUG_SUPPORT void uw_push_fcall(uw_frame_t *, val fun, struct args *args); void uw_push_eval(uw_frame_t *, val form, val env); +void uw_push_expand(uw_frame_t *, val form, val env); #endif noreturn val uw_throw(val sym, val exception); noreturn val uw_throwv(val sym, struct args *); @@ -174,6 +175,9 @@ val uw_find_frame(val extype, val frtype); val uw_find_frames(val extype, val frtype); #if CONFIG_DEBUG_SUPPORT val uw_find_frames_by_mask(val mask); +val uw_last_form_expanded(void); +#else +define uw_last_form_expanded() ((void) 0) #endif val uw_invoke_catch(val catch_frame, val sym, struct args *); val uw_muffle_warning(val exc, struct args *); -- cgit v1.2.3