2015-02-26 14:43:10 -05:00
|
|
|
// Copyright 2015 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.
|
|
|
|
|
|
|
|
#include "snapshot/minidump/process_snapshot_minidump.h"
|
|
|
|
|
|
|
|
#include <windows.h>
|
|
|
|
#include <dbghelp.h>
|
2016-01-06 12:22:50 -05:00
|
|
|
#include <string.h>
|
2015-02-26 14:43:10 -05:00
|
|
|
|
2016-04-25 12:13:07 -07:00
|
|
|
#include <memory>
|
|
|
|
|
2015-02-26 14:43:10 -05:00
|
|
|
#include "gtest/gtest.h"
|
2017-11-01 16:24:09 -04:00
|
|
|
#include "snapshot/minidump/minidump_annotation_reader.h"
|
2015-03-04 12:29:01 -05:00
|
|
|
#include "snapshot/module_snapshot.h"
|
2015-02-26 14:43:10 -05:00
|
|
|
#include "util/file/string_file.h"
|
|
|
|
|
|
|
|
namespace crashpad {
|
|
|
|
namespace test {
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
TEST(ProcessSnapshotMinidump, EmptyFile) {
|
|
|
|
StringFile string_file;
|
|
|
|
ProcessSnapshotMinidump process_snapshot;
|
|
|
|
|
|
|
|
EXPECT_FALSE(process_snapshot.Initialize(&string_file));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(ProcessSnapshotMinidump, InvalidSignatureAndVersion) {
|
|
|
|
StringFile string_file;
|
|
|
|
|
|
|
|
MINIDUMP_HEADER header = {};
|
|
|
|
|
|
|
|
EXPECT_TRUE(string_file.Write(&header, sizeof(header)));
|
|
|
|
|
|
|
|
ProcessSnapshotMinidump process_snapshot;
|
|
|
|
EXPECT_FALSE(process_snapshot.Initialize(&string_file));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(ProcessSnapshotMinidump, Empty) {
|
|
|
|
StringFile string_file;
|
|
|
|
|
|
|
|
MINIDUMP_HEADER header = {};
|
|
|
|
header.Signature = MINIDUMP_SIGNATURE;
|
|
|
|
header.Version = MINIDUMP_VERSION;
|
|
|
|
|
|
|
|
EXPECT_TRUE(string_file.Write(&header, sizeof(header)));
|
|
|
|
|
|
|
|
ProcessSnapshotMinidump process_snapshot;
|
|
|
|
EXPECT_TRUE(process_snapshot.Initialize(&string_file));
|
2015-03-11 17:10:50 -04:00
|
|
|
|
|
|
|
UUID client_id;
|
|
|
|
process_snapshot.ClientID(&client_id);
|
test: Use (actual, [un]expected) in gtest {ASSERT,EXPECT}_{EQ,NE}
gtest used to require (expected, actual) ordering for arguments to
EXPECT_EQ and ASSERT_EQ, and in failed test assertions would identify
each side as “expected” or “actual.” Tests in Crashpad adhered to this
traditional ordering. After a gtest change in February 2016, it is now
agnostic with respect to the order of these arguments.
This change mechanically updates all uses of these macros to (actual,
expected) by reversing them. This provides consistency with our use of
the logging CHECK_EQ and DCHECK_EQ macros, and makes for better
readability by ordinary native speakers. The rough (but working!)
conversion tool is
https://chromium-review.googlesource.com/c/466727/1/rewrite_expectassert_eq.py,
and “git cl format” cleaned up its output.
EXPECT_NE and ASSERT_NE never had a preferred ordering. gtest never made
a judgment that one side or the other needed to provide an “unexpected”
value. Consequently, some code used (unexpected, actual) while other
code used (actual, unexpected). For consistency with the new EXPECT_EQ
and ASSERT_EQ usage, as well as consistency with CHECK_NE and DCHECK_NE,
this change also updates these use sites to (actual, unexpected) where
one side can be called “unexpected” as, for example, std::string::npos
can be. Unfortunately, this portion was a manual conversion.
References:
https://github.com/google/googletest/blob/master/googletest/docs/Primer.md#binary-comparison
https://github.com/google/googletest/commit/77d6b173380332b1c1bc540532641f410ec82d65
https://github.com/google/googletest/pull/713
Change-Id: I978fef7c94183b8b1ef63f12f5ab4d6693626be3
Reviewed-on: https://chromium-review.googlesource.com/466727
Reviewed-by: Scott Graham <scottmg@chromium.org>
2017-04-04 00:35:21 -04:00
|
|
|
EXPECT_EQ(client_id, UUID());
|
2015-03-11 17:10:50 -04:00
|
|
|
|
|
|
|
EXPECT_TRUE(process_snapshot.AnnotationsSimpleMap().empty());
|
2015-02-26 14:43:10 -05:00
|
|
|
}
|
|
|
|
|
2015-03-04 12:29:01 -05:00
|
|
|
// Writes |string| to |writer| as a MinidumpUTF8String, and returns the file
|
2017-11-01 16:24:09 -04:00
|
|
|
// offset of the beginning of the string.
|
2015-03-04 12:29:01 -05:00
|
|
|
RVA WriteString(FileWriterInterface* writer, const std::string& string) {
|
|
|
|
RVA rva = static_cast<RVA>(writer->SeekGet());
|
|
|
|
|
2015-03-06 16:05:34 -08:00
|
|
|
uint32_t string_size = static_cast<uint32_t>(string.size());
|
2015-03-04 12:29:01 -05:00
|
|
|
EXPECT_TRUE(writer->Write(&string_size, sizeof(string_size)));
|
|
|
|
|
|
|
|
// Include the trailing NUL character.
|
|
|
|
EXPECT_TRUE(writer->Write(string.c_str(), string.size() + 1));
|
|
|
|
|
|
|
|
return rva;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Writes |dictionary| to |writer| as a MinidumpSimpleStringDictionary, and
|
|
|
|
// populates |location| with a location descriptor identifying what was written.
|
|
|
|
void WriteMinidumpSimpleStringDictionary(
|
|
|
|
MINIDUMP_LOCATION_DESCRIPTOR* location,
|
|
|
|
FileWriterInterface* writer,
|
|
|
|
const std::map<std::string, std::string>& dictionary) {
|
|
|
|
std::vector<MinidumpSimpleStringDictionaryEntry> entries;
|
|
|
|
for (const auto& it : dictionary) {
|
|
|
|
MinidumpSimpleStringDictionaryEntry entry;
|
|
|
|
entry.key = WriteString(writer, it.first);
|
|
|
|
entry.value = WriteString(writer, it.second);
|
|
|
|
entries.push_back(entry);
|
|
|
|
}
|
|
|
|
|
|
|
|
location->Rva = static_cast<RVA>(writer->SeekGet());
|
|
|
|
|
2015-03-06 16:05:34 -08:00
|
|
|
const uint32_t simple_string_dictionary_entries =
|
|
|
|
static_cast<uint32_t>(entries.size());
|
2015-03-04 12:29:01 -05:00
|
|
|
EXPECT_TRUE(writer->Write(&simple_string_dictionary_entries,
|
|
|
|
sizeof(simple_string_dictionary_entries)));
|
|
|
|
for (const MinidumpSimpleStringDictionaryEntry& entry : entries) {
|
|
|
|
EXPECT_TRUE(writer->Write(&entry, sizeof(entry)));
|
|
|
|
}
|
|
|
|
|
2015-03-06 16:05:34 -08:00
|
|
|
location->DataSize = static_cast<uint32_t>(
|
2015-03-04 12:29:01 -05:00
|
|
|
sizeof(simple_string_dictionary_entries) +
|
2015-03-06 16:05:34 -08:00
|
|
|
entries.size() * sizeof(MinidumpSimpleStringDictionaryEntry));
|
2015-03-04 12:29:01 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Writes |strings| to |writer| as a MinidumpRVAList referencing
|
|
|
|
// MinidumpUTF8String objects, and populates |location| with a location
|
|
|
|
// descriptor identifying what was written.
|
|
|
|
void WriteMinidumpStringList(MINIDUMP_LOCATION_DESCRIPTOR* location,
|
|
|
|
FileWriterInterface* writer,
|
|
|
|
const std::vector<std::string>& strings) {
|
|
|
|
std::vector<RVA> rvas;
|
|
|
|
for (const std::string& string : strings) {
|
|
|
|
rvas.push_back(WriteString(writer, string));
|
|
|
|
}
|
|
|
|
|
|
|
|
location->Rva = static_cast<RVA>(writer->SeekGet());
|
|
|
|
|
2015-03-06 16:05:34 -08:00
|
|
|
const uint32_t string_list_entries = static_cast<uint32_t>(rvas.size());
|
2015-03-04 12:29:01 -05:00
|
|
|
EXPECT_TRUE(writer->Write(&string_list_entries, sizeof(string_list_entries)));
|
|
|
|
for (RVA rva : rvas) {
|
|
|
|
EXPECT_TRUE(writer->Write(&rva, sizeof(rva)));
|
|
|
|
}
|
|
|
|
|
2015-03-06 16:05:34 -08:00
|
|
|
location->DataSize = static_cast<uint32_t>(sizeof(string_list_entries) +
|
|
|
|
rvas.size() * sizeof(RVA));
|
2015-03-04 12:29:01 -05:00
|
|
|
}
|
|
|
|
|
2017-11-01 16:24:09 -04:00
|
|
|
// Writes |data| to |writer| as a MinidumpByteArray, and returns the file offset
|
|
|
|
// from the beginning of the string.
|
|
|
|
RVA WriteByteArray(FileWriterInterface* writer,
|
|
|
|
const std::vector<uint8_t> data) {
|
|
|
|
auto rva = static_cast<RVA>(writer->SeekGet());
|
|
|
|
|
|
|
|
auto length = static_cast<uint32_t>(data.size());
|
|
|
|
EXPECT_TRUE(writer->Write(&length, sizeof(length)));
|
|
|
|
EXPECT_TRUE(writer->Write(data.data(), length));
|
|
|
|
|
|
|
|
return rva;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Writes |annotations| to |writer| as a MinidumpAnnotationList, and populates
|
|
|
|
// |location| with a location descriptor identifying what was written.
|
|
|
|
void WriteMinidumpAnnotationList(
|
|
|
|
MINIDUMP_LOCATION_DESCRIPTOR* location,
|
|
|
|
FileWriterInterface* writer,
|
|
|
|
const std::vector<AnnotationSnapshot>& annotations) {
|
|
|
|
std::vector<MinidumpAnnotation> minidump_annotations;
|
|
|
|
for (const auto& it : annotations) {
|
|
|
|
MinidumpAnnotation annotation;
|
|
|
|
annotation.name = WriteString(writer, it.name);
|
|
|
|
annotation.type = it.type;
|
|
|
|
annotation.reserved = 0;
|
|
|
|
annotation.value = WriteByteArray(writer, it.value);
|
|
|
|
minidump_annotations.push_back(annotation);
|
|
|
|
}
|
|
|
|
|
|
|
|
location->Rva = static_cast<RVA>(writer->SeekGet());
|
|
|
|
|
|
|
|
auto count = static_cast<uint32_t>(minidump_annotations.size());
|
|
|
|
EXPECT_TRUE(writer->Write(&count, sizeof(count)));
|
|
|
|
|
|
|
|
for (const auto& it : minidump_annotations) {
|
|
|
|
EXPECT_TRUE(writer->Write(&it, sizeof(MinidumpAnnotation)));
|
|
|
|
}
|
|
|
|
|
|
|
|
location->DataSize =
|
|
|
|
sizeof(MinidumpAnnotationList) + count * sizeof(MinidumpAnnotation);
|
|
|
|
}
|
|
|
|
|
2015-03-11 17:10:50 -04:00
|
|
|
TEST(ProcessSnapshotMinidump, ClientID) {
|
|
|
|
StringFile string_file;
|
|
|
|
|
|
|
|
MINIDUMP_HEADER header = {};
|
|
|
|
EXPECT_TRUE(string_file.Write(&header, sizeof(header)));
|
|
|
|
|
|
|
|
UUID client_id;
|
|
|
|
ASSERT_TRUE(
|
|
|
|
client_id.InitializeFromString("0001f4a9-d00d-5155-0a55-c0ffeec0ffee"));
|
|
|
|
|
|
|
|
MinidumpCrashpadInfo crashpad_info = {};
|
|
|
|
crashpad_info.version = MinidumpCrashpadInfo::kVersion;
|
|
|
|
crashpad_info.client_id = client_id;
|
|
|
|
|
|
|
|
MINIDUMP_DIRECTORY crashpad_info_directory = {};
|
|
|
|
crashpad_info_directory.StreamType = kMinidumpStreamTypeCrashpadInfo;
|
|
|
|
crashpad_info_directory.Location.Rva =
|
|
|
|
static_cast<RVA>(string_file.SeekGet());
|
|
|
|
EXPECT_TRUE(string_file.Write(&crashpad_info, sizeof(crashpad_info)));
|
|
|
|
crashpad_info_directory.Location.DataSize = sizeof(crashpad_info);
|
|
|
|
|
|
|
|
header.StreamDirectoryRva = static_cast<RVA>(string_file.SeekGet());
|
|
|
|
EXPECT_TRUE(string_file.Write(&crashpad_info_directory,
|
|
|
|
sizeof(crashpad_info_directory)));
|
|
|
|
|
|
|
|
header.Signature = MINIDUMP_SIGNATURE;
|
|
|
|
header.Version = MINIDUMP_VERSION;
|
|
|
|
header.NumberOfStreams = 1;
|
|
|
|
EXPECT_TRUE(string_file.SeekSet(0));
|
|
|
|
EXPECT_TRUE(string_file.Write(&header, sizeof(header)));
|
|
|
|
|
|
|
|
ProcessSnapshotMinidump process_snapshot;
|
|
|
|
EXPECT_TRUE(process_snapshot.Initialize(&string_file));
|
|
|
|
|
|
|
|
UUID actual_client_id;
|
|
|
|
process_snapshot.ClientID(&actual_client_id);
|
test: Use (actual, [un]expected) in gtest {ASSERT,EXPECT}_{EQ,NE}
gtest used to require (expected, actual) ordering for arguments to
EXPECT_EQ and ASSERT_EQ, and in failed test assertions would identify
each side as “expected” or “actual.” Tests in Crashpad adhered to this
traditional ordering. After a gtest change in February 2016, it is now
agnostic with respect to the order of these arguments.
This change mechanically updates all uses of these macros to (actual,
expected) by reversing them. This provides consistency with our use of
the logging CHECK_EQ and DCHECK_EQ macros, and makes for better
readability by ordinary native speakers. The rough (but working!)
conversion tool is
https://chromium-review.googlesource.com/c/466727/1/rewrite_expectassert_eq.py,
and “git cl format” cleaned up its output.
EXPECT_NE and ASSERT_NE never had a preferred ordering. gtest never made
a judgment that one side or the other needed to provide an “unexpected”
value. Consequently, some code used (unexpected, actual) while other
code used (actual, unexpected). For consistency with the new EXPECT_EQ
and ASSERT_EQ usage, as well as consistency with CHECK_NE and DCHECK_NE,
this change also updates these use sites to (actual, unexpected) where
one side can be called “unexpected” as, for example, std::string::npos
can be. Unfortunately, this portion was a manual conversion.
References:
https://github.com/google/googletest/blob/master/googletest/docs/Primer.md#binary-comparison
https://github.com/google/googletest/commit/77d6b173380332b1c1bc540532641f410ec82d65
https://github.com/google/googletest/pull/713
Change-Id: I978fef7c94183b8b1ef63f12f5ab4d6693626be3
Reviewed-on: https://chromium-review.googlesource.com/466727
Reviewed-by: Scott Graham <scottmg@chromium.org>
2017-04-04 00:35:21 -04:00
|
|
|
EXPECT_EQ(actual_client_id, client_id);
|
2015-03-11 17:10:50 -04:00
|
|
|
|
|
|
|
EXPECT_TRUE(process_snapshot.AnnotationsSimpleMap().empty());
|
|
|
|
}
|
|
|
|
|
2015-02-26 14:43:10 -05:00
|
|
|
TEST(ProcessSnapshotMinidump, AnnotationsSimpleMap) {
|
|
|
|
StringFile string_file;
|
|
|
|
|
|
|
|
MINIDUMP_HEADER header = {};
|
|
|
|
EXPECT_TRUE(string_file.Write(&header, sizeof(header)));
|
|
|
|
|
|
|
|
MinidumpCrashpadInfo crashpad_info = {};
|
|
|
|
crashpad_info.version = MinidumpCrashpadInfo::kVersion;
|
|
|
|
|
2015-03-04 12:29:01 -05:00
|
|
|
std::map<std::string, std::string> dictionary;
|
|
|
|
dictionary["the first key"] = "THE FIRST VALUE EVER!";
|
|
|
|
dictionary["2key"] = "a lowly second value";
|
|
|
|
WriteMinidumpSimpleStringDictionary(
|
|
|
|
&crashpad_info.simple_annotations, &string_file, dictionary);
|
2015-02-26 14:43:10 -05:00
|
|
|
|
|
|
|
MINIDUMP_DIRECTORY crashpad_info_directory = {};
|
|
|
|
crashpad_info_directory.StreamType = kMinidumpStreamTypeCrashpadInfo;
|
|
|
|
crashpad_info_directory.Location.Rva =
|
|
|
|
static_cast<RVA>(string_file.SeekGet());
|
|
|
|
EXPECT_TRUE(string_file.Write(&crashpad_info, sizeof(crashpad_info)));
|
|
|
|
crashpad_info_directory.Location.DataSize = sizeof(crashpad_info);
|
|
|
|
|
|
|
|
header.StreamDirectoryRva = static_cast<RVA>(string_file.SeekGet());
|
|
|
|
EXPECT_TRUE(string_file.Write(&crashpad_info_directory,
|
|
|
|
sizeof(crashpad_info_directory)));
|
|
|
|
|
|
|
|
header.Signature = MINIDUMP_SIGNATURE;
|
|
|
|
header.Version = MINIDUMP_VERSION;
|
|
|
|
header.NumberOfStreams = 1;
|
|
|
|
EXPECT_TRUE(string_file.SeekSet(0));
|
|
|
|
EXPECT_TRUE(string_file.Write(&header, sizeof(header)));
|
|
|
|
|
|
|
|
ProcessSnapshotMinidump process_snapshot;
|
|
|
|
EXPECT_TRUE(process_snapshot.Initialize(&string_file));
|
|
|
|
|
2015-03-11 17:10:50 -04:00
|
|
|
UUID client_id;
|
|
|
|
process_snapshot.ClientID(&client_id);
|
test: Use (actual, [un]expected) in gtest {ASSERT,EXPECT}_{EQ,NE}
gtest used to require (expected, actual) ordering for arguments to
EXPECT_EQ and ASSERT_EQ, and in failed test assertions would identify
each side as “expected” or “actual.” Tests in Crashpad adhered to this
traditional ordering. After a gtest change in February 2016, it is now
agnostic with respect to the order of these arguments.
This change mechanically updates all uses of these macros to (actual,
expected) by reversing them. This provides consistency with our use of
the logging CHECK_EQ and DCHECK_EQ macros, and makes for better
readability by ordinary native speakers. The rough (but working!)
conversion tool is
https://chromium-review.googlesource.com/c/466727/1/rewrite_expectassert_eq.py,
and “git cl format” cleaned up its output.
EXPECT_NE and ASSERT_NE never had a preferred ordering. gtest never made
a judgment that one side or the other needed to provide an “unexpected”
value. Consequently, some code used (unexpected, actual) while other
code used (actual, unexpected). For consistency with the new EXPECT_EQ
and ASSERT_EQ usage, as well as consistency with CHECK_NE and DCHECK_NE,
this change also updates these use sites to (actual, unexpected) where
one side can be called “unexpected” as, for example, std::string::npos
can be. Unfortunately, this portion was a manual conversion.
References:
https://github.com/google/googletest/blob/master/googletest/docs/Primer.md#binary-comparison
https://github.com/google/googletest/commit/77d6b173380332b1c1bc540532641f410ec82d65
https://github.com/google/googletest/pull/713
Change-Id: I978fef7c94183b8b1ef63f12f5ab4d6693626be3
Reviewed-on: https://chromium-review.googlesource.com/466727
Reviewed-by: Scott Graham <scottmg@chromium.org>
2017-04-04 00:35:21 -04:00
|
|
|
EXPECT_EQ(client_id, UUID());
|
2015-03-11 17:10:50 -04:00
|
|
|
|
2015-02-26 14:43:10 -05:00
|
|
|
const auto annotations_simple_map = process_snapshot.AnnotationsSimpleMap();
|
test: Use (actual, [un]expected) in gtest {ASSERT,EXPECT}_{EQ,NE}
gtest used to require (expected, actual) ordering for arguments to
EXPECT_EQ and ASSERT_EQ, and in failed test assertions would identify
each side as “expected” or “actual.” Tests in Crashpad adhered to this
traditional ordering. After a gtest change in February 2016, it is now
agnostic with respect to the order of these arguments.
This change mechanically updates all uses of these macros to (actual,
expected) by reversing them. This provides consistency with our use of
the logging CHECK_EQ and DCHECK_EQ macros, and makes for better
readability by ordinary native speakers. The rough (but working!)
conversion tool is
https://chromium-review.googlesource.com/c/466727/1/rewrite_expectassert_eq.py,
and “git cl format” cleaned up its output.
EXPECT_NE and ASSERT_NE never had a preferred ordering. gtest never made
a judgment that one side or the other needed to provide an “unexpected”
value. Consequently, some code used (unexpected, actual) while other
code used (actual, unexpected). For consistency with the new EXPECT_EQ
and ASSERT_EQ usage, as well as consistency with CHECK_NE and DCHECK_NE,
this change also updates these use sites to (actual, unexpected) where
one side can be called “unexpected” as, for example, std::string::npos
can be. Unfortunately, this portion was a manual conversion.
References:
https://github.com/google/googletest/blob/master/googletest/docs/Primer.md#binary-comparison
https://github.com/google/googletest/commit/77d6b173380332b1c1bc540532641f410ec82d65
https://github.com/google/googletest/pull/713
Change-Id: I978fef7c94183b8b1ef63f12f5ab4d6693626be3
Reviewed-on: https://chromium-review.googlesource.com/466727
Reviewed-by: Scott Graham <scottmg@chromium.org>
2017-04-04 00:35:21 -04:00
|
|
|
EXPECT_EQ(annotations_simple_map, dictionary);
|
2015-03-04 12:29:01 -05:00
|
|
|
}
|
|
|
|
|
2017-11-01 16:24:09 -04:00
|
|
|
TEST(ProcessSnapshotMinidump, AnnotationObjects) {
|
|
|
|
StringFile string_file;
|
|
|
|
|
|
|
|
MINIDUMP_HEADER header{};
|
|
|
|
EXPECT_TRUE(string_file.Write(&header, sizeof(header)));
|
|
|
|
|
|
|
|
std::vector<AnnotationSnapshot> annotations;
|
|
|
|
annotations.emplace_back(
|
|
|
|
AnnotationSnapshot("name 1", 0xBBBB, {'t', 'e', '\0', 's', 't', '\0'}));
|
|
|
|
annotations.emplace_back(
|
|
|
|
AnnotationSnapshot("name 2", 0xABBA, {0xF0, 0x9F, 0x92, 0x83}));
|
|
|
|
|
|
|
|
MINIDUMP_LOCATION_DESCRIPTOR location;
|
|
|
|
WriteMinidumpAnnotationList(&location, &string_file, annotations);
|
|
|
|
|
|
|
|
std::vector<AnnotationSnapshot> read_annotations;
|
|
|
|
EXPECT_TRUE(internal::ReadMinidumpAnnotationList(
|
|
|
|
&string_file, location, &read_annotations));
|
|
|
|
|
|
|
|
EXPECT_EQ(read_annotations, annotations);
|
|
|
|
}
|
|
|
|
|
2015-03-04 12:29:01 -05:00
|
|
|
TEST(ProcessSnapshotMinidump, Modules) {
|
|
|
|
StringFile string_file;
|
|
|
|
|
|
|
|
MINIDUMP_HEADER header = {};
|
|
|
|
EXPECT_TRUE(string_file.Write(&header, sizeof(header)));
|
|
|
|
|
|
|
|
MINIDUMP_MODULE minidump_module = {};
|
2017-11-01 16:24:09 -04:00
|
|
|
uint32_t minidump_module_count = 4;
|
2015-03-04 12:29:01 -05:00
|
|
|
|
|
|
|
MINIDUMP_DIRECTORY minidump_module_list_directory = {};
|
|
|
|
minidump_module_list_directory.StreamType = kMinidumpStreamTypeModuleList;
|
|
|
|
minidump_module_list_directory.Location.DataSize =
|
|
|
|
sizeof(MINIDUMP_MODULE_LIST) +
|
|
|
|
minidump_module_count * sizeof(MINIDUMP_MODULE);
|
|
|
|
minidump_module_list_directory.Location.Rva =
|
|
|
|
static_cast<RVA>(string_file.SeekGet());
|
|
|
|
|
|
|
|
EXPECT_TRUE(
|
|
|
|
string_file.Write(&minidump_module_count, sizeof(minidump_module_count)));
|
|
|
|
for (uint32_t minidump_module_index = 0;
|
|
|
|
minidump_module_index < minidump_module_count;
|
|
|
|
++minidump_module_index) {
|
|
|
|
EXPECT_TRUE(string_file.Write(&minidump_module, sizeof(minidump_module)));
|
|
|
|
}
|
|
|
|
|
|
|
|
MinidumpModuleCrashpadInfo crashpad_module_0 = {};
|
|
|
|
crashpad_module_0.version = MinidumpModuleCrashpadInfo::kVersion;
|
|
|
|
std::map<std::string, std::string> dictionary_0;
|
|
|
|
dictionary_0["ptype"] = "browser";
|
|
|
|
dictionary_0["pid"] = "12345";
|
|
|
|
WriteMinidumpSimpleStringDictionary(
|
|
|
|
&crashpad_module_0.simple_annotations, &string_file, dictionary_0);
|
|
|
|
|
|
|
|
MinidumpModuleCrashpadInfoLink crashpad_module_0_link = {};
|
|
|
|
crashpad_module_0_link.minidump_module_list_index = 0;
|
|
|
|
crashpad_module_0_link.location.DataSize = sizeof(crashpad_module_0);
|
|
|
|
crashpad_module_0_link.location.Rva = static_cast<RVA>(string_file.SeekGet());
|
|
|
|
EXPECT_TRUE(string_file.Write(&crashpad_module_0, sizeof(crashpad_module_0)));
|
|
|
|
|
|
|
|
MinidumpModuleCrashpadInfo crashpad_module_2 = {};
|
|
|
|
crashpad_module_2.version = MinidumpModuleCrashpadInfo::kVersion;
|
|
|
|
std::map<std::string, std::string> dictionary_2;
|
|
|
|
dictionary_2["fakemodule"] = "yes";
|
|
|
|
WriteMinidumpSimpleStringDictionary(
|
|
|
|
&crashpad_module_2.simple_annotations, &string_file, dictionary_2);
|
|
|
|
|
|
|
|
std::vector<std::string> list_annotations_2;
|
|
|
|
list_annotations_2.push_back("first string");
|
|
|
|
list_annotations_2.push_back("last string");
|
|
|
|
WriteMinidumpStringList(
|
|
|
|
&crashpad_module_2.list_annotations, &string_file, list_annotations_2);
|
|
|
|
|
|
|
|
MinidumpModuleCrashpadInfoLink crashpad_module_2_link = {};
|
|
|
|
crashpad_module_2_link.minidump_module_list_index = 2;
|
|
|
|
crashpad_module_2_link.location.DataSize = sizeof(crashpad_module_2);
|
|
|
|
crashpad_module_2_link.location.Rva = static_cast<RVA>(string_file.SeekGet());
|
|
|
|
EXPECT_TRUE(string_file.Write(&crashpad_module_2, sizeof(crashpad_module_2)));
|
|
|
|
|
2017-11-01 16:24:09 -04:00
|
|
|
MinidumpModuleCrashpadInfo crashpad_module_4 = {};
|
|
|
|
crashpad_module_4.version = MinidumpModuleCrashpadInfo::kVersion;
|
|
|
|
std::vector<AnnotationSnapshot> annotations_4{
|
|
|
|
{"first one", 0xBADE, {'a', 'b', 'c'}},
|
|
|
|
{"2", 0xEDD1, {0x11, 0x22, 0x33}},
|
|
|
|
{"threeeeee", 0xDADA, {'f'}},
|
|
|
|
};
|
|
|
|
WriteMinidumpAnnotationList(
|
|
|
|
&crashpad_module_4.annotation_objects, &string_file, annotations_4);
|
|
|
|
|
|
|
|
MinidumpModuleCrashpadInfoLink crashpad_module_4_link = {};
|
|
|
|
crashpad_module_4_link.minidump_module_list_index = 3;
|
|
|
|
crashpad_module_4_link.location.DataSize = sizeof(crashpad_module_4);
|
|
|
|
crashpad_module_4_link.location.Rva = static_cast<RVA>(string_file.SeekGet());
|
|
|
|
EXPECT_TRUE(string_file.Write(&crashpad_module_4, sizeof(crashpad_module_4)));
|
|
|
|
|
2015-03-04 12:29:01 -05:00
|
|
|
MinidumpCrashpadInfo crashpad_info = {};
|
|
|
|
crashpad_info.version = MinidumpCrashpadInfo::kVersion;
|
|
|
|
|
2017-11-01 16:24:09 -04:00
|
|
|
uint32_t crashpad_module_count = 3;
|
2015-03-04 12:29:01 -05:00
|
|
|
|
|
|
|
crashpad_info.module_list.DataSize =
|
|
|
|
sizeof(MinidumpModuleCrashpadInfoList) +
|
|
|
|
crashpad_module_count * sizeof(MinidumpModuleCrashpadInfoLink);
|
|
|
|
crashpad_info.module_list.Rva = static_cast<RVA>(string_file.SeekGet());
|
|
|
|
|
|
|
|
EXPECT_TRUE(
|
|
|
|
string_file.Write(&crashpad_module_count, sizeof(crashpad_module_count)));
|
|
|
|
EXPECT_TRUE(string_file.Write(&crashpad_module_0_link,
|
|
|
|
sizeof(crashpad_module_0_link)));
|
|
|
|
EXPECT_TRUE(string_file.Write(&crashpad_module_2_link,
|
|
|
|
sizeof(crashpad_module_2_link)));
|
2017-11-01 16:24:09 -04:00
|
|
|
EXPECT_TRUE(string_file.Write(&crashpad_module_4_link,
|
|
|
|
sizeof(crashpad_module_4_link)));
|
2015-03-04 12:29:01 -05:00
|
|
|
|
|
|
|
MINIDUMP_DIRECTORY crashpad_info_directory = {};
|
|
|
|
crashpad_info_directory.StreamType = kMinidumpStreamTypeCrashpadInfo;
|
|
|
|
crashpad_info_directory.Location.DataSize = sizeof(crashpad_info);
|
|
|
|
crashpad_info_directory.Location.Rva =
|
|
|
|
static_cast<RVA>(string_file.SeekGet());
|
|
|
|
EXPECT_TRUE(string_file.Write(&crashpad_info, sizeof(crashpad_info)));
|
|
|
|
|
|
|
|
header.StreamDirectoryRva = static_cast<RVA>(string_file.SeekGet());
|
|
|
|
EXPECT_TRUE(string_file.Write(&minidump_module_list_directory,
|
|
|
|
sizeof(minidump_module_list_directory)));
|
|
|
|
EXPECT_TRUE(string_file.Write(&crashpad_info_directory,
|
|
|
|
sizeof(crashpad_info_directory)));
|
|
|
|
|
|
|
|
header.Signature = MINIDUMP_SIGNATURE;
|
|
|
|
header.Version = MINIDUMP_VERSION;
|
|
|
|
header.NumberOfStreams = 2;
|
|
|
|
EXPECT_TRUE(string_file.SeekSet(0));
|
|
|
|
EXPECT_TRUE(string_file.Write(&header, sizeof(header)));
|
|
|
|
|
|
|
|
ProcessSnapshotMinidump process_snapshot;
|
|
|
|
EXPECT_TRUE(process_snapshot.Initialize(&string_file));
|
|
|
|
|
|
|
|
std::vector<const ModuleSnapshot*> modules = process_snapshot.Modules();
|
test: Use (actual, [un]expected) in gtest {ASSERT,EXPECT}_{EQ,NE}
gtest used to require (expected, actual) ordering for arguments to
EXPECT_EQ and ASSERT_EQ, and in failed test assertions would identify
each side as “expected” or “actual.” Tests in Crashpad adhered to this
traditional ordering. After a gtest change in February 2016, it is now
agnostic with respect to the order of these arguments.
This change mechanically updates all uses of these macros to (actual,
expected) by reversing them. This provides consistency with our use of
the logging CHECK_EQ and DCHECK_EQ macros, and makes for better
readability by ordinary native speakers. The rough (but working!)
conversion tool is
https://chromium-review.googlesource.com/c/466727/1/rewrite_expectassert_eq.py,
and “git cl format” cleaned up its output.
EXPECT_NE and ASSERT_NE never had a preferred ordering. gtest never made
a judgment that one side or the other needed to provide an “unexpected”
value. Consequently, some code used (unexpected, actual) while other
code used (actual, unexpected). For consistency with the new EXPECT_EQ
and ASSERT_EQ usage, as well as consistency with CHECK_NE and DCHECK_NE,
this change also updates these use sites to (actual, unexpected) where
one side can be called “unexpected” as, for example, std::string::npos
can be. Unfortunately, this portion was a manual conversion.
References:
https://github.com/google/googletest/blob/master/googletest/docs/Primer.md#binary-comparison
https://github.com/google/googletest/commit/77d6b173380332b1c1bc540532641f410ec82d65
https://github.com/google/googletest/pull/713
Change-Id: I978fef7c94183b8b1ef63f12f5ab4d6693626be3
Reviewed-on: https://chromium-review.googlesource.com/466727
Reviewed-by: Scott Graham <scottmg@chromium.org>
2017-04-04 00:35:21 -04:00
|
|
|
ASSERT_EQ(modules.size(), minidump_module_count);
|
2015-03-04 12:29:01 -05:00
|
|
|
|
|
|
|
auto annotations_simple_map = modules[0]->AnnotationsSimpleMap();
|
test: Use (actual, [un]expected) in gtest {ASSERT,EXPECT}_{EQ,NE}
gtest used to require (expected, actual) ordering for arguments to
EXPECT_EQ and ASSERT_EQ, and in failed test assertions would identify
each side as “expected” or “actual.” Tests in Crashpad adhered to this
traditional ordering. After a gtest change in February 2016, it is now
agnostic with respect to the order of these arguments.
This change mechanically updates all uses of these macros to (actual,
expected) by reversing them. This provides consistency with our use of
the logging CHECK_EQ and DCHECK_EQ macros, and makes for better
readability by ordinary native speakers. The rough (but working!)
conversion tool is
https://chromium-review.googlesource.com/c/466727/1/rewrite_expectassert_eq.py,
and “git cl format” cleaned up its output.
EXPECT_NE and ASSERT_NE never had a preferred ordering. gtest never made
a judgment that one side or the other needed to provide an “unexpected”
value. Consequently, some code used (unexpected, actual) while other
code used (actual, unexpected). For consistency with the new EXPECT_EQ
and ASSERT_EQ usage, as well as consistency with CHECK_NE and DCHECK_NE,
this change also updates these use sites to (actual, unexpected) where
one side can be called “unexpected” as, for example, std::string::npos
can be. Unfortunately, this portion was a manual conversion.
References:
https://github.com/google/googletest/blob/master/googletest/docs/Primer.md#binary-comparison
https://github.com/google/googletest/commit/77d6b173380332b1c1bc540532641f410ec82d65
https://github.com/google/googletest/pull/713
Change-Id: I978fef7c94183b8b1ef63f12f5ab4d6693626be3
Reviewed-on: https://chromium-review.googlesource.com/466727
Reviewed-by: Scott Graham <scottmg@chromium.org>
2017-04-04 00:35:21 -04:00
|
|
|
EXPECT_EQ(annotations_simple_map, dictionary_0);
|
2015-03-04 12:29:01 -05:00
|
|
|
|
|
|
|
auto annotations_vector = modules[0]->AnnotationsVector();
|
|
|
|
EXPECT_TRUE(annotations_vector.empty());
|
|
|
|
|
|
|
|
annotations_simple_map = modules[1]->AnnotationsSimpleMap();
|
|
|
|
EXPECT_TRUE(annotations_simple_map.empty());
|
|
|
|
|
|
|
|
annotations_vector = modules[1]->AnnotationsVector();
|
|
|
|
EXPECT_TRUE(annotations_vector.empty());
|
2015-02-26 14:43:10 -05:00
|
|
|
|
2015-03-04 12:29:01 -05:00
|
|
|
annotations_simple_map = modules[2]->AnnotationsSimpleMap();
|
test: Use (actual, [un]expected) in gtest {ASSERT,EXPECT}_{EQ,NE}
gtest used to require (expected, actual) ordering for arguments to
EXPECT_EQ and ASSERT_EQ, and in failed test assertions would identify
each side as “expected” or “actual.” Tests in Crashpad adhered to this
traditional ordering. After a gtest change in February 2016, it is now
agnostic with respect to the order of these arguments.
This change mechanically updates all uses of these macros to (actual,
expected) by reversing them. This provides consistency with our use of
the logging CHECK_EQ and DCHECK_EQ macros, and makes for better
readability by ordinary native speakers. The rough (but working!)
conversion tool is
https://chromium-review.googlesource.com/c/466727/1/rewrite_expectassert_eq.py,
and “git cl format” cleaned up its output.
EXPECT_NE and ASSERT_NE never had a preferred ordering. gtest never made
a judgment that one side or the other needed to provide an “unexpected”
value. Consequently, some code used (unexpected, actual) while other
code used (actual, unexpected). For consistency with the new EXPECT_EQ
and ASSERT_EQ usage, as well as consistency with CHECK_NE and DCHECK_NE,
this change also updates these use sites to (actual, unexpected) where
one side can be called “unexpected” as, for example, std::string::npos
can be. Unfortunately, this portion was a manual conversion.
References:
https://github.com/google/googletest/blob/master/googletest/docs/Primer.md#binary-comparison
https://github.com/google/googletest/commit/77d6b173380332b1c1bc540532641f410ec82d65
https://github.com/google/googletest/pull/713
Change-Id: I978fef7c94183b8b1ef63f12f5ab4d6693626be3
Reviewed-on: https://chromium-review.googlesource.com/466727
Reviewed-by: Scott Graham <scottmg@chromium.org>
2017-04-04 00:35:21 -04:00
|
|
|
EXPECT_EQ(annotations_simple_map, dictionary_2);
|
2015-02-26 14:43:10 -05:00
|
|
|
|
2015-03-04 12:29:01 -05:00
|
|
|
annotations_vector = modules[2]->AnnotationsVector();
|
test: Use (actual, [un]expected) in gtest {ASSERT,EXPECT}_{EQ,NE}
gtest used to require (expected, actual) ordering for arguments to
EXPECT_EQ and ASSERT_EQ, and in failed test assertions would identify
each side as “expected” or “actual.” Tests in Crashpad adhered to this
traditional ordering. After a gtest change in February 2016, it is now
agnostic with respect to the order of these arguments.
This change mechanically updates all uses of these macros to (actual,
expected) by reversing them. This provides consistency with our use of
the logging CHECK_EQ and DCHECK_EQ macros, and makes for better
readability by ordinary native speakers. The rough (but working!)
conversion tool is
https://chromium-review.googlesource.com/c/466727/1/rewrite_expectassert_eq.py,
and “git cl format” cleaned up its output.
EXPECT_NE and ASSERT_NE never had a preferred ordering. gtest never made
a judgment that one side or the other needed to provide an “unexpected”
value. Consequently, some code used (unexpected, actual) while other
code used (actual, unexpected). For consistency with the new EXPECT_EQ
and ASSERT_EQ usage, as well as consistency with CHECK_NE and DCHECK_NE,
this change also updates these use sites to (actual, unexpected) where
one side can be called “unexpected” as, for example, std::string::npos
can be. Unfortunately, this portion was a manual conversion.
References:
https://github.com/google/googletest/blob/master/googletest/docs/Primer.md#binary-comparison
https://github.com/google/googletest/commit/77d6b173380332b1c1bc540532641f410ec82d65
https://github.com/google/googletest/pull/713
Change-Id: I978fef7c94183b8b1ef63f12f5ab4d6693626be3
Reviewed-on: https://chromium-review.googlesource.com/466727
Reviewed-by: Scott Graham <scottmg@chromium.org>
2017-04-04 00:35:21 -04:00
|
|
|
EXPECT_EQ(annotations_vector, list_annotations_2);
|
2017-11-01 16:24:09 -04:00
|
|
|
|
|
|
|
auto annotation_objects = modules[3]->AnnotationObjects();
|
|
|
|
EXPECT_EQ(annotation_objects, annotations_4);
|
2015-02-26 14:43:10 -05:00
|
|
|
}
|
|
|
|
|
2018-07-24 09:21:51 -07:00
|
|
|
TEST(ProcessSnapshotMinidump, ProcessID) {
|
|
|
|
StringFile string_file;
|
|
|
|
|
|
|
|
MINIDUMP_HEADER header = {};
|
|
|
|
ASSERT_TRUE(string_file.Write(&header, sizeof(header)));
|
|
|
|
|
|
|
|
static const pid_t kTestProcessId = 42;
|
|
|
|
MINIDUMP_MISC_INFO misc_info = {};
|
|
|
|
misc_info.SizeOfInfo = sizeof(misc_info);
|
|
|
|
misc_info.Flags1 = MINIDUMP_MISC1_PROCESS_ID;
|
|
|
|
misc_info.ProcessId = kTestProcessId;
|
|
|
|
|
|
|
|
MINIDUMP_DIRECTORY misc_directory = {};
|
|
|
|
misc_directory.StreamType = kMinidumpStreamTypeMiscInfo;
|
|
|
|
misc_directory.Location.DataSize = sizeof(misc_info);
|
|
|
|
misc_directory.Location.Rva = static_cast<RVA>(string_file.SeekGet());
|
|
|
|
ASSERT_TRUE(string_file.Write(&misc_info, sizeof(misc_info)));
|
|
|
|
|
|
|
|
header.StreamDirectoryRva = static_cast<RVA>(string_file.SeekGet());
|
|
|
|
ASSERT_TRUE(string_file.Write(&misc_directory, sizeof(misc_directory)));
|
|
|
|
|
|
|
|
header.Signature = MINIDUMP_SIGNATURE;
|
|
|
|
header.Version = MINIDUMP_VERSION;
|
|
|
|
header.NumberOfStreams = 1;
|
|
|
|
ASSERT_TRUE(string_file.SeekSet(0));
|
|
|
|
ASSERT_TRUE(string_file.Write(&header, sizeof(header)));
|
|
|
|
|
|
|
|
ProcessSnapshotMinidump process_snapshot;
|
|
|
|
ASSERT_TRUE(process_snapshot.Initialize(&string_file));
|
|
|
|
EXPECT_EQ(process_snapshot.ProcessID(), kTestProcessId);
|
|
|
|
}
|
|
|
|
|
2018-10-12 13:12:01 -07:00
|
|
|
TEST(ProcessSnapshotMinidump, Threads) {
|
|
|
|
StringFile string_file;
|
|
|
|
|
|
|
|
MINIDUMP_HEADER header = {};
|
|
|
|
EXPECT_TRUE(string_file.Write(&header, sizeof(header)));
|
|
|
|
|
|
|
|
MINIDUMP_THREAD minidump_thread = {};
|
|
|
|
uint32_t minidump_thread_count = 4;
|
|
|
|
|
|
|
|
minidump_thread.ThreadId = 42;
|
|
|
|
minidump_thread.Teb = 24;
|
|
|
|
|
|
|
|
MINIDUMP_DIRECTORY minidump_thread_list_directory = {};
|
|
|
|
minidump_thread_list_directory.StreamType = kMinidumpStreamTypeThreadList;
|
|
|
|
minidump_thread_list_directory.Location.DataSize =
|
|
|
|
sizeof(MINIDUMP_THREAD_LIST) +
|
|
|
|
minidump_thread_count * sizeof(MINIDUMP_THREAD);
|
|
|
|
minidump_thread_list_directory.Location.Rva =
|
|
|
|
static_cast<RVA>(string_file.SeekGet());
|
|
|
|
|
|
|
|
// Fields in MINIDUMP_THREAD_LIST.
|
|
|
|
EXPECT_TRUE(
|
|
|
|
string_file.Write(&minidump_thread_count, sizeof(minidump_thread_count)));
|
|
|
|
for (uint32_t minidump_thread_index = 0;
|
|
|
|
minidump_thread_index < minidump_thread_count;
|
|
|
|
++minidump_thread_index) {
|
|
|
|
EXPECT_TRUE(string_file.Write(&minidump_thread, sizeof(minidump_thread)));
|
|
|
|
minidump_thread.ThreadId++;
|
|
|
|
}
|
|
|
|
|
|
|
|
header.StreamDirectoryRva = static_cast<RVA>(string_file.SeekGet());
|
|
|
|
EXPECT_TRUE(string_file.Write(&minidump_thread_list_directory,
|
|
|
|
sizeof(minidump_thread_list_directory)));
|
|
|
|
|
|
|
|
header.Signature = MINIDUMP_SIGNATURE;
|
|
|
|
header.Version = MINIDUMP_VERSION;
|
|
|
|
header.NumberOfStreams = 1;
|
|
|
|
EXPECT_TRUE(string_file.SeekSet(0));
|
|
|
|
EXPECT_TRUE(string_file.Write(&header, sizeof(header)));
|
|
|
|
|
|
|
|
ProcessSnapshotMinidump process_snapshot;
|
|
|
|
EXPECT_TRUE(process_snapshot.Initialize(&string_file));
|
|
|
|
|
|
|
|
std::vector<const ThreadSnapshot*> threads = process_snapshot.Threads();
|
|
|
|
ASSERT_EQ(threads.size(), minidump_thread_count);
|
|
|
|
|
|
|
|
uint32_t thread_id = 42;
|
|
|
|
for (const auto& thread : threads) {
|
|
|
|
EXPECT_EQ(thread->ThreadID(), thread_id);
|
|
|
|
EXPECT_EQ(thread->ThreadSpecificDataAddress(), 24UL);
|
|
|
|
thread_id++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-26 14:43:10 -05:00
|
|
|
} // namespace
|
|
|
|
} // namespace test
|
|
|
|
} // namespace crashpad
|