e597b8d169626ee1967d81ec0160e75161bb9438
[openbsd] /
1 """
2 Test SB API support for identifying artificial (tail call) frames.
3 """
4
5 import lldb
6 import lldbsuite.test.lldbutil as lldbutil
7 from lldbsuite.test.decorators import *
8 from lldbsuite.test.lldbtest import *
9
10 class TestTailCallFrameSBAPI(TestBase):
11     mydir = TestBase.compute_mydir(__file__)
12
13     @skipIf(compiler="clang", compiler_version=['<', '8.0'])
14     @skipIf(dwarf_version=['<', '4'])
15     @expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr26265")
16     def test_tail_call_frame_sbapi(self):
17         self.build()
18         self.do_test()
19
20     def do_test(self):
21         exe = self.getBuildArtifact("a.out")
22
23         # Create a target by the debugger.
24         target = self.dbg.CreateTarget(exe)
25         self.assertTrue(target, VALID_TARGET)
26
27         breakpoint = target.BreakpointCreateBySourceRegex("break here",
28                 lldb.SBFileSpec("main.cpp"))
29         self.assertTrue(breakpoint and
30                         breakpoint.GetNumLocations() == 1,
31                         VALID_BREAKPOINT)
32
33         error = lldb.SBError()
34         launch_info = lldb.SBLaunchInfo(None)
35         process = target.Launch(launch_info, error)
36         self.assertTrue(process, PROCESS_IS_VALID)
37
38         # Did we hit our breakpoint?
39         threads = lldbutil.get_threads_stopped_at_breakpoint(process,
40                 breakpoint)
41         self.assertEqual(
42             len(threads), 1,
43             "There should be a thread stopped at our breakpoint")
44
45         self.assertEqual(breakpoint.GetHitCount(), 1)
46
47         thread = threads[0]
48
49         # Here's what we expect to see in the backtrace:
50         #   frame #0: ... a.out`sink() at main.cpp:13:4 [opt]
51         #   frame #1: ... a.out`func3() at main.cpp:14:1 [opt] [artificial]
52         #   frame #2: ... a.out`func2() at main.cpp:18:62 [opt]
53         #   frame #3: ... a.out`func1() at main.cpp:18:85 [opt] [artificial]
54         #   frame #4: ... a.out`main at main.cpp:23:3 [opt]
55         names = ["sink", "func3", "func2", "func1", "main"]
56         artificiality = [False, True, False, True, False]
57         for idx, (name, is_artificial) in enumerate(zip(names, artificiality)):
58             frame = thread.GetFrameAtIndex(idx)
59
60             # Use a relaxed substring check because function dislpay names are
61             # platform-dependent. E.g we see "void sink(void)" on Windows, but
62             # "sink()" on Darwin. This seems like a bug -- just work around it
63             # for now.
64             self.assertTrue(name in frame.GetDisplayFunctionName())
65             self.assertEqual(frame.IsArtificial(), is_artificial)