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 * |
| 9 | |
| 10 | class NamespaceTestCase(TestBase): |
| 11 | |
Johnny Chen | 30a6a1e | 2011-06-25 20:21:10 +0000 | [diff] [blame] | 12 | mydir = os.path.join("lang", "cpp", "namespace") |
Johnny Chen | 3d57ee7 | 2010-11-11 23:29:54 +0000 | [diff] [blame] | 13 | |
Johnny Chen | d71ffbc | 2010-12-23 23:26:05 +0000 | [diff] [blame] | 14 | # rdar://problem/8668674 |
| 15 | @unittest2.expectedFailure |
Johnny Chen | 3d57ee7 | 2010-11-11 23:29:54 +0000 | [diff] [blame] | 16 | @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin") |
| 17 | def test_with_dsym_and_run_command(self): |
| 18 | """Test that anonymous and named namespace variables display correctly.""" |
| 19 | self.buildDsym() |
| 20 | self.namespace_variable_commands() |
| 21 | |
Johnny Chen | d71ffbc | 2010-12-23 23:26:05 +0000 | [diff] [blame] | 22 | # rdar://problem/8668674 |
| 23 | @unittest2.expectedFailure |
Johnny Chen | 3d57ee7 | 2010-11-11 23:29:54 +0000 | [diff] [blame] | 24 | def test_with_dwarf_and_run_command(self): |
| 25 | """Test that anonymous and named namespace variables display correctly.""" |
| 26 | self.buildDwarf() |
| 27 | self.namespace_variable_commands() |
| 28 | |
| 29 | def setUp(self): |
| 30 | # Call super's setUp(). |
| 31 | TestBase.setUp(self) |
| 32 | # Find the line numbers for declarations of namespace variables i and j. |
| 33 | self.line_var_i = line_number('main.cpp', |
| 34 | '// Find the line number for anonymous namespace variable i.') |
| 35 | self.line_var_j = line_number('main.cpp', |
| 36 | '// Find the line number for named namespace variable j.') |
| 37 | # And the line number to break at. |
| 38 | self.line_break = line_number('main.cpp', |
| 39 | '// Set break point at this line.') |
| 40 | |
| 41 | def namespace_variable_commands(self): |
| 42 | """Test that anonymous and named namespace variables display correctly.""" |
| 43 | self.runCmd("file a.out", CURRENT_EXECUTABLE_SET) |
| 44 | |
| 45 | self.expect("breakpoint set -f main.cpp -l %d" % self.line_break, |
| 46 | BREAKPOINT_CREATED, |
| 47 | startstr = "Breakpoint created: 1: file ='main.cpp', line = %d, locations = 1" % |
| 48 | self.line_break) |
| 49 | |
| 50 | self.runCmd("run", RUN_SUCCEEDED) |
| 51 | |
| 52 | # The stop reason of the thread should be breakpoint. |
| 53 | self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 54 | substrs = ['stopped', |
Johnny Chen | 3d57ee7 | 2010-11-11 23:29:54 +0000 | [diff] [blame] | 55 | 'stop reason = breakpoint']) |
| 56 | |
Johnny Chen | 80e6db9 | 2010-11-17 00:52:41 +0000 | [diff] [blame] | 57 | # On Mac OS X, gcc 4.2 emits the wrong debug info with respect to types. |
| 58 | slist = ['(int) a = 12', 'anon_uint', 'a_uint', 'b_uint', 'y_uint'] |
| 59 | if sys.platform.startswith("darwin") and self.getCompiler() in ['clang', 'llvm-gcc']: |
| 60 | slist = ['(int) a = 12', |
| 61 | '(my_uint_t) anon_uint = 0', |
| 62 | '(A::uint_t) a_uint = 1', |
| 63 | '(A::B::uint_t) b_uint = 2', |
Johnny Chen | b4d59f4 | 2010-11-18 20:20:18 +0000 | [diff] [blame] | 64 | '(Y::uint_t) y_uint = 3'] |
| 65 | |
Johnny Chen | 80e6db9 | 2010-11-17 00:52:41 +0000 | [diff] [blame] | 66 | # 'frame variable' displays the local variables with type information. |
Johnny Chen | 13e64a7 | 2010-11-15 19:10:53 +0000 | [diff] [blame] | 67 | self.expect('frame variable', VARIABLES_DISPLAYED_CORRECTLY, |
Johnny Chen | 80e6db9 | 2010-11-17 00:52:41 +0000 | [diff] [blame] | 68 | substrs = slist) |
Johnny Chen | 13e64a7 | 2010-11-15 19:10:53 +0000 | [diff] [blame] | 69 | |
Johnny Chen | 6ba9d1f | 2010-11-15 18:27:57 +0000 | [diff] [blame] | 70 | # 'frame variable' with basename 'i' should work. |
Johnny Chen | 1d3e880 | 2011-07-11 23:38:23 +0000 | [diff] [blame] | 71 | self.expect("frame variable -c -g i", |
Johnny Chen | 3d57ee7 | 2010-11-11 23:29:54 +0000 | [diff] [blame] | 72 | startstr = "main.cpp:%d: (int) (anonymous namespace)::i = 3" % self.line_var_i) |
| 73 | # main.cpp:12: (int) (anonymous namespace)::i = 3 |
| 74 | |
Johnny Chen | 6ba9d1f | 2010-11-15 18:27:57 +0000 | [diff] [blame] | 75 | # 'frame variable' with basename 'j' should work, too. |
Johnny Chen | 1d3e880 | 2011-07-11 23:38:23 +0000 | [diff] [blame] | 76 | self.expect("frame variable -c -g j", |
Johnny Chen | 3d57ee7 | 2010-11-11 23:29:54 +0000 | [diff] [blame] | 77 | startstr = "main.cpp:%d: (int) A::B::j = 4" % self.line_var_j) |
| 78 | # main.cpp:19: (int) A::B::j = 4 |
| 79 | |
Johnny Chen | 6ba9d1f | 2010-11-15 18:27:57 +0000 | [diff] [blame] | 80 | # 'frame variable' should support address-of operator. |
| 81 | self.runCmd("frame variable &i") |
| 82 | |
| 83 | # 'frame variable' with fully qualified name 'A::B::j' should work. |
Johnny Chen | d71ffbc | 2010-12-23 23:26:05 +0000 | [diff] [blame] | 84 | self.expect("frame variable A::B::j", VARIABLES_DISPLAYED_CORRECTLY, |
Johnny Chen | 8a81515 | 2011-07-28 00:52:23 +0000 | [diff] [blame^] | 85 | startstr = '(int) A::B::j = 4', |
| 86 | patterns = [' = 4$']) |
Johnny Chen | 6ba9d1f | 2010-11-15 18:27:57 +0000 | [diff] [blame] | 87 | |
Johnny Chen | 913af51 | 2010-11-15 18:40:06 +0000 | [diff] [blame] | 88 | # So should the anonymous namespace case. |
Johnny Chen | d71ffbc | 2010-12-23 23:26:05 +0000 | [diff] [blame] | 89 | self.expect("frame variable '(anonymous namespace)::i'", VARIABLES_DISPLAYED_CORRECTLY, |
Johnny Chen | 8a81515 | 2011-07-28 00:52:23 +0000 | [diff] [blame^] | 90 | startstr = '(int) (anonymous namespace)::i = 3', |
| 91 | patterns = [' = 3$']) |
Johnny Chen | 913af51 | 2010-11-15 18:40:06 +0000 | [diff] [blame] | 92 | |
Johnny Chen | 6df2cd3 | 2010-11-12 01:00:56 +0000 | [diff] [blame] | 93 | # rdar://problem/8660275 |
| 94 | # test/namespace: 'expression -- i+j' not working |
Johnny Chen | d71ffbc | 2010-12-23 23:26:05 +0000 | [diff] [blame] | 95 | # This has been fixed. |
Johnny Chen | deac523 | 2010-11-15 17:42:22 +0000 | [diff] [blame] | 96 | self.expect("expression -- i + j", |
| 97 | startstr = "(int) $0 = 7") |
Johnny Chen | 064d7f5 | 2010-11-12 00:50:45 +0000 | [diff] [blame] | 98 | # (int) $0 = 7 |
Johnny Chen | 3d57ee7 | 2010-11-11 23:29:54 +0000 | [diff] [blame] | 99 | |
Johnny Chen | d71ffbc | 2010-12-23 23:26:05 +0000 | [diff] [blame] | 100 | self.runCmd("expression -- i") |
| 101 | self.runCmd("expression -- j") |
| 102 | |
Johnny Chen | 8ed80e6 | 2010-11-15 18:49:03 +0000 | [diff] [blame] | 103 | # rdar://problem/8668674 |
| 104 | # expression command with fully qualified namespace for a variable does not work |
Johnny Chen | 847f511 | 2011-07-27 23:17:56 +0000 | [diff] [blame] | 105 | self.expect("expression -- '::i'", VARIABLES_DISPLAYED_CORRECTLY, |
Johnny Chen | 8a81515 | 2011-07-28 00:52:23 +0000 | [diff] [blame^] | 106 | patterns = [' = 3$']) |
Johnny Chen | d71ffbc | 2010-12-23 23:26:05 +0000 | [diff] [blame] | 107 | self.expect("expression -- 'A::B::j'", VARIABLES_DISPLAYED_CORRECTLY, |
Johnny Chen | 8a81515 | 2011-07-28 00:52:23 +0000 | [diff] [blame^] | 108 | patterns = [' = 4$']) |
Johnny Chen | 913af51 | 2010-11-15 18:40:06 +0000 | [diff] [blame] | 109 | |
| 110 | |
Johnny Chen | 3d57ee7 | 2010-11-11 23:29:54 +0000 | [diff] [blame] | 111 | if __name__ == '__main__': |
| 112 | import atexit |
| 113 | lldb.SBDebugger.Initialize() |
| 114 | atexit.register(lambda: lldb.SBDebugger.Terminate()) |
| 115 | unittest2.main() |