From 667074b5867ffe40e3f1c59bd8e4ebf259f86aaa Mon Sep 17 00:00:00 2001 From: Ben Burdette Date: Mon, 16 May 2022 09:20:51 -0600 Subject: [PATCH] first whack at passing evalState as an arg to debuggerHook. --- src/libcmd/command.cc | 11 ++++++----- src/libcmd/command.hh | 2 +- src/libcmd/repl.cc | 2 +- src/libexpr/eval.cc | 2 +- src/libexpr/eval.hh | 4 ++-- src/libexpr/nixexpr.cc | 2 +- src/libexpr/nixexpr.hh | 2 +- src/libexpr/primops.cc | 2 +- src/libutil/ref.hh | 2 +- 9 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/libcmd/command.cc b/src/libcmd/command.cc index bf97a3de8..ee5102a6a 100644 --- a/src/libcmd/command.cc +++ b/src/libcmd/command.cc @@ -119,13 +119,14 @@ ref EvalCommand::getEvalState() #endif ; if (startReplOnEvalErrors) - debuggerHook = [evalState{ref(evalState)}](const Error * error, const Env & env, const Expr & expr) { + // debuggerHook = [evalState{ref(evalState)}](const Error * error, const Env & env, const Expr & expr) { + debuggerHook = [](const EvalState & evalState, const Error * error, const Env & env, const Expr & expr) { auto dts = error && expr.getPos() ? std::make_unique( - *evalState, + evalState, DebugTrace { - .pos = error->info().errPos ? *error->info().errPos : evalState->positions[expr.getPos()], + .pos = error->info().errPos ? *error->info().errPos : evalState.positions[expr.getPos()], .expr = expr, .env = env, .hint = error->info().msg, @@ -137,8 +138,8 @@ ref EvalCommand::getEvalState() printError("%s\n\n" ANSI_BOLD "Starting REPL to allow you to inspect the current state of the evaluator.\n" ANSI_NORMAL, error->what()); if (expr.staticEnv) { - auto vm = mapStaticEnvBindings(evalState->symbols, *expr.staticEnv.get(), env); - runRepl(evalState, *vm); + auto vm = mapStaticEnvBindings(evalState.symbols, *expr.staticEnv.get(), env); + runRepl(*const_cast(&evalState), *vm); } }; } diff --git a/src/libcmd/command.hh b/src/libcmd/command.hh index 196bd3aaa..8b37be901 100644 --- a/src/libcmd/command.hh +++ b/src/libcmd/command.hh @@ -274,7 +274,7 @@ void printClosureDiff( void runRepl( - ref evalState, + EvalState & evalState, const ValMap & extraEnv); } diff --git a/src/libcmd/repl.cc b/src/libcmd/repl.cc index deac3d408..cb5d5bb34 100644 --- a/src/libcmd/repl.cc +++ b/src/libcmd/repl.cc @@ -1011,7 +1011,7 @@ std::ostream & NixRepl::printValue(std::ostream & str, Value & v, unsigned int m } void runRepl( - ref evalState, + EvalState& evalState, const ValMap & extraEnv) { auto repl = std::make_unique(evalState); diff --git a/src/libexpr/eval.cc b/src/libexpr/eval.cc index d9ea92cc0..3c998f7b6 100644 --- a/src/libexpr/eval.cc +++ b/src/libexpr/eval.cc @@ -1044,7 +1044,7 @@ DebugTraceStacker::DebugTraceStacker(EvalState & evalState, DebugTrace t) { evalState.debugTraces.push_front(trace); if (evalState.debugStop && debuggerHook) - debuggerHook(nullptr, trace.env, trace.expr); + debuggerHook(evalState, nullptr, trace.env, trace.expr); } void Value::mkString(std::string_view s) diff --git a/src/libexpr/eval.hh b/src/libexpr/eval.hh index f274278be..26717a6f8 100644 --- a/src/libexpr/eval.hh +++ b/src/libexpr/eval.hh @@ -136,7 +136,7 @@ public: void debugThrow(const E &error, const Env & env, const Expr & expr) const { if (debuggerHook) - debuggerHook(&error, env, expr); + debuggerHook(*this, &error, env, expr); throw error; } @@ -150,7 +150,7 @@ public: // DebugTrace stack. if (debuggerHook && !debugTraces.empty()) { const DebugTrace & last = debugTraces.front(); - debuggerHook(&e, last.env, last.expr); + debuggerHook(*this, &e, last.env, last.expr); } throw e; diff --git a/src/libexpr/nixexpr.cc b/src/libexpr/nixexpr.cc index 213cf93fa..a7b7b8aad 100644 --- a/src/libexpr/nixexpr.cc +++ b/src/libexpr/nixexpr.cc @@ -10,7 +10,7 @@ namespace nix { /* Launch the nix debugger */ -std::function debuggerHook; +std::function debuggerHook; /* Displaying abstract syntax trees. */ diff --git a/src/libexpr/nixexpr.hh b/src/libexpr/nixexpr.hh index c4a509f31..856676033 100644 --- a/src/libexpr/nixexpr.hh +++ b/src/libexpr/nixexpr.hh @@ -22,7 +22,7 @@ MakeError(UndefinedVarError, Error); MakeError(MissingArgumentError, EvalError); MakeError(RestrictedPathError, Error); -extern std::function debuggerHook; +extern std::function debuggerHook; /* Position objects. */ diff --git a/src/libexpr/primops.cc b/src/libexpr/primops.cc index ff5ae8809..e56e6314b 100644 --- a/src/libexpr/primops.cc +++ b/src/libexpr/primops.cc @@ -765,7 +765,7 @@ static RegisterPrimOp primop_break({ }); auto & dt = state.debugTraces.front(); - debuggerHook(&error, dt.env, dt.expr); + debuggerHook(state, &error, dt.env, dt.expr); if (state.debugQuit) { // If the user elects to quit the repl, throw an exception. diff --git a/src/libutil/ref.hh b/src/libutil/ref.hh index f9578afc7..bf26321db 100644 --- a/src/libutil/ref.hh +++ b/src/libutil/ref.hh @@ -7,7 +7,7 @@ namespace nix { /* A simple non-nullable reference-counted pointer. Actually a wrapper - around std::shared_ptr that prevents non-null constructions. */ + around std::shared_ptr that prevents null constructions. */ template class ref {