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    def setUp(self):
17        # Call super's setUp().
18        TestBase.setUp(self)
19        # Find the line number to break at.
20        self.line = line_number('main.cpp', '// Set break point at this line.')
21
22    # gcc generates incorrect linetable
23    @expectedFailureAll(archs="arm", compiler="gcc", triple=".*-android")
24    @expectedFailureAll(archs=['aarch64'], oslist=no_match(['freebsd', 'linux']))
25    @skipIfWindows
26    def test_with_run_command(self):
27        """Test that LLDB handles a function with __builtin_trap correctly."""
28        self.build()
29        self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET)
30
31        lldbutil.run_break_set_by_file_and_line(self, "main.cpp", self.line,
32                                                num_expected_locations=1,
33                                                loc_exact=True)
34
35        self.runCmd("run", RUN_SUCCEEDED)
36
37        # The stop reason of the thread should be breakpoint.
38        self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
39                    substrs=['stopped',
40                             'stop reason = breakpoint'])
41
42        # print backtrace, expect both 'bar' and 'main' functions to be listed
43        self.expect('bt', substrs=['bar', 'main'])
44
45        # go up one frame
46        self.runCmd("up", RUN_SUCCEEDED)
47
48        # evaluate a local
49        self.expect('p foo', substrs=['= 5'])
50