1""" 2Tests that C strings work as expected in expressions 3""" 4import lldb 5from lldbtest import * 6import lldbutil 7 8class CStringsTestCase(TestBase): 9 10 mydir = os.path.join("lang", "c", "strings") 11 12 @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin") 13 @dsym_test 14 def test_with_dsym_and_run_command(self): 15 """Tests that C strings work as expected in expressions""" 16 self.buildDsym() 17 self.static_method_commands() 18 19 @expectedFailureFreeBSD # llvm.org/pr16697 20 @dwarf_test 21 def test_with_dwarf_and_run_command(self): 22 """Tests that C strings work as expected in expressions""" 23 self.buildDwarf() 24 self.static_method_commands() 25 26 def setUp(self): 27 TestBase.setUp(self) 28 29 def set_breakpoint(self, line): 30 lldbutil.run_break_set_by_file_and_line (self, "main.c", line, num_expected_locations=1, loc_exact=True) 31 32 def static_method_commands(self): 33 """Tests that C strings work as expected in expressions""" 34 self.runCmd("file a.out", CURRENT_EXECUTABLE_SET) 35 36 self.set_breakpoint(line_number('main.c', '// breakpoint 1')) 37 38 self.runCmd("process launch", RUN_SUCCEEDED) 39 40 self.expect("expression -- a[2]", 41 patterns = ["\((const )?char\) \$0 = 'c'"]) 42 43 self.expect("expression -- z[2]", 44 startstr = "(const char) $1 = 'x'") 45 46 # On Linux, the expression below will test GNU indirect function calls. 47 self.expect("expression -- (int)strlen(\"hello\")", 48 startstr = "(int) $2 = 5") 49 50 self.expect("expression -- \"world\"[2]", 51 startstr = "(const char) $3 = 'r'") 52 53 self.expect("expression -- \"\"[0]", 54 startstr = "(const char) $4 = '\\0'") 55 56 self.expect("expr --raw -- \"hello\"", 57 substrs = ['[0] = \'h\'', 58 '[5] = \'\\0\'']) 59 60 self.expect("p \"hello\"", 61 substrs = ['[6]) $', 'hello']) 62 63 self.expect("p (char*)\"hello\"", 64 substrs = ['(char *) $', ' = 0x', 65 'hello']) 66 67 self.expect("p (int)strlen(\"\")", 68 substrs = ['(int) $', ' = 0']) 69 70 self.expect("expression !z", 71 substrs = ['false']) 72 73if __name__ == '__main__': 74 import atexit 75 lldb.SBDebugger.Initialize() 76 atexit.register(lambda: lldb.SBDebugger.Terminate()) 77 unittest2.main() 78