2 Miscellaneous (Intel) platform-specific commands.
8 @lldb_command('showmcastate')
9 def showMCAstate(cmd_args
=None):
11 Print machine-check register state after MC exception.
13 if kern
.arch
!= 'x86_64':
14 print "Not available for current architecture."
17 present
= ["not present", "present"]
18 print 'MCA {:s}, control MSR {:s}, threshold status {:s}'.format(
19 present
[int(kern
.globals.mca_MCA_present
)],
20 present
[int(kern
.globals.mca_control_MSR_present
)],
21 present
[int(kern
.globals.mca_threshold_status_present
)])
22 print '{:d} error banks, family code {:#0x}, machine-check dump state: {:d}'.format(
23 kern
.globals.mca_error_bank_count
,
24 kern
.globals.mca_dump_state
,
25 kern
.globals.mca_family
)
27 while kern
.globals.cpu_data_ptr
[cpu
]:
28 cd
= kern
.globals.cpu_data_ptr
[cpu
]
31 print 'CPU {:d}: mca_mcg_ctl: {:#018x} mca_mcg_status {:#018x}'.format(cpu
, mc
.mca_mcg_ctl
, mc
.mca_mcg_status
.u64
)
32 hdr
= '{:<4s} {:<18s} {:<18s} {:<18s} {:<18s}'
33 val
= '{:>3d}: {:#018x} {:#018x} {:#018x} {:#018x}'
34 print hdr
.format('bank',
39 for i
in range(int(kern
.globals.mca_error_bank_count
)):
40 bank
= mc
.mca_error_bank
[i
]
43 bank
.mca_mci_status
.u64
,
46 print 'register state:'
47 reg
= cd
.cpu_desc_index
.cdi_ktss
.ist1
- sizeof('x86_saved_state_t')
48 print lldb_run_command('p/x *(x86_saved_state_t *) ' + hex(reg
))
51 def dumpTimerList(anchor
):
53 Utility function to dump the timer entries in list (anchor).
55 entry
= Cast(anchor
.head
, 'queue_t')
56 if entry
== addressof(anchor
):
60 thdr
= ' {:<22s}{:<17s}{:<16s} {:<14s} {:<18s}'
61 print thdr
.format('entry:','deadline','soft_deadline','to go','(*func)(param0,param1')
62 while entry
!= addressof(anchor
):
63 timer_call
= Cast(entry
, 'timer_call_t')
64 call_entry
= Cast(entry
, 'struct call_entry *')
65 debugger_entry
= kern
.globals.debugger_entry_time
66 if (debugger_entry
< call_entry
.deadline
):
68 timer_fire
= call_entry
.deadline
- debugger_entry
71 timer_fire
= debugger_entry
- call_entry
.deadline
72 tval
= ' {:#018x}: {:16d} {:16d} {:s}{:3d}.{:09d} ({:#018x})({:#018x},{:#018x})'
73 print tval
.format(entry
,
75 timer_call
.soft_deadline
,
77 timer_fire
/1000000000,
78 timer_fire
%1000000000,
84 @lldb_command('longtermtimers')
85 def longtermTimers(cmd_args
=None):
87 Print details of long-term timers and stats.
89 if kern
.arch
!= 'x86_64':
90 print "Not available for current architecture."
93 lt
= kern
.globals.timer_longterm
96 if ltt
.interval
== EndofAllTime
:
97 print "Longterm timers disabled"
101 ratio
= lt
.enqueues
/ lt
.escalates
104 print 'Longterm timer object: {:#018x}'.format(addressof(lt
))
105 print ' queue count : {:d}' .format(lt
.queue
.count
)
106 print ' number of enqueues : {:d}' .format(lt
.enqueues
)
107 print ' number of dequeues : {:d}' .format(lt
.dequeues
)
108 print ' number of escalates : {:d}' .format(lt
.escalates
)
109 print ' enqueues/escalates : {:d}' .format(ratio
)
110 print ' threshold.interval : {:d}' .format(ltt
.interval
)
111 print ' threshold.margin : {:d}' .format(ltt
.margin
)
112 print ' scan_time : {:d}' .format(lt
.scan_time
)
113 if ltt
.preempted
== EndofAllTime
:
114 print ' threshold.preempted : None'
116 print ' threshold.preempted : {:d}' .format(ltt
.preempted
)
117 if ltt
.deadline
== EndofAllTime
:
118 print ' threshold.deadline : None'
120 print ' threshold.deadline : {:d}' .format(ltt
.deadline
)
121 print ' threshold.call : {:#018x}'.format(ltt
.call
)
122 print ' actual deadline set : {:d}' .format(ltt
.deadline_set
)
123 print ' threshold.scans : {:d}' .format(ltt
.scans
)
124 print ' threshold.preempts : {:d}' .format(ltt
.preempts
)
125 print ' threshold.latency : {:d}' .format(ltt
.latency
)
126 print ' - min : {:d}' .format(ltt
.latency_min
)
127 print ' - max : {:d}' .format(ltt
.latency_max
)
128 dumpTimerList(lt
.queue
)
131 @lldb_command('processortimers')
132 def processorTimers(cmd_args
=None):
134 Print details of processor timers, noting anything suspicious
135 Also include long-term timer details
137 hdr
= '{:<32s}{:<18s} {:<18s} {:<18s}'
138 print hdr
.format('Processor','Last dispatch','Next deadline','difference')
139 p
= kern
.globals.processor_list
142 rt_timer
= kern
.globals.cpu_data_ptr
[cpu
].rtclock_timer
143 diff
= p
.last_dispatch
- rt_timer
.deadline
144 tmr
= 'Processor {:d}: {:#018x} {:#018x} {:#018x} {:#018x} {:s}'
145 print tmr
.format(cpu
,
150 ['probably BAD', '(ok)'][int(diff
< 0)])
151 if kern
.arch
== 'x86_64':
152 print 'Next deadline set at: {:#018x}. Timer call list:'.format(rt_timer
.when_set
)
153 dumpTimerList(rt_timer
.queue
)
158 @lldb_command('showtimerwakeupstats')
159 def showTimerWakeupStats(cmd_args
=None):
161 Displays interrupt and platform idle wakeup frequencies
162 associated with each thread, timer time-to-deadline frequencies, and
163 CPU time with user/system break down where applicable, with thread tags.
165 for task
in kern
.tasks
:
166 proc
= Cast(task
.bsd_info
, 'proc_t')
167 print dereference(task
)
168 print '{:d}({:s}), terminated thread timer wakeups: {:d} {:d} 2ms: {:d} 5ms: {:d} UT: {:d} ST: {:d}'.format(
171 # Commented-out references below to be addressed by rdar://13009660.
172 0, #task.task_interrupt_wakeups,
173 0, #task.task_platform_idle_wakeups,
174 task
.task_timer_wakeups_bin_1
,
175 task
.task_timer_wakeups_bin_2
,
176 task
.total_user_time
,
177 task
.total_system_time
)
178 tot_wakes
= 0 #task.task_interrupt_wakeups
179 tot_platform_wakes
= 0 #task.task_platform_idle_wakeups
180 for thread
in IterateQueue(task
.threads
, 'thread_t', 'task_threads'):
181 # if thread.thread_interrupt_wakeups == 0:
183 print '\tThread ID 0x{:x}, Tag 0x{:x}, timer wakeups: {:d} {:d} {:d} {:d} <2ms: {:d}, <5ms: {:d} UT: {:d} ST: {:d}'.format(
186 0, #thread.thread_interrupt_wakeups,
187 0, #thread.thread_platform_idle_wakeups,
188 0, #thread.thread_callout_interrupt_wakeups,
189 0, #thread.thread_callout_platform_idle_wakeups,
191 thread
.thread_timer_wakeups_bin_1
,
192 thread
.thread_timer_wakeups_bin_2
,
193 thread
.user_timer
.all_bits
,
194 thread
.system_timer
.all_bits
)
195 tot_wakes
+= 0 #thread.thread_interrupt_wakeups
196 tot_platform_wakes
+= 0 #thread.thread_platform_idle_wakeups
197 print 'Task total wakeups: {:d} {:d}'.format(
198 tot_wakes
, tot_platform_wakes
)
200 def DoReadMsr64(msr_address
, lcpu
):
201 """ Read a 64-bit MSR from the specified CPU
203 msr_address: int - MSR index to read from
204 lcpu: int - CPU identifier
206 64-bit value read from the MSR
210 if "kdp" != GetConnectionProtocol():
211 print "Target is not connected over kdp. Cannot read MSR."
214 input_address
= unsigned(addressof(kern
.globals.manual_pkt
.input))
215 len_address
= unsigned(addressof(kern
.globals.manual_pkt
.len))
216 data_address
= unsigned(addressof(kern
.globals.manual_pkt
.data
))
217 if not WriteInt32ToMemoryAddress(0, input_address
):
218 print "DoReadMsr64() failed to write 0 to input_address"
221 kdp_pkt_size
= GetType('kdp_readmsr64_req_t').GetByteSize()
222 if not WriteInt32ToMemoryAddress(kdp_pkt_size
, len_address
):
223 print "DoReadMsr64() failed to write kdp_pkt_size"
226 kgm_pkt
= kern
.GetValueFromAddress(data_address
, 'kdp_readmsr64_req_t *')
227 header_value
= GetKDPPacketHeaderInt(
228 request
=GetEnumValue('kdp_req_t::KDP_READMSR64'),
231 if not WriteInt64ToMemoryAddress(header_value
, int(addressof(kgm_pkt
.hdr
))):
232 print "DoReadMsr64() failed to write header_value"
234 if not WriteInt32ToMemoryAddress(msr_address
, int(addressof(kgm_pkt
.address
))):
235 print "DoReadMsr64() failed to write msr_address"
237 if not WriteInt16ToMemoryAddress(lcpu
, int(addressof(kgm_pkt
.lcpu
))):
238 print "DoReadMsr64() failed to write lcpu"
240 if not WriteInt32ToMemoryAddress(1, input_address
):
241 print "DoReadMsr64() failed to write to input_address"
244 result_pkt
= Cast(addressof(kern
.globals.manual_pkt
.data
),
245 'kdp_readmsr64_reply_t *')
246 if (result_pkt
.error
== 0):
247 result
= dereference(Cast(addressof(result_pkt
.data
), 'uint64_t *'))
249 print "DoReadMsr64() result_pkt.error != 0"
252 def DoWriteMsr64(msr_address
, lcpu
, data
):
253 """ Write a 64-bit MSR
255 msr_address: int - MSR index to write to
256 lcpu: int - CPU identifier
257 data: int - value to write
259 True upon success, False if error
261 if "kdp" != GetConnectionProtocol():
262 print "Target is not connected over kdp. Cannot write MSR."
265 input_address
= unsigned(addressof(kern
.globals.manual_pkt
.input))
266 len_address
= unsigned(addressof(kern
.globals.manual_pkt
.len))
267 data_address
= unsigned(addressof(kern
.globals.manual_pkt
.data
))
268 if not WriteInt32ToMemoryAddress(0, input_address
):
269 print "DoWriteMsr64() failed to write 0 to input_address"
272 kdp_pkt_size
= GetType('kdp_writemsr64_req_t').GetByteSize()
273 if not WriteInt32ToMemoryAddress(kdp_pkt_size
, len_address
):
274 print "DoWriteMsr64() failed to kdp_pkt_size"
277 kgm_pkt
= kern
.GetValueFromAddress(data_address
, 'kdp_writemsr64_req_t *')
278 header_value
= GetKDPPacketHeaderInt(
279 request
=GetEnumValue('kdp_req_t::KDP_WRITEMSR64'),
282 if not WriteInt64ToMemoryAddress(header_value
, int(addressof(kgm_pkt
.hdr
))):
283 print "DoWriteMsr64() failed to write header_value"
285 if not WriteInt32ToMemoryAddress(msr_address
, int(addressof(kgm_pkt
.address
))):
286 print "DoWriteMsr64() failed to write msr_address"
288 if not WriteInt16ToMemoryAddress(lcpu
, int(addressof(kgm_pkt
.lcpu
))):
289 print "DoWriteMsr64() failed to write lcpu"
291 if not WriteInt64ToMemoryAddress(data
, int(addressof(kgm_pkt
.data
))):
292 print "DoWriteMsr64() failed to write data"
294 if not WriteInt32ToMemoryAddress(1, input_address
):
295 print "DoWriteMsr64() failed to write to input_address"
298 result_pkt
= Cast(addressof(kern
.globals.manual_pkt
.data
),
299 'kdp_writemsr64_reply_t *')
300 if not result_pkt
.error
== 0:
301 print "DoWriteMsr64() error received in reply packet"
306 @lldb_command('readmsr64')
307 def ReadMsr64(cmd_args
=None):
308 """ Read the specified MSR. The CPU can be optionally specified
309 Syntax: readmsr64 <msr> [lcpu]
311 if cmd_args
== None or len(cmd_args
) < 1:
312 print ReadMsr64
.__doc__
315 msr_address
= ArgumentStringToInt(cmd_args
[0])
316 if len(cmd_args
) > 1:
317 lcpu
= ArgumentStringToInt(cmd_args
[1])
319 lcpu
= int(xnudefines
.lcpu_self
)
321 msr_value
= DoReadMsr64(msr_address
, lcpu
)
322 print "MSR[{:x}]: {:#016x}".format(msr_address
, msr_value
)
324 @lldb_command('writemsr64')
325 def WriteMsr64(cmd_args
=None):
326 """ Write the specified MSR. The CPU can be optionally specified
327 Syntax: writemsr64 <msr> <value> [lcpu]
329 if cmd_args
== None or len(cmd_args
) < 2:
330 print WriteMsr64
.__doc__
332 msr_address
= ArgumentStringToInt(cmd_args
[0])
333 write_val
= ArgumentStringToInt(cmd_args
[1])
334 if len(cmd_args
) > 2:
335 lcpu
= ArgumentStringToInt(cmd_args
[2])
337 lcpu
= xnudefines
.lcpu_self
339 if not DoWriteMsr64(msr_address
, lcpu
, write_val
):
340 print "writemsr64 FAILED"
342 def GetEVFlags(debug_arg
):
343 """ Return the EV Flags for the given kernel debug arg value
345 debug_arg - value from arg member of kernel debug buffer entry
347 str - string representing the EV Flag for given input arg value
358 if debug_arg
& 0x00100:
359 out_str
+= "EV_RBYTES "
360 if debug_arg
& 0x00200:
361 out_str
+= "EV_WBYTES "
362 if debug_arg
& 0x00400:
363 out_str
+= "EV_RCLOSED "
364 if debug_arg
& 0x00800:
365 out_str
+= "EV_RCONN "
366 if debug_arg
& 0x01000:
367 out_str
+= "EV_WCLOSED "
368 if debug_arg
& 0x02000:
369 out_str
+= "EV_WCONN "
370 if debug_arg
& 0x04000:
372 if debug_arg
& 0x08000:
374 if debug_arg
& 0x10000:
375 out_str
+= "EV_RESET "
376 if debug_arg
& 0x20000:
377 out_str
+= "EV_TIMEOUT "
381 def GetKernelDebugBufferEntry(kdbg_entry
):
382 """ Extract the information from given kernel debug buffer entry and return the summary
384 kdebug_entry - kd_buf - address of kernel debug buffer entry
386 str - formatted output information of kd_buf entry
390 kdebug_entry
= kern
.GetValueFromAddress(kdbg_entry
, 'kd_buf *')
391 debugid
= kdebug_entry
.debugid
392 kdebug_arg1
= kdebug_entry
.arg1
393 kdebug_arg2
= kdebug_entry
.arg2
394 kdebug_arg3
= kdebug_entry
.arg3
395 kdebug_arg4
= kdebug_entry
.arg4
397 if kern
.arch
in ('x86_64', 'arm64'):
398 kdebug_cpu
= kdebug_entry
.cpuid
399 ts_hi
= (kdebug_entry
.timestamp
>> 32) & 0xFFFFFFFF
400 ts_lo
= kdebug_entry
.timestamp
& 0xFFFFFFFF
402 kdebug_cpu
= (kdebug_entry
.timestamp
>> 56)
403 ts_hi
= (kdebug_entry
.timestamp
>> 32) & 0x00FFFFFF
404 ts_lo
= kdebug_entry
.timestamp
& 0xFFFFFFFF
406 kdebug_class
= (debugid
>> 24) & 0x000FF
407 kdebug_subclass
= (debugid
>> 16) & 0x000FF
408 kdebug_code
= (debugid
>> 2) & 0x03FFF
409 kdebug_qual
= (debugid
) & 0x00003
413 elif kdebug_qual
== 1:
415 elif kdebug_qual
== 2:
417 elif kdebug_qual
== 3:
421 out_str
+= "{:<#20x} {:>6d} {:>#12x} ".format(kdebug_entry
, kdebug_cpu
, kdebug_entry
.arg5
)
422 out_str
+= " {:#010x}{:08x} {:>6s} ".format(ts_hi
, ts_lo
, kdebug_qual
)
426 if kdebug_class
== 1:
428 elif kdebug_class
== 2:
430 elif kdebug_class
== 3:
432 elif kdebug_class
== 4:
434 elif kdebug_class
== 5:
436 elif kdebug_class
== 6:
438 elif kdebug_class
== 7:
440 elif kdebug_class
== 8:
442 elif kdebug_class
== 9:
444 elif kdebug_class
== 10:
446 elif kdebug_class
== 11:
448 elif kdebug_class
== 20:
450 elif kdebug_class
== 30:
452 elif kdebug_class
== 31:
454 elif kdebug_class
== 32:
456 elif kdebug_class
== 33:
458 elif kdebug_class
== 34:
460 elif kdebug_class
== 36:
462 elif kdebug_class
== 37:
464 elif kdebug_class
== 38:
466 elif kdebug_class
== 39:
468 elif kdebug_class
== 40:
470 elif kdebug_class
== 41:
472 elif kdebug_class
== 42:
474 elif kdebug_class
== 128:
476 elif kdebug_class
== 129:
478 elif kdebug_class
== 130:
480 elif kdebug_class
== 131:
482 elif kdebug_class
== 132:
484 elif kdebug_class
== 133:
486 elif kdebug_class
== 255:
489 out_str
+= "{:^#10x} ".format(kdebug_class
)
492 out_str
+= "{:^10s} ".format(kdbg_class
)
495 out_str
+= " {:>#5x} {:>8d} ".format(kdebug_subclass
, kdebug_code
)
497 # space for debugid-specific processing
498 # EVPROC from bsd/kern/sys_generic.c
499 # MISCDBG_CODE(DBG_EVENT,DBG_WAIT)
500 if debugid
== 0x14100048:
501 code_info_str
+= "waitevent "
503 code_info_str
+= "before sleep"
504 elif kdebug_arg1
== 2:
505 code_info_str
+= "after sleep"
507 code_info_str
+= "????????????"
508 code_info_str
+= " chan={:#08x} ".format(kdebug_arg2
)
509 elif debugid
== 0x14100049:
510 # MISCDBG_CODE(DBG_EVENT,DBG_WAIT|DBG_FUNC_START)
511 code_info_str
+= "waitevent "
512 elif debugid
== 0x1410004a:
513 # MISCDBG_CODE(DBG_EVENT,DBG_WAIT|DBG_FUNC_END)
514 code_info_str
+= "waitevent error={:d} ".format(kdebug_arg1
)
515 code_info_str
+= "eqp={:#08x} ".format(kdebug_arg4
)
516 code_info_str
+= GetEVFlags(kdebug_arg3
)
517 code_info_str
+= "er_handle={:d} ".format(kdebug_arg2
)
518 elif debugid
== 0x14100059:
519 # MISCDBG_CODE(DBG_EVENT,DBG_DEQUEUE|DBG_FUNC_START)
520 code_info_str
+= "evprocdeque proc={:#08x} ".format(kdebug_arg1
)
522 code_info_str
+= "remove first "
524 code_info_str
+= "remove {:#08x} ".format(kdebug_arg2
)
525 elif debugid
== 0x1410005a:
526 # MISCDBG_CODE(DBG_EVENT,DBG_DEQUEUE|DBG_FUNC_END)
527 code_info_str
+= "evprocdeque "
529 code_info_str
+= "result=NULL "
531 code_info_str
+= "result={:#08x} ".format(kdebug_arg1
)
532 elif debugid
== 0x14100041:
533 # MISCDBG_CODE(DBG_EVENT,DBG_POST|DBG_FUNC_START)
534 code_info_str
+= "postevent "
535 code_info_str
+= GetEVFlags(kdebug_arg1
)
536 elif debugid
== 0x14100040:
537 # MISCDBG_CODE(DBG_EVENT,DBG_POST)
538 code_info_str
+= "postevent "
539 code_info_str
+= "evq={:#08x} ".format(kdebug_arg1
)
540 code_info_str
+= "er_eventbits="
541 code_info_str
+= GetEVFlags(kdebug_arg2
)
542 code_info_str
+="mask="
543 code_info_str
+= GetEVFlags(kdebug_arg3
)
544 elif debugid
== 0x14100042:
545 # MISCDBG_CODE(DBG_EVENT,DBG_POST|DBG_FUNC_END)
546 code_info_str
+= "postevent "
547 elif debugid
== 0x14100055:
548 # MISCDBG_CODE(DBG_EVENT,DBG_ENQUEUE|DBG_FUNC_START)
549 code_info_str
+= "evprocenque eqp={:#08x} ".format(kdebug_arg1
)
551 code_info_str
+= "EV_QUEUED "
552 code_info_str
+= GetEVFlags(kdebug_arg3
)
553 elif debugid
== 0x14100050:
554 # MISCDBG_CODE(DBG_EVENT,DBG_EWAKEUP)
555 code_info_str
+= "evprocenque before wakeup eqp={:#08x} ".format(kdebug_arg4
)
556 elif debugid
== 0x14100056:
557 # MISCDBG_CODE(DBG_EVENT,DBG_ENQUEUE|DBG_FUNC_END)
558 code_info_str
+= "evprocenque "
559 elif debugid
== 0x1410004d:
560 # MISCDBG_CODE(DBG_EVENT,DBG_MOD|DBG_FUNC_START)
561 code_info_str
+= "modwatch "
562 elif debugid
== 0x1410004c:
563 # MISCDBG_CODE(DBG_EVENT,DBG_MOD)
564 code_info_str
+= "modwatch er_handle={:d} ".format(kdebug_arg1
)
565 code_info_str
+= GetEVFlags(kdebug_arg2
)
566 code_info_str
+= "evq={:#08x} ", kdebug_arg3
567 elif debugid
== 0x1410004e:
568 # MISCDBG_CODE(DBG_EVENT,DBG_MOD|DBG_FUNC_END)
569 code_info_str
+= "modwatch er_handle={:d} ".format(kdebug_arg1
)
570 code_info_str
+= "ee_eventmask="
571 code_info_str
+= GetEVFlags(kdebug_arg2
)
572 code_info_str
+= "sp={:#08x} ".format(kdebug_arg3
)
573 code_info_str
+= "flag="
574 code_info_str
+= GetEVFlags(kdebug_arg4
)
576 code_info_str
+= "arg1={:#010x} ".format(kdebug_arg1
)
577 code_info_str
+= "arg2={:#010x} ".format(kdebug_arg2
)
578 code_info_str
+= "arg3={:#010x} ".format(kdebug_arg3
)
579 code_info_str
+= "arg4={:#010x} ".format(kdebug_arg4
)
582 out_str
+= "{:<25s}\n".format(code_info_str
)
585 @lldb_command('showkerneldebugbuffercpu')
586 @header("{0: ^20s} {1: >6s} {2: >12s} {3: ^20s} {4: >6s} {5: ^10s} {6: >5s} {7: >8s} {8: ^25s}".
587 format('kd_buf', 'CPU', 'Thread', 'Timestamp', 'S/E', 'Class', 'Sub', 'Code', 'Code Specific Info'))
588 def ShowKernelDebugBufferCPU(cmd_args
=None):
589 """ Prints the last N entries in the kernel debug buffer for specified cpu
590 Syntax: showkerneldebugbuffercpu <cpu_num> <count>
592 if cmd_args
== None or len(cmd_args
) < 2:
593 raise ArgumentError("Invalid arguments passed.")
597 cpu_number
= ArgumentStringToInt(cmd_args
[0])
598 entry_count
= ArgumentStringToInt(cmd_args
[1])
599 debugentriesfound
= 0
600 # Check if KDBG_BFINIT (0x80000000) is set in kdebug_flags
601 if (kern
.globals.kd_ctrl_page
.kdebug_flags
& 0x80000000):
602 out_str
+= ShowKernelDebugBufferCPU
.header
+ "\n"
604 out_str
+= "<count> is 0, dumping 50 entries\n"
607 if cpu_number
>= kern
.globals.kd_ctrl_page
.kdebug_cpus
:
608 kdbg_str
+= "cpu number too big\n"
610 kdbp
= addressof(kern
.globals.kdbip
[cpu_number
])
611 kdsp
= kdbp
.kd_list_head
612 while ((kdsp
.raw
!= 0 and kdsp
.raw
!= 0x00000000ffffffff) and (entry_count
> 0)):
613 kd_buffer
= kern
.globals.kd_bufs
[kdsp
.buffer_index
]
614 kdsp_actual
= addressof(kd_buffer
.kdsb_addr
[kdsp
.offset
])
615 if kdsp_actual
.kds_readlast
!= kdsp_actual
.kds_bufindx
:
616 kds_buf
= kdsp_actual
.kds_records
[kdsp_actual
.kds_bufindx
]
617 kds_bufptr
= addressof(kds_buf
)
618 while (entry_count
> 0) and \
619 (unsigned(kds_bufptr
) > unsigned(addressof(kdsp_actual
.kds_records
[kdsp_actual
.kds_readlast
]))):
620 kds_bufptr
= kds_bufptr
- sizeof(kds_buf
)
621 entry_count
= entry_count
- 1
622 kdbg_str
+= GetKernelDebugBufferEntry(kds_bufptr
)
623 kdsp
= kdsp_actual
.kds_next
625 kdbg_str
+= "Trace buffer not enabled for CPU {:d}\n".format(cpu_number
)
631 @lldb_command('showkerneldebugbuffer')
632 def ShowKernelDebugBuffer(cmd_args
=None):
633 """ Prints the last N entries in the kernel debug buffer per cpu
634 Syntax: showkerneldebugbuffer <count>
636 if cmd_args
== None or len(cmd_args
) < 1:
637 raise ArgumentError("Invalid arguments passed.")
639 # Check if KDBG_BFINIT (0x80000000) is set in kdebug_flags
640 if (kern
.globals.kd_ctrl_page
.kdebug_flags
& 0x80000000):
641 entrycount
= ArgumentStringToInt(cmd_args
[0])
643 print "<count> is 0, dumping 50 entries per cpu\n"
646 while cpu_num
< kern
.globals.kd_ctrl_page
.kdebug_cpus
:
647 ShowKernelDebugBufferCPU([str(cpu_num
), str(entrycount
)])
650 print "Trace buffer not enabled\n"