From 1b2e7e1ab7e972347f871f63014334d59d2e7d61 Mon Sep 17 00:00:00 2001 From: piegames Date: Wed, 18 Dec 2024 10:05:26 +0100 Subject: [PATCH] repl: Improve error messages for debug commands outside of debug mode Pretending that these commands are "unknown" when not in debug mode is just silly. Change-Id: I7036ae792656ef540bbad00649be4f7309944a07 --- lix/libcmd/repl.cc | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/lix/libcmd/repl.cc b/lix/libcmd/repl.cc index a03bbe28a..4cf3e8128 100644 --- a/lix/libcmd/repl.cc +++ b/lix/libcmd/repl.cc @@ -530,6 +530,8 @@ ProcessLineResult NixRepl::processLine(std::string line) arg = line; } + bool inDebugger = evaluator.debug && evaluator.debug->inDebugger; + if (command == ":?" || command == ":help") { // FIXME: convert to Markdown, include in the 'nix repl' manpage. std::cout @@ -560,7 +562,7 @@ ProcessLineResult NixRepl::processLine(std::string line) << " errors\n" << " :?, :help Brings up this help menu\n" ; - if (evaluator.debug && evaluator.debug->inDebugger) { + if (inDebugger) { std::cout << "\n" << " Debug mode commands\n" @@ -575,7 +577,9 @@ ProcessLineResult NixRepl::processLine(std::string line) } - else if (evaluator.debug && evaluator.debug->inDebugger && (command == ":bt" || command == ":backtrace")) { + else if (command == ":bt" || command == ":backtrace") { + if (!inDebugger) + throw Error("backtrace command is only available in debug mode (see %s)", "--debugger"); auto traces = evaluator.debug->traces(); for (const auto & [idx, i] : enumerate(traces)) { std::cout << "\n" << ANSI_BLUE << idx << ANSI_NORMAL << ": "; @@ -583,7 +587,9 @@ ProcessLineResult NixRepl::processLine(std::string line) } } - else if (evaluator.debug && evaluator.debug->inDebugger && (command == ":env")) { + else if (command == ":env") { + if (!inDebugger) + throw Error("env command is only available in debug mode (see %s)", "--debugger"); auto traces = evaluator.debug->traces(); for (const auto & [idx, i] : enumerate(traces)) { if (idx == debugTraceIndex) { @@ -593,7 +599,9 @@ ProcessLineResult NixRepl::processLine(std::string line) } } - else if (evaluator.debug && evaluator.debug->inDebugger && (command == ":st")) { + else if (command == ":st") { + if (!inDebugger) + throw Error("trace command is only available in debug mode (see %s)", "--debugger"); try { // change the DebugTrace index. debugTraceIndex = stoi(arg); @@ -612,13 +620,17 @@ ProcessLineResult NixRepl::processLine(std::string line) } } - else if (evaluator.debug && evaluator.debug->inDebugger && (command == ":s" || command == ":step")) { + else if (command == ":s" || command == ":step") { + if (!inDebugger) + throw Error("step command is only available in debug mode (see %s)", "--debugger"); // set flag to stop at next DebugTrace; exit repl. evaluator.debug->stop = true; return ProcessLineResult::Continue; } - else if (evaluator.debug && evaluator.debug->inDebugger && (command == ":c" || command == ":continue")) { + else if (command == ":c" || command == ":continue") { + if (!inDebugger) + throw Error("continue command is only available in debug mode (see %s)", "--debugger"); // set flag to run to next breakpoint or end of program; exit repl. evaluator.debug->stop = false; return ProcessLineResult::Continue;