Skip to content

Commit eb5fa6e

Browse files
authored
feat: allow predefined report ID (#144)
1 parent 45a6f02 commit eb5fa6e

20 files changed

+121
-34
lines changed

client/client_argv_handling.cc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ std::vector<std::string> BuildHandlerArgvStrings(
3737
const std::vector<std::string>& arguments,
3838
const std::vector<base::FilePath>& attachments,
3939
const base::FilePath& crash_reporter,
40-
const base::FilePath& crash_envelope) {
40+
const base::FilePath& crash_envelope,
41+
const std::string& report_id) {
4142
std::vector<std::string> argv_strings(1, handler.value());
4243

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

85+
if (!report_id.empty()) {
86+
argv_strings.push_back(FormatArgumentString("report-id", report_id));
87+
}
88+
8489
return argv_strings;
8590
}
8691

client/client_argv_handling.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ std::vector<std::string> BuildHandlerArgvStrings(
3939
const std::vector<std::string>& arguments,
4040
const std::vector<base::FilePath>& attachments = {},
4141
const base::FilePath& crash_reporter = base::FilePath(),
42-
const base::FilePath& crash_envelope = base::FilePath());
42+
const base::FilePath& crash_envelope = base::FilePath(),
43+
const std::string& report_id = std::string());
4344

4445
//! \brief Flattens a string vector into a const char* vector suitable for use
4546
//! in an exec() call.

