From 39aab4d60664a3ee56e7add57aafed453cab1df7 Mon Sep 17 00:00:00 2001 From: Pavel Labath Date: Wed, 16 Mar 2016 09:19:57 +0000 Subject: Fix thread/process ID reading from linux core files Summary: This also adds a basic smoke test for linux core file reading. I'm checking in the core files as well, so that the tests can run on all platforms. With some tricks I was able to produce reasonably-sized core files (~40K). This fixes the first part of pr26322. Reviewers: zturner Subscribers: lldb-commits Differential Revision: http://reviews.llvm.org/D18176 llvm-svn: 263628 --- .../postmortem/linux-core/TestLinuxCore.py | 45 +++++++++++++++++++++ .../postmortem/linux-core/i386.core | Bin 0 -> 28672 bytes .../functionalities/postmortem/linux-core/i386.out | Bin 0 -> 1971 bytes .../functionalities/postmortem/linux-core/main.c | 17 ++++++++ .../postmortem/linux-core/make-core.sh | 32 +++++++++++++++ .../postmortem/linux-core/x86_64.core | Bin 0 -> 40960 bytes .../postmortem/linux-core/x86_64.out | Bin 0 -> 2575 bytes 7 files changed, 94 insertions(+) create mode 100644 lldb/packages/Python/lldbsuite/test/functionalities/postmortem/linux-core/TestLinuxCore.py create mode 100644 lldb/packages/Python/lldbsuite/test/functionalities/postmortem/linux-core/i386.core create mode 100755 lldb/packages/Python/lldbsuite/test/functionalities/postmortem/linux-core/i386.out create mode 100644 lldb/packages/Python/lldbsuite/test/functionalities/postmortem/linux-core/main.c create mode 100755 lldb/packages/Python/lldbsuite/test/functionalities/postmortem/linux-core/make-core.sh create mode 100644 lldb/packages/Python/lldbsuite/test/functionalities/postmortem/linux-core/x86_64.core create mode 100755 lldb/packages/Python/lldbsuite/test/functionalities/postmortem/linux-core/x86_64.out (limited to 'lldb/packages/Python/lldbsuite') 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 new file mode 100644 index 00000000000..3efd3ec3f7b --- /dev/null +++ b/lldb/packages/Python/lldbsuite/test/functionalities/postmortem/linux-core/TestLinuxCore.py @@ -0,0 +1,45 @@ +""" +Test basics of linux core file debugging. +""" + +from __future__ import print_function + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + +class LinuxCoreTestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + @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) + + @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) + + def do_test(self, arch, pid): + target = self.dbg.CreateTarget(arch + ".out") + process = target.LoadCore(arch + ".core") + self.assertTrue(process, PROCESS_IS_VALID) + self.assertEqual(process.GetNumThreads(), 1) + self.assertEqual(process.GetProcessID(), pid) + + thread = process.GetSelectedThread() + self.assertTrue(thread) + self.assertEqual(thread.GetThreadID(), pid) + backtrace = ["bar", "foo", "_start"] + self.assertEqual(thread.GetNumFrames(), len(backtrace)) + for i in range(len(backtrace)): + frame = thread.GetFrameAtIndex(i) + self.assertTrue(frame) + self.assertEqual(frame.GetFunctionName(), backtrace[i]) + self.assertEqual(frame.GetLineEntry().GetLine(), + line_number("main.c", "Frame " + backtrace[i])) + self.assertEqual(frame.FindVariable("F").GetValueAsUnsigned(), ord(backtrace[i][0])) diff --git a/lldb/packages/Python/lldbsuite/test/functionalities/postmortem/linux-core/i386.core b/lldb/packages/Python/lldbsuite/test/functionalities/postmortem/linux-core/i386.core new file mode 100644 index 00000000000..f8deff474d1 Binary files /dev/null and b/lldb/packages/Python/lldbsuite/test/functionalities/postmortem/linux-core/i386.core differ diff --git a/lldb/packages/Python/lldbsuite/test/functionalities/postmortem/linux-core/i386.out b/lldb/packages/Python/lldbsuite/test/functionalities/postmortem/linux-core/i386.out new file mode 100755 index 00000000000..3cdd4eeca10 Binary files /dev/null and b/lldb/packages/Python/lldbsuite/test/functionalities/postmortem/linux-core/i386.out differ diff --git a/lldb/packages/Python/lldbsuite/test/functionalities/postmortem/linux-core/main.c b/lldb/packages/Python/lldbsuite/test/functionalities/postmortem/linux-core/main.c new file mode 100644 index 00000000000..f5bde4171ca --- /dev/null +++ b/lldb/packages/Python/lldbsuite/test/functionalities/postmortem/linux-core/main.c @@ -0,0 +1,17 @@ +static void bar(char *boom) +{ + char F = 'b'; + *boom = 47; // Frame bar +} + +static void foo(char *boom, void (*boomer)(char *)) +{ + char F = 'f'; + boomer(boom); // Frame foo +} + +void _start(void) +{ + char F = '_'; + foo(0, bar); // Frame _start +} 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 new file mode 100755 index 00000000000..10f5f06c505 --- /dev/null +++ b/lldb/packages/Python/lldbsuite/test/functionalities/postmortem/linux-core/make-core.sh @@ -0,0 +1,32 @@ +#! /bin/bash + +set -e -x + +if grep -q '^|' smaller core files. +exec ./a.out diff --git a/lldb/packages/Python/lldbsuite/test/functionalities/postmortem/linux-core/x86_64.core b/lldb/packages/Python/lldbsuite/test/functionalities/postmortem/linux-core/x86_64.core new file mode 100644 index 00000000000..e2fa69e4558 Binary files /dev/null and b/lldb/packages/Python/lldbsuite/test/functionalities/postmortem/linux-core/x86_64.core differ diff --git a/lldb/packages/Python/lldbsuite/test/functionalities/postmortem/linux-core/x86_64.out b/lldb/packages/Python/lldbsuite/test/functionalities/postmortem/linux-core/x86_64.out new file mode 100755 index 00000000000..842402fd519 Binary files /dev/null and b/lldb/packages/Python/lldbsuite/test/functionalities/postmortem/linux-core/x86_64.out differ -- cgit v1.2.3