libexpr: refactor fallibly doing stuff on debug traces (NFC)

Change-Id: I009ce2ea424938507223fc6b3cf3b1236a6a6964
This commit is contained in:
Qyriad
2025-11-20 17:52:29 +01:00
parent 0ade82d23a
commit 6192cbebac
4 changed files with 20 additions and 7 deletions
+9
View File
@@ -2924,6 +2924,15 @@ Expr & Evaluator::parseStdin()
);
}
std::optional<DebugTrace const *> Evaluator::nextDebugTrace() const
{
if (!debug) {
return std::nullopt;
}
return debug->traces().next();
}
kj::Promise<Result<EvalPaths::PathResult<SourcePath, ThrownError>>>
EvalPaths::findFile(const std::string_view path)
+3
View File
@@ -568,6 +568,9 @@ public:
*/
void evalLazily(Expr & e, Value & v);
/** If debugging is enabled, returns the next trace. Otherwise, std::nullopt. */
std::optional<DebugTrace const *> nextDebugTrace() const;
private:
Expr * parse(
char * text,
+7 -6
View File
@@ -629,7 +629,7 @@ static void prim_genericClosure(EvalState & state, Value * * args, Value & v)
static void prim_break(EvalState & state, Value * * args, Value & v)
{
if (auto trace = state.ctx.debug ? state.ctx.debug->traces().next() : std::nullopt) {
if (auto const trace = state.ctx.nextDebugTrace()) {
auto error = EvalError(ErrorInfo {
.level = lvlInfo,
.msg = HintFmt("breakpoint reached"),
@@ -758,12 +758,13 @@ static void prim_trace(EvalState & state, Value * * args, Value & v)
printError("trace: %1%", Uncolored(args[0]->str()));
else
printError("trace: %1%", Uncolored(ValuePrinter(state, *args[0])));
if (auto last = evalSettings.builtinsTraceDebugger && state.ctx.debug
? state.ctx.debug->traces().next()
: std::nullopt)
{
state.ctx.debug->onEvalError(nullptr, (*last)->env, (*last)->expr);
if (evalSettings.debuggerOnTrace) {
if (auto const trace = state.ctx.nextDebugTrace()) {
state.ctx.debug->onEvalError(nullptr, (*trace)->env, (*trace)->expr);
}
}
state.forceValue(*args[1], noPos);
v = *args[1];
}
+1 -1
View File
@@ -1,6 +1,6 @@
---
name: debugger-on-trace
internalName: builtinsTraceDebugger
internalName: debuggerOnTrace
type: bool
default: false
---