Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
Showing
14 changed files
with
136 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,8 +29,6 @@ func_a (void) | |
int | ||
main (int argc, char *argv[]) | ||
{ | ||
sleep (2); | ||
|
||
func_a (); | ||
|
||
return 0; | ||
|
53 changes: 53 additions & 0 deletions
53
...Python/lldbsuite/test/functionalities/unwind/noreturn/module-end/TestNoReturnModuleEnd.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
35 changes: 35 additions & 0 deletions
35
lldb/packages/Python/lldbsuite/test/functionalities/unwind/noreturn/module-end/a.s
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
|
Binary file added
BIN
+40 KB
lldb/packages/Python/lldbsuite/test/functionalities/unwind/noreturn/module-end/test.core
Binary file not shown.
Binary file added
BIN
+520 Bytes
lldb/packages/Python/lldbsuite/test/functionalities/unwind/noreturn/module-end/test.out
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters