1""" 2Test the SB API SBFrame::GuessLanguage. 3""" 4 5 6 7import lldb 8import lldbsuite.test.lldbutil as lldbutil 9from lldbsuite.test.decorators import * 10from lldbsuite.test.lldbtest import * 11 12 13class TestFrameGuessLanguage(TestBase): 14 15 # If your test case doesn't stress debug info, then 16 # set this to true. That way it won't be run once for 17 # each debug info format. 18 NO_DEBUG_INFO_TESTCASE = True 19 20 @skipIf(compiler="clang", compiler_version=['<', '10.0']) 21 @expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr37658") 22 def test_guess_language(self): 23 """Test GuessLanguage for C and C++.""" 24 self.build() 25 self.do_test() 26 27 def check_language(self, thread, frame_no, test_lang): 28 frame = thread.frames[frame_no] 29 self.assertTrue(frame.IsValid(), "Frame %d was not valid."%(frame_no)) 30 lang = frame.GuessLanguage() 31 self.assertEqual(lang, test_lang) 32 33 def do_test(self): 34 """Test GuessLanguage for C & C++.""" 35 target = self.createTestTarget() 36 37 # Now create a breakpoint in main.c at the source matching 38 # "Set a breakpoint here" 39 breakpoint = target.BreakpointCreateBySourceRegex( 40 "Set breakpoint here", lldb.SBFileSpec("somefunc.c")) 41 self.assertTrue(breakpoint and 42 breakpoint.GetNumLocations() >= 1, 43 VALID_BREAKPOINT) 44 45 error = lldb.SBError() 46 # This is the launch info. If you want to launch with arguments or 47 # environment variables, add them using SetArguments or 48 # SetEnvironmentEntries 49 50 launch_info = target.GetLaunchInfo() 51 process = target.Launch(launch_info, error) 52 self.assertTrue(process, PROCESS_IS_VALID) 53 54 # Did we hit our breakpoint? 55 from lldbsuite.test.lldbutil import get_threads_stopped_at_breakpoint 56 threads = get_threads_stopped_at_breakpoint(process, breakpoint) 57 self.assertEqual( 58 len(threads), 1, 59 "There should be a thread stopped at our breakpoint") 60 61 # The hit count for the breakpoint should be 1. 62 self.assertEquals(breakpoint.GetHitCount(), 1) 63 64 thread = threads[0] 65 66 c_frame_language = lldb.eLanguageTypeC99 67 cxx_frame_language = lldb.eLanguageTypeC_plus_plus_11 68 # gcc emits DW_LANG_C89 even if -std=c99 was specified 69 if "gcc" in self.getCompiler(): 70 c_frame_language = lldb.eLanguageTypeC89 71 cxx_frame_language = lldb.eLanguageTypeC_plus_plus 72 73 self.check_language(thread, 0, c_frame_language) 74 self.check_language(thread, 1, cxx_frame_language) 75 self.check_language(thread, 2, lldb.eLanguageTypeC_plus_plus) 76 77 78 79