diff options
| author | Dimitar Vlahovski <dvlahovski@google.com> | 2016-10-31 15:35:18 +0000 |
|---|---|---|
| committer | Dimitar Vlahovski <dvlahovski@google.com> | 2016-10-31 15:35:18 +0000 |
| commit | 7b18dd4f7743e4dc9dc02040a2e706e96eb29f6e (patch) | |
| tree | f69da2ec227d92df7e7a8810863d70a9c15bb60c /lldb/packages/Python/lldbsuite | |
| parent | f01f65ea593bf1bbdcbeb425e1053ac3bbd9644d (diff) | |
| download | bcm5719-llvm-7b18dd4f7743e4dc9dc02040a2e706e96eb29f6e.tar.gz bcm5719-llvm-7b18dd4f7743e4dc9dc02040a2e706e96eb29f6e.zip | |
Minidump plugin: Adding ProcessMinidump, ThreadMinidump and register the plugin in SystemInitializerFull
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 arches that this supports are x86_32 and x86_64.
This is because I have only written register contexts for those.
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, modocache, lldb-commits, amccarth
Differential Revision: https://reviews.llvm.org/D25905
llvm-svn: 285587
Diffstat (limited to 'lldb/packages/Python/lldbsuite')
9 files changed, 179 insertions, 0 deletions
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..8e839a6f05b --- /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_minidump(self): + """Test that lldb can read the process information from the Minidump.""" + # target create -c linux-x86_64.dmp + self.dbg.CreateTarget(None) + 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(), 29917) + + def test_thread_info_in_minidump(self): + """Test that lldb can read the thread information from the Minidump.""" + # target create -c linux-x86_64.dmp + self.dbg.CreateTarget(None) + 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_minidump(self): + """Test that we can see a trivial stack in a breakpad-generated Minidump.""" + # target create linux-x86_64 -c linux-x86_64.dmp + self.dbg.CreateTarget("linux-x86_64") + 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: linux-x86_64`crash() + # frame #1: linux-x86_64`_start + self.assertEqual(thread.GetNumFrames(), 2) + 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(None) + 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_minidump(self): + """Test that we can examine a more interesting stack in a Minidump.""" + # Launch with the Minidump, and inspect the stack. + # target create linux-x86_64_not_crashed -c linux-x86_64_not_crashed.dmp + target = self.dbg.CreateTarget("linux-x86_64_not_crashed") + process = target.LoadCore("linux-x86_64_not_crashed.dmp") + thread = process.GetThreadAtIndex(0) + + expected_stack = {1: 'bar', 2: 'foo', 3: '_start'} + 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_minidump(self): + """Test that we can examine local variables in a Minidump.""" + # Launch with the Minidump, and inspect a local variable. + # target create linux-x86_64_not_crashed -c linux-x86_64_not_crashed.dmp + target = self.dbg.CreateTarget("linux-x86_64_not_crashed") + 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/install_breakpad.cpp b/lldb/packages/Python/lldbsuite/test/functionalities/postmortem/minidump-new/install_breakpad.cpp new file mode 100644 index 00000000000..c34ac17128f --- /dev/null +++ b/lldb/packages/Python/lldbsuite/test/functionalities/postmortem/minidump-new/install_breakpad.cpp @@ -0,0 +1,16 @@ +#include "client/linux/handler/exception_handler.h" + +static bool dumpCallback(const google_breakpad::MinidumpDescriptor &descriptor, + void *context, bool succeeded) { + return succeeded; +} + +google_breakpad::ExceptionHandler *eh; + +void InstallBreakpad() { + google_breakpad::MinidumpDescriptor descriptor("/tmp"); + eh = new google_breakpad::ExceptionHandler(descriptor, NULL, dumpCallback, + NULL, true, -1); +} + +void WriteMinidump() { eh->WriteMinidump(); } diff --git a/lldb/packages/Python/lldbsuite/test/functionalities/postmortem/minidump-new/linux-x86_64 b/lldb/packages/Python/lldbsuite/test/functionalities/postmortem/minidump-new/linux-x86_64 Binary files differnew file mode 100755 index 00000000000..078d9c8fa90 --- /dev/null +++ b/lldb/packages/Python/lldbsuite/test/functionalities/postmortem/minidump-new/linux-x86_64 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..61d31492940 --- /dev/null +++ b/lldb/packages/Python/lldbsuite/test/functionalities/postmortem/minidump-new/linux-x86_64.cpp @@ -0,0 +1,12 @@ +void crash() { + volatile int *a = (int *)(nullptr); + *a = 1; +} + +extern "C" void _start(); +void InstallBreakpad(); + +void _start() { + InstallBreakpad(); + crash(); +} 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..e2ae724abe9 --- /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 b/lldb/packages/Python/lldbsuite/test/functionalities/postmortem/minidump-new/linux-x86_64_not_crashed Binary files differnew file mode 100755 index 00000000000..8b38cdb48bd --- /dev/null +++ b/lldb/packages/Python/lldbsuite/test/functionalities/postmortem/minidump-new/linux-x86_64_not_crashed 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..070c565e72b --- /dev/null +++ b/lldb/packages/Python/lldbsuite/test/functionalities/postmortem/minidump-new/linux-x86_64_not_crashed.cpp @@ -0,0 +1,22 @@ +void InstallBreakpad(); +void WriteMinidump(); + +int global = 42; + +int bar(int x) { + WriteMinidump(); + int y = 4 * x + global; + return y; +} + +int foo(int x) { + int y = 2 * bar(3 * x); + return y; +} + +extern "C" void _start(); + +void _start() { + InstallBreakpad(); + foo(1); +} 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..ad4b61a7bbb --- /dev/null +++ b/lldb/packages/Python/lldbsuite/test/functionalities/postmortem/minidump-new/linux-x86_64_not_crashed.dmp diff --git a/lldb/packages/Python/lldbsuite/test/functionalities/postmortem/minidump-new/makefile.txt b/lldb/packages/Python/lldbsuite/test/functionalities/postmortem/minidump-new/makefile.txt new file mode 100644 index 00000000000..79a95d61d85 --- /dev/null +++ b/lldb/packages/Python/lldbsuite/test/functionalities/postmortem/minidump-new/makefile.txt @@ -0,0 +1,29 @@ +# This makefile aims to make the binaries as small as possible, for us not to +# upload huge binary blobs in the repo. +# The binary should have debug symbols because stack unwinding doesn't work +# correctly using the information in the Minidump only. Also we want to evaluate +# local variables, etc. +# Breakpad compiles as a static library, so statically linking againts it +# makes the binary huge. +# Dynamically linking to it does improve things, but we are still #include-ing +# breakpad headers (which is a lot of source code for which we generate debug +# symbols) +# So, install_breakpad.cpp does the #include-ing and defines a global function +# "InstallBreakpad" that does all the exception handler registration. +# We compile install_breakpad to object file and then link it, alongside the +# static libbreakpad, into a shared library. +# Then the binaries dynamically link to that lib. +# The other optimisation is not using the standard library (hence the _start +# instead of main). We only link dynamically to some standard libraries. +# This way we have a tiny binary (~8K) that has debug symbols and uses breakpad +# to generate a Minidump when the binary crashes/requests such. +# +CC=g++ +FLAGS=-g --std=c++11 +INCLUDE=-I$HOME/breakpad/src/src/ +LINK=-L. -lbreakpad -lpthread -nostdlib -lc -lstdc++ -lgcc_s -fno-exceptions +all: + $(CC) $(FLAGS) -fPIC -c install_breakpad.cpp $(INCLUDE) -o install_breakpad.o + ld -shared install_breakpad.o libbreakpad_client.a -o libbreakpad.so + $(CC) $(FLAGS) -o linux-x86_64 linux-x86_64.cpp $(LINK) + $(CC) $(FLAGS) -o linux-x86_64_not_crashed linux-x86_64_not_crashed.cpp $(LINK) |

