]> git.saurik.com Git - apple/xnu.git/blame - osfmk/.gdbinit
xnu-123.5.tar.gz
[apple/xnu.git] / osfmk / .gdbinit
CommitLineData
1c79356b
A
1#
2# Kernel gdb macros
3#
4# These gdb macros should be useful during kernel development in
5# determining what's going on in the kernel.
6#
7# All the convenience variables used by these macros begin with $kgm_
8
9set $kgm_vers = 2
10
11echo Loading Kernel GDB Macros package. Type "help kgm" for more info.\n
12
13define kgm
14printf "These are the kernel gdb macros version %d. ", $kgm_vers
15echo Type "help kgm" for more info.\n
16end
17
18document kgm
19| These are the kernel gdb macros. These gdb macros are intended to be
20| used when debugging a remote kernel via the kdp protocol. Typically, you
21| would connect to your remote target like so:
22| (gdb) target remote-kdp
23| (gdb) attach <name-of-remote-host>
24|
25| The following macros are available in this package:
26|
27| showalltasks Display a summary listing of tasks
28| showallacts Display a summary listing of all activations
29| showallstacks Display the kernel stacks for all activations
30| showallvm Display a summary listing of all the vm maps
31| showallvme Display a summary listing of all the vm map entries
32| showallipc Display a summary listing of all the ipc spaces
33| showallrights Display a summary listing of all the ipc rights
34| showallkmods Display a summary listing of all the kernel modules
35|
36| showtask Display status of the specified task
37| showtaskacts Display the status of all activations in the task
38| showtaskstacks Display all kernel stacks for all activations in the task
39| showtaskvm Display status of the specified task's vm_map
40| showtaskvme Display a summary list of the task's vm_map entries
41| showtaskipc Display status of the specified task's ipc space
42| showtaskrights Display a summary list of the task's ipc space entries
43|
44| showact Display status of the specified thread activation
45| showactstack Display the kernel stack for the specified activation
46|
47| showmap Display the status of the specified vm_map
48| showmapvme Display a summary list of the specified vm_map's entries
49|
50| showipc Display the status of the specified ipc space
51| showrights Display a summary list of all the rights in an ipc space
52|
53| showpid Display the status of the process identified by pid
54| showproc Display the status of the process identified by a proc pointer
55|
56| showkmod Display information about a kernel module
57| showkmodaddr Given an address, display the kernel module and offset
58|
59| zprint Display zone information
60|
61| Type "help <macro>" for more specific help on a particular macro.
62| Type "show user <macro>" to see what the macro is really doing.
63end
64
65
66define showkmodheader
67 printf "kmod address size "
68 printf "id refs version name\n"
69end
70
71define showkmodint
72 set $kgm_kmodp = (struct kmod_info *)$arg0
73 printf "0x%08x ", $arg0
74 printf "0x%08x ", $kgm_kmodp->address
75 printf "0x%08x ", $kgm_kmodp->size
76 printf "%3d ", $kgm_kmodp->id
77 printf "%5d ", $kgm_kmodp->reference_count
78 printf "%10s ", &$kgm_kmodp->version
79 printf "%s\n", &$kgm_kmodp->name
80end
81
82set $kgm_kmodmin = 0xffffffff
83set $kgm_fkmodmin = 0x00000000
84set $kgm_kmodmax = 0x00000000
85set $kgm_fkmodmax = 0xffffffff
86set $kgm_pkmod = 0
87set $kgm_pkmodst = 0
88set $kgm_pkmoden = 0
89define showkmodaddr
90 printf "0x%x" , $arg0
91 if ((unsigned int)$arg0 >= (unsigned int)$kgm_pkmodst) && ((unsigned int)$arg0 <= (unsigned int)$kgm_pkmoden)
92 set $kgm_off = ((unsigned int)$arg0 - (unsigned int)$kgm_pkmodst)
93 printf " <%s + 0x%x>", $kgm_pkmod->name, $kgm_off
94 else
95 if ((unsigned int)$arg0 <= (unsigned int)$kgm_fkmodmax) && ((unsigned int)$arg0 >= (unsigned int)$kgm_fkmodmin)
96 set $kgm_kmodp = (struct kmod_info *)kmod
97 while $kgm_kmodp
98 set $kgm_kmod = *$kgm_kmodp
99 if $kgm_kmod.address && ($kgm_kmod.address < $kgm_kmodmin)
100 set $kgm_kmodmin = $kgm_kmod.address
101 end
102 if ($kgm_kmod.address + $kgm_kmod.size) > $kgm_kmodmax
103 set $kgm_kmodmax = $kgm_kmod.address
104 end
105 set $kgm_off = ((unsigned int)$arg0 - (unsigned int)$kgm_kmod.address)
106 if ($kgm_kmod.address <= $arg0) && ($kgm_off <= $kgm_kmod.size)
107 printf " <%s + 0x%x>", $kgm_kmodp->name, $kgm_off
108 set $kgm_pkmod = $kgm_kmodp
109 set $kgm_pkmodst = $kgm_kmod.address
110 set $kgm_pkmoden = $kgm_pkmodst + $kgm_kmod.size
111 set $kgm_kmodp = 0
112 else
113 set $kgm_kmodp = $kgm_kmod.next
114 end
115 end
116 if !$kgm_pkmod
117 set $kgm_fkmodmin = $kgm_kmodmin
118 set $kgm_fkmodmax = $kgm_kmodmax
119 end
120 end
121 end
122end
123document showkmodaddr
124| Given an address, print the offset and name for the kmod containing it
125| The following is the syntax:
126| (gdb) showkmodaddr <addr>
127end
128
129define showkmod
130 showkmodheader
131 showkmodint $arg0
132end
133document showkmod
134| Routine to print info about a kernel module
135| The following is the syntax:
136| (gdb) showkmod <kmod>
137end
138
139define showallkmods
140 showkmodheader
141 set $kgm_kmodp = (struct kmod_info *)kmod
142 while $kgm_kmodp
143 showkmodint $kgm_kmodp
144 set $kgm_kmodp = $kgm_kmodp->next
145 end
146end
147document showallkmods
148| Routine to print a summary listing of all the kernel modules
149| The following is the syntax:
150| (gdb) showallkmods
151end
152
153define showactheader
154 printf " activation "
155 printf "thread pri state wait_queue wait_event\n"
156end
157
158
159define showactint
160 printf " 0x%08x ", $arg0
161 set $kgm_actp = *(Thread_Activation *)$arg0
162 if $kgm_actp.thread
163 set $kgm_thread = *$kgm_actp.thread
164 printf "0x%08x ", $kgm_actp.thread
165 printf "%3d ", $kgm_thread.sched_pri
166 set $kgm_state = $kgm_thread.state
167 if $kgm_state & 0x80
168 printf "I"
169 end
170 if $kgm_state & 0x40
171 printf "P"
172 end
173 if $kgm_state & 0x20
174 printf "A"
175 end
176 if $kgm_state & 0x10
177 printf "H"
178 end
179 if $kgm_state & 0x08
180 printf "U"
181 end
182 if $kgm_state & 0x04
183 printf "R"
184 end
185 if $kgm_state & 0x02
186 printf "S"
187 end
188 if $kgm_state & 0x01
189 printf "W\t"
190 printf "0x%08x ", $kgm_thread.wait_queue
191 output /a $kgm_thread.wait_event
192 end
193 if $arg1 != 0
194 if ($kgm_thread.kernel_stack != 0)
195 if ($kgm_thread.stack_privilege != 0)
196 printf "\n\t\tstack_privilege=0x%08x", $kgm_thread.stack_privilege
197 end
198 printf "\n\t\tkernel_stack=0x%08x", $kgm_thread.kernel_stack
199 set $mysp = $kgm_actp->mact.pcb.ss.r1
200 set $prevsp = 0
201 printf "\n\t\tstacktop=0x%08x", $mysp
202 while ($mysp != 0) && (($mysp & 0xf) == 0) && ($mysp < 0xb0000000) && ($mysp > $prevsp)
203 printf "\n\t\t0x%08x ", $mysp
204 set $kgm_return = *($mysp + 8)
205 if ($kgm_return > end)
206 showkmodaddr $kgm_return
207 else
208 output /a * ($mysp + 8)
209 end
210 set $prevsp = $mysp
211 set $mysp = * $mysp
212 end
213 printf "\n\t\tstackbottom=0x%08x", $prevsp
214 else
215 printf "\n\t\t\tcontinuation="
216 output /a $kgm_thread.continuation
217 end
218 printf "\n"
219 else
220 printf "\n"
221 end
222 end
223end
224
225define showact
226 showactheader
227 showactint $arg0 0
228end
229document showact
230| Routine to print out the state of a specific thread activation.
231| The following is the syntax:
232| (gdb) showact <activation>
233end
234
235
236define showactstack
237 showactheader
238 showactint $arg0 1
239end
240document showactstack
241| Routine to print out the stack of a specific thread activation.
242| The following is the syntax:
243| (gdb) showactstack <activation>
244end
245
246
247define showallacts
248 set $kgm_head_taskp = &default_pset.tasks
249 set $kgm_taskp = (Task *)($kgm_head_taskp->next)
250 while $kgm_taskp != $kgm_head_taskp
251 showtaskheader
252 showtaskint $kgm_taskp
253 showactheader
254 set $kgm_head_actp = &($kgm_taskp->thr_acts)
255 set $kgm_actp = (Thread_Activation *)($kgm_taskp->thr_acts.next)
256 while $kgm_actp != $kgm_head_actp
257 showactint $kgm_actp 0
258 set $kgm_actp = (Thread_Activation *)($kgm_actp->thr_acts.next)
259 end
260 printf "\n"
261 set $kgm_taskp = (Task *)($kgm_taskp->pset_tasks.next)
262 end
263end
264document showallacts
265| Routine to print out a summary listing of all the thread activations.
266| The following is the syntax:
267| (gdb) showallacts
268end
269
270
271define showallstacks
272 set $kgm_head_taskp = &default_pset.tasks
273 set $kgm_taskp = (Task *)($kgm_head_taskp->next)
274 while $kgm_taskp != $kgm_head_taskp
275 showtaskheader
276 showtaskint $kgm_taskp
277 set $kgm_head_actp = &($kgm_taskp->thr_acts)
278 set $kgm_actp = (Thread_Activation *)($kgm_taskp->thr_acts.next)
279 while $kgm_actp != $kgm_head_actp
280 showactheader
281 showactint $kgm_actp 1
282 set $kgm_actp = (Thread_Activation *)($kgm_actp->thr_acts.next)
283 end
284 printf "\n"
285 set $kgm_taskp = (Task *)($kgm_taskp->pset_tasks.next)
286 end
287end
288document showallstacks
289| Routine to print out a summary listing of all the thread kernel stacks.
290| The following is the syntax:
291| (gdb) showallstacks
292end
293
294define showwaitqmembercount
295 set $kgm_waitqsubp = (wait_queue_sub_t)$arg0
296 set $kgm_sublinksp = &($kgm_waitqsubp->wqs_sublinks)
297 set $kgm_wql = (wait_queue_link_t)$kgm_sublinksp->next
298 set $kgm_count = 0
299 while ( (queue_entry_t)$kgm_wql != (queue_entry_t)$kgm_sublinksp)
300 set $kgm_waitqp = $kgm_wql->wql_element->wqe_queue
301 if !$kgm_found
302 showwaitqmemberheader
303 set $kgm_found = 1
304 end
305 showwaitqmemberint $kgm_waitqp
306 end
307end
308
309
310define showwaitqmemberint
311 set $kgm_waitqp = (wait_queue_t)$arg0
312 printf " 0x%08x ", $kgm_waitqp
313 printf "0x%08x ", $kgm_waitqp->wq_interlock
314 if ($kgm_waitqp->wq_fifo)
315 printf "Fifo"
316 else
317 printf "Prio"
318 end
319 if ($kgm_waitqp->wq_issub)
320 printf "S"
321 else
322 printf " "
323 end
324 printf " "
325 showwaitqwaitercount $kgm_waitqp
326 showwaitqmembercount $kgm_waitqp
327 printf "\n"
328end
329
330
331define showwaitqmembers
332 set $kgm_waitqsubp = (wait_queue_sub_t)$arg0
333 set $kgm_sublinksp = &($kgm_waitqsubp->wqs_sublinks)
334 set $kgm_wql = (wait_queue_link_t)$kgm_sublinksp->next
335 set $kgm_found = 0
336 while ( (queue_entry_t)$kgm_wql != (queue_entry_t)$kgm_sublinksp)
337 set $kgm_waitqp = $kgm_wql->wql_element->wqe_queue
338 if !$kgm_found
339 showwaitqmemberheader
340 set $kgm_found = 1
341 end
342 showwaitqmemberint $kgm_waitqp
343 end
344end
345
346define showwaitq
347 set $kgm_waitq = (wait_queue_t)$arg0
348 showwaitqheader
349 showwaitqwaiters
350 if ($kgm_waitq->wq_issub)
351 showwaitqmembers
352 end
353end
354
355define showmapheader
356 printf "vm_map pmap vm_size "
357 printf "#ents rpage hint first_free\n"
358end
359
360define showvmeheader
361 printf " entry start "
362 printf "prot #page object offset\n"
363end
364
365define showvmint
366 set $kgm_mapp = (vm_map_t)$arg0
367 set $kgm_map = *$kgm_mapp
368 printf "0x%08x ", $arg0
369 printf "0x%08x ", $kgm_map.pmap
370 printf "0x%08x ", $kgm_map.size
371 printf "%3d ", $kgm_map.hdr.nentries
372 printf "%5d ", $kgm_map.pmap->stats.resident_count
373 printf "0x%08x ", $kgm_map.hint
374 printf "0x%08x\n", $kgm_map.first_free
375 if $arg1 != 0
376 showvmeheader
377 set $kgm_head_vmep = &($kgm_mapp->hdr.links)
378 set $kgm_vmep = $kgm_map.hdr.links.next
379 while (($kgm_vmep != 0) && ($kgm_vmep != $kgm_head_vmep))
380 set $kgm_vme = *$kgm_vmep
381 printf " 0x%08x ", $kgm_vmep
382 printf "0x%08x ", $kgm_vme.links.start
383 printf "%1x", $kgm_vme.protection
384 printf "%1x", $kgm_vme.max_protection
385 if $kgm_vme.inheritance == 0x0
386 printf "S"
387 end
388 if $kgm_vme.inheritance == 0x1
389 printf "C"
390 end
391 if $kgm_vme.inheritance == 0x2
392 printf "-"
393 end
394 if $kgm_vme.inheritance == 0x3
395 printf "D"
396 end
397 if $kgm_vme.is_sub_map
398 printf "s "
399 else
400 if $kgm_vme.needs_copy
401 printf "n "
402 else
403 printf " "
404 end
405 end
406 printf "%5d ",($kgm_vme.links.end - $kgm_vme.links.start) >> 12
407 printf "0x%08x ", $kgm_vme.object.vm_object
408 printf "0x%08x\n", $kgm_vme.offset
409 set $kgm_vmep = $kgm_vme.links.next
410 end
411 end
412 printf "\n"
413end
414
415
416define showmapvme
417 showmapheader
418 showvmint $arg0 1
419end
420document showmapvme
421| Routine to print out a summary listing of all the entries in a vm_map
422| The following is the syntax:
423| (gdb) showmapvme <vm_map>
424end
425
426
427define showmap
428 showmapheader
429 showvmint $arg0 0
430end
431document showmap
432| Routine to print out a summary description of a vm_map
433| The following is the syntax:
434| (gdb) showmap <vm_map>
435end
436
437define showallvm
438 set $kgm_head_taskp = &default_pset.tasks
439 set $kgm_taskp = (Task *)($kgm_head_taskp->next)
440 while $kgm_taskp != $kgm_head_taskp
441 showtaskheader
442 showmapheader
443 showtaskint $kgm_taskp
444 showvmint $kgm_taskp->map 0
445 set $kgm_taskp = (Task *)($kgm_taskp->pset_tasks.next)
446 end
447end
448document showallvm
449| Routine to print a summary listing of all the vm maps
450| The following is the syntax:
451| (gdb) showallvm
452end
453
454
455define showallvme
456 set $kgm_head_taskp = &default_pset.tasks
457 set $kgm_taskp = (Task *)($kgm_head_taskp->next)
458 while $kgm_taskp != $kgm_head_taskp
459 showtaskheader
460 showmapheader
461 showtaskint $kgm_taskp
462 showvmint $kgm_taskp->map 1
463 set $kgm_taskp = (Task *)($kgm_taskp->pset_tasks.next)
464 end
465end
466document showallvme
467| Routine to print a summary listing of all the vm map entries
468| The following is the syntax:
469| (gdb) showallvme
470end
471
472
473define showipcheader
474 printf "ipc_space is_table table_next "
475 printf "flags tsize splaytree splaybase\n"
476end
477
478define showipceheader
479 printf " name object "
480 printf "rite urefs destname destination\n"
481end
482
483define showipceint
484 set $kgm_ie = *(ipc_entry_t)$arg0
485 printf " 0x%08x ", $arg1
486 printf "0x%08x ", $kgm_ie.ie_object
487 if $kgm_ie.ie_bits & 0x00100000
488 printf "Dead "
489 printf "%5d\n", $kgm_ie.ie_bits & 0xffff
490 else
491 if $kgm_ie.ie_bits & 0x00080000
492 printf "SET "
493 printf "%5d\n", $kgm_ie.ie_bits & 0xffff
494 else
495 if $kgm_ie.ie_bits & 0x00010000
496 if $kgm_ie.ie_bits & 0x00020000
497 printf " SR"
498 else
499 printf " S"
500 end
501 else
502 if $kgm_ie.ie_bits & 0x00020000
503 printf " R"
504 end
505 end
506 if $kgm_ie.ie_bits & 0x00040000
507 printf " O"
508 end
509 if $kgm_ie.index.request
510 printf "n"
511 else
512 printf " "
513 end
514 if $kgm_ie.ie_bits & 0x00800000
515 printf "c"
516 else
517 printf " "
518 end
519 printf "%5d ", $kgm_ie.ie_bits & 0xffff
520 showportdest $kgm_ie.ie_object
521 end
522 end
523end
524
525define showipcint
526 set $kgm_isp = (ipc_space_t)$arg0
527 set $kgm_is = *$kgm_isp
528 printf "0x%08x ", $arg0
529 printf "0x%08x ", $kgm_is.is_table
530 printf "0x%08x ", $kgm_is.is_table_next
531 if $kgm_is.is_growing != 0
532 printf "G"
533 else
534 printf " "
535 end
536 if $kgm_is.is_fast != 0
537 printf "F"
538 else
539 printf " "
540 end
541 if $kgm_is.is_active != 0
542 printf "A "
543 else
544 printf " "
545 end
546 printf "%5d ", $kgm_is.is_table_size
547 printf "0x%08x ", $kgm_is.is_tree_total
548 printf "0x%08x\n", &$kgm_isp->is_tree
549 if $arg1 != 0
550 showipceheader
551 set $kgm_iindex = 0
552 set $kgm_iep = $kgm_is.is_table
553 set $kgm_destspacep = (ipc_space_t)0
554 while ( $kgm_iindex < $kgm_is.is_table_size )
555 set $kgm_ie = *$kgm_iep
556 if $kgm_ie.ie_bits & 0x001f0000
557 set $kgm_name = (($kgm_iindex << 8)|($kgm_ie.ie_bits >> 24))
558 showipceint $kgm_iep $kgm_name
559 end
560 set $kgm_iindex = $kgm_iindex + 1
561 set $kgm_iep = &($kgm_is.is_table[$kgm_iindex])
562 end
563 if $kgm_is.is_tree_total
564 printf "Still need to write tree traversal\n"
565 end
566 end
567 printf "\n"
568end
569
570
571define showipc
572 set $kgm_isp = (ipc_space_t)$arg0
573 showipcheader
574 showipcint $kgm_isp 0
575end
576document showipc
577| Routine to print the status of the specified ipc space
578| The following is the syntax:
579| (gdb) showipc <ipc_space>
580end
581
582define showrights
583 set $kgm_isp = (ipc_space_t)$arg0
584 showipcheader
585 showipcint $kgm_isp 1
586end
587document showrights
588| Routine to print a summary list of all the rights in a specified ipc space
589| The following is the syntax:
590| (gdb) showrights <ipc_space>
591end
592
593
594define showtaskipc
595 set $kgm_taskp = (task_t)$arg0
596 showtaskheader
597 showipcheader
598 showtaskint $kgm_taskp
599 showipcint $kgm_taskp->itk_space 0
600end
601document showtaskipc
602| Routine to print the status of the ipc space for a task
603| The following is the syntax:
604| (gdb) showtaskipc <task>
605end
606
607
608define showtaskrights
609 set $kgm_taskp = (task_t)$arg0
610 showtaskheader
611 showipcheader
612 showtaskint $kgm_taskp
613 showipcint $kgm_taskp->itk_space 1
614end
615document showtaskrights
616| Routine to print a summary listing of all the ipc rights for a task
617| The following is the syntax:
618| (gdb) showtaskrights <task>
619end
620
621define showallipc
622 set $kgm_head_taskp = &default_pset.tasks
623 set $kgm_taskp = (Task *)($kgm_head_taskp->next)
624 while $kgm_taskp != $kgm_head_taskp
625 showtaskheader
626 showipcheader
627 showtaskint $kgm_taskp
628 showipcint $kgm_taskp->itk_space 0
629 set $kgm_taskp = (Task *)($kgm_taskp->pset_tasks.next)
630 end
631end
632document showallipc
633| Routine to print a summary listing of all the ipc spaces
634| The following is the syntax:
635| (gdb) showallipc
636end
637
638
639define showallrights
640 set $kgm_head_taskp = &default_pset.tasks
641 set $kgm_taskp = (Task *)($kgm_head_taskp->next)
642 while $kgm_taskp != $kgm_head_taskp
643 showtaskheader
644 showipcheader
645 showtaskint $kgm_taskp
646 showipcint $kgm_taskp->itk_space 1
647 set $kgm_taskp = (Task *)($kgm_taskp->pset_tasks.next)
648 end
649end
650document showallrights
651| Routine to print a summary listing of all the ipc rights
652| The following is the syntax:
653| (gdb) showallrights
654end
655
656
657define showtaskvm
658 set $kgm_taskp = (task_t)$arg0
659 showtaskheader
660 showmapheader
661 showtaskint $kgm_taskp
662 showvmint $kgm_taskp->map 0
663end
664document showtaskvm
665| Routine to print out a summary description of a task's vm_map
666| The following is the syntax:
667| (gdb) showtaskvm <task>
668end
669
670define showtaskvme
671 set $kgm_taskp = (task_t)$arg0
672 showtaskheader
673 showmapheader
674 showtaskint $kgm_taskp
675 showvmint $kgm_taskp->map 1
676end
677document showtaskvme
678| Routine to print out a summary listing of a task's vm_map_entries
679| The following is the syntax:
680| (gdb) showtaskvme <task>
681end
682
683
684define showtaskheader
685 printf "task vm_map ipc_space #acts "
686 showprocheader
687end
688
689
690define showtaskint
691 set $kgm_task = *(Task *)$arg0
692 printf "0x%08x ", $arg0
693 printf "0x%08x ", $kgm_task.map
694 printf "0x%08x ", $kgm_task.itk_space
695 printf "%3d ", $kgm_task.thr_act_count
696 showprocint $kgm_task.bsd_info
697end
698
699define showtask
700 showtaskheader
701 showtaskint $arg0
702end
703document showtask
704| Routine to print out info about a task.
705| The following is the syntax:
706| (gdb) showtask <task>
707end
708
709
710define showtaskacts
711 showtaskheader
712 set $kgm_taskp = (Task *)$arg0
713 showtaskint $kgm_taskp
714 showactheader
715 set $kgm_head_actp = &($kgm_taskp->thr_acts)
716 set $kgm_actp = (Thread_Activation *)($kgm_taskp->thr_acts.next)
717 while $kgm_actp != $kgm_head_actp
718 showactint $kgm_actp 0
719 set $kgm_actp = (Thread_Activation *)($kgm_actp->thr_acts.next)
720 end
721end
722document showtaskacts
723| Routine to print a summary listing of the activations in a task
724| The following is the syntax:
725| (gdb) showtaskacts <task>
726end
727
728
729define showtaskstacks
730 showtaskheader
731 set $kgm_taskp = (Task *)$arg0
732 showtaskint $kgm_taskp
733 set $kgm_head_actp = &($kgm_taskp->thr_acts)
734 set $kgm_actp = (Thread_Activation *)($kgm_taskp->thr_acts.next)
735 while $kgm_actp != $kgm_head_actp
736 showactheader
737 showactint $kgm_actp 1
738 set $kgm_actp = (Thread_Activation *)($kgm_actp->thr_acts.next)
739 end
740end
741document showtaskstacks
742| Routine to print a summary listing of the activations in a task and their stacks
743| The following is the syntax:
744| (gdb) showtaskstacks <task>
745end
746
747
748define showalltasks
749 showtaskheader
750 set $kgm_head_taskp = &default_pset.tasks
751 set $kgm_taskp = (Task *)($kgm_head_taskp->next)
752 while $kgm_taskp != $kgm_head_taskp
753 showtaskint $kgm_taskp
754 set $kgm_taskp = (Task *)($kgm_taskp->pset_tasks.next)
755 end
756end
757document showalltasks
758| Routine to print a summary listing of all the tasks
759| The following is the syntax:
760| (gdb) showalltasks
761end
762
763
764define showprocheader
765 printf " pid proc command\n"
766end
767
768define showprocint
769 set $kgm_procp = (struct proc *)$arg0
770 if $kgm_procp != 0
771 printf "%5d ", $kgm_procp->p_pid
772 printf "0x%08x ", $kgm_procp
773 printf "%s\n", $kgm_procp->p_comm
774 else
775 printf " *0* 0x00000000 --\n"
776 end
777end
778
779define showpid
780 showtaskheader
781 set $kgm_head_taskp = &default_pset.tasks
782 set $kgm_taskp = (Task *)($kgm_head_taskp->next)
783 while $kgm_taskp != $kgm_head_taskp
784 set $kgm_procp = (struct proc *)$kgm_taskp->bsd_info
785 if (($kgm_procp != 0) && ($kgm_procp->p_pid == $arg0))
786 showtaskint $kgm_taskp
787 set $kgm_taskp = $kgm_head_taskp
788 else
789 set $kgm_taskp = (Task *)($kgm_taskp->pset_tasks.next)
790 end
791 end
792end
793document showpid
794| Routine to print a single process by pid
795| The following is the syntax:
796| (gdb) showpid <pid>
797end
798
799define showproc
800 showtaskheader
801 set $kgm_procp = (struct proc *)$arg0
802 showtaskint $kgm_procp->task $arg1 $arg2
803end
804
805
806define kdb
807 set switch_debugger=1
808 continue
809end
810document kdb
811| kdb - Switch to the inline kernel debugger
812|
813| usage: kdb
814|
815| The kdb macro allows you to invoke the inline kernel debugger.
816end
817
818define showpsetheader
819 printf "portset waitqueue recvname "
820 printf "flags refs recvname process\n"
821end
822
823define showportheader
824 printf "port mqueue recvname "
825 printf "flags refs recvname process\n"
826end
827
828define showportmemberheader
829 printf " port recvname "
830 printf "flags refs mqueue msgcount\n"
831end
832
833define showkmsgheader
834 printf " kmsg size "
835 printf "disp msgid remote-port local-port\n"
836end
837
838define showkmsgint
839 printf " 0x%08x ", $arg0
840 set $kgm_kmsgh = ((ipc_kmsg_t)$arg0)->ikm_header
841 printf "0x%08x ", $kgm_kmsgh.msgh_size
842 if (($kgm_kmsgh.msgh_bits & 0xff) == 19)
843 printf "rC"
844 else
845 printf "rM"
846 end
847 if (($kgm_kmsgh.msgh_bits & 0xff00) == (19 < 8))
848 printf "lC"
849 else
850 printf "lM"
851 end
852 if ($kgm_kmsgh.msgh_bits & 0xf0000000)
853 printf "c"
854 else
855 printf "s"
856 end
857 printf "%5d ", $kgm_kmsgh.msgh_msgid
858 printf "0x%08x ", $kgm_kmsgh.msgh_remote_port
859 printf "0x%08x\n", $kgm_kmsgh.msgh_local_port
860end
861
862
863
864define showkobject
865 set $kgm_portp = (ipc_port_t)$arg0
866 printf "0x%08x kobject(", $kgm_portp->ip_kobject
867 set $kgm_kotype = ($kgm_portp->ip_object.io_bits & 0x00000fff)
868 if ($kgm_kotype == 1)
869 printf "THREAD"
870 end
871 if ($kgm_kotype == 2)
872 printf "TASK"
873 end
874 if ($kgm_kotype == 3)
875 printf "HOST"
876 end
877 if ($kgm_kotype == 4)
878 printf "HOST_PRIV"
879 end
880 if ($kgm_kotype == 5)
881 printf "PROCESSOR"
882 end
883 if ($kgm_kotype == 6)
884 printf "PSET"
885 end
886 if ($kgm_kotype == 7)
887 printf "PSET_NAME"
888 end
889 if ($kgm_kotype == 8)
890 printf "TIMER"
891 end
892 if ($kgm_kotype == 9)
893 printf "PAGER_REQ"
894 end
895 if ($kgm_kotype == 10)
896 printf "DEVICE"
897 end
898 if ($kgm_kotype == 11)
899 printf "XMM_OBJECT"
900 end
901 if ($kgm_kotype == 12)
902 printf "XMM_PAGER"
903 end
904 if ($kgm_kotype == 13)
905 printf "XMM_KERNEL"
906 end
907 if ($kgm_kotype == 14)
908 printf "XMM_REPLY"
909 end
910 if ($kgm_kotype == 15)
911 printf "NOTDEF 15"
912 end
913 if ($kgm_kotype == 16)
914 printf "NOTDEF 16"
915 end
916 if ($kgm_kotype == 17)
917 printf "HOST_SEC"
918 end
919 if ($kgm_kotype == 18)
920 printf "LEDGER"
921 end
922 if ($kgm_kotype == 19)
923 printf "MASTER_DEV"
924 end
925 if ($kgm_kotype == 20)
926 printf "ACTIVATION"
927 end
928 if ($kgm_kotype == 21)
929 printf "SUBSYSTEM"
930 end
931 if ($kgm_kotype == 22)
932 printf "IO_DONE_QUE"
933 end
934 if ($kgm_kotype == 23)
935 printf "SEMAPHORE"
936 end
937 if ($kgm_kotype == 24)
938 printf "LOCK_SET"
939 end
940 if ($kgm_kotype == 25)
941 printf "CLOCK"
942 end
943 if ($kgm_kotype == 26)
944 printf "CLOCK_CTRL"
945 end
946 if ($kgm_kotype == 27)
947 printf "IOKIT_SPARE"
948 end
949 if ($kgm_kotype == 28)
950 printf "NAMED_MEM"
951 end
952 if ($kgm_kotype == 29)
953 printf "IOKIT_CON"
954 end
955 if ($kgm_kotype == 30)
956 printf "IOKIT_OBJ"
957 end
958 if ($kgm_kotype == 31)
959 printf "UPL"
960 end
961 printf ")\n"
962end
963
964define showportdestproc
965 set $kgm_portp = (ipc_port_t)$arg0
966 set $kgm_spacep = $kgm_portp->data.receiver
967# check against the previous cached value - this is slow
968 if ($kgm_spacep != $kgm_destspacep)
969 set $kgm_destprocp = (struct proc *)0
970 set $kgm_head_taskp = &default_pset.tasks
971 set $kgm_taskp = (Task *)($kgm_head_taskp->next)
972 while (($kgm_destprocp == 0) && ($kgm_taskp != $kgm_head_taskp))
973 set $kgm_destspacep = $kgm_taskp->itk_space
974 if ($kgm_destspacep == $kgm_spacep)
975 set $kgm_destprocp = (struct proc *)$kgm_taskp->bsd_info
976 else
977 set $kgm_taskp = (Task *)($kgm_taskp->pset_tasks.next)
978 end
979 end
980 end
981 if $kgm_destprocp != 0
982 printf "%s(%d)\n", $kgm_destprocp->p_comm, $kgm_destprocp->p_pid
983 else
984 printf "task 0x%08x\n", $kgm_taskp
985 end
986end
987
988define showportdest
989 set $kgm_portp = (ipc_port_t)$arg0
990 set $kgm_spacep = $kgm_portp->data.receiver
991 if ($kgm_spacep == ipc_space_kernel)
992 showkobject $kgm_portp
993 else
994 if ($kgm_portp->ip_object.io_bits & 0x80000000)
995 printf "0x%08x ", $kgm_portp->ip_object.io_receiver_name
996 showportdestproc $kgm_portp
997 else
998 printf "0x%08x inactive-port\n", $kgm_portp
999 end
1000 end
1001end
1002
1003define showportmember
1004 printf " 0x%08x ", $arg0
1005 set $kgm_portp = (ipc_port_t)$arg0
1006 printf "0x%08x ", $kgm_portp->ip_object.io_receiver_name
1007 if ($kgm_portp->ip_object.io_bits & 0x80000000)
1008 printf "A"
1009 else
1010 printf " "
1011 end
1012 if ($kgm_portp->ip_object.io_bits & 0x7fff0000)
1013 printf "Set "
1014 else
1015 printf "Port"
1016 end
1017 printf "%5d ", $kgm_portp->ip_object.io_references
1018 printf "0x%08x ", &($kgm_portp->ip_messages)
1019 printf "0x%08x\n", $kgm_portp->ip_messages.data.port.msgcount
1020end
1021
1022define showportint
1023 printf "0x%08x ", $arg0
1024 set $kgm_portp = (ipc_port_t)$arg0
1025 printf "0x%08x ", &($kgm_portp->ip_messages)
1026 printf "0x%08x ", $kgm_portp->ip_object.io_receiver_name
1027 if ($kgm_portp->ip_object.io_bits & 0x80000000)
1028 printf "A"
1029 else
1030 printf "D"
1031 end
1032 printf "Port"
1033 printf "%5d ", $kgm_portp->ip_object.io_references
1034 set $kgm_destspacep = (ipc_space_t)0
1035 showportdest $kgm_portp
1036 set $kgm_kmsgp = (ipc_kmsg_t)$kgm_portp->ip_messages.data.port.messages.ikmq_base
1037 if $arg1 && $kgm_kmsgp
1038 showkmsgheader
1039 showkmsgint $kgm_kmsgp
1040 set $kgm_kmsgheadp = $kgm_kmsgp
1041 set $kgm_kmsgp = $kgm_kmsgp->ikm_next
1042 while $kgm_kmsgp != $kgm_kmsgheadp
1043 showkmsgint $kgm_kmsgp
1044 set $kgm_kmsgp = $kgm_kmsgp->ikm_next
1045 end
1046 end
1047end
1048
1049define showpsetint
1050 printf "0x%08x ", $arg0
1051 set $kgm_psetp = (ipc_pset_t)$arg0
1052 printf "0x%08x ", &($kgm_psetp->ips_messages)
1053 printf "0x%08x ", $kgm_psetp->ips_object.io_receiver_name
1054 if ($kgm_psetp->ips_object.io_bits & 0x80000000)
1055 printf "A"
1056 else
1057 printf "D"
1058 end
1059 printf "Set "
1060 printf "%5d ", $kgm_psetp->ips_object.io_references
1061 set $kgm_sublinksp = &($kgm_psetp->ips_messages.data.set_queue.wqs_sublinks)
1062 set $kgm_wql = (wait_queue_link_t)$kgm_sublinksp->next
1063 set $kgm_found = 0
1064 while ( (queue_entry_t)$kgm_wql != (queue_entry_t)$kgm_sublinksp)
1065 set $kgm_portp = (ipc_port_t)((int)($kgm_wql->wql_element->wqe_queue) - ((int)$kgm_portoff))
1066 if !$kgm_found
1067 set $kgm_destspacep = (ipc_space_t)0
1068 showportdest $kgm_portp
1069 showportmemberheader
1070 set $kgm_found = 1
1071 end
1072 showportmember $kgm_portp 0
1073 set $kgm_wql = (wait_queue_link_t)$kgm_wql->wql_sublinks.next
1074 end
1075 if !$kgm_found
1076 printf "--n/e-- --n/e--\n"
1077 end
1078end
1079
1080define showpset
1081 showpsetheader
1082 showpsetint $arg0 1
1083end
1084
1085define showport
1086 showportheader
1087 showportint $arg0 1
1088end
1089
1090define showipcobject
1091 set $kgm_object = (ipc_object_t)$arg0
1092 if ($kgm_objectp->io_bits & 0x7fff0000)
1093 showpset $kgm_objectp
1094 else
1095 showport $kgm_objectp
1096 end
1097end
1098
1099define showmqueue
1100 set $kgm_mqueue = *(ipc_mqueue_t)$arg0
1101 set $kgm_psetoff = &(((ipc_pset_t)0)->ips_messages)
1102 set $kgm_portoff = &(((ipc_port_t)0)->ip_messages)
1103 if ($kgm_mqueue.data.set_queue.wqs_wait_queue.wq_issub)
1104 set $kgm_pset = (((int)$arg0) - ((int)$kgm_psetoff))
1105 showpsetheader
1106 showpsetint $kgm_pset 1
1107 else
1108 showportheader
1109 set $kgm_port = (((int)$arg0) - ((int)$kgm_portoff))
1110 showportint $kgm_port 1
1111 end
1112end
1113
1114define zprint_one
1115set $kgm_zone = (struct zone *)$arg0
1116
1117printf "0x%08x ", $kgm_zone
1118printf "%8d ",$kgm_zone->count
1119printf "%8x ",$kgm_zone->cur_size
1120printf "%8x ",$kgm_zone->max_size
1121printf "%6d ",$kgm_zone->elem_size
1122printf "%8x ",$kgm_zone->alloc_size
1123printf "%s ",$kgm_zone->zone_name
1124
1125if ($kgm_zone->exhaustible)
1126 printf "H"
1127end
1128if ($kgm_zone->collectable)
1129 printf "C"
1130end
1131if ($kgm_zone->expandable)
1132 printf "X"
1133end
1134printf "\n"
1135end
1136
1137
1138define zprint
1139printf "ZONE COUNT TOT_SZ MAX_SZ ELT_SZ ALLOC_SZ NAME\n"
1140set $kgm_zone_ptr = (struct zone *)first_zone
1141while ($kgm_zone_ptr != 0)
1142 zprint_one $kgm_zone_ptr
1143 set $kgm_zone_ptr = $kgm_zone_ptr->next_zone
1144end
1145printf "\n"
1146end
1147document zprint
1148| Routine to print a summary listing of all the kernel zones
1149| The following is the syntax:
1150| (gdb) zprint
1151end
1152