From d86bed44ec3afc0b91c837505b26f99824a897ca Mon Sep 17 00:00:00 2001 From: George Menhorn Date: Wed, 29 May 2024 12:40:16 -0400 Subject: [PATCH] crashpad/linux: NFC: factor appending arguments to handler Factor the appending of additional arguments that are passed to a handler for the crash loop detection and guid override features. These will also be passed to the Java handler used by Android in a later commit. Internal ref BT-2929 --- client/crashpad_client.h | 9 +++++++ client/crashpad_client_linux.cc | 44 +++++++++++++++++---------------- 2 files changed, 32 insertions(+), 21 deletions(-) diff --git a/client/crashpad_client.h b/client/crashpad_client.h index f48faab5..7441580c 100644 --- a/client/crashpad_client.h +++ b/client/crashpad_client.h @@ -856,10 +856,19 @@ class CrashpadClient { bool crash_loop_detection_ = false; UUID run_uuid_; std::set unhandled_signals_; + + // Append the necessary annotation to the crash handler arguments if crash loop detection is + // enabled. + void MaybeAppendCrashLoopDetectionArgs(const base::FilePath& database, + std::vector *handler_args); #endif // BUILDFLAG(IS_APPLE) #if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_ANDROID) bool uuid_override_enabled_ = false; UUID uuid_override_; + + // Append the necessary annotation to the crash handler arguments if the GUID was overriden + // by `OverrideGuid`. + void MaybeAppendUuidOverrideArgs(std::vector *handler_args); #endif // BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_ANDROID) }; diff --git a/client/crashpad_client_linux.cc b/client/crashpad_client_linux.cc index e78149ed..01f5970d 100644 --- a/client/crashpad_client_linux.cc +++ b/client/crashpad_client_linux.cc @@ -471,16 +471,8 @@ bool CrashpadClient::StartHandler( argv.push_back(FormatArgumentInt("initial-client-fd", handler_sock.get())); argv.push_back("--shared-client-connection"); - if (crash_loop_detection_) { - namespace clc = backtrace::crash_loop_detection; - DCHECK(clc::CrashLoopDetectionAppend(database, run_uuid_)); - argv.push_back("--annotation=run-uuid=" + run_uuid_.ToString()); - } - - if (uuid_override_enabled_) { - argv.push_back("--annotation=_backtrace_internal_guid_override=" + - uuid_override_.ToString()); - } + MaybeAppendCrashLoopDetectionArgs(database, &argv); + MaybeAppendUuidOverrideArgs(&argv); if (!SpawnSubprocess(argv, nullptr, handler_sock.get(), false, nullptr)) { return false; @@ -514,6 +506,17 @@ int CrashpadClient::ConsecutiveCrashesCount(const base::FilePath& database) namespace clc = backtrace::crash_loop_detection; return clc::ConsecutiveCrashesCount(database); } + +void CrashpadClient::MaybeAppendCrashLoopDetectionArgs(const base::FilePath& database, + std::vector *handler_args) +{ + if (crash_loop_detection_) { + namespace clc = backtrace::crash_loop_detection; + bool ok = clc::CrashLoopDetectionAppend(database, run_uuid_); + DCHECK(ok); + handler_args->push_back("--annotation=run-uuid=" + run_uuid_.ToString()); + } +} #endif bool CrashpadClient::OverrideGuid(const std::string& uuid) @@ -531,6 +534,14 @@ bool CrashpadClient::OverrideGuid(const UUID& uuid) return true; } +void CrashpadClient::MaybeAppendUuidOverrideArgs(std::vector *handler_args) +{ + if (uuid_override_enabled_) { + handler_args->push_back("--annotation=_backtrace_internal_guid_override=" + + uuid_override_.ToString()); + } +} + #if BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) // static bool CrashpadClient::GetHandlerSocket(int* sock, pid_t* pid) { @@ -741,17 +752,8 @@ bool CrashpadClient::StartHandlerAtCrash( backtrace::android_cert_store::create(database); #endif - if (crash_loop_detection_) { - namespace clc = backtrace::crash_loop_detection; - bool ok = clc::CrashLoopDetectionAppend(database, run_uuid_); - DCHECK(ok); - argv.push_back("--annotation=run-uuid=" + run_uuid_.ToString()); - } - - if (uuid_override_enabled_) { - argv.push_back("--annotation=_backtrace_internal_guid_override=" + - uuid_override_.ToString()); - } + MaybeAppendCrashLoopDetectionArgs(database, &argv); + MaybeAppendUuidOverrideArgs(&argv); auto signal_handler = LaunchAtCrashHandler::Get(); return signal_handler->Initialize(&argv, nullptr, &unhandled_signals_);