1""" 2Test the 'memory region' command. 3""" 4 5 6 7import lldb 8from lldbsuite.test.decorators import * 9from lldbsuite.test.lldbtest import * 10from lldbsuite.test import lldbutil 11 12 13class MemoryCommandRegion(TestBase): 14 15 mydir = TestBase.compute_mydir(__file__) 16 17 NO_DEBUG_INFO_TESTCASE = True 18 19 def setUp(self): 20 TestBase.setUp(self) 21 # Find the line number to break for main.c. 22 self.line = line_number( 23 'main.cpp', 24 '// Run here before printing memory regions') 25 26 def test(self): 27 self.build() 28 29 # Set breakpoint in main and run 30 self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET) 31 lldbutil.run_break_set_by_file_and_line( 32 self, "main.cpp", self.line, num_expected_locations=-1, loc_exact=True) 33 34 self.runCmd("run", RUN_SUCCEEDED) 35 36 interp = self.dbg.GetCommandInterpreter() 37 result = lldb.SBCommandReturnObject() 38 39 # Test that the first 'memory region' command prints the usage. 40 interp.HandleCommand("memory region", result) 41 self.assertFalse(result.Succeeded()) 42 self.assertRegexpMatches(result.GetError(), "Usage: memory region ADDR") 43 44 # Now let's print the memory region starting at 0 which should always work. 45 interp.HandleCommand("memory region 0x0", result) 46 self.assertTrue(result.Succeeded()) 47 self.assertRegexpMatches(result.GetOutput(), "\\[0x0+-") 48 49 # Keep printing memory regions until we printed all of them. 50 while True: 51 interp.HandleCommand("memory region", result) 52 if not result.Succeeded(): 53 break 54 55 # Now that we reached the end, 'memory region' should again print the usage. 56 interp.HandleCommand("memory region", result) 57 self.assertFalse(result.Succeeded()) 58 self.assertRegexpMatches(result.GetError(), "Usage: memory region ADDR") 59