4 # From the defines in bsd/sys/kdebug.h:
44 def GetKdebugClassName(class_num
):
45 return (KdebugClassNames
[class_num
] + ' ({})'.format(class_num) if class_num in KdebugClassNames else 'unknown ({})'.format(class_num
))
47 @lldb_type_summary(['typefilter_t'])
48 @header('{0: <20s}'.format("class") + ' '.join(map('{:02x}'.format
, xrange(0, 255, 8))))
49 def GetKdebugTypefilter(typefilter
):
50 """ Summarizes the provided typefilter.
53 subclasses_per_class
= 256
56 subclasses_per_element
= 64
57 cur_typefilter
= cast(typefilter
, 'uint64_t *')
58 subclasses_fmts
= ' '.join(['{:02x}'] * 8)
60 elements_per_class
= subclasses_per_class
/ subclasses_per_element
63 for i
in xrange(0, classes
):
65 subclasses
= [0] * elements_per_class
67 # check subclass ranges for set bits, remember those subclasses
68 for j
in xrange(0, elements_per_class
):
69 element
= unsigned(cur_typefilter
[i
* elements_per_class
+ j
])
73 subclasses
[j
] = element
75 ## if any of the bits were set in a class, print the entire class
77 out_str
+= '{:<20s}'.format(GetKdebugClassName(i
))
78 for element
in subclasses
:
79 # split up the 64-bit values into byte-sized pieces
80 bytes = [unsigned((element
>> i
) & 0xff) for i
in (0, 8, 16, 24, 32, 40, 48, 56)]
81 out_str
+= subclasses_fmts
.format(*bytes)
88 @lldb_command('showkdebugtypefilter')
89 def ShowKdebugTypefilter(cmd_args
=None):
90 """ Show the current kdebug typefilter (or the typefilter at an address)
92 usage: showkdebugtypefilter [<address>]
96 typefilter
= kern
.GetValueFromAddress(cmd_args
[0], 'typefilter_t')
97 if unsigned(typefilter
) == 0:
98 raise ArgumentError('argument provided is NULL')
100 print GetKdebugTypefilter
.header
101 print '-' * len(GetKdebugTypefilter
.header
)
103 print GetKdebugTypefilter(typefilter
)
106 typefilter
= kern
.globals.kdbg_typefilter
107 if unsigned(typefilter
) == 0:
108 raise ArgumentError('no argument provided and active typefilter is not set')
110 print GetKdebugTypefilter
.header
111 print '-' * len(GetKdebugTypefilter
.header
)
112 print GetKdebugTypefilter(typefilter
)
114 def GetKdebugStatus():
115 """ Get a string summary of the kdebug subsystem.
119 kdebug_flags
= kern
.globals.kd_ctrl_page
.kdebug_flags
120 out
+= 'kdebug flags: {}\n'.format(xnudefines
.GetStateString(xnudefines
.kdebug_flags_strings
, kdebug_flags
))
121 events
= kern
.globals.nkdbufs
122 buf_mb
= events
* (64 if kern
.arch
== 'x86_64' or kern
.arch
.startswith('arm64') else 32) / 1000000
123 out
+= 'events allocated: {:<d} ({:<d} MB)\n'.format(events
, buf_mb
)
124 out
+= 'enabled: {}\n'.format('yes' if kern
.globals.kdebug_enable
!= 0 else 'no')
125 if kdebug_flags
& xnudefines
.kdebug_typefilter_check
:
126 out
+= 'typefilter:\n'
127 out
+= GetKdebugTypefilter
.header
+ '\n'
128 out
+= '-' * len(GetKdebugTypefilter
.header
) + '\n'
129 typefilter
= kern
.globals.kdbg_typefilter
130 if unsigned(typefilter
) != 0:
131 out
+= GetKdebugTypefilter(typefilter
)
135 @lldb_command('showkdebug')
136 def ShowKdebug(cmd_args
=None):
137 """ Show the current kdebug state.
142 print GetKdebugStatus()
144 @lldb_type_summary(['kperf_timer'])
145 @header('{:<10s} {:<7s} {:<20s}'.format('period-ns', 'action', 'pending'))
146 def GetKperfTimerSummary(timer
):
147 """ Get a string summary of a kperf timer.
150 timer: the kperf_timer object to get a summary of
152 return '{:<10d} {:<7d} {:<20x}\n'.format(
153 kern
.GetNanotimeFromAbstime(timer
.period
), timer
.actionid
, timer
.pending_cpus
)
155 @lldb_type_summary(['action'])
156 @header('{:<10s} {:<20s} {:<20s}'.format('pid-filter', 'user-data', 'samplers'))
157 def GetKperfActionSummary(action
):
158 """ Get a string summary of a kperf action.
161 action: the action object to get a summary of
163 samplers
= xnudefines
.GetStateString(xnudefines
.kperf_samplers_strings
, action
.sample
)
164 return '{:<10s} {:<20x} {:<20s}\n'.format(
165 '-' if action
.pid_filter
< 0 else str(action
.pid_filter
), action
.userdata
, samplers
)
167 def GetKperfStatus():
168 """ Get a string summary of the kperf subsystem.
172 kperf_status
= kern
.globals.sampling_status
174 if kperf_status
== 0:
176 elif kperf_status
== 1:
178 elif kperf_status
== 2:
179 out
+= 'shutting down\n'
183 pet
= 0# kern.globals.pet_running
184 pet_timer_id
= kern
.globals.pet_timer_id
186 pet_idle_rate
= kern
.globals.pet_idle_rate
187 out
+= 'legacy PET is active (timer = {:<d}, idle rate = {:<d})\n'.format(pet_timer_id
, pet_idle_rate
)
189 out
+= 'legacy PET is off\n'
191 lw_pet
= kern
.globals.kperf_lightweight_pet_active
193 lw_pet_gen
= kern
.globals.kperf_pet_gen
194 out
+= 'lightweight PET is active (timer = {:<d}, generation count = {:<d})\n'.format(pet_timer_id
, lw_pet_gen
)
196 out
+= 'lightweight PET is off\n'
198 actions
= kern
.globals.actionc
199 actions_arr
= kern
.globals.actionv
202 out
+= '{:<5s} '.format('id') + GetKperfActionSummary
.header
+ '\n'
203 for i
in xrange(0, actions
):
204 out
+= '{:<5d} '.format(i
) + GetKperfActionSummary(actions_arr
[i
])
206 timers
= kern
.globals.kperf_timerc
207 timers_arr
= kern
.globals.kperf_timerv
210 out
+= '{:<5s} '.format('id') + GetKperfTimerSummary
.header
+ '\n'
211 for i
in xrange(0, timers
):
212 out
+= '{:<5d} '.format(i
) + GetKperfTimerSummary(timers_arr
[i
])
216 def GetKtraceStatus():
217 """ Get a string summary of the ktrace subsystem.
221 state
= kern
.globals.ktrace_state
222 if state
== GetEnumValue('ktrace_state::KTRACE_STATE_OFF'):
223 out
+= 'ktrace is off\n'
225 out
+= 'ktrace is active ('
226 if state
== GetEnumValue('ktrace_state::KTRACE_STATE_FG'):
231 owner
= kern
.globals.ktrace_last_owner_execname
232 out
+= 'owned by: {0: <s}\n'.format(owner
)
233 active_mask
= kern
.globals.ktrace_active_mask
234 out
+= 'active systems: {:<#x}\n'.format(active_mask
)
238 @lldb_command('showktrace')
239 def ShowKtrace(cmd_args
=None):
240 """ Show the current ktrace state, including subsystems.
245 print GetKtraceStatus()
248 print GetKdebugStatus()
251 print GetKperfStatus()