1"""
2Test lldb ability to unwind a stack with a function containing a call to the
3'__builtin_trap' intrinsic, which GCC (4.6) encodes to an illegal opcode.
4"""
5
6
7
8import lldb
9from lldbsuite.test.decorators import *
10from lldbsuite.test.lldbtest import *
11from lldbsuite.test import lldbutil
12
13
14class BuiltinTrapTestCase(TestBase):
15
16    mydir = TestBase.compute_mydir(__file__)
17
18    def setUp(self):
19        # Call super's setUp().
20        TestBase.setUp(self)
21        # Find the line number to break at.
22        self.line = line_number('main.cpp', '// Set break point at this line.')
23
24    # gcc generates incorrect linetable
25    @expectedFailureAll(archs="arm", compiler="gcc", triple=".*-android")
26    @expectedFailureAll(archs=['aarch64'], oslist=no_match(['freebsd', 'linux']))
27    @skipIfWindows
28    def test_with_run_command(self):
29        """Test that LLDB handles a function with __builtin_trap correctly."""
30        self.build()
31        self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET)
32
33        lldbutil.run_break_set_by_file_and_line(self, "main.cpp", self.line,
34                                                num_expected_locations=1,
35                                                loc_exact=True)
36
37        self.runCmd("run", RUN_SUCCEEDED)
38
39        # The stop reason of the thread should be breakpoint.
40        self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
41                    substrs=['stopped',
42                             'stop reason = breakpoint'])
43
44        # print backtrace, expect both 'bar' and 'main' functions to be listed
45        self.expect('bt', substrs=['bar', 'main'])
46
47        # go up one frame
48        self.runCmd("up", RUN_SUCCEEDED)
49
50        # evaluate a local
51        self.expect('p foo', substrs=['= 5'])
52