| Sean Callanan | 5207a34 | 2011-08-10 21:05:52 +0000 | [diff] [blame] | 1 | """ |
| 2 | Tests that C strings work as expected in expressions |
| 3 | """ |
| Jim Ingham | 63dfc72 | 2012-09-22 00:05:11 +0000 | [diff] [blame] | 4 | import lldb |
| Sean Callanan | 5207a34 | 2011-08-10 21:05:52 +0000 | [diff] [blame] | 5 | from lldbtest import * |
| Jim Ingham | 63dfc72 | 2012-09-22 00:05:11 +0000 | [diff] [blame] | 6 | import lldbutil |
| Sean Callanan | 5207a34 | 2011-08-10 21:05:52 +0000 | [diff] [blame] | 7 | |
| 8 | class CStringsTestCase(TestBase): |
| 9 | |
| Greg Clayton | 4570d3e | 2013-12-10 23:19:29 +0000 | [diff] [blame] | 10 | mydir = TestBase.compute_mydir(__file__) |
| Sean Callanan | 5207a34 | 2011-08-10 21:05:52 +0000 | [diff] [blame] | 11 | |
| Robert Flack | 13c7ad9 | 2015-03-30 14:12:17 +0000 | [diff] [blame] | 12 | @skipUnlessDarwin |
| Johnny Chen | 24086bc | 2012-04-06 19:54:10 +0000 | [diff] [blame] | 13 | @dsym_test |
| Sean Callanan | 5207a34 | 2011-08-10 21:05:52 +0000 | [diff] [blame] | 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 | |
| Johnny Chen | 24086bc | 2012-04-06 19:54:10 +0000 | [diff] [blame] | 19 | @dwarf_test |
| Sean Callanan | 5207a34 | 2011-08-10 21:05:52 +0000 | [diff] [blame] | 20 | def test_with_dwarf_and_run_command(self): |
| 21 | """Tests that C strings work as expected in expressions""" |
| 22 | self.buildDwarf() |
| 23 | self.static_method_commands() |
| 24 | |
| 25 | def setUp(self): |
| 26 | TestBase.setUp(self) |
| 27 | |
| 28 | def set_breakpoint(self, line): |
| Jim Ingham | 63dfc72 | 2012-09-22 00:05:11 +0000 | [diff] [blame] | 29 | lldbutil.run_break_set_by_file_and_line (self, "main.c", line, num_expected_locations=1, loc_exact=True) |
| Sean Callanan | 5207a34 | 2011-08-10 21:05:52 +0000 | [diff] [blame] | 30 | |
| 31 | def static_method_commands(self): |
| 32 | """Tests that C strings work as expected in expressions""" |
| 33 | self.runCmd("file a.out", CURRENT_EXECUTABLE_SET) |
| 34 | |
| 35 | self.set_breakpoint(line_number('main.c', '// breakpoint 1')) |
| 36 | |
| Sean Callanan | 05834cd | 2015-07-01 23:56:30 +0000 | [diff] [blame^] | 37 | self.runCmd("process launch", RUN_SUCCEEDED) |
| Sean Callanan | 5207a34 | 2011-08-10 21:05:52 +0000 | [diff] [blame] | 38 | |
| 39 | self.expect("expression -- a[2]", |
| Johnny Chen | e1cdc92 | 2011-08-16 19:59:22 +0000 | [diff] [blame] | 40 | patterns = ["\((const )?char\) \$0 = 'c'"]) |
| Sean Callanan | 5207a34 | 2011-08-10 21:05:52 +0000 | [diff] [blame] | 41 | |
| 42 | self.expect("expression -- z[2]", |
| 43 | startstr = "(const char) $1 = 'x'") |
| 44 | |
| Matt Kopec | 00049b8 | 2013-02-27 20:13:38 +0000 | [diff] [blame] | 45 | # On Linux, the expression below will test GNU indirect function calls. |
| Sean Callanan | 5207a34 | 2011-08-10 21:05:52 +0000 | [diff] [blame] | 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 Granata | cd58d11 | 2013-03-28 21:58:05 +0000 | [diff] [blame] | 55 | self.expect("expr --raw -- \"hello\"", |
| 56 | substrs = ['[0] = \'h\'', |
| Enrico Granata | b576bba | 2013-01-09 20:12:53 +0000 | [diff] [blame] | 57 | '[5] = \'\\0\'']) |
| Enrico Granata | 9128ee2 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 58 | |
| Enrico Granata | cd58d11 | 2013-03-28 21:58:05 +0000 | [diff] [blame] | 59 | self.expect("p \"hello\"", |
| 60 | substrs = ['[6]) $', 'hello']) |
| 61 | |
| Enrico Granata | 9128ee2 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 62 | self.expect("p (char*)\"hello\"", |
| 63 | substrs = ['(char *) $', ' = 0x', |
| 64 | 'hello']) |
| 65 | |
| Sean Callanan | 76ee3e7 | 2013-04-24 19:50:12 +0000 | [diff] [blame] | 66 | self.expect("p (int)strlen(\"\")", |
| 67 | substrs = ['(int) $', ' = 0']) |
| 68 | |
| Sean Callanan | 7d01ddd | 2013-05-31 17:29:03 +0000 | [diff] [blame] | 69 | self.expect("expression !z", |
| 70 | substrs = ['false']) |
| 71 | |
| Sean Callanan | 5207a34 | 2011-08-10 21:05:52 +0000 | [diff] [blame] | 72 | if __name__ == '__main__': |
| 73 | import atexit |
| 74 | lldb.SBDebugger.Initialize() |
| 75 | atexit.register(lambda: lldb.SBDebugger.Terminate()) |
| 76 | unittest2.main() |