add cout debugging

This commit is contained in:
Ben Burdette 2021-09-15 16:16:53 -06:00
parent 1e04b2568d
commit cd8c232b55
7 changed files with 53 additions and 11 deletions

View file

@ -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

View file

@ -99,8 +99,6 @@ EvalCommand::EvalCommand()
// extern std::function<void(const Error & error, const std::map<std::string, Value *> & env)> debuggerHook;
extern std::function<void(const Error & error, const Env & env)> debuggerHook;
ref<EvalState> EvalCommand::getEvalState()
{
std::cout << "EvalCommand::getEvalState()" << startReplOnEvalErrors << std::endl;

View file

@ -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;

View file

@ -3,7 +3,7 @@
#include "util.hh"
#include <cstdlib>
#include <iostream>
namespace nix {
@ -283,6 +283,7 @@ void ExprVar::bindVars(const std::shared_ptr<const StaticEnv> &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<const StaticEnv> &env)
void ExprAttrs::bindVars(const std::shared_ptr<const StaticEnv> &env)
{
const StaticEnv * dynamicEnv = env.get();
auto newEnv = std::shared_ptr<StaticEnv>(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<StaticEnv>(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<const StaticEnv> &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<const StaticEnv> &env)
@ -375,6 +386,7 @@ void ExprLet::bindVars(const std::shared_ptr<const StaticEnv> &env)
void ExprWith::bindVars(const std::shared_ptr<const StaticEnv> &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<const StaticEnv> &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<StaticEnv>(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<const StaticEnv> &env)

View file

@ -20,6 +20,7 @@ MakeError(UndefinedVarError, Error);
MakeError(MissingArgumentError, EvalError);
MakeError(RestrictedPathError, Error);
extern std::function<void(const Error & error, const Env & env)> debuggerHook;
/* Position objects. */

View file

@ -22,6 +22,8 @@
#include "eval.hh"
#include "globals.hh"
#include <iostream>
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> & 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;
}

View file

@ -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);