2 Test lldb data formatter subsystem.
5 from __future__ import print_function
9 from lldbsuite.test.decorators import *
10 from lldbsuite.test.lldbtest import *
11 from lldbsuite.test import lldbutil
14 class DataFormatterSynthValueTestCase(TestBase):
16 mydir = TestBase.compute_mydir(__file__)
19 # Call super's setUp().
21 # Find the line number to break at.
22 self.line = line_number('main.cpp', 'break here')
24 @skipIfFreeBSD # llvm.org/pr20545 bogus output confuses buildbot parser
25 def test_with_run_command(self):
26 """Test using Python synthetic children provider to provide a value."""
28 self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET)
30 lldbutil.run_break_set_by_file_and_line(
31 self, "main.cpp", self.line, num_expected_locations=1, loc_exact=True)
33 self.runCmd("run", RUN_SUCCEEDED)
35 # The stop reason of the thread should be breakpoint.
36 self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
38 'stop reason = breakpoint'])
40 # This is the function to remove the custom formats in order to have a
41 # clean slate for the next test case.
43 self.runCmd('type format clear', check=False)
44 self.runCmd('type summary clear', check=False)
45 self.runCmd('type filter clear', check=False)
46 self.runCmd('type synth clear', check=False)
48 # Execute the cleanup function during test case tear down.
49 self.addTearDownHook(cleanup)
51 x = self.frame().FindVariable("x")
52 x.SetPreferSyntheticValue(True)
53 y = self.frame().FindVariable("y")
54 y.SetPreferSyntheticValue(True)
55 z = self.frame().FindVariable("z")
56 z.SetPreferSyntheticValue(True)
57 q = self.frame().FindVariable("q")
58 z.SetPreferSyntheticValue(True)
60 x_val = x.GetValueAsUnsigned
61 y_val = y.GetValueAsUnsigned
62 z_val = z.GetValueAsUnsigned
63 q_val = q.GetValueAsUnsigned
67 "x_val = %s; y_val = %s; z_val = %s; q_val = %s" %
68 (x_val(), y_val(), z_val(), q_val()))
70 self.assertFalse(x_val() == 3, "x == 3 before synthetics")
71 self.assertFalse(y_val() == 4, "y == 4 before synthetics")
72 self.assertFalse(z_val() == 7, "z == 7 before synthetics")
73 self.assertFalse(q_val() == 8, "q == 8 before synthetics")
75 # now set up the synth
76 self.runCmd("script from myIntSynthProvider import *")
77 self.runCmd("type synth add -l myIntSynthProvider myInt")
78 self.runCmd("type synth add -l myArraySynthProvider myArray")
79 self.runCmd("type synth add -l myIntSynthProvider myIntAndStuff")
83 "x_val = %s; y_val = %s; z_val = %s; q_val = %s" %
84 (x_val(), y_val(), z_val(), q_val()))
86 self.assertTrue(x_val() == 3, "x != 3 after synthetics")
87 self.assertTrue(y_val() == 4, "y != 4 after synthetics")
88 self.assertTrue(z_val() == 7, "z != 7 after synthetics")
89 self.assertTrue(q_val() == 8, "q != 8 after synthetics")
91 self.expect("frame variable x", substrs=['3'])
94 substrs=['theValue = 3'],
96 self.expect("frame variable q", substrs=['8'])
99 substrs=['theValue = 8'],
102 # check that an aptly defined synthetic provider does not affect
105 "expression struct Struct { myInt theInt{12}; }; Struct()",
106 substrs=['(theInt = 12)'])
108 # check that we can use a synthetic value in a summary
109 self.runCmd("type summary add hasAnInt -s ${var.theInt}")
110 hi = self.frame().FindVariable("hi")
111 self.assertEqual(hi.GetSummary(), "42")
113 ma = self.frame().FindVariable("ma")
114 self.assertTrue(ma.IsValid())
115 self.assertEqual(ma.GetNumChildren(15), 15)
116 self.assertEqual(ma.GetNumChildren(16), 16)
117 self.assertEqual(ma.GetNumChildren(17), 16)