diff options
Diffstat (limited to 'tools/driver/Driver.cpp')
| -rw-r--r-- | tools/driver/Driver.cpp | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/tools/driver/Driver.cpp b/tools/driver/Driver.cpp index 7e1dec7a34fad..f3391a55e0d13 100644 --- a/tools/driver/Driver.cpp +++ b/tools/driver/Driver.cpp @@ -41,7 +41,10 @@ #include "lldb/API/SBStringList.h" #include "lldb/API/SBTarget.h" #include "lldb/API/SBThread.h" +#include "llvm/ADT/StringRef.h" #include "llvm/Support/ConvertUTF.h" +#include "llvm/Support/PrettyStackTrace.h" +#include "llvm/Support/Signals.h" #include <thread> #if !defined(__APPLE__) @@ -866,7 +869,6 @@ SBError Driver::ParseArgs(int argc, const char *argv[], FILE *out_fh, } else { // Skip any options we consumed with getopt_long_only argc -= optind; - // argv += optind; // Commented out to keep static analyzer happy if (argc > 0) ::fprintf(out_fh, @@ -963,7 +965,7 @@ std::string EscapeString(std::string arg) { return '"' + arg + '"'; } -void Driver::MainLoop() { +int Driver::MainLoop() { if (::tcgetattr(STDIN_FILENO, &g_old_stdin_termios) == 0) { g_old_stdin_termios_is_valid = true; atexit(reset_stdin_termios); @@ -1002,6 +1004,10 @@ void Driver::MainLoop() { result.PutOutput(m_debugger.GetOutputFileHandle()); } + // We allow the user to specify an exit code when calling quit which we will + // return when exiting. + m_debugger.GetCommandInterpreter().AllowExitCodeOnQuit(true); + // Now we handle options we got from the command line SBStream commands_stream; @@ -1160,7 +1166,9 @@ void Driver::MainLoop() { reset_stdin_termios(); fclose(stdin); + int exit_code = sb_interpreter.GetQuitStatus(); SBDebugger::Destroy(m_debugger); + return exit_code; } void Driver::ResizeWindow(unsigned short col) { @@ -1226,6 +1234,10 @@ main(int argc, char const *argv[]) const char **argv = argvPointers.data(); #endif + llvm::StringRef ToolName = argv[0]; + llvm::sys::PrintStackTraceOnErrorSignal(ToolName); + llvm::PrettyStackTraceProgram X(argc, argv); + SBDebugger::Initialize(); SBHostOS::ThreadCreated("<lldb.driver.main-thread>"); @@ -1238,6 +1250,7 @@ main(int argc, char const *argv[]) signal(SIGCONT, sigcont_handler); #endif + int exit_code = 0; // Create a scope for driver so that the driver object will destroy itself // before SBDebugger::Terminate() is called. { @@ -1246,14 +1259,15 @@ main(int argc, char const *argv[]) bool exiting = false; SBError error(driver.ParseArgs(argc, argv, stdout, exiting)); if (error.Fail()) { + exit_code = 1; const char *error_cstr = error.GetCString(); if (error_cstr) ::fprintf(stderr, "error: %s\n", error_cstr); } else if (!exiting) { - driver.MainLoop(); + exit_code = driver.MainLoop(); } } SBDebugger::Terminate(); - return 0; + return exit_code; } |
