brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.6 KiB · dbf581e Raw
76 lines · python
1"""2Test the SB API SBFrame::GuessLanguage.3"""4 5 6import lldb7import lldbsuite.test.lldbutil as lldbutil8from lldbsuite.test.decorators import *9from lldbsuite.test.lldbtest import *10 11 12class TestFrameGuessLanguage(TestBase):13    # If your test case doesn't stress debug info, then14    # set this to true.  That way it won't be run once for15    # each debug info format.16    NO_DEBUG_INFO_TESTCASE = True17 18    @skipIf(compiler="clang", compiler_version=["<", "10.0"])19    @expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr37658")20    def test_guess_language(self):21        """Test GuessLanguage for C and C++."""22        self.build()23        self.do_test()24 25    def check_language(self, thread, frame_no, test_lang):26        frame = thread.frames[frame_no]27        self.assertTrue(frame.IsValid(), "Frame %d was not valid." % (frame_no))28        lang = frame.GuessLanguage()29        self.assertEqual(lang, test_lang)30 31    def do_test(self):32        """Test GuessLanguage for C & C++."""33        target = self.createTestTarget()34 35        # Now create a breakpoint in main.c at the source matching36        # "Set a breakpoint here"37        breakpoint = target.BreakpointCreateBySourceRegex(38            "Set breakpoint here", lldb.SBFileSpec("somefunc.c")39        )40        self.assertTrue(41            breakpoint and breakpoint.GetNumLocations() >= 1, VALID_BREAKPOINT42        )43 44        error = lldb.SBError()45        # This is the launch info.  If you want to launch with arguments or46        # environment variables, add them using SetArguments or47        # SetEnvironmentEntries48 49        launch_info = target.GetLaunchInfo()50        process = target.Launch(launch_info, error)51        self.assertTrue(process, PROCESS_IS_VALID)52 53        # Did we hit our breakpoint?54        from lldbsuite.test.lldbutil import get_threads_stopped_at_breakpoint55 56        threads = get_threads_stopped_at_breakpoint(process, breakpoint)57        self.assertEqual(58            len(threads), 1, "There should be a thread stopped at our breakpoint"59        )60 61        # The hit count for the breakpoint should be 1.62        self.assertEqual(breakpoint.GetHitCount(), 1)63 64        thread = threads[0]65 66        c_frame_language = lldb.eLanguageTypeC9967        cxx_frame_language = lldb.eLanguageTypeC_plus_plus_1168        # gcc emits DW_LANG_C89 even if -std=c99 was specified69        if "gcc" in self.getCompiler():70            c_frame_language = lldb.eLanguageTypeC8971            cxx_frame_language = lldb.eLanguageTypeC_plus_plus72 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