From 8b7eb7400b166b1c2ef45a6d66999041f33c40bf Mon Sep 17 00:00:00 2001 From: Rebecca Turner Date: Fri, 2 Feb 2024 17:41:34 -0800 Subject: [PATCH 1/3] 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]; } From 4440eb54e7274734ec442081f55023853efa8708 Mon Sep 17 00:00:00 2001 From: Rebecca Turner Date: Mon, 5 Feb 2024 13:03:08 -0800 Subject: [PATCH 2/3] Add release note --- doc/manual/rl-next/debugger-on-trace.md | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 doc/manual/rl-next/debugger-on-trace.md diff --git a/doc/manual/rl-next/debugger-on-trace.md b/doc/manual/rl-next/debugger-on-trace.md new file mode 100644 index 000000000..d4e55d59c --- /dev/null +++ b/doc/manual/rl-next/debugger-on-trace.md @@ -0,0 +1,9 @@ +--- +synopsis: Enter the `--debugger` when `builtins.trace` is called if `builtins-trace-debugger` is set +prs: 9914 +--- + +If the `builtins-trace-debugger` option is set and `--debugger` is given, +`builtins.trace` calls will behave similarly to `builtins.break` and will enter +the debug REPL. This is useful for determining where warnings are being emitted +from. From b111fba8cd3c5d492565b5dc22a493ed58ef8571 Mon Sep 17 00:00:00 2001 From: Rebecca Turner Date: Wed, 21 Feb 2024 09:07:39 -0800 Subject: [PATCH 3/3] Add documentation, rename to `debugger-on-trace` --- doc/manual/rl-next/debugger-on-trace.md | 4 ++-- src/libexpr/eval-settings.hh | 11 +++++++++-- src/libexpr/primops.cc | 6 ++++++ 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/doc/manual/rl-next/debugger-on-trace.md b/doc/manual/rl-next/debugger-on-trace.md index d4e55d59c..721928550 100644 --- a/doc/manual/rl-next/debugger-on-trace.md +++ b/doc/manual/rl-next/debugger-on-trace.md @@ -1,9 +1,9 @@ --- -synopsis: Enter the `--debugger` when `builtins.trace` is called if `builtins-trace-debugger` is set +synopsis: Enter the `--debugger` when `builtins.trace` is called if `debugger-on-trace` is set prs: 9914 --- -If the `builtins-trace-debugger` option is set and `--debugger` is given, +If the `debugger-on-trace` option is set and `--debugger` is given, `builtins.trace` calls will behave similarly to `builtins.break` and will enter the debug REPL. This is useful for determining where warnings are being emitted from. diff --git a/src/libexpr/eval-settings.hh b/src/libexpr/eval-settings.hh index 757daebc0..b5783d28f 100644 --- a/src/libexpr/eval-settings.hh +++ b/src/libexpr/eval-settings.hh @@ -128,8 +128,15 @@ 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."}; + Setting builtinsTraceDebugger{this, false, "debugger-on-trace", + R"( + If set to true and the `--debugger` flag is given, + [`builtins.trace`](@docroot@/language/builtins.md#builtins-trace) will + enter the debugger like + [`builtins.break`](@docroot@/language/builtins.md#builtins-break). + + This is useful for debugging warnings in third-party Nix code. + )"}; }; extern EvalSettings evalSettings; diff --git a/src/libexpr/primops.cc b/src/libexpr/primops.cc index a24a2d018..0ee146359 100644 --- a/src/libexpr/primops.cc +++ b/src/libexpr/primops.cc @@ -1010,6 +1010,12 @@ static RegisterPrimOp primop_trace({ Evaluate *e1* and print its abstract syntax representation on standard error. Then return *e2*. This function is useful for debugging. + + If the + [`debugger-on-trace`](@docroot@/command-ref/conf-file.md#conf-debugger-on-trace) + option is set to `true` and the `--debugger` flag is given, the + interactive debugger will be started when `trace` is called (like + [`break`](@docroot@/language/builtins.md#builtins-break)). )", .fun = prim_trace, });