2018-01-10 11:23:56 -08:00
|
|
|
// Copyright 2018 The Crashpad Authors. All rights reserved.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
2018-02-20 16:11:41 -08:00
|
|
|
#include "snapshot/elf/module_snapshot_elf.h"
|
2018-01-10 11:23:56 -08:00
|
|
|
|
|
|
|
#include <algorithm>
|
|
|
|
|
|
|
|
#include "base/files/file_path.h"
|
|
|
|
#include "snapshot/crashpad_types/image_annotation_reader.h"
|
2018-02-15 10:38:36 -08:00
|
|
|
#include "util/misc/elf_note_types.h"
|
2018-01-10 11:23:56 -08:00
|
|
|
|
|
|
|
namespace crashpad {
|
|
|
|
namespace internal {
|
|
|
|
|
2018-02-20 16:11:41 -08:00
|
|
|
ModuleSnapshotElf::ModuleSnapshotElf(const std::string& name,
|
|
|
|
ElfImageReader* elf_reader,
|
|
|
|
ModuleSnapshot::ModuleType type)
|
2018-01-10 11:23:56 -08:00
|
|
|
: ModuleSnapshot(),
|
2018-02-20 16:11:41 -08:00
|
|
|
name_(name),
|
|
|
|
elf_reader_(elf_reader),
|
2018-01-10 11:23:56 -08:00
|
|
|
crashpad_info_(),
|
2018-02-20 16:11:41 -08:00
|
|
|
type_(type),
|
2018-01-10 11:23:56 -08:00
|
|
|
initialized_() {}
|
|
|
|
|
2018-02-20 16:11:41 -08:00
|
|
|
ModuleSnapshotElf::~ModuleSnapshotElf() = default;
|
2018-01-10 11:23:56 -08:00
|
|
|
|
2018-02-20 16:11:41 -08:00
|
|
|
bool ModuleSnapshotElf::Initialize() {
|
2018-01-10 11:23:56 -08:00
|
|
|
INITIALIZATION_STATE_SET_INITIALIZING(initialized_);
|
|
|
|
|
2018-02-20 16:11:41 -08:00
|
|
|
if (!elf_reader_) {
|
2018-01-10 11:23:56 -08:00
|
|
|
LOG(ERROR) << "no elf reader";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-02-15 10:38:36 -08:00
|
|
|
// The data payload is only sizeof(VMAddress) in the note, but add a bit to
|
|
|
|
// account for the name, header, and padding.
|
|
|
|
constexpr ssize_t kMaxNoteSize = 256;
|
|
|
|
std::unique_ptr<ElfImageReader::NoteReader> notes =
|
|
|
|
elf_reader_->NotesWithNameAndType(CRASHPAD_ELF_NOTE_NAME,
|
|
|
|
CRASHPAD_ELF_NOTE_TYPE_CRASHPAD_INFO,
|
|
|
|
kMaxNoteSize);
|
|
|
|
std::string desc;
|
2018-01-10 11:23:56 -08:00
|
|
|
VMAddress info_address;
|
2018-02-15 10:38:36 -08:00
|
|
|
if (notes->NextNote(nullptr, nullptr, &desc) ==
|
|
|
|
ElfImageReader::NoteReader::Result::kSuccess) {
|
|
|
|
info_address = *reinterpret_cast<VMAddress*>(&desc[0]);
|
|
|
|
|
2018-02-15 11:45:36 -08:00
|
|
|
ProcessMemoryRange range;
|
|
|
|
if (range.Initialize(*elf_reader_->Memory())) {
|
|
|
|
auto info = std::make_unique<CrashpadInfoReader>();
|
|
|
|
if (info->Initialize(&range, info_address)) {
|
|
|
|
crashpad_info_ = std::move(info);
|
|
|
|
}
|
2018-01-10 11:23:56 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
INITIALIZATION_STATE_SET_VALID(initialized_);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-02-20 16:11:41 -08:00
|
|
|
bool ModuleSnapshotElf::GetCrashpadOptions(CrashpadInfoClientOptions* options) {
|
2018-01-10 11:23:56 -08:00
|
|
|
INITIALIZATION_STATE_DCHECK_VALID(initialized_);
|
|
|
|
|
|
|
|
if (!crashpad_info_) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
options->crashpad_handler_behavior =
|
|
|
|
crashpad_info_->CrashpadHandlerBehavior();
|
|
|
|
options->system_crash_reporter_forwarding =
|
|
|
|
crashpad_info_->SystemCrashReporterForwarding();
|
|
|
|
options->gather_indirectly_referenced_memory =
|
|
|
|
crashpad_info_->GatherIndirectlyReferencedMemory();
|
|
|
|
options->indirectly_referenced_memory_cap =
|
|
|
|
crashpad_info_->IndirectlyReferencedMemoryCap();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-02-20 16:11:41 -08:00
|
|
|
std::string ModuleSnapshotElf::Name() const {
|
2018-01-10 11:23:56 -08:00
|
|
|
INITIALIZATION_STATE_DCHECK_VALID(initialized_);
|
|
|
|
return name_;
|
|
|
|
}
|
|
|
|
|
2018-02-20 16:11:41 -08:00
|
|
|
uint64_t ModuleSnapshotElf::Address() const {
|
2018-01-10 11:23:56 -08:00
|
|
|
INITIALIZATION_STATE_DCHECK_VALID(initialized_);
|
|
|
|
return elf_reader_->Address();
|
|
|
|
}
|
|
|
|
|
2018-02-20 16:11:41 -08:00
|
|
|
uint64_t ModuleSnapshotElf::Size() const {
|
2018-01-10 11:23:56 -08:00
|
|
|
INITIALIZATION_STATE_DCHECK_VALID(initialized_);
|
|
|
|
return elf_reader_->Size();
|
|
|
|
}
|
|
|
|
|
2018-02-20 16:11:41 -08:00
|
|
|
time_t ModuleSnapshotElf::Timestamp() const {
|
2018-01-10 11:23:56 -08:00
|
|
|
INITIALIZATION_STATE_DCHECK_VALID(initialized_);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-02-20 16:11:41 -08:00
|
|
|
void ModuleSnapshotElf::FileVersion(uint16_t* version_0,
|
|
|
|
uint16_t* version_1,
|
|
|
|
uint16_t* version_2,
|
|
|
|
uint16_t* version_3) const {
|
2018-01-10 11:23:56 -08:00
|
|
|
INITIALIZATION_STATE_DCHECK_VALID(initialized_);
|
|
|
|
*version_0 = 0;
|
|
|
|
*version_1 = 0;
|
|
|
|
*version_2 = 0;
|
|
|
|
*version_3 = 0;
|
|
|
|
}
|
|
|
|
|
2018-02-20 16:11:41 -08:00
|
|
|
void ModuleSnapshotElf::SourceVersion(uint16_t* version_0,
|
|
|
|
uint16_t* version_1,
|
|
|
|
uint16_t* version_2,
|
|
|
|
uint16_t* version_3) const {
|
2018-01-10 11:23:56 -08:00
|
|
|
INITIALIZATION_STATE_DCHECK_VALID(initialized_);
|
|
|
|
*version_0 = 0;
|
|
|
|
*version_1 = 0;
|
|
|
|
*version_2 = 0;
|
|
|
|
*version_3 = 0;
|
|
|
|
}
|
|
|
|
|
2018-02-20 16:11:41 -08:00
|
|
|
ModuleSnapshot::ModuleType ModuleSnapshotElf::GetModuleType() const {
|
2018-01-10 11:23:56 -08:00
|
|
|
INITIALIZATION_STATE_DCHECK_VALID(initialized_);
|
|
|
|
return type_;
|
|
|
|
}
|
|
|
|
|
2018-02-20 16:11:41 -08:00
|
|
|
void ModuleSnapshotElf::UUIDAndAge(crashpad::UUID* uuid, uint32_t* age) const {
|
2018-01-10 11:23:56 -08:00
|
|
|
INITIALIZATION_STATE_DCHECK_VALID(initialized_);
|
|
|
|
*age = 0;
|
|
|
|
|
|
|
|
std::unique_ptr<ElfImageReader::NoteReader> notes =
|
|
|
|
elf_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]));
|
|
|
|
}
|
|
|
|
|
2018-02-20 16:11:41 -08:00
|
|
|
std::string ModuleSnapshotElf::DebugFileName() const {
|
2018-01-10 11:23:56 -08:00
|
|
|
INITIALIZATION_STATE_DCHECK_VALID(initialized_);
|
|
|
|
return base::FilePath(Name()).BaseName().value();
|
|
|
|
}
|
|
|
|
|
2018-02-20 16:11:41 -08:00
|
|
|
std::vector<std::string> ModuleSnapshotElf::AnnotationsVector() const {
|
2018-01-10 11:23:56 -08:00
|
|
|
INITIALIZATION_STATE_DCHECK_VALID(initialized_);
|
|
|
|
return std::vector<std::string>();
|
|
|
|
}
|
|
|
|
|
2018-02-20 16:11:41 -08:00
|
|
|
std::map<std::string, std::string> ModuleSnapshotElf::AnnotationsSimpleMap()
|
2018-01-10 11:23:56 -08:00
|
|
|
const {
|
|
|
|
INITIALIZATION_STATE_DCHECK_VALID(initialized_);
|
|
|
|
std::map<std::string, std::string> annotations;
|
|
|
|
if (crashpad_info_ && crashpad_info_->SimpleAnnotations()) {
|
|
|
|
ImageAnnotationReader reader(elf_reader_->Memory());
|
|
|
|
reader.SimpleMap(crashpad_info_->SimpleAnnotations(), &annotations);
|
|
|
|
}
|
|
|
|
return annotations;
|
|
|
|
}
|
|
|
|
|
2018-02-20 16:11:41 -08:00
|
|
|
std::vector<AnnotationSnapshot> ModuleSnapshotElf::AnnotationObjects() const {
|
2018-01-10 11:23:56 -08:00
|
|
|
INITIALIZATION_STATE_DCHECK_VALID(initialized_);
|
|
|
|
std::vector<AnnotationSnapshot> annotations;
|
|
|
|
if (crashpad_info_ && crashpad_info_->AnnotationsList()) {
|
|
|
|
ImageAnnotationReader reader(elf_reader_->Memory());
|
|
|
|
reader.AnnotationsList(crashpad_info_->AnnotationsList(), &annotations);
|
|
|
|
}
|
|
|
|
return annotations;
|
|
|
|
}
|
|
|
|
|
2018-02-20 16:11:41 -08:00
|
|
|
std::set<CheckedRange<uint64_t>> ModuleSnapshotElf::ExtraMemoryRanges() const {
|
2018-01-10 11:23:56 -08:00
|
|
|
INITIALIZATION_STATE_DCHECK_VALID(initialized_);
|
|
|
|
return std::set<CheckedRange<uint64_t>>();
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<const UserMinidumpStream*>
|
2018-02-20 16:11:41 -08:00
|
|
|
ModuleSnapshotElf::CustomMinidumpStreams() const {
|
2018-01-10 11:23:56 -08:00
|
|
|
return std::vector<const UserMinidumpStream*>();
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace internal
|
|
|
|
} // namespace crashpad
|