libcmd/repl: allow :st argument to be relative to current stack index
See [lix-project/lix#1156], but basically currently the `:st <n>` debugger command doesn't allow any negative indices, and putting a plus sign in front of the arg doesn't change anything; thus, we can exploit that "design space" to allow users to move between different stack frames easily, by simply prepending their arg with a +/- sign. The actual behavior is little more nuanced when you account for errors: as suggested by @pennae (thanks! :), when the user inputs an offset that would result in an invalid frame index, the debugger instead clamps it to the closest bound (i.e. 0 for negative offsets, $maxFrame for positive ones) and just prints a warning. Fixes #1156 [lix-project/lix#1156]: https://git.lix.systems/lix-project/lix/issues/1156 Change-Id: I02a0cdb6aaebbdb0515308880a3bf9c0d2fcd25e
This commit is contained in:
@@ -40,21 +40,11 @@ frames from 0 up to 4 work fine
|
||||
Env level 2
|
||||
abort baseNameOf break builtins derivation derivationStrict dirOf false fetchGit fetchMercurial fetchTarball fetchTree fromTOML import isNull map null placeholder removeAttrs scopedImport throw toString true
|
||||
|
||||
negative frames print an error
|
||||
nix-repl> :st -1
|
||||
error: stack index must be between 0 and 4, but was -1
|
||||
|
||||
nix-repl> :st -100
|
||||
error: stack index must be between 0 and 4, but was -100
|
||||
|
||||
positives frames out of bounds also print an error
|
||||
absolute frames out of bounds print an error
|
||||
nix-repl> :st 5
|
||||
error: stack index must be between 0 and 4, but was 5
|
||||
|
||||
nix-repl> :st 100
|
||||
error: stack index must be between 0 and 4, but was 100
|
||||
|
||||
argument-less :st is still at the same after oob
|
||||
argument-less :st is still at the same after absolute oob
|
||||
nix-repl> :st
|
||||
|
||||
4: while evaluating a 'let' expression
|
||||
@@ -72,6 +62,49 @@ argument-less :st is still at the same after oob
|
||||
Env level 2
|
||||
abort baseNameOf break builtins derivation derivationStrict dirOf false fetchGit fetchMercurial fetchTarball fetchTree fromTOML import isNull map null placeholder removeAttrs scopedImport throw toString true
|
||||
|
||||
positive relative frames oob clamp to upper bound and print a warning
|
||||
nix-repl> :st +5
|
||||
|
||||
4: while evaluating a 'let' expression
|
||||
«string»:1:1
|
||||
|
||||
1| let f = _: throw "x_x"; x = f 5; in x
|
||||
| ^
|
||||
|
||||
Env level 0
|
||||
static: f x
|
||||
|
||||
Env level 1
|
||||
static:
|
||||
|
||||
Env level 2
|
||||
abort baseNameOf break builtins derivation derivationStrict dirOf false fetchGit fetchMercurial fetchTarball fetchTree fromTOML import isNull map null placeholder removeAttrs scopedImport throw toString true
|
||||
|
||||
warning: stopped at stack frame 4, cannot go any higher
|
||||
|
||||
negative relative frames oob clamp to lower bound and print a warning
|
||||
nix-repl> :st -5
|
||||
|
||||
0: error: x_x
|
||||
«string»:1:12
|
||||
|
||||
1| let f = _: throw "x_x"; x = f 5; in x
|
||||
| ^
|
||||
|
||||
Env level 0
|
||||
static: _
|
||||
|
||||
Env level 1
|
||||
static: f x
|
||||
|
||||
Env level 2
|
||||
static:
|
||||
|
||||
Env level 3
|
||||
abort baseNameOf break builtins derivation derivationStrict dirOf false fetchGit fetchMercurial fetchTarball fetchTree fromTOML import isNull map null placeholder removeAttrs scopedImport throw toString true
|
||||
|
||||
warning: stopped at stack frame 0, cannot go any deeper
|
||||
|
||||
quit
|
||||
nix-repl> :quit
|
||||
error: x_x
|
||||
|
||||
Reference in New Issue
Block a user