From e09f5ee48448154a5543355365c5e962908d5d0a Mon Sep 17 00:00:00 2001 From: Justin Cohen Date: Wed, 12 Mar 2025 15:47:55 -0400 Subject: [PATCH] ios: Support UserStreamDataSources on iOS. Adds a parameter to the iOS ProcessIntermediateDumps API to allow for post-crash user stream processing. Also moves user_stream_data_source.h to handler:common to avoid a dependency cycle on iOS. This will be used by gwp-asan. Change-Id: Ic528725276e3c4d284aef89a86cc86878a7af9b0 Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/6340388 Reviewed-by: Joshua Peraza Commit-Queue: Justin Cohen --- client/crashpad_client.h | 8 +++++- client/crashpad_client_ios.cc | 11 +++++--- client/ios_handler/in_process_handler.cc | 15 +++++++---- client/ios_handler/in_process_handler.h | 27 ++++++++++++++++--- client/ios_handler/in_process_handler_test.cc | 12 ++++----- handler/BUILD.gn | 5 ++-- 6 files changed, 57 insertions(+), 21 deletions(-) diff --git a/client/crashpad_client.h b/client/crashpad_client.h index 41f03211..b089892b 100644 --- a/client/crashpad_client.h +++ b/client/crashpad_client.h @@ -43,6 +43,7 @@ #if BUILDFLAG(IS_IOS) #include "client/upload_behavior_ios.h" +#include "handler/user_stream_data_source.h" // nogncheck #endif namespace crashpad { @@ -531,8 +532,13 @@ class CrashpadClient { //! \param[in] annotations Process annotations to set in each crash report. //! Useful when adding crash annotations detected on the next run after a //! crash but before upload. + //! \param[in] user_stream_sources An optional vector containing the + //! extensibility data sources to call on crash. Each time a minidump is + //! created, the sources are called in turn. Any streams returned are + //! added to the minidump. static void ProcessIntermediateDumps( - const std::map& annotations = {}); + const std::map& annotations = {}, + const UserStreamDataSources* user_stream_sources = {}); //! \brief Requests that the handler convert a single intermediate dump at \a //! file generated by DumpWithoutCrashAndDeferProcessingAtPath into a diff --git a/client/crashpad_client_ios.cc b/client/crashpad_client_ios.cc index 663a17c4..7eaa9982 100644 --- a/client/crashpad_client_ios.cc +++ b/client/crashpad_client_ios.cc @@ -153,8 +153,10 @@ class CrashHandler : public Thread, } void ProcessIntermediateDumps( - const std::map& annotations) { - in_process_handler_.ProcessIntermediateDumps(annotations); + const std::map& annotations, + const UserStreamDataSources* user_stream_sources) { + in_process_handler_.ProcessIntermediateDumps(annotations, + user_stream_sources); } void ProcessIntermediateDump( @@ -457,10 +459,11 @@ bool CrashpadClient::StartCrashpadInProcessHandler( // static void CrashpadClient::ProcessIntermediateDumps( - const std::map& annotations) { + const std::map& annotations, + const UserStreamDataSources* user_stream_sources) { CrashHandler* crash_handler = CrashHandler::Get(); DCHECK(crash_handler); - crash_handler->ProcessIntermediateDumps(annotations); + crash_handler->ProcessIntermediateDumps(annotations, user_stream_sources); } // static diff --git a/client/ios_handler/in_process_handler.cc b/client/ios_handler/in_process_handler.cc index 90fec769..1fd8161b 100644 --- a/client/ios_handler/in_process_handler.cc +++ b/client/ios_handler/in_process_handler.cc @@ -254,21 +254,23 @@ bool InProcessHandler::MoveIntermediateDumpAtPathToPending( return MoveFileOrDirectory(path, new_path_unlocked); } void InProcessHandler::ProcessIntermediateDumps( - const std::map& annotations) { + const std::map& annotations, + const UserStreamDataSources* user_stream_sources) { INITIALIZATION_STATE_DCHECK_VALID(initialized_); for (auto& file : PendingFiles()) - ProcessIntermediateDump(file, annotations); + ProcessIntermediateDump(file, annotations, user_stream_sources); } void InProcessHandler::ProcessIntermediateDump( const base::FilePath& file, - const std::map& annotations) { + const std::map& annotations, + const UserStreamDataSources* user_stream_sources) { INITIALIZATION_STATE_DCHECK_VALID(initialized_); ProcessSnapshotIOSIntermediateDump process_snapshot; if (process_snapshot.InitializeWithFilePath(file, annotations)) { - SaveSnapshot(process_snapshot); + SaveSnapshot(process_snapshot, user_stream_sources); } } @@ -320,7 +322,8 @@ void InProcessHandler::UpdatePruneAndUploadThreads( } void InProcessHandler::SaveSnapshot( - ProcessSnapshotIOSIntermediateDump& process_snapshot) { + ProcessSnapshotIOSIntermediateDump& process_snapshot, + const UserStreamDataSources* user_stream_sources) { std::unique_ptr new_report; CrashReportDatabase::OperationStatus database_status = database_->PrepareNewCrashReport(&new_report); @@ -339,6 +342,8 @@ void InProcessHandler::SaveSnapshot( MinidumpFileWriter minidump; minidump.InitializeFromSnapshot(&process_snapshot); + AddUserExtensionStreams(user_stream_sources, &process_snapshot, &minidump); + if (!minidump.WriteEverything(new_report->Writer())) { Metrics::ExceptionCaptureResult( Metrics::CaptureResult::kMinidumpWriteFailed); diff --git a/client/ios_handler/in_process_handler.h b/client/ios_handler/in_process_handler.h index 13c18cb8..3b694a5b 100644 --- a/client/ios_handler/in_process_handler.h +++ b/client/ios_handler/in_process_handler.h @@ -12,6 +12,9 @@ // See the License for the specific language governing permissions and // limitations under the License. +#ifndef CRASHPAD_CLIENT_IOS_HANDLER_IN_PROCESS_IN_PROCESS_HANDLER_H_ +#define CRASHPAD_CLIENT_IOS_HANDLER_IN_PROCESS_IN_PROCESS_HANDLER_H_ + #include #include @@ -26,6 +29,7 @@ #include "client/ios_handler/prune_intermediate_dumps_and_crash_reports_thread.h" #include "client/upload_behavior_ios.h" #include "handler/crash_report_upload_thread.h" +#include "handler/user_stream_data_source.h" #include "snapshot/ios/process_snapshot_ios_intermediate_dump.h" #include "util/ios/ios_intermediate_dump_writer.h" #include "util/ios/ios_system_data_collector.h" @@ -159,17 +163,27 @@ class InProcessHandler { //! minidumps and trigger an upload if possible. //! //! \param[in] annotations Process annotations to set in each crash report. + //! \param[in] user_stream_sources An optional vector containing the + //! extensibility data sources to call on crash. Each time a minidump is + //! created, the sources are called in turn. Any streams returned are + //! added to the minidump. void ProcessIntermediateDumps( - const std::map& annotations); + const std::map& annotations, + const UserStreamDataSources* user_stream_sources); //! \brief Requests that the handler convert a specific intermediate dump into //! a minidump and trigger an upload if possible. //! //! \param[in] path Path to the specific intermediate dump. //! \param[in] annotations Process annotations to set in each crash report. + //! \param[in] user_stream_sources An optional vector containing the + //! extensibility data sources to call on crash. Each time a minidump is + //! created, the sources are called in turn. Any streams returned are + //! added to the minidump. void ProcessIntermediateDump( const base::FilePath& path, - const std::map& annotations = {}); + const std::map& annotations = {}, + const UserStreamDataSources* user_stream_sources = {}); //! \brief Requests that the handler begin in-process uploading of any //! pending reports. @@ -239,7 +253,12 @@ class InProcessHandler { //! \brief Writes a minidump to the Crashpad database from the //! \a process_snapshot, and triggers the upload_thread_ if started. - void SaveSnapshot(ProcessSnapshotIOSIntermediateDump& process_snapshot); + //! \param[in] user_stream_sources An optional vector containing the + //! extensibility data sources to call on crash. Each time a minidump is + //! created, the sources are called in turn. Any streams returned are + //! added to the minidump. + void SaveSnapshot(ProcessSnapshotIOSIntermediateDump& process_snapshot, + const UserStreamDataSources* user_stream_sources = {}); //! \brief Process a maximum of 20 pending intermediate dumps. Dumps named //! with our bundle id get first priority to prevent spamming. @@ -284,3 +303,5 @@ class InProcessHandler { } // namespace internal } // namespace crashpad + +#endif // CRASHPAD_CLIENT_IOS_HANDLER_IN_PROCESS_IN_PROCESS_HANDLER_H_ diff --git a/client/ios_handler/in_process_handler_test.cc b/client/ios_handler/in_process_handler_test.cc index 7d69d34f..cd6eaaee 100644 --- a/client/ios_handler/in_process_handler_test.cc +++ b/client/ios_handler/in_process_handler_test.cc @@ -110,35 +110,35 @@ TEST_F(InProcessHandlerTest, TestPendingFileLimit) { // Only process other app files. CreateFiles(0, 20); - handler().ProcessIntermediateDumps({}); + handler().ProcessIntermediateDumps({}, {}); VerifyRemainingFileCount(0, 0); ClearFiles(); // Only process our app files. CreateFiles(20, 20); - handler().ProcessIntermediateDumps({}); + handler().ProcessIntermediateDumps({}, {}); VerifyRemainingFileCount(0, 20); ClearFiles(); // Process all of our files and 10 remaining. CreateFiles(10, 30); - handler().ProcessIntermediateDumps({}); + handler().ProcessIntermediateDumps({}, {}); VerifyRemainingFileCount(0, 20); ClearFiles(); // Process 20 our files, leaving 10 remaining, and all other files remaining. CreateFiles(30, 10); - handler().ProcessIntermediateDumps({}); + handler().ProcessIntermediateDumps({}, {}); VerifyRemainingFileCount(10, 10); ClearFiles(); CreateFiles(0, 0); - handler().ProcessIntermediateDumps({}); + handler().ProcessIntermediateDumps({}, {}); VerifyRemainingFileCount(0, 0); ClearFiles(); CreateFiles(10, 0); - handler().ProcessIntermediateDumps({}); + handler().ProcessIntermediateDumps({}, {}); VerifyRemainingFileCount(0, 0); ClearFiles(); } diff --git a/handler/BUILD.gn b/handler/BUILD.gn index 368fef05..99f47015 100644 --- a/handler/BUILD.gn +++ b/handler/BUILD.gn @@ -20,8 +20,6 @@ static_library("handler") { "handler_main.h", "prune_crash_reports_thread.cc", "prune_crash_reports_thread.h", - "user_stream_data_source.cc", - "user_stream_data_source.h", ] if (crashpad_is_mac) { @@ -98,6 +96,8 @@ static_library("common") { "crash_report_upload_thread.h", "minidump_to_upload_parameters.cc", "minidump_to_upload_parameters.h", + "user_stream_data_source.cc", + "user_stream_data_source.h", ] if (crashpad_is_apple) { sources += [ @@ -112,6 +112,7 @@ static_library("common") { ] deps = [ "../client:common", + "../minidump", "../snapshot", "../util", "../util:net",