4 # These gdb macros should be useful during kernel development in
5 # determining what's going on in the kernel.
7 # All the convenience variables used by these macros begin with $kgm_
11 set $kgm_dummy = &proc0
12 set $kgm_dummy = &kmod
14 echo Loading Kernel GDB Macros package. Type "help kgm" for more info.\n
17 printf "These are the kernel gdb macros version %d. ", $kgm_vers
18 echo Type "help kgm" for more info.\n
22 | These are the kernel gdb macros. These gdb macros are intended to be
23 | used when debugging a remote kernel via the kdp protocol. Typically, you
24 | would connect to your remote target like so:
25 | (gdb) target remote-kdp
26 | (gdb) attach <name-of-remote-host>
28 | The following macros are available in this package:
30 | showalltasks Display a summary listing of tasks
31 | showallacts Display a summary listing of all activations
32 | showallstacks Display the kernel stacks for all activations
33 | showallvm Display a summary listing of all the vm maps
34 | showallvme Display a summary listing of all the vm map entries
35 | showallipc Display a summary listing of all the ipc spaces
36 | showallrights Display a summary listing of all the ipc rights
37 | showallkmods Display a summary listing of all the kernel modules
39 | showtask Display status of the specified task
40 | showtaskacts Display the status of all activations in the task
41 | showtaskstacks Display all kernel stacks for all activations in the task
42 | showtaskvm Display status of the specified task's vm_map
43 | showtaskvme Display a summary list of the task's vm_map entries
44 | showtaskipc Display status of the specified task's ipc space
45 | showtaskrights Display a summary list of the task's ipc space entries
47 | showact Display status of the specified thread activation
48 | showactstack Display the kernel stack for the specified activation
50 | showmap Display the status of the specified vm_map
51 | showmapvme Display a summary list of the specified vm_map's entries
53 | showipc Display the status of the specified ipc space
54 | showrights Display a summary list of all the rights in an ipc space
56 | showpid Display the status of the process identified by pid
57 | showproc Display the status of the process identified by a proc pointer
59 | showkmod Display information about a kernel module
60 | showkmodaddr Given an address, display the kernel module and offset
62 | zprint Display zone information
63 | paniclog Display the panic log information
65 | switchtoact Switch thread context
66 | switchtoctx Switch context
67 | resetctx Reset context
69 | Type "help <macro>" for more specific help on a particular macro.
70 | Type "show user <macro>" to see what the macro is really doing.
75 printf "kmod address size "
76 printf "id refs version name\n"
80 set $kgm_kmodp = (struct kmod_info *)$arg0
81 printf "0x%08x ", $arg0
82 printf "0x%08x ", $kgm_kmodp->address
83 printf "0x%08x ", $kgm_kmodp->size
84 printf "%3d ", $kgm_kmodp->id
85 printf "%5d ", $kgm_kmodp->reference_count
86 printf "%10s ", &$kgm_kmodp->version
87 printf "%s\n", &$kgm_kmodp->name
90 set $kgm_kmodmin = 0xffffffff
91 set $kgm_fkmodmin = 0x00000000
92 set $kgm_kmodmax = 0x00000000
93 set $kgm_fkmodmax = 0xffffffff
99 if ((unsigned int)$arg0 >= (unsigned int)$kgm_pkmodst) && ((unsigned int)$arg0 <= (unsigned int)$kgm_pkmoden)
100 set $kgm_off = ((unsigned int)$arg0 - (unsigned int)$kgm_pkmodst)
101 printf " <%s + 0x%x>", $kgm_pkmod->name, $kgm_off
103 if ((unsigned int)$arg0 <= (unsigned int)$kgm_fkmodmax) && ((unsigned int)$arg0 >= (unsigned int)$kgm_fkmodmin)
104 set $kgm_kmodp = (struct kmod_info *)kmod
106 set $kgm_kmod = *$kgm_kmodp
107 if $kgm_kmod.address && ($kgm_kmod.address < $kgm_kmodmin)
108 set $kgm_kmodmin = $kgm_kmod.address
110 if ($kgm_kmod.address + $kgm_kmod.size) > $kgm_kmodmax
111 set $kgm_kmodmax = $kgm_kmod.address
113 set $kgm_off = ((unsigned int)$arg0 - (unsigned int)$kgm_kmod.address)
114 if ($kgm_kmod.address <= $arg0) && ($kgm_off <= $kgm_kmod.size)
115 printf " <%s + 0x%x>", $kgm_kmodp->name, $kgm_off
116 set $kgm_pkmod = $kgm_kmodp
117 set $kgm_pkmodst = $kgm_kmod.address
118 set $kgm_pkmoden = $kgm_pkmodst + $kgm_kmod.size
121 set $kgm_kmodp = $kgm_kmod.next
125 set $kgm_fkmodmin = $kgm_kmodmin
126 set $kgm_fkmodmax = $kgm_kmodmax
131 document showkmodaddr
132 | Given an address, print the offset and name for the kmod containing it
133 | The following is the syntax:
134 | (gdb) showkmodaddr <addr>
142 | Routine to print info about a kernel module
143 | The following is the syntax:
144 | (gdb) showkmod <kmod>
149 set $kgm_kmodp = (struct kmod_info *)kmod
151 showkmodint $kgm_kmodp
152 set $kgm_kmodp = $kgm_kmodp->next
155 document showallkmods
156 | Routine to print a summary listing of all the kernel modules
157 | The following is the syntax:
162 printf " activation "
163 printf "thread pri state wait_queue wait_event\n"
168 printf " 0x%08x ", $arg0
169 set $kgm_actp = *(struct thread_activation *)$arg0
171 set $kgm_thread = *$kgm_actp.thread
172 printf "0x%08x ", $kgm_actp.thread
173 printf "%3d ", $kgm_thread.sched_pri
174 set $kgm_state = $kgm_thread.state
198 printf "0x%08x ", $kgm_thread.wait_queue
199 output /a $kgm_thread.wait_event
202 if ($kgm_thread.kernel_stack != 0)
203 if ($kgm_thread.stack_privilege != 0)
204 printf "\n\t\tstack_privilege=0x%08x", $kgm_thread.stack_privilege
206 printf "\n\t\tkernel_stack=0x%08x", $kgm_thread.kernel_stack
207 set $mysp = $kgm_actp->mact.pcb->save_r1
209 printf "\n\t\tstacktop=0x%08x", $mysp
210 while ($mysp != 0) && (($mysp & 0xf) == 0) && ($mysp < 0xb0000000) && ($mysp > $prevsp)
211 printf "\n\t\t0x%08x ", $mysp
212 set $kgm_return = *($mysp + 8)
213 if (($kgm_return > end) && ($kgm_return < 0x40000000))
214 showkmodaddr $kgm_return
216 output /a * ($mysp + 8)
221 printf "\n\t\tstackbottom=0x%08x", $prevsp
223 printf "\n\t\t\tcontinuation="
224 output /a $kgm_thread.continuation
238 | Routine to print out the state of a specific thread activation.
239 | The following is the syntax:
240 | (gdb) showact <activation>
248 document showactstack
249 | Routine to print out the stack of a specific thread activation.
250 | The following is the syntax:
251 | (gdb) showactstack <activation>
256 set $kgm_head_taskp = &default_pset.tasks
257 set $kgm_taskp = (struct task *)($kgm_head_taskp->next)
258 while $kgm_taskp != $kgm_head_taskp
260 showtaskint $kgm_taskp
262 set $kgm_head_actp = &($kgm_taskp->thr_acts)
263 set $kgm_actp = (struct thread_activation *)($kgm_taskp->thr_acts.next)
264 while $kgm_actp != $kgm_head_actp
265 showactint $kgm_actp 0
266 set $kgm_actp = (struct thread_activation *)($kgm_actp->thr_acts.next)
269 set $kgm_taskp = (struct task *)($kgm_taskp->pset_tasks.next)
273 | Routine to print out a summary listing of all the thread activations.
274 | The following is the syntax:
280 set $kgm_head_taskp = &default_pset.tasks
281 set $kgm_taskp = (struct task *)($kgm_head_taskp->next)
282 while $kgm_taskp != $kgm_head_taskp
284 showtaskint $kgm_taskp
285 set $kgm_head_actp = &($kgm_taskp->thr_acts)
286 set $kgm_actp = (struct thread_activation *)($kgm_taskp->thr_acts.next)
287 while $kgm_actp != $kgm_head_actp
289 showactint $kgm_actp 1
290 set $kgm_actp = (struct thread_activation *)($kgm_actp->thr_acts.next)
293 set $kgm_taskp = (struct task *)($kgm_taskp->pset_tasks.next)
296 document showallstacks
297 | Routine to print out a summary listing of all the thread kernel stacks.
298 | The following is the syntax:
299 | (gdb) showallstacks
302 define showwaiterheader
303 printf "waiters activation "
304 printf "thread pri state wait_queue wait_event\n"
307 define showwaitqwaiters
308 set $kgm_w_waitqp = (struct wait_queue *)$arg0
309 set $kgm_w_linksp = &($kgm_w_waitqp->wq_queue)
310 set $kgm_w_wqe = (struct wait_queue_element *)$kgm_w_linksp->next
312 while ( (queue_entry_t)$kgm_w_wqe != (queue_entry_t)$kgm_w_linksp)
313 if ($kgm_w_wqe->wqe_type != &_wait_queue_link)
318 set $kgm_w_shuttle = (struct thread_shuttle *)$kgm_w_wqe
319 showactint $kgm_w_shuttle->top_act 0
321 set $kgm_w_wqe = (struct wait_queue_element *)$kgm_w_wqe->wqe_links.next
325 define showwaitqwaitercount
326 set $kgm_wc_waitqp = (struct wait_queue *)$arg0
327 set $kgm_wc_linksp = &($kgm_wc_waitqp->wq_queue)
328 set $kgm_wc_wqe = (struct wait_queue_element *)$kgm_wc_linksp->next
329 set $kgm_wc_count = 0
330 while ( (queue_entry_t)$kgm_wc_wqe != (queue_entry_t)$kgm_wc_linksp)
331 if ($kgm_wc_wqe->wqe_type != &_wait_queue_link)
332 set $kgm_wc_count = $kgm_wc_count + 1
334 set $kgm_wc_wqe = (struct wait_queue_element *)$kgm_wc_wqe->wqe_links.next
336 printf "0x%08x ", $kgm_wc_count
339 define showwaitqmembercount
340 set $kgm_mc_waitqsetp = (struct wait_queue_set *)$arg0
341 set $kgm_mc_setlinksp = &($kgm_mc_waitqsetp->wqs_setlinks)
342 set $kgm_mc_wql = (struct wait_queue_link *)$kgm_mc_setlinksp->next
343 set $kgm_mc_count = 0
344 while ( (queue_entry_t)$kgm_mc_wql != (queue_entry_t)$kgm_mc_setlinksp)
345 set $kgm_mc_count = $kgm_mc_count + 1
346 set $kgm_mc_wql = (struct wait_queue_link *)$kgm_mc_wql->wql_setlinks.next
348 printf "0x%08x ", $kgm_mc_count
352 define showwaitqmemberheader
353 printf "set-members wait_queue interlock "
354 printf "pol type member_cnt waiter_cnt\n"
357 define showwaitqmemberint
358 set $kgm_m_waitqp = (struct wait_queue *)$arg0
359 printf " 0x%08x ", $kgm_m_waitqp
360 printf "0x%08x ", $kgm_m_waitqp->wq_interlock.lock_data
361 if ($kgm_m_waitqp->wq_fifo)
366 if ($kgm_m_waitqp->wq_type == 0xf1d1)
368 showwaitqmembercount $kgm_m_waitqp
370 printf "Que 0x00000000 "
372 showwaitqwaitercount $kgm_m_waitqp
377 define showwaitqmemberofheader
378 printf "member-of wait_queue interlock "
379 printf "pol type member_cnt waiter_cnt\n"
382 define showwaitqmemberof
383 set $kgm_mo_waitqp = (struct wait_queue *)$arg0
384 set $kgm_mo_linksp = &($kgm_mo_waitqp->wq_queue)
385 set $kgm_mo_wqe = (struct wait_queue_element *)$kgm_mo_linksp->next
386 set $kgm_mo_found = 0
387 while ( (queue_entry_t)$kgm_mo_wqe != (queue_entry_t)$kgm_mo_linksp)
388 if ($kgm_mo_wqe->wqe_type == &_wait_queue_link)
390 set $kgm_mo_found = 1
391 showwaitqmemberofheader
393 set $kgm_mo_wqlp = (struct wait_queue_link *)$kgm_mo_wqe
394 set $kgm_mo_wqsetp = (struct wait_queue *)($kgm_mo_wqlp->wql_setqueue)
395 showwaitqmemberint $kgm_mo_wqsetp
397 set $kgm_mo_wqe = (struct wait_queue_element *)$kgm_mo_wqe->wqe_links.next
401 define showwaitqmembers
402 set $kgm_ms_waitqsetp = (struct wait_queue_set *)$arg0
403 set $kgm_ms_setlinksp = &($kgm_ms_waitqsetp->wqs_setlinks)
404 set $kgm_ms_wql = (struct wait_queue_link *)$kgm_ms_setlinksp->next
405 set $kgm_ms_found = 0
406 while ( (queue_entry_t)$kgm_ms_wql != (queue_entry_t)$kgm_ms_setlinksp)
407 set $kgm_ms_waitqp = $kgm_ms_wql->wql_element.wqe_queue
409 showwaitqmemberheader
410 set $kgm_ms_found = 1
412 showwaitqmemberint $kgm_ms_waitqp
413 set $kgm_ms_wql = (struct wait_queue_link *)$kgm_ms_wql->wql_setlinks.next
417 define showwaitqheader
418 printf "wait_queue ref_count interlock "
419 printf "pol type member_cnt waiter_cnt\n"
423 set $kgm_waitqp = (struct wait_queue *)$arg0
424 printf "0x%08x ", $kgm_waitqp
425 if ($kgm_waitqp->wq_type == 0xf1d1)
426 printf "0x%08x ", ((struct wait_queue_set *)$kgm_waitqp)->wqs_refcount
430 printf "0x%08x ", $kgm_waitqp->wq_interlock.lock_data
431 if ($kgm_waitqp->wq_fifo)
436 if ($kgm_waitqp->wq_type == 0xf1d1)
438 showwaitqmembercount $kgm_waitqp
440 printf "Que 0x00000000 "
442 showwaitqwaitercount $kgm_waitqp
447 set $kgm_waitq1p = (wait_queue_t)$arg0
449 showwaitqint $kgm_waitq1p
450 if ($kgm_waitq1p->wq_type == 0xf1d1)
451 showwaitqmembers $kgm_waitq1p
453 showwaitqmemberof $kgm_waitq1p
455 showwaitqwaiters $kgm_waitq1p
459 printf "vm_map pmap vm_size "
460 printf "#ents rpage hint first_free\n"
464 printf " entry start "
465 printf "prot #page object offset\n"
469 set $kgm_mapp = (vm_map_t)$arg0
470 set $kgm_map = *$kgm_mapp
471 printf "0x%08x ", $arg0
472 printf "0x%08x ", $kgm_map.pmap
473 printf "0x%08x ", $kgm_map.size
474 printf "%3d ", $kgm_map.hdr.nentries
475 printf "%5d ", $kgm_map.pmap->stats.resident_count
476 printf "0x%08x ", $kgm_map.hint
477 printf "0x%08x\n", $kgm_map.first_free
480 set $kgm_head_vmep = &($kgm_mapp->hdr.links)
481 set $kgm_vmep = $kgm_map.hdr.links.next
482 while (($kgm_vmep != 0) && ($kgm_vmep != $kgm_head_vmep))
483 set $kgm_vme = *$kgm_vmep
484 printf " 0x%08x ", $kgm_vmep
485 printf "0x%08x ", $kgm_vme.links.start
486 printf "%1x", $kgm_vme.protection
487 printf "%1x", $kgm_vme.max_protection
488 if $kgm_vme.inheritance == 0x0
491 if $kgm_vme.inheritance == 0x1
494 if $kgm_vme.inheritance == 0x2
497 if $kgm_vme.inheritance == 0x3
500 if $kgm_vme.is_sub_map
503 if $kgm_vme.needs_copy
509 printf "%5d ",($kgm_vme.links.end - $kgm_vme.links.start) >> 12
510 printf "0x%08x ", $kgm_vme.object.vm_object
511 printf "0x%08x\n", $kgm_vme.offset
512 set $kgm_vmep = $kgm_vme.links.next
524 | Routine to print out a summary listing of all the entries in a vm_map
525 | The following is the syntax:
526 | (gdb) showmapvme <vm_map>
535 | Routine to print out a summary description of a vm_map
536 | The following is the syntax:
537 | (gdb) showmap <vm_map>
541 set $kgm_head_taskp = &default_pset.tasks
542 set $kgm_taskp = (struct task *)($kgm_head_taskp->next)
543 while $kgm_taskp != $kgm_head_taskp
546 showtaskint $kgm_taskp
547 showvmint $kgm_taskp->map 0
548 set $kgm_taskp = (struct task *)($kgm_taskp->pset_tasks.next)
552 | Routine to print a summary listing of all the vm maps
553 | The following is the syntax:
559 set $kgm_head_taskp = &default_pset.tasks
560 set $kgm_taskp = (struct task *)($kgm_head_taskp->next)
561 while $kgm_taskp != $kgm_head_taskp
564 showtaskint $kgm_taskp
565 showvmint $kgm_taskp->map 1
566 set $kgm_taskp = (struct task *)($kgm_taskp->pset_tasks.next)
570 | Routine to print a summary listing of all the vm map entries
571 | The following is the syntax:
577 printf "ipc_space is_table table_next "
578 printf "flags tsize splaytree splaybase\n"
581 define showipceheader
582 printf " name object "
583 printf "rite urefs destname destination\n"
587 set $kgm_ie = *(ipc_entry_t)$arg0
588 printf " 0x%08x ", $arg1
589 printf "0x%08x ", $kgm_ie.ie_object
590 if $kgm_ie.ie_bits & 0x00100000
592 printf "%5d\n", $kgm_ie.ie_bits & 0xffff
594 if $kgm_ie.ie_bits & 0x00080000
596 printf "%5d\n", $kgm_ie.ie_bits & 0xffff
598 if $kgm_ie.ie_bits & 0x00010000
599 if $kgm_ie.ie_bits & 0x00020000
605 if $kgm_ie.ie_bits & 0x00020000
609 if $kgm_ie.ie_bits & 0x00040000
612 if $kgm_ie.index.request
617 if $kgm_ie.ie_bits & 0x00800000
622 printf "%5d ", $kgm_ie.ie_bits & 0xffff
623 showportdest $kgm_ie.ie_object
629 set $kgm_isp = (ipc_space_t)$arg0
630 set $kgm_is = *$kgm_isp
631 printf "0x%08x ", $arg0
632 printf "0x%08x ", $kgm_is.is_table
633 printf "0x%08x ", $kgm_is.is_table_next
634 if $kgm_is.is_growing != 0
639 if $kgm_is.is_fast != 0
644 if $kgm_is.is_active != 0
649 printf "%5d ", $kgm_is.is_table_size
650 printf "0x%08x ", $kgm_is.is_tree_total
651 printf "0x%08x\n", &$kgm_isp->is_tree
655 set $kgm_iep = $kgm_is.is_table
656 set $kgm_destspacep = (ipc_space_t)0
657 while ( $kgm_iindex < $kgm_is.is_table_size )
658 set $kgm_ie = *$kgm_iep
659 if $kgm_ie.ie_bits & 0x001f0000
660 set $kgm_name = (($kgm_iindex << 8)|($kgm_ie.ie_bits >> 24))
661 showipceint $kgm_iep $kgm_name
663 set $kgm_iindex = $kgm_iindex + 1
664 set $kgm_iep = &($kgm_is.is_table[$kgm_iindex])
666 if $kgm_is.is_tree_total
667 printf "Still need to write tree traversal\n"
675 set $kgm_isp = (ipc_space_t)$arg0
677 showipcint $kgm_isp 0
680 | Routine to print the status of the specified ipc space
681 | The following is the syntax:
682 | (gdb) showipc <ipc_space>
686 set $kgm_isp = (ipc_space_t)$arg0
688 showipcint $kgm_isp 1
691 | Routine to print a summary list of all the rights in a specified ipc space
692 | The following is the syntax:
693 | (gdb) showrights <ipc_space>
698 set $kgm_taskp = (task_t)$arg0
701 showtaskint $kgm_taskp
702 showipcint $kgm_taskp->itk_space 0
705 | Routine to print the status of the ipc space for a task
706 | The following is the syntax:
707 | (gdb) showtaskipc <task>
711 define showtaskrights
712 set $kgm_taskp = (task_t)$arg0
715 showtaskint $kgm_taskp
716 showipcint $kgm_taskp->itk_space 1
718 document showtaskrights
719 | Routine to print a summary listing of all the ipc rights for a task
720 | The following is the syntax:
721 | (gdb) showtaskrights <task>
725 set $kgm_head_taskp = &default_pset.tasks
726 set $kgm_taskp = (struct task *)($kgm_head_taskp->next)
727 while $kgm_taskp != $kgm_head_taskp
730 showtaskint $kgm_taskp
731 showipcint $kgm_taskp->itk_space 0
732 set $kgm_taskp = (struct task *)($kgm_taskp->pset_tasks.next)
736 | Routine to print a summary listing of all the ipc spaces
737 | The following is the syntax:
743 set $kgm_head_taskp = &default_pset.tasks
744 set $kgm_taskp = (struct task *)($kgm_head_taskp->next)
745 while $kgm_taskp != $kgm_head_taskp
748 showtaskint $kgm_taskp
749 showipcint $kgm_taskp->itk_space 1
750 set $kgm_taskp = (struct task *)($kgm_taskp->pset_tasks.next)
753 document showallrights
754 | Routine to print a summary listing of all the ipc rights
755 | The following is the syntax:
756 | (gdb) showallrights
761 set $kgm_taskp = (task_t)$arg0
764 showtaskint $kgm_taskp
765 showvmint $kgm_taskp->map 0
768 | Routine to print out a summary description of a task's vm_map
769 | The following is the syntax:
770 | (gdb) showtaskvm <task>
774 set $kgm_taskp = (task_t)$arg0
777 showtaskint $kgm_taskp
778 showvmint $kgm_taskp->map 1
781 | Routine to print out a summary listing of a task's vm_map_entries
782 | The following is the syntax:
783 | (gdb) showtaskvme <task>
787 define showtaskheader
788 printf "task vm_map ipc_space #acts "
794 set $kgm_task = *(struct task *)$arg0
795 printf "0x%08x ", $arg0
796 printf "0x%08x ", $kgm_task.map
797 printf "0x%08x ", $kgm_task.itk_space
798 printf "%3d ", $kgm_task.thr_act_count
799 showprocint $kgm_task.bsd_info
807 | Routine to print out info about a task.
808 | The following is the syntax:
809 | (gdb) showtask <task>
815 set $kgm_taskp = (struct task *)$arg0
816 showtaskint $kgm_taskp
818 set $kgm_head_actp = &($kgm_taskp->thr_acts)
819 set $kgm_actp = (struct thread_activation *)($kgm_taskp->thr_acts.next)
820 while $kgm_actp != $kgm_head_actp
821 showactint $kgm_actp 0
822 set $kgm_actp = (struct thread_activation *)($kgm_actp->thr_acts.next)
825 document showtaskacts
826 | Routine to print a summary listing of the activations in a task
827 | The following is the syntax:
828 | (gdb) showtaskacts <task>
832 define showtaskstacks
834 set $kgm_taskp = (struct task *)$arg0
835 showtaskint $kgm_taskp
836 set $kgm_head_actp = &($kgm_taskp->thr_acts)
837 set $kgm_actp = (struct thread_activation *)($kgm_taskp->thr_acts.next)
838 while $kgm_actp != $kgm_head_actp
840 showactint $kgm_actp 1
841 set $kgm_actp = (struct thread_activation *)($kgm_actp->thr_acts.next)
844 document showtaskstacks
845 | Routine to print a summary listing of the activations in a task and their stacks
846 | The following is the syntax:
847 | (gdb) showtaskstacks <task>
853 set $kgm_head_taskp = &default_pset.tasks
854 set $kgm_taskp = (struct task *)($kgm_head_taskp->next)
855 while $kgm_taskp != $kgm_head_taskp
856 showtaskint $kgm_taskp
857 set $kgm_taskp = (struct task *)($kgm_taskp->pset_tasks.next)
860 document showalltasks
861 | Routine to print a summary listing of all the tasks
862 | The following is the syntax:
867 define showprocheader
868 printf " pid proc command\n"
872 set $kgm_procp = (struct proc *)$arg0
874 printf "%5d ", $kgm_procp->p_pid
875 printf "0x%08x ", $kgm_procp
876 printf "%s\n", $kgm_procp->p_comm
878 printf " *0* 0x00000000 --\n"
884 set $kgm_head_taskp = &default_pset.tasks
885 set $kgm_taskp = (struct task *)($kgm_head_taskp->next)
886 while $kgm_taskp != $kgm_head_taskp
887 set $kgm_procp = (struct proc *)$kgm_taskp->bsd_info
888 if (($kgm_procp != 0) && ($kgm_procp->p_pid == $arg0))
889 showtaskint $kgm_taskp
890 set $kgm_taskp = $kgm_head_taskp
892 set $kgm_taskp = (struct task *)($kgm_taskp->pset_tasks.next)
897 | Routine to print a single process by pid
898 | The following is the syntax:
899 | (gdb) showpid <pid>
904 set $kgm_procp = (struct proc *)$arg0
905 showtaskint $kgm_procp->task $arg1 $arg2
910 set switch_debugger=1
914 | kdb - Switch to the inline kernel debugger
918 | The kdb macro allows you to invoke the inline kernel debugger.
921 define showpsetheader
922 printf "portset waitqueue recvname "
923 printf "flags refs recvname process\n"
926 define showportheader
927 printf "port mqueue recvname "
928 printf "flags refs recvname process\n"
931 define showportmemberheader
932 printf "members port recvname "
933 printf "flags refs mqueue msgcount\n"
936 define showkmsgheader
937 printf "messages kmsg size "
938 printf "disp msgid remote-port local-port\n"
942 printf " 0x%08x ", $arg0
943 set $kgm_kmsgh = ((ipc_kmsg_t)$arg0)->ikm_header
944 printf "0x%08x ", $kgm_kmsgh.msgh_size
945 if (($kgm_kmsgh.msgh_bits & 0xff) == 19)
950 if (($kgm_kmsgh.msgh_bits & 0xff00) == (19 < 8))
955 if ($kgm_kmsgh.msgh_bits & 0xf0000000)
960 printf "%5d ", $kgm_kmsgh.msgh_id
961 printf "0x%08x ", $kgm_kmsgh.msgh_remote_port
962 printf "0x%08x\n", $kgm_kmsgh.msgh_local_port
968 set $kgm_portp = (struct ipc_port *)$arg0
969 printf "0x%08x kobject(", $kgm_portp->ip_kobject
970 set $kgm_kotype = ($kgm_portp->ip_object.io_bits & 0x00000fff)
971 if ($kgm_kotype == 1)
974 if ($kgm_kotype == 2)
977 if ($kgm_kotype == 3)
980 if ($kgm_kotype == 4)
983 if ($kgm_kotype == 5)
986 if ($kgm_kotype == 6)
989 if ($kgm_kotype == 7)
992 if ($kgm_kotype == 8)
995 if ($kgm_kotype == 9)
998 if ($kgm_kotype == 10)
1001 if ($kgm_kotype == 11)
1004 if ($kgm_kotype == 12)
1007 if ($kgm_kotype == 13)
1010 if ($kgm_kotype == 14)
1013 if ($kgm_kotype == 15)
1016 if ($kgm_kotype == 16)
1019 if ($kgm_kotype == 17)
1022 if ($kgm_kotype == 18)
1025 if ($kgm_kotype == 19)
1028 if ($kgm_kotype == 20)
1031 if ($kgm_kotype == 21)
1034 if ($kgm_kotype == 22)
1035 printf "IO_DONE_QUE"
1037 if ($kgm_kotype == 23)
1040 if ($kgm_kotype == 24)
1043 if ($kgm_kotype == 25)
1046 if ($kgm_kotype == 26)
1049 if ($kgm_kotype == 27)
1050 printf "IOKIT_SPARE"
1052 if ($kgm_kotype == 28)
1055 if ($kgm_kotype == 29)
1058 if ($kgm_kotype == 30)
1061 if ($kgm_kotype == 31)
1067 define showportdestproc
1068 set $kgm_portp = (struct ipc_port *)$arg0
1069 set $kgm_spacep = $kgm_portp->data.receiver
1070 # check against the previous cached value - this is slow
1071 if ($kgm_spacep != $kgm_destspacep)
1072 set $kgm_destprocp = (struct proc *)0
1073 set $kgm_head_taskp = &default_pset.tasks
1074 set $kgm_taskp = (struct task *)($kgm_head_taskp->next)
1075 while (($kgm_destprocp == 0) && ($kgm_taskp != $kgm_head_taskp))
1076 set $kgm_destspacep = $kgm_taskp->itk_space
1077 if ($kgm_destspacep == $kgm_spacep)
1078 set $kgm_destprocp = (struct proc *)$kgm_taskp->bsd_info
1080 set $kgm_taskp = (struct task *)($kgm_taskp->pset_tasks.next)
1084 if $kgm_destprocp != 0
1085 printf "%s(%d)\n", $kgm_destprocp->p_comm, $kgm_destprocp->p_pid
1087 printf "task 0x%08x\n", $kgm_taskp
1092 set $kgm_portp = (struct ipc_port *)$arg0
1093 set $kgm_spacep = $kgm_portp->data.receiver
1094 if ($kgm_spacep == ipc_space_kernel)
1095 showkobject $kgm_portp
1097 if ($kgm_portp->ip_object.io_bits & 0x80000000)
1098 printf "0x%08x ", $kgm_portp->ip_object.io_receiver_name
1099 showportdestproc $kgm_portp
1101 printf "0x%08x inactive-port\n", $kgm_portp
1106 define showportmember
1107 printf " 0x%08x ", $arg0
1108 set $kgm_portp = (struct ipc_port *)$arg0
1109 printf "0x%08x ", $kgm_portp->ip_object.io_receiver_name
1110 if ($kgm_portp->ip_object.io_bits & 0x80000000)
1115 if ($kgm_portp->ip_object.io_bits & 0x7fff0000)
1120 printf "%5d ", $kgm_portp->ip_object.io_references
1121 printf "0x%08x ", &($kgm_portp->ip_messages)
1122 printf "0x%08x\n", $kgm_portp->ip_messages.data.port.msgcount
1126 printf "0x%08x ", $arg0
1127 set $kgm_portp = (struct ipc_port *)$arg0
1128 printf "0x%08x ", &($kgm_portp->ip_messages)
1129 printf "0x%08x ", $kgm_portp->ip_object.io_receiver_name
1130 if ($kgm_portp->ip_object.io_bits & 0x80000000)
1136 printf "%5d ", $kgm_portp->ip_object.io_references
1137 set $kgm_destspacep = (struct ipc_space *)0
1138 showportdest $kgm_portp
1139 set $kgm_kmsgp = (ipc_kmsg_t)$kgm_portp->ip_messages.data.port.messages.ikmq_base
1140 if $arg1 && $kgm_kmsgp
1142 showkmsgint $kgm_kmsgp
1143 set $kgm_kmsgheadp = $kgm_kmsgp
1144 set $kgm_kmsgp = $kgm_kmsgp->ikm_next
1145 while $kgm_kmsgp != $kgm_kmsgheadp
1146 showkmsgint $kgm_kmsgp
1147 set $kgm_kmsgp = $kgm_kmsgp->ikm_next
1153 printf "0x%08x ", $arg0
1154 set $kgm_psetp = (struct ipc_pset *)$arg0
1155 printf "0x%08x ", &($kgm_psetp->ips_messages)
1156 printf "0x%08x ", $kgm_psetp->ips_object.io_receiver_name
1157 if ($kgm_psetp->ips_object.io_bits & 0x80000000)
1163 printf "%5d ", $kgm_psetp->ips_object.io_references
1164 printf "0x%08x ", $kgm_psetp->ips_object.io_receiver_name
1165 set $kgm_setlinksp = &($kgm_psetp->ips_messages.data.set_queue.wqs_setlinks)
1166 set $kgm_wql = (struct wait_queue_link *)$kgm_setlinksp->next
1168 while ( (queue_entry_t)$kgm_wql != (queue_entry_t)$kgm_setlinksp)
1169 set $kgm_portp = (struct ipc_port *)((int)($kgm_wql->wql_element->wqe_queue) - ((int)$kgm_portoff))
1171 set $kgm_destspacep = (struct ipc_space *)0
1172 showportdestproc $kgm_portp
1173 showportmemberheader
1176 showportmember $kgm_portp 0
1177 set $kgm_wql = (struct wait_queue_link *)$kgm_wql->wql_setlinks.next
1194 define showipcobject
1195 set $kgm_object = (ipc_object_t)$arg0
1196 if ($kgm_objectp->io_bits & 0x7fff0000)
1197 showpset $kgm_objectp
1199 showport $kgm_objectp
1204 set $kgm_mqueue = *(struct ipc_mqueue *)$arg0
1205 set $kgm_psetoff = &(((struct ipc_pset *)0)->ips_messages)
1206 set $kgm_portoff = &(((struct ipc_port *)0)->ip_messages)
1207 if ($kgm_mqueue.data.set_queue.wqs_wait_queue.wq_type == 0xf1d1)
1208 set $kgm_pset = (((int)$arg0) - ((int)$kgm_psetoff))
1210 showpsetint $kgm_pset 1
1212 if ($kgm_mqueue.data.set_queue.wqs_wait_queue.wq_type == 0xf1d0)
1214 set $kgm_port = (((int)$arg0) - ((int)$kgm_portoff))
1215 showportint $kgm_port 1
1220 set $kgm_zone = (struct zone *)$arg0
1222 printf "0x%08x ", $kgm_zone
1223 printf "%8d ",$kgm_zone->count
1224 printf "%8x ",$kgm_zone->cur_size
1225 printf "%8x ",$kgm_zone->max_size
1226 printf "%6d ",$kgm_zone->elem_size
1227 printf "%8x ",$kgm_zone->alloc_size
1228 printf "%s ",$kgm_zone->zone_name
1230 if ($kgm_zone->exhaustible)
1233 if ($kgm_zone->collectable)
1236 if ($kgm_zone->expandable)
1244 printf "ZONE COUNT TOT_SZ MAX_SZ ELT_SZ ALLOC_SZ NAME\n"
1245 set $kgm_zone_ptr = (struct zone *)first_zone
1246 while ($kgm_zone_ptr != 0)
1247 zprint_one $kgm_zone_ptr
1248 set $kgm_zone_ptr = $kgm_zone_ptr->next_zone
1253 | Routine to print a summary listing of all the kernel zones
1254 | The following is the syntax:
1258 set $kdp_act_counter = 0
1261 if (machine_slot[0].cpu_type == 18)
1262 if ($kdp_act_counter == 0)
1263 set $kdpstate = (struct savearea *) kdp.saved_state
1265 set $kdp_act_counter = $kdp_act_counter + 1
1266 set $newact = (struct thread_activation *) $arg0
1267 if (($newact.thread)->kernel_stack == 0)
1268 echo This activation does not have a stack.\n
1270 output/a $newact.thread.continuation
1273 set (struct savearea *) kdp.saved_state=$newact->mact->pcb
1275 set $pc=$newact->mact->pcb.save_srr0
1278 echo switchtoact not implemented for this architecture.\n
1282 document switchtoact
1283 Syntax: switchtoact <address of activation>
1284 | This command allows gdb to examine the execution context and call
1285 | stack for the specified activation. For example, to view the backtrace
1286 | for an activation issue "switchtoact <address>", followed by "bt".
1287 | Before resuming execution, issue a "resetctx" command, to
1288 | return to the original execution context.
1292 if (machine_slot[0].cpu_type == 18)
1293 if ($kdp_act_counter == 0)
1294 set $kdpstate = (struct savearea *) kdp.saved_state
1296 set $kdp_act_counter = $kdp_act_counter + 1
1297 set (struct savearea *) kdp.saved_state=(struct savearea *) $arg0
1299 set $pc=((struct savearea *) $arg0)->save_srr0
1302 echo switchtoctx not implemented for this architecture.\n
1306 document switchtoctx
1307 Syntax: switchtoctx <address of pcb>
1308 | This command allows gdb to examine an execution context and dump the
1309 | backtrace for this execution context.
1310 | Before resuming execution, issue a "resetctx" command, to
1311 | return to the original execution context.
1315 if (machine_slot[0].cpu_type == 18)
1316 set (struct savearea *)kdp.saved_state=$kdpstate
1318 set $pc=((struct savearea *) kdp.saved_state)->save_srr0
1320 set $kdp_act_counter = 0
1322 echo resetctx not implemented for this architecture.\n
1328 | Returns to the original execution context. This command should be
1329 | issued if you wish to resume execution after using the "switchtoact"
1330 | or "switchtoctx" commands.
1334 set $kgm_panic_bufptr = debug_buf
1335 set $kgm_panic_bufptr_max = debug_buf+debug_buf_size
1336 while *$kgm_panic_bufptr && $kgm_panic_bufptr < $kgm_panic_bufptr_max
1337 if *(char *)$kgm_panic_bufptr == 10
1340 printf "%c", *$kgm_panic_bufptr
1342 set $kgm_panic_bufptr= (char *)$kgm_panic_bufptr + 1
1348 | Display the panic log information