diff options
author | Pavel Labath <labath@google.com> | 2017-06-08 13:26:35 +0000 |
---|---|---|
committer | Pavel Labath <labath@google.com> | 2017-06-08 13:26:35 +0000 |
commit | c3c721222d3ca702ebe14ebc487a7feced6c36c1 (patch) | |
tree | 8736e1b3e627c0cfb652ab597442c339a37b23cc /lldb/packages/Python/lldbsuite | |
parent | 62fb8498d32ae76c316437c7429095dad6873a82 (diff) | |
download | bcm5719-llvm-c3c721222d3ca702ebe14ebc487a7feced6c36c1.tar.gz bcm5719-llvm-c3c721222d3ca702ebe14ebc487a7feced6c36c1.zip |
Fix backtrace of noreturn functions situated at the end of a module
Summary:
When a call instruction is the last instruction in a function, the
backtrace PC will point past the end of the function. We already had
special code to handle that, but we did not handle the case where the PC
ends up outside of the bounds of the module containing the function,
which is a situation that occured in TestNoreturnUnwind on android for
some arch/compiler combinations.
I fix this by adding an argument to Address resolution code which states
that we are ok with addresses pointing to the end of a module/section to
resolve to that module/section.
I create a reproducible test case for this situation by hand-crafting an
executable which has a noreturn function at the end of a module.
Reviewers: jasonmolenda, jingham
Subscribers: lldb-commits
Differential Revision: https://reviews.llvm.org/D32022
llvm-svn: 304976
Diffstat (limited to 'lldb/packages/Python/lldbsuite')
6 files changed, 88 insertions, 4 deletions
diff --git a/lldb/packages/Python/lldbsuite/test/functionalities/unwind/noreturn/TestNoreturnUnwind.py b/lldb/packages/Python/lldbsuite/test/functionalities/unwind/noreturn/TestNoreturnUnwind.py index eafe62a0e08..e5c9c907727 100644 --- a/lldb/packages/Python/lldbsuite/test/functionalities/unwind/noreturn/TestNoreturnUnwind.py +++ b/lldb/packages/Python/lldbsuite/test/functionalities/unwind/noreturn/TestNoreturnUnwind.py @@ -17,8 +17,6 @@ class NoreturnUnwind(TestBase): mydir = TestBase.compute_mydir(__file__) @skipIfWindows # clang-cl does not support gcc style attributes. - @expectedFailureAndroid(bugnumber="llvm.org/pr31192") - @expectedFailureAll(bugnumber="llvm.org/pr31192", oslist=['linux'], compiler="gcc", archs=['arm']) def test(self): """Test that we can backtrace correctly with 'noreturn' functions on the stack""" self.build() diff --git a/lldb/packages/Python/lldbsuite/test/functionalities/unwind/noreturn/main.c b/lldb/packages/Python/lldbsuite/test/functionalities/unwind/noreturn/main.c index 7190e38f5d8..4f6525fbf52 100644 --- a/lldb/packages/Python/lldbsuite/test/functionalities/unwind/noreturn/main.c +++ b/lldb/packages/Python/lldbsuite/test/functionalities/unwind/noreturn/main.c @@ -29,8 +29,6 @@ func_a (void) int main (int argc, char *argv[]) { - sleep (2); - func_a (); return 0; diff --git a/lldb/packages/Python/lldbsuite/test/functionalities/unwind/noreturn/module-end/TestNoReturnModuleEnd.py b/lldb/packages/Python/lldbsuite/test/functionalities/unwind/noreturn/module-end/TestNoReturnModuleEnd.py new file mode 100644 index 00000000000..3aa6a230e8b --- /dev/null +++ b/lldb/packages/Python/lldbsuite/test/functionalities/unwind/noreturn/module-end/TestNoReturnModuleEnd.py @@ -0,0 +1,53 @@ +""" +Test that we properly display the backtrace when a noreturn function happens to +be at the end of the stack. +""" + +from __future__ import print_function + +import shutil +import struct + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class TestNoreturnModuleEnd(TestBase): + NO_DEBUG_INFO_TESTCASE = True + mydir = TestBase.compute_mydir(__file__) + + def setUp(self): + super(TestNoreturnModuleEnd, self).setUp() + self._initial_platform = lldb.DBG.GetSelectedPlatform() + + def tearDown(self): + lldb.DBG.SetSelectedPlatform(self._initial_platform) + super(TestNoreturnModuleEnd, self).tearDown() + + def test(self): + target = self.dbg.CreateTarget("test.out") + process = target.LoadCore("test.core") + self.assertTrue(process.IsValid(), PROCESS_IS_VALID) + self.assertEqual(process.GetNumThreads(), 1) + + thread = process.GetSelectedThread() + self.assertTrue(thread.IsValid()) + + backtrace = [ + ["func2", 3], + ["func1", 8], + ["_start", 8], + ] + self.assertEqual(thread.GetNumFrames(), len(backtrace)) + for i in range(len(backtrace)): + frame = thread.GetFrameAtIndex(i) + self.assertTrue(frame.IsValid()) + symbol = frame.GetSymbol() + self.assertTrue(symbol.IsValid()) + self.assertEqual(symbol.GetName(), backtrace[i][0]) + function_start = symbol.GetStartAddress().GetLoadAddress(target) + self.assertEquals(function_start + backtrace[i][1], frame.GetPC()) + + self.dbg.DeleteTarget(target) diff --git a/lldb/packages/Python/lldbsuite/test/functionalities/unwind/noreturn/module-end/a.s b/lldb/packages/Python/lldbsuite/test/functionalities/unwind/noreturn/module-end/a.s new file mode 100644 index 00000000000..119465c132a --- /dev/null +++ b/lldb/packages/Python/lldbsuite/test/functionalities/unwind/noreturn/module-end/a.s @@ -0,0 +1,35 @@ +# compile this with: +# as a.s -o a.o --32 && ld a.o -m elf_i386 +# generate core file with: +# ulimit -s 12 && ./a.out + +.text + +.globl func2 +.type func2, @function +func2: + pushl %ebp + movl %esp, %ebp + movl 0, %eax + popl %ebp + ret +.size func2, .-func2 + +.globl _start +.type _start, @function +_start: + pushl %ebp + movl %esp, %ebp + call func1 + popl %ebp + ret +.size _start, .-_start + +.globl func1 +.type func1, @function +func1: + pushl %ebp + movl %esp, %ebp + call func2 +.size func1, .-func1 + diff --git a/lldb/packages/Python/lldbsuite/test/functionalities/unwind/noreturn/module-end/test.core b/lldb/packages/Python/lldbsuite/test/functionalities/unwind/noreturn/module-end/test.core Binary files differnew file mode 100644 index 00000000000..6717d4ff647 --- /dev/null +++ b/lldb/packages/Python/lldbsuite/test/functionalities/unwind/noreturn/module-end/test.core diff --git a/lldb/packages/Python/lldbsuite/test/functionalities/unwind/noreturn/module-end/test.out b/lldb/packages/Python/lldbsuite/test/functionalities/unwind/noreturn/module-end/test.out Binary files differnew file mode 100755 index 00000000000..141c61ecbea --- /dev/null +++ b/lldb/packages/Python/lldbsuite/test/functionalities/unwind/noreturn/module-end/test.out |