Skip to content

Commit

Permalink
crashpad/linux: NFC: factor appending arguments to handler
Browse files Browse the repository at this point in the history
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
  • Loading branch information
gm4sl committed May 30, 2024
1 parent eeef0df commit d86bed4
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 21 deletions.
9 changes: 9 additions & 0 deletions client/crashpad_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -856,10 +856,19 @@ class CrashpadClient {
bool crash_loop_detection_ = false;
UUID run_uuid_;
std::set<int> 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<std::string> *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<std::string> *handler_args);
#endif // BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_ANDROID)
};

Expand Down
44 changes: 23 additions & 21 deletions client/crashpad_client_linux.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<std::string> *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)
Expand All @@ -531,6 +534,14 @@ bool CrashpadClient::OverrideGuid(const UUID& uuid)
return true;
}

void CrashpadClient::MaybeAppendUuidOverrideArgs(std::vector<std::string> *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) {
Expand Down Expand Up @@ -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_);
Expand Down

0 comments on commit d86bed4

Please sign in to comment.