diff options
author | Dimitar Vlahovski <dvlahovski@google.com> | 2016-10-04 21:02:13 +0000 |
---|---|---|
committer | Dimitar Vlahovski <dvlahovski@google.com> | 2016-10-04 21:02:13 +0000 |
commit | 8cabfb764d6b0390038f2d0af6f29781b4b2294b (patch) | |
tree | d5f809b2ae4a5dce6cb4e632e95b8b673547f733 /lldb/packages/Python/lldbsuite/test | |
parent | 625fba88406e3ff47ceb63b7d36d5db756ec44cf (diff) | |
download | bcm5719-llvm-8cabfb764d6b0390038f2d0af6f29781b4b2294b.tar.gz bcm5719-llvm-8cabfb764d6b0390038f2d0af6f29781b4b2294b.zip |
Adding a new Minidump post-mortem debugging plugin
Summary:
This plugin resembles the already existing Windows-only Minidump plugin.
The WinMinidumpPlugin uses the Windows API for parsing Minidumps
while this plugin is cross-platform because it includes a Minidump
parser (which is already commited)
It is able to produce a backtrace, to read the general puprose regiters,
inspect local variables, show image list, do memory reads, etc.
For now the only arch that this supports is x86 64 bit
This is because I have only written a register context for that arch.
Others will come in next CLs.
I copied the WinMinidump tests and adapted them a little bit for them to
work with the new plugin (and they pass)
I will add more tests, aiming for better code coverage.
There is still functionality to be added, see TODOs in code.
Reviewers: labath, zturner
Subscribers: beanz, mgorny, amccarth, lldb-commits, modocache
Differential Revision: https://reviews.llvm.org/D25196
llvm-svn: 283259
Diffstat (limited to 'lldb/packages/Python/lldbsuite/test')
6 files changed, 170 insertions, 0 deletions
diff --git a/lldb/packages/Python/lldbsuite/test/functionalities/postmortem/minidump-new/Makefile b/lldb/packages/Python/lldbsuite/test/functionalities/postmortem/minidump-new/Makefile new file mode 100644 index 00000000000..b3034c12abd --- /dev/null +++ b/lldb/packages/Python/lldbsuite/test/functionalities/postmortem/minidump-new/Makefile @@ -0,0 +1,6 @@ +LEVEL = ../../../make + +CXX_SOURCES := main.cpp + +include $(LEVEL)/Makefile.rules + diff --git a/lldb/packages/Python/lldbsuite/test/functionalities/postmortem/minidump-new/TestMiniDumpNew.py b/lldb/packages/Python/lldbsuite/test/functionalities/postmortem/minidump-new/TestMiniDumpNew.py new file mode 100644 index 00000000000..2064fd37fde --- /dev/null +++ b/lldb/packages/Python/lldbsuite/test/functionalities/postmortem/minidump-new/TestMiniDumpNew.py @@ -0,0 +1,100 @@ +""" +Test basics of Minidump debugging. +""" + +from __future__ import print_function +from six import iteritems + + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class MiniDumpNewTestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + NO_DEBUG_INFO_TESTCASE = True + + def test_process_info_in_mini_dump(self): + """Test that lldb can read the process information from the Minidump.""" + # target create -c linux-x86_64.dmp + self.dbg.CreateTarget("") + self.target = self.dbg.GetSelectedTarget() + self.process = self.target.LoadCore("linux-x86_64.dmp") + self.assertTrue(self.process, PROCESS_IS_VALID) + self.assertEqual(self.process.GetNumThreads(), 1) + self.assertEqual(self.process.GetProcessID(), 16001) + + def test_thread_info_in_mini_dump(self): + """Test that lldb can read the thread information from the Minidump.""" + # target create -c linux-x86_64.dmp + self.dbg.CreateTarget("") + self.target = self.dbg.GetSelectedTarget() + self.process = self.target.LoadCore("linux-x86_64.dmp") + # This process crashed due to a segmentation fault in its + # one and only thread. + self.assertEqual(self.process.GetNumThreads(), 1) + thread = self.process.GetThreadAtIndex(0) + self.assertEqual(thread.GetStopReason(), lldb.eStopReasonSignal) + stop_description = thread.GetStopDescription(256) + self.assertTrue("SIGSEGV" in stop_description) + + def test_stack_info_in_mini_dump(self): + """Test that we can see a trivial stack in a breakpad-generated Minidump.""" + # target create -c linux-x86_64.dmp + self.dbg.CreateTarget("") + self.target = self.dbg.GetSelectedTarget() + self.process = self.target.LoadCore("linux-x86_64.dmp") + self.assertEqual(self.process.GetNumThreads(), 1) + thread = self.process.GetThreadAtIndex(0) + # frame #0: a.out`crash() + # frame #1: a.out`main() + # frame #2: libc-2.19.so`__libc_start_main() + # frame #3: a.out`_start + self.assertEqual(thread.GetNumFrames(), 4) + frame = thread.GetFrameAtIndex(0) + self.assertTrue(frame.IsValid()) + pc = frame.GetPC() + eip = frame.FindRegister("pc") + self.assertTrue(eip.IsValid()) + self.assertEqual(pc, eip.GetValueAsUnsigned()) + + def test_snapshot_minidump(self): + """Test that if we load a snapshot minidump file (meaning the process did not crash) there is no stop reason.""" + # target create -c linux-x86_64_not_crashed.dmp + self.dbg.CreateTarget("") + self.target = self.dbg.GetSelectedTarget() + self.process = self.target.LoadCore("linux-x86_64_not_crashed.dmp") + self.assertEqual(self.process.GetNumThreads(), 1) + thread = self.process.GetThreadAtIndex(0) + self.assertEqual(thread.GetStopReason(), lldb.eStopReasonNone) + stop_description = thread.GetStopDescription(256) + self.assertEqual(stop_description, None) + + def test_deeper_stack_in_mini_dump(self): + """Test that we can examine a more interesting stack in a Minidump.""" + # Launch with the Minidump, and inspect the stack. + target = self.dbg.CreateTarget(None) + process = target.LoadCore("linux-x86_64_not_crashed.dmp") + thread = process.GetThreadAtIndex(0) + + expected_stack = {1: 'bar', 2: 'foo', 3: 'main'} + self.assertGreaterEqual(thread.GetNumFrames(), len(expected_stack)) + for index, name in iteritems(expected_stack): + frame = thread.GetFrameAtIndex(index) + self.assertTrue(frame.IsValid()) + function_name = frame.GetFunctionName() + self.assertTrue(name in function_name) + + def test_local_variables_in_mini_dump(self): + """Test that we can examine local variables in a Minidump.""" + # Launch with the Minidump, and inspect a local variable. + target = self.dbg.CreateTarget(None) + process = target.LoadCore("linux-x86_64_not_crashed.dmp") + thread = process.GetThreadAtIndex(0) + frame = thread.GetFrameAtIndex(1) + value = frame.EvaluateExpression('x') + self.assertEqual(value.GetValueAsSigned(), 3) diff --git a/lldb/packages/Python/lldbsuite/test/functionalities/postmortem/minidump-new/linux-x86_64.cpp b/lldb/packages/Python/lldbsuite/test/functionalities/postmortem/minidump-new/linux-x86_64.cpp new file mode 100644 index 00000000000..827fe67b503 --- /dev/null +++ b/lldb/packages/Python/lldbsuite/test/functionalities/postmortem/minidump-new/linux-x86_64.cpp @@ -0,0 +1,28 @@ +// Example source from breakpad's linux tutorial +// https://chromium.googlesource.com/breakpad/breakpad/+/master/docs/linux_starter_guide.md + +#include <stdio.h> +#include <sys/types.h> +#include <unistd.h> + +#include "client/linux/handler/exception_handler.h" + +static bool dumpCallback(const google_breakpad::MinidumpDescriptor &descriptor, + void *context, bool succeeded) { + printf("Dump path: %s\n", descriptor.path()); + return succeeded; +} + +void crash() { + volatile int *a = (int *)(NULL); + *a = 1; +} + +int main(int argc, char *argv[]) { + google_breakpad::MinidumpDescriptor descriptor("/tmp"); + google_breakpad::ExceptionHandler eh(descriptor, NULL, dumpCallback, NULL, + true, -1); + printf("pid: %d\n", getpid()); + crash(); + return 0; +} diff --git a/lldb/packages/Python/lldbsuite/test/functionalities/postmortem/minidump-new/linux-x86_64.dmp b/lldb/packages/Python/lldbsuite/test/functionalities/postmortem/minidump-new/linux-x86_64.dmp Binary files differnew file mode 100644 index 00000000000..29a12d6a2eb --- /dev/null +++ b/lldb/packages/Python/lldbsuite/test/functionalities/postmortem/minidump-new/linux-x86_64.dmp diff --git a/lldb/packages/Python/lldbsuite/test/functionalities/postmortem/minidump-new/linux-x86_64_not_crashed.cpp b/lldb/packages/Python/lldbsuite/test/functionalities/postmortem/minidump-new/linux-x86_64_not_crashed.cpp new file mode 100644 index 00000000000..1d2743bc41c --- /dev/null +++ b/lldb/packages/Python/lldbsuite/test/functionalities/postmortem/minidump-new/linux-x86_64_not_crashed.cpp @@ -0,0 +1,36 @@ +#include <stdio.h> +#include <sys/types.h> +#include <unistd.h> + +#include "client/linux/handler/exception_handler.h" + +static bool dumpCallback(const google_breakpad::MinidumpDescriptor& descriptor, +void* context, bool succeeded) { + printf("Dump path: %s\n", descriptor.path()); + return succeeded; +} + +int global = 42; + +int +bar(int x, google_breakpad::ExceptionHandler &eh) +{ + eh.WriteMinidump(); + int y = 4*x + global; + return y; +} + +int +foo(int x, google_breakpad::ExceptionHandler &eh) +{ + int y = 2*bar(3*x, eh); + return y; +} + + +int main(int argc, char* argv[]) { + google_breakpad::MinidumpDescriptor descriptor("/tmp"); + google_breakpad::ExceptionHandler eh(descriptor, NULL, dumpCallback, NULL, true, -1); + foo(1, eh); + return 0; +} diff --git a/lldb/packages/Python/lldbsuite/test/functionalities/postmortem/minidump-new/linux-x86_64_not_crashed.dmp b/lldb/packages/Python/lldbsuite/test/functionalities/postmortem/minidump-new/linux-x86_64_not_crashed.dmp Binary files differnew file mode 100644 index 00000000000..e175b0d7264 --- /dev/null +++ b/lldb/packages/Python/lldbsuite/test/functionalities/postmortem/minidump-new/linux-x86_64_not_crashed.dmp |