Johnny Chen | 3d57ee7 | 2010-11-11 23:29:54 +0000 | [diff] [blame] | 1 | """ |
| 2 | Test the printing of anonymous and named namespace variables. |
| 3 | """ |
| 4 | |
| 5 | import os, time |
| 6 | import unittest2 |
| 7 | import lldb |
| 8 | from lldbtest import * |
Jim Ingham | 63dfc72 | 2012-09-22 00:05:11 +0000 | [diff] [blame] | 9 | import lldbutil |
Johnny Chen | 3d57ee7 | 2010-11-11 23:29:54 +0000 | [diff] [blame] | 10 | |
| 11 | class NamespaceTestCase(TestBase): |
| 12 | |
Greg Clayton | 4570d3e | 2013-12-10 23:19:29 +0000 | [diff] [blame] | 13 | mydir = TestBase.compute_mydir(__file__) |
Johnny Chen | 3d57ee7 | 2010-11-11 23:29:54 +0000 | [diff] [blame] | 14 | |
Johnny Chen | d71ffbc | 2010-12-23 23:26:05 +0000 | [diff] [blame] | 15 | # rdar://problem/8668674 |
Robert Flack | 13c7ad9 | 2015-03-30 14:12:17 +0000 | [diff] [blame^] | 16 | @skipUnlessDarwin |
Johnny Chen | 24086bc | 2012-04-06 19:54:10 +0000 | [diff] [blame] | 17 | @dsym_test |
Johnny Chen | 3d57ee7 | 2010-11-11 23:29:54 +0000 | [diff] [blame] | 18 | def test_with_dsym_and_run_command(self): |
| 19 | """Test that anonymous and named namespace variables display correctly.""" |
| 20 | self.buildDsym() |
| 21 | self.namespace_variable_commands() |
| 22 | |
Johnny Chen | d71ffbc | 2010-12-23 23:26:05 +0000 | [diff] [blame] | 23 | # rdar://problem/8668674 |
Johnny Chen | 24086bc | 2012-04-06 19:54:10 +0000 | [diff] [blame] | 24 | @dwarf_test |
Johnny Chen | 3d57ee7 | 2010-11-11 23:29:54 +0000 | [diff] [blame] | 25 | def test_with_dwarf_and_run_command(self): |
| 26 | """Test that anonymous and named namespace variables display correctly.""" |
| 27 | self.buildDwarf() |
| 28 | self.namespace_variable_commands() |
| 29 | |
| 30 | def setUp(self): |
| 31 | # Call super's setUp(). |
| 32 | TestBase.setUp(self) |
| 33 | # Find the line numbers for declarations of namespace variables i and j. |
| 34 | self.line_var_i = line_number('main.cpp', |
| 35 | '// Find the line number for anonymous namespace variable i.') |
| 36 | self.line_var_j = line_number('main.cpp', |
| 37 | '// Find the line number for named namespace variable j.') |
| 38 | # And the line number to break at. |
| 39 | self.line_break = line_number('main.cpp', |
| 40 | '// Set break point at this line.') |
| 41 | |
| 42 | def namespace_variable_commands(self): |
| 43 | """Test that anonymous and named namespace variables display correctly.""" |
| 44 | self.runCmd("file a.out", CURRENT_EXECUTABLE_SET) |
| 45 | |
Jim Ingham | 63dfc72 | 2012-09-22 00:05:11 +0000 | [diff] [blame] | 46 | lldbutil.run_break_set_by_file_and_line (self, "main.cpp", self.line_break, num_expected_locations=1, loc_exact=True) |
Johnny Chen | 3d57ee7 | 2010-11-11 23:29:54 +0000 | [diff] [blame] | 47 | |
| 48 | self.runCmd("run", RUN_SUCCEEDED) |
| 49 | |
| 50 | # The stop reason of the thread should be breakpoint. |
| 51 | self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 52 | substrs = ['stopped', |
Johnny Chen | 3d57ee7 | 2010-11-11 23:29:54 +0000 | [diff] [blame] | 53 | 'stop reason = breakpoint']) |
| 54 | |
Johnny Chen | 80e6db9 | 2010-11-17 00:52:41 +0000 | [diff] [blame] | 55 | # On Mac OS X, gcc 4.2 emits the wrong debug info with respect to types. |
| 56 | slist = ['(int) a = 12', 'anon_uint', 'a_uint', 'b_uint', 'y_uint'] |
| 57 | if sys.platform.startswith("darwin") and self.getCompiler() in ['clang', 'llvm-gcc']: |
| 58 | slist = ['(int) a = 12', |
Johnny Chen | 5e27d5e | 2011-11-01 18:46:52 +0000 | [diff] [blame] | 59 | '::my_uint_t', 'anon_uint = 0', |
Johnny Chen | 80e6db9 | 2010-11-17 00:52:41 +0000 | [diff] [blame] | 60 | '(A::uint_t) a_uint = 1', |
| 61 | '(A::B::uint_t) b_uint = 2', |
Johnny Chen | b4d59f4 | 2010-11-18 20:20:18 +0000 | [diff] [blame] | 62 | '(Y::uint_t) y_uint = 3'] |
| 63 | |
Johnny Chen | 80e6db9 | 2010-11-17 00:52:41 +0000 | [diff] [blame] | 64 | # 'frame variable' displays the local variables with type information. |
Johnny Chen | 13e64a7 | 2010-11-15 19:10:53 +0000 | [diff] [blame] | 65 | self.expect('frame variable', VARIABLES_DISPLAYED_CORRECTLY, |
Johnny Chen | 80e6db9 | 2010-11-17 00:52:41 +0000 | [diff] [blame] | 66 | substrs = slist) |
Johnny Chen | 13e64a7 | 2010-11-15 19:10:53 +0000 | [diff] [blame] | 67 | |
Johnny Chen | 6ba9d1f | 2010-11-15 18:27:57 +0000 | [diff] [blame] | 68 | # 'frame variable' with basename 'i' should work. |
Greg Clayton | 3bcdfc0 | 2012-12-04 00:32:51 +0000 | [diff] [blame] | 69 | self.expect("frame variable --show-declaration --show-globals i", |
Johnny Chen | 3d57ee7 | 2010-11-11 23:29:54 +0000 | [diff] [blame] | 70 | startstr = "main.cpp:%d: (int) (anonymous namespace)::i = 3" % self.line_var_i) |
| 71 | # main.cpp:12: (int) (anonymous namespace)::i = 3 |
| 72 | |
Johnny Chen | 6ba9d1f | 2010-11-15 18:27:57 +0000 | [diff] [blame] | 73 | # 'frame variable' with basename 'j' should work, too. |
Greg Clayton | 3bcdfc0 | 2012-12-04 00:32:51 +0000 | [diff] [blame] | 74 | self.expect("frame variable --show-declaration --show-globals j", |
Johnny Chen | 3d57ee7 | 2010-11-11 23:29:54 +0000 | [diff] [blame] | 75 | startstr = "main.cpp:%d: (int) A::B::j = 4" % self.line_var_j) |
| 76 | # main.cpp:19: (int) A::B::j = 4 |
| 77 | |
Johnny Chen | 6ba9d1f | 2010-11-15 18:27:57 +0000 | [diff] [blame] | 78 | # 'frame variable' should support address-of operator. |
| 79 | self.runCmd("frame variable &i") |
| 80 | |
| 81 | # 'frame variable' with fully qualified name 'A::B::j' should work. |
Johnny Chen | d71ffbc | 2010-12-23 23:26:05 +0000 | [diff] [blame] | 82 | self.expect("frame variable A::B::j", VARIABLES_DISPLAYED_CORRECTLY, |
Johnny Chen | 8a81515 | 2011-07-28 00:52:23 +0000 | [diff] [blame] | 83 | startstr = '(int) A::B::j = 4', |
Enrico Granata | 4d93b8c | 2013-09-30 19:11:51 +0000 | [diff] [blame] | 84 | patterns = [' = 4']) |
Johnny Chen | 6ba9d1f | 2010-11-15 18:27:57 +0000 | [diff] [blame] | 85 | |
Johnny Chen | 913af51 | 2010-11-15 18:40:06 +0000 | [diff] [blame] | 86 | # So should the anonymous namespace case. |
Johnny Chen | d71ffbc | 2010-12-23 23:26:05 +0000 | [diff] [blame] | 87 | self.expect("frame variable '(anonymous namespace)::i'", VARIABLES_DISPLAYED_CORRECTLY, |
Johnny Chen | 8a81515 | 2011-07-28 00:52:23 +0000 | [diff] [blame] | 88 | startstr = '(int) (anonymous namespace)::i = 3', |
Enrico Granata | 4d93b8c | 2013-09-30 19:11:51 +0000 | [diff] [blame] | 89 | patterns = [' = 3']) |
Johnny Chen | 913af51 | 2010-11-15 18:40:06 +0000 | [diff] [blame] | 90 | |
Johnny Chen | 6df2cd3 | 2010-11-12 01:00:56 +0000 | [diff] [blame] | 91 | # rdar://problem/8660275 |
| 92 | # test/namespace: 'expression -- i+j' not working |
Johnny Chen | d71ffbc | 2010-12-23 23:26:05 +0000 | [diff] [blame] | 93 | # This has been fixed. |
Johnny Chen | deac523 | 2010-11-15 17:42:22 +0000 | [diff] [blame] | 94 | self.expect("expression -- i + j", |
| 95 | startstr = "(int) $0 = 7") |
Johnny Chen | 064d7f5 | 2010-11-12 00:50:45 +0000 | [diff] [blame] | 96 | # (int) $0 = 7 |
Johnny Chen | 3d57ee7 | 2010-11-11 23:29:54 +0000 | [diff] [blame] | 97 | |
Johnny Chen | d71ffbc | 2010-12-23 23:26:05 +0000 | [diff] [blame] | 98 | self.runCmd("expression -- i") |
| 99 | self.runCmd("expression -- j") |
| 100 | |
Johnny Chen | 8ed80e6 | 2010-11-15 18:49:03 +0000 | [diff] [blame] | 101 | # rdar://problem/8668674 |
| 102 | # expression command with fully qualified namespace for a variable does not work |
Johnny Chen | 098781b | 2011-08-01 21:30:30 +0000 | [diff] [blame] | 103 | self.expect("expression -- ::i", VARIABLES_DISPLAYED_CORRECTLY, |
Enrico Granata | 4d93b8c | 2013-09-30 19:11:51 +0000 | [diff] [blame] | 104 | patterns = [' = 3']) |
Johnny Chen | 098781b | 2011-08-01 21:30:30 +0000 | [diff] [blame] | 105 | self.expect("expression -- A::B::j", VARIABLES_DISPLAYED_CORRECTLY, |
Enrico Granata | 4d93b8c | 2013-09-30 19:11:51 +0000 | [diff] [blame] | 106 | patterns = [' = 4']) |
Johnny Chen | 913af51 | 2010-11-15 18:40:06 +0000 | [diff] [blame] | 107 | |
Matt Kopec | 201284a | 2013-05-13 22:00:32 +0000 | [diff] [blame] | 108 | # expression command with function in anonymous namespace |
| 109 | self.expect("expression -- myanonfunc(3)", |
| 110 | patterns = [' = 6']) |
| 111 | |
| 112 | # global namespace qualification with function in anonymous namespace |
| 113 | self.expect("expression -- ::myanonfunc(4)", |
| 114 | patterns = [' = 8']) |
| 115 | |
| 116 | self.expect("p myanonfunc", |
| 117 | patterns = ['\(anonymous namespace\)::myanonfunc\(int\)']) |
Johnny Chen | 913af51 | 2010-11-15 18:40:06 +0000 | [diff] [blame] | 118 | |
Siva Chandra | 462722d | 2015-03-27 00:10:04 +0000 | [diff] [blame] | 119 | self.expect("p variadic_sum", |
| 120 | patterns = ['\(anonymous namespace\)::variadic_sum\(int, ...\)']) |
| 121 | |
Johnny Chen | 3d57ee7 | 2010-11-11 23:29:54 +0000 | [diff] [blame] | 122 | if __name__ == '__main__': |
| 123 | import atexit |
| 124 | lldb.SBDebugger.Initialize() |
| 125 | atexit.register(lambda: lldb.SBDebugger.Terminate()) |
| 126 | unittest2.main() |