1""" 2Test API logging. 3""" 4 5import re 6 7import lldb 8import lldbsuite.test.lldbutil as lldbutil 9from lldbsuite.test.lldbtest import * 10 11 12class APILogTestCase(TestBase): 13 14 mydir = TestBase.compute_mydir(__file__) 15 16 NO_DEBUG_INFO_TESTCASE = True 17 18 def test_api_log(self): 19 """Test API logging""" 20 logfile = self.getBuildArtifact("api-log.txt") 21 22 def cleanup(): 23 if os.path.exists(logfile): 24 os.unlink(logfile) 25 26 if configuration.is_reproducer_replay(): 27 logfile = self.getReproducerRemappedPath(logfile) 28 29 self.addTearDownHook(cleanup) 30 self.expect("log enable lldb api -f {}".format(logfile)) 31 32 self.dbg.SetDefaultArchitecture(None) 33 self.dbg.GetScriptingLanguage(None) 34 target = self.dbg.CreateTarget(None) 35 36 self.assertTrue(os.path.isfile(logfile)) 37 with open(logfile, 'r') as f: 38 log = f.read() 39 40 # Find the SBDebugger's address. 41 debugger_addr = re.findall( 42 r"lldb::SBDebugger::GetScriptingLanguage\([^)]*\) \(0x([0-9a-fA-F]+),", 43 log) 44 45 # Make sure we've found a match. 46 self.assertTrue(debugger_addr, log) 47 48 # Make sure the GetScriptingLanguage matches. 49 self.assertTrue(re.search(r'lldb::SBDebugger::GetScriptingLanguage\([^)]*\) \(0x{}, ""\)'.format( 50 debugger_addr[0]), log), log) 51 52 # Make sure the address matches. 53 self.assertTrue(re.search(r'lldb::SBDebugger::CreateTarget\([^)]*\) \(0x{}, ""\)'.format( 54 debugger_addr[0]), log), log) 55