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