Skip to content

Commit

Permalink
Rename repl-backtrace-highlight-source-level to repl-highlight-source…
Browse files Browse the repository at this point in the history
…-level and add runtime options for setting backtrace detail level and source highlighting level
  • Loading branch information
feeley committed Oct 19, 2023
1 parent c4a3d6c commit 287e798
Show file tree
Hide file tree
Showing 9 changed files with 233 additions and 148 deletions.
79 changes: 51 additions & 28 deletions doc/gambit.txi
Expand Up @@ -2237,6 +2237,30 @@ At level 3 and above variable bindings are displayed in the backtrace.
At level 5 and above garbage collection reports are displayed during
program execution.

@anchor{bLEVEL}
@item @code{@b{b}}@var{LEVEL}
@opindex -:debug=b@var{LEVEL}
@opindex -:db@var{LEVEL}
The value of the @code{repl-backtrace-detail-level} parameter object
is set to @var{LEVEL}, a digit from 0 to 9. This controls the amount
of backtrace detail that is displayed when an exception is caught by
the REPL
(@pxref{repl-backtrace-detail-level,,@code{repl-backtrace-detail-level}}).
By default the @code{repl-backtrace-detail-level} parameter object has
a value of 0 (no backtrace).

@anchor{hLEVEL}
@item @code{@b{h}}@var{LEVEL}
@opindex -:debug=h@var{LEVEL}
@opindex -:dh@var{LEVEL}
The value of the @code{repl-highlight-source-level} parameter object
is set to @var{LEVEL}, a digit from 0 to 9. This controls when to
pinpoint source code locations by displaying the relevant part of the
source code with the location highlighted
(@pxref{repl-backtrace-detail-level,,@code{repl-highlight-source-level}}).
By default the @code{repl-highlight-source-level} parameter object has
a value of 1 (only highlight source for exceptions caught by the REPL).

@item @code{@b{c}}
@opindex -:debug=c
@opindex -:dc
Expand Down Expand Up @@ -3257,32 +3281,36 @@ For example:

@end deffn

@deffn procedure repl-backtrace-detail-level @var{level}
@anchor{repl-backtrace-detail-level}
@deffn procedure repl-backtrace-detail-level @r{[}@var{level}@r{]}

The parameter object @code{repl-backtrace-detail-level} is bound to an
exact integer that controls the amount of backtrace detail that
is displayed when an exception is caught by the REPL. At a
@var{level} of 0, no backtrace is displayed. At a
@var{level} of 1, a backtrace is displayed with no environment information.
At a @var{level} of 2, a backtrace with the lexical environment is displayed.
At a @var{level} of 3, a backtrace with the lexical and dynamic
environments is displayed.
The initial value of the parameter object @code{repl-backtrace-detail-level}
is 0.

@end deffn

@deffn procedure repl-backtrace-highlight-source-level @var{level}

The parameter object @code{repl-backtrace-highlight-source-level} is bound to an
exact integer that controls the amount of backtrace detail that is
displayed when an exception is caught by the REPL. At a @var{level}
of 0, no backtrace is displayed. At a @var{level} of 1, a backtrace
is displayed with no environment information. At a @var{level} of 2,
a backtrace with the lexical environment is displayed. At a
@var{level} of 3, a backtrace with the lexical and dynamic
environments is displayed. At a @var{level} of 4, 5, or 6, the same
format is used as a @var{level} of 1, 2, or 3 respectively but the
backtrace includes frames that are normally hidden. The initial value
of the parameter object @code{repl-backtrace-detail-level} is 0 unless
overridden by the runtime options
(@pxref{bLEVEL,,@code{-:db@var{LEVEL}}}).
@end deffn

@anchor{repl-highlight-source-level}
@deffn procedure repl-highlight-source-level @r{[}@var{level}@r{]}

