From b4095401639ebe2ad33169e5c1d994065cbff1b8 Mon Sep 17 00:00:00 2001 From: Mark Mentovai Date: Tue, 4 Apr 2017 16:12:12 -0400 Subject: [PATCH] handler: Reuse existing annotations SimpleStringDictionary if present Bug: crashpad:143 Change-Id: I75a77adacd83febb7c363598bbc6d19c184b773d Reviewed-on: https://chromium-review.googlesource.com/468167 Reviewed-by: Scott Graham --- client/crashpad_info.h | 9 +++++++++ handler/handler_main.cc | 13 +++++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/client/crashpad_info.h b/client/crashpad_info.h index 0462eaf9..77c9097a 100644 --- a/client/crashpad_info.h +++ b/client/crashpad_info.h @@ -96,10 +96,19 @@ struct CrashpadInfo { //! SimpleStringDictionary object. It is the caller’s responsibility to //! ensure that this pointer remains valid while it is in effect for a //! CrashpadInfo object. + //! + //! \sa simple_annotations() void set_simple_annotations(SimpleStringDictionary* simple_annotations) { simple_annotations_ = simple_annotations; } + //! \return The simple annotations dictionary. + //! + //! \sa set_simple_annotations() + SimpleStringDictionary* simple_annotations() const { + return simple_annotations_; + } + //! \brief Enables or disables Crashpad handler processing. //! //! When handling an exception, the Crashpad handler will scan all modules in diff --git a/handler/handler_main.cc b/handler/handler_main.cc index 1e681308..f58f1ba4 100644 --- a/handler/handler_main.cc +++ b/handler/handler_main.cc @@ -627,12 +627,21 @@ int HandlerMain(int argc, char* argv[]) { if (!options.monitor_self_annotations.empty()) { // Establish these annotations even if --monitor-self is not present, in // case something such as generate_dump wants to try to access them later. - SimpleStringDictionary* module_annotations = new SimpleStringDictionary(); + // + // If the handler is part of a multi-purpose executable, simple annotations + // may already be present for this module. If they are, use them. + CrashpadInfo* crashpad_info = CrashpadInfo::GetCrashpadInfo(); + SimpleStringDictionary* module_annotations = + crashpad_info->simple_annotations(); + if (!module_annotations) { + module_annotations = new SimpleStringDictionary(); + crashpad_info->set_simple_annotations(module_annotations); + } + for (const auto& iterator : options.monitor_self_annotations) { module_annotations->SetKeyValue(iterator.first.c_str(), iterator.second.c_str()); } - CrashpadInfo::GetCrashpadInfo()->set_simple_annotations(module_annotations); } #if defined(OS_MACOSX)