| OLD | NEW |
| 1 // Copyright 2014 The Crashpad Authors. All rights reserved. | 1 // Copyright 2014 The Crashpad Authors. All rights reserved. |
| 2 // | 2 // |
| 3 // Licensed under the Apache License, Version 2.0 (the "License"); | 3 // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 // you may not use this file except in compliance with the License. | 4 // you may not use this file except in compliance with the License. |
| 5 // You may obtain a copy of the License at | 5 // You may obtain a copy of the License at |
| 6 // | 6 // |
| 7 // http://www.apache.org/licenses/LICENSE-2.0 | 7 // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 // | 8 // |
| 9 // Unless required by applicable law or agreed to in writing, software | 9 // Unless required by applicable law or agreed to in writing, software |
| 10 // distributed under the License is distributed on an "AS IS" BASIS, | 10 // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 // See the License for the specific language governing permissions and | 12 // See the License for the specific language governing permissions and |
| 13 // limitations under the License. | 13 // limitations under the License. |
| 14 | 14 |
| 15 #include "minidump/minidump_memory_writer.h" | 15 #include "minidump/minidump_memory_writer.h" |
| 16 | 16 |
| 17 #include <windows.h> | 17 #include <windows.h> |
| 18 #include <dbghelp.h> | 18 #include <dbghelp.h> |
| 19 #include <stdint.h> | 19 #include <stdint.h> |
| 20 | 20 |
| 21 #include <utility> |
| 22 |
| 21 #include "base/basictypes.h" | 23 #include "base/basictypes.h" |
| 22 #include "base/format_macros.h" | 24 #include "base/format_macros.h" |
| 23 #include "base/strings/stringprintf.h" | 25 #include "base/strings/stringprintf.h" |
| 24 #include "gtest/gtest.h" | 26 #include "gtest/gtest.h" |
| 25 #include "minidump/minidump_extensions.h" | 27 #include "minidump/minidump_extensions.h" |
| 26 #include "minidump/minidump_file_writer.h" | 28 #include "minidump/minidump_file_writer.h" |
| 27 #include "minidump/minidump_stream_writer.h" | 29 #include "minidump/minidump_stream_writer.h" |
| 28 #include "minidump/test/minidump_file_writer_test_util.h" | 30 #include "minidump/test/minidump_file_writer_test_util.h" |
| 29 #include "minidump/test/minidump_memory_writer_test_util.h" | 31 #include "minidump/test/minidump_memory_writer_test_util.h" |
| 30 #include "minidump/test/minidump_writable_test_util.h" | 32 #include "minidump/test/minidump_writable_test_util.h" |
| 31 #include "snapshot/test/test_memory_snapshot.h" | 33 #include "snapshot/test/test_memory_snapshot.h" |
| 32 #include "util/file/string_file.h" | 34 #include "util/file/string_file.h" |
| 33 #include "util/stdlib/move.h" | |
| 34 #include "util/stdlib/pointer_container.h" | 35 #include "util/stdlib/pointer_container.h" |
| 35 | 36 |
| 36 namespace crashpad { | 37 namespace crashpad { |
| 37 namespace test { | 38 namespace test { |
| 38 namespace { | 39 namespace { |
| 39 | 40 |
| 40 const MinidumpStreamType kBogusStreamType = | 41 const MinidumpStreamType kBogusStreamType = |
| 41 static_cast<MinidumpStreamType>(1234); | 42 static_cast<MinidumpStreamType>(1234); |
| 42 | 43 |
| 43 // expected_streams is the expected number of streams in the file. The memory | 44 // expected_streams is the expected number of streams in the file. The memory |
| (...skipping 30 matching lines...) Expand all Loading... |
| 74 | 75 |
| 75 *memory_list = MinidumpWritableAtLocationDescriptor<MINIDUMP_MEMORY_LIST>( | 76 *memory_list = MinidumpWritableAtLocationDescriptor<MINIDUMP_MEMORY_LIST>( |
| 76 file_contents, directory[directory_index].Location); | 77 file_contents, directory[directory_index].Location); |
| 77 ASSERT_TRUE(memory_list); | 78 ASSERT_TRUE(memory_list); |
| 78 } | 79 } |
| 79 | 80 |
| 80 TEST(MinidumpMemoryWriter, EmptyMemoryList) { | 81 TEST(MinidumpMemoryWriter, EmptyMemoryList) { |
| 81 MinidumpFileWriter minidump_file_writer; | 82 MinidumpFileWriter minidump_file_writer; |
| 82 auto memory_list_writer = make_scoped_ptr(new MinidumpMemoryListWriter()); | 83 auto memory_list_writer = make_scoped_ptr(new MinidumpMemoryListWriter()); |
| 83 | 84 |
| 84 minidump_file_writer.AddStream(crashpad::move(memory_list_writer)); | 85 minidump_file_writer.AddStream(std::move(memory_list_writer)); |
| 85 | 86 |
| 86 StringFile string_file; | 87 StringFile string_file; |
| 87 ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file)); | 88 ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file)); |
| 88 | 89 |
| 89 ASSERT_EQ(sizeof(MINIDUMP_HEADER) + sizeof(MINIDUMP_DIRECTORY) + | 90 ASSERT_EQ(sizeof(MINIDUMP_HEADER) + sizeof(MINIDUMP_DIRECTORY) + |
| 90 sizeof(MINIDUMP_MEMORY_LIST), | 91 sizeof(MINIDUMP_MEMORY_LIST), |
| 91 string_file.string().size()); | 92 string_file.string().size()); |
| 92 | 93 |
| 93 const MINIDUMP_MEMORY_LIST* memory_list = nullptr; | 94 const MINIDUMP_MEMORY_LIST* memory_list = nullptr; |
| 94 ASSERT_NO_FATAL_FAILURE( | 95 ASSERT_NO_FATAL_FAILURE( |
| 95 GetMemoryListStream(string_file.string(), &memory_list, 1)); | 96 GetMemoryListStream(string_file.string(), &memory_list, 1)); |
| 96 | 97 |
| 97 EXPECT_EQ(0u, memory_list->NumberOfMemoryRanges); | 98 EXPECT_EQ(0u, memory_list->NumberOfMemoryRanges); |
| 98 } | 99 } |
| 99 | 100 |
| 100 TEST(MinidumpMemoryWriter, OneMemoryRegion) { | 101 TEST(MinidumpMemoryWriter, OneMemoryRegion) { |
| 101 MinidumpFileWriter minidump_file_writer; | 102 MinidumpFileWriter minidump_file_writer; |
| 102 auto memory_list_writer = make_scoped_ptr(new MinidumpMemoryListWriter()); | 103 auto memory_list_writer = make_scoped_ptr(new MinidumpMemoryListWriter()); |
| 103 | 104 |
| 104 const uint64_t kBaseAddress = 0xfedcba9876543210; | 105 const uint64_t kBaseAddress = 0xfedcba9876543210; |
| 105 const uint64_t kSize = 0x1000; | 106 const uint64_t kSize = 0x1000; |
| 106 const uint8_t kValue = 'm'; | 107 const uint8_t kValue = 'm'; |
| 107 | 108 |
| 108 auto memory_writer = make_scoped_ptr( | 109 auto memory_writer = make_scoped_ptr( |
| 109 new TestMinidumpMemoryWriter(kBaseAddress, kSize, kValue)); | 110 new TestMinidumpMemoryWriter(kBaseAddress, kSize, kValue)); |
| 110 memory_list_writer->AddMemory(crashpad::move(memory_writer)); | 111 memory_list_writer->AddMemory(std::move(memory_writer)); |
| 111 | 112 |
| 112 minidump_file_writer.AddStream(crashpad::move(memory_list_writer)); | 113 minidump_file_writer.AddStream(std::move(memory_list_writer)); |
| 113 | 114 |
| 114 StringFile string_file; | 115 StringFile string_file; |
| 115 ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file)); | 116 ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file)); |
| 116 | 117 |
| 117 const MINIDUMP_MEMORY_LIST* memory_list = nullptr; | 118 const MINIDUMP_MEMORY_LIST* memory_list = nullptr; |
| 118 ASSERT_NO_FATAL_FAILURE( | 119 ASSERT_NO_FATAL_FAILURE( |
| 119 GetMemoryListStream(string_file.string(), &memory_list, 1)); | 120 GetMemoryListStream(string_file.string(), &memory_list, 1)); |
| 120 | 121 |
| 121 MINIDUMP_MEMORY_DESCRIPTOR expected; | 122 MINIDUMP_MEMORY_DESCRIPTOR expected; |
| 122 expected.StartOfMemoryRange = kBaseAddress; | 123 expected.StartOfMemoryRange = kBaseAddress; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 138 | 139 |
| 139 const uint64_t kBaseAddress0 = 0xc0ffee; | 140 const uint64_t kBaseAddress0 = 0xc0ffee; |
| 140 const uint64_t kSize0 = 0x0100; | 141 const uint64_t kSize0 = 0x0100; |
| 141 const uint8_t kValue0 = '6'; | 142 const uint8_t kValue0 = '6'; |
| 142 const uint64_t kBaseAddress1 = 0xfac00fac; | 143 const uint64_t kBaseAddress1 = 0xfac00fac; |
| 143 const uint64_t kSize1 = 0x0200; | 144 const uint64_t kSize1 = 0x0200; |
| 144 const uint8_t kValue1 = '!'; | 145 const uint8_t kValue1 = '!'; |
| 145 | 146 |
| 146 auto memory_writer_0 = make_scoped_ptr( | 147 auto memory_writer_0 = make_scoped_ptr( |
| 147 new TestMinidumpMemoryWriter(kBaseAddress0, kSize0, kValue0)); | 148 new TestMinidumpMemoryWriter(kBaseAddress0, kSize0, kValue0)); |
| 148 memory_list_writer->AddMemory(crashpad::move(memory_writer_0)); | 149 memory_list_writer->AddMemory(std::move(memory_writer_0)); |
| 149 auto memory_writer_1 = make_scoped_ptr( | 150 auto memory_writer_1 = make_scoped_ptr( |
| 150 new TestMinidumpMemoryWriter(kBaseAddress1, kSize1, kValue1)); | 151 new TestMinidumpMemoryWriter(kBaseAddress1, kSize1, kValue1)); |
| 151 memory_list_writer->AddMemory(crashpad::move(memory_writer_1)); | 152 memory_list_writer->AddMemory(std::move(memory_writer_1)); |
| 152 | 153 |
| 153 minidump_file_writer.AddStream(crashpad::move(memory_list_writer)); | 154 minidump_file_writer.AddStream(std::move(memory_list_writer)); |
| 154 | 155 |
| 155 StringFile string_file; | 156 StringFile string_file; |
| 156 ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file)); | 157 ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file)); |
| 157 | 158 |
| 158 const MINIDUMP_MEMORY_LIST* memory_list = nullptr; | 159 const MINIDUMP_MEMORY_LIST* memory_list = nullptr; |
| 159 ASSERT_NO_FATAL_FAILURE( | 160 ASSERT_NO_FATAL_FAILURE( |
| 160 GetMemoryListStream(string_file.string(), &memory_list, 1)); | 161 GetMemoryListStream(string_file.string(), &memory_list, 1)); |
| 161 | 162 |
| 162 EXPECT_EQ(2u, memory_list->NumberOfMemoryRanges); | 163 EXPECT_EQ(2u, memory_list->NumberOfMemoryRanges); |
| 163 | 164 |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 242 | 243 |
| 243 const uint64_t kBaseAddress0 = 0x1000; | 244 const uint64_t kBaseAddress0 = 0x1000; |
| 244 const size_t kSize0 = 0x0400; | 245 const size_t kSize0 = 0x0400; |
| 245 const uint8_t kValue0 = '1'; | 246 const uint8_t kValue0 = '1'; |
| 246 auto test_memory_stream = | 247 auto test_memory_stream = |
| 247 make_scoped_ptr(new TestMemoryStream(kBaseAddress0, kSize0, kValue0)); | 248 make_scoped_ptr(new TestMemoryStream(kBaseAddress0, kSize0, kValue0)); |
| 248 | 249 |
| 249 auto memory_list_writer = make_scoped_ptr(new MinidumpMemoryListWriter()); | 250 auto memory_list_writer = make_scoped_ptr(new MinidumpMemoryListWriter()); |
| 250 memory_list_writer->AddExtraMemory(test_memory_stream->memory()); | 251 memory_list_writer->AddExtraMemory(test_memory_stream->memory()); |
| 251 | 252 |
| 252 minidump_file_writer.AddStream(crashpad::move(test_memory_stream)); | 253 minidump_file_writer.AddStream(std::move(test_memory_stream)); |
| 253 | 254 |
| 254 const uint64_t kBaseAddress1 = 0x2000; | 255 const uint64_t kBaseAddress1 = 0x2000; |
| 255 const size_t kSize1 = 0x0400; | 256 const size_t kSize1 = 0x0400; |
| 256 const uint8_t kValue1 = 'm'; | 257 const uint8_t kValue1 = 'm'; |
| 257 | 258 |
| 258 auto memory_writer = make_scoped_ptr( | 259 auto memory_writer = make_scoped_ptr( |
| 259 new TestMinidumpMemoryWriter(kBaseAddress1, kSize1, kValue1)); | 260 new TestMinidumpMemoryWriter(kBaseAddress1, kSize1, kValue1)); |
| 260 memory_list_writer->AddMemory(crashpad::move(memory_writer)); | 261 memory_list_writer->AddMemory(std::move(memory_writer)); |
| 261 | 262 |
| 262 minidump_file_writer.AddStream(crashpad::move(memory_list_writer)); | 263 minidump_file_writer.AddStream(std::move(memory_list_writer)); |
| 263 | 264 |
| 264 StringFile string_file; | 265 StringFile string_file; |
| 265 ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file)); | 266 ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file)); |
| 266 | 267 |
| 267 const MINIDUMP_MEMORY_LIST* memory_list = nullptr; | 268 const MINIDUMP_MEMORY_LIST* memory_list = nullptr; |
| 268 ASSERT_NO_FATAL_FAILURE( | 269 ASSERT_NO_FATAL_FAILURE( |
| 269 GetMemoryListStream(string_file.string(), &memory_list, 2)); | 270 GetMemoryListStream(string_file.string(), &memory_list, 2)); |
| 270 | 271 |
| 271 EXPECT_EQ(2u, memory_list->NumberOfMemoryRanges); | 272 EXPECT_EQ(2u, memory_list->NumberOfMemoryRanges); |
| 272 | 273 |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 330 expect_memory_descriptors[index].StartOfMemoryRange); | 331 expect_memory_descriptors[index].StartOfMemoryRange); |
| 331 memory_snapshot->SetSize(expect_memory_descriptors[index].Memory.DataSize); | 332 memory_snapshot->SetSize(expect_memory_descriptors[index].Memory.DataSize); |
| 332 memory_snapshot->SetValue(values[index]); | 333 memory_snapshot->SetValue(values[index]); |
| 333 memory_snapshots.push_back(memory_snapshot); | 334 memory_snapshots.push_back(memory_snapshot); |
| 334 } | 335 } |
| 335 | 336 |
| 336 auto memory_list_writer = make_scoped_ptr(new MinidumpMemoryListWriter()); | 337 auto memory_list_writer = make_scoped_ptr(new MinidumpMemoryListWriter()); |
| 337 memory_list_writer->AddFromSnapshot(memory_snapshots); | 338 memory_list_writer->AddFromSnapshot(memory_snapshots); |
| 338 | 339 |
| 339 MinidumpFileWriter minidump_file_writer; | 340 MinidumpFileWriter minidump_file_writer; |
| 340 minidump_file_writer.AddStream(crashpad::move(memory_list_writer)); | 341 minidump_file_writer.AddStream(std::move(memory_list_writer)); |
| 341 | 342 |
| 342 StringFile string_file; | 343 StringFile string_file; |
| 343 ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file)); | 344 ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file)); |
| 344 | 345 |
| 345 const MINIDUMP_MEMORY_LIST* memory_list = nullptr; | 346 const MINIDUMP_MEMORY_LIST* memory_list = nullptr; |
| 346 ASSERT_NO_FATAL_FAILURE( | 347 ASSERT_NO_FATAL_FAILURE( |
| 347 GetMemoryListStream(string_file.string(), &memory_list, 1)); | 348 GetMemoryListStream(string_file.string(), &memory_list, 1)); |
| 348 | 349 |
| 349 ASSERT_EQ(3u, memory_list->NumberOfMemoryRanges); | 350 ASSERT_EQ(3u, memory_list->NumberOfMemoryRanges); |
| 350 | 351 |
| 351 for (size_t index = 0; index < memory_list->NumberOfMemoryRanges; ++index) { | 352 for (size_t index = 0; index < memory_list->NumberOfMemoryRanges; ++index) { |
| 352 SCOPED_TRACE(base::StringPrintf("index %" PRIuS, index)); | 353 SCOPED_TRACE(base::StringPrintf("index %" PRIuS, index)); |
| 353 ExpectMinidumpMemoryDescriptorAndContents( | 354 ExpectMinidumpMemoryDescriptorAndContents( |
| 354 &expect_memory_descriptors[index], | 355 &expect_memory_descriptors[index], |
| 355 &memory_list->MemoryRanges[index], | 356 &memory_list->MemoryRanges[index], |
| 356 string_file.string(), | 357 string_file.string(), |
| 357 values[index], | 358 values[index], |
| 358 index == memory_list->NumberOfMemoryRanges - 1); | 359 index == memory_list->NumberOfMemoryRanges - 1); |
| 359 } | 360 } |
| 360 } | 361 } |
| 361 | 362 |
| 362 } // namespace | 363 } // namespace |
| 363 } // namespace test | 364 } // namespace test |
| 364 } // namespace crashpad | 365 } // namespace crashpad |
| OLD | NEW |