blob: 7bdeabbbc3e6f5df50cc8fd1f0acf9b32cf02415 [file] [log] [blame]
Daniel Maleaee648122013-05-08 15:09:30 +00001"""
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
6import os
7import unittest2
8import lldb
9from lldbtest import *
10import lldbutil
11
12class BuiltinTrapTestCase(TestBase):
13
Greg Clayton4570d3e2013-12-10 23:19:29 +000014 mydir = TestBase.compute_mydir(__file__)
Daniel Maleaee648122013-05-08 15:09:30 +000015
Robert Flack13c7ad92015-03-30 14:12:17 +000016 @skipUnlessDarwin
Daniel Maleaee648122013-05-08 15:09:30 +000017 @dsym_test
18 def test_with_dsym_and_run_command(self):
19 """Test that LLDB handles a function with __builtin_trap correctly."""
20 self.buildDsym()
21 self.builtin_trap_unwind()
22
23 @dwarf_test
Siva Chandra2f8e6072015-05-21 18:12:19 +000024 @expectedFailureAll("llvm.org/pr15936", compiler="gcc", compiler_version=["<=","4.6"])
Daniel Maleaee648122013-05-08 15:09:30 +000025 def test_with_dwarf_and_run_command(self):
26 """Test that LLDB handles a function with __builtin_trap correctly."""
27 self.buildDwarf()
28 self.builtin_trap_unwind()
29
30 def setUp(self):
31 # Call super's setUp().
32 TestBase.setUp(self)
33 # Find the line number to break at.
34 self.line = line_number('main.cpp', '// Set break point at this line.')
35
36 def builtin_trap_unwind(self):
37 """Test that LLDB handles unwinding a frame that contains a function
38 with a __builtin_trap intrinsic.
39 """
40 self.runCmd("file a.out", CURRENT_EXECUTABLE_SET)
41
42 lldbutil.run_break_set_by_file_and_line (self, "main.cpp", self.line,
43 num_expected_locations=1,
44 loc_exact=True)
45
Siva Chandra3154aa22015-05-27 22:27:41 +000046 self.runCmd("run", RUN_FAILED)
Daniel Maleaee648122013-05-08 15:09:30 +000047
48 # The stop reason of the thread should be breakpoint.
49 self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
50 substrs = ['stopped',
51 'stop reason = breakpoint'])
52
53 # print backtrace, expect both 'bar' and 'main' functions to be listed
54 self.expect('bt', substrs = ['bar', 'main'])
55
56 # go up one frame
Siva Chandra3154aa22015-05-27 22:27:41 +000057 self.runCmd("up", RUN_FAILED)
Daniel Maleaee648122013-05-08 15:09:30 +000058
59 # evaluate a local
60 self.expect('p foo', substrs = ['= 5'])
61
62
63
64if __name__ == '__main__':
65 import atexit
66 lldb.SBDebugger.Initialize()
67 atexit.register(lambda: lldb.SBDebugger.Terminate())
68 unittest2.main()