xref: /llvm-project/lldb/test/API/lang/cpp/std-function-recognizer/TestStdFunctionRecognizer.py (revision f01f80ce6ca7640bb0e267b84b1ed0e89b57e2d9)
1import lldb
2from lldbsuite.test.decorators import *
3from lldbsuite.test.lldbtest import *
4from lldbsuite.test import lldbutil
5
6
7class LibCxxStdFunctionRecognizerTestCase(TestBase):
8    NO_DEBUG_INFO_TESTCASE = True
9
10    @add_test_categories(["libc++"])
11    def test_backtrace(self):
12        """Test that std::function implementation details are hidden in bt"""
13        self.build()
14        (target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(
15            self, "// break here", lldb.SBFileSpec("main.cpp")
16        )
17        # Filtered.
18        self.expect(
19            "thread backtrace",
20            ordered=True,
21            substrs=["frame", "foo", "frame", "main"],
22        )
23        self.expect(
24            "thread backtrace", matching=False, patterns=["frame.*std::__1::__function"]
25        )
26        # Unfiltered.
27        self.expect(
28            "thread backtrace -u",
29            ordered=True,
30            patterns=["frame.*foo", "frame.*std::__1::__function", "frame.*main"],
31        )
32        self.expect(
33            "thread backtrace --unfiltered",
34            ordered=True,
35            patterns=["frame.*foo", "frame.*std::__1::__function", "frame.*main"],
36        )
37
38    @add_test_categories(["libc++"])
39    def test_up_down(self):
40        """Test that std::function implementation details are skipped"""
41        self.build()
42        (target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(
43            self, "// break here", lldb.SBFileSpec("main.cpp")
44        )
45        frame = thread.GetSelectedFrame()
46        # up
47        self.assertIn("foo", frame.GetFunctionName())
48        start_idx = frame.GetFrameID()
49        i = 0
50        while i < thread.GetNumFrames():
51            self.expect("up")
52            frame = thread.GetSelectedFrame()
53            if frame.GetFunctionName() == "main":
54                break
55        end_idx = frame.GetFrameID()
56        self.assertLess(i, end_idx - start_idx, "skipped frames")
57
58        # Back down again.
59        start_idx = frame.GetFrameID()
60        for i in range(1, thread.GetNumFrames()):
61            self.expect("down")
62            frame = thread.GetSelectedFrame()
63            if "foo" in frame.GetFunctionName():
64                break
65        end_idx = frame.GetFrameID()
66        self.assertLess(i, start_idx - end_idx, "skipped frames")
67
68    @add_test_categories(["libc++"])
69    def test_api(self):
70        """Test that std::function implementation details are skipped"""
71        self.build()
72        (target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(
73            self, "// break here", lldb.SBFileSpec("main.cpp")
74        )
75        frame = thread.GetSelectedFrame()
76        num_hidden = 0
77        for i in range(1, thread.GetNumFrames()):
78            thread.SetSelectedFrame(i)
79            frame = thread.GetSelectedFrame()
80            if frame.IsHidden():
81                num_hidden += 1
82
83        self.assertGreater(num_hidden, 0)
84        self.assertLess(num_hidden, thread.GetNumFrames())
85