mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2025-01-19 17:46:46 +02:00
Forbid nested debuggers
This commit is contained in:
parent
4ee5433919
commit
14b0356dc5
4 changed files with 20 additions and 11 deletions
|
@ -336,13 +336,7 @@ ReplExitStatus NixRepl::mainLoop()
|
||||||
printMsg(lvlError, e.msg());
|
printMsg(lvlError, e.msg());
|
||||||
}
|
}
|
||||||
} catch (EvalError & e) {
|
} catch (EvalError & e) {
|
||||||
// in debugger mode, an EvalError should trigger another repl session.
|
printMsg(lvlError, e.msg());
|
||||||
// when that session returns the exception will land here. No need to show it again;
|
|
||||||
// show the error for this repl session instead.
|
|
||||||
if (state->debugRepl && !state->debugTraces.empty())
|
|
||||||
showDebugTrace(std::cout, state->positions, state->debugTraces.front());
|
|
||||||
else
|
|
||||||
printMsg(lvlError, e.msg());
|
|
||||||
} catch (Error & e) {
|
} catch (Error & e) {
|
||||||
printMsg(lvlError, e.msg());
|
printMsg(lvlError, e.msg());
|
||||||
} catch (Interrupted & e) {
|
} catch (Interrupted & e) {
|
||||||
|
|
|
@ -762,10 +762,24 @@ std::unique_ptr<ValMap> mapStaticEnvBindings(const SymbolTable & st, const Stati
|
||||||
return vm;
|
return vm;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets `inDebugger` to true on construction and false on destruction.
|
||||||
|
*/
|
||||||
|
class DebuggerGuard {
|
||||||
|
bool & inDebugger;
|
||||||
|
public:
|
||||||
|
DebuggerGuard(bool & inDebugger) : inDebugger(inDebugger) {
|
||||||
|
inDebugger = true;
|
||||||
|
}
|
||||||
|
~DebuggerGuard() {
|
||||||
|
inDebugger = false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
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 function pointer.
|
// Make sure we have a debugger to run and we're not already in a debugger.
|
||||||
if (!debugRepl)
|
if (!debugRepl || inDebugger)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
auto dts =
|
auto dts =
|
||||||
|
@ -792,6 +806,7 @@ void EvalState::runDebugRepl(const Error * error, const Env & env, const Expr &
|
||||||
auto se = getStaticEnv(expr);
|
auto se = getStaticEnv(expr);
|
||||||
if (se) {
|
if (se) {
|
||||||
auto vm = mapStaticEnvBindings(symbols, *se.get(), env);
|
auto vm = mapStaticEnvBindings(symbols, *se.get(), env);
|
||||||
|
DebuggerGuard _guard(inDebugger);
|
||||||
auto exitStatus = (debugRepl)(ref<EvalState>(shared_from_this()), *vm);
|
auto exitStatus = (debugRepl)(ref<EvalState>(shared_from_this()), *vm);
|
||||||
switch (exitStatus) {
|
switch (exitStatus) {
|
||||||
case ReplExitStatus::QuitAll:
|
case ReplExitStatus::QuitAll:
|
||||||
|
|
|
@ -153,6 +153,7 @@ struct DebugTrace {
|
||||||
bool isError;
|
bool isError;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class EvalState : public std::enable_shared_from_this<EvalState>
|
class EvalState : public std::enable_shared_from_this<EvalState>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@ -222,6 +223,7 @@ public:
|
||||||
*/
|
*/
|
||||||
ReplExitStatus (* debugRepl)(ref<EvalState> es, const ValMap & extraEnv);
|
ReplExitStatus (* debugRepl)(ref<EvalState> es, const ValMap & extraEnv);
|
||||||
bool debugStop;
|
bool debugStop;
|
||||||
|
bool inDebugger = false;
|
||||||
int trylevel;
|
int trylevel;
|
||||||
std::list<DebugTrace> debugTraces;
|
std::list<DebugTrace> debugTraces;
|
||||||
std::map<const Expr*, const std::shared_ptr<const StaticEnv>> exprEnvs;
|
std::map<const Expr*, const std::shared_ptr<const StaticEnv>> exprEnvs;
|
||||||
|
|
|
@ -8,7 +8,6 @@
|
||||||
|
|
||||||
namespace nix {
|
namespace nix {
|
||||||
|
|
||||||
namespace {
|
|
||||||
/**
|
/**
|
||||||
* A helper for writing `boost::format` expressions.
|
* A helper for writing `boost::format` expressions.
|
||||||
*
|
*
|
||||||
|
@ -42,7 +41,6 @@ void setExceptions(boost::format & fmt)
|
||||||
boost::io::too_many_args_bit ^
|
boost::io::too_many_args_bit ^
|
||||||
boost::io::too_few_args_bit);
|
boost::io::too_few_args_bit);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A helper for writing a `boost::format` expression to a string.
|
* A helper for writing a `boost::format` expression to a string.
|
||||||
|
|
Loading…
Reference in a new issue