blob: 0a1a826674a0580a5db02a534d791779c802a276 [file] [log] [blame]
Sean Callanan5207a342011-08-10 21:05:52 +00001"""
2Tests that C strings work as expected in expressions
3"""
Jim Ingham63dfc722012-09-22 00:05:11 +00004import lldb
Sean Callanan5207a342011-08-10 21:05:52 +00005from lldbtest import *
Jim Ingham63dfc722012-09-22 00:05:11 +00006import lldbutil
Sean Callanan5207a342011-08-10 21:05:52 +00007
8class CStringsTestCase(TestBase):
9
10 mydir = os.path.join("lang", "c", "strings")
11
12 @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
Johnny Chen24086bc2012-04-06 19:54:10 +000013 @dsym_test
Sean Callanan5207a342011-08-10 21:05:52 +000014 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
Daniel Malea2bbf09e2012-11-27 21:33:41 +000019 @expectedFailureLinux # bugzilla 14437
Johnny Chen24086bc2012-04-06 19:54:10 +000020 @dwarf_test
Sean Callanan5207a342011-08-10 21:05:52 +000021 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):
Jim Ingham63dfc722012-09-22 00:05:11 +000030 lldbutil.run_break_set_by_file_and_line (self, "main.c", line, num_expected_locations=1, loc_exact=True)
Sean Callanan5207a342011-08-10 21:05:52 +000031
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]",
Johnny Chene1cdc922011-08-16 19:59:22 +000041 patterns = ["\((const )?char\) \$0 = 'c'"])
Sean Callanan5207a342011-08-10 21:05:52 +000042
43 self.expect("expression -- z[2]",
44 startstr = "(const char) $1 = 'x'")
45
46 self.expect("expression -- (int)strlen(\"hello\")",
47 startstr = "(int) $2 = 5")
48
49 self.expect("expression -- \"world\"[2]",
50 startstr = "(const char) $3 = 'r'")
51
52 self.expect("expression -- \"\"[0]",
53 startstr = "(const char) $4 = '\\0'")
54
Enrico Granata9128ee22011-09-06 19:20:51 +000055 self.expect("p \"hello\"",
Enrico Granatab576bba2013-01-09 20:12:53 +000056 substrs = ['[6]) $', 'hello',
57 '[0] = \'h\'',
58 '[5] = \'\\0\''])
Enrico Granata9128ee22011-09-06 19:20:51 +000059
60 self.expect("p (char*)\"hello\"",
61 substrs = ['(char *) $', ' = 0x',
62 'hello'])
63
Sean Callanan5207a342011-08-10 21:05:52 +000064if __name__ == '__main__':
65 import atexit
66 lldb.SBDebugger.Initialize()
67 atexit.register(lambda: lldb.SBDebugger.Terminate())
68 unittest2.main()