]>
git.saurik.com Git - apple/xnu.git/blob - tools/lldbmacros/kevent.py
1fb875628748e23d261d26061f461639b3539c27
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(int(kn
.kn_kq_packed
), '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} {:s}'.format('kqrequest', 'thread', 'qos', 'ovr_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_thread: <#020x} {qos: <5s} {ovr_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 sa_qos
=xnudefines
.thread_qos_short_strings
[int(kqr
.kqr_stayactive_qos
)],
165 state_str
=xnudefines
.GetStateString(xnudefines
.kqrequest_state_strings
, kqr
.kqr_state
))
167 @lldb_command('showkqrequest')
168 def ShowKqrequest(cmd_args
=None):
169 """ Display information about a kqrequest object.
171 usage: showkqrequest <struct kqrequest *>
173 if len(cmd_args
) < 1:
174 raise ArgumentError('missing struct kqrequest * argument')
175 kqr
= kern
.GetValueFromAddress(cmd_args
[0], 'struct kqrequest *')
176 print GetKqrequestSummary
.header
177 print GetKqrequestSummary(kqr
)
178 print GetKnoteSummary
.header
179 for kn
in IterateTAILQ_HEAD(kqr
.kqr_suppressed
, 'kn_tqe'):
180 print GetKnoteSummary(kn
)
182 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}'
184 @lldb_type_summary(['struct kqueue *'])
185 @header('{: <20s} {: <20s} {: <20s} {: <20s} {: <20s} {: <6s} {: <20s} {: <30s} {: <10s}'.format('kqueue', 'process', 'dynamic_id', 'servicer', 'owner', '#evts', 'wqs', 'request', 'state'))
186 def GetKqueueSummary(kq
):
187 """ Summarize kqueue information
190 kq - the kqueue object
191 returns: str - summary of kqueue
193 if kq
.kq_state
& xnudefines
.KQ_WORKLOOP
:
194 return GetKqworkloopSummary(kern
.GetValueFromAddress(int(kq
), 'struct kqworkloop *'))
195 elif kq
.kq_state
& xnudefines
.KQ_WORKQ
:
196 return GetKqworkqSummary(kern
.GetValueFromAddress(int(kq
), 'struct kqworkq *'))
198 return GetKqfileSummary(kern
.GetValueFromAddress(int(kq
), 'struct kqfile *'))
200 @lldb_type_summary(['struct kqfile *'])
201 @header(GetKqueueSummary
.header
)
202 def GetKqfileSummary(kqf
):
203 kq
= kern
.GetValueFromAddress(int(kqf
), 'struct kqueue *')
204 state
= int(kq
.kq_state
)
205 return kqueue_summary_fmt
.format(
211 st_str
=xnudefines
.GetStateString(xnudefines
.kq_state_strings
, state
),
215 @lldb_command('showkqfile')
216 def ShowKqfile(cmd_args
=None):
217 """ Display information about a kqfile object.
219 usage: showkqfile <struct kqfile *>
221 if len(cmd_args
) < 1:
222 raise ArgumentError('missing struct kqfile * argument')
224 kqf
= kern
.GetValueFromAddress(cmd_args
[0], 'kqfile *')
226 print GetKqfileSummary
.header
227 print GetKqfileSummary(kqf
)
228 print GetKnoteSummary
.header
229 for kn
in IterateKqueueKnotes(kqf
.kqf_kqueue
):
230 print GetKnoteSummary(kn
)
231 for kn
in IterateTAILQ_HEAD(kqf
.kqf_suppressed
, 'kn_tqe'):
232 print GetKnoteSummary(kn
)
234 @lldb_type_summary(['struct kqworkq *'])
235 @header(GetKqueueSummary
.header
)
236 def GetKqworkqSummary(kqwq
):
237 """ Summarize workqueue kqueue information
240 kqwq - the kqworkq object
241 returns: str - summary of workqueue kqueue
243 return GetKqfileSummary(kern
.GetValueFromAddress(int(kqwq
), 'struct kqfile *'))
245 @lldb_command('showkqworkq')
246 def ShowKqworkq(cmd_args
=None):
247 """ Display summary and knote information about a kqworkq.
249 usage: showkqworkq <struct kqworkq *>
251 if len(cmd_args
) < 1:
252 raise ArgumentError('missing struct kqworkq * argument')
254 kqwq
= kern
.GetValueFromAddress(cmd_args
[0], 'struct kqworkq *')
255 kq
= kqwq
.kqwq_kqueue
256 print GetKqueueSummary
.header
257 print GetKqworkqSummary(kqwq
)
258 print GetKnoteSummary
.header
259 for kn
in IterateKqueueKnotes(kq
):
260 print GetKnoteSummary(kn
)
261 for i
in xrange(0, xnudefines
.KQWQ_NBUCKETS
):
262 for kn
in IterateTAILQ_HEAD(kq
.kq_queue
[i
], 'kn_tqe'):
263 print GetKnoteSummary(kn
)
265 @lldb_type_summary(['struct kqworkloop *'])
266 @header(GetKqueueSummary
.header
)
267 def GetKqworkloopSummary(kqwl
):
268 """ Summarize workloop kqueue information
271 kqwl - the kqworkloop object
272 returns: str - summary of workloop kqueue
274 state
= int(kqwl
.kqwl_kqueue
.kq_state
)
275 return kqueue_summary_fmt
.format(
278 wqs
=int(kqwl
.kqwl_kqueue
.kq_wqs
),
279 dyn_id
=kqwl
.kqwl_dynamicid
,
280 kqr_state
=xnudefines
.GetStateString(xnudefines
.kqrequest_state_strings
, kqwl
.kqwl_request
.kqr_state
),
281 st_str
=xnudefines
.GetStateString(xnudefines
.kq_state_strings
, state
),
282 servicer
=int(kqwl
.kqwl_request
.kqr_thread
),
283 owner
=int(kqwl
.kqwl_owner
)
286 @lldb_command('showkqworkloop')
287 def ShowKqworkloop(cmd_args
=None):
288 """ Display information about a kqworkloop.
290 usage: showkqworkloop <struct kqworkloop *>
292 if len(cmd_args
) < 1:
293 raise ArgumentError('missing struct kqworkloop * argument')
295 kqwl
= kern
.GetValueFromAddress(cmd_args
[0], 'struct kqworkloop *')
297 print GetKqworkloopSummary
.header
298 print GetKqworkloopSummary(kqwl
)
300 print GetKqrequestSummary
.header
301 kqr
= kern
.GetValueFromAddress(unsigned(addressof(kqwl
.kqwl_request
)), 'struct kqrequest *')
302 print GetKqrequestSummary(kqr
)
304 print GetKnoteSummary
.header
305 for kn
in IterateKqueueKnotes(kqwl
.kqwl_kqueue
):
306 print GetKnoteSummary(kn
)
308 @lldb_command('showkqueue')
309 def ShowKqueue(cmd_args
=None):
310 """ Given a struct kqueue pointer, display the summary of the kqueue
312 usage: showkqueue <struct kqueue *>
315 raise ArgumentError('missing struct kqueue * argument')
317 kq
= kern
.GetValueFromAddress(cmd_args
[0], 'struct kqueue *')
318 if int(kq
.kq_state
) & xnudefines
.KQ_WORKQ
:
319 ShowKqworkq(cmd_args
=[str(int(kq
))])
320 elif int(kq
.kq_state
) & xnudefines
.KQ_WORKLOOP
:
321 ShowKqworkloop(cmd_args
=[str(int(kq
))])
323 print GetKqueueSummary
.header
324 print GetKqueueSummary(kq
)
325 print GetKnoteSummary
.header
326 for kn
in IterateKqueueKnotes(kq
):
327 print GetKnoteSummary(kn
)
329 @lldb_command('showprocworkqkqueue')
330 def ShowProcWorkqKqueue(cmd_args
=None):
331 """ Show the workqueue kqueue for a given process.
333 usage: showworkqkqueue <proc_t>
336 raise ArgumentError('missing struct proc * argument')
338 proc
= kern
.GetValueFromAddress(cmd_args
[0], 'proc_t')
339 ShowKqworkq(cmd_args
=[str(int(proc
.p_fd
.fd_wqkqueue
))])
341 @lldb_command('showprockqueues')
342 def ShowProcKqueues(cmd_args
=None):
343 """ Show the kqueues for a given process.
345 usage: showprockqueues <proc_t>
348 raise ArgumentError('missing struct proc * argument')
350 proc
= kern
.GetValueFromAddress(cmd_args
[0], 'proc_t')
352 print GetKqueueSummary
.header
353 for kq
in IterateProcKqueues(proc
):
354 print GetKqueueSummary(kq
)
356 @lldb_command('showprocknotes')
357 def ShowProcKnotes(cmd_args
=None):
358 """ Show the knotes for a given process.
360 usage: showprocknotes <proc_t>
364 raise ArgumentError('missing struct proc * argument')
366 proc
= kern
.GetValueFromAddress(cmd_args
[0], 'proc_t')
368 print GetKnoteSummary
.header
369 for kn
in IterateProcKnotes(proc
):
370 print GetKnoteSummary(kn
)
372 @lldb_command('showallkqueues')
373 def ShowAllKqueues(cmd_args
=[], cmd_options
={}):
374 """ Display a summary of all the kqueues in the system
376 usage: showallkqueues
378 print GetKqueueSummary
.header
379 for kq
in IterateAllKqueues():
380 print GetKqueueSummary(kq
)