makeDebugTraceStacker

This commit is contained in:
Ben Burdette 2021-12-23 09:08:41 -07:00
parent 1bda6a01e1
commit deb1fd66e8

View file

@ -49,10 +49,8 @@ class DebugTraceStacker {
// assert(evalState.debugTraces.front() == trace); // assert(evalState.debugTraces.front() == trace);
evalState.debugTraces.pop_front(); evalState.debugTraces.pop_front();
} }
EvalState &evalState; EvalState &evalState;
Trace trace; Trace trace;
}; };
static char * dupString(const char * s) static char * dupString(const char * s)
@ -882,7 +880,6 @@ LocalNoInlineNoReturn(void throwUndefinedVarError(const Pos & pos, const char *
}); });
if (debuggerHook && expr) { if (debuggerHook && expr) {
std::cout << "throwUndefinedVarError debuggerHook" << std::endl; std::cout << "throwUndefinedVarError debuggerHook" << std::endl;
debuggerHook(error, env, *expr); debuggerHook(error, env, *expr);
} }
@ -913,15 +910,17 @@ LocalNoInline(void addErrorTrace(Error & e, const Pos & pos, const char * s, con
e.addTrace(pos, s, s2); e.addTrace(pos, s, s2);
} }
// LocalNoInline(void makeErrorTrace(Error & e, const char * s, const string & s2)) LocalNoInline(std::unique_ptr<DebugTraceStacker>
// { makeDebugTraceStacker(EvalState &state, std::optional<ErrPos> pos, const char * s, const string & s2))
// Trace { .pos = e, .hint = hint } {
// } return std::unique_ptr<DebugTraceStacker>(
new DebugTraceStacker(
state,
Trace {.pos = pos,
.hint = hintfmt(s, s2)
}));
}
// LocalNoInline(void makeErrorTrace(Error & e, const Pos & pos, const char * s, const string & s2))
// {
// return Trace { .pos = e, .hint = hintfmt(s, s2); };
// }
void mkString(Value & v, const char * s) void mkString(Value & v, const char * s)
{ {
@ -1127,20 +1126,6 @@ void EvalState::resetFileCache()
fileParseCache.clear(); fileParseCache.clear();
} }
// class DebugTraceStacker {
// DebugTraceStacker(std::ref<EvalState> evalState, std::ref<Trace> t)
// :evalState(evalState), trace(t)
// {
// evalState->debugTraces.push_front(t);
// }
// ~DebugTraceStacker() {
// assert(evalState->debugTraces.pop_front() == trace);
// }
// std::ref<EvalState> evalState;
// std::ref<Trace> trace;
// };
@ -1154,15 +1139,14 @@ void EvalState::cacheFile(
fileParseCache[resolvedPath] = e; fileParseCache[resolvedPath] = e;
try { try {
std::unique_ptr<DebugTraceStacker> dts = debuggerHook ? std::unique_ptr<DebugTraceStacker> dts =
std::unique_ptr<DebugTraceStacker>(new DebugTraceStacker(*this, debuggerHook ?
Trace { .pos = (e->getPos() ? std::optional(ErrPos(*e->getPos())) : std::nullopt), makeDebugTraceStacker(
.hint = hintfmt("while evaluating the file '%1%':", resolvedPath) *this,
} (e->getPos() ? std::optional(ErrPos(*e->getPos())) : std::nullopt),
)) : std::unique_ptr<DebugTraceStacker>(); "while evaluating the file '%1%':", resolvedPath)
: std::unique_ptr<DebugTraceStacker>();
// Trace( .pos = (e->getPos() ? std::optional(ErrPos(*e->getPos())):
// std::nullopt), hintfmt("while evaluating the file '%1%':", resolvedPath));
// Enforce that 'flake.nix' is a direct attrset, not a // Enforce that 'flake.nix' is a direct attrset, not a
// computation. // computation.
if (mustBeTrivial && if (mustBeTrivial &&
@ -1389,14 +1373,11 @@ void ExprSelect::eval(EvalState & state, Env & env, Value & v)
try { try {
std::unique_ptr<DebugTraceStacker> dts = std::unique_ptr<DebugTraceStacker> dts =
debuggerHook ? debuggerHook ?
std::unique_ptr<DebugTraceStacker>( makeDebugTraceStacker(
new DebugTraceStacker(
state, state,
Trace { .pos = *pos2, *pos2,
.hint = hintfmt(
"while evaluating the attribute '%1%'", "while evaluating the attribute '%1%'",
showAttrPath(state, env, attrPath)) showAttrPath(state, env, attrPath))
}))
: std::unique_ptr<DebugTraceStacker>(); : std::unique_ptr<DebugTraceStacker>();
for (auto & i : attrPath) { for (auto & i : attrPath) {
@ -1543,19 +1524,13 @@ void EvalState::callFunction(Value & fun, size_t nrArgs, Value * * args, Value &
try { try {
std::unique_ptr<DebugTraceStacker> dts = std::unique_ptr<DebugTraceStacker> dts =
debuggerHook ? debuggerHook ?
std::unique_ptr<DebugTraceStacker>( makeDebugTraceStacker(*this, lambda.pos,
new DebugTraceStacker(
*this,
Trace {.pos = lambda.pos,
.hint = hintfmt(
"while evaluating %s", "while evaluating %s",
(lambda.name.set() (lambda.name.set()
? "'" + (string) lambda.name + "'" ? "'" + (string) lambda.name + "'"
: "anonymous lambda")) : "anonymous lambda"))
}))
: std::unique_ptr<DebugTraceStacker>(); : std::unique_ptr<DebugTraceStacker>();
lambda.body->eval(*this, env2, vCur); lambda.body->eval(*this, env2, vCur);
} catch (Error & e) { } catch (Error & e) {
std::cout << "eval showErrorInfo showTrace: " << loggerSettings.showTrace.get() << std::endl; std::cout << "eval showErrorInfo showTrace: " << loggerSettings.showTrace.get() << std::endl;
@ -1952,16 +1927,10 @@ void EvalState::forceValueDeep(Value & v)
try { try {
std::unique_ptr<DebugTraceStacker> dts = std::unique_ptr<DebugTraceStacker> dts =
debuggerHook ? debuggerHook ?
std::unique_ptr<DebugTraceStacker>( makeDebugTraceStacker(*this, *i.pos,
new DebugTraceStacker(
*this,
Trace { .pos = *i.pos,
.hint = hintfmt(
"while evaluating the attribute '%1%'", i.name) "while evaluating the attribute '%1%'", i.name)
}))
: std::unique_ptr<DebugTraceStacker>(); : std::unique_ptr<DebugTraceStacker>();
recurse(*i.value); recurse(*i.value);
} catch (Error & e) { } catch (Error & e) {
addErrorTrace(e, *i.pos, "while evaluating the attribute '%1%'", i.name); addErrorTrace(e, *i.pos, "while evaluating the attribute '%1%'", i.name);