The parameter object @code{repl-highlight-source-level} is bound to an
exact integer that controls when to pinpoint source code locations
by displaying the relevant part of the source code with the location
highlighted. At a @var{level} of 0, no source highlighting is used.
At a @var{level} of 1, source highlighting is done when an exception
is caught by the REPL, but it is not used in the frames of a backtrace.
At a @var{level} of 2, source highlighting is done in all situations.
The initial value of the parameter object @code{repl-backtrace-highlight-source-level}
is 1.
The initial value of the parameter object @code{repl-highlight-source-level}
is 1 unless overridden by the runtime options (@pxref{hLEVEL,,@code{-:dh@var{LEVEL}}}).

@end deffn

Expand Down Expand Up @@ -5069,20 +5097,15 @@ same format as the REPL's @samp{,b} command.
The parameter @var{detail-level}, which defaults to the value of the
parameter object @code{repl-backtrace-detail-level} or @code{1}
whichever is larger, controls the amount of backtrace detail that is
displayed. At a @var{level} of 1, a backtrace is displayed with no
environment information. At a @var{level} of 2, a backtrace with the
lexical environment is displayed. At a @var{level} of 3, a backtrace
with the lexical and dynamic environments is displayed.
At a @var{level} of 4, 5, or 6, the same format is used as @var{level}-3
but the backtrace includes frames that are normally hidden.
displayed
(@pxref{repl-backtrace-detail-level,,@code{repl-backtrace-detail-level}}).

The parameter @var{highlight-source-level}, which defaults to the
value of the parameter object
@code{repl-backtrace-highlight-source-level}, controls when to
@code{repl-highlight-source-level}, controls when to
pinpoint source code locations by displaying the relevant part of the
source code with the location highlighted. At a @var{level} of 0 or
1, no source highlighting is used. At a @var{level} of 2, source
highlighting is done on each frame of the backtrace.
source code with the location highlighted
(@pxref{repl-highlight-source-level,,@code{repl-highlight-source-level}}).

The parameter @var{depth}, which defaults to 0, causes the frame numbers
to be offset by that value.
Expand Down
29 changes: 19 additions & 10 deletions include/gambit.h.in
Expand Up @@ -10404,6 +10404,11 @@ typedef struct ___setup_params_struct
#define ___DEBUG_SETTINGS_USER_INTR_QUIT 2
#define ___DEBUG_SETTINGS_USER_INTR_SHIFT 10

#define ___DEBUG_SETTINGS_BACKTRACE_DETAIL_LEVEL_MASK (15<<12)
#define ___DEBUG_SETTINGS_BACKTRACE_DETAIL_LEVEL_SHIFT 12
#define ___DEBUG_SETTINGS_HIGHLIGHT_SOURCE_LEVEL_MASK (15<<16)
#define ___DEBUG_SETTINGS_HIGHLIGHT_SOURCE_LEVEL_SHIFT 16

#define ___DEBUG_SETTINGS_LEVEL(settings) \
(((settings) & ___DEBUG_SETTINGS_LEVEL_MASK) \
>> ___DEBUG_SETTINGS_LEVEL_SHIFT)
Expand All @@ -10424,6 +10429,14 @@ typedef struct ___setup_params_struct
(((settings) & ___DEBUG_SETTINGS_USER_INTR_MASK) \
>> ___DEBUG_SETTINGS_LEVEL_SHIFT)

#define ___DEBUG_SETTINGS_BACKTRACE_DETAIL_LEVEL(settings) \
(((settings) & ___DEBUG_SETTINGS_BACKTRACE_DETAIL_LEVEL_MASK) \
>> ___DEBUG_SETTINGS_BACKTRACE_DETAIL_LEVEL_SHIFT)

#define ___DEBUG_SETTINGS_HIGHLIGHT_SOURCE_LEVEL(settings) \
(((settings) & ___DEBUG_SETTINGS_HIGHLIGHT_SOURCE_LEVEL_MASK) \
>> ___DEBUG_SETTINGS_HIGHLIGHT_SOURCE_LEVEL_SHIFT)

