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
10class BuiltinDebugTrapTestCase(TestBase):
11
12    mydir = TestBase.compute_mydir(__file__)
13
14    NO_DEBUG_INFO_TESTCASE = True
15
16    # Currently this depends on behavior in debugserver to
17    # advance the pc past __builtin_trap instructions so that
18    # continue works.  Everyone is in agreement that this
19    # should be moved up into lldb instead of depending on the
20    # remote stub rewriting the pc values.
21    @skipUnlessDarwin
22
23    def test(self):
24        self.build()
25        (target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(
26            self, "// Set a breakpoint here", lldb.SBFileSpec("main.cpp"))
27
28        # Continue to __builtin_debugtrap()
29        process.Continue()
30        if self.TraceOn():
31            self.runCmd("f")
32            self.runCmd("bt")
33            self.runCmd("ta v global")
34
35        self.assertEqual(process.GetSelectedThread().GetStopReason(),
36                         lldb.eStopReasonException)
37
38        list = target.FindGlobalVariables("global", 1, lldb.eMatchTypeNormal)
39        self.assertEqual(list.GetSize(), 1)
40        global_value = list.GetValueAtIndex(0)
41
42        self.assertEqual(global_value.GetValueAsUnsigned(), 5)
43
44        # Continue to the __builtin_trap() -- we should be able to
45        # continue past __builtin_debugtrap.
46        process.Continue()
47        if self.TraceOn():
48            self.runCmd("f")
49            self.runCmd("bt")
50            self.runCmd("ta v global")
51
52        self.assertEqual(process.GetSelectedThread().GetStopReason(),
53                         lldb.eStopReasonException)
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(process.GetSelectedThread().GetStopReason(),
67                         lldb.eStopReasonException)
68
69        # "global" is still 10.
70        self.assertEqual(global_value.GetValueAsUnsigned(), 10)
71