1""" 2Test lldb data formatter subsystem. 3""" 4 5 6 7import lldb 8from lldbsuite.test.decorators import * 9from lldbsuite.test.lldbtest import * 10from lldbsuite.test import lldbutil 11 12 13class LibCxxFunctionTestCase(TestBase): 14 15 # Run frame var for a variable twice. Verify we do not hit the cache 16 # the first time but do the second time. 17 def run_frame_var_check_cache_use(self, variable, result_to_match, skip_find_function=False): 18 self.runCmd("log timers reset") 19 self.expect("frame variable " + variable, 20 substrs=[variable + " = " + result_to_match]) 21 if not skip_find_function: 22 self.expect("log timers dump", 23 substrs=["lldb_private::CompileUnit::FindFunction"]) 24 25 self.runCmd("log timers reset") 26 self.expect("frame variable " + variable, 27 substrs=[variable + " = " + result_to_match]) 28 self.expect("log timers dump", 29 matching=False, 30 substrs=["lldb_private::CompileUnit::FindFunction"]) 31 32 33 @add_test_categories(["libc++"]) 34 def test(self): 35 """Test that std::function as defined by libc++ is correctly printed by LLDB""" 36 self.build() 37 self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET) 38 39 bkpt = self.target().FindBreakpointByID( 40 lldbutil.run_break_set_by_source_regexp( 41 self, "Set break point at this line.")) 42 43 self.runCmd("run", RUN_SUCCEEDED) 44 45 # The stop reason of the thread should be breakpoint. 46 self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, 47 substrs=['stopped', 48 'stop reason = breakpoint']) 49 50 self.run_frame_var_check_cache_use("foo2_f", "Lambda in File main.cpp at Line 22") 51 52 lldbutil.continue_to_breakpoint(self.process(), bkpt) 53 54 self.run_frame_var_check_cache_use("add_num2_f", "Lambda in File main.cpp at Line 13") 55 56 lldbutil.continue_to_breakpoint(self.process(), bkpt) 57 58 self.run_frame_var_check_cache_use("f2", "Lambda in File main.cpp at Line 35") 59 self.run_frame_var_check_cache_use("f3", "Lambda in File main.cpp at Line 39", True) 60 # TODO reenable this case when std::function formatter supports 61 # general callable object case. 62 #self.run_frame_var_check_cache_use("f4", "Function in File main.cpp at Line 8") 63 64 # These cases won't hit the cache at all but also don't require 65 # an expensive lookup. 66 self.expect("frame variable f1", 67 substrs=['f1 = Function = foo(int, int)']) 68 69 self.expect("frame variable f5", 70 substrs=['f5 = Function = Bar::add_num(int) const']) 71