]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - packages/Python/lldbsuite/test/lang/cpp/namespace/TestNamespace.py
Vendor import of lldb trunk r256945:
[FreeBSD/FreeBSD.git] / packages / Python / lldbsuite / test / lang / cpp / namespace / TestNamespace.py
1 """
2 Test the printing of anonymous and named namespace variables.
3 """
4
5 from __future__ import print_function
6
7
8
9 import os, time
10 import lldb
11 from lldbsuite.test.lldbtest import *
12 import lldbsuite.test.lldbutil as lldbutil
13
14 class NamespaceTestCase(TestBase):
15
16     mydir = TestBase.compute_mydir(__file__)
17
18     def setUp(self):
19         # Call super's setUp().
20         TestBase.setUp(self)
21         # Find the line numbers for declarations of namespace variables i and j.
22         self.line_var_i = line_number('main.cpp',
23                 '// Find the line number for anonymous namespace variable i.')
24         self.line_var_j = line_number('main.cpp',
25                 '// Find the line number for named namespace variable j.')
26         # And the line number to break at.
27         self.line_break = line_number('main.cpp',
28                 '// Set break point at this line.')
29         # Break inside do {} while and evaluate value
30         self.line_break_ns1 = line_number('main.cpp', '// Evaluate ns1::value')
31         self.line_break_ns2 = line_number('main.cpp', '// Evaluate ns2::value')
32
33     def runToBkpt(self, command):
34         self.runCmd(command, RUN_SUCCEEDED)
35         # The stop reason of the thread should be breakpoint.
36         self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
37             substrs = ['stopped',
38                        'stop reason = breakpoint'])
39
40     # rdar://problem/8668674
41     @expectedFailureWindows("llvm.org/pr24764")
42     def test_with_run_command(self):
43         """Test that anonymous and named namespace variables display correctly."""
44         self.build()
45         self.runCmd("file a.out", CURRENT_EXECUTABLE_SET)
46
47         lldbutil.run_break_set_by_file_and_line (self, "main.cpp", self.line_break_ns1, num_expected_locations=1, loc_exact=True)
48         lldbutil.run_break_set_by_file_and_line (self, "main.cpp", self.line_break_ns2, num_expected_locations=1, loc_exact=True)
49         lldbutil.run_break_set_by_file_and_line (self, "main.cpp", self.line_break, num_expected_locations=1, loc_exact=True)
50
51         self.runToBkpt("run")
52         # Evaluate ns1::value
53         self.expect("expression -- value", startstr = "(int) $0 = 100")
54
55         self.runToBkpt("continue")
56         # Evaluate ns2::value
57         self.expect("expression -- value", startstr = "(int) $1 = 200")
58         
59         self.runToBkpt("continue")
60         # On Mac OS X, gcc 4.2 emits the wrong debug info with respect to types.
61         slist = ['(int) a = 12', 'anon_uint', 'a_uint', 'b_uint', 'y_uint']
62         if self.platformIsDarwin() and self.getCompiler() in ['clang', 'llvm-gcc']:
63             slist = ['(int) a = 12',
64                      '::my_uint_t', 'anon_uint = 0',
65                      '(A::uint_t) a_uint = 1',
66                      '(A::B::uint_t) b_uint = 2',
67                      '(Y::uint_t) y_uint = 3']
68
69         # 'frame variable' displays the local variables with type information.
70         self.expect('frame variable', VARIABLES_DISPLAYED_CORRECTLY,
71             substrs = slist)
72
73         # 'frame variable' with basename 'i' should work.
74         self.expect("frame variable --show-declaration --show-globals i",
75             startstr = "main.cpp:%d: (int) (anonymous namespace)::i = 3" % self.line_var_i)
76         # main.cpp:12: (int) (anonymous namespace)::i = 3
77
78         # 'frame variable' with basename 'j' should work, too.
79         self.expect("frame variable --show-declaration --show-globals j",
80             startstr = "main.cpp:%d: (int) A::B::j = 4" % self.line_var_j)
81         # main.cpp:19: (int) A::B::j = 4
82
83         # 'frame variable' should support address-of operator.
84         self.runCmd("frame variable &i")
85
86         # 'frame variable' with fully qualified name 'A::B::j' should work.
87         self.expect("frame variable A::B::j", VARIABLES_DISPLAYED_CORRECTLY,
88             startstr = '(int) A::B::j = 4',
89             patterns = [' = 4'])
90
91         # So should the anonymous namespace case.
92         self.expect("frame variable '(anonymous namespace)::i'", VARIABLES_DISPLAYED_CORRECTLY,
93             startstr = '(int) (anonymous namespace)::i = 3',
94             patterns = [' = 3'])
95
96         # rdar://problem/8660275
97         # test/namespace: 'expression -- i+j' not working
98         # This has been fixed.
99         self.expect("expression -- i + j",
100             startstr = "(int) $2 = 7")
101         # (int) $2 = 7
102
103         self.runCmd("expression -- i")
104         self.runCmd("expression -- j")
105
106         # rdar://problem/8668674
107         # expression command with fully qualified namespace for a variable does not work
108         self.expect("expression -- ::i", VARIABLES_DISPLAYED_CORRECTLY,
109             patterns = [' = 3'])
110         self.expect("expression -- A::B::j", VARIABLES_DISPLAYED_CORRECTLY,
111             patterns = [' = 4'])
112
113         # expression command with function in anonymous namespace
114         self.expect("expression -- myanonfunc(3)",
115             patterns = [' = 6'])
116
117         # global namespace qualification with function in anonymous namespace
118         self.expect("expression -- ::myanonfunc(4)",
119             patterns = [' = 8'])
120
121         self.expect("p myanonfunc",
122             patterns = ['\(anonymous namespace\)::myanonfunc\(int\)'])
123
124         self.expect("p variadic_sum",
125             patterns = ['\(anonymous namespace\)::variadic_sum\(int, ...\)'])