1""" 2Tests that C strings work as expected in expressions 3""" 4import lldb 5from lldbsuite.test.decorators import * 6from lldbsuite.test.lldbtest import * 7from lldbsuite.test import lldbutil 8 9 10class CStringsTestCase(TestBase): 11 12 mydir = TestBase.compute_mydir(__file__) 13 14 def test_with_run_command(self): 15 """Tests that C strings work as expected in expressions""" 16 self.build() 17 self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET) 18 19 line = line_number('main.c', '// breakpoint 1') 20 lldbutil.run_break_set_by_file_and_line( 21 self, "main.c", line, num_expected_locations=1, loc_exact=True) 22 23 self.runCmd("process launch", RUN_SUCCEEDED) 24 25 self.expect("expression -- a[2]", 26 patterns=["\((const )?char\) \$0 = 'c'"]) 27 28 self.expect("expression -- z[2]", 29 startstr="(const char) $1 = 'x'") 30 31 # On Linux, the expression below will test GNU indirect function calls. 32 self.expect("expression -- (int)strlen(\"hello\")", 33 startstr="(int) $2 = 5") 34 35 self.expect("expression -- \"world\"[2]", 36 startstr="(const char) $3 = 'r'") 37 38 self.expect("expression -- \"\"[0]", 39 startstr="(const char) $4 = '\\0'") 40 41 self.expect("expr --raw -- \"hello\"", 42 substrs=['[0] = \'h\'', 43 '[5] = \'\\0\'']) 44 45 self.expect("p \"hello\"", 46 substrs=['[6]) $', 'hello']) 47 48 self.expect("p (char*)\"hello\"", 49 substrs=['(char *) $', ' = 0x', 50 'hello']) 51 52 self.expect("p (int)strlen(\"\")", 53 substrs=['(int) $', ' = 0']) 54 55 self.expect("expression !z", 56 substrs=['false']) 57