1""" 2Test lldb data formatter subsystem. 3""" 4 5 6import lldb 7from lldbsuite.test.decorators import * 8from lldbsuite.test.lldbtest import * 9from lldbsuite.test import lldbutil 10 11 12class DataFormatterVarScriptFormatting(TestBase): 13 def setUp(self): 14 # Call super's setUp(). 15 TestBase.setUp(self) 16 # Find the line number to break at. 17 self.line = line_number("main.cpp", " // Set breakpoint here.") 18 19 def test_with_run_command(self): 20 """Test using Python synthetic children provider.""" 21 self.build() 22 self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET) 23 24 lldbutil.run_break_set_by_file_and_line( 25 self, "main.cpp", self.line, num_expected_locations=1, loc_exact=True 26 ) 27 28 self.runCmd("run", RUN_SUCCEEDED) 29 30 # The stop reason of the thread should be breakpoint. 31 self.expect( 32 "thread list", 33 STOPPED_DUE_TO_BREAKPOINT, 34 substrs=["stopped", "stop reason = breakpoint"], 35 ) 36 37 # This is the function to remove the custom formats in order to have a 38 # clean slate for the next test case. 39 def cleanup(): 40 self.runCmd("type format clear", check=False) 41 self.runCmd("type summary clear", check=False) 42 self.runCmd("type filter clear", check=False) 43 self.runCmd("type synth clear", check=False) 44 45 # Execute the cleanup function during test case tear down. 46 self.addTearDownHook(cleanup) 47 48 self.runCmd("command script import helperfunc.py") 49 self.runCmd( 50 'type summary add -x "^something<.*>$" -s "T is a ${script.var:helperfunc.f}"' 51 ) 52 53 self.expect("frame variable x", substrs=["T is a non-pointer type"]) 54 55 self.expect("frame variable y", substrs=["T is a pointer type"]) 56