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 @expectedFailureAll(oslist=["freebsd"]) 27 def test(self): 28 self.build() 29 30 # Set breakpoint in main and run 31 self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET) 32 lldbutil.run_break_set_by_file_and_line( 33 self, "main.cpp", self.line, num_expected_locations=-1, loc_exact=True) 34 35 self.runCmd("run", RUN_SUCCEEDED) 36 37 interp = self.dbg.GetCommandInterpreter() 38 result = lldb.SBCommandReturnObject() 39 40 # Test that the first 'memory region' command prints the usage. 41 interp.HandleCommand("memory region", result) 42 self.assertFalse(result.Succeeded()) 43 self.assertRegexpMatches(result.GetError(), "Usage: memory region ADDR") 44 45 # Test that when the address fails to parse, we show an error and do not continue 46 interp.HandleCommand("memory region not_an_address", result) 47 self.assertFalse(result.Succeeded()) 48 self.assertEqual(result.GetError(), 49 "error: invalid address argument \"not_an_address\": address expression \"not_an_address\" evaluation failed\n") 50 51 # Now let's print the memory region starting at 0 which should always work. 52 interp.HandleCommand("memory region 0x0", result) 53 self.assertTrue(result.Succeeded()) 54 self.assertRegexpMatches(result.GetOutput(), "\\[0x0+-") 55 56 # Keep printing memory regions until we printed all of them. 57 while True: 58 interp.HandleCommand("memory region", result) 59 if not result.Succeeded(): 60 break 61 62 # Now that we reached the end, 'memory region' should again print the usage. 63 interp.HandleCommand("memory region", result) 64 self.assertFalse(result.Succeeded()) 65 self.assertRegexpMatches(result.GetError(), "Usage: memory region ADDR") 66