aboutsummaryrefslogtreecommitdiff
path: root/src/libexpr/eval.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/libexpr/eval.cc')
-rw-r--r--src/libexpr/eval.cc19
1 files changed, 17 insertions, 2 deletions
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: