From 6c6d60171a53742ae856a59f063a229e990141b6 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Sun, 21 Apr 2019 01:48:11 -0700 Subject: debugger: eval frames. We introduce evaluation tracking frames. The backtrace function can use these to deduce the line from which a function is called (if called from interpreted code). Eventually we will have analogous virtual machine frames to do this for compiled code. * eval.c (do_eval): If backtraces are enabled, then push and pop an eval frame, which holds the two key pieces: the form and environment. * share/txr/stdlib/debug.tl ((fcall-frame loc), (fcall-frame print-trace), (eval-frame loc), (eval-frame print-trace)): New methods. (print-backtrace): Loop reduced to just dispatching frame-specific print-trace methods. It gives the previous and next frame to each method. The (fcall-frame print-trace) method prints function frames, using the previous form to deduce the location from which the function is called. The (eval-frame print-trace) method mostly suppresses the printing of eval frames. We print an eval frame if it is the parent of an internal function frame, and if it is the topmost frame (to identify the toplevel form at the root of the backtrace). * unwind.c (form_s): New symbol variable. (eval_frame_type): New static variable. (uw_find_frames_by_mask): Handle UW_EVAL case, producing eval-frame struct. (uw_push_eval): New function. (uw_late_init): Allocate eval-frame struct type, storing it in eval_frame_type, and gc-protect that new variable. Register uw-eval variable evaluating to a one bit mask with the UW_EVAL-th bit set. * unwind.h (enum uw_frtype): New enum constant UW_EVAL. (struct uw_eval): New struct type. (union uw_frame): New member, el. (uw_push_eval): Declared. --- unwind.h | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'unwind.h') diff --git a/unwind.h b/unwind.h index 58e8c5fd..1a122ebd 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_FCALL, UW_EVAL #endif } uw_frtype_t; @@ -100,6 +100,13 @@ struct uw_fcall { struct args *args; }; +struct uw_eval { + uw_frame_t *up; + uw_frtype_t type; + val form; + val env; +}; + #endif #if __aarch64__ @@ -118,6 +125,7 @@ union uw_frame { struct uw_guard gu; #if CONFIG_DEBUG_SUPPORT struct uw_fcall fc; + struct uw_eval el; #endif } UW_FRAME_ALIGN; @@ -137,6 +145,7 @@ void uw_push_catch(uw_frame_t *, val matches); 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); #endif noreturn val uw_throw(val sym, val exception); noreturn val uw_throwv(val sym, struct args *); -- cgit v1.2.3