3 # These gdb macros should be useful during kernel development in
4 # determining what's going on in the kernel.
6 # All the convenience variables used by these macros begin with $kgm_
8 set print asm-demangle on
11 echo Loading Kernel GDB Macros package. Type "help kgm" for more info.\n
15 echo These are the gdb macros for kernel debugging. Type "help kgm" for more info.\n
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>
25 | The following macros are available in this package:
26 | showversion Displays a string describing the remote kernel version
28 | showalltasks Display a summary listing of all tasks
29 | showallthreads Display info about all threads in the system
30 | showallstacks Display the stack for each thread in the system
31 | showcurrentthreads Display info about the thread running on each cpu
32 | showcurrentstacks Display the stack for the thread running on each cpu
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 | showallclasses Display info about all OSObject subclasses in the system
40 | showobject Show info about an OSObject - its vtable ptr and retain count, & more info for simple container classes.
41 | showregistry Show info about all registry entries in the current plane
42 | showregistryprops Show info about all registry entries in the current plane, and their properties
43 | showregistryentry Show info about a registry entry; its properties and descendants in the current plane
44 | setregistryplane Set the plane to be used for the iokit registry macros (pass zero for list)
46 | showtask Display info about the specified task
47 | showtaskthreads Display info about the threads in the task
48 | showtaskstacks Display the stack for each thread in the task
49 | showtaskvm Display info about the specified task's vm_map
50 | showtaskvme Display info about the task's vm_map entries
51 | showtaskipc Display info about the specified task's ipc space
52 | showtaskrights Display info about the task's ipc space entries
54 | showact Display info about a thread specified by activation
55 | showactstack Display the stack for a thread specified by activation
57 | showmap Display info about the specified vm_map
58 | showmapvme Display a summary list of the specified vm_map's entries
60 | showipc Display info about the specified ipc space
61 | showrights Display a summary list of all the rights in an ipc space
63 | showpid Display info about the process identified by pid
64 | showproc Display info about the process identified by proc struct
65 | showprocinfo Display detailed info about the process identified by proc struct
66 | showprocfiles Given a proc_t pointer, display the list of open file descriptors
67 | showproclocks Given a proc_t pointer, display the list of advisory file locks
68 | zombproc Print out all procs in the zombie list
69 | allproc Print out all process in the system not in the zombie list
70 | zombstacks Print out all stacks of tasks that are exiting
72 | showinitchild Print out all processes in the system which are children of init process
74 | showkmod Display info about a kernel module
75 | showkmodaddr Given an address, display the kernel module and offset
77 | dumpcallqueue Dump out all the entries given a queue head
79 | showallmtx Display info about mutexes usage
80 | showallrwlck Display info about reader/writer locks usage
82 | zprint Display info about the memory zones
83 | showioalloc Display info about iokit allocations
84 | paniclog Display the panic log info
86 | switchtoact Switch to different context specified by activation
87 | switchtoctx Switch to different context
88 | showuserstack Display numeric backtrace of the user stack for an
91 | switchtouserthread Switch to the user context of the specified thread
92 | resetstacks Return to the original kernel context
94 | resetctx Reset context
95 | resume_on Resume when detaching from gdb
96 | resume_off Don't resume when detaching from gdb
98 | sendcore Configure kernel to send a coredump to the specified IP
99 | disablecore Configure the kernel to disable coredump transmission
100 | switchtocorethread Corefile version of "switchtoact"
101 | resetcorectx Corefile version of "resetctx"
103 | readphys Reads the specified untranslated address
104 | readphys64 Reads the specified untranslated 64-bit address
106 | rtentry_showdbg Print the debug information of a route entry
107 | rtentry_trash Walk the list of trash route entries
109 | mbuf_walkpkt Walk the mbuf packet chain (m_nextpkt)
110 | mbuf_walk Walk the mbuf chain (m_next)
111 | mbuf_buf2slab Find the slab structure of the corresponding buffer
112 | mbuf_buf2mca Find the mcache audit structure of the corresponding mbuf
113 | mbuf_showmca Print the contents of an mbuf mcache audit structure
114 | mbuf_showactive Print all active/in-use mbuf objects
115 | mbuf_showinactive Print all freed/in-cache mbuf objects
116 | mbuf_showall Print all mbuf objects
117 | mbuf_slabs Print all slabs in the group
118 | mbuf_slabstbl Print slabs table
119 | mbuf_stat Print extended mbuf allocator statistics
121 | mcache_walkobj Walk the mcache object chain (obj_next)
122 | mcache_stat Print all mcaches in the system
123 | mcache_showcache Display the number of objects in the cache
125 | showbootermemorymap Dump phys memory map from EFI
127 | systemlog Display the kernel's printf ring buffer
129 | showvnodepath Print the path for a vnode
130 | showvnodelocks Display list of advisory locks held/blocked on a vnode
131 | showallvols Display a summary of mounted volumes
132 | showvnode Display info about one vnode
133 | showvolvnodes Display info about all vnodes of a given volume
134 | showvolbusyvnodes Display info about busy (iocount!=0) vnodes of a given volume
135 | showallbusyvnodes Display info about all busy (iocount!=0) vnodes
136 | showallvnodes Display info about all vnodes
137 | print_vnode Print out the fields of a vnode struct
138 | showprocvnodes Print out all the open fds which are vnodes in a process
139 | showallprocvnodes Print out all the open fds which are vnodes in any process
140 | showmountvnodes Print the vnode list
141 | showmountallvnodes Print the vnode inactive list
142 | showworkqvnodes Print the vnode worker list
143 | shownewvnodes Print the new vnode list
145 | ifconfig display ifconfig-like output
146 | showifaddrs show the list of addresses for the given ifp
147 | showifmultiaddrs show the list of multicast addresses for the given ifp
149 | showallpmworkqueues Display info about all IOPMWorkQueue objects
150 | showregistrypmstate Display power management state for all IOPower registry entries
151 | showioservicepm Display the IOServicePM object
152 | showstacksaftertask showallstacks starting after a given task
153 | showstacksafterthread showallstacks starting after a given thread
155 | showMCAstate Print machine-check register state after MC exception.
157 | showallgdbstacks Cause GDB to trace all thread stacks
158 | showallgdbcorestacks Corefile equivalent of "showallgdbstacks"
159 | kdp-reenter Schedule reentry into the debugger and continue.
160 | kdp-reboot Restart remote target
162 | Type "help <macro>" for more specific help on a particular macro.
163 | Type "show user <macro>" to see what the macro is really doing.
166 # This macro should appear before any symbol references, to facilitate
167 # a gdb "source" without a loaded symbol file.
169 printf "%s\n", *(char **)0x501C
174 | Read the kernel version string from a fixed address in low
175 | memory. Useful if you don't know which kernel is on the other end,
176 | and need to find the appropriate symbols. Beware that if you've
177 | loaded a symbol file, but aren't connected to a remote target,
178 | the version string from the symbol file will be displayed instead.
179 | This macro expects to be connected to the remote kernel to function
183 set $kgm_mtype = ((struct mach_header)_mh_execute_header).cputype
185 # This option tells gdb to relax its stack tracing heuristics
186 # Useful for debugging across stack switches
187 # (to the interrupt stack, for instance). Requires gdb-675 or greater.
188 # Don't do this for arm as a workaround to 5486905
189 if ($kgm_mtype != 12)
190 set backtrace sanity-checks off
193 set $kgm_dummy = &proc0
194 set $kgm_dummy = &kmod
196 set $kgm_reg_depth = 0
197 set $kgm_reg_plane = (void **) gIOServicePlane
198 set $kgm_namekey = (OSSymbol *) 0
199 set $kgm_childkey = (OSSymbol *) 0
201 set $kgm_show_object_addrs = 0
202 set $kgm_show_object_retain = 0
203 set $kgm_show_props = 0
205 set $kgm_show_kmod_syms = 0
207 define showkmodheader
208 printf "kmod address size "
209 printf "id refs version name\n"
213 set $kgm_kmodp = (struct kmod_info *)$arg0
214 printf "0x%08x ", $arg0
215 printf "0x%08x ", $kgm_kmodp->address
216 printf "0x%08x ", $kgm_kmodp->size
217 printf "%3d ", $kgm_kmodp->id
218 printf "%5d ", $kgm_kmodp->reference_count
219 printf "%10s ", &$kgm_kmodp->version
220 printf "%s\n", &$kgm_kmodp->name
223 set $kgm_kmodmin = 0xffffffff
224 set $kgm_fkmodmin = 0x00000000
225 set $kgm_kmodmax = 0x00000000
226 set $kgm_fkmodmax = 0xffffffff
230 define showkmodaddrint
231 printf "0x%x" , $arg0
232 if ((unsigned int)$arg0 >= (unsigned int)$kgm_pkmodst) && ((unsigned int)$arg0 <= (unsigned int)$kgm_pkmoden)
233 set $kgm_off = ((unsigned int)$arg0 - (unsigned int)$kgm_pkmodst)
234 printf " <%s + 0x%x>", $kgm_pkmod->name, $kgm_off
236 if ((unsigned int)$arg0 <= (unsigned int)$kgm_fkmodmax) && ((unsigned int)$arg0 >= (unsigned int)$kgm_fkmodmin)
237 set $kgm_kmodp = (struct kmod_info *)kmod
239 set $kgm_kmod = *$kgm_kmodp
240 if $kgm_kmod.address && ($kgm_kmod.address < $kgm_kmodmin)
241 set $kgm_kmodmin = $kgm_kmod.address
243 if ($kgm_kmod.address + $kgm_kmod.size) > $kgm_kmodmax
244 set $kgm_kmodmax = $kgm_kmod.address + $kgm_kmod.size
246 set $kgm_off = ((unsigned int)$arg0 - (unsigned int)$kgm_kmod.address)
247 if ($kgm_kmod.address <= $arg0) && ($kgm_off <= $kgm_kmod.size)
248 printf " <%s + 0x%x>", $kgm_kmodp->name, $kgm_off
249 set $kgm_pkmod = $kgm_kmodp
250 set $kgm_pkmodst = $kgm_kmod.address
251 set $kgm_pkmoden = $kgm_pkmodst + $kgm_kmod.size
254 set $kgm_kmodp = $kgm_kmod.next
258 set $kgm_fkmodmin = $kgm_kmodmin
259 set $kgm_fkmodmax = $kgm_kmodmax
266 showkmodaddrint $arg0
269 document showkmodaddr
270 Syntax: (gdb) showkmodaddr <addr>
271 | Given an address, print the offset and name for the kmod containing it
279 Syntax: (gdb) showkmod <kmod>
280 | Routine to print info about a kernel module
285 set $kgm_kmodp = (struct kmod_info *)kmod
287 showkmodint $kgm_kmodp
288 set $kgm_kmodp = $kgm_kmodp->next
291 document showallkmods
292 Syntax: (gdb) showallkmods
293 | Routine to print a summary listing of all the kernel modules
298 printf "processor pri state wait_queue wait_event\n"
303 printf " 0x%08x ", $arg0
304 set $kgm_thread = *(struct thread *)$arg0
305 printf "0x%08x ", $kgm_thread.last_processor
306 printf "%3d ", $kgm_thread.sched_pri
307 set $kgm_state = $kgm_thread.state
331 printf "0x%08x ", $kgm_thread.wait_queue
332 if (((unsigned)$kgm_thread.wait_event > (unsigned)sectPRELINKB) \
333 && ($arg1 != 2) && ($kgm_show_kmod_syms == 0))
334 showkmodaddr $kgm_thread.wait_event
336 output /a (unsigned) $kgm_thread.wait_event
338 if ($kgm_thread.uthread != 0)
339 set $kgm_uthread = (struct uthread *)$kgm_thread.uthread
340 if ($kgm_uthread->uu_wmesg != 0)
341 printf " \"%s\"", $kgm_uthread->uu_wmesg
346 if ($kgm_thread.kernel_stack != 0)
347 if ($kgm_thread.reserved_stack != 0)
348 printf "\n\t\treserved_stack=0x%08x", $kgm_thread.reserved_stack
350 printf "\n\t\tkernel_stack=0x%08x", $kgm_thread.kernel_stack
351 if ($kgm_mtype == 18)
352 set $mysp = $kgm_thread.machine.pcb->save_r1
355 set $kgm_statep = (struct x86_kernel_state32 *) \
356 ($kgm_thread->kernel_stack + 0x4000 \
357 - sizeof(struct x86_kernel_state32))
358 set $mysp = $kgm_statep->k_ebp
360 if ($kgm_mtype == 12)
364 set $kgm_statep = (struct arm_saved_state *)$kgm_thread.machine.kstackptr
365 set $mysp = $kgm_statep->r[7]
368 set $prevsp = $mysp - 16
369 printf "\n\t\tstacktop=0x%08x", $mysp
370 if ($kgm_mtype == 18)
376 while ($mysp != 0) && (($mysp & $stkmask) == 0) \
377 && ($mysp != $prevsp) \
378 && ((((unsigned) $mysp ^ (unsigned) $prevsp) < 0x2000) \
379 || (((unsigned)$mysp < ((unsigned) ($kgm_thread->kernel_stack+0x4000))) \
380 && ((unsigned)$mysp > (unsigned) ($kgm_thread->kernel_stack))))
381 printf "\n\t\t0x%08x ", $mysp
382 if ($kgm_mtype == 18)
383 set $kgm_return = *($mysp + 8)
386 set $kgm_return = *($mysp + 4)
388 if ($kgm_mtype == 12)
389 set $kgm_return = *($mysp + 4)
391 if (((unsigned) $kgm_return > (unsigned) sectPRELINKB) \
392 && ($kgm_show_kmod_syms == 0))
393 showkmodaddr $kgm_return
395 output /a (unsigned) $kgm_return
401 printf "\n\t\tstackbottom=0x%08x", $prevsp
403 printf "\n\t\t\tcontinuation="
404 output /a (unsigned) $kgm_thread.continuation
417 Syntax: (gdb) showact <activation>
418 | Routine to print out the state of a specific thread.
426 document showactstack
427 Syntax: (gdb) showactstack <activation>
428 | Routine to print out the stack of a specific thread.
432 define showallthreads
433 set $kgm_head_taskp = &tasks
434 set $kgm_taskp = (struct task *)($kgm_head_taskp->next)
435 while $kgm_taskp != $kgm_head_taskp
437 showtaskint $kgm_taskp
439 set $kgm_head_actp = &($kgm_taskp->threads)
440 set $kgm_actp = (struct thread *)($kgm_taskp->threads.next)
441 while $kgm_actp != $kgm_head_actp
442 showactint $kgm_actp 0
443 set $kgm_actp = (struct thread *)($kgm_actp->task_threads.next)
446 set $kgm_taskp = (struct task *)($kgm_taskp->tasks.next)
449 document showallthreads
450 Syntax: (gdb) showallthreads
451 | Routine to print out info about all threads in the system.
454 define showcurrentthreads
455 set $kgm_prp = (struct processor *)processor_list
457 if ($kgm_prp)->active_thread != 0
458 set $kgm_actp = ($kgm_prp)->active_thread
460 showtaskint ($kgm_actp)->task
462 showactint $kgm_actp 0
465 set $kgm_prp = ($kgm_prp)->processor_list
468 document showcurrentthreads
469 Syntax: (gdb) showcurrentthreads
470 | Routine to print out info about the thread running on each cpu.
473 set $decode_wait_events = 0
475 set $kgm_head_taskp = &tasks
476 set $kgm_taskp = (struct task *)($kgm_head_taskp->next)
477 while $kgm_taskp != $kgm_head_taskp
479 showtaskint $kgm_taskp
480 set $kgm_head_actp = &($kgm_taskp->threads)
481 set $kgm_actp = (struct thread *)($kgm_taskp->threads.next)
482 while $kgm_actp != $kgm_head_actp
484 if ($decode_wait_events > 0)
485 showactint $kgm_actp 1
487 showactint $kgm_actp 2
489 set $kgm_actp = (struct thread *)($kgm_actp->task_threads.next)
492 set $kgm_taskp = (struct task *)($kgm_taskp->tasks.next)
496 document showallstacks
497 Syntax: (gdb) showallstacks
498 | Routine to print out the stack for each thread in the system.
499 | If the variable $decode_wait_events is non-zero, the routine attempts to
500 | interpret thread wait_events as kernel module offsets, which can add to
504 define showcurrentstacks
505 set $kgm_prp = processor_list
507 if ($kgm_prp)->active_thread != 0
508 set $kgm_actp = ($kgm_prp)->active_thread
510 showtaskint ($kgm_actp)->task
512 showactint $kgm_actp 1
515 set $kgm_prp = ($kgm_prp)->processor_list
519 document showcurrentstacks
520 Syntax: (gdb) showcurrentstacks
521 | Routine to print out the thread running on each cpu (incl. its stack)
524 define showwaiterheader
525 printf "waiters activation "
526 printf "thread pri state wait_queue wait_event\n"
529 define showwaitqwaiters
530 set $kgm_w_waitqp = (struct wait_queue *)$arg0
531 set $kgm_w_linksp = &($kgm_w_waitqp->wq_queue)
532 set $kgm_w_wqe = (struct wait_queue_element *)$kgm_w_linksp->next
534 while ( (queue_entry_t)$kgm_w_wqe != (queue_entry_t)$kgm_w_linksp)
535 if ($kgm_w_wqe->wqe_type != &_wait_queue_link)
540 set $kgm_w_shuttle = (struct thread *)$kgm_w_wqe
541 showactint $kgm_w_shuttle 0
543 set $kgm_w_wqe = (struct wait_queue_element *)$kgm_w_wqe->wqe_links.next
547 define showwaitqwaitercount
548 set $kgm_wc_waitqp = (struct wait_queue *)$arg0
549 set $kgm_wc_linksp = &($kgm_wc_waitqp->wq_queue)
550 set $kgm_wc_wqe = (struct wait_queue_element *)$kgm_wc_linksp->next
551 set $kgm_wc_count = 0
552 while ( (queue_entry_t)$kgm_wc_wqe != (queue_entry_t)$kgm_wc_linksp)
553 if ($kgm_wc_wqe->wqe_type != &_wait_queue_link)
554 set $kgm_wc_count = $kgm_wc_count + 1
556 set $kgm_wc_wqe = (struct wait_queue_element *)$kgm_wc_wqe->wqe_links.next
558 printf "0x%08x ", $kgm_wc_count
561 define showwaitqmembercount
562 set $kgm_mc_waitqsetp = (struct wait_queue_set *)$arg0
563 set $kgm_mc_setlinksp = &($kgm_mc_waitqsetp->wqs_setlinks)
564 set $kgm_mc_wql = (struct wait_queue_link *)$kgm_mc_setlinksp->next
565 set $kgm_mc_count = 0
566 while ( (queue_entry_t)$kgm_mc_wql != (queue_entry_t)$kgm_mc_setlinksp)
567 set $kgm_mc_count = $kgm_mc_count + 1
568 set $kgm_mc_wql = (struct wait_queue_link *)$kgm_mc_wql->wql_setlinks.next
570 printf "0x%08x ", $kgm_mc_count
574 define showwaitqmemberheader
575 printf "set-members wait_queue interlock "
576 printf "pol type member_cnt waiter_cnt\n"
579 define showwaitqmemberint
580 set $kgm_m_waitqp = (struct wait_queue *)$arg0
581 printf " 0x%08x ", $kgm_m_waitqp
582 printf "0x%08x ", $kgm_m_waitqp->wq_interlock.lock_data
583 if ($kgm_m_waitqp->wq_fifo)
588 if ($kgm_m_waitqp->wq_type == 0xf1d1)
590 showwaitqmembercount $kgm_m_waitqp
592 printf "Que 0x00000000 "
594 showwaitqwaitercount $kgm_m_waitqp
599 define showwaitqmemberofheader
600 printf "member-of wait_queue interlock "
601 printf "pol type member_cnt waiter_cnt\n"
604 define showwaitqmemberof
605 set $kgm_mo_waitqp = (struct wait_queue *)$arg0
606 set $kgm_mo_linksp = &($kgm_mo_waitqp->wq_queue)
607 set $kgm_mo_wqe = (struct wait_queue_element *)$kgm_mo_linksp->next
608 set $kgm_mo_found = 0
609 while ( (queue_entry_t)$kgm_mo_wqe != (queue_entry_t)$kgm_mo_linksp)
610 if ($kgm_mo_wqe->wqe_type == &_wait_queue_link)
612 set $kgm_mo_found = 1
613 showwaitqmemberofheader
615 set $kgm_mo_wqlp = (struct wait_queue_link *)$kgm_mo_wqe
616 set $kgm_mo_wqsetp = (struct wait_queue *)($kgm_mo_wqlp->wql_setqueue)
617 showwaitqmemberint $kgm_mo_wqsetp
619 set $kgm_mo_wqe = (struct wait_queue_element *)$kgm_mo_wqe->wqe_links.next
623 define showwaitqmembers
624 set $kgm_ms_waitqsetp = (struct wait_queue_set *)$arg0
625 set $kgm_ms_setlinksp = &($kgm_ms_waitqsetp->wqs_setlinks)
626 set $kgm_ms_wql = (struct wait_queue_link *)$kgm_ms_setlinksp->next
627 set $kgm_ms_found = 0
628 while ( (queue_entry_t)$kgm_ms_wql != (queue_entry_t)$kgm_ms_setlinksp)
629 set $kgm_ms_waitqp = $kgm_ms_wql->wql_element.wqe_queue
631 showwaitqmemberheader
632 set $kgm_ms_found = 1
634 showwaitqmemberint $kgm_ms_waitqp
635 set $kgm_ms_wql = (struct wait_queue_link *)$kgm_ms_wql->wql_setlinks.next
639 define showwaitqheader
640 printf "wait_queue ref_count interlock "
641 printf "pol type member_cnt waiter_cnt\n"
645 set $kgm_waitqp = (struct wait_queue *)$arg0
646 printf "0x%08x ", $kgm_waitqp
647 if ($kgm_waitqp->wq_type == 0xf1d1)
648 printf "0x%08x ", ((struct wait_queue_set *)$kgm_waitqp)->wqs_refcount
652 printf "0x%08x ", $kgm_waitqp->wq_interlock.lock_data
653 if ($kgm_waitqp->wq_fifo)
658 if ($kgm_waitqp->wq_type == 0xf1d1)
660 showwaitqmembercount $kgm_waitqp
662 printf "Que 0x00000000 "
664 showwaitqwaitercount $kgm_waitqp
669 set $kgm_waitq1p = (wait_queue_t)$arg0
671 showwaitqint $kgm_waitq1p
672 if ($kgm_waitq1p->wq_type == 0xf1d1)
673 showwaitqmembers $kgm_waitq1p
675 showwaitqmemberof $kgm_waitq1p
677 showwaitqwaiters $kgm_waitq1p
681 printf "vm_map pmap vm_size "
682 printf "#ents rpage hint first_free\n"
686 printf " entry start "
687 printf " prot #page object offset\n"
691 set $kgm_mapp = (vm_map_t)$arg0
692 set $kgm_map = *$kgm_mapp
693 printf "0x%08x ", $arg0
694 printf "0x%08x ", $kgm_map.pmap
695 printf "0x%08x ", $kgm_map.size
696 printf "%3d ", $kgm_map.hdr.nentries
698 printf "%5d ", $kgm_map.pmap->stats.resident_count
702 printf "0x%08x ", $kgm_map.hint
703 printf "0x%08x\n", $kgm_map.first_free
706 set $kgm_head_vmep = &($kgm_mapp->hdr.links)
707 set $kgm_vmep = $kgm_map.hdr.links.next
708 while (($kgm_vmep != 0) && ($kgm_vmep != $kgm_head_vmep))
709 set $kgm_vme = *$kgm_vmep
710 printf " 0x%08x ", $kgm_vmep
711 printf "0x%016llx ", $kgm_vme.links.start
712 printf "%1x", $kgm_vme.protection
713 printf "%1x", $kgm_vme.max_protection
714 if $kgm_vme.inheritance == 0x0
717 if $kgm_vme.inheritance == 0x1
720 if $kgm_vme.inheritance == 0x2
723 if $kgm_vme.inheritance == 0x3
726 if $kgm_vme.is_sub_map
729 if $kgm_vme.needs_copy
735 printf "%5d ",($kgm_vme.links.end - $kgm_vme.links.start) >> 12
736 printf "0x%08x ", $kgm_vme.object.vm_object
737 printf "0x%016llx\n", $kgm_vme.offset
738 set $kgm_vmep = $kgm_vme.links.next
750 Syntax: (gdb) showmapvme <vm_map>
751 | Routine to print out a summary listing of all the entries in a vm_map
760 Syntax: (gdb) showmap <vm_map>
761 | Routine to print out info about the specified vm_map
765 set $kgm_head_taskp = &tasks
766 set $kgm_taskp = (struct task *)($kgm_head_taskp->next)
767 while $kgm_taskp != $kgm_head_taskp
770 showtaskint $kgm_taskp
771 showvmint $kgm_taskp->map 0
772 set $kgm_taskp = (struct task *)($kgm_taskp->tasks.next)
776 Syntax: (gdb) showallvm
777 | Routine to print a summary listing of all the vm maps
782 set $kgm_head_taskp = &tasks
783 set $kgm_taskp = (struct task *)($kgm_head_taskp->next)
784 while $kgm_taskp != $kgm_head_taskp
787 showtaskint $kgm_taskp
788 showvmint $kgm_taskp->map 1
789 set $kgm_taskp = (struct task *)($kgm_taskp->tasks.next)
793 Syntax: (gdb) showallvme
794 | Routine to print a summary listing of all the vm map entries
799 printf "ipc_space is_table table_next "
800 printf "flags tsize splaytree splaybase\n"
803 define showipceheader
804 printf " name object "
805 printf "rite urefs destname destination\n"
809 set $kgm_ie = *(ipc_entry_t)$arg0
810 printf " 0x%08x ", $arg1
811 printf "0x%08x ", $kgm_ie.ie_object
812 if $kgm_ie.ie_bits & 0x00100000
814 printf "%5d\n", $kgm_ie.ie_bits & 0xffff
816 if $kgm_ie.ie_bits & 0x00080000
818 printf "%5d\n", $kgm_ie.ie_bits & 0xffff
820 if $kgm_ie.ie_bits & 0x00010000
821 if $kgm_ie.ie_bits & 0x00020000
827 if $kgm_ie.ie_bits & 0x00020000
831 if $kgm_ie.ie_bits & 0x00040000
834 if $kgm_ie.index.request
839 if $kgm_ie.ie_bits & 0x00800000
844 printf "%5d ", $kgm_ie.ie_bits & 0xffff
845 showportdest $kgm_ie.ie_object
851 set $kgm_isp = (ipc_space_t)$arg0
852 set $kgm_is = *$kgm_isp
853 printf "0x%08x ", $arg0
854 printf "0x%08x ", $kgm_is.is_table
855 printf "0x%08x ", $kgm_is.is_table_next
856 if $kgm_is.is_growing != 0
861 if $kgm_is.is_fast != 0
866 if $kgm_is.is_active != 0
871 printf "%5d ", $kgm_is.is_table_size
872 printf "0x%08x ", $kgm_is.is_tree_total
873 printf "0x%08x\n", &$kgm_isp->is_tree
877 set $kgm_iep = $kgm_is.is_table
878 set $kgm_destspacep = (ipc_space_t)0
879 while ( $kgm_iindex < $kgm_is.is_table_size )
880 set $kgm_ie = *$kgm_iep
881 if $kgm_ie.ie_bits & 0x001f0000
882 set $kgm_name = (($kgm_iindex << 8)|($kgm_ie.ie_bits >> 24))
883 showipceint $kgm_iep $kgm_name
885 set $kgm_iindex = $kgm_iindex + 1
886 set $kgm_iep = &($kgm_is.is_table[$kgm_iindex])
888 if $kgm_is.is_tree_total
889 printf "Still need to write tree traversal\n"
897 set $kgm_isp = (ipc_space_t)$arg0
899 showipcint $kgm_isp 0
902 Syntax: (gdb) showipc <ipc_space>
903 | Routine to print the status of the specified ipc space
907 set $kgm_isp = (ipc_space_t)$arg0
909 showipcint $kgm_isp 1
912 Syntax: (gdb) showrights <ipc_space>
913 | Routine to print a summary list of all the rights in a specified ipc space
918 set $kgm_taskp = (task_t)$arg0
921 showtaskint $kgm_taskp
922 showipcint $kgm_taskp->itk_space 0
925 Syntax: (gdb) showtaskipc <task>
926 | Routine to print info about the ipc space for a task
930 define showtaskrights
931 set $kgm_taskp = (task_t)$arg0
934 showtaskint $kgm_taskp
935 showipcint $kgm_taskp->itk_space 1
937 document showtaskrights
938 Syntax: (gdb) showtaskrights <task>
939 | Routine to print info about the ipc rights for a task
943 set $kgm_head_taskp = &tasks
944 set $kgm_cur_taskp = (struct task *)($kgm_head_taskp->next)
945 while $kgm_cur_taskp != $kgm_head_taskp
948 showtaskint $kgm_cur_taskp
949 showipcint $kgm_cur_taskp->itk_space 0
950 set $kgm_cur_taskp = (struct task *)($kgm_cur_taskp->tasks.next)
954 Syntax: (gdb) showallipc
955 | Routine to print a summary listing of all the ipc spaces
960 set $kgm_head_taskp = &tasks
961 set $kgm_cur_taskp = (struct task *)($kgm_head_taskp->next)
962 while $kgm_cur_taskp != $kgm_head_taskp
965 showtaskint $kgm_cur_taskp
966 showipcint $kgm_cur_taskp->itk_space 1
967 set $kgm_cur_taskp = (struct task *)($kgm_cur_taskp->tasks.next)
970 document showallrights
971 Syntax: (gdb) showallrights
972 | Routine to print a summary listing of all the ipc rights
977 set $kgm_taskp = (task_t)$arg0
980 showtaskint $kgm_taskp
981 showvmint $kgm_taskp->map 0
984 Syntax: (gdb) showtaskvm <task>
985 | Routine to print out info about a task's vm_map
989 set $kgm_taskp = (task_t)$arg0
992 showtaskint $kgm_taskp
993 showvmint $kgm_taskp->map 1
996 Syntax: (gdb) showtaskvme <task>
997 | Routine to print out info about a task's vm_map_entries
1001 define showtaskheader
1002 printf "task vm_map ipc_space #acts "
1008 set $kgm_task = *(struct task *)$arg0
1009 printf "0x%08x ", $arg0
1010 printf "0x%08x ", $kgm_task.map
1011 printf "0x%08x ", $kgm_task.itk_space
1012 printf "%3d ", $kgm_task.thread_count
1013 showprocint $kgm_task.bsd_info
1021 Syntax (gdb) showtask <task>
1022 | Routine to print out info about a task.
1026 define showtaskthreads
1028 set $kgm_taskp = (struct task *)$arg0
1029 showtaskint $kgm_taskp
1031 set $kgm_head_actp = &($kgm_taskp->threads)
1032 set $kgm_actp = (struct thread *)($kgm_taskp->threads.next)
1033 while $kgm_actp != $kgm_head_actp
1034 showactint $kgm_actp 0
1035 set $kgm_actp = (struct thread *)($kgm_actp->task_threads.next)
1038 document showtaskthreads
1039 Syntax: (gdb) showtaskthreads <task>
1040 | Routine to print info about the threads in a task.
1044 define showtaskstacks
1046 set $kgm_taskp = (struct task *)$arg0
1047 showtaskint $kgm_taskp
1048 set $kgm_head_actp = &($kgm_taskp->threads)
1049 set $kgm_actp = (struct thread *)($kgm_taskp->threads.next)
1050 while $kgm_actp != $kgm_head_actp
1052 showactint $kgm_actp 1
1053 set $kgm_actp = (struct thread *)($kgm_actp->task_threads.next)
1056 document showtaskstacks
1057 Syntax: (gdb) showtaskstacks <task>
1058 | Routine to print out the stack for each thread in a task.
1064 set $kgm_head_taskp = &tasks
1065 set $kgm_taskp = (struct task *)($kgm_head_taskp->next)
1066 while $kgm_taskp != $kgm_head_taskp
1067 showtaskint $kgm_taskp
1068 set $kgm_taskp = (struct task *)($kgm_taskp->tasks.next)
1071 document showalltasks
1072 Syntax: (gdb) showalltasks
1073 | Routine to print a summary listing of all the tasks
1077 define showprocheader
1078 printf " pid proc command\n"
1082 set $kgm_procp = (struct proc *)$arg0
1084 printf "%5d ", $kgm_procp->p_pid
1085 printf "0x%08x ", $kgm_procp
1086 printf "%s\n", $kgm_procp->p_comm
1088 printf " *0* 0x00000000 --\n"
1094 set $kgm_head_taskp = &tasks
1095 set $kgm_taskp = (struct task *)($kgm_head_taskp->next)
1096 while $kgm_taskp != $kgm_head_taskp
1097 set $kgm_procp = (struct proc *)$kgm_taskp->bsd_info
1098 if (($kgm_procp != 0) && ($kgm_procp->p_pid == $arg0))
1099 showtaskint $kgm_taskp
1100 set $kgm_taskp = $kgm_head_taskp
1102 set $kgm_taskp = (struct task *)($kgm_taskp->tasks.next)
1107 Syntax: (gdb) showpid <pid>
1108 | Routine to print a single process by pid
1113 set $kgm_procp = (struct proc *)$arg0
1114 showtaskint $kgm_procp->task $arg1 $arg2
1119 set switch_debugger=1
1123 | kdb - Switch to the inline kernel debugger
1127 | The kdb macro allows you to invoke the inline kernel debugger.
1130 define showpsetheader
1131 printf "portset waitqueue recvname "
1132 printf "flags refs recvname process\n"
1135 define showportheader
1136 printf "port mqueue recvname "
1137 printf "flags refs recvname process\n"
1140 define showportmemberheader
1141 printf "members port recvname "
1142 printf "flags refs mqueue msgcount\n"
1145 define showkmsgheader
1146 printf "messages kmsg size "
1147 printf "disp msgid remote-port local-port\n"
1151 printf " 0x%08x ", $arg0
1152 set $kgm_kmsgh = ((ipc_kmsg_t)$arg0)->ikm_header
1153 printf "0x%08x ", $kgm_kmsgh.msgh_size
1154 if (($kgm_kmsgh.msgh_bits & 0xff) == 19)
1159 if (($kgm_kmsgh.msgh_bits & 0xff00) == (19 < 8))
1164 if ($kgm_kmsgh.msgh_bits & 0xf0000000)
1169 printf "%5d ", $kgm_kmsgh.msgh_id
1170 printf "0x%08x ", $kgm_kmsgh.msgh_remote_port
1171 printf "0x%08x\n", $kgm_kmsgh.msgh_local_port
1177 set $kgm_portp = (struct ipc_port *)$arg0
1178 printf "0x%08x kobject(", $kgm_portp->ip_kobject
1179 set $kgm_kotype = ($kgm_portp->ip_object.io_bits & 0x00000fff)
1180 if ($kgm_kotype == 1)
1183 if ($kgm_kotype == 2)
1186 if ($kgm_kotype == 3)
1189 if ($kgm_kotype == 4)
1192 if ($kgm_kotype == 5)
1195 if ($kgm_kotype == 6)
1198 if ($kgm_kotype == 7)
1201 if ($kgm_kotype == 8)
1204 if ($kgm_kotype == 9)
1207 if ($kgm_kotype == 10)
1210 if ($kgm_kotype == 11)
1213 if ($kgm_kotype == 12)
1216 if ($kgm_kotype == 13)
1219 if ($kgm_kotype == 14)
1222 if ($kgm_kotype == 15)
1225 if ($kgm_kotype == 16)
1228 if ($kgm_kotype == 17)
1231 if ($kgm_kotype == 18)
1234 if ($kgm_kotype == 19)
1237 if ($kgm_kotype == 20)
1240 if ($kgm_kotype == 21)
1243 if ($kgm_kotype == 22)
1244 printf "IO_DONE_QUE"
1246 if ($kgm_kotype == 23)
1249 if ($kgm_kotype == 24)
1252 if ($kgm_kotype == 25)
1255 if ($kgm_kotype == 26)
1258 if ($kgm_kotype == 27)
1259 printf "IOKIT_SPARE"
1261 if ($kgm_kotype == 28)
1264 if ($kgm_kotype == 29)
1267 if ($kgm_kotype == 30)
1270 if ($kgm_kotype == 31)
1276 define showportdestproc
1277 set $kgm_portp = (struct ipc_port *)$arg0
1278 set $kgm_spacep = $kgm_portp->data.receiver
1279 # check against the previous cached value - this is slow
1280 if ($kgm_spacep != $kgm_destspacep)
1281 set $kgm_destprocp = (struct proc *)0
1282 set $kgm_head_taskp = &tasks
1283 set $kgm_desttaskp = (struct task *)($kgm_head_taskp->next)
1284 while (($kgm_destprocp == 0) && ($kgm_desttaskp != $kgm_head_taskp))
1285 set $kgm_destspacep = $kgm_desttaskp->itk_space
1286 if ($kgm_destspacep == $kgm_spacep)
1287 set $kgm_destprocp = (struct proc *)$kgm_desttaskp->bsd_info
1289 set $kgm_desttaskp = (struct task *)($kgm_desttaskp->tasks.next)
1293 if $kgm_destprocp != 0
1294 printf "%s(%d)\n", $kgm_destprocp->p_comm, $kgm_destprocp->p_pid
1296 printf "task 0x%08x\n", $kgm_desttaskp
1301 set $kgm_portp = (struct ipc_port *)$arg0
1302 set $kgm_spacep = $kgm_portp->data.receiver
1303 if ($kgm_spacep == ipc_space_kernel)
1304 showkobject $kgm_portp
1306 if ($kgm_portp->ip_object.io_bits & 0x80000000)
1307 printf "0x%08x ", $kgm_portp->ip_object.io_receiver_name
1308 showportdestproc $kgm_portp
1310 printf "0x%08x inactive-port\n", $kgm_portp
1315 define showportmember
1316 printf " 0x%08x ", $arg0
1317 set $kgm_portp = (struct ipc_port *)$arg0
1318 printf "0x%08x ", $kgm_portp->ip_object.io_receiver_name
1319 if ($kgm_portp->ip_object.io_bits & 0x80000000)
1324 if ($kgm_portp->ip_object.io_bits & 0x7fff0000)
1329 printf "%5d ", $kgm_portp->ip_object.io_references
1330 printf "0x%08x ", &($kgm_portp->ip_messages)
1331 printf "0x%08x\n", $kgm_portp->ip_messages.data.port.msgcount
1335 printf "0x%08x ", $arg0
1336 set $kgm_portp = (struct ipc_port *)$arg0
1337 printf "0x%08x ", &($kgm_portp->ip_messages)
1338 printf "0x%08x ", $kgm_portp->ip_object.io_receiver_name
1339 if ($kgm_portp->ip_object.io_bits & 0x80000000)
1345 printf "%5d ", $kgm_portp->ip_object.io_references
1346 set $kgm_destspacep = (struct ipc_space *)0
1347 showportdest $kgm_portp
1348 set $kgm_kmsgp = (ipc_kmsg_t)$kgm_portp->ip_messages.data.port.messages.ikmq_base
1349 if $arg1 && $kgm_kmsgp
1351 showkmsgint $kgm_kmsgp
1352 set $kgm_kmsgheadp = $kgm_kmsgp
1353 set $kgm_kmsgp = $kgm_kmsgp->ikm_next
1354 while $kgm_kmsgp != $kgm_kmsgheadp
1355 showkmsgint $kgm_kmsgp
1356 set $kgm_kmsgp = $kgm_kmsgp->ikm_next
1362 printf "0x%08x ", $arg0
1363 set $kgm_psetp = (struct ipc_pset *)$arg0
1364 printf "0x%08x ", &($kgm_psetp->ips_messages)
1365 printf "0x%08x ", $kgm_psetp->ips_object.io_receiver_name
1366 if ($kgm_psetp->ips_object.io_bits & 0x80000000)
1372 printf "%5d ", $kgm_psetp->ips_object.io_references
1373 printf "0x%08x ", $kgm_psetp->ips_object.io_receiver_name
1374 set $kgm_setlinksp = &($kgm_psetp->ips_messages.data.set_queue.wqs_setlinks)
1375 set $kgm_wql = (struct wait_queue_link *)$kgm_setlinksp->next
1377 while ( (queue_entry_t)$kgm_wql != (queue_entry_t)$kgm_setlinksp)
1378 set $kgm_portp = (struct ipc_port *)((int)($kgm_wql->wql_element->wqe_queue) - ((int)$kgm_portoff))
1380 set $kgm_destspacep = (struct ipc_space *)0
1381 showportdestproc $kgm_portp
1382 showportmemberheader
1385 showportmember $kgm_portp 0
1386 set $kgm_wql = (struct wait_queue_link *)$kgm_wql->wql_setlinks.next
1403 define showipcobject
1404 set $kgm_object = (ipc_object_t)$arg0
1405 if ($kgm_objectp->io_bits & 0x7fff0000)
1406 showpset $kgm_objectp
1408 showport $kgm_objectp
1413 set $kgm_mqueue = *(struct ipc_mqueue *)$arg0
1414 set $kgm_psetoff = &(((struct ipc_pset *)0)->ips_messages)
1415 set $kgm_portoff = &(((struct ipc_port *)0)->ip_messages)
1416 if ($kgm_mqueue.data.set_queue.wqs_wait_queue.wq_type == 0xf1d1)
1417 set $kgm_pset = (((int)$arg0) - ((int)$kgm_psetoff))
1419 showpsetint $kgm_pset 1
1421 if ($kgm_mqueue.data.set_queue.wqs_wait_queue.wq_type == 0xf1d0)
1423 set $kgm_port = (((int)$arg0) - ((int)$kgm_portoff))
1424 showportint $kgm_port 1
1429 set $kgm_zone = (struct zone *)$arg0
1431 printf "0x%08x ", $kgm_zone
1432 printf "%8d ",$kgm_zone->count
1433 printf "%8x ",$kgm_zone->cur_size
1434 printf "%8x ",$kgm_zone->max_size
1435 printf "%6d ",$kgm_zone->elem_size
1436 printf "%8x ",$kgm_zone->alloc_size
1437 printf "%s ",$kgm_zone->zone_name
1439 if ($kgm_zone->exhaustible)
1442 if ($kgm_zone->collectable)
1445 if ($kgm_zone->expandable)
1453 printf "ZONE COUNT TOT_SZ MAX_SZ ELT_SZ ALLOC_SZ NAME\n"
1454 set $kgm_zone_ptr = (struct zone *)first_zone
1455 while ($kgm_zone_ptr != 0)
1456 zprint_one $kgm_zone_ptr
1457 set $kgm_zone_ptr = $kgm_zone_ptr->next_zone
1462 Syntax: (gdb) zprint
1463 | Routine to print a summary listing of all the kernel zones
1467 set $kgm_mtxgrp = (struct _lck_grp_ *)$arg0
1469 if ($kgm_mtxgrp->lck_grp_mtxcnt)
1470 printf "0x%08x ", $kgm_mtxgrp
1471 printf "%8d ",$kgm_mtxgrp->lck_grp_mtxcnt
1472 printf "%12u ",$kgm_mtxgrp->lck_grp_stat.lck_grp_mtx_stat.lck_grp_mtx_util_cnt
1473 printf "%8u ",$kgm_mtxgrp->lck_grp_stat.lck_grp_mtx_stat.lck_grp_mtx_miss_cnt
1474 printf "%8u ",$kgm_mtxgrp->lck_grp_stat.lck_grp_mtx_stat.lck_grp_mtx_wait_cnt
1475 printf "%s ",&$kgm_mtxgrp->lck_grp_name
1482 printf "LCK GROUP CNT UTIL MISS WAIT NAME\n"
1483 set $kgm_mtxgrp_ptr = (struct _lck_grp_ *)&lck_grp_queue
1484 set $kgm_mtxgrp_ptr = (struct _lck_grp_ *)$kgm_mtxgrp_ptr->lck_grp_link.next
1485 while ($kgm_mtxgrp_ptr != (struct _lck_grp_ *)&lck_grp_queue)
1486 showmtxgrp $kgm_mtxgrp_ptr
1487 set $kgm_mtxgrp_ptr = (struct _lck_grp_ *)$kgm_mtxgrp_ptr->lck_grp_link.next
1492 Syntax: (gdb) showallmtx
1493 | Routine to print a summary listing of all mutexes
1497 set $kgm_rwlckgrp = (struct _lck_grp_ *)$arg0
1499 if ($kgm_rwlckgrp->lck_grp_rwcnt)
1500 printf "0x%08x ", $kgm_rwlckgrp
1501 printf "%8d ",$kgm_rwlckgrp->lck_grp_rwcnt
1502 printf "%12u ",$kgm_rwlckgrp->lck_grp_stat.lck_grp_rw_stat.lck_grp_rw_util_cnt
1503 printf "%8u ",$kgm_rwlckgrp->lck_grp_stat.lck_grp_rw_stat.lck_grp_rw_miss_cnt
1504 printf "%8u ",$kgm_rwlckgrp->lck_grp_stat.lck_grp_rw_stat.lck_grp_rw_wait_cnt
1505 printf "%s ",&$kgm_rwlckgrp->lck_grp_name
1512 printf "LCK GROUP CNT UTIL MISS WAIT NAME\n"
1513 set $kgm_rwlckgrp_ptr = (struct _lck_grp_ *)&lck_grp_queue
1514 set $kgm_rwlckgrp_ptr = (struct _lck_grp_ *)$kgm_rwlckgrp_ptr->lck_grp_link.next
1515 while ($kgm_rwlckgrp_ptr != (struct _lck_grp_ *)&lck_grp_queue)
1516 showrwlckgrp $kgm_rwlckgrp_ptr
1517 set $kgm_rwlckgrp_ptr = (struct _lck_grp_ *)$kgm_rwlckgrp_ptr->lck_grp_link.next
1521 document showallrwlck
1522 Syntax: (gdb) showallrwlck
1523 | Routine to print a summary listing of all read/writer locks
1526 set $kdp_act_counter = 0
1545 define showcontext_int
1546 echo Context switched, current instruction pointer:
1552 set $newact = (struct thread *) $arg0
1554 if ($newact->kernel_stack == 0)
1555 echo This activation does not have a stack.\n
1557 output/a (unsigned) $newact.continuation
1560 if ($kgm_mtype == 18)
1561 if ($kdp_act_counter == 0)
1562 set $kdpstate = (struct savearea *) kdp.saved_state
1564 set $kdp_act_counter = $kdp_act_counter + 1
1565 set (struct savearea *) kdp.saved_state=$newact->machine->pcb
1568 set $pc=$newact->machine->pcb.save_srr0
1571 if ($kgm_mtype == 7)
1572 set $kdpstatep = (struct x86_saved_state32 *) kdp.saved_state
1573 if ($kdp_act_counter == 0)
1574 set $kdpstate = *($kdpstatep)
1576 set $kdp_act_counter = $kdp_act_counter + 1
1578 set $kgm_statep = (struct x86_kernel_state32 *) \
1579 ($newact->kernel_stack + 0x4000 \
1580 - sizeof(struct x86_kernel_state32))
1581 set $kdpstatep->ebx = $kgm_statep->k_ebx
1582 set $kdpstatep->ebp = $kgm_statep->k_ebp
1583 set $kdpstatep->edi = $kgm_statep->k_edi
1584 set $kdpstatep->esi = $kgm_statep->k_esi
1585 set $kdpstatep->eip = $kgm_statep->k_eip
1588 set $pc = $kgm_statep->k_eip
1591 if ($kgm_mtype == 12)
1602 set $r10_save = $r10
1603 set $r11_save = $r11
1604 set $r12_save = $r12
1608 set $pc_ctx = load_reg+8
1609 set $kgm_statep = (struct arm_saved_state *)((struct thread*)$arg0)->machine.kstackptr
1610 set $r0 = $kgm_statep->r[0]
1611 set $r1 = $kgm_statep->r[1]
1612 set $r2 = $kgm_statep->r[2]
1613 set $r3 = $kgm_statep->r[3]
1614 set $r4 = $kgm_statep->r[4]
1615 set $r5 = $kgm_statep->r[5]
1616 set $r6 = $kgm_statep->r[6]
1617 set $r8 = $kgm_statep->r[8]
1618 set $r9 = $kgm_statep->r[9]
1619 set $r10 = $kgm_statep->r[10]
1620 set $r11 = $kgm_statep->r[11]
1621 set $r12 = $kgm_statep->r[12]
1622 set $sp = $kgm_statep->sp
1623 set $lr = $kgm_statep->lr
1625 set $r7 = $kgm_statep->r[7]
1633 document switchtoact
1634 Syntax: switchtoact <address of activation>
1635 | This command allows gdb to examine the execution context and call
1636 | stack for the specified activation. For example, to view the backtrace
1637 | for an activation issue "switchtoact <address>", followed by "bt".
1638 | Before resuming execution, issue a "resetctx" command, to
1639 | return to the original execution context.
1644 if ($kgm_mtype == 18)
1645 if ($kdp_act_counter == 0)
1646 set $kdpstate = (struct savearea *) kdp.saved_state
1648 set $kdp_act_counter = $kdp_act_counter + 1
1649 set (struct savearea *) kdp.saved_state=(struct savearea *) $arg0
1652 set $pc=((struct savearea *) $arg0)->save_srr0
1655 if ($kgm_mtype == 12)
1666 set $r10_save = $r10
1667 set $r11_save = $r11
1668 set $r12_save = $r12
1672 set $kgm_statep = (struct arm_saved_state *)$arg0
1673 set $r0 = $kgm_statep->r[0]
1674 set $r1 = $kgm_statep->r[1]
1675 set $r2 = $kgm_statep->r[2]
1676 set $r3 = $kgm_statep->r[3]
1677 set $r4 = $kgm_statep->r[4]
1678 set $r5 = $kgm_statep->r[5]
1679 set $r6 = $kgm_statep->r[6]
1680 set $r8 = $kgm_statep->r[8]
1681 set $r9 = $kgm_statep->r[9]
1682 set $r10 = $kgm_statep->r[10]
1683 set $r11 = $kgm_statep->r[11]
1684 set $r12 = $kgm_statep->r[12]
1685 set $sp = $kgm_statep->sp
1686 set $lr = $kgm_statep->lr
1687 set $r7 = $kgm_statep->r[7]
1688 set $pc = $kgm_statep->pc
1693 echo switchtoctx not implemented for this architecture.\n
1697 document switchtoctx
1698 Syntax: switchtoctx <address of pcb>
1699 | This command allows gdb to examine an execution context and dump the
1700 | backtrace for this execution context.
1701 | Before resuming execution, issue a "resetctx" command, to
1702 | return to the original execution context.
1707 if ($kdp_act_counter != 0)
1708 if ($kgm_mtype == 18)
1709 set (struct savearea *)kdp.saved_state=$kdpstate
1712 set $pc=((struct savearea *) kdp.saved_state)->save_srr0
1714 set $kdp_act_counter = 0
1716 if ($kgm_mtype == 7)
1717 set $kdpstatep = (struct x86_saved_state32 *) kdp.saved_state
1718 set *($kdpstatep)=$kdpstate
1721 set $pc=$kdpstatep->eip
1723 set $kdp_act_counter = 0
1725 if ($kgm_mtype == 12)
1744 set $r10 = $r10_save
1746 set $r11 = $r11_save
1748 set $r12 = $r12_save
1765 | Returns to the original execution context. This command should be
1766 | issued if you wish to resume execution after using the "switchtoact"
1767 | or "switchtoctx" commands.
1770 # This is a pre-hook for the continue command, to prevent inadvertent attempts
1771 # to resume from the context switched to for examination.
1772 define hook-continue
1776 # This is a pre-hook for the detach command, to prevent inadvertent attempts
1777 # to resume from the context switched to for examination.
1783 set noresume_on_disconnect = 0
1788 | The target system will resume when detaching or exiting from gdb.
1789 | This is the default behavior.
1793 set noresume_on_disconnect = 1
1797 | Syntax: resume_off
1798 | The target system won't resume after detaching from gdb and
1799 | can be attached with a new gdb session
1803 set $kgm_panic_bufptr = debug_buf
1804 set $kgm_panic_bufptr_max = debug_buf_ptr
1805 while $kgm_panic_bufptr < $kgm_panic_bufptr_max
1806 if *(char *)$kgm_panic_bufptr == 10
1809 printf "%c", *$kgm_panic_bufptr
1811 set $kgm_panic_bufptr= (char *)$kgm_panic_bufptr + 1
1817 | Display the panic log information
1821 define dumpcallqueue
1822 set $kgm_callhead = (queue_t)&$arg0
1823 set $kgm_call = (struct call_entry *)$kgm_callhead.next
1825 while $kgm_call != $kgm_callhead
1826 printf "0x%08x ", $kgm_call
1827 printf "0x%08x 0x%08x ", $kgm_call->param0, $kgm_call->param1
1828 output $kgm_call->state
1830 output $kgm_call->deadline
1832 output $kgm_call->func
1834 set $kgm_i = $kgm_i + 1
1835 set $kgm_call = (struct call_entry *)$kgm_call->q_link.next
1837 printf "%d entries\n", $kgm_i
1840 document dumpcallqueue
1841 | Syntax: dumpcallqueue <queue head>
1842 | Displays the contents of the specified call_entry queue.
1846 showtaskthreads $arg0
1848 document showtaskacts
1849 | See help showtaskthreads.
1855 document showallacts
1856 | See help showallthreads.
1871 document resetstacks
1872 | Syntax: resetstacks
1873 | Internal kgmacro routine used by the "showuserstack" macro
1874 | to reset the target pmap to the kernel pmap.
1877 #Barely effective hacks to work around bugs in the "flush" and "update"
1878 #gdb commands in Tiger (up to 219); these aren't necessary with Panther
1879 #gdb, but do no harm.
1880 define _kgm_flush_loop
1881 set $kgm_flush_loop_ctr = 0
1882 while ($kgm_flush_loop_ctr < 30)
1885 set $kgm_flush_loop_ctr = $kgm_flush_loop_ctr + 1
1889 define _kgm_update_loop
1890 set $kgm_update_loop_ctr = 0
1891 while ($kgm_update_loop_ctr < 30)
1893 set $kgm_update_loop_ctr = $kgm_update_loop_ctr + 1
1897 #This is necessary since gdb often doesn't do backtraces on x86 correctly
1898 #in the absence of symbols.The code below in showuserstack and
1899 #showx86backtrace also contains several workarouds for the gdb bug where
1900 #gdb stops macro evaluation because of spurious "Cannot read memory"
1901 #errors on x86. These errors appear on ppc as well, but they don't
1902 #always stop macro evaluation.
1904 set $kgm_cur_ebp = 0
1905 set $kgm_cur_eip = 0
1907 define showx86backtrace
1908 if ($kgm_cur_ebp == 0)
1909 set $kgm_cur_ebp = $ebp
1911 if ($kgm_cur_eip == 0)
1912 set $kgm_cur_eip = $eip
1914 printf "0: EBP: 0x%08x EIP: 0x%08x\n", $kgm_cur_ebp, $kgm_cur_eip
1916 set $kgm_prev_ebp = *((uint32_t *) $kgm_cur_ebp)
1917 set $kgm_prev_eip = *((uint32_t *) ($kgm_cur_ebp + 4))
1918 set $kgm_cur_ebp = 0
1919 set $kgm_cur_eip = 0
1920 set $kgm_frameno = 1
1921 while $kgm_prev_ebp != 0
1922 printf "%d: saved EBP: 0x%08x saved EIP: 0x%08x\n", $kgm_frameno, $kgm_prev_ebp, $kgm_prev_eip
1924 set $kgm_prev_eip = *((uint32_t *) ($kgm_prev_ebp + 4))
1925 set $kgm_prev_ebp = *((uint32_t *) $kgm_prev_ebp)
1926 set $kgm_frameno = $kgm_frameno + 1
1931 define showuserstack
1933 if ($kgm_mtype == 18)
1934 if ($kdp_act_counter == 0)
1935 set $kdpstate = (struct savearea *) kdp.saved_state
1937 set $kdp_act_counter = $kdp_act_counter + 1
1938 set $newact = (struct thread *) $arg0
1940 set $checkpc = $newact->machine->upcb.save_srr0
1942 echo This activation does not appear to have
1943 echo \20 a valid user context.\n
1945 set (struct savearea *) kdp.saved_state=$newact->machine->upcb
1947 #flush and update seem to be executed lazily by gdb on Tiger, hence the
1948 #repeated invocations - see 3743135
1950 # This works because the new pmap is used only for reads
1951 set kdp_pmap = $newact->task->map->pmap
1963 set $newact = (struct thread *) $arg0
1964 #This needs to identify 64-bit processes as well
1965 set $newiss = (x86_saved_state32_t) ($newact->machine.pcb->iss.uss.ss_32)
1966 set $checkpc = $newiss.eip
1968 echo This activation does not appear to have
1969 echo \20 a valid user context.\n
1971 set $kgm_cur_ebp = $newiss.ebp
1972 set $kgm_cur_eip = $checkpc
1973 printf "You may now issue the showx86backtrace command to see the user space backtrace for this thread (0x%08x); you can also examine memory locations in this address space (pmap 0x%08x) before issuing the backtrace. This two-step process is necessary to work around various bugs in x86 gdb, which cause it to stop memory evaluation on spurious memory read errors. Additionally, you may need to issue a set kdp_pmap = 0 command after the showx86backtrace completes, to resume reading from the kernel address space.\n", $arg0, $newact->task->map->pmap
1974 set kdp_pmap = $newact->task->map->pmap
1980 document showuserstack
1981 Syntax: showuserstack <address of thread activation>
1982 |This command displays a numeric backtrace for the user space stack of
1983 |the given thread activation. It may, of course, fail to display a
1984 |complete backtrace if portions of the user stack are not mapped in.
1985 |Symbolic backtraces can be obtained either by running gdb on the
1986 |user space binary, or a tool such as "symbolicate".
1987 |Note that while this command works on Panther's gdb, an issue
1988 |with Tiger gdb (3743135) appears to hamper the evaluation of this
1989 |macro in some cases.
1992 #Stopgap until gdb can generate the HOSTREBOOT packet
1994 #Alternatively, set *(*(unsigned **) 0x2498) = 1 (or 0x5498 on PPC)
1995 set flag_kdp_trigger_reboot = 1
2001 |Reboot the remote target machine; not guaranteed to succeed. Requires symbols
2002 |until gdb support for the HOSTREBOOT packet is implemented.
2006 set kdp_trigger_core_dump = 1
2007 set kdp_flag |= 0x40
2008 set panicd_ip_str = "$arg0"
2009 set panicd_specified = 1
2010 set disable_debug_output = 0
2011 set disableConsoleOutput = 0
2012 set logPanicDataToScreen = 1
2013 set reattach_wait = 1
2018 Syntax: sendcore <IP address>
2019 |Configure the kernel to transmit a kernel coredump to a server (kdumpd)
2020 |at the specified IP address. This is useful when the remote target has
2021 |not been previously configured to transmit coredumps, and you wish to
2022 |preserve kernel state for later examination. NOTE: You must issue a "continue"
2023 |command after using this macro to trigger the kernel coredump. The kernel
2024 |will resume waiting in the debugger after completion of the coredump. You
2025 |may disable coredumps by executing the "disablecore" macro.
2029 set kdp_trigger_core_dump = 0
2030 set kdp_flag |= 0x40
2031 set kdp_flag &= ~0x10
2032 set panicd_specified = 0
2035 document disablecore
2037 |Reconfigures the kernel so that it no longer transmits kernel coredumps. This
2038 |complements the "sendcore" macro, but it may be used if the kernel has been
2039 |configured to transmit coredumps through boot-args as well.
2042 define switchtocorethread
2043 set $newact = (struct thread *) $arg0
2045 if ($newact->kernel_stack == 0)
2046 echo This thread does not have a stack.\n
2048 output/a (unsigned) $newact.continuation
2051 if ($kgm_mtype == 18)
2052 loadcontext $newact->machine->pcb
2054 set $pc = $newact->machine->pcb.save_srr0
2056 set $kgm_cstatep = (struct x86_kernel_state32 *) \
2057 ($newact->kernel_stack + 0x4000 \
2058 - sizeof(struct x86_kernel_state32))
2059 loadcontext $kgm_cstatep
2066 document switchtocorethread
2067 Syntax: switchtocorethread <address of activation>
2068 | The corefile equivalent of "switchtoact". When debugging a kernel coredump
2069 | file, this command can be used to examine the execution context and stack
2070 | trace for a given thread activation. For example, to view the backtrace
2071 | for a thread issue "switchtocorethread <address>", followed by "bt".
2072 | Before resuming execution, issue a "resetcorectx" command, to
2073 | return to the original execution context. Note that this command
2074 | requires gdb support, as documented in Radar 3401283.
2079 if ($kgm_mtype == 18)
2080 set $kgm_contextp = (struct savearea *) $arg0
2081 set $pc = $kgm_contextp.save_srr0
2082 set $r1 = $kgm_contextp.save_r1
2083 set $lr = $kgm_contextp.save_lr
2085 set $r2 = $kgm_contextp.save_r2
2086 set $r3 = $kgm_contextp.save_r3
2087 set $r4 = $kgm_contextp.save_r4
2088 set $r5 = $kgm_contextp.save_r5
2089 set $r6 = $kgm_contextp.save_r6
2090 set $r7 = $kgm_contextp.save_r7
2091 set $r8 = $kgm_contextp.save_r8
2092 set $r9 = $kgm_contextp.save_r9
2093 set $r10 = $kgm_contextp.save_r10
2094 set $r11 = $kgm_contextp.save_r11
2095 set $r12 = $kgm_contextp.save_r12
2096 set $r13 = $kgm_contextp.save_r13
2097 set $r14 = $kgm_contextp.save_r14
2098 set $r15 = $kgm_contextp.save_r15
2099 set $r16 = $kgm_contextp.save_r16
2100 set $r17 = $kgm_contextp.save_r17
2101 set $r18 = $kgm_contextp.save_r18
2102 set $r19 = $kgm_contextp.save_r19
2103 set $r20 = $kgm_contextp.save_r20
2104 set $r21 = $kgm_contextp.save_r21
2105 set $r22 = $kgm_contextp.save_r22
2106 set $r23 = $kgm_contextp.save_r23
2107 set $r24 = $kgm_contextp.save_r24
2108 set $r25 = $kgm_contextp.save_r25
2109 set $r26 = $kgm_contextp.save_r26
2110 set $r27 = $kgm_contextp.save_r27
2111 set $r28 = $kgm_contextp.save_r28
2112 set $r29 = $kgm_contextp.save_r29
2113 set $r30 = $kgm_contextp.save_r30
2114 set $r31 = $kgm_contextp.save_r31
2116 set $cr = $kgm_contextp.save_cr
2117 set $ctr = $kgm_contextp.save_ctr
2119 set $kgm_contextp = (struct x86_kernel_state32 *) $arg0
2120 set $ebx = $kgm_contextp->k_ebx
2121 set $ebp = $kgm_contextp->k_ebp
2122 set $edi = $kgm_contextp->k_edi
2123 set $esi = $kgm_contextp->k_esi
2124 set $eip = $kgm_contextp->k_eip
2125 set $pc = $kgm_contextp->k_eip
2131 if ($kgm_mtype == 18)
2132 set $kgm_corecontext = (struct savearea *) kdp.saved_state
2133 loadcontext $kgm_corecontext
2135 if ($kgm_mtype == 7)
2136 set $kdpstatep = (struct x86_saved_state32 *) kdp.saved_state
2137 set $ebx = $kdpstatep->ebx
2138 set $ebp = $kdpstatep->ebp
2139 set $edi = $kdpstatep->edi
2140 set $esi = $kdpstatep->esi
2141 set $eip = $kdpstatep->eip
2142 set $eax = $kdpstatep->eax
2143 set $ecx = $kdpstatep->ecx
2144 set $edx = $kdpstatep->edx
2147 set $pc = $kdpstatep->eip
2154 document resetcorectx
2155 Syntax: resetcorectx
2156 | The corefile equivalent of "resetctx". Returns to the original
2157 | execution context (that of the active thread at the time of the NMI or
2158 | panic). This command should be issued if you wish to resume
2159 | execution after using the "switchtocorethread" command.
2162 #Helper function for "showallgdbstacks"
2164 define showgdbthread
2165 printf " 0x%08x ", $arg0
2166 set $kgm_thread = *(struct thread *)$arg0
2167 printf "0x%08x ", $arg0
2168 printf "%3d ", $kgm_thread.sched_pri
2169 set $kgm_state = $kgm_thread.state
2170 if $kgm_state & 0x80
2173 if $kgm_state & 0x40
2176 if $kgm_state & 0x20
2179 if $kgm_state & 0x10
2182 if $kgm_state & 0x08
2185 if $kgm_state & 0x04
2188 if $kgm_state & 0x02
2191 if $kgm_state & 0x01
2193 printf "0x%08x ", $kgm_thread.wait_queue
2194 output /a (unsigned) $kgm_thread.wait_event
2195 if ($kgm_thread.uthread != 0)
2196 set $kgm_uthread = (struct uthread *)$kgm_thread.uthread
2197 if ($kgm_uthread->uu_wmesg != 0)
2198 printf " \"%s\"", $kgm_uthread->uu_wmesg
2203 if ($kgm_thread.kernel_stack != 0)
2204 if ($kgm_thread.reserved_stack != 0)
2205 printf "\n\t\treserved_stack=0x%08x", $kgm_thread.reserved_stack
2207 printf "\n\t\tkernel_stack=0x%08x", $kgm_thread.kernel_stack
2208 if ($kgm_mtype == 18)
2209 set $mysp = $kgm_thread.machine.pcb->save_r1
2211 if ($kgm_mtype == 7)
2212 set $kgm_statep = (struct x86_kernel_state32 *) \
2213 ($kgm_thread->kernel_stack + 0x4000 \
2214 - sizeof(struct x86_kernel_state32))
2215 set $mysp = $kgm_statep->k_ebp
2217 if ($kgm_mtype == 12)
2221 set $kgm_statep = (struct arm_saved_state *)$kgm_thread.machine.kstackptr
2222 set $mysp = $kgm_statep->r[7]
2226 printf "\n\t\tstacktop=0x%08x", $mysp
2230 switchtocorethread $arg0
2234 printf "\n\t\t\tcontinuation="
2235 output /a (unsigned) $kgm_thread.continuation
2243 #Use of this macro is currently (8/04) blocked by the fact that gdb
2244 #stops evaluating macros when encountering an error, such as a failure
2245 #to read memory from a certain location. Until this issue (described in
2246 #3758949) is addressed, evaluation of this macro may stop upon
2247 #encountering such an error.
2249 define showallgdbstacks
2250 set $kgm_head_taskp = &tasks
2251 set $kgm_taskp = (struct task *)($kgm_head_taskp->next)
2252 while $kgm_taskp != $kgm_head_taskp
2254 showtaskint $kgm_taskp
2255 set $kgm_head_actp = &($kgm_taskp->threads)
2256 set $kgm_actp = (struct thread *)($kgm_taskp->threads.next)
2257 while $kgm_actp != $kgm_head_actp
2259 showgdbthread $kgm_actp 1 0
2260 set $kgm_actp = (struct thread *)($kgm_actp->task_threads.next)
2263 set $kgm_taskp = (struct task *)($kgm_taskp->tasks.next)
2268 document showallgdbstacks
2269 Syntax: showallgdbstacks
2270 | An alternative to "showallstacks". Iterates through the task list and
2271 | displays a gdb generated backtrace for each kernel thread. It is
2272 | advantageous in that it is much faster than "showallstacks", and
2273 | decodes function call arguments and displays source level traces, but
2274 | it has the drawback that it doesn't determine if frames belong to
2275 | functions from kernel extensions, as with "showallstacks".
2276 | This command may terminate prematurely because of a gdb bug
2277 | (Radar 3758949), which stops macro evaluation on memory read
2281 define showallgdbcorestacks
2283 set $kgm_head_taskp = &tasks
2284 set $kgm_taskp = (struct task *)($kgm_head_taskp->next)
2285 while $kgm_taskp != $kgm_head_taskp
2287 showtaskint $kgm_taskp
2288 set $kgm_head_actp = &($kgm_taskp->threads)
2289 set $kgm_actp = (struct thread *)($kgm_taskp->threads.next)
2290 while $kgm_actp != $kgm_head_actp
2292 showgdbthread $kgm_actp 1 1
2293 set $kgm_actp = (struct thread *)($kgm_actp->task_threads.next)
2296 set $kgm_taskp = (struct task *)($kgm_taskp->tasks.next)
2302 document showallgdbcorestacks
2303 Syntax: showallgdbcorestacks
2304 |Corefile version of "showallgdbstacks"
2308 define switchtouserthread
2310 if ($kgm_mtype == 18)
2311 if ($kdp_act_counter == 0)
2312 set $kdpstate = (struct savearea *) kdp.saved_state
2314 set $kdp_act_counter = $kdp_act_counter + 1
2315 set $newact = (struct thread *) $arg0
2317 set $checkpc = $newact->machine->upcb.save_srr0
2319 echo This activation does not appear to have
2320 echo \20 a valid user context.\n
2322 set (struct savearea *) kdp.saved_state=$newact->machine->upcb
2324 #flush and update seem to be executed lazily by gdb on Tiger, hence the
2325 #repeated invocations - see 3743135
2327 # This works because the new pmap is used only for reads
2328 set kdp_pmap = $newact->task->map->pmap
2333 echo switchtouserthread not implemented for this architecture.\n
2337 document switchtouserthread
2338 Syntax: switchtouserthread <address of thread>
2339 | Analogous to switchtoact, but switches to the user context of a
2340 | specified thread address. Similar to the "showuserstack"
2341 | command, but this command does not return gdb to the kernel context
2342 | immediately. This is to assist with the following (rather risky)
2343 | manoeuvre - upon switching to the user context and virtual address
2344 | space, the user may choose to call remove-symbol-file on the
2345 | mach_kernel symbol file, and then add-symbol-file on the user space
2346 | binary's symfile. gdb can then generate symbolic backtraces
2347 | for the user space thread. To return to the
2348 | kernel context and virtual address space, the process must be
2349 | reversed, i.e. call remove-symbol-file on the user space symbols, and
2350 | then add-symbol-file on the appropriate mach_kernel, and issue the
2351 | "resetstacks" command. Note that gdb may not react kindly to all these
2352 | symbol file switches. The same restrictions that apply to "showuserstack"
2353 | apply here - pages that have been paged out cannot be read while in the
2354 | debugger context, so backtraces may terminate early.
2355 | If the virtual addresses in the stack trace do not conflict with those
2356 | of symbols in the kernel's address space, it may be sufficient to
2357 | just do an add-symbol-file on the user space binary's symbol file.
2358 | Note that while this command works on Panther's gdb, an issue
2359 | with Tiger gdb (3743135) appears to hamper the evaluation of this
2360 | macro in some cases.
2363 define showmetaclass
2364 set $kgm_metaclassp = (OSMetaClass *)$arg0
2365 printf "%-5d", $kgm_metaclassp->instanceCount
2366 printf "x %5d bytes", $kgm_metaclassp->classSize
2367 printf " %s\n", $kgm_metaclassp->className->string
2371 printf "\"%s\"", ((OSString *)$arg0)->string
2375 printf "%lld", ((OSNumber *)$arg0)->value
2379 if ($arg0 == gOSBooleanFalse)
2387 set $kgm_data = (OSData *)$arg0
2390 set $kgm_datap = (const unsigned char *) $kgm_data->data
2392 set $kgm_printstr = 0
2393 if (0 == (3 & (unsigned int)$kgm_datap) && ($kgm_data->length >= 3))
2394 set $kgm_bytes = *(unsigned int *) $kgm_datap
2395 if (0xffff0000 & $kgm_bytes)
2397 set $kgm_printstr = 1
2398 while ($kgm_idx++ < 4)
2399 set $kgm_bytes = $kgm_bytes >> 8
2400 set $kgm_char = 0xff & $kgm_bytes
2401 if ($kgm_char && (($kgm_char < 0x20) || ($kgm_char > 0x7e)))
2402 set $kgm_printstr = 0
2411 while ($kgm_idx < $kgm_data->length)
2412 set $kgm_char = $kgm_datap[$kgm_idx++]
2414 if (0 == $kgm_quoted)
2422 printf "%c", $kgm_char
2434 if (0 == (3 & (unsigned int)$kgm_datap))
2435 while (($kgm_idx + 3) <= $kgm_data->length)
2436 printf "%08x", *(unsigned int *) &$kgm_datap[$kgm_idx]
2437 set $kgm_idx = $kgm_idx + 4
2440 while ($kgm_idx < $kgm_data->length)
2441 printf "%02x", $kgm_datap[$kgm_idx++]
2447 define showdictionaryint
2448 set $kgm$arg0_dict = (OSDictionary *)$arg1
2451 set $kgm$arg0_idx = 0
2452 while ($kgm$arg0_idx < $kgm$arg0_dict->count)
2453 set $kgm_obj = $kgm$arg0_dict->dictionary[$kgm$arg0_idx].key
2454 showobjectint _$arg0 $kgm_obj
2456 set $kgm_obj = $kgm$arg0_dict->dictionary[$kgm$arg0_idx++].value
2457 showobjectint _$arg0 $kgm_obj
2458 if ($kgm$arg0_idx < $kgm$arg0_dict->count)
2467 while ($kgm_idx < $arg0)
2468 if ($arg1 & (1 << $kgm_idx++))
2476 define showregdictionary
2477 indent $kgm_reg_depth+2 $arg1
2480 set $kgm_reg_idx = 0
2481 while ($kgm_reg_idx < $arg0->count)
2482 indent $kgm_reg_depth+2 $arg1
2484 set $kgm_obj = $arg0->dictionary[$kgm_reg_idx].key
2485 showobjectint _ $kgm_obj
2488 set $kgm_obj = $arg0->dictionary[$kgm_reg_idx++].value
2489 showobjectint _ $kgm_obj
2492 indent $kgm_reg_depth+2 $arg1
2497 define showarraysetint
2498 set $kgm$arg0_array = (OSArray *)$arg1
2500 set $kgm$arg0_idx = 0
2501 while ($kgm$arg0_idx < $kgm$arg0_array->count)
2502 set $kgm_obj = $kgm$arg0_array->array[$kgm$arg0_idx++]
2503 showobjectint _$arg0 $kgm_obj
2504 if ($kgm$arg0_idx < $kgm$arg0_array->count)
2512 showarraysetint $arg0 $arg1
2517 set $kgm_array = ((OSSet *)$arg1)->members
2519 showarraysetint $arg0 $kgm_array
2524 define showobjectint
2525 set $kgm_obj = (OSObject *) $arg1
2526 set $kgm_vt = *((void **) $arg1)
2528 if ($kgm_show_object_addrs)
2529 printf "`object %p, vt ", $arg1
2530 output /a (unsigned) $kgm_vt
2531 if ($kgm_show_object_retain)
2532 printf ", retain count %d, container retain %d", (0xffff & $kgm_obj->retainCount), $kgm_obj->retainCount >> 16
2537 if ($kgm_vt == _ZTV8OSString)
2540 if ($kgm_vt == _ZTV8OSSymbol)
2543 if ($kgm_vt == _ZTV8OSNumber)
2546 if ($kgm_vt == _ZTV6OSData)
2549 if ($kgm_vt == _ZTV9OSBoolean)
2552 if ($kgm_vt == _ZTV12OSDictionary)
2553 showdictionaryint _$arg0 $arg1
2555 if ($kgm_vt == _ZTV7OSArray)
2556 showarrayint _$arg0 $arg1
2558 if ($kgm_vt == _ZTV5OSSet)
2559 showsetint _$arg0 $arg1
2561 if ($kgm_show_object_addrs == 0)
2562 printf "`object %p, vt ", $arg1
2563 output /a (unsigned) $kgm_vt
2577 set $kgm_save = $kgm_show_object_addrs
2578 set $kgm_show_object_addrs = 1
2579 set $kgm_show_object_retain = 1
2580 showobjectint _ $arg0
2581 set $kgm_show_object_addrs = $kgm_save
2582 set $kgm_show_object_retain = 0
2586 Syntax: (gdb) showobject <object address>
2587 | Show info about an OSObject - its vtable ptr and retain count.
2588 | If the object is a simple container class, more info will be shown.
2592 set $kgm_dictp = (OSDictionary *)$arg0
2593 set $kgm_keyp = (const OSSymbol *)$arg1
2596 while (($kgm_idx < $kgm_dictp->count) && ($kgm_result == 0))
2597 if ($kgm_keyp == $kgm_dictp->dictionary[$kgm_idx].key)
2598 set $kgm_result = $kgm_dictp->dictionary[$kgm_idx].value
2600 set $kgm_idx = $kgm_idx + 1
2605 define showregistryentryrecurse
2606 set $kgm_re = (IOService *)$arg1
2607 set $kgm$arg0_stack = (unsigned long long) $arg2
2610 set $kgm$arg0_stack = $kgm$arg0_stack | (1ULL << $kgm_reg_depth)
2612 set $kgm$arg0_stack = $kgm$arg0_stack & ~(1ULL << $kgm_reg_depth)
2615 dictget $kgm_re->fRegistryTable $kgm_childkey
2616 set $kgm$arg0_child_array = (OSArray *) $kgm_result
2618 if ($kgm$arg0_child_array)
2619 set $kgm$arg0_child_count = $kgm$arg0_child_array->count
2621 set $kgm$arg0_child_count = 0
2624 if ($kgm$arg0_child_count)
2625 set $kgm$arg0_stack = $kgm$arg0_stack | (2ULL << $kgm_reg_depth)
2627 set $kgm$arg0_stack = $kgm$arg0_stack & ~(2ULL << $kgm_reg_depth)
2630 indent $kgm_reg_depth $kgm$arg0_stack
2633 dictget $kgm_re->fRegistryTable $kgm_namekey
2634 if ($kgm_result == 0)
2635 dictget $kgm_re->fRegistryTable gIONameKey
2637 if ($kgm_result == 0)
2638 dictget $kgm_re->fPropertyTable gIOClassKey
2641 if ($kgm_result != 0)
2642 printf "%s", ((OSString *)$kgm_result)->string
2644 if (((IOService*)$kgm_re)->pwrMgt && ((IOService*)$kgm_re)->pwrMgt->Name)
2645 printf "%s", ((IOService*)$kgm_re)->pwrMgt->Name
2647 # printf ", guessclass "
2648 # guessclass $kgm_re
2654 printf " <object %p, ", $kgm_re
2656 set $kgm_vt = (unsigned) *(void**) $kgm_re
2659 if ($kgm_vt != _ZTV15IORegistryEntry)
2661 set $kgm_state = $kgm_re->__state[0]
2662 # kIOServiceRegisteredState
2663 if (0 == ($kgm_state & 2))
2666 printf "registered, "
2667 # kIOServiceMatchedState
2668 if (0 == ($kgm_state & 4))
2672 # kIOServiceInactiveState
2676 printf "active, busy %d, retain count %d", (0xff & $kgm_re->__state[1]), (0xffff & $kgm_re->retainCount)
2680 if ($kgm_show_props)
2681 set $kgm_props = $kgm_re->fPropertyTable
2682 showregdictionary $kgm_props $kgm$arg0_stack
2686 if ($kgm$arg0_child_count != 0)
2688 set $kgm_reg_depth = $kgm_reg_depth + 1
2689 set $kgm$arg0_child_idx = 0
2691 while ($kgm$arg0_child_idx < $kgm$arg0_child_count)
2692 set $kgm_re = $kgm$arg0_child_array->array[$kgm$arg0_child_idx++]
2693 set $kgm_more_sib = ($kgm$arg0_child_idx < $kgm$arg0_child_count)
2694 showregistryentryrecurse _$arg0 $kgm_re $kgm$arg0_stack $kgm_more_sib
2697 set $kgm_reg_depth = $kgm_reg_depth - 1
2701 define showregistryentryint
2702 set $kgm_namekey = (OSSymbol *) $kgm_reg_plane[2]
2703 set $kgm_childkey = (OSSymbol *) $kgm_reg_plane[4]
2705 showregistryentryrecurse _ $arg0 0 0
2709 set $kgm_reg_depth = 0
2710 set $kgm_show_props = 0
2711 showregistryentryint gRegistryRoot
2713 document showregistry
2714 Syntax: (gdb) showregistry
2715 | Show info about all registry entries in the current plane.
2718 define showregistryprops
2719 set $kgm_reg_depth = 0
2720 set $kgm_show_props = 1
2721 showregistryentryint gRegistryRoot
2723 document showregistryprops
2724 Syntax: (gdb) showregistryprops
2725 | Show info about all registry entries in the current plane, and their properties.
2726 | set $kgm_show_object_addrs = 1 and/or set $kgm_show_object_retain = 1 will display
2727 | more verbose information
2730 define showregistryentry
2731 set $kgm_reg_depth = 0
2732 set $kgm_show_props = 1
2733 showregistryentryint $arg0
2735 document showregistryentry
2736 Syntax: (gdb) showregistryentry <object address>
2737 | Show info about a registry entry; its properties and descendants in the current plane.
2740 define setregistryplane
2742 set $kgm_reg_plane = (void **) $arg0
2744 showobjectint _ gIORegistryPlanes
2748 document setregistryplane
2749 Syntax: (gdb) setregistryplane <plane object address>
2750 | Set the plane to be used for the iokit registry macros. An argument of zero will
2751 | display known planes.
2755 set $kgm_classidx = 0
2756 set $kgm_lookvt = *((void **) $arg0)
2757 set $kgm_bestvt = (void *) 0
2758 set $kgm_bestidx = 0
2760 while $kgm_classidx < sAllClassesDict->count
2761 set $kgm_meta = (OSMetaClass *) sAllClassesDict->dictionary[$kgm_classidx].value
2763 set $kgm_vt = *((void **) $kgm_meta)
2765 if (($kgm_vt > $kgm_bestvt) && ($kgm_vt < $kgm_lookvt))
2766 set $kgm_bestvt = $kgm_vt
2767 set $kgm_bestidx = $kgm_classidx
2769 set $kgm_classidx = $kgm_classidx + 1
2771 printf "%s", sAllClassesDict->dictionary[$kgm_bestidx].key->string
2774 define showallclasses
2775 set $kgm_classidx = 0
2776 while $kgm_classidx < sAllClassesDict->count
2777 set $kgm_meta = (OSMetaClass *) sAllClassesDict->dictionary[$kgm_classidx++].value
2778 showmetaclass $kgm_meta
2782 document showallclasses
2783 Syntax: (gdb) showallclasses
2784 | Show the instance counts and ivar size of all OSObject subclasses. See ioclasscount man page for details.
2788 printf " Instance allocation = 0x%08lx = %4ld K\n", (int) debug_ivars_size, ((int) debug_ivars_size) / 1024
2789 printf "Container allocation = 0x%08lx = %4ld K\n", (int) debug_container_malloc_size, ((int) debug_container_malloc_size) / 1024
2790 printf " IOMalloc allocation = 0x%08lx = %4ld K\n", (int) debug_iomalloc_size, ((int) debug_iomalloc_size) / 1024
2791 printf " Pageable allocation = 0x%08lx = %4ld K\n", (vm_size_t) debug_iomallocpageable_size, ((vm_size_t) debug_iomallocpageable_size) / 1024
2794 document showioalloc
2795 Syntax: (gdb) showioalloc
2796 | Show some accounting of memory allocated by IOKit allocators. See ioalloccount man page for details.
2799 define showosobjecttracking
2800 set $kgm_next = (OSObjectTracking *) gOSObjectTrackList.next
2801 while $kgm_next != &gOSObjectTrackList
2802 set $obj = (OSObject *) ($kgm_next+1)
2805 while $kgm_idx < (sizeof($kgm_next->bt) / sizeof($kgm_next->bt[0]))
2806 if ((unsigned) $kgm_next->bt[$kgm_idx] > (unsigned) sectPRELINKB)
2807 showkmodaddr $kgm_next->bt[$kgm_idx]
2810 if ((unsigned) $kgm_next->bt[$kgm_idx] > 0)
2811 output /a (unsigned) $kgm_next->bt[$kgm_idx]
2815 set $kgm_idx = $kgm_idx + 1
2818 set $kgm_next = (OSObjectTracking *) $kgm_next->link.next
2822 document showosobjecttracking
2823 Syntax: (gdb) showosobjecttracking
2824 | Show the list of tracked OSObject allocations with backtraces.
2825 | Boot with the kOSTraceObjectAlloc (0x00400000) io debug flag set.
2826 | Set gOSObjectTrackThread to 1 or a thread_t to capture new OSObjects allocated by a thread or all threads.
2830 set kdp_trans_off = 1
2832 set kdp_trans_off = 0
2836 if ($kgm_mtype == 18)
2837 set kdp_src_high32 = ((uint32_t) ($arg0)) >> 32
2838 x/x (uint32_t) (($arg0) & 0x00000000ffffffffUL)
2839 set kdp_src_high32 = 0
2841 echo readphys64 not available on this architecture.\n
2846 | The argument is interpreted as a physical address, and the word addressed is
2847 | displayed. While this fails if no physical page exists at the given address,
2848 | it must be used with caution.
2852 | The argument is interpreted as a 64-bit physical address, and the word
2853 | addressed is displayed. While this fails if no physical page exists at the
2854 | given address, it must be used with caution.
2858 shell ls $arg0/* | xargs -n 1 echo add-symbol-file > /tmp/gdb-syms
2859 source /tmp/gdb-syms
2860 set $kgm_show_kmod_syms = 1
2863 document addkextsyms
2864 | Takes a directory of symbols for kexts generated with kextcache -y and loads them
2866 | (gdb) addkextsyms /path/to/symboldir
2869 define showprocfiles
2872 _showprocfiles $arg0
2874 printf "| Usage:\n|\n"
2878 document showprocfiles
2879 Syntax: (gdb) showprocfiles <proc_t>
2880 | Given a proc_t pointer, display the list of open file descriptors for the
2881 | referenced process.
2884 define _showprocheader
2885 printf "fd fileglob fg flags fg type fg data info\n"
2886 printf "----- ---------- ---------- -------- ---------- -------------------\n"
2889 define _showprocfiles
2890 set $kgm_spf_filedesc = ((proc_t)$arg0)->p_fd
2891 set $kgm_spf_last = $kgm_spf_filedesc->fd_lastfile
2892 set $kgm_spf_ofiles = $kgm_spf_filedesc->fd_ofiles
2893 set $kgm_spf_count = 0
2894 while ($kgm_spf_count <= $kgm_spf_last)
2895 if ($kgm_spf_ofiles[$kgm_spf_count] == 0)
2896 # DEBUG: For files that were open, but are now closed
2897 # printf "%-5d FILEPROC_NULL\n", $kgm_spf_count
2899 # display fd #, fileglob address, fileglob flags
2900 set $kgm_spf_flags = $kgm_spf_ofiles[$kgm_spf_count].f_flags
2901 set $kgm_spf_fg = $kgm_spf_ofiles[$kgm_spf_count].f_fglob
2902 printf "%-5d 0x%08x 0x%08x ", $kgm_spf_count, $kgm_spf_fg, $kgm_spf_flags
2903 # decode fileglob type
2904 set $kgm_spf_fgt = $kgm_spf_fg->fg_type
2905 if ($kgm_spf_fgt == 1)
2908 if ($kgm_spf_fgt == 2)
2911 if ($kgm_spf_fgt == 3)
2914 if ($kgm_spf_fgt == 4)
2917 if ($kgm_spf_fgt == 5)
2920 if ($kgm_spf_fgt == 6)
2923 if ($kgm_spf_fgt == 7)
2926 if ($kgm_spf_fgt < 1 || $kgm_spf_fgt > 7)
2927 printf "?: %-5d", $kgm_spf_fgt
2930 # display fileglob data address and decode interesting fact(s)
2931 # about data, if we know any
2932 set $kgm_spf_fgd = $kgm_spf_fg->fg_data
2933 printf " 0x%08x ", $kgm_spf_fgd
2934 if ($kgm_spf_fgt == 1)
2935 set $kgm_spf_name = ((struct vnode *)$kgm_spf_fgd)->v_name
2936 if ($kgm_spf_name == 0)
2939 printf "%s", $kgm_spf_name
2944 set $kgm_spf_count = $kgm_spf_count + 1
2949 # Show all the advisory file locks held by a process for each of the vnode
2950 # type files that it has open; do this by walking the per process open file
2951 # table and looking at any vnode type fileglob that has a non-NULL lock list
2952 # associated with it.
2954 define showproclocks
2956 _showproclocks $arg0
2958 printf "| Usage:\n|\n"
2962 document showproclocks
2963 Syntax: (gdb) showproclocks <proc_t>
2964 | Given a proc_t pointer, display the list of advisory file locks held by the
2965 | referenced process.
2968 define _showproclocks
2969 set $kgm_spl_filedesc = ((proc_t)$arg0)->p_fd
2970 set $kgm_spl_last = $kgm_spl_filedesc->fd_lastfile
2971 set $kgm_spl_ofiles = $kgm_spl_filedesc->fd_ofiles
2972 set $kgm_spl_count = 0
2973 set $kgm_spl_seen = 0
2974 while ($kgm_spl_count <= $kgm_spl_last)
2975 if ($kgm_spl_ofiles[$kgm_spl_count] == 0)
2976 # DEBUG: For files that were open, but are now closed
2977 # printf "%-5d FILEPROC_NULL\n", $kgm_spl_count
2979 set $kgm_spl_fg = $kgm_spl_ofiles[$kgm_spl_count].f_fglob
2980 # decode fileglob type
2981 set $kgm_spl_fgt = $kgm_spl_fg->fg_type
2982 if ($kgm_spl_fgt == 1)
2983 set $kgm_spl_fgd = $kgm_spl_fg->fg_data
2984 set $kgm_spl_name = ((struct vnode *)$kgm_spl_fgd)->v_name
2985 set $kgm_spl_vnode = ((vnode_t)$kgm_spl_fgd)
2986 set $kgm_spl_lockiter = $kgm_spl_vnode->v_lockf
2987 if ($kgm_spl_lockiter != 0)
2988 if ($kgm_spl_seen == 0)
2989 _showvnodelockheader
2991 set $kgm_spl_seen = $kgm_spl_seen + 1
2992 printf "( fd %d, name ", $kgm_spl_count
2993 if ($kgm_spl_name == 0)
2996 printf "%s )\n", $kgm_spl_name
2998 _showvnodelocks $kgm_spl_fgd
3002 set $kgm_spl_count = $kgm_spf_count + 1
3004 printf "%d total locks for 0x%08x\n", $kgm_spl_seen, $arg0
3008 set $kgm_spi_proc = (proc_t)$arg0
3009 printf "Process 0x%08x\n", $kgm_spi_proc
3010 printf " name %s\n", $kgm_spi_proc->p_comm
3011 printf " pid:%.8d", $kgm_spi_proc->p_pid
3012 printf " task:0x%.8x", $kgm_spi_proc->task
3013 printf " p_stat:%.1d", $kgm_spi_proc->p_stat
3014 printf " parent pid:%.8d", $kgm_spi_proc->p_ppid
3015 # decode part of credential
3016 set $kgm_spi_cred = $kgm_spi_proc->p_ucred
3017 if ($kgm_spi_cred != 0)
3018 printf "Cred: euid %d ruid %d svuid %d\n", $kgm_spi_cred->cr_uid, $kgm_spi_cred->cr_ruid, $kgm_spi_cred->cr_svuid
3020 printf "Cred: (null)\n"
3023 set $kgm_spi_flag = $kgm_spi_proc->p_flag
3024 printf "Flags: 0x%08x\n", $kgm_spi_flag
3025 if ($kgm_spi_flag & 0x00000001)
3026 printf " 0x00000001 - may hold advisory locks\n"
3028 if ($kgm_spi_flag & 0x00000002)
3029 printf " 0x00000002 - has a controlling tty\n"
3031 if ($kgm_spi_flag & 0x00000004)
3032 printf " 0x00000004 - process is 64 bit\n"
3034 printf " !0x00000004 - process is 32 bit\n"
3036 if ($kgm_spi_flag & 0x00000008)
3037 printf " 0x00000008 - no SIGCHLD on child stop\n"
3039 if ($kgm_spi_flag & 0x00000010)
3040 printf " 0x00000010 - waiting for child exec/exit\n"
3042 if ($kgm_spi_flag & 0x00000020)
3043 printf " 0x00000020 - has started profiling\n"
3045 if ($kgm_spi_flag & 0x00000040)
3046 printf " 0x00000040 - in select; wakeup/waiting danger\n"
3048 if ($kgm_spi_flag & 0x00000080)
3049 printf " 0x00000080 - was stopped and continued\n"
3051 if ($kgm_spi_flag & 0x00000100)
3052 printf " 0x00000100 - has set privileges since exec\n"
3054 if ($kgm_spi_flag & 0x00000200)
3055 printf " 0x00000200 - system process: no signals, stats, or swap\n"
3057 if ($kgm_spi_flag & 0x00000400)
3058 printf " 0x00000400 - timing out during a sleep\n"
3060 if ($kgm_spi_flag & 0x00000800)
3061 printf " 0x00000800 - debugged process being traced\n"
3063 if ($kgm_spi_flag & 0x00001000)
3064 printf " 0x00001000 - debugging process has waited for child\n"
3066 if ($kgm_spi_flag & 0x00002000)
3067 printf " 0x00002000 - exit in progress\n"
3069 if ($kgm_spi_flag & 0x00004000)
3070 printf " 0x00004000 - process has called exec\n"
3072 if ($kgm_spi_flag & 0x00008000)
3073 printf " 0x00008000 - owe process an addupc() XXX\n"
3075 if ($kgm_spi_flag & 0x00010000)
3076 printf " 0x00010000 - affinity for Rosetta children\n"
3078 if ($kgm_spi_flag & 0x00020000)
3079 printf " 0x00020000 - wants to run Rosetta\n"
3081 if ($kgm_spi_flag & 0x00040000)
3082 printf " 0x00040000 - has wait() in progress\n"
3084 if ($kgm_spi_flag & 0x00080000)
3085 printf " 0x00080000 - kdebug tracing on for this process\n"
3087 if ($kgm_spi_flag & 0x00100000)
3088 printf " 0x00100000 - blocked due to SIGTTOU or SIGTTIN\n"
3090 if ($kgm_spi_flag & 0x00200000)
3091 printf " 0x00200000 - has called reboot()\n"
3093 if ($kgm_spi_flag & 0x00400000)
3094 printf " 0x00400000 - is TBE state\n"
3096 if ($kgm_spi_flag & 0x00800000)
3097 printf " 0x00800000 - signal exceptions\n"
3099 if ($kgm_spi_flag & 0x01000000)
3100 printf " 0x01000000 - being branch traced\n"
3102 if ($kgm_spi_flag & 0x02000000)
3103 printf " 0x02000000 - has vfork() children\n"
3105 if ($kgm_spi_flag & 0x04000000)
3106 printf " 0x04000000 - not allowed to attach\n"
3108 if ($kgm_spi_flag & 0x08000000)
3109 printf " 0x08000000 - vfork() in progress\n"
3111 if ($kgm_spi_flag & 0x10000000)
3112 printf " 0x10000000 - no shared libraries\n"
3114 if ($kgm_spi_flag & 0x20000000)
3115 printf " 0x20000000 - force quota for root\n"
3117 if ($kgm_spi_flag & 0x40000000)
3118 printf " 0x40000000 - no zombies when children exit\n"
3120 if ($kgm_spi_flag & 0x80000000)
3121 printf " 0x80000000 - don't hang on remote FS ops\n"
3124 set $kgm_spi_state = $kgm_spi_proc->p_stat
3126 if ($kgm_spi_state == 1)
3129 if ($kgm_spi_state == 2)
3132 if ($kgm_spi_state == 3)
3135 if ($kgm_spi_state == 4)
3138 if ($kgm_spi_state == 5)
3141 if ($kgm_spi_state == 6)
3144 if ($kgm_spi_state < 1 || $kgm_spi_state > 6)
3145 printf "(Unknown)\n"
3149 document showprocinfo
3150 Syntax: (gdb) showprocinfo <proc_t>
3151 | Displays name, pid, parent and task for a proc_t. Decodes cred, flag and p_stat fields.
3155 # dump the zombprocs
3158 set $basep = (struct proc *)zombproc->lh_first
3162 set $pp = $pp->p_list.le_next
3167 Syntax: (gdb) zombproc
3168 | Routine to print out all procs in the zombie list
3172 # dump the zombstacks
3175 set $basep = (struct proc *)zombproc->lh_first
3179 showtaskstacks $pp->task
3181 set $pp = $pp->p_list.le_next
3186 Syntax: (gdb) zombstacks
3187 | Routine to print out all stacks of tasks that are exiting
3195 set $basep = (struct proc *)allproc->lh_first
3199 set $pp = $pp->p_list.le_next
3204 Syntax: (gdb) allproc
3205 | Routine to print out all process in the system
3206 | which are not in the zombie list
3212 set $vp = (struct vnode *)$arg0
3214 printf " vp 0x%.8x", $vp
3215 printf " use %d", $vp->v_usecount
3216 printf " io %d", $vp->v_iocount
3217 printf " kuse %d", $vp->v_kusecount
3218 printf " type %d", $vp->v_type
3219 printf " flg 0x%.8x", $vp->v_flag
3220 printf " lflg 0x%.8x", $vp->v_lflag
3221 printf " par 0x%.8x", $vp->v_parent
3222 set $_name = (char *)$vp->v_name
3224 printf " %s", $_name
3226 if ($vp->v_type == VREG) && ($vp->v_un.vu_ubcinfo != 0)
3227 printf " mapped %d", ($vp->v_un.vu_ubcinfo.ui_flags & 0x08) ? 1 : 0
3232 document print_vnode
3233 Syntax: (gdb) print_vnode <vnode>
3234 | Prints out the fields of a vnode struct
3237 define showprocvnodes
3238 set $pp = (struct proc *)$arg0
3239 set $fdp = (struct filedesc *)$pp->p_fd
3240 set $cvp = $fdp->fd_cdir
3241 set $rvp = $fdp->fd_rdir
3243 printf "Current Working Directory \n"
3248 printf "Current Root Directory \n"
3253 set $fpp = (struct fileproc **)($fdp->fd_ofiles)
3254 set $fpo = (char)($fdp->fd_ofileflags[0])
3255 while $count < $fdp->fd_nfiles
3256 #printf"fpp %x ", *$fpp
3258 set $fg =(struct fileglob *)((**$fpp)->f_fglob)
3259 if $fg && (($fg)->fg_type == 1)
3260 if $fdp->fd_ofileflags[$count] & 4
3265 printf "fd = %d ", $count
3266 print_vnode $fg->fg_data
3270 set $count = $count + 1
3274 document showprocvnodes
3275 Syntax: (gdb) showprocvnodes <proc_address>
3276 | Routine to print out all the open fds
3277 | which are vnodes in a process
3280 define showallprocvnodes
3281 set $basep = (struct proc *)allproc->lh_first
3284 printf "============================================ \n"
3287 set $pp = $pp->p_list.le_next
3291 document showallprocvnodes
3292 Syntax: (gdb) showallprocvnodes
3293 | Routine to print out all the open fds
3299 # dump the childrent of a proc
3301 define showinitchild
3302 set $basep = (struct proc *)initproc->p_children.lh_first
3306 set $pp = $pp->p_sibling.le_next
3310 document showinitchild
3311 Syntax: (gdb) showinitchild
3312 | Routine to print out all processes in the system
3313 | which are children of init process
3317 define showmountallvnodes
3318 set $mp = (struct mount *)$arg0
3319 set $basevp = (struct vnode *)$mp->mnt_vnodelist.tqh_first
3321 printf "____________________ Vnode list Queue ---------------\n"
3324 set $vp = $vp->v_mntvnodes->tqe_next
3326 set $basevp = (struct vnode *)$mp->mnt_workerqueue.tqh_first
3328 printf "____________________ Worker Queue ---------------\n"
3331 set $vp = $vp->v_mntvnodes->tqe_next
3333 set $basevp = (struct vnode *)$mp->mnt_newvnodes.tqh_first
3335 printf "____________________ New vnodes Queue ---------------\n"
3338 set $vp = $vp->v_mntvnodes->tqe_next
3341 document showmountallvnodes
3342 Syntax: showmountallvnodes <struct mount *>
3343 | Print the vnode inactive list
3347 define showmountvnodes
3348 set $mp = (struct mount *)$arg0
3349 set $basevp = (struct vnode *)$mp->mnt_vnodelist.tqh_first
3351 printf "____________________ Vnode list Queue ---------------\n"
3354 set $vp = $vp->v_mntvnodes->tqe_next
3357 document showmountvnodes
3358 Syntax: showmountvnodes <struct mount *>
3359 | Print the vnode list
3364 define showworkqvnodes
3365 set $mp = (struct mount *)$arg0
3366 set $basevp = (struct vnode *)$mp->mnt_workerqueue.tqh_first
3368 printf "____________________ Worker Queue ---------------\n"
3371 set $vp = $vp->v_mntvnodes->tqe_next
3374 document showworkqvnodes
3375 Syntax: showworkqvnodes <struct mount *>
3376 | Print the vnode worker list
3380 define shownewvnodes
3381 set $mp = (struct mount *)$arg0
3382 set $basevp = (struct vnode *)$mp->mnt_newvnodes.tqh_first
3384 printf "____________________ New vnodes Queue ---------------\n"
3387 set $vp = $vp->v_mntvnodes->tqe_next
3391 document shownewvnodes
3392 Syntax: shownewvnodes <struct mount *>
3393 | Print the new vnode list
3398 # print mount point info
3400 set $mp = (struct mount *)$arg0
3402 printf " mp 0x%.8x", $mp
3403 printf " flag %x", $mp->mnt_flag
3404 printf " kern_flag %x", $mp->mnt_kern_flag
3405 printf " lflag %x", $mp->mnt_lflag
3406 printf " type: %s", $mp->mnt_vfsstat.f_fstypename
3407 printf " mnton: %s", $mp->mnt_vfsstat.f_mntonname
3408 printf " mntfrom: %s", $mp->mnt_vfsstat.f_mntfromname
3412 define showallmounts
3413 set $mp=(struct mount *)mountlist.tqh_first
3416 set $mp = $mp->mnt_list.tqe_next
3420 document showallmounts
3421 Syntax: showallmounts
3422 | Print all mount points
3427 if ((unsigned int)$pc <= (unsigned int) $kgm_fkmodmax) && \
3428 ((unsigned int)$pc >= (unsigned int)$kgm_fkmodmin)
3436 set $mp = (struct mbuf *)$arg0
3440 printf "%4d: 0x%08x [len %4d, type %2d, ", $cnt, $mp, \
3441 $mp->m_hdr.mh_len, $mp->m_hdr.mh_type
3446 set $tot = $tot + $mp->m_hdr.mh_len
3447 printf "total %d]\n", $tot
3448 set $mp = $mp->m_hdr.mh_nextpkt
3453 document mbuf_walkpkt
3454 Syntax: (gdb) mbuf_walkpkt <addr>
3455 | Given an mbuf address, walk its m_nextpkt pointer
3459 set $mp = (struct mbuf *)$arg0
3463 printf "%4d: 0x%08x [len %4d, type %2d, ", $cnt, $mp, \
3464 $mp->m_hdr.mh_len, $mp->m_hdr.mh_type
3469 set $tot = $tot + $mp->m_hdr.mh_len
3470 printf "total %d]\n", $tot
3471 set $mp = $mp->m_hdr.mh_next
3477 Syntax: (gdb) mbuf_walk <addr>
3478 | Given an mbuf address, walk its m_next pointer
3481 define mbuf_buf2slab
3483 set $gix = ((char *)$addr - (char *)mbutl) >> 20
3484 set $ix = ((char *)$addr - (char *)mbutl) >> 11
3485 set $slab = &slabstbl[$gix].slg_slab[$ix]
3486 printf "0x%08x", $slab
3489 document mbuf_buf2slab
3490 | Given an mbuf object, find its corresponding slab address.
3495 set $ix = ((char *)$addr - (char *)mbutl) >> 11
3496 set $clbase = ((union mcluster *)(mbutl + $ix))
3497 set $mclidx = (((char *)$addr - (char *)$clbase) >> 8)
3498 set $mca = mclaudit[$ix].cl_audit[$mclidx]
3499 printf "mca: 0x%08x", $mca
3502 document mbuf_buf2mca
3503 Syntax: (gdb) mbuf_buf2mca <addr>
3504 | Given an mbuf object, find its buffer audit structure address.
3505 | This requires mbuf buffer auditing to be turned on, by setting
3506 | the appropriate flags to the "mbuf_debug" boot-args parameter.
3511 set $mca = (mcache_audit_t *)$arg0
3512 set $cp = (mcache_t *)$mca->mca_cache
3513 printf "object type:\t\t"
3514 mbuf_mca_ctype $mca 1
3515 printf "\ncontrolling mcache:\t%p (%s)\n", $mca->mca_cache, $cp->mc_name
3516 if $mca->mca_uflags & $MB_SCVALID
3517 set $ix = ((char *)$mca->mca_addr - (char *)mbutl) >> 11
3518 set $clbase = ((union mcluster *)(mbutl + $ix))
3519 set $mclidx = (((char *)$mca->mca_addr - (char *)$clbase) >> 8)
3520 printf "mbuf obj:\t\t%p\n", $mca->mca_addr
3521 printf "mbuf index:\t\t%d (out of 8) in cluster base %p\n", \
3522 $mclidx + 1, $clbase
3523 if $mca->mca_uptr != 0
3524 set $peer_mca = (mcache_audit_t *)$mca->mca_uptr
3525 printf "paired cluster obj:\t%p (mca %p)\n", \
3526 $peer_mca->mca_addr, $peer_mca
3528 printf "saved contents:\t\t%p (%d bytes)\n", \
3529 $mca->mca_contents, $mca->mca_contents_size
3531 printf "cluster obj:\t\t%p\n", $mca->mca_addr
3532 if $mca->mca_uptr != 0
3533 set $peer_mca = (mcache_audit_t *)$mca->mca_uptr
3534 printf "paired mbuf obj:\t%p (mca %p)\n", \
3535 $peer_mca->mca_addr, $peer_mca
3538 printf "recent transaction for this buffer (thread %p):\n", \
3541 while $cnt < $mca->mca_depth
3542 set $pc = $mca->mca_stack[$cnt]
3543 printf "%4d: ", $cnt + 1
3548 if $mca->mca_pdepth > 0
3549 printf "previous transaction for this buffer (thread %p):\n", \
3553 while $cnt < $mca->mca_pdepth
3554 set $pc = $mca->mca_pstack[$cnt]
3555 printf "%4d: ", $cnt + 1
3563 document mbuf_showmca
3564 Syntax: (gdb) mbuf_showmca <addr>
3565 | Given an mbuf/cluster buffer audit structure address, print the audit
3566 | records including the stack trace of the last buffer transaction.
3569 set $MCF_NOCPUCACHE = 0x10
3572 set $head = (mcache_t *)mcache_head
3574 printf "cache cache cache buf buf backing (# of retries) bufs\n"
3575 printf "name state addr size align zone wait nowait failed incache\n"
3576 printf "------------------------- -------- ---------- ------ ----- ---------- -------------------------- --------\n"
3578 set $bktsize = $mc->mc_cpu.cc_bktsize
3579 printf "%-25s ", $mc->mc_name
3580 if ($mc->mc_flags & $MCF_NOCPUCACHE)
3583 if $mc->mc_purge_cnt > 0
3593 printf " 0x%08x %6d %5d ",$mc, \
3594 $mc->mc_bufsize, $mc->mc_align
3595 if $mc->mc_slab_zone != 0
3596 printf "0x%08x", $mc->mc_slab_zone
3601 set $tot += $mc->mc_full.bl_total * $bktsize
3602 set $ccp = (mcache_cpu_t *)$mc->mc_cpu
3605 if $ccp->cc_objs > 0
3606 set $tot += $ccp->cc_objs
3608 if $ccp->cc_pobjs > 0
3609 set $tot += $ccp->cc_pobjs
3614 printf " %8d %8d %8d %8d", $mc->mc_wretry_cnt, \
3615 $mc->mc_nwretry_cnt, $mc->mc_nwfail_cnt, $tot
3617 set $mc = (mcache_t *)$mc->mc_list.le_next
3621 document mcache_stat
3622 Syntax: (gdb) mcache_stat
3623 | Print all mcaches in the system.
3626 define mcache_showzone
3627 set $mc = (mcache_t *)$arg0
3628 if $mc->mc_slab_zone != 0
3629 printf "%p", $mc->mc_slab_zone
3634 document mcache_showzone
3635 Syntax: (gdb) mcache_showzone <mcache_addr>
3636 | Print the type of backend (custom or zone) of a mcache.
3639 define mcache_walkobj
3640 set $p = (mcache_obj_t *)$arg0
3644 printf "%4d: 0x%08x\n", $cnt, $p,
3645 set $p = $p->obj_next
3650 document mcache_walkobj
3651 Syntax: (gdb) mcache_walkobj <addr>
3652 | Given a mcache object address, walk its obj_next pointer
3655 define mcache_showcache
3656 set $cp = (mcache_t *)$arg0
3657 set $ccp = (mcache_cpu_t *)$cp->mc_cpu
3658 set $bktsize = $cp->mc_cpu.cc_bktsize
3661 printf "Showing cache '%s':\n\n", $cp->mc_name
3662 printf " CPU cc_objs cc_pobjs total\n"
3663 printf "---- -------- -------- --------\n"
3665 set $objs = $ccp->cc_objs
3669 set $pobjs = $ccp->cc_pobjs
3673 set $tot_cpu = $objs + $pobjs
3674 set $tot += $tot_cpu
3675 printf "%4d %8d %8d %8d\n", $cnt, $objs, $pobjs, $tot_cpu
3679 printf " ========\n"
3680 printf " %8d\n", $tot
3682 set $tot += $cp->mc_full.bl_total * $bktsize
3683 printf "Total # of full buckets (%d objs/bkt):\t%-8d\n", \
3684 $bktsize, $cp->mc_full.bl_total
3685 printf "Total # of objects cached:\t\t%-8d\n", $tot
3688 document mcache_showcache
3689 | Display the number of objects in the cache
3692 set $NSLABSPMB = sizeof(mcl_slabg_t)/sizeof(mcl_slab_t)
3694 define mbuf_slabstbl
3697 printf "slot addr slabs range\n"
3698 printf "---- ---------- -----------------------\n"
3699 while $x < maxslabgrp
3700 set $slg = slabstbl[$x]
3705 printf "%p [%p-%p]\n", $slg, &$slg->slg_slab[0], \
3706 &$slg->slg_slab[$NSLABSPMB-1]
3712 document mbuf_slabstbl
3713 | Display the mbuf slabs table
3716 set $SLF_MAPPED=0x0001
3717 set $SLF_PARTIAL=0x0002
3718 set $SLF_DETACHED=0x0004
3721 set $slg = (mcl_slabg_t *)$arg0
3724 printf "slot addr next base C R N size flags\n"
3725 printf "---- ---------- ---------- ---------- -- -- -- ------ -----\n"
3726 while $x < $NSLABSPMB
3727 set $sl = &$slg->slg_slab[$x]
3728 printf "%3d: 0x%08x 0x%08x 0x%08x %2d %2d %2d %6d 0x%04x ", \
3729 $x + 1, $sl, $sl->sl_next, $sl->sl_base, $sl->sl_class, \
3730 $sl->sl_refcnt, $sl->sl_chunks, $sl->sl_len, \
3732 if $sl->sl_flags != 0
3734 if $sl->sl_flags & $SLF_MAPPED
3737 if $sl->sl_flags & $SLF_PARTIAL
3740 if $sl->sl_flags & $SLF_DETACHED
3751 | Display all mbuf slabs in the group
3757 printf "class total cached uncached inuse failed waiter notified purge\n"
3758 printf "name objs objs objs / slabs objs alloc count count count count\n"
3759 printf "---------------- -------- -------- ------------------- -------- ---------------- -------- -------- --------\n"
3760 while $x < (sizeof(mbuf_table) / sizeof(mbuf_table[0]))
3761 set $mbt = mbuf_table[$x]
3762 set $mcs = (mb_class_stat_t *)mbuf_table[$x].mtbl_stats
3764 set $mc = $mbt->mtbl_cache
3765 set $bktsize = $mc->mc_cpu.cc_bktsize
3766 set $tot += $mc->mc_full.bl_total * $bktsize
3767 set $ccp = (mcache_cpu_t *)$mc->mc_cpu
3770 if $ccp->cc_objs > 0
3771 set $tot += $ccp->cc_objs
3773 if $ccp->cc_pobjs > 0
3774 set $tot += $ccp->cc_pobjs
3780 printf "%-16s %8d %8d %8d / %-8d %8d %16llu %8d %8llu %8llu", \
3781 $mcs->mbcl_cname, $mcs->mbcl_total, $tot, \
3782 $mcs->mbcl_infree, $mcs->mbcl_slab_cnt, \
3783 ($mcs->mbcl_total - $tot - $mcs->mbcl_infree), \
3784 $mcs->mbcl_fail_cnt, $mc->mc_waiter_cnt, \
3785 $mcs->mbcl_notified, $mcs->mbcl_purge_cnt
3792 | Print extended mbuf allocator statistics.
3796 set $MB_COMP_INUSE = 0x2
3797 set $MB_SCVALID = 0x4
3799 set $MCLBYTES = 2048
3802 set $M16KCLBYTES = 16384
3804 define mbuf_mca_ctype
3805 set $mca = (mcache_audit_t *)$arg0
3807 set $cp = $mca->mca_cache
3808 set $class = (unsigned int)$cp->mc_private
3809 set $csize = mbuf_table[$class].mtbl_stats->mbcl_size
3819 if !$done && $csize == $MCLBYTES
3821 printf "CL (2K cluster) "
3827 if !$done && $csize == $NBPG
3829 printf "BCL (4K cluster) "
3835 if !$done && $csize == $M16KCLBYTES
3837 printf "JCL (16K cluster) "
3843 if !$done && $csize == ($MSIZE+$MCLBYTES)
3844 if $mca->mca_uflags & $MB_SCVALID
3848 printf "(paired mbuf, 2K cluster)"
3853 printf "(unpaired mbuf, 2K cluster) "
3860 printf "(paired 2K cluster, mbuf) "
3865 printf "(paired 2K cluster, mbuf) "
3871 if !$done && $csize == ($MSIZE+$NBPG)
3872 if $mca->mca_uflags & $MB_SCVALID
3876 printf "(paired mbuf, 4K cluster) "
3881 printf "(unpaired mbuf, 4K cluster) "
3888 printf "(paired 4K cluster, mbuf) "
3893 printf "(unpaired 4K cluster, mbuf) "
3899 if !$done && $csize == ($MSIZE+$M16KCLBYTES)
3900 if $mca->mca_uflags & $MB_SCVALID
3904 printf "(paired mbuf, 16K cluster) "
3909 printf "(unpaired mbuf, 16K cluster) "
3916 printf "(paired 16K cluster, mbuf) "
3921 printf "(unpaired 16K cluster, mbuf) "
3928 printf "unknown: %s ", $cp->mc_name
3932 document mbuf_mca_ctype
3933 | This is a helper macro for mbuf_show{active,inactive,all} that prints
3934 | out the mbuf object type represented by a given mcache audit structure.
3937 define mbuf_showactive
3938 mbuf_walkallslabs 1 0
3941 document mbuf_showactive
3942 Syntax: (gdb) mbuf_showactive
3943 | Walk the mbuf objects pool and print only the active ones; this
3944 | requires mbuf debugging to be turned on, by setting the appropriate flags
3945 | to the "mbuf_debug" boot-args parameter. Active objects are those that
3946 | are outstanding (have not returned to the mbuf slab layer) and in use
3947 | by the client (have not been freed).
3950 define mbuf_showinactive
3951 mbuf_walkallslabs 0 1
3954 document mbuf_showinactive
3955 Syntax: (gdb) mbuf_showinactive
3956 | Walk the mbuf objects pool and print only the inactive ones; this
3957 | requires mbuf debugging to be turned on, by setting the appropriate flags
3958 | to the "mbuf_debug" boot-args parameter. Inactive objects are those that
3959 | are outstanding (have not returned to the mbuf slab layer) but have been
3960 | freed by the client, i.e. they still reside in the mcache layer ready to
3961 | be used for subsequent allocation requests.
3965 mbuf_walkallslabs 1 1
3968 document mbuf_showall
3969 Syntax: (gdb) mbuf_showall
3970 | Walk the mbuf objects pool and print them all; this requires
3971 | mbuf debugging to be turned on, by setting the appropriate flags to the
3972 | "mbuf_debug" boot-args parameter.
3978 define mbuf_walkallslabs
3987 if $show_a && !$show_f
3988 printf "Searching only for active "
3990 if !$show_a && $show_f
3991 printf "Searching only for inactive "
3993 if $show_a && $show_f
3994 printf "Displaying all "
3996 printf "objects; this may take a while ...)\n\n"
3998 printf " slab mca obj allocation\n"
3999 printf "slot idx address address address type state\n"
4000 printf "---- ---- ---------- ---------- ---------- ----- -----------\n"
4003 set $slg = slabstbl[$x]
4006 while $y < $NSLABSPMB && $stop == 0
4007 set $sl = &$slg->slg_slab[$y]
4008 set $base = (char *)$sl->sl_base
4009 set $ix = ($base - (char *)mbutl) >> 11
4010 set $clbase = ((union mcluster *)(mbutl + $ix))
4011 set $mclidx = ($base - (char *)$clbase) >> 8
4012 set $mca = mclaudit[$ix].cl_audit[$mclidx]
4015 while $mca != 0 && $mca->mca_addr != 0
4017 if $mca->mca_uflags & ($MB_INUSE|$MB_COMP_INUSE)
4018 set $total_a = $total_a + 1
4019 set $printmca = $show_a
4021 set $total_f = $total_f + 1
4022 set $printmca = $show_f
4027 printf "%4d %4d 0x%08x ", $x, $y, $sl
4032 printf "0x%08x 0x%08x ", $mca, $mca->mca_addr
4033 mbuf_mca_ctype $mca 0
4034 if $mca->mca_uflags & ($MB_INUSE|$MB_COMP_INUSE)
4043 set $total = $total + 1
4045 set $mca = $mca->mca_next
4048 if $slg->slg_slab[$y].sl_base == 0
4054 if $total && $show_a && $show_f
4055 printf "\ntotal objects:\t%d\n", $total
4056 printf "active/unfreed:\t%d\n", $total_a
4057 printf "freed/in_cache:\t%d\n", $total_f
4061 document mbuf_walkallslabs
4062 | Walk the mbuf objects pool; this requires mbuf debugging to be
4063 | turned on, by setting the appropriate flags to the "mbuf_debug" boot-args
4064 | parameter. This is a backend routine for mbuf_show{active,inactive,all}.
4067 define rtentry_trash
4068 set $rtd = (struct rtentry_dbg *)rttrash_head.tqh_first
4072 printf " rtentry_dbg ref flags\n"
4073 printf " ------------ --- ----------\n"
4075 printf "%4d: %p %3d 0x%08x\n", $cnt + 1, $rtd, \
4076 $rtd->rtd_refhold_cnt - $rtd->rtd_refrele_cnt, \
4077 $rtd->rtd_entry.rt_flags
4078 set $rtd = $rtd->rtd_trash_link.tqe_next
4083 document rtentry_trash
4084 Syntax: (gdb) rtentry_trash
4085 | Walk the list of trash route entries; this requires route entry
4086 | debugging to be turned on, by setting the appropriate flags to the
4087 | "rte_debug" boot-args parameter.
4090 set $RTD_TRSTACK_SIZE = 8
4091 set $RTD_REFHIST_SIZE = 4
4093 define rtentry_showdbg
4094 set $rtd = (struct rtentry_dbg *)$arg0
4097 printf "Total holds: %d\n", $rtd->rtd_refhold_cnt
4098 printf "Next hold slot: %d\n", $rtd->rtd_refhold_next
4099 printf "Total releases: %d\n", $rtd->rtd_refrele_cnt
4100 printf "Next release slot: %d\n", $rtd->rtd_refrele_next
4103 while $ix < $RTD_TRSTACK_SIZE
4104 set $pc = $rtd->rtd_alloc_stk_pc[$ix]
4107 printf "\nAlloc (thread %p):\n", \
4108 $rtd->rtd_alloc_thread
4110 printf "%4d: ", $ix + 1
4117 while $ix < $RTD_TRSTACK_SIZE
4118 set $pc = $rtd->rtd_free_stk_pc[$ix]
4121 printf "\nFree: (thread %p)\n", \
4122 $rtd->rtd_free_thread
4124 printf "%4d: ", $ix + 1
4130 while $cnt < $RTD_REFHIST_SIZE
4132 while $ix < $RTD_TRSTACK_SIZE
4133 set $pc = $rtd->rtd_refhold[$cnt].pc[$ix]
4136 printf "\nHold [%d] (thread %p):\n", \
4137 $cnt, $rtd->rtd_refhold[$cnt].th
4139 printf "%4d: ", $ix + 1
4148 while $cnt < $RTD_REFHIST_SIZE
4150 while $ix < $RTD_TRSTACK_SIZE
4151 set $pc = $rtd->rtd_refrele[$cnt].pc[$ix]
4154 printf "\nRelease [%d] (thread %p):\n",\
4155 $cnt, $rtd->rtd_refrele[$cnt].th
4157 printf "%4d: ", $ix + 1
4167 document rtentry_showdbg
4168 Syntax: (gdb) rtentry_showdbg <addr>
4169 | Given a route entry structure address, print the debug information
4170 | related to it. This requires route entry debugging to be turned
4171 | on, by setting the appropriate flags to the "rte_debug" boot-args
4176 # print all OSMalloc stats
4179 set $kgm_tagp = (OSMallocTag)$arg0
4180 printf "0x%08x: ", $kgm_tagp
4181 printf "%8d ",$kgm_tagp->OSMT_refcnt
4182 printf "%8x ",$kgm_tagp->OSMT_state
4183 printf "%8x ",$kgm_tagp->OSMT_attr
4184 printf "%s ",$kgm_tagp->OSMT_name
4190 printf "TAG COUNT STATE ATTR NAME\n"
4191 set $kgm_tagheadp = (OSMallocTag)&OSMalloc_tag_list
4192 set $kgm_tagptr = (OSMallocTag )($kgm_tagheadp->OSMT_link.next)
4193 while $kgm_tagptr != $kgm_tagheadp
4194 ostag_print $kgm_tagptr
4195 set $kgm_tagptr = (OSMallocTag)$kgm_tagptr->OSMT_link.next
4199 document showosmalloc
4200 Syntax: (gdb) showosmalloc
4201 | Print the outstanding allocation count by OSMallocTags.
4206 if msgbufp->msg_bufc[msgbufp->msg_bufx] == 0
4207 # The buffer hasn't wrapped, so take the easy (and fast!) path
4208 printf "%s", msgbufp->msg_bufc
4210 set $kgm_msgbuf = *msgbufp
4211 set $kgm_syslog_bufsize = $kgm_msgbuf.msg_size
4212 set $kgm_syslog_bufend = $kgm_msgbuf.msg_bufx
4213 if $kgm_syslog_bufend >= $kgm_syslog_bufsize
4214 set $kgm_syslog_bufend = 0
4217 # print older messages from msg_bufx to end of buffer
4218 set $kgm_i = $kgm_syslog_bufend
4219 while $kgm_i < $kgm_syslog_bufsize
4220 set $kgm_syslog_char = $kgm_msgbuf.msg_bufc[$kgm_i]
4221 if $kgm_syslog_char == 0
4223 set $kgm_i = $kgm_syslog_bufsize
4225 printf "%c", $kgm_syslog_char
4227 set $kgm_i = $kgm_i + 1
4230 # print newer messages from start of buffer to msg_bufx
4232 while $kgm_i < $kgm_syslog_bufend
4233 set $kgm_syslog_char = $kgm_msgbuf.msg_bufc[$kgm_i]
4234 printf "%c", $kgm_syslog_char
4235 set $kgm_i = $kgm_i + 1
4242 | Display the kernel's printf ring buffer
4245 define printvnodepathint_recur
4247 if ($arg0->v_flag & 0x000001) && ($arg0->v_mount != 0)
4248 if $arg0->v_mount->mnt_vnodecovered != 0
4249 printvnodepathint_recur $arg0->v_mount->mnt_vnodecovered $arg0->v_mount->mnt_vnodecovered->v_name
4252 printvnodepathint_recur $arg0->v_parent $arg0->v_parent->v_name
4259 # Show the locks held on a vnode by range, type, and holder.
4261 define showvnodelocks
4263 _showvnodelockheader
4264 _showvnodelocks $arg0
4266 printf "| Usage:\n|\n"
4270 document showvnodelocks
4271 | Given a vnodet pointer, display the list of advisory record locks for the
4272 | referenced pvnode.
4273 | The following is the syntax:
4274 | (gdb) showvnodelocks <vnode_t>
4277 define _showvnodelockheader
4278 printf "* type W held by lock type start end\n"
4279 printf "- ----- - ------------- --------- ------------------ ------------------\n"
4283 # Macro to display a single lock; used to display both held locks and
4286 define _showvnodelock
4287 set $kgm_svl_lock = ((struct lockf *)$arg0)
4290 set $kgm_svl_flags = $kgm_svl_lock->lf_flags
4291 set $kgm_svl_type = $kgm_svl_lock->lf_type
4292 if ($kgm_svl_flags & 0x20)
4295 if ($kgm_svl_flags & 0x40)
4298 if ($kgm_svl_flags & 0x80)
4301 if ($kgm_svl_flags & 0x10)
4307 # POSIX file vs. advisory range locks
4308 if ($kgm_svl_flags & 0x40)
4309 set $kgm_svl_proc = (proc_t)$kgm_svl_lock->lf_id
4310 printf "PID %8d ", $kgm_svl_proc->p_pid
4312 printf "ID 0x%08x ", $kgm_svl_lock->lf_id
4316 if ($kgm_svl_type == 1)
4319 if ($kgm_svl_type == 3)
4322 if ($kgm_svl_type == 2)
4331 printf "0x%016x..", $kgm_svl_lock->lf_start
4332 printf "0x%016x ", $kgm_svl_lock->lf_end
4336 # Body of showvnodelocks, not including header
4337 define _showvnodelocks
4338 set $kgm_svl_vnode = ((vnode_t)$arg0)
4339 set $kgm_svl_lockiter = $kgm_svl_vnode->v_lockf
4340 while ($kgm_svl_lockiter != 0)
4341 # locks that are held
4343 _showvnodelock $kgm_svl_lockiter
4345 # and any locks blocked by them
4346 set $kgm_svl_blocker = $kgm_svl_lockiter->lf_blkhd.tqh_first
4347 while ($kgm_svl_blocker != 0)
4349 _showvnodelock $kgm_svl_blocker
4350 set $kgm_svl_blocker = $kgm_svl_blocker->lf_block.tqe_next
4353 # and on to the next one...
4354 set $kgm_svl_lockiter = $kgm_svl_lockiter->lf_next
4358 define showvnodepath
4359 set $vp = (struct vnode *)$arg0
4361 if ($vp->v_flag & 0x000001) && ($vp->v_mount != 0) && ($vp->v_mount->mnt_flag & 0x00004000)
4364 printvnodepathint_recur $vp $vp->v_name
4370 document showvnodepath
4371 Syntax: (gdb) showvnodepath <vnode>
4372 | Prints the path for a vnode
4375 define printcolonhex
4380 while ($li < $count)
4382 printf "%02x", (u_char)$addr[$li]
4385 printf ":%02x", (u_char)$addr[$li]
4392 define showsockaddr_dl
4393 set $sdl = (struct sockaddr_dl *)$arg0
4398 set $addr = $sdl->sdl_data + $sdl->sdl_nlen
4399 set $count = $sdl->sdl_alen
4400 printcolonhex $addr $count
4404 define showsockaddr_unspec
4405 set $sockaddr = (struct sockaddr *)$arg0
4406 set $addr = $sockaddr->sa_data
4407 set $count = $sockaddr->sa_len - 2
4409 printcolonhex $addr $count
4412 define showsockaddr_at
4413 set $sockaddr = (struct sockaddr *)$arg0
4414 set $addr = $sockaddr->sa_data
4415 set $count = $sockaddr->sa_len - 2
4417 printcolonhex $addr $count
4420 define showsockaddr_in
4421 set $sin = (struct sockaddr_in *)$arg0
4422 set $sa_bytes = (unsigned char *)&($sin->sin_addr)
4423 printf "IPV4 %d.%d.%d.%d", $sa_bytes[0], $sa_bytes[1], $sa_bytes[2], $sa_bytes[3]
4426 define showsockaddr_in6
4427 set $sin6 = (struct sockaddr_in6 *)$arg0
4428 set $sa_bytes = $sin6->sin6_addr.__u6_addr.__u6_addr8
4429 printf "IPV6 %02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x", $sa_bytes[0], $sa_bytes[1], $sa_bytes[2], $sa_bytes[3], $sa_bytes[4], $sa_bytes[5], $sa_bytes[6], $sa_bytes[7], $sa_bytes[8], $sa_bytes[9], $sa_bytes[10], $sa_bytes[11], $sa_bytes[12], $sa_bytes[13], $sa_bytes[14], $sa_bytes[15]
4432 define showifmultiaddrs
4433 set $ifp = (struct ifnet *)$arg0
4434 set $if_multi = (struct ifmultiaddr *)$ifp->if_multiaddrs->lh_first
4435 set $mymulti = $if_multi
4437 while ($mymulti != 0)
4438 printf "%2d. ", $myi
4439 set $sa_family = $mymulti->ifma_addr.sa_family
4440 if ($sa_family == 2)
4441 if ($mymulti->ifma_ll != 0)
4442 showsockaddr_dl $mymulti->ifma_ll->ifma_addr
4445 showsockaddr_in $mymulti->ifma_addr
4447 if ($sa_family == 30)
4448 if ($mymulti->ifma_ll != 0)
4449 showsockaddr_dl $mymulti->ifma_ll->ifma_addr
4452 showsockaddr_in6 $mymulti->ifma_addr
4454 if ($sa_family == 18)
4455 showsockaddr_dl $mymulti->ifma_addr
4457 if ($sa_family == 0)
4458 showsockaddr_unspec $mymulti->ifma_addr 6
4460 printf " [%d]", $mymulti->ifma_refcount
4462 set $mymulti = $mymulti->ifma_link.le_next
4467 document showifmultiaddrs
4468 Syntax showifmultiaddrs <ifp>
4469 | show the (struct ifnet).if_multiaddrs list of multicast addresses for the given ifp
4473 set $mysock = (struct sockaddr *)$arg0
4474 set $showsockaddr_handled = 0
4478 if ($mysock->sa_family == 0)
4479 showsockaddr_unspec $mysock
4480 set $showsockaddr_handled = 1
4482 if ($mysock->sa_family == 2)
4483 showsockaddr_in $mysock
4484 set $showsockaddr_handled = 1
4486 if ($mysock->sa_family == 30)
4487 showsockaddr_in6 $mysock
4488 set $showsockaddr_handled = 1
4490 if ($mysock->sa_family == 18)
4491 showsockaddr_dl $mysock
4492 set $showsockaddr_handled = 1
4494 if ($mysock->sa_family == 16)
4495 showsockaddr_at $mysock
4496 set $showsockaddr_handled = 1
4498 if ($showsockaddr_handled == 0)
4499 printf "%d ", $mysock->sa_family
4500 set $addr = $mysock->sa_data
4501 set $count = $mysock->sa_len
4502 printcolonhex $addr $count
4508 set $flags = (u_short)$arg0
4540 printf "POINTTOPOINT"
4542 # if ($flags & 0x20)
4548 # printf "NOTRAILERS"
4598 if ($flags & 0x1000)
4606 if ($flags & 0x2000)
4614 if ($flags & 0x4000)
4620 printf "LINK2-ALTPHYS"
4622 if ($flags & 0x8000)
4634 set $ifp = (struct ifnet *)$arg0
4635 set $myifaddr = (struct ifaddr *)$ifp->if_addrhead->tqh_first
4637 while ($myifaddr != 0)
4638 printf "\t%d. ", $myi
4639 showsockaddr $myifaddr->ifa_addr
4640 printf " [%d]\n", $myifaddr->ifa_refcnt
4641 set $myifaddr = $myifaddr->ifa_link->tqe_next
4646 document showifaddrs
4647 Syntax: showifaddrs <ifp>
4648 | show the (struct ifnet).if_addrhead list of addresses for the given ifp
4652 set $ifconfig_all = 0
4654 set $ifconfig_all = 1
4656 set $ifp = (struct ifnet *)(ifnet->tqh_first)
4658 printf "%s%d: flags=%x", $ifp->if_name, $ifp->if_unit, (u_short)$ifp->if_flags
4659 showifflags $ifp->if_flags
4660 printf " mtu %d\n", $ifp->if_data.ifi_mtu
4661 printf "\t(struct ifnet *)0x%x\n", $ifp
4662 if ($ifconfig_all == 1)
4665 set $ifp = $ifp->if_link->tqe_next
4669 Syntax: (gdb) ifconfig
4670 | display ifconfig-like output, and print the (struct ifnet *) pointers for further inspection
4675 while ($myi < bpf_dtab_size)
4676 if (bpf_dtab[$myi] != 0)
4677 printf "Address 0x%x, bd_next 0x%x\n", bpf_dtab[$myi], bpf_dtab[$myi]->bd_next
4678 print *bpf_dtab[$myi]
4685 printf "volume mnt_data mnt_devvp typename mountpoint\n"
4686 set $kgm_vol = (mount_t) mountlist.tqh_first
4688 printf "0x%08x ", $kgm_vol
4689 printf "0x%08x ", $kgm_vol->mnt_data
4690 printf "0x%08x ", $kgm_vol->mnt_devvp
4691 if ($kgm_vol->mnt_vtable->vfc_name[0] == 'h') && \
4692 ($kgm_vol->mnt_vtable->vfc_name[1] == 'f') && \
4693 ($kgm_vol->mnt_vtable->vfc_name[2] == 's') && \
4694 ($kgm_vol->mnt_vtable->vfc_name[3] == '\0')
4695 set $kgm_hfsmount = \
4696 (struct hfsmount *) $kgm_vol->mnt_data
4697 if $kgm_hfsmount->hfs_freezing_proc != 0
4698 printf "FROZEN hfs "
4703 printf "%-10s ", $kgm_vol->mnt_vtable->vfc_name
4705 printf "%s\n", $kgm_vol->mnt_vfsstat.f_mntonname
4707 set $kgm_vol = (mount_t) $kgm_vol->mnt_list.tqe_next
4711 document showallvols
4712 Syntax: (gdb) showallvols
4713 | Display a summary of mounted volumes
4716 define showvnodeheader
4717 printf "vnode usecount iocount v_data vtype parent name\n"
4721 set $kgm_vnode = (vnode_t) $arg0
4722 printf "0x%08x ", $kgm_vnode
4723 printf "%8d ", $kgm_vnode->v_usecount
4724 printf "%7d ", $kgm_vnode->v_iocount
4725 # print information about clean/dirty blocks?
4726 printf "0x%08x ", $kgm_vnode->v_data
4728 # print the vtype, using the enum tag
4729 set $kgm_vtype = $kgm_vnode->v_type
4730 if $kgm_vtype == VNON
4733 if $kgm_vtype == VREG
4736 if $kgm_vtype == VDIR
4739 if $kgm_vtype == VBLK
4742 if $kgm_vtype == VCHR
4745 if $kgm_vtype == VLNK
4748 if $kgm_vtype == VSOCK
4751 if $kgm_vtype == VFIFO
4754 if $kgm_vtype == VBAD
4757 if ($kgm_vtype < VNON) || ($kgm_vtype > VBAD)
4758 printf "%5d ", $kgm_vtype
4761 printf "0x%08x ", $kgm_vnode->v_parent
4762 if $kgm_vnode->v_name != 0
4763 printf "%s\n", $kgm_vnode->v_name
4775 Syntax: (gdb) showvnode <vnode>
4776 | Display info about one vnode
4779 define showvolvnodes
4781 set $kgm_vol = (mount_t) $arg0
4782 set $kgm_vnode = (vnode_t) $kgm_vol.mnt_vnodelist.tqh_first
4784 showvnodeint $kgm_vnode
4785 set $kgm_vnode = (vnode_t) $kgm_vnode->v_mntvnodes.tqe_next
4789 document showvolvnodes
4790 Syntax: (gdb) showvolvnodes <mouont_t>
4791 | Display info about all vnodes of a given mount_t
4794 define showvolbusyvnodes
4796 set $kgm_vol = (mount_t) $arg0
4797 set $kgm_vnode = (vnode_t) $kgm_vol.mnt_vnodelist.tqh_first
4799 if $kgm_vnode->v_iocount != 0
4800 showvnodeint $kgm_vnode
4802 set $kgm_vnode = (vnode_t) $kgm_vnode->v_mntvnodes.tqe_next
4806 document showvolbusyvnodes
4807 Syntax: (gdb) showvolbusyvnodes <mount_t>
4808 | Display info about busy (iocount!=0) vnodes of a given mount_t
4811 define showallbusyvnodes
4813 set $kgm_vol = (mount_t) mountlist.tqh_first
4815 set $kgm_vnode = (vnode_t) $kgm_vol.mnt_vnodelist.tqh_first
4817 if $kgm_vnode->v_iocount != 0
4818 showvnodeint $kgm_vnode
4820 set $kgm_vnode = (vnode_t) $kgm_vnode->v_mntvnodes.tqe_next
4822 set $kgm_vol = (mount_t) $kgm_vol->mnt_list.tqe_next
4826 document showallbusyvnodes
4827 Syntax: (gdb) showallbusyvnodes <vnode>
4828 | Display info about all busy (iocount!=0) vnodes
4831 define showallvnodes
4833 set $kgm_vol = (mount_t) mountlist.tqh_first
4835 set $kgm_vnode = (vnode_t) $kgm_vol.mnt_vnodelist.tqh_first
4837 showvnodeint $kgm_vnode
4838 set $kgm_vnode = (vnode_t) $kgm_vnode->v_mntvnodes.tqe_next
4840 set $kgm_vol = (mount_t) $kgm_vol->mnt_list.tqe_next
4844 document showallvnodes
4845 Syntax: (gdb) showallvnodes
4846 | Display info about all vnodes
4849 define _showvnodelockheader
4850 printf "* type W held by lock type start end\n"
4851 printf "- ----- - ------------- --------- ------------------ ------------------\n"
4854 define _showvnodelock
4855 set $kgm_svl_lock = ((struct lockf *)$arg0)
4858 set $kgm_svl_flags = $kgm_svl_lock->lf_flags
4859 set $kgm_svl_type = $kgm_svl_lock->lf_type
4860 if ($kgm_svl_flags & 0x20)
4863 if ($kgm_svl_flags & 0x40)
4866 if ($kgm_svl_flags & 0x80)
4869 if ($kgm_svl_flags & 0x10)
4875 # POSIX file vs. advisory range locks
4876 if ($kgm_svl_flags & 0x40)
4877 set $kgm_svl_proc = (proc_t)$kgm_svl_lock->lf_id
4878 printf "PID %8d ", $kgm_svl_proc->p_pid
4880 printf "ID 0x%08x ", $kgm_svl_lock->lf_id
4884 if ($kgm_svl_type == 1)
4887 if ($kgm_svl_type == 3)
4890 if ($kgm_svl_type == 2)
4899 printf "0x%016x..", $kgm_svl_lock->lf_start
4900 printf "0x%016x ", $kgm_svl_lock->lf_end
4903 # Body of showvnodelocks, not including header
4904 define _showvnodelocks
4905 set $kgm_svl_vnode = ((vnode_t)$arg0)
4906 set $kgm_svl_lockiter = $kgm_svl_vnode->v_lockf
4907 while ($kgm_svl_lockiter != 0)
4908 # locks that are held
4910 _showvnodelock $kgm_svl_lockiter
4912 # and any locks blocked by them
4913 set $kgm_svl_blocker = $kgm_svl_lockiter->lf_blkhd.tqh_first
4914 while ($kgm_svl_blocker != 0)
4916 _showvnodelock $kgm_svl_blocker
4917 set $kgm_svl_blocker = $kgm_svl_blocker->lf_block.tqe_next
4920 # and on to the next one...
4921 set $kgm_svl_lockiter = $kgm_svl_lockiter->lf_next
4926 define showvnodelocks
4928 _showvnodelockheader
4929 _showvnodelocks $arg0
4931 printf "| Usage:\n|\n"
4936 document showvnodelocks
4937 Syntax: (gdb) showvnodelocks <vnode_t>
4938 | Given a vnodet pointer, display the list of advisory record locks for the
4939 | referenced pvnodes
4943 printf "%s\n", (char*)((boot_args*)PE_state.bootArgs).CommandLine
4946 document showbootargs
4947 Syntax: showbootargs
4948 | Display boot arguments passed to the target kernel
4951 define showbootermemorymap
4952 set $kgm_boot_args = kernelBootArgs
4953 set $kgm_msize = kernelBootArgs->MemoryMapDescriptorSize
4954 set $kgm_mcount = kernelBootArgs->MemoryMapSize / $kgm_msize
4957 printf "Type Physical Start Number of Pages\n"
4958 while $kgm_i < $kgm_mcount
4959 set $kgm_mptr = (EfiMemoryRange *)((unsigned long)kernelBootArgs->MemoryMap + $kgm_i * $kgm_msize)
4961 if $kgm_mptr->Type == 0
4964 if $kgm_mptr->Type == 1
4967 if $kgm_mptr->Type == 2
4970 if $kgm_mptr->Type == 3
4973 if $kgm_mptr->Type == 4
4976 if $kgm_mptr->Type == 5
4979 if $kgm_mptr->Type == 6
4982 if $kgm_mptr->Type == 7
4985 if $kgm_mptr->Type == 8
4988 if $kgm_mptr->Type == 9
4991 if $kgm_mptr->Type == 10
4994 if $kgm_mptr->Type == 11
4997 if $kgm_mptr->Type == 12
5000 if $kgm_mptr->Type == 13
5003 if $kgm_mptr->Type > 13
5007 printf " %016llx %016llx\n", $kgm_mptr->PhysicalStart, $kgm_mptr->NumberOfPages
5008 set $kgm_i = $kgm_i + 1
5012 document showbootermemorymap
5013 Syntax: (gdb) showbootermemorymap
5014 | Prints out the phys memory map from kernelBootArgs
5018 define showstacksaftertask
5019 set $kgm_head_taskp = &default_pset.tasks
5020 set $kgm_taskp = (struct task *)$arg0
5021 while $kgm_taskp != $kgm_head_taskp
5023 showtaskint $kgm_taskp
5024 set $kgm_head_actp = &($kgm_taskp->threads)
5025 set $kgm_actp = (struct thread *)($kgm_taskp->threads.next)
5026 while $kgm_actp != $kgm_head_actp
5028 if ($decode_wait_events > 0)
5029 showactint $kgm_actp 1
5031 showactint $kgm_actp 2
5033 set $kgm_actp = (struct thread *)($kgm_actp->task_threads.next)
5036 set $kgm_taskp = (struct task *)($kgm_taskp->pset_tasks.next)
5039 document showstacksaftertask
5040 Syntax: (gdb) showstacksaftertask <task>
5041 | Routine to print out all stacks (as in showallstacks) starting after a given task
5042 | Useful if that gdb refuses to print a certain task's stack.
5045 define showpmworkqueueint
5046 set $kgm_pm_wq = (IOPMWorkQueue *)$arg0
5047 set $kgm_pm_node = (IOService *)$kgm_pm_wq->owner
5048 printf "0x%08x 0x%08x ", $kgm_pm_wq, $kgm_pm_node
5049 printf "%02d ", $kgm_pm_node->pwrMgt->CurrentPowerState
5050 printf "%02d ", $kgm_pm_node->pwrMgt->MachineState
5051 printf "%02d ", $kgm_pm_node->pwrMgt->WaitReason
5052 printf "%s\n", $kgm_pm_node->pwrMgt->Name
5053 set $kgm_pm_queue = &($kgm_pm_wq->fWorkQueue)
5054 set $kgm_pm_req = (IOPMRequest *) $kgm_pm_queue->next
5055 while ( (queue_entry_t) $kgm_pm_req != (queue_entry_t) $kgm_pm_queue)
5056 printf " Request 0x%08x [%02x] Args ", $kgm_pm_req, $kgm_pm_req->fType
5057 printf "0x%08x ", $kgm_pm_req->fArg0
5058 printf "0x%08x ", $kgm_pm_req->fArg1
5059 printf "0x%08x\n", $kgm_pm_req->fArg2
5060 set $kgm_pm_req = (IOPMRequest *)$kgm_pm_req->fCommandChain.next
5064 define showallpmworkqueues
5065 set $kgm_pm_next = gIOPMWorkLoop->eventChain
5066 printf "WorkQueue Owner PS MS WT Name\n"
5067 printf "--------------------------------------\n"
5068 while ( $kgm_pm_next )
5069 set $kgm_vt = *((void **) $kgm_pm_next)
5070 if ($kgm_vt == _ZTV13IOPMWorkQueue)
5071 showpmworkqueueint $kgm_pm_next
5073 set $kgm_pm_next = $kgm_pm_next->eventChainNext
5077 document showallpmworkqueues
5078 Syntax: (gdb) showallpmworkqueues
5079 | Display info about all IOPMWorkQueue objects
5082 define showioservicepm
5083 set $kgm_iopmpriv = (IOServicePM *)$arg0
5084 printf "{ this object = %08x", $kgm_iopmpriv->Owner
5085 if ( $kgm_iopmpriv->WeAreRoot )
5090 printf "MachineState = %d (", $kgm_iopmpriv->MachineState
5091 if ( $kgm_iopmpriv->MachineState == 1 )
5092 printf "kIOPM_OurChangeTellClientsPowerDown"
5094 if ( $kgm_iopmpriv->MachineState == 2 )
5095 printf "kIOPM_OurChangeTellPriorityClientsPowerDown"
5097 if ( $kgm_iopmpriv->MachineState == 3 )
5098 printf "kIOPM_OurChangeNotifyInterestedDriversWillChange"
5100 if ( $kgm_iopmpriv->MachineState == 4 )
5101 printf "kIOPM_OurChangeSetPowerState"
5103 if ( $kgm_iopmpriv->MachineState == 5 )
5104 printf "kIOPM_OurChangeWaitForPowerSettle"
5106 if ( $kgm_iopmpriv->MachineState == 6 )
5107 printf "kIOPM_OurChangeNotifyInterestedDriversDidChange"
5109 if ( $kgm_iopmpriv->MachineState == 7 )
5110 printf "kIOPM_OurChangeFinish"
5112 if ( $kgm_iopmpriv->MachineState == 8 )
5113 printf "kIOPM_ParentDownTellPriorityClientsPowerDown"
5115 if ( $kgm_iopmpriv->MachineState == 9 )
5116 printf "kIOPM_ParentDownNotifyInterestedDriversWillChange"
5118 if ( $kgm_iopmpriv->MachineState == 10 )
5119 printf "Unused_MachineState_10"
5121 if ( $kgm_iopmpriv->MachineState == 11 )
5122 printf "kIOPM_ParentDownNotifyDidChangeAndAcknowledgeChange"
5124 if ( $kgm_iopmpriv->MachineState == 12 )
5125 printf "kIOPM_ParentDownSetPowerState"
5127 if ( $kgm_iopmpriv->MachineState == 13 )
5128 printf "kIOPM_ParentDownWaitForPowerSettle"
5130 if ( $kgm_iopmpriv->MachineState == 14 )
5131 printf "kIOPM_ParentDownAcknowledgeChange"
5133 if ( $kgm_iopmpriv->MachineState == 15)
5134 printf "kIOPM_ParentUpSetPowerState"
5136 if ( $kgm_iopmpriv->MachineState == 16)
5137 printf "Unused_MachineState_16"
5139 if ( $kgm_iopmpriv->MachineState == 17)
5140 printf "kIOPM_ParentUpWaitForSettleTime"
5142 if ( $kgm_iopmpriv->MachineState == 18)
5143 printf "kIOPM_ParentUpNotifyInterestedDriversDidChange"
5145 if ( $kgm_iopmpriv->MachineState == 19)
5146 printf "kIOPM_ParentUpAcknowledgePowerChange"
5148 if ( $kgm_iopmpriv->MachineState == 20)
5149 printf "kIOPM_Finished"
5151 if ( $kgm_iopmpriv->MachineState == 21)
5152 printf "kIOPM_DriverThreadCallDone"
5154 if ( $kgm_iopmpriv->MachineState == 22)
5155 printf "kIOPM_NotifyChildrenDone"
5180 if ( $kgm_iopmpriv->MachineState != 20 )
5181 printf "DriverTimer = %d, ",(unsigned int)$kgm_iopmpriv->DriverTimer
5182 printf "SettleTime = %d, ",(unsigned int)$kgm_iopmpriv->SettleTimeUS
5183 printf "HeadNoteFlags = %08x, ",(unsigned int)$kgm_iopmpriv->HeadNoteFlags
5184 printf "HeadNoteState = %d, ",(unsigned int)$kgm_iopmpriv->HeadNoteState
5185 printf "HeadNoteOutputFlags = %08x, ",(unsigned int)$kgm_iopmpriv->HeadNoteOutputFlags
5186 printf "HeadNoteDomainState = %08x, ",(unsigned int)$kgm_iopmpriv->HeadNoteDomainState
5187 printf "HeadNoteCapabilityFlags = %08x, ",(unsigned int)$kgm_iopmpriv->HeadNoteCapabilityFlags
5188 printf "HeadNotePendingAcks = %x, ",(unsigned int)$kgm_iopmpriv->HeadNotePendingAcks
5191 if ( $kgm_iopmpriv->DeviceOverrides != 0 )
5192 printf"DeviceOverrides, "
5195 printf "DriverDesire = %d, ",(unsigned int)$kgm_iopmpriv->DriverDesire
5196 printf "DeviceDesire = %d, ",(unsigned int)$kgm_iopmpriv->DeviceDesire
5197 printf "DesiredPowerState = %d, ",(unsigned int)$kgm_iopmpriv->DesiredPowerState
5198 printf "PreviousRequest = %d }",(unsigned int)$kgm_iopmpriv->PreviousRequest
5201 document showioservicepm
5202 Syntax: (gdb) showioservicepm <IOServicePM pointer>
5203 | Routine to dump the IOServicePM object
5206 define showregistryentryrecursepmstate
5207 set $kgm_re = (IOService *)$arg1
5208 set $kgm$arg0_stack = (unsigned long long) $arg2
5211 set $kgm$arg0_stack = $kgm$arg0_stack | (1ULL << $kgm_reg_depth)
5213 set $kgm$arg0_stack = $kgm$arg0_stack & ~(1ULL << $kgm_reg_depth)
5216 dictget $kgm_re->fRegistryTable $kgm_childkey
5217 set $kgm$arg0_child_array = (OSArray *) $kgm_result
5219 if ($kgm$arg0_child_array)
5220 set $kgm$arg0_child_count = $kgm$arg0_child_array->count
5222 set $kgm$arg0_child_count = 0
5225 if ($kgm$arg0_child_count)
5226 set $kgm$arg0_stack = $kgm$arg0_stack | (2ULL << $kgm_reg_depth)
5228 set $kgm$arg0_stack = $kgm$arg0_stack & ~(2ULL << $kgm_reg_depth)
5231 indent $kgm_reg_depth $kgm$arg0_stack
5234 dictget $kgm_re->fRegistryTable $kgm_namekey
5235 if ($kgm_result == 0)
5236 dictget $kgm_re->fRegistryTable gIONameKey
5238 if ($kgm_result == 0)
5239 dictget $kgm_re->fPropertyTable gIOClassKey
5242 if ($kgm_result != 0)
5243 printf "%s <%p>", ((OSString *)$kgm_result)->string, $kgm_re
5245 if (((IOService*)$kgm_re)->pwrMgt && ((IOService*)$kgm_re)->pwrMgt->Name)
5246 printf "%s <%p>", ((IOService*)$kgm_re)->pwrMgt->Name, $kgm_re
5248 printf "?? <%p>", $kgm_re
5252 if (((IOService*)$kgm_re)->pwrMgt )
5253 printf " Current Power State: %ld ", ((IOService*)$kgm_re)->pwrMgt->CurrentPowerState
5254 #printf " Mach State %ld", ((IOService*)$kgm_re)->pwrMgt->MachineState
5255 showioservicepm ((IOService*)$kgm_re)->pwrMgt
5261 if ($kgm$arg0_child_count != 0)
5263 set $kgm_reg_depth = $kgm_reg_depth + 1
5264 set $kgm$arg0_child_idx = 0
5266 while ($kgm$arg0_child_idx < $kgm$arg0_child_count)
5267 set $kgm_re = $kgm$arg0_child_array->array[$kgm$arg0_child_idx++]
5268 set $kgm_more_sib = ($kgm$arg0_child_idx < $kgm$arg0_child_count)
5269 showregistryentryrecursepmstate _$arg0 $kgm_re $kgm$arg0_stack $kgm_more_sib
5272 set $kgm_reg_depth = $kgm_reg_depth - 1
5276 define showregistryentryintpmstate
5277 set $kgm_namekey = (OSSymbol *) $kgm_reg_plane[2]
5278 set $kgm_childkey = (OSSymbol *) $kgm_reg_plane[4]
5279 showregistryentryrecursepmstate _ $arg0 0 0
5282 define showregistrypmstate
5283 # setregistryplane gIOPowerPlane
5284 set $kgm_reg_depth = 0
5285 set $kgm_show_props = 1
5286 showregistryentryintpmstate gRegistryRoot
5289 document showregistrypmstate
5290 Syntax: (gdb) showregistrypmstate
5291 | Routine to dump the PM state of each IOPower registry entry
5294 define showstacksafterthread
5295 set $kgm_head_taskp = &default_pset.tasks
5296 set $kgm_actp = (struct thread *)$arg0
5297 set $kgm_actp = (struct thread *)($kgm_actp->task_threads.next)
5298 set $kgm_taskp = (struct task *)$kgm_actp->task
5299 while $kgm_taskp != $kgm_head_taskp
5301 showtaskint $kgm_taskp
5302 set $kgm_head_actp = &($kgm_taskp->threads)
5303 while $kgm_actp != $kgm_head_actp
5305 if ($decode_wait_events > 0)
5306 showactint $kgm_actp 1
5308 showactint $kgm_actp 2
5310 set $kgm_actp = (struct thread *)($kgm_actp->task_threads.next)
5313 set $kgm_taskp = (struct task *)($kgm_taskp->pset_tasks.next)
5317 document showstacksafterthread
5318 Syntax: (gdb) showstacksafterthread <thread>
5319 | Routine to print out all stacks (as in showallstacks) starting after a given thread
5320 | Useful if that gdb refuses to print a certain task's stack.
5324 set kdp_reentry_deadline = ((unsigned) $arg0)*1000
5328 document kdp-reenter
5329 Syntax: (gdb) kdp-reenter <seconds>
5330 | Schedules reentry into the debugger after <seconds> seconds, and resumes
5331 | the target system.
5342 if ($kgm_mtype != 7)
5343 printf "Not available for current architecture.\n"
5346 _if_present mca_MCA_present
5347 printf ", control MSR"
5348 _if_present mca_control_MSR_present
5349 printf ", threshold status"
5350 _if_present mca_threshold_status_present
5351 printf "\n%d error banks, ", mca_error_bank_count
5352 printf "family code 0x%x, ", mca_family
5353 printf "machine-check exception taken: %d\n", mca_exception_taken
5355 while cpu_data_ptr[$kgm_cpu] != 0
5356 set $kgm_mcp = cpu_data_ptr[$kgm_cpu]->cpu_mca_state
5358 printf "CPU %d:", $kgm_cpu
5359 printf " mca_mcg_ctl: 0x%016llx", $kgm_mcp->mca_mcg_ctl
5360 printf " mca_mcg_status: 0x%016llx\n", $kgm_mcp->mca_mcg_status.u64
5362 printf "mca_mci_ctl "
5363 printf "mca_mci_status "
5364 printf "mca_mci_addr "
5365 printf "mca_mci_misc\n"
5367 while $kgm_bank < mca_error_bank_count
5368 set $kgm_bp = &$kgm_mcp->mca_error_bank[$kgm_bank]
5369 printf " %2d:", $kgm_bank
5370 printf " 0x%016llx", $kgm_bp->mca_mci_ctl
5371 printf " 0x%016llx", $kgm_bp->mca_mci_status.u64
5372 printf " 0x%016llx", $kgm_bp->mca_mci_addr
5373 printf " 0x%016llx\n", $kgm_bp->mca_mci_misc
5374 set $kgm_bank = $kgm_bank + 1
5377 set $kgm_cpu = $kgm_cpu + 1
5382 document showMCAstate
5383 Syntax: showMCAstate
5384 | Print machine-check register state after MC exception.
5389 # Step to lower-level page table and print attributes
5390 # $kgm_pt_paddr: current page table entry physical address
5391 # $kgm_pt_index: current page table entry index (0..511)
5393 # $kgm_pt_paddr: next level page table entry physical address
5394 # or null if invalid
5395 # For $kgm_pt_verbose = 0: print nothing
5396 # 1: print basic information
5397 # 2: print basic information and hex table dump
5398 # The trickery with kdp_src_high32 is required for accesses above 4GB.
5400 set $kgm_entryp = $kgm_pt_paddr + 8*$kgm_pt_index
5401 set kdp_src_high32 = $kgm_pt_paddr >> 32
5402 set kdp_trans_off = 1
5403 set $entry = *(pt_entry_t *)($kgm_entryp & 0x0ffffffffULL)
5404 if $kgm_pt_verbose == 2
5405 x/512g ($kgm_pt_paddr & 0x0ffffffffULL)
5407 set kdp_trans_off = 0
5408 set kdp_src_high32 = 0
5409 set $kgm_paddr_mask = ~((0xffffULL<<48) | 0xfffULL)
5410 if $kgm_pt_verbose == 0
5411 if $entry & (0x1 << 0)
5412 set $kgm_pt_paddr = $entry & $kgm_paddr_mask
5414 set $kgm_pt_paddr = 0
5417 printf "0x%016llx:\n\t0x%016llx\n\t", $kgm_entryp, $entry
5418 if $entry & (0x1 << 0)
5420 set $kgm_pt_paddr = $entry & $kgm_paddr_mask
5423 set $kgm_pt_paddr = 0
5425 if $entry & (0x1 << 1)
5430 if $entry & (0x1 << 2)
5433 printf " supervisor"
5435 if $entry & (0x1 << 3)
5438 if $entry & (0x1 << 4)
5441 if $entry & (0x1 << 5)
5444 if $entry & (0x1 << 6)
5447 if $entry & (0x1 << 7)
5450 if $entry & (0x1 << 8)
5453 if $entry & (0x3 << 9)
5454 printf " avail:0x%x", ($entry >> 9) & 0x3
5456 if $entry & (0x1 << 63)
5464 set $kgm_pmap = (pmap_t) $arg0
5465 set $kgm_vaddr = $arg1
5466 set $kgm_pt_paddr = $kgm_pmap->pm_cr3
5467 if $kgm_pt_paddr && cpu_64bit
5468 set $kgm_pt_index = ($kgm_vaddr >> 39) & 0x1ffULL
5470 printf "pml4 (index %d):\n", $kgm_pt_index
5475 set $kgm_pt_index = ($kgm_vaddr >> 30) & 0x1ffULL
5477 printf "pdpt (index %d):\n", $kgm_pt_index
5482 set $kgm_pt_index = ($kgm_vaddr >> 21) & 0x1ffULL
5484 printf "pdt (index %d):\n", $kgm_pt_index
5489 set $kgm_pt_index = ($kgm_vaddr >> 12) & 0x1ffULL
5491 printf "pt (index %d):\n", $kgm_pt_index
5496 set $kgm_paddr = $kgm_pt_paddr + ($kgm_vaddr & 0xfffULL)
5497 set kdp_trans_off = 1
5498 set kdp_src_high32 = $kgm_paddr >> 32
5499 set $kgm_value = *($kgm_paddr & 0x0ffffffffULL)
5500 set kdp_trans_off = 0
5501 set kdp_src_high32 = 0
5502 printf "phys 0x%016llx: 0x%08x\n", $kgm_paddr, $kgm_value
5505 printf "(no translation)\n"
5511 printf "Not available for current architecture.\n"
5514 printf "pmap_walk <pmap> <vaddr>\n"
5517 set $kgm_pt_verbose = 1
5519 if $kgm_pt_verbose != 2
5520 set $kgm_pt_verbose = 1
5523 _pmap_walk $arg0 $arg1
5529 Syntax: (gdb) pmap_walk <pmap> <virtual_address>
5530 | Perform a page-table walk in <pmap> for <virtual_address>.
5531 | Set $kgm_pt_verbose=2 for full hex dump of page tables.
5536 printf "Not available for current architecture.\n"
5539 printf "pmap_vtop <pamp> <vaddr>\n"
5541 set $kgm_pt_verbose = 0
5542 _pmap_walk $arg0 $arg1
5548 Syntax: (gdb) pmap_vtop <pmap> <virtual_address>
5549 | For page-tables in <pmap> translate <virtual_address> to physical address.