diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/libcmd/repl.cc | 8 | ||||
-rw-r--r-- | src/libexpr/eval.cc | 19 | ||||
-rw-r--r-- | src/libexpr/eval.hh | 2 |
3 files changed, 20 insertions, 9 deletions
diff --git a/src/libcmd/repl.cc b/src/libcmd/repl.cc index ab7d7f18c..45b56d012 100644 --- a/src/libcmd/repl.cc +++ b/src/libcmd/repl.cc @@ -233,13 +233,7 @@ ReplExitStatus NixRepl::mainLoop() printMsg(lvlError, e.msg()); } } catch (EvalError & e) { - // in debugger mode, an EvalError should trigger another repl session. - // when that session returns the exception will land here. No need to show it again; - // show the error for this repl session instead. - if (state->debugRepl && !state->debugTraces.empty()) - showDebugTrace(std::cout, state->positions, state->debugTraces.front()); - else - printMsg(lvlError, e.msg()); + printMsg(lvlError, e.msg()); } catch (Error & e) { printMsg(lvlError, e.msg()); } catch (Interrupted & e) { diff --git a/src/libexpr/eval.cc b/src/libexpr/eval.cc index bef0effb6..b24f10c24 100644 --- a/src/libexpr/eval.cc +++ b/src/libexpr/eval.cc @@ -778,10 +778,24 @@ std::unique_ptr<ValMap> mapStaticEnvBindings(const SymbolTable & st, const Stati return vm; } +/** + * Sets `inDebugger` to true on construction and false on destruction. + */ +class DebuggerGuard { + bool & inDebugger; +public: + DebuggerGuard(bool & inDebugger) : inDebugger(inDebugger) { + inDebugger = true; + } + ~DebuggerGuard() { + inDebugger = false; + } +}; + void EvalState::runDebugRepl(const Error * error, const Env & env, const Expr & expr) { - // double check we've got the debugRepl function pointer. - if (!debugRepl) + // Make sure we have a debugger to run and we're not already in a debugger. + if (!debugRepl || inDebugger) return; auto dts = @@ -808,6 +822,7 @@ void EvalState::runDebugRepl(const Error * error, const Env & env, const Expr & auto se = getStaticEnv(expr); if (se) { auto vm = mapStaticEnvBindings(symbols, *se.get(), env); + DebuggerGuard _guard(inDebugger); auto exitStatus = (debugRepl)(ref<EvalState>(shared_from_this()), *vm); switch (exitStatus) { case ReplExitStatus::QuitAll: diff --git a/src/libexpr/eval.hh b/src/libexpr/eval.hh index d2d8140e9..2291d618c 100644 --- a/src/libexpr/eval.hh +++ b/src/libexpr/eval.hh @@ -152,6 +152,7 @@ struct DebugTrace { bool isError; }; + class EvalState : public std::enable_shared_from_this<EvalState> { public: @@ -210,6 +211,7 @@ public: */ ReplExitStatus (* debugRepl)(ref<EvalState> es, const ValMap & extraEnv); bool debugStop; + bool inDebugger = false; int trylevel; std::list<DebugTrace> debugTraces; std::map<const Expr*, const std::shared_ptr<const StaticEnv>> exprEnvs; |