blob: ef4e370a5f45893fb9c8b859452cb33e1bbf40c8 [file] [log] [blame]
Daniel Malea015f7ad2013-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
14 mydir = os.path.join("linux", "builtin_trap")
15
16 @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
17 @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
Daniel Malea6bc4dcd2013-05-15 18:48:32 +000024 @expectedFailureGcc # llvm.org/pr15936: LLDB is omits a function that contains an
Daniel Malea015f7ad2013-05-08 15:09:30 +000025 # illegal opcode from backtraces. This
26 # failure is GCC 4.6 specific.
27 def test_with_dwarf_and_run_command(self):
28 """Test that LLDB handles a function with __builtin_trap correctly."""
29 self.buildDwarf()
30 self.builtin_trap_unwind()
31
32 def setUp(self):
33 # Call super's setUp().
34 TestBase.setUp(self)
35 # Find the line number to break at.
36 self.line = line_number('main.cpp', '// Set break point at this line.')
37
38 def builtin_trap_unwind(self):
39 """Test that LLDB handles unwinding a frame that contains a function
40 with a __builtin_trap intrinsic.
41 """
42 self.runCmd("file a.out", CURRENT_EXECUTABLE_SET)
43
44 lldbutil.run_break_set_by_file_and_line (self, "main.cpp", self.line,
45 num_expected_locations=1,
46 loc_exact=True)
47
48 self.runCmd("run", RUN_SUCCEEDED)
49
50 # The stop reason of the thread should be breakpoint.
51 self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
52 substrs = ['stopped',
53 'stop reason = breakpoint'])
54
55 # print backtrace, expect both 'bar' and 'main' functions to be listed
56 self.expect('bt', substrs = ['bar', 'main'])
57
58 # go up one frame
59 self.runCmd("up", RUN_SUCCEEDED)
60
61 # evaluate a local
62 self.expect('p foo', substrs = ['= 5'])
63
64
65
66if __name__ == '__main__':
67 import atexit
68 lldb.SBDebugger.Initialize()
69 atexit.register(lambda: lldb.SBDebugger.Terminate())
70 unittest2.main()