The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/kgmacros

Version: -  FREEBSD  -  FREEBSD11  -  FREEBSD10  -  FREEBSD9  -  FREEBSD92  -  FREEBSD91  -  FREEBSD90  -  FREEBSD8  -  FREEBSD82  -  FREEBSD81  -  FREEBSD80  -  FREEBSD7  -  FREEBSD74  -  FREEBSD73  -  FREEBSD72  -  FREEBSD71  -  FREEBSD70  -  FREEBSD6  -  FREEBSD64  -  FREEBSD63  -  FREEBSD62  -  FREEBSD61  -  FREEBSD60  -  FREEBSD5  -  FREEBSD55  -  FREEBSD54  -  FREEBSD53  -  FREEBSD52  -  FREEBSD51  -  FREEBSD50  -  FREEBSD4  -  FREEBSD3  -  FREEBSD22  -  linux-2.6  -  linux-2.4.22  -  MK83  -  MK84  -  PLAN9  -  DFBSD  -  NETBSD  -  NETBSD5  -  NETBSD4  -  NETBSD3  -  NETBSD20  -  OPENBSD  -  xnu-517  -  xnu-792  -  xnu-792.6.70  -  xnu-1228  -  xnu-1456.1.26  -  xnu-1699.24.8  -  xnu-2050.18.24  -  OPENSOLARIS  -  minix-3-1-1 
SearchContext: -  none  -  3  -  10 

    1 
    2 # Kernel gdb macros
    3 #
    4 #  These gdb macros should be useful during kernel development in
    5 #  determining what's going on in the kernel.
    6 #
    7 #  All the convenience variables used by these macros begin with $kgm_
    8 
    9 set print asm-demangle on
   10 set cp-abi gnu-v2
   11 
   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
   16 
   17 echo Loading Kernel GDB Macros package.  Type "help kgm" for more info.\n
   18 
   19 define kgm
   20 printf ""
   21 echo  These are the gdb macros for kernel debugging.  Type "help kgm" for more info.\n
   22 end
   23 
   24 document kgm
   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>
   30 |
   31 | The following macros are available in this package:
   32 |     showversion    Displays a string describing the remote kernel version
   33 |
   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
   48 |
   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)
   55 |
   56 |     setfindregistrystr  Set the encoded string for matching with
   57 |                         findregistryentry or findregistryprop (created from
   58 |                         strcmp_arg_pack64)
   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
   62 |                         the encoded string
   63 |
   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
   73 |
   74 |     showact        Display info about a thread specified by activation
   75 |     showactstack   Display the stack for a thread specified by activation
   76 |
   77 |     showmap        Display info about the specified vm_map
   78 |     showmapvme     Display a summary list of the specified vm_map's entries
   79 |
   80 |     showipc        Display info about the specified ipc space
   81 |     showrights     Display a summary list of all the rights in an ipc space
   82 |
   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
   92 |
   93 |     showinitchild  Print out all processes in the system which are children of init process
   94 |
   95 |     showkext       Display info about a kext (alias: showkmod)
   96 |     showkextaddr   Given an address, display the kext and offset (alias: showkmodaddr)
   97 |
   98 |     dumpcallqueue  Dump out all the entries given a queue head
   99 |
  100 |     showallmtx     Display info about mutexes usage
  101 |     showallrwlck   Display info about reader/writer locks usage
  102 |
  103 |     zprint         Display info about the memory zones
  104 |     showioalloc    Display info about iokit allocations
  105 |     paniclog       Display the panic log info
  106 |
  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 
  110 |                    activation
  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
  114 |
  115 |     switchtouserthread Switch to the user context of the specified thread
  116 |     resetstacks    Return to the original kernel context
  117 |
  118 |     resetctx       Reset context
  119 |     resume_on      Resume when detaching from gdb
  120 |     resume_off     Don't resume when detaching from gdb 
  121 |
  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
  128 |
  129 |     switchtocorethread Corefile version of "switchtoact"
  130 |     resetcorectx   Corefile version of "resetctx"
  131 |
  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)
  140 |
  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
  147 |
  148 |     readmsr64      Read 64-bits from the specified MSR
  149 |     writemsr64     Write 64-bits into the specified MSR
  150 |
  151 |     rtentry_showdbg Print the debug information of a route entry
  152 |     rtentry_trash  Walk the list of trash route entries
  153 |
  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
  159 |
  160 |     ndpr_showdbg   Print the debug information of a nd_prefix structure
  161 |     nddr_showdbg   Print the debug information of a nd_defrouter structure
  162 |
  163 |     imo_showdbg    Print the debug information of a ip_moptions structure
  164 |     im6o_showdbg   Print the debug information of a ip6_moptions structure
  165 |
  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
  171 |
  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
  186 |
  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
  190 |
  191 |     showbootargs       Display boot arguments passed to the target kernel
  192 |     showbootermemorymap Dump phys memory map from EFI
  193 |
  194 |     systemlog          Display the kernel's printf ring buffer
  195 |
  196 |     hexdump            Show the contents of memory as a hex/ASCII dump
  197 |
  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
  215 |
  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
  222 |
  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
  226 |
  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
  230 |
  231 |     show_rt_inet       Display the IPv4 routing table
  232 |     show_rt_inet6      Display the IPv6 routing table
  233 |
  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
  239 |
  240 |     showMCAstate      Print machine-check register state after MC exception.
  241 |
  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
  247 |
  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
  251 |
  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
  258 |     
  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
  262 |
  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     
  266 |
  267 |     pmap_walk     Perform a page-table walk
  268 |     pmap_vtop     Translate a virtual address to physical address
  269 |
  270 |     showuserdyldinfo       Show dyld information and error messages
  271 |                            in the target task
  272 |     showuserlibraries      Show binary images known by dyld in the
  273 |                            target task
  274 |     showallvmstats    Prints a summary of vm statistics in a table format
  275 |     memstats                  Displays memory statistics in a table format
  276 |
  277 |     showthreadfortid  Displays the address of the thread structure
  278 |                       for a given thread_id value. 
  279 |     
  280 |     strcmp_nomalloc   A version of strcmp that avoids the use of malloc
  281 |                       through the use of encoded strings created via
  282 |                       strcmp_arg_pack64.
  283 |     strcmp_arg_pack64 Pack a string into a 64-bit quantity for use by
  284 |                       strcmp_nomalloc
  285 |
  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
  295 |
  296 |     lapic_read32      Read APIC entry
  297 |     lapic_write32     Write APIC entry
  298 |     lapic_dump        Dump APIC entries
  299 |
  300 |     ioapic_read32     Read IOAPIC entry
  301 |     ioapic_write32    Write IOAPIC entry
  302 |     ioapic_dump       Dump IOAPIC entries
  303 |
  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
  309 |         
  310 |     maplocalcache     Enable local caching in GDB for improved debug speeds
  311 |     flushlocalcahe    Disable local caching in GDB (deletes all memory regions)
  312 |
  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.
  315 end
  316 
  317 # This macro should appear before any symbol references, to facilitate
  318 # a gdb "source" without a loaded symbol file.
  319 define showversion
  320     kdp-kernelversion
  321 end
  322 
  323 document showversion
  324 Syntax: showversion
  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
  331 | correctly.
  332 end
  333 
  334 set $kgm_mtype_ppc      = 0x00000012
  335 set $kgm_mtype_arm      = 0x0000000C
  336 
  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
  341 
  342 set $kgm_mtype = ((unsigned int *)&_mh_execute_header)[1]
  343 set $kgm_lp64 = $kgm_mtype & 0x01000000
  344 
  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
  349 
  350 set $kgm_kdp_pkt_data_len   = 128
  351 
  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
  357 
  358 # after data packet
  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
  361 
  362 set $kgm_kdp_pkt_hostreboot = 0x13
  363 set $kgm_kdp_pkt_hdr_size   = 8
  364 
  365 
  366 set $kgm_readphys_force_kdp     = 0
  367 set $kgm_readphys_force_physmap = 0
  368 
  369 set $kgm_lcpu_self      = 0xFFFE
  370 
  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
  376 
  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
  381 
  382 set $kgm_show_kmod_syms = 0
  383 
  384 # send a manual packet header that doesn't require knowing the location
  385 # of everything.
  386 define manualhdrint
  387        set $req = $arg0
  388 
  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
  393        end
  394        if ($kgm_mtype == $kgm_mtype_x86_64)
  395           set $hdrp = (uint64_t *) $kgm_manual_pkt_x86_64
  396        end
  397        if ($kgm_mtype == $kgm_mtype_arm)
  398           set $hdrp = (uint32_t *) $kgm_manual_pkt_arm
  399        end
  400 
  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
  404 
  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
  410 
  411        # dummy to make sure manual packet is executed
  412        set $kgm_dummy = &_mh_execute_header
  413 end
  414 
  415 # Print a pointer
  416 define showptr
  417     if $kgm_lp64
  418         printf "0x%016llx", $arg0
  419     else
  420         printf "0x%08x", $arg0
  421     end
  422 end
  423 
  424 # for headers, leave 8 chars for LP64 pointers
  425 define showptrhdrpad
  426     if $kgm_lp64
  427         printf "        "
  428     end
  429 end
  430 
  431 # Print a userspace pointer, using $kgm_tasp
  432 define showuserptr
  433     set $kgm_userptr_task_64 = ( $kgm_taskp->taskFeatures[0] & 0x80000000)
  434     if $kgm_userptr_task_64
  435         printf "0x%016llx", $arg0
  436     else
  437         printf "0x%08x", $arg0
  438     end
  439 end
  440 
  441 define showkmodheader
  442     printf   "kmod_info "
  443     showptrhdrpad
  444     printf "  address   "
  445     showptrhdrpad
  446     printf "  size      "
  447     showptrhdrpad
  448     printf "  id    refs     version  name\n"
  449 end
  450 
  451 define showkmodint
  452     set $kgm_kmodp = (struct kmod_info *)$arg0
  453     showptr $kgm_kmodp
  454     printf "  "
  455     showptr $kgm_kmodp->address
  456     printf "  "
  457     showptr $kgm_kmodp->size
  458     printf "  "
  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
  463 end
  464 
  465 # cached info of the last kext found, to speed up subsequent lookups
  466 set $kgm_pkmod = 0
  467 set $kgm_pkmodst = 0
  468 set $kgm_pkmoden = 0
  469 
  470 define showkmodaddrint
  471     showptr $arg0
  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
  475     else
  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
  479             set $kgm_kmodp = 0
  480         end
  481         while $kgm_kmodp
  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
  488                 set $kgm_kmodp = 0
  489             else
  490                 set $kgm_kmodp = $kgm_kmodp->next
  491             end
  492         end
  493     end
  494 end
  495 
  496 define showkmodaddr
  497     showkmodaddrint $arg0
  498 end
  499 document showkmodaddr
  500 Syntax: (gdb) showkmodaddr <addr>
  501 | Given an address, print the offset and name for the kmod containing it
  502 end
  503 
  504 define showkmod
  505     showkmodheader
  506     showkmodint $arg0
  507 end
  508 document showkmod
  509 Syntax: (gdb) showkmod <kmod>
  510 | Routine to print info about a kext
  511 end
  512 
  513 define showkext
  514     showkmod $arg0
  515 end
  516 document showkext
  517 Syntax: (gdb) showkext <kmod_info_address>
  518 | Routine to print info about a kext
  519 end
  520 
  521 define showallkmods
  522     showkmodheader
  523     set $kgm_kmodp = (struct kmod_info *)kmod
  524     while $kgm_kmodp
  525         showkmodint $kgm_kmodp
  526         set $kgm_kmodp = $kgm_kmodp->next
  527     end
  528 end
  529 document showallkmods
  530 Syntax: (gdb) showallkmods
  531 | Routine to print a summary listing of all loaded kexts
  532 end
  533 
  534 define showallkexts
  535     showallkmods
  536 end
  537 document showallkexts
  538 Syntax: (gdb) showallkexts
  539 | Routine to print a summary listing of all loaded kexts
  540 end
  541 
  542 # See OSKextVersion.c for the C code this is based on
  543 #
  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
  548 
  549 define printoskextversion
  550     set $vers_scratch = $arg0
  551 
  552     if ($vers_scratch == -1)
  553         printf "(invalid)"
  554     else
  555      
  556         set $vers_major =  $vers_scratch / $KGM_OSKEXT_VERS_MAJ_MULT
  557 
  558         set $vers_scratch = $vers_scratch - ($vers_major * $KGM_OSKEXT_VERS_MAJ_MULT)
  559         set $vers_minor = $vers_scratch / $KGM_OSKEXT_VERS_MIN_MULT
  560 
  561         set $vers_scratch = $vers_scratch - ( $vers_minor * $KGM_OSKEXT_VERS_MIN_MULT)
  562         set $vers_revision =  $vers_scratch / $KGM_OSKEXT_VERS_REV_MULT
  563 
  564         set $vers_scratch = $vers_scratch - ( $vers_revision * $KGM_OSKEXT_VERS_REV_MULT)
  565         set $vers_stage =  $vers_scratch / $KGM_OSKEXT_VERS_STAGE_MULT
  566 
  567         set $vers_scratch = $vers_scratch - ( $vers_stage * $KGM_OSKEXT_VERS_STAGE_MULT)
  568         set $vers_stagelevel =  $vers_scratch
  569 
  570         printf "%d.%d", $vers_major, $vers_minor
  571         if ($vers_revision > 0)
  572             printf ".%d", $vers_revision
  573         end
  574         
  575         if ($vers_stage == 1)
  576             printf "d"
  577         end
  578         if ($vers_stage == 3)
  579             printf "a"
  580         end
  581         if ($vers_stage == 5)
  582             printf "b"
  583         end
  584         if ($vers_stage == 7)
  585             printf "fc"
  586         end
  587         if ($vers_stage == 1 || $vers_stage == 3 || $vers_stage == 5 || $vers_stage == 7)
  588             printf "%d", $vers_stagelevel
  589         end
  590     end
  591 end
  592 
  593 define showallknownkexts
  594    set $kext_count = sKextsByID->count
  595    set $kext_index = 0
  596    printf "%d kexts in sKextsByID:\n", $kext_count
  597 
  598    printf "OSKext *    "
  599    showptrhdrpad
  600    printf "load_addr   "
  601    showptrhdrpad
  602    
  603    printf " id  name (version)\n"
  604 
  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
  608 
  609        showptr $oskext
  610        printf "  "
  611 
  612        if ($oskext->flags.loaded)
  613            showptr $oskext->kmod_info
  614            printf "  "
  615            printf "%3d", $oskext->loadTag
  616        else
  617            showptrhdrpad
  618            printf " -------- "
  619            printf "  "
  620            printf " --"
  621         end
  622         printf "  "
  623 
  624        printf "%.64s (", $kext_id
  625        printoskextversion (uint64_t)$oskext->version
  626        printf ")\n"
  627        set $kext_index = $kext_index + 1
  628    end
  629 end
  630 document showallknownkexts
  631 Syntax: (gdb) showallknownkexts
  632 | Routine to print a summary listing of all kexts, loaded or not
  633 end
  634 
  635 define showactheader
  636     printf "          "
  637     showptrhdrpad
  638     printf "  thread    "
  639     showptrhdrpad
  640     printf "    thread_id "
  641     showptrhdrpad
  642     printf "  processor "
  643     showptrhdrpad
  644     printf "   pri io_policy   state    wait_queue"
  645     showptrhdrpad
  646     printf "  wait_event\n"
  647 end
  648 
  649 
  650 define showactint
  651         printf "            "
  652         showptrhdrpad
  653         set $kgm_thread = *(struct thread *)$arg0
  654         showptr $arg0
  655         if ($kgm_thread.static_param)
  656            printf "[WQ]"
  657         else
  658            printf "    "
  659         end
  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)
  664            set $kgm_printed = 0
  665            set $kgm_uthread = (struct uthread *)$kgm_thread.uthread
  666            if ($kgm_uthread->uu_flag & 0x400)
  667               printf "RAGE "
  668            else
  669               printf "     "
  670            end
  671            set $diskpolicy = 0
  672            if ($kgm_thread->ext_appliedstate.hw_disk != 0)
  673                 set $diskpolicy = $kgm_thread->ext_appliedstate.hw_disk
  674            else 
  675                 if ($kgm_thread->appliedstate.hw_disk != 0)
  676                         set $diskpolicy = $kgm_thread->appliedstate.hw_disk
  677                 end
  678            end
  679            if ($kgm_thread->ext_appliedstate.hw_bg != 0)
  680                 set $diskpolicy = 5
  681            end
  682            if ($kgm_thread->appliedstate.hw_bg != 0)
  683                 set $diskpolicy = 4
  684            end
  685            if ($diskpolicy == 2)
  686               printf "PASS    "
  687               set $kgm_printed = 1
  688            end
  689            if ($diskpolicy == 3)
  690               printf "THROT   "
  691               set $kgm_printed = 1
  692            end
  693            if ($diskpolicy == 4)
  694               printf "BG_THRT "
  695               set $kgm_printed = 1
  696            end
  697            if ($diskpolicy == 5)
  698               printf "EBG_THRT"
  699               set $kgm_printed = 1
  700            end
  701            if ($kgm_printed == 0)
  702               printf "        "
  703            end
  704         end
  705         set $kgm_state = $kgm_thread.state
  706         if $kgm_state & 0x80
  707             printf "I" 
  708         end
  709         if $kgm_state & 0x40
  710             printf "P" 
  711         end
  712         if $kgm_state & 0x20
  713             printf "A" 
  714         end
  715         if $kgm_state & 0x10
  716             printf "H" 
  717         end
  718         if $kgm_state & 0x08
  719             printf "U" 
  720         end
  721         if $kgm_state & 0x04
  722             printf "R" 
  723         end
  724         if $kgm_state & 0x02
  725             printf "S" 
  726         end
  727         if $kgm_state & 0x01
  728             printf "W"
  729             printf "\t    " 
  730             showptr $kgm_thread.wait_queue
  731             printf "  "
  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
  735                 else
  736                         output /a $kgm_thread.wait_event
  737                 end
  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
  742                     end
  743                 end
  744         end
  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
  749            end
  750         end
  751         if $arg1 != 0
  752             if ($kgm_thread.kernel_stack != 0)
  753                 if ($kgm_thread.uthread != 0)
  754                         printf "\n          "
  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
  759                                 printf "\n                "
  760                                 show_kwq $kwq
  761                                 printf "          "
  762                         end
  763                 end
  764                 if ($kgm_thread.reserved_stack != 0)
  765                         printf "\n          "
  766                         showptrhdrpad
  767                         printf "      reserved_stack="
  768                         showptr $kgm_thread.reserved_stack
  769                 end
  770                 printf "\n          "
  771                 showptrhdrpad
  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
  776                 end
  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
  783                         else
  784                                 set $mysp = $kgm_statep->k_rbp
  785                         end
  786                 end
  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)))
  790                                 set $mysp = $r7
  791                         else
  792                                 set $kgm_statep = (struct arm_saved_state *)$kgm_thread.machine.kstackptr
  793                                 set $mysp = $kgm_statep->r[7]
  794                         end
  795                 end
  796                 set $prevsp = $mysp - 16
  797                 printf "\n          "
  798                 showptrhdrpad
  799                 printf "      stacktop="
  800                 showptr $mysp
  801                 if ($kgm_mtype == $kgm_mtype_ppc)
  802                         set $stkmask = 0xf
  803                 else
  804                         set $stkmask = 0x3
  805                 end
  806                 set $kgm_return = 0
  807                 set $kgm_actint_framecount = 0
  808                 while ($mysp != 0) && (($mysp & $stkmask) == 0) \
  809                       && ($mysp != $prevsp) \
  810                       && ((((unsigned long) $mysp ^ (unsigned long) $prevsp) < 0x2000) \
  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)
  814                         printf "\n          "
  815                         set $kgm_actint_framecount = $kgm_actint_framecount + 1
  816                         showptrhdrpad
  817                         printf "      "
  818                         showptr $mysp
  819                         printf "  "
  820                         if ($kgm_mtype == $kgm_mtype_ppc)
  821                                 set $kgm_return = *($mysp + 8)
  822                         end
  823                         if ($kgm_mtype == $kgm_mtype_i386)
  824                                 set $kgm_return = *($mysp + 4)
  825                         end
  826                         if ($kgm_mtype == $kgm_mtype_x86_64)
  827                                 set $kgm_return = *(unsigned long *)($mysp + 8)
  828                         end
  829                         if ($kgm_mtype == $kgm_mtype_arm)
  830                                 set $kgm_return = *($mysp + 4)
  831                         end
  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
  836                         else
  837                                 output /a $kgm_return
  838                         end
  839                         set $prevsp = $mysp
  840                         set $mysp = *(unsigned long *)$mysp
  841                 end
  842                 set $kgm_return = 0
  843                 printf "\n          "
  844                 showptrhdrpad
  845                 printf "      stackbottom="
  846                 showptr $prevsp
  847             else
  848                 printf "\n          "
  849                 showptrhdrpad
  850                 printf "      continuation="
  851                 output /a $kgm_thread.continuation
  852             end
  853             printf "\n"
  854         else
  855             printf "\n"
  856         end
  857 end         
  858 
  859 define showact
  860     showactheader
  861     showactint $arg0 0
  862 end
  863 document showact
  864 Syntax: (gdb) showact <activation> 
  865 | Routine to print out the state of a specific thread.
  866 end
  867 
  868 
  869 define showactstack
  870     showactheader
  871     showactint $arg0 1
  872 end
  873 document showactstack
  874 Syntax: (gdb) showactstack <activation> 
  875 | Routine to print out the stack of a specific thread.
  876 end
  877 
  878 
  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
  883         showtaskheader
  884         showtaskint $kgm_taskp
  885         showactheader
  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)
  891         end
  892         printf "\n"
  893         set $kgm_taskp = (struct task *)($kgm_taskp->tasks.next)
  894     end
  895 end
  896 document showallthreads
  897 Syntax: (gdb) showallthreads
  898 | Routine to print out info about all threads in the system.
  899 end
  900 
  901 define showprocessorint
  902     set $kgm_processor_int = (struct processor *)$arg0
  903     printf "Processor "
  904     showptr $kgm_processor_int
  905     printf " State %d (cpu_id 0x%x)\n", ($kgm_processor_int)->state, ($kgm_processor_int)->cpu_id
  906 end
  907 
  908 define showcurrentthreads
  909     set $kgm_prp = (struct processor *)processor_list
  910     while $kgm_prp != 0
  911         showprocessorint $kgm_prp
  912         if ($kgm_prp)->active_thread != 0
  913             set $kgm_actp = ($kgm_prp)->active_thread
  914             showtaskheader
  915             showtaskint ($kgm_actp)->task
  916             showactheader
  917             showactint $kgm_actp 0
  918             printf "\n"
  919         end
  920         set $kgm_prp = ($kgm_prp)->processor_list
  921     end
  922 end
  923 document showcurrentthreads
  924 Syntax: (gdb) showcurrentthreads
  925 | Routine to print out info about the thread running on each cpu.
  926 end
  927 
  928 
  929 define _showrunqint
  930         set $kgm_runq = (struct run_queue *)$arg0
  931         
  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
  945                         end
  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
  949                 end
  950                 set $kgm_runq_queue_i = $kgm_runq_queue_i + 1
  951         end
  952 
  953 end
  954 
  955 define _showgrrrint
  956         set $kgm_grrr_runq = $arg0
  957         
  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
  960         printf "\n"
  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
  975                         end
  976                 end
  977                 set $kgm_grrr_group_i = $kgm_grrr_group_i + 1
  978         end
  979 end
  980 
  981 define showallprocessors
  982         set $kgm_pset = &pset0
  983 
  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
  989 
  990         if _sched_enum == 1
  991                 set $kgm_show_priority_runq = 1
  992                 set $kgm_show_fairshare_list = 1
  993         end
  994         if _sched_enum == 2
  995                 set $kgm_show_priority_pset_runq = 1
  996                 set $kgm_show_fairshare_list = 1
  997         end
  998         if _sched_enum == 4
  999                 set $kgm_show_grrr = 1
 1000                 set $kgm_show_fairshare_grrr = 1
 1001         end
 1002         if _sched_enum == 5
 1003                 set $kgm_show_priority_runq = 1
 1004                 set $kgm_show_fairshare_list = 1
 1005         end
 1006         if _sched_enum == 6
 1007                 set $kgm_show_priority_pset_runq = 1
 1008                 set $kgm_show_fairshare_list = 1
 1009         end
 1010 
 1011         while $kgm_pset != 0
 1012                 printf "Processor Set "
 1013                 showptr $kgm_pset
 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
 1020                         printf "    "
 1021                         showprocessorint $kgm_processor
 1022 
 1023                         if $kgm_show_priority_runq
 1024                                 set $kgm_runq = &$kgm_processor->runq
 1025                                 _showrunqint $kgm_runq
 1026                         end
 1027                         if $kgm_show_grrr
 1028                                 set $kgm_grrr_runq = &$kgm_processor->grrr_runq
 1029                                 _showgrrrint $kgm_grrr_runq
 1030                         end
 1031                         
 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
 1039                                 end
 1040                         end
 1041                         
 1042                         set $kgm_active_elt = $kgm_active_elt->next
 1043                 end
 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
 1049                         printf "    "
 1050                         showprocessorint $kgm_processor
 1051                         
 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
 1059                                 end
 1060                         end
 1061 
 1062                         set $kgm_idle_elt = $kgm_idle_elt->next
 1063                 end
 1064 
 1065                 if $kgm_show_priority_pset_runq
 1066                         set $kgm_runq = &$kgm_pset->pset_runq
 1067                         printf "\n"
 1068                         _showrunqint $kgm_runq
 1069                 end
 1070                 set $kgm_pset = ($kgm_pset)->pset_list
 1071         end
 1072         
 1073         printf "\n"
 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
 1081         end
 1082         
 1083         printf "\n"
 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
 1092                 end
 1093         end
 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
 1098         end
 1099 end
 1100 document showallprocessors
 1101 Syntax: (gdb) showallprocessors
 1102 | Routine to print out info about all psets and processors
 1103 end
 1104 
 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
 1110         showtaskheader
 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
 1115             showactheader
 1116             if ($decode_wait_events > 0)
 1117                showactint $kgm_actp 1
 1118             else
 1119                showactint $kgm_actp 2
 1120             end
 1121             set $kgm_actp = (struct thread *)($kgm_actp->task_threads.next)
 1122         end
 1123         printf "\n"
 1124         set $kgm_taskp = (struct task *)($kgm_taskp->tasks.next)
 1125     end
 1126 
 1127     printf "\nZombie Processes:\n" 
 1128     zombstacks
 1129 end
 1130 
 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
 1136 | processing time.
 1137 end
 1138 
 1139 define showcurrentstacks
 1140     set $kgm_prp = processor_list
 1141     while $kgm_prp != 0
 1142         showprocessorint $kgm_prp
 1143         if ($kgm_prp)->active_thread != 0
 1144             set $kgm_actp = ($kgm_prp)->active_thread
 1145             showtaskheader
 1146             showtaskint ($kgm_actp)->task
 1147             showactheader
 1148             showactint $kgm_actp 1
 1149             printf "\n"
 1150         end
 1151         set $kgm_prp = ($kgm_prp)->processor_list
 1152     end
 1153 end
 1154 
 1155 document showcurrentstacks
 1156 Syntax: (gdb) showcurrentstacks
 1157 | Routine to print out the thread running on each cpu (incl. its stack)
 1158 end
 1159 
 1160 define showwaiterheader
 1161     printf "waiters     thread      "
 1162     printf "processor   pri  state  wait_queue  wait_event\n"
 1163 end
 1164 
 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)
 1172                 if !$kgm_w_found
 1173                         set $kgm_w_found = 1
 1174                         showwaiterheader
 1175                 end
 1176                 set $kgm_w_shuttle = (struct thread *)$kgm_w_wqe
 1177                 showactint $kgm_w_shuttle 0
 1178         end     
 1179         set $kgm_w_wqe = (WaitQueueElement *)$kgm_w_wqe->wqe_links.next
 1180     end
 1181 end
 1182 
 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
 1191         end
 1192         set $kgm_wc_wqe = (WaitQueueElement *)$kgm_wc_wqe->wqe_links.next
 1193     end
 1194     printf "0x%08x  ", $kgm_wc_count
 1195 end
 1196 
 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
 1205     end
 1206     printf "0x%08x  ", $kgm_mc_count
 1207 end
 1208 
 1209     
 1210 define showwaitqmemberheader
 1211     printf "set-members wait_queue  interlock   "
 1212     printf "pol  type   member_cnt  waiter_cnt\n"
 1213 end
 1214 
 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)
 1220         printf "Fifo "
 1221     else
 1222         printf "Prio "
 1223     end
 1224     if ($kgm_m_waitqp->wq_type == 0xf1d1)
 1225         printf "Set    "
 1226         showwaitqmembercount $kgm_m_waitqp
 1227     else
 1228         printf "Que    0x00000000  "
 1229     end
 1230     showwaitqwaitercount $kgm_m_waitqp
 1231     printf "\n"
 1232 end
 1233 
 1234 
 1235 define showwaitqmemberofheader
 1236     printf "member-of   wait_queue  interlock   "
 1237     printf "pol  type   member_cnt  waiter_cnt\n"
 1238 end
 1239 
 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)
 1247                 if !$kgm_mo_found
 1248                         set $kgm_mo_found = 1
 1249                         showwaitqmemberofheader
 1250                 end
 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
 1254         end     
 1255         set $kgm_mo_wqe = (WaitQueueElement *)$kgm_mo_wqe->wqe_links.next
 1256     end
 1257 end
 1258 
 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
 1266         if !$kgm_ms_found  
 1267             showwaitqmemberheader
 1268             set $kgm_ms_found = 1
 1269         end
 1270         showwaitqmemberint $kgm_ms_waitqp
 1271         set $kgm_ms_wql = (WaitQueueLink *)$kgm_ms_wql->wql_setlinks.next
 1272     end
 1273 end
 1274 
 1275 define showwaitqheader
 1276     printf "wait_queue  ref_count   interlock   "
 1277     printf "pol  type   member_cnt  waiter_cnt\n"
 1278 end
 1279 
 1280 define showwaitqint
 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
 1285     else
 1286         printf "0x00000000  "
 1287     end
 1288     printf "0x%08x  ", $kgm_waitqp->wq_interlock.lock_data
 1289     if ($kgm_waitqp->wq_fifo)
 1290         printf "Fifo "
 1291     else
 1292         printf "Prio "
 1293     end
 1294     if ($kgm_waitqp->wq_type == 0xf1d1)
 1295         printf "Set    "
 1296         showwaitqmembercount $kgm_waitqp
 1297     else
 1298         printf "Que    0x00000000  "
 1299     end
 1300     showwaitqwaitercount $kgm_waitqp
 1301     printf "\n"
 1302 end
 1303 
 1304 define showwaitq
 1305     set $kgm_waitq1p = (WaitQueue*)$arg0
 1306     showwaitqheader
 1307     showwaitqint $kgm_waitq1p   
 1308     if ($kgm_waitq1p->wq_type == 0xf1d1)
 1309         showwaitqmembers $kgm_waitq1p
 1310     else
 1311         showwaitqmemberof $kgm_waitq1p
 1312     end
 1313     showwaitqwaiters $kgm_waitq1p
 1314 end
 1315 
 1316 define showmapheader
 1317     printf "vm_map    "
 1318     showptrhdrpad
 1319     printf "  pmap      "
 1320     showptrhdrpad
 1321     printf "  vm_size   "
 1322     showptrhdrpad
 1323     printf " #ents rpage  hint      "
 1324     showptrhdrpad
 1325     printf "  first_free\n"
 1326 end
 1327 
 1328 define showvmeheader
 1329     printf "    entry     "
 1330     showptrhdrpad
 1331     printf "  start               prot  #page  object    "
 1332     showptrhdrpad
 1333     printf "  offset\n"
 1334 end
 1335 
 1336 define showvmint
 1337     set $kgm_mapp = (vm_map_t)$arg0
 1338     set $kgm_map = *$kgm_mapp
 1339     showptr $arg0
 1340     printf "  "
 1341     showptr $kgm_map.pmap
 1342     printf "  "
 1343     showptr $kgm_map.size
 1344     printf "   %3d ", $kgm_map.hdr.nentries
 1345     if $kgm_map.pmap
 1346         printf "%5d  ", $kgm_map.pmap->stats.resident_count
 1347     else
 1348         printf "<n/a>  "
 1349     end
 1350     showptr $kgm_map.hint
 1351     printf "  "
 1352     showptr $kgm_map.first_free
 1353     printf "\n"
 1354     if $arg1 != 0
 1355         showvmeheader   
 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
 1360             printf "    "
 1361             showptr $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
 1366                 printf "S"
 1367             end
 1368             if $kgm_vme.inheritance == 0x1
 1369                 printf "C"
 1370             end
 1371             if $kgm_vme.inheritance == 0x2
 1372                 printf "-"
 1373             end
 1374             if $kgm_vme.inheritance == 0x3
 1375                 printf "D"
 1376             end
 1377             if $kgm_vme.is_sub_map
 1378                 printf "s "
 1379             else
 1380                 if $kgm_vme.needs_copy
 1381                     printf "n "
 1382                 else
 1383                     printf "  "
 1384                 end
 1385             end
 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
 1390         end
 1391     end
 1392     printf "\n"
 1393 end
 1394 
 1395 
 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
 1402     if $arg1 == 0
 1403         set $kgm_saw_kernel_obj = 0
 1404         set $kgm_wired_count = 0
 1405         set $kgm_objp_print_space = 1
 1406     else
 1407         set $kgm_objp_print_space = 0
 1408     end
 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
 1413             if $arg1 == 0
 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
 1418                 printf "\n****"
 1419                 showptr $kgm_objp
 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
 1426             else
 1427                 printf "\n????"     
 1428                 showptr $kgm_mapp
 1429                 printf "    "
 1430                 showptr $kgm_vmep
 1431                 set $kgm_objp = (struct vm_object *)0
 1432                 printf "\n"
 1433             end
 1434         end
 1435         if ($kgm_objp == $kgm_objp_prev)
 1436             set $kgm_objp = (struct vm_object *)0
 1437         end
 1438         if $kgm_objp == kernel_object
 1439            if $kgm_saw_kernel_obj
 1440                set $kgm_objp = (struct vm_object *)0
 1441            end
 1442            set $kgm_saw_kernel_obj = 1
 1443         end
 1444         if $kgm_objp && $kgm_objp->wired_page_count
 1445             if $kgm_objp_print_space == 1
 1446                 printf "    "
 1447                 showptr $kgm_mapp
 1448             end
 1449             set $kgm_objp_print_space = 1
 1450             printf "    "
 1451             showptr $kgm_vmep
 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
 1455             showptr $kgm_objp
 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
 1460         end
 1461         set $kgm_vmep = $kgm_vme.links.next
 1462     end
 1463     if $arg1 == 0
 1464         printf "total wired count = %d\n", $kgm_wired_count
 1465     end
 1466 end
 1467 
 1468 define showmapwired
 1469     printf "    map       "
 1470     showptrhdrpad
 1471     printf "    entry     "
 1472     showptrhdrpad
 1473     printf "  start               alias  #page  object    "
 1474     showptrhdrpad
 1475     printf "       wired\n"
 1476     showmapwiredp $arg0 0
 1477 end
 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
 1481 end
 1482 
 1483 define showmapvme
 1484         showmapheader
 1485         showvmint $arg0 1
 1486 end
 1487 document showmapvme
 1488 Syntax: (gdb) showmapvme <vm_map>
 1489 | Routine to print out a summary listing of all the entries in a vm_map
 1490 end
 1491 
 1492 
 1493 define showmap
 1494         showmapheader
 1495         showvmint $arg0 0
 1496 end
 1497 document showmap
 1498 Syntax: (gdb) showmap <vm_map>
 1499 | Routine to print out info about the specified vm_map
 1500 end
 1501 
 1502 define showallvm
 1503     set $kgm_head_taskp = &tasks
 1504     set $kgm_taskp = (struct task *)($kgm_head_taskp->next)
 1505     while $kgm_taskp != $kgm_head_taskp
 1506         showtaskheader
 1507         showmapheader
 1508         showtaskint $kgm_taskp
 1509         showvmint $kgm_taskp->map 0
 1510         set $kgm_taskp = (struct task *)($kgm_taskp->tasks.next)
 1511     end
 1512 end
 1513 document showallvm
 1514 Syntax: (gdb) showallvm
 1515 | Routine to print a summary listing of all the vm maps
 1516 end
 1517 
 1518 
 1519 define showallvme
 1520     set $kgm_head_taskp = &tasks
 1521     set $kgm_taskp = (struct task *)($kgm_head_taskp->next)
 1522     while $kgm_taskp != $kgm_head_taskp
 1523         showtaskheader
 1524         showmapheader
 1525         showtaskint $kgm_taskp
 1526         showvmint $kgm_taskp->map 1
 1527         set $kgm_taskp = (struct task *)($kgm_taskp->tasks.next)
 1528     end
 1529 end
 1530 document showallvme
 1531 Syntax: (gdb) showallvme
 1532 | Routine to print a summary listing of all the vm map entries
 1533 end
 1534 
 1535 
 1536 define showipcheader
 1537     printf "ipc_space "
 1538     showptrhdrpad
 1539     printf "  is_task   "
 1540     showptrhdrpad
 1541     printf "  is_table  "
 1542     showptrhdrpad
 1543     printf " flags ports  table_next  "
 1544     showptrhdrpad
 1545     printf "   low_mod   high_mod\n"
 1546 end
 1547 
 1548 define showipceheader
 1549     printf "            "
 1550     showptrhdrpad
 1551     printf "object      "
 1552     showptrhdrpad
 1553     showptrhdrpad
 1554     printf "name        rite urefs  destname    "
 1555     showptrhdrpad
 1556     printf "destination\n"
 1557 end
 1558 
 1559 define showipceint
 1560     set $kgm_ie = *(ipc_entry_t)$arg0
 1561     printf "            "
 1562     showptrhdrpad
 1563     showptr $kgm_ie.ie_object
 1564     showptrhdrpad
 1565     printf "  0x%08x  ", $arg1
 1566     if $kgm_ie.ie_bits & 0x00100000
 1567         printf "Dead "
 1568         printf "%5d\n", $kgm_ie.ie_bits & 0xffff
 1569     else
 1570         if $kgm_ie.ie_bits & 0x00080000
 1571             printf "SET  "
 1572             printf "%5d\n", $kgm_ie.ie_bits & 0xffff
 1573         else
 1574             if $kgm_ie.ie_bits & 0x00010000
 1575                 if $kgm_ie.ie_bits & 0x00020000
 1576                     printf " SR"
 1577                 else
 1578                     printf "  S"
 1579                 end
 1580             else
 1581                 if $kgm_ie.ie_bits & 0x00020000
 1582                    printf "  R"
 1583                 end
 1584             end
 1585             if $kgm_ie.ie_bits & 0x00040000
 1586                 printf "  O"
 1587             end
 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
 1592                 if $kgm_req_soright
 1593 #                   Armed send-possible notification?
 1594                     if (uintptr_t)$kgm_req_soright & 0x1
 1595                         printf "s"
 1596                     else
 1597 #                       Delayed send-possible notification?
 1598                         if (uintptr_t)$kgm_req_soright & 0x2
 1599                             printf "d"
 1600                         else
 1601 #                           Dead-name notification
 1602                             printf "n"
 1603                         end
 1604                     end     
 1605                 else
 1606                     printf " "
 1607                 end
 1608             else
 1609                 printf " "
 1610             end
 1611 #           Collision (with tree)?
 1612             if $kgm_ie.ie_bits & 0x00800000
 1613                 printf "c"
 1614             else
 1615                 printf " "
 1616             end
 1617             printf "%5d  ", $kgm_ie.ie_bits & 0xffff
 1618             showportdest $kgm_ie.ie_object
 1619         end
 1620     end
 1621 end
 1622 
 1623 define showipcint
 1624     set $kgm_isp = (ipc_space_t)$arg0
 1625     set $kgm_is = *$kgm_isp
 1626     showptr $arg0
 1627     printf "  "
 1628     showptr $kgm_is.is_task
 1629     printf "  "
 1630     showptr $kgm_is.is_table
 1631     printf "  "
 1632     if ($kgm_is.is_bits & 0x40000000) == 0
 1633         printf "A"
 1634     else
 1635         printf " "
 1636     end
 1637     if ($kgm_is.is_bits & 0x20000000) != 0
 1638         printf "G   "
 1639     else
 1640         printf "    "
 1641     end
 1642     printf "%5d  ", $kgm_is.is_table_size 
 1643     showptr $kgm_is.is_table_next
 1644     printf "  "
 1645     printf "%10d ", $kgm_is.is_low_mod
 1646     printf "%10d", $kgm_is.is_high_mod
 1647     printf "\n"
 1648     if $arg1 != 0
 1649         showipceheader
 1650         set $kgm_iindex = 0
 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
 1658                 if $arg2 != 0
 1659                    if $kgm_ie.ie_object != 0 && ($kgm_ie.ie_bits & 0x00070000) && ((ipc_port_t) $kgm_ie.ie_object)->ip_callstack[0] != 0
 1660                         printf "              user bt: "
 1661                         showportbt $kgm_ie.ie_object $kgm_is.is_task
 1662                    end
 1663                 end
 1664             end
 1665             set $kgm_iindex = $kgm_iindex + 1
 1666             set $kgm_iep = &($kgm_is.is_table[$kgm_iindex])
 1667         end
 1668     end
 1669     printf "\n"
 1670 end
 1671 
 1672 
 1673 define showipc
 1674     set $kgm_isp = (ipc_space_t)$arg0
 1675     showipcheader
 1676     showipcint $kgm_isp 0 0
 1677 end
 1678 document showipc
 1679 Syntax: (gdb) showipc <ipc_space>
 1680 | Routine to print the status of the specified ipc space
 1681 end
 1682 
 1683 define showrights
 1684         set $kgm_isp = (ipc_space_t)$arg0
 1685     showipcheader
 1686         showipcint $kgm_isp 1 0
 1687 end
 1688 document showrights
 1689 Syntax: (gdb) showrights <ipc_space>
 1690 | Routine to print a summary list of all the rights in a specified ipc space
 1691 end
 1692 
 1693 
 1694 define showtaskipc
 1695         set $kgm_taskp = (task_t)$arg0
 1696         showtaskheader
 1697         showtaskint $kgm_taskp
 1698         showipcheader
 1699         showipcint $kgm_taskp->itk_space 0 0
 1700 end
 1701 document showtaskipc
 1702 Syntax: (gdb) showtaskipc <task>
 1703 | Routine to print info about the ipc space for a task
 1704 end
 1705 
 1706 
 1707 define showtaskrights
 1708         set $kgm_taskp = (task_t)$arg0
 1709         showtaskheader
 1710         showtaskint $kgm_taskp
 1711         showipcheader
 1712         showipcint $kgm_taskp->itk_space 1 0
 1713 end
 1714 document showtaskrights
 1715 Syntax: (gdb) showtaskrights <task>
 1716 | Routine to print info about the ipc rights for a task
 1717 end
 1718 
 1719 define showtaskrightsbt
 1720         set $kgm_taskp = (task_t)$arg0
 1721         showtaskheader
 1722         showtaskint $kgm_taskp
 1723         showipcheader
 1724         showipcint $kgm_taskp->itk_space 1 1
 1725 end
 1726 document showtaskrightsbt
 1727 Syntax: (gdb) showtaskrightsbt <task>
 1728 | Routine to print info about the ipc rights for a task with backtraces
 1729 end
 1730 
 1731 define showallipc
 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
 1735         showtaskheader
 1736         showtaskint $kgm_cur_taskp
 1737         showipcheader
 1738         showipcint $kgm_cur_taskp->itk_space 0 0
 1739         set $kgm_cur_taskp = (struct task *)($kgm_cur_taskp->tasks.next)
 1740     end
 1741 end
 1742 document showallipc
 1743 Syntax: (gdb) showallipc
 1744 | Routine to print a summary listing of all the ipc spaces
 1745 end
 1746 
 1747 define showipcsumheader
 1748     printf "task         "
 1749     showptrhdrpad
 1750     printf " pid         "
 1751     printf " #acts         "
 1752     printf " tsize "
 1753     printf "command\n"
 1754 end
 1755 
 1756 define showipcsummaryint
 1757     set $kgm_taskp = (struct task *)$arg0
 1758     showptr $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
 1763 end
 1764 
 1765 define showipcsummary
 1766     showipcsumheader
 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)
 1772     end
 1773 end
 1774 
 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.
 1780 end
 1781 
 1782 
 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
 1787         showtaskheader
 1788         showtaskint $kgm_cur_taskp
 1789         showipcheader
 1790         showipcint $kgm_cur_taskp->itk_space 1 0
 1791         set $kgm_cur_taskp = (struct task *)($kgm_cur_taskp->tasks.next)
 1792     end
 1793 end
 1794 document showallrights
 1795 Syntax: (gdb) showallrights
 1796 | Routine to print a summary listing of all the ipc rights
 1797 end
 1798 
 1799 
 1800 define showtaskvm
 1801         set $kgm_taskp = (task_t)$arg0
 1802         showtaskheader
 1803         showmapheader
 1804         showtaskint $kgm_taskp
 1805         showvmint $kgm_taskp->map 0
 1806 end
 1807 document showtaskvm
 1808 Syntax: (gdb) showtaskvm <task>
 1809 | Routine to print out info about a task's vm_map
 1810 end
 1811 
 1812 define showtaskvme
 1813         set $kgm_taskp = (task_t)$arg0
 1814         showtaskheader
 1815         showtaskint $kgm_taskp
 1816         showmapheader
 1817         showvmint $kgm_taskp->map 1
 1818 end
 1819 document showtaskvme
 1820 Syntax: (gdb) showtaskvme <task>
 1821 | Routine to print out info about a task's vm_map_entries
 1822 end
 1823 
 1824 
 1825 define showtaskheader
 1826     printf "task      "
 1827     showptrhdrpad
 1828     printf "  vm_map    "
 1829     showptrhdrpad
 1830     printf "  ipc_space "
 1831     showptrhdrpad
 1832     printf " #acts "
 1833     showprocheader
 1834 end
 1835 
 1836 
 1837 define showtaskint
 1838     set $kgm_taskp = (struct task *)$arg0
 1839     showptr $arg0
 1840     printf "  "
 1841     showptr $kgm_taskp->map
 1842     printf "  "
 1843     showptr $kgm_taskp->itk_space
 1844     printf " %5d ", $kgm_taskp->thread_count
 1845     showprocint $kgm_taskp->bsd_info
 1846 end
 1847 
 1848 define showtask
 1849     showtaskheader
 1850     showtaskint $arg0
 1851 end
 1852 document showtask
 1853 Syntax (gdb) showtask <task>
 1854 | Routine to print out info about a task.
 1855 end
 1856 
 1857 
 1858 define showtaskthreads
 1859     showtaskheader
 1860     set $kgm_taskp = (struct task *)$arg0
 1861     showtaskint $kgm_taskp
 1862     showactheader
 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)
 1868     end
 1869 end
 1870 document showtaskthreads
 1871 Syntax: (gdb) showtaskthreads <task>
 1872 | Routine to print info about the threads in a task.
 1873 end
 1874 
 1875 
 1876 define showtaskstacks
 1877     showtaskheader
 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
 1883         showactheader
 1884         showactint $kgm_actp 1
 1885         set $kgm_actp = (struct thread *)($kgm_actp->task_threads.next)
 1886     end
 1887 end
 1888 document showtaskstacks
 1889 Syntax: (gdb) showtaskstacks <task>
 1890 | Routine to print out the stack for each thread in a task.
 1891 end
 1892 
 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
 1897                 showptr $queue
 1898                 printf " "
 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
 1903                 showptr $thread
 1904                 printf " "
 1905                 showptr $task
 1906                 printf " "
 1907                 showptr $bsd
 1908                 printf " "
 1909                 showptr $guy
 1910                 #printf "  %s\n", $kgm_procp->p_comm
 1911                 printf "\n"
 1912         set $queue = (struct queue_entry *)($queue->next)
 1913     end
 1914 end
 1915 
 1916 define showalltasks
 1917     showtaskheader
 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)
 1923     end
 1924 end
 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)
 1934 end
 1935 
 1936 define showprocheader
 1937     printf "  pid  process     "
 1938     showptrhdrpad
 1939     printf "io_policy    wq_state   command\n"
 1940 end
 1941 
 1942 define showprocint
 1943     set $kgm_procp = (struct proc *)$arg0
 1944     if $kgm_procp != 0
 1945         set $kgm_printed = 0
 1946         printf "%5d  ", $kgm_procp->p_pid
 1947         showptr $kgm_procp
 1948         if ($kgm_procp->p_lflag & 0x400000)
 1949            printf "  RAGE "
 1950         else
 1951            printf "       "
 1952         end
 1953         set $ptask = (struct task *)$kgm_procp->task
 1954         set $diskpolicy = 0
 1955         if ($ptask->ext_appliedstate.hw_disk != 0)
 1956                 set $diskpolicy = $ptask->ext_appliedstate.hw_disk
 1957         else 
 1958                 if ($ptask->appliedstate.hw_disk != 0)
 1959                         set $diskpolicy = $ptask->appliedstate.hw_disk
 1960                 end
 1961         end
 1962         if ($ptask->ext_appliedstate.hw_bg != 0)
 1963                 set $diskpolicy = 5
 1964         end
 1965         if ($ptask->appliedstate.hw_bg != 0)
 1966                 set $diskpolicy = 4
 1967         end
 1968         if ($ptask->ext_appliedstate.apptype == 2)
 1969                 set $diskpolicy = 6
 1970         end
 1971         if ($diskpolicy == 2)
 1972                 printf "PASS    "
 1973                 set $kgm_printed = 1
 1974         end
 1975         if ($diskpolicy == 3)
 1976                 printf "THROT   "
 1977                 set $kgm_printed = 1
 1978         end
 1979         if ($diskpolicy == 4)
 1980                 printf "BG_THRT "
 1981                 set $kgm_printed = 1
 1982         end
 1983         if ($diskpolicy == 5)
 1984                 printf "EBG_THRT"
 1985                 set $kgm_printed = 1
 1986         end
 1987         if ($diskpolicy == 6)
 1988                 printf "APD_THRT"
 1989                 set $kgm_printed = 1
 1990         end
 1991         if ($kgm_printed == 0)
 1992            printf "      "
 1993         end
 1994         set $kgm_wqp = (struct workqueue *)$kgm_procp->p_wqptr
 1995         if $kgm_wqp != 0
 1996            printf "  %2d %2d %2d ", $kgm_wqp->wq_nthreads, $kgm_wqp->wq_thidlecount, $kgm_wqp->wq_reqcount
 1997         else
 1998            printf "           "
 1999         end
 2000         printf "  %s\n", $kgm_procp->p_comm
 2001     else
 2002         printf "  *0*  "
 2003         showptr 0
 2004         printf "  --\n"
 2005     end
 2006 end
 2007 
 2008 define showpid
 2009     showtaskheader
 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
 2017         else
 2018             set $kgm_taskp = (struct task *)($kgm_taskp->tasks.next)
 2019         end
 2020     end
 2021 end
 2022 document showpid
 2023 Syntax: (gdb) showpid <pid>
 2024 | Routine to print a single process by pid
 2025 end
 2026 
 2027 define showproc
 2028     showtaskheader
 2029     set $kgm_procp = (struct proc *)$arg0
 2030     showtaskint $kgm_procp->task
 2031 end
 2032 
 2033 
 2034 define kdb
 2035     set switch_debugger=1
 2036     continue
 2037 end
 2038 document kdb
 2039 | kdb - Switch to the inline kernel debugger
 2040 |
 2041 | usage: kdb
 2042 |
 2043 | The kdb macro allows you to invoke the inline kernel debugger.
 2044 end
 2045 
 2046 define showpsetheader
 2047     printf "portset     "
 2048     showptrhdrpad
 2049     printf "waitqueue   "
 2050     showptrhdrpad
 2051     showptrhdrpad
 2052     printf "recvname    flags refs  recvname    "
 2053     showptrhdrpad
 2054     printf "process\n"
 2055 end
 2056 
 2057 define showportheader
 2058     printf "port        "
 2059     showptrhdrpad
 2060     printf "mqueue      "
 2061     showptrhdrpad
 2062     showptrhdrpad
 2063     printf "recvname    flags refs  recvname    "
 2064     showptrhdrpad
 2065     printf "dest\n"
 2066 end
 2067 
 2068 define showportmemberheader
 2069     printf "members     "
 2070     showptrhdrpad
 2071     printf "port        "
 2072     showptrhdrpad
 2073     showptrhdrpad
 2074     printf "recvname    "
 2075     printf "flags refs  mqueue      "
 2076     showptrhdrpad
 2077     printf "msgcount\n"
 2078 end
 2079 
 2080 define showkmsgheader
 2081     printf "dest-port   "
 2082     showptrhdrpad
 2083     printf "kmsg        "
 2084     showptrhdrpad
 2085     showptrhdrpad
 2086     printf "msgid       "
 2087     printf "disp  size  "
 2088     printf "reply-port  "
 2089     showptrhdrpad
 2090     printf "source\n"
 2091 end
 2092 
 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
 2102     else 
 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
 2111               else
 2112                   set $kgm_kmsgsrctaskp = (struct task *)($kgm_kmsgsrctaskp->tasks.next)
 2113               end
 2114           end
 2115        end
 2116     end
 2117     if ($kgm_kmsgsrcprocp->p_pid == $kgm_kmsgpid)
 2118         printf "%s(%d)\n", $kgm_kmsgsrcprocp->p_comm, $kgm_kmsgpid
 2119     else
 2120         printf "unknown(%d)\n", $kgm_kmsgpid
 2121     end
 2122 end
 2123 
 2124 define showkmsgint
 2125     set $kgm_kmsghp = ((ipc_kmsg_t)$arg0)->ikm_header
 2126     set $kgm_kmsgh = *$kgm_kmsghp
 2127     if ($arg1 != 0)
 2128         printf "            "
 2129         showptrhdrpad
 2130     else
 2131         showptr $kgm_kmsgh.msgh_remote_port
 2132     end
 2133     showptr $arg0
 2134     showptrhdrpad
 2135     printf "  0x%08x  ", $kgm_kmsgh.msgh_id
 2136     if (($kgm_kmsgh.msgh_bits & 0xff) == 19)
 2137         printf "rC"
 2138     else
 2139         printf "rM"
 2140     end
 2141     if (($kgm_kmsgh.msgh_bits & 0xff00) == (19 << 8))
 2142         printf "lC"
 2143     else
 2144         printf "lM"
 2145     end
 2146     if ($kgm_kmsgh.msgh_bits & 0xf0000000)
 2147         printf "c"
 2148     else
 2149         printf "s"
 2150     end
 2151     printf "%5d  ", $kgm_kmsgh.msgh_size
 2152     showptr $kgm_kmsgh.msgh_local_port
 2153     printf "  "
 2154     set $kgm_kmsgsrcpid = (pid_t)0
 2155     showkmsgsrcint $arg0
 2156 end
 2157 
 2158 define showkmsg
 2159     showkmsgint $arg0 0
 2160 end
 2161 
 2162 define showkobject
 2163     set $kgm_portp = (struct ipc_port *)$arg0
 2164     showptr $kgm_portp->ip_kobject
 2165     printf "  kobject("
 2166     set $kgm_kotype = ($kgm_portp->ip_object.io_bits & 0x00000fff)
 2167     if ($kgm_kotype == 1)
 2168         printf "THREAD"
 2169     end
 2170     if ($kgm_kotype == 2)
 2171         printf "TASK"
 2172     end
 2173     if ($kgm_kotype == 3)
 2174         printf "HOST"
 2175     end
 2176     if ($kgm_kotype == 4)
 2177         printf "HOST_PRIV"
 2178     end
 2179     if ($kgm_kotype == 5)
 2180         printf "PROCESSOR"
 2181     end
 2182     if ($kgm_kotype == 6)
 2183         printf "PSET"
 2184     end
 2185     if ($kgm_kotype == 7)
 2186         printf "PSET_NAME"
 2187     end
 2188     if ($kgm_kotype == 8)
 2189         printf "TIMER"
 2190     end
 2191     if ($kgm_kotype == 9)
 2192         printf "PAGER_REQ"
 2193     end
 2194     if ($kgm_kotype == 10)
 2195         printf "DEVICE"
 2196     end
 2197     if ($kgm_kotype == 11)
 2198         printf "XMM_OBJECT"
 2199     end
 2200     if ($kgm_kotype == 12)
 2201         printf "XMM_PAGER"
 2202     end
 2203     if ($kgm_kotype == 13)
 2204         printf "XMM_KERNEL"
 2205     end
 2206     if ($kgm_kotype == 14)
 2207         printf "XMM_REPLY"
 2208     end
 2209     if ($kgm_kotype == 15)
 2210         printf "NOTDEF 15"
 2211     end
 2212     if ($kgm_kotype == 16)
 2213         printf "NOTDEF 16"
 2214     end
 2215     if ($kgm_kotype == 17)
 2216         printf "HOST_SEC"
 2217     end
 2218     if ($kgm_kotype == 18)
 2219         printf "LEDGER"
 2220     end
 2221     if ($kgm_kotype == 19)
 2222         printf "MASTER_DEV"
 2223     end
 2224     if ($kgm_kotype == 20)
 2225         printf "ACTIVATION"
 2226     end
 2227     if ($kgm_kotype == 21)
 2228         printf "SUBSYSTEM"
 2229     end
 2230     if ($kgm_kotype == 22)
 2231         printf "IO_DONE_QUE"
 2232     end
 2233     if ($kgm_kotype == 23)
 2234         printf "SEMAPHORE"
 2235     end
 2236     if ($kgm_kotype == 24)
 2237         printf "LOCK_SET"
 2238     end
 2239     if ($kgm_kotype == 25)
 2240         printf "CLOCK"
 2241     end
 2242     if ($kgm_kotype == 26)
 2243         printf "CLOCK_CTRL"
 2244     end
 2245     if ($kgm_kotype == 27)
 2246         printf "IOKIT_SPARE"
 2247     end
 2248     if ($kgm_kotype == 28)
 2249         printf "NAMED_MEM"
 2250     end
 2251     if ($kgm_kotype == 29)
 2252         printf "IOKIT_CON"
 2253     end
 2254     if ($kgm_kotype == 30)
 2255         printf "IOKIT_OBJ"
 2256     end
 2257     if ($kgm_kotype == 31)
 2258         printf "UPL"
 2259     end
 2260     if ($kgm_kotype == 34)
 2261         printf "FD"
 2262     end
 2263     printf ")\n"
 2264 end
 2265 
 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
 2278             else
 2279                set $kgm_desttaskp = (struct task *)($kgm_desttaskp->tasks.next)
 2280             end
 2281         end
 2282     end
 2283     if $kgm_destprocp != 0
 2284        printf "%s(%d)\n", $kgm_destprocp->p_comm, $kgm_destprocp->p_pid
 2285     else
 2286        printf "task "
 2287        showptr $kgm_desttaskp
 2288        printf "\n"
 2289     end
 2290 end
 2291 
 2292 define showportdest
 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
 2297     else
 2298         if ($kgm_portp->ip_object.io_bits & 0x80000000)
 2299             showptr $kgm_portp->ip_messages.data.port.receiver_name
 2300         printf "  "
 2301             showportdestproc $kgm_portp
 2302         else
 2303         showptr $kgm_portp
 2304             printf "  inactive-port\n"
 2305         end
 2306     end
 2307 end
 2308 
 2309 define showportmember
 2310     printf "            "
 2311     showptrhdrpad
 2312     showptr $arg0
 2313     showptrhdrpad
 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)
 2317         printf "A"
 2318     else
 2319         printf " "
 2320     end
 2321     printf "Port"
 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
 2325 end
 2326 
 2327 define showportbt
 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])
 2335             printf " "
 2336             showptr $kgm_iebt[$kgm_iebt_loop_ctr]
 2337             set $kgm_iebt_loop_ctr = $kgm_iebt_loop_ctr + 1
 2338         end
 2339         if $kgm_iepid != $kgm_procpid
 2340             printf " (%d)", $kgm_iepid
 2341         end
 2342         printf "\n"
 2343     end
 2344 end
 2345 
 2346 define showportint
 2347     showptr $arg0
 2348     printf "  "
 2349     set $kgm_portp = (struct ipc_port *)$arg0
 2350     showptr &($kgm_portp->ip_messages)
 2351     showptrhdrpad
 2352     printf "  0x%08x  ", $kgm_portp->ip_messages.data.port.receiver_name
 2353     if ($kgm_portp->ip_object.io_bits & 0x80000000)
 2354         printf "A"
 2355     else
 2356         printf "D"
 2357     end
 2358     printf "Port"
 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
 2364         showkmsgheader
 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
 2371         end
 2372     end
 2373 end
 2374 
 2375 define showpsetint
 2376     showptr $arg0
 2377     printf "  "
 2378     set $kgm_psetp = (struct ipc_pset *)$arg0
 2379     showptr &($kgm_psetp->ips_messages)
 2380     showptrhdrpad
 2381     printf "  0x%08x  ", $kgm_psetp->ips_messages.data.pset.local_name
 2382     if ($kgm_psetp->ips_object.io_bits & 0x80000000)
 2383         printf "A"
 2384     else
 2385         printf "D"
 2386     end
 2387     printf "Set "
 2388     printf "%5d  ", $kgm_psetp->ips_object.io_references
 2389     showptr $kgm_psetp->ips_messages.data.pset.local_name
 2390     printf "  "
 2391     set $kgm_setlinksp = &($kgm_psetp->ips_messages.data.pset.set_queue.wqs_setlinks)
 2392     set $kgm_wql = (WaitQueueLink *)$kgm_setlinksp->next
 2393     set $kgm_found = 0
 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)
 2396         if !$kgm_found  
 2397             set $kgm_destspacep = (struct ipc_space *)0
 2398             showportdestproc $kgm_portp
 2399             showportmemberheader
 2400             set $kgm_found = 1
 2401         end
 2402         showportmember $kgm_portp 0
 2403         set $kgm_wql = (WaitQueueLink *)$kgm_wql->wql_setlinks.next
 2404     end
 2405     if !$kgm_found
 2406         printf "--n/e--\n"
 2407     end
 2408 end
 2409 
 2410 define showpset
 2411     set $kgm_portoff = &(((struct ipc_port *)0)->ip_messages)
 2412     showpsetheader
 2413     showpsetint $arg0 1
 2414 end
 2415 
 2416 define showport
 2417     showportheader
 2418     showportint $arg0 1
 2419 end
 2420 
 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
 2426     else
 2427         showport $kgm_objectp
 2428     end
 2429 end
 2430 
 2431 define showmqueue
 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))
 2436         showpsetheader
 2437         showpsetint $kgm_pset 1
 2438     end
 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))
 2442         showportheader
 2443         showportint $kgm_port 1
 2444     end
 2445 end
 2446 
 2447 define zprint_one
 2448     set $kgm_zone = (struct zone *)$arg0
 2449 
 2450     showptr $kgm_zone
 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
 2459     end
 2460     printf "%s ",$kgm_zone->zone_name
 2461 
 2462     if ($kgm_zone->exhaustible)
 2463         printf "H"
 2464     end
 2465     if ($kgm_zone->collectable)
 2466         printf "C"
 2467     end
 2468     if ($kgm_zone->expandable)
 2469         printf "X"
 2470     end
 2471     if ($kgm_zone->noencrypt)
 2472         printf "$"
 2473     end
 2474     printf "\n"
 2475 end
 2476 
 2477 
 2478 define zprint
 2479     printf "ZONE      "
 2480     showptrhdrpad
 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
 2486     end
 2487     printf "\n"
 2488 end
 2489 document zprint
 2490 Syntax: (gdb) zprint
 2491 | Routine to print a summary listing of all the kernel zones
 2492 end
 2493 
 2494 define showmtxgrp
 2495     set $kgm_mtxgrp = (struct _lck_grp_ *)$arg0
 2496 
 2497     if ($kgm_mtxgrp->lck_grp_mtxcnt)
 2498         showptr $kgm_mtxgrp
 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
 2504         printf "\n"
 2505     end
 2506 end
 2507 
 2508 
 2509 define showallmtx
 2510     printf "LCK GROUP "
 2511     showptrhdrpad
 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
 2518     end
 2519     printf "\n"
 2520 end
 2521 document showallmtx
 2522 Syntax: (gdb) showallmtx
 2523 | Routine to print a summary listing of all mutexes
 2524 end
 2525 
 2526 define showrwlckgrp
 2527     set $kgm_rwlckgrp = (struct _lck_grp_ *)$arg0
 2528 
 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
 2536         printf "\n"
 2537     end
 2538 end
 2539 
 2540 
 2541 define showallrwlck
 2542     printf "LCK GROUP "
 2543     showptrhdrpad
 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
 2550     end
 2551     printf "\n"
 2552 end
 2553 document showallrwlck
 2554 Syntax: (gdb) showallrwlck
 2555 | Routine to print a summary listing of all read/writer locks
 2556 end
 2557 
 2558 set $kdp_act_counter = 0
 2559 set $kdp_arm_act_counter = 0
 2560 
 2561 set $r0_save    = 0
 2562 set $r1_save    = 0
 2563 set $r2_save    = 0
 2564 set $r3_save    = 0
 2565 set $r4_save    = 0
 2566 set $r5_save    = 0
 2567 set $r6_save    = 0
 2568 set $r7_save    = 0
 2569 set $r8_save    = 0
 2570 set $r9_save    = 0
 2571 set $r10_save   = 0
 2572 set $r11_save   = 0
 2573 set $r12_save   = 0
 2574 set $sp_save    = 0
 2575 set $lr_save    = 0
 2576 set $pc_save    = 0
 2577 
 2578 define showcontext_int
 2579         echo Context switched, current instruction pointer: 
 2580         output/a $pc
 2581         echo \n
 2582 end
 2583 
 2584 define switchtoact
 2585         set $newact = (struct thread *) $arg0
 2586         select 0
 2587         if ($newact->kernel_stack == 0)
 2588                 echo This activation does not have a stack.\n
 2589                 echo continuation:
 2590                 output/a (unsigned) $newact.continuation
 2591                 echo \n
 2592         else
 2593                 if ($kgm_mtype == $kgm_mtype_ppc)
 2594                         if ($kdp_act_counter == 0)
 2595                                 set $kdpstate = (struct savearea *) kdp.saved_state
 2596                         end
 2597                         set $kdp_act_counter = $kdp_act_counter + 1
 2598                         set (struct savearea *) kdp.saved_state=$newact->machine->pcb
 2599                         flushregs
 2600                         flushstack
 2601                         set $pc=$newact->machine->pcb.save_srr0
 2602                         update
 2603                 end
 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)
 2608                         end     
 2609                         set $kdp_act_counter = $kdp_act_counter + 1
 2610         
 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 
 2619                         flushregs
 2620                         flushstack
 2621                         set $pc = $kgm_statep->k_eip
 2622                         update
 2623                 end
 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)
 2628                         end     
 2629                         set $kdp_act_counter = $kdp_act_counter + 1
 2630         
 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 
 2641                         flushregs
 2642                         flushstack
 2643                         set $pc = $kgm_statep->k_rip
 2644                         update
 2645                 end
 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)
 2649                                 set $r0_save   = $r0
 2650                                 set $r1_save   = $r1
 2651                                 set $r2_save   = $r2
 2652                                 set $r3_save   = $r3
 2653                                 set $r4_save   = $r4
 2654                                 set $r5_save   = $r5
 2655                                 set $r6_save   = $r6
 2656                                 set $r7_save   = $r7
 2657                                 set $r8_save   = $r8
 2658                                 set $r9_save   = $r9
 2659                                 set $r10_save  = $r10
 2660                                 set $r11_save  = $r11
 2661                                 set $r12_save  = $r12
 2662                                 set $sp_save   = $sp
 2663                                 set $lr_save   = $lr
 2664                                 set $pc_save   = $pc
 2665                         end
 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
 2682                         set $pc = $pc_ctx
 2683                         set $r7 =  $kgm_statep->r[7]
 2684                         flushregs
 2685                         flushstack
 2686                 end
 2687         end
 2688         showcontext_int
 2689 end
 2690 
 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.
 2698 end     
 2699 
 2700 define switchtoctx
 2701         select 0
 2702         if ($kgm_mtype == $kgm_mtype_ppc)
 2703                 if ($kdp_act_counter == 0)
 2704                    set $kdpstate = (struct savearea *) kdp.saved_state
 2705                 end
 2706                 set $kdp_act_counter = $kdp_act_counter + 1
 2707                 set (struct savearea *) kdp.saved_state=(struct savearea *) $arg0
 2708                 flushregs
 2709                 flushstack
 2710                 set $pc=((struct savearea *) $arg0)->save_srr0
 2711                 update
 2712         else
 2713                 if ($kgm_mtype == $kgm_mtype_arm)
 2714                         select 0
 2715                         set $kdp_arm_act_counter = $kdp_arm_act_counter + 1
 2716                         if ($kdp_arm_act_counter == 1)
 2717                                 set $r0_save   = $r0
 2718                                 set $r1_save   = $r1
 2719                                 set $r2_save   = $r2
 2720                                 set $r3_save   = $r3
 2721                                 set $r4_save   = $r4
 2722                                 set $r5_save   = $r5
 2723                                 set $r6_save   = $r6
 2724                                 set $r7_save   = $r7
 2725                                 set $r8_save   = $r8
 2726                                 set $r9_save   = $r9
 2727                                 set $r10_save  = $r10
 2728                                 set $r11_save  = $r11
 2729                                 set $r12_save  = $r12
 2730                                 set $sp_save   = $sp
 2731                                 set $lr_save   = $lr
 2732                                 set $pc_save   = $pc
 2733                         end
 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
 2751                         flushregs
 2752                         flushstack
 2753                         update
 2754                 else
 2755                         echo switchtoctx not implemented for this architecture.\n
 2756                 end
 2757         end
 2758 end
 2759 
 2760 
 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.
 2767 end     
 2768 
 2769 define resetctx
 2770         select 0
 2771         if ($kdp_act_counter != 0)
 2772                 if ($kgm_mtype == $kgm_mtype_ppc)
 2773                         set (struct savearea *)kdp.saved_state=$kdpstate
 2774                         flushregs
 2775                         flushstack
 2776                         set $pc=((struct savearea *) kdp.saved_state)->save_srr0
 2777                         update
 2778                         set $kdp_act_counter = 0
 2779                 end
 2780                 if ($kgm_mtype == $kgm_mtype_i386)
 2781                         set $kdpstatep = (struct x86_saved_state32 *) kdp.saved_state
 2782                         set *($kdpstatep)=$kdpstate
 2783                         flushregs
 2784                         flushstack
 2785                         set $pc=$kdpstatep->eip
 2786                         update
 2787                         set $kdp_act_counter = 0
 2788                 end
 2789                 if ($kgm_mtype == $kgm_mtype_x86_64)
 2790                         set $kdpstatep = (struct x86_saved_state64 *) kdp.saved_state
 2791                         set *($kdpstatep)=$kdpstate
 2792                         flushregs
 2793                         flushstack
 2794                         set $pc=$kdpstatep->isf.rip
 2795                         update
 2796                         set $kdp_act_counter = 0
 2797                 end
 2798                 showcontext_int
 2799         end
 2800         if ($kgm_mtype == $kgm_mtype_arm && $kdp_arm_act_counter != 0)
 2801                 echo Restoring context\n
 2802                 set $r0  = $r0_save
 2803                 flushregs
 2804                 set $r1  = $r1_save
 2805                 flushregs
 2806                 set $r2  = $r2_save
 2807                 flushregs
 2808                 set $r3  = $r3_save
 2809                 flushregs
 2810                 set $r4  = $r4_save
 2811                 flushregs
 2812                 set $r5  = $r5_save
 2813                 flushregs
 2814                 set $r6  = $r6_save
 2815                 flushregs
 2816                 set $r8  = $r8_save
 2817                 flushregs
 2818                 set $r9  = $r9_save
 2819                 flushregs
 2820                 set $r10 = $r10_save
 2821                 flushregs
 2822                 set $r11 = $r11_save
 2823                 flushregs
 2824                 set $r12 = $r12_save
 2825                 flushregs
 2826                 set $sp  = $sp_save
 2827                 flushregs
 2828                 set $lr  = $lr_save
 2829                 flushregs
 2830                 set $pc  = $pc_save
 2831                 flushregs
 2832                 set $r7  = $r7_save
 2833                 flushregs
 2834                 flushstack
 2835                 update
 2836                 set $kdp_arm_act_counter = 0
 2837         end
 2838 end     
 2839         
 2840 document resetctx
 2841 | Syntax: resetctx
 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.
 2845 end     
 2846 
 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
 2850        resetctx
 2851 end
 2852 
 2853 # This is a pre-hook for the detach command, to prevent inadvertent attempts 
 2854 # to resume from the context switched to for examination.
 2855 define hook-detach
 2856        resetctx
 2857 end
 2858 
 2859 define resume_on
 2860         set $resume = KDP_DUMPINFO_SETINFO | KDP_DUMPINFO_RESUME
 2861         dumpinfoint $resume
 2862 end
 2863 
 2864 document resume_on
 2865 | Syntax: resume_on
 2866 | The target system will resume when detaching  or exiting from gdb. 
 2867 | This is the default behavior.
 2868 end
 2869 
 2870 define resume_off
 2871         set $noresume = KDP_DUMPINFO_SETINFO | KDP_DUMPINFO_NORESUME
 2872         dumpinfoint $noresume
 2873 end
 2874 
 2875 document resume_off
 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
 2879 end
 2880 
 2881 define paniclog
 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
 2886                         printf "\n"
 2887                 else
 2888                         printf "%c", *(char *)$kgm_panic_bufptr
 2889                 end
 2890                 set $kgm_panic_bufptr= (char *)$kgm_panic_bufptr + 1
 2891         end
 2892 end
 2893 
 2894 document paniclog
 2895 | Syntax: paniclog
 2896 | Display the panic log information
 2897 |
 2898 end
 2899 
 2900 define dumpcallqueue
 2901         set $kgm_callhead = $arg0
 2902         set $kgm_callentry = $kgm_callhead->next
 2903         set $kgm_i = 0
 2904         while $kgm_callentry != $kgm_callhead
 2905                 set $kgm_call = (struct call_entry *)$kgm_callentry
 2906                 showptr $kgm_call
 2907                 printf "0x%lx 0x%lx ", $kgm_call->param0, $kgm_call->param1
 2908                 output $kgm_call->deadline
 2909                 printf "\t"
 2910                 output $kgm_call->func
 2911                 printf "\n"
 2912                 set $kgm_i = $kgm_i + 1
 2913                 set $kgm_callentry = $kgm_callentry->next
 2914         end
 2915         printf "%d entries\n", $kgm_i
 2916 end
 2917 
 2918 document dumpcallqueue
 2919 | Syntax: dumpcallqueue <queue head>
 2920 | Displays the contents of the specified call_entry queue.
 2921 end
 2922 
 2923 define showtaskacts
 2924 showtaskthreads $arg0
 2925 end
 2926 document showtaskacts
 2927 | See help showtaskthreads.
 2928 end
 2929 
 2930 define showallacts
 2931 showallthreads
 2932 end
 2933 document showallacts
 2934 | See help showallthreads.
 2935 end
 2936 
 2937 
 2938 define resetstacks
 2939        _kgm_flush_loop
 2940        set kdp_pmap = 0
 2941        _kgm_flush_loop
 2942        resetctx
 2943        _kgm_flush_loop
 2944        _kgm_update_loop
 2945        resetctx
 2946        _kgm_update_loop
 2947 end
 2948 
 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.
 2953 end
 2954 
 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)
 2961              flushregs
 2962              flushstack
 2963              set $kgm_flush_loop_ctr = $kgm_flush_loop_ctr + 1
 2964        end
 2965 end
 2966 
 2967 define _kgm_update_loop
 2968        set $kgm_update_loop_ctr = 0
 2969        while ($kgm_update_loop_ctr < 30)
 2970              update
 2971              set $kgm_update_loop_ctr = $kgm_update_loop_ctr + 1
 2972        end
 2973 end
 2974 # Internal routine used by "_loadfrom" to read from 64-bit addresses
 2975 # on 32-bit kernels
 2976 define _loadk32m64
 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
 2994        else
 2995                 set $kgm_k32read64 = 0
 2996        end
 2997 end
 2998 
 2999 # Internal routine used by "showx86backtrace" to abstract possible loads from
 3000 # user space
 3001 define _loadfrom
 3002         if (kdp_pmap == 0)
 3003                 set $kgm_loadval = *(uintptr_t *)$arg0
 3004         else
 3005         if ($kgm_x86_abi == 0xe)
 3006               set $kgm_loadval = *(uint32_t *)$arg0
 3007         else
 3008         if ($kgm_x86_abi == 0xf)
 3009             if ($kgm_mtype == $kgm_mtype_i386)
 3010                     _loadk32m64 $arg0
 3011                     set $kgm_loadval = $kgm_k32read64
 3012             else
 3013                     set $kgm_loadval = *(uint64_t *)$arg0
 3014             end
 3015         end
 3016         end
 3017 end
 3018 end
 3019 
 3020 
 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.
 3027 
 3028 set $kgm_cur_frame = 0
 3029 set $kgm_cur_pc = 0
 3030 set $kgm_x86_abi = 0
 3031 define showx86backtrace
 3032         if ($kgm_mtype == $kgm_mtype_i386)
 3033                 set $kgm_frame_reg = $ebp
 3034                 set $kgm_pc = $eip
 3035                 set $kgm_ret_off = 4
 3036         end
 3037         if ($kgm_mtype == $kgm_mtype_x86_64)
 3038                 set $kgm_frame_reg = $rbp
 3039                 set $kgm_pc = $rip
 3040                 set $kgm_ret_off = 8
 3041         end
 3042 
 3043         if ($kgm_x86_abi == 0xe)
 3044                 set $kgm_ret_off = 4
 3045         end
 3046         if ($kgm_x86_abi == 0xf)
 3047                 set $kgm_ret_off = 8
 3048         end
 3049 
 3050         if ($kgm_cur_frame == 0)
 3051                 set $kgm_cur_frame = $kgm_frame_reg
 3052         end
 3053         if ($kgm_cur_pc == 0)
 3054                 set $kgm_cur_pc = $kgm_pc
 3055         end
 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)))
 3058                 x/i $kgm_cur_pc
 3059         end
 3060         set $kgm_tmp_frame = $kgm_cur_frame
 3061         set $kgm_cur_frame = 0
 3062         set $kgm_cur_pc = 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)))
 3071                    x/i $kgm_prev_pc
 3072                 end
 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
 3078         end
 3079         set kdp_pmap = 0
 3080         set $kgm_x86_abi = 0
 3081 end
 3082 
 3083 define showx86backtrace2
 3084         set $kgm_cur_frame = $arg0
 3085         set $kgm_cur_pc = $arg1
 3086         showx86backtrace
 3087 end
 3088 
 3089 define showuserstack
 3090                 select 0
 3091                 if ($kgm_mtype == $kgm_mtype_ppc)       
 3092                    if ($kdp_act_counter == 0)
 3093                       set $kdpstate = (struct savearea *) kdp.saved_state
 3094                    end
 3095                    set $kdp_act_counter = $kdp_act_counter + 1
 3096                    set $newact = (struct thread *) $arg0
 3097                    _kgm_flush_loop
 3098                    set $checkpc = $newact->machine->upcb.save_srr0
 3099                    if ($checkpc == 0)
 3100                       echo This activation does not appear to have
 3101                       echo \20 a valid user context.\n
 3102                    else       
 3103                      set (struct savearea *) kdp.saved_state=$newact->machine->upcb
 3104                      set $pc = $checkpc
 3105 #flush and update seem to be executed lazily by gdb on Tiger, hence the
 3106 #repeated invocations - see 3743135
 3107                     _kgm_flush_loop
 3108 # This works because the new pmap is used only for reads
 3109                      set kdp_pmap = $newact->task->map->pmap
 3110                      _kgm_flush_loop
 3111                      _kgm_update_loop
 3112                      bt
 3113                      resetstacks
 3114                      _kgm_flush_loop
 3115                      _kgm_update_loop
 3116                      resetstacks
 3117                      _kgm_flush_loop
 3118                      _kgm_update_loop
 3119                    end
 3120                 else
 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
 3128 
 3129                         else
 3130                                 set $checkpc = $newiss.uss.ss_32.eip
 3131                                 set $checkframe = $newiss.uss.ss_32.ebp
 3132                         end
 3133 
 3134                         if ($checkpc == 0)
 3135                             echo This activation does not appear to have
 3136                             echo \20 a valid user context.\n
 3137                         else
 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
 3141                         if ( $argc == 1 )
 3142                                 printf "You may now issue the showx86backtrace command to see the user space backtrace for this thread ("
 3143                                 showptr $arg0
 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"
 3147                         end
 3148                         set kdp_pmap = $newact->task->map->pmap
 3149                         _kgm_flush_loop
 3150                         _kgm_update_loop
 3151                         end                     
 3152                 else
 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
 3157                                 showactheader
 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]
 3161                                 showptrhdrpad
 3162                                 printf "                  "
 3163                                 showptr 0
 3164                                 printf "  "
 3165                                 showptr $kgm_threadp.machine->PcbData.pc
 3166                                 printf "\n"
 3167                                 set kdp_pmap = $kgm_thread_pmap
 3168                                 while ($kgm_thread_sp != 0)
 3169                                 set $link_register = *($kgm_thread_sp + 4)
 3170                                 showptrhdrpad
 3171                                         printf "                  "
 3172                                         showptr $kgm_thread_sp
 3173                                         printf "  "
 3174                                 showptr $link_register
 3175                                 printf "\n"
 3176                                 set $kgm_thread_sp = *$kgm_thread_sp
 3177                                 end
 3178                                 set kdp_pmap = $kgm_saved_pmap
 3179                         else
 3180                                 set $kgm_threadp = (struct thread *)$arg0
 3181                                 showactheader
 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)
 3188                                 showptrhdrpad
 3189                                         printf "                  "
 3190                                         showptr $kgm_thread_sp
 3191                                         printf "  "
 3192                                 showptr $link_register
 3193                                 printf "\n"
 3194                                 set $kgm_thread_sp = *$kgm_thread_sp_window
 3195                                 _unmap_user_data_from_task
 3196                                 end
 3197                         end
 3198                 else
 3199                         echo showuserstack not supported on this architecture\n
 3200                 end
 3201                 end
 3202                 end
 3203 end
 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.
 3214 end
 3215 
 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 "
 3222         showptr $kgm_actp
 3223         printf "\n"
 3224         showuserstack $kgm_actp quiet
 3225         if (($kgm_mtype & $kgm_mtype_x86_mask) == $kgm_mtype_x86_any)
 3226                 showx86backtrace
 3227         end
 3228         set kdp_pmap=0
 3229         set $kgm_actp = (struct thread *)($kgm_actp->task_threads.next)
 3230         printf "\n"
 3231     end
 3232     showuserlibraries $kgm_taskp
 3233 end
 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.
 3237 end
 3238 
 3239 
 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
 3249 
 3250                         printf "  rax: "
 3251                         showuserptr $kgm_ss64.rax
 3252                         printf "  rbx: "
 3253                         showuserptr $kgm_ss64.rbx
 3254                         printf "  rcx: "
 3255                         showuserptr $kgm_ss64.rcx
 3256                         printf "  rdx: "
 3257                         showuserptr $kgm_ss64.rdx
 3258                         printf "\n"
 3259 
 3260                         printf "  rdi: "
 3261                         showuserptr $kgm_ss64.rdi
 3262                         printf "  rsi: "
 3263                         showuserptr $kgm_ss64.rsi
 3264                         printf "  rbp: "
 3265                         showuserptr $kgm_ss64.rbp
 3266                         printf "  rsp: "
 3267                         showuserptr $kgm_ss64.isf.rsp
 3268                         printf "\n"
 3269 
 3270                         printf "   r8: "
 3271                         showuserptr $kgm_ss64.r8
 3272                         printf "   r9: "
 3273                         showuserptr $kgm_ss64.r9
 3274                         printf "  r10: "
 3275                         showuserptr $kgm_ss64.r10
 3276                         printf "  r11: "
 3277                         showuserptr $kgm_ss64.r11
 3278                         printf "\n"
 3279 
 3280                         printf "  r12: "
 3281                         showuserptr $kgm_ss64.r12
 3282                         printf "  r13: "
 3283                         showuserptr $kgm_ss64.r13
 3284                         printf "  r14: "
 3285                         showuserptr $kgm_ss64.r14
 3286                         printf "  r15: "
 3287                         showuserptr $kgm_ss64.r15
 3288                         printf "\n"
 3289 
 3290                         printf "  rip: "
 3291                         showuserptr $kgm_ss64.isf.rip
 3292                         printf "  rfl: "
 3293                         showuserptr $kgm_ss64.isf.rflags
 3294                         printf "  cr2: "
 3295                         showuserptr $kgm_ss64.cr2
 3296                         printf "\n"
 3297                 else
 3298                         printf "X86 Thread State (32-bit):\n"
 3299                         set $kgm_ss32 = $newiss.uss.ss_32
 3300 
 3301                         printf "  eax: "
 3302                         showuserptr $kgm_ss32.eax
 3303                         printf "  ebx: "
 3304                         showuserptr $kgm_ss32.ebx
 3305                         printf "  ecx: "
 3306                         showuserptr $kgm_ss32.ecx
 3307                         printf "  edx: "
 3308                         showuserptr $kgm_ss32.edx
 3309                         printf "\n"
 3310 
 3311                         printf "  edi: "
 3312                         showuserptr $kgm_ss32.edi
 3313                         printf "  esi: "
 3314                         showuserptr $kgm_ss32.esi
 3315                         printf "  ebp: "
 3316                         showuserptr $kgm_ss32.ebp
 3317                         printf "  esp: "
 3318                         showuserptr $kgm_ss32.uesp
 3319                         printf "\n"
 3320 
 3321                         printf "   ss: "
 3322                         showuserptr $kgm_ss32.ss
 3323                         printf "  efl: "
 3324                         showuserptr $kgm_ss32.efl
 3325                         printf "  eip: "
 3326                         showuserptr $kgm_ss32.eip
 3327                         printf "   cs: "
 3328                         showuserptr $kgm_ss32.cs
 3329                         printf "\n"
 3330 
 3331                         printf "   ds: "
 3332                         showuserptr $kgm_ss32.ds
 3333                         printf "   es: "
 3334                         showuserptr $kgm_ss32.es
 3335                         printf "   fs: "
 3336                         showuserptr $kgm_ss32.fs
 3337                         printf "   gs: "
 3338                         showuserptr $kgm_ss32.gs
 3339                         printf "\n"
 3340 
 3341                         printf "  cr2: "
 3342                         showuserptr $kgm_ss32.cr2
 3343                         printf "\n"
 3344                 end
 3345         else
 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)
 3349 
 3350                 printf "    r0: "
 3351                 showuserptr $kgm_pcb.r[0]
 3352                 printf "    r1: "
 3353                 showuserptr $kgm_pcb.r[1]
 3354                 printf "    r2: "
 3355                 showuserptr $kgm_pcb.r[2]
 3356                 printf "    r3: "
 3357                 showuserptr $kgm_pcb.r[3]
 3358                 printf "\n"
 3359 
 3360                 printf "    r4: "
 3361                 showuserptr $kgm_pcb.r[4]
 3362                 printf "    r5: "
 3363                 showuserptr $kgm_pcb.r[5]
 3364                 printf "    r6: "
 3365                 showuserptr $kgm_pcb.r[6]
 3366                 printf "    r7: "
 3367                 showuserptr $kgm_pcb.r[7]
 3368                 printf "\n"
 3369 
 3370                 printf "    r8: "
 3371                 showuserptr $kgm_pcb.r[8]
 3372                 printf "    r9: "
 3373                 showuserptr $kgm_pcb.r[9]
 3374                 printf "   r10: "
 3375                 showuserptr $kgm_pcb.r[10]
 3376                 printf "   r11: "
 3377                 showuserptr $kgm_pcb.r[11]
 3378                 printf "\n"
 3379 
 3380                 printf "    ip: "
 3381                 showuserptr $kgm_pcb.r[12]
 3382                 printf "    sp: "
 3383                 showuserptr $kgm_pcb.sp
 3384                 printf "    lr: "
 3385                 showuserptr $kgm_pcb.lr
 3386                 printf "    pc: "
 3387                 showuserptr $kgm_pcb.pc
 3388                 printf "\n"
 3389 
 3390                 printf "  cpsr: "
 3391                 showuserptr $kgm_pcb.cpsr
 3392                 printf "\n"
 3393         else
 3394                 echo showuserregisters not supported on this architecture\n
 3395         end
 3396         end
 3397 end
 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
 3405 |be accurate
 3406 end
 3407 
 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 "
 3414         showptr $kgm_actp
 3415         printf "\n"
 3416         showuserregisters $kgm_actp
 3417         set $kgm_actp = (struct thread *)($kgm_actp->task_threads.next)
 3418         printf "\n"
 3419     end
 3420 end
 3421 document showtaskuserregisters
 3422 Syntax: (gdb) showtaskuserregisters <task>
 3423 | Print out the user registers for each thread in a task
 3424 end
 3425 
 3426 define kdp-reboot
 3427 # Alternatively, set *(*(unsigned **) 0x2498) = 1 
 3428 # (or 0x5498 on PPC, 0xffffff8000002928 on x86_64, 0xffff049c on arm)
 3429        manualhdrint $kgm_kdp_pkt_hostreboot
 3430        detach
 3431 end
 3432 
 3433 document kdp-reboot
 3434 Syntax: kdp-reboot
 3435 |Reboot the remote target machine; not guaranteed to succeed. 
 3436 end
 3437 
 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
 3454 end
 3455 
 3456 define kdp-version
 3457        kdpversionint
 3458        printf "KDP VERSION = %d, FEATURE = 0x%x\n", $kgm_kdp_version, $kgm_kdp_feature
 3459 end
 3460 
 3461 document kdp-version
 3462 Syntax: kdp-version
 3463 |Get the KDP protocol version being used by the kernel.
 3464 end
 3465 
 3466 define dumpinfoint
 3467        # set up the manual KDP packet
 3468        set manual_pkt.input        = 0
 3469 
 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
 3482 
 3483        if $argc > 1
 3484           set $kgm_pkt->name      = "$arg1"
 3485        end
 3486        if $argc > 2
 3487           set $kgm_pkt->destip    = "$arg2"
 3488        end
 3489        if $argc > 3
 3490           set $kgm_pkt->routerip  = "$arg3"
 3491        end
 3492        if $argc > 4
 3493           set $kgm_pkt->port      = $arg4
 3494        end
 3495 
 3496        set manual_pkt.input       = 1
 3497        # dummy to make sure manual packet is executed
 3498        set $kgm_dummy = &_mh_execute_header
 3499 end
 3500 
 3501 define sendcore
 3502        if $argc > 1
 3503           dumpinfoint KDP_DUMPINFO_CORE $arg1 $arg0
 3504        else
 3505           dumpinfoint KDP_DUMPINFO_CORE \0 $arg0
 3506        end
 3507 end
 3508 
 3509 document sendcore
 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.
 3519 end
 3520 
 3521 define sendsyslog
 3522        if $argc > 1
 3523           dumpinfoint KDP_DUMPINFO_SYSTEMLOG $arg1 $arg0
 3524        else
 3525           dumpinfoint KDP_DUMPINFO_SYSTEMLOG \0 $arg0
 3526        end
 3527 end
 3528 
 3529 document sendsyslog
 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.
 3536 end
 3537 
 3538 define sendpaniclog
 3539        if panicstr 
 3540           if $argc > 1
 3541              dumpinfoint KDP_DUMPINFO_PANICLOG $arg1 $arg0
 3542           else
 3543              dumpinfoint KDP_DUMPINFO_PANICLOG \0 $arg0
 3544           end
 3545        else
 3546           printf "No panic log available.\n"
 3547        end
 3548 end
 3549 
 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.
 3557 end
 3558 
 3559 define getdumpinfo
 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"
 3564        else
 3565           printf "System will not reboot after kernel info gets dumped.\n"
 3566        end
 3567        if $kgm_dumpinfo->type & KDP_DUMPINFO_NORESUME
 3568           printf "System will allow a re-attach after a KDP disconnect.\n"
 3569        else
 3570           printf "System will resume after a KDP disconnect.\n"
 3571        end
 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"
 3575        else
 3576           printf "Remote dump type: "
 3577           if $kgm_dumpinfo_type == KDP_DUMPINFO_CORE
 3578              printf "Core file\n"
 3579           end
 3580           if $kgm_dumpinfo_type == KDP_DUMPINFO_PANICLOG
 3581              printf "Panic log\n"
 3582           end
 3583           if $kgm_dumpinfo_type == KDP_DUMPINFO_SYSTEMLOG
 3584              printf "System log\n"
 3585           end
 3586 
 3587           printf "Name: "
 3588           if $kgm_dumpinfo->name[0] == '\0'
 3589              printf "(autogenerated)\n"
 3590           else
 3591              printf "%s\n", $kgm_dumpinfo->name
 3592           end             
 3593 
 3594           printf "Network Info: %s[%d] ", $kgm_dumpinfo->destip, $kgm_dumpinfo->port
 3595           if $kgm_dumpinfo->routerip[0] == '\0'
 3596              printf "\n"
 3597           else
 3598              printf "Router: %s\n", $kgm_dumpinfo->routerip
 3599           end
 3600        end
 3601 end
 3602 
 3603 document getdumpinfo
 3604 Syntax: getdumpinfo
 3605 |Retrieve the current remote dump settings. 
 3606 end
 3607 
 3608 define setdumpinfo
 3609        dumpinfoint KDP_DUMPINFO_SETINFO $arg0 $arg1 $arg2 $arg3
 3610 end
 3611 
 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.
 3618 end
 3619 
 3620 define disablecore
 3621        dumpinfoint KDP_DUMPINFO_DISABLE
 3622 end
 3623 
 3624 document disablecore
 3625 Syntax: 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.
 3629 end
 3630 
 3631 define switchtocorethread
 3632         set $newact = (struct thread *) $arg0
 3633         select 0
 3634         if ($newact->kernel_stack == 0)
 3635            echo This thread does not have a stack.\n
 3636            echo continuation:
 3637            output/a (unsigned) $newact.continuation
 3638            echo \n
 3639         else
 3640         if ($kgm_mtype == $kgm_mtype_ppc)
 3641            loadcontext $newact->machine->pcb
 3642            flushstack
 3643            set $pc = $newact->machine->pcb.save_srr0
 3644         else
 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
 3650                 flushstack
 3651         else
 3652                 echo switchtocorethread not supported on this architecture\n
 3653         end
 3654         end
 3655         showcontext_int
 3656         end
 3657 end
 3658 
 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.
 3668 end
 3669 
 3670 define loadcontext
 3671         select 0
 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
 3677 
 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
 3708 
 3709         set $cr = $kgm_contextp.save_cr
 3710         set $ctr = $kgm_contextp.save_ctr
 3711        else
 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
 3720         else
 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
 3731         else
 3732                 echo loadcontext not supported on this architecture\n
 3733         end
 3734         end
 3735         end
 3736 end
 3737 
 3738 define resetcorectx
 3739         select 0
 3740         if ($kgm_mtype == $kgm_mtype_ppc)
 3741                 set $kgm_corecontext = (struct savearea *) kdp.saved_state
 3742                 loadcontext $kgm_corecontext
 3743         else
 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
 3754                 flushregs
 3755                 flushstack
 3756                 set $pc = $kdpstatep->eip
 3757                 update
 3758         else
 3759                 echo resetcorectx not supported on this architecture\n
 3760         end
 3761         end
 3762         showcontext_int
 3763 end
 3764 
 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.
 3771 end
 3772 
 3773 #Helper function for "showallgdbstacks"
 3774 
 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
 3782             printf "I" 
 3783         end
 3784         if $kgm_state & 0x40
 3785             printf "P" 
 3786         end
 3787         if $kgm_state & 0x20
 3788             printf "A" 
 3789         end
 3790         if $kgm_state & 0x10
 3791             printf "H" 
 3792         end
 3793         if $kgm_state & 0x08
 3794             printf "U" 
 3795         end
 3796         if $kgm_state & 0x04
 3797             printf "R" 
 3798         end
 3799         if $kgm_state & 0x02
 3800             printf "S" 
 3801         end
 3802         if $kgm_state & 0x01
 3803             printf "W\t" 
 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
 3810                         end
 3811             end
 3812         end
 3813         if $arg1 != 0
 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
 3817                 end
 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
 3821                 end
 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
 3827                 end
 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)))
 3831                                 set $mysp = $r7
 3832                         else
 3833                                 set $kgm_statep = (struct arm_saved_state *)$kgm_thread.machine.kstackptr
 3834                                 set $mysp = $kgm_statep->r[7]
 3835                         end
 3836                 end
 3837                 set $prevsp = 0
 3838                 printf "\n\t\tstacktop=0x%08x", $mysp
 3839                 if ($arg2 == 0)
 3840                         switchtoact $arg0
 3841                 else
 3842                         switchtocorethread $arg0
 3843                 end
 3844                 bt
 3845             else
 3846                 printf "\n\t\t\tcontinuation="
 3847                 output /a (unsigned) $kgm_thread.continuation
 3848             end
 3849             printf "\n"
 3850         else
 3851             printf "\n"
 3852         end
 3853 end         
 3854 
 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.
 3860 
 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
 3865         showtaskheader
 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
 3870             showactheader
 3871             showgdbthread $kgm_actp 1 0
 3872             set $kgm_actp = (struct thread *)($kgm_actp->task_threads.next)
 3873         end
 3874         printf "\n"
 3875         set $kgm_taskp = (struct task *)($kgm_taskp->tasks.next)
 3876     end
 3877     resetctx
 3878 end
 3879 
 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
 3890 | errors.
 3891 end
 3892 
 3893 define showallgdbcorestacks
 3894         select 0
 3895         set $kgm_head_taskp = &tasks
 3896         set $kgm_taskp = (struct task *)($kgm_head_taskp->next)
 3897         while $kgm_taskp != $kgm_head_taskp
 3898                 showtaskheader
 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
 3903                 showactheader
 3904                 showgdbthread $kgm_actp 1 1
 3905                 set $kgm_actp = (struct thread *)($kgm_actp->task_threads.next)
 3906                 end
 3907                 printf "\n"
 3908                 set $kgm_taskp = (struct task *)($kgm_taskp->tasks.next)
 3909         end
 3910         resetcorectx
 3911 end
 3912 
 3913 
 3914 document showallgdbcorestacks
 3915 Syntax: showallgdbcorestacks
 3916 |Corefile version of "showallgdbstacks"
 3917 end
 3918 
 3919 
 3920 define switchtouserthread
 3921                 select 0
 3922                 if ($kgm_mtype == $kgm_mtype_ppc)       
 3923                    if ($kdp_act_counter == 0)
 3924                       set $kdpstate = (struct savearea *) kdp.saved_state
 3925                    end
 3926                    set $kdp_act_counter = $kdp_act_counter + 1
 3927                    set $newact = (struct thread *) $arg0
 3928                    _kgm_flush_loop
 3929                    set $checkpc = $newact->machine->upcb.save_srr0
 3930                    if ($checkpc == 0)
 3931                       echo This activation does not appear to have
 3932                       echo \20 a valid user context.\n
 3933                    else       
 3934                      set (struct savearea *) kdp.saved_state=$newact->machine->upcb
 3935                      set $pc = $checkpc
 3936 #flush and update seem to be executed lazily by gdb on Tiger, hence the
 3937 #repeated invocations - see 3743135
 3938                     _kgm_flush_loop
 3939 # This works because the new pmap is used only for reads
 3940                      set kdp_pmap = $newact->task->map->pmap
 3941                      _kgm_flush_loop
 3942                      _kgm_update_loop
 3943                    end
 3944                 else
 3945                    echo switchtouserthread not implemented for this architecture.\n
 3946         end
 3947 end
 3948 
 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.
 3973 end
 3974 
 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
 3980 end
 3981 
 3982 define showstring
 3983     printf "\"%s\"", ((OSString *)$arg0)->string
 3984 end
 3985 
 3986 define shownumber
 3987     printf "%lld", ((OSNumber *)$arg0)->value
 3988 end
 3989 
 3990 define showboolean
 3991     if ($arg0 == gOSBooleanFalse)
 3992         printf "No"
 3993     else
 3994         printf "Yes"
 3995     end
 3996 end
 3997 
 3998 define showdatabytes
 3999     set $kgm_data = (OSData *)$arg0
 4000 
 4001     printf "<"
 4002     set $kgm_datap = (const unsigned char *) $kgm_data->data
 4003         set $kgm_idx = 0
 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
 4008         end
 4009         printf ">\n"
 4010 end
 4011 
 4012 define showdata
 4013     set $kgm_data = (OSData *)$arg0
 4014 
 4015     printf "<"
 4016     set $kgm_datap = (const unsigned char *) $kgm_data->data
 4017 
 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)
 4022             set $kgm_idx = 0
 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
 4029                 end
 4030             end
 4031         end
 4032     end
 4033     
 4034     set $kgm_idx = 0
 4035     if ($kgm_printstr)
 4036         set $kgm_quoted = 0
 4037         while ($kgm_idx < $kgm_data->length)
 4038             set $kgm_char = $kgm_datap[$kgm_idx++]
 4039             if ($kgm_char)
 4040                 if (0 == $kgm_quoted)
 4041                     set $kgm_quoted = 1
 4042                     if ($kgm_idx > 1)
 4043                         printf ",\""
 4044                     else
 4045                         printf "\""
 4046                     end
 4047                 end
 4048                 printf "%c", $kgm_char
 4049             else
 4050                 if ($kgm_quoted)
 4051                     set $kgm_quoted = 0
 4052                     printf "\""
 4053                 end
 4054             end
 4055         end
 4056         if ($kgm_quoted)
 4057             printf "\""
 4058         end
 4059     else
 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
 4064             end
 4065         end
 4066         while ($kgm_idx < $kgm_data->length)
 4067             printf "%02x", $kgm_datap[$kgm_idx++]
 4068         end
 4069     end
 4070     printf ">"
 4071 end
 4072 
 4073 define showdictionaryint
 4074     set $kgm$arg0_dict = (OSDictionary *)$arg1
 4075 
 4076     printf "{"
 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
 4081         printf "="
 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)
 4085             printf ","
 4086         end
 4087     end
 4088     printf "}"
 4089 end
 4090 
 4091 define indent
 4092     set $kgm_idx = 0
 4093     while ($kgm_idx < $arg0)
 4094         if ($arg1 & (1 << $kgm_idx++))
 4095             printf "| "
 4096         else
 4097             printf "  "
 4098         end
 4099     end
 4100 end
 4101 
 4102 define showregdictionary
 4103     indent $kgm_reg_depth+2 $arg1
 4104     printf "{\n"
 4105 
 4106     set $kgm_reg_idx = 0
 4107     while ($kgm_reg_idx < $arg0->count)
 4108         indent $kgm_reg_depth+2 $arg1
 4109         printf "  "
 4110         set $kgm_obj = $arg0->dictionary[$kgm_reg_idx].key
 4111         showobjectint _ $kgm_obj
 4112         printf " = "
 4113 
 4114         set $kgm_obj = $arg0->dictionary[$kgm_reg_idx++].value
 4115         showobjectint _ $kgm_obj
 4116         printf "\n"
 4117     end
 4118     indent $kgm_reg_depth+2 $arg1
 4119     printf "}\n"
 4120 end
 4121 
 4122 
 4123 define showorderedsetarrayint
 4124     set $kgm$arg0_array = (_Element *)$arg1
 4125     set $kgm$arg0_count = $arg2
 4126 
 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)
 4132             printf ","
 4133         end
 4134     end
 4135 end
 4136 
 4137 define showorderedsetint
 4138     set $kgm_array = ((OSOrderedSet *)$arg1)->array
 4139     set $count = ((OSOrderedSet *)$arg1)->count
 4140     printf "["
 4141     showorderedsetarrayint $arg0 $kgm_array $count
 4142     printf "]"
 4143 end
 4144 
 4145 define showarraysetint
 4146     set $kgm$arg0_array = (OSArray *)$arg1
 4147 
 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)
 4153             printf ","
 4154         end
 4155     end
 4156 end
 4157 
 4158 define showarrayint
 4159     printf "("
 4160     showarraysetint $arg0 $arg1
 4161     printf ")"
 4162 end
 4163 
 4164 define showsetint
 4165     set $kgm_array = ((OSSet *)$arg1)->members
 4166     printf "["
 4167     showarraysetint $arg0 $kgm_array
 4168     printf "]"
 4169 end
 4170 
 4171 
 4172 define showobjectint
 4173     set $kgm_obj = (OSObject *) $arg1
 4174     set $kgm_vt = *((void **) $arg1)
 4175 
 4176     if ($kgm_lp64 || $kgm_mtype == $kgm_mtype_arm)
 4177         set $kgm_vt = $kgm_vt - 2 * sizeof(void *)
 4178     end
 4179 
 4180     if ($kgm_show_object_addrs)
 4181         printf "`object "
 4182         showptr $arg1
 4183         printf ", vt "
 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
 4187         end
 4188         printf "` "
 4189     end
 4190 
 4191     # No multiple-inheritance
 4192     set $kgm_shown = 0
 4193     if ($kgm_vt == &_ZTV8OSString)
 4194         showstring $arg1
 4195         set $kgm_shown = 1
 4196     end
 4197         if ($kgm_vt == &_ZTV8OSSymbol)
 4198             showstring $arg1
 4199         set $kgm_shown = 1
 4200     end
 4201     if ($kgm_vt == &_ZTV8OSNumber)
 4202                 shownumber $arg1
 4203         set $kgm_shown = 1
 4204     end
 4205     if ($kgm_vt == &_ZTV6OSData)
 4206         if $kgm_show_data_alwaysbytes == 1
 4207             showdatabytes $arg1
 4208         else
 4209             showdata $arg1
 4210         end
 4211         set $kgm_shown = 1
 4212     end
 4213     if ($kgm_vt == &_ZTV9OSBoolean)
 4214         showboolean $arg1
 4215         set $kgm_shown = 1
 4216     end
 4217     if ($kgm_vt == &_ZTV12OSDictionary)
 4218         showdictionaryint _$arg0 $arg1
 4219         set $kgm_shown = 1
 4220     end
 4221     if ($kgm_vt == &_ZTV7OSArray)
 4222         showarrayint _$arg0 $arg1
 4223         set $kgm_shown = 1
 4224     end
 4225     if ($kgm_vt == &_ZTV5OSSet)
 4226         showsetint _$arg0 $arg1
 4227         set $kgm_shown = 1
 4228     end
 4229     if ($kgm_vt == &_ZTV12OSOrderedSet)
 4230         showorderedsetint _$arg0 $arg1
 4231         set $kgm_shown = 1
 4232     end
 4233     
 4234     if ($kgm_shown != 1)
 4235         if ($kgm_show_object_addrs == 0)
 4236             printf "`object "
 4237             showptr $arg1
 4238             printf ", vt "
 4239             output /a (unsigned long) $kgm_vt
 4240             printf "`"
 4241         end
 4242     end
 4243 end
 4244 
 4245 define showobject
 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
 4252     printf "\n"
 4253 end
 4254 document showobject
 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.
 4258 end
 4259 
 4260 define dictget 
 4261     set $kgm_dictp = (OSDictionary *)$arg0
 4262     set $kgm_keyp = (const OSSymbol *)$arg1
 4263     set $kgm_idx = 0
 4264     set $kgm_result = 0
 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
 4268         end
 4269         set $kgm_idx = $kgm_idx + 1
 4270     end
 4271 end
 4272 
 4273 
 4274 define _registryentryrecurseinit
 4275     set $kgm_re         = (IOService *)$arg1
 4276     set $kgm$arg0_stack = (unsigned long long) $arg2
 4277 
 4278     if ($arg3)
 4279         set $kgm$arg0_stack = $kgm$arg0_stack | (1ULL << $kgm_reg_depth)
 4280     else
 4281         set $kgm$arg0_stack = $kgm$arg0_stack & ~(1ULL << $kgm_reg_depth)
 4282     end
 4283 
 4284     dictget $kgm_re->fRegistryTable $kgm_childkey
 4285     set $kgm$arg0_child_array = (OSArray *) $kgm_result
 4286 
 4287     if ($kgm$arg0_child_array)
 4288         set $kgm$arg0_child_count = $kgm$arg0_child_array->count
 4289     else
 4290         set $kgm$arg0_child_count = 0
 4291     end
 4292 
 4293     if ($kgm$arg0_child_count)
 4294         set $kgm$arg0_stack = $kgm$arg0_stack | (2ULL << $kgm_reg_depth)
 4295     else
 4296         set $kgm$arg0_stack = $kgm$arg0_stack & ~(2ULL << $kgm_reg_depth)
 4297     end
 4298 end
 4299 
 4300 define findregistryentryrecurse
 4301     set $kgm_registry_entry = 0
 4302     _registryentryrecurseinit $arg0 $arg1 $arg2 $arg3
 4303 
 4304     dictget $kgm_re->fRegistryTable $kgm_namekey
 4305     if ($kgm_result == 0)
 4306         dictget $kgm_re->fRegistryTable gIONameKey
 4307     end
 4308     if ($kgm_result == 0)
 4309         dictget $kgm_re->fPropertyTable gIOClassKey
 4310     end
 4311 
 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
 4316           echo .
 4317        end
 4318 
 4319        if $kgm_strcmp_result == 0
 4320           if $kgm_findregistry_verbose
 4321              printf "\n%s:\n | ", ((OSString *) $kgm_result)->string
 4322              showobject $kgm_re
 4323              printf " | "
 4324              print $kgm_re
 4325           end
 4326 
 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
 4330           end
 4331        end
 4332     end
 4333 
 4334     # recurse
 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
 4338 
 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
 4343                loop_break
 4344             end
 4345             findregistryentryrecurse _$arg0 $kgm_re $kgm$arg0_stack $kgm_more_sib 
 4346             if $kgm_registry_entry
 4347                loop_break
 4348             end
 4349         end
 4350         set $kgm_reg_depth = $kgm_reg_depth - 1
 4351     end
 4352 end
 4353 
 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 
 4361 
 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
 4367            end
 4368            loop_break
 4369         end
 4370         set $kgm_reg_idx = $kgm_reg_idx + 1
 4371     end
 4372 end
 4373 
 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
 4384 
 4385     if $argc > 0
 4386        set $kgm_reg_find_str0 = $arg0
 4387     end
 4388     if $argc > 1
 4389        set $kgm_reg_find_str1 = $arg1
 4390     end
 4391     if $argc > 2
 4392        set $kgm_reg_find_str2 = $arg2
 4393     end
 4394     if $argc > 3
 4395        set $kgm_reg_find_str3 = $arg3
 4396     end
 4397     if $argc > 4
 4398        set $kgm_reg_find_str4 = $arg4
 4399     end
 4400     if $argc > 5
 4401        set $kgm_reg_find_str5 = $arg5
 4402     end
 4403     if $argc > 6
 4404        set $kgm_reg_find_str6 = $arg6
 4405     end
 4406     if $argc > 7
 4407        set $kgm_reg_find_str7 = $arg7
 4408     end
 4409     if $argc > 8
 4410        set $kgm_reg_find_str8 = $arg8
 4411     end
 4412 end
 4413 
 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
 4419 end
 4420 
 4421 define _findregistryprop
 4422     set $reg       = (IOService *) $arg0
 4423     set $kgm_props = $reg->fPropertyTable
 4424     set $kgm_findregistry_verbose = 0
 4425 
 4426     findregdictvalue $kgm_props 
 4427 end
 4428 
 4429 define findregistryprop
 4430     set $reg       = (IOService *) $arg0
 4431     set $kgm_props = $reg->fPropertyTable
 4432 
 4433     set $kgm_findregistry_verbose = 1
 4434     findregdictvalue $kgm_props 
 4435 end
 4436 
 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.
 4441 |
 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
 4450 end
 4451 
 4452 define findregistryentryint
 4453     if !$kgm_reg_plane
 4454        set $kgm_reg_plane = (IORegistryPlane *) gIOServicePlane
 4455     end
 4456 
 4457     if !$kgm_reg_plane
 4458        printf "Please load kgmacros after KDP attaching to the target.\n"
 4459     else
 4460        set $kgm_namekey   = (OSSymbol *) $kgm_reg_plane->nameKey
 4461        set $kgm_childkey  = (OSSymbol *) $kgm_reg_plane->keys[1]
 4462        if $kgm_findregistry_verbose
 4463           printf "Searching"
 4464        end
 4465        findregistryentryrecurse _ $arg0 0 0
 4466     end
 4467 end
 4468 
 4469 define _findregistryentry
 4470     set $kgm_findregistry_verbose  = 0
 4471     set $kgm_findregistry_continue = 0
 4472     set $kgm_reg_depth             = 0
 4473 
 4474     findregistryentryint gRegistryRoot
 4475 end
 4476 
 4477 define findregistryentry
 4478     set $kgm_findregistry_verbose  = 1
 4479     set $kgm_findregistry_continue = 0
 4480     set $kgm_reg_depth             = 0
 4481 
 4482     findregistryentryint gRegistryRoot
 4483 end
 4484 
 4485 define findregistryentries
 4486     set $kgm_findregistry_verbose  = 1
 4487     set $kgm_findregistry_continue = 1
 4488     set $kgm_reg_depth             = 0
 4489 
 4490     findregistryentryint gRegistryRoot
 4491 end
 4492 
 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.
 4498 |
 4499 | For example, the following will pull out the AppleACPIPlatformExpert registry
 4500 | entry:
 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
 4508 |         findregistryentry
 4509 end
 4510 
 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.
 4516 end
 4517 
 4518 
 4519 define showregistryentryrecurse
 4520     _registryentryrecurseinit $arg0 $arg1 $arg2 $arg3
 4521 
 4522     indent $kgm_reg_depth $kgm$arg0_stack
 4523     printf "+-o "
 4524 
 4525     dictget $kgm_re->fRegistryTable $kgm_namekey
 4526     if ($kgm_result == 0)
 4527         dictget $kgm_re->fRegistryTable gIONameKey
 4528     end
 4529     if ($kgm_result == 0)
 4530         dictget $kgm_re->fPropertyTable gIOClassKey
 4531     end
 4532 
 4533     if ($kgm_result != 0)
 4534         printf "%s", ((OSString *)$kgm_result)->string
 4535     else
 4536         if (((IOService*)$kgm_re)->pwrMgt &&  ((IOService*)$kgm_re)->pwrMgt->Name)
 4537             printf "%s", ((IOService*)$kgm_re)->pwrMgt->Name
 4538         else
 4539 #           printf ", guessclass "
 4540 #           guessclass $kgm_re
 4541             printf "??"
 4542         end
 4543     end
 4544 
 4545 
 4546     printf "  <object "
 4547     showptr $kgm_re
 4548     printf ", id 0x%llx, ", $kgm_re->IORegistryEntry::reserved->fRegistryEntryID
 4549     printf "vtable "
 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 *)
 4553     end
 4554     output /a $kgm_vt
 4555 
 4556     if ($kgm_vt != &_ZTV15IORegistryEntry)
 4557         printf ", "
 4558         set $kgm_state =  $kgm_re->__state[0]
 4559         # kIOServiceRegisteredState
 4560         if (0 == ($kgm_state & 2))
 4561             printf "!"
 4562         end
 4563         printf "registered, "
 4564         # kIOServiceMatchedState
 4565         if (0 == ($kgm_state & 4))
 4566             printf "!"
 4567         end
 4568         printf "matched, "
 4569         # kIOServiceInactiveState
 4570         if ($kgm_state & 1)
 4571             printf "in"
 4572         end
 4573         printf "active, busy %d, retain count %d", (0xff & $kgm_re->__state[1]), (0xffff & $kgm_re->retainCount)
 4574     end
 4575     printf ">\n"
 4576 
 4577     if ($kgm_show_props)
 4578         set $kgm_props = $kgm_re->fPropertyTable
 4579         showregdictionary $kgm_props $kgm$arg0_stack
 4580     end
 4581 
 4582     # recurse
 4583     if ($kgm$arg0_child_count != 0)
 4584 
 4585         set $kgm_reg_depth = $kgm_reg_depth + 1
 4586         set $kgm$arg0_child_idx = 0
 4587 
 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
 4592                loop_break
 4593             end
 4594             showregistryentryrecurse _$arg0 $kgm_re $kgm$arg0_stack $kgm_more_sib
 4595         end
 4596 
 4597         set $kgm_reg_depth = $kgm_reg_depth - 1
 4598     end
 4599 end
 4600 
 4601 define showregistryentryint
 4602     if !$kgm_reg_plane
 4603        set $kgm_reg_plane = (IORegistryPlane *) gIOServicePlane
 4604     end
 4605 
 4606     if !$kgm_reg_plane
 4607        printf "Please load kgmacros after KDP attaching to the target.\n"
 4608     else        
 4609        set $kgm_namekey   = (OSSymbol *) $kgm_reg_plane->nameKey
 4610        set $kgm_childkey  = (OSSymbol *) $kgm_reg_plane->keys[1]
 4611        showregistryentryrecurse _ $arg0 0 0
 4612     end
 4613 end
 4614 
 4615 define showregistry
 4616     set $kgm_reg_depth  = 0
 4617     set $kgm_show_props = 0
 4618     showregistryentryint gRegistryRoot
 4619 end
 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.
 4624 end
 4625 
 4626 define showregistryprops
 4627     set $kgm_reg_depth  = 0
 4628     set $kgm_show_props = 1
 4629     showregistryentryint gRegistryRoot
 4630 end
 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
 4636 end
 4637 
 4638 define showregistryentry
 4639     set $kgm_reg_depth  = 0
 4640     set $kgm_show_props = 1
 4641     showregistryentryint $arg0
 4642 end
 4643 document showregistryentry
 4644 Syntax: (gdb) showregistryentry <object address>
 4645 | Show info about a registry entry; its properties and descendants in the current plane.
 4646 end
 4647 
 4648 define setregistryplane
 4649     if ($arg0 != 0)
 4650         set $kgm_reg_plane = (IORegistryPlane *) $arg0
 4651     else
 4652         showobjectint _ gIORegistryPlanes
 4653         printf "\n"
 4654     end
 4655 end
 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.
 4660 end
 4661 
 4662 define guessclass
 4663     set $kgm_classidx = 0
 4664     set $kgm_lookvt = *((void **) $arg0)
 4665     set $kgm_bestvt = (void *) 0
 4666     set $kgm_bestidx = 0
 4667     
 4668     while $kgm_classidx < sAllClassesDict->count
 4669         set $kgm_meta = (OSMetaClass *) sAllClassesDict->dictionary[$kgm_classidx].value
 4670 
 4671         set $kgm_vt = *((void **) $kgm_meta)
 4672 
 4673         if (($kgm_vt > $kgm_bestvt) && ($kgm_vt < $kgm_lookvt))
 4674             set $kgm_bestvt  = $kgm_vt
 4675             set $kgm_bestidx = $kgm_classidx
 4676         end
 4677         set $kgm_classidx = $kgm_classidx + 1
 4678     end
 4679     printf "%s", sAllClassesDict->dictionary[$kgm_bestidx].key->string
 4680 end
 4681 
 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
 4687     end
 4688 end
 4689 
 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.
 4693 end
 4694 
 4695 define showioalloc
 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
 4700 end
 4701 
 4702 document showioalloc
 4703 Syntax: (gdb) showioalloc
 4704 | Show some accounting of memory allocated by IOKit allocators. See ioalloccount man page for details.
 4705 end
 4706 
 4707 define showosobjecttracking
 4708     set $kgm_next = (OSObjectTracking *) gOSObjectTrackList.next
 4709     while $kgm_next != &gOSObjectTrackList
 4710         set $obj = (OSObject *) ($kgm_next+1)
 4711         showobject $obj
 4712         set $kgm_idx = 0
 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]
 4716                 printf "\n"
 4717             else
 4718                 if ((unsigned long) $kgm_next->bt[$kgm_idx] > 0)
 4719                     output /a $kgm_next->bt[$kgm_idx]
 4720                     printf "\n"
 4721                 end
 4722             end
 4723             set $kgm_idx = $kgm_idx + 1
 4724         end
 4725         printf "\n"
 4726         set $kgm_next = (OSObjectTracking *) $kgm_next->link.next
 4727     end
 4728 end
 4729 
 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.
 4735 end
 4736 
 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.
 4741 define readphysint
 4742     set $kgm_readphysint_result = 0xBAD10AD
 4743 
 4744     if ($kgm_readphys_force_kdp != 0)
 4745         set $kgm_readphys_use_kdp = 1
 4746     else
 4747         if ($kgm_readphys_force_physmap)
 4748             set $kgm_readphys_use_kdp = 0
 4749         else
 4750             set $kgm_readphys_use_kdp = ( kdp->is_conn > 0 )
 4751         end
 4752     end
 4753 
 4754     if ($kgm_readphys_use_kdp)
 4755 
 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)
 4773             if $arg1 == 8
 4774                 set $kgm_readphysint_result = *((uint8_t *)$kgm_pkt->data)
 4775             end
 4776             if $arg1 == 16
 4777                 set $kgm_readphysint_result = *((uint16_t *)$kgm_pkt->data)
 4778             end
 4779             if $arg1 == 32
 4780                 set $kgm_readphysint_result = *((uint32_t *)$kgm_pkt->data)
 4781             end
 4782             if $arg1 == 64
 4783                 set $kgm_readphysint_result = *((uint64_t *)$kgm_pkt->data)
 4784             end
 4785         end
 4786 
 4787     else
 4788         # No KDP. Attempt to use physical memory mapping
 4789 
 4790         if ($kgm_mtype == $kgm_mtype_x86_64)
 4791             set $kgm_readphys_paddr_in_kva = (unsigned long long)$arg0 + physmap_base
 4792         else
 4793             if ($kgm_mtype == $kgm_mtype_arm)
 4794                 set $kgm_readphys_paddr_in_kva = (unsigned long long)$arg0 - gPhysBase + gVirtBase
 4795             else
 4796                 printf "readphys not available for current architecture.\n"
 4797                 set $kgm_readphys_paddr_in_kva = 0
 4798             end
 4799         end
 4800         if $kgm_readphys_paddr_in_kva
 4801             if $arg1 == 8
 4802                 set $kgm_readphysint_result = *((uint8_t *)$kgm_readphys_paddr_in_kva)
 4803             end
 4804             if $arg1 == 16
 4805                 set $kgm_readphysint_result = *((uint16_t *)$kgm_readphys_paddr_in_kva)
 4806             end
 4807             if $arg1 == 32
 4808                 set $kgm_readphysint_result = *((uint32_t *)$kgm_readphys_paddr_in_kva)
 4809             end
 4810             if $arg1 == 64
 4811                 set $kgm_readphysint_result = *((uint64_t *)$kgm_readphys_paddr_in_kva)
 4812             end
 4813         end
 4814     end
 4815 end
 4816 
 4817 define readphys8
 4818        readphysint $arg0 8 $kgm_lcpu_self
 4819        output /a $arg0
 4820        printf ":\t0x%02hhx\n", $kgm_readphysint_result
 4821        set $kgm_readphys_result = (uint64_t)$kgm_readphysint_result
 4822 end
 4823 
 4824 define readphys16
 4825        readphysint $arg0 16 $kgm_lcpu_self
 4826        output /a $arg0
 4827        printf ":\t0x%04hx\n", $kgm_readphysint_result
 4828        set $kgm_readphys_result = (uint64_t)$kgm_readphysint_result
 4829 end
 4830 
 4831 define readphys32
 4832        readphysint $arg0 32 $kgm_lcpu_self
 4833        output /a $arg0
 4834        printf ":\t0x%08x\n", $kgm_readphysint_result
 4835        set $kgm_readphys_result = (uint64_t)$kgm_readphysint_result
 4836 end
 4837 
 4838 define readphys64
 4839        readphysint $arg0 64 $kgm_lcpu_self
 4840        output /a $arg0
 4841        printf ":\t0x%016llx\n", $kgm_readphysint_result
 4842        set $kgm_readphys_result = (uint64_t)$kgm_readphysint_result
 4843 end
 4844 
 4845 define readphys
 4846        readphys32 $arg0
 4847 end
 4848 
 4849 document readphys8
 4850 | See readphys64
 4851 end
 4852 
 4853 document readphys16
 4854 | See readphys64
 4855 end
 4856 
 4857 document readphys32
 4858 | See readphys64
 4859 end
 4860 
 4861 document readphys64
 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.
 4864 end
 4865 
 4866 define writephysint
 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
 4879        if $arg1 == 8
 4880           set *(uint8_t *)$kgm_pkt->data = (uint8_t)$arg2
 4881        end
 4882        if $arg1 == 16
 4883           set *(uint16_t *)$kgm_pkt->data = (uint16_t)$arg2
 4884        end
 4885        if $arg1 == 32
 4886           set *(uint32_t *)$kgm_pkt->data = (uint32_t)$arg2
 4887        end
 4888        if $arg1 == 64
 4889           set *(uint64_t *)$kgm_pkt->data = (uint64_t)$arg2
 4890        end
 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
 4896 end
 4897 
 4898 define writephys8
 4899        writephysint $arg0 8 $arg1 $kgm_lcpu_self
 4900 end
 4901 
 4902 define writephys16
 4903        writephysint $arg0 16 $arg1 $kgm_lcpu_self
 4904 end
 4905 
 4906 define writephys32
 4907        writephysint $arg0 32 $arg1 $kgm_lcpu_self
 4908 end
 4909 
 4910 define writephys64
 4911        writephysint $arg0 64 $arg1 $kgm_lcpu_self
 4912 end
 4913 
 4914 document writephys8
 4915 | See writephys64
 4916 end
 4917 
 4918 document writephys16
 4919 | See writephys64
 4920 end
 4921 
 4922 document writephys32
 4923 | See writephys64
 4924 end
 4925 
 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.
 4929 end
 4930 
 4931 define addkextsyms
 4932         if ($argc <= 1)
 4933                 if ($argc == 0)
 4934                         printf "Adding kext symbols from in-kernel summary data.\n"
 4935                         add-all-kexts
 4936                 else
 4937                         printf "Adding kext symbols from $arg0.\n"
 4938                         shell echo cd `pwd` > /tmp/gdb-cd
 4939                         cd $arg0
 4940                         source kcbmacros
 4941                         source /tmp/gdb-cd
 4942                 end
 4943                 set $kgm_show_kmod_syms = 1
 4944         else
 4945                 printf "| Usage:\n|\n"
 4946                 help addkextsyms
 4947         end
 4948 end
 4949 
 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.
 4954 | (gdb) addkextsyms
 4955 | - or -
 4956 | (gdb) addkextsyms /path/to/symboldir
 4957 end
 4958 
 4959 define showprocfiles
 4960     if ($argc == 1)
 4961         _showprocheader
 4962         _showprocfiles $arg0
 4963     else
 4964         printf "| Usage:\n|\n"
 4965         help showprocfiles
 4966     end
 4967 end
 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.
 4972 end
 4973 
 4974 define _showprocheader
 4975     printf "fd     fileglob  "
 4976     showptrhdrpad
 4977     printf "  fg flags    fg type   fg data   "
 4978     showptrhdrpad
 4979     printf "  info\n"
 4980     printf "-----  ----------"
 4981     if $kgm_lp64
 4982         printf "--------"
 4983     end
 4984     printf "  ----------  --------  ----------"
 4985     if $kgm_lp64
 4986         printf "--------"
 4987     end
 4988     printf "  -------------------\n"
 4989 end
 4990 
 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
 5000         else
 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
 5005             showptr $kgm_spf_fg
 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)
 5010                 printf "VNODE   "
 5011             end
 5012             if ($kgm_spf_fgt == 2)
 5013                 printf "SOCKET  "
 5014             end
 5015             if ($kgm_spf_fgt == 3)
 5016                 printf "PSXSHM  "
 5017             end
 5018             if ($kgm_spf_fgt == 4)
 5019                 printf "PSXSEM  "
 5020             end
 5021             if ($kgm_spf_fgt == 5)
 5022                 printf "KQUEUE  "
 5023             end
 5024             if ($kgm_spf_fgt == 6)
 5025                 printf "PIPE    "
 5026             end
 5027             if ($kgm_spf_fgt == 7)
 5028                 printf "FSEVENTS"
 5029             end
 5030             if ($kgm_spf_fgt < 1 || $kgm_spf_fgt > 7)
 5031                 printf "?: %-5d", $kgm_spf_fgt
 5032             end
 5033 
 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
 5037             printf "  "
 5038             showptr $kgm_spf_fgd
 5039             printf "  "
 5040             if ($kgm_spf_fgt == 1)
 5041                 set $kgm_spf_name = ((struct vnode *)$kgm_spf_fgd)->v_name
 5042                 if ($kgm_spf_name == 0)
 5043                     printf "(null)"
 5044                 else
 5045                     printf "%s", $kgm_spf_name
 5046                 end
 5047             end
 5048             printf "\n"
 5049         end
 5050         set $kgm_spf_count = $kgm_spf_count + 1
 5051     end
 5052 end
 5053 
 5054 #
 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.
 5059 #
 5060 define showproclocks
 5061     if ($argc == 1)
 5062         _showproclocks $arg0
 5063     else
 5064         printf "| Usage:\n|\n"
 5065         help showproclocks
 5066     end
 5067 end
 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.
 5072 end
 5073 
 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
 5084         else
 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
 5096                     end
 5097                     set $kgm_spl_seen = $kgm_spl_seen + 1
 5098                     printf "( fd %d, name ", $kgm_spl_count
 5099                     if ($kgm_spl_name == 0)
 5100                         printf "(null) )"
 5101                     else
 5102                         printf "%s )\n", $kgm_spl_name
 5103                     end
 5104                     _showvnodelocks $kgm_spl_fgd
 5105                 end
 5106             end
 5107         end
 5108         set $kgm_spl_count = $kgm_spf_count + 1
 5109     end
 5110     printf "%d total locks for ", $kgm_spl_seen
 5111     showptr $arg0
 5112     printf "\n"
 5113 end
 5114 
 5115 define showprocinfo
 5116     set $kgm_spi_proc = (proc_t)$arg0
 5117     printf "Process "
 5118     showptr $kgm_spi_proc
 5119     printf "\n"
 5120     printf "   name %s\n", $kgm_spi_proc->p_comm
 5121     printf "   pid:%.8d", $kgm_spi_proc->p_pid
 5122     printf "   task:"
 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
 5126     printf "\n"
 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
 5131     else
 5132         printf "Cred: (null)\n"
 5133     end
 5134     # decode flags
 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"
 5139     end
 5140     if ($kgm_spi_flag & 0x00000002)
 5141         printf "    0x00000002 - has a controlling tty\n"
 5142     end
 5143     if ($kgm_spi_flag & 0x00000004)
 5144         printf "    0x00000004 - process is 64 bit\n"
 5145     else
 5146         printf "   !0x00000004 - process is 32 bit\n"
 5147     end
 5148     if ($kgm_spi_flag & 0x00000008)
 5149         printf "    0x00000008 - no SIGCHLD on child stop\n"
 5150     end
 5151     if ($kgm_spi_flag & 0x00000010)
 5152         printf "    0x00000010 - waiting for child exec/exit\n"
 5153     end
 5154     if ($kgm_spi_flag & 0x00000020)
 5155         printf "    0x00000020 - has started profiling\n"
 5156     end
 5157     if ($kgm_spi_flag & 0x00000040)
 5158         printf "    0x00000040 - in select; wakeup/waiting danger\n"
 5159     end
 5160     if ($kgm_spi_flag & 0x00000080)
 5161         printf "    0x00000080 - was stopped and continued\n"
 5162     end
 5163     if ($kgm_spi_flag & 0x00000100)
 5164         printf "    0x00000100 - has set privileges since exec\n"
 5165     end
 5166     if ($kgm_spi_flag & 0x00000200)
 5167         printf "    0x00000200 - system process: no signals, stats, or swap\n"
 5168     end
 5169     if ($kgm_spi_flag & 0x00000400)
 5170         printf "    0x00000400 - timing out during a sleep\n"
 5171     end
 5172     if ($kgm_spi_flag & 0x00000800)
 5173         printf "    0x00000800 - debugged process being traced\n"
 5174     end
 5175     if ($kgm_spi_flag & 0x00001000)
 5176         printf "    0x00001000 - debugging process has waited for child\n"
 5177     end
 5178     if ($kgm_spi_flag & 0x00002000)
 5179         printf "    0x00002000 - exit in progress\n"
 5180     end
 5181     if ($kgm_spi_flag & 0x00004000)
 5182         printf "    0x00004000 - process has called exec\n"
 5183     end
 5184     if ($kgm_spi_flag & 0x00008000)
 5185         printf "    0x00008000 - owe process an addupc() XXX\n"
 5186     end
 5187     if ($kgm_spi_flag & 0x00010000)
 5188         printf "    0x00010000 - affinity for Rosetta children\n"
 5189     end
 5190     if ($kgm_spi_flag & 0x00020000)
 5191         printf "    0x00020000 - wants to run Rosetta\n"
 5192     end
 5193     if ($kgm_spi_flag & 0x00040000)
 5194         printf "    0x00040000 - has wait() in progress\n"
 5195     end
 5196     if ($kgm_spi_flag & 0x00080000)
 5197         printf "    0x00080000 - kdebug tracing on for this process\n"
 5198     end
 5199     if ($kgm_spi_flag & 0x00100000)
 5200         printf "    0x00100000 - blocked due to SIGTTOU or SIGTTIN\n"
 5201     end
 5202     if ($kgm_spi_flag & 0x00200000)
 5203         printf "    0x00200000 - has called reboot()\n"
 5204     end
 5205     if ($kgm_spi_flag & 0x00400000)
 5206         printf "    0x00400000 - is TBE state\n"
 5207     end
 5208     if ($kgm_spi_flag & 0x00800000)
 5209         printf "    0x00800000 - signal exceptions\n"
 5210     end
 5211     if ($kgm_spi_flag & 0x01000000)
 5212         printf "    0x01000000 - has thread cwd\n"
 5213     end
 5214     if ($kgm_spi_flag & 0x02000000)
 5215         printf "    0x02000000 - has vfork() children\n"
 5216     end
 5217     if ($kgm_spi_flag & 0x04000000)
 5218         printf "    0x04000000 - not allowed to attach\n"
 5219     end
 5220     if ($kgm_spi_flag & 0x08000000)
 5221         printf "    0x08000000 - vfork() in progress\n"
 5222     end
 5223     if ($kgm_spi_flag & 0x10000000)
 5224         printf "    0x10000000 - no shared libraries\n"
 5225     end
 5226     if ($kgm_spi_flag & 0x20000000)
 5227         printf "    0x20000000 - force quota for root\n"
 5228     end
 5229     if ($kgm_spi_flag & 0x40000000)
 5230         printf "    0x40000000 - no zombies when children exit\n"
 5231     end
 5232     if ($kgm_spi_flag & 0x80000000)
 5233         printf "    0x80000000 - don't hang on remote FS ops\n"
 5234     end
 5235     # decode state
 5236     set $kgm_spi_state = $kgm_spi_proc->p_stat
 5237     printf "State: "
 5238     if ($kgm_spi_state == 1)
 5239         printf "Idle\n"
 5240     end
 5241     if ($kgm_spi_state == 2)
 5242         printf "Run\n"
 5243     end
 5244     if ($kgm_spi_state == 3)
 5245         printf "Sleep\n"
 5246     end
 5247     if ($kgm_spi_state == 4)
 5248         printf "Stop\n"
 5249     end
 5250     if ($kgm_spi_state == 5)
 5251         printf "Zombie\n"
 5252     end
 5253     if ($kgm_spi_state == 6)
 5254         printf "Reaping\n"
 5255     end
 5256     if ($kgm_spi_state < 1 || $kgm_spi_state > 6)
 5257         printf "(Unknown)\n"
 5258     end
 5259 end
 5260 
 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.
 5264 end
 5265 
 5266 #
 5267 # dump the zombprocs 
 5268 #
 5269 define zombproc
 5270   set $basep = (struct proc  *)zombproc->lh_first
 5271   set $pp = $basep
 5272   while $pp
 5273         showprocinfo $pp
 5274       set $pp = $pp->p_list.le_next
 5275   end
 5276 end
 5277 
 5278 document zombproc
 5279 Syntax: (gdb) zombproc 
 5280 | Routine to print out all procs in the zombie list
 5281 end
 5282 
 5283 #
 5284 # dump the zombstacks 
 5285 #
 5286 define zombstacks
 5287   set $basep = (struct proc  *)zombproc->lh_first
 5288   set $pp = $basep
 5289   while $pp
 5290         if $pp->p_stat != 5
 5291                 showtaskstacks $pp->task
 5292         end
 5293      set $pp = $pp->p_list.le_next
 5294   end
 5295 end
 5296 
 5297 document zombstacks
 5298 Syntax: (gdb) zombstacks 
 5299 | Routine to print out all stacks of tasks that are exiting
 5300 end
 5301 
 5302 
 5303 #
 5304 # dump the allprocs
 5305 #
 5306 define allproc
 5307   set $basep = (struct proc  *)allproc->lh_first
 5308   set $pp = $basep
 5309   while $pp
 5310         showprocinfo $pp
 5311       set $pp = $pp->p_list.le_next
 5312   end
 5313 end
 5314 
 5315 document allproc
 5316 Syntax: (gdb) allproc 
 5317 | Routine to print out all process in the system 
 5318 | which are not in the zombie list
 5319 end
 5320 define showprocsiblingint
 5321     set $kgm_sibling_ptr = (struct proc *)$arg0
 5322     set $kgm_lx = $arg1 
 5323     while $kgm_lx
 5324         printf "|  " 
 5325         set $kgm_lx = $kgm_lx-3 
 5326     end   
 5327     printf "|--%d    %s    [ 0x%llx ]\n", $kgm_sibling_ptr->p_pid, $kgm_sibling_ptr->p_comm, $kgm_sibling_ptr
 5328 end
 5329 define showproctreeint
 5330 #Initialize all the set variables used in this macro
 5331     set $kgm_basep1 = 0
 5332     set $kgm_sibling_ptr = 0
 5333     set $kgm_lx = 0
 5334     set $kgm_tmp_base = 0
 5335     set $kgm_head_ptr = 0
 5336     set $kgm_search_pid = 0 
 5337     set $kgm_rev = 0
 5338     set $kgm_x = 0
 5339 
 5340     set $kgm_basep1 = (struct proc *)allproc->lh_first
 5341     if ($arg0 == 0)
 5342         set $kgm_head_ptr = (struct proc *)initproc
 5343     end       
 5344     if ($arg0 > 0)
 5345         set $kgm_tmp_base = (struct proc *)allproc->lh_first
 5346         set $kgm_search_pid = $arg0 
 5347         while $kgm_tmp_base
 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
 5351                else
 5352                     set $kgm_head_ptr = 0
 5353                     printf "No children present for PID=%d", $kgm_search_pid
 5354                end
 5355                loop_break
 5356             end
 5357             set $kgm_tmp_base = $kgm_tmp_base->p_list.le_next
 5358         end
 5359     end
 5360     set $kgm_rev = 0
 5361     set $kgm_x = 0
 5362     if ($kgm_head_ptr)
 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
 5367     end
 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)
 5375                     loop_break
 5376                 end
 5377                 set $kgm_head_ptr = $kgm_head_ptr->p_pptr
 5378                 if ($kgm_head_ptr == $kgm_tmp_base)
 5379                     loop_break
 5380                 end
 5381                 if ($kgm_x > 3)
 5382                     set $kgm_x = $kgm_x - 3
 5383                 end
 5384                 set $kgm_rev = 1
 5385             end
 5386             if($kgm_head_ptr->p_sibling.le_next != 0)
 5387                 # Yes, it has sibling. So print sibling
 5388                 set $kgm_rev = 0
 5389                 showprocsiblingint $kgm_head_ptr->p_sibling.le_next $kgm_x
 5390                 set $kgm_head_ptr = $kgm_head_ptr->p_sibling.le_next
 5391             end
 5392         # childrencnt != 0  {=> it has children}
 5393         else
 5394             if ($kgm_rev == 1)
 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)
 5398                         loop_break
 5399                     end
 5400                     set $kgm_head_ptr = $kgm_head_ptr->p_pptr
 5401                     if ($kgm_head_ptr == $kgm_tmp_base)
 5402                         loop_break
 5403                     end
 5404 
 5405                     if ($kgm_x > 3)
 5406                         set $kgm_x = $kgm_x - 3
 5407                     end
 5408                     set $kgm_rev = 1
 5409                 end
 5410                 if($kgm_head_ptr->p_sibling.le_next != 0)
 5411                     set $kgm_rev = 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
 5415                 end
 5416             else
 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
 5420                 while $kgm_lx
 5421                     printf "|  "
 5422                     set $kgm_lx = $kgm_lx-3
 5423                 end
 5424                 printf "|--%d    %s      [ 0x%llx ] \n", $kgm_head_ptr->p_pid, $kgm_head_ptr->p_comm, $kgm_head_ptr
 5425             end
 5426         end
 5427     end
 5428     printf "\n"
 5429 #Unset all the set variables used in this macro
 5430     set $kgm_basep1 = 0
 5431     set $kgm_sibling_ptr = 0
 5432     set $kgm_lx = 0
 5433     set $kgm_tmp_base = 0
 5434     set $kgm_head_ptr = 0
 5435     set $kgm_search_pid = 0
 5436     set $kgm_rev = 0
 5437     set $kgm_x = 0
 5438 end
 5439 define showproctree
 5440     if ($argc > 0)
 5441         showproctreeint $arg0
 5442     else
 5443         showproctreeint 0
 5444     end
 5445 end
 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
 5451 end
 5452 
 5453 
 5454 define print_vnode
 5455    set $vp = (struct vnode *)$arg0
 5456    printf "   "
 5457    printf " vp "
 5458    showptr $vp
 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
 5465    printf " par "
 5466    showptr $vp->v_parent
 5467    set $_name = (char *)$vp->v_name
 5468    if ($_name != 0)
 5469       printf " %s", $_name
 5470    end
 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
 5473    end
 5474    printf "\n"
 5475 end
 5476 
 5477 document print_vnode
 5478 Syntax: (gdb) print_vnode <vnode>
 5479 | Prints out the fields of a vnode struct
 5480 end
 5481 
 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
 5487         if $cvp
 5488                 printf "Current Working Directory \n"
 5489                 print_vnode $cvp
 5490                 printf "\n"
 5491         end
 5492         if $rvp
 5493                 printf "Current Root Directory \n"
 5494                 print_vnode $rvp
 5495                 printf "\n"
 5496         end
 5497         set $count = 0
 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
 5502                 if *$fpp
 5503                         set $fg =(struct fileglob *)((**$fpp)->f_fglob)
 5504                         if  $fg && (($fg)->fg_type == 1) 
 5505                                 if $fdp->fd_ofileflags[$count] & 4
 5506                                         printf "U: "
 5507                                 else
 5508                                         printf " "
 5509                                 end
 5510                                 printf "fd = %d ", $count
 5511                                 print_vnode $fg->fg_data
 5512                         end
 5513                 end
 5514                 set $fpp = $fpp + 1
 5515                 set $count = $count + 1         
 5516         end
 5517 end
 5518 
 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
 5523 end
 5524 
 5525 define showallprocvnodes
 5526   set $basep = (struct proc  *)allproc->lh_first
 5527   set $pp = $basep
 5528   while $pp
 5529         printf "============================================ \n"
 5530         showprocinfo $pp
 5531         showprocvnodes $pp
 5532         set $pp = $pp->p_list.le_next
 5533   end
 5534 end
 5535 
 5536 document showallprocvnodes
 5537 Syntax: (gdb) showallprocvnodes
 5538 | Routine to print out all the open fds
 5539 | which are vnodes 
 5540 end
 5541 
 5542 
 5543 #   
 5544 # dump the childrent of a proc 
 5545 #
 5546 define showinitchild
 5547   set $basep = (struct proc  *)initproc->p_children.lh_first
 5548   set $pp = $basep
 5549   while $pp
 5550         showprocinfo $pp
 5551       set $pp = $pp->p_sibling.le_next
 5552   end
 5553 end
 5554 
 5555 document showinitchild
 5556 Syntax: (gdb) showinitchild 
 5557 | Routine to print out all processes in the system 
 5558 | which are children of init process
 5559 end
 5560 
 5561 
 5562 define showmountallvnodes
 5563   set $mp = (struct mount *)$arg0
 5564   set $basevp = (struct vnode *)$mp->mnt_vnodelist.tqh_first
 5565   set $vp = $basevp
 5566   printf "____________________ Vnode list Queue ---------------\n"
 5567   while $vp
 5568       print_vnode $vp
 5569       set $vp = $vp->v_mntvnodes->tqe_next
 5570   end
 5571   set $basevp = (struct vnode *)$mp->mnt_workerqueue.tqh_first
 5572   set $vp = $basevp
 5573   printf "____________________ Worker Queue ---------------\n"
 5574   while $vp
 5575       print_vnode $vp
 5576       set $vp = $vp->v_mntvnodes->tqe_next
 5577   end
 5578   set $basevp = (struct vnode *)$mp->mnt_newvnodes.tqh_first
 5579   set $vp = $basevp
 5580   printf "____________________ New vnodes  Queue ---------------\n"
 5581   while $vp
 5582       print_vnode $vp
 5583       set $vp = $vp->v_mntvnodes->tqe_next
 5584   end
 5585 end
 5586 document showmountallvnodes
 5587 Syntax: showmountallvnodes <struct mount *>
 5588 | Print the vnode inactive list
 5589 end
 5590 
 5591 
 5592 define showmountvnodes
 5593   set $mp = (struct mount *)$arg0
 5594   set $basevp = (struct vnode *)$mp->mnt_vnodelist.tqh_first
 5595   set $vp = $basevp
 5596   printf "____________________ Vnode list Queue ---------------\n"
 5597   while $vp
 5598       print_vnode $vp
 5599       set $vp = $vp->v_mntvnodes->tqe_next
 5600   end
 5601 end
 5602 document showmountvnodes
 5603 Syntax: showmountvnodes <struct mount *>
 5604 | Print the vnode list
 5605 end
 5606 
 5607 
 5608 
 5609 define showworkqvnodes
 5610   set $mp = (struct mount *)$arg0
 5611   set $basevp = (struct vnode *)$mp->mnt_workerqueue.tqh_first
 5612   set $vp = $basevp
 5613   printf "____________________ Worker Queue ---------------\n"
 5614   while $vp
 5615       print_vnode $vp
 5616       set $vp = $vp->v_mntvnodes->tqe_next
 5617   end
 5618 end
 5619 document showworkqvnodes
 5620 Syntax: showworkqvnodes <struct mount *>
 5621 | Print the vnode worker list
 5622 end
 5623 
 5624 
 5625 define shownewvnodes
 5626   set $mp = (struct mount *)$arg0
 5627   set $basevp = (struct vnode *)$mp->mnt_newvnodes.tqh_first
 5628   set $vp = $basevp
 5629   printf "____________________ New vnodes  Queue ---------------\n"
 5630   while $vp
 5631       print_vnode $vp
 5632       set $vp = $vp->v_mntvnodes->tqe_next
 5633   end
 5634 end
 5635 
 5636 document shownewvnodes
 5637 Syntax: shownewvnodes <struct mount *>
 5638 | Print the new vnode list
 5639 end
 5640 
 5641 
 5642 #
 5643 # print mount point info
 5644 define print_mount 
 5645    set $mp = (struct mount *)$arg0
 5646    printf "   "
 5647    printf " mp "
 5648    showptr $mp
 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
 5655    printf "\n"
 5656 end
 5657 
 5658 define showallmounts
 5659         set $mp=(struct mount *)mountlist.tqh_first
 5660         while $mp
 5661                 print_mount $mp
 5662                 set $mp = $mp->mnt_list.tqe_next
 5663         end
 5664 end
 5665         
 5666 document showallmounts
 5667 Syntax: showallmounts
 5668 | Print all mount points
 5669 end
 5670 
 5671 define pcprint
 5672         if (((unsigned long) $arg0 < (unsigned long) &_mh_execute_header || \
 5673              (unsigned long) $arg0 >= (unsigned long) &last_kernel_symbol ))
 5674                 showkmodaddr $arg0
 5675         else
 5676                 output /a $arg0
 5677         end
 5678 end
 5679 
 5680 define mbuf_walkpkt
 5681         set $mp = (struct mbuf *)$arg0
 5682         set $cnt = 1
 5683         set $tot = 0
 5684         while $mp
 5685                 printf "%4d: %p [len %4d, type %2d, ", $cnt, $mp, \
 5686                     $mp->m_hdr.mh_len, $mp->m_hdr.mh_type
 5687                 if mclaudit != 0
 5688                         mbuf_buf2mca $mp
 5689                         printf ", "
 5690                 end
 5691                 set $tot = $tot + $mp->m_hdr.mh_len
 5692                 printf "total %d]\n", $tot
 5693                 set $mp = $mp->m_hdr.mh_nextpkt
 5694                 set $cnt = $cnt + 1
 5695         end
 5696 end
 5697 
 5698 document mbuf_walkpkt
 5699 Syntax: (gdb) mbuf_walkpkt <addr>
 5700 | Given an mbuf address, walk its m_nextpkt pointer
 5701 end
 5702 
 5703 define mbuf_walk
 5704         set $mp = (struct mbuf *)$arg0
 5705         set $cnt = 1
 5706         set $tot = 0
 5707         while $mp
 5708                 printf "%4d: %p [len %4d, type %2d, ", $cnt, $mp, \
 5709                     $mp->m_hdr.mh_len, $mp->m_hdr.mh_type
 5710                 if mclaudit != 0
 5711                         mbuf_buf2mca $mp
 5712                         printf ", "
 5713                 end
 5714                 set $tot = $tot + $mp->m_hdr.mh_len
 5715                 printf "total %d]\n", $tot
 5716                 set $mp = $mp->m_hdr.mh_next
 5717                 set $cnt = $cnt + 1
 5718         end
 5719 end
 5720 
 5721 document mbuf_walk
 5722 Syntax: (gdb) mbuf_walk <addr>
 5723 | Given an mbuf address, walk its m_next pointer
 5724 end
 5725 
 5726 define mbuf_buf2slab
 5727         set $addr = $arg0
 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]
 5731         if $kgm_lp64
 5732                 printf "0x%-16llx", $slab
 5733         else
 5734                 printf "0x%-8x", $slab
 5735         end
 5736 end
 5737 
 5738 document mbuf_buf2slab
 5739 | Given an mbuf object, find its corresponding slab address.
 5740 end
 5741 
 5742 define mbuf_buf2mca
 5743         set $addr = $arg0
 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]
 5748         if $kgm_lp64
 5749                 printf "mca: 0x%-16llx", $mca
 5750         else
 5751                 printf "mca: 0x%-8x", $mca
 5752         end
 5753 end
 5754 
 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.
 5760 end
 5761 
 5762 define mbuf_showmca
 5763         set language c
 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
 5780                 end
 5781                 printf "saved contents:\t\t%p (%d bytes)\n", \
 5782                     $mca->mca_contents, $mca->mca_contents_size
 5783         else
 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
 5789                 end
 5790         end
 5791         printf "recent transaction for this buffer (thread %p):\n", \
 5792             $mca->mca_thread
 5793         set $cnt = 0
 5794         while $cnt < $mca->mca_depth
 5795                 set $kgm_pc = $mca->mca_stack[$cnt]
 5796                 printf "%4d: ", $cnt + 1
 5797                 pcprint $kgm_pc
 5798                 printf "\n"
 5799                 set $cnt = $cnt + 1
 5800         end
 5801         if $mca->mca_pdepth > 0
 5802                 printf "previous transaction for this buffer (thread %p):\n", \
 5803                     $mca->mca_pthread
 5804         end
 5805         set $cnt = 0
 5806         while $cnt < $mca->mca_pdepth
 5807                 set $kgm_pc = $mca->mca_pstack[$cnt]
 5808                 printf "%4d: ", $cnt + 1
 5809                 pcprint $kgm_pc
 5810                 printf "\n"
 5811                 set $cnt = $cnt + 1
 5812         end
 5813         set language auto
 5814 end
 5815 
 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.
 5820 end
 5821 
 5822 define mbuf_topleak
 5823         set language c
 5824         set $topcnt = 0
 5825         if $arg0 < 5
 5826                 set $maxcnt = $arg0
 5827         else
 5828                 set $maxcnt = 5
 5829         end
 5830         while $topcnt < $maxcnt
 5831                 mbuf_traceleak mleak_top_trace[$topcnt]
 5832                 set $topcnt = $topcnt + 1
 5833         end
 5834         set language auto
 5835 end
 5836 
 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
 5841 end
 5842 
 5843 define mbuf_traceleak
 5844         set language c
 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
 5850                         set $cnt = 0
 5851                         while $cnt < $trace->depth
 5852                                 printf "%4d: ", $cnt + 1
 5853                                 pcprint $trace->addr[$cnt]
 5854                                 printf "\n"
 5855                                 set $cnt = $cnt + 1
 5856                         end
 5857                 end
 5858         end
 5859         set language auto
 5860 end
 5861 
 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
 5866 end
 5867 
 5868 set $MCF_NOCPUCACHE = 0x10
 5869 
 5870 define mcache_stat
 5871         set $head = (mcache_t *)mcache_head
 5872         set $mc = $head
 5873 
 5874     if $kgm_lp64
 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"
 5878         else
 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"
 5882         end
 5883         while $mc != 0
 5884                 set $bktsize = $mc->mc_cpu.cc_bktsize
 5885                 printf "%-25s ", $mc->mc_name
 5886                 if ($mc->mc_flags & $MCF_NOCPUCACHE)
 5887                         printf "disabled"
 5888                 else
 5889                         if $mc->mc_purge_cnt > 0
 5890                                 printf " purging"
 5891                         else
 5892                                 if $bktsize == 0
 5893                                         printf " offline"
 5894                                 else
 5895                                         printf "  online"
 5896                                 end
 5897                         end
 5898                 end
 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
 5903                 else
 5904                     if $kgm_lp64
 5905                                 printf "            custom"
 5906                         else
 5907                                 printf "    custom"
 5908                         end
 5909                 end
 5910                 set $tot = 0
 5911                 set $tot += $mc->mc_full.bl_total * $bktsize
 5912                 set $ccp = (mcache_cpu_t *)$mc->mc_cpu
 5913                 set $n = 0
 5914                 while $n < ncpu
 5915                         if $ccp->cc_objs > 0
 5916                                 set $tot += $ccp->cc_objs
 5917                         end
 5918                         if $ccp->cc_pobjs > 0
 5919                                 set $tot += $ccp->cc_pobjs
 5920                         end
 5921                         set $n += 1
 5922                         set $ccp += 1
 5923                 end
 5924                 printf " %8d %8d %8d %8d", $mc->mc_wretry_cnt, \
 5925                     $mc->mc_nwretry_cnt, $mc->mc_nwfail_cnt, $tot
 5926                 printf "\n"
 5927                 set $mc = (mcache_t *)$mc->mc_list.le_next
 5928         end
 5929 end
 5930 
 5931 document mcache_stat
 5932 Syntax: (gdb) mcache_stat
 5933 | Print all mcaches in the system.
 5934 end
 5935 
 5936 define mcache_showzone
 5937         set $mc = (mcache_t *)$arg0
 5938         if $mc->mc_slab_zone != 0
 5939                 printf "%p", $mc->mc_slab_zone
 5940         else
 5941                 printf "   custom"
 5942 end
 5943 
 5944 document mcache_showzone
 5945 Syntax: (gdb) mcache_showzone <mcache_addr>
 5946 | Print the type of backend (custom or zone) of a mcache.
 5947 end
 5948 
 5949 define mcache_walkobj
 5950         set $p = (mcache_obj_t *)$arg0
 5951         set $cnt = 1
 5952         set $tot = 0
 5953         while $p
 5954                 printf "%4d: %p\n", $cnt, $p,
 5955                 set $p = $p->obj_next
 5956                 set $cnt = $cnt + 1
 5957         end
 5958 end
 5959 
 5960 document mcache_walkobj
 5961 Syntax: (gdb) mcache_walkobj <addr>
 5962 | Given a mcache object address, walk its obj_next pointer
 5963 end
 5964 
 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
 5969         set $cnt = 0
 5970         set $tot = 0
 5971         printf "Showing cache '%s':\n\n", $cp->mc_name
 5972         printf " CPU  cc_objs cc_pobjs    total\n"
 5973         printf "---- -------- -------- --------\n"
 5974         while $cnt < ncpu
 5975                 set $objs = $ccp->cc_objs
 5976                 if $objs <= 0
 5977                         set $objs = 0
 5978                 end
 5979                 set $pobjs = $ccp->cc_pobjs
 5980                 if $pobjs <= 0
 5981                         set $pobjs = 0
 5982                 end
 5983                 set $tot_cpu = $objs + $pobjs
 5984                 set $tot += $tot_cpu
 5985                 printf "%4d %8d %8d %8d\n", $cnt, $objs, $pobjs, $tot_cpu
 5986                 set $ccp += 1
 5987                 set $cnt += 1
 5988         end
 5989         printf "                       ========\n"
 5990         printf "                       %8d\n", $tot
 5991         printf "\n"
 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
 5996 end
 5997 
 5998 document mcache_showcache
 5999 | Display the number of objects in the cache
 6000 end
 6001 
 6002 set $NSLABSPMB = sizeof(mcl_slabg_t)/sizeof(mcl_slab_t)
 6003 
 6004 define mbuf_slabstbl
 6005         set $x = 0
 6006 
 6007         if $kgm_lp64
 6008                 printf "slot slabg              slabs range\n"
 6009                 printf "---- ------------------ -------------------------------------------\n"
 6010         else
 6011                 printf "slot slabg      slabs range\n"
 6012                 printf "---- ---------- ---------------------------\n"
 6013         end
 6014         while $x < maxslabgrp
 6015                 set $slg = slabstbl[$x]
 6016                 printf "%3d: ", $x
 6017                 if $slg == 0
 6018                         printf "-\n"
 6019                 else
 6020                         if $kgm_lp64
 6021                                 printf "0x%-16llx [ 0x%-16llx - 0x%-16llx ]\n", $slg, &$slg->slg_slab[0], \
 6022                                     &$slg->slg_slab[$NSLABSPMB-1]
 6023                         else
 6024                                 printf "0x%-8x [ 0x%-8x - 0x%-8x ]\n", $slg, &$slg->slg_slab[0], \
 6025                                     &$slg->slg_slab[$NSLABSPMB-1]
 6026                         end
 6027                 end
 6028                 set $x += 1
 6029         end
 6030 end
 6031 
 6032 document mbuf_slabstbl
 6033 | Display the mbuf slabs table
 6034 end
 6035 
 6036 set $SLF_MAPPED=0x0001
 6037 set $SLF_PARTIAL=0x0002
 6038 set $SLF_DETACHED=0x0004
 6039 
 6040 define mbuf_slabs
 6041         set $slg = (mcl_slabg_t *)$arg0
 6042         set $x = 0
 6043 
 6044         if $kgm_lp64
 6045                 printf "slot slab               next               obj                mca                 C  R  N   size flags\n"
 6046                 printf "---- ------------------ ------------------ ------------------ ------------------ -- -- -- ------ -----\n"
 6047         else
 6048                 printf "slot slab       next       obj        mca         C  R  N   size flags\n"
 6049                 printf "---- ---------- ---------- ---------- ---------- -- -- -- ------ -----\n"
 6050         end
 6051         while $x < $NSLABSPMB
 6052                 set $sl = &$slg->slg_slab[$x]
 6053                 set $mca = 0
 6054                 set $obj = $sl->sl_base
 6055 
 6056                 if mclaudit != 0
 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]
 6061                 end
 6062 
 6063                 if $kgm_lp64
 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, \
 6067                             $sl->sl_flags
 6068                 else
 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, \
 6072                             $sl->sl_flags
 6073                 end
 6074                 if $sl->sl_flags != 0
 6075                         printf "<"
 6076                         if $sl->sl_flags & $SLF_MAPPED
 6077                                 printf "mapped"
 6078                         end
 6079                         if $sl->sl_flags & $SLF_PARTIAL
 6080                                 printf ",partial"
 6081                         end
 6082                         if $sl->sl_flags & $SLF_DETACHED
 6083                                 printf ",detached"
 6084                         end
 6085                         printf ">"
 6086                 end
 6087                 printf "\n"
 6088 
 6089                 if $sl->sl_chunks > 1
 6090                         set $z = 1
 6091                         set $c = $sl->sl_len / $sl->sl_chunks
 6092 
 6093                         while $z < $sl->sl_chunks
 6094                                 set $obj = $sl->sl_base + ($c * $z)
 6095                                 set $mca = 0
 6096 
 6097                                 if mclaudit != 0
 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]
 6102                                 end
 6103 
 6104                                 if $kgm_lp64
 6105                                         printf "                                           0x%-16llx 0x%-16llx\n", $obj, $mca
 6106                                 else
 6107                                         printf "                           0x%-8x 0x%-8x\n", $obj, $mca
 6108                                 end
 6109                                 set $z += 1
 6110                         end
 6111                 end
 6112 
 6113                 set $x += 1
 6114         end
 6115 end
 6116 
 6117 document mbuf_slabs
 6118 | Display all mbuf slabs in the group
 6119 end
 6120 
 6121 define mbuf_stat
 6122         set $x = 0
 6123 
 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
 6130                 set $tot = 0
 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
 6135                 set $n = 0
 6136                 while $n < ncpu
 6137                         if $ccp->cc_objs > 0
 6138                                 set $tot += $ccp->cc_objs
 6139                         end
 6140                         if $ccp->cc_pobjs > 0
 6141                                 set $tot += $ccp->cc_pobjs
 6142                         end
 6143                         set $n += 1
 6144                         set $ccp += 1
 6145                 end
 6146 
 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
 6153                 printf "\n"
 6154                 set $x += 1
 6155         end
 6156 end
 6157 
 6158 document mbuf_stat
 6159 | Print extended mbuf allocator statistics.
 6160 end
 6161 
 6162 set $MB_INUSE = 0x1
 6163 set $MB_COMP_INUSE = 0x2
 6164 set $MB_SCVALID = 0x4
 6165 
 6166 set $MCLBYTES = 2048
 6167 set $MSIZE = 256
 6168 set $NBPG = 4096
 6169 set $M16KCLBYTES = 16384
 6170 
 6171 define mbuf_mca_ctype
 6172         set $mca = (mcache_audit_t *)$arg0
 6173         set $vopt = $arg1
 6174         set $cp = $mca->mca_cache
 6175         set $class = (unsigned int)$cp->mc_private
 6176         set $csize = mbuf_table[$class].mtbl_stats->mbcl_size
 6177         set $done = 0
 6178         if $csize == $MSIZE
 6179                 if $vopt
 6180                         printf "M (mbuf) "
 6181                 else
 6182                         printf "M     "
 6183                 end
 6184                 set $done = 1
 6185         end
 6186         if !$done && $csize == $MCLBYTES
 6187                 if $vopt
 6188                         printf "CL (2K cluster) "
 6189                 else
 6190                         printf "CL    "
 6191                 end
 6192                 set $done = 1
 6193         end
 6194         if !$done && $csize == $NBPG
 6195                 if $vopt
 6196                         printf "BCL (4K cluster) "
 6197                 else
 6198                         printf "BCL   "
 6199                 end
 6200                 set $done = 1
 6201         end
 6202         if !$done && $csize == $M16KCLBYTES
 6203                 if $vopt
 6204                         printf "JCL (16K cluster) "
 6205                 else
 6206                         printf "JCL   "
 6207                 end
 6208                 set $done = 1
 6209         end
 6210         if !$done && $csize == ($MSIZE+$MCLBYTES)
 6211                 if $mca->mca_uflags & $MB_SCVALID
 6212                         if $mca->mca_uptr
 6213                                 printf "M+CL  "
 6214                                 if $vopt
 6215                                         printf "(paired mbuf, 2K cluster)"
 6216                                 end
 6217                         else
 6218                                 printf "M-CL  "
 6219                                 if $vopt
 6220                                         printf "(unpaired mbuf, 2K cluster) "
 6221                                 end
 6222                         end
 6223                 else
 6224                         if $mca->mca_uptr
 6225                                 printf "CL+M  "
 6226                                 if $vopt
 6227                                         printf "(paired 2K cluster, mbuf) "
 6228                                 end
 6229                         else
 6230                                 printf "CL-M  "
 6231                                 if $vopt
 6232                                         printf "(paired 2K cluster, mbuf) "
 6233                                 end
 6234                         end
 6235                 end
 6236                 set $done = 1
 6237         end
 6238         if !$done && $csize == ($MSIZE+$NBPG)
 6239                 if $mca->mca_uflags & $MB_SCVALID
 6240                         if $mca->mca_uptr
 6241                                 printf "M+BCL "
 6242                                 if $vopt
 6243                                         printf "(paired mbuf, 4K cluster) "
 6244                                 end
 6245                         else
 6246                                 printf "M-BCL "
 6247                                 if $vopt
 6248                                         printf "(unpaired mbuf, 4K cluster) "
 6249                                 end
 6250                         end
 6251                 else
 6252                         if $mca->mca_uptr
 6253                                 printf "BCL+M "
 6254                                 if $vopt
 6255                                         printf "(paired 4K cluster, mbuf) "
 6256                                 end
 6257                         else
 6258                                 printf "BCL-M "
 6259                                 if $vopt
 6260                                         printf "(unpaired 4K cluster, mbuf) "
 6261                                 end
 6262                         end
 6263                 end
 6264                 set $done = 1
 6265         end
 6266         if !$done && $csize == ($MSIZE+$M16KCLBYTES)
 6267                 if $mca->mca_uflags & $MB_SCVALID
 6268                         if $mca->mca_uptr
 6269                                 printf "M+JCL "
 6270                                 if $vopt
 6271                                         printf "(paired mbuf, 16K cluster) "
 6272                                 end
 6273                         else
 6274                                 printf "M-JCL "
 6275                                 if $vopt
 6276                                         printf "(unpaired mbuf, 16K cluster) "
 6277                                 end
 6278                         end
 6279                 else
 6280                         if $mca->mca_uptr
 6281                                 printf "JCL+M "
 6282                                 if $vopt
 6283                                         printf "(paired 16K cluster, mbuf) "
 6284                                 end
 6285                         else
 6286                                 printf "JCL-M "
 6287                                 if $vopt
 6288                                         printf "(unpaired 16K cluster, mbuf) "
 6289                                 end
 6290                         end
 6291                 end
 6292                 set $done = 1
 6293         end
 6294         if !$done
 6295                 printf "unknown: %s ", $cp->mc_name
 6296         end
 6297 end
 6298 
 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.
 6302 end
 6303 
 6304 define mbuf_showactive
 6305         if $argc == 0
 6306                 mbuf_walkallslabs 1 0
 6307         else
 6308                 mbuf_walkallslabs 1 0 $arg0
 6309         end
 6310 end
 6311 
 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).
 6319 end
 6320 
 6321 define mbuf_showinactive
 6322         mbuf_walkallslabs 0 1
 6323 end
 6324 
 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.
 6333 end
 6334 
 6335 define mbuf_showall
 6336         mbuf_walkallslabs 1 1
 6337 end
 6338 
 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.
 6344 end
 6345 
 6346 define mbuf_mcaobjs
 6347 end
 6348 
 6349 define mbuf_walkallslabs
 6350         set $show_a = $arg0
 6351         set $show_f = $arg1
 6352         if $argc == 3
 6353                 set $show_tr = $arg2
 6354         else
 6355                 set $show_tr = 0
 6356         end
 6357         set $x = 0
 6358         set $total = 0
 6359         set $total_a = 0
 6360         set $total_f = 0
 6361 
 6362         printf "("
 6363         if $show_a && !$show_f
 6364                 printf "Searching only for active "
 6365         end
 6366         if !$show_a && $show_f
 6367                 printf "Searching only for inactive "
 6368         end
 6369         if $show_a && $show_f
 6370                 printf "Displaying all "
 6371         end
 6372         printf "objects; this may take a while ...)\n\n"
 6373 
 6374         if $kgm_lp64
 6375                 printf "                        slab                mca                obj        allocation\n"
 6376                 printf "slot idx             address            address            address type        state\n"
 6377                 printf "---- ---- ------------------ ------------------ ------------------ ----- -----------\n"
 6378         else
 6379                 printf "                slab        mca        obj        allocation\n"
 6380                 printf "slot idx     address    address    address type        state\n"
 6381                 printf "---- ---- ---------- ---------- ---------- ----- -----------\n"
 6382         end
 6383         
 6384         while $x < slabgrp
 6385                 set $slg = slabstbl[$x]
 6386                 set $y = 0
 6387                 set $stop = 0
 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]
 6395                         set $first = 1
 6396 
 6397                         while $mca != 0 && $mca->mca_addr != 0
 6398                                 set $printmca = 0
 6399                                 if $mca->mca_uflags & ($MB_INUSE|$MB_COMP_INUSE)
 6400                                         set $total_a = $total_a + 1
 6401                                         set $printmca = $show_a
 6402                                 else
 6403                                         set $total_f = $total_f + 1
 6404                                         set $printmca = $show_f
 6405                                 end
 6406 
 6407                                 if $printmca != 0
 6408                                         if $first == 1
 6409                                                 if $kgm_lp64
 6410                                                         printf "%4d %4d 0x%-16llx ", $x, $y, $sl
 6411                                                 else
 6412                                                         printf "%4d %4d 0x%-8x ", $x, $y, $sl
 6413                                                 end
 6414                                         else
 6415                                             if $kgm_lp64
 6416                                                         printf "                             "
 6417                                             else
 6418                                                         printf "                     "
 6419                                             end
 6420                                         end
 6421 
 6422                                         if $kgm_lp64
 6423                                                 printf "0x%-16llx 0x%-16llx ", $mca, $mca->mca_addr
 6424                                         else
 6425                                                 printf "0x%-8x 0x%-8x ", $mca, $mca->mca_addr
 6426                                         end
 6427 
 6428                                         mbuf_mca_ctype $mca 0
 6429                                         if $mca->mca_uflags & ($MB_INUSE|$MB_COMP_INUSE)
 6430                                                 printf "active      "
 6431                                         else
 6432                                                 printf "      freed "
 6433                                         end
 6434                                         if $first == 1
 6435                                                 set $first = 0
 6436                                         end
 6437                                         printf "\n"
 6438                                         set $total = $total + 1
 6439                                         
 6440                                         if $show_tr != 0
 6441                                                 printf "recent transaction for this buffer (thread %p):\n", \
 6442                                                         $mca->mca_thread
 6443                                                 set $cnt = 0
 6444                                                 while $cnt < $mca->mca_depth
 6445                                                         set $kgm_pc = $mca->mca_stack[$cnt]
 6446                                                         printf "%4d: ", $cnt + 1
 6447                                                         pcprint $kgm_pc
 6448                                                         printf "\n"
 6449                                                         set $cnt = $cnt + 1
 6450                                                 end
 6451                                         end
 6452                                 end
 6453                                 
 6454                                 set $mca = $mca->mca_next
 6455                         end
 6456                         set $y += 1
 6457                         if $slg->slg_slab[$y].sl_base == 0
 6458                                 set $stop = 1
 6459                         end
 6460                 end
 6461                 set $x += 1
 6462         end
 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
 6467         end
 6468 end
 6469 
 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}.
 6474 end
 6475 
 6476 define mbuf_countchain
 6477         set $mp = (struct mbuf *)$arg0
 6478         
 6479         set $pkt = 0
 6480         set $nxt = 0
 6481 
 6482         while $mp != 0
 6483                 set $pkt = $pkt + 1
 6484         
 6485                 set $mn = (struct mbuf *)$mp->m_hdr.mh_next
 6486                 while $mn != 0
 6487                         set $nxt = $nxt + 1
 6488                         
 6489                         set $mn = (struct mbuf *)$mn->m_hdr.mh_next
 6490                 end
 6491                 
 6492                 set $mp = $mp->m_hdr.mh_nextpkt
 6493 
 6494                 if (($pkt + $nxt) % 50) == 0
 6495                         printf "... %d\n", $pkt + $nxt
 6496                 end
 6497         end
 6498 
 6499         printf "\ntotal: %d (via m_next: %d)\n", $pkt + $nxt, $nxt
 6500 end
 6501 
 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.
 6506 end
 6507 
 6508 set $RTF_UP          = 0x1
 6509 set $RTF_GATEWAY     = 0x2
 6510 set $RTF_HOST        = 0x4
 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
 6535 
 6536 set $AF_INET = 2
 6537 set $AF_INET6 = 30
 6538 set $AF_LINK = 18
 6539 
 6540 define rtentry_prdetails
 6541         set $rt = (struct rtentry *)$arg0
 6542         set $is_v6 = 0
 6543 
 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
 6547                 printf " "
 6548         else
 6549                 if $dst->sa_family == $AF_INET6
 6550                         showsockaddr_in6 $dst
 6551                         printf " "
 6552                         set $is_v6 = 1
 6553                 else
 6554                         if $dst->sa_family == $AF_LINK
 6555                                 showsockaddr_dl $dst
 6556                                 printf " "
 6557                         else
 6558                                 showsockaddr_unspec $dst
 6559                         end
 6560                 end
 6561         end
 6562 
 6563         set $dst = (struct sockaddr *)$rt->rt_gateway
 6564         if $dst->sa_family == $AF_INET
 6565                 showsockaddr_in $dst
 6566                 printf "   "
 6567         else
 6568                 if $dst->sa_family == $AF_INET6
 6569                         set $is_v6 = 1
 6570                         showsockaddr_in6 $dst
 6571                         printf " "
 6572                 else
 6573                         if $dst->sa_family == $AF_LINK
 6574                                 showsockaddr_dl $dst
 6575                                 if $is_v6
 6576                                         printf "                       "
 6577                                 else
 6578                                         printf " "
 6579                                 end
 6580                         else
 6581                                 showsockaddr_unspec $dst
 6582                         end
 6583                 end
 6584         end
 6585 
 6586         if $rt->rt_flags & $RTF_WASCLONED
 6587                 if $kgm_lp64
 6588                         printf "%18p ", $rt->rt_parent
 6589                 else
 6590                         printf "%10p ", $rt->rt_parent
 6591                 end
 6592         else
 6593                 if $kgm_lp64
 6594                         printf "                   "
 6595                 else
 6596                         printf "           "
 6597                 end
 6598         end
 6599 
 6600         printf "%6u %8u ", $rt->rt_refcnt, $rt->rt_rmx.rmx_pksent
 6601 
 6602         if $rt->rt_flags & $RTF_UP
 6603                 printf "U"
 6604         end
 6605         if $rt->rt_flags & $RTF_GATEWAY
 6606                 printf "G"
 6607         end
 6608         if $rt->rt_flags & $RTF_HOST
 6609                 printf "H"
 6610         end
 6611         if $rt->rt_flags & $RTF_REJECT
 6612                 printf "R"
 6613         end
 6614         if $rt->rt_flags & $RTF_DYNAMIC
 6615                 printf "D"
 6616         end
 6617         if $rt->rt_flags & $RTF_MODIFIED
 6618                 printf "M"
 6619         end
 6620         if $rt->rt_flags & $RTF_CLONING
 6621                 printf "C"
 6622         end
 6623         if $rt->rt_flags & $RTF_PRCLONING
 6624                 printf "c"
 6625         end
 6626         if $rt->rt_flags & $RTF_LLINFO
 6627                 printf "L"
 6628         end
 6629         if $rt->rt_flags & $RTF_STATIC
 6630                 printf "S"
 6631         end
 6632         if $rt->rt_flags & $RTF_PROTO1
 6633                 printf "1"
 6634         end
 6635         if $rt->rt_flags & $RTF_PROTO2
 6636                 printf "2"
 6637         end
 6638         if $rt->rt_flags & $RTF_PROTO3
 6639                 printf "3"
 6640         end
 6641         if $rt->rt_flags & $RTF_WASCLONED
 6642                 printf "W"
 6643         end
 6644         if $rt->rt_flags & $RTF_BROADCAST
 6645                 printf "b"
 6646         end
 6647         if $rt->rt_flags & $RTF_MULTICAST
 6648                 printf "m"
 6649         end
 6650         if $rt->rt_flags & $RTF_XRESOLVE
 6651                 printf "X"
 6652         end
 6653         if $rt->rt_flags & $RTF_BLACKHOLE
 6654                 printf "B"
 6655         end
 6656         if $rt->rt_flags & $RTF_IFSCOPE
 6657                 printf "I"
 6658         end
 6659         if $rt->rt_flags & $RTF_CONDEMNED
 6660                 printf "Z"
 6661         end
 6662         if $rt->rt_flags & $RTF_IFREF
 6663                 printf "i"
 6664         end
 6665         if $rt->rt_flags & $RTF_PROXY
 6666                 printf "Y"
 6667         end
 6668         if $rt->rt_flags & $RTF_ROUTER
 6669                 printf "r"
 6670         end
 6671 
 6672         printf "/%s%d", $rt->rt_ifp->if_name, $rt->rt_ifp->if_unit
 6673 end
 6674 
 6675 set $RNF_ROOT   = 2
 6676 
 6677 define _rttable_dump
 6678         set $rnh = $arg0
 6679         set $rn = (struct radix_node *)$rnh->rnh_treetop
 6680         set $rnh_cnt = $rnh->rnh_cnt
 6681                 
 6682         while $rn->rn_bit >= 0
 6683                 set $rn = $rn->rn_u.rn_node.rn_L
 6684         end
 6685         
 6686         while 1
 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
 6690                 end
 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
 6694                 end
 6695                 set $next = $rn
 6696                 while $base != 0
 6697                         set $rn = $base
 6698                         set $base = $rn->rn_u.rn_leaf.rn_Dupedkey
 6699                         if ($rn->rn_flags & $RNF_ROOT) == 0
 6700                                 
 6701                                 set $rt = (struct rtentry *)$rn
 6702                                 
 6703                                 if $kgm_lp64
 6704                                         printf "%18p ", $rt
 6705                                 else
 6706                                         printf "%10p ", $rt
 6707                                 end
 6708                                 rtentry_prdetails $rt
 6709                                 printf "\n"
 6710                                 
 6711                         end
 6712                 end
 6713                 set $rn = $next
 6714                 if ($rn->rn_flags & $RNF_ROOT) != 0
 6715                         loop_break
 6716                 end
 6717         end
 6718 end
 6719 
 6720 
 6721 define show_rt_inet
 6722         if $kgm_lp64
 6723                 printf " rtentry           dst             gw                parent             Refs   Use      flags/if\n"
 6724                 printf " ----------------- --------------- ----------------- ------------------ ------ -------- -----------\n"
 6725         else
 6726                 printf " rtentry   dst             gw                parent     Refs   Use      flags/if\n"
 6727                 printf " --------- --------------- ----------------- ---------- ------ -------- -----------\n"
 6728         end
 6729         _rttable_dump rt_tables[2]
 6730 end
 6731 
 6732 document show_rt_inet
 6733 Syntax: (gdb) show_rt_inet
 6734 | Show the entries of the IPv4 routing table.
 6735 end
 6736 
 6737 define show_rt_inet6
 6738         if $kgm_lp64
 6739                 printf " rtentry           dst                                     gw                                      parent             Refs   Use      flags/if\n"
 6740                 printf " ----------------- --------------------------------------- --------------------------------------- ------------------ ------ -------- -----------\n"
 6741         else
 6742                 printf " rtentry   dst                                     gw                                      parent     Refs   Use      flags/if\n"
 6743                 printf " --------- --------------------------------------- --------------------------------------- ---------- ------ -------- -----------\n"
 6744         end
 6745         _rttable_dump rt_tables[30]
 6746 end
 6747 
 6748 document show_rt_inet6
 6749 Syntax: (gdb) show_rt_inet6
 6750 | Show the entries of the IPv6 routing table.
 6751 end
 6752 
 6753 define rtentry_trash
 6754         set $rtd = (struct rtentry_dbg *)rttrash_head.tqh_first
 6755         set $cnt = 0
 6756         while $rtd != 0
 6757                 if $cnt == 0
 6758                     if $kgm_lp64
 6759                                 printf "                rtentry ref   hold   rele             dst    gw             parent flags/if\n"
 6760                                 printf "      ----------------- --- ------ ------ --------------- ----- ------------------ -----------\n"
 6761                         else
 6762                                 printf "        rtentry ref   hold   rele             dst    gw     parent flags/if\n"
 6763                                 printf "      --------- --- ------ ------ --------------- ----- ---------- -----------\n"
 6764                         end
 6765                 end
 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
 6770                 printf "\n"
 6771                 set $rtd = $rtd->rtd_trash_link.tqe_next
 6772                 set $cnt = $cnt + 1
 6773         end
 6774 end
 6775 
 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.
 6781 end
 6782 
 6783 set $CTRACE_STACK_SIZE = ctrace_stack_size
 6784 set $CTRACE_HIST_SIZE = ctrace_hist_size
 6785 
 6786 define rtentry_showdbg
 6787         set $rtd = (struct rtentry_dbg *)$arg0
 6788         set $cnt = 0
 6789 
 6790         printf "Total holds:\t%d\n", $rtd->rtd_refhold_cnt
 6791         printf "Total releases:\t%d\n", $rtd->rtd_refrele_cnt
 6792 
 6793         set $ix = 0
 6794         while $ix < $CTRACE_STACK_SIZE
 6795                 set $kgm_pc = $rtd->rtd_alloc.pc[$ix]
 6796                 if $kgm_pc != 0
 6797                         if $ix == 0
 6798                                 printf "\nAlloc (thread %p):\n", \
 6799                                     $rtd->rtd_alloc.th
 6800                         end
 6801                         printf "%4d: ", $ix + 1
 6802                         pcprint $kgm_pc
 6803                         printf "\n"
 6804                 end
 6805                 set $ix = $ix + 1
 6806         end
 6807         set $ix = 0
 6808         while $ix < $CTRACE_STACK_SIZE
 6809                 set $kgm_pc = $rtd->rtd_free.pc[$ix]
 6810                 if $kgm_pc != 0
 6811                         if $ix == 0
 6812                                 printf "\nFree: (thread %p)\n", \
 6813                                     $rtd->rtd_free.th
 6814                         end
 6815                         printf "%4d: ", $ix + 1
 6816                         pcprint $kgm_pc
 6817                         printf "\n"
 6818                 end
 6819                 set $ix = $ix + 1
 6820         end
 6821         while $cnt < $CTRACE_HIST_SIZE
 6822                 set $ix = 0
 6823                 while $ix < $CTRACE_STACK_SIZE
 6824                         set $kgm_pc = $rtd->rtd_refhold[$cnt].pc[$ix]
 6825                         if $kgm_pc != 0
 6826                                 if $ix == 0
 6827                                         printf "\nHold [%d] (thread %p):\n", \
 6828                                             $cnt, $rtd->rtd_refhold[$cnt].th
 6829                                 end
 6830                                 printf "%4d: ", $ix + 1
 6831                                 pcprint $kgm_pc
 6832                                 printf "\n"
 6833                         end
 6834                         set $ix = $ix + 1
 6835                 end
 6836                 set $cnt = $cnt + 1
 6837         end
 6838         set $cnt = 0
 6839         while $cnt < $CTRACE_HIST_SIZE
 6840                 set $ix = 0
 6841                 while $ix < $CTRACE_STACK_SIZE
 6842                         set $kgm_pc = $rtd->rtd_refrele[$cnt].pc[$ix]
 6843                         if $kgm_pc != 0
 6844                                 if $ix == 0
 6845                                         printf "\nRelease [%d] (thread %p):\n",\
 6846                                             $cnt, $rtd->rtd_refrele[$cnt].th
 6847                                 end
 6848                                 printf "%4d: ", $ix + 1
 6849                                 pcprint $kgm_pc
 6850                                 printf "\n"
 6851                         end
 6852                         set $ix = $ix + 1
 6853                 end
 6854                 set $cnt = $cnt + 1
 6855         end
 6856 
 6857         printf "\nTotal locks:\t%d\n", $rtd->rtd_lock_cnt
 6858         printf "Total unlocks:\t%d\n", $rtd->rtd_unlock_cnt
 6859 
 6860         set $cnt = 0
 6861         while $cnt < $CTRACE_HIST_SIZE
 6862                 set $ix = 0
 6863                 while $ix < $CTRACE_STACK_SIZE
 6864                         set $kgm_pc = $rtd->rtd_lock[$cnt].pc[$ix]
 6865                         if $kgm_pc != 0
 6866                                 if $ix == 0
 6867                                         printf "\nLock [%d] (thread %p):\n",\
 6868                                             $cnt, $rtd->rtd_lock[$cnt].th
 6869                                 end
 6870                                 printf "%4d: ", $ix + 1
 6871                                 pcprint $kgm_pc
 6872                                 printf "\n"
 6873                         end
 6874                         set $ix = $ix + 1
 6875                 end
 6876                 set $cnt = $cnt + 1
 6877         end
 6878         set $cnt = 0
 6879         while $cnt < $CTRACE_HIST_SIZE
 6880                 set $ix = 0
 6881                 while $ix < $CTRACE_STACK_SIZE
 6882                         set $kgm_pc = $rtd->rtd_unlock[$cnt].pc[$ix]
 6883                         if $kgm_pc != 0
 6884                                 if $ix == 0
 6885                                         printf "\nUnlock [%d] (thread %p):\n",\
 6886                                             $cnt, $rtd->rtd_unlock[$cnt].th
 6887                                 end
 6888                                 printf "%4d: ", $ix + 1
 6889                                 pcprint $kgm_pc
 6890                                 printf "\n"
 6891                         end
 6892                         set $ix = $ix + 1
 6893                 end
 6894                 set $cnt = $cnt + 1
 6895         end
 6896 end
 6897 
 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
 6903 | parameter.
 6904 end
 6905 
 6906 set $INIFA_TRACE_HIST_SIZE = inifa_trace_hist_size
 6907 
 6908 define inifa_showdbg
 6909         set $inifa = (struct in_ifaddr_dbg *)$arg0
 6910         set $cnt = 0
 6911 
 6912         printf "Total holds:\t%d\n", $inifa->inifa_refhold_cnt
 6913         printf "Total releases:\t%d\n", $inifa->inifa_refrele_cnt
 6914 
 6915         set $ix = 0
 6916         while $ix < $CTRACE_STACK_SIZE
 6917                 set $kgm_pc = $inifa->inifa_alloc.pc[$ix]
 6918                 if $kgm_pc != 0
 6919                         if $ix == 0
 6920                                 printf "\nAlloc (thread %p):\n", \
 6921                                     $inifa->inifa_alloc.th
 6922                         end
 6923                         printf "%4d: ", $ix + 1
 6924                         pcprint $kgm_pc
 6925                         printf "\n"
 6926                 end
 6927                 set $ix = $ix + 1
 6928         end
 6929         set $ix = 0
 6930         while $ix < $CTRACE_STACK_SIZE
 6931                 set $kgm_pc = $inifa->inifa_free.pc[$ix]
 6932                 if $kgm_pc != 0
 6933                         if $ix == 0
 6934                                 printf "\nFree: (thread %p)\n", \
 6935                                     $inifa->inifa_free.th
 6936                         end
 6937                         printf "%4d: ", $ix + 1
 6938                         pcprint $kgm_pc
 6939                         printf "\n"
 6940                 end
 6941                 set $ix = $ix + 1
 6942         end
 6943         while $cnt < $INIFA_TRACE_HIST_SIZE
 6944                 set $ix = 0
 6945                 while $ix < $CTRACE_STACK_SIZE
 6946                         set $kgm_pc = $inifa->inifa_refhold[$cnt].pc[$ix]
 6947                         if $kgm_pc != 0
 6948                                 if $ix == 0
 6949                                         printf "\nHold [%d] (thread %p):\n", \
 6950                                             $cnt, $inifa->inifa_refhold[$cnt].th
 6951                                 end
 6952                                 printf "%4d: ", $ix + 1
 6953                                 pcprint $kgm_pc
 6954                                 printf "\n"
 6955                         end
 6956                         set $ix = $ix + 1
 6957                 end
 6958                 set $cnt = $cnt + 1
 6959         end
 6960         set $cnt = 0
 6961         while $cnt < $INIFA_TRACE_HIST_SIZE
 6962                 set $ix = 0
 6963                 while $ix < $CTRACE_STACK_SIZE
 6964                         set $kgm_pc = $inifa->inifa_refrele[$cnt].pc[$ix]
 6965                         if $kgm_pc != 0
 6966                                 if $ix == 0
 6967                                         printf "\nRelease [%d] (thread %p):\n",\
 6968                                             $cnt, $inifa->inifa_refrele[$cnt].th
 6969                                 end
 6970                                 printf "%4d: ", $ix + 1
 6971                                 pcprint $kgm_pc
 6972                                 printf "\n"
 6973                         end
 6974                         set $ix = $ix + 1
 6975                 end
 6976                 set $cnt = $cnt + 1
 6977         end
 6978 end
 6979 
 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
 6985 | parameter.
 6986 end
 6987 
 6988 set $IN6IFA_TRACE_HIST_SIZE = in6ifa_trace_hist_size
 6989 
 6990 define in6ifa_showdbg
 6991         set $in6ifa = (struct in6_ifaddr_dbg *)$arg0
 6992         set $cnt = 0
 6993 
 6994         printf "Total holds:\t%d\n", $in6ifa->in6ifa_refhold_cnt
 6995         printf "Total releases:\t%d\n", $in6ifa->in6ifa_refrele_cnt
 6996 
 6997         set $ix = 0
 6998         while $ix < $CTRACE_STACK_SIZE
 6999                 set $kgm_pc = $in6ifa->in6ifa_alloc.pc[$ix]
 7000                 if $kgm_pc != 0
 7001                         if $ix == 0
 7002                                 printf "\nAlloc (thread %p):\n", \
 7003                                     $in6ifa->in6ifa_alloc.th
 7004                         end
 7005                         printf "%4d: ", $ix + 1
 7006                         pcprint $kgm_pc
 7007                         printf "\n"
 7008                 end
 7009                 set $ix = $ix + 1
 7010         end
 7011         set $ix = 0
 7012         while $ix < $CTRACE_STACK_SIZE
 7013                 set $kgm_pc = $in6ifa->in6ifa_free.pc[$ix]
 7014                 if $kgm_pc != 0
 7015                         if $ix == 0
 7016                                 printf "\nFree: (thread %p)\n", \
 7017                                     $in6ifa->in6ifa_free.th
 7018                         end
 7019                         printf "%4d: ", $ix + 1
 7020                         pcprint $kgm_pc
 7021                         printf "\n"
 7022                 end
 7023                 set $ix = $ix + 1
 7024         end
 7025         while $cnt < $IN6IFA_TRACE_HIST_SIZE
 7026                 set $ix = 0
 7027                 while $ix < $CTRACE_STACK_SIZE
 7028                         set $kgm_pc = $in6ifa->in6ifa_refhold[$cnt].pc[$ix]
 7029                         if $kgm_pc != 0
 7030                                 if $ix == 0
 7031                                         printf "\nHold [%d] (thread %p):\n", \
 7032                                           $cnt, $in6ifa->in6ifa_refhold[$cnt].th
 7033                                 end
 7034                                 printf "%4d: ", $ix + 1
 7035                                 pcprint $kgm_pc
 7036                                 printf "\n"
 7037                         end
 7038                         set $ix = $ix + 1
 7039                 end
 7040                 set $cnt = $cnt + 1
 7041         end
 7042         set $cnt = 0
 7043         while $cnt < $IN6IFA_TRACE_HIST_SIZE
 7044                 set $ix = 0
 7045                 while $ix < $CTRACE_STACK_SIZE
 7046                         set $kgm_pc = $in6ifa->in6ifa_refrele[$cnt].pc[$ix]
 7047                         if $kgm_pc != 0
 7048                                 if $ix == 0
 7049                                         printf "\nRelease [%d] (thread %p):\n",\
 7050                                           $cnt, $in6ifa->in6ifa_refrele[$cnt].th
 7051                                 end
 7052                                 printf "%4d: ", $ix + 1
 7053                                 pcprint $kgm_pc
 7054                                 printf "\n"
 7055                         end
 7056                         set $ix = $ix + 1
 7057                 end
 7058                 set $cnt = $cnt + 1
 7059         end
 7060 end
 7061 
 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
 7067 | parameter.
 7068 end
 7069 
 7070 set $IFMA_TRACE_HIST_SIZE = ifma_trace_hist_size
 7071 
 7072 define ifma_showdbg
 7073         set $ifma = (struct ifmultiaddr_dbg *)$arg0
 7074         set $cnt = 0
 7075 
 7076         printf "Total holds:\t%d\n", $ifma->ifma_refhold_cnt
 7077         printf "Total releases:\t%d\n", $ifma->ifma_refrele_cnt
 7078 
 7079         while $cnt < $IFMA_TRACE_HIST_SIZE
 7080                 set $ix = 0
 7081                 while $ix < $CTRACE_STACK_SIZE
 7082                         set $kgm_pc = $ifma->ifma_refhold[$cnt].pc[$ix]
 7083                         if $kgm_pc != 0
 7084                                 if $ix == 0
 7085                                         printf "\nHold [%d] (thread %p):\n", \
 7086                                           $cnt, $ifma->ifma_refhold[$cnt].th
 7087                                 end
 7088                                 printf "%4d: ", $ix + 1
 7089                                 pcprint $kgm_pc
 7090                                 printf "\n"
 7091                         end
 7092                         set $ix = $ix + 1
 7093                 end
 7094                 set $cnt = $cnt + 1
 7095         end
 7096         set $cnt = 0
 7097         while $cnt < $IFMA_TRACE_HIST_SIZE
 7098                 set $ix = 0
 7099                 while $ix < $CTRACE_STACK_SIZE
 7100                         set $kgm_pc = $ifma->ifma_refrele[$cnt].pc[$ix]
 7101                         if $kgm_pc != 0
 7102                                 if $ix == 0
 7103                                         printf "\nRelease [%d] (thread %p):\n",\
 7104                                           $cnt, $ifma->ifma_refrele[$cnt].th
 7105                                 end
 7106                                 printf "%4d: ", $ix + 1
 7107                                 pcprint $kgm_pc
 7108                                 printf "\n"
 7109                         end
 7110                         set $ix = $ix + 1
 7111                 end
 7112                 set $cnt = $cnt + 1
 7113         end
 7114 end
 7115 
 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
 7121 | parameter.
 7122 end
 7123 
 7124 set $INM_TRACE_HIST_SIZE = inm_trace_hist_size
 7125 
 7126 define inm_showdbg
 7127         set $inm = (struct in_multi_dbg *)$arg0
 7128         set $cnt = 0
 7129 
 7130         printf "Total holds:\t%d\n", $inm->inm_refhold_cnt
 7131         printf "Total releases:\t%d\n", $inm->inm_refrele_cnt
 7132 
 7133         while $cnt < $INM_TRACE_HIST_SIZE
 7134                 set $ix = 0
 7135                 while $ix < $CTRACE_STACK_SIZE
 7136                         set $kgm_pc = $inm->inm_refhold[$cnt].pc[$ix]
 7137                         if $kgm_pc != 0
 7138                                 if $ix == 0
 7139                                         printf "\nHold [%d] (thread %p):\n", \
 7140                                           $cnt, $inm->inm_refhold[$cnt].th
 7141                                 end
 7142                                 printf "%4d: ", $ix + 1
 7143                                 pcprint $kgm_pc
 7144                                 printf "\n"
 7145                         end
 7146                         set $ix = $ix + 1
 7147                 end
 7148                 set $cnt = $cnt + 1
 7149         end
 7150         set $cnt = 0
 7151         while $cnt < $INM_TRACE_HIST_SIZE
 7152                 set $ix = 0
 7153                 while $ix < $CTRACE_STACK_SIZE
 7154                         set $kgm_pc = $inm->inm_refrele[$cnt].pc[$ix]
 7155                         if $kgm_pc != 0
 7156                                 if $ix == 0
 7157                                         printf "\nRelease [%d] (thread %p):\n",\
 7158                                           $cnt, $inm->inm_refrele[$cnt].th
 7159                                 end
 7160                                 printf "%4d: ", $ix + 1
 7161                                 pcprint $kgm_pc
 7162                                 printf "\n"
 7163                         end
 7164                         set $ix = $ix + 1
 7165                 end
 7166                 set $cnt = $cnt + 1
 7167         end
 7168 end
 7169 
 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
 7175 | parameter.
 7176 end
 7177 
 7178 set $IF_REF_TRACE_HIST_SIZE = if_ref_trace_hist_size
 7179 
 7180 define ifpref_showdbg
 7181         set $dl_if = (struct dlil_ifnet_dbg *)$arg0
 7182         set $cnt = 0
 7183 
 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
 7186 
 7187         while $cnt < $IF_REF_TRACE_HIST_SIZE
 7188                 set $ix = 0
 7189                 while $ix < $CTRACE_STACK_SIZE
 7190                         set $kgm_pc = $dl_if->dldbg_if_refhold[$cnt].pc[$ix]
 7191                         if $kgm_pc != 0
 7192                                 if $ix == 0
 7193                                         printf "\nHold [%d] (thread %p):\n", \
 7194                                             $cnt, \
 7195                                             $dl_if->dldbg_if_refhold[$cnt].th
 7196                                 end
 7197                                 printf "%4d: ", $ix + 1
 7198                                 pcprint $kgm_pc
 7199                                 printf "\n"
 7200                         end
 7201                         set $ix = $ix + 1
 7202                 end
 7203                 set $cnt = $cnt + 1
 7204         end
 7205         set $cnt = 0
 7206         while $cnt < $IF_REF_TRACE_HIST_SIZE
 7207                 set $ix = 0
 7208                 while $ix < $CTRACE_STACK_SIZE
 7209                         set $kgm_pc = $dl_if->dldbg_if_refrele[$cnt].pc[$ix]
 7210                         if $kgm_pc != 0
 7211                                 if $ix == 0
 7212                                         printf "\nRelease [%d] (thread %p):\n",\
 7213                                             $cnt, \
 7214                                             $dl_if->dldbg_if_refrele[$cnt].th
 7215                                 end
 7216                                 printf "%4d: ", $ix + 1
 7217                                 pcprint $kgm_pc
 7218                                 printf "\n"
 7219                         end
 7220                         set $ix = $ix + 1
 7221                 end
 7222                 set $cnt = $cnt + 1
 7223         end
 7224 end
 7225 
 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
 7231 | parameter.
 7232 end
 7233 
 7234 define in6ifa_trash
 7235         set $ifa = (struct in6_ifaddr_dbg *)in6ifa_trash_head.tqh_first
 7236         set $cnt = 0
 7237         while $ifa != 0
 7238                 if $cnt == 0
 7239                     if $kgm_lp64
 7240                                 printf "                in6_ifa ref   hold   rele\n"
 7241                                 printf "      ----------------- --- ------ ------\n"
 7242                         else
 7243                                 printf "        in6_ifa ref   hold   rele\n"
 7244                                 printf "      --------- --- ------ ------\n"
 7245                         end
 7246                 end
 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
 7251                 printf "\n"
 7252                 set $ifa = $ifa->in6ifa_trash_link.tqe_next
 7253                 set $cnt = $cnt + 1
 7254         end
 7255 end
 7256 
 7257 set $NDPR_TRACE_HIST_SIZE = ndpr_trace_hist_size
 7258 
 7259 define ndpr_showdbg
 7260         set $ndpr = (struct nd_prefix_dbg *)$arg0
 7261         set $cnt = 0
 7262 
 7263         printf "Total references:\t%d\n", $ndpr->ndpr_refhold_cnt
 7264         printf "Total releases:\t\t%d\n", $ndpr->ndpr_refrele_cnt
 7265 
 7266         while $cnt < $NDPR_TRACE_HIST_SIZE
 7267                 set $ix = 0
 7268                 while $ix < $CTRACE_STACK_SIZE
 7269                         set $kgm_pc = $ndpr->ndpr_refhold[$cnt].pc[$ix]
 7270                         if $kgm_pc != 0
 7271                                 if $ix == 0
 7272                                         printf "\nHold [%d] (thread %p):\n", \
 7273                                             $cnt, \
 7274                                             $ndpr->ndpr_refhold[$cnt].th
 7275                                 end
 7276                                 printf "%4d: ", $ix + 1
 7277                                 pcprint $kgm_pc
 7278                                 printf "\n"
 7279                         end
 7280                         set $ix = $ix + 1
 7281                 end
 7282                 set $cnt = $cnt + 1
 7283         end
 7284         set $cnt = 0
 7285         while $cnt < $NDPR_TRACE_HIST_SIZE
 7286                 set $ix = 0
 7287                 while $ix < $CTRACE_STACK_SIZE
 7288                         set $kgm_pc = $ndpr->ndpr_refrele[$cnt].pc[$ix]
 7289                         if $kgm_pc != 0
 7290                                 if $ix == 0
 7291                                         printf "\nRelease [%d] (thread %p):\n",\
 7292                                             $cnt, \
 7293                                             $ndpr->ndpr_refrele[$cnt].th
 7294                                 end
 7295                                 printf "%4d: ", $ix + 1
 7296                                 pcprint $kgm_pc
 7297                                 printf "\n"
 7298                         end
 7299                         set $ix = $ix + 1
 7300                 end
 7301                 set $cnt = $cnt + 1
 7302         end
 7303 end
 7304 
 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.
 7311 end
 7312 
 7313 set $NDDR_TRACE_HIST_SIZE = nddr_trace_hist_size
 7314 
 7315 define nddr_showdbg
 7316         set $nddr = (struct nd_defrouter_dbg *)$arg0
 7317         set $cnt = 0
 7318 
 7319         printf "Total references:\t%d\n", $nddr->nddr_refhold_cnt
 7320         printf "Total releases:\t\t%d\n", $nddr->nddr_refrele_cnt
 7321 
 7322         while $cnt < $NDDR_TRACE_HIST_SIZE
 7323                 set $ix = 0
 7324                 while $ix < $CTRACE_STACK_SIZE
 7325                         set $kgm_pc = $nddr->nddr_refhold[$cnt].pc[$ix]
 7326                         if $kgm_pc != 0
 7327                                 if $ix == 0
 7328                                         printf "\nHold [%d] (thread %p):\n", \
 7329                                             $cnt, \
 7330                                             $nddr->nddr_refhold[$cnt].th
 7331                                 end
 7332                                 printf "%4d: ", $ix + 1
 7333                                 pcprint $kgm_pc
 7334                                 printf "\n"
 7335                         end
 7336                         set $ix = $ix + 1
 7337                 end
 7338                 set $cnt = $cnt + 1
 7339         end
 7340         set $cnt = 0
 7341         while $cnt < $NDDR_TRACE_HIST_SIZE
 7342                 set $ix = 0
 7343                 while $ix < $CTRACE_STACK_SIZE
 7344                         set $kgm_pc = $nddr->nddr_refrele[$cnt].pc[$ix]
 7345                         if $kgm_pc != 0
 7346                                 if $ix == 0
 7347                                         printf "\nRelease [%d] (thread %p):\n",\
 7348                                             $cnt, \
 7349                                             $nddr->nddr_refrele[$cnt].th
 7350                                 end
 7351                                 printf "%4d: ", $ix + 1
 7352                                 pcprint $kgm_pc
 7353                                 printf "\n"
 7354                         end
 7355                         set $ix = $ix + 1
 7356                 end
 7357                 set $cnt = $cnt + 1
 7358         end
 7359 end
 7360 
 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.
 7367 end
 7368 set $IMO_TRACE_HIST_SIZE = imo_trace_hist_size
 7369 
 7370 define imo_showdbg
 7371         set $imo = (struct ip_moptions_dbg *)$arg0
 7372         set $cnt = 0
 7373 
 7374         printf "Total references:\t%d\n", $imo->imo_refhold_cnt
 7375         printf "Total releases:\t\t%d\n", $imo->imo_refrele_cnt
 7376 
 7377         while $cnt < $IMO_TRACE_HIST_SIZE
 7378                 set $ix = 0
 7379                 while $ix < $CTRACE_STACK_SIZE
 7380                         set $kgm_pc = $imo->imo_refhold[$cnt].pc[$ix]
 7381                         if $kgm_pc != 0
 7382                                 if $ix == 0
 7383                                         printf "\nHold [%d] (thread %p):\n", \
 7384                                             $cnt, \
 7385                                             $imo->imo_refhold[$cnt].th
 7386                                 end
 7387                                 printf "%4d: ", $ix + 1
 7388                                 pcprint $kgm_pc
 7389                                 printf "\n"
 7390                         end
 7391                         set $ix = $ix + 1
 7392                 end
 7393                 set $cnt = $cnt + 1
 7394         end
 7395         set $cnt = 0
 7396         while $cnt < $IMO_TRACE_HIST_SIZE
 7397                 set $ix = 0
 7398                 while $ix < $CTRACE_STACK_SIZE
 7399                         set $kgm_pc = $imo->imo_refrele[$cnt].pc[$ix]
 7400                         if $kgm_pc != 0
 7401                                 if $ix == 0
 7402                                         printf "\nRelease [%d] (thread %p):\n",\
 7403                                             $cnt, \
 7404                                             $imo->imo_refrele[$cnt].th
 7405                                 end
 7406                                 printf "%4d: ", $ix + 1
 7407                                 pcprint $kgm_pc
 7408                                 printf "\n"
 7409                         end
 7410                         set $ix = $ix + 1
 7411                 end
 7412                 set $cnt = $cnt + 1
 7413         end
 7414 end
 7415 
 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.
 7422 end
 7423 
 7424 set $IM6O_TRACE_HIST_SIZE = im6o_trace_hist_size
 7425 
 7426 define im6o_showdbg
 7427         set $im6o = (struct ip6_moptions_dbg *)$arg0
 7428         set $cnt = 0
 7429 
 7430         printf "Total references:\t%d\n", $im6o->im6o_refhold_cnt
 7431         printf "Total releases:\t\t%d\n", $im6o->im6o_refrele_cnt
 7432 
 7433         while $cnt < $IM6O_TRACE_HIST_SIZE
 7434                 set $ix = 0
 7435                 while $ix < $CTRACE_STACK_SIZE
 7436                         set $kgm_pc = $im6o->im6o_refhold[$cnt].pc[$ix]
 7437                         if $kgm_pc != 0
 7438                                 if $ix == 0
 7439                                         printf "\nHold [%d] (thread %p):\n", \
 7440                                             $cnt, \
 7441                                             $im6o->im6o_refhold[$cnt].th
 7442                                 end
 7443                                 printf "%4d: ", $ix + 1
 7444                                 pcprint $kgm_pc
 7445                                 printf "\n"
 7446                         end
 7447                         set $ix = $ix + 1
 7448                 end
 7449                 set $cnt = $cnt + 1
 7450         end
 7451         set $cnt = 0
 7452         while $cnt < $IM6O_TRACE_HIST_SIZE
 7453                 set $ix = 0
 7454                 while $ix < $CTRACE_STACK_SIZE
 7455                         set $kgm_pc = $im6o->im6o_refrele[$cnt].pc[$ix]
 7456                         if $kgm_pc != 0
 7457                                 if $ix == 0
 7458                                         printf "\nRelease [%d] (thread %p):\n",\
 7459                                             $cnt, \
 7460                                             $im6o->im6o_refrele[$cnt].th
 7461                                 end
 7462                                 printf "%4d: ", $ix + 1
 7463                                 pcprint $kgm_pc
 7464                                 printf "\n"
 7465                         end
 7466                         set $ix = $ix + 1
 7467                 end
 7468                 set $cnt = $cnt + 1
 7469         end
 7470 end
 7471 
 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.
 7478 end
 7479 
 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.
 7485 end
 7486 
 7487 define inifa_trash
 7488         set $ifa = (struct in_ifaddr_dbg *)inifa_trash_head.tqh_first
 7489         set $cnt = 0
 7490         while $ifa != 0
 7491                 if $cnt == 0
 7492                     if $kgm_lp64
 7493                                 printf "                 in_ifa ref   hold   rele\n"
 7494                                 printf "      ----------------- --- ------ ------\n"
 7495                         else
 7496                                 printf "         in_ifa ref   hold   rele\n"
 7497                                 printf "      --------- --- ------ ------\n"
 7498                         end
 7499                 end
 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
 7504                 printf "\n"
 7505                 set $ifa = $ifa->inifa_trash_link.tqe_next
 7506                 set $cnt = $cnt + 1
 7507         end
 7508 end
 7509 
 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.
 7515 end
 7516 
 7517 define ifma_trash
 7518         set $ifma = (struct ifmultiaddr_dbg *)ifma_trash_head.tqh_first
 7519         set $cnt = 0
 7520         while $ifma != 0
 7521                 if $cnt == 0
 7522                     if $kgm_lp64
 7523                                 printf "                   ifma ref   hold   rele\n"
 7524                                 printf "      ----------------- --- ------ ------\n"
 7525                         else
 7526                                 printf "          ifma  ref   hold   rele\n"
 7527                                 printf "      --------- --- ------ ------\n"
 7528                         end
 7529                 end
 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
 7536                 printf "\n"
 7537                 set $ifma = $ifma->ifma_trash_link.tqe_next
 7538                 set $cnt = $cnt + 1
 7539         end
 7540 end
 7541 
 7542 document ifma_trash
 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.
 7547 end
 7548 
 7549 define inm_trash
 7550         set $inm = (struct in_multi_dbg *)inm_trash_head.tqh_first
 7551         set $cnt = 0
 7552         while $inm != 0
 7553                 if $cnt == 0
 7554                     if $kgm_lp64
 7555                                 printf "                    inm ref   hold   rele\n"
 7556                                 printf "      ----------------- --- ------ ------\n"
 7557                         else
 7558                                 printf "            inm ref   hold   rele\n"
 7559                                 printf "      --------- --- ------ ------\n"
 7560                         end
 7561                 end
 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)
 7566                 printf "\n"
 7567                 set $inm = $inm->inm_trash_link.tqe_next
 7568                 set $cnt = $cnt + 1
 7569         end
 7570 end
 7571 
 7572 document inm_trash
 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.
 7577 end
 7578 
 7579 define in6m_trash
 7580         set $in6m = (struct in6_multi_dbg *)in6m_trash_head.tqh_first
 7581         set $cnt = 0
 7582         while $in6m != 0
 7583                 if $cnt == 0
 7584                     if $kgm_lp64
 7585                                 printf "                   in6m ref   hold   rele\n"
 7586                                 printf "      ----------------- --- ------ ------\n"
 7587                         else
 7588                                 printf "           in6m ref   hold   rele\n"
 7589                                 printf "      --------- --- ------ ------\n"
 7590                         end
 7591                 end
 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)
 7596                 printf "\n"
 7597                 set $in6m = $in6m->in6m_trash_link.tqe_next
 7598                 set $cnt = $cnt + 1
 7599         end
 7600 end
 7601 
 7602 document in6m_trash
 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.
 7607 end
 7608 
 7609 #
 7610 # print all OSMalloc stats 
 7611 
 7612 define ostag_print
 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
 7619 printf "\n"
 7620 end
 7621 
 7622 
 7623 define showosmalloc 
 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
 7630     end
 7631         printf "\n"
 7632 end
 7633 document showosmalloc
 7634 Syntax: (gdb) showosmalloc
 7635 | Print the outstanding allocation count by OSMallocTags.
 7636 end
 7637 
 7638 
 7639 define systemlog
 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
 7644     else
 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
 7650         end
 7651     
 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
 7657                 # break out of loop
 7658                 set $kgm_i = $kgm_syslog_bufsize
 7659             else
 7660                 printf "%c", $kgm_syslog_char
 7661             end
 7662             set $kgm_i = $kgm_i + 1
 7663         end
 7664         
 7665         # print newer messages from start of buffer to msg_bufx
 7666         set $kgm_i = 0
 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
 7671             end
 7672             set $kgm_i = $kgm_i + 1
 7673         end
 7674     end
 7675     printf "\n"
 7676 end
 7677 document systemlog
 7678 | Syntax: systemlog
 7679 | Display the kernel's printf ring buffer
 7680 end
 7681 
 7682 
 7683 define hexdump
 7684         set $kgm_addr = (unsigned char *)$arg0
 7685         set $kgm_len = $arg1
 7686         while $kgm_len > 0
 7687                 showptr $kgm_addr
 7688                 printf ": "
 7689                 set $kgm_i = 0
 7690                 while $kgm_i < 16
 7691                         printf "%02x ", *($kgm_addr+$kgm_i)
 7692                         set $kgm_i += 1
 7693                 end
 7694                 printf " |"
 7695                 set $kgm_i = 0
 7696                 while $kgm_i < 16
 7697                         set $kgm_temp = *($kgm_addr+$kgm_i)
 7698                         if $kgm_temp < 32 || $kgm_temp >= 127
 7699                                 printf "."
 7700                         else
 7701                                 printf "%c", $kgm_temp
 7702                         end
 7703                         set $kgm_i += 1
 7704                 end
 7705                 printf "|\n"
 7706                 set $kgm_addr += 16
 7707                 set $kgm_len -= 16
 7708         end
 7709 end
 7710 document hexdump
 7711 | Show the contents of memory as a hex/ASCII dump
 7712 | The following is the syntax:
 7713 | (gdb) hexdump <address> <length>
 7714 end
 7715 
 7716 
 7717 define printcolonhex
 7718     if ($argc == 2) 
 7719         set $addr = $arg0
 7720         set $count = $arg1
 7721         set $li = 0
 7722         while ($li < $count)
 7723             if ($li == 0)
 7724                         printf "%02x", (u_char)$addr[$li]
 7725             end
 7726             if ($li != 0)
 7727                         printf ":%02x", (u_char)$addr[$li]
 7728             end
 7729             set $li = $li + 1
 7730         end
 7731     end
 7732 end
 7733 
 7734 define showsockaddr_dl
 7735     set $sdl = (struct sockaddr_dl *)$arg0
 7736     if ($sdl == 0)
 7737                 printf "(null)           "
 7738     else
 7739             if $sdl->sdl_nlen == 0 && $sdl->sdl_alen == 0 && $sdl->sdl_slen == 0
 7740                 printf "link#%3d         ", $sdl->sdl_index
 7741             else
 7742                         set $addr = $sdl->sdl_data + $sdl->sdl_nlen
 7743                         set $count = $sdl->sdl_alen
 7744                         printcolonhex $addr $count
 7745                 end
 7746     end
 7747 end
 7748 
 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
 7754 end
 7755 
 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
 7761 end
 7762 
 7763 define show_in_addr
 7764     set $ia = (unsigned char *)$arg0
 7765     printf "%3u.%03u.%03u.%03u", $ia[0], $ia[1], $ia[2], $ia[3]
 7766 end
 7767 
 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
 7772 end
 7773 
 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]
 7778 end
 7779 
 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
 7784 end
 7785 
 7786 define showsockaddr_un
 7787         set $sun = (struct sockaddr_un *)$arg0
 7788         if $sun == 0
 7789                 printf "(null)"
 7790         else
 7791                 if $sun->sun_path[0] == 0
 7792                         printf "\"\""
 7793                 else
 7794                         printf "%s", $sun->sun_path
 7795                 end
 7796         end
 7797 end
 7798 
 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
 7803    set $myi = 0
 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
 7810                 printf " "
 7811             end
 7812             showsockaddr_in $mymulti->ifma_addr
 7813         end
 7814         if ($sa_family == 30)
 7815             if ($mymulti->ifma_ll != 0)
 7816                 showsockaddr_dl $mymulti->ifma_ll->ifma_addr
 7817                 printf " "
 7818             end
 7819             showsockaddr_in6 $mymulti->ifma_addr
 7820         end
 7821         if ($sa_family == 18)
 7822             showsockaddr_dl $mymulti->ifma_addr
 7823         end
 7824         if ($sa_family == 0)
 7825             showsockaddr_unspec $mymulti->ifma_addr 6
 7826         end
 7827         printf " [%d]", $mymulti->ifma_refcount
 7828         printf "\n"
 7829         set $mymulti = $mymulti->ifma_link.le_next
 7830         set $myi = $myi + 1
 7831    end
 7832 end
 7833 
 7834 document showifmultiaddrs
 7835 Syntax showifmultiaddrs <ifp>
 7836 | show the (struct ifnet).if_multiaddrs list of multicast addresses for the given ifp
 7837 end
 7838 
 7839 define showinmultiaddrs
 7840    set $in_multi = (struct in_multi *)(in_multihead->lh_first)
 7841    set $mymulti = $in_multi
 7842    set $myi = 0
 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
 7849         printf "\n"
 7850         set $mymulti = $mymulti->inm_link.le_next
 7851         set $myi = $myi + 1
 7852    end
 7853 end
 7854 
 7855 document showinmultiaddrs
 7856 Syntax showinmultiaddrs
 7857 | show the contents of IPv4 multicast address records
 7858 end
 7859 
 7860 define showin6multiaddrs
 7861    set $in6_multi = (struct in6_multi *)(in6_multihead->lh_first)
 7862    set $mymulti = $in6_multi
 7863    set $myi = 0
 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
 7870         printf "\n"
 7871         set $mymulti = $mymulti->in6m_entry.le_next
 7872         set $myi = $myi + 1
 7873    end
 7874 end
 7875 
 7876 document showin6multiaddrs
 7877 Syntax showin6multiaddrs
 7878 | show the contents of IPv6 multicast address records
 7879 end
 7880 
 7881 define showsockaddr
 7882     set $mysock = (struct sockaddr *)$arg0
 7883     set $showsockaddr_handled = 0
 7884     if ($mysock == 0)
 7885         printf "(null)"
 7886     else
 7887         if ($mysock->sa_family == 0)
 7888                 printf "UNSPC"
 7889             showsockaddr_unspec $mysock
 7890             set $showsockaddr_handled = 1
 7891         end
 7892         if ($mysock->sa_family == 1)
 7893                 printf "UNIX "
 7894             showsockaddr_un $mysock
 7895             set $showsockaddr_handled = 1
 7896         end
 7897         if ($mysock->sa_family == 2)
 7898                 printf "INET "
 7899             showsockaddr_in $mysock
 7900             set $showsockaddr_handled = 1
 7901         end
 7902         if ($mysock->sa_family == 30)
 7903                 printf "INET6 "
 7904             showsockaddr_in6 $mysock
 7905             set $showsockaddr_handled = 1
 7906         end
 7907         if ($mysock->sa_family == 18)
 7908                 printf "LINK "
 7909             showsockaddr_dl $mysock
 7910             set $showsockaddr_handled = 1
 7911         end
 7912         if ($mysock->sa_family == 16)
 7913                 printf "ATLK "
 7914             showsockaddr_at $mysock
 7915             set $showsockaddr_handled = 1
 7916         end
 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
 7922         end
 7923     end
 7924 end
 7925 
 7926 define showifflags
 7927         set $flags = (u_short)$arg0
 7928         set $first = 1
 7929         printf "<"
 7930         if ($flags & 0x1)
 7931             printf "UP"
 7932             set $first = 0
 7933         end
 7934         if ($flags & 0x2)
 7935             if ($first == 1)
 7936                 set $first = 0
 7937             else
 7938                 printf ","
 7939             end
 7940             printf "BROADCAST"
 7941         end
 7942         if ($flags & 0x4)
 7943             printf "DEBUG"
 7944         end
 7945         if ($flags & 0x8)
 7946             if ($first == 1)
 7947                 set $first = 0
 7948             else
 7949                 printf ","
 7950             end
 7951             printf "LOOPBACK"
 7952         end
 7953         if ($flags & 0x10)
 7954             if ($first == 1)
 7955                 set $first = 0
 7956             else
 7957                 printf ","
 7958             end
 7959             printf "POINTTOPOINT"
 7960         end
 7961 ##      if ($flags & 0x20)
 7962 ##          if ($first == 1)
 7963 #               set $first = 0
 7964 ##          else
 7965 #               printf ","
 7966 #           end
 7967 #           printf "NOTRAILERS"
 7968 #       end
 7969         if ($flags & 0x40)
 7970             if ($first == 1)
 7971                 set $first = 0
 7972             else
 7973                 printf ","
 7974             end
 7975             printf "RUNNING"
 7976         end
 7977         if ($flags & 0x80)
 7978             if ($first == 1)
 7979                 set $first = 0
 7980             else
 7981                 printf ","
 7982             end
 7983             printf "NOARP"
 7984         end
 7985         if ($flags & 0x100)
 7986             if ($first == 1)
 7987                 set $first = 0
 7988             else
 7989                 printf ","
 7990             end
 7991             printf "PROMISC"
 7992         end
 7993         if ($flags & 0x200)
 7994             if ($first == 1)
 7995                 set $first = 0
 7996             else
 7997                 printf ","
 7998             end
 7999             printf "ALLMULTI"
 8000         end
 8001         if ($flags & 0x400)
 8002             if ($first == 1)
 8003                 set $first = 0
 8004             else
 8005                 printf ","
 8006             end
 8007             printf "OACTIVE"
 8008         end
 8009         if ($flags & 0x800)
 8010             if ($first == 1)
 8011                 set $first = 0
 8012             else
 8013                 printf ","
 8014             end
 8015             printf "SIMPLEX"
 8016         end
 8017         if ($flags & 0x1000)
 8018             if ($first == 1)
 8019                 set $first = 0
 8020             else
 8021                 printf ","
 8022             end
 8023             printf "LINK0"
 8024         end
 8025         if ($flags & 0x2000)
 8026             if ($first == 1)
 8027                 set $first = 0
 8028             else
 8029                 printf ","
 8030             end
 8031             printf "LINK1"
 8032         end
 8033         if ($flags & 0x4000)
 8034             if ($first == 1)
 8035                 set $first = 0
 8036             else
 8037                 printf ","
 8038             end
 8039             printf "LINK2-ALTPHYS"
 8040         end
 8041         if ($flags & 0x8000)
 8042             if ($first == 1)
 8043                 set $first = 0
 8044             else
 8045                 printf ","
 8046             end
 8047             printf "MULTICAST"
 8048         end
 8049         printf ">"
 8050 end
 8051 
 8052 define showifaddrs
 8053    set $ifp = (struct ifnet *)$arg0
 8054    set $myifaddr = (struct ifaddr *)$ifp->if_addrhead->tqh_first
 8055    set $myi = 0
 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
 8061         set $myi = $myi + 1
 8062    end
 8063 end
 8064 
 8065 document showifaddrs
 8066 Syntax: showifaddrs <ifp>
 8067 | show the (struct ifnet).if_addrhead list of addresses for the given ifp
 8068 end
 8069 
 8070 define ifconfig
 8071    set $ifconfig_all = 0
 8072    if ($argc == 1)
 8073         set $ifconfig_all = 1
 8074    end
 8075    set $ifp = (struct ifnet *)(ifnet_head->tqh_first)
 8076    while ($ifp != 0)
 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 *)"
 8082     showptr $ifp
 8083     printf "\n"
 8084         if ($ifconfig_all == 1) 
 8085            showifaddrs $ifp
 8086     end
 8087         set $ifp = $ifp->if_link->tqe_next
 8088    end
 8089 end
 8090 document ifconfig
 8091 Syntax: (gdb) ifconfig
 8092 | display ifconfig-like output, and print the (struct ifnet *) pointers for further inspection
 8093 end
 8094 
 8095 set $DLIF_INUSE = 0x1
 8096 set $DLIF_REUSE = 0x2
 8097 
 8098 define showifnets
 8099         set $all = 0
 8100         if ($argc == 1)
 8101                 set $all = 1
 8102         end
 8103         set $dlifp = (struct dlil_ifnet *)(dlil_ifnet_head->tqh_first)
 8104         while ($dlifp != 0)
 8105                 set $ifp = (struct ifnet *)$dlifp
 8106                 if ($dlifp->dl_if_flags & $DLIF_REUSE)
 8107                         printf "*"
 8108                 end
 8109                 if ($dlifp->dl_if_flags & $DLIF_INUSE)
 8110                         printf "%s%d: ", $ifp->if_name, $ifp->if_unit
 8111                 else
 8112                         printf "[%s%d]: ", $ifp->if_name, $ifp->if_unit
 8113                 end
 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 *)"
 8119                 showptr $ifp
 8120                 printf "\n"
 8121                 if ($all == 1) 
 8122                         showifaddrs $ifp
 8123                 end
 8124                 set $dlifp = $dlifp->dl_if_link->tqe_next
 8125         end
 8126 end
 8127 
 8128 document showifnets
 8129 Syntax: (gdb) showifnets
 8130 | Display ifconfig-like output for all attached and detached interfaces
 8131 end
 8132 
 8133 define _show_unix_domain_socket
 8134         set $so = (struct socket *)$arg0
 8135         set $pcb = (struct unpcb *)$so->so_pcb
 8136         if $pcb == 0
 8137                 printf "unpcb: (null) "
 8138         else
 8139                 printf "unpcb: %p ", $pcb
 8140                 printf "unp_vnode: %p ", $pcb->unp_vnode
 8141                 printf "unp_conn: %p ", $pcb->unp_conn
 8142                 printf "unp_addr: "
 8143                 showsockaddr_un $pcb->unp_addr
 8144         end
 8145 end
 8146 
 8147 define _show_in_port
 8148         set $str = (unsigned char *)$arg0
 8149         set $port = *(unsigned short *)$arg0
 8150         
 8151         if (((($port & 0xff00) >> 8) == $str[0])) && ((($port & 0x00ff) == $str[1]))
 8152                 #printf "big endian "
 8153                 printf ":%d ", $port
 8154         else
 8155                 #printf "little endian "
 8156                 printf ":%d ", (($port & 0xff00) >> 8) | (($port & 0x00ff) << 8)
 8157         end
 8158 end
 8159 
 8160 define _show_in_addr_4in6
 8161         set $ia = (unsigned char *)$arg0
 8162         if $ia
 8163             printf "%3u.%03u.%03u.%03u", $ia[0], $ia[1], $ia[2], $ia[3]
 8164         end
 8165 end
 8166 
 8167 define _show_in6_addr
 8168         set $ia = (unsigned char *)$arg0
 8169         if $ia
 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]
 8173         end
 8174 end
 8175 
 8176 define _showtcpstate
 8177         set $tp = (struct tcpcb *)$arg0
 8178         if $tp
 8179                 if $tp->t_state == 0
 8180                         printf "CLOSED      "
 8181                 end
 8182                 if $tp->t_state == 1
 8183                         printf "LISTEN      "
 8184                 end
 8185                 if $tp->t_state == 2
 8186                         printf "SYN_SENT    "
 8187                 end
 8188                 if $tp->t_state == 3
 8189                         printf "SYN_RCVD    "
 8190                 end
 8191                 if $tp->t_state == 4
 8192                         printf "ESTABLISHED "
 8193                 end
 8194                 if $tp->t_state == 5
 8195                         printf "CLOSE_WAIT   "
 8196                 end
 8197                 if $tp->t_state == 6
 8198                         printf "FIN_WAIT_1   "
 8199                 end
 8200                 if $tp->t_state == 7
 8201                         printf "CLOSING      "
 8202                 end
 8203                 if $tp->t_state == 8
 8204                         printf "LAST_ACK     "
 8205                 end
 8206                 if $tp->t_state == 9
 8207                         printf "FIN_WAIT_2   "
 8208                 end
 8209                 if $tp->t_state == 10
 8210                         printf "TIME_WAIT    "
 8211                 end
 8212         end
 8213 end
 8214 
 8215 define _showsockprotocol
 8216         set $so = (struct socket *)$arg0
 8217         set $inpcb = (struct inpcb *)$so->so_pcb
 8218 
 8219         if $so->so_proto->pr_protocol == 6
 8220                 printf "TCP "
 8221                 _showtcpstate $inpcb->inp_ppcb
 8222         end
 8223         if $so->so_proto->pr_protocol == 17
 8224                 printf "UDP "
 8225         end
 8226         if $so->so_proto->pr_protocol == 1
 8227                 printf "ICMP "
 8228         end
 8229         if $so->so_proto->pr_protocol == 254
 8230                 printf "DIVERT "
 8231         end
 8232         if $so->so_proto->pr_protocol == 255
 8233                 printf "RAW "
 8234         end
 8235 end
 8236 
 8237 define _show_ipv4_socket
 8238         set $so = (struct socket *)$arg0
 8239         set $inpcb = (struct inpcb *)$so->so_pcb
 8240         if $inpcb == 0
 8241                 printf "inpcb: (null) "
 8242         else
 8243                 printf "inpcb: %p ", $inpcb
 8244                 
 8245                 _showsockprotocol $so
 8246 
 8247                 _show_in_addr_4in6  &$inpcb->inp_dependladdr.inp46_local
 8248                 _show_in_port  &$inpcb->inp_lport
 8249                 printf "-> "
 8250                 _show_in_addr_4in6  &$inpcb->inp_dependfaddr.inp46_foreign
 8251                 _show_in_port &$inpcb->inp_fport
 8252         end
 8253 end
 8254 
 8255 define _show_ipv6_socket
 8256         set $so = (struct socket *)$arg0
 8257         set $pcb = (struct inpcb *)$so->so_pcb
 8258         if $pcb == 0
 8259                 printf "inpcb: (null) "
 8260         else
 8261                 printf "inpcb: %p ", $pcb
 8262 
 8263                 _showsockprotocol $so
 8264 
 8265                 _show_in6_addr  &$pcb->inp_dependladdr.inp6_local
 8266                 _show_in_port  &$pcb->inp_lport
 8267                 printf "-> "
 8268                 _show_in6_addr  &$pcb->inp_dependfaddr.inp6_foreign
 8269                 _show_in_port &$pcb->inp_fport
 8270         end
 8271 end
 8272 
 8273 
 8274 define showsocket
 8275         set $so = (struct socket *)$arg0
 8276         if $so == 0
 8277                 printf "so: (null) "
 8278         else
 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
 8282 
 8283                         printf "%s ", $domain->dom_name
 8284                         if  $domain->dom_family == 1
 8285                                 _show_unix_domain_socket $so
 8286                         end
 8287                         if  $domain->dom_family == 2
 8288                                 _show_ipv4_socket $so
 8289                         end
 8290                         if  $domain->dom_family == 30
 8291                                 _show_ipv6_socket $so
 8292                         end
 8293                 end
 8294         end
 8295         printf "\n"
 8296 end
 8297 document showsocket
 8298 Syntax: (gdb) showsocket <socket_address>
 8299 | Routine to print out a socket
 8300 end
 8301 
 8302 define showprocsockets
 8303         set $pp = (struct proc *)$arg0
 8304         set $fdp = (struct filedesc *)$pp->p_fd
 8305 
 8306         set $count = 0
 8307         set $fpp =  (struct fileproc **)($fdp->fd_ofiles)
 8308         set $fpo =  (char)($fdp->fd_ofileflags[0])
 8309         while $count < $fdp->fd_nfiles
 8310                 if *$fpp
 8311                         set $fg =(struct fileglob *)((**$fpp)->f_fglob)
 8312                         if  $fg && (($fg)->fg_type == 2) 
 8313                                 if $fdp->fd_ofileflags[$count] & 4
 8314                                         printf "U: "
 8315                                 else
 8316                                         printf " "
 8317                                 end
 8318                                 printf "fd = %d ", $count
 8319                                 if  $fg->fg_data
 8320                                         showsocket  $fg->fg_data
 8321                                 else
 8322                                         printf "\n"
 8323                                 end
 8324                         end
 8325                 end
 8326                 set $fpp = $fpp + 1
 8327                 set $count = $count + 1         
 8328         end
 8329 end
 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
 8334 end
 8335 
 8336 define showallprocsockets
 8337   set $basep = (struct proc  *)allproc->lh_first
 8338   set $pp = $basep
 8339   while $pp
 8340         printf "============================================ \n"
 8341         showproc $pp
 8342         showprocsockets $pp
 8343         set $pp = $pp->p_list.le_next
 8344   end
 8345 end
 8346 document showallprocsockets
 8347 Syntax: (gdb) showallprocsockets
 8348 | Routine to print out all the open fds
 8349 | which are sockets 
 8350 end
 8351 
 8352 define _print_ntohs
 8353         set $port = (unsigned short)$arg0
 8354         set $port = (unsigned short)((($arg0 & 0xff00) >> 8) & 0xff)
 8355         set $port |= (unsigned short)(($arg0 & 0xff) << 8)
 8356         printf "%5d", $port
 8357 end
 8358 
 8359 set $INPCB_STATE_INUSE=0x1
 8360 set $INPCB_STATE_CACHED=0x2
 8361 set $INPCB_STATE_DEAD=0x3
 8362 
 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
 8386 
 8387 set $INP_IPV4=0x1
 8388 set $INP_IPV6=0x2
 8389 
 8390 set $IPPROTO_TCP=6
 8391 set $IPPROTO_UDP=17
 8392 
 8393 define _dump_inpcb
 8394         set $pcb = (struct inpcb *)$arg0
 8395         if $kgm_lp64
 8396                 printf "%18p", $pcb
 8397         else
 8398                 printf "%10p ", $pcb
 8399         end
 8400         if $arg1 == $IPPROTO_TCP
 8401                 printf "tcp"
 8402         else
 8403                 if $arg1 == $IPPROTO_UDP
 8404                         printf "udp"
 8405                 else
 8406                         printf "%2d.", $arg1
 8407                 end
 8408         end
 8409         if ($pcb->inp_vflag & $INP_IPV4)
 8410                 printf "4 "
 8411         end
 8412         if ($pcb->inp_vflag & $INP_IPV6)
 8413                 printf "6 "
 8414         end
 8415 
 8416         if ($pcb->inp_vflag & $INP_IPV4)
 8417                 printf "                        "
 8418                 _show_in_addr &$pcb->inp_dependladdr.inp46_local.ia46_addr4
 8419         else
 8420                 _show_in6_addr &$pcb->inp_dependladdr.inp6_local
 8421         end
 8422         printf " "
 8423         _print_ntohs $pcb->inp_lport
 8424         printf " "
 8425         if ($pcb->inp_vflag & $INP_IPV4)
 8426                 printf "                        "
 8427                 _show_in_addr &($pcb->inp_dependfaddr.inp46_foreign.ia46_addr4)
 8428         else
 8429                 _show_in6_addr &($pcb->inp_dependfaddr.inp6_foreign)
 8430         end
 8431         printf " "
 8432         _print_ntohs $pcb->inp_fport
 8433         printf " "
 8434 
 8435         if $arg1 == $IPPROTO_TCP
 8436                 _showtcpstate $pcb->inp_ppcb
 8437         end
 8438 
 8439 #       printf "phd "
 8440 #       set $phd = $pcb->inp_phd
 8441 #       while $phd != 0
 8442 #               printf " "
 8443 #               _print_ntohs $phd->phd_port
 8444 #               set $phd = $phd->phd_hash.le_next
 8445 #       end
 8446 #       printf ", "
 8447         if ($pcb->inp_flags & $INP_RECVOPTS)
 8448                 printf "recvopts "
 8449         end
 8450         if ($pcb->inp_flags & $INP_RECVRETOPTS)
 8451                 printf "recvretopts "
 8452         end
 8453         if ($pcb->inp_flags & $INP_RECVDSTADDR)
 8454                 printf "recvdstaddr "
 8455         end
 8456         if ($pcb->inp_flags & $INP_HDRINCL)
 8457                 printf "hdrincl "
 8458         end
 8459         if ($pcb->inp_flags & $INP_HIGHPORT)
 8460                 printf "highport "
 8461         end
 8462         if ($pcb->inp_flags & $INP_LOWPORT)
 8463                 printf "lowport "
 8464         end
 8465         if ($pcb->inp_flags & $INP_ANONPORT)
 8466                 printf "anonport "
 8467         end
 8468         if ($pcb->inp_flags & $INP_RECVIF)
 8469                 printf "recvif "
 8470         end
 8471         if ($pcb->inp_flags & $INP_MTUDISC)
 8472                 printf "mtudisc "
 8473         end
 8474         if ($pcb->inp_flags & $INP_STRIPHDR)
 8475                 printf "striphdr "
 8476         end
 8477         if ($pcb->inp_flags & $INP_RECV_ANYIF)
 8478                 printf "recv_anyif "
 8479         end
 8480         if ($pcb->inp_flags & $INP_INADDR_ANY)
 8481                 printf "inaddr_any "
 8482         end
 8483         if ($pcb->inp_flags & $INP_RECVTTL)
 8484                 printf "recvttl "
 8485         end
 8486         if ($pcb->inp_flags & $INP_UDP_NOCKSUM)
 8487                 printf "nocksum "
 8488         end
 8489         if ($pcb->inp_flags & $IN6P_IPV6_V6ONLY)
 8490                 printf "v6only "
 8491         end
 8492         if ($pcb->inp_flags & $IN6P_PKTINFO)
 8493                 printf "pktinfo "
 8494         end
 8495         if ($pcb->inp_flags & $IN6P_HOPLIMIT)
 8496                 printf "hoplimit "
 8497         end
 8498         if ($pcb->inp_flags & $IN6P_HOPOPTS)
 8499                 printf "hopopts "
 8500         end
 8501         if ($pcb->inp_flags & $IN6P_DSTOPTS)
 8502                 printf "dstopts "
 8503         end
 8504         if ($pcb->inp_flags & $IN6P_RTHDR)
 8505                 printf "rthdr "
 8506         end
 8507         if ($pcb->inp_flags & $IN6P_RTHDRDSTOPTS)
 8508                 printf "rthdrdstopts "
 8509         end
 8510         if ($pcb->inp_flags & $IN6P_AUTOFLOWLABEL)
 8511                 printf "autoflowlabel "
 8512         end
 8513         if ($pcb->inp_flags & $IN6P_BINDV6ONLY)
 8514                 printf "bindv6only "
 8515         end
 8516         set $so = (struct socket *)$pcb->inp_socket
 8517         if $so != 0
 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
 8520         end
 8521         if ($pcb->inp_state == 0 || $pcb->inp_state == $INPCB_STATE_INUSE)
 8522                 printf "inuse, "
 8523         else
 8524                 if ($pcb->inp_state == $INPCB_STATE_CACHED)
 8525                         printf "cached, "
 8526                 else
 8527                         if ($pcb->inp_state == $INPCB_STATE_DEAD)
 8528                                 printf "dead, "
 8529                         else
 8530                                 printf "unknown (%d), ", $pcb->inp_state
 8531                         end
 8532                 end
 8533         end
 8534 end
 8535 
 8536 define _dump_inpcbport
 8537         set $ppcb = (struct inpcbport *)$arg0
 8538         printf "%p: lport ", $ppcb
 8539         _print_ntohs $ppcb->phd_port
 8540 end
 8541 
 8542 set $UDBHASHSIZE=16
 8543 
 8544 define _dump_pcbinfo
 8545         set $snd_cc = 0
 8546         set $snd_buf = (unsigned int)0
 8547         set $rcv_cc = 0
 8548         set $rcv_buf = (unsigned int)0
 8549         set $pcbseen = 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
 8557         if $kgm_lp64
 8558                 printf "pcb                prot source                          address port  destination                     address port\n"
 8559                 printf "------------------ ---- --------------------------------------- ----- --------------------------------------- -----\n"
 8560         else
 8561                 printf "pcb        prot source                          address port  destination                     address port\n"
 8562                 printf "---------- ---- --------------------------------------- ----- --------------------------------------- -----\n"
 8563         end
 8564         set $i = 0
 8565         set $hashbase = $pcbi->hashbase
 8566         set $head = *(uintptr_t *)$hashbase
 8567         while $i < $hashsize
 8568                 if $head != 0
 8569                         set $pcb0 = (struct inpcb *)$head
 8570                         while $pcb0  != 0
 8571                                 set $pcbseen += 1
 8572                                 _dump_inpcb $pcb0 $arg1
 8573                                 set $so = (struct socket *)$pcb->inp_socket
 8574                                 if $so != 0
 8575                                         set $snd_cc += $so->so_snd.sb_cc
 8576                                         set $mp = $so->so_snd.sb_mb
 8577                                         while $mp
 8578                                                 set $snd_buf += 256
 8579                                                 if ($mp->m_hdr.mh_flags & 0x01)
 8580                                                         set $snd_buf += $mp->M_dat.MH.MH_dat.MH_ext.ext_size
 8581                                                 end
 8582                                                 set $mp = $mp->m_hdr.mh_next
 8583                                         end
 8584                                         set $rcv_cc += $so->so_rcv.sb_cc
 8585                                         set $mp = $so->so_rcv.sb_mb
 8586                                         while $mp
 8587                                                 set $rcv_buf += 256
 8588                                                 if ($mp->m_hdr.mh_flags & 0x01)
 8589                                                         set $rcv_buf += $mp->M_dat.MH.MH_dat.MH_ext.ext_size
 8590                                                 end
 8591                                                 set $mp = $mp->m_hdr.mh_next
 8592                                         end
 8593                                 end
 8594                                 set $pcb0 = $pcb0->inp_hash.le_next
 8595                                 printf "\n"
 8596                         end
 8597                 end
 8598                 set $i += 1
 8599                 set $hashbase += 1
 8600                 set $head = *(uintptr_t *)$hashbase
 8601         end
 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
 8605         set $i = 0
 8606         set $hashbase = $pcbi->porthashbase
 8607         set $head = *(uintptr_t *)$hashbase
 8608         while $i < $hashsize
 8609                 if $head != 0
 8610                         set $pcb0 = (struct inpcbport *)$head
 8611                         while $pcb0  != 0
 8612                                 printf "\t"
 8613                                 _dump_inpcbport $pcb0
 8614                                 printf "\n"
 8615                                 set $pcb0 = $pcb0->phd_hash.le_next
 8616                         end
 8617                 end
 8618                 set $i += 1
 8619                 set $hashbase += 1
 8620                 set $head = *(uintptr_t *)$hashbase
 8621         end
 8622 end
 8623 
 8624 set $N_TIME_WAIT_SLOTS=128
 8625 
 8626 define show_tcp_timewaitslots
 8627         set $slot = -1
 8628         set $all = 0
 8629         if $argc == 1
 8630                 if (int)$arg0 == -1
 8631                         set $all = 1
 8632                 else
 8633                         set $slot = (int)$arg0
 8634                 end
 8635         end
 8636         printf "time wait slot size %d cur_tw_slot %ld\n", $N_TIME_WAIT_SLOTS, cur_tw_slot
 8637         set $i = 0
 8638         while $i < $N_TIME_WAIT_SLOTS
 8639                 set $perslot = 0
 8640                 set $head = (uintptr_t *)time_wait_slots[$i]
 8641                 if $i == $slot || $slot == -1
 8642                         if $head != 0
 8643                                 set $pcb0 = (struct inpcb *)$head
 8644                                 while $pcb0  != 0
 8645                                         set $perslot += 1
 8646                                         set $pcb0 = $pcb0->inp_list.le_next
 8647                                 end
 8648                         end
 8649                         printf "  slot %ld count %ld\n", $i, $perslot
 8650                 end
 8651                 if $all ||  $i == $slot
 8652                         if $head != 0
 8653                                 set $pcb0 = (struct inpcb *)$head
 8654                                 while $pcb0  != 0
 8655                                         printf "\t"
 8656                                         _dump_inpcb $pcb0 $IPPROTO_TCP
 8657                                         printf "\n"
 8658                                         set $pcb0 = $pcb0->inp_list.le_next
 8659                                 end
 8660                         end
 8661                 end
 8662                 set $i += 1
 8663         end
 8664 end
 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
 8670 end
 8671 
 8672 define show_tcp_pcbinfo
 8673         _dump_pcbinfo &tcbinfo $IPPROTO_TCP
 8674 end
 8675 document show_tcp_pcbinfo
 8676 Syntax: (gdb) show_tcp_pcbinfo
 8677 | Print the list of TCP protocol control block information
 8678 end
 8679 
 8680 
 8681 define show_udp_pcbinfo
 8682         _dump_pcbinfo &udbinfo $IPPROTO_UDP
 8683 end
 8684 document show_udp_pcbinfo
 8685 Syntax: (gdb) show_udp_pcbinfo
 8686 | Print the list of UDP protocol control block information
 8687 end
 8688 
 8689 define showbpfdtab
 8690     set $myi = 0
 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]
 8695         end
 8696         set $myi = $myi + 1
 8697     end
 8698 end
 8699 
 8700 define printvnodepathint_recur
 8701         if $arg0 != 0
 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
 8705                         end
 8706                 else
 8707                         printvnodepathint_recur $arg0->v_parent $arg0->v_parent->v_name
 8708                         printf "/%s", $arg1
 8709                 end
 8710         end
 8711 end
 8712 
 8713 define showvnodepath
 8714         set $vp = (struct vnode *)$arg0
 8715         if $vp != 0
 8716                 if ($vp->v_flag & 0x000001) && ($vp->v_mount != 0) && ($vp->v_mount->mnt_flag & 0x00004000)
 8717                         printf "/"
 8718                 else
 8719                         printvnodepathint_recur $vp $vp->v_name
 8720                 end
 8721         end
 8722         printf "\n"
 8723 end
 8724 
 8725 document showvnodepath
 8726 Syntax: (gdb) showvnodepath <vnode>
 8727 | Prints the path for a vnode
 8728 end
 8729 
 8730 define showallvols
 8731         printf "volume    "
 8732     showptrhdrpad
 8733     printf "  mnt_data  "
 8734     showptrhdrpad
 8735     printf "  mnt_devvp "
 8736     showptrhdrpad
 8737     printf "  typename    mountpoint\n"
 8738         set $kgm_vol = (mount_t) mountlist.tqh_first
 8739         while $kgm_vol
 8740         showptr $kgm_vol
 8741         printf "  "
 8742         showptr $kgm_vol->mnt_data
 8743         printf "  "
 8744         showptr $kgm_vol->mnt_devvp
 8745         printf "  "
 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  "
 8754                         else
 8755                                 printf "hfs         "
 8756                         end
 8757                 else
 8758                         printf "%-10s  ", $kgm_vol->mnt_vtable->vfc_name
 8759                 end
 8760                 printf "%s\n", $kgm_vol->mnt_vfsstat.f_mntonname
 8761                 
 8762                 set $kgm_vol = (mount_t) $kgm_vol->mnt_list.tqe_next
 8763         end
 8764 end
 8765 
 8766 document showallvols
 8767 Syntax: (gdb) showallvols
 8768 | Display a summary of mounted volumes
 8769 end
 8770 
 8771 define showvnodeheader
 8772         printf "vnode     "
 8773     showptrhdrpad
 8774     printf "  usecount  iocount  v_data    "
 8775     showptrhdrpad
 8776     printf "  vtype  parent    "
 8777     showptrhdrpad    
 8778     printf "  name\n"
 8779 end
 8780 
 8781 define showvnodeint
 8782         set $kgm_vnode = (vnode_t) $arg0
 8783         showptr $kgm_vnode
 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
 8788     printf "  "
 8789         # print the vtype, using the enum tag
 8790         set $kgm_vtype = $kgm_vnode->v_type
 8791         if $kgm_vtype == VNON
 8792                 printf "VNON   "
 8793         end
 8794         if $kgm_vtype == VREG
 8795                 printf "VREG   "
 8796         end
 8797         if $kgm_vtype == VDIR
 8798                 printf "VDIR   "
 8799         end
 8800         if $kgm_vtype == VBLK
 8801                 printf "VBLK   "
 8802         end
 8803         if $kgm_vtype == VCHR
 8804                 printf "VCHR   "
 8805         end
 8806         if $kgm_vtype == VLNK
 8807                 printf "VLNK   "
 8808         end
 8809         if $kgm_vtype == VSOCK
 8810                 printf "VSOCK  "
 8811         end
 8812         if $kgm_vtype == VFIFO
 8813                 printf "VFIFO  "
 8814         end
 8815         if $kgm_vtype == VBAD
 8816                 printf "VBAD   "
 8817         end
 8818         if ($kgm_vtype < VNON) || ($kgm_vtype > VBAD)
 8819                 printf "%5d  ", $kgm_vtype
 8820         end
 8821 
 8822         showptr $kgm_vnode->v_parent
 8823     printf "  "
 8824         if ($kgm_vnode->v_name != 0)
 8825                 printf "%s\n", $kgm_vnode->v_name
 8826         else 
 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
 8831                 else 
 8832                         printf "\n"
 8833                 end
 8834         end
 8835 end
 8836 
 8837 define showvnode
 8838         showvnodeheader
 8839         showvnodeint $arg0
 8840 end
 8841 
 8842 document showvnode
 8843 Syntax: (gdb) showvnode <vnode>
 8844 | Display info about one vnode
 8845 end
 8846 
 8847 define showvolvnodes
 8848         showvnodeheader
 8849         set $kgm_vol = (mount_t) $arg0
 8850         set $kgm_vnode = (vnode_t) $kgm_vol.mnt_vnodelist.tqh_first
 8851         while $kgm_vnode
 8852                 showvnodeint $kgm_vnode
 8853                 set $kgm_vnode = (vnode_t) $kgm_vnode->v_mntvnodes.tqe_next
 8854         end
 8855 end
 8856 
 8857 document showvolvnodes
 8858 Syntax: (gdb) showvolvnodes <mouont_t>
 8859 | Display info about all vnodes of a given mount_t
 8860 end
 8861 
 8862 define showvolbusyvnodes
 8863         showvnodeheader
 8864         set $kgm_vol = (mount_t) $arg0
 8865         set $kgm_vnode = (vnode_t) $kgm_vol.mnt_vnodelist.tqh_first
 8866         while $kgm_vnode
 8867                 if $kgm_vnode->v_iocount != 0
 8868                         showvnodeint $kgm_vnode
 8869                 end
 8870                 set $kgm_vnode = (vnode_t) $kgm_vnode->v_mntvnodes.tqe_next
 8871         end
 8872 end
 8873 
 8874 document showvolbusyvnodes
 8875 Syntax: (gdb) showvolbusyvnodes <mount_t>
 8876 | Display info about busy (iocount!=0) vnodes of a given mount_t
 8877 end
 8878 
 8879 define showallbusyvnodes
 8880         showvnodeheader
 8881         set $kgm_vol = (mount_t) mountlist.tqh_first
 8882         while $kgm_vol
 8883                 set $kgm_vnode = (vnode_t) $kgm_vol.mnt_vnodelist.tqh_first
 8884                 while $kgm_vnode
 8885                         if $kgm_vnode->v_iocount != 0
 8886                                 showvnodeint $kgm_vnode
 8887                         end
 8888                         set $kgm_vnode = (vnode_t) $kgm_vnode->v_mntvnodes.tqe_next
 8889                 end
 8890                 set $kgm_vol = (mount_t) $kgm_vol->mnt_list.tqe_next
 8891         end
 8892 end
 8893 
 8894 document showallbusyvnodes
 8895 Syntax: (gdb) showallbusyvnodes <vnode>
 8896 | Display info about all busy (iocount!=0) vnodes
 8897 end
 8898 
 8899 define showallvnodes
 8900         showvnodeheader
 8901         set $kgm_vol = (mount_t) mountlist.tqh_first
 8902         while $kgm_vol
 8903                 set $kgm_vnode = (vnode_t) $kgm_vol.mnt_vnodelist.tqh_first
 8904                 while $kgm_vnode
 8905                         showvnodeint $kgm_vnode
 8906                         set $kgm_vnode = (vnode_t) $kgm_vnode->v_mntvnodes.tqe_next
 8907                 end
 8908                 set $kgm_vol = (mount_t) $kgm_vol->mnt_list.tqe_next
 8909         end
 8910 end
 8911 
 8912 document showallvnodes
 8913 Syntax: (gdb) showallvnodes
 8914 | Display info about all vnodes
 8915 end
 8916 
 8917 define _showvnodelockheader
 8918     printf "*  type   W  held by        lock type  start               end\n"
 8919     printf "-  -----  -  -------------  ---------  ------------------  ------------------\n"
 8920 end
 8921 
 8922 define _showvnodelock
 8923     set $kgm_svl_lock = ((struct lockf *)$arg0)
 8924 
 8925     # decode flags
 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)
 8929         printf "flock"
 8930     end
 8931     if ($kgm_svl_flags & 0x40)
 8932         printf "posix"
 8933     end
 8934     if ($kgm_svl_flags & 0x80)
 8935         printf "prov "
 8936     end
 8937     if ($kgm_svl_flags & 0x10)
 8938         printf "  W  "
 8939     else
 8940         printf "  .  "
 8941     end
 8942 
 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
 8947     else
 8948         printf "ID 0x%08x  ", $kgm_svl_lock->lf_id
 8949     end
 8950 
 8951     # lock type
 8952     if ($kgm_svl_type == 1)
 8953                 printf "shared     "
 8954     else
 8955         if ($kgm_svl_type == 3)
 8956                 printf "exclusive  "
 8957         else
 8958             if ($kgm_svl_type == 2)
 8959                 printf "unlock     "
 8960             else
 8961                 printf "unknown    "
 8962             end
 8963         end
 8964     end
 8965 
 8966     # start and stop
 8967     printf "0x%016x..", $kgm_svl_lock->lf_start
 8968     printf "0x%016x  ", $kgm_svl_lock->lf_end
 8969     printf "\n"
 8970 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
 8977         printf "H  "
 8978         _showvnodelock $kgm_svl_lockiter
 8979 
 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)
 8983             printf ">  "
 8984             _showvnodelock $kgm_svl_blocker
 8985             set $kgm_svl_blocker = $kgm_svl_blocker->lf_block.tqe_next
 8986         end
 8987 
 8988         # and on to the next one...
 8989         set $kgm_svl_lockiter = $kgm_svl_lockiter->lf_next
 8990     end
 8991 end
 8992 
 8993 
 8994 define showvnodelocks
 8995     if ($argc == 1)
 8996         _showvnodelockheader
 8997         _showvnodelocks $arg0
 8998     else
 8999         printf "| Usage:\n|\n"
 9000         help showvnodelocks
 9001     end
 9002 end
 9003 
 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
 9008 end
 9009 
 9010 define showbootargs
 9011         printf "%s\n", (char*)((boot_args*)PE_state.bootArgs).CommandLine
 9012 end
 9013 
 9014 document showbootargs
 9015 Syntax: showbootargs
 9016 | Display boot arguments passed to the target kernel
 9017 end
 9018 
 9019 define showbootermemorymap
 9020         if ($kgm_mtype == $kgm_mtype_i386)
 9021             set $kgm_voffset = 0
 9022         else
 9023             if ($kgm_mtype == $kgm_mtype_x86_64)
 9024                 set $kgm_voffset = 0xFFFFFF8000000000ULL
 9025             else
 9026                 echo showbootermemorymap not supported on this architecture
 9027             end
 9028         end
 9029 
 9030         set $kgm_boot_args = kernelBootArgs
 9031         set $kgm_msize = kernelBootArgs->MemoryMapDescriptorSize
 9032         set $kgm_mcount = kernelBootArgs->MemoryMapSize / $kgm_msize
 9033         set $kgm_i = 0
 9034        
 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)
 9038 #            p/x *$kgm_mptr
 9039              if $kgm_mptr->Type == 0
 9040                printf "Reserved  "
 9041              end
 9042              if $kgm_mptr->Type == 1
 9043                printf "LoaderCode"
 9044              end
 9045              if $kgm_mptr->Type == 2
 9046                printf "LoaderData"
 9047              end
 9048              if $kgm_mptr->Type == 3
 9049                printf "BS_code   "
 9050              end
 9051              if $kgm_mptr->Type == 4
 9052                printf "BS_data   "
 9053              end
 9054              if $kgm_mptr->Type == 5
 9055                printf "RT_code   "
 9056              end
 9057              if $kgm_mptr->Type == 6
 9058                printf "RT_data   "
 9059              end
 9060              if $kgm_mptr->Type == 7
 9061                printf "Convention"
 9062              end
 9063              if $kgm_mptr->Type == 8
 9064                printf "Unusable  "
 9065              end
 9066              if $kgm_mptr->Type == 9
 9067                printf "ACPI_recl "
 9068              end
 9069              if $kgm_mptr->Type == 10
 9070                printf "ACPI_NVS  "
 9071              end
 9072              if $kgm_mptr->Type == 11
 9073                printf "MemMapIO  "
 9074              end
 9075              if $kgm_mptr->Type == 12
 9076                printf "MemPortIO "
 9077              end
 9078              if $kgm_mptr->Type == 13
 9079                printf "PAL_code  "
 9080              end
 9081              if $kgm_mptr->Type > 13
 9082                printf "UNKNOWN   "
 9083              end
 9084 
 9085              printf " %016llx %016llx", $kgm_mptr->PhysicalStart, $kgm_mptr->NumberOfPages
 9086              if $kgm_mptr->VirtualStart != 0
 9087                printf " %016llx", $kgm_mptr->VirtualStart
 9088              else
 9089                printf "                 "
 9090              end
 9091              printf " %016llx\n", $kgm_mptr->Attribute
 9092              set $kgm_i = $kgm_i + 1
 9093        end
 9094 end
 9095 
 9096 document showbootermemorymap
 9097 Syntax: (gdb) showbootermemorymap
 9098 | Prints out the phys memory map from kernelBootArgs
 9099 end
 9100 
 9101 
 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
 9107         showtaskheader
 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
 9112             showactheader
 9113             if ($decode_wait_events > 0)
 9114                showactint $kgm_actp 1
 9115             else
 9116                showactint $kgm_actp 2
 9117             end
 9118             set $kgm_actp = (struct thread *)($kgm_actp->task_threads.next)
 9119         end
 9120         printf "\n"
 9121         set $kgm_taskp = (struct task *)($kgm_taskp->tasks.next)
 9122     end
 9123 end
 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.
 9128 end
 9129 
 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)
 9135         printf "service   "
 9136         showptrhdrpad
 9137         printf "  ps  ms  wr  name\n"
 9138         showptr $kgm_pm_wqe->Owner
 9139         printf "  "
 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
 9144         printf "request   "
 9145         showptrhdrpad
 9146         printf "  type  next      "
 9147         showptrhdrpad
 9148         printf "  root      "
 9149         showptrhdrpad
 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)
 9154             showptr $kgm_pm_rqe
 9155             printf "  0x%02x  ", $kgm_pm_rqe->fType
 9156             showptr $kgm_pm_rqe->fRequestNext
 9157             printf "  "
 9158             showptr $kgm_pm_rqe->fRequestRoot
 9159             printf "  0x%08x  0x%08x\n", $kgm_pm_rqe->fWorkWaitCount, $kgm_pm_rqe->fFreeWaitCount
 9160             showptrhdrpad
 9161             printf "            args  "
 9162             showptr $kgm_pm_rqe->fArg0
 9163             printf "  "
 9164             showptr $kgm_pm_rqe->fArg1
 9165             printf "  "
 9166             showptr $kgm_pm_rqe->fArg2
 9167             printf "\n"
 9168             set $kgm_pm_rqe = (IOPMRequest *)$kgm_pm_rqe->fCommandChain.next
 9169         end
 9170         printf "\n"
 9171         set $kgm_pm_wqe = (IOServicePM *)$kgm_pm_wqe->WorkChain.next
 9172     end
 9173 end
 9174 
 9175 define showpmworkqueue
 9176     printf "IOPMWorkQueue "
 9177     showptr gIOPMWorkQueue
 9178     printf " length "
 9179     printf "%u", gIOPMWorkQueue->fQueueLength
 9180     printf "\n"
 9181     if (gIOPMWorkQueue->fQueueLength > 0)
 9182         showpmworkqueueint gIOPMWorkQueue
 9183     end
 9184 end
 9185 
 9186 document showpmworkqueue
 9187 Syntax: (gdb) showpmworkqueue
 9188 | Display the IOPMWorkQueue object
 9189 end
 9190 
 9191 define showioservicepm
 9192     set $kgm_iopmpriv = (IOServicePM *)$arg0
 9193     printf "{ "
 9194     printf "MachineState = %d (", $kgm_iopmpriv->MachineState
 9195     if ( $kgm_iopmpriv->MachineState == 0 )
 9196         printf "kIOPM_Finished"
 9197     else
 9198     if ( $kgm_iopmpriv->MachineState == 1 )
 9199         printf "kIOPM_OurChangeTellClientsPowerDown"
 9200     else
 9201     if ( $kgm_iopmpriv->MachineState == 2 )
 9202         printf "kIOPM_OurChangeTellPriorityClientsPowerDown"
 9203     else
 9204     if ( $kgm_iopmpriv->MachineState == 3 )
 9205         printf "kIOPM_OurChangeNotifyInterestedDriversWillChange"
 9206     else
 9207     if ( $kgm_iopmpriv->MachineState == 4 )
 9208         printf "kIOPM_OurChangeSetPowerState"
 9209     else
 9210     if ( $kgm_iopmpriv->MachineState == 5 )
 9211         printf "kIOPM_OurChangeWaitForPowerSettle"
 9212     else
 9213     if ( $kgm_iopmpriv->MachineState == 6 )
 9214         printf "kIOPM_OurChangeNotifyInterestedDriversDidChange"
 9215     else
 9216     if ( $kgm_iopmpriv->MachineState == 7 )
 9217         printf "kIOPM_OurChangeTellCapabilityDidChange"
 9218     else
 9219     if ( $kgm_iopmpriv->MachineState == 8 )
 9220         printf "kIOPM_OurChangeFinish"
 9221     else
 9222     if ( $kgm_iopmpriv->MachineState == 9 )
 9223         printf "Unused_MachineState_9"
 9224     else
 9225     if ( $kgm_iopmpriv->MachineState == 10 )
 9226         printf "kIOPM_ParentChangeTellPriorityClientsPowerDown"
 9227     else
 9228     if ( $kgm_iopmpriv->MachineState == 11 )
 9229         printf "kIOPM_ParentChangeNotifyInterestedDriversWillChange"
 9230     else
 9231     if ( $kgm_iopmpriv->MachineState == 12 )
 9232         printf "kIOPM_ParentChangeSetPowerState"
 9233     else
 9234     if ( $kgm_iopmpriv->MachineState == 13 )
 9235         printf "kIOPM_ParentChangeWaitForPowerSettle"
 9236     else
 9237     if ( $kgm_iopmpriv->MachineState == 14)
 9238         printf "kIOPM_ParentChangeNotifyInterestedDriversDidChange"
 9239     else
 9240     if ( $kgm_iopmpriv->MachineState == 15)
 9241         printf "kIOPM_ParentChangeTellCapabilityDidChange"
 9242     else
 9243     if ( $kgm_iopmpriv->MachineState == 16)
 9244         printf "kIOPM_ParentChangeAcknowledgePowerChange"
 9245     else
 9246     if ( $kgm_iopmpriv->MachineState == 17)
 9247         printf "kIOPM_NotifyChildrenStart"
 9248     else
 9249     if ( $kgm_iopmpriv->MachineState == 18)
 9250         printf "kIOPM_NotifyChildrenOrdered"
 9251     else
 9252     if ( $kgm_iopmpriv->MachineState == 19)
 9253         printf "kIOPM_NotifyChildrenDelayed"
 9254     else
 9255     if ( $kgm_iopmpriv->MachineState == 20)
 9256         printf "kIOPM_SyncTellClientsPowerDown"
 9257     else
 9258     if ( $kgm_iopmpriv->MachineState == 21)
 9259         printf "kIOPM_SyncTellPriorityClientsPowerDown"
 9260     else
 9261     if ( $kgm_iopmpriv->MachineState == 22)
 9262         printf "kIOPM_SyncNotifyWillChange"
 9263     else
 9264     if ( $kgm_iopmpriv->MachineState == 23)
 9265         printf "kIOPM_SyncNotifyDidChange"
 9266     else
 9267     if ( $kgm_iopmpriv->MachineState == 24)
 9268         printf "kIOPM_SyncTellCapabilityDidChange"
 9269     else
 9270     if ( $kgm_iopmpriv->MachineState == 25)
 9271         printf "kIOPM_SyncFinish"
 9272     else
 9273     if ( $kgm_iopmpriv->MachineState == 26)
 9274         printf "kIOPM_TellCapabilityChangeDone"
 9275     else
 9276     if ( $kgm_iopmpriv->MachineState == 27)
 9277         printf "kIOPM_DriverThreadCallDone"
 9278     else
 9279         printf "Unknown_MachineState"
 9280     end
 9281     end
 9282     end
 9283     end
 9284     end
 9285     end
 9286     end
 9287     end
 9288     end
 9289     end
 9290     end
 9291     end
 9292     end
 9293     end
 9294     end
 9295     end
 9296     end
 9297     end
 9298     end
 9299     end
 9300     end
 9301     end
 9302     end
 9303     end
 9304     end
 9305     end
 9306     end
 9307         end
 9308         printf "), "
 9309         
 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
 9315         end
 9316 
 9317     if ( $kgm_iopmpriv->DeviceOverrideEnabled != 0 )
 9318         printf"DeviceOverrides, "
 9319     end
 9320         
 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
 9324 end
 9325 
 9326 document showioservicepm
 9327 Syntax: (gdb) showioservicepm <IOServicePM pointer>
 9328 | Routine to dump the IOServicePM object
 9329 end
 9330 
 9331 define showregistryentryrecursepmstate
 9332     set $kgm_re         = (IOService *)$arg1
 9333     set $kgm$arg0_stack = (unsigned long long) $arg2
 9334 
 9335     if ($arg3)
 9336         set $kgm$arg0_stack = $kgm$arg0_stack | (1ULL << $kgm_reg_depth)
 9337     else
 9338         set $kgm$arg0_stack = $kgm$arg0_stack & ~(1ULL << $kgm_reg_depth)
 9339     end
 9340 
 9341     dictget $kgm_re->fRegistryTable $kgm_childkey
 9342     set $kgm$arg0_child_array = (OSArray *) $kgm_result
 9343 
 9344     if ($kgm$arg0_child_array)
 9345         set $kgm$arg0_child_count = $kgm$arg0_child_array->count
 9346     else
 9347         set $kgm$arg0_child_count = 0
 9348     end
 9349 
 9350     if ($kgm$arg0_child_count)
 9351         set $kgm$arg0_stack = $kgm$arg0_stack | (2ULL << $kgm_reg_depth)
 9352     else
 9353         set $kgm$arg0_stack = $kgm$arg0_stack & ~(2ULL << $kgm_reg_depth)
 9354     end
 9355 
 9356     indent $kgm_reg_depth $kgm$arg0_stack
 9357     printf "+-o "
 9358 
 9359     dictget $kgm_re->fRegistryTable $kgm_namekey
 9360     if ($kgm_result == 0)
 9361         dictget $kgm_re->fRegistryTable gIONameKey
 9362     end
 9363     if ($kgm_result == 0)
 9364         dictget $kgm_re->fPropertyTable gIOClassKey
 9365     end
 9366 
 9367     if ($kgm_result != 0)
 9368         printf "%s <%p>", ((OSString *)$kgm_result)->string, $kgm_re
 9369     else
 9370         if (((IOService*)$kgm_re)->pwrMgt &&  ((IOService*)$kgm_re)->pwrMgt->Name)
 9371             printf "%s <", ((IOService*)$kgm_re)->pwrMgt->Name
 9372             showptr $kgm_re
 9373             printf ">"
 9374         else
 9375             printf "?? <"
 9376             showptr $kgm_re
 9377             printf ">"
 9378         end
 9379     end
 9380 
 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
 9385     end
 9386     printf "\n"
 9387    
 9388 
 9389     # recurse
 9390     if ($kgm$arg0_child_count != 0)
 9391 
 9392         set $kgm_reg_depth = $kgm_reg_depth + 1
 9393         set $kgm$arg0_child_idx = 0
 9394 
 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
 9399                loop_break
 9400             end
 9401             showregistryentryrecursepmstate _$arg0 $kgm_re $kgm$arg0_stack $kgm_more_sib
 9402         end
 9403 
 9404         set $kgm_reg_depth = $kgm_reg_depth - 1
 9405     end
 9406 end
 9407 
 9408 define showregistryentryintpmstate
 9409     if !$kgm_reg_plane
 9410        set $kgm_reg_plane = (IORegistryPlane *) gIOServicePlane
 9411     end
 9412 
 9413     if !$kgm_reg_plane
 9414        printf "Please load kgmacros after KDP attaching to the target.\n"
 9415     else
 9416        set $kgm_namekey   = (OSSymbol *) $kgm_reg_plane->nameKey
 9417        set $kgm_childkey  = (OSSymbol *) $kgm_reg_plane->keys[1]
 9418        showregistryentryrecursepmstate _ $arg0 0 0
 9419     end
 9420 end
 9421 
 9422 define showregistrypmstate
 9423 #    setregistryplane gIOPowerPlane
 9424     set $kgm_reg_depth  = 0
 9425     set $kgm_show_props = 1
 9426     showregistryentryintpmstate gRegistryRoot
 9427 end
 9428 
 9429 document showregistrypmstate
 9430 Syntax: (gdb) showregistrypmstate
 9431 | Routine to dump the PM state of each IOPower registry entry
 9432 end
 9433 
 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
 9440         showtaskheader
 9441         showtaskint $kgm_taskp
 9442         set $kgm_head_actp = &($kgm_taskp->threads)
 9443         if $kgm_actp == 0
 9444             set $kgm_actp = (struct thread *)($kgm_taskp->threads.next)
 9445         end
 9446         while $kgm_actp != $kgm_head_actp
 9447             showactheader
 9448             if ($decode_wait_events > 0)
 9449                showactint $kgm_actp 1
 9450             else
 9451                showactint $kgm_actp 2
 9452             end
 9453             set $kgm_actp = (struct thread *)($kgm_actp->task_threads.next)
 9454         end
 9455         printf "\n"
 9456         set $kgm_taskp = (struct task *)($kgm_taskp->tasks.next)
 9457         set $kgm_actp = 0
 9458     end
 9459 end
 9460 
 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.
 9465 end
 9466 
 9467 define kdp-reenter
 9468        set kdp_reentry_deadline = ((unsigned) $arg0)*1000
 9469        continue
 9470 end
 9471 
 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.
 9476 end
 9477 
 9478 define _if_present
 9479     if (!$arg0)
 9480         printf " not"
 9481     end
 9482     printf " present"
 9483 end
 9484 
 9485 define showMCAstate
 9486     if (($kgm_mtype & $kgm_mtype_x86_mask) != $kgm_mtype_x86_any)
 9487         printf "Not available for current architecture.\n"
 9488     else
 9489         printf "MCA"
 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
 9498         set $kgm_cpu = 0
 9499         while cpu_data_ptr[$kgm_cpu] != 0
 9500             set $kgm_mcp = cpu_data_ptr[$kgm_cpu]->cpu_mca_state
 9501             if $kgm_mcp
 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
 9505                 printf "bank   "
 9506                 printf "mca_mci_ctl        "
 9507                 printf "mca_mci_status     "
 9508                 printf "mca_mci_addr       "
 9509                 printf "mca_mci_misc\n"
 9510                 set $kgm_bank = 0
 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
 9519                 end
 9520             end
 9521             set $kgm_cpu = $kgm_cpu + 1
 9522         end
 9523     end
 9524 end
 9525 
 9526 document showMCAstate
 9527 Syntax: showMCAstate
 9528 | Print machine-check register state after MC exception.
 9529 end
 9530 
 9531 define _pt_step
 9532     #
 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)
 9536     # returns
 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
 9540     #                  should be aborted
 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
 9546     #
 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
 9556         end
 9557     end
 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
 9566             else
 9567                 set $kgm_pt_large = 0
 9568                 set $kgm_pt_paddr = $entry & $kgm_paddr_mask
 9569             end     
 9570         else
 9571             set $kgm_pt_valid = 0
 9572             set $kgm_pt_large = 0
 9573             set $kgm_pt_paddr = 0
 9574         end
 9575     else
 9576         printf "0x%016llx:\n\t0x%016llx\n\t", $kgm_entryp, $entry
 9577         if $entry & (0x1 << 0)
 9578             printf "valid"      
 9579             set $kgm_pt_paddr = $entry & $kgm_paddr_mask
 9580             set $kgm_pt_valid = 1
 9581         else
 9582             printf "invalid"
 9583             set $kgm_pt_paddr = 0
 9584             set $kgm_pt_valid = 0
 9585             # stop decoding other bits
 9586             set $entry = 0
 9587         end
 9588         if $entry & (0x1 << 1)
 9589             printf " writeable" 
 9590         else
 9591             printf " read-only" 
 9592         end
 9593         if $entry & (0x1 << 2)
 9594             printf " user" 
 9595         else
 9596             printf " supervisor" 
 9597         end
 9598         if $entry & (0x1 << 3)
 9599             printf " PWT" 
 9600         end
 9601         if $entry & (0x1 << 4)
 9602             printf " PCD" 
 9603         end
 9604         if $entry & (0x1 << 5)
 9605             printf " accessed" 
 9606         end
 9607         if $entry & (0x1 << 6)
 9608             printf " dirty" 
 9609         end
 9610         if $entry & (0x1 << 7)
 9611             printf " large" 
 9612             set $kgm_pt_large = 1
 9613         else
 9614             set $kgm_pt_large = 0
 9615         end
 9616         if $entry & (0x1 << 8)
 9617             printf " global" 
 9618         end
 9619         if $entry & (0x3 << 9)
 9620             printf " avail:0x%x", ($entry >> 9) & 0x3
 9621         end
 9622         if $entry & (0x1ULL << 63)
 9623             printf " noexec" 
 9624         end
 9625         printf "\n"
 9626     end
 9627 end
 9628 
 9629 define _pml4_walk
 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
 9641         end
 9642         _pt_step
 9643     end
 9644     if $kgm_pt_valid
 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
 9650         end
 9651         _pt_step
 9652     end
 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
 9659         end
 9660         _pt_step
 9661     end
 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
 9668         end
 9669         _pt_step
 9670     end
 9671 
 9672     if $kgm_pt_valid
 9673         set $kgm_paddr = $kgm_pt_paddr + $kgm_pframe_offset
 9674         set $kgm_paddr_isvalid = 1
 9675     else
 9676         set $kgm_paddr = 0
 9677         set $kgm_paddr_isvalid = 0
 9678     end
 9679 
 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
 9685         else
 9686             printf "(no translation)\n"
 9687         end
 9688     end
 9689 end
 9690 
 9691 define _pmap_walk_x86
 9692     set $kgm_pmap = (pmap_t) $arg0
 9693     _pml4_walk $kgm_pmap->pm_cr3 $arg1
 9694 end
 9695 
 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
 9700 
 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
 9705     else
 9706         set $kgm_paddr = ($kgm_tte & 0xFFF00000) | ($kgm_vaddr & 0x000FFFFF)
 9707         set $kgm_paddr_isvalid = 1
 9708     end
 9709 
 9710     if $kgm_pt_verbose >= 2
 9711         printf "0x%08x\n\t0x%08x\n\t", (unsigned long)$kgm_tte_p, $kgm_tte
 9712 
 9713         # bit [1:0] evaluated in _pmap_walk_arm
 9714 
 9715         # B bit 2
 9716         set $kgm_b_bit = (($kgm_tte & 0x00000004) >> 2)
 9717 
 9718         # C bit 3
 9719         set $kgm_c_bit = (($kgm_tte & 0x00000008) >> 3)
 9720 
 9721         # XN bit 4
 9722         if ($kgm_tte & 0x00000010)
 9723             printf "no-execute" 
 9724         else
 9725             printf "execute" 
 9726         end
 9727 
 9728         # Domain bit [8:5] if not supersection
 9729         if (($kgm_tte & 0x00040000) == 0x00000000)
 9730             printf " domain(%d)", (($kgm_tte & 0x000001e0) >> 5)
 9731         end
 9732 
 9733         # IMP bit 9
 9734         printf " imp(%d)", (($kgm_tte & 0x00000200) >> 9) 
 9735 
 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)
 9739             printf " noaccess"
 9740         end
 9741         if ($kgm_access == 0x1)
 9742             printf " supervisor(readwrite) user(noaccess)"
 9743         end
 9744         if ($kgm_access == 0x2)
 9745             printf " supervisor(readwrite) user(readonly)"
 9746         end
 9747         if ($kgm_access == 0x3)
 9748             printf " supervisor(readwrite) user(readwrite)"
 9749         end
 9750         if ($kgm_access == 0x4)
 9751             printf " noaccess(reserved)"
 9752         end
 9753         if ($kgm_access == 0x5)
 9754             printf " supervisor(readonly) user(noaccess)"
 9755         end
 9756         if ($kgm_access == 0x6)
 9757             printf " supervisor(readonly) user(readonly)"
 9758         end
 9759         if ($kgm_access == 0x7)
 9760             printf " supervisor(readonly) user(readonly)"
 9761         end
 9762 
 9763         # TEX bit [14:12]
 9764         set $kgm_tex_bits = (($kgm_tte & 0x00007000) >> 12)
 9765 
 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
 9768 
 9769         # S bit 16
 9770         if ($kgm_tte & 0x00010000)
 9771             printf " shareable" 
 9772         else
 9773             printf " not-shareable" 
 9774         end
 9775 
 9776         # nG bit 17
 9777         if ($kgm_tte & 0x00020000)
 9778             printf " not-global"
 9779         else
 9780             printf " global" 
 9781         end
 9782 
 9783         # Supersection bit 18
 9784         if ($kgm_tte & 0x00040000)
 9785             printf " supersection"
 9786         else
 9787             printf " section" 
 9788         end
 9789 
 9790         # NS bit 19
 9791         if ($kgm_tte & 0x00080000)
 9792             printf " no-secure"
 9793         else
 9794             printf " secure" 
 9795         end
 9796 
 9797         printf "\n"
 9798     end
 9799 end
 9800 
 9801 define _pmap_walk_arm_level2
 9802     set $kgm_tte_p = $arg0
 9803     set $kgm_tte = *$kgm_tte_p
 9804     set $kgm_vaddr = $arg1
 9805 
 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
 9810 
 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
 9814 
 9815         # bit [1:0] evaluated in _pmap_walk_arm
 9816 
 9817         # NS bit 3
 9818         if ($kgm_tte & 0x00000008)
 9819             printf "no-secure"
 9820         else
 9821             printf "secure" 
 9822         end
 9823 
 9824         # Domain bit [8:5]
 9825         printf " domain(%d)", (($kgm_tte & 0x000001e0) >> 5)
 9826 
 9827         # IMP bit 9
 9828         printf " imp(%d)", (($kgm_tte & 0x00000200) >> 9) 
 9829 
 9830         printf "\n"
 9831     end
 9832 
 9833     if $kgm_pt_verbose >= 2
 9834         printf "second-level table (index %d):\n", $kgm_pte_index
 9835     end
 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
 9842         end
 9843     end
 9844 
 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
 9851         else
 9852             set $kgm_paddr = (*$kgm_pte_p & 0xFFFFF000) | ($kgm_vaddr & 0xFFF)
 9853             set $kgm_paddr_isvalid = 1
 9854         end
 9855     else
 9856         set $kgm_paddr = 0
 9857         set $kgm_paddr_isvalid = 0
 9858     end
 9859 
 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)
 9863             printf "invalid" 
 9864         else
 9865             if (($kgm_pte & 0x00000003) == 0x00000001)
 9866                 printf "large"
 9867 
 9868                 # XN bit 15
 9869                 if ($kgm_pte & 0x00008000) == 0x00008000
 9870                     printf " no-execute"
 9871                 else
 9872                     printf " execute"
 9873                 end
 9874             else
 9875                 printf "small"
 9876 
 9877                 # XN bit 0
 9878                 if ($kgm_pte & 0x00000001) == 0x00000001
 9879                     printf " no-execute"
 9880                 else
 9881                     printf " execute"
 9882                 end
 9883             end
 9884 
 9885             # B bit 2
 9886             set $kgm_b_bit = (($kgm_pte & 0x00000004) >> 2)
 9887 
 9888             # C bit 3
 9889             set $kgm_c_bit = (($kgm_pte & 0x00000008) >> 3)
 9890 
 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)
 9894                 printf " noaccess"
 9895             end
 9896             if ($kgm_access == 0x1)
 9897                 printf " supervisor(readwrite) user(noaccess)"
 9898             end
 9899             if ($kgm_access == 0x2)
 9900                 printf " supervisor(readwrite) user(readonly)"
 9901             end
 9902             if ($kgm_access == 0x3)
 9903                 printf " supervisor(readwrite) user(readwrite)"
 9904             end
 9905             if ($kgm_access == 0x4)
 9906                 printf " noaccess(reserved)"
 9907             end
 9908             if ($kgm_access == 0x5)
 9909                 printf " supervisor(readonly) user(noaccess)"
 9910             end
 9911             if ($kgm_access == 0x6)
 9912                 printf " supervisor(readonly) user(readonly)"
 9913             end
 9914             if ($kgm_access == 0x7)
 9915                 printf " supervisor(readonly) user(readonly)"
 9916             end
 9917 
 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)
 9921             else
 9922                 set $kgm_tex_bits = (($kgm_pte & 0x000001c0) >> 6)
 9923             end
 9924 
 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
 9927 
 9928             # S bit 10
 9929             if ($kgm_pte & 0x00000400)
 9930                 printf " shareable" 
 9931             else
 9932                 printf " not-shareable" 
 9933             end
 9934 
 9935             # nG bit 11
 9936             if ($kgm_pte & 0x00000800)
 9937                 printf " not-global"
 9938             else
 9939                 printf " global"