621b22a538c3446ecd65ce7e1b5a05232ae3061c
[openbsd] /
1 """
2 Test lldb data formatter subsystem.
3 """
4
5
6
7 import lldb
8 from lldbsuite.test.decorators import *
9 from lldbsuite.test.lldbtest import *
10 from lldbsuite.test import lldbutil
11
12
13 class LibcxxMultiSetDataFormatterTestCase(TestBase):
14
15     mydir = TestBase.compute_mydir(__file__)
16
17     def setUp(self):
18         TestBase.setUp(self)
19         ns = 'ndk' if lldbplatformutil.target_is_android() else ''
20         self.namespace = 'std::__' + ns + '1'
21
22     def getVariableType(self, name):
23         var = self.frame().FindVariable(name)
24         self.assertTrue(var.IsValid())
25         return var.GetType().GetCanonicalType().GetName()
26
27     def check_ii(self, var_name):
28         """ This checks the value of the bitset stored in ii at the call to by_ref_and_ptr.
29             We use this to make sure we get the same values for ii when we look at the object
30             directly, and when we look at a reference to the object. """
31         self.expect(
32             "frame variable " + var_name,
33             substrs=["size=7",
34                      "[2] = 2",
35                      "[3] = 3",
36                      "[6] = 6"])
37         self.expect("frame variable " + var_name + "[2]", substrs=[" = 2"])
38         self.expect(
39             "p " + var_name,
40             substrs=[
41                 "size=7",
42                 "[2] = 2",
43                 "[3] = 3",
44                 "[6] = 6"])
45
46     @add_test_categories(["libc++"])
47     def test_with_run_command(self):
48         """Test that that file and class static variables display correctly."""
49         self.build()
50         (self.target, process, _, bkpt) = lldbutil.run_to_source_breakpoint(
51             self, "Set break point at this line.", lldb.SBFileSpec("main.cpp", False))
52
53         # This is the function to remove the custom formats in order to have a
54         # clean slate for the next test case.
55         def cleanup():
56             self.runCmd('type format clear', check=False)
57             self.runCmd('type summary clear', check=False)
58             self.runCmd('type filter clear', check=False)
59             self.runCmd('type synth clear', check=False)
60             self.runCmd(
61                 "settings set target.max-children-count 256",
62                 check=False)
63
64         # Execute the cleanup function during test case tear down.
65         self.addTearDownHook(cleanup)
66
67         ii_type = self.getVariableType("ii")
68         self.assertTrue(ii_type.startswith(self.namespace + "::multiset"),
69                         "Type: " + ii_type)
70
71         self.expect("frame variable ii", substrs=["size=0", "{}"])
72         lldbutil.continue_to_breakpoint(process, bkpt)
73         self.expect(
74             "frame variable ii",
75             substrs=[
76                 "size=6",
77                 "[0] = 0",
78                 "[1] = 1",
79                 "[2] = 2",
80                 "[3] = 3",
81                 "[4] = 4",
82                 "[5] = 5"])
83         lldbutil.continue_to_breakpoint(process, bkpt)
84
85         self.check_ii("ii")
86
87         lldbutil.continue_to_breakpoint(process, bkpt)
88         self.expect("frame variable ii", substrs=["size=0", "{}"])
89         lldbutil.continue_to_breakpoint(process, bkpt)
90         self.expect("frame variable ii", substrs=["size=0", "{}"])
91         ss_type = self.getVariableType("ss")
92         self.assertTrue(ss_type.startswith(self.namespace + "::multiset"),
93                         "Type: " + ss_type)
94         self.expect("frame variable ss", substrs=["size=0", "{}"])
95         lldbutil.continue_to_breakpoint(process, bkpt)
96         self.expect(
97             "frame variable ss",
98             substrs=[
99                 "size=2",
100                 '[0] = "a"',
101                 '[1] = "a very long string is right here"'])
102         lldbutil.continue_to_breakpoint(process, bkpt)
103         self.expect(
104             "frame variable ss",
105             substrs=[
106                 "size=4",
107                 '[2] = "b"',
108                 '[3] = "c"',
109                 '[0] = "a"',
110                 '[1] = "a very long string is right here"'])
111         self.expect(
112             "p ss",
113             substrs=[
114                 "size=4",
115                 '[2] = "b"',
116                 '[3] = "c"',
117                 '[0] = "a"',
118                 '[1] = "a very long string is right here"'])
119         self.expect("frame variable ss[2]", substrs=[' = "b"'])
120         lldbutil.continue_to_breakpoint(process, bkpt)
121         self.expect(
122             "frame variable ss",
123             substrs=[
124                 "size=3",
125                 '[0] = "a"',
126                 '[1] = "a very long string is right here"',
127                 '[2] = "c"'])
128
129     @add_test_categories(["libc++"])
130     def test_ref_and_ptr(self):
131         """Test that the data formatters work on ref and ptr."""
132         self.build()
133         (self.target, process, _, bkpt) = lldbutil.run_to_source_breakpoint(
134             self, "Stop here to check by ref and ptr.",
135             lldb.SBFileSpec("main.cpp", False))
136         # The reference should print just like the value:
137         self.check_ii("ref")
138
139         self.expect("frame variable ptr",
140                     substrs=["ptr =", "size=7"])
141         self.expect("expr ptr",
142                     substrs=["size=7"])