[Lldb-commits] [lldb] r255379 - Add some tests for stack and local variable inspection for mini dumps.

Adrian McCarthy via lldb-commits lldb-commits at lists.llvm.org
Fri Dec 11 14:27:58 PST 2015


Author: amccarth
Date: Fri Dec 11 16:27:57 2015
New Revision: 255379

URL: http://llvm.org/viewvc/llvm-project?rev=255379&view=rev
Log:
Add some tests for stack and local variable inspection for mini dumps.

Differential Revision: http://reviews.llvm.org/D15435

Added:
    lldb/trunk/packages/Python/lldbsuite/test/functionalities/postmortem/minidump/Makefile
    lldb/trunk/packages/Python/lldbsuite/test/functionalities/postmortem/minidump/main.cpp
Modified:
    lldb/trunk/packages/Python/lldbsuite/test/functionalities/postmortem/minidump/TestMiniDump.py

Added: lldb/trunk/packages/Python/lldbsuite/test/functionalities/postmortem/minidump/Makefile
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/functionalities/postmortem/minidump/Makefile?rev=255379&view=auto
==============================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/functionalities/postmortem/minidump/Makefile (added)
+++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/postmortem/minidump/Makefile Fri Dec 11 16:27:57 2015
@@ -0,0 +1,6 @@
+LEVEL = ../../../make
+
+CXX_SOURCES := main.cpp
+
+include $(LEVEL)/Makefile.rules
+

Modified: lldb/trunk/packages/Python/lldbsuite/test/functionalities/postmortem/minidump/TestMiniDump.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/functionalities/postmortem/minidump/TestMiniDump.py?rev=255379&r1=255378&r2=255379&view=diff
==============================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/functionalities/postmortem/minidump/TestMiniDump.py (original)
+++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/postmortem/minidump/TestMiniDump.py Fri Dec 11 16:27:57 2015
@@ -10,21 +10,30 @@ import lldb
 from lldbsuite.test.lldbtest import *
 import lldbsuite.test.lldbutil as lldbutil
 
- at skipUnlessWindows  # for now mini-dump debugging is limited to Windows hosts
 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)
@@ -32,9 +41,14 @@ class MiniDumpTestCase(TestBase):
         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 the stack."""
+        """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.
@@ -46,10 +60,69 @@ class MiniDumpTestCase(TestBase):
         self.assertTrue(eip.IsValid())
         self.assertEqual(pc, eip.GetValueAsUnsigned())
 
-    def setUp(self):
-        # Call super's setUp().
-        TestBase.setUp(self)
-        # target create -c fizzbuzz_no_heap.dmp
-        self.dbg.CreateTarget("")
-        self.target = self.dbg.GetSelectedTarget()
-        self.process = self.target.LoadCore("fizzbuzz_no_heap.dmp")
+    @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)

Added: lldb/trunk/packages/Python/lldbsuite/test/functionalities/postmortem/minidump/main.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/functionalities/postmortem/minidump/main.cpp?rev=255379&view=auto
==============================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/functionalities/postmortem/minidump/main.cpp (added)
+++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/postmortem/minidump/main.cpp Fri Dec 11 16:27:57 2015
@@ -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);
+}




More information about the lldb-commits mailing list