brintos

brintos / llvm-project-archived public Read only

0
0
Text · 3.2 KiB · 280ac71 Raw
77 lines · python
1import lldb2from lldbsuite.test.decorators import *3from lldbsuite.test.lldbtest import *4from lldbsuite.test import lldbutil5 6import re7 8@skipIf(macos_version=[">=", "15.4"], asan=True)9class LibCxxInternalsRecognizerTestCase(TestBase):10    NO_DEBUG_INFO_TESTCASE = True11 12    @add_test_categories(["libc++"])13    @skipIf(compiler="clang", compiler_version=["<", "21.0"])14    def test_frame_recognizer(self):15        """Test that implementation details of libc++ are hidden"""16        self.build()17        (target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(18            self, "break here", lldb.SBFileSpec("main.cpp")19        )20 21        expected_parents = {22            "sort_less(int, int)": ["::sort", "test_algorithms"],23            # `std::ranges::sort` is implemented as an object of types `__sort`.24            # We never hide the frame of the entry-point into the standard library, even25            # if the name starts with `__` which usually indicates an internal function.26            "ranges_sort_less(int, int)": [27                re.compile(r"ranges::__sort::(__fn::)?operator\(\)"),28                "test_algorithms",29            ],30            # `ranges::views::transform` internally uses `std::invoke`, and that31            # call also shows up in the stack trace32            "view_transform(int)": [33                "::invoke",34                "ranges::transform_view",35                "test_algorithms",36            ],37            # Various types of `invoke` calls38            "consume_number(int)": ["::invoke", "test_invoke"],39            "invoke_add(int, int)": ["::invoke", "test_invoke"],40            "Callable::member_function(int) const": ["::invoke", "test_invoke"],41            "Callable::operator()(int) const": ["::invoke", "test_invoke"],42            # Containers43            "MyKey::operator<(MyKey const&) const": [44                "::operator()",45                "less",46                "::emplace",47                "test_containers",48            ],49        }50        stop_set = set()51        while process.GetState() != lldb.eStateExited:52            fn = thread.GetFrameAtIndex(0).GetFunctionName()53            stop_set.add(fn)54            self.assertIn(fn, expected_parents.keys())55            frame_id = 156            for expected_parent in expected_parents[fn]:57                # Skip all hidden frames58                while (59                    frame_id < thread.GetNumFrames()60                    and thread.GetFrameAtIndex(frame_id).IsHidden()61                ):62                    frame_id = frame_id + 163                # Expect the correct parent frame64                func_name = thread.GetFrameAtIndex(frame_id).GetFunctionName()65                if isinstance(expected_parent, re.Pattern):66                    self.assertTrue(67                        expected_parent.search(func_name) is not None,68                        f"'{expected_parent}' not found in '{func_name}'"69                    )70                else:71                    self.assertIn(expected_parent, func_name)72                frame_id = frame_id + 173            process.Continue()74 75        # Make sure that we actually verified all intended scenarios76        self.assertEqual(len(stop_set), len(expected_parents))77