================ @@ -0,0 +1,142 @@ +""" +Test saving a mini dump, from yamilized examples. +""" + +import os +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class ProcessSaveCoreMinidumpTestCaseYaml(TestBase): + def process_from_yaml(self, yaml_file): + minidump_path = self.getBuildArtifact(os.path.basename(yaml_file) + ".dmp") + self.yaml2obj(yaml_file, minidump_path) + self.target = self.dbg.CreateTarget(None) + self.process = self.target.LoadCore(minidump_path) + return self.process + + def test_saving_sub_memory_range(self): + """ + Validate we can save a Minidump for a subsection of a memory range. + I.E. + If our memory range is 0x1000-0x2000 nd the user specifies 0x1200-0x1800 + we should still capture 0x1200 to 0x1800 + """ + yaml = "minidump_mem64.yaml" + proc = self.process_from_yaml(yaml) + new_minidump_path = self.getBuildArtifact(__name__ + ".dmp") + options = lldb.SBSaveCoreOptions() + options.SetOutputFile(lldb.SBFileSpec(new_minidump_path)) + options.SetPluginName("minidump") + options.SetStyle(lldb.eSaveCoreCustomOnly) + + size = 8 + begin = 0x2000 + end = begin + size + custom_range = lldb.SBMemoryRegionInfo("", begin, end, 3, True, False) + options.AddMemoryRegionToSave(custom_range) + + error = proc.SaveCore(options) + self.assertTrue(error.Success(), error.GetCString()) + core_target = self.dbg.CreateTarget(None) + core_process = core_target.LoadCore(new_minidump_path) + + error = lldb.SBError() + core_process.ReadMemory(begin, size, error) + self.assertTrue(error.Success(), error.GetCString()) + + # Try to read 1 byte past the end + core_process.ReadMemory(end + 1, 1, error) + self.assertTrue(error.Fail(), error.GetCString()) + + def test_saving_super_memory_range(self): + """ + Validate we can save a Minidump for a subsection of a memory range. + I.E. + If our memory range is 0x1000-0x2000 nd the user specifies 0x0800-0x2800 + we should still capture 0x1000-0x2000 + """ + yaml = "minidump_mem64.yaml" + proc = self.process_from_yaml(yaml) + new_minidump_path = self.getBuildArtifact(__name__ + ".dmp") + options = lldb.SBSaveCoreOptions() + options.SetOutputFile(lldb.SBFileSpec(new_minidump_path)) + options.SetPluginName("minidump") + options.SetStyle(lldb.eSaveCoreCustomOnly) + + size = 0x100 + begin = 0x1000 + end = begin + size + custom_range = lldb.SBMemoryRegionInfo("", begin - 16, end + 16, 3, True, False) + options.AddMemoryRegionToSave(custom_range) + + error = proc.SaveCore(options) + self.assertTrue(error.Success(), error.GetCString()) + core_target = self.dbg.CreateTarget(None) + core_process = core_target.LoadCore(new_minidump_path) + + error = lldb.SBError() + core_process.ReadMemory(begin, size, error) + self.assertTrue(error.Success(), error.GetCString()) + + def test_region_that_goes_out_of_bounds(self): + """ + Validate we can save a Minidump for a custom region + that includes an end that enters an invalid (---) page. + """ + yaml = "minidump_mem64.yaml" + proc = self.process_from_yaml(yaml) + new_minidump_path = self.getBuildArtifact(__name__ + ".dmp") + options = lldb.SBSaveCoreOptions() + options.SetOutputFile(lldb.SBFileSpec(new_minidump_path)) + options.SetPluginName("minidump") + options.SetStyle(lldb.eSaveCoreCustomOnly) + + size = 0x120 + begin = 0x1000 + end = begin + size + custom_range = lldb.SBMemoryRegionInfo("", begin, end, 3, True, False) + options.AddMemoryRegionToSave(custom_range) + + error = proc.SaveCore(options) + self.assertTrue(error.Success(), error.GetCString()) + core_target = self.dbg.CreateTarget(None) + core_process = core_target.LoadCore(new_minidump_path) + + error = lldb.SBError() + core_process.ReadMemory(begin, 0x00000020, error) ---------------- dmpots wrote:
Nit: 0x20 would be easier to read. https://github.com/llvm/llvm-project/pull/138206 _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits