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 # This option tells gdb to relax its stack tracing heuristics
12 # Useful for debugging across stack switches
13 # (to the interrupt stack, for instance). Requires gdb-675 or greater.
14 set backtrace sanity-checks off
16 echo Loading Kernel GDB Macros package. Type "help kgm" for more info.\n
20 echo These are the gdb macros for kernel debugging. Type "help kgm" for more info.\n
24 | These are the kernel gdb macros. These gdb macros are intended to be
25 | used when debugging a remote kernel via the kdp protocol. Typically, you
26 | would connect to your remote target like so:
27 | (gdb) target remote-kdp
28 | (gdb) attach <name-of-remote-host>
30 | The following macros are available in this package:
31 | showversion Displays a string describing the remote kernel version
33 | showalltasks Display a summary listing of all tasks
34 | showallthreads Display info about all threads in the system
35 | showallstacks Display the stack for each thread in the system
36 | showcurrentthreads Display info about the thread running on each cpu
37 | showcurrentstacks Display the stack for the thread running on each cpu
38 | showallvm Display a summary listing of all the vm maps
39 | showallvme Display a summary listing of all the vm map entries
40 | showallipc Display a summary listing of all the ipc spaces
41 | showallrights Display a summary listing of all the ipc rights
42 | showallkmods Display a summary listing of all the kernel modules
43 | showallbusyports Display a listing of all ports with unread messages
45 | showallclasses Display info about all OSObject subclasses in the system
46 | showobject Show info about an OSObject - its vtable ptr and retain count, & more info for simple container classes.
47 | showregistry Show info about all registry entries in the current plane
48 | showregistryprops Show info about all registry entries in the current plane, and their properties
49 | showregistryentry Show info about a registry entry; its properties and descendants in the current plane
50 | setregistryplane Set the plane to be used for the iokit registry macros (pass zero for list)
52 | setfindregistrystr Set the encoded string for matching with
53 | findregistryentry or findregistryprop (created from
55 | findregistryentry Find a registry entry that matches the encoded string
56 | findregistryentries Find all the registry entries that match the encoded string
57 | findregistryprop Search the registry entry for a property that matches
60 | showtask Display info about the specified task
61 | showtaskthreads Display info about the threads in the task
62 | showtaskstacks Display the stack for each thread in the task
63 | showtaskvm Display info about the specified task's vm_map
64 | showtaskvme Display info about the task's vm_map entries
65 | showtaskipc Display info about the specified task's ipc space
66 | showtaskrights Display info about the task's ipc space entries
67 | showtaskbusyports Display all of the task's ports with unread messages
69 | showact Display info about a thread specified by activation
70 | showactstack Display the stack for a thread specified by activation
72 | showmap Display info about the specified vm_map
73 | showmapvme Display a summary list of the specified vm_map's entries
75 | showipc Display info about the specified ipc space
76 | showrights Display a summary list of all the rights in an ipc space
78 | showpid Display info about the process identified by pid
79 | showproc Display info about the process identified by proc struct
80 | showprocinfo Display detailed info about the process identified by proc struct
81 | showprocfiles Given a proc_t pointer, display the list of open file descriptors
82 | showproclocks Given a proc_t pointer, display the list of advisory file locks
83 | zombproc Print out all procs in the zombie list
84 | allproc Print out all process in the system not in the zombie list
85 | zombstacks Print out all stacks of tasks that are exiting
87 | showinitchild Print out all processes in the system which are children of init process
89 | showkmod Display info about a kernel module
90 | showkmodaddr Given an address, display the kernel module and offset
92 | dumpcallqueue Dump out all the entries given a queue head
94 | showallmtx Display info about mutexes usage
95 | showallrwlck Display info about reader/writer locks usage
97 | zprint Display info about the memory zones
98 | showioalloc Display info about iokit allocations
99 | paniclog Display the panic log info
101 | switchtoact Switch to different context specified by activation
102 | switchtoctx Switch to different context
103 | showuserstack Display numeric backtrace of the user stack for an
106 | switchtouserthread Switch to the user context of the specified thread
107 | resetstacks Return to the original kernel context
109 | resetctx Reset context
110 | resume_on Resume when detaching from gdb
111 | resume_off Don't resume when detaching from gdb
113 | sendcore Configure kernel to send a coredump to the specified IP
114 | sendsyslog Configure kernel to send a system log to the specified IP
115 | sendpaniclog Configure kernel to send a panic log to the specified IP
116 | disablecore Configure the kernel to disable coredump transmission
117 | getdumpinfo Retrieve the current remote dump parameters
118 | setdumpinfo Configure the remote dump parameters
120 | switchtocorethread Corefile version of "switchtoact"
121 | resetcorectx Corefile version of "resetctx"
123 | readphys8 Reads the specified untranslated address (8-bit read)
124 | readphys16 Reads the specified untranslated address (16-bit read)
125 | readphys32 Reads the specified untranslated address (32-bit read)
126 | readphys64 Reads the specified untranslated address (64-bit read)
127 | writephys8 Writes to the specified untranslated address (8-bit write)
128 | writephys16 Writes to the specified untranslated address (16-bit write)
129 | writephys32 Writes to the specified untranslated address (32-bit write)
130 | writephys64 Writes to the specified untranslated address (64-bit write)
132 | readioport8 Read 8-bits from the specified I/O Port
133 | readioport16 Read 16-bits from the specified I/O Port
134 | readioport32 Read 32-bits from the specified I/O Port
135 | writeioport8 Write 8-bits into the specified I/O Port
136 | writeioport16 Write 16-bits into the specified I/O Port
137 | writeioport32 Write 32-bits into the specified I/O Port
139 | readmsr64 Read 64-bits from the specified MSR
140 | writemsr64 Write 64-bits into the specified MSR
142 | rtentry_showdbg Print the debug information of a route entry
143 | rtentry_trash Walk the list of trash route entries
145 | inifa_showdbg Print the debug information of an IPv4 interface address
146 | in6ifa_showdbg Print the debug information of an IPv6 interface address
148 | mbuf_walkpkt Walk the mbuf packet chain (m_nextpkt)
149 | mbuf_walk Walk the mbuf chain (m_next)
150 | mbuf_buf2slab Find the slab structure of the corresponding buffer
151 | mbuf_buf2mca Find the mcache audit structure of the corresponding mbuf
152 | mbuf_showmca Print the contents of an mbuf mcache audit structure
153 | mbuf_showactive Print all active/in-use mbuf objects
154 | mbuf_showinactive Print all freed/in-cache mbuf objects
155 | mbuf_showall Print all mbuf objects
156 | mbuf_slabs Print all slabs in the group
157 | mbuf_slabstbl Print slabs table
158 | mbuf_stat Print extended mbuf allocator statistics
160 | mcache_walkobj Walk the mcache object chain (obj_next)
161 | mcache_stat Print all mcaches in the system
162 | mcache_showcache Display the number of objects in the cache
164 | showbootargs Display boot arguments passed to the target kernel
165 | showbootermemorymap Dump phys memory map from EFI
167 | systemlog Display the kernel's printf ring buffer
169 | hexdump Show the contents of memory as a hex/ASCII dump
171 | showvnodepath Print the path for a vnode
172 | showvnodelocks Display list of advisory locks held/blocked on a vnode
173 | showvnodedev Display information about a device vnode
174 | showtty Display information about a struct tty
175 | showallvols Display a summary of mounted volumes
176 | showvnode Display info about one vnode
177 | showvolvnodes Display info about all vnodes of a given volume
178 | showvolbusyvnodes Display info about busy (iocount!=0) vnodes of a given volume
179 | showallbusyvnodes Display info about all busy (iocount!=0) vnodes
180 | showallvnodes Display info about all vnodes
181 | print_vnode Print out the fields of a vnode struct
182 | showprocvnodes Print out all the open fds which are vnodes in a process
183 | showallprocvnodes Print out all the open fds which are vnodes in any process
184 | showmountvnodes Print the vnode list
185 | showmountallvnodes Print the vnode inactive list
186 | showworkqvnodes Print the vnode worker list
187 | shownewvnodes Print the new vnode list
189 | ifconfig display ifconfig-like output
190 | showifaddrs show the list of addresses for the given ifp
191 | showifmultiaddrs show the list of multicast addresses for the given ifp
193 | showsocket Display information about a socket
194 | showprocsockets Given a proc_t pointer, display information about its sockets
195 | showallprocsockets Display information about the sockets of all the processes
197 | show_tcp_pcbinfo Display the list of the TCP protocol control blocks
198 | show_tcp_timewaitslots Display the list of the TCP protocol control blocks in TIMEWAIT
199 | show_udp_pcbinfo Display the list of UDP protocol control blocks
201 | show_rt_inet Display the IPv4 routing table
202 | show_rt_inet6 Display the IPv6 routing table
204 | showallpmworkqueues Display info about all IOPMWorkQueue objects
205 | showregistrypmstate Display power management state for all IOPower registry entries
206 | showioservicepm Display the IOServicePM object
207 | showstacksaftertask showallstacks starting after a given task
208 | showstacksafterthread showallstacks starting after a given thread
210 | showMCAstate Print machine-check register state after MC exception.
212 | showallgdbstacks Cause GDB to trace all thread stacks
213 | showallgdbcorestacks Corefile equivalent of "showallgdbstacks"
214 | kdp-reenter Schedule reentry into the debugger and continue.
215 | kdp-reboot Restart remote target
216 | kdp-version Get KDP version number
218 | zstack Print zalloc caller stack (zone leak debugging)
219 | findoldest Find oldest zone leak debugging record
220 | countpcs Print how often a pc occurs in the zone leak log
222 | pmap_walk Perform a page-table walk
223 | pmap_vtop Translate a virtual address to physical address
225 | showuserlibraries Show binary images known by dyld in the target task
227 | showthreadfortid Displays the address of the thread structure for a given thread_id value.
229 | strcmp_nomalloc A version of strcmp that avoids the use of malloc
230 | through the use of encoded strings created via
232 | strcmp_arg_pack64 Pack a string into a 64-bit quantity for use by
235 | pci_cfg_read8 Read 8-bits from a PCI config space register
236 | pci_cfg_read16 Read 16-bits from a PCI config space register
237 | pci_cfg_read32 Read 32-bits from a PCI config space register
238 | pci_cfg_write8 Write 8-bits into a PCI config space register
239 | pci_cfg_write16 Write 16-bits into a PCI config space register
240 | pci_cfg_write32 Write 32-bits into a PCI config space register
241 | pci_cfg_dump Dump entire config space for a PCI device
242 | pci_cfg_scan Perform a scan for PCI devices
243 | pci_cfg_dump_all Dump config spaces for all detected PCI devices
245 | lapic_read32 Read APIC entry
246 | lapic_write32 Write APIC entry
247 | lapic_dump Dump APIC entries
249 | ioapic_read32 Read IOAPIC entry
250 | ioapic_write32 Write IOAPIC entry
251 | ioapic_dump Dump IOAPIC entries
253 | Type "help <macro>" for more specific help on a particular macro.
254 | Type "show user <macro>" to see what the macro is really doing.
257 # This macro should appear before any symbol references, to facilitate
258 # a gdb "source" without a loaded symbol file.
265 | Read the kernel version string from a fixed address in low
266 | memory. Useful if you don't know which kernel is on the other end,
267 | and need to find the appropriate symbols. Beware that if you've
268 | loaded a symbol file, but aren't connected to a remote target,
269 | the version string from the symbol file will be displayed instead.
270 | This macro expects to be connected to the remote kernel to function
274 set $kgm_mtype_ppc = 0x00000012
275 set $kgm_mtype_arm = 0x0000000C
277 set $kgm_mtype_i386 = 0x00000007
278 set $kgm_mtype_x86_64 = 0x01000007
279 set $kgm_mtype_x86_any = $kgm_mtype_i386
280 set $kgm_mtype_x86_mask = 0xFEFFFFFF
282 set $kgm_mtype = ((unsigned int *)&_mh_execute_header)[1]
283 set $kgm_lp64 = $kgm_mtype & 0x01000000
285 set $kgm_manual_pkt_ppc = 0x549C
286 set $kgm_manual_pkt_i386 = 0x249C
287 set $kgm_manual_pkt_x86_64 = 0xFFFFFF8000002930
288 set $kgm_manual_pkt_arm = 0xFFFF04A0
290 set $kgm_kdp_pkt_data_len = 128
292 # part of data packet
293 set $kgm_kdp_pkt_hdr_req_off = 0
294 set $kgm_kdp_pkt_hdr_seq_off = 1
295 set $kgm_kdp_pkt_hdr_len_off = 2
296 set $kgm_kdp_pkt_hdr_key_off = 4
299 set $kgm_kdp_pkt_len_off = $kgm_kdp_pkt_data_len
300 set $kgm_kdp_pkt_input_off = $kgm_kdp_pkt_data_len + 4
302 set $kgm_kdp_pkt_hostreboot = 0x13
303 set $kgm_kdp_pkt_hdr_size = 8
305 set $kgm_lcpu_self = 0xFFFE
307 set $kgm_reg_depth = 0
308 set $kgm_reg_depth_max = 0xFFFF
309 set $kgm_reg_plane = (IORegistryPlane *) gIOServicePlane
310 set $kgm_namekey = (OSSymbol *) 0
311 set $kgm_childkey = (OSSymbol *) 0
313 set $kgm_show_object_addrs = 0
314 set $kgm_show_object_retain = 0
315 set $kgm_show_props = 0
316 set $kgm_show_data_alwaysbytes = 0
318 set $kgm_show_kmod_syms = 0
320 # send a manual packet header that doesn't require knowing the location
325 set $hdrp = (uint32_t *) $kgm_manual_pkt_i386
326 if ($kgm_mtype == $kgm_mtype_ppc)
327 set $hdrp = (uint32_t *) $kgm_manual_pkt_ppc
328 set $req = $req << 1 # shift to deal with endiannness
330 if ($kgm_mtype == $kgm_mtype_x86_64)
331 set $hdrp = (uint64_t *) $kgm_manual_pkt_x86_64
333 if ($kgm_mtype == $kgm_mtype_arm)
334 set $hdrp = (uint32_t *) $kgm_manual_pkt_arm
337 set $pkt_hdr = *$hdrp
338 set *((uint8_t *) ($pkt_hdr + $kgm_kdp_pkt_input_off)) = 0
339 set *((uint32_t *) ($pkt_hdr + $kgm_kdp_pkt_len_off)) = $kgm_kdp_pkt_hdr_size
341 set *((uint8_t *) ($pkt_hdr + $kgm_kdp_pkt_hdr_req_off)) = $req
342 set *((uint8_t *) ($pkt_hdr + $kgm_kdp_pkt_hdr_seq_off)) = 0
343 set *((uint16_t *) ($pkt_hdr + $kgm_kdp_pkt_hdr_len_off)) = $kgm_kdp_pkt_hdr_size
344 set *((uint32_t *) ($pkt_hdr + $kgm_kdp_pkt_hdr_key_off)) = 0
345 set *((uint8_t *) ($pkt_hdr + $kgm_kdp_pkt_input_off)) = 1
347 # dummy to make sure manual packet is executed
348 set $kgm_dummy = &_mh_execute_header
354 printf "0x%016llx", $arg0
356 printf "0x%08x", $arg0
360 # for headers, leave 8 chars for LP64 pointers
367 define showkmodheader
374 printf " id refs version name\n"
378 set $kgm_kmodp = (struct kmod_info *)$arg0
381 showptr $kgm_kmodp->address
383 showptr $kgm_kmodp->size
385 printf "%3d ", $kgm_kmodp->id
386 printf "%5d ", $kgm_kmodp->reference_count
387 printf "%10s ", $kgm_kmodp->version
388 printf "%s\n", $kgm_kmodp->name
391 # cached info of the last kext found, to speed up subsequent lookups
396 define showkmodaddrint
398 if ((unsigned long)$arg0 >= (unsigned long)$kgm_pkmodst) && ((unsigned long)$arg0 < (unsigned long)$kgm_pkmoden)
399 set $kgm_off = ((unsigned long)$arg0 - (unsigned long)$kgm_pkmodst)
400 printf " <%s + 0x%x>", $kgm_pkmod->name, $kgm_off
402 set $kgm_kmodp = (struct kmod_info *)kmod
403 if ($kgm_mtype == $kgm_mtype_x86_64) && ($arg0 >= (unsigned long)&_mh_execute_header)
404 # kexts are loaded below the kernel for x86_64
408 set $kgm_off = ((unsigned long)$arg0 - (unsigned long)$kgm_kmodp->address)
409 if ($kgm_kmodp->address <= $arg0) && ($kgm_off < $kgm_kmodp->size)
410 printf " <%s + 0x%x>", $kgm_kmodp->name, $kgm_off
411 set $kgm_pkmod = $kgm_kmodp
412 set $kgm_pkmodst = $kgm_kmodp->address
413 set $kgm_pkmoden = $kgm_pkmodst + $kgm_kmodp->size
416 set $kgm_kmodp = $kgm_kmodp->next
423 showkmodaddrint $arg0
426 document showkmodaddr
427 Syntax: (gdb) showkmodaddr <addr>
428 | Given an address, print the offset and name for the kmod containing it
436 Syntax: (gdb) showkmod <kmod>
437 | Routine to print info about a kernel module
442 set $kgm_kmodp = (struct kmod_info *)kmod
444 showkmodint $kgm_kmodp
445 set $kgm_kmodp = $kgm_kmodp->next
448 document showallkmods
449 Syntax: (gdb) showallkmods
450 | Routine to print a summary listing of all the kernel modules
462 printf " pri io_policy state wait_queue"
464 printf " wait_event\n"
471 set $kgm_thread = *(struct thread *)$arg0
473 if ($kgm_thread.static_param)
478 printf " %7ld ", $kgm_thread.thread_id
479 showptr $kgm_thread.last_processor
480 printf " %3d ", $kgm_thread.sched_pri
481 if ($kgm_thread.uthread != 0)
483 set $kgm_uthread = (struct uthread *)$kgm_thread.uthread
484 if ($kgm_uthread->uu_flag & 0x400)
489 if ($kgm_uthread->uu_iopol_disk == 1)
493 if ($kgm_uthread->uu_iopol_disk == 2)
497 if ($kgm_uthread->uu_iopol_disk == 3)
501 if ($kgm_printed == 0)
505 set $kgm_state = $kgm_thread.state
530 showptr $kgm_thread.wait_queue
532 if (((unsigned long)$kgm_thread.wait_event > (unsigned long)&last_kernel_symbol) \
533 && ($arg1 != 2) && ($kgm_show_kmod_syms == 0))
534 showkmodaddr $kgm_thread.wait_event
536 output /a $kgm_thread.wait_event
538 if ($kgm_thread.uthread != 0)
539 set $kgm_uthread = (struct uthread *)$kgm_thread.uthread
540 if ($kgm_uthread->uu_wmesg != 0)
541 printf "\t \"%s\"", $kgm_uthread->uu_wmesg
546 if ($kgm_thread.kernel_stack != 0)
547 if ($kgm_thread.reserved_stack != 0)
550 printf " reserved_stack="
551 showptr $kgm_thread.reserved_stack
555 printf " kernel_stack="
556 showptr $kgm_thread.kernel_stack
557 if ($kgm_mtype == $kgm_mtype_ppc)
558 set $mysp = $kgm_thread.machine.pcb->save_r1
560 if (($kgm_mtype & $kgm_mtype_x86_mask) == $kgm_mtype_x86_any)
561 set $kgm_statep = (struct x86_kernel_state *) \
562 ($kgm_thread->kernel_stack + kernel_stack_size \
563 - sizeof(struct x86_kernel_state))
564 if ($kgm_mtype == $kgm_mtype_i386)
565 set $mysp = $kgm_statep->k_ebp
567 set $mysp = $kgm_statep->k_rbp
570 if ($kgm_mtype == $kgm_mtype_arm)
571 if (((unsigned long)$r7 < ((unsigned long) ($kgm_thread->kernel_stack+kernel_stack_size))) \
572 && ((unsigned long)$r7 > (unsigned long) ($kgm_thread->kernel_stack)))
575 set $kgm_statep = (struct arm_saved_state *)$kgm_thread.machine.kstackptr
576 set $mysp = $kgm_statep->r[7]
579 set $prevsp = $mysp - 16
584 if ($kgm_mtype == $kgm_mtype_ppc)
590 while ($mysp != 0) && (($mysp & $stkmask) == 0) \
591 && ($mysp != $prevsp) \
592 && ((((unsigned long) $mysp ^ (unsigned long) $prevsp) < 0x2000) \
593 || (((unsigned long)$mysp < ((unsigned long) ($kgm_thread->kernel_stack+kernel_stack_size))) \
594 && ((unsigned long)$mysp > (unsigned long) ($kgm_thread->kernel_stack))))
600 if ($kgm_mtype == $kgm_mtype_ppc)
601 set $kgm_return = *($mysp + 8)
603 if ($kgm_mtype == $kgm_mtype_i386)
604 set $kgm_return = *($mysp + 4)
606 if ($kgm_mtype == $kgm_mtype_x86_64)
607 set $kgm_return = *(unsigned long *)($mysp + 8)
609 if ($kgm_mtype == $kgm_mtype_arm)
610 set $kgm_return = *($mysp + 4)
612 if (((unsigned long) $kgm_return < (unsigned long) &_mh_execute_header || \
613 (unsigned long) $kgm_return >= (unsigned long) &last_kernel_symbol ) \
614 && ($kgm_show_kmod_syms == 0))
615 showkmodaddr $kgm_return
617 output /a $kgm_return
620 set $mysp = *(unsigned long *)$mysp
625 printf " stackbottom="
630 printf " continuation="
631 output /a $kgm_thread.continuation
644 Syntax: (gdb) showact <activation>
645 | Routine to print out the state of a specific thread.
653 document showactstack
654 Syntax: (gdb) showactstack <activation>
655 | Routine to print out the stack of a specific thread.
659 define showallthreads
660 set $kgm_head_taskp = &tasks
661 set $kgm_taskp = (struct task *)($kgm_head_taskp->next)
662 while $kgm_taskp != $kgm_head_taskp
664 showtaskint $kgm_taskp
666 set $kgm_head_actp = &($kgm_taskp->threads)
667 set $kgm_actp = (struct thread *)($kgm_taskp->threads.next)
668 while $kgm_actp != $kgm_head_actp
669 showactint $kgm_actp 0
670 set $kgm_actp = (struct thread *)($kgm_actp->task_threads.next)
673 set $kgm_taskp = (struct task *)($kgm_taskp->tasks.next)
676 document showallthreads
677 Syntax: (gdb) showallthreads
678 | Routine to print out info about all threads in the system.
681 define showcurrentthreads
682 set $kgm_prp = (struct processor *)processor_list
684 printf "Processor 0x%08x State %d (cpu_id %x)\n", $kgm_prp, ($kgm_prp)->state, ($kgm_prp)->cpu_id
685 if ($kgm_prp)->active_thread != 0
686 set $kgm_actp = ($kgm_prp)->active_thread
688 showtaskint ($kgm_actp)->task
690 showactint $kgm_actp 0
693 set $kgm_prp = ($kgm_prp)->processor_list
696 document showcurrentthreads
697 Syntax: (gdb) showcurrentthreads
698 | Routine to print out info about the thread running on each cpu.
701 set $decode_wait_events = 0
703 set $kgm_head_taskp = &tasks
704 set $kgm_taskp = (struct task *)($kgm_head_taskp->next)
705 while $kgm_taskp != $kgm_head_taskp
707 showtaskint $kgm_taskp
708 set $kgm_head_actp = &($kgm_taskp->threads)
709 set $kgm_actp = (struct thread *)($kgm_taskp->threads.next)
710 while $kgm_actp != $kgm_head_actp
712 if ($decode_wait_events > 0)
713 showactint $kgm_actp 1
715 showactint $kgm_actp 2
717 set $kgm_actp = (struct thread *)($kgm_actp->task_threads.next)
720 set $kgm_taskp = (struct task *)($kgm_taskp->tasks.next)
724 document showallstacks
725 Syntax: (gdb) showallstacks
726 | Routine to print out the stack for each thread in the system.
727 | If the variable $decode_wait_events is non-zero, the routine attempts to
728 | interpret thread wait_events as kernel module offsets, which can add to
732 define showcurrentstacks
733 set $kgm_prp = processor_list
735 printf "Processor 0x%08x State %d (cpu_id %x)\n", $kgm_prp, ($kgm_prp)->state, ($kgm_prp)->cpu_id
736 if ($kgm_prp)->active_thread != 0
737 set $kgm_actp = ($kgm_prp)->active_thread
739 showtaskint ($kgm_actp)->task
741 showactint $kgm_actp 1
744 set $kgm_prp = ($kgm_prp)->processor_list
748 document showcurrentstacks
749 Syntax: (gdb) showcurrentstacks
750 | Routine to print out the thread running on each cpu (incl. its stack)
753 define showwaiterheader
754 printf "waiters thread "
755 printf "processor pri state wait_queue wait_event\n"
758 define showwaitqwaiters
759 set $kgm_w_waitqp = (WaitQueue*)$arg0
760 set $kgm_w_linksp = &($kgm_w_waitqp->wq_queue)
761 set $kgm_w_wqe = (WaitQueueElement *)$kgm_w_linksp->next
763 while ( (queue_entry_t)$kgm_w_wqe != (queue_entry_t)$kgm_w_linksp)
764 if ($kgm_w_wqe->wqe_type != &_wait_queue_link)
769 set $kgm_w_shuttle = (struct thread *)$kgm_w_wqe
770 showactint $kgm_w_shuttle 0
772 set $kgm_w_wqe = (WaitQueueElement *)$kgm_w_wqe->wqe_links.next
776 define showwaitqwaitercount
777 set $kgm_wc_waitqp = (WaitQueue*)$arg0
778 set $kgm_wc_linksp = &($kgm_wc_waitqp->wq_queue)
779 set $kgm_wc_wqe = (WaitQueueElement *)$kgm_wc_linksp->next
780 set $kgm_wc_count = 0
781 while ( (queue_entry_t)$kgm_wc_wqe != (queue_entry_t)$kgm_wc_linksp)
782 if ($kgm_wc_wqe->wqe_type != &_wait_queue_link)
783 set $kgm_wc_count = $kgm_wc_count + 1
785 set $kgm_wc_wqe = (WaitQueueElement *)$kgm_wc_wqe->wqe_links.next
787 printf "0x%08x ", $kgm_wc_count
790 define showwaitqmembercount
791 set $kgm_mc_waitqsetp = (WaitQueueSet*)$arg0
792 set $kgm_mc_setlinksp = &($kgm_mc_waitqsetp->wqs_setlinks)
793 set $kgm_mc_wql = (WaitQueueLink *)$kgm_mc_setlinksp->next
794 set $kgm_mc_count = 0
795 while ( (queue_entry_t)$kgm_mc_wql != (queue_entry_t)$kgm_mc_setlinksp)
796 set $kgm_mc_count = $kgm_mc_count + 1
797 set $kgm_mc_wql = (WaitQueueLink *)$kgm_mc_wql->wql_setlinks.next
799 printf "0x%08x ", $kgm_mc_count
803 define showwaitqmemberheader
804 printf "set-members wait_queue interlock "
805 printf "pol type member_cnt waiter_cnt\n"
808 define showwaitqmemberint
809 set $kgm_m_waitqp = (WaitQueue*)$arg0
810 printf " 0x%08x ", $kgm_m_waitqp
811 printf "0x%08x ", $kgm_m_waitqp->wq_interlock.lock_data
812 if ($kgm_m_waitqp->wq_fifo)
817 if ($kgm_m_waitqp->wq_type == 0xf1d1)
819 showwaitqmembercount $kgm_m_waitqp
821 printf "Que 0x00000000 "
823 showwaitqwaitercount $kgm_m_waitqp
828 define showwaitqmemberofheader
829 printf "member-of wait_queue interlock "
830 printf "pol type member_cnt waiter_cnt\n"
833 define showwaitqmemberof
834 set $kgm_mo_waitqp = (WaitQueue*)$arg0
835 set $kgm_mo_linksp = &($kgm_mo_waitqp->wq_queue)
836 set $kgm_mo_wqe = (WaitQueueElement *)$kgm_mo_linksp->next
837 set $kgm_mo_found = 0
838 while ( (queue_entry_t)$kgm_mo_wqe != (queue_entry_t)$kgm_mo_linksp)
839 if ($kgm_mo_wqe->wqe_type == &_wait_queue_link)
841 set $kgm_mo_found = 1
842 showwaitqmemberofheader
844 set $kgm_mo_wqlp = (WaitQueueLink *)$kgm_mo_wqe
845 set $kgm_mo_wqsetp = (WaitQueue*)($kgm_mo_wqlp->wql_setqueue)
846 showwaitqmemberint $kgm_mo_wqsetp
848 set $kgm_mo_wqe = (WaitQueueElement *)$kgm_mo_wqe->wqe_links.next
852 define showwaitqmembers
853 set $kgm_ms_waitqsetp = (WaitQueueSet*)$arg0
854 set $kgm_ms_setlinksp = &($kgm_ms_waitqsetp->wqs_setlinks)
855 set $kgm_ms_wql = (WaitQueueLink *)$kgm_ms_setlinksp->next
856 set $kgm_ms_found = 0
857 while ( (queue_entry_t)$kgm_ms_wql != (queue_entry_t)$kgm_ms_setlinksp)
858 set $kgm_ms_waitqp = $kgm_ms_wql->wql_element.wqe_queue
860 showwaitqmemberheader
861 set $kgm_ms_found = 1
863 showwaitqmemberint $kgm_ms_waitqp
864 set $kgm_ms_wql = (WaitQueueLink *)$kgm_ms_wql->wql_setlinks.next
868 define showwaitqheader
869 printf "wait_queue ref_count interlock "
870 printf "pol type member_cnt waiter_cnt\n"
874 set $kgm_waitqp = (WaitQueue*)$arg0
875 printf "0x%08x ", $kgm_waitqp
876 if ($kgm_waitqp->wq_type == 0xf1d1)
877 printf "0x%08x ", ((WaitQueueSet*)$kgm_waitqp)->wqs_refcount
881 printf "0x%08x ", $kgm_waitqp->wq_interlock.lock_data
882 if ($kgm_waitqp->wq_fifo)
887 if ($kgm_waitqp->wq_type == 0xf1d1)
889 showwaitqmembercount $kgm_waitqp
891 printf "Que 0x00000000 "
893 showwaitqwaitercount $kgm_waitqp
898 set $kgm_waitq1p = (WaitQueue*)$arg0
900 showwaitqint $kgm_waitq1p
901 if ($kgm_waitq1p->wq_type == 0xf1d1)
902 showwaitqmembers $kgm_waitq1p
904 showwaitqmemberof $kgm_waitq1p
906 showwaitqwaiters $kgm_waitq1p
916 printf " #ents rpage hint "
918 printf " first_free\n"
924 printf " start prot #page object "
930 set $kgm_mapp = (vm_map_t)$arg0
931 set $kgm_map = *$kgm_mapp
934 showptr $kgm_map.pmap
936 showptr $kgm_map.size
937 printf " %3d ", $kgm_map.hdr.nentries
939 printf "%5d ", $kgm_map.pmap->stats.resident_count
943 showptr $kgm_map.hint
945 showptr $kgm_map.first_free
949 set $kgm_head_vmep = &($kgm_mapp->hdr.links)
950 set $kgm_vmep = $kgm_map.hdr.links.next
951 while (($kgm_vmep != 0) && ($kgm_vmep != $kgm_head_vmep))
952 set $kgm_vme = *$kgm_vmep
955 printf " 0x%016llx ", $kgm_vme.links.start
956 printf "%1x", $kgm_vme.protection
957 printf "%1x", $kgm_vme.max_protection
958 if $kgm_vme.inheritance == 0x0
961 if $kgm_vme.inheritance == 0x1
964 if $kgm_vme.inheritance == 0x2
967 if $kgm_vme.inheritance == 0x3
970 if $kgm_vme.is_sub_map
973 if $kgm_vme.needs_copy
979 printf "%6d ",($kgm_vme.links.end - $kgm_vme.links.start) >> 12
980 showptr $kgm_vme.object.vm_object
981 printf " 0x%016llx\n", $kgm_vme.offset
982 set $kgm_vmep = $kgm_vme.links.next
994 Syntax: (gdb) showmapvme <vm_map>
995 | Routine to print out a summary listing of all the entries in a vm_map
1004 Syntax: (gdb) showmap <vm_map>
1005 | Routine to print out info about the specified vm_map
1009 set $kgm_head_taskp = &tasks
1010 set $kgm_taskp = (struct task *)($kgm_head_taskp->next)
1011 while $kgm_taskp != $kgm_head_taskp
1014 showtaskint $kgm_taskp
1015 showvmint $kgm_taskp->map 0
1016 set $kgm_taskp = (struct task *)($kgm_taskp->tasks.next)
1020 Syntax: (gdb) showallvm
1021 | Routine to print a summary listing of all the vm maps
1026 set $kgm_head_taskp = &tasks
1027 set $kgm_taskp = (struct task *)($kgm_head_taskp->next)
1028 while $kgm_taskp != $kgm_head_taskp
1031 showtaskint $kgm_taskp
1032 showvmint $kgm_taskp->map 1
1033 set $kgm_taskp = (struct task *)($kgm_taskp->tasks.next)
1037 Syntax: (gdb) showallvme
1038 | Routine to print a summary listing of all the vm map entries
1042 define showipcheader
1047 printf " table_next"
1049 printf " flags tsize splaytree splaybase\n"
1052 define showipceheader
1053 printf " name object "
1055 printf " rite urefs destname destination\n"
1059 set $kgm_ie = *(ipc_entry_t)$arg0
1060 printf " 0x%08x ", $arg1
1061 showptr $kgm_ie.ie_object
1063 if $kgm_ie.ie_bits & 0x00100000
1065 printf "%5d\n", $kgm_ie.ie_bits & 0xffff
1067 if $kgm_ie.ie_bits & 0x00080000
1069 printf "%5d\n", $kgm_ie.ie_bits & 0xffff
1071 if $kgm_ie.ie_bits & 0x00010000
1072 if $kgm_ie.ie_bits & 0x00020000
1078 if $kgm_ie.ie_bits & 0x00020000
1082 if $kgm_ie.ie_bits & 0x00040000
1085 if $kgm_ie.index.request
1090 if $kgm_ie.ie_bits & 0x00800000
1095 printf "%5d ", $kgm_ie.ie_bits & 0xffff
1096 showportdest $kgm_ie.ie_object
1102 set $kgm_isp = (ipc_space_t)$arg0
1103 set $kgm_is = *$kgm_isp
1106 showptr $kgm_is.is_table
1108 showptr $kgm_is.is_table_next
1110 if $kgm_is.is_growing != 0
1115 if $kgm_is.is_fast != 0
1120 if $kgm_is.is_active != 0
1125 printf "%5d ", $kgm_is.is_table_size
1126 printf "0x%08x ", $kgm_is.is_tree_total
1127 showptr &$kgm_isp->is_tree
1132 set $kgm_iep = $kgm_is.is_table
1133 set $kgm_destspacep = (ipc_space_t)0
1134 while ( $kgm_iindex < $kgm_is.is_table_size )
1135 set $kgm_ie = *$kgm_iep
1136 if $kgm_ie.ie_bits & 0x001f0000
1137 set $kgm_name = (($kgm_iindex << 8)|($kgm_ie.ie_bits >> 24))
1138 showipceint $kgm_iep $kgm_name
1140 set $kgm_iindex = $kgm_iindex + 1
1141 set $kgm_iep = &($kgm_is.is_table[$kgm_iindex])
1143 if $kgm_is.is_tree_total
1144 printf "Still need to write tree traversal\n"
1152 set $kgm_isp = (ipc_space_t)$arg0
1154 showipcint $kgm_isp 0
1157 Syntax: (gdb) showipc <ipc_space>
1158 | Routine to print the status of the specified ipc space
1162 set $kgm_isp = (ipc_space_t)$arg0
1164 showipcint $kgm_isp 1
1167 Syntax: (gdb) showrights <ipc_space>
1168 | Routine to print a summary list of all the rights in a specified ipc space
1173 set $kgm_taskp = (task_t)$arg0
1176 showtaskint $kgm_taskp
1177 showipcint $kgm_taskp->itk_space 0
1179 document showtaskipc
1180 Syntax: (gdb) showtaskipc <task>
1181 | Routine to print info about the ipc space for a task
1185 define showtaskrights
1186 set $kgm_taskp = (task_t)$arg0
1189 showtaskint $kgm_taskp
1190 showipcint $kgm_taskp->itk_space 1
1192 document showtaskrights
1193 Syntax: (gdb) showtaskrights <task>
1194 | Routine to print info about the ipc rights for a task
1198 set $kgm_head_taskp = &tasks
1199 set $kgm_cur_taskp = (struct task *)($kgm_head_taskp->next)
1200 while $kgm_cur_taskp != $kgm_head_taskp
1203 showtaskint $kgm_cur_taskp
1204 showipcint $kgm_cur_taskp->itk_space 0
1205 set $kgm_cur_taskp = (struct task *)($kgm_cur_taskp->tasks.next)
1209 Syntax: (gdb) showallipc
1210 | Routine to print a summary listing of all the ipc spaces
1214 define showallrights
1215 set $kgm_head_taskp = &tasks
1216 set $kgm_cur_taskp = (struct task *)($kgm_head_taskp->next)
1217 while $kgm_cur_taskp != $kgm_head_taskp
1220 showtaskint $kgm_cur_taskp
1221 showipcint $kgm_cur_taskp->itk_space 1
1222 set $kgm_cur_taskp = (struct task *)($kgm_cur_taskp->tasks.next)
1225 document showallrights
1226 Syntax: (gdb) showallrights
1227 | Routine to print a summary listing of all the ipc rights
1232 set $kgm_taskp = (task_t)$arg0
1235 showtaskint $kgm_taskp
1236 showvmint $kgm_taskp->map 0
1239 Syntax: (gdb) showtaskvm <task>
1240 | Routine to print out info about a task's vm_map
1244 set $kgm_taskp = (task_t)$arg0
1247 showtaskint $kgm_taskp
1248 showvmint $kgm_taskp->map 1
1250 document showtaskvme
1251 Syntax: (gdb) showtaskvme <task>
1252 | Routine to print out info about a task's vm_map_entries
1256 define showtaskheader
1261 printf " ipc_space "
1269 set $kgm_taskp = (struct task *)$arg0
1272 showptr $kgm_taskp->map
1274 showptr $kgm_taskp->itk_space
1275 printf " %5d ", $kgm_taskp->thread_count
1276 showprocint $kgm_taskp->bsd_info
1284 Syntax (gdb) showtask <task>
1285 | Routine to print out info about a task.
1289 define showtaskthreads
1291 set $kgm_taskp = (struct task *)$arg0
1292 showtaskint $kgm_taskp
1294 set $kgm_head_actp = &($kgm_taskp->threads)
1295 set $kgm_actp = (struct thread *)($kgm_taskp->threads.next)
1296 while $kgm_actp != $kgm_head_actp
1297 showactint $kgm_actp 0
1298 set $kgm_actp = (struct thread *)($kgm_actp->task_threads.next)
1301 document showtaskthreads
1302 Syntax: (gdb) showtaskthreads <task>
1303 | Routine to print info about the threads in a task.
1307 define showtaskstacks
1309 set $kgm_taskp = (struct task *)$arg0
1310 showtaskint $kgm_taskp
1311 set $kgm_head_actp = &($kgm_taskp->threads)
1312 set $kgm_actp = (struct thread *)($kgm_taskp->threads.next)
1313 while $kgm_actp != $kgm_head_actp
1315 showactint $kgm_actp 1
1316 set $kgm_actp = (struct thread *)($kgm_actp->task_threads.next)
1319 document showtaskstacks
1320 Syntax: (gdb) showtaskstacks <task>
1321 | Routine to print out the stack for each thread in a task.
1327 set $kgm_head_taskp = &tasks
1328 set $kgm_taskp = (struct task *)($kgm_head_taskp->next)
1329 while $kgm_taskp != $kgm_head_taskp
1330 showtaskint $kgm_taskp
1331 set $kgm_taskp = (struct task *)($kgm_taskp->tasks.next)
1334 document showalltasks
1335 Syntax: (gdb) showalltasks
1336 | Routine to print a summary listing of all the tasks
1337 | wq_state -> reports "number of workq threads", "number of scheduled workq threads", "number of pending work items"
1338 | if "number of pending work items" seems stuck at non-zero, it may indicate that the workqueue mechanism is hung
1339 | io_policy -> RAGE - rapid aging of vnodes requested
1340 | NORM - normal I/O explicitly requested (this is the default)
1341 | PASS - passive I/O requested (i.e. I/Os do not affect throttling decisions)
1342 | THROT - throttled I/O requested (i.e. thread/task may be throttled after each I/O completes)
1345 define showprocheader
1346 printf " pid process io_policy wq_state"
1352 set $kgm_procp = (struct proc *)$arg0
1354 set $kgm_printed = 0
1355 printf "%5d ", $kgm_procp->p_pid
1357 if ($kgm_procp->p_lflag & 0x400000)
1362 if ($kgm_procp->p_iopol_disk == 1)
1364 set $kgm_printed = 1
1366 if ($kgm_procp->p_iopol_disk == 2)
1368 set $kgm_printed = 1
1370 if ($kgm_procp->p_iopol_disk == 3)
1372 set $kgm_printed = 1
1374 if ($kgm_printed == 0)
1377 set $kgm_wqp = (struct workqueue *)$kgm_procp->p_wqptr
1379 printf " %2d %2d %2d ", $kgm_wqp->wq_nthreads, $kgm_wqp->wq_thidlecount, $kgm_wqp->wq_itemcount
1383 printf " %s\n", $kgm_procp->p_comm
1393 set $kgm_head_taskp = &tasks
1394 set $kgm_taskp = (struct task *)($kgm_head_taskp->next)
1395 while $kgm_taskp != $kgm_head_taskp
1396 set $kgm_procp = (struct proc *)$kgm_taskp->bsd_info
1397 if (($kgm_procp != 0) && ($kgm_procp->p_pid == $arg0))
1398 showtaskint $kgm_taskp
1399 set $kgm_taskp = $kgm_head_taskp
1401 set $kgm_taskp = (struct task *)($kgm_taskp->tasks.next)
1406 Syntax: (gdb) showpid <pid>
1407 | Routine to print a single process by pid
1412 set $kgm_procp = (struct proc *)$arg0
1413 showtaskint $kgm_procp->task
1418 set switch_debugger=1
1422 | kdb - Switch to the inline kernel debugger
1426 | The kdb macro allows you to invoke the inline kernel debugger.
1429 define showpsetheader
1430 printf "portset waitqueue recvname "
1431 printf "flags refs recvname process\n"
1434 define showportheader
1435 printf "port mqueue recvname "
1436 printf "flags refs recvname process\n"
1439 define showportmemberheader
1440 printf "members port recvname "
1441 printf "flags refs mqueue msgcount\n"
1444 define showkmsgheader
1445 printf "messages kmsg size "
1446 printf "disp msgid remote-port local-port\n"
1450 printf " 0x%08x ", $arg0
1451 set $kgm_kmsgh = ((ipc_kmsg_t)$arg0)->ikm_header
1452 printf "0x%08x ", $kgm_kmsgh.msgh_size
1453 if (($kgm_kmsgh.msgh_bits & 0xff) == 19)
1458 if (($kgm_kmsgh.msgh_bits & 0xff00) == (19 << 8))
1463 if ($kgm_kmsgh.msgh_bits & 0xf0000000)
1468 printf "%5d ", $kgm_kmsgh.msgh_id
1469 printf "0x%08x ", $kgm_kmsgh.msgh_remote_port
1470 printf "0x%08x\n", $kgm_kmsgh.msgh_local_port
1476 set $kgm_portp = (struct ipc_port *)$arg0
1477 showptr $kgm_portp->ip_kobject
1479 set $kgm_kotype = ($kgm_portp->ip_object.io_bits & 0x00000fff)
1480 if ($kgm_kotype == 1)
1483 if ($kgm_kotype == 2)
1486 if ($kgm_kotype == 3)
1489 if ($kgm_kotype == 4)
1492 if ($kgm_kotype == 5)
1495 if ($kgm_kotype == 6)
1498 if ($kgm_kotype == 7)
1501 if ($kgm_kotype == 8)
1504 if ($kgm_kotype == 9)
1507 if ($kgm_kotype == 10)
1510 if ($kgm_kotype == 11)
1513 if ($kgm_kotype == 12)
1516 if ($kgm_kotype == 13)
1519 if ($kgm_kotype == 14)
1522 if ($kgm_kotype == 15)
1525 if ($kgm_kotype == 16)
1528 if ($kgm_kotype == 17)
1531 if ($kgm_kotype == 18)
1534 if ($kgm_kotype == 19)
1537 if ($kgm_kotype == 20)
1540 if ($kgm_kotype == 21)
1543 if ($kgm_kotype == 22)
1544 printf "IO_DONE_QUE"
1546 if ($kgm_kotype == 23)
1549 if ($kgm_kotype == 24)
1552 if ($kgm_kotype == 25)
1555 if ($kgm_kotype == 26)
1558 if ($kgm_kotype == 27)
1559 printf "IOKIT_SPARE"
1561 if ($kgm_kotype == 28)
1564 if ($kgm_kotype == 29)
1567 if ($kgm_kotype == 30)
1570 if ($kgm_kotype == 31)
1576 define showportdestproc
1577 set $kgm_portp = (struct ipc_port *)$arg0
1578 set $kgm_spacep = $kgm_portp->data.receiver
1579 # check against the previous cached value - this is slow
1580 if ($kgm_spacep != $kgm_destspacep)
1581 set $kgm_destprocp = (struct proc *)0
1582 set $kgm_head_taskp = &tasks
1583 set $kgm_desttaskp = (struct task *)($kgm_head_taskp->next)
1584 while (($kgm_destprocp == 0) && ($kgm_desttaskp != $kgm_head_taskp))
1585 set $kgm_destspacep = $kgm_desttaskp->itk_space
1586 if ($kgm_destspacep == $kgm_spacep)
1587 set $kgm_destprocp = (struct proc *)$kgm_desttaskp->bsd_info
1589 set $kgm_desttaskp = (struct task *)($kgm_desttaskp->tasks.next)
1593 if $kgm_destprocp != 0
1594 printf "%s(%d)\n", $kgm_destprocp->p_comm, $kgm_destprocp->p_pid
1597 showptr $kgm_desttaskp
1603 set $kgm_portp = (struct ipc_port *)$arg0
1604 set $kgm_spacep = $kgm_portp->data.receiver
1605 if ($kgm_spacep == ipc_space_kernel)
1606 showkobject $kgm_portp
1608 if ($kgm_portp->ip_object.io_bits & 0x80000000)
1609 showptr $kgm_portp->ip_messages.data.port.receiver_name
1611 showportdestproc $kgm_portp
1614 printf " inactive-port\n"
1619 define showportmember
1620 printf " 0x%08x ", $arg0
1621 set $kgm_portp = (struct ipc_port *)$arg0
1622 printf "0x%08x ", $kgm_portp->ip_messages.data.port.receiver_name
1623 if ($kgm_portp->ip_object.io_bits & 0x80000000)
1629 printf "%5d ", $kgm_portp->ip_object.io_references
1630 printf "0x%08x ", &($kgm_portp->ip_messages)
1631 printf "0x%08x\n", $kgm_portp->ip_messages.data.port.msgcount
1635 printf "0x%08x ", $arg0
1636 set $kgm_portp = (struct ipc_port *)$arg0
1637 printf "0x%08x ", &($kgm_portp->ip_messages)
1638 printf "0x%08x ", $kgm_portp->ip_messages.data.port.receiver_name
1639 if ($kgm_portp->ip_object.io_bits & 0x80000000)
1645 printf "%5d ", $kgm_portp->ip_object.io_references
1646 set $kgm_destspacep = (struct ipc_space *)0
1647 showportdest $kgm_portp
1648 set $kgm_kmsgp = (ipc_kmsg_t)$kgm_portp->ip_messages.data.port.messages.ikmq_base
1649 if $arg1 && $kgm_kmsgp
1651 showkmsgint $kgm_kmsgp
1652 set $kgm_kmsgheadp = $kgm_kmsgp
1653 set $kgm_kmsgp = $kgm_kmsgp->ikm_next
1654 while $kgm_kmsgp != $kgm_kmsgheadp
1655 showkmsgint $kgm_kmsgp
1656 set $kgm_kmsgp = $kgm_kmsgp->ikm_next
1662 printf "0x%08x ", $arg0
1663 set $kgm_psetp = (struct ipc_pset *)$arg0
1664 printf "0x%08x ", &($kgm_psetp->ips_messages)
1665 printf "0x%08x ", $kgm_psetp->ips_messages.data.pset.local_name
1666 if ($kgm_psetp->ips_object.io_bits & 0x80000000)
1672 printf "%5d ", $kgm_psetp->ips_object.io_references
1673 printf "0x%08x ", $kgm_psetp->ips_messages.data.pset.local_name
1674 set $kgm_setlinksp = &($kgm_psetp->ips_messages.data.set_queue.wqs_setlinks)
1675 set $kgm_wql = (WaitQueueLink *)$kgm_setlinksp->next
1677 while ( (queue_entry_t)$kgm_wql != (queue_entry_t)$kgm_setlinksp)
1678 set $kgm_portp = (struct ipc_port *)((int)($kgm_wql->wql_element->wqe_queue) - ((int)$kgm_portoff))
1680 set $kgm_destspacep = (struct ipc_space *)0
1681 showportdestproc $kgm_portp
1682 showportmemberheader
1685 showportmember $kgm_portp 0
1686 set $kgm_wql = (WaitQueueLink *)$kgm_wql->wql_setlinks.next
1703 define showipcobject
1704 set $kgm_object = (ipc_object_t)$arg0
1705 if ($kgm_objectp->io_bits & 0x7fff0000)
1706 showpset $kgm_objectp
1708 showport $kgm_objectp
1713 set $kgm_mqueue = *(struct ipc_mqueue *)$arg0
1714 if ($kgm_mqueue.data.pset.set_queue.wqs_wait_queue.wq_type == 0xf1d1)
1715 set $kgm_psetoff = &(((struct ipc_pset *)0)->ips_messages)
1716 set $kgm_pset = (((long)$arg0) - ((long)$kgm_psetoff))
1718 showpsetint $kgm_pset 1
1720 if ($kgm_mqueue.data.pset.set_queue.wqs_wait_queue.wq_type == 0xf1d0)
1721 set $kgm_portoff = &(((struct ipc_port *)0)->ip_messages)
1722 set $kgm_port = (((long)$arg0) - ((long)$kgm_portoff))
1724 showportint $kgm_port 1
1729 set $kgm_zone = (struct zone *)$arg0
1732 printf " %6d ",$kgm_zone->count
1733 printf "%8x ",$kgm_zone->cur_size
1734 printf "%8x ",$kgm_zone->max_size
1735 printf "%6d ",$kgm_zone->elem_size
1736 printf "%8x ",$kgm_zone->alloc_size
1737 printf "%s ",$kgm_zone->zone_name
1739 if ($kgm_zone->exhaustible)
1742 if ($kgm_zone->collectable)
1745 if ($kgm_zone->expandable)
1755 printf " COUNT TOT_SZ MAX_SZ ELT_SZ ALLOC_SZ NAME\n"
1756 set $kgm_zone_ptr = (struct zone *)first_zone
1757 while ($kgm_zone_ptr != 0)
1758 zprint_one $kgm_zone_ptr
1759 set $kgm_zone_ptr = $kgm_zone_ptr->next_zone
1764 Syntax: (gdb) zprint
1765 | Routine to print a summary listing of all the kernel zones
1769 set $kgm_mtxgrp = (struct _lck_grp_ *)$arg0
1771 if ($kgm_mtxgrp->lck_grp_mtxcnt)
1773 printf " %8d ",$kgm_mtxgrp->lck_grp_mtxcnt
1774 printf "%12u ",$kgm_mtxgrp->lck_grp_stat.lck_grp_mtx_stat.lck_grp_mtx_util_cnt
1775 printf "%8u ",$kgm_mtxgrp->lck_grp_stat.lck_grp_mtx_stat.lck_grp_mtx_miss_cnt
1776 printf "%8u ",$kgm_mtxgrp->lck_grp_stat.lck_grp_mtx_stat.lck_grp_mtx_wait_cnt
1777 printf "%s ",&$kgm_mtxgrp->lck_grp_name
1786 printf " CNT UTIL MISS WAIT NAME\n"
1787 set $kgm_mtxgrp_ptr = (struct _lck_grp_ *)&lck_grp_queue
1788 set $kgm_mtxgrp_ptr = (struct _lck_grp_ *)$kgm_mtxgrp_ptr->lck_grp_link.next
1789 while ($kgm_mtxgrp_ptr != (struct _lck_grp_ *)&lck_grp_queue)
1790 showmtxgrp $kgm_mtxgrp_ptr
1791 set $kgm_mtxgrp_ptr = (struct _lck_grp_ *)$kgm_mtxgrp_ptr->lck_grp_link.next
1796 Syntax: (gdb) showallmtx
1797 | Routine to print a summary listing of all mutexes
1801 set $kgm_rwlckgrp = (struct _lck_grp_ *)$arg0
1803 if ($kgm_rwlckgrp->lck_grp_rwcnt)
1804 showptr $kgm_rwlckgrp
1805 printf " %8d ",$kgm_rwlckgrp->lck_grp_rwcnt
1806 printf "%12u ",$kgm_rwlckgrp->lck_grp_stat.lck_grp_rw_stat.lck_grp_rw_util_cnt
1807 printf "%8u ",$kgm_rwlckgrp->lck_grp_stat.lck_grp_rw_stat.lck_grp_rw_miss_cnt
1808 printf "%8u ",$kgm_rwlckgrp->lck_grp_stat.lck_grp_rw_stat.lck_grp_rw_wait_cnt
1809 printf "%s ",&$kgm_rwlckgrp->lck_grp_name
1818 printf " CNT UTIL MISS WAIT NAME\n"
1819 set $kgm_rwlckgrp_ptr = (struct _lck_grp_ *)&lck_grp_queue
1820 set $kgm_rwlckgrp_ptr = (struct _lck_grp_ *)$kgm_rwlckgrp_ptr->lck_grp_link.next
1821 while ($kgm_rwlckgrp_ptr != (struct _lck_grp_ *)&lck_grp_queue)
1822 showrwlckgrp $kgm_rwlckgrp_ptr
1823 set $kgm_rwlckgrp_ptr = (struct _lck_grp_ *)$kgm_rwlckgrp_ptr->lck_grp_link.next
1827 document showallrwlck
1828 Syntax: (gdb) showallrwlck
1829 | Routine to print a summary listing of all read/writer locks
1832 set $kdp_act_counter = 0
1851 define showcontext_int
1852 echo Context switched, current instruction pointer:
1858 set $newact = (struct thread *) $arg0
1860 if ($newact->kernel_stack == 0)
1861 echo This activation does not have a stack.\n
1863 output/a (unsigned) $newact.continuation
1866 if ($kgm_mtype == $kgm_mtype_ppc)
1867 if ($kdp_act_counter == 0)
1868 set $kdpstate = (struct savearea *) kdp.saved_state
1870 set $kdp_act_counter = $kdp_act_counter + 1
1871 set (struct savearea *) kdp.saved_state=$newact->machine->pcb
1874 set $pc=$newact->machine->pcb.save_srr0
1877 if ($kgm_mtype == $kgm_mtype_i386)
1878 set $kdpstatep = (struct x86_saved_state32 *) kdp.saved_state
1879 if ($kdp_act_counter == 0)
1880 set $kdpstate = *($kdpstatep)
1882 set $kdp_act_counter = $kdp_act_counter + 1
1884 set $kgm_statep = (struct x86_kernel_state *) \
1885 ($newact->kernel_stack + kernel_stack_size \
1886 - sizeof(struct x86_kernel_state))
1887 set $kdpstatep->ebx = $kgm_statep->k_ebx
1888 set $kdpstatep->ebp = $kgm_statep->k_ebp
1889 set $kdpstatep->edi = $kgm_statep->k_edi
1890 set $kdpstatep->esi = $kgm_statep->k_esi
1891 set $kdpstatep->eip = $kgm_statep->k_eip
1894 set $pc = $kgm_statep->k_eip
1897 if ($kgm_mtype == $kgm_mtype_x86_64)
1898 set $kdpstatep = (struct x86_saved_state64 *) kdp.saved_state
1899 if ($kdp_act_counter == 0)
1900 set $kdpstate = *($kdpstatep)
1902 set $kdp_act_counter = $kdp_act_counter + 1
1904 set $kgm_statep = (struct x86_kernel_state *) \
1905 ($newact->kernel_stack + kernel_stack_size \
1906 - sizeof(struct x86_kernel_state))
1907 set $kdpstatep->rbx = $kgm_statep->k_rbx
1908 set $kdpstatep->rbp = $kgm_statep->k_rbp
1909 set $kdpstatep->r12 = $kgm_statep->k_r12
1910 set $kdpstatep->r13 = $kgm_statep->k_r13
1911 set $kdpstatep->r14 = $kgm_statep->k_r14
1912 set $kdpstatep->r15 = $kgm_statep->k_r15
1913 set $kdpstatep->isf.rsp = $kgm_statep->k_rsp
1916 set $pc = $kgm_statep->k_rip
1919 if ($kgm_mtype == $kgm_mtype_arm)
1930 set $r10_save = $r10
1931 set $r11_save = $r11
1932 set $r12_save = $r12
1936 set $pc_ctx = load_reg+8
1937 set $kgm_statep = (struct arm_saved_state *)((struct thread*)$arg0)->machine.kstackptr
1938 set $r0 = $kgm_statep->r[0]
1939 set $r1 = $kgm_statep->r[1]
1940 set $r2 = $kgm_statep->r[2]
1941 set $r3 = $kgm_statep->r[3]
1942 set $r4 = $kgm_statep->r[4]
1943 set $r5 = $kgm_statep->r[5]
1944 set $r6 = $kgm_statep->r[6]
1945 set $r8 = $kgm_statep->r[8]
1946 set $r9 = $kgm_statep->r[9]
1947 set $r10 = $kgm_statep->r[10]
1948 set $r11 = $kgm_statep->r[11]
1949 set $r12 = $kgm_statep->r[12]
1950 set $sp = $kgm_statep->sp
1951 set $lr = $kgm_statep->lr
1953 set $r7 = $kgm_statep->r[7]
1961 document switchtoact
1962 Syntax: switchtoact <address of activation>
1963 | This command allows gdb to examine the execution context and call
1964 | stack for the specified activation. For example, to view the backtrace
1965 | for an activation issue "switchtoact <address>", followed by "bt".
1966 | Before resuming execution, issue a "resetctx" command, to
1967 | return to the original execution context.
1972 if ($kgm_mtype == $kgm_mtype_ppc)
1973 if ($kdp_act_counter == 0)
1974 set $kdpstate = (struct savearea *) kdp.saved_state
1976 set $kdp_act_counter = $kdp_act_counter + 1
1977 set (struct savearea *) kdp.saved_state=(struct savearea *) $arg0
1980 set $pc=((struct savearea *) $arg0)->save_srr0
1983 if ($kgm_mtype == $kgm_mtype_arm)
1984 set arm disassembler std
1996 set $r10_save = $r10
1997 set $r11_save = $r11
1998 set $r12_save = $r12
2002 set $kgm_statep = (struct arm_saved_state *)$arg0
2003 set $r0 = $kgm_statep->r[0]
2004 set $r1 = $kgm_statep->r[1]
2005 set $r2 = $kgm_statep->r[2]
2006 set $r3 = $kgm_statep->r[3]
2007 set $r4 = $kgm_statep->r[4]
2008 set $r5 = $kgm_statep->r[5]
2009 set $r6 = $kgm_statep->r[6]
2010 set $r8 = $kgm_statep->r[8]
2011 set $r9 = $kgm_statep->r[9]
2012 set $r10 = $kgm_statep->r[10]
2013 set $r11 = $kgm_statep->r[11]
2014 set $r12 = $kgm_statep->r[12]
2015 set $sp = $kgm_statep->sp
2016 set $lr = $kgm_statep->lr
2017 set $r7 = $kgm_statep->r[7]
2018 set $pc = $kgm_statep->pc
2023 echo switchtoctx not implemented for this architecture.\n
2027 document switchtoctx
2028 Syntax: switchtoctx <address of pcb>
2029 | This command allows gdb to examine an execution context and dump the
2030 | backtrace for this execution context.
2031 | Before resuming execution, issue a "resetctx" command, to
2032 | return to the original execution context.
2037 if ($kdp_act_counter != 0)
2038 if ($kgm_mtype == $kgm_mtype_ppc)
2039 set (struct savearea *)kdp.saved_state=$kdpstate
2042 set $pc=((struct savearea *) kdp.saved_state)->save_srr0
2044 set $kdp_act_counter = 0
2046 if ($kgm_mtype == $kgm_mtype_i386)
2047 set $kdpstatep = (struct x86_saved_state32 *) kdp.saved_state
2048 set *($kdpstatep)=$kdpstate
2051 set $pc=$kdpstatep->eip
2053 set $kdp_act_counter = 0
2055 if ($kgm_mtype == $kgm_mtype_x86_64)
2056 set $kdpstatep = (struct x86_saved_state64 *) kdp.saved_state
2057 set *($kdpstatep)=$kdpstate
2060 set $pc=$kdpstatep->isf.rip
2062 set $kdp_act_counter = 0
2064 if ($kgm_mtype == $kgm_mtype_arm)
2083 set $r10 = $r10_save
2085 set $r11 = $r11_save
2087 set $r12 = $r12_save
2104 | Returns to the original execution context. This command should be
2105 | issued if you wish to resume execution after using the "switchtoact"
2106 | or "switchtoctx" commands.
2109 # This is a pre-hook for the continue command, to prevent inadvertent attempts
2110 # to resume from the context switched to for examination.
2111 define hook-continue
2115 # This is a pre-hook for the detach command, to prevent inadvertent attempts
2116 # to resume from the context switched to for examination.
2122 set $resume = KDP_DUMPINFO_SETINFO | KDP_DUMPINFO_RESUME
2128 | The target system will resume when detaching or exiting from gdb.
2129 | This is the default behavior.
2133 set $noresume = KDP_DUMPINFO_SETINFO | KDP_DUMPINFO_NORESUME
2134 dumpinfoint $noresume
2138 | Syntax: resume_off
2139 | The target system won't resume after detaching from gdb and
2140 | can be attached with a new gdb session
2144 set $kgm_panic_bufptr = debug_buf
2145 set $kgm_panic_bufptr_max = debug_buf_ptr
2146 while $kgm_panic_bufptr < $kgm_panic_bufptr_max
2147 if *(char *)$kgm_panic_bufptr == 10
2150 printf "%c", *(char *)$kgm_panic_bufptr
2152 set $kgm_panic_bufptr= (char *)$kgm_panic_bufptr + 1
2158 | Display the panic log information
2162 define dumpcallqueue
2163 set $kgm_callhead = $arg0
2164 set $kgm_callentry = $kgm_callhead->next
2166 while $kgm_callentry != $kgm_callhead
2167 set $kgm_call = (struct call_entry *)$kgm_callentry
2168 printf "0x%08x ", $kgm_call
2169 printf "0x%08x 0x%08x ", $kgm_call->param0, $kgm_call->param1
2170 output $kgm_call->deadline
2172 output $kgm_call->func
2174 set $kgm_i = $kgm_i + 1
2175 set $kgm_callentry = $kgm_callentry->next
2177 printf "%d entries\n", $kgm_i
2180 document dumpcallqueue
2181 | Syntax: dumpcallqueue <queue head>
2182 | Displays the contents of the specified call_entry queue.
2186 showtaskthreads $arg0
2188 document showtaskacts
2189 | See help showtaskthreads.
2195 document showallacts
2196 | See help showallthreads.
2211 document resetstacks
2212 | Syntax: resetstacks
2213 | Internal kgmacro routine used by the "showuserstack" macro
2214 | to reset the target pmap to the kernel pmap.
2217 #Barely effective hacks to work around bugs in the "flush" and "update"
2218 #gdb commands in Tiger (up to 219); these aren't necessary with Panther
2219 #gdb, but do no harm.
2220 define _kgm_flush_loop
2221 set $kgm_flush_loop_ctr = 0
2222 while ($kgm_flush_loop_ctr < 30)
2225 set $kgm_flush_loop_ctr = $kgm_flush_loop_ctr + 1
2229 define _kgm_update_loop
2230 set $kgm_update_loop_ctr = 0
2231 while ($kgm_update_loop_ctr < 30)
2233 set $kgm_update_loop_ctr = $kgm_update_loop_ctr + 1
2236 # Internal routine used by "_loadfrom" to read from 64-bit addresses
2239 # set up the manual KDP packet
2240 set manual_pkt.input = 0
2241 set manual_pkt.len = sizeof(kdp_readmem64_req_t)
2242 set $kgm_pkt = (kdp_readmem64_req_t *)&manual_pkt.data
2243 set $kgm_pkt->hdr.request = KDP_READMEM64
2244 set $kgm_pkt->hdr.len = sizeof(kdp_readmem64_req_t)
2245 set $kgm_pkt->hdr.is_reply = 0
2246 set $kgm_pkt->hdr.seq = 0
2247 set $kgm_pkt->hdr.key = 0
2248 set $kgm_pkt->address = (uint64_t)$arg0
2249 set $kgm_pkt->nbytes = sizeof(uint64_t)
2250 set manual_pkt.input = 1
2251 # dummy to make sure manual packet is executed
2252 set $kgm_dummy = &_mh_execute_header
2253 set $kgm_pkt = (kdp_readmem64_reply_t *)&manual_pkt.data
2254 if ($kgm_pkt->error == 0)
2255 set $kgm_k32read64 = *(uint64_t *)$kgm_pkt->data
2257 set $kgm_k32read64 = 0
2261 # Internal routine used by "showx86backtrace" to abstract possible loads from
2265 set $kgm_loadval = *(uintptr_t *)$arg0
2267 if ($kgm_x86_abi == 0xe)
2268 set $kgm_loadval = *(uint32_t *)$arg0
2270 if ($kgm_x86_abi == 0xf)
2271 if ($kgm_mtype == $kgm_mtype_i386)
2273 set $kgm_loadval = $kgm_k32read64
2275 set $kgm_loadval = *(uint64_t *)$arg0
2283 #This is necessary since gdb often doesn't do backtraces on x86 correctly
2284 #in the absence of symbols.The code below in showuserstack and
2285 #showx86backtrace also contains several workarouds for the gdb bug where
2286 #gdb stops macro evaluation because of spurious "Cannot read memory"
2287 #errors on x86. These errors appear on ppc as well, but they don't
2288 #always stop macro evaluation.
2290 set $kgm_cur_frame = 0
2292 set $kgm_x86_abi = 0
2293 define showx86backtrace
2294 if ($kgm_mtype == $kgm_mtype_i386)
2295 set $kgm_frame_reg = $ebp
2297 set $kgm_ret_off = 4
2299 if ($kgm_mtype == $kgm_mtype_x86_64)
2300 set $kgm_frame_reg = $rbp
2302 set $kgm_ret_off = 8
2305 if ($kgm_x86_abi == 0xe)
2306 set $kgm_ret_off = 4
2308 if ($kgm_x86_abi == 0xf)
2309 set $kgm_ret_off = 8
2312 if ($kgm_cur_frame == 0)
2313 set $kgm_cur_frame = $kgm_frame_reg
2315 if ($kgm_cur_pc == 0)
2316 set $kgm_cur_pc = $kgm_pc
2318 printf "0: Frame: 0x%016llx PC: 0x%016llx\n", $kgm_cur_frame, $kgm_cur_pc
2319 if (!(($kgm_x86_abi == 0xf) && ($kgm_mtype == $kgm_mtype_i386)))
2322 set $kgm_tmp_frame = $kgm_cur_frame
2323 set $kgm_cur_frame = 0
2325 _loadfrom ($kgm_tmp_frame)
2326 set $kgm_prev_frame = $kgm_loadval
2327 _loadfrom ($kgm_tmp_frame+$kgm_ret_off)
2328 set $kgm_prev_pc = $kgm_loadval
2329 set $kgm_frameno = 1
2330 while $kgm_prev_frame != 0
2331 printf "%d: Saved frame: 0x%016llx Saved PC: 0x%016llx\n", $kgm_frameno, $kgm_prev_frame, $kgm_prev_pc
2332 if (!(($kgm_x86_abi == 0xf) && ($kgm_mtype == $kgm_mtype_i386)))
2335 _loadfrom ($kgm_prev_frame+$kgm_ret_off)
2336 set $kgm_prev_pc = $kgm_loadval
2337 _loadfrom ($kgm_prev_frame)
2338 set $kgm_prev_frame = $kgm_loadval
2339 set $kgm_frameno = $kgm_frameno + 1
2342 set $kgm_x86_abi = 0
2345 define showx86backtrace2
2346 set $kgm_cur_frame = $arg0
2347 set $kgm_cur_pc = $arg1
2351 define showuserstack
2353 if ($kgm_mtype == $kgm_mtype_ppc)
2354 if ($kdp_act_counter == 0)
2355 set $kdpstate = (struct savearea *) kdp.saved_state
2357 set $kdp_act_counter = $kdp_act_counter + 1
2358 set $newact = (struct thread *) $arg0
2360 set $checkpc = $newact->machine->upcb.save_srr0
2362 echo This activation does not appear to have
2363 echo \20 a valid user context.\n
2365 set (struct savearea *) kdp.saved_state=$newact->machine->upcb
2367 #flush and update seem to be executed lazily by gdb on Tiger, hence the
2368 #repeated invocations - see 3743135
2370 # This works because the new pmap is used only for reads
2371 set kdp_pmap = $newact->task->map->pmap
2383 if (($kgm_mtype & $kgm_mtype_x86_mask) == $kgm_mtype_x86_any)
2384 set $newact = (struct thread *) $arg0
2385 set $newiss = (x86_saved_state_t *) ($newact->machine.pcb->iss)
2386 set $kgm_x86_abi = $newiss.flavor
2387 if ($newiss.flavor == 0xf)
2388 set $checkpc = $newiss.uss.ss_64.isf.rip
2389 set $checkframe = $newiss.uss.ss_64.rbp
2392 set $checkpc = $newiss.uss.ss_32.eip
2393 set $checkframe = $newiss.uss.ss_32.ebp
2397 echo This activation does not appear to have
2398 echo \20 a valid user context.\n
2400 set $kgm_cur_frame = $checkframe
2401 set $kgm_cur_pc = $checkpc
2402 printf "You may now issue the showx86backtrace command to see the user space backtrace for this thread ("
2404 printf "); you can also examine memory locations in this address space (pmap "
2405 showptr $newact->task->map->pmap
2406 printf ") 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"
2407 set kdp_pmap = $newact->task->map->pmap
2412 echo showuserstack not supported on this architecture\n
2416 document showuserstack
2417 Syntax: showuserstack <address of thread activation>
2418 |This command displays a numeric backtrace for the user space stack of
2419 |the given thread activation. It may, of course, fail to display a
2420 |complete backtrace if portions of the user stack are not mapped in.
2421 |Symbolic backtraces can be obtained either by running gdb on the
2422 |user space binary, or a tool such as "symbolicate".
2423 |Note that while this command works on Panther's gdb, an issue
2424 |with Tiger gdb (3743135) appears to hamper the evaluation of this
2425 |macro in some cases.
2429 # Alternatively, set *(*(unsigned **) 0x2498) = 1
2430 # (or 0x5498 on PPC, 0xffffff8000002928 on x86_64, 0xffff049c on arm)
2431 manualhdrint $kgm_kdp_pkt_hostreboot
2437 |Reboot the remote target machine; not guaranteed to succeed.
2440 define kdpversionint
2441 # set up the manual KDP packet
2442 set manual_pkt.input = 0
2443 set manual_pkt.len = sizeof(kdp_version_req_t)
2444 set $kgm_pkt = (kdp_version_req_t *)&manual_pkt.data
2445 set $kgm_pkt->hdr.request = KDP_VERSION
2446 set $kgm_pkt->hdr.len = sizeof(kdp_version_req_t)
2447 set $kgm_pkt->hdr.is_reply = 0
2448 set $kgm_pkt->hdr.seq = 0
2449 set $kgm_pkt->hdr.key = 0
2450 set manual_pkt.input = 1
2451 # dummy to make sure manual packet is executed
2452 set $kgm_dummy = &_mh_execute_header
2453 set $kgm_pkt = (kdp_version_reply_t *)&manual_pkt.data
2454 set $kgm_kdp_version = $kgm_pkt->version
2455 set $kgm_kdp_feature = $kgm_pkt->feature
2460 printf "KDP VERSION = %d, FEATURE = 0x%x\n", $kgm_kdp_version, $kgm_kdp_feature
2463 document kdp-version
2465 |Get the KDP protocol version being used by the kernel.
2469 # set up the manual KDP packet
2470 set manual_pkt.input = 0
2472 set manual_pkt.len = sizeof(kdp_dumpinfo_req_t)
2473 set $kgm_pkt = (kdp_dumpinfo_req_t *)manual_pkt.data
2474 set $kgm_pkt->hdr.request = KDP_DUMPINFO
2475 set $kgm_pkt->hdr.len = sizeof(kdp_dumpinfo_req_t)
2476 set $kgm_pkt->hdr.is_reply = 0
2477 set $kgm_pkt->hdr.seq = 0
2478 set $kgm_pkt->hdr.key = 0
2479 set $kgm_pkt->type = $arg0
2480 set $kgm_pkt->name = ""
2481 set $kgm_pkt->destip = ""
2482 set $kgm_pkt->routerip = ""
2483 set $kgm_pkt->port = 0
2486 set $kgm_pkt->name = "$arg1"
2489 set $kgm_pkt->destip = "$arg2"
2492 set $kgm_pkt->routerip = "$arg3"
2495 set $kgm_pkt->port = $arg4
2498 set manual_pkt.input = 1
2499 # dummy to make sure manual packet is executed
2500 set $kgm_dummy = &_mh_execute_header
2505 dumpinfoint KDP_DUMPINFO_CORE $arg1 $arg0
2507 dumpinfoint KDP_DUMPINFO_CORE \0 $arg0
2512 Syntax: sendcore <IP address> [filename]
2513 |Configure the kernel to transmit a kernel coredump to a server (kdumpd)
2514 |at the specified IP address. This is useful when the remote target has
2515 |not been previously configured to transmit coredumps, and you wish to
2516 |preserve kernel state for later examination. NOTE: You must issue a "continue"
2517 |command after using this macro to trigger the kernel coredump. The kernel
2518 |will resume waiting in the debugger after completion of the coredump. You
2519 |may disable coredumps by executing the "disablecore" macro. You can
2520 |optionally specify the filename to be used for the generated core file.
2525 dumpinfoint KDP_DUMPINFO_SYSTEMLOG $arg1 $arg0
2527 dumpinfoint KDP_DUMPINFO_SYSTEMLOG \0 $arg0
2532 Syntax: sendsyslog <IP address> [filename]
2533 |Configure the kernel to transmit a kernel system log to a server (kdumpd)
2534 |at the specified IP address. NOTE: You must issue a "continue"
2535 |command after using this macro to trigger the kernel system log. The kernel
2536 |will resume waiting in the debugger after completion. You can optionally
2537 |specify the name to be used for the generated system log.
2543 dumpinfoint KDP_DUMPINFO_PANICLOG $arg1 $arg0
2545 dumpinfoint KDP_DUMPINFO_PANICLOG \0 $arg0
2548 printf "No panic log available.\n"
2552 document sendpaniclog
2553 Syntax: sendpaniclog <IP address> [filename]
2554 |Configure the kernel to transmit a kernel paniclog to a server (kdumpd)
2555 |at the specified IP address. NOTE: You must issue a "continue"
2556 |command after using this macro to trigger the kernel panic log. The kernel
2557 |will resume waiting in the debugger after completion. You can optionally
2558 |specify the name to be used for the generated panic log.
2562 dumpinfoint KDP_DUMPINFO_GETINFO
2563 set $kgm_dumpinfo = (kdp_dumpinfo_reply_t *) manual_pkt.data
2564 if $kgm_dumpinfo->type & KDP_DUMPINFO_REBOOT
2565 printf "Sysem will reboot after kernel info gets dumped.\n"
2567 printf "Sysem will not reboot after kernel info gets dumped.\n"
2569 if $kgm_dumpinfo->type & KDP_DUMPINFO_NORESUME
2570 printf "System will allow a re-attach after a KDP disconnect.\n"
2572 printf "System will resume after a KDP disconnect.\n"
2574 set $kgm_dumpinfo_type = $kgm_dumpinfo->type & KDP_DUMPINFO_MASK
2575 if $kgm_dumpinfo_type == KDP_DUMPINFO_DISABLE
2576 printf "Kernel not setup for remote dumps.\n"
2578 printf "Remote dump type: "
2579 if $kgm_dumpinfo_type == KDP_DUMPINFO_CORE
2580 printf "Core file\n"
2582 if $kgm_dumpinfo_type == KDP_DUMPINFO_PANICLOG
2583 printf "Panic log\n"
2585 if $kgm_dumpinfo_type == KDP_DUMPINFO_SYSTEMLOG
2586 printf "System log\n"
2590 if $kgm_dumpinfo->name[0] == '\0'
2591 printf "(autogenerated)\n"
2593 printf "%s\n", $kgm_dumpinfo->name
2596 printf "Network Info: %s[%d] ", $kgm_dumpinfo->destip, $kgm_dumpinfo->port
2597 if $kgm_dumpinfo->routerip[0] == '\0'
2600 printf "Router: %s\n", $kgm_dumpinfo->routerip
2605 document getdumpinfo
2607 |Retrieve the current remote dump settings.
2611 dumpinfoint KDP_DUMPINFO_SETINFO $arg0 $arg1 $arg2 $arg3
2614 document setdumpinfo
2615 Syntax: setdumpinfo <filename> <ip> <router> <port>
2616 |Configure the current remote dump settings. Specify \0 if you
2617 |want to use the defaults (filename) or previously configured
2618 |settings (ip/router). Specify 0 for the port if you wish to
2619 |use the previously configured/default setting for that.
2623 dumpinfoint KDP_DUMPINFO_DISABLE
2626 document disablecore
2628 |Reconfigures the kernel so that it no longer transmits kernel coredumps. This
2629 |complements the "sendcore" macro, but it may be used if the kernel has been
2630 |configured to transmit coredumps through boot-args as well.
2633 define switchtocorethread
2634 set $newact = (struct thread *) $arg0
2636 if ($newact->kernel_stack == 0)
2637 echo This thread does not have a stack.\n
2639 output/a (unsigned) $newact.continuation
2642 if ($kgm_mtype == $kgm_mtype_ppc)
2643 loadcontext $newact->machine->pcb
2645 set $pc = $newact->machine->pcb.save_srr0
2647 if (($kgm_mtype & $kgm_mtype_x86_mask) == $kgm_mtype_x86_any)
2648 set $kgm_cstatep = (struct x86_kernel_state *) \
2649 ($newact->kernel_stack + kernel_stack_size \
2650 - sizeof(struct x86_kernel_state))
2651 loadcontext $kgm_cstatep
2654 echo switchtocorethread not supported on this architecture\n
2661 document switchtocorethread
2662 Syntax: switchtocorethread <address of activation>
2663 | The corefile equivalent of "switchtoact". When debugging a kernel coredump
2664 | file, this command can be used to examine the execution context and stack
2665 | trace for a given thread activation. For example, to view the backtrace
2666 | for a thread issue "switchtocorethread <address>", followed by "bt".
2667 | Before resuming execution, issue a "resetcorectx" command, to
2668 | return to the original execution context. Note that this command
2669 | requires gdb support, as documented in Radar 3401283.
2674 if ($kgm_mtype == $kgm_mtype_ppc)
2675 set $kgm_contextp = (struct savearea *) $arg0
2676 set $pc = $kgm_contextp.save_srr0
2677 set $r1 = $kgm_contextp.save_r1
2678 set $lr = $kgm_contextp.save_lr
2680 set $r2 = $kgm_contextp.save_r2
2681 set $r3 = $kgm_contextp.save_r3
2682 set $r4 = $kgm_contextp.save_r4
2683 set $r5 = $kgm_contextp.save_r5
2684 set $r6 = $kgm_contextp.save_r6
2685 set $r7 = $kgm_contextp.save_r7
2686 set $r8 = $kgm_contextp.save_r8
2687 set $r9 = $kgm_contextp.save_r9
2688 set $r10 = $kgm_contextp.save_r10
2689 set $r11 = $kgm_contextp.save_r11
2690 set $r12 = $kgm_contextp.save_r12
2691 set $r13 = $kgm_contextp.save_r13
2692 set $r14 = $kgm_contextp.save_r14
2693 set $r15 = $kgm_contextp.save_r15
2694 set $r16 = $kgm_contextp.save_r16
2695 set $r17 = $kgm_contextp.save_r17
2696 set $r18 = $kgm_contextp.save_r18
2697 set $r19 = $kgm_contextp.save_r19
2698 set $r20 = $kgm_contextp.save_r20
2699 set $r21 = $kgm_contextp.save_r21
2700 set $r22 = $kgm_contextp.save_r22
2701 set $r23 = $kgm_contextp.save_r23
2702 set $r24 = $kgm_contextp.save_r24
2703 set $r25 = $kgm_contextp.save_r25
2704 set $r26 = $kgm_contextp.save_r26
2705 set $r27 = $kgm_contextp.save_r27
2706 set $r28 = $kgm_contextp.save_r28
2707 set $r29 = $kgm_contextp.save_r29
2708 set $r30 = $kgm_contextp.save_r30
2709 set $r31 = $kgm_contextp.save_r31
2711 set $cr = $kgm_contextp.save_cr
2712 set $ctr = $kgm_contextp.save_ctr
2714 if ($kgm_mtype == $kgm_mtype_i386)
2715 set $kgm_contextp = (struct x86_kernel_state *) $arg0
2716 set $ebx = $kgm_contextp->k_ebx
2717 set $ebp = $kgm_contextp->k_ebp
2718 set $edi = $kgm_contextp->k_edi
2719 set $esi = $kgm_contextp->k_esi
2720 set $eip = $kgm_contextp->k_eip
2721 set $pc = $kgm_contextp->k_eip
2723 if ($kgm_mtype == $kgm_mtype_x86_64)
2724 set $kgm_contextp = (struct x86_kernel_state *) $arg0
2725 set $rbx = $kgm_contextp->k_rbx
2726 set $rbp = $kgm_contextp->k_rbp
2727 set $r12 = $kgm_contextp->k_r12
2728 set $r13 = $kgm_contextp->k_r13
2729 set $r14 = $kgm_contextp->k_r14
2730 set $r15 = $kgm_contextp->k_r15
2731 set $rip = $kgm_contextp->k_rip
2732 set $pc = $kgm_contextp->k_rip
2734 echo loadcontext not supported on this architecture\n
2742 if ($kgm_mtype == $kgm_mtype_ppc)
2743 set $kgm_corecontext = (struct savearea *) kdp.saved_state
2744 loadcontext $kgm_corecontext
2746 if ($kgm_mtype == $kgm_mtype_i386)
2747 set $kdpstatep = (struct x86_saved_state32 *) kdp.saved_state
2748 set $ebx = $kdpstatep->ebx
2749 set $ebp = $kdpstatep->ebp
2750 set $edi = $kdpstatep->edi
2751 set $esi = $kdpstatep->esi
2752 set $eip = $kdpstatep->eip
2753 set $eax = $kdpstatep->eax
2754 set $ecx = $kdpstatep->ecx
2755 set $edx = $kdpstatep->edx
2758 set $pc = $kdpstatep->eip
2761 echo resetcorectx not supported on this architecture\n
2767 document resetcorectx
2768 Syntax: resetcorectx
2769 | The corefile equivalent of "resetctx". Returns to the original
2770 | execution context (that of the active thread at the time of the NMI or
2771 | panic). This command should be issued if you wish to resume
2772 | execution after using the "switchtocorethread" command.
2775 #Helper function for "showallgdbstacks"
2777 define showgdbthread
2778 printf " 0x%08x ", $arg0
2779 set $kgm_thread = *(struct thread *)$arg0
2780 printf "0x%08x ", $arg0
2781 printf "%3d ", $kgm_thread.sched_pri
2782 set $kgm_state = $kgm_thread.state
2783 if $kgm_state & 0x80
2786 if $kgm_state & 0x40
2789 if $kgm_state & 0x20
2792 if $kgm_state & 0x10
2795 if $kgm_state & 0x08
2798 if $kgm_state & 0x04
2801 if $kgm_state & 0x02
2804 if $kgm_state & 0x01
2806 printf "0x%08x ", $kgm_thread.wait_queue
2807 output /a (unsigned) $kgm_thread.wait_event
2808 if ($kgm_thread.uthread != 0)
2809 set $kgm_uthread = (struct uthread *)$kgm_thread.uthread
2810 if ($kgm_uthread->uu_wmesg != 0)
2811 printf " \"%s\"", $kgm_uthread->uu_wmesg
2816 if ($kgm_thread.kernel_stack != 0)
2817 if ($kgm_thread.reserved_stack != 0)
2818 printf "\n\t\treserved_stack=0x%08x", $kgm_thread.reserved_stack
2820 printf "\n\t\tkernel_stack=0x%08x", $kgm_thread.kernel_stack
2821 if ($kgm_mtype == $kgm_mtype_ppc)
2822 set $mysp = $kgm_thread.machine.pcb->save_r1
2824 if ($kgm_mtype == $kgm_mtype_i386)
2825 set $kgm_statep = (struct x86_kernel_state *) \
2826 ($kgm_thread->kernel_stack + kernel_stack_size \
2827 - sizeof(struct x86_kernel_state))
2828 set $mysp = $kgm_statep->k_ebp
2830 if ($kgm_mtype == $kgm_mtype_arm)
2831 if (((unsigned long)$r7 < ((unsigned long) ($kgm_thread->kernel_stack+kernel_stack_size))) \
2832 && ((unsigned long)$r7 > (unsigned long) ($kgm_thread->kernel_stack)))
2835 set $kgm_statep = (struct arm_saved_state *)$kgm_thread.machine.kstackptr
2836 set $mysp = $kgm_statep->r[7]
2840 printf "\n\t\tstacktop=0x%08x", $mysp
2844 switchtocorethread $arg0
2848 printf "\n\t\t\tcontinuation="
2849 output /a (unsigned) $kgm_thread.continuation
2857 #Use of this macro is currently (8/04) blocked by the fact that gdb
2858 #stops evaluating macros when encountering an error, such as a failure
2859 #to read memory from a certain location. Until this issue (described in
2860 #3758949) is addressed, evaluation of this macro may stop upon
2861 #encountering such an error.
2863 define showallgdbstacks
2864 set $kgm_head_taskp = &tasks
2865 set $kgm_taskp = (struct task *)($kgm_head_taskp->next)
2866 while $kgm_taskp != $kgm_head_taskp
2868 showtaskint $kgm_taskp
2869 set $kgm_head_actp = &($kgm_taskp->threads)
2870 set $kgm_actp = (struct thread *)($kgm_taskp->threads.next)
2871 while $kgm_actp != $kgm_head_actp
2873 showgdbthread $kgm_actp 1 0
2874 set $kgm_actp = (struct thread *)($kgm_actp->task_threads.next)
2877 set $kgm_taskp = (struct task *)($kgm_taskp->tasks.next)
2882 document showallgdbstacks
2883 Syntax: showallgdbstacks
2884 | An alternative to "showallstacks". Iterates through the task list and
2885 | displays a gdb generated backtrace for each kernel thread. It is
2886 | advantageous in that it is much faster than "showallstacks", and
2887 | decodes function call arguments and displays source level traces, but
2888 | it has the drawback that it doesn't determine if frames belong to
2889 | functions from kernel extensions, as with "showallstacks".
2890 | This command may terminate prematurely because of a gdb bug
2891 | (Radar 3758949), which stops macro evaluation on memory read
2895 define showallgdbcorestacks
2897 set $kgm_head_taskp = &tasks
2898 set $kgm_taskp = (struct task *)($kgm_head_taskp->next)
2899 while $kgm_taskp != $kgm_head_taskp
2901 showtaskint $kgm_taskp
2902 set $kgm_head_actp = &($kgm_taskp->threads)
2903 set $kgm_actp = (struct thread *)($kgm_taskp->threads.next)
2904 while $kgm_actp != $kgm_head_actp
2906 showgdbthread $kgm_actp 1 1
2907 set $kgm_actp = (struct thread *)($kgm_actp->task_threads.next)
2910 set $kgm_taskp = (struct task *)($kgm_taskp->tasks.next)
2916 document showallgdbcorestacks
2917 Syntax: showallgdbcorestacks
2918 |Corefile version of "showallgdbstacks"
2922 define switchtouserthread
2924 if ($kgm_mtype == $kgm_mtype_ppc)
2925 if ($kdp_act_counter == 0)
2926 set $kdpstate = (struct savearea *) kdp.saved_state
2928 set $kdp_act_counter = $kdp_act_counter + 1
2929 set $newact = (struct thread *) $arg0
2931 set $checkpc = $newact->machine->upcb.save_srr0
2933 echo This activation does not appear to have
2934 echo \20 a valid user context.\n
2936 set (struct savearea *) kdp.saved_state=$newact->machine->upcb
2938 #flush and update seem to be executed lazily by gdb on Tiger, hence the
2939 #repeated invocations - see 3743135
2941 # This works because the new pmap is used only for reads
2942 set kdp_pmap = $newact->task->map->pmap
2947 echo switchtouserthread not implemented for this architecture.\n
2951 document switchtouserthread
2952 Syntax: switchtouserthread <address of thread>
2953 | Analogous to switchtoact, but switches to the user context of a
2954 | specified thread address. Similar to the "showuserstack"
2955 | command, but this command does not return gdb to the kernel context
2956 | immediately. This is to assist with the following (rather risky)
2957 | manoeuvre - upon switching to the user context and virtual address
2958 | space, the user may choose to call remove-symbol-file on the
2959 | mach_kernel symbol file, and then add-symbol-file on the user space
2960 | binary's symfile. gdb can then generate symbolic backtraces
2961 | for the user space thread. To return to the
2962 | kernel context and virtual address space, the process must be
2963 | reversed, i.e. call remove-symbol-file on the user space symbols, and
2964 | then add-symbol-file on the appropriate mach_kernel, and issue the
2965 | "resetstacks" command. Note that gdb may not react kindly to all these
2966 | symbol file switches. The same restrictions that apply to "showuserstack"
2967 | apply here - pages that have been paged out cannot be read while in the
2968 | debugger context, so backtraces may terminate early.
2969 | If the virtual addresses in the stack trace do not conflict with those
2970 | of symbols in the kernel's address space, it may be sufficient to
2971 | just do an add-symbol-file on the user space binary's symbol file.
2972 | Note that while this command works on Panther's gdb, an issue
2973 | with Tiger gdb (3743135) appears to hamper the evaluation of this
2974 | macro in some cases.
2977 define showmetaclass
2978 set $kgm_metaclassp = (OSMetaClass *)$arg0
2979 printf "%-5d", $kgm_metaclassp->instanceCount
2980 printf "x %5d bytes", $kgm_metaclassp->classSize
2981 printf " %s\n", $kgm_metaclassp->className->string
2985 printf "\"%s\"", ((OSString *)$arg0)->string
2989 printf "%lld", ((OSNumber *)$arg0)->value
2993 if ($arg0 == gOSBooleanFalse)
3000 define showdatabytes
3001 set $kgm_data = (OSData *)$arg0
3004 set $kgm_datap = (const unsigned char *) $kgm_data->data
3006 while ( $kgm_idx < $kgm_data->length )
3007 printf "%02X", *$kgm_datap
3008 set $kgm_datap = $kgm_datap + 1
3009 set $kgm_idx = $kgm_idx + 1
3015 set $kgm_data = (OSData *)$arg0
3018 set $kgm_datap = (const unsigned char *) $kgm_data->data
3020 set $kgm_printstr = 0
3021 if (0 == (3 & (unsigned int)$kgm_datap) && ($kgm_data->length >= 3))
3022 set $kgm_bytes = *(unsigned int *) $kgm_datap
3023 if (0xffff0000 & $kgm_bytes)
3025 set $kgm_printstr = 1
3026 while ($kgm_idx++ < 4)
3027 set $kgm_bytes = $kgm_bytes >> 8
3028 set $kgm_char = 0xff & $kgm_bytes
3029 if ($kgm_char && (($kgm_char < 0x20) || ($kgm_char > 0x7e)))
3030 set $kgm_printstr = 0
3039 while ($kgm_idx < $kgm_data->length)
3040 set $kgm_char = $kgm_datap[$kgm_idx++]
3042 if (0 == $kgm_quoted)
3050 printf "%c", $kgm_char
3062 if (0 == (3 & (unsigned int)$kgm_datap))
3063 while (($kgm_idx + 3) <= $kgm_data->length)
3064 printf "%08x", *(unsigned int *) &$kgm_datap[$kgm_idx]
3065 set $kgm_idx = $kgm_idx + 4
3068 while ($kgm_idx < $kgm_data->length)
3069 printf "%02x", $kgm_datap[$kgm_idx++]
3075 define showdictionaryint
3076 set $kgm$arg0_dict = (OSDictionary *)$arg1
3079 set $kgm$arg0_idx = 0
3080 while ($kgm$arg0_idx < $kgm$arg0_dict->count)
3081 set $kgm_obj = $kgm$arg0_dict->dictionary[$kgm$arg0_idx].key
3082 showobjectint _$arg0 $kgm_obj
3084 set $kgm_obj = $kgm$arg0_dict->dictionary[$kgm$arg0_idx++].value
3085 showobjectint _$arg0 $kgm_obj
3086 if ($kgm$arg0_idx < $kgm$arg0_dict->count)
3095 while ($kgm_idx < $arg0)
3096 if ($arg1 & (1 << $kgm_idx++))
3104 define showregdictionary
3105 indent $kgm_reg_depth+2 $arg1
3108 set $kgm_reg_idx = 0
3109 while ($kgm_reg_idx < $arg0->count)
3110 indent $kgm_reg_depth+2 $arg1
3112 set $kgm_obj = $arg0->dictionary[$kgm_reg_idx].key
3113 showobjectint _ $kgm_obj
3116 set $kgm_obj = $arg0->dictionary[$kgm_reg_idx++].value
3117 showobjectint _ $kgm_obj
3120 indent $kgm_reg_depth+2 $arg1
3125 define showarraysetint
3126 set $kgm$arg0_array = (OSArray *)$arg1
3128 set $kgm$arg0_idx = 0
3129 while ($kgm$arg0_idx < $kgm$arg0_array->count)
3130 set $kgm_obj = $kgm$arg0_array->array[$kgm$arg0_idx++]
3131 showobjectint _$arg0 $kgm_obj
3132 if ($kgm$arg0_idx < $kgm$arg0_array->count)
3140 showarraysetint $arg0 $arg1
3145 set $kgm_array = ((OSSet *)$arg1)->members
3147 showarraysetint $arg0 $kgm_array
3152 define showobjectint
3153 set $kgm_obj = (OSObject *) $arg1
3154 set $kgm_vt = *((void **) $arg1)
3156 if ($kgm_lp64 || $kgm_mtype == $kgm_mtype_arm)
3157 set $kgm_vt = $kgm_vt - 2 * sizeof(void *)
3160 if ($kgm_show_object_addrs)
3164 output /a (unsigned long) $kgm_vt
3165 if ($kgm_show_object_retain)
3166 printf ", retain count %d, container retain %d", (0xffff & $kgm_obj->retainCount), $kgm_obj->retainCount >> 16
3171 # No multiple-inheritance
3173 if ($kgm_vt == &_ZTV8OSString)
3177 if ($kgm_vt == &_ZTV8OSSymbol)
3181 if ($kgm_vt == &_ZTV8OSNumber)
3185 if ($kgm_vt == &_ZTV6OSData)
3186 if $kgm_show_data_alwaysbytes == 1
3193 if ($kgm_vt == &_ZTV9OSBoolean)
3197 if ($kgm_vt == &_ZTV12OSDictionary)
3198 showdictionaryint _$arg0 $arg1
3201 if ($kgm_vt == &_ZTV7OSArray)
3202 showarrayint _$arg0 $arg1
3205 if ($kgm_vt == &_ZTV5OSSet)
3206 showsetint _$arg0 $arg1
3210 if ($kgm_shown != 1)
3211 if ($kgm_show_object_addrs == 0)
3215 output /a (unsigned long) $kgm_vt
3222 set $kgm_save = $kgm_show_object_addrs
3223 set $kgm_show_object_addrs = 1
3224 set $kgm_show_object_retain = 1
3225 showobjectint _ $arg0
3226 set $kgm_show_object_addrs = $kgm_save
3227 set $kgm_show_object_retain = 0
3231 Syntax: (gdb) showobject <object address>
3232 | Show info about an OSObject - its vtable ptr and retain count.
3233 | If the object is a simple container class, more info will be shown.
3237 set $kgm_dictp = (OSDictionary *)$arg0
3238 set $kgm_keyp = (const OSSymbol *)$arg1
3241 while (($kgm_idx < $kgm_dictp->count) && ($kgm_result == 0))
3242 if ($kgm_keyp == $kgm_dictp->dictionary[$kgm_idx].key)
3243 set $kgm_result = $kgm_dictp->dictionary[$kgm_idx].value
3245 set $kgm_idx = $kgm_idx + 1
3250 define _registryentryrecurseinit
3251 set $kgm_re = (IOService *)$arg1
3252 set $kgm$arg0_stack = (unsigned long long) $arg2
3255 set $kgm$arg0_stack = $kgm$arg0_stack | (1ULL << $kgm_reg_depth)
3257 set $kgm$arg0_stack = $kgm$arg0_stack & ~(1ULL << $kgm_reg_depth)
3260 dictget $kgm_re->fRegistryTable $kgm_childkey
3261 set $kgm$arg0_child_array = (OSArray *) $kgm_result
3263 if ($kgm$arg0_child_array)
3264 set $kgm$arg0_child_count = $kgm$arg0_child_array->count
3266 set $kgm$arg0_child_count = 0
3269 if ($kgm$arg0_child_count)
3270 set $kgm$arg0_stack = $kgm$arg0_stack | (2ULL << $kgm_reg_depth)
3272 set $kgm$arg0_stack = $kgm$arg0_stack & ~(2ULL << $kgm_reg_depth)
3276 define findregistryentryrecurse
3277 set $kgm_registry_entry = 0
3278 _registryentryrecurseinit $arg0 $arg1 $arg2 $arg3
3280 dictget $kgm_re->fRegistryTable $kgm_namekey
3281 if ($kgm_result == 0)
3282 dictget $kgm_re->fRegistryTable gIONameKey
3284 if ($kgm_result == 0)
3285 dictget $kgm_re->fPropertyTable gIOClassKey
3288 if ($kgm_result != 0)
3289 set $str = ((OSString *) $kgm_result)->string
3290 strcmp_nomalloc $str $kgm_reg_find_str0 $kgm_reg_find_str1 $kgm_reg_find_str2 $kgm_reg_find_str3 $kgm_reg_find_str4 $kgm_reg_find_str5 $kgm_reg_find_str6 $kgm_reg_find_str7 $kgm_reg_find_str8
3291 if $kgm_findregistry_verbose
3295 if $kgm_strcmp_result == 0
3296 if $kgm_findregistry_verbose
3297 printf "\n%s:\n | ", ((OSString *) $kgm_result)->string
3303 # if we want to show everything, then don't populate $kgm_registry_entry
3304 if !$kgm_findregistry_continue
3305 set $kgm_registry_entry = $kgm_re
3311 if (!$kgm_registry_entry && ($kgm$arg0_child_count != 0))
3312 set $kgm_reg_depth = $kgm_reg_depth + 1
3313 set $kgm$arg0_child_idx = 0
3315 while ($kgm$arg0_child_idx < $kgm$arg0_child_count)
3316 set $kgm_re = $kgm$arg0_child_array->array[$kgm$arg0_child_idx++]
3317 set $kgm_more_sib = ($kgm$arg0_child_idx < $kgm$arg0_child_count)
3318 if $kgm_reg_depth >= $kgm_reg_depth_max + 1
3321 findregistryentryrecurse _$arg0 $kgm_re $kgm$arg0_stack $kgm_more_sib
3322 if $kgm_registry_entry
3326 set $kgm_reg_depth = $kgm_reg_depth - 1
3330 define findregdictvalue
3331 set $kgm_registry_value = 0
3332 set $kgm_reg_idx = 0
3333 while ($kgm_reg_idx < $arg0->count)
3334 set $kgm_obj = $arg0->dictionary + $kgm_reg_idx
3335 set $str = ((OSString *)$kgm_obj->key)->string
3336 strcmp_nomalloc $str $kgm_reg_find_str0 $kgm_reg_find_str1 $kgm_reg_find_str2 $kgm_reg_find_str3 $kgm_reg_find_str4 $kgm_reg_find_str5 $kgm_reg_find_str6 $kgm_reg_find_str7 $kgm_reg_find_str8
3338 if $kgm_strcmp_result == 0
3339 set $kgm_registry_value = $kgm_obj->value
3340 if $kgm_findregistry_verbose
3341 showobject $kgm_registry_value
3342 print $kgm_registry_value
3346 set $kgm_reg_idx = $kgm_reg_idx + 1
3350 define setfindregistrystr
3351 set $kgm_reg_find_str0 = 0
3352 set $kgm_reg_find_str1 = 0
3353 set $kgm_reg_find_str2 = 0
3354 set $kgm_reg_find_str3 = 0
3355 set $kgm_reg_find_str4 = 0
3356 set $kgm_reg_find_str5 = 0
3357 set $kgm_reg_find_str6 = 0
3358 set $kgm_reg_find_str7 = 0
3359 set $kgm_reg_find_str8 = 0
3362 set $kgm_reg_find_str0 = $arg0
3365 set $kgm_reg_find_str1 = $arg1
3368 set $kgm_reg_find_str2 = $arg2
3371 set $kgm_reg_find_str3 = $arg3
3374 set $kgm_reg_find_str4 = $arg4
3377 set $kgm_reg_find_str5 = $arg5
3380 set $kgm_reg_find_str6 = $arg6
3383 set $kgm_reg_find_str7 = $arg7
3386 set $kgm_reg_find_str8 = $arg8
3390 document setfindregistrystr
3391 Syntax: (gdb) setfindregistrystr [a] [b] [c] [d] [e] [f] [g] [h] [i]
3392 | Store an encoded string into up to 9 arguments for use by
3393 | findregistryprop or findregistryentry. The arguments are created
3394 | through calls to strcmp_arg_pack64
3397 define _findregistryprop
3398 set $reg = (IOService *) $arg0
3399 set $kgm_props = $reg->fPropertyTable
3400 set $kgm_findregistry_verbose = 0
3402 findregdictvalue $kgm_props
3405 define findregistryprop
3406 set $reg = (IOService *) $arg0
3407 set $kgm_props = $reg->fPropertyTable
3409 set $kgm_findregistry_verbose = 1
3410 findregdictvalue $kgm_props
3413 document findregistryprop
3414 Syntax: (gdb) findregistryprop <entry>
3415 | Given a registry entry, print out the contents for the property that matches
3416 | the encoded string specified via setfindregistrystr.
3418 | For example, the following will print out the "intel-pic" property stored in
3419 | the AppleACPIPlatformExpert registry entry $pe_entry:
3420 | strcmp_arg_pack64 'i' 'n' 't' 'e' 'l' '-' 'p' 'i'
3421 | set $intel_pi = $kgm_strcmp_arg
3422 | strcmp_arg_pack64 'c' 0 0 0 0 0 0 0
3423 | set $c = $kgm_strcmp_arg
3424 | setfindregistrystr $intel_pi $c
3425 | findregistryprop $pe_entry
3428 define findregistryentryint
3430 set $kgm_reg_plane = (IORegistryPlane *) gIOServicePlane
3434 printf "Please load kgmacros after KDP attaching to the target.\n"
3436 set $kgm_namekey = (OSSymbol *) $kgm_reg_plane->nameKey
3437 set $kgm_childkey = (OSSymbol *) $kgm_reg_plane->keys[1]
3438 if $kgm_findregistry_verbose
3441 findregistryentryrecurse _ $arg0 0 0
3445 define _findregistryentry
3446 set $kgm_findregistry_verbose = 0
3447 set $kgm_findregistry_continue = 0
3448 set $kgm_reg_depth = 0
3450 findregistryentryint gRegistryRoot
3453 define findregistryentry
3454 set $kgm_findregistry_verbose = 1
3455 set $kgm_findregistry_continue = 0
3456 set $kgm_reg_depth = 0
3458 findregistryentryint gRegistryRoot
3461 define findregistryentries
3462 set $kgm_findregistry_verbose = 1
3463 set $kgm_findregistry_continue = 1
3464 set $kgm_reg_depth = 0
3466 findregistryentryint gRegistryRoot
3469 document findregistryentry
3470 Syntax: (gdb) findregistryentry
3471 | Search for a registry entry that matches the encoded string specified through
3472 | setfindregistrystr. You can alter the search depth through use of
3473 | $kgm_reg_depth_max.
3475 | For example, the following will pull out the AppleACPIPlatformExpert registry
3477 | strcmp_arg_pack64 'A' 'p' 'p' 'l' 'e' 'A' 'C' 'P'
3478 | set $AppleACP = $kgm_strcmp_arg
3479 | strcmp_arg_pack64 'I' 'P' 'l' 'a' 't' 'f' 'o' 'r'
3480 | set $IPlatfor = $kgm_strcmp_arg
3481 | strcmp_arg_pack64 'm' 'E' 'x' 'p' 'e' 'r' 't' 0
3482 | set $mExpert = $kgm_strcmp_arg
3483 | setfindregistrystr $AppleACP $IPlatfor $mExpert
3487 document findregistryentries
3488 Syntax: (gdb) findregistryentries
3489 | Search for all registry entries that match the encoded string specified through
3490 | setfindregistrystr. You can alter the search depth through use of
3491 | $kgm_reg_depth_max. See findregistryentry for an example of how to encode a string.
3495 define showregistryentryrecurse
3496 _registryentryrecurseinit $arg0 $arg1 $arg2 $arg3
3498 indent $kgm_reg_depth $kgm$arg0_stack
3501 dictget $kgm_re->fRegistryTable $kgm_namekey
3502 if ($kgm_result == 0)
3503 dictget $kgm_re->fRegistryTable gIONameKey
3505 if ($kgm_result == 0)
3506 dictget $kgm_re->fPropertyTable gIOClassKey
3509 if ($kgm_result != 0)
3510 printf "%s", ((OSString *)$kgm_result)->string
3512 if (((IOService*)$kgm_re)->pwrMgt && ((IOService*)$kgm_re)->pwrMgt->Name)
3513 printf "%s", ((IOService*)$kgm_re)->pwrMgt->Name
3515 # printf ", guessclass "
3516 # guessclass $kgm_re
3524 printf ", id 0x%llx, ", $kgm_re->IORegistryEntry::reserved->fRegistryEntryID
3526 set $kgm_vt = (unsigned long) *(void**) $kgm_re
3527 if ($kgm_lp64 || $kgm_mtype == $kgm_mtype_arm)
3528 set $kgm_vt = $kgm_vt - 2 * sizeof(void *)
3532 if ($kgm_vt != &_ZTV15IORegistryEntry)
3534 set $kgm_state = $kgm_re->__state[0]
3535 # kIOServiceRegisteredState
3536 if (0 == ($kgm_state & 2))
3539 printf "registered, "
3540 # kIOServiceMatchedState
3541 if (0 == ($kgm_state & 4))
3545 # kIOServiceInactiveState
3549 printf "active, busy %d, retain count %d", (0xff & $kgm_re->__state[1]), (0xffff & $kgm_re->retainCount)
3553 if ($kgm_show_props)
3554 set $kgm_props = $kgm_re->fPropertyTable
3555 showregdictionary $kgm_props $kgm$arg0_stack
3559 if ($kgm$arg0_child_count != 0)
3561 set $kgm_reg_depth = $kgm_reg_depth + 1
3562 set $kgm$arg0_child_idx = 0
3564 while ($kgm$arg0_child_idx < $kgm$arg0_child_count)
3565 set $kgm_re = $kgm$arg0_child_array->array[$kgm$arg0_child_idx++]
3566 set $kgm_more_sib = ($kgm$arg0_child_idx < $kgm$arg0_child_count)
3567 if $kgm_reg_depth >= $kgm_reg_depth_max + 1
3570 showregistryentryrecurse _$arg0 $kgm_re $kgm$arg0_stack $kgm_more_sib
3573 set $kgm_reg_depth = $kgm_reg_depth - 1
3577 define showregistryentryint
3579 set $kgm_reg_plane = (IORegistryPlane *) gIOServicePlane
3583 printf "Please load kgmacros after KDP attaching to the target.\n"
3585 set $kgm_namekey = (OSSymbol *) $kgm_reg_plane->nameKey
3586 set $kgm_childkey = (OSSymbol *) $kgm_reg_plane->keys[1]
3587 showregistryentryrecurse _ $arg0 0 0
3592 set $kgm_reg_depth = 0
3593 set $kgm_show_props = 0
3594 showregistryentryint gRegistryRoot
3596 document showregistry
3597 Syntax: (gdb) showregistry
3598 | Show info about all registry entries in the current plane. You can specify the maximum
3599 | display depth with $kgm_reg_depth_max.
3602 define showregistryprops
3603 set $kgm_reg_depth = 0
3604 set $kgm_show_props = 1
3605 showregistryentryint gRegistryRoot
3607 document showregistryprops
3608 Syntax: (gdb) showregistryprops
3609 | Show info about all registry entries in the current plane, and their properties.
3610 | set $kgm_show_object_addrs = 1 and/or set $kgm_show_object_retain = 1 will display
3611 | more verbose information
3614 define showregistryentry
3615 set $kgm_reg_depth = 0
3616 set $kgm_show_props = 1
3617 showregistryentryint $arg0
3619 document showregistryentry
3620 Syntax: (gdb) showregistryentry <object address>
3621 | Show info about a registry entry; its properties and descendants in the current plane.
3624 define setregistryplane
3626 set $kgm_reg_plane = (IORegistryPlane *) $arg0
3628 showobjectint _ gIORegistryPlanes
3632 document setregistryplane
3633 Syntax: (gdb) setregistryplane <plane object address>
3634 | Set the plane to be used for the iokit registry macros. An argument of zero will
3635 | display known planes.
3639 set $kgm_classidx = 0
3640 set $kgm_lookvt = *((void **) $arg0)
3641 set $kgm_bestvt = (void *) 0
3642 set $kgm_bestidx = 0
3644 while $kgm_classidx < sAllClassesDict->count
3645 set $kgm_meta = (OSMetaClass *) sAllClassesDict->dictionary[$kgm_classidx].value
3647 set $kgm_vt = *((void **) $kgm_meta)
3649 if (($kgm_vt > $kgm_bestvt) && ($kgm_vt < $kgm_lookvt))
3650 set $kgm_bestvt = $kgm_vt
3651 set $kgm_bestidx = $kgm_classidx
3653 set $kgm_classidx = $kgm_classidx + 1
3655 printf "%s", sAllClassesDict->dictionary[$kgm_bestidx].key->string
3658 define showallclasses
3659 set $kgm_classidx = 0
3660 while $kgm_classidx < sAllClassesDict->count
3661 set $kgm_meta = (OSMetaClass *) sAllClassesDict->dictionary[$kgm_classidx++].value
3662 showmetaclass $kgm_meta
3666 document showallclasses
3667 Syntax: (gdb) showallclasses
3668 | Show the instance counts and ivar size of all OSObject subclasses. See ioclasscount man page for details.
3672 printf " Instance allocation = 0x%08lx = %4ld K\n", (int) debug_ivars_size, ((int) debug_ivars_size) / 1024
3673 printf "Container allocation = 0x%08lx = %4ld K\n", (int) debug_container_malloc_size, ((int) debug_container_malloc_size) / 1024
3674 printf " IOMalloc allocation = 0x%08lx = %4ld K\n", (int) debug_iomalloc_size, ((int) debug_iomalloc_size) / 1024
3675 printf " Pageable allocation = 0x%08lx = %4ld K\n", (vm_size_t) debug_iomallocpageable_size, ((vm_size_t) debug_iomallocpageable_size) / 1024
3678 document showioalloc
3679 Syntax: (gdb) showioalloc
3680 | Show some accounting of memory allocated by IOKit allocators. See ioalloccount man page for details.
3683 define showosobjecttracking
3684 set $kgm_next = (OSObjectTracking *) gOSObjectTrackList.next
3685 while $kgm_next != &gOSObjectTrackList
3686 set $obj = (OSObject *) ($kgm_next+1)
3689 while $kgm_idx < (sizeof($kgm_next->bt) / sizeof($kgm_next->bt[0]))
3690 if ((unsigned long) $kgm_next->bt[$kgm_idx] > (unsigned long) &last_kernel_symbol)
3691 showkmodaddr $kgm_next->bt[$kgm_idx]
3694 if ((unsigned long) $kgm_next->bt[$kgm_idx] > 0)
3695 output /a $kgm_next->bt[$kgm_idx]
3699 set $kgm_idx = $kgm_idx + 1
3702 set $kgm_next = (OSObjectTracking *) $kgm_next->link.next
3706 document showosobjecttracking
3707 Syntax: (gdb) showosobjecttracking
3708 | Show the list of tracked OSObject allocations with backtraces.
3709 | Boot with the kOSTraceObjectAlloc (0x00400000) io debug flag set.
3710 | Set gOSObjectTrackThread to 1 or a thread_t to capture new OSObjects allocated by a thread or all threads.
3714 set $kgm_readphysint_result = 0xBAD10AD
3715 # set up the manual KDP packet
3716 set manual_pkt.input = 0
3717 set manual_pkt.len = sizeof(kdp_readphysmem64_req_t)
3718 set $kgm_pkt = (kdp_readphysmem64_req_t *)&manual_pkt.data
3719 set $kgm_pkt->hdr.request = KDP_READPHYSMEM64
3720 set $kgm_pkt->hdr.len = sizeof(kdp_readphysmem64_req_t)
3721 set $kgm_pkt->hdr.is_reply = 0
3722 set $kgm_pkt->hdr.seq = 0
3723 set $kgm_pkt->hdr.key = 0
3724 set $kgm_pkt->address = (uint64_t)$arg0
3725 set $kgm_pkt->nbytes = $arg1 >> 3
3726 set $kgm_pkt->lcpu = $arg2
3727 set manual_pkt.input = 1
3728 # dummy to make sure manual packet is executed
3729 set $kgm_dummy = &_mh_execute_header
3730 set $kgm_pkt = (kdp_readphysmem64_reply_t *)&manual_pkt.data
3731 if ($kgm_pkt->error == 0)
3733 set $kgm_readphysint_result = *((uint8_t *)$kgm_pkt->data)
3736 set $kgm_readphysint_result = *((uint16_t *)$kgm_pkt->data)
3739 set $kgm_readphysint_result = *((uint32_t *)$kgm_pkt->data)
3742 set $kgm_readphysint_result = *((uint64_t *)$kgm_pkt->data)
3748 readphysint $arg0 8 $kgm_lcpu_self
3750 printf ":\t0x%02hhx\n", $kgm_readphysint_result
3751 set $kgm_readphys_result = (uint64_t)$kgm_readphysint_result
3755 readphysint $arg0 16 $kgm_lcpu_self
3757 printf ":\t0x%04hx\n", $kgm_readphysint_result
3758 set $kgm_readphys_result = (uint64_t)$kgm_readphysint_result
3762 readphysint $arg0 32 $kgm_lcpu_self
3764 printf ":\t0x%08x\n", $kgm_readphysint_result
3765 set $kgm_readphys_result = (uint64_t)$kgm_readphysint_result
3769 readphysint $arg0 64 $kgm_lcpu_self
3771 printf ":\t0x%016llx\n", $kgm_readphysint_result
3772 set $kgm_readphys_result = (uint64_t)$kgm_readphysint_result
3792 | The argument is interpreted as a physical address, and the 64-bit word
3793 | addressed is displayed. Saves 64-bit result in $kgm_readphys_result.
3797 # set up the manual KDP packet
3798 set manual_pkt.input = 0
3799 set manual_pkt.len = sizeof(kdp_writephysmem64_req_t)
3800 set $kgm_pkt = (kdp_writephysmem64_req_t *)&manual_pkt.data
3801 set $kgm_pkt->hdr.request = KDP_WRITEPHYSMEM64
3802 set $kgm_pkt->hdr.len = sizeof(kdp_writephysmem64_req_t)
3803 set $kgm_pkt->hdr.is_reply = 0
3804 set $kgm_pkt->hdr.seq = 0
3805 set $kgm_pkt->hdr.key = 0
3806 set $kgm_pkt->address = (uint64_t)$arg0
3807 set $kgm_pkt->nbytes = $arg1 >> 3
3808 set $kgm_pkt->lcpu = $arg3
3810 set *(uint8_t *)$kgm_pkt->data = (uint8_t)$arg2
3813 set *(uint16_t *)$kgm_pkt->data = (uint16_t)$arg2
3816 set *(uint32_t *)$kgm_pkt->data = (uint32_t)$arg2
3819 set *(uint64_t *)$kgm_pkt->data = (uint64_t)$arg2
3821 set manual_pkt.input = 1
3822 # dummy to make sure manual packet is executed
3823 set $kgm_dummy = &_mh_execute_header
3824 set $kgm_pkt = (kdp_writephysmem64_reply_t *)&manual_pkt.data
3825 set $kgm_writephysint_result = $kgm_pkt->error
3829 writephysint $arg0 8 $arg1 $kgm_lcpu_self
3833 writephysint $arg0 16 $arg1 $kgm_lcpu_self
3837 writephysint $arg0 32 $arg1 $kgm_lcpu_self
3841 writephysint $arg0 64 $arg1 $kgm_lcpu_self
3848 document writephys16
3852 document writephys32
3856 document writephys64
3857 | The argument is interpreted as a physical address, and the second argument is
3858 | written to that address as a 64-bit word.
3862 shell ls $arg0/* | xargs -n 1 echo add-symbol-file > /tmp/gdb-syms
3863 source /tmp/gdb-syms
3864 set $kgm_show_kmod_syms = 1
3867 document addkextsyms
3868 | Takes a directory of symbols for kexts generated with kextcache -y and loads them
3870 | (gdb) addkextsyms /path/to/symboldir
3873 define showprocfiles
3876 _showprocfiles $arg0
3878 printf "| Usage:\n|\n"
3882 document showprocfiles
3883 Syntax: (gdb) showprocfiles <proc_t>
3884 | Given a proc_t pointer, display the list of open file descriptors for the
3885 | referenced process.
3888 define _showprocheader
3889 printf "fd fileglob "
3891 printf " fg flags fg type fg data "
3894 printf "----- ----------"
3898 printf " ---------- -------- ----------"
3902 printf " -------------------\n"
3905 define _showprocfiles
3906 set $kgm_spf_filedesc = ((proc_t)$arg0)->p_fd
3907 set $kgm_spf_last = $kgm_spf_filedesc->fd_lastfile
3908 set $kgm_spf_ofiles = $kgm_spf_filedesc->fd_ofiles
3909 set $kgm_spf_count = 0
3910 while ($kgm_spf_count <= $kgm_spf_last)
3911 if ($kgm_spf_ofiles[$kgm_spf_count] == 0)
3912 # DEBUG: For files that were open, but are now closed
3913 # printf "%-5d FILEPROC_NULL\n", $kgm_spf_count
3915 # display fd #, fileglob address, fileglob flags
3916 set $kgm_spf_flags = $kgm_spf_ofiles[$kgm_spf_count].f_flags
3917 set $kgm_spf_fg = $kgm_spf_ofiles[$kgm_spf_count].f_fglob
3918 printf "%-5d ", $kgm_spf_count
3920 printf " 0x%08x ", $kgm_spf_flags
3921 # decode fileglob type
3922 set $kgm_spf_fgt = $kgm_spf_fg->fg_type
3923 if ($kgm_spf_fgt == 1)
3926 if ($kgm_spf_fgt == 2)
3929 if ($kgm_spf_fgt == 3)
3932 if ($kgm_spf_fgt == 4)
3935 if ($kgm_spf_fgt == 5)
3938 if ($kgm_spf_fgt == 6)
3941 if ($kgm_spf_fgt == 7)
3944 if ($kgm_spf_fgt < 1 || $kgm_spf_fgt > 7)
3945 printf "?: %-5d", $kgm_spf_fgt
3948 # display fileglob data address and decode interesting fact(s)
3949 # about data, if we know any
3950 set $kgm_spf_fgd = $kgm_spf_fg->fg_data
3952 showptr $kgm_spf_fgd
3954 if ($kgm_spf_fgt == 1)
3955 set $kgm_spf_name = ((struct vnode *)$kgm_spf_fgd)->v_name
3956 if ($kgm_spf_name == 0)
3959 printf "%s", $kgm_spf_name
3964 set $kgm_spf_count = $kgm_spf_count + 1
3969 # Show all the advisory file locks held by a process for each of the vnode
3970 # type files that it has open; do this by walking the per process open file
3971 # table and looking at any vnode type fileglob that has a non-NULL lock list
3972 # associated with it.
3974 define showproclocks
3976 _showproclocks $arg0
3978 printf "| Usage:\n|\n"
3982 document showproclocks
3983 Syntax: (gdb) showproclocks <proc_t>
3984 | Given a proc_t pointer, display the list of advisory file locks held by the
3985 | referenced process.
3988 define _showproclocks
3989 set $kgm_spl_filedesc = ((proc_t)$arg0)->p_fd
3990 set $kgm_spl_last = $kgm_spl_filedesc->fd_lastfile
3991 set $kgm_spl_ofiles = $kgm_spl_filedesc->fd_ofiles
3992 set $kgm_spl_count = 0
3993 set $kgm_spl_seen = 0
3994 while ($kgm_spl_count <= $kgm_spl_last)
3995 if ($kgm_spl_ofiles[$kgm_spl_count] == 0)
3996 # DEBUG: For files that were open, but are now closed
3997 # printf "%-5d FILEPROC_NULL\n", $kgm_spl_count
3999 set $kgm_spl_fg = $kgm_spl_ofiles[$kgm_spl_count].f_fglob
4000 # decode fileglob type
4001 set $kgm_spl_fgt = $kgm_spl_fg->fg_type
4002 if ($kgm_spl_fgt == 1)
4003 set $kgm_spl_fgd = $kgm_spl_fg->fg_data
4004 set $kgm_spl_name = ((struct vnode *)$kgm_spl_fgd)->v_name
4005 set $kgm_spl_vnode = ((vnode_t)$kgm_spl_fgd)
4006 set $kgm_spl_lockiter = $kgm_spl_vnode->v_lockf
4007 if ($kgm_spl_lockiter != 0)
4008 if ($kgm_spl_seen == 0)
4009 _showvnodelockheader
4011 set $kgm_spl_seen = $kgm_spl_seen + 1
4012 printf "( fd %d, name ", $kgm_spl_count
4013 if ($kgm_spl_name == 0)
4016 printf "%s )\n", $kgm_spl_name
4018 _showvnodelocks $kgm_spl_fgd
4022 set $kgm_spl_count = $kgm_spf_count + 1
4024 printf "%d total locks for ", $kgm_spl_seen
4030 set $kgm_spi_proc = (proc_t)$arg0
4032 showptr $kgm_spi_proc
4034 printf " name %s\n", $kgm_spi_proc->p_comm
4035 printf " pid:%.8d", $kgm_spi_proc->p_pid
4037 showptr $kgm_spi_proc->task
4038 printf " p_stat:%.1d", $kgm_spi_proc->p_stat
4039 printf " parent pid:%.8d", $kgm_spi_proc->p_ppid
4041 # decode part of credential
4042 set $kgm_spi_cred = $kgm_spi_proc->p_ucred
4043 if ($kgm_spi_cred != 0)
4044 printf "Cred: euid %d ruid %d svuid %d\n", $kgm_spi_cred->cr_uid, $kgm_spi_cred->cr_ruid, $kgm_spi_cred->cr_svuid
4046 printf "Cred: (null)\n"
4049 set $kgm_spi_flag = $kgm_spi_proc->p_flag
4050 printf "Flags: 0x%08x\n", $kgm_spi_flag
4051 if ($kgm_spi_flag & 0x00000001)
4052 printf " 0x00000001 - may hold advisory locks\n"
4054 if ($kgm_spi_flag & 0x00000002)
4055 printf " 0x00000002 - has a controlling tty\n"
4057 if ($kgm_spi_flag & 0x00000004)
4058 printf " 0x00000004 - process is 64 bit\n"
4060 printf " !0x00000004 - process is 32 bit\n"
4062 if ($kgm_spi_flag & 0x00000008)
4063 printf " 0x00000008 - no SIGCHLD on child stop\n"
4065 if ($kgm_spi_flag & 0x00000010)
4066 printf " 0x00000010 - waiting for child exec/exit\n"
4068 if ($kgm_spi_flag & 0x00000020)
4069 printf " 0x00000020 - has started profiling\n"
4071 if ($kgm_spi_flag & 0x00000040)
4072 printf " 0x00000040 - in select; wakeup/waiting danger\n"
4074 if ($kgm_spi_flag & 0x00000080)
4075 printf " 0x00000080 - was stopped and continued\n"
4077 if ($kgm_spi_flag & 0x00000100)
4078 printf " 0x00000100 - has set privileges since exec\n"
4080 if ($kgm_spi_flag & 0x00000200)
4081 printf " 0x00000200 - system process: no signals, stats, or swap\n"
4083 if ($kgm_spi_flag & 0x00000400)
4084 printf " 0x00000400 - timing out during a sleep\n"
4086 if ($kgm_spi_flag & 0x00000800)
4087 printf " 0x00000800 - debugged process being traced\n"
4089 if ($kgm_spi_flag & 0x00001000)
4090 printf " 0x00001000 - debugging process has waited for child\n"
4092 if ($kgm_spi_flag & 0x00002000)
4093 printf " 0x00002000 - exit in progress\n"
4095 if ($kgm_spi_flag & 0x00004000)
4096 printf " 0x00004000 - process has called exec\n"
4098 if ($kgm_spi_flag & 0x00008000)
4099 printf " 0x00008000 - owe process an addupc() XXX\n"
4101 if ($kgm_spi_flag & 0x00010000)
4102 printf " 0x00010000 - affinity for Rosetta children\n"
4104 if ($kgm_spi_flag & 0x00020000)
4105 printf " 0x00020000 - wants to run Rosetta\n"
4107 if ($kgm_spi_flag & 0x00040000)
4108 printf " 0x00040000 - has wait() in progress\n"
4110 if ($kgm_spi_flag & 0x00080000)
4111 printf " 0x00080000 - kdebug tracing on for this process\n"
4113 if ($kgm_spi_flag & 0x00100000)
4114 printf " 0x00100000 - blocked due to SIGTTOU or SIGTTIN\n"
4116 if ($kgm_spi_flag & 0x00200000)
4117 printf " 0x00200000 - has called reboot()\n"
4119 if ($kgm_spi_flag & 0x00400000)
4120 printf " 0x00400000 - is TBE state\n"
4122 if ($kgm_spi_flag & 0x00800000)
4123 printf " 0x00800000 - signal exceptions\n"
4125 if ($kgm_spi_flag & 0x01000000)
4126 printf " 0x01000000 - has thread cwd\n"
4128 if ($kgm_spi_flag & 0x02000000)
4129 printf " 0x02000000 - has vfork() children\n"
4131 if ($kgm_spi_flag & 0x04000000)
4132 printf " 0x04000000 - not allowed to attach\n"
4134 if ($kgm_spi_flag & 0x08000000)
4135 printf " 0x08000000 - vfork() in progress\n"
4137 if ($kgm_spi_flag & 0x10000000)
4138 printf " 0x10000000 - no shared libraries\n"
4140 if ($kgm_spi_flag & 0x20000000)
4141 printf " 0x20000000 - force quota for root\n"
4143 if ($kgm_spi_flag & 0x40000000)
4144 printf " 0x40000000 - no zombies when children exit\n"
4146 if ($kgm_spi_flag & 0x80000000)
4147 printf " 0x80000000 - don't hang on remote FS ops\n"
4150 set $kgm_spi_state = $kgm_spi_proc->p_stat
4152 if ($kgm_spi_state == 1)
4155 if ($kgm_spi_state == 2)
4158 if ($kgm_spi_state == 3)
4161 if ($kgm_spi_state == 4)
4164 if ($kgm_spi_state == 5)
4167 if ($kgm_spi_state == 6)
4170 if ($kgm_spi_state < 1 || $kgm_spi_state > 6)
4171 printf "(Unknown)\n"
4175 document showprocinfo
4176 Syntax: (gdb) showprocinfo <proc_t>
4177 | Displays name, pid, parent and task for a proc_t. Decodes cred, flag and p_stat fields.
4181 # dump the zombprocs
4184 set $basep = (struct proc *)zombproc->lh_first
4188 set $pp = $pp->p_list.le_next
4193 Syntax: (gdb) zombproc
4194 | Routine to print out all procs in the zombie list
4198 # dump the zombstacks
4201 set $basep = (struct proc *)zombproc->lh_first
4205 showtaskstacks $pp->task
4207 set $pp = $pp->p_list.le_next
4212 Syntax: (gdb) zombstacks
4213 | Routine to print out all stacks of tasks that are exiting
4221 set $basep = (struct proc *)allproc->lh_first
4225 set $pp = $pp->p_list.le_next
4230 Syntax: (gdb) allproc
4231 | Routine to print out all process in the system
4232 | which are not in the zombie list
4238 set $vp = (struct vnode *)$arg0
4242 printf " use %d", $vp->v_usecount
4243 printf " io %d", $vp->v_iocount
4244 printf " kuse %d", $vp->v_kusecount
4245 printf " type %d", $vp->v_type
4246 printf " flg 0x%.8x", $vp->v_flag
4247 printf " lflg 0x%.8x", $vp->v_lflag
4249 showptr $vp->v_parent
4250 set $_name = (char *)$vp->v_name
4252 printf " %s", $_name
4254 if ($vp->v_type == VREG) && ($vp->v_un.vu_ubcinfo != 0)
4255 printf " mapped %d", ($vp->v_un.vu_ubcinfo.ui_flags & 0x08) ? 1 : 0
4260 document print_vnode
4261 Syntax: (gdb) print_vnode <vnode>
4262 | Prints out the fields of a vnode struct
4265 define showprocvnodes
4266 set $pp = (struct proc *)$arg0
4267 set $fdp = (struct filedesc *)$pp->p_fd
4268 set $cvp = $fdp->fd_cdir
4269 set $rvp = $fdp->fd_rdir
4271 printf "Current Working Directory \n"
4276 printf "Current Root Directory \n"
4281 set $fpp = (struct fileproc **)($fdp->fd_ofiles)
4282 set $fpo = (char)($fdp->fd_ofileflags[0])
4283 while $count < $fdp->fd_nfiles
4284 #printf"fpp %x ", *$fpp
4286 set $fg =(struct fileglob *)((**$fpp)->f_fglob)
4287 if $fg && (($fg)->fg_type == 1)
4288 if $fdp->fd_ofileflags[$count] & 4
4293 printf "fd = %d ", $count
4294 print_vnode $fg->fg_data
4298 set $count = $count + 1
4302 document showprocvnodes
4303 Syntax: (gdb) showprocvnodes <proc_address>
4304 | Routine to print out all the open fds
4305 | which are vnodes in a process
4308 define showallprocvnodes
4309 set $basep = (struct proc *)allproc->lh_first
4312 printf "============================================ \n"
4315 set $pp = $pp->p_list.le_next
4319 document showallprocvnodes
4320 Syntax: (gdb) showallprocvnodes
4321 | Routine to print out all the open fds
4327 # dump the childrent of a proc
4329 define showinitchild
4330 set $basep = (struct proc *)initproc->p_children.lh_first
4334 set $pp = $pp->p_sibling.le_next
4338 document showinitchild
4339 Syntax: (gdb) showinitchild
4340 | Routine to print out all processes in the system
4341 | which are children of init process
4345 define showmountallvnodes
4346 set $mp = (struct mount *)$arg0
4347 set $basevp = (struct vnode *)$mp->mnt_vnodelist.tqh_first
4349 printf "____________________ Vnode list Queue ---------------\n"
4352 set $vp = $vp->v_mntvnodes->tqe_next
4354 set $basevp = (struct vnode *)$mp->mnt_workerqueue.tqh_first
4356 printf "____________________ Worker Queue ---------------\n"
4359 set $vp = $vp->v_mntvnodes->tqe_next
4361 set $basevp = (struct vnode *)$mp->mnt_newvnodes.tqh_first
4363 printf "____________________ New vnodes Queue ---------------\n"
4366 set $vp = $vp->v_mntvnodes->tqe_next
4369 document showmountallvnodes
4370 Syntax: showmountallvnodes <struct mount *>
4371 | Print the vnode inactive list
4375 define showmountvnodes
4376 set $mp = (struct mount *)$arg0
4377 set $basevp = (struct vnode *)$mp->mnt_vnodelist.tqh_first
4379 printf "____________________ Vnode list Queue ---------------\n"
4382 set $vp = $vp->v_mntvnodes->tqe_next
4385 document showmountvnodes
4386 Syntax: showmountvnodes <struct mount *>
4387 | Print the vnode list
4392 define showworkqvnodes
4393 set $mp = (struct mount *)$arg0
4394 set $basevp = (struct vnode *)$mp->mnt_workerqueue.tqh_first
4396 printf "____________________ Worker Queue ---------------\n"
4399 set $vp = $vp->v_mntvnodes->tqe_next
4402 document showworkqvnodes
4403 Syntax: showworkqvnodes <struct mount *>
4404 | Print the vnode worker list
4408 define shownewvnodes
4409 set $mp = (struct mount *)$arg0
4410 set $basevp = (struct vnode *)$mp->mnt_newvnodes.tqh_first
4412 printf "____________________ New vnodes Queue ---------------\n"
4415 set $vp = $vp->v_mntvnodes->tqe_next
4419 document shownewvnodes
4420 Syntax: shownewvnodes <struct mount *>
4421 | Print the new vnode list
4426 # print mount point info
4428 set $mp = (struct mount *)$arg0
4432 printf " flag %x", $mp->mnt_flag
4433 printf " kern_flag %x", $mp->mnt_kern_flag
4434 printf " lflag %x", $mp->mnt_lflag
4435 printf " type: %s", $mp->mnt_vfsstat.f_fstypename
4436 printf " mnton: %s", $mp->mnt_vfsstat.f_mntonname
4437 printf " mntfrom: %s", $mp->mnt_vfsstat.f_mntfromname
4441 define showallmounts
4442 set $mp=(struct mount *)mountlist.tqh_first
4445 set $mp = $mp->mnt_list.tqe_next
4449 document showallmounts
4450 Syntax: showallmounts
4451 | Print all mount points
4455 if (((unsigned long) $arg0 < (unsigned long) &_mh_execute_header || \
4456 (unsigned long) $arg0 >= (unsigned long) &last_kernel_symbol ))
4464 set $mp = (struct mbuf *)$arg0
4468 printf "%4d: %p [len %4d, type %2d, ", $cnt, $mp, \
4469 $mp->m_hdr.mh_len, $mp->m_hdr.mh_type
4474 set $tot = $tot + $mp->m_hdr.mh_len
4475 printf "total %d]\n", $tot
4476 set $mp = $mp->m_hdr.mh_nextpkt
4481 document mbuf_walkpkt
4482 Syntax: (gdb) mbuf_walkpkt <addr>
4483 | Given an mbuf address, walk its m_nextpkt pointer
4487 set $mp = (struct mbuf *)$arg0
4491 printf "%4d: %p [len %4d, type %2d, ", $cnt, $mp, \
4492 $mp->m_hdr.mh_len, $mp->m_hdr.mh_type
4497 set $tot = $tot + $mp->m_hdr.mh_len
4498 printf "total %d]\n", $tot
4499 set $mp = $mp->m_hdr.mh_next
4505 Syntax: (gdb) mbuf_walk <addr>
4506 | Given an mbuf address, walk its m_next pointer
4509 define mbuf_buf2slab
4511 set $gix = ((char *)$addr - (char *)mbutl) >> 20
4512 set $ix = ((char *)$addr - (char *)mbutl) >> 11
4513 set $slab = &slabstbl[$gix].slg_slab[$ix]
4517 document mbuf_buf2slab
4518 | Given an mbuf object, find its corresponding slab address.
4523 set $ix = ((char *)$addr - (char *)mbutl) >> 11
4524 set $clbase = ((union mcluster *)(mbutl + $ix))
4525 set $mclidx = (((char *)$addr - (char *)$clbase) >> 8)
4526 set $mca = mclaudit[$ix].cl_audit[$mclidx]
4527 printf "mca: %p", $mca
4530 document mbuf_buf2mca
4531 Syntax: (gdb) mbuf_buf2mca <addr>
4532 | Given an mbuf object, find its buffer audit structure address.
4533 | This requires mbuf buffer auditing to be turned on, by setting
4534 | the appropriate flags to the "mbuf_debug" boot-args parameter.
4539 set $mca = (mcache_audit_t *)$arg0
4540 set $cp = (mcache_t *)$mca->mca_cache
4541 printf "object type:\t\t"
4542 mbuf_mca_ctype $mca 1
4543 printf "\ncontrolling mcache:\t%p (%s)\n", $mca->mca_cache, $cp->mc_name
4544 if $mca->mca_uflags & $MB_SCVALID
4545 set $ix = ((char *)$mca->mca_addr - (char *)mbutl) >> 11
4546 set $clbase = ((union mcluster *)(mbutl + $ix))
4547 set $mclidx = (((char *)$mca->mca_addr - (char *)$clbase) >> 8)
4548 printf "mbuf obj:\t\t%p\n", $mca->mca_addr
4549 printf "mbuf index:\t\t%d (out of 8) in cluster base %p\n", \
4550 $mclidx + 1, $clbase
4551 if $mca->mca_uptr != 0
4552 set $peer_mca = (mcache_audit_t *)$mca->mca_uptr
4553 printf "paired cluster obj:\t%p (mca %p)\n", \
4554 $peer_mca->mca_addr, $peer_mca
4556 printf "saved contents:\t\t%p (%d bytes)\n", \
4557 $mca->mca_contents, $mca->mca_contents_size
4559 printf "cluster obj:\t\t%p\n", $mca->mca_addr
4560 if $mca->mca_uptr != 0
4561 set $peer_mca = (mcache_audit_t *)$mca->mca_uptr
4562 printf "paired mbuf obj:\t%p (mca %p)\n", \
4563 $peer_mca->mca_addr, $peer_mca
4566 printf "recent transaction for this buffer (thread %p):\n", \
4569 while $cnt < $mca->mca_depth
4570 set $kgm_pc = $mca->mca_stack[$cnt]
4571 printf "%4d: ", $cnt + 1
4576 if $mca->mca_pdepth > 0
4577 printf "previous transaction for this buffer (thread %p):\n", \
4581 while $cnt < $mca->mca_pdepth
4582 set $kgm_pc = $mca->mca_pstack[$cnt]
4583 printf "%4d: ", $cnt + 1
4591 document mbuf_showmca
4592 Syntax: (gdb) mbuf_showmca <addr>
4593 | Given an mbuf/cluster buffer audit structure address, print the audit
4594 | records including the stack trace of the last buffer transaction.
4597 set $MCF_NOCPUCACHE = 0x10
4600 set $head = (mcache_t *)mcache_head
4604 printf "cache cache cache buf buf backing (# of retries) bufs\n"
4605 printf "name state addr size align zone wait nowait failed incache\n"
4606 printf "------------------------- -------- ------------------ ------ ----- ------------------ -------------------------- --------\n"
4608 printf "cache cache cache buf buf backing (# of retries) bufs\n"
4609 printf "name state addr size align zone wait nowait failed incache\n"
4610 printf "------------------------- -------- ---------- ------ ----- ---------- -------------------------- --------\n"
4613 set $bktsize = $mc->mc_cpu.cc_bktsize
4614 printf "%-25s ", $mc->mc_name
4615 if ($mc->mc_flags & $MCF_NOCPUCACHE)
4618 if $mc->mc_purge_cnt > 0
4628 printf " %p %6d %5d ",$mc, \
4629 $mc->mc_bufsize, $mc->mc_align
4630 if $mc->mc_slab_zone != 0
4631 printf "%p", $mc->mc_slab_zone
4640 set $tot += $mc->mc_full.bl_total * $bktsize
4641 set $ccp = (mcache_cpu_t *)$mc->mc_cpu
4644 if $ccp->cc_objs > 0
4645 set $tot += $ccp->cc_objs
4647 if $ccp->cc_pobjs > 0
4648 set $tot += $ccp->cc_pobjs
4653 printf " %8d %8d %8d %8d", $mc->mc_wretry_cnt, \
4654 $mc->mc_nwretry_cnt, $mc->mc_nwfail_cnt, $tot
4656 set $mc = (mcache_t *)$mc->mc_list.le_next
4660 document mcache_stat
4661 Syntax: (gdb) mcache_stat
4662 | Print all mcaches in the system.
4665 define mcache_showzone
4666 set $mc = (mcache_t *)$arg0
4667 if $mc->mc_slab_zone != 0
4668 printf "%p", $mc->mc_slab_zone
4673 document mcache_showzone
4674 Syntax: (gdb) mcache_showzone <mcache_addr>
4675 | Print the type of backend (custom or zone) of a mcache.
4678 define mcache_walkobj
4679 set $p = (mcache_obj_t *)$arg0
4683 printf "%4d: %p\n", $cnt, $p,
4684 set $p = $p->obj_next
4689 document mcache_walkobj
4690 Syntax: (gdb) mcache_walkobj <addr>
4691 | Given a mcache object address, walk its obj_next pointer
4694 define mcache_showcache
4695 set $cp = (mcache_t *)$arg0
4696 set $ccp = (mcache_cpu_t *)$cp->mc_cpu
4697 set $bktsize = $cp->mc_cpu.cc_bktsize
4700 printf "Showing cache '%s':\n\n", $cp->mc_name
4701 printf " CPU cc_objs cc_pobjs total\n"
4702 printf "---- -------- -------- --------\n"
4704 set $objs = $ccp->cc_objs
4708 set $pobjs = $ccp->cc_pobjs
4712 set $tot_cpu = $objs + $pobjs
4713 set $tot += $tot_cpu
4714 printf "%4d %8d %8d %8d\n", $cnt, $objs, $pobjs, $tot_cpu
4718 printf " ========\n"
4719 printf " %8d\n", $tot
4721 set $tot += $cp->mc_full.bl_total * $bktsize
4722 printf "Total # of full buckets (%d objs/bkt):\t%-8d\n", \
4723 $bktsize, $cp->mc_full.bl_total
4724 printf "Total # of objects cached:\t\t%-8d\n", $tot
4727 document mcache_showcache
4728 | Display the number of objects in the cache
4731 set $NSLABSPMB = sizeof(mcl_slabg_t)/sizeof(mcl_slab_t)
4733 define mbuf_slabstbl
4736 printf "slot addr slabs range\n"
4737 printf "---- ---------- -----------------------\n"
4738 while $x < maxslabgrp
4739 set $slg = slabstbl[$x]
4744 printf "%p [%p-%p]\n", $slg, &$slg->slg_slab[0], \
4745 &$slg->slg_slab[$NSLABSPMB-1]
4751 document mbuf_slabstbl
4752 | Display the mbuf slabs table
4755 set $SLF_MAPPED=0x0001
4756 set $SLF_PARTIAL=0x0002
4757 set $SLF_DETACHED=0x0004
4760 set $slg = (mcl_slabg_t *)$arg0
4764 printf "slot addr next base C R N size flags\n"
4765 printf "---- ------------------ ------------------ ------------------ -- -- -- ------ -----\n"
4767 printf "slot addr next base C R N size flags\n"
4768 printf "---- ---------- ---------- ---------- -- -- -- ------ -----\n"
4770 while $x < $NSLABSPMB
4771 set $sl = &$slg->slg_slab[$x]
4772 printf "%3d: %p %p %p %2d %2d %2d %6d 0x%04x ", \
4773 $x + 1, $sl, $sl->sl_next, $sl->sl_base, $sl->sl_class, \
4774 $sl->sl_refcnt, $sl->sl_chunks, $sl->sl_len, \
4776 if $sl->sl_flags != 0
4778 if $sl->sl_flags & $SLF_MAPPED
4781 if $sl->sl_flags & $SLF_PARTIAL
4784 if $sl->sl_flags & $SLF_DETACHED
4795 | Display all mbuf slabs in the group
4801 printf "class total cached uncached inuse failed waiter notified purge\n"
4802 printf "name objs objs objs / slabs objs alloc count count count count\n"
4803 printf "---------------- -------- -------- ------------------- -------- ---------------- -------- -------- --------\n"
4804 while $x < (sizeof(mbuf_table) / sizeof(mbuf_table[0]))
4805 set $mbt = mbuf_table[$x]
4806 set $mcs = (mb_class_stat_t *)mbuf_table[$x].mtbl_stats
4808 set $mc = $mbt->mtbl_cache
4809 set $bktsize = $mc->mc_cpu.cc_bktsize
4810 set $tot += $mc->mc_full.bl_total * $bktsize
4811 set $ccp = (mcache_cpu_t *)$mc->mc_cpu
4814 if $ccp->cc_objs > 0
4815 set $tot += $ccp->cc_objs
4817 if $ccp->cc_pobjs > 0
4818 set $tot += $ccp->cc_pobjs
4824 printf "%-16s %8d %8d %8d / %-8d %8d %16llu %8d %8llu %8llu", \
4825 $mcs->mbcl_cname, $mcs->mbcl_total, $tot, \
4826 $mcs->mbcl_infree, $mcs->mbcl_slab_cnt, \
4827 ($mcs->mbcl_total - $tot - $mcs->mbcl_infree), \
4828 $mcs->mbcl_fail_cnt, $mc->mc_waiter_cnt, \
4829 $mcs->mbcl_notified, $mcs->mbcl_purge_cnt
4836 | Print extended mbuf allocator statistics.
4840 set $MB_COMP_INUSE = 0x2
4841 set $MB_SCVALID = 0x4
4843 set $MCLBYTES = 2048
4846 set $M16KCLBYTES = 16384
4848 define mbuf_mca_ctype
4849 set $mca = (mcache_audit_t *)$arg0
4851 set $cp = $mca->mca_cache
4852 set $class = (unsigned int)$cp->mc_private
4853 set $csize = mbuf_table[$class].mtbl_stats->mbcl_size
4863 if !$done && $csize == $MCLBYTES
4865 printf "CL (2K cluster) "
4871 if !$done && $csize == $NBPG
4873 printf "BCL (4K cluster) "
4879 if !$done && $csize == $M16KCLBYTES
4881 printf "JCL (16K cluster) "
4887 if !$done && $csize == ($MSIZE+$MCLBYTES)
4888 if $mca->mca_uflags & $MB_SCVALID
4892 printf "(paired mbuf, 2K cluster)"
4897 printf "(unpaired mbuf, 2K cluster) "
4904 printf "(paired 2K cluster, mbuf) "
4909 printf "(paired 2K cluster, mbuf) "
4915 if !$done && $csize == ($MSIZE+$NBPG)
4916 if $mca->mca_uflags & $MB_SCVALID
4920 printf "(paired mbuf, 4K cluster) "
4925 printf "(unpaired mbuf, 4K cluster) "
4932 printf "(paired 4K cluster, mbuf) "
4937 printf "(unpaired 4K cluster, mbuf) "
4943 if !$done && $csize == ($MSIZE+$M16KCLBYTES)
4944 if $mca->mca_uflags & $MB_SCVALID
4948 printf "(paired mbuf, 16K cluster) "
4953 printf "(unpaired mbuf, 16K cluster) "
4960 printf "(paired 16K cluster, mbuf) "
4965 printf "(unpaired 16K cluster, mbuf) "
4972 printf "unknown: %s ", $cp->mc_name
4976 document mbuf_mca_ctype
4977 | This is a helper macro for mbuf_show{active,inactive,all} that prints
4978 | out the mbuf object type represented by a given mcache audit structure.
4981 define mbuf_showactive
4983 mbuf_walkallslabs 1 0
4985 mbuf_walkallslabs 1 0 $arg0
4989 document mbuf_showactive
4990 Syntax: (gdb) mbuf_showactive
4991 | Walk the mbuf objects pool and print only the active ones; this
4992 | requires mbuf debugging to be turned on, by setting the appropriate flags
4993 | to the "mbuf_debug" boot-args parameter. Active objects are those that
4994 | are outstanding (have not returned to the mbuf slab layer) and in use
4995 | by the client (have not been freed).
4998 define mbuf_showinactive
4999 mbuf_walkallslabs 0 1
5002 document mbuf_showinactive
5003 Syntax: (gdb) mbuf_showinactive
5004 | Walk the mbuf objects pool and print only the inactive ones; this
5005 | requires mbuf debugging to be turned on, by setting the appropriate flags
5006 | to the "mbuf_debug" boot-args parameter. Inactive objects are those that
5007 | are outstanding (have not returned to the mbuf slab layer) but have been
5008 | freed by the client, i.e. they still reside in the mcache layer ready to
5009 | be used for subsequent allocation requests.
5013 mbuf_walkallslabs 1 1
5016 document mbuf_showall
5017 Syntax: (gdb) mbuf_showall
5018 | Walk the mbuf objects pool and print them all; this requires
5019 | mbuf debugging to be turned on, by setting the appropriate flags to the
5020 | "mbuf_debug" boot-args parameter.
5026 define mbuf_walkallslabs
5030 set $show_tr = $arg2
5040 if $show_a && !$show_f
5041 printf "Searching only for active "
5043 if !$show_a && $show_f
5044 printf "Searching only for inactive "
5046 if $show_a && $show_f
5047 printf "Displaying all "
5049 printf "objects; this may take a while ...)\n\n"
5052 printf " slab mca obj allocation\n"
5053 printf "slot idx address address address type state\n"
5054 printf "---- ---- ------------------ ------------------ ------------------ ----- -----------\n"
5056 printf " slab mca obj allocation\n"
5057 printf "slot idx address address address type state\n"
5058 printf "---- ---- ---------- ---------- ---------- ----- -----------\n"
5062 set $slg = slabstbl[$x]
5065 while $y < $NSLABSPMB && $stop == 0
5066 set $sl = &$slg->slg_slab[$y]
5067 set $base = (char *)$sl->sl_base
5068 set $ix = ($base - (char *)mbutl) >> 11
5069 set $clbase = ((union mcluster *)(mbutl + $ix))
5070 set $mclidx = ($base - (char *)$clbase) >> 8
5071 set $mca = mclaudit[$ix].cl_audit[$mclidx]
5074 while $mca != 0 && $mca->mca_addr != 0
5076 if $mca->mca_uflags & ($MB_INUSE|$MB_COMP_INUSE)
5077 set $total_a = $total_a + 1
5078 set $printmca = $show_a
5080 set $total_f = $total_f + 1
5081 set $printmca = $show_f
5086 printf "%4d %4d %p ", $x, $y, $sl
5095 printf "%p %p ", $mca, $mca->mca_addr
5096 mbuf_mca_ctype $mca 0
5097 if $mca->mca_uflags & ($MB_INUSE|$MB_COMP_INUSE)
5106 set $total = $total + 1
5109 printf "recent transaction for this buffer (thread %p):\n", \
5112 while $cnt < $mca->mca_depth
5113 set $kgm_pc = $mca->mca_stack[$cnt]
5114 printf "%4d: ", $cnt + 1
5122 set $mca = $mca->mca_next
5125 if $slg->slg_slab[$y].sl_base == 0
5131 if $total && $show_a && $show_f
5132 printf "\ntotal objects:\t%d\n", $total
5133 printf "active/unfreed:\t%d\n", $total_a
5134 printf "freed/in_cache:\t%d\n", $total_f
5138 document mbuf_walkallslabs
5139 | Walk the mbuf objects pool; this requires mbuf debugging to be
5140 | turned on, by setting the appropriate flags to the "mbuf_debug" boot-args
5141 | parameter. This is a backend routine for mbuf_show{active,inactive,all}.
5145 set $RTF_GATEWAY = 0x2
5147 set $RTF_REJECT = 0x8
5148 set $RTF_DYNAMIC = 0x10
5149 set $RTF_MODIFIED = 0x20
5150 set $RTF_DONE = 0x40
5151 set $RTF_DELCLONE = 0x80
5152 set $RTF_CLONING = 0x100
5153 set $RTF_XRESOLVE = 0x200
5154 set $RTF_LLINFO = 0x400
5155 set $RTF_STATIC = 0x800
5156 set $RTF_BLACKHOLE = 0x1000
5157 set $RTF_PROTO2 = 0x4000
5158 set $RTF_PROTO1 = 0x8000
5159 set $RTF_PRCLONING = 0x10000
5160 set $RTF_WASCLONED = 0x20000
5161 set $RTF_PROTO3 = 0x40000
5162 set $RTF_PINNED = 0x100000
5163 set $RTF_LOCAL = 0x200000
5164 set $RTF_BROADCAST = 0x400000
5165 set $RTF_MULTICAST = 0x800000
5166 set $RTF_IFSCOPE = 0x1000000
5167 set $RTF_CONDEMNED = 0x2000000
5173 define rtentry_prdetails
5174 set $rt = (struct rtentry *)$arg0
5177 set $dst = (struct sockaddr *)$rt->rt_nodes->rn_u.rn_leaf.rn_Key
5178 if $dst->sa_family == $AF_INET
5179 showsockaddr_in $dst
5182 if $dst->sa_family == $AF_INET6
5183 showsockaddr_in6 $dst
5187 if $dst->sa_family == $AF_LINK
5188 showsockaddr_dl $dst
5191 showsockaddr_unspec $dst
5196 set $dst = (struct sockaddr *)$rt->rt_gateway
5197 if $dst->sa_family == $AF_INET
5198 showsockaddr_in $dst
5201 if $dst->sa_family == $AF_INET6
5203 showsockaddr_in6 $dst
5206 if $dst->sa_family == $AF_LINK
5207 showsockaddr_dl $dst
5214 showsockaddr_unspec $dst
5219 if $rt->rt_flags & $RTF_WASCLONED
5221 printf "%18p ", $rt->rt_parent
5223 printf "%10p ", $rt->rt_parent
5233 printf "%6u %8u ", $rt->rt_refcnt, $rt->rt_rmx.rmx_pksent
5235 if $rt->rt_flags & $RTF_UP
5238 if $rt->rt_flags & $RTF_GATEWAY
5241 if $rt->rt_flags & $RTF_HOST
5244 if $rt->rt_flags & $RTF_REJECT
5247 if $rt->rt_flags & $RTF_DYNAMIC
5250 if $rt->rt_flags & $RTF_MODIFIED
5253 if $rt->rt_flags & $RTF_CLONING
5256 if $rt->rt_flags & $RTF_PRCLONING
5259 if $rt->rt_flags & $RTF_LLINFO
5262 if $rt->rt_flags & $RTF_STATIC
5265 if $rt->rt_flags & $RTF_PROTO1
5268 if $rt->rt_flags & $RTF_PROTO2
5271 if $rt->rt_flags & $RTF_PROTO3
5274 if $rt->rt_flags & $RTF_WASCLONED
5277 if $rt->rt_flags & $RTF_BROADCAST
5280 if $rt->rt_flags & $RTF_MULTICAST
5283 if $rt->rt_flags & $RTF_XRESOLVE
5286 if $rt->rt_flags & $RTF_BLACKHOLE
5289 if $rt->rt_flags & $RTF_IFSCOPE
5293 printf "/%s%d", $rt->rt_ifp->if_name, $rt->rt_ifp->if_unit
5298 define _rttable_dump
5300 set $rn = (struct radix_node *)$rnh->rnh_treetop
5301 set $rnh_cnt = $rnh->rnh_cnt
5303 while $rn->rn_bit >= 0
5304 set $rn = $rn->rn_u.rn_node.rn_L
5308 set $base = (struct radix_node *)$rn
5309 while ($rn->rn_parent->rn_u.rn_node.rn_R == $rn) && ($rn->rn_flags & $RNF_ROOT) == 0
5310 set $rn = $rn->rn_parent
5312 set $rn = $rn->rn_parent->rn_u.rn_node.rn_R
5313 while $rn->rn_bit >= 0
5314 set $rn = $rn->rn_u.rn_node.rn_L
5319 set $base = $rn->rn_u.rn_leaf.rn_Dupedkey
5320 if ($rn->rn_flags & $RNF_ROOT) == 0
5322 set $rt = (struct rtentry *)$rn
5329 rtentry_prdetails $rt
5335 if ($rn->rn_flags & $RNF_ROOT) != 0
5344 printf " rtentry dst gw parent Refs Use flags/if\n"
5345 printf " ----------------- --------------- ----------------- ------------------ ------ -------- -----------\n"
5347 printf " rtentry dst gw parent Refs Use flags/if\n"
5348 printf " --------- --------------- ----------------- ---------- ------ -------- -----------\n"
5350 _rttable_dump rt_tables[2]
5353 document show_rt_inet
5354 Syntax: (gdb) show_rt_inet
5355 | Show the entries of the IPv4 routing table.
5358 define show_rt_inet6
5360 printf " rtentry dst gw parent Refs Use flags/if\n"
5361 printf " ----------------- --------------------------------------- --------------------------------------- ------------------ ------ -------- -----------\n"
5363 printf " rtentry dst gw parent Refs Use flags/if\n"
5364 printf " --------- --------------------------------------- --------------------------------------- ---------- ------ -------- -----------\n"
5366 _rttable_dump rt_tables[30]
5369 document show_rt_inet6
5370 Syntax: (gdb) show_rt_inet6
5371 | Show the entries of the IPv6 routing table.
5374 define rtentry_trash
5375 set $rtd = (struct rtentry_dbg *)rttrash_head.tqh_first
5380 printf " rtentry ref hold rele dst gw parent flags/if\n"
5381 printf " ----------------- --- ------ ------ --------------- ----- ------------------ -----------\n"
5383 printf " rtentry ref hold rele dst gw parent flags/if\n"
5384 printf " --------- --- ------ ------ --------------- ----- ---------- -----------\n"
5387 printf "%4d: %p %3d %6d %6d ", $cnt + 1, $rtd, \
5388 $rtd->rtd_refhold_cnt - $rtd->rtd_refrele_cnt, \
5389 $rtd->rtd_refhold_cnt, $rtd->rtd_refrele_cnt
5390 rtentry_prdetails $rtd
5392 set $rtd = $rtd->rtd_trash_link.tqe_next
5397 document rtentry_trash
5398 Syntax: (gdb) rtentry_trash
5399 | Walk the list of trash route entries; this requires route entry
5400 | debugging to be turned on, by setting the appropriate flags to the
5401 | "rte_debug" boot-args parameter.
5404 set $CTRACE_STACK_SIZE = ctrace_stack_size
5405 set $CTRACE_HIST_SIZE = ctrace_hist_size
5407 define rtentry_showdbg
5408 set $rtd = (struct rtentry_dbg *)$arg0
5411 printf "Total holds:\t%d\n", $rtd->rtd_refhold_cnt
5412 printf "Total releases:\t%d\n", $rtd->rtd_refrele_cnt
5415 while $ix < $CTRACE_STACK_SIZE
5416 set $kgm_pc = $rtd->rtd_alloc.pc[$ix]
5419 printf "\nAlloc (thread %p):\n", \
5422 printf "%4d: ", $ix + 1
5429 while $ix < $CTRACE_STACK_SIZE
5430 set $kgm_pc = $rtd->rtd_free.pc[$ix]
5433 printf "\nFree: (thread %p)\n", \
5436 printf "%4d: ", $ix + 1
5442 while $cnt < $CTRACE_HIST_SIZE
5444 while $ix < $CTRACE_STACK_SIZE
5445 set $kgm_pc = $rtd->rtd_refhold[$cnt].pc[$ix]
5448 printf "\nHold [%d] (thread %p):\n", \
5449 $cnt, $rtd->rtd_refhold[$cnt].th
5451 printf "%4d: ", $ix + 1
5460 while $cnt < $CTRACE_HIST_SIZE
5462 while $ix < $CTRACE_STACK_SIZE
5463 set $kgm_pc = $rtd->rtd_refrele[$cnt].pc[$ix]
5466 printf "\nRelease [%d] (thread %p):\n",\
5467 $cnt, $rtd->rtd_refrele[$cnt].th
5469 printf "%4d: ", $ix + 1
5478 printf "\nTotal locks:\t%d\n", $rtd->rtd_lock_cnt
5479 printf "Total unlocks:\t%d\n", $rtd->rtd_unlock_cnt
5482 while $cnt < $CTRACE_HIST_SIZE
5484 while $ix < $CTRACE_STACK_SIZE
5485 set $kgm_pc = $rtd->rtd_lock[$cnt].pc[$ix]
5488 printf "\nLock [%d] (thread %p):\n",\
5489 $cnt, $rtd->rtd_lock[$cnt].th
5491 printf "%4d: ", $ix + 1
5500 while $cnt < $CTRACE_HIST_SIZE
5502 while $ix < $CTRACE_STACK_SIZE
5503 set $kgm_pc = $rtd->rtd_unlock[$cnt].pc[$ix]
5506 printf "\nUnlock [%d] (thread %p):\n",\
5507 $cnt, $rtd->rtd_unlock[$cnt].th
5509 printf "%4d: ", $ix + 1
5519 document rtentry_showdbg
5520 Syntax: (gdb) rtentry_showdbg <addr>
5521 | Given a route entry structure address, print the debug information
5522 | related to it. This requires route entry debugging to be turned
5523 | on, by setting the appropriate flags to the "rte_debug" boot-args
5527 define inifa_showdbg
5528 set $inifa = (struct in_ifaddr_dbg *)$arg0
5531 printf "Total holds:\t%d\n", $inifa->inifa_refhold_cnt
5532 printf "Total releases:\t%d\n", $inifa->inifa_refrele_cnt
5535 while $ix < $CTRACE_STACK_SIZE
5536 set $kgm_pc = $inifa->inifa_alloc.pc[$ix]
5539 printf "\nAlloc (thread %p):\n", \
5540 $inifa->inifa_alloc.th
5542 printf "%4d: ", $ix + 1
5549 while $ix < $CTRACE_STACK_SIZE
5550 set $kgm_pc = $inifa->inifa_free.pc[$ix]
5553 printf "\nFree: (thread %p)\n", \
5554 $inifa->inifa_free.th
5556 printf "%4d: ", $ix + 1
5562 while $cnt < $CTRACE_HIST_SIZE
5564 while $ix < $CTRACE_STACK_SIZE
5565 set $kgm_pc = $inifa->inifa_refhold[$cnt].pc[$ix]
5568 printf "\nHold [%d] (thread %p):\n", \
5569 $cnt, $inifa->inifa_refhold[$cnt].th
5571 printf "%4d: ", $ix + 1
5580 while $cnt < $CTRACE_HIST_SIZE
5582 while $ix < $CTRACE_STACK_SIZE
5583 set $kgm_pc = $inifa->inifa_refrele[$cnt].pc[$ix]
5586 printf "\nRelease [%d] (thread %p):\n",\
5587 $cnt, $inifa->inifa_refrele[$cnt].th
5589 printf "%4d: ", $ix + 1
5599 document inifa_showdbg
5600 Syntax: (gdb) inifa_showdbg <addr>
5601 | Given an IPv4 interface structure address, print the debug information
5602 | related to it. This requires interface address debugging to be turned
5603 | on, by setting the appropriate flags to the "ifa_debug" boot-args
5607 define in6ifa_showdbg
5608 set $in6ifa = (struct in6_ifaddr_dbg *)$arg0
5611 printf "Total holds:\t%d\n", $in6ifa->in6ifa_refhold_cnt
5612 printf "Total releases:\t%d\n", $in6ifa->in6ifa_refrele_cnt
5615 while $ix < $CTRACE_STACK_SIZE
5616 set $kgm_pc = $in6ifa->in6ifa_alloc.pc[$ix]
5619 printf "\nAlloc (thread %p):\n", \
5620 $in6ifa->in6ifa_alloc.th
5622 printf "%4d: ", $ix + 1
5629 while $ix < $CTRACE_STACK_SIZE
5630 set $kgm_pc = $in6ifa->in6ifa_free.pc[$ix]
5633 printf "\nFree: (thread %p)\n", \
5634 $in6ifa->in6ifa_free.th
5636 printf "%4d: ", $ix + 1
5642 while $cnt < $CTRACE_HIST_SIZE
5644 while $ix < $CTRACE_STACK_SIZE
5645 set $kgm_pc = $in6ifa->in6ifa_refhold[$cnt].pc[$ix]
5648 printf "\nHold [%d] (thread %p):\n", \
5649 $cnt, $in6ifa->in6ifa_refhold[$cnt].th
5651 printf "%4d: ", $ix + 1
5660 while $cnt < $CTRACE_HIST_SIZE
5662 while $ix < $CTRACE_STACK_SIZE
5663 set $kgm_pc = $in6ifa->in6ifa_refrele[$cnt].pc[$ix]
5666 printf "\nRelease [%d] (thread %p):\n",\
5667 $cnt, $in6ifa->in6ifa_refrele[$cnt].th
5669 printf "%4d: ", $ix + 1
5679 document in6ifa_showdbg
5680 Syntax: (gdb) in6ifa_showdbg <addr>
5681 | Given an IPv6 interface structure address, print the debug information
5682 | related to it. This requires interface address debugging to be turned
5683 | on, by setting the appropriate flags to the "ifa_debug" boot-args
5688 # print all OSMalloc stats
5691 set $kgm_tagp = (OSMallocTag)$arg0
5692 printf "0x%08x: ", $kgm_tagp
5693 printf "%8d ",$kgm_tagp->OSMT_refcnt
5694 printf "%8x ",$kgm_tagp->OSMT_state
5695 printf "%8x ",$kgm_tagp->OSMT_attr
5696 printf "%s ",$kgm_tagp->OSMT_name
5702 printf "TAG COUNT STATE ATTR NAME\n"
5703 set $kgm_tagheadp = (OSMallocTag)&OSMalloc_tag_list
5704 set $kgm_tagptr = (OSMallocTag )($kgm_tagheadp->OSMT_link.next)
5705 while $kgm_tagptr != $kgm_tagheadp
5706 ostag_print $kgm_tagptr
5707 set $kgm_tagptr = (OSMallocTag)$kgm_tagptr->OSMT_link.next
5711 document showosmalloc
5712 Syntax: (gdb) showosmalloc
5713 | Print the outstanding allocation count by OSMallocTags.
5718 if msgbufp->msg_bufc[msgbufp->msg_bufx] == 0
5719 # The buffer hasn't wrapped, so take the easy (and fast!) path
5720 printf "%s", msgbufp->msg_bufc
5722 set $kgm_msgbuf = *msgbufp
5723 set $kgm_syslog_bufsize = $kgm_msgbuf.msg_size
5724 set $kgm_syslog_bufend = $kgm_msgbuf.msg_bufx
5725 if $kgm_syslog_bufend >= $kgm_syslog_bufsize
5726 set $kgm_syslog_bufend = 0
5729 # print older messages from msg_bufx to end of buffer
5730 set $kgm_i = $kgm_syslog_bufend
5731 while $kgm_i < $kgm_syslog_bufsize
5732 set $kgm_syslog_char = $kgm_msgbuf.msg_bufc[$kgm_i]
5733 if $kgm_syslog_char == 0
5735 set $kgm_i = $kgm_syslog_bufsize
5737 printf "%c", $kgm_syslog_char
5739 set $kgm_i = $kgm_i + 1
5742 # print newer messages from start of buffer to msg_bufx
5744 while $kgm_i < $kgm_syslog_bufend
5745 set $kgm_syslog_char = $kgm_msgbuf.msg_bufc[$kgm_i]
5746 printf "%c", $kgm_syslog_char
5747 set $kgm_i = $kgm_i + 1
5754 | Display the kernel's printf ring buffer
5759 set $kgm_addr = (unsigned char *)$arg0
5760 set $kgm_len = $arg1
5766 printf "%02x ", *($kgm_addr+$kgm_i)
5772 set $kgm_temp = *($kgm_addr+$kgm_i)
5773 if $kgm_temp < 32 || $kgm_temp >= 127
5776 printf "%c", $kgm_temp
5786 | Show the contents of memory as a hex/ASCII dump
5787 | The following is the syntax:
5788 | (gdb) hexdump <address> <length>
5792 define printcolonhex
5797 while ($li < $count)
5799 printf "%02x", (u_char)$addr[$li]
5802 printf ":%02x", (u_char)$addr[$li]
5809 define showsockaddr_dl
5810 set $sdl = (struct sockaddr_dl *)$arg0
5814 if $sdl->sdl_nlen == 0 && $sdl->sdl_alen == 0 && $sdl->sdl_slen == 0
5815 printf "link#%3d ", $sdl->sdl_index
5817 set $addr = $sdl->sdl_data + $sdl->sdl_nlen
5818 set $count = $sdl->sdl_alen
5819 printcolonhex $addr $count
5824 define showsockaddr_unspec
5825 set $sockaddr = (struct sockaddr *)$arg0
5826 set $addr = $sockaddr->sa_data
5827 set $count = $sockaddr->sa_len - 2
5828 printcolonhex $addr $count
5831 define showsockaddr_at
5832 set $sockaddr = (struct sockaddr *)$arg0
5833 set $addr = $sockaddr->sa_data
5834 set $count = $sockaddr->sa_len - 2
5835 printcolonhex $addr $count
5838 define showsockaddr_in
5839 set $sin = (struct sockaddr_in *)$arg0
5840 set $sa_bytes = (unsigned char *)&($sin->sin_addr)
5841 printf "%3u.%03u.%03u.%03u", $sa_bytes[0], $sa_bytes[1], $sa_bytes[2], $sa_bytes[3]
5844 define showsockaddr_in6
5845 set $sin6 = (struct sockaddr_in6 *)$arg0
5846 set $sa_bytes = $sin6->sin6_addr.__u6_addr.__u6_addr8
5847 printf "%2x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x", \
5848 $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]
5851 define showsockaddr_un
5852 set $sun = (struct sockaddr_un *)$arg0
5856 if $sun->sun_path[0] == 0
5859 printf "%s", $sun->sun_path
5864 define showifmultiaddrs
5865 set $ifp = (struct ifnet *)$arg0
5866 set $if_multi = (struct ifmultiaddr *)$ifp->if_multiaddrs->lh_first
5867 set $mymulti = $if_multi
5869 while ($mymulti != 0)
5870 printf "%2d. ", $myi
5871 set $sa_family = $mymulti->ifma_addr.sa_family
5872 if ($sa_family == 2)
5873 if ($mymulti->ifma_ll != 0)
5874 showsockaddr_dl $mymulti->ifma_ll->ifma_addr
5877 showsockaddr_in $mymulti->ifma_addr
5879 if ($sa_family == 30)
5880 if ($mymulti->ifma_ll != 0)
5881 showsockaddr_dl $mymulti->ifma_ll->ifma_addr
5884 showsockaddr_in6 $mymulti->ifma_addr
5886 if ($sa_family == 18)
5887 showsockaddr_dl $mymulti->ifma_addr
5889 if ($sa_family == 0)
5890 showsockaddr_unspec $mymulti->ifma_addr 6
5892 printf " [%d]", $mymulti->ifma_refcount
5894 set $mymulti = $mymulti->ifma_link.le_next
5899 document showifmultiaddrs
5900 Syntax showifmultiaddrs <ifp>
5901 | show the (struct ifnet).if_multiaddrs list of multicast addresses for the given ifp
5905 set $mysock = (struct sockaddr *)$arg0
5906 set $showsockaddr_handled = 0
5910 if ($mysock->sa_family == 0)
5912 showsockaddr_unspec $mysock
5913 set $showsockaddr_handled = 1
5915 if ($mysock->sa_family == 1)
5917 showsockaddr_un $mysock
5918 set $showsockaddr_handled = 1
5920 if ($mysock->sa_family == 2)
5922 showsockaddr_in $mysock
5923 set $showsockaddr_handled = 1
5925 if ($mysock->sa_family == 30)
5927 showsockaddr_in6 $mysock
5928 set $showsockaddr_handled = 1
5930 if ($mysock->sa_family == 18)
5932 showsockaddr_dl $mysock
5933 set $showsockaddr_handled = 1
5935 if ($mysock->sa_family == 16)
5937 showsockaddr_at $mysock
5938 set $showsockaddr_handled = 1
5940 if ($showsockaddr_handled == 0)
5941 printf "FAM %d ", $mysock->sa_family
5942 set $addr = $mysock->sa_data
5943 set $count = $mysock->sa_len
5944 printcolonhex $addr $count
5950 set $flags = (u_short)$arg0
5982 printf "POINTTOPOINT"
5984 # if ($flags & 0x20)
5990 # printf "NOTRAILERS"
6040 if ($flags & 0x1000)
6048 if ($flags & 0x2000)
6056 if ($flags & 0x4000)
6062 printf "LINK2-ALTPHYS"
6064 if ($flags & 0x8000)
6076 set $ifp = (struct ifnet *)$arg0
6077 set $myifaddr = (struct ifaddr *)$ifp->if_addrhead->tqh_first
6079 while ($myifaddr != 0)
6080 printf "\t%d. ", $myi
6081 showsockaddr $myifaddr->ifa_addr
6082 printf " [%d]\n", $myifaddr->ifa_refcnt
6083 set $myifaddr = $myifaddr->ifa_link->tqe_next
6088 document showifaddrs
6089 Syntax: showifaddrs <ifp>
6090 | show the (struct ifnet).if_addrhead list of addresses for the given ifp
6094 set $ifconfig_all = 0
6096 set $ifconfig_all = 1
6098 set $ifp = (struct ifnet *)(ifnet->tqh_first)
6100 printf "%s%d: flags=%hx", $ifp->if_name, $ifp->if_unit, (u_short)$ifp->if_flags
6101 showifflags $ifp->if_flags
6102 printf " index %d", $ifp->if_index
6103 printf " mtu %d\n", $ifp->if_data.ifi_mtu
6104 printf "\t(struct ifnet *)"
6107 if ($ifconfig_all == 1)
6110 set $ifp = $ifp->if_link->tqe_next
6114 Syntax: (gdb) ifconfig
6115 | display ifconfig-like output, and print the (struct ifnet *) pointers for further inspection
6118 define _show_unix_domain_socket
6119 set $so = (struct socket *)$arg0
6120 set $pcb = (struct unpcb *)$so->so_pcb
6122 printf "unpcb: (null) "
6124 printf "unpcb: %p ", $pcb
6125 printf "unp_vnode: %p ", $pcb->unp_vnode
6126 printf "unp_conn: %p ", $pcb->unp_conn
6128 showsockaddr_un $pcb->unp_addr
6132 define _show_in_port
6133 set $str = (unsigned char *)$arg0
6134 set $port = *(unsigned short *)$arg0
6136 if (((($port & 0xff00) >> 8) == $str[0])) && ((($port & 0x00ff) == $str[1]))
6137 #printf "big endian "
6138 printf ":%d ", $port
6140 #printf "little endian "
6141 printf ":%d ", (($port & 0xff00) >> 8) | (($port & 0x00ff) << 8)
6145 define _show_in_addr_4in6
6146 set $ia = (unsigned char *)$arg0
6148 printf "%3u.%03u.%03u.%03u", $ia[0], $ia[1], $ia[2], $ia[3]
6152 define _show_in6_addr
6153 set $ia = (unsigned char *)$arg0
6155 printf "%2x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x", \
6156 $ia[0], $ia[1], $ia[2], $ia[3], $ia[4], $ia[5], $ia[6], $ia[7], \
6157 $ia[8], $ia[9], $ia[10], $ia[11], $ia[12], $ia[13], $ia[14], $ia[15]
6161 define _showtcpstate
6162 set $tp = (struct tcpcb *)$arg0
6164 if $tp->t_state == 0
6167 if $tp->t_state == 1
6170 if $tp->t_state == 2
6173 if $tp->t_state == 3
6176 if $tp->t_state == 4
6177 printf "ESTABLISHED "
6179 if $tp->t_state == 5
6180 printf "CLOSE_WAIT "
6182 if $tp->t_state == 6
6183 printf "FIN_WAIT_1 "
6185 if $tp->t_state == 7
6188 if $tp->t_state == 8
6191 if $tp->t_state == 9
6192 printf "FIN_WAIT_2 "
6194 if $tp->t_state == 10
6200 define _showsockprotocol
6201 set $so = (struct socket *)$arg0
6202 set $inpcb = (struct inpcb *)$so->so_pcb
6204 if $so->so_proto->pr_protocol == 6
6206 _showtcpstate $inpcb->inp_ppcb
6208 if $so->so_proto->pr_protocol == 17
6211 if $so->so_proto->pr_protocol == 1
6214 if $so->so_proto->pr_protocol == 254
6217 if $so->so_proto->pr_protocol == 255
6222 define _show_ipv4_socket
6223 set $so = (struct socket *)$arg0
6224 set $inpcb = (struct inpcb *)$so->so_pcb
6226 printf "inpcb: (null) "
6228 printf "inpcb: %p ", $inpcb
6230 _showsockprotocol $so
6232 _show_in_addr_4in6 &$inpcb->inp_dependladdr.inp46_local
6233 _show_in_port &$inpcb->inp_lport
6235 _show_in_addr_4in6 &$inpcb->inp_dependfaddr.inp46_foreign
6236 _show_in_port &$inpcb->inp_fport
6240 define _show_ipv6_socket
6241 set $so = (struct socket *)$arg0
6242 set $pcb = (struct inpcb *)$so->so_pcb
6244 printf "inpcb: (null) "
6246 printf "inpcb: %p ", $pcb
6248 _showsockprotocol $so
6250 _show_in6_addr &$pcb->inp_dependladdr.inp6_local
6251 _show_in_port &$pcb->inp_lport
6253 _show_in6_addr &$pcb->inp_dependfaddr.inp6_foreign
6254 _show_in_port &$pcb->inp_fport
6260 set $so = (struct socket *)$arg0
6262 printf "so: (null) "
6264 printf "so: %p ", $so
6265 if $so && $so->so_proto && $so->so_proto->pr_domain
6266 set $domain = (struct domain *) $so->so_proto->pr_domain
6268 printf "%s ", $domain->dom_name
6269 if $domain->dom_family == 1
6270 _show_unix_domain_socket $so
6272 if $domain->dom_family == 2
6273 _show_ipv4_socket $so
6275 if $domain->dom_family == 30
6276 _show_ipv6_socket $so
6283 Syntax: (gdb) showsocket <socket_address>
6284 | Routine to print out a socket
6287 define showprocsockets
6288 set $pp = (struct proc *)$arg0
6289 set $fdp = (struct filedesc *)$pp->p_fd
6292 set $fpp = (struct fileproc **)($fdp->fd_ofiles)
6293 set $fpo = (char)($fdp->fd_ofileflags[0])
6294 while $count < $fdp->fd_nfiles
6296 set $fg =(struct fileglob *)((**$fpp)->f_fglob)
6297 if $fg && (($fg)->fg_type == 2)
6298 if $fdp->fd_ofileflags[$count] & 4
6303 printf "fd = %d ", $count
6305 showsocket $fg->fg_data
6312 set $count = $count + 1
6315 document showprocsockets
6316 Syntax: (gdb) showprocsockets <proc_address>
6317 | Routine to print out all the open fds
6318 | which are sockets in a process
6321 define showallprocsockets
6322 set $basep = (struct proc *)allproc->lh_first
6325 printf "============================================ \n"
6328 set $pp = $pp->p_list.le_next
6331 document showallprocsockets
6332 Syntax: (gdb) showallprocsockets
6333 | Routine to print out all the open fds
6338 set $port = (unsigned short)$arg0
6339 set $port = (unsigned short)((($arg0 & 0xff00) >> 8) & 0xff)
6340 set $port |= (unsigned short)(($arg0 & 0xff) << 8)
6344 set $INPCB_STATE_INUSE=0x1
6345 set $INPCB_STATE_CACHED=0x2
6346 set $INPCB_STATE_DEAD=0x3
6348 set $INP_RECVOPTS=0x01
6349 set $INP_RECVRETOPTS=0x02
6350 set $INP_RECVDSTADDR=0x04
6351 set $INP_HDRINCL=0x08
6352 set $INP_HIGHPORT=0x10
6353 set $INP_LOWPORT=0x20
6354 set $INP_ANONPORT=0x40
6355 set $INP_RECVIF=0x80
6356 set $INP_MTUDISC=0x100
6357 set $INP_STRIPHDR=0x200
6358 set $INP_FAITH=0x400
6359 set $INP_INADDR_ANY=0x800
6360 set $INP_RECVTTL=0x1000
6361 set $INP_UDP_NOCKSUM=0x2000
6362 set $IN6P_IPV6_V6ONLY=0x008000
6363 set $IN6P_PKTINFO=0x010000
6364 set $IN6P_HOPLIMIT=0x020000
6365 set $IN6P_HOPOPTS=0x040000
6366 set $IN6P_DSTOPTS=0x080000
6367 set $IN6P_RTHDR=0x100000
6368 set $IN6P_RTHDRDSTOPTS=0x200000
6369 set $IN6P_AUTOFLOWLABEL=0x800000
6370 set $IN6P_BINDV6ONLY=0x10000000
6379 set $pcb = (struct inpcb *)$arg0
6383 printf "%10p ", $pcb
6385 if $arg1 == $IPPROTO_TCP
6388 if $arg1 == $IPPROTO_UDP
6391 printf "%2d.", $arg1
6394 if ($pcb->inp_vflag & $INP_IPV4)
6397 if ($pcb->inp_vflag & $INP_IPV6)
6401 if ($pcb->inp_vflag & $INP_IPV4)
6403 _show_in_addr &$pcb->inp_dependladdr.inp46_local.ia46_addr4
6405 _show_in6_addr &$pcb->inp_dependladdr.inp6_local
6408 _print_ntohs $pcb->inp_lport
6410 if ($pcb->inp_vflag & $INP_IPV4)
6412 _show_in_addr &($pcb->inp_dependfaddr.inp46_foreign.ia46_addr4)
6414 _show_in6_addr &($pcb->inp_dependfaddr.inp6_foreign)
6417 _print_ntohs $pcb->inp_fport
6420 if $arg1 == $IPPROTO_TCP
6421 _showtcpstate $pcb->inp_ppcb
6425 # set $phd = $pcb->inp_phd
6428 # _print_ntohs $phd->phd_port
6429 # set $phd = $phd->phd_hash.le_next
6432 if ($pcb->inp_flags & $INP_RECVOPTS)
6435 if ($pcb->inp_flags & $INP_RECVRETOPTS)
6436 printf "recvretopts "
6438 if ($pcb->inp_flags & $INP_RECVDSTADDR)
6439 printf "recvdstaddr "
6441 if ($pcb->inp_flags & $INP_HDRINCL)
6444 if ($pcb->inp_flags & $INP_HIGHPORT)
6447 if ($pcb->inp_flags & $INP_LOWPORT)
6450 if ($pcb->inp_flags & $INP_ANONPORT)
6453 if ($pcb->inp_flags & $INP_RECVIF)
6456 if ($pcb->inp_flags & $INP_MTUDISC)
6459 if ($pcb->inp_flags & $INP_STRIPHDR)
6462 if ($pcb->inp_flags & $INP_FAITH)
6465 if ($pcb->inp_flags & $INP_INADDR_ANY)
6466 printf "inaddr_any "
6468 if ($pcb->inp_flags & $INP_RECVTTL)
6471 if ($pcb->inp_flags & $INP_UDP_NOCKSUM)
6474 if ($pcb->inp_flags & $IN6P_IPV6_V6ONLY)
6477 if ($pcb->inp_flags & $IN6P_PKTINFO)
6480 if ($pcb->inp_flags & $IN6P_HOPLIMIT)
6483 if ($pcb->inp_flags & $IN6P_HOPOPTS)
6486 if ($pcb->inp_flags & $IN6P_DSTOPTS)
6489 if ($pcb->inp_flags & $IN6P_RTHDR)
6492 if ($pcb->inp_flags & $IN6P_RTHDRDSTOPTS)
6493 printf "rthdrdstopts "
6495 if ($pcb->inp_flags & $IN6P_AUTOFLOWLABEL)
6496 printf "autoflowlabel "
6498 if ($pcb->inp_flags & $IN6P_BINDV6ONLY)
6499 printf "bindv6only "
6501 set $so = (struct socket *)$pcb->inp_socket
6503 printf "[so=%p s=%ld r=%ld usecnt=%ld] ", $so, $so->so_snd.sb_cc, \
6504 $so->so_rcv.sb_cc, $so->so_usecount
6506 if ($pcb->inp_state == 0 || $pcb->inp_state == $INPCB_STATE_INUSE)
6509 if ($pcb->inp_state == $INPCB_STATE_CACHED)
6512 if ($pcb->inp_state == $INPCB_STATE_DEAD)
6515 printf "unknown (%d), ", $pcb->inp_state
6521 define _dump_inpcbport
6522 set $ppcb = (struct inpcbport *)$arg0
6523 printf "%p: lport ", $ppcb
6524 _print_ntohs $ppcb->phd_port
6529 define _dump_pcbinfo
6533 set $pcbi = (struct inpcbinfo *)$arg0
6534 printf "lastport %d lastlow %d lasthi %d\n", \
6535 $pcbi->lastport, $pcbi->lastlow, $pcbi->lasthi
6536 printf "active pcb count is %d\n", $pcbi->ipi_count
6537 set $hashsize = $pcbi->hashmask + 1
6538 printf "hash size is %d\n", $hashsize
6539 printf "hash base %p has the following inpcb(s):\n", $pcbi->hashbase
6541 printf "pcb prot source address port destination address port\n"
6542 printf "------------------ ---- --------------------------------------- ----- --------------------------------------- -----\n"
6544 printf "pcb prot source address port destination address port\n"
6545 printf "---------- ---- --------------------------------------- ----- --------------------------------------- -----\n"
6548 set $hashbase = $pcbi->hashbase
6549 set $head = *(uintptr_t *)$hashbase
6550 while $i < $hashsize
6552 set $pcb0 = (struct inpcb *)$head
6555 _dump_inpcb $pcb0 $arg1
6556 set $so = (struct socket *)$pcb->inp_socket
6558 set $snd_cc += $so->so_snd.sb_cc
6559 set $rcv_cc += $so-> so_rcv.sb_cc
6561 set $pcb0 = $pcb0->inp_hash.le_next
6567 set $head = *(uintptr_t *)$hashbase
6569 printf "total seen %ld snd_cc %ld rcv_cc %ld\n", $pcbseen, $snd_cc, $rcv_cc
6570 printf "port hash base is %p\n", $pcbi->porthashbase
6572 set $hashbase = $pcbi->porthashbase
6573 set $head = *(uintptr_t *)$hashbase
6574 while $i < $hashsize
6576 set $pcb0 = (struct inpcbport *)$head
6579 _dump_inpcbport $pcb0
6581 set $pcb0 = $pcb0->phd_hash.le_next
6586 set $head = *(uintptr_t *)$hashbase
6590 set $N_TIME_WAIT_SLOTS=128
6592 define show_tcp_timewaitslots
6599 set $slot = (int)$arg0
6602 printf "time wait slot size %d cur_tw_slot %ld\n", $N_TIME_WAIT_SLOTS, cur_tw_slot
6604 while $i < $N_TIME_WAIT_SLOTS
6606 set $head = (uintptr_t *)time_wait_slots[$i]
6607 if $i == $slot || $slot == -1
6609 set $pcb0 = (struct inpcb *)$head
6612 set $pcb0 = $pcb0->inp_list.le_next
6615 printf " slot %ld count %ld\n", $i, $perslot
6617 if $all || $i == $slot
6619 set $pcb0 = (struct inpcb *)$head
6622 _dump_inpcb $pcb0 $IPPROTO_TCP
6624 set $pcb0 = $pcb0->inp_list.le_next
6631 document show_tcp_timewaitslots
6632 Syntax: (gdb) show_tcp_timewaitslots
6633 | Print the list of TCP protocol control block in the TIMEWAIT state
6634 | Pass -1 to see the list of PCB for each slot
6635 | Pass a slot number to see information for that slot with the list of PCB
6638 define show_tcp_pcbinfo
6639 _dump_pcbinfo &tcbinfo $IPPROTO_TCP
6641 document show_tcp_pcbinfo
6642 Syntax: (gdb) show_tcp_pcbinfo
6643 | Print the list of TCP protocol control block information
6647 define show_udp_pcbinfo
6648 _dump_pcbinfo &udbinfo $IPPROTO_UDP
6650 document show_udp_pcbinfo
6651 Syntax: (gdb) show_udp_pcbinfo
6652 | Print the list of UDP protocol control block information
6657 while ($myi < bpf_dtab_size)
6658 if (bpf_dtab[$myi] != 0)
6659 printf "Address 0x%x, bd_next 0x%x\n", bpf_dtab[$myi], bpf_dtab[$myi]->bd_next
6660 print *bpf_dtab[$myi]
6666 define printvnodepathint_recur
6668 if ($arg0->v_flag & 0x000001) && ($arg0->v_mount != 0)
6669 if $arg0->v_mount->mnt_vnodecovered != 0
6670 printvnodepathint_recur $arg0->v_mount->mnt_vnodecovered $arg0->v_mount->mnt_vnodecovered->v_name
6673 printvnodepathint_recur $arg0->v_parent $arg0->v_parent->v_name
6679 define showvnodepath
6680 set $vp = (struct vnode *)$arg0
6682 if ($vp->v_flag & 0x000001) && ($vp->v_mount != 0) && ($vp->v_mount->mnt_flag & 0x00004000)
6685 printvnodepathint_recur $vp $vp->v_name
6691 document showvnodepath
6692 Syntax: (gdb) showvnodepath <vnode>
6693 | Prints the path for a vnode
6701 printf " mnt_devvp "
6703 printf " typename mountpoint\n"
6704 set $kgm_vol = (mount_t) mountlist.tqh_first
6708 showptr $kgm_vol->mnt_data
6710 showptr $kgm_vol->mnt_devvp
6712 if ($kgm_vol->mnt_vtable->vfc_name[0] == 'h') && \
6713 ($kgm_vol->mnt_vtable->vfc_name[1] == 'f') && \
6714 ($kgm_vol->mnt_vtable->vfc_name[2] == 's') && \
6715 ($kgm_vol->mnt_vtable->vfc_name[3] == '\0')
6716 set $kgm_hfsmount = \
6717 (struct hfsmount *) $kgm_vol->mnt_data
6718 if $kgm_hfsmount->hfs_freezing_proc != 0
6719 printf "FROZEN hfs "
6724 printf "%-10s ", $kgm_vol->mnt_vtable->vfc_name
6726 printf "%s\n", $kgm_vol->mnt_vfsstat.f_mntonname
6728 set $kgm_vol = (mount_t) $kgm_vol->mnt_list.tqe_next
6732 document showallvols
6733 Syntax: (gdb) showallvols
6734 | Display a summary of mounted volumes
6737 define showvnodeheader
6740 printf " usecount iocount v_data "
6742 printf " vtype parent "
6748 set $kgm_vnode = (vnode_t) $arg0
6750 printf " %8d ", $kgm_vnode->v_usecount
6751 printf "%7d ", $kgm_vnode->v_iocount
6752 # print information about clean/dirty blocks?
6753 showptr $kgm_vnode->v_data
6755 # print the vtype, using the enum tag
6756 set $kgm_vtype = $kgm_vnode->v_type
6757 if $kgm_vtype == VNON
6760 if $kgm_vtype == VREG
6763 if $kgm_vtype == VDIR
6766 if $kgm_vtype == VBLK
6769 if $kgm_vtype == VCHR
6772 if $kgm_vtype == VLNK
6775 if $kgm_vtype == VSOCK
6778 if $kgm_vtype == VFIFO
6781 if $kgm_vtype == VBAD
6784 if ($kgm_vtype < VNON) || ($kgm_vtype > VBAD)
6785 printf "%5d ", $kgm_vtype
6788 showptr $kgm_vnode->v_parent
6790 if $kgm_vnode->v_name != 0
6791 printf "%s\n", $kgm_vnode->v_name
6803 Syntax: (gdb) showvnode <vnode>
6804 | Display info about one vnode
6807 define showvolvnodes
6809 set $kgm_vol = (mount_t) $arg0
6810 set $kgm_vnode = (vnode_t) $kgm_vol.mnt_vnodelist.tqh_first
6812 showvnodeint $kgm_vnode
6813 set $kgm_vnode = (vnode_t) $kgm_vnode->v_mntvnodes.tqe_next
6817 document showvolvnodes
6818 Syntax: (gdb) showvolvnodes <mouont_t>
6819 | Display info about all vnodes of a given mount_t
6822 define showvolbusyvnodes
6824 set $kgm_vol = (mount_t) $arg0
6825 set $kgm_vnode = (vnode_t) $kgm_vol.mnt_vnodelist.tqh_first
6827 if $kgm_vnode->v_iocount != 0
6828 showvnodeint $kgm_vnode
6830 set $kgm_vnode = (vnode_t) $kgm_vnode->v_mntvnodes.tqe_next
6834 document showvolbusyvnodes
6835 Syntax: (gdb) showvolbusyvnodes <mount_t>
6836 | Display info about busy (iocount!=0) vnodes of a given mount_t
6839 define showallbusyvnodes
6841 set $kgm_vol = (mount_t) mountlist.tqh_first
6843 set $kgm_vnode = (vnode_t) $kgm_vol.mnt_vnodelist.tqh_first
6845 if $kgm_vnode->v_iocount != 0
6846 showvnodeint $kgm_vnode
6848 set $kgm_vnode = (vnode_t) $kgm_vnode->v_mntvnodes.tqe_next
6850 set $kgm_vol = (mount_t) $kgm_vol->mnt_list.tqe_next
6854 document showallbusyvnodes
6855 Syntax: (gdb) showallbusyvnodes <vnode>
6856 | Display info about all busy (iocount!=0) vnodes
6859 define showallvnodes
6861 set $kgm_vol = (mount_t) mountlist.tqh_first
6863 set $kgm_vnode = (vnode_t) $kgm_vol.mnt_vnodelist.tqh_first
6865 showvnodeint $kgm_vnode
6866 set $kgm_vnode = (vnode_t) $kgm_vnode->v_mntvnodes.tqe_next
6868 set $kgm_vol = (mount_t) $kgm_vol->mnt_list.tqe_next
6872 document showallvnodes
6873 Syntax: (gdb) showallvnodes
6874 | Display info about all vnodes
6877 define _showvnodelockheader
6878 printf "* type W held by lock type start end\n"
6879 printf "- ----- - ------------- --------- ------------------ ------------------\n"
6882 define _showvnodelock
6883 set $kgm_svl_lock = ((struct lockf *)$arg0)
6886 set $kgm_svl_flags = $kgm_svl_lock->lf_flags
6887 set $kgm_svl_type = $kgm_svl_lock->lf_type
6888 if ($kgm_svl_flags & 0x20)
6891 if ($kgm_svl_flags & 0x40)
6894 if ($kgm_svl_flags & 0x80)
6897 if ($kgm_svl_flags & 0x10)
6903 # POSIX file vs. advisory range locks
6904 if ($kgm_svl_flags & 0x40)
6905 set $kgm_svl_proc = (proc_t)$kgm_svl_lock->lf_id
6906 printf "PID %8d ", $kgm_svl_proc->p_pid
6908 printf "ID 0x%08x ", $kgm_svl_lock->lf_id
6912 if ($kgm_svl_type == 1)
6915 if ($kgm_svl_type == 3)
6918 if ($kgm_svl_type == 2)
6927 printf "0x%016x..", $kgm_svl_lock->lf_start
6928 printf "0x%016x ", $kgm_svl_lock->lf_end
6931 # Body of showvnodelocks, not including header
6932 define _showvnodelocks
6933 set $kgm_svl_vnode = ((vnode_t)$arg0)
6934 set $kgm_svl_lockiter = $kgm_svl_vnode->v_lockf
6935 while ($kgm_svl_lockiter != 0)
6936 # locks that are held
6938 _showvnodelock $kgm_svl_lockiter
6940 # and any locks blocked by them
6941 set $kgm_svl_blocker = $kgm_svl_lockiter->lf_blkhd.tqh_first
6942 while ($kgm_svl_blocker != 0)
6944 _showvnodelock $kgm_svl_blocker
6945 set $kgm_svl_blocker = $kgm_svl_blocker->lf_block.tqe_next
6948 # and on to the next one...
6949 set $kgm_svl_lockiter = $kgm_svl_lockiter->lf_next
6954 define showvnodelocks
6956 _showvnodelockheader
6957 _showvnodelocks $arg0
6959 printf "| Usage:\n|\n"
6964 document showvnodelocks
6965 Syntax: (gdb) showvnodelocks <vnode_t>
6966 | Given a vnodet pointer, display the list of advisory record locks for the
6967 | referenced pvnodes
6971 printf "%s\n", (char*)((boot_args*)PE_state.bootArgs).CommandLine
6974 document showbootargs
6975 Syntax: showbootargs
6976 | Display boot arguments passed to the target kernel
6979 define showbootermemorymap
6980 if ($kgm_mtype == $kgm_mtype_i386)
6981 set $kgm_voffset = 0
6983 if ($kgm_mtype == $kgm_mtype_x86_64)
6984 set $kgm_voffset = 0xFFFFFF8000000000ULL
6986 echo showbootermemorymap not supported on this architecture
6990 set $kgm_boot_args = kernelBootArgs
6991 set $kgm_msize = kernelBootArgs->MemoryMapDescriptorSize
6992 set $kgm_mcount = kernelBootArgs->MemoryMapSize / $kgm_msize
6995 printf "Type Physical Start Number of Pages Virtual Start Attributes\n"
6996 while $kgm_i < $kgm_mcount
6997 set $kgm_mptr = (EfiMemoryRange *)((unsigned long)kernelBootArgs->MemoryMap + $kgm_voffset + $kgm_i * $kgm_msize)
6999 if $kgm_mptr->Type == 0
7002 if $kgm_mptr->Type == 1
7005 if $kgm_mptr->Type == 2
7008 if $kgm_mptr->Type == 3
7011 if $kgm_mptr->Type == 4
7014 if $kgm_mptr->Type == 5
7017 if $kgm_mptr->Type == 6
7020 if $kgm_mptr->Type == 7
7023 if $kgm_mptr->Type == 8
7026 if $kgm_mptr->Type == 9
7029 if $kgm_mptr->Type == 10
7032 if $kgm_mptr->Type == 11
7035 if $kgm_mptr->Type == 12
7038 if $kgm_mptr->Type == 13
7041 if $kgm_mptr->Type > 13
7045 printf " %016llx %016llx", $kgm_mptr->PhysicalStart, $kgm_mptr->NumberOfPages
7046 if $kgm_mptr->VirtualStart != 0
7047 printf " %016llx", $kgm_mptr->VirtualStart
7051 printf " %016llx\n", $kgm_mptr->Attribute
7052 set $kgm_i = $kgm_i + 1
7056 document showbootermemorymap
7057 Syntax: (gdb) showbootermemorymap
7058 | Prints out the phys memory map from kernelBootArgs
7062 define showstacksaftertask
7063 set $kgm_head_taskp = &default_pset.tasks
7064 set $kgm_taskp = (struct task *)$arg0
7065 while $kgm_taskp != $kgm_head_taskp
7067 showtaskint $kgm_taskp
7068 set $kgm_head_actp = &($kgm_taskp->threads)
7069 set $kgm_actp = (struct thread *)($kgm_taskp->threads.next)
7070 while $kgm_actp != $kgm_head_actp
7072 if ($decode_wait_events > 0)
7073 showactint $kgm_actp 1
7075 showactint $kgm_actp 2
7077 set $kgm_actp = (struct thread *)($kgm_actp->task_threads.next)
7080 set $kgm_taskp = (struct task *)($kgm_taskp->pset_tasks.next)
7083 document showstacksaftertask
7084 Syntax: (gdb) showstacksaftertask <task>
7085 | Routine to print out all stacks (as in showallstacks) starting after a given task
7086 | Useful if that gdb refuses to print a certain task's stack.
7089 define showpmworkqueueint
7090 set $kgm_pm_wq = (IOPMWorkQueue *)$arg0
7091 set $kgm_pm_node = (IOService *)$kgm_pm_wq->owner
7094 showptr $kgm_pm_node
7096 printf "%02d ", $kgm_pm_node->pwrMgt->CurrentPowerState
7097 printf "%02d ", $kgm_pm_node->pwrMgt->MachineState
7098 printf "%02d ", $kgm_pm_node->pwrMgt->WaitReason
7099 printf "%s\n", $kgm_pm_node->pwrMgt->Name
7100 set $kgm_pm_queue = &($kgm_pm_wq->fWorkQueue)
7101 set $kgm_pm_req = (IOPMRequest *)$kgm_pm_queue->next
7102 if ((queue_entry_t) $kgm_pm_req != (queue_entry_t) $kgm_pm_queue)
7106 printf " type next "
7110 printf " work_wait free_wait\n"
7111 while ((queue_entry_t) $kgm_pm_req != (queue_entry_t) $kgm_pm_queue)
7113 printf " 0x%02x ", $kgm_pm_req->fType
7114 showptr $kgm_pm_req->fRequestNext
7116 showptr $kgm_pm_req->fRequestRoot
7117 printf " 0x%08x 0x%08x\n", $kgm_pm_req->fWorkWaitCount, $kgm_pm_req->fFreeWaitCount
7120 showptr $kgm_pm_req->fArg0
7122 showptr $kgm_pm_req->fArg1
7124 showptr $kgm_pm_req->fArg2
7126 set $kgm_pm_req = (IOPMRequest *)$kgm_pm_req->fCommandChain.next
7132 define showallpmworkqueues
7133 set $kgm_pm_next = gIOPMWorkLoop->eventChain
7138 printf " ps ms wr name\n"
7139 while ( $kgm_pm_next )
7140 set $kgm_vt = *((void **) $kgm_pm_next)
7141 if ($kgm_lp64 || $kgm_mtype == $kgm_mtype_arm)
7142 set $kgm_vt = $kgm_vt - 2 * sizeof(void *)
7144 if ($kgm_vt == &_ZTV13IOPMWorkQueue)
7145 showpmworkqueueint $kgm_pm_next
7147 set $kgm_pm_next = $kgm_pm_next->eventChainNext
7151 document showallpmworkqueues
7152 Syntax: (gdb) showallpmworkqueues
7153 | Display info about all IOPMWorkQueue objects
7156 define showioservicepm
7157 set $kgm_iopmpriv = (IOServicePM *)$arg0
7159 printf "MachineState = %d (", $kgm_iopmpriv->MachineState
7160 if ( $kgm_iopmpriv->MachineState == 1 )
7161 printf "kIOPM_OurChangeTellClientsPowerDown"
7163 if ( $kgm_iopmpriv->MachineState == 2 )
7164 printf "kIOPM_OurChangeTellPriorityClientsPowerDown"
7166 if ( $kgm_iopmpriv->MachineState == 3 )
7167 printf "kIOPM_OurChangeNotifyInterestedDriversWillChange"
7169 if ( $kgm_iopmpriv->MachineState == 4 )
7170 printf "kIOPM_OurChangeSetPowerState"
7172 if ( $kgm_iopmpriv->MachineState == 5 )
7173 printf "kIOPM_OurChangeWaitForPowerSettle"
7175 if ( $kgm_iopmpriv->MachineState == 6 )
7176 printf "kIOPM_OurChangeNotifyInterestedDriversDidChange"
7178 if ( $kgm_iopmpriv->MachineState == 7 )
7179 printf "kIOPM_OurChangeFinish"
7181 if ( $kgm_iopmpriv->MachineState == 8 )
7182 printf "kIOPM_ParentDownTellPriorityClientsPowerDown"
7184 if ( $kgm_iopmpriv->MachineState == 9 )
7185 printf "kIOPM_ParentDownNotifyInterestedDriversWillChange"
7187 if ( $kgm_iopmpriv->MachineState == 10 )
7188 printf "Unused_MachineState_10"
7190 if ( $kgm_iopmpriv->MachineState == 11 )
7191 printf "kIOPM_ParentDownNotifyDidChangeAndAcknowledgeChange"
7193 if ( $kgm_iopmpriv->MachineState == 12 )
7194 printf "kIOPM_ParentDownSetPowerState"
7196 if ( $kgm_iopmpriv->MachineState == 13 )
7197 printf "kIOPM_ParentDownWaitForPowerSettle"
7199 if ( $kgm_iopmpriv->MachineState == 14 )
7200 printf "kIOPM_ParentDownAcknowledgeChange"
7202 if ( $kgm_iopmpriv->MachineState == 15)
7203 printf "kIOPM_ParentUpSetPowerState"
7205 if ( $kgm_iopmpriv->MachineState == 16)
7206 printf "Unused_MachineState_16"
7208 if ( $kgm_iopmpriv->MachineState == 17)
7209 printf "kIOPM_ParentUpWaitForSettleTime"
7211 if ( $kgm_iopmpriv->MachineState == 18)
7212 printf "kIOPM_ParentUpNotifyInterestedDriversDidChange"
7214 if ( $kgm_iopmpriv->MachineState == 19)
7215 printf "kIOPM_ParentUpAcknowledgePowerChange"
7217 if ( $kgm_iopmpriv->MachineState == 20)
7218 printf "kIOPM_Finished"
7220 if ( $kgm_iopmpriv->MachineState == 21)
7221 printf "kIOPM_DriverThreadCallDone"
7223 if ( $kgm_iopmpriv->MachineState == 22)
7224 printf "kIOPM_NotifyChildrenDone"
7249 if ( $kgm_iopmpriv->MachineState != 20 )
7250 printf "DriverTimer = %d, ",(unsigned int)$kgm_iopmpriv->DriverTimer
7251 printf "SettleTime = %d, ",(unsigned int)$kgm_iopmpriv->SettleTimeUS
7252 printf "HeadNoteFlags = %08x, ",(unsigned int)$kgm_iopmpriv->HeadNoteFlags
7253 printf "HeadNotePendingAcks = %x, ",(unsigned int)$kgm_iopmpriv->HeadNotePendingAcks
7256 if ( $kgm_iopmpriv->DeviceOverrides != 0 )
7257 printf"DeviceOverrides, "
7260 printf "DeviceDesire = %d, ",(unsigned int)$kgm_iopmpriv->DeviceDesire
7261 printf "DesiredPowerState = %d, ",(unsigned int)$kgm_iopmpriv->DesiredPowerState
7262 printf "PreviousRequest = %d }\n",(unsigned int)$kgm_iopmpriv->PreviousRequest
7265 document showioservicepm
7266 Syntax: (gdb) showioservicepm <IOServicePM pointer>
7267 | Routine to dump the IOServicePM object
7270 define showregistryentryrecursepmstate
7271 set $kgm_re = (IOService *)$arg1
7272 set $kgm$arg0_stack = (unsigned long long) $arg2
7275 set $kgm$arg0_stack = $kgm$arg0_stack | (1ULL << $kgm_reg_depth)
7277 set $kgm$arg0_stack = $kgm$arg0_stack & ~(1ULL << $kgm_reg_depth)
7280 dictget $kgm_re->fRegistryTable $kgm_childkey
7281 set $kgm$arg0_child_array = (OSArray *) $kgm_result
7283 if ($kgm$arg0_child_array)
7284 set $kgm$arg0_child_count = $kgm$arg0_child_array->count
7286 set $kgm$arg0_child_count = 0
7289 if ($kgm$arg0_child_count)
7290 set $kgm$arg0_stack = $kgm$arg0_stack | (2ULL << $kgm_reg_depth)
7292 set $kgm$arg0_stack = $kgm$arg0_stack & ~(2ULL << $kgm_reg_depth)
7295 indent $kgm_reg_depth $kgm$arg0_stack
7298 dictget $kgm_re->fRegistryTable $kgm_namekey
7299 if ($kgm_result == 0)
7300 dictget $kgm_re->fRegistryTable gIONameKey
7302 if ($kgm_result == 0)
7303 dictget $kgm_re->fPropertyTable gIOClassKey
7306 if ($kgm_result != 0)
7307 printf "%s <%p>", ((OSString *)$kgm_result)->string, $kgm_re
7309 if (((IOService*)$kgm_re)->pwrMgt && ((IOService*)$kgm_re)->pwrMgt->Name)
7310 printf "%s <", ((IOService*)$kgm_re)->pwrMgt->Name
7320 if (((IOService*)$kgm_re)->pwrMgt )
7321 printf " Current Power State: %ld ", ((IOService*)$kgm_re)->pwrMgt->CurrentPowerState
7322 #printf " Mach State %ld", ((IOService*)$kgm_re)->pwrMgt->MachineState
7323 showioservicepm ((IOService*)$kgm_re)->pwrMgt
7329 if ($kgm$arg0_child_count != 0)
7331 set $kgm_reg_depth = $kgm_reg_depth + 1
7332 set $kgm$arg0_child_idx = 0
7334 while ($kgm$arg0_child_idx < $kgm$arg0_child_count)
7335 set $kgm_re = $kgm$arg0_child_array->array[$kgm$arg0_child_idx++]
7336 set $kgm_more_sib = ($kgm$arg0_child_idx < $kgm$arg0_child_count)
7337 if $kgm_reg_depth >= $kgm_reg_depth_max + 1
7340 showregistryentryrecursepmstate _$arg0 $kgm_re $kgm$arg0_stack $kgm_more_sib
7343 set $kgm_reg_depth = $kgm_reg_depth - 1
7347 define showregistryentryintpmstate
7349 set $kgm_reg_plane = (IORegistryPlane *) gIOServicePlane
7353 printf "Please load kgmacros after KDP attaching to the target.\n"
7355 set $kgm_namekey = (OSSymbol *) $kgm_reg_plane->nameKey
7356 set $kgm_childkey = (OSSymbol *) $kgm_reg_plane->keys[1]
7357 showregistryentryrecursepmstate _ $arg0 0 0
7361 define showregistrypmstate
7362 # setregistryplane gIOPowerPlane
7363 set $kgm_reg_depth = 0
7364 set $kgm_show_props = 1
7365 showregistryentryintpmstate gRegistryRoot
7368 document showregistrypmstate
7369 Syntax: (gdb) showregistrypmstate
7370 | Routine to dump the PM state of each IOPower registry entry
7373 define showstacksafterthread
7374 set $kgm_head_taskp = &default_pset.tasks
7375 set $kgm_actp = (struct thread *)$arg0
7376 set $kgm_actp = (struct thread *)($kgm_actp->task_threads.next)
7377 set $kgm_taskp = (struct task *)$kgm_actp->task
7378 while $kgm_taskp != $kgm_head_taskp
7380 showtaskint $kgm_taskp
7381 set $kgm_head_actp = &($kgm_taskp->threads)
7382 while $kgm_actp != $kgm_head_actp
7384 if ($decode_wait_events > 0)
7385 showactint $kgm_actp 1
7387 showactint $kgm_actp 2
7389 set $kgm_actp = (struct thread *)($kgm_actp->task_threads.next)
7392 set $kgm_taskp = (struct task *)($kgm_taskp->pset_tasks.next)
7396 document showstacksafterthread
7397 Syntax: (gdb) showstacksafterthread <thread>
7398 | Routine to print out all stacks (as in showallstacks) starting after a given thread
7399 | Useful if that gdb refuses to print a certain task's stack.
7403 set kdp_reentry_deadline = ((unsigned) $arg0)*1000
7407 document kdp-reenter
7408 Syntax: (gdb) kdp-reenter <seconds>
7409 | Schedules reentry into the debugger after <seconds> seconds, and resumes
7410 | the target system.
7421 if (($kgm_mtype & $kgm_mtype_x86_mask) != $kgm_mtype_x86_any)
7422 printf "Not available for current architecture.\n"
7425 _if_present mca_MCA_present
7426 printf ", control MSR"
7427 _if_present mca_control_MSR_present
7428 printf ", threshold status"
7429 _if_present mca_threshold_status_present
7430 printf "\n%d error banks, ", mca_error_bank_count
7431 printf "family code 0x%x, ", mca_family
7432 printf "machine-check dump state: %d\n", mca_dump_state
7434 while cpu_data_ptr[$kgm_cpu] != 0
7435 set $kgm_mcp = cpu_data_ptr[$kgm_cpu]->cpu_mca_state
7437 printf "CPU %d:", $kgm_cpu
7438 printf " mca_mcg_ctl: 0x%016llx", $kgm_mcp->mca_mcg_ctl
7439 printf " mca_mcg_status: 0x%016llx\n", $kgm_mcp->mca_mcg_status.u64
7441 printf "mca_mci_ctl "
7442 printf "mca_mci_status "
7443 printf "mca_mci_addr "
7444 printf "mca_mci_misc\n"
7446 while $kgm_bank < mca_error_bank_count
7447 set $kgm_bp = &$kgm_mcp->mca_error_bank[$kgm_bank]
7448 printf " %2d:", $kgm_bank
7449 printf " 0x%016llx", $kgm_bp->mca_mci_ctl
7450 printf " 0x%016llx", $kgm_bp->mca_mci_status.u64
7451 printf " 0x%016llx", $kgm_bp->mca_mci_addr
7452 printf " 0x%016llx\n", $kgm_bp->mca_mci_misc
7453 set $kgm_bank = $kgm_bank + 1
7456 set $kgm_cpu = $kgm_cpu + 1
7461 document showMCAstate
7462 Syntax: showMCAstate
7463 | Print machine-check register state after MC exception.
7468 # Step to lower-level page table and print attributes
7469 # $kgm_pt_paddr: current page table entry physical address
7470 # $kgm_pt_index: current page table entry index (0..511)
7472 # $kgm_pt_paddr: next level page table entry physical address
7473 # or null if invalid
7474 # $kgm_pt_valid: 1 if $kgm_pt_paddr is valid, 0 if the walk
7476 # $kgm_pt_large: 1 if kgm_pt_paddr is a page frame address
7477 # of a large page and not another page table entry
7478 # For $kgm_pt_verbose = 0: print nothing
7479 # 1: print basic information
7480 # 2: print basic information and hex table dump
7482 set $kgm_entryp = $kgm_pt_paddr + 8*$kgm_pt_index
7483 readphysint $kgm_entryp 64 $kgm_lcpu_self
7484 set $entry = $kgm_readphysint_result
7485 if $kgm_pt_verbose == 2
7486 set $kgm_pte_loop = 0
7487 while $kgm_pte_loop < 512
7488 set $kgm_pt_paddr_tmp = $kgm_pt_paddr + $kgm_pte_loop*8
7489 readphys64 $kgm_pt_paddr_tmp
7490 set $kgm_pte_loop = $kgm_pte_loop + 1
7493 set $kgm_paddr_mask = ~((0xfffULL<<52) | 0xfffULL)
7494 set $kgm_paddr_largemask = ~((0xfffULL<<52) | 0x1fffffULL)
7495 if $kgm_pt_verbose == 0
7496 if $entry & (0x1 << 0)
7497 set $kgm_pt_valid = 1
7498 if $entry & (0x1 << 7)
7499 set $kgm_pt_large = 1
7500 set $kgm_pt_paddr = $entry & $kgm_paddr_largemask
7502 set $kgm_pt_large = 0
7503 set $kgm_pt_paddr = $entry & $kgm_paddr_mask
7506 set $kgm_pt_valid = 0
7507 set $kgm_pt_large = 0
7508 set $kgm_pt_paddr = 0
7511 printf "0x%016llx:\n\t0x%016llx\n\t", $kgm_entryp, $entry
7512 if $entry & (0x1 << 0)
7514 set $kgm_pt_paddr = $entry & $kgm_paddr_mask
7515 set $kgm_pt_valid = 1
7518 set $kgm_pt_paddr = 0
7519 set $kgm_pt_valid = 0
7520 # stop decoding other bits
7523 if $entry & (0x1 << 1)
7528 if $entry & (0x1 << 2)
7531 printf " supervisor"
7533 if $entry & (0x1 << 3)
7536 if $entry & (0x1 << 4)
7539 if $entry & (0x1 << 5)
7542 if $entry & (0x1 << 6)
7545 if $entry & (0x1 << 7)
7547 set $kgm_pt_large = 1
7549 set $kgm_pt_large = 0
7551 if $entry & (0x1 << 8)
7554 if $entry & (0x3 << 9)
7555 printf " avail:0x%x", ($entry >> 9) & 0x3
7557 if $entry & (0x1 << 63)
7565 set $kgm_pmap = (pmap_t) $arg0
7566 set $kgm_vaddr = $arg1
7567 set $kgm_pt_paddr = $kgm_pmap->pm_cr3
7568 set $kgm_pt_valid = $kgm_pt_paddr != 0
7569 set $kgm_pt_large = 0
7570 set $kgm_pframe_offset = 0
7571 if $kgm_pt_valid && cpu_64bit
7572 # Look up bits 47:39 of the linear address in PML4T
7573 set $kgm_pt_index = ($kgm_vaddr >> 39) & 0x1ffULL
7574 set $kgm_pframe_offset = $kgm_vaddr & 0x7fffffffffULL
7576 printf "pml4 (index %d):\n", $kgm_pt_index
7581 # Look up bits 38:30 of the linear address in PDPT
7582 set $kgm_pt_index = ($kgm_vaddr >> 30) & 0x1ffULL
7583 set $kgm_pframe_offset = $kgm_vaddr & 0x3fffffffULL
7585 printf "pdpt (index %d):\n", $kgm_pt_index
7589 if $kgm_pt_valid && !$kgm_pt_large
7590 # Look up bits 29:21 of the linear address in PDT
7591 set $kgm_pt_index = ($kgm_vaddr >> 21) & 0x1ffULL
7592 set $kgm_pframe_offset = $kgm_vaddr & 0x1fffffULL
7594 printf "pdt (index %d):\n", $kgm_pt_index
7598 if $kgm_pt_valid && !$kgm_pt_large
7599 # Look up bits 20:21 of the linear address in PT
7600 set $kgm_pt_index = ($kgm_vaddr >> 12) & 0x1ffULL
7601 set $kgm_pframe_offset = $kgm_vaddr & 0xfffULL
7603 printf "pt (index %d):\n", $kgm_pt_index
7608 set $kgm_paddr = $kgm_pt_paddr + $kgm_pframe_offset
7609 readphysint $kgm_paddr 32 $kgm_lcpu_self
7610 set $kgm_value = $kgm_readphysint_result
7611 printf "phys 0x%016llx: 0x%08x\n", $kgm_paddr, $kgm_value
7614 printf "(no translation)\n"
7619 if (($kgm_mtype & $kgm_mtype_x86_mask) != $kgm_mtype_x86_any)
7620 printf "Not available for current architecture.\n"
7623 printf "pmap_walk <pmap> <vaddr>\n"
7626 set $kgm_pt_verbose = 1
7628 if $kgm_pt_verbose != 2
7629 set $kgm_pt_verbose = 1
7632 _pmap_walk $arg0 $arg1
7638 Syntax: (gdb) pmap_walk <pmap> <virtual_address>
7639 | Perform a page-table walk in <pmap> for <virtual_address>.
7640 | Set $kgm_pt_verbose=2 for full hex dump of page tables.
7644 if (($kgm_mtype & $kgm_mtype_x86_mask) != $kgm_mtype_x86_any)
7645 printf "Not available for current architecture.\n"
7648 printf "pmap_vtop <pamp> <vaddr>\n"
7650 set $kgm_pt_verbose = 0
7651 _pmap_walk $arg0 $arg1
7657 Syntax: (gdb) pmap_vtop <pmap> <virtual_address>
7658 | For page-tables in <pmap> translate <virtual_address> to physical address.
7664 if (log_records == 0)
7666 printf "Zone logging not enabled. Add 'zlog=<zone name>' to boot-args.\n"
7676 printf "\n--------------- "
7678 if (zrecords[$index].z_opcode == 1)
7684 printf " 0x%x : index %d : ztime %d -------------\n", zrecords[$index].z_element, $index, zrecords[$index].z_time
7689 set $frame_pc = zrecords[$index].z_pc[$frame]
7696 set $frame = $frame + 1
7699 set $index = $index + 1
7700 set $count = $count - 1
7705 Syntax: (gdb) zstack <index> [<count>]
7706 | Zone leak debugging: print the stack trace of log element at <index>.
7707 | If a <count> is supplied, it prints <count> log elements starting at <index>.
7709 | The suggested usage is to look at indexes below zcurrent and look for common stack traces.
7710 | The stack trace that occurs the most is probably the cause of the leak. Find the pc of the
7711 | function calling into zalloc and use the countpcs kgmacro to find out how often that pc occurs in the log.
7712 | The pc occuring in a high percentage of records is most likely the source of the leak.
7714 | The findoldest kgmacro is also useful for leak debugging since it identifies the oldest record
7715 | in the log, which may indicate the leaker.
7720 set $count = log_records
7721 set $cur_min = 2000000000
7724 if (log_records == 0)
7725 printf "Zone logging not enabled. Add 'zlog=<zone name>' to boot-args.\n"
7729 if (zrecords[$index].z_element && zrecords[$index].z_time < $cur_min)
7730 set $cur_index = $index
7731 set $cur_min = zrecords[$index].z_time
7734 set $count = $count - 1
7735 set $index = $index + 1
7738 printf "oldest record is at log index %d:\n", $cur_index
7744 Syntax: (gdb) findoldest
7745 | Zone leak debugging: find and print the oldest record in the log. Note that this command
7746 | can take several minutes to run since it uses linear search.
7748 | Once it prints a stack trace, find the pc of the caller above all the zalloc, kalloc and
7749 | IOKit layers. Then use the countpcs kgmacro to see how often this caller has allocated
7750 | memory. A caller with a high percentage of records in the log is probably the leaker.
7754 set $target_pc = $arg0
7756 set $count = log_records
7759 if (log_records == 0)
7760 printf "Zone logging not enabled. Add 'zlog=<zone name>' to boot-args.\n"
7766 if (zrecords[$index].z_element != 0)
7768 if (zrecords[$index].z_pc[$frame] == $target_pc)
7769 set $found = $found + 1
7773 set $frame = $frame + 1
7777 set $index = $index + 1
7778 set $count = $count - 1
7781 printf "occurred %d times in log (%d%c of records)\n", $found, ($found * 100) / zrecorded, '%'
7786 Syntax: (gdb) countpcs <pc>
7787 | Zone leak debugging: search the log and print a count of all log entries that contain the given <pc>
7788 | in the stack trace. This is useful for verifying a suspected <pc> as being the source of
7789 | the leak. If a high percentage of the log entries contain the given <pc>, then it's most
7790 | likely the source of the leak. Note that this command can take several minutes to run.
7794 set $fe_index = zcurrent
7795 set $fe_count = log_records
7796 set $fe_elem = $arg0
7797 set $fe_prev_op = -1
7799 if (log_records == 0)
7800 printf "Zone logging not enabled. Add 'zlog=<zone name>' to boot-args.\n"
7804 if (zrecords[$fe_index].z_element == $fe_elem)
7807 if (zrecords[$fe_index].z_opcode == $fe_prev_op)
7808 printf "*************** DOUBLE OP! *********************\n
7811 set $fe_prev_op = zrecords[$fe_index].z_opcode
7814 set $fe_count = $fe_count - 1
7815 set $fe_index = $fe_index + 1
7817 if ($fe_index >= log_records)
7824 Syntax: (gdb) findelem <elem addr>
7825 | Zone corruption debugging: search the log and print out the stack traces for all log entries that
7826 | refer to the given zone element. When the kernel panics due to a corrupted zone element, get the
7827 | element address and use this macro. This will show you the stack traces of all logged zalloc and
7828 | zfree operations which tells you who touched the element in the recent past. This also makes
7829 | double-frees readily apparent.
7833 # This implements a shadowing scheme in kgmacros. If the
7834 # current user data can be accessed by simply changing kdp_pmap,
7835 # that is used. Otherwise, we copy data into a temporary buffer
7836 # in the kernel's address space and use that instead. Don't rely on
7837 # kdp_pmap between invocations of map/unmap. Since the shadow
7838 # codepath uses a manual KDP packet, request no more than 128 bytes.
7839 # Uses $kgm_lp64 for kernel address space size
7840 define _map_user_data_from_task
7841 set $kgm_map_user_taskp = (task_t)$arg0
7842 set $kgm_map_user_map = $kgm_map_user_taskp->map
7843 set $kgm_map_user_pmap = $kgm_map_user_map->pmap
7844 set $kgm_map_user_task_64 = ( $kgm_map_user_taskp->taskFeatures[0] & 0x80000000)
7845 set $kgm_map_user_window = 0
7846 set $kgm_map_switch_map = 0
7849 set $kgm_map_switch_map = 1
7851 if !$kgm_map_user_task_64
7852 set $kgm_map_switch_map = 1
7856 if ($kgm_map_switch_map)
7857 # switch the map safely
7858 set $kgm_map_user_window = $arg1
7859 set kdp_pmap = $kgm_map_user_pmap
7861 # requires shadowing/copying
7863 # set up the manual KDP packet
7864 set manual_pkt.input = 0
7865 set manual_pkt.len = sizeof(kdp_readmem64_req_t)
7866 set $kgm_pkt = (kdp_readmem64_req_t *)&manual_pkt.data
7867 set $kgm_pkt->hdr.request = KDP_READMEM64
7868 set $kgm_pkt->hdr.len = sizeof(kdp_readmem64_req_t)
7869 set $kgm_pkt->hdr.is_reply = 0
7870 set $kgm_pkt->hdr.seq = 0
7871 set $kgm_pkt->hdr.key = 0
7872 set $kgm_pkt->address = (uint64_t)$arg1
7873 set $kgm_pkt->nbytes = (uint32_t)$arg2
7875 set kdp_pmap = $kgm_map_user_pmap
7876 set manual_pkt.input = 1
7877 # dummy to make sure manual packet is executed
7878 set $kgm_dummy = &_mh_execute_header
7879 # Go back to kernel map so that we can access buffer directly
7882 set $kgm_pkt = (kdp_readmem64_reply_t *)&manual_pkt.data
7883 if ($kgm_pkt->error == 0)
7884 set $kgm_map_user_window = $kgm_pkt->data
7886 set $kgm_map_user_window = 0
7892 define _unmap_user_data_from_task
7896 # uses $kgm_taskp. Maps 32 bytes at a time and prints it
7897 define _print_path_for_image
7898 set $kgm_print_path_address = (unsigned long long)$arg0
7899 set $kgm_path_str_notdone = 1
7901 while $kgm_path_str_notdone
7902 _map_user_data_from_task $kgm_taskp $kgm_print_path_address 32
7904 set $kgm_print_path_ptr = (char *)$kgm_map_user_window
7906 while ($kgm_path_i < 32 && $kgm_print_path_ptr[$kgm_path_i] != '\0')
7907 set $kgm_path_i = $kgm_path_i + 1
7909 printf "%.32s", $kgm_print_path_ptr
7911 _unmap_user_data_from_task $kgm_taskp
7913 # if we terminated on NUL, break out
7915 set $kgm_path_str_notdone = 0
7917 set $kgm_print_path_address = $kgm_print_path_address + 32
7922 # uses $kgm_taskp and $kgm_task_64
7923 define _print_image_info
7924 set $kgm_mh_image_address = (unsigned long long)$arg0
7925 set $kgm_mh_path_address = (unsigned long long)$arg1
7927 # 32 bytes enough for mach_header/mach_header_64
7928 _map_user_data_from_task $kgm_taskp $kgm_mh_image_address 32
7930 set $kgm_mh_ptr = (unsigned int*)$kgm_map_user_window
7931 set $kgm_mh_magic = $kgm_mh_ptr[0]
7932 set $kgm_mh_cputype = $kgm_mh_ptr[1]
7933 set $kgm_mh_cpusubtype = $kgm_mh_ptr[2]
7934 set $kgm_mh_filetype = $kgm_mh_ptr[3]
7935 set $kgm_mh_ncmds = $kgm_mh_ptr[4]
7936 set $kgm_mh_sizeofcmds = $kgm_mh_ptr[5]
7937 set $kgm_mh_flags = $kgm_mh_ptr[6]
7939 _unmap_user_data_from_task $kgm_taskp
7941 if $kgm_mh_magic == 0xfeedfacf
7943 set $kgm_lc_address = $kgm_mh_image_address + 32
7946 set $kgm_lc_address = $kgm_mh_image_address + 28
7950 set $kgm_uuid_data = 0
7951 while $kgm_lc_idx < $kgm_mh_ncmds
7953 # 24 bytes is size of uuid_command
7954 _map_user_data_from_task $kgm_taskp $kgm_lc_address 24
7956 set $kgm_lc_ptr = (unsigned int *)$kgm_map_user_window
7957 set $kgm_lc_cmd = $kgm_lc_ptr[0]
7958 set $kgm_lc_cmd_size = $kgm_lc_ptr[1]
7959 set $kgm_lc_data = (unsigned char *)$kgm_lc_ptr + 8
7961 if $kgm_lc_cmd == 0x1b
7962 set $kgm_uuid_data = $kgm_lc_data
7964 printf "0x%016llx ", $kgm_mh_image_address
7966 printf "0x%08x ", $kgm_mh_image_address
7969 set $kgm_printed_type = 0
7970 if $kgm_mh_filetype == 0x2
7971 printf "MH_EXECUTE "
7972 set $kgm_printed_type = 1
7974 if $kgm_mh_filetype == 0x6
7976 set $kgm_printed_type = 1
7978 if $kgm_mh_filetype == 0x7
7979 printf "MH_DYLINKER "
7980 set $kgm_printed_type = 1
7982 if $kgm_mh_filetype == 0x8
7984 set $kgm_printed_type = 1
7986 if !$kgm_printed_type
7989 printf "%02.2X%02.2X%02.2X%02.2X-", $kgm_uuid_data[0], $kgm_uuid_data[1], $kgm_uuid_data[2], $kgm_uuid_data[3]
7990 printf "%02.2X%02.2X-", $kgm_uuid_data[4], $kgm_uuid_data[5]
7991 printf "%02.2X%02.2X-", $kgm_uuid_data[6], $kgm_uuid_data[7]
7992 printf "%02.2X%02.2X-", $kgm_uuid_data[8], $kgm_uuid_data[9]
7993 printf "%02.2X%02.2X%02.2X%02.2X%02.2X%02.2X", $kgm_uuid_data[10], $kgm_uuid_data[11], $kgm_uuid_data[12], $kgm_uuid_data[13], $kgm_uuid_data[14], $kgm_uuid_data[15]
7995 _unmap_user_data_from_task $kgm_taskp
7998 _print_path_for_image $kgm_mh_path_address
8003 _unmap_user_data_from_task $kgm_taskp
8006 set $kgm_lc_address = $kgm_lc_address + $kgm_lc_cmd_size
8007 set $kgm_lc_idx = $kgm_lc_idx + 1
8010 if (!$kgm_uuid_data)
8011 # didn't find LC_UUID, for a dylib, just print out basic info
8013 printf "0x%016llx ", $kgm_mh_image_address
8015 printf "0x%08x ", $kgm_mh_image_address
8017 set $kgm_printed_type = 0
8018 if $kgm_mh_filetype == 0x2
8019 printf "MH_EXECUTE "
8020 set $kgm_printed_type = 1
8022 if $kgm_mh_filetype == 0x6
8024 set $kgm_printed_type = 1
8026 if $kgm_mh_filetype == 0x7
8027 printf "MH_DYLINKER "
8028 set $kgm_printed_type = 1
8030 if $kgm_mh_filetype == 0x8
8032 set $kgm_printed_type = 1
8034 if !$kgm_printed_type
8040 _print_path_for_image $kgm_mh_path_address
8047 define _print_images_for_dyld_image_info
8048 set $kgm_taskp = $arg0
8049 set $kgm_task_64 = $arg1
8050 set $kgm_dyld_all_image_infos_address = (unsigned long long)$arg2
8052 _map_user_data_from_task $kgm_taskp $kgm_dyld_all_image_infos_address 16
8054 set $kgm_dyld_all_image_infos = (unsigned int *)$kgm_map_user_window
8055 if ($kgm_dyld_all_image_infos[0] != 6)
8056 printf "Invalid version number %d\n", $kgm_dyld_all_image_infos[0]
8058 set $kgm_image_info_count = $kgm_dyld_all_image_infos[1]
8061 set $kgm_image_info_size = 24
8062 set $kgm_image_info_array_address = ((unsigned long long *)$kgm_dyld_all_image_infos)[1]
8064 set $kgm_image_info_size = 12
8065 set $kgm_image_info_array_address = ((unsigned int *)$kgm_dyld_all_image_infos)[2]
8068 _unmap_user_data_from_task $kgm_taskp
8070 set $kgm_image_info_i = 0
8071 while $kgm_image_info_i < $kgm_image_info_count
8073 set $kgm_image_info_address = $kgm_image_info_array_address + $kgm_image_info_size*$kgm_image_info_i
8075 _map_user_data_from_task $kgm_taskp $kgm_image_info_address $kgm_image_info_size
8077 set $kgm_image_info_addr = ((unsigned long long *)$kgm_map_user_window)[0]
8078 set $kgm_image_info_path = ((unsigned long long *)$kgm_map_user_window)[1]
8080 set $kgm_image_info_addr = ((unsigned int *)$kgm_map_user_window)[0]
8081 set $kgm_image_info_path = ((unsigned int *)$kgm_map_user_window)[1]
8083 _unmap_user_data_from_task $kgm_taskp
8085 # printf "[%d] = image address %llx path address %llx\n", $kgm_image_info_i, $kgm_image_info_addr, $kgm_image_info_path
8086 _print_image_info $kgm_image_info_addr $kgm_image_info_path
8088 set $kgm_image_info_i = $kgm_image_info_i + 1
8092 define showuserlibraries
8093 set $kgm_taskp = (task_t)$arg0
8094 set $kgm_dyld_image_info = $kgm_taskp->all_image_info_addr
8096 set $kgm_map = $kgm_taskp->map
8097 set $kgm_task_64 = ( $kgm_taskp->taskFeatures[0] & 0x80000000)
8099 if ($kgm_dyld_image_info != 0)
8108 _print_images_for_dyld_image_info $kgm_taskp $kgm_task_64 $kgm_dyld_image_info
8110 printf "No dyld shared library information available for task\n"
8113 document showuserlibraries
8114 Syntax: (gdb) showuserlibraries <task_t>
8115 | For a given user task, inspect the dyld shared library state and print
8116 | information about all Mach-O images.
8119 define showkerneldebugheader
8122 printf "CPU Thread "
8124 printf "Timestamp S/E Class Sub Code Code Specific Info\n"
8127 define _printevflags
8148 printf "EV_RCLOSED "
8154 printf "EV_WCLOSED "
8169 printf "EV_TIMEOUT "
8173 define showkerneldebugbufferentry
8174 set $kgm_kdebug_entry = (kd_buf *) $arg0
8176 set $kgm_debugid = $kgm_kdebug_entry->debugid
8177 set $kgm_kdebug_arg1 = $kgm_kdebug_entry->arg1
8178 set $kgm_kdebug_arg2 = $kgm_kdebug_entry->arg2
8179 set $kgm_kdebug_arg3 = $kgm_kdebug_entry->arg3
8180 set $kgm_kdebug_arg4 = $kgm_kdebug_entry->arg4
8183 set $kgm_kdebug_cpu = $kgm_kdebug_entry->cpuid
8184 set $kgm_ts_hi = ($kgm_kdebug_entry->timestamp >> 32) & 0xFFFFFFFF
8185 set $kgm_ts_lo = $kgm_kdebug_entry->timestamp & 0xFFFFFFFF
8187 set $kgm_kdebug_cpu = ($kgm_kdebug_entry->timestamp >> 56)
8188 set $kgm_ts_hi = ($kgm_kdebug_entry->timestamp >> 32) & 0x00FFFFFF
8189 set $kgm_ts_lo = $kgm_kdebug_entry->timestamp & 0xFFFFFFFF
8192 set $kgm_kdebug_class = ($kgm_debugid >> 24) & 0x000FF
8193 set $kgm_kdebug_subclass = ($kgm_debugid >> 16) & 0x000FF
8194 set $kgm_kdebug_code = ($kgm_debugid >> 2) & 0x03FFF
8195 set $kgm_kdebug_qual = ($kgm_debugid ) & 0x00003
8197 if $kgm_kdebug_qual == 0
8198 set $kgm_kdebug_qual = '-'
8200 if $kgm_kdebug_qual == 1
8201 set $kgm_kdebug_qual = 'S'
8203 if $kgm_kdebug_qual == 2
8204 set $kgm_kdebug_qual = 'E'
8206 if $kgm_kdebug_qual == 3
8207 set $kgm_kdebug_qual = '?'
8215 showptr $kgm_kdebug_entry
8216 printf " %d ", $kgm_kdebug_cpu
8217 showptr $kgm_kdebug_entry->arg5
8218 printf " 0x%08X%08X %c ", $kgm_ts_hi, $kgm_ts_lo, $kgm_kdebug_qual
8222 if $kgm_kdebug_class == 1
8225 if $kgm_kdebug_class == 2
8228 if $kgm_kdebug_class == 3
8231 if $kgm_kdebug_class == 4
8234 if $kgm_kdebug_class == 5
8237 if $kgm_kdebug_class == 6
8240 if $kgm_kdebug_class == 7
8243 if $kgm_kdebug_class == 8
8246 if $kgm_kdebug_class == 8
8249 if $kgm_kdebug_class == 20
8252 if $kgm_kdebug_class == 31
8255 if $kgm_kdebug_class == 32
8258 if $kgm_kdebug_class == 33
8261 if $kgm_kdebug_class == 255
8264 printf "0x%02X", $kgm_kdebug_class
8282 printf " 0x%02X %5d ", $kgm_kdebug_subclass, $kgm_kdebug_code
8284 # space for debugid-specific processing
8286 # EVPROC from bsd/kern/sys_generic.c
8288 # MISCDBG_CODE(DBG_EVENT,DBG_WAIT)
8289 if $kgm_debugid == 0x14100048
8291 if $kgm_kdebug_arg1 == 1
8292 printf "before sleep"
8294 if $kgm_kdebug_arg1 == 2
8295 printf "after sleep"
8297 printf "????????????"
8300 printf " chan=0x%08X ", $kgm_kdebug_arg2
8302 # MISCDBG_CODE(DBG_EVENT,DBG_WAIT|DBG_FUNC_START)
8303 if $kgm_debugid == 0x14100049
8306 # MISCDBG_CODE(DBG_EVENT,DBG_WAIT|DBG_FUNC_END)
8307 if $kgm_debugid == 0x1410004a
8308 printf "waitevent error=%d ", $kgm_kdebug_arg1
8309 printf "eqp=0x%08X ", $kgm_kdebug_arg4
8310 _printevflags $kgm_kdebug_arg3
8311 printf "er_handle=%d ", $kgm_kdebug_arg2
8313 # MISCDBG_CODE(DBG_EVENT,DBG_DEQUEUE|DBG_FUNC_START)
8314 if $kgm_debugid == 0x14100059
8315 printf "evprocdeque proc=0x%08X ", $kgm_kdebug_arg1
8316 if $kgm_kdebug_arg2 == 0
8317 printf "remove first "
8319 printf "remove 0x%08X ", $kgm_kdebug_arg2
8322 # MISCDBG_CODE(DBG_EVENT,DBG_DEQUEUE|DBG_FUNC_END)
8323 if $kgm_debugid == 0x1410005a
8324 printf "evprocdeque "
8325 if $kgm_kdebug_arg1 == 0
8326 printf "result=NULL "
8328 printf "result=0x%08X ", $kgm_kdebug_arg1
8331 # MISCDBG_CODE(DBG_EVENT,DBG_POST|DBG_FUNC_START)
8332 if $kgm_debugid == 0x14100041
8334 _printevflags $kgm_kdebug_arg1
8336 # MISCDBG_CODE(DBG_EVENT,DBG_POST)
8337 if $kgm_debugid == 0x14100040
8339 printf "evq=0x%08X ", $kgm_kdebug_arg1
8340 printf "er_eventbits="
8341 _printevflags $kgm_kdebug_arg2
8343 _printevflags $kgm_kdebug_arg3
8345 # MISCDBG_CODE(DBG_EVENT,DBG_POST|DBG_FUNC_END)
8346 if $kgm_debugid == 0x14100042
8349 # MISCDBG_CODE(DBG_EVENT,DBG_ENQUEUE|DBG_FUNC_START)
8350 if $kgm_debugid == 0x14100055
8351 printf "evprocenque eqp=0x%08d ", $kgm_kdebug_arg1
8352 if $kgm_kdebug_arg2 & 1
8355 _printevflags $kgm_kdebug_arg3
8358 # MISCDBG_CODE(DBG_EVENT,DBG_EWAKEUP)
8359 if $kgm_debugid == 0x14100050
8360 printf "evprocenque before wakeup eqp=0x%08d ", $kgm_kdebug_arg4
8362 # MISCDBG_CODE(DBG_EVENT,DBG_ENQUEUE|DBG_FUNC_END)
8363 if $kgm_debugid == 0x14100056
8364 printf "evprocenque "
8366 # MISCDBG_CODE(DBG_EVENT,DBG_MOD|DBG_FUNC_START)
8367 if $kgm_debugid == 0x1410004d
8370 # MISCDBG_CODE(DBG_EVENT,DBG_MOD)
8371 if $kgm_debugid == 0x1410004c
8372 printf "modwatch er_handle=%d ", $kgm_kdebug_arg1
8373 _printevflags $kgm_kdebug_arg2
8374 printf "evq=0x%08X ", $kgm_kdebug_arg3
8376 # MISCDBG_CODE(DBG_EVENT,DBG_MOD|DBG_FUNC_END)
8377 if $kgm_debugid == 0x1410004e
8378 printf "modwatch er_handle=%d ", $kgm_kdebug_arg1
8379 printf "ee_eventmask="
8380 _printevflags $kgm_kdebug_arg2
8381 printf "sp=0x%08X ", $kgm_kdebug_arg3
8383 _printevflags $kgm_kdebug_arg4
8385 printf "arg1=0x%08X ", $kgm_kdebug_arg1
8386 printf "arg2=0x%08X ", $kgm_kdebug_arg2
8387 printf "arg3=0x%08X ", $kgm_kdebug_arg3
8388 printf "arg4=0x%08X ", $kgm_kdebug_arg4
8409 define showkerneldebugbuffercpu
8410 set $kgm_cpu_number = (int) $arg0
8411 set $kgm_entry_count = (int) $arg1
8412 set $kgm_debugentriesfound = 0
8414 #if kdebug_flags & KDBG_BFINIT
8415 if (kdebug_flags & 0x80000000)
8416 showkerneldebugheader
8418 if $kgm_entry_count == 0
8419 printf "<count> is 0, dumping 50 entries\n"
8420 set $kgm_entry_count = 50
8423 if $kgm_cpu_number >= kd_cpus
8424 printf "cpu number too big\n"
8426 set $kgm_kdbp = &kdbip[$kgm_cpu_number]
8427 set $kgm_kdsp = $kgm_kdbp->kd_list_head
8428 while (($kgm_kdsp != 0) && ($kgm_entry_count > 0))
8429 if $kgm_kdsp->kds_readlast != $kgm_kdsp->kds_bufptr
8430 set $kgm_kds_bufptr = $kgm_kdsp->kds_bufptr
8431 while (($kgm_kds_bufptr > $kgm_kdsp->kds_readlast) && ($kgm_entry_count > 0))
8432 set $kgm_kds_bufptr = $kgm_kds_bufptr - 1
8433 set $kgm_entry_count = $kgm_entry_count - 1
8434 showkerneldebugbufferentry $kgm_kds_bufptr
8437 set $kgm_kdsp = $kgm_kdsp->kds_next
8441 printf "Trace buffer not enabled\n"
8445 document showkerneldebugbuffercpu
8446 Syntax: showkerneldebugbuffercpu <cpu> <count>
8447 | Prints the last N entries in the kernel debug buffer for CPU x.
8450 define showkerneldebugbuffer
8452 #if kdebug_flags & KDBG_BFINIT
8453 if (kdebug_flags & 0x80000000)
8455 set $kgm_entrycount = (int) $arg0
8457 if $kgm_entrycount == 0
8458 printf "<count> is 0, dumping 50 entries per cpu\n"
8459 set $kgm_entrycount = 50
8462 set $kgm_cpu = (int) 0
8464 while $kgm_cpu < kd_cpus
8465 showkerneldebugbuffercpu $kgm_cpu $kgm_entrycount
8466 set $kgm_cpu = $kgm_cpu + 1
8469 printf "Trace buffer not enabled\n"
8473 document showkerneldebugbuffer
8474 Syntax: showkerneldebugbuffer <count>
8475 | Prints the last N entries in the kernel debug buffer per cpu. i.e. showkerneldebugbuffer 50 will
8476 | display the last 50 entries in each CPU's debug buffer.
8479 define showallvmstats
8480 printf " pid command #ents wired vsize rsize max rsize\n"
8481 printf " (pages) (pages) (pages) (pages)\n"
8482 set $kgm_head_taskp = &tasks
8483 set $kgm_taskp = (struct task *)($kgm_head_taskp->next)
8484 while $kgm_taskp != $kgm_head_taskp
8485 set $kgm_procp = (struct proc *)($kgm_taskp->bsd_info)
8486 set $kgm_mapp = (struct _vm_map *)($kgm_taskp->map)
8487 printf "%8d %17s %8d %15d %15d %15d %15d\n", $kgm_procp->p_pid, $kgm_procp->p_comm, $kgm_mapp->hdr.nentries, $kgm_mapp->pmap->stats.wired_count, $kgm_mapp->size >> 12, $kgm_mapp->pmap->stats.resident_count, $kgm_mapp->pmap->stats.resident_max
8488 set $kgm_taskp = (struct task *)($kgm_taskp->tasks.next)
8492 document showallvmstats
8493 Syntax: showallvmstats
8494 | prints a summary of vm statistics in a table format
8497 define show_user_registers
8498 if (($kgm_mtype & $kgm_mtype_x86_mask) == $kgm_mtype_x86_any)
8499 set $kgm_thread = (thread_t)$arg0
8500 if ((*(thread_t)$kgm_thread)->machine.xxx_pcb.iss.flavor == 15)
8501 p/x ($kgm_thread)->machine.xxx_pcb.iss->uss.ss_64
8503 p/x ($kgm_thread)->machine.xxx_pcb.iss->uss.ss_32
8506 if ($kgm_mtype == $kgm_mtype_ppc)
8507 set $kgm_thread = (thread_t)$arg0
8508 p/x *($kgm_thread)->machine.pcb
8512 document show_user_registers
8513 Syntax: show_user_registers <thread_address>
8514 | Display user registers associated with a kernel thread
8515 | properly displays the 32 bit or 64 bit registers for intel architecture
8522 # check for end of string. cmp0 can be longer than cmp1. it
8525 set $kgm_strcmp_result = 0
8526 set $kgm_strcmp_done = 1
8529 if !$kgm_strcmp_done && $cmp0 == '\0'
8530 set $kgm_strcmp_result = -1
8531 set $kgm_strcmp_done = 1
8535 if !$kgm_strcmp_done
8536 set $kgm_strcmp_result = (uint8_t) $cmp0 - (uint8_t) $cmp1
8537 if $kgm_strcmp_result != 0
8538 set $kgm_strcmp_done = 1
8545 set $masked = $cmp & 0xFF
8546 _cmp $arg0[0] $masked
8548 if !$kgm_strcmp_done
8549 set $cmp = $cmp >> 8
8550 set $masked = $cmp & 0xFF
8551 _cmp $arg0[1] $masked
8553 if !$kgm_strcmp_done
8554 set $cmp = $cmp >> 8
8555 set $masked = $cmp & 0xFF
8556 _cmp $arg0[2] $masked
8558 if !$kgm_strcmp_done
8559 set $cmp = $cmp >> 8
8560 set $masked = $cmp & 0xFF
8561 _cmp $arg0[3] $masked
8563 if !$kgm_strcmp_done
8564 set $cmp = $cmp >> 8
8565 set $masked = $cmp & 0xFF
8566 _cmp $arg0[4] $masked
8568 if !$kgm_strcmp_done
8569 set $cmp = $cmp >> 8
8570 set $masked = $cmp & 0xFF
8571 _cmp $arg0[5] $masked
8573 if !$kgm_strcmp_done
8574 set $cmp = $cmp >> 8
8575 set $masked = $cmp & 0xFF
8576 _cmp $arg0[6] $masked
8578 if !$kgm_strcmp_done
8579 set $cmp = $cmp >> 8
8580 set $masked = $cmp & 0xFF
8581 _cmp $arg0[7] $masked
8585 define strcmp_arg_pack64
8586 set $kgm_strcmp_arg = ((((((((((((((uint64_t) $arg7 << 8) | $arg6) << 8) | $arg5) << 8) | $arg4) << 8) | $arg3) << 8) | $arg2) << 8) | $arg1) << 8) | $arg0
8589 document strcmp_arg_pack64
8590 Syntax: strcmp_arg_pack64 <a> <b> <c> <d> <e <f> <g> <h>
8591 | Packs a string given as 8 character arguments into a 64-bit int stored in
8592 | $kgm_strcmp_arg. Use 0 or '\0' for unused arguments. The encoded string
8593 | is suitable for use by strcmp_nomalloc and setfindregistrystr.
8594 | e.g., strcmp_arg_pack64 'H' 'e' 'l' 'l' 'o' 0 0 0
8595 | packs "Hello" into $kgm_strcmp_arg.
8599 define strcmp_nomalloc
8601 set $count = $argc - 1
8603 set $kgm_strcmp_result = 0
8604 set $kgm_strcmp_done = 0
8607 _cmp_arg64 $str $arg1
8609 if !$kgm_strcmp_done && $count > 1
8611 _cmp_arg64 $str $arg2
8613 if !$kgm_strcmp_done && $count > 2
8615 _cmp_arg64 $str $arg3
8617 if !$kgm_strcmp_done && $count > 3
8619 _cmp_arg64 $str $arg4
8621 if !$kgm_strcmp_done && $count > 4
8623 _cmp_arg64 $str $arg5
8625 if !$kgm_strcmp_done && $count > 5
8627 _cmp_arg64 $str $arg6
8629 if !$kgm_strcmp_done && $count > 6
8631 _cmp_arg64 $str $arg7
8633 if !$kgm_strcmp_done && $count > 7
8635 _cmp_arg64 $str $arg8
8637 if !$kgm_strcmp_done && $count > 8
8639 _cmp_arg64 $str $arg9
8643 document strcmp_nomalloc
8644 Syntax: strcmp_nomalloc <string> <a> [b] [c] [d] [e] [f] [g] [h] [i]
8645 | Given a pre-allocated <string>, perform a string compare with the
8646 | encoded string stored in arguments a - i. The result is stored in
8647 | $kgm_strcmp_result.
8649 | For example, the following will result in $kgm_strcmp_result == 0:
8650 | strcmp_arg_pack64 'D' 'a' 'r' 'w' 'i' 'n' ' ' 'K'
8651 | strcmp_nomalloc version $kgm_strcmp_arg
8654 # _pci_cfg_addr_value $addr $size
8655 define _pci_cfg_addr_value
8656 readphysint $arg0 $arg1 $kgm_lcpu_self
8657 set $kgm_pci_cfg_value = $kgm_readphysint_result
8661 set $kgm_pci_cfg_init = 0
8662 define _pci_cfg_init
8663 # get this from the registry if it exists there
8664 if $kgm_pci_cfg_init == 0
8665 strcmp_arg_pack64 'A' 'p' 'p' 'l' 'e' 'A' 'C' 'P'
8666 set $AppleACP = $kgm_strcmp_arg
8667 strcmp_arg_pack64 'I' 'P' 'l' 'a' 't' 'f' 'o' 'r'
8668 set $IPlatfor = $kgm_strcmp_arg
8669 strcmp_arg_pack64 'm' 'E' 'x' 'p' 'e' 'r' 't' 0
8670 set $mExpert = $kgm_strcmp_arg
8671 setfindregistrystr $AppleACP $IPlatfor $mExpert
8673 set $olddepth = $kgm_reg_depth_max
8674 set $kgm_reg_depth_max = 2
8676 set $kgm_reg_depth_max = $olddepth
8678 if $kgm_registry_entry
8679 strcmp_arg_pack64 'a' 'c' 'p' 'i' '-' 'm' 'm' 'c'
8680 set $acpi_mmc = $kgm_strcmp_arg
8681 strcmp_arg_pack64 'f' 'g' '-' 's' 'e' 'g' '0' 0
8682 set $fg_seg0 = $kgm_strcmp_arg
8683 setfindregistrystr $acpi_mmc $fg_seg0
8685 _findregistryprop $kgm_registry_entry
8686 if $kgm_registry_value
8687 set $kgm_pci_cfg_base = ((OSNumber *) $kgm_registry_value)->value
8688 set $kgm_pci_cfg_init = 1
8693 # if the above fails, search for 0:0:0 in likely places.
8694 if $kgm_pci_cfg_init == 0
8695 set $kgm_pci_cfg_base = 0xF0000000
8696 while $kgm_pci_cfg_init == 0 && $kgm_pci_cfg_base > 0xA0000000
8697 _pci_cfg_addr_value $kgm_pci_cfg_base 8
8698 if $kgm_pci_cfg_value > 0x0 && $kgm_pci_cfg_value < 0xFF
8699 set $kgm_pci_cfg_init = 1
8701 set $kgm_pci_cfg_base = $kgm_pci_cfg_base - 0x10000000
8707 # _pci_cfg_addr $bus $dev $fcn $off
8708 define _pci_cfg_addr
8715 set $kgm_pci_cfg_addr = $kgm_pci_cfg_base | ($bus << 20) | ($dev << 15) | ($fcn << 12) | $off
8718 define _pci_cfg_value
8719 _pci_cfg_addr $arg0 $arg1 $arg2 $arg3
8720 _pci_cfg_addr_value $kgm_pci_cfg_addr $arg4
8723 define pci_cfg_read8
8724 _pci_cfg_value $arg0 $arg1 $arg2 $arg3 8
8725 printf "%08X: %02X\n", $kgm_pci_cfg_addr, $kgm_pci_cfg_value
8728 define pci_cfg_read16
8729 _pci_cfg_value $arg0 $arg1 $arg2 $arg3 16
8730 printf "%08X: %04X\n", $kgm_pci_cfg_addr, $kgm_pci_cfg_value
8733 define pci_cfg_read32
8734 _pci_cfg_value $arg0 $arg1 $arg2 $arg3 32
8735 printf "%08X: %08X\n", $kgm_pci_cfg_addr, $kgm_pci_cfg_value
8738 document pci_cfg_read8
8739 Syntax: (gdb) pci_cfg_read8 <bus> <dev> <fcn> <off>
8740 | read 8 bits for the given <off> of the pci device located at
8741 | <bus>:<dev>:<fcn>.
8744 document pci_cfg_read16
8745 Syntax: (gdb) pci_cfg_read <bus> <dev> <fcn> <off>
8746 | read 16 bits for the given <off> of the pci device located at
8747 | <bus>:<dev>:<fcn>.
8750 document pci_cfg_read32
8751 Syntax: (gdb) pci_cfg_read <bus> <dev> <fcn> <off>
8752 | read 32 bits for the given <off> of the pci device located at
8753 | <bus>:<dev>:<fcn>.
8756 define pci_cfg_write8
8757 _pci_cfg_addr $arg0 $arg1 $arg2 $arg3
8758 writephysint $kgm_pci_cfg_addr 8 $arg4 $kgm_lcpu_self
8761 define pci_cfg_write16
8762 _pci_cfg_addr $arg0 $arg1 $arg2 $arg3
8763 writephysint $kgm_pci_cfg_addr 16 $arg4 $kgm_lcpu_self
8766 define pci_cfg_write32
8767 _pci_cfg_addr $arg0 $arg1 $arg2 $arg3
8768 writephysint $kgm_pci_cfg_addr 32 $arg4 $kgm_lcpu_self
8771 document pci_cfg_write8
8772 Syntax: (gdb) pci_cfg_write8 <bus> <dev> <fcn> <off> <value>
8773 | write an 8-bit <value> into the given <off> of the pci device located at
8774 | <bus>:<dev>:<fcn>.
8777 document pci_cfg_write16
8778 Syntax: (gdb) pci_cfg_write16 <bus> <dev> <fcn> <off> <value>
8779 | write a 16-bit <value> into the given <off> of the pci device located at
8780 | <bus>:<dev>:<fcn>.
8783 document pci_cfg_write32
8784 Syntax: (gdb) pci_cfg_write32 <bus> <dev> <fcn> <off> <value>
8785 | write a 32-bit <value> into the given <off> of the pci device located at
8786 | <bus>:<dev>:<fcn>.
8796 # check for a valid pci device
8797 _pci_cfg_value $bus $dev $fcn $off 8
8798 if $kgm_pci_cfg_value > 0x0 && $kgm_pci_cfg_value < 0xff
8799 printf " address: 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F\n"
8800 printf "---------------------------------------------------------"
8803 _pci_cfg_value $bus $dev $fcn $off 32
8804 if ($off & 0xF) == 0
8805 printf "\n%08X: ", $kgm_pci_cfg_addr
8807 printf "%02X %02X %02X %02X ", $kgm_pci_cfg_value & 0xFF, ($kgm_pci_cfg_value >> 8) & 0xFF, ($kgm_pci_cfg_value >> 16) & 0xFF, ($kgm_pci_cfg_value >> 24) & 0xFF
8812 # check for pcie extended capability config space
8813 _pci_cfg_value $bus $dev $fcn $off 8
8814 if $kgm_pci_cfg_value < 0xff
8816 _pci_cfg_value $bus $dev $fcn $off 32
8817 if ($off & 0xF) == 0
8818 printf "\n%08X: ", $kgm_pci_cfg_addr
8820 printf "%02X %02X %02X %02X ", $kgm_pci_cfg_value & 0xFF, ($kgm_pci_cfg_value >> 8) & 0xFF, ($kgm_pci_cfg_value >> 16) & 0xFF, ($kgm_pci_cfg_value >> 24) & 0xFF
8828 document pci_cfg_dump
8829 Syntax: (gdb) pci_cfg_dump <bus> <dev> <fcn>
8830 | dump config space for the pci device located at <bus>:<dev>:<fcn>
8831 | if you specify an invalid/inaccessible pci device, nothing will be
8835 set $kgm_pci_cfg_bus_start = 0
8836 set $kgm_pci_cfg_bus_max = 8
8837 set $kgm_pci_cfg_device_max = 32
8838 set $kgm_pci_cfg_function_max = 8
8839 define _pci_cfg_scan
8842 set $bus = $kgm_pci_cfg_bus_start
8843 while $bus < $kgm_pci_cfg_bus_max
8844 # check for bus:0:0 to see if we should
8845 # probe this bus further
8846 _pci_cfg_value $bus 0x0 0x0 0x0 32
8847 if $kgm_pci_cfg_value > 0 && $kgm_pci_cfg_value < 0xFFFFFFFF
8850 while $dev < $kgm_pci_cfg_device_max
8853 while $fcn < $kgm_pci_cfg_function_max
8854 _pci_cfg_value $bus $dev $fcn 0x0 32
8855 if $kgm_pci_cfg_value > 0 && $kgm_pci_cfg_value < 0xFFFFFFFF
8857 printf "%03X:%03X:%03X: %02X%02X %02X%02X", $bus, $dev, $fcn, ($kgm_pci_cfg_value >> 8) & 0xFF, $kgm_pci_cfg_value & 0xFF, ($kgm_pci_cfg_value >> 24) & 0xFF, ($kgm_pci_cfg_value >> 16) & 0xFF
8858 _pci_cfg_value $bus $dev $fcn 0x8 32
8859 printf " %02X | %02X%02X%02X\n", $kgm_pci_cfg_value & 0xFF, ($kgm_pci_cfg_value >> 24) & 0xFF, ($kgm_pci_cfg_value >> 16) & 0xFF, ($kgm_pci_cfg_value >> 8) & 0xFF
8861 printf " device: %03X:%03X:%03X\n", $bus, $dev, $fcn
8862 pci_cfg_dump $bus $dev $fcn
8875 define pci_cfg_dump_all
8879 document pci_cfg_dump_all
8880 Syntax: (gdb) pci_cfg_dump_all
8881 | dump config spaces for scanned pci devices. the number of busses to scan
8882 | is stored in $kgm_pci_cfg_bus_max. the default for that is 8. you can also
8883 | specify the starting bus with $kgm_pci_cfg_bus_start.
8887 printf "bus:dev:fcn: vendor device rev | class\n"
8888 printf "---------------------------------------\n"
8892 document pci_cfg_scan
8893 Syntax: (gdb) pci_cfg_scan
8894 | scan for pci devices. the number of busses to scan is stored in
8895 | $kgm_pci_cfg_bus_max. the default for that is 8. you can also specify the
8896 | starting bus with $kgm_pci_cfg_bus_start.
8899 define readioportint
8900 set $kgm_readioportint_result = 0xBAD10AD
8901 # set up the manual KDP packet
8902 set manual_pkt.input = 0
8903 set manual_pkt.len = sizeof(kdp_readioport_req_t)
8904 set $kgm_pkt = (kdp_readioport_req_t *)&manual_pkt.data
8905 set $kgm_pkt->hdr.request = KDP_READIOPORT
8906 set $kgm_pkt->hdr.len = sizeof(kdp_readioport_req_t)
8907 set $kgm_pkt->hdr.is_reply = 0
8908 set $kgm_pkt->hdr.seq = 0
8909 set $kgm_pkt->hdr.key = 0
8910 set $kgm_pkt->address = (uint16_t)$arg0
8911 set $kgm_pkt->nbytes = $arg1 >> 3
8912 set $kgm_pkt->lcpu = (uint16_t)$arg2
8913 set manual_pkt.input = 1
8914 # dummy to make sure manual packet is executed
8915 set $kgm_dummy = &_mh_execute_header
8916 set $kgm_pkt = (kdp_readioport_reply_t *)&manual_pkt.data
8917 if ($kgm_pkt->error == 0)
8919 set $kgm_readioportint_result = *((uint8_t *) $kgm_pkt->data)
8922 set $kgm_readioportint_result = *((uint16_t *) $kgm_pkt->data)
8925 set $kgm_readioportint_result = *((uint32_t *) $kgm_pkt->data)
8931 set $lcpu = $kgm_lcpu_self
8935 readioportint $arg0 8 $lcpu
8937 printf ":\t0x%02hhx\n", $kgm_readioportint_result
8941 set $lcpu = $kgm_lcpu_self
8945 readioportint $arg0 16 $lcpu
8947 printf ":\t0x%04hx\n", $kgm_readioportint_result
8951 set $lcpu = $kgm_lcpu_self
8955 readioportint $arg0 32 $lcpu
8957 printf ":\t0x%08x\n", $kgm_readioportint_result
8960 document readioport8
8964 document readioport16
8968 document readioport32
8969 Syntax: (gdb) readioport32 <port> [lcpu (kernel's numbering convention)]
8970 | Read value stored in the specified IO port. The CPU can be optionally
8971 | specified as well.
8974 define writeioportint
8975 # set up the manual KDP packet
8976 set manual_pkt.input = 0
8977 set manual_pkt.len = sizeof(kdp_writeioport_req_t)
8978 set $kgm_pkt = (kdp_writeioport_req_t *)&manual_pkt.data
8979 set $kgm_pkt->hdr.request = KDP_WRITEIOPORT
8980 set $kgm_pkt->hdr.len = sizeof(kdp_writeioport_req_t)
8981 set $kgm_pkt->hdr.is_reply = 0
8982 set $kgm_pkt->hdr.seq = 0
8983 set $kgm_pkt->hdr.key = 0
8984 set $kgm_pkt->address = (uint16_t)$arg0
8985 set $kgm_pkt->nbytes = $arg1 >> 3
8986 set $kgm_pkt->lcpu = (uint16_t)$arg3
8988 set *(uint8_t *)$kgm_pkt->data = (uint8_t)$arg2
8991 set *(uint16_t *)$kgm_pkt->data = (uint16_t)$arg2
8994 set *(uint32_t *)$kgm_pkt->data = (uint32_t)$arg2
8996 set manual_pkt.input = 1
8997 # dummy to make sure manual packet is executed
8998 set $kgm_dummy = &_mh_execute_header
8999 set $kgm_pkt = (kdp_writeioport_reply_t *)&manual_pkt.data
9000 set $kgm_writeioportint_result = $kgm_pkt->error
9004 set $lcpu = $kgm_lcpu_self
9008 writeioportint $arg0 8 $arg1 $lcpu
9011 define writeioport16
9012 set $lcpu = $kgm_lcpu_self
9016 writeioportint $arg0 16 $arg1 $lcpu
9019 define writeioport32
9020 set $lcpu = $kgm_lcpu_self
9024 writeioportint $arg0 32 $arg1 $lcpu
9027 document writeioport8
9028 | See writeioport32.
9031 document writeioport16
9032 | See writeioport32.
9035 document writeioport32
9036 Syntax: (gdb) writeioport32 <port> <value> [lcpu (kernel's numbering convention)]
9037 | Write the value to the specified IO port. The size of the value is
9038 | determined by the name of the command. The CPU used can be optionally
9043 set $kgm_readmsr64int_result = 0xBAD10AD
9044 # set up the manual KDP packet
9045 set manual_pkt.input = 0
9046 set manual_pkt.len = sizeof(kdp_readmsr64_req_t)
9047 set $kgm_pkt = (kdp_readmsr64_req_t *)&manual_pkt.data
9048 set $kgm_pkt->hdr.request = KDP_READMSR64
9049 set $kgm_pkt->hdr.len = sizeof(kdp_readmsr64_req_t)
9050 set $kgm_pkt->hdr.is_reply = 0
9051 set $kgm_pkt->hdr.seq = 0
9052 set $kgm_pkt->hdr.key = 0
9053 set $kgm_pkt->address = (uint32_t)$arg0
9054 set $kgm_pkt->lcpu = (uint16_t)$arg1
9055 set manual_pkt.input = 1
9056 # dummy to make sure manual packet is executed
9057 set $kgm_dummy = &_mh_execute_header
9058 set $kgm_pkt = (kdp_readmsr64_reply_t *)&manual_pkt.data
9059 if ($kgm_pkt->error == 0)
9060 set $kgm_readmsr64int_result = *((uint64_t *) $kgm_pkt->data)
9065 set $lcpu = $kgm_lcpu_self
9069 readmsr64int $arg0 $lcpu
9071 printf ":\t0x%016llx\n", $kgm_readmsr64int_result
9074 define writemsr64int
9075 # set up the manual KDP packet
9076 set manual_pkt.input = 0
9077 set manual_pkt.len = sizeof(kdp_writemsr64_req_t)
9078 set $kgm_pkt = (kdp_writemsr64_req_t *)&manual_pkt.data
9079 set $kgm_pkt->hdr.request = KDP_WRITEMSR64
9080 set $kgm_pkt->hdr.len = sizeof(kdp_writemsr64_req_t)
9081 set $kgm_pkt->hdr.is_reply = 0
9082 set $kgm_pkt->hdr.seq = 0
9083 set $kgm_pkt->hdr.key = 0
9084 set $kgm_pkt->address = (uint32_t)$arg0
9085 set $kgm_pkt->lcpu = (uint16_t)$arg2
9086 set *(uint64_t *)$kgm_pkt->data = (uint64_t)$arg1
9087 set manual_pkt.input = 1
9088 # dummy to make sure manual packet is executed
9089 set $kgm_dummy = &_mh_execute_header
9090 set $kgm_pkt = (kdp_writemsr64_reply_t *)&manual_pkt.data
9091 set $kgm_writemsr64int_result = $kgm_pkt->error
9095 set $lcpu = $kgm_lcpu_self
9099 writemsr64int $arg0 $arg1 $lcpu
9103 Syntax: (gdb) writemsr64 <msr> <value> [lcpu (kernel's numbering convention)]
9104 | Write <value> to the specified MSR. The CPU can be optionally specified.
9108 Syntax: (gdb) readmsr64 <msr> [lcpu (kernel's numbering convention)]
9109 | Read the specified MSR. The CPU can be optionally specified.
9112 # default if we can't find a registry entry
9113 set $kgm_ioapic_addr = 0xFEC00000
9114 set $kgm_ioapic_init = 0
9116 set $_ioapic_index_off = 0x00
9117 set $_ioapic_data_off = 0x10
9118 set $_ioapic_eoi_off = 0x40
9120 set $_ioapic_index_id = 0x00
9121 set $_ioapic_index_ver = 0x01
9122 set $_ioapic_index_redir_base = 0x10
9124 set $_apic_vector_mask = 0xFF
9125 set $_apic_masked = 0x10000
9126 set $_apic_trigger_level = 0x08000
9127 set $_apic_polarity_high = 0x02000
9128 set $_apic_pending = 0x01000
9131 if $kgm_ioapic_init == 0
9132 strcmp_arg_pack64 'i' 'o' '-' 'a' 'p' 'i' 'c' 0
9133 setfindregistrystr $kgm_strcmp_arg
9135 set $olddepth = $kgm_reg_depth_max
9136 set $kgm_reg_depth_max = 3
9138 set $kgm_reg_depth_max = $olddepth
9140 if $kgm_registry_entry
9141 strcmp_arg_pack64 'P' 'h' 'y' 's' 'i' 'c' 'a' 'l'
9142 set $Physical = $kgm_strcmp_arg
9143 strcmp_arg_pack64 ' ' 'A' 'd' 'd' 'r' 'e' 's' 's'
9144 set $_Address = $kgm_strcmp_arg
9145 setfindregistrystr $Physical $_Address
9147 _findregistryprop $kgm_registry_entry
9148 if $kgm_registry_value
9149 set $kgm_ioapic_addr = ((OSNumber *) $kgm_registry_value)->value
9152 set $kgm_ioapic_index_addr = $kgm_ioapic_addr + $_ioapic_index_off
9153 set $kgm_ioapic_data_addr = $kgm_ioapic_addr + $_ioapic_data_off
9154 set $kgm_ioapic_init = 1
9158 define _ioapic_addr_value
9160 writephysint $kgm_ioapic_index_addr 8 $arg0 $kgm_lcpu_self
9162 writephysint $kgm_ioapic_data_addr 32 $arg1 $kgm_lcpu_self
9164 readphysint $kgm_ioapic_data_addr 32 $kgm_lcpu_self
9165 set $kgm_ioapic_value = $kgm_readphysint_result
9172 printf "[VEC=%3d ", $value & $_apic_vector_mask
9173 if $value & $_apic_masked
9179 if $value & $_apic_trigger_level
9180 printf "TRIG=level "
9185 if $value & $_apic_polarity_high
9191 if $value & $_apic_pending
9192 printf " PEND=yes]\n"
9194 printf " PEND=no ]\n"
9198 define ioapic_read32
9199 if (($kgm_mtype & $kgm_mtype_x86_mask) != $kgm_mtype_x86_any)
9200 printf "ioapic_read32 not supported on this architecture.\n"
9202 _ioapic_addr_value $arg0
9203 printf "IOAPIC[0x%02X]: 0x%08X\n", $arg0, $kgm_ioapic_value
9207 document ioapic_read32
9208 Syntax: (gdb) ioapic_read <offset>
9209 | Read the IOAPIC register at the offset specified.
9212 define ioapic_write32
9213 if (($kgm_mtype & $kgm_mtype_x86_mask) != $kgm_mtype_x86_any)
9214 printf "ioapic_write32 not supported on this architecture.\n"
9216 _ioapic_addr_value $arg0 $arg1
9220 document ioapic_write32
9221 Syntax: (gdb) ioapic_write32 <offset> <value>
9222 | Write the IOAPIC register at the offset specified.
9226 if (($kgm_mtype & $kgm_mtype_x86_mask) != $kgm_mtype_x86_any)
9227 printf "ioapic_dump not supported on this architecture.\n"
9230 _ioapic_addr_value $_ioapic_index_id
9231 printf "IOAPIC[0x%02X] ID: 0x%08X\n", $_ioapic_index_id, $kgm_ioapic_value
9234 _ioapic_addr_value $_ioapic_index_ver
9235 set $maxredir = (($kgm_ioapic_value & 0xFF0000) >> 16) + 1
9237 printf "IOAPIC[0x%02X] VERSION: 0x%08X [", $_ioapic_index_ver, $kgm_ioapic_value
9238 printf "MAXREDIR=%02d PRQ=%d VERSION=0x%02X]\n", $maxredir, ($kgm_ioapic_value >> 15) & 0x1, $kgm_ioapic_value & 0xFF
9240 # all the redir entries
9242 while $i < $maxredir
9243 set $addr0 = $_ioapic_index_redir_base + ($i << 1)
9244 set $addr1 = $addr0 + 1
9245 _ioapic_addr_value $addr1
9246 printf "IOAPIC[0x%02X] IOREDIR%02d: 0x%08X", $addr0, $i, $kgm_ioapic_value
9248 _ioapic_addr_value $addr0
9249 printf "%08X ", $kgm_ioapic_value
9250 _apic_print $kgm_ioapic_value
9256 document ioapic_dump
9257 Syntax: (gdb) ioapic_dump
9258 | Dump all the IOAPIC entries.
9262 set $_lapic_base_addr = 0xFEE00000
9263 set $_lapic_id = 0x20
9264 set $_lapic_version = 0x30
9265 set $_lapic_tpr = 0x80
9266 set $_lapic_apr = 0x90
9267 set $_lapic_ppr = 0xA0
9268 set $_lapic_eoi = 0xB0
9269 set $_lapic_ldr = 0xD0
9270 set $_lapic_dfr = 0xE0
9271 set $_lapic_sivr = 0xF0
9273 set $_lapic_isr_size = 0x10
9274 set $_lapic_isr_num = 8
9275 set $_lapic_isr0 = 0x100
9276 set $_lapic_tmr0 = 0x180
9277 set $_lapic_irr0 = 0x200
9279 set $_lapic_esr = 0x280
9280 set $_lapic_esr_register = 0x80
9281 set $_lapic_esr_recv_vect = 0x40
9282 set $_lapic_esr_send_vect = 0x20
9284 set $_lapic_icr0 = 0x300
9285 set $_lapic_icr1 = 0x310
9287 set $_lapic_lvt_timer = 0x320
9288 set $_lapic_lvt_thermal = 0x330
9289 set $_lapic_lvt_pmcr = 0x340
9290 set $_lapic_lvt_lint0 = 0x350
9291 set $_lapic_lvt_lint1 = 0x360
9292 set $_lapic_lvt_error = 0x370
9294 set $_lapic_icr = 0x380
9295 set $_lapic_ccr = 0x390
9296 set $_lapic_dcr = 0x3E0
9298 set $_apic_cfg_msr = 0x1B
9299 set $_apic_cfg_msr_x2EN = 0x00000C00
9300 set $_x2apic_enabled = -1
9302 # _lapic_addr $offset returns the actual address to use
9304 if $_x2apic_enabled < 0
9305 readmsr64int $_apic_cfg_msr $kgm_lcpu_self
9306 if ($kgm_readmsr64int_result & $_apic_cfg_msr_x2EN) == $_apic_cfg_msr_x2EN
9307 set $_x2apic_enabled = 1
9309 set $_x2apic_enabled = 0
9314 # x2APIC addresses are MSRs that use xAPIC offsets that
9316 set $kgm_lapic_addr = $arg0 >> 4
9318 set $kgm_lapic_addr = $_lapic_base_addr + $arg0
9322 # _lapic_addr_value $offset $lcpu
9323 define _lapic_addr_value
9326 readmsr64int $kgm_lapic_addr $arg1
9327 set $kgm_lapic_value = $kgm_readmsr64int_result
9329 readphysint $kgm_lapic_addr 32 $arg1
9330 set $kgm_lapic_value = $kgm_readphysint_result
9334 # lapic_read32 $offset [$lcpu]
9336 if (($kgm_mtype & $kgm_mtype_x86_mask) != $kgm_mtype_x86_any)
9337 printf "lapic_read32 not supported on this architecture.\n"
9339 set $lcpu = $kgm_lcpu_self
9343 _lapic_addr_value $arg0 $lcpu
9344 printf "LAPIC[0x%03X]: 0x%08X\n", $arg0, $kgm_lapic_value
9348 document lapic_read32
9349 Syntax: (gdb) apic_read32_cpu <offset> [lcpu (kernel's numbering convention)]
9350 | Read the LAPIC register at the offset specified. The CPU can be optionally
9354 # lapic_write32 $offset $value [$lcpu]
9355 define lapic_write32
9356 if (($kgm_mtype & $kgm_mtype_x86_mask) != $kgm_mtype_x86_any)
9357 printf "lapic_write32_cpu not supported on this architecture.\n"
9359 set $lcpu = $kgm_lcpu_self
9366 writemsr64int $kgm_lapic_addr $arg1 $lcpu
9368 writephysint $kgm_lapic_addr 32 $arg1 $lcpu
9373 document lapic_write32
9374 Syntax: (gdb) lapic_write32 <offset> <value> [lcpu (kernel's numbering convention)]
9375 | Write the LAPIC register at the offset specified. The CPU can be optionally
9381 if (($kgm_mtype & $kgm_mtype_x86_mask) != $kgm_mtype_x86_any)
9382 printf "lapic_dump not supported on this architecture.\n"
9384 set $lcpu = $kgm_lcpu_self
9389 _lapic_addr_value $_lapic_id $lcpu
9391 # the above also figures out if we're using an xAPIC or an x2APIC
9392 printf "LAPIC operating mode: "
9399 printf "LAPIC[0x%03X] ID: 0x%08X\n", $_lapic_id, $kgm_lapic_value
9401 _lapic_addr_value $_lapic_version $lcpu
9402 set $lvt_num = ($kgm_lapic_value >> 16) + 1
9403 printf "LAPIC[0x%03X] VERSION: 0x%08X [VERSION=%d MaxLVT=%d]\n", $_lapic_version, $kgm_lapic_value, $kgm_lapic_value & 0xFF, $lvt_num
9405 _lapic_addr_value $_lapic_tpr $lcpu
9406 printf "LAPIC[0x%03X] TASK PRIORITY: 0x%08X\n", $_lapic_tpr, $kgm_lapic_value
9408 _lapic_addr_value $_lapic_ppr $lcpu
9409 printf "LAPIC[0x%03X] PROCESSOR PRIORITY: 0x%08X\n", $_lapic_ppr, $kgm_lapic_value
9411 _lapic_addr_value $_lapic_ldr $lcpu
9412 printf "LAPIC[0x%03X] LOGICAL DEST: 0x%08X\n", $_lapic_ldr, $kgm_lapic_value
9414 _lapic_addr_value $_lapic_dfr $lcpu
9415 printf "LAPIC[0x%03X] DEST FORMAT: 0x%08X\n", $_lapic_dfr, $kgm_lapic_value
9417 _lapic_addr_value $_lapic_sivr $lcpu
9418 printf "LAPIC[0x%03X] SPURIOUS VECTOR: 0x%08X [VEC=%3d ENABLED=%d]\n", $_lapic_sivr, $kgm_lapic_value, $kgm_lapic_value & $_apic_vector_mask, ($kgm_lapic_value & 0x100) >> 8,
9421 while $i < $_lapic_isr_num
9422 set $addr = $_lapic_isr0 + $i * $_lapic_isr_size
9423 _lapic_addr_value $addr $lcpu
9424 printf "LAPIC[0x%03X] ISR[%03d:%03d]: 0x%08X\n", $addr, 32*($i + 1) - 1, 32*$i, $kgm_lapic_value
9429 while $i < $_lapic_isr_num
9430 set $addr = $_lapic_tmr0 + $i * $_lapic_isr_size
9431 _lapic_addr_value $addr $lcpu
9432 printf "LAPIC[0x%03X] TMR[%03d:%03d]: 0x%08X\n", $addr, 32*($i + 1) - 1, 32*$i, $kgm_lapic_value
9437 while $i < $_lapic_isr_num
9438 set $addr = $_lapic_irr0 + $i * $_lapic_isr_size
9439 _lapic_addr_value $addr $lcpu
9440 printf "LAPIC[0x%03X] IRR[%03d:%03d]: 0x%08X\n", $addr, 32*($i + 1) - 1, 32*$i, $kgm_lapic_value
9444 _lapic_addr_value $_lapic_esr $lcpu
9445 printf "LAPIC[0x%03X] ERROR STATUS: 0x%08X ", $_lapic_esr, $kgm_lapic_value
9449 if $kgm_lapic_value & $_lapic_esr_register
9452 if $kgm_lapic_value & $_lapic_esr_recv_vect
9453 printf "Received Vector "
9455 if $kgm_lapic_value & $_lapic_esr_send_vect
9456 printf "Send Vector"
9463 _lapic_addr_value $_lapic_icr1 $lcpu
9464 printf "LAPIC[0x%03X] Interrupt Command: 0x%08X [DEST=%d]\n", $_lapic_icr0, $kgm_lapic_value, $kgm_lapic_value >> 24
9465 _lapic_addr_value $_lapic_icr0 $lcpu
9466 printf " 0x%08X ", $kgm_lapic_value
9467 _apic_print $kgm_lapic_value
9470 _lapic_addr_value $_lapic_lvt_timer $lcpu
9471 printf "LAPIC[0x%03X] LVT Timer: 0x%08X ", $_lapic_lvt_timer, $kgm_lapic_value
9472 _apic_print $kgm_lapic_value
9476 _lapic_addr_value $_lapic_lvt_lint0 $lcpu
9477 printf "LAPIC[0x%03X] LVT LINT0: 0x%08X ", $_lapic_lvt_lint0, $kgm_lapic_value
9478 _apic_print $kgm_lapic_value
9482 _lapic_addr_value $_lapic_lvt_lint1 $lcpu
9483 printf "LAPIC[0x%03X] LVT LINT1: 0x%08X ", $_lapic_lvt_lint1, $kgm_lapic_value
9484 _apic_print $kgm_lapic_value
9488 _lapic_addr_value $_lapic_lvt_error $lcpu
9489 printf "LAPIC[0x%03X] LVT Error: 0x%08X ", $_lapic_lvt_error, $kgm_lapic_value
9490 _apic_print $kgm_lapic_value
9494 _lapic_addr_value $_lapic_lvt_pmcr $lcpu
9495 printf "LAPIC[0x%03X] LVT PerfMon: 0x%08X ", $_lapic_lvt_pmcr, $kgm_lapic_value
9496 _apic_print $kgm_lapic_value
9500 _lapic_addr_value $_lapic_lvt_thermal $lcpu
9501 printf "LAPIC[0x%03X] LVT Thermal: 0x%08X ", $_lapic_lvt_thermal, $kgm_lapic_value
9502 _apic_print $kgm_lapic_value
9505 _lapic_addr_value $_lapic_dcr $lcpu
9506 printf "LAPIC[0x%03X] Timer Divide: 0x%08X [Divide by ", $_lapic_dcr, $kgm_lapic_value
9507 set $kgm_lapic_value = ($kgm_lapic_value & 0x8) >> 1 | $kgm_lapic_value & 0x3
9508 if $kgm_lapic_value == 0x7
9511 printf "%d]\n", 2 << $kgm_lapic_value
9514 _lapic_addr_value $_lapic_icr $lcpu
9515 printf "LAPIC[0x%03X] Timer Init Count: 0x%08X\n", $_lapic_icr, $kgm_lapic_value
9517 _lapic_addr_value $_lapic_ccr $lcpu
9518 printf "LAPIC[0x%03X] Timer Cur Count: 0x%08X\n", $_lapic_ccr, $kgm_lapic_value
9523 Syntax: (gdb) lapic_dump [lcpu (kernel's numbering convention)]
9524 | Dump all the LAPIC entries. The CPU can be optionally specified.
9527 define showknoteheader
9528 printf " knote filter ident kn_ptr status\n"
9532 set $kgm_knotep = ((struct knote *) $arg0)
9536 set $kgm_filt = -$kgm_knotep->kn_kevent.filter
9538 printf "EVFILT_READ "
9541 printf "EVFILT_WRITE "
9544 printf "EVFILT_AIO "
9547 printf "EVFILT_VNODE "
9550 printf "EVFILT_PROC "
9553 printf "EVFILT_SIGNAL "
9556 printf "EVFILT_TIMER "
9559 printf "EVFILT_MACHPORT"
9564 if ($kgm_filt == 10)
9565 printf "EVFILT_USER "
9567 if ($kgm_filt == 11)
9568 printf "EVFILT_SESSION "
9570 printf "%7d ", $kgm_knotep->kn_kevent.ident
9571 showptr $kgm_knotep->kn_ptr.p_fp
9573 if ($kgm_knotep->kn_status == 0)
9576 if ($kgm_knotep->kn_status & 0x01)
9579 if ($kgm_knotep->kn_status & 0x02)
9582 if ($kgm_knotep->kn_status & 0x04)
9585 if ($kgm_knotep->kn_status & 0x08)
9588 if ($kgm_knotep->kn_status & 0x10)
9591 if ($kgm_knotep->kn_status & 0x20)
9594 if ($kgm_knotep->kn_status & 0x40)
9601 define showprocknotes
9603 set $kgm_fdp = ((proc_t)$arg0)->p_fd
9604 set $kgm_knlist = $kgm_fdp->fd_knlist
9606 while (($i < $kgm_fdp->fd_knlistsize) && ($kgm_knlist != 0))
9607 set $kgm_kn = ((struct knote *)$kgm_knlist[$i].slh_first)
9608 while ($kgm_kn != 0)
9609 showknoteint $kgm_kn
9610 set $kgm_kn = ((struct knote *)$kgm_kn->kn_link.sle_next)
9614 set $kgm_knhash = $kgm_fdp->fd_knhash
9616 while (($i < $kgm_fdp->fd_knhashmask + 1) && ($kgm_knhash != 0))
9617 set $kgm_kn = ((struct knote *)$kgm_knhash[$i].slh_first)
9618 while ($kgm_kn != 0)
9619 showknoteint $kgm_kn
9620 set $kgm_kn = ((struct knote *)$kgm_kn->kn_link.sle_next)
9626 define showallknotes
9627 set $kgm_head_taskp = &tasks
9628 set $kgm_taskp = (struct task *)($kgm_head_taskp->next)
9629 while $kgm_taskp != $kgm_head_taskp
9631 showtaskint $kgm_taskp
9632 showprocknotes $kgm_taskp->bsd_info
9633 set $kgm_taskp = (struct task *)($kgm_taskp->tasks.next)
9636 document showprocknotes
9637 Syntax: showprocknotes <proc>
9638 | Displays filter and status information for every kevent registered for
9643 # Device node related debug macros
9647 set $kgm_tty = (struct tty *) $arg0
9648 printf "tty struct at "
9651 printf "-last input to raw queue:\n"
9652 p $kgm_tty->t_rawq->c_cs
9653 printf "-last input to canonical queue:\n"
9654 p $kgm_tty->t_canq->c_cs
9655 printf "-last output data:\n"
9656 p $kgm_tty->t_outq->c_cs
9658 if ($kgm_tty->t_state & 0x00000001)
9659 printf " TS_SO_OLOWAT (Wake up when output <= low water)\n"
9661 if ($kgm_tty->t_state & 0x00000002)
9662 printf " TS_ASYNC (async I/O mode)\n"
9664 printf " - (synchronous I/O mode)\n"
9666 if ($kgm_tty->t_state & 0x00000004)
9667 printf " TS_BUSY (Draining output)\n"
9669 if ($kgm_tty->t_state & 0x00000008)
9670 printf " TS_CARR_ON (Carrier is present)\n"
9672 printf " - (Carrier is NOT present)\n"
9674 if ($kgm_tty->t_state & 0x00000010)
9675 printf " TS_FLUSH (Outq has been flushed during DMA)\n"
9677 if ($kgm_tty->t_state & 0x00000020)
9678 printf " TS_ISOPEN (Open has completed)\n"
9680 printf " - (Open has NOT completed)\n"
9682 if ($kgm_tty->t_state & 0x00000040)
9683 printf " TS_TBLOCK (Further input blocked)\n"
9685 if ($kgm_tty->t_state & 0x00000080)
9686 printf " TS_TIMEOUT (Wait for output char processing)\n"
9688 if ($kgm_tty->t_state & 0x00000100)
9689 printf " TS_TTSTOP (Output paused)\n"
9691 if ($kgm_tty->t_state & 0x00000200)
9692 printf " TS_WOPEN (Open in progress)\n"
9694 if ($kgm_tty->t_state & 0x00000400)
9695 printf " TS_XCLUDE (Tty requires exclusivity)\n"
9697 if ($kgm_tty->t_state & 0x00000800)
9698 printf " TS_BKSL (State for lowercase \\ work)\n"
9700 if ($kgm_tty->t_state & 0x00001000)
9701 printf " TS_CNTTB (Counting tab width, ignore FLUSHO)\n"
9703 if ($kgm_tty->t_state & 0x00002000)
9704 printf " TS_ERASE (Within a \\.../ for PRTRUB)\n"
9706 if ($kgm_tty->t_state & 0x00004000)
9707 printf " TS_LNCH (Next character is literal)\n"
9709 if ($kgm_tty->t_state & 0x00008000)
9710 printf " TS_TYPEN (Retyping suspended input (PENDIN))\n"
9712 if ($kgm_tty->t_state & 0x00010000)
9713 printf " TS_CAN_BYPASS_L_RINT (Device in "raw" mode)\n"
9715 if ($kgm_tty->t_state & 0x00020000)
9716 printf " TS_CONNECTED (Connection open)\n"
9718 printf " - (Connection NOT open)\n"
9720 if ($kgm_tty->t_state & 0x00040000)
9721 printf " TS_SNOOP (Device is being snooped on)\n"
9723 if ($kgm_tty->t_state & 0x80000)
9724 printf " TS_SO_OCOMPLETE (Wake up when output completes)\n"
9726 if ($kgm_tty->t_state & 0x00100000)
9727 printf " TS_ZOMBIE (Connection lost)\n"
9729 if ($kgm_tty->t_state & 0x00200000)
9730 printf " TS_CAR_OFLOW (For MDMBUF - handle in driver)\n"
9732 if ($kgm_tty->t_state & 0x00400000)
9733 printf " TS_CTS_OFLOW (For CCTS_OFLOW - handle in driver)\n"
9735 if ($kgm_tty->t_state & 0x00800000)
9736 printf " TS_DSR_OFLOW (For CDSR_OFLOW - handle in driver)\n"
9738 # xxx todo: do we care about decoding flags?
9739 printf "flags: 0x%08x\n", $kgm_tty->t_flags
9740 printf "foreground process group: "
9741 showptr $kgm_tty->t_pgrp
9743 printf "enclosing session: "
9744 showptr $kgm_tty->t_session
9747 # XXX todo: decode these flags, someday
9748 printf " Input flags: 0x%08x\n", $kgm_tty->t_termios.c_iflag
9749 printf " Output flags: 0x%08x\n", $kgm_tty->t_termios.c_oflag
9750 printf " Control flags: 0x%08x\n", $kgm_tty->t_termios.c_cflag
9751 printf " Local flags: 0x%08x\n", $kgm_tty->t_termios.c_lflag
9752 printf " Input speed: %d\n", $kgm_tty->t_termios.c_ispeed
9753 printf " Output speed: %d\n", $kgm_tty->t_termios.c_ospeed
9754 # XXX todo: useful to decode t_winsize? t_iokit? c_cc? anything else?
9755 printf "high watermark: %d bytes\n", $kgm_tty->t_hiwat
9756 printf "low watermark: %d bytes\n", $kgm_tty->t_lowat
9760 # _showwhohas <major> <minor>
9770 set $kgm_swh_devnode_dev = (((int) $arg0) << 24) | (int) $arg1
9771 # iterate all tasks to iterate all processes to iterate all
9772 # open files in each process to see who has a given major/minor
9774 set $kgm_taskp = (struct task *)($kgm_head_taskp->next)
9775 while $kgm_taskp != $kgm_head_taskp
9776 set $kgm_procp = (proc_t) $kgm_taskp->bsd_info
9777 set $kgm_spf_filedesc = $kgm_procp->p_fd
9778 set $kgm_spf_last = $kgm_spf_filedesc->fd_lastfile
9779 set $kgm_spf_ofiles = $kgm_spf_filedesc->fd_ofiles
9780 set $kgm_spf_count = 0
9781 while (($kgm_spf_ofiles != 0) && ($kgm_spf_count <= $kgm_spf_last))
9782 # only files currently open
9783 if ($kgm_spf_ofiles[$kgm_spf_count] != 0)
9784 set $kgm_spf_fg = $kgm_spf_ofiles[$kgm_spf_count].f_fglob
9785 if ($kgm_spf_fg->fg_type == 1)
9786 # display fd #, fileglob & vnode address, proc name
9787 set $kgm_swh_m_vnode = (vnode_t) $kgm_spf_fg->fg_data
9788 set $kgm_swh_m_vtype = (enum vtype) $kgm_swh_m_vnode->v_type
9789 if (($kgm_swh_m_vtype == VBLK) || ($kgm_swh_m_vtype == VCHR)) && ((((devnode_t *)$kgm_swh_m_vnode->v_data)->dn_typeinfo.dev) == $kgm_swh_devnode_dev)
9790 printf "%-5d ", $kgm_spf_count
9793 showptr $kgm_swh_m_vnode
9796 printf " %s\n", $kgm_procp->p_comm
9800 set $kgm_spf_count = $kgm_spf_count + 1
9803 set $kgm_taskp = (struct task *)($kgm_taskp->tasks.next)
9807 define _showvnodedev_cpty
9808 set $kgm_ptmx_major = (int) $arg0
9809 set $kgm_ptmx_minor = (int) $arg1
9810 set $kgm_ptmx_ioctl = _state.pis_ioctl_list[$kgm_ptmx_minor]
9811 set $kgm_ptmx_ioctl = _state.pis_ioctl_list[$kgm_ptmx_minor]
9812 printf " ptmx_ioctl struct at "
9813 showptr $kgm_ptmx_ioctl
9816 if ($kgm_ptmx_ioctl->pt_flags & 0x0008)
9817 printf " PF_PKT (packet mode)\n"
9819 if ($kgm_ptmx_ioctl->pt_flags & 0x0010)
9820 printf " PF_STOPPED (user told stopped)\n"
9822 if ($kgm_ptmx_ioctl->pt_flags & 0x0020)
9823 printf " PF_REMOTE (remote and flow controlled input)\n"
9825 if ($kgm_ptmx_ioctl->pt_flags & 0x0040)
9828 if ($kgm_ptmx_ioctl->pt_flags & 0x0080)
9829 printf " PF_UCNTL (user control mode)\n"
9831 if ($kgm_ptmx_ioctl->pt_flags & 0x0100)
9832 printf " PF_UNLOCKED (slave unlock - master open resets)\n"
9834 if ($kgm_ptmx_ioctl->pt_flags & 0x0200)
9835 printf " PF_OPEN_M (master is open)\n"
9836 # XXX we should search for who has the master open, but
9837 # XXX each master gets the same minor, even though it
9838 # XXX gets a different vnode. we chold probably change
9839 # XXX this, but to do it we would need some way of
9840 # XXX expressing the information in the vnode structure
9841 # XXX somewhere. If we *did* change it, it would buy us
9842 # XXX the ability to determine who has the corresponding
9843 # XXX master end of the pty open
9845 printf " PF_OPEN_M (master is closed)\n"
9847 if ($kgm_ptmx_ioctl->pt_flags & 0x0400)
9848 printf " PF_OPEN_S (slave is open)\n"
9849 printf "---vvvvv--- fds open on this device ---vvvvv---\n"
9850 _showwhohas ($kgm_ptmx_major) ($kgm_ptmx_minor)
9851 printf "---^^^^^--- fds open on this device ---^^^^^---\n"
9853 printf " - (slave is closed)\n"
9855 printf "TTY Specific Information\n"
9856 _showtty $kgm_ptmx_ioctl->pt_tty
9861 set $kgm_vnode = (vnode_t) $arg0
9862 set $kgm_vtype = (enum vtype) $kgm_vnode->v_type
9863 if (($kgm_vtype == VBLK) || ($kgm_vtype == VCHR))
9864 set $kgm_devnode = (devnode_t *) $kgm_vnode->v_data
9865 set $kgm_devnode_dev = $kgm_devnode->dn_typeinfo.dev
9866 set $kgm_devnode_major = ($kgm_devnode_dev >> 24) & 0xff
9867 set $kgm_devnode_minor = $kgm_devnode_dev & 0x00ffffff
9869 # boilerplate device information for a vnode
9870 printf "Device Info:\n"
9875 if ($kgm_vtype == VBLK)
9878 if ($kgm_vtype == VCHR)
9882 printf " name: %s\n", $kgm_vnode->v_name
9883 printf " major, minor: %d, %d\n", $kgm_devnode_major, $kgm_devnode_minor
9884 printf " mode 0%o\n", $kgm_devnode->dn_mode
9885 printf " owner (u,g): %d %d", $kgm_devnode->dn_uid, $kgm_devnode->dn_gid
9888 # decode device specific data
9889 printf "Device Specific Information: "
9890 if ($kgm_vtype == VBLK)
9891 printf " Sorry, I do not know how to decode block devices yet!\n"
9892 printf " Maybe you can write me!"
9894 if ($kgm_vtype == VCHR)
9895 # Device information; this is scanty
9897 if ($kgm_devnode_major > 42) || ($kgm_devnode_major < 0)
9898 printf "Invalid major #\n"
9900 # static assignments in conf
9901 if ($kgm_devnode_major == 0)
9902 printf "Console mux device\n"
9904 if ($kgm_devnode_major == 2)
9905 printf "Current tty alias\n"
9907 if ($kgm_devnode_major == 3)
9908 printf "NULL device\n"
9910 if ($kgm_devnode_major == 4)
9911 printf "Old pty slave\n"
9913 if ($kgm_devnode_major == 5)
9914 printf "Old pty master\n"
9916 if ($kgm_devnode_major == 6)
9917 printf "Kernel log\n"
9919 if ($kgm_devnode_major == 12)
9920 printf "Memory devices\n"
9922 # Statically linked dynamic assignments
9923 if cdevsw[$kgm_devnode_major].d_open == ptmx_open
9924 printf "Cloning pty master\n"
9925 _showvnodedev_cpty ($kgm_devnode_major) ($kgm_devnode_minor)
9927 if cdevsw[$kgm_devnode_major].d_open == ptsd_open
9928 printf "Cloning pty slave\n"
9929 _showvnodedev_cpty ($kgm_devnode_major) ($kgm_devnode_minor)
9931 printf "RESERVED SLOT\n"
9945 printf " is not a device\n"
9948 printf "| Usage:\n|\n"
9952 document showvnodedev
9953 Syntax: (gdb) showvnodedev <vnode>
9954 | showvnodedev Display information about a device vnode
9961 printf "| Usage:\n|\n"
9966 Syntax: (gdb) showtty <tty struct>
9967 | showtty Display information about a struct tty
9970 define showeventsourceobject
9971 set $kgm_vt = *((void **) $arg1)
9973 set $kgm_vt = $kgm_vt - 16
9977 document showeventsourceobject
9978 Syntax: (gdb) showeventsourceobject <prefix> <object>
9979 | Routine to display information about an IOEventSource subclass.
9982 define showworkloopeventsources
9983 set $kgm_eventsource = (struct IOEventSource*)$arg0
9984 while $kgm_eventsource != 0
9986 printf "EventSource:\t"
9987 showptr $kgm_eventsource
9988 printf " Description: "
9989 showeventsourceobject _ $kgm_eventsource
9991 if $kgm_eventsource->action != 0
9994 pcprint $kgm_eventsource->action
9997 if $kgm_eventsource->owner != 0
10000 showptr $kgm_eventsource->owner
10001 printf " Description: "
10002 showeventsourceobject _ $kgm_eventsource->owner
10005 set $kgm_eventsource = $kgm_eventsource->eventChainNext
10009 document showworkloopeventsources
10010 Syntax: (gdb) showworkloopeventsources
10011 | Routine to walk an IOEventSource chain associated with an IOWorkLoop and print information
10012 | about each event source in the chain.
10015 define showworkloopheader
10018 printf " workloop "
10020 printf " pri state\tLockGroupName\n"
10022 document showworkloopheader
10023 Syntax: (gdb) showworkloopheader
10024 | Routine to print out header info about an IOKit workloop.
10027 define showworkloop
10028 set $kgm_workloopthread = (struct thread*)$arg0
10029 set $kgm_workloop = (struct IOWorkLoop*)$arg1
10030 showptr $kgm_workloopthread
10032 showptr $kgm_workloop
10033 printf " %3d ", $kgm_workloopthread.sched_pri
10034 set $kgm_state = $kgm_workloopthread.state
10035 if $kgm_state & 0x80
10038 if $kgm_state & 0x40
10041 if $kgm_state & 0x20
10044 if $kgm_state & 0x10
10047 if $kgm_state & 0x08
10050 if $kgm_state & 0x04
10053 if $kgm_state & 0x02
10056 if $kgm_state & 0x01
10060 set $kgm_gateLock = ( struct _IORecursiveLock *)$kgm_workloop->gateLock
10061 set $kgm_lockGroup = (struct _lck_grp_*)($kgm_gateLock->group)
10062 printf "%s", $kgm_lockGroup->lck_grp_name
10064 showworkloopeventsources $kgm_workloop->eventChain
10066 document showworkloop
10067 Syntax: (gdb) showworkloop <thread> <workloop>
10068 | Routine to print out info about an IOKit workloop.
10071 define showallworkloopthreads
10072 set $kgm_head_taskp = &tasks
10073 set $kgm_taskp = (struct task *)($kgm_head_taskp->next)
10074 set $kgm_head_actp = &($kgm_taskp->threads)
10075 set $kgm_actp = (struct thread *)($kgm_taskp->threads.next)
10076 while $kgm_actp != $kgm_head_actp
10077 if ($kgm_actp->continuation == _ZN10IOWorkLoop10threadMainEv)
10079 showworkloop $kgm_actp $kgm_actp->parameter
10081 if ($kgm_actp->kernel_stack != 0)
10082 if ($kgm_mtype == $kgm_mtype_x86_64)
10083 #Warning: Grokking stack looking for hopeful workloops until we squirrel some info in thread_t.
10084 set $kgm_workloop = *((struct IOWorkLoop **)($kgm_actp->kernel_stack + kernel_stack_size - 0xB8))
10086 if ($kgm_mtype == $kgm_mtype_i386)
10087 set $kgm_workloop = *((struct IOWorkLoop **)($kgm_actp->kernel_stack + kernel_stack_size - 0x3C))
10090 if ($kgm_workloop != 0)
10091 set $kgm_vt = *((void **) $kgm_workloop)
10093 set $kgm_vt = $kgm_vt - 16
10095 if ($kgm_vt == &_ZTV10IOWorkLoop)
10097 showworkloop $kgm_actp $kgm_workloop
10102 set $kgm_actp = (struct thread *)($kgm_actp->task_threads.next)
10106 document showallworkloopthreads
10107 Syntax: (gdb) showallworkloopthreads
10108 | Routine to print out info about all IOKit workloop threads in the system. This macro will find
10109 | all IOWorkLoop threads blocked in continuations and on i386 and x86_64 systems will make a
10110 | best-effort guess to find any workloops that are actually not blocked in a continuation. For a
10111 | complete list, it is best to compare the output of this macro against the output of 'showallstacks'.
10114 define showthreadfortid
10115 set $kgm_id_found = 0
10117 set $kgm_head_taskp = &tasks
10118 set $kgm_taskp = (struct task *)($kgm_head_taskp->next)
10119 while $kgm_taskp != $kgm_head_taskp
10120 set $kgm_head_actp = &($kgm_taskp->threads)
10121 set $kgm_actp = (struct thread *)($kgm_taskp->threads.next)
10122 while $kgm_actp != $kgm_head_actp
10123 set $kgm_thread = *(struct thread *)$kgm_actp
10124 set $kgm_thread_id = $kgm_thread.thread_id
10125 if ($kgm_thread_id == $arg0)
10128 set $kgm_id_found = 1
10131 set $kgm_actp = (struct thread *)($kgm_actp->task_threads.next)
10133 if ($kgm_id_found == 1)
10136 set $kgm_taskp = (struct task *)($kgm_taskp->tasks.next)
10138 if ($kgm_id_found == 0)
10139 printf "Not a valid thread_id\n"
10143 document showthreadfortid
10144 Syntax: showthreadfortid <thread_id>
10145 |The thread structure contains a unique thread_id value for each thread.
10146 |This command is used to retrieve the address of the thread structure(thread_t)
10147 |corresponding to a given thread_id.
10150 define showtaskbusyports
10151 set $kgm_isp = ((task_t)$arg0)->itk_space
10152 set $kgm_iindex = 0
10153 while ( $kgm_iindex < $kgm_isp->is_table_size )
10154 set $kgm_iep = &($kgm_isp->is_table[$kgm_iindex])
10155 if $kgm_iep->ie_bits & 0x00020000
10156 set $kgm_port = ((ipc_port_t)$kgm_iep->ie_object)
10157 if $kgm_port->ip_messages.data.port.msgcount > 0
10161 set $kgm_iindex = $kgm_iindex + 1
10165 document showtaskbusyports
10166 Syntax: showtaskbusyports <task>
10167 |Routine to print information about receive rights belonging to this task that
10168 |have enqueued messages. This is often a sign of a blocked or hung process.
10171 define showallbusyports
10172 set $kgm_head_taskp = &tasks
10173 set $kgm_cur_taskp = (struct task *)($kgm_head_taskp->next)
10174 while $kgm_cur_taskp != $kgm_head_taskp
10175 showtaskbusyports $kgm_cur_taskp
10176 set $kgm_cur_taskp = (struct task *)($kgm_cur_taskp->tasks.next)
10180 document showallbusyports
10181 Syntax: showallbusyports
10182 |Routine to print information about all receive rights on the system that
10183 |have enqueued messages.