Skip to content

Commit

Permalink
Merge pull request NixOS#5416 from bburdette/debug-exploratory-PR
Browse files Browse the repository at this point in the history
--debugger flag
  • Loading branch information
edolstra authored May 26, 2022
2 parents d8398d3 + 9068d32 commit 5f097fb
Show file tree
Hide file tree
Showing 17 changed files with 906 additions and 310 deletions.
13 changes: 13 additions & 0 deletions doc/manual/src/release-notes/rl-next.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,18 @@
Selecting derivation outputs using the attribute selection syntax
(e.g. `nixpkgs#glibc.dev`) no longer works.

* Running nix with the new `--debugger` flag will cause it to start a repl session if
there is an exception thrown during eval, or if `builtins.break` is called. From
there one can inspect symbol values and evaluate nix expressions. In debug mode
the following new repl commands are available:
```
:env Show env stack
:bt Show trace stack
:st Show current trace
:st <idx> Change to another trace in the stack
:c Go until end of program, exception, or builtins.break().
:s Go one step
```

* `builtins.fetchTree` (and flake inputs) can now be used to fetch plain files
over the `http(s)` and `file` protocols in addition to directory tarballs.
12 changes: 11 additions & 1 deletion src/libcmd/command.cc
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ ref<Store> CopyCommand::getDstStore()

EvalCommand::EvalCommand()
{
addFlag({
.longName = "debugger",
.description = "start an interactive environment if evaluation fails",
.handler = {&startReplOnEvalErrors, true},
});
}

EvalCommand::~EvalCommand()
Expand All @@ -103,7 +108,7 @@ ref<Store> EvalCommand::getEvalStore()

ref<EvalState> EvalCommand::getEvalState()
{
if (!evalState)
if (!evalState) {
evalState =
#if HAVE_BOEHMGC
std::allocate_shared<EvalState>(traceable_allocator<EvalState>(),
Expand All @@ -113,6 +118,11 @@ ref<EvalState> EvalCommand::getEvalState()
searchPath, getEvalStore(), getStore())
#endif
;

if (startReplOnEvalErrors) {
evalState->debugRepl = &runRepl;
};
}
return ref<EvalState>(evalState);
}

Expand Down
6 changes: 6 additions & 0 deletions src/libcmd/command.hh
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ struct CopyCommand : virtual StoreCommand

struct EvalCommand : virtual StoreCommand, MixEvalArgs
{
bool startReplOnEvalErrors = false;

EvalCommand();

~EvalCommand();
Expand Down Expand Up @@ -270,4 +272,8 @@ void printClosureDiff(
const StorePath & afterPath,
std::string_view indent);


void runRepl(
ref<EvalState> evalState,
const ValMap & extraEnv);
}
4 changes: 2 additions & 2 deletions src/libcmd/local.mk
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ libcmd_DIR := $(d)

libcmd_SOURCES := $(wildcard $(d)/*.cc)

libcmd_CXXFLAGS += -I src/libutil -I src/libstore -I src/libexpr -I src/libmain -I src/libfetchers
libcmd_CXXFLAGS += -I src/libutil -I src/libstore -I src/libexpr -I src/libmain -I src/libfetchers -I src/nix

libcmd_LDFLAGS += $(LOWDOWN_LIBS) -pthread
libcmd_LDFLAGS = $(EDITLINE_LIBS) -llowdown -pthread

libcmd_LIBS = libstore libutil libexpr libmain libfetchers

Expand Down
Loading

0 comments on commit 5f097fb

Please sign in to comment.