Daniel Malea | ee64812 | 2013-05-08 15:09:30 +0000 | [diff] [blame] | 1 | """ |
| 2 | Test 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 | import os |
| 7 | import unittest2 |
| 8 | import lldb |
| 9 | from lldbtest import * |
| 10 | import lldbutil |
| 11 | |
| 12 | class BuiltinTrapTestCase(TestBase): |
| 13 | |
Greg Clayton | 4570d3e | 2013-12-10 23:19:29 +0000 | [diff] [blame] | 14 | mydir = TestBase.compute_mydir(__file__) |
Daniel Malea | ee64812 | 2013-05-08 15:09:30 +0000 | [diff] [blame] | 15 | |
Robert Flack | 13c7ad9 | 2015-03-30 14:12:17 +0000 | [diff] [blame] | 16 | @skipUnlessDarwin |
Daniel Malea | ee64812 | 2013-05-08 15:09:30 +0000 | [diff] [blame] | 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 |
Siva Chandra | 2f8e607 | 2015-05-21 18:12:19 +0000 | [diff] [blame] | 24 | @expectedFailureAll("llvm.org/pr15936", compiler="gcc", compiler_version=["<=","4.6"]) |
Daniel Malea | ee64812 | 2013-05-08 15:09:30 +0000 | [diff] [blame] | 25 | 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 Chandra | 3154aa2 | 2015-05-27 22:27:41 +0000 | [diff] [blame] | 46 | self.runCmd("run", RUN_FAILED) |
Daniel Malea | ee64812 | 2013-05-08 15:09:30 +0000 | [diff] [blame] | 47 | |
| 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 Chandra | 3154aa2 | 2015-05-27 22:27:41 +0000 | [diff] [blame] | 57 | self.runCmd("up", RUN_FAILED) |
Daniel Malea | ee64812 | 2013-05-08 15:09:30 +0000 | [diff] [blame] | 58 | |
| 59 | # evaluate a local |
| 60 | self.expect('p foo', substrs = ['= 5']) |
| 61 | |
| 62 | |
| 63 | |
| 64 | if __name__ == '__main__': |
| 65 | import atexit |
| 66 | lldb.SBDebugger.Initialize() |
| 67 | atexit.register(lambda: lldb.SBDebugger.Terminate()) |
| 68 | unittest2.main() |