Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / lldb / test / API / functionalities / postmortem / FreeBSDKernel / TestFreeBSDKernelVMCore.py
blob86ba661296a7f03ccb3fa377be8f60353ebcd46a
1 import bz2
2 import shutil
3 import struct
5 import lldb
6 from lldbsuite.test.decorators import *
7 from lldbsuite.test.lldbtest import *
8 from lldbsuite.test import lldbutil
11 @skipIfFBSDVMCoreSupportMissing
12 class FreeBSDKernelVMCoreTestCase(TestBase):
13 NO_DEBUG_INFO_TESTCASE = True
14 maxDiff = None
16 def make_target(self, src_filename):
17 src = self.getSourcePath(src_filename)
18 dest = self.getBuildArtifact("kernel")
19 self.yaml2obj(src, dest, max_size=30 * 1024 * 1024)
20 return self.dbg.CreateTarget(dest)
22 def make_vmcore(self, src_filename):
23 src = self.getSourcePath(src_filename)
24 dest = self.getBuildArtifact("vmcore")
25 with bz2.open(src, "rb") as inf:
26 with open(dest, "wb") as outf:
27 shutil.copyfileobj(inf, outf)
28 return dest
30 def do_test(self, kernel_yaml, vmcore_bz2, numthread, threads={}, hz=100):
31 target = self.make_target(kernel_yaml)
32 vmcore_file = self.make_vmcore(vmcore_bz2)
33 process = target.LoadCore(vmcore_file)
35 self.assertTrue(process, PROCESS_IS_VALID)
36 self.assertEqual(process.GetNumThreads(), numthread)
37 self.assertEqual(process.GetProcessID(), 0)
39 # test memory reading
40 self.expect("expr -- *(int *) &hz", substrs=["(int) $0 = %d" % hz])
42 main_mod = target.GetModuleAtIndex(0)
43 hz_addr = main_mod.FindSymbols("hz")[0].symbol.addr.GetLoadAddress(target)
44 error = lldb.SBError()
45 self.assertEqual(process.ReadMemory(hz_addr, 4, error), struct.pack("<I", hz))
47 for thread_index, thread_data in threads.items():
48 bt_expected = thread_data["bt"]
49 regs_expected = thread_data["regs"]
50 thread = process.GetThreadAtIndex(thread_index)
51 self.assertEqual(thread.GetName(), thread_data["name"])
53 # test backtrace
54 self.assertEqual(
55 [frame.addr.GetLoadAddress(target) for frame in thread], bt_expected
58 # test registers
59 regs = thread.GetFrameAtIndex(0).GetRegisters()
60 reg_values = {}
61 for regset in regs:
62 for reg in regset:
63 if reg.value is None:
64 continue
65 reg_values[reg.name] = reg.value
66 self.assertEqual(reg_values, regs_expected)
68 self.dbg.DeleteTarget(target)
70 def test_amd64_full_vmcore(self):
71 self.do_test(
72 "kernel-amd64.yaml",
73 "vmcore-amd64-full.bz2",
74 numthread=13,
75 threads={
76 0: {
77 "name": "(pid 806) sysctl (crashed)",
78 "bt": [
79 0xFFFFFFFF80C09ADE,
80 0xFFFFFFFF80C09916,
81 0xFFFFFFFF80C09D90,
82 0xFFFFFFFF80C09B93,
83 0xFFFFFFFF80C57D91,
84 0xFFFFFFFF80C19E71,
85 0xFFFFFFFF80C192BC,
86 0xFFFFFFFF80C19933,
87 0xFFFFFFFF80C1977F,
88 0xFFFFFFFF8108BA8C,
89 0xFFFFFFFF810620CE,
91 "regs": {
92 "rbx": "0x0000000000000000",
93 "rbp": "0xfffffe0085cb2760",
94 "rsp": "0xfffffe0085cb2748",
95 "r12": "0xfffffe0045a6c300",
96 "r13": "0xfffff800033693a8",
97 "r14": "0x0000000000000000",
98 "r15": "0xfffff80003369380",
99 "rip": "0xffffffff80c09ade",
102 1: {
103 "name": "(pid 11) idle/idle: cpu0 (on CPU 0)",
104 "bt": [
105 0xFFFFFFFF81057988,
106 0xFFFFFFFF81057949,
107 0xFFFFFFFF8108A5FF,
108 0xFFFFFFFF81062537,
109 0xFFFFFFFF80C1AA38,
110 0xFFFFFFFF80B9D587,
111 0xFFFFFFFF810575B1,
112 0xFFFFFFFF81063B33,
113 0xFFFFFFFF804E3EDB,
114 0xFFFFFFFF8104DC6E,
115 0xFFFFFFFF8104DD1F,
116 0xFFFFFFFF80C3F0B4,
117 0xFFFFFFFF80BC7C5E,
119 "regs": {
120 "rbx": "0xffffffff81d43950",
121 "rbp": "0xffffffff81d43820",
122 "rsp": "0xffffffff81d43808",
123 "r12": "0xfffff80003374000",
124 "r13": "0x00000000027be000",
125 "r14": "0x0000000000000000",
126 "r15": "0xfffffe00009f7300",
127 "rip": "0xffffffff81057988",
130 10: {
131 "name": "(pid 11) idle/idle: cpu9",
132 "bt": [
133 0xFFFFFFFF80C3C8C8,
134 0xFFFFFFFF80C16521,
135 0xFFFFFFFF80C3F0B4,
136 0xFFFFFFFF80BC7C5E,
138 "regs": {
139 "rbx": "0x000000007fff29f4",
140 "rbp": "0xfffffe00007a4ad0",
141 "rsp": "0xfffffe00007a4a08",
142 "r12": "0xfffffe00009fd300",
143 "r13": "0x0000000000000608",
144 "r14": "0xfffffe00009250c0",
145 "r15": "0xfffffe0045a6c300",
146 "rip": "0xffffffff80c3c8c8",
152 def test_amd64_minidump(self):
153 self.do_test(
154 "kernel-amd64.yaml",
155 "vmcore-amd64-minidump.bz2",
156 numthread=16,
157 threads={
158 0: {
159 "name": "(pid 800) sysctl (crashed)",
160 "bt": [
161 0xFFFFFFFF80C09ADE,
162 0xFFFFFFFF80C09916,
163 0xFFFFFFFF80C09D90,
164 0xFFFFFFFF80C09B93,
165 0xFFFFFFFF80C57D91,
166 0xFFFFFFFF80C19E71,
167 0xFFFFFFFF80C192BC,
168 0xFFFFFFFF80C19933,
169 0xFFFFFFFF80C1977F,
170 0xFFFFFFFF8108BA8C,
171 0xFFFFFFFF810620CE,
173 "regs": {
174 "rbx": "0x0000000000000000",
175 "rbp": "0xfffffe00798c4760",
176 "rsp": "0xfffffe00798c4748",
177 "r12": "0xfffffe0045b11c00",
178 "r13": "0xfffff800033693a8",
179 "r14": "0x0000000000000000",
180 "r15": "0xfffff80003369380",
181 "rip": "0xffffffff80c09ade",
184 1: {
185 "name": "(pid 28) pagedaemon/dom0 (on CPU 4)",
186 "bt": [
187 0xFFFFFFFF81057988,
188 0xFFFFFFFF81057949,
189 0xFFFFFFFF8108A5FF,
190 0xFFFFFFFF81062537,
191 0xFFFFFFFF8107171E,
192 0xFFFFFFFF81075F9C,
193 0xFFFFFFFF80F4359E,
194 0xFFFFFFFF80F494B4,
195 0xFFFFFFFF80F47430,
196 0xFFFFFFFF80F46EEE,
197 0xFFFFFFFF80BC7C5E,
199 "regs": {
200 "rbx": "0xfffffe00008e2f30",
201 "rbp": "0xfffffe00008e2e00",
202 "rsp": "0xfffffe00008e2de8",
203 "r12": "0xfffff80003845000",
204 "r13": "0x00000000027be000",
205 "r14": "0x0000000000000004",
206 "r15": "0xfffffe00458c2700",
207 "rip": "0xffffffff81057988",
210 2: {
211 "name": "(pid 28) pagedaemon/laundry: dom0",
212 "bt": [
213 0xFFFFFFFF80C3C8C8,
214 0xFFFFFFFF80C16521,
215 0xFFFFFFFF80C15C3B,
216 0xFFFFFFFF80F48DFC,
217 0xFFFFFFFF80BC7C5E,
219 "regs": {
220 "rbx": "0x000000007fff25f1",
221 "rbp": "0xfffffe00527dd890",
222 "rsp": "0xfffffe00527dd7c8",
223 "r12": "0xfffffe0045b13100",
224 "r13": "0x0000000000000104",
225 "r14": "0xfffffe00008d70c0",
226 "r15": "0xfffffe00009f5e00",
227 "rip": "0xffffffff80c3c8c8",
233 def test_arm64_minidump(self):
234 self.do_test(
235 "kernel-arm64.yaml",
236 "vmcore-arm64-minidump.bz2",
237 hz=1000,
238 numthread=10,
239 threads={
240 0: {
241 "name": "(pid 939) sysctl (crashed)",
242 # TODO: fix unwinding
243 "bt": [
244 0xFFFF0000004B6E78,
246 "regs": {
247 "x0": "0x0000000000000000",
248 "x1": "0x0000000000000000",
249 "x2": "0x0000000000000000",
250 "x3": "0x0000000000000000",
251 "x4": "0x0000000000000000",
252 "x5": "0x0000000000000000",
253 "x6": "0x0000000000000000",
254 "x7": "0x0000000000000000",
255 "x8": "0xffffa00001548700",
256 "x9": "0x0000000000000000",
257 "x10": "0xffffa00000e04580",
258 "x11": "0x0000000000000000",
259 "x12": "0x000000000008950a",
260 "x13": "0x0000000000089500",
261 "x14": "0x0000000000000039",
262 "x15": "0x0000000000000000",
263 "x16": "0x00000000ffffffd8",
264 "x17": "0x0000000000000000",
265 "x18": "0xffff000000e6d380",
266 "x19": "0xffff000000af9000",
267 "x20": "0xffff000000b82000",
268 "x21": "0xffffa00000319da8",
269 "x22": "0xffff000000b84000",
270 "x23": "0xffff000000b84000",
271 "x24": "0xffff000000b55000",
272 "x25": "0x0000000000000000",
273 "x26": "0x0000000000040800",
274 "x27": "0x0000000000000000",
275 "x28": "0x00000000002019ca",
276 "fp": "0xffff0000d58f23b0",
277 "sp": "0xffff0000d58f23b0",
278 "pc": "0xffff0000004b6e78",
281 1: {
282 "name": "(pid 21) syncer (on CPU 6)",
283 # TODO: fix unwinding
284 "bt": [
285 0xFFFF000000811370,
287 "regs": {
288 "x0": "0x0000000000000000",
289 "x1": "0x0000000000000000",
290 "x2": "0x0000000000000000",
291 "x3": "0x0000000000000000",
292 "x4": "0x0000000000000000",
293 "x5": "0x0000000000000000",
294 "x6": "0x0000000000000000",
295 "x7": "0x0000000000000000",
296 "x8": "0x0000000000000006",
297 "x9": "0x0000000000000560",
298 "x10": "0xffff000000e8f640",
299 "x11": "0x0000000000000001",
300 "x12": "0x0000000056000000",
301 "x13": "0x0000000000002af8",
302 "x14": "0x0000000000002710",
303 "x15": "0x0000000000000002",
304 "x16": "0x00000000ffffffff",
305 "x17": "0x0000000000000002",
306 "x18": "0xffff000000e6db80",
307 "x19": "0x0000000000000006",
308 "x20": "0xffff0000853a3670",
309 "x21": "0xffff0000009279c1",
310 "x22": "0x0000000000000804",
311 "x23": "0x0000000000000004",
312 "x24": "0xffff000082a93000",
313 "x25": "0xffffa0000053f080",
314 "x26": "0xffff000000e6391c",
315 "x27": "0xffff000000e63000",
316 "x28": "0x0000000000000004",
317 "fp": "0xffff0000853a35c0",
318 "sp": "0xffff0000853a35c0",
319 "pc": "0xffff000000811370",
322 4: {
323 "name": "(pid 11) idle/idle: cpu2",
324 # TODO: fix unwinding
325 "bt": [
326 0xFFFF0000004EE99C,
328 "regs": {
329 "x0": "0x0000000000000000",
330 "x1": "0x0000000000000000",
331 "x2": "0x0000000000000000",
332 "x3": "0x0000000000000000",
333 "x4": "0x0000000000000000",
334 "x5": "0x0000000000000000",
335 "x6": "0x0000000000000000",
336 "x7": "0x0000000000000000",
337 "x8": "0x00000000ffffffff",
338 "x9": "0x0000000000000001",
339 "x10": "0x0000000000002710",
340 "x11": "0x000000007ff7e333",
341 "x12": "0x000000007ff7ba9c",
342 "x13": "0x0000000000002af8",
343 "x14": "0x0000000000002897",
344 "x15": "0x0000000000002af8",
345 "x16": "0x00000000000028e1",
346 "x17": "0x00000000ffffffff",
347 "x18": "0xffff000000e6d380",
348 "x19": "0xffffa0000032e580",
349 "x20": "0xffff000000b82000",
350 "x21": "0xffff000040517100",
351 "x22": "0xffffa00000e04580",
352 "x23": "0xffff000000b84000",
353 "x24": "0x0000000000000001",
354 "x25": "0xffff000000dd1000",
355 "x26": "0xffff000082783898",
356 "x27": "0xffff000000e26000",
357 "x28": "0xffff000000b82000",
358 "fp": "0xffff0000827835f0",
359 "sp": "0xffff000082783570",
360 "pc": "0xffff0000004ee99c",
366 def test_i386_minidump(self):
367 self.do_test(
368 "kernel-i386.yaml",
369 "vmcore-i386-minidump.bz2",
370 numthread=13,
371 threads={
372 0: {
373 "name": "(pid 806) sysctl (crashed)",
374 "bt": [
375 0x010025C5,
376 0x01002410,
377 0x010027D5,
378 0x01002644,
379 0x01049A2F,
380 0x01011077,
381 0x01010780,
382 0x01010C7A,
383 0x01010AB2,
384 0x013E9E2D,
385 0xFFC033F9,
387 "regs": {
388 "ebp": "0x151968e4",
389 "esp": "0x151968d8",
390 "esi": "0x0c77aa80",
391 "edi": "0x03f0dc80",
392 "eip": "0x010025c5",
395 1: {
396 "name": "(pid 11) idle/idle: cpu0 (on CPU 0)",
397 "bt": [
398 0x013A91F6,
399 0x013A91C0,
400 0x013E8CE4,
401 0xFFC0319F,
402 0x00000028,
404 "regs": {
405 "ebp": "0x03d979bc",
406 "esp": "0x03d979a0",
407 "esi": "0x000007f7",
408 "edi": "0x00000000",
409 "eip": "0x013a91f6",
412 12: {
413 "name": "(pid 11) idle/idle: cpu11",
414 "bt": [
415 0x0103012C,
416 0x0100DE0E,
417 0x0100B770,
418 0x010323BE,
419 0x00FC50B6,
421 "regs": {
422 "ebp": "0x03dc4af0",
423 "esp": "0x03dc4aa4",
424 "esi": "0x03f97e00",
425 "edi": "0x000003e8",
426 "eip": "0x0103012c",