brintos

brintos / llvm-project-archived public Read only

0
0
Text · 4.3 KiB · a06b0d9 Raw
136 lines · python
1"""2Test the 'memory find' command.3"""4 5 6import lldb7from lldbsuite.test.lldbtest import *8import lldbsuite.test.lldbutil as lldbutil9from 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=True28        )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            substrs=[60                "Expression evaluation failed:",61                "use of undeclared identifier 'not_a_symbol'",62            ],63            error=True,64        )65 66        self.expect(67            'memory find -e "" `&bytedata[0]` `&bytedata[2]`',68            substrs=[69                "Expression evaluation failed:",70                "No result returned from expression. Exit status: 1",71            ],72            error=True,73        )74 75        # Valid expressions/strings76        self.expect(77            'memory find -e "(uint8_t)0x22" `&bytedata[0]` `&bytedata[15]`',78            substrs=["data found at location: 0x", "22 33 44 55 66"],79        )80 81        self.expect(82            'memory find -e "(uint8_t)0x22" `&bytedata[0]` `&bytedata[2]`',83            substrs=["data not found within the range."],84        )85 86        self.expect(87            'memory find -s "nothere" `stringdata` `stringdata+5`',88            substrs=["data not found within the range."],89        )90 91        self.expect(92            'memory find -s "nothere" `stringdata` `stringdata+10`',93            substrs=["data not found within the range."],94        )95 96        # Expression results with unsupported result types.97        self.expect(98            'memory find -e "ThreeBytes{}" `&bytedata[0]` `&bytedata[2]`',99            substrs=[100                "Only expressions resulting in 1, 2, 4, or 8-byte-sized values are supported"101            ],102            error=True,103        )104 105        self.expect(106            'memory find -e "FiveBytes{}" `&bytedata[0]` `&bytedata[2]`',107            substrs=[108                "Only expressions resulting in 1, 2, 4, or 8-byte-sized values are supported"109            ],110            error=True,111        )112 113        self.expect(114            'memory find -e "SixBytes{}" `&bytedata[0]` `&bytedata[2]`',115            substrs=[116                "Only expressions resulting in 1, 2, 4, or 8-byte-sized values are supported"117            ],118            error=True,119        )120 121        self.expect(122            'memory find -e "SevenBytes{}" `&bytedata[0]` `&bytedata[2]`',123            substrs=[124                "Only expressions resulting in 1, 2, 4, or 8-byte-sized values are supported"125            ],126            error=True,127        )128 129        self.expect(130            'memory find -e "NineBytes{}" `&bytedata[0]` `&bytedata[2]`',131            substrs=[132                "Only expressions resulting in 1, 2, 4, or 8-byte-sized values are supported"133            ],134            error=True,135        )136