Files
lix/tests/functional/repl_characterization/data/debug_frames.test
T
blokyk f8b13b254b libcmd/repl: print backtraces from outer to innermost frame
before this change, the innermost frame was all the way at the top,
which means that in very nested code you'd have to scroll though
dozens or hundreds of frames before even seeing where you are, because
the last lines (which are immediately visible when the command returns)
would be the nix code's entry point and other outer frames instead,
which is rarely relevant.

this CL reverses this order, so that the innermost frames are the last
ones printed, and thus are immediately visible. (note that this is
already how errors are printed by nix in other contexts anyway, the
debugger's :bt is the only thing that prints the trace in "forward"
order.)

because `DebugState.traces()` use the homegrown `libutil::Generator`
instead of an stdlib container, we have to do that reversing ourselves,
in this case by just storing every element in an `std::list` (in reverse
order) and then traversing it. this is feels kinda dirty, but i don't
know any other way, and it's not exactly performance-critical.

Change-Id: I9f23e40e57f72a251d65a335b3bba3c3f77b935d
2026-04-28 12:09:13 +02:00

114 lines
3.9 KiB
Plaintext

@args --debugger
:c at the root repl is not allowed since no debugger is running yet
nix-repl> :c
error: command 'c' can only be used when the debugger is active
:c and other commands become available once a debugger starts
nix-repl> with {}; a
error: undefined variable 'a'
at «string»:1:10:
1| with {}; a
| ^
nix-repl> :?
The following commands are available:
<expr> Evaluate and print expression
<x> = <expr> Bind expression to variable
:?, :help Print help about all commands (this content)
:a, :add <expr> Add attributes from resulting set to scope
:b, :build <expr> Build a derivation
:bl, :build-with-gc-roots <expr> Build a derivation, creating GC roots in the working directory
:doc <expr> Show documentation for the provided function (experimental lambda support)
:e, :edit <expr> Open package or function in $EDITOR
:env Show environment stack
:i, :build-and-install <expr> Build derivation, then install result into current profile
:l, :load <path> Load Nix expression and add it to scope
:log <expr | .drv path> Show logs for a derivation
:p, :print <expr> Evaluate and print expression recursively
Strings are printed directly, without escaping.
:q, :quit Exit the REPL
:r, :reload Reload all files successfully loaded
:sh, :shell <expr> Build dependencies of derivation, then start nix-shell
:t, :type <expr> Describe result of evaluation
:te, :trace-enable [bool] Enable, disable, or toggle showing traces for errors
:u, :use <expr> Build derivation, then start nix-shell
Debug mode commands
:bt, :backtrace Show trace stack
:c, :continue Go until end of program, exception or builtins.break
:s, :step Go one step
:st, :show-trace [integer index] Show current trace. If an integer is provided, this switches to that stack beforehand. If the integer has an explicit + or - sign, it is treated as relative to the current stack index.
Flakes commands
:lf, :load-flake <flakeref> Load Nix flake and add it to the scope
we can now inspect state
nix-repl> :bt
1: error: Fake frame for debugging purposes
«string»:1:10
1| with {}; a
| ^
0: error: undefined variable 'a'
«string»:1:10
1| with {}; a
| ^
and resume execution
nix-repl> :c
error: undefined variable 'a'
at «string»:1:10:
1| with {}; a
| ^
the debugger is once again disabled
nix-repl> :c
error: command 'c' can only be used when the debugger is active
leaving the debugger from a toplevel error and entering it again doesn't leave old frames visible
nix-repl> with {}; a
error: undefined variable 'a'
at «string»:1:10:
1| with {}; a
| ^
nix-repl> :s
error: undefined variable 'a'
at «string»:1:10:
1| with {}; a
| ^
nix-repl> with {}; b
error: undefined variable 'b'
at «string»:1:10:
1| with {}; b
| ^
nix-repl> :bt
1: error: Fake frame for debugging purposes
«string»:1:10
1| with {}; b
| ^
0: error: undefined variable 'b'
«string»:1:10
1| with {}; b
| ^
exiting from here prints the error
nix-repl> :q
error: undefined variable 'b'
at «string»:1:10:
1| with {}; b
| ^