2 Test basics of mini dump debugging.
5 from __future__ import print_function
10 from lldbsuite.test.lldbtest import *
11 import lldbsuite.test.lldbutil as lldbutil
13 class MiniDumpTestCase(TestBase):
15 mydir = TestBase.compute_mydir(__file__)
17 @skipUnlessWindows # for now mini-dump debugging is limited to Windows hosts
19 def test_process_info_in_mini_dump(self):
20 """Test that lldb can read the process information from the minidump."""
21 # target create -c fizzbuzz_no_heap.dmp
22 self.dbg.CreateTarget("")
23 self.target = self.dbg.GetSelectedTarget()
24 self.process = self.target.LoadCore("fizzbuzz_no_heap.dmp")
25 self.assertTrue(self.process, PROCESS_IS_VALID)
26 self.assertEqual(self.process.GetNumThreads(), 1)
27 self.assertEqual(self.process.GetProcessID(), 4440)
29 @skipUnlessWindows # for now mini-dump debugging is limited to Windows hosts
31 def test_thread_info_in_mini_dump(self):
32 """Test that lldb can read the thread information from the minidump."""
33 # target create -c fizzbuzz_no_heap.dmp
34 self.dbg.CreateTarget("")
35 self.target = self.dbg.GetSelectedTarget()
36 self.process = self.target.LoadCore("fizzbuzz_no_heap.dmp")
37 # This process crashed due to an access violation (0xc0000005) in its one and only thread.
38 self.assertEqual(self.process.GetNumThreads(), 1)
39 thread = self.process.GetThreadAtIndex(0)
40 self.assertEqual(thread.GetStopReason(), lldb.eStopReasonException)
41 stop_description = thread.GetStopDescription(256);
42 self.assertTrue("0xc0000005" in stop_description);
44 @skipUnlessWindows # for now mini-dump debugging is limited to Windows hosts
46 def test_stack_info_in_mini_dump(self):
47 """Test that we can see a trivial stack in a VS-generate mini dump."""
48 # target create -c fizzbuzz_no_heap.dmp
49 self.dbg.CreateTarget("")
50 self.target = self.dbg.GetSelectedTarget()
51 self.process = self.target.LoadCore("fizzbuzz_no_heap.dmp")
52 self.assertEqual(self.process.GetNumThreads(), 1)
53 thread = self.process.GetThreadAtIndex(0)
54 # The crash is in main, so there should be one frame on the stack.
55 self.assertEqual(thread.GetNumFrames(), 1)
56 frame = thread.GetFrameAtIndex(0)
57 self.assertTrue(frame.IsValid())
59 eip = frame.FindRegister("pc")
60 self.assertTrue(eip.IsValid())
61 self.assertEqual(pc, eip.GetValueAsUnsigned())
64 @not_remote_testsuite_ready
65 def test_deeper_stack_in_mini_dump(self):
66 """Test that we can examine a more interesting stack in a mini dump."""
68 exe = os.path.join(os.getcwd(), "a.out")
69 core = os.path.join(os.getcwd(), "core.dmp")
71 # Set a breakpoint and capture a mini dump.
72 target = self.dbg.CreateTarget(exe)
73 breakpoint = target.BreakpointCreateByName("bar")
74 process = target.LaunchSimple(None, None, self.get_process_working_directory())
75 self.assertEqual(process.GetState(), lldb.eStateStopped)
76 self.assertTrue(process.SaveCore(core))
77 self.assertTrue(os.path.isfile(core))
78 self.assertTrue(process.Kill().Success())
80 # Launch with the mini dump, and inspect the stack.
81 target = self.dbg.CreateTarget(None)
82 process = target.LoadCore(core)
83 thread = process.GetThreadAtIndex(0)
85 expected_stack = { 0: 'bar', 1: 'foo', 2: 'main' }
86 self.assertEqual(thread.GetNumFrames(), len(expected_stack))
87 for index, name in expected_stack.iteritems():
88 frame = thread.GetFrameAtIndex(index)
89 self.assertTrue(frame.IsValid())
90 function_name = frame.GetFunctionName()
91 self.assertTrue(name in function_name)
94 # Clean up the mini dump file.
95 self.assertTrue(self.dbg.DeleteTarget(target))
96 if (os.path.isfile(core)):
100 @not_remote_testsuite_ready
101 def test_local_variables_in_mini_dump(self):
102 """Test that we can examine local variables in a mini dump."""
104 exe = os.path.join(os.getcwd(), "a.out")
105 core = os.path.join(os.getcwd(), "core.dmp")
107 # Set a breakpoint and capture a mini dump.
108 target = self.dbg.CreateTarget(exe)
109 breakpoint = target.BreakpointCreateByName("bar")
110 process = target.LaunchSimple(None, None, self.get_process_working_directory())
111 self.assertEqual(process.GetState(), lldb.eStateStopped)
112 self.assertTrue(process.SaveCore(core))
113 self.assertTrue(os.path.isfile(core))
114 self.assertTrue(process.Kill().Success())
116 # Launch with the mini dump, and inspect a local variable.
117 target = self.dbg.CreateTarget(None)
118 process = target.LoadCore(core)
119 thread = process.GetThreadAtIndex(0)
120 frame = thread.GetFrameAtIndex(0)
121 value = frame.EvaluateExpression('x')
122 self.assertEqual(value.GetValueAsSigned(), 3)
125 # Clean up the mini dump file.
126 self.assertTrue(self.dbg.DeleteTarget(target))
127 if (os.path.isfile(core)):