2014-10-24 22:44:55 +04:00
|
|
|
// Copyright 2014 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.
|
|
|
|
|
2014-10-24 22:58:53 +04:00
|
|
|
#include "minidump/minidump_module_crashpad_info_writer.h"
|
2014-10-24 22:44:55 +04:00
|
|
|
|
2015-12-10 01:36:32 +03:00
|
|
|
#include <utility>
|
|
|
|
|
2014-10-24 22:44:55 +04:00
|
|
|
#include "base/logging.h"
|
2017-11-02 00:06:18 +03:00
|
|
|
#include "minidump/minidump_annotation_writer.h"
|
2014-10-24 22:44:55 +04:00
|
|
|
#include "minidump/minidump_simple_string_dictionary_writer.h"
|
2014-10-29 00:00:46 +03:00
|
|
|
#include "snapshot/module_snapshot.h"
|
2014-10-24 22:44:55 +04:00
|
|
|
#include "util/file/file_writer.h"
|
|
|
|
#include "util/numeric/safe_assignment.h"
|
|
|
|
|
|
|
|
namespace crashpad {
|
|
|
|
|
|
|
|
MinidumpModuleCrashpadInfoWriter::MinidumpModuleCrashpadInfoWriter()
|
2014-11-07 18:01:17 +03:00
|
|
|
: MinidumpWritable(),
|
|
|
|
module_(),
|
|
|
|
list_annotations_(),
|
2017-11-02 00:06:18 +03:00
|
|
|
simple_annotations_(),
|
|
|
|
annotation_objects_() {
|
2014-10-24 22:44:55 +04:00
|
|
|
module_.version = MinidumpModuleCrashpadInfo::kVersion;
|
|
|
|
}
|
|
|
|
|
|
|
|
MinidumpModuleCrashpadInfoWriter::~MinidumpModuleCrashpadInfoWriter() {
|
|
|
|
}
|
|
|
|
|
2014-10-29 00:00:46 +03:00
|
|
|
void MinidumpModuleCrashpadInfoWriter::InitializeFromSnapshot(
|
2015-03-04 18:53:34 +03:00
|
|
|
const ModuleSnapshot* module_snapshot) {
|
2014-10-29 00:00:46 +03:00
|
|
|
DCHECK_EQ(state(), kStateMutable);
|
2014-11-07 18:01:17 +03:00
|
|
|
DCHECK(!list_annotations_);
|
2014-10-29 00:00:46 +03:00
|
|
|
DCHECK(!simple_annotations_);
|
|
|
|
|
2017-10-12 19:42:28 +03:00
|
|
|
auto list_annotations = std::make_unique<MinidumpUTF8StringListWriter>();
|
2014-11-07 18:01:17 +03:00
|
|
|
list_annotations->InitializeFromVector(module_snapshot->AnnotationsVector());
|
|
|
|
if (list_annotations->IsUseful()) {
|
2015-12-10 01:36:32 +03:00
|
|
|
SetListAnnotations(std::move(list_annotations));
|
2014-11-07 18:01:17 +03:00
|
|
|
}
|
|
|
|
|
2014-10-29 00:00:46 +03:00
|
|
|
auto simple_annotations =
|
2017-10-12 19:42:28 +03:00
|
|
|
std::make_unique<MinidumpSimpleStringDictionaryWriter>();
|
2014-10-29 00:00:46 +03:00
|
|
|
simple_annotations->InitializeFromMap(
|
|
|
|
module_snapshot->AnnotationsSimpleMap());
|
|
|
|
if (simple_annotations->IsUseful()) {
|
2015-12-10 01:36:32 +03:00
|
|
|
SetSimpleAnnotations(std::move(simple_annotations));
|
2014-10-29 00:00:46 +03:00
|
|
|
}
|
2017-11-02 00:06:18 +03:00
|
|
|
|
|
|
|
auto annotation_objects = std::make_unique<MinidumpAnnotationListWriter>();
|
|
|
|
annotation_objects->InitializeFromList(module_snapshot->AnnotationObjects());
|
|
|
|
if (annotation_objects->IsUseful()) {
|
|
|
|
SetAnnotationObjects(std::move(annotation_objects));
|
|
|
|
}
|
2014-10-29 00:00:46 +03:00
|
|
|
}
|
|
|
|
|
2014-11-07 18:01:17 +03:00
|
|
|
void MinidumpModuleCrashpadInfoWriter::SetListAnnotations(
|
2016-04-25 22:13:07 +03:00
|
|
|
std::unique_ptr<MinidumpUTF8StringListWriter> list_annotations) {
|
2014-11-07 18:01:17 +03:00
|
|
|
DCHECK_EQ(state(), kStateMutable);
|
|
|
|
|
2015-12-10 01:36:32 +03:00
|
|
|
list_annotations_ = std::move(list_annotations);
|
2014-11-07 18:01:17 +03:00
|
|
|
}
|
|
|
|
|
2014-10-24 22:44:55 +04:00
|
|
|
void MinidumpModuleCrashpadInfoWriter::SetSimpleAnnotations(
|
2016-04-25 22:13:07 +03:00
|
|
|
std::unique_ptr<MinidumpSimpleStringDictionaryWriter> simple_annotations) {
|
2014-10-24 22:44:55 +04:00
|
|
|
DCHECK_EQ(state(), kStateMutable);
|
|
|
|
|
2015-12-10 01:36:32 +03:00
|
|
|
simple_annotations_ = std::move(simple_annotations);
|
2014-10-24 22:44:55 +04:00
|
|
|
}
|
|
|
|
|
2017-11-02 00:06:18 +03:00
|
|
|
void MinidumpModuleCrashpadInfoWriter::SetAnnotationObjects(
|
|
|
|
std::unique_ptr<MinidumpAnnotationListWriter> annotation_objects) {
|
|
|
|
DCHECK_EQ(state(), kStateMutable);
|
|
|
|
|
|
|
|
annotation_objects_ = std::move(annotation_objects);
|
|
|
|
}
|
|
|
|
|
2014-10-29 00:00:46 +03:00
|
|
|
bool MinidumpModuleCrashpadInfoWriter::IsUseful() const {
|
2017-11-02 00:06:18 +03:00
|
|
|
return list_annotations_ || simple_annotations_ || annotation_objects_;
|
2014-10-29 00:00:46 +03:00
|
|
|
}
|
|
|
|
|
2014-10-24 22:44:55 +04:00
|
|
|
bool MinidumpModuleCrashpadInfoWriter::Freeze() {
|
|
|
|
DCHECK_EQ(state(), kStateMutable);
|
|
|
|
|
|
|
|
if (!MinidumpWritable::Freeze()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-11-07 18:01:17 +03:00
|
|
|
if (list_annotations_) {
|
|
|
|
list_annotations_->RegisterLocationDescriptor(&module_.list_annotations);
|
|
|
|
}
|
|
|
|
|
2014-10-24 22:44:55 +04:00
|
|
|
if (simple_annotations_) {
|
|
|
|
simple_annotations_->RegisterLocationDescriptor(
|
|
|
|
&module_.simple_annotations);
|
|
|
|
}
|
|
|
|
|
2017-11-02 00:06:18 +03:00
|
|
|
if (annotation_objects_) {
|
|
|
|
annotation_objects_->RegisterLocationDescriptor(
|
|
|
|
&module_.annotation_objects);
|
|
|
|
}
|
|
|
|
|
2014-10-24 22:44:55 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t MinidumpModuleCrashpadInfoWriter::SizeOfObject() {
|
|
|
|
DCHECK_GE(state(), kStateFrozen);
|
|
|
|
|
|
|
|
return sizeof(module_);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<internal::MinidumpWritable*>
|
|
|
|
MinidumpModuleCrashpadInfoWriter::Children() {
|
|
|
|
DCHECK_GE(state(), kStateFrozen);
|
|
|
|
|
|
|
|
std::vector<MinidumpWritable*> children;
|
2014-11-07 18:01:17 +03:00
|
|
|
if (list_annotations_) {
|
|
|
|
children.push_back(list_annotations_.get());
|
|
|
|
}
|
2014-10-24 22:44:55 +04:00
|
|
|
if (simple_annotations_) {
|
2014-10-27 22:01:39 +03:00
|
|
|
children.push_back(simple_annotations_.get());
|
2014-10-24 22:44:55 +04:00
|
|
|
}
|
2017-11-02 00:06:18 +03:00
|
|
|
if (annotation_objects_) {
|
|
|
|
children.push_back(annotation_objects_.get());
|
|
|
|
}
|
2014-10-24 22:44:55 +04:00
|
|
|
|
|
|
|
return children;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool MinidumpModuleCrashpadInfoWriter::WriteObject(
|
|
|
|
FileWriterInterface* file_writer) {
|
|
|
|
DCHECK_EQ(state(), kStateWritable);
|
|
|
|
|
|
|
|
return file_writer->Write(&module_, sizeof(module_));
|
|
|
|
}
|
|
|
|
|
|
|
|
MinidumpModuleCrashpadInfoListWriter::MinidumpModuleCrashpadInfoListWriter()
|
2015-03-04 18:53:34 +03:00
|
|
|
: MinidumpWritable(),
|
|
|
|
module_crashpad_infos_(),
|
|
|
|
module_crashpad_info_links_(),
|
|
|
|
module_crashpad_info_list_base_() {
|
2014-10-24 22:44:55 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
MinidumpModuleCrashpadInfoListWriter::~MinidumpModuleCrashpadInfoListWriter() {
|
|
|
|
}
|
|
|
|
|
2014-10-29 00:00:46 +03:00
|
|
|
void MinidumpModuleCrashpadInfoListWriter::InitializeFromSnapshot(
|
|
|
|
const std::vector<const ModuleSnapshot*>& module_snapshots) {
|
|
|
|
DCHECK_EQ(state(), kStateMutable);
|
2015-03-04 18:53:34 +03:00
|
|
|
DCHECK(module_crashpad_infos_.empty());
|
|
|
|
DCHECK(module_crashpad_info_links_.empty());
|
2014-10-29 00:00:46 +03:00
|
|
|
|
|
|
|
size_t count = module_snapshots.size();
|
|
|
|
for (size_t index = 0; index < count; ++index) {
|
|
|
|
const ModuleSnapshot* module_snapshot = module_snapshots[index];
|
|
|
|
|
2017-10-12 19:42:28 +03:00
|
|
|
auto module = std::make_unique<MinidumpModuleCrashpadInfoWriter>();
|
2015-03-04 18:53:34 +03:00
|
|
|
module->InitializeFromSnapshot(module_snapshot);
|
2014-10-29 00:00:46 +03:00
|
|
|
if (module->IsUseful()) {
|
2015-12-10 01:36:32 +03:00
|
|
|
AddModule(std::move(module), index);
|
2014-10-29 00:00:46 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-24 22:44:55 +04:00
|
|
|
void MinidumpModuleCrashpadInfoListWriter::AddModule(
|
2016-04-25 22:13:07 +03:00
|
|
|
std::unique_ptr<MinidumpModuleCrashpadInfoWriter> module_crashpad_info,
|
2015-03-04 18:53:34 +03:00
|
|
|
size_t minidump_module_list_index) {
|
2014-10-24 22:44:55 +04:00
|
|
|
DCHECK_EQ(state(), kStateMutable);
|
2015-03-04 18:53:34 +03:00
|
|
|
DCHECK_EQ(module_crashpad_infos_.size(), module_crashpad_info_links_.size());
|
|
|
|
|
|
|
|
MinidumpModuleCrashpadInfoLink module_crashpad_info_link = {};
|
|
|
|
if (!AssignIfInRange(&module_crashpad_info_link.minidump_module_list_index,
|
|
|
|
minidump_module_list_index)) {
|
|
|
|
LOG(ERROR) << "minidump_module_list_index " << minidump_module_list_index
|
|
|
|
<< " out of range";
|
|
|
|
return;
|
|
|
|
}
|
2014-10-24 22:44:55 +04:00
|
|
|
|
2015-03-04 18:53:34 +03:00
|
|
|
module_crashpad_info_links_.push_back(module_crashpad_info_link);
|
2017-10-19 07:26:38 +03:00
|
|
|
module_crashpad_infos_.push_back(std::move(module_crashpad_info));
|
2014-10-24 22:44:55 +04:00
|
|
|
}
|
|
|
|
|
2014-11-07 19:38:13 +03:00
|
|
|
bool MinidumpModuleCrashpadInfoListWriter::IsUseful() const {
|
2015-03-04 18:53:34 +03:00
|
|
|
DCHECK_EQ(module_crashpad_infos_.size(), module_crashpad_info_links_.size());
|
|
|
|
return !module_crashpad_infos_.empty();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool MinidumpModuleCrashpadInfoListWriter::Freeze() {
|
|
|
|
DCHECK_EQ(state(), kStateMutable);
|
|
|
|
CHECK_EQ(module_crashpad_infos_.size(), module_crashpad_info_links_.size());
|
|
|
|
|
|
|
|
if (!MinidumpWritable::Freeze()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t module_count = module_crashpad_infos_.size();
|
|
|
|
if (!AssignIfInRange(&module_crashpad_info_list_base_.count, module_count)) {
|
|
|
|
LOG(ERROR) << "module_count " << module_count << " out of range";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (size_t index = 0; index < module_count; ++index) {
|
|
|
|
module_crashpad_infos_[index]->RegisterLocationDescriptor(
|
|
|
|
&module_crashpad_info_links_[index].location);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t MinidumpModuleCrashpadInfoListWriter::SizeOfObject() {
|
|
|
|
DCHECK_GE(state(), kStateFrozen);
|
|
|
|
DCHECK_EQ(module_crashpad_infos_.size(), module_crashpad_info_links_.size());
|
|
|
|
|
|
|
|
return sizeof(module_crashpad_info_list_base_) +
|
|
|
|
module_crashpad_info_links_.size() *
|
|
|
|
sizeof(module_crashpad_info_links_[0]);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<internal::MinidumpWritable*>
|
|
|
|
MinidumpModuleCrashpadInfoListWriter::Children() {
|
|
|
|
DCHECK_GE(state(), kStateFrozen);
|
|
|
|
DCHECK_EQ(module_crashpad_infos_.size(), module_crashpad_info_links_.size());
|
|
|
|
|
|
|
|
std::vector<MinidumpWritable*> children;
|
2017-10-19 07:26:38 +03:00
|
|
|
for (const auto& module : module_crashpad_infos_) {
|
|
|
|
children.push_back(module.get());
|
2015-03-04 18:53:34 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return children;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool MinidumpModuleCrashpadInfoListWriter::WriteObject(
|
|
|
|
FileWriterInterface* file_writer) {
|
|
|
|
DCHECK_EQ(state(), kStateWritable);
|
|
|
|
DCHECK_EQ(module_crashpad_infos_.size(), module_crashpad_info_links_.size());
|
|
|
|
|
|
|
|
WritableIoVec iov;
|
|
|
|
iov.iov_base = &module_crashpad_info_list_base_;
|
|
|
|
iov.iov_len = sizeof(module_crashpad_info_list_base_);
|
|
|
|
std::vector<WritableIoVec> iovecs(1, iov);
|
|
|
|
|
|
|
|
if (!module_crashpad_info_links_.empty()) {
|
|
|
|
iov.iov_base = &module_crashpad_info_links_[0];
|
|
|
|
iov.iov_len = module_crashpad_info_links_.size() *
|
|
|
|
sizeof(module_crashpad_info_links_[0]);
|
|
|
|
iovecs.push_back(iov);
|
|
|
|
}
|
|
|
|
|
|
|
|
return file_writer->WriteIoVec(&iovecs);
|
2014-11-07 19:38:13 +03:00
|
|
|
}
|
|
|
|
|
2014-10-24 22:44:55 +04:00
|
|
|
} // namespace crashpad
|