|
13 | 13 | class ProcessSaveCoreMinidump64bTestCase(TestBase): |
14 | 14 | def verify_minidump( |
15 | 15 | self, |
16 | | - core_proc, |
17 | | - live_proc, |
18 | 16 | options, |
19 | 17 | ): |
20 | 18 | """Verify that the minidump is the same byte for byte as the live process.""" |
21 | | - # Get the memory regions we saved off in this core, we can't compare to the core |
22 | | - # because we pull from /proc/pid/maps, so even ranges that don't get mapped in will show up |
23 | | - # as ranges in the minidump. |
24 | | - # |
25 | | - # Instead, we have an API that returns to us the number of regions we planned to save from the live process |
26 | | - # and we compare those |
27 | | - memory_regions_to_compare = options.GetMemoryRegionsToSave() |
28 | | - |
29 | | - for region in memory_regions_to_compare: |
30 | | - start_addr = region.GetRegionBase() |
31 | | - end_addr = region.GetRegionEnd() |
32 | | - actual_process_read_error = lldb.SBError() |
33 | | - actual = live_proc.ReadMemory( |
34 | | - start_addr, end_addr - start_addr, actual_process_read_error |
35 | | - ) |
36 | | - expected_process_read_error = lldb.SBError() |
37 | | - expected = core_proc.ReadMemory( |
38 | | - start_addr, end_addr - start_addr, expected_process_read_error |
39 | | - ) |
40 | | - |
41 | | - # Both processes could fail to read a given memory region, so if they both pass |
42 | | - # compare, then we'll fail them if the core differs from the live process. |
43 | | - if ( |
44 | | - actual_process_read_error.Success() |
45 | | - and expected_process_read_error.Success() |
46 | | - ): |
47 | | - self.assertEqual( |
48 | | - actual, expected, "Bytes differ between live process and core" |
| 19 | + self.build() |
| 20 | + exe = self.getBuildArtifact("a.out") |
| 21 | + target = self.dbg.CreateTarget(exe) |
| 22 | + core_target = None |
| 23 | + live_proc = target.LaunchSimple( |
| 24 | + None, None, self.get_process_working_directory() |
| 25 | + ) |
| 26 | + try: |
| 27 | + self.assertState(live_proc.GetState(), lldb.eStateStopped) |
| 28 | + error = live_proc.SaveCore(options) |
| 29 | + self.assertTrue(error.Success(), error.GetCString()) |
| 30 | + core_target = self.dbg.CreateTarget(None) |
| 31 | + core_proc = target.LoadCore(options.GetOutputFile().fullpath) |
| 32 | + # Get the memory regions we saved off in this core, we can't compare to the core |
| 33 | + # because we pull from /proc/pid/maps, so even ranges that don't get mapped in will show up |
| 34 | + # as ranges in the minidump. |
| 35 | + # |
| 36 | + # Instead, we have an API that returns to us the number of regions we planned to save from the live process |
| 37 | + # and we compare those |
| 38 | + memory_regions_to_compare = options.GetMemoryRegionsToSave() |
| 39 | + |
| 40 | + for region in memory_regions_to_compare: |
| 41 | + start_addr = region.GetRegionBase() |
| 42 | + end_addr = region.GetRegionEnd() |
| 43 | + actual_process_read_error = lldb.SBError() |
| 44 | + actual = live_proc.ReadMemory( |
| 45 | + start_addr, end_addr - start_addr, actual_process_read_error |
| 46 | + ) |
| 47 | + expected_process_read_error = lldb.SBError() |
| 48 | + expected = core_proc.ReadMemory( |
| 49 | + start_addr, end_addr - start_addr, expected_process_read_error |
49 | 50 | ) |
50 | 51 |
|
51 | | - # Now we check if the error is the same, error isn't abnormal but they should fail for the same reason |
52 | | - self.assertTrue( |
53 | | - ( |
| 52 | + # Both processes could fail to read a given memory region, so if they both pass |
| 53 | + # compare, then we'll fail them if the core differs from the live process. |
| 54 | + if ( |
54 | 55 | actual_process_read_error.Success() |
55 | 56 | and expected_process_read_error.Success() |
| 57 | + ): |
| 58 | + self.assertEqual( |
| 59 | + actual, expected, "Bytes differ between live process and core" |
| 60 | + ) |
| 61 | + |
| 62 | + # Now we check if the error is the same, error isn't abnormal but they should fail for the same reason |
| 63 | + self.assertTrue( |
| 64 | + ( |
| 65 | + actual_process_read_error.Success() |
| 66 | + and expected_process_read_error.Success() |
| 67 | + ) |
| 68 | + or ( |
| 69 | + actual_process_read_error.Fail() |
| 70 | + and expected_process_read_error.Fail() |
| 71 | + ), |
| 72 | + f"Address range {hex(start_addr)} - {hex(end_addr)} failed to read from live process and core for different reasons", |
56 | 73 | ) |
57 | | - or ( |
58 | | - actual_process_read_error.Fail() |
59 | | - and expected_process_read_error.Fail() |
60 | | - ), |
61 | | - f"Address range {hex(start_addr)} - {hex(end_addr)} failed to read from live process and core for different reasons", |
62 | | - ) |
| 74 | + finally: |
| 75 | + self.assertTrue(self.dbg.DeleteTarget(target)) |
| 76 | + if core_target is not None: |
| 77 | + self.assertTrue(self.dbg.DeleteTarget(core_target)) |
63 | 78 |
|
64 | 79 | @skipUnlessArch("x86_64") |
65 | 80 | @skipUnlessPlatform(["linux"]) |
66 | 81 | def test_minidump_save_style_full(self): |
67 | 82 | """Test that a full minidump is the same byte for byte.""" |
68 | | - |
69 | | - self.build() |
70 | | - exe = self.getBuildArtifact("a.out") |
71 | 83 | minidump_path = self.getBuildArtifact("minidump_full_force64b.dmp") |
72 | | - |
73 | 84 | try: |
74 | | - target = self.dbg.CreateTarget(exe) |
75 | | - live_process = target.LaunchSimple( |
76 | | - None, None, self.get_process_working_directory() |
77 | | - ) |
78 | | - self.assertState(live_process.GetState(), lldb.eStateStopped) |
79 | 85 | options = lldb.SBSaveCoreOptions() |
80 | | - |
81 | 86 | options.SetOutputFile(lldb.SBFileSpec(minidump_path)) |
82 | 87 | options.SetStyle(lldb.eSaveCoreFull) |
83 | 88 | options.SetPluginName("minidump") |
84 | | - options.SetProcess(live_process) |
85 | | - |
86 | | - error = live_process.SaveCore(options) |
87 | | - self.assertTrue(error.Success(), error.GetCString()) |
88 | | - |
89 | | - target = self.dbg.CreateTarget(None) |
90 | | - core_proc = target.LoadCore(minidump_path) |
91 | | - |
92 | | - self.verify_minidump(core_proc, live_process, options) |
| 89 | + self.verify_minidump(options) |
93 | 90 | finally: |
94 | | - self.assertTrue(self.dbg.DeleteTarget(target)) |
95 | 91 | if os.path.isfile(minidump_path): |
96 | 92 | os.unlink(minidump_path) |
97 | 93 |
|
98 | 94 | @skipUnlessArch("x86_64") |
99 | 95 | @skipUnlessPlatform(["linux"]) |
100 | 96 | def test_minidump_save_style_mixed_memory(self): |
101 | 97 | """Test that a mixed memory minidump is the same byte for byte.""" |
102 | | - |
103 | | - self.build() |
104 | | - exe = self.getBuildArtifact("a.out") |
105 | 98 | minidump_path = self.getBuildArtifact("minidump_mixed_force64b.dmp") |
106 | | - |
107 | 99 | try: |
108 | | - target = self.dbg.CreateTarget(exe) |
109 | | - live_process = target.LaunchSimple( |
110 | | - None, None, self.get_process_working_directory() |
111 | | - ) |
112 | | - self.assertState(live_process.GetState(), lldb.eStateStopped) |
113 | 100 | options = lldb.SBSaveCoreOptions() |
114 | | - |
115 | 101 | options.SetOutputFile(lldb.SBFileSpec(minidump_path)) |
116 | 102 | options.SetStyle(lldb.eSaveCoreDirtyOnly) |
117 | 103 | options.SetPluginName("minidump") |
118 | | - options.SetProcess(live_process) |
119 | | - |
120 | | - error = live_process.SaveCore(options) |
121 | | - self.assertTrue(error.Success(), error.GetCString()) |
122 | | - |
123 | | - target = self.dbg.CreateTarget(None) |
124 | | - core_proc = target.LoadCore(minidump_path) |
125 | | - |
126 | | - self.verify_minidump(core_proc, live_process, options) |
| 104 | + self.verify_minidump(options) |
127 | 105 | finally: |
128 | | - self.assertTrue(self.dbg.DeleteTarget(target)) |
129 | 106 | if os.path.isfile(minidump_path): |
130 | 107 | os.unlink(minidump_path) |
0 commit comments