From c9a8bbd7f5308b9d165b0d21ff9b49bcd4fc070e Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Thu, 6 Aug 2015 22:10:18 -0700 Subject: Suppress debug stepping into auto-loaded library code. * debug.c (debug_set_state, debug_restore_state): New functions. * debug.h (debug_state_t): New type. (debug_set_state, debug_restore_state): Declared, and defined as dummy macros in non-debug-support build. * lisplib.c (opt_dbg_autoload): New global variable. (lisplib_try_load): Disable or enable debugging around library loading based on opt_dbg_autoload option. * lisplib.h (opt_dbg_autoload): Declared. * txr.c (help): List --debug-autoload option. (no_dbg_support): New static function to avoid repeated code. (txr_main): Add debugger option. Change duplicate no debug support error messages into calls to no_dbg_support. * txr.1: Document --debug-autoload --- ChangeLog | 23 +++++++++++++++++++++++ debug.c | 14 ++++++++++++++ debug.h | 12 ++++++++++++ lisplib.c | 8 +++++++- lisplib.h | 2 +- txr.1 | 7 +++++++ txr.c | 28 ++++++++++++++++++++++------ 7 files changed, 86 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index 8caefa5b..6c2d36f6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,26 @@ +2015-08-06 Kaz Kylheku + + Suppress debug stepping into auto-loaded library code. + + * debug.c (debug_set_state, debug_restore_state): New functions. + + * debug.h (debug_state_t): New type. + (debug_set_state, debug_restore_state): Declared, and defined + as dummy macros in non-debug-support build. + + * lisplib.c (opt_dbg_autoload): New global variable. + (lisplib_try_load): Disable or enable debugging around + library loading based on opt_dbg_autoload option. + + * lisplib.h (opt_dbg_autoload): Declared. + + * txr.c (help): List --debug-autoload option. + (no_dbg_support): New static function to avoid repeated code. + (txr_main): Add debugger-autoload option. Change duplicate no debug + support error messages into calls to no_dbg_support. + + * txr.1: Document --debug-autoload + 2015-08-06 Kaz Kylheku * txr.c (txr_main): Bugfix: debugger long option nonfunctional. diff --git a/debug.c b/debug.c index 00117558..0fb426b2 100644 --- a/debug.c +++ b/debug.c @@ -241,6 +241,20 @@ val debug(val form, val bindings, val data, val line, val pos, val base) } } +debug_state_t debug_set_state(int depth, int step) +{ + debug_state_t old = { next_depth, step_mode }; + next_depth = depth; + step_mode = step; + return old; +} + +void debug_restore_state(debug_state_t state) +{ + next_depth = state.next_depth; + step_mode = state.step_mode; +} + void debug_init(void) { step_mode = 1; diff --git a/debug.h b/debug.h index c14a304c..3ae18cab 100644 --- a/debug.h +++ b/debug.h @@ -31,6 +31,11 @@ val debug(val form, val bindings, val data, val line, val pos, val base); #if CONFIG_DEBUG_SUPPORT +typedef struct { + int next_depth; + int step_mode; +} debug_state_t; + #define debug_enter \ { \ int debug_depth_save = debug_depth++; \ @@ -55,6 +60,8 @@ INLINE val debug_check(val form, val bindings, val data, val line, return (opt_debugger) ? debug(form, bindings, data, line, pos, base) : nil; } +debug_state_t debug_set_state(int depth, int step); +void debug_restore_state(debug_state_t); void debug_init(void); #define debug_frame(FUNC, ARGS, UBP, \ @@ -77,6 +84,8 @@ void debug_init(void); #else +typedef int debug_state_t; + #define debug_enter { #define debug_leave } @@ -98,6 +107,9 @@ INLINE val debug_check(val form, val bindings, val data, val line, #define debug_end \ } while (0) +#define debug_set_state(D, S) (0) +#define debug_restore_state(S) ((void) 0) + INLINE void debug_init(void) { } diff --git a/lisplib.c b/lisplib.c index 699d076e..8a98a23e 100644 --- a/lisplib.c +++ b/lisplib.c @@ -35,10 +35,12 @@ #include "stream.h" #include "hash.h" #include "gc.h" +#include "debug.h" #include "txr.h" #include "lisplib.h" val dl_table; +int opt_dbg_autoload; void set_dlt_entries(val dlt, val *name, val fun) { @@ -186,5 +188,9 @@ void lisplib_init(void) val lisplib_try_load(val sym) { val fun = gethash(dl_table, sym); - return if3(fun, (funcall(fun), t), nil); + debug_state_t ds; + return if3(fun, (ds = debug_set_state(opt_dbg_autoload ? 0 : -1, + opt_dbg_autoload), + funcall(fun), + debug_restore_state(ds), t), nil); } diff --git a/lisplib.h b/lisplib.h index 1e5ce485..e12d4641 100644 --- a/lisplib.h +++ b/lisplib.h @@ -25,7 +25,7 @@ */ extern val dl_table; - +extern int opt_dbg_autoload; void lisplib_init(void); val lisplib_try_load(val sym); void set_dlt_entries(val dlt, val *name, val fun); diff --git a/txr.1 b/txr.1 index e30f47a7..bf5a553f 100644 --- a/txr.1 +++ b/txr.1 @@ -671,6 +671,13 @@ See the .code gc-set-delta function for a description. +.meIP --debug-autoload +This option turns on debugging, like +.code --debugger +but also arranges for stepping into the auto-load processing of +\*(TL library code. Normally, debugging through the evaluations +triggered by auto-loading is suppressed. + .coIP --help Prints usage summary on standard output, and terminates successfully. diff --git a/txr.c b/txr.c index e784c224..b9a65f80 100644 --- a/txr.c +++ b/txr.c @@ -52,6 +52,7 @@ #include "eval.h" #include "regex.h" #include "arith.h" +#include "lisplib.h" #include "txr.h" const wchli_t *version = wli(TXR_VER); @@ -144,6 +145,7 @@ static void help(void) "--compat=N Synonym for -C N\n" "--gc-delta=N Invoke garbage collection when malloc activity\n" " increments by N megabytes since last collection.\n" +"--debug-autoload Allow debugger to step through library auto-loading.\n" "\n" "Options that take no argument can be combined. The -q and -v options\n" "are mutually exclusive; the right-most one dominates.\n" @@ -366,6 +368,15 @@ static int gc_delta(val optval) return 1; } +#ifndef CONFIG_DEBUG_SUPPORT +static void no_dbg_support(val arg) +{ + format(std_error, + lit("~a: option ~a requires debug support compiled in\n"), + prog_string, arg, nao); +} +#endif + int txr_main(int argc, char **argv) { val specstring = nil; @@ -500,9 +511,16 @@ int txr_main(int argc, char **argv) opt_debugger = 1; continue; #else - format(std_error, - lit("~a: option ~a requires debug support compiled in\n"), - prog_string, arg, nao); + no_dbg_support(arg); + return EXIT_FAILURE; +#endif + } else if (equal(opt, lit("debug-autoload"))) { +#if CONFIG_DEBUG_SUPPORT + opt_debugger = 1; + opt_dbg_autoload = 1; + continue; +#else + no_dbg_support(opt); return EXIT_FAILURE; #endif } else if (equal(opt, lit("noninteractive"))) { @@ -591,9 +609,7 @@ int txr_main(int argc, char **argv) #if CONFIG_DEBUG_SUPPORT opt_debugger = 1; #else - format(std_error, - lit("~a: option ~a requires debug support compiled in\n"), - prog_string, opch, nao); + no_dbg_support(opch); return EXIT_FAILURE; #endif break; -- cgit v1.2.3