xref: /llvm-project/lldb/test/API/macosx/builtin-debugtrap/TestBuiltinDebugTrap.py (revision 2238dcc39358353cac21df75c3c3286ab20b8f53)
1"""
2Test that lldb can continue past a __builtin_debugtrap, but not a __builtin_trap
3"""
4
5import lldb
6import lldbsuite.test.lldbutil as lldbutil
7from lldbsuite.test.decorators import *
8from lldbsuite.test.lldbtest import *
9
10
11class BuiltinDebugTrapTestCase(TestBase):
12    NO_DEBUG_INFO_TESTCASE = True
13
14    # Currently this depends on behavior in debugserver to
15    # advance the pc past __builtin_trap instructions so that
16    # continue works.  Everyone is in agreement that this
17    # should be moved up into lldb instead of depending on the
18    # remote stub rewriting the pc values.
19    @skipUnlessDarwin
20    def test(self):
21        self.build()
22        (target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(
23            self, "// Set a breakpoint here", lldb.SBFileSpec("main.cpp")
24        )
25
26        # Continue to __builtin_debugtrap()
27        process.Continue()
28        if self.TraceOn():
29            self.runCmd("f")
30            self.runCmd("bt")
31            self.runCmd("ta v global")
32
33        self.assertEqual(
34            process.GetSelectedThread().GetStopReason(), lldb.eStopReasonException
35        )
36
37        list = target.FindGlobalVariables("global", 1, lldb.eMatchTypeNormal)
38        self.assertEqual(list.GetSize(), 1)
39        global_value = list.GetValueAtIndex(0)
40
41        self.assertEqual(global_value.GetValueAsUnsigned(), 5)
42
43        # Continue to the __builtin_trap() -- we should be able to
44        # continue past __builtin_debugtrap.
45        process.Continue()
46        if self.TraceOn():
47            self.runCmd("f")
48            self.runCmd("bt")
49            self.runCmd("ta v global")
50
51        self.assertEqual(
52            process.GetSelectedThread().GetStopReason(), lldb.eStopReasonException
53        )
54
55        # "global" is now 10.
56        self.assertEqual(global_value.GetValueAsUnsigned(), 10)
57
58        # We should be at the same point as before -- cannot advance
59        # past a __builtin_trap().
60        process.Continue()
61        if self.TraceOn():
62            self.runCmd("f")
63            self.runCmd("bt")
64            self.runCmd("ta v global")
65
66        self.assertEqual(
67            process.GetSelectedThread().GetStopReason(), lldb.eStopReasonException
68        )
69
70        # "global" is still 10.
71        self.assertEqual(global_value.GetValueAsUnsigned(), 10)
72