3 def IterateProcKqueues(proc
):
4 """ Iterate through all kqueues in the given process
8 returns: nothing, this is meant to be used as a generator function
9 kq - yields each kqueue in the process
11 for kqf
in IterateProcKqfiles(proc
):
12 yield kern
.GetValueFromAddress(int(kqf
), 'struct kqueue *')
13 if int(proc
.p_fd
.fd_wqkqueue
) != 0:
14 yield kern
.GetValueFromAddress(int(proc
.p_fd
.fd_wqkqueue
), 'struct kqueue *')
15 for kqwl
in IterateProcKqworkloops(proc
):
16 yield kern
.GetValueFromAddress(int(kqwl
), 'struct kqueue *')
18 def IterateProcKqfiles(proc
):
19 """ Iterate through all kqfiles in the given process
22 proc - the proc object
23 returns: nothing, this is meant to be used as a generator function
24 kqf - yields each kqfile in the process
28 proc_filedesc
= proc
.p_fd
29 proc_lastfile
= unsigned(proc_filedesc
.fd_lastfile
)
30 proc_ofiles
= proc_filedesc
.fd_ofiles
34 if unsigned(proc_ofiles
) == 0:
37 while count
<= proc_lastfile
:
38 if unsigned(proc_ofiles
[count
]) != 0:
39 proc_fd_flags
= proc_ofiles
[count
].f_flags
40 proc_fd_fglob
= proc_ofiles
[count
].f_fglob
41 proc_fd_ftype
= unsigned(proc_fd_fglob
.fg_ops
.fo_type
)
42 if proc_fd_ftype
== xnudefines
.DTYPE_KQUEUE
:
43 yield kern
.GetValueFromAddress(int(proc_fd_fglob
.fg_data
), 'struct kqfile *')
46 def IterateProcKqworkloops(proc
):
47 """ Iterate through all kqworkloops in the given process
50 proc - the proc object
51 returns: nothing, this is meant to be used as a generator function
52 kqwl - yields each kqworkloop in the process
54 proc_filedesc
= proc
.p_fd
55 if int(proc_filedesc
.fd_kqhash
) == 0:
58 hash_mask
= proc_filedesc
.fd_kqhashmask
59 for i
in xrange(hash_mask
+ 1):
60 for kqwl
in IterateListEntry(proc_filedesc
.fd_kqhash
[i
], 'struct kqworkloop *', 'kqwl_hashlink', list_prefix
='s'):
63 def IterateAllKqueues():
64 """ Iterate through all kqueues in the system
66 returns: nothing, this is meant to be used as a generator function
67 kq - yields each kqueue in the system
70 if unsigned(t
.bsd_info
) == 0:
72 proc
= kern
.GetValueFromAddress(t
.bsd_info
, 'proc_t')
73 for kq
in IterateProcKqueues(proc
):
76 def IterateProcKnotes(proc
):
77 """ Iterate through all knotes in the given process
80 proc - the proc object
81 returns: nothing, this is meant to be used as a generator function
82 kn - yields each knote in the process
84 proc_filedesc
= proc
.p_fd
86 if int(proc
.p_fd
.fd_knlist
) != 0:
87 for i
in xrange(proc
.p_fd
.fd_knlistsize
):
88 for kn
in IterateListEntry(proc
.p_fd
.fd_knlist
[i
], 'struct knote *', 'kn_link', list_prefix
='s'):
90 if int(proc
.p_fd
.fd_knhash
) != 0:
91 for i
in xrange(proc
.p_fd
.fd_knhashmask
+ 1):
92 for kn
in IterateListEntry(proc
.p_fd
.fd_knhash
[i
], 'struct knote *', 'kn_link', list_prefix
='s'):
95 def GetKnoteKqueue(kn
):
96 """ Get the kqueue corresponding to a given knote
100 returns: kq - the kqueue corresponding to the knote
102 return kern
.GetValueFromAddress(kn
.kn_kq_packed
+ kern
.VM_MIN_KERNEL_AND_KEXT_ADDRESS
, 'struct kqueue *')
104 @lldb_type_summary(['knote *'])
105 @header('{:<20s} {:<20s} {:<10s} {:<20s} {:<20s} {:<30s} {:<10} {:<10} {:<10} {:<30s}'.format('knote', 'ident', 'kev_flags', 'kqueue', 'udata', 'filtops', 'qos_use', 'qos_req', 'qos_ovr', 'status'))
106 def GetKnoteSummary(kn
):
107 """ Summarizes a knote and related information
109 returns: str - summary of knote
111 format_string
= '{o: <#020x} {o.kn_kevent.ident: <#020x} {o.kn_kevent.flags: <#010x} {kq_ptr: <#020x} {o.kn_kevent.udata: <#020x} {ops_str: <30s} {qos_use: <10s} {qos_req: <10s} {qos_ovr: <10s} {st_str: <30s}'
112 state
= unsigned(kn
.kn_status
)
113 fops_str
= kern
.Symbolicate(kern
.globals.sysfilt_ops
[unsigned(kn
.kn_filtid
)])
114 return format_string
.format(
116 qos_use
=xnudefines
.thread_qos_short_strings
[int(kn
.kn_qos_index
)],
117 qos_req
=xnudefines
.thread_qos_short_strings
[int(kn
.kn_req_index
)],
118 qos_ovr
=xnudefines
.thread_qos_short_strings
[int(kn
.kn_qos_override
)],
119 st_str
=xnudefines
.GetStateString(xnudefines
.kn_state_strings
, state
),
120 kq_ptr
=int(GetKnoteKqueue(kn
)),
123 @lldb_command('showknote')
124 def ShowKnote(cmd_args
=None):
125 """ Show information about a knote
127 usage: showknote <struct knote *>
130 raise ArgumentError('missing struct knote * argument')
132 kn
= kern
.GetValueFromAddress(cmd_args
[0], 'struct knote *')
133 print GetKnoteSummary
.header
134 print GetKnoteSummary(kn
)
136 def IterateKqueueKnotes(kq
):
137 """ Iterate through all knotes of a given kqueue
140 kq - the kqueue to iterate the knotes of
141 returns: nothing, this is meant to be used as a generator function
142 kn - yields each knote in the kqueue
145 for kn
in IterateProcKnotes(proc
):
146 if unsigned(GetKnoteKqueue(kn
)) != unsigned(addressof(kq
)):
150 @lldb_type_summary(['struct kqrequest *'])
151 @header('{:<20s} {:<20s} {:<5s} {:<5s} {:<5s} {:<5s} {:s}'.format('kqrequest', 'thread', 'qos', 'ovr_qos', 'w_qos', 'sa_qos', 'state'))
152 def GetKqrequestSummary(kqr
):
153 """ Summarize kqrequest information
156 kqr - the kqrequest object
157 returns: str - summary of kqrequest
159 fmt
= '{kqrp: <#020x} {kqr.kqr_bound.kqrb_thread: <#020x} {qos: <5s} {ovr_qos: <5s} {w_qos: <5s} {sa_qos: <5s} {state_str:<s}'
160 return fmt
.format(kqrp
=int(kqr
),
162 qos
=xnudefines
.thread_qos_short_strings
[int(kqr
.kqr_qos_index
)],
163 ovr_qos
=xnudefines
.thread_qos_short_strings
[int(kqr
.kqr_override_index
)],
164 w_qos
=xnudefines
.thread_qos_short_strings
[int(kqr
.kqr_dsync_waiters_qos
)],
165 sa_qos
=xnudefines
.thread_qos_short_strings
[int(kqr
.kqr_stayactive_qos
)],
166 state_str
=xnudefines
.GetStateString(xnudefines
.kqrequest_state_strings
, kqr
.kqr_state
))
168 @lldb_command('showkqrequest')
169 def ShowKqrequest(cmd_args
=None):
170 """ Display information about a kqrequest object.
172 usage: showkqrequest <struct kqrequest *>
174 if len(cmd_args
) < 1:
175 raise ArgumentError('missing struct kqrequest * argument')
176 kqr
= kern
.GetValueFromAddress(cmd_args
[0], 'struct kqrequest *')
177 print GetKqrequestSummary
.header
178 print GetKqrequestSummary(kqr
)
179 print GetKnoteSummary
.header
180 for kn
in IterateTAILQ_HEAD(kqr
.kqr_suppressed
, 'kn_tqe'):
181 print GetKnoteSummary(kn
)
183 kqueue_summary_fmt
= '{ptr: <#020x} {o.kq_p: <#020x} {dyn_id: <#020x} {servicer: <#20x} {owner: <#20x} {o.kq_count: <6d} {wqs: <#020x} {kqr_state: <30s} {st_str: <10s}'
185 @lldb_type_summary(['struct kqueue *'])
186 @header('{: <20s} {: <20s} {: <20s} {: <20s} {: <20s} {: <6s} {: <20s} {: <30s} {: <10s}'.format('kqueue', 'process', 'dynamic_id', 'servicer', 'owner', '#evts', 'wqs', 'request', 'state'))
187 def GetKqueueSummary(kq
):
188 """ Summarize kqueue information
191 kq - the kqueue object
192 returns: str - summary of kqueue
194 if kq
.kq_state
& xnudefines
.KQ_WORKLOOP
:
195 return GetKqworkloopSummary(kern
.GetValueFromAddress(int(kq
), 'struct kqworkloop *'))
196 elif kq
.kq_state
& xnudefines
.KQ_WORKQ
:
197 return GetKqworkqSummary(kern
.GetValueFromAddress(int(kq
), 'struct kqworkq *'))
199 return GetKqfileSummary(kern
.GetValueFromAddress(int(kq
), 'struct kqfile *'))
201 @lldb_type_summary(['struct kqfile *'])
202 @header(GetKqueueSummary
.header
)
203 def GetKqfileSummary(kqf
):
204 kq
= kern
.GetValueFromAddress(int(kqf
), 'struct kqueue *')
205 state
= int(kq
.kq_state
)
206 return kqueue_summary_fmt
.format(
212 st_str
=xnudefines
.GetStateString(xnudefines
.kq_state_strings
, state
),
216 @lldb_command('showkqfile')
217 def ShowKqfile(cmd_args
=None):
218 """ Display information about a kqfile object.
220 usage: showkqfile <struct kqfile *>
222 if len(cmd_args
) < 1:
223 raise ArgumentError('missing struct kqfile * argument')
225 kqf
= kern
.GetValueFromAddress(cmd_args
[0], 'kqfile *')
227 print GetKqfileSummary
.header
228 print GetKqfileSummary(kqf
)
229 print GetKnoteSummary
.header
230 for kn
in IterateKqueueKnotes(kqf
.kqf_kqueue
):
231 print GetKnoteSummary(kn
)
232 for kn
in IterateTAILQ_HEAD(kqf
.kqf_suppressed
, 'kn_tqe'):
233 print GetKnoteSummary(kn
)
235 @lldb_type_summary(['struct kqworkq *'])
236 @header(GetKqueueSummary
.header
)
237 def GetKqworkqSummary(kqwq
):
238 """ Summarize workqueue kqueue information
241 kqwq - the kqworkq object
242 returns: str - summary of workqueue kqueue
244 return GetKqfileSummary(kern
.GetValueFromAddress(int(kqwq
), 'struct kqfile *'))
246 @lldb_command('showkqworkq')
247 def ShowKqworkq(cmd_args
=None):
248 """ Display summary and knote information about a kqworkq.
250 usage: showkqworkq <struct kqworkq *>
252 if len(cmd_args
) < 1:
253 raise ArgumentError('missing struct kqworkq * argument')
255 kqwq
= kern
.GetValueFromAddress(cmd_args
[0], 'struct kqworkq *')
256 kq
= kqwq
.kqwq_kqueue
257 print GetKqueueSummary
.header
258 print GetKqworkqSummary(kqwq
)
259 print GetKnoteSummary
.header
260 for kn
in IterateKqueueKnotes(kq
):
261 print GetKnoteSummary(kn
)
262 for i
in xrange(0, xnudefines
.KQWQ_NBUCKETS
):
263 for kn
in IterateTAILQ_HEAD(kq
.kq_queue
[i
], 'kn_tqe'):
264 print GetKnoteSummary(kn
)
266 @lldb_type_summary(['struct kqworkloop *'])
267 @header(GetKqueueSummary
.header
)
268 def GetKqworkloopSummary(kqwl
):
269 """ Summarize workloop kqueue information
272 kqwl - the kqworkloop object
273 returns: str - summary of workloop kqueue
275 state
= int(kqwl
.kqwl_kqueue
.kq_state
)
276 return kqueue_summary_fmt
.format(
279 wqs
=int(kqwl
.kqwl_kqueue
.kq_wqs
),
280 dyn_id
=kqwl
.kqwl_dynamicid
,
281 kqr_state
=xnudefines
.GetStateString(xnudefines
.kqrequest_state_strings
, kqwl
.kqwl_request
.kqr_state
),
282 st_str
=xnudefines
.GetStateString(xnudefines
.kq_state_strings
, state
),
283 servicer
=int(kqwl
.kqwl_request
.kqr_bound
.kqrb_thread
),
284 owner
=int(kqwl
.kqwl_owner
)
287 @lldb_command('showkqworkloop')
288 def ShowKqworkloop(cmd_args
=None):
289 """ Display information about a kqworkloop.
291 usage: showkqworkloop <struct kqworkloop *>
293 if len(cmd_args
) < 1:
294 raise ArgumentError('missing struct kqworkloop * argument')
296 kqwl
= kern
.GetValueFromAddress(cmd_args
[0], 'struct kqworkloop *')
298 print GetKqworkloopSummary
.header
299 print GetKqworkloopSummary(kqwl
)
301 print GetKqrequestSummary
.header
302 kqr
= kern
.GetValueFromAddress(unsigned(addressof(kqwl
.kqwl_request
)), 'struct kqrequest *')
303 print GetKqrequestSummary(kqr
)
305 print GetKnoteSummary
.header
306 for kn
in IterateKqueueKnotes(kqwl
.kqwl_kqueue
):
307 print GetKnoteSummary(kn
)
309 @lldb_command('showkqueue')
310 def ShowKqueue(cmd_args
=None):
311 """ Given a struct kqueue pointer, display the summary of the kqueue
313 usage: showkqueue <struct kqueue *>
316 raise ArgumentError('missing struct kqueue * argument')
318 kq
= kern
.GetValueFromAddress(cmd_args
[0], 'struct kqueue *')
319 if int(kq
.kq_state
) & xnudefines
.KQ_WORKQ
:
320 ShowKqworkq(cmd_args
=[str(int(kq
))])
321 elif int(kq
.kq_state
) & xnudefines
.KQ_WORKLOOP
:
322 ShowKqworkloop(cmd_args
=[str(int(kq
))])
324 print GetKqueueSummary
.header
325 print GetKqueueSummary(kq
)
326 print GetKnoteSummary
.header
327 for kn
in IterateKqueueKnotes(kq
):
328 print GetKnoteSummary(kn
)
330 @lldb_command('showprocworkqkqueue')
331 def ShowProcWorkqKqueue(cmd_args
=None):
332 """ Show the workqueue kqueue for a given process.
334 usage: showworkqkqueue <proc_t>
337 raise ArgumentError('missing struct proc * argument')
339 proc
= kern
.GetValueFromAddress(cmd_args
[0], 'proc_t')
340 ShowKqworkq(cmd_args
=[str(int(proc
.p_fd
.fd_wqkqueue
))])
342 @lldb_command('showprockqueues')
343 def ShowProcKqueues(cmd_args
=None):
344 """ Show the kqueues for a given process.
346 usage: showprockqueues <proc_t>
349 raise ArgumentError('missing struct proc * argument')
351 proc
= kern
.GetValueFromAddress(cmd_args
[0], 'proc_t')
353 print GetKqueueSummary
.header
354 for kq
in IterateProcKqueues(proc
):
355 print GetKqueueSummary(kq
)
357 @lldb_command('showprocknotes')
358 def ShowProcKnotes(cmd_args
=None):
359 """ Show the knotes for a given process.
361 usage: showprocknotes <proc_t>
365 raise ArgumentError('missing struct proc * argument')
367 proc
= kern
.GetValueFromAddress(cmd_args
[0], 'proc_t')
369 print GetKnoteSummary
.header
370 for kn
in IterateProcKnotes(proc
):
371 print GetKnoteSummary(kn
)
373 @lldb_command('showallkqueues')
374 def ShowAllKqueues(cmd_args
=[], cmd_options
={}):
375 """ Display a summary of all the kqueues in the system
377 usage: showallkqueues
379 print GetKqueueSummary
.header
380 for kq
in IterateAllKqueues():
381 print GetKqueueSummary(kq
)