1""" 2Test the 'memory find' command. 3""" 4 5 6 7import lldb 8from lldbsuite.test.lldbtest import * 9import lldbsuite.test.lldbutil as lldbutil 10from lldbsuite.test.decorators import * 11 12 13class MemoryFindTestCase(TestBase): 14 15 mydir = TestBase.compute_mydir(__file__) 16 17 def setUp(self): 18 # Call super's setUp(). 19 TestBase.setUp(self) 20 # Find the line number to break inside main(). 21 self.line = line_number('main.cpp', '// break here') 22 23 def test_memory_find(self): 24 """Test the 'memory find' command.""" 25 self.build() 26 exe = self.getBuildArtifact("a.out") 27 self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) 28 29 # Break in main() after the variables are assigned values. 30 lldbutil.run_break_set_by_file_and_line( 31 self, "main.cpp", self.line, num_expected_locations=1, loc_exact=True) 32 33 self.runCmd("run", RUN_SUCCEEDED) 34 35 # The stop reason of the thread should be breakpoint. 36 self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, 37 substrs=['stopped', 'stop reason = breakpoint']) 38 39 # The breakpoint should have a hit count of 1. 40 lldbutil.check_breakpoint(self, bpno = 1, expected_hit_count = 1) 41 42 # Test the memory find commands. 43 44 # Empty search string should be handled. 45 self.expect('memory find -s "" `stringdata` `stringdata+16`', 46 error=True, 47 substrs=["error: search string must have non-zero length."]) 48 49 self.expect( 50 'memory find -s "in const" `stringdata` `stringdata+(int)strlen(stringdata)`', 51 substrs=[ 52 'data found at location: 0x', 53 '69 6e 20 63', 54 'in const']) 55 56 # Invalid expr is an error. 57 self.expect( 58 'memory find -e "not_a_symbol" `&bytedata[0]` `&bytedata[15]`', 59 error=True, 60 substrs=["error: expression evaluation failed. pass a string instead"]) 61 62 self.expect( 63 'memory find -e "(uint8_t)0x22" `&bytedata[0]` `&bytedata[15]`', 64 substrs=[ 65 'data found at location: 0x', 66 '22 33 44 55 66']) 67 68 self.expect( 69 'memory find -e "(uint8_t)0x22" `&bytedata[0]` `&bytedata[2]`', 70 substrs=['data not found within the range.']) 71 72 self.expect('memory find -s "nothere" `stringdata` `stringdata+5`', 73 substrs=['data not found within the range.']) 74 75 self.expect('memory find -s "nothere" `stringdata` `stringdata+10`', 76 substrs=['data not found within the range.']) 77