[Lldb-commits] [lldb] 8bb81c2 - Convert to early exit (NFC)

Adrian Prantl via lldb-commits lldb-commits at lists.llvm.org
Mon Aug 17 14:42:36 PDT 2020


Author: Adrian Prantl
Date: 2020-08-17T14:42:25-07:00
New Revision: 8bb81c29b980d7fe37527d82cdae14f7f94727b1

URL: https://github.com/llvm/llvm-project/commit/8bb81c29b980d7fe37527d82cdae14f7f94727b1
DIFF: https://github.com/llvm/llvm-project/commit/8bb81c29b980d7fe37527d82cdae14f7f94727b1.diff

LOG: Convert to early exit (NFC)

Added: 
    

Modified: 
    lldb/source/Target/Target.cpp

Removed: 
    


################################################################################
diff  --git a/lldb/source/Target/Target.cpp b/lldb/source/Target/Target.cpp
index a3ec621e7141..201a146440e1 100644
--- a/lldb/source/Target/Target.cpp
+++ b/lldb/source/Target/Target.cpp
@@ -2902,68 +2902,70 @@ Status Target::Launch(ProcessLaunchInfo &launch_info, Stream *stream) {
   if (!error.Success())
     return error;
 
-  if (synchronous_execution ||
-      !launch_info.GetFlags().Test(eLaunchFlagStopAtEntry)) {
-    ListenerSP hijack_listener_sp(launch_info.GetHijackListener());
-    if (!hijack_listener_sp) {
-      hijack_listener_sp = Listener::MakeListener("lldb.Target.Launch.hijack");
-      launch_info.SetHijackListener(hijack_listener_sp);
-      m_process_sp->HijackProcessEvents(hijack_listener_sp);
-    }
+  auto at_exit =
+      llvm::make_scope_exit([&]() { m_process_sp->RestoreProcessEvents(); });
 
-    StateType state = m_process_sp->WaitForProcessToStop(
-        llvm::None, nullptr, false, hijack_listener_sp, nullptr);
-
-    if (state == eStateStopped) {
-      if (!launch_info.GetFlags().Test(eLaunchFlagStopAtEntry)) {
-        if (synchronous_execution) {
-          // Now we have handled the stop-from-attach, and we are just
-          // switching to a synchronous resume.  So we should switch to the
-          // SyncResume hijacker.
-          m_process_sp->RestoreProcessEvents();
-          m_process_sp->ResumeSynchronous(stream);
-        } else {
-          m_process_sp->RestoreProcessEvents();
-          error = m_process_sp->PrivateResume();
-        }
-        if (!error.Success()) {
-          Status error2;
-          error2.SetErrorStringWithFormat(
-              "process resume at entry point failed: %s", error.AsCString());
-          error = error2;
-        }
+  if (!synchronous_execution &&
+      launch_info.GetFlags().Test(eLaunchFlagStopAtEntry))
+    return error;
+
+  ListenerSP hijack_listener_sp(launch_info.GetHijackListener());
+  if (!hijack_listener_sp) {
+    hijack_listener_sp = Listener::MakeListener("lldb.Target.Launch.hijack");
+    launch_info.SetHijackListener(hijack_listener_sp);
+    m_process_sp->HijackProcessEvents(hijack_listener_sp);
+  }
+
+  state = m_process_sp->WaitForProcessToStop(llvm::None, nullptr, false,
+                                             hijack_listener_sp, nullptr);
+
+  if (state == eStateStopped) {
+    if (!launch_info.GetFlags().Test(eLaunchFlagStopAtEntry)) {
+      if (synchronous_execution) {
+        // Now we have handled the stop-from-attach, and we are just
+        // switching to a synchronous resume.  So we should switch to the
+        // SyncResume hijacker.
+        m_process_sp->RestoreProcessEvents();
+        m_process_sp->ResumeSynchronous(stream);
+      } else {
+        m_process_sp->RestoreProcessEvents();
+        error = m_process_sp->PrivateResume();
       }
-    } else if (state == eStateExited) {
-      bool with_shell = !!launch_info.GetShell();
-      const int exit_status = m_process_sp->GetExitStatus();
-      const char *exit_desc = m_process_sp->GetExitDescription();
+      if (!error.Success()) {
+        Status error2;
+        error2.SetErrorStringWithFormat(
+            "process resume at entry point failed: %s", error.AsCString());
+        error = error2;
+      }
+    }
+  } else if (state == eStateExited) {
+    bool with_shell = !!launch_info.GetShell();
+    const int exit_status = m_process_sp->GetExitStatus();
+    const char *exit_desc = m_process_sp->GetExitDescription();
 #define LAUNCH_SHELL_MESSAGE                                                   \
   "\n'r' and 'run' are aliases that default to launching through a "           \
   "shell.\nTry launching without going through a shell by using 'process "     \
   "launch'."
-        if (exit_desc && exit_desc[0]) {
-          if (with_shell)
-            error.SetErrorStringWithFormat(
-                "process exited with status %i (%s)" LAUNCH_SHELL_MESSAGE,
-                exit_status, exit_desc);
-          else
-            error.SetErrorStringWithFormat("process exited with status %i (%s)",
-                                           exit_status, exit_desc);
-        } else {
-          if (with_shell)
-            error.SetErrorStringWithFormat(
-                "process exited with status %i" LAUNCH_SHELL_MESSAGE,
-                exit_status);
-          else
-            error.SetErrorStringWithFormat("process exited with status %i",
-                                           exit_status);
-        }
-      } else {
+    if (exit_desc && exit_desc[0]) {
+      if (with_shell)
         error.SetErrorStringWithFormat(
-            "initial process state wasn't stopped: %s", StateAsCString(state));
-      }
+            "process exited with status %i (%s)" LAUNCH_SHELL_MESSAGE,
+            exit_status, exit_desc);
+      else
+        error.SetErrorStringWithFormat("process exited with status %i (%s)",
+                                       exit_status, exit_desc);
+    } else {
+      if (with_shell)
+        error.SetErrorStringWithFormat(
+            "process exited with status %i" LAUNCH_SHELL_MESSAGE, exit_status);
+      else
+        error.SetErrorStringWithFormat("process exited with status %i",
+                                       exit_status);
+    }
+  } else {
+    error.SetErrorStringWithFormat("initial process state wasn't stopped: %s",
+                                   StateAsCString(state));
   }
-  m_process_sp->RestoreProcessEvents();
   return error;
 }
 


        


More information about the lldb-commits mailing list