From cab259330f2e73c4862d9d71eae70bcfcd44faa6 Mon Sep 17 00:00:00 2001 From: Scott Graham Date: Tue, 20 Feb 2018 16:10:33 -0800 Subject: [PATCH] fuchsia: Pass more data out of module snapshot After https://chromium-review.googlesource.com/c/crashpad/crashpad/+/927355 image annotations can be read. Plumb those through ModuleSnapshotFuchsia. Bug: crashpad:196 Change-Id: Iba0730fd88c60cbad8a721ddcaf8f60860f76b77 Reviewed-on: https://chromium-review.googlesource.com/927704 Reviewed-by: Mark Mentovai Commit-Queue: Scott Graham --- snapshot/fuchsia/module_snapshot_fuchsia.cc | 35 ++++++++++++++------ snapshot/fuchsia/module_snapshot_fuchsia.h | 7 ++-- snapshot/fuchsia/process_reader.cc | 9 ++++- snapshot/fuchsia/process_reader.h | 4 +++ snapshot/fuchsia/process_snapshot_fuchsia.cc | 2 +- 5 files changed, 40 insertions(+), 17 deletions(-) diff --git a/snapshot/fuchsia/module_snapshot_fuchsia.cc b/snapshot/fuchsia/module_snapshot_fuchsia.cc index 6d57bf7f..6a90edd0 100644 --- a/snapshot/fuchsia/module_snapshot_fuchsia.cc +++ b/snapshot/fuchsia/module_snapshot_fuchsia.cc @@ -14,8 +14,9 @@ #include "snapshot/fuchsia/module_snapshot_fuchsia.h" +#include + #include "base/logging.h" -#include "client/crashpad_info.h" #include "snapshot/crashpad_types/image_annotation_reader.h" #include "util/misc/elf_note_types.h" @@ -27,13 +28,12 @@ ModuleSnapshotFuchsia::ModuleSnapshotFuchsia() = default; ModuleSnapshotFuchsia::~ModuleSnapshotFuchsia() = default; bool ModuleSnapshotFuchsia::Initialize( - ProcessReader* process_reader, const ProcessReader::Module& process_reader_module) { INITIALIZATION_STATE_SET_INITIALIZING(initialized_); - process_reader_ = process_reader; name_ = process_reader_module.name; elf_image_reader_ = process_reader_module.reader; + type_ = process_reader_module.type; if (!elf_image_reader_) { return false; } @@ -128,14 +128,21 @@ void ModuleSnapshotFuchsia::SourceVersion(uint16_t* version_0, ModuleSnapshot::ModuleType ModuleSnapshotFuchsia::GetModuleType() const { INITIALIZATION_STATE_DCHECK_VALID(initialized_); - NOTREACHED(); // TODO(scottmg): https://crashpad.chromium.org/bug/196 - return kModuleTypeUnknown; + return type_; } void ModuleSnapshotFuchsia::UUIDAndAge(crashpad::UUID* uuid, uint32_t* age) const { INITIALIZATION_STATE_DCHECK_VALID(initialized_); - NOTREACHED(); // TODO(scottmg): https://crashpad.chromium.org/bug/196 + *age = 0; + + std::unique_ptr notes = + elf_image_reader_->NotesWithNameAndType( + ELF_NOTE_GNU, NT_GNU_BUILD_ID, 64); + std::string desc; + notes->NextNote(nullptr, nullptr, &desc); + desc.insert(desc.end(), 16 - std::min(desc.size(), size_t{16}), '\0'); + uuid->InitializeFromBytes(reinterpret_cast(&desc[0])); } std::string ModuleSnapshotFuchsia::DebugFileName() const { @@ -153,15 +160,23 @@ std::vector ModuleSnapshotFuchsia::AnnotationsVector() const { std::map ModuleSnapshotFuchsia::AnnotationsSimpleMap() const { INITIALIZATION_STATE_DCHECK_VALID(initialized_); - NOTREACHED(); // TODO(scottmg): https://crashpad.chromium.org/bug/196 - return std::map(); + std::map annotations; + if (crashpad_info_ && crashpad_info_->SimpleAnnotations()) { + ImageAnnotationReader reader(elf_image_reader_->Memory()); + reader.SimpleMap(crashpad_info_->SimpleAnnotations(), &annotations); + } + return annotations; } std::vector ModuleSnapshotFuchsia::AnnotationObjects() const { INITIALIZATION_STATE_DCHECK_VALID(initialized_); - NOTREACHED(); // TODO(scottmg): https://crashpad.chromium.org/bug/196 - return std::vector(); + std::vector annotations; + if (crashpad_info_ && crashpad_info_->AnnotationsList()) { + ImageAnnotationReader reader(elf_image_reader_->Memory()); + reader.AnnotationsList(crashpad_info_->AnnotationsList(), &annotations); + } + return annotations; } std::set> ModuleSnapshotFuchsia::ExtraMemoryRanges() diff --git a/snapshot/fuchsia/module_snapshot_fuchsia.h b/snapshot/fuchsia/module_snapshot_fuchsia.h index b7831441..6d66fd23 100644 --- a/snapshot/fuchsia/module_snapshot_fuchsia.h +++ b/snapshot/fuchsia/module_snapshot_fuchsia.h @@ -44,15 +44,12 @@ class ModuleSnapshotFuchsia final : public ModuleSnapshot { //! \brief Initializes the object. //! - //! \param[in] process_reader A ProcessReader for the process containing the - //! module. //! \param[in] process_reader_module The module within the ProcessReader for //! which the snapshot should be created. //! //! \return `true` if the snapshot could be created, `false` otherwise with //! an appropriate message logged. - bool Initialize(ProcessReader* process_reader, - const ProcessReader::Module& process_reader_module); + bool Initialize(const ProcessReader::Module& process_reader_module); //! \brief Returns options from the module’s CrashpadInfo structure. //! @@ -87,8 +84,8 @@ class ModuleSnapshotFuchsia final : public ModuleSnapshot { private: std::string name_; ElfImageReader* elf_image_reader_; // weak - ProcessReader* process_reader_; // weak std::unique_ptr crashpad_info_; + ModuleType type_; InitializationStateDcheck initialized_; DISALLOW_COPY_AND_ASSIGN(ModuleSnapshotFuchsia); diff --git a/snapshot/fuchsia/process_reader.cc b/snapshot/fuchsia/process_reader.cc index df19667d..ffd81635 100644 --- a/snapshot/fuchsia/process_reader.cc +++ b/snapshot/fuchsia/process_reader.cc @@ -137,7 +137,14 @@ void ProcessReader::InitializeModules() { } Module module; - module.name = dsoname.empty() ? app_name : dsoname; + if (dsoname.empty()) { + module.name = app_name; + module.type = ModuleSnapshot::kModuleTypeExecutable; + } else { + module.name = dsoname; + // TODO(scottmg): Handle kModuleTypeDynamicLoader. + module.type = ModuleSnapshot::kModuleTypeSharedLibrary; + } std::unique_ptr reader(new ElfImageReader()); diff --git a/snapshot/fuchsia/process_reader.h b/snapshot/fuchsia/process_reader.h index 332afc37..b3b24e36 100644 --- a/snapshot/fuchsia/process_reader.h +++ b/snapshot/fuchsia/process_reader.h @@ -21,6 +21,7 @@ #include "base/macros.h" #include "build/build_config.h" #include "snapshot/elf/elf_image_reader.h" +#include "snapshot/module_snapshot.h" #include "util/misc/initialization_state_dcheck.h" #include "util/process/process_memory_fuchsia.h" #include "util/process/process_memory_range.h" @@ -48,6 +49,9 @@ class ProcessReader { //! This field may be `nullptr` if a reader could not be created for the //! module. ElfImageReader* reader; + + //! \brief The module's type. + ModuleSnapshot::ModuleType type = ModuleSnapshot::kModuleTypeUnknown; }; ProcessReader(); diff --git a/snapshot/fuchsia/process_snapshot_fuchsia.cc b/snapshot/fuchsia/process_snapshot_fuchsia.cc index 1505f1b2..02f8285d 100644 --- a/snapshot/fuchsia/process_snapshot_fuchsia.cc +++ b/snapshot/fuchsia/process_snapshot_fuchsia.cc @@ -173,7 +173,7 @@ void ProcessSnapshotFuchsia::InitializeModules() { for (const ProcessReader::Module& process_reader_module : process_reader_modules) { auto module = std::make_unique(); - if (module->Initialize(&process_reader_, process_reader_module)) { + if (module->Initialize(process_reader_module)) { modules_.push_back(std::move(module)); } }