2022-09-06 19:14:07 -04:00
|
|
|
// Copyright 2014 The Crashpad Authors
|
2014-10-17 18:00:41 -04:00
|
|
|
//
|
|
|
|
// 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.
|
|
|
|
|
|
|
|
#include "minidump/minidump_crashpad_info_writer.h"
|
|
|
|
|
2015-12-09 17:36:32 -05:00
|
|
|
#include <utility>
|
|
|
|
|
2020-06-22 11:14:31 +02:00
|
|
|
#include "base/check_op.h"
|
2014-10-24 14:58:53 -04:00
|
|
|
#include "minidump/minidump_module_crashpad_info_writer.h"
|
2015-02-17 17:38:02 -05:00
|
|
|
#include "minidump/minidump_simple_string_dictionary_writer.h"
|
2014-11-07 11:38:13 -05:00
|
|
|
#include "snapshot/process_snapshot.h"
|
2023-01-06 13:45:52 -05:00
|
|
|
#include "snapshot/system_snapshot.h"
|
2014-10-23 18:47:27 -04:00
|
|
|
#include "util/file/file_writer.h"
|
2014-10-17 18:00:41 -04:00
|
|
|
|
|
|
|
namespace crashpad {
|
|
|
|
|
|
|
|
MinidumpCrashpadInfoWriter::MinidumpCrashpadInfoWriter()
|
2015-02-17 17:38:02 -05:00
|
|
|
: MinidumpStreamWriter(),
|
|
|
|
crashpad_info_(),
|
|
|
|
simple_annotations_(nullptr),
|
|
|
|
module_list_(nullptr) {
|
2014-10-24 14:44:55 -04:00
|
|
|
crashpad_info_.version = MinidumpCrashpadInfo::kVersion;
|
2023-01-06 13:45:52 -05:00
|
|
|
crashpad_info_.reserved = 0;
|
2014-10-17 18:00:41 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
MinidumpCrashpadInfoWriter::~MinidumpCrashpadInfoWriter() {
|
|
|
|
}
|
|
|
|
|
2014-11-07 11:38:13 -05:00
|
|
|
void MinidumpCrashpadInfoWriter::InitializeFromSnapshot(
|
|
|
|
const ProcessSnapshot* process_snapshot) {
|
|
|
|
DCHECK_EQ(state(), kStateMutable);
|
|
|
|
DCHECK(!module_list_);
|
|
|
|
|
2015-03-13 13:00:56 -04:00
|
|
|
UUID report_id;
|
|
|
|
process_snapshot->ReportID(&report_id);
|
|
|
|
SetReportID(report_id);
|
|
|
|
|
2015-03-11 17:10:50 -04:00
|
|
|
UUID client_id;
|
|
|
|
process_snapshot->ClientID(&client_id);
|
|
|
|
SetClientID(client_id);
|
|
|
|
|
2015-02-17 17:38:02 -05:00
|
|
|
auto simple_annotations =
|
2017-10-12 12:42:28 -04:00
|
|
|
std::make_unique<MinidumpSimpleStringDictionaryWriter>();
|
2015-02-17 17:38:02 -05:00
|
|
|
simple_annotations->InitializeFromMap(
|
|
|
|
process_snapshot->AnnotationsSimpleMap());
|
|
|
|
if (simple_annotations->IsUseful()) {
|
2015-12-09 17:36:32 -05:00
|
|
|
SetSimpleAnnotations(std::move(simple_annotations));
|
2015-02-17 17:38:02 -05:00
|
|
|
}
|
|
|
|
|
2023-01-06 13:45:52 -05:00
|
|
|
if (process_snapshot->System()) {
|
|
|
|
SetAddressMask(process_snapshot->System()->AddressMask());
|
|
|
|
}
|
|
|
|
|
2017-10-12 12:42:28 -04:00
|
|
|
auto modules = std::make_unique<MinidumpModuleCrashpadInfoListWriter>();
|
2014-11-07 11:38:13 -05:00
|
|
|
modules->InitializeFromSnapshot(process_snapshot->Modules());
|
|
|
|
|
|
|
|
if (modules->IsUseful()) {
|
2015-12-09 17:36:32 -05:00
|
|
|
SetModuleList(std::move(modules));
|
2014-11-07 11:38:13 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-13 13:00:56 -04:00
|
|
|
void MinidumpCrashpadInfoWriter::SetReportID(const UUID& report_id) {
|
|
|
|
DCHECK_EQ(state(), kStateMutable);
|
|
|
|
|
|
|
|
crashpad_info_.report_id = report_id;
|
|
|
|
}
|
|
|
|
|
2015-03-11 17:10:50 -04:00
|
|
|
void MinidumpCrashpadInfoWriter::SetClientID(const UUID& client_id) {
|
|
|
|
DCHECK_EQ(state(), kStateMutable);
|
|
|
|
|
|
|
|
crashpad_info_.client_id = client_id;
|
|
|
|
}
|
|
|
|
|
2015-02-17 17:38:02 -05:00
|
|
|
void MinidumpCrashpadInfoWriter::SetSimpleAnnotations(
|
2016-04-25 12:13:07 -07:00
|
|
|
std::unique_ptr<MinidumpSimpleStringDictionaryWriter> simple_annotations) {
|
2015-02-17 17:38:02 -05:00
|
|
|
DCHECK_EQ(state(), kStateMutable);
|
|
|
|
|
2015-12-09 17:36:32 -05:00
|
|
|
simple_annotations_ = std::move(simple_annotations);
|
2015-02-17 17:38:02 -05:00
|
|
|
}
|
|
|
|
|
2014-10-24 14:44:55 -04:00
|
|
|
void MinidumpCrashpadInfoWriter::SetModuleList(
|
2016-04-25 12:13:07 -07:00
|
|
|
std::unique_ptr<MinidumpModuleCrashpadInfoListWriter> module_list) {
|
2014-10-17 18:00:41 -04:00
|
|
|
DCHECK_EQ(state(), kStateMutable);
|
|
|
|
|
2015-12-09 17:36:32 -05:00
|
|
|
module_list_ = std::move(module_list);
|
2014-10-17 18:00:41 -04:00
|
|
|
}
|
|
|
|
|
2023-01-06 13:45:52 -05:00
|
|
|
void MinidumpCrashpadInfoWriter::SetAddressMask(uint64_t mask) {
|
|
|
|
crashpad_info_.address_mask = mask;
|
|
|
|
}
|
|
|
|
|
2014-10-17 18:00:41 -04:00
|
|
|
bool MinidumpCrashpadInfoWriter::Freeze() {
|
|
|
|
DCHECK_EQ(state(), kStateMutable);
|
|
|
|
|
|
|
|
if (!MinidumpStreamWriter::Freeze()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-02-17 17:38:02 -05:00
|
|
|
if (simple_annotations_) {
|
|
|
|
simple_annotations_->RegisterLocationDescriptor(
|
|
|
|
&crashpad_info_.simple_annotations);
|
|
|
|
}
|
2014-10-24 14:44:55 -04:00
|
|
|
if (module_list_) {
|
|
|
|
module_list_->RegisterLocationDescriptor(&crashpad_info_.module_list);
|
2014-10-17 18:00:41 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t MinidumpCrashpadInfoWriter::SizeOfObject() {
|
|
|
|
DCHECK_GE(state(), kStateFrozen);
|
|
|
|
|
|
|
|
return sizeof(crashpad_info_);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<internal::MinidumpWritable*>
|
|
|
|
MinidumpCrashpadInfoWriter::Children() {
|
|
|
|
DCHECK_GE(state(), kStateFrozen);
|
|
|
|
|
|
|
|
std::vector<MinidumpWritable*> children;
|
2015-02-17 17:38:02 -05:00
|
|
|
if (simple_annotations_) {
|
|
|
|
children.push_back(simple_annotations_.get());
|
|
|
|
}
|
2014-10-24 14:44:55 -04:00
|
|
|
if (module_list_) {
|
2014-10-27 15:01:39 -04:00
|
|
|
children.push_back(module_list_.get());
|
2014-10-17 18:00:41 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return children;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool MinidumpCrashpadInfoWriter::WriteObject(FileWriterInterface* file_writer) {
|
|
|
|
DCHECK_EQ(state(), kStateWritable);
|
|
|
|
|
|
|
|
return file_writer->Write(&crashpad_info_, sizeof(crashpad_info_));
|
|
|
|
}
|
|
|
|
|
|
|
|
MinidumpStreamType MinidumpCrashpadInfoWriter::StreamType() const {
|
|
|
|
return kMinidumpStreamTypeCrashpadInfo;
|
|
|
|
}
|
|
|
|
|
2014-11-07 11:38:13 -05:00
|
|
|
bool MinidumpCrashpadInfoWriter::IsUseful() const {
|
2015-03-13 13:00:56 -04:00
|
|
|
return crashpad_info_.report_id != UUID() ||
|
|
|
|
crashpad_info_.client_id != UUID() ||
|
2015-03-11 17:10:50 -04:00
|
|
|
simple_annotations_ ||
|
|
|
|
module_list_;
|
2014-11-07 11:38:13 -05:00
|
|
|
}
|
|
|
|
|
2014-10-17 18:00:41 -04:00
|
|
|
} // namespace crashpad
|