[lldb] Don't use ::exit but instead return from the driver loop (NFC)
authorJonas Devlieghere <jonas@devlieghere.com>
Tue, 10 Nov 2020 00:36:47 +0000 (16:36 -0800)
committerJonas Devlieghere <jonas@devlieghere.com>
Tue, 10 Nov 2020 00:47:30 +0000 (16:47 -0800)
This fixes a reproducer test failure that was caused by the undefined
order in which global destructors run. More concretely, the static
instance of the RealFileSystem had been destroyed before we finalized
the reproducer, which uses it to copy files into the reproducer. By
exiting normally, we call SBDebugger::Terminate and finalize the
reproducer before any static dtors are run.

lldb/tools/driver/Driver.cpp

index 526afdc..870f763 100644 (file)
@@ -593,7 +593,7 @@ int Driver::MainLoop() {
 
     if (commands_file == nullptr) {
       // We should have already printed an error in PrepareCommandsForSourcing.
-      exit(1);
+      return 1;
     }
 
     m_debugger.SetInputFileHandle(commands_file, true);
@@ -621,7 +621,7 @@ int Driver::MainLoop() {
     // non-zero exit status.
     if (m_option_data.m_batch &&
         results.GetResult() == lldb::eCommandInterpreterResultCommandError)
-      exit(1);
+      return 1;
 
     if (m_option_data.m_batch &&
         results.GetResult() == lldb::eCommandInterpreterResultInferiorCrash &&
@@ -646,7 +646,7 @@ int Driver::MainLoop() {
         if (m_option_data.m_batch &&
             local_results.GetResult() ==
                 lldb::eCommandInterpreterResultCommandError)
-          exit(1);
+          return 1;
       }
     }
     m_debugger.SetAsync(old_async);