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 | maplocalcache Enable local caching in GDB for improved debug speeds
311 | flushlocalcahe Disable local caching in GDB (deletes all memory regions)
313 | Type "help <macro>" for more specific help on a particular macro.
314 | Type "show user <macro>" to see what the macro is really doing.
317 # This macro should appear before any symbol references, to facilitate
318 # a gdb "source" without a loaded symbol file.
325 | Read the kernel version string from a fixed address in low
326 | memory. Useful if you don't know which kernel is on the other end,
327 | and need to find the appropriate symbols. Beware that if you've
328 | loaded a symbol file, but aren't connected to a remote target,
329 | the version string from the symbol file will be displayed instead.
330 | This macro expects to be connected to the remote kernel to function
334 set $kgm_mtype_ppc = 0x00000012
335 set $kgm_mtype_arm = 0x0000000C
337 set $kgm_mtype_i386 = 0x00000007
338 set $kgm_mtype_x86_64 = 0x01000007
339 set $kgm_mtype_x86_any = $kgm_mtype_i386
340 set $kgm_mtype_x86_mask = 0xFEFFFFFF
342 set $kgm_mtype = ((unsigned int *)&_mh_execute_header)[1]
343 set $kgm_lp64 = $kgm_mtype & 0x01000000
345 set $kgm_manual_pkt_ppc = 0x549C
346 set $kgm_manual_pkt_i386 = 0x249C
347 set $kgm_manual_pkt_x86_64 = 0xFFFFFF8000002930
348 set $kgm_manual_pkt_arm = 0xFFFF04A0
350 set $kgm_kdp_pkt_data_len = 128
352 # part of data packet
353 set $kgm_kdp_pkt_hdr_req_off = 0
354 set $kgm_kdp_pkt_hdr_seq_off = 1
355 set $kgm_kdp_pkt_hdr_len_off = 2
356 set $kgm_kdp_pkt_hdr_key_off = 4
359 set $kgm_kdp_pkt_len_off = $kgm_kdp_pkt_data_len
360 set $kgm_kdp_pkt_input_off = $kgm_kdp_pkt_data_len + 4
362 set $kgm_kdp_pkt_hostreboot = 0x13
363 set $kgm_kdp_pkt_hdr_size = 8
366 set $kgm_readphys_force_kdp = 0
367 set $kgm_readphys_force_physmap = 0
369 set $kgm_lcpu_self = 0xFFFE
371 set $kgm_reg_depth = 0
372 set $kgm_reg_depth_max = 0xFFFF
373 set $kgm_reg_plane = (IORegistryPlane *) gIOServicePlane
374 set $kgm_namekey = (OSSymbol *) 0
375 set $kgm_childkey = (OSSymbol *) 0
377 set $kgm_show_object_addrs = 0
378 set $kgm_show_object_retain = 0
379 set $kgm_show_props = 0
380 set $kgm_show_data_alwaysbytes = 0
382 set $kgm_show_kmod_syms = 0
384 # send a manual packet header that doesn't require knowing the location
389 set $hdrp = (uint32_t *) $kgm_manual_pkt_i386
390 if ($kgm_mtype == $kgm_mtype_ppc)
391 set $hdrp = (uint32_t *) $kgm_manual_pkt_ppc
392 set $req = $req << 1 # shift to deal with endiannness
394 if ($kgm_mtype == $kgm_mtype_x86_64)
395 set $hdrp = (uint64_t *) $kgm_manual_pkt_x86_64
397 if ($kgm_mtype == $kgm_mtype_arm)
398 set $hdrp = (uint32_t *) $kgm_manual_pkt_arm
401 set $pkt_hdr = *$hdrp
402 set *((uint8_t *) ($pkt_hdr + $kgm_kdp_pkt_input_off)) = 0
403 set *((uint32_t *) ($pkt_hdr + $kgm_kdp_pkt_len_off)) = $kgm_kdp_pkt_hdr_size
405 set *((uint8_t *) ($pkt_hdr + $kgm_kdp_pkt_hdr_req_off)) = $req
406 set *((uint8_t *) ($pkt_hdr + $kgm_kdp_pkt_hdr_seq_off)) = 0
407 set *((uint16_t *) ($pkt_hdr + $kgm_kdp_pkt_hdr_len_off)) = $kgm_kdp_pkt_hdr_size
408 set *((uint32_t *) ($pkt_hdr + $kgm_kdp_pkt_hdr_key_off)) = 0
409 set *((uint8_t *) ($pkt_hdr + $kgm_kdp_pkt_input_off)) = 1
411 # dummy to make sure manual packet is executed
412 set $kgm_dummy = &_mh_execute_header
418 printf "0x%016llx", $arg0
420 printf "0x%08x", $arg0
424 # for headers, leave 8 chars for LP64 pointers
431 # Print a userspace pointer, using $kgm_tasp
433 set $kgm_userptr_task_64 = ( $kgm_taskp->taskFeatures[0] & 0x80000000)
434 if $kgm_userptr_task_64
435 printf "0x%016llx", $arg0
437 printf "0x%08x", $arg0
441 define showkmodheader
448 printf " id refs version name\n"
452 set $kgm_kmodp = (struct kmod_info *)$arg0
455 showptr $kgm_kmodp->address
457 showptr $kgm_kmodp->size
459 printf "%3d ", $kgm_kmodp->id
460 printf "%5d ", $kgm_kmodp->reference_count
461 printf "%10s ", $kgm_kmodp->version
462 printf "%s\n", $kgm_kmodp->name
465 # cached info of the last kext found, to speed up subsequent lookups
470 define showkmodaddrint
472 if ((unsigned long)$arg0 >= (unsigned long)$kgm_pkmodst) && ((unsigned long)$arg0 < (unsigned long)$kgm_pkmoden)
473 set $kgm_off = ((unsigned long)$arg0 - (unsigned long)$kgm_pkmodst)
474 printf " <%s + 0x%x>", $kgm_pkmod->name, $kgm_off
476 set $kgm_kmodp = (struct kmod_info *)kmod
477 if ($kgm_mtype == $kgm_mtype_x86_64) && ($arg0 >= (unsigned long)&_mh_execute_header)
478 # kexts are loaded below the kernel for x86_64
482 set $kgm_off = ((unsigned long)$arg0 - (unsigned long)$kgm_kmodp->address)
483 if ($kgm_kmodp->address <= $arg0) && ($kgm_off < $kgm_kmodp->size)
484 printf " <%s + 0x%x>", $kgm_kmodp->name, $kgm_off
485 set $kgm_pkmod = $kgm_kmodp
486 set $kgm_pkmodst = $kgm_kmodp->address
487 set $kgm_pkmoden = $kgm_pkmodst + $kgm_kmodp->size
490 set $kgm_kmodp = $kgm_kmodp->next
497 showkmodaddrint $arg0
499 document showkmodaddr
500 Syntax: (gdb) showkmodaddr <addr>
501 | Given an address, print the offset and name for the kmod containing it
509 Syntax: (gdb) showkmod <kmod>
510 | Routine to print info about a kext
517 Syntax: (gdb) showkext <kmod_info_address>
518 | Routine to print info about a kext
523 set $kgm_kmodp = (struct kmod_info *)kmod
525 showkmodint $kgm_kmodp
526 set $kgm_kmodp = $kgm_kmodp->next
529 document showallkmods
530 Syntax: (gdb) showallkmods
531 | Routine to print a summary listing of all loaded kexts
537 document showallkexts
538 Syntax: (gdb) showallkexts
539 | Routine to print a summary listing of all loaded kexts
542 # See OSKextVersion.c for the C code this is based on
544 set $KGM_OSKEXT_VERS_MAJ_MULT = 100000000
545 set $KGM_OSKEXT_VERS_MIN_MULT = 1000000
546 set $KGM_OSKEXT_VERS_REV_MULT = 10000
547 set $KGM_OSKEXT_VERS_STAGE_MULT = 1000
549 define printoskextversion
550 set $vers_scratch = $arg0
552 if ($vers_scratch == -1)
556 set $vers_major = $vers_scratch / $KGM_OSKEXT_VERS_MAJ_MULT
558 set $vers_scratch = $vers_scratch - ($vers_major * $KGM_OSKEXT_VERS_MAJ_MULT)
559 set $vers_minor = $vers_scratch / $KGM_OSKEXT_VERS_MIN_MULT
561 set $vers_scratch = $vers_scratch - ( $vers_minor * $KGM_OSKEXT_VERS_MIN_MULT)
562 set $vers_revision = $vers_scratch / $KGM_OSKEXT_VERS_REV_MULT
564 set $vers_scratch = $vers_scratch - ( $vers_revision * $KGM_OSKEXT_VERS_REV_MULT)
565 set $vers_stage = $vers_scratch / $KGM_OSKEXT_VERS_STAGE_MULT
567 set $vers_scratch = $vers_scratch - ( $vers_stage * $KGM_OSKEXT_VERS_STAGE_MULT)
568 set $vers_stagelevel = $vers_scratch
570 printf "%d.%d", $vers_major, $vers_minor
571 if ($vers_revision > 0)
572 printf ".%d", $vers_revision
575 if ($vers_stage == 1)
578 if ($vers_stage == 3)
581 if ($vers_stage == 5)
584 if ($vers_stage == 7)
587 if ($vers_stage == 1 || $vers_stage == 3 || $vers_stage == 5 || $vers_stage == 7)
588 printf "%d", $vers_stagelevel
593 define showallknownkexts
594 set $kext_count = sKextsByID->count
596 printf "%d kexts in sKextsByID:\n", $kext_count
603 printf " id name (version)\n"
605 while $kext_index < $kext_count
606 set $kext_id = sKextsByID->dictionary[$kext_index].key->string
607 set $oskext = (OSKext *)sKextsByID->dictionary[$kext_index].value
612 if ($oskext->flags.loaded)
613 showptr $oskext->kmod_info
615 printf "%3d", $oskext->loadTag
624 printf "%.64s (", $kext_id
625 printoskextversion (uint64_t)$oskext->version
627 set $kext_index = $kext_index + 1
630 document showallknownkexts
631 Syntax: (gdb) showallknownkexts
632 | Routine to print a summary listing of all kexts, loaded or not
644 printf " pri io_policy state wait_queue"
646 printf " wait_event\n"
653 set $kgm_thread = *(struct thread *)$arg0
655 if ($kgm_thread.static_param)
660 printf " 0x%llx ", $kgm_thread.thread_id
661 showptr $kgm_thread.last_processor
662 printf " %3d ", $kgm_thread.sched_pri
663 if ($kgm_thread.uthread != 0)
665 set $kgm_uthread = (struct uthread *)$kgm_thread.uthread
666 if ($kgm_uthread->uu_flag & 0x400)
672 if ($kgm_thread->ext_appliedstate.hw_disk != 0)
673 set $diskpolicy = $kgm_thread->ext_appliedstate.hw_disk
675 if ($kgm_thread->appliedstate.hw_disk != 0)
676 set $diskpolicy = $kgm_thread->appliedstate.hw_disk
679 if ($kgm_thread->ext_appliedstate.hw_bg != 0)
682 if ($kgm_thread->appliedstate.hw_bg != 0)
685 if ($diskpolicy == 2)
689 if ($diskpolicy == 3)
693 if ($diskpolicy == 4)
697 if ($diskpolicy == 5)
701 if ($kgm_printed == 0)
705 set $kgm_state = $kgm_thread.state
730 showptr $kgm_thread.wait_queue
732 if (((unsigned long)$kgm_thread.wait_event > (unsigned long)&last_kernel_symbol) \
733 && ($arg1 != 2) && ($kgm_show_kmod_syms == 0))
734 showkmodaddr $kgm_thread.wait_event
736 output /a $kgm_thread.wait_event
738 if ($kgm_thread.uthread != 0)
739 set $kgm_uthread = (struct uthread *)$kgm_thread.uthread
740 if ($kgm_uthread->uu_wmesg != 0)
741 printf "\t \"%s\"", $kgm_uthread->uu_wmesg
745 if ($kgm_thread.uthread != 0)
746 set $kgm_uthread = (struct uthread *)$kgm_thread.uthread
747 if ($kgm_uthread->pth_name && $kgm_uthread->pth_name[0])
748 printf "\n\t\tThread Name: %s", $kgm_uthread->pth_name
752 if ($kgm_thread.kernel_stack != 0)
753 if ($kgm_thread.uthread != 0)
755 set $kgm_uthread = (struct uthread *)$kgm_thread.uthread
756 if ($kgm_uthread->uu_kwe.kwe_kwqqueue != 0)
757 set $kwq = (ksyn_wait_queue_t)$kgm_uthread->uu_kwe.kwe_kwqqueue
758 printf " kwq_lockcount:0x%x; kwq_retval:0x%x", $kgm_uthread->uu_kwe.kwe_lockseq, $kgm_uthread->uu_kwe.kwe_psynchretval
764 if ($kgm_thread.reserved_stack != 0)
767 printf " reserved_stack="
768 showptr $kgm_thread.reserved_stack
772 printf " kernel_stack="
773 showptr $kgm_thread.kernel_stack
774 if ($kgm_mtype == $kgm_mtype_ppc)
775 set $mysp = $kgm_thread.machine.pcb->save_r1
777 if (($kgm_mtype & $kgm_mtype_x86_mask) == $kgm_mtype_x86_any)
778 set $kgm_statep = (struct x86_kernel_state *) \
779 ($kgm_thread->kernel_stack + kernel_stack_size \
780 - sizeof(struct x86_kernel_state))
781 if ($kgm_mtype == $kgm_mtype_i386)
782 set $mysp = $kgm_statep->k_ebp
784 set $mysp = $kgm_statep->k_rbp
787 if ($kgm_mtype == $kgm_mtype_arm)
788 if (((unsigned long)$r7 < ((unsigned long) ($kgm_thread->kernel_stack+kernel_stack_size))) \
789 && ((unsigned long)$r7 > (unsigned long) ($kgm_thread->kernel_stack)))
792 set $kgm_statep = (struct arm_saved_state *)$kgm_thread.machine.kstackptr
793 set $mysp = $kgm_statep->r[7]
796 set $prevsp = $mysp - 16
801 if ($kgm_mtype == $kgm_mtype_ppc)
807 set $kgm_actint_framecount = 0
808 while ($mysp != 0) && (($mysp & $stkmask) == 0) \
809 && ($mysp != $prevsp) \
810 && ((((unsigned long) $mysp - (unsigned long) $prevsp) < 0x4000) \
811 || (((unsigned long)$mysp < ((unsigned long) ($kgm_thread->kernel_stack+kernel_stack_size))) \
812 && ((unsigned long)$mysp > (unsigned long) ($kgm_thread->kernel_stack)))) \
813 && ($kgm_actint_framecount < 128)
815 set $kgm_actint_framecount = $kgm_actint_framecount + 1
820 if ($kgm_mtype == $kgm_mtype_ppc)
821 set $kgm_return = *($mysp + 8)
823 if ($kgm_mtype == $kgm_mtype_i386)
824 set $kgm_return = *($mysp + 4)
826 if ($kgm_mtype == $kgm_mtype_x86_64)
827 set $kgm_return = *(unsigned long *)($mysp + 8)
829 if ($kgm_mtype == $kgm_mtype_arm)
830 set $kgm_return = *($mysp + 4)
832 if (((unsigned long) $kgm_return < (unsigned long) &_mh_execute_header || \
833 (unsigned long) $kgm_return >= (unsigned long) &last_kernel_symbol ) \
834 && ($kgm_show_kmod_syms == 0))
835 showkmodaddr $kgm_return
837 output /a $kgm_return
840 set $mysp = *(unsigned long *)$mysp
845 printf " stackbottom="
850 printf " continuation="
851 output /a $kgm_thread.continuation
864 Syntax: (gdb) showact <activation>
865 | Routine to print out the state of a specific thread.
873 document showactstack
874 Syntax: (gdb) showactstack <activation>
875 | Routine to print out the stack of a specific thread.
879 define showallthreads
880 set $kgm_head_taskp = &tasks
881 set $kgm_taskp = (struct task *)($kgm_head_taskp->next)
882 while $kgm_taskp != $kgm_head_taskp
884 showtaskint $kgm_taskp
886 set $kgm_head_actp = &($kgm_taskp->threads)
887 set $kgm_actp = (struct thread *)($kgm_taskp->threads.next)
888 while $kgm_actp != $kgm_head_actp
889 showactint $kgm_actp 0
890 set $kgm_actp = (struct thread *)($kgm_actp->task_threads.next)
893 set $kgm_taskp = (struct task *)($kgm_taskp->tasks.next)
896 document showallthreads
897 Syntax: (gdb) showallthreads
898 | Routine to print out info about all threads in the system.
901 define showprocessorint
902 set $kgm_processor_int = (struct processor *)$arg0
904 showptr $kgm_processor_int
905 printf " State %d (cpu_id 0x%x)\n", ($kgm_processor_int)->state, ($kgm_processor_int)->cpu_id
908 define showcurrentthreads
909 set $kgm_prp = (struct processor *)processor_list
911 showprocessorint $kgm_prp
912 if ($kgm_prp)->active_thread != 0
913 set $kgm_actp = ($kgm_prp)->active_thread
915 showtaskint ($kgm_actp)->task
917 showactint $kgm_actp 0
920 set $kgm_prp = ($kgm_prp)->processor_list
923 document showcurrentthreads
924 Syntax: (gdb) showcurrentthreads
925 | Routine to print out info about the thread running on each cpu.
930 set $kgm_runq = (struct run_queue *)$arg0
932 printf " Priority Run Queue Info: Count %d\n", $kgm_runq->count
933 set $kgm_runq_queue_i = 0
934 set $kgm_runq_queue_count = sizeof($kgm_runq->queues)/sizeof($kgm_runq->queues[0])
935 while $kgm_runq->count && $kgm_runq_queue_i < $kgm_runq_queue_count
936 set $kgm_runq_queue_head = &$kgm_runq->queues[$kgm_runq_queue_i]
937 set $kgm_runq_queue_p = $kgm_runq_queue_head->next
938 if $kgm_runq_queue_p != $kgm_runq_queue_head
939 set $kgm_runq_queue_this_count = 0
940 while $kgm_runq_queue_p != $kgm_runq_queue_head
941 set $kgm_runq_queue_this_count = $kgm_runq_queue_this_count + 1
942 showtask ((thread_t)$kgm_runq_queue_p)->task
943 showactstack $kgm_runq_queue_p
944 set $kgm_runq_queue_p = $kgm_runq_queue_p->next
946 printf " Queue Priority %3d [", $kgm_runq_queue_i
947 showptr $kgm_runq_queue_head
948 printf "] Count %d\n", $kgm_runq_queue_this_count
950 set $kgm_runq_queue_i = $kgm_runq_queue_i + 1
956 set $kgm_grrr_runq = $arg0
958 printf " GRRR Info: Count %d Weight %d Current Group ", $kgm_grrr_runq->count, $kgm_grrr_runq->weight
959 showptr $kgm_grrr_runq->current_group
961 set $kgm_grrr_group_i = 0
962 set $kgm_grrr_group_count = sizeof($kgm_grrr_runq->groups)/sizeof($kgm_grrr_runq->groups[0])
963 while $kgm_grrr_runq->count && $kgm_grrr_group_i < $kgm_grrr_group_count
964 set $kgm_grrr_group = &$kgm_grrr_runq->groups[$kgm_grrr_group_i]
965 if $kgm_grrr_group->count > 0
966 printf " Group %3d [", $kgm_grrr_group->index
967 showptr $kgm_grrr_group
968 printf "] Count %d Weight %d\n", $kgm_grrr_group->count, $kgm_grrr_group->weight
969 set $kgm_grrr_group_client_head = &$kgm_grrr_group->clients
970 set $kgm_grrr_group_client = $kgm_grrr_group_client_head->next
971 while $kgm_grrr_group_client != $kgm_grrr_group_client_head
972 # showtask ((thread_t)$kgm_grrr_group_client)->task
973 # showactstack $kgm_grrr_group_client
974 set $kgm_grrr_group_client = $kgm_grrr_group_client->next
977 set $kgm_grrr_group_i = $kgm_grrr_group_i + 1
981 define showallprocessors
982 set $kgm_pset = &pset0
984 set $kgm_show_grrr = 0
985 set $kgm_show_priority_runq = 0
986 set $kgm_show_priority_pset_runq = 0
987 set $kgm_show_fairshare_grrr = 0
988 set $kgm_show_fairshare_list = 0
991 set $kgm_show_priority_runq = 1
992 set $kgm_show_fairshare_list = 1
995 set $kgm_show_priority_pset_runq = 1
996 set $kgm_show_fairshare_list = 1
999 set $kgm_show_grrr = 1
1000 set $kgm_show_fairshare_grrr = 1
1003 set $kgm_show_priority_runq = 1
1004 set $kgm_show_fairshare_list = 1
1007 set $kgm_show_priority_pset_runq = 1
1008 set $kgm_show_fairshare_list = 1
1011 while $kgm_pset != 0
1012 printf "Processor Set "
1014 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
1015 printf " Active Processors:\n"
1016 set $kgm_active_queue_head = &($kgm_pset)->active_queue
1017 set $kgm_active_elt = $kgm_active_queue_head->next
1018 while $kgm_active_elt != $kgm_active_queue_head
1019 set $kgm_processor = (processor_t)$kgm_active_elt
1021 showprocessorint $kgm_processor
1023 if $kgm_show_priority_runq
1024 set $kgm_runq = &$kgm_processor->runq
1025 _showrunqint $kgm_runq
1028 set $kgm_grrr_runq = &$kgm_processor->grrr_runq
1029 _showgrrrint $kgm_grrr_runq
1032 if $kgm_processor->processor_meta != 0 && $kgm_processor->processor_meta->primary == $kgm_processor
1033 set $kgm_processor_meta_idle_head = &$kgm_processor->processor_meta->idle_queue
1034 set $kgm_processor_meta_idle = $kgm_processor_meta_idle_head->next
1035 while $kgm_processor_meta_idle != $kgm_processor_meta_idle_head
1036 printf " Idle Meta Processor: "
1037 showprocessorint $kgm_processor_meta_idle
1038 set $kgm_processor_meta_idle = $kgm_processor_meta_idle->next
1042 set $kgm_active_elt = $kgm_active_elt->next
1044 printf " Idle Processors:\n"
1045 set $kgm_idle_queue_head = &($kgm_pset)->idle_queue
1046 set $kgm_idle_elt = $kgm_idle_queue_head->next
1047 while $kgm_idle_elt != $kgm_idle_queue_head
1048 set $kgm_processor = (processor_t)$kgm_idle_elt
1050 showprocessorint $kgm_processor
1052 if $kgm_processor->processor_meta != 0 && $kgm_processor->processor_meta->primary == $kgm_processor
1053 set $kgm_processor_meta_idle_head = &$kgm_processor->processor_meta->idle_queue
1054 set $kgm_processor_meta_idle = $kgm_processor_meta_idle_head->next
1055 while $kgm_processor_meta_idle != $kgm_processor_meta_idle_head
1056 printf " Idle Meta Processor: "
1057 showprocessorint $kgm_processor_meta_idle
1058 set $kgm_processor_meta_idle = $kgm_processor_meta_idle->next
1062 set $kgm_idle_elt = $kgm_idle_elt->next
1065 if $kgm_show_priority_pset_runq
1066 set $kgm_runq = &$kgm_pset->pset_runq
1068 _showrunqint $kgm_runq
1070 set $kgm_pset = ($kgm_pset)->pset_list
1074 printf "Realtime Queue Count %d\n", rt_runq.count
1075 set $kgm_rt_runq_head = &rt_runq.queue
1076 set $kgm_rt_runq = $kgm_rt_runq_head->next
1077 while $kgm_rt_runq != $kgm_rt_runq_head
1078 showtask ((thread_t)$kgm_rt_runq)->task
1079 showact $kgm_rt_runq
1080 set $kgm_rt_runq = $kgm_rt_runq->next
1084 if $kgm_show_fairshare_list
1085 printf "Fair Share Queue Count %d\n", fs_runq.count
1086 set $kgm_fs_runq_head = &fs_runq.queue
1087 set $kgm_fs_runq = $kgm_fs_runq_head->next
1088 while $kgm_fs_runq != $kgm_fs_runq_head
1089 showtask ((thread_t)$kgm_fs_runq)->task
1090 showact $kgm_fs_runq
1091 set $kgm_fs_runq = $kgm_fs_runq->next
1094 if $kgm_show_fairshare_grrr
1095 printf "Fair Share Queue Count %d\n", fs_grrr_runq.count
1096 set $kgm_fs_grrr = &fs_grrr_runq
1097 _showgrrrint $kgm_fs_grrr
1100 document showallprocessors
1101 Syntax: (gdb) showallprocessors
1102 | Routine to print out info about all psets and processors
1105 set $decode_wait_events = 0
1106 define showallstacks
1107 set $kgm_head_taskp = &tasks
1108 set $kgm_taskp = (struct task *)($kgm_head_taskp->next)
1109 while $kgm_taskp != $kgm_head_taskp
1111 showtaskint $kgm_taskp
1112 set $kgm_head_actp = &($kgm_taskp->threads)
1113 set $kgm_actp = (struct thread *)($kgm_taskp->threads.next)
1114 while $kgm_actp != $kgm_head_actp
1116 if ($decode_wait_events > 0)
1117 showactint $kgm_actp 1
1119 showactint $kgm_actp 2
1121 set $kgm_actp = (struct thread *)($kgm_actp->task_threads.next)
1124 set $kgm_taskp = (struct task *)($kgm_taskp->tasks.next)
1127 printf "\nZombie Processes:\n"
1131 document showallstacks
1132 Syntax: (gdb) showallstacks
1133 | Routine to print out the stack for each thread in the system.
1134 | If the variable $decode_wait_events is non-zero, the routine attempts to
1135 | interpret thread wait_events as kernel module offsets, which can add to
1139 define showcurrentstacks
1140 set $kgm_prp = processor_list
1142 showprocessorint $kgm_prp
1143 if ($kgm_prp)->active_thread != 0
1144 set $kgm_actp = ($kgm_prp)->active_thread
1146 showtaskint ($kgm_actp)->task
1148 showactint $kgm_actp 1
1151 set $kgm_prp = ($kgm_prp)->processor_list
1155 document showcurrentstacks
1156 Syntax: (gdb) showcurrentstacks
1157 | Routine to print out the thread running on each cpu (incl. its stack)
1160 define showwaiterheader
1161 printf "waiters thread "
1162 printf "processor pri state wait_queue wait_event\n"
1165 define showwaitqwaiters
1166 set $kgm_w_waitqp = (WaitQueue*)$arg0
1167 set $kgm_w_linksp = &($kgm_w_waitqp->wq_queue)
1168 set $kgm_w_wqe = (WaitQueueElement *)$kgm_w_linksp->next
1169 set $kgm_w_found = 0
1170 while ( (queue_entry_t)$kgm_w_wqe != (queue_entry_t)$kgm_w_linksp)
1171 if ($kgm_w_wqe->wqe_type != &_wait_queue_link)
1173 set $kgm_w_found = 1
1176 set $kgm_w_shuttle = (struct thread *)$kgm_w_wqe
1177 showactint $kgm_w_shuttle 0
1179 set $kgm_w_wqe = (WaitQueueElement *)$kgm_w_wqe->wqe_links.next
1183 define showwaitqwaitercount
1184 set $kgm_wc_waitqp = (WaitQueue*)$arg0
1185 set $kgm_wc_linksp = &($kgm_wc_waitqp->wq_queue)
1186 set $kgm_wc_wqe = (WaitQueueElement *)$kgm_wc_linksp->next
1187 set $kgm_wc_count = 0
1188 while ( (queue_entry_t)$kgm_wc_wqe != (queue_entry_t)$kgm_wc_linksp)
1189 if ($kgm_wc_wqe->wqe_type != &_wait_queue_link)
1190 set $kgm_wc_count = $kgm_wc_count + 1
1192 set $kgm_wc_wqe = (WaitQueueElement *)$kgm_wc_wqe->wqe_links.next
1194 printf "0x%08x ", $kgm_wc_count
1197 define showwaitqmembercount
1198 set $kgm_mc_waitqsetp = (WaitQueueSet*)$arg0
1199 set $kgm_mc_setlinksp = &($kgm_mc_waitqsetp->wqs_setlinks)
1200 set $kgm_mc_wql = (WaitQueueLink *)$kgm_mc_setlinksp->next
1201 set $kgm_mc_count = 0
1202 while ( (queue_entry_t)$kgm_mc_wql != (queue_entry_t)$kgm_mc_setlinksp)
1203 set $kgm_mc_count = $kgm_mc_count + 1
1204 set $kgm_mc_wql = (WaitQueueLink *)$kgm_mc_wql->wql_setlinks.next
1206 printf "0x%08x ", $kgm_mc_count
1210 define showwaitqmemberheader
1211 printf "set-members wait_queue interlock "
1212 printf "pol type member_cnt waiter_cnt\n"
1215 define showwaitqmemberint
1216 set $kgm_m_waitqp = (WaitQueue*)$arg0
1217 printf " 0x%08x ", $kgm_m_waitqp
1218 printf "0x%08x ", $kgm_m_waitqp->wq_interlock.lock_data
1219 if ($kgm_m_waitqp->wq_fifo)
1224 if ($kgm_m_waitqp->wq_type == 0xf1d1)
1226 showwaitqmembercount $kgm_m_waitqp
1228 printf "Que 0x00000000 "
1230 showwaitqwaitercount $kgm_m_waitqp
1235 define showwaitqmemberofheader
1236 printf "member-of wait_queue interlock "
1237 printf "pol type member_cnt waiter_cnt\n"
1240 define showwaitqmemberof
1241 set $kgm_mo_waitqp = (WaitQueue*)$arg0
1242 set $kgm_mo_linksp = &($kgm_mo_waitqp->wq_queue)
1243 set $kgm_mo_wqe = (WaitQueueElement *)$kgm_mo_linksp->next
1244 set $kgm_mo_found = 0
1245 while ( (queue_entry_t)$kgm_mo_wqe != (queue_entry_t)$kgm_mo_linksp)
1246 if ($kgm_mo_wqe->wqe_type == &_wait_queue_link)
1248 set $kgm_mo_found = 1
1249 showwaitqmemberofheader
1251 set $kgm_mo_wqlp = (WaitQueueLink *)$kgm_mo_wqe
1252 set $kgm_mo_wqsetp = (WaitQueue*)($kgm_mo_wqlp->wql_setqueue)
1253 showwaitqmemberint $kgm_mo_wqsetp
1255 set $kgm_mo_wqe = (WaitQueueElement *)$kgm_mo_wqe->wqe_links.next
1259 define showwaitqmembers
1260 set $kgm_ms_waitqsetp = (WaitQueueSet*)$arg0
1261 set $kgm_ms_setlinksp = &($kgm_ms_waitqsetp->wqs_setlinks)
1262 set $kgm_ms_wql = (WaitQueueLink *)$kgm_ms_setlinksp->next
1263 set $kgm_ms_found = 0
1264 while ( (queue_entry_t)$kgm_ms_wql != (queue_entry_t)$kgm_ms_setlinksp)
1265 set $kgm_ms_waitqp = $kgm_ms_wql->wql_element.wqe_queue
1267 showwaitqmemberheader
1268 set $kgm_ms_found = 1
1270 showwaitqmemberint $kgm_ms_waitqp
1271 set $kgm_ms_wql = (WaitQueueLink *)$kgm_ms_wql->wql_setlinks.next
1275 define showwaitqheader
1276 printf "wait_queue ref_count interlock "
1277 printf "pol type member_cnt waiter_cnt\n"
1281 set $kgm_waitqp = (WaitQueue*)$arg0
1282 printf "0x%08x ", $kgm_waitqp
1283 if ($kgm_waitqp->wq_type == 0xf1d1)
1284 printf "0x%08x ", ((WaitQueueSet*)$kgm_waitqp)->wqs_refcount
1286 printf "0x00000000 "
1288 printf "0x%08x ", $kgm_waitqp->wq_interlock.lock_data
1289 if ($kgm_waitqp->wq_fifo)
1294 if ($kgm_waitqp->wq_type == 0xf1d1)
1296 showwaitqmembercount $kgm_waitqp
1298 printf "Que 0x00000000 "
1300 showwaitqwaitercount $kgm_waitqp
1305 set $kgm_waitq1p = (WaitQueue*)$arg0
1307 showwaitqint $kgm_waitq1p
1308 if ($kgm_waitq1p->wq_type == 0xf1d1)
1309 showwaitqmembers $kgm_waitq1p
1311 showwaitqmemberof $kgm_waitq1p
1313 showwaitqwaiters $kgm_waitq1p
1316 define showmapheader
1323 printf " #ents rpage hint "
1325 printf " first_free\n"
1328 define showvmeheader
1331 printf " start prot #page object "
1337 set $kgm_mapp = (vm_map_t)$arg0
1338 set $kgm_map = *$kgm_mapp
1341 showptr $kgm_map.pmap
1343 showptr $kgm_map.size
1344 printf " %3d ", $kgm_map.hdr.nentries
1346 printf "%5d ", $kgm_map.pmap->stats.resident_count
1350 showptr $kgm_map.hint
1352 showptr $kgm_map.first_free
1356 set $kgm_head_vmep = &($kgm_mapp->hdr.links)
1357 set $kgm_vmep = $kgm_map.hdr.links.next
1358 while (($kgm_vmep != 0) && ($kgm_vmep != $kgm_head_vmep))
1359 set $kgm_vme = *$kgm_vmep
1362 printf " 0x%016llx ", $kgm_vme.links.start
1363 printf "%1x", $kgm_vme.protection
1364 printf "%1x", $kgm_vme.max_protection
1365 if $kgm_vme.inheritance == 0x0
1368 if $kgm_vme.inheritance == 0x1
1371 if $kgm_vme.inheritance == 0x2
1374 if $kgm_vme.inheritance == 0x3
1377 if $kgm_vme.is_sub_map
1380 if $kgm_vme.needs_copy
1386 printf "%6d ",($kgm_vme.links.end - $kgm_vme.links.start) >> 12
1387 showptr $kgm_vme.object.vm_object
1388 printf " 0x%016llx\n", $kgm_vme.offset
1389 set $kgm_vmep = $kgm_vme.links.next
1396 define showmapwiredp
1397 set $kgm_mapp = (vm_map_t)$arg0
1398 set $kgm_map = *$kgm_mapp
1399 set $kgm_head_vmep = &($kgm_mapp->hdr.links)
1400 set $kgm_vmep = $kgm_map.hdr.links.next
1401 set $kgm_objp_prev = (struct vm_object *)0
1403 set $kgm_saw_kernel_obj = 0
1404 set $kgm_wired_count = 0
1405 set $kgm_objp_print_space = 1
1407 set $kgm_objp_print_space = 0
1409 while (($kgm_vmep != 0) && ($kgm_vmep != $kgm_head_vmep))
1410 set $kgm_vme = *$kgm_vmep
1411 set $kgm_objp = $kgm_vme.object.vm_object
1412 if $kgm_vme.is_sub_map
1414 set $kgm_mapp_orig = $kgm_mapp
1415 set $kgm_vmep_orig = $kgm_vmep
1416 set $kgm_vme_orig = $kgm_vme
1417 set $kgm_head_vmep_orig = $kgm_head_vmep
1420 showmapwiredp $kgm_objp 1
1421 set $kgm_vme = $kgm_vme_orig
1422 set $kgm_vmep = $kgm_vmep_orig
1423 set $kgm_mapp = $kgm_mapp_orig
1424 set $kgm_head_vmep = $kgm_head_vmep_orig
1425 set $kgm_objp = (struct vm_object *)0
1431 set $kgm_objp = (struct vm_object *)0
1435 if ($kgm_objp == $kgm_objp_prev)
1436 set $kgm_objp = (struct vm_object *)0
1438 if $kgm_objp == kernel_object
1439 if $kgm_saw_kernel_obj
1440 set $kgm_objp = (struct vm_object *)0
1442 set $kgm_saw_kernel_obj = 1
1444 if $kgm_objp && $kgm_objp->wired_page_count
1445 if $kgm_objp_print_space == 1
1449 set $kgm_objp_print_space = 1
1452 printf " 0x%016llx ", $kgm_vme.links.start
1453 printf "%5d", $kgm_vme.alias
1454 printf "%6d ",($kgm_vme.links.end - $kgm_vme.links.start) >> 12
1456 printf "[%3d]", $kgm_objp->ref_count
1457 printf "%7d\n", $kgm_objp->wired_page_count
1458 set $kgm_wired_count = $kgm_wired_count + $kgm_objp->wired_page_count
1459 set $kgm_objp_prev = $kgm_objp
1461 set $kgm_vmep = $kgm_vme.links.next
1464 printf "total wired count = %d\n", $kgm_wired_count
1473 printf " start alias #page object "
1476 showmapwiredp $arg0 0
1478 document showmapwired
1479 Syntax: (gdb) showmapwired <vm_map>
1480 | Routine to print out a summary listing of all the entries with wired pages in a vm_map
1488 Syntax: (gdb) showmapvme <vm_map>
1489 | Routine to print out a summary listing of all the entries in a vm_map
1498 Syntax: (gdb) showmap <vm_map>
1499 | Routine to print out info about the specified vm_map
1503 set $kgm_head_taskp = &tasks
1504 set $kgm_taskp = (struct task *)($kgm_head_taskp->next)
1505 while $kgm_taskp != $kgm_head_taskp
1508 showtaskint $kgm_taskp
1509 showvmint $kgm_taskp->map 0
1510 set $kgm_taskp = (struct task *)($kgm_taskp->tasks.next)
1514 Syntax: (gdb) showallvm
1515 | Routine to print a summary listing of all the vm maps
1520 set $kgm_head_taskp = &tasks
1521 set $kgm_taskp = (struct task *)($kgm_head_taskp->next)
1522 while $kgm_taskp != $kgm_head_taskp
1525 showtaskint $kgm_taskp
1526 showvmint $kgm_taskp->map 1
1527 set $kgm_taskp = (struct task *)($kgm_taskp->tasks.next)
1531 Syntax: (gdb) showallvme
1532 | Routine to print a summary listing of all the vm map entries
1536 define showipcheader
1543 printf " flags ports table_next "
1545 printf " low_mod high_mod\n"
1548 define showipceheader
1554 printf "name rite urefs destname "
1556 printf "destination\n"
1560 set $kgm_ie = *(ipc_entry_t)$arg0
1563 showptr $kgm_ie.ie_object
1565 printf " 0x%08x ", $arg1
1566 if $kgm_ie.ie_bits & 0x00100000
1568 printf "%5d\n", $kgm_ie.ie_bits & 0xffff
1570 if $kgm_ie.ie_bits & 0x00080000
1572 printf "%5d\n", $kgm_ie.ie_bits & 0xffff
1574 if $kgm_ie.ie_bits & 0x00010000
1575 if $kgm_ie.ie_bits & 0x00020000
1581 if $kgm_ie.ie_bits & 0x00020000
1585 if $kgm_ie.ie_bits & 0x00040000
1588 if $kgm_ie.index.request
1589 set $kgm_port = (ipc_port_t)$kgm_ie.ie_object
1590 set $kgm_requests = $kgm_port->ip_requests
1591 set $kgm_req_soright = $kgm_requests[$kgm_ie.index.request].notify.port
1593 # Armed send-possible notification?
1594 if (uintptr_t)$kgm_req_soright & 0x1
1597 # Delayed send-possible notification?
1598 if (uintptr_t)$kgm_req_soright & 0x2
1601 # Dead-name notification
1611 # Collision (with tree)?
1612 if $kgm_ie.ie_bits & 0x00800000
1617 printf "%5d ", $kgm_ie.ie_bits & 0xffff
1618 showportdest $kgm_ie.ie_object
1624 set $kgm_isp = (ipc_space_t)$arg0
1625 set $kgm_is = *$kgm_isp
1628 showptr $kgm_is.is_task
1630 showptr $kgm_is.is_table
1632 if ($kgm_is.is_bits & 0x40000000) == 0
1637 if ($kgm_is.is_bits & 0x20000000) != 0
1642 printf "%5d ", $kgm_is.is_table_size
1643 showptr $kgm_is.is_table_next
1645 printf "%10d ", $kgm_is.is_low_mod
1646 printf "%10d", $kgm_is.is_high_mod
1651 set $kgm_iep = $kgm_is.is_table
1652 set $kgm_destspacep = (ipc_space_t)0
1653 while ( $kgm_iindex < $kgm_is.is_table_size )
1654 set $kgm_ie = *$kgm_iep
1655 if $kgm_ie.ie_bits & 0x001f0000
1656 set $kgm_name = (($kgm_iindex << 8)|($kgm_ie.ie_bits >> 24))
1657 showipceint $kgm_iep $kgm_name
1659 if $kgm_ie.ie_object != 0 && ($kgm_ie.ie_bits & 0x00070000) && ((ipc_port_t) $kgm_ie.ie_object)->ip_callstack[0] != 0
1661 showportbt $kgm_ie.ie_object $kgm_is.is_task
1665 set $kgm_iindex = $kgm_iindex + 1
1666 set $kgm_iep = &($kgm_is.is_table[$kgm_iindex])
1674 set $kgm_isp = (ipc_space_t)$arg0
1676 showipcint $kgm_isp 0 0
1679 Syntax: (gdb) showipc <ipc_space>
1680 | Routine to print the status of the specified ipc space
1684 set $kgm_isp = (ipc_space_t)$arg0
1686 showipcint $kgm_isp 1 0
1689 Syntax: (gdb) showrights <ipc_space>
1690 | Routine to print a summary list of all the rights in a specified ipc space
1695 set $kgm_taskp = (task_t)$arg0
1697 showtaskint $kgm_taskp
1699 showipcint $kgm_taskp->itk_space 0 0
1701 document showtaskipc
1702 Syntax: (gdb) showtaskipc <task>
1703 | Routine to print info about the ipc space for a task
1707 define showtaskrights
1708 set $kgm_taskp = (task_t)$arg0
1710 showtaskint $kgm_taskp
1712 showipcint $kgm_taskp->itk_space 1 0
1714 document showtaskrights
1715 Syntax: (gdb) showtaskrights <task>
1716 | Routine to print info about the ipc rights for a task
1719 define showtaskrightsbt
1720 set $kgm_taskp = (task_t)$arg0
1722 showtaskint $kgm_taskp
1724 showipcint $kgm_taskp->itk_space 1 1
1726 document showtaskrightsbt
1727 Syntax: (gdb) showtaskrightsbt <task>
1728 | Routine to print info about the ipc rights for a task with backtraces
1732 set $kgm_head_taskp = &tasks
1733 set $kgm_cur_taskp = (struct task *)($kgm_head_taskp->next)
1734 while $kgm_cur_taskp != $kgm_head_taskp
1736 showtaskint $kgm_cur_taskp
1738 showipcint $kgm_cur_taskp->itk_space 0 0
1739 set $kgm_cur_taskp = (struct task *)($kgm_cur_taskp->tasks.next)
1743 Syntax: (gdb) showallipc
1744 | Routine to print a summary listing of all the ipc spaces
1747 define showipcsumheader
1756 define showipcsummaryint
1757 set $kgm_taskp = (struct task *)$arg0
1759 printf "%7d", ((struct proc *)$kgm_taskp->bsd_info)->p_pid
1760 printf "%15d", $kgm_taskp->thread_count
1761 printf "%15d", $kgm_cur_taskp->itk_space.is_table_size
1762 printf " %s\n", ((struct proc *)$kgm_taskp->bsd_info)->p_comm
1765 define showipcsummary
1767 set $kgm_head_taskp = &tasks
1768 set $kgm_cur_taskp = (struct task *)($kgm_head_taskp->next)
1769 while $kgm_cur_taskp != $kgm_head_taskp
1770 showipcsummaryint $kgm_cur_taskp
1771 set $kgm_cur_taskp = (struct task *)($kgm_cur_taskp->tasks.next)
1775 document showipcsummary
1776 Syntax: (gdb) showipcsummary
1777 | Summarizes the IPC state of all tasks. This is a convenient way to dump
1778 | some basic clues about IPC messaging. You can use the output to determine
1779 | tasks that are candidates for further investigation.
1783 define showallrights
1784 set $kgm_head_taskp = &tasks
1785 set $kgm_cur_taskp = (struct task *)($kgm_head_taskp->next)
1786 while $kgm_cur_taskp != $kgm_head_taskp
1788 showtaskint $kgm_cur_taskp
1790 showipcint $kgm_cur_taskp->itk_space 1 0
1791 set $kgm_cur_taskp = (struct task *)($kgm_cur_taskp->tasks.next)
1794 document showallrights
1795 Syntax: (gdb) showallrights
1796 | Routine to print a summary listing of all the ipc rights
1801 set $kgm_taskp = (task_t)$arg0
1804 showtaskint $kgm_taskp
1805 showvmint $kgm_taskp->map 0
1808 Syntax: (gdb) showtaskvm <task>
1809 | Routine to print out info about a task's vm_map
1813 set $kgm_taskp = (task_t)$arg0
1815 showtaskint $kgm_taskp
1817 showvmint $kgm_taskp->map 1
1819 document showtaskvme
1820 Syntax: (gdb) showtaskvme <task>
1821 | Routine to print out info about a task's vm_map_entries
1825 define showtaskheader
1830 printf " ipc_space "
1838 set $kgm_taskp = (struct task *)$arg0
1841 showptr $kgm_taskp->map
1843 showptr $kgm_taskp->itk_space
1844 printf " %5d ", $kgm_taskp->thread_count
1845 showprocint $kgm_taskp->bsd_info
1853 Syntax (gdb) showtask <task>
1854 | Routine to print out info about a task.
1858 define showtaskthreads
1860 set $kgm_taskp = (struct task *)$arg0
1861 showtaskint $kgm_taskp
1863 set $kgm_head_actp = &($kgm_taskp->threads)
1864 set $kgm_actp = (struct thread *)($kgm_taskp->threads.next)
1865 while $kgm_actp != $kgm_head_actp
1866 showactint $kgm_actp 0
1867 set $kgm_actp = (struct thread *)($kgm_actp->task_threads.next)
1870 document showtaskthreads
1871 Syntax: (gdb) showtaskthreads <task>
1872 | Routine to print info about the threads in a task.
1876 define showtaskstacks
1878 set $kgm_taskp = (struct task *)$arg0
1879 showtaskint $kgm_taskp
1880 set $kgm_head_actp = &($kgm_taskp->threads)
1881 set $kgm_actp = (struct thread *)($kgm_taskp->threads.next)
1882 while $kgm_actp != $kgm_head_actp
1884 showactint $kgm_actp 1
1885 set $kgm_actp = (struct thread *)($kgm_actp->task_threads.next)
1888 document showtaskstacks
1889 Syntax: (gdb) showtaskstacks <task>
1890 | Routine to print out the stack for each thread in a task.
1893 define showqueue_elems
1894 set $queue_head = (struct queue_entry *)($arg0)
1895 set $queue = (struct queue_entry *)($queue_head->next)
1896 while $queue != $queue_head
1899 set $thread = (struct thread *)$queue
1900 set $task = (struct task *)$thread->task
1901 set $bsd = (struct proc *)$task->bsd_info
1902 set $guy = (char *)$bsd->p_comm
1910 #printf " %s\n", $kgm_procp->p_comm
1912 set $queue = (struct queue_entry *)($queue->next)
1918 set $kgm_head_taskp = &tasks
1919 set $kgm_taskp = (struct task *)($kgm_head_taskp->next)
1920 while $kgm_taskp != $kgm_head_taskp
1921 showtaskint $kgm_taskp
1922 set $kgm_taskp = (struct task *)($kgm_taskp->tasks.next)
1925 document showalltasks
1926 Syntax: (gdb) showalltasks
1927 | Routine to print a summary listing of all the tasks
1928 | wq_state -> reports "number of workq threads", "number of scheduled workq threads", "number of pending work items"
1929 | if "number of pending work items" seems stuck at non-zero, it may indicate that the workqueue mechanism is hung
1930 | io_policy -> RAGE - rapid aging of vnodes requested
1931 | NORM - normal I/O explicitly requested (this is the default)
1932 | PASS - passive I/O requested (i.e. I/Os do not affect throttling decisions)
1933 | THROT - throttled I/O requested (i.e. thread/task may be throttled after each I/O completes)
1936 define showprocheader
1937 printf " pid process "
1939 printf "io_policy wq_state command\n"
1943 set $kgm_procp = (struct proc *)$arg0
1945 set $kgm_printed = 0
1946 printf "%5d ", $kgm_procp->p_pid
1948 if ($kgm_procp->p_lflag & 0x400000)
1953 set $ptask = (struct task *)$kgm_procp->task
1955 if ($ptask->ext_appliedstate.hw_disk != 0)
1956 set $diskpolicy = $ptask->ext_appliedstate.hw_disk
1958 if ($ptask->appliedstate.hw_disk != 0)
1959 set $diskpolicy = $ptask->appliedstate.hw_disk
1962 if ($ptask->ext_appliedstate.hw_bg != 0)
1965 if ($ptask->appliedstate.hw_bg != 0)
1968 if ($ptask->ext_appliedstate.apptype == 2)
1971 if ($diskpolicy == 2)
1973 set $kgm_printed = 1
1975 if ($diskpolicy == 3)
1977 set $kgm_printed = 1
1979 if ($diskpolicy == 4)
1981 set $kgm_printed = 1
1983 if ($diskpolicy == 5)
1985 set $kgm_printed = 1
1987 if ($diskpolicy == 6)
1989 set $kgm_printed = 1
1991 if ($kgm_printed == 0)
1994 set $kgm_wqp = (struct workqueue *)$kgm_procp->p_wqptr
1996 printf " %2d %2d %2d ", $kgm_wqp->wq_nthreads, $kgm_wqp->wq_thidlecount, $kgm_wqp->wq_reqcount
2000 printf " %s\n", $kgm_procp->p_comm
2010 set $kgm_head_taskp = &tasks
2011 set $kgm_taskp = (struct task *)($kgm_head_taskp->next)
2012 while $kgm_taskp != $kgm_head_taskp
2013 set $kgm_procp = (struct proc *)$kgm_taskp->bsd_info
2014 if (($kgm_procp != 0) && ($kgm_procp->p_pid == $arg0))
2015 showtaskint $kgm_taskp
2016 set $kgm_taskp = $kgm_head_taskp
2018 set $kgm_taskp = (struct task *)($kgm_taskp->tasks.next)
2023 Syntax: (gdb) showpid <pid>
2024 | Routine to print a single process by pid
2029 set $kgm_procp = (struct proc *)$arg0
2030 showtaskint $kgm_procp->task
2035 set switch_debugger=1
2039 | kdb - Switch to the inline kernel debugger
2043 | The kdb macro allows you to invoke the inline kernel debugger.
2046 define showpsetheader
2052 printf "recvname flags refs recvname "
2057 define showportheader
2063 printf "recvname flags refs recvname "
2068 define showportmemberheader
2075 printf "flags refs mqueue "
2080 define showkmsgheader
2088 printf "reply-port "
2093 define showkmsgsrcint
2094 set $kgm_kmsgsrchp = ((ipc_kmsg_t)$arg0)->ikm_header
2095 # set $kgm_kmsgsrctp = (mach_msg_audit_trailer_t *)((uintptr_t)$kgm_kmsgsrchp + $kgm_kmsgsrchp->msgh_size)
2096 # set $kgm_kmsgpid = $kgm_kmsgsrctp->msgh_audit.val[5]
2097 set $kgm_kmsgpid = (pid_t)((uint *)((uintptr_t)$kgm_kmsgsrchp + $kgm_kmsgsrchp->msgh_size))[10]
2098 # compare against a well-known or cached value as this may be slow
2099 if ($kgm_kmsgpid == 0)
2100 set $kgm_kmsgsrcpid = (pid_t)0
2101 set $kgm_kmsgsrcprocp = (struct proc *)kernel_task->bsd_info
2103 if ($kgm_kmsgpid != $kgm_kmsgsrcpid)
2104 set $kgm_kmsgsrchead_taskp = &tasks
2105 set $kgm_kmsgsrctaskp = (struct task *)($kgm_kmsgsrchead_taskp->next)
2106 while $kgm_kmsgsrctaskp != $kgm_kmsgsrchead_taskp
2107 set $kgm_kmsgsrcprocp = (struct proc *)$kgm_kmsgsrctaskp->bsd_info
2108 set $kgm_kmsgsrcpid = $kgm_kmsgsrcprocp->p_pid
2109 if (($kgm_kmsgsrcprocp != 0) && ($kgm_kmsgsrcprocp->p_pid == $kgm_kmsgpid))
2110 set $kgm_kmsgsrctaskp = $kgm_kmsgsrchead_taskp
2112 set $kgm_kmsgsrctaskp = (struct task *)($kgm_kmsgsrctaskp->tasks.next)
2117 if ($kgm_kmsgsrcprocp->p_pid == $kgm_kmsgpid)
2118 printf "%s(%d)\n", $kgm_kmsgsrcprocp->p_comm, $kgm_kmsgpid
2120 printf "unknown(%d)\n", $kgm_kmsgpid
2125 set $kgm_kmsghp = ((ipc_kmsg_t)$arg0)->ikm_header
2126 set $kgm_kmsgh = *$kgm_kmsghp
2131 showptr $kgm_kmsgh.msgh_remote_port
2135 printf " 0x%08x ", $kgm_kmsgh.msgh_id
2136 if (($kgm_kmsgh.msgh_bits & 0xff) == 19)
2141 if (($kgm_kmsgh.msgh_bits & 0xff00) == (19 << 8))
2146 if ($kgm_kmsgh.msgh_bits & 0xf0000000)
2151 printf "%5d ", $kgm_kmsgh.msgh_size
2152 showptr $kgm_kmsgh.msgh_local_port
2154 set $kgm_kmsgsrcpid = (pid_t)0
2155 showkmsgsrcint $arg0
2163 set $kgm_portp = (struct ipc_port *)$arg0
2164 showptr $kgm_portp->ip_kobject
2166 set $kgm_kotype = ($kgm_portp->ip_object.io_bits & 0x00000fff)
2167 if ($kgm_kotype == 1)
2170 if ($kgm_kotype == 2)
2173 if ($kgm_kotype == 3)
2176 if ($kgm_kotype == 4)
2179 if ($kgm_kotype == 5)
2182 if ($kgm_kotype == 6)
2185 if ($kgm_kotype == 7)
2188 if ($kgm_kotype == 8)
2191 if ($kgm_kotype == 9)
2194 if ($kgm_kotype == 10)
2197 if ($kgm_kotype == 11)
2200 if ($kgm_kotype == 12)
2203 if ($kgm_kotype == 13)
2206 if ($kgm_kotype == 14)
2209 if ($kgm_kotype == 15)
2212 if ($kgm_kotype == 16)
2215 if ($kgm_kotype == 17)
2218 if ($kgm_kotype == 18)
2221 if ($kgm_kotype == 19)
2224 if ($kgm_kotype == 20)
2227 if ($kgm_kotype == 21)
2230 if ($kgm_kotype == 22)
2231 printf "IO_DONE_QUE"
2233 if ($kgm_kotype == 23)
2236 if ($kgm_kotype == 24)
2239 if ($kgm_kotype == 25)
2242 if ($kgm_kotype == 26)
2245 if ($kgm_kotype == 27)
2246 printf "IOKIT_SPARE"
2248 if ($kgm_kotype == 28)
2251 if ($kgm_kotype == 29)
2254 if ($kgm_kotype == 30)
2257 if ($kgm_kotype == 31)
2260 if ($kgm_kotype == 34)
2266 define showportdestproc
2267 set $kgm_portp = (struct ipc_port *)$arg0
2268 set $kgm_spacep = $kgm_portp->data.receiver
2269 # check against the previous cached value - this is slow
2270 if ($kgm_spacep != $kgm_destspacep)
2271 set $kgm_destprocp = (struct proc *)0
2272 set $kgm_head_taskp = &tasks
2273 set $kgm_desttaskp = (struct task *)($kgm_head_taskp->next)
2274 while (($kgm_destprocp == 0) && ($kgm_desttaskp != $kgm_head_taskp))
2275 set $kgm_destspacep = $kgm_desttaskp->itk_space
2276 if ($kgm_destspacep == $kgm_spacep)
2277 set $kgm_destprocp = (struct proc *)$kgm_desttaskp->bsd_info
2279 set $kgm_desttaskp = (struct task *)($kgm_desttaskp->tasks.next)
2283 if $kgm_destprocp != 0
2284 printf "%s(%d)\n", $kgm_destprocp->p_comm, $kgm_destprocp->p_pid
2287 showptr $kgm_desttaskp
2293 set $kgm_portp = (struct ipc_port *)$arg0
2294 set $kgm_spacep = $kgm_portp->data.receiver
2295 if ((uintptr_t)$kgm_spacep == (uintptr_t)ipc_space_kernel)
2296 showkobject $kgm_portp
2298 if ($kgm_portp->ip_object.io_bits & 0x80000000)
2299 showptr $kgm_portp->ip_messages.data.port.receiver_name
2301 showportdestproc $kgm_portp
2304 printf " inactive-port\n"
2309 define showportmember
2314 set $kgm_portp = (struct ipc_port *)$arg0
2315 printf " 0x%08x ", $kgm_portp->ip_messages.data.port.receiver_name
2316 if ($kgm_portp->ip_object.io_bits & 0x80000000)
2322 printf "%5d ", $kgm_portp->ip_object.io_references
2323 showptr &($kgm_portp->ip_messages)
2324 printf " 0x%08x\n", $kgm_portp->ip_messages.data.port.msgcount
2328 set $kgm_iebt = ((ipc_port_t) $arg0)->ip_callstack
2329 set $kgm_iepid = ((ipc_port_t) $arg0)->ip_spares[0]
2330 set $kgm_procpid = ((proc_t) (((task_t) $arg1)->bsd_info))->p_pid
2331 if $kgm_iebt[0] != 0
2332 showptr $kgm_iebt[0]
2333 set $kgm_iebt_loop_ctr = 1
2334 while ($kgm_iebt_loop_ctr < 16 && $kgm_iebt[$kgm_iebt_loop_ctr])
2336 showptr $kgm_iebt[$kgm_iebt_loop_ctr]
2337 set $kgm_iebt_loop_ctr = $kgm_iebt_loop_ctr + 1
2339 if $kgm_iepid != $kgm_procpid
2340 printf " (%d)", $kgm_iepid
2349 set $kgm_portp = (struct ipc_port *)$arg0
2350 showptr &($kgm_portp->ip_messages)
2352 printf " 0x%08x ", $kgm_portp->ip_messages.data.port.receiver_name
2353 if ($kgm_portp->ip_object.io_bits & 0x80000000)
2359 printf "%5d ", $kgm_portp->ip_object.io_references
2360 set $kgm_destspacep = (struct ipc_space *)0
2361 showportdest $kgm_portp
2362 set $kgm_kmsgp = (ipc_kmsg_t)$kgm_portp->ip_messages.data.port.messages.ikmq_base
2363 if $arg1 && $kgm_kmsgp
2365 showkmsgint $kgm_kmsgp 1
2366 set $kgm_kmsgheadp = $kgm_kmsgp
2367 set $kgm_kmsgp = $kgm_kmsgp->ikm_next
2368 while $kgm_kmsgp != $kgm_kmsgheadp
2369 showkmsgint $kgm_kmsgp 1
2370 set $kgm_kmsgp = $kgm_kmsgp->ikm_next
2378 set $kgm_psetp = (struct ipc_pset *)$arg0
2379 showptr &($kgm_psetp->ips_messages)
2381 printf " 0x%08x ", $kgm_psetp->ips_messages.data.pset.local_name
2382 if ($kgm_psetp->ips_object.io_bits & 0x80000000)
2388 printf "%5d ", $kgm_psetp->ips_object.io_references
2389 showptr $kgm_psetp->ips_messages.data.pset.local_name
2391 set $kgm_setlinksp = &($kgm_psetp->ips_messages.data.pset.set_queue.wqs_setlinks)
2392 set $kgm_wql = (WaitQueueLink *)$kgm_setlinksp->next
2394 while ( (queue_entry_t)$kgm_wql != (queue_entry_t)$kgm_setlinksp)
2395 set $kgm_portp = (struct ipc_port *)((uintptr_t)($kgm_wql->wql_element->wqe_queue) - (uintptr_t)$kgm_portoff)
2397 set $kgm_destspacep = (struct ipc_space *)0
2398 showportdestproc $kgm_portp
2399 showportmemberheader
2402 showportmember $kgm_portp 0
2403 set $kgm_wql = (WaitQueueLink *)$kgm_wql->wql_setlinks.next
2411 set $kgm_portoff = &(((struct ipc_port *)0)->ip_messages)
2421 define showipcobject
2422 set $kgm_objectp = (ipc_object_t)$arg0
2423 if ($kgm_objectp->io_bits & 0x7fff0000)
2424 set $kgm_portoff = &(((struct ipc_port *)0)->ip_messages)
2425 showpset $kgm_objectp
2427 showport $kgm_objectp
2432 set $kgm_mqueue = *(struct ipc_mqueue *)$arg0
2433 if ($kgm_mqueue.data.pset.set_queue.wqs_wait_queue.wq_type == 0xf1d1)
2434 set $kgm_psetoff = &(((struct ipc_pset *)0)->ips_messages)
2435 set $kgm_pset = (((long)$arg0) - ((long)$kgm_psetoff))
2437 showpsetint $kgm_pset 1
2439 if ($kgm_mqueue.data.pset.set_queue.wqs_wait_queue.wq_type == 0xf1d0)
2440 set $kgm_portoff = &(((struct ipc_port *)0)->ip_messages)
2441 set $kgm_port = (((long)$arg0) - ((long)$kgm_portoff))
2443 showportint $kgm_port 1
2448 set $kgm_zone = (struct zone *)$arg0
2451 printf " %8d ",$kgm_zone->count
2452 printf "%8x ",$kgm_zone->cur_size
2453 printf "%8x ",$kgm_zone->max_size
2454 printf "%8d ",$kgm_zone->elem_size
2455 printf "%8x ",$kgm_zone->alloc_size
2456 if ($kgm_mtype != $kgm_mtype_arm)
2457 printf " %16ld ",$kgm_zone->num_allocs
2458 printf "%16ld ",$kgm_zone->num_frees
2460 printf "%s ",$kgm_zone->zone_name
2462 if ($kgm_zone->exhaustible)
2465 if ($kgm_zone->collectable)
2468 if ($kgm_zone->expandable)
2471 if ($kgm_zone->noencrypt)
2481 printf " COUNT TOT_SZ MAX_SZ ELT_SZ ALLOC_SZ TOT_ALLOC TOT_FREE NAME\n"
2482 set $kgm_zone_ptr = (struct zone *)first_zone
2483 while ($kgm_zone_ptr != 0)
2484 zprint_one $kgm_zone_ptr
2485 set $kgm_zone_ptr = $kgm_zone_ptr->next_zone
2490 Syntax: (gdb) zprint
2491 | Routine to print a summary listing of all the kernel zones
2495 set $kgm_mtxgrp = (struct _lck_grp_ *)$arg0
2497 if ($kgm_mtxgrp->lck_grp_mtxcnt)
2499 printf " %8d ",$kgm_mtxgrp->lck_grp_mtxcnt
2500 printf "%12u ",$kgm_mtxgrp->lck_grp_stat.lck_grp_mtx_stat.lck_grp_mtx_util_cnt
2501 printf "%8u ",$kgm_mtxgrp->lck_grp_stat.lck_grp_mtx_stat.lck_grp_mtx_miss_cnt
2502 printf "%8u ",$kgm_mtxgrp->lck_grp_stat.lck_grp_mtx_stat.lck_grp_mtx_wait_cnt
2503 printf "%s ",&$kgm_mtxgrp->lck_grp_name
2512 printf " CNT UTIL MISS WAIT NAME\n"
2513 set $kgm_mtxgrp_ptr = (struct _lck_grp_ *)&lck_grp_queue
2514 set $kgm_mtxgrp_ptr = (struct _lck_grp_ *)$kgm_mtxgrp_ptr->lck_grp_link.next
2515 while ($kgm_mtxgrp_ptr != (struct _lck_grp_ *)&lck_grp_queue)
2516 showmtxgrp $kgm_mtxgrp_ptr
2517 set $kgm_mtxgrp_ptr = (struct _lck_grp_ *)$kgm_mtxgrp_ptr->lck_grp_link.next
2522 Syntax: (gdb) showallmtx
2523 | Routine to print a summary listing of all mutexes
2527 set $kgm_rwlckgrp = (struct _lck_grp_ *)$arg0
2529 if ($kgm_rwlckgrp->lck_grp_rwcnt)
2530 showptr $kgm_rwlckgrp
2531 printf " %8d ",$kgm_rwlckgrp->lck_grp_rwcnt
2532 printf "%12u ",$kgm_rwlckgrp->lck_grp_stat.lck_grp_rw_stat.lck_grp_rw_util_cnt
2533 printf "%8u ",$kgm_rwlckgrp->lck_grp_stat.lck_grp_rw_stat.lck_grp_rw_miss_cnt
2534 printf "%8u ",$kgm_rwlckgrp->lck_grp_stat.lck_grp_rw_stat.lck_grp_rw_wait_cnt
2535 printf "%s ",&$kgm_rwlckgrp->lck_grp_name
2544 printf " CNT UTIL MISS WAIT NAME\n"
2545 set $kgm_rwlckgrp_ptr = (struct _lck_grp_ *)&lck_grp_queue
2546 set $kgm_rwlckgrp_ptr = (struct _lck_grp_ *)$kgm_rwlckgrp_ptr->lck_grp_link.next
2547 while ($kgm_rwlckgrp_ptr != (struct _lck_grp_ *)&lck_grp_queue)
2548 showrwlckgrp $kgm_rwlckgrp_ptr
2549 set $kgm_rwlckgrp_ptr = (struct _lck_grp_ *)$kgm_rwlckgrp_ptr->lck_grp_link.next
2553 document showallrwlck
2554 Syntax: (gdb) showallrwlck
2555 | Routine to print a summary listing of all read/writer locks
2558 set $kdp_act_counter = 0
2559 set $kdp_arm_act_counter = 0
2578 define showcontext_int
2579 echo Context switched, current instruction pointer:
2585 set $newact = (struct thread *) $arg0
2587 if ($newact->kernel_stack == 0)
2588 echo This activation does not have a stack.\n
2590 output/a (unsigned) $newact.continuation
2593 if ($kgm_mtype == $kgm_mtype_ppc)
2594 if ($kdp_act_counter == 0)
2595 set $kdpstate = (struct savearea *) kdp.saved_state
2597 set $kdp_act_counter = $kdp_act_counter + 1
2598 set (struct savearea *) kdp.saved_state=$newact->machine->pcb
2601 set $pc=$newact->machine->pcb.save_srr0
2604 if ($kgm_mtype == $kgm_mtype_i386)
2605 set $kdpstatep = (struct x86_saved_state32 *) kdp.saved_state
2606 if ($kdp_act_counter == 0)
2607 set $kdpstate = *($kdpstatep)
2609 set $kdp_act_counter = $kdp_act_counter + 1
2611 set $kgm_statep = (struct x86_kernel_state *) \
2612 ($newact->kernel_stack + kernel_stack_size \
2613 - sizeof(struct x86_kernel_state))
2614 set $kdpstatep->ebx = $kgm_statep->k_ebx
2615 set $kdpstatep->ebp = $kgm_statep->k_ebp
2616 set $kdpstatep->edi = $kgm_statep->k_edi
2617 set $kdpstatep->esi = $kgm_statep->k_esi
2618 set $kdpstatep->eip = $kgm_statep->k_eip
2621 set $pc = $kgm_statep->k_eip
2624 if ($kgm_mtype == $kgm_mtype_x86_64)
2625 set $kdpstatep = (struct x86_saved_state64 *) kdp.saved_state
2626 if ($kdp_act_counter == 0)
2627 set $kdpstate = *($kdpstatep)
2629 set $kdp_act_counter = $kdp_act_counter + 1
2631 set $kgm_statep = (struct x86_kernel_state *) \
2632 ($newact->kernel_stack + kernel_stack_size \
2633 - sizeof(struct x86_kernel_state))
2634 set $kdpstatep->rbx = $kgm_statep->k_rbx
2635 set $kdpstatep->rbp = $kgm_statep->k_rbp
2636 set $kdpstatep->r12 = $kgm_statep->k_r12
2637 set $kdpstatep->r13 = $kgm_statep->k_r13
2638 set $kdpstatep->r14 = $kgm_statep->k_r14
2639 set $kdpstatep->r15 = $kgm_statep->k_r15
2640 set $kdpstatep->isf.rsp = $kgm_statep->k_rsp
2643 set $pc = $kgm_statep->k_rip
2646 if ($kgm_mtype == $kgm_mtype_arm)
2647 set $kdp_arm_act_counter = $kdp_arm_act_counter + 1
2648 if ($kdp_arm_act_counter == 1)
2659 set $r10_save = $r10
2660 set $r11_save = $r11
2661 set $r12_save = $r12
2666 set $pc_ctx = load_reg+8
2667 set $kgm_statep = (struct arm_saved_state *)((struct thread*)$arg0)->machine.kstackptr
2668 set $r0 = $kgm_statep->r[0]
2669 set $r1 = $kgm_statep->r[1]
2670 set $r2 = $kgm_statep->r[2]
2671 set $r3 = $kgm_statep->r[3]
2672 set $r4 = $kgm_statep->r[4]
2673 set $r5 = $kgm_statep->r[5]
2674 set $r6 = $kgm_statep->r[6]
2675 set $r8 = $kgm_statep->r[8]
2676 set $r9 = $kgm_statep->r[9]
2677 set $r10 = $kgm_statep->r[10]
2678 set $r11 = $kgm_statep->r[11]
2679 set $r12 = $kgm_statep->r[12]
2680 set $sp = $kgm_statep->sp
2681 set $lr = $kgm_statep->lr
2683 set $r7 = $kgm_statep->r[7]
2691 document switchtoact
2692 Syntax: switchtoact <address of activation>
2693 | This command allows gdb to examine the execution context and call
2694 | stack for the specified activation. For example, to view the backtrace
2695 | for an activation issue "switchtoact <address>", followed by "bt".
2696 | Before resuming execution, issue a "resetctx" command, to
2697 | return to the original execution context.
2702 if ($kgm_mtype == $kgm_mtype_ppc)
2703 if ($kdp_act_counter == 0)
2704 set $kdpstate = (struct savearea *) kdp.saved_state
2706 set $kdp_act_counter = $kdp_act_counter + 1
2707 set (struct savearea *) kdp.saved_state=(struct savearea *) $arg0
2710 set $pc=((struct savearea *) $arg0)->save_srr0
2713 if ($kgm_mtype == $kgm_mtype_arm)
2715 set $kdp_arm_act_counter = $kdp_arm_act_counter + 1
2716 if ($kdp_arm_act_counter == 1)
2727 set $r10_save = $r10
2728 set $r11_save = $r11
2729 set $r12_save = $r12
2734 set $kgm_statep = (struct arm_saved_state *)$arg0
2735 set $r0 = $kgm_statep->r[0]
2736 set $r1 = $kgm_statep->r[1]
2737 set $r2 = $kgm_statep->r[2]
2738 set $r3 = $kgm_statep->r[3]
2739 set $r4 = $kgm_statep->r[4]
2740 set $r5 = $kgm_statep->r[5]
2741 set $r6 = $kgm_statep->r[6]
2742 set $r8 = $kgm_statep->r[8]
2743 set $r9 = $kgm_statep->r[9]
2744 set $r10 = $kgm_statep->r[10]
2745 set $r11 = $kgm_statep->r[11]
2746 set $r12 = $kgm_statep->r[12]
2747 set $sp = $kgm_statep->sp
2748 set $lr = $kgm_statep->lr
2749 set $r7 = $kgm_statep->r[7]
2750 set $pc = $kgm_statep->pc
2755 echo switchtoctx not implemented for this architecture.\n
2761 document switchtoctx
2762 Syntax: switchtoctx <address of pcb>
2763 | This command allows gdb to examine an execution context and dump the
2764 | backtrace for this execution context.
2765 | Before resuming execution, issue a "resetctx" command, to
2766 | return to the original execution context.
2771 if ($kdp_act_counter != 0)
2772 if ($kgm_mtype == $kgm_mtype_ppc)
2773 set (struct savearea *)kdp.saved_state=$kdpstate
2776 set $pc=((struct savearea *) kdp.saved_state)->save_srr0
2778 set $kdp_act_counter = 0
2780 if ($kgm_mtype == $kgm_mtype_i386)
2781 set $kdpstatep = (struct x86_saved_state32 *) kdp.saved_state
2782 set *($kdpstatep)=$kdpstate
2785 set $pc=$kdpstatep->eip
2787 set $kdp_act_counter = 0
2789 if ($kgm_mtype == $kgm_mtype_x86_64)
2790 set $kdpstatep = (struct x86_saved_state64 *) kdp.saved_state
2791 set *($kdpstatep)=$kdpstate
2794 set $pc=$kdpstatep->isf.rip
2796 set $kdp_act_counter = 0
2800 if ($kgm_mtype == $kgm_mtype_arm && $kdp_arm_act_counter != 0)
2801 echo Restoring context\n
2820 set $r10 = $r10_save
2822 set $r11 = $r11_save
2824 set $r12 = $r12_save
2836 set $kdp_arm_act_counter = 0
2842 | Returns to the original execution context. This command should be
2843 | issued if you wish to resume execution after using the "switchtoact"
2844 | or "switchtoctx" commands.
2847 # This is a pre-hook for the continue command, to prevent inadvertent attempts
2848 # to resume from the context switched to for examination.
2849 define hook-continue
2853 # This is a pre-hook for the detach command, to prevent inadvertent attempts
2854 # to resume from the context switched to for examination.
2860 set $resume = KDP_DUMPINFO_SETINFO | KDP_DUMPINFO_RESUME
2866 | The target system will resume when detaching or exiting from gdb.
2867 | This is the default behavior.
2871 set $noresume = KDP_DUMPINFO_SETINFO | KDP_DUMPINFO_NORESUME
2872 dumpinfoint $noresume
2876 | Syntax: resume_off
2877 | The target system won't resume after detaching from gdb and
2878 | can be attached with a new gdb session
2882 set $kgm_panic_bufptr = debug_buf
2883 set $kgm_panic_bufptr_max = debug_buf_ptr
2884 while $kgm_panic_bufptr < $kgm_panic_bufptr_max
2885 if *(char *)$kgm_panic_bufptr == 10
2888 printf "%c", *(char *)$kgm_panic_bufptr
2890 set $kgm_panic_bufptr= (char *)$kgm_panic_bufptr + 1
2896 | Display the panic log information
2900 define dumpcallqueue
2901 set $kgm_callhead = $arg0
2902 set $kgm_callentry = $kgm_callhead->next
2904 while $kgm_callentry != $kgm_callhead
2905 set $kgm_call = (struct call_entry *)$kgm_callentry
2907 printf "0x%lx 0x%lx ", $kgm_call->param0, $kgm_call->param1
2908 output $kgm_call->deadline
2910 output $kgm_call->func
2912 set $kgm_i = $kgm_i + 1
2913 set $kgm_callentry = $kgm_callentry->next
2915 printf "%d entries\n", $kgm_i
2918 document dumpcallqueue
2919 | Syntax: dumpcallqueue <queue head>
2920 | Displays the contents of the specified call_entry queue.
2924 showtaskthreads $arg0
2926 document showtaskacts
2927 | See help showtaskthreads.
2933 document showallacts
2934 | See help showallthreads.
2949 document resetstacks
2950 | Syntax: resetstacks
2951 | Internal kgmacro routine used by the "showuserstack" macro
2952 | to reset the target pmap to the kernel pmap.
2955 #Barely effective hacks to work around bugs in the "flush" and "update"
2956 #gdb commands in Tiger (up to 219); these aren't necessary with Panther
2957 #gdb, but do no harm.
2958 define _kgm_flush_loop
2959 set $kgm_flush_loop_ctr = 0
2960 while ($kgm_flush_loop_ctr < 30)
2963 set $kgm_flush_loop_ctr = $kgm_flush_loop_ctr + 1
2967 define _kgm_update_loop
2968 set $kgm_update_loop_ctr = 0
2969 while ($kgm_update_loop_ctr < 30)
2971 set $kgm_update_loop_ctr = $kgm_update_loop_ctr + 1
2974 # Internal routine used by "_loadfrom" to read from 64-bit addresses
2977 # set up the manual KDP packet
2978 set manual_pkt.input = 0
2979 set manual_pkt.len = sizeof(kdp_readmem64_req_t)
2980 set $kgm_pkt = (kdp_readmem64_req_t *)&manual_pkt.data
2981 set $kgm_pkt->hdr.request = KDP_READMEM64
2982 set $kgm_pkt->hdr.len = sizeof(kdp_readmem64_req_t)
2983 set $kgm_pkt->hdr.is_reply = 0
2984 set $kgm_pkt->hdr.seq = 0
2985 set $kgm_pkt->hdr.key = 0
2986 set $kgm_pkt->address = (uint64_t)$arg0
2987 set $kgm_pkt->nbytes = sizeof(uint64_t)
2988 set manual_pkt.input = 1
2989 # dummy to make sure manual packet is executed
2990 set $kgm_dummy = &_mh_execute_header
2991 set $kgm_pkt = (kdp_readmem64_reply_t *)&manual_pkt.data
2992 if ($kgm_pkt->error == 0)
2993 set $kgm_k32read64 = *(uint64_t *)$kgm_pkt->data
2995 set $kgm_k32read64 = 0
2999 # Internal routine used by "showx86backtrace" to abstract possible loads from
3003 set $kgm_loadval = *(uintptr_t *)$arg0
3005 if ($kgm_x86_abi == 0xe)
3006 set $kgm_loadval = *(uint32_t *)$arg0
3008 if ($kgm_x86_abi == 0xf)
3009 if ($kgm_mtype == $kgm_mtype_i386)
3011 set $kgm_loadval = $kgm_k32read64
3013 set $kgm_loadval = *(uint64_t *)$arg0
3021 #This is necessary since gdb often doesn't do backtraces on x86 correctly
3022 #in the absence of symbols.The code below in showuserstack and
3023 #showx86backtrace also contains several workarouds for the gdb bug where
3024 #gdb stops macro evaluation because of spurious "Cannot read memory"
3025 #errors on x86. These errors appear on ppc as well, but they don't
3026 #always stop macro evaluation.
3028 set $kgm_cur_frame = 0
3030 set $kgm_x86_abi = 0
3031 define showx86backtrace
3032 if ($kgm_mtype == $kgm_mtype_i386)
3033 set $kgm_frame_reg = $ebp
3035 set $kgm_ret_off = 4
3037 if ($kgm_mtype == $kgm_mtype_x86_64)
3038 set $kgm_frame_reg = $rbp
3040 set $kgm_ret_off = 8
3043 if ($kgm_x86_abi == 0xe)
3044 set $kgm_ret_off = 4
3046 if ($kgm_x86_abi == 0xf)
3047 set $kgm_ret_off = 8
3050 if ($kgm_cur_frame == 0)
3051 set $kgm_cur_frame = $kgm_frame_reg
3053 if ($kgm_cur_pc == 0)
3054 set $kgm_cur_pc = $kgm_pc
3056 printf "0: Frame: 0x%016llx PC: 0x%016llx\n", $kgm_cur_frame, $kgm_cur_pc
3057 if (!(($kgm_x86_abi == 0xf) && ($kgm_mtype == $kgm_mtype_i386)))
3060 set $kgm_tmp_frame = $kgm_cur_frame
3061 set $kgm_cur_frame = 0
3063 _loadfrom ($kgm_tmp_frame)
3064 set $kgm_prev_frame = $kgm_loadval
3065 _loadfrom ($kgm_tmp_frame+$kgm_ret_off)
3066 set $kgm_prev_pc = $kgm_loadval
3067 set $kgm_frameno = 1
3068 while ($kgm_prev_frame != 0) && ($kgm_prev_frame != 0x0000000800000008)
3069 printf "%d: Saved frame: 0x%016llx Saved PC: 0x%016llx\n", $kgm_frameno, $kgm_prev_frame, $kgm_prev_pc
3070 if (!(($kgm_x86_abi == 0xf) && ($kgm_mtype == $kgm_mtype_i386)))
3073 _loadfrom ($kgm_prev_frame+$kgm_ret_off)
3074 set $kgm_prev_pc = $kgm_loadval
3075 _loadfrom ($kgm_prev_frame)
3076 set $kgm_prev_frame = $kgm_loadval
3077 set $kgm_frameno = $kgm_frameno + 1
3080 set $kgm_x86_abi = 0
3083 define showx86backtrace2
3084 set $kgm_cur_frame = $arg0
3085 set $kgm_cur_pc = $arg1
3089 define showuserstack
3091 if ($kgm_mtype == $kgm_mtype_ppc)
3092 if ($kdp_act_counter == 0)
3093 set $kdpstate = (struct savearea *) kdp.saved_state
3095 set $kdp_act_counter = $kdp_act_counter + 1
3096 set $newact = (struct thread *) $arg0
3098 set $checkpc = $newact->machine->upcb.save_srr0
3100 echo This activation does not appear to have
3101 echo \20 a valid user context.\n
3103 set (struct savearea *) kdp.saved_state=$newact->machine->upcb
3105 #flush and update seem to be executed lazily by gdb on Tiger, hence the
3106 #repeated invocations - see 3743135
3108 # This works because the new pmap is used only for reads
3109 set kdp_pmap = $newact->task->map->pmap
3121 if (($kgm_mtype & $kgm_mtype_x86_mask) == $kgm_mtype_x86_any)
3122 set $newact = (struct thread *) $arg0
3123 set $newiss = (x86_saved_state_t *) ($newact->machine->iss)
3124 set $kgm_x86_abi = $newiss.flavor
3125 if ($newiss.flavor == 0xf)
3126 set $checkpc = $newiss.uss.ss_64.isf.rip
3127 set $checkframe = $newiss.uss.ss_64.rbp
3130 set $checkpc = $newiss.uss.ss_32.eip
3131 set $checkframe = $newiss.uss.ss_32.ebp
3135 echo This activation does not appear to have
3136 echo \20 a valid user context.\n
3138 set $kgm_cur_frame = $checkframe
3139 set $kgm_cur_pc = $checkpc
3140 # When have more than one argument is present, don't print usage
3142 printf "You may now issue the showx86backtrace command to see the user space backtrace for this thread ("
3144 printf "); you can also examine memory locations in this address space (pmap "
3145 showptr $newact->task->map->pmap
3146 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"
3148 set kdp_pmap = $newact->task->map->pmap
3153 if ($kgm_mtype == $kgm_mtype_arm)
3154 if (kdp->is_conn > 0)
3155 set $kgm_threadp = (struct thread *)$arg0
3156 set $kgm_saved_pmap = kdp_pmap
3158 showactint $kgm_threadp 0
3159 set $kgm_thread_pmap = $kgm_threadp->task->map->pmap
3160 set $kgm_thread_sp = $kgm_threadp.machine->PcbData.r[7]
3165 showptr $kgm_threadp.machine->PcbData.pc
3167 set kdp_pmap = $kgm_thread_pmap
3168 while ($kgm_thread_sp != 0)
3169 set $link_register = *($kgm_thread_sp + 4)
3172 showptr $kgm_thread_sp
3174 showptr $link_register
3176 set $kgm_thread_sp = *$kgm_thread_sp
3178 set kdp_pmap = $kgm_saved_pmap
3180 set $kgm_threadp = (struct thread *)$arg0
3182 showactint $kgm_threadp 0
3183 set $kgm_thread_sp = $kgm_threadp.machine->PcbData.r[7]
3184 while ($kgm_thread_sp != 0)
3185 _map_user_data_from_task $kgm_threadp->task $kgm_thread_sp 8
3186 set $kgm_thread_sp_window = (int *)$kgm_map_user_window
3187 set $link_register = *($kgm_thread_sp_window + 1)
3190 showptr $kgm_thread_sp
3192 showptr $link_register
3194 set $kgm_thread_sp = *$kgm_thread_sp_window
3195 _unmap_user_data_from_task
3199 echo showuserstack not supported on this architecture\n
3204 document showuserstack
3205 Syntax: showuserstack <address of thread activation>
3206 |This command displays a numeric backtrace for the user space stack of
3207 |the given thread activation. It may, of course, fail to display a
3208 |complete backtrace if portions of the user stack are not mapped in.
3209 |Symbolic backtraces can be obtained either by running gdb on the
3210 |user space binary, or a tool such as "symbolicate".
3211 |Note that while this command works on Panther's gdb, an issue
3212 |with Tiger gdb (3743135) appears to hamper the evaluation of this
3213 |macro in some cases.
3216 define showtaskuserstacks
3217 set $kgm_taskp = (struct task *)$arg0
3218 set $kgm_head_actp = &($kgm_taskp->threads)
3219 set $kgm_actp = (struct thread *)($kgm_taskp->threads.next)
3220 while $kgm_actp != $kgm_head_actp
3221 printf "For thread "
3224 showuserstack $kgm_actp quiet
3225 if (($kgm_mtype & $kgm_mtype_x86_mask) == $kgm_mtype_x86_any)
3229 set $kgm_actp = (struct thread *)($kgm_actp->task_threads.next)
3232 showuserlibraries $kgm_taskp
3234 document showtaskuserstacks
3235 Syntax: (gdb) showtaskuserstacks <task>
3236 | Print out the user stack for each thread in a task, followed by the user libraries.
3240 define showuserregisters
3241 set $kgm_threadp = (struct thread *)$arg0
3242 set $kgm_taskp = $kgm_threadp->task
3243 if (($kgm_mtype & $kgm_mtype_x86_mask) == $kgm_mtype_x86_any)
3244 set $newiss = (x86_saved_state_t *) ($kgm_threadp->machine.iss)
3245 set $kgm_x86_abi = $newiss.flavor
3246 if ($newiss.flavor == 0xf)
3247 printf "X86 Thread State (64-bit):\n"
3248 set $kgm_ss64 = $newiss.uss.ss_64
3251 showuserptr $kgm_ss64.rax
3253 showuserptr $kgm_ss64.rbx
3255 showuserptr $kgm_ss64.rcx
3257 showuserptr $kgm_ss64.rdx
3261 showuserptr $kgm_ss64.rdi
3263 showuserptr $kgm_ss64.rsi
3265 showuserptr $kgm_ss64.rbp
3267 showuserptr $kgm_ss64.isf.rsp
3271 showuserptr $kgm_ss64.r8
3273 showuserptr $kgm_ss64.r9
3275 showuserptr $kgm_ss64.r10
3277 showuserptr $kgm_ss64.r11
3281 showuserptr $kgm_ss64.r12
3283 showuserptr $kgm_ss64.r13
3285 showuserptr $kgm_ss64.r14
3287 showuserptr $kgm_ss64.r15
3291 showuserptr $kgm_ss64.isf.rip
3293 showuserptr $kgm_ss64.isf.rflags
3295 showuserptr $kgm_ss64.cr2
3298 printf "X86 Thread State (32-bit):\n"
3299 set $kgm_ss32 = $newiss.uss.ss_32
3302 showuserptr $kgm_ss32.eax
3304 showuserptr $kgm_ss32.ebx
3306 showuserptr $kgm_ss32.ecx
3308 showuserptr $kgm_ss32.edx
3312 showuserptr $kgm_ss32.edi
3314 showuserptr $kgm_ss32.esi
3316 showuserptr $kgm_ss32.ebp
3318 showuserptr $kgm_ss32.uesp
3322 showuserptr $kgm_ss32.ss
3324 showuserptr $kgm_ss32.efl
3326 showuserptr $kgm_ss32.eip
3328 showuserptr $kgm_ss32.cs
3332 showuserptr $kgm_ss32.ds
3334 showuserptr $kgm_ss32.es
3336 showuserptr $kgm_ss32.fs
3338 showuserptr $kgm_ss32.gs
3342 showuserptr $kgm_ss32.cr2
3346 if ($kgm_mtype == $kgm_mtype_arm)
3347 printf "ARM Thread State:\n"
3348 set $kgm_pcb = (arm_saved_state_t *) (&$kgm_threadp->machine.PcbData)
3351 showuserptr $kgm_pcb.r[0]
3353 showuserptr $kgm_pcb.r[1]
3355 showuserptr $kgm_pcb.r[2]
3357 showuserptr $kgm_pcb.r[3]
3361 showuserptr $kgm_pcb.r[4]
3363 showuserptr $kgm_pcb.r[5]
3365 showuserptr $kgm_pcb.r[6]
3367 showuserptr $kgm_pcb.r[7]
3371 showuserptr $kgm_pcb.r[8]
3373 showuserptr $kgm_pcb.r[9]
3375 showuserptr $kgm_pcb.r[10]
3377 showuserptr $kgm_pcb.r[11]
3381 showuserptr $kgm_pcb.r[12]
3383 showuserptr $kgm_pcb.sp
3385 showuserptr $kgm_pcb.lr
3387 showuserptr $kgm_pcb.pc
3391 showuserptr $kgm_pcb.cpsr
3394 echo showuserregisters not supported on this architecture\n
3398 document showuserregisters
3399 Syntax: showuserstack <address of thread>
3400 |This command displays the last known user register state
3401 |for the thread. This map not be correct for cases where
3402 |the thread is currently executing in userspace. However
3403 |for threads that have entered the kernel (either explicitly
3404 |with a system call or implicitly with a fault), it should
3408 define showtaskuserregisters
3409 set $kgm_taskp = (struct task *)$arg0
3410 set $kgm_head_actp = &($kgm_taskp->threads)
3411 set $kgm_actp = (struct thread *)($kgm_taskp->threads.next)
3412 while $kgm_actp != $kgm_head_actp
3413 printf "For thread "
3416 showuserregisters $kgm_actp
3417 set $kgm_actp = (struct thread *)($kgm_actp->task_threads.next)
3421 document showtaskuserregisters
3422 Syntax: (gdb) showtaskuserregisters <task>
3423 | Print out the user registers for each thread in a task
3427 # Alternatively, set *(*(unsigned **) 0x2498) = 1
3428 # (or 0x5498 on PPC, 0xffffff8000002928 on x86_64, 0xffff049c on arm)
3429 manualhdrint $kgm_kdp_pkt_hostreboot
3435 |Reboot the remote target machine; not guaranteed to succeed.
3438 define kdpversionint
3439 # set up the manual KDP packet
3440 set manual_pkt.input = 0
3441 set manual_pkt.len = sizeof(kdp_version_req_t)
3442 set $kgm_pkt = (kdp_version_req_t *)&manual_pkt.data
3443 set $kgm_pkt->hdr.request = KDP_VERSION
3444 set $kgm_pkt->hdr.len = sizeof(kdp_version_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 manual_pkt.input = 1
3449 # dummy to make sure manual packet is executed
3450 set $kgm_dummy = &_mh_execute_header
3451 set $kgm_pkt = (kdp_version_reply_t *)&manual_pkt.data
3452 set $kgm_kdp_version = $kgm_pkt->version
3453 set $kgm_kdp_feature = $kgm_pkt->feature
3458 printf "KDP VERSION = %d, FEATURE = 0x%x\n", $kgm_kdp_version, $kgm_kdp_feature
3461 document kdp-version
3463 |Get the KDP protocol version being used by the kernel.
3467 # set up the manual KDP packet
3468 set manual_pkt.input = 0
3470 set manual_pkt.len = sizeof(kdp_dumpinfo_req_t)
3471 set $kgm_pkt = (kdp_dumpinfo_req_t *)&manual_pkt.data
3472 set $kgm_pkt->hdr.request = KDP_DUMPINFO
3473 set $kgm_pkt->hdr.len = sizeof(kdp_dumpinfo_req_t)
3474 set $kgm_pkt->hdr.is_reply = 0
3475 set $kgm_pkt->hdr.seq = 0
3476 set $kgm_pkt->hdr.key = 0
3477 set $kgm_pkt->type = $arg0
3478 set $kgm_pkt->name = ""
3479 set $kgm_pkt->destip = ""
3480 set $kgm_pkt->routerip = ""
3481 set $kgm_pkt->port = 0
3484 set $kgm_pkt->name = "$arg1"
3487 set $kgm_pkt->destip = "$arg2"
3490 set $kgm_pkt->routerip = "$arg3"
3493 set $kgm_pkt->port = $arg4
3496 set manual_pkt.input = 1
3497 # dummy to make sure manual packet is executed
3498 set $kgm_dummy = &_mh_execute_header
3503 dumpinfoint KDP_DUMPINFO_CORE $arg1 $arg0
3505 dumpinfoint KDP_DUMPINFO_CORE \0 $arg0
3510 Syntax: sendcore <IP address> [filename]
3511 |Configure the kernel to transmit a kernel coredump to a server (kdumpd)
3512 |at the specified IP address. This is useful when the remote target has
3513 |not been previously configured to transmit coredumps, and you wish to
3514 |preserve kernel state for later examination. NOTE: You must issue a "continue"
3515 |command after using this macro to trigger the kernel coredump. The kernel
3516 |will resume waiting in the debugger after completion of the coredump. You
3517 |may disable coredumps by executing the "disablecore" macro. You can
3518 |optionally specify the filename to be used for the generated core file.
3523 dumpinfoint KDP_DUMPINFO_SYSTEMLOG $arg1 $arg0
3525 dumpinfoint KDP_DUMPINFO_SYSTEMLOG \0 $arg0
3530 Syntax: sendsyslog <IP address> [filename]
3531 |Configure the kernel to transmit a kernel system log to a server (kdumpd)
3532 |at the specified IP address. NOTE: You must issue a "continue"
3533 |command after using this macro to trigger the kernel system log. The kernel
3534 |will resume waiting in the debugger after completion. You can optionally
3535 |specify the name to be used for the generated system log.
3541 dumpinfoint KDP_DUMPINFO_PANICLOG $arg1 $arg0
3543 dumpinfoint KDP_DUMPINFO_PANICLOG \0 $arg0
3546 printf "No panic log available.\n"
3550 document sendpaniclog
3551 Syntax: sendpaniclog <IP address> [filename]
3552 |Configure the kernel to transmit a kernel paniclog to a server (kdumpd)
3553 |at the specified IP address. NOTE: You must issue a "continue"
3554 |command after using this macro to trigger the kernel panic log. The kernel
3555 |will resume waiting in the debugger after completion. You can optionally
3556 |specify the name to be used for the generated panic log.
3560 dumpinfoint KDP_DUMPINFO_GETINFO
3561 set $kgm_dumpinfo = (kdp_dumpinfo_reply_t *) manual_pkt.data
3562 if $kgm_dumpinfo->type & KDP_DUMPINFO_REBOOT
3563 printf "System will reboot after kernel info gets dumped.\n"
3565 printf "System will not reboot after kernel info gets dumped.\n"
3567 if $kgm_dumpinfo->type & KDP_DUMPINFO_NORESUME
3568 printf "System will allow a re-attach after a KDP disconnect.\n"
3570 printf "System will resume after a KDP disconnect.\n"
3572 set $kgm_dumpinfo_type = $kgm_dumpinfo->type & KDP_DUMPINFO_MASK
3573 if $kgm_dumpinfo_type == KDP_DUMPINFO_DISABLE
3574 printf "Kernel not setup for remote dumps.\n"
3576 printf "Remote dump type: "
3577 if $kgm_dumpinfo_type == KDP_DUMPINFO_CORE
3578 printf "Core file\n"
3580 if $kgm_dumpinfo_type == KDP_DUMPINFO_PANICLOG
3581 printf "Panic log\n"
3583 if $kgm_dumpinfo_type == KDP_DUMPINFO_SYSTEMLOG
3584 printf "System log\n"
3588 if $kgm_dumpinfo->name[0] == '\0'
3589 printf "(autogenerated)\n"
3591 printf "%s\n", $kgm_dumpinfo->name
3594 printf "Network Info: %s[%d] ", $kgm_dumpinfo->destip, $kgm_dumpinfo->port
3595 if $kgm_dumpinfo->routerip[0] == '\0'
3598 printf "Router: %s\n", $kgm_dumpinfo->routerip
3603 document getdumpinfo
3605 |Retrieve the current remote dump settings.
3609 dumpinfoint KDP_DUMPINFO_SETINFO $arg0 $arg1 $arg2 $arg3
3612 document setdumpinfo
3613 Syntax: setdumpinfo <filename> <ip> <router> <port>
3614 |Configure the current remote dump settings. Specify \0 if you
3615 |want to use the defaults (filename) or previously configured
3616 |settings (ip/router). Specify 0 for the port if you wish to
3617 |use the previously configured/default setting for that.
3621 dumpinfoint KDP_DUMPINFO_DISABLE
3624 document disablecore
3626 |Reconfigures the kernel so that it no longer transmits kernel coredumps. This
3627 |complements the "sendcore" macro, but it may be used if the kernel has been
3628 |configured to transmit coredumps through boot-args as well.
3631 define switchtocorethread
3632 set $newact = (struct thread *) $arg0
3634 if ($newact->kernel_stack == 0)
3635 echo This thread does not have a stack.\n
3637 output/a (unsigned) $newact.continuation
3640 if ($kgm_mtype == $kgm_mtype_ppc)
3641 loadcontext $newact->machine->pcb
3643 set $pc = $newact->machine->pcb.save_srr0
3645 if (($kgm_mtype & $kgm_mtype_x86_mask) == $kgm_mtype_x86_any)
3646 set $kgm_cstatep = (struct x86_kernel_state *) \
3647 ($newact->kernel_stack + kernel_stack_size \
3648 - sizeof(struct x86_kernel_state))
3649 loadcontext $kgm_cstatep
3652 echo switchtocorethread not supported on this architecture\n
3659 document switchtocorethread
3660 Syntax: switchtocorethread <address of activation>
3661 | The corefile equivalent of "switchtoact". When debugging a kernel coredump
3662 | file, this command can be used to examine the execution context and stack
3663 | trace for a given thread activation. For example, to view the backtrace
3664 | for a thread issue "switchtocorethread <address>", followed by "bt".
3665 | Before resuming execution, issue a "resetcorectx" command, to
3666 | return to the original execution context. Note that this command
3667 | requires gdb support, as documented in Radar 3401283.
3672 if ($kgm_mtype == $kgm_mtype_ppc)
3673 set $kgm_contextp = (struct savearea *) $arg0
3674 set $pc = $kgm_contextp.save_srr0
3675 set $r1 = $kgm_contextp.save_r1
3676 set $lr = $kgm_contextp.save_lr
3678 set $r2 = $kgm_contextp.save_r2
3679 set $r3 = $kgm_contextp.save_r3
3680 set $r4 = $kgm_contextp.save_r4
3681 set $r5 = $kgm_contextp.save_r5
3682 set $r6 = $kgm_contextp.save_r6
3683 set $r7 = $kgm_contextp.save_r7
3684 set $r8 = $kgm_contextp.save_r8
3685 set $r9 = $kgm_contextp.save_r9
3686 set $r10 = $kgm_contextp.save_r10
3687 set $r11 = $kgm_contextp.save_r11
3688 set $r12 = $kgm_contextp.save_r12
3689 set $r13 = $kgm_contextp.save_r13
3690 set $r14 = $kgm_contextp.save_r14
3691 set $r15 = $kgm_contextp.save_r15
3692 set $r16 = $kgm_contextp.save_r16
3693 set $r17 = $kgm_contextp.save_r17
3694 set $r18 = $kgm_contextp.save_r18
3695 set $r19 = $kgm_contextp.save_r19
3696 set $r20 = $kgm_contextp.save_r20
3697 set $r21 = $kgm_contextp.save_r21
3698 set $r22 = $kgm_contextp.save_r22
3699 set $r23 = $kgm_contextp.save_r23
3700 set $r24 = $kgm_contextp.save_r24
3701 set $r25 = $kgm_contextp.save_r25
3702 set $r26 = $kgm_contextp.save_r26
3703 set $r27 = $kgm_contextp.save_r27
3704 set $r28 = $kgm_contextp.save_r28
3705 set $r29 = $kgm_contextp.save_r29
3706 set $r30 = $kgm_contextp.save_r30
3707 set $r31 = $kgm_contextp.save_r31
3709 set $cr = $kgm_contextp.save_cr
3710 set $ctr = $kgm_contextp.save_ctr
3712 if ($kgm_mtype == $kgm_mtype_i386)
3713 set $kgm_contextp = (struct x86_kernel_state *) $arg0
3714 set $ebx = $kgm_contextp->k_ebx
3715 set $ebp = $kgm_contextp->k_ebp
3716 set $edi = $kgm_contextp->k_edi
3717 set $esi = $kgm_contextp->k_esi
3718 set $eip = $kgm_contextp->k_eip
3719 set $pc = $kgm_contextp->k_eip
3721 if ($kgm_mtype == $kgm_mtype_x86_64)
3722 set $kgm_contextp = (struct x86_kernel_state *) $arg0
3723 set $rbx = $kgm_contextp->k_rbx
3724 set $rbp = $kgm_contextp->k_rbp
3725 set $r12 = $kgm_contextp->k_r12
3726 set $r13 = $kgm_contextp->k_r13
3727 set $r14 = $kgm_contextp->k_r14
3728 set $r15 = $kgm_contextp->k_r15
3729 set $rip = $kgm_contextp->k_rip
3730 set $pc = $kgm_contextp->k_rip
3732 echo loadcontext not supported on this architecture\n
3740 if ($kgm_mtype == $kgm_mtype_ppc)
3741 set $kgm_corecontext = (struct savearea *) kdp.saved_state
3742 loadcontext $kgm_corecontext
3744 if ($kgm_mtype == $kgm_mtype_i386)
3745 set $kdpstatep = (struct x86_saved_state32 *) kdp.saved_state
3746 set $ebx = $kdpstatep->ebx
3747 set $ebp = $kdpstatep->ebp
3748 set $edi = $kdpstatep->edi
3749 set $esi = $kdpstatep->esi
3750 set $eip = $kdpstatep->eip
3751 set $eax = $kdpstatep->eax
3752 set $ecx = $kdpstatep->ecx
3753 set $edx = $kdpstatep->edx
3756 set $pc = $kdpstatep->eip
3759 echo resetcorectx not supported on this architecture\n
3765 document resetcorectx
3766 Syntax: resetcorectx
3767 | The corefile equivalent of "resetctx". Returns to the original
3768 | execution context (that of the active thread at the time of the NMI or
3769 | panic). This command should be issued if you wish to resume
3770 | execution after using the "switchtocorethread" command.
3773 #Helper function for "showallgdbstacks"
3775 define showgdbthread
3776 printf " 0x%08x ", $arg0
3777 set $kgm_thread = *(struct thread *)$arg0
3778 printf "0x%08x ", $arg0
3779 printf "%3d ", $kgm_thread.sched_pri
3780 set $kgm_state = $kgm_thread.state
3781 if $kgm_state & 0x80
3784 if $kgm_state & 0x40
3787 if $kgm_state & 0x20
3790 if $kgm_state & 0x10
3793 if $kgm_state & 0x08
3796 if $kgm_state & 0x04
3799 if $kgm_state & 0x02
3802 if $kgm_state & 0x01
3804 printf "0x%08x ", $kgm_thread.wait_queue
3805 output /a (unsigned) $kgm_thread.wait_event
3806 if ($kgm_thread.uthread != 0)
3807 set $kgm_uthread = (struct uthread *)$kgm_thread.uthread
3808 if ($kgm_uthread->uu_wmesg != 0)
3809 printf " \"%s\"", $kgm_uthread->uu_wmesg
3814 if ($kgm_thread.kernel_stack != 0)
3815 if ($kgm_thread.reserved_stack != 0)
3816 printf "\n\t\treserved_stack=0x%08x", $kgm_thread.reserved_stack
3818 printf "\n\t\tkernel_stack=0x%08x", $kgm_thread.kernel_stack
3819 if ($kgm_mtype == $kgm_mtype_ppc)
3820 set $mysp = $kgm_thread.machine.pcb->save_r1
3822 if ($kgm_mtype == $kgm_mtype_i386)
3823 set $kgm_statep = (struct x86_kernel_state *) \
3824 ($kgm_thread->kernel_stack + kernel_stack_size \
3825 - sizeof(struct x86_kernel_state))
3826 set $mysp = $kgm_statep->k_ebp
3828 if ($kgm_mtype == $kgm_mtype_arm)
3829 if (((unsigned long)$r7 < ((unsigned long) ($kgm_thread->kernel_stack+kernel_stack_size))) \
3830 && ((unsigned long)$r7 > (unsigned long) ($kgm_thread->kernel_stack)))
3833 set $kgm_statep = (struct arm_saved_state *)$kgm_thread.machine.kstackptr
3834 set $mysp = $kgm_statep->r[7]
3838 printf "\n\t\tstacktop=0x%08x", $mysp
3842 switchtocorethread $arg0
3846 printf "\n\t\t\tcontinuation="
3847 output /a (unsigned) $kgm_thread.continuation
3855 #Use of this macro is currently (8/04) blocked by the fact that gdb
3856 #stops evaluating macros when encountering an error, such as a failure
3857 #to read memory from a certain location. Until this issue (described in
3858 #3758949) is addressed, evaluation of this macro may stop upon
3859 #encountering such an error.
3861 define showallgdbstacks
3862 set $kgm_head_taskp = &tasks
3863 set $kgm_taskp = (struct task *)($kgm_head_taskp->next)
3864 while $kgm_taskp != $kgm_head_taskp
3866 showtaskint $kgm_taskp
3867 set $kgm_head_actp = &($kgm_taskp->threads)
3868 set $kgm_actp = (struct thread *)($kgm_taskp->threads.next)
3869 while $kgm_actp != $kgm_head_actp
3871 showgdbthread $kgm_actp 1 0
3872 set $kgm_actp = (struct thread *)($kgm_actp->task_threads.next)
3875 set $kgm_taskp = (struct task *)($kgm_taskp->tasks.next)
3880 document showallgdbstacks
3881 Syntax: showallgdbstacks
3882 | An alternative to "showallstacks". Iterates through the task list and
3883 | displays a gdb generated backtrace for each kernel thread. It is
3884 | advantageous in that it is much faster than "showallstacks", and
3885 | decodes function call arguments and displays source level traces, but
3886 | it has the drawback that it doesn't determine if frames belong to
3887 | functions from kernel extensions, as with "showallstacks".
3888 | This command may terminate prematurely because of a gdb bug
3889 | (Radar 3758949), which stops macro evaluation on memory read
3893 define showallgdbcorestacks
3895 set $kgm_head_taskp = &tasks
3896 set $kgm_taskp = (struct task *)($kgm_head_taskp->next)
3897 while $kgm_taskp != $kgm_head_taskp
3899 showtaskint $kgm_taskp
3900 set $kgm_head_actp = &($kgm_taskp->threads)
3901 set $kgm_actp = (struct thread *)($kgm_taskp->threads.next)
3902 while $kgm_actp != $kgm_head_actp
3904 showgdbthread $kgm_actp 1 1
3905 set $kgm_actp = (struct thread *)($kgm_actp->task_threads.next)
3908 set $kgm_taskp = (struct task *)($kgm_taskp->tasks.next)
3914 document showallgdbcorestacks
3915 Syntax: showallgdbcorestacks
3916 |Corefile version of "showallgdbstacks"
3920 define switchtouserthread
3922 if ($kgm_mtype == $kgm_mtype_ppc)
3923 if ($kdp_act_counter == 0)
3924 set $kdpstate = (struct savearea *) kdp.saved_state
3926 set $kdp_act_counter = $kdp_act_counter + 1
3927 set $newact = (struct thread *) $arg0
3929 set $checkpc = $newact->machine->upcb.save_srr0
3931 echo This activation does not appear to have
3932 echo \20 a valid user context.\n
3934 set (struct savearea *) kdp.saved_state=$newact->machine->upcb
3936 #flush and update seem to be executed lazily by gdb on Tiger, hence the
3937 #repeated invocations - see 3743135
3939 # This works because the new pmap is used only for reads
3940 set kdp_pmap = $newact->task->map->pmap
3945 echo switchtouserthread not implemented for this architecture.\n
3949 document switchtouserthread
3950 Syntax: switchtouserthread <address of thread>
3951 | Analogous to switchtoact, but switches to the user context of a
3952 | specified thread address. Similar to the "showuserstack"
3953 | command, but this command does not return gdb to the kernel context
3954 | immediately. This is to assist with the following (rather risky)
3955 | manoeuvre - upon switching to the user context and virtual address
3956 | space, the user may choose to call remove-symbol-file on the
3957 | mach_kernel symbol file, and then add-symbol-file on the user space
3958 | binary's symfile. gdb can then generate symbolic backtraces
3959 | for the user space thread. To return to the
3960 | kernel context and virtual address space, the process must be
3961 | reversed, i.e. call remove-symbol-file on the user space symbols, and
3962 | then add-symbol-file on the appropriate mach_kernel, and issue the
3963 | "resetstacks" command. Note that gdb may not react kindly to all these
3964 | symbol file switches. The same restrictions that apply to "showuserstack"
3965 | apply here - pages that have been paged out cannot be read while in the
3966 | debugger context, so backtraces may terminate early.
3967 | If the virtual addresses in the stack trace do not conflict with those
3968 | of symbols in the kernel's address space, it may be sufficient to
3969 | just do an add-symbol-file on the user space binary's symbol file.
3970 | Note that while this command works on Panther's gdb, an issue
3971 | with Tiger gdb (3743135) appears to hamper the evaluation of this
3972 | macro in some cases.
3975 define showmetaclass
3976 set $kgm_metaclassp = (OSMetaClass *)$arg0
3977 printf "%-5d", $kgm_metaclassp->instanceCount
3978 printf "x %5d bytes", $kgm_metaclassp->classSize
3979 printf " %s\n", $kgm_metaclassp->className->string
3983 printf "\"%s\"", ((OSString *)$arg0)->string
3987 printf "%lld", ((OSNumber *)$arg0)->value
3991 if ($arg0 == gOSBooleanFalse)
3998 define showdatabytes
3999 set $kgm_data = (OSData *)$arg0
4002 set $kgm_datap = (const unsigned char *) $kgm_data->data
4004 while ( $kgm_idx < $kgm_data->length )
4005 printf "%02X", *$kgm_datap
4006 set $kgm_datap = $kgm_datap + 1
4007 set $kgm_idx = $kgm_idx + 1
4013 set $kgm_data = (OSData *)$arg0
4016 set $kgm_datap = (const unsigned char *) $kgm_data->data
4018 set $kgm_printstr = 0
4019 if (0 == (3 & (unsigned int)$kgm_datap) && ($kgm_data->length >= 3))
4020 set $kgm_bytes = *(unsigned int *) $kgm_datap
4021 if (0xffff0000 & $kgm_bytes)
4023 set $kgm_printstr = 1
4024 while ($kgm_idx++ < 4)
4025 set $kgm_bytes = $kgm_bytes >> 8
4026 set $kgm_char = 0xff & $kgm_bytes
4027 if ($kgm_char && (($kgm_char < 0x20) || ($kgm_char > 0x7e)))
4028 set $kgm_printstr = 0
4037 while ($kgm_idx < $kgm_data->length)
4038 set $kgm_char = $kgm_datap[$kgm_idx++]
4040 if (0 == $kgm_quoted)
4048 printf "%c", $kgm_char
4060 if (0 == (3 & (unsigned int)$kgm_datap))
4061 while (($kgm_idx + 3) <= $kgm_data->length)
4062 printf "%08x", *(unsigned int *) &$kgm_datap[$kgm_idx]
4063 set $kgm_idx = $kgm_idx + 4
4066 while ($kgm_idx < $kgm_data->length)
4067 printf "%02x", $kgm_datap[$kgm_idx++]
4073 define showdictionaryint
4074 set $kgm$arg0_dict = (OSDictionary *)$arg1
4077 set $kgm$arg0_idx = 0
4078 while ($kgm$arg0_idx < $kgm$arg0_dict->count)
4079 set $kgm_obj = $kgm$arg0_dict->dictionary[$kgm$arg0_idx].key
4080 showobjectint _$arg0 $kgm_obj
4082 set $kgm_obj = $kgm$arg0_dict->dictionary[$kgm$arg0_idx++].value
4083 showobjectint _$arg0 $kgm_obj
4084 if ($kgm$arg0_idx < $kgm$arg0_dict->count)
4093 while ($kgm_idx < $arg0)
4094 if ($arg1 & (1 << $kgm_idx++))
4102 define showregdictionary
4103 indent $kgm_reg_depth+2 $arg1
4106 set $kgm_reg_idx = 0
4107 while ($kgm_reg_idx < $arg0->count)
4108 indent $kgm_reg_depth+2 $arg1
4110 set $kgm_obj = $arg0->dictionary[$kgm_reg_idx].key
4111 showobjectint _ $kgm_obj
4114 set $kgm_obj = $arg0->dictionary[$kgm_reg_idx++].value
4115 showobjectint _ $kgm_obj
4118 indent $kgm_reg_depth+2 $arg1
4123 define showorderedsetarrayint
4124 set $kgm$arg0_array = (_Element *)$arg1
4125 set $kgm$arg0_count = $arg2
4127 set $kgm$arg0_idx = 0
4128 while ($kgm$arg0_idx < $kgm$arg0_count)
4129 set $kgm_obj = $kgm$arg0_array[$kgm$arg0_idx++]
4130 showobjectint _$arg0 $kgm_obj
4131 if ($kgm$arg0_idx < $kgm$arg0_count)
4137 define showorderedsetint
4138 set $kgm_array = ((OSOrderedSet *)$arg1)->array
4139 set $count = ((OSOrderedSet *)$arg1)->count
4141 showorderedsetarrayint $arg0 $kgm_array $count
4145 define showarraysetint
4146 set $kgm$arg0_array = (OSArray *)$arg1
4148 set $kgm$arg0_idx = 0
4149 while ($kgm$arg0_idx < $kgm$arg0_array->count)
4150 set $kgm_obj = $kgm$arg0_array->array[$kgm$arg0_idx++]
4151 showobjectint _$arg0 $kgm_obj
4152 if ($kgm$arg0_idx < $kgm$arg0_array->count)
4160 showarraysetint $arg0 $arg1
4165 set $kgm_array = ((OSSet *)$arg1)->members
4167 showarraysetint $arg0 $kgm_array
4172 define showobjectint
4173 set $kgm_obj = (OSObject *) $arg1
4174 set $kgm_vt = *((void **) $arg1)
4176 if ($kgm_lp64 || $kgm_mtype == $kgm_mtype_arm)
4177 set $kgm_vt = $kgm_vt - 2 * sizeof(void *)
4180 if ($kgm_show_object_addrs)
4184 output /a (unsigned long) $kgm_vt
4185 if ($kgm_show_object_retain)
4186 printf ", retain count %d, container retain %d", (0xffff & $kgm_obj->retainCount), $kgm_obj->retainCount >> 16
4191 # No multiple-inheritance
4193 if ($kgm_vt == &_ZTV8OSString)
4197 if ($kgm_vt == &_ZTV8OSSymbol)
4201 if ($kgm_vt == &_ZTV8OSNumber)
4205 if ($kgm_vt == &_ZTV6OSData)
4206 if $kgm_show_data_alwaysbytes == 1
4213 if ($kgm_vt == &_ZTV9OSBoolean)
4217 if ($kgm_vt == &_ZTV12OSDictionary)
4218 showdictionaryint _$arg0 $arg1
4221 if ($kgm_vt == &_ZTV7OSArray)
4222 showarrayint _$arg0 $arg1
4225 if ($kgm_vt == &_ZTV5OSSet)
4226 showsetint _$arg0 $arg1
4229 if ($kgm_vt == &_ZTV12OSOrderedSet)
4230 showorderedsetint _$arg0 $arg1
4234 if ($kgm_shown != 1)
4235 if ($kgm_show_object_addrs == 0)
4239 output /a (unsigned long) $kgm_vt
4246 set $kgm_save = $kgm_show_object_addrs
4247 set $kgm_show_object_addrs = 1
4248 set $kgm_show_object_retain = 1
4249 showobjectint _ $arg0
4250 set $kgm_show_object_addrs = $kgm_save
4251 set $kgm_show_object_retain = 0
4255 Syntax: (gdb) showobject <object address>
4256 | Show info about an OSObject - its vtable ptr and retain count.
4257 | If the object is a simple container class, more info will be shown.
4261 set $kgm_dictp = (OSDictionary *)$arg0
4262 set $kgm_keyp = (const OSSymbol *)$arg1
4265 while (($kgm_idx < $kgm_dictp->count) && ($kgm_result == 0))
4266 if ($kgm_keyp == $kgm_dictp->dictionary[$kgm_idx].key)
4267 set $kgm_result = $kgm_dictp->dictionary[$kgm_idx].value
4269 set $kgm_idx = $kgm_idx + 1
4274 define _registryentryrecurseinit
4275 set $kgm_re = (IOService *)$arg1
4276 set $kgm$arg0_stack = (unsigned long long) $arg2
4279 set $kgm$arg0_stack = $kgm$arg0_stack | (1ULL << $kgm_reg_depth)
4281 set $kgm$arg0_stack = $kgm$arg0_stack & ~(1ULL << $kgm_reg_depth)
4284 dictget $kgm_re->fRegistryTable $kgm_childkey
4285 set $kgm$arg0_child_array = (OSArray *) $kgm_result
4287 if ($kgm$arg0_child_array)
4288 set $kgm$arg0_child_count = $kgm$arg0_child_array->count
4290 set $kgm$arg0_child_count = 0
4293 if ($kgm$arg0_child_count)
4294 set $kgm$arg0_stack = $kgm$arg0_stack | (2ULL << $kgm_reg_depth)
4296 set $kgm$arg0_stack = $kgm$arg0_stack & ~(2ULL << $kgm_reg_depth)
4300 define findregistryentryrecurse
4301 set $kgm_registry_entry = 0
4302 _registryentryrecurseinit $arg0 $arg1 $arg2 $arg3
4304 dictget $kgm_re->fRegistryTable $kgm_namekey
4305 if ($kgm_result == 0)
4306 dictget $kgm_re->fRegistryTable gIONameKey
4308 if ($kgm_result == 0)
4309 dictget $kgm_re->fPropertyTable gIOClassKey
4312 if ($kgm_result != 0)
4313 set $str = ((OSString *) $kgm_result)->string
4314 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
4315 if $kgm_findregistry_verbose
4319 if $kgm_strcmp_result == 0
4320 if $kgm_findregistry_verbose
4321 printf "\n%s:\n | ", ((OSString *) $kgm_result)->string
4327 # don't populate $kgm_registry_entry if we want to show everything
4328 if !$kgm_findregistry_continue
4329 set $kgm_registry_entry = $kgm_re
4335 if (!$kgm_registry_entry && ($kgm$arg0_child_count != 0))
4336 set $kgm_reg_depth = $kgm_reg_depth + 1
4337 set $kgm$arg0_child_idx = 0
4339 while ($kgm$arg0_child_idx < $kgm$arg0_child_count)
4340 set $kgm_re = $kgm$arg0_child_array->array[$kgm$arg0_child_idx++]
4341 set $kgm_more_sib = ($kgm$arg0_child_idx < $kgm$arg0_child_count)
4342 if $kgm_reg_depth >= $kgm_reg_depth_max + 1
4345 findregistryentryrecurse _$arg0 $kgm_re $kgm$arg0_stack $kgm_more_sib
4346 if $kgm_registry_entry
4350 set $kgm_reg_depth = $kgm_reg_depth - 1
4354 define findregdictvalue
4355 set $kgm_registry_value = 0
4356 set $kgm_reg_idx = 0
4357 while ($kgm_reg_idx < $arg0->count)
4358 set $kgm_obj = $arg0->dictionary + $kgm_reg_idx
4359 set $str = ((OSString *)$kgm_obj->key)->string
4360 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
4362 if $kgm_strcmp_result == 0
4363 set $kgm_registry_value = $kgm_obj->value
4364 if $kgm_findregistry_verbose
4365 showobject $kgm_registry_value
4366 print $kgm_registry_value
4370 set $kgm_reg_idx = $kgm_reg_idx + 1
4374 define setfindregistrystr
4375 set $kgm_reg_find_str0 = 0
4376 set $kgm_reg_find_str1 = 0
4377 set $kgm_reg_find_str2 = 0
4378 set $kgm_reg_find_str3 = 0
4379 set $kgm_reg_find_str4 = 0
4380 set $kgm_reg_find_str5 = 0
4381 set $kgm_reg_find_str6 = 0
4382 set $kgm_reg_find_str7 = 0
4383 set $kgm_reg_find_str8 = 0
4386 set $kgm_reg_find_str0 = $arg0
4389 set $kgm_reg_find_str1 = $arg1
4392 set $kgm_reg_find_str2 = $arg2
4395 set $kgm_reg_find_str3 = $arg3
4398 set $kgm_reg_find_str4 = $arg4
4401 set $kgm_reg_find_str5 = $arg5
4404 set $kgm_reg_find_str6 = $arg6
4407 set $kgm_reg_find_str7 = $arg7
4410 set $kgm_reg_find_str8 = $arg8
4414 document setfindregistrystr
4415 Syntax: (gdb) setfindregistrystr [a] [b] [c] [d] [e] [f] [g] [h] [i]
4416 | Store an encoded string into up to 9 arguments for use by
4417 | findregistryprop or findregistryentry. The arguments are created
4418 | through calls to strcmp_arg_pack64
4421 define _findregistryprop
4422 set $reg = (IOService *) $arg0
4423 set $kgm_props = $reg->fPropertyTable
4424 set $kgm_findregistry_verbose = 0
4426 findregdictvalue $kgm_props
4429 define findregistryprop
4430 set $reg = (IOService *) $arg0
4431 set $kgm_props = $reg->fPropertyTable
4433 set $kgm_findregistry_verbose = 1
4434 findregdictvalue $kgm_props
4437 document findregistryprop
4438 Syntax: (gdb) findregistryprop <entry>
4439 | Given a registry entry, print out the contents for the property that matches
4440 | the encoded string specified via setfindregistrystr.
4442 | For example, the following will print out the "intel-pic" property stored in
4443 | the AppleACPIPlatformExpert registry entry $pe_entry:
4444 | strcmp_arg_pack64 'i' 'n' 't' 'e' 'l' '-' 'p' 'i'
4445 | set $intel_pi = $kgm_strcmp_arg
4446 | strcmp_arg_pack64 'c' 0 0 0 0 0 0 0
4447 | set $c = $kgm_strcmp_arg
4448 | setfindregistrystr $intel_pi $c
4449 | findregistryprop $pe_entry
4452 define findregistryentryint
4454 set $kgm_reg_plane = (IORegistryPlane *) gIOServicePlane
4458 printf "Please load kgmacros after KDP attaching to the target.\n"
4460 set $kgm_namekey = (OSSymbol *) $kgm_reg_plane->nameKey
4461 set $kgm_childkey = (OSSymbol *) $kgm_reg_plane->keys[1]
4462 if $kgm_findregistry_verbose
4465 findregistryentryrecurse _ $arg0 0 0
4469 define _findregistryentry
4470 set $kgm_findregistry_verbose = 0
4471 set $kgm_findregistry_continue = 0
4472 set $kgm_reg_depth = 0
4474 findregistryentryint gRegistryRoot
4477 define findregistryentry
4478 set $kgm_findregistry_verbose = 1
4479 set $kgm_findregistry_continue = 0
4480 set $kgm_reg_depth = 0
4482 findregistryentryint gRegistryRoot
4485 define findregistryentries
4486 set $kgm_findregistry_verbose = 1
4487 set $kgm_findregistry_continue = 1
4488 set $kgm_reg_depth = 0
4490 findregistryentryint gRegistryRoot
4493 document findregistryentry
4494 Syntax: (gdb) findregistryentry
4495 | Search for a registry entry that matches the encoded string specified through
4496 | setfindregistrystr. You can alter the search depth through use of
4497 | $kgm_reg_depth_max.
4499 | For example, the following will pull out the AppleACPIPlatformExpert registry
4501 | strcmp_arg_pack64 'A' 'p' 'p' 'l' 'e' 'A' 'C' 'P'
4502 | set $AppleACP = $kgm_strcmp_arg
4503 | strcmp_arg_pack64 'I' 'P' 'l' 'a' 't' 'f' 'o' 'r'
4504 | set $IPlatfor = $kgm_strcmp_arg
4505 | strcmp_arg_pack64 'm' 'E' 'x' 'p' 'e' 'r' 't' 0
4506 | set $mExpert = $kgm_strcmp_arg
4507 | setfindregistrystr $AppleACP $IPlatfor $mExpert
4511 document findregistryentries
4512 Syntax: (gdb) findregistryentries
4513 | Search for all registry entries that match the encoded string specified through
4514 | setfindregistrystr. You can alter the search depth through use of
4515 | $kgm_reg_depth_max. See findregistryentry for an example of how to encode a string.
4519 define showregistryentryrecurse
4520 _registryentryrecurseinit $arg0 $arg1 $arg2 $arg3
4522 indent $kgm_reg_depth $kgm$arg0_stack
4525 dictget $kgm_re->fRegistryTable $kgm_namekey
4526 if ($kgm_result == 0)
4527 dictget $kgm_re->fRegistryTable gIONameKey
4529 if ($kgm_result == 0)
4530 dictget $kgm_re->fPropertyTable gIOClassKey
4533 if ($kgm_result != 0)
4534 printf "%s", ((OSString *)$kgm_result)->string
4536 if (((IOService*)$kgm_re)->pwrMgt && ((IOService*)$kgm_re)->pwrMgt->Name)
4537 printf "%s", ((IOService*)$kgm_re)->pwrMgt->Name
4539 # printf ", guessclass "
4540 # guessclass $kgm_re
4548 printf ", id 0x%llx, ", $kgm_re->IORegistryEntry::reserved->fRegistryEntryID
4550 set $kgm_vt = (unsigned long) *(void**) $kgm_re
4551 if ($kgm_lp64 || $kgm_mtype == $kgm_mtype_arm)
4552 set $kgm_vt = $kgm_vt - 2 * sizeof(void *)
4556 if ($kgm_vt != &_ZTV15IORegistryEntry)
4558 set $kgm_state = $kgm_re->__state[0]
4559 # kIOServiceRegisteredState
4560 if (0 == ($kgm_state & 2))
4563 printf "registered, "
4564 # kIOServiceMatchedState
4565 if (0 == ($kgm_state & 4))
4569 # kIOServiceInactiveState
4573 printf "active, busy %d, retain count %d", (0xff & $kgm_re->__state[1]), (0xffff & $kgm_re->retainCount)
4577 if ($kgm_show_props)
4578 set $kgm_props = $kgm_re->fPropertyTable
4579 showregdictionary $kgm_props $kgm$arg0_stack
4583 if ($kgm$arg0_child_count != 0)
4585 set $kgm_reg_depth = $kgm_reg_depth + 1
4586 set $kgm$arg0_child_idx = 0
4588 while ($kgm$arg0_child_idx < $kgm$arg0_child_count)
4589 set $kgm_re = $kgm$arg0_child_array->array[$kgm$arg0_child_idx++]
4590 set $kgm_more_sib = ($kgm$arg0_child_idx < $kgm$arg0_child_count)
4591 if $kgm_reg_depth >= $kgm_reg_depth_max + 1
4594 showregistryentryrecurse _$arg0 $kgm_re $kgm$arg0_stack $kgm_more_sib
4597 set $kgm_reg_depth = $kgm_reg_depth - 1
4601 define showregistryentryint
4603 set $kgm_reg_plane = (IORegistryPlane *) gIOServicePlane
4607 printf "Please load kgmacros after KDP attaching to the target.\n"
4609 set $kgm_namekey = (OSSymbol *) $kgm_reg_plane->nameKey
4610 set $kgm_childkey = (OSSymbol *) $kgm_reg_plane->keys[1]
4611 showregistryentryrecurse _ $arg0 0 0
4616 set $kgm_reg_depth = 0
4617 set $kgm_show_props = 0
4618 showregistryentryint gRegistryRoot
4620 document showregistry
4621 Syntax: (gdb) showregistry
4622 | Show info about all registry entries in the current plane. You can specify the maximum
4623 | display depth with $kgm_reg_depth_max.
4626 define showregistryprops
4627 set $kgm_reg_depth = 0
4628 set $kgm_show_props = 1
4629 showregistryentryint gRegistryRoot
4631 document showregistryprops
4632 Syntax: (gdb) showregistryprops
4633 | Show info about all registry entries in the current plane, and their properties.
4634 | set $kgm_show_object_addrs = 1 and/or set $kgm_show_object_retain = 1 will display
4635 | more verbose information
4638 define showregistryentry
4639 set $kgm_reg_depth = 0
4640 set $kgm_show_props = 1
4641 showregistryentryint $arg0
4643 document showregistryentry
4644 Syntax: (gdb) showregistryentry <object address>
4645 | Show info about a registry entry; its properties and descendants in the current plane.
4648 define setregistryplane
4650 set $kgm_reg_plane = (IORegistryPlane *) $arg0
4652 showobjectint _ gIORegistryPlanes
4656 document setregistryplane
4657 Syntax: (gdb) setregistryplane <plane object address>
4658 | Set the plane to be used for the iokit registry macros. An argument of zero will
4659 | display known planes.
4663 set $kgm_classidx = 0
4664 set $kgm_lookvt = *((void **) $arg0)
4665 set $kgm_bestvt = (void *) 0
4666 set $kgm_bestidx = 0
4668 while $kgm_classidx < sAllClassesDict->count
4669 set $kgm_meta = (OSMetaClass *) sAllClassesDict->dictionary[$kgm_classidx].value
4671 set $kgm_vt = *((void **) $kgm_meta)
4673 if (($kgm_vt > $kgm_bestvt) && ($kgm_vt < $kgm_lookvt))
4674 set $kgm_bestvt = $kgm_vt
4675 set $kgm_bestidx = $kgm_classidx
4677 set $kgm_classidx = $kgm_classidx + 1
4679 printf "%s", sAllClassesDict->dictionary[$kgm_bestidx].key->string
4682 define showallclasses
4683 set $kgm_classidx = 0
4684 while $kgm_classidx < sAllClassesDict->count
4685 set $kgm_meta = (OSMetaClass *) sAllClassesDict->dictionary[$kgm_classidx++].value
4686 showmetaclass $kgm_meta
4690 document showallclasses
4691 Syntax: (gdb) showallclasses
4692 | Show the instance counts and ivar size of all OSObject subclasses. See ioclasscount man page for details.
4696 printf " Instance allocation = 0x%08lx = %4ld K\n", (int) debug_ivars_size, ((int) debug_ivars_size) / 1024
4697 printf "Container allocation = 0x%08lx = %4ld K\n", (int) debug_container_malloc_size, ((int) debug_container_malloc_size) / 1024
4698 printf " IOMalloc allocation = 0x%08lx = %4ld K\n", (int) debug_iomalloc_size, ((int) debug_iomalloc_size) / 1024
4699 printf " Pageable allocation = 0x%08lx = %4ld K\n", (vm_size_t) debug_iomallocpageable_size, ((vm_size_t) debug_iomallocpageable_size) / 1024
4702 document showioalloc
4703 Syntax: (gdb) showioalloc
4704 | Show some accounting of memory allocated by IOKit allocators. See ioalloccount man page for details.
4707 define showosobjecttracking
4708 set $kgm_next = (OSObjectTracking *) gOSObjectTrackList.next
4709 while $kgm_next != &gOSObjectTrackList
4710 set $obj = (OSObject *) ($kgm_next+1)
4713 while $kgm_idx < (sizeof($kgm_next->bt) / sizeof($kgm_next->bt[0]))
4714 if ((unsigned long) $kgm_next->bt[$kgm_idx] > (unsigned long) &last_kernel_symbol)
4715 showkmodaddr $kgm_next->bt[$kgm_idx]
4718 if ((unsigned long) $kgm_next->bt[$kgm_idx] > 0)
4719 output /a $kgm_next->bt[$kgm_idx]
4723 set $kgm_idx = $kgm_idx + 1
4726 set $kgm_next = (OSObjectTracking *) $kgm_next->link.next
4730 document showosobjecttracking
4731 Syntax: (gdb) showosobjecttracking
4732 | Show the list of tracked OSObject allocations with backtraces.
4733 | Boot with the kOSTraceObjectAlloc (0x00400000) io debug flag set.
4734 | Set gOSObjectTrackThread to 1 or a thread_t to capture new OSObjects allocated by a thread or all threads.
4737 # $kgm_readphys_force_kdp and $kgm_readphys_force_physmap
4738 # can respectively cause physical memory access to use
4739 # a KDP manual packet or the physical memory mapping
4740 # even if the default behavior would be otherwise.
4742 set $kgm_readphysint_result = 0xBAD10AD
4744 if ($kgm_readphys_force_kdp != 0)
4745 set $kgm_readphys_use_kdp = 1
4747 if ($kgm_readphys_force_physmap)
4748 set $kgm_readphys_use_kdp = 0
4750 set $kgm_readphys_use_kdp = ( kdp->is_conn > 0 )
4754 if ($kgm_readphys_use_kdp)
4756 # set up the manual KDP packet
4757 set manual_pkt.input = 0
4758 set manual_pkt.len = sizeof(kdp_readphysmem64_req_t)
4759 set $kgm_pkt = (kdp_readphysmem64_req_t *)&manual_pkt.data
4760 set $kgm_pkt->hdr.request = KDP_READPHYSMEM64
4761 set $kgm_pkt->hdr.len = sizeof(kdp_readphysmem64_req_t)
4762 set $kgm_pkt->hdr.is_reply = 0
4763 set $kgm_pkt->hdr.seq = 0
4764 set $kgm_pkt->hdr.key = 0
4765 set $kgm_pkt->address = (uint64_t)$arg0
4766 set $kgm_pkt->nbytes = $arg1 >> 3
4767 set $kgm_pkt->lcpu = $arg2
4768 set manual_pkt.input = 1
4769 # dummy to make sure manual packet is executed
4770 set $kgm_dummy = &_mh_execute_header
4771 set $kgm_pkt = (kdp_readphysmem64_reply_t *)&manual_pkt.data
4772 if ($kgm_pkt->error == 0)
4774 set $kgm_readphysint_result = *((uint8_t *)$kgm_pkt->data)
4777 set $kgm_readphysint_result = *((uint16_t *)$kgm_pkt->data)
4780 set $kgm_readphysint_result = *((uint32_t *)$kgm_pkt->data)
4783 set $kgm_readphysint_result = *((uint64_t *)$kgm_pkt->data)
4788 # No KDP. Attempt to use physical memory mapping
4790 if ($kgm_mtype == $kgm_mtype_x86_64)
4791 set $kgm_readphys_paddr_in_kva = (unsigned long long)$arg0 + physmap_base
4793 if ($kgm_mtype == $kgm_mtype_arm)
4794 set $kgm_readphys_paddr_in_kva = (unsigned long long)$arg0 - gPhysBase + gVirtBase
4796 printf "readphys not available for current architecture.\n"
4797 set $kgm_readphys_paddr_in_kva = 0
4800 if $kgm_readphys_paddr_in_kva
4802 set $kgm_readphysint_result = *((uint8_t *)$kgm_readphys_paddr_in_kva)
4805 set $kgm_readphysint_result = *((uint16_t *)$kgm_readphys_paddr_in_kva)
4808 set $kgm_readphysint_result = *((uint32_t *)$kgm_readphys_paddr_in_kva)
4811 set $kgm_readphysint_result = *((uint64_t *)$kgm_readphys_paddr_in_kva)
4818 readphysint $arg0 8 $kgm_lcpu_self
4820 printf ":\t0x%02hhx\n", $kgm_readphysint_result
4821 set $kgm_readphys_result = (uint64_t)$kgm_readphysint_result
4825 readphysint $arg0 16 $kgm_lcpu_self
4827 printf ":\t0x%04hx\n", $kgm_readphysint_result
4828 set $kgm_readphys_result = (uint64_t)$kgm_readphysint_result
4832 readphysint $arg0 32 $kgm_lcpu_self
4834 printf ":\t0x%08x\n", $kgm_readphysint_result
4835 set $kgm_readphys_result = (uint64_t)$kgm_readphysint_result
4839 readphysint $arg0 64 $kgm_lcpu_self
4841 printf ":\t0x%016llx\n", $kgm_readphysint_result
4842 set $kgm_readphys_result = (uint64_t)$kgm_readphysint_result
4862 | The argument is interpreted as a physical address, and the 64-bit word
4863 | addressed is displayed. Saves 64-bit result in $kgm_readphys_result.
4867 # set up the manual KDP packet
4868 set manual_pkt.input = 0
4869 set manual_pkt.len = sizeof(kdp_writephysmem64_req_t)
4870 set $kgm_pkt = (kdp_writephysmem64_req_t *)&manual_pkt.data
4871 set $kgm_pkt->hdr.request = KDP_WRITEPHYSMEM64
4872 set $kgm_pkt->hdr.len = sizeof(kdp_writephysmem64_req_t)
4873 set $kgm_pkt->hdr.is_reply = 0
4874 set $kgm_pkt->hdr.seq = 0
4875 set $kgm_pkt->hdr.key = 0
4876 set $kgm_pkt->address = (uint64_t)$arg0
4877 set $kgm_pkt->nbytes = $arg1 >> 3
4878 set $kgm_pkt->lcpu = $arg3
4880 set *(uint8_t *)$kgm_pkt->data = (uint8_t)$arg2
4883 set *(uint16_t *)$kgm_pkt->data = (uint16_t)$arg2
4886 set *(uint32_t *)$kgm_pkt->data = (uint32_t)$arg2
4889 set *(uint64_t *)$kgm_pkt->data = (uint64_t)$arg2
4891 set manual_pkt.input = 1
4892 # dummy to make sure manual packet is executed
4893 set $kgm_dummy = &_mh_execute_header
4894 set $kgm_pkt = (kdp_writephysmem64_reply_t *)&manual_pkt.data
4895 set $kgm_writephysint_result = $kgm_pkt->error
4899 writephysint $arg0 8 $arg1 $kgm_lcpu_self
4903 writephysint $arg0 16 $arg1 $kgm_lcpu_self
4907 writephysint $arg0 32 $arg1 $kgm_lcpu_self
4911 writephysint $arg0 64 $arg1 $kgm_lcpu_self
4918 document writephys16
4922 document writephys32
4926 document writephys64
4927 | The argument is interpreted as a physical address, and the second argument is
4928 | written to that address as a 64-bit word.
4934 printf "Adding kext symbols from in-kernel summary data.\n"
4937 printf "Adding kext symbols from $arg0.\n"
4938 shell echo cd `pwd` > /tmp/gdb-cd
4943 set $kgm_show_kmod_syms = 1
4945 printf "| Usage:\n|\n"
4950 document addkextsyms
4951 | If specified without an argument, uses gdb's add-all-kexts command to load
4952 | kext symbols. Otherwise, takes a directory of kext symbols generated with
4953 | kextcache -y or kcgen and loads them into gdb.
4956 | (gdb) addkextsyms /path/to/symboldir
4959 define showprocfiles
4962 _showprocfiles $arg0
4964 printf "| Usage:\n|\n"
4968 document showprocfiles
4969 Syntax: (gdb) showprocfiles <proc_t>
4970 | Given a proc_t pointer, display the list of open file descriptors for the
4971 | referenced process.
4974 define _showprocheader
4975 printf "fd fileglob "
4977 printf " fg flags fg type fg data "
4980 printf "----- ----------"
4984 printf " ---------- -------- ----------"
4988 printf " -------------------\n"
4991 define _showprocfiles
4992 set $kgm_spf_filedesc = ((proc_t)$arg0)->p_fd
4993 set $kgm_spf_last = $kgm_spf_filedesc->fd_lastfile
4994 set $kgm_spf_ofiles = $kgm_spf_filedesc->fd_ofiles
4995 set $kgm_spf_count = 0
4996 while ($kgm_spf_count <= $kgm_spf_last)
4997 if ($kgm_spf_ofiles[$kgm_spf_count] == 0)
4998 # DEBUG: For files that were open, but are now closed
4999 # printf "%-5d FILEPROC_NULL\n", $kgm_spf_count
5001 # display fd #, fileglob address, fileglob flags
5002 set $kgm_spf_flags = $kgm_spf_ofiles[$kgm_spf_count].f_flags
5003 set $kgm_spf_fg = $kgm_spf_ofiles[$kgm_spf_count].f_fglob
5004 printf "%-5d ", $kgm_spf_count
5006 printf " 0x%08x ", $kgm_spf_flags
5007 # decode fileglob type
5008 set $kgm_spf_fgt = $kgm_spf_fg->fg_type
5009 if ($kgm_spf_fgt == 1)
5012 if ($kgm_spf_fgt == 2)
5015 if ($kgm_spf_fgt == 3)
5018 if ($kgm_spf_fgt == 4)
5021 if ($kgm_spf_fgt == 5)
5024 if ($kgm_spf_fgt == 6)
5027 if ($kgm_spf_fgt == 7)
5030 if ($kgm_spf_fgt < 1 || $kgm_spf_fgt > 7)
5031 printf "?: %-5d", $kgm_spf_fgt
5034 # display fileglob data address and decode interesting fact(s)
5035 # about data, if we know any
5036 set $kgm_spf_fgd = $kgm_spf_fg->fg_data
5038 showptr $kgm_spf_fgd
5040 if ($kgm_spf_fgt == 1)
5041 set $kgm_spf_name = ((struct vnode *)$kgm_spf_fgd)->v_name
5042 if ($kgm_spf_name == 0)
5045 printf "%s", $kgm_spf_name
5050 set $kgm_spf_count = $kgm_spf_count + 1
5055 # Show all the advisory file locks held by a process for each of the vnode
5056 # type files that it has open; do this by walking the per process open file
5057 # table and looking at any vnode type fileglob that has a non-NULL lock list
5058 # associated with it.
5060 define showproclocks
5062 _showproclocks $arg0
5064 printf "| Usage:\n|\n"
5068 document showproclocks
5069 Syntax: (gdb) showproclocks <proc_t>
5070 | Given a proc_t pointer, display the list of advisory file locks held by the
5071 | referenced process.
5074 define _showproclocks
5075 set $kgm_spl_filedesc = ((proc_t)$arg0)->p_fd
5076 set $kgm_spl_last = $kgm_spl_filedesc->fd_lastfile
5077 set $kgm_spl_ofiles = $kgm_spl_filedesc->fd_ofiles
5078 set $kgm_spl_count = 0
5079 set $kgm_spl_seen = 0
5080 while ($kgm_spl_count <= $kgm_spl_last)
5081 if ($kgm_spl_ofiles[$kgm_spl_count] == 0)
5082 # DEBUG: For files that were open, but are now closed
5083 # printf "%-5d FILEPROC_NULL\n", $kgm_spl_count
5085 set $kgm_spl_fg = $kgm_spl_ofiles[$kgm_spl_count].f_fglob
5086 # decode fileglob type
5087 set $kgm_spl_fgt = $kgm_spl_fg->fg_type
5088 if ($kgm_spl_fgt == 1)
5089 set $kgm_spl_fgd = $kgm_spl_fg->fg_data
5090 set $kgm_spl_name = ((struct vnode *)$kgm_spl_fgd)->v_name
5091 set $kgm_spl_vnode = ((vnode_t)$kgm_spl_fgd)
5092 set $kgm_spl_lockiter = $kgm_spl_vnode->v_lockf
5093 if ($kgm_spl_lockiter != 0)
5094 if ($kgm_spl_seen == 0)
5095 _showvnodelockheader
5097 set $kgm_spl_seen = $kgm_spl_seen + 1
5098 printf "( fd %d, name ", $kgm_spl_count
5099 if ($kgm_spl_name == 0)
5102 printf "%s )\n", $kgm_spl_name
5104 _showvnodelocks $kgm_spl_fgd
5108 set $kgm_spl_count = $kgm_spf_count + 1
5110 printf "%d total locks for ", $kgm_spl_seen
5116 set $kgm_spi_proc = (proc_t)$arg0
5118 showptr $kgm_spi_proc
5120 printf " name %s\n", $kgm_spi_proc->p_comm
5121 printf " pid:%.8d", $kgm_spi_proc->p_pid
5123 showptr $kgm_spi_proc->task
5124 printf " p_stat:%.1d", $kgm_spi_proc->p_stat
5125 printf " parent pid:%.8d", $kgm_spi_proc->p_ppid
5127 # decode part of credential
5128 set $kgm_spi_cred = $kgm_spi_proc->p_ucred
5129 if ($kgm_spi_cred != 0)
5130 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
5132 printf "Cred: (null)\n"
5135 set $kgm_spi_flag = $kgm_spi_proc->p_flag
5136 printf "Flags: 0x%08x\n", $kgm_spi_flag
5137 if ($kgm_spi_flag & 0x00000001)
5138 printf " 0x00000001 - may hold advisory locks\n"
5140 if ($kgm_spi_flag & 0x00000002)
5141 printf " 0x00000002 - has a controlling tty\n"
5143 if ($kgm_spi_flag & 0x00000004)
5144 printf " 0x00000004 - process is 64 bit\n"
5146 printf " !0x00000004 - process is 32 bit\n"
5148 if ($kgm_spi_flag & 0x00000008)
5149 printf " 0x00000008 - no SIGCHLD on child stop\n"
5151 if ($kgm_spi_flag & 0x00000010)
5152 printf " 0x00000010 - waiting for child exec/exit\n"
5154 if ($kgm_spi_flag & 0x00000020)
5155 printf " 0x00000020 - has started profiling\n"
5157 if ($kgm_spi_flag & 0x00000040)
5158 printf " 0x00000040 - in select; wakeup/waiting danger\n"
5160 if ($kgm_spi_flag & 0x00000080)
5161 printf " 0x00000080 - was stopped and continued\n"
5163 if ($kgm_spi_flag & 0x00000100)
5164 printf " 0x00000100 - has set privileges since exec\n"
5166 if ($kgm_spi_flag & 0x00000200)
5167 printf " 0x00000200 - system process: no signals, stats, or swap\n"
5169 if ($kgm_spi_flag & 0x00000400)
5170 printf " 0x00000400 - timing out during a sleep\n"
5172 if ($kgm_spi_flag & 0x00000800)
5173 printf " 0x00000800 - debugged process being traced\n"
5175 if ($kgm_spi_flag & 0x00001000)
5176 printf " 0x00001000 - debugging process has waited for child\n"
5178 if ($kgm_spi_flag & 0x00002000)
5179 printf " 0x00002000 - exit in progress\n"
5181 if ($kgm_spi_flag & 0x00004000)
5182 printf " 0x00004000 - process has called exec\n"
5184 if ($kgm_spi_flag & 0x00008000)
5185 printf " 0x00008000 - owe process an addupc() XXX\n"
5187 if ($kgm_spi_flag & 0x00010000)
5188 printf " 0x00010000 - affinity for Rosetta children\n"
5190 if ($kgm_spi_flag & 0x00020000)
5191 printf " 0x00020000 - wants to run Rosetta\n"
5193 if ($kgm_spi_flag & 0x00040000)
5194 printf " 0x00040000 - has wait() in progress\n"
5196 if ($kgm_spi_flag & 0x00080000)
5197 printf " 0x00080000 - kdebug tracing on for this process\n"
5199 if ($kgm_spi_flag & 0x00100000)
5200 printf " 0x00100000 - blocked due to SIGTTOU or SIGTTIN\n"
5202 if ($kgm_spi_flag & 0x00200000)
5203 printf " 0x00200000 - has called reboot()\n"
5205 if ($kgm_spi_flag & 0x00400000)
5206 printf " 0x00400000 - is TBE state\n"
5208 if ($kgm_spi_flag & 0x00800000)
5209 printf " 0x00800000 - signal exceptions\n"
5211 if ($kgm_spi_flag & 0x01000000)
5212 printf " 0x01000000 - has thread cwd\n"
5214 if ($kgm_spi_flag & 0x02000000)
5215 printf " 0x02000000 - has vfork() children\n"
5217 if ($kgm_spi_flag & 0x04000000)
5218 printf " 0x04000000 - not allowed to attach\n"
5220 if ($kgm_spi_flag & 0x08000000)
5221 printf " 0x08000000 - vfork() in progress\n"
5223 if ($kgm_spi_flag & 0x10000000)
5224 printf " 0x10000000 - no shared libraries\n"
5226 if ($kgm_spi_flag & 0x20000000)
5227 printf " 0x20000000 - force quota for root\n"
5229 if ($kgm_spi_flag & 0x40000000)
5230 printf " 0x40000000 - no zombies when children exit\n"
5232 if ($kgm_spi_flag & 0x80000000)
5233 printf " 0x80000000 - don't hang on remote FS ops\n"
5236 set $kgm_spi_state = $kgm_spi_proc->p_stat
5238 if ($kgm_spi_state == 1)
5241 if ($kgm_spi_state == 2)
5244 if ($kgm_spi_state == 3)
5247 if ($kgm_spi_state == 4)
5250 if ($kgm_spi_state == 5)
5253 if ($kgm_spi_state == 6)
5256 if ($kgm_spi_state < 1 || $kgm_spi_state > 6)
5257 printf "(Unknown)\n"
5261 document showprocinfo
5262 Syntax: (gdb) showprocinfo <proc_t>
5263 | Displays name, pid, parent and task for a proc_t. Decodes cred, flag and p_stat fields.
5267 # dump the zombprocs
5270 set $basep = (struct proc *)zombproc->lh_first
5274 set $pp = $pp->p_list.le_next
5279 Syntax: (gdb) zombproc
5280 | Routine to print out all procs in the zombie list
5284 # dump the zombstacks
5287 set $basep = (struct proc *)zombproc->lh_first
5291 showtaskstacks $pp->task
5293 set $pp = $pp->p_list.le_next
5298 Syntax: (gdb) zombstacks
5299 | Routine to print out all stacks of tasks that are exiting
5307 set $basep = (struct proc *)allproc->lh_first
5311 set $pp = $pp->p_list.le_next
5316 Syntax: (gdb) allproc
5317 | Routine to print out all process in the system
5318 | which are not in the zombie list
5320 define showprocsiblingint
5321 set $kgm_sibling_ptr = (struct proc *)$arg0
5325 set $kgm_lx = $kgm_lx-3
5327 printf "|--%d %s [ 0x%llx ]\n", $kgm_sibling_ptr->p_pid, $kgm_sibling_ptr->p_comm, $kgm_sibling_ptr
5329 define showproctreeint
5330 #Initialize all the set variables used in this macro
5332 set $kgm_sibling_ptr = 0
5334 set $kgm_tmp_base = 0
5335 set $kgm_head_ptr = 0
5336 set $kgm_search_pid = 0
5340 set $kgm_basep1 = (struct proc *)allproc->lh_first
5342 set $kgm_head_ptr = (struct proc *)initproc
5345 set $kgm_tmp_base = (struct proc *)allproc->lh_first
5346 set $kgm_search_pid = $arg0
5348 if ( $kgm_tmp_base->p_pid == $kgm_search_pid)
5349 if ($kgm_tmp_base->p_childrencnt > 0)
5350 set $kgm_head_ptr = $kgm_tmp_base->p_children.lh_first
5352 set $kgm_head_ptr = 0
5353 printf "No children present for PID=%d", $kgm_search_pid
5357 set $kgm_tmp_base = $kgm_tmp_base->p_list.le_next
5363 printf "PID PROCESS POINTER]\n"
5364 printf "=== ======= =======\n"
5365 printf "%d %s [ 0x%llx ]\n", $kgm_head_ptr->p_ppid, $kgm_head_ptr->p_pptr->p_comm, $kgm_head_ptr
5366 printf "|--%d %s [ 0x%llx ]\n", $kgm_head_ptr->p_pid, $kgm_head_ptr->p_comm, $kgm_head_ptr
5368 while ($kgm_head_ptr)
5369 #Is childrencnt = 0? YES {=> no children}
5370 if ($kgm_head_ptr->p_childrencnt == 0)
5371 # Does it have sibling?
5372 if($kgm_head_ptr->p_sibling.le_next == 0)
5373 #No, it does not have sibling, so go back to its parent which will go to its sibling
5374 if($kgm_head_ptr == $kgm_head_ptr->p_pptr)
5377 set $kgm_head_ptr = $kgm_head_ptr->p_pptr
5378 if ($kgm_head_ptr == $kgm_tmp_base)
5382 set $kgm_x = $kgm_x - 3
5386 if($kgm_head_ptr->p_sibling.le_next != 0)
5387 # Yes, it has sibling. So print sibling
5389 showprocsiblingint $kgm_head_ptr->p_sibling.le_next $kgm_x
5390 set $kgm_head_ptr = $kgm_head_ptr->p_sibling.le_next
5392 # childrencnt != 0 {=> it has children}
5395 if($kgm_head_ptr->p_sibling.le_next == 0)
5396 #No, it does not have sibling, so go back to its parent which will go to its sibling
5397 if($kgm_head_ptr == $kgm_head_ptr->p_pptr)
5400 set $kgm_head_ptr = $kgm_head_ptr->p_pptr
5401 if ($kgm_head_ptr == $kgm_tmp_base)
5406 set $kgm_x = $kgm_x - 3
5410 if($kgm_head_ptr->p_sibling.le_next != 0)
5412 # Yes, it has sibling. So print sibling
5413 showprocsiblingint $kgm_head_ptr->p_sibling.le_next $kgm_x
5414 set $kgm_head_ptr = $kgm_head_ptr->p_sibling.le_next
5417 set $kgm_head_ptr = $kgm_head_ptr->p_children.lh_first
5418 set $kgm_x = $kgm_x + 3
5419 set $kgm_lx = $kgm_x
5422 set $kgm_lx = $kgm_lx-3
5424 printf "|--%d %s [ 0x%llx ] \n", $kgm_head_ptr->p_pid, $kgm_head_ptr->p_comm, $kgm_head_ptr
5429 #Unset all the set variables used in this macro
5431 set $kgm_sibling_ptr = 0
5433 set $kgm_tmp_base = 0
5434 set $kgm_head_ptr = 0
5435 set $kgm_search_pid = 0
5441 showproctreeint $arg0
5446 document showproctree
5447 Syntax: (gdb) showproctree <pid>
5448 | Routine to print the processes in the system in a hierarchical tree form. This routine does not print zombie processes.
5449 | If no argument is given, showproctree will print all the processes in the system.
5450 | If pid is specified, showproctree prints all the descendants of the indicated process
5455 set $vp = (struct vnode *)$arg0
5459 printf " use %d", $vp->v_usecount
5460 printf " io %d", $vp->v_iocount
5461 printf " kuse %d", $vp->v_kusecount
5462 printf " type %d", $vp->v_type
5463 printf " flg 0x%.8x", $vp->v_flag
5464 printf " lflg 0x%.8x", $vp->v_lflag
5466 showptr $vp->v_parent
5467 set $_name = (char *)$vp->v_name
5469 printf " %s", $_name
5471 if ($vp->v_type == VREG) && ($vp->v_un.vu_ubcinfo != 0)
5472 printf " mapped %d", ($vp->v_un.vu_ubcinfo.ui_flags & 0x08) ? 1 : 0
5477 document print_vnode
5478 Syntax: (gdb) print_vnode <vnode>
5479 | Prints out the fields of a vnode struct
5482 define showprocvnodes
5483 set $pp = (struct proc *)$arg0
5484 set $fdp = (struct filedesc *)$pp->p_fd
5485 set $cvp = $fdp->fd_cdir
5486 set $rvp = $fdp->fd_rdir
5488 printf "Current Working Directory \n"
5493 printf "Current Root Directory \n"
5498 set $fpp = (struct fileproc **)($fdp->fd_ofiles)
5499 set $fpo = (char)($fdp->fd_ofileflags[0])
5500 while $count < $fdp->fd_nfiles
5501 #printf"fpp %x ", *$fpp
5503 set $fg =(struct fileglob *)((**$fpp)->f_fglob)
5504 if $fg && (($fg)->fg_type == 1)
5505 if $fdp->fd_ofileflags[$count] & 4
5510 printf "fd = %d ", $count
5511 print_vnode $fg->fg_data
5515 set $count = $count + 1
5519 document showprocvnodes
5520 Syntax: (gdb) showprocvnodes <proc_address>
5521 | Routine to print out all the open fds
5522 | which are vnodes in a process
5525 define showallprocvnodes
5526 set $basep = (struct proc *)allproc->lh_first
5529 printf "============================================ \n"
5532 set $pp = $pp->p_list.le_next
5536 document showallprocvnodes
5537 Syntax: (gdb) showallprocvnodes
5538 | Routine to print out all the open fds
5544 # dump the childrent of a proc
5546 define showinitchild
5547 set $basep = (struct proc *)initproc->p_children.lh_first
5551 set $pp = $pp->p_sibling.le_next
5555 document showinitchild
5556 Syntax: (gdb) showinitchild
5557 | Routine to print out all processes in the system
5558 | which are children of init process
5562 define showmountallvnodes
5563 set $mp = (struct mount *)$arg0
5564 set $basevp = (struct vnode *)$mp->mnt_vnodelist.tqh_first
5566 printf "____________________ Vnode list Queue ---------------\n"
5569 set $vp = $vp->v_mntvnodes->tqe_next
5571 set $basevp = (struct vnode *)$mp->mnt_workerqueue.tqh_first
5573 printf "____________________ Worker Queue ---------------\n"
5576 set $vp = $vp->v_mntvnodes->tqe_next
5578 set $basevp = (struct vnode *)$mp->mnt_newvnodes.tqh_first
5580 printf "____________________ New vnodes Queue ---------------\n"
5583 set $vp = $vp->v_mntvnodes->tqe_next
5586 document showmountallvnodes
5587 Syntax: showmountallvnodes <struct mount *>
5588 | Print the vnode inactive list
5592 define showmountvnodes
5593 set $mp = (struct mount *)$arg0
5594 set $basevp = (struct vnode *)$mp->mnt_vnodelist.tqh_first
5596 printf "____________________ Vnode list Queue ---------------\n"
5599 set $vp = $vp->v_mntvnodes->tqe_next
5602 document showmountvnodes
5603 Syntax: showmountvnodes <struct mount *>
5604 | Print the vnode list
5609 define showworkqvnodes
5610 set $mp = (struct mount *)$arg0
5611 set $basevp = (struct vnode *)$mp->mnt_workerqueue.tqh_first
5613 printf "____________________ Worker Queue ---------------\n"
5616 set $vp = $vp->v_mntvnodes->tqe_next
5619 document showworkqvnodes
5620 Syntax: showworkqvnodes <struct mount *>
5621 | Print the vnode worker list
5625 define shownewvnodes
5626 set $mp = (struct mount *)$arg0
5627 set $basevp = (struct vnode *)$mp->mnt_newvnodes.tqh_first
5629 printf "____________________ New vnodes Queue ---------------\n"
5632 set $vp = $vp->v_mntvnodes->tqe_next
5636 document shownewvnodes
5637 Syntax: shownewvnodes <struct mount *>
5638 | Print the new vnode list
5643 # print mount point info
5645 set $mp = (struct mount *)$arg0
5649 printf " flag %x", $mp->mnt_flag
5650 printf " kern_flag %x", $mp->mnt_kern_flag
5651 printf " lflag %x", $mp->mnt_lflag
5652 printf " type: %s", $mp->mnt_vfsstat.f_fstypename
5653 printf " mnton: %s", $mp->mnt_vfsstat.f_mntonname
5654 printf " mntfrom: %s", $mp->mnt_vfsstat.f_mntfromname
5658 define showallmounts
5659 set $mp=(struct mount *)mountlist.tqh_first
5662 set $mp = $mp->mnt_list.tqe_next
5666 document showallmounts
5667 Syntax: showallmounts
5668 | Print all mount points
5672 if (((unsigned long) $arg0 < (unsigned long) &_mh_execute_header || \
5673 (unsigned long) $arg0 >= (unsigned long) &last_kernel_symbol ))
5681 set $mp = (struct mbuf *)$arg0
5685 printf "%4d: %p [len %4d, type %2d, ", $cnt, $mp, \
5686 $mp->m_hdr.mh_len, $mp->m_hdr.mh_type
5691 set $tot = $tot + $mp->m_hdr.mh_len
5692 printf "total %d]\n", $tot
5693 set $mp = $mp->m_hdr.mh_nextpkt
5698 document mbuf_walkpkt
5699 Syntax: (gdb) mbuf_walkpkt <addr>
5700 | Given an mbuf address, walk its m_nextpkt pointer
5704 set $mp = (struct mbuf *)$arg0
5708 printf "%4d: %p [len %4d, type %2d, ", $cnt, $mp, \
5709 $mp->m_hdr.mh_len, $mp->m_hdr.mh_type
5714 set $tot = $tot + $mp->m_hdr.mh_len
5715 printf "total %d]\n", $tot
5716 set $mp = $mp->m_hdr.mh_next
5722 Syntax: (gdb) mbuf_walk <addr>
5723 | Given an mbuf address, walk its m_next pointer
5726 define mbuf_buf2slab
5728 set $gix = ((char *)$addr - (char *)mbutl) >> 20
5729 set $ix = ((char *)$addr - (char *)slabstbl[$gix].slg_slab[0].sl_base) >> 12
5730 set $slab = &slabstbl[$gix].slg_slab[$ix]
5732 printf "0x%-16llx", $slab
5734 printf "0x%-8x", $slab
5738 document mbuf_buf2slab
5739 | Given an mbuf object, find its corresponding slab address.
5744 set $ix = ((char *)$addr - (char *)mbutl) >> 12
5745 set $clbase = ((union mbigcluster *)mbutl) + $ix
5746 set $mclidx = (((char *)$addr - (char *)$clbase) >> 8)
5747 set $mca = mclaudit[$ix].cl_audit[$mclidx]
5749 printf "mca: 0x%-16llx", $mca
5751 printf "mca: 0x%-8x", $mca
5755 document mbuf_buf2mca
5756 Syntax: (gdb) mbuf_buf2mca <addr>
5757 | Given an mbuf object, find its buffer audit structure address.
5758 | This requires mbuf buffer auditing to be turned on, by setting
5759 | the appropriate flags to the "mbuf_debug" boot-args parameter.
5764 set $mca = (mcache_audit_t *)$arg0
5765 set $cp = (mcache_t *)$mca->mca_cache
5766 printf "object type:\t\t"
5767 mbuf_mca_ctype $mca 1
5768 printf "\ncontrolling mcache:\t%p (%s)\n", $mca->mca_cache, $cp->mc_name
5769 if $mca->mca_uflags & $MB_SCVALID
5770 set $ix = ((char *)$mca->mca_addr - (char *)mbutl) >> 12
5771 set $clbase = ((union mbigcluster *)mbutl) + $ix
5772 set $mclidx = (((char *)$mca->mca_addr - (char *)$clbase) >> 8)
5773 printf "mbuf obj:\t\t%p\n", $mca->mca_addr
5774 printf "mbuf index:\t\t%d (out of 16) in cluster base %p\n", \
5775 $mclidx + 1, $clbase
5776 if $mca->mca_uptr != 0
5777 set $peer_mca = (mcache_audit_t *)$mca->mca_uptr
5778 printf "paired cluster obj:\t%p (mca %p)\n", \
5779 $peer_mca->mca_addr, $peer_mca
5781 printf "saved contents:\t\t%p (%d bytes)\n", \
5782 $mca->mca_contents, $mca->mca_contents_size
5784 printf "cluster obj:\t\t%p\n", $mca->mca_addr
5785 if $mca->mca_uptr != 0
5786 set $peer_mca = (mcache_audit_t *)$mca->mca_uptr
5787 printf "paired mbuf obj:\t%p (mca %p)\n", \
5788 $peer_mca->mca_addr, $peer_mca
5791 printf "recent transaction for this buffer (thread %p):\n", \
5794 while $cnt < $mca->mca_depth
5795 set $kgm_pc = $mca->mca_stack[$cnt]
5796 printf "%4d: ", $cnt + 1
5801 if $mca->mca_pdepth > 0
5802 printf "previous transaction for this buffer (thread %p):\n", \
5806 while $cnt < $mca->mca_pdepth
5807 set $kgm_pc = $mca->mca_pstack[$cnt]
5808 printf "%4d: ", $cnt + 1
5816 document mbuf_showmca
5817 Syntax: (gdb) mbuf_showmca <addr>
5818 | Given an mbuf/cluster buffer audit structure address, print the audit
5819 | records including the stack trace of the last buffer transaction.
5830 while $topcnt < $maxcnt
5831 mbuf_traceleak mleak_top_trace[$topcnt]
5832 set $topcnt = $topcnt + 1
5837 document mbuf_topleak
5838 Syntax: (gdb) mbuf_topleak <num>
5839 | Prints information about the top <num> suspected mbuf leakers
5840 | where <num> is a value <= 5
5843 define mbuf_traceleak
5845 set $trace = (struct mtrace *) $arg0
5846 if $trace->allocs != 0
5847 printf "%p:%d outstanding allocs\n", $trace, $trace->allocs
5848 printf "backtrace saved %d deep:\n", $trace->depth
5849 if $trace->depth != 0
5851 while $cnt < $trace->depth
5852 printf "%4d: ", $cnt + 1
5853 pcprint $trace->addr[$cnt]
5862 document mbuf_traceleak
5863 Syntax: (gdb) mbuf_traceleak <addr>
5864 | Given an mbuf leak trace (mtrace) structure address, print out the
5865 | stored information with that trace
5868 set $MCF_NOCPUCACHE = 0x10
5871 set $head = (mcache_t *)mcache_head
5875 printf "cache cache cache buf buf backing (# of retries) bufs\n"
5876 printf "name state addr size align zone wait nowait failed incache\n"
5877 printf "------------------------- -------- ------------------ ------ ----- ------------------ -------------------------- --------\n"
5879 printf "cache cache cache buf buf backing (# of retries) bufs\n"
5880 printf "name state addr size align zone wait nowait failed incache\n"
5881 printf "------------------------- -------- ---------- ------ ----- ---------- -------------------------- --------\n"
5884 set $bktsize = $mc->mc_cpu.cc_bktsize
5885 printf "%-25s ", $mc->mc_name
5886 if ($mc->mc_flags & $MCF_NOCPUCACHE)
5889 if $mc->mc_purge_cnt > 0
5899 printf " %p %6d %5d ",$mc, \
5900 $mc->mc_bufsize, $mc->mc_align
5901 if $mc->mc_slab_zone != 0
5902 printf "%p", $mc->mc_slab_zone
5911 set $tot += $mc->mc_full.bl_total * $bktsize
5912 set $ccp = (mcache_cpu_t *)$mc->mc_cpu
5915 if $ccp->cc_objs > 0
5916 set $tot += $ccp->cc_objs
5918 if $ccp->cc_pobjs > 0
5919 set $tot += $ccp->cc_pobjs
5924 printf " %8d %8d %8d %8d", $mc->mc_wretry_cnt, \
5925 $mc->mc_nwretry_cnt, $mc->mc_nwfail_cnt, $tot
5927 set $mc = (mcache_t *)$mc->mc_list.le_next
5931 document mcache_stat
5932 Syntax: (gdb) mcache_stat
5933 | Print all mcaches in the system.
5936 define mcache_showzone
5937 set $mc = (mcache_t *)$arg0
5938 if $mc->mc_slab_zone != 0
5939 printf "%p", $mc->mc_slab_zone
5944 document mcache_showzone
5945 Syntax: (gdb) mcache_showzone <mcache_addr>
5946 | Print the type of backend (custom or zone) of a mcache.
5949 define mcache_walkobj
5950 set $p = (mcache_obj_t *)$arg0
5954 printf "%4d: %p\n", $cnt, $p,
5955 set $p = $p->obj_next
5960 document mcache_walkobj
5961 Syntax: (gdb) mcache_walkobj <addr>
5962 | Given a mcache object address, walk its obj_next pointer
5965 define mcache_showcache
5966 set $cp = (mcache_t *)$arg0
5967 set $ccp = (mcache_cpu_t *)$cp->mc_cpu
5968 set $bktsize = $cp->mc_cpu.cc_bktsize
5971 printf "Showing cache '%s':\n\n", $cp->mc_name
5972 printf " CPU cc_objs cc_pobjs total\n"
5973 printf "---- -------- -------- --------\n"
5975 set $objs = $ccp->cc_objs
5979 set $pobjs = $ccp->cc_pobjs
5983 set $tot_cpu = $objs + $pobjs
5984 set $tot += $tot_cpu
5985 printf "%4d %8d %8d %8d\n", $cnt, $objs, $pobjs, $tot_cpu
5989 printf " ========\n"
5990 printf " %8d\n", $tot
5992 set $tot += $cp->mc_full.bl_total * $bktsize
5993 printf "Total # of full buckets (%d objs/bkt):\t%-8d\n", \
5994 $bktsize, $cp->mc_full.bl_total
5995 printf "Total # of objects cached:\t\t%-8d\n", $tot
5998 document mcache_showcache
5999 | Display the number of objects in the cache
6002 set $NSLABSPMB = sizeof(mcl_slabg_t)/sizeof(mcl_slab_t)
6004 define mbuf_slabstbl
6008 printf "slot slabg slabs range\n"
6009 printf "---- ------------------ -------------------------------------------\n"
6011 printf "slot slabg slabs range\n"
6012 printf "---- ---------- ---------------------------\n"
6014 while $x < maxslabgrp
6015 set $slg = slabstbl[$x]
6021 printf "0x%-16llx [ 0x%-16llx - 0x%-16llx ]\n", $slg, &$slg->slg_slab[0], \
6022 &$slg->slg_slab[$NSLABSPMB-1]
6024 printf "0x%-8x [ 0x%-8x - 0x%-8x ]\n", $slg, &$slg->slg_slab[0], \
6025 &$slg->slg_slab[$NSLABSPMB-1]
6032 document mbuf_slabstbl
6033 | Display the mbuf slabs table
6036 set $SLF_MAPPED=0x0001
6037 set $SLF_PARTIAL=0x0002
6038 set $SLF_DETACHED=0x0004
6041 set $slg = (mcl_slabg_t *)$arg0
6045 printf "slot slab next obj mca C R N size flags\n"
6046 printf "---- ------------------ ------------------ ------------------ ------------------ -- -- -- ------ -----\n"
6048 printf "slot slab next obj mca C R N size flags\n"
6049 printf "---- ---------- ---------- ---------- ---------- -- -- -- ------ -----\n"
6051 while $x < $NSLABSPMB
6052 set $sl = &$slg->slg_slab[$x]
6054 set $obj = $sl->sl_base
6057 set $ix = ((char *)$obj - (char *)mbutl) >> 12
6058 set $clbase = ((union mbigcluster *)mbutl) + $ix
6059 set $mclidx = (((char *)$obj - (char *)$clbase) >> 8)
6060 set $mca = mclaudit[$ix].cl_audit[$mclidx]
6064 printf "%3d: 0x%-16llx 0x%-16llx 0x%-16llx 0x%-16llx %2d %2d %2d %6d 0x%04x ", \
6065 $x + 1, $sl, $sl->sl_next, $obj, $mca, $sl->sl_class, \
6066 $sl->sl_refcnt, $sl->sl_chunks, $sl->sl_len, \
6069 printf "%3d: 0x%-8x 0x%-8x 0x%-8x 0x%-8x %2d %2d %2d %6d 0x%04x ", \
6070 $x + 1, $sl, $sl->sl_next, $obj, $mca, $sl->sl_class, \
6071 $sl->sl_refcnt, $sl->sl_chunks, $sl->sl_len, \
6074 if $sl->sl_flags != 0
6076 if $sl->sl_flags & $SLF_MAPPED
6079 if $sl->sl_flags & $SLF_PARTIAL
6082 if $sl->sl_flags & $SLF_DETACHED
6089 if $sl->sl_chunks > 1
6091 set $c = $sl->sl_len / $sl->sl_chunks
6093 while $z < $sl->sl_chunks
6094 set $obj = $sl->sl_base + ($c * $z)
6098 set $ix = ((char *)$obj - (char *)mbutl) >> 12
6099 set $clbase = ((union mbigcluster *)mbutl) + $ix
6100 set $mclidx = (((char *)$obj - (char *)$clbase) >> 8)
6101 set $mca = mclaudit[$ix].cl_audit[$mclidx]
6105 printf " 0x%-16llx 0x%-16llx\n", $obj, $mca
6107 printf " 0x%-8x 0x%-8x\n", $obj, $mca
6118 | Display all mbuf slabs in the group
6124 printf "class total cached uncached inuse failed waiter notified purge\n"
6125 printf "name objs objs objs / slabs objs alloc count count count count\n"
6126 printf "---------------- -------- -------- ------------------- -------- ---------------- -------- -------- --------\n"
6127 while $x < (sizeof(mbuf_table) / sizeof(mbuf_table[0]))
6128 set $mbt = mbuf_table[$x]
6129 set $mcs = (mb_class_stat_t *)mbuf_table[$x].mtbl_stats
6131 set $mc = $mbt->mtbl_cache
6132 set $bktsize = $mc->mc_cpu.cc_bktsize
6133 set $tot += $mc->mc_full.bl_total * $bktsize
6134 set $ccp = (mcache_cpu_t *)$mc->mc_cpu
6137 if $ccp->cc_objs > 0
6138 set $tot += $ccp->cc_objs
6140 if $ccp->cc_pobjs > 0
6141 set $tot += $ccp->cc_pobjs
6147 printf "%-16s %8d %8d %8d / %-8d %8d %16llu %8d %8llu %8llu", \
6148 $mcs->mbcl_cname, $mcs->mbcl_total, $tot, \
6149 $mcs->mbcl_infree, $mcs->mbcl_slab_cnt, \
6150 ($mcs->mbcl_total - $tot - $mcs->mbcl_infree), \
6151 $mcs->mbcl_fail_cnt, $mc->mc_waiter_cnt, \
6152 $mcs->mbcl_notified, $mcs->mbcl_purge_cnt
6159 | Print extended mbuf allocator statistics.
6163 set $MB_COMP_INUSE = 0x2
6164 set $MB_SCVALID = 0x4
6166 set $MCLBYTES = 2048
6169 set $M16KCLBYTES = 16384
6171 define mbuf_mca_ctype
6172 set $mca = (mcache_audit_t *)$arg0
6174 set $cp = $mca->mca_cache
6175 set $class = (unsigned int)$cp->mc_private
6176 set $csize = mbuf_table[$class].mtbl_stats->mbcl_size
6186 if !$done && $csize == $MCLBYTES
6188 printf "CL (2K cluster) "
6194 if !$done && $csize == $NBPG
6196 printf "BCL (4K cluster) "
6202 if !$done && $csize == $M16KCLBYTES
6204 printf "JCL (16K cluster) "
6210 if !$done && $csize == ($MSIZE+$MCLBYTES)
6211 if $mca->mca_uflags & $MB_SCVALID
6215 printf "(paired mbuf, 2K cluster)"
6220 printf "(unpaired mbuf, 2K cluster) "
6227 printf "(paired 2K cluster, mbuf) "
6232 printf "(paired 2K cluster, mbuf) "
6238 if !$done && $csize == ($MSIZE+$NBPG)
6239 if $mca->mca_uflags & $MB_SCVALID
6243 printf "(paired mbuf, 4K cluster) "
6248 printf "(unpaired mbuf, 4K cluster) "
6255 printf "(paired 4K cluster, mbuf) "
6260 printf "(unpaired 4K cluster, mbuf) "
6266 if !$done && $csize == ($MSIZE+$M16KCLBYTES)
6267 if $mca->mca_uflags & $MB_SCVALID
6271 printf "(paired mbuf, 16K cluster) "
6276 printf "(unpaired mbuf, 16K cluster) "
6283 printf "(paired 16K cluster, mbuf) "
6288 printf "(unpaired 16K cluster, mbuf) "
6295 printf "unknown: %s ", $cp->mc_name
6299 document mbuf_mca_ctype
6300 | This is a helper macro for mbuf_show{active,inactive,all} that prints
6301 | out the mbuf object type represented by a given mcache audit structure.
6304 define mbuf_showactive
6306 mbuf_walkallslabs 1 0
6308 mbuf_walkallslabs 1 0 $arg0
6312 document mbuf_showactive
6313 Syntax: (gdb) mbuf_showactive
6314 | Walk the mbuf objects pool and print only the active ones; this
6315 | requires mbuf debugging to be turned on, by setting the appropriate flags
6316 | to the "mbuf_debug" boot-args parameter. Active objects are those that
6317 | are outstanding (have not returned to the mbuf slab layer) and in use
6318 | by the client (have not been freed).
6321 define mbuf_showinactive
6322 mbuf_walkallslabs 0 1
6325 document mbuf_showinactive
6326 Syntax: (gdb) mbuf_showinactive
6327 | Walk the mbuf objects pool and print only the inactive ones; this
6328 | requires mbuf debugging to be turned on, by setting the appropriate flags
6329 | to the "mbuf_debug" boot-args parameter. Inactive objects are those that
6330 | are outstanding (have not returned to the mbuf slab layer) but have been
6331 | freed by the client, i.e. they still reside in the mcache layer ready to
6332 | be used for subsequent allocation requests.
6336 mbuf_walkallslabs 1 1
6339 document mbuf_showall
6340 Syntax: (gdb) mbuf_showall
6341 | Walk the mbuf objects pool and print them all; this requires
6342 | mbuf debugging to be turned on, by setting the appropriate flags to the
6343 | "mbuf_debug" boot-args parameter.
6349 define mbuf_walkallslabs
6353 set $show_tr = $arg2
6363 if $show_a && !$show_f
6364 printf "Searching only for active "
6366 if !$show_a && $show_f
6367 printf "Searching only for inactive "
6369 if $show_a && $show_f
6370 printf "Displaying all "
6372 printf "objects; this may take a while ...)\n\n"
6375 printf " slab mca obj allocation\n"
6376 printf "slot idx address address address type state\n"
6377 printf "---- ---- ------------------ ------------------ ------------------ ----- -----------\n"
6379 printf " slab mca obj allocation\n"
6380 printf "slot idx address address address type state\n"
6381 printf "---- ---- ---------- ---------- ---------- ----- -----------\n"
6385 set $slg = slabstbl[$x]
6388 while $y < $NSLABSPMB && $stop == 0
6389 set $sl = &$slg->slg_slab[$y]
6390 set $base = (char *)$sl->sl_base
6391 set $ix = ($base - (char *)mbutl) >> 12
6392 set $clbase = ((union mbigcluster *)mbutl) + $ix
6393 set $mclidx = ($base - (char *)$clbase) >> 8
6394 set $mca = mclaudit[$ix].cl_audit[$mclidx]
6397 while $mca != 0 && $mca->mca_addr != 0
6399 if $mca->mca_uflags & ($MB_INUSE|$MB_COMP_INUSE)
6400 set $total_a = $total_a + 1
6401 set $printmca = $show_a
6403 set $total_f = $total_f + 1
6404 set $printmca = $show_f
6410 printf "%4d %4d 0x%-16llx ", $x, $y, $sl
6412 printf "%4d %4d 0x%-8x ", $x, $y, $sl
6423 printf "0x%-16llx 0x%-16llx ", $mca, $mca->mca_addr
6425 printf "0x%-8x 0x%-8x ", $mca, $mca->mca_addr
6428 mbuf_mca_ctype $mca 0
6429 if $mca->mca_uflags & ($MB_INUSE|$MB_COMP_INUSE)
6438 set $total = $total + 1
6441 printf "recent transaction for this buffer (thread %p):\n", \
6444 while $cnt < $mca->mca_depth
6445 set $kgm_pc = $mca->mca_stack[$cnt]
6446 printf "%4d: ", $cnt + 1
6454 set $mca = $mca->mca_next
6457 if $slg->slg_slab[$y].sl_base == 0
6463 if $total && $show_a && $show_f
6464 printf "\ntotal objects:\t%d\n", $total
6465 printf "active/unfreed:\t%d\n", $total_a
6466 printf "freed/in_cache:\t%d\n", $total_f
6470 document mbuf_walkallslabs
6471 | Walk the mbuf objects pool; this requires mbuf debugging to be
6472 | turned on, by setting the appropriate flags to the "mbuf_debug" boot-args
6473 | parameter. This is a backend routine for mbuf_show{active,inactive,all}.
6476 define mbuf_countchain
6477 set $mp = (struct mbuf *)$arg0
6485 set $mn = (struct mbuf *)$mp->m_hdr.mh_next
6489 set $mn = (struct mbuf *)$mn->m_hdr.mh_next
6492 set $mp = $mp->m_hdr.mh_nextpkt
6494 if (($pkt + $nxt) % 50) == 0
6495 printf "... %d\n", $pkt + $nxt
6499 printf "\ntotal: %d (via m_next: %d)\n", $pkt + $nxt, $nxt
6502 document mbuf_countchain
6503 Syntax: mbuf_countchain <addr>
6504 | Count the total number of mbufs chained from the given the address of an mbuf.
6505 | The routine follows both the m_next pointers and m_nextpkt pointers.
6509 set $RTF_GATEWAY = 0x2
6511 set $RTF_REJECT = 0x8
6512 set $RTF_DYNAMIC = 0x10
6513 set $RTF_MODIFIED = 0x20
6514 set $RTF_DONE = 0x40
6515 set $RTF_DELCLONE = 0x80
6516 set $RTF_CLONING = 0x100
6517 set $RTF_XRESOLVE = 0x200
6518 set $RTF_LLINFO = 0x400
6519 set $RTF_STATIC = 0x800
6520 set $RTF_BLACKHOLE = 0x1000
6521 set $RTF_PROTO2 = 0x4000
6522 set $RTF_PROTO1 = 0x8000
6523 set $RTF_PRCLONING = 0x10000
6524 set $RTF_WASCLONED = 0x20000
6525 set $RTF_PROTO3 = 0x40000
6526 set $RTF_PINNED = 0x100000
6527 set $RTF_LOCAL = 0x200000
6528 set $RTF_BROADCAST = 0x400000
6529 set $RTF_MULTICAST = 0x800000
6530 set $RTF_IFSCOPE = 0x1000000
6531 set $RTF_CONDEMNED = 0x2000000
6532 set $RTF_IFREF = 0x4000000
6533 set $RTF_PROXY = 0x8000000
6534 set $RTF_ROUTER = 0x10000000
6540 define rtentry_prdetails
6541 set $rt = (struct rtentry *)$arg0
6544 set $dst = (struct sockaddr *)$rt->rt_nodes->rn_u.rn_leaf.rn_Key
6545 if $dst->sa_family == $AF_INET
6546 showsockaddr_in $dst
6549 if $dst->sa_family == $AF_INET6
6550 showsockaddr_in6 $dst
6554 if $dst->sa_family == $AF_LINK
6555 showsockaddr_dl $dst
6558 showsockaddr_unspec $dst
6563 set $dst = (struct sockaddr *)$rt->rt_gateway
6564 if $dst->sa_family == $AF_INET
6565 showsockaddr_in $dst
6568 if $dst->sa_family == $AF_INET6
6570 showsockaddr_in6 $dst
6573 if $dst->sa_family == $AF_LINK
6574 showsockaddr_dl $dst
6581 showsockaddr_unspec $dst
6586 if $rt->rt_flags & $RTF_WASCLONED
6588 printf "%18p ", $rt->rt_parent
6590 printf "%10p ", $rt->rt_parent
6600 printf "%6u %8u ", $rt->rt_refcnt, $rt->rt_rmx.rmx_pksent
6602 if $rt->rt_flags & $RTF_UP
6605 if $rt->rt_flags & $RTF_GATEWAY
6608 if $rt->rt_flags & $RTF_HOST
6611 if $rt->rt_flags & $RTF_REJECT
6614 if $rt->rt_flags & $RTF_DYNAMIC
6617 if $rt->rt_flags & $RTF_MODIFIED
6620 if $rt->rt_flags & $RTF_CLONING
6623 if $rt->rt_flags & $RTF_PRCLONING
6626 if $rt->rt_flags & $RTF_LLINFO
6629 if $rt->rt_flags & $RTF_STATIC
6632 if $rt->rt_flags & $RTF_PROTO1
6635 if $rt->rt_flags & $RTF_PROTO2
6638 if $rt->rt_flags & $RTF_PROTO3
6641 if $rt->rt_flags & $RTF_WASCLONED
6644 if $rt->rt_flags & $RTF_BROADCAST
6647 if $rt->rt_flags & $RTF_MULTICAST
6650 if $rt->rt_flags & $RTF_XRESOLVE
6653 if $rt->rt_flags & $RTF_BLACKHOLE
6656 if $rt->rt_flags & $RTF_IFSCOPE
6659 if $rt->rt_flags & $RTF_CONDEMNED
6662 if $rt->rt_flags & $RTF_IFREF
6665 if $rt->rt_flags & $RTF_PROXY
6668 if $rt->rt_flags & $RTF_ROUTER
6672 printf "/%s%d", $rt->rt_ifp->if_name, $rt->rt_ifp->if_unit
6677 define _rttable_dump
6679 set $rn = (struct radix_node *)$rnh->rnh_treetop
6680 set $rnh_cnt = $rnh->rnh_cnt
6682 while $rn->rn_bit >= 0
6683 set $rn = $rn->rn_u.rn_node.rn_L
6687 set $base = (struct radix_node *)$rn
6688 while ($rn->rn_parent->rn_u.rn_node.rn_R == $rn) && ($rn->rn_flags & $RNF_ROOT) == 0
6689 set $rn = $rn->rn_parent
6691 set $rn = $rn->rn_parent->rn_u.rn_node.rn_R
6692 while $rn->rn_bit >= 0
6693 set $rn = $rn->rn_u.rn_node.rn_L
6698 set $base = $rn->rn_u.rn_leaf.rn_Dupedkey
6699 if ($rn->rn_flags & $RNF_ROOT) == 0
6701 set $rt = (struct rtentry *)$rn
6708 rtentry_prdetails $rt
6714 if ($rn->rn_flags & $RNF_ROOT) != 0
6723 printf " rtentry dst gw parent Refs Use flags/if\n"
6724 printf " ----------------- --------------- ----------------- ------------------ ------ -------- -----------\n"
6726 printf " rtentry dst gw parent Refs Use flags/if\n"
6727 printf " --------- --------------- ----------------- ---------- ------ -------- -----------\n"
6729 _rttable_dump rt_tables[2]
6732 document show_rt_inet
6733 Syntax: (gdb) show_rt_inet
6734 | Show the entries of the IPv4 routing table.
6737 define show_rt_inet6
6739 printf " rtentry dst gw parent Refs Use flags/if\n"
6740 printf " ----------------- --------------------------------------- --------------------------------------- ------------------ ------ -------- -----------\n"
6742 printf " rtentry dst gw parent Refs Use flags/if\n"
6743 printf " --------- --------------------------------------- --------------------------------------- ---------- ------ -------- -----------\n"
6745 _rttable_dump rt_tables[30]
6748 document show_rt_inet6
6749 Syntax: (gdb) show_rt_inet6
6750 | Show the entries of the IPv6 routing table.
6753 define rtentry_trash
6754 set $rtd = (struct rtentry_dbg *)rttrash_head.tqh_first
6759 printf " rtentry ref hold rele dst gw parent flags/if\n"
6760 printf " ----------------- --- ------ ------ --------------- ----- ------------------ -----------\n"
6762 printf " rtentry ref hold rele dst gw parent flags/if\n"
6763 printf " --------- --- ------ ------ --------------- ----- ---------- -----------\n"
6766 printf "%4d: %p %3d %6d %6d ", $cnt + 1, $rtd, \
6767 $rtd->rtd_refhold_cnt - $rtd->rtd_refrele_cnt, \
6768 $rtd->rtd_refhold_cnt, $rtd->rtd_refrele_cnt
6769 rtentry_prdetails $rtd
6771 set $rtd = $rtd->rtd_trash_link.tqe_next
6776 document rtentry_trash
6777 Syntax: (gdb) rtentry_trash
6778 | Walk the list of trash route entries; this requires route entry
6779 | debugging to be turned on, by setting the appropriate flags to the
6780 | "rte_debug" boot-args parameter.
6783 set $CTRACE_STACK_SIZE = ctrace_stack_size
6784 set $CTRACE_HIST_SIZE = ctrace_hist_size
6786 define rtentry_showdbg
6787 set $rtd = (struct rtentry_dbg *)$arg0
6790 printf "Total holds:\t%d\n", $rtd->rtd_refhold_cnt
6791 printf "Total releases:\t%d\n", $rtd->rtd_refrele_cnt
6794 while $ix < $CTRACE_STACK_SIZE
6795 set $kgm_pc = $rtd->rtd_alloc.pc[$ix]
6798 printf "\nAlloc (thread %p):\n", \
6801 printf "%4d: ", $ix + 1
6808 while $ix < $CTRACE_STACK_SIZE
6809 set $kgm_pc = $rtd->rtd_free.pc[$ix]
6812 printf "\nFree: (thread %p)\n", \
6815 printf "%4d: ", $ix + 1
6821 while $cnt < $CTRACE_HIST_SIZE
6823 while $ix < $CTRACE_STACK_SIZE
6824 set $kgm_pc = $rtd->rtd_refhold[$cnt].pc[$ix]
6827 printf "\nHold [%d] (thread %p):\n", \
6828 $cnt, $rtd->rtd_refhold[$cnt].th
6830 printf "%4d: ", $ix + 1
6839 while $cnt < $CTRACE_HIST_SIZE
6841 while $ix < $CTRACE_STACK_SIZE
6842 set $kgm_pc = $rtd->rtd_refrele[$cnt].pc[$ix]
6845 printf "\nRelease [%d] (thread %p):\n",\
6846 $cnt, $rtd->rtd_refrele[$cnt].th
6848 printf "%4d: ", $ix + 1
6857 printf "\nTotal locks:\t%d\n", $rtd->rtd_lock_cnt
6858 printf "Total unlocks:\t%d\n", $rtd->rtd_unlock_cnt
6861 while $cnt < $CTRACE_HIST_SIZE
6863 while $ix < $CTRACE_STACK_SIZE
6864 set $kgm_pc = $rtd->rtd_lock[$cnt].pc[$ix]
6867 printf "\nLock [%d] (thread %p):\n",\
6868 $cnt, $rtd->rtd_lock[$cnt].th
6870 printf "%4d: ", $ix + 1
6879 while $cnt < $CTRACE_HIST_SIZE
6881 while $ix < $CTRACE_STACK_SIZE
6882 set $kgm_pc = $rtd->rtd_unlock[$cnt].pc[$ix]
6885 printf "\nUnlock [%d] (thread %p):\n",\
6886 $cnt, $rtd->rtd_unlock[$cnt].th
6888 printf "%4d: ", $ix + 1
6898 document rtentry_showdbg
6899 Syntax: (gdb) rtentry_showdbg <addr>
6900 | Given a route entry structure address, print the debug information
6901 | related to it. This requires route entry debugging to be turned
6902 | on, by setting the appropriate flags to the "rte_debug" boot-args
6906 set $INIFA_TRACE_HIST_SIZE = inifa_trace_hist_size
6908 define inifa_showdbg
6909 set $inifa = (struct in_ifaddr_dbg *)$arg0
6912 printf "Total holds:\t%d\n", $inifa->inifa_refhold_cnt
6913 printf "Total releases:\t%d\n", $inifa->inifa_refrele_cnt
6916 while $ix < $CTRACE_STACK_SIZE
6917 set $kgm_pc = $inifa->inifa_alloc.pc[$ix]
6920 printf "\nAlloc (thread %p):\n", \
6921 $inifa->inifa_alloc.th
6923 printf "%4d: ", $ix + 1
6930 while $ix < $CTRACE_STACK_SIZE
6931 set $kgm_pc = $inifa->inifa_free.pc[$ix]
6934 printf "\nFree: (thread %p)\n", \
6935 $inifa->inifa_free.th
6937 printf "%4d: ", $ix + 1
6943 while $cnt < $INIFA_TRACE_HIST_SIZE
6945 while $ix < $CTRACE_STACK_SIZE
6946 set $kgm_pc = $inifa->inifa_refhold[$cnt].pc[$ix]
6949 printf "\nHold [%d] (thread %p):\n", \
6950 $cnt, $inifa->inifa_refhold[$cnt].th
6952 printf "%4d: ", $ix + 1
6961 while $cnt < $INIFA_TRACE_HIST_SIZE
6963 while $ix < $CTRACE_STACK_SIZE
6964 set $kgm_pc = $inifa->inifa_refrele[$cnt].pc[$ix]
6967 printf "\nRelease [%d] (thread %p):\n",\
6968 $cnt, $inifa->inifa_refrele[$cnt].th
6970 printf "%4d: ", $ix + 1
6980 document inifa_showdbg
6981 Syntax: (gdb) inifa_showdbg <addr>
6982 | Given an IPv4 interface structure address, print the debug information
6983 | related to it. This requires interface address debugging to be turned
6984 | on, by setting the appropriate flags to the "ifa_debug" boot-args
6988 set $IN6IFA_TRACE_HIST_SIZE = in6ifa_trace_hist_size
6990 define in6ifa_showdbg
6991 set $in6ifa = (struct in6_ifaddr_dbg *)$arg0
6994 printf "Total holds:\t%d\n", $in6ifa->in6ifa_refhold_cnt
6995 printf "Total releases:\t%d\n", $in6ifa->in6ifa_refrele_cnt
6998 while $ix < $CTRACE_STACK_SIZE
6999 set $kgm_pc = $in6ifa->in6ifa_alloc.pc[$ix]
7002 printf "\nAlloc (thread %p):\n", \
7003 $in6ifa->in6ifa_alloc.th
7005 printf "%4d: ", $ix + 1
7012 while $ix < $CTRACE_STACK_SIZE
7013 set $kgm_pc = $in6ifa->in6ifa_free.pc[$ix]
7016 printf "\nFree: (thread %p)\n", \
7017 $in6ifa->in6ifa_free.th
7019 printf "%4d: ", $ix + 1
7025 while $cnt < $IN6IFA_TRACE_HIST_SIZE
7027 while $ix < $CTRACE_STACK_SIZE
7028 set $kgm_pc = $in6ifa->in6ifa_refhold[$cnt].pc[$ix]
7031 printf "\nHold [%d] (thread %p):\n", \
7032 $cnt, $in6ifa->in6ifa_refhold[$cnt].th
7034 printf "%4d: ", $ix + 1
7043 while $cnt < $IN6IFA_TRACE_HIST_SIZE
7045 while $ix < $CTRACE_STACK_SIZE
7046 set $kgm_pc = $in6ifa->in6ifa_refrele[$cnt].pc[$ix]
7049 printf "\nRelease [%d] (thread %p):\n",\
7050 $cnt, $in6ifa->in6ifa_refrele[$cnt].th
7052 printf "%4d: ", $ix + 1
7062 document in6ifa_showdbg
7063 Syntax: (gdb) in6ifa_showdbg <addr>
7064 | Given an IPv6 interface structure address, print the debug information
7065 | related to it. This requires interface address debugging to be turned
7066 | on, by setting the appropriate flags to the "ifa_debug" boot-args
7070 set $IFMA_TRACE_HIST_SIZE = ifma_trace_hist_size
7073 set $ifma = (struct ifmultiaddr_dbg *)$arg0
7076 printf "Total holds:\t%d\n", $ifma->ifma_refhold_cnt
7077 printf "Total releases:\t%d\n", $ifma->ifma_refrele_cnt
7079 while $cnt < $IFMA_TRACE_HIST_SIZE
7081 while $ix < $CTRACE_STACK_SIZE
7082 set $kgm_pc = $ifma->ifma_refhold[$cnt].pc[$ix]
7085 printf "\nHold [%d] (thread %p):\n", \
7086 $cnt, $ifma->ifma_refhold[$cnt].th
7088 printf "%4d: ", $ix + 1
7097 while $cnt < $IFMA_TRACE_HIST_SIZE
7099 while $ix < $CTRACE_STACK_SIZE
7100 set $kgm_pc = $ifma->ifma_refrele[$cnt].pc[$ix]
7103 printf "\nRelease [%d] (thread %p):\n",\
7104 $cnt, $ifma->ifma_refrele[$cnt].th
7106 printf "%4d: ", $ix + 1
7116 document ifma_showdbg
7117 Syntax: (gdb) ifma_showdbg <addr>
7118 | Given a link multicast structure address, print the debug information
7119 | related to it. This requires interface address debugging to be turned
7120 | on, by setting the appropriate flags to the "ifa_debug" boot-args
7124 set $INM_TRACE_HIST_SIZE = inm_trace_hist_size
7127 set $inm = (struct in_multi_dbg *)$arg0
7130 printf "Total holds:\t%d\n", $inm->inm_refhold_cnt
7131 printf "Total releases:\t%d\n", $inm->inm_refrele_cnt
7133 while $cnt < $INM_TRACE_HIST_SIZE
7135 while $ix < $CTRACE_STACK_SIZE
7136 set $kgm_pc = $inm->inm_refhold[$cnt].pc[$ix]
7139 printf "\nHold [%d] (thread %p):\n", \
7140 $cnt, $inm->inm_refhold[$cnt].th
7142 printf "%4d: ", $ix + 1
7151 while $cnt < $INM_TRACE_HIST_SIZE
7153 while $ix < $CTRACE_STACK_SIZE
7154 set $kgm_pc = $inm->inm_refrele[$cnt].pc[$ix]
7157 printf "\nRelease [%d] (thread %p):\n",\
7158 $cnt, $inm->inm_refrele[$cnt].th
7160 printf "%4d: ", $ix + 1
7170 document inm_showdbg
7171 Syntax: (gdb) inm_showdbg <addr>
7172 | Given an IPv4 multicast structure address, print the debug information
7173 | related to it. This requires interface address debugging to be turned
7174 | on, by setting the appropriate flags to the "ifa_debug" boot-args
7178 set $IF_REF_TRACE_HIST_SIZE = if_ref_trace_hist_size
7180 define ifpref_showdbg
7181 set $dl_if = (struct dlil_ifnet_dbg *)$arg0
7184 printf "Total references:\t%d\n", $dl_if->dldbg_if_refhold_cnt
7185 printf "Total releases:\t\t%d\n", $dl_if->dldbg_if_refrele_cnt
7187 while $cnt < $IF_REF_TRACE_HIST_SIZE
7189 while $ix < $CTRACE_STACK_SIZE
7190 set $kgm_pc = $dl_if->dldbg_if_refhold[$cnt].pc[$ix]
7193 printf "\nHold [%d] (thread %p):\n", \
7195 $dl_if->dldbg_if_refhold[$cnt].th
7197 printf "%4d: ", $ix + 1
7206 while $cnt < $IF_REF_TRACE_HIST_SIZE
7208 while $ix < $CTRACE_STACK_SIZE
7209 set $kgm_pc = $dl_if->dldbg_if_refrele[$cnt].pc[$ix]
7212 printf "\nRelease [%d] (thread %p):\n",\
7214 $dl_if->dldbg_if_refrele[$cnt].th
7216 printf "%4d: ", $ix + 1
7226 document ifpref_showdbg
7227 Syntax: (gdb) ifpref_showdbg <addr>
7228 | Given an ifnet structure address, print the debug information
7229 | related to its refcnt. This requires ifnet debugging to be turned
7230 | on, by setting the appropriate flags to the "ifnet_debug" boot-args
7235 set $ifa = (struct in6_ifaddr_dbg *)in6ifa_trash_head.tqh_first
7240 printf " in6_ifa ref hold rele\n"
7241 printf " ----------------- --- ------ ------\n"
7243 printf " in6_ifa ref hold rele\n"
7244 printf " --------- --- ------ ------\n"
7247 printf "%4d: %p %3d %6d %6d ", $cnt + 1, $ifa, \
7248 $ifa->in6ifa_refhold_cnt - $ifa->in6ifa_refrele_cnt, \
7249 $ifa->in6ifa_refhold_cnt, $ifa->in6ifa_refrele_cnt
7250 showsockaddr_in6 $ifa->in6ifa.ia_ifa.ifa_addr
7252 set $ifa = $ifa->in6ifa_trash_link.tqe_next
7257 set $NDPR_TRACE_HIST_SIZE = ndpr_trace_hist_size
7260 set $ndpr = (struct nd_prefix_dbg *)$arg0
7263 printf "Total references:\t%d\n", $ndpr->ndpr_refhold_cnt
7264 printf "Total releases:\t\t%d\n", $ndpr->ndpr_refrele_cnt
7266 while $cnt < $NDPR_TRACE_HIST_SIZE
7268 while $ix < $CTRACE_STACK_SIZE
7269 set $kgm_pc = $ndpr->ndpr_refhold[$cnt].pc[$ix]
7272 printf "\nHold [%d] (thread %p):\n", \
7274 $ndpr->ndpr_refhold[$cnt].th
7276 printf "%4d: ", $ix + 1
7285 while $cnt < $NDPR_TRACE_HIST_SIZE
7287 while $ix < $CTRACE_STACK_SIZE
7288 set $kgm_pc = $ndpr->ndpr_refrele[$cnt].pc[$ix]
7291 printf "\nRelease [%d] (thread %p):\n",\
7293 $ndpr->ndpr_refrele[$cnt].th
7295 printf "%4d: ", $ix + 1
7305 document ndpr_showdbg
7306 Syntax: (gdb) ndpr_showdbg <addr>
7307 | Given a nd_prefix structure address, print the debug information
7308 | related to its refcnt. This requires the interface address debugging
7309 | to be turned on, by setting the appropriate flags to the "ifa_debug"
7310 | boot-args parameter.
7313 set $NDDR_TRACE_HIST_SIZE = nddr_trace_hist_size
7316 set $nddr = (struct nd_defrouter_dbg *)$arg0
7319 printf "Total references:\t%d\n", $nddr->nddr_refhold_cnt
7320 printf "Total releases:\t\t%d\n", $nddr->nddr_refrele_cnt
7322 while $cnt < $NDDR_TRACE_HIST_SIZE
7324 while $ix < $CTRACE_STACK_SIZE
7325 set $kgm_pc = $nddr->nddr_refhold[$cnt].pc[$ix]
7328 printf "\nHold [%d] (thread %p):\n", \
7330 $nddr->nddr_refhold[$cnt].th
7332 printf "%4d: ", $ix + 1
7341 while $cnt < $NDDR_TRACE_HIST_SIZE
7343 while $ix < $CTRACE_STACK_SIZE
7344 set $kgm_pc = $nddr->nddr_refrele[$cnt].pc[$ix]
7347 printf "\nRelease [%d] (thread %p):\n",\
7349 $nddr->nddr_refrele[$cnt].th
7351 printf "%4d: ", $ix + 1
7361 document nddr_showdbg
7362 Syntax: (gdb) nddr_showdbg <addr>
7363 | Given a nd_defrouter structure address, print the debug information
7364 | related to its refcnt. This requires the interface address debugging
7365 | to be turned on, by setting the appropriate flags to the "ifa_debug"
7366 | boot-args parameter.
7368 set $IMO_TRACE_HIST_SIZE = imo_trace_hist_size
7371 set $imo = (struct ip_moptions_dbg *)$arg0
7374 printf "Total references:\t%d\n", $imo->imo_refhold_cnt
7375 printf "Total releases:\t\t%d\n", $imo->imo_refrele_cnt
7377 while $cnt < $IMO_TRACE_HIST_SIZE
7379 while $ix < $CTRACE_STACK_SIZE
7380 set $kgm_pc = $imo->imo_refhold[$cnt].pc[$ix]
7383 printf "\nHold [%d] (thread %p):\n", \
7385 $imo->imo_refhold[$cnt].th
7387 printf "%4d: ", $ix + 1
7396 while $cnt < $IMO_TRACE_HIST_SIZE
7398 while $ix < $CTRACE_STACK_SIZE
7399 set $kgm_pc = $imo->imo_refrele[$cnt].pc[$ix]
7402 printf "\nRelease [%d] (thread %p):\n",\
7404 $imo->imo_refrele[$cnt].th
7406 printf "%4d: ", $ix + 1
7416 document imo_showdbg
7417 Syntax: (gdb) imo_showdbg <addr>
7418 | Given a ip_moptions structure address, print the debug information
7419 | related to its refcnt. This requires the interface address debugging
7420 | to be turned on, by setting the appropriate flags to the "ifa_debug"
7421 | boot-args parameter.
7424 set $IM6O_TRACE_HIST_SIZE = im6o_trace_hist_size
7427 set $im6o = (struct ip6_moptions_dbg *)$arg0
7430 printf "Total references:\t%d\n", $im6o->im6o_refhold_cnt
7431 printf "Total releases:\t\t%d\n", $im6o->im6o_refrele_cnt
7433 while $cnt < $IM6O_TRACE_HIST_SIZE
7435 while $ix < $CTRACE_STACK_SIZE
7436 set $kgm_pc = $im6o->im6o_refhold[$cnt].pc[$ix]
7439 printf "\nHold [%d] (thread %p):\n", \
7441 $im6o->im6o_refhold[$cnt].th
7443 printf "%4d: ", $ix + 1
7452 while $cnt < $IM6O_TRACE_HIST_SIZE
7454 while $ix < $CTRACE_STACK_SIZE
7455 set $kgm_pc = $im6o->im6o_refrele[$cnt].pc[$ix]
7458 printf "\nRelease [%d] (thread %p):\n",\
7460 $im6o->im6o_refrele[$cnt].th
7462 printf "%4d: ", $ix + 1
7472 document im6o_showdbg
7473 Syntax: (gdb) im6o_showdbg <addr>
7474 | Given a ip6_moptions structure address, print the debug information
7475 | related to its refcnt. This requires the interface address debugging
7476 | to be turned on, by setting the appropriate flags to the "ifa_debug"
7477 | boot-args parameter.
7480 document in6ifa_trash
7481 Syntax: (gdb) in6ifa_trash
7482 | Walk the list of trash in6_ifaddr entries; this requires interface
7483 | address debugging to be turned on, by setting the appropriate flags
7484 | to the "ifa_debug" boot-args parameter.
7488 set $ifa = (struct in_ifaddr_dbg *)inifa_trash_head.tqh_first
7493 printf " in_ifa ref hold rele\n"
7494 printf " ----------------- --- ------ ------\n"
7496 printf " in_ifa ref hold rele\n"
7497 printf " --------- --- ------ ------\n"
7500 printf "%4d: %p %3d %6d %6d ", $cnt + 1, $ifa, \
7501 $ifa->inifa_refhold_cnt - $ifa->inifa_refrele_cnt, \
7502 $ifa->inifa_refhold_cnt, $ifa->inifa_refrele_cnt
7503 showsockaddr_in $ifa->inifa.ia_ifa.ifa_addr
7505 set $ifa = $ifa->inifa_trash_link.tqe_next
7510 document inifa_trash
7511 Syntax: (gdb) inifa_trash
7512 | Walk the list of trash in_ifaddr entries; this requires interface
7513 | address debugging to be turned on, by setting the appropriate flags
7514 | to the "ifa_debug" boot-args parameter.
7518 set $ifma = (struct ifmultiaddr_dbg *)ifma_trash_head.tqh_first
7523 printf " ifma ref hold rele\n"
7524 printf " ----------------- --- ------ ------\n"
7526 printf " ifma ref hold rele\n"
7527 printf " --------- --- ------ ------\n"
7530 printf "%4d: %p %3d %6d %6d ", $cnt + 1, $ifma, \
7531 $ifma->ifma_refhold_cnt - $ifma->ifma_refrele_cnt, \
7532 $ifma->ifma_refhold_cnt, $ifma->ifma_refrele_cnt
7533 showsockaddr $ifma->ifma.ifma_addr
7534 printf " @ %s%d", $ifma->ifma.ifma_ifp->if_name, \
7535 $ifma->ifma.ifma_ifp->if_unit
7537 set $ifma = $ifma->ifma_trash_link.tqe_next
7543 Syntax: (gdb) ifma_trash
7544 | Walk the list of trash ifmultiaddr entries; this requires interface
7545 | address debugging to be turned on, by setting the appropriate flags
7546 | to the "ifa_debug" boot-args parameter.
7550 set $inm = (struct in_multi_dbg *)inm_trash_head.tqh_first
7555 printf " inm ref hold rele\n"
7556 printf " ----------------- --- ------ ------\n"
7558 printf " inm ref hold rele\n"
7559 printf " --------- --- ------ ------\n"
7562 printf "%4d: %p %3d %6d %6d ", $cnt + 1, $inm, \
7563 $inm->inm_refhold_cnt - $inm->inm_refrele_cnt, \
7564 $inm->inm_refhold_cnt, $inm->inm_refrele_cnt
7565 show_in_addr &($inm->inm.inm_addr)
7567 set $inm = $inm->inm_trash_link.tqe_next
7573 Syntax: (gdb) inm_trash
7574 | Walk the list of trash in_multi entries; this requires interface
7575 | address debugging to be turned on, by setting the appropriate flags
7576 | to the "ifa_debug" boot-args parameter.
7580 set $in6m = (struct in6_multi_dbg *)in6m_trash_head.tqh_first
7585 printf " in6m ref hold rele\n"
7586 printf " ----------------- --- ------ ------\n"
7588 printf " in6m ref hold rele\n"
7589 printf " --------- --- ------ ------\n"
7592 printf "%4d: %p %3d %6d %6d ", $cnt + 1, $in6m, \
7593 $in6m->in6m_refhold_cnt - $in6m->in6m_refrele_cnt, \
7594 $in6m->in6m_refhold_cnt, $in6m->in6m_refrele_cnt
7595 show_in_addr &($in6m->in6m.in6m_addr)
7597 set $in6m = $in6m->in6m_trash_link.tqe_next
7603 Syntax: (gdb) in6m_trash
7604 | Walk the list of trash in6_multi entries; this requires interface
7605 | address debugging to be turned on, by setting the appropriate flags
7606 | to the "ifa_debug" boot-args parameter.
7610 # print all OSMalloc stats
7613 set $kgm_tagp = (OSMallocTag)$arg0
7614 printf "0x%08x: ", $kgm_tagp
7615 printf "%8d ",$kgm_tagp->OSMT_refcnt
7616 printf "%8x ",$kgm_tagp->OSMT_state
7617 printf "%8x ",$kgm_tagp->OSMT_attr
7618 printf "%s ",$kgm_tagp->OSMT_name
7624 printf "TAG COUNT STATE ATTR NAME\n"
7625 set $kgm_tagheadp = (struct _OSMallocTag_ *)&OSMalloc_tag_list
7626 set $kgm_tagptr = (struct _OSMallocTag_ * )($kgm_tagheadp->OSMT_link.next)
7627 while $kgm_tagptr != $kgm_tagheadp
7628 ostag_print $kgm_tagptr
7629 set $kgm_tagptr = (struct _OSMallocTag_ *)$kgm_tagptr->OSMT_link.next
7633 document showosmalloc
7634 Syntax: (gdb) showosmalloc
7635 | Print the outstanding allocation count by OSMallocTags.
7640 if msgbufp->msg_bufc[msgbufp->msg_bufx] == 0 \
7641 && msgbufp->msg_bufc[0] != 0
7642 # The buffer hasn't wrapped, so take the easy (and fast!) path
7643 printf "%s", msgbufp->msg_bufc
7645 set $kgm_msgbuf = *msgbufp
7646 set $kgm_syslog_bufsize = $kgm_msgbuf.msg_size
7647 set $kgm_syslog_bufend = $kgm_msgbuf.msg_bufx
7648 if $kgm_syslog_bufend >= $kgm_syslog_bufsize
7649 set $kgm_syslog_bufend = 0
7652 # print older messages from msg_bufx to end of buffer
7653 set $kgm_i = $kgm_syslog_bufend
7654 while $kgm_i < $kgm_syslog_bufsize
7655 set $kgm_syslog_char = $kgm_msgbuf.msg_bufc[$kgm_i]
7656 if $kgm_syslog_char == 0
7658 set $kgm_i = $kgm_syslog_bufsize
7660 printf "%c", $kgm_syslog_char
7662 set $kgm_i = $kgm_i + 1
7665 # print newer messages from start of buffer to msg_bufx
7667 while $kgm_i < $kgm_syslog_bufend
7668 set $kgm_syslog_char = $kgm_msgbuf.msg_bufc[$kgm_i]
7669 if $kgm_syslog_char != 0
7670 printf "%c", $kgm_syslog_char
7672 set $kgm_i = $kgm_i + 1
7679 | Display the kernel's printf ring buffer
7684 set $kgm_addr = (unsigned char *)$arg0
7685 set $kgm_len = $arg1
7691 printf "%02x ", *($kgm_addr+$kgm_i)
7697 set $kgm_temp = *($kgm_addr+$kgm_i)
7698 if $kgm_temp < 32 || $kgm_temp >= 127
7701 printf "%c", $kgm_temp
7711 | Show the contents of memory as a hex/ASCII dump
7712 | The following is the syntax:
7713 | (gdb) hexdump <address> <length>
7717 define printcolonhex
7722 while ($li < $count)
7724 printf "%02x", (u_char)$addr[$li]
7727 printf ":%02x", (u_char)$addr[$li]
7734 define showsockaddr_dl
7735 set $sdl = (struct sockaddr_dl *)$arg0
7739 if $sdl->sdl_nlen == 0 && $sdl->sdl_alen == 0 && $sdl->sdl_slen == 0
7740 printf "link#%3d ", $sdl->sdl_index
7742 set $addr = $sdl->sdl_data + $sdl->sdl_nlen
7743 set $count = $sdl->sdl_alen
7744 printcolonhex $addr $count
7749 define showsockaddr_unspec
7750 set $sockaddr = (struct sockaddr *)$arg0
7751 set $addr = $sockaddr->sa_data
7752 set $count = $sockaddr->sa_len - 2
7753 printcolonhex $addr $count
7756 define showsockaddr_at
7757 set $sockaddr = (struct sockaddr *)$arg0
7758 set $addr = $sockaddr->sa_data
7759 set $count = $sockaddr->sa_len - 2
7760 printcolonhex $addr $count
7764 set $ia = (unsigned char *)$arg0
7765 printf "%3u.%03u.%03u.%03u", $ia[0], $ia[1], $ia[2], $ia[3]
7768 define showsockaddr_in
7769 set $sin = (struct sockaddr_in *)$arg0
7770 set $sa_bytes = (unsigned char *)&($sin->sin_addr)
7771 show_in_addr $sa_bytes
7774 define show_in6_addr
7775 set $ia = (unsigned char *)$arg0
7776 printf "%2x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x", \
7777 $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]
7780 define showsockaddr_in6
7781 set $sin6 = (struct sockaddr_in6 *)$arg0
7782 set $sa_bytes = $sin6->sin6_addr.__u6_addr.__u6_addr8
7783 show_in6_addr $sa_bytes
7786 define showsockaddr_un
7787 set $sun = (struct sockaddr_un *)$arg0
7791 if $sun->sun_path[0] == 0
7794 printf "%s", $sun->sun_path
7799 define showifmultiaddrs
7800 set $ifp = (struct ifnet *)$arg0
7801 set $if_multi = (struct ifmultiaddr *)$ifp->if_multiaddrs->lh_first
7802 set $mymulti = $if_multi
7804 while ($mymulti != 0)
7805 printf "%2d. %p ", $myi, $mymulti
7806 set $sa_family = $mymulti->ifma_addr.sa_family
7807 if ($sa_family == 2)
7808 if ($mymulti->ifma_ll != 0)
7809 showsockaddr_dl $mymulti->ifma_ll->ifma_addr
7812 showsockaddr_in $mymulti->ifma_addr
7814 if ($sa_family == 30)
7815 if ($mymulti->ifma_ll != 0)
7816 showsockaddr_dl $mymulti->ifma_ll->ifma_addr
7819 showsockaddr_in6 $mymulti->ifma_addr
7821 if ($sa_family == 18)
7822 showsockaddr_dl $mymulti->ifma_addr
7824 if ($sa_family == 0)
7825 showsockaddr_unspec $mymulti->ifma_addr 6
7827 printf " [%d]", $mymulti->ifma_refcount
7829 set $mymulti = $mymulti->ifma_link.le_next
7834 document showifmultiaddrs
7835 Syntax showifmultiaddrs <ifp>
7836 | show the (struct ifnet).if_multiaddrs list of multicast addresses for the given ifp
7839 define showinmultiaddrs
7840 set $in_multi = (struct in_multi *)(in_multihead->lh_first)
7841 set $mymulti = $in_multi
7843 while ($mymulti != 0)
7844 set $ifp = (struct ifnet *)$mymulti->inm_ifp
7845 printf "%2d. %p ", $myi, $mymulti
7846 show_in_addr &($mymulti->inm_addr)
7847 printf " (ifp %p [%s%d] ifma %p) ", $ifp, $ifp->if_name, \
7848 $ifp->if_unit, $mymulti->inm_ifma
7850 set $mymulti = $mymulti->inm_link.le_next
7855 document showinmultiaddrs
7856 Syntax showinmultiaddrs
7857 | show the contents of IPv4 multicast address records
7860 define showin6multiaddrs
7861 set $in6_multi = (struct in6_multi *)(in6_multihead->lh_first)
7862 set $mymulti = $in6_multi
7864 while ($mymulti != 0)
7865 set $ifp = (struct ifnet *)$mymulti->in6m_ifp
7866 printf "%2d. %p ", $myi, $mymulti
7867 show_in6_addr &($mymulti->in6m_addr)
7868 printf " (ifp %p [%s%d] ifma %p) ", $ifp, $ifp->if_name, \
7869 $ifp->if_unit, $mymulti->in6m_ifma
7871 set $mymulti = $mymulti->in6m_entry.le_next
7876 document showin6multiaddrs
7877 Syntax showin6multiaddrs
7878 | show the contents of IPv6 multicast address records
7882 set $mysock = (struct sockaddr *)$arg0
7883 set $showsockaddr_handled = 0
7887 if ($mysock->sa_family == 0)
7889 showsockaddr_unspec $mysock
7890 set $showsockaddr_handled = 1
7892 if ($mysock->sa_family == 1)
7894 showsockaddr_un $mysock
7895 set $showsockaddr_handled = 1
7897 if ($mysock->sa_family == 2)
7899 showsockaddr_in $mysock
7900 set $showsockaddr_handled = 1
7902 if ($mysock->sa_family == 30)
7904 showsockaddr_in6 $mysock
7905 set $showsockaddr_handled = 1
7907 if ($mysock->sa_family == 18)
7909 showsockaddr_dl $mysock
7910 set $showsockaddr_handled = 1
7912 if ($mysock->sa_family == 16)
7914 showsockaddr_at $mysock
7915 set $showsockaddr_handled = 1
7917 if ($showsockaddr_handled == 0)
7918 printf "FAM %d ", $mysock->sa_family
7919 set $addr = $mysock->sa_data
7920 set $count = $mysock->sa_len
7921 printcolonhex $addr $count
7927 set $flags = (u_short)$arg0
7959 printf "POINTTOPOINT"
7961 ## if ($flags & 0x20)
7967 # printf "NOTRAILERS"
8017 if ($flags & 0x1000)
8025 if ($flags & 0x2000)
8033 if ($flags & 0x4000)
8039 printf "LINK2-ALTPHYS"
8041 if ($flags & 0x8000)
8053 set $ifp = (struct ifnet *)$arg0
8054 set $myifaddr = (struct ifaddr *)$ifp->if_addrhead->tqh_first
8056 while ($myifaddr != 0)
8057 printf "\t%d. %p ", $myi, $myifaddr
8058 showsockaddr $myifaddr->ifa_addr
8059 printf " [%d]\n", $myifaddr->ifa_refcnt
8060 set $myifaddr = $myifaddr->ifa_link->tqe_next
8065 document showifaddrs
8066 Syntax: showifaddrs <ifp>
8067 | show the (struct ifnet).if_addrhead list of addresses for the given ifp
8071 set $ifconfig_all = 0
8073 set $ifconfig_all = 1
8075 set $ifp = (struct ifnet *)(ifnet_head->tqh_first)
8077 printf "%s%d: flags=%hx", $ifp->if_name, $ifp->if_unit, (u_short)$ifp->if_flags
8078 showifflags $ifp->if_flags
8079 printf " index %d", $ifp->if_index
8080 printf " mtu %d\n", $ifp->if_data.ifi_mtu
8081 printf "\t(struct ifnet *)"
8084 if ($ifconfig_all == 1)
8087 set $ifp = $ifp->if_link->tqe_next
8091 Syntax: (gdb) ifconfig
8092 | display ifconfig-like output, and print the (struct ifnet *) pointers for further inspection
8095 set $DLIF_INUSE = 0x1
8096 set $DLIF_REUSE = 0x2
8103 set $dlifp = (struct dlil_ifnet *)(dlil_ifnet_head->tqh_first)
8105 set $ifp = (struct ifnet *)$dlifp
8106 if ($dlifp->dl_if_flags & $DLIF_REUSE)
8109 if ($dlifp->dl_if_flags & $DLIF_INUSE)
8110 printf "%s%d: ", $ifp->if_name, $ifp->if_unit
8112 printf "[%s%d]: ", $ifp->if_name, $ifp->if_unit
8114 printf "flags=%hx", (u_short)$ifp->if_flags
8115 showifflags $ifp->if_flags
8116 printf " index %d", $ifp->if_index
8117 printf " mtu %d\n", $ifp->if_data.ifi_mtu
8118 printf "\t(struct ifnet *)"
8124 set $dlifp = $dlifp->dl_if_link->tqe_next
8129 Syntax: (gdb) showifnets
8130 | Display ifconfig-like output for all attached and detached interfaces
8133 define _show_unix_domain_socket
8134 set $so = (struct socket *)$arg0
8135 set $pcb = (struct unpcb *)$so->so_pcb
8137 printf "unpcb: (null) "
8139 printf "unpcb: %p ", $pcb
8140 printf "unp_vnode: %p ", $pcb->unp_vnode
8141 printf "unp_conn: %p ", $pcb->unp_conn
8143 showsockaddr_un $pcb->unp_addr
8147 define _show_in_port
8148 set $str = (unsigned char *)$arg0
8149 set $port = *(unsigned short *)$arg0
8151 if (((($port & 0xff00) >> 8) == $str[0])) && ((($port & 0x00ff) == $str[1]))
8152 #printf "big endian "
8153 printf ":%d ", $port
8155 #printf "little endian "
8156 printf ":%d ", (($port & 0xff00) >> 8) | (($port & 0x00ff) << 8)
8160 define _show_in_addr_4in6
8161 set $ia = (unsigned char *)$arg0
8163 printf "%3u.%03u.%03u.%03u", $ia[0], $ia[1], $ia[2], $ia[3]
8167 define _show_in6_addr
8168 set $ia = (unsigned char *)$arg0
8170 printf "%2x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x", \
8171 $ia[0], $ia[1], $ia[2], $ia[3], $ia[4], $ia[5], $ia[6], $ia[7], \
8172 $ia[8], $ia[9], $ia[10], $ia[11], $ia[12], $ia[13], $ia[14], $ia[15]
8176 define _showtcpstate
8177 set $tp = (struct tcpcb *)$arg0
8179 if $tp->t_state == 0
8182 if $tp->t_state == 1
8185 if $tp->t_state == 2
8188 if $tp->t_state == 3
8191 if $tp->t_state == 4
8192 printf "ESTABLISHED "
8194 if $tp->t_state == 5
8195 printf "CLOSE_WAIT "
8197 if $tp->t_state == 6
8198 printf "FIN_WAIT_1 "
8200 if $tp->t_state == 7
8203 if $tp->t_state == 8
8206 if $tp->t_state == 9
8207 printf "FIN_WAIT_2 "
8209 if $tp->t_state == 10
8215 define _showsockprotocol
8216 set $so = (struct socket *)$arg0
8217 set $inpcb = (struct inpcb *)$so->so_pcb
8219 if $so->so_proto->pr_protocol == 6
8221 _showtcpstate $inpcb->inp_ppcb
8223 if $so->so_proto->pr_protocol == 17
8226 if $so->so_proto->pr_protocol == 1
8229 if $so->so_proto->pr_protocol == 254
8232 if $so->so_proto->pr_protocol == 255
8237 define _show_ipv4_socket
8238 set $so = (struct socket *)$arg0
8239 set $inpcb = (struct inpcb *)$so->so_pcb
8241 printf "inpcb: (null) "
8243 printf "inpcb: %p ", $inpcb
8245 _showsockprotocol $so
8247 _show_in_addr_4in6 &$inpcb->inp_dependladdr.inp46_local
8248 _show_in_port &$inpcb->inp_lport
8250 _show_in_addr_4in6 &$inpcb->inp_dependfaddr.inp46_foreign
8251 _show_in_port &$inpcb->inp_fport
8255 define _show_ipv6_socket
8256 set $so = (struct socket *)$arg0
8257 set $pcb = (struct inpcb *)$so->so_pcb
8259 printf "inpcb: (null) "
8261 printf "inpcb: %p ", $pcb
8263 _showsockprotocol $so
8265 _show_in6_addr &$pcb->inp_dependladdr.inp6_local
8266 _show_in_port &$pcb->inp_lport
8268 _show_in6_addr &$pcb->inp_dependfaddr.inp6_foreign
8269 _show_in_port &$pcb->inp_fport
8275 set $so = (struct socket *)$arg0
8277 printf "so: (null) "
8279 printf "so: %p ", $so
8280 if $so && $so->so_proto && $so->so_proto->pr_domain
8281 set $domain = (struct domain *) $so->so_proto->pr_domain
8283 printf "%s ", $domain->dom_name
8284 if $domain->dom_family == 1
8285 _show_unix_domain_socket $so
8287 if $domain->dom_family == 2
8288 _show_ipv4_socket $so
8290 if $domain->dom_family == 30
8291 _show_ipv6_socket $so
8298 Syntax: (gdb) showsocket <socket_address>
8299 | Routine to print out a socket
8302 define showprocsockets
8303 set $pp = (struct proc *)$arg0
8304 set $fdp = (struct filedesc *)$pp->p_fd
8307 set $fpp = (struct fileproc **)($fdp->fd_ofiles)
8308 set $fpo = (char)($fdp->fd_ofileflags[0])
8309 while $count < $fdp->fd_nfiles
8311 set $fg =(struct fileglob *)((**$fpp)->f_fglob)
8312 if $fg && (($fg)->fg_type == 2)
8313 if $fdp->fd_ofileflags[$count] & 4
8318 printf "fd = %d ", $count
8320 showsocket $fg->fg_data
8327 set $count = $count + 1
8330 document showprocsockets
8331 Syntax: (gdb) showprocsockets <proc_address>
8332 | Routine to print out all the open fds
8333 | which are sockets in a process
8336 define showallprocsockets
8337 set $basep = (struct proc *)allproc->lh_first
8340 printf "============================================ \n"
8343 set $pp = $pp->p_list.le_next
8346 document showallprocsockets
8347 Syntax: (gdb) showallprocsockets
8348 | Routine to print out all the open fds
8353 set $port = (unsigned short)$arg0
8354 set $port = (unsigned short)((($arg0 & 0xff00) >> 8) & 0xff)
8355 set $port |= (unsigned short)(($arg0 & 0xff) << 8)
8359 set $INPCB_STATE_INUSE=0x1
8360 set $INPCB_STATE_CACHED=0x2
8361 set $INPCB_STATE_DEAD=0x3
8363 set $INP_RECVOPTS=0x01
8364 set $INP_RECVRETOPTS=0x02
8365 set $INP_RECVDSTADDR=0x04
8366 set $INP_HDRINCL=0x08
8367 set $INP_HIGHPORT=0x10
8368 set $INP_LOWPORT=0x20
8369 set $INP_ANONPORT=0x40
8370 set $INP_RECVIF=0x80
8371 set $INP_MTUDISC=0x100
8372 set $INP_STRIPHDR=0x200
8373 set $INP_RECV_ANYIF=0x400
8374 set $INP_INADDR_ANY=0x800
8375 set $INP_RECVTTL=0x1000
8376 set $INP_UDP_NOCKSUM=0x2000
8377 set $IN6P_IPV6_V6ONLY=0x008000
8378 set $IN6P_PKTINFO=0x010000
8379 set $IN6P_HOPLIMIT=0x020000
8380 set $IN6P_HOPOPTS=0x040000
8381 set $IN6P_DSTOPTS=0x080000
8382 set $IN6P_RTHDR=0x100000
8383 set $IN6P_RTHDRDSTOPTS=0x200000
8384 set $IN6P_AUTOFLOWLABEL=0x800000
8385 set $IN6P_BINDV6ONLY=0x10000000
8394 set $pcb = (struct inpcb *)$arg0
8398 printf "%10p ", $pcb
8400 if $arg1 == $IPPROTO_TCP
8403 if $arg1 == $IPPROTO_UDP
8406 printf "%2d.", $arg1
8409 if ($pcb->inp_vflag & $INP_IPV4)
8412 if ($pcb->inp_vflag & $INP_IPV6)
8416 if ($pcb->inp_vflag & $INP_IPV4)
8418 _show_in_addr &$pcb->inp_dependladdr.inp46_local.ia46_addr4
8420 _show_in6_addr &$pcb->inp_dependladdr.inp6_local
8423 _print_ntohs $pcb->inp_lport
8425 if ($pcb->inp_vflag & $INP_IPV4)
8427 _show_in_addr &($pcb->inp_dependfaddr.inp46_foreign.ia46_addr4)
8429 _show_in6_addr &($pcb->inp_dependfaddr.inp6_foreign)
8432 _print_ntohs $pcb->inp_fport
8435 if $arg1 == $IPPROTO_TCP
8436 _showtcpstate $pcb->inp_ppcb
8440 # set $phd = $pcb->inp_phd
8443 # _print_ntohs $phd->phd_port
8444 # set $phd = $phd->phd_hash.le_next
8447 if ($pcb->inp_flags & $INP_RECVOPTS)
8450 if ($pcb->inp_flags & $INP_RECVRETOPTS)
8451 printf "recvretopts "
8453 if ($pcb->inp_flags & $INP_RECVDSTADDR)
8454 printf "recvdstaddr "
8456 if ($pcb->inp_flags & $INP_HDRINCL)
8459 if ($pcb->inp_flags & $INP_HIGHPORT)
8462 if ($pcb->inp_flags & $INP_LOWPORT)
8465 if ($pcb->inp_flags & $INP_ANONPORT)
8468 if ($pcb->inp_flags & $INP_RECVIF)
8471 if ($pcb->inp_flags & $INP_MTUDISC)
8474 if ($pcb->inp_flags & $INP_STRIPHDR)
8477 if ($pcb->inp_flags & $INP_RECV_ANYIF)
8478 printf "recv_anyif "
8480 if ($pcb->inp_flags & $INP_INADDR_ANY)
8481 printf "inaddr_any "
8483 if ($pcb->inp_flags & $INP_RECVTTL)
8486 if ($pcb->inp_flags & $INP_UDP_NOCKSUM)
8489 if ($pcb->inp_flags & $IN6P_IPV6_V6ONLY)
8492 if ($pcb->inp_flags & $IN6P_PKTINFO)
8495 if ($pcb->inp_flags & $IN6P_HOPLIMIT)
8498 if ($pcb->inp_flags & $IN6P_HOPOPTS)
8501 if ($pcb->inp_flags & $IN6P_DSTOPTS)
8504 if ($pcb->inp_flags & $IN6P_RTHDR)
8507 if ($pcb->inp_flags & $IN6P_RTHDRDSTOPTS)
8508 printf "rthdrdstopts "
8510 if ($pcb->inp_flags & $IN6P_AUTOFLOWLABEL)
8511 printf "autoflowlabel "
8513 if ($pcb->inp_flags & $IN6P_BINDV6ONLY)
8514 printf "bindv6only "
8516 set $so = (struct socket *)$pcb->inp_socket
8518 printf "[so=%p s=%ld r=%ld usecnt=%ld] ", $so, $so->so_snd.sb_cc, \
8519 $so->so_rcv.sb_cc, $so->so_usecount
8521 if ($pcb->inp_state == 0 || $pcb->inp_state == $INPCB_STATE_INUSE)
8524 if ($pcb->inp_state == $INPCB_STATE_CACHED)
8527 if ($pcb->inp_state == $INPCB_STATE_DEAD)
8530 printf "unknown (%d), ", $pcb->inp_state
8536 define _dump_inpcbport
8537 set $ppcb = (struct inpcbport *)$arg0
8538 printf "%p: lport ", $ppcb
8539 _print_ntohs $ppcb->phd_port
8544 define _dump_pcbinfo
8546 set $snd_buf = (unsigned int)0
8548 set $rcv_buf = (unsigned int)0
8550 set $pcbi = (struct inpcbinfo *)$arg0
8551 printf "lastport %d lastlow %d lasthi %d\n", \
8552 $pcbi->lastport, $pcbi->lastlow, $pcbi->lasthi
8553 printf "active pcb count is %d\n", $pcbi->ipi_count
8554 set $hashsize = $pcbi->hashmask + 1
8555 printf "hash size is %d\n", $hashsize
8556 printf "hash base %p has the following inpcb(s):\n", $pcbi->hashbase
8558 printf "pcb prot source address port destination address port\n"
8559 printf "------------------ ---- --------------------------------------- ----- --------------------------------------- -----\n"
8561 printf "pcb prot source address port destination address port\n"
8562 printf "---------- ---- --------------------------------------- ----- --------------------------------------- -----\n"
8565 set $hashbase = $pcbi->hashbase
8566 set $head = *(uintptr_t *)$hashbase
8567 while $i < $hashsize
8569 set $pcb0 = (struct inpcb *)$head
8572 _dump_inpcb $pcb0 $arg1
8573 set $so = (struct socket *)$pcb->inp_socket
8575 set $snd_cc += $so->so_snd.sb_cc
8576 set $mp = $so->so_snd.sb_mb
8579 if ($mp->m_hdr.mh_flags & 0x01)
8580 set $snd_buf += $mp->M_dat.MH.MH_dat.MH_ext.ext_size
8582 set $mp = $mp->m_hdr.mh_next
8584 set $rcv_cc += $so->so_rcv.sb_cc
8585 set $mp = $so->so_rcv.sb_mb
8588 if ($mp->m_hdr.mh_flags & 0x01)
8589 set $rcv_buf += $mp->M_dat.MH.MH_dat.MH_ext.ext_size
8591 set $mp = $mp->m_hdr.mh_next
8594 set $pcb0 = $pcb0->inp_hash.le_next
8600 set $head = *(uintptr_t *)$hashbase
8602 printf "total seen %ld snd_cc %ld rcv_cc %ld\n", $pcbseen, $snd_cc, $rcv_cc
8603 printf "total snd_buf %u rcv_buf %u \n", (unsigned int)$snd_buf, (unsigned int)$rcv_buf
8604 printf "port hash base is %p\n", $pcbi->porthashbase
8606 set $hashbase = $pcbi->porthashbase
8607 set $head = *(uintptr_t *)$hashbase
8608 while $i < $hashsize
8610 set $pcb0 = (struct inpcbport *)$head
8613 _dump_inpcbport $pcb0
8615 set $pcb0 = $pcb0->phd_hash.le_next
8620 set $head = *(uintptr_t *)$hashbase
8624 set $N_TIME_WAIT_SLOTS=128
8626 define show_tcp_timewaitslots
8633 set $slot = (int)$arg0
8636 printf "time wait slot size %d cur_tw_slot %ld\n", $N_TIME_WAIT_SLOTS, cur_tw_slot
8638 while $i < $N_TIME_WAIT_SLOTS
8640 set $head = (uintptr_t *)time_wait_slots[$i]
8641 if $i == $slot || $slot == -1
8643 set $pcb0 = (struct inpcb *)$head
8646 set $pcb0 = $pcb0->inp_list.le_next
8649 printf " slot %ld count %ld\n", $i, $perslot
8651 if $all || $i == $slot
8653 set $pcb0 = (struct inpcb *)$head
8656 _dump_inpcb $pcb0 $IPPROTO_TCP
8658 set $pcb0 = $pcb0->inp_list.le_next
8665 document show_tcp_timewaitslots
8666 Syntax: (gdb) show_tcp_timewaitslots
8667 | Print the list of TCP protocol control block in the TIMEWAIT state
8668 | Pass -1 to see the list of PCB for each slot
8669 | Pass a slot number to see information for that slot with the list of PCB
8672 define show_tcp_pcbinfo
8673 _dump_pcbinfo &tcbinfo $IPPROTO_TCP
8675 document show_tcp_pcbinfo
8676 Syntax: (gdb) show_tcp_pcbinfo
8677 | Print the list of TCP protocol control block information
8681 define show_udp_pcbinfo
8682 _dump_pcbinfo &udbinfo $IPPROTO_UDP
8684 document show_udp_pcbinfo
8685 Syntax: (gdb) show_udp_pcbinfo
8686 | Print the list of UDP protocol control block information
8691 while ($myi < bpf_dtab_size)
8692 if (bpf_dtab[$myi] != 0)
8693 printf "Address 0x%x, bd_next 0x%x\n", bpf_dtab[$myi], bpf_dtab[$myi]->bd_next
8694 print *bpf_dtab[$myi]
8700 define printvnodepathint_recur
8702 if ($arg0->v_flag & 0x000001) && ($arg0->v_mount != 0)
8703 if $arg0->v_mount->mnt_vnodecovered != 0
8704 printvnodepathint_recur $arg0->v_mount->mnt_vnodecovered $arg0->v_mount->mnt_vnodecovered->v_name
8707 printvnodepathint_recur $arg0->v_parent $arg0->v_parent->v_name
8713 define showvnodepath
8714 set $vp = (struct vnode *)$arg0
8716 if ($vp->v_flag & 0x000001) && ($vp->v_mount != 0) && ($vp->v_mount->mnt_flag & 0x00004000)
8719 printvnodepathint_recur $vp $vp->v_name
8725 document showvnodepath
8726 Syntax: (gdb) showvnodepath <vnode>
8727 | Prints the path for a vnode
8735 printf " mnt_devvp "
8737 printf " typename mountpoint\n"
8738 set $kgm_vol = (mount_t) mountlist.tqh_first
8742 showptr $kgm_vol->mnt_data
8744 showptr $kgm_vol->mnt_devvp
8746 if ($kgm_vol->mnt_vtable->vfc_name[0] == 'h') && \
8747 ($kgm_vol->mnt_vtable->vfc_name[1] == 'f') && \
8748 ($kgm_vol->mnt_vtable->vfc_name[2] == 's') && \
8749 ($kgm_vol->mnt_vtable->vfc_name[3] == '\0')
8750 set $kgm_hfsmount = \
8751 (struct hfsmount *) $kgm_vol->mnt_data
8752 if $kgm_hfsmount->hfs_freezing_proc != 0
8753 printf "FROZEN hfs "
8758 printf "%-10s ", $kgm_vol->mnt_vtable->vfc_name
8760 printf "%s\n", $kgm_vol->mnt_vfsstat.f_mntonname
8762 set $kgm_vol = (mount_t) $kgm_vol->mnt_list.tqe_next
8766 document showallvols
8767 Syntax: (gdb) showallvols
8768 | Display a summary of mounted volumes
8771 define showvnodeheader
8774 printf " usecount iocount v_data "
8776 printf " vtype parent "
8782 set $kgm_vnode = (vnode_t) $arg0
8784 printf " %8d ", $kgm_vnode->v_usecount
8785 printf "%7d ", $kgm_vnode->v_iocount
8786 # print information about clean/dirty blocks?
8787 showptr $kgm_vnode->v_data
8789 # print the vtype, using the enum tag
8790 set $kgm_vtype = $kgm_vnode->v_type
8791 if $kgm_vtype == VNON
8794 if $kgm_vtype == VREG
8797 if $kgm_vtype == VDIR
8800 if $kgm_vtype == VBLK
8803 if $kgm_vtype == VCHR
8806 if $kgm_vtype == VLNK
8809 if $kgm_vtype == VSOCK
8812 if $kgm_vtype == VFIFO
8815 if $kgm_vtype == VBAD
8818 if ($kgm_vtype < VNON) || ($kgm_vtype > VBAD)
8819 printf "%5d ", $kgm_vtype
8822 showptr $kgm_vnode->v_parent
8824 if ($kgm_vnode->v_name != 0)
8825 printf "%s\n", $kgm_vnode->v_name
8827 # If this is HFS vnode, get name from the cnode
8828 if ($kgm_vnode->v_tag == 16)
8829 set $kgm_cnode = (struct cnode *)$kgm_vnode->v_data
8830 printf "hfs: %s\n", (char *)$kgm_cnode->c_desc->cd_nameptr
8843 Syntax: (gdb) showvnode <vnode>
8844 | Display info about one vnode
8847 define showvolvnodes
8849 set $kgm_vol = (mount_t) $arg0
8850 set $kgm_vnode = (vnode_t) $kgm_vol.mnt_vnodelist.tqh_first
8852 showvnodeint $kgm_vnode
8853 set $kgm_vnode = (vnode_t) $kgm_vnode->v_mntvnodes.tqe_next
8857 document showvolvnodes
8858 Syntax: (gdb) showvolvnodes <mouont_t>
8859 | Display info about all vnodes of a given mount_t
8862 define showvolbusyvnodes
8864 set $kgm_vol = (mount_t) $arg0
8865 set $kgm_vnode = (vnode_t) $kgm_vol.mnt_vnodelist.tqh_first
8867 if $kgm_vnode->v_iocount != 0
8868 showvnodeint $kgm_vnode
8870 set $kgm_vnode = (vnode_t) $kgm_vnode->v_mntvnodes.tqe_next
8874 document showvolbusyvnodes
8875 Syntax: (gdb) showvolbusyvnodes <mount_t>
8876 | Display info about busy (iocount!=0) vnodes of a given mount_t
8879 define showallbusyvnodes
8881 set $kgm_vol = (mount_t) mountlist.tqh_first
8883 set $kgm_vnode = (vnode_t) $kgm_vol.mnt_vnodelist.tqh_first
8885 if $kgm_vnode->v_iocount != 0
8886 showvnodeint $kgm_vnode
8888 set $kgm_vnode = (vnode_t) $kgm_vnode->v_mntvnodes.tqe_next
8890 set $kgm_vol = (mount_t) $kgm_vol->mnt_list.tqe_next
8894 document showallbusyvnodes
8895 Syntax: (gdb) showallbusyvnodes <vnode>
8896 | Display info about all busy (iocount!=0) vnodes
8899 define showallvnodes
8901 set $kgm_vol = (mount_t) mountlist.tqh_first
8903 set $kgm_vnode = (vnode_t) $kgm_vol.mnt_vnodelist.tqh_first
8905 showvnodeint $kgm_vnode
8906 set $kgm_vnode = (vnode_t) $kgm_vnode->v_mntvnodes.tqe_next
8908 set $kgm_vol = (mount_t) $kgm_vol->mnt_list.tqe_next
8912 document showallvnodes
8913 Syntax: (gdb) showallvnodes
8914 | Display info about all vnodes
8917 define _showvnodelockheader
8918 printf "* type W held by lock type start end\n"
8919 printf "- ----- - ------------- --------- ------------------ ------------------\n"
8922 define _showvnodelock
8923 set $kgm_svl_lock = ((struct lockf *)$arg0)
8926 set $kgm_svl_flags = $kgm_svl_lock->lf_flags
8927 set $kgm_svl_type = $kgm_svl_lock->lf_type
8928 if ($kgm_svl_flags & 0x20)
8931 if ($kgm_svl_flags & 0x40)
8934 if ($kgm_svl_flags & 0x80)
8937 if ($kgm_svl_flags & 0x10)
8943 # POSIX file vs. advisory range locks
8944 if ($kgm_svl_flags & 0x40)
8945 set $kgm_svl_proc = (proc_t)$kgm_svl_lock->lf_id
8946 printf "PID %8d ", $kgm_svl_proc->p_pid
8948 printf "ID 0x%08x ", $kgm_svl_lock->lf_id
8952 if ($kgm_svl_type == 1)
8955 if ($kgm_svl_type == 3)
8958 if ($kgm_svl_type == 2)
8967 printf "0x%016x..", $kgm_svl_lock->lf_start
8968 printf "0x%016x ", $kgm_svl_lock->lf_end
8971 # Body of showvnodelocks, not including header
8972 define _showvnodelocks
8973 set $kgm_svl_vnode = ((vnode_t)$arg0)
8974 set $kgm_svl_lockiter = $kgm_svl_vnode->v_lockf
8975 while ($kgm_svl_lockiter != 0)
8976 # locks that are held
8978 _showvnodelock $kgm_svl_lockiter
8980 # and any locks blocked by them
8981 set $kgm_svl_blocker = $kgm_svl_lockiter->lf_blkhd.tqh_first
8982 while ($kgm_svl_blocker != 0)
8984 _showvnodelock $kgm_svl_blocker
8985 set $kgm_svl_blocker = $kgm_svl_blocker->lf_block.tqe_next
8988 # and on to the next one...
8989 set $kgm_svl_lockiter = $kgm_svl_lockiter->lf_next
8994 define showvnodelocks
8996 _showvnodelockheader
8997 _showvnodelocks $arg0
8999 printf "| Usage:\n|\n"
9004 document showvnodelocks
9005 Syntax: (gdb) showvnodelocks <vnode_t>
9006 | Given a vnodet pointer, display the list of advisory record locks for the
9007 | referenced pvnodes
9011 printf "%s\n", (char*)((boot_args*)PE_state.bootArgs).CommandLine
9014 document showbootargs
9015 Syntax: showbootargs
9016 | Display boot arguments passed to the target kernel
9019 define showbootermemorymap
9020 if ($kgm_mtype == $kgm_mtype_i386)
9021 set $kgm_voffset = 0
9023 if ($kgm_mtype == $kgm_mtype_x86_64)
9024 set $kgm_voffset = 0xFFFFFF8000000000ULL
9026 echo showbootermemorymap not supported on this architecture
9030 set $kgm_boot_args = kernelBootArgs
9031 set $kgm_msize = kernelBootArgs->MemoryMapDescriptorSize
9032 set $kgm_mcount = kernelBootArgs->MemoryMapSize / $kgm_msize
9035 printf "Type Physical Start Number of Pages Virtual Start Attributes\n"
9036 while $kgm_i < $kgm_mcount
9037 set $kgm_mptr = (EfiMemoryRange *)((unsigned long)kernelBootArgs->MemoryMap + $kgm_voffset + $kgm_i * $kgm_msize)
9039 if $kgm_mptr->Type == 0
9042 if $kgm_mptr->Type == 1
9045 if $kgm_mptr->Type == 2
9048 if $kgm_mptr->Type == 3
9051 if $kgm_mptr->Type == 4
9054 if $kgm_mptr->Type == 5
9057 if $kgm_mptr->Type == 6
9060 if $kgm_mptr->Type == 7
9063 if $kgm_mptr->Type == 8
9066 if $kgm_mptr->Type == 9
9069 if $kgm_mptr->Type == 10
9072 if $kgm_mptr->Type == 11
9075 if $kgm_mptr->Type == 12
9078 if $kgm_mptr->Type == 13
9081 if $kgm_mptr->Type > 13
9085 printf " %016llx %016llx", $kgm_mptr->PhysicalStart, $kgm_mptr->NumberOfPages
9086 if $kgm_mptr->VirtualStart != 0
9087 printf " %016llx", $kgm_mptr->VirtualStart
9091 printf " %016llx\n", $kgm_mptr->Attribute
9092 set $kgm_i = $kgm_i + 1
9096 document showbootermemorymap
9097 Syntax: (gdb) showbootermemorymap
9098 | Prints out the phys memory map from kernelBootArgs
9102 define showstacksaftertask
9103 set $kgm_head_taskp = &tasks
9104 set $kgm_taskp = (struct task *)$arg0
9105 set $kgm_taskp = (struct task *)$kgm_taskp->tasks.next
9106 while $kgm_taskp != $kgm_head_taskp
9108 showtaskint $kgm_taskp
9109 set $kgm_head_actp = &($kgm_taskp->threads)
9110 set $kgm_actp = (struct thread *)($kgm_taskp->threads.next)
9111 while $kgm_actp != $kgm_head_actp
9113 if ($decode_wait_events > 0)
9114 showactint $kgm_actp 1
9116 showactint $kgm_actp 2
9118 set $kgm_actp = (struct thread *)($kgm_actp->task_threads.next)
9121 set $kgm_taskp = (struct task *)($kgm_taskp->tasks.next)
9124 document showstacksaftertask
9125 Syntax: (gdb) showstacksaftertask <task>
9126 | Routine to print out all stacks (as in showallstacks) starting after a given task
9127 | Useful if that gdb refuses to print a certain task's stack.
9130 define showpmworkqueueint
9131 set $kgm_pm_workqueue = (IOPMWorkQueue *)$arg0
9132 set $kgm_pm_wq = &($kgm_pm_workqueue->fWorkQueue)
9133 set $kgm_pm_wqe = (IOServicePM *)$kgm_pm_wq->next
9134 while ((queue_entry_t) $kgm_pm_wqe != (queue_entry_t) $kgm_pm_wq)
9137 printf " ps ms wr name\n"
9138 showptr $kgm_pm_wqe->Owner
9140 printf "%02d ", $kgm_pm_wqe->CurrentPowerState
9141 printf "%02d ", $kgm_pm_wqe->MachineState
9142 printf "%02d ", $kgm_pm_wqe->WaitReason
9143 printf "%s\n", $kgm_pm_wqe->Name
9146 printf " type next "
9150 printf " work_wait free_wait\n"
9151 set $kgm_pm_rq = &($kgm_pm_wqe->RequestHead)
9152 set $kgm_pm_rqe = (IOPMRequest *)$kgm_pm_rq->next
9153 while ((queue_entry_t) $kgm_pm_rqe != (queue_entry_t) $kgm_pm_rq)
9155 printf " 0x%02x ", $kgm_pm_rqe->fType
9156 showptr $kgm_pm_rqe->fRequestNext
9158 showptr $kgm_pm_rqe->fRequestRoot
9159 printf " 0x%08x 0x%08x\n", $kgm_pm_rqe->fWorkWaitCount, $kgm_pm_rqe->fFreeWaitCount
9162 showptr $kgm_pm_rqe->fArg0
9164 showptr $kgm_pm_rqe->fArg1
9166 showptr $kgm_pm_rqe->fArg2
9168 set $kgm_pm_rqe = (IOPMRequest *)$kgm_pm_rqe->fCommandChain.next
9171 set $kgm_pm_wqe = (IOServicePM *)$kgm_pm_wqe->WorkChain.next
9175 define showpmworkqueue
9176 printf "IOPMWorkQueue "
9177 showptr gIOPMWorkQueue
9179 printf "%u", gIOPMWorkQueue->fQueueLength
9181 if (gIOPMWorkQueue->fQueueLength > 0)
9182 showpmworkqueueint gIOPMWorkQueue
9186 document showpmworkqueue
9187 Syntax: (gdb) showpmworkqueue
9188 | Display the IOPMWorkQueue object
9191 define showioservicepm
9192 set $kgm_iopmpriv = (IOServicePM *)$arg0
9194 printf "MachineState = %d (", $kgm_iopmpriv->MachineState
9195 if ( $kgm_iopmpriv->MachineState == 0 )
9196 printf "kIOPM_Finished"
9198 if ( $kgm_iopmpriv->MachineState == 1 )
9199 printf "kIOPM_OurChangeTellClientsPowerDown"
9201 if ( $kgm_iopmpriv->MachineState == 2 )
9202 printf "kIOPM_OurChangeTellPriorityClientsPowerDown"
9204 if ( $kgm_iopmpriv->MachineState == 3 )
9205 printf "kIOPM_OurChangeNotifyInterestedDriversWillChange"
9207 if ( $kgm_iopmpriv->MachineState == 4 )
9208 printf "kIOPM_OurChangeSetPowerState"
9210 if ( $kgm_iopmpriv->MachineState == 5 )
9211 printf "kIOPM_OurChangeWaitForPowerSettle"
9213 if ( $kgm_iopmpriv->MachineState == 6 )
9214 printf "kIOPM_OurChangeNotifyInterestedDriversDidChange"
9216 if ( $kgm_iopmpriv->MachineState == 7 )
9217 printf "kIOPM_OurChangeTellCapabilityDidChange"
9219 if ( $kgm_iopmpriv->MachineState == 8 )
9220 printf "kIOPM_OurChangeFinish"
9222 if ( $kgm_iopmpriv->MachineState == 9 )
9223 printf "Unused_MachineState_9"
9225 if ( $kgm_iopmpriv->MachineState == 10 )
9226 printf "kIOPM_ParentChangeTellPriorityClientsPowerDown"
9228 if ( $kgm_iopmpriv->MachineState == 11 )
9229 printf "kIOPM_ParentChangeNotifyInterestedDriversWillChange"
9231 if ( $kgm_iopmpriv->MachineState == 12 )
9232 printf "kIOPM_ParentChangeSetPowerState"
9234 if ( $kgm_iopmpriv->MachineState == 13 )
9235 printf "kIOPM_ParentChangeWaitForPowerSettle"
9237 if ( $kgm_iopmpriv->MachineState == 14)
9238 printf "kIOPM_ParentChangeNotifyInterestedDriversDidChange"
9240 if ( $kgm_iopmpriv->MachineState == 15)
9241 printf "kIOPM_ParentChangeTellCapabilityDidChange"
9243 if ( $kgm_iopmpriv->MachineState == 16)
9244 printf "kIOPM_ParentChangeAcknowledgePowerChange"
9246 if ( $kgm_iopmpriv->MachineState == 17)
9247 printf "kIOPM_NotifyChildrenStart"
9249 if ( $kgm_iopmpriv->MachineState == 18)
9250 printf "kIOPM_NotifyChildrenOrdered"
9252 if ( $kgm_iopmpriv->MachineState == 19)
9253 printf "kIOPM_NotifyChildrenDelayed"
9255 if ( $kgm_iopmpriv->MachineState == 20)
9256 printf "kIOPM_SyncTellClientsPowerDown"
9258 if ( $kgm_iopmpriv->MachineState == 21)
9259 printf "kIOPM_SyncTellPriorityClientsPowerDown"
9261 if ( $kgm_iopmpriv->MachineState == 22)
9262 printf "kIOPM_SyncNotifyWillChange"
9264 if ( $kgm_iopmpriv->MachineState == 23)
9265 printf "kIOPM_SyncNotifyDidChange"
9267 if ( $kgm_iopmpriv->MachineState == 24)
9268 printf "kIOPM_SyncTellCapabilityDidChange"
9270 if ( $kgm_iopmpriv->MachineState == 25)
9271 printf "kIOPM_SyncFinish"
9273 if ( $kgm_iopmpriv->MachineState == 26)
9274 printf "kIOPM_TellCapabilityChangeDone"
9276 if ( $kgm_iopmpriv->MachineState == 27)
9277 printf "kIOPM_DriverThreadCallDone"
9279 printf "Unknown_MachineState"
9310 if ( $kgm_iopmpriv->MachineState != 20 )
9311 printf "DriverTimer = %d, ",(unsigned int)$kgm_iopmpriv->DriverTimer
9312 printf "SettleTime = %d, ",(unsigned int)$kgm_iopmpriv->SettleTimeUS
9313 printf "HeadNoteFlags = %08x, ",(unsigned int)$kgm_iopmpriv->HeadNoteChangeFlags
9314 printf "HeadNotePendingAcks = %x, ",(unsigned int)$kgm_iopmpriv->HeadNotePendingAcks
9317 if ( $kgm_iopmpriv->DeviceOverrideEnabled != 0 )
9318 printf"DeviceOverrides, "
9321 printf "DeviceDesire = %d, ",(unsigned int)$kgm_iopmpriv->DeviceDesire
9322 printf "DesiredPowerState = %d, ",(unsigned int)$kgm_iopmpriv->DesiredPowerState
9323 printf "PreviousRequest = %d }\n",(unsigned int)$kgm_iopmpriv->PreviousRequestPowerFlags
9326 document showioservicepm
9327 Syntax: (gdb) showioservicepm <IOServicePM pointer>
9328 | Routine to dump the IOServicePM object
9331 define showregistryentryrecursepmstate
9332 set $kgm_re = (IOService *)$arg1
9333 set $kgm$arg0_stack = (unsigned long long) $arg2
9336 set $kgm$arg0_stack = $kgm$arg0_stack | (1ULL << $kgm_reg_depth)
9338 set $kgm$arg0_stack = $kgm$arg0_stack & ~(1ULL << $kgm_reg_depth)
9341 dictget $kgm_re->fRegistryTable $kgm_childkey
9342 set $kgm$arg0_child_array = (OSArray *) $kgm_result
9344 if ($kgm$arg0_child_array)
9345 set $kgm$arg0_child_count = $kgm$arg0_child_array->count
9347 set $kgm$arg0_child_count = 0
9350 if ($kgm$arg0_child_count)
9351 set $kgm$arg0_stack = $kgm$arg0_stack | (2ULL << $kgm_reg_depth)
9353 set $kgm$arg0_stack = $kgm$arg0_stack & ~(2ULL << $kgm_reg_depth)
9356 indent $kgm_reg_depth $kgm$arg0_stack
9359 dictget $kgm_re->fRegistryTable $kgm_namekey
9360 if ($kgm_result == 0)
9361 dictget $kgm_re->fRegistryTable gIONameKey
9363 if ($kgm_result == 0)
9364 dictget $kgm_re->fPropertyTable gIOClassKey
9367 if ($kgm_result != 0)
9368 printf "%s <%p>", ((OSString *)$kgm_result)->string, $kgm_re
9370 if (((IOService*)$kgm_re)->pwrMgt && ((IOService*)$kgm_re)->pwrMgt->Name)
9371 printf "%s <", ((IOService*)$kgm_re)->pwrMgt->Name
9381 if (((IOService*)$kgm_re)->pwrMgt )
9382 printf " Current Power State: %ld ", ((IOService*)$kgm_re)->pwrMgt->CurrentPowerState
9383 #printf " Mach State %ld", ((IOService*)$kgm_re)->pwrMgt->MachineState
9384 showioservicepm ((IOService*)$kgm_re)->pwrMgt
9390 if ($kgm$arg0_child_count != 0)
9392 set $kgm_reg_depth = $kgm_reg_depth + 1
9393 set $kgm$arg0_child_idx = 0
9395 while ($kgm$arg0_child_idx < $kgm$arg0_child_count)
9396 set $kgm_re = $kgm$arg0_child_array->array[$kgm$arg0_child_idx++]
9397 set $kgm_more_sib = ($kgm$arg0_child_idx < $kgm$arg0_child_count)
9398 if $kgm_reg_depth >= $kgm_reg_depth_max + 1
9401 showregistryentryrecursepmstate _$arg0 $kgm_re $kgm$arg0_stack $kgm_more_sib
9404 set $kgm_reg_depth = $kgm_reg_depth - 1
9408 define showregistryentryintpmstate
9410 set $kgm_reg_plane = (IORegistryPlane *) gIOServicePlane
9414 printf "Please load kgmacros after KDP attaching to the target.\n"
9416 set $kgm_namekey = (OSSymbol *) $kgm_reg_plane->nameKey
9417 set $kgm_childkey = (OSSymbol *) $kgm_reg_plane->keys[1]
9418 showregistryentryrecursepmstate _ $arg0 0 0
9422 define showregistrypmstate
9423 # setregistryplane gIOPowerPlane
9424 set $kgm_reg_depth = 0
9425 set $kgm_show_props = 1
9426 showregistryentryintpmstate gRegistryRoot
9429 document showregistrypmstate
9430 Syntax: (gdb) showregistrypmstate
9431 | Routine to dump the PM state of each IOPower registry entry
9434 define showstacksafterthread
9435 set $kgm_head_taskp = &tasks
9436 set $kgm_actp = (struct thread *)$arg0
9437 set $kgm_actp = (struct thread *)($kgm_actp->task_threads.next)
9438 set $kgm_taskp = (struct task *)$kgm_actp->task
9439 while $kgm_taskp != $kgm_head_taskp
9441 showtaskint $kgm_taskp
9442 set $kgm_head_actp = &($kgm_taskp->threads)
9444 set $kgm_actp = (struct thread *)($kgm_taskp->threads.next)
9446 while $kgm_actp != $kgm_head_actp
9448 if ($decode_wait_events > 0)
9449 showactint $kgm_actp 1
9451 showactint $kgm_actp 2
9453 set $kgm_actp = (struct thread *)($kgm_actp->task_threads.next)
9456 set $kgm_taskp = (struct task *)($kgm_taskp->tasks.next)
9461 document showstacksafterthread
9462 Syntax: (gdb) showstacksafterthread <thread>
9463 | Routine to print out all stacks (as in showallstacks) starting after a given thread
9464 | Useful if that gdb refuses to print a certain task's stack.
9468 set kdp_reentry_deadline = ((unsigned) $arg0)*1000
9472 document kdp-reenter
9473 Syntax: (gdb) kdp-reenter <seconds>
9474 | Schedules reentry into the debugger after <seconds> seconds, and resumes
9475 | the target system.
9486 if (($kgm_mtype & $kgm_mtype_x86_mask) != $kgm_mtype_x86_any)
9487 printf "Not available for current architecture.\n"
9490 _if_present mca_MCA_present
9491 printf ", control MSR"
9492 _if_present mca_control_MSR_present
9493 printf ", threshold status"
9494 _if_present mca_threshold_status_present
9495 printf "\n%d error banks, ", mca_error_bank_count
9496 printf "family code 0x%x, ", mca_family
9497 printf "machine-check dump state: %d\n", mca_dump_state
9499 while cpu_data_ptr[$kgm_cpu] != 0
9500 set $kgm_mcp = cpu_data_ptr[$kgm_cpu]->cpu_mca_state
9502 printf "CPU %d:", $kgm_cpu
9503 printf " mca_mcg_ctl: 0x%016llx", $kgm_mcp->mca_mcg_ctl
9504 printf " mca_mcg_status: 0x%016llx\n", $kgm_mcp->mca_mcg_status.u64
9506 printf "mca_mci_ctl "
9507 printf "mca_mci_status "
9508 printf "mca_mci_addr "
9509 printf "mca_mci_misc\n"
9511 while $kgm_bank < mca_error_bank_count
9512 set $kgm_bp = &$kgm_mcp->mca_error_bank[$kgm_bank]
9513 printf " %2d:", $kgm_bank
9514 printf " 0x%016llx", $kgm_bp->mca_mci_ctl
9515 printf " 0x%016llx", $kgm_bp->mca_mci_status.u64
9516 printf " 0x%016llx", $kgm_bp->mca_mci_addr
9517 printf " 0x%016llx\n", $kgm_bp->mca_mci_misc
9518 set $kgm_bank = $kgm_bank + 1
9521 set $kgm_cpu = $kgm_cpu + 1
9526 document showMCAstate
9527 Syntax: showMCAstate
9528 | Print machine-check register state after MC exception.
9533 # Step to lower-level page table and print attributes
9534 # $kgm_pt_paddr: current page table entry physical address
9535 # $kgm_pt_index: current page table entry index (0..511)
9537 # $kgm_pt_paddr: next level page table entry physical address
9538 # or null if invalid
9539 # $kgm_pt_valid: 1 if $kgm_pt_paddr is valid, 0 if the walk
9541 # $kgm_pt_large: 1 if kgm_pt_paddr is a page frame address
9542 # of a large page and not another page table entry
9543 # For $kgm_pt_verbose = 0: print nothing
9544 # 1: print basic information
9545 # 2: print basic information and hex table dump
9547 set $kgm_entryp = $kgm_pt_paddr + 8*$kgm_pt_index
9548 readphysint $kgm_entryp 64 $kgm_lcpu_self
9549 set $entry = $kgm_readphysint_result
9550 if $kgm_pt_verbose >= 3
9551 set $kgm_pte_loop = 0
9552 while $kgm_pte_loop < 512
9553 set $kgm_pt_paddr_tmp = $kgm_pt_paddr + $kgm_pte_loop*8
9554 readphys64 $kgm_pt_paddr_tmp
9555 set $kgm_pte_loop = $kgm_pte_loop + 1
9558 set $kgm_paddr_mask = ~((0xfffULL<<52) | 0xfffULL)
9559 set $kgm_paddr_largemask = ~((0xfffULL<<52) | 0x1fffffULL)
9560 if $kgm_pt_verbose < 2
9561 if $entry & (0x1 << 0)
9562 set $kgm_pt_valid = 1
9563 if $entry & (0x1 << 7)
9564 set $kgm_pt_large = 1
9565 set $kgm_pt_paddr = $entry & $kgm_paddr_largemask
9567 set $kgm_pt_large = 0
9568 set $kgm_pt_paddr = $entry & $kgm_paddr_mask
9571 set $kgm_pt_valid = 0
9572 set $kgm_pt_large = 0
9573 set $kgm_pt_paddr = 0
9576 printf "0x%016llx:\n\t0x%016llx\n\t", $kgm_entryp, $entry
9577 if $entry & (0x1 << 0)
9579 set $kgm_pt_paddr = $entry & $kgm_paddr_mask
9580 set $kgm_pt_valid = 1
9583 set $kgm_pt_paddr = 0
9584 set $kgm_pt_valid = 0
9585 # stop decoding other bits
9588 if $entry & (0x1 << 1)
9593 if $entry & (0x1 << 2)
9596 printf " supervisor"
9598 if $entry & (0x1 << 3)
9601 if $entry & (0x1 << 4)
9604 if $entry & (0x1 << 5)
9607 if $entry & (0x1 << 6)
9610 if $entry & (0x1 << 7)
9612 set $kgm_pt_large = 1
9614 set $kgm_pt_large = 0
9616 if $entry & (0x1 << 8)
9619 if $entry & (0x3 << 9)
9620 printf " avail:0x%x", ($entry >> 9) & 0x3
9622 if $entry & (0x1ULL << 63)
9630 set $kgm_pt_paddr = $arg0
9631 set $kgm_vaddr = $arg1
9632 set $kgm_pt_valid = $kgm_pt_paddr != 0
9633 set $kgm_pt_large = 0
9634 set $kgm_pframe_offset = 0
9635 if $kgm_pt_valid && cpu_64bit
9636 # Look up bits 47:39 of the linear address in PML4T
9637 set $kgm_pt_index = ($kgm_vaddr >> 39) & 0x1ffULL
9638 set $kgm_pframe_offset = $kgm_vaddr & 0x7fffffffffULL
9639 if $kgm_pt_verbose >= 2
9640 printf "pml4 (index %d):\n", $kgm_pt_index
9645 # Look up bits 38:30 of the linear address in PDPT
9646 set $kgm_pt_index = ($kgm_vaddr >> 30) & 0x1ffULL
9647 set $kgm_pframe_offset = $kgm_vaddr & 0x3fffffffULL
9648 if $kgm_pt_verbose >= 2
9649 printf "pdpt (index %d):\n", $kgm_pt_index
9653 if $kgm_pt_valid && !$kgm_pt_large
9654 # Look up bits 29:21 of the linear address in PDT
9655 set $kgm_pt_index = ($kgm_vaddr >> 21) & 0x1ffULL
9656 set $kgm_pframe_offset = $kgm_vaddr & 0x1fffffULL
9657 if $kgm_pt_verbose >= 2
9658 printf "pdt (index %d):\n", $kgm_pt_index
9662 if $kgm_pt_valid && !$kgm_pt_large
9663 # Look up bits 20:21 of the linear address in PT
9664 set $kgm_pt_index = ($kgm_vaddr >> 12) & 0x1ffULL
9665 set $kgm_pframe_offset = $kgm_vaddr & 0xfffULL
9666 if $kgm_pt_verbose >= 2
9667 printf "pt (index %d):\n", $kgm_pt_index
9673 set $kgm_paddr = $kgm_pt_paddr + $kgm_pframe_offset
9674 set $kgm_paddr_isvalid = 1
9677 set $kgm_paddr_isvalid = 0
9680 if $kgm_pt_verbose >= 1
9681 if $kgm_paddr_isvalid
9682 readphysint $kgm_paddr 32 $kgm_lcpu_self
9683 set $kgm_value = $kgm_readphysint_result
9684 printf "phys 0x%016llx: 0x%08x\n", $kgm_paddr, $kgm_value
9686 printf "(no translation)\n"
9691 define _pmap_walk_x86
9692 set $kgm_pmap = (pmap_t) $arg0
9693 _pml4_walk $kgm_pmap->pm_cr3 $arg1
9696 define _pmap_walk_arm_level1_section
9697 set $kgm_tte_p = $arg0
9698 set $kgm_tte = *$kgm_tte_p
9699 set $kgm_vaddr = $arg1
9701 # Supersection or just section?
9702 if (($kgm_tte & 0x00040000) == 0x00040000)
9703 set $kgm_paddr = ($kgm_tte & 0xFF000000) | ($kgm_vaddr & 0x00FFFFFF)
9704 set $kgm_paddr_isvalid = 1
9706 set $kgm_paddr = ($kgm_tte & 0xFFF00000) | ($kgm_vaddr & 0x000FFFFF)
9707 set $kgm_paddr_isvalid = 1
9710 if $kgm_pt_verbose >= 2
9711 printf "0x%08x\n\t0x%08x\n\t", (unsigned long)$kgm_tte_p, $kgm_tte
9713 # bit [1:0] evaluated in _pmap_walk_arm
9716 set $kgm_b_bit = (($kgm_tte & 0x00000004) >> 2)
9719 set $kgm_c_bit = (($kgm_tte & 0x00000008) >> 3)
9722 if ($kgm_tte & 0x00000010)
9728 # Domain bit [8:5] if not supersection
9729 if (($kgm_tte & 0x00040000) == 0x00000000)
9730 printf " domain(%d)", (($kgm_tte & 0x000001e0) >> 5)
9734 printf " imp(%d)", (($kgm_tte & 0x00000200) >> 9)
9736 # AP bit 15 and [11:10], merged to a single 3-bit value
9737 set $kgm_access = (($kgm_tte & 0x00000c00) >> 10) | (($kgm_tte & 0x00008000) >> 13)
9738 if ($kgm_access == 0x0)
9741 if ($kgm_access == 0x1)
9742 printf " supervisor(readwrite) user(noaccess)"
9744 if ($kgm_access == 0x2)
9745 printf " supervisor(readwrite) user(readonly)"
9747 if ($kgm_access == 0x3)
9748 printf " supervisor(readwrite) user(readwrite)"
9750 if ($kgm_access == 0x4)
9751 printf " noaccess(reserved)"
9753 if ($kgm_access == 0x5)
9754 printf " supervisor(readonly) user(noaccess)"
9756 if ($kgm_access == 0x6)
9757 printf " supervisor(readonly) user(readonly)"
9759 if ($kgm_access == 0x7)
9760 printf " supervisor(readonly) user(readonly)"
9764 set $kgm_tex_bits = (($kgm_tte & 0x00007000) >> 12)
9766 # Print TEX, C, B all together
9767 printf " TEX:C:B(%d%d%d:%d:%d)", ($kgm_tex_bits & 0x4 ? 1 : 0), ($kgm_tex_bits & 0x2 ? 1 : 0), ($kgm_tex_bits & 0x1 ? 1 : 0), $kgm_c_bit, $kgm_b_bit
9770 if ($kgm_tte & 0x00010000)
9773 printf " not-shareable"
9777 if ($kgm_tte & 0x00020000)
9778 printf " not-global"
9783 # Supersection bit 18
9784 if ($kgm_tte & 0x00040000)
9785 printf " supersection"
9791 if ($kgm_tte & 0x00080000)
9801 define _pmap_walk_arm_level2
9802 set $kgm_tte_p = $arg0
9803 set $kgm_tte = *$kgm_tte_p
9804 set $kgm_vaddr = $arg1
9806 set $kgm_pte_pbase = (($kgm_tte & 0xFFFFFC00) - gPhysBase + gVirtBase)
9807 set $kgm_pte_index = ($kgm_vaddr >> 12) & 0x000000FF
9808 set $kgm_pte_p = &((pt_entry_t *)$kgm_pte_pbase)[$kgm_pte_index]
9809 set $kgm_pte = *$kgm_pte_p
9811 # Print first level symbolically
9812 if $kgm_pt_verbose >= 2
9813 printf "0x%08x\n\t0x%08x\n\t", (unsigned long)$kgm_tte_p, $kgm_tte
9815 # bit [1:0] evaluated in _pmap_walk_arm
9818 if ($kgm_tte & 0x00000008)
9825 printf " domain(%d)", (($kgm_tte & 0x000001e0) >> 5)
9828 printf " imp(%d)", (($kgm_tte & 0x00000200) >> 9)
9833 if $kgm_pt_verbose >= 2
9834 printf "second-level table (index %d):\n", $kgm_pte_index
9836 if $kgm_pt_verbose >= 3
9837 set $kgm_pte_loop = 0
9838 while $kgm_pte_loop < 256
9839 set $kgm_pte_p_tmp = &((pt_entry_t *)$kgm_pte_pbase)[$kgm_pte_loop]
9840 printf "0x%08x:\t0x%08x\n", (unsigned long)$kgm_pte_p_tmp, *$kgm_pte_p_tmp
9841 set $kgm_pte_loop = $kgm_pte_loop + 1
9845 if ($kgm_pte & 0x00000003)
9846 set $kgm_pve_p = (pv_entry_t *)($kgm_pte_pbase + 0x100*sizeof(pt_entry_t) + $kgm_pte_index*sizeof(pv_entry_t))
9847 if ($kgm_pve_p->shadow != 0)
9848 set $kgm_spte = $kgm_pve_p->shadow ^ ($kgm_vaddr & ~0xFFF)
9849 set $kgm_paddr = ($kgm_spte & 0xFFFFF000) | ($kgm_vaddr & 0xFFF)
9850 set $kgm_paddr_isvalid = 1
9852 set $kgm_paddr = (*$kgm_pte_p & 0xFFFFF000) | ($kgm_vaddr & 0xFFF)
9853 set $kgm_paddr_isvalid = 1
9857 set $kgm_paddr_isvalid = 0
9860 if $kgm_pt_verbose >= 2
9861 printf "0x%08x\n\t0x%08x\n\t", (unsigned long)$kgm_pte_p, $kgm_pte
9862 if (($kgm_pte & 0x00000003) == 0x00000000)
9865 if (($kgm_pte & 0x00000003) == 0x00000001)
9869 if ($kgm_pte & 0x00008000) == 0x00008000
9870 printf " no-execute"
9878 if ($kgm_pte & 0x00000001) == 0x00000001
9879 printf " no-execute"
9886 set $kgm_b_bit = (($kgm_pte & 0x00000004) >> 2)
9889 set $kgm_c_bit = (($kgm_pte & 0x00000008) >> 3)
9891 # AP bit 9 and [5:4], merged to a single 3-bit value
9892 set $kgm_access = (($kgm_pte & 0x00000030) >> 4) | (($kgm_pte & 0x00000200) >> 7)
9893 if ($kgm_access == 0x0)
9896 if ($kgm_access == 0x1)
9897 printf " supervisor(readwrite) user(noaccess)"
9899 if ($kgm_access == 0x2)
9900 printf " supervisor(readwrite) user(readonly)"
9902 if ($kgm_access == 0x3)
9903 printf " supervisor(readwrite) user(readwrite)"
9905 if ($kgm_access == 0x4)
9906 printf " noaccess(reserved)"
9908 if ($kgm_access == 0x5)
9909 printf " supervisor(readonly) user(noaccess)"
9911 if ($kgm_access == 0x6)
9912 printf " supervisor(readonly) user(readonly)"
9914 if ($kgm_access == 0x7)
9915 printf " supervisor(readonly) user(readonly)"
9918 # TEX bit [14:12] for large, [8:6] for small
9919 if (($kgm_pte & 0x00000003) == 0x00000001)
9920 set $kgm_tex_bits = (($kgm_pte & 0x00007000) >> 12)
9922 set $kgm_tex_bits = (($kgm_pte & 0x000001c0) >> 6)
9925 # Print TEX, C, B all together
9926 printf " TEX:C:B(%d%d%d:%d:%d)", ($kgm_tex_bits & 0x4 ? 1 : 0), ($kgm_tex_bits & 0x2 ? 1 : 0), ($kgm_tex_bits & 0x1 ? 1 : 0), $kgm_c_bit, $kgm_b_bit
9929 if ($kgm_pte & 0x00000400)
9932 printf " not-shareable"
9936 if ($kgm_pte & 0x00000800)
9937 printf " not-global"
9947 # See ARM ARM Section B3.3
9948 define _pmap_walk_arm
9949 set $kgm_pmap = (pmap_t) $arg0
9950 set $kgm_vaddr = $arg1
9952 set $kgm_paddr_isvalid = 0
9954 # Shift by TTESHIFT (20) to get tte index
9955 set $kgm_tte_index = (($kgm_vaddr - $kgm_pmap->min) >> 20)
9956 set $kgm_tte_p = &$kgm_pmap->tte[$kgm_tte_index]
9957 set $kgm_tte = *$kgm_tte_p
9958 if $kgm_pt_verbose >= 2
9959 printf "first-level table (index %d):\n", $kgm_tte_index
9961 if $kgm_pt_verbose >= 3
9962 set $kgm_tte_loop = 0
9963 while $kgm_tte_loop < 4096
9964 set $kgm_tte_p_tmp = &$kgm_pmap->tte[$kgm_tte_loop]
9965 printf "0x%08x:\t0x%08x\n", (unsigned long)$kgm_tte_p_tmp, *$kgm_tte_p_tmp
9966 set $kgm_tte_loop = $kgm_tte_loop + 1
9970 if (($kgm_tte & 0x00000003) == 0x00000001)
9971 _pmap_walk_arm_level2 $kgm_tte_p $kgm_vaddr
9973 if (($kgm_tte & 0x00000003) == 0x00000002)
9974 _pmap_walk_arm_level1_section $kgm_tte_p $kgm_vaddr
9977 set $kgm_paddr_isvalid = 0
9978 if $kgm_pt_verbose >= 2
9979 printf "Invalid First-Level Translation Table Entry: 0x%08x\n", $kgm_tte
9984 if $kgm_pt_verbose >= 1
9985 if $kgm_paddr_isvalid
9986 readphysint $kgm_paddr 32 $kgm_lcpu_self
9987 set $kgm_value = $kgm_readphysint_result
9988 printf "phys 0x%016llx: 0x%08x\n", $kgm_paddr, $kgm_value
9990 printf "(no translation)\n"
9997 printf "pmap_walk <pmap> <vaddr>\n"
10000 set $kgm_pt_verbose = 2
10002 if $kgm_pt_verbose > 3
10003 set $kgm_pt_verbose = 2
10006 if (($kgm_mtype & $kgm_mtype_x86_mask) == $kgm_mtype_x86_any)
10007 _pmap_walk_x86 $arg0 $arg1
10009 if ($kgm_mtype == $kgm_mtype_arm)
10010 _pmap_walk_arm $arg0 $arg1
10012 printf "Not available for current architecture.\n"
10019 Syntax: (gdb) pmap_walk <pmap> <virtual_address>
10020 | Perform a page-table walk in <pmap> for <virtual_address>.
10022 | $kgm_pt_verbose=0 for no output, $kgm_paddr will be set
10023 | if $kgm_paddr_isvalid is 1
10024 | $kgm_pt_verbose=1 for final physical address
10025 | $kgm_pt_verbose=2 for dump of page table entry.
10026 | $kgm_pt_verbose=3 for full hex dump of page tables.
10031 printf "pmap_vtop <pamp> <vaddr>\n"
10033 set $kgm_pt_verbose = 1
10034 if (($kgm_mtype & $kgm_mtype_x86_mask) == $kgm_mtype_x86_any)
10035 _pmap_walk_x86 $arg0 $arg1
10037 if ($kgm_mtype == $kgm_mtype_arm)
10038 _pmap_walk_arm $arg0 $arg1
10040 printf "Not available for current architecture.\n"
10047 Syntax: (gdb) pmap_vtop <pmap> <virtual_address>
10048 | For page-tables in <pmap> translate <virtual_address> to physical address.
10054 if (log_records == 0)
10056 printf "Zone logging not enabled. Add 'zlog=<zone name>' to boot-args.\n"
10066 printf "\n--------------- "
10068 if (zrecords[$index].z_opcode == 1)
10073 showptr zrecords[$index].z_element
10074 printf " : index %d : ztime %d -------------\n", $index, zrecords[$index].z_time
10078 while ($frame < 15)
10079 set $frame_pc = zrecords[$index].z_pc[$frame]
10081 if ($frame_pc == 0)
10086 set $frame = $frame + 1
10089 set $index = $index + 1
10090 set $count = $count - 1
10095 Syntax: (gdb) zstack <index> [<count>]
10096 | Zone leak debugging: print the stack trace of log element at <index>.
10097 | If a <count> is supplied, it prints <count> log elements starting at <index>.
10099 | The suggested usage is to look at indexes below zcurrent and look for common stack traces.
10100 | The stack trace that occurs the most is probably the cause of the leak. Find the pc of the
10101 | function calling into zalloc and use the countpcs kgmacro to find out how often that pc occurs in the log.
10102 | The pc occuring in a high percentage of records is most likely the source of the leak.
10104 | The findoldest kgmacro is also useful for leak debugging since it identifies the oldest record
10105 | in the log, which may indicate the leaker.
10110 set $count = log_records
10111 set $cur_min = 2000000000
10114 if (log_records == 0)
10115 printf "Zone logging not enabled. Add 'zlog=<zone name>' to boot-args.\n"
10119 if (zrecords[$index].z_element && zrecords[$index].z_time < $cur_min)
10120 set $cur_index = $index
10121 set $cur_min = zrecords[$index].z_time
10124 set $count = $count - 1
10125 set $index = $index + 1
10128 printf "oldest record is at log index %d:\n", $cur_index
10133 document findoldest
10134 Syntax: (gdb) findoldest
10135 | Zone leak debugging: find and print the oldest record in the log. Note that this command
10136 | can take several minutes to run since it uses linear search.
10138 | Once it prints a stack trace, find the pc of the caller above all the zalloc, kalloc and
10139 | IOKit layers. Then use the countpcs kgmacro to see how often this caller has allocated
10140 | memory. A caller with a high percentage of records in the log is probably the leaker.
10144 set $target_pc = $arg0
10146 set $count = log_records
10149 if (log_records == 0)
10150 printf "Zone logging not enabled. Add 'zlog=<zone name>' to boot-args.\n"
10156 if (zrecords[$index].z_element != 0)
10157 while ($frame < 15)
10158 if (zrecords[$index].z_pc[$frame] == $target_pc)
10159 set $found = $found + 1
10163 set $frame = $frame + 1
10167 set $index = $index + 1
10168 set $count = $count - 1
10171 printf "occurred %d times in log (%d%c of records)\n", $found, ($found * 100) / zrecorded, '%'
10176 Syntax: (gdb) countpcs <pc>
10177 | Zone leak debugging: search the log and print a count of all log entries that contain the given <pc>
10178 | in the stack trace. This is useful for verifying a suspected <pc> as being the source of
10179 | the leak. If a high percentage of the log entries contain the given <pc>, then it's most
10180 | likely the source of the leak. Note that this command can take several minutes to run.
10184 set $fe_index = zcurrent
10185 set $fe_count = log_records
10186 set $fe_elem = $arg0
10187 set $fe_prev_op = -1
10189 if (log_records == 0)
10190 printf "Zone logging not enabled. Add 'zlog=<zone name>' to boot-args.\n"
10194 if (zrecords[$fe_index].z_element == $fe_elem)
10197 if (zrecords[$fe_index].z_opcode == $fe_prev_op)
10198 printf "*************** DOUBLE OP! *********************\n"
10201 set $fe_prev_op = zrecords[$fe_index].z_opcode
10204 set $fe_count = $fe_count - 1
10205 set $fe_index = $fe_index + 1
10207 if ($fe_index >= log_records)
10214 Syntax: (gdb) findelem <elem addr>
10215 | Zone corruption debugging: search the log and print out the stack traces for all log entries that
10216 | refer to the given zone element. When the kernel panics due to a corrupted zone element, get the
10217 | element address and use this macro. This will show you the stack traces of all logged zalloc and
10218 | zfree operations which tells you who touched the element in the recent past. This also makes
10219 | double-frees readily apparent.
10223 # This implements a shadowing scheme in kgmacros. If the
10224 # current user data can be accessed by simply changing kdp_pmap,
10225 # that is used. Otherwise, we copy data into a temporary buffer
10226 # in the kernel's address space and use that instead. Don't rely on
10227 # kdp_pmap between invocations of map/unmap. Since the shadow
10228 # codepath uses a manual KDP packet, request no more than 128 bytes.
10229 # Uses $kgm_lp64 for kernel address space size, and
10230 # $kgm_readphys_use_kdp/$kgm_readphys_force_physmap to override
10231 # how the user pages are accessed ($kgm_readphys_force_physmap
10232 # implies walking the user task's pagetables to get a physical
10233 # address and then shadowing data from there using the
10234 # physical mapping of memory).
10235 define _map_user_data_from_task
10236 set $kgm_map_user_taskp = (task_t)$arg0
10237 set $kgm_map_user_map = $kgm_map_user_taskp->map
10238 set $kgm_map_user_pmap = $kgm_map_user_map->pmap
10239 set $kgm_map_user_task_64 = ( $kgm_map_user_taskp->taskFeatures[0] & 0x80000000)
10240 set $kgm_map_user_window = 0
10241 set $kgm_map_switch_map = 0
10243 if ($kgm_readphys_force_kdp != 0)
10244 set $kgm_readphys_use_kdp = 1
10246 if ($kgm_readphys_force_physmap)
10247 set $kgm_readphys_use_kdp = 0
10249 set $kgm_readphys_use_kdp = ( kdp->is_conn > 0 )
10253 if ($kgm_readphys_use_kdp)
10256 set $kgm_map_switch_map = 1
10258 if !$kgm_map_user_task_64
10259 set $kgm_map_switch_map = 1
10263 if ($kgm_map_switch_map)
10264 # switch the map safely
10265 set $kgm_map_user_window = $arg1
10266 set kdp_pmap = $kgm_map_user_pmap
10268 # requires shadowing/copying
10270 # set up the manual KDP packet
10271 set manual_pkt.input = 0
10272 set manual_pkt.len = sizeof(kdp_readmem64_req_t)
10273 set $kgm_pkt = (kdp_readmem64_req_t *)&manual_pkt.data
10274 set $kgm_pkt->hdr.request = KDP_READMEM64
10275 set $kgm_pkt->hdr.len = sizeof(kdp_readmem64_req_t)
10276 set $kgm_pkt->hdr.is_reply = 0
10277 set $kgm_pkt->hdr.seq = 0
10278 set $kgm_pkt->hdr.key = 0
10279 set $kgm_pkt->address = (uint64_t)$arg1
10280 set $kgm_pkt->nbytes = (uint32_t)$arg2
10282 set kdp_pmap = $kgm_map_user_pmap
10283 set manual_pkt.input = 1
10284 # dummy to make sure manual packet is executed
10285 set $kgm_dummy = &_mh_execute_header
10286 # Go back to kernel map so that we can access buffer directly
10289 set $kgm_pkt = (kdp_readmem64_reply_t *)&manual_pkt.data
10290 if ($kgm_pkt->error == 0)
10291 set $kgm_map_user_window = $kgm_pkt->data
10293 set $kgm_map_user_window = 0
10298 # without the benefit of a KDP stub on the target, try to
10299 # find the user task's physical mapping and memcpy the data.
10300 # If it straddles a page boundary, copy in two passes
10301 set $kgm_vaddr_range1_start = (unsigned long long)$arg1
10302 set $kgm_vaddr_range1_count = (unsigned long long)$arg2
10303 if (($kgm_vaddr_range1_start + $kgm_vaddr_range1_count) & 0xFFF) < $kgm_vaddr_range1_count
10304 set $kgm_vaddr_range2_start = ($kgm_vaddr_range1_start + $kgm_vaddr_range1_count) & ~((unsigned long long)0xFFF)
10305 set $kgm_vaddr_range2_count = $kgm_vaddr_range1_start + $kgm_vaddr_range1_count - $kgm_vaddr_range2_start
10306 set $kgm_vaddr_range1_count = $kgm_vaddr_range2_start - $kgm_vaddr_range1_start
10308 set $kgm_vaddr_range2_start = 0
10309 set $kgm_vaddr_range2_count = 0
10311 set $kgm_paddr_range1_in_kva = 0
10312 set $kgm_paddr_range2_in_kva = 0
10314 if ($kgm_mtype == $kgm_mtype_x86_64)
10315 set $kgm_pt_verbose = 0
10316 _pmap_walk_x86 $kgm_map_user_pmap $kgm_vaddr_range1_start
10317 if $kgm_paddr_isvalid
10318 set $kgm_paddr_range1_in_kva = $kgm_paddr + physmap_base
10320 if $kgm_vaddr_range2_start
10321 _pmap_walk_x86 $kgm_map_user_pmap $kgm_vaddr_range2_start
10322 if $kgm_paddr_isvalid
10323 set $kgm_paddr_range2_in_kva = $kgm_paddr + physmap_base
10327 if ($kgm_mtype == $kgm_mtype_arm)
10328 set $kgm_pt_verbose = 0
10329 _pmap_walk_arm $kgm_map_user_pmap $kgm_vaddr_range1_start
10330 if $kgm_paddr_isvalid
10331 set $kgm_paddr_range1_in_kva = $kgm_paddr - gPhysBase + gVirtBase
10333 if $kgm_vaddr_range2_start
10334 _pmap_walk_arm $kgm_map_user_pmap $kgm_vaddr_range2_start
10335 if $kgm_paddr_isvalid
10336 set $kgm_paddr_range2_in_kva = $kgm_paddr - gPhysBase + gVirtBase
10340 printf "Not available for current architecture.\n"
10341 set $kgm_paddr_isvalid = 0
10344 if $kgm_paddr_range1_in_kva
10345 set $kgm_pkt = (kdp_readmem64_reply_t *)&manual_pkt.data
10346 memcpy $kgm_pkt->data $kgm_paddr_range1_in_kva $kgm_vaddr_range1_count
10347 if $kgm_paddr_range2_in_kva
10348 memcpy &$kgm_pkt->data[$kgm_vaddr_range1_count] $kgm_paddr_range2_in_kva $kgm_vaddr_range2_count
10350 set $kgm_map_user_window = $kgm_pkt->data
10352 set $kgm_map_user_window = 0
10357 define _unmap_user_data_from_task
10361 # uses $kgm_taskp. Maps 32 bytes at a time and prints it
10362 define _print_path_for_image
10363 set $kgm_print_path_address = (unsigned long long)$arg0
10364 set $kgm_path_str_notdone = 1
10366 if ($kgm_print_path_address == 0)
10367 set $kgm_path_str_notdone = 0
10370 while $kgm_path_str_notdone
10371 _map_user_data_from_task $kgm_taskp $kgm_print_path_address 32
10373 set $kgm_print_path_ptr = (char *)$kgm_map_user_window
10374 set $kgm_path_i = 0
10375 while ($kgm_path_i < 32 && $kgm_print_path_ptr[$kgm_path_i] != '\0')
10376 set $kgm_path_i = $kgm_path_i + 1
10378 printf "%.32s", $kgm_print_path_ptr
10380 _unmap_user_data_from_task $kgm_taskp
10382 # break out if we terminated on NUL
10383 if $kgm_path_i < 32
10384 set $kgm_path_str_notdone = 0
10386 set $kgm_print_path_address = $kgm_print_path_address + 32
10391 # uses $kgm_taskp and $kgm_task_64. May modify $kgm_dyld_load_path
10392 define _print_image_info
10393 set $kgm_mh_image_address = (unsigned long long)$arg0
10394 set $kgm_mh_path_address = (unsigned long long)$arg1
10396 # 32 bytes enough for mach_header/mach_header_64
10397 _map_user_data_from_task $kgm_taskp $kgm_mh_image_address 32
10399 set $kgm_mh_ptr = (unsigned int*)$kgm_map_user_window
10400 set $kgm_mh_magic = $kgm_mh_ptr[0]
10401 set $kgm_mh_cputype = $kgm_mh_ptr[1]
10402 set $kgm_mh_cpusubtype = $kgm_mh_ptr[2]
10403 set $kgm_mh_filetype = $kgm_mh_ptr[3]
10404 set $kgm_mh_ncmds = $kgm_mh_ptr[4]
10405 set $kgm_mh_sizeofcmds = $kgm_mh_ptr[5]
10406 set $kgm_mh_flags = $kgm_mh_ptr[6]
10408 _unmap_user_data_from_task $kgm_taskp
10410 if $kgm_mh_magic == 0xfeedfacf
10412 set $kgm_lc_address = $kgm_mh_image_address + 32
10415 set $kgm_lc_address = $kgm_mh_image_address + 28
10418 set $kgm_lc_idx = 0
10419 set $kgm_uuid_data = 0
10420 while $kgm_lc_idx < $kgm_mh_ncmds
10422 # 24 bytes is size of uuid_command
10423 _map_user_data_from_task $kgm_taskp $kgm_lc_address 24
10425 set $kgm_lc_ptr = (unsigned int *)$kgm_map_user_window
10426 set $kgm_lc_cmd = $kgm_lc_ptr[0]
10427 set $kgm_lc_cmd_size = $kgm_lc_ptr[1]
10428 set $kgm_lc_data = (unsigned char *)$kgm_lc_ptr + 8
10430 if $kgm_lc_cmd == 0x1b
10431 set $kgm_uuid_data = $kgm_lc_data
10433 printf "0x%016llx ", $kgm_mh_image_address
10435 printf "0x%08x ", $kgm_mh_image_address
10438 set $kgm_printed_type = 0
10439 if $kgm_mh_filetype == 0x2
10440 printf "MH_EXECUTE "
10441 set $kgm_printed_type = 1
10443 if $kgm_mh_filetype == 0x6
10445 set $kgm_printed_type = 1
10447 if $kgm_mh_filetype == 0x7
10448 printf "MH_DYLINKER "
10449 set $kgm_printed_type = 1
10451 if $kgm_mh_filetype == 0x8
10452 printf "MH_BUNDLE "
10453 set $kgm_printed_type = 1
10455 if !$kgm_printed_type
10458 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]
10459 printf "%02.2X%02.2X-", $kgm_uuid_data[4], $kgm_uuid_data[5]
10460 printf "%02.2X%02.2X-", $kgm_uuid_data[6], $kgm_uuid_data[7]
10461 printf "%02.2X%02.2X-", $kgm_uuid_data[8], $kgm_uuid_data[9]
10462 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]
10464 _unmap_user_data_from_task $kgm_taskp
10467 _print_path_for_image $kgm_mh_path_address
10472 if $kgm_lc_cmd == 0xe
10473 set $kgm_load_dylinker_data = $kgm_lc_data
10474 set $kgm_dyld_load_path = $kgm_lc_address + *((unsigned int *)$kgm_load_dylinker_data)
10476 _unmap_user_data_from_task $kgm_taskp
10479 set $kgm_lc_address = $kgm_lc_address + $kgm_lc_cmd_size
10480 set $kgm_lc_idx = $kgm_lc_idx + 1
10483 if (!$kgm_uuid_data)
10484 # didn't find LC_UUID, for a dylib, just print out basic info
10486 printf "0x%016llx ", $kgm_mh_image_address
10488 printf "0x%08x ", $kgm_mh_image_address
10490 set $kgm_printed_type = 0
10491 if $kgm_mh_filetype == 0x2
10492 printf "MH_EXECUTE "
10493 set $kgm_printed_type = 1
10495 if $kgm_mh_filetype == 0x6
10497 set $kgm_printed_type = 1
10499 if $kgm_mh_filetype == 0x7
10500 printf "MH_DYLINKER "
10501 set $kgm_printed_type = 1
10503 if $kgm_mh_filetype == 0x8
10504 printf "MH_BUNDLE "
10505 set $kgm_printed_type = 1
10507 if !$kgm_printed_type
10513 _print_path_for_image $kgm_mh_path_address
10520 define _print_images_for_dyld_image_info
10521 set $kgm_taskp = $arg0
10522 set $kgm_task_64 = $arg1
10523 set $kgm_dyld_all_image_infos_address = (unsigned long long)$arg2
10525 _map_user_data_from_task $kgm_taskp $kgm_dyld_all_image_infos_address 112
10527 set $kgm_dyld_all_image_infos = (unsigned int *)$kgm_map_user_window
10528 set $kgm_dyld_all_image_infos_version = $kgm_dyld_all_image_infos[0]
10529 if ($kgm_dyld_all_image_infos_version > 12)
10530 printf "Unknown dyld all_image_infos version number %d\n", $kgm_dyld_all_image_infos_version
10532 set $kgm_image_info_count = $kgm_dyld_all_image_infos[1]
10534 set $kgm_dyld_load_path = 0
10536 set $kgm_image_info_size = 24
10537 set $kgm_image_info_array_address = ((unsigned long long *)$kgm_dyld_all_image_infos)[1]
10538 set $kgm_dyld_load_address = ((unsigned long long *)$kgm_dyld_all_image_infos)[4]
10539 set $kgm_dyld_all_image_infos_address_from_struct = ((unsigned long long *)$kgm_dyld_all_image_infos)[13]
10541 set $kgm_image_info_size = 12
10542 set $kgm_image_info_array_address = ((unsigned int *)$kgm_dyld_all_image_infos)[2]
10543 set $kgm_dyld_load_address = ((unsigned int *)$kgm_dyld_all_image_infos)[5]
10544 set $kgm_dyld_all_image_infos_address_from_struct = ((unsigned int *)$kgm_dyld_all_image_infos)[14]
10547 _unmap_user_data_from_task $kgm_taskp
10549 # Account for ASLR slide before dyld can fix the structure
10550 set $kgm_dyld_load_address = $kgm_dyld_load_address + ($kgm_dyld_all_image_infos_address - $kgm_dyld_all_image_infos_address_from_struct)
10552 set $kgm_image_info_i = 0
10553 while $kgm_image_info_i < $kgm_image_info_count
10555 set $kgm_image_info_address = $kgm_image_info_array_address + $kgm_image_info_size*$kgm_image_info_i
10557 _map_user_data_from_task $kgm_taskp $kgm_image_info_address $kgm_image_info_size
10559 set $kgm_image_info_addr = ((unsigned long long *)$kgm_map_user_window)[0]
10560 set $kgm_image_info_path = ((unsigned long long *)$kgm_map_user_window)[1]
10562 set $kgm_image_info_addr = ((unsigned int *)$kgm_map_user_window)[0]
10563 set $kgm_image_info_path = ((unsigned int *)$kgm_map_user_window)[1]
10565 _unmap_user_data_from_task $kgm_taskp
10567 # printf "[%d] = image address %llx path address %llx\n", $kgm_image_info_i, $kgm_image_info_addr, $kgm_image_info_path
10568 _print_image_info $kgm_image_info_addr $kgm_image_info_path
10570 set $kgm_image_info_i = $kgm_image_info_i + 1
10573 # $kgm_dyld_load_path may get set when the main executable is processed
10574 # printf "[dyld] = image address %llx path address %llx\n", $kgm_dyld_load_address, $kgm_dyld_load_path
10575 _print_image_info $kgm_dyld_load_address $kgm_dyld_load_path
10579 define showuserlibraries
10580 set $kgm_taskp = (task_t)$arg0
10581 set $kgm_dyld_image_info = $kgm_taskp->all_image_info_addr
10583 set $kgm_map = $kgm_taskp->map
10584 set $kgm_task_64 = ( $kgm_taskp->taskFeatures[0] & 0x80000000)
10586 if ($kgm_dyld_image_info != 0)
10595 _print_images_for_dyld_image_info $kgm_taskp $kgm_task_64 $kgm_dyld_image_info
10597 printf "No dyld shared library information available for task\n"
10600 document showuserlibraries
10601 Syntax: (gdb) showuserlibraries <task_t>
10602 | For a given user task, inspect the dyld shared library state and print
10603 | information about all Mach-O images.
10606 define showuserdyldinfo
10607 set $kgm_taskp = (task_t)$arg0
10608 set $kgm_dyld_all_image_infos_address = (unsigned long long)$kgm_taskp->all_image_info_addr
10610 set $kgm_map = $kgm_taskp->map
10611 set $kgm_task_64 = ( $kgm_taskp->taskFeatures[0] & 0x80000000)
10613 if ($kgm_dyld_all_image_infos_address != 0)
10615 _map_user_data_from_task $kgm_taskp $kgm_dyld_all_image_infos_address 112
10617 set $kgm_dyld_all_image_infos = (unsigned char *)$kgm_map_user_window
10618 set $kgm_dyld_all_image_infos_version = ((unsigned int *)$kgm_dyld_all_image_infos)[0]
10619 if ($kgm_dyld_all_image_infos_version > 12)
10620 printf "Unknown dyld all_image_infos version number %d\n", $kgm_dyld_all_image_infos_version
10623 # Find fields by byte offset. We assume at least version 9 is supported
10625 set $kgm_dyld_all_image_infos_infoArrayCount = *(unsigned int *)(&$kgm_dyld_all_image_infos[4])
10626 set $kgm_dyld_all_image_infos_infoArray = *(unsigned long long *)(&$kgm_dyld_all_image_infos[8])
10627 set $kgm_dyld_all_image_infos_notification = *(unsigned long long *)(&$kgm_dyld_all_image_infos[16])
10628 set $kgm_dyld_all_image_infos_processDetachedFromSharedRegion = *(unsigned char *)(&$kgm_dyld_all_image_infos[24])
10629 set $kgm_dyld_all_image_infos_libSystemInitialized = *(unsigned char *)(&$kgm_dyld_all_image_infos[25])
10630 set $kgm_dyld_all_image_infos_dyldImageLoadAddress = *(unsigned long long *)(&$kgm_dyld_all_image_infos[32])
10631 set $kgm_dyld_all_image_infos_jitInfo = *(unsigned long long *)(&$kgm_dyld_all_image_infos[40])
10632 set $kgm_dyld_all_image_infos_dyldVersion = *(unsigned long long *)(&$kgm_dyld_all_image_infos[48])
10633 set $kgm_dyld_all_image_infos_errorMessage = *(unsigned long long *)(&$kgm_dyld_all_image_infos[56])
10634 set $kgm_dyld_all_image_infos_terminationFlags = *(unsigned long long *)(&$kgm_dyld_all_image_infos[64])
10635 set $kgm_dyld_all_image_infos_coreSymbolicationShmPage = *(unsigned long long *)(&$kgm_dyld_all_image_infos[72])
10636 set $kgm_dyld_all_image_infos_systemOrderFlag = *(unsigned long long *)(&$kgm_dyld_all_image_infos[80])
10637 set $kgm_dyld_all_image_infos_uuidArrayCount = *(unsigned long long *)(&$kgm_dyld_all_image_infos[88])
10638 set $kgm_dyld_all_image_infos_uuidArray = *(unsigned long long *)(&$kgm_dyld_all_image_infos[96])
10639 set $kgm_dyld_all_image_infos_dyldAllImageInfosAddress = *(unsigned long long *)(&$kgm_dyld_all_image_infos[104])
10641 set $kgm_dyld_all_image_infos_infoArrayCount = *(unsigned int *)(&$kgm_dyld_all_image_infos[4])
10642 set $kgm_dyld_all_image_infos_infoArray = *(unsigned int *)(&$kgm_dyld_all_image_infos[8])
10643 set $kgm_dyld_all_image_infos_notification = *(unsigned int *)(&$kgm_dyld_all_image_infos[12])
10644 set $kgm_dyld_all_image_infos_processDetachedFromSharedRegion = *(unsigned char *)(&$kgm_dyld_all_image_infos[16])
10645 set $kgm_dyld_all_image_infos_libSystemInitialized = *(unsigned char *)(&$kgm_dyld_all_image_infos[17])
10646 set $kgm_dyld_all_image_infos_dyldImageLoadAddress = *(unsigned int *)(&$kgm_dyld_all_image_infos[20])
10647 set $kgm_dyld_all_image_infos_jitInfo = *(unsigned int *)(&$kgm_dyld_all_image_infos[24])
10648 set $kgm_dyld_all_image_infos_dyldVersion = *(unsigned int *)(&$kgm_dyld_all_image_infos[28])
10649 set $kgm_dyld_all_image_infos_errorMessage = *(unsigned int *)(&$kgm_dyld_all_image_infos[32])
10650 set $kgm_dyld_all_image_infos_terminationFlags = *(unsigned int *)(&$kgm_dyld_all_image_infos[36])
10651 set $kgm_dyld_all_image_infos_coreSymbolicationShmPage = *(unsigned int *)(&$kgm_dyld_all_image_infos[40])
10652 set $kgm_dyld_all_image_infos_systemOrderFlag = *(unsigned int *)(&$kgm_dyld_all_image_infos[44])
10653 set $kgm_dyld_all_image_infos_uuidArrayCount = *(unsigned int *)(&$kgm_dyld_all_image_infos[48])
10654 set $kgm_dyld_all_image_infos_uuidArray = *(unsigned int *)(&$kgm_dyld_all_image_infos[52])
10655 set $kgm_dyld_all_image_infos_dyldAllImageInfosAddress = *(unsigned int *)(&$kgm_dyld_all_image_infos[56])
10658 _unmap_user_data_from_task $kgm_taskp
10660 set $kgm_dyld_all_imfo_infos_slide = ( $kgm_dyld_all_image_infos_address - $kgm_dyld_all_image_infos_dyldAllImageInfosAddress )
10661 set $kgm_dyld_all_image_infos_dyldVersion_postslide = ( $kgm_dyld_all_image_infos_dyldVersion + $kgm_dyld_all_imfo_infos_slide )
10663 printf " version %u\n", $kgm_dyld_all_image_infos_version
10664 printf " infoArrayCount %u\n", $kgm_dyld_all_image_infos_infoArrayCount
10665 printf " infoArray "
10666 showuserptr $kgm_dyld_all_image_infos_infoArray
10668 printf " notification "
10669 showuserptr $kgm_dyld_all_image_infos_notification
10671 printf "processDetachedFromSharedRegion %d\n", $kgm_dyld_all_image_infos_processDetachedFromSharedRegion
10672 printf " libSystemInitialized %d\n", $kgm_dyld_all_image_infos_libSystemInitialized
10673 printf " dyldImageLoadAddress "
10674 showuserptr $kgm_dyld_all_image_infos_dyldImageLoadAddress
10677 showuserptr $kgm_dyld_all_image_infos_jitInfo
10679 printf " dyldVersion "
10680 showuserptr $kgm_dyld_all_image_infos_dyldVersion
10683 _print_path_for_image $kgm_dyld_all_image_infos_dyldVersion_postslide
10684 if ($kgm_dyld_all_imfo_infos_slide != 0)
10685 printf " (currently "
10686 showuserptr $kgm_dyld_all_image_infos_dyldVersion_postslide
10691 printf " errorMessage "
10692 showuserptr $kgm_dyld_all_image_infos_errorMessage
10694 if $kgm_dyld_all_image_infos_errorMessage != 0
10696 _print_path_for_image $kgm_dyld_all_image_infos_errorMessage
10700 printf " terminationFlags "
10701 showuserptr $kgm_dyld_all_image_infos_terminationFlags
10703 printf " coreSymbolicationShmPage "
10704 showuserptr $kgm_dyld_all_image_infos_coreSymbolicationShmPage
10706 printf " systemOrderFlag "
10707 showuserptr $kgm_dyld_all_image_infos_systemOrderFlag
10709 printf " uuidArrayCount "
10710 showuserptr $kgm_dyld_all_image_infos_uuidArrayCount
10712 printf " uuidArray "
10713 showuserptr $kgm_dyld_all_image_infos_uuidArray
10715 printf " dyldAllImageInfosAddress "
10716 showuserptr $kgm_dyld_all_image_infos_dyldAllImageInfosAddress
10718 printf " (currently "
10719 showuserptr $kgm_dyld_all_image_infos_address
10723 set $kgm_dyld_all_image_infos_address = $kgm_dyld_all_image_infos_address + 112
10724 _map_user_data_from_task $kgm_taskp $kgm_dyld_all_image_infos_address 64
10725 set $kgm_dyld_all_image_infos_v10 = (unsigned char *)$kgm_map_user_window
10726 set $kgm_dyld_all_image_infos_initialImageCount = *(unsigned long long *)(&$kgm_dyld_all_image_infos_v10[112-112])
10727 set $kgm_dyld_all_image_infos_errorKind = *(unsigned long long *)(&$kgm_dyld_all_image_infos_v10[120-112])
10728 set $kgm_dyld_all_image_infos_errorClientOfDylibPath = *(unsigned long long *)(&$kgm_dyld_all_image_infos_v10[128-112])
10729 set $kgm_dyld_all_image_infos_errorTargetDylibPath = *(unsigned long long *)(&$kgm_dyld_all_image_infos_v10[136-112])
10730 set $kgm_dyld_all_image_infos_errorSymbol = *(unsigned long long *)(&$kgm_dyld_all_image_infos_v10[144-112])
10731 set $kgm_dyld_all_image_infos_sharedCacheSlide = *(unsigned long long *)(&$kgm_dyld_all_image_infos_v10[152-112])
10733 _unmap_user_data_from_task $kgm_taskp
10735 set $kgm_dyld_all_image_infos_address = $kgm_dyld_all_image_infos_address + 60
10736 _map_user_data_from_task $kgm_taskp $kgm_dyld_all_image_infos_address 64
10737 set $kgm_dyld_all_image_infos_v10 = (unsigned char *)$kgm_map_user_window
10738 set $kgm_dyld_all_image_infos_initialImageCount = *(unsigned int *)(&$kgm_dyld_all_image_infos_v10[60-60])
10739 set $kgm_dyld_all_image_infos_errorKind = *(unsigned int *)(&$kgm_dyld_all_image_infos_v10[64-60])
10740 set $kgm_dyld_all_image_infos_errorClientOfDylibPath = *(unsigned int *)(&$kgm_dyld_all_image_infos_v10[68-60])
10741 set $kgm_dyld_all_image_infos_errorTargetDylibPath = *(unsigned int *)(&$kgm_dyld_all_image_infos_v10[72-60])
10742 set $kgm_dyld_all_image_infos_errorSymbol = *(unsigned int *)(&$kgm_dyld_all_image_infos_v10[76-60])
10743 set $kgm_dyld_all_image_infos_sharedCacheSlide = *(unsigned int *)(&$kgm_dyld_all_image_infos_v10[80-60])
10744 _unmap_user_data_from_task $kgm_taskp
10747 if $kgm_dyld_all_image_infos_version >= 10
10748 printf " initialImageCount "
10749 showuserptr $kgm_dyld_all_image_infos_initialImageCount
10753 if $kgm_dyld_all_image_infos_version >= 11
10754 printf " errorKind "
10755 showuserptr $kgm_dyld_all_image_infos_errorKind
10757 printf " errorClientOfDylibPath "
10758 showuserptr $kgm_dyld_all_image_infos_errorClientOfDylibPath
10760 if $kgm_dyld_all_image_infos_errorClientOfDylibPath != 0
10762 _print_path_for_image $kgm_dyld_all_image_infos_errorClientOfDylibPath
10765 printf " errorTargetDylibPath "
10766 showuserptr $kgm_dyld_all_image_infos_errorTargetDylibPath
10768 if $kgm_dyld_all_image_infos_errorTargetDylibPath != 0
10770 _print_path_for_image $kgm_dyld_all_image_infos_errorTargetDylibPath
10773 printf " errorSymbol "
10774 showuserptr $kgm_dyld_all_image_infos_errorSymbol
10776 if $kgm_dyld_all_image_infos_errorSymbol != 0
10778 _print_path_for_image $kgm_dyld_all_image_infos_errorSymbol
10783 if $kgm_dyld_all_image_infos_version >= 12
10784 printf " sharedCacheSlide "
10785 showuserptr $kgm_dyld_all_image_infos_sharedCacheSlide
10790 printf "No dyld information available for task\n"
10793 document showuserdyldinfo
10794 Syntax: (gdb) showuserdyldinfo <task_t>
10795 | For a given user task, inspect the dyld global info and print
10796 | out all fields, including error messages.
10799 define showkerneldebugheader
10802 printf "CPU Thread "
10804 printf "Timestamp S/E Class Sub Code Code Specific Info\n"
10807 define _printevflags
10822 printf "EV_RBYTES "
10825 printf "EV_WBYTES "
10828 printf "EV_RCLOSED "
10834 printf "EV_WCLOSED "
10849 printf "EV_TIMEOUT "
10853 define showkerneldebugbufferentry
10854 set $kgm_kdebug_entry = (kd_buf *) $arg0
10856 set $kgm_debugid = $kgm_kdebug_entry->debugid
10857 set $kgm_kdebug_arg1 = $kgm_kdebug_entry->arg1
10858 set $kgm_kdebug_arg2 = $kgm_kdebug_entry->arg2
10859 set $kgm_kdebug_arg3 = $kgm_kdebug_entry->arg3
10860 set $kgm_kdebug_arg4 = $kgm_kdebug_entry->arg4
10863 set $kgm_kdebug_cpu = $kgm_kdebug_entry->cpuid
10864 set $kgm_ts_hi = ($kgm_kdebug_entry->timestamp >> 32) & 0xFFFFFFFF
10865 set $kgm_ts_lo = $kgm_kdebug_entry->timestamp & 0xFFFFFFFF
10867 set $kgm_kdebug_cpu = ($kgm_kdebug_entry->timestamp >> 56)
10868 set $kgm_ts_hi = ($kgm_kdebug_entry->timestamp >> 32) & 0x00FFFFFF
10869 set $kgm_ts_lo = $kgm_kdebug_entry->timestamp & 0xFFFFFFFF
10872 set $kgm_kdebug_class = ($kgm_debugid >> 24) & 0x000FF
10873 set $kgm_kdebug_subclass = ($kgm_debugid >> 16) & 0x000FF
10874 set $kgm_kdebug_code = ($kgm_debugid >> 2) & 0x03FFF
10875 set $kgm_kdebug_qual = ($kgm_debugid ) & 0x00003
10877 if $kgm_kdebug_qual == 0
10878 set $kgm_kdebug_qual = '-'
10880 if $kgm_kdebug_qual == 1
10881 set $kgm_kdebug_qual = 'S'
10883 if $kgm_kdebug_qual == 2
10884 set $kgm_kdebug_qual = 'E'
10886 if $kgm_kdebug_qual == 3
10887 set $kgm_kdebug_qual = '?'
10893 # preamble and qual
10895 showptr $kgm_kdebug_entry
10896 printf " %d ", $kgm_kdebug_cpu
10897 showptr $kgm_kdebug_entry->arg5
10898 printf " 0x%08X%08X %c ", $kgm_ts_hi, $kgm_ts_lo, $kgm_kdebug_qual
10902 if $kgm_kdebug_class == 1
10905 if $kgm_kdebug_class == 2
10908 if $kgm_kdebug_class == 3
10911 if $kgm_kdebug_class == 4
10914 if $kgm_kdebug_class == 5
10917 if $kgm_kdebug_class == 6
10920 if $kgm_kdebug_class == 7
10923 if $kgm_kdebug_class == 8
10926 if $kgm_kdebug_class == 8
10929 if $kgm_kdebug_class == 20
10932 if $kgm_kdebug_class == 31
10935 if $kgm_kdebug_class == 32
10938 if $kgm_kdebug_class == 33
10941 if $kgm_kdebug_class == 255
10944 printf "0x%02X", $kgm_kdebug_class
10960 # subclass and code
10962 printf " 0x%02X %5d ", $kgm_kdebug_subclass, $kgm_kdebug_code
10964 # space for debugid-specific processing
10966 # EVPROC from bsd/kern/sys_generic.c
10968 # MISCDBG_CODE(DBG_EVENT,DBG_WAIT)
10969 if $kgm_debugid == 0x14100048
10970 printf "waitevent "
10971 if $kgm_kdebug_arg1 == 1
10972 printf "before sleep"
10974 if $kgm_kdebug_arg1 == 2
10975 printf "after sleep"
10977 printf "????????????"
10980 printf " chan=0x%08X ", $kgm_kdebug_arg2
10982 # MISCDBG_CODE(DBG_EVENT,DBG_WAIT|DBG_FUNC_START)
10983 if $kgm_debugid == 0x14100049
10984 printf "waitevent "
10986 # MISCDBG_CODE(DBG_EVENT,DBG_WAIT|DBG_FUNC_END)
10987 if $kgm_debugid == 0x1410004a
10988 printf "waitevent error=%d ", $kgm_kdebug_arg1
10989 printf "eqp=0x%08X ", $kgm_kdebug_arg4
10990 _printevflags $kgm_kdebug_arg3
10991 printf "er_handle=%d ", $kgm_kdebug_arg2
10993 # MISCDBG_CODE(DBG_EVENT,DBG_DEQUEUE|DBG_FUNC_START)
10994 if $kgm_debugid == 0x14100059
10995 printf "evprocdeque proc=0x%08X ", $kgm_kdebug_arg1
10996 if $kgm_kdebug_arg2 == 0
10997 printf "remove first "
10999 printf "remove 0x%08X ", $kgm_kdebug_arg2
11002 # MISCDBG_CODE(DBG_EVENT,DBG_DEQUEUE|DBG_FUNC_END)
11003 if $kgm_debugid == 0x1410005a
11004 printf "evprocdeque "
11005 if $kgm_kdebug_arg1 == 0
11006 printf "result=NULL "
11008 printf "result=0x%08X ", $kgm_kdebug_arg1
11011 # MISCDBG_CODE(DBG_EVENT,DBG_POST|DBG_FUNC_START)
11012 if $kgm_debugid == 0x14100041
11013 printf "postevent "
11014 _printevflags $kgm_kdebug_arg1
11016 # MISCDBG_CODE(DBG_EVENT,DBG_POST)
11017 if $kgm_debugid == 0x14100040
11018 printf "postevent "
11019 printf "evq=0x%08X ", $kgm_kdebug_arg1
11020 printf "er_eventbits="
11021 _printevflags $kgm_kdebug_arg2
11023 _printevflags $kgm_kdebug_arg3
11025 # MISCDBG_CODE(DBG_EVENT,DBG_POST|DBG_FUNC_END)
11026 if $kgm_debugid == 0x14100042
11027 printf "postevent "
11029 # MISCDBG_CODE(DBG_EVENT,DBG_ENQUEUE|DBG_FUNC_START)
11030 if $kgm_debugid == 0x14100055
11031 printf "evprocenque eqp=0x%08d ", $kgm_kdebug_arg1
11032 if $kgm_kdebug_arg2 & 1
11033 printf "EV_QUEUED "
11035 _printevflags $kgm_kdebug_arg3
11038 # MISCDBG_CODE(DBG_EVENT,DBG_EWAKEUP)
11039 if $kgm_debugid == 0x14100050
11040 printf "evprocenque before wakeup eqp=0x%08d ", $kgm_kdebug_arg4
11042 # MISCDBG_CODE(DBG_EVENT,DBG_ENQUEUE|DBG_FUNC_END)
11043 if $kgm_debugid == 0x14100056
11044 printf "evprocenque "
11046 # MISCDBG_CODE(DBG_EVENT,DBG_MOD|DBG_FUNC_START)
11047 if $kgm_debugid == 0x1410004d
11050 # MISCDBG_CODE(DBG_EVENT,DBG_MOD)
11051 if $kgm_debugid == 0x1410004c
11052 printf "modwatch er_handle=%d ", $kgm_kdebug_arg1
11053 _printevflags $kgm_kdebug_arg2
11054 printf "evq=0x%08X ", $kgm_kdebug_arg3
11056 # MISCDBG_CODE(DBG_EVENT,DBG_MOD|DBG_FUNC_END)
11057 if $kgm_debugid == 0x1410004e
11058 printf "modwatch er_handle=%d ", $kgm_kdebug_arg1
11059 printf "ee_eventmask="
11060 _printevflags $kgm_kdebug_arg2
11061 printf "sp=0x%08X ", $kgm_kdebug_arg3
11063 _printevflags $kgm_kdebug_arg4
11065 printf "arg1=0x%08X ", $kgm_kdebug_arg1
11066 printf "arg2=0x%08X ", $kgm_kdebug_arg2
11067 printf "arg3=0x%08X ", $kgm_kdebug_arg3
11068 printf "arg4=0x%08X ", $kgm_kdebug_arg4
11089 define showkerneldebugbuffercpu
11090 set $kgm_cpu_number = (int) $arg0
11091 set $kgm_entry_count = (int) $arg1
11092 set $kgm_debugentriesfound = 0
11093 # 0x80000000 == KDBG_BFINIT
11094 if (kd_ctrl_page.kdebug_flags & 0x80000000)
11095 showkerneldebugheader
11097 if $kgm_entry_count == 0
11098 printf "<count> is 0, dumping 50 entries\n"
11099 set $kgm_entry_count = 50
11102 if $kgm_cpu_number >= kd_cpus
11103 printf "cpu number too big\n"
11105 set $kgm_kdbp = &kdbip[$kgm_cpu_number]
11106 set $kgm_kdsp = $kgm_kdbp->kd_list_head
11107 while (($kgm_kdsp.raw != 0) && ($kgm_entry_count > 0))
11108 set $kgm_kdsp_actual = &kd_bufs[$kgm_kdsp.buffer_index].kdsb_addr[$kgm_kdsp.offset]
11109 if $kgm_kdsp_actual->kds_readlast != $kgm_kdsp_actual->kds_bufindx
11110 set $kgm_kds_bufptr = &$kgm_kdsp_actual->kds_records[$kgm_kdsp_actual->kds_bufindx]
11111 while (($kgm_kds_bufptr > &$kgm_kdsp_actual->kds_records[$kgm_kdsp_actual->kds_readlast]) && ($kgm_entry_count > 0))
11112 set $kgm_kds_bufptr = $kgm_kds_bufptr - 1
11113 set $kgm_entry_count = $kgm_entry_count - 1
11114 showkerneldebugbufferentry $kgm_kds_bufptr
11117 set $kgm_kdsp = $kgm_kdsp_actual->kds_next
11121 printf "Trace buffer not enabled\n"
11125 document showkerneldebugbuffercpu
11126 Syntax: showkerneldebugbuffercpu <cpu> <count>
11127 | Prints the last N entries in the kernel debug buffer for CPU x.
11130 define showkerneldebugbuffer
11131 # 0x80000000 == KDBG_BFINIT
11132 if (kd_ctrl_page.kdebug_flags & 0x80000000)
11134 set $kgm_entrycount = (int) $arg0
11136 if $kgm_entrycount == 0
11137 printf "<count> is 0, dumping 50 entries per cpu\n"
11138 set $kgm_entrycount = 50
11141 set $kgm_cpu = (int) 0
11143 while $kgm_cpu < kd_cpus
11144 showkerneldebugbuffercpu $kgm_cpu $kgm_entrycount
11145 set $kgm_cpu = $kgm_cpu + 1
11148 printf "Trace buffer not enabled\n"
11152 document showkerneldebugbuffer
11153 Syntax: showkerneldebugbuffer <count>
11154 | Prints the last N entries in the kernel debug buffer per cpu. i.e. showkerneldebugbuffer 50 will
11155 | display the last 50 entries in each CPU's debug buffer.
11158 define showallvmstats
11159 printf " pid command #ents wired vsize rsize max rsize\n"
11160 printf " (pages) (pages) (pages) (pages)\n"
11161 set $kgm_head_taskp = &tasks
11162 set $kgm_taskp = (struct task *)($kgm_head_taskp->next)
11163 while $kgm_taskp != $kgm_head_taskp
11164 set $kgm_procp = (struct proc *)($kgm_taskp->bsd_info)
11165 set $kgm_mapp = (struct _vm_map *)($kgm_taskp->map)
11166 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
11167 set $kgm_taskp = (struct task *)($kgm_taskp->tasks.next)
11171 document showallvmstats
11172 Syntax: showallvmstats
11173 | prints a summary of vm statistics in a table format
11177 if ($kgm_mtype == $kgm_mtype_arm)
11178 printf "kern_memorystatus_level: %8d\n", kern_memorystatus_level
11180 printf "vm_page_throttled_count: %8d\n", vm_page_throttled_count
11181 printf "vm_page_active_count: %8d\n", vm_page_active_count
11182 printf "vm_page_inactive_count: %8d\n", vm_page_inactive_count
11183 printf "vm_page_wire_count: %8d\n", vm_page_wire_count
11184 printf "vm_page_free_count: %8d\n", vm_page_free_count
11185 printf "vm_page_purgeable_count: %8d\n", vm_page_purgeable_count
11186 printf "vm_page_inactive_target: %8d\n", vm_page_inactive_target
11187 printf "vm_page_free_target: %8d\n", vm_page_free_target
11188 printf "inuse_ptepages_count: %8d\n", inuse_ptepages_count
11189 printf "vm_page_free_reserved: %8d\n", vm_page_free_reserved
11193 Syntax: (gdb) memstats
11194 | Prints out a summary of various memory statistics. In particular vm_page_wire_count should
11195 | be greater than 2K or you are under memory pressure.
11198 define show_user_registers
11199 showuserregisters $arg0
11202 document show_user_registers
11203 Syntax: show_user_registers <thread_address>
11204 | Display user registers associated with a kernel thread
11205 | properly displays the 32 bit or 64 bit registers for intel architecture
11212 # check for end of string. cmp0 can be longer than cmp1. it
11213 # can't be shorter.
11215 set $kgm_strcmp_result = 0
11216 set $kgm_strcmp_done = 1
11219 if !$kgm_strcmp_done && $cmp0 == '\0'
11220 set $kgm_strcmp_result = -1
11221 set $kgm_strcmp_done = 1
11225 if !$kgm_strcmp_done
11226 set $kgm_strcmp_result = (uint8_t) $cmp0 - (uint8_t) $cmp1
11227 if $kgm_strcmp_result != 0
11228 set $kgm_strcmp_done = 1
11235 set $masked = $cmp & 0xFF
11236 _cmp $arg0[0] $masked
11238 if !$kgm_strcmp_done
11239 set $cmp = $cmp >> 8
11240 set $masked = $cmp & 0xFF
11241 _cmp $arg0[1] $masked
11243 if !$kgm_strcmp_done
11244 set $cmp = $cmp >> 8
11245 set $masked = $cmp & 0xFF
11246 _cmp $arg0[2] $masked
11248 if !$kgm_strcmp_done
11249 set $cmp = $cmp >> 8
11250 set $masked = $cmp & 0xFF
11251 _cmp $arg0[3] $masked
11253 if !$kgm_strcmp_done
11254 set $cmp = $cmp >> 8
11255 set $masked = $cmp & 0xFF
11256 _cmp $arg0[4] $masked
11258 if !$kgm_strcmp_done
11259 set $cmp = $cmp >> 8
11260 set $masked = $cmp & 0xFF
11261 _cmp $arg0[5] $masked
11263 if !$kgm_strcmp_done
11264 set $cmp = $cmp >> 8
11265 set $masked = $cmp & 0xFF
11266 _cmp $arg0[6] $masked
11268 if !$kgm_strcmp_done
11269 set $cmp = $cmp >> 8
11270 set $masked = $cmp & 0xFF
11271 _cmp $arg0[7] $masked
11275 define strcmp_arg_pack64
11276 set $kgm_strcmp_arg = ((((((((((((((uint64_t) $arg7 << 8) | $arg6) << 8) | $arg5) << 8) | $arg4) << 8) | $arg3) << 8) | $arg2) << 8) | $arg1) << 8) | $arg0
11279 document strcmp_arg_pack64
11280 Syntax: strcmp_arg_pack64 <a> <b> <c> <d> <e <f> <g> <h>
11281 | Packs a string given as 8 character arguments into a 64-bit int stored in
11282 | $kgm_strcmp_arg. Use 0 or '\0' for unused arguments. The encoded string
11283 | is suitable for use by strcmp_nomalloc and setfindregistrystr.
11284 | e.g., strcmp_arg_pack64 'H' 'e' 'l' 'l' 'o' 0 0 0
11285 | packs "Hello" into $kgm_strcmp_arg.
11289 define strcmp_nomalloc
11291 set $count = $argc - 1
11293 set $kgm_strcmp_result = 0
11294 set $kgm_strcmp_done = 0
11297 _cmp_arg64 $str $arg1
11299 if !$kgm_strcmp_done && $count > 1
11300 set $str = $str + 8
11301 _cmp_arg64 $str $arg2
11303 if !$kgm_strcmp_done && $count > 2
11304 set $str = $str + 8
11305 _cmp_arg64 $str $arg3
11307 if !$kgm_strcmp_done && $count > 3
11308 set $str = $str + 8
11309 _cmp_arg64 $str $arg4
11311 if !$kgm_strcmp_done && $count > 4
11312 set $str = $str + 8
11313 _cmp_arg64 $str $arg5
11315 if !$kgm_strcmp_done && $count > 5
11316 set $str = $str + 8
11317 _cmp_arg64 $str $arg6
11319 if !$kgm_strcmp_done && $count > 6
11320 set $str = $str + 8
11321 _cmp_arg64 $str $arg7
11323 if !$kgm_strcmp_done && $count > 7
11324 set $str = $str + 8
11325 _cmp_arg64 $str $arg8
11327 if !$kgm_strcmp_done && $count > 8
11328 set $str = $str + 8
11329 _cmp_arg64 $str $arg9
11333 document strcmp_nomalloc
11334 Syntax: strcmp_nomalloc <string> <a> [b] [c] [d] [e] [f] [g] [h] [i]
11335 | Given a pre-allocated <string>, perform a string compare with the
11336 | encoded string stored in arguments a - i. The result is stored in
11337 | $kgm_strcmp_result.
11339 | For example, the following will result in $kgm_strcmp_result == 0:
11340 | strcmp_arg_pack64 'D' 'a' 'r' 'w' 'i' 'n' ' ' 'K'
11341 | strcmp_nomalloc version $kgm_strcmp_arg
11345 set $kgm_dst = (unsigned char *)$arg0
11346 set $kgm_src = (unsigned char *)$arg1
11347 set $kgm_count = $arg2
11349 # printf "src %p dst %p len %d\n", $kgm_src, $kgm_dst, $kgm_count
11351 while ($kgm_count >= 8)
11352 set *(unsigned long long *)$kgm_dst = *(unsigned long long *)$kgm_src
11354 set $kgm_dst = $kgm_dst + 8
11355 set $kgm_src = $kgm_src + 8
11356 set $kgm_count = $kgm_count - 8
11358 while ($kgm_count > 0)
11359 set *$kgm_dst = *$kgm_src
11361 set $kgm_dst = $kgm_dst + 1
11362 set $kgm_src = $kgm_src + 1
11363 set $kgm_count = $kgm_count - 1
11368 Syntax: memcpy <dst> <src> <n>
11369 | Given two addresses that are accessible by the debugger, perform
11370 | a memory copy of <n> bytes from <src> to <dst>
11373 # _pci_cfg_addr_value $addr $size
11374 define _pci_cfg_addr_value
11375 readphysint $arg0 $arg1 $kgm_lcpu_self
11376 set $kgm_pci_cfg_value = $kgm_readphysint_result
11380 set $kgm_pci_cfg_init = 0
11381 define _pci_cfg_init
11382 # get this from the registry if it exists there
11383 if $kgm_pci_cfg_init == 0
11384 strcmp_arg_pack64 'A' 'p' 'p' 'l' 'e' 'A' 'C' 'P'
11385 set $AppleACP = $kgm_strcmp_arg
11386 strcmp_arg_pack64 'I' 'P' 'l' 'a' 't' 'f' 'o' 'r'
11387 set $IPlatfor = $kgm_strcmp_arg
11388 strcmp_arg_pack64 'm' 'E' 'x' 'p' 'e' 'r' 't' 0
11389 set $mExpert = $kgm_strcmp_arg
11390 setfindregistrystr $AppleACP $IPlatfor $mExpert
11392 set $olddepth = $kgm_reg_depth_max
11393 set $kgm_reg_depth_max = 2
11395 set $kgm_reg_depth_max = $olddepth
11397 if $kgm_registry_entry
11398 strcmp_arg_pack64 'a' 'c' 'p' 'i' '-' 'm' 'm' 'c'
11399 set $acpi_mmc = $kgm_strcmp_arg
11400 strcmp_arg_pack64 'f' 'g' '-' 's' 'e' 'g' '0' 0
11401 set $fg_seg0 = $kgm_strcmp_arg
11402 setfindregistrystr $acpi_mmc $fg_seg0
11404 _findregistryprop $kgm_registry_entry
11405 if $kgm_registry_value
11406 set $kgm_pci_cfg_base = ((OSNumber *) $kgm_registry_value)->value
11407 set $kgm_pci_cfg_init = 1
11412 # search for 0:0:0 in likely places if the above fails
11413 if $kgm_pci_cfg_init == 0
11414 set $kgm_pci_cfg_base = 0xF0000000
11415 while $kgm_pci_cfg_init == 0 && $kgm_pci_cfg_base > 0xA0000000
11416 _pci_cfg_addr_value $kgm_pci_cfg_base 8
11417 if $kgm_pci_cfg_value > 0x0 && $kgm_pci_cfg_value < 0xFF
11418 set $kgm_pci_cfg_init = 1
11420 set $kgm_pci_cfg_base = $kgm_pci_cfg_base - 0x10000000
11426 # _pci_cfg_addr $bus $dev $fcn $off
11427 define _pci_cfg_addr
11434 set $kgm_pci_cfg_addr = $kgm_pci_cfg_base | ($bus << 20) | ($dev << 15) | ($fcn << 12) | $off
11437 define _pci_cfg_value
11438 _pci_cfg_addr $arg0 $arg1 $arg2 $arg3
11439 _pci_cfg_addr_value $kgm_pci_cfg_addr $arg4
11442 define pci_cfg_read8
11443 _pci_cfg_value $arg0 $arg1 $arg2 $arg3 8
11444 printf "%08X: %02X\n", $kgm_pci_cfg_addr, $kgm_pci_cfg_value
11447 define pci_cfg_read16
11448 _pci_cfg_value $arg0 $arg1 $arg2 $arg3 16
11449 printf "%08X: %04X\n", $kgm_pci_cfg_addr, $kgm_pci_cfg_value
11452 define pci_cfg_read32
11453 _pci_cfg_value $arg0 $arg1 $arg2 $arg3 32
11454 printf "%08X: %08X\n", $kgm_pci_cfg_addr, $kgm_pci_cfg_value
11457 document pci_cfg_read8
11458 Syntax: (gdb) pci_cfg_read8 <bus> <dev> <fcn> <off>
11459 | read 8 bits for the given <off> of the pci device located at
11460 | <bus>:<dev>:<fcn>.
11463 document pci_cfg_read16
11464 Syntax: (gdb) pci_cfg_read <bus> <dev> <fcn> <off>
11465 | read 16 bits for the given <off> of the pci device located at
11466 | <bus>:<dev>:<fcn>.
11469 document pci_cfg_read32
11470 Syntax: (gdb) pci_cfg_read <bus> <dev> <fcn> <off>
11471 | read 32 bits for the given <off> of the pci device located at
11472 | <bus>:<dev>:<fcn>.
11475 define pci_cfg_write8
11476 _pci_cfg_addr $arg0 $arg1 $arg2 $arg3
11477 writephysint $kgm_pci_cfg_addr 8 $arg4 $kgm_lcpu_self
11480 define pci_cfg_write16
11481 _pci_cfg_addr $arg0 $arg1 $arg2 $arg3
11482 writephysint $kgm_pci_cfg_addr 16 $arg4 $kgm_lcpu_self
11485 define pci_cfg_write32
11486 _pci_cfg_addr $arg0 $arg1 $arg2 $arg3
11487 writephysint $kgm_pci_cfg_addr 32 $arg4 $kgm_lcpu_self
11490 document pci_cfg_write8
11491 Syntax: (gdb) pci_cfg_write8 <bus> <dev> <fcn> <off> <value>
11492 | write an 8-bit <value> into the given <off> of the pci device located at
11493 | <bus>:<dev>:<fcn>.
11496 document pci_cfg_write16
11497 Syntax: (gdb) pci_cfg_write16 <bus> <dev> <fcn> <off> <value>
11498 | write a 16-bit <value> into the given <off> of the pci device located at
11499 | <bus>:<dev>:<fcn>.
11502 document pci_cfg_write32
11503 Syntax: (gdb) pci_cfg_write32 <bus> <dev> <fcn> <off> <value>
11504 | write a 32-bit <value> into the given <off> of the pci device located at
11505 | <bus>:<dev>:<fcn>.
11509 define pci_cfg_dump
11515 # check for a valid pci device
11516 _pci_cfg_value $bus $dev $fcn $off 8
11517 if $kgm_pci_cfg_value > 0x0 && $kgm_pci_cfg_value < 0xff
11518 printf " address: 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F\n"
11519 printf "---------------------------------------------------------"
11522 _pci_cfg_value $bus $dev $fcn $off 32
11523 if ($off & 0xF) == 0
11524 printf "\n%08X: ", $kgm_pci_cfg_addr
11526 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
11527 set $off = $off + 4
11531 # check for pcie extended capability config space
11532 _pci_cfg_value $bus $dev $fcn $off 8
11533 if $kgm_pci_cfg_value < 0xff
11535 _pci_cfg_value $bus $dev $fcn $off 32
11536 if ($off & 0xF) == 0
11537 printf "\n%08X: ", $kgm_pci_cfg_addr
11539 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
11540 set $off = $off + 4
11547 document pci_cfg_dump
11548 Syntax: (gdb) pci_cfg_dump <bus> <dev> <fcn>
11549 | dump config space for the pci device located at <bus>:<dev>:<fcn>
11550 | if you specify an invalid/inaccessible pci device, nothing will be
11554 set $kgm_pci_cfg_bus_start = 0
11555 set $kgm_pci_cfg_bus_max = 8
11556 set $kgm_pci_cfg_device_max = 32
11557 set $kgm_pci_cfg_function_max = 8
11558 define _pci_cfg_scan
11561 set $bus = $kgm_pci_cfg_bus_start
11562 while $bus < $kgm_pci_cfg_bus_max
11563 # check for bus:0:0 to see if we should
11564 # probe this bus further
11565 _pci_cfg_value $bus 0x0 0x0 0x0 32
11566 if $kgm_pci_cfg_value > 0 && $kgm_pci_cfg_value < 0xFFFFFFFF
11569 while $dev < $kgm_pci_cfg_device_max
11572 while $fcn < $kgm_pci_cfg_function_max
11573 _pci_cfg_value $bus $dev $fcn 0x0 32
11574 if $kgm_pci_cfg_value > 0 && $kgm_pci_cfg_value < 0xFFFFFFFF
11576 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
11577 _pci_cfg_value $bus $dev $fcn 0x8 32
11578 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
11580 printf " device: %03X:%03X:%03X\n", $bus, $dev, $fcn
11581 pci_cfg_dump $bus $dev $fcn
11585 set $fcn = $fcn + 1
11587 set $dev = $dev + 1
11590 set $bus = $bus + 1
11594 define pci_cfg_dump_all
11598 document pci_cfg_dump_all
11599 Syntax: (gdb) pci_cfg_dump_all
11600 | dump config spaces for scanned pci devices. the number of busses to scan
11601 | is stored in $kgm_pci_cfg_bus_max. the default for that is 8. you can also
11602 | specify the starting bus with $kgm_pci_cfg_bus_start.
11605 define pci_cfg_scan
11606 printf "bus:dev:fcn: vendor device rev | class\n"
11607 printf "---------------------------------------\n"
11611 document pci_cfg_scan
11612 Syntax: (gdb) pci_cfg_scan
11613 | scan for pci devices. the number of busses to scan is stored in
11614 | $kgm_pci_cfg_bus_max. the default for that is 8. you can also specify the
11615 | starting bus with $kgm_pci_cfg_bus_start.
11618 define readioportint
11619 set $kgm_readioportint_result = 0xBAD10AD
11620 # set up the manual KDP packet
11621 set manual_pkt.input = 0
11622 set manual_pkt.len = sizeof(kdp_readioport_req_t)
11623 set $kgm_pkt = (kdp_readioport_req_t *)&manual_pkt.data
11624 set $kgm_pkt->hdr.request = KDP_READIOPORT
11625 set $kgm_pkt->hdr.len = sizeof(kdp_readioport_req_t)
11626 set $kgm_pkt->hdr.is_reply = 0
11627 set $kgm_pkt->hdr.seq = 0
11628 set $kgm_pkt->hdr.key = 0
11629 set $kgm_pkt->address = (uint16_t)$arg0
11630 set $kgm_pkt->nbytes = $arg1 >> 3
11631 set $kgm_pkt->lcpu = (uint16_t)$arg2
11632 set manual_pkt.input = 1
11633 # dummy to make sure manual packet is executed
11634 set $kgm_dummy = &_mh_execute_header
11635 set $kgm_pkt = (kdp_readioport_reply_t *)&manual_pkt.data
11636 if ($kgm_pkt->error == 0)
11638 set $kgm_readioportint_result = *((uint8_t *) $kgm_pkt->data)
11641 set $kgm_readioportint_result = *((uint16_t *) $kgm_pkt->data)
11644 set $kgm_readioportint_result = *((uint32_t *) $kgm_pkt->data)
11650 set $lcpu = $kgm_lcpu_self
11654 readioportint $arg0 8 $lcpu
11656 printf ":\t0x%02hhx\n", $kgm_readioportint_result
11659 define readioport16
11660 set $lcpu = $kgm_lcpu_self
11664 readioportint $arg0 16 $lcpu
11666 printf ":\t0x%04hx\n", $kgm_readioportint_result
11669 define readioport32
11670 set $lcpu = $kgm_lcpu_self
11674 readioportint $arg0 32 $lcpu
11676 printf ":\t0x%08x\n", $kgm_readioportint_result
11679 document readioport8
11680 | See readioport32.
11683 document readioport16
11684 | See readioport32.
11687 document readioport32
11688 Syntax: (gdb) readioport32 <port> [lcpu (kernel's numbering convention)]
11689 | Read value stored in the specified IO port. The CPU can be optionally
11690 | specified as well.
11693 define writeioportint
11694 # set up the manual KDP packet
11695 set manual_pkt.input = 0
11696 set manual_pkt.len = sizeof(kdp_writeioport_req_t)
11697 set $kgm_pkt = (kdp_writeioport_req_t *)&manual_pkt.data
11698 set $kgm_pkt->hdr.request = KDP_WRITEIOPORT
11699 set $kgm_pkt->hdr.len = sizeof(kdp_writeioport_req_t)
11700 set $kgm_pkt->hdr.is_reply = 0
11701 set $kgm_pkt->hdr.seq = 0
11702 set $kgm_pkt->hdr.key = 0
11703 set $kgm_pkt->address = (uint16_t)$arg0
11704 set $kgm_pkt->nbytes = $arg1 >> 3
11705 set $kgm_pkt->lcpu = (uint16_t)$arg3
11707 set *(uint8_t *)$kgm_pkt->data = (uint8_t)$arg2
11710 set *(uint16_t *)$kgm_pkt->data = (uint16_t)$arg2
11713 set *(uint32_t *)$kgm_pkt->data = (uint32_t)$arg2
11715 set manual_pkt.input = 1
11716 # dummy to make sure manual packet is executed
11717 set $kgm_dummy = &_mh_execute_header
11718 set $kgm_pkt = (kdp_writeioport_reply_t *)&manual_pkt.data
11719 set $kgm_writeioportint_result = $kgm_pkt->error
11722 define writeioport8
11723 set $lcpu = $kgm_lcpu_self
11727 writeioportint $arg0 8 $arg1 $lcpu
11730 define writeioport16
11731 set $lcpu = $kgm_lcpu_self
11735 writeioportint $arg0 16 $arg1 $lcpu
11738 define writeioport32
11739 set $lcpu = $kgm_lcpu_self
11743 writeioportint $arg0 32 $arg1 $lcpu
11746 document writeioport8
11747 | See writeioport32.
11750 document writeioport16
11751 | See writeioport32.
11754 document writeioport32
11755 Syntax: (gdb) writeioport32 <port> <value> [lcpu (kernel's numbering convention)]
11756 | Write the value to the specified IO port. The size of the value is
11757 | determined by the name of the command. The CPU used can be optionally
11761 define readmsr64int
11762 set $kgm_readmsr64int_result = 0xBAD10AD
11763 # set up the manual KDP packet
11764 set manual_pkt.input = 0
11765 set manual_pkt.len = sizeof(kdp_readmsr64_req_t)
11766 set $kgm_pkt = (kdp_readmsr64_req_t *)&manual_pkt.data
11767 set $kgm_pkt->hdr.request = KDP_READMSR64
11768 set $kgm_pkt->hdr.len = sizeof(kdp_readmsr64_req_t)
11769 set $kgm_pkt->hdr.is_reply = 0
11770 set $kgm_pkt->hdr.seq = 0
11771 set $kgm_pkt->hdr.key = 0
11772 set $kgm_pkt->address = (uint32_t)$arg0
11773 set $kgm_pkt->lcpu = (uint16_t)$arg1
11774 set manual_pkt.input = 1
11775 # dummy to make sure manual packet is executed
11776 set $kgm_dummy = &_mh_execute_header
11777 set $kgm_pkt = (kdp_readmsr64_reply_t *)&manual_pkt.data
11778 if ($kgm_pkt->error == 0)
11779 set $kgm_readmsr64int_result = *((uint64_t *) $kgm_pkt->data)
11784 set $lcpu = $kgm_lcpu_self
11788 readmsr64int $arg0 $lcpu
11790 printf ":\t0x%016llx\n", $kgm_readmsr64int_result
11793 define writemsr64int
11794 # set up the manual KDP packet
11795 set manual_pkt.input = 0
11796 set manual_pkt.len = sizeof(kdp_writemsr64_req_t)
11797 set $kgm_pkt = (kdp_writemsr64_req_t *)&manual_pkt.data
11798 set $kgm_pkt->hdr.request = KDP_WRITEMSR64
11799 set $kgm_pkt->hdr.len = sizeof(kdp_writemsr64_req_t)
11800 set $kgm_pkt->hdr.is_reply = 0
11801 set $kgm_pkt->hdr.seq = 0
11802 set $kgm_pkt->hdr.key = 0
11803 set $kgm_pkt->address = (uint32_t)$arg0
11804 set $kgm_pkt->lcpu = (uint16_t)$arg2
11805 set *(uint64_t *)$kgm_pkt->data = (uint64_t)$arg1
11806 set manual_pkt.input = 1
11807 # dummy to make sure manual packet is executed
11808 set $kgm_dummy = &_mh_execute_header
11809 set $kgm_pkt = (kdp_writemsr64_reply_t *)&manual_pkt.data
11810 set $kgm_writemsr64int_result = $kgm_pkt->error
11814 set $lcpu = $kgm_lcpu_self
11818 writemsr64int $arg0 $arg1 $lcpu
11821 document writemsr64
11822 Syntax: (gdb) writemsr64 <msr> <value> [lcpu (kernel's numbering convention)]
11823 | Write <value> to the specified MSR. The CPU can be optionally specified.
11827 Syntax: (gdb) readmsr64 <msr> [lcpu (kernel's numbering convention)]
11828 | Read the specified MSR. The CPU can be optionally specified.
11831 # default if we can't find a registry entry
11832 set $kgm_ioapic_addr = 0xFEC00000
11833 set $kgm_ioapic_init = 0
11835 set $_ioapic_index_off = 0x00
11836 set $_ioapic_data_off = 0x10
11837 set $_ioapic_eoi_off = 0x40
11839 set $_ioapic_index_id = 0x00
11840 set $_ioapic_index_ver = 0x01
11841 set $_ioapic_index_redir_base = 0x10
11843 set $_apic_vector_mask = 0xFF
11844 set $_apic_timer_tsc_deadline = 0x40000
11845 set $_apic_timer_periodic = 0x20000
11846 set $_apic_masked = 0x10000
11847 set $_apic_trigger_level = 0x08000
11848 set $_apic_polarity_high = 0x02000
11849 set $_apic_pending = 0x01000
11851 define _ioapic_init
11852 if $kgm_ioapic_init == 0
11853 strcmp_arg_pack64 'i' 'o' '-' 'a' 'p' 'i' 'c' 0
11854 setfindregistrystr $kgm_strcmp_arg
11856 set $olddepth = $kgm_reg_depth_max
11857 set $kgm_reg_depth_max = 3
11859 set $kgm_reg_depth_max = $olddepth
11861 if $kgm_registry_entry
11862 strcmp_arg_pack64 'P' 'h' 'y' 's' 'i' 'c' 'a' 'l'
11863 set $Physical = $kgm_strcmp_arg
11864 strcmp_arg_pack64 ' ' 'A' 'd' 'd' 'r' 'e' 's' 's'
11865 set $_Address = $kgm_strcmp_arg
11866 setfindregistrystr $Physical $_Address
11868 _findregistryprop $kgm_registry_entry
11869 if $kgm_registry_value
11870 set $kgm_ioapic_addr = ((OSNumber *) $kgm_registry_value)->value
11873 set $kgm_ioapic_index_addr = $kgm_ioapic_addr + $_ioapic_index_off
11874 set $kgm_ioapic_data_addr = $kgm_ioapic_addr + $_ioapic_data_off
11875 set $kgm_ioapic_init = 1
11879 define _ioapic_addr_value
11881 writephysint $kgm_ioapic_index_addr 8 $arg0 $kgm_lcpu_self
11883 writephysint $kgm_ioapic_data_addr 32 $arg1 $kgm_lcpu_self
11885 readphysint $kgm_ioapic_data_addr 32 $kgm_lcpu_self
11886 set $kgm_ioapic_value = $kgm_readphysint_result
11893 printf "[VEC=%3d", $value & $_apic_vector_mask
11894 if $value & $_apic_masked
11900 if $value & $_apic_trigger_level
11901 printf " TRIG=level"
11903 printf " TRIG=edge "
11906 if $value & $_apic_polarity_high
11912 if $value & $_apic_pending
11918 if $value & $_apic_timer_periodic
11921 if $value & $_apic_timer_tsc_deadline
11922 printf " TSC_DEADLINE"
11928 define ioapic_read32
11929 if (($kgm_mtype & $kgm_mtype_x86_mask) != $kgm_mtype_x86_any)
11930 printf "ioapic_read32 not supported on this architecture.\n"
11932 _ioapic_addr_value $arg0
11933 printf "IOAPIC[0x%02X]: 0x%08X\n", $arg0, $kgm_ioapic_value
11937 document ioapic_read32
11938 Syntax: (gdb) ioapic_read <offset>
11939 | Read the IOAPIC register at the offset specified.
11942 define ioapic_write32
11943 if (($kgm_mtype & $kgm_mtype_x86_mask) != $kgm_mtype_x86_any)
11944 printf "ioapic_write32 not supported on this architecture.\n"
11946 _ioapic_addr_value $arg0 $arg1
11950 document ioapic_write32
11951 Syntax: (gdb) ioapic_write32 <offset> <value>
11952 | Write the IOAPIC register at the offset specified.
11956 if (($kgm_mtype & $kgm_mtype_x86_mask) != $kgm_mtype_x86_any)
11957 printf "ioapic_dump not supported on this architecture.\n"
11960 _ioapic_addr_value $_ioapic_index_id
11961 printf "IOAPIC[0x%02X] ID: 0x%08X\n", $_ioapic_index_id, $kgm_ioapic_value
11964 _ioapic_addr_value $_ioapic_index_ver
11965 set $maxredir = (($kgm_ioapic_value & 0xFF0000) >> 16) + 1
11967 printf "IOAPIC[0x%02X] VERSION: 0x%08X [", $_ioapic_index_ver, $kgm_ioapic_value
11968 printf "MAXREDIR=%02d PRQ=%d VERSION=0x%02X]\n", $maxredir, ($kgm_ioapic_value >> 15) & 0x1, $kgm_ioapic_value & 0xFF
11970 # all the redir entries
11972 while $i < $maxredir
11973 set $addr0 = $_ioapic_index_redir_base + ($i << 1)
11974 set $addr1 = $addr0 + 1
11975 _ioapic_addr_value $addr1
11976 printf "IOAPIC[0x%02X] IOREDIR%02d: 0x%08X", $addr0, $i, $kgm_ioapic_value
11978 _ioapic_addr_value $addr0
11979 printf "%08X ", $kgm_ioapic_value
11980 _apic_print $kgm_ioapic_value
11986 document ioapic_dump
11987 Syntax: (gdb) ioapic_dump
11988 | Dump all the IOAPIC entries.
11992 set $_lapic_base_addr = 0xFEE00000
11993 set $_lapic_id = 0x20
11994 set $_lapic_version = 0x30
11995 set $_lapic_tpr = 0x80
11996 set $_lapic_apr = 0x90
11997 set $_lapic_ppr = 0xA0
11998 set $_lapic_eoi = 0xB0
11999 set $_lapic_ldr = 0xD0
12000 set $_lapic_dfr = 0xE0
12001 set $_lapic_sivr = 0xF0
12003 set $_lapic_isr_size = 0x10
12004 set $_lapic_isr_num = 8
12005 set $_lapic_isr0 = 0x100
12006 set $_lapic_tmr0 = 0x180
12007 set $_lapic_irr0 = 0x200
12009 set $_lapic_esr = 0x280
12010 set $_lapic_esr_register = 0x80
12011 set $_lapic_esr_recv_vect = 0x40
12012 set $_lapic_esr_send_vect = 0x20
12014 set $_lapic_icr0 = 0x300
12015 set $_lapic_icr1 = 0x310
12017 set $_lapic_lvt_timer = 0x320
12018 set $_lapic_lvt_thermal = 0x330
12019 set $_lapic_lvt_pmcr = 0x340
12020 set $_lapic_lvt_lint0 = 0x350
12021 set $_lapic_lvt_lint1 = 0x360
12022 set $_lapic_lvt_error = 0x370
12024 set $_lapic_icr = 0x380
12025 set $_lapic_ccr = 0x390
12026 set $_lapic_dcr = 0x3E0
12028 set $_apic_cfg_msr = 0x1B
12029 set $_apic_cfg_msr_x2EN = 0x00000C00
12030 set $_x2apic_enabled = -1
12032 # _lapic_addr $offset returns the actual address to use
12034 if $_x2apic_enabled < 0
12035 readmsr64int $_apic_cfg_msr $kgm_lcpu_self
12036 if ($kgm_readmsr64int_result & $_apic_cfg_msr_x2EN) == $_apic_cfg_msr_x2EN
12037 set $_x2apic_enabled = 1
12039 set $_x2apic_enabled = 0
12043 if $_x2apic_enabled
12044 # x2APIC addresses are MSRs that use xAPIC offsets that
12045 # are 4-bit shifted
12046 set $kgm_lapic_addr = $arg0 >> 4
12048 set $kgm_lapic_addr = $_lapic_base_addr + $arg0
12052 # _lapic_addr_value $offset $lcpu
12053 define _lapic_addr_value
12055 if $_x2apic_enabled
12056 readmsr64int $kgm_lapic_addr $arg1
12057 set $kgm_lapic_value = $kgm_readmsr64int_result
12059 readphysint $kgm_lapic_addr 32 $arg1
12060 set $kgm_lapic_value = $kgm_readphysint_result
12064 # lapic_read32 $offset [$lcpu]
12065 define lapic_read32
12066 if (($kgm_mtype & $kgm_mtype_x86_mask) != $kgm_mtype_x86_any)
12067 printf "lapic_read32 not supported on this architecture.\n"
12069 set $lcpu = $kgm_lcpu_self
12073 _lapic_addr_value $arg0 $lcpu
12074 printf "LAPIC[0x%03X]: 0x%08X\n", $arg0, $kgm_lapic_value
12078 document lapic_read32
12079 Syntax: (gdb) apic_read32_cpu <offset> [lcpu (kernel's numbering convention)]
12080 | Read the LAPIC register at the offset specified. The CPU can be optionally
12084 # lapic_write32 $offset $value [$lcpu]
12085 define lapic_write32
12086 if (($kgm_mtype & $kgm_mtype_x86_mask) != $kgm_mtype_x86_any)
12087 printf "lapic_write32_cpu not supported on this architecture.\n"
12089 set $lcpu = $kgm_lcpu_self
12095 if $_x2apic_enabled
12096 writemsr64int $kgm_lapic_addr $arg1 $lcpu
12098 writephysint $kgm_lapic_addr 32 $arg1 $lcpu
12103 document lapic_write32
12104 Syntax: (gdb) lapic_write32 <offset> <value> [lcpu (kernel's numbering convention)]
12105 | Write the LAPIC register at the offset specified. The CPU can be optionally
12109 # lapic_dump [lcpu]
12111 if (($kgm_mtype & $kgm_mtype_x86_mask) != $kgm_mtype_x86_any)
12112 printf "lapic_dump not supported on this architecture.\n"
12114 set $lcpu = $kgm_lcpu_self
12119 _lapic_addr_value $_lapic_id $lcpu
12121 # the above also figures out if we're using an xAPIC or an x2APIC
12122 printf "LAPIC operating mode: "
12123 if $_x2apic_enabled
12129 printf "LAPIC[0x%03X] ID: 0x%08X\n", $_lapic_id, $kgm_lapic_value
12131 _lapic_addr_value $_lapic_version $lcpu
12132 set $lvt_num = ($kgm_lapic_value >> 16) + 1
12133 printf "LAPIC[0x%03X] VERSION: 0x%08X [VERSION=%d MaxLVT=%d]\n", $_lapic_version, $kgm_lapic_value, $kgm_lapic_value & 0xFF, $lvt_num
12135 _lapic_addr_value $_lapic_tpr $lcpu
12136 printf "LAPIC[0x%03X] TASK PRIORITY: 0x%08X\n", $_lapic_tpr, $kgm_lapic_value
12138 _lapic_addr_value $_lapic_ppr $lcpu
12139 printf "LAPIC[0x%03X] PROCESSOR PRIORITY: 0x%08X\n", $_lapic_ppr, $kgm_lapic_value
12141 _lapic_addr_value $_lapic_ldr $lcpu
12142 printf "LAPIC[0x%03X] LOGICAL DEST: 0x%08X\n", $_lapic_ldr, $kgm_lapic_value
12144 _lapic_addr_value $_lapic_dfr $lcpu
12145 printf "LAPIC[0x%03X] DEST FORMAT: 0x%08X\n", $_lapic_dfr, $kgm_lapic_value
12147 _lapic_addr_value $_lapic_sivr $lcpu
12148 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,
12151 while $i < $_lapic_isr_num
12152 set $addr = $_lapic_isr0 + $i * $_lapic_isr_size
12153 _lapic_addr_value $addr $lcpu
12154 printf "LAPIC[0x%03X] ISR[%03d:%03d]: 0x%08X\n", $addr, 32*($i + 1) - 1, 32*$i, $kgm_lapic_value
12159 while $i < $_lapic_isr_num
12160 set $addr = $_lapic_tmr0 + $i * $_lapic_isr_size
12161 _lapic_addr_value $addr $lcpu
12162 printf "LAPIC[0x%03X] TMR[%03d:%03d]: 0x%08X\n", $addr, 32*($i + 1) - 1, 32*$i, $kgm_lapic_value
12167 while $i < $_lapic_isr_num
12168 set $addr = $_lapic_irr0 + $i * $_lapic_isr_size
12169 _lapic_addr_value $addr $lcpu
12170 printf "LAPIC[0x%03X] IRR[%03d:%03d]: 0x%08X\n", $addr, 32*($i + 1) - 1, 32*$i, $kgm_lapic_value
12174 _lapic_addr_value $_lapic_esr $lcpu
12175 printf "LAPIC[0x%03X] ERROR STATUS: 0x%08X ", $_lapic_esr, $kgm_lapic_value
12176 if $kgm_lapic_value
12179 if $kgm_lapic_value & $_lapic_esr_register
12182 if $kgm_lapic_value & $_lapic_esr_recv_vect
12183 printf "Received Vector "
12185 if $kgm_lapic_value & $_lapic_esr_send_vect
12186 printf "Send Vector"
12188 if $kgm_lapic_value
12193 _lapic_addr_value $_lapic_icr1 $lcpu
12194 printf "LAPIC[0x%03X] Interrupt Command: 0x%08X [DEST=%d]\n", $_lapic_icr0, $kgm_lapic_value, $kgm_lapic_value >> 24
12195 _lapic_addr_value $_lapic_icr0 $lcpu
12196 printf " 0x%08X ", $kgm_lapic_value
12197 _apic_print $kgm_lapic_value
12200 _lapic_addr_value $_lapic_lvt_timer $lcpu
12201 printf "LAPIC[0x%03X] LVT Timer: 0x%08X ", $_lapic_lvt_timer, $kgm_lapic_value
12202 _apic_print $kgm_lapic_value
12206 _lapic_addr_value $_lapic_lvt_lint0 $lcpu
12207 printf "LAPIC[0x%03X] LVT LINT0: 0x%08X ", $_lapic_lvt_lint0, $kgm_lapic_value
12208 _apic_print $kgm_lapic_value
12212 _lapic_addr_value $_lapic_lvt_lint1 $lcpu
12213 printf "LAPIC[0x%03X] LVT LINT1: 0x%08X ", $_lapic_lvt_lint1, $kgm_lapic_value
12214 _apic_print $kgm_lapic_value
12218 _lapic_addr_value $_lapic_lvt_error $lcpu
12219 printf "LAPIC[0x%03X] LVT Error: 0x%08X ", $_lapic_lvt_error, $kgm_lapic_value
12220 _apic_print $kgm_lapic_value
12224 _lapic_addr_value $_lapic_lvt_pmcr $lcpu
12225 printf "LAPIC[0x%03X] LVT PerfMon: 0x%08X ", $_lapic_lvt_pmcr, $kgm_lapic_value
12226 _apic_print $kgm_lapic_value
12230 _lapic_addr_value $_lapic_lvt_thermal $lcpu
12231 printf "LAPIC[0x%03X] LVT Thermal: 0x%08X ", $_lapic_lvt_thermal, $kgm_lapic_value
12232 _apic_print $kgm_lapic_value
12235 _lapic_addr_value $_lapic_dcr $lcpu
12236 printf "LAPIC[0x%03X] Timer Divide: 0x%08X [Divide by ", $_lapic_dcr, $kgm_lapic_value
12237 set $kgm_lapic_value = ($kgm_lapic_value & 0x8) >> 1 | $kgm_lapic_value & 0x3
12238 if $kgm_lapic_value == 0x7
12241 printf "%d]\n", 2 << $kgm_lapic_value
12244 _lapic_addr_value $_lapic_icr $lcpu
12245 printf "LAPIC[0x%03X] Timer Init Count: 0x%08X\n", $_lapic_icr, $kgm_lapic_value
12247 _lapic_addr_value $_lapic_ccr $lcpu
12248 printf "LAPIC[0x%03X] Timer Cur Count: 0x%08X\n", $_lapic_ccr, $kgm_lapic_value
12252 document lapic_dump
12253 Syntax: (gdb) lapic_dump [lcpu (kernel's numbering convention)]
12254 | Dump all the LAPIC entries. The CPU can be optionally specified.
12257 define showknoteheader
12258 printf " knote filter ident kn_ptr status\n"
12261 define showknoteint
12262 set $kgm_knotep = ((struct knote *) $arg0)
12264 showptr $kgm_knotep
12266 set $kgm_filt = -$kgm_knotep->kn_kevent.filter
12267 if ($kgm_filt == 1)
12268 printf "EVFILT_READ "
12270 if ($kgm_filt == 2)
12271 printf "EVFILT_WRITE "
12273 if ($kgm_filt == 3)
12274 printf "EVFILT_AIO "
12276 if ($kgm_filt == 4)
12277 printf "EVFILT_VNODE "
12279 if ($kgm_filt == 5)
12280 printf "EVFILT_PROC "
12282 if ($kgm_filt == 6)
12283 printf "EVFILT_SIGNAL "
12285 if ($kgm_filt == 7)
12286 printf "EVFILT_TIMER "
12288 if ($kgm_filt == 8)
12289 printf "EVFILT_MACHPORT"
12291 if ($kgm_filt == 9)
12292 printf "EVFILT_FS "
12294 if ($kgm_filt == 10)
12295 printf "EVFILT_USER "
12297 if ($kgm_filt == 11)
12298 printf "EVFILT_SESSION "
12300 printf "%7d ", $kgm_knotep->kn_kevent.ident
12301 showptr $kgm_knotep->kn_ptr.p_fp
12303 if ($kgm_knotep->kn_status == 0)
12306 if ($kgm_knotep->kn_status & 0x01)
12309 if ($kgm_knotep->kn_status & 0x02)
12312 if ($kgm_knotep->kn_status & 0x04)
12315 if ($kgm_knotep->kn_status & 0x08)
12318 if ($kgm_knotep->kn_status & 0x10)
12321 if ($kgm_knotep->kn_status & 0x20)
12324 if ($kgm_knotep->kn_status & 0x40)
12331 define showprocknotes
12333 set $kgm_fdp = ((proc_t)$arg0)->p_fd
12334 set $kgm_knlist = $kgm_fdp->fd_knlist
12336 while (($i < $kgm_fdp->fd_knlistsize) && ($kgm_knlist != 0))
12337 set $kgm_kn = ((struct knote *)$kgm_knlist[$i].slh_first)
12338 while ($kgm_kn != 0)
12339 showknoteint $kgm_kn
12340 set $kgm_kn = ((struct knote *)$kgm_kn->kn_link.sle_next)
12344 set $kgm_knhash = $kgm_fdp->fd_knhash
12346 while (($i < $kgm_fdp->fd_knhashmask + 1) && ($kgm_knhash != 0))
12347 set $kgm_kn = ((struct knote *)$kgm_knhash[$i].slh_first)
12348 while ($kgm_kn != 0)
12349 showknoteint $kgm_kn
12350 set $kgm_kn = ((struct knote *)$kgm_kn->kn_link.sle_next)
12356 define showallknotes
12357 set $kgm_head_taskp = &tasks
12358 set $kgm_taskp = (struct task *)($kgm_head_taskp->next)
12359 while $kgm_taskp != $kgm_head_taskp
12361 showtaskint $kgm_taskp
12362 showprocknotes $kgm_taskp->bsd_info
12363 set $kgm_taskp = (struct task *)($kgm_taskp->tasks.next)
12366 document showprocknotes
12367 Syntax: showprocknotes <proc>
12368 | Displays filter and status information for every kevent registered for
12373 # Device node related debug macros
12377 set $kgm_tty = (struct tty *) $arg0
12378 printf "tty struct at "
12381 printf "-last input to raw queue:\n"
12382 p $kgm_tty->t_rawq->c_cs
12383 printf "-last input to canonical queue:\n"
12384 p $kgm_tty->t_canq->c_cs
12385 printf "-last output data:\n"
12386 p $kgm_tty->t_outq->c_cs
12388 if ($kgm_tty->t_state & 0x00000001)
12389 printf " TS_SO_OLOWAT (Wake up when output <= low water)\n"
12391 if ($kgm_tty->t_state & 0x00000002)
12392 printf " TS_ASYNC (async I/O mode)\n"
12394 printf " - (synchronous I/O mode)\n"
12396 if ($kgm_tty->t_state & 0x00000004)
12397 printf " TS_BUSY (Draining output)\n"
12399 if ($kgm_tty->t_state & 0x00000008)
12400 printf " TS_CARR_ON (Carrier is present)\n"
12402 printf " - (Carrier is NOT present)\n"
12404 if ($kgm_tty->t_state & 0x00000010)
12405 printf " TS_FLUSH (Outq has been flushed during DMA)\n"
12407 if ($kgm_tty->t_state & 0x00000020)
12408 printf " TS_ISOPEN (Open has completed)\n"
12410 printf " - (Open has NOT completed)\n"
12412 if ($kgm_tty->t_state & 0x00000040)
12413 printf " TS_TBLOCK (Further input blocked)\n"
12415 if ($kgm_tty->t_state & 0x00000080)
12416 printf " TS_TIMEOUT (Wait for output char processing)\n"
12418 if ($kgm_tty->t_state & 0x00000100)
12419 printf " TS_TTSTOP (Output paused)\n"
12421 if ($kgm_tty->t_state & 0x00000200)
12422 printf " TS_WOPEN (Open in progress)\n"
12424 if ($kgm_tty->t_state & 0x00000400)
12425 printf " TS_XCLUDE (Tty requires exclusivity)\n"
12427 if ($kgm_tty->t_state & 0x00000800)
12428 printf " TS_BKSL (State for lowercase \\ work)\n"
12430 if ($kgm_tty->t_state & 0x00001000)
12431 printf " TS_CNTTB (Counting tab width, ignore FLUSHO)\n"
12433 if ($kgm_tty->t_state & 0x00002000)
12434 printf " TS_ERASE (Within a \\.../ for PRTRUB)\n"
12436 if ($kgm_tty->t_state & 0x00004000)
12437 printf " TS_LNCH (Next character is literal)\n"
12439 if ($kgm_tty->t_state & 0x00008000)
12440 printf " TS_TYPEN (Retyping suspended input (PENDIN))\n"
12442 if ($kgm_tty->t_state & 0x00010000)
12443 printf " TS_CAN_BYPASS_L_RINT (Device in "raw" mode)\n"
12445 if ($kgm_tty->t_state & 0x00020000)
12446 printf " TS_CONNECTED (Connection open)\n"
12448 printf " - (Connection NOT open)\n"
12450 if ($kgm_tty->t_state & 0x00040000)
12451 printf " TS_SNOOP (Device is being snooped on)\n"
12453 if ($kgm_tty->t_state & 0x80000)
12454 printf " TS_SO_OCOMPLETE (Wake up when output completes)\n"
12456 if ($kgm_tty->t_state & 0x00100000)
12457 printf " TS_ZOMBIE (Connection lost)\n"
12459 if ($kgm_tty->t_state & 0x00200000)
12460 printf " TS_CAR_OFLOW (For MDMBUF - handle in driver)\n"
12462 if ($kgm_tty->t_state & 0x00400000)
12463 printf " TS_CTS_OFLOW (For CCTS_OFLOW - handle in driver)\n"
12465 if ($kgm_tty->t_state & 0x00800000)
12466 printf " TS_DSR_OFLOW (For CDSR_OFLOW - handle in driver)\n"
12468 # xxx todo: do we care about decoding flags?
12469 printf "flags: 0x%08x\n", $kgm_tty->t_flags
12470 printf "foreground process group: "
12471 showptr $kgm_tty->t_pgrp
12473 printf "enclosing session: "
12474 showptr $kgm_tty->t_session
12476 printf "Termios:\n"
12477 # XXX todo: decode these flags, someday
12478 printf " Input flags: 0x%08x\n", $kgm_tty->t_termios.c_iflag
12479 printf " Output flags: 0x%08x\n", $kgm_tty->t_termios.c_oflag
12480 printf " Control flags: 0x%08x\n", $kgm_tty->t_termios.c_cflag
12481 printf " Local flags: 0x%08x\n", $kgm_tty->t_termios.c_lflag
12482 printf " Input speed: %d\n", $kgm_tty->t_termios.c_ispeed
12483 printf " Output speed: %d\n", $kgm_tty->t_termios.c_ospeed
12484 # XXX todo: useful to decode t_winsize? t_iokit? c_cc? anything else?
12485 printf "high watermark: %d bytes\n", $kgm_tty->t_hiwat
12486 printf "low watermark: %d bytes\n", $kgm_tty->t_lowat
12490 # _showwhohas <major> <minor>
12500 set $kgm_swh_devnode_dev = (((int) $arg0) << 24) | (int) $arg1
12501 # iterate all tasks to iterate all processes to iterate all
12502 # open files in each process to see who has a given major/minor
12504 set $kgm_taskp = (struct task *)($kgm_head_taskp->next)
12505 while $kgm_taskp != $kgm_head_taskp
12506 set $kgm_procp = (proc_t) $kgm_taskp->bsd_info
12507 set $kgm_spf_filedesc = $kgm_procp->p_fd
12508 set $kgm_spf_last = $kgm_spf_filedesc->fd_lastfile
12509 set $kgm_spf_ofiles = $kgm_spf_filedesc->fd_ofiles
12510 set $kgm_spf_count = 0
12511 while (($kgm_spf_ofiles != 0) && ($kgm_spf_count <= $kgm_spf_last))
12512 # only files currently open
12513 if ($kgm_spf_ofiles[$kgm_spf_count] != 0)
12514 set $kgm_spf_fg = $kgm_spf_ofiles[$kgm_spf_count].f_fglob
12515 if ($kgm_spf_fg->fg_type == 1)
12516 # display fd #, fileglob & vnode address, proc name
12517 set $kgm_swh_m_vnode = (vnode_t) $kgm_spf_fg->fg_data
12518 set $kgm_swh_m_vtype = (enum vtype) $kgm_swh_m_vnode->v_type
12519 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)
12520 printf "%-5d ", $kgm_spf_count
12521 showptr $kgm_spf_fg
12523 showptr $kgm_swh_m_vnode
12526 printf " %s\n", $kgm_procp->p_comm
12530 set $kgm_spf_count = $kgm_spf_count + 1
12533 set $kgm_taskp = (struct task *)($kgm_taskp->tasks.next)
12537 define _showvnodedev_cpty
12538 set $kgm_ptmx_major = (int) $arg0
12539 set $kgm_ptmx_minor = (int) $arg1
12540 set $kgm_ptmx_ioctl = _state.pis_ioctl_list[$kgm_ptmx_minor]
12541 set $kgm_ptmx_ioctl = _state.pis_ioctl_list[$kgm_ptmx_minor]
12542 printf " ptmx_ioctl struct at "
12543 showptr $kgm_ptmx_ioctl
12546 if ($kgm_ptmx_ioctl->pt_flags & 0x0008)
12547 printf " PF_PKT (packet mode)\n"
12549 if ($kgm_ptmx_ioctl->pt_flags & 0x0010)
12550 printf " PF_STOPPED (user told stopped)\n"
12552 if ($kgm_ptmx_ioctl->pt_flags & 0x0020)
12553 printf " PF_REMOTE (remote and flow controlled input)\n"
12555 if ($kgm_ptmx_ioctl->pt_flags & 0x0040)
12556 printf " PF_NOSTOP"
12558 if ($kgm_ptmx_ioctl->pt_flags & 0x0080)
12559 printf " PF_UCNTL (user control mode)\n"
12561 if ($kgm_ptmx_ioctl->pt_flags & 0x0100)
12562 printf " PF_UNLOCKED (slave unlock - master open resets)\n"
12564 if ($kgm_ptmx_ioctl->pt_flags & 0x0200)
12565 printf " PF_OPEN_M (master is open)\n"
12566 # XXX we should search for who has the master open, but
12567 # XXX each master gets the same minor, even though it
12568 # XXX gets a different vnode. we chold probably change
12569 # XXX this, but to do it we would need some way of
12570 # XXX expressing the information in the vnode structure
12571 # XXX somewhere. If we *did* change it, it would buy us
12572 # XXX the ability to determine who has the corresponding
12573 # XXX master end of the pty open
12575 printf " PF_OPEN_M (master is closed)\n"
12577 if ($kgm_ptmx_ioctl->pt_flags & 0x0400)
12578 printf " PF_OPEN_S (slave is open)\n"
12579 printf "---vvvvv--- fds open on this device ---vvvvv---\n"
12580 _showwhohas ($kgm_ptmx_major) ($kgm_ptmx_minor)
12581 printf "---^^^^^--- fds open on this device ---^^^^^---\n"
12583 printf " - (slave is closed)\n"
12585 printf "TTY Specific Information\n"
12586 _showtty $kgm_ptmx_ioctl->pt_tty
12589 define showvnodedev
12591 set $kgm_vnode = (vnode_t) $arg0
12592 set $kgm_vtype = (enum vtype) $kgm_vnode->v_type
12593 if (($kgm_vtype == VBLK) || ($kgm_vtype == VCHR))
12594 set $kgm_devnode = (devnode_t *) $kgm_vnode->v_data
12595 set $kgm_devnode_dev = $kgm_devnode->dn_typeinfo.dev
12596 set $kgm_devnode_major = ($kgm_devnode_dev >> 24) & 0xff
12597 set $kgm_devnode_minor = $kgm_devnode_dev & 0x00ffffff
12599 # boilerplate device information for a vnode
12600 printf "Device Info:\n"
12605 if ($kgm_vtype == VBLK)
12608 if ($kgm_vtype == VCHR)
12612 printf " name: %s\n", $kgm_vnode->v_name
12613 printf " major, minor: %d, %d\n", $kgm_devnode_major, $kgm_devnode_minor
12614 printf " mode 0%o\n", $kgm_devnode->dn_mode
12615 printf " owner (u,g): %d %d", $kgm_devnode->dn_uid, $kgm_devnode->dn_gid
12618 # decode device specific data
12619 printf "Device Specific Information: "
12620 if ($kgm_vtype == VBLK)
12621 printf " Sorry, I do not know how to decode block devices yet!\n"
12622 printf " Maybe you can write me!"
12624 if ($kgm_vtype == VCHR)
12625 # Device information; this is scanty
12627 if ($kgm_devnode_major > 42) || ($kgm_devnode_major < 0)
12628 printf "Invalid major #\n"
12630 # static assignments in conf
12631 if ($kgm_devnode_major == 0)
12632 printf "Console mux device\n"
12634 if ($kgm_devnode_major == 2)
12635 printf "Current tty alias\n"
12637 if ($kgm_devnode_major == 3)
12638 printf "NULL device\n"
12640 if ($kgm_devnode_major == 4)
12641 printf "Old pty slave\n"
12643 if ($kgm_devnode_major == 5)
12644 printf "Old pty master\n"
12646 if ($kgm_devnode_major == 6)
12647 printf "Kernel log\n"
12649 if ($kgm_devnode_major == 12)
12650 printf "Memory devices\n"
12652 # Statically linked dynamic assignments
12653 if cdevsw[$kgm_devnode_major].d_open == ptmx_open
12654 printf "Cloning pty master\n"
12655 _showvnodedev_cpty ($kgm_devnode_major) ($kgm_devnode_minor)
12657 if cdevsw[$kgm_devnode_major].d_open == ptsd_open
12658 printf "Cloning pty slave\n"
12659 _showvnodedev_cpty ($kgm_devnode_major) ($kgm_devnode_minor)
12661 printf "RESERVED SLOT\n"
12675 printf " is not a device\n"
12678 printf "| Usage:\n|\n"
12682 document showvnodedev
12683 Syntax: (gdb) showvnodedev <vnode>
12684 | showvnodedev Display information about a device vnode
12691 printf "| Usage:\n|\n"
12696 Syntax: (gdb) showtty <tty struct>
12697 | showtty Display information about a struct tty
12700 define showeventsourceobject
12701 set $kgm_vt = *((void **) $arg1)
12703 set $kgm_vt = $kgm_vt - 16
12707 document showeventsourceobject
12708 Syntax: (gdb) showeventsourceobject <prefix> <object>
12709 | Routine to display information about an IOEventSource subclass.
12712 define showworkloopallocator
12713 set $kgm_workloop = (struct IOWorkLoop*)$arg0
12714 set $kgm_bt = (void**)$kgm_workloop->reserved->allocationBacktrace
12715 set $kgm_bt_count = 0
12716 while $kgm_bt_count != (sizeof(IOWorkLoop::ExpansionData.allocationBacktrace) / sizeof(IOWorkLoop::ExpansionData.allocationBacktrace[0]))
12717 set $kgm_frame_address = (void*)$kgm_bt[$kgm_bt_count]
12718 if $kgm_frame_address != 0
12719 if (((unsigned long) $kgm_frame_address < (unsigned long) &_mh_execute_header || \
12720 (unsigned long) $kgm_frame_address >= (unsigned long) &last_kernel_symbol ) \
12721 && ($kgm_show_kmod_syms == 0))
12722 showkmodaddr $kgm_frame_address
12724 output /a $kgm_frame_address
12728 set $kgm_bt_count = $kgm_bt_count + 1
12731 document showworkloopallocator
12732 Syntax: (gdb) showworkloopallocator <workloop>
12733 | Routine to display the backtrace of the thread which allocated the workloop in question. Only
12734 | valid on DEBUG kernels.
12737 define showworkloopeventsources
12738 set $kgm_eventsource = (struct IOEventSource*)$arg0
12739 while $kgm_eventsource != 0
12741 printf "EventSource:\t"
12742 showptr $kgm_eventsource
12743 printf " Description: "
12744 showeventsourceobject _ $kgm_eventsource
12746 if $kgm_eventsource->action != 0
12748 printf "Action: \t"
12749 pcprint $kgm_eventsource->action
12752 if $kgm_eventsource->owner != 0
12755 showptr $kgm_eventsource->owner
12756 printf " Description: "
12757 showeventsourceobject _ $kgm_eventsource->owner
12760 set $kgm_eventsource = $kgm_eventsource->eventChainNext
12764 document showworkloopeventsources
12765 Syntax: (gdb) showworkloopeventsources
12766 | Routine to walk an IOEventSource chain associated with an IOWorkLoop and print information
12767 | about each event source in the chain.
12770 define showworkloopheader
12773 printf " workloop "
12775 printf " pri state\tLockGroupName\n"
12777 document showworkloopheader
12778 Syntax: (gdb) showworkloopheader
12779 | Routine to print out header info about an IOKit workloop.
12782 define showworkloop
12783 set $kgm_workloopthread = (struct thread*)$arg0
12784 set $kgm_workloop = (struct IOWorkLoop*)$arg1
12785 showptr $kgm_workloopthread
12787 showptr $kgm_workloop
12788 printf " %3d ", $kgm_workloopthread.sched_pri
12789 set $kgm_state = $kgm_workloopthread.state
12790 if $kgm_state & 0x80
12793 if $kgm_state & 0x40
12796 if $kgm_state & 0x20
12799 if $kgm_state & 0x10
12802 if $kgm_state & 0x08
12805 if $kgm_state & 0x04
12808 if $kgm_state & 0x02
12811 if $kgm_state & 0x01
12815 set $kgm_gateLock = ( struct _IORecursiveLock *)$kgm_workloop->gateLock
12816 if $kgm_gateLock != 0
12817 set $kgm_lockGroup = (struct _lck_grp_*)($kgm_gateLock->group)
12818 printf "%s", $kgm_lockGroup->lck_grp_name
12820 printf "No WorkLoop Lock found"
12824 #Allocation backtrace is only valid on DEBUG kernels.
12825 #printf "Allocation path:\n\n"
12826 #showworkloopallocator $kgm_workloop
12829 if $kgm_workloop->eventChain != 0
12830 printf "Active event sources:\n\n"
12831 showworkloopeventsources $kgm_workloop->eventChain
12833 if $kgm_workloop->reserved->passiveEventChain != 0
12834 printf "Passive event sources:\n"
12835 showworkloopeventsources $kgm_workloop->reserved->passiveEventChain
12838 document showworkloop
12839 Syntax: (gdb) showworkloop <thread> <workloop>
12840 | Routine to print out info about an IOKit workloop.
12843 define showallworkloopthreads
12844 set $kgm_head_taskp = &tasks
12845 set $kgm_taskp = (struct task *)($kgm_head_taskp->next)
12846 set $kgm_head_actp = &($kgm_taskp->threads)
12847 set $kgm_actp = (struct thread *)($kgm_taskp->threads.next)
12848 while $kgm_actp != $kgm_head_actp
12849 if ($kgm_actp->continuation == _ZN10IOWorkLoop10threadMainEv)
12851 showworkloop $kgm_actp $kgm_actp->parameter
12853 if ($kgm_actp->kernel_stack != 0)
12854 if ($kgm_mtype == $kgm_mtype_x86_64)
12855 #Warning: Grokking stack looking for hopeful workloops until we squirrel some info in thread_t.
12856 set $kgm_workloop = *((struct IOWorkLoop **)($kgm_actp->kernel_stack + kernel_stack_size - 0xB8))
12858 if ($kgm_mtype == $kgm_mtype_i386)
12859 set $kgm_workloop = *((struct IOWorkLoop **)($kgm_actp->kernel_stack + kernel_stack_size - 0x3C))
12862 if ($kgm_workloop != 0)
12863 set $kgm_vt = *((void **) $kgm_workloop)
12865 set $kgm_vt = $kgm_vt - 16
12867 if ($kgm_vt == &_ZTV10IOWorkLoop)
12869 showworkloop $kgm_actp $kgm_workloop
12874 set $kgm_actp = (struct thread *)($kgm_actp->task_threads.next)
12878 document showallworkloopthreads
12879 Syntax: (gdb) showallworkloopthreads
12880 | Routine to print out info about all IOKit workloop threads in the system. This macro will find
12881 | all IOWorkLoop threads blocked in continuations and on i386 and x86_64 systems will make a
12882 | best-effort guess to find any workloops that are actually not blocked in a continuation. For a
12883 | complete list, it is best to compare the output of this macro against the output of 'showallstacks'.
12886 define showthreadfortid
12887 set $kgm_id_found = 0
12889 set $kgm_head_taskp = &tasks
12890 set $kgm_taskp = (struct task *)($kgm_head_taskp->next)
12891 while $kgm_taskp != $kgm_head_taskp
12892 set $kgm_head_actp = &($kgm_taskp->threads)
12893 set $kgm_actp = (struct thread *)($kgm_taskp->threads.next)
12894 while $kgm_actp != $kgm_head_actp
12895 set $kgm_thread = *(struct thread *)$kgm_actp
12896 set $kgm_thread_id = $kgm_thread.thread_id
12897 if ($kgm_thread_id == $arg0)
12900 set $kgm_id_found = 1
12903 set $kgm_actp = (struct thread *)($kgm_actp->task_threads.next)
12905 if ($kgm_id_found == 1)
12908 set $kgm_taskp = (struct task *)($kgm_taskp->tasks.next)
12910 if ($kgm_id_found == 0)
12911 printf "Not a valid thread_id\n"
12915 document showthreadfortid
12916 Syntax: showthreadfortid <thread_id>
12917 |The thread structure contains a unique thread_id value for each thread.
12918 |This command is used to retrieve the address of the thread structure(thread_t)
12919 |corresponding to a given thread_id.
12922 define showtaskbusyportsint
12923 set $kgm_isp = ((task_t)$arg0)->itk_space
12924 set $kgm_iindex = 0
12925 while ( $kgm_iindex < $kgm_isp->is_table_size )
12926 set $kgm_iep = &($kgm_isp->is_table[$kgm_iindex])
12927 if $kgm_iep->ie_bits & 0x00020000
12928 set $kgm_port = ((ipc_port_t)$kgm_iep->ie_object)
12929 if $kgm_port->ip_messages.data.port.msgcount > 0
12933 set $kgm_iindex = $kgm_iindex + 1
12937 define showtaskbusyports
12938 showtaskbusyportsint $arg0
12941 document showtaskbusyports
12942 Syntax: showtaskbusyports <task>
12943 |Routine to print information about receive rights belonging to this task that
12944 |have enqueued messages. This is often a sign of a blocked or hung process.
12947 define showallbusyports
12948 set $kgm_head_taskp = &tasks
12949 set $kgm_cur_taskp = (struct task *)($kgm_head_taskp->next)
12950 while $kgm_cur_taskp != $kgm_head_taskp
12951 showtaskbusyportsint $kgm_cur_taskp
12952 set $kgm_cur_taskp = (struct task *)($kgm_cur_taskp->tasks.next)
12956 document showallbusyports
12957 Syntax: showallbusyports
12958 |Routine to print information about all receive rights on the system that
12959 |have enqueued messages.
12962 define showallproviders
12963 set $kgm_providerp = dtrace_provider
12964 while $kgm_providerp
12965 p *(dtrace_provider_t *)$kgm_providerp
12967 set $kgm_providerp = (dtrace_provider_t *)($kgm_providerp->dtpv_next)
12971 document showallproviders
12972 Syntax: showallproviders
12973 | Display summary listing of all dtrace_providers
12976 define showmodctlheader
12987 printf " loadid loaded nenabled flags name\n"
12990 define showmodctlint
12991 set $kgm_modctlp = (struct modctl *)$arg0
12992 showptr $kgm_modctlp
12994 showptr $kgm_modctlp->mod_stale
12996 showptr $kgm_modctlp->mod_user_symbols
12998 showptr $kgm_modctlp->mod_address
13000 showptr $kgm_modctlp->mod_size
13002 printf "%6d ", $kgm_modctlp->mod_loadcnt
13003 printf "%6d ", $kgm_modctlp->mod_loaded
13004 printf "%6d ", $kgm_modctlp->mod_nenabled
13005 printf " 0x%x ", $kgm_modctlp->mod_flags
13006 printf "%s\n", $kgm_modctlp->mod_modname
13011 showmodctlint $arg0
13013 document showmodctl
13014 Syntax: (gdb) showmodctl <addr>
13015 | Display info about a dtrace modctl
13018 define showallmodctls
13020 set $kgm_modctlp = (struct modctl *)dtrace_modctl_list
13022 showmodctlint $kgm_modctlp
13023 set $kgm_modctlp = $kgm_modctlp->mod_next
13026 document showallmodctls
13027 Syntax: (gdb) showallmodctls
13028 | Display summary listing of all dtrace modctls
13031 define showfbtprobe
13032 printf "Be very patient, this traverses a large list \n"
13036 while $kgm_indx < fbt_probetab_size && !$kgm_found
13037 set $kgm_fbt_probep = (struct fbt_probe *)fbt_probetab[$kgm_indx]
13040 set $kgm_probeid = (struct fbt_probe *)$kgm_fbt_probep->fbtp_id
13041 if $kgm_probeid == $arg0
13045 set $kgm_fbt_probep = $kgm_fbt_probep->fbtp_hashnext
13046 while $kgm_fbt_probep
13048 set $kgm_probeid = (struct fbt_probe *)$kgm_fbt_probep->fbtp_id
13049 if $kgm_probeid == $arg0
13053 set $kgm_fbt_probep = $kgm_fbt_probep->fbtp_hashnext
13061 printf "fbt_probetab[index=%d], depth=%d, 0x%x\n", $kgm_indx, $kgm_depth, $kgm_fbt_probep
13062 printf "(gdb) p *(struct fbt_probe *)0x%x\n", $kgm_fbt_probep
13063 p *(struct fbt_probe *)$kgm_fbt_probep
13064 set $kgm_fbtp_ctl = (struct fbt_probe *)$kgm_fbt_probep->fbtp_ctl
13065 showmodctl $kgm_fbtp_ctl
13070 document showfbtprobe
13071 Syntax: (gdb) showfbtprobe <id>
13072 | Display info about an fbt probe given an id.
13073 | Traverses fbt_probetab and matches <id> with fbtp_id.
13074 | The <id> is found using dtrace -l
13077 define showzstacktrace
13078 set $kgm_trace = (void*)$arg0
13080 set $kgm_trace_size = 15
13083 set $kgm_trace_size = $arg1
13085 set $kgm_trace_current = 0
13086 while ($kgm_trace_current < $kgm_trace_size)
13087 set $kgm_trace_addr = (void**)$kgm_trace + $kgm_trace_current
13088 set $kgm_trace_value = *((void**)$kgm_trace_addr)
13090 output /a $kgm_trace_value
13091 set $kgm_trace_current = $kgm_trace_current + 1
13096 document showzstacktrace
13097 Syntax: showzstacktrace <saved stacktrace> [size]
13098 | Routine to print a stacktrace stored by OSBacktrace.
13099 | size is optional, defaults to 15.
13103 set $kgm_zallocation = zallocations[$arg0]
13104 print $kgm_zallocation
13105 showztrace $kgm_zallocation->za_trace_index
13108 document showzalloc
13109 Syntax: showzalloc <index>
13110 | Prints a zallocation from the zallocations array based off its index,
13111 | and prints the associated symbolicated backtrace.
13115 set $kgm_ztrace = &ztraces[$arg0]
13116 showztraceaddr $kgm_ztrace
13119 document showztrace
13120 Syntax: showztrace <trace index>
13121 | Prints the backtrace from the ztraces array at index
13124 define showztraceaddr
13126 showzstacktrace $arg0->zt_stack ($arg0)->zt_depth
13129 document showztraceaddr
13130 Syntax: showztraceaddr <trace address>
13131 | Prints the struct ztrace passed in
13134 #TODO: Iterate through the hash table, or make top_ztrace accurate in the face of deallocations (better idea).
13135 define showtopztrace
13136 set $kgm_top_ztrace = top_ztrace
13137 printf "Index: %d\n", (top_ztrace - ztraces)
13138 showztraceaddr $kgm_top_ztrace
13141 document showtopztrace
13142 Syntax: showtopztrace
13143 | Shows the ztrace with the biggest size. (according to top_ztrace, not by iterating through the hash table)
13147 set $kgm_zallocation_current_index = 0
13148 set $kgm_zallocations_count = 0
13149 set $kgm_max_zallocation = zleak_alloc_buckets
13150 printf "INDEX ADDRESS "
13154 printf "TRACE SIZE\n"
13155 while ($kgm_zallocation_current_index < $kgm_max_zallocation)
13156 set $kgm_zallocation_current = zallocations[$kgm_zallocation_current_index]
13157 if ($kgm_zallocation_current->element != 0)
13158 printf "%5d %p ", $kgm_zallocation_current_index, $kgm_zallocation_current->za_element
13159 printf "%5d %6lu\n", $kgm_zallocation_current->za_trace_index, $kgm_zallocation_current->za_size
13160 set $kgm_zallocations_count = $kgm_zallocations_count + 1
13162 set $kgm_zallocation_current_index = $kgm_zallocation_current_index + 1
13164 printf "Total allocations: %d\n", $kgm_zallocations_count
13167 document showzallocs
13168 Syntax: showzallocs
13169 | Prints all allocations in the zallocations table
13172 define showzallocsfortrace
13173 set $kgm_zallocation_current_index = 0
13174 set $kgm_zallocations_count = 0
13175 set $kgm_max_zallocation = zleak_alloc_buckets
13176 printf "INDEX ADDRESS "
13181 while ($kgm_zallocation_current_index < $kgm_max_zallocation)
13182 set $kgm_zallocation_current = zallocations[$kgm_zallocation_current_index]
13183 if ($kgm_zallocation_current->element != 0 && $kgm_zallocation_current->za_trace_index == $arg0)
13184 printf "%5d %p ", $kgm_zallocation_current_index, $kgm_zallocation_current->za_element
13185 printf "%6lu\n", $kgm_zallocation_current->size
13186 set $kgm_zallocations_count = $kgm_zallocations_count + 1
13188 set $kgm_zallocation_current_index = $kgm_zallocation_current_index + 1
13190 printf "Total allocations: %d\n", $kgm_zallocations_count
13193 document showzallocsfortrace
13194 Syntax: showzallocsfortrace <trace index>
13195 | Prints all allocations pointing to the passed in trace's index into ztraces by looking through zallocations table
13202 document showztraces
13203 Syntax: showztraces
13204 | Prints all traces with size > 0
13207 define showztracesabove
13208 set $kgm_ztrace_current_index = 0
13209 set $kgm_ztrace_count = 0
13210 set $kgm_max_ztrace = zleak_trace_buckets
13211 printf "INDEX SIZE\n"
13212 while ($kgm_ztrace_current_index < $kgm_max_ztrace)
13213 set $kgm_ztrace_current = ztraces[$kgm_ztrace_current_index]
13214 if ($kgm_ztrace_current->zt_size > $arg0)
13215 printf "%5d %6lu\n", $kgm_ztrace_current_index, $kgm_ztrace_current->zt_size
13216 set $kgm_ztrace_count = $kgm_ztrace_count + 1
13218 set $kgm_ztrace_current_index = $kgm_ztrace_current_index + 1
13220 printf "Total traces: %d\n", $kgm_ztrace_count
13223 document showztracesabove
13224 Syntax: showztracesabove <size>
13225 | Prints all traces with size greater than X
13228 define showztracehistogram
13229 set $kgm_ztrace_current_index = 0
13230 set $kgm_ztrace_count = 0
13231 set $kgm_max_ztrace = zleak_trace_buckets
13232 printf "INDEX HIT_COUNT COLLISIONS\n"
13233 while ($kgm_ztrace_current_index < $kgm_max_ztrace)
13234 set $kgm_ztrace_current = ztraces[$kgm_ztrace_current_index]
13235 if ($kgm_ztrace_current->zt_hit_count != 0)
13236 printf "%5d %5d %5d\n", $kgm_ztrace_current_index, $kgm_ztrace_current->zt_hit_count, $kgm_ztrace_current->zt_collisions
13237 set $kgm_ztrace_count = $kgm_ztrace_count + 1
13239 set $kgm_ztrace_current_index = $kgm_ztrace_current_index + 1
13241 printf "Total traces: %d\n", $kgm_ztrace_count
13244 document showztracehistogram
13245 Syntax: showztracehistogram
13246 | Prints the histogram of the ztrace table
13249 define showzallochistogram
13250 set $kgm_zallocation_current_index = 0
13251 set $kgm_zallocations_count = 0
13252 set $kgm_max_zallocation = zleak_alloc_buckets
13253 printf "INDEX HIT_COUNT\n"
13254 while ($kgm_zallocation_current_index < $kgm_max_zallocation)
13255 set $kgm_zallocation_current = zallocations[$kgm_zallocation_current_index]
13256 if ($kgm_zallocation_current->za_hit_count != 0)
13257 printf "%5d %5d\n", $kgm_zallocation_current_index, $kgm_zallocation_current->za_hit_count
13258 set $kgm_zallocations_count = $kgm_zallocations_count + 1
13260 set $kgm_zallocation_current_index = $kgm_zallocation_current_index + 1
13262 printf "Total allocations: %d\n", $kgm_zallocations_count
13265 document showzallochistogram
13266 Syntax: showzallochistogram
13267 | Prints the histogram for the zalloc table
13271 printf "z_alloc_collisions: %u, z_trace_collisions: %u\n", z_alloc_collisions, z_trace_collisions
13272 printf "z_alloc_overwrites: %u, z_trace_overwrites: %u\n", z_alloc_overwrites, z_trace_overwrites
13273 printf "z_alloc_recorded: %u, z_trace_recorded: %u\n", z_alloc_recorded, z_trace_recorded
13276 document showzstats
13278 | Prints the zone leak detection stats
13282 set $kgm_au_sentry_hash_table_size = 97
13284 define showsession1
13285 set $p = (struct au_sentry *)$arg0
13287 printf " 0x%08x 0x%08x 0x%016x", $p->se_auinfo.ai_asid, $p->se_auinfo.ai_auid, $p->se_auinfo.ai_flags
13288 printf " %3ld %3ld", $p->se_refcnt, $p->se_procnt
13292 define showsessionhdr
13293 printf "au_sentry "
13295 printf " ASID AUID FLAGS C P\n"
13303 document showsession
13304 Syntax: showsession
13305 | Display info about a specified audit session
13308 define showallsessions
13310 set $kgm_au_sentry_hash_table = au_sentry_bucket
13311 set $i = $kgm_au_sentry_hash_table_size - 1
13313 set $p = $kgm_au_sentry_hash_table[$i].lh_first
13316 set $p = $p->se_link.le_next
13322 document showallsessions
13323 Syntax: showallsessions
13324 | Prints the audit sessions in the global hash table
13327 define showauhistorystack
13329 set $pp = (void **)$arg1
13337 define showauhistory1
13338 set $p = (struct au_history *)$arg0
13339 set $stack_depth = $p->stack_depth
13340 set $stack = $p->stack
13358 printf " 0x%08x 0x%08x 0x%016x", $p->se_auinfo.ai_asid, $p->se_auinfo.ai_auid, $p->se_auinfo.ai_flags
13359 printf " %3ld %3ld", $p->se_refcnt, $p->se_procnt
13361 showauhistorystack $stack_depth $stack
13364 define showauhistory
13365 set $i = (au_history_index-1) % au_history_size
13366 if au_history_index >= au_history_size
13367 set $n = au_history_size
13369 set $n = au_history_index
13372 if au_history[$i].ptr != 0 && (0 == $arg0 || au_history[$i].ptr == $arg0)
13373 printf "[% 4d] ", $i
13374 showauhistory1 &au_history[$i]
13377 set $i = ($i - 1) % au_history_size
13381 define showallauhistory
13385 define showkwqheader
13390 printf " inqueue fakecount highseq lowseq flags lastunlock p_rwwc"
13396 set $kgm_kwq = (ksyn_wait_queue_t)$arg0
13399 showptr $kgm_kwq->kw_addr
13401 printf " %d ", $kgm_kwq->kw_inqueue
13402 printf " %d ", $kgm_kwq->kw_fakecount
13403 printf " 0x%x ", $kgm_kwq->kw_highseq
13404 printf " 0x%x ", $kgm_kwq->kw_lowseq
13405 printf " 0x%x ", $kgm_kwq->kw_flags
13406 printf " 0x%x ", $kgm_kwq->kw_lastunlockseq
13407 printf " 0x%x ", $kgm_kwq->kw_pre_rwwc
13417 Syntax: (gdb) show_kwq <kwq>
13418 | Display info about one ksyn_wait_queue
13421 # Internal routine used by "showpthread_mutex" to abstract possible loads from
13423 define _loadfrommutex
13425 set $kgm_loadval = *(uintptr_t *)$arg0
13427 if ($kgm_x86_abi == 0xe)
13428 set $kgm_loadval = *(uint32_t *)$arg0
13430 if ($kgm_x86_abi == 0xf)
13431 if ($kgm_mtype == $kgm_mtype_i386)
13433 set $kgm_loadval = $kgm_k32read64
13435 set $kgm_loadval = *(uint32_t *)$arg0
13442 define show_pthreadmutex
13443 set $newact = (struct thread *) $arg0
13444 set $ourtask = (struct task *)($newact->task)
13445 set $our_user_is64 = ($ourtask->taskFeatures[0] & 0x80000000)
13447 set $mutex = (void *)$arg1
13448 set kdp_pmap = $newact->task->map->pmap
13451 set $newiss = (x86_saved_state_t *) ($newact->machine.pcb->iss)
13452 set $kgm_x86_abi = $newiss.flavor
13453 if ($our_user_is64 != 0)
13454 printf "\tUser 64Bit\n "
13455 printf "\tSignature: "
13456 set $nextval = $mutex
13457 _loadfrommutex $nextval
13458 printf "0x%x\n",$kgm_loadval
13460 set $nextval = $mutex + 12
13461 _loadfrommutex $nextval
13462 printf "0x%x\n",$kgm_loadval
13464 set $nextval = $mutex + 20
13465 _loadfrommutex $nextval
13466 printf "0x%x ",$kgm_loadval
13467 set $nextval = $mutex + 24
13468 _loadfrommutex $nextval
13469 printf "0x%x ",$kgm_loadval
13470 set $nextval = $mutex + 28
13471 _loadfrommutex $nextval
13472 printf "0x%x\n",$kgm_loadval
13473 printf "\ttid[0]: "
13474 set $nextval = $mutex + 32
13475 _loadfrommutex $nextval
13476 printf "0x%x\n",$kgm_loadval
13477 printf "\ttid[1]: "
13478 set $nextval = $mutex + 36
13479 _loadfrommutex $nextval
13480 printf "0x%x\n",$kgm_loadval
13482 printf "\tUser 32Bit\n "
13483 printf "\tSignature: "
13484 set $nextval = $mutex
13485 _loadfrommutex $nextval
13486 printf "0x%x\n",$kgm_loadval
13488 set $nextval = $mutex + 8
13489 _loadfrommutex $nextval
13490 printf "0x%x\n",$kgm_loadval
13492 set $nextval = $mutex + 16
13493 _loadfrommutex $nextval
13494 printf "0x%x ",$kgm_loadval
13495 set $nextval = $mutex + 20
13496 _loadfrommutex $nextval
13497 printf "0x%x ",$kgm_loadval
13498 set $nextval = $mutex + 24
13499 _loadfrommutex $nextval
13500 printf "0x%x\n",$kgm_loadval
13501 printf "\ttid[0]: "
13502 set $nextval = $mutex + 32
13503 _loadfrommutex $nextval
13504 printf "0x%x\n",$kgm_loadval
13505 printf "\ttid[1]: "
13506 set $nextval = $mutex + 36
13507 _loadfrommutex $nextval
13508 printf "0x%x\n",$kgm_loadval
13515 document show_pthreadmutex
13516 Syntax: (gdb) show_pthreadmutex <thread> <user_mutexaddr>
13517 | Display the mutex contents from userspace.
13521 define show_pthreadcondition
13522 set $newact = (struct thread *) $arg0
13523 set $ourtask = (struct task *)($newact->task)
13524 set $our_user_is64 = ($ourtask->taskFeatures[0] & 0x80000000)
13526 set $cond = (void *)$arg1
13527 set kdp_pmap = $newact->task->map->pmap
13530 set $newiss = (x86_saved_state_t *) ($newact->machine.pcb->iss)
13531 set $kgm_x86_abi = $newiss.flavor
13532 if ($our_user_is64 != 0)
13533 printf "\tUser 64Bit\n "
13534 printf "\tSignature: "
13535 set $nextval = $cond
13536 _loadfrommutex $nextval
13537 printf "0x%x\n",$kgm_loadval
13539 set $nextval = $cond + 12
13540 _loadfrommutex $nextval
13541 printf "0x%x\n",$kgm_loadval
13543 set $nextval = $cond + 24
13544 _loadfrommutex $nextval
13545 printf "0x%x ",$kgm_loadval
13546 set $nextval = $cond + 28
13547 _loadfrommutex $nextval
13548 printf "0x%x ",$kgm_loadval
13549 set $nextval = $cond + 32
13550 _loadfrommutex $nextval
13551 printf "0x%x\n",$kgm_loadval
13552 printf "\tMutex lowaddr: "
13553 set $nextval = $cond + 16
13554 _loadfrommutex $nextval
13555 printf "0x%08x\n",$kgm_loadval
13556 printf "\tMutex highaddr: "
13557 set $nextval = $cond + 20
13558 _loadfrommutex $nextval
13559 printf "0x%x\n",$kgm_loadval
13561 printf "\tUser 32Bit\n "
13562 printf "\tSignature: "
13563 set $nextval = $cond
13564 _loadfrommutex $nextval
13565 printf "0x%x\n",$kgm_loadval
13567 set $nextval = $cond + 8
13568 _loadfrommutex $nextval
13569 printf "0x%x\n",$kgm_loadval
13571 set $nextval = $cond + 16
13572 _loadfrommutex $nextval
13573 printf "0x%x ",$kgm_loadval
13574 set $nextval = $cond + 20
13575 _loadfrommutex $nextval
13576 printf "0x%x ",$kgm_loadval
13577 set $nextval = $cond + 24
13578 _loadfrommutex $nextval
13579 printf "0x%x\n",$kgm_loadval
13580 printf "\tMutex addr: "
13581 set $nextval = $cond + 12
13582 _loadfrommutex $nextval
13583 printf "0x%x\n",$kgm_loadval
13590 document show_pthreadcondition
13591 Syntax: (gdb) show_pthreadcondition <thread> <user_cvaddr>
13592 | Display the condition variable contents from userspace.
13595 define processortimers
13596 set $kgm_p = processor_list
13597 printf "Processor\t\t\t Last dispatch\t\t Next deadline\t\t difference\n"
13599 printf "Processor %d: %p\t", $kgm_p->cpu_id, $kgm_p
13600 printf " 0x%016llx\t", $kgm_p->last_dispatch
13601 set $kgm_rt_timer = &(cpu_data_ptr[$kgm_p->cpu_id].rtclock_timer)
13602 printf " 0x%016llx \t", $kgm_rt_timer->deadline
13603 set $kgm_rt_diff = ((long long)$kgm_p->last_dispatch) - ((long long)$kgm_rt_timer->deadline)
13604 printf " 0x%016llx ", $kgm_rt_diff
13605 # normally the $kgm_rt_diff will be close to the last dispatch time, or negative
13606 # When it isn't, mark the result as bad. This is a suggestion, not an absolute
13607 if ( ($kgm_rt_diff > 0) && ((long long)$kgm_p->last_dispatch) - ($kgm_rt_diff + 1) > 0 )
13608 printf "probably BAD\n"
13612 # dump the call entries (Intel only)
13613 if (($kgm_mtype & $kgm_mtype_x86_mask) == $kgm_mtype_x86_any)
13614 printf "Next deadline set at: 0x%016llx. Timer call list:", $kgm_rt_timer->when_set
13615 set $kgm_entry = (queue_t *)$kgm_rt_timer->queue
13616 if ($kgm_entry == $kgm_rt_timer)
13617 printf " (empty)\n"
13619 printf "\n entry: "
13621 printf "deadline soft_deadline delta (*func)(param0,param1)\n"
13622 while $kgm_entry != $kgm_rt_timer
13623 set $kgm_timer_call = (timer_call_t) $kgm_entry
13624 set $kgm_call_entry = (struct call_entry *) $kgm_entry
13627 printf ": 0x%016llx 0x%016llx 0x%08x (%p)(%p,%p)\n", \
13628 $kgm_call_entry->deadline, \
13629 $kgm_timer_call->soft_deadline, \
13630 ($kgm_call_entry->deadline - $kgm_timer_call->soft_deadline), \
13631 $kgm_call_entry->func, \
13632 $kgm_call_entry->param0, $kgm_call_entry->param1
13633 set $kgm_entry = $kgm_entry->next
13637 set $kgm_p = $kgm_p->processor_list
13642 document processortimers
13643 Syntax: (gdb) processortimers
13644 | Print details of processor timers, noting any timer which might be suspicious
13647 define maplocalcache
13648 if ($kgm_mtype == $kgm_mtype_arm)
13649 mem 0x80000000 0xefffffff cache
13650 set dcache-linesize-power 9
13651 printf "GDB memory caching enabled. Be sure to disable by calling flushlocalcache before detaching or connecting to a new device\n"
13655 document maplocalcache
13656 Syntax: (gdb) maplocalcache
13657 | Sets up memory regions for GDB to cache on read. Significantly increases debug speed over KDP
13660 define flushlocalcache
13661 if ($kgm_mtype == $kgm_mtype_arm)
13663 printf "GDB memory caching disabled.\n"
13667 document flushlocalcache
13668 Syntax: (gdb) flushlocalcache
13669 | Clears all memory regions