From a933d5179e411f40059a3711c9a09559b4acb62d Mon Sep 17 00:00:00 2001 From: Pavel Labath Date: Tue, 5 Apr 2016 13:07:16 +0000 Subject: 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 --- .../postmortem/linux-core/TestLinuxCore.py | 63 ++++++++++++++++++--- .../postmortem/linux-core/altmain.c | 6 ++ .../postmortem/linux-core/altmain.core | Bin 0 -> 40960 bytes .../postmortem/linux-core/altmain.out | Bin 0 -> 2330 bytes .../postmortem/linux-core/make-core.sh | 10 +++- 5 files changed, 71 insertions(+), 8 deletions(-) create mode 100644 lldb/packages/Python/lldbsuite/test/functionalities/postmortem/linux-core/altmain.c create mode 100644 lldb/packages/Python/lldbsuite/test/functionalities/postmortem/linux-core/altmain.core create mode 100755 lldb/packages/Python/lldbsuite/test/functionalities/postmortem/linux-core/altmain.out (limited to 'lldb/packages/Python/lldbsuite/test/functionalities') 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("