2022-09-06 19:14:07 -04:00
|
|
|
|
// Copyright 2014 The Crashpad Authors
|
2014-08-13 15:26:21 -07: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_module_writer.h"
|
|
|
|
|
|
2017-03-22 21:44:05 -04:00
|
|
|
|
#include <stddef.h>
|
|
|
|
|
|
2014-10-29 11:38:49 -04:00
|
|
|
|
#include <limits>
|
2015-12-09 17:36:32 -05:00
|
|
|
|
#include <utility>
|
2014-10-29 11:38:49 -04:00
|
|
|
|
|
2023-10-18 12:08:10 -07:00
|
|
|
|
#include "base/check_op.h"
|
2014-08-13 15:26:21 -07:00
|
|
|
|
#include "base/logging.h"
|
2015-03-06 16:05:34 -08:00
|
|
|
|
#include "base/numerics/safe_conversions.h"
|
2014-08-13 15:26:21 -07:00
|
|
|
|
#include "minidump/minidump_string_writer.h"
|
|
|
|
|
#include "minidump/minidump_writer_util.h"
|
2014-10-29 11:38:49 -04:00
|
|
|
|
#include "snapshot/module_snapshot.h"
|
2014-10-23 18:47:27 -04:00
|
|
|
|
#include "util/file/file_writer.h"
|
2015-09-14 11:09:46 -07:00
|
|
|
|
#include "util/misc/implicit_cast.h"
|
2014-10-29 11:38:49 -04:00
|
|
|
|
#include "util/numeric/in_range_cast.h"
|
2014-08-13 15:26:21 -07:00
|
|
|
|
#include "util/numeric/safe_assignment.h"
|
|
|
|
|
|
|
|
|
|
namespace crashpad {
|
|
|
|
|
|
2019-04-17 22:01:50 -07:00
|
|
|
|
MinidumpModuleCodeViewRecordWriter::~MinidumpModuleCodeViewRecordWriter() {}
|
2014-08-13 15:26:21 -07:00
|
|
|
|
|
|
|
|
|
namespace internal {
|
|
|
|
|
|
|
|
|
|
template <typename CodeViewRecordType>
|
|
|
|
|
MinidumpModuleCodeViewRecordPDBLinkWriter<
|
|
|
|
|
CodeViewRecordType>::MinidumpModuleCodeViewRecordPDBLinkWriter()
|
|
|
|
|
: MinidumpModuleCodeViewRecordWriter(), codeview_record_(), pdb_name_() {
|
|
|
|
|
codeview_record_.signature = CodeViewRecordType::kSignature;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template <typename CodeViewRecordType>
|
|
|
|
|
MinidumpModuleCodeViewRecordPDBLinkWriter<
|
2019-04-17 22:01:50 -07:00
|
|
|
|
CodeViewRecordType>::~MinidumpModuleCodeViewRecordPDBLinkWriter() {}
|
2014-08-13 15:26:21 -07:00
|
|
|
|
|
|
|
|
|
template <typename CodeViewRecordType>
|
|
|
|
|
size_t
|
|
|
|
|
MinidumpModuleCodeViewRecordPDBLinkWriter<CodeViewRecordType>::SizeOfObject() {
|
|
|
|
|
DCHECK_GE(state(), kStateFrozen);
|
|
|
|
|
|
|
|
|
|
// NUL-terminate.
|
2014-10-28 17:28:31 -04:00
|
|
|
|
return offsetof(decltype(codeview_record_), pdb_name) +
|
2014-08-13 15:26:21 -07:00
|
|
|
|
(pdb_name_.size() + 1) * sizeof(pdb_name_[0]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template <typename CodeViewRecordType>
|
|
|
|
|
bool MinidumpModuleCodeViewRecordPDBLinkWriter<CodeViewRecordType>::WriteObject(
|
|
|
|
|
FileWriterInterface* file_writer) {
|
|
|
|
|
DCHECK_EQ(state(), kStateWritable);
|
|
|
|
|
|
|
|
|
|
WritableIoVec iov;
|
|
|
|
|
iov.iov_base = &codeview_record_;
|
2014-10-28 17:28:31 -04:00
|
|
|
|
iov.iov_len = offsetof(decltype(codeview_record_), pdb_name);
|
2014-08-13 15:26:21 -07:00
|
|
|
|
std::vector<WritableIoVec> iovecs(1, iov);
|
|
|
|
|
|
|
|
|
|
// NUL-terminate.
|
|
|
|
|
iov.iov_base = &pdb_name_[0];
|
|
|
|
|
iov.iov_len = (pdb_name_.size() + 1) * sizeof(pdb_name_[0]);
|
|
|
|
|
iovecs.push_back(iov);
|
|
|
|
|
|
|
|
|
|
return file_writer->WriteIoVec(&iovecs);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace internal
|
|
|
|
|
|
|
|
|
|
template class internal::MinidumpModuleCodeViewRecordPDBLinkWriter<
|
2015-09-01 09:32:09 -07:00
|
|
|
|
CodeViewRecordPDB20>;
|
2014-08-13 15:26:21 -07:00
|
|
|
|
|
|
|
|
|
MinidumpModuleCodeViewRecordPDB20Writer::
|
2019-04-17 22:01:50 -07:00
|
|
|
|
~MinidumpModuleCodeViewRecordPDB20Writer() {}
|
2014-08-13 15:26:21 -07:00
|
|
|
|
|
|
|
|
|
void MinidumpModuleCodeViewRecordPDB20Writer::SetTimestampAndAge(
|
|
|
|
|
time_t timestamp,
|
|
|
|
|
uint32_t age) {
|
|
|
|
|
DCHECK_EQ(state(), kStateMutable);
|
|
|
|
|
|
|
|
|
|
internal::MinidumpWriterUtil::AssignTimeT(&codeview_record()->timestamp,
|
|
|
|
|
timestamp);
|
|
|
|
|
|
|
|
|
|
codeview_record()->age = age;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template class internal::MinidumpModuleCodeViewRecordPDBLinkWriter<
|
2015-09-01 09:32:09 -07:00
|
|
|
|
CodeViewRecordPDB70>;
|
2014-08-13 15:26:21 -07:00
|
|
|
|
|
|
|
|
|
MinidumpModuleCodeViewRecordPDB70Writer::
|
2019-04-17 22:01:50 -07:00
|
|
|
|
~MinidumpModuleCodeViewRecordPDB70Writer() {}
|
2014-08-13 15:26:21 -07:00
|
|
|
|
|
2014-10-29 11:38:49 -04:00
|
|
|
|
void MinidumpModuleCodeViewRecordPDB70Writer::InitializeFromSnapshot(
|
|
|
|
|
const ModuleSnapshot* module_snapshot) {
|
|
|
|
|
DCHECK_EQ(state(), kStateMutable);
|
|
|
|
|
|
2015-10-29 10:48:23 -07:00
|
|
|
|
SetPDBName(module_snapshot->DebugFileName());
|
2014-10-29 11:38:49 -04:00
|
|
|
|
|
|
|
|
|
UUID uuid;
|
2015-10-27 13:06:58 -07:00
|
|
|
|
uint32_t age;
|
|
|
|
|
module_snapshot->UUIDAndAge(&uuid, &age);
|
|
|
|
|
SetUUIDAndAge(uuid, age);
|
2014-10-29 11:38:49 -04:00
|
|
|
|
}
|
|
|
|
|
|
2019-04-17 22:01:50 -07:00
|
|
|
|
MinidumpModuleCodeViewRecordBuildIDWriter::
|
|
|
|
|
MinidumpModuleCodeViewRecordBuildIDWriter()
|
|
|
|
|
: MinidumpModuleCodeViewRecordWriter(), build_id_() {}
|
|
|
|
|
|
|
|
|
|
MinidumpModuleCodeViewRecordBuildIDWriter::
|
|
|
|
|
~MinidumpModuleCodeViewRecordBuildIDWriter() {}
|
|
|
|
|
|
|
|
|
|
size_t MinidumpModuleCodeViewRecordBuildIDWriter::SizeOfObject() {
|
|
|
|
|
DCHECK_GE(state(), kStateFrozen);
|
|
|
|
|
return offsetof(CodeViewRecordBuildID, build_id) + build_id_.size();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MinidumpModuleCodeViewRecordBuildIDWriter::SetBuildID(
|
|
|
|
|
const std::vector<uint8_t>& build_id) {
|
|
|
|
|
DCHECK_EQ(state(), kStateMutable);
|
|
|
|
|
build_id_ = build_id;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool MinidumpModuleCodeViewRecordBuildIDWriter::WriteObject(
|
|
|
|
|
FileWriterInterface* file_writer) {
|
|
|
|
|
DCHECK_EQ(state(), kStateWritable);
|
|
|
|
|
|
|
|
|
|
CodeViewRecordBuildID cv;
|
|
|
|
|
cv.signature = CodeViewRecordBuildID::kSignature;
|
|
|
|
|
|
|
|
|
|
WritableIoVec iov;
|
|
|
|
|
iov.iov_base = &cv;
|
|
|
|
|
iov.iov_len = offsetof(CodeViewRecordBuildID, build_id);
|
|
|
|
|
std::vector<WritableIoVec> iovecs(1, iov);
|
|
|
|
|
|
|
|
|
|
if (!build_id_.empty()) {
|
|
|
|
|
iov.iov_base = build_id_.data();
|
|
|
|
|
iov.iov_len = build_id_.size();
|
|
|
|
|
iovecs.push_back(iov);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return file_writer->WriteIoVec(&iovecs);
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-13 15:26:21 -07:00
|
|
|
|
MinidumpModuleMiscDebugRecordWriter::MinidumpModuleMiscDebugRecordWriter()
|
|
|
|
|
: internal::MinidumpWritable(),
|
|
|
|
|
image_debug_misc_(),
|
|
|
|
|
data_(),
|
2019-04-17 22:01:50 -07:00
|
|
|
|
data_utf16_() {}
|
2014-08-13 15:26:21 -07:00
|
|
|
|
|
2019-04-17 22:01:50 -07:00
|
|
|
|
MinidumpModuleMiscDebugRecordWriter::~MinidumpModuleMiscDebugRecordWriter() {}
|
2014-10-27 15:01:39 -04:00
|
|
|
|
|
2014-08-13 15:26:21 -07:00
|
|
|
|
void MinidumpModuleMiscDebugRecordWriter::SetData(const std::string& data,
|
|
|
|
|
bool utf16) {
|
|
|
|
|
DCHECK_EQ(state(), kStateMutable);
|
|
|
|
|
|
|
|
|
|
if (!utf16) {
|
|
|
|
|
data_utf16_.clear();
|
|
|
|
|
image_debug_misc_.Unicode = 0;
|
|
|
|
|
data_ = data;
|
|
|
|
|
} else {
|
|
|
|
|
data_.clear();
|
|
|
|
|
image_debug_misc_.Unicode = 1;
|
|
|
|
|
data_utf16_ = internal::MinidumpWriterUtil::ConvertUTF8ToUTF16(data);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool MinidumpModuleMiscDebugRecordWriter::Freeze() {
|
|
|
|
|
DCHECK_EQ(state(), kStateMutable);
|
|
|
|
|
|
|
|
|
|
if (!MinidumpWritable::Freeze()) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// NUL-terminate.
|
|
|
|
|
if (!image_debug_misc_.Unicode) {
|
|
|
|
|
DCHECK(data_utf16_.empty());
|
2015-03-06 16:05:34 -08:00
|
|
|
|
image_debug_misc_.Length = base::checked_cast<uint32_t>(
|
|
|
|
|
offsetof(decltype(image_debug_misc_), Data) +
|
|
|
|
|
(data_.size() + 1) * sizeof(data_[0]));
|
2014-08-13 15:26:21 -07:00
|
|
|
|
} else {
|
|
|
|
|
DCHECK(data_.empty());
|
2015-03-06 16:05:34 -08:00
|
|
|
|
image_debug_misc_.Length = base::checked_cast<uint32_t>(
|
2014-10-28 17:28:31 -04:00
|
|
|
|
offsetof(decltype(image_debug_misc_), Data) +
|
2015-03-06 16:05:34 -08:00
|
|
|
|
(data_utf16_.size() + 1) * sizeof(data_utf16_[0]));
|
2014-08-13 15:26:21 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
size_t MinidumpModuleMiscDebugRecordWriter::SizeOfObject() {
|
|
|
|
|
DCHECK_GE(state(), kStateFrozen);
|
|
|
|
|
|
|
|
|
|
return image_debug_misc_.Length;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool MinidumpModuleMiscDebugRecordWriter::WriteObject(
|
|
|
|
|
FileWriterInterface* file_writer) {
|
|
|
|
|
DCHECK_EQ(state(), kStateWritable);
|
|
|
|
|
|
2014-10-28 17:28:31 -04:00
|
|
|
|
const size_t base_length = offsetof(decltype(image_debug_misc_), Data);
|
2014-08-13 15:26:21 -07:00
|
|
|
|
|
|
|
|
|
WritableIoVec iov;
|
|
|
|
|
iov.iov_base = &image_debug_misc_;
|
|
|
|
|
iov.iov_len = base_length;
|
|
|
|
|
std::vector<WritableIoVec> iovecs(1, iov);
|
|
|
|
|
|
|
|
|
|
if (!image_debug_misc_.Unicode) {
|
|
|
|
|
DCHECK(data_utf16_.empty());
|
|
|
|
|
iov.iov_base = &data_[0];
|
|
|
|
|
} else {
|
|
|
|
|
DCHECK(data_.empty());
|
|
|
|
|
iov.iov_base = &data_utf16_[0];
|
|
|
|
|
}
|
2014-10-23 17:25:20 -04:00
|
|
|
|
iov.iov_len = image_debug_misc_.Length - base_length;
|
2014-08-13 15:26:21 -07:00
|
|
|
|
iovecs.push_back(iov);
|
|
|
|
|
|
|
|
|
|
return file_writer->WriteIoVec(&iovecs);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MinidumpModuleWriter::MinidumpModuleWriter()
|
|
|
|
|
: MinidumpWritable(),
|
|
|
|
|
module_(),
|
|
|
|
|
name_(),
|
2014-10-14 11:10:45 -04:00
|
|
|
|
codeview_record_(nullptr),
|
|
|
|
|
misc_debug_record_(nullptr) {
|
2014-08-13 15:26:21 -07:00
|
|
|
|
module_.VersionInfo.dwSignature = VS_FFI_SIGNATURE;
|
|
|
|
|
module_.VersionInfo.dwStrucVersion = VS_FFI_STRUCVERSION;
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-17 22:01:50 -07:00
|
|
|
|
MinidumpModuleWriter::~MinidumpModuleWriter() {}
|
2014-08-13 15:26:21 -07:00
|
|
|
|
|
2014-10-29 11:38:49 -04:00
|
|
|
|
void MinidumpModuleWriter::InitializeFromSnapshot(
|
|
|
|
|
const ModuleSnapshot* module_snapshot) {
|
|
|
|
|
DCHECK_EQ(state(), kStateMutable);
|
|
|
|
|
DCHECK(!name_);
|
|
|
|
|
DCHECK(!codeview_record_);
|
|
|
|
|
DCHECK(!misc_debug_record_);
|
|
|
|
|
|
|
|
|
|
SetName(module_snapshot->Name());
|
|
|
|
|
|
|
|
|
|
SetImageBaseAddress(module_snapshot->Address());
|
|
|
|
|
SetImageSize(InRangeCast<uint32_t>(module_snapshot->Size(),
|
|
|
|
|
std::numeric_limits<uint32_t>::max()));
|
|
|
|
|
SetTimestamp(module_snapshot->Timestamp());
|
|
|
|
|
|
|
|
|
|
uint16_t v[4];
|
|
|
|
|
module_snapshot->FileVersion(&v[0], &v[1], &v[2], &v[3]);
|
|
|
|
|
SetFileVersion(v[0], v[1], v[2], v[3]);
|
|
|
|
|
|
|
|
|
|
module_snapshot->SourceVersion(&v[0], &v[1], &v[2], &v[3]);
|
|
|
|
|
SetProductVersion(v[0], v[1], v[2], v[3]);
|
|
|
|
|
|
|
|
|
|
uint32_t file_type;
|
|
|
|
|
switch (module_snapshot->GetModuleType()) {
|
|
|
|
|
case ModuleSnapshot::kModuleTypeExecutable:
|
|
|
|
|
file_type = VFT_APP;
|
|
|
|
|
break;
|
|
|
|
|
case ModuleSnapshot::kModuleTypeSharedLibrary:
|
|
|
|
|
case ModuleSnapshot::kModuleTypeLoadableModule:
|
|
|
|
|
file_type = VFT_DLL;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
file_type = VFT_UNKNOWN;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
SetFileTypeAndSubtype(file_type, VFT2_UNKNOWN);
|
|
|
|
|
|
2019-04-17 22:01:50 -07:00
|
|
|
|
auto build_id = module_snapshot->BuildID();
|
|
|
|
|
|
|
|
|
|
std::unique_ptr<MinidumpModuleCodeViewRecordWriter> codeview_record;
|
|
|
|
|
if (!build_id.empty()) {
|
|
|
|
|
auto cv_record_build_id =
|
|
|
|
|
std::make_unique<MinidumpModuleCodeViewRecordBuildIDWriter>();
|
|
|
|
|
cv_record_build_id->SetBuildID(build_id);
|
|
|
|
|
codeview_record = std::move(cv_record_build_id);
|
|
|
|
|
} else {
|
|
|
|
|
auto cv_record_pdb70 =
|
|
|
|
|
std::make_unique<MinidumpModuleCodeViewRecordPDB70Writer>();
|
|
|
|
|
cv_record_pdb70->InitializeFromSnapshot(module_snapshot);
|
|
|
|
|
codeview_record = std::move(cv_record_pdb70);
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-09 17:36:32 -05:00
|
|
|
|
SetCodeViewRecord(std::move(codeview_record));
|
2014-10-29 11:38:49 -04:00
|
|
|
|
}
|
|
|
|
|
|
2014-08-13 15:26:21 -07:00
|
|
|
|
const MINIDUMP_MODULE* MinidumpModuleWriter::MinidumpModule() const {
|
|
|
|
|
DCHECK_EQ(state(), kStateWritable);
|
|
|
|
|
|
|
|
|
|
return &module_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MinidumpModuleWriter::SetName(const std::string& name) {
|
|
|
|
|
DCHECK_EQ(state(), kStateMutable);
|
|
|
|
|
|
|
|
|
|
if (!name_) {
|
|
|
|
|
name_.reset(new internal::MinidumpUTF16StringWriter());
|
|
|
|
|
}
|
|
|
|
|
name_->SetUTF8(name);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MinidumpModuleWriter::SetCodeViewRecord(
|
2016-04-25 12:13:07 -07:00
|
|
|
|
std::unique_ptr<MinidumpModuleCodeViewRecordWriter> codeview_record) {
|
2014-08-13 15:26:21 -07:00
|
|
|
|
DCHECK_EQ(state(), kStateMutable);
|
|
|
|
|
|
2015-12-09 17:36:32 -05:00
|
|
|
|
codeview_record_ = std::move(codeview_record);
|
2014-08-13 15:26:21 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MinidumpModuleWriter::SetMiscDebugRecord(
|
2016-04-25 12:13:07 -07:00
|
|
|
|
std::unique_ptr<MinidumpModuleMiscDebugRecordWriter> misc_debug_record) {
|
2014-08-13 15:26:21 -07:00
|
|
|
|
DCHECK_EQ(state(), kStateMutable);
|
|
|
|
|
|
2015-12-09 17:36:32 -05:00
|
|
|
|
misc_debug_record_ = std::move(misc_debug_record);
|
2014-08-13 15:26:21 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MinidumpModuleWriter::SetTimestamp(time_t timestamp) {
|
|
|
|
|
DCHECK_EQ(state(), kStateMutable);
|
|
|
|
|
|
|
|
|
|
internal::MinidumpWriterUtil::AssignTimeT(&module_.TimeDateStamp, timestamp);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MinidumpModuleWriter::SetFileVersion(uint16_t version_0,
|
|
|
|
|
uint16_t version_1,
|
|
|
|
|
uint16_t version_2,
|
|
|
|
|
uint16_t version_3) {
|
|
|
|
|
DCHECK_EQ(state(), kStateMutable);
|
|
|
|
|
|
|
|
|
|
module_.VersionInfo.dwFileVersionMS =
|
2014-11-06 16:44:38 -05:00
|
|
|
|
(implicit_cast<uint32_t>(version_0) << 16) | version_1;
|
2014-08-13 15:26:21 -07:00
|
|
|
|
module_.VersionInfo.dwFileVersionLS =
|
2014-11-06 16:44:38 -05:00
|
|
|
|
(implicit_cast<uint32_t>(version_2) << 16) | version_3;
|
2014-08-13 15:26:21 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MinidumpModuleWriter::SetProductVersion(uint16_t version_0,
|
|
|
|
|
uint16_t version_1,
|
|
|
|
|
uint16_t version_2,
|
|
|
|
|
uint16_t version_3) {
|
|
|
|
|
DCHECK_EQ(state(), kStateMutable);
|
|
|
|
|
|
|
|
|
|
module_.VersionInfo.dwProductVersionMS =
|
2014-11-06 16:44:38 -05:00
|
|
|
|
(implicit_cast<uint32_t>(version_0) << 16) | version_1;
|
2014-08-13 15:26:21 -07:00
|
|
|
|
module_.VersionInfo.dwProductVersionLS =
|
2014-11-06 16:44:38 -05:00
|
|
|
|
(implicit_cast<uint32_t>(version_2) << 16) | version_3;
|
2014-08-13 15:26:21 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MinidumpModuleWriter::SetFileFlagsAndMask(uint32_t file_flags,
|
|
|
|
|
uint32_t file_flags_mask) {
|
|
|
|
|
DCHECK_EQ(state(), kStateMutable);
|
|
|
|
|
DCHECK_EQ(file_flags & ~file_flags_mask, 0u);
|
|
|
|
|
|
|
|
|
|
module_.VersionInfo.dwFileFlags = file_flags;
|
|
|
|
|
module_.VersionInfo.dwFileFlagsMask = file_flags_mask;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool MinidumpModuleWriter::Freeze() {
|
|
|
|
|
DCHECK_EQ(state(), kStateMutable);
|
2014-10-07 17:31:43 -04:00
|
|
|
|
CHECK(name_);
|
2014-08-13 15:26:21 -07:00
|
|
|
|
|
|
|
|
|
if (!MinidumpWritable::Freeze()) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
name_->RegisterRVA(&module_.ModuleNameRva);
|
|
|
|
|
|
|
|
|
|
if (codeview_record_) {
|
|
|
|
|
codeview_record_->RegisterLocationDescriptor(&module_.CvRecord);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (misc_debug_record_) {
|
|
|
|
|
misc_debug_record_->RegisterLocationDescriptor(&module_.MiscRecord);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
size_t MinidumpModuleWriter::SizeOfObject() {
|
|
|
|
|
DCHECK_GE(state(), kStateFrozen);
|
|
|
|
|
|
|
|
|
|
// This object doesn’t directly write anything itself. Its MINIDUMP_MODULE is
|
|
|
|
|
// written by its parent as part of a MINIDUMP_MODULE_LIST, and its children
|
|
|
|
|
// are responsible for writing themselves.
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::vector<internal::MinidumpWritable*> MinidumpModuleWriter::Children() {
|
|
|
|
|
DCHECK_GE(state(), kStateFrozen);
|
2014-10-07 17:31:43 -04:00
|
|
|
|
DCHECK(name_);
|
2014-08-13 15:26:21 -07:00
|
|
|
|
|
|
|
|
|
std::vector<MinidumpWritable*> children;
|
2014-10-07 17:31:43 -04:00
|
|
|
|
children.push_back(name_.get());
|
2014-08-13 15:26:21 -07:00
|
|
|
|
if (codeview_record_) {
|
2014-10-27 15:01:39 -04:00
|
|
|
|
children.push_back(codeview_record_.get());
|
2014-08-13 15:26:21 -07:00
|
|
|
|
}
|
|
|
|
|
if (misc_debug_record_) {
|
2014-10-27 15:01:39 -04:00
|
|
|
|
children.push_back(misc_debug_record_.get());
|
2014-08-13 15:26:21 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return children;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool MinidumpModuleWriter::WriteObject(FileWriterInterface* file_writer) {
|
|
|
|
|
DCHECK_EQ(state(), kStateWritable);
|
|
|
|
|
|
|
|
|
|
// This object doesn’t directly write anything itself. Its MINIDUMP_MODULE is
|
|
|
|
|
// written by its parent as part of a MINIDUMP_MODULE_LIST, and its children
|
|
|
|
|
// are responsible for writing themselves.
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MinidumpModuleListWriter::MinidumpModuleListWriter()
|
2019-04-17 22:01:50 -07:00
|
|
|
|
: MinidumpStreamWriter(), modules_(), module_list_base_() {}
|
2014-08-13 15:26:21 -07:00
|
|
|
|
|
2019-04-17 22:01:50 -07:00
|
|
|
|
MinidumpModuleListWriter::~MinidumpModuleListWriter() {}
|
2014-08-13 15:26:21 -07:00
|
|
|
|
|
2014-10-29 11:38:49 -04:00
|
|
|
|
void MinidumpModuleListWriter::InitializeFromSnapshot(
|
|
|
|
|
const std::vector<const ModuleSnapshot*>& module_snapshots) {
|
|
|
|
|
DCHECK_EQ(state(), kStateMutable);
|
|
|
|
|
DCHECK(modules_.empty());
|
|
|
|
|
|
|
|
|
|
for (const ModuleSnapshot* module_snapshot : module_snapshots) {
|
2017-10-12 12:42:28 -04:00
|
|
|
|
auto module = std::make_unique<MinidumpModuleWriter>();
|
2014-10-29 11:38:49 -04:00
|
|
|
|
module->InitializeFromSnapshot(module_snapshot);
|
2015-12-09 17:36:32 -05:00
|
|
|
|
AddModule(std::move(module));
|
2014-10-29 11:38:49 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-27 15:01:39 -04:00
|
|
|
|
void MinidumpModuleListWriter::AddModule(
|
2016-04-25 12:13:07 -07:00
|
|
|
|
std::unique_ptr<MinidumpModuleWriter> module) {
|
2014-08-13 15:26:21 -07:00
|
|
|
|
DCHECK_EQ(state(), kStateMutable);
|
|
|
|
|
|
2017-10-19 00:26:38 -04:00
|
|
|
|
modules_.push_back(std::move(module));
|
2014-08-13 15:26:21 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool MinidumpModuleListWriter::Freeze() {
|
|
|
|
|
DCHECK_EQ(state(), kStateMutable);
|
|
|
|
|
|
|
|
|
|
if (!MinidumpStreamWriter::Freeze()) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
size_t module_count = modules_.size();
|
|
|
|
|
if (!AssignIfInRange(&module_list_base_.NumberOfModules, module_count)) {
|
|
|
|
|
LOG(ERROR) << "module_count " << module_count << " out of range";
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
size_t MinidumpModuleListWriter::SizeOfObject() {
|
|
|
|
|
DCHECK_GE(state(), kStateFrozen);
|
|
|
|
|
|
|
|
|
|
return sizeof(module_list_base_) + modules_.size() * sizeof(MINIDUMP_MODULE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::vector<internal::MinidumpWritable*> MinidumpModuleListWriter::Children() {
|
|
|
|
|
DCHECK_GE(state(), kStateFrozen);
|
|
|
|
|
|
|
|
|
|
std::vector<MinidumpWritable*> children;
|
2017-10-19 00:26:38 -04:00
|
|
|
|
for (const auto& module : modules_) {
|
|
|
|
|
children.push_back(module.get());
|
2014-08-13 15:26:21 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return children;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool MinidumpModuleListWriter::WriteObject(FileWriterInterface* file_writer) {
|
|
|
|
|
DCHECK_EQ(state(), kStateWritable);
|
|
|
|
|
|
|
|
|
|
WritableIoVec iov;
|
|
|
|
|
iov.iov_base = &module_list_base_;
|
|
|
|
|
iov.iov_len = sizeof(module_list_base_);
|
|
|
|
|
std::vector<WritableIoVec> iovecs(1, iov);
|
|
|
|
|
|
2017-10-19 00:26:38 -04:00
|
|
|
|
for (const auto& module : modules_) {
|
2014-08-13 15:26:21 -07:00
|
|
|
|
iov.iov_base = module->MinidumpModule();
|
2014-10-23 17:25:20 -04:00
|
|
|
|
iov.iov_len = sizeof(MINIDUMP_MODULE);
|
2014-08-13 15:26:21 -07:00
|
|
|
|
iovecs.push_back(iov);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return file_writer->WriteIoVec(&iovecs);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MinidumpStreamType MinidumpModuleListWriter::StreamType() const {
|
|
|
|
|
return kMinidumpStreamTypeModuleList;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace crashpad
|