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