|
| 1 | +""" |
| 2 | +Test saving a mini dump, from yamilized examples. |
| 3 | +""" |
| 4 | + |
| 5 | +import os |
| 6 | +import lldb |
| 7 | +from lldbsuite.test.decorators import * |
| 8 | +from lldbsuite.test.lldbtest import * |
| 9 | +from lldbsuite.test import lldbutil |
| 10 | + |
| 11 | +class ProcessSaveCoreMinidumpTestCaseYaml(TestBase): |
| 12 | + def process_from_yaml(self, yaml_file): |
| 13 | + minidump_path = self.getBuildArtifact(os.path.basename(yaml_file) + ".dmp") |
| 14 | + self.yaml2obj(yaml_file, minidump_path) |
| 15 | + self.target = self.dbg.CreateTarget(None) |
| 16 | + self.process = self.target.LoadCore(minidump_path) |
| 17 | + return self.process |
| 18 | + |
| 19 | + def test_saving_sub_memory_range(self): |
| 20 | + """ |
| 21 | + Validate we can save a Minidump for a subsection of a memory range. |
| 22 | + I.E. |
| 23 | + If our memory range is 0x1000-0x2000 nd the user specifies 0x1200-0x1800 |
| 24 | + we should still capture 0x1200 to 0x1800 |
| 25 | + """ |
| 26 | + yaml = "minidump_mem64.yaml" |
| 27 | + proc = self.process_from_yaml(yaml) |
| 28 | + new_minidump_path = self.getBuildArtifact(__name__ + ".dmp") |
| 29 | + options = lldb.SBSaveCoreOptions() |
| 30 | + options.SetOutputFile(lldb.SBFileSpec(new_minidump_path)) |
| 31 | + options.SetPluginName("minidump") |
| 32 | + options.SetStyle(lldb.eSaveCoreCustomOnly) |
| 33 | + |
| 34 | + size = 8 |
| 35 | + begin = 0x7FFF12A84030 |
| 36 | + end = begin + size |
| 37 | + custom_range = lldb.SBMemoryRegionInfo("", begin, end, 3, True, False) |
| 38 | + options.AddMemoryRegionToSave(custom_range) |
| 39 | + |
| 40 | + error = proc.SaveCore(options) |
| 41 | + self.assertTrue(error.Success(), error.GetCString()) |
| 42 | + core_target = self.dbg.CreateTarget(None) |
| 43 | + core_process = core_target.LoadCore(new_minidump_path) |
| 44 | + |
| 45 | + error = lldb.SBError() |
| 46 | + core_process.ReadMemory(begin, size, error) |
| 47 | + self.assertTrue(error.Success(), error.GetCString()) |
| 48 | + |
| 49 | + # Try to read 1 byte past the end |
| 50 | + core_process.ReadMemory(end + 1, 1, error) |
| 51 | + self.assertTrue(error.Fail(), error.GetCString()) |
| 52 | + |
| 53 | + def test_saving_super_memory_range(self): |
| 54 | + """ |
| 55 | + Validate we can save a Minidump for a subsection of a memory range. |
| 56 | + I.E. |
| 57 | + If our memory range is 0x1000-0x2000 nd the user specifies 0x0800-0x2800 |
| 58 | + we should still capture 0x1000-0x2000 |
| 59 | + """ |
| 60 | + yaml = "minidump_mem64.yaml" |
| 61 | + proc = self.process_from_yaml(yaml) |
| 62 | + new_minidump_path = self.getBuildArtifact(__name__ + ".dmp") |
| 63 | + options = lldb.SBSaveCoreOptions() |
| 64 | + options.SetOutputFile(lldb.SBFileSpec(new_minidump_path)) |
| 65 | + options.SetPluginName("minidump") |
| 66 | + options.SetStyle(lldb.eSaveCoreCustomOnly) |
| 67 | + |
| 68 | + size = 0x2FD0 |
| 69 | + begin = 0x7FFF12A84030 |
| 70 | + end = begin + size |
| 71 | + custom_range = lldb.SBMemoryRegionInfo("", begin - 16, end + 16, 3, True, False) |
| 72 | + options.AddMemoryRegionToSave(custom_range) |
| 73 | + |
| 74 | + error = proc.SaveCore(options) |
| 75 | + self.assertTrue(error.Success(), error.GetCString()) |
| 76 | + core_target = self.dbg.CreateTarget(None) |
| 77 | + core_process = core_target.LoadCore(new_minidump_path) |
| 78 | + |
| 79 | + error = lldb.SBError() |
| 80 | + core_process.ReadMemory(begin, size, error) |
| 81 | + self.assertTrue(error.Success(), error.GetCString()) |
| 82 | + |
| 83 | + |
| 84 | + def test_region_that_goes_out_of_bounds(self): |
| 85 | + """ |
| 86 | + Validate we can save a Minidump for a custom region |
| 87 | + that includes an end that enters an invalid (---) page. |
| 88 | + """ |
| 89 | + yaml = "minidump_mem64.yaml" |
| 90 | + proc = self.process_from_yaml(yaml) |
| 91 | + new_minidump_path = self.getBuildArtifact(__name__ + ".dmp") |
| 92 | + options = lldb.SBSaveCoreOptions() |
| 93 | + options.SetOutputFile(lldb.SBFileSpec(new_minidump_path)) |
| 94 | + options.SetPluginName("minidump") |
| 95 | + options.SetStyle(lldb.eSaveCoreCustomOnly) |
| 96 | + |
| 97 | + size = 1024 |
| 98 | + begin = 0x00007fff12a8ffff |
| 99 | + end = begin + size |
| 100 | + custom_range = lldb.SBMemoryRegionInfo("", begin, end, 3, True, False) |
| 101 | + options.AddMemoryRegionToSave(custom_range) |
| 102 | + |
| 103 | + error = proc.SaveCore(options) |
| 104 | + self.assertTrue(error.Success(), error.GetCString()) |
| 105 | + core_target = self.dbg.CreateTarget(None) |
| 106 | + core_process = core_target.LoadCore(new_minidump_path) |
| 107 | + |
| 108 | + error = lldb.SBError() |
| 109 | + core_process.ReadMemory(begin, 0x00000020, error) |
| 110 | + self.assertTrue(error.Success(), error.GetCString()) |
| 111 | + |
| 112 | + # Whole region should be unavailable |
| 113 | + core_process.ReadMemory(end, 1, error) |
| 114 | + self.assertTrue(error.Fail(), error.GetCString()) |
| 115 | + |
| 116 | + def test_region_that_starts_out_of_bounds(self): |
| 117 | + """ |
| 118 | + Validate we can save a Minidump for a custom region |
| 119 | + that includes a start in a (---) page but ends in a valid page. |
| 120 | + """ |
| 121 | + yaml = "minidump_mem64.yaml" |
| 122 | + proc = self.process_from_yaml(yaml) |
| 123 | + new_minidump_path = self.getBuildArtifact(__name__ + ".dmp") |
| 124 | + options = lldb.SBSaveCoreOptions() |
| 125 | + options.SetOutputFile(lldb.SBFileSpec(new_minidump_path)) |
| 126 | + options.SetPluginName("minidump") |
| 127 | + options.SetStyle(lldb.eSaveCoreCustomOnly) |
| 128 | + |
| 129 | + size = 0x00000020 |
| 130 | + begin = 0x00007fff12a8ffff |
| 131 | + end = begin + size |
| 132 | + custom_range = lldb.SBMemoryRegionInfo("", begin - 16, end, 3, True, False) |
| 133 | + options.AddMemoryRegionToSave(custom_range) |
| 134 | + |
| 135 | + error = proc.SaveCore(options) |
| 136 | + self.assertTrue(error.Success(), error.GetCString()) |
| 137 | + core_target = self.dbg.CreateTarget(None) |
| 138 | + core_process = core_target.LoadCore(new_minidump_path) |
| 139 | + |
| 140 | + error = lldb.SBError() |
| 141 | + core_process.ReadMemory(begin, 0x00000020, error) |
| 142 | + self.assertTrue(error.Success(), error.GetCString()) |
0 commit comments