]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
analyze: merge if branches on debugger
authorYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 17 Jul 2025 16:29:05 +0000 (01:29 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 17 Jul 2025 16:39:51 +0000 (01:39 +0900)
No functional changes, just refactoring.

src/analyze/analyze-unit-gdb.c

index 85e7488ca06fe78ad1998bba540f88d543903fbf..06b5fa74530abab4b7c067c6f91a188681f6d62e 100644 (file)
@@ -69,39 +69,39 @@ int verb_unit_gdb(int argc, char *argv[], void *userdata) {
                         return log_oom();
         }
 
+        if (!STR_IN_SET(arg_debugger, "gdb", "lldb"))
+                return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "The debugger must be either 'gdb' or 'lldb'.");
+
         _cleanup_strv_free_ char **debugger_call = NULL;
         r = strv_extend(&debugger_call, arg_debugger);
         if (r < 0)
                 return log_oom();
 
-        if (!STR_IN_SET(arg_debugger, "gdb", "lldb"))
-                return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "The debugger must be either 'gdb' or 'lldb'.");
-
         if (streq(arg_debugger, "gdb")) {
                 r = strv_extendf(&debugger_call, "--pid=" PID_FMT, pid);
                 if (r < 0)
                         return log_oom();
-        }
 
-        if (streq(arg_debugger, "lldb")) {
-                r = strv_extendf(&debugger_call, "--attach-pid=" PID_FMT, pid);
-                if (r < 0)
-                        return log_oom();
-        }
-
-        if (arg_root) {
-                if (streq(arg_debugger, "gdb")) {
+                if (arg_root) {
                         _cleanup_free_ char *sysroot_cmd = strjoin("set sysroot ", arg_root);
                         r = strv_extend_many(&debugger_call, "-iex", sysroot_cmd);
                         if (r < 0)
                                 return log_oom();
-                } else if (streq(arg_debugger, "lldb")) {
+                }
+
+        } else if (streq(arg_debugger, "lldb")) {
+                r = strv_extendf(&debugger_call, "--attach-pid=" PID_FMT, pid);
+                if (r < 0)
+                        return log_oom();
+
+                if (arg_root) {
                         _cleanup_free_ char *sysroot_cmd = strjoin("platform select --sysroot ", arg_root, " host");
                         r = strv_extend_many(&debugger_call, "-O", sysroot_cmd);
                         if (r < 0)
                                 return log_oom();
                 }
-        }
+        } else
+                assert_not_reached();
 
         /* Don't interfere with debugger and its handling of SIGINT. */
         (void) ignore_signals(SIGINT);