From c51b527c280ee08b3ce3ca6d229139c4292b3176 Mon Sep 17 00:00:00 2001 From: Ben Burdette Date: Fri, 7 Jan 2022 16:37:44 -0700 Subject: [PATCH] add env to DebugTrace --- src/libcmd/repl.cc | 1 + src/libexpr/eval.cc | 9 ++++++--- src/libexpr/eval.hh | 6 +++++- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/libcmd/repl.cc b/src/libcmd/repl.cc index 57463bd79..fdd63621f 100644 --- a/src/libcmd/repl.cc +++ b/src/libcmd/repl.cc @@ -927,6 +927,7 @@ void runRepl( DebugTrace {.pos = debugError->info().errPos, .expr = expr, + .env = *repl->env, .hint = debugError->info().msg }); diff --git a/src/libexpr/eval.cc b/src/libexpr/eval.cc index 585042b9d..e01147169 100644 --- a/src/libexpr/eval.cc +++ b/src/libexpr/eval.cc @@ -913,7 +913,7 @@ LocalNoInline(void addErrorTrace(Error & e, const Pos & pos, const char * s, con } LocalNoInline(std::unique_ptr - makeDebugTraceStacker(EvalState &state, Expr &expr, std::optional pos, const char * s, const string & s2)) + makeDebugTraceStacker(EvalState &state, Expr &expr, Env &env, std::optional pos, const char * s, const string & s2)) { return std::unique_ptr( new DebugTraceStacker( @@ -921,6 +921,7 @@ LocalNoInline(std::unique_ptr DebugTrace {.pos = pos, .expr = expr, + .env = env, .hint = hintfmt(s, s2) })); } @@ -1161,6 +1162,7 @@ void EvalState::cacheFile( makeDebugTraceStacker( *this, *e, + this->baseEnv, (e->getPos() ? std::optional(ErrPos(*e->getPos())) : std::nullopt), "while evaluating the file '%1%':", resolvedPath) : nullptr; @@ -1394,6 +1396,7 @@ void ExprSelect::eval(EvalState & state, Env & env, Value & v) makeDebugTraceStacker( state, *this, + env, *pos2, "while evaluating the attribute '%1%'", showAttrPath(state, env, attrPath)) @@ -1543,7 +1546,7 @@ void EvalState::callFunction(Value & fun, size_t nrArgs, Value * * args, Value & try { auto dts = debuggerHook ? - makeDebugTraceStacker(*this, *lambda.body, lambda.pos, + makeDebugTraceStacker(*this, *lambda.body, env2, lambda.pos, "while evaluating %s", (lambda.name.set() ? "'" + (string) lambda.name + "'" @@ -1948,7 +1951,7 @@ void EvalState::forceValueDeep(Value & v) debuggerHook ? // if the value is a thunk, we're evaling. otherwise no trace necessary. (i.value->isThunk() ? - makeDebugTraceStacker(*this, *v.thunk.expr, *i.pos, + makeDebugTraceStacker(*this, *v.thunk.expr, *v.thunk.env, *i.pos, "while evaluating the attribute '%1%'", i.name) : nullptr) : nullptr; diff --git a/src/libexpr/eval.hh b/src/libexpr/eval.hh index 5dbb9b5e5..3c74bb4a1 100644 --- a/src/libexpr/eval.hh +++ b/src/libexpr/eval.hh @@ -77,6 +77,7 @@ std::shared_ptr makeRegexCache(); struct DebugTrace { std::optional pos; const Expr &expr; + const Env &env; hintformat hint; }; @@ -203,7 +204,7 @@ public: trivial (i.e. doesn't require arbitrary computation). */ void evalFile(const Path & path, Value & v, bool mustBeTrivial = false); - /* Like `cacheFile`, but with an already parsed expression. */ + /* Like `evalFile`, but with an already parsed expression. */ void cacheFile( const Path & path, const Path & resolvedPath, @@ -416,6 +417,9 @@ class DebugTraceStacker { DebugTraceStacker(EvalState &evalState, DebugTrace t) :evalState(evalState), trace(t) { + + // evalState.debuggerHook(const Error & error, const Env & env, const Expr & expr); + evalState.debugTraces.push_front(t); } ~DebugTraceStacker()