199451b44SJordan Rupprecht""" 299451b44SJordan RupprechtTests that C strings work as expected in expressions 399451b44SJordan Rupprecht""" 499451b44SJordan Rupprechtimport lldb 599451b44SJordan Rupprechtfrom lldbsuite.test.decorators import * 699451b44SJordan Rupprechtfrom lldbsuite.test.lldbtest import * 799451b44SJordan Rupprechtfrom lldbsuite.test import lldbutil 899451b44SJordan Rupprecht 999451b44SJordan Rupprecht 1099451b44SJordan Rupprechtclass CStringsTestCase(TestBase): 1199451b44SJordan Rupprecht def test_with_run_command(self): 1299451b44SJordan Rupprecht """Tests that C strings work as expected in expressions""" 1399451b44SJordan Rupprecht self.build() 1499451b44SJordan Rupprecht self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET) 1599451b44SJordan Rupprecht 16*2238dcc3SJonas Devlieghere line = line_number("main.c", "// breakpoint 1") 1799451b44SJordan Rupprecht lldbutil.run_break_set_by_file_and_line( 18*2238dcc3SJonas Devlieghere self, "main.c", line, num_expected_locations=1, loc_exact=True 19*2238dcc3SJonas Devlieghere ) 2099451b44SJordan Rupprecht 2199451b44SJordan Rupprecht self.runCmd("process launch", RUN_SUCCEEDED) 2299451b44SJordan Rupprecht 23*2238dcc3SJonas Devlieghere self.expect("expression -- a[2]", patterns=["\((const )?char\) \$0 = 'c'"]) 2499451b44SJordan Rupprecht 25*2238dcc3SJonas Devlieghere self.expect("expression -- z[2]", startstr="(const char) $1 = 'x'") 2699451b44SJordan Rupprecht 2799451b44SJordan Rupprecht # On Linux, the expression below will test GNU indirect function calls. 28*2238dcc3SJonas Devlieghere self.expect('expression -- (int)strlen("hello")', startstr="(int) $2 = 5") 2999451b44SJordan Rupprecht 30*2238dcc3SJonas Devlieghere self.expect('expression -- "world"[2]', startstr="(const char) $3 = 'r'") 3199451b44SJordan Rupprecht 32*2238dcc3SJonas Devlieghere self.expect('expression -- ""[0]', startstr="(const char) $4 = '\\0'") 3399451b44SJordan Rupprecht 34*2238dcc3SJonas Devlieghere self.expect('expr --raw -- "hello"', substrs=["[0] = 'h'", "[5] = '\\0'"]) 3599451b44SJordan Rupprecht 36*2238dcc3SJonas Devlieghere self.expect('expression "hello"', substrs=["[6]) $", "hello"]) 3799451b44SJordan Rupprecht 38*2238dcc3SJonas Devlieghere self.expect( 39*2238dcc3SJonas Devlieghere 'expression (char*)"hello"', substrs=["(char *) $", " = 0x", "hello"] 40*2238dcc3SJonas Devlieghere ) 4199451b44SJordan Rupprecht 42*2238dcc3SJonas Devlieghere self.expect('expression (int)strlen("")', substrs=["(int) $", " = 0"]) 4399451b44SJordan Rupprecht 44*2238dcc3SJonas Devlieghere self.expect("expression !z", substrs=["false"]) 45