e9e570eda5862791717147317f07cda2f2df2e6a
[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 SyntheticFilterRecomputingTestCase(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_rdar12437442_with_run_command(self):
25         """Test that we update SBValues correctly as dynamic types change."""
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 run the bulk of the test
50         id_x = self.dbg.GetSelectedTarget().GetProcess(
51         ).GetSelectedThread().GetSelectedFrame().FindVariable("x")
52         id_x.SetPreferDynamicValue(lldb.eDynamicCanRunTarget)
53         id_x.SetPreferSyntheticValue(True)
54
55         if self.TraceOn():
56             self.runCmd("expr --dynamic-type run-target --ptr-depth 1 -- x")
57
58         self.assertTrue(
59             id_x.GetSummary() == '@"5 elements"',
60             "array does not get correct summary")
61
62         self.runCmd("next")
63         self.runCmd("frame select 0")
64
65         id_x = self.dbg.GetSelectedTarget().GetProcess(
66         ).GetSelectedThread().GetSelectedFrame().FindVariable("x")
67         id_x.SetPreferDynamicValue(lldb.eDynamicCanRunTarget)
68         id_x.SetPreferSyntheticValue(True)
69
70         if self.TraceOn():
71             self.runCmd("expr --dynamic-type run-target --ptr-depth 1 -- x")
72
73         self.assertTrue(
74             id_x.GetNumChildren() == 7,
75             "dictionary does not have 7 children")
76         id_x.SetPreferSyntheticValue(False)
77         self.assertFalse(
78             id_x.GetNumChildren() == 7,
79             "dictionary still looks synthetic")
80         id_x.SetPreferSyntheticValue(True)
81         self.assertTrue(
82             id_x.GetSummary() == "7 key/value pairs",
83             "dictionary does not get correct summary")