client/crash_report_database.cc

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,10 +199,13 @@ CrashReportDatabase::NewReport::~NewReport() = default;
199199
bool CrashReportDatabase::NewReport::Initialize(
200200
CrashReportDatabase* database,
201201
const base::FilePath& directory,
202-
const base::FilePath::StringType& extension) {
202+
const base::FilePath::StringType& extension,
203+
const UUID* uuid) {
203204
database_ = database;
204205

205-
if (!uuid_.InitializeWithNew()) {
206+
if (uuid && !uuid->IsZero()) {
207+
uuid_ = *uuid;
208+
} else if (!uuid_.InitializeWithNew()) {
206209
return false;
207210
}
208211

client/crash_report_database.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,8 @@ class CrashReportDatabase {
145145

146146
bool Initialize(CrashReportDatabase* database,
147147
const base::FilePath& directory,
148-
const base::FilePath::StringType& extension);
148+
const base::FilePath::StringType& extension,
149+
const UUID* uuid = nullptr);
149150

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

339342
//! \brief Informs the database that a crash report has been successfully
340343
//! written.

client/crash_report_database_generic.cc

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ class CrashReportDatabaseGeneric : public CrashReportDatabase {
176176
// CrashReportDatabase:
177177
Settings* GetSettings() override;
178178
OperationStatus PrepareNewCrashReport(
179-
std::unique_ptr<NewReport>* report) override;
179+
std::unique_ptr<NewReport>* report, const UUID* uuid) override;
180180
OperationStatus FinishedWritingCrashReport(std::unique_ptr<NewReport> report,
181181
UUID* uuid) override;
182182
OperationStatus LookUpCrashReport(const UUID& uuid, Report* report) override;
@@ -332,12 +332,15 @@ Settings* CrashReportDatabaseGeneric::GetSettings() {
332332
}
333333

334334
OperationStatus CrashReportDatabaseGeneric::PrepareNewCrashReport(
335-
std::unique_ptr<NewReport>* report) {
335+
std::unique_ptr<NewReport>* report, const UUID* uuid) {
336336
INITIALIZATION_STATE_DCHECK_VALID(initialized_);
337337

338338
auto new_report = std::make_unique<NewReport>();
339339
if (!new_report->Initialize(
340-
this, base_dir_.Append(kNewDirectory), kCrashReportExtension)) {
340+
this,
341+
base_dir_.Append(kNewDirectory),
342+
kCrashReportExtension,
343+
uuid)) {
341344
return kFileSystemError;
342345
}
343346

client/crash_report_database_mac.mm

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ bool CreateOrEnsureDirectoryExists(const base::FilePath& path) {
152152
// CrashReportDatabase:
153153
Settings* GetSettings() override;
154154
OperationStatus PrepareNewCrashReport(
155-
std::unique_ptr<NewReport>* report) override;
155+
std::unique_ptr<NewReport>* report, const UUID* uuid) override;
156156
OperationStatus FinishedWritingCrashReport(std::unique_ptr<NewReport> report,
157157
UUID* uuid) override;
158158
OperationStatus LookUpCrashReport(const UUID& uuid, Report* report) override;
@@ -371,13 +371,14 @@ OperationStatus ReportsInDirectory(const base::FilePath& path,
371371

372372
CrashReportDatabase::OperationStatus
373373
CrashReportDatabaseMac::PrepareNewCrashReport(
374-
std::unique_ptr<NewReport>* out_report) {
374+
std::unique_ptr<NewReport>* out_report, const UUID* uuid) {
375375
INITIALIZATION_STATE_DCHECK_VALID(initialized_);
376376

377377
std::unique_ptr<NewReport> report(new NewReport());
378378
if (!report->Initialize(this,
379379
base_dir_.Append(kWriteDirectory),
380-
std::string(".") + kCrashReportFileExtension)) {
380+
std::string(".") + kCrashReportFileExtension,
381+
uuid)) {
381382
return kFileSystemError;
382383
}
383384

client/crash_report_database_win.cc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -635,7 +635,7 @@ class CrashReportDatabaseWin : public CrashReportDatabase {
635635
// CrashReportDatabase:
636636
Settings* GetSettings() override;
637637
OperationStatus PrepareNewCrashReport(
638-
std::unique_ptr<NewReport>* report) override;
638+
std::unique_ptr<NewReport>* report, const UUID* uuid) override;
639639
OperationStatus FinishedWritingCrashReport(std::unique_ptr<NewReport> report,
640640
UUID* uuid) override;
641641
OperationStatus LookUpCrashReport(const UUID& uuid, Report* report) override;
@@ -749,13 +749,14 @@ Settings* CrashReportDatabaseWin::GetSettings() {
749749
}
750750

751751
OperationStatus CrashReportDatabaseWin::PrepareNewCrashReport(
752-
std::unique_ptr<NewReport>* report) {
752+
std::unique_ptr<NewReport>* report, const UUID* uuid) {
753753
INITIALIZATION_STATE_DCHECK_VALID(initialized_);
754754

755755
std::unique_ptr<NewReport> new_report(new NewReport());
756756
if (!new_report->Initialize(this,
757757
base_dir_.Append(kReportsDirectory),
758-
std::wstring(L".") + kCrashReportFileExtension)) {
758+
std::wstring(L".") + kCrashReportFileExtension,
759+
uuid)) {
759760
return kFileSystemError;
760761
}
761762

client/crashpad_client.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,8 @@ class CrashpadClient {
129129
//! executable that will be executed after a crash has been captured.
130130
//! \param[in] crash_envelope The path to a crash report envelope that will be
131131
//! filled up and passed as an argument to the crash reporter.
132+
//! \param[in] report_id A UUID string to use as the report identifier instead
133+
//! of generating a random one.
132134
//!
133135
//! \return `true` on success, `false` on failure with a message logged.
134136
bool StartHandler(const base::FilePath& handler,
@@ -144,7 +146,8 @@ class CrashpadClient {
144146
const base::FilePath& screenshot = base::FilePath(),
145147
bool wait_for_upload = false,
146148
const base::FilePath& crash_reporter = base::FilePath(),
147-
const base::FilePath& crash_envelope = base::FilePath());
149+
const base::FilePath& crash_envelope = base::FilePath(),
150+
const std::string& report_id = std::string());
148151

149152
#if BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || \
150153
DOXYGEN

client/crashpad_client_linux.cc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,8 @@ bool CrashpadClient::StartHandler(
490490
const base::FilePath& screenshot,
491491
bool wait_for_upload,
492492
const base::FilePath& crash_reporter,
493-
const base::FilePath& crash_envelope) {
493+
const base::FilePath& crash_envelope,
494+
const std::string& report_id) {
494495
DCHECK(!asynchronous_start);
495496

496497
ScopedFileHandle client_sock, handler_sock;
@@ -508,7 +509,8 @@ bool CrashpadClient::StartHandler(
508509
arguments,
509510
attachments,
510511
crash_reporter,
511-
crash_envelope);
512+
crash_envelope,
513+
report_id);
512514

513515
argv.push_back(FormatArgumentInt("initial-client-fd", handler_sock.get()));
514516
argv.push_back("--shared-client-connection");

client/crashpad_client_mac.cc

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ class HandlerStarter final : public NotifyServer::DefaultInterface {
141141
const std::vector<base::FilePath>& attachments,
142142
const base::FilePath& crash_reporter,
143143
const base::FilePath& crash_envelope,
144+
const std::string& report_id,
144145
bool restartable) {
145146
base::apple::ScopedMachReceiveRight receive_right(
146147
NewMachPort(MACH_PORT_RIGHT_RECEIVE));
@@ -184,6 +185,7 @@ class HandlerStarter final : public NotifyServer::DefaultInterface {
184185
attachments,
185186
crash_reporter,
186187
crash_envelope,
188+
report_id,
187189
std::move(receive_right),
188190
handler_restarter.get(),
189191
false)) {
@@ -200,7 +202,8 @@ class HandlerStarter final : public NotifyServer::DefaultInterface {
200202
arguments,
201203
attachments,
202204
crash_reporter,
203-
crash_envelope)) {
205+
crash_envelope,
206+
report_id)) {
204207
// The thread owns the object now.
205208
std::ignore = handler_restarter.release();
206209
}
@@ -239,6 +242,7 @@ class HandlerStarter final : public NotifyServer::DefaultInterface {
239242
attachments_,
240243
crash_reporter_,
241244
crash_envelope_,
245+
report_id_,
242246
base::apple::ScopedMachReceiveRight(rights),
243247
this,
244248
true);
@@ -258,6 +262,7 @@ class HandlerStarter final : public NotifyServer::DefaultInterface {
258262
attachments_(),
259263
crash_reporter_(),
260264
crash_envelope_(),
265+
report_id_(),
261266
notify_port_(NewMachPort(MACH_PORT_RIGHT_RECEIVE)),
262267
last_start_time_(0) {}
263268

@@ -290,6 +295,7 @@ class HandlerStarter final : public NotifyServer::DefaultInterface {
290295
const std::vector<base::FilePath>& attachments,
291296
const base::FilePath& crash_reporter,
292297
const base::FilePath& crash_envelope,
298+
const std::string& report_id,
293299
base::apple::ScopedMachReceiveRight receive_right,
294300
HandlerStarter* handler_restarter,
295301
bool restart) {
@@ -387,6 +393,10 @@ class HandlerStarter final : public NotifyServer::DefaultInterface {
387393
FormatArgumentString("crash-envelope", crash_envelope.value()));
388394
}
389395

396+
if (!report_id.empty()) {
397+
argv.push_back(FormatArgumentString("report-id", report_id));
398+
}
399+
390400
argv.push_back(FormatArgumentInt("handshake-fd", server_write_fd.get()));
391401

392402
// When restarting, reset the system default crash handler first. Otherwise,
@@ -426,7 +436,8 @@ class HandlerStarter final : public NotifyServer::DefaultInterface {
426436
const std::vector<std::string>& arguments,
427437
const std::vector<base::FilePath>& attachments,
428438
const base::FilePath& crash_reporter,
429-
const base::FilePath& crash_envelope) {
439+
const base::FilePath& crash_envelope,
440+
const std::string& report_id) {
430441
handler_ = handler;
431442
database_ = database;
432443
metrics_dir_ = metrics_dir;
@@ -437,6 +448,7 @@ class HandlerStarter final : public NotifyServer::DefaultInterface {
437448
attachments_ = attachments;
438449
crash_reporter_ = crash_reporter;
439450
crash_envelope_ = crash_envelope;
451+
report_id_ = report_id;
440452

441453
pthread_attr_t pthread_attr;
442454
errno = pthread_attr_init(&pthread_attr);
@@ -493,6 +505,7 @@ class HandlerStarter final : public NotifyServer::DefaultInterface {
493505
std::vector<base::FilePath> attachments_;
494506
base::FilePath crash_reporter_;
495507
base::FilePath crash_envelope_;
508+
std::string report_id_;
496509
base::apple::ScopedMachReceiveRight notify_port_;
497510
uint64_t last_start_time_;
498511
};
@@ -519,7 +532,8 @@ bool CrashpadClient::StartHandler(
519532
const base::FilePath& screenshot,
520533
bool wait_for_upload,
521534
const base::FilePath& crash_reporter,
522-
const base::FilePath& crash_envelope) {
535+
const base::FilePath& crash_envelope,
536+
const std::string& report_id) {
523537
(void) wait_for_upload; // unused in mac (for now)
524538

525539
// The “restartable” behavior can only be selected on OS X 10.10 and later. In
@@ -536,6 +550,7 @@ bool CrashpadClient::StartHandler(
536550
attachments,
537551
crash_reporter,
538552
crash_envelope,
553+
report_id,
539554
restartable && (__MAC_OS_X_VERSION_MIN_REQUIRED >= __MAC_10_10 ||
540555
MacOSVersionNumber() >= 10'10'00)));
541556
if (!exception_port.is_valid()) {

0 commit comments

Comments
 (0)