4 # These gdb macros should be useful during kernel development in
5 # determining what's going on in the kernel.
7 # All the convenience variables used by these macros begin with $kgm_
9 set print asm-demangle on
12 # This option tells gdb to relax its stack tracing heuristics
13 # Useful for debugging across stack switches
14 # (to the interrupt stack, for instance). Requires gdb-675 or greater.
15 set backtrace sanity-checks off
17 echo Loading Kernel GDB Macros package. Type "help kgm" for more info.\n
21 echo These are the gdb macros for kernel debugging. Type "help kgm" for more info.\n
25 | These are the kernel gdb macros. These gdb macros are intended to be
26 | used when debugging a remote kernel via the kdp protocol. Typically, you
27 | would connect to your remote target like so:
28 | (gdb) target remote-kdp
29 | (gdb) attach <name-of-remote-host>
31 | The following macros are available in this package:
32 | showversion Displays a string describing the remote kernel version
34 | showalltasks Display a summary listing of all tasks
35 | showallthreads Display info about all threads in the system
36 | showallstacks Display the stack for each thread in the system
37 | showcurrentthreads Display info about the thread running on each cpu
38 | showcurrentstacks Display the stack for the thread running on each cpu
39 | showallvm Display a summary listing of all the vm maps
40 | showallvme Display a summary listing of all the vm map entries
41 | showallipc Display a summary listing of all the ipc spaces
42 | showipcsummary Display a summary listing of the ipc spaces of all tasks
43 | showallrights Display a summary listing of all the ipc rights
44 | showallkexts Display a summary listing of all loaded kexts (alias: showallkmods)
45 | showallknownkexts Display a summary listing of all kexts, loaded or not
46 | showallbusyports Display a listing of all ports with unread messages
47 | showallprocessors Display a listing of all psets and processors
49 | showallclasses Display info about all OSObject subclasses in the system
50 | showobject Show info about an OSObject - its vtable ptr and retain count, & more info for simple container classes.
51 | showregistry Show info about all registry entries in the current plane
52 | showregistryprops Show info about all registry entries in the current plane, and their properties
53 | showregistryentry Show info about a registry entry; its properties and descendants in the current plane
54 | setregistryplane Set the plane to be used for the iokit registry macros (pass zero for list)
56 | setfindregistrystr Set the encoded string for matching with
57 | findregistryentry or findregistryprop (created from
59 | findregistryentry Find a registry entry that matches the encoded string
60 | findregistryentries Find all the registry entries that match the encoded string
61 | findregistryprop Search the registry entry for a property that matches
64 | showtask Display info about the specified task
65 | showtaskthreads Display info about the threads in the task
66 | showtaskstacks Display the stack for each thread in the task
67 | showtaskvm Display info about the specified task's vm_map
68 | showtaskvme Display info about the task's vm_map entries
69 | showtaskipc Display info about the specified task's ipc space
70 | showtaskrights Display info about the task's ipc space entries
71 | showtaskrightsbt Display info about the task's ipc space entries with back traces
72 | showtaskbusyports Display all of the task's ports with unread messages
74 | showact Display info about a thread specified by activation
75 | showactstack Display the stack for a thread specified by activation
77 | showmap Display info about the specified vm_map
78 | showmapvme Display a summary list of the specified vm_map's entries
80 | showipc Display info about the specified ipc space
81 | showrights Display a summary list of all the rights in an ipc space
83 | showpid Display info about the process identified by pid
84 | showproc Display info about the process identified by proc struct
85 | showprocinfo Display detailed info about the process identified by proc struct
86 | showprocfiles Given a proc_t pointer, display the list of open file descriptors
87 | showproclocks Given a proc_t pointer, display the list of advisory file locks
88 | zombproc Print out all procs in the zombie list
89 | showproctree Show all the processes in a hierarchical tree form
90 | allproc Print out all process in the system not in the zombie list
91 | zombstacks Print out all stacks of tasks that are exiting
93 | showinitchild Print out all processes in the system which are children of init process
95 | showkext Display info about a kext (alias: showkmod)
96 | showkextaddr Given an address, display the kext and offset (alias: showkmodaddr)
98 | dumpcallqueue Dump out all the entries given a queue head
100 | showallmtx Display info about mutexes usage
101 | showallrwlck Display info about reader/writer locks usage
103 | zprint Display info about the memory zones
104 | showioalloc Display info about iokit allocations
105 | paniclog Display the panic log info
107 | switchtoact Switch to different context specified by activation
108 | switchtoctx Switch to different context
109 | showuserstack Display numeric backtrace of the user stack for an
111 | showtaskuserstacks Display user stacks for a specified task
112 | showuserregisters Display user registers for the specified thread
113 | showtaskuserregisters Display user registers for the specified task
115 | switchtouserthread Switch to the user context of the specified thread
116 | resetstacks Return to the original kernel context
118 | resetctx Reset context
119 | resume_on Resume when detaching from gdb
120 | resume_off Don't resume when detaching from gdb
122 | sendcore Configure kernel to send a coredump to the specified IP
123 | sendsyslog Configure kernel to send a system log to the specified IP
124 | sendpaniclog Configure kernel to send a panic log to the specified IP
125 | disablecore Configure the kernel to disable coredump transmission
126 | getdumpinfo Retrieve the current remote dump parameters
127 | setdumpinfo Configure the remote dump parameters
129 | switchtocorethread Corefile version of "switchtoact"
130 | resetcorectx Corefile version of "resetctx"
132 | readphys8 Reads the specified untranslated address (8-bit read)
133 | readphys16 Reads the specified untranslated address (16-bit read)
134 | readphys32 Reads the specified untranslated address (32-bit read)
135 | readphys64 Reads the specified untranslated address (64-bit read)
136 | writephys8 Writes to the specified untranslated address (8-bit write)
137 | writephys16 Writes to the specified untranslated address (16-bit write)
138 | writephys32 Writes to the specified untranslated address (32-bit write)
139 | writephys64 Writes to the specified untranslated address (64-bit write)
141 | readioport8 Read 8-bits from the specified I/O Port
142 | readioport16 Read 16-bits from the specified I/O Port
143 | readioport32 Read 32-bits from the specified I/O Port
144 | writeioport8 Write 8-bits into the specified I/O Port
145 | writeioport16 Write 16-bits into the specified I/O Port
146 | writeioport32 Write 32-bits into the specified I/O Port
148 | readmsr64 Read 64-bits from the specified MSR
149 | writemsr64 Write 64-bits into the specified MSR
151 | rtentry_showdbg Print the debug information of a route entry
152 | rtentry_trash Walk the list of trash route entries
154 | inifa_showdbg Print the debug information of an IPv4 interface address
155 | in6ifa_showdbg Print the debug information of an IPv6 interface address
156 | inm_showdbg Print the debug information of an IPv4 multicast address
157 | ifma_showdbg Print the debug information of a link multicast address
158 | ifpref_showdbg Print the debug information of an interface ref count
160 | ndpr_showdbg Print the debug information of a nd_prefix structure
161 | nddr_showdbg Print the debug information of a nd_defrouter structure
163 | imo_showdbg Print the debug information of a ip_moptions structure
164 | im6o_showdbg Print the debug information of a ip6_moptions structure
166 | inifa_trash Walk the list of trash in_ifaddr entries
167 | in6ifa_trash Walk the list of trash in6_ifaddr entries
168 | inm_trash Walk the list of trash in_multi entries
169 | in6m_trash Walk the list of trash in6_multi entries
170 | ifma_trash Walk the list of trash ifmultiaddr entries
172 | mbuf_walkpkt Walk the mbuf packet chain (m_nextpkt)
173 | mbuf_walk Walk the mbuf chain (m_next)
174 | mbuf_buf2slab Find the slab structure of the corresponding buffer
175 | mbuf_buf2mca Find the mcache audit structure of the corresponding mbuf
176 | mbuf_showmca Print the contents of an mbuf mcache audit structure
177 | mbuf_showactive Print all active/in-use mbuf objects
178 | mbuf_showinactive Print all freed/in-cache mbuf objects
179 | mbuf_showall Print all mbuf objects
180 | mbuf_slabs Print all slabs in the group
181 | mbuf_slabstbl Print slabs table
182 | mbuf_stat Print extended mbuf allocator statistics
183 | mbuf_countchain Count the length of an mbuf chain
184 | mbuf_topleak Print the top suspected mbuf leakers
185 | mbuf_traceleak Print the leak information for a given leak address
187 | mcache_walkobj Walk the mcache object chain (obj_next)
188 | mcache_stat Print all mcaches in the system
189 | mcache_showcache Display the number of objects in the cache
191 | showbootargs Display boot arguments passed to the target kernel
192 | showbootermemorymap Dump phys memory map from EFI
194 | systemlog Display the kernel's printf ring buffer
196 | hexdump Show the contents of memory as a hex/ASCII dump
198 | showvnodepath Print the path for a vnode
199 | showvnodelocks Display list of advisory locks held/blocked on a vnode
200 | showvnodedev Display information about a device vnode
201 | showtty Display information about a struct tty
202 | showallvols Display a summary of mounted volumes
203 | showvnode Display info about one vnode
204 | showvolvnodes Display info about all vnodes of a given volume
205 | showvolbusyvnodes Display info about busy (iocount!=0) vnodes of a given volume
206 | showallbusyvnodes Display info about all busy (iocount!=0) vnodes
207 | showallvnodes Display info about all vnodes
208 | print_vnode Print out the fields of a vnode struct
209 | showprocvnodes Print out all the open fds which are vnodes in a process
210 | showallprocvnodes Print out all the open fds which are vnodes in any process
211 | showmountvnodes Print the vnode list
212 | showmountallvnodes Print the vnode inactive list
213 | showworkqvnodes Print the vnode worker list
214 | shownewvnodes Print the new vnode list
216 | ifconfig display ifconfig-like output
217 | showifnets show the list of attached and detached interfaces
218 | showifaddrs show the list of addresses for the given ifp
219 | showifmultiaddrs show the list of multicast addresses for the given ifp
220 | showinmultiaddrs show the list of IPv4 multicast addresses records
221 | showin6multiaddrs show the list of IPv6 multicast addresses records
223 | showsocket Display information about a socket
224 | showprocsockets Given a proc_t pointer, display information about its sockets
225 | showallprocsockets Display information about the sockets of all the processes
227 | show_tcp_pcbinfo Display the list of the TCP protocol control blocks
228 | show_tcp_timewaitslots Display the list of the TCP protocol control blocks in TIMEWAIT
229 | show_udp_pcbinfo Display the list of UDP protocol control blocks
231 | show_rt_inet Display the IPv4 routing table
232 | show_rt_inet6 Display the IPv6 routing table
234 | showpmworkqueue Display the IOPMWorkQueue object
235 | showregistrypmstate Display power management state for all IOPower registry entries
236 | showioservicepm Display the IOServicePM object
237 | showstacksaftertask showallstacks starting after a given task
238 | showstacksafterthread showallstacks starting after a given thread
240 | showMCAstate Print machine-check register state after MC exception.
242 | showallgdbstacks Cause GDB to trace all thread stacks
243 | showallgdbcorestacks Corefile equivalent of "showallgdbstacks"
244 | kdp-reenter Schedule reentry into the debugger and continue.
245 | kdp-reboot Restart remote target
246 | kdp-version Get KDP version number
248 | zstack Print zalloc caller stack (zone leak debugging)
249 | findoldest Find oldest zone leak debugging record
250 | countpcs Print how often a pc occurs in the zone leak log
252 | showtopztrace Print the ztrace with the most outstanding allocated memory
253 | showztrace Print a backtrace record given its index
254 | showzalloc Print an allocation record + stacktrace at index
255 | showztraceaddr Print a backtrace record given its address
256 | showztracesabove Print all the backtrace records with a size bigger than X
257 | showzstacktrace Symbolicate and print a stored OSBacktrace
259 | showztraces Finds all in-use traces in the ztraces table
260 | showzallocs Finds all in-use allocations in the zallocs table
261 | showzstats Shows the statistics gathered about the hash tables
263 | showzallocsfortrace Print all the allocations that refer to a trace
264 | showztracehistogram Prints a histogram of the ztraces table
265 | showzallochistogram Prints a histogram of the zallocs table
267 | pmap_walk Perform a page-table walk
268 | pmap_vtop Translate a virtual address to physical address
270 | showuserdyldinfo Show dyld information and error messages
272 | showuserlibraries Show binary images known by dyld in the
274 | showallvmstats Prints a summary of vm statistics in a table format
275 | memstats Displays memory statistics in a table format
277 | showthreadfortid Displays the address of the thread structure
278 | for a given thread_id value.
280 | strcmp_nomalloc A version of strcmp that avoids the use of malloc
281 | through the use of encoded strings created via
283 | strcmp_arg_pack64 Pack a string into a 64-bit quantity for use by
286 | pci_cfg_read8 Read 8-bits from a PCI config space register
287 | pci_cfg_read16 Read 16-bits from a PCI config space register
288 | pci_cfg_read32 Read 32-bits from a PCI config space register
289 | pci_cfg_write8 Write 8-bits into a PCI config space register
290 | pci_cfg_write16 Write 16-bits into a PCI config space register
291 | pci_cfg_write32 Write 32-bits into a PCI config space register
292 | pci_cfg_dump Dump entire config space for a PCI device
293 | pci_cfg_scan Perform a scan for PCI devices
294 | pci_cfg_dump_all Dump config spaces for all detected PCI devices
296 | lapic_read32 Read APIC entry
297 | lapic_write32 Write APIC entry
298 | lapic_dump Dump APIC entries
300 | ioapic_read32 Read IOAPIC entry
301 | ioapic_write32 Write IOAPIC entry
302 | ioapic_dump Dump IOAPIC entries
304 | showallproviders Display summary listing of all dtrace_providers
305 | showallmodctls Display summary listing of all dtrace modctls
306 | showmodctl Display info about a dtrace modctl
307 | showfbtprobe Display info about an fbt probe given an id (traverses fbt_probetab)
308 | processortimers Display all processor timers, noting any inconsistencies
310 | Type "help <macro>" for more specific help on a particular macro.
311 | Type "show user <macro>" to see what the macro is really doing.
314 # This macro should appear before any symbol references, to facilitate
315 # a gdb "source" without a loaded symbol file.
322 | Read the kernel version string from a fixed address in low
323 | memory. Useful if you don't know which kernel is on the other end,
324 | and need to find the appropriate symbols. Beware that if you've
325 | loaded a symbol file, but aren't connected to a remote target,
326 | the version string from the symbol file will be displayed instead.
327 | This macro expects to be connected to the remote kernel to function
331 set $kgm_mtype_ppc = 0x00000012
332 set $kgm_mtype_arm = 0x0000000C
334 set $kgm_mtype_i386 = 0x00000007
335 set $kgm_mtype_x86_64 = 0x01000007
336 set $kgm_mtype_x86_any = $kgm_mtype_i386
337 set $kgm_mtype_x86_mask = 0xFEFFFFFF
339 set $kgm_mtype = ((unsigned int *)&_mh_execute_header)[1]
340 set $kgm_lp64 = $kgm_mtype & 0x01000000
342 set $kgm_manual_pkt_ppc = 0x549C
343 set $kgm_manual_pkt_i386 = 0x249C
344 set $kgm_manual_pkt_x86_64 = 0xFFFFFF8000002930
345 set $kgm_manual_pkt_arm = 0xFFFF04A0
347 set $kgm_kdp_pkt_data_len = 128
349 # part of data packet
350 set $kgm_kdp_pkt_hdr_req_off = 0
351 set $kgm_kdp_pkt_hdr_seq_off = 1
352 set $kgm_kdp_pkt_hdr_len_off = 2
353 set $kgm_kdp_pkt_hdr_key_off = 4
356 set $kgm_kdp_pkt_len_off = $kgm_kdp_pkt_data_len
357 set $kgm_kdp_pkt_input_off = $kgm_kdp_pkt_data_len + 4
359 set $kgm_kdp_pkt_hostreboot = 0x13
360 set $kgm_kdp_pkt_hdr_size = 8
363 set $kgm_readphys_force_kdp = 0
364 set $kgm_readphys_force_physmap = 0
366 set $kgm_lcpu_self = 0xFFFE
368 set $kgm_reg_depth = 0
369 set $kgm_reg_depth_max = 0xFFFF
370 set $kgm_reg_plane = (IORegistryPlane *) gIOServicePlane
371 set $kgm_namekey = (OSSymbol *) 0
372 set $kgm_childkey = (OSSymbol *) 0
374 set $kgm_show_object_addrs = 0
375 set $kgm_show_object_retain = 0
376 set $kgm_show_props = 0
377 set $kgm_show_data_alwaysbytes = 0
379 set $kgm_show_kmod_syms = 0
381 # send a manual packet header that doesn't require knowing the location
386 set $hdrp = (uint32_t *) $kgm_manual_pkt_i386
387 if ($kgm_mtype == $kgm_mtype_ppc)
388 set $hdrp = (uint32_t *) $kgm_manual_pkt_ppc
389 set $req = $req << 1 # shift to deal with endiannness
391 if ($kgm_mtype == $kgm_mtype_x86_64)
392 set $hdrp = (uint64_t *) $kgm_manual_pkt_x86_64
394 if ($kgm_mtype == $kgm_mtype_arm)
395 set $hdrp = (uint32_t *) $kgm_manual_pkt_arm
398 set $pkt_hdr = *$hdrp
399 set *((uint8_t *) ($pkt_hdr + $kgm_kdp_pkt_input_off)) = 0
400 set *((uint32_t *) ($pkt_hdr + $kgm_kdp_pkt_len_off)) = $kgm_kdp_pkt_hdr_size
402 set *((uint8_t *) ($pkt_hdr + $kgm_kdp_pkt_hdr_req_off)) = $req
403 set *((uint8_t *) ($pkt_hdr + $kgm_kdp_pkt_hdr_seq_off)) = 0
404 set *((uint16_t *) ($pkt_hdr + $kgm_kdp_pkt_hdr_len_off)) = $kgm_kdp_pkt_hdr_size
405 set *((uint32_t *) ($pkt_hdr + $kgm_kdp_pkt_hdr_key_off)) = 0
406 set *((uint8_t *) ($pkt_hdr + $kgm_kdp_pkt_input_off)) = 1
408 # dummy to make sure manual packet is executed
409 set $kgm_dummy = &_mh_execute_header
415 printf "0x%016llx", $arg0
417 printf "0x%08x", $arg0
421 # for headers, leave 8 chars for LP64 pointers
428 # Print a userspace pointer, using $kgm_tasp
430 set $kgm_userptr_task_64 = ( $kgm_taskp->taskFeatures[0] & 0x80000000)
431 if $kgm_userptr_task_64
432 printf "0x%016llx", $arg0
434 printf "0x%08x", $arg0
438 define showkmodheader
445 printf " id refs version name\n"
449 set $kgm_kmodp = (struct kmod_info *)$arg0
452 showptr $kgm_kmodp->address
454 showptr $kgm_kmodp->size
456 printf "%3d ", $kgm_kmodp->id
457 printf "%5d ", $kgm_kmodp->reference_count
458 printf "%10s ", $kgm_kmodp->version
459 printf "%s\n", $kgm_kmodp->name
462 # cached info of the last kext found, to speed up subsequent lookups
467 define showkmodaddrint
469 if ((unsigned long)$arg0 >= (unsigned long)$kgm_pkmodst) && ((unsigned long)$arg0 < (unsigned long)$kgm_pkmoden)
470 set $kgm_off = ((unsigned long)$arg0 - (unsigned long)$kgm_pkmodst)
471 printf " <%s + 0x%x>", $kgm_pkmod->name, $kgm_off
473 set $kgm_kmodp = (struct kmod_info *)kmod
474 if ($kgm_mtype == $kgm_mtype_x86_64) && ($arg0 >= (unsigned long)&_mh_execute_header)
475 # kexts are loaded below the kernel for x86_64
479 set $kgm_off = ((unsigned long)$arg0 - (unsigned long)$kgm_kmodp->address)
480 if ($kgm_kmodp->address <= $arg0) && ($kgm_off < $kgm_kmodp->size)
481 printf " <%s + 0x%x>", $kgm_kmodp->name, $kgm_off
482 set $kgm_pkmod = $kgm_kmodp
483 set $kgm_pkmodst = $kgm_kmodp->address
484 set $kgm_pkmoden = $kgm_pkmodst + $kgm_kmodp->size
487 set $kgm_kmodp = $kgm_kmodp->next
494 showkmodaddrint $arg0
496 document showkmodaddr
497 Syntax: (gdb) showkmodaddr <addr>
498 | Given an address, print the offset and name for the kmod containing it
506 Syntax: (gdb) showkmod <kmod>
507 | Routine to print info about a kext
514 Syntax: (gdb) showkext <kmod_info_address>
515 | Routine to print info about a kext
520 set $kgm_kmodp = (struct kmod_info *)kmod
522 showkmodint $kgm_kmodp
523 set $kgm_kmodp = $kgm_kmodp->next
526 document showallkmods
527 Syntax: (gdb) showallkmods
528 | Routine to print a summary listing of all loaded kexts
534 document showallkexts
535 Syntax: (gdb) showallkexts
536 | Routine to print a summary listing of all loaded kexts
539 # See OSKextVersion.c for the C code this is based on
541 set $KGM_OSKEXT_VERS_MAJ_MULT = 100000000
542 set $KGM_OSKEXT_VERS_MIN_MULT = 1000000
543 set $KGM_OSKEXT_VERS_REV_MULT = 10000
544 set $KGM_OSKEXT_VERS_STAGE_MULT = 1000
546 define printoskextversion
547 set $vers_scratch = $arg0
549 if ($vers_scratch == -1)
553 set $vers_major = $vers_scratch / $KGM_OSKEXT_VERS_MAJ_MULT
555 set $vers_scratch = $vers_scratch - ($vers_major * $KGM_OSKEXT_VERS_MAJ_MULT)
556 set $vers_minor = $vers_scratch / $KGM_OSKEXT_VERS_MIN_MULT
558 set $vers_scratch = $vers_scratch - ( $vers_minor * $KGM_OSKEXT_VERS_MIN_MULT)
559 set $vers_revision = $vers_scratch / $KGM_OSKEXT_VERS_REV_MULT
561 set $vers_scratch = $vers_scratch - ( $vers_revision * $KGM_OSKEXT_VERS_REV_MULT)
562 set $vers_stage = $vers_scratch / $KGM_OSKEXT_VERS_STAGE_MULT
564 set $vers_scratch = $vers_scratch - ( $vers_stage * $KGM_OSKEXT_VERS_STAGE_MULT)
565 set $vers_stagelevel = $vers_scratch
567 printf "%d.%d", $vers_major, $vers_minor
568 if ($vers_revision > 0)
569 printf ".%d", $vers_revision
572 if ($vers_stage == 1)
575 if ($vers_stage == 3)
578 if ($vers_stage == 5)
581 if ($vers_stage == 7)
584 if ($vers_stage == 1 || $vers_stage == 3 || $vers_stage == 5 || $vers_stage == 7)
585 printf "%d", $vers_stagelevel
590 define showallknownkexts
591 set $kext_count = sKextsByID->count
593 printf "%d kexts in sKextsByID:\n", $kext_count
600 printf " id name (version)\n"
602 while $kext_index < $kext_count
603 set $kext_id = sKextsByID->dictionary[$kext_index].key->string
604 set $oskext = (OSKext *)sKextsByID->dictionary[$kext_index].value
609 if ($oskext->flags.loaded)
610 showptr $oskext->kmod_info
612 printf "%3d", $oskext->loadTag
621 printf "%.64s (", $kext_id
622 printoskextversion (uint64_t)$oskext->version
624 set $kext_index = $kext_index + 1
627 document showallknownkexts
628 Syntax: (gdb) showallknownkexts
629 | Routine to print a summary listing of all kexts, loaded or not
641 printf " pri io_policy state wait_queue"
643 printf " wait_event\n"
650 set $kgm_thread = *(struct thread *)$arg0
652 if ($kgm_thread.static_param)
657 printf " 0x%llx ", $kgm_thread.thread_id
658 showptr $kgm_thread.last_processor
659 printf " %3d ", $kgm_thread.sched_pri
660 if ($kgm_thread.uthread != 0)
662 set $kgm_uthread = (struct uthread *)$kgm_thread.uthread
663 if ($kgm_uthread->uu_flag & 0x400)
669 if ($kgm_thread->ext_actionstate.hw_disk != 0)
670 set $diskpolicy = $kgm_thread->ext_actionstate.hw_disk
672 if ($kgm_thread->actionstate.hw_disk != 0)
673 set $diskpolicy = $kgm_thread->actionstate.hw_disk
676 if ($kgm_thread->ext_actionstate.hw_bg != 0)
679 if ($kgm_thread->actionstate.hw_bg != 0)
682 if ($diskpolicy == 2)
686 if ($diskpolicy == 3)
690 if ($diskpolicy == 4)
694 if ($diskpolicy == 5)
698 if ($kgm_printed == 0)
702 set $kgm_state = $kgm_thread.state
727 showptr $kgm_thread.wait_queue
729 if (((unsigned long)$kgm_thread.wait_event > (unsigned long)&last_kernel_symbol) \
730 && ($arg1 != 2) && ($kgm_show_kmod_syms == 0))
731 showkmodaddr $kgm_thread.wait_event
733 output /a $kgm_thread.wait_event
735 if ($kgm_thread.uthread != 0)
736 set $kgm_uthread = (struct uthread *)$kgm_thread.uthread
737 if ($kgm_uthread->uu_wmesg != 0)
738 printf "\t \"%s\"", $kgm_uthread->uu_wmesg
742 if ($kgm_thread.uthread != 0)
743 set $kgm_uthread = (struct uthread *)$kgm_thread.uthread
744 if ($kgm_uthread->pth_name && $kgm_uthread->pth_name[0])
745 printf "\n\t\tThread Name: %s", $kgm_uthread->pth_name
749 if ($kgm_thread.kernel_stack != 0)
750 if ($kgm_thread.uthread != 0)
752 set $kgm_uthread = (struct uthread *)$kgm_thread.uthread
753 if ($kgm_uthread->uu_kwe.kwe_kwqqueue != 0)
754 set $kwq = (ksyn_wait_queue_t)$kgm_uthread->uu_kwe.kwe_kwqqueue
755 printf " kwq_lockcount:0x%x; kwq_retval:0x%x", $kgm_uthread->uu_kwe.kwe_lockseq, $kgm_uthread->uu_kwe.kwe_psynchretval
761 if ($kgm_thread.reserved_stack != 0)
764 printf " reserved_stack="
765 showptr $kgm_thread.reserved_stack
769 printf " kernel_stack="
770 showptr $kgm_thread.kernel_stack
771 if ($kgm_mtype == $kgm_mtype_ppc)
772 set $mysp = $kgm_thread.machine.pcb->save_r1
774 if (($kgm_mtype & $kgm_mtype_x86_mask) == $kgm_mtype_x86_any)
775 set $kgm_statep = (struct x86_kernel_state *) \
776 ($kgm_thread->kernel_stack + kernel_stack_size \
777 - sizeof(struct x86_kernel_state))
778 if ($kgm_mtype == $kgm_mtype_i386)
779 set $mysp = $kgm_statep->k_ebp
781 set $mysp = $kgm_statep->k_rbp
784 if ($kgm_mtype == $kgm_mtype_arm)
785 if (((unsigned long)$r7 < ((unsigned long) ($kgm_thread->kernel_stack+kernel_stack_size))) \
786 && ((unsigned long)$r7 > (unsigned long) ($kgm_thread->kernel_stack)))
789 set $kgm_statep = (struct arm_saved_state *)$kgm_thread.machine.kstackptr
790 set $mysp = $kgm_statep->r[7]
793 set $prevsp = $mysp - 16
798 if ($kgm_mtype == $kgm_mtype_ppc)
804 set $kgm_actint_framecount = 0
805 while ($mysp != 0) && (($mysp & $stkmask) == 0) \
806 && ($mysp != $prevsp) \
807 && ((((unsigned long) $mysp ^ (unsigned long) $prevsp) < 0x2000) \
808 || (((unsigned long)$mysp < ((unsigned long) ($kgm_thread->kernel_stack+kernel_stack_size))) \
809 && ((unsigned long)$mysp > (unsigned long) ($kgm_thread->kernel_stack)))) \
810 && ($kgm_actint_framecount < 128)
812 set $kgm_actint_framecount = $kgm_actint_framecount + 1
817 if ($kgm_mtype == $kgm_mtype_ppc)
818 set $kgm_return = *($mysp + 8)
820 if ($kgm_mtype == $kgm_mtype_i386)
821 set $kgm_return = *($mysp + 4)
823 if ($kgm_mtype == $kgm_mtype_x86_64)
824 set $kgm_return = *(unsigned long *)($mysp + 8)
826 if ($kgm_mtype == $kgm_mtype_arm)
827 set $kgm_return = *($mysp + 4)
829 if (((unsigned long) $kgm_return < (unsigned long) &_mh_execute_header || \
830 (unsigned long) $kgm_return >= (unsigned long) &last_kernel_symbol ) \
831 && ($kgm_show_kmod_syms == 0))
832 showkmodaddr $kgm_return
834 output /a $kgm_return
837 set $mysp = *(unsigned long *)$mysp
842 printf " stackbottom="
847 printf " continuation="
848 output /a $kgm_thread.continuation
861 Syntax: (gdb) showact <activation>
862 | Routine to print out the state of a specific thread.
870 document showactstack
871 Syntax: (gdb) showactstack <activation>
872 | Routine to print out the stack of a specific thread.
876 define showallthreads
877 set $kgm_head_taskp = &tasks
878 set $kgm_taskp = (struct task *)($kgm_head_taskp->next)
879 while $kgm_taskp != $kgm_head_taskp
881 showtaskint $kgm_taskp
883 set $kgm_head_actp = &($kgm_taskp->threads)
884 set $kgm_actp = (struct thread *)($kgm_taskp->threads.next)
885 while $kgm_actp != $kgm_head_actp
886 showactint $kgm_actp 0
887 set $kgm_actp = (struct thread *)($kgm_actp->task_threads.next)
890 set $kgm_taskp = (struct task *)($kgm_taskp->tasks.next)
893 document showallthreads
894 Syntax: (gdb) showallthreads
895 | Routine to print out info about all threads in the system.
898 define showprocessorint
899 set $kgm_processor_int = (struct processor *)$arg0
901 showptr $kgm_processor_int
902 printf " State %d (cpu_id 0x%x)\n", ($kgm_processor_int)->state, ($kgm_processor_int)->cpu_id
905 define showcurrentthreads
906 set $kgm_prp = (struct processor *)processor_list
908 showprocessorint $kgm_prp
909 if ($kgm_prp)->active_thread != 0
910 set $kgm_actp = ($kgm_prp)->active_thread
912 showtaskint ($kgm_actp)->task
914 showactint $kgm_actp 0
917 set $kgm_prp = ($kgm_prp)->processor_list
920 document showcurrentthreads
921 Syntax: (gdb) showcurrentthreads
922 | Routine to print out info about the thread running on each cpu.
927 set $kgm_runq = (struct run_queue *)$arg0
929 printf " Priority Run Queue Info: Count %d\n", $kgm_runq->count
930 set $kgm_runq_queue_i = 0
931 set $kgm_runq_queue_count = sizeof($kgm_runq->queues)/sizeof($kgm_runq->queues[0])
932 while $kgm_runq->count && $kgm_runq_queue_i < $kgm_runq_queue_count
933 set $kgm_runq_queue_head = &$kgm_runq->queues[$kgm_runq_queue_i]
934 set $kgm_runq_queue_p = $kgm_runq_queue_head->next
935 if $kgm_runq_queue_p != $kgm_runq_queue_head
936 set $kgm_runq_queue_this_count = 0
937 while $kgm_runq_queue_p != $kgm_runq_queue_head
938 set $kgm_runq_queue_this_count = $kgm_runq_queue_this_count + 1
939 showtask ((thread_t)$kgm_runq_queue_p)->task
940 showactstack $kgm_runq_queue_p
941 set $kgm_runq_queue_p = $kgm_runq_queue_p->next
943 printf " Queue Priority %3d [", $kgm_runq_queue_i
944 showptr $kgm_runq_queue_head
945 printf "] Count %d\n", $kgm_runq_queue_this_count
947 set $kgm_runq_queue_i = $kgm_runq_queue_i + 1
953 set $kgm_grrr_runq = $arg0
955 printf " GRRR Info: Count %d Weight %d Current Group ", $kgm_grrr_runq->count, $kgm_grrr_runq->weight
956 showptr $kgm_grrr_runq->current_group
958 set $kgm_grrr_group_i = 0
959 set $kgm_grrr_group_count = sizeof($kgm_grrr_runq->groups)/sizeof($kgm_grrr_runq->groups[0])
960 while $kgm_grrr_runq->count && $kgm_grrr_group_i < $kgm_grrr_group_count
961 set $kgm_grrr_group = &$kgm_grrr_runq->groups[$kgm_grrr_group_i]
962 if $kgm_grrr_group->count > 0
963 printf " Group %3d [", $kgm_grrr_group->index
964 showptr $kgm_grrr_group
965 printf "] Count %d Weight %d\n", $kgm_grrr_group->count, $kgm_grrr_group->weight
966 set $kgm_grrr_group_client_head = &$kgm_grrr_group->clients
967 set $kgm_grrr_group_client = $kgm_grrr_group_client_head->next
968 while $kgm_grrr_group_client != $kgm_grrr_group_client_head
969 # showtask ((thread_t)$kgm_grrr_group_client)->task
970 # showactstack $kgm_grrr_group_client
971 set $kgm_grrr_group_client = $kgm_grrr_group_client->next
974 set $kgm_grrr_group_i = $kgm_grrr_group_i + 1
978 define showallprocessors
979 set $kgm_pset = &pset0
981 set $kgm_show_grrr = 0
982 set $kgm_show_priority_runq = 0
983 set $kgm_show_priority_pset_runq = 0
984 set $kgm_show_fairshare_grrr = 0
985 set $kgm_show_fairshare_list = 0
988 set $kgm_show_priority_runq = 1
989 set $kgm_show_fairshare_list = 1
992 set $kgm_show_priority_pset_runq = 1
993 set $kgm_show_fairshare_list = 1
996 set $kgm_show_grrr = 1
997 set $kgm_show_fairshare_grrr = 1
1000 set $kgm_show_priority_runq = 1
1001 set $kgm_show_fairshare_list = 1
1004 set $kgm_show_priority_pset_runq = 1
1005 set $kgm_show_fairshare_list = 1
1008 while $kgm_pset != 0
1009 printf "Processor Set "
1011 printf " Count %d (cpu_id 0x%x-0x%x)\n", ($kgm_pset)->cpu_set_count, ($kgm_pset)->cpu_set_low, ($kgm_pset)->cpu_set_hi
1012 printf " Active Processors:\n"
1013 set $kgm_active_queue_head = &($kgm_pset)->active_queue
1014 set $kgm_active_elt = $kgm_active_queue_head->next
1015 while $kgm_active_elt != $kgm_active_queue_head
1016 set $kgm_processor = (processor_t)$kgm_active_elt
1018 showprocessorint $kgm_processor
1020 if $kgm_show_priority_runq
1021 set $kgm_runq = &$kgm_processor->runq
1022 _showrunqint $kgm_runq
1025 set $kgm_grrr_runq = &$kgm_processor->grrr_runq
1026 _showgrrrint $kgm_grrr_runq
1029 if $kgm_processor->processor_meta != 0 && $kgm_processor->processor_meta->primary == $kgm_processor
1030 set $kgm_processor_meta_idle_head = &$kgm_processor->processor_meta->idle_queue
1031 set $kgm_processor_meta_idle = $kgm_processor_meta_idle_head->next
1032 while $kgm_processor_meta_idle != $kgm_processor_meta_idle_head
1033 printf " Idle Meta Processor: "
1034 showprocessorint $kgm_processor_meta_idle
1035 set $kgm_processor_meta_idle = $kgm_processor_meta_idle->next
1039 set $kgm_active_elt = $kgm_active_elt->next
1041 printf " Idle Processors:\n"
1042 set $kgm_idle_queue_head = &($kgm_pset)->idle_queue
1043 set $kgm_idle_elt = $kgm_idle_queue_head->next
1044 while $kgm_idle_elt != $kgm_idle_queue_head
1045 set $kgm_processor = (processor_t)$kgm_idle_elt
1047 showprocessorint $kgm_processor
1049 if $kgm_processor->processor_meta != 0 && $kgm_processor->processor_meta->primary == $kgm_processor
1050 set $kgm_processor_meta_idle_head = &$kgm_processor->processor_meta->idle_queue
1051 set $kgm_processor_meta_idle = $kgm_processor_meta_idle_head->next
1052 while $kgm_processor_meta_idle != $kgm_processor_meta_idle_head
1053 printf " Idle Meta Processor: "
1054 showprocessorint $kgm_processor_meta_idle
1055 set $kgm_processor_meta_idle = $kgm_processor_meta_idle->next
1059 set $kgm_idle_elt = $kgm_idle_elt->next
1062 if $kgm_show_priority_pset_runq
1063 set $kgm_runq = &$kgm_pset->pset_runq
1065 _showrunqint $kgm_runq
1067 set $kgm_pset = ($kgm_pset)->pset_list
1071 printf "Realtime Queue Count %d\n", rt_runq.count
1072 set $kgm_rt_runq_head = &rt_runq.queue
1073 set $kgm_rt_runq = $kgm_rt_runq_head->next
1074 while $kgm_rt_runq != $kgm_rt_runq_head
1075 showtask ((thread_t)$kgm_rt_runq)->task
1076 showact $kgm_rt_runq
1077 set $kgm_rt_runq = $kgm_rt_runq->next
1081 if $kgm_show_fairshare_list
1082 printf "Fair Share Queue Count %d\n", fs_runq.count
1083 set $kgm_fs_runq_head = &fs_runq.queue
1084 set $kgm_fs_runq = $kgm_fs_runq_head->next
1085 while $kgm_fs_runq != $kgm_fs_runq_head
1086 showtask ((thread_t)$kgm_fs_runq)->task
1087 showact $kgm_fs_runq
1088 set $kgm_fs_runq = $kgm_fs_runq->next
1091 if $kgm_show_fairshare_grrr
1092 printf "Fair Share Queue Count %d\n", fs_grrr_runq.count
1093 set $kgm_fs_grrr = &fs_grrr_runq
1094 _showgrrrint $kgm_fs_grrr
1097 document showallprocessors
1098 Syntax: (gdb) showallprocessors
1099 | Routine to print out info about all psets and processors
1102 set $decode_wait_events = 0
1103 define showallstacks
1104 set $kgm_head_taskp = &tasks
1105 set $kgm_taskp = (struct task *)($kgm_head_taskp->next)
1106 while $kgm_taskp != $kgm_head_taskp
1108 showtaskint $kgm_taskp
1109 set $kgm_head_actp = &($kgm_taskp->threads)
1110 set $kgm_actp = (struct thread *)($kgm_taskp->threads.next)
1111 while $kgm_actp != $kgm_head_actp
1113 if ($decode_wait_events > 0)
1114 showactint $kgm_actp 1
1116 showactint $kgm_actp 2
1118 set $kgm_actp = (struct thread *)($kgm_actp->task_threads.next)
1121 set $kgm_taskp = (struct task *)($kgm_taskp->tasks.next)
1124 printf "\nZombie Processes:\n"
1128 document showallstacks
1129 Syntax: (gdb) showallstacks
1130 | Routine to print out the stack for each thread in the system.
1131 | If the variable $decode_wait_events is non-zero, the routine attempts to
1132 | interpret thread wait_events as kernel module offsets, which can add to
1136 define showcurrentstacks
1137 set $kgm_prp = processor_list
1139 showprocessorint $kgm_prp
1140 if ($kgm_prp)->active_thread != 0
1141 set $kgm_actp = ($kgm_prp)->active_thread
1143 showtaskint ($kgm_actp)->task
1145 showactint $kgm_actp 1
1148 set $kgm_prp = ($kgm_prp)->processor_list
1152 document showcurrentstacks
1153 Syntax: (gdb) showcurrentstacks
1154 | Routine to print out the thread running on each cpu (incl. its stack)
1157 define showwaiterheader
1158 printf "waiters thread "
1159 printf "processor pri state wait_queue wait_event\n"
1162 define showwaitqwaiters
1163 set $kgm_w_waitqp = (WaitQueue*)$arg0
1164 set $kgm_w_linksp = &($kgm_w_waitqp->wq_queue)
1165 set $kgm_w_wqe = (WaitQueueElement *)$kgm_w_linksp->next
1166 set $kgm_w_found = 0
1167 while ( (queue_entry_t)$kgm_w_wqe != (queue_entry_t)$kgm_w_linksp)
1168 if ($kgm_w_wqe->wqe_type != &_wait_queue_link)
1170 set $kgm_w_found = 1
1173 set $kgm_w_shuttle = (struct thread *)$kgm_w_wqe
1174 showactint $kgm_w_shuttle 0
1176 set $kgm_w_wqe = (WaitQueueElement *)$kgm_w_wqe->wqe_links.next
1180 define showwaitqwaitercount
1181 set $kgm_wc_waitqp = (WaitQueue*)$arg0
1182 set $kgm_wc_linksp = &($kgm_wc_waitqp->wq_queue)
1183 set $kgm_wc_wqe = (WaitQueueElement *)$kgm_wc_linksp->next
1184 set $kgm_wc_count = 0
1185 while ( (queue_entry_t)$kgm_wc_wqe != (queue_entry_t)$kgm_wc_linksp)
1186 if ($kgm_wc_wqe->wqe_type != &_wait_queue_link)
1187 set $kgm_wc_count = $kgm_wc_count + 1
1189 set $kgm_wc_wqe = (WaitQueueElement *)$kgm_wc_wqe->wqe_links.next
1191 printf "0x%08x ", $kgm_wc_count
1194 define showwaitqmembercount
1195 set $kgm_mc_waitqsetp = (WaitQueueSet*)$arg0
1196 set $kgm_mc_setlinksp = &($kgm_mc_waitqsetp->wqs_setlinks)
1197 set $kgm_mc_wql = (WaitQueueLink *)$kgm_mc_setlinksp->next
1198 set $kgm_mc_count = 0
1199 while ( (queue_entry_t)$kgm_mc_wql != (queue_entry_t)$kgm_mc_setlinksp)
1200 set $kgm_mc_count = $kgm_mc_count + 1
1201 set $kgm_mc_wql = (WaitQueueLink *)$kgm_mc_wql->wql_setlinks.next
1203 printf "0x%08x ", $kgm_mc_count
1207 define showwaitqmemberheader
1208 printf "set-members wait_queue interlock "
1209 printf "pol type member_cnt waiter_cnt\n"
1212 define showwaitqmemberint
1213 set $kgm_m_waitqp = (WaitQueue*)$arg0
1214 printf " 0x%08x ", $kgm_m_waitqp
1215 printf "0x%08x ", $kgm_m_waitqp->wq_interlock.lock_data
1216 if ($kgm_m_waitqp->wq_fifo)
1221 if ($kgm_m_waitqp->wq_type == 0xf1d1)
1223 showwaitqmembercount $kgm_m_waitqp
1225 printf "Que 0x00000000 "
1227 showwaitqwaitercount $kgm_m_waitqp
1232 define showwaitqmemberofheader
1233 printf "member-of wait_queue interlock "
1234 printf "pol type member_cnt waiter_cnt\n"
1237 define showwaitqmemberof
1238 set $kgm_mo_waitqp = (WaitQueue*)$arg0
1239 set $kgm_mo_linksp = &($kgm_mo_waitqp->wq_queue)
1240 set $kgm_mo_wqe = (WaitQueueElement *)$kgm_mo_linksp->next
1241 set $kgm_mo_found = 0
1242 while ( (queue_entry_t)$kgm_mo_wqe != (queue_entry_t)$kgm_mo_linksp)
1243 if ($kgm_mo_wqe->wqe_type == &_wait_queue_link)
1245 set $kgm_mo_found = 1
1246 showwaitqmemberofheader
1248 set $kgm_mo_wqlp = (WaitQueueLink *)$kgm_mo_wqe
1249 set $kgm_mo_wqsetp = (WaitQueue*)($kgm_mo_wqlp->wql_setqueue)
1250 showwaitqmemberint $kgm_mo_wqsetp
1252 set $kgm_mo_wqe = (WaitQueueElement *)$kgm_mo_wqe->wqe_links.next
1256 define showwaitqmembers
1257 set $kgm_ms_waitqsetp = (WaitQueueSet*)$arg0
1258 set $kgm_ms_setlinksp = &($kgm_ms_waitqsetp->wqs_setlinks)
1259 set $kgm_ms_wql = (WaitQueueLink *)$kgm_ms_setlinksp->next
1260 set $kgm_ms_found = 0
1261 while ( (queue_entry_t)$kgm_ms_wql != (queue_entry_t)$kgm_ms_setlinksp)
1262 set $kgm_ms_waitqp = $kgm_ms_wql->wql_element.wqe_queue
1264 showwaitqmemberheader
1265 set $kgm_ms_found = 1
1267 showwaitqmemberint $kgm_ms_waitqp
1268 set $kgm_ms_wql = (WaitQueueLink *)$kgm_ms_wql->wql_setlinks.next
1272 define showwaitqheader
1273 printf "wait_queue ref_count interlock "
1274 printf "pol type member_cnt waiter_cnt\n"
1278 set $kgm_waitqp = (WaitQueue*)$arg0
1279 printf "0x%08x ", $kgm_waitqp
1280 if ($kgm_waitqp->wq_type == 0xf1d1)
1281 printf "0x%08x ", ((WaitQueueSet*)$kgm_waitqp)->wqs_refcount
1283 printf "0x00000000 "
1285 printf "0x%08x ", $kgm_waitqp->wq_interlock.lock_data
1286 if ($kgm_waitqp->wq_fifo)
1291 if ($kgm_waitqp->wq_type == 0xf1d1)
1293 showwaitqmembercount $kgm_waitqp
1295 printf "Que 0x00000000 "
1297 showwaitqwaitercount $kgm_waitqp
1302 set $kgm_waitq1p = (WaitQueue*)$arg0
1304 showwaitqint $kgm_waitq1p
1305 if ($kgm_waitq1p->wq_type == 0xf1d1)
1306 showwaitqmembers $kgm_waitq1p
1308 showwaitqmemberof $kgm_waitq1p
1310 showwaitqwaiters $kgm_waitq1p
1313 define showmapheader
1320 printf " #ents rpage hint "
1322 printf " first_free\n"
1325 define showvmeheader
1328 printf " start prot #page object "
1334 set $kgm_mapp = (vm_map_t)$arg0
1335 set $kgm_map = *$kgm_mapp
1338 showptr $kgm_map.pmap
1340 showptr $kgm_map.size
1341 printf " %3d ", $kgm_map.hdr.nentries
1343 printf "%5d ", $kgm_map.pmap->stats.resident_count
1347 showptr $kgm_map.hint
1349 showptr $kgm_map.first_free
1353 set $kgm_head_vmep = &($kgm_mapp->hdr.links)
1354 set $kgm_vmep = $kgm_map.hdr.links.next
1355 while (($kgm_vmep != 0) && ($kgm_vmep != $kgm_head_vmep))
1356 set $kgm_vme = *$kgm_vmep
1359 printf " 0x%016llx ", $kgm_vme.links.start
1360 printf "%1x", $kgm_vme.protection
1361 printf "%1x", $kgm_vme.max_protection
1362 if $kgm_vme.inheritance == 0x0
1365 if $kgm_vme.inheritance == 0x1
1368 if $kgm_vme.inheritance == 0x2
1371 if $kgm_vme.inheritance == 0x3
1374 if $kgm_vme.is_sub_map
1377 if $kgm_vme.needs_copy
1383 printf "%6d ",($kgm_vme.links.end - $kgm_vme.links.start) >> 12
1384 showptr $kgm_vme.object.vm_object
1385 printf " 0x%016llx\n", $kgm_vme.offset
1386 set $kgm_vmep = $kgm_vme.links.next
1393 define showmapwiredp
1394 set $kgm_mapp = (vm_map_t)$arg0
1395 set $kgm_map = *$kgm_mapp
1396 set $kgm_head_vmep = &($kgm_mapp->hdr.links)
1397 set $kgm_vmep = $kgm_map.hdr.links.next
1398 set $kgm_objp_prev = (struct vm_object *)0
1400 set $kgm_saw_kernel_obj = 0
1401 set $kgm_wired_count = 0
1402 set $kgm_objp_print_space = 1
1404 set $kgm_objp_print_space = 0
1406 while (($kgm_vmep != 0) && ($kgm_vmep != $kgm_head_vmep))
1407 set $kgm_vme = *$kgm_vmep
1408 set $kgm_objp = $kgm_vme.object.vm_object
1409 if $kgm_vme.is_sub_map
1411 set $kgm_mapp_orig = $kgm_mapp
1412 set $kgm_vmep_orig = $kgm_vmep
1413 set $kgm_vme_orig = $kgm_vme
1414 set $kgm_head_vmep_orig = $kgm_head_vmep
1417 showmapwiredp $kgm_objp 1
1418 set $kgm_vme = $kgm_vme_orig
1419 set $kgm_vmep = $kgm_vmep_orig
1420 set $kgm_mapp = $kgm_mapp_orig
1421 set $kgm_head_vmep = $kgm_head_vmep_orig
1422 set $kgm_objp = (struct vm_object *)0
1428 set $kgm_objp = (struct vm_object *)0
1432 if ($kgm_objp == $kgm_objp_prev)
1433 set $kgm_objp = (struct vm_object *)0
1435 if $kgm_objp == kernel_object
1436 if $kgm_saw_kernel_obj
1437 set $kgm_objp = (struct vm_object *)0
1439 set $kgm_saw_kernel_obj = 1
1441 if $kgm_objp && $kgm_objp->wired_page_count
1442 if $kgm_objp_print_space == 1
1446 set $kgm_objp_print_space = 1
1449 printf " 0x%016llx ", $kgm_vme.links.start
1450 printf "%5d", $kgm_vme.alias
1451 printf "%6d ",($kgm_vme.links.end - $kgm_vme.links.start) >> 12
1453 printf "[%3d]", $kgm_objp->ref_count
1454 printf "%7d\n", $kgm_objp->wired_page_count
1455 set $kgm_wired_count = $kgm_wired_count + $kgm_objp->wired_page_count
1456 set $kgm_objp_prev = $kgm_objp
1458 set $kgm_vmep = $kgm_vme.links.next
1461 printf "total wired count = %d\n", $kgm_wired_count
1470 printf " start alias #page object "
1473 showmapwiredp $arg0 0
1475 document showmapwired
1476 Syntax: (gdb) showmapwired <vm_map>
1477 | Routine to print out a summary listing of all the entries with wired pages in a vm_map
1485 Syntax: (gdb) showmapvme <vm_map>
1486 | Routine to print out a summary listing of all the entries in a vm_map
1495 Syntax: (gdb) showmap <vm_map>
1496 | Routine to print out info about the specified vm_map
1500 set $kgm_head_taskp = &tasks
1501 set $kgm_taskp = (struct task *)($kgm_head_taskp->next)
1502 while $kgm_taskp != $kgm_head_taskp
1505 showtaskint $kgm_taskp
1506 showvmint $kgm_taskp->map 0
1507 set $kgm_taskp = (struct task *)($kgm_taskp->tasks.next)
1511 Syntax: (gdb) showallvm
1512 | Routine to print a summary listing of all the vm maps
1517 set $kgm_head_taskp = &tasks
1518 set $kgm_taskp = (struct task *)($kgm_head_taskp->next)
1519 while $kgm_taskp != $kgm_head_taskp
1522 showtaskint $kgm_taskp
1523 showvmint $kgm_taskp->map 1
1524 set $kgm_taskp = (struct task *)($kgm_taskp->tasks.next)
1528 Syntax: (gdb) showallvme
1529 | Routine to print a summary listing of all the vm map entries
1533 define showipcheader
1538 printf " table_next"
1540 printf " flags ports splaysize "
1542 printf "splaybase\n"
1545 define showipceheader
1551 printf "name rite urefs destname "
1553 printf "destination\n"
1557 set $kgm_ie = *(ipc_entry_t)$arg0
1560 showptr $kgm_ie.ie_object
1562 printf " 0x%08x ", $arg1
1563 if $kgm_ie.ie_bits & 0x00100000
1565 printf "%5d\n", $kgm_ie.ie_bits & 0xffff
1567 if $kgm_ie.ie_bits & 0x00080000
1569 printf "%5d\n", $kgm_ie.ie_bits & 0xffff
1571 if $kgm_ie.ie_bits & 0x00010000
1572 if $kgm_ie.ie_bits & 0x00020000
1578 if $kgm_ie.ie_bits & 0x00020000
1582 if $kgm_ie.ie_bits & 0x00040000
1585 if $kgm_ie.index.request
1586 set $kgm_port = (ipc_port_t)$kgm_ie.ie_object
1587 set $kgm_requests = $kgm_port->ip_requests
1588 set $kgm_req_soright = $kgm_requests[$kgm_ie.index.request].notify.port
1590 # Armed send-possible notification?
1591 if (uintptr_t)$kgm_req_soright & 0x1
1594 # Delayed send-possible notification?
1595 if (uintptr_t)$kgm_req_soright & 0x2
1598 # Dead-name notification
1608 # Collision (with tree)?
1609 if $kgm_ie.ie_bits & 0x00800000
1614 printf "%5d ", $kgm_ie.ie_bits & 0xffff
1615 showportdest $kgm_ie.ie_object
1621 set $kgm_isp = (ipc_space_t)$arg0
1622 set $kgm_is = *$kgm_isp
1625 showptr $kgm_is.is_table
1627 showptr $kgm_is.is_table_next
1629 if $kgm_is.is_growing != 0
1634 if $kgm_is.is_fast != 0
1639 if $kgm_is.is_active != 0
1644 printf "%5d ", $kgm_is.is_table_size + $kgm_is.is_tree_total
1645 showptr $kgm_is.is_tree_total
1647 showptr &$kgm_isp->is_tree
1652 set $kgm_iep = $kgm_is.is_table
1653 set $kgm_destspacep = (ipc_space_t)0
1654 while ( $kgm_iindex < $kgm_is.is_table_size )
1655 set $kgm_ie = *$kgm_iep
1656 if $kgm_ie.ie_bits & 0x001f0000
1657 set $kgm_name = (($kgm_iindex << 8)|($kgm_ie.ie_bits >> 24))
1658 showipceint $kgm_iep $kgm_name
1660 if $kgm_ie.ie_object != 0 && ($kgm_ie.ie_bits & 0x00070000) && ((ipc_port_t) $kgm_ie.ie_object)->ip_callstack[0] != 0
1662 showportbt $kgm_ie.ie_object $kgm_is.is_task
1666 set $kgm_iindex = $kgm_iindex + 1
1667 set $kgm_iep = &($kgm_is.is_table[$kgm_iindex])
1669 if $kgm_is.is_tree_total
1670 printf "Still need to write tree traversal\n"
1678 set $kgm_isp = (ipc_space_t)$arg0
1680 showipcint $kgm_isp 0 0
1683 Syntax: (gdb) showipc <ipc_space>
1684 | Routine to print the status of the specified ipc space
1688 set $kgm_isp = (ipc_space_t)$arg0
1690 showipcint $kgm_isp 1 0
1693 Syntax: (gdb) showrights <ipc_space>
1694 | Routine to print a summary list of all the rights in a specified ipc space
1699 set $kgm_taskp = (task_t)$arg0
1701 showtaskint $kgm_taskp
1703 showipcint $kgm_taskp->itk_space 0 0
1705 document showtaskipc
1706 Syntax: (gdb) showtaskipc <task>
1707 | Routine to print info about the ipc space for a task
1711 define showtaskrights
1712 set $kgm_taskp = (task_t)$arg0
1714 showtaskint $kgm_taskp
1716 showipcint $kgm_taskp->itk_space 1 0
1718 document showtaskrights
1719 Syntax: (gdb) showtaskrights <task>
1720 | Routine to print info about the ipc rights for a task
1723 define showtaskrightsbt
1724 set $kgm_taskp = (task_t)$arg0
1726 showtaskint $kgm_taskp
1728 showipcint $kgm_taskp->itk_space 1 1
1730 document showtaskrightsbt
1731 Syntax: (gdb) showtaskrightsbt <task>
1732 | Routine to print info about the ipc rights for a task with backtraces
1736 set $kgm_head_taskp = &tasks
1737 set $kgm_cur_taskp = (struct task *)($kgm_head_taskp->next)
1738 while $kgm_cur_taskp != $kgm_head_taskp
1740 showtaskint $kgm_cur_taskp
1742 showipcint $kgm_cur_taskp->itk_space 0 0
1743 set $kgm_cur_taskp = (struct task *)($kgm_cur_taskp->tasks.next)
1747 Syntax: (gdb) showallipc
1748 | Routine to print a summary listing of all the ipc spaces
1751 define showipcsumheader
1760 define showipcsummaryint
1761 set $kgm_taskp = (struct task *)$arg0
1763 printf "%7d", ((struct proc *)$kgm_taskp->bsd_info)->p_pid
1764 printf "%15d", $kgm_taskp->thread_count
1765 printf "%15d", $kgm_cur_taskp->itk_space.is_table_size
1766 printf " %s\n", ((struct proc *)$kgm_taskp->bsd_info)->p_comm
1769 define showipcsummary
1771 set $kgm_head_taskp = &tasks
1772 set $kgm_cur_taskp = (struct task *)($kgm_head_taskp->next)
1773 while $kgm_cur_taskp != $kgm_head_taskp
1774 showipcsummaryint $kgm_cur_taskp
1775 set $kgm_cur_taskp = (struct task *)($kgm_cur_taskp->tasks.next)
1779 document showipcsummary
1780 Syntax: (gdb) showipcsummary
1781 | Summarizes the IPC state of all tasks. This is a convenient way to dump
1782 | some basic clues about IPC messaging. You can use the output to determine
1783 | tasks that are candidates for further investigation.
1787 define showallrights
1788 set $kgm_head_taskp = &tasks
1789 set $kgm_cur_taskp = (struct task *)($kgm_head_taskp->next)
1790 while $kgm_cur_taskp != $kgm_head_taskp
1792 showtaskint $kgm_cur_taskp
1794 showipcint $kgm_cur_taskp->itk_space 1 0
1795 set $kgm_cur_taskp = (struct task *)($kgm_cur_taskp->tasks.next)
1798 document showallrights
1799 Syntax: (gdb) showallrights
1800 | Routine to print a summary listing of all the ipc rights
1805 set $kgm_taskp = (task_t)$arg0
1808 showtaskint $kgm_taskp
1809 showvmint $kgm_taskp->map 0
1812 Syntax: (gdb) showtaskvm <task>
1813 | Routine to print out info about a task's vm_map
1817 set $kgm_taskp = (task_t)$arg0
1819 showtaskint $kgm_taskp
1821 showvmint $kgm_taskp->map 1
1823 document showtaskvme
1824 Syntax: (gdb) showtaskvme <task>
1825 | Routine to print out info about a task's vm_map_entries
1829 define showtaskheader
1834 printf " ipc_space "
1842 set $kgm_taskp = (struct task *)$arg0
1845 showptr $kgm_taskp->map
1847 showptr $kgm_taskp->itk_space
1848 printf " %5d ", $kgm_taskp->thread_count
1849 showprocint $kgm_taskp->bsd_info
1857 Syntax (gdb) showtask <task>
1858 | Routine to print out info about a task.
1862 define showtaskthreads
1864 set $kgm_taskp = (struct task *)$arg0
1865 showtaskint $kgm_taskp
1867 set $kgm_head_actp = &($kgm_taskp->threads)
1868 set $kgm_actp = (struct thread *)($kgm_taskp->threads.next)
1869 while $kgm_actp != $kgm_head_actp
1870 showactint $kgm_actp 0
1871 set $kgm_actp = (struct thread *)($kgm_actp->task_threads.next)
1874 document showtaskthreads
1875 Syntax: (gdb) showtaskthreads <task>
1876 | Routine to print info about the threads in a task.
1880 define showtaskstacks
1882 set $kgm_taskp = (struct task *)$arg0
1883 showtaskint $kgm_taskp
1884 set $kgm_head_actp = &($kgm_taskp->threads)
1885 set $kgm_actp = (struct thread *)($kgm_taskp->threads.next)
1886 while $kgm_actp != $kgm_head_actp
1888 showactint $kgm_actp 1
1889 set $kgm_actp = (struct thread *)($kgm_actp->task_threads.next)
1892 document showtaskstacks
1893 Syntax: (gdb) showtaskstacks <task>
1894 | Routine to print out the stack for each thread in a task.
1897 define showqueue_elems
1898 set $queue_head = (struct queue_entry *)($arg0)
1899 set $queue = (struct queue_entry *)($queue_head->next)
1900 while $queue != $queue_head
1903 set $thread = (struct thread *)$queue
1904 set $task = (struct task *)$thread->task
1905 set $bsd = (struct proc *)$task->bsd_info
1906 set $guy = (char *)$bsd->p_comm
1914 #printf " %s\n", $kgm_procp->p_comm
1916 set $queue = (struct queue_entry *)($queue->next)
1922 set $kgm_head_taskp = &tasks
1923 set $kgm_taskp = (struct task *)($kgm_head_taskp->next)
1924 while $kgm_taskp != $kgm_head_taskp
1925 showtaskint $kgm_taskp
1926 set $kgm_taskp = (struct task *)($kgm_taskp->tasks.next)
1929 document showalltasks
1930 Syntax: (gdb) showalltasks
1931 | Routine to print a summary listing of all the tasks
1932 | wq_state -> reports "number of workq threads", "number of scheduled workq threads", "number of pending work items"
1933 | if "number of pending work items" seems stuck at non-zero, it may indicate that the workqueue mechanism is hung
1934 | io_policy -> RAGE - rapid aging of vnodes requested
1935 | NORM - normal I/O explicitly requested (this is the default)
1936 | PASS - passive I/O requested (i.e. I/Os do not affect throttling decisions)
1937 | THROT - throttled I/O requested (i.e. thread/task may be throttled after each I/O completes)
1940 define showprocheader
1941 printf " pid process "
1943 printf "io_policy wq_state command\n"
1947 set $kgm_procp = (struct proc *)$arg0
1949 set $kgm_printed = 0
1950 printf "%5d ", $kgm_procp->p_pid
1952 if ($kgm_procp->p_lflag & 0x400000)
1957 set $ptask = (struct task *)$kgm_procp->task
1959 if ($ptask->ext_actionstate.hw_disk != 0)
1960 set $diskpolicy = $ptask->ext_actionstate.hw_disk
1962 if ($ptask->actionstate.hw_disk != 0)
1963 set $diskpolicy = $ptask->actionstate.hw_disk
1966 if ($ptask->ext_actionstate.hw_bg != 0)
1969 if ($ptask->actionstate.hw_bg != 0)
1972 if ($diskpolicy == 2)
1974 set $kgm_printed = 1
1976 if ($diskpolicy == 3)
1978 set $kgm_printed = 1
1980 if ($diskpolicy == 4)
1982 set $kgm_printed = 1
1984 if ($diskpolicy == 5)
1986 set $kgm_printed = 1
1988 if ($kgm_printed == 0)
1991 set $kgm_wqp = (struct workqueue *)$kgm_procp->p_wqptr
1993 printf " %2d %2d %2d ", $kgm_wqp->wq_nthreads, $kgm_wqp->wq_thidlecount, $kgm_wqp->wq_itemcount
1997 printf " %s\n", $kgm_procp->p_comm
2007 set $kgm_head_taskp = &tasks
2008 set $kgm_taskp = (struct task *)($kgm_head_taskp->next)
2009 while $kgm_taskp != $kgm_head_taskp
2010 set $kgm_procp = (struct proc *)$kgm_taskp->bsd_info
2011 if (($kgm_procp != 0) && ($kgm_procp->p_pid == $arg0))
2012 showtaskint $kgm_taskp
2013 set $kgm_taskp = $kgm_head_taskp
2015 set $kgm_taskp = (struct task *)($kgm_taskp->tasks.next)
2020 Syntax: (gdb) showpid <pid>
2021 | Routine to print a single process by pid
2026 set $kgm_procp = (struct proc *)$arg0
2027 showtaskint $kgm_procp->task
2032 set switch_debugger=1
2036 | kdb - Switch to the inline kernel debugger
2040 | The kdb macro allows you to invoke the inline kernel debugger.
2043 define showpsetheader
2049 printf "recvname flags refs recvname "
2054 define showportheader
2060 printf "recvname flags refs recvname "
2065 define showportmemberheader
2072 printf "flags refs mqueue "
2077 define showkmsgheader
2085 printf "reply-port "
2090 define showkmsgsrcint
2091 set $kgm_kmsgsrchp = ((ipc_kmsg_t)$arg0)->ikm_header
2092 # set $kgm_kmsgsrctp = (mach_msg_audit_trailer_t *)((uintptr_t)$kgm_kmsgsrchp + $kgm_kmsgsrchp->msgh_size)
2093 # set $kgm_kmsgpid = $kgm_kmsgsrctp->msgh_audit.val[5]
2094 set $kgm_kmsgpid = (pid_t)((uint *)((uintptr_t)$kgm_kmsgsrchp + $kgm_kmsgsrchp->msgh_size))[10]
2095 # compare against a well-known or cached value as this may be slow
2096 if ($kgm_kmsgpid == 0)
2097 set $kgm_kmsgsrcpid = (pid_t)0
2098 set $kgm_kmsgsrcprocp = (struct proc *)kernel_task->bsd_info
2100 if ($kgm_kmsgpid != $kgm_kmsgsrcpid)
2101 set $kgm_kmsgsrchead_taskp = &tasks
2102 set $kgm_kmsgsrctaskp = (struct task *)($kgm_kmsgsrchead_taskp->next)
2103 while $kgm_kmsgsrctaskp != $kgm_kmsgsrchead_taskp
2104 set $kgm_kmsgsrcprocp = (struct proc *)$kgm_kmsgsrctaskp->bsd_info
2105 set $kgm_kmsgsrcpid = $kgm_kmsgsrcprocp->p_pid
2106 if (($kgm_kmsgsrcprocp != 0) && ($kgm_kmsgsrcprocp->p_pid == $kgm_kmsgpid))
2107 set $kgm_kmsgsrctaskp = $kgm_kmsgsrchead_taskp
2109 set $kgm_kmsgsrctaskp = (struct task *)($kgm_kmsgsrctaskp->tasks.next)
2114 if ($kgm_kmsgsrcprocp->p_pid == $kgm_kmsgpid)
2115 printf "%s(%d)\n", $kgm_kmsgsrcprocp->p_comm, $kgm_kmsgpid
2117 printf "unknown(%d)\n", $kgm_kmsgpid
2122 set $kgm_kmsghp = ((ipc_kmsg_t)$arg0)->ikm_header
2123 set $kgm_kmsgh = *$kgm_kmsghp
2128 showptr $kgm_kmsgh.msgh_remote_port
2132 printf " 0x%08x ", $kgm_kmsgh.msgh_id
2133 if (($kgm_kmsgh.msgh_bits & 0xff) == 19)
2138 if (($kgm_kmsgh.msgh_bits & 0xff00) == (19 << 8))
2143 if ($kgm_kmsgh.msgh_bits & 0xf0000000)
2148 printf "%5d ", $kgm_kmsgh.msgh_size
2149 showptr $kgm_kmsgh.msgh_local_port
2151 set $kgm_kmsgsrcpid = (pid_t)0
2152 showkmsgsrcint $arg0
2160 set $kgm_portp = (struct ipc_port *)$arg0
2161 showptr $kgm_portp->ip_kobject
2163 set $kgm_kotype = ($kgm_portp->ip_object.io_bits & 0x00000fff)
2164 if ($kgm_kotype == 1)
2167 if ($kgm_kotype == 2)
2170 if ($kgm_kotype == 3)
2173 if ($kgm_kotype == 4)
2176 if ($kgm_kotype == 5)
2179 if ($kgm_kotype == 6)
2182 if ($kgm_kotype == 7)
2185 if ($kgm_kotype == 8)
2188 if ($kgm_kotype == 9)
2191 if ($kgm_kotype == 10)
2194 if ($kgm_kotype == 11)
2197 if ($kgm_kotype == 12)
2200 if ($kgm_kotype == 13)
2203 if ($kgm_kotype == 14)
2206 if ($kgm_kotype == 15)
2209 if ($kgm_kotype == 16)
2212 if ($kgm_kotype == 17)
2215 if ($kgm_kotype == 18)
2218 if ($kgm_kotype == 19)
2221 if ($kgm_kotype == 20)
2224 if ($kgm_kotype == 21)
2227 if ($kgm_kotype == 22)
2228 printf "IO_DONE_QUE"
2230 if ($kgm_kotype == 23)
2233 if ($kgm_kotype == 24)
2236 if ($kgm_kotype == 25)
2239 if ($kgm_kotype == 26)
2242 if ($kgm_kotype == 27)
2243 printf "IOKIT_SPARE"
2245 if ($kgm_kotype == 28)
2248 if ($kgm_kotype == 29)
2251 if ($kgm_kotype == 30)
2254 if ($kgm_kotype == 31)
2257 if ($kgm_kotype == 34)
2263 define showportdestproc
2264 set $kgm_portp = (struct ipc_port *)$arg0
2265 set $kgm_spacep = $kgm_portp->data.receiver
2266 # check against the previous cached value - this is slow
2267 if ($kgm_spacep != $kgm_destspacep)
2268 set $kgm_destprocp = (struct proc *)0
2269 set $kgm_head_taskp = &tasks
2270 set $kgm_desttaskp = (struct task *)($kgm_head_taskp->next)
2271 while (($kgm_destprocp == 0) && ($kgm_desttaskp != $kgm_head_taskp))
2272 set $kgm_destspacep = $kgm_desttaskp->itk_space
2273 if ($kgm_destspacep == $kgm_spacep)
2274 set $kgm_destprocp = (struct proc *)$kgm_desttaskp->bsd_info
2276 set $kgm_desttaskp = (struct task *)($kgm_desttaskp->tasks.next)
2280 if $kgm_destprocp != 0
2281 printf "%s(%d)\n", $kgm_destprocp->p_comm, $kgm_destprocp->p_pid
2284 showptr $kgm_desttaskp
2290 set $kgm_portp = (struct ipc_port *)$arg0
2291 set $kgm_spacep = $kgm_portp->data.receiver
2292 if ((uintptr_t)$kgm_spacep == (uintptr_t)ipc_space_kernel)
2293 showkobject $kgm_portp
2295 if ($kgm_portp->ip_object.io_bits & 0x80000000)
2296 showptr $kgm_portp->ip_messages.data.port.receiver_name
2298 showportdestproc $kgm_portp
2301 printf " inactive-port\n"
2306 define showportmember
2311 set $kgm_portp = (struct ipc_port *)$arg0
2312 printf " 0x%08x ", $kgm_portp->ip_messages.data.port.receiver_name
2313 if ($kgm_portp->ip_object.io_bits & 0x80000000)
2319 printf "%5d ", $kgm_portp->ip_object.io_references
2320 showptr &($kgm_portp->ip_messages)
2321 printf " 0x%08x\n", $kgm_portp->ip_messages.data.port.msgcount
2325 set $kgm_iebt = ((ipc_port_t) $arg0)->ip_callstack
2326 set $kgm_iepid = ((ipc_port_t) $arg0)->ip_spares[0]
2327 set $kgm_procpid = ((proc_t) (((task_t) $arg1)->bsd_info))->p_pid
2328 if $kgm_iebt[0] != 0
2329 showptr $kgm_iebt[0]
2330 set $kgm_iebt_loop_ctr = 1
2331 while ($kgm_iebt_loop_ctr < 16 && $kgm_iebt[$kgm_iebt_loop_ctr])
2333 showptr $kgm_iebt[$kgm_iebt_loop_ctr]
2334 set $kgm_iebt_loop_ctr = $kgm_iebt_loop_ctr + 1
2336 if $kgm_iepid != $kgm_procpid
2337 printf " (%d)", $kgm_iepid
2346 set $kgm_portp = (struct ipc_port *)$arg0
2347 showptr &($kgm_portp->ip_messages)
2349 printf " 0x%08x ", $kgm_portp->ip_messages.data.port.receiver_name
2350 if ($kgm_portp->ip_object.io_bits & 0x80000000)
2356 printf "%5d ", $kgm_portp->ip_object.io_references
2357 set $kgm_destspacep = (struct ipc_space *)0
2358 showportdest $kgm_portp
2359 set $kgm_kmsgp = (ipc_kmsg_t)$kgm_portp->ip_messages.data.port.messages.ikmq_base
2360 if $arg1 && $kgm_kmsgp
2362 showkmsgint $kgm_kmsgp 1
2363 set $kgm_kmsgheadp = $kgm_kmsgp
2364 set $kgm_kmsgp = $kgm_kmsgp->ikm_next
2365 while $kgm_kmsgp != $kgm_kmsgheadp
2366 showkmsgint $kgm_kmsgp 1
2367 set $kgm_kmsgp = $kgm_kmsgp->ikm_next
2375 set $kgm_psetp = (struct ipc_pset *)$arg0
2376 showptr &($kgm_psetp->ips_messages)
2378 printf " 0x%08x ", $kgm_psetp->ips_messages.data.pset.local_name
2379 if ($kgm_psetp->ips_object.io_bits & 0x80000000)
2385 printf "%5d ", $kgm_psetp->ips_object.io_references
2386 showptr $kgm_psetp->ips_messages.data.pset.local_name
2388 set $kgm_setlinksp = &($kgm_psetp->ips_messages.data.pset.set_queue.wqs_setlinks)
2389 set $kgm_wql = (WaitQueueLink *)$kgm_setlinksp->next
2391 while ( (queue_entry_t)$kgm_wql != (queue_entry_t)$kgm_setlinksp)
2392 set $kgm_portp = (struct ipc_port *)((uintptr_t)($kgm_wql->wql_element->wqe_queue) - (uintptr_t)$kgm_portoff)
2394 set $kgm_destspacep = (struct ipc_space *)0
2395 showportdestproc $kgm_portp
2396 showportmemberheader
2399 showportmember $kgm_portp 0
2400 set $kgm_wql = (WaitQueueLink *)$kgm_wql->wql_setlinks.next
2408 set $kgm_portoff = &(((struct ipc_port *)0)->ip_messages)
2418 define showipcobject
2419 set $kgm_objectp = (ipc_object_t)$arg0
2420 if ($kgm_objectp->io_bits & 0x7fff0000)
2421 set $kgm_portoff = &(((struct ipc_port *)0)->ip_messages)
2422 showpset $kgm_objectp
2424 showport $kgm_objectp
2429 set $kgm_mqueue = *(struct ipc_mqueue *)$arg0
2430 if ($kgm_mqueue.data.pset.set_queue.wqs_wait_queue.wq_type == 0xf1d1)
2431 set $kgm_psetoff = &(((struct ipc_pset *)0)->ips_messages)
2432 set $kgm_pset = (((long)$arg0) - ((long)$kgm_psetoff))
2434 showpsetint $kgm_pset 1
2436 if ($kgm_mqueue.data.pset.set_queue.wqs_wait_queue.wq_type == 0xf1d0)
2437 set $kgm_portoff = &(((struct ipc_port *)0)->ip_messages)
2438 set $kgm_port = (((long)$arg0) - ((long)$kgm_portoff))
2440 showportint $kgm_port 1
2445 set $kgm_zone = (struct zone *)$arg0
2448 printf " %6d ",$kgm_zone->count
2449 printf "%8x ",$kgm_zone->cur_size
2450 printf "%8x ",$kgm_zone->max_size
2451 printf "%6d ",$kgm_zone->elem_size
2452 printf "%8x ",$kgm_zone->alloc_size
2453 printf " %8d ",$kgm_zone->num_allocs
2454 printf "%8d ",$kgm_zone->num_frees
2455 printf "%s ",$kgm_zone->zone_name
2457 if ($kgm_zone->exhaustible)
2460 if ($kgm_zone->collectable)
2463 if ($kgm_zone->expandable)
2466 if ($kgm_zone->noencrypt)
2476 printf " COUNT TOT_SZ MAX_SZ ELT_SZ ALLOC_SZ TOT_ALLOC TOT_FREE NAME\n"
2477 set $kgm_zone_ptr = (struct zone *)first_zone
2478 while ($kgm_zone_ptr != 0)
2479 zprint_one $kgm_zone_ptr
2480 set $kgm_zone_ptr = $kgm_zone_ptr->next_zone
2485 Syntax: (gdb) zprint
2486 | Routine to print a summary listing of all the kernel zones
2490 set $kgm_mtxgrp = (struct _lck_grp_ *)$arg0
2492 if ($kgm_mtxgrp->lck_grp_mtxcnt)
2494 printf " %8d ",$kgm_mtxgrp->lck_grp_mtxcnt
2495 printf "%12u ",$kgm_mtxgrp->lck_grp_stat.lck_grp_mtx_stat.lck_grp_mtx_util_cnt
2496 printf "%8u ",$kgm_mtxgrp->lck_grp_stat.lck_grp_mtx_stat.lck_grp_mtx_miss_cnt
2497 printf "%8u ",$kgm_mtxgrp->lck_grp_stat.lck_grp_mtx_stat.lck_grp_mtx_wait_cnt
2498 printf "%s ",&$kgm_mtxgrp->lck_grp_name
2507 printf " CNT UTIL MISS WAIT NAME\n"
2508 set $kgm_mtxgrp_ptr = (struct _lck_grp_ *)&lck_grp_queue
2509 set $kgm_mtxgrp_ptr = (struct _lck_grp_ *)$kgm_mtxgrp_ptr->lck_grp_link.next
2510 while ($kgm_mtxgrp_ptr != (struct _lck_grp_ *)&lck_grp_queue)
2511 showmtxgrp $kgm_mtxgrp_ptr
2512 set $kgm_mtxgrp_ptr = (struct _lck_grp_ *)$kgm_mtxgrp_ptr->lck_grp_link.next
2517 Syntax: (gdb) showallmtx
2518 | Routine to print a summary listing of all mutexes
2522 set $kgm_rwlckgrp = (struct _lck_grp_ *)$arg0
2524 if ($kgm_rwlckgrp->lck_grp_rwcnt)
2525 showptr $kgm_rwlckgrp
2526 printf " %8d ",$kgm_rwlckgrp->lck_grp_rwcnt
2527 printf "%12u ",$kgm_rwlckgrp->lck_grp_stat.lck_grp_rw_stat.lck_grp_rw_util_cnt
2528 printf "%8u ",$kgm_rwlckgrp->lck_grp_stat.lck_grp_rw_stat.lck_grp_rw_miss_cnt
2529 printf "%8u ",$kgm_rwlckgrp->lck_grp_stat.lck_grp_rw_stat.lck_grp_rw_wait_cnt
2530 printf "%s ",&$kgm_rwlckgrp->lck_grp_name
2539 printf " CNT UTIL MISS WAIT NAME\n"
2540 set $kgm_rwlckgrp_ptr = (struct _lck_grp_ *)&lck_grp_queue
2541 set $kgm_rwlckgrp_ptr = (struct _lck_grp_ *)$kgm_rwlckgrp_ptr->lck_grp_link.next
2542 while ($kgm_rwlckgrp_ptr != (struct _lck_grp_ *)&lck_grp_queue)
2543 showrwlckgrp $kgm_rwlckgrp_ptr
2544 set $kgm_rwlckgrp_ptr = (struct _lck_grp_ *)$kgm_rwlckgrp_ptr->lck_grp_link.next
2548 document showallrwlck
2549 Syntax: (gdb) showallrwlck
2550 | Routine to print a summary listing of all read/writer locks
2553 set $kdp_act_counter = 0
2554 set $kdp_arm_act_counter = 0
2573 define showcontext_int
2574 echo Context switched, current instruction pointer:
2580 set $newact = (struct thread *) $arg0
2582 if ($newact->kernel_stack == 0)
2583 echo This activation does not have a stack.\n
2585 output/a (unsigned) $newact.continuation
2588 if ($kgm_mtype == $kgm_mtype_ppc)
2589 if ($kdp_act_counter == 0)
2590 set $kdpstate = (struct savearea *) kdp.saved_state
2592 set $kdp_act_counter = $kdp_act_counter + 1
2593 set (struct savearea *) kdp.saved_state=$newact->machine->pcb
2596 set $pc=$newact->machine->pcb.save_srr0
2599 if ($kgm_mtype == $kgm_mtype_i386)
2600 set $kdpstatep = (struct x86_saved_state32 *) kdp.saved_state
2601 if ($kdp_act_counter == 0)
2602 set $kdpstate = *($kdpstatep)
2604 set $kdp_act_counter = $kdp_act_counter + 1
2606 set $kgm_statep = (struct x86_kernel_state *) \
2607 ($newact->kernel_stack + kernel_stack_size \
2608 - sizeof(struct x86_kernel_state))
2609 set $kdpstatep->ebx = $kgm_statep->k_ebx
2610 set $kdpstatep->ebp = $kgm_statep->k_ebp
2611 set $kdpstatep->edi = $kgm_statep->k_edi
2612 set $kdpstatep->esi = $kgm_statep->k_esi
2613 set $kdpstatep->eip = $kgm_statep->k_eip
2616 set $pc = $kgm_statep->k_eip
2619 if ($kgm_mtype == $kgm_mtype_x86_64)
2620 set $kdpstatep = (struct x86_saved_state64 *) kdp.saved_state
2621 if ($kdp_act_counter == 0)
2622 set $kdpstate = *($kdpstatep)
2624 set $kdp_act_counter = $kdp_act_counter + 1
2626 set $kgm_statep = (struct x86_kernel_state *) \
2627 ($newact->kernel_stack + kernel_stack_size \
2628 - sizeof(struct x86_kernel_state))
2629 set $kdpstatep->rbx = $kgm_statep->k_rbx
2630 set $kdpstatep->rbp = $kgm_statep->k_rbp
2631 set $kdpstatep->r12 = $kgm_statep->k_r12
2632 set $kdpstatep->r13 = $kgm_statep->k_r13
2633 set $kdpstatep->r14 = $kgm_statep->k_r14
2634 set $kdpstatep->r15 = $kgm_statep->k_r15
2635 set $kdpstatep->isf.rsp = $kgm_statep->k_rsp
2638 set $pc = $kgm_statep->k_rip
2641 if ($kgm_mtype == $kgm_mtype_arm)
2642 set $kdp_arm_act_counter = $kdp_arm_act_counter + 1
2643 if ($kdp_arm_act_counter == 1)
2654 set $r10_save = $r10
2655 set $r11_save = $r11
2656 set $r12_save = $r12
2661 set $pc_ctx = load_reg+8
2662 set $kgm_statep = (struct arm_saved_state *)((struct thread*)$arg0)->machine.kstackptr
2663 set $r0 = $kgm_statep->r[0]
2664 set $r1 = $kgm_statep->r[1]
2665 set $r2 = $kgm_statep->r[2]
2666 set $r3 = $kgm_statep->r[3]
2667 set $r4 = $kgm_statep->r[4]
2668 set $r5 = $kgm_statep->r[5]
2669 set $r6 = $kgm_statep->r[6]
2670 set $r8 = $kgm_statep->r[8]
2671 set $r9 = $kgm_statep->r[9]
2672 set $r10 = $kgm_statep->r[10]
2673 set $r11 = $kgm_statep->r[11]
2674 set $r12 = $kgm_statep->r[12]
2675 set $sp = $kgm_statep->sp
2676 set $lr = $kgm_statep->lr
2678 set $r7 = $kgm_statep->r[7]
2686 document switchtoact
2687 Syntax: switchtoact <address of activation>
2688 | This command allows gdb to examine the execution context and call
2689 | stack for the specified activation. For example, to view the backtrace
2690 | for an activation issue "switchtoact <address>", followed by "bt".
2691 | Before resuming execution, issue a "resetctx" command, to
2692 | return to the original execution context.
2697 if ($kgm_mtype == $kgm_mtype_ppc)
2698 if ($kdp_act_counter == 0)
2699 set $kdpstate = (struct savearea *) kdp.saved_state
2701 set $kdp_act_counter = $kdp_act_counter + 1
2702 set (struct savearea *) kdp.saved_state=(struct savearea *) $arg0
2705 set $pc=((struct savearea *) $arg0)->save_srr0
2708 if ($kgm_mtype == $kgm_mtype_arm)
2710 set $kdp_arm_act_counter = $kdp_arm_act_counter + 1
2711 if ($kdp_arm_act_counter == 1)
2722 set $r10_save = $r10
2723 set $r11_save = $r11
2724 set $r12_save = $r12
2729 set $kgm_statep = (struct arm_saved_state *)$arg0
2730 set $r0 = $kgm_statep->r[0]
2731 set $r1 = $kgm_statep->r[1]
2732 set $r2 = $kgm_statep->r[2]
2733 set $r3 = $kgm_statep->r[3]
2734 set $r4 = $kgm_statep->r[4]
2735 set $r5 = $kgm_statep->r[5]
2736 set $r6 = $kgm_statep->r[6]
2737 set $r8 = $kgm_statep->r[8]
2738 set $r9 = $kgm_statep->r[9]
2739 set $r10 = $kgm_statep->r[10]
2740 set $r11 = $kgm_statep->r[11]
2741 set $r12 = $kgm_statep->r[12]
2742 set $sp = $kgm_statep->sp
2743 set $lr = $kgm_statep->lr
2744 set $r7 = $kgm_statep->r[7]
2745 set $pc = $kgm_statep->pc
2750 echo switchtoctx not implemented for this architecture.\n
2754 document switchtoctx
2755 Syntax: switchtoctx <address of pcb>
2756 | This command allows gdb to examine an execution context and dump the
2757 | backtrace for this execution context.
2758 | Before resuming execution, issue a "resetctx" command, to
2759 | return to the original execution context.
2764 if ($kdp_act_counter != 0)
2765 if ($kgm_mtype == $kgm_mtype_ppc)
2766 set (struct savearea *)kdp.saved_state=$kdpstate
2769 set $pc=((struct savearea *) kdp.saved_state)->save_srr0
2771 set $kdp_act_counter = 0
2773 if ($kgm_mtype == $kgm_mtype_i386)
2774 set $kdpstatep = (struct x86_saved_state32 *) kdp.saved_state
2775 set *($kdpstatep)=$kdpstate
2778 set $pc=$kdpstatep->eip
2780 set $kdp_act_counter = 0
2782 if ($kgm_mtype == $kgm_mtype_x86_64)
2783 set $kdpstatep = (struct x86_saved_state64 *) kdp.saved_state
2784 set *($kdpstatep)=$kdpstate
2787 set $pc=$kdpstatep->isf.rip
2789 set $kdp_act_counter = 0
2793 if ($kgm_mtype == $kgm_mtype_arm && $kdp_arm_act_counter != 0)
2794 echo Restoring context\n
2813 set $r10 = $r10_save
2815 set $r11 = $r11_save
2817 set $r12 = $r12_save
2829 set $kdp_arm_act_counter = 0
2835 | Returns to the original execution context. This command should be
2836 | issued if you wish to resume execution after using the "switchtoact"
2837 | or "switchtoctx" commands.
2840 # This is a pre-hook for the continue command, to prevent inadvertent attempts
2841 # to resume from the context switched to for examination.
2842 define hook-continue
2846 # This is a pre-hook for the detach command, to prevent inadvertent attempts
2847 # to resume from the context switched to for examination.
2853 set $resume = KDP_DUMPINFO_SETINFO | KDP_DUMPINFO_RESUME
2859 | The target system will resume when detaching or exiting from gdb.
2860 | This is the default behavior.
2864 set $noresume = KDP_DUMPINFO_SETINFO | KDP_DUMPINFO_NORESUME
2865 dumpinfoint $noresume
2869 | Syntax: resume_off
2870 | The target system won't resume after detaching from gdb and
2871 | can be attached with a new gdb session
2875 set $kgm_panic_bufptr = debug_buf
2876 set $kgm_panic_bufptr_max = debug_buf_ptr
2877 while $kgm_panic_bufptr < $kgm_panic_bufptr_max
2878 if *(char *)$kgm_panic_bufptr == 10
2881 printf "%c", *(char *)$kgm_panic_bufptr
2883 set $kgm_panic_bufptr= (char *)$kgm_panic_bufptr + 1
2889 | Display the panic log information
2893 define dumpcallqueue
2894 set $kgm_callhead = $arg0
2895 set $kgm_callentry = $kgm_callhead->next
2897 while $kgm_callentry != $kgm_callhead
2898 set $kgm_call = (struct call_entry *)$kgm_callentry
2899 printf "0x%08x ", $kgm_call
2900 printf "0x%08x 0x%08x ", $kgm_call->param0, $kgm_call->param1
2901 output $kgm_call->deadline
2903 output $kgm_call->func
2905 set $kgm_i = $kgm_i + 1
2906 set $kgm_callentry = $kgm_callentry->next
2908 printf "%d entries\n", $kgm_i
2911 document dumpcallqueue
2912 | Syntax: dumpcallqueue <queue head>
2913 | Displays the contents of the specified call_entry queue.
2917 showtaskthreads $arg0
2919 document showtaskacts
2920 | See help showtaskthreads.
2926 document showallacts
2927 | See help showallthreads.
2942 document resetstacks
2943 | Syntax: resetstacks
2944 | Internal kgmacro routine used by the "showuserstack" macro
2945 | to reset the target pmap to the kernel pmap.
2948 #Barely effective hacks to work around bugs in the "flush" and "update"
2949 #gdb commands in Tiger (up to 219); these aren't necessary with Panther
2950 #gdb, but do no harm.
2951 define _kgm_flush_loop
2952 set $kgm_flush_loop_ctr = 0
2953 while ($kgm_flush_loop_ctr < 30)
2956 set $kgm_flush_loop_ctr = $kgm_flush_loop_ctr + 1
2960 define _kgm_update_loop
2961 set $kgm_update_loop_ctr = 0
2962 while ($kgm_update_loop_ctr < 30)
2964 set $kgm_update_loop_ctr = $kgm_update_loop_ctr + 1
2967 # Internal routine used by "_loadfrom" to read from 64-bit addresses
2970 # set up the manual KDP packet
2971 set manual_pkt.input = 0
2972 set manual_pkt.len = sizeof(kdp_readmem64_req_t)
2973 set $kgm_pkt = (kdp_readmem64_req_t *)&manual_pkt.data
2974 set $kgm_pkt->hdr.request = KDP_READMEM64
2975 set $kgm_pkt->hdr.len = sizeof(kdp_readmem64_req_t)
2976 set $kgm_pkt->hdr.is_reply = 0
2977 set $kgm_pkt->hdr.seq = 0
2978 set $kgm_pkt->hdr.key = 0
2979 set $kgm_pkt->address = (uint64_t)$arg0
2980 set $kgm_pkt->nbytes = sizeof(uint64_t)
2981 set manual_pkt.input = 1
2982 # dummy to make sure manual packet is executed
2983 set $kgm_dummy = &_mh_execute_header
2984 set $kgm_pkt = (kdp_readmem64_reply_t *)&manual_pkt.data
2985 if ($kgm_pkt->error == 0)
2986 set $kgm_k32read64 = *(uint64_t *)$kgm_pkt->data
2988 set $kgm_k32read64 = 0
2992 # Internal routine used by "showx86backtrace" to abstract possible loads from
2996 set $kgm_loadval = *(uintptr_t *)$arg0
2998 if ($kgm_x86_abi == 0xe)
2999 set $kgm_loadval = *(uint32_t *)$arg0
3001 if ($kgm_x86_abi == 0xf)
3002 if ($kgm_mtype == $kgm_mtype_i386)
3004 set $kgm_loadval = $kgm_k32read64
3006 set $kgm_loadval = *(uint64_t *)$arg0
3014 #This is necessary since gdb often doesn't do backtraces on x86 correctly
3015 #in the absence of symbols.The code below in showuserstack and
3016 #showx86backtrace also contains several workarouds for the gdb bug where
3017 #gdb stops macro evaluation because of spurious "Cannot read memory"
3018 #errors on x86. These errors appear on ppc as well, but they don't
3019 #always stop macro evaluation.
3021 set $kgm_cur_frame = 0
3023 set $kgm_x86_abi = 0
3024 define showx86backtrace
3025 if ($kgm_mtype == $kgm_mtype_i386)
3026 set $kgm_frame_reg = $ebp
3028 set $kgm_ret_off = 4
3030 if ($kgm_mtype == $kgm_mtype_x86_64)
3031 set $kgm_frame_reg = $rbp
3033 set $kgm_ret_off = 8
3036 if ($kgm_x86_abi == 0xe)
3037 set $kgm_ret_off = 4
3039 if ($kgm_x86_abi == 0xf)
3040 set $kgm_ret_off = 8
3043 if ($kgm_cur_frame == 0)
3044 set $kgm_cur_frame = $kgm_frame_reg
3046 if ($kgm_cur_pc == 0)
3047 set $kgm_cur_pc = $kgm_pc
3049 printf "0: Frame: 0x%016llx PC: 0x%016llx\n", $kgm_cur_frame, $kgm_cur_pc
3050 if (!(($kgm_x86_abi == 0xf) && ($kgm_mtype == $kgm_mtype_i386)))
3053 set $kgm_tmp_frame = $kgm_cur_frame
3054 set $kgm_cur_frame = 0
3056 _loadfrom ($kgm_tmp_frame)
3057 set $kgm_prev_frame = $kgm_loadval
3058 _loadfrom ($kgm_tmp_frame+$kgm_ret_off)
3059 set $kgm_prev_pc = $kgm_loadval
3060 set $kgm_frameno = 1
3061 while ($kgm_prev_frame != 0) && ($kgm_prev_frame != 0x0000000800000008)
3062 printf "%d: Saved frame: 0x%016llx Saved PC: 0x%016llx\n", $kgm_frameno, $kgm_prev_frame, $kgm_prev_pc
3063 if (!(($kgm_x86_abi == 0xf) && ($kgm_mtype == $kgm_mtype_i386)))
3066 _loadfrom ($kgm_prev_frame+$kgm_ret_off)
3067 set $kgm_prev_pc = $kgm_loadval
3068 _loadfrom ($kgm_prev_frame)
3069 set $kgm_prev_frame = $kgm_loadval
3070 set $kgm_frameno = $kgm_frameno + 1
3073 set $kgm_x86_abi = 0
3076 define showx86backtrace2
3077 set $kgm_cur_frame = $arg0
3078 set $kgm_cur_pc = $arg1
3082 define showuserstack
3084 if ($kgm_mtype == $kgm_mtype_ppc)
3085 if ($kdp_act_counter == 0)
3086 set $kdpstate = (struct savearea *) kdp.saved_state
3088 set $kdp_act_counter = $kdp_act_counter + 1
3089 set $newact = (struct thread *) $arg0
3091 set $checkpc = $newact->machine->upcb.save_srr0
3093 echo This activation does not appear to have
3094 echo \20 a valid user context.\n
3096 set (struct savearea *) kdp.saved_state=$newact->machine->upcb
3098 #flush and update seem to be executed lazily by gdb on Tiger, hence the
3099 #repeated invocations - see 3743135
3101 # This works because the new pmap is used only for reads
3102 set kdp_pmap = $newact->task->map->pmap
3114 if (($kgm_mtype & $kgm_mtype_x86_mask) == $kgm_mtype_x86_any)
3115 set $newact = (struct thread *) $arg0
3116 set $newiss = (x86_saved_state_t *) ($newact->machine->iss)
3117 set $kgm_x86_abi = $newiss.flavor
3118 if ($newiss.flavor == 0xf)
3119 set $checkpc = $newiss.uss.ss_64.isf.rip
3120 set $checkframe = $newiss.uss.ss_64.rbp
3123 set $checkpc = $newiss.uss.ss_32.eip
3124 set $checkframe = $newiss.uss.ss_32.ebp
3128 echo This activation does not appear to have
3129 echo \20 a valid user context.\n
3131 set $kgm_cur_frame = $checkframe
3132 set $kgm_cur_pc = $checkpc
3133 # When have more than one argument is present, don't print usage
3135 printf "You may now issue the showx86backtrace command to see the user space backtrace for this thread ("
3137 printf "); you can also examine memory locations in this address space (pmap "
3138 showptr $newact->task->map->pmap
3139 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"
3141 set kdp_pmap = $newact->task->map->pmap
3146 if ($kgm_mtype == $kgm_mtype_arm)
3147 if (kdp->is_conn > 0)
3148 set $kgm_threadp = (struct thread *)$arg0
3149 set $kgm_saved_pmap = kdp_pmap
3151 showactint $kgm_threadp 0
3152 set $kgm_thread_pmap = $kgm_threadp->task->map->pmap
3153 set $kgm_thread_sp = $kgm_threadp.machine->PcbData.r[7]
3154 set kdp_pmap = $kgm_thread_pmap
3155 while ($kgm_thread_sp != 0)
3156 set $link_register = *($kgm_thread_sp + 4)
3159 showptr $kgm_thread_sp
3161 showptr $link_register
3163 set $kgm_thread_sp = *$kgm_thread_sp
3165 set kdp_pmap = $kgm_saved_pmap
3167 echo You must be connected via nanokdp to use this macro\n
3170 echo showuserstack not supported on this architecture\n
3175 document showuserstack
3176 Syntax: showuserstack <address of thread activation>
3177 |This command displays a numeric backtrace for the user space stack of
3178 |the given thread activation. It may, of course, fail to display a
3179 |complete backtrace if portions of the user stack are not mapped in.
3180 |Symbolic backtraces can be obtained either by running gdb on the
3181 |user space binary, or a tool such as "symbolicate".
3182 |Note that while this command works on Panther's gdb, an issue
3183 |with Tiger gdb (3743135) appears to hamper the evaluation of this
3184 |macro in some cases.
3187 define showtaskuserstacks
3188 set $kgm_taskp = (struct task *)$arg0
3189 set $kgm_head_actp = &($kgm_taskp->threads)
3190 set $kgm_actp = (struct thread *)($kgm_taskp->threads.next)
3191 while $kgm_actp != $kgm_head_actp
3192 printf "For thread "
3195 showuserstack $kgm_actp quiet
3196 if (($kgm_mtype & $kgm_mtype_x86_mask) == $kgm_mtype_x86_any)
3200 set $kgm_actp = (struct thread *)($kgm_actp->task_threads.next)
3203 showuserlibraries $kgm_taskp
3205 document showtaskuserstacks
3206 Syntax: (gdb) showtaskuserstacks <task>
3207 | Print out the user stack for each thread in a task, followed by the user libraries.
3211 define showuserregisters
3212 set $kgm_threadp = (struct thread *)$arg0
3213 set $kgm_taskp = $kgm_threadp->task
3214 if (($kgm_mtype & $kgm_mtype_x86_mask) == $kgm_mtype_x86_any)
3215 set $newiss = (x86_saved_state_t *) ($kgm_threadp->machine.iss)
3216 set $kgm_x86_abi = $newiss.flavor
3217 if ($newiss.flavor == 0xf)
3218 printf "X86 Thread State (64-bit):\n"
3219 set $kgm_ss64 = $newiss.uss.ss_64
3222 showuserptr $kgm_ss64.rax
3224 showuserptr $kgm_ss64.rbx
3226 showuserptr $kgm_ss64.rcx
3228 showuserptr $kgm_ss64.rdx
3232 showuserptr $kgm_ss64.rdi
3234 showuserptr $kgm_ss64.rsi
3236 showuserptr $kgm_ss64.rbp
3238 showuserptr $kgm_ss64.isf.rsp
3242 showuserptr $kgm_ss64.r8
3244 showuserptr $kgm_ss64.r9
3246 showuserptr $kgm_ss64.r10
3248 showuserptr $kgm_ss64.r11
3252 showuserptr $kgm_ss64.r12
3254 showuserptr $kgm_ss64.r13
3256 showuserptr $kgm_ss64.r14
3258 showuserptr $kgm_ss64.r15
3262 showuserptr $kgm_ss64.isf.rip
3264 showuserptr $kgm_ss64.isf.rflags
3266 showuserptr $kgm_ss64.cr2
3269 printf "X86 Thread State (32-bit):\n"
3270 set $kgm_ss32 = $newiss.uss.ss_32
3273 showuserptr $kgm_ss32.eax
3275 showuserptr $kgm_ss32.ebx
3277 showuserptr $kgm_ss32.ecx
3279 showuserptr $kgm_ss32.edx
3283 showuserptr $kgm_ss32.edi
3285 showuserptr $kgm_ss32.esi
3287 showuserptr $kgm_ss32.ebp
3289 showuserptr $kgm_ss32.uesp
3293 showuserptr $kgm_ss32.ss
3295 showuserptr $kgm_ss32.efl
3297 showuserptr $kgm_ss32.eip
3299 showuserptr $kgm_ss32.cs
3303 showuserptr $kgm_ss32.ds
3305 showuserptr $kgm_ss32.es
3307 showuserptr $kgm_ss32.fs
3309 showuserptr $kgm_ss32.gs
3313 showuserptr $kgm_ss32.cr2
3317 if ($kgm_mtype == $kgm_mtype_arm)
3318 printf "ARM Thread State:\n"
3319 set $kgm_pcb = (arm_saved_state_t *) ($kgm_threadp->machine.upcb)
3322 showuserptr $kgm_pcb.r[0]
3324 showuserptr $kgm_pcb.r[1]
3326 showuserptr $kgm_pcb.r[2]
3328 showuserptr $kgm_pcb.r[3]
3332 showuserptr $kgm_pcb.r[4]
3334 showuserptr $kgm_pcb.r[5]
3336 showuserptr $kgm_pcb.r[6]
3338 showuserptr $kgm_pcb.r[7]
3342 showuserptr $kgm_pcb.r[8]
3344 showuserptr $kgm_pcb.r[9]
3346 showuserptr $kgm_pcb.r[10]
3348 showuserptr $kgm_pcb.r[11]
3352 showuserptr $kgm_pcb.r[12]
3354 showuserptr $kgm_pcb.sp
3356 showuserptr $kgm_pcb.lr
3358 showuserptr $kgm_pcb.pc
3362 showuserptr $kgm_pcb.cpsr
3365 echo showuserregisters not supported on this architecture\n
3369 document showuserregisters
3370 Syntax: showuserstack <address of thread>
3371 |This command displays the last known user register state
3372 |for the thread. This map not be correct for cases where
3373 |the thread is currently executing in userspace. However
3374 |for threads that have entered the kernel (either explicitly
3375 |with a system call or implicitly with a fault), it should
3379 define showtaskuserregisters
3380 set $kgm_taskp = (struct task *)$arg0
3381 set $kgm_head_actp = &($kgm_taskp->threads)
3382 set $kgm_actp = (struct thread *)($kgm_taskp->threads.next)
3383 while $kgm_actp != $kgm_head_actp
3384 printf "For thread "
3387 showuserregisters $kgm_actp
3388 set $kgm_actp = (struct thread *)($kgm_actp->task_threads.next)
3392 document showtaskuserregisters
3393 Syntax: (gdb) showtaskuserregisters <task>
3394 | Print out the user registers for each thread in a task
3398 # Alternatively, set *(*(unsigned **) 0x2498) = 1
3399 # (or 0x5498 on PPC, 0xffffff8000002928 on x86_64, 0xffff049c on arm)
3400 manualhdrint $kgm_kdp_pkt_hostreboot
3406 |Reboot the remote target machine; not guaranteed to succeed.
3409 define kdpversionint
3410 # set up the manual KDP packet
3411 set manual_pkt.input = 0
3412 set manual_pkt.len = sizeof(kdp_version_req_t)
3413 set $kgm_pkt = (kdp_version_req_t *)&manual_pkt.data
3414 set $kgm_pkt->hdr.request = KDP_VERSION
3415 set $kgm_pkt->hdr.len = sizeof(kdp_version_req_t)
3416 set $kgm_pkt->hdr.is_reply = 0
3417 set $kgm_pkt->hdr.seq = 0
3418 set $kgm_pkt->hdr.key = 0
3419 set manual_pkt.input = 1
3420 # dummy to make sure manual packet is executed
3421 set $kgm_dummy = &_mh_execute_header
3422 set $kgm_pkt = (kdp_version_reply_t *)&manual_pkt.data
3423 set $kgm_kdp_version = $kgm_pkt->version
3424 set $kgm_kdp_feature = $kgm_pkt->feature
3429 printf "KDP VERSION = %d, FEATURE = 0x%x\n", $kgm_kdp_version, $kgm_kdp_feature
3432 document kdp-version
3434 |Get the KDP protocol version being used by the kernel.
3438 # set up the manual KDP packet
3439 set manual_pkt.input = 0
3441 set manual_pkt.len = sizeof(kdp_dumpinfo_req_t)
3442 set $kgm_pkt = (kdp_dumpinfo_req_t *)&manual_pkt.data
3443 set $kgm_pkt->hdr.request = KDP_DUMPINFO
3444 set $kgm_pkt->hdr.len = sizeof(kdp_dumpinfo_req_t)
3445 set $kgm_pkt->hdr.is_reply = 0
3446 set $kgm_pkt->hdr.seq = 0
3447 set $kgm_pkt->hdr.key = 0
3448 set $kgm_pkt->type = $arg0
3449 set $kgm_pkt->name = ""
3450 set $kgm_pkt->destip = ""
3451 set $kgm_pkt->routerip = ""
3452 set $kgm_pkt->port = 0
3455 set $kgm_pkt->name = "$arg1"
3458 set $kgm_pkt->destip = "$arg2"
3461 set $kgm_pkt->routerip = "$arg3"
3464 set $kgm_pkt->port = $arg4
3467 set manual_pkt.input = 1
3468 # dummy to make sure manual packet is executed
3469 set $kgm_dummy = &_mh_execute_header
3474 dumpinfoint KDP_DUMPINFO_CORE $arg1 $arg0
3476 dumpinfoint KDP_DUMPINFO_CORE \0 $arg0
3481 Syntax: sendcore <IP address> [filename]
3482 |Configure the kernel to transmit a kernel coredump to a server (kdumpd)
3483 |at the specified IP address. This is useful when the remote target has
3484 |not been previously configured to transmit coredumps, and you wish to
3485 |preserve kernel state for later examination. NOTE: You must issue a "continue"
3486 |command after using this macro to trigger the kernel coredump. The kernel
3487 |will resume waiting in the debugger after completion of the coredump. You
3488 |may disable coredumps by executing the "disablecore" macro. You can
3489 |optionally specify the filename to be used for the generated core file.
3494 dumpinfoint KDP_DUMPINFO_SYSTEMLOG $arg1 $arg0
3496 dumpinfoint KDP_DUMPINFO_SYSTEMLOG \0 $arg0
3501 Syntax: sendsyslog <IP address> [filename]
3502 |Configure the kernel to transmit a kernel system log to a server (kdumpd)
3503 |at the specified IP address. NOTE: You must issue a "continue"
3504 |command after using this macro to trigger the kernel system log. The kernel
3505 |will resume waiting in the debugger after completion. You can optionally
3506 |specify the name to be used for the generated system log.
3512 dumpinfoint KDP_DUMPINFO_PANICLOG $arg1 $arg0
3514 dumpinfoint KDP_DUMPINFO_PANICLOG \0 $arg0
3517 printf "No panic log available.\n"
3521 document sendpaniclog
3522 Syntax: sendpaniclog <IP address> [filename]
3523 |Configure the kernel to transmit a kernel paniclog to a server (kdumpd)
3524 |at the specified IP address. NOTE: You must issue a "continue"
3525 |command after using this macro to trigger the kernel panic log. The kernel
3526 |will resume waiting in the debugger after completion. You can optionally
3527 |specify the name to be used for the generated panic log.
3531 dumpinfoint KDP_DUMPINFO_GETINFO
3532 set $kgm_dumpinfo = (kdp_dumpinfo_reply_t *) manual_pkt.data
3533 if $kgm_dumpinfo->type & KDP_DUMPINFO_REBOOT
3534 printf "Sysem will reboot after kernel info gets dumped.\n"
3536 printf "Sysem will not reboot after kernel info gets dumped.\n"
3538 if $kgm_dumpinfo->type & KDP_DUMPINFO_NORESUME
3539 printf "System will allow a re-attach after a KDP disconnect.\n"
3541 printf "System will resume after a KDP disconnect.\n"
3543 set $kgm_dumpinfo_type = $kgm_dumpinfo->type & KDP_DUMPINFO_MASK
3544 if $kgm_dumpinfo_type == KDP_DUMPINFO_DISABLE
3545 printf "Kernel not setup for remote dumps.\n"
3547 printf "Remote dump type: "
3548 if $kgm_dumpinfo_type == KDP_DUMPINFO_CORE
3549 printf "Core file\n"
3551 if $kgm_dumpinfo_type == KDP_DUMPINFO_PANICLOG
3552 printf "Panic log\n"
3554 if $kgm_dumpinfo_type == KDP_DUMPINFO_SYSTEMLOG
3555 printf "System log\n"
3559 if $kgm_dumpinfo->name[0] == '\0'
3560 printf "(autogenerated)\n"
3562 printf "%s\n", $kgm_dumpinfo->name
3565 printf "Network Info: %s[%d] ", $kgm_dumpinfo->destip, $kgm_dumpinfo->port
3566 if $kgm_dumpinfo->routerip[0] == '\0'
3569 printf "Router: %s\n", $kgm_dumpinfo->routerip
3574 document getdumpinfo
3576 |Retrieve the current remote dump settings.
3580 dumpinfoint KDP_DUMPINFO_SETINFO $arg0 $arg1 $arg2 $arg3
3583 document setdumpinfo
3584 Syntax: setdumpinfo <filename> <ip> <router> <port>
3585 |Configure the current remote dump settings. Specify \0 if you
3586 |want to use the defaults (filename) or previously configured
3587 |settings (ip/router). Specify 0 for the port if you wish to
3588 |use the previously configured/default setting for that.
3592 dumpinfoint KDP_DUMPINFO_DISABLE
3595 document disablecore
3597 |Reconfigures the kernel so that it no longer transmits kernel coredumps. This
3598 |complements the "sendcore" macro, but it may be used if the kernel has been
3599 |configured to transmit coredumps through boot-args as well.
3602 define switchtocorethread
3603 set $newact = (struct thread *) $arg0
3605 if ($newact->kernel_stack == 0)
3606 echo This thread does not have a stack.\n
3608 output/a (unsigned) $newact.continuation
3611 if ($kgm_mtype == $kgm_mtype_ppc)
3612 loadcontext $newact->machine->pcb
3614 set $pc = $newact->machine->pcb.save_srr0
3616 if (($kgm_mtype & $kgm_mtype_x86_mask) == $kgm_mtype_x86_any)
3617 set $kgm_cstatep = (struct x86_kernel_state *) \
3618 ($newact->kernel_stack + kernel_stack_size \
3619 - sizeof(struct x86_kernel_state))
3620 loadcontext $kgm_cstatep
3623 echo switchtocorethread not supported on this architecture\n
3630 document switchtocorethread
3631 Syntax: switchtocorethread <address of activation>
3632 | The corefile equivalent of "switchtoact". When debugging a kernel coredump
3633 | file, this command can be used to examine the execution context and stack
3634 | trace for a given thread activation. For example, to view the backtrace
3635 | for a thread issue "switchtocorethread <address>", followed by "bt".
3636 | Before resuming execution, issue a "resetcorectx" command, to
3637 | return to the original execution context. Note that this command
3638 | requires gdb support, as documented in Radar 3401283.
3643 if ($kgm_mtype == $kgm_mtype_ppc)
3644 set $kgm_contextp = (struct savearea *) $arg0
3645 set $pc = $kgm_contextp.save_srr0
3646 set $r1 = $kgm_contextp.save_r1
3647 set $lr = $kgm_contextp.save_lr
3649 set $r2 = $kgm_contextp.save_r2
3650 set $r3 = $kgm_contextp.save_r3
3651 set $r4 = $kgm_contextp.save_r4
3652 set $r5 = $kgm_contextp.save_r5
3653 set $r6 = $kgm_contextp.save_r6
3654 set $r7 = $kgm_contextp.save_r7
3655 set $r8 = $kgm_contextp.save_r8
3656 set $r9 = $kgm_contextp.save_r9
3657 set $r10 = $kgm_contextp.save_r10
3658 set $r11 = $kgm_contextp.save_r11
3659 set $r12 = $kgm_contextp.save_r12
3660 set $r13 = $kgm_contextp.save_r13
3661 set $r14 = $kgm_contextp.save_r14
3662 set $r15 = $kgm_contextp.save_r15
3663 set $r16 = $kgm_contextp.save_r16
3664 set $r17 = $kgm_contextp.save_r17
3665 set $r18 = $kgm_contextp.save_r18
3666 set $r19 = $kgm_contextp.save_r19
3667 set $r20 = $kgm_contextp.save_r20
3668 set $r21 = $kgm_contextp.save_r21
3669 set $r22 = $kgm_contextp.save_r22
3670 set $r23 = $kgm_contextp.save_r23
3671 set $r24 = $kgm_contextp.save_r24
3672 set $r25 = $kgm_contextp.save_r25
3673 set $r26 = $kgm_contextp.save_r26
3674 set $r27 = $kgm_contextp.save_r27
3675 set $r28 = $kgm_contextp.save_r28
3676 set $r29 = $kgm_contextp.save_r29
3677 set $r30 = $kgm_contextp.save_r30
3678 set $r31 = $kgm_contextp.save_r31
3680 set $cr = $kgm_contextp.save_cr
3681 set $ctr = $kgm_contextp.save_ctr
3683 if ($kgm_mtype == $kgm_mtype_i386)
3684 set $kgm_contextp = (struct x86_kernel_state *) $arg0
3685 set $ebx = $kgm_contextp->k_ebx
3686 set $ebp = $kgm_contextp->k_ebp
3687 set $edi = $kgm_contextp->k_edi
3688 set $esi = $kgm_contextp->k_esi
3689 set $eip = $kgm_contextp->k_eip
3690 set $pc = $kgm_contextp->k_eip
3692 if ($kgm_mtype == $kgm_mtype_x86_64)
3693 set $kgm_contextp = (struct x86_kernel_state *) $arg0
3694 set $rbx = $kgm_contextp->k_rbx
3695 set $rbp = $kgm_contextp->k_rbp
3696 set $r12 = $kgm_contextp->k_r12
3697 set $r13 = $kgm_contextp->k_r13
3698 set $r14 = $kgm_contextp->k_r14
3699 set $r15 = $kgm_contextp->k_r15
3700 set $rip = $kgm_contextp->k_rip
3701 set $pc = $kgm_contextp->k_rip
3703 echo loadcontext not supported on this architecture\n
3711 if ($kgm_mtype == $kgm_mtype_ppc)
3712 set $kgm_corecontext = (struct savearea *) kdp.saved_state
3713 loadcontext $kgm_corecontext
3715 if ($kgm_mtype == $kgm_mtype_i386)
3716 set $kdpstatep = (struct x86_saved_state32 *) kdp.saved_state
3717 set $ebx = $kdpstatep->ebx
3718 set $ebp = $kdpstatep->ebp
3719 set $edi = $kdpstatep->edi
3720 set $esi = $kdpstatep->esi
3721 set $eip = $kdpstatep->eip
3722 set $eax = $kdpstatep->eax
3723 set $ecx = $kdpstatep->ecx
3724 set $edx = $kdpstatep->edx
3727 set $pc = $kdpstatep->eip
3730 echo resetcorectx not supported on this architecture\n
3736 document resetcorectx
3737 Syntax: resetcorectx
3738 | The corefile equivalent of "resetctx". Returns to the original
3739 | execution context (that of the active thread at the time of the NMI or
3740 | panic). This command should be issued if you wish to resume
3741 | execution after using the "switchtocorethread" command.
3744 #Helper function for "showallgdbstacks"
3746 define showgdbthread
3747 printf " 0x%08x ", $arg0
3748 set $kgm_thread = *(struct thread *)$arg0
3749 printf "0x%08x ", $arg0
3750 printf "%3d ", $kgm_thread.sched_pri
3751 set $kgm_state = $kgm_thread.state
3752 if $kgm_state & 0x80
3755 if $kgm_state & 0x40
3758 if $kgm_state & 0x20
3761 if $kgm_state & 0x10
3764 if $kgm_state & 0x08
3767 if $kgm_state & 0x04
3770 if $kgm_state & 0x02
3773 if $kgm_state & 0x01
3775 printf "0x%08x ", $kgm_thread.wait_queue
3776 output /a (unsigned) $kgm_thread.wait_event
3777 if ($kgm_thread.uthread != 0)
3778 set $kgm_uthread = (struct uthread *)$kgm_thread.uthread
3779 if ($kgm_uthread->uu_wmesg != 0)
3780 printf " \"%s\"", $kgm_uthread->uu_wmesg
3785 if ($kgm_thread.kernel_stack != 0)
3786 if ($kgm_thread.reserved_stack != 0)
3787 printf "\n\t\treserved_stack=0x%08x", $kgm_thread.reserved_stack
3789 printf "\n\t\tkernel_stack=0x%08x", $kgm_thread.kernel_stack
3790 if ($kgm_mtype == $kgm_mtype_ppc)
3791 set $mysp = $kgm_thread.machine.pcb->save_r1
3793 if ($kgm_mtype == $kgm_mtype_i386)
3794 set $kgm_statep = (struct x86_kernel_state *) \
3795 ($kgm_thread->kernel_stack + kernel_stack_size \
3796 - sizeof(struct x86_kernel_state))
3797 set $mysp = $kgm_statep->k_ebp
3799 if ($kgm_mtype == $kgm_mtype_arm)
3800 if (((unsigned long)$r7 < ((unsigned long) ($kgm_thread->kernel_stack+kernel_stack_size))) \
3801 && ((unsigned long)$r7 > (unsigned long) ($kgm_thread->kernel_stack)))
3804 set $kgm_statep = (struct arm_saved_state *)$kgm_thread.machine.kstackptr
3805 set $mysp = $kgm_statep->r[7]
3809 printf "\n\t\tstacktop=0x%08x", $mysp
3813 switchtocorethread $arg0
3817 printf "\n\t\t\tcontinuation="
3818 output /a (unsigned) $kgm_thread.continuation
3826 #Use of this macro is currently (8/04) blocked by the fact that gdb
3827 #stops evaluating macros when encountering an error, such as a failure
3828 #to read memory from a certain location. Until this issue (described in
3829 #3758949) is addressed, evaluation of this macro may stop upon
3830 #encountering such an error.
3832 define showallgdbstacks
3833 set $kgm_head_taskp = &tasks
3834 set $kgm_taskp = (struct task *)($kgm_head_taskp->next)
3835 while $kgm_taskp != $kgm_head_taskp
3837 showtaskint $kgm_taskp
3838 set $kgm_head_actp = &($kgm_taskp->threads)
3839 set $kgm_actp = (struct thread *)($kgm_taskp->threads.next)
3840 while $kgm_actp != $kgm_head_actp
3842 showgdbthread $kgm_actp 1 0
3843 set $kgm_actp = (struct thread *)($kgm_actp->task_threads.next)
3846 set $kgm_taskp = (struct task *)($kgm_taskp->tasks.next)
3851 document showallgdbstacks
3852 Syntax: showallgdbstacks
3853 | An alternative to "showallstacks". Iterates through the task list and
3854 | displays a gdb generated backtrace for each kernel thread. It is
3855 | advantageous in that it is much faster than "showallstacks", and
3856 | decodes function call arguments and displays source level traces, but
3857 | it has the drawback that it doesn't determine if frames belong to
3858 | functions from kernel extensions, as with "showallstacks".
3859 | This command may terminate prematurely because of a gdb bug
3860 | (Radar 3758949), which stops macro evaluation on memory read
3864 define showallgdbcorestacks
3866 set $kgm_head_taskp = &tasks
3867 set $kgm_taskp = (struct task *)($kgm_head_taskp->next)
3868 while $kgm_taskp != $kgm_head_taskp
3870 showtaskint $kgm_taskp
3871 set $kgm_head_actp = &($kgm_taskp->threads)
3872 set $kgm_actp = (struct thread *)($kgm_taskp->threads.next)
3873 while $kgm_actp != $kgm_head_actp
3875 showgdbthread $kgm_actp 1 1
3876 set $kgm_actp = (struct thread *)($kgm_actp->task_threads.next)
3879 set $kgm_taskp = (struct task *)($kgm_taskp->tasks.next)
3885 document showallgdbcorestacks
3886 Syntax: showallgdbcorestacks
3887 |Corefile version of "showallgdbstacks"
3891 define switchtouserthread
3893 if ($kgm_mtype == $kgm_mtype_ppc)
3894 if ($kdp_act_counter == 0)
3895 set $kdpstate = (struct savearea *) kdp.saved_state
3897 set $kdp_act_counter = $kdp_act_counter + 1
3898 set $newact = (struct thread *) $arg0
3900 set $checkpc = $newact->machine->upcb.save_srr0
3902 echo This activation does not appear to have
3903 echo \20 a valid user context.\n
3905 set (struct savearea *) kdp.saved_state=$newact->machine->upcb
3907 #flush and update seem to be executed lazily by gdb on Tiger, hence the
3908 #repeated invocations - see 3743135
3910 # This works because the new pmap is used only for reads
3911 set kdp_pmap = $newact->task->map->pmap
3916 echo switchtouserthread not implemented for this architecture.\n
3920 document switchtouserthread
3921 Syntax: switchtouserthread <address of thread>
3922 | Analogous to switchtoact, but switches to the user context of a
3923 | specified thread address. Similar to the "showuserstack"
3924 | command, but this command does not return gdb to the kernel context
3925 | immediately. This is to assist with the following (rather risky)
3926 | manoeuvre - upon switching to the user context and virtual address
3927 | space, the user may choose to call remove-symbol-file on the
3928 | mach_kernel symbol file, and then add-symbol-file on the user space
3929 | binary's symfile. gdb can then generate symbolic backtraces
3930 | for the user space thread. To return to the
3931 | kernel context and virtual address space, the process must be
3932 | reversed, i.e. call remove-symbol-file on the user space symbols, and
3933 | then add-symbol-file on the appropriate mach_kernel, and issue the
3934 | "resetstacks" command. Note that gdb may not react kindly to all these
3935 | symbol file switches. The same restrictions that apply to "showuserstack"
3936 | apply here - pages that have been paged out cannot be read while in the
3937 | debugger context, so backtraces may terminate early.
3938 | If the virtual addresses in the stack trace do not conflict with those
3939 | of symbols in the kernel's address space, it may be sufficient to
3940 | just do an add-symbol-file on the user space binary's symbol file.
3941 | Note that while this command works on Panther's gdb, an issue
3942 | with Tiger gdb (3743135) appears to hamper the evaluation of this
3943 | macro in some cases.
3946 define showmetaclass
3947 set $kgm_metaclassp = (OSMetaClass *)$arg0
3948 printf "%-5d", $kgm_metaclassp->instanceCount
3949 printf "x %5d bytes", $kgm_metaclassp->classSize
3950 printf " %s\n", $kgm_metaclassp->className->string
3954 printf "\"%s\"", ((OSString *)$arg0)->string
3958 printf "%lld", ((OSNumber *)$arg0)->value
3962 if ($arg0 == gOSBooleanFalse)
3969 define showdatabytes
3970 set $kgm_data = (OSData *)$arg0
3973 set $kgm_datap = (const unsigned char *) $kgm_data->data
3975 while ( $kgm_idx < $kgm_data->length )
3976 printf "%02X", *$kgm_datap
3977 set $kgm_datap = $kgm_datap + 1
3978 set $kgm_idx = $kgm_idx + 1
3984 set $kgm_data = (OSData *)$arg0
3987 set $kgm_datap = (const unsigned char *) $kgm_data->data
3989 set $kgm_printstr = 0
3990 if (0 == (3 & (unsigned int)$kgm_datap) && ($kgm_data->length >= 3))
3991 set $kgm_bytes = *(unsigned int *) $kgm_datap
3992 if (0xffff0000 & $kgm_bytes)
3994 set $kgm_printstr = 1
3995 while ($kgm_idx++ < 4)
3996 set $kgm_bytes = $kgm_bytes >> 8
3997 set $kgm_char = 0xff & $kgm_bytes
3998 if ($kgm_char && (($kgm_char < 0x20) || ($kgm_char > 0x7e)))
3999 set $kgm_printstr = 0
4008 while ($kgm_idx < $kgm_data->length)
4009 set $kgm_char = $kgm_datap[$kgm_idx++]
4011 if (0 == $kgm_quoted)
4019 printf "%c", $kgm_char
4031 if (0 == (3 & (unsigned int)$kgm_datap))
4032 while (($kgm_idx + 3) <= $kgm_data->length)
4033 printf "%08x", *(unsigned int *) &$kgm_datap[$kgm_idx]
4034 set $kgm_idx = $kgm_idx + 4
4037 while ($kgm_idx < $kgm_data->length)
4038 printf "%02x", $kgm_datap[$kgm_idx++]
4044 define showdictionaryint
4045 set $kgm$arg0_dict = (OSDictionary *)$arg1
4048 set $kgm$arg0_idx = 0
4049 while ($kgm$arg0_idx < $kgm$arg0_dict->count)
4050 set $kgm_obj = $kgm$arg0_dict->dictionary[$kgm$arg0_idx].key
4051 showobjectint _$arg0 $kgm_obj
4053 set $kgm_obj = $kgm$arg0_dict->dictionary[$kgm$arg0_idx++].value
4054 showobjectint _$arg0 $kgm_obj
4055 if ($kgm$arg0_idx < $kgm$arg0_dict->count)
4064 while ($kgm_idx < $arg0)
4065 if ($arg1 & (1 << $kgm_idx++))
4073 define showregdictionary
4074 indent $kgm_reg_depth+2 $arg1
4077 set $kgm_reg_idx = 0
4078 while ($kgm_reg_idx < $arg0->count)
4079 indent $kgm_reg_depth+2 $arg1
4081 set $kgm_obj = $arg0->dictionary[$kgm_reg_idx].key
4082 showobjectint _ $kgm_obj
4085 set $kgm_obj = $arg0->dictionary[$kgm_reg_idx++].value
4086 showobjectint _ $kgm_obj
4089 indent $kgm_reg_depth+2 $arg1
4094 define showorderedsetarrayint
4095 set $kgm$arg0_array = (_Element *)$arg1
4096 set $kgm$arg0_count = $arg2
4098 set $kgm$arg0_idx = 0
4099 while ($kgm$arg0_idx < $kgm$arg0_count)
4100 set $kgm_obj = $kgm$arg0_array[$kgm$arg0_idx++]
4101 showobjectint _$arg0 $kgm_obj
4102 if ($kgm$arg0_idx < $kgm$arg0_count)
4108 define showorderedsetint
4109 set $kgm_array = ((OSOrderedSet *)$arg1)->array
4110 set $count = ((OSOrderedSet *)$arg1)->count
4112 showorderedsetarrayint $arg0 $kgm_array $count
4116 define showarraysetint
4117 set $kgm$arg0_array = (OSArray *)$arg1
4119 set $kgm$arg0_idx = 0
4120 while ($kgm$arg0_idx < $kgm$arg0_array->count)
4121 set $kgm_obj = $kgm$arg0_array->array[$kgm$arg0_idx++]
4122 showobjectint _$arg0 $kgm_obj
4123 if ($kgm$arg0_idx < $kgm$arg0_array->count)
4131 showarraysetint $arg0 $arg1
4136 set $kgm_array = ((OSSet *)$arg1)->members
4138 showarraysetint $arg0 $kgm_array
4143 define showobjectint
4144 set $kgm_obj = (OSObject *) $arg1
4145 set $kgm_vt = *((void **) $arg1)
4147 if ($kgm_lp64 || $kgm_mtype == $kgm_mtype_arm)
4148 set $kgm_vt = $kgm_vt - 2 * sizeof(void *)
4151 if ($kgm_show_object_addrs)
4155 output /a (unsigned long) $kgm_vt
4156 if ($kgm_show_object_retain)
4157 printf ", retain count %d, container retain %d", (0xffff & $kgm_obj->retainCount), $kgm_obj->retainCount >> 16
4162 # No multiple-inheritance
4164 if ($kgm_vt == &_ZTV8OSString)
4168 if ($kgm_vt == &_ZTV8OSSymbol)
4172 if ($kgm_vt == &_ZTV8OSNumber)
4176 if ($kgm_vt == &_ZTV6OSData)
4177 if $kgm_show_data_alwaysbytes == 1
4184 if ($kgm_vt == &_ZTV9OSBoolean)
4188 if ($kgm_vt == &_ZTV12OSDictionary)
4189 showdictionaryint _$arg0 $arg1
4192 if ($kgm_vt == &_ZTV7OSArray)
4193 showarrayint _$arg0 $arg1
4196 if ($kgm_vt == &_ZTV5OSSet)
4197 showsetint _$arg0 $arg1
4200 if ($kgm_vt == &_ZTV12OSOrderedSet)
4201 showorderedsetint _$arg0 $arg1
4205 if ($kgm_shown != 1)
4206 if ($kgm_show_object_addrs == 0)
4210 output /a (unsigned long) $kgm_vt
4217 set $kgm_save = $kgm_show_object_addrs
4218 set $kgm_show_object_addrs = 1
4219 set $kgm_show_object_retain = 1
4220 showobjectint _ $arg0
4221 set $kgm_show_object_addrs = $kgm_save
4222 set $kgm_show_object_retain = 0
4226 Syntax: (gdb) showobject <object address>
4227 | Show info about an OSObject - its vtable ptr and retain count.
4228 | If the object is a simple container class, more info will be shown.
4232 set $kgm_dictp = (OSDictionary *)$arg0
4233 set $kgm_keyp = (const OSSymbol *)$arg1
4236 while (($kgm_idx < $kgm_dictp->count) && ($kgm_result == 0))
4237 if ($kgm_keyp == $kgm_dictp->dictionary[$kgm_idx].key)
4238 set $kgm_result = $kgm_dictp->dictionary[$kgm_idx].value
4240 set $kgm_idx = $kgm_idx + 1
4245 define _registryentryrecurseinit
4246 set $kgm_re = (IOService *)$arg1
4247 set $kgm$arg0_stack = (unsigned long long) $arg2
4250 set $kgm$arg0_stack = $kgm$arg0_stack | (1ULL << $kgm_reg_depth)
4252 set $kgm$arg0_stack = $kgm$arg0_stack & ~(1ULL << $kgm_reg_depth)
4255 dictget $kgm_re->fRegistryTable $kgm_childkey
4256 set $kgm$arg0_child_array = (OSArray *) $kgm_result
4258 if ($kgm$arg0_child_array)
4259 set $kgm$arg0_child_count = $kgm$arg0_child_array->count
4261 set $kgm$arg0_child_count = 0
4264 if ($kgm$arg0_child_count)
4265 set $kgm$arg0_stack = $kgm$arg0_stack | (2ULL << $kgm_reg_depth)
4267 set $kgm$arg0_stack = $kgm$arg0_stack & ~(2ULL << $kgm_reg_depth)
4271 define findregistryentryrecurse
4272 set $kgm_registry_entry = 0
4273 _registryentryrecurseinit $arg0 $arg1 $arg2 $arg3
4275 dictget $kgm_re->fRegistryTable $kgm_namekey
4276 if ($kgm_result == 0)
4277 dictget $kgm_re->fRegistryTable gIONameKey
4279 if ($kgm_result == 0)
4280 dictget $kgm_re->fPropertyTable gIOClassKey
4283 if ($kgm_result != 0)
4284 set $str = ((OSString *) $kgm_result)->string
4285 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
4286 if $kgm_findregistry_verbose
4290 if $kgm_strcmp_result == 0
4291 if $kgm_findregistry_verbose
4292 printf "\n%s:\n | ", ((OSString *) $kgm_result)->string
4298 # don't populate $kgm_registry_entry if we want to show everything
4299 if !$kgm_findregistry_continue
4300 set $kgm_registry_entry = $kgm_re
4306 if (!$kgm_registry_entry && ($kgm$arg0_child_count != 0))
4307 set $kgm_reg_depth = $kgm_reg_depth + 1
4308 set $kgm$arg0_child_idx = 0
4310 while ($kgm$arg0_child_idx < $kgm$arg0_child_count)
4311 set $kgm_re = $kgm$arg0_child_array->array[$kgm$arg0_child_idx++]
4312 set $kgm_more_sib = ($kgm$arg0_child_idx < $kgm$arg0_child_count)
4313 if $kgm_reg_depth >= $kgm_reg_depth_max + 1
4316 findregistryentryrecurse _$arg0 $kgm_re $kgm$arg0_stack $kgm_more_sib
4317 if $kgm_registry_entry
4321 set $kgm_reg_depth = $kgm_reg_depth - 1
4325 define findregdictvalue
4326 set $kgm_registry_value = 0
4327 set $kgm_reg_idx = 0
4328 while ($kgm_reg_idx < $arg0->count)
4329 set $kgm_obj = $arg0->dictionary + $kgm_reg_idx
4330 set $str = ((OSString *)$kgm_obj->key)->string
4331 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
4333 if $kgm_strcmp_result == 0
4334 set $kgm_registry_value = $kgm_obj->value
4335 if $kgm_findregistry_verbose
4336 showobject $kgm_registry_value
4337 print $kgm_registry_value
4341 set $kgm_reg_idx = $kgm_reg_idx + 1
4345 define setfindregistrystr
4346 set $kgm_reg_find_str0 = 0
4347 set $kgm_reg_find_str1 = 0
4348 set $kgm_reg_find_str2 = 0
4349 set $kgm_reg_find_str3 = 0
4350 set $kgm_reg_find_str4 = 0
4351 set $kgm_reg_find_str5 = 0
4352 set $kgm_reg_find_str6 = 0
4353 set $kgm_reg_find_str7 = 0
4354 set $kgm_reg_find_str8 = 0
4357 set $kgm_reg_find_str0 = $arg0
4360 set $kgm_reg_find_str1 = $arg1
4363 set $kgm_reg_find_str2 = $arg2
4366 set $kgm_reg_find_str3 = $arg3
4369 set $kgm_reg_find_str4 = $arg4
4372 set $kgm_reg_find_str5 = $arg5
4375 set $kgm_reg_find_str6 = $arg6
4378 set $kgm_reg_find_str7 = $arg7
4381 set $kgm_reg_find_str8 = $arg8
4385 document setfindregistrystr
4386 Syntax: (gdb) setfindregistrystr [a] [b] [c] [d] [e] [f] [g] [h] [i]
4387 | Store an encoded string into up to 9 arguments for use by
4388 | findregistryprop or findregistryentry. The arguments are created
4389 | through calls to strcmp_arg_pack64
4392 define _findregistryprop
4393 set $reg = (IOService *) $arg0
4394 set $kgm_props = $reg->fPropertyTable
4395 set $kgm_findregistry_verbose = 0
4397 findregdictvalue $kgm_props
4400 define findregistryprop
4401 set $reg = (IOService *) $arg0
4402 set $kgm_props = $reg->fPropertyTable
4404 set $kgm_findregistry_verbose = 1
4405 findregdictvalue $kgm_props
4408 document findregistryprop
4409 Syntax: (gdb) findregistryprop <entry>
4410 | Given a registry entry, print out the contents for the property that matches
4411 | the encoded string specified via setfindregistrystr.
4413 | For example, the following will print out the "intel-pic" property stored in
4414 | the AppleACPIPlatformExpert registry entry $pe_entry:
4415 | strcmp_arg_pack64 'i' 'n' 't' 'e' 'l' '-' 'p' 'i'
4416 | set $intel_pi = $kgm_strcmp_arg
4417 | strcmp_arg_pack64 'c' 0 0 0 0 0 0 0
4418 | set $c = $kgm_strcmp_arg
4419 | setfindregistrystr $intel_pi $c
4420 | findregistryprop $pe_entry
4423 define findregistryentryint
4425 set $kgm_reg_plane = (IORegistryPlane *) gIOServicePlane
4429 printf "Please load kgmacros after KDP attaching to the target.\n"
4431 set $kgm_namekey = (OSSymbol *) $kgm_reg_plane->nameKey
4432 set $kgm_childkey = (OSSymbol *) $kgm_reg_plane->keys[1]
4433 if $kgm_findregistry_verbose
4436 findregistryentryrecurse _ $arg0 0 0
4440 define _findregistryentry
4441 set $kgm_findregistry_verbose = 0
4442 set $kgm_findregistry_continue = 0
4443 set $kgm_reg_depth = 0
4445 findregistryentryint gRegistryRoot
4448 define findregistryentry
4449 set $kgm_findregistry_verbose = 1
4450 set $kgm_findregistry_continue = 0
4451 set $kgm_reg_depth = 0
4453 findregistryentryint gRegistryRoot
4456 define findregistryentries
4457 set $kgm_findregistry_verbose = 1
4458 set $kgm_findregistry_continue = 1
4459 set $kgm_reg_depth = 0
4461 findregistryentryint gRegistryRoot
4464 document findregistryentry
4465 Syntax: (gdb) findregistryentry
4466 | Search for a registry entry that matches the encoded string specified through
4467 | setfindregistrystr. You can alter the search depth through use of
4468 | $kgm_reg_depth_max.
4470 | For example, the following will pull out the AppleACPIPlatformExpert registry
4472 | strcmp_arg_pack64 'A' 'p' 'p' 'l' 'e' 'A' 'C' 'P'
4473 | set $AppleACP = $kgm_strcmp_arg
4474 | strcmp_arg_pack64 'I' 'P' 'l' 'a' 't' 'f' 'o' 'r'
4475 | set $IPlatfor = $kgm_strcmp_arg
4476 | strcmp_arg_pack64 'm' 'E' 'x' 'p' 'e' 'r' 't' 0
4477 | set $mExpert = $kgm_strcmp_arg
4478 | setfindregistrystr $AppleACP $IPlatfor $mExpert
4482 document findregistryentries
4483 Syntax: (gdb) findregistryentries
4484 | Search for all registry entries that match the encoded string specified through
4485 | setfindregistrystr. You can alter the search depth through use of
4486 | $kgm_reg_depth_max. See findregistryentry for an example of how to encode a string.
4490 define showregistryentryrecurse
4491 _registryentryrecurseinit $arg0 $arg1 $arg2 $arg3
4493 indent $kgm_reg_depth $kgm$arg0_stack
4496 dictget $kgm_re->fRegistryTable $kgm_namekey
4497 if ($kgm_result == 0)
4498 dictget $kgm_re->fRegistryTable gIONameKey
4500 if ($kgm_result == 0)
4501 dictget $kgm_re->fPropertyTable gIOClassKey
4504 if ($kgm_result != 0)
4505 printf "%s", ((OSString *)$kgm_result)->string
4507 if (((IOService*)$kgm_re)->pwrMgt && ((IOService*)$kgm_re)->pwrMgt->Name)
4508 printf "%s", ((IOService*)$kgm_re)->pwrMgt->Name
4510 # printf ", guessclass "
4511 # guessclass $kgm_re
4519 printf ", id 0x%llx, ", $kgm_re->IORegistryEntry::reserved->fRegistryEntryID
4521 set $kgm_vt = (unsigned long) *(void**) $kgm_re
4522 if ($kgm_lp64 || $kgm_mtype == $kgm_mtype_arm)
4523 set $kgm_vt = $kgm_vt - 2 * sizeof(void *)
4527 if ($kgm_vt != &_ZTV15IORegistryEntry)
4529 set $kgm_state = $kgm_re->__state[0]
4530 # kIOServiceRegisteredState
4531 if (0 == ($kgm_state & 2))
4534 printf "registered, "
4535 # kIOServiceMatchedState
4536 if (0 == ($kgm_state & 4))
4540 # kIOServiceInactiveState
4544 printf "active, busy %d, retain count %d", (0xff & $kgm_re->__state[1]), (0xffff & $kgm_re->retainCount)
4548 if ($kgm_show_props)
4549 set $kgm_props = $kgm_re->fPropertyTable
4550 showregdictionary $kgm_props $kgm$arg0_stack
4554 if ($kgm$arg0_child_count != 0)
4556 set $kgm_reg_depth = $kgm_reg_depth + 1
4557 set $kgm$arg0_child_idx = 0
4559 while ($kgm$arg0_child_idx < $kgm$arg0_child_count)
4560 set $kgm_re = $kgm$arg0_child_array->array[$kgm$arg0_child_idx++]
4561 set $kgm_more_sib = ($kgm$arg0_child_idx < $kgm$arg0_child_count)
4562 if $kgm_reg_depth >= $kgm_reg_depth_max + 1
4565 showregistryentryrecurse _$arg0 $kgm_re $kgm$arg0_stack $kgm_more_sib
4568 set $kgm_reg_depth = $kgm_reg_depth - 1
4572 define showregistryentryint
4574 set $kgm_reg_plane = (IORegistryPlane *) gIOServicePlane
4578 printf "Please load kgmacros after KDP attaching to the target.\n"
4580 set $kgm_namekey = (OSSymbol *) $kgm_reg_plane->nameKey
4581 set $kgm_childkey = (OSSymbol *) $kgm_reg_plane->keys[1]
4582 showregistryentryrecurse _ $arg0 0 0
4587 set $kgm_reg_depth = 0
4588 set $kgm_show_props = 0
4589 showregistryentryint gRegistryRoot
4591 document showregistry
4592 Syntax: (gdb) showregistry
4593 | Show info about all registry entries in the current plane. You can specify the maximum
4594 | display depth with $kgm_reg_depth_max.
4597 define showregistryprops
4598 set $kgm_reg_depth = 0
4599 set $kgm_show_props = 1
4600 showregistryentryint gRegistryRoot
4602 document showregistryprops
4603 Syntax: (gdb) showregistryprops
4604 | Show info about all registry entries in the current plane, and their properties.
4605 | set $kgm_show_object_addrs = 1 and/or set $kgm_show_object_retain = 1 will display
4606 | more verbose information
4609 define showregistryentry
4610 set $kgm_reg_depth = 0
4611 set $kgm_show_props = 1
4612 showregistryentryint $arg0
4614 document showregistryentry
4615 Syntax: (gdb) showregistryentry <object address>
4616 | Show info about a registry entry; its properties and descendants in the current plane.
4619 define setregistryplane
4621 set $kgm_reg_plane = (IORegistryPlane *) $arg0
4623 showobjectint _ gIORegistryPlanes
4627 document setregistryplane
4628 Syntax: (gdb) setregistryplane <plane object address>
4629 | Set the plane to be used for the iokit registry macros. An argument of zero will
4630 | display known planes.
4634 set $kgm_classidx = 0
4635 set $kgm_lookvt = *((void **) $arg0)
4636 set $kgm_bestvt = (void *) 0
4637 set $kgm_bestidx = 0
4639 while $kgm_classidx < sAllClassesDict->count
4640 set $kgm_meta = (OSMetaClass *) sAllClassesDict->dictionary[$kgm_classidx].value
4642 set $kgm_vt = *((void **) $kgm_meta)
4644 if (($kgm_vt > $kgm_bestvt) && ($kgm_vt < $kgm_lookvt))
4645 set $kgm_bestvt = $kgm_vt
4646 set $kgm_bestidx = $kgm_classidx
4648 set $kgm_classidx = $kgm_classidx + 1
4650 printf "%s", sAllClassesDict->dictionary[$kgm_bestidx].key->string
4653 define showallclasses
4654 set $kgm_classidx = 0
4655 while $kgm_classidx < sAllClassesDict->count
4656 set $kgm_meta = (OSMetaClass *) sAllClassesDict->dictionary[$kgm_classidx++].value
4657 showmetaclass $kgm_meta
4661 document showallclasses
4662 Syntax: (gdb) showallclasses
4663 | Show the instance counts and ivar size of all OSObject subclasses. See ioclasscount man page for details.
4667 printf " Instance allocation = 0x%08lx = %4ld K\n", (int) debug_ivars_size, ((int) debug_ivars_size) / 1024
4668 printf "Container allocation = 0x%08lx = %4ld K\n", (int) debug_container_malloc_size, ((int) debug_container_malloc_size) / 1024
4669 printf " IOMalloc allocation = 0x%08lx = %4ld K\n", (int) debug_iomalloc_size, ((int) debug_iomalloc_size) / 1024
4670 printf " Pageable allocation = 0x%08lx = %4ld K\n", (vm_size_t) debug_iomallocpageable_size, ((vm_size_t) debug_iomallocpageable_size) / 1024
4673 document showioalloc
4674 Syntax: (gdb) showioalloc
4675 | Show some accounting of memory allocated by IOKit allocators. See ioalloccount man page for details.
4678 define showosobjecttracking
4679 set $kgm_next = (OSObjectTracking *) gOSObjectTrackList.next
4680 while $kgm_next != &gOSObjectTrackList
4681 set $obj = (OSObject *) ($kgm_next+1)
4684 while $kgm_idx < (sizeof($kgm_next->bt) / sizeof($kgm_next->bt[0]))
4685 if ((unsigned long) $kgm_next->bt[$kgm_idx] > (unsigned long) &last_kernel_symbol)
4686 showkmodaddr $kgm_next->bt[$kgm_idx]
4689 if ((unsigned long) $kgm_next->bt[$kgm_idx] > 0)
4690 output /a $kgm_next->bt[$kgm_idx]
4694 set $kgm_idx = $kgm_idx + 1
4697 set $kgm_next = (OSObjectTracking *) $kgm_next->link.next
4701 document showosobjecttracking
4702 Syntax: (gdb) showosobjecttracking
4703 | Show the list of tracked OSObject allocations with backtraces.
4704 | Boot with the kOSTraceObjectAlloc (0x00400000) io debug flag set.
4705 | Set gOSObjectTrackThread to 1 or a thread_t to capture new OSObjects allocated by a thread or all threads.
4708 # $kgm_readphys_force_kdp and $kgm_readphys_force_physmap
4709 # can respectively cause physical memory access to use
4710 # a KDP manual packet or the physical memory mapping
4711 # even if the default behavior would be otherwise.
4713 set $kgm_readphysint_result = 0xBAD10AD
4715 if ($kgm_readphys_force_kdp != 0)
4716 set $kgm_readphys_use_kdp = 1
4718 if ($kgm_readphys_force_physmap)
4719 set $kgm_readphys_use_kdp = 0
4721 set $kgm_readphys_use_kdp = ( kdp->is_conn > 0 )
4725 if ($kgm_readphys_use_kdp)
4727 # set up the manual KDP packet
4728 set manual_pkt.input = 0
4729 set manual_pkt.len = sizeof(kdp_readphysmem64_req_t)
4730 set $kgm_pkt = (kdp_readphysmem64_req_t *)&manual_pkt.data
4731 set $kgm_pkt->hdr.request = KDP_READPHYSMEM64
4732 set $kgm_pkt->hdr.len = sizeof(kdp_readphysmem64_req_t)
4733 set $kgm_pkt->hdr.is_reply = 0
4734 set $kgm_pkt->hdr.seq = 0
4735 set $kgm_pkt->hdr.key = 0
4736 set $kgm_pkt->address = (uint64_t)$arg0
4737 set $kgm_pkt->nbytes = $arg1 >> 3
4738 set $kgm_pkt->lcpu = $arg2
4739 set manual_pkt.input = 1
4740 # dummy to make sure manual packet is executed
4741 set $kgm_dummy = &_mh_execute_header
4742 set $kgm_pkt = (kdp_readphysmem64_reply_t *)&manual_pkt.data
4743 if ($kgm_pkt->error == 0)
4745 set $kgm_readphysint_result = *((uint8_t *)$kgm_pkt->data)
4748 set $kgm_readphysint_result = *((uint16_t *)$kgm_pkt->data)
4751 set $kgm_readphysint_result = *((uint32_t *)$kgm_pkt->data)
4754 set $kgm_readphysint_result = *((uint64_t *)$kgm_pkt->data)
4759 # No KDP. Attempt to use physical memory mapping
4761 if ($kgm_mtype == $kgm_mtype_x86_64)
4762 set $kgm_readphys_paddr_in_kva = (unsigned long long)$arg0 + (((unsigned long long)-1 << 47) | ((unsigned long long)509 << 39))
4764 if ($kgm_mtype == $kgm_mtype_arm)
4765 set $kgm_readphys_paddr_in_kva = (unsigned long long)$arg0 - gPhysBase + gVirtBase
4767 printf "readphys not available for current architecture.\n"
4768 set $kgm_readphys_paddr_in_kva = 0
4771 if $kgm_readphys_paddr_in_kva
4773 set $kgm_readphysint_result = *((uint8_t *)$kgm_readphys_paddr_in_kva)
4776 set $kgm_readphysint_result = *((uint16_t *)$kgm_readphys_paddr_in_kva)
4779 set $kgm_readphysint_result = *((uint32_t *)$kgm_readphys_paddr_in_kva)
4782 set $kgm_readphysint_result = *((uint64_t *)$kgm_readphys_paddr_in_kva)
4789 readphysint $arg0 8 $kgm_lcpu_self
4791 printf ":\t0x%02hhx\n", $kgm_readphysint_result
4792 set $kgm_readphys_result = (uint64_t)$kgm_readphysint_result
4796 readphysint $arg0 16 $kgm_lcpu_self
4798 printf ":\t0x%04hx\n", $kgm_readphysint_result
4799 set $kgm_readphys_result = (uint64_t)$kgm_readphysint_result
4803 readphysint $arg0 32 $kgm_lcpu_self
4805 printf ":\t0x%08x\n", $kgm_readphysint_result
4806 set $kgm_readphys_result = (uint64_t)$kgm_readphysint_result
4810 readphysint $arg0 64 $kgm_lcpu_self
4812 printf ":\t0x%016llx\n", $kgm_readphysint_result
4813 set $kgm_readphys_result = (uint64_t)$kgm_readphysint_result
4833 | The argument is interpreted as a physical address, and the 64-bit word
4834 | addressed is displayed. Saves 64-bit result in $kgm_readphys_result.
4838 # set up the manual KDP packet
4839 set manual_pkt.input = 0
4840 set manual_pkt.len = sizeof(kdp_writephysmem64_req_t)
4841 set $kgm_pkt = (kdp_writephysmem64_req_t *)&manual_pkt.data
4842 set $kgm_pkt->hdr.request = KDP_WRITEPHYSMEM64
4843 set $kgm_pkt->hdr.len = sizeof(kdp_writephysmem64_req_t)
4844 set $kgm_pkt->hdr.is_reply = 0
4845 set $kgm_pkt->hdr.seq = 0
4846 set $kgm_pkt->hdr.key = 0
4847 set $kgm_pkt->address = (uint64_t)$arg0
4848 set $kgm_pkt->nbytes = $arg1 >> 3
4849 set $kgm_pkt->lcpu = $arg3
4851 set *(uint8_t *)$kgm_pkt->data = (uint8_t)$arg2
4854 set *(uint16_t *)$kgm_pkt->data = (uint16_t)$arg2
4857 set *(uint32_t *)$kgm_pkt->data = (uint32_t)$arg2
4860 set *(uint64_t *)$kgm_pkt->data = (uint64_t)$arg2
4862 set manual_pkt.input = 1
4863 # dummy to make sure manual packet is executed
4864 set $kgm_dummy = &_mh_execute_header
4865 set $kgm_pkt = (kdp_writephysmem64_reply_t *)&manual_pkt.data
4866 set $kgm_writephysint_result = $kgm_pkt->error
4870 writephysint $arg0 8 $arg1 $kgm_lcpu_self
4874 writephysint $arg0 16 $arg1 $kgm_lcpu_self
4878 writephysint $arg0 32 $arg1 $kgm_lcpu_self
4882 writephysint $arg0 64 $arg1 $kgm_lcpu_self
4889 document writephys16
4893 document writephys32
4897 document writephys64
4898 | The argument is interpreted as a physical address, and the second argument is
4899 | written to that address as a 64-bit word.
4903 shell echo cd `pwd` > /tmp/gdb-cd
4907 set $kgm_show_kmod_syms = 1
4910 document addkextsyms
4911 | Takes a directory of symbols for kexts generated with kextcache -y and loads them
4913 | (gdb) addkextsyms /path/to/symboldir
4916 define showprocfiles
4919 _showprocfiles $arg0
4921 printf "| Usage:\n|\n"
4925 document showprocfiles
4926 Syntax: (gdb) showprocfiles <proc_t>
4927 | Given a proc_t pointer, display the list of open file descriptors for the
4928 | referenced process.
4931 define _showprocheader
4932 printf "fd fileglob "
4934 printf " fg flags fg type fg data "
4937 printf "----- ----------"
4941 printf " ---------- -------- ----------"
4945 printf " -------------------\n"
4948 define _showprocfiles
4949 set $kgm_spf_filedesc = ((proc_t)$arg0)->p_fd
4950 set $kgm_spf_last = $kgm_spf_filedesc->fd_lastfile
4951 set $kgm_spf_ofiles = $kgm_spf_filedesc->fd_ofiles
4952 set $kgm_spf_count = 0
4953 while ($kgm_spf_count <= $kgm_spf_last)
4954 if ($kgm_spf_ofiles[$kgm_spf_count] == 0)
4955 # DEBUG: For files that were open, but are now closed
4956 # printf "%-5d FILEPROC_NULL\n", $kgm_spf_count
4958 # display fd #, fileglob address, fileglob flags
4959 set $kgm_spf_flags = $kgm_spf_ofiles[$kgm_spf_count].f_flags
4960 set $kgm_spf_fg = $kgm_spf_ofiles[$kgm_spf_count].f_fglob
4961 printf "%-5d ", $kgm_spf_count
4963 printf " 0x%08x ", $kgm_spf_flags
4964 # decode fileglob type
4965 set $kgm_spf_fgt = $kgm_spf_fg->fg_type
4966 if ($kgm_spf_fgt == 1)
4969 if ($kgm_spf_fgt == 2)
4972 if ($kgm_spf_fgt == 3)
4975 if ($kgm_spf_fgt == 4)
4978 if ($kgm_spf_fgt == 5)
4981 if ($kgm_spf_fgt == 6)
4984 if ($kgm_spf_fgt == 7)
4987 if ($kgm_spf_fgt < 1 || $kgm_spf_fgt > 7)
4988 printf "?: %-5d", $kgm_spf_fgt
4991 # display fileglob data address and decode interesting fact(s)
4992 # about data, if we know any
4993 set $kgm_spf_fgd = $kgm_spf_fg->fg_data
4995 showptr $kgm_spf_fgd
4997 if ($kgm_spf_fgt == 1)
4998 set $kgm_spf_name = ((struct vnode *)$kgm_spf_fgd)->v_name
4999 if ($kgm_spf_name == 0)
5002 printf "%s", $kgm_spf_name
5007 set $kgm_spf_count = $kgm_spf_count + 1
5012 # Show all the advisory file locks held by a process for each of the vnode
5013 # type files that it has open; do this by walking the per process open file
5014 # table and looking at any vnode type fileglob that has a non-NULL lock list
5015 # associated with it.
5017 define showproclocks
5019 _showproclocks $arg0
5021 printf "| Usage:\n|\n"
5025 document showproclocks
5026 Syntax: (gdb) showproclocks <proc_t>
5027 | Given a proc_t pointer, display the list of advisory file locks held by the
5028 | referenced process.
5031 define _showproclocks
5032 set $kgm_spl_filedesc = ((proc_t)$arg0)->p_fd
5033 set $kgm_spl_last = $kgm_spl_filedesc->fd_lastfile
5034 set $kgm_spl_ofiles = $kgm_spl_filedesc->fd_ofiles
5035 set $kgm_spl_count = 0
5036 set $kgm_spl_seen = 0
5037 while ($kgm_spl_count <= $kgm_spl_last)
5038 if ($kgm_spl_ofiles[$kgm_spl_count] == 0)
5039 # DEBUG: For files that were open, but are now closed
5040 # printf "%-5d FILEPROC_NULL\n", $kgm_spl_count
5042 set $kgm_spl_fg = $kgm_spl_ofiles[$kgm_spl_count].f_fglob
5043 # decode fileglob type
5044 set $kgm_spl_fgt = $kgm_spl_fg->fg_type
5045 if ($kgm_spl_fgt == 1)
5046 set $kgm_spl_fgd = $kgm_spl_fg->fg_data
5047 set $kgm_spl_name = ((struct vnode *)$kgm_spl_fgd)->v_name
5048 set $kgm_spl_vnode = ((vnode_t)$kgm_spl_fgd)
5049 set $kgm_spl_lockiter = $kgm_spl_vnode->v_lockf
5050 if ($kgm_spl_lockiter != 0)
5051 if ($kgm_spl_seen == 0)
5052 _showvnodelockheader
5054 set $kgm_spl_seen = $kgm_spl_seen + 1
5055 printf "( fd %d, name ", $kgm_spl_count
5056 if ($kgm_spl_name == 0)
5059 printf "%s )\n", $kgm_spl_name
5061 _showvnodelocks $kgm_spl_fgd
5065 set $kgm_spl_count = $kgm_spf_count + 1
5067 printf "%d total locks for ", $kgm_spl_seen
5073 set $kgm_spi_proc = (proc_t)$arg0
5075 showptr $kgm_spi_proc
5077 printf " name %s\n", $kgm_spi_proc->p_comm
5078 printf " pid:%.8d", $kgm_spi_proc->p_pid
5080 showptr $kgm_spi_proc->task
5081 printf " p_stat:%.1d", $kgm_spi_proc->p_stat
5082 printf " parent pid:%.8d", $kgm_spi_proc->p_ppid
5084 # decode part of credential
5085 set $kgm_spi_cred = $kgm_spi_proc->p_ucred
5086 if ($kgm_spi_cred != 0)
5087 printf "Cred: euid %d ruid %d svuid %d\n", $kgm_spi_cred->cr_posix.cr_uid, $kgm_spi_cred->cr_posix.cr_ruid, $kgm_spi_cred->cr_posix.cr_svuid
5089 printf "Cred: (null)\n"
5092 set $kgm_spi_flag = $kgm_spi_proc->p_flag
5093 printf "Flags: 0x%08x\n", $kgm_spi_flag
5094 if ($kgm_spi_flag & 0x00000001)
5095 printf " 0x00000001 - may hold advisory locks\n"
5097 if ($kgm_spi_flag & 0x00000002)
5098 printf " 0x00000002 - has a controlling tty\n"
5100 if ($kgm_spi_flag & 0x00000004)
5101 printf " 0x00000004 - process is 64 bit\n"
5103 printf " !0x00000004 - process is 32 bit\n"
5105 if ($kgm_spi_flag & 0x00000008)
5106 printf " 0x00000008 - no SIGCHLD on child stop\n"
5108 if ($kgm_spi_flag & 0x00000010)
5109 printf " 0x00000010 - waiting for child exec/exit\n"
5111 if ($kgm_spi_flag & 0x00000020)
5112 printf " 0x00000020 - has started profiling\n"
5114 if ($kgm_spi_flag & 0x00000040)
5115 printf " 0x00000040 - in select; wakeup/waiting danger\n"
5117 if ($kgm_spi_flag & 0x00000080)
5118 printf " 0x00000080 - was stopped and continued\n"
5120 if ($kgm_spi_flag & 0x00000100)
5121 printf " 0x00000100 - has set privileges since exec\n"
5123 if ($kgm_spi_flag & 0x00000200)
5124 printf " 0x00000200 - system process: no signals, stats, or swap\n"
5126 if ($kgm_spi_flag & 0x00000400)
5127 printf " 0x00000400 - timing out during a sleep\n"
5129 if ($kgm_spi_flag & 0x00000800)
5130 printf " 0x00000800 - debugged process being traced\n"
5132 if ($kgm_spi_flag & 0x00001000)
5133 printf " 0x00001000 - debugging process has waited for child\n"
5135 if ($kgm_spi_flag & 0x00002000)
5136 printf " 0x00002000 - exit in progress\n"
5138 if ($kgm_spi_flag & 0x00004000)
5139 printf " 0x00004000 - process has called exec\n"
5141 if ($kgm_spi_flag & 0x00008000)
5142 printf " 0x00008000 - owe process an addupc() XXX\n"
5144 if ($kgm_spi_flag & 0x00010000)
5145 printf " 0x00010000 - affinity for Rosetta children\n"
5147 if ($kgm_spi_flag & 0x00020000)
5148 printf " 0x00020000 - wants to run Rosetta\n"
5150 if ($kgm_spi_flag & 0x00040000)
5151 printf " 0x00040000 - has wait() in progress\n"
5153 if ($kgm_spi_flag & 0x00080000)
5154 printf " 0x00080000 - kdebug tracing on for this process\n"
5156 if ($kgm_spi_flag & 0x00100000)
5157 printf " 0x00100000 - blocked due to SIGTTOU or SIGTTIN\n"
5159 if ($kgm_spi_flag & 0x00200000)
5160 printf " 0x00200000 - has called reboot()\n"
5162 if ($kgm_spi_flag & 0x00400000)
5163 printf " 0x00400000 - is TBE state\n"
5165 if ($kgm_spi_flag & 0x00800000)
5166 printf " 0x00800000 - signal exceptions\n"
5168 if ($kgm_spi_flag & 0x01000000)
5169 printf " 0x01000000 - has thread cwd\n"
5171 if ($kgm_spi_flag & 0x02000000)
5172 printf " 0x02000000 - has vfork() children\n"
5174 if ($kgm_spi_flag & 0x04000000)
5175 printf " 0x04000000 - not allowed to attach\n"
5177 if ($kgm_spi_flag & 0x08000000)
5178 printf " 0x08000000 - vfork() in progress\n"
5180 if ($kgm_spi_flag & 0x10000000)
5181 printf " 0x10000000 - no shared libraries\n"
5183 if ($kgm_spi_flag & 0x20000000)
5184 printf " 0x20000000 - force quota for root\n"
5186 if ($kgm_spi_flag & 0x40000000)
5187 printf " 0x40000000 - no zombies when children exit\n"
5189 if ($kgm_spi_flag & 0x80000000)
5190 printf " 0x80000000 - don't hang on remote FS ops\n"
5193 set $kgm_spi_state = $kgm_spi_proc->p_stat
5195 if ($kgm_spi_state == 1)
5198 if ($kgm_spi_state == 2)
5201 if ($kgm_spi_state == 3)
5204 if ($kgm_spi_state == 4)
5207 if ($kgm_spi_state == 5)
5210 if ($kgm_spi_state == 6)
5213 if ($kgm_spi_state < 1 || $kgm_spi_state > 6)
5214 printf "(Unknown)\n"
5218 document showprocinfo
5219 Syntax: (gdb) showprocinfo <proc_t>
5220 | Displays name, pid, parent and task for a proc_t. Decodes cred, flag and p_stat fields.
5224 # dump the zombprocs
5227 set $basep = (struct proc *)zombproc->lh_first
5231 set $pp = $pp->p_list.le_next
5236 Syntax: (gdb) zombproc
5237 | Routine to print out all procs in the zombie list
5241 # dump the zombstacks
5244 set $basep = (struct proc *)zombproc->lh_first
5248 showtaskstacks $pp->task
5250 set $pp = $pp->p_list.le_next
5255 Syntax: (gdb) zombstacks
5256 | Routine to print out all stacks of tasks that are exiting
5264 set $basep = (struct proc *)allproc->lh_first
5268 set $pp = $pp->p_list.le_next
5273 Syntax: (gdb) allproc
5274 | Routine to print out all process in the system
5275 | which are not in the zombie list
5277 define showprocsiblingint
5278 set $kgm_sibling_ptr = (struct proc *)$arg0
5282 set $kgm_lx = $kgm_lx-3
5284 printf "|--%d %s [ 0x%llx ]\n", $kgm_sibling_ptr->p_pid, $kgm_sibling_ptr->p_comm, $kgm_sibling_ptr
5286 define showproctreeint
5287 #Initialize all the set variables used in this macro
5289 set $kgm_sibling_ptr = 0
5291 set $kgm_tmp_base = 0
5292 set $kgm_head_ptr = 0
5293 set $kgm_search_pid = 0
5297 set $kgm_basep1 = (struct proc *)allproc->lh_first
5299 set $kgm_head_ptr = (struct proc *)initproc
5302 set $kgm_tmp_base = (struct proc *)allproc->lh_first
5303 set $kgm_search_pid = $arg0
5305 if ( $kgm_tmp_base->p_pid == $kgm_search_pid)
5306 if ($kgm_tmp_base->p_childrencnt > 0)
5307 set $kgm_head_ptr = $kgm_tmp_base->p_children.lh_first
5309 set $kgm_head_ptr = 0
5310 printf "No children present for PID=%d", $kgm_search_pid
5314 set $kgm_tmp_base = $kgm_tmp_base->p_list.le_next
5320 printf "PID PROCESS POINTER]\n"
5321 printf "=== ======= =======\n"
5322 printf "%d %s [ 0x%llx ]\n", $kgm_head_ptr->p_ppid, $kgm_head_ptr->p_pptr->p_comm, $kgm_head_ptr
5323 printf "|--%d %s [ 0x%llx ]\n", $kgm_head_ptr->p_pid, $kgm_head_ptr->p_comm, $kgm_head_ptr
5325 while ($kgm_head_ptr)
5326 #Is childrencnt = 0? YES {=> no children}
5327 if ($kgm_head_ptr->p_childrencnt == 0)
5328 # Does it have sibling?
5329 if($kgm_head_ptr->p_sibling.le_next == 0)
5330 #No, it does not have sibling, so go back to its parent which will go to its sibling
5331 if($kgm_head_ptr == $kgm_head_ptr->p_pptr)
5334 set $kgm_head_ptr = $kgm_head_ptr->p_pptr
5335 if ($kgm_head_ptr == $kgm_tmp_base)
5339 set $kgm_x = $kgm_x - 3
5343 if($kgm_head_ptr->p_sibling.le_next != 0)
5344 # Yes, it has sibling. So print sibling
5346 showprocsiblingint $kgm_head_ptr->p_sibling.le_next $kgm_x
5347 set $kgm_head_ptr = $kgm_head_ptr->p_sibling.le_next
5349 # childrencnt != 0 {=> it has children}
5352 if($kgm_head_ptr->p_sibling.le_next == 0)
5353 #No, it does not have sibling, so go back to its parent which will go to its sibling
5354 if($kgm_head_ptr == $kgm_head_ptr->p_pptr)
5357 set $kgm_head_ptr = $kgm_head_ptr->p_pptr
5358 if ($kgm_head_ptr == $kgm_tmp_base)
5363 set $kgm_x = $kgm_x - 3
5367 if($kgm_head_ptr->p_sibling.le_next != 0)
5369 # Yes, it has sibling. So print sibling
5370 showprocsiblingint $kgm_head_ptr->p_sibling.le_next $kgm_x
5371 set $kgm_head_ptr = $kgm_head_ptr->p_sibling.le_next
5374 set $kgm_head_ptr = $kgm_head_ptr->p_children.lh_first
5375 set $kgm_x = $kgm_x + 3
5376 set $kgm_lx = $kgm_x
5379 set $kgm_lx = $kgm_lx-3
5381 printf "|--%d %s [ 0x%llx ] \n", $kgm_head_ptr->p_pid, $kgm_head_ptr->p_comm, $kgm_head_ptr
5386 #Unset all the set variables used in this macro
5388 set $kgm_sibling_ptr = 0
5390 set $kgm_tmp_base = 0
5391 set $kgm_head_ptr = 0
5392 set $kgm_search_pid = 0
5398 showproctreeint $arg0
5403 document showproctree
5404 Syntax: (gdb) showproctree <pid>
5405 | Routine to print the processes in the system in a hierarchical tree form. This routine does not print zombie processes.
5406 | If no argument is given, showproctree will print all the processes in the system.
5407 | If pid is specified, showproctree prints all the descendants of the indicated process
5412 set $vp = (struct vnode *)$arg0
5416 printf " use %d", $vp->v_usecount
5417 printf " io %d", $vp->v_iocount
5418 printf " kuse %d", $vp->v_kusecount
5419 printf " type %d", $vp->v_type
5420 printf " flg 0x%.8x", $vp->v_flag
5421 printf " lflg 0x%.8x", $vp->v_lflag
5423 showptr $vp->v_parent
5424 set $_name = (char *)$vp->v_name
5426 printf " %s", $_name
5428 if ($vp->v_type == VREG) && ($vp->v_un.vu_ubcinfo != 0)
5429 printf " mapped %d", ($vp->v_un.vu_ubcinfo.ui_flags & 0x08) ? 1 : 0
5434 document print_vnode
5435 Syntax: (gdb) print_vnode <vnode>
5436 | Prints out the fields of a vnode struct
5439 define showprocvnodes
5440 set $pp = (struct proc *)$arg0
5441 set $fdp = (struct filedesc *)$pp->p_fd
5442 set $cvp = $fdp->fd_cdir
5443 set $rvp = $fdp->fd_rdir
5445 printf "Current Working Directory \n"
5450 printf "Current Root Directory \n"
5455 set $fpp = (struct fileproc **)($fdp->fd_ofiles)
5456 set $fpo = (char)($fdp->fd_ofileflags[0])
5457 while $count < $fdp->fd_nfiles
5458 #printf"fpp %x ", *$fpp
5460 set $fg =(struct fileglob *)((**$fpp)->f_fglob)
5461 if $fg && (($fg)->fg_type == 1)
5462 if $fdp->fd_ofileflags[$count] & 4
5467 printf "fd = %d ", $count
5468 print_vnode $fg->fg_data
5472 set $count = $count + 1
5476 document showprocvnodes
5477 Syntax: (gdb) showprocvnodes <proc_address>
5478 | Routine to print out all the open fds
5479 | which are vnodes in a process
5482 define showallprocvnodes
5483 set $basep = (struct proc *)allproc->lh_first
5486 printf "============================================ \n"
5489 set $pp = $pp->p_list.le_next
5493 document showallprocvnodes
5494 Syntax: (gdb) showallprocvnodes
5495 | Routine to print out all the open fds
5501 # dump the childrent of a proc
5503 define showinitchild
5504 set $basep = (struct proc *)initproc->p_children.lh_first
5508 set $pp = $pp->p_sibling.le_next
5512 document showinitchild
5513 Syntax: (gdb) showinitchild
5514 | Routine to print out all processes in the system
5515 | which are children of init process
5519 define showmountallvnodes
5520 set $mp = (struct mount *)$arg0
5521 set $basevp = (struct vnode *)$mp->mnt_vnodelist.tqh_first
5523 printf "____________________ Vnode list Queue ---------------\n"
5526 set $vp = $vp->v_mntvnodes->tqe_next
5528 set $basevp = (struct vnode *)$mp->mnt_workerqueue.tqh_first
5530 printf "____________________ Worker Queue ---------------\n"
5533 set $vp = $vp->v_mntvnodes->tqe_next
5535 set $basevp = (struct vnode *)$mp->mnt_newvnodes.tqh_first
5537 printf "____________________ New vnodes Queue ---------------\n"
5540 set $vp = $vp->v_mntvnodes->tqe_next
5543 document showmountallvnodes
5544 Syntax: showmountallvnodes <struct mount *>
5545 | Print the vnode inactive list
5549 define showmountvnodes
5550 set $mp = (struct mount *)$arg0
5551 set $basevp = (struct vnode *)$mp->mnt_vnodelist.tqh_first
5553 printf "____________________ Vnode list Queue ---------------\n"
5556 set $vp = $vp->v_mntvnodes->tqe_next
5559 document showmountvnodes
5560 Syntax: showmountvnodes <struct mount *>
5561 | Print the vnode list
5566 define showworkqvnodes
5567 set $mp = (struct mount *)$arg0
5568 set $basevp = (struct vnode *)$mp->mnt_workerqueue.tqh_first
5570 printf "____________________ Worker Queue ---------------\n"
5573 set $vp = $vp->v_mntvnodes->tqe_next
5576 document showworkqvnodes
5577 Syntax: showworkqvnodes <struct mount *>
5578 | Print the vnode worker list
5582 define shownewvnodes
5583 set $mp = (struct mount *)$arg0
5584 set $basevp = (struct vnode *)$mp->mnt_newvnodes.tqh_first
5586 printf "____________________ New vnodes Queue ---------------\n"
5589 set $vp = $vp->v_mntvnodes->tqe_next
5593 document shownewvnodes
5594 Syntax: shownewvnodes <struct mount *>
5595 | Print the new vnode list
5600 # print mount point info
5602 set $mp = (struct mount *)$arg0
5606 printf " flag %x", $mp->mnt_flag
5607 printf " kern_flag %x", $mp->mnt_kern_flag
5608 printf " lflag %x", $mp->mnt_lflag
5609 printf " type: %s", $mp->mnt_vfsstat.f_fstypename
5610 printf " mnton: %s", $mp->mnt_vfsstat.f_mntonname
5611 printf " mntfrom: %s", $mp->mnt_vfsstat.f_mntfromname
5615 define showallmounts
5616 set $mp=(struct mount *)mountlist.tqh_first
5619 set $mp = $mp->mnt_list.tqe_next
5623 document showallmounts
5624 Syntax: showallmounts
5625 | Print all mount points
5629 if (((unsigned long) $arg0 < (unsigned long) &_mh_execute_header || \
5630 (unsigned long) $arg0 >= (unsigned long) &last_kernel_symbol ))
5638 set $mp = (struct mbuf *)$arg0
5642 printf "%4d: %p [len %4d, type %2d, ", $cnt, $mp, \
5643 $mp->m_hdr.mh_len, $mp->m_hdr.mh_type
5648 set $tot = $tot + $mp->m_hdr.mh_len
5649 printf "total %d]\n", $tot
5650 set $mp = $mp->m_hdr.mh_nextpkt
5655 document mbuf_walkpkt
5656 Syntax: (gdb) mbuf_walkpkt <addr>
5657 | Given an mbuf address, walk its m_nextpkt pointer
5661 set $mp = (struct mbuf *)$arg0
5665 printf "%4d: %p [len %4d, type %2d, ", $cnt, $mp, \
5666 $mp->m_hdr.mh_len, $mp->m_hdr.mh_type
5671 set $tot = $tot + $mp->m_hdr.mh_len
5672 printf "total %d]\n", $tot
5673 set $mp = $mp->m_hdr.mh_next
5679 Syntax: (gdb) mbuf_walk <addr>
5680 | Given an mbuf address, walk its m_next pointer
5683 define mbuf_buf2slab
5685 set $gix = ((char *)$addr - (char *)mbutl) >> 20
5686 set $ix = ((char *)$addr - (char *)slabstbl[$gix].slg_slab[0].sl_base) >> 12
5687 set $slab = &slabstbl[$gix].slg_slab[$ix]
5689 printf "0x%-16llx", $slab
5691 printf "0x%-8x", $slab
5695 document mbuf_buf2slab
5696 | Given an mbuf object, find its corresponding slab address.
5701 set $ix = ((char *)$addr - (char *)mbutl) >> 12
5702 set $clbase = ((union mbigcluster *)mbutl) + $ix
5703 set $mclidx = (((char *)$addr - (char *)$clbase) >> 8)
5704 set $mca = mclaudit[$ix].cl_audit[$mclidx]
5706 printf "mca: 0x%-16llx", $mca
5708 printf "mca: 0x%-8x", $mca
5712 document mbuf_buf2mca
5713 Syntax: (gdb) mbuf_buf2mca <addr>
5714 | Given an mbuf object, find its buffer audit structure address.
5715 | This requires mbuf buffer auditing to be turned on, by setting
5716 | the appropriate flags to the "mbuf_debug" boot-args parameter.
5721 set $mca = (mcache_audit_t *)$arg0
5722 set $cp = (mcache_t *)$mca->mca_cache
5723 printf "object type:\t\t"
5724 mbuf_mca_ctype $mca 1
5725 printf "\ncontrolling mcache:\t%p (%s)\n", $mca->mca_cache, $cp->mc_name
5726 if $mca->mca_uflags & $MB_SCVALID
5727 set $ix = ((char *)$mca->mca_addr - (char *)mbutl) >> 12
5728 set $clbase = ((union mbigcluster *)mbutl) + $ix
5729 set $mclidx = (((char *)$mca->mca_addr - (char *)$clbase) >> 8)
5730 printf "mbuf obj:\t\t%p\n", $mca->mca_addr
5731 printf "mbuf index:\t\t%d (out of 16) in cluster base %p\n", \
5732 $mclidx + 1, $clbase
5733 if $mca->mca_uptr != 0
5734 set $peer_mca = (mcache_audit_t *)$mca->mca_uptr
5735 printf "paired cluster obj:\t%p (mca %p)\n", \
5736 $peer_mca->mca_addr, $peer_mca
5738 printf "saved contents:\t\t%p (%d bytes)\n", \
5739 $mca->mca_contents, $mca->mca_contents_size
5741 printf "cluster obj:\t\t%p\n", $mca->mca_addr
5742 if $mca->mca_uptr != 0
5743 set $peer_mca = (mcache_audit_t *)$mca->mca_uptr
5744 printf "paired mbuf obj:\t%p (mca %p)\n", \
5745 $peer_mca->mca_addr, $peer_mca
5748 printf "recent transaction for this buffer (thread %p):\n", \
5751 while $cnt < $mca->mca_depth
5752 set $kgm_pc = $mca->mca_stack[$cnt]
5753 printf "%4d: ", $cnt + 1
5758 if $mca->mca_pdepth > 0
5759 printf "previous transaction for this buffer (thread %p):\n", \
5763 while $cnt < $mca->mca_pdepth
5764 set $kgm_pc = $mca->mca_pstack[$cnt]
5765 printf "%4d: ", $cnt + 1
5773 document mbuf_showmca
5774 Syntax: (gdb) mbuf_showmca <addr>
5775 | Given an mbuf/cluster buffer audit structure address, print the audit
5776 | records including the stack trace of the last buffer transaction.
5787 while $topcnt < $maxcnt
5788 mbuf_traceleak mleak_top_trace[$topcnt]
5789 set $topcnt = $topcnt + 1
5794 document mbuf_topleak
5795 Syntax: (gdb) mbuf_topleak <num>
5796 | Prints information about the top <num> suspected mbuf leakers
5797 | where <num> is a value <= 5
5800 define mbuf_traceleak
5802 set $trace = (struct mtrace *) $arg0
5803 if $trace->allocs != 0
5804 printf "%p:%d outstanding allocs\n", $trace, $trace->allocs
5805 printf "backtrace saved %d deep:\n", $trace->depth
5806 if $trace->depth != 0
5808 while $cnt < $trace->depth
5809 printf "%4d: ", $cnt + 1
5810 pcprint $trace->addr[$cnt]
5819 document mbuf_traceleak
5820 Syntax: (gdb) mbuf_traceleak <addr>
5821 | Given an mbuf leak trace (mtrace) structure address, print out the
5822 | stored information with that trace
5825 set $MCF_NOCPUCACHE = 0x10
5828 set $head = (mcache_t *)mcache_head
5832 printf "cache cache cache buf buf backing (# of retries) bufs\n"
5833 printf "name state addr size align zone wait nowait failed incache\n"
5834 printf "------------------------- -------- ------------------ ------ ----- ------------------ -------------------------- --------\n"
5836 printf "cache cache cache buf buf backing (# of retries) bufs\n"
5837 printf "name state addr size align zone wait nowait failed incache\n"
5838 printf "------------------------- -------- ---------- ------ ----- ---------- -------------------------- --------\n"
5841 set $bktsize = $mc->mc_cpu.cc_bktsize
5842 printf "%-25s ", $mc->mc_name
5843 if ($mc->mc_flags & $MCF_NOCPUCACHE)
5846 if $mc->mc_purge_cnt > 0
5856 printf " %p %6d %5d ",$mc, \
5857 $mc->mc_bufsize, $mc->mc_align
5858 if $mc->mc_slab_zone != 0
5859 printf "%p", $mc->mc_slab_zone
5868 set $tot += $mc->mc_full.bl_total * $bktsize
5869 set $ccp = (mcache_cpu_t *)$mc->mc_cpu
5872 if $ccp->cc_objs > 0
5873 set $tot += $ccp->cc_objs
5875 if $ccp->cc_pobjs > 0
5876 set $tot += $ccp->cc_pobjs
5881 printf " %8d %8d %8d %8d", $mc->mc_wretry_cnt, \
5882 $mc->mc_nwretry_cnt, $mc->mc_nwfail_cnt, $tot
5884 set $mc = (mcache_t *)$mc->mc_list.le_next
5888 document mcache_stat
5889 Syntax: (gdb) mcache_stat
5890 | Print all mcaches in the system.
5893 define mcache_showzone
5894 set $mc = (mcache_t *)$arg0
5895 if $mc->mc_slab_zone != 0
5896 printf "%p", $mc->mc_slab_zone
5901 document mcache_showzone
5902 Syntax: (gdb) mcache_showzone <mcache_addr>
5903 | Print the type of backend (custom or zone) of a mcache.
5906 define mcache_walkobj
5907 set $p = (mcache_obj_t *)$arg0
5911 printf "%4d: %p\n", $cnt, $p,
5912 set $p = $p->obj_next
5917 document mcache_walkobj
5918 Syntax: (gdb) mcache_walkobj <addr>
5919 | Given a mcache object address, walk its obj_next pointer
5922 define mcache_showcache
5923 set $cp = (mcache_t *)$arg0
5924 set $ccp = (mcache_cpu_t *)$cp->mc_cpu
5925 set $bktsize = $cp->mc_cpu.cc_bktsize
5928 printf "Showing cache '%s':\n\n", $cp->mc_name
5929 printf " CPU cc_objs cc_pobjs total\n"
5930 printf "---- -------- -------- --------\n"
5932 set $objs = $ccp->cc_objs
5936 set $pobjs = $ccp->cc_pobjs
5940 set $tot_cpu = $objs + $pobjs
5941 set $tot += $tot_cpu
5942 printf "%4d %8d %8d %8d\n", $cnt, $objs, $pobjs, $tot_cpu
5946 printf " ========\n"
5947 printf " %8d\n", $tot
5949 set $tot += $cp->mc_full.bl_total * $bktsize
5950 printf "Total # of full buckets (%d objs/bkt):\t%-8d\n", \
5951 $bktsize, $cp->mc_full.bl_total
5952 printf "Total # of objects cached:\t\t%-8d\n", $tot
5955 document mcache_showcache
5956 | Display the number of objects in the cache
5959 set $NSLABSPMB = sizeof(mcl_slabg_t)/sizeof(mcl_slab_t)
5961 define mbuf_slabstbl
5965 printf "slot slabg slabs range\n"
5966 printf "---- ------------------ -------------------------------------------\n"
5968 printf "slot slabg slabs range\n"
5969 printf "---- ---------- ---------------------------\n"
5971 while $x < maxslabgrp
5972 set $slg = slabstbl[$x]
5978 printf "0x%-16llx [ 0x%-16llx - 0x%-16llx ]\n", $slg, &$slg->slg_slab[0], \
5979 &$slg->slg_slab[$NSLABSPMB-1]
5981 printf "0x%-8x [ 0x%-8x - 0x%-8x ]\n", $slg, &$slg->slg_slab[0], \
5982 &$slg->slg_slab[$NSLABSPMB-1]
5989 document mbuf_slabstbl
5990 | Display the mbuf slabs table
5993 set $SLF_MAPPED=0x0001
5994 set $SLF_PARTIAL=0x0002
5995 set $SLF_DETACHED=0x0004
5998 set $slg = (mcl_slabg_t *)$arg0
6002 printf "slot slab next obj mca C R N size flags\n"
6003 printf "---- ------------------ ------------------ ------------------ ------------------ -- -- -- ------ -----\n"
6005 printf "slot slab next obj mca C R N size flags\n"
6006 printf "---- ---------- ---------- ---------- ---------- -- -- -- ------ -----\n"
6008 while $x < $NSLABSPMB
6009 set $sl = &$slg->slg_slab[$x]
6011 set $obj = $sl->sl_base
6014 set $ix = ((char *)$obj - (char *)mbutl) >> 12
6015 set $clbase = ((union mbigcluster *)mbutl) + $ix
6016 set $mclidx = (((char *)$obj - (char *)$clbase) >> 8)
6017 set $mca = mclaudit[$ix].cl_audit[$mclidx]
6021 printf "%3d: 0x%-16llx 0x%-16llx 0x%-16llx 0x%-16llx %2d %2d %2d %6d 0x%04x ", \
6022 $x + 1, $sl, $sl->sl_next, $obj, $mca, $sl->sl_class, \
6023 $sl->sl_refcnt, $sl->sl_chunks, $sl->sl_len, \
6026 printf "%3d: 0x%-8x 0x%-8x 0x%-8x 0x%-8x %2d %2d %2d %6d 0x%04x ", \
6027 $x + 1, $sl, $sl->sl_next, $obj, $mca, $sl->sl_class, \
6028 $sl->sl_refcnt, $sl->sl_chunks, $sl->sl_len, \
6031 if $sl->sl_flags != 0
6033 if $sl->sl_flags & $SLF_MAPPED
6036 if $sl->sl_flags & $SLF_PARTIAL
6039 if $sl->sl_flags & $SLF_DETACHED
6046 if $sl->sl_chunks > 1
6048 set $c = $sl->sl_len / $sl->sl_chunks
6050 while $z < $sl->sl_chunks
6051 set $obj = $sl->sl_base + ($c * $z)
6055 set $ix = ((char *)$obj - (char *)mbutl) >> 12
6056 set $clbase = ((union mbigcluster *)mbutl) + $ix
6057 set $mclidx = (((char *)$obj - (char *)$clbase) >> 8)
6058 set $mca = mclaudit[$ix].cl_audit[$mclidx]
6062 printf " 0x%-16llx 0x%-16llx\n", $obj, $mca
6064 printf " 0x%-8x 0x%-8x\n", $obj, $mca
6075 | Display all mbuf slabs in the group
6081 printf "class total cached uncached inuse failed waiter notified purge\n"
6082 printf "name objs objs objs / slabs objs alloc count count count count\n"
6083 printf "---------------- -------- -------- ------------------- -------- ---------------- -------- -------- --------\n"
6084 while $x < (sizeof(mbuf_table) / sizeof(mbuf_table[0]))
6085 set $mbt = mbuf_table[$x]
6086 set $mcs = (mb_class_stat_t *)mbuf_table[$x].mtbl_stats
6088 set $mc = $mbt->mtbl_cache
6089 set $bktsize = $mc->mc_cpu.cc_bktsize
6090 set $tot += $mc->mc_full.bl_total * $bktsize
6091 set $ccp = (mcache_cpu_t *)$mc->mc_cpu
6094 if $ccp->cc_objs > 0
6095 set $tot += $ccp->cc_objs
6097 if $ccp->cc_pobjs > 0
6098 set $tot += $ccp->cc_pobjs
6104 printf "%-16s %8d %8d %8d / %-8d %8d %16llu %8d %8llu %8llu", \
6105 $mcs->mbcl_cname, $mcs->mbcl_total, $tot, \
6106 $mcs->mbcl_infree, $mcs->mbcl_slab_cnt, \
6107 ($mcs->mbcl_total - $tot - $mcs->mbcl_infree), \
6108 $mcs->mbcl_fail_cnt, $mc->mc_waiter_cnt, \
6109 $mcs->mbcl_notified, $mcs->mbcl_purge_cnt
6116 | Print extended mbuf allocator statistics.
6120 set $MB_COMP_INUSE = 0x2
6121 set $MB_SCVALID = 0x4
6123 set $MCLBYTES = 2048
6126 set $M16KCLBYTES = 16384
6128 define mbuf_mca_ctype
6129 set $mca = (mcache_audit_t *)$arg0
6131 set $cp = $mca->mca_cache
6132 set $class = (unsigned int)$cp->mc_private
6133 set $csize = mbuf_table[$class].mtbl_stats->mbcl_size
6143 if !$done && $csize == $MCLBYTES
6145 printf "CL (2K cluster) "
6151 if !$done && $csize == $NBPG
6153 printf "BCL (4K cluster) "
6159 if !$done && $csize == $M16KCLBYTES
6161 printf "JCL (16K cluster) "
6167 if !$done && $csize == ($MSIZE+$MCLBYTES)
6168 if $mca->mca_uflags & $MB_SCVALID
6172 printf "(paired mbuf, 2K cluster)"
6177 printf "(unpaired mbuf, 2K cluster) "
6184 printf "(paired 2K cluster, mbuf) "
6189 printf "(paired 2K cluster, mbuf) "
6195 if !$done && $csize == ($MSIZE+$NBPG)
6196 if $mca->mca_uflags & $MB_SCVALID
6200 printf "(paired mbuf, 4K cluster) "
6205 printf "(unpaired mbuf, 4K cluster) "
6212 printf "(paired 4K cluster, mbuf) "
6217 printf "(unpaired 4K cluster, mbuf) "
6223 if !$done && $csize == ($MSIZE+$M16KCLBYTES)
6224 if $mca->mca_uflags & $MB_SCVALID
6228 printf "(paired mbuf, 16K cluster) "
6233 printf "(unpaired mbuf, 16K cluster) "
6240 printf "(paired 16K cluster, mbuf) "
6245 printf "(unpaired 16K cluster, mbuf) "
6252 printf "unknown: %s ", $cp->mc_name
6256 document mbuf_mca_ctype
6257 | This is a helper macro for mbuf_show{active,inactive,all} that prints
6258 | out the mbuf object type represented by a given mcache audit structure.
6261 define mbuf_showactive
6263 mbuf_walkallslabs 1 0
6265 mbuf_walkallslabs 1 0 $arg0
6269 document mbuf_showactive
6270 Syntax: (gdb) mbuf_showactive
6271 | Walk the mbuf objects pool and print only the active ones; this
6272 | requires mbuf debugging to be turned on, by setting the appropriate flags
6273 | to the "mbuf_debug" boot-args parameter. Active objects are those that
6274 | are outstanding (have not returned to the mbuf slab layer) and in use
6275 | by the client (have not been freed).
6278 define mbuf_showinactive
6279 mbuf_walkallslabs 0 1
6282 document mbuf_showinactive
6283 Syntax: (gdb) mbuf_showinactive
6284 | Walk the mbuf objects pool and print only the inactive ones; this
6285 | requires mbuf debugging to be turned on, by setting the appropriate flags
6286 | to the "mbuf_debug" boot-args parameter. Inactive objects are those that
6287 | are outstanding (have not returned to the mbuf slab layer) but have been
6288 | freed by the client, i.e. they still reside in the mcache layer ready to
6289 | be used for subsequent allocation requests.
6293 mbuf_walkallslabs 1 1
6296 document mbuf_showall
6297 Syntax: (gdb) mbuf_showall
6298 | Walk the mbuf objects pool and print them all; this requires
6299 | mbuf debugging to be turned on, by setting the appropriate flags to the
6300 | "mbuf_debug" boot-args parameter.
6306 define mbuf_walkallslabs
6310 set $show_tr = $arg2
6320 if $show_a && !$show_f
6321 printf "Searching only for active "
6323 if !$show_a && $show_f
6324 printf "Searching only for inactive "
6326 if $show_a && $show_f
6327 printf "Displaying all "
6329 printf "objects; this may take a while ...)\n\n"
6332 printf " slab mca obj allocation\n"
6333 printf "slot idx address address address type state\n"
6334 printf "---- ---- ------------------ ------------------ ------------------ ----- -----------\n"
6336 printf " slab mca obj allocation\n"
6337 printf "slot idx address address address type state\n"
6338 printf "---- ---- ---------- ---------- ---------- ----- -----------\n"
6342 set $slg = slabstbl[$x]
6345 while $y < $NSLABSPMB && $stop == 0
6346 set $sl = &$slg->slg_slab[$y]
6347 set $base = (char *)$sl->sl_base
6348 set $ix = ($base - (char *)mbutl) >> 12
6349 set $clbase = ((union mbigcluster *)mbutl) + $ix
6350 set $mclidx = ($base - (char *)$clbase) >> 8
6351 set $mca = mclaudit[$ix].cl_audit[$mclidx]
6354 while $mca != 0 && $mca->mca_addr != 0
6356 if $mca->mca_uflags & ($MB_INUSE|$MB_COMP_INUSE)
6357 set $total_a = $total_a + 1
6358 set $printmca = $show_a
6360 set $total_f = $total_f + 1
6361 set $printmca = $show_f
6367 printf "%4d %4d 0x%-16llx ", $x, $y, $sl
6369 printf "%4d %4d 0x%-8x ", $x, $y, $sl
6380 printf "0x%-16llx 0x%-16llx ", $mca, $mca->mca_addr
6382 printf "0x%-8x 0x%-8x ", $mca, $mca->mca_addr
6385 mbuf_mca_ctype $mca 0
6386 if $mca->mca_uflags & ($MB_INUSE|$MB_COMP_INUSE)
6395 set $total = $total + 1
6398 printf "recent transaction for this buffer (thread %p):\n", \
6401 while $cnt < $mca->mca_depth
6402 set $kgm_pc = $mca->mca_stack[$cnt]
6403 printf "%4d: ", $cnt + 1
6411 set $mca = $mca->mca_next
6414 if $slg->slg_slab[$y].sl_base == 0
6420 if $total && $show_a && $show_f
6421 printf "\ntotal objects:\t%d\n", $total
6422 printf "active/unfreed:\t%d\n", $total_a
6423 printf "freed/in_cache:\t%d\n", $total_f
6427 document mbuf_walkallslabs
6428 | Walk the mbuf objects pool; this requires mbuf debugging to be
6429 | turned on, by setting the appropriate flags to the "mbuf_debug" boot-args
6430 | parameter. This is a backend routine for mbuf_show{active,inactive,all}.
6433 define mbuf_countchain
6434 set $mp = (struct mbuf *)$arg0
6442 set $mn = (struct mbuf *)$mp->m_hdr.mh_next
6446 set $mn = (struct mbuf *)$mn->m_hdr.mh_next
6449 set $mp = $mp->m_hdr.mh_nextpkt
6451 if (($pkt + $nxt) % 50) == 0
6452 printf "... %d\n", $pkt + $nxt
6456 printf "\ntotal: %d (via m_next: %d)\n", $pkt + $nxt, $nxt
6459 document mbuf_countchain
6460 Syntax: mbuf_countchain <addr>
6461 | Count the total number of mbufs chained from the given the address of an mbuf.
6462 | The routine follows both the m_next pointers and m_nextpkt pointers.
6466 set $RTF_GATEWAY = 0x2
6468 set $RTF_REJECT = 0x8
6469 set $RTF_DYNAMIC = 0x10
6470 set $RTF_MODIFIED = 0x20
6471 set $RTF_DONE = 0x40
6472 set $RTF_DELCLONE = 0x80
6473 set $RTF_CLONING = 0x100
6474 set $RTF_XRESOLVE = 0x200
6475 set $RTF_LLINFO = 0x400
6476 set $RTF_STATIC = 0x800
6477 set $RTF_BLACKHOLE = 0x1000
6478 set $RTF_PROTO2 = 0x4000
6479 set $RTF_PROTO1 = 0x8000
6480 set $RTF_PRCLONING = 0x10000
6481 set $RTF_WASCLONED = 0x20000
6482 set $RTF_PROTO3 = 0x40000
6483 set $RTF_PINNED = 0x100000
6484 set $RTF_LOCAL = 0x200000
6485 set $RTF_BROADCAST = 0x400000
6486 set $RTF_MULTICAST = 0x800000
6487 set $RTF_IFSCOPE = 0x1000000
6488 set $RTF_CONDEMNED = 0x2000000
6494 define rtentry_prdetails
6495 set $rt = (struct rtentry *)$arg0
6498 set $dst = (struct sockaddr *)$rt->rt_nodes->rn_u.rn_leaf.rn_Key
6499 if $dst->sa_family == $AF_INET
6500 showsockaddr_in $dst
6503 if $dst->sa_family == $AF_INET6
6504 showsockaddr_in6 $dst
6508 if $dst->sa_family == $AF_LINK
6509 showsockaddr_dl $dst
6512 showsockaddr_unspec $dst
6517 set $dst = (struct sockaddr *)$rt->rt_gateway
6518 if $dst->sa_family == $AF_INET
6519 showsockaddr_in $dst
6522 if $dst->sa_family == $AF_INET6
6524 showsockaddr_in6 $dst
6527 if $dst->sa_family == $AF_LINK
6528 showsockaddr_dl $dst
6535 showsockaddr_unspec $dst
6540 if $rt->rt_flags & $RTF_WASCLONED
6542 printf "%18p ", $rt->rt_parent
6544 printf "%10p ", $rt->rt_parent
6554 printf "%6u %8u ", $rt->rt_refcnt, $rt->rt_rmx.rmx_pksent
6556 if $rt->rt_flags & $RTF_UP
6559 if $rt->rt_flags & $RTF_GATEWAY
6562 if $rt->rt_flags & $RTF_HOST
6565 if $rt->rt_flags & $RTF_REJECT
6568 if $rt->rt_flags & $RTF_DYNAMIC
6571 if $rt->rt_flags & $RTF_MODIFIED
6574 if $rt->rt_flags & $RTF_CLONING
6577 if $rt->rt_flags & $RTF_PRCLONING
6580 if $rt->rt_flags & $RTF_LLINFO
6583 if $rt->rt_flags & $RTF_STATIC
6586 if $rt->rt_flags & $RTF_PROTO1
6589 if $rt->rt_flags & $RTF_PROTO2
6592 if $rt->rt_flags & $RTF_PROTO3
6595 if $rt->rt_flags & $RTF_WASCLONED
6598 if $rt->rt_flags & $RTF_BROADCAST
6601 if $rt->rt_flags & $RTF_MULTICAST
6604 if $rt->rt_flags & $RTF_XRESOLVE
6607 if $rt->rt_flags & $RTF_BLACKHOLE
6610 if $rt->rt_flags & $RTF_IFSCOPE
6614 printf "/%s%d", $rt->rt_ifp->if_name, $rt->rt_ifp->if_unit
6619 define _rttable_dump
6621 set $rn = (struct radix_node *)$rnh->rnh_treetop
6622 set $rnh_cnt = $rnh->rnh_cnt
6624 while $rn->rn_bit >= 0
6625 set $rn = $rn->rn_u.rn_node.rn_L
6629 set $base = (struct radix_node *)$rn
6630 while ($rn->rn_parent->rn_u.rn_node.rn_R == $rn) && ($rn->rn_flags & $RNF_ROOT) == 0
6631 set $rn = $rn->rn_parent
6633 set $rn = $rn->rn_parent->rn_u.rn_node.rn_R
6634 while $rn->rn_bit >= 0
6635 set $rn = $rn->rn_u.rn_node.rn_L
6640 set $base = $rn->rn_u.rn_leaf.rn_Dupedkey
6641 if ($rn->rn_flags & $RNF_ROOT) == 0
6643 set $rt = (struct rtentry *)$rn
6650 rtentry_prdetails $rt
6656 if ($rn->rn_flags & $RNF_ROOT) != 0
6665 printf " rtentry dst gw parent Refs Use flags/if\n"
6666 printf " ----------------- --------------- ----------------- ------------------ ------ -------- -----------\n"
6668 printf " rtentry dst gw parent Refs Use flags/if\n"
6669 printf " --------- --------------- ----------------- ---------- ------ -------- -----------\n"
6671 _rttable_dump rt_tables[2]
6674 document show_rt_inet
6675 Syntax: (gdb) show_rt_inet
6676 | Show the entries of the IPv4 routing table.
6679 define show_rt_inet6
6681 printf " rtentry dst gw parent Refs Use flags/if\n"
6682 printf " ----------------- --------------------------------------- --------------------------------------- ------------------ ------ -------- -----------\n"
6684 printf " rtentry dst gw parent Refs Use flags/if\n"
6685 printf " --------- --------------------------------------- --------------------------------------- ---------- ------ -------- -----------\n"
6687 _rttable_dump rt_tables[30]
6690 document show_rt_inet6
6691 Syntax: (gdb) show_rt_inet6
6692 | Show the entries of the IPv6 routing table.
6695 define rtentry_trash
6696 set $rtd = (struct rtentry_dbg *)rttrash_head.tqh_first
6701 printf " rtentry ref hold rele dst gw parent flags/if\n"
6702 printf " ----------------- --- ------ ------ --------------- ----- ------------------ -----------\n"
6704 printf " rtentry ref hold rele dst gw parent flags/if\n"
6705 printf " --------- --- ------ ------ --------------- ----- ---------- -----------\n"
6708 printf "%4d: %p %3d %6d %6d ", $cnt + 1, $rtd, \
6709 $rtd->rtd_refhold_cnt - $rtd->rtd_refrele_cnt, \
6710 $rtd->rtd_refhold_cnt, $rtd->rtd_refrele_cnt
6711 rtentry_prdetails $rtd
6713 set $rtd = $rtd->rtd_trash_link.tqe_next
6718 document rtentry_trash
6719 Syntax: (gdb) rtentry_trash
6720 | Walk the list of trash route entries; this requires route entry
6721 | debugging to be turned on, by setting the appropriate flags to the
6722 | "rte_debug" boot-args parameter.
6725 set $CTRACE_STACK_SIZE = ctrace_stack_size
6726 set $CTRACE_HIST_SIZE = ctrace_hist_size
6728 define rtentry_showdbg
6729 set $rtd = (struct rtentry_dbg *)$arg0
6732 printf "Total holds:\t%d\n", $rtd->rtd_refhold_cnt
6733 printf "Total releases:\t%d\n", $rtd->rtd_refrele_cnt
6736 while $ix < $CTRACE_STACK_SIZE
6737 set $kgm_pc = $rtd->rtd_alloc.pc[$ix]
6740 printf "\nAlloc (thread %p):\n", \
6743 printf "%4d: ", $ix + 1
6750 while $ix < $CTRACE_STACK_SIZE
6751 set $kgm_pc = $rtd->rtd_free.pc[$ix]
6754 printf "\nFree: (thread %p)\n", \
6757 printf "%4d: ", $ix + 1
6763 while $cnt < $CTRACE_HIST_SIZE
6765 while $ix < $CTRACE_STACK_SIZE
6766 set $kgm_pc = $rtd->rtd_refhold[$cnt].pc[$ix]
6769 printf "\nHold [%d] (thread %p):\n", \
6770 $cnt, $rtd->rtd_refhold[$cnt].th
6772 printf "%4d: ", $ix + 1
6781 while $cnt < $CTRACE_HIST_SIZE
6783 while $ix < $CTRACE_STACK_SIZE
6784 set $kgm_pc = $rtd->rtd_refrele[$cnt].pc[$ix]
6787 printf "\nRelease [%d] (thread %p):\n",\
6788 $cnt, $rtd->rtd_refrele[$cnt].th
6790 printf "%4d: ", $ix + 1
6799 printf "\nTotal locks:\t%d\n", $rtd->rtd_lock_cnt
6800 printf "Total unlocks:\t%d\n", $rtd->rtd_unlock_cnt
6803 while $cnt < $CTRACE_HIST_SIZE
6805 while $ix < $CTRACE_STACK_SIZE
6806 set $kgm_pc = $rtd->rtd_lock[$cnt].pc[$ix]
6809 printf "\nLock [%d] (thread %p):\n",\
6810 $cnt, $rtd->rtd_lock[$cnt].th
6812 printf "%4d: ", $ix + 1
6821 while $cnt < $CTRACE_HIST_SIZE
6823 while $ix < $CTRACE_STACK_SIZE
6824 set $kgm_pc = $rtd->rtd_unlock[$cnt].pc[$ix]
6827 printf "\nUnlock [%d] (thread %p):\n",\
6828 $cnt, $rtd->rtd_unlock[$cnt].th
6830 printf "%4d: ", $ix + 1
6840 document rtentry_showdbg
6841 Syntax: (gdb) rtentry_showdbg <addr>
6842 | Given a route entry structure address, print the debug information
6843 | related to it. This requires route entry debugging to be turned
6844 | on, by setting the appropriate flags to the "rte_debug" boot-args
6848 set $INIFA_TRACE_HIST_SIZE = inifa_trace_hist_size
6850 define inifa_showdbg
6851 set $inifa = (struct in_ifaddr_dbg *)$arg0
6854 printf "Total holds:\t%d\n", $inifa->inifa_refhold_cnt
6855 printf "Total releases:\t%d\n", $inifa->inifa_refrele_cnt
6858 while $ix < $CTRACE_STACK_SIZE
6859 set $kgm_pc = $inifa->inifa_alloc.pc[$ix]
6862 printf "\nAlloc (thread %p):\n", \
6863 $inifa->inifa_alloc.th
6865 printf "%4d: ", $ix + 1
6872 while $ix < $CTRACE_STACK_SIZE
6873 set $kgm_pc = $inifa->inifa_free.pc[$ix]
6876 printf "\nFree: (thread %p)\n", \
6877 $inifa->inifa_free.th
6879 printf "%4d: ", $ix + 1
6885 while $cnt < $INIFA_TRACE_HIST_SIZE
6887 while $ix < $CTRACE_STACK_SIZE
6888 set $kgm_pc = $inifa->inifa_refhold[$cnt].pc[$ix]
6891 printf "\nHold [%d] (thread %p):\n", \
6892 $cnt, $inifa->inifa_refhold[$cnt].th
6894 printf "%4d: ", $ix + 1
6903 while $cnt < $INIFA_TRACE_HIST_SIZE
6905 while $ix < $CTRACE_STACK_SIZE
6906 set $kgm_pc = $inifa->inifa_refrele[$cnt].pc[$ix]
6909 printf "\nRelease [%d] (thread %p):\n",\
6910 $cnt, $inifa->inifa_refrele[$cnt].th
6912 printf "%4d: ", $ix + 1
6922 document inifa_showdbg
6923 Syntax: (gdb) inifa_showdbg <addr>
6924 | Given an IPv4 interface structure address, print the debug information
6925 | related to it. This requires interface address debugging to be turned
6926 | on, by setting the appropriate flags to the "ifa_debug" boot-args
6930 set $IN6IFA_TRACE_HIST_SIZE = in6ifa_trace_hist_size
6932 define in6ifa_showdbg
6933 set $in6ifa = (struct in6_ifaddr_dbg *)$arg0
6936 printf "Total holds:\t%d\n", $in6ifa->in6ifa_refhold_cnt
6937 printf "Total releases:\t%d\n", $in6ifa->in6ifa_refrele_cnt
6940 while $ix < $CTRACE_STACK_SIZE
6941 set $kgm_pc = $in6ifa->in6ifa_alloc.pc[$ix]
6944 printf "\nAlloc (thread %p):\n", \
6945 $in6ifa->in6ifa_alloc.th
6947 printf "%4d: ", $ix + 1
6954 while $ix < $CTRACE_STACK_SIZE
6955 set $kgm_pc = $in6ifa->in6ifa_free.pc[$ix]
6958 printf "\nFree: (thread %p)\n", \
6959 $in6ifa->in6ifa_free.th
6961 printf "%4d: ", $ix + 1
6967 while $cnt < $IN6IFA_TRACE_HIST_SIZE
6969 while $ix < $CTRACE_STACK_SIZE
6970 set $kgm_pc = $in6ifa->in6ifa_refhold[$cnt].pc[$ix]
6973 printf "\nHold [%d] (thread %p):\n", \
6974 $cnt, $in6ifa->in6ifa_refhold[$cnt].th
6976 printf "%4d: ", $ix + 1
6985 while $cnt < $IN6IFA_TRACE_HIST_SIZE
6987 while $ix < $CTRACE_STACK_SIZE
6988 set $kgm_pc = $in6ifa->in6ifa_refrele[$cnt].pc[$ix]
6991 printf "\nRelease [%d] (thread %p):\n",\
6992 $cnt, $in6ifa->in6ifa_refrele[$cnt].th
6994 printf "%4d: ", $ix + 1
7004 document in6ifa_showdbg
7005 Syntax: (gdb) in6ifa_showdbg <addr>
7006 | Given an IPv6 interface structure address, print the debug information
7007 | related to it. This requires interface address debugging to be turned
7008 | on, by setting the appropriate flags to the "ifa_debug" boot-args
7012 set $IFMA_TRACE_HIST_SIZE = ifma_trace_hist_size
7015 set $ifma = (struct ifmultiaddr_dbg *)$arg0
7018 printf "Total holds:\t%d\n", $ifma->ifma_refhold_cnt
7019 printf "Total releases:\t%d\n", $ifma->ifma_refrele_cnt
7021 while $cnt < $IFMA_TRACE_HIST_SIZE
7023 while $ix < $CTRACE_STACK_SIZE
7024 set $kgm_pc = $ifma->ifma_refhold[$cnt].pc[$ix]
7027 printf "\nHold [%d] (thread %p):\n", \
7028 $cnt, $ifma->ifma_refhold[$cnt].th
7030 printf "%4d: ", $ix + 1
7039 while $cnt < $IFMA_TRACE_HIST_SIZE
7041 while $ix < $CTRACE_STACK_SIZE
7042 set $kgm_pc = $ifma->ifma_refrele[$cnt].pc[$ix]
7045 printf "\nRelease [%d] (thread %p):\n",\
7046 $cnt, $ifma->ifma_refrele[$cnt].th
7048 printf "%4d: ", $ix + 1
7058 document ifma_showdbg
7059 Syntax: (gdb) ifma_showdbg <addr>
7060 | Given a link multicast structure address, print the debug information
7061 | related to it. This requires interface address debugging to be turned
7062 | on, by setting the appropriate flags to the "ifa_debug" boot-args
7066 set $INM_TRACE_HIST_SIZE = inm_trace_hist_size
7069 set $inm = (struct in_multi_dbg *)$arg0
7072 printf "Total holds:\t%d\n", $inm->inm_refhold_cnt
7073 printf "Total releases:\t%d\n", $inm->inm_refrele_cnt
7075 while $cnt < $INM_TRACE_HIST_SIZE
7077 while $ix < $CTRACE_STACK_SIZE
7078 set $kgm_pc = $inm->inm_refhold[$cnt].pc[$ix]
7081 printf "\nHold [%d] (thread %p):\n", \
7082 $cnt, $inm->inm_refhold[$cnt].th
7084 printf "%4d: ", $ix + 1
7093 while $cnt < $INM_TRACE_HIST_SIZE
7095 while $ix < $CTRACE_STACK_SIZE
7096 set $kgm_pc = $inm->inm_refrele[$cnt].pc[$ix]
7099 printf "\nRelease [%d] (thread %p):\n",\
7100 $cnt, $inm->inm_refrele[$cnt].th
7102 printf "%4d: ", $ix + 1
7112 document inm_showdbg
7113 Syntax: (gdb) inm_showdbg <addr>
7114 | Given an IPv4 multicast structure address, print the debug information
7115 | related to it. This requires interface address debugging to be turned
7116 | on, by setting the appropriate flags to the "ifa_debug" boot-args
7120 set $IF_REF_TRACE_HIST_SIZE = if_ref_trace_hist_size
7122 define ifpref_showdbg
7123 set $dl_if = (struct dlil_ifnet_dbg *)$arg0
7126 printf "Total references:\t%d\n", $dl_if->dldbg_if_refhold_cnt
7127 printf "Total releases:\t\t%d\n", $dl_if->dldbg_if_refrele_cnt
7129 while $cnt < $IF_REF_TRACE_HIST_SIZE
7131 while $ix < $CTRACE_STACK_SIZE
7132 set $kgm_pc = $dl_if->dldbg_if_refhold[$cnt].pc[$ix]
7135 printf "\nHold [%d] (thread %p):\n", \
7137 $dl_if->dldbg_if_refhold[$cnt].th
7139 printf "%4d: ", $ix + 1
7148 while $cnt < $IF_REF_TRACE_HIST_SIZE
7150 while $ix < $CTRACE_STACK_SIZE
7151 set $kgm_pc = $dl_if->dldbg_if_refrele[$cnt].pc[$ix]
7154 printf "\nRelease [%d] (thread %p):\n",\
7156 $dl_if->dldbg_if_refrele[$cnt].th
7158 printf "%4d: ", $ix + 1
7168 document ifpref_showdbg
7169 Syntax: (gdb) ifpref_showdbg <addr>
7170 | Given an ifnet structure address, print the debug information
7171 | related to its refcnt. This requires ifnet debugging to be turned
7172 | on, by setting the appropriate flags to the "ifnet_debug" boot-args
7177 set $ifa = (struct in6_ifaddr_dbg *)in6ifa_trash_head.tqh_first
7182 printf " in6_ifa ref hold rele\n"
7183 printf " ----------------- --- ------ ------\n"
7185 printf " in6_ifa ref hold rele\n"
7186 printf " --------- --- ------ ------\n"
7189 printf "%4d: %p %3d %6d %6d ", $cnt + 1, $ifa, \
7190 $ifa->in6ifa_refhold_cnt - $ifa->in6ifa_refrele_cnt, \
7191 $ifa->in6ifa_refhold_cnt, $ifa->in6ifa_refrele_cnt
7192 showsockaddr_in6 $ifa->in6ifa.ia_ifa.ifa_addr
7194 set $ifa = $ifa->in6ifa_trash_link.tqe_next
7199 set $NDPR_TRACE_HIST_SIZE = ndpr_trace_hist_size
7202 set $ndpr = (struct nd_prefix_dbg *)$arg0
7205 printf "Total references:\t%d\n", $ndpr->ndpr_refhold_cnt
7206 printf "Total releases:\t\t%d\n", $ndpr->ndpr_refrele_cnt
7208 while $cnt < $NDPR_TRACE_HIST_SIZE
7210 while $ix < $CTRACE_STACK_SIZE
7211 set $kgm_pc = $ndpr->ndpr_refhold[$cnt].pc[$ix]
7214 printf "\nHold [%d] (thread %p):\n", \
7216 $ndpr->ndpr_refhold[$cnt].th
7218 printf "%4d: ", $ix + 1
7227 while $cnt < $NDPR_TRACE_HIST_SIZE
7229 while $ix < $CTRACE_STACK_SIZE
7230 set $kgm_pc = $ndpr->ndpr_refrele[$cnt].pc[$ix]
7233 printf "\nRelease [%d] (thread %p):\n",\
7235 $ndpr->ndpr_refrele[$cnt].th
7237 printf "%4d: ", $ix + 1
7247 document ndpr_showdbg
7248 Syntax: (gdb) ndpr_showdbg <addr>
7249 | Given a nd_prefix structure address, print the debug information
7250 | related to its refcnt. This requires the interface address debugging
7251 | to be turned on, by setting the appropriate flags to the "ifa_debug"
7252 | boot-args parameter.
7255 set $NDDR_TRACE_HIST_SIZE = nddr_trace_hist_size
7258 set $nddr = (struct nd_defrouter_dbg *)$arg0
7261 printf "Total references:\t%d\n", $nddr->nddr_refhold_cnt
7262 printf "Total releases:\t\t%d\n", $nddr->nddr_refrele_cnt
7264 while $cnt < $NDDR_TRACE_HIST_SIZE
7266 while $ix < $CTRACE_STACK_SIZE
7267 set $kgm_pc = $nddr->nddr_refhold[$cnt].pc[$ix]
7270 printf "\nHold [%d] (thread %p):\n", \
7272 $nddr->nddr_refhold[$cnt].th
7274 printf "%4d: ", $ix + 1
7283 while $cnt < $NDDR_TRACE_HIST_SIZE
7285 while $ix < $CTRACE_STACK_SIZE
7286 set $kgm_pc = $nddr->nddr_refrele[$cnt].pc[$ix]
7289 printf "\nRelease [%d] (thread %p):\n",\
7291 $nddr->nddr_refrele[$cnt].th
7293 printf "%4d: ", $ix + 1
7303 document nddr_showdbg
7304 Syntax: (gdb) nddr_showdbg <addr>
7305 | Given a nd_defrouter structure address, print the debug information
7306 | related to its refcnt. This requires the interface address debugging
7307 | to be turned on, by setting the appropriate flags to the "ifa_debug"
7308 | boot-args parameter.
7310 set $IMO_TRACE_HIST_SIZE = imo_trace_hist_size
7313 set $imo = (struct ip_moptions_dbg *)$arg0
7316 printf "Total references:\t%d\n", $imo->imo_refhold_cnt
7317 printf "Total releases:\t\t%d\n", $imo->imo_refrele_cnt
7319 while $cnt < $IMO_TRACE_HIST_SIZE
7321 while $ix < $CTRACE_STACK_SIZE
7322 set $kgm_pc = $imo->imo_refhold[$cnt].pc[$ix]
7325 printf "\nHold [%d] (thread %p):\n", \
7327 $imo->imo_refhold[$cnt].th
7329 printf "%4d: ", $ix + 1
7338 while $cnt < $IMO_TRACE_HIST_SIZE
7340 while $ix < $CTRACE_STACK_SIZE
7341 set $kgm_pc = $imo->imo_refrele[$cnt].pc[$ix]
7344 printf "\nRelease [%d] (thread %p):\n",\
7346 $imo->imo_refrele[$cnt].th
7348 printf "%4d: ", $ix + 1
7358 document imo_showdbg
7359 Syntax: (gdb) imo_showdbg <addr>
7360 | Given a ip_moptions structure address, print the debug information
7361 | related to its refcnt. This requires the interface address debugging
7362 | to be turned on, by setting the appropriate flags to the "ifa_debug"
7363 | boot-args parameter.
7366 set $IM6O_TRACE_HIST_SIZE = im6o_trace_hist_size
7369 set $im6o = (struct ip6_moptions_dbg *)$arg0
7372 printf "Total references:\t%d\n", $im6o->im6o_refhold_cnt
7373 printf "Total releases:\t\t%d\n", $im6o->im6o_refrele_cnt
7375 while $cnt < $IM6O_TRACE_HIST_SIZE
7377 while $ix < $CTRACE_STACK_SIZE
7378 set $kgm_pc = $im6o->im6o_refhold[$cnt].pc[$ix]
7381 printf "\nHold [%d] (thread %p):\n", \
7383 $im6o->im6o_refhold[$cnt].th
7385 printf "%4d: ", $ix + 1
7394 while $cnt < $IM6O_TRACE_HIST_SIZE
7396 while $ix < $CTRACE_STACK_SIZE
7397 set $kgm_pc = $im6o->im6o_refrele[$cnt].pc[$ix]
7400 printf "\nRelease [%d] (thread %p):\n",\
7402 $im6o->im6o_refrele[$cnt].th
7404 printf "%4d: ", $ix + 1
7414 document im6o_showdbg
7415 Syntax: (gdb) im6o_showdbg <addr>
7416 | Given a ip6_moptions structure address, print the debug information
7417 | related to its refcnt. This requires the interface address debugging
7418 | to be turned on, by setting the appropriate flags to the "ifa_debug"
7419 | boot-args parameter.
7422 document in6ifa_trash
7423 Syntax: (gdb) in6ifa_trash
7424 | Walk the list of trash in6_ifaddr entries; this requires interface
7425 | address debugging to be turned on, by setting the appropriate flags
7426 | to the "ifa_debug" boot-args parameter.
7430 set $ifa = (struct in_ifaddr_dbg *)inifa_trash_head.tqh_first
7435 printf " in_ifa ref hold rele\n"
7436 printf " ----------------- --- ------ ------\n"
7438 printf " in_ifa ref hold rele\n"
7439 printf " --------- --- ------ ------\n"
7442 printf "%4d: %p %3d %6d %6d ", $cnt + 1, $ifa, \
7443 $ifa->inifa_refhold_cnt - $ifa->inifa_refrele_cnt, \
7444 $ifa->inifa_refhold_cnt, $ifa->inifa_refrele_cnt
7445 showsockaddr_in $ifa->inifa.ia_ifa.ifa_addr
7447 set $ifa = $ifa->inifa_trash_link.tqe_next
7452 document inifa_trash
7453 Syntax: (gdb) inifa_trash
7454 | Walk the list of trash in_ifaddr entries; this requires interface
7455 | address debugging to be turned on, by setting the appropriate flags
7456 | to the "ifa_debug" boot-args parameter.
7460 set $ifma = (struct ifmultiaddr_dbg *)ifma_trash_head.tqh_first
7465 printf " ifma ref hold rele\n"
7466 printf " ----------------- --- ------ ------\n"
7468 printf " ifma ref hold rele\n"
7469 printf " --------- --- ------ ------\n"
7472 printf "%4d: %p %3d %6d %6d ", $cnt + 1, $ifma, \
7473 $ifma->ifma_refhold_cnt - $ifma->ifma_refrele_cnt, \
7474 $ifma->ifma_refhold_cnt, $ifma->ifma_refrele_cnt
7475 showsockaddr $ifma->ifma.ifma_addr
7476 printf " @ %s%d", $ifma->ifma.ifma_ifp->if_name, \
7477 $ifma->ifma.ifma_ifp->if_unit
7479 set $ifma = $ifma->ifma_trash_link.tqe_next
7485 Syntax: (gdb) ifma_trash
7486 | Walk the list of trash ifmultiaddr entries; this requires interface
7487 | address debugging to be turned on, by setting the appropriate flags
7488 | to the "ifa_debug" boot-args parameter.
7492 set $inm = (struct in_multi_dbg *)inm_trash_head.tqh_first
7497 printf " inm ref hold rele\n"
7498 printf " ----------------- --- ------ ------\n"
7500 printf " inm ref hold rele\n"
7501 printf " --------- --- ------ ------\n"
7504 printf "%4d: %p %3d %6d %6d ", $cnt + 1, $inm, \
7505 $inm->inm_refhold_cnt - $inm->inm_refrele_cnt, \
7506 $inm->inm_refhold_cnt, $inm->inm_refrele_cnt
7507 show_in_addr &($inm->inm.inm_addr)
7509 set $inm = $inm->inm_trash_link.tqe_next
7515 Syntax: (gdb) inm_trash
7516 | Walk the list of trash in_multi entries; this requires interface
7517 | address debugging to be turned on, by setting the appropriate flags
7518 | to the "ifa_debug" boot-args parameter.
7522 set $in6m = (struct in6_multi_dbg *)in6m_trash_head.tqh_first
7527 printf " in6m ref hold rele\n"
7528 printf " ----------------- --- ------ ------\n"
7530 printf " in6m ref hold rele\n"
7531 printf " --------- --- ------ ------\n"
7534 printf "%4d: %p %3d %6d %6d ", $cnt + 1, $in6m, \
7535 $in6m->in6m_refhold_cnt - $in6m->in6m_refrele_cnt, \
7536 $in6m->in6m_refhold_cnt, $in6m->in6m_refrele_cnt
7537 show_in_addr &($in6m->in6m.in6m_addr)
7539 set $in6m = $in6m->in6m_trash_link.tqe_next
7545 Syntax: (gdb) in6m_trash
7546 | Walk the list of trash in6_multi entries; this requires interface
7547 | address debugging to be turned on, by setting the appropriate flags
7548 | to the "ifa_debug" boot-args parameter.
7552 # print all OSMalloc stats
7555 set $kgm_tagp = (OSMallocTag)$arg0
7556 printf "0x%08x: ", $kgm_tagp
7557 printf "%8d ",$kgm_tagp->OSMT_refcnt
7558 printf "%8x ",$kgm_tagp->OSMT_state
7559 printf "%8x ",$kgm_tagp->OSMT_attr
7560 printf "%s ",$kgm_tagp->OSMT_name
7566 printf "TAG COUNT STATE ATTR NAME\n"
7567 set $kgm_tagheadp = (struct _OSMallocTag_ *)&OSMalloc_tag_list
7568 set $kgm_tagptr = (struct _OSMallocTag_ * )($kgm_tagheadp->OSMT_link.next)
7569 while $kgm_tagptr != $kgm_tagheadp
7570 ostag_print $kgm_tagptr
7571 set $kgm_tagptr = (struct _OSMallocTag_ *)$kgm_tagptr->OSMT_link.next
7575 document showosmalloc
7576 Syntax: (gdb) showosmalloc
7577 | Print the outstanding allocation count by OSMallocTags.
7582 if msgbufp->msg_bufc[msgbufp->msg_bufx] == 0 \
7583 && msgbufp->msg_bufc[0] != 0
7584 # The buffer hasn't wrapped, so take the easy (and fast!) path
7585 printf "%s", msgbufp->msg_bufc
7587 set $kgm_msgbuf = *msgbufp
7588 set $kgm_syslog_bufsize = $kgm_msgbuf.msg_size
7589 set $kgm_syslog_bufend = $kgm_msgbuf.msg_bufx
7590 if $kgm_syslog_bufend >= $kgm_syslog_bufsize
7591 set $kgm_syslog_bufend = 0
7594 # print older messages from msg_bufx to end of buffer
7595 set $kgm_i = $kgm_syslog_bufend
7596 while $kgm_i < $kgm_syslog_bufsize
7597 set $kgm_syslog_char = $kgm_msgbuf.msg_bufc[$kgm_i]
7598 if $kgm_syslog_char == 0
7600 set $kgm_i = $kgm_syslog_bufsize
7602 printf "%c", $kgm_syslog_char
7604 set $kgm_i = $kgm_i + 1
7607 # print newer messages from start of buffer to msg_bufx
7609 while $kgm_i < $kgm_syslog_bufend
7610 set $kgm_syslog_char = $kgm_msgbuf.msg_bufc[$kgm_i]
7611 if $kgm_syslog_char != 0
7612 printf "%c", $kgm_syslog_char
7614 set $kgm_i = $kgm_i + 1
7621 | Display the kernel's printf ring buffer
7626 set $kgm_addr = (unsigned char *)$arg0
7627 set $kgm_len = $arg1
7633 printf "%02x ", *($kgm_addr+$kgm_i)
7639 set $kgm_temp = *($kgm_addr+$kgm_i)
7640 if $kgm_temp < 32 || $kgm_temp >= 127
7643 printf "%c", $kgm_temp
7653 | Show the contents of memory as a hex/ASCII dump
7654 | The following is the syntax:
7655 | (gdb) hexdump <address> <length>
7659 define printcolonhex
7664 while ($li < $count)
7666 printf "%02x", (u_char)$addr[$li]
7669 printf ":%02x", (u_char)$addr[$li]
7676 define showsockaddr_dl
7677 set $sdl = (struct sockaddr_dl *)$arg0
7681 if $sdl->sdl_nlen == 0 && $sdl->sdl_alen == 0 && $sdl->sdl_slen == 0
7682 printf "link#%3d ", $sdl->sdl_index
7684 set $addr = $sdl->sdl_data + $sdl->sdl_nlen
7685 set $count = $sdl->sdl_alen
7686 printcolonhex $addr $count
7691 define showsockaddr_unspec
7692 set $sockaddr = (struct sockaddr *)$arg0
7693 set $addr = $sockaddr->sa_data
7694 set $count = $sockaddr->sa_len - 2
7695 printcolonhex $addr $count
7698 define showsockaddr_at
7699 set $sockaddr = (struct sockaddr *)$arg0
7700 set $addr = $sockaddr->sa_data
7701 set $count = $sockaddr->sa_len - 2
7702 printcolonhex $addr $count
7706 set $ia = (unsigned char *)$arg0
7707 printf "%3u.%03u.%03u.%03u", $ia[0], $ia[1], $ia[2], $ia[3]
7710 define showsockaddr_in
7711 set $sin = (struct sockaddr_in *)$arg0
7712 set $sa_bytes = (unsigned char *)&($sin->sin_addr)
7713 show_in_addr $sa_bytes
7716 define show_in6_addr
7717 set $ia = (unsigned char *)$arg0
7718 printf "%2x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x", \
7719 $ia[0], $ia[1], $ia[2], $ia[3], $ia[4], $ia[5], $ia[6], $ia[7], $ia[8], $ia[9], $ia[10], $ia[11], $ia[12], $ia[13], $ia[14], $ia[15]
7722 define showsockaddr_in6
7723 set $sin6 = (struct sockaddr_in6 *)$arg0
7724 set $sa_bytes = $sin6->sin6_addr.__u6_addr.__u6_addr8
7725 show_in6_addr $sa_bytes
7728 define showsockaddr_un
7729 set $sun = (struct sockaddr_un *)$arg0
7733 if $sun->sun_path[0] == 0
7736 printf "%s", $sun->sun_path
7741 define showifmultiaddrs
7742 set $ifp = (struct ifnet *)$arg0
7743 set $if_multi = (struct ifmultiaddr *)$ifp->if_multiaddrs->lh_first
7744 set $mymulti = $if_multi
7746 while ($mymulti != 0)
7747 printf "%2d. %p ", $myi, $mymulti
7748 set $sa_family = $mymulti->ifma_addr.sa_family
7749 if ($sa_family == 2)
7750 if ($mymulti->ifma_ll != 0)
7751 showsockaddr_dl $mymulti->ifma_ll->ifma_addr
7754 showsockaddr_in $mymulti->ifma_addr
7756 if ($sa_family == 30)
7757 if ($mymulti->ifma_ll != 0)
7758 showsockaddr_dl $mymulti->ifma_ll->ifma_addr
7761 showsockaddr_in6 $mymulti->ifma_addr
7763 if ($sa_family == 18)
7764 showsockaddr_dl $mymulti->ifma_addr
7766 if ($sa_family == 0)
7767 showsockaddr_unspec $mymulti->ifma_addr 6
7769 printf " [%d]", $mymulti->ifma_refcount
7771 set $mymulti = $mymulti->ifma_link.le_next
7776 document showifmultiaddrs
7777 Syntax showifmultiaddrs <ifp>
7778 | show the (struct ifnet).if_multiaddrs list of multicast addresses for the given ifp
7781 define showinmultiaddrs
7782 set $in_multi = (struct in_multi *)(in_multihead->lh_first)
7783 set $mymulti = $in_multi
7785 while ($mymulti != 0)
7786 set $ifp = (struct ifnet *)$mymulti->inm_ifp
7787 printf "%2d. %p ", $myi, $mymulti
7788 show_in_addr &($mymulti->inm_addr)
7789 printf " (ifp %p [%s%d] ifma %p) ", $ifp, $ifp->if_name, \
7790 $ifp->if_unit, $mymulti->inm_ifma
7792 set $mymulti = $mymulti->inm_link.le_next
7797 document showinmultiaddrs
7798 Syntax showinmultiaddrs
7799 | show the contents of IPv4 multicast address records
7802 define showin6multiaddrs
7803 set $in6_multi = (struct in6_multi *)(in6_multihead->lh_first)
7804 set $mymulti = $in6_multi
7806 while ($mymulti != 0)
7807 set $ifp = (struct ifnet *)$mymulti->in6m_ifp
7808 printf "%2d. %p ", $myi, $mymulti
7809 show_in6_addr &($mymulti->in6m_addr)
7810 printf " (ifp %p [%s%d] ifma %p) ", $ifp, $ifp->if_name, \
7811 $ifp->if_unit, $mymulti->in6m_ifma
7813 set $mymulti = $mymulti->in6m_entry.le_next
7818 document showin6multiaddrs
7819 Syntax showin6multiaddrs
7820 | show the contents of IPv6 multicast address records
7824 set $mysock = (struct sockaddr *)$arg0
7825 set $showsockaddr_handled = 0
7829 if ($mysock->sa_family == 0)
7831 showsockaddr_unspec $mysock
7832 set $showsockaddr_handled = 1
7834 if ($mysock->sa_family == 1)
7836 showsockaddr_un $mysock
7837 set $showsockaddr_handled = 1
7839 if ($mysock->sa_family == 2)
7841 showsockaddr_in $mysock
7842 set $showsockaddr_handled = 1
7844 if ($mysock->sa_family == 30)
7846 showsockaddr_in6 $mysock
7847 set $showsockaddr_handled = 1
7849 if ($mysock->sa_family == 18)
7851 showsockaddr_dl $mysock
7852 set $showsockaddr_handled = 1
7854 if ($mysock->sa_family == 16)
7856 showsockaddr_at $mysock
7857 set $showsockaddr_handled = 1
7859 if ($showsockaddr_handled == 0)
7860 printf "FAM %d ", $mysock->sa_family
7861 set $addr = $mysock->sa_data
7862 set $count = $mysock->sa_len
7863 printcolonhex $addr $count
7869 set $flags = (u_short)$arg0
7901 printf "POINTTOPOINT"
7903 ## if ($flags & 0x20)
7909 # printf "NOTRAILERS"
7959 if ($flags & 0x1000)
7967 if ($flags & 0x2000)
7975 if ($flags & 0x4000)
7981 printf "LINK2-ALTPHYS"
7983 if ($flags & 0x8000)
7995 set $ifp = (struct ifnet *)$arg0
7996 set $myifaddr = (struct ifaddr *)$ifp->if_addrhead->tqh_first
7998 while ($myifaddr != 0)
7999 printf "\t%d. %p ", $myi, $myifaddr
8000 showsockaddr $myifaddr->ifa_addr
8001 printf " [%d]\n", $myifaddr->ifa_refcnt
8002 set $myifaddr = $myifaddr->ifa_link->tqe_next
8007 document showifaddrs
8008 Syntax: showifaddrs <ifp>
8009 | show the (struct ifnet).if_addrhead list of addresses for the given ifp
8013 set $ifconfig_all = 0
8015 set $ifconfig_all = 1
8017 set $ifp = (struct ifnet *)(ifnet_head->tqh_first)
8019 printf "%s%d: flags=%hx", $ifp->if_name, $ifp->if_unit, (u_short)$ifp->if_flags
8020 showifflags $ifp->if_flags
8021 printf " index %d", $ifp->if_index
8022 printf " mtu %d\n", $ifp->if_data.ifi_mtu
8023 printf "\t(struct ifnet *)"
8026 if ($ifconfig_all == 1)
8029 set $ifp = $ifp->if_link->tqe_next
8033 Syntax: (gdb) ifconfig
8034 | display ifconfig-like output, and print the (struct ifnet *) pointers for further inspection
8037 set $DLIF_INUSE = 0x1
8038 set $DLIF_REUSE = 0x2
8045 set $dlifp = (struct dlil_ifnet *)(dlil_ifnet_head->tqh_first)
8047 set $ifp = (struct ifnet *)$dlifp
8048 if ($dlifp->dl_if_flags & $DLIF_REUSE)
8051 if ($dlifp->dl_if_flags & $DLIF_INUSE)
8052 printf "%s%d: ", $ifp->if_name, $ifp->if_unit
8054 printf "[%s%d]: ", $ifp->if_name, $ifp->if_unit
8056 printf "flags=%hx", (u_short)$ifp->if_flags
8057 showifflags $ifp->if_flags
8058 printf " index %d", $ifp->if_index
8059 printf " mtu %d\n", $ifp->if_data.ifi_mtu
8060 printf "\t(struct ifnet *)"
8066 set $dlifp = $dlifp->dl_if_link->tqe_next
8071 Syntax: (gdb) showifnets
8072 | Display ifconfig-like output for all attached and detached interfaces
8075 define _show_unix_domain_socket
8076 set $so = (struct socket *)$arg0
8077 set $pcb = (struct unpcb *)$so->so_pcb
8079 printf "unpcb: (null) "
8081 printf "unpcb: %p ", $pcb
8082 printf "unp_vnode: %p ", $pcb->unp_vnode
8083 printf "unp_conn: %p ", $pcb->unp_conn
8085 showsockaddr_un $pcb->unp_addr
8089 define _show_in_port
8090 set $str = (unsigned char *)$arg0
8091 set $port = *(unsigned short *)$arg0
8093 if (((($port & 0xff00) >> 8) == $str[0])) && ((($port & 0x00ff) == $str[1]))
8094 #printf "big endian "
8095 printf ":%d ", $port
8097 #printf "little endian "
8098 printf ":%d ", (($port & 0xff00) >> 8) | (($port & 0x00ff) << 8)
8102 define _show_in_addr_4in6
8103 set $ia = (unsigned char *)$arg0
8105 printf "%3u.%03u.%03u.%03u", $ia[0], $ia[1], $ia[2], $ia[3]
8109 define _show_in6_addr
8110 set $ia = (unsigned char *)$arg0
8112 printf "%2x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x", \
8113 $ia[0], $ia[1], $ia[2], $ia[3], $ia[4], $ia[5], $ia[6], $ia[7], \
8114 $ia[8], $ia[9], $ia[10], $ia[11], $ia[12], $ia[13], $ia[14], $ia[15]
8118 define _showtcpstate
8119 set $tp = (struct tcpcb *)$arg0
8121 if $tp->t_state == 0
8124 if $tp->t_state == 1
8127 if $tp->t_state == 2
8130 if $tp->t_state == 3
8133 if $tp->t_state == 4
8134 printf "ESTABLISHED "
8136 if $tp->t_state == 5
8137 printf "CLOSE_WAIT "
8139 if $tp->t_state == 6
8140 printf "FIN_WAIT_1 "
8142 if $tp->t_state == 7
8145 if $tp->t_state == 8
8148 if $tp->t_state == 9
8149 printf "FIN_WAIT_2 "
8151 if $tp->t_state == 10
8157 define _showsockprotocol
8158 set $so = (struct socket *)$arg0
8159 set $inpcb = (struct inpcb *)$so->so_pcb
8161 if $so->so_proto->pr_protocol == 6
8163 _showtcpstate $inpcb->inp_ppcb
8165 if $so->so_proto->pr_protocol == 17
8168 if $so->so_proto->pr_protocol == 1
8171 if $so->so_proto->pr_protocol == 254
8174 if $so->so_proto->pr_protocol == 255
8179 define _show_ipv4_socket
8180 set $so = (struct socket *)$arg0
8181 set $inpcb = (struct inpcb *)$so->so_pcb
8183 printf "inpcb: (null) "
8185 printf "inpcb: %p ", $inpcb
8187 _showsockprotocol $so
8189 _show_in_addr_4in6 &$inpcb->inp_dependladdr.inp46_local
8190 _show_in_port &$inpcb->inp_lport
8192 _show_in_addr_4in6 &$inpcb->inp_dependfaddr.inp46_foreign
8193 _show_in_port &$inpcb->inp_fport
8197 define _show_ipv6_socket
8198 set $so = (struct socket *)$arg0
8199 set $pcb = (struct inpcb *)$so->so_pcb
8201 printf "inpcb: (null) "
8203 printf "inpcb: %p ", $pcb
8205 _showsockprotocol $so
8207 _show_in6_addr &$pcb->inp_dependladdr.inp6_local
8208 _show_in_port &$pcb->inp_lport
8210 _show_in6_addr &$pcb->inp_dependfaddr.inp6_foreign
8211 _show_in_port &$pcb->inp_fport
8217 set $so = (struct socket *)$arg0
8219 printf "so: (null) "
8221 printf "so: %p ", $so
8222 if $so && $so->so_proto && $so->so_proto->pr_domain
8223 set $domain = (struct domain *) $so->so_proto->pr_domain
8225 printf "%s ", $domain->dom_name
8226 if $domain->dom_family == 1
8227 _show_unix_domain_socket $so
8229 if $domain->dom_family == 2
8230 _show_ipv4_socket $so
8232 if $domain->dom_family == 30
8233 _show_ipv6_socket $so
8240 Syntax: (gdb) showsocket <socket_address>
8241 | Routine to print out a socket
8244 define showprocsockets
8245 set $pp = (struct proc *)$arg0
8246 set $fdp = (struct filedesc *)$pp->p_fd
8249 set $fpp = (struct fileproc **)($fdp->fd_ofiles)
8250 set $fpo = (char)($fdp->fd_ofileflags[0])
8251 while $count < $fdp->fd_nfiles
8253 set $fg =(struct fileglob *)((**$fpp)->f_fglob)
8254 if $fg && (($fg)->fg_type == 2)
8255 if $fdp->fd_ofileflags[$count] & 4
8260 printf "fd = %d ", $count
8262 showsocket $fg->fg_data
8269 set $count = $count + 1
8272 document showprocsockets
8273 Syntax: (gdb) showprocsockets <proc_address>
8274 | Routine to print out all the open fds
8275 | which are sockets in a process
8278 define showallprocsockets
8279 set $basep = (struct proc *)allproc->lh_first
8282 printf "============================================ \n"
8285 set $pp = $pp->p_list.le_next
8288 document showallprocsockets
8289 Syntax: (gdb) showallprocsockets
8290 | Routine to print out all the open fds
8295 set $port = (unsigned short)$arg0
8296 set $port = (unsigned short)((($arg0 & 0xff00) >> 8) & 0xff)
8297 set $port |= (unsigned short)(($arg0 & 0xff) << 8)
8301 set $INPCB_STATE_INUSE=0x1
8302 set $INPCB_STATE_CACHED=0x2
8303 set $INPCB_STATE_DEAD=0x3
8305 set $INP_RECVOPTS=0x01
8306 set $INP_RECVRETOPTS=0x02
8307 set $INP_RECVDSTADDR=0x04
8308 set $INP_HDRINCL=0x08
8309 set $INP_HIGHPORT=0x10
8310 set $INP_LOWPORT=0x20
8311 set $INP_ANONPORT=0x40
8312 set $INP_RECVIF=0x80
8313 set $INP_MTUDISC=0x100
8314 set $INP_STRIPHDR=0x200
8315 set $INP_FAITH=0x400
8316 set $INP_INADDR_ANY=0x800
8317 set $INP_RECVTTL=0x1000
8318 set $INP_UDP_NOCKSUM=0x2000
8319 set $IN6P_IPV6_V6ONLY=0x008000
8320 set $IN6P_PKTINFO=0x010000
8321 set $IN6P_HOPLIMIT=0x020000
8322 set $IN6P_HOPOPTS=0x040000
8323 set $IN6P_DSTOPTS=0x080000
8324 set $IN6P_RTHDR=0x100000
8325 set $IN6P_RTHDRDSTOPTS=0x200000
8326 set $IN6P_AUTOFLOWLABEL=0x800000
8327 set $IN6P_BINDV6ONLY=0x10000000
8336 set $pcb = (struct inpcb *)$arg0
8340 printf "%10p ", $pcb
8342 if $arg1 == $IPPROTO_TCP
8345 if $arg1 == $IPPROTO_UDP
8348 printf "%2d.", $arg1
8351 if ($pcb->inp_vflag & $INP_IPV4)
8354 if ($pcb->inp_vflag & $INP_IPV6)
8358 if ($pcb->inp_vflag & $INP_IPV4)
8360 _show_in_addr &$pcb->inp_dependladdr.inp46_local.ia46_addr4
8362 _show_in6_addr &$pcb->inp_dependladdr.inp6_local
8365 _print_ntohs $pcb->inp_lport
8367 if ($pcb->inp_vflag & $INP_IPV4)
8369 _show_in_addr &($pcb->inp_dependfaddr.inp46_foreign.ia46_addr4)
8371 _show_in6_addr &($pcb->inp_dependfaddr.inp6_foreign)
8374 _print_ntohs $pcb->inp_fport
8377 if $arg1 == $IPPROTO_TCP
8378 _showtcpstate $pcb->inp_ppcb
8382 # set $phd = $pcb->inp_phd
8385 # _print_ntohs $phd->phd_port
8386 # set $phd = $phd->phd_hash.le_next
8389 if ($pcb->inp_flags & $INP_RECVOPTS)
8392 if ($pcb->inp_flags & $INP_RECVRETOPTS)
8393 printf "recvretopts "
8395 if ($pcb->inp_flags & $INP_RECVDSTADDR)
8396 printf "recvdstaddr "
8398 if ($pcb->inp_flags & $INP_HDRINCL)
8401 if ($pcb->inp_flags & $INP_HIGHPORT)
8404 if ($pcb->inp_flags & $INP_LOWPORT)
8407 if ($pcb->inp_flags & $INP_ANONPORT)
8410 if ($pcb->inp_flags & $INP_RECVIF)
8413 if ($pcb->inp_flags & $INP_MTUDISC)
8416 if ($pcb->inp_flags & $INP_STRIPHDR)
8419 if ($pcb->inp_flags & $INP_FAITH)
8422 if ($pcb->inp_flags & $INP_INADDR_ANY)
8423 printf "inaddr_any "
8425 if ($pcb->inp_flags & $INP_RECVTTL)
8428 if ($pcb->inp_flags & $INP_UDP_NOCKSUM)
8431 if ($pcb->inp_flags & $IN6P_IPV6_V6ONLY)
8434 if ($pcb->inp_flags & $IN6P_PKTINFO)
8437 if ($pcb->inp_flags & $IN6P_HOPLIMIT)
8440 if ($pcb->inp_flags & $IN6P_HOPOPTS)
8443 if ($pcb->inp_flags & $IN6P_DSTOPTS)
8446 if ($pcb->inp_flags & $IN6P_RTHDR)
8449 if ($pcb->inp_flags & $IN6P_RTHDRDSTOPTS)
8450 printf "rthdrdstopts "
8452 if ($pcb->inp_flags & $IN6P_AUTOFLOWLABEL)
8453 printf "autoflowlabel "
8455 if ($pcb->inp_flags & $IN6P_BINDV6ONLY)
8456 printf "bindv6only "
8458 set $so = (struct socket *)$pcb->inp_socket
8460 printf "[so=%p s=%ld r=%ld usecnt=%ld] ", $so, $so->so_snd.sb_cc, \
8461 $so->so_rcv.sb_cc, $so->so_usecount
8463 if ($pcb->inp_state == 0 || $pcb->inp_state == $INPCB_STATE_INUSE)
8466 if ($pcb->inp_state == $INPCB_STATE_CACHED)
8469 if ($pcb->inp_state == $INPCB_STATE_DEAD)
8472 printf "unknown (%d), ", $pcb->inp_state
8478 define _dump_inpcbport
8479 set $ppcb = (struct inpcbport *)$arg0
8480 printf "%p: lport ", $ppcb
8481 _print_ntohs $ppcb->phd_port
8486 define _dump_pcbinfo
8488 set $snd_buf = (unsigned int)0
8490 set $rcv_buf = (unsigned int)0
8492 set $pcbi = (struct inpcbinfo *)$arg0
8493 printf "lastport %d lastlow %d lasthi %d\n", \
8494 $pcbi->lastport, $pcbi->lastlow, $pcbi->lasthi
8495 printf "active pcb count is %d\n", $pcbi->ipi_count
8496 set $hashsize = $pcbi->hashmask + 1
8497 printf "hash size is %d\n", $hashsize
8498 printf "hash base %p has the following inpcb(s):\n", $pcbi->hashbase
8500 printf "pcb prot source address port destination address port\n"
8501 printf "------------------ ---- --------------------------------------- ----- --------------------------------------- -----\n"
8503 printf "pcb prot source address port destination address port\n"
8504 printf "---------- ---- --------------------------------------- ----- --------------------------------------- -----\n"
8507 set $hashbase = $pcbi->hashbase
8508 set $head = *(uintptr_t *)$hashbase
8509 while $i < $hashsize
8511 set $pcb0 = (struct inpcb *)$head
8514 _dump_inpcb $pcb0 $arg1
8515 set $so = (struct socket *)$pcb->inp_socket
8517 set $snd_cc += $so->so_snd.sb_cc
8518 set $mp = $so->so_snd.sb_mb
8521 if ($mp->m_hdr.mh_flags & 0x01)
8522 set $snd_buf += $mp->M_dat.MH.MH_dat.MH_ext.ext_size
8524 set $mp = $mp->m_hdr.mh_next
8526 set $rcv_cc += $so->so_rcv.sb_cc
8527 set $mp = $so->so_rcv.sb_mb
8530 if ($mp->m_hdr.mh_flags & 0x01)
8531 set $rcv_buf += $mp->M_dat.MH.MH_dat.MH_ext.ext_size
8533 set $mp = $mp->m_hdr.mh_next
8536 set $pcb0 = $pcb0->inp_hash.le_next
8542 set $head = *(uintptr_t *)$hashbase
8544 printf "total seen %ld snd_cc %ld rcv_cc %ld\n", $pcbseen, $snd_cc, $rcv_cc
8545 printf "total snd_buf %u rcv_buf %u \n", (unsigned int)$snd_buf, (unsigned int)$rcv_buf
8546 printf "port hash base is %p\n", $pcbi->porthashbase
8548 set $hashbase = $pcbi->porthashbase
8549 set $head = *(uintptr_t *)$hashbase
8550 while $i < $hashsize
8552 set $pcb0 = (struct inpcbport *)$head
8555 _dump_inpcbport $pcb0
8557 set $pcb0 = $pcb0->phd_hash.le_next
8562 set $head = *(uintptr_t *)$hashbase
8566 set $N_TIME_WAIT_SLOTS=128
8568 define show_tcp_timewaitslots
8575 set $slot = (int)$arg0
8578 printf "time wait slot size %d cur_tw_slot %ld\n", $N_TIME_WAIT_SLOTS, cur_tw_slot
8580 while $i < $N_TIME_WAIT_SLOTS
8582 set $head = (uintptr_t *)time_wait_slots[$i]
8583 if $i == $slot || $slot == -1
8585 set $pcb0 = (struct inpcb *)$head
8588 set $pcb0 = $pcb0->inp_list.le_next
8591 printf " slot %ld count %ld\n", $i, $perslot
8593 if $all || $i == $slot
8595 set $pcb0 = (struct inpcb *)$head
8598 _dump_inpcb $pcb0 $IPPROTO_TCP
8600 set $pcb0 = $pcb0->inp_list.le_next
8607 document show_tcp_timewaitslots
8608 Syntax: (gdb) show_tcp_timewaitslots
8609 | Print the list of TCP protocol control block in the TIMEWAIT state
8610 | Pass -1 to see the list of PCB for each slot
8611 | Pass a slot number to see information for that slot with the list of PCB
8614 define show_tcp_pcbinfo
8615 _dump_pcbinfo &tcbinfo $IPPROTO_TCP
8617 document show_tcp_pcbinfo
8618 Syntax: (gdb) show_tcp_pcbinfo
8619 | Print the list of TCP protocol control block information
8623 define show_udp_pcbinfo
8624 _dump_pcbinfo &udbinfo $IPPROTO_UDP
8626 document show_udp_pcbinfo
8627 Syntax: (gdb) show_udp_pcbinfo
8628 | Print the list of UDP protocol control block information
8633 while ($myi < bpf_dtab_size)
8634 if (bpf_dtab[$myi] != 0)
8635 printf "Address 0x%x, bd_next 0x%x\n", bpf_dtab[$myi], bpf_dtab[$myi]->bd_next
8636 print *bpf_dtab[$myi]
8642 define printvnodepathint_recur
8644 if ($arg0->v_flag & 0x000001) && ($arg0->v_mount != 0)
8645 if $arg0->v_mount->mnt_vnodecovered != 0
8646 printvnodepathint_recur $arg0->v_mount->mnt_vnodecovered $arg0->v_mount->mnt_vnodecovered->v_name
8649 printvnodepathint_recur $arg0->v_parent $arg0->v_parent->v_name
8655 define showvnodepath
8656 set $vp = (struct vnode *)$arg0
8658 if ($vp->v_flag & 0x000001) && ($vp->v_mount != 0) && ($vp->v_mount->mnt_flag & 0x00004000)
8661 printvnodepathint_recur $vp $vp->v_name
8667 document showvnodepath
8668 Syntax: (gdb) showvnodepath <vnode>
8669 | Prints the path for a vnode
8677 printf " mnt_devvp "
8679 printf " typename mountpoint\n"
8680 set $kgm_vol = (mount_t) mountlist.tqh_first
8684 showptr $kgm_vol->mnt_data
8686 showptr $kgm_vol->mnt_devvp
8688 if ($kgm_vol->mnt_vtable->vfc_name[0] == 'h') && \
8689 ($kgm_vol->mnt_vtable->vfc_name[1] == 'f') && \
8690 ($kgm_vol->mnt_vtable->vfc_name[2] == 's') && \
8691 ($kgm_vol->mnt_vtable->vfc_name[3] == '\0')
8692 set $kgm_hfsmount = \
8693 (struct hfsmount *) $kgm_vol->mnt_data
8694 if $kgm_hfsmount->hfs_freezing_proc != 0
8695 printf "FROZEN hfs "
8700 printf "%-10s ", $kgm_vol->mnt_vtable->vfc_name
8702 printf "%s\n", $kgm_vol->mnt_vfsstat.f_mntonname
8704 set $kgm_vol = (mount_t) $kgm_vol->mnt_list.tqe_next
8708 document showallvols
8709 Syntax: (gdb) showallvols
8710 | Display a summary of mounted volumes
8713 define showvnodeheader
8716 printf " usecount iocount v_data "
8718 printf " vtype parent "
8724 set $kgm_vnode = (vnode_t) $arg0
8726 printf " %8d ", $kgm_vnode->v_usecount
8727 printf "%7d ", $kgm_vnode->v_iocount
8728 # print information about clean/dirty blocks?
8729 showptr $kgm_vnode->v_data
8731 # print the vtype, using the enum tag
8732 set $kgm_vtype = $kgm_vnode->v_type
8733 if $kgm_vtype == VNON
8736 if $kgm_vtype == VREG
8739 if $kgm_vtype == VDIR
8742 if $kgm_vtype == VBLK
8745 if $kgm_vtype == VCHR
8748 if $kgm_vtype == VLNK
8751 if $kgm_vtype == VSOCK
8754 if $kgm_vtype == VFIFO
8757 if $kgm_vtype == VBAD
8760 if ($kgm_vtype < VNON) || ($kgm_vtype > VBAD)
8761 printf "%5d ", $kgm_vtype
8764 showptr $kgm_vnode->v_parent
8766 if ($kgm_vnode->v_name != 0)
8767 printf "%s\n", $kgm_vnode->v_name
8769 # If this is HFS vnode, get name from the cnode
8770 if ($kgm_vnode->v_tag == 16)
8771 set $kgm_cnode = (struct cnode *)$kgm_vnode->v_data
8772 printf "hfs: %s\n", (char *)$kgm_cnode->c_desc->cd_nameptr
8785 Syntax: (gdb) showvnode <vnode>
8786 | Display info about one vnode
8789 define showvolvnodes
8791 set $kgm_vol = (mount_t) $arg0
8792 set $kgm_vnode = (vnode_t) $kgm_vol.mnt_vnodelist.tqh_first
8794 showvnodeint $kgm_vnode
8795 set $kgm_vnode = (vnode_t) $kgm_vnode->v_mntvnodes.tqe_next
8799 document showvolvnodes
8800 Syntax: (gdb) showvolvnodes <mouont_t>
8801 | Display info about all vnodes of a given mount_t
8804 define showvolbusyvnodes
8806 set $kgm_vol = (mount_t) $arg0
8807 set $kgm_vnode = (vnode_t) $kgm_vol.mnt_vnodelist.tqh_first
8809 if $kgm_vnode->v_iocount != 0
8810 showvnodeint $kgm_vnode
8812 set $kgm_vnode = (vnode_t) $kgm_vnode->v_mntvnodes.tqe_next
8816 document showvolbusyvnodes
8817 Syntax: (gdb) showvolbusyvnodes <mount_t>
8818 | Display info about busy (iocount!=0) vnodes of a given mount_t
8821 define showallbusyvnodes
8823 set $kgm_vol = (mount_t) mountlist.tqh_first
8825 set $kgm_vnode = (vnode_t) $kgm_vol.mnt_vnodelist.tqh_first
8827 if $kgm_vnode->v_iocount != 0
8828 showvnodeint $kgm_vnode
8830 set $kgm_vnode = (vnode_t) $kgm_vnode->v_mntvnodes.tqe_next
8832 set $kgm_vol = (mount_t) $kgm_vol->mnt_list.tqe_next
8836 document showallbusyvnodes
8837 Syntax: (gdb) showallbusyvnodes <vnode>
8838 | Display info about all busy (iocount!=0) vnodes
8841 define showallvnodes
8843 set $kgm_vol = (mount_t) mountlist.tqh_first
8845 set $kgm_vnode = (vnode_t) $kgm_vol.mnt_vnodelist.tqh_first
8847 showvnodeint $kgm_vnode
8848 set $kgm_vnode = (vnode_t) $kgm_vnode->v_mntvnodes.tqe_next
8850 set $kgm_vol = (mount_t) $kgm_vol->mnt_list.tqe_next
8854 document showallvnodes
8855 Syntax: (gdb) showallvnodes
8856 | Display info about all vnodes
8859 define _showvnodelockheader
8860 printf "* type W held by lock type start end\n"
8861 printf "- ----- - ------------- --------- ------------------ ------------------\n"
8864 define _showvnodelock
8865 set $kgm_svl_lock = ((struct lockf *)$arg0)
8868 set $kgm_svl_flags = $kgm_svl_lock->lf_flags
8869 set $kgm_svl_type = $kgm_svl_lock->lf_type
8870 if ($kgm_svl_flags & 0x20)
8873 if ($kgm_svl_flags & 0x40)
8876 if ($kgm_svl_flags & 0x80)
8879 if ($kgm_svl_flags & 0x10)
8885 # POSIX file vs. advisory range locks
8886 if ($kgm_svl_flags & 0x40)
8887 set $kgm_svl_proc = (proc_t)$kgm_svl_lock->lf_id
8888 printf "PID %8d ", $kgm_svl_proc->p_pid
8890 printf "ID 0x%08x ", $kgm_svl_lock->lf_id
8894 if ($kgm_svl_type == 1)
8897 if ($kgm_svl_type == 3)
8900 if ($kgm_svl_type == 2)
8909 printf "0x%016x..", $kgm_svl_lock->lf_start
8910 printf "0x%016x ", $kgm_svl_lock->lf_end
8913 # Body of showvnodelocks, not including header
8914 define _showvnodelocks
8915 set $kgm_svl_vnode = ((vnode_t)$arg0)
8916 set $kgm_svl_lockiter = $kgm_svl_vnode->v_lockf
8917 while ($kgm_svl_lockiter != 0)
8918 # locks that are held
8920 _showvnodelock $kgm_svl_lockiter
8922 # and any locks blocked by them
8923 set $kgm_svl_blocker = $kgm_svl_lockiter->lf_blkhd.tqh_first
8924 while ($kgm_svl_blocker != 0)
8926 _showvnodelock $kgm_svl_blocker
8927 set $kgm_svl_blocker = $kgm_svl_blocker->lf_block.tqe_next
8930 # and on to the next one...
8931 set $kgm_svl_lockiter = $kgm_svl_lockiter->lf_next
8936 define showvnodelocks
8938 _showvnodelockheader
8939 _showvnodelocks $arg0
8941 printf "| Usage:\n|\n"
8946 document showvnodelocks
8947 Syntax: (gdb) showvnodelocks <vnode_t>
8948 | Given a vnodet pointer, display the list of advisory record locks for the
8949 | referenced pvnodes
8953 printf "%s\n", (char*)((boot_args*)PE_state.bootArgs).CommandLine
8956 document showbootargs
8957 Syntax: showbootargs
8958 | Display boot arguments passed to the target kernel
8961 define showbootermemorymap
8962 if ($kgm_mtype == $kgm_mtype_i386)
8963 set $kgm_voffset = 0
8965 if ($kgm_mtype == $kgm_mtype_x86_64)
8966 set $kgm_voffset = 0xFFFFFF8000000000ULL
8968 echo showbootermemorymap not supported on this architecture
8972 set $kgm_boot_args = kernelBootArgs
8973 set $kgm_msize = kernelBootArgs->MemoryMapDescriptorSize
8974 set $kgm_mcount = kernelBootArgs->MemoryMapSize / $kgm_msize
8977 printf "Type Physical Start Number of Pages Virtual Start Attributes\n"
8978 while $kgm_i < $kgm_mcount
8979 set $kgm_mptr = (EfiMemoryRange *)((unsigned long)kernelBootArgs->MemoryMap + $kgm_voffset + $kgm_i * $kgm_msize)
8981 if $kgm_mptr->Type == 0
8984 if $kgm_mptr->Type == 1
8987 if $kgm_mptr->Type == 2
8990 if $kgm_mptr->Type == 3
8993 if $kgm_mptr->Type == 4
8996 if $kgm_mptr->Type == 5
8999 if $kgm_mptr->Type == 6
9002 if $kgm_mptr->Type == 7
9005 if $kgm_mptr->Type == 8
9008 if $kgm_mptr->Type == 9
9011 if $kgm_mptr->Type == 10
9014 if $kgm_mptr->Type == 11
9017 if $kgm_mptr->Type == 12
9020 if $kgm_mptr->Type == 13
9023 if $kgm_mptr->Type > 13
9027 printf " %016llx %016llx", $kgm_mptr->PhysicalStart, $kgm_mptr->NumberOfPages
9028 if $kgm_mptr->VirtualStart != 0
9029 printf " %016llx", $kgm_mptr->VirtualStart
9033 printf " %016llx\n", $kgm_mptr->Attribute
9034 set $kgm_i = $kgm_i + 1
9038 document showbootermemorymap
9039 Syntax: (gdb) showbootermemorymap
9040 | Prints out the phys memory map from kernelBootArgs
9044 define showstacksaftertask
9045 set $kgm_head_taskp = &tasks
9046 set $kgm_taskp = (struct task *)$arg0
9047 set $kgm_taskp = (struct task *)$kgm_taskp->tasks.next
9048 while $kgm_taskp != $kgm_head_taskp
9050 showtaskint $kgm_taskp
9051 set $kgm_head_actp = &($kgm_taskp->threads)
9052 set $kgm_actp = (struct thread *)($kgm_taskp->threads.next)
9053 while $kgm_actp != $kgm_head_actp
9055 if ($decode_wait_events > 0)
9056 showactint $kgm_actp 1
9058 showactint $kgm_actp 2
9060 set $kgm_actp = (struct thread *)($kgm_actp->task_threads.next)
9063 set $kgm_taskp = (struct task *)($kgm_taskp->tasks.next)
9066 document showstacksaftertask
9067 Syntax: (gdb) showstacksaftertask <task>
9068 | Routine to print out all stacks (as in showallstacks) starting after a given task
9069 | Useful if that gdb refuses to print a certain task's stack.
9072 define showpmworkqueueint
9073 set $kgm_pm_workqueue = (IOPMWorkQueue *)$arg0
9074 set $kgm_pm_wq = &($kgm_pm_workqueue->fWorkQueue)
9075 set $kgm_pm_wqe = (IOServicePM *)$kgm_pm_wq->next
9076 while ((queue_entry_t) $kgm_pm_wqe != (queue_entry_t) $kgm_pm_wq)
9079 printf " ps ms wr name\n"
9080 showptr $kgm_pm_wqe->Owner
9082 printf "%02d ", $kgm_pm_wqe->CurrentPowerState
9083 printf "%02d ", $kgm_pm_wqe->MachineState
9084 printf "%02d ", $kgm_pm_wqe->WaitReason
9085 printf "%s\n", $kgm_pm_wqe->Name
9088 printf " type next "
9092 printf " work_wait free_wait\n"
9093 set $kgm_pm_rq = &($kgm_pm_wqe->RequestHead)
9094 set $kgm_pm_rqe = (IOPMRequest *)$kgm_pm_rq->next
9095 while ((queue_entry_t) $kgm_pm_rqe != (queue_entry_t) $kgm_pm_rq)
9097 printf " 0x%02x ", $kgm_pm_rqe->fType
9098 showptr $kgm_pm_rqe->fRequestNext
9100 showptr $kgm_pm_rqe->fRequestRoot
9101 printf " 0x%08x 0x%08x\n", $kgm_pm_rqe->fWorkWaitCount, $kgm_pm_rqe->fFreeWaitCount
9104 showptr $kgm_pm_rqe->fArg0
9106 showptr $kgm_pm_rqe->fArg1
9108 showptr $kgm_pm_rqe->fArg2
9110 set $kgm_pm_rqe = (IOPMRequest *)$kgm_pm_rqe->fCommandChain.next
9113 set $kgm_pm_wqe = (IOServicePM *)$kgm_pm_wqe->WorkChain.next
9117 define showpmworkqueue
9118 printf "IOPMWorkQueue "
9119 showptr gIOPMWorkQueue
9121 printf "%u", gIOPMWorkQueue->fQueueLength
9123 if (gIOPMWorkQueue->fQueueLength > 0)
9124 showpmworkqueueint gIOPMWorkQueue
9128 document showpmworkqueue
9129 Syntax: (gdb) showpmworkqueue
9130 | Display the IOPMWorkQueue object
9133 define showioservicepm
9134 set $kgm_iopmpriv = (IOServicePM *)$arg0
9136 printf "MachineState = %d (", $kgm_iopmpriv->MachineState
9137 if ( $kgm_iopmpriv->MachineState == 0 )
9138 printf "kIOPM_Finished"
9140 if ( $kgm_iopmpriv->MachineState == 1 )
9141 printf "kIOPM_OurChangeTellClientsPowerDown"
9143 if ( $kgm_iopmpriv->MachineState == 2 )
9144 printf "kIOPM_OurChangeTellPriorityClientsPowerDown"
9146 if ( $kgm_iopmpriv->MachineState == 3 )
9147 printf "kIOPM_OurChangeNotifyInterestedDriversWillChange"
9149 if ( $kgm_iopmpriv->MachineState == 4 )
9150 printf "kIOPM_OurChangeSetPowerState"
9152 if ( $kgm_iopmpriv->MachineState == 5 )
9153 printf "kIOPM_OurChangeWaitForPowerSettle"
9155 if ( $kgm_iopmpriv->MachineState == 6 )
9156 printf "kIOPM_OurChangeNotifyInterestedDriversDidChange"
9158 if ( $kgm_iopmpriv->MachineState == 7 )
9159 printf "kIOPM_OurChangeTellCapabilityDidChange"
9161 if ( $kgm_iopmpriv->MachineState == 8 )
9162 printf "kIOPM_OurChangeFinish"
9164 if ( $kgm_iopmpriv->MachineState == 9 )
9165 printf "Unused_MachineState_9"
9167 if ( $kgm_iopmpriv->MachineState == 10 )
9168 printf "kIOPM_ParentChangeTellPriorityClientsPowerDown"
9170 if ( $kgm_iopmpriv->MachineState == 11 )
9171 printf "kIOPM_ParentChangeNotifyInterestedDriversWillChange"
9173 if ( $kgm_iopmpriv->MachineState == 12 )
9174 printf "kIOPM_ParentChangeSetPowerState"
9176 if ( $kgm_iopmpriv->MachineState == 13 )
9177 printf "kIOPM_ParentChangeWaitForPowerSettle"
9179 if ( $kgm_iopmpriv->MachineState == 14)
9180 printf "kIOPM_ParentChangeNotifyInterestedDriversDidChange"
9182 if ( $kgm_iopmpriv->MachineState == 15)
9183 printf "kIOPM_ParentChangeTellCapabilityDidChange"
9185 if ( $kgm_iopmpriv->MachineState == 16)
9186 printf "kIOPM_ParentChangeAcknowledgePowerChange"
9188 if ( $kgm_iopmpriv->MachineState == 17)
9189 printf "kIOPM_NotifyChildrenStart"
9191 if ( $kgm_iopmpriv->MachineState == 18)
9192 printf "kIOPM_NotifyChildrenOrdered"
9194 if ( $kgm_iopmpriv->MachineState == 19)
9195 printf "kIOPM_NotifyChildrenDelayed"
9197 if ( $kgm_iopmpriv->MachineState == 20)
9198 printf "kIOPM_SyncTellClientsPowerDown"
9200 if ( $kgm_iopmpriv->MachineState == 21)
9201 printf "kIOPM_SyncTellPriorityClientsPowerDown"
9203 if ( $kgm_iopmpriv->MachineState == 22)
9204 printf "kIOPM_SyncNotifyWillChange"
9206 if ( $kgm_iopmpriv->MachineState == 23)
9207 printf "kIOPM_SyncNotifyDidChange"
9209 if ( $kgm_iopmpriv->MachineState == 24)
9210 printf "kIOPM_SyncTellCapabilityDidChange"
9212 if ( $kgm_iopmpriv->MachineState == 25)
9213 printf "kIOPM_SyncFinish"
9215 if ( $kgm_iopmpriv->MachineState == 26)
9216 printf "kIOPM_TellCapabilityChangeDone"
9218 if ( $kgm_iopmpriv->MachineState == 27)
9219 printf "kIOPM_DriverThreadCallDone"
9221 printf "Unknown_MachineState"
9252 if ( $kgm_iopmpriv->MachineState != 20 )
9253 printf "DriverTimer = %d, ",(unsigned int)$kgm_iopmpriv->DriverTimer
9254 printf "SettleTime = %d, ",(unsigned int)$kgm_iopmpriv->SettleTimeUS
9255 printf "HeadNoteFlags = %08x, ",(unsigned int)$kgm_iopmpriv->HeadNoteChangeFlags
9256 printf "HeadNotePendingAcks = %x, ",(unsigned int)$kgm_iopmpriv->HeadNotePendingAcks
9259 if ( $kgm_iopmpriv->DeviceOverrideEnabled != 0 )
9260 printf"DeviceOverrides, "
9263 printf "DeviceDesire = %d, ",(unsigned int)$kgm_iopmpriv->DeviceDesire
9264 printf "DesiredPowerState = %d, ",(unsigned int)$kgm_iopmpriv->DesiredPowerState
9265 printf "PreviousRequest = %d }\n",(unsigned int)$kgm_iopmpriv->PreviousRequestPowerFlags
9268 document showioservicepm
9269 Syntax: (gdb) showioservicepm <IOServicePM pointer>
9270 | Routine to dump the IOServicePM object
9273 define showregistryentryrecursepmstate
9274 set $kgm_re = (IOService *)$arg1
9275 set $kgm$arg0_stack = (unsigned long long) $arg2
9278 set $kgm$arg0_stack = $kgm$arg0_stack | (1ULL << $kgm_reg_depth)
9280 set $kgm$arg0_stack = $kgm$arg0_stack & ~(1ULL << $kgm_reg_depth)
9283 dictget $kgm_re->fRegistryTable $kgm_childkey
9284 set $kgm$arg0_child_array = (OSArray *) $kgm_result
9286 if ($kgm$arg0_child_array)
9287 set $kgm$arg0_child_count = $kgm$arg0_child_array->count
9289 set $kgm$arg0_child_count = 0
9292 if ($kgm$arg0_child_count)
9293 set $kgm$arg0_stack = $kgm$arg0_stack | (2ULL << $kgm_reg_depth)
9295 set $kgm$arg0_stack = $kgm$arg0_stack & ~(2ULL << $kgm_reg_depth)
9298 indent $kgm_reg_depth $kgm$arg0_stack
9301 dictget $kgm_re->fRegistryTable $kgm_namekey
9302 if ($kgm_result == 0)
9303 dictget $kgm_re->fRegistryTable gIONameKey
9305 if ($kgm_result == 0)
9306 dictget $kgm_re->fPropertyTable gIOClassKey
9309 if ($kgm_result != 0)
9310 printf "%s <%p>", ((OSString *)$kgm_result)->string, $kgm_re
9312 if (((IOService*)$kgm_re)->pwrMgt && ((IOService*)$kgm_re)->pwrMgt->Name)
9313 printf "%s <", ((IOService*)$kgm_re)->pwrMgt->Name
9323 if (((IOService*)$kgm_re)->pwrMgt )
9324 printf " Current Power State: %ld ", ((IOService*)$kgm_re)->pwrMgt->CurrentPowerState
9325 #printf " Mach State %ld", ((IOService*)$kgm_re)->pwrMgt->MachineState
9326 showioservicepm ((IOService*)$kgm_re)->pwrMgt
9332 if ($kgm$arg0_child_count != 0)
9334 set $kgm_reg_depth = $kgm_reg_depth + 1
9335 set $kgm$arg0_child_idx = 0
9337 while ($kgm$arg0_child_idx < $kgm$arg0_child_count)
9338 set $kgm_re = $kgm$arg0_child_array->array[$kgm$arg0_child_idx++]
9339 set $kgm_more_sib = ($kgm$arg0_child_idx < $kgm$arg0_child_count)
9340 if $kgm_reg_depth >= $kgm_reg_depth_max + 1
9343 showregistryentryrecursepmstate _$arg0 $kgm_re $kgm$arg0_stack $kgm_more_sib
9346 set $kgm_reg_depth = $kgm_reg_depth - 1
9350 define showregistryentryintpmstate
9352 set $kgm_reg_plane = (IORegistryPlane *) gIOServicePlane
9356 printf "Please load kgmacros after KDP attaching to the target.\n"
9358 set $kgm_namekey = (OSSymbol *) $kgm_reg_plane->nameKey
9359 set $kgm_childkey = (OSSymbol *) $kgm_reg_plane->keys[1]
9360 showregistryentryrecursepmstate _ $arg0 0 0
9364 define showregistrypmstate
9365 # setregistryplane gIOPowerPlane
9366 set $kgm_reg_depth = 0
9367 set $kgm_show_props = 1
9368 showregistryentryintpmstate gRegistryRoot
9371 document showregistrypmstate
9372 Syntax: (gdb) showregistrypmstate
9373 | Routine to dump the PM state of each IOPower registry entry
9376 define showstacksafterthread
9377 set $kgm_head_taskp = &tasks
9378 set $kgm_actp = (struct thread *)$arg0
9379 set $kgm_actp = (struct thread *)($kgm_actp->task_threads.next)
9380 set $kgm_taskp = (struct task *)$kgm_actp->task
9381 while $kgm_taskp != $kgm_head_taskp
9383 showtaskint $kgm_taskp
9384 set $kgm_head_actp = &($kgm_taskp->threads)
9386 set $kgm_actp = (struct thread *)($kgm_taskp->threads.next)
9388 while $kgm_actp != $kgm_head_actp
9390 if ($decode_wait_events > 0)
9391 showactint $kgm_actp 1
9393 showactint $kgm_actp 2
9395 set $kgm_actp = (struct thread *)($kgm_actp->task_threads.next)
9398 set $kgm_taskp = (struct task *)($kgm_taskp->tasks.next)
9403 document showstacksafterthread
9404 Syntax: (gdb) showstacksafterthread <thread>
9405 | Routine to print out all stacks (as in showallstacks) starting after a given thread
9406 | Useful if that gdb refuses to print a certain task's stack.
9410 set kdp_reentry_deadline = ((unsigned) $arg0)*1000
9414 document kdp-reenter
9415 Syntax: (gdb) kdp-reenter <seconds>
9416 | Schedules reentry into the debugger after <seconds> seconds, and resumes
9417 | the target system.
9428 if (($kgm_mtype & $kgm_mtype_x86_mask) != $kgm_mtype_x86_any)
9429 printf "Not available for current architecture.\n"
9432 _if_present mca_MCA_present
9433 printf ", control MSR"
9434 _if_present mca_control_MSR_present
9435 printf ", threshold status"
9436 _if_present mca_threshold_status_present
9437 printf "\n%d error banks, ", mca_error_bank_count
9438 printf "family code 0x%x, ", mca_family
9439 printf "machine-check dump state: %d\n", mca_dump_state
9441 while cpu_data_ptr[$kgm_cpu] != 0
9442 set $kgm_mcp = cpu_data_ptr[$kgm_cpu]->cpu_mca_state
9444 printf "CPU %d:", $kgm_cpu
9445 printf " mca_mcg_ctl: 0x%016llx", $kgm_mcp->mca_mcg_ctl
9446 printf " mca_mcg_status: 0x%016llx\n", $kgm_mcp->mca_mcg_status.u64
9448 printf "mca_mci_ctl "
9449 printf "mca_mci_status "
9450 printf "mca_mci_addr "
9451 printf "mca_mci_misc\n"
9453 while $kgm_bank < mca_error_bank_count
9454 set $kgm_bp = &$kgm_mcp->mca_error_bank[$kgm_bank]
9455 printf " %2d:", $kgm_bank
9456 printf " 0x%016llx", $kgm_bp->mca_mci_ctl
9457 printf " 0x%016llx", $kgm_bp->mca_mci_status.u64
9458 printf " 0x%016llx", $kgm_bp->mca_mci_addr
9459 printf " 0x%016llx\n", $kgm_bp->mca_mci_misc
9460 set $kgm_bank = $kgm_bank + 1
9463 set $kgm_cpu = $kgm_cpu + 1
9468 document showMCAstate
9469 Syntax: showMCAstate
9470 | Print machine-check register state after MC exception.
9475 # Step to lower-level page table and print attributes
9476 # $kgm_pt_paddr: current page table entry physical address
9477 # $kgm_pt_index: current page table entry index (0..511)
9479 # $kgm_pt_paddr: next level page table entry physical address
9480 # or null if invalid
9481 # $kgm_pt_valid: 1 if $kgm_pt_paddr is valid, 0 if the walk
9483 # $kgm_pt_large: 1 if kgm_pt_paddr is a page frame address
9484 # of a large page and not another page table entry
9485 # For $kgm_pt_verbose = 0: print nothing
9486 # 1: print basic information
9487 # 2: print basic information and hex table dump
9489 set $kgm_entryp = $kgm_pt_paddr + 8*$kgm_pt_index
9490 readphysint $kgm_entryp 64 $kgm_lcpu_self
9491 set $entry = $kgm_readphysint_result
9492 if $kgm_pt_verbose >= 3
9493 set $kgm_pte_loop = 0
9494 while $kgm_pte_loop < 512
9495 set $kgm_pt_paddr_tmp = $kgm_pt_paddr + $kgm_pte_loop*8
9496 readphys64 $kgm_pt_paddr_tmp
9497 set $kgm_pte_loop = $kgm_pte_loop + 1
9500 set $kgm_paddr_mask = ~((0xfffULL<<52) | 0xfffULL)
9501 set $kgm_paddr_largemask = ~((0xfffULL<<52) | 0x1fffffULL)
9502 if $kgm_pt_verbose < 2
9503 if $entry & (0x1 << 0)
9504 set $kgm_pt_valid = 1
9505 if $entry & (0x1 << 7)
9506 set $kgm_pt_large = 1
9507 set $kgm_pt_paddr = $entry & $kgm_paddr_largemask
9509 set $kgm_pt_large = 0
9510 set $kgm_pt_paddr = $entry & $kgm_paddr_mask
9513 set $kgm_pt_valid = 0
9514 set $kgm_pt_large = 0
9515 set $kgm_pt_paddr = 0
9518 printf "0x%016llx:\n\t0x%016llx\n\t", $kgm_entryp, $entry
9519 if $entry & (0x1 << 0)
9521 set $kgm_pt_paddr = $entry & $kgm_paddr_mask
9522 set $kgm_pt_valid = 1
9525 set $kgm_pt_paddr = 0
9526 set $kgm_pt_valid = 0
9527 # stop decoding other bits
9530 if $entry & (0x1 << 1)
9535 if $entry & (0x1 << 2)
9538 printf " supervisor"
9540 if $entry & (0x1 << 3)
9543 if $entry & (0x1 << 4)
9546 if $entry & (0x1 << 5)
9549 if $entry & (0x1 << 6)
9552 if $entry & (0x1 << 7)
9554 set $kgm_pt_large = 1
9556 set $kgm_pt_large = 0
9558 if $entry & (0x1 << 8)
9561 if $entry & (0x3 << 9)
9562 printf " avail:0x%x", ($entry >> 9) & 0x3
9564 if $entry & (0x1ULL << 63)
9572 set $kgm_pt_paddr = $arg0
9573 set $kgm_vaddr = $arg1
9574 set $kgm_pt_valid = $kgm_pt_paddr != 0
9575 set $kgm_pt_large = 0
9576 set $kgm_pframe_offset = 0
9577 if $kgm_pt_valid && cpu_64bit
9578 # Look up bits 47:39 of the linear address in PML4T
9579 set $kgm_pt_index = ($kgm_vaddr >> 39) & 0x1ffULL
9580 set $kgm_pframe_offset = $kgm_vaddr & 0x7fffffffffULL
9581 if $kgm_pt_verbose >= 2
9582 printf "pml4 (index %d):\n", $kgm_pt_index
9587 # Look up bits 38:30 of the linear address in PDPT
9588 set $kgm_pt_index = ($kgm_vaddr >> 30) & 0x1ffULL
9589 set $kgm_pframe_offset = $kgm_vaddr & 0x3fffffffULL
9590 if $kgm_pt_verbose >= 2
9591 printf "pdpt (index %d):\n", $kgm_pt_index
9595 if $kgm_pt_valid && !$kgm_pt_large
9596 # Look up bits 29:21 of the linear address in PDT
9597 set $kgm_pt_index = ($kgm_vaddr >> 21) & 0x1ffULL
9598 set $kgm_pframe_offset = $kgm_vaddr & 0x1fffffULL
9599 if $kgm_pt_verbose >= 2
9600 printf "pdt (index %d):\n", $kgm_pt_index
9604 if $kgm_pt_valid && !$kgm_pt_large
9605 # Look up bits 20:21 of the linear address in PT
9606 set $kgm_pt_index = ($kgm_vaddr >> 12) & 0x1ffULL
9607 set $kgm_pframe_offset = $kgm_vaddr & 0xfffULL
9608 if $kgm_pt_verbose >= 2
9609 printf "pt (index %d):\n", $kgm_pt_index
9615 set $kgm_paddr = $kgm_pt_paddr + $kgm_pframe_offset
9616 set $kgm_paddr_isvalid = 1
9619 set $kgm_paddr_isvalid = 0
9622 if $kgm_pt_verbose >= 1
9623 if $kgm_paddr_isvalid
9624 readphysint $kgm_paddr 32 $kgm_lcpu_self
9625 set $kgm_value = $kgm_readphysint_result
9626 printf "phys 0x%016llx: 0x%08x\n", $kgm_paddr, $kgm_value
9628 printf "(no translation)\n"
9633 define _pmap_walk_x86
9634 set $kgm_pmap = (pmap_t) $arg0
9635 _pml4_walk $kgm_pmap->pm_cr3 $arg1
9638 define _pmap_walk_arm
9640 set $kgm_paddr_isvalid = 0
9645 printf "pmap_walk <pmap> <vaddr>\n"
9648 set $kgm_pt_verbose = 2
9650 if $kgm_pt_verbose > 3
9651 set $kgm_pt_verbose = 2
9654 if (($kgm_mtype & $kgm_mtype_x86_mask) == $kgm_mtype_x86_any)
9655 _pmap_walk_x86 $arg0 $arg1
9657 if ($kgm_mtype == $kgm_mtype_arm)
9658 _pmap_walk_arm $arg0 $arg1
9660 printf "Not available for current architecture.\n"
9667 Syntax: (gdb) pmap_walk <pmap> <virtual_address>
9668 | Perform a page-table walk in <pmap> for <virtual_address>.
9670 | $kgm_pt_verbose=0 for no output, $kgm_paddr will be set
9671 | if $kgm_paddr_isvalid is 1
9672 | $kgm_pt_verbose=1 for final physical address
9673 | $kgm_pt_verbose=2 for dump of page table entry.
9674 | $kgm_pt_verbose=3 for full hex dump of page tables.
9679 printf "pmap_vtop <pamp> <vaddr>\n"
9681 set $kgm_pt_verbose = 1
9682 if (($kgm_mtype & $kgm_mtype_x86_mask) == $kgm_mtype_x86_any)
9683 _pmap_walk_x86 $arg0 $arg1
9685 if ($kgm_mtype == $kgm_mtype_arm)
9686 _pmap_walk_arm $arg0 $arg1
9688 printf "Not available for current architecture.\n"
9695 Syntax: (gdb) pmap_vtop <pmap> <virtual_address>
9696 | For page-tables in <pmap> translate <virtual_address> to physical address.
9702 if (log_records == 0)
9704 printf "Zone logging not enabled. Add 'zlog=<zone name>' to boot-args.\n"
9714 printf "\n--------------- "
9716 if (zrecords[$index].z_opcode == 1)
9722 printf " 0x%x : index %d : ztime %d -------------\n", zrecords[$index].z_element, $index, zrecords[$index].z_time
9727 set $frame_pc = zrecords[$index].z_pc[$frame]
9734 set $frame = $frame + 1
9737 set $index = $index + 1
9738 set $count = $count - 1
9743 Syntax: (gdb) zstack <index> [<count>]
9744 | Zone leak debugging: print the stack trace of log element at <index>.
9745 | If a <count> is supplied, it prints <count> log elements starting at <index>.
9747 | The suggested usage is to look at indexes below zcurrent and look for common stack traces.
9748 | The stack trace that occurs the most is probably the cause of the leak. Find the pc of the
9749 | function calling into zalloc and use the countpcs kgmacro to find out how often that pc occurs in the log.
9750 | The pc occuring in a high percentage of records is most likely the source of the leak.
9752 | The findoldest kgmacro is also useful for leak debugging since it identifies the oldest record
9753 | in the log, which may indicate the leaker.
9758 set $count = log_records
9759 set $cur_min = 2000000000
9762 if (log_records == 0)
9763 printf "Zone logging not enabled. Add 'zlog=<zone name>' to boot-args.\n"
9767 if (zrecords[$index].z_element && zrecords[$index].z_time < $cur_min)
9768 set $cur_index = $index
9769 set $cur_min = zrecords[$index].z_time
9772 set $count = $count - 1
9773 set $index = $index + 1
9776 printf "oldest record is at log index %d:\n", $cur_index
9782 Syntax: (gdb) findoldest
9783 | Zone leak debugging: find and print the oldest record in the log. Note that this command
9784 | can take several minutes to run since it uses linear search.
9786 | Once it prints a stack trace, find the pc of the caller above all the zalloc, kalloc and
9787 | IOKit layers. Then use the countpcs kgmacro to see how often this caller has allocated
9788 | memory. A caller with a high percentage of records in the log is probably the leaker.
9792 set $target_pc = $arg0
9794 set $count = log_records
9797 if (log_records == 0)
9798 printf "Zone logging not enabled. Add 'zlog=<zone name>' to boot-args.\n"
9804 if (zrecords[$index].z_element != 0)
9806 if (zrecords[$index].z_pc[$frame] == $target_pc)
9807 set $found = $found + 1
9811 set $frame = $frame + 1
9815 set $index = $index + 1
9816 set $count = $count - 1
9819 printf "occurred %d times in log (%d%c of records)\n", $found, ($found * 100) / zrecorded, '%'
9824 Syntax: (gdb) countpcs <pc>
9825 | Zone leak debugging: search the log and print a count of all log entries that contain the given <pc>
9826 | in the stack trace. This is useful for verifying a suspected <pc> as being the source of
9827 | the leak. If a high percentage of the log entries contain the given <pc>, then it's most
9828 | likely the source of the leak. Note that this command can take several minutes to run.
9832 set $fe_index = zcurrent
9833 set $fe_count = log_records
9834 set $fe_elem = $arg0
9835 set $fe_prev_op = -1
9837 if (log_records == 0)
9838 printf "Zone logging not enabled. Add 'zlog=<zone name>' to boot-args.\n"
9842 if (zrecords[$fe_index].z_element == $fe_elem)
9845 if (zrecords[$fe_index].z_opcode == $fe_prev_op)
9846 printf "*************** DOUBLE OP! *********************\n
9849 set $fe_prev_op = zrecords[$fe_index].z_opcode
9852 set $fe_count = $fe_count - 1
9853 set $fe_index = $fe_index + 1
9855 if ($fe_index >= log_records)
9862 Syntax: (gdb) findelem <elem addr>
9863 | Zone corruption debugging: search the log and print out the stack traces for all log entries that
9864 | refer to the given zone element. When the kernel panics due to a corrupted zone element, get the
9865 | element address and use this macro. This will show you the stack traces of all logged zalloc and
9866 | zfree operations which tells you who touched the element in the recent past. This also makes
9867 | double-frees readily apparent.
9871 # This implements a shadowing scheme in kgmacros. If the
9872 # current user data can be accessed by simply changing kdp_pmap,
9873 # that is used. Otherwise, we copy data into a temporary buffer
9874 # in the kernel's address space and use that instead. Don't rely on
9875 # kdp_pmap between invocations of map/unmap. Since the shadow
9876 # codepath uses a manual KDP packet, request no more than 128 bytes.
9877 # Uses $kgm_lp64 for kernel address space size, and
9878 # $kgm_readphys_use_kdp/$kgm_readphys_force_physmap to override
9879 # how the user pages are accessed ($kgm_readphys_force_physmap
9880 # implies walking the user task's pagetables to get a physical
9881 # address and then shadowing data from there using the
9882 # physical mapping of memory).
9883 define _map_user_data_from_task
9884 set $kgm_map_user_taskp = (task_t)$arg0
9885 set $kgm_map_user_map = $kgm_map_user_taskp->map
9886 set $kgm_map_user_pmap = $kgm_map_user_map->pmap
9887 set $kgm_map_user_task_64 = ( $kgm_map_user_taskp->taskFeatures[0] & 0x80000000)
9888 set $kgm_map_user_window = 0
9889 set $kgm_map_switch_map = 0
9891 if ($kgm_readphys_force_kdp != 0)
9892 set $kgm_readphys_use_kdp = 1
9894 if ($kgm_readphys_force_physmap)
9895 set $kgm_readphys_use_kdp = 0
9897 set $kgm_readphys_use_kdp = ( kdp->is_conn > 0 )
9901 if ($kgm_readphys_use_kdp)
9904 set $kgm_map_switch_map = 1
9906 if !$kgm_map_user_task_64
9907 set $kgm_map_switch_map = 1
9911 if ($kgm_map_switch_map)
9912 # switch the map safely
9913 set $kgm_map_user_window = $arg1
9914 set kdp_pmap = $kgm_map_user_pmap
9916 # requires shadowing/copying
9918 # set up the manual KDP packet
9919 set manual_pkt.input = 0
9920 set manual_pkt.len = sizeof(kdp_readmem64_req_t)
9921 set $kgm_pkt = (kdp_readmem64_req_t *)&manual_pkt.data
9922 set $kgm_pkt->hdr.request = KDP_READMEM64
9923 set $kgm_pkt->hdr.len = sizeof(kdp_readmem64_req_t)
9924 set $kgm_pkt->hdr.is_reply = 0
9925 set $kgm_pkt->hdr.seq = 0
9926 set $kgm_pkt->hdr.key = 0
9927 set $kgm_pkt->address = (uint64_t)$arg1
9928 set $kgm_pkt->nbytes = (uint32_t)$arg2
9930 set kdp_pmap = $kgm_map_user_pmap
9931 set manual_pkt.input = 1
9932 # dummy to make sure manual packet is executed
9933 set $kgm_dummy = &_mh_execute_header
9934 # Go back to kernel map so that we can access buffer directly
9937 set $kgm_pkt = (kdp_readmem64_reply_t *)&manual_pkt.data
9938 if ($kgm_pkt->error == 0)
9939 set $kgm_map_user_window = $kgm_pkt->data
9941 set $kgm_map_user_window = 0
9946 # without the benefit of a KDP stub on the target, try to
9947 # find the user task's physical mapping and memcpy the data.
9948 # If it straddles a page boundary, copy in two passes
9949 set $kgm_vaddr_range1_start = (unsigned long long)$arg1
9950 set $kgm_vaddr_range1_count = (unsigned long long)$arg2
9951 if (($kgm_vaddr_range1_start + $kgm_vaddr_range1_count) & 0xFFF) < $kgm_vaddr_range1_count
9952 set $kgm_vaddr_range2_start = ($kgm_vaddr_range1_start + $kgm_vaddr_range1_count) & ~((unsigned long long)0xFFF)
9953 set $kgm_vaddr_range2_count = $kgm_vaddr_range1_start + $kgm_vaddr_range1_count - $kgm_vaddr_range2_start
9954 set $kgm_vaddr_range1_count = $kgm_vaddr_range2_start - $kgm_vaddr_range1_start
9956 set $kgm_vaddr_range2_start = 0
9957 set $kgm_vaddr_range2_count = 0
9959 set $kgm_paddr_range1_in_kva = 0
9960 set $kgm_paddr_range2_in_kva = 0
9962 if ($kgm_mtype == $kgm_mtype_x86_64)
9963 set $kgm_pt_verbose = 0
9964 _pmap_walk_x86 $kgm_map_user_pmap $kgm_vaddr_range1_start
9965 if $kgm_paddr_isvalid
9966 set $kgm_paddr_range1_in_kva = $kgm_paddr + (((unsigned long long)-1 << 47) | ((unsigned long long)509 << 39))
9968 if $kgm_vaddr_range2_start
9969 _pmap_walk_x86 $kgm_map_user_pmap $kgm_vaddr_range2_start
9970 if $kgm_paddr_isvalid
9971 set $kgm_paddr_range2_in_kva = $kgm_paddr + (((unsigned long long)-1 << 47) | ((unsigned long long)509 << 39))
9975 if ($kgm_mtype == $kgm_mtype_arm)
9976 set $kgm_pt_verbose = 0
9977 _pmap_walk_arm $kgm_map_user_pmap $kgm_vaddr_range1_start
9978 if $kgm_paddr_isvalid
9979 set $kgm_paddr_range1_in_kva = $kgm_paddr - gPhysBase + gVirtBase
9981 if $kgm_vaddr_range2_start
9982 _pmap_walk_arm $kgm_map_user_pmap $kgm_vaddr_range2_start
9983 if $kgm_paddr_isvalid
9984 set $kgm_paddr_range2_in_kva = $kgm_paddr - gPhysBase + gVirtBase
9988 printf "Not available for current architecture.\n"
9989 set $kgm_paddr_isvalid = 0
9992 if $kgm_paddr_range1_in_kva
9993 set $kgm_pkt = (kdp_readmem64_reply_t *)&manual_pkt.data
9994 memcpy $kgm_pkt->data $kgm_paddr_range1_in_kva $kgm_vaddr_range1_count
9995 if $kgm_paddr_range2_in_kva
9996 memcpy &$kgm_pkt->data[$kgm_vaddr_range1_count] $kgm_paddr_range2_in_kva $kgm_vaddr_range2_count
9998 set $kgm_map_user_window = $kgm_pkt->data
10000 set $kgm_map_user_window = 0
10005 define _unmap_user_data_from_task
10009 # uses $kgm_taskp. Maps 32 bytes at a time and prints it
10010 define _print_path_for_image
10011 set $kgm_print_path_address = (unsigned long long)$arg0
10012 set $kgm_path_str_notdone = 1
10014 if ($kgm_print_path_address == 0)
10015 set $kgm_path_str_notdone = 0
10018 while $kgm_path_str_notdone
10019 _map_user_data_from_task $kgm_taskp $kgm_print_path_address 32
10021 set $kgm_print_path_ptr = (char *)$kgm_map_user_window
10022 set $kgm_path_i = 0
10023 while ($kgm_path_i < 32 && $kgm_print_path_ptr[$kgm_path_i] != '\0')
10024 set $kgm_path_i = $kgm_path_i + 1
10026 printf "%.32s", $kgm_print_path_ptr
10028 _unmap_user_data_from_task $kgm_taskp
10030 # break out if we terminated on NUL
10031 if $kgm_path_i < 32
10032 set $kgm_path_str_notdone = 0
10034 set $kgm_print_path_address = $kgm_print_path_address + 32
10039 # uses $kgm_taskp and $kgm_task_64. May modify $kgm_dyld_load_path
10040 define _print_image_info
10041 set $kgm_mh_image_address = (unsigned long long)$arg0
10042 set $kgm_mh_path_address = (unsigned long long)$arg1
10044 # 32 bytes enough for mach_header/mach_header_64
10045 _map_user_data_from_task $kgm_taskp $kgm_mh_image_address 32
10047 set $kgm_mh_ptr = (unsigned int*)$kgm_map_user_window
10048 set $kgm_mh_magic = $kgm_mh_ptr[0]
10049 set $kgm_mh_cputype = $kgm_mh_ptr[1]
10050 set $kgm_mh_cpusubtype = $kgm_mh_ptr[2]
10051 set $kgm_mh_filetype = $kgm_mh_ptr[3]
10052 set $kgm_mh_ncmds = $kgm_mh_ptr[4]
10053 set $kgm_mh_sizeofcmds = $kgm_mh_ptr[5]
10054 set $kgm_mh_flags = $kgm_mh_ptr[6]
10056 _unmap_user_data_from_task $kgm_taskp
10058 if $kgm_mh_magic == 0xfeedfacf
10060 set $kgm_lc_address = $kgm_mh_image_address + 32
10063 set $kgm_lc_address = $kgm_mh_image_address + 28
10066 set $kgm_lc_idx = 0
10067 set $kgm_uuid_data = 0
10068 while $kgm_lc_idx < $kgm_mh_ncmds
10070 # 24 bytes is size of uuid_command
10071 _map_user_data_from_task $kgm_taskp $kgm_lc_address 24
10073 set $kgm_lc_ptr = (unsigned int *)$kgm_map_user_window
10074 set $kgm_lc_cmd = $kgm_lc_ptr[0]
10075 set $kgm_lc_cmd_size = $kgm_lc_ptr[1]
10076 set $kgm_lc_data = (unsigned char *)$kgm_lc_ptr + 8
10078 if $kgm_lc_cmd == 0x1b
10079 set $kgm_uuid_data = $kgm_lc_data
10081 printf "0x%016llx ", $kgm_mh_image_address
10083 printf "0x%08x ", $kgm_mh_image_address
10086 set $kgm_printed_type = 0
10087 if $kgm_mh_filetype == 0x2
10088 printf "MH_EXECUTE "
10089 set $kgm_printed_type = 1
10091 if $kgm_mh_filetype == 0x6
10093 set $kgm_printed_type = 1
10095 if $kgm_mh_filetype == 0x7
10096 printf "MH_DYLINKER "
10097 set $kgm_printed_type = 1
10099 if $kgm_mh_filetype == 0x8
10100 printf "MH_BUNDLE "
10101 set $kgm_printed_type = 1
10103 if !$kgm_printed_type
10106 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]
10107 printf "%02.2X%02.2X-", $kgm_uuid_data[4], $kgm_uuid_data[5]
10108 printf "%02.2X%02.2X-", $kgm_uuid_data[6], $kgm_uuid_data[7]
10109 printf "%02.2X%02.2X-", $kgm_uuid_data[8], $kgm_uuid_data[9]
10110 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]
10112 _unmap_user_data_from_task $kgm_taskp
10115 _print_path_for_image $kgm_mh_path_address
10120 if $kgm_lc_cmd == 0xe
10121 set $kgm_load_dylinker_data = $kgm_lc_data
10122 set $kgm_dyld_load_path = $kgm_lc_address + *((unsigned int *)$kgm_load_dylinker_data)
10124 _unmap_user_data_from_task $kgm_taskp
10127 set $kgm_lc_address = $kgm_lc_address + $kgm_lc_cmd_size
10128 set $kgm_lc_idx = $kgm_lc_idx + 1
10131 if (!$kgm_uuid_data)
10132 # didn't find LC_UUID, for a dylib, just print out basic info
10134 printf "0x%016llx ", $kgm_mh_image_address
10136 printf "0x%08x ", $kgm_mh_image_address
10138 set $kgm_printed_type = 0
10139 if $kgm_mh_filetype == 0x2
10140 printf "MH_EXECUTE "
10141 set $kgm_printed_type = 1
10143 if $kgm_mh_filetype == 0x6
10145 set $kgm_printed_type = 1
10147 if $kgm_mh_filetype == 0x7
10148 printf "MH_DYLINKER "
10149 set $kgm_printed_type = 1
10151 if $kgm_mh_filetype == 0x8
10152 printf "MH_BUNDLE "
10153 set $kgm_printed_type = 1
10155 if !$kgm_printed_type
10161 _print_path_for_image $kgm_mh_path_address
10168 define _print_images_for_dyld_image_info
10169 set $kgm_taskp = $arg0
10170 set $kgm_task_64 = $arg1
10171 set $kgm_dyld_all_image_infos_address = (unsigned long long)$arg2
10173 _map_user_data_from_task $kgm_taskp $kgm_dyld_all_image_infos_address 112
10175 set $kgm_dyld_all_image_infos = (unsigned int *)$kgm_map_user_window
10176 set $kgm_dyld_all_image_infos_version = $kgm_dyld_all_image_infos[0]
10177 if ($kgm_dyld_all_image_infos_version > 12)
10178 printf "Unknown dyld all_image_infos version number %d\n", $kgm_dyld_all_image_infos_version
10180 set $kgm_image_info_count = $kgm_dyld_all_image_infos[1]
10182 set $kgm_dyld_load_path = 0
10184 set $kgm_image_info_size = 24
10185 set $kgm_image_info_array_address = ((unsigned long long *)$kgm_dyld_all_image_infos)[1]
10186 set $kgm_dyld_load_address = ((unsigned long long *)$kgm_dyld_all_image_infos)[4]
10188 set $kgm_image_info_size = 12
10189 set $kgm_image_info_array_address = ((unsigned int *)$kgm_dyld_all_image_infos)[2]
10190 set $kgm_dyld_load_address = ((unsigned int *)$kgm_dyld_all_image_infos)[5]
10193 _unmap_user_data_from_task $kgm_taskp
10195 set $kgm_image_info_i = 0
10196 while $kgm_image_info_i < $kgm_image_info_count
10198 set $kgm_image_info_address = $kgm_image_info_array_address + $kgm_image_info_size*$kgm_image_info_i
10200 _map_user_data_from_task $kgm_taskp $kgm_image_info_address $kgm_image_info_size
10202 set $kgm_image_info_addr = ((unsigned long long *)$kgm_map_user_window)[0]
10203 set $kgm_image_info_path = ((unsigned long long *)$kgm_map_user_window)[1]
10205 set $kgm_image_info_addr = ((unsigned int *)$kgm_map_user_window)[0]
10206 set $kgm_image_info_path = ((unsigned int *)$kgm_map_user_window)[1]
10208 _unmap_user_data_from_task $kgm_taskp
10210 # printf "[%d] = image address %llx path address %llx\n", $kgm_image_info_i, $kgm_image_info_addr, $kgm_image_info_path
10211 _print_image_info $kgm_image_info_addr $kgm_image_info_path
10213 set $kgm_image_info_i = $kgm_image_info_i + 1
10216 # $kgm_dyld_load_path may get set when the main executable is processed
10217 # printf "[dyld] = image address %llx path address %llx\n", $kgm_dyld_load_address, $kgm_dyld_load_path
10218 _print_image_info $kgm_dyld_load_address $kgm_dyld_load_path
10222 define showuserlibraries
10223 set $kgm_taskp = (task_t)$arg0
10224 set $kgm_dyld_image_info = $kgm_taskp->all_image_info_addr
10226 set $kgm_map = $kgm_taskp->map
10227 set $kgm_task_64 = ( $kgm_taskp->taskFeatures[0] & 0x80000000)
10229 if ($kgm_dyld_image_info != 0)
10238 _print_images_for_dyld_image_info $kgm_taskp $kgm_task_64 $kgm_dyld_image_info
10240 printf "No dyld shared library information available for task\n"
10243 document showuserlibraries
10244 Syntax: (gdb) showuserlibraries <task_t>
10245 | For a given user task, inspect the dyld shared library state and print
10246 | information about all Mach-O images.
10249 define showuserdyldinfo
10250 set $kgm_taskp = (task_t)$arg0
10251 set $kgm_dyld_all_image_infos_address = (unsigned long long)$kgm_taskp->all_image_info_addr
10253 set $kgm_map = $kgm_taskp->map
10254 set $kgm_task_64 = ( $kgm_taskp->taskFeatures[0] & 0x80000000)
10256 if ($kgm_dyld_all_image_infos_address != 0)
10258 _map_user_data_from_task $kgm_taskp $kgm_dyld_all_image_infos_address 112
10260 set $kgm_dyld_all_image_infos = (unsigned char *)$kgm_map_user_window
10261 set $kgm_dyld_all_image_infos_version = ((unsigned int *)$kgm_dyld_all_image_infos)[0]
10262 if ($kgm_dyld_all_image_infos_version > 12)
10263 printf "Unknown dyld all_image_infos version number %d\n", $kgm_dyld_all_image_infos_version
10266 # Find fields by byte offset. We assume at least version 9 is supported
10268 set $kgm_dyld_all_image_infos_infoArrayCount = *(unsigned int *)(&$kgm_dyld_all_image_infos[4])
10269 set $kgm_dyld_all_image_infos_infoArray = *(unsigned long long *)(&$kgm_dyld_all_image_infos[8])
10270 set $kgm_dyld_all_image_infos_notification = *(unsigned long long *)(&$kgm_dyld_all_image_infos[16])
10271 set $kgm_dyld_all_image_infos_processDetachedFromSharedRegion = *(unsigned char *)(&$kgm_dyld_all_image_infos[24])
10272 set $kgm_dyld_all_image_infos_libSystemInitialized = *(unsigned char *)(&$kgm_dyld_all_image_infos[25])
10273 set $kgm_dyld_all_image_infos_dyldImageLoadAddress = *(unsigned long long *)(&$kgm_dyld_all_image_infos[32])
10274 set $kgm_dyld_all_image_infos_jitInfo = *(unsigned long long *)(&$kgm_dyld_all_image_infos[40])
10275 set $kgm_dyld_all_image_infos_dyldVersion = *(unsigned long long *)(&$kgm_dyld_all_image_infos[48])
10276 set $kgm_dyld_all_image_infos_errorMessage = *(unsigned long long *)(&$kgm_dyld_all_image_infos[56])
10277 set $kgm_dyld_all_image_infos_terminationFlags = *(unsigned long long *)(&$kgm_dyld_all_image_infos[64])
10278 set $kgm_dyld_all_image_infos_coreSymbolicationShmPage = *(unsigned long long *)(&$kgm_dyld_all_image_infos[72])
10279 set $kgm_dyld_all_image_infos_systemOrderFlag = *(unsigned long long *)(&$kgm_dyld_all_image_infos[80])
10280 set $kgm_dyld_all_image_infos_uuidArrayCount = *(unsigned long long *)(&$kgm_dyld_all_image_infos[88])
10281 set $kgm_dyld_all_image_infos_uuidArray = *(unsigned long long *)(&$kgm_dyld_all_image_infos[96])
10282 set $kgm_dyld_all_image_infos_dyldAllImageInfosAddress = *(unsigned long long *)(&$kgm_dyld_all_image_infos[104])
10284 set $kgm_dyld_all_image_infos_infoArrayCount = *(unsigned int *)(&$kgm_dyld_all_image_infos[4])
10285 set $kgm_dyld_all_image_infos_infoArray = *(unsigned int *)(&$kgm_dyld_all_image_infos[8])
10286 set $kgm_dyld_all_image_infos_notification = *(unsigned int *)(&$kgm_dyld_all_image_infos[12])
10287 set $kgm_dyld_all_image_infos_processDetachedFromSharedRegion = *(unsigned char *)(&$kgm_dyld_all_image_infos[16])
10288 set $kgm_dyld_all_image_infos_libSystemInitialized = *(unsigned char *)(&$kgm_dyld_all_image_infos[17])
10289 set $kgm_dyld_all_image_infos_dyldImageLoadAddress = *(unsigned int *)(&$kgm_dyld_all_image_infos[20])
10290 set $kgm_dyld_all_image_infos_jitInfo = *(unsigned int *)(&$kgm_dyld_all_image_infos[24])
10291 set $kgm_dyld_all_image_infos_dyldVersion = *(unsigned int *)(&$kgm_dyld_all_image_infos[28])
10292 set $kgm_dyld_all_image_infos_errorMessage = *(unsigned int *)(&$kgm_dyld_all_image_infos[32])
10293 set $kgm_dyld_all_image_infos_terminationFlags = *(unsigned int *)(&$kgm_dyld_all_image_infos[36])
10294 set $kgm_dyld_all_image_infos_coreSymbolicationShmPage = *(unsigned int *)(&$kgm_dyld_all_image_infos[40])
10295 set $kgm_dyld_all_image_infos_systemOrderFlag = *(unsigned int *)(&$kgm_dyld_all_image_infos[44])
10296 set $kgm_dyld_all_image_infos_uuidArrayCount = *(unsigned int *)(&$kgm_dyld_all_image_infos[48])
10297 set $kgm_dyld_all_image_infos_uuidArray = *(unsigned int *)(&$kgm_dyld_all_image_infos[52])
10298 set $kgm_dyld_all_image_infos_dyldAllImageInfosAddress = *(unsigned int *)(&$kgm_dyld_all_image_infos[56])
10301 _unmap_user_data_from_task $kgm_taskp
10303 printf " version %u\n", $kgm_dyld_all_image_infos_version
10304 printf " infoArrayCount %u\n", $kgm_dyld_all_image_infos_infoArrayCount
10305 printf " infoArray "
10306 showuserptr $kgm_dyld_all_image_infos_infoArray
10308 printf " notification "
10309 showuserptr $kgm_dyld_all_image_infos_notification
10311 printf "processDetachedFromSharedRegion %d\n", $kgm_dyld_all_image_infos_processDetachedFromSharedRegion
10312 printf " libSystemInitialized %d\n", $kgm_dyld_all_image_infos_libSystemInitialized
10313 printf " dyldImageLoadAddress "
10314 showuserptr $kgm_dyld_all_image_infos_dyldImageLoadAddress
10317 showuserptr $kgm_dyld_all_image_infos_jitInfo
10319 printf " dyldVersion "
10320 showuserptr $kgm_dyld_all_image_infos_dyldVersion
10323 _print_path_for_image $kgm_dyld_all_image_infos_dyldVersion
10326 printf " errorMessage "
10327 showuserptr $kgm_dyld_all_image_infos_errorMessage
10329 if $kgm_dyld_all_image_infos_errorMessage != 0
10331 _print_path_for_image $kgm_dyld_all_image_infos_errorMessage
10335 printf " terminationFlags "
10336 showuserptr $kgm_dyld_all_image_infos_terminationFlags
10338 printf " coreSymbolicationShmPage "
10339 showuserptr $kgm_dyld_all_image_infos_coreSymbolicationShmPage
10341 printf " systemOrderFlag "
10342 showuserptr $kgm_dyld_all_image_infos_systemOrderFlag
10344 printf " uuidArrayCount "
10345 showuserptr $kgm_dyld_all_image_infos_uuidArrayCount
10347 printf " uuidArray "
10348 showuserptr $kgm_dyld_all_image_infos_uuidArray
10350 printf " dyldAllImageInfosAddress "
10351 showuserptr $kgm_dyld_all_image_infos_dyldAllImageInfosAddress
10353 printf " (currently "
10354 showuserptr $kgm_dyld_all_image_infos_address
10358 set $kgm_dyld_all_image_infos_address = $kgm_dyld_all_image_infos_address + 112
10359 _map_user_data_from_task $kgm_taskp $kgm_dyld_all_image_infos_address 64
10360 set $kgm_dyld_all_image_infos_v10 = (unsigned char *)$kgm_map_user_window
10361 set $kgm_dyld_all_image_infos_initialImageCount = *(unsigned long long *)(&$kgm_dyld_all_image_infos_v10[112-112])
10362 set $kgm_dyld_all_image_infos_errorKind = *(unsigned long long *)(&$kgm_dyld_all_image_infos_v10[120-112])
10363 set $kgm_dyld_all_image_infos_errorClientOfDylibPath = *(unsigned long long *)(&$kgm_dyld_all_image_infos_v10[128-112])
10364 set $kgm_dyld_all_image_infos_errorTargetDylibPath = *(unsigned long long *)(&$kgm_dyld_all_image_infos_v10[136-112])
10365 set $kgm_dyld_all_image_infos_errorSymbol = *(unsigned long long *)(&$kgm_dyld_all_image_infos_v10[144-112])
10366 set $kgm_dyld_all_image_infos_sharedCacheSlide = *(unsigned long long *)(&$kgm_dyld_all_image_infos_v10[152-112])
10368 _unmap_user_data_from_task $kgm_taskp
10370 set $kgm_dyld_all_image_infos_address = $kgm_dyld_all_image_infos_address + 60
10371 _map_user_data_from_task $kgm_taskp $kgm_dyld_all_image_infos_address 64
10372 set $kgm_dyld_all_image_infos_v10 = (unsigned char *)$kgm_map_user_window
10373 set $kgm_dyld_all_image_infos_initialImageCount = *(unsigned int *)(&$kgm_dyld_all_image_infos_v10[60-60])
10374 set $kgm_dyld_all_image_infos_errorKind = *(unsigned int *)(&$kgm_dyld_all_image_infos_v10[64-60])
10375 set $kgm_dyld_all_image_infos_errorClientOfDylibPath = *(unsigned int *)(&$kgm_dyld_all_image_infos_v10[68-60])
10376 set $kgm_dyld_all_image_infos_errorTargetDylibPath = *(unsigned int *)(&$kgm_dyld_all_image_infos_v10[72-60])
10377 set $kgm_dyld_all_image_infos_errorSymbol = *(unsigned int *)(&$kgm_dyld_all_image_infos_v10[76-60])
10378 set $kgm_dyld_all_image_infos_sharedCacheSlide = *(unsigned int *)(&$kgm_dyld_all_image_infos_v10[80-60])
10379 _unmap_user_data_from_task $kgm_taskp
10382 if $kgm_dyld_all_image_infos_version >= 10
10383 printf " initialImageCount "
10384 showuserptr $kgm_dyld_all_image_infos_initialImageCount
10388 if $kgm_dyld_all_image_infos_version >= 11
10389 printf " errorKind "
10390 showuserptr $kgm_dyld_all_image_infos_errorKind
10392 printf " errorClientOfDylibPath "
10393 showuserptr $kgm_dyld_all_image_infos_errorClientOfDylibPath
10395 if $kgm_dyld_all_image_infos_errorClientOfDylibPath != 0
10397 _print_path_for_image $kgm_dyld_all_image_infos_errorClientOfDylibPath
10400 printf " errorTargetDylibPath "
10401 showuserptr $kgm_dyld_all_image_infos_errorTargetDylibPath
10403 if $kgm_dyld_all_image_infos_errorTargetDylibPath != 0
10405 _print_path_for_image $kgm_dyld_all_image_infos_errorTargetDylibPath
10408 printf " errorSymbol "
10409 showuserptr $kgm_dyld_all_image_infos_errorSymbol
10411 if $kgm_dyld_all_image_infos_errorSymbol != 0
10413 _print_path_for_image $kgm_dyld_all_image_infos_errorSymbol
10418 if $kgm_dyld_all_image_infos_version >= 12
10419 printf " sharedCacheSlide "
10420 showuserptr $kgm_dyld_all_image_infos_sharedCacheSlide
10425 printf "No dyld information available for task\n"
10428 document showuserdyldinfo
10429 Syntax: (gdb) showuserdyldinfo <task_t>
10430 | For a given user task, inspect the dyld global info and print
10431 | out all fields, including error messages.
10434 define showkerneldebugheader
10437 printf "CPU Thread "
10439 printf "Timestamp S/E Class Sub Code Code Specific Info\n"
10442 define _printevflags
10457 printf "EV_RBYTES "
10460 printf "EV_WBYTES "
10463 printf "EV_RCLOSED "
10469 printf "EV_WCLOSED "
10484 printf "EV_TIMEOUT "
10488 define showkerneldebugbufferentry
10489 set $kgm_kdebug_entry = (kd_buf *) $arg0
10491 set $kgm_debugid = $kgm_kdebug_entry->debugid
10492 set $kgm_kdebug_arg1 = $kgm_kdebug_entry->arg1
10493 set $kgm_kdebug_arg2 = $kgm_kdebug_entry->arg2
10494 set $kgm_kdebug_arg3 = $kgm_kdebug_entry->arg3
10495 set $kgm_kdebug_arg4 = $kgm_kdebug_entry->arg4
10498 set $kgm_kdebug_cpu = $kgm_kdebug_entry->cpuid
10499 set $kgm_ts_hi = ($kgm_kdebug_entry->timestamp >> 32) & 0xFFFFFFFF
10500 set $kgm_ts_lo = $kgm_kdebug_entry->timestamp & 0xFFFFFFFF
10502 set $kgm_kdebug_cpu = ($kgm_kdebug_entry->timestamp >> 56)
10503 set $kgm_ts_hi = ($kgm_kdebug_entry->timestamp >> 32) & 0x00FFFFFF
10504 set $kgm_ts_lo = $kgm_kdebug_entry->timestamp & 0xFFFFFFFF
10507 set $kgm_kdebug_class = ($kgm_debugid >> 24) & 0x000FF
10508 set $kgm_kdebug_subclass = ($kgm_debugid >> 16) & 0x000FF
10509 set $kgm_kdebug_code = ($kgm_debugid >> 2) & 0x03FFF
10510 set $kgm_kdebug_qual = ($kgm_debugid ) & 0x00003
10512 if $kgm_kdebug_qual == 0
10513 set $kgm_kdebug_qual = '-'
10515 if $kgm_kdebug_qual == 1
10516 set $kgm_kdebug_qual = 'S'
10518 if $kgm_kdebug_qual == 2
10519 set $kgm_kdebug_qual = 'E'
10521 if $kgm_kdebug_qual == 3
10522 set $kgm_kdebug_qual = '?'
10528 # preamble and qual
10530 showptr $kgm_kdebug_entry
10531 printf " %d ", $kgm_kdebug_cpu
10532 showptr $kgm_kdebug_entry->arg5
10533 printf " 0x%08X%08X %c ", $kgm_ts_hi, $kgm_ts_lo, $kgm_kdebug_qual
10537 if $kgm_kdebug_class == 1
10540 if $kgm_kdebug_class == 2
10543 if $kgm_kdebug_class == 3
10546 if $kgm_kdebug_class == 4
10549 if $kgm_kdebug_class == 5
10552 if $kgm_kdebug_class == 6
10555 if $kgm_kdebug_class == 7
10558 if $kgm_kdebug_class == 8
10561 if $kgm_kdebug_class == 8
10564 if $kgm_kdebug_class == 20
10567 if $kgm_kdebug_class == 31
10570 if $kgm_kdebug_class == 32
10573 if $kgm_kdebug_class == 33
10576 if $kgm_kdebug_class == 255
10579 printf "0x%02X", $kgm_kdebug_class
10595 # subclass and code
10597 printf " 0x%02X %5d ", $kgm_kdebug_subclass, $kgm_kdebug_code
10599 # space for debugid-specific processing
10601 # EVPROC from bsd/kern/sys_generic.c
10603 # MISCDBG_CODE(DBG_EVENT,DBG_WAIT)
10604 if $kgm_debugid == 0x14100048
10605 printf "waitevent "
10606 if $kgm_kdebug_arg1 == 1
10607 printf "before sleep"
10609 if $kgm_kdebug_arg1 == 2
10610 printf "after sleep"
10612 printf "????????????"
10615 printf " chan=0x%08X ", $kgm_kdebug_arg2
10617 # MISCDBG_CODE(DBG_EVENT,DBG_WAIT|DBG_FUNC_START)
10618 if $kgm_debugid == 0x14100049
10619 printf "waitevent "
10621 # MISCDBG_CODE(DBG_EVENT,DBG_WAIT|DBG_FUNC_END)
10622 if $kgm_debugid == 0x1410004a
10623 printf "waitevent error=%d ", $kgm_kdebug_arg1
10624 printf "eqp=0x%08X ", $kgm_kdebug_arg4
10625 _printevflags $kgm_kdebug_arg3
10626 printf "er_handle=%d ", $kgm_kdebug_arg2
10628 # MISCDBG_CODE(DBG_EVENT,DBG_DEQUEUE|DBG_FUNC_START)
10629 if $kgm_debugid == 0x14100059
10630 printf "evprocdeque proc=0x%08X ", $kgm_kdebug_arg1
10631 if $kgm_kdebug_arg2 == 0
10632 printf "remove first "
10634 printf "remove 0x%08X ", $kgm_kdebug_arg2
10637 # MISCDBG_CODE(DBG_EVENT,DBG_DEQUEUE|DBG_FUNC_END)
10638 if $kgm_debugid == 0x1410005a
10639 printf "evprocdeque "
10640 if $kgm_kdebug_arg1 == 0
10641 printf "result=NULL "
10643 printf "result=0x%08X ", $kgm_kdebug_arg1
10646 # MISCDBG_CODE(DBG_EVENT,DBG_POST|DBG_FUNC_START)
10647 if $kgm_debugid == 0x14100041
10648 printf "postevent "
10649 _printevflags $kgm_kdebug_arg1
10651 # MISCDBG_CODE(DBG_EVENT,DBG_POST)
10652 if $kgm_debugid == 0x14100040
10653 printf "postevent "
10654 printf "evq=0x%08X ", $kgm_kdebug_arg1
10655 printf "er_eventbits="
10656 _printevflags $kgm_kdebug_arg2
10658 _printevflags $kgm_kdebug_arg3
10660 # MISCDBG_CODE(DBG_EVENT,DBG_POST|DBG_FUNC_END)
10661 if $kgm_debugid == 0x14100042
10662 printf "postevent "
10664 # MISCDBG_CODE(DBG_EVENT,DBG_ENQUEUE|DBG_FUNC_START)
10665 if $kgm_debugid == 0x14100055
10666 printf "evprocenque eqp=0x%08d ", $kgm_kdebug_arg1
10667 if $kgm_kdebug_arg2 & 1
10668 printf "EV_QUEUED "
10670 _printevflags $kgm_kdebug_arg3
10673 # MISCDBG_CODE(DBG_EVENT,DBG_EWAKEUP)
10674 if $kgm_debugid == 0x14100050
10675 printf "evprocenque before wakeup eqp=0x%08d ", $kgm_kdebug_arg4
10677 # MISCDBG_CODE(DBG_EVENT,DBG_ENQUEUE|DBG_FUNC_END)
10678 if $kgm_debugid == 0x14100056
10679 printf "evprocenque "
10681 # MISCDBG_CODE(DBG_EVENT,DBG_MOD|DBG_FUNC_START)
10682 if $kgm_debugid == 0x1410004d
10685 # MISCDBG_CODE(DBG_EVENT,DBG_MOD)
10686 if $kgm_debugid == 0x1410004c
10687 printf "modwatch er_handle=%d ", $kgm_kdebug_arg1
10688 _printevflags $kgm_kdebug_arg2
10689 printf "evq=0x%08X ", $kgm_kdebug_arg3
10691 # MISCDBG_CODE(DBG_EVENT,DBG_MOD|DBG_FUNC_END)
10692 if $kgm_debugid == 0x1410004e
10693 printf "modwatch er_handle=%d ", $kgm_kdebug_arg1
10694 printf "ee_eventmask="
10695 _printevflags $kgm_kdebug_arg2
10696 printf "sp=0x%08X ", $kgm_kdebug_arg3
10698 _printevflags $kgm_kdebug_arg4
10700 printf "arg1=0x%08X ", $kgm_kdebug_arg1
10701 printf "arg2=0x%08X ", $kgm_kdebug_arg2
10702 printf "arg3=0x%08X ", $kgm_kdebug_arg3
10703 printf "arg4=0x%08X ", $kgm_kdebug_arg4
10724 define showkerneldebugbuffercpu
10725 set $kgm_cpu_number = (int) $arg0
10726 set $kgm_entry_count = (int) $arg1
10727 set $kgm_debugentriesfound = 0
10729 if (kdebug_flags & 0x80000000) # 0x80000000 == KDBG_BFINIT
10730 showkerneldebugheader
10732 if $kgm_entry_count == 0
10733 printf "<count> is 0, dumping 50 entries\n"
10734 set $kgm_entry_count = 50
10737 if $kgm_cpu_number >= kd_cpus
10738 printf "cpu number too big\n"
10740 set $kgm_kdbp = &kdbip[$kgm_cpu_number]
10741 set $kgm_kdsp = $kgm_kdbp->kd_list_head
10742 while (($kgm_kdsp != 0) && ($kgm_entry_count > 0))
10743 if $kgm_kdsp->kds_readlast != $kgm_kdsp->kds_bufptr
10744 set $kgm_kds_bufptr = $kgm_kdsp->kds_bufptr
10745 while (($kgm_kds_bufptr > $kgm_kdsp->kds_readlast) && ($kgm_entry_count > 0))
10746 set $kgm_kds_bufptr = $kgm_kds_bufptr - 1
10747 set $kgm_entry_count = $kgm_entry_count - 1
10748 showkerneldebugbufferentry $kgm_kds_bufptr
10751 set $kgm_kdsp = $kgm_kdsp->kds_next
10755 printf "Trace buffer not enabled\n"
10759 document showkerneldebugbuffercpu
10760 Syntax: showkerneldebugbuffercpu <cpu> <count>
10761 | Prints the last N entries in the kernel debug buffer for CPU x.
10764 define showkerneldebugbuffer
10766 if (kdebug_flags & 0x80000000) # 0x80000000 == KDBG_BFINIT
10768 set $kgm_entrycount = (int) $arg0
10770 if $kgm_entrycount == 0
10771 printf "<count> is 0, dumping 50 entries per cpu\n"
10772 set $kgm_entrycount = 50
10775 set $kgm_cpu = (int) 0
10777 while $kgm_cpu < kd_cpus
10778 showkerneldebugbuffercpu $kgm_cpu $kgm_entrycount
10779 set $kgm_cpu = $kgm_cpu + 1
10782 printf "Trace buffer not enabled\n"
10786 document showkerneldebugbuffer
10787 Syntax: showkerneldebugbuffer <count>
10788 | Prints the last N entries in the kernel debug buffer per cpu. i.e. showkerneldebugbuffer 50 will
10789 | display the last 50 entries in each CPU's debug buffer.
10792 define showallvmstats
10793 printf " pid command #ents wired vsize rsize max rsize\n"
10794 printf " (pages) (pages) (pages) (pages)\n"
10795 set $kgm_head_taskp = &tasks
10796 set $kgm_taskp = (struct task *)($kgm_head_taskp->next)
10797 while $kgm_taskp != $kgm_head_taskp
10798 set $kgm_procp = (struct proc *)($kgm_taskp->bsd_info)
10799 set $kgm_mapp = (struct _vm_map *)($kgm_taskp->map)
10800 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
10801 set $kgm_taskp = (struct task *)($kgm_taskp->tasks.next)
10805 document showallvmstats
10806 Syntax: showallvmstats
10807 | prints a summary of vm statistics in a table format
10811 if ($kgm_mtype == $kgm_mtype_arm)
10812 printf "kern_memorystatus_level: %8d\n", kern_memorystatus_level
10814 printf "vm_page_throttled_count: %8d\n", vm_page_throttled_count
10815 printf "vm_page_active_count: %8d\n", vm_page_active_count
10816 printf "vm_page_inactive_count: %8d\n", vm_page_inactive_count
10817 printf "vm_page_wire_count: %8d\n", vm_page_wire_count
10818 printf "vm_page_free_count: %8d\n", vm_page_free_count
10819 printf "vm_page_purgeable_count: %8d\n", vm_page_purgeable_count
10820 printf "vm_page_inactive_target: %8d\n", vm_page_inactive_target
10821 printf "vm_page_free_target: %8d\n", vm_page_free_target
10822 printf "inuse_ptepages_count: %8d\n", inuse_ptepages_count
10823 printf "vm_page_free_reserved: %8d\n", vm_page_free_reserved
10827 Syntax: (gdb) memstats
10828 | Prints out a summary of various memory statistics. In particular vm_page_wire_count should
10829 | be greater than 2K or you are under memory pressure.
10832 define show_user_registers
10833 showuserregisters $arg0
10836 document show_user_registers
10837 Syntax: show_user_registers <thread_address>
10838 | Display user registers associated with a kernel thread
10839 | properly displays the 32 bit or 64 bit registers for intel architecture
10846 # check for end of string. cmp0 can be longer than cmp1. it
10847 # can't be shorter.
10849 set $kgm_strcmp_result = 0
10850 set $kgm_strcmp_done = 1
10853 if !$kgm_strcmp_done && $cmp0 == '\0'
10854 set $kgm_strcmp_result = -1
10855 set $kgm_strcmp_done = 1
10859 if !$kgm_strcmp_done
10860 set $kgm_strcmp_result = (uint8_t) $cmp0 - (uint8_t) $cmp1
10861 if $kgm_strcmp_result != 0
10862 set $kgm_strcmp_done = 1
10869 set $masked = $cmp & 0xFF
10870 _cmp $arg0[0] $masked
10872 if !$kgm_strcmp_done
10873 set $cmp = $cmp >> 8
10874 set $masked = $cmp & 0xFF
10875 _cmp $arg0[1] $masked
10877 if !$kgm_strcmp_done
10878 set $cmp = $cmp >> 8
10879 set $masked = $cmp & 0xFF
10880 _cmp $arg0[2] $masked
10882 if !$kgm_strcmp_done
10883 set $cmp = $cmp >> 8
10884 set $masked = $cmp & 0xFF
10885 _cmp $arg0[3] $masked
10887 if !$kgm_strcmp_done
10888 set $cmp = $cmp >> 8
10889 set $masked = $cmp & 0xFF
10890 _cmp $arg0[4] $masked
10892 if !$kgm_strcmp_done
10893 set $cmp = $cmp >> 8
10894 set $masked = $cmp & 0xFF
10895 _cmp $arg0[5] $masked
10897 if !$kgm_strcmp_done
10898 set $cmp = $cmp >> 8
10899 set $masked = $cmp & 0xFF
10900 _cmp $arg0[6] $masked
10902 if !$kgm_strcmp_done
10903 set $cmp = $cmp >> 8
10904 set $masked = $cmp & 0xFF
10905 _cmp $arg0[7] $masked
10909 define strcmp_arg_pack64
10910 set $kgm_strcmp_arg = ((((((((((((((uint64_t) $arg7 << 8) | $arg6) << 8) | $arg5) << 8) | $arg4) << 8) | $arg3) << 8) | $arg2) << 8) | $arg1) << 8) | $arg0
10913 document strcmp_arg_pack64
10914 Syntax: strcmp_arg_pack64 <a> <b> <c> <d> <e <f> <g> <h>
10915 | Packs a string given as 8 character arguments into a 64-bit int stored in
10916 | $kgm_strcmp_arg. Use 0 or '\0' for unused arguments. The encoded string
10917 | is suitable for use by strcmp_nomalloc and setfindregistrystr.
10918 | e.g., strcmp_arg_pack64 'H' 'e' 'l' 'l' 'o' 0 0 0
10919 | packs "Hello" into $kgm_strcmp_arg.
10923 define strcmp_nomalloc
10925 set $count = $argc - 1
10927 set $kgm_strcmp_result = 0
10928 set $kgm_strcmp_done = 0
10931 _cmp_arg64 $str $arg1
10933 if !$kgm_strcmp_done && $count > 1
10934 set $str = $str + 8
10935 _cmp_arg64 $str $arg2
10937 if !$kgm_strcmp_done && $count > 2
10938 set $str = $str + 8
10939 _cmp_arg64 $str $arg3
10941 if !$kgm_strcmp_done && $count > 3
10942 set $str = $str + 8
10943 _cmp_arg64 $str $arg4
10945 if !$kgm_strcmp_done && $count > 4
10946 set $str = $str + 8
10947 _cmp_arg64 $str $arg5
10949 if !$kgm_strcmp_done && $count > 5
10950 set $str = $str + 8
10951 _cmp_arg64 $str $arg6
10953 if !$kgm_strcmp_done && $count > 6
10954 set $str = $str + 8
10955 _cmp_arg64 $str $arg7
10957 if !$kgm_strcmp_done && $count > 7
10958 set $str = $str + 8
10959 _cmp_arg64 $str $arg8
10961 if !$kgm_strcmp_done && $count > 8
10962 set $str = $str + 8
10963 _cmp_arg64 $str $arg9
10967 document strcmp_nomalloc
10968 Syntax: strcmp_nomalloc <string> <a> [b] [c] [d] [e] [f] [g] [h] [i]
10969 | Given a pre-allocated <string>, perform a string compare with the
10970 | encoded string stored in arguments a - i. The result is stored in
10971 | $kgm_strcmp_result.
10973 | For example, the following will result in $kgm_strcmp_result == 0:
10974 | strcmp_arg_pack64 'D' 'a' 'r' 'w' 'i' 'n' ' ' 'K'
10975 | strcmp_nomalloc version $kgm_strcmp_arg
10979 set $kgm_dst = (unsigned char *)$arg0
10980 set $kgm_src = (unsigned char *)$arg1
10981 set $kgm_count = $arg2
10983 # printf "src %p dst %p len %d\n", $kgm_src, $kgm_dst, $kgm_count
10985 while ($kgm_count >= 8)
10986 set *(unsigned long long *)$kgm_dst = *(unsigned long long *)$kgm_src
10988 set $kgm_dst = $kgm_dst + 8
10989 set $kgm_src = $kgm_src + 8
10990 set $kgm_count = $kgm_count - 8
10992 while ($kgm_count > 0)
10993 set *$kgm_dst = *$kgm_src
10995 set $kgm_dst = $kgm_dst + 1
10996 set $kgm_src = $kgm_src + 1
10997 set $kgm_count = $kgm_count - 1
11002 Syntax: memcpy <dst> <src> <n>
11003 | Given two addresses that are accessible by the debugger, perform
11004 | a memory copy of <n> bytes from <src> to <dst>
11007 # _pci_cfg_addr_value $addr $size
11008 define _pci_cfg_addr_value
11009 readphysint $arg0 $arg1 $kgm_lcpu_self
11010 set $kgm_pci_cfg_value = $kgm_readphysint_result
11014 set $kgm_pci_cfg_init = 0
11015 define _pci_cfg_init
11016 # get this from the registry if it exists there
11017 if $kgm_pci_cfg_init == 0
11018 strcmp_arg_pack64 'A' 'p' 'p' 'l' 'e' 'A' 'C' 'P'
11019 set $AppleACP = $kgm_strcmp_arg
11020 strcmp_arg_pack64 'I' 'P' 'l' 'a' 't' 'f' 'o' 'r'
11021 set $IPlatfor = $kgm_strcmp_arg
11022 strcmp_arg_pack64 'm' 'E' 'x' 'p' 'e' 'r' 't' 0
11023 set $mExpert = $kgm_strcmp_arg
11024 setfindregistrystr $AppleACP $IPlatfor $mExpert
11026 set $olddepth = $kgm_reg_depth_max
11027 set $kgm_reg_depth_max = 2
11029 set $kgm_reg_depth_max = $olddepth
11031 if $kgm_registry_entry
11032 strcmp_arg_pack64 'a' 'c' 'p' 'i' '-' 'm' 'm' 'c'
11033 set $acpi_mmc = $kgm_strcmp_arg
11034 strcmp_arg_pack64 'f' 'g' '-' 's' 'e' 'g' '0' 0
11035 set $fg_seg0 = $kgm_strcmp_arg
11036 setfindregistrystr $acpi_mmc $fg_seg0
11038 _findregistryprop $kgm_registry_entry
11039 if $kgm_registry_value
11040 set $kgm_pci_cfg_base = ((OSNumber *) $kgm_registry_value)->value
11041 set $kgm_pci_cfg_init = 1
11046 # search for 0:0:0 in likely places if the above fails
11047 if $kgm_pci_cfg_init == 0
11048 set $kgm_pci_cfg_base = 0xF0000000
11049 while $kgm_pci_cfg_init == 0 && $kgm_pci_cfg_base > 0xA0000000
11050 _pci_cfg_addr_value $kgm_pci_cfg_base 8
11051 if $kgm_pci_cfg_value > 0x0 && $kgm_pci_cfg_value < 0xFF
11052 set $kgm_pci_cfg_init = 1
11054 set $kgm_pci_cfg_base = $kgm_pci_cfg_base - 0x10000000
11060 # _pci_cfg_addr $bus $dev $fcn $off
11061 define _pci_cfg_addr
11068 set $kgm_pci_cfg_addr = $kgm_pci_cfg_base | ($bus << 20) | ($dev << 15) | ($fcn << 12) | $off
11071 define _pci_cfg_value
11072 _pci_cfg_addr $arg0 $arg1 $arg2 $arg3
11073 _pci_cfg_addr_value $kgm_pci_cfg_addr $arg4
11076 define pci_cfg_read8
11077 _pci_cfg_value $arg0 $arg1 $arg2 $arg3 8
11078 printf "%08X: %02X\n", $kgm_pci_cfg_addr, $kgm_pci_cfg_value
11081 define pci_cfg_read16
11082 _pci_cfg_value $arg0 $arg1 $arg2 $arg3 16
11083 printf "%08X: %04X\n", $kgm_pci_cfg_addr, $kgm_pci_cfg_value
11086 define pci_cfg_read32
11087 _pci_cfg_value $arg0 $arg1 $arg2 $arg3 32
11088 printf "%08X: %08X\n", $kgm_pci_cfg_addr, $kgm_pci_cfg_value
11091 document pci_cfg_read8
11092 Syntax: (gdb) pci_cfg_read8 <bus> <dev> <fcn> <off>
11093 | read 8 bits for the given <off> of the pci device located at
11094 | <bus>:<dev>:<fcn>.
11097 document pci_cfg_read16
11098 Syntax: (gdb) pci_cfg_read <bus> <dev> <fcn> <off>
11099 | read 16 bits for the given <off> of the pci device located at
11100 | <bus>:<dev>:<fcn>.
11103 document pci_cfg_read32
11104 Syntax: (gdb) pci_cfg_read <bus> <dev> <fcn> <off>
11105 | read 32 bits for the given <off> of the pci device located at
11106 | <bus>:<dev>:<fcn>.
11109 define pci_cfg_write8
11110 _pci_cfg_addr $arg0 $arg1 $arg2 $arg3
11111 writephysint $kgm_pci_cfg_addr 8 $arg4 $kgm_lcpu_self
11114 define pci_cfg_write16
11115 _pci_cfg_addr $arg0 $arg1 $arg2 $arg3
11116 writephysint $kgm_pci_cfg_addr 16 $arg4 $kgm_lcpu_self
11119 define pci_cfg_write32
11120 _pci_cfg_addr $arg0 $arg1 $arg2 $arg3
11121 writephysint $kgm_pci_cfg_addr 32 $arg4 $kgm_lcpu_self
11124 document pci_cfg_write8
11125 Syntax: (gdb) pci_cfg_write8 <bus> <dev> <fcn> <off> <value>
11126 | write an 8-bit <value> into the given <off> of the pci device located at
11127 | <bus>:<dev>:<fcn>.
11130 document pci_cfg_write16
11131 Syntax: (gdb) pci_cfg_write16 <bus> <dev> <fcn> <off> <value>
11132 | write a 16-bit <value> into the given <off> of the pci device located at
11133 | <bus>:<dev>:<fcn>.
11136 document pci_cfg_write32
11137 Syntax: (gdb) pci_cfg_write32 <bus> <dev> <fcn> <off> <value>
11138 | write a 32-bit <value> into the given <off> of the pci device located at
11139 | <bus>:<dev>:<fcn>.
11143 define pci_cfg_dump
11149 # check for a valid pci device
11150 _pci_cfg_value $bus $dev $fcn $off 8
11151 if $kgm_pci_cfg_value > 0x0 && $kgm_pci_cfg_value < 0xff
11152 printf " address: 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F\n"
11153 printf "---------------------------------------------------------"
11156 _pci_cfg_value $bus $dev $fcn $off 32
11157 if ($off & 0xF) == 0
11158 printf "\n%08X: ", $kgm_pci_cfg_addr
11160 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
11161 set $off = $off + 4
11165 # check for pcie extended capability config space
11166 _pci_cfg_value $bus $dev $fcn $off 8
11167 if $kgm_pci_cfg_value < 0xff
11169 _pci_cfg_value $bus $dev $fcn $off 32
11170 if ($off & 0xF) == 0
11171 printf "\n%08X: ", $kgm_pci_cfg_addr
11173 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
11174 set $off = $off + 4
11181 document pci_cfg_dump
11182 Syntax: (gdb) pci_cfg_dump <bus> <dev> <fcn>
11183 | dump config space for the pci device located at <bus>:<dev>:<fcn>
11184 | if you specify an invalid/inaccessible pci device, nothing will be
11188 set $kgm_pci_cfg_bus_start = 0
11189 set $kgm_pci_cfg_bus_max = 8
11190 set $kgm_pci_cfg_device_max = 32
11191 set $kgm_pci_cfg_function_max = 8
11192 define _pci_cfg_scan
11195 set $bus = $kgm_pci_cfg_bus_start
11196 while $bus < $kgm_pci_cfg_bus_max
11197 # check for bus:0:0 to see if we should
11198 # probe this bus further
11199 _pci_cfg_value $bus 0x0 0x0 0x0 32
11200 if $kgm_pci_cfg_value > 0 && $kgm_pci_cfg_value < 0xFFFFFFFF
11203 while $dev < $kgm_pci_cfg_device_max
11206 while $fcn < $kgm_pci_cfg_function_max
11207 _pci_cfg_value $bus $dev $fcn 0x0 32
11208 if $kgm_pci_cfg_value > 0 && $kgm_pci_cfg_value < 0xFFFFFFFF
11210 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
11211 _pci_cfg_value $bus $dev $fcn 0x8 32
11212 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
11214 printf " device: %03X:%03X:%03X\n", $bus, $dev, $fcn
11215 pci_cfg_dump $bus $dev $fcn
11219 set $fcn = $fcn + 1
11221 set $dev = $dev + 1
11224 set $bus = $bus + 1
11228 define pci_cfg_dump_all
11232 document pci_cfg_dump_all
11233 Syntax: (gdb) pci_cfg_dump_all
11234 | dump config spaces for scanned pci devices. the number of busses to scan
11235 | is stored in $kgm_pci_cfg_bus_max. the default for that is 8. you can also
11236 | specify the starting bus with $kgm_pci_cfg_bus_start.
11239 define pci_cfg_scan
11240 printf "bus:dev:fcn: vendor device rev | class\n"
11241 printf "---------------------------------------\n"
11245 document pci_cfg_scan
11246 Syntax: (gdb) pci_cfg_scan
11247 | scan for pci devices. the number of busses to scan is stored in
11248 | $kgm_pci_cfg_bus_max. the default for that is 8. you can also specify the
11249 | starting bus with $kgm_pci_cfg_bus_start.
11252 define readioportint
11253 set $kgm_readioportint_result = 0xBAD10AD
11254 # set up the manual KDP packet
11255 set manual_pkt.input = 0
11256 set manual_pkt.len = sizeof(kdp_readioport_req_t)
11257 set $kgm_pkt = (kdp_readioport_req_t *)&manual_pkt.data
11258 set $kgm_pkt->hdr.request = KDP_READIOPORT
11259 set $kgm_pkt->hdr.len = sizeof(kdp_readioport_req_t)
11260 set $kgm_pkt->hdr.is_reply = 0
11261 set $kgm_pkt->hdr.seq = 0
11262 set $kgm_pkt->hdr.key = 0
11263 set $kgm_pkt->address = (uint16_t)$arg0
11264 set $kgm_pkt->nbytes = $arg1 >> 3
11265 set $kgm_pkt->lcpu = (uint16_t)$arg2
11266 set manual_pkt.input = 1
11267 # dummy to make sure manual packet is executed
11268 set $kgm_dummy = &_mh_execute_header
11269 set $kgm_pkt = (kdp_readioport_reply_t *)&manual_pkt.data
11270 if ($kgm_pkt->error == 0)
11272 set $kgm_readioportint_result = *((uint8_t *) $kgm_pkt->data)
11275 set $kgm_readioportint_result = *((uint16_t *) $kgm_pkt->data)
11278 set $kgm_readioportint_result = *((uint32_t *) $kgm_pkt->data)
11284 set $lcpu = $kgm_lcpu_self
11288 readioportint $arg0 8 $lcpu
11290 printf ":\t0x%02hhx\n", $kgm_readioportint_result
11293 define readioport16
11294 set $lcpu = $kgm_lcpu_self
11298 readioportint $arg0 16 $lcpu
11300 printf ":\t0x%04hx\n", $kgm_readioportint_result
11303 define readioport32
11304 set $lcpu = $kgm_lcpu_self
11308 readioportint $arg0 32 $lcpu
11310 printf ":\t0x%08x\n", $kgm_readioportint_result
11313 document readioport8
11314 | See readioport32.
11317 document readioport16
11318 | See readioport32.
11321 document readioport32
11322 Syntax: (gdb) readioport32 <port> [lcpu (kernel's numbering convention)]
11323 | Read value stored in the specified IO port. The CPU can be optionally
11324 | specified as well.
11327 define writeioportint
11328 # set up the manual KDP packet
11329 set manual_pkt.input = 0
11330 set manual_pkt.len = sizeof(kdp_writeioport_req_t)
11331 set $kgm_pkt = (kdp_writeioport_req_t *)&manual_pkt.data
11332 set $kgm_pkt->hdr.request = KDP_WRITEIOPORT
11333 set $kgm_pkt->hdr.len = sizeof(kdp_writeioport_req_t)
11334 set $kgm_pkt->hdr.is_reply = 0
11335 set $kgm_pkt->hdr.seq = 0
11336 set $kgm_pkt->hdr.key = 0
11337 set $kgm_pkt->address = (uint16_t)$arg0
11338 set $kgm_pkt->nbytes = $arg1 >> 3
11339 set $kgm_pkt->lcpu = (uint16_t)$arg3
11341 set *(uint8_t *)$kgm_pkt->data = (uint8_t)$arg2
11344 set *(uint16_t *)$kgm_pkt->data = (uint16_t)$arg2
11347 set *(uint32_t *)$kgm_pkt->data = (uint32_t)$arg2
11349 set manual_pkt.input = 1
11350 # dummy to make sure manual packet is executed
11351 set $kgm_dummy = &_mh_execute_header
11352 set $kgm_pkt = (kdp_writeioport_reply_t *)&manual_pkt.data
11353 set $kgm_writeioportint_result = $kgm_pkt->error
11356 define writeioport8
11357 set $lcpu = $kgm_lcpu_self
11361 writeioportint $arg0 8 $arg1 $lcpu
11364 define writeioport16
11365 set $lcpu = $kgm_lcpu_self
11369 writeioportint $arg0 16 $arg1 $lcpu
11372 define writeioport32
11373 set $lcpu = $kgm_lcpu_self
11377 writeioportint $arg0 32 $arg1 $lcpu
11380 document writeioport8
11381 | See writeioport32.
11384 document writeioport16
11385 | See writeioport32.
11388 document writeioport32
11389 Syntax: (gdb) writeioport32 <port> <value> [lcpu (kernel's numbering convention)]
11390 | Write the value to the specified IO port. The size of the value is
11391 | determined by the name of the command. The CPU used can be optionally
11395 define readmsr64int
11396 set $kgm_readmsr64int_result = 0xBAD10AD
11397 # set up the manual KDP packet
11398 set manual_pkt.input = 0
11399 set manual_pkt.len = sizeof(kdp_readmsr64_req_t)
11400 set $kgm_pkt = (kdp_readmsr64_req_t *)&manual_pkt.data
11401 set $kgm_pkt->hdr.request = KDP_READMSR64
11402 set $kgm_pkt->hdr.len = sizeof(kdp_readmsr64_req_t)
11403 set $kgm_pkt->hdr.is_reply = 0
11404 set $kgm_pkt->hdr.seq = 0
11405 set $kgm_pkt->hdr.key = 0
11406 set $kgm_pkt->address = (uint32_t)$arg0
11407 set $kgm_pkt->lcpu = (uint16_t)$arg1
11408 set manual_pkt.input = 1
11409 # dummy to make sure manual packet is executed
11410 set $kgm_dummy = &_mh_execute_header
11411 set $kgm_pkt = (kdp_readmsr64_reply_t *)&manual_pkt.data
11412 if ($kgm_pkt->error == 0)
11413 set $kgm_readmsr64int_result = *((uint64_t *) $kgm_pkt->data)
11418 set $lcpu = $kgm_lcpu_self
11422 readmsr64int $arg0 $lcpu
11424 printf ":\t0x%016llx\n", $kgm_readmsr64int_result
11427 define writemsr64int
11428 # set up the manual KDP packet
11429 set manual_pkt.input = 0
11430 set manual_pkt.len = sizeof(kdp_writemsr64_req_t)
11431 set $kgm_pkt = (kdp_writemsr64_req_t *)&manual_pkt.data
11432 set $kgm_pkt->hdr.request = KDP_WRITEMSR64
11433 set $kgm_pkt->hdr.len = sizeof(kdp_writemsr64_req_t)
11434 set $kgm_pkt->hdr.is_reply = 0
11435 set $kgm_pkt->hdr.seq = 0
11436 set $kgm_pkt->hdr.key = 0
11437 set $kgm_pkt->address = (uint32_t)$arg0
11438 set $kgm_pkt->lcpu = (uint16_t)$arg2
11439 set *(uint64_t *)$kgm_pkt->data = (uint64_t)$arg1
11440 set manual_pkt.input = 1
11441 # dummy to make sure manual packet is executed
11442 set $kgm_dummy = &_mh_execute_header
11443 set $kgm_pkt = (kdp_writemsr64_reply_t *)&manual_pkt.data
11444 set $kgm_writemsr64int_result = $kgm_pkt->error
11448 set $lcpu = $kgm_lcpu_self
11452 writemsr64int $arg0 $arg1 $lcpu
11455 document writemsr64
11456 Syntax: (gdb) writemsr64 <msr> <value> [lcpu (kernel's numbering convention)]
11457 | Write <value> to the specified MSR. The CPU can be optionally specified.
11461 Syntax: (gdb) readmsr64 <msr> [lcpu (kernel's numbering convention)]
11462 | Read the specified MSR. The CPU can be optionally specified.
11465 # default if we can't find a registry entry
11466 set $kgm_ioapic_addr = 0xFEC00000
11467 set $kgm_ioapic_init = 0
11469 set $_ioapic_index_off = 0x00
11470 set $_ioapic_data_off = 0x10
11471 set $_ioapic_eoi_off = 0x40
11473 set $_ioapic_index_id = 0x00
11474 set $_ioapic_index_ver = 0x01
11475 set $_ioapic_index_redir_base = 0x10
11477 set $_apic_vector_mask = 0xFF
11478 set $_apic_timer_tsc_deadline = 0x40000
11479 set $_apic_timer_periodic = 0x20000
11480 set $_apic_masked = 0x10000
11481 set $_apic_trigger_level = 0x08000
11482 set $_apic_polarity_high = 0x02000
11483 set $_apic_pending = 0x01000
11485 define _ioapic_init
11486 if $kgm_ioapic_init == 0
11487 strcmp_arg_pack64 'i' 'o' '-' 'a' 'p' 'i' 'c' 0
11488 setfindregistrystr $kgm_strcmp_arg
11490 set $olddepth = $kgm_reg_depth_max
11491 set $kgm_reg_depth_max = 3
11493 set $kgm_reg_depth_max = $olddepth
11495 if $kgm_registry_entry
11496 strcmp_arg_pack64 'P' 'h' 'y' 's' 'i' 'c' 'a' 'l'
11497 set $Physical = $kgm_strcmp_arg
11498 strcmp_arg_pack64 ' ' 'A' 'd' 'd' 'r' 'e' 's' 's'
11499 set $_Address = $kgm_strcmp_arg
11500 setfindregistrystr $Physical $_Address
11502 _findregistryprop $kgm_registry_entry
11503 if $kgm_registry_value
11504 set $kgm_ioapic_addr = ((OSNumber *) $kgm_registry_value)->value
11507 set $kgm_ioapic_index_addr = $kgm_ioapic_addr + $_ioapic_index_off
11508 set $kgm_ioapic_data_addr = $kgm_ioapic_addr + $_ioapic_data_off
11509 set $kgm_ioapic_init = 1
11513 define _ioapic_addr_value
11515 writephysint $kgm_ioapic_index_addr 8 $arg0 $kgm_lcpu_self
11517 writephysint $kgm_ioapic_data_addr 32 $arg1 $kgm_lcpu_self
11519 readphysint $kgm_ioapic_data_addr 32 $kgm_lcpu_self
11520 set $kgm_ioapic_value = $kgm_readphysint_result
11527 printf "[VEC=%3d", $value & $_apic_vector_mask
11528 if $value & $_apic_masked
11534 if $value & $_apic_trigger_level
11535 printf " TRIG=level"
11537 printf " TRIG=edge "
11540 if $value & $_apic_polarity_high
11546 if $value & $_apic_pending
11552 if $value & $_apic_timer_periodic
11555 if $value & $_apic_timer_tsc_deadline
11556 printf " TSC_DEADLINE"
11562 define ioapic_read32
11563 if (($kgm_mtype & $kgm_mtype_x86_mask) != $kgm_mtype_x86_any)
11564 printf "ioapic_read32 not supported on this architecture.\n"
11566 _ioapic_addr_value $arg0
11567 printf "IOAPIC[0x%02X]: 0x%08X\n", $arg0, $kgm_ioapic_value
11571 document ioapic_read32
11572 Syntax: (gdb) ioapic_read <offset>
11573 | Read the IOAPIC register at the offset specified.
11576 define ioapic_write32
11577 if (($kgm_mtype & $kgm_mtype_x86_mask) != $kgm_mtype_x86_any)
11578 printf "ioapic_write32 not supported on this architecture.\n"
11580 _ioapic_addr_value $arg0 $arg1
11584 document ioapic_write32
11585 Syntax: (gdb) ioapic_write32 <offset> <value>
11586 | Write the IOAPIC register at the offset specified.
11590 if (($kgm_mtype & $kgm_mtype_x86_mask) != $kgm_mtype_x86_any)
11591 printf "ioapic_dump not supported on this architecture.\n"
11594 _ioapic_addr_value $_ioapic_index_id
11595 printf "IOAPIC[0x%02X] ID: 0x%08X\n", $_ioapic_index_id, $kgm_ioapic_value
11598 _ioapic_addr_value $_ioapic_index_ver
11599 set $maxredir = (($kgm_ioapic_value & 0xFF0000) >> 16) + 1
11601 printf "IOAPIC[0x%02X] VERSION: 0x%08X [", $_ioapic_index_ver, $kgm_ioapic_value
11602 printf "MAXREDIR=%02d PRQ=%d VERSION=0x%02X]\n", $maxredir, ($kgm_ioapic_value >> 15) & 0x1, $kgm_ioapic_value & 0xFF
11604 # all the redir entries
11606 while $i < $maxredir
11607 set $addr0 = $_ioapic_index_redir_base + ($i << 1)
11608 set $addr1 = $addr0 + 1
11609 _ioapic_addr_value $addr1
11610 printf "IOAPIC[0x%02X] IOREDIR%02d: 0x%08X", $addr0, $i, $kgm_ioapic_value
11612 _ioapic_addr_value $addr0
11613 printf "%08X ", $kgm_ioapic_value
11614 _apic_print $kgm_ioapic_value
11620 document ioapic_dump
11621 Syntax: (gdb) ioapic_dump
11622 | Dump all the IOAPIC entries.
11626 set $_lapic_base_addr = 0xFEE00000
11627 set $_lapic_id = 0x20
11628 set $_lapic_version = 0x30
11629 set $_lapic_tpr = 0x80
11630 set $_lapic_apr = 0x90
11631 set $_lapic_ppr = 0xA0
11632 set $_lapic_eoi = 0xB0
11633 set $_lapic_ldr = 0xD0
11634 set $_lapic_dfr = 0xE0
11635 set $_lapic_sivr = 0xF0
11637 set $_lapic_isr_size = 0x10
11638 set $_lapic_isr_num = 8
11639 set $_lapic_isr0 = 0x100
11640 set $_lapic_tmr0 = 0x180
11641 set $_lapic_irr0 = 0x200
11643 set $_lapic_esr = 0x280
11644 set $_lapic_esr_register = 0x80
11645 set $_lapic_esr_recv_vect = 0x40
11646 set $_lapic_esr_send_vect = 0x20
11648 set $_lapic_icr0 = 0x300
11649 set $_lapic_icr1 = 0x310
11651 set $_lapic_lvt_timer = 0x320
11652 set $_lapic_lvt_thermal = 0x330
11653 set $_lapic_lvt_pmcr = 0x340
11654 set $_lapic_lvt_lint0 = 0x350
11655 set $_lapic_lvt_lint1 = 0x360
11656 set $_lapic_lvt_error = 0x370
11658 set $_lapic_icr = 0x380
11659 set $_lapic_ccr = 0x390
11660 set $_lapic_dcr = 0x3E0
11662 set $_apic_cfg_msr = 0x1B
11663 set $_apic_cfg_msr_x2EN = 0x00000C00
11664 set $_x2apic_enabled = -1
11666 # _lapic_addr $offset returns the actual address to use
11668 if $_x2apic_enabled < 0
11669 readmsr64int $_apic_cfg_msr $kgm_lcpu_self
11670 if ($kgm_readmsr64int_result & $_apic_cfg_msr_x2EN) == $_apic_cfg_msr_x2EN
11671 set $_x2apic_enabled = 1
11673 set $_x2apic_enabled = 0
11677 if $_x2apic_enabled
11678 # x2APIC addresses are MSRs that use xAPIC offsets that
11679 # are 4-bit shifted
11680 set $kgm_lapic_addr = $arg0 >> 4
11682 set $kgm_lapic_addr = $_lapic_base_addr + $arg0
11686 # _lapic_addr_value $offset $lcpu
11687 define _lapic_addr_value
11689 if $_x2apic_enabled
11690 readmsr64int $kgm_lapic_addr $arg1
11691 set $kgm_lapic_value = $kgm_readmsr64int_result
11693 readphysint $kgm_lapic_addr 32 $arg1
11694 set $kgm_lapic_value = $kgm_readphysint_result
11698 # lapic_read32 $offset [$lcpu]
11699 define lapic_read32
11700 if (($kgm_mtype & $kgm_mtype_x86_mask) != $kgm_mtype_x86_any)
11701 printf "lapic_read32 not supported on this architecture.\n"
11703 set $lcpu = $kgm_lcpu_self
11707 _lapic_addr_value $arg0 $lcpu
11708 printf "LAPIC[0x%03X]: 0x%08X\n", $arg0, $kgm_lapic_value
11712 document lapic_read32
11713 Syntax: (gdb) apic_read32_cpu <offset> [lcpu (kernel's numbering convention)]
11714 | Read the LAPIC register at the offset specified. The CPU can be optionally
11718 # lapic_write32 $offset $value [$lcpu]
11719 define lapic_write32
11720 if (($kgm_mtype & $kgm_mtype_x86_mask) != $kgm_mtype_x86_any)
11721 printf "lapic_write32_cpu not supported on this architecture.\n"
11723 set $lcpu = $kgm_lcpu_self
11729 if $_x2apic_enabled
11730 writemsr64int $kgm_lapic_addr $arg1 $lcpu
11732 writephysint $kgm_lapic_addr 32 $arg1 $lcpu
11737 document lapic_write32
11738 Syntax: (gdb) lapic_write32 <offset> <value> [lcpu (kernel's numbering convention)]
11739 | Write the LAPIC register at the offset specified. The CPU can be optionally
11743 # lapic_dump [lcpu]
11745 if (($kgm_mtype & $kgm_mtype_x86_mask) != $kgm_mtype_x86_any)
11746 printf "lapic_dump not supported on this architecture.\n"
11748 set $lcpu = $kgm_lcpu_self
11753 _lapic_addr_value $_lapic_id $lcpu
11755 # the above also figures out if we're using an xAPIC or an x2APIC
11756 printf "LAPIC operating mode: "
11757 if $_x2apic_enabled
11763 printf "LAPIC[0x%03X] ID: 0x%08X\n", $_lapic_id, $kgm_lapic_value
11765 _lapic_addr_value $_lapic_version $lcpu
11766 set $lvt_num = ($kgm_lapic_value >> 16) + 1
11767 printf "LAPIC[0x%03X] VERSION: 0x%08X [VERSION=%d MaxLVT=%d]\n", $_lapic_version, $kgm_lapic_value, $kgm_lapic_value & 0xFF, $lvt_num
11769 _lapic_addr_value $_lapic_tpr $lcpu
11770 printf "LAPIC[0x%03X] TASK PRIORITY: 0x%08X\n", $_lapic_tpr, $kgm_lapic_value
11772 _lapic_addr_value $_lapic_ppr $lcpu
11773 printf "LAPIC[0x%03X] PROCESSOR PRIORITY: 0x%08X\n", $_lapic_ppr, $kgm_lapic_value
11775 _lapic_addr_value $_lapic_ldr $lcpu
11776 printf "LAPIC[0x%03X] LOGICAL DEST: 0x%08X\n", $_lapic_ldr, $kgm_lapic_value
11778 _lapic_addr_value $_lapic_dfr $lcpu
11779 printf "LAPIC[0x%03X] DEST FORMAT: 0x%08X\n", $_lapic_dfr, $kgm_lapic_value
11781 _lapic_addr_value $_lapic_sivr $lcpu
11782 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,
11785 while $i < $_lapic_isr_num
11786 set $addr = $_lapic_isr0 + $i * $_lapic_isr_size
11787 _lapic_addr_value $addr $lcpu
11788 printf "LAPIC[0x%03X] ISR[%03d:%03d]: 0x%08X\n", $addr, 32*($i + 1) - 1, 32*$i, $kgm_lapic_value
11793 while $i < $_lapic_isr_num
11794 set $addr = $_lapic_tmr0 + $i * $_lapic_isr_size
11795 _lapic_addr_value $addr $lcpu
11796 printf "LAPIC[0x%03X] TMR[%03d:%03d]: 0x%08X\n", $addr, 32*($i + 1) - 1, 32*$i, $kgm_lapic_value
11801 while $i < $_lapic_isr_num
11802 set $addr = $_lapic_irr0 + $i * $_lapic_isr_size
11803 _lapic_addr_value $addr $lcpu
11804 printf "LAPIC[0x%03X] IRR[%03d:%03d]: 0x%08X\n", $addr, 32*($i + 1) - 1, 32*$i, $kgm_lapic_value
11808 _lapic_addr_value $_lapic_esr $lcpu
11809 printf "LAPIC[0x%03X] ERROR STATUS: 0x%08X ", $_lapic_esr, $kgm_lapic_value
11810 if $kgm_lapic_value
11813 if $kgm_lapic_value & $_lapic_esr_register
11816 if $kgm_lapic_value & $_lapic_esr_recv_vect
11817 printf "Received Vector "
11819 if $kgm_lapic_value & $_lapic_esr_send_vect
11820 printf "Send Vector"
11822 if $kgm_lapic_value
11827 _lapic_addr_value $_lapic_icr1 $lcpu
11828 printf "LAPIC[0x%03X] Interrupt Command: 0x%08X [DEST=%d]\n", $_lapic_icr0, $kgm_lapic_value, $kgm_lapic_value >> 24
11829 _lapic_addr_value $_lapic_icr0 $lcpu
11830 printf " 0x%08X ", $kgm_lapic_value
11831 _apic_print $kgm_lapic_value
11834 _lapic_addr_value $_lapic_lvt_timer $lcpu
11835 printf "LAPIC[0x%03X] LVT Timer: 0x%08X ", $_lapic_lvt_timer, $kgm_lapic_value
11836 _apic_print $kgm_lapic_value
11840 _lapic_addr_value $_lapic_lvt_lint0 $lcpu
11841 printf "LAPIC[0x%03X] LVT LINT0: 0x%08X ", $_lapic_lvt_lint0, $kgm_lapic_value
11842 _apic_print $kgm_lapic_value
11846 _lapic_addr_value $_lapic_lvt_lint1 $lcpu
11847 printf "LAPIC[0x%03X] LVT LINT1: 0x%08X ", $_lapic_lvt_lint1, $kgm_lapic_value
11848 _apic_print $kgm_lapic_value
11852 _lapic_addr_value $_lapic_lvt_error $lcpu
11853 printf "LAPIC[0x%03X] LVT Error: 0x%08X ", $_lapic_lvt_error, $kgm_lapic_value
11854 _apic_print $kgm_lapic_value
11858 _lapic_addr_value $_lapic_lvt_pmcr $lcpu
11859 printf "LAPIC[0x%03X] LVT PerfMon: 0x%08X ", $_lapic_lvt_pmcr, $kgm_lapic_value
11860 _apic_print $kgm_lapic_value
11864 _lapic_addr_value $_lapic_lvt_thermal $lcpu
11865 printf "LAPIC[0x%03X] LVT Thermal: 0x%08X ", $_lapic_lvt_thermal, $kgm_lapic_value
11866 _apic_print $kgm_lapic_value
11869 _lapic_addr_value $_lapic_dcr $lcpu
11870 printf "LAPIC[0x%03X] Timer Divide: 0x%08X [Divide by ", $_lapic_dcr, $kgm_lapic_value
11871 set $kgm_lapic_value = ($kgm_lapic_value & 0x8) >> 1 | $kgm_lapic_value & 0x3
11872 if $kgm_lapic_value == 0x7
11875 printf "%d]\n", 2 << $kgm_lapic_value
11878 _lapic_addr_value $_lapic_icr $lcpu
11879 printf "LAPIC[0x%03X] Timer Init Count: 0x%08X\n", $_lapic_icr, $kgm_lapic_value
11881 _lapic_addr_value $_lapic_ccr $lcpu
11882 printf "LAPIC[0x%03X] Timer Cur Count: 0x%08X\n", $_lapic_ccr, $kgm_lapic_value
11886 document lapic_dump
11887 Syntax: (gdb) lapic_dump [lcpu (kernel's numbering convention)]
11888 | Dump all the LAPIC entries. The CPU can be optionally specified.
11891 define showknoteheader
11892 printf " knote filter ident kn_ptr status\n"
11895 define showknoteint
11896 set $kgm_knotep = ((struct knote *) $arg0)
11898 showptr $kgm_knotep
11900 set $kgm_filt = -$kgm_knotep->kn_kevent.filter
11901 if ($kgm_filt == 1)
11902 printf "EVFILT_READ "
11904 if ($kgm_filt == 2)
11905 printf "EVFILT_WRITE "
11907 if ($kgm_filt == 3)
11908 printf "EVFILT_AIO "
11910 if ($kgm_filt == 4)
11911 printf "EVFILT_VNODE "
11913 if ($kgm_filt == 5)
11914 printf "EVFILT_PROC "
11916 if ($kgm_filt == 6)
11917 printf "EVFILT_SIGNAL "
11919 if ($kgm_filt == 7)
11920 printf "EVFILT_TIMER "
11922 if ($kgm_filt == 8)
11923 printf "EVFILT_MACHPORT"
11925 if ($kgm_filt == 9)
11926 printf "EVFILT_FS "
11928 if ($kgm_filt == 10)
11929 printf "EVFILT_USER "
11931 if ($kgm_filt == 11)
11932 printf "EVFILT_SESSION "
11934 printf "%7d ", $kgm_knotep->kn_kevent.ident
11935 showptr $kgm_knotep->kn_ptr.p_fp
11937 if ($kgm_knotep->kn_status == 0)
11940 if ($kgm_knotep->kn_status & 0x01)
11943 if ($kgm_knotep->kn_status & 0x02)
11946 if ($kgm_knotep->kn_status & 0x04)
11949 if ($kgm_knotep->kn_status & 0x08)
11952 if ($kgm_knotep->kn_status & 0x10)
11955 if ($kgm_knotep->kn_status & 0x20)
11958 if ($kgm_knotep->kn_status & 0x40)
11965 define showprocknotes
11967 set $kgm_fdp = ((proc_t)$arg0)->p_fd
11968 set $kgm_knlist = $kgm_fdp->fd_knlist
11970 while (($i < $kgm_fdp->fd_knlistsize) && ($kgm_knlist != 0))
11971 set $kgm_kn = ((struct knote *)$kgm_knlist[$i].slh_first)
11972 while ($kgm_kn != 0)
11973 showknoteint $kgm_kn
11974 set $kgm_kn = ((struct knote *)$kgm_kn->kn_link.sle_next)
11978 set $kgm_knhash = $kgm_fdp->fd_knhash
11980 while (($i < $kgm_fdp->fd_knhashmask + 1) && ($kgm_knhash != 0))
11981 set $kgm_kn = ((struct knote *)$kgm_knhash[$i].slh_first)
11982 while ($kgm_kn != 0)
11983 showknoteint $kgm_kn
11984 set $kgm_kn = ((struct knote *)$kgm_kn->kn_link.sle_next)
11990 define showallknotes
11991 set $kgm_head_taskp = &tasks
11992 set $kgm_taskp = (struct task *)($kgm_head_taskp->next)
11993 while $kgm_taskp != $kgm_head_taskp
11995 showtaskint $kgm_taskp
11996 showprocknotes $kgm_taskp->bsd_info
11997 set $kgm_taskp = (struct task *)($kgm_taskp->tasks.next)
12000 document showprocknotes
12001 Syntax: showprocknotes <proc>
12002 | Displays filter and status information for every kevent registered for
12007 # Device node related debug macros
12011 set $kgm_tty = (struct tty *) $arg0
12012 printf "tty struct at "
12015 printf "-last input to raw queue:\n"
12016 p $kgm_tty->t_rawq->c_cs
12017 printf "-last input to canonical queue:\n"
12018 p $kgm_tty->t_canq->c_cs
12019 printf "-last output data:\n"
12020 p $kgm_tty->t_outq->c_cs
12022 if ($kgm_tty->t_state & 0x00000001)
12023 printf " TS_SO_OLOWAT (Wake up when output <= low water)\n"
12025 if ($kgm_tty->t_state & 0x00000002)
12026 printf " TS_ASYNC (async I/O mode)\n"
12028 printf " - (synchronous I/O mode)\n"
12030 if ($kgm_tty->t_state & 0x00000004)
12031 printf " TS_BUSY (Draining output)\n"
12033 if ($kgm_tty->t_state & 0x00000008)
12034 printf " TS_CARR_ON (Carrier is present)\n"
12036 printf " - (Carrier is NOT present)\n"
12038 if ($kgm_tty->t_state & 0x00000010)
12039 printf " TS_FLUSH (Outq has been flushed during DMA)\n"
12041 if ($kgm_tty->t_state & 0x00000020)
12042 printf " TS_ISOPEN (Open has completed)\n"
12044 printf " - (Open has NOT completed)\n"
12046 if ($kgm_tty->t_state & 0x00000040)
12047 printf " TS_TBLOCK (Further input blocked)\n"
12049 if ($kgm_tty->t_state & 0x00000080)
12050 printf " TS_TIMEOUT (Wait for output char processing)\n"
12052 if ($kgm_tty->t_state & 0x00000100)
12053 printf " TS_TTSTOP (Output paused)\n"
12055 if ($kgm_tty->t_state & 0x00000200)
12056 printf " TS_WOPEN (Open in progress)\n"
12058 if ($kgm_tty->t_state & 0x00000400)
12059 printf " TS_XCLUDE (Tty requires exclusivity)\n"
12061 if ($kgm_tty->t_state & 0x00000800)
12062 printf " TS_BKSL (State for lowercase \\ work)\n"
12064 if ($kgm_tty->t_state & 0x00001000)
12065 printf " TS_CNTTB (Counting tab width, ignore FLUSHO)\n"
12067 if ($kgm_tty->t_state & 0x00002000)
12068 printf " TS_ERASE (Within a \\.../ for PRTRUB)\n"
12070 if ($kgm_tty->t_state & 0x00004000)
12071 printf " TS_LNCH (Next character is literal)\n"
12073 if ($kgm_tty->t_state & 0x00008000)
12074 printf " TS_TYPEN (Retyping suspended input (PENDIN))\n"
12076 if ($kgm_tty->t_state & 0x00010000)
12077 printf " TS_CAN_BYPASS_L_RINT (Device in "raw" mode)\n"
12079 if ($kgm_tty->t_state & 0x00020000)
12080 printf " TS_CONNECTED (Connection open)\n"
12082 printf " - (Connection NOT open)\n"
12084 if ($kgm_tty->t_state & 0x00040000)
12085 printf " TS_SNOOP (Device is being snooped on)\n"
12087 if ($kgm_tty->t_state & 0x80000)
12088 printf " TS_SO_OCOMPLETE (Wake up when output completes)\n"
12090 if ($kgm_tty->t_state & 0x00100000)
12091 printf " TS_ZOMBIE (Connection lost)\n"
12093 if ($kgm_tty->t_state & 0x00200000)
12094 printf " TS_CAR_OFLOW (For MDMBUF - handle in driver)\n"
12096 if ($kgm_tty->t_state & 0x00400000)
12097 printf " TS_CTS_OFLOW (For CCTS_OFLOW - handle in driver)\n"
12099 if ($kgm_tty->t_state & 0x00800000)
12100 printf " TS_DSR_OFLOW (For CDSR_OFLOW - handle in driver)\n"
12102 # xxx todo: do we care about decoding flags?
12103 printf "flags: 0x%08x\n", $kgm_tty->t_flags
12104 printf "foreground process group: "
12105 showptr $kgm_tty->t_pgrp
12107 printf "enclosing session: "
12108 showptr $kgm_tty->t_session
12110 printf "Termios:\n"
12111 # XXX todo: decode these flags, someday
12112 printf " Input flags: 0x%08x\n", $kgm_tty->t_termios.c_iflag
12113 printf " Output flags: 0x%08x\n", $kgm_tty->t_termios.c_oflag
12114 printf " Control flags: 0x%08x\n", $kgm_tty->t_termios.c_cflag
12115 printf " Local flags: 0x%08x\n", $kgm_tty->t_termios.c_lflag
12116 printf " Input speed: %d\n", $kgm_tty->t_termios.c_ispeed
12117 printf " Output speed: %d\n", $kgm_tty->t_termios.c_ospeed
12118 # XXX todo: useful to decode t_winsize? t_iokit? c_cc? anything else?
12119 printf "high watermark: %d bytes\n", $kgm_tty->t_hiwat
12120 printf "low watermark: %d bytes\n", $kgm_tty->t_lowat
12124 # _showwhohas <major> <minor>
12134 set $kgm_swh_devnode_dev = (((int) $arg0) << 24) | (int) $arg1
12135 # iterate all tasks to iterate all processes to iterate all
12136 # open files in each process to see who has a given major/minor
12138 set $kgm_taskp = (struct task *)($kgm_head_taskp->next)
12139 while $kgm_taskp != $kgm_head_taskp
12140 set $kgm_procp = (proc_t) $kgm_taskp->bsd_info
12141 set $kgm_spf_filedesc = $kgm_procp->p_fd
12142 set $kgm_spf_last = $kgm_spf_filedesc->fd_lastfile
12143 set $kgm_spf_ofiles = $kgm_spf_filedesc->fd_ofiles
12144 set $kgm_spf_count = 0
12145 while (($kgm_spf_ofiles != 0) && ($kgm_spf_count <= $kgm_spf_last))
12146 # only files currently open
12147 if ($kgm_spf_ofiles[$kgm_spf_count] != 0)
12148 set $kgm_spf_fg = $kgm_spf_ofiles[$kgm_spf_count].f_fglob
12149 if ($kgm_spf_fg->fg_type == 1)
12150 # display fd #, fileglob & vnode address, proc name
12151 set $kgm_swh_m_vnode = (vnode_t) $kgm_spf_fg->fg_data
12152 set $kgm_swh_m_vtype = (enum vtype) $kgm_swh_m_vnode->v_type
12153 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)
12154 printf "%-5d ", $kgm_spf_count
12155 showptr $kgm_spf_fg
12157 showptr $kgm_swh_m_vnode
12160 printf " %s\n", $kgm_procp->p_comm
12164 set $kgm_spf_count = $kgm_spf_count + 1
12167 set $kgm_taskp = (struct task *)($kgm_taskp->tasks.next)
12171 define _showvnodedev_cpty
12172 set $kgm_ptmx_major = (int) $arg0
12173 set $kgm_ptmx_minor = (int) $arg1
12174 set $kgm_ptmx_ioctl = _state.pis_ioctl_list[$kgm_ptmx_minor]
12175 set $kgm_ptmx_ioctl = _state.pis_ioctl_list[$kgm_ptmx_minor]
12176 printf " ptmx_ioctl struct at "
12177 showptr $kgm_ptmx_ioctl
12180 if ($kgm_ptmx_ioctl->pt_flags & 0x0008)
12181 printf " PF_PKT (packet mode)\n"
12183 if ($kgm_ptmx_ioctl->pt_flags & 0x0010)
12184 printf " PF_STOPPED (user told stopped)\n"
12186 if ($kgm_ptmx_ioctl->pt_flags & 0x0020)
12187 printf " PF_REMOTE (remote and flow controlled input)\n"
12189 if ($kgm_ptmx_ioctl->pt_flags & 0x0040)
12190 printf " PF_NOSTOP"
12192 if ($kgm_ptmx_ioctl->pt_flags & 0x0080)
12193 printf " PF_UCNTL (user control mode)\n"
12195 if ($kgm_ptmx_ioctl->pt_flags & 0x0100)
12196 printf " PF_UNLOCKED (slave unlock - master open resets)\n"
12198 if ($kgm_ptmx_ioctl->pt_flags & 0x0200)
12199 printf " PF_OPEN_M (master is open)\n"
12200 # XXX we should search for who has the master open, but
12201 # XXX each master gets the same minor, even though it
12202 # XXX gets a different vnode. we chold probably change
12203 # XXX this, but to do it we would need some way of
12204 # XXX expressing the information in the vnode structure
12205 # XXX somewhere. If we *did* change it, it would buy us
12206 # XXX the ability to determine who has the corresponding
12207 # XXX master end of the pty open
12209 printf " PF_OPEN_M (master is closed)\n"
12211 if ($kgm_ptmx_ioctl->pt_flags & 0x0400)
12212 printf " PF_OPEN_S (slave is open)\n"
12213 printf "---vvvvv--- fds open on this device ---vvvvv---\n"
12214 _showwhohas ($kgm_ptmx_major) ($kgm_ptmx_minor)
12215 printf "---^^^^^--- fds open on this device ---^^^^^---\n"
12217 printf " - (slave is closed)\n"
12219 printf "TTY Specific Information\n"
12220 _showtty $kgm_ptmx_ioctl->pt_tty
12223 define showvnodedev
12225 set $kgm_vnode = (vnode_t) $arg0
12226 set $kgm_vtype = (enum vtype) $kgm_vnode->v_type
12227 if (($kgm_vtype == VBLK) || ($kgm_vtype == VCHR))
12228 set $kgm_devnode = (devnode_t *) $kgm_vnode->v_data
12229 set $kgm_devnode_dev = $kgm_devnode->dn_typeinfo.dev
12230 set $kgm_devnode_major = ($kgm_devnode_dev >> 24) & 0xff
12231 set $kgm_devnode_minor = $kgm_devnode_dev & 0x00ffffff
12233 # boilerplate device information for a vnode
12234 printf "Device Info:\n"
12239 if ($kgm_vtype == VBLK)
12242 if ($kgm_vtype == VCHR)
12246 printf " name: %s\n", $kgm_vnode->v_name
12247 printf " major, minor: %d, %d\n", $kgm_devnode_major, $kgm_devnode_minor
12248 printf " mode 0%o\n", $kgm_devnode->dn_mode
12249 printf " owner (u,g): %d %d", $kgm_devnode->dn_uid, $kgm_devnode->dn_gid
12252 # decode device specific data
12253 printf "Device Specific Information: "
12254 if ($kgm_vtype == VBLK)
12255 printf " Sorry, I do not know how to decode block devices yet!\n"
12256 printf " Maybe you can write me!"
12258 if ($kgm_vtype == VCHR)
12259 # Device information; this is scanty
12261 if ($kgm_devnode_major > 42) || ($kgm_devnode_major < 0)
12262 printf "Invalid major #\n"
12264 # static assignments in conf
12265 if ($kgm_devnode_major == 0)
12266 printf "Console mux device\n"
12268 if ($kgm_devnode_major == 2)
12269 printf "Current tty alias\n"
12271 if ($kgm_devnode_major == 3)
12272 printf "NULL device\n"
12274 if ($kgm_devnode_major == 4)
12275 printf "Old pty slave\n"
12277 if ($kgm_devnode_major == 5)
12278 printf "Old pty master\n"
12280 if ($kgm_devnode_major == 6)
12281 printf "Kernel log\n"
12283 if ($kgm_devnode_major == 12)
12284 printf "Memory devices\n"
12286 # Statically linked dynamic assignments
12287 if cdevsw[$kgm_devnode_major].d_open == ptmx_open
12288 printf "Cloning pty master\n"
12289 _showvnodedev_cpty ($kgm_devnode_major) ($kgm_devnode_minor)
12291 if cdevsw[$kgm_devnode_major].d_open == ptsd_open
12292 printf "Cloning pty slave\n"
12293 _showvnodedev_cpty ($kgm_devnode_major) ($kgm_devnode_minor)
12295 printf "RESERVED SLOT\n"
12309 printf " is not a device\n"
12312 printf "| Usage:\n|\n"
12316 document showvnodedev
12317 Syntax: (gdb) showvnodedev <vnode>
12318 | showvnodedev Display information about a device vnode
12325 printf "| Usage:\n|\n"
12330 Syntax: (gdb) showtty <tty struct>
12331 | showtty Display information about a struct tty
12334 define showeventsourceobject
12335 set $kgm_vt = *((void **) $arg1)
12337 set $kgm_vt = $kgm_vt - 16
12341 document showeventsourceobject
12342 Syntax: (gdb) showeventsourceobject <prefix> <object>
12343 | Routine to display information about an IOEventSource subclass.
12346 define showworkloopallocator
12347 set $kgm_workloop = (struct IOWorkLoop*)$arg0
12348 set $kgm_bt = (void**)$kgm_workloop->reserved->allocationBacktrace
12349 set $kgm_bt_count = 0
12350 while $kgm_bt_count != (sizeof(IOWorkLoop::ExpansionData.allocationBacktrace) / sizeof(IOWorkLoop::ExpansionData.allocationBacktrace[0]))
12351 set $kgm_frame_address = (void*)$kgm_bt[$kgm_bt_count]
12352 if $kgm_frame_address != 0
12353 if (((unsigned long) $kgm_frame_address < (unsigned long) &_mh_execute_header || \
12354 (unsigned long) $kgm_frame_address >= (unsigned long) &last_kernel_symbol ) \
12355 && ($kgm_show_kmod_syms == 0))
12356 showkmodaddr $kgm_frame_address
12358 output /a $kgm_frame_address
12362 set $kgm_bt_count = $kgm_bt_count + 1
12365 document showworkloopallocator
12366 Syntax: (gdb) showworkloopallocator <workloop>
12367 | Routine to display the backtrace of the thread which allocated the workloop in question. Only
12368 | valid on DEBUG kernels.
12371 define showworkloopeventsources
12372 set $kgm_eventsource = (struct IOEventSource*)$arg0
12373 while $kgm_eventsource != 0
12375 printf "EventSource:\t"
12376 showptr $kgm_eventsource
12377 printf " Description: "
12378 showeventsourceobject _ $kgm_eventsource
12380 if $kgm_eventsource->action != 0
12382 printf "Action: \t"
12383 pcprint $kgm_eventsource->action
12386 if $kgm_eventsource->owner != 0
12389 showptr $kgm_eventsource->owner
12390 printf " Description: "
12391 showeventsourceobject _ $kgm_eventsource->owner
12394 set $kgm_eventsource = $kgm_eventsource->eventChainNext
12398 document showworkloopeventsources
12399 Syntax: (gdb) showworkloopeventsources
12400 | Routine to walk an IOEventSource chain associated with an IOWorkLoop and print information
12401 | about each event source in the chain.
12404 define showworkloopheader
12407 printf " workloop "
12409 printf " pri state\tLockGroupName\n"
12411 document showworkloopheader
12412 Syntax: (gdb) showworkloopheader
12413 | Routine to print out header info about an IOKit workloop.
12416 define showworkloop
12417 set $kgm_workloopthread = (struct thread*)$arg0
12418 set $kgm_workloop = (struct IOWorkLoop*)$arg1
12419 showptr $kgm_workloopthread
12421 showptr $kgm_workloop
12422 printf " %3d ", $kgm_workloopthread.sched_pri
12423 set $kgm_state = $kgm_workloopthread.state
12424 if $kgm_state & 0x80
12427 if $kgm_state & 0x40
12430 if $kgm_state & 0x20
12433 if $kgm_state & 0x10
12436 if $kgm_state & 0x08
12439 if $kgm_state & 0x04
12442 if $kgm_state & 0x02
12445 if $kgm_state & 0x01
12449 set $kgm_gateLock = ( struct _IORecursiveLock *)$kgm_workloop->gateLock
12450 if $kgm_gateLock != 0
12451 set $kgm_lockGroup = (struct _lck_grp_*)($kgm_gateLock->group)
12452 printf "%s", $kgm_lockGroup->lck_grp_name
12454 printf "No WorkLoop Lock found"
12458 #Allocation backtrace is only valid on DEBUG kernels.
12459 #printf "Allocation path:\n\n"
12460 #showworkloopallocator $kgm_workloop
12463 if $kgm_workloop->eventChain != 0
12464 printf "Active event sources:\n\n"
12465 showworkloopeventsources $kgm_workloop->eventChain
12467 if $kgm_workloop->reserved->passiveEventChain != 0
12468 printf "Passive event sources:\n"
12469 showworkloopeventsources $kgm_workloop->reserved->passiveEventChain
12472 document showworkloop
12473 Syntax: (gdb) showworkloop <thread> <workloop>
12474 | Routine to print out info about an IOKit workloop.
12477 define showallworkloopthreads
12478 set $kgm_head_taskp = &tasks
12479 set $kgm_taskp = (struct task *)($kgm_head_taskp->next)
12480 set $kgm_head_actp = &($kgm_taskp->threads)
12481 set $kgm_actp = (struct thread *)($kgm_taskp->threads.next)
12482 while $kgm_actp != $kgm_head_actp
12483 if ($kgm_actp->continuation == _ZN10IOWorkLoop10threadMainEv)
12485 showworkloop $kgm_actp $kgm_actp->parameter
12487 if ($kgm_actp->kernel_stack != 0)
12488 if ($kgm_mtype == $kgm_mtype_x86_64)
12489 #Warning: Grokking stack looking for hopeful workloops until we squirrel some info in thread_t.
12490 set $kgm_workloop = *((struct IOWorkLoop **)($kgm_actp->kernel_stack + kernel_stack_size - 0xB8))
12492 if ($kgm_mtype == $kgm_mtype_i386)
12493 set $kgm_workloop = *((struct IOWorkLoop **)($kgm_actp->kernel_stack + kernel_stack_size - 0x3C))
12496 if ($kgm_workloop != 0)
12497 set $kgm_vt = *((void **) $kgm_workloop)
12499 set $kgm_vt = $kgm_vt - 16
12501 if ($kgm_vt == &_ZTV10IOWorkLoop)
12503 showworkloop $kgm_actp $kgm_workloop
12508 set $kgm_actp = (struct thread *)($kgm_actp->task_threads.next)
12512 document showallworkloopthreads
12513 Syntax: (gdb) showallworkloopthreads
12514 | Routine to print out info about all IOKit workloop threads in the system. This macro will find
12515 | all IOWorkLoop threads blocked in continuations and on i386 and x86_64 systems will make a
12516 | best-effort guess to find any workloops that are actually not blocked in a continuation. For a
12517 | complete list, it is best to compare the output of this macro against the output of 'showallstacks'.
12520 define showthreadfortid
12521 set $kgm_id_found = 0
12523 set $kgm_head_taskp = &tasks
12524 set $kgm_taskp = (struct task *)($kgm_head_taskp->next)
12525 while $kgm_taskp != $kgm_head_taskp
12526 set $kgm_head_actp = &($kgm_taskp->threads)
12527 set $kgm_actp = (struct thread *)($kgm_taskp->threads.next)
12528 while $kgm_actp != $kgm_head_actp
12529 set $kgm_thread = *(struct thread *)$kgm_actp
12530 set $kgm_thread_id = $kgm_thread.thread_id
12531 if ($kgm_thread_id == $arg0)
12534 set $kgm_id_found = 1
12537 set $kgm_actp = (struct thread *)($kgm_actp->task_threads.next)
12539 if ($kgm_id_found == 1)
12542 set $kgm_taskp = (struct task *)($kgm_taskp->tasks.next)
12544 if ($kgm_id_found == 0)
12545 printf "Not a valid thread_id\n"
12549 document showthreadfortid
12550 Syntax: showthreadfortid <thread_id>
12551 |The thread structure contains a unique thread_id value for each thread.
12552 |This command is used to retrieve the address of the thread structure(thread_t)
12553 |corresponding to a given thread_id.
12556 define showtaskbusyportsint
12557 set $kgm_isp = ((task_t)$arg0)->itk_space
12558 set $kgm_iindex = 0
12559 while ( $kgm_iindex < $kgm_isp->is_table_size )
12560 set $kgm_iep = &($kgm_isp->is_table[$kgm_iindex])
12561 if $kgm_iep->ie_bits & 0x00020000
12562 set $kgm_port = ((ipc_port_t)$kgm_iep->ie_object)
12563 if $kgm_port->ip_messages.data.port.msgcount > 0
12567 set $kgm_iindex = $kgm_iindex + 1
12571 define showtaskbusyports
12572 showtaskbusyportsint $arg0
12575 document showtaskbusyports
12576 Syntax: showtaskbusyports <task>
12577 |Routine to print information about receive rights belonging to this task that
12578 |have enqueued messages. This is often a sign of a blocked or hung process.
12581 define showallbusyports
12582 set $kgm_head_taskp = &tasks
12583 set $kgm_cur_taskp = (struct task *)($kgm_head_taskp->next)
12584 while $kgm_cur_taskp != $kgm_head_taskp
12585 showtaskbusyportsint $kgm_cur_taskp
12586 set $kgm_cur_taskp = (struct task *)($kgm_cur_taskp->tasks.next)
12590 document showallbusyports
12591 Syntax: showallbusyports
12592 |Routine to print information about all receive rights on the system that
12593 |have enqueued messages.
12596 define showallproviders
12597 set $kgm_providerp = dtrace_provider
12598 while $kgm_providerp
12599 p *(dtrace_provider_t *)$kgm_providerp
12601 set $kgm_providerp = (dtrace_provider_t *)($kgm_providerp->dtpv_next)
12605 document showallproviders
12606 Syntax: showallproviders
12607 | Display summary listing of all dtrace_providers
12610 define showmodctlheader
12621 printf " loadid loaded nenabled flags name\n"
12624 define showmodctlint
12625 set $kgm_modctlp = (struct modctl *)$arg0
12626 showptr $kgm_modctlp
12628 showptr $kgm_modctlp->mod_stale
12630 showptr $kgm_modctlp->mod_user_symbols
12632 showptr $kgm_modctlp->mod_address
12634 showptr $kgm_modctlp->mod_size
12636 printf "%6d ", $kgm_modctlp->mod_loadcnt
12637 printf "%6d ", $kgm_modctlp->mod_loaded
12638 printf "%6d ", $kgm_modctlp->mod_nenabled
12639 printf " 0x%x ", $kgm_modctlp->mod_flags
12640 printf "%s\n", $kgm_modctlp->mod_modname
12645 showmodctlint $arg0
12647 document showmodctl
12648 Syntax: (gdb) showmodctl <addr>
12649 | Display info about a dtrace modctl
12652 define showallmodctls
12654 set $kgm_modctlp = (struct modctl *)dtrace_modctl_list
12656 showmodctlint $kgm_modctlp
12657 set $kgm_modctlp = $kgm_modctlp->mod_next
12660 document showallmodctls
12661 Syntax: (gdb) showallmodctls
12662 | Display summary listing of all dtrace modctls
12665 define showfbtprobe
12666 printf "Be very patient, this traverses a large list \n"
12670 while $kgm_indx < fbt_probetab_size && !$kgm_found
12671 set $kgm_fbt_probep = (struct fbt_probe *)fbt_probetab[$kgm_indx]
12674 set $kgm_probeid = (struct fbt_probe *)$kgm_fbt_probep->fbtp_id
12675 if $kgm_probeid == $arg0
12679 set $kgm_fbt_probep = $kgm_fbt_probep->fbtp_hashnext
12680 while $kgm_fbt_probep
12682 set $kgm_probeid = (struct fbt_probe *)$kgm_fbt_probep->fbtp_id
12683 if $kgm_probeid == $arg0
12687 set $kgm_fbt_probep = $kgm_fbt_probep->fbtp_hashnext
12695 printf "fbt_probetab[index=%d], depth=%d, 0x%x\n", $kgm_indx, $kgm_depth, $kgm_fbt_probep
12696 printf "(gdb) p *(struct fbt_probe *)0x%x\n", $kgm_fbt_probep
12697 p *(struct fbt_probe *)$kgm_fbt_probep
12698 set $kgm_fbtp_ctl = (struct fbt_probe *)$kgm_fbt_probep->fbtp_ctl
12699 showmodctl $kgm_fbtp_ctl
12704 document showfbtprobe
12705 Syntax: (gdb) showfbtprobe <id>
12706 | Display info about an fbt probe given an id.
12707 | Traverses fbt_probetab and matches <id> with fbtp_id.
12708 | The <id> is found using dtrace -l
12711 define showzstacktrace
12712 set $kgm_trace = (void*)$arg0
12714 set $kgm_trace_size = 15
12717 set $kgm_trace_size = $arg1
12719 set $kgm_trace_current = 0
12720 while ($kgm_trace_current < $kgm_trace_size)
12721 set $kgm_trace_addr = (void**)$kgm_trace + $kgm_trace_current
12722 set $kgm_trace_value = *((void**)$kgm_trace_addr)
12724 output /a $kgm_trace_value
12725 set $kgm_trace_current = $kgm_trace_current + 1
12730 document showzstacktrace
12731 Syntax: showzstacktrace <saved stacktrace> [size]
12732 | Routine to print a stacktrace stored by OSBacktrace.
12733 | size is optional, defaults to 15.
12737 set $kgm_zallocation = zallocations[$arg0]
12738 print $kgm_zallocation
12739 showztrace $kgm_zallocation->za_trace_index
12742 document showzalloc
12743 Syntax: showzalloc <index>
12744 | Prints a zallocation from the zallocations array based off its index,
12745 | and prints the associated symbolicated backtrace.
12749 set $kgm_ztrace = &ztraces[$arg0]
12750 showztraceaddr $kgm_ztrace
12753 document showztrace
12754 Syntax: showztrace <trace index>
12755 | Prints the backtrace from the ztraces array at index
12758 define showztraceaddr
12760 showzstacktrace $arg0->zt_stack ($arg0)->zt_depth
12763 document showztraceaddr
12764 Syntax: showztraceaddr <trace address>
12765 | Prints the struct ztrace passed in
12768 #TODO: Iterate through the hash table, or make top_ztrace accurate in the face of deallocations (better idea).
12769 define showtopztrace
12770 set $kgm_top_ztrace = top_ztrace
12771 printf "Index: %d\n", (top_ztrace - ztraces)
12772 showztraceaddr $kgm_top_ztrace
12775 document showtopztrace
12776 Syntax: showtopztrace
12777 | Shows the ztrace with the biggest size. (according to top_ztrace, not by iterating through the hash table)
12781 set $kgm_zallocation_current_index = 0
12782 set $kgm_zallocations_count = 0
12783 set $kgm_max_zallocation = zleak_alloc_buckets
12784 printf "INDEX ADDRESS "
12788 printf "TRACE SIZE\n"
12789 while ($kgm_zallocation_current_index < $kgm_max_zallocation)
12790 set $kgm_zallocation_current = zallocations[$kgm_zallocation_current_index]
12791 if ($kgm_zallocation_current->element != 0)
12792 printf "%5d %p ", $kgm_zallocation_current_index, $kgm_zallocation_current->za_element
12793 printf "%5d %6lu\n", $kgm_zallocation_current->za_trace_index, $kgm_zallocation_current->za_size
12794 set $kgm_zallocations_count = $kgm_zallocations_count + 1
12796 set $kgm_zallocation_current_index = $kgm_zallocation_current_index + 1
12798 printf "Total allocations: %d\n", $kgm_zallocations_count
12801 document showzallocs
12802 Syntax: showzallocs
12803 | Prints all allocations in the zallocations table
12806 define showzallocsfortrace
12807 set $kgm_zallocation_current_index = 0
12808 set $kgm_zallocations_count = 0
12809 set $kgm_max_zallocation = zleak_alloc_buckets
12810 printf "INDEX ADDRESS "
12815 while ($kgm_zallocation_current_index < $kgm_max_zallocation)
12816 set $kgm_zallocation_current = zallocations[$kgm_zallocation_current_index]
12817 if ($kgm_zallocation_current->element != 0 && $kgm_zallocation_current->za_trace_index == $arg0)
12818 printf "%5d %p ", $kgm_zallocation_current_index, $kgm_zallocation_current->za_element
12819 printf "%6lu\n", $kgm_zallocation_current->size
12820 set $kgm_zallocations_count = $kgm_zallocations_count + 1
12822 set $kgm_zallocation_current_index = $kgm_zallocation_current_index + 1
12824 printf "Total allocations: %d\n", $kgm_zallocations_count
12827 document showzallocsfortrace
12828 Syntax: showzallocsfortrace <trace index>
12829 | Prints all allocations pointing to the passed in trace's index into ztraces by looking through zallocations table
12836 document showztraces
12837 Syntax: showztraces
12838 | Prints all traces with size > 0
12841 define showztracesabove
12842 set $kgm_ztrace_current_index = 0
12843 set $kgm_ztrace_count = 0
12844 set $kgm_max_ztrace = zleak_trace_buckets
12845 printf "INDEX SIZE\n"
12846 while ($kgm_ztrace_current_index < $kgm_max_ztrace)
12847 set $kgm_ztrace_current = ztraces[$kgm_ztrace_current_index]
12848 if ($kgm_ztrace_current->zt_size > $arg0)
12849 printf "%5d %6lu\n", $kgm_ztrace_current_index, $kgm_ztrace_current->zt_size
12850 set $kgm_ztrace_count = $kgm_ztrace_count + 1
12852 set $kgm_ztrace_current_index = $kgm_ztrace_current_index + 1
12854 printf "Total traces: %d\n", $kgm_ztrace_count
12857 document showztracesabove
12858 Syntax: showztracesabove <size>
12859 | Prints all traces with size greater than X
12862 define showztracehistogram
12863 set $kgm_ztrace_current_index = 0
12864 set $kgm_ztrace_count = 0
12865 set $kgm_max_ztrace = zleak_trace_buckets
12866 printf "INDEX HIT_COUNT COLLISIONS\n"
12867 while ($kgm_ztrace_current_index < $kgm_max_ztrace)
12868 set $kgm_ztrace_current = ztraces[$kgm_ztrace_current_index]
12869 if ($kgm_ztrace_current->zt_hit_count != 0)
12870 printf "%5d %5d %5d\n", $kgm_ztrace_current_index, $kgm_ztrace_current->zt_hit_count, $kgm_ztrace_current->zt_collisions
12871 set $kgm_ztrace_count = $kgm_ztrace_count + 1
12873 set $kgm_ztrace_current_index = $kgm_ztrace_current_index + 1
12875 printf "Total traces: %d\n", $kgm_ztrace_count
12878 document showztracehistogram
12879 Syntax: showztracehistogram
12880 | Prints the histogram of the ztrace table
12883 define showzallochistogram
12884 set $kgm_zallocation_current_index = 0
12885 set $kgm_zallocations_count = 0
12886 set $kgm_max_zallocation = zleak_alloc_buckets
12887 printf "INDEX HIT_COUNT\n"
12888 while ($kgm_zallocation_current_index < $kgm_max_zallocation)
12889 set $kgm_zallocation_current = zallocations[$kgm_zallocation_current_index]
12890 if ($kgm_zallocation_current->za_hit_count != 0)
12891 printf "%5d %5d\n", $kgm_zallocation_current_index, $kgm_zallocation_current->za_hit_count
12892 set $kgm_zallocations_count = $kgm_zallocations_count + 1
12894 set $kgm_zallocation_current_index = $kgm_zallocation_current_index + 1
12896 printf "Total allocations: %d\n", $kgm_zallocations_count
12899 document showzallochistogram
12900 Syntax: showzallochistogram
12901 | Prints the histogram for the zalloc table
12905 printf "z_alloc_collisions: %u, z_trace_collisions: %u\n", z_alloc_collisions, z_trace_collisions
12906 printf "z_alloc_overwrites: %u, z_trace_overwrites: %u\n", z_alloc_overwrites, z_trace_overwrites
12907 printf "z_alloc_recorded: %u, z_trace_recorded: %u\n", z_alloc_recorded, z_trace_recorded
12910 document showzstats
12912 | Prints the zone leak detection stats
12916 set $kgm_au_sentry_hash_table_size = 97
12918 define showsession1
12919 set $p = (struct au_sentry *)$arg0
12921 printf " 0x%08x 0x%08x 0x%016x", $p->se_auinfo.ai_asid, $p->se_auinfo.ai_auid, $p->se_auinfo.ai_flags
12922 printf " %3ld %3ld", $p->se_refcnt, $p->se_procnt
12926 define showsessionhdr
12927 printf "au_sentry "
12929 printf " ASID AUID FLAGS C P\n"
12937 document showsession
12938 Syntax: showsession
12939 | Display info about a specified audit session
12942 define showallsessions
12944 set $kgm_au_sentry_hash_table = au_sentry_bucket
12945 set $i = $kgm_au_sentry_hash_table_size - 1
12947 set $p = $kgm_au_sentry_hash_table[$i].lh_first
12950 set $p = $p->se_link.le_next
12956 document showallsessions
12957 Syntax: showallsessions
12958 | Prints the audit sessions in the global hash table
12961 define showauhistorystack
12963 set $pp = (void **)$arg1
12971 define showauhistory1
12972 set $p = (struct au_history *)$arg0
12973 set $stack_depth = $p->stack_depth
12974 set $stack = $p->stack
12992 printf " 0x%08x 0x%08x 0x%016x", $p->se_auinfo.ai_asid, $p->se_auinfo.ai_auid, $p->se_auinfo.ai_flags
12993 printf " %3ld %3ld", $p->se_refcnt, $p->se_procnt
12995 showauhistorystack $stack_depth $stack
12998 define showauhistory
12999 set $i = (au_history_index-1) % au_history_size
13000 if au_history_index >= au_history_size
13001 set $n = au_history_size
13003 set $n = au_history_index
13006 if au_history[$i].ptr != 0 && (0 == $arg0 || au_history[$i].ptr == $arg0)
13007 printf "[% 4d] ", $i
13008 showauhistory1 &au_history[$i]
13011 set $i = ($i - 1) % au_history_size
13015 define showallauhistory
13019 define showkwqheader
13024 printf " inqueue fakecount highseq lowseq flags lastunlock p_rwwc"
13030 set $kgm_kwq = (ksyn_wait_queue_t)$arg0
13033 showptr $kgm_kwq->kw_addr
13035 printf " %d ", $kgm_kwq->kw_inqueue
13036 printf " %d ", $kgm_kwq->kw_fakecount
13037 printf " 0x%x ", $kgm_kwq->kw_highseq
13038 printf " 0x%x ", $kgm_kwq->kw_lowseq
13039 printf " 0x%x ", $kgm_kwq->kw_flags
13040 printf " 0x%x ", $kgm_kwq->kw_lastunlockseq
13041 printf " 0x%x ", $kgm_kwq->kw_pre_rwwc
13051 Syntax: (gdb) show_kwq <kwq>
13052 | Display info about one ksyn_wait_queue
13055 # Internal routine used by "showpthread_mutex" to abstract possible loads from
13057 define _loadfrommutex
13059 set $kgm_loadval = *(uintptr_t *)$arg0
13061 if ($kgm_x86_abi == 0xe)
13062 set $kgm_loadval = *(uint32_t *)$arg0
13064 if ($kgm_x86_abi == 0xf)
13065 if ($kgm_mtype == $kgm_mtype_i386)
13067 set $kgm_loadval = $kgm_k32read64
13069 set $kgm_loadval = *(uint32_t *)$arg0
13076 define show_pthreadmutex
13077 set $newact = (struct thread *) $arg0
13078 set $ourtask = (struct task *)($newact->task)
13079 set $our_user_is64 = ($ourtask->taskFeatures[0] & 0x80000000)
13081 set $mutex = (void *)$arg1
13082 set kdp_pmap = $newact->task->map->pmap
13085 set $newiss = (x86_saved_state_t *) ($newact->machine.pcb->iss)
13086 set $kgm_x86_abi = $newiss.flavor
13087 if ($our_user_is64 != 0)
13088 printf "\tUser 64Bit\n "
13089 printf "\tSignature: "
13090 set $nextval = $mutex
13091 _loadfrommutex $nextval
13092 printf "0x%x\n",$kgm_loadval
13094 set $nextval = $mutex + 12
13095 _loadfrommutex $nextval
13096 printf "0x%x\n",$kgm_loadval
13098 set $nextval = $mutex + 20
13099 _loadfrommutex $nextval
13100 printf "0x%x ",$kgm_loadval
13101 set $nextval = $mutex + 24
13102 _loadfrommutex $nextval
13103 printf "0x%x ",$kgm_loadval
13104 set $nextval = $mutex + 28
13105 _loadfrommutex $nextval
13106 printf "0x%x\n",$kgm_loadval
13107 printf "\ttid[0]: "
13108 set $nextval = $mutex + 32
13109 _loadfrommutex $nextval
13110 printf "0x%x\n",$kgm_loadval
13111 printf "\ttid[1]: "
13112 set $nextval = $mutex + 36
13113 _loadfrommutex $nextval
13114 printf "0x%x\n",$kgm_loadval
13116 printf "\tUser 32Bit\n "
13117 printf "\tSignature: "
13118 set $nextval = $mutex
13119 _loadfrommutex $nextval
13120 printf "0x%x\n",$kgm_loadval
13122 set $nextval = $mutex + 8
13123 _loadfrommutex $nextval
13124 printf "0x%x\n",$kgm_loadval
13126 set $nextval = $mutex + 16
13127 _loadfrommutex $nextval
13128 printf "0x%x ",$kgm_loadval
13129 set $nextval = $mutex + 20
13130 _loadfrommutex $nextval
13131 printf "0x%x ",$kgm_loadval
13132 set $nextval = $mutex + 24
13133 _loadfrommutex $nextval
13134 printf "0x%x\n",$kgm_loadval
13135 printf "\ttid[0]: "
13136 set $nextval = $mutex + 32
13137 _loadfrommutex $nextval
13138 printf "0x%x\n",$kgm_loadval
13139 printf "\ttid[1]: "
13140 set $nextval = $mutex + 36
13141 _loadfrommutex $nextval
13142 printf "0x%x\n",$kgm_loadval
13149 document show_pthreadmutex
13150 Syntax: (gdb) show_pthreadmutex <thread> <user_mutexaddr>
13151 | Display the mutex contents from userspace.
13155 define show_pthreadcondition
13156 set $newact = (struct thread *) $arg0
13157 set $ourtask = (struct task *)($newact->task)
13158 set $our_user_is64 = ($ourtask->taskFeatures[0] & 0x80000000)
13160 set $cond = (void *)$arg1
13161 set kdp_pmap = $newact->task->map->pmap
13164 set $newiss = (x86_saved_state_t *) ($newact->machine.pcb->iss)
13165 set $kgm_x86_abi = $newiss.flavor
13166 if ($our_user_is64 != 0)
13167 printf "\tUser 64Bit\n "
13168 printf "\tSignature: "
13169 set $nextval = $cond
13170 _loadfrommutex $nextval
13171 printf "0x%x\n",$kgm_loadval
13173 set $nextval = $cond + 12
13174 _loadfrommutex $nextval
13175 printf "0x%x\n",$kgm_loadval
13177 set $nextval = $cond + 24
13178 _loadfrommutex $nextval
13179 printf "0x%x ",$kgm_loadval
13180 set $nextval = $cond + 28
13181 _loadfrommutex $nextval
13182 printf "0x%x ",$kgm_loadval
13183 set $nextval = $cond + 32
13184 _loadfrommutex $nextval
13185 printf "0x%x\n",$kgm_loadval
13186 printf "\tMutex lowaddr: "
13187 set $nextval = $cond + 16
13188 _loadfrommutex $nextval
13189 printf "0x%08x\n",$kgm_loadval
13190 printf "\tMutex highaddr: "
13191 set $nextval = $cond + 20
13192 _loadfrommutex $nextval
13193 printf "0x%x\n",$kgm_loadval
13195 printf "\tUser 32Bit\n "
13196 printf "\tSignature: "
13197 set $nextval = $cond
13198 _loadfrommutex $nextval
13199 printf "0x%x\n",$kgm_loadval
13201 set $nextval = $cond + 8
13202 _loadfrommutex $nextval
13203 printf "0x%x\n",$kgm_loadval
13205 set $nextval = $cond + 16
13206 _loadfrommutex $nextval
13207 printf "0x%x ",$kgm_loadval
13208 set $nextval = $cond + 20
13209 _loadfrommutex $nextval
13210 printf "0x%x ",$kgm_loadval
13211 set $nextval = $cond + 24
13212 _loadfrommutex $nextval
13213 printf "0x%x\n",$kgm_loadval
13214 printf "\tMutex addr: "
13215 set $nextval = $cond + 12
13216 _loadfrommutex $nextval
13217 printf "0x%x\n",$kgm_loadval
13224 document show_pthreadcondition
13225 Syntax: (gdb) show_pthreadcondition <thread> <user_cvaddr>
13226 | Display the condition variable contents from userspace.
13229 define processortimers
13230 set $kgm_p = processor_list
13231 printf "Processor\t\t\t Last dispatch\t\t Next deadline\t\t difference\n"
13233 printf "Processor %d: %p\t", $kgm_p->cpu_id, $kgm_p
13234 printf " 0x%016llx\t", $kgm_p->last_dispatch
13235 set $kgm_rt_timer = &(cpu_data_ptr[$kgm_p->cpu_id].rtclock_timer)
13236 printf " 0x%016llx \t", $kgm_rt_timer->deadline
13237 set $kgm_rt_diff = ((long long)$kgm_p->last_dispatch) - ((long long)$kgm_rt_timer->deadline)
13238 printf " 0x%016llx ", $kgm_rt_diff
13239 # normally the $kgm_rt_diff will be close to the last dispatch time, or negative
13240 # When it isn't, mark the result as bad. This is a suggestion, not an absolute
13241 if ( ($kgm_rt_diff > 0) && ((long long)$kgm_p->last_dispatch) - ($kgm_rt_diff + 1) > 0 )
13242 printf "probably BAD\n"
13246 # dump the call entries (Intel only)
13247 if (($kgm_mtype & $kgm_mtype_x86_mask) == $kgm_mtype_x86_any)
13248 printf "Next deadline set at: 0x%016llx. Timer call list:", $kgm_rt_timer->when_set
13249 set $kgm_entry = (queue_t *)$kgm_rt_timer->queue
13250 if ($kgm_entry == $kgm_rt_timer)
13251 printf " (empty)\n"
13253 printf "\n entry: "
13255 printf "deadline soft_deadline delta (*func)(param0,param1)\n"
13256 while $kgm_entry != $kgm_rt_timer
13257 set $kgm_timer_call = (timer_call_t) $kgm_entry
13258 set $kgm_call_entry = (struct call_entry *) $kgm_entry
13261 printf ": 0x%016llx 0x%016llx 0x%08x (%p)(%p,%p)\n", \
13262 $kgm_call_entry->deadline, \
13263 $kgm_timer_call->soft_deadline, \
13264 ($kgm_call_entry->deadline - $kgm_timer_call->soft_deadline), \
13265 $kgm_call_entry->func, \
13266 $kgm_call_entry->param0, $kgm_call_entry->param1
13267 set $kgm_entry = $kgm_entry->next
13271 set $kgm_p = $kgm_p->processor_list
13276 document processortimers
13277 Syntax: (gdb) processortimers
13278 | Print details of processor timers, noting any timer which might be suspicious