738df85d0519349b45f8e5e0916793ceeb12326a
[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 LibcxxSetDataFormatterTestCase(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 + "::set"),
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=["size=6",
76                      "[0] = 0",
77                      "[1] = 1",
78                      "[2] = 2",
79                      "[3] = 3",
80                      "[4] = 4",
81                      "[5] = 5"])
82         lldbutil.continue_to_breakpoint(process, bkpt)
83         self.check_ii("ii")
84
85         lldbutil.continue_to_breakpoint(process, bkpt)
86         self.expect("frame variable ii", substrs=["size=0", "{}"])
87         lldbutil.continue_to_breakpoint(process, bkpt)
88         self.expect("frame variable ii", substrs=["size=0", "{}"])
89
90         ss_type = self.getVariableType("ss")
91         self.assertTrue(ii_type.startswith(self.namespace + "::set"),
92                         "Type: " + ss_type)
93
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=["size=2",
99                      '[0] = "a"',
100                      '[1] = "a very long string is right here"'])
101         lldbutil.continue_to_breakpoint(process, bkpt)
102         self.expect(
103             "frame variable ss",
104             substrs=["size=4",
105                      '[2] = "b"',
106                      '[3] = "c"',
107                      '[0] = "a"',
108                      '[1] = "a very long string is right here"'])
109         self.expect(
110             "p ss",
111             substrs=["size=4",
112                      '[2] = "b"',
113                      '[3] = "c"',
114                      '[0] = "a"',
115                      '[1] = "a very long string is right here"'])
116         self.expect("frame variable ss[2]", substrs=[' = "b"'])
117         lldbutil.continue_to_breakpoint(process, bkpt)
118         self.expect(
119             "frame variable ss",
120             substrs=["size=3",
121                      '[0] = "a"',
122                      '[1] = "a very long string is right here"',
123                      '[2] = "c"'])
124
125     @add_test_categories(["libc++"])
126     def test_ref_and_ptr(self):
127         """Test that the data formatters work on ref and ptr."""
128         self.build()
129         (self.target, process, _, bkpt) = lldbutil.run_to_source_breakpoint(
130             self, "Stop here to check by ref and ptr.",
131             lldb.SBFileSpec("main.cpp", False))
132         # The reference should print just like the value:
133         self.check_ii("ref")
134
135         self.expect("frame variable ptr",
136                     substrs=["ptr =", "size=7"])
137         self.expect("expr ptr",
138                     substrs=["size=7"])
139