From 8b7eb7400b166b1c2ef45a6d66999041f33c40bf Mon Sep 17 00:00:00 2001 From: Rebecca Turner Date: Fri, 2 Feb 2024 17:41:34 -0800 Subject: [PATCH] Enter debugger on `builtins.trace` with an option --- src/libexpr/eval-settings.hh | 3 +++ src/libexpr/primops.cc | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/src/libexpr/eval-settings.hh b/src/libexpr/eval-settings.hh index 2f6c12d45..757daebc0 100644 --- a/src/libexpr/eval-settings.hh +++ b/src/libexpr/eval-settings.hh @@ -127,6 +127,9 @@ struct EvalSettings : Config Setting maxCallDepth{this, 10000, "max-call-depth", "The maximum function call depth to allow before erroring."}; + + Setting builtinsTraceDebugger{this, false, "builtins-trace-debugger", + "Whether to enter the debugger on `builtins.trace` calls."}; }; extern EvalSettings evalSettings; diff --git a/src/libexpr/primops.cc b/src/libexpr/primops.cc index 5e2bbe16f..a24a2d018 100644 --- a/src/libexpr/primops.cc +++ b/src/libexpr/primops.cc @@ -995,6 +995,10 @@ static void prim_trace(EvalState & state, const PosIdx pos, Value * * args, Valu printError("trace: %1%", args[0]->string_view()); else printError("trace: %1%", ValuePrinter(state, *args[0])); + if (evalSettings.builtinsTraceDebugger && state.debugRepl && !state.debugTraces.empty()) { + const DebugTrace & last = state.debugTraces.front(); + state.runDebugRepl(nullptr, last.env, last.expr); + } state.forceValue(*args[1], pos); v = *args[1]; }