From cd8c232b554776031f61cee5f70a8825c60fbfdb Mon Sep 17 00:00:00 2001 From: Ben Burdette Date: Wed, 15 Sep 2021 16:16:53 -0600 Subject: [PATCH] add cout debugging --- Makefile | 2 +- src/libcmd/command.cc | 2 -- src/libexpr/eval.cc | 2 ++ src/libexpr/nixexpr.cc | 42 ++++++++++++++++++++++++++++++++++-------- src/libexpr/nixexpr.hh | 1 + src/libexpr/parser.y | 11 +++++++++++ src/libexpr/primops.cc | 4 ++++ 7 files changed, 53 insertions(+), 11 deletions(-) diff --git a/Makefile b/Makefile index bc2684eaa..ab8ab5ae1 100644 --- a/Makefile +++ b/Makefile @@ -15,7 +15,7 @@ makefiles = \ misc/systemd/local.mk \ misc/launchd/local.mk \ misc/upstart/local.mk \ - doc/manual/local.mk \ + # doc/manual/local.mk \ tests/local.mk \ tests/plugins/local.mk diff --git a/src/libcmd/command.cc b/src/libcmd/command.cc index 07f4208da..55f6ffd00 100644 --- a/src/libcmd/command.cc +++ b/src/libcmd/command.cc @@ -99,8 +99,6 @@ EvalCommand::EvalCommand() // extern std::function & env)> debuggerHook; extern std::function debuggerHook; - - ref EvalCommand::getEvalState() { std::cout << "EvalCommand::getEvalState()" << startReplOnEvalErrors << std::endl; diff --git a/src/libexpr/eval.cc b/src/libexpr/eval.cc index 69e3a4107..bcef2008f 100644 --- a/src/libexpr/eval.cc +++ b/src/libexpr/eval.cc @@ -918,6 +918,8 @@ LocalNoInlineNoReturn(void throwUndefinedVarError(const Pos & pos, const char * .errPos = pos }); + std::cout << "pre debuggerHook" << std::endl; + if (debuggerHook) debuggerHook(error, env); throw error; diff --git a/src/libexpr/nixexpr.cc b/src/libexpr/nixexpr.cc index 218e35f33..f8ded2157 100644 --- a/src/libexpr/nixexpr.cc +++ b/src/libexpr/nixexpr.cc @@ -3,7 +3,7 @@ #include "util.hh" #include - +#include namespace nix { @@ -283,6 +283,7 @@ void ExprVar::bindVars(const std::shared_ptr &env) enclosing `with'. If there is no `with', then we can issue an "undefined variable" error now. */ if (withLevel == -1) + std::cout << " throw UndefinedVarError({" << std::endl; throw UndefinedVarError({ .msg = hintfmt("undefined variable '%1%'", name), .errPos = pos @@ -310,11 +311,12 @@ void ExprOpHasAttr::bindVars(const std::shared_ptr &env) void ExprAttrs::bindVars(const std::shared_ptr &env) { - const StaticEnv * dynamicEnv = env.get(); - auto newEnv = std::shared_ptr(new StaticEnv(false, env.get())); // also make shared_ptr? + std::cout << "ExprAttrs::bindVars" << std::endl; + // auto dynamicEnv(env); if (recursive) { - dynamicEnv = newEnv.get(); + // dynamicEnv = newEnv.get(); + auto newEnv = std::shared_ptr(new StaticEnv(false, env.get())); // also make shared_ptr? unsigned int displ = 0; for (auto & i : attrs) @@ -322,16 +324,25 @@ void ExprAttrs::bindVars(const std::shared_ptr &env) for (auto & i : attrs) i.second.e->bindVars(i.second.inherited ? env : newEnv); + + for (auto & i : dynamicAttrs) { + i.nameExpr->bindVars(newEnv); + i.valueExpr->bindVars(newEnv); + } } - else + else { for (auto & i : attrs) i.second.e->bindVars(env); - for (auto & i : dynamicAttrs) { - i.nameExpr->bindVars(newEnv); - i.valueExpr->bindVars(newEnv); + for (auto & i : dynamicAttrs) { + i.nameExpr->bindVars(env); + i.valueExpr->bindVars(env); + } } + + std::cout << "ExprAttrs::bindVars end" << std::endl; + } void ExprList::bindVars(const std::shared_ptr &env) @@ -375,6 +386,7 @@ void ExprLet::bindVars(const std::shared_ptr &env) void ExprWith::bindVars(const std::shared_ptr &env) { + std::cout << " ExprWith::bindVars " << std::endl; /* Does this `with' have an enclosing `with'? If so, record its level so that `lookupVar' can look up variables in the previous `with' if this one doesn't contain the desired attribute. */ @@ -387,9 +399,23 @@ void ExprWith::bindVars(const std::shared_ptr &env) break; } + std::cout << " ExprWith::bindVars 1" << std::endl; + attrs->show(std::cout); + std::cout << std::endl; attrs->bindVars(env); auto newEnv = std::shared_ptr(new StaticEnv(false, env.get())); // also make shared_ptr? + std::cout << " ExprWith::bindVars 2" << std::endl; + std::cout << " body: " << std::endl; + body->show(std::cout); + std::cout << std::endl; + + std::cout << "ExprWith::newenv: " << newEnv->vars.size() << std::endl; + for (auto i = newEnv->vars.begin(); i != newEnv->vars.end(); ++i) + std::cout << "EvalState::parse newEnv " << i->first << std::endl; + + body->bindVars(newEnv); + std::cout << " ExprWith::bindVars 3" << std::endl; } void ExprIf::bindVars(const std::shared_ptr &env) diff --git a/src/libexpr/nixexpr.hh b/src/libexpr/nixexpr.hh index 4c55cb64b..ce3ee9f4d 100644 --- a/src/libexpr/nixexpr.hh +++ b/src/libexpr/nixexpr.hh @@ -20,6 +20,7 @@ MakeError(UndefinedVarError, Error); MakeError(MissingArgumentError, EvalError); MakeError(RestrictedPathError, Error); +extern std::function debuggerHook; /* Position objects. */ diff --git a/src/libexpr/parser.y b/src/libexpr/parser.y index d1e898677..a3432eb32 100644 --- a/src/libexpr/parser.y +++ b/src/libexpr/parser.y @@ -22,6 +22,8 @@ #include "eval.hh" #include "globals.hh" +#include + namespace nix { struct ParseData @@ -572,6 +574,10 @@ namespace nix { Expr * EvalState::parse(const char * text, FileOrigin origin, const Path & path, const Path & basePath, std::shared_ptr & staticEnv) { + std::cout << "EvalState::parse " << std::endl; + for (auto i = staticEnv->vars.begin(); i != staticEnv->vars.end(); ++i) + std::cout << "EvalState::parse staticEnv " << i->first << std::endl; + yyscan_t scanner; ParseData data(*this); data.origin = origin; @@ -595,8 +601,13 @@ Expr * EvalState::parse(const char * text, FileOrigin origin, if (res) throw ParseError(data.error.value()); + + std::cout << "EvalState::parse pre bindvars " << std::endl; + data.result->bindVars(staticEnv); + std::cout << "EvalState::parse post bindVars " << std::endl; + return data.result; } diff --git a/src/libexpr/primops.cc b/src/libexpr/primops.cc index 0400c8942..7a277a7f5 100644 --- a/src/libexpr/primops.cc +++ b/src/libexpr/primops.cc @@ -110,6 +110,8 @@ static void mkOutputString(EvalState & state, Value & v, argument. */ static void import(EvalState & state, const Pos & pos, Value & vPath, Value * vScope, Value & v) { + std::cout << " import " << std::endl; + PathSet context; Path path = state.coerceToPath(pos, vPath, context); @@ -194,6 +196,8 @@ static void import(EvalState & state, const Pos & pos, Value & vPath, Value * vS env->values[displ++] = attr.value; } + std::cout << "import staticenv: {} " << staticEnv << std::endl; + printTalkative("evaluating file '%1%'", realPath); Expr * e = state.parseExprFromFile(resolveExprPath(realPath), staticEnv);