remove redundant 'debugMode' flag

This commit is contained in:
Ben Burdette 2022-05-22 21:45:24 -06:00
parent 7ccb2700c0
commit 13d02af079
6 changed files with 35 additions and 39 deletions

View file

@ -119,8 +119,6 @@ ref<EvalState> EvalCommand::getEvalState()
#endif #endif
; ;
evalState->debugMode = startReplOnEvalErrors;
if (startReplOnEvalErrors) { if (startReplOnEvalErrors) {
evalState->debugRepl = &runRepl; evalState->debugRepl = &runRepl;
}; };

View file

@ -280,7 +280,7 @@ void NixRepl::mainLoop(const std::vector<std::string> & files)
// in debugger mode, an EvalError should trigger another repl session. // in debugger mode, an EvalError should trigger another repl session.
// when that session returns the exception will land here. No need to show it again; // when that session returns the exception will land here. No need to show it again;
// show the error for this repl session instead. // show the error for this repl session instead.
if (state.debugMode && !state.debugTraces.empty()) if (state.debugRepl && !state.debugTraces.empty())
showDebugTrace(std::cout, state.positions, state.debugTraces.front()); showDebugTrace(std::cout, state.positions, state.debugTraces.front());
else else
printMsg(lvlError, e.msg()); printMsg(lvlError, e.msg());
@ -493,7 +493,7 @@ bool NixRepl::processLine(std::string line)
<< " :log <expr> Show logs for a derivation\n" << " :log <expr> Show logs for a derivation\n"
<< " :te [bool] Enable, disable or toggle showing traces for errors\n" << " :te [bool] Enable, disable or toggle showing traces for errors\n"
; ;
if (state.debugMode) { if (state.debugRepl) {
std::cout std::cout
<< "\n" << "\n"
<< " Debug mode commands\n" << " Debug mode commands\n"
@ -508,14 +508,14 @@ bool NixRepl::processLine(std::string line)
} }
else if (state.debugMode && (command == ":bt" || command == ":backtrace")) { else if (state.debugRepl && (command == ":bt" || command == ":backtrace")) {
for (const auto & [idx, i] : enumerate(state.debugTraces)) { for (const auto & [idx, i] : enumerate(state.debugTraces)) {
std::cout << "\n" << ANSI_BLUE << idx << ANSI_NORMAL << ": "; std::cout << "\n" << ANSI_BLUE << idx << ANSI_NORMAL << ": ";
showDebugTrace(std::cout, state.positions, i); showDebugTrace(std::cout, state.positions, i);
} }
} }
else if (state.debugMode && (command == ":env")) { else if (state.debugRepl && (command == ":env")) {
for (const auto & [idx, i] : enumerate(state.debugTraces)) { for (const auto & [idx, i] : enumerate(state.debugTraces)) {
if (idx == debugTraceIndex) { if (idx == debugTraceIndex) {
printEnvBindings(state, i.expr, i.env); printEnvBindings(state, i.expr, i.env);
@ -524,7 +524,7 @@ bool NixRepl::processLine(std::string line)
} }
} }
else if (state.debugMode && (command == ":st")) { else if (state.debugRepl && (command == ":st")) {
try { try {
// change the DebugTrace index. // change the DebugTrace index.
debugTraceIndex = stoi(arg); debugTraceIndex = stoi(arg);
@ -542,13 +542,13 @@ bool NixRepl::processLine(std::string line)
} }
} }
else if (state.debugMode && (command == ":s" || command == ":step")) { else if (state.debugRepl && (command == ":s" || command == ":step")) {
// set flag to stop at next DebugTrace; exit repl. // set flag to stop at next DebugTrace; exit repl.
state.debugStop = true; state.debugStop = true;
return false; return false;
} }
else if (state.debugMode && (command == ":c" || command == ":continue")) { else if (state.debugRepl && (command == ":c" || command == ":continue")) {
// set flag to run to next breakpoint or end of program; exit repl. // set flag to run to next breakpoint or end of program; exit repl.
state.debugStop = false; state.debugStop = false;
return false; return false;

View file

@ -813,7 +813,7 @@ std::unique_ptr<ValMap> mapStaticEnvBindings(const SymbolTable & st, const Stati
void EvalState::runDebugRepl(const Error * error, const Env & env, const Expr & expr) void EvalState::runDebugRepl(const Error * error, const Env & env, const Expr & expr)
{ {
// double check we've got the debugRepl ftn pointer. // double check we've got the debugRepl function pointer.
if (!debugRepl) if (!debugRepl)
return; return;
@ -1073,7 +1073,7 @@ DebugTraceStacker::DebugTraceStacker(EvalState & evalState, DebugTrace t)
, trace(std::move(t)) , trace(std::move(t))
{ {
evalState.debugTraces.push_front(trace); evalState.debugTraces.push_front(trace);
if (evalState.debugStop && evalState.debugMode) if (evalState.debugStop && evalState.debugRepl)
evalState.runDebugRepl(nullptr, trace.env, trace.expr); evalState.runDebugRepl(nullptr, trace.env, trace.expr);
} }
@ -1271,7 +1271,7 @@ void EvalState::cacheFile(
fileParseCache[resolvedPath] = e; fileParseCache[resolvedPath] = e;
try { try {
auto dts = debugMode auto dts = debugRepl
? makeDebugTraceStacker( ? makeDebugTraceStacker(
*this, *this,
*e, *e,
@ -1505,7 +1505,7 @@ void ExprSelect::eval(EvalState & state, Env & env, Value & v)
e->eval(state, env, vTmp); e->eval(state, env, vTmp);
try { try {
auto dts = state.debugMode auto dts = state.debugRepl
? makeDebugTraceStacker( ? makeDebugTraceStacker(
state, state,
*this, *this,
@ -1674,7 +1674,7 @@ void EvalState::callFunction(Value & fun, size_t nrArgs, Value * * args, Value &
/* Evaluate the body. */ /* Evaluate the body. */
try { try {
auto dts = debugMode auto dts = debugRepl
? makeDebugTraceStacker( ? makeDebugTraceStacker(
*this, *lambda.body, env2, positions[lambda.pos], *this, *lambda.body, env2, positions[lambda.pos],
"while evaluating %s", "while evaluating %s",
@ -2102,7 +2102,7 @@ void EvalState::forceValueDeep(Value & v)
for (auto & i : *v.attrs) for (auto & i : *v.attrs)
try { try {
// If the value is a thunk, we're evaling. Otherwise no trace necessary. // If the value is a thunk, we're evaling. Otherwise no trace necessary.
auto dts = debugMode && i.value->isThunk() auto dts = debugRepl && i.value->isThunk()
? makeDebugTraceStacker(*this, *i.value->thunk.expr, *i.value->thunk.env, positions[i.pos], ? makeDebugTraceStacker(*this, *i.value->thunk.expr, *i.value->thunk.env, positions[i.pos],
"while evaluating the attribute '%1%'", symbols[i.name]) "while evaluating the attribute '%1%'", symbols[i.name])
: nullptr; : nullptr;

View file

@ -128,8 +128,6 @@ public:
/* Debugger */ /* Debugger */
void (* debugRepl)(EvalState & es, const ValMap & extraEnv); void (* debugRepl)(EvalState & es, const ValMap & extraEnv);
bool debugMode;
bool debugStop; bool debugStop;
bool debugQuit; bool debugQuit;
std::list<DebugTrace> debugTraces; std::list<DebugTrace> debugTraces;
@ -149,7 +147,7 @@ public:
[[gnu::noinline, gnu::noreturn]] [[gnu::noinline, gnu::noreturn]]
void debugThrow(const E &error, const Env & env, const Expr & expr) void debugThrow(const E &error, const Env & env, const Expr & expr)
{ {
if (debugMode) if (debugRepl)
runDebugRepl(&error, env, expr); runDebugRepl(&error, env, expr);
throw error; throw error;
@ -162,7 +160,7 @@ public:
// Call this in the situation where Expr and Env are inaccessible. // Call this in the situation where Expr and Env are inaccessible.
// The debugger will start in the last context that's in the // The debugger will start in the last context that's in the
// DebugTrace stack. // DebugTrace stack.
if (debugMode && !debugTraces.empty()) { if (debugRepl && !debugTraces.empty()) {
const DebugTrace & last = debugTraces.front(); const DebugTrace & last = debugTraces.front();
runDebugRepl(&e, last.env, last.expr); runDebugRepl(&e, last.env, last.expr);
} }

View file

@ -299,31 +299,31 @@ void Expr::bindVars(EvalState & es, const std::shared_ptr<const StaticEnv> & env
void ExprInt::bindVars(EvalState & es, const std::shared_ptr<const StaticEnv> & env) void ExprInt::bindVars(EvalState & es, const std::shared_ptr<const StaticEnv> & env)
{ {
if (es.debugMode) if (es.debugRepl)
es.exprEnvs.insert(std::make_pair(this, env)); es.exprEnvs.insert(std::make_pair(this, env));
} }
void ExprFloat::bindVars(EvalState & es, const std::shared_ptr<const StaticEnv> & env) void ExprFloat::bindVars(EvalState & es, const std::shared_ptr<const StaticEnv> & env)
{ {
if (es.debugMode) if (es.debugRepl)
es.exprEnvs.insert(std::make_pair(this, env)); es.exprEnvs.insert(std::make_pair(this, env));
} }
void ExprString::bindVars(EvalState & es, const std::shared_ptr<const StaticEnv> & env) void ExprString::bindVars(EvalState & es, const std::shared_ptr<const StaticEnv> & env)
{ {
if (es.debugMode) if (es.debugRepl)
es.exprEnvs.insert(std::make_pair(this, env)); es.exprEnvs.insert(std::make_pair(this, env));
} }
void ExprPath::bindVars(EvalState & es, const std::shared_ptr<const StaticEnv> & env) void ExprPath::bindVars(EvalState & es, const std::shared_ptr<const StaticEnv> & env)
{ {
if (es.debugMode) if (es.debugRepl)
es.exprEnvs.insert(std::make_pair(this, env)); es.exprEnvs.insert(std::make_pair(this, env));
} }
void ExprVar::bindVars(EvalState & es, const std::shared_ptr<const StaticEnv> & env) void ExprVar::bindVars(EvalState & es, const std::shared_ptr<const StaticEnv> & env)
{ {
if (es.debugMode) if (es.debugRepl)
es.exprEnvs.insert(std::make_pair(this, env)); es.exprEnvs.insert(std::make_pair(this, env));
/* Check whether the variable appears in the environment. If so, /* Check whether the variable appears in the environment. If so,
@ -359,7 +359,7 @@ void ExprVar::bindVars(EvalState & es, const std::shared_ptr<const StaticEnv> &
void ExprSelect::bindVars(EvalState & es, const std::shared_ptr<const StaticEnv> & env) void ExprSelect::bindVars(EvalState & es, const std::shared_ptr<const StaticEnv> & env)
{ {
if (es.debugMode) if (es.debugRepl)
es.exprEnvs.insert(std::make_pair(this, env)); es.exprEnvs.insert(std::make_pair(this, env));
e->bindVars(es, env); e->bindVars(es, env);
@ -371,7 +371,7 @@ void ExprSelect::bindVars(EvalState & es, const std::shared_ptr<const StaticEnv>
void ExprOpHasAttr::bindVars(EvalState & es, const std::shared_ptr<const StaticEnv> & env) void ExprOpHasAttr::bindVars(EvalState & es, const std::shared_ptr<const StaticEnv> & env)
{ {
if (es.debugMode) if (es.debugRepl)
es.exprEnvs.insert(std::make_pair(this, env)); es.exprEnvs.insert(std::make_pair(this, env));
e->bindVars(es, env); e->bindVars(es, env);
@ -382,7 +382,7 @@ void ExprOpHasAttr::bindVars(EvalState & es, const std::shared_ptr<const StaticE
void ExprAttrs::bindVars(EvalState & es, const std::shared_ptr<const StaticEnv> & env) void ExprAttrs::bindVars(EvalState & es, const std::shared_ptr<const StaticEnv> & env)
{ {
if (es.debugMode) if (es.debugRepl)
es.exprEnvs.insert(std::make_pair(this, env)); es.exprEnvs.insert(std::make_pair(this, env));
if (recursive) { if (recursive) {
@ -415,7 +415,7 @@ void ExprAttrs::bindVars(EvalState & es, const std::shared_ptr<const StaticEnv>
void ExprList::bindVars(EvalState & es, const std::shared_ptr<const StaticEnv> & env) void ExprList::bindVars(EvalState & es, const std::shared_ptr<const StaticEnv> & env)
{ {
if (es.debugMode) if (es.debugRepl)
es.exprEnvs.insert(std::make_pair(this, env)); es.exprEnvs.insert(std::make_pair(this, env));
for (auto & i : elems) for (auto & i : elems)
@ -424,7 +424,7 @@ void ExprList::bindVars(EvalState & es, const std::shared_ptr<const StaticEnv> &
void ExprLambda::bindVars(EvalState & es, const std::shared_ptr<const StaticEnv> & env) void ExprLambda::bindVars(EvalState & es, const std::shared_ptr<const StaticEnv> & env)
{ {
if (es.debugMode) if (es.debugRepl)
es.exprEnvs.insert(std::make_pair(this, env)); es.exprEnvs.insert(std::make_pair(this, env));
auto newEnv = std::make_shared<StaticEnv>( auto newEnv = std::make_shared<StaticEnv>(
@ -451,7 +451,7 @@ void ExprLambda::bindVars(EvalState & es, const std::shared_ptr<const StaticEnv>
void ExprCall::bindVars(EvalState & es, const std::shared_ptr<const StaticEnv> & env) void ExprCall::bindVars(EvalState & es, const std::shared_ptr<const StaticEnv> & env)
{ {
if (es.debugMode) if (es.debugRepl)
es.exprEnvs.insert(std::make_pair(this, env)); es.exprEnvs.insert(std::make_pair(this, env));
fun->bindVars(es, env); fun->bindVars(es, env);
@ -461,7 +461,7 @@ void ExprCall::bindVars(EvalState & es, const std::shared_ptr<const StaticEnv> &
void ExprLet::bindVars(EvalState & es, const std::shared_ptr<const StaticEnv> & env) void ExprLet::bindVars(EvalState & es, const std::shared_ptr<const StaticEnv> & env)
{ {
if (es.debugMode) if (es.debugRepl)
es.exprEnvs.insert(std::make_pair(this, env)); es.exprEnvs.insert(std::make_pair(this, env));
auto newEnv = std::make_shared<StaticEnv>(false, env.get(), attrs->attrs.size()); auto newEnv = std::make_shared<StaticEnv>(false, env.get(), attrs->attrs.size());
@ -480,7 +480,7 @@ void ExprLet::bindVars(EvalState & es, const std::shared_ptr<const StaticEnv> &
void ExprWith::bindVars(EvalState & es, const std::shared_ptr<const StaticEnv> & env) void ExprWith::bindVars(EvalState & es, const std::shared_ptr<const StaticEnv> & env)
{ {
if (es.debugMode) if (es.debugRepl)
es.exprEnvs.insert(std::make_pair(this, env)); es.exprEnvs.insert(std::make_pair(this, env));
/* Does this `with' have an enclosing `with'? If so, record its /* Does this `with' have an enclosing `with'? If so, record its
@ -495,7 +495,7 @@ void ExprWith::bindVars(EvalState & es, const std::shared_ptr<const StaticEnv> &
break; break;
} }
if (es.debugMode) if (es.debugRepl)
es.exprEnvs.insert(std::make_pair(this, env)); es.exprEnvs.insert(std::make_pair(this, env));
attrs->bindVars(es, env); attrs->bindVars(es, env);
@ -505,7 +505,7 @@ void ExprWith::bindVars(EvalState & es, const std::shared_ptr<const StaticEnv> &
void ExprIf::bindVars(EvalState & es, const std::shared_ptr<const StaticEnv> & env) void ExprIf::bindVars(EvalState & es, const std::shared_ptr<const StaticEnv> & env)
{ {
if (es.debugMode) if (es.debugRepl)
es.exprEnvs.insert(std::make_pair(this, env)); es.exprEnvs.insert(std::make_pair(this, env));
cond->bindVars(es, env); cond->bindVars(es, env);
@ -515,7 +515,7 @@ void ExprIf::bindVars(EvalState & es, const std::shared_ptr<const StaticEnv> & e
void ExprAssert::bindVars(EvalState & es, const std::shared_ptr<const StaticEnv> & env) void ExprAssert::bindVars(EvalState & es, const std::shared_ptr<const StaticEnv> & env)
{ {
if (es.debugMode) if (es.debugRepl)
es.exprEnvs.insert(std::make_pair(this, env)); es.exprEnvs.insert(std::make_pair(this, env));
cond->bindVars(es, env); cond->bindVars(es, env);
@ -524,7 +524,7 @@ void ExprAssert::bindVars(EvalState & es, const std::shared_ptr<const StaticEnv>
void ExprOpNot::bindVars(EvalState & es, const std::shared_ptr<const StaticEnv> & env) void ExprOpNot::bindVars(EvalState & es, const std::shared_ptr<const StaticEnv> & env)
{ {
if (es.debugMode) if (es.debugRepl)
es.exprEnvs.insert(std::make_pair(this, env)); es.exprEnvs.insert(std::make_pair(this, env));
e->bindVars(es, env); e->bindVars(es, env);
@ -532,7 +532,7 @@ void ExprOpNot::bindVars(EvalState & es, const std::shared_ptr<const StaticEnv>
void ExprConcatStrings::bindVars(EvalState & es, const std::shared_ptr<const StaticEnv> & env) void ExprConcatStrings::bindVars(EvalState & es, const std::shared_ptr<const StaticEnv> & env)
{ {
if (es.debugMode) if (es.debugRepl)
es.exprEnvs.insert(std::make_pair(this, env)); es.exprEnvs.insert(std::make_pair(this, env));
for (auto & i : *this->es) for (auto & i : *this->es)
@ -541,7 +541,7 @@ void ExprConcatStrings::bindVars(EvalState & es, const std::shared_ptr<const Sta
void ExprPos::bindVars(EvalState & es, const std::shared_ptr<const StaticEnv> & env) void ExprPos::bindVars(EvalState & es, const std::shared_ptr<const StaticEnv> & env)
{ {
if (es.debugMode) if (es.debugRepl)
es.exprEnvs.insert(std::make_pair(this, env)); es.exprEnvs.insert(std::make_pair(this, env));
} }

View file

@ -757,7 +757,7 @@ static RegisterPrimOp primop_break({
)", )",
.fun = [](EvalState & state, const PosIdx pos, Value * * args, Value & v) .fun = [](EvalState & state, const PosIdx pos, Value * * args, Value & v)
{ {
if (state.debugMode && !state.debugTraces.empty()) { if (state.debugRepl && !state.debugTraces.empty()) {
auto error = Error(ErrorInfo { auto error = Error(ErrorInfo {
.level = lvlInfo, .level = lvlInfo,
.msg = hintfmt("breakpoint reached"), .msg = hintfmt("breakpoint reached"),