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 <mark@chromium.org>
Commit-Queue: Scott Graham <scottmg@chromium.org>
This commit is contained in:
Scott Graham 2018-02-20 16:10:33 -08:00 committed by Commit Bot
parent 3dd85dc126
commit cab259330f
5 changed files with 40 additions and 17 deletions

View File

@ -14,8 +14,9 @@
#include "snapshot/fuchsia/module_snapshot_fuchsia.h"
#include <algorithm>
#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<ElfImageReader::NoteReader> 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<const uint8_t*>(&desc[0]));
}
std::string ModuleSnapshotFuchsia::DebugFileName() const {
@ -153,15 +160,23 @@ std::vector<std::string> ModuleSnapshotFuchsia::AnnotationsVector() const {
std::map<std::string, std::string> ModuleSnapshotFuchsia::AnnotationsSimpleMap()
const {
INITIALIZATION_STATE_DCHECK_VALID(initialized_);
NOTREACHED(); // TODO(scottmg): https://crashpad.chromium.org/bug/196
return std::map<std::string, std::string>();
std::map<std::string, std::string> annotations;
if (crashpad_info_ && crashpad_info_->SimpleAnnotations()) {
ImageAnnotationReader reader(elf_image_reader_->Memory());
reader.SimpleMap(crashpad_info_->SimpleAnnotations(), &annotations);
}
return annotations;
}
std::vector<AnnotationSnapshot> ModuleSnapshotFuchsia::AnnotationObjects()
const {
INITIALIZATION_STATE_DCHECK_VALID(initialized_);
NOTREACHED(); // TODO(scottmg): https://crashpad.chromium.org/bug/196
return std::vector<AnnotationSnapshot>();
std::vector<AnnotationSnapshot> annotations;
if (crashpad_info_ && crashpad_info_->AnnotationsList()) {
ImageAnnotationReader reader(elf_image_reader_->Memory());
reader.AnnotationsList(crashpad_info_->AnnotationsList(), &annotations);
}
return annotations;
}
std::set<CheckedRange<uint64_t>> ModuleSnapshotFuchsia::ExtraMemoryRanges()

View File

@ -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 modules 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<CrashpadInfoReader> crashpad_info_;
ModuleType type_;
InitializationStateDcheck initialized_;
DISALLOW_COPY_AND_ASSIGN(ModuleSnapshotFuchsia);

View File

@ -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<ElfImageReader> reader(new ElfImageReader());

View File

@ -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();

View File

@ -173,7 +173,7 @@ void ProcessSnapshotFuchsia::InitializeModules() {
for (const ProcessReader::Module& process_reader_module :
process_reader_modules) {
auto module = std::make_unique<internal::ModuleSnapshotFuchsia>();
if (module->Initialize(&process_reader_, process_reader_module)) {
if (module->Initialize(process_reader_module)) {
modules_.push_back(std::move(module));
}
}