Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion client/client_argv_handling.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ std::vector<std::string> BuildHandlerArgvStrings(
const std::vector<std::string>& arguments,
const std::vector<base::FilePath>& attachments,
const base::FilePath& crash_reporter,
const base::FilePath& crash_envelope) {
const base::FilePath& crash_envelope,
const std::string& report_id) {
std::vector<std::string> argv_strings(1, handler.value());

for (const auto& argument : arguments) {
Expand Down Expand Up @@ -81,6 +82,10 @@ std::vector<std::string> BuildHandlerArgvStrings(
FormatArgumentString("crash-envelope", crash_envelope.value()));
}

if (!report_id.empty()) {
argv_strings.push_back(FormatArgumentString("report-id", report_id));
}

return argv_strings;
}

Expand Down
3 changes: 2 additions & 1 deletion client/client_argv_handling.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ std::vector<std::string> BuildHandlerArgvStrings(
const std::vector<std::string>& arguments,
const std::vector<base::FilePath>& attachments = {},
const base::FilePath& crash_reporter = base::FilePath(),
const base::FilePath& crash_envelope = base::FilePath());
const base::FilePath& crash_envelope = base::FilePath(),
const std::string& report_id = std::string());

//! \brief Flattens a string vector into a const char* vector suitable for use
//! in an exec() call.
Expand Down
7 changes: 5 additions & 2 deletions client/crash_report_database.cc
Original file line number Diff line number Diff line change
Expand Up @@ -199,10 +199,13 @@ CrashReportDatabase::NewReport::~NewReport() = default;
bool CrashReportDatabase::NewReport::Initialize(
CrashReportDatabase* database,
const base::FilePath& directory,
const base::FilePath::StringType& extension) {
const base::FilePath::StringType& extension,
const UUID* uuid) {
database_ = database;

if (!uuid_.InitializeWithNew()) {
if (uuid && !uuid->IsZero()) {
uuid_ = *uuid;
} else if (!uuid_.InitializeWithNew()) {
return false;
}

Expand Down
7 changes: 5 additions & 2 deletions client/crash_report_database.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,8 @@ class CrashReportDatabase {

bool Initialize(CrashReportDatabase* database,
const base::FilePath& directory,
const base::FilePath::StringType& extension);
const base::FilePath::StringType& extension,
const UUID* uuid = nullptr);

std::unique_ptr<FileWriter> writer_;
std::unique_ptr<FileReader> reader_;
Expand Down Expand Up @@ -331,10 +332,12 @@ class CrashReportDatabase {
//!
//! \param[out] report A NewReport object containing a FileWriter with which
//! to write the report data. Only valid if this returns #kNoError.
//! \param[in] uuid Optional caller-provided UUID to use for this report. If
//! null, the database generates one.
//!
//! \return The operation status code.
virtual OperationStatus PrepareNewCrashReport(
std::unique_ptr<NewReport>* report) = 0;
std::unique_ptr<NewReport>* report, const UUID* uuid = nullptr) = 0;

//! \brief Informs the database that a crash report has been successfully
//! written.
Expand Down
9 changes: 6 additions & 3 deletions client/crash_report_database_generic.cc
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ class CrashReportDatabaseGeneric : public CrashReportDatabase {
// CrashReportDatabase:
Settings* GetSettings() override;
OperationStatus PrepareNewCrashReport(
std::unique_ptr<NewReport>* report) override;
std::unique_ptr<NewReport>* report, const UUID* uuid) override;
OperationStatus FinishedWritingCrashReport(std::unique_ptr<NewReport> report,
UUID* uuid) override;
OperationStatus LookUpCrashReport(const UUID& uuid, Report* report) override;
Expand Down Expand Up @@ -332,12 +332,15 @@ Settings* CrashReportDatabaseGeneric::GetSettings() {
}

OperationStatus CrashReportDatabaseGeneric::PrepareNewCrashReport(
std::unique_ptr<NewReport>* report) {
std::unique_ptr<NewReport>* report, const UUID* uuid) {
INITIALIZATION_STATE_DCHECK_VALID(initialized_);

auto new_report = std::make_unique<NewReport>();
if (!new_report->Initialize(
this, base_dir_.Append(kNewDirectory), kCrashReportExtension)) {
this,
base_dir_.Append(kNewDirectory),
kCrashReportExtension,
uuid)) {
return kFileSystemError;
}

Expand Down
7 changes: 4 additions & 3 deletions client/crash_report_database_mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ bool CreateOrEnsureDirectoryExists(const base::FilePath& path) {
// CrashReportDatabase:
Settings* GetSettings() override;
OperationStatus PrepareNewCrashReport(
std::unique_ptr<NewReport>* report) override;
std::unique_ptr<NewReport>* report, const UUID* uuid) override;
OperationStatus FinishedWritingCrashReport(std::unique_ptr<NewReport> report,
UUID* uuid) override;
OperationStatus LookUpCrashReport(const UUID& uuid, Report* report) override;
Expand Down Expand Up @@ -371,13 +371,14 @@ OperationStatus ReportsInDirectory(const base::FilePath& path,

CrashReportDatabase::OperationStatus
CrashReportDatabaseMac::PrepareNewCrashReport(
std::unique_ptr<NewReport>* out_report) {
std::unique_ptr<NewReport>* out_report, const UUID* uuid) {
INITIALIZATION_STATE_DCHECK_VALID(initialized_);

std::unique_ptr<NewReport> report(new NewReport());
if (!report->Initialize(this,
base_dir_.Append(kWriteDirectory),
std::string(".") + kCrashReportFileExtension)) {
std::string(".") + kCrashReportFileExtension,
uuid)) {
return kFileSystemError;
}

Expand Down
7 changes: 4 additions & 3 deletions client/crash_report_database_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,7 @@ class CrashReportDatabaseWin : public CrashReportDatabase {
// CrashReportDatabase:
Settings* GetSettings() override;
OperationStatus PrepareNewCrashReport(
std::unique_ptr<NewReport>* report) override;
std::unique_ptr<NewReport>* report, const UUID* uuid) override;
OperationStatus FinishedWritingCrashReport(std::unique_ptr<NewReport> report,
UUID* uuid) override;
OperationStatus LookUpCrashReport(const UUID& uuid, Report* report) override;
Expand Down Expand Up @@ -749,13 +749,14 @@ Settings* CrashReportDatabaseWin::GetSettings() {
}

OperationStatus CrashReportDatabaseWin::PrepareNewCrashReport(
std::unique_ptr<NewReport>* report) {
std::unique_ptr<NewReport>* report, const UUID* uuid) {
INITIALIZATION_STATE_DCHECK_VALID(initialized_);

std::unique_ptr<NewReport> new_report(new NewReport());
if (!new_report->Initialize(this,
base_dir_.Append(kReportsDirectory),
std::wstring(L".") + kCrashReportFileExtension)) {
std::wstring(L".") + kCrashReportFileExtension,
uuid)) {
return kFileSystemError;
}

Expand Down
5 changes: 4 additions & 1 deletion client/crashpad_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ class CrashpadClient {
//! executable that will be executed after a crash has been captured.
//! \param[in] crash_envelope The path to a crash report envelope that will be
//! filled up and passed as an argument to the crash reporter.
//! \param[in] report_id A UUID string to use as the report identifier instead
//! of generating a random one.
//!
//! \return `true` on success, `false` on failure with a message logged.
bool StartHandler(const base::FilePath& handler,
Expand All @@ -144,7 +146,8 @@ class CrashpadClient {
const base::FilePath& screenshot = base::FilePath(),
bool wait_for_upload = false,
const base::FilePath& crash_reporter = base::FilePath(),
const base::FilePath& crash_envelope = base::FilePath());
const base::FilePath& crash_envelope = base::FilePath(),
const std::string& report_id = std::string());

#if BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || \
DOXYGEN
Expand Down
6 changes: 4 additions & 2 deletions client/crashpad_client_linux.cc
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,8 @@ bool CrashpadClient::StartHandler(
const base::FilePath& screenshot,
bool wait_for_upload,
const base::FilePath& crash_reporter,
const base::FilePath& crash_envelope) {
const base::FilePath& crash_envelope,
const std::string& report_id) {
DCHECK(!asynchronous_start);

ScopedFileHandle client_sock, handler_sock;
Expand All @@ -508,7 +509,8 @@ bool CrashpadClient::StartHandler(
arguments,
attachments,
crash_reporter,
crash_envelope);
crash_envelope,
report_id);

argv.push_back(FormatArgumentInt("initial-client-fd", handler_sock.get()));
argv.push_back("--shared-client-connection");
Expand Down
21 changes: 18 additions & 3 deletions client/crashpad_client_mac.cc
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ class HandlerStarter final : public NotifyServer::DefaultInterface {
const std::vector<base::FilePath>& attachments,
const base::FilePath& crash_reporter,
const base::FilePath& crash_envelope,
const std::string& report_id,
bool restartable) {
base::apple::ScopedMachReceiveRight receive_right(
NewMachPort(MACH_PORT_RIGHT_RECEIVE));
Expand Down Expand Up @@ -184,6 +185,7 @@ class HandlerStarter final : public NotifyServer::DefaultInterface {
attachments,
crash_reporter,
crash_envelope,
report_id,
std::move(receive_right),
handler_restarter.get(),
false)) {
Expand All @@ -200,7 +202,8 @@ class HandlerStarter final : public NotifyServer::DefaultInterface {
arguments,
attachments,
crash_reporter,
crash_envelope)) {
crash_envelope,
report_id)) {
// The thread owns the object now.
std::ignore = handler_restarter.release();
}
Expand Down Expand Up @@ -239,6 +242,7 @@ class HandlerStarter final : public NotifyServer::DefaultInterface {
attachments_,
crash_reporter_,
crash_envelope_,
report_id_,
base::apple::ScopedMachReceiveRight(rights),
this,
true);
Expand All @@ -258,6 +262,7 @@ class HandlerStarter final : public NotifyServer::DefaultInterface {
attachments_(),
crash_reporter_(),
crash_envelope_(),
report_id_(),
notify_port_(NewMachPort(MACH_PORT_RIGHT_RECEIVE)),
last_start_time_(0) {}

Expand Down Expand Up @@ -290,6 +295,7 @@ class HandlerStarter final : public NotifyServer::DefaultInterface {
const std::vector<base::FilePath>& attachments,
const base::FilePath& crash_reporter,
const base::FilePath& crash_envelope,
const std::string& report_id,
base::apple::ScopedMachReceiveRight receive_right,
HandlerStarter* handler_restarter,
bool restart) {
Expand Down Expand Up @@ -387,6 +393,10 @@ class HandlerStarter final : public NotifyServer::DefaultInterface {
FormatArgumentString("crash-envelope", crash_envelope.value()));
}

if (!report_id.empty()) {
argv.push_back(FormatArgumentString("report-id", report_id));
}

argv.push_back(FormatArgumentInt("handshake-fd", server_write_fd.get()));

// When restarting, reset the system default crash handler first. Otherwise,
Expand Down Expand Up @@ -426,7 +436,8 @@ class HandlerStarter final : public NotifyServer::DefaultInterface {
const std::vector<std::string>& arguments,
const std::vector<base::FilePath>& attachments,
const base::FilePath& crash_reporter,
const base::FilePath& crash_envelope) {
const base::FilePath& crash_envelope,
const std::string& report_id) {
handler_ = handler;
database_ = database;
metrics_dir_ = metrics_dir;
Expand All @@ -437,6 +448,7 @@ class HandlerStarter final : public NotifyServer::DefaultInterface {
attachments_ = attachments;
crash_reporter_ = crash_reporter;
crash_envelope_ = crash_envelope;
report_id_ = report_id;

pthread_attr_t pthread_attr;
errno = pthread_attr_init(&pthread_attr);
Expand Down Expand Up @@ -493,6 +505,7 @@ class HandlerStarter final : public NotifyServer::DefaultInterface {
std::vector<base::FilePath> attachments_;
base::FilePath crash_reporter_;
base::FilePath crash_envelope_;
std::string report_id_;
base::apple::ScopedMachReceiveRight notify_port_;
uint64_t last_start_time_;
};
Expand All @@ -519,7 +532,8 @@ bool CrashpadClient::StartHandler(
const base::FilePath& screenshot,
bool wait_for_upload,
const base::FilePath& crash_reporter,
const base::FilePath& crash_envelope) {
const base::FilePath& crash_envelope,
const std::string& report_id) {
(void) wait_for_upload; // unused in mac (for now)

// The “restartable” behavior can only be selected on OS X 10.10 and later. In
Expand All @@ -536,6 +550,7 @@ bool CrashpadClient::StartHandler(
attachments,
crash_reporter,
crash_envelope,
report_id,
restartable && (__MAC_OS_X_VERSION_MIN_REQUIRED >= __MAC_10_10 ||
MacOSVersionNumber() >= 10'10'00)));
if (!exception_port.is_valid()) {
Expand Down
12 changes: 11 additions & 1 deletion client/crashpad_client_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,7 @@ struct BackgroundHandlerStartThreadData {
const bool wait_for_upload,
const base::FilePath& crash_reporter,
const base::FilePath& crash_envelope,
const std::string& report_id,
const std::wstring& ipc_pipe,
ScopedFileHANDLE ipc_pipe_handle)
: handler(handler),
Expand All @@ -373,6 +374,7 @@ struct BackgroundHandlerStartThreadData {
wait_for_upload(wait_for_upload),
crash_reporter(crash_reporter),
crash_envelope(crash_envelope),
report_id(report_id),
ipc_pipe(ipc_pipe),
ipc_pipe_handle(std::move(ipc_pipe_handle)) {}

Expand All @@ -388,6 +390,7 @@ struct BackgroundHandlerStartThreadData {
bool wait_for_upload;
base::FilePath crash_reporter;
base::FilePath crash_envelope;
std::string report_id;
std::wstring ipc_pipe;
ScopedFileHANDLE ipc_pipe_handle;
};
Expand Down Expand Up @@ -475,6 +478,11 @@ bool StartHandlerProcess(
FormatArgumentString("crash-envelope", data->crash_envelope.value()),
&command_line);
}
if (!data->report_id.empty()) {
AppendCommandLineArgument(
FormatArgumentString("report-id", base::UTF8ToWide(data->report_id)),
&command_line);
}

ScopedKernelHANDLE this_process(
OpenProcess(kXPProcessLimitedAccess, true, GetCurrentProcessId()));
Expand Down Expand Up @@ -674,7 +682,8 @@ bool CrashpadClient::StartHandler(
const base::FilePath& screenshot,
bool wait_for_upload,
const base::FilePath& crash_reporter,
const base::FilePath& crash_envelope) {
const base::FilePath& crash_envelope,
const std::string& report_id) {
DCHECK(ipc_pipe_.empty());

// Both the pipe and the signalling events have to be created on the main
Expand Down Expand Up @@ -710,6 +719,7 @@ bool CrashpadClient::StartHandler(
wait_for_upload,
crash_reporter,
crash_envelope,
report_id,
ipc_pipe_,
std::move(ipc_pipe_handle));

Expand Down
Loading