aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBen Burdette <bburdette@protonmail.com>2022-05-20 10:33:50 -0600
committerBen Burdette <bburdette@protonmail.com>2022-05-20 10:33:50 -0600
commit884d59178735bcb5d5db7db97a05ad62a175493b (patch)
tree9dd9356cca8f7fc882bb8962ab3a0f156ea3488a /src
parent0600df86b8bc59633457f7ceb79e84c8ea3fed17 (diff)
debugRepl ftn pointer
Diffstat (limited to 'src')
-rw-r--r--src/libcmd/command.cc27
-rw-r--r--src/libexpr/eval.cc12
-rw-r--r--src/libexpr/eval.hh10
-rw-r--r--src/libexpr/primops.cc2
4 files changed, 41 insertions, 10 deletions
diff --git a/src/libcmd/command.cc b/src/libcmd/command.cc
index a4ea5bc33..b61b9b61d 100644
--- a/src/libcmd/command.cc
+++ b/src/libcmd/command.cc
@@ -120,7 +120,34 @@ ref<EvalState> EvalCommand::getEvalState()
;
evalState->debugMode = startReplOnEvalErrors;
+
// TODO move this somewhere else. Its only here to get the evalState ptr!
+ if (startReplOnEvalErrors) {
+ evalState->debugRepl = &runRepl;
+ };
+ // // debuggerHook = [evalState{ref<EvalState>(evalState)}](const Error * error, const Env & env, const Expr & expr) {
+ // debuggerHook = [](EvalState & evalState, const Error * error, const Env & env, const Expr & expr) {
+ // auto dts =
+ // error && expr.getPos()
+ // ? std::make_unique<DebugTraceStacker>(
+ // evalState,
+ // DebugTrace {
+ // .pos = error->info().errPos ? *error->info().errPos : evalState.positions[expr.getPos()],
+ // .expr = expr,
+ // .env = env,
+ // .hint = error->info().msg,
+ // .isError = true
+ // })
+ // : nullptr;
+
+ // if (error)
+ // printError("%s\n\n" ANSI_BOLD "Starting REPL to allow you to inspect the current state of the evaluator.\n" ANSI_NORMAL, error->what());
+
+ // auto se = evalState.getStaticEnv(expr);
+ // if (se) {
+ // auto vm = mapStaticEnvBindings(evalState.symbols, *se.get(), env);
+ // runRepl(evalState, *vm);
+ // }
// if (startReplOnEvalErrors)
// // debuggerHook = [evalState{ref<EvalState>(evalState)}](const Error * error, const Env & env, const Expr & expr) {
diff --git a/src/libexpr/eval.cc b/src/libexpr/eval.cc
index 1cde4a9ab..5faecdbe3 100644
--- a/src/libexpr/eval.cc
+++ b/src/libexpr/eval.cc
@@ -463,7 +463,7 @@ EvalState::EvalState(
, emptyBindings(0)
, store(store)
, buildStore(buildStore ? buildStore : store)
- , debugMode(false)
+ , debugRepl(0)
, debugStop(false)
, debugQuit(false)
, regexCache(makeRegexCache())
@@ -811,8 +811,12 @@ std::unique_ptr<ValMap> mapStaticEnvBindings(const SymbolTable & st, const Stati
return vm;
}
-void EvalState::debugRepl(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.
+ if (!debugRepl)
+ return;
+
auto dts =
error && expr.getPos()
? std::make_unique<DebugTraceStacker>(
@@ -832,7 +836,7 @@ void EvalState::debugRepl(const Error * error, const Env & env, const Expr & exp
auto se = getStaticEnv(expr);
if (se) {
auto vm = mapStaticEnvBindings(symbols, *se.get(), env);
- runRepl(*this, *vm);
+ (debugRepl)(*this, *vm);
}
}
@@ -1070,7 +1074,7 @@ DebugTraceStacker::DebugTraceStacker(EvalState & evalState, DebugTrace t)
{
evalState.debugTraces.push_front(trace);
if (evalState.debugStop && evalState.debugMode)
- evalState.debugRepl(nullptr, trace.env, trace.expr);
+ evalState.runDebugRepl(nullptr, trace.env, trace.expr);
}
void Value::mkString(std::string_view s)
diff --git a/src/libexpr/eval.hh b/src/libexpr/eval.hh
index 711a4d6be..90bd5497b 100644
--- a/src/libexpr/eval.hh
+++ b/src/libexpr/eval.hh
@@ -48,8 +48,6 @@ struct Env
Value * values[0];
};
-extern void runRepl(ref<EvalState> evalState, const ValMap & extraEnv);
-
void printEnvBindings(const EvalState &es, const Expr & expr, const Env & env);
void printEnvBindings(const SymbolTable & st, const StaticEnv & se, const Env & env, int lvl = 0);
@@ -129,6 +127,8 @@ public:
RootValue vImportedDrvToDerivation = nullptr;
/* Debugger */
+ void (* debugRepl)(EvalState & es, const ValMap & extraEnv);
+
bool debugMode;
bool debugStop;
bool debugQuit;
@@ -143,14 +143,14 @@ public:
return std::shared_ptr<const StaticEnv>();;
}
- void debugRepl(const Error * error, const Env & env, const Expr & expr);
+ void runDebugRepl(const Error * error, const Env & env, const Expr & expr);
template<class E>
[[gnu::noinline, gnu::noreturn]]
void debugThrow(const E &error, const Env & env, const Expr & expr)
{
if (debugMode)
- debugRepl(&error, env, expr);
+ runDebugRepl(&error, env, expr);
throw error;
}
@@ -164,7 +164,7 @@ public:
// DebugTrace stack.
if (debugMode && !debugTraces.empty()) {
const DebugTrace & last = debugTraces.front();
- debugRepl(&e, last.env, last.expr);
+ runDebugRepl(&e, last.env, last.expr);
}
throw e;
diff --git a/src/libexpr/primops.cc b/src/libexpr/primops.cc
index f7429197a..3ca377b7c 100644
--- a/src/libexpr/primops.cc
+++ b/src/libexpr/primops.cc
@@ -765,7 +765,7 @@ static RegisterPrimOp primop_break({
});
auto & dt = state.debugTraces.front();
- state.debugRepl(&error, dt.env, dt.expr);
+ state.runDebugRepl(&error, dt.env, dt.expr);
if (state.debugQuit) {
// If the user elects to quit the repl, throw an exception.