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, the 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 exe = self.getBuildArtifact("a.out") 38 39 # Create a target by the debugger. 40 target = self.dbg.CreateTarget(exe) 41 self.assertTrue(target, VALID_TARGET) 42 43 # Now create a breakpoint in main.c at the source matching 44 # "Set a breakpoint here" 45 breakpoint = target.BreakpointCreateBySourceRegex( 46 "Set breakpoint here", lldb.SBFileSpec("somefunc.c")) 47 self.assertTrue(breakpoint and 48 breakpoint.GetNumLocations() >= 1, 49 VALID_BREAKPOINT) 50 51 error = lldb.SBError() 52 # This is the launch info. If you want to launch with arguments or 53 # environment variables, add them using SetArguments or 54 # SetEnvironmentEntries 55 56 launch_info = target.GetLaunchInfo() 57 process = target.Launch(launch_info, error) 58 self.assertTrue(process, PROCESS_IS_VALID) 59 60 # Did we hit our breakpoint? 61 from lldbsuite.test.lldbutil import get_threads_stopped_at_breakpoint 62 threads = get_threads_stopped_at_breakpoint(process, breakpoint) 63 self.assertTrue( 64 len(threads) == 1, 65 "There should be a thread stopped at our breakpoint") 66 67 # The hit count for the breakpoint should be 1. 68 self.assertEquals(breakpoint.GetHitCount(), 1) 69 70 thread = threads[0] 71 72 c_frame_language = lldb.eLanguageTypeC99 73 cxx_frame_language = lldb.eLanguageTypeC_plus_plus_11 74 # gcc emits DW_LANG_C89 even if -std=c99 was specified 75 if "gcc" in self.getCompiler(): 76 c_frame_language = lldb.eLanguageTypeC89 77 cxx_frame_language = lldb.eLanguageTypeC_plus_plus 78 79 self.check_language(thread, 0, c_frame_language) 80 self.check_language(thread, 1, cxx_frame_language) 81 self.check_language(thread, 2, lldb.eLanguageTypeC_plus_plus) 82 83 84 85