diff options
author | Pavel Labath <labath@google.com> | 2016-04-05 13:07:16 +0000 |
---|---|---|
committer | Pavel Labath <labath@google.com> | 2016-04-05 13:07:16 +0000 |
commit | a933d5179e411f40059a3711c9a09559b4acb62d (patch) | |
tree | 7851360ca4a039c85f9bd15e6636c218fa815398 /lldb/packages/Python/lldbsuite/test/functionalities | |
parent | d9d41f531ef63ecf14472df29c68d8113284f051 (diff) | |
download | bcm5719-llvm-a933d5179e411f40059a3711c9a09559b4acb62d.tar.gz bcm5719-llvm-a933d5179e411f40059a3711c9a09559b4acb62d.zip |
Fix a bug in linux core file handling
Summary:
There was a bug in linux core file handling, where if there was a running process with the same
process id as the id in the core file, the core file debugging would fail, as we would pull some
pieces of information (ProcessInfo structure) from the running process instead of the core file.
I fix this by routing the ProcessInfo requests through the Process class and overriding it in
ProcessElfCore to return correct data.
A (slightly convoluted) test is included.
Reviewers: clayborg, zturner
Subscribers: lldb-commits
Differential Revision: http://reviews.llvm.org/D18697
llvm-svn: 265391
Diffstat (limited to 'lldb/packages/Python/lldbsuite/test/functionalities')
5 files changed, 71 insertions, 8 deletions
diff --git a/lldb/packages/Python/lldbsuite/test/functionalities/postmortem/linux-core/TestLinuxCore.py b/lldb/packages/Python/lldbsuite/test/functionalities/postmortem/linux-core/TestLinuxCore.py index 3efd3ec3f7b..5eb33d08c5e 100644 --- a/lldb/packages/Python/lldbsuite/test/functionalities/postmortem/linux-core/TestLinuxCore.py +++ b/lldb/packages/Python/lldbsuite/test/functionalities/postmortem/linux-core/TestLinuxCore.py @@ -4,29 +4,78 @@ Test basics of linux core file debugging. 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 LinuxCoreTestCase(TestBase): + NO_DEBUG_INFO_TESTCASE = True mydir = TestBase.compute_mydir(__file__) + _i386_pid = 32306 + _x86_64_pid = 32259 + @skipIf(bugnumber="llvm.org/pr26947") - @no_debug_info_test def test_i386(self): """Test that lldb can read the process information from an i386 linux core file.""" - self.do_test("i386", 32306) + self.do_test("i386", self._i386_pid) - @no_debug_info_test def test_x86_64(self): """Test that lldb can read the process information from an x86_64 linux core file.""" - self.do_test("x86_64", 32259) + self.do_test("x86_64", self._x86_64_pid) + + def test_same_pid_running(self): + """Test that we read the information from the core correctly even if we have a running + process with the same PID around""" + try: + shutil.copyfile("x86_64.out", "x86_64-pid.out") + shutil.copyfile("x86_64.core", "x86_64-pid.core") + with open("x86_64-pid.core", "r+b") as f: + # These are offsets into the NT_PRSTATUS and NT_PRPSINFO structures in the note + # segment of the core file. If you update the file, these offsets may need updating + # as well. (Notes can be viewed with readelf --notes.) + for pid_offset in [0x1c4, 0x320]: + f.seek(pid_offset) + self.assertEqual(struct.unpack("<I", f.read(4))[0], self._x86_64_pid) + + # We insert our own pid, and make sure the test still works. + f.seek(pid_offset) + f.write(struct.pack("<I", os.getpid())) + self.do_test("x86_64-pid", os.getpid()) + finally: + self.RemoveTempFile("x86_64-pid.out") + self.RemoveTempFile("x86_64-pid.core") + + def test_two_cores_same_pid(self): + """Test that we handle the situation if we have two core files with the same PID + around""" + alttarget = self.dbg.CreateTarget("altmain.out") + altprocess = alttarget.LoadCore("altmain.core") + self.assertTrue(altprocess, PROCESS_IS_VALID) + self.assertEqual(altprocess.GetNumThreads(), 1) + self.assertEqual(altprocess.GetProcessID(), self._x86_64_pid) + + altframe = altprocess.GetSelectedThread().GetFrameAtIndex(0) + self.assertEqual(altframe.GetFunctionName(), "_start") + self.assertEqual(altframe.GetLineEntry().GetLine(), line_number("altmain.c", "Frame _start")) + + error = lldb.SBError() + F = altprocess.ReadCStringFromMemory(altframe.FindVariable("F").GetValueAsUnsigned(), 256, error) + self.assertTrue(error.Success()) + self.assertEqual(F, "_start") + + # without destroying this process, run the test which opens another core file with the + # same pid + self.do_test("x86_64", self._x86_64_pid) - def do_test(self, arch, pid): - target = self.dbg.CreateTarget(arch + ".out") - process = target.LoadCore(arch + ".core") + def do_test(self, filename, pid): + target = self.dbg.CreateTarget(filename + ".out") + process = target.LoadCore(filename + ".core") self.assertTrue(process, PROCESS_IS_VALID) self.assertEqual(process.GetNumThreads(), 1) self.assertEqual(process.GetProcessID(), pid) diff --git a/lldb/packages/Python/lldbsuite/test/functionalities/postmortem/linux-core/altmain.c b/lldb/packages/Python/lldbsuite/test/functionalities/postmortem/linux-core/altmain.c new file mode 100644 index 00000000000..da49a00996e --- /dev/null +++ b/lldb/packages/Python/lldbsuite/test/functionalities/postmortem/linux-core/altmain.c @@ -0,0 +1,6 @@ +void _start(void) +{ + const char *F = "_start"; + char *boom = (char *)0; + *boom = 47; // Frame _start +} diff --git a/lldb/packages/Python/lldbsuite/test/functionalities/postmortem/linux-core/altmain.core b/lldb/packages/Python/lldbsuite/test/functionalities/postmortem/linux-core/altmain.core Binary files differnew file mode 100644 index 00000000000..423413070c7 --- /dev/null +++ b/lldb/packages/Python/lldbsuite/test/functionalities/postmortem/linux-core/altmain.core diff --git a/lldb/packages/Python/lldbsuite/test/functionalities/postmortem/linux-core/altmain.out b/lldb/packages/Python/lldbsuite/test/functionalities/postmortem/linux-core/altmain.out Binary files differnew file mode 100755 index 00000000000..2fddf3e8f80 --- /dev/null +++ b/lldb/packages/Python/lldbsuite/test/functionalities/postmortem/linux-core/altmain.out diff --git a/lldb/packages/Python/lldbsuite/test/functionalities/postmortem/linux-core/make-core.sh b/lldb/packages/Python/lldbsuite/test/functionalities/postmortem/linux-core/make-core.sh index 10f5f06c505..efe1b801df3 100755 --- a/lldb/packages/Python/lldbsuite/test/functionalities/postmortem/linux-core/make-core.sh +++ b/lldb/packages/Python/lldbsuite/test/functionalities/postmortem/linux-core/make-core.sh @@ -2,6 +2,14 @@ set -e -x +file=$1 +if [ -z "$file" ]; then + cat <<EOF +Please supply the main source file as the first argument. +EOF + exit 1 +fi + if grep -q '^|' </proc/sys/kernel/core_pattern; then cat <<EOF Your system uses a crash report tool ($(cat /proc/sys/kernel/core_pattern)). Core files @@ -21,7 +29,7 @@ privileges. EOF fi -${CC:-cc} -nostdlib -static -g $CFLAGS main.c -o a.out +${CC:-cc} -nostdlib -static -g $CFLAGS "$file" -o a.out cat <<EOF Executable file is in a.out. |