2 Test lldb data formatter subsystem.
5 from __future__ import print_function
11 from lldbsuite.test.lldbtest import *
12 import lldbsuite.test.lldbutil as lldbutil
15 class ScriptDataFormatterTestCase(TestBase):
17 mydir = TestBase.compute_mydir(__file__)
19 def test_with_run_command(self):
20 """Test data formatter commands."""
22 self.data_formatter_commands()
25 # Call super's setUp().
27 # Find the line number to break at.
28 self.line = line_number('main.cpp', '// Set break point at this line.')
30 def data_formatter_commands(self):
31 """Test that that file and class static variables display correctly."""
32 self.runCmd("file a.out", CURRENT_EXECUTABLE_SET)
34 lldbutil.run_break_set_by_file_and_line(
35 self, "main.cpp", self.line, num_expected_locations=1, loc_exact=True)
37 self.runCmd("run", RUN_SUCCEEDED)
39 # The stop reason of the thread should be breakpoint.
40 self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
42 'stop reason = breakpoint'])
44 # This is the function to remove the custom formats in order to have a
45 # clean slate for the next test case.
47 self.runCmd('type format clear', check=False)
48 self.runCmd('type summary clear', check=False)
50 # Execute the cleanup function during test case tear down.
51 self.addTearDownHook(cleanup)
53 # Set the script here to ease the formatting
54 script = 'a = valobj.GetChildMemberWithName(\'integer\'); a_val = a.GetValue(); str = \'Hello from Python, \' + a_val + \' time\'; return str + (\'!\' if a_val == \'1\' else \'s!\');'
57 "type summary add i_am_cool --python-script \"%s\"" %
59 self.expect('type summary list i_am_cool', substrs=[script])
61 self.expect("frame variable one",
62 substrs=['Hello from Python',
65 self.expect("frame variable two",
66 substrs=['Hello from Python',
69 self.runCmd("n") # skip ahead to make values change
71 self.expect("frame variable three",
72 substrs=['Hello from Python, 10 times!',
73 'Hello from Python, 4 times!'])
75 self.runCmd("n") # skip ahead to make values change
77 self.expect("frame variable two",
78 substrs=['Hello from Python',
81 script = 'a = valobj.GetChildMemberWithName(\'integer\'); a_val = a.GetValue(); str = \'int says \' + a_val; return str;'
83 # Check that changes in the script are immediately reflected
85 "type summary add i_am_cool --python-script \"%s\"" %
88 self.expect("frame variable two",
89 substrs=['int says 1'])
91 self.expect("frame variable twoptr",
92 substrs=['int says 1'])
96 "type summary add --summary-string \"int says ${var.integer}, and float says ${var.floating}\" i_am_cool")
98 self.expect("frame variable two",
99 substrs=['int says 1',
100 'and float says 2.71'])
101 # Try it for pointers
102 self.expect("frame variable twoptr",
103 substrs=['int says 1',
104 'and float says 2.71'])
106 # Force a failure for pointers
108 "type summary add i_am_cool -p --python-script \"%s\"" %
111 self.expect("frame variable twoptr", matching=False,
112 substrs=['and float says 2.71'])
114 script = 'return \'Python summary\''
117 "type summary add --name test_summary --python-script \"%s\"" %
120 # attach the Python named summary to someone
121 self.expect("frame variable one --summary test_summary",
122 substrs=['Python summary'])
124 # should not bind to the type
125 self.expect("frame variable two", matching=False,
126 substrs=['Python summary'])
128 # and should not stick to the variable
129 self.expect("frame variable one", matching=False,
130 substrs=['Python summary'])
133 "type summary add i_am_cool --summary-string \"Text summary\"")
135 # should be temporary only
136 self.expect("frame variable one", matching=False,
137 substrs=['Python summary'])
139 # use the type summary
140 self.expect("frame variable two",
141 substrs=['Text summary'])
143 self.runCmd("n") # skip ahead to make values change
145 # both should use the type summary now
146 self.expect("frame variable one",
147 substrs=['Text summary'])
149 self.expect("frame variable two",
150 substrs=['Text summary'])
152 # disable type summary for pointers, and make a Python regex summary
154 "type summary add i_am_cool -p --summary-string \"Text summary\"")
155 self.runCmd("type summary add -x cool --python-script \"%s\"" % script)
157 # variables should stick to the type summary
158 self.expect("frame variable one",
159 substrs=['Text summary'])
161 self.expect("frame variable two",
162 substrs=['Text summary'])
164 # array and pointer should match the Python one
165 self.expect("frame variable twoptr",
166 substrs=['Python summary'])
168 self.expect("frame variable array",
169 substrs=['Python summary'])
171 # return pointers to the type summary
173 "type summary add i_am_cool --summary-string \"Text summary\"")
175 self.expect("frame variable one",
176 substrs=['Text summary'])
178 self.expect("frame variable two",
179 substrs=['Text summary'])
181 self.expect("frame variable twoptr",
182 substrs=['Text summary'])
184 self.expect("frame variable array",
185 substrs=['Python summary'])