1""" 2Test the 'memory find' command. 3""" 4 5 6import lldb 7from lldbsuite.test.lldbtest import * 8import lldbsuite.test.lldbutil as lldbutil 9from lldbsuite.test.decorators import * 10 11 12class MemoryFindTestCase(TestBase): 13 def setUp(self): 14 # Call super's setUp(). 15 TestBase.setUp(self) 16 # Find the line number to break inside main(). 17 self.line = line_number("main.cpp", "// break here") 18 19 def test_memory_find(self): 20 """Test the 'memory find' command.""" 21 self.build() 22 exe = self.getBuildArtifact("a.out") 23 self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) 24 25 # Break in main() after the variables are assigned values. 26 lldbutil.run_break_set_by_file_and_line( 27 self, "main.cpp", self.line, num_expected_locations=1, loc_exact=True 28 ) 29 30 self.runCmd("run", RUN_SUCCEEDED) 31 32 # The stop reason of the thread should be breakpoint. 33 self.expect( 34 "thread list", 35 STOPPED_DUE_TO_BREAKPOINT, 36 substrs=["stopped", "stop reason = breakpoint"], 37 ) 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( 46 'memory find -s "" `stringdata` `stringdata+16`', 47 error=True, 48 substrs=["error: search string must have non-zero length."], 49 ) 50 51 self.expect( 52 'memory find -s "in const" `stringdata` `stringdata+(int)strlen(stringdata)`', 53 substrs=["data found at location: 0x", "69 6e 20 63", "in const"], 54 ) 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 63 self.expect( 64 'memory find -e "(uint8_t)0x22" `&bytedata[0]` `&bytedata[15]`', 65 substrs=["data found at location: 0x", "22 33 44 55 66"], 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 73 self.expect( 74 'memory find -s "nothere" `stringdata` `stringdata+5`', 75 substrs=["data not found within the range."], 76 ) 77 78 self.expect( 79 'memory find -s "nothere" `stringdata` `stringdata+10`', 80 substrs=["data not found within the range."], 81 ) 82