2014-08-12 10:26:40 -07: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.
|
|
|
|
|
|
|
|
#include "minidump/minidump_memory_writer.h"
|
|
|
|
|
2015-02-04 17:30:03 -08:00
|
|
|
#include <windows.h>
|
2014-08-12 10:26:40 -07:00
|
|
|
#include <dbghelp.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
#include "base/basictypes.h"
|
2014-10-30 17:15:49 -04:00
|
|
|
#include "base/strings/stringprintf.h"
|
2014-08-12 10:26:40 -07:00
|
|
|
#include "gtest/gtest.h"
|
2014-08-13 15:26:21 -07:00
|
|
|
#include "minidump/minidump_extensions.h"
|
2014-08-12 10:26:40 -07:00
|
|
|
#include "minidump/minidump_file_writer.h"
|
|
|
|
#include "minidump/minidump_stream_writer.h"
|
2014-10-20 12:11:14 -04:00
|
|
|
#include "minidump/test/minidump_file_writer_test_util.h"
|
|
|
|
#include "minidump/test/minidump_memory_writer_test_util.h"
|
2014-10-22 18:35:18 -04:00
|
|
|
#include "minidump/test/minidump_writable_test_util.h"
|
2014-10-30 17:15:49 -04:00
|
|
|
#include "snapshot/test/test_memory_snapshot.h"
|
2014-08-12 10:26:40 -07:00
|
|
|
#include "util/file/string_file_writer.h"
|
2014-10-30 17:15:49 -04:00
|
|
|
#include "util/stdlib/pointer_container.h"
|
2014-08-12 10:26:40 -07:00
|
|
|
|
2014-10-07 17:28:50 -04:00
|
|
|
namespace crashpad {
|
|
|
|
namespace test {
|
2014-08-12 10:26:40 -07:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
const MinidumpStreamType kBogusStreamType =
|
|
|
|
static_cast<MinidumpStreamType>(1234);
|
|
|
|
|
|
|
|
// expected_streams is the expected number of streams in the file. The memory
|
|
|
|
// list must be the last stream. If there is another stream, it must come first,
|
|
|
|
// have stream type kBogusStreamType, and have zero-length data.
|
|
|
|
void GetMemoryListStream(const std::string& file_contents,
|
|
|
|
const MINIDUMP_MEMORY_LIST** memory_list,
|
|
|
|
const uint32_t expected_streams) {
|
|
|
|
const size_t kDirectoryOffset = sizeof(MINIDUMP_HEADER);
|
|
|
|
const size_t kMemoryListStreamOffset =
|
|
|
|
kDirectoryOffset + expected_streams * sizeof(MINIDUMP_DIRECTORY);
|
|
|
|
const size_t kMemoryDescriptorsOffset =
|
|
|
|
kMemoryListStreamOffset + sizeof(MINIDUMP_MEMORY_LIST);
|
|
|
|
|
|
|
|
ASSERT_GE(file_contents.size(), kMemoryDescriptorsOffset);
|
|
|
|
|
2014-10-21 14:15:07 -04:00
|
|
|
const MINIDUMP_DIRECTORY* directory;
|
2014-08-12 10:26:40 -07:00
|
|
|
const MINIDUMP_HEADER* header =
|
2014-10-21 14:15:07 -04:00
|
|
|
MinidumpHeaderAtStart(file_contents, &directory);
|
2014-10-09 15:08:54 -04:00
|
|
|
ASSERT_NO_FATAL_FAILURE(VerifyMinidumpHeader(header, expected_streams, 0));
|
2014-10-21 14:15:07 -04:00
|
|
|
ASSERT_TRUE(directory);
|
2014-08-12 10:26:40 -07:00
|
|
|
|
2014-10-21 14:15:07 -04:00
|
|
|
size_t directory_index = 0;
|
2014-08-12 10:26:40 -07:00
|
|
|
if (expected_streams > 1) {
|
2014-10-21 14:15:07 -04:00
|
|
|
ASSERT_EQ(kBogusStreamType, directory[directory_index].StreamType);
|
|
|
|
ASSERT_EQ(0u, directory[directory_index].Location.DataSize);
|
|
|
|
ASSERT_EQ(kMemoryListStreamOffset, directory[directory_index].Location.Rva);
|
|
|
|
++directory_index;
|
2014-08-12 10:26:40 -07:00
|
|
|
}
|
|
|
|
|
2014-10-21 14:15:07 -04:00
|
|
|
ASSERT_EQ(kMinidumpStreamTypeMemoryList,
|
|
|
|
directory[directory_index].StreamType);
|
2014-10-22 18:35:18 -04:00
|
|
|
EXPECT_EQ(kMemoryListStreamOffset, directory[directory_index].Location.Rva);
|
2014-08-12 10:26:40 -07:00
|
|
|
|
2014-10-22 18:35:18 -04:00
|
|
|
*memory_list = MinidumpWritableAtLocationDescriptor<MINIDUMP_MEMORY_LIST>(
|
|
|
|
file_contents, directory[directory_index].Location);
|
|
|
|
ASSERT_TRUE(memory_list);
|
2014-08-12 10:26:40 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(MinidumpMemoryWriter, EmptyMemoryList) {
|
|
|
|
MinidumpFileWriter minidump_file_writer;
|
2014-10-27 15:01:39 -04:00
|
|
|
auto memory_list_writer = make_scoped_ptr(new MinidumpMemoryListWriter());
|
2014-08-12 10:26:40 -07:00
|
|
|
|
2014-10-27 15:01:39 -04:00
|
|
|
minidump_file_writer.AddStream(memory_list_writer.Pass());
|
2014-08-12 10:26:40 -07:00
|
|
|
|
|
|
|
StringFileWriter file_writer;
|
|
|
|
ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer));
|
|
|
|
|
|
|
|
ASSERT_EQ(sizeof(MINIDUMP_HEADER) + sizeof(MINIDUMP_DIRECTORY) +
|
|
|
|
sizeof(MINIDUMP_MEMORY_LIST),
|
|
|
|
file_writer.string().size());
|
|
|
|
|
2015-02-04 20:46:44 -08:00
|
|
|
const MINIDUMP_MEMORY_LIST* memory_list = nullptr;
|
2014-10-09 15:08:54 -04:00
|
|
|
ASSERT_NO_FATAL_FAILURE(
|
|
|
|
GetMemoryListStream(file_writer.string(), &memory_list, 1));
|
2014-08-12 10:26:40 -07:00
|
|
|
|
|
|
|
EXPECT_EQ(0u, memory_list->NumberOfMemoryRanges);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(MinidumpMemoryWriter, OneMemoryRegion) {
|
|
|
|
MinidumpFileWriter minidump_file_writer;
|
2014-10-27 15:01:39 -04:00
|
|
|
auto memory_list_writer = make_scoped_ptr(new MinidumpMemoryListWriter());
|
2014-08-12 10:26:40 -07:00
|
|
|
|
2014-08-13 15:27:33 -07:00
|
|
|
const uint64_t kBaseAddress = 0xfedcba9876543210;
|
2014-08-12 10:26:40 -07:00
|
|
|
const uint64_t kSize = 0x1000;
|
|
|
|
const uint8_t kValue = 'm';
|
|
|
|
|
2014-10-27 15:01:39 -04:00
|
|
|
auto memory_writer = make_scoped_ptr(
|
|
|
|
new TestMinidumpMemoryWriter(kBaseAddress, kSize, kValue));
|
|
|
|
memory_list_writer->AddMemory(memory_writer.Pass());
|
2014-08-12 10:26:40 -07:00
|
|
|
|
2014-10-27 15:01:39 -04:00
|
|
|
minidump_file_writer.AddStream(memory_list_writer.Pass());
|
2014-08-12 10:26:40 -07:00
|
|
|
|
|
|
|
StringFileWriter file_writer;
|
|
|
|
ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer));
|
|
|
|
|
2015-02-04 20:46:44 -08:00
|
|
|
const MINIDUMP_MEMORY_LIST* memory_list = nullptr;
|
2014-10-09 15:08:54 -04:00
|
|
|
ASSERT_NO_FATAL_FAILURE(
|
|
|
|
GetMemoryListStream(file_writer.string(), &memory_list, 1));
|
2014-08-12 10:26:40 -07:00
|
|
|
|
|
|
|
MINIDUMP_MEMORY_DESCRIPTOR expected;
|
|
|
|
expected.StartOfMemoryRange = kBaseAddress;
|
|
|
|
expected.Memory.DataSize = kSize;
|
|
|
|
expected.Memory.Rva =
|
|
|
|
sizeof(MINIDUMP_HEADER) + sizeof(MINIDUMP_DIRECTORY) +
|
|
|
|
sizeof(MINIDUMP_MEMORY_LIST) +
|
|
|
|
memory_list->NumberOfMemoryRanges * sizeof(MINIDUMP_MEMORY_DESCRIPTOR);
|
2014-10-07 17:58:43 -04:00
|
|
|
ExpectMinidumpMemoryDescriptorAndContents(&expected,
|
|
|
|
&memory_list->MemoryRanges[0],
|
|
|
|
file_writer.string(),
|
|
|
|
kValue,
|
|
|
|
true);
|
2014-08-12 10:26:40 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(MinidumpMemoryWriter, TwoMemoryRegions) {
|
|
|
|
MinidumpFileWriter minidump_file_writer;
|
2014-10-27 15:01:39 -04:00
|
|
|
auto memory_list_writer = make_scoped_ptr(new MinidumpMemoryListWriter());
|
2014-08-12 10:26:40 -07:00
|
|
|
|
2014-10-09 15:21:05 -04:00
|
|
|
const uint64_t kBaseAddress0 = 0xc0ffee;
|
|
|
|
const uint64_t kSize0 = 0x0100;
|
|
|
|
const uint8_t kValue0 = '6';
|
|
|
|
const uint64_t kBaseAddress1 = 0xfac00fac;
|
|
|
|
const uint64_t kSize1 = 0x0200;
|
|
|
|
const uint8_t kValue1 = '!';
|
|
|
|
|
2014-10-27 15:01:39 -04:00
|
|
|
auto memory_writer_0 = make_scoped_ptr(
|
|
|
|
new TestMinidumpMemoryWriter(kBaseAddress0, kSize0, kValue0));
|
|
|
|
memory_list_writer->AddMemory(memory_writer_0.Pass());
|
|
|
|
auto memory_writer_1 = make_scoped_ptr(
|
|
|
|
new TestMinidumpMemoryWriter(kBaseAddress1, kSize1, kValue1));
|
|
|
|
memory_list_writer->AddMemory(memory_writer_1.Pass());
|
2014-08-12 10:26:40 -07:00
|
|
|
|
2014-10-27 15:01:39 -04:00
|
|
|
minidump_file_writer.AddStream(memory_list_writer.Pass());
|
2014-08-12 10:26:40 -07:00
|
|
|
|
|
|
|
StringFileWriter file_writer;
|
|
|
|
ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer));
|
|
|
|
|
2015-02-04 20:46:44 -08:00
|
|
|
const MINIDUMP_MEMORY_LIST* memory_list = nullptr;
|
2014-10-09 15:08:54 -04:00
|
|
|
ASSERT_NO_FATAL_FAILURE(
|
|
|
|
GetMemoryListStream(file_writer.string(), &memory_list, 1));
|
2014-08-12 10:26:40 -07:00
|
|
|
|
|
|
|
EXPECT_EQ(2u, memory_list->NumberOfMemoryRanges);
|
|
|
|
|
|
|
|
MINIDUMP_MEMORY_DESCRIPTOR expected;
|
|
|
|
|
2014-08-13 15:26:21 -07:00
|
|
|
{
|
|
|
|
SCOPED_TRACE("region 0");
|
|
|
|
|
2014-10-09 15:21:05 -04:00
|
|
|
expected.StartOfMemoryRange = kBaseAddress0;
|
|
|
|
expected.Memory.DataSize = kSize0;
|
2014-08-13 15:26:21 -07:00
|
|
|
expected.Memory.Rva =
|
|
|
|
sizeof(MINIDUMP_HEADER) + sizeof(MINIDUMP_DIRECTORY) +
|
|
|
|
sizeof(MINIDUMP_MEMORY_LIST) +
|
|
|
|
memory_list->NumberOfMemoryRanges * sizeof(MINIDUMP_MEMORY_DESCRIPTOR);
|
2014-10-07 17:58:43 -04:00
|
|
|
ExpectMinidumpMemoryDescriptorAndContents(&expected,
|
|
|
|
&memory_list->MemoryRanges[0],
|
|
|
|
file_writer.string(),
|
2014-10-09 15:21:05 -04:00
|
|
|
kValue0,
|
2014-10-07 17:58:43 -04:00
|
|
|
false);
|
2014-08-13 15:26:21 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
SCOPED_TRACE("region 1");
|
|
|
|
|
2014-10-09 15:21:05 -04:00
|
|
|
expected.StartOfMemoryRange = kBaseAddress1;
|
|
|
|
expected.Memory.DataSize = kSize1;
|
2014-08-13 15:26:21 -07:00
|
|
|
expected.Memory.Rva = memory_list->MemoryRanges[0].Memory.Rva +
|
|
|
|
memory_list->MemoryRanges[0].Memory.DataSize;
|
2014-10-07 17:58:43 -04:00
|
|
|
ExpectMinidumpMemoryDescriptorAndContents(&expected,
|
|
|
|
&memory_list->MemoryRanges[1],
|
|
|
|
file_writer.string(),
|
2014-10-09 15:21:05 -04:00
|
|
|
kValue1,
|
2014-10-07 17:58:43 -04:00
|
|
|
true);
|
2014-08-13 15:26:21 -07:00
|
|
|
}
|
2014-08-12 10:26:40 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
class TestMemoryStream final : public internal::MinidumpStreamWriter {
|
|
|
|
public:
|
|
|
|
TestMemoryStream(uint64_t base_address, size_t size, uint8_t value)
|
|
|
|
: MinidumpStreamWriter(), memory_(base_address, size, value) {}
|
|
|
|
|
2014-10-27 15:01:39 -04:00
|
|
|
~TestMemoryStream() override {}
|
2014-08-12 10:26:40 -07:00
|
|
|
|
2014-10-27 15:01:39 -04:00
|
|
|
TestMinidumpMemoryWriter* memory() {
|
|
|
|
return &memory_;
|
|
|
|
}
|
2014-08-12 10:26:40 -07:00
|
|
|
|
|
|
|
// MinidumpStreamWriter:
|
2014-10-14 11:11:57 -04:00
|
|
|
MinidumpStreamType StreamType() const override {
|
2014-08-12 10:26:40 -07:00
|
|
|
return kBogusStreamType;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
// MinidumpWritable:
|
2014-10-14 11:11:57 -04:00
|
|
|
size_t SizeOfObject() override {
|
2014-08-12 10:26:40 -07:00
|
|
|
EXPECT_GE(state(), kStateFrozen);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-10-14 11:11:57 -04:00
|
|
|
std::vector<MinidumpWritable*> Children() override {
|
2014-08-12 10:26:40 -07:00
|
|
|
EXPECT_GE(state(), kStateFrozen);
|
|
|
|
std::vector<MinidumpWritable*> children(1, memory());
|
|
|
|
return children;
|
|
|
|
}
|
|
|
|
|
2014-10-14 11:11:57 -04:00
|
|
|
bool WriteObject(FileWriterInterface* file_writer) override {
|
2014-08-12 10:26:40 -07:00
|
|
|
EXPECT_EQ(kStateWritable, state());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2014-10-07 17:58:43 -04:00
|
|
|
TestMinidumpMemoryWriter memory_;
|
2014-08-12 10:26:40 -07:00
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(TestMemoryStream);
|
|
|
|
};
|
|
|
|
|
|
|
|
TEST(MinidumpMemoryWriter, ExtraMemory) {
|
|
|
|
// This tests MinidumpMemoryListWriter::AddExtraMemory(). That method adds
|
|
|
|
// a MinidumpMemoryWriter to the MinidumpMemoryListWriter without making the
|
|
|
|
// memory writer a child of the memory list writer.
|
|
|
|
MinidumpFileWriter minidump_file_writer;
|
|
|
|
|
2014-10-09 15:21:05 -04:00
|
|
|
const uint64_t kBaseAddress0 = 0x1000;
|
2014-10-30 17:15:49 -04:00
|
|
|
const size_t kSize0 = 0x0400;
|
2014-10-09 15:21:05 -04:00
|
|
|
const uint8_t kValue0 = '1';
|
2014-10-27 15:01:39 -04:00
|
|
|
auto test_memory_stream =
|
|
|
|
make_scoped_ptr(new TestMemoryStream(kBaseAddress0, kSize0, kValue0));
|
2014-08-12 10:26:40 -07:00
|
|
|
|
2014-10-27 15:01:39 -04:00
|
|
|
auto memory_list_writer = make_scoped_ptr(new MinidumpMemoryListWriter());
|
|
|
|
memory_list_writer->AddExtraMemory(test_memory_stream->memory());
|
2014-08-12 10:26:40 -07:00
|
|
|
|
2014-10-27 15:01:39 -04:00
|
|
|
minidump_file_writer.AddStream(test_memory_stream.Pass());
|
2014-08-12 10:26:40 -07:00
|
|
|
|
2014-10-09 15:21:05 -04:00
|
|
|
const uint64_t kBaseAddress1 = 0x2000;
|
2014-10-30 17:15:49 -04:00
|
|
|
const size_t kSize1 = 0x0400;
|
2014-10-09 15:21:05 -04:00
|
|
|
const uint8_t kValue1 = 'm';
|
2014-08-12 10:26:40 -07:00
|
|
|
|
2014-10-27 15:01:39 -04:00
|
|
|
auto memory_writer = make_scoped_ptr(
|
|
|
|
new TestMinidumpMemoryWriter(kBaseAddress1, kSize1, kValue1));
|
|
|
|
memory_list_writer->AddMemory(memory_writer.Pass());
|
2014-08-12 10:26:40 -07:00
|
|
|
|
2014-10-27 15:01:39 -04:00
|
|
|
minidump_file_writer.AddStream(memory_list_writer.Pass());
|
2014-08-12 10:26:40 -07:00
|
|
|
|
|
|
|
StringFileWriter file_writer;
|
|
|
|
ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer));
|
|
|
|
|
2015-02-04 20:46:44 -08:00
|
|
|
const MINIDUMP_MEMORY_LIST* memory_list = nullptr;
|
2014-10-09 15:08:54 -04:00
|
|
|
ASSERT_NO_FATAL_FAILURE(
|
|
|
|
GetMemoryListStream(file_writer.string(), &memory_list, 2));
|
2014-08-12 10:26:40 -07:00
|
|
|
|
|
|
|
EXPECT_EQ(2u, memory_list->NumberOfMemoryRanges);
|
|
|
|
|
|
|
|
MINIDUMP_MEMORY_DESCRIPTOR expected;
|
|
|
|
|
2014-08-13 15:26:21 -07:00
|
|
|
{
|
|
|
|
SCOPED_TRACE("region 0");
|
|
|
|
|
2014-10-09 15:21:05 -04:00
|
|
|
expected.StartOfMemoryRange = kBaseAddress0;
|
|
|
|
expected.Memory.DataSize = kSize0;
|
2014-08-13 15:26:21 -07:00
|
|
|
expected.Memory.Rva =
|
|
|
|
sizeof(MINIDUMP_HEADER) + 2 * sizeof(MINIDUMP_DIRECTORY) +
|
|
|
|
sizeof(MINIDUMP_MEMORY_LIST) +
|
|
|
|
memory_list->NumberOfMemoryRanges * sizeof(MINIDUMP_MEMORY_DESCRIPTOR);
|
2014-10-07 17:58:43 -04:00
|
|
|
ExpectMinidumpMemoryDescriptorAndContents(&expected,
|
|
|
|
&memory_list->MemoryRanges[0],
|
|
|
|
file_writer.string(),
|
2014-10-09 15:21:05 -04:00
|
|
|
kValue0,
|
2014-10-07 17:58:43 -04:00
|
|
|
false);
|
2014-08-13 15:26:21 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
SCOPED_TRACE("region 1");
|
|
|
|
|
2014-10-09 15:21:05 -04:00
|
|
|
expected.StartOfMemoryRange = kBaseAddress1;
|
|
|
|
expected.Memory.DataSize = kSize1;
|
2014-08-13 15:26:21 -07:00
|
|
|
expected.Memory.Rva = memory_list->MemoryRanges[0].Memory.Rva +
|
|
|
|
memory_list->MemoryRanges[0].Memory.DataSize;
|
2014-10-07 17:58:43 -04:00
|
|
|
ExpectMinidumpMemoryDescriptorAndContents(&expected,
|
|
|
|
&memory_list->MemoryRanges[1],
|
|
|
|
file_writer.string(),
|
2014-10-09 15:21:05 -04:00
|
|
|
kValue1,
|
2014-10-07 17:58:43 -04:00
|
|
|
true);
|
2014-08-13 15:26:21 -07:00
|
|
|
}
|
2014-08-12 10:26:40 -07:00
|
|
|
}
|
|
|
|
|
2014-10-30 17:15:49 -04:00
|
|
|
TEST(MinidumpMemoryWriter, AddFromSnapshot) {
|
|
|
|
MINIDUMP_MEMORY_DESCRIPTOR expect_memory_descriptors[3] = {};
|
|
|
|
uint8_t values[arraysize(expect_memory_descriptors)] = {};
|
|
|
|
|
|
|
|
expect_memory_descriptors[0].StartOfMemoryRange = 0;
|
|
|
|
expect_memory_descriptors[0].Memory.DataSize = 0x1000;
|
|
|
|
values[0] = 0x01;
|
|
|
|
|
|
|
|
expect_memory_descriptors[1].StartOfMemoryRange = 0x1000;
|
|
|
|
expect_memory_descriptors[1].Memory.DataSize = 0x2000;
|
|
|
|
values[1] = 0xf4;
|
|
|
|
|
|
|
|
expect_memory_descriptors[2].StartOfMemoryRange = 0x7654321000000000;
|
|
|
|
expect_memory_descriptors[2].Memory.DataSize = 0x800;
|
|
|
|
values[2] = 0xa9;
|
|
|
|
|
|
|
|
PointerVector<TestMemorySnapshot> memory_snapshots_owner;
|
|
|
|
std::vector<const MemorySnapshot*> memory_snapshots;
|
|
|
|
for (size_t index = 0;
|
|
|
|
index < arraysize(expect_memory_descriptors);
|
|
|
|
++index) {
|
|
|
|
TestMemorySnapshot* memory_snapshot = new TestMemorySnapshot();
|
|
|
|
memory_snapshots_owner.push_back(memory_snapshot);
|
|
|
|
memory_snapshot->SetAddress(
|
|
|
|
expect_memory_descriptors[index].StartOfMemoryRange);
|
|
|
|
memory_snapshot->SetSize(expect_memory_descriptors[index].Memory.DataSize);
|
|
|
|
memory_snapshot->SetValue(values[index]);
|
|
|
|
memory_snapshots.push_back(memory_snapshot);
|
|
|
|
}
|
|
|
|
|
|
|
|
auto memory_list_writer = make_scoped_ptr(new MinidumpMemoryListWriter());
|
|
|
|
memory_list_writer->AddFromSnapshot(memory_snapshots);
|
|
|
|
|
|
|
|
MinidumpFileWriter minidump_file_writer;
|
|
|
|
minidump_file_writer.AddStream(memory_list_writer.Pass());
|
|
|
|
|
|
|
|
StringFileWriter file_writer;
|
|
|
|
ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer));
|
|
|
|
|
2015-02-04 20:46:44 -08:00
|
|
|
const MINIDUMP_MEMORY_LIST* memory_list = nullptr;
|
2014-10-30 17:15:49 -04:00
|
|
|
ASSERT_NO_FATAL_FAILURE(
|
|
|
|
GetMemoryListStream(file_writer.string(), &memory_list, 1));
|
|
|
|
|
|
|
|
ASSERT_EQ(3u, memory_list->NumberOfMemoryRanges);
|
|
|
|
|
|
|
|
for (size_t index = 0; index < memory_list->NumberOfMemoryRanges; ++index) {
|
|
|
|
SCOPED_TRACE(base::StringPrintf("index %zu", index));
|
|
|
|
ExpectMinidumpMemoryDescriptorAndContents(
|
|
|
|
&expect_memory_descriptors[index],
|
|
|
|
&memory_list->MemoryRanges[index],
|
|
|
|
file_writer.string(),
|
|
|
|
values[index],
|
|
|
|
index == memory_list->NumberOfMemoryRanges - 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-12 10:26:40 -07:00
|
|
|
} // namespace
|
2014-10-07 17:28:50 -04:00
|
|
|
} // namespace test
|
|
|
|
} // namespace crashpad
|