[Lldb-commits] [lldb] 55dd731 - [debugserver] Extract function for default launch flavor

Dave Lee via lldb-commits lldb-commits at lists.llvm.org
Wed Sep 9 11:35:52 PDT 2020


Author: Dave Lee
Date: 2020-09-09T11:35:44-07:00
New Revision: 55dd731b291c2d64f318f27c40a17d2255e16215

URL: https://github.com/llvm/llvm-project/commit/55dd731b291c2d64f318f27c40a17d2255e16215
DIFF: https://github.com/llvm/llvm-project/commit/55dd731b291c2d64f318f27c40a17d2255e16215.diff

LOG: [debugserver] Extract function for default launch flavor

Extract a function for turning `eLaunchFlavorDefault` into a concreate `eLaunchFlavor` value.

This new function encapsulates the few compile time variables involved, and also prevents clang unused code diagnostics.

Differential Revision: https://reviews.llvm.org/D87327

Added: 
    

Modified: 
    lldb/tools/debugserver/source/debugserver.cpp

Removed: 
    


################################################################################
diff  --git a/lldb/tools/debugserver/source/debugserver.cpp b/lldb/tools/debugserver/source/debugserver.cpp
index 04cbd2c8b503..feb65eb6d3fb 100644
--- a/lldb/tools/debugserver/source/debugserver.cpp
+++ b/lldb/tools/debugserver/source/debugserver.cpp
@@ -156,18 +156,36 @@ RNBRunLoopMode RNBRunLoopGetStartModeFromRemote(RNBRemote *remote) {
   return eRNBRunLoopModeExit;
 }
 
-// Check the name to see if it ends with .app
-static bool is_dot_app (const char *app_name) {
-  size_t len = strlen(app_name);
-  if (len < 4)
+static nub_launch_flavor_t default_launch_flavor(const char *app_name) {
+#if defined(WITH_FBS) || defined(WITH_BKS) || defined(WITH_SPRINGBOARD)
+  // Check the name to see if it ends with .app
+  auto is_dot_app = [](const char *app_name) {
+    size_t len = strlen(app_name);
+    if (len < 4)
+      return false;
+
+    if (app_name[len - 4] == '.' && app_name[len - 3] == 'a' &&
+        app_name[len - 2] == 'p' && app_name[len - 1] == 'p')
+      return true;
     return false;
-  
-  if (app_name[len - 4] == '.' &&
-      app_name[len - 3] == 'a' && 
-      app_name[len - 2] == 'p' &&
-      app_name[len - 1] == 'p')
-    return true;
-  return false;
+  };
+
+  if (is_dot_app(app_name)) {
+#if defined WITH_FBS
+    // Check if we have an app bundle, if so launch using FrontBoard Services.
+    return eLaunchFlavorFBS;
+#elif defined WITH_BKS
+    // Check if we have an app bundle, if so launch using BackBoard Services.
+    return eLaunchFlavorBKS;
+#elif defined WITH_SPRINGBOARD
+    // Check if we have an app bundle, if so launch using SpringBoard.
+    return eLaunchFlavorSpringBoard;
+#endif
+  }
+#endif
+
+  // Our default launch method is posix spawn
+  return eLaunchFlavorPosixSpawn;
 }
 
 // This run loop mode will wait for the process to launch and hit its
@@ -208,29 +226,8 @@ RNBRunLoopMode RNBRunLoopLaunchInferior(RNBRemote *remote,
   // figure our how we are going to launch automatically.
 
   nub_launch_flavor_t launch_flavor = g_launch_flavor;
-  if (launch_flavor == eLaunchFlavorDefault) {
-    // Our default launch method is posix spawn
-    launch_flavor = eLaunchFlavorPosixSpawn;
-
-    const bool dot_app = is_dot_app(inferior_argv[0]);
-    (void)dot_app;
-#if defined WITH_FBS
-    // Check if we have an app bundle, if so launch using BackBoard Services.
-    if (dot_app) {
-      launch_flavor = eLaunchFlavorFBS;
-    }
-#elif defined WITH_BKS
-    // Check if we have an app bundle, if so launch using BackBoard Services.
-    if (dot_app) {
-      launch_flavor = eLaunchFlavorBKS;
-    }
-#elif defined WITH_SPRINGBOARD
-    // Check if we have an app bundle, if so launch using SpringBoard.
-    if (dot_app) {
-      launch_flavor = eLaunchFlavorSpringBoard;
-    }
-#endif
-  }
+  if (launch_flavor == eLaunchFlavorDefault)
+    launch_flavor = default_launch_flavor(inferior_argv[0]);
 
   ctx.SetLaunchFlavor(launch_flavor);
   char resolved_path[PATH_MAX];
@@ -1509,27 +1506,8 @@ int main(int argc, char *argv[]) {
           timeout_ptr = &attach_timeout_abstime;
         }
         nub_launch_flavor_t launch_flavor = g_launch_flavor;
-        if (launch_flavor == eLaunchFlavorDefault) {
-          // Our default launch method is posix spawn
-          launch_flavor = eLaunchFlavorPosixSpawn;
-
-#if defined WITH_FBS
-          // Check if we have an app bundle, if so launch using SpringBoard.
-          if (is_dot_app(waitfor_pid_name.c_str())) {
-            launch_flavor = eLaunchFlavorFBS;
-          }
-#elif defined WITH_BKS
-          // Check if we have an app bundle, if so launch using SpringBoard.
-          if (is_dot_app(waitfor_pid_name.c_str())) {
-            launch_flavor = eLaunchFlavorBKS;
-          }
-#elif defined WITH_SPRINGBOARD
-          // Check if we have an app bundle, if so launch using SpringBoard.
-          if (is_dot_app(waitfor_pid_name.c_str())) {
-            launch_flavor = eLaunchFlavorSpringBoard;
-          }
-#endif
-        }
+        if (launch_flavor == eLaunchFlavorDefault)
+          launch_flavor = default_launch_flavor(waitfor_pid_name.c_str());
 
         ctx.SetLaunchFlavor(launch_flavor);
         bool ignore_existing = false;


        


More information about the lldb-commits mailing list