aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Burdette <bburdette@gmail.com>2022-01-07 16:37:44 -0700
committerBen Burdette <bburdette@gmail.com>2022-01-07 16:37:44 -0700
commitc51b527c280ee08b3ce3ca6d229139c4292b3176 (patch)
tree3d8c7dc9f74bed1876aed2d78785099b2745d1f6
parent84aeb74377ce41408680256813870271999e8208 (diff)
add env to DebugTrace
-rw-r--r--src/libcmd/repl.cc1
-rw-r--r--src/libexpr/eval.cc9
-rw-r--r--src/libexpr/eval.hh6
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<DebugTraceStacker>
- makeDebugTraceStacker(EvalState &state, Expr &expr, std::optional<ErrPos> pos, const char * s, const string & s2))
+ makeDebugTraceStacker(EvalState &state, Expr &expr, Env &env, std::optional<ErrPos> pos, const char * s, const string & s2))
{
return std::unique_ptr<DebugTraceStacker>(
new DebugTraceStacker(
@@ -921,6 +921,7 @@ LocalNoInline(std::unique_ptr<DebugTraceStacker>
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<RegexCache> makeRegexCache();
struct DebugTrace {
std::optional<ErrPos> 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()