]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - packages/Python/lldbsuite/test/functionalities/postmortem/minidump/TestMiniDump.py
Vendor import of lldb trunk r256945:
[FreeBSD/FreeBSD.git] / packages / Python / lldbsuite / test / functionalities / postmortem / minidump / TestMiniDump.py
1 """
2 Test basics of mini dump debugging.
3 """
4
5 from __future__ import print_function
6
7
8
9 import lldb
10 from lldbsuite.test.lldbtest import *
11 import lldbsuite.test.lldbutil as lldbutil
12
13 class MiniDumpTestCase(TestBase):
14
15     mydir = TestBase.compute_mydir(__file__)
16
17     @skipUnlessWindows  # for now mini-dump debugging is limited to Windows hosts
18     @no_debug_info_test
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)
28
29     @skipUnlessWindows  # for now mini-dump debugging is limited to Windows hosts
30     @no_debug_info_test
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);
43
44     @skipUnlessWindows  # for now mini-dump debugging is limited to Windows hosts
45     @no_debug_info_test
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())
58         pc = frame.GetPC()
59         eip = frame.FindRegister("pc")
60         self.assertTrue(eip.IsValid())
61         self.assertEqual(pc, eip.GetValueAsUnsigned())
62
63     @skipUnlessWindows
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."""
67         self.build()
68         exe = os.path.join(os.getcwd(), "a.out")
69         core = os.path.join(os.getcwd(), "core.dmp")
70         try:
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())
79
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)
84
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)
92
93         finally:
94             # Clean up the mini dump file.
95             self.assertTrue(self.dbg.DeleteTarget(target))
96             if (os.path.isfile(core)):
97                 os.unlink(core)
98
99     @skipUnlessWindows
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."""
103         self.build()
104         exe = os.path.join(os.getcwd(), "a.out")
105         core = os.path.join(os.getcwd(), "core.dmp")
106         try:
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())
115
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)
123
124         finally:
125             # Clean up the mini dump file.
126             self.assertTrue(self.dbg.DeleteTarget(target))
127             if (os.path.isfile(core)):
128                 os.unlink(core)