summaryrefslogtreecommitdiffstats
path: root/lldb/tools
diff options
context:
space:
mode:
authorRaphael Isemann <teemperor@gmail.com>2018-07-11 17:18:01 +0000
committerRaphael Isemann <teemperor@gmail.com>2018-07-11 17:18:01 +0000
commitc094d23f6f23a2bec0c7aa00a7113bee456f78c5 (patch)
tree7a8ad3568fa360199085ffd7e8b49ebb6a8097bc /lldb/tools
parent3f27e57adeb5fc262e07c191eca07f28977a1f3b (diff)
downloadbcm5719-llvm-c094d23f6f23a2bec0c7aa00a7113bee456f78c5.tar.gz
bcm5719-llvm-c094d23f6f23a2bec0c7aa00a7113bee456f78c5.zip
Allow specifying an exit code for the 'quit' command
Summary: This patch adds the possibility to specify an exit code when calling quit. We accept any int, even though it depends on the user what happens if the int is out of the range of what the operating system supports as exit codes. Fixes rdar://problem/38452312 Reviewers: davide, jingham, clayborg Reviewed By: jingham Subscribers: clayborg, jingham, lldb-commits Differential Revision: https://reviews.llvm.org/D48659 llvm-svn: 336824
Diffstat (limited to 'lldb/tools')
-rw-r--r--lldb/tools/driver/Driver.cpp14
-rw-r--r--lldb/tools/driver/Driver.h5
2 files changed, 15 insertions, 4 deletions
diff --git a/lldb/tools/driver/Driver.cpp b/lldb/tools/driver/Driver.cpp
index 58296b2eee8..e28093482f3 100644
--- a/lldb/tools/driver/Driver.cpp
+++ b/lldb/tools/driver/Driver.cpp
@@ -962,7 +962,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);
@@ -1001,6 +1001,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;
@@ -1159,7 +1163,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) {
@@ -1237,6 +1243,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.
{
@@ -1245,14 +1252,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;
}
diff --git a/lldb/tools/driver/Driver.h b/lldb/tools/driver/Driver.h
index 2be697ccc44..34746a23999 100644
--- a/lldb/tools/driver/Driver.h
+++ b/lldb/tools/driver/Driver.h
@@ -37,7 +37,10 @@ public:
virtual ~Driver();
- void MainLoop();
+ /// Runs the main loop.
+ ///
+ /// @return The exit code that the process should return.
+ int MainLoop();
lldb::SBError ParseArgs(int argc, const char *argv[], FILE *out_fh,
bool &do_exit);
OpenPOWER on IntegriCloud