| 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, |
| (...skipping 596 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 607 nullptr, | 607 nullptr, |
| 608 0, | 608 0, |
| 609 false)); | 609 false)); |
| 610 } | 610 } |
| 611 } | 611 } |
| 612 | 612 |
| 613 void InitializeTestModuleSnapshotFromMinidumpModule( | 613 void InitializeTestModuleSnapshotFromMinidumpModule( |
| 614 TestModuleSnapshot* module_snapshot, | 614 TestModuleSnapshot* module_snapshot, |
| 615 const MINIDUMP_MODULE& minidump_module, | 615 const MINIDUMP_MODULE& minidump_module, |
| 616 const std::string& name, | 616 const std::string& name, |
| 617 const std::string& pdb_name, |
| 617 const crashpad::UUID& uuid, | 618 const crashpad::UUID& uuid, |
| 618 uint32_t age) { | 619 uint32_t age) { |
| 619 module_snapshot->SetName(name); | 620 module_snapshot->SetName(name); |
| 620 | 621 |
| 621 module_snapshot->SetAddressAndSize(minidump_module.BaseOfImage, | 622 module_snapshot->SetAddressAndSize(minidump_module.BaseOfImage, |
| 622 minidump_module.SizeOfImage); | 623 minidump_module.SizeOfImage); |
| 623 module_snapshot->SetTimestamp(minidump_module.TimeDateStamp); | 624 module_snapshot->SetTimestamp(minidump_module.TimeDateStamp); |
| 624 module_snapshot->SetFileVersion( | 625 module_snapshot->SetFileVersion( |
| 625 minidump_module.VersionInfo.dwFileVersionMS >> 16, | 626 minidump_module.VersionInfo.dwFileVersionMS >> 16, |
| 626 minidump_module.VersionInfo.dwFileVersionMS & 0xffff, | 627 minidump_module.VersionInfo.dwFileVersionMS & 0xffff, |
| (...skipping 13 matching lines...) Expand all Loading... |
| 640 case VFT_DLL: | 641 case VFT_DLL: |
| 641 module_type = ModuleSnapshot::kModuleTypeSharedLibrary; | 642 module_type = ModuleSnapshot::kModuleTypeSharedLibrary; |
| 642 break; | 643 break; |
| 643 default: | 644 default: |
| 644 module_type = ModuleSnapshot::kModuleTypeUnknown; | 645 module_type = ModuleSnapshot::kModuleTypeUnknown; |
| 645 break; | 646 break; |
| 646 } | 647 } |
| 647 module_snapshot->SetModuleType(module_type); | 648 module_snapshot->SetModuleType(module_type); |
| 648 | 649 |
| 649 module_snapshot->SetUUIDAndAge(uuid, age); | 650 module_snapshot->SetUUIDAndAge(uuid, age); |
| 651 module_snapshot->SetDebugFileName(pdb_name); |
| 650 } | 652 } |
| 651 | 653 |
| 652 TEST(MinidumpModuleWriter, InitializeFromSnapshot) { | 654 TEST(MinidumpModuleWriter, InitializeFromSnapshot) { |
| 653 MINIDUMP_MODULE expect_modules[3] = {}; | 655 MINIDUMP_MODULE expect_modules[3] = {}; |
| 654 const char* module_paths[arraysize(expect_modules)] = {}; | 656 const char* module_paths[arraysize(expect_modules)] = {}; |
| 655 const char* module_names[arraysize(expect_modules)] = {}; | 657 const char* module_names[arraysize(expect_modules)] = {}; |
| 658 const char* module_pdbs[arraysize(expect_modules)] = {}; |
| 656 UUID uuids[arraysize(expect_modules)] = {}; | 659 UUID uuids[arraysize(expect_modules)] = {}; |
| 657 uint32_t ages[arraysize(expect_modules)] = {}; | 660 uint32_t ages[arraysize(expect_modules)] = {}; |
| 658 | 661 |
| 659 expect_modules[0].BaseOfImage = 0x100101000; | 662 expect_modules[0].BaseOfImage = 0x100101000; |
| 660 expect_modules[0].SizeOfImage = 0xf000; | 663 expect_modules[0].SizeOfImage = 0xf000; |
| 661 expect_modules[0].TimeDateStamp = 0x01234567; | 664 expect_modules[0].TimeDateStamp = 0x01234567; |
| 662 expect_modules[0].VersionInfo.dwFileVersionMS = 0x00010002; | 665 expect_modules[0].VersionInfo.dwFileVersionMS = 0x00010002; |
| 663 expect_modules[0].VersionInfo.dwFileVersionLS = 0x00030004; | 666 expect_modules[0].VersionInfo.dwFileVersionLS = 0x00030004; |
| 664 expect_modules[0].VersionInfo.dwProductVersionMS = 0x00050006; | 667 expect_modules[0].VersionInfo.dwProductVersionMS = 0x00050006; |
| 665 expect_modules[0].VersionInfo.dwProductVersionLS = 0x00070008; | 668 expect_modules[0].VersionInfo.dwProductVersionLS = 0x00070008; |
| 666 expect_modules[0].VersionInfo.dwFileType = VFT_APP; | 669 expect_modules[0].VersionInfo.dwFileType = VFT_APP; |
| 667 module_paths[0] = "/usr/bin/true"; | 670 module_paths[0] = "/usr/bin/true"; |
| 668 module_names[0] = "true"; | 671 module_names[0] = "true"; |
| 672 module_pdbs[0] = "true"; |
| 669 const uint8_t kUUIDBytes0[16] = | 673 const uint8_t kUUIDBytes0[16] = |
| 670 {0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, | 674 {0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, |
| 671 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff}; | 675 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff}; |
| 672 uuids[0].InitializeFromBytes(kUUIDBytes0); | 676 uuids[0].InitializeFromBytes(kUUIDBytes0); |
| 673 ages[0] = 10; | 677 ages[0] = 10; |
| 674 | 678 |
| 675 expect_modules[1].BaseOfImage = 0x200202000; | 679 expect_modules[1].BaseOfImage = 0x200202000; |
| 676 expect_modules[1].SizeOfImage = 0x1e1000; | 680 expect_modules[1].SizeOfImage = 0x1e1000; |
| 677 expect_modules[1].TimeDateStamp = 0x89abcdef; | 681 expect_modules[1].TimeDateStamp = 0x89abcdef; |
| 678 expect_modules[1].VersionInfo.dwFileVersionMS = 0x0009000a; | 682 expect_modules[1].VersionInfo.dwFileVersionMS = 0x0009000a; |
| 679 expect_modules[1].VersionInfo.dwFileVersionLS = 0x000b000c; | 683 expect_modules[1].VersionInfo.dwFileVersionLS = 0x000b000c; |
| 680 expect_modules[1].VersionInfo.dwProductVersionMS = 0x000d000e; | 684 expect_modules[1].VersionInfo.dwProductVersionMS = 0x000d000e; |
| 681 expect_modules[1].VersionInfo.dwProductVersionLS = 0x000f0000; | 685 expect_modules[1].VersionInfo.dwProductVersionLS = 0x000f0000; |
| 682 expect_modules[1].VersionInfo.dwFileType = VFT_DLL; | 686 expect_modules[1].VersionInfo.dwFileType = VFT_DLL; |
| 683 module_paths[1] = "/usr/lib/libSystem.B.dylib"; | 687 module_paths[1] = "/usr/lib/libSystem.B.dylib"; |
| 684 module_names[1] = "libSystem.B.dylib"; | 688 module_names[1] = "libSystem.B.dylib"; |
| 689 module_pdbs[1] = "libSystem.B.dylib.pdb"; |
| 685 const uint8_t kUUIDBytes1[16] = | 690 const uint8_t kUUIDBytes1[16] = |
| 686 {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, | 691 {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, |
| 687 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}; | 692 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}; |
| 688 uuids[1].InitializeFromBytes(kUUIDBytes1); | 693 uuids[1].InitializeFromBytes(kUUIDBytes1); |
| 689 ages[1] = 20; | 694 ages[1] = 20; |
| 690 | 695 |
| 691 expect_modules[2].BaseOfImage = 0x300303000; | 696 expect_modules[2].BaseOfImage = 0x300303000; |
| 692 expect_modules[2].SizeOfImage = 0x2d000; | 697 expect_modules[2].SizeOfImage = 0x2d000; |
| 693 expect_modules[2].TimeDateStamp = 0x76543210; | 698 expect_modules[2].TimeDateStamp = 0x76543210; |
| 694 expect_modules[2].VersionInfo.dwFileVersionMS = 0x11112222; | 699 expect_modules[2].VersionInfo.dwFileVersionMS = 0x11112222; |
| 695 expect_modules[2].VersionInfo.dwFileVersionLS = 0x33334444; | 700 expect_modules[2].VersionInfo.dwFileVersionLS = 0x33334444; |
| 696 expect_modules[2].VersionInfo.dwProductVersionMS = 0x9999aaaa; | 701 expect_modules[2].VersionInfo.dwProductVersionMS = 0x9999aaaa; |
| 697 expect_modules[2].VersionInfo.dwProductVersionLS = 0xbbbbcccc; | 702 expect_modules[2].VersionInfo.dwProductVersionLS = 0xbbbbcccc; |
| 698 expect_modules[2].VersionInfo.dwFileType = VFT_UNKNOWN; | 703 expect_modules[2].VersionInfo.dwFileType = VFT_UNKNOWN; |
| 699 module_paths[2] = "/usr/lib/dyld"; | 704 module_paths[2] = "/usr/lib/dyld"; |
| 700 module_names[2] = "dyld"; | 705 module_names[2] = "dyld"; |
| 706 module_pdbs[2] = "/usr/lib/dyld.pdb"; |
| 701 const uint8_t kUUIDBytes2[16] = | 707 const uint8_t kUUIDBytes2[16] = |
| 702 {0xff, 0xfe, 0xfd, 0xfc, 0xfb, 0xfa, 0xf9, 0xf8, | 708 {0xff, 0xfe, 0xfd, 0xfc, 0xfb, 0xfa, 0xf9, 0xf8, |
| 703 0xf7, 0xf6, 0xf5, 0xf4, 0xf3, 0xf2, 0xf1, 0xf0}; | 709 0xf7, 0xf6, 0xf5, 0xf4, 0xf3, 0xf2, 0xf1, 0xf0}; |
| 704 uuids[2].InitializeFromBytes(kUUIDBytes2); | 710 uuids[2].InitializeFromBytes(kUUIDBytes2); |
| 705 ages[2] = 30; | 711 ages[2] = 30; |
| 706 | 712 |
| 707 PointerVector<TestModuleSnapshot> module_snapshots_owner; | 713 PointerVector<TestModuleSnapshot> module_snapshots_owner; |
| 708 std::vector<const ModuleSnapshot*> module_snapshots; | 714 std::vector<const ModuleSnapshot*> module_snapshots; |
| 709 for (size_t index = 0; index < arraysize(expect_modules); ++index) { | 715 for (size_t index = 0; index < arraysize(expect_modules); ++index) { |
| 710 TestModuleSnapshot* module_snapshot = new TestModuleSnapshot(); | 716 TestModuleSnapshot* module_snapshot = new TestModuleSnapshot(); |
| 711 module_snapshots_owner.push_back(module_snapshot); | 717 module_snapshots_owner.push_back(module_snapshot); |
| 712 InitializeTestModuleSnapshotFromMinidumpModule(module_snapshot, | 718 InitializeTestModuleSnapshotFromMinidumpModule(module_snapshot, |
| 713 expect_modules[index], | 719 expect_modules[index], |
| 714 module_paths[index], | 720 module_paths[index], |
| 721 module_pdbs[index], |
| 715 uuids[index], | 722 uuids[index], |
| 716 ages[index]); | 723 ages[index]); |
| 717 module_snapshots.push_back(module_snapshot); | 724 module_snapshots.push_back(module_snapshot); |
| 718 } | 725 } |
| 719 | 726 |
| 720 auto module_list_writer = make_scoped_ptr(new MinidumpModuleListWriter()); | 727 auto module_list_writer = make_scoped_ptr(new MinidumpModuleListWriter()); |
| 721 module_list_writer->InitializeFromSnapshot(module_snapshots); | 728 module_list_writer->InitializeFromSnapshot(module_snapshots); |
| 722 | 729 |
| 723 MinidumpFileWriter minidump_file_writer; | 730 MinidumpFileWriter minidump_file_writer; |
| 724 minidump_file_writer.AddStream(module_list_writer.Pass()); | 731 minidump_file_writer.AddStream(module_list_writer.Pass()); |
| 725 | 732 |
| 726 StringFile string_file; | 733 StringFile string_file; |
| 727 ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file)); | 734 ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file)); |
| 728 | 735 |
| 729 const MINIDUMP_MODULE_LIST* module_list = nullptr; | 736 const MINIDUMP_MODULE_LIST* module_list = nullptr; |
| 730 ASSERT_NO_FATAL_FAILURE( | 737 ASSERT_NO_FATAL_FAILURE( |
| 731 GetModuleListStream(string_file.string(), &module_list)); | 738 GetModuleListStream(string_file.string(), &module_list)); |
| 732 | 739 |
| 733 ASSERT_EQ(3u, module_list->NumberOfModules); | 740 ASSERT_EQ(3u, module_list->NumberOfModules); |
| 734 | 741 |
| 735 for (size_t index = 0; index < module_list->NumberOfModules; ++index) { | 742 for (size_t index = 0; index < module_list->NumberOfModules; ++index) { |
| 736 SCOPED_TRACE(base::StringPrintf("index %" PRIuS, index)); | 743 SCOPED_TRACE(base::StringPrintf("index %" PRIuS, index)); |
| 737 ASSERT_NO_FATAL_FAILURE(ExpectModule(&expect_modules[index], | 744 ASSERT_NO_FATAL_FAILURE(ExpectModule(&expect_modules[index], |
| 738 &module_list->Modules[index], | 745 &module_list->Modules[index], |
| 739 string_file.string(), | 746 string_file.string(), |
| 740 module_paths[index], | 747 module_paths[index], |
| 741 module_names[index], | 748 module_pdbs[index], |
| 742 &uuids[index], | 749 &uuids[index], |
| 743 0, | 750 0, |
| 744 ages[index], | 751 ages[index], |
| 745 nullptr, | 752 nullptr, |
| 746 0, | 753 0, |
| 747 false)); | 754 false)); |
| 748 } | 755 } |
| 749 } | 756 } |
| 750 | 757 |
| 751 TEST(MinidumpModuleWriterDeathTest, NoModuleName) { | 758 TEST(MinidumpModuleWriterDeathTest, NoModuleName) { |
| 752 MinidumpFileWriter minidump_file_writer; | 759 MinidumpFileWriter minidump_file_writer; |
| 753 auto module_list_writer = make_scoped_ptr(new MinidumpModuleListWriter()); | 760 auto module_list_writer = make_scoped_ptr(new MinidumpModuleListWriter()); |
| 754 auto module_writer = make_scoped_ptr(new MinidumpModuleWriter()); | 761 auto module_writer = make_scoped_ptr(new MinidumpModuleWriter()); |
| 755 module_list_writer->AddModule(module_writer.Pass()); | 762 module_list_writer->AddModule(module_writer.Pass()); |
| 756 minidump_file_writer.AddStream(module_list_writer.Pass()); | 763 minidump_file_writer.AddStream(module_list_writer.Pass()); |
| 757 | 764 |
| 758 StringFile string_file; | 765 StringFile string_file; |
| 759 ASSERT_DEATH_CHECK(minidump_file_writer.WriteEverything(&string_file), | 766 ASSERT_DEATH_CHECK(minidump_file_writer.WriteEverything(&string_file), |
| 760 "name_"); | 767 "name_"); |
| 761 } | 768 } |
| 762 | 769 |
| 763 } // namespace | 770 } // namespace |
| 764 } // namespace test | 771 } // namespace test |
| 765 } // namespace crashpad | 772 } // namespace crashpad |
| OLD | NEW |