Skip to content

Commit b265391

Browse files
authored
feat: wait-for-upload Windows support (#126)
* feat: wait-for-upload windows support * update `mini_chromium` after merge to fork's `getsentry` branch
1 parent a17b30d commit b265391

File tree

7 files changed

+42
-11
lines changed

7 files changed

+42
-11
lines changed

client/crashpad_client_win.cc

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,7 @@ struct BackgroundHandlerStartThreadData {
356356
const std::vector<std::string>& arguments,
357357
const std::vector<base::FilePath>& attachments,
358358
const base::FilePath& screenshot,
359+
const bool wait_for_upload,
359360
const std::wstring& ipc_pipe,
360361
ScopedFileHANDLE ipc_pipe_handle)
361362
: handler(handler),
@@ -367,6 +368,7 @@ struct BackgroundHandlerStartThreadData {
367368
arguments(arguments),
368369
attachments(attachments),
369370
screenshot(screenshot),
371+
wait_for_upload(wait_for_upload),
370372
ipc_pipe(ipc_pipe),
371373
ipc_pipe_handle(std::move(ipc_pipe_handle)) {}
372374

@@ -379,6 +381,7 @@ struct BackgroundHandlerStartThreadData {
379381
std::vector<std::string> arguments;
380382
std::vector<base::FilePath> attachments;
381383
base::FilePath screenshot;
384+
bool wait_for_upload;
382385
std::wstring ipc_pipe;
383386
ScopedFileHANDLE ipc_pipe_handle;
384387
};
@@ -452,6 +455,10 @@ bool StartHandlerProcess(
452455
&command_line);
453456
}
454457

458+
if (data->wait_for_upload) {
459+
AppendCommandLineArgument(L"--wait-for-upload", &command_line);
460+
}
461+
455462
ScopedKernelHANDLE this_process(
456463
OpenProcess(kXPProcessLimitedAccess, true, GetCurrentProcessId()));
457464
if (!this_process.is_valid()) {
@@ -648,7 +655,6 @@ bool CrashpadClient::StartHandler(
648655
const std::vector<base::FilePath>& attachments,
649656
const base::FilePath& screenshot,
650657
bool wait_for_upload) {
651-
(void) wait_for_upload; // unused in win (for now)
652658
DCHECK(ipc_pipe_.empty());
653659

654660
// Both the pipe and the signalling events have to be created on the main
@@ -681,6 +687,7 @@ bool CrashpadClient::StartHandler(
681687
arguments,
682688
attachments,
683689
screenshot,
690+
wait_for_upload,
684691
ipc_pipe_,
685692
std::move(ipc_pipe_handle));
686693

handler/crash_report_upload_thread.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,11 @@ void CrashReportUploadThread::ReportPending(const UUID& report_uuid) {
116116
thread_.DoWorkNow();
117117
}
118118

119+
void CrashReportUploadThread::ReportPendingSync(const UUID& report_uuid) {
120+
known_pending_report_uuids_.PushBack(report_uuid);
121+
DoWork(nullptr);
122+
}
123+
119124
void CrashReportUploadThread::Start() {
120125
thread_.Start(
121126
options_.watch_pending_reports ? 0.0 : WorkerThread::kIndefiniteWait);

handler/crash_report_upload_thread.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,16 @@ class CrashReportUploadThread : public WorkerThread::Delegate,
104104
//! This method may be called from any thread.
105105
void ReportPending(const UUID& report_uuid);
106106

107+
//! \brief Runs the upload on the calling thread rather than in the upload
108+
//! thread. This is only used from the exception handler to block the
109+
//! termination of the crashed process until the upload is completed.
110+
//!
111+
//! \param[in] report_uuid The unique identifier of the newly added pending
112+
//! report.
113+
//!
114+
//! This method will run on the pool thread executing the OnCrashDumpEvent
115+
void ReportPendingSync(const UUID& report_uuid);
116+
107117
// Stoppable:
108118

109119
//! \brief Starts a dedicated upload thread, which executes ThreadMain().

handler/handler_main.cc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ struct Options {
269269
#if defined(SCREENSHOT_SUPPORTED)
270270
base::FilePath screenshot;
271271
#endif // SCREENSHOT_SUPPORTED
272-
#if BUILDFLAG(IS_LINUX)
272+
#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_WIN)
273273
bool wait_for_upload = false;
274274
#endif
275275
};
@@ -650,7 +650,7 @@ int HandlerMain(int argc,
650650
#if BUILDFLAG(IS_ANDROID)
651651
kOptionWriteMinidumpToLog,
652652
#endif // BUILDFLAG(IS_ANDROID)
653-
#if BUILDFLAG(IS_LINUX)
653+
#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_WIN)
654654
kOptionWaitForUpload,
655655
#endif
656656

@@ -747,8 +747,8 @@ int HandlerMain(int argc,
747747
#if BUILDFLAG(IS_ANDROID)
748748
{"write-minidump-to-log", no_argument, nullptr, kOptionWriteMinidumpToLog},
749749
#endif // BUILDFLAG(IS_ANDROID)
750-
#if BUILDFLAG(IS_LINUX)
751-
{"wait-for-upload", optional_argument, nullptr, kOptionWaitForUpload},
750+
#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_WIN)
751+
{"wait-for-upload", no_argument, nullptr, kOptionWaitForUpload},
752752
#endif
753753
{"help", no_argument, nullptr, kOptionHelp},
754754
{"version", no_argument, nullptr, kOptionVersion},
@@ -941,7 +941,7 @@ int HandlerMain(int argc,
941941
break;
942942
}
943943
#endif // BUILDFLAG(IS_ANDROID)
944-
#if BUILDFLAG(IS_LINUX)
944+
#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_WIN)
945945
case kOptionWaitForUpload : {
946946
options.wait_for_upload = true;
947947
break;
@@ -1136,7 +1136,7 @@ int HandlerMain(int argc,
11361136
false,
11371137
#endif // BUILDFLAG(IS_LINUX)
11381138
user_stream_sources
1139-
#if BUILDFLAG(IS_LINUX)
1139+
#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_WIN)
11401140
,options.wait_for_upload
11411141
#endif
11421142
);

handler/win/crash_report_exception_handler.cc

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,14 @@ CrashReportExceptionHandler::CrashReportExceptionHandler(
4040
const std::map<std::string, std::string>* process_annotations,
4141
const std::vector<base::FilePath>* attachments,
4242
const base::FilePath* screenshot,
43-
const UserStreamDataSources* user_stream_data_sources)
43+
const UserStreamDataSources* user_stream_data_sources,
44+
const bool wait_for_upload)
4445
: database_(database),
4546
upload_thread_(upload_thread),
4647
process_annotations_(process_annotations),
4748
attachments_(attachments),
4849
screenshot_(screenshot),
50+
wait_for_upload_(wait_for_upload),
4951
user_stream_data_sources_(user_stream_data_sources) {}
5052

5153
CrashReportExceptionHandler::~CrashReportExceptionHandler() {}
@@ -160,7 +162,12 @@ unsigned int CrashReportExceptionHandler::ExceptionHandlerServerException(
160162
}
161163

162164
if (upload_thread_) {
163-
upload_thread_->ReportPending(uuid);
165+
if (wait_for_upload_) {
166+
upload_thread_->ReportPendingSync(uuid);
167+
}
168+
else {
169+
upload_thread_->ReportPending(uuid);
170+
}
164171
}
165172
}
166173

handler/win/crash_report_exception_handler.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ class CrashReportExceptionHandler final
6161
const std::map<std::string, std::string>* process_annotations,
6262
const std::vector<base::FilePath>* attachments,
6363
const base::FilePath* screenshot,
64-
const UserStreamDataSources* user_stream_data_sources);
64+
const UserStreamDataSources* user_stream_data_sources,
65+
bool wait_for_upload);
6566

6667
CrashReportExceptionHandler(const CrashReportExceptionHandler&) = delete;
6768
CrashReportExceptionHandler& operator=(const CrashReportExceptionHandler&) =
@@ -85,6 +86,7 @@ class CrashReportExceptionHandler final
8586
const std::map<std::string, std::string>* process_annotations_; // weak
8687
const std::vector<base::FilePath>* attachments_; // weak
8788
const base::FilePath* screenshot_; // weak
89+
const bool wait_for_upload_;
8890
const UserStreamDataSources* user_stream_data_sources_; // weak
8991
};
9092

0 commit comments

Comments
 (0)