blob: 794be62aba6fd1c5976375bac9ded24c728a512d [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
Greg Clayton4570d3e2013-12-10 23:19:29 +000010 mydir = TestBase.compute_mydir(__file__)
Sean Callanan5207a342011-08-10 21:05:52 +000011
Robert Flack13c7ad92015-03-30 14:12:17 +000012 @skipUnlessDarwin
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
Johnny Chen24086bc2012-04-06 19:54:10 +000019 @dwarf_test
Zachary Turner18442842015-08-20 22:09:35 +000020 @expectedFailureWindows("llvm.org/pr21765")
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
Sean Callanan05834cd2015-07-01 23:56:30 +000038 self.runCmd("process launch", RUN_SUCCEEDED)
Sean Callanan5207a342011-08-10 21:05:52 +000039
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
Matt Kopec00049b82013-02-27 20:13:38 +000046 # On Linux, the expression below will test GNU indirect function calls.
Sean Callanan5207a342011-08-10 21:05:52 +000047 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
Enrico Granatacd58d112013-03-28 21:58:05 +000056 self.expect("expr --raw -- \"hello\"",
57 substrs = ['[0] = \'h\'',
Enrico Granatab576bba2013-01-09 20:12:53 +000058 '[5] = \'\\0\''])
Enrico Granata9128ee22011-09-06 19:20:51 +000059
Enrico Granatacd58d112013-03-28 21:58:05 +000060 self.expect("p \"hello\"",
61 substrs = ['[6]) $', 'hello'])
62
Enrico Granata9128ee22011-09-06 19:20:51 +000063 self.expect("p (char*)\"hello\"",
64 substrs = ['(char *) $', ' = 0x',
65 'hello'])
66
Sean Callanan76ee3e72013-04-24 19:50:12 +000067 self.expect("p (int)strlen(\"\")",
68 substrs = ['(int) $', ' = 0'])
69
Sean Callanan7d01ddd2013-05-31 17:29:03 +000070 self.expect("expression !z",
71 substrs = ['false'])
72
Sean Callanan5207a342011-08-10 21:05:52 +000073if __name__ == '__main__':
74 import atexit
75 lldb.SBDebugger.Initialize()
76 atexit.register(lambda: lldb.SBDebugger.Terminate())
77 unittest2.main()