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"