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 if ($kgm_mtype == 7)
1964 set $newact = (struct thread *) $arg0
1965 #This needs to identify 64-bit processes as well
1966 set $newiss = (x86_saved_state32_t) ($newact->machine.pcb->iss.uss.ss_32)
1967 set $checkpc = $newiss.eip
1969 echo This activation does not appear to have
1970 echo \20 a valid user context.\n
1972 set $kgm_cur_ebp = $newiss.ebp
1973 set $kgm_cur_eip = $checkpc
1974 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
1975 set kdp_pmap = $newact->task->map->pmap
1980 echo showuserstack not supported on this architecture\n
1984 document showuserstack
1985 Syntax: showuserstack <address of thread activation>
1986 |This command displays a numeric backtrace for the user space stack of
1987 |the given thread activation. It may, of course, fail to display a
1988 |complete backtrace if portions of the user stack are not mapped in.
1989 |Symbolic backtraces can be obtained either by running gdb on the
1990 |user space binary, or a tool such as "symbolicate".
1991 |Note that while this command works on Panther's gdb, an issue
1992 |with Tiger gdb (3743135) appears to hamper the evaluation of this
1993 |macro in some cases.
1996 #Stopgap until gdb can generate the HOSTREBOOT packet
1998 #Alternatively, set *(*(unsigned **) 0x2498) = 1 (or 0x5498 on PPC)
1999 set flag_kdp_trigger_reboot = 1
2005 |Reboot the remote target machine; not guaranteed to succeed. Requires symbols
2006 |until gdb support for the HOSTREBOOT packet is implemented.
2010 set kdp_trigger_core_dump = 1
2011 set kdp_flag |= 0x40
2012 set panicd_ip_str = "$arg0"
2013 set panicd_specified = 1
2014 set disable_debug_output = 0
2015 set disableConsoleOutput = 0
2016 set logPanicDataToScreen = 1
2017 set reattach_wait = 1
2022 Syntax: sendcore <IP address>
2023 |Configure the kernel to transmit a kernel coredump to a server (kdumpd)
2024 |at the specified IP address. This is useful when the remote target has
2025 |not been previously configured to transmit coredumps, and you wish to
2026 |preserve kernel state for later examination. NOTE: You must issue a "continue"
2027 |command after using this macro to trigger the kernel coredump. The kernel
2028 |will resume waiting in the debugger after completion of the coredump. You
2029 |may disable coredumps by executing the "disablecore" macro.
2033 set kdp_trigger_core_dump = 0
2034 set kdp_flag |= 0x40
2035 set kdp_flag &= ~0x10
2036 set panicd_specified = 0
2039 document disablecore
2041 |Reconfigures the kernel so that it no longer transmits kernel coredumps. This
2042 |complements the "sendcore" macro, but it may be used if the kernel has been
2043 |configured to transmit coredumps through boot-args as well.
2046 define switchtocorethread
2047 set $newact = (struct thread *) $arg0
2049 if ($newact->kernel_stack == 0)
2050 echo This thread does not have a stack.\n
2052 output/a (unsigned) $newact.continuation
2055 if ($kgm_mtype == 18)
2056 loadcontext $newact->machine->pcb
2058 set $pc = $newact->machine->pcb.save_srr0
2060 if ($kgm_mtype == 7)
2061 set $kgm_cstatep = (struct x86_kernel_state32 *) \
2062 ($newact->kernel_stack + 0x4000 \
2063 - sizeof(struct x86_kernel_state32))
2064 loadcontext $kgm_cstatep
2067 echo switchtocorethread not supported on this architecture\n
2074 document switchtocorethread
2075 Syntax: switchtocorethread <address of activation>
2076 | The corefile equivalent of "switchtoact". When debugging a kernel coredump
2077 | file, this command can be used to examine the execution context and stack
2078 | trace for a given thread activation. For example, to view the backtrace
2079 | for a thread issue "switchtocorethread <address>", followed by "bt".
2080 | Before resuming execution, issue a "resetcorectx" command, to
2081 | return to the original execution context. Note that this command
2082 | requires gdb support, as documented in Radar 3401283.
2087 if ($kgm_mtype == 18)
2088 set $kgm_contextp = (struct savearea *) $arg0
2089 set $pc = $kgm_contextp.save_srr0
2090 set $r1 = $kgm_contextp.save_r1
2091 set $lr = $kgm_contextp.save_lr
2093 set $r2 = $kgm_contextp.save_r2
2094 set $r3 = $kgm_contextp.save_r3
2095 set $r4 = $kgm_contextp.save_r4
2096 set $r5 = $kgm_contextp.save_r5
2097 set $r6 = $kgm_contextp.save_r6
2098 set $r7 = $kgm_contextp.save_r7
2099 set $r8 = $kgm_contextp.save_r8
2100 set $r9 = $kgm_contextp.save_r9
2101 set $r10 = $kgm_contextp.save_r10
2102 set $r11 = $kgm_contextp.save_r11
2103 set $r12 = $kgm_contextp.save_r12
2104 set $r13 = $kgm_contextp.save_r13
2105 set $r14 = $kgm_contextp.save_r14
2106 set $r15 = $kgm_contextp.save_r15
2107 set $r16 = $kgm_contextp.save_r16
2108 set $r17 = $kgm_contextp.save_r17
2109 set $r18 = $kgm_contextp.save_r18
2110 set $r19 = $kgm_contextp.save_r19
2111 set $r20 = $kgm_contextp.save_r20
2112 set $r21 = $kgm_contextp.save_r21
2113 set $r22 = $kgm_contextp.save_r22
2114 set $r23 = $kgm_contextp.save_r23
2115 set $r24 = $kgm_contextp.save_r24
2116 set $r25 = $kgm_contextp.save_r25
2117 set $r26 = $kgm_contextp.save_r26
2118 set $r27 = $kgm_contextp.save_r27
2119 set $r28 = $kgm_contextp.save_r28
2120 set $r29 = $kgm_contextp.save_r29
2121 set $r30 = $kgm_contextp.save_r30
2122 set $r31 = $kgm_contextp.save_r31
2124 set $cr = $kgm_contextp.save_cr
2125 set $ctr = $kgm_contextp.save_ctr
2127 if ($kgm_mtype == 7)
2128 set $kgm_contextp = (struct x86_kernel_state32 *) $arg0
2129 set $ebx = $kgm_contextp->k_ebx
2130 set $ebp = $kgm_contextp->k_ebp
2131 set $edi = $kgm_contextp->k_edi
2132 set $esi = $kgm_contextp->k_esi
2133 set $eip = $kgm_contextp->k_eip
2134 set $pc = $kgm_contextp->k_eip
2136 echo loadcontext not supported on this architecture\n
2143 if ($kgm_mtype == 18)
2144 set $kgm_corecontext = (struct savearea *) kdp.saved_state
2145 loadcontext $kgm_corecontext
2147 if ($kgm_mtype == 7)
2148 set $kdpstatep = (struct x86_saved_state32 *) kdp.saved_state
2149 set $ebx = $kdpstatep->ebx
2150 set $ebp = $kdpstatep->ebp
2151 set $edi = $kdpstatep->edi
2152 set $esi = $kdpstatep->esi
2153 set $eip = $kdpstatep->eip
2154 set $eax = $kdpstatep->eax
2155 set $ecx = $kdpstatep->ecx
2156 set $edx = $kdpstatep->edx
2159 set $pc = $kdpstatep->eip
2162 echo resetcorectx not supported on this architecture\n
2168 document resetcorectx
2169 Syntax: resetcorectx
2170 | The corefile equivalent of "resetctx". Returns to the original
2171 | execution context (that of the active thread at the time of the NMI or
2172 | panic). This command should be issued if you wish to resume
2173 | execution after using the "switchtocorethread" command.
2176 #Helper function for "showallgdbstacks"
2178 define showgdbthread
2179 printf " 0x%08x ", $arg0
2180 set $kgm_thread = *(struct thread *)$arg0
2181 printf "0x%08x ", $arg0
2182 printf "%3d ", $kgm_thread.sched_pri
2183 set $kgm_state = $kgm_thread.state
2184 if $kgm_state & 0x80
2187 if $kgm_state & 0x40
2190 if $kgm_state & 0x20
2193 if $kgm_state & 0x10
2196 if $kgm_state & 0x08
2199 if $kgm_state & 0x04
2202 if $kgm_state & 0x02
2205 if $kgm_state & 0x01
2207 printf "0x%08x ", $kgm_thread.wait_queue
2208 output /a (unsigned) $kgm_thread.wait_event
2209 if ($kgm_thread.uthread != 0)
2210 set $kgm_uthread = (struct uthread *)$kgm_thread.uthread
2211 if ($kgm_uthread->uu_wmesg != 0)
2212 printf " \"%s\"", $kgm_uthread->uu_wmesg
2217 if ($kgm_thread.kernel_stack != 0)
2218 if ($kgm_thread.reserved_stack != 0)
2219 printf "\n\t\treserved_stack=0x%08x", $kgm_thread.reserved_stack
2221 printf "\n\t\tkernel_stack=0x%08x", $kgm_thread.kernel_stack
2222 if ($kgm_mtype == 18)
2223 set $mysp = $kgm_thread.machine.pcb->save_r1
2225 if ($kgm_mtype == 7)
2226 set $kgm_statep = (struct x86_kernel_state32 *) \
2227 ($kgm_thread->kernel_stack + 0x4000 \
2228 - sizeof(struct x86_kernel_state32))
2229 set $mysp = $kgm_statep->k_ebp
2231 if ($kgm_mtype == 12)
2235 set $kgm_statep = (struct arm_saved_state *)$kgm_thread.machine.kstackptr
2236 set $mysp = $kgm_statep->r[7]
2240 printf "\n\t\tstacktop=0x%08x", $mysp
2244 switchtocorethread $arg0
2248 printf "\n\t\t\tcontinuation="
2249 output /a (unsigned) $kgm_thread.continuation
2257 #Use of this macro is currently (8/04) blocked by the fact that gdb
2258 #stops evaluating macros when encountering an error, such as a failure
2259 #to read memory from a certain location. Until this issue (described in
2260 #3758949) is addressed, evaluation of this macro may stop upon
2261 #encountering such an error.
2263 define showallgdbstacks
2264 set $kgm_head_taskp = &tasks
2265 set $kgm_taskp = (struct task *)($kgm_head_taskp->next)
2266 while $kgm_taskp != $kgm_head_taskp
2268 showtaskint $kgm_taskp
2269 set $kgm_head_actp = &($kgm_taskp->threads)
2270 set $kgm_actp = (struct thread *)($kgm_taskp->threads.next)
2271 while $kgm_actp != $kgm_head_actp
2273 showgdbthread $kgm_actp 1 0
2274 set $kgm_actp = (struct thread *)($kgm_actp->task_threads.next)
2277 set $kgm_taskp = (struct task *)($kgm_taskp->tasks.next)
2282 document showallgdbstacks
2283 Syntax: showallgdbstacks
2284 | An alternative to "showallstacks". Iterates through the task list and
2285 | displays a gdb generated backtrace for each kernel thread. It is
2286 | advantageous in that it is much faster than "showallstacks", and
2287 | decodes function call arguments and displays source level traces, but
2288 | it has the drawback that it doesn't determine if frames belong to
2289 | functions from kernel extensions, as with "showallstacks".
2290 | This command may terminate prematurely because of a gdb bug
2291 | (Radar 3758949), which stops macro evaluation on memory read
2295 define showallgdbcorestacks
2297 set $kgm_head_taskp = &tasks
2298 set $kgm_taskp = (struct task *)($kgm_head_taskp->next)
2299 while $kgm_taskp != $kgm_head_taskp
2301 showtaskint $kgm_taskp
2302 set $kgm_head_actp = &($kgm_taskp->threads)
2303 set $kgm_actp = (struct thread *)($kgm_taskp->threads.next)
2304 while $kgm_actp != $kgm_head_actp
2306 showgdbthread $kgm_actp 1 1
2307 set $kgm_actp = (struct thread *)($kgm_actp->task_threads.next)
2310 set $kgm_taskp = (struct task *)($kgm_taskp->tasks.next)
2316 document showallgdbcorestacks
2317 Syntax: showallgdbcorestacks
2318 |Corefile version of "showallgdbstacks"
2322 define switchtouserthread
2324 if ($kgm_mtype == 18)
2325 if ($kdp_act_counter == 0)
2326 set $kdpstate = (struct savearea *) kdp.saved_state
2328 set $kdp_act_counter = $kdp_act_counter + 1
2329 set $newact = (struct thread *) $arg0
2331 set $checkpc = $newact->machine->upcb.save_srr0
2333 echo This activation does not appear to have
2334 echo \20 a valid user context.\n
2336 set (struct savearea *) kdp.saved_state=$newact->machine->upcb
2338 #flush and update seem to be executed lazily by gdb on Tiger, hence the
2339 #repeated invocations - see 3743135
2341 # This works because the new pmap is used only for reads
2342 set kdp_pmap = $newact->task->map->pmap
2347 echo switchtouserthread not implemented for this architecture.\n
2351 document switchtouserthread
2352 Syntax: switchtouserthread <address of thread>
2353 | Analogous to switchtoact, but switches to the user context of a
2354 | specified thread address. Similar to the "showuserstack"
2355 | command, but this command does not return gdb to the kernel context
2356 | immediately. This is to assist with the following (rather risky)
2357 | manoeuvre - upon switching to the user context and virtual address
2358 | space, the user may choose to call remove-symbol-file on the
2359 | mach_kernel symbol file, and then add-symbol-file on the user space
2360 | binary's symfile. gdb can then generate symbolic backtraces
2361 | for the user space thread. To return to the
2362 | kernel context and virtual address space, the process must be
2363 | reversed, i.e. call remove-symbol-file on the user space symbols, and
2364 | then add-symbol-file on the appropriate mach_kernel, and issue the
2365 | "resetstacks" command. Note that gdb may not react kindly to all these
2366 | symbol file switches. The same restrictions that apply to "showuserstack"
2367 | apply here - pages that have been paged out cannot be read while in the
2368 | debugger context, so backtraces may terminate early.
2369 | If the virtual addresses in the stack trace do not conflict with those
2370 | of symbols in the kernel's address space, it may be sufficient to
2371 | just do an add-symbol-file on the user space binary's symbol file.
2372 | Note that while this command works on Panther's gdb, an issue
2373 | with Tiger gdb (3743135) appears to hamper the evaluation of this
2374 | macro in some cases.
2377 define showmetaclass
2378 set $kgm_metaclassp = (OSMetaClass *)$arg0
2379 printf "%-5d", $kgm_metaclassp->instanceCount
2380 printf "x %5d bytes", $kgm_metaclassp->classSize
2381 printf " %s\n", $kgm_metaclassp->className->string
2385 printf "\"%s\"", ((OSString *)$arg0)->string
2389 printf "%lld", ((OSNumber *)$arg0)->value
2393 if ($arg0 == gOSBooleanFalse)
2401 set $kgm_data = (OSData *)$arg0
2404 set $kgm_datap = (const unsigned char *) $kgm_data->data
2406 set $kgm_printstr = 0
2407 if (0 == (3 & (unsigned int)$kgm_datap) && ($kgm_data->length >= 3))
2408 set $kgm_bytes = *(unsigned int *) $kgm_datap
2409 if (0xffff0000 & $kgm_bytes)
2411 set $kgm_printstr = 1
2412 while ($kgm_idx++ < 4)
2413 set $kgm_bytes = $kgm_bytes >> 8
2414 set $kgm_char = 0xff & $kgm_bytes
2415 if ($kgm_char && (($kgm_char < 0x20) || ($kgm_char > 0x7e)))
2416 set $kgm_printstr = 0
2425 while ($kgm_idx < $kgm_data->length)
2426 set $kgm_char = $kgm_datap[$kgm_idx++]
2428 if (0 == $kgm_quoted)
2436 printf "%c", $kgm_char
2448 if (0 == (3 & (unsigned int)$kgm_datap))
2449 while (($kgm_idx + 3) <= $kgm_data->length)
2450 printf "%08x", *(unsigned int *) &$kgm_datap[$kgm_idx]
2451 set $kgm_idx = $kgm_idx + 4
2454 while ($kgm_idx < $kgm_data->length)
2455 printf "%02x", $kgm_datap[$kgm_idx++]
2461 define showdictionaryint
2462 set $kgm$arg0_dict = (OSDictionary *)$arg1
2465 set $kgm$arg0_idx = 0
2466 while ($kgm$arg0_idx < $kgm$arg0_dict->count)
2467 set $kgm_obj = $kgm$arg0_dict->dictionary[$kgm$arg0_idx].key
2468 showobjectint _$arg0 $kgm_obj
2470 set $kgm_obj = $kgm$arg0_dict->dictionary[$kgm$arg0_idx++].value
2471 showobjectint _$arg0 $kgm_obj
2472 if ($kgm$arg0_idx < $kgm$arg0_dict->count)
2481 while ($kgm_idx < $arg0)
2482 if ($arg1 & (1 << $kgm_idx++))
2490 define showregdictionary
2491 indent $kgm_reg_depth+2 $arg1
2494 set $kgm_reg_idx = 0
2495 while ($kgm_reg_idx < $arg0->count)
2496 indent $kgm_reg_depth+2 $arg1
2498 set $kgm_obj = $arg0->dictionary[$kgm_reg_idx].key
2499 showobjectint _ $kgm_obj
2502 set $kgm_obj = $arg0->dictionary[$kgm_reg_idx++].value
2503 showobjectint _ $kgm_obj
2506 indent $kgm_reg_depth+2 $arg1
2511 define showarraysetint
2512 set $kgm$arg0_array = (OSArray *)$arg1
2514 set $kgm$arg0_idx = 0
2515 while ($kgm$arg0_idx < $kgm$arg0_array->count)
2516 set $kgm_obj = $kgm$arg0_array->array[$kgm$arg0_idx++]
2517 showobjectint _$arg0 $kgm_obj
2518 if ($kgm$arg0_idx < $kgm$arg0_array->count)
2526 showarraysetint $arg0 $arg1
2531 set $kgm_array = ((OSSet *)$arg1)->members
2533 showarraysetint $arg0 $kgm_array
2538 define showobjectint
2539 set $kgm_obj = (OSObject *) $arg1
2540 set $kgm_vt = *((void **) $arg1)
2542 if ($kgm_show_object_addrs)
2543 printf "`object %p, vt ", $arg1
2544 output /a (unsigned) $kgm_vt
2545 if ($kgm_show_object_retain)
2546 printf ", retain count %d, container retain %d", (0xffff & $kgm_obj->retainCount), $kgm_obj->retainCount >> 16
2551 if ($kgm_vt == _ZTV8OSString)
2554 if ($kgm_vt == _ZTV8OSSymbol)
2557 if ($kgm_vt == _ZTV8OSNumber)
2560 if ($kgm_vt == _ZTV6OSData)
2563 if ($kgm_vt == _ZTV9OSBoolean)
2566 if ($kgm_vt == _ZTV12OSDictionary)
2567 showdictionaryint _$arg0 $arg1
2569 if ($kgm_vt == _ZTV7OSArray)
2570 showarrayint _$arg0 $arg1
2572 if ($kgm_vt == _ZTV5OSSet)
2573 showsetint _$arg0 $arg1
2575 if ($kgm_show_object_addrs == 0)
2576 printf "`object %p, vt ", $arg1
2577 output /a (unsigned) $kgm_vt
2591 set $kgm_save = $kgm_show_object_addrs
2592 set $kgm_show_object_addrs = 1
2593 set $kgm_show_object_retain = 1
2594 showobjectint _ $arg0
2595 set $kgm_show_object_addrs = $kgm_save
2596 set $kgm_show_object_retain = 0
2600 Syntax: (gdb) showobject <object address>
2601 | Show info about an OSObject - its vtable ptr and retain count.
2602 | If the object is a simple container class, more info will be shown.
2606 set $kgm_dictp = (OSDictionary *)$arg0
2607 set $kgm_keyp = (const OSSymbol *)$arg1
2610 while (($kgm_idx < $kgm_dictp->count) && ($kgm_result == 0))
2611 if ($kgm_keyp == $kgm_dictp->dictionary[$kgm_idx].key)
2612 set $kgm_result = $kgm_dictp->dictionary[$kgm_idx].value
2614 set $kgm_idx = $kgm_idx + 1
2619 define showregistryentryrecurse
2620 set $kgm_re = (IOService *)$arg1
2621 set $kgm$arg0_stack = (unsigned long long) $arg2
2624 set $kgm$arg0_stack = $kgm$arg0_stack | (1ULL << $kgm_reg_depth)
2626 set $kgm$arg0_stack = $kgm$arg0_stack & ~(1ULL << $kgm_reg_depth)
2629 dictget $kgm_re->fRegistryTable $kgm_childkey
2630 set $kgm$arg0_child_array = (OSArray *) $kgm_result
2632 if ($kgm$arg0_child_array)
2633 set $kgm$arg0_child_count = $kgm$arg0_child_array->count
2635 set $kgm$arg0_child_count = 0
2638 if ($kgm$arg0_child_count)
2639 set $kgm$arg0_stack = $kgm$arg0_stack | (2ULL << $kgm_reg_depth)
2641 set $kgm$arg0_stack = $kgm$arg0_stack & ~(2ULL << $kgm_reg_depth)
2644 indent $kgm_reg_depth $kgm$arg0_stack
2647 dictget $kgm_re->fRegistryTable $kgm_namekey
2648 if ($kgm_result == 0)
2649 dictget $kgm_re->fRegistryTable gIONameKey
2651 if ($kgm_result == 0)
2652 dictget $kgm_re->fPropertyTable gIOClassKey
2655 if ($kgm_result != 0)
2656 printf "%s", ((OSString *)$kgm_result)->string
2658 if (((IOService*)$kgm_re)->pwrMgt && ((IOService*)$kgm_re)->pwrMgt->Name)
2659 printf "%s", ((IOService*)$kgm_re)->pwrMgt->Name
2661 # printf ", guessclass "
2662 # guessclass $kgm_re
2668 printf " <object %p, ", $kgm_re
2670 set $kgm_vt = (unsigned) *(void**) $kgm_re
2673 if ($kgm_vt != _ZTV15IORegistryEntry)
2675 set $kgm_state = $kgm_re->__state[0]
2676 # kIOServiceRegisteredState
2677 if (0 == ($kgm_state & 2))
2680 printf "registered, "
2681 # kIOServiceMatchedState
2682 if (0 == ($kgm_state & 4))
2686 # kIOServiceInactiveState
2690 printf "active, busy %d, retain count %d", (0xff & $kgm_re->__state[1]), (0xffff & $kgm_re->retainCount)
2694 if ($kgm_show_props)
2695 set $kgm_props = $kgm_re->fPropertyTable
2696 showregdictionary $kgm_props $kgm$arg0_stack
2700 if ($kgm$arg0_child_count != 0)
2702 set $kgm_reg_depth = $kgm_reg_depth + 1
2703 set $kgm$arg0_child_idx = 0
2705 while ($kgm$arg0_child_idx < $kgm$arg0_child_count)
2706 set $kgm_re = $kgm$arg0_child_array->array[$kgm$arg0_child_idx++]
2707 set $kgm_more_sib = ($kgm$arg0_child_idx < $kgm$arg0_child_count)
2708 showregistryentryrecurse _$arg0 $kgm_re $kgm$arg0_stack $kgm_more_sib
2711 set $kgm_reg_depth = $kgm_reg_depth - 1
2715 define showregistryentryint
2716 set $kgm_namekey = (OSSymbol *) $kgm_reg_plane[2]
2717 set $kgm_childkey = (OSSymbol *) $kgm_reg_plane[4]
2719 showregistryentryrecurse _ $arg0 0 0
2723 set $kgm_reg_depth = 0
2724 set $kgm_show_props = 0
2725 showregistryentryint gRegistryRoot
2727 document showregistry
2728 Syntax: (gdb) showregistry
2729 | Show info about all registry entries in the current plane.
2732 define showregistryprops
2733 set $kgm_reg_depth = 0
2734 set $kgm_show_props = 1
2735 showregistryentryint gRegistryRoot
2737 document showregistryprops
2738 Syntax: (gdb) showregistryprops
2739 | Show info about all registry entries in the current plane, and their properties.
2740 | set $kgm_show_object_addrs = 1 and/or set $kgm_show_object_retain = 1 will display
2741 | more verbose information
2744 define showregistryentry
2745 set $kgm_reg_depth = 0
2746 set $kgm_show_props = 1
2747 showregistryentryint $arg0
2749 document showregistryentry
2750 Syntax: (gdb) showregistryentry <object address>
2751 | Show info about a registry entry; its properties and descendants in the current plane.
2754 define setregistryplane
2756 set $kgm_reg_plane = (void **) $arg0
2758 showobjectint _ gIORegistryPlanes
2762 document setregistryplane
2763 Syntax: (gdb) setregistryplane <plane object address>
2764 | Set the plane to be used for the iokit registry macros. An argument of zero will
2765 | display known planes.
2769 set $kgm_classidx = 0
2770 set $kgm_lookvt = *((void **) $arg0)
2771 set $kgm_bestvt = (void *) 0
2772 set $kgm_bestidx = 0
2774 while $kgm_classidx < sAllClassesDict->count
2775 set $kgm_meta = (OSMetaClass *) sAllClassesDict->dictionary[$kgm_classidx].value
2777 set $kgm_vt = *((void **) $kgm_meta)
2779 if (($kgm_vt > $kgm_bestvt) && ($kgm_vt < $kgm_lookvt))
2780 set $kgm_bestvt = $kgm_vt
2781 set $kgm_bestidx = $kgm_classidx
2783 set $kgm_classidx = $kgm_classidx + 1
2785 printf "%s", sAllClassesDict->dictionary[$kgm_bestidx].key->string
2788 define showallclasses
2789 set $kgm_classidx = 0
2790 while $kgm_classidx < sAllClassesDict->count
2791 set $kgm_meta = (OSMetaClass *) sAllClassesDict->dictionary[$kgm_classidx++].value
2792 showmetaclass $kgm_meta
2796 document showallclasses
2797 Syntax: (gdb) showallclasses
2798 | Show the instance counts and ivar size of all OSObject subclasses. See ioclasscount man page for details.
2802 printf " Instance allocation = 0x%08lx = %4ld K\n", (int) debug_ivars_size, ((int) debug_ivars_size) / 1024
2803 printf "Container allocation = 0x%08lx = %4ld K\n", (int) debug_container_malloc_size, ((int) debug_container_malloc_size) / 1024
2804 printf " IOMalloc allocation = 0x%08lx = %4ld K\n", (int) debug_iomalloc_size, ((int) debug_iomalloc_size) / 1024
2805 printf " Pageable allocation = 0x%08lx = %4ld K\n", (vm_size_t) debug_iomallocpageable_size, ((vm_size_t) debug_iomallocpageable_size) / 1024
2808 document showioalloc
2809 Syntax: (gdb) showioalloc
2810 | Show some accounting of memory allocated by IOKit allocators. See ioalloccount man page for details.
2813 define showosobjecttracking
2814 set $kgm_next = (OSObjectTracking *) gOSObjectTrackList.next
2815 while $kgm_next != &gOSObjectTrackList
2816 set $obj = (OSObject *) ($kgm_next+1)
2819 while $kgm_idx < (sizeof($kgm_next->bt) / sizeof($kgm_next->bt[0]))
2820 if ((unsigned) $kgm_next->bt[$kgm_idx] > (unsigned) sectPRELINKB)
2821 showkmodaddr $kgm_next->bt[$kgm_idx]
2824 if ((unsigned) $kgm_next->bt[$kgm_idx] > 0)
2825 output /a (unsigned) $kgm_next->bt[$kgm_idx]
2829 set $kgm_idx = $kgm_idx + 1
2832 set $kgm_next = (OSObjectTracking *) $kgm_next->link.next
2836 document showosobjecttracking
2837 Syntax: (gdb) showosobjecttracking
2838 | Show the list of tracked OSObject allocations with backtraces.
2839 | Boot with the kOSTraceObjectAlloc (0x00400000) io debug flag set.
2840 | Set gOSObjectTrackThread to 1 or a thread_t to capture new OSObjects allocated by a thread or all threads.
2844 set kdp_trans_off = 1
2846 set kdp_trans_off = 0
2850 if ($kgm_mtype == 18)
2851 set kdp_src_high32 = ((uint32_t) ($arg0)) >> 32
2852 x/x (uint32_t) (($arg0) & 0x00000000ffffffffUL)
2853 set kdp_src_high32 = 0
2855 echo readphys64 not available on this architecture.\n
2860 | The argument is interpreted as a physical address, and the word addressed is
2861 | displayed. While this fails if no physical page exists at the given address,
2862 | it must be used with caution.
2866 | The argument is interpreted as a 64-bit physical address, and the word
2867 | addressed is displayed. While this fails if no physical page exists at the
2868 | given address, it must be used with caution.
2872 shell ls $arg0/* | xargs -n 1 echo add-symbol-file > /tmp/gdb-syms
2873 source /tmp/gdb-syms
2874 set $kgm_show_kmod_syms = 1
2877 document addkextsyms
2878 | Takes a directory of symbols for kexts generated with kextcache -y and loads them
2880 | (gdb) addkextsyms /path/to/symboldir
2883 define showprocfiles
2886 _showprocfiles $arg0
2888 printf "| Usage:\n|\n"
2892 document showprocfiles
2893 Syntax: (gdb) showprocfiles <proc_t>
2894 | Given a proc_t pointer, display the list of open file descriptors for the
2895 | referenced process.
2898 define _showprocheader
2899 printf "fd fileglob fg flags fg type fg data info\n"
2900 printf "----- ---------- ---------- -------- ---------- -------------------\n"
2903 define _showprocfiles
2904 set $kgm_spf_filedesc = ((proc_t)$arg0)->p_fd
2905 set $kgm_spf_last = $kgm_spf_filedesc->fd_lastfile
2906 set $kgm_spf_ofiles = $kgm_spf_filedesc->fd_ofiles
2907 set $kgm_spf_count = 0
2908 while ($kgm_spf_count <= $kgm_spf_last)
2909 if ($kgm_spf_ofiles[$kgm_spf_count] == 0)
2910 # DEBUG: For files that were open, but are now closed
2911 # printf "%-5d FILEPROC_NULL\n", $kgm_spf_count
2913 # display fd #, fileglob address, fileglob flags
2914 set $kgm_spf_flags = $kgm_spf_ofiles[$kgm_spf_count].f_flags
2915 set $kgm_spf_fg = $kgm_spf_ofiles[$kgm_spf_count].f_fglob
2916 printf "%-5d 0x%08x 0x%08x ", $kgm_spf_count, $kgm_spf_fg, $kgm_spf_flags
2917 # decode fileglob type
2918 set $kgm_spf_fgt = $kgm_spf_fg->fg_type
2919 if ($kgm_spf_fgt == 1)
2922 if ($kgm_spf_fgt == 2)
2925 if ($kgm_spf_fgt == 3)
2928 if ($kgm_spf_fgt == 4)
2931 if ($kgm_spf_fgt == 5)
2934 if ($kgm_spf_fgt == 6)
2937 if ($kgm_spf_fgt == 7)
2940 if ($kgm_spf_fgt < 1 || $kgm_spf_fgt > 7)
2941 printf "?: %-5d", $kgm_spf_fgt
2944 # display fileglob data address and decode interesting fact(s)
2945 # about data, if we know any
2946 set $kgm_spf_fgd = $kgm_spf_fg->fg_data
2947 printf " 0x%08x ", $kgm_spf_fgd
2948 if ($kgm_spf_fgt == 1)
2949 set $kgm_spf_name = ((struct vnode *)$kgm_spf_fgd)->v_name
2950 if ($kgm_spf_name == 0)
2953 printf "%s", $kgm_spf_name
2958 set $kgm_spf_count = $kgm_spf_count + 1
2963 # Show all the advisory file locks held by a process for each of the vnode
2964 # type files that it has open; do this by walking the per process open file
2965 # table and looking at any vnode type fileglob that has a non-NULL lock list
2966 # associated with it.
2968 define showproclocks
2970 _showproclocks $arg0
2972 printf "| Usage:\n|\n"
2976 document showproclocks
2977 Syntax: (gdb) showproclocks <proc_t>
2978 | Given a proc_t pointer, display the list of advisory file locks held by the
2979 | referenced process.
2982 define _showproclocks
2983 set $kgm_spl_filedesc = ((proc_t)$arg0)->p_fd
2984 set $kgm_spl_last = $kgm_spl_filedesc->fd_lastfile
2985 set $kgm_spl_ofiles = $kgm_spl_filedesc->fd_ofiles
2986 set $kgm_spl_count = 0
2987 set $kgm_spl_seen = 0
2988 while ($kgm_spl_count <= $kgm_spl_last)
2989 if ($kgm_spl_ofiles[$kgm_spl_count] == 0)
2990 # DEBUG: For files that were open, but are now closed
2991 # printf "%-5d FILEPROC_NULL\n", $kgm_spl_count
2993 set $kgm_spl_fg = $kgm_spl_ofiles[$kgm_spl_count].f_fglob
2994 # decode fileglob type
2995 set $kgm_spl_fgt = $kgm_spl_fg->fg_type
2996 if ($kgm_spl_fgt == 1)
2997 set $kgm_spl_fgd = $kgm_spl_fg->fg_data
2998 set $kgm_spl_name = ((struct vnode *)$kgm_spl_fgd)->v_name
2999 set $kgm_spl_vnode = ((vnode_t)$kgm_spl_fgd)
3000 set $kgm_spl_lockiter = $kgm_spl_vnode->v_lockf
3001 if ($kgm_spl_lockiter != 0)
3002 if ($kgm_spl_seen == 0)
3003 _showvnodelockheader
3005 set $kgm_spl_seen = $kgm_spl_seen + 1
3006 printf "( fd %d, name ", $kgm_spl_count
3007 if ($kgm_spl_name == 0)
3010 printf "%s )\n", $kgm_spl_name
3012 _showvnodelocks $kgm_spl_fgd
3016 set $kgm_spl_count = $kgm_spf_count + 1
3018 printf "%d total locks for 0x%08x\n", $kgm_spl_seen, $arg0
3022 set $kgm_spi_proc = (proc_t)$arg0
3023 printf "Process 0x%08x\n", $kgm_spi_proc
3024 printf " name %s\n", $kgm_spi_proc->p_comm
3025 printf " pid:%.8d", $kgm_spi_proc->p_pid
3026 printf " task:0x%.8x", $kgm_spi_proc->task
3027 printf " p_stat:%.1d", $kgm_spi_proc->p_stat
3028 printf " parent pid:%.8d", $kgm_spi_proc->p_ppid
3029 # decode part of credential
3030 set $kgm_spi_cred = $kgm_spi_proc->p_ucred
3031 if ($kgm_spi_cred != 0)
3032 printf "Cred: euid %d ruid %d svuid %d\n", $kgm_spi_cred->cr_uid, $kgm_spi_cred->cr_ruid, $kgm_spi_cred->cr_svuid
3034 printf "Cred: (null)\n"
3037 set $kgm_spi_flag = $kgm_spi_proc->p_flag
3038 printf "Flags: 0x%08x\n", $kgm_spi_flag
3039 if ($kgm_spi_flag & 0x00000001)
3040 printf " 0x00000001 - may hold advisory locks\n"
3042 if ($kgm_spi_flag & 0x00000002)
3043 printf " 0x00000002 - has a controlling tty\n"
3045 if ($kgm_spi_flag & 0x00000004)
3046 printf " 0x00000004 - process is 64 bit\n"
3048 printf " !0x00000004 - process is 32 bit\n"
3050 if ($kgm_spi_flag & 0x00000008)
3051 printf " 0x00000008 - no SIGCHLD on child stop\n"
3053 if ($kgm_spi_flag & 0x00000010)
3054 printf " 0x00000010 - waiting for child exec/exit\n"
3056 if ($kgm_spi_flag & 0x00000020)
3057 printf " 0x00000020 - has started profiling\n"
3059 if ($kgm_spi_flag & 0x00000040)
3060 printf " 0x00000040 - in select; wakeup/waiting danger\n"
3062 if ($kgm_spi_flag & 0x00000080)
3063 printf " 0x00000080 - was stopped and continued\n"
3065 if ($kgm_spi_flag & 0x00000100)
3066 printf " 0x00000100 - has set privileges since exec\n"
3068 if ($kgm_spi_flag & 0x00000200)
3069 printf " 0x00000200 - system process: no signals, stats, or swap\n"
3071 if ($kgm_spi_flag & 0x00000400)
3072 printf " 0x00000400 - timing out during a sleep\n"
3074 if ($kgm_spi_flag & 0x00000800)
3075 printf " 0x00000800 - debugged process being traced\n"
3077 if ($kgm_spi_flag & 0x00001000)
3078 printf " 0x00001000 - debugging process has waited for child\n"
3080 if ($kgm_spi_flag & 0x00002000)
3081 printf " 0x00002000 - exit in progress\n"
3083 if ($kgm_spi_flag & 0x00004000)
3084 printf " 0x00004000 - process has called exec\n"
3086 if ($kgm_spi_flag & 0x00008000)
3087 printf " 0x00008000 - owe process an addupc() XXX\n"
3089 if ($kgm_spi_flag & 0x00010000)
3090 printf " 0x00010000 - affinity for Rosetta children\n"
3092 if ($kgm_spi_flag & 0x00020000)
3093 printf " 0x00020000 - wants to run Rosetta\n"
3095 if ($kgm_spi_flag & 0x00040000)
3096 printf " 0x00040000 - has wait() in progress\n"
3098 if ($kgm_spi_flag & 0x00080000)
3099 printf " 0x00080000 - kdebug tracing on for this process\n"
3101 if ($kgm_spi_flag & 0x00100000)
3102 printf " 0x00100000 - blocked due to SIGTTOU or SIGTTIN\n"
3104 if ($kgm_spi_flag & 0x00200000)
3105 printf " 0x00200000 - has called reboot()\n"
3107 if ($kgm_spi_flag & 0x00400000)
3108 printf " 0x00400000 - is TBE state\n"
3110 if ($kgm_spi_flag & 0x00800000)
3111 printf " 0x00800000 - signal exceptions\n"
3113 if ($kgm_spi_flag & 0x01000000)
3114 printf " 0x01000000 - being branch traced\n"
3116 if ($kgm_spi_flag & 0x02000000)
3117 printf " 0x02000000 - has vfork() children\n"
3119 if ($kgm_spi_flag & 0x04000000)
3120 printf " 0x04000000 - not allowed to attach\n"
3122 if ($kgm_spi_flag & 0x08000000)
3123 printf " 0x08000000 - vfork() in progress\n"
3125 if ($kgm_spi_flag & 0x10000000)
3126 printf " 0x10000000 - no shared libraries\n"
3128 if ($kgm_spi_flag & 0x20000000)
3129 printf " 0x20000000 - force quota for root\n"
3131 if ($kgm_spi_flag & 0x40000000)
3132 printf " 0x40000000 - no zombies when children exit\n"
3134 if ($kgm_spi_flag & 0x80000000)
3135 printf " 0x80000000 - don't hang on remote FS ops\n"
3138 set $kgm_spi_state = $kgm_spi_proc->p_stat
3140 if ($kgm_spi_state == 1)
3143 if ($kgm_spi_state == 2)
3146 if ($kgm_spi_state == 3)
3149 if ($kgm_spi_state == 4)
3152 if ($kgm_spi_state == 5)
3155 if ($kgm_spi_state == 6)
3158 if ($kgm_spi_state < 1 || $kgm_spi_state > 6)
3159 printf "(Unknown)\n"
3163 document showprocinfo
3164 Syntax: (gdb) showprocinfo <proc_t>
3165 | Displays name, pid, parent and task for a proc_t. Decodes cred, flag and p_stat fields.
3169 # dump the zombprocs
3172 set $basep = (struct proc *)zombproc->lh_first
3176 set $pp = $pp->p_list.le_next
3181 Syntax: (gdb) zombproc
3182 | Routine to print out all procs in the zombie list
3186 # dump the zombstacks
3189 set $basep = (struct proc *)zombproc->lh_first
3193 showtaskstacks $pp->task
3195 set $pp = $pp->p_list.le_next
3200 Syntax: (gdb) zombstacks
3201 | Routine to print out all stacks of tasks that are exiting
3209 set $basep = (struct proc *)allproc->lh_first
3213 set $pp = $pp->p_list.le_next
3218 Syntax: (gdb) allproc
3219 | Routine to print out all process in the system
3220 | which are not in the zombie list
3226 set $vp = (struct vnode *)$arg0
3228 printf " vp 0x%.8x", $vp
3229 printf " use %d", $vp->v_usecount
3230 printf " io %d", $vp->v_iocount
3231 printf " kuse %d", $vp->v_kusecount
3232 printf " type %d", $vp->v_type
3233 printf " flg 0x%.8x", $vp->v_flag
3234 printf " lflg 0x%.8x", $vp->v_lflag
3235 printf " par 0x%.8x", $vp->v_parent
3236 set $_name = (char *)$vp->v_name
3238 printf " %s", $_name
3240 if ($vp->v_type == VREG) && ($vp->v_un.vu_ubcinfo != 0)
3241 printf " mapped %d", ($vp->v_un.vu_ubcinfo.ui_flags & 0x08) ? 1 : 0
3246 document print_vnode
3247 Syntax: (gdb) print_vnode <vnode>
3248 | Prints out the fields of a vnode struct
3251 define showprocvnodes
3252 set $pp = (struct proc *)$arg0
3253 set $fdp = (struct filedesc *)$pp->p_fd
3254 set $cvp = $fdp->fd_cdir
3255 set $rvp = $fdp->fd_rdir
3257 printf "Current Working Directory \n"
3262 printf "Current Root Directory \n"
3267 set $fpp = (struct fileproc **)($fdp->fd_ofiles)
3268 set $fpo = (char)($fdp->fd_ofileflags[0])
3269 while $count < $fdp->fd_nfiles
3270 #printf"fpp %x ", *$fpp
3272 set $fg =(struct fileglob *)((**$fpp)->f_fglob)
3273 if $fg && (($fg)->fg_type == 1)
3274 if $fdp->fd_ofileflags[$count] & 4
3279 printf "fd = %d ", $count
3280 print_vnode $fg->fg_data
3284 set $count = $count + 1
3288 document showprocvnodes
3289 Syntax: (gdb) showprocvnodes <proc_address>
3290 | Routine to print out all the open fds
3291 | which are vnodes in a process
3294 define showallprocvnodes
3295 set $basep = (struct proc *)allproc->lh_first
3298 printf "============================================ \n"
3301 set $pp = $pp->p_list.le_next
3305 document showallprocvnodes
3306 Syntax: (gdb) showallprocvnodes
3307 | Routine to print out all the open fds
3313 # dump the childrent of a proc
3315 define showinitchild
3316 set $basep = (struct proc *)initproc->p_children.lh_first
3320 set $pp = $pp->p_sibling.le_next
3324 document showinitchild
3325 Syntax: (gdb) showinitchild
3326 | Routine to print out all processes in the system
3327 | which are children of init process
3331 define showmountallvnodes
3332 set $mp = (struct mount *)$arg0
3333 set $basevp = (struct vnode *)$mp->mnt_vnodelist.tqh_first
3335 printf "____________________ Vnode list Queue ---------------\n"
3338 set $vp = $vp->v_mntvnodes->tqe_next
3340 set $basevp = (struct vnode *)$mp->mnt_workerqueue.tqh_first
3342 printf "____________________ Worker Queue ---------------\n"
3345 set $vp = $vp->v_mntvnodes->tqe_next
3347 set $basevp = (struct vnode *)$mp->mnt_newvnodes.tqh_first
3349 printf "____________________ New vnodes Queue ---------------\n"
3352 set $vp = $vp->v_mntvnodes->tqe_next
3355 document showmountallvnodes
3356 Syntax: showmountallvnodes <struct mount *>
3357 | Print the vnode inactive list
3361 define showmountvnodes
3362 set $mp = (struct mount *)$arg0
3363 set $basevp = (struct vnode *)$mp->mnt_vnodelist.tqh_first
3365 printf "____________________ Vnode list Queue ---------------\n"
3368 set $vp = $vp->v_mntvnodes->tqe_next
3371 document showmountvnodes
3372 Syntax: showmountvnodes <struct mount *>
3373 | Print the vnode list
3378 define showworkqvnodes
3379 set $mp = (struct mount *)$arg0
3380 set $basevp = (struct vnode *)$mp->mnt_workerqueue.tqh_first
3382 printf "____________________ Worker Queue ---------------\n"
3385 set $vp = $vp->v_mntvnodes->tqe_next
3388 document showworkqvnodes
3389 Syntax: showworkqvnodes <struct mount *>
3390 | Print the vnode worker list
3394 define shownewvnodes
3395 set $mp = (struct mount *)$arg0
3396 set $basevp = (struct vnode *)$mp->mnt_newvnodes.tqh_first
3398 printf "____________________ New vnodes Queue ---------------\n"
3401 set $vp = $vp->v_mntvnodes->tqe_next
3405 document shownewvnodes
3406 Syntax: shownewvnodes <struct mount *>
3407 | Print the new vnode list
3412 # print mount point info
3414 set $mp = (struct mount *)$arg0
3416 printf " mp 0x%.8x", $mp
3417 printf " flag %x", $mp->mnt_flag
3418 printf " kern_flag %x", $mp->mnt_kern_flag
3419 printf " lflag %x", $mp->mnt_lflag
3420 printf " type: %s", $mp->mnt_vfsstat.f_fstypename
3421 printf " mnton: %s", $mp->mnt_vfsstat.f_mntonname
3422 printf " mntfrom: %s", $mp->mnt_vfsstat.f_mntfromname
3426 define showallmounts
3427 set $mp=(struct mount *)mountlist.tqh_first
3430 set $mp = $mp->mnt_list.tqe_next
3434 document showallmounts
3435 Syntax: showallmounts
3436 | Print all mount points
3441 if ((unsigned int)$pc <= (unsigned int) $kgm_fkmodmax) && \
3442 ((unsigned int)$pc >= (unsigned int)$kgm_fkmodmin)
3450 set $mp = (struct mbuf *)$arg0
3454 printf "%4d: 0x%08x [len %4d, type %2d, ", $cnt, $mp, \
3455 $mp->m_hdr.mh_len, $mp->m_hdr.mh_type
3460 set $tot = $tot + $mp->m_hdr.mh_len
3461 printf "total %d]\n", $tot
3462 set $mp = $mp->m_hdr.mh_nextpkt
3467 document mbuf_walkpkt
3468 Syntax: (gdb) mbuf_walkpkt <addr>
3469 | Given an mbuf address, walk its m_nextpkt pointer
3473 set $mp = (struct mbuf *)$arg0
3477 printf "%4d: 0x%08x [len %4d, type %2d, ", $cnt, $mp, \
3478 $mp->m_hdr.mh_len, $mp->m_hdr.mh_type
3483 set $tot = $tot + $mp->m_hdr.mh_len
3484 printf "total %d]\n", $tot
3485 set $mp = $mp->m_hdr.mh_next
3491 Syntax: (gdb) mbuf_walk <addr>
3492 | Given an mbuf address, walk its m_next pointer
3495 define mbuf_buf2slab
3497 set $gix = ((char *)$addr - (char *)mbutl) >> 20
3498 set $ix = ((char *)$addr - (char *)mbutl) >> 11
3499 set $slab = &slabstbl[$gix].slg_slab[$ix]
3500 printf "0x%08x", $slab
3503 document mbuf_buf2slab
3504 | Given an mbuf object, find its corresponding slab address.
3509 set $ix = ((char *)$addr - (char *)mbutl) >> 11
3510 set $clbase = ((union mcluster *)(mbutl + $ix))
3511 set $mclidx = (((char *)$addr - (char *)$clbase) >> 8)
3512 set $mca = mclaudit[$ix].cl_audit[$mclidx]
3513 printf "mca: 0x%08x", $mca
3516 document mbuf_buf2mca
3517 Syntax: (gdb) mbuf_buf2mca <addr>
3518 | Given an mbuf object, find its buffer audit structure address.
3519 | This requires mbuf buffer auditing to be turned on, by setting
3520 | the appropriate flags to the "mbuf_debug" boot-args parameter.
3525 set $mca = (mcache_audit_t *)$arg0
3526 set $cp = (mcache_t *)$mca->mca_cache
3527 printf "object type:\t\t"
3528 mbuf_mca_ctype $mca 1
3529 printf "\ncontrolling mcache:\t%p (%s)\n", $mca->mca_cache, $cp->mc_name
3530 if $mca->mca_uflags & $MB_SCVALID
3531 set $ix = ((char *)$mca->mca_addr - (char *)mbutl) >> 11
3532 set $clbase = ((union mcluster *)(mbutl + $ix))
3533 set $mclidx = (((char *)$mca->mca_addr - (char *)$clbase) >> 8)
3534 printf "mbuf obj:\t\t%p\n", $mca->mca_addr
3535 printf "mbuf index:\t\t%d (out of 8) in cluster base %p\n", \
3536 $mclidx + 1, $clbase
3537 if $mca->mca_uptr != 0
3538 set $peer_mca = (mcache_audit_t *)$mca->mca_uptr
3539 printf "paired cluster obj:\t%p (mca %p)\n", \
3540 $peer_mca->mca_addr, $peer_mca
3542 printf "saved contents:\t\t%p (%d bytes)\n", \
3543 $mca->mca_contents, $mca->mca_contents_size
3545 printf "cluster obj:\t\t%p\n", $mca->mca_addr
3546 if $mca->mca_uptr != 0
3547 set $peer_mca = (mcache_audit_t *)$mca->mca_uptr
3548 printf "paired mbuf obj:\t%p (mca %p)\n", \
3549 $peer_mca->mca_addr, $peer_mca
3552 printf "recent transaction for this buffer (thread %p):\n", \
3555 while $cnt < $mca->mca_depth
3556 set $pc = $mca->mca_stack[$cnt]
3557 printf "%4d: ", $cnt + 1
3562 if $mca->mca_pdepth > 0
3563 printf "previous transaction for this buffer (thread %p):\n", \
3567 while $cnt < $mca->mca_pdepth
3568 set $pc = $mca->mca_pstack[$cnt]
3569 printf "%4d: ", $cnt + 1
3577 document mbuf_showmca
3578 Syntax: (gdb) mbuf_showmca <addr>
3579 | Given an mbuf/cluster buffer audit structure address, print the audit
3580 | records including the stack trace of the last buffer transaction.
3583 set $MCF_NOCPUCACHE = 0x10
3586 set $head = (mcache_t *)mcache_head
3588 printf "cache cache cache buf buf backing (# of retries) bufs\n"
3589 printf "name state addr size align zone wait nowait failed incache\n"
3590 printf "------------------------- -------- ---------- ------ ----- ---------- -------------------------- --------\n"
3592 set $bktsize = $mc->mc_cpu.cc_bktsize
3593 printf "%-25s ", $mc->mc_name
3594 if ($mc->mc_flags & $MCF_NOCPUCACHE)
3597 if $mc->mc_purge_cnt > 0
3607 printf " 0x%08x %6d %5d ",$mc, \
3608 $mc->mc_bufsize, $mc->mc_align
3609 if $mc->mc_slab_zone != 0
3610 printf "0x%08x", $mc->mc_slab_zone
3615 set $tot += $mc->mc_full.bl_total * $bktsize
3616 set $ccp = (mcache_cpu_t *)$mc->mc_cpu
3619 if $ccp->cc_objs > 0
3620 set $tot += $ccp->cc_objs
3622 if $ccp->cc_pobjs > 0
3623 set $tot += $ccp->cc_pobjs
3628 printf " %8d %8d %8d %8d", $mc->mc_wretry_cnt, \
3629 $mc->mc_nwretry_cnt, $mc->mc_nwfail_cnt, $tot
3631 set $mc = (mcache_t *)$mc->mc_list.le_next
3635 document mcache_stat
3636 Syntax: (gdb) mcache_stat
3637 | Print all mcaches in the system.
3640 define mcache_showzone
3641 set $mc = (mcache_t *)$arg0
3642 if $mc->mc_slab_zone != 0
3643 printf "%p", $mc->mc_slab_zone
3648 document mcache_showzone
3649 Syntax: (gdb) mcache_showzone <mcache_addr>
3650 | Print the type of backend (custom or zone) of a mcache.
3653 define mcache_walkobj
3654 set $p = (mcache_obj_t *)$arg0
3658 printf "%4d: 0x%08x\n", $cnt, $p,
3659 set $p = $p->obj_next
3664 document mcache_walkobj
3665 Syntax: (gdb) mcache_walkobj <addr>
3666 | Given a mcache object address, walk its obj_next pointer
3669 define mcache_showcache
3670 set $cp = (mcache_t *)$arg0
3671 set $ccp = (mcache_cpu_t *)$cp->mc_cpu
3672 set $bktsize = $cp->mc_cpu.cc_bktsize
3675 printf "Showing cache '%s':\n\n", $cp->mc_name
3676 printf " CPU cc_objs cc_pobjs total\n"
3677 printf "---- -------- -------- --------\n"
3679 set $objs = $ccp->cc_objs
3683 set $pobjs = $ccp->cc_pobjs
3687 set $tot_cpu = $objs + $pobjs
3688 set $tot += $tot_cpu
3689 printf "%4d %8d %8d %8d\n", $cnt, $objs, $pobjs, $tot_cpu
3693 printf " ========\n"
3694 printf " %8d\n", $tot
3696 set $tot += $cp->mc_full.bl_total * $bktsize
3697 printf "Total # of full buckets (%d objs/bkt):\t%-8d\n", \
3698 $bktsize, $cp->mc_full.bl_total
3699 printf "Total # of objects cached:\t\t%-8d\n", $tot
3702 document mcache_showcache
3703 | Display the number of objects in the cache
3706 set $NSLABSPMB = sizeof(mcl_slabg_t)/sizeof(mcl_slab_t)
3708 define mbuf_slabstbl
3711 printf "slot addr slabs range\n"
3712 printf "---- ---------- -----------------------\n"
3713 while $x < maxslabgrp
3714 set $slg = slabstbl[$x]
3719 printf "%p [%p-%p]\n", $slg, &$slg->slg_slab[0], \
3720 &$slg->slg_slab[$NSLABSPMB-1]
3726 document mbuf_slabstbl
3727 | Display the mbuf slabs table
3730 set $SLF_MAPPED=0x0001
3731 set $SLF_PARTIAL=0x0002
3732 set $SLF_DETACHED=0x0004
3735 set $slg = (mcl_slabg_t *)$arg0
3738 printf "slot addr next base C R N size flags\n"
3739 printf "---- ---------- ---------- ---------- -- -- -- ------ -----\n"
3740 while $x < $NSLABSPMB
3741 set $sl = &$slg->slg_slab[$x]
3742 printf "%3d: 0x%08x 0x%08x 0x%08x %2d %2d %2d %6d 0x%04x ", \
3743 $x + 1, $sl, $sl->sl_next, $sl->sl_base, $sl->sl_class, \
3744 $sl->sl_refcnt, $sl->sl_chunks, $sl->sl_len, \
3746 if $sl->sl_flags != 0
3748 if $sl->sl_flags & $SLF_MAPPED
3751 if $sl->sl_flags & $SLF_PARTIAL
3754 if $sl->sl_flags & $SLF_DETACHED
3765 | Display all mbuf slabs in the group
3771 printf "class total cached uncached inuse failed waiter notified purge\n"
3772 printf "name objs objs objs / slabs objs alloc count count count count\n"
3773 printf "---------------- -------- -------- ------------------- -------- ---------------- -------- -------- --------\n"
3774 while $x < (sizeof(mbuf_table) / sizeof(mbuf_table[0]))
3775 set $mbt = mbuf_table[$x]
3776 set $mcs = (mb_class_stat_t *)mbuf_table[$x].mtbl_stats
3778 set $mc = $mbt->mtbl_cache
3779 set $bktsize = $mc->mc_cpu.cc_bktsize
3780 set $tot += $mc->mc_full.bl_total * $bktsize
3781 set $ccp = (mcache_cpu_t *)$mc->mc_cpu
3784 if $ccp->cc_objs > 0
3785 set $tot += $ccp->cc_objs
3787 if $ccp->cc_pobjs > 0
3788 set $tot += $ccp->cc_pobjs
3794 printf "%-16s %8d %8d %8d / %-8d %8d %16llu %8d %8llu %8llu", \
3795 $mcs->mbcl_cname, $mcs->mbcl_total, $tot, \
3796 $mcs->mbcl_infree, $mcs->mbcl_slab_cnt, \
3797 ($mcs->mbcl_total - $tot - $mcs->mbcl_infree), \
3798 $mcs->mbcl_fail_cnt, $mc->mc_waiter_cnt, \
3799 $mcs->mbcl_notified, $mcs->mbcl_purge_cnt
3806 | Print extended mbuf allocator statistics.
3810 set $MB_COMP_INUSE = 0x2
3811 set $MB_SCVALID = 0x4
3813 set $MCLBYTES = 2048
3816 set $M16KCLBYTES = 16384
3818 define mbuf_mca_ctype
3819 set $mca = (mcache_audit_t *)$arg0
3821 set $cp = $mca->mca_cache
3822 set $class = (unsigned int)$cp->mc_private
3823 set $csize = mbuf_table[$class].mtbl_stats->mbcl_size
3833 if !$done && $csize == $MCLBYTES
3835 printf "CL (2K cluster) "
3841 if !$done && $csize == $NBPG
3843 printf "BCL (4K cluster) "
3849 if !$done && $csize == $M16KCLBYTES
3851 printf "JCL (16K cluster) "
3857 if !$done && $csize == ($MSIZE+$MCLBYTES)
3858 if $mca->mca_uflags & $MB_SCVALID
3862 printf "(paired mbuf, 2K cluster)"
3867 printf "(unpaired mbuf, 2K cluster) "
3874 printf "(paired 2K cluster, mbuf) "
3879 printf "(paired 2K cluster, mbuf) "
3885 if !$done && $csize == ($MSIZE+$NBPG)
3886 if $mca->mca_uflags & $MB_SCVALID
3890 printf "(paired mbuf, 4K cluster) "
3895 printf "(unpaired mbuf, 4K cluster) "
3902 printf "(paired 4K cluster, mbuf) "
3907 printf "(unpaired 4K cluster, mbuf) "
3913 if !$done && $csize == ($MSIZE+$M16KCLBYTES)
3914 if $mca->mca_uflags & $MB_SCVALID
3918 printf "(paired mbuf, 16K cluster) "
3923 printf "(unpaired mbuf, 16K cluster) "
3930 printf "(paired 16K cluster, mbuf) "
3935 printf "(unpaired 16K cluster, mbuf) "
3942 printf "unknown: %s ", $cp->mc_name
3946 document mbuf_mca_ctype
3947 | This is a helper macro for mbuf_show{active,inactive,all} that prints
3948 | out the mbuf object type represented by a given mcache audit structure.
3951 define mbuf_showactive
3952 mbuf_walkallslabs 1 0
3955 document mbuf_showactive
3956 Syntax: (gdb) mbuf_showactive
3957 | Walk the mbuf objects pool and print only the active ones; this
3958 | requires mbuf debugging to be turned on, by setting the appropriate flags
3959 | to the "mbuf_debug" boot-args parameter. Active objects are those that
3960 | are outstanding (have not returned to the mbuf slab layer) and in use
3961 | by the client (have not been freed).
3964 define mbuf_showinactive
3965 mbuf_walkallslabs 0 1
3968 document mbuf_showinactive
3969 Syntax: (gdb) mbuf_showinactive
3970 | Walk the mbuf objects pool and print only the inactive ones; this
3971 | requires mbuf debugging to be turned on, by setting the appropriate flags
3972 | to the "mbuf_debug" boot-args parameter. Inactive objects are those that
3973 | are outstanding (have not returned to the mbuf slab layer) but have been
3974 | freed by the client, i.e. they still reside in the mcache layer ready to
3975 | be used for subsequent allocation requests.
3979 mbuf_walkallslabs 1 1
3982 document mbuf_showall
3983 Syntax: (gdb) mbuf_showall
3984 | Walk the mbuf objects pool and print them all; this requires
3985 | mbuf debugging to be turned on, by setting the appropriate flags to the
3986 | "mbuf_debug" boot-args parameter.
3992 define mbuf_walkallslabs
4001 if $show_a && !$show_f
4002 printf "Searching only for active "
4004 if !$show_a && $show_f
4005 printf "Searching only for inactive "
4007 if $show_a && $show_f
4008 printf "Displaying all "
4010 printf "objects; this may take a while ...)\n\n"
4012 printf " slab mca obj allocation\n"
4013 printf "slot idx address address address type state\n"
4014 printf "---- ---- ---------- ---------- ---------- ----- -----------\n"
4017 set $slg = slabstbl[$x]
4020 while $y < $NSLABSPMB && $stop == 0
4021 set $sl = &$slg->slg_slab[$y]
4022 set $base = (char *)$sl->sl_base
4023 set $ix = ($base - (char *)mbutl) >> 11
4024 set $clbase = ((union mcluster *)(mbutl + $ix))
4025 set $mclidx = ($base - (char *)$clbase) >> 8
4026 set $mca = mclaudit[$ix].cl_audit[$mclidx]
4029 while $mca != 0 && $mca->mca_addr != 0
4031 if $mca->mca_uflags & ($MB_INUSE|$MB_COMP_INUSE)
4032 set $total_a = $total_a + 1
4033 set $printmca = $show_a
4035 set $total_f = $total_f + 1
4036 set $printmca = $show_f
4041 printf "%4d %4d 0x%08x ", $x, $y, $sl
4046 printf "0x%08x 0x%08x ", $mca, $mca->mca_addr
4047 mbuf_mca_ctype $mca 0
4048 if $mca->mca_uflags & ($MB_INUSE|$MB_COMP_INUSE)
4057 set $total = $total + 1
4059 set $mca = $mca->mca_next
4062 if $slg->slg_slab[$y].sl_base == 0
4068 if $total && $show_a && $show_f
4069 printf "\ntotal objects:\t%d\n", $total
4070 printf "active/unfreed:\t%d\n", $total_a
4071 printf "freed/in_cache:\t%d\n", $total_f
4075 document mbuf_walkallslabs
4076 | Walk the mbuf objects pool; this requires mbuf debugging to be
4077 | turned on, by setting the appropriate flags to the "mbuf_debug" boot-args
4078 | parameter. This is a backend routine for mbuf_show{active,inactive,all}.
4081 define rtentry_trash
4082 set $rtd = (struct rtentry_dbg *)rttrash_head.tqh_first
4086 printf " rtentry_dbg ref flags\n"
4087 printf " ------------ --- ----------\n"
4089 printf "%4d: %p %3d 0x%08x\n", $cnt + 1, $rtd, \
4090 $rtd->rtd_refhold_cnt - $rtd->rtd_refrele_cnt, \
4091 $rtd->rtd_entry.rt_flags
4092 set $rtd = $rtd->rtd_trash_link.tqe_next
4097 document rtentry_trash
4098 Syntax: (gdb) rtentry_trash
4099 | Walk the list of trash route entries; this requires route entry
4100 | debugging to be turned on, by setting the appropriate flags to the
4101 | "rte_debug" boot-args parameter.
4104 set $RTD_TRSTACK_SIZE = 8
4105 set $RTD_REFHIST_SIZE = 4
4107 define rtentry_showdbg
4108 set $rtd = (struct rtentry_dbg *)$arg0
4111 printf "Total holds: %d\n", $rtd->rtd_refhold_cnt
4112 printf "Next hold slot: %d\n", $rtd->rtd_refhold_next
4113 printf "Total releases: %d\n", $rtd->rtd_refrele_cnt
4114 printf "Next release slot: %d\n", $rtd->rtd_refrele_next
4117 while $ix < $RTD_TRSTACK_SIZE
4118 set $pc = $rtd->rtd_alloc_stk_pc[$ix]
4121 printf "\nAlloc (thread %p):\n", \
4122 $rtd->rtd_alloc_thread
4124 printf "%4d: ", $ix + 1
4131 while $ix < $RTD_TRSTACK_SIZE
4132 set $pc = $rtd->rtd_free_stk_pc[$ix]
4135 printf "\nFree: (thread %p)\n", \
4136 $rtd->rtd_free_thread
4138 printf "%4d: ", $ix + 1
4144 while $cnt < $RTD_REFHIST_SIZE
4146 while $ix < $RTD_TRSTACK_SIZE
4147 set $pc = $rtd->rtd_refhold[$cnt].pc[$ix]
4150 printf "\nHold [%d] (thread %p):\n", \
4151 $cnt, $rtd->rtd_refhold[$cnt].th
4153 printf "%4d: ", $ix + 1
4162 while $cnt < $RTD_REFHIST_SIZE
4164 while $ix < $RTD_TRSTACK_SIZE
4165 set $pc = $rtd->rtd_refrele[$cnt].pc[$ix]
4168 printf "\nRelease [%d] (thread %p):\n",\
4169 $cnt, $rtd->rtd_refrele[$cnt].th
4171 printf "%4d: ", $ix + 1
4181 document rtentry_showdbg
4182 Syntax: (gdb) rtentry_showdbg <addr>
4183 | Given a route entry structure address, print the debug information
4184 | related to it. This requires route entry debugging to be turned
4185 | on, by setting the appropriate flags to the "rte_debug" boot-args
4190 # print all OSMalloc stats
4193 set $kgm_tagp = (OSMallocTag)$arg0
4194 printf "0x%08x: ", $kgm_tagp
4195 printf "%8d ",$kgm_tagp->OSMT_refcnt
4196 printf "%8x ",$kgm_tagp->OSMT_state
4197 printf "%8x ",$kgm_tagp->OSMT_attr
4198 printf "%s ",$kgm_tagp->OSMT_name
4204 printf "TAG COUNT STATE ATTR NAME\n"
4205 set $kgm_tagheadp = (OSMallocTag)&OSMalloc_tag_list
4206 set $kgm_tagptr = (OSMallocTag )($kgm_tagheadp->OSMT_link.next)
4207 while $kgm_tagptr != $kgm_tagheadp
4208 ostag_print $kgm_tagptr
4209 set $kgm_tagptr = (OSMallocTag)$kgm_tagptr->OSMT_link.next
4213 document showosmalloc
4214 Syntax: (gdb) showosmalloc
4215 | Print the outstanding allocation count by OSMallocTags.
4220 if msgbufp->msg_bufc[msgbufp->msg_bufx] == 0
4221 # The buffer hasn't wrapped, so take the easy (and fast!) path
4222 printf "%s", msgbufp->msg_bufc
4224 set $kgm_msgbuf = *msgbufp
4225 set $kgm_syslog_bufsize = $kgm_msgbuf.msg_size
4226 set $kgm_syslog_bufend = $kgm_msgbuf.msg_bufx
4227 if $kgm_syslog_bufend >= $kgm_syslog_bufsize
4228 set $kgm_syslog_bufend = 0
4231 # print older messages from msg_bufx to end of buffer
4232 set $kgm_i = $kgm_syslog_bufend
4233 while $kgm_i < $kgm_syslog_bufsize
4234 set $kgm_syslog_char = $kgm_msgbuf.msg_bufc[$kgm_i]
4235 if $kgm_syslog_char == 0
4237 set $kgm_i = $kgm_syslog_bufsize
4239 printf "%c", $kgm_syslog_char
4241 set $kgm_i = $kgm_i + 1
4244 # print newer messages from start of buffer to msg_bufx
4246 while $kgm_i < $kgm_syslog_bufend
4247 set $kgm_syslog_char = $kgm_msgbuf.msg_bufc[$kgm_i]
4248 printf "%c", $kgm_syslog_char
4249 set $kgm_i = $kgm_i + 1
4256 | Display the kernel's printf ring buffer
4259 define printvnodepathint_recur
4261 if ($arg0->v_flag & 0x000001) && ($arg0->v_mount != 0)
4262 if $arg0->v_mount->mnt_vnodecovered != 0
4263 printvnodepathint_recur $arg0->v_mount->mnt_vnodecovered $arg0->v_mount->mnt_vnodecovered->v_name
4266 printvnodepathint_recur $arg0->v_parent $arg0->v_parent->v_name
4273 # Show the locks held on a vnode by range, type, and holder.
4275 define showvnodelocks
4277 _showvnodelockheader
4278 _showvnodelocks $arg0
4280 printf "| Usage:\n|\n"
4284 document showvnodelocks
4285 | Given a vnodet pointer, display the list of advisory record locks for the
4286 | referenced pvnode.
4287 | The following is the syntax:
4288 | (gdb) showvnodelocks <vnode_t>
4291 define _showvnodelockheader
4292 printf "* type W held by lock type start end\n"
4293 printf "- ----- - ------------- --------- ------------------ ------------------\n"
4297 # Macro to display a single lock; used to display both held locks and
4300 define _showvnodelock
4301 set $kgm_svl_lock = ((struct lockf *)$arg0)
4304 set $kgm_svl_flags = $kgm_svl_lock->lf_flags
4305 set $kgm_svl_type = $kgm_svl_lock->lf_type
4306 if ($kgm_svl_flags & 0x20)
4309 if ($kgm_svl_flags & 0x40)
4312 if ($kgm_svl_flags & 0x80)
4315 if ($kgm_svl_flags & 0x10)
4321 # POSIX file vs. advisory range locks
4322 if ($kgm_svl_flags & 0x40)
4323 set $kgm_svl_proc = (proc_t)$kgm_svl_lock->lf_id
4324 printf "PID %8d ", $kgm_svl_proc->p_pid
4326 printf "ID 0x%08x ", $kgm_svl_lock->lf_id
4330 if ($kgm_svl_type == 1)
4333 if ($kgm_svl_type == 3)
4336 if ($kgm_svl_type == 2)
4345 printf "0x%016x..", $kgm_svl_lock->lf_start
4346 printf "0x%016x ", $kgm_svl_lock->lf_end
4350 # Body of showvnodelocks, not including header
4351 define _showvnodelocks
4352 set $kgm_svl_vnode = ((vnode_t)$arg0)
4353 set $kgm_svl_lockiter = $kgm_svl_vnode->v_lockf
4354 while ($kgm_svl_lockiter != 0)
4355 # locks that are held
4357 _showvnodelock $kgm_svl_lockiter
4359 # and any locks blocked by them
4360 set $kgm_svl_blocker = $kgm_svl_lockiter->lf_blkhd.tqh_first
4361 while ($kgm_svl_blocker != 0)
4363 _showvnodelock $kgm_svl_blocker
4364 set $kgm_svl_blocker = $kgm_svl_blocker->lf_block.tqe_next
4367 # and on to the next one...
4368 set $kgm_svl_lockiter = $kgm_svl_lockiter->lf_next
4372 define showvnodepath
4373 set $vp = (struct vnode *)$arg0
4375 if ($vp->v_flag & 0x000001) && ($vp->v_mount != 0) && ($vp->v_mount->mnt_flag & 0x00004000)
4378 printvnodepathint_recur $vp $vp->v_name
4384 document showvnodepath
4385 Syntax: (gdb) showvnodepath <vnode>
4386 | Prints the path for a vnode
4389 define printcolonhex
4394 while ($li < $count)
4396 printf "%02x", (u_char)$addr[$li]
4399 printf ":%02x", (u_char)$addr[$li]
4406 define showsockaddr_dl
4407 set $sdl = (struct sockaddr_dl *)$arg0
4412 set $addr = $sdl->sdl_data + $sdl->sdl_nlen
4413 set $count = $sdl->sdl_alen
4414 printcolonhex $addr $count
4418 define showsockaddr_unspec
4419 set $sockaddr = (struct sockaddr *)$arg0
4420 set $addr = $sockaddr->sa_data
4421 set $count = $sockaddr->sa_len - 2
4423 printcolonhex $addr $count
4426 define showsockaddr_at
4427 set $sockaddr = (struct sockaddr *)$arg0
4428 set $addr = $sockaddr->sa_data
4429 set $count = $sockaddr->sa_len - 2
4431 printcolonhex $addr $count
4434 define showsockaddr_in
4435 set $sin = (struct sockaddr_in *)$arg0
4436 set $sa_bytes = (unsigned char *)&($sin->sin_addr)
4437 printf "IPV4 %d.%d.%d.%d", $sa_bytes[0], $sa_bytes[1], $sa_bytes[2], $sa_bytes[3]
4440 define showsockaddr_in6
4441 set $sin6 = (struct sockaddr_in6 *)$arg0
4442 set $sa_bytes = $sin6->sin6_addr.__u6_addr.__u6_addr8
4443 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]
4446 define showifmultiaddrs
4447 set $ifp = (struct ifnet *)$arg0
4448 set $if_multi = (struct ifmultiaddr *)$ifp->if_multiaddrs->lh_first
4449 set $mymulti = $if_multi
4451 while ($mymulti != 0)
4452 printf "%2d. ", $myi
4453 set $sa_family = $mymulti->ifma_addr.sa_family
4454 if ($sa_family == 2)
4455 if ($mymulti->ifma_ll != 0)
4456 showsockaddr_dl $mymulti->ifma_ll->ifma_addr
4459 showsockaddr_in $mymulti->ifma_addr
4461 if ($sa_family == 30)
4462 if ($mymulti->ifma_ll != 0)
4463 showsockaddr_dl $mymulti->ifma_ll->ifma_addr
4466 showsockaddr_in6 $mymulti->ifma_addr
4468 if ($sa_family == 18)
4469 showsockaddr_dl $mymulti->ifma_addr
4471 if ($sa_family == 0)
4472 showsockaddr_unspec $mymulti->ifma_addr 6
4474 printf " [%d]", $mymulti->ifma_refcount
4476 set $mymulti = $mymulti->ifma_link.le_next
4481 document showifmultiaddrs
4482 Syntax showifmultiaddrs <ifp>
4483 | show the (struct ifnet).if_multiaddrs list of multicast addresses for the given ifp
4487 set $mysock = (struct sockaddr *)$arg0
4488 set $showsockaddr_handled = 0
4492 if ($mysock->sa_family == 0)
4493 showsockaddr_unspec $mysock
4494 set $showsockaddr_handled = 1
4496 if ($mysock->sa_family == 2)
4497 showsockaddr_in $mysock
4498 set $showsockaddr_handled = 1
4500 if ($mysock->sa_family == 30)
4501 showsockaddr_in6 $mysock
4502 set $showsockaddr_handled = 1
4504 if ($mysock->sa_family == 18)
4505 showsockaddr_dl $mysock
4506 set $showsockaddr_handled = 1
4508 if ($mysock->sa_family == 16)
4509 showsockaddr_at $mysock
4510 set $showsockaddr_handled = 1
4512 if ($showsockaddr_handled == 0)
4513 printf "%d ", $mysock->sa_family
4514 set $addr = $mysock->sa_data
4515 set $count = $mysock->sa_len
4516 printcolonhex $addr $count
4522 set $flags = (u_short)$arg0
4554 printf "POINTTOPOINT"
4556 # if ($flags & 0x20)
4562 # printf "NOTRAILERS"
4612 if ($flags & 0x1000)
4620 if ($flags & 0x2000)
4628 if ($flags & 0x4000)
4634 printf "LINK2-ALTPHYS"
4636 if ($flags & 0x8000)
4648 set $ifp = (struct ifnet *)$arg0
4649 set $myifaddr = (struct ifaddr *)$ifp->if_addrhead->tqh_first
4651 while ($myifaddr != 0)
4652 printf "\t%d. ", $myi
4653 showsockaddr $myifaddr->ifa_addr
4654 printf " [%d]\n", $myifaddr->ifa_refcnt
4655 set $myifaddr = $myifaddr->ifa_link->tqe_next
4660 document showifaddrs
4661 Syntax: showifaddrs <ifp>
4662 | show the (struct ifnet).if_addrhead list of addresses for the given ifp
4666 set $ifconfig_all = 0
4668 set $ifconfig_all = 1
4670 set $ifp = (struct ifnet *)(ifnet->tqh_first)
4672 printf "%s%d: flags=%x", $ifp->if_name, $ifp->if_unit, (u_short)$ifp->if_flags
4673 showifflags $ifp->if_flags
4674 printf " mtu %d\n", $ifp->if_data.ifi_mtu
4675 printf "\t(struct ifnet *)0x%x\n", $ifp
4676 if ($ifconfig_all == 1)
4679 set $ifp = $ifp->if_link->tqe_next
4683 Syntax: (gdb) ifconfig
4684 | display ifconfig-like output, and print the (struct ifnet *) pointers for further inspection
4689 while ($myi < bpf_dtab_size)
4690 if (bpf_dtab[$myi] != 0)
4691 printf "Address 0x%x, bd_next 0x%x\n", bpf_dtab[$myi], bpf_dtab[$myi]->bd_next
4692 print *bpf_dtab[$myi]
4699 printf "volume mnt_data mnt_devvp typename mountpoint\n"
4700 set $kgm_vol = (mount_t) mountlist.tqh_first
4702 printf "0x%08x ", $kgm_vol
4703 printf "0x%08x ", $kgm_vol->mnt_data
4704 printf "0x%08x ", $kgm_vol->mnt_devvp
4705 if ($kgm_vol->mnt_vtable->vfc_name[0] == 'h') && \
4706 ($kgm_vol->mnt_vtable->vfc_name[1] == 'f') && \
4707 ($kgm_vol->mnt_vtable->vfc_name[2] == 's') && \
4708 ($kgm_vol->mnt_vtable->vfc_name[3] == '\0')
4709 set $kgm_hfsmount = \
4710 (struct hfsmount *) $kgm_vol->mnt_data
4711 if $kgm_hfsmount->hfs_freezing_proc != 0
4712 printf "FROZEN hfs "
4717 printf "%-10s ", $kgm_vol->mnt_vtable->vfc_name
4719 printf "%s\n", $kgm_vol->mnt_vfsstat.f_mntonname
4721 set $kgm_vol = (mount_t) $kgm_vol->mnt_list.tqe_next
4725 document showallvols
4726 Syntax: (gdb) showallvols
4727 | Display a summary of mounted volumes
4730 define showvnodeheader
4731 printf "vnode usecount iocount v_data vtype parent name\n"
4735 set $kgm_vnode = (vnode_t) $arg0
4736 printf "0x%08x ", $kgm_vnode
4737 printf "%8d ", $kgm_vnode->v_usecount
4738 printf "%7d ", $kgm_vnode->v_iocount
4739 # print information about clean/dirty blocks?
4740 printf "0x%08x ", $kgm_vnode->v_data
4742 # print the vtype, using the enum tag
4743 set $kgm_vtype = $kgm_vnode->v_type
4744 if $kgm_vtype == VNON
4747 if $kgm_vtype == VREG
4750 if $kgm_vtype == VDIR
4753 if $kgm_vtype == VBLK
4756 if $kgm_vtype == VCHR
4759 if $kgm_vtype == VLNK
4762 if $kgm_vtype == VSOCK
4765 if $kgm_vtype == VFIFO
4768 if $kgm_vtype == VBAD
4771 if ($kgm_vtype < VNON) || ($kgm_vtype > VBAD)
4772 printf "%5d ", $kgm_vtype
4775 printf "0x%08x ", $kgm_vnode->v_parent
4776 if $kgm_vnode->v_name != 0
4777 printf "%s\n", $kgm_vnode->v_name
4789 Syntax: (gdb) showvnode <vnode>
4790 | Display info about one vnode
4793 define showvolvnodes
4795 set $kgm_vol = (mount_t) $arg0
4796 set $kgm_vnode = (vnode_t) $kgm_vol.mnt_vnodelist.tqh_first
4798 showvnodeint $kgm_vnode
4799 set $kgm_vnode = (vnode_t) $kgm_vnode->v_mntvnodes.tqe_next
4803 document showvolvnodes
4804 Syntax: (gdb) showvolvnodes <mouont_t>
4805 | Display info about all vnodes of a given mount_t
4808 define showvolbusyvnodes
4810 set $kgm_vol = (mount_t) $arg0
4811 set $kgm_vnode = (vnode_t) $kgm_vol.mnt_vnodelist.tqh_first
4813 if $kgm_vnode->v_iocount != 0
4814 showvnodeint $kgm_vnode
4816 set $kgm_vnode = (vnode_t) $kgm_vnode->v_mntvnodes.tqe_next
4820 document showvolbusyvnodes
4821 Syntax: (gdb) showvolbusyvnodes <mount_t>
4822 | Display info about busy (iocount!=0) vnodes of a given mount_t
4825 define showallbusyvnodes
4827 set $kgm_vol = (mount_t) mountlist.tqh_first
4829 set $kgm_vnode = (vnode_t) $kgm_vol.mnt_vnodelist.tqh_first
4831 if $kgm_vnode->v_iocount != 0
4832 showvnodeint $kgm_vnode
4834 set $kgm_vnode = (vnode_t) $kgm_vnode->v_mntvnodes.tqe_next
4836 set $kgm_vol = (mount_t) $kgm_vol->mnt_list.tqe_next
4840 document showallbusyvnodes
4841 Syntax: (gdb) showallbusyvnodes <vnode>
4842 | Display info about all busy (iocount!=0) vnodes
4845 define showallvnodes
4847 set $kgm_vol = (mount_t) mountlist.tqh_first
4849 set $kgm_vnode = (vnode_t) $kgm_vol.mnt_vnodelist.tqh_first
4851 showvnodeint $kgm_vnode
4852 set $kgm_vnode = (vnode_t) $kgm_vnode->v_mntvnodes.tqe_next
4854 set $kgm_vol = (mount_t) $kgm_vol->mnt_list.tqe_next
4858 document showallvnodes
4859 Syntax: (gdb) showallvnodes
4860 | Display info about all vnodes
4863 define _showvnodelockheader
4864 printf "* type W held by lock type start end\n"
4865 printf "- ----- - ------------- --------- ------------------ ------------------\n"
4868 define _showvnodelock
4869 set $kgm_svl_lock = ((struct lockf *)$arg0)
4872 set $kgm_svl_flags = $kgm_svl_lock->lf_flags
4873 set $kgm_svl_type = $kgm_svl_lock->lf_type
4874 if ($kgm_svl_flags & 0x20)
4877 if ($kgm_svl_flags & 0x40)
4880 if ($kgm_svl_flags & 0x80)
4883 if ($kgm_svl_flags & 0x10)
4889 # POSIX file vs. advisory range locks
4890 if ($kgm_svl_flags & 0x40)
4891 set $kgm_svl_proc = (proc_t)$kgm_svl_lock->lf_id
4892 printf "PID %8d ", $kgm_svl_proc->p_pid
4894 printf "ID 0x%08x ", $kgm_svl_lock->lf_id
4898 if ($kgm_svl_type == 1)
4901 if ($kgm_svl_type == 3)
4904 if ($kgm_svl_type == 2)
4913 printf "0x%016x..", $kgm_svl_lock->lf_start
4914 printf "0x%016x ", $kgm_svl_lock->lf_end
4917 # Body of showvnodelocks, not including header
4918 define _showvnodelocks
4919 set $kgm_svl_vnode = ((vnode_t)$arg0)
4920 set $kgm_svl_lockiter = $kgm_svl_vnode->v_lockf
4921 while ($kgm_svl_lockiter != 0)
4922 # locks that are held
4924 _showvnodelock $kgm_svl_lockiter
4926 # and any locks blocked by them
4927 set $kgm_svl_blocker = $kgm_svl_lockiter->lf_blkhd.tqh_first
4928 while ($kgm_svl_blocker != 0)
4930 _showvnodelock $kgm_svl_blocker
4931 set $kgm_svl_blocker = $kgm_svl_blocker->lf_block.tqe_next
4934 # and on to the next one...
4935 set $kgm_svl_lockiter = $kgm_svl_lockiter->lf_next
4940 define showvnodelocks
4942 _showvnodelockheader
4943 _showvnodelocks $arg0
4945 printf "| Usage:\n|\n"
4950 document showvnodelocks
4951 Syntax: (gdb) showvnodelocks <vnode_t>
4952 | Given a vnodet pointer, display the list of advisory record locks for the
4953 | referenced pvnodes
4957 printf "%s\n", (char*)((boot_args*)PE_state.bootArgs).CommandLine
4960 document showbootargs
4961 Syntax: showbootargs
4962 | Display boot arguments passed to the target kernel
4965 define showbootermemorymap
4966 set $kgm_boot_args = kernelBootArgs
4967 set $kgm_msize = kernelBootArgs->MemoryMapDescriptorSize
4968 set $kgm_mcount = kernelBootArgs->MemoryMapSize / $kgm_msize
4971 printf "Type Physical Start Number of Pages\n"
4972 while $kgm_i < $kgm_mcount
4973 set $kgm_mptr = (EfiMemoryRange *)((unsigned long)kernelBootArgs->MemoryMap + $kgm_i * $kgm_msize)
4975 if $kgm_mptr->Type == 0
4978 if $kgm_mptr->Type == 1
4981 if $kgm_mptr->Type == 2
4984 if $kgm_mptr->Type == 3
4987 if $kgm_mptr->Type == 4
4990 if $kgm_mptr->Type == 5
4993 if $kgm_mptr->Type == 6
4996 if $kgm_mptr->Type == 7
4999 if $kgm_mptr->Type == 8
5002 if $kgm_mptr->Type == 9
5005 if $kgm_mptr->Type == 10
5008 if $kgm_mptr->Type == 11
5011 if $kgm_mptr->Type == 12
5014 if $kgm_mptr->Type == 13
5017 if $kgm_mptr->Type > 13
5021 printf " %016llx %016llx\n", $kgm_mptr->PhysicalStart, $kgm_mptr->NumberOfPages
5022 set $kgm_i = $kgm_i + 1
5026 document showbootermemorymap
5027 Syntax: (gdb) showbootermemorymap
5028 | Prints out the phys memory map from kernelBootArgs
5032 define showstacksaftertask
5033 set $kgm_head_taskp = &default_pset.tasks
5034 set $kgm_taskp = (struct task *)$arg0
5035 while $kgm_taskp != $kgm_head_taskp
5037 showtaskint $kgm_taskp
5038 set $kgm_head_actp = &($kgm_taskp->threads)
5039 set $kgm_actp = (struct thread *)($kgm_taskp->threads.next)
5040 while $kgm_actp != $kgm_head_actp
5042 if ($decode_wait_events > 0)
5043 showactint $kgm_actp 1
5045 showactint $kgm_actp 2
5047 set $kgm_actp = (struct thread *)($kgm_actp->task_threads.next)
5050 set $kgm_taskp = (struct task *)($kgm_taskp->pset_tasks.next)
5053 document showstacksaftertask
5054 Syntax: (gdb) showstacksaftertask <task>
5055 | Routine to print out all stacks (as in showallstacks) starting after a given task
5056 | Useful if that gdb refuses to print a certain task's stack.
5059 define showpmworkqueueint
5060 set $kgm_pm_wq = (IOPMWorkQueue *)$arg0
5061 set $kgm_pm_node = (IOService *)$kgm_pm_wq->owner
5062 printf "0x%08x 0x%08x ", $kgm_pm_wq, $kgm_pm_node
5063 printf "%02d ", $kgm_pm_node->pwrMgt->CurrentPowerState
5064 printf "%02d ", $kgm_pm_node->pwrMgt->MachineState
5065 printf "%02d ", $kgm_pm_node->pwrMgt->WaitReason
5066 printf "%s\n", $kgm_pm_node->pwrMgt->Name
5067 set $kgm_pm_queue = &($kgm_pm_wq->fWorkQueue)
5068 set $kgm_pm_req = (IOPMRequest *) $kgm_pm_queue->next
5069 while ( (queue_entry_t) $kgm_pm_req != (queue_entry_t) $kgm_pm_queue)
5070 printf " Request 0x%08x [%02x] Args ", $kgm_pm_req, $kgm_pm_req->fType
5071 printf "0x%08x ", $kgm_pm_req->fArg0
5072 printf "0x%08x ", $kgm_pm_req->fArg1
5073 printf "0x%08x\n", $kgm_pm_req->fArg2
5074 set $kgm_pm_req = (IOPMRequest *)$kgm_pm_req->fCommandChain.next
5078 define showallpmworkqueues
5079 set $kgm_pm_next = gIOPMWorkLoop->eventChain
5080 printf "WorkQueue Owner PS MS WT Name\n"
5081 printf "--------------------------------------\n"
5082 while ( $kgm_pm_next )
5083 set $kgm_vt = *((void **) $kgm_pm_next)
5084 if ($kgm_vt == _ZTV13IOPMWorkQueue)
5085 showpmworkqueueint $kgm_pm_next
5087 set $kgm_pm_next = $kgm_pm_next->eventChainNext
5091 document showallpmworkqueues
5092 Syntax: (gdb) showallpmworkqueues
5093 | Display info about all IOPMWorkQueue objects
5096 define showioservicepm
5097 set $kgm_iopmpriv = (IOServicePM *)$arg0
5098 printf "{ this object = %08x", $kgm_iopmpriv->Owner
5099 if ( $kgm_iopmpriv->WeAreRoot )
5104 printf "MachineState = %d (", $kgm_iopmpriv->MachineState
5105 if ( $kgm_iopmpriv->MachineState == 1 )
5106 printf "kIOPM_OurChangeTellClientsPowerDown"
5108 if ( $kgm_iopmpriv->MachineState == 2 )
5109 printf "kIOPM_OurChangeTellPriorityClientsPowerDown"
5111 if ( $kgm_iopmpriv->MachineState == 3 )
5112 printf "kIOPM_OurChangeNotifyInterestedDriversWillChange"
5114 if ( $kgm_iopmpriv->MachineState == 4 )
5115 printf "kIOPM_OurChangeSetPowerState"
5117 if ( $kgm_iopmpriv->MachineState == 5 )
5118 printf "kIOPM_OurChangeWaitForPowerSettle"
5120 if ( $kgm_iopmpriv->MachineState == 6 )
5121 printf "kIOPM_OurChangeNotifyInterestedDriversDidChange"
5123 if ( $kgm_iopmpriv->MachineState == 7 )
5124 printf "kIOPM_OurChangeFinish"
5126 if ( $kgm_iopmpriv->MachineState == 8 )
5127 printf "kIOPM_ParentDownTellPriorityClientsPowerDown"
5129 if ( $kgm_iopmpriv->MachineState == 9 )
5130 printf "kIOPM_ParentDownNotifyInterestedDriversWillChange"
5132 if ( $kgm_iopmpriv->MachineState == 10 )
5133 printf "Unused_MachineState_10"
5135 if ( $kgm_iopmpriv->MachineState == 11 )
5136 printf "kIOPM_ParentDownNotifyDidChangeAndAcknowledgeChange"
5138 if ( $kgm_iopmpriv->MachineState == 12 )
5139 printf "kIOPM_ParentDownSetPowerState"
5141 if ( $kgm_iopmpriv->MachineState == 13 )
5142 printf "kIOPM_ParentDownWaitForPowerSettle"
5144 if ( $kgm_iopmpriv->MachineState == 14 )
5145 printf "kIOPM_ParentDownAcknowledgeChange"
5147 if ( $kgm_iopmpriv->MachineState == 15)
5148 printf "kIOPM_ParentUpSetPowerState"
5150 if ( $kgm_iopmpriv->MachineState == 16)
5151 printf "Unused_MachineState_16"
5153 if ( $kgm_iopmpriv->MachineState == 17)
5154 printf "kIOPM_ParentUpWaitForSettleTime"
5156 if ( $kgm_iopmpriv->MachineState == 18)
5157 printf "kIOPM_ParentUpNotifyInterestedDriversDidChange"
5159 if ( $kgm_iopmpriv->MachineState == 19)
5160 printf "kIOPM_ParentUpAcknowledgePowerChange"
5162 if ( $kgm_iopmpriv->MachineState == 20)
5163 printf "kIOPM_Finished"
5165 if ( $kgm_iopmpriv->MachineState == 21)
5166 printf "kIOPM_DriverThreadCallDone"
5168 if ( $kgm_iopmpriv->MachineState == 22)
5169 printf "kIOPM_NotifyChildrenDone"
5194 if ( $kgm_iopmpriv->MachineState != 20 )
5195 printf "DriverTimer = %d, ",(unsigned int)$kgm_iopmpriv->DriverTimer
5196 printf "SettleTime = %d, ",(unsigned int)$kgm_iopmpriv->SettleTimeUS
5197 printf "HeadNoteFlags = %08x, ",(unsigned int)$kgm_iopmpriv->HeadNoteFlags
5198 printf "HeadNoteState = %d, ",(unsigned int)$kgm_iopmpriv->HeadNoteState
5199 printf "HeadNoteOutputFlags = %08x, ",(unsigned int)$kgm_iopmpriv->HeadNoteOutputFlags
5200 printf "HeadNoteDomainState = %08x, ",(unsigned int)$kgm_iopmpriv->HeadNoteDomainState
5201 printf "HeadNoteCapabilityFlags = %08x, ",(unsigned int)$kgm_iopmpriv->HeadNoteCapabilityFlags
5202 printf "HeadNotePendingAcks = %x, ",(unsigned int)$kgm_iopmpriv->HeadNotePendingAcks
5205 if ( $kgm_iopmpriv->DeviceOverrides != 0 )
5206 printf"DeviceOverrides, "
5209 printf "DriverDesire = %d, ",(unsigned int)$kgm_iopmpriv->DriverDesire
5210 printf "DeviceDesire = %d, ",(unsigned int)$kgm_iopmpriv->DeviceDesire
5211 printf "DesiredPowerState = %d, ",(unsigned int)$kgm_iopmpriv->DesiredPowerState
5212 printf "PreviousRequest = %d }",(unsigned int)$kgm_iopmpriv->PreviousRequest
5215 document showioservicepm
5216 Syntax: (gdb) showioservicepm <IOServicePM pointer>
5217 | Routine to dump the IOServicePM object
5220 define showregistryentryrecursepmstate
5221 set $kgm_re = (IOService *)$arg1
5222 set $kgm$arg0_stack = (unsigned long long) $arg2
5225 set $kgm$arg0_stack = $kgm$arg0_stack | (1ULL << $kgm_reg_depth)
5227 set $kgm$arg0_stack = $kgm$arg0_stack & ~(1ULL << $kgm_reg_depth)
5230 dictget $kgm_re->fRegistryTable $kgm_childkey
5231 set $kgm$arg0_child_array = (OSArray *) $kgm_result
5233 if ($kgm$arg0_child_array)
5234 set $kgm$arg0_child_count = $kgm$arg0_child_array->count
5236 set $kgm$arg0_child_count = 0
5239 if ($kgm$arg0_child_count)
5240 set $kgm$arg0_stack = $kgm$arg0_stack | (2ULL << $kgm_reg_depth)
5242 set $kgm$arg0_stack = $kgm$arg0_stack & ~(2ULL << $kgm_reg_depth)
5245 indent $kgm_reg_depth $kgm$arg0_stack
5248 dictget $kgm_re->fRegistryTable $kgm_namekey
5249 if ($kgm_result == 0)
5250 dictget $kgm_re->fRegistryTable gIONameKey
5252 if ($kgm_result == 0)
5253 dictget $kgm_re->fPropertyTable gIOClassKey
5256 if ($kgm_result != 0)
5257 printf "%s <%p>", ((OSString *)$kgm_result)->string, $kgm_re
5259 if (((IOService*)$kgm_re)->pwrMgt && ((IOService*)$kgm_re)->pwrMgt->Name)
5260 printf "%s <%p>", ((IOService*)$kgm_re)->pwrMgt->Name, $kgm_re
5262 printf "?? <%p>", $kgm_re
5266 if (((IOService*)$kgm_re)->pwrMgt )
5267 printf " Current Power State: %ld ", ((IOService*)$kgm_re)->pwrMgt->CurrentPowerState
5268 #printf " Mach State %ld", ((IOService*)$kgm_re)->pwrMgt->MachineState
5269 showioservicepm ((IOService*)$kgm_re)->pwrMgt
5275 if ($kgm$arg0_child_count != 0)
5277 set $kgm_reg_depth = $kgm_reg_depth + 1
5278 set $kgm$arg0_child_idx = 0
5280 while ($kgm$arg0_child_idx < $kgm$arg0_child_count)
5281 set $kgm_re = $kgm$arg0_child_array->array[$kgm$arg0_child_idx++]
5282 set $kgm_more_sib = ($kgm$arg0_child_idx < $kgm$arg0_child_count)
5283 showregistryentryrecursepmstate _$arg0 $kgm_re $kgm$arg0_stack $kgm_more_sib
5286 set $kgm_reg_depth = $kgm_reg_depth - 1
5290 define showregistryentryintpmstate
5291 set $kgm_namekey = (OSSymbol *) $kgm_reg_plane[2]
5292 set $kgm_childkey = (OSSymbol *) $kgm_reg_plane[4]
5293 showregistryentryrecursepmstate _ $arg0 0 0
5296 define showregistrypmstate
5297 # setregistryplane gIOPowerPlane
5298 set $kgm_reg_depth = 0
5299 set $kgm_show_props = 1
5300 showregistryentryintpmstate gRegistryRoot
5303 document showregistrypmstate
5304 Syntax: (gdb) showregistrypmstate
5305 | Routine to dump the PM state of each IOPower registry entry
5308 define showstacksafterthread
5309 set $kgm_head_taskp = &default_pset.tasks
5310 set $kgm_actp = (struct thread *)$arg0
5311 set $kgm_actp = (struct thread *)($kgm_actp->task_threads.next)
5312 set $kgm_taskp = (struct task *)$kgm_actp->task
5313 while $kgm_taskp != $kgm_head_taskp
5315 showtaskint $kgm_taskp
5316 set $kgm_head_actp = &($kgm_taskp->threads)
5317 while $kgm_actp != $kgm_head_actp
5319 if ($decode_wait_events > 0)
5320 showactint $kgm_actp 1
5322 showactint $kgm_actp 2
5324 set $kgm_actp = (struct thread *)($kgm_actp->task_threads.next)
5327 set $kgm_taskp = (struct task *)($kgm_taskp->pset_tasks.next)
5331 document showstacksafterthread
5332 Syntax: (gdb) showstacksafterthread <thread>
5333 | Routine to print out all stacks (as in showallstacks) starting after a given thread
5334 | Useful if that gdb refuses to print a certain task's stack.
5338 set kdp_reentry_deadline = ((unsigned) $arg0)*1000
5342 document kdp-reenter
5343 Syntax: (gdb) kdp-reenter <seconds>
5344 | Schedules reentry into the debugger after <seconds> seconds, and resumes
5345 | the target system.
5356 if ($kgm_mtype != 7)
5357 printf "Not available for current architecture.\n"
5360 _if_present mca_MCA_present
5361 printf ", control MSR"
5362 _if_present mca_control_MSR_present
5363 printf ", threshold status"
5364 _if_present mca_threshold_status_present
5365 printf "\n%d error banks, ", mca_error_bank_count
5366 printf "family code 0x%x, ", mca_family
5367 printf "machine-check dump state: %d\n", mca_dump_state
5369 while cpu_data_ptr[$kgm_cpu] != 0
5370 set $kgm_mcp = cpu_data_ptr[$kgm_cpu]->cpu_mca_state
5372 printf "CPU %d:", $kgm_cpu
5373 printf " mca_mcg_ctl: 0x%016llx", $kgm_mcp->mca_mcg_ctl
5374 printf " mca_mcg_status: 0x%016llx\n", $kgm_mcp->mca_mcg_status.u64
5376 printf "mca_mci_ctl "
5377 printf "mca_mci_status "
5378 printf "mca_mci_addr "
5379 printf "mca_mci_misc\n"
5381 while $kgm_bank < mca_error_bank_count
5382 set $kgm_bp = &$kgm_mcp->mca_error_bank[$kgm_bank]
5383 printf " %2d:", $kgm_bank
5384 printf " 0x%016llx", $kgm_bp->mca_mci_ctl
5385 printf " 0x%016llx", $kgm_bp->mca_mci_status.u64
5386 printf " 0x%016llx", $kgm_bp->mca_mci_addr
5387 printf " 0x%016llx\n", $kgm_bp->mca_mci_misc
5388 set $kgm_bank = $kgm_bank + 1
5391 set $kgm_cpu = $kgm_cpu + 1
5396 document showMCAstate
5397 Syntax: showMCAstate
5398 | Print machine-check register state after MC exception.
5403 # Step to lower-level page table and print attributes
5404 # $kgm_pt_paddr: current page table entry physical address
5405 # $kgm_pt_index: current page table entry index (0..511)
5407 # $kgm_pt_paddr: next level page table entry physical address
5408 # or null if invalid
5409 # For $kgm_pt_verbose = 0: print nothing
5410 # 1: print basic information
5411 # 2: print basic information and hex table dump
5412 # The trickery with kdp_src_high32 is required for accesses above 4GB.
5414 set $kgm_entryp = $kgm_pt_paddr + 8*$kgm_pt_index
5415 set kdp_src_high32 = $kgm_pt_paddr >> 32
5416 set kdp_trans_off = 1
5417 set $entry = *(pt_entry_t *)($kgm_entryp & 0x0ffffffffULL)
5418 if $kgm_pt_verbose == 2
5419 x/512g ($kgm_pt_paddr & 0x0ffffffffULL)
5421 set kdp_trans_off = 0
5422 set kdp_src_high32 = 0
5423 set $kgm_paddr_mask = ~((0xffffULL<<48) | 0xfffULL)
5424 if $kgm_pt_verbose == 0
5425 if $entry & (0x1 << 0)
5426 set $kgm_pt_paddr = $entry & $kgm_paddr_mask
5428 set $kgm_pt_paddr = 0
5431 printf "0x%016llx:\n\t0x%016llx\n\t", $kgm_entryp, $entry
5432 if $entry & (0x1 << 0)
5434 set $kgm_pt_paddr = $entry & $kgm_paddr_mask
5437 set $kgm_pt_paddr = 0
5439 if $entry & (0x1 << 1)
5444 if $entry & (0x1 << 2)
5447 printf " supervisor"
5449 if $entry & (0x1 << 3)
5452 if $entry & (0x1 << 4)
5455 if $entry & (0x1 << 5)
5458 if $entry & (0x1 << 6)
5461 if $entry & (0x1 << 7)
5464 if $entry & (0x1 << 8)
5467 if $entry & (0x3 << 9)
5468 printf " avail:0x%x", ($entry >> 9) & 0x3
5470 if $entry & (0x1 << 63)
5478 set $kgm_pmap = (pmap_t) $arg0
5479 set $kgm_vaddr = $arg1
5480 set $kgm_pt_paddr = $kgm_pmap->pm_cr3
5481 if $kgm_pt_paddr && cpu_64bit
5482 set $kgm_pt_index = ($kgm_vaddr >> 39) & 0x1ffULL
5484 printf "pml4 (index %d):\n", $kgm_pt_index
5489 set $kgm_pt_index = ($kgm_vaddr >> 30) & 0x1ffULL
5491 printf "pdpt (index %d):\n", $kgm_pt_index
5496 set $kgm_pt_index = ($kgm_vaddr >> 21) & 0x1ffULL
5498 printf "pdt (index %d):\n", $kgm_pt_index
5503 set $kgm_pt_index = ($kgm_vaddr >> 12) & 0x1ffULL
5505 printf "pt (index %d):\n", $kgm_pt_index
5510 set $kgm_paddr = $kgm_pt_paddr + ($kgm_vaddr & 0xfffULL)
5511 set kdp_trans_off = 1
5512 set kdp_src_high32 = $kgm_paddr >> 32
5513 set $kgm_value = *($kgm_paddr & 0x0ffffffffULL)
5514 set kdp_trans_off = 0
5515 set kdp_src_high32 = 0
5516 printf "phys 0x%016llx: 0x%08x\n", $kgm_paddr, $kgm_value
5519 printf "(no translation)\n"
5525 printf "Not available for current architecture.\n"
5528 printf "pmap_walk <pmap> <vaddr>\n"
5531 set $kgm_pt_verbose = 1
5533 if $kgm_pt_verbose != 2
5534 set $kgm_pt_verbose = 1
5537 _pmap_walk $arg0 $arg1
5543 Syntax: (gdb) pmap_walk <pmap> <virtual_address>
5544 | Perform a page-table walk in <pmap> for <virtual_address>.
5545 | Set $kgm_pt_verbose=2 for full hex dump of page tables.
5550 printf "Not available for current architecture.\n"
5553 printf "pmap_vtop <pamp> <vaddr>\n"
5555 set $kgm_pt_verbose = 0
5556 _pmap_walk $arg0 $arg1
5562 Syntax: (gdb) pmap_vtop <pmap> <virtual_address>
5563 | For page-tables in <pmap> translate <virtual_address> to physical address.