#define ___DEBUG_SETTINGS_INITIAL \
((1 << ___DEBUG_SETTINGS_LEVEL_SHIFT) | \
(___DEBUG_SETTINGS_UNCAUGHT_PRIMORDIAL \
Expand All @@ -10433,18 +10446,14 @@ typedef struct ___setup_params_struct
(___DEBUG_SETTINGS_REPL_STDIO \
<< ___DEBUG_SETTINGS_REPL_SHIFT) | \
(___DEBUG_SETTINGS_USER_INTR_QUIT \
<< ___DEBUG_SETTINGS_USER_INTR_SHIFT))
<< ___DEBUG_SETTINGS_USER_INTR_SHIFT) | \
(0 << ___DEBUG_SETTINGS_BACKTRACE_DETAIL_LEVEL_SHIFT) | \
(1 << ___DEBUG_SETTINGS_HIGHLIGHT_SOURCE_LEVEL_SHIFT))

#define ___DEBUG_SETTINGS_DEFAULT \
((1 << ___DEBUG_SETTINGS_LEVEL_SHIFT) | \
(___DEBUG_SETTINGS_UNCAUGHT_PRIMORDIAL \
<< ___DEBUG_SETTINGS_UNCAUGHT_SHIFT) | \
(___DEBUG_SETTINGS_ERROR_REPL \
<< ___DEBUG_SETTINGS_ERROR_SHIFT) | \
(___DEBUG_SETTINGS_REPL_STDIO \
<< ___DEBUG_SETTINGS_REPL_SHIFT) | \
(___DEBUG_SETTINGS_USER_INTR_REPL \
<< ___DEBUG_SETTINGS_USER_INTR_SHIFT))
((((___DEBUG_SETTINGS_INITIAL \
& ~___DEBUG_SETTINGS_ERROR_MASK) | ___DEBUG_SETTINGS_ERROR_REPL) \
& ~___DEBUG_SETTINGS_USER_INTR_MASK) | ___DEBUG_SETTINGS_USER_INTR_REPL)

#define ___MODULE_INSTALL_MODE_INITIAL ___MODULE_INSTALL_MODE_ASK_WHEN_REPL
#define ___MODULE_INSTALL_MODE_ASK_NEVER 0
Expand Down
10 changes: 10 additions & 0 deletions lib/_kernel#.scm
Expand Up @@ -276,6 +276,16 @@
(##define-macro (macro-debug-settings-user-intr-quit) 2)
(##define-macro (macro-debug-settings-user-intr-shift) 10)

(##define-macro (macro-debug-settings-backtrace-detail-level-mask)
(* 15 (expt 2 12)))
(##define-macro (macro-debug-settings-backtrace-detail-level-shift)
12)

(##define-macro (macro-debug-settings-highlight-source-level-mask)
(* 15 (expt 2 16)))
(##define-macro (macro-debug-settings-highlight-source-level-shift)
16)

(##define-macro (macro-debug-settings-level settings)
`(##fxwraplogical-shift-right
(##fxand ,settings
Expand Down
39 changes: 21 additions & 18 deletions lib/_repl.scm
Expand Up @@ -1153,15 +1153,15 @@
cont
port
(##fxmax detail-level (##repl-backtrace-detail-level))
(##repl-backtrace-highlight-source-level)
(##repl-highlight-source-level)
depth))

(define-prim (##display-continuation-backtrace
cont
#!optional
(port (##current-output-port))
(detail-level (##fxmax 1 (##repl-backtrace-detail-level)))
(highlight-source-level (##repl-backtrace-highlight-source-level))
(highlight-source-level (##repl-highlight-source-level))
(depth 0)
(max-head ##backtrace-default-max-head)
(max-tail ##backtrace-default-max-tail)
Expand Down Expand Up @@ -1228,7 +1228,7 @@
detail-level))
(hsl
(if (##eq? highlight-source-level (macro-absent-obj))
(##repl-backtrace-highlight-source-level)
(##repl-highlight-source-level)
highlight-source-level))
(d
(if (##eq? depth (macro-absent-obj))
Expand Down Expand Up @@ -1538,7 +1538,7 @@
port
#t ;; pinpoint?
0 ;; detail-level
(##repl-backtrace-highlight-source-level)
(##repl-highlight-source-level)
depth
##backtrace-default-max-head
##backtrace-default-max-tail
Expand Down Expand Up @@ -2454,23 +2454,31 @@

(define ##repl-backtrace-detail-level
(##make-parameter
0 ;; default is no backtrace
(##fxwraplogical-shift-right
(##fxand
(##set-debug-settings! 0 0)
(macro-debug-settings-backtrace-detail-level-mask))
(macro-debug-settings-backtrace-detail-level-shift))
(lambda (val)
(macro-check-fixnum val 1 (##repl-backtrace-detail-level val)
val))))

(define repl-backtrace-detail-level
##repl-backtrace-detail-level)

(define ##repl-backtrace-highlight-source-level
(define ##repl-highlight-source-level
(##make-parameter
1 ;; default is highlight source on errors, but not in backtrace frames
(##fxwraplogical-shift-right
(##fxand
(##set-debug-settings! 0 0)
(macro-debug-settings-highlight-source-level-mask))
(macro-debug-settings-highlight-source-level-shift))
(lambda (val)
(macro-check-fixnum val 1 (##repl-backtrace-highlight-source-level val)
(macro-check-fixnum val 1 (##repl-highlight-source-level val)
val))))

(define repl-backtrace-highlight-source-level
##repl-backtrace-highlight-source-level)
(define repl-highlight-source-level
##repl-highlight-source-level)

(define-prim (##step-handler leapable? $code rte execute-body . other)
(##declare (not interrupts-enabled) (environment-map))
Expand Down Expand Up @@ -3807,12 +3815,7 @@
(level (macro-debug-settings-level settings)))
(if (or (##not quit?)
(##fx>= level 1))
(##display-exception-in-context
exc
first
port
(##fxmax (##fxmin (##fx- level 1) 3)
(##repl-backtrace-detail-level))))
(##display-exception-in-context exc first port))
(and quit?
(##exit-with-exception exc))))
exc
Expand Down Expand Up @@ -3926,7 +3929,7 @@
#!optional
(port (##current-output-port))
(detail-level (##repl-backtrace-detail-level))
(highlight-source-level (##repl-backtrace-highlight-source-level))
(highlight-source-level (##repl-highlight-source-level))
(depth 0)
(max-head ##backtrace-default-max-head)
(max-tail ##backtrace-default-max-tail)
Expand Down Expand Up @@ -3998,7 +4001,7 @@
(kind #f)
(proc #f)
(port (##current-output-port))
(highlight-source-level (##repl-backtrace-highlight-source-level))
(highlight-source-level (##repl-highlight-source-level))
(line-numbers? ##highlight-source-default-line-numbers?)
(context-inner ##highlight-source-default-context-inner)
(context-outer ##highlight-source-default-context-outer))
Expand Down
2 changes: 1 addition & 1 deletion lib/_test/test/test.scm
Expand Up @@ -30,8 +30,8 @@
(define _test#call-thunk ;; redefined here to make location the same wether _test module is interpreted or compiled
(let () (declare (not inline)) (lambda (thunk) (##first-argument (thunk)))))

(repl-backtrace-highlight-source-level 0)

(repl-highlight-source-level 0)

(test-assert (< 1 2))

Expand Down
2 changes: 1 addition & 1 deletion lib/gambit#.scm
Expand Up @@ -688,7 +688,7 @@ remove
remq
rename-file
repl-backtrace-detail-level
repl-backtrace-highlight-source-level
repl-highlight-source-level
repl-error-port
repl-input-port
repl-output-port
Expand Down
2 changes: 1 addition & 1 deletion lib/gambit/gambit.sld
Expand Up @@ -1040,7 +1040,7 @@ remove
remq
rename-file
repl-backtrace-detail-level
repl-backtrace-highlight-source-level
repl-highlight-source-level
repl-error-port
repl-input-port
repl-output-port
Expand Down

0 comments on commit 287e798

Please sign in to comment.