forked from lix-project/lix
DebugTrace
This commit is contained in:
parent
deb1fd66e8
commit
e5eebda194
|
@ -84,7 +84,7 @@ ref<EvalState> EvalCommand::getEvalState()
|
|||
if (expr.staticenv)
|
||||
{
|
||||
auto vm = mapStaticEnvBindings(*expr.staticenv.get(), env);
|
||||
runRepl(evalState, ref<const Error>(&error), *vm);
|
||||
runRepl(evalState, &error, *vm);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -314,8 +314,6 @@ void printClosureDiff(
|
|||
|
||||
void runRepl(
|
||||
ref<EvalState> evalState,
|
||||
std::optional<ref<const Error>> debugError,
|
||||
const Error *debugError,
|
||||
const std::map<std::string, Value *> & extraEnv);
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -50,7 +50,7 @@ struct NixRepl
|
|||
ref<EvalState> state;
|
||||
Bindings * autoArgs;
|
||||
|
||||
std::optional<ref<const Error>> debugError;
|
||||
const Error *debugError;
|
||||
|
||||
Strings loadedFiles;
|
||||
|
||||
|
@ -470,13 +470,12 @@ bool NixRepl::processLine(string line)
|
|||
|
||||
}
|
||||
else if (arg == "error") {
|
||||
if (this->debugError.has_value()) {
|
||||
// TODO user --show-trace setting?
|
||||
showErrorInfo(std::cout, (*debugError)->info(), true);
|
||||
if (this->debugError) {
|
||||
showErrorInfo(std::cout, debugError->info(), true);
|
||||
}
|
||||
else
|
||||
{
|
||||
notice("error information not available");
|
||||
notice("error information not available");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -893,7 +892,7 @@ std::ostream & NixRepl::printValue(std::ostream & str, Value & v, unsigned int m
|
|||
|
||||
void runRepl(
|
||||
ref<EvalState> evalState,
|
||||
std::optional<ref<const Error>> debugError,
|
||||
const Error *debugError,
|
||||
const std::map<std::string, Value *> & extraEnv)
|
||||
{
|
||||
auto repl = std::make_unique<NixRepl>(evalState);
|
||||
|
|
|
@ -40,7 +40,7 @@ std::function<void(const Error & error, const Env & env, const Expr & expr)> deb
|
|||
|
||||
class DebugTraceStacker {
|
||||
public:
|
||||
DebugTraceStacker(EvalState &evalState, Trace t)
|
||||
DebugTraceStacker(EvalState &evalState, DebugTrace t)
|
||||
:evalState(evalState), trace(t)
|
||||
{
|
||||
evalState.debugTraces.push_front(t);
|
||||
|
@ -50,7 +50,7 @@ class DebugTraceStacker {
|
|||
evalState.debugTraces.pop_front();
|
||||
}
|
||||
EvalState &evalState;
|
||||
Trace trace;
|
||||
DebugTrace trace;
|
||||
};
|
||||
|
||||
static char * dupString(const char * s)
|
||||
|
@ -911,12 +911,14 @@ LocalNoInline(void addErrorTrace(Error & e, const Pos & pos, const char * s, con
|
|||
}
|
||||
|
||||
LocalNoInline(std::unique_ptr<DebugTraceStacker>
|
||||
makeDebugTraceStacker(EvalState &state, std::optional<ErrPos> pos, const char * s, const string & s2))
|
||||
makeDebugTraceStacker(EvalState &state, Expr &expr, std::optional<ErrPos> pos, const char * s, const string & s2))
|
||||
{
|
||||
return std::unique_ptr<DebugTraceStacker>(
|
||||
new DebugTraceStacker(
|
||||
state,
|
||||
Trace {.pos = pos,
|
||||
DebugTrace
|
||||
{.pos = pos,
|
||||
.expr = expr,
|
||||
.hint = hintfmt(s, s2)
|
||||
}));
|
||||
}
|
||||
|
@ -1143,6 +1145,7 @@ void EvalState::cacheFile(
|
|||
debuggerHook ?
|
||||
makeDebugTraceStacker(
|
||||
*this,
|
||||
*e,
|
||||
(e->getPos() ? std::optional(ErrPos(*e->getPos())) : std::nullopt),
|
||||
"while evaluating the file '%1%':", resolvedPath)
|
||||
: std::unique_ptr<DebugTraceStacker>();
|
||||
|
@ -1375,6 +1378,7 @@ void ExprSelect::eval(EvalState & state, Env & env, Value & v)
|
|||
debuggerHook ?
|
||||
makeDebugTraceStacker(
|
||||
state,
|
||||
*this,
|
||||
*pos2,
|
||||
"while evaluating the attribute '%1%'",
|
||||
showAttrPath(state, env, attrPath))
|
||||
|
@ -1524,7 +1528,7 @@ void EvalState::callFunction(Value & fun, size_t nrArgs, Value * * args, Value &
|
|||
try {
|
||||
std::unique_ptr<DebugTraceStacker> dts =
|
||||
debuggerHook ?
|
||||
makeDebugTraceStacker(*this, lambda.pos,
|
||||
makeDebugTraceStacker(*this, *lambda.body, lambda.pos,
|
||||
"while evaluating %s",
|
||||
(lambda.name.set()
|
||||
? "'" + (string) lambda.name + "'"
|
||||
|
@ -1925,10 +1929,14 @@ void EvalState::forceValueDeep(Value & v)
|
|||
if (v.type() == nAttrs) {
|
||||
for (auto & i : *v.attrs)
|
||||
try {
|
||||
|
||||
std::unique_ptr<DebugTraceStacker> dts =
|
||||
debuggerHook ?
|
||||
makeDebugTraceStacker(*this, *i.pos,
|
||||
"while evaluating the attribute '%1%'", i.name)
|
||||
// if the value is a thunk, we're evaling. otherwise no trace necessary.
|
||||
(i.value->isThunk() ?
|
||||
makeDebugTraceStacker(*this, *v.thunk.expr, *i.pos,
|
||||
"while evaluating the attribute '%1%'", i.name)
|
||||
: std::unique_ptr<DebugTraceStacker>())
|
||||
: std::unique_ptr<DebugTraceStacker>();
|
||||
|
||||
recurse(*i.value);
|
||||
|
|
|
@ -74,6 +74,12 @@ struct RegexCache;
|
|||
|
||||
std::shared_ptr<RegexCache> makeRegexCache();
|
||||
|
||||
struct DebugTrace {
|
||||
std::optional<ErrPos> pos;
|
||||
Expr &expr;
|
||||
hintformat hint;
|
||||
};
|
||||
|
||||
|
||||
class EvalState
|
||||
{
|
||||
|
@ -109,7 +115,7 @@ public:
|
|||
RootValue vCallFlake = nullptr;
|
||||
RootValue vImportedDrvToDerivation = nullptr;
|
||||
|
||||
std::list<Trace> debugTraces;
|
||||
std::list<DebugTrace> debugTraces;
|
||||
|
||||
private:
|
||||
SrcToStore srcToStore;
|
||||
|
|
Loading…
Reference in a new issue