From 78b9749c0a4ea980a8b934645da6ae98fcc665e8 Mon Sep 17 00:00:00 2001 From: dim Date: Wed, 6 Jan 2016 20:12:03 +0000 Subject: Vendor import of lldb trunk r256945: https://llvm.org/svn/llvm-project/lldb/trunk@256945 --- .../functionalities/postmortem/minidump/Makefile | 6 + .../postmortem/minidump/TestMiniDump.py | 128 +++++++++++++++++++++ .../postmortem/minidump/fizzbuzz.cpp | 31 +++++ .../postmortem/minidump/fizzbuzz_no_heap.dmp | Bin 0 -> 6297 bytes .../functionalities/postmortem/minidump/main.cpp | 21 ++++ 5 files changed, 186 insertions(+) create mode 100644 packages/Python/lldbsuite/test/functionalities/postmortem/minidump/Makefile create mode 100644 packages/Python/lldbsuite/test/functionalities/postmortem/minidump/TestMiniDump.py create mode 100644 packages/Python/lldbsuite/test/functionalities/postmortem/minidump/fizzbuzz.cpp create mode 100644 packages/Python/lldbsuite/test/functionalities/postmortem/minidump/fizzbuzz_no_heap.dmp create mode 100644 packages/Python/lldbsuite/test/functionalities/postmortem/minidump/main.cpp (limited to 'packages/Python/lldbsuite/test/functionalities/postmortem') diff --git a/packages/Python/lldbsuite/test/functionalities/postmortem/minidump/Makefile b/packages/Python/lldbsuite/test/functionalities/postmortem/minidump/Makefile new file mode 100644 index 0000000..b3034c1 --- /dev/null +++ b/packages/Python/lldbsuite/test/functionalities/postmortem/minidump/Makefile @@ -0,0 +1,6 @@ +LEVEL = ../../../make + +CXX_SOURCES := main.cpp + +include $(LEVEL)/Makefile.rules + diff --git a/packages/Python/lldbsuite/test/functionalities/postmortem/minidump/TestMiniDump.py b/packages/Python/lldbsuite/test/functionalities/postmortem/minidump/TestMiniDump.py new file mode 100644 index 0000000..5388850 --- /dev/null +++ b/packages/Python/lldbsuite/test/functionalities/postmortem/minidump/TestMiniDump.py @@ -0,0 +1,128 @@ +""" +Test basics of mini dump debugging. +""" + +from __future__ import print_function + + + +import lldb +from lldbsuite.test.lldbtest import * +import lldbsuite.test.lldbutil as lldbutil + +class MiniDumpTestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + @skipUnlessWindows # for now mini-dump debugging is limited to Windows hosts + @no_debug_info_test + def test_process_info_in_mini_dump(self): + """Test that lldb can read the process information from the minidump.""" + # target create -c fizzbuzz_no_heap.dmp + self.dbg.CreateTarget("") + self.target = self.dbg.GetSelectedTarget() + self.process = self.target.LoadCore("fizzbuzz_no_heap.dmp") + self.assertTrue(self.process, PROCESS_IS_VALID) + self.assertEqual(self.process.GetNumThreads(), 1) + self.assertEqual(self.process.GetProcessID(), 4440) + + @skipUnlessWindows # for now mini-dump debugging is limited to Windows hosts + @no_debug_info_test + def test_thread_info_in_mini_dump(self): + """Test that lldb can read the thread information from the minidump.""" + # target create -c fizzbuzz_no_heap.dmp + self.dbg.CreateTarget("") + self.target = self.dbg.GetSelectedTarget() + self.process = self.target.LoadCore("fizzbuzz_no_heap.dmp") + # This process crashed due to an access violation (0xc0000005) in its one and only thread. + self.assertEqual(self.process.GetNumThreads(), 1) + thread = self.process.GetThreadAtIndex(0) + self.assertEqual(thread.GetStopReason(), lldb.eStopReasonException) + stop_description = thread.GetStopDescription(256); + self.assertTrue("0xc0000005" in stop_description); + + @skipUnlessWindows # for now mini-dump debugging is limited to Windows hosts + @no_debug_info_test + def test_stack_info_in_mini_dump(self): + """Test that we can see a trivial stack in a VS-generate mini dump.""" + # target create -c fizzbuzz_no_heap.dmp + self.dbg.CreateTarget("") + self.target = self.dbg.GetSelectedTarget() + self.process = self.target.LoadCore("fizzbuzz_no_heap.dmp") + self.assertEqual(self.process.GetNumThreads(), 1) + thread = self.process.GetThreadAtIndex(0) + # The crash is in main, so there should be one frame on the stack. + self.assertEqual(thread.GetNumFrames(), 1) + frame = thread.GetFrameAtIndex(0) + self.assertTrue(frame.IsValid()) + pc = frame.GetPC() + eip = frame.FindRegister("pc") + self.assertTrue(eip.IsValid()) + self.assertEqual(pc, eip.GetValueAsUnsigned()) + + @skipUnlessWindows + @not_remote_testsuite_ready + def test_deeper_stack_in_mini_dump(self): + """Test that we can examine a more interesting stack in a mini dump.""" + self.build() + exe = os.path.join(os.getcwd(), "a.out") + core = os.path.join(os.getcwd(), "core.dmp") + try: + # Set a breakpoint and capture a mini dump. + target = self.dbg.CreateTarget(exe) + breakpoint = target.BreakpointCreateByName("bar") + process = target.LaunchSimple(None, None, self.get_process_working_directory()) + self.assertEqual(process.GetState(), lldb.eStateStopped) + self.assertTrue(process.SaveCore(core)) + self.assertTrue(os.path.isfile(core)) + self.assertTrue(process.Kill().Success()) + + # Launch with the mini dump, and inspect the stack. + target = self.dbg.CreateTarget(None) + process = target.LoadCore(core) + thread = process.GetThreadAtIndex(0) + + expected_stack = { 0: 'bar', 1: 'foo', 2: 'main' } + self.assertEqual(thread.GetNumFrames(), len(expected_stack)) + for index, name in expected_stack.iteritems(): + frame = thread.GetFrameAtIndex(index) + self.assertTrue(frame.IsValid()) + function_name = frame.GetFunctionName() + self.assertTrue(name in function_name) + + finally: + # Clean up the mini dump file. + self.assertTrue(self.dbg.DeleteTarget(target)) + if (os.path.isfile(core)): + os.unlink(core) + + @skipUnlessWindows + @not_remote_testsuite_ready + def test_local_variables_in_mini_dump(self): + """Test that we can examine local variables in a mini dump.""" + self.build() + exe = os.path.join(os.getcwd(), "a.out") + core = os.path.join(os.getcwd(), "core.dmp") + try: + # Set a breakpoint and capture a mini dump. + target = self.dbg.CreateTarget(exe) + breakpoint = target.BreakpointCreateByName("bar") + process = target.LaunchSimple(None, None, self.get_process_working_directory()) + self.assertEqual(process.GetState(), lldb.eStateStopped) + self.assertTrue(process.SaveCore(core)) + self.assertTrue(os.path.isfile(core)) + self.assertTrue(process.Kill().Success()) + + # Launch with the mini dump, and inspect a local variable. + target = self.dbg.CreateTarget(None) + process = target.LoadCore(core) + thread = process.GetThreadAtIndex(0) + frame = thread.GetFrameAtIndex(0) + value = frame.EvaluateExpression('x') + self.assertEqual(value.GetValueAsSigned(), 3) + + finally: + # Clean up the mini dump file. + self.assertTrue(self.dbg.DeleteTarget(target)) + if (os.path.isfile(core)): + os.unlink(core) diff --git a/packages/Python/lldbsuite/test/functionalities/postmortem/minidump/fizzbuzz.cpp b/packages/Python/lldbsuite/test/functionalities/postmortem/minidump/fizzbuzz.cpp new file mode 100644 index 0000000..eb6476b --- /dev/null +++ b/packages/Python/lldbsuite/test/functionalities/postmortem/minidump/fizzbuzz.cpp @@ -0,0 +1,31 @@ +// A sample program for getting minidumps on Windows. + +#include + +bool +fizz(int x) +{ + return x % 3 == 0; +} + +bool +buzz(int x) +{ + return x % 5 == 0; +} + +int +main() +{ + int *buggy = 0; + + for (int i = 1; i <= 100; ++i) + { + if (fizz(i)) std::cout << "fizz"; + if (buzz(i)) std::cout << "buzz"; + if (!fizz(i) && !buzz(i)) std::cout << i; + std::cout << '\n'; + } + + return *buggy; +} diff --git a/packages/Python/lldbsuite/test/functionalities/postmortem/minidump/fizzbuzz_no_heap.dmp b/packages/Python/lldbsuite/test/functionalities/postmortem/minidump/fizzbuzz_no_heap.dmp new file mode 100644 index 0000000..19008c9 Binary files /dev/null and b/packages/Python/lldbsuite/test/functionalities/postmortem/minidump/fizzbuzz_no_heap.dmp differ diff --git a/packages/Python/lldbsuite/test/functionalities/postmortem/minidump/main.cpp b/packages/Python/lldbsuite/test/functionalities/postmortem/minidump/main.cpp new file mode 100644 index 0000000..4037ea5 --- /dev/null +++ b/packages/Python/lldbsuite/test/functionalities/postmortem/minidump/main.cpp @@ -0,0 +1,21 @@ +int global = 42; + +int +bar(int x) +{ + int y = 4*x + global; + return y; +} + +int +foo(int x) +{ + int y = 2*bar(3*x); + return y; +} + +int +main() +{ + return 0 * foo(1); +} -- cgit v1.1