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