From ff4c911ffd3f67875fabb41bcbd192af015116a5 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Fri, 18 Jul 2025 01:29:05 +0900 Subject: [PATCH] analyze: merge if branches on debugger No functional changes, just refactoring. --- src/analyze/analyze-unit-gdb.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/analyze/analyze-unit-gdb.c b/src/analyze/analyze-unit-gdb.c index 85e7488ca06..06b5fa74530 100644 --- a/src/analyze/analyze-unit-gdb.c +++ b/src/analyze/analyze-unit-gdb.c @@ -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); -- 2.47.3