Skip to content

Commit 55dd731

Browse files
committed
[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
1 parent 81ff2d3 commit 55dd731

File tree

1 file changed

+33
-55
lines changed

1 file changed

+33
-55
lines changed

lldb/tools/debugserver/source/debugserver.cpp

Lines changed: 33 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -156,18 +156,36 @@ RNBRunLoopMode RNBRunLoopGetStartModeFromRemote(RNBRemote *remote) {
156156
return eRNBRunLoopModeExit;
157157
}
158158

159-
// Check the name to see if it ends with .app
160-
static bool is_dot_app (const char *app_name) {
161-
size_t len = strlen(app_name);
162-
if (len < 4)
159+
static nub_launch_flavor_t default_launch_flavor(const char *app_name) {
160+
#if defined(WITH_FBS) || defined(WITH_BKS) || defined(WITH_SPRINGBOARD)
161+
// Check the name to see if it ends with .app
162+
auto is_dot_app = [](const char *app_name) {
163+
size_t len = strlen(app_name);
164+
if (len < 4)
165+
return false;
166+
167+
if (app_name[len - 4] == '.' && app_name[len - 3] == 'a' &&
168+
app_name[len - 2] == 'p' && app_name[len - 1] == 'p')
169+
return true;
163170
return false;
164-
165-
if (app_name[len - 4] == '.' &&
166-
app_name[len - 3] == 'a' &&
167-
app_name[len - 2] == 'p' &&
168-
app_name[len - 1] == 'p')
169-
return true;
170-
return false;
171+
};
172+
173+
if (is_dot_app(app_name)) {
174+
#if defined WITH_FBS
175+
// Check if we have an app bundle, if so launch using FrontBoard Services.
176+
return eLaunchFlavorFBS;
177+
#elif defined WITH_BKS
178+
// Check if we have an app bundle, if so launch using BackBoard Services.
179+
return eLaunchFlavorBKS;
180+
#elif defined WITH_SPRINGBOARD
181+
// Check if we have an app bundle, if so launch using SpringBoard.
182+
return eLaunchFlavorSpringBoard;
183+
#endif
184+
}
185+
#endif
186+
187+
// Our default launch method is posix spawn
188+
return eLaunchFlavorPosixSpawn;
171189
}
172190

173191
// This run loop mode will wait for the process to launch and hit its
@@ -208,29 +226,8 @@ RNBRunLoopMode RNBRunLoopLaunchInferior(RNBRemote *remote,
208226
// figure our how we are going to launch automatically.
209227

210228
nub_launch_flavor_t launch_flavor = g_launch_flavor;
211-
if (launch_flavor == eLaunchFlavorDefault) {
212-
// Our default launch method is posix spawn
213-
launch_flavor = eLaunchFlavorPosixSpawn;
214-
215-
const bool dot_app = is_dot_app(inferior_argv[0]);
216-
(void)dot_app;
217-
#if defined WITH_FBS
218-
// Check if we have an app bundle, if so launch using BackBoard Services.
219-
if (dot_app) {
220-
launch_flavor = eLaunchFlavorFBS;
221-
}
222-
#elif defined WITH_BKS
223-
// Check if we have an app bundle, if so launch using BackBoard Services.
224-
if (dot_app) {
225-
launch_flavor = eLaunchFlavorBKS;
226-
}
227-
#elif defined WITH_SPRINGBOARD
228-
// Check if we have an app bundle, if so launch using SpringBoard.
229-
if (dot_app) {
230-
launch_flavor = eLaunchFlavorSpringBoard;
231-
}
232-
#endif
233-
}
229+
if (launch_flavor == eLaunchFlavorDefault)
230+
launch_flavor = default_launch_flavor(inferior_argv[0]);
234231

235232
ctx.SetLaunchFlavor(launch_flavor);
236233
char resolved_path[PATH_MAX];
@@ -1509,27 +1506,8 @@ int main(int argc, char *argv[]) {
15091506
timeout_ptr = &attach_timeout_abstime;
15101507
}
15111508
nub_launch_flavor_t launch_flavor = g_launch_flavor;
1512-
if (launch_flavor == eLaunchFlavorDefault) {
1513-
// Our default launch method is posix spawn
1514-
launch_flavor = eLaunchFlavorPosixSpawn;
1515-
1516-
#if defined WITH_FBS
1517-
// Check if we have an app bundle, if so launch using SpringBoard.
1518-
if (is_dot_app(waitfor_pid_name.c_str())) {
1519-
launch_flavor = eLaunchFlavorFBS;
1520-
}
1521-
#elif defined WITH_BKS
1522-
// Check if we have an app bundle, if so launch using SpringBoard.
1523-
if (is_dot_app(waitfor_pid_name.c_str())) {
1524-
launch_flavor = eLaunchFlavorBKS;
1525-
}
1526-
#elif defined WITH_SPRINGBOARD
1527-
// Check if we have an app bundle, if so launch using SpringBoard.
1528-
if (is_dot_app(waitfor_pid_name.c_str())) {
1529-
launch_flavor = eLaunchFlavorSpringBoard;
1530-
}
1531-
#endif
1532-
}
1509+
if (launch_flavor == eLaunchFlavorDefault)
1510+
launch_flavor = default_launch_flavor(waitfor_pid_name.c_str());
15331511

15341512
ctx.SetLaunchFlavor(launch_flavor);
15351513
bool ignore_existing = false;

0 commit comments

Comments
 (0)