b77d01a8086c35156bddd43389f39e40febff273
[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 NSDictionarySyntheticTestCase(TestBase):
14
15     mydir = TestBase.compute_mydir(__file__)
16
17     def setUp(self):
18         # Call super's setUp().
19         TestBase.setUp(self)
20         # Find the line number to break at.
21         self.line = line_number('main.m', '// Set break point at this line.')
22
23     @skipUnlessDarwin
24     def test_rdar11988289_with_run_command(self):
25         """Test that NSDictionary reports its synthetic children properly."""
26         self.build()
27         self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET)
28
29         lldbutil.run_break_set_by_file_and_line(
30             self, "main.m", self.line, num_expected_locations=1, loc_exact=True)
31
32         self.runCmd("run", RUN_SUCCEEDED)
33
34         # The stop reason of the thread should be breakpoint.
35         self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
36                     substrs=['stopped',
37                              'stop reason = breakpoint'])
38
39         # This is the function to remove the custom formats in order to have a
40         # clean slate for the next test case.
41         def cleanup():
42             self.runCmd('type format clear', check=False)
43             self.runCmd('type summary clear', check=False)
44             self.runCmd('type synth clear', check=False)
45
46         # Execute the cleanup function during test case tear down.
47         self.addTearDownHook(cleanup)
48
49         # Now check that we are displaying Cocoa classes correctly
50         self.expect('frame variable dictionary',
51                     substrs=['3 key/value pairs'])
52         self.expect('frame variable mutabledict',
53                     substrs=['4 key/value pairs'])
54         self.expect(
55             'frame variable dictionary --ptr-depth 1',
56             substrs=[
57                 '3 key/value pairs',
58                 '[0] = ',
59                 'key = 0x',
60                 'value = 0x',
61                 '[1] = ',
62                 '[2] = '])
63         self.expect(
64             'frame variable mutabledict --ptr-depth 1',
65             substrs=[
66                 '4 key/value pairs',
67                 '[0] = ',
68                 'key = 0x',
69                 'value = 0x',
70                 '[1] = ',
71                 '[2] = ',
72                 '[3] = '])
73         self.expect(
74             'frame variable dictionary --ptr-depth 1 --dynamic-type no-run-target',
75             substrs=[
76                 '3 key/value pairs',
77                 '@"bar"',
78                 '@"2 elements"',
79                 '@"baz"',
80                 '2 key/value pairs'])
81         self.expect(
82             'frame variable mutabledict --ptr-depth 1 --dynamic-type no-run-target',
83             substrs=[
84                 '4 key/value pairs',
85                 '(int)23',
86                 '@"123"',
87                 '@"http://www.apple.com"',
88                 '@"sourceofstuff"',
89                 '3 key/value pairs'])
90         self.expect(
91             'frame variable mutabledict --ptr-depth 2 --dynamic-type no-run-target',
92             substrs=[
93                 '4 key/value pairs',
94                 '(int)23',
95                 '@"123"',
96                 '@"http://www.apple.com"',
97                 '@"sourceofstuff"',
98                 '3 key/value pairs',
99                 '@"bar"',
100                 '@"2 elements"'])
101         self.expect(
102             'frame variable mutabledict --ptr-depth 3 --dynamic-type no-run-target',
103             substrs=[
104                 '4 key/value pairs',
105                 '(int)23',
106                 '@"123"',
107                 '@"http://www.apple.com"',
108                 '@"sourceofstuff"',
109                 '3 key/value pairs',
110                 '@"bar"',
111                 '@"2 elements"',
112                 '(int)1',
113                 '@"two"'])
114
115         self.assertTrue(
116             self.frame().FindVariable("dictionary").MightHaveChildren(),
117             "dictionary says it does not have children!")
118         self.assertTrue(
119             self.frame().FindVariable("mutabledict").MightHaveChildren(),
120             "mutable says it does not have children!")