]> git.saurik.com Git - apple/xnu.git/blobdiff - kgmacros
xnu-2050.48.11.tar.gz
[apple/xnu.git] / kgmacros
index 5a4897abd126ed409b3bdf05d32e40c0bb095203..6a12bb11cee59600f00a8d4c00f1c7b762829254 100644 (file)
--- a/kgmacros
+++ b/kgmacros
@@ -1,3 +1,4 @@
+
 # Kernel gdb macros
 #
 #  These gdb macros should be useful during kernel development in
@@ -38,9 +39,12 @@ document kgm
 |     showallvm      Display a summary listing of all the vm maps
 |     showallvme     Display a summary listing of all the vm map entries
 |     showallipc     Display a summary listing of all the ipc spaces
+|     showipcsummary     Display a summary listing of the ipc spaces of all tasks
 |     showallrights  Display a summary listing of all the ipc rights
-|     showallkmods   Display a summary listing of all the kernel modules
-|     showallbusyports     Display a listing of all ports with unread messages
+|     showallkexts   Display a summary listing of all loaded kexts (alias: showallkmods)
+|     showallknownkexts   Display a summary listing of all kexts, loaded or not
+|     showallbusyports    Display a listing of all ports with unread messages
+|     showallprocessors   Display a listing of all psets and processors
 |
 |     showallclasses    Display info about all OSObject subclasses in the system
 |     showobject        Show info about an OSObject - its vtable ptr and retain count, & more info for simple container classes.
@@ -82,13 +86,14 @@ document kgm
 |     showprocfiles  Given a proc_t pointer, display the list of open file descriptors
 |     showproclocks  Given a proc_t pointer, display the list of advisory file locks
 |     zombproc       Print out all procs in the zombie list
+|     showproctree   Show all the processes in a hierarchical tree form
 |     allproc        Print out all process in the system not in the zombie list
 |     zombstacks     Print out all stacks of tasks that are exiting
 |
 |     showinitchild  Print out all processes in the system which are children of init process
 |
-|     showkmod      Display info about a kernel module
-|     showkmodaddr   Given an address, display the kernel module and offset
+|     showkext      Display info about a kext (alias: showkmod)
+|     showkextaddr   Given an address, display the kext and offset (alias: showkmodaddr)
 |
 |     dumpcallqueue  Dump out all the entries given a queue head
 |
@@ -103,6 +108,9 @@ document kgm
 |     switchtoctx    Switch to different context
 |     showuserstack  Display numeric backtrace of the user stack for an 
 |                   activation
+|     showtaskuserstacks        Display user stacks for a specified task
+|     showuserregisters                 Display user registers for the specified thread
+|     showtaskuserregisters             Display user registers for the specified task
 |
 |     switchtouserthread Switch to the user context of the specified thread
 |     resetstacks    Return to the original kernel context
@@ -145,6 +153,21 @@ document kgm
 |
 |     inifa_showdbg  Print the debug information of an IPv4 interface address
 |     in6ifa_showdbg Print the debug information of an IPv6 interface address
+|     inm_showdbg    Print the debug information of an IPv4 multicast address
+|     ifma_showdbg   Print the debug information of a link multicast address
+|     ifpref_showdbg Print the debug information of an interface ref count
+|
+|     ndpr_showdbg   Print the debug information of a nd_prefix structure
+|     nddr_showdbg   Print the debug information of a nd_defrouter structure
+|
+|     imo_showdbg    Print the debug information of a ip_moptions structure
+|     im6o_showdbg   Print the debug information of a ip6_moptions structure
+|
+|     inifa_trash    Walk the list of trash in_ifaddr entries
+|     in6ifa_trash   Walk the list of trash in6_ifaddr entries
+|     inm_trash      Walk the list of trash in_multi entries
+|     in6m_trash     Walk the list of trash in6_multi entries
+|     ifma_trash     Walk the list of trash ifmultiaddr entries
 |
 |     mbuf_walkpkt   Walk the mbuf packet chain (m_nextpkt)
 |     mbuf_walk      Walk the mbuf chain (m_next)
@@ -157,6 +180,9 @@ document kgm
 |     mbuf_slabs     Print all slabs in the group
 |     mbuf_slabstbl  Print slabs table
 |     mbuf_stat      Print extended mbuf allocator statistics
+|     mbuf_countchain   Count the length of an mbuf chain
+|     mbuf_topleak   Print the top suspected mbuf leakers
+|     mbuf_traceleak Print the leak information for a given leak address
 |
 |     mcache_walkobj     Walk the mcache object chain (obj_next)
 |     mcache_stat        Print all mcaches in the system
@@ -188,8 +214,11 @@ document kgm
 |     shownewvnodes      Print the new vnode list
 |
 |     ifconfig           display ifconfig-like output
+|     showifnets         show the list of attached and detached interfaces
 |     showifaddrs        show the list of addresses for the given ifp
 |     showifmultiaddrs   show the list of multicast addresses for the given ifp
+|     showinmultiaddrs   show the list of IPv4 multicast addresses records 
+|     showin6multiaddrs  show the list of IPv6 multicast addresses records
 |
 |     showsocket         Display information about a socket
 |     showprocsockets    Given a proc_t pointer, display information about its sockets
@@ -202,7 +231,7 @@ document kgm
 |     show_rt_inet       Display the IPv4 routing table
 |     show_rt_inet6      Display the IPv6 routing table
 |
-|     showallpmworkqueues   Display info about all IOPMWorkQueue objects
+|     showpmworkqueue       Display the IOPMWorkQueue object
 |     showregistrypmstate   Display power management state for all IOPower registry entries
 |     showioservicepm       Display the IOServicePM object
 |     showstacksaftertask   showallstacks starting after a given task
@@ -214,19 +243,39 @@ document kgm
 |     showallgdbcorestacks Corefile equivalent of "showallgdbstacks"
 |     kdp-reenter      Schedule reentry into the debugger and continue.
 |     kdp-reboot       Restart remote target
-|     kdp-version      Get KDP version number
-|     kdp-connect      "shorthand" connection macro
+|     kdp-version       Get KDP version number
 |
 |     zstack           Print zalloc caller stack (zone leak debugging)
 |     findoldest       Find oldest zone leak debugging record
 |     countpcs         Print how often a pc occurs in the zone leak log
 |
+|     showtopztrace     Print the ztrace with the most outstanding allocated memory
+|     showztrace               Print a backtrace record given its index
+|     showzalloc           Print an allocation record + stacktrace at index
+|     showztraceaddr    Print a backtrace record given its address
+|     showztracesabove  Print all the backtrace records with a size bigger than X
+|     showzstacktrace   Symbolicate and print a stored OSBacktrace
+|     
+|     showztraces       Finds all in-use traces in the ztraces table
+|     showzallocs       Finds all in-use allocations in the zallocs table
+|     showzstats        Shows the statistics gathered about the hash tables
+|
+|     showzallocsfortrace   Print all the allocations that refer to a trace
+|     showztracehistogram   Prints a histogram of the ztraces table
+|     showzallochistogram   Prints a histogram of the zallocs table    
+|
 |     pmap_walk     Perform a page-table walk
 |     pmap_vtop     Translate a virtual address to physical address
 |
-|     showuserlibraries      Show binary images known by dyld in the target task
+|     showuserdyldinfo       Show dyld information and error messages
+|                            in the target task
+|     showuserlibraries      Show binary images known by dyld in the
+|                            target task
+|     showallvmstats   Prints a summary of vm statistics in a table format
+|     memstats                 Displays memory statistics in a table format
 |
-|     showthreadfortid Displays the address of the thread structure for a given thread_id value. 
+|     showthreadfortid Displays the address of the thread structure
+|                       for a given thread_id value. 
 |     
 |     strcmp_nomalloc   A version of strcmp that avoids the use of malloc
 |                       through the use of encoded strings created via
@@ -252,6 +301,15 @@ document kgm
 |     ioapic_write32    Write IOAPIC entry
 |     ioapic_dump       Dump IOAPIC entries
 |
+|     showallproviders  Display summary listing of all dtrace_providers
+|     showallmodctls    Display summary listing of all dtrace modctls
+|     showmodctl        Display info about a dtrace modctl
+|     showfbtprobe      Display info about an fbt probe given an id (traverses fbt_probetab)
+|     processortimers   Display all processor timers, noting any inconsistencies
+|        
+|     maplocalcache     Enable local caching in GDB for improved debug speeds
+|     flushlocalcahe    Disable local caching in GDB (deletes all memory regions)
+|
 | Type "help <macro>" for more specific help on a particular macro.
 | Type "show user <macro>" to see what the macro is really doing.
 end
@@ -304,6 +362,10 @@ set $kgm_kdp_pkt_input_off   = $kgm_kdp_pkt_data_len + 4
 set $kgm_kdp_pkt_hostreboot = 0x13
 set $kgm_kdp_pkt_hdr_size   = 8
 
+
+set $kgm_readphys_force_kdp     = 0
+set $kgm_readphys_force_physmap = 0
+
 set $kgm_lcpu_self      = 0xFFFE
 
 set $kgm_reg_depth = 0
@@ -366,8 +428,18 @@ define showptrhdrpad
     end
 end
 
+# Print a userspace pointer, using $kgm_tasp
+define showuserptr
+    set $kgm_userptr_task_64 = ( $kgm_taskp->taskFeatures[0] & 0x80000000)
+    if $kgm_userptr_task_64
+        printf "0x%016llx", $arg0
+    else
+        printf "0x%08x", $arg0
+    end
+end
+
 define showkmodheader
-    printf   "kmod      "
+    printf   "kmod_info "
     showptrhdrpad
     printf "  address   "
     showptrhdrpad
@@ -424,7 +496,6 @@ end
 define showkmodaddr
     showkmodaddrint $arg0
 end
-
 document showkmodaddr
 Syntax: (gdb) showkmodaddr <addr>
 | Given an address, print the offset and name for the kmod containing it
@@ -436,7 +507,15 @@ define showkmod
 end
 document showkmod
 Syntax: (gdb) showkmod <kmod>
-| Routine to print info about a kernel module
+| Routine to print info about a kext
+end
+
+define showkext
+    showkmod $arg0
+end
+document showkext
+Syntax: (gdb) showkext <kmod_info_address>
+| Routine to print info about a kext
 end
 
 define showallkmods
@@ -449,7 +528,108 @@ define showallkmods
 end
 document showallkmods
 Syntax: (gdb) showallkmods
-| Routine to print a summary listing of all the kernel modules
+| Routine to print a summary listing of all loaded kexts
+end
+
+define showallkexts
+    showallkmods
+end
+document showallkexts
+Syntax: (gdb) showallkexts
+| Routine to print a summary listing of all loaded kexts
+end
+
+# See OSKextVersion.c for the C code this is based on
+#
+set $KGM_OSKEXT_VERS_MAJ_MULT   = 100000000
+set $KGM_OSKEXT_VERS_MIN_MULT   = 1000000
+set $KGM_OSKEXT_VERS_REV_MULT   = 10000
+set $KGM_OSKEXT_VERS_STAGE_MULT = 1000
+
+define printoskextversion
+    set $vers_scratch = $arg0
+
+    if ($vers_scratch == -1)
+        printf "(invalid)"
+    else
+     
+        set $vers_major =  $vers_scratch / $KGM_OSKEXT_VERS_MAJ_MULT
+
+        set $vers_scratch = $vers_scratch - ($vers_major * $KGM_OSKEXT_VERS_MAJ_MULT)
+        set $vers_minor = $vers_scratch / $KGM_OSKEXT_VERS_MIN_MULT
+
+        set $vers_scratch = $vers_scratch - ( $vers_minor * $KGM_OSKEXT_VERS_MIN_MULT)
+        set $vers_revision =  $vers_scratch / $KGM_OSKEXT_VERS_REV_MULT
+
+        set $vers_scratch = $vers_scratch - ( $vers_revision * $KGM_OSKEXT_VERS_REV_MULT)
+        set $vers_stage =  $vers_scratch / $KGM_OSKEXT_VERS_STAGE_MULT
+
+        set $vers_scratch = $vers_scratch - ( $vers_stage * $KGM_OSKEXT_VERS_STAGE_MULT)
+        set $vers_stagelevel =  $vers_scratch
+
+        printf "%d.%d", $vers_major, $vers_minor
+        if ($vers_revision > 0)
+            printf ".%d", $vers_revision
+        end
+        
+        if ($vers_stage == 1)
+            printf "d"
+        end
+        if ($vers_stage == 3)
+            printf "a"
+        end
+        if ($vers_stage == 5)
+            printf "b"
+        end
+        if ($vers_stage == 7)
+            printf "fc"
+        end
+        if ($vers_stage == 1 || $vers_stage == 3 || $vers_stage == 5 || $vers_stage == 7)
+            printf "%d", $vers_stagelevel
+        end
+    end
+end
+
+define showallknownkexts
+   set $kext_count = sKextsByID->count
+   set $kext_index = 0
+   printf "%d kexts in sKextsByID:\n", $kext_count
+
+   printf "OSKext *    "
+   showptrhdrpad
+   printf "load_addr   "
+   showptrhdrpad
+   
+   printf " id  name (version)\n"
+
+   while $kext_index < $kext_count
+       set $kext_id = sKextsByID->dictionary[$kext_index].key->string
+       set $oskext = (OSKext *)sKextsByID->dictionary[$kext_index].value
+
+       showptr $oskext
+       printf "  "
+
+       if ($oskext->flags.loaded)
+           showptr $oskext->kmod_info
+           printf "  "
+           printf "%3d", $oskext->loadTag
+       else
+           showptrhdrpad
+           printf " -------- "
+           printf "  "
+           printf " --"
+        end
+        printf "  "
+
+       printf "%.64s (", $kext_id
+       printoskextversion (uint64_t)$oskext->version
+       printf ")\n"
+       set $kext_index = $kext_index + 1
+   end
+end
+document showallknownkexts
+Syntax: (gdb) showallknownkexts
+| Routine to print a summary listing of all kexts, loaded or not
 end
 
 define showactheader
@@ -477,7 +657,7 @@ define showactint
        else
           printf "    "
        end
-       printf "  %7ld   ", $kgm_thread.thread_id
+       printf "  0x%llx   ", $kgm_thread.thread_id
        showptr $kgm_thread.last_processor
        printf "   %3d ", $kgm_thread.sched_pri
        if ($kgm_thread.uthread != 0)
@@ -488,18 +668,36 @@ define showactint
           else
              printf "     "
           end
-          if ($kgm_uthread->uu_iopol_disk == 1)
-             printf "NORM    "
-             set $kgm_printed = 1
+          set $diskpolicy = 0
+          if ($kgm_thread->ext_appliedstate.hw_disk != 0)
+               set $diskpolicy = $kgm_thread->ext_appliedstate.hw_disk
+          else 
+               if ($kgm_thread->appliedstate.hw_disk != 0)
+                       set $diskpolicy = $kgm_thread->appliedstate.hw_disk
+               end
+          end
+          if ($kgm_thread->ext_appliedstate.hw_bg != 0)
+               set $diskpolicy = 5
           end
-          if ($kgm_uthread->uu_iopol_disk == 2)
+          if ($kgm_thread->appliedstate.hw_bg != 0)
+               set $diskpolicy = 4
+          end
+          if ($diskpolicy == 2)
              printf "PASS    "
              set $kgm_printed = 1
            end
-          if ($kgm_uthread->uu_iopol_disk == 3)
+          if ($diskpolicy == 3)
              printf "THROT   "
              set $kgm_printed = 1
           end
+          if ($diskpolicy == 4)
+             printf "BG_THRT "
+             set $kgm_printed = 1
+           end
+          if ($diskpolicy == 5)
+             printf "EBG_THRT"
+             set $kgm_printed = 1
+           end
           if ($kgm_printed == 0)
              printf "        "
           end
@@ -544,8 +742,25 @@ define showactint
                    end
                end
        end
+       if ($kgm_thread.uthread != 0)
+          set $kgm_uthread = (struct uthread *)$kgm_thread.uthread
+          if ($kgm_uthread->pth_name && $kgm_uthread->pth_name[0])
+                  printf "\n\t\tThread Name: %s", $kgm_uthread->pth_name
+          end
+       end
        if $arg1 != 0
            if ($kgm_thread.kernel_stack != 0)
+               if ($kgm_thread.uthread != 0)
+                       printf "\n          "
+                       set $kgm_uthread = (struct uthread *)$kgm_thread.uthread
+                       if ($kgm_uthread->uu_kwe.kwe_kwqqueue != 0)
+                               set $kwq = (ksyn_wait_queue_t)$kgm_uthread->uu_kwe.kwe_kwqqueue
+                               printf "              kwq_lockcount:0x%x; kwq_retval:0x%x", $kgm_uthread->uu_kwe.kwe_lockseq, $kgm_uthread->uu_kwe.kwe_psynchretval
+                               printf "\n                "
+                               show_kwq $kwq
+                               printf "          "
+                       end
+               end
                if ($kgm_thread.reserved_stack != 0)
                        printf "\n          "
                        showptrhdrpad
@@ -589,12 +804,15 @@ define showactint
                        set $stkmask = 0x3
                end
                set $kgm_return = 0
+               set $kgm_actint_framecount = 0
                while ($mysp != 0) && (($mysp & $stkmask) == 0) \
                      && ($mysp != $prevsp) \
-                     && ((((unsigned long) $mysp ^ (unsigned long) $prevsp) < 0x2000) \
+                     && ((((unsigned long) $mysp - (unsigned long) $prevsp) < 0x4000) \
                      || (((unsigned long)$mysp < ((unsigned long) ($kgm_thread->kernel_stack+kernel_stack_size))) \
-                     && ((unsigned long)$mysp > (unsigned long) ($kgm_thread->kernel_stack))))
+                     && ((unsigned long)$mysp > (unsigned long) ($kgm_thread->kernel_stack)))) \
+                     && ($kgm_actint_framecount < 128)
                        printf "\n          "
+                       set $kgm_actint_framecount = $kgm_actint_framecount + 1
                        showptrhdrpad
                        printf "      "
                        showptr $mysp
@@ -680,10 +898,17 @@ Syntax: (gdb) showallthreads
 | Routine to print out info about all threads in the system.
 end
 
+define showprocessorint
+    set $kgm_processor_int = (struct processor *)$arg0
+    printf "Processor "
+    showptr $kgm_processor_int
+    printf " State %d (cpu_id 0x%x)\n", ($kgm_processor_int)->state, ($kgm_processor_int)->cpu_id
+end
+
 define showcurrentthreads
-set $kgm_prp = (struct processor *)processor_list
+    set $kgm_prp = (struct processor *)processor_list
     while $kgm_prp != 0
-       printf "Processor 0x%08x State %d (cpu_id %x)\n", $kgm_prp, ($kgm_prp)->state, ($kgm_prp)->cpu_id
+        showprocessorint $kgm_prp
        if ($kgm_prp)->active_thread != 0
            set $kgm_actp = ($kgm_prp)->active_thread
            showtaskheader
@@ -700,15 +925,192 @@ Syntax: (gdb) showcurrentthreads
 | Routine to print out info about the thread running on each cpu.
 end
 
+
+define _showrunqint
+       set $kgm_runq = (struct run_queue *)$arg0
+       
+       printf "    Priority Run Queue Info: Count %d\n", $kgm_runq->count
+       set $kgm_runq_queue_i = 0
+       set $kgm_runq_queue_count = sizeof($kgm_runq->queues)/sizeof($kgm_runq->queues[0])
+       while $kgm_runq->count && $kgm_runq_queue_i < $kgm_runq_queue_count
+               set $kgm_runq_queue_head = &$kgm_runq->queues[$kgm_runq_queue_i]
+               set $kgm_runq_queue_p = $kgm_runq_queue_head->next
+               if $kgm_runq_queue_p != $kgm_runq_queue_head
+                       set $kgm_runq_queue_this_count = 0
+                       while $kgm_runq_queue_p != $kgm_runq_queue_head
+                               set $kgm_runq_queue_this_count = $kgm_runq_queue_this_count + 1
+                               showtask ((thread_t)$kgm_runq_queue_p)->task
+                               showactstack $kgm_runq_queue_p
+                               set $kgm_runq_queue_p = $kgm_runq_queue_p->next
+                       end
+                       printf "      Queue Priority %3d [", $kgm_runq_queue_i
+                       showptr $kgm_runq_queue_head
+                       printf "] Count %d\n", $kgm_runq_queue_this_count
+               end
+               set $kgm_runq_queue_i = $kgm_runq_queue_i + 1
+       end
+
+end
+
+define _showgrrrint
+       set $kgm_grrr_runq = $arg0
+       
+       printf "    GRRR Info: Count %d Weight %d Current Group ", $kgm_grrr_runq->count, $kgm_grrr_runq->weight
+       showptr $kgm_grrr_runq->current_group
+       printf "\n"
+       set $kgm_grrr_group_i = 0
+       set $kgm_grrr_group_count = sizeof($kgm_grrr_runq->groups)/sizeof($kgm_grrr_runq->groups[0])
+       while $kgm_grrr_runq->count && $kgm_grrr_group_i < $kgm_grrr_group_count
+               set $kgm_grrr_group = &$kgm_grrr_runq->groups[$kgm_grrr_group_i]
+               if $kgm_grrr_group->count > 0
+                       printf "      Group %3d [", $kgm_grrr_group->index
+                       showptr $kgm_grrr_group
+                       printf "] Count %d Weight %d\n", $kgm_grrr_group->count, $kgm_grrr_group->weight
+                       set $kgm_grrr_group_client_head = &$kgm_grrr_group->clients
+                       set $kgm_grrr_group_client = $kgm_grrr_group_client_head->next
+                       while $kgm_grrr_group_client != $kgm_grrr_group_client_head
+                               # showtask ((thread_t)$kgm_grrr_group_client)->task
+                               # showactstack $kgm_grrr_group_client
+                               set $kgm_grrr_group_client = $kgm_grrr_group_client->next
+                       end
+               end
+               set $kgm_grrr_group_i = $kgm_grrr_group_i + 1
+       end
+end
+
+define showallprocessors
+       set $kgm_pset = &pset0
+
+       set $kgm_show_grrr = 0
+       set $kgm_show_priority_runq = 0
+       set $kgm_show_priority_pset_runq = 0
+       set $kgm_show_fairshare_grrr = 0
+       set $kgm_show_fairshare_list = 0
+
+       if _sched_enum == 1
+               set $kgm_show_priority_runq = 1
+               set $kgm_show_fairshare_list = 1
+       end
+       if _sched_enum == 2
+               set $kgm_show_priority_pset_runq = 1
+               set $kgm_show_fairshare_list = 1
+       end
+       if _sched_enum == 4
+               set $kgm_show_grrr = 1
+               set $kgm_show_fairshare_grrr = 1
+       end
+       if _sched_enum == 5
+               set $kgm_show_priority_runq = 1
+               set $kgm_show_fairshare_list = 1
+       end
+       if _sched_enum == 6
+               set $kgm_show_priority_pset_runq = 1
+               set $kgm_show_fairshare_list = 1
+       end
+
+       while $kgm_pset != 0
+               printf "Processor Set "
+               showptr $kgm_pset
+               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
+               printf "  Active Processors:\n"
+               set $kgm_active_queue_head = &($kgm_pset)->active_queue
+               set $kgm_active_elt = $kgm_active_queue_head->next
+               while $kgm_active_elt != $kgm_active_queue_head
+                       set $kgm_processor = (processor_t)$kgm_active_elt
+                       printf "    "
+                       showprocessorint $kgm_processor
+
+                       if $kgm_show_priority_runq
+                               set $kgm_runq = &$kgm_processor->runq
+                               _showrunqint $kgm_runq
+                       end
+                       if $kgm_show_grrr
+                               set $kgm_grrr_runq = &$kgm_processor->grrr_runq
+                               _showgrrrint $kgm_grrr_runq
+                       end
+                       
+                       if $kgm_processor->processor_meta != 0 && $kgm_processor->processor_meta->primary == $kgm_processor
+                               set $kgm_processor_meta_idle_head = &$kgm_processor->processor_meta->idle_queue
+                               set $kgm_processor_meta_idle = $kgm_processor_meta_idle_head->next
+                               while $kgm_processor_meta_idle != $kgm_processor_meta_idle_head
+                                       printf "      Idle Meta Processor: "
+                                       showprocessorint $kgm_processor_meta_idle
+                                       set $kgm_processor_meta_idle = $kgm_processor_meta_idle->next
+                               end
+                       end
+                       
+                       set $kgm_active_elt = $kgm_active_elt->next
+               end
+               printf "  Idle Processors:\n"
+               set $kgm_idle_queue_head = &($kgm_pset)->idle_queue
+               set $kgm_idle_elt = $kgm_idle_queue_head->next
+               while $kgm_idle_elt != $kgm_idle_queue_head
+                       set $kgm_processor = (processor_t)$kgm_idle_elt
+                       printf "    "
+                       showprocessorint $kgm_processor
+                       
+                       if $kgm_processor->processor_meta != 0 && $kgm_processor->processor_meta->primary == $kgm_processor
+                               set $kgm_processor_meta_idle_head = &$kgm_processor->processor_meta->idle_queue
+                               set $kgm_processor_meta_idle = $kgm_processor_meta_idle_head->next
+                               while $kgm_processor_meta_idle != $kgm_processor_meta_idle_head
+                                       printf "      Idle Meta Processor: "
+                                       showprocessorint $kgm_processor_meta_idle
+                                       set $kgm_processor_meta_idle = $kgm_processor_meta_idle->next
+                               end
+                       end
+
+                       set $kgm_idle_elt = $kgm_idle_elt->next
+               end
+
+               if $kgm_show_priority_pset_runq
+                       set $kgm_runq = &$kgm_pset->pset_runq
+                       printf "\n"
+                       _showrunqint $kgm_runq
+               end
+               set $kgm_pset = ($kgm_pset)->pset_list
+       end
+       
+       printf "\n"
+       printf "Realtime Queue Count %d\n", rt_runq.count
+       set $kgm_rt_runq_head = &rt_runq.queue
+       set $kgm_rt_runq = $kgm_rt_runq_head->next
+       while $kgm_rt_runq != $kgm_rt_runq_head
+               showtask ((thread_t)$kgm_rt_runq)->task
+               showact $kgm_rt_runq
+               set $kgm_rt_runq = $kgm_rt_runq->next
+       end
+       
+       printf "\n"
+       if $kgm_show_fairshare_list
+               printf "Fair Share Queue Count %d\n", fs_runq.count
+               set $kgm_fs_runq_head = &fs_runq.queue
+               set $kgm_fs_runq = $kgm_fs_runq_head->next
+               while $kgm_fs_runq != $kgm_fs_runq_head
+                       showtask ((thread_t)$kgm_fs_runq)->task
+                       showact $kgm_fs_runq
+                       set $kgm_fs_runq = $kgm_fs_runq->next
+               end
+       end
+       if $kgm_show_fairshare_grrr
+               printf "Fair Share Queue Count %d\n", fs_grrr_runq.count
+               set $kgm_fs_grrr = &fs_grrr_runq
+               _showgrrrint $kgm_fs_grrr
+       end
+end
+document showallprocessors
+Syntax: (gdb) showallprocessors
+| Routine to print out info about all psets and processors
+end
+
 set $decode_wait_events = 0
 define showallstacks
     set $kgm_head_taskp = &tasks
     set $kgm_taskp = (struct task *)($kgm_head_taskp->next)
     while $kgm_taskp != $kgm_head_taskp
-        showtaskheader
+       showtaskheader
        showtaskint $kgm_taskp
        set $kgm_head_actp = &($kgm_taskp->threads)
-        set $kgm_actp = (struct thread *)($kgm_taskp->threads.next)
+       set $kgm_actp = (struct thread *)($kgm_taskp->threads.next)
        while $kgm_actp != $kgm_head_actp
            showactheader
            if ($decode_wait_events > 0)
@@ -716,11 +1118,14 @@ define showallstacks
            else
               showactint $kgm_actp 2
            end
-           set $kgm_actp = (struct thread *)($kgm_actp->task_threads.next)
-        end
+           set $kgm_actp = (struct thread *)($kgm_actp->task_threads.next)
+       end
        printf "\n"
-       set $kgm_taskp = (struct task *)($kgm_taskp->tasks.next)
+       set $kgm_taskp = (struct task *)($kgm_taskp->tasks.next)
     end
+
+    printf "\nZombie Processes:\n" 
+    zombstacks
 end
 
 document showallstacks
@@ -732,9 +1137,9 @@ Syntax: (gdb) showallstacks
 end
 
 define showcurrentstacks
-set $kgm_prp = processor_list
+    set $kgm_prp = processor_list
     while $kgm_prp != 0
-       printf "Processor 0x%08x State %d (cpu_id %x)\n", $kgm_prp, ($kgm_prp)->state, ($kgm_prp)->cpu_id
+       showprocessorint $kgm_prp
        if ($kgm_prp)->active_thread != 0
            set $kgm_actp = ($kgm_prp)->active_thread
            showtaskheader
@@ -988,6 +1393,93 @@ define showvmint
 end
 
 
+define showmapwiredp
+    set $kgm_mapp = (vm_map_t)$arg0
+    set $kgm_map = *$kgm_mapp
+    set $kgm_head_vmep = &($kgm_mapp->hdr.links)
+    set $kgm_vmep = $kgm_map.hdr.links.next
+    set $kgm_objp_prev = (struct vm_object *)0
+    if $arg1 == 0
+        set $kgm_saw_kernel_obj = 0
+       set $kgm_wired_count = 0
+       set $kgm_objp_print_space = 1
+    else
+       set $kgm_objp_print_space = 0
+    end
+    while (($kgm_vmep != 0) && ($kgm_vmep != $kgm_head_vmep))
+        set $kgm_vme = *$kgm_vmep
+       set $kgm_objp = $kgm_vme.object.vm_object
+       if $kgm_vme.is_sub_map
+           if $arg1 == 0
+               set $kgm_mapp_orig = $kgm_mapp
+               set $kgm_vmep_orig = $kgm_vmep
+               set $kgm_vme_orig = $kgm_vme
+               set $kgm_head_vmep_orig = $kgm_head_vmep
+               printf "\n****"
+               showptr $kgm_objp
+               showmapwiredp $kgm_objp 1
+               set $kgm_vme = $kgm_vme_orig
+               set $kgm_vmep = $kgm_vmep_orig
+               set $kgm_mapp = $kgm_mapp_orig
+               set $kgm_head_vmep = $kgm_head_vmep_orig
+               set $kgm_objp = (struct vm_object *)0
+           else
+               printf "\n????"     
+               showptr $kgm_mapp
+               printf "    "
+               showptr $kgm_vmep
+               set $kgm_objp = (struct vm_object *)0
+               printf "\n"
+           end
+       end
+       if ($kgm_objp == $kgm_objp_prev)
+           set $kgm_objp = (struct vm_object *)0
+       end
+       if $kgm_objp == kernel_object
+          if $kgm_saw_kernel_obj
+              set $kgm_objp = (struct vm_object *)0
+          end
+          set $kgm_saw_kernel_obj = 1
+       end
+       if $kgm_objp && $kgm_objp->wired_page_count
+           if $kgm_objp_print_space == 1
+               printf "    "
+               showptr $kgm_mapp
+           end
+           set $kgm_objp_print_space = 1
+           printf "    "
+           showptr $kgm_vmep
+           printf "  0x%016llx  ", $kgm_vme.links.start
+           printf "%5d", $kgm_vme.alias
+            printf "%6d  ",($kgm_vme.links.end - $kgm_vme.links.start) >> 12
+           showptr $kgm_objp
+           printf "[%3d]", $kgm_objp->ref_count
+           printf "%7d\n", $kgm_objp->wired_page_count
+           set $kgm_wired_count = $kgm_wired_count + $kgm_objp->wired_page_count
+           set $kgm_objp_prev = $kgm_objp
+       end
+        set $kgm_vmep = $kgm_vme.links.next
+    end
+    if $arg1 == 0
+        printf "total wired count = %d\n", $kgm_wired_count
+    end
+end
+
+define showmapwired
+    printf "    map       "
+    showptrhdrpad
+    printf "    entry     "
+    showptrhdrpad
+    printf "  start               alias  #page  object    "
+    showptrhdrpad
+    printf "       wired\n"
+    showmapwiredp $arg0 0
+end
+document showmapwired
+Syntax: (gdb) showmapwired <vm_map>
+| Routine to print out a summary listing of all the entries with wired pages in a vm_map
+end
+
 define showmapvme
        showmapheader
        showvmint $arg0 1
@@ -1044,24 +1536,33 @@ end
 define showipcheader
     printf "ipc_space "
     showptrhdrpad
+    printf "  is_task   "
+    showptrhdrpad
     printf "  is_table  "
     showptrhdrpad
-    printf "  table_next"
+    printf " flags ports  table_next  "
     showptrhdrpad
-    printf " flags tsize  splaytree   splaybase\n"
+    printf "   low_mod   high_mod\n"
 end
 
 define showipceheader
-    printf "            name        object    "
+    printf "            "
+    showptrhdrpad
+    printf "object      "
+    showptrhdrpad
+    showptrhdrpad
+    printf "name        rite urefs  destname    "
     showptrhdrpad
-    printf "  rite urefs  destname    destination\n"
+    printf "destination\n"
 end
 
 define showipceint
     set $kgm_ie = *(ipc_entry_t)$arg0
-    printf "            0x%08x  ", $arg1
+    printf "            "
+    showptrhdrpad
     showptr $kgm_ie.ie_object
-    printf "  "
+    showptrhdrpad
+    printf "  0x%08x  ", $arg1
     if $kgm_ie.ie_bits & 0x00100000
         printf "Dead "
         printf "%5d\n", $kgm_ie.ie_bits & 0xffff
@@ -1085,10 +1586,29 @@ define showipceint
                 printf "  O"
             end
             if $kgm_ie.index.request
-                printf "n"
+                set $kgm_port = (ipc_port_t)$kgm_ie.ie_object
+               set $kgm_requests = $kgm_port->ip_requests
+               set $kgm_req_soright = $kgm_requests[$kgm_ie.index.request].notify.port
+               if $kgm_req_soright
+#                   Armed send-possible notification?
+                   if (uintptr_t)$kgm_req_soright & 0x1
+                       printf "s"
+                    else
+#                       Delayed send-possible notification?
+                       if (uintptr_t)$kgm_req_soright & 0x2
+                           printf "d"
+                       else
+#                           Dead-name notification
+                           printf "n"
+                       end
+                   end     
+               else
+                   printf " "
+               end
             else
                 printf " "
             end
+#           Collision (with tree)?
             if $kgm_ie.ie_bits & 0x00800000
                 printf "c"
            else
@@ -1105,28 +1625,25 @@ define showipcint
     set $kgm_is = *$kgm_isp
     showptr $arg0
     printf "  "
-    showptr $kgm_is.is_table
+    showptr $kgm_is.is_task
     printf "  "
-    showptr $kgm_is.is_table_next
+    showptr $kgm_is.is_table
     printf "  "
-    if $kgm_is.is_growing != 0
-        printf "G"
-    else
-        printf " "
-    end
-    if $kgm_is.is_fast != 0
-        printf "F"
+    if ($kgm_is.is_bits & 0x40000000) == 0
+        printf "A"
     else
         printf " "
     end
-    if $kgm_is.is_active != 0
-        printf "A  "
+    if ($kgm_is.is_bits & 0x20000000) != 0
+        printf "  "
     else
-        printf "   "
+        printf "    "
     end
-    printf "%5d  ", $kgm_is.is_table_size
-    printf "0x%08x  ", $kgm_is.is_tree_total
-    showptr &$kgm_isp->is_tree
+    printf "%5d  ", $kgm_is.is_table_size 
+    showptr $kgm_is.is_table_next
+    printf "  "
+    printf "%10d ", $kgm_is.is_low_mod
+    printf "%10d", $kgm_is.is_high_mod
     printf "\n"
     if $arg1 != 0
         showipceheader
@@ -1138,17 +1655,16 @@ define showipcint
             if $kgm_ie.ie_bits & 0x001f0000
                 set $kgm_name = (($kgm_iindex << 8)|($kgm_ie.ie_bits >> 24))
                 showipceint $kgm_iep $kgm_name
-                if $arg2 != 0 && $kgm_ie.ie_object != 0 && ($kgm_ie.ie_bits & 0x00070000) && ((ipc_port_t) $kgm_ie.ie_object)->ip_callstack[0] != 0
-                    printf "              user bt: "
-                    showportbt $kgm_ie.ie_object $kgm_is.is_task
-                end
+                if $arg2 != 0
+                  if $kgm_ie.ie_object != 0 && ($kgm_ie.ie_bits & 0x00070000) && ((ipc_port_t) $kgm_ie.ie_object)->ip_callstack[0] != 0
+                       printf "              user bt: "
+                       showportbt $kgm_ie.ie_object $kgm_is.is_task
+                   end
+               end
             end
             set $kgm_iindex = $kgm_iindex + 1
             set $kgm_iep = &($kgm_is.is_table[$kgm_iindex])
         end
-        if $kgm_is.is_tree_total
-            printf "Still need to write tree traversal\n"
-        end
     end
     printf "\n"
 end
@@ -1178,8 +1694,8 @@ end
 define showtaskipc
        set $kgm_taskp = (task_t)$arg0
        showtaskheader
-    showipcheader
        showtaskint $kgm_taskp
+        showipcheader
        showipcint $kgm_taskp->itk_space 0 0
 end
 document showtaskipc
@@ -1191,8 +1707,8 @@ end
 define showtaskrights
        set $kgm_taskp = (task_t)$arg0
        showtaskheader
-    showipcheader
        showtaskint $kgm_taskp
+       showipcheader
        showipcint $kgm_taskp->itk_space 1 0
 end
 document showtaskrights
@@ -1203,8 +1719,8 @@ end
 define showtaskrightsbt
        set $kgm_taskp = (task_t)$arg0
        showtaskheader
-    showipcheader
        showtaskint $kgm_taskp
+       showipcheader
        showipcint $kgm_taskp->itk_space 1 1
 end
 document showtaskrightsbt
@@ -1217,8 +1733,8 @@ define showallipc
     set $kgm_cur_taskp = (struct task *)($kgm_head_taskp->next)
     while $kgm_cur_taskp != $kgm_head_taskp
         showtaskheader
-        showipcheader
         showtaskint $kgm_cur_taskp
+        showipcheader
         showipcint $kgm_cur_taskp->itk_space 0 0
        set $kgm_cur_taskp = (struct task *)($kgm_cur_taskp->tasks.next)
     end
@@ -1228,14 +1744,49 @@ Syntax: (gdb) showallipc
 | Routine to print a summary listing of all the ipc spaces
 end
 
+define showipcsumheader
+    printf "task         "
+    showptrhdrpad
+    printf " pid         "
+    printf " #acts         "
+    printf " tsize "
+    printf "command\n"
+end
+
+define showipcsummaryint
+    set $kgm_taskp = (struct task *)$arg0
+    showptr $arg0
+    printf "%7d", ((struct proc *)$kgm_taskp->bsd_info)->p_pid
+    printf "%15d", $kgm_taskp->thread_count
+    printf "%15d", $kgm_cur_taskp->itk_space.is_table_size     
+       printf " %s\n", ((struct proc *)$kgm_taskp->bsd_info)->p_comm
+end
+
+define showipcsummary
+    showipcsumheader
+    set $kgm_head_taskp = &tasks
+    set $kgm_cur_taskp = (struct task *)($kgm_head_taskp->next)
+    while $kgm_cur_taskp != $kgm_head_taskp
+        showipcsummaryint $kgm_cur_taskp
+       set $kgm_cur_taskp = (struct task *)($kgm_cur_taskp->tasks.next)
+    end
+end
+
+document showipcsummary
+Syntax: (gdb) showipcsummary 
+| Summarizes the IPC state of all tasks. This is a convenient way to dump
+| some basic clues about IPC messaging. You can use the output to determine
+| tasks that are candidates for further investigation.
+end
+
 
 define showallrights
     set $kgm_head_taskp = &tasks
     set $kgm_cur_taskp = (struct task *)($kgm_head_taskp->next)
     while $kgm_cur_taskp != $kgm_head_taskp
         showtaskheader
-        showipcheader
         showtaskint $kgm_cur_taskp
+        showipcheader
         showipcint $kgm_cur_taskp->itk_space 1 0
        set $kgm_cur_taskp = (struct task *)($kgm_cur_taskp->tasks.next)
     end
@@ -1261,8 +1812,8 @@ end
 define showtaskvme
        set $kgm_taskp = (task_t)$arg0
        showtaskheader
-       showmapheader
        showtaskint $kgm_taskp
+       showmapheader
        showvmint $kgm_taskp->map 1
 end
 document showtaskvme
@@ -1339,6 +1890,28 @@ Syntax: (gdb) showtaskstacks <task>
 | Routine to print out the stack for each thread in a task.
 end
 
+define showqueue_elems
+       set $queue_head = (struct queue_entry *)($arg0)
+       set $queue = (struct queue_entry *)($queue_head->next)
+    while $queue != $queue_head
+               showptr $queue
+               printf " "
+               set $thread = (struct thread *)$queue
+               set $task = (struct task *)$thread->task
+               set $bsd = (struct proc *)$task->bsd_info
+               set $guy = (char *)$bsd->p_comm
+               showptr $thread
+               printf " "
+               showptr $task
+               printf " "
+               showptr $bsd
+               printf " "
+               showptr $guy
+               #printf "  %s\n", $kgm_procp->p_comm
+               printf "\n"
+       set $queue = (struct queue_entry *)($queue->next)
+    end
+end
 
 define showalltasks
     showtaskheader
@@ -1361,9 +1934,9 @@ Syntax: (gdb) showalltasks
 end
 
 define showprocheader
-    printf "  pid  process     io_policy    wq_state"
+    printf "  pid  process     "
     showptrhdrpad
-    printf "   command\n"
+    printf "io_policy    wq_state   command\n"
 end
 
 define showprocint
@@ -1377,24 +1950,50 @@ define showprocint
        else
           printf "       "
        end
-       if ($kgm_procp->p_iopol_disk == 1)
-          printf "NORM  "
-          set $kgm_printed = 1
+       set $ptask = (struct task *)$kgm_procp->task
+       set $diskpolicy = 0
+       if ($ptask->ext_appliedstate.hw_disk != 0)
+               set $diskpolicy = $ptask->ext_appliedstate.hw_disk
+       else 
+               if ($ptask->appliedstate.hw_disk != 0)
+                       set $diskpolicy = $ptask->appliedstate.hw_disk
+               end
+       end
+       if ($ptask->ext_appliedstate.hw_bg != 0)
+               set $diskpolicy = 5
        end
-       if ($kgm_procp->p_iopol_disk == 2)
-          printf "PASS  "
-          set $kgm_printed = 1
-        end
-       if ($kgm_procp->p_iopol_disk == 3)
-          printf "THROT "
-          set $kgm_printed = 1
+       if ($ptask->appliedstate.hw_bg != 0)
+               set $diskpolicy = 4
+       end
+       if ($ptask->ext_appliedstate.apptype == 2)
+               set $diskpolicy = 6
+       end
+       if ($diskpolicy == 2)
+               printf "PASS    "
+               set $kgm_printed = 1
+       end
+       if ($diskpolicy == 3)
+               printf "THROT   "
+               set $kgm_printed = 1
+       end
+       if ($diskpolicy == 4)
+               printf "BG_THRT "
+               set $kgm_printed = 1
+       end
+       if ($diskpolicy == 5)
+               printf "EBG_THRT"
+               set $kgm_printed = 1
+       end
+       if ($diskpolicy == 6)
+               printf "APD_THRT"
+               set $kgm_printed = 1
        end
        if ($kgm_printed == 0)
           printf "      "
        end
        set $kgm_wqp = (struct workqueue *)$kgm_procp->p_wqptr
        if $kgm_wqp != 0
-          printf "  %2d %2d %2d ", $kgm_wqp->wq_nthreads, $kgm_wqp->wq_thidlecount, $kgm_wqp->wq_itemcount
+          printf "  %2d %2d %2d ", $kgm_wqp->wq_nthreads, $kgm_wqp->wq_thidlecount, $kgm_wqp->wq_reqcount
        else
           printf "           "
        end
@@ -1445,29 +2044,95 @@ document kdb
 end
 
 define showpsetheader
-    printf "portset     waitqueue   recvname    "
-    printf "flags refs  recvname    process\n"
+    printf "portset     "
+    showptrhdrpad
+    printf "waitqueue   "
+    showptrhdrpad
+    showptrhdrpad
+    printf "recvname    flags refs  recvname    "
+    showptrhdrpad
+    printf "process\n"
 end
 
 define showportheader
-    printf "port        mqueue      recvname    "
-    printf "flags refs  recvname    process\n"
+    printf "port        "
+    showptrhdrpad
+    printf "mqueue      "
+    showptrhdrpad
+    showptrhdrpad
+    printf "recvname    flags refs  recvname    "
+    showptrhdrpad
+    printf "dest\n"
 end
 
 define showportmemberheader
-    printf "members     port        recvname    "
-    printf "flags refs  mqueue      msgcount\n"
+    printf "members     "
+    showptrhdrpad
+    printf "port        "
+    showptrhdrpad
+    showptrhdrpad
+    printf "recvname    "
+    printf "flags refs  mqueue      "
+    showptrhdrpad
+    printf "msgcount\n"
 end
 
 define showkmsgheader
-    printf "messages    kmsg        size        "
-    printf "disp msgid  remote-port local-port\n"
+    printf "dest-port   "
+    showptrhdrpad
+    printf "kmsg        "
+    showptrhdrpad
+    showptrhdrpad
+    printf "msgid       "
+    printf "disp  size  "
+    printf "reply-port  "
+    showptrhdrpad
+    printf "source\n"
+end
+
+define showkmsgsrcint
+    set $kgm_kmsgsrchp = ((ipc_kmsg_t)$arg0)->ikm_header
+#    set $kgm_kmsgsrctp = (mach_msg_audit_trailer_t *)((uintptr_t)$kgm_kmsgsrchp + $kgm_kmsgsrchp->msgh_size)
+#    set $kgm_kmsgpid = $kgm_kmsgsrctp->msgh_audit.val[5]
+    set $kgm_kmsgpid = (pid_t)((uint *)((uintptr_t)$kgm_kmsgsrchp + $kgm_kmsgsrchp->msgh_size))[10]
+# compare against a well-known or cached value as this may be slow
+    if ($kgm_kmsgpid == 0)
+       set $kgm_kmsgsrcpid = (pid_t)0
+       set $kgm_kmsgsrcprocp = (struct proc *)kernel_task->bsd_info
+    else 
+       if ($kgm_kmsgpid != $kgm_kmsgsrcpid)
+         set $kgm_kmsgsrchead_taskp = &tasks
+          set $kgm_kmsgsrctaskp = (struct task *)($kgm_kmsgsrchead_taskp->next)
+          while $kgm_kmsgsrctaskp != $kgm_kmsgsrchead_taskp
+             set $kgm_kmsgsrcprocp = (struct proc *)$kgm_kmsgsrctaskp->bsd_info
+             set $kgm_kmsgsrcpid = $kgm_kmsgsrcprocp->p_pid
+             if (($kgm_kmsgsrcprocp != 0) && ($kgm_kmsgsrcprocp->p_pid == $kgm_kmsgpid))
+                 set $kgm_kmsgsrctaskp = $kgm_kmsgsrchead_taskp
+             else
+                 set $kgm_kmsgsrctaskp = (struct task *)($kgm_kmsgsrctaskp->tasks.next)
+             end
+          end
+       end
+    end
+    if ($kgm_kmsgsrcprocp->p_pid == $kgm_kmsgpid)
+       printf "%s(%d)\n", $kgm_kmsgsrcprocp->p_comm, $kgm_kmsgpid
+    else
+        printf "unknown(%d)\n", $kgm_kmsgpid
+    end
 end
 
 define showkmsgint
-    printf "            0x%08x  ", $arg0
-    set $kgm_kmsgh = ((ipc_kmsg_t)$arg0)->ikm_header
-    printf "0x%08x  ", $kgm_kmsgh.msgh_size
+    set $kgm_kmsghp = ((ipc_kmsg_t)$arg0)->ikm_header
+    set $kgm_kmsgh = *$kgm_kmsghp
+    if ($arg1 != 0)
+        printf "            "
+        showptrhdrpad
+    else
+        showptr $kgm_kmsgh.msgh_remote_port
+    end
+    showptr $arg0
+    showptrhdrpad
+    printf "  0x%08x  ", $kgm_kmsgh.msgh_id
     if (($kgm_kmsgh.msgh_bits & 0xff) == 19)
        printf "rC"
     else
@@ -1483,12 +2148,16 @@ define showkmsgint
     else
        printf "s"
     end
-    printf "%5d  ", $kgm_kmsgh.msgh_id
-    printf "0x%08x  ", $kgm_kmsgh.msgh_remote_port
-    printf "0x%08x\n", $kgm_kmsgh.msgh_local_port
+    printf "%5d  ", $kgm_kmsgh.msgh_size
+    showptr $kgm_kmsgh.msgh_local_port
+    printf "  "
+    set $kgm_kmsgsrcpid = (pid_t)0
+    showkmsgsrcint $arg0
 end
 
-
+define showkmsg
+    showkmsgint $arg0 0
+end
 
 define showkobject
     set $kgm_portp = (struct ipc_port *)$arg0
@@ -1623,7 +2292,7 @@ end
 define showportdest
     set $kgm_portp = (struct ipc_port *)$arg0
     set $kgm_spacep = $kgm_portp->data.receiver
-    if ($kgm_spacep == ipc_space_kernel)
+    if ((uintptr_t)$kgm_spacep == (uintptr_t)ipc_space_kernel)
        showkobject $kgm_portp
     else
        if ($kgm_portp->ip_object.io_bits & 0x80000000)
@@ -1638,9 +2307,12 @@ define showportdest
 end
 
 define showportmember
-    printf "            0x%08x  ", $arg0
+    printf "            "
+    showptrhdrpad
+    showptr $arg0
+    showptrhdrpad
     set $kgm_portp = (struct ipc_port *)$arg0
-    printf "0x%08x  ", $kgm_portp->ip_messages.data.port.receiver_name
+    printf "  0x%08x  ", $kgm_portp->ip_messages.data.port.receiver_name
     if ($kgm_portp->ip_object.io_bits & 0x80000000)
        printf "A"
     else
@@ -1648,8 +2320,8 @@ define showportmember
     end
     printf "Port"
     printf "%5d  ", $kgm_portp->ip_object.io_references
-    printf "0x%08x  ", &($kgm_portp->ip_messages)
-    printf "0x%08x\n", $kgm_portp->ip_messages.data.port.msgcount
+    showptr &($kgm_portp->ip_messages)
+    printf "  0x%08x\n", $kgm_portp->ip_messages.data.port.msgcount
 end
 
 define showportbt
@@ -1672,10 +2344,12 @@ define showportbt
 end
 
 define showportint
-    printf "0x%08x  ", $arg0
-    set $kgm_portp = (struct ipc_port *)$arg0
-    printf "0x%08x  ", &($kgm_portp->ip_messages)
-    printf "0x%08x  ", $kgm_portp->ip_messages.data.port.receiver_name
+    showptr $arg0
+    printf "  "
+    set $kgm_portp = (struct ipc_port *)$arg0
+    showptr &($kgm_portp->ip_messages)
+    showptrhdrpad
+    printf "  0x%08x  ", $kgm_portp->ip_messages.data.port.receiver_name
     if ($kgm_portp->ip_object.io_bits & 0x80000000)
        printf "A"
     else
@@ -1688,21 +2362,23 @@ define showportint
     set $kgm_kmsgp = (ipc_kmsg_t)$kgm_portp->ip_messages.data.port.messages.ikmq_base
     if $arg1 && $kgm_kmsgp
        showkmsgheader
-       showkmsgint $kgm_kmsgp
+       showkmsgint $kgm_kmsgp 1
        set $kgm_kmsgheadp = $kgm_kmsgp
        set $kgm_kmsgp = $kgm_kmsgp->ikm_next
        while $kgm_kmsgp != $kgm_kmsgheadp
-           showkmsgint $kgm_kmsgp
+           showkmsgint $kgm_kmsgp 1
            set $kgm_kmsgp = $kgm_kmsgp->ikm_next
         end
     end
 end
 
 define showpsetint
-    printf "0x%08x  ", $arg0
+    showptr $arg0
+    printf "  "
     set $kgm_psetp = (struct ipc_pset *)$arg0
-    printf "0x%08x  ", &($kgm_psetp->ips_messages)
-    printf "0x%08x  ", $kgm_psetp->ips_messages.data.pset.local_name
+    showptr &($kgm_psetp->ips_messages)
+    showptrhdrpad
+    printf "  0x%08x  ", $kgm_psetp->ips_messages.data.pset.local_name
     if ($kgm_psetp->ips_object.io_bits & 0x80000000)
        printf "A"
     else
@@ -1710,12 +2386,13 @@ define showpsetint
     end
     printf "Set "
     printf "%5d  ", $kgm_psetp->ips_object.io_references
-    printf "0x%08x  ", $kgm_psetp->ips_messages.data.pset.local_name
-    set $kgm_setlinksp = &($kgm_psetp->ips_messages.data.set_queue.wqs_setlinks)
+    showptr $kgm_psetp->ips_messages.data.pset.local_name
+    printf "  "
+    set $kgm_setlinksp = &($kgm_psetp->ips_messages.data.pset.set_queue.wqs_setlinks)
     set $kgm_wql = (WaitQueueLink *)$kgm_setlinksp->next
     set $kgm_found = 0
     while ( (queue_entry_t)$kgm_wql != (queue_entry_t)$kgm_setlinksp)
-        set $kgm_portp = (struct ipc_port *)((int)($kgm_wql->wql_element->wqe_queue) - ((int)$kgm_portoff))
+        set $kgm_portp = (struct ipc_port *)((uintptr_t)($kgm_wql->wql_element->wqe_queue) - (uintptr_t)$kgm_portoff)
        if !$kgm_found  
            set $kgm_destspacep = (struct ipc_space *)0
            showportdestproc $kgm_portp
@@ -1731,6 +2408,7 @@ define showpsetint
 end
 
 define showpset
+    set $kgm_portoff = &(((struct ipc_port *)0)->ip_messages)
     showpsetheader
     showpsetint $arg0 1
 end
@@ -1741,8 +2419,9 @@ define showport
 end
 
 define showipcobject
-    set $kgm_object = (ipc_object_t)$arg0
+    set $kgm_objectp = (ipc_object_t)$arg0
     if ($kgm_objectp->io_bits & 0x7fff0000)
+        set $kgm_portoff = &(((struct ipc_port *)0)->ip_messages)
        showpset $kgm_objectp
     else
        showport $kgm_objectp
@@ -1769,11 +2448,15 @@ define zprint_one
     set $kgm_zone = (struct zone *)$arg0
 
     showptr $kgm_zone
-    printf "  %6d ",$kgm_zone->count
+    printf "  %8d ",$kgm_zone->count
     printf "%8x ",$kgm_zone->cur_size
     printf "%8x ",$kgm_zone->max_size
-    printf "%6d ",$kgm_zone->elem_size
+    printf "%8d ",$kgm_zone->elem_size
     printf "%8x ",$kgm_zone->alloc_size
+    if ($kgm_mtype != $kgm_mtype_arm) 
+        printf " %16ld ",$kgm_zone->num_allocs 
+        printf "%16ld ",$kgm_zone->num_frees
+    end
     printf "%s ",$kgm_zone->zone_name
 
     if ($kgm_zone->exhaustible)
@@ -1785,6 +2468,9 @@ define zprint_one
     if ($kgm_zone->expandable)
         printf "X"
     end
+    if ($kgm_zone->noencrypt)
+        printf "$"
+    end
     printf "\n"
 end
 
@@ -1792,7 +2478,7 @@ end
 define zprint
     printf "ZONE      "
     showptrhdrpad
-    printf "   COUNT   TOT_SZ   MAX_SZ ELT_SZ ALLOC_SZ NAME\n"
+    printf "     COUNT   TOT_SZ   MAX_SZ   ELT_SZ ALLOC_SZ         TOT_ALLOC         TOT_FREE NAME\n"
     set $kgm_zone_ptr = (struct zone *)first_zone
     while ($kgm_zone_ptr != 0)
         zprint_one $kgm_zone_ptr
@@ -1870,6 +2556,7 @@ Syntax: (gdb) showallrwlck
 end
 
 set $kdp_act_counter = 0
+set $kdp_arm_act_counter = 0
 
 set $r0_save   = 0
 set $r1_save   = 0
@@ -1903,96 +2590,99 @@ define switchtoact
                output/a (unsigned) $newact.continuation
                echo \n
        else
-       if ($kgm_mtype == $kgm_mtype_ppc)
-               if ($kdp_act_counter == 0)
-                       set $kdpstate = (struct savearea *) kdp.saved_state
+               if ($kgm_mtype == $kgm_mtype_ppc)
+                       if ($kdp_act_counter == 0)
+                               set $kdpstate = (struct savearea *) kdp.saved_state
+                       end
+                       set $kdp_act_counter = $kdp_act_counter + 1
+                       set (struct savearea *) kdp.saved_state=$newact->machine->pcb
+                       flushregs
+                       flushstack
+                       set $pc=$newact->machine->pcb.save_srr0
+                       update
                end
-               set $kdp_act_counter = $kdp_act_counter + 1
-               set (struct savearea *) kdp.saved_state=$newact->machine->pcb
-               flushregs
-               flushstack
-               set $pc=$newact->machine->pcb.save_srr0
-               update
-       end
-       if ($kgm_mtype == $kgm_mtype_i386)
-               set $kdpstatep = (struct x86_saved_state32 *) kdp.saved_state
-               if ($kdp_act_counter == 0)
-                  set $kdpstate = *($kdpstatep)
-               end     
-               set $kdp_act_counter = $kdp_act_counter + 1
-
-               set $kgm_statep = (struct x86_kernel_state *) \
-                                       ($newact->kernel_stack + kernel_stack_size \
-                                        - sizeof(struct x86_kernel_state))
-               set $kdpstatep->ebx = $kgm_statep->k_ebx 
-               set $kdpstatep->ebp = $kgm_statep->k_ebp 
-               set $kdpstatep->edi = $kgm_statep->k_edi 
-               set $kdpstatep->esi = $kgm_statep->k_esi 
-               set $kdpstatep->eip = $kgm_statep->k_eip 
-               flushregs
-               flushstack
-               set $pc = $kgm_statep->k_eip
-               update
-       end
-       if ($kgm_mtype == $kgm_mtype_x86_64)
-               set $kdpstatep = (struct x86_saved_state64 *) kdp.saved_state
-               if ($kdp_act_counter == 0)
-                  set $kdpstate = *($kdpstatep)
-               end     
-               set $kdp_act_counter = $kdp_act_counter + 1
-
-               set $kgm_statep = (struct x86_kernel_state *) \
-                                       ($newact->kernel_stack + kernel_stack_size \
-                                        - sizeof(struct x86_kernel_state))
-               set $kdpstatep->rbx = $kgm_statep->k_rbx 
-               set $kdpstatep->rbp = $kgm_statep->k_rbp 
-               set $kdpstatep->r12 = $kgm_statep->k_r12 
-               set $kdpstatep->r13 = $kgm_statep->k_r13 
-               set $kdpstatep->r14 = $kgm_statep->k_r14 
-               set $kdpstatep->r15 = $kgm_statep->k_r15 
-               set $kdpstatep->isf.rsp = $kgm_statep->k_rsp 
-               flushregs
-               flushstack
-               set $pc = $kgm_statep->k_rip
-               update
-       end
-       if ($kgm_mtype == $kgm_mtype_arm)
-               set $r0_save   = $r0
-               set $r1_save   = $r1
-               set $r2_save   = $r2
-               set $r3_save   = $r3
-               set $r4_save   = $r4
-               set $r5_save   = $r5
-               set $r6_save   = $r6
-               set $r7_save   = $r7
-               set $r8_save   = $r8
-               set $r9_save   = $r9
-               set $r10_save  = $r10
-               set $r11_save  = $r11
-               set $r12_save  = $r12
-               set $sp_save   = $sp
-               set $lr_save   = $lr
-               set $pc_save   = $pc
-               set $pc_ctx = load_reg+8
-               set $kgm_statep = (struct arm_saved_state *)((struct thread*)$arg0)->machine.kstackptr
-               set $r0 =  $kgm_statep->r[0]
-               set $r1 =  $kgm_statep->r[1]
-               set $r2 =  $kgm_statep->r[2]
-               set $r3 =  $kgm_statep->r[3]
-               set $r4 =  $kgm_statep->r[4]
-               set $r5 =  $kgm_statep->r[5]
-               set $r6 =  $kgm_statep->r[6]
-               set $r8 =  $kgm_statep->r[8]
-               set $r9 =  $kgm_statep->r[9]
-               set $r10 = $kgm_statep->r[10]
-               set $r11 = $kgm_statep->r[11]
-               set $r12 = $kgm_statep->r[12]
-               set $sp = $kgm_statep->sp
-               set $lr = $kgm_statep->lr
-               set $pc = $pc_ctx
-               set $r7 =  $kgm_statep->r[7]
-               flushregs
-               flushstack
+               if ($kgm_mtype == $kgm_mtype_i386)
+                       set $kdpstatep = (struct x86_saved_state32 *) kdp.saved_state
+                       if ($kdp_act_counter == 0)
+                          set $kdpstate = *($kdpstatep)
+                       end     
+                       set $kdp_act_counter = $kdp_act_counter + 1
+       
+                       set $kgm_statep = (struct x86_kernel_state *) \
+                                               ($newact->kernel_stack + kernel_stack_size \
+                                                - sizeof(struct x86_kernel_state))
+                       set $kdpstatep->ebx = $kgm_statep->k_ebx 
+                       set $kdpstatep->ebp = $kgm_statep->k_ebp 
+                       set $kdpstatep->edi = $kgm_statep->k_edi 
+                       set $kdpstatep->esi = $kgm_statep->k_esi 
+                       set $kdpstatep->eip = $kgm_statep->k_eip 
+                       flushregs
+                       flushstack
+                       set $pc = $kgm_statep->k_eip
+                       update
+               end
+               if ($kgm_mtype == $kgm_mtype_x86_64)
+                       set $kdpstatep = (struct x86_saved_state64 *) kdp.saved_state
+                       if ($kdp_act_counter == 0)
+                          set $kdpstate = *($kdpstatep)
+                       end     
+                       set $kdp_act_counter = $kdp_act_counter + 1
+       
+                       set $kgm_statep = (struct x86_kernel_state *) \
+                                               ($newact->kernel_stack + kernel_stack_size \
+                                                - sizeof(struct x86_kernel_state))
+                       set $kdpstatep->rbx = $kgm_statep->k_rbx 
+                       set $kdpstatep->rbp = $kgm_statep->k_rbp 
+                       set $kdpstatep->r12 = $kgm_statep->k_r12 
+                       set $kdpstatep->r13 = $kgm_statep->k_r13 
+                       set $kdpstatep->r14 = $kgm_statep->k_r14 
+                       set $kdpstatep->r15 = $kgm_statep->k_r15 
+                       set $kdpstatep->isf.rsp = $kgm_statep->k_rsp 
+                       flushregs
+                       flushstack
+                       set $pc = $kgm_statep->k_rip
+                       update
+               end
+               if ($kgm_mtype == $kgm_mtype_arm)
+                       set $kdp_arm_act_counter = $kdp_arm_act_counter + 1
+                       if ($kdp_arm_act_counter == 1)
+                               set $r0_save   = $r0
+                               set $r1_save   = $r1
+                               set $r2_save   = $r2
+                               set $r3_save   = $r3
+                               set $r4_save   = $r4
+                               set $r5_save   = $r5
+                               set $r6_save   = $r6
+                               set $r7_save   = $r7
+                               set $r8_save   = $r8
+                               set $r9_save   = $r9
+                               set $r10_save  = $r10
+                               set $r11_save  = $r11
+                               set $r12_save  = $r12
+                               set $sp_save   = $sp
+                               set $lr_save   = $lr
+                               set $pc_save   = $pc
+                       end
+                       set $pc_ctx = load_reg+8
+                       set $kgm_statep = (struct arm_saved_state *)((struct thread*)$arg0)->machine.kstackptr
+                       set $r0 =  $kgm_statep->r[0]
+                       set $r1 =  $kgm_statep->r[1]
+                       set $r2 =  $kgm_statep->r[2]
+                       set $r3 =  $kgm_statep->r[3]
+                       set $r4 =  $kgm_statep->r[4]
+                       set $r5 =  $kgm_statep->r[5]
+                       set $r6 =  $kgm_statep->r[6]
+                       set $r8 =  $kgm_statep->r[8]
+                       set $r9 =  $kgm_statep->r[9]
+                       set $r10 = $kgm_statep->r[10]
+                       set $r11 = $kgm_statep->r[11]
+                       set $r12 = $kgm_statep->r[12]
+                       set $sp = $kgm_statep->sp
+                       set $lr = $kgm_statep->lr
+                       set $pc = $pc_ctx
+                       set $r7 =  $kgm_statep->r[7]
+                       flushregs
+                       flushstack
                end
        end
        showcontext_int
@@ -2020,50 +2710,54 @@ define switchtoctx
                set $pc=((struct savearea *) $arg0)->save_srr0
                update
        else
-       if ($kgm_mtype == $kgm_mtype_arm)
-               set arm disassembler std
-               select-frame 0
-               set $r0_save   = $r0
-               set $r1_save   = $r1
-               set $r2_save   = $r2
-               set $r3_save   = $r3
-               set $r4_save   = $r4
-               set $r5_save   = $r5
-               set $r6_save   = $r6
-               set $r7_save   = $r7
-               set $r8_save   = $r8
-               set $r9_save   = $r9
-               set $r10_save  = $r10
-               set $r11_save  = $r11
-               set $r12_save  = $r12
-               set $sp_save   = $sp
-               set $lr_save   = $lr
-               set $pc_save   = $pc
-               set $kgm_statep = (struct arm_saved_state *)$arg0
-               set $r0 =  $kgm_statep->r[0]
-               set $r1 =  $kgm_statep->r[1]
-               set $r2 =  $kgm_statep->r[2]
-               set $r3 =  $kgm_statep->r[3]
-               set $r4 =  $kgm_statep->r[4]
-               set $r5 =  $kgm_statep->r[5]
-               set $r6 =  $kgm_statep->r[6]
-               set $r8 =  $kgm_statep->r[8]
-               set $r9 =  $kgm_statep->r[9]
-               set $r10 = $kgm_statep->r[10]
-               set $r11 = $kgm_statep->r[11]
-               set $r12 = $kgm_statep->r[12]
-               set $sp = $kgm_statep->sp
-               set $lr = $kgm_statep->lr
-               set $r7 =  $kgm_statep->r[7]
-               set $pc = $kgm_statep->pc
-               flushregs
-               flushstack
-               update
-       else
-               echo switchtoctx not implemented for this architecture.\n
+               if ($kgm_mtype == $kgm_mtype_arm)
+                       select 0
+                       set $kdp_arm_act_counter = $kdp_arm_act_counter + 1
+                       if ($kdp_arm_act_counter == 1)
+                               set $r0_save   = $r0
+                               set $r1_save   = $r1
+                               set $r2_save   = $r2
+                               set $r3_save   = $r3
+                               set $r4_save   = $r4
+                               set $r5_save   = $r5
+                               set $r6_save   = $r6
+                               set $r7_save   = $r7
+                               set $r8_save   = $r8
+                               set $r9_save   = $r9
+                               set $r10_save  = $r10
+                               set $r11_save  = $r11
+                               set $r12_save  = $r12
+                               set $sp_save   = $sp
+                               set $lr_save   = $lr
+                               set $pc_save   = $pc
+                       end
+                       set $kgm_statep = (struct arm_saved_state *)$arg0
+                       set $r0 =  $kgm_statep->r[0]
+                       set $r1 =  $kgm_statep->r[1]
+                       set $r2 =  $kgm_statep->r[2]
+                       set $r3 =  $kgm_statep->r[3]
+                       set $r4 =  $kgm_statep->r[4]
+                       set $r5 =  $kgm_statep->r[5]
+                       set $r6 =  $kgm_statep->r[6]
+                       set $r8 =  $kgm_statep->r[8]
+                       set $r9 =  $kgm_statep->r[9]
+                       set $r10 = $kgm_statep->r[10]
+                       set $r11 = $kgm_statep->r[11]
+                       set $r12 = $kgm_statep->r[12]
+                       set $sp = $kgm_statep->sp
+                       set $lr = $kgm_statep->lr
+                       set $r7 =  $kgm_statep->r[7]
+                       set $pc = $kgm_statep->pc
+                       flushregs
+                       flushstack
+                       update
+               else
+                       echo switchtoctx not implemented for this architecture.\n
+               end
        end
 end
 
+
 document switchtoctx  
 Syntax: switchtoctx <address of pcb>
 | This command allows gdb to examine an execution context and dump the
@@ -2075,33 +2769,36 @@ end
 define resetctx
        select 0
        if ($kdp_act_counter != 0)
-       if ($kgm_mtype == $kgm_mtype_ppc)
-               set (struct savearea *)kdp.saved_state=$kdpstate
-               flushregs
-               flushstack
-               set $pc=((struct savearea *) kdp.saved_state)->save_srr0
-               update
-               set $kdp_act_counter = 0
-       end
-       if ($kgm_mtype == $kgm_mtype_i386)
-               set $kdpstatep = (struct x86_saved_state32 *) kdp.saved_state
-               set *($kdpstatep)=$kdpstate
-               flushregs
-               flushstack
-               set $pc=$kdpstatep->eip
-               update
-               set $kdp_act_counter = 0
-       end
-       if ($kgm_mtype == $kgm_mtype_x86_64)
-               set $kdpstatep = (struct x86_saved_state64 *) kdp.saved_state
-               set *($kdpstatep)=$kdpstate
-               flushregs
-               flushstack
-               set $pc=$kdpstatep->isf.rip
-               update
-               set $kdp_act_counter = 0
-       end
-       if ($kgm_mtype == $kgm_mtype_arm)
+               if ($kgm_mtype == $kgm_mtype_ppc)
+                       set (struct savearea *)kdp.saved_state=$kdpstate
+                       flushregs
+                       flushstack
+                       set $pc=((struct savearea *) kdp.saved_state)->save_srr0
+                       update
+                       set $kdp_act_counter = 0
+               end
+               if ($kgm_mtype == $kgm_mtype_i386)
+                       set $kdpstatep = (struct x86_saved_state32 *) kdp.saved_state
+                       set *($kdpstatep)=$kdpstate
+                       flushregs
+                       flushstack
+                       set $pc=$kdpstatep->eip
+                       update
+                       set $kdp_act_counter = 0
+               end
+               if ($kgm_mtype == $kgm_mtype_x86_64)
+                       set $kdpstatep = (struct x86_saved_state64 *) kdp.saved_state
+                       set *($kdpstatep)=$kdpstate
+                       flushregs
+                       flushstack
+                       set $pc=$kdpstatep->isf.rip
+                       update
+                       set $kdp_act_counter = 0
+               end
+               showcontext_int
+       end
+       if ($kgm_mtype == $kgm_mtype_arm && $kdp_arm_act_counter != 0)
+               echo Restoring context\n
                set $r0  = $r0_save
                flushregs
                set $r1  = $r1_save
@@ -2134,8 +2831,9 @@ define resetctx
                flushregs
                set $r7  = $r7_save
                flushregs
-       end
-       showcontext_int
+               flushstack
+               update
+               set $kdp_arm_act_counter = 0
        end
 end     
         
@@ -2205,8 +2903,8 @@ define dumpcallqueue
        set $kgm_i = 0
        while $kgm_callentry != $kgm_callhead
                set $kgm_call = (struct call_entry *)$kgm_callentry
-               printf "0x%08x ", $kgm_call
-               printf "0x%08x 0x%08x ", $kgm_call->param0, $kgm_call->param1
+               showptr $kgm_call
+               printf "0x%lx 0x%lx ", $kgm_call->param0, $kgm_call->param1
                output $kgm_call->deadline
                printf "\t"
                output $kgm_call->func
@@ -2367,7 +3065,7 @@ define showx86backtrace
        _loadfrom ($kgm_tmp_frame+$kgm_ret_off)
        set $kgm_prev_pc = $kgm_loadval
        set $kgm_frameno = 1
-       while $kgm_prev_frame != 0
+       while ($kgm_prev_frame != 0) && ($kgm_prev_frame != 0x0000000800000008)
                printf "%d: Saved frame: 0x%016llx Saved PC: 0x%016llx\n", $kgm_frameno, $kgm_prev_frame, $kgm_prev_pc
                if (!(($kgm_x86_abi == 0xf) && ($kgm_mtype == $kgm_mtype_i386)))
                   x/i $kgm_prev_pc
@@ -2422,7 +3120,7 @@ define showuserstack
                else
                if (($kgm_mtype & $kgm_mtype_x86_mask) == $kgm_mtype_x86_any)
                        set $newact = (struct thread *) $arg0
-                       set $newiss = (x86_saved_state_t *) ($newact->machine.pcb->iss)
+                       set $newiss = (x86_saved_state_t *) ($newact->machine->iss)
                        set $kgm_x86_abi = $newiss.flavor
                        if ($newiss.flavor == 0xf) 
                                set $checkpc = $newiss.uss.ss_64.isf.rip
@@ -2439,19 +3137,69 @@ define showuserstack
                        else
                        set $kgm_cur_frame = $checkframe
                        set $kgm_cur_pc = $checkpc
-                       printf "You may now issue the showx86backtrace command to see the user space backtrace for this thread ("
-                       showptr $arg0
-                       printf "); you can also examine memory locations in this address space (pmap "
-                       showptr $newact->task->map->pmap
-                       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"
+# When have more than one argument is present, don't print usage
+                       if ( $argc == 1 )
+                               printf "You may now issue the showx86backtrace command to see the user space backtrace for this thread ("
+                               showptr $arg0
+                               printf "); you can also examine memory locations in this address space (pmap "
+                               showptr $newact->task->map->pmap
+                               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"
+                       end
                        set kdp_pmap = $newact->task->map->pmap
                        _kgm_flush_loop
                        _kgm_update_loop
                        end                     
+               else
+               if ($kgm_mtype == $kgm_mtype_arm)
+                       if (kdp->is_conn > 0)
+                               set $kgm_threadp = (struct thread *)$arg0
+                               set $kgm_saved_pmap = kdp_pmap
+                               showactheader
+                               showactint $kgm_threadp 0
+                               set $kgm_thread_pmap = $kgm_threadp->task->map->pmap
+                               set $kgm_thread_sp = $kgm_threadp.machine->PcbData.r[7]
+                               showptrhdrpad
+                               printf "                  "
+                               showptr 0
+                               printf "  "
+                               showptr $kgm_threadp.machine->PcbData.pc
+                               printf "\n"
+                               set kdp_pmap = $kgm_thread_pmap
+                               while ($kgm_thread_sp != 0)
+                               set $link_register = *($kgm_thread_sp + 4)
+                               showptrhdrpad
+                                       printf "                  "
+                                       showptr $kgm_thread_sp
+                                       printf "  "
+                               showptr $link_register
+                               printf "\n"
+                               set $kgm_thread_sp = *$kgm_thread_sp
+                               end
+                               set kdp_pmap = $kgm_saved_pmap
+                       else
+                               set $kgm_threadp = (struct thread *)$arg0
+                               showactheader
+                               showactint $kgm_threadp 0
+                               set $kgm_thread_sp = $kgm_threadp.machine->PcbData.r[7]
+                               while ($kgm_thread_sp != 0)
+                               _map_user_data_from_task $kgm_threadp->task $kgm_thread_sp 8
+                               set $kgm_thread_sp_window = (int *)$kgm_map_user_window
+                               set $link_register = *($kgm_thread_sp_window + 1)
+                               showptrhdrpad
+                                       printf "                  "
+                                       showptr $kgm_thread_sp
+                                       printf "  "
+                               showptr $link_register
+                               printf "\n"
+                               set $kgm_thread_sp = *$kgm_thread_sp_window
+                               _unmap_user_data_from_task
+                               end
+                       end
                else
                        echo showuserstack not supported on this architecture\n
                end
                end
+               end
 end
 document showuserstack
 Syntax: showuserstack <address of thread activation>
@@ -2465,11 +3213,221 @@ Syntax: showuserstack <address of thread activation>
 |macro in some cases.
 end
 
+define showtaskuserstacks
+    set $kgm_taskp = (struct task *)$arg0
+    set $kgm_head_actp = &($kgm_taskp->threads)
+    set $kgm_actp = (struct thread *)($kgm_taskp->threads.next)
+    while $kgm_actp != $kgm_head_actp
+       printf "For thread "
+       showptr $kgm_actp
+       printf "\n"
+       showuserstack $kgm_actp quiet
+       if (($kgm_mtype & $kgm_mtype_x86_mask) == $kgm_mtype_x86_any)
+               showx86backtrace
+       end
+       set kdp_pmap=0
+       set $kgm_actp = (struct thread *)($kgm_actp->task_threads.next)
+       printf "\n"
+    end
+    showuserlibraries $kgm_taskp
+end
+document showtaskuserstacks
+Syntax: (gdb) showtaskuserstacks <task>
+| Print out the user stack for each thread in a task, followed by the user libraries.
+end
+
+
+define showuserregisters
+       set $kgm_threadp = (struct thread *)$arg0
+       set $kgm_taskp = $kgm_threadp->task
+       if (($kgm_mtype & $kgm_mtype_x86_mask) == $kgm_mtype_x86_any)
+               set $newiss = (x86_saved_state_t *) ($kgm_threadp->machine.iss)
+               set $kgm_x86_abi = $newiss.flavor
+               if ($newiss.flavor == 0xf)
+                       printf "X86 Thread State (64-bit):\n"
+                       set $kgm_ss64 = $newiss.uss.ss_64
+
+                       printf "  rax: "
+                       showuserptr $kgm_ss64.rax
+                       printf "  rbx: "
+                       showuserptr $kgm_ss64.rbx
+                       printf "  rcx: "
+                       showuserptr $kgm_ss64.rcx
+                       printf "  rdx: "
+                       showuserptr $kgm_ss64.rdx
+                       printf "\n"
+
+                       printf "  rdi: "
+                       showuserptr $kgm_ss64.rdi
+                       printf "  rsi: "
+                       showuserptr $kgm_ss64.rsi
+                       printf "  rbp: "
+                       showuserptr $kgm_ss64.rbp
+                       printf "  rsp: "
+                       showuserptr $kgm_ss64.isf.rsp
+                       printf "\n"
+
+                       printf "   r8: "
+                       showuserptr $kgm_ss64.r8
+                       printf "   r9: "
+                       showuserptr $kgm_ss64.r9
+                       printf "  r10: "
+                       showuserptr $kgm_ss64.r10
+                       printf "  r11: "
+                       showuserptr $kgm_ss64.r11
+                       printf "\n"
+
+                       printf "  r12: "
+                       showuserptr $kgm_ss64.r12
+                       printf "  r13: "
+                       showuserptr $kgm_ss64.r13
+                       printf "  r14: "
+                       showuserptr $kgm_ss64.r14
+                       printf "  r15: "
+                       showuserptr $kgm_ss64.r15
+                       printf "\n"
+
+                       printf "  rip: "
+                       showuserptr $kgm_ss64.isf.rip
+                       printf "  rfl: "
+                       showuserptr $kgm_ss64.isf.rflags
+                       printf "  cr2: "
+                       showuserptr $kgm_ss64.cr2
+                       printf "\n"
+               else
+                       printf "X86 Thread State (32-bit):\n"
+                       set $kgm_ss32 = $newiss.uss.ss_32
+
+                       printf "  eax: "
+                       showuserptr $kgm_ss32.eax
+                       printf "  ebx: "
+                       showuserptr $kgm_ss32.ebx
+                       printf "  ecx: "
+                       showuserptr $kgm_ss32.ecx
+                       printf "  edx: "
+                       showuserptr $kgm_ss32.edx
+                       printf "\n"
+
+                       printf "  edi: "
+                       showuserptr $kgm_ss32.edi
+                       printf "  esi: "
+                       showuserptr $kgm_ss32.esi
+                       printf "  ebp: "
+                       showuserptr $kgm_ss32.ebp
+                       printf "  esp: "
+                       showuserptr $kgm_ss32.uesp
+                       printf "\n"
+
+                       printf "   ss: "
+                       showuserptr $kgm_ss32.ss
+                       printf "  efl: "
+                       showuserptr $kgm_ss32.efl
+                       printf "  eip: "
+                       showuserptr $kgm_ss32.eip
+                       printf "   cs: "
+                       showuserptr $kgm_ss32.cs
+                       printf "\n"
+
+                       printf "   ds: "
+                       showuserptr $kgm_ss32.ds
+                       printf "   es: "
+                       showuserptr $kgm_ss32.es
+                       printf "   fs: "
+                       showuserptr $kgm_ss32.fs
+                       printf "   gs: "
+                       showuserptr $kgm_ss32.gs
+                       printf "\n"
+
+                       printf "  cr2: "
+                       showuserptr $kgm_ss32.cr2
+                       printf "\n"
+               end
+       else
+       if ($kgm_mtype == $kgm_mtype_arm)
+               printf "ARM Thread State:\n"
+               set $kgm_pcb = (arm_saved_state_t *) (&$kgm_threadp->machine.PcbData)
+
+               printf "    r0: "
+               showuserptr $kgm_pcb.r[0]
+               printf "    r1: "
+               showuserptr $kgm_pcb.r[1]
+               printf "    r2: "
+               showuserptr $kgm_pcb.r[2]
+               printf "    r3: "
+               showuserptr $kgm_pcb.r[3]
+               printf "\n"
+
+               printf "    r4: "
+               showuserptr $kgm_pcb.r[4]
+               printf "    r5: "
+               showuserptr $kgm_pcb.r[5]
+               printf "    r6: "
+               showuserptr $kgm_pcb.r[6]
+               printf "    r7: "
+               showuserptr $kgm_pcb.r[7]
+               printf "\n"
+
+               printf "    r8: "
+               showuserptr $kgm_pcb.r[8]
+               printf "    r9: "
+               showuserptr $kgm_pcb.r[9]
+               printf "   r10: "
+               showuserptr $kgm_pcb.r[10]
+               printf "   r11: "
+               showuserptr $kgm_pcb.r[11]
+               printf "\n"
+
+               printf "    ip: "
+               showuserptr $kgm_pcb.r[12]
+               printf "    sp: "
+               showuserptr $kgm_pcb.sp
+               printf "    lr: "
+               showuserptr $kgm_pcb.lr
+               printf "    pc: "
+               showuserptr $kgm_pcb.pc
+               printf "\n"
+
+               printf "  cpsr: "
+               showuserptr $kgm_pcb.cpsr
+               printf "\n"
+       else
+               echo showuserregisters not supported on this architecture\n
+       end
+       end
+end
+document showuserregisters
+Syntax: showuserstack <address of thread>
+|This command displays the last known user register state
+|for the thread. This map not be correct for cases where
+|the thread is currently executing in userspace. However
+|for threads that have entered the kernel (either explicitly
+|with a system call or implicitly with a fault), it should
+|be accurate
+end
+
+define showtaskuserregisters
+    set $kgm_taskp = (struct task *)$arg0
+    set $kgm_head_actp = &($kgm_taskp->threads)
+    set $kgm_actp = (struct thread *)($kgm_taskp->threads.next)
+    while $kgm_actp != $kgm_head_actp
+       printf "For thread "
+       showptr $kgm_actp
+       printf "\n"
+       showuserregisters $kgm_actp
+       set $kgm_actp = (struct thread *)($kgm_actp->task_threads.next)
+       printf "\n"
+    end
+end
+document showtaskuserregisters
+Syntax: (gdb) showtaskuserregisters <task>
+| Print out the user registers for each thread in a task
+end
+
 define kdp-reboot
 # Alternatively, set *(*(unsigned **) 0x2498) = 1 
 # (or 0x5498 on PPC, 0xffffff8000002928 on x86_64, 0xffff049c on arm)
        manualhdrint $kgm_kdp_pkt_hostreboot
-       continue
+       detach
 end
 
 document kdp-reboot
@@ -2510,7 +3468,7 @@ define dumpinfoint
        set manual_pkt.input        = 0
 
        set manual_pkt.len          = sizeof(kdp_dumpinfo_req_t)
-       set $kgm_pkt                = (kdp_dumpinfo_req_t *)manual_pkt.data
+       set $kgm_pkt                = (kdp_dumpinfo_req_t *)&manual_pkt.data
        set $kgm_pkt->hdr.request  = KDP_DUMPINFO
        set $kgm_pkt->hdr.len      = sizeof(kdp_dumpinfo_req_t)
        set $kgm_pkt->hdr.is_reply = 0
@@ -2604,7 +3562,7 @@ define getdumpinfo
        if $kgm_dumpinfo->type & KDP_DUMPINFO_REBOOT
                  printf "System will reboot after kernel info gets dumped.\n"
        else
-                 printf "Sysem will not reboot after kernel info gets dumped.\n"
+                 printf "System will not reboot after kernel info gets dumped.\n"
        end
        if $kgm_dumpinfo->type & KDP_DUMPINFO_NORESUME
                  printf "System will allow a re-attach after a KDP disconnect.\n"
@@ -3162,6 +4120,28 @@ define showregdictionary
 end
 
 
+define showorderedsetarrayint
+    set $kgm$arg0_array = (_Element *)$arg1
+    set $kgm$arg0_count = $arg2
+
+    set $kgm$arg0_idx = 0
+    while ($kgm$arg0_idx < $kgm$arg0_count)
+        set $kgm_obj = $kgm$arg0_array[$kgm$arg0_idx++]
+        showobjectint _$arg0 $kgm_obj
+        if ($kgm$arg0_idx < $kgm$arg0_count)
+           printf ","
+        end
+    end
+end
+
+define showorderedsetint
+    set $kgm_array = ((OSOrderedSet *)$arg1)->array
+    set $count = ((OSOrderedSet *)$arg1)->count
+    printf "["
+    showorderedsetarrayint $arg0 $kgm_array $count
+    printf "]"
+end
+
 define showarraysetint
     set $kgm$arg0_array = (OSArray *)$arg1
 
@@ -3246,6 +4226,10 @@ define showobjectint
         showsetint _$arg0 $arg1
         set $kgm_shown = 1
     end
+    if ($kgm_vt == &_ZTV12OSOrderedSet)
+        showorderedsetint _$arg0 $arg1
+        set $kgm_shown = 1
+    end
     
     if ($kgm_shown != 1)
         if ($kgm_show_object_addrs == 0)
@@ -3340,7 +4324,7 @@ define findregistryentryrecurse
             print $kgm_re
          end
 
-         # if we want to show everything, then don't populate $kgm_registry_entry
+         # don't populate $kgm_registry_entry if we want to show everything
          if !$kgm_findregistry_continue
                     set $kgm_registry_entry = $kgm_re
          end
@@ -3750,38 +4734,84 @@ Syntax: (gdb) showosobjecttracking
 | Set gOSObjectTrackThread to 1 or a thread_t to capture new OSObjects allocated by a thread or all threads.
 end
 
+# $kgm_readphys_force_kdp and $kgm_readphys_force_physmap
+# can respectively cause physical memory access to use
+# a KDP manual packet or the physical memory mapping
+# even if the default behavior would be otherwise.
 define readphysint
-       set $kgm_readphysint_result = 0xBAD10AD
-       # set up the manual KDP packet
-       set manual_pkt.input = 0
-       set manual_pkt.len = sizeof(kdp_readphysmem64_req_t)
-       set $kgm_pkt = (kdp_readphysmem64_req_t *)&manual_pkt.data
-       set $kgm_pkt->hdr.request  = KDP_READPHYSMEM64
-       set $kgm_pkt->hdr.len      = sizeof(kdp_readphysmem64_req_t)
-       set $kgm_pkt->hdr.is_reply = 0
-       set $kgm_pkt->hdr.seq      = 0
-       set $kgm_pkt->hdr.key      = 0
-       set $kgm_pkt->address      = (uint64_t)$arg0
-       set $kgm_pkt->nbytes       = $arg1 >> 3
-       set $kgm_pkt->lcpu         = $arg2
-       set manual_pkt.input       = 1
-       # dummy to make sure manual packet is executed
-       set $kgm_dummy = &_mh_execute_header
-       set $kgm_pkt = (kdp_readphysmem64_reply_t *)&manual_pkt.data
-       if ($kgm_pkt->error == 0)
-                 if $arg1 == 8
-                    set $kgm_readphysint_result = *((uint8_t *)$kgm_pkt->data)
-         end
-                 if $arg1 == 16
-                    set $kgm_readphysint_result = *((uint16_t *)$kgm_pkt->data)
-         end
-                 if $arg1 == 32
-                    set $kgm_readphysint_result = *((uint32_t *)$kgm_pkt->data)
-         end
-                 if $arg1 == 64
-                    set $kgm_readphysint_result = *((uint64_t *)$kgm_pkt->data)
-         end
-       end
+    set $kgm_readphysint_result = 0xBAD10AD
+
+    if ($kgm_readphys_force_kdp != 0)
+        set $kgm_readphys_use_kdp = 1
+    else
+        if ($kgm_readphys_force_physmap)
+            set $kgm_readphys_use_kdp = 0
+        else
+            set $kgm_readphys_use_kdp = ( kdp->is_conn > 0 )
+        end
+    end
+
+    if ($kgm_readphys_use_kdp)
+
+        # set up the manual KDP packet
+        set manual_pkt.input = 0
+        set manual_pkt.len = sizeof(kdp_readphysmem64_req_t)
+        set $kgm_pkt = (kdp_readphysmem64_req_t *)&manual_pkt.data
+        set $kgm_pkt->hdr.request  = KDP_READPHYSMEM64
+        set $kgm_pkt->hdr.len      = sizeof(kdp_readphysmem64_req_t)
+        set $kgm_pkt->hdr.is_reply = 0
+        set $kgm_pkt->hdr.seq      = 0
+        set $kgm_pkt->hdr.key      = 0
+        set $kgm_pkt->address      = (uint64_t)$arg0
+        set $kgm_pkt->nbytes       = $arg1 >> 3
+        set $kgm_pkt->lcpu         = $arg2
+        set manual_pkt.input       = 1
+        # dummy to make sure manual packet is executed
+        set $kgm_dummy = &_mh_execute_header
+        set $kgm_pkt = (kdp_readphysmem64_reply_t *)&manual_pkt.data
+        if ($kgm_pkt->error == 0)
+            if $arg1 == 8
+                set $kgm_readphysint_result = *((uint8_t *)$kgm_pkt->data)
+            end
+            if $arg1 == 16
+                set $kgm_readphysint_result = *((uint16_t *)$kgm_pkt->data)
+            end
+            if $arg1 == 32
+                set $kgm_readphysint_result = *((uint32_t *)$kgm_pkt->data)
+            end
+            if $arg1 == 64
+                set $kgm_readphysint_result = *((uint64_t *)$kgm_pkt->data)
+            end
+        end
+
+    else
+        # No KDP. Attempt to use physical memory mapping
+
+        if ($kgm_mtype == $kgm_mtype_x86_64)
+            set $kgm_readphys_paddr_in_kva = (unsigned long long)$arg0 + physmap_base
+        else
+            if ($kgm_mtype == $kgm_mtype_arm)
+                set $kgm_readphys_paddr_in_kva = (unsigned long long)$arg0 - gPhysBase + gVirtBase
+            else
+                printf "readphys not available for current architecture.\n"
+                set $kgm_readphys_paddr_in_kva = 0
+            end
+        end
+        if $kgm_readphys_paddr_in_kva
+            if $arg1 == 8
+                set $kgm_readphysint_result = *((uint8_t *)$kgm_readphys_paddr_in_kva)
+            end
+            if $arg1 == 16
+                set $kgm_readphysint_result = *((uint16_t *)$kgm_readphys_paddr_in_kva)
+            end
+            if $arg1 == 32
+                set $kgm_readphysint_result = *((uint32_t *)$kgm_readphys_paddr_in_kva)
+            end
+            if $arg1 == 64
+                set $kgm_readphysint_result = *((uint64_t *)$kgm_readphys_paddr_in_kva)
+            end
+        end
+    end
 end
 
 define readphys8
@@ -3899,14 +4929,30 @@ document writephys64
 end
 
 define addkextsyms
-        shell ls $arg0/* | xargs -n 1 echo add-symbol-file > /tmp/gdb-syms
-        source /tmp/gdb-syms
-       set $kgm_show_kmod_syms = 1
+       if ($argc <= 1)
+               if ($argc == 0)
+                       printf "Adding kext symbols from in-kernel summary data.\n"
+                       add-all-kexts
+               else
+                       printf "Adding kext symbols from $arg0.\n"
+                       shell echo cd `pwd` > /tmp/gdb-cd
+                       cd $arg0
+                       source kcbmacros
+                       source /tmp/gdb-cd
+               end
+               set $kgm_show_kmod_syms = 1
+       else
+               printf "| Usage:\n|\n"
+               help addkextsyms
+       end
 end
 
 document addkextsyms
-| Takes a directory of symbols for kexts generated with kextcache -y and loads them
-| into gdb.
+| If specified without an argument, uses gdb's add-all-kexts command to load
+| kext symbols. Otherwise, takes a directory of kext symbols generated with
+| kextcache -y or kcgen and loads them into gdb.
+| (gdb) addkextsyms
+| - or -
 | (gdb) addkextsyms /path/to/symboldir
 end
 
@@ -4081,7 +5127,7 @@ define showprocinfo
     # decode part of credential
     set $kgm_spi_cred = $kgm_spi_proc->p_ucred
     if ($kgm_spi_cred != 0)
-       printf "Cred: euid %d ruid %d svuid %d\n", $kgm_spi_cred->cr_uid, $kgm_spi_cred->cr_ruid, $kgm_spi_cred->cr_svuid
+       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
     else
        printf "Cred: (null)\n"
     end
@@ -4271,7 +5317,138 @@ Syntax: (gdb) allproc
 | Routine to print out all process in the system 
 | which are not in the zombie list
 end
-
+define showprocsiblingint
+    set $kgm_sibling_ptr = (struct proc *)$arg0
+    set $kgm_lx = $arg1 
+    while $kgm_lx
+        printf "|  " 
+        set $kgm_lx = $kgm_lx-3 
+    end   
+    printf "|--%d    %s    [ 0x%llx ]\n", $kgm_sibling_ptr->p_pid, $kgm_sibling_ptr->p_comm, $kgm_sibling_ptr
+end
+define showproctreeint
+#Initialize all the set variables used in this macro
+    set $kgm_basep1 = 0
+    set $kgm_sibling_ptr = 0
+    set $kgm_lx = 0
+    set $kgm_tmp_base = 0
+    set $kgm_head_ptr = 0
+    set $kgm_search_pid = 0 
+    set $kgm_rev = 0
+    set $kgm_x = 0
+
+    set $kgm_basep1 = (struct proc *)allproc->lh_first
+    if ($arg0 == 0)
+        set $kgm_head_ptr = (struct proc *)initproc
+    end       
+    if ($arg0 > 0)
+        set $kgm_tmp_base = (struct proc *)allproc->lh_first
+        set $kgm_search_pid = $arg0 
+        while $kgm_tmp_base
+            if ( $kgm_tmp_base->p_pid == $kgm_search_pid)
+               if ($kgm_tmp_base->p_childrencnt > 0)
+                    set $kgm_head_ptr = $kgm_tmp_base->p_children.lh_first
+               else
+                    set $kgm_head_ptr = 0
+                    printf "No children present for PID=%d", $kgm_search_pid
+               end
+               loop_break
+            end
+            set $kgm_tmp_base = $kgm_tmp_base->p_list.le_next
+        end
+    end
+    set $kgm_rev = 0
+    set $kgm_x = 0
+    if ($kgm_head_ptr)
+        printf "PID   PROCESS       POINTER]\n"
+        printf "===   =======       =======\n"
+        printf "%d    %s      [ 0x%llx ]\n", $kgm_head_ptr->p_ppid, $kgm_head_ptr->p_pptr->p_comm, $kgm_head_ptr
+        printf "|--%d    %s      [ 0x%llx ]\n", $kgm_head_ptr->p_pid, $kgm_head_ptr->p_comm, $kgm_head_ptr
+    end
+    while ($kgm_head_ptr)
+       #Is childrencnt = 0?       YES  {=> no children}
+        if ($kgm_head_ptr->p_childrencnt == 0)
+            # Does it have sibling? 
+            if($kgm_head_ptr->p_sibling.le_next == 0)
+                #No, it does not have sibling, so go back to its parent which will go to its sibling
+                if($kgm_head_ptr == $kgm_head_ptr->p_pptr)
+                    loop_break
+                end
+                set $kgm_head_ptr = $kgm_head_ptr->p_pptr
+                if ($kgm_head_ptr == $kgm_tmp_base)
+                    loop_break
+                end
+                if ($kgm_x > 3)
+                    set $kgm_x = $kgm_x - 3
+                end
+                set $kgm_rev = 1
+            end
+            if($kgm_head_ptr->p_sibling.le_next != 0)
+                # Yes, it has sibling. So print sibling
+                set $kgm_rev = 0
+                showprocsiblingint $kgm_head_ptr->p_sibling.le_next $kgm_x
+                set $kgm_head_ptr = $kgm_head_ptr->p_sibling.le_next
+            end
+        # childrencnt != 0  {=> it has children}
+        else
+            if ($kgm_rev == 1)
+                if($kgm_head_ptr->p_sibling.le_next == 0)
+                    #No, it does not have sibling, so go back to its parent which will go to its sibling
+                    if($kgm_head_ptr == $kgm_head_ptr->p_pptr)
+                        loop_break
+                    end
+                    set $kgm_head_ptr = $kgm_head_ptr->p_pptr
+                    if ($kgm_head_ptr == $kgm_tmp_base)
+                        loop_break
+                    end
+
+                    if ($kgm_x > 3)
+                        set $kgm_x = $kgm_x - 3
+                    end
+                    set $kgm_rev = 1
+                end
+                if($kgm_head_ptr->p_sibling.le_next != 0)
+                    set $kgm_rev = 0
+                    # Yes, it has sibling. So print sibling
+                    showprocsiblingint $kgm_head_ptr->p_sibling.le_next $kgm_x
+                    set $kgm_head_ptr = $kgm_head_ptr->p_sibling.le_next
+                end
+            else
+                set $kgm_head_ptr = $kgm_head_ptr->p_children.lh_first
+                set $kgm_x = $kgm_x + 3
+                set $kgm_lx = $kgm_x
+                while $kgm_lx
+                    printf "|  "
+                    set $kgm_lx = $kgm_lx-3
+                end
+                printf "|--%d    %s      [ 0x%llx ] \n", $kgm_head_ptr->p_pid, $kgm_head_ptr->p_comm, $kgm_head_ptr
+            end
+        end
+    end
+    printf "\n"
+#Unset all the set variables used in this macro
+    set $kgm_basep1 = 0
+    set $kgm_sibling_ptr = 0
+    set $kgm_lx = 0
+    set $kgm_tmp_base = 0
+    set $kgm_head_ptr = 0
+    set $kgm_search_pid = 0
+    set $kgm_rev = 0
+    set $kgm_x = 0
+end
+define showproctree
+    if ($argc > 0)
+        showproctreeint $arg0
+    else
+        showproctreeint 0
+    end
+end
+document showproctree
+Syntax: (gdb) showproctree <pid>
+| Routine to print the processes in the system in a hierarchical tree form. This routine does not print zombie processes.
+| If no argument is given, showproctree will print all the processes in the system.  
+| If pid is specified, showproctree prints all the descendants of the indicated process
+end
 
 
 define print_vnode
@@ -4549,9 +5726,13 @@ end
 define mbuf_buf2slab
        set $addr = $arg0
        set $gix = ((char *)$addr - (char *)mbutl) >> 20
-       set $ix = ((char *)$addr - (char *)mbutl) >> 11
+       set $ix = ((char *)$addr - (char *)slabstbl[$gix].slg_slab[0].sl_base) >> 12
        set $slab = &slabstbl[$gix].slg_slab[$ix]
-       printf "%p", $slab
+       if $kgm_lp64
+               printf "0x%-16llx", $slab
+       else
+               printf "0x%-8x", $slab
+       end
 end
 
 document mbuf_buf2slab
@@ -4560,11 +5741,15 @@ end
 
 define mbuf_buf2mca
        set $addr = $arg0
-       set $ix = ((char *)$addr - (char *)mbutl) >> 11
-       set $clbase = ((union mcluster *)(mbutl + $ix))
+       set $ix = ((char *)$addr - (char *)mbutl) >> 12
+       set $clbase = ((union mbigcluster *)mbutl) + $ix
        set $mclidx = (((char *)$addr - (char *)$clbase) >> 8)
        set $mca = mclaudit[$ix].cl_audit[$mclidx]
-       printf "mca: %p", $mca
+       if $kgm_lp64
+               printf "mca: 0x%-16llx", $mca
+       else
+               printf "mca: 0x%-8x", $mca
+       end
 end
 
 document mbuf_buf2mca
@@ -4582,11 +5767,11 @@ define mbuf_showmca
        mbuf_mca_ctype $mca 1
        printf "\ncontrolling mcache:\t%p (%s)\n", $mca->mca_cache, $cp->mc_name
        if $mca->mca_uflags & $MB_SCVALID
-               set $ix = ((char *)$mca->mca_addr - (char *)mbutl) >> 11
-               set $clbase = ((union mcluster *)(mbutl + $ix))
+               set $ix = ((char *)$mca->mca_addr - (char *)mbutl) >> 12
+               set $clbase = ((union mbigcluster *)mbutl) + $ix
                set $mclidx = (((char *)$mca->mca_addr - (char *)$clbase) >> 8)
                printf "mbuf obj:\t\t%p\n", $mca->mca_addr
-               printf "mbuf index:\t\t%d (out of 8) in cluster base %p\n", \
+               printf "mbuf index:\t\t%d (out of 16) in cluster base %p\n", \
                    $mclidx + 1, $clbase
                if $mca->mca_uptr != 0
                        set $peer_mca = (mcache_audit_t *)$mca->mca_uptr
@@ -4634,9 +5819,55 @@ Syntax: (gdb) mbuf_showmca <addr>
 | records including the stack trace of the last buffer transaction.
 end
 
-set $MCF_NOCPUCACHE = 0x10
-
-define mcache_stat
+define mbuf_topleak
+       set language c
+       set $topcnt = 0
+       if $arg0 < 5
+               set $maxcnt = $arg0
+       else
+               set $maxcnt = 5
+       end
+       while $topcnt < $maxcnt
+               mbuf_traceleak mleak_top_trace[$topcnt]
+               set $topcnt = $topcnt + 1
+       end
+       set language auto
+end
+
+document mbuf_topleak
+Syntax: (gdb) mbuf_topleak <num>
+| Prints information about the top <num> suspected mbuf leakers
+| where <num> is a value <= 5
+end
+
+define mbuf_traceleak
+       set language c
+       set $trace = (struct mtrace *) $arg0
+       if $trace->allocs != 0
+               printf "%p:%d outstanding allocs\n", $trace, $trace->allocs
+               printf "backtrace saved %d deep:\n", $trace->depth
+               if $trace->depth != 0
+                       set $cnt = 0
+                       while $cnt < $trace->depth
+                               printf "%4d: ", $cnt + 1
+                               pcprint $trace->addr[$cnt]
+                               printf "\n"
+                               set $cnt = $cnt + 1
+                       end
+               end
+       end
+       set language auto
+end
+
+document mbuf_traceleak
+Syntax: (gdb) mbuf_traceleak <addr>
+| Given an mbuf leak trace (mtrace) structure address, print out the
+| stored information with that trace
+end
+
+set $MCF_NOCPUCACHE = 0x10
+
+define mcache_stat
        set $head = (mcache_t *)mcache_head
        set $mc = $head
 
@@ -4773,16 +6004,26 @@ set $NSLABSPMB = sizeof(mcl_slabg_t)/sizeof(mcl_slab_t)
 define mbuf_slabstbl
        set $x = 0
 
-       printf "slot addr       slabs range\n"
-       printf "---- ---------- -----------------------\n"
+       if $kgm_lp64
+               printf "slot slabg              slabs range\n"
+               printf "---- ------------------ -------------------------------------------\n"
+       else
+               printf "slot slabg      slabs range\n"
+               printf "---- ---------- ---------------------------\n"
+       end
        while $x < maxslabgrp
                set $slg = slabstbl[$x]
                printf "%3d: ", $x
                if $slg == 0
                        printf "-\n"
                else
-                       printf "%p [%p-%p]\n", $slg, &$slg->slg_slab[0], \
-                           &$slg->slg_slab[$NSLABSPMB-1]
+                       if $kgm_lp64
+                               printf "0x%-16llx [ 0x%-16llx - 0x%-16llx ]\n", $slg, &$slg->slg_slab[0], \
+                                   &$slg->slg_slab[$NSLABSPMB-1]
+                       else
+                               printf "0x%-8x [ 0x%-8x - 0x%-8x ]\n", $slg, &$slg->slg_slab[0], \
+                                   &$slg->slg_slab[$NSLABSPMB-1]
+                       end
                end
                set $x += 1
        end
@@ -4800,19 +6041,36 @@ define mbuf_slabs
        set $slg = (mcl_slabg_t *)$arg0
        set $x = 0
 
-    if $kgm_lp64
-               printf "slot addr               next               base               C  R  N   size flags\n"
-               printf "---- ------------------ ------------------ ------------------ -- -- -- ------ -----\n"
+       if $kgm_lp64
+               printf "slot slab               next               obj                mca                 C  R  N   size flags\n"
+               printf "---- ------------------ ------------------ ------------------ ------------------ -- -- -- ------ -----\n"
        else
-               printf "slot addr       next       base        C  R  N   size flags\n"
-               printf "---- ---------- ---------- ---------- -- -- -- ------ -----\n"
+               printf "slot slab       next       obj        mca         C  R  N   size flags\n"
+               printf "---- ---------- ---------- ---------- ---------- -- -- -- ------ -----\n"
        end
        while $x < $NSLABSPMB
                set $sl = &$slg->slg_slab[$x]
-               printf "%3d: %p %p %p %2d %2d %2d %6d 0x%04x ", \
-                   $x + 1, $sl, $sl->sl_next, $sl->sl_base, $sl->sl_class, \
-                   $sl->sl_refcnt, $sl->sl_chunks, $sl->sl_len, \
-                   $sl->sl_flags
+               set $mca = 0
+               set $obj = $sl->sl_base
+
+               if mclaudit != 0
+                       set $ix = ((char *)$obj - (char *)mbutl) >> 12
+                       set $clbase = ((union mbigcluster *)mbutl) + $ix
+                       set $mclidx = (((char *)$obj - (char *)$clbase) >> 8)
+                       set $mca = mclaudit[$ix].cl_audit[$mclidx]
+               end
+
+               if $kgm_lp64
+                       printf "%3d: 0x%-16llx 0x%-16llx 0x%-16llx 0x%-16llx %2d %2d %2d %6d 0x%04x ", \
+                           $x + 1, $sl, $sl->sl_next, $obj, $mca, $sl->sl_class, \
+                           $sl->sl_refcnt, $sl->sl_chunks, $sl->sl_len, \
+                           $sl->sl_flags
+               else
+                       printf "%3d: 0x%-8x 0x%-8x 0x%-8x 0x%-8x %2d %2d %2d %6d 0x%04x ", \
+                           $x + 1, $sl, $sl->sl_next, $obj, $mca, $sl->sl_class, \
+                           $sl->sl_refcnt, $sl->sl_chunks, $sl->sl_len, \
+                           $sl->sl_flags
+               end
                if $sl->sl_flags != 0
                        printf "<"
                        if $sl->sl_flags & $SLF_MAPPED
@@ -4827,6 +6085,31 @@ define mbuf_slabs
                        printf ">"
                end
                printf "\n"
+
+               if $sl->sl_chunks > 1
+                       set $z = 1
+                       set $c = $sl->sl_len / $sl->sl_chunks
+
+                       while $z < $sl->sl_chunks
+                               set $obj = $sl->sl_base + ($c * $z)
+                               set $mca = 0
+
+                               if mclaudit != 0
+                                       set $ix = ((char *)$obj - (char *)mbutl) >> 12
+                                       set $clbase = ((union mbigcluster *)mbutl) + $ix
+                                       set $mclidx = (((char *)$obj - (char *)$clbase) >> 8)
+                                       set $mca = mclaudit[$ix].cl_audit[$mclidx]
+                               end
+
+                               if $kgm_lp64
+                                       printf "                                           0x%-16llx 0x%-16llx\n", $obj, $mca
+                               else
+                                       printf "                           0x%-8x 0x%-8x\n", $obj, $mca
+                               end
+                               set $z += 1
+                       end
+               end
+
                set $x += 1
        end
 end
@@ -5088,7 +6371,7 @@ define mbuf_walkallslabs
        end
        printf "objects; this may take a while ...)\n\n"
 
-    if $kgm_lp64
+       if $kgm_lp64
                printf "                        slab                mca                obj        allocation\n"
                printf "slot idx             address            address            address type        state\n"
                printf "---- ---- ------------------ ------------------ ------------------ ----- -----------\n"
@@ -5105,8 +6388,8 @@ define mbuf_walkallslabs
                while $y < $NSLABSPMB && $stop == 0
                        set $sl = &$slg->slg_slab[$y]
                        set $base = (char *)$sl->sl_base
-                       set $ix = ($base - (char *)mbutl) >> 11
-                       set $clbase = ((union mcluster *)(mbutl + $ix))
+                       set $ix = ($base - (char *)mbutl) >> 12
+                       set $clbase = ((union mbigcluster *)mbutl) + $ix
                        set $mclidx = ($base - (char *)$clbase) >> 8
                        set $mca = mclaudit[$ix].cl_audit[$mclidx]
                        set $first = 1
@@ -5123,7 +6406,11 @@ define mbuf_walkallslabs
 
                                if $printmca != 0
                                        if $first == 1
-                                               printf "%4d %4d %p ", $x, $y, $sl
+                                               if $kgm_lp64
+                                                       printf "%4d %4d 0x%-16llx ", $x, $y, $sl
+                                               else
+                                                       printf "%4d %4d 0x%-8x ", $x, $y, $sl
+                                               end
                                        else
                                            if $kgm_lp64
                                                        printf "                             "
@@ -5132,7 +6419,12 @@ define mbuf_walkallslabs
                                            end
                                        end
 
-                                       printf "%p %p ", $mca, $mca->mca_addr
+                                       if $kgm_lp64
+                                               printf "0x%-16llx 0x%-16llx ", $mca, $mca->mca_addr
+                                       else
+                                               printf "0x%-8x 0x%-8x ", $mca, $mca->mca_addr
+                                       end
+
                                        mbuf_mca_ctype $mca 0
                                        if $mca->mca_uflags & ($MB_INUSE|$MB_COMP_INUSE)
                                                printf "active      "
@@ -5181,6 +6473,38 @@ document mbuf_walkallslabs
 | parameter.  This is a backend routine for mbuf_show{active,inactive,all}.
 end
 
+define mbuf_countchain
+       set $mp = (struct mbuf *)$arg0
+       
+       set $pkt = 0
+       set $nxt = 0
+
+       while $mp != 0
+               set $pkt = $pkt + 1
+       
+               set $mn = (struct mbuf *)$mp->m_hdr.mh_next
+               while $mn != 0
+                       set $nxt = $nxt + 1
+                       
+                       set $mn = (struct mbuf *)$mn->m_hdr.mh_next
+               end
+               
+               set $mp = $mp->m_hdr.mh_nextpkt
+
+               if (($pkt + $nxt) % 50) == 0
+                       printf "... %d\n", $pkt + $nxt
+               end
+       end
+
+       printf "\ntotal: %d (via m_next: %d)\n", $pkt + $nxt, $nxt
+end
+
+document mbuf_countchain
+Syntax: mbuf_countchain <addr>
+| Count the total number of mbufs chained from the given the address of an mbuf. 
+| The routine follows both the m_next pointers and m_nextpkt pointers.
+end
+
 set $RTF_UP          = 0x1
 set $RTF_GATEWAY     = 0x2
 set $RTF_HOST        = 0x4
@@ -5205,6 +6529,9 @@ set $RTF_BROADCAST   = 0x400000
 set $RTF_MULTICAST   = 0x800000
 set $RTF_IFSCOPE     = 0x1000000
 set $RTF_CONDEMNED   = 0x2000000
+set $RTF_IFREF       = 0x4000000
+set $RTF_PROXY       = 0x8000000
+set $RTF_ROUTER      = 0x10000000
 
 set $AF_INET = 2
 set $AF_INET6 = 30
@@ -5329,6 +6656,18 @@ define rtentry_prdetails
        if $rt->rt_flags & $RTF_IFSCOPE
                printf "I"
        end
+       if $rt->rt_flags & $RTF_CONDEMNED
+               printf "Z"
+       end
+       if $rt->rt_flags & $RTF_IFREF
+               printf "i"
+       end
+       if $rt->rt_flags & $RTF_PROXY
+               printf "Y"
+       end
+       if $rt->rt_flags & $RTF_ROUTER
+               printf "r"
+       end
 
        printf "/%s%d", $rt->rt_ifp->if_name, $rt->rt_ifp->if_unit
 end
@@ -5564,6 +6903,8 @@ Syntax: (gdb) rtentry_showdbg <addr>
 | parameter.
 end
 
+set $INIFA_TRACE_HIST_SIZE = inifa_trace_hist_size
+
 define inifa_showdbg
        set $inifa = (struct in_ifaddr_dbg *)$arg0
        set $cnt = 0
@@ -5599,7 +6940,7 @@ define inifa_showdbg
                end
                set $ix = $ix + 1
        end
-       while $cnt < $CTRACE_HIST_SIZE
+       while $cnt < $INIFA_TRACE_HIST_SIZE
                set $ix = 0
                while $ix < $CTRACE_STACK_SIZE
                        set $kgm_pc = $inifa->inifa_refhold[$cnt].pc[$ix]
@@ -5617,7 +6958,7 @@ define inifa_showdbg
                set $cnt = $cnt + 1
        end
        set $cnt = 0
-       while $cnt < $CTRACE_HIST_SIZE
+       while $cnt < $INIFA_TRACE_HIST_SIZE
                set $ix = 0
                while $ix < $CTRACE_STACK_SIZE
                        set $kgm_pc = $inifa->inifa_refrele[$cnt].pc[$ix]
@@ -5644,6 +6985,8 @@ Syntax: (gdb) inifa_showdbg <addr>
 | parameter.
 end
 
+set $IN6IFA_TRACE_HIST_SIZE = in6ifa_trace_hist_size
+
 define in6ifa_showdbg
        set $in6ifa = (struct in6_ifaddr_dbg *)$arg0
        set $cnt = 0
@@ -5679,7 +7022,7 @@ define in6ifa_showdbg
                end
                set $ix = $ix + 1
        end
-       while $cnt < $CTRACE_HIST_SIZE
+       while $cnt < $IN6IFA_TRACE_HIST_SIZE
                set $ix = 0
                while $ix < $CTRACE_STACK_SIZE
                        set $kgm_pc = $in6ifa->in6ifa_refhold[$cnt].pc[$ix]
@@ -5697,7 +7040,7 @@ define in6ifa_showdbg
                set $cnt = $cnt + 1
        end
        set $cnt = 0
-       while $cnt < $CTRACE_HIST_SIZE
+       while $cnt < $IN6IFA_TRACE_HIST_SIZE
                set $ix = 0
                while $ix < $CTRACE_STACK_SIZE
                        set $kgm_pc = $in6ifa->in6ifa_refrele[$cnt].pc[$ix]
@@ -5724,139 +7067,681 @@ Syntax: (gdb) in6ifa_showdbg <addr>
 | parameter.
 end
 
-#
-# print all OSMalloc stats 
+set $IFMA_TRACE_HIST_SIZE = ifma_trace_hist_size
 
-define ostag_print
-set $kgm_tagp = (OSMallocTag)$arg0
-printf "0x%08x: ", $kgm_tagp
-printf "%8d ",$kgm_tagp->OSMT_refcnt
-printf "%8x ",$kgm_tagp->OSMT_state
-printf "%8x ",$kgm_tagp->OSMT_attr
-printf "%s ",$kgm_tagp->OSMT_name
-printf "\n"
-end
+define ifma_showdbg
+       set $ifma = (struct ifmultiaddr_dbg *)$arg0
+       set $cnt = 0
 
+       printf "Total holds:\t%d\n", $ifma->ifma_refhold_cnt
+       printf "Total releases:\t%d\n", $ifma->ifma_refrele_cnt
 
-define showosmalloc 
-printf "TAG          COUNT     STATE     ATTR     NAME\n"
-set $kgm_tagheadp = (OSMallocTag)&OSMalloc_tag_list
-    set $kgm_tagptr = (OSMallocTag )($kgm_tagheadp->OSMT_link.next)
-    while $kgm_tagptr != $kgm_tagheadp
-       ostag_print $kgm_tagptr
-       set $kgm_tagptr = (OSMallocTag)$kgm_tagptr->OSMT_link.next
-    end
-       printf "\n"
+       while $cnt < $IFMA_TRACE_HIST_SIZE
+               set $ix = 0
+               while $ix < $CTRACE_STACK_SIZE
+                       set $kgm_pc = $ifma->ifma_refhold[$cnt].pc[$ix]
+                       if $kgm_pc != 0
+                               if $ix == 0
+                                       printf "\nHold [%d] (thread %p):\n", \
+                                         $cnt, $ifma->ifma_refhold[$cnt].th
+                               end
+                               printf "%4d: ", $ix + 1
+                               pcprint $kgm_pc
+                               printf "\n"
+                       end
+                       set $ix = $ix + 1
+               end
+               set $cnt = $cnt + 1
+       end
+       set $cnt = 0
+       while $cnt < $IFMA_TRACE_HIST_SIZE
+               set $ix = 0
+               while $ix < $CTRACE_STACK_SIZE
+                       set $kgm_pc = $ifma->ifma_refrele[$cnt].pc[$ix]
+                       if $kgm_pc != 0
+                               if $ix == 0
+                                       printf "\nRelease [%d] (thread %p):\n",\
+                                         $cnt, $ifma->ifma_refrele[$cnt].th
+                               end
+                               printf "%4d: ", $ix + 1
+                               pcprint $kgm_pc
+                               printf "\n"
+                       end
+                       set $ix = $ix + 1
+               end
+               set $cnt = $cnt + 1
+       end
 end
-document showosmalloc
-Syntax: (gdb) showosmalloc
-| Print the outstanding allocation count by OSMallocTags.
+
+document ifma_showdbg
+Syntax: (gdb) ifma_showdbg <addr>
+| Given a link multicast structure address, print the debug information
+| related to it.  This requires interface address debugging to be turned
+| on, by setting the appropriate flags to the "ifa_debug" boot-args
+| parameter.
 end
 
+set $INM_TRACE_HIST_SIZE = inm_trace_hist_size
 
-define systemlog
-    if msgbufp->msg_bufc[msgbufp->msg_bufx] == 0
-        # The buffer hasn't wrapped, so take the easy (and fast!) path
-        printf "%s", msgbufp->msg_bufc
-    else
-        set $kgm_msgbuf = *msgbufp
-        set $kgm_syslog_bufsize = $kgm_msgbuf.msg_size
-        set $kgm_syslog_bufend = $kgm_msgbuf.msg_bufx
-        if $kgm_syslog_bufend >= $kgm_syslog_bufsize
-            set $kgm_syslog_bufend = 0
-        end
-    
-        # print older messages from msg_bufx to end of buffer
-        set $kgm_i = $kgm_syslog_bufend
-        while $kgm_i < $kgm_syslog_bufsize
-            set $kgm_syslog_char = $kgm_msgbuf.msg_bufc[$kgm_i]
-            if $kgm_syslog_char == 0
-                # break out of loop
-                set $kgm_i = $kgm_syslog_bufsize
-            else
-                printf "%c", $kgm_syslog_char
-            end
-            set $kgm_i = $kgm_i + 1
-        end
-        
-        # print newer messages from start of buffer to msg_bufx
-        set $kgm_i = 0
-        while $kgm_i < $kgm_syslog_bufend
-            set $kgm_syslog_char = $kgm_msgbuf.msg_bufc[$kgm_i]
-            printf "%c", $kgm_syslog_char
-            set $kgm_i = $kgm_i + 1
-        end
-    end
-    printf "\n"
-end
-document systemlog
-| Syntax: systemlog
-| Display the kernel's printf ring buffer
-end
+define inm_showdbg
+       set $inm = (struct in_multi_dbg *)$arg0
+       set $cnt = 0
 
+       printf "Total holds:\t%d\n", $inm->inm_refhold_cnt
+       printf "Total releases:\t%d\n", $inm->inm_refrele_cnt
 
-define hexdump
-       set $kgm_addr = (unsigned char *)$arg0
-       set $kgm_len = $arg1
-       while $kgm_len > 0
-               showptr $kgm_addr
-               printf ": "
-               set $kgm_i = 0
-               while $kgm_i < 16
-                       printf "%02x ", *($kgm_addr+$kgm_i)
-                       set $kgm_i += 1
+       while $cnt < $INM_TRACE_HIST_SIZE
+               set $ix = 0
+               while $ix < $CTRACE_STACK_SIZE
+                       set $kgm_pc = $inm->inm_refhold[$cnt].pc[$ix]
+                       if $kgm_pc != 0
+                               if $ix == 0
+                                       printf "\nHold [%d] (thread %p):\n", \
+                                         $cnt, $inm->inm_refhold[$cnt].th
+                               end
+                               printf "%4d: ", $ix + 1
+                               pcprint $kgm_pc
+                               printf "\n"
+                       end
+                       set $ix = $ix + 1
                end
-               printf " |"
-               set $kgm_i = 0
-               while $kgm_i < 16
-                       set $kgm_temp = *($kgm_addr+$kgm_i)
-                       if $kgm_temp < 32 || $kgm_temp >= 127
-                               printf "."
-                       else
-                               printf "%c", $kgm_temp
+               set $cnt = $cnt + 1
+       end
+       set $cnt = 0
+       while $cnt < $INM_TRACE_HIST_SIZE
+               set $ix = 0
+               while $ix < $CTRACE_STACK_SIZE
+                       set $kgm_pc = $inm->inm_refrele[$cnt].pc[$ix]
+                       if $kgm_pc != 0
+                               if $ix == 0
+                                       printf "\nRelease [%d] (thread %p):\n",\
+                                         $cnt, $inm->inm_refrele[$cnt].th
+                               end
+                               printf "%4d: ", $ix + 1
+                               pcprint $kgm_pc
+                               printf "\n"
                        end
-                       set $kgm_i += 1
+                       set $ix = $ix + 1
                end
-               printf "|\n"
-               set $kgm_addr += 16
-               set $kgm_len -= 16
+               set $cnt = $cnt + 1
        end
 end
-document hexdump
-| Show the contents of memory as a hex/ASCII dump
-| The following is the syntax:
-| (gdb) hexdump <address> <length>
+
+document inm_showdbg
+Syntax: (gdb) inm_showdbg <addr>
+| Given an IPv4 multicast structure address, print the debug information
+| related to it.  This requires interface address debugging to be turned
+| on, by setting the appropriate flags to the "ifa_debug" boot-args
+| parameter.
 end
 
+set $IF_REF_TRACE_HIST_SIZE = if_ref_trace_hist_size
 
-define printcolonhex
-    if ($argc == 2) 
-       set $addr = $arg0
-       set $count = $arg1
-       set $li = 0
-       while ($li < $count)
-           if ($li == 0)
-                       printf "%02x", (u_char)$addr[$li]
-           end
-           if ($li != 0)
-                       printf ":%02x", (u_char)$addr[$li]
-           end
-           set $li = $li + 1
-       end
-    end
-end
+define ifpref_showdbg
+       set $dl_if = (struct dlil_ifnet_dbg *)$arg0
+       set $cnt = 0
 
-define showsockaddr_dl
-    set $sdl = (struct sockaddr_dl *)$arg0
-    if ($sdl == 0)
-               printf "(null)           "
-    else
-           if $sdl->sdl_nlen == 0 && $sdl->sdl_alen == 0 && $sdl->sdl_slen == 0
-               printf "link#%3d         ", $sdl->sdl_index
-           else
-                       set $addr = $sdl->sdl_data + $sdl->sdl_nlen
-                       set $count = $sdl->sdl_alen
-                       printcolonhex $addr $count
+       printf "Total references:\t%d\n", $dl_if->dldbg_if_refhold_cnt
+       printf "Total releases:\t\t%d\n", $dl_if->dldbg_if_refrele_cnt
+
+       while $cnt < $IF_REF_TRACE_HIST_SIZE
+               set $ix = 0
+               while $ix < $CTRACE_STACK_SIZE
+                       set $kgm_pc = $dl_if->dldbg_if_refhold[$cnt].pc[$ix]
+                       if $kgm_pc != 0
+                               if $ix == 0
+                                       printf "\nHold [%d] (thread %p):\n", \
+                                           $cnt, \
+                                           $dl_if->dldbg_if_refhold[$cnt].th
+                               end
+                               printf "%4d: ", $ix + 1
+                               pcprint $kgm_pc
+                               printf "\n"
+                       end
+                       set $ix = $ix + 1
+               end
+               set $cnt = $cnt + 1
+       end
+       set $cnt = 0
+       while $cnt < $IF_REF_TRACE_HIST_SIZE
+               set $ix = 0
+               while $ix < $CTRACE_STACK_SIZE
+                       set $kgm_pc = $dl_if->dldbg_if_refrele[$cnt].pc[$ix]
+                       if $kgm_pc != 0
+                               if $ix == 0
+                                       printf "\nRelease [%d] (thread %p):\n",\
+                                           $cnt, \
+                                           $dl_if->dldbg_if_refrele[$cnt].th
+                               end
+                               printf "%4d: ", $ix + 1
+                               pcprint $kgm_pc
+                               printf "\n"
+                       end
+                       set $ix = $ix + 1
+               end
+               set $cnt = $cnt + 1
+       end
+end
+
+document ifpref_showdbg
+Syntax: (gdb) ifpref_showdbg <addr>
+| Given an ifnet structure address, print the debug information
+| related to its refcnt.  This requires ifnet debugging to be turned
+| on, by setting the appropriate flags to the "ifnet_debug" boot-args
+| parameter.
+end
+
+define in6ifa_trash
+       set $ifa = (struct in6_ifaddr_dbg *)in6ifa_trash_head.tqh_first
+       set $cnt = 0
+       while $ifa != 0
+               if $cnt == 0
+                   if $kgm_lp64
+                               printf "                in6_ifa ref   hold   rele\n"
+                               printf "      ----------------- --- ------ ------\n"
+                       else
+                               printf "        in6_ifa ref   hold   rele\n"
+                               printf "      --------- --- ------ ------\n"
+                       end
+               end
+               printf "%4d: %p %3d %6d %6d ", $cnt + 1, $ifa, \
+                   $ifa->in6ifa_refhold_cnt - $ifa->in6ifa_refrele_cnt, \
+                   $ifa->in6ifa_refhold_cnt, $ifa->in6ifa_refrele_cnt
+               showsockaddr_in6 $ifa->in6ifa.ia_ifa.ifa_addr
+               printf "\n"
+               set $ifa = $ifa->in6ifa_trash_link.tqe_next
+               set $cnt = $cnt + 1
+       end
+end
+
+set $NDPR_TRACE_HIST_SIZE = ndpr_trace_hist_size
+
+define ndpr_showdbg
+       set $ndpr = (struct nd_prefix_dbg *)$arg0
+       set $cnt = 0
+
+       printf "Total references:\t%d\n", $ndpr->ndpr_refhold_cnt
+       printf "Total releases:\t\t%d\n", $ndpr->ndpr_refrele_cnt
+
+       while $cnt < $NDPR_TRACE_HIST_SIZE
+               set $ix = 0
+               while $ix < $CTRACE_STACK_SIZE
+                       set $kgm_pc = $ndpr->ndpr_refhold[$cnt].pc[$ix]
+                       if $kgm_pc != 0
+                               if $ix == 0
+                                       printf "\nHold [%d] (thread %p):\n", \
+                                           $cnt, \
+                                           $ndpr->ndpr_refhold[$cnt].th
+                               end
+                               printf "%4d: ", $ix + 1
+                               pcprint $kgm_pc
+                               printf "\n"
+                       end
+                       set $ix = $ix + 1
+               end
+               set $cnt = $cnt + 1
+       end
+       set $cnt = 0
+       while $cnt < $NDPR_TRACE_HIST_SIZE
+               set $ix = 0
+               while $ix < $CTRACE_STACK_SIZE
+                       set $kgm_pc = $ndpr->ndpr_refrele[$cnt].pc[$ix]
+                       if $kgm_pc != 0
+                               if $ix == 0
+                                       printf "\nRelease [%d] (thread %p):\n",\
+                                           $cnt, \
+                                           $ndpr->ndpr_refrele[$cnt].th
+                               end
+                               printf "%4d: ", $ix + 1
+                               pcprint $kgm_pc
+                               printf "\n"
+                       end
+                       set $ix = $ix + 1
+               end
+               set $cnt = $cnt + 1
+       end
+end
+
+document ndpr_showdbg
+Syntax: (gdb) ndpr_showdbg <addr>
+| Given a nd_prefix structure address, print the debug information
+| related to its refcnt.  This requires the interface address debugging
+| to be turned on, by setting the appropriate flags to the "ifa_debug"
+| boot-args parameter.
+end
+
+set $NDDR_TRACE_HIST_SIZE = nddr_trace_hist_size
+
+define nddr_showdbg
+       set $nddr = (struct nd_defrouter_dbg *)$arg0
+       set $cnt = 0
+
+       printf "Total references:\t%d\n", $nddr->nddr_refhold_cnt
+       printf "Total releases:\t\t%d\n", $nddr->nddr_refrele_cnt
+
+       while $cnt < $NDDR_TRACE_HIST_SIZE
+               set $ix = 0
+               while $ix < $CTRACE_STACK_SIZE
+                       set $kgm_pc = $nddr->nddr_refhold[$cnt].pc[$ix]
+                       if $kgm_pc != 0
+                               if $ix == 0
+                                       printf "\nHold [%d] (thread %p):\n", \
+                                           $cnt, \
+                                           $nddr->nddr_refhold[$cnt].th
+                               end
+                               printf "%4d: ", $ix + 1
+                               pcprint $kgm_pc
+                               printf "\n"
+                       end
+                       set $ix = $ix + 1
+               end
+               set $cnt = $cnt + 1
+       end
+       set $cnt = 0
+       while $cnt < $NDDR_TRACE_HIST_SIZE
+               set $ix = 0
+               while $ix < $CTRACE_STACK_SIZE
+                       set $kgm_pc = $nddr->nddr_refrele[$cnt].pc[$ix]
+                       if $kgm_pc != 0
+                               if $ix == 0
+                                       printf "\nRelease [%d] (thread %p):\n",\
+                                           $cnt, \
+                                           $nddr->nddr_refrele[$cnt].th
+                               end
+                               printf "%4d: ", $ix + 1
+                               pcprint $kgm_pc
+                               printf "\n"
+                       end
+                       set $ix = $ix + 1
+               end
+               set $cnt = $cnt + 1
+       end
+end
+
+document nddr_showdbg
+Syntax: (gdb) nddr_showdbg <addr>
+| Given a nd_defrouter structure address, print the debug information
+| related to its refcnt.  This requires the interface address debugging
+| to be turned on, by setting the appropriate flags to the "ifa_debug"
+| boot-args parameter.
+end
+set $IMO_TRACE_HIST_SIZE = imo_trace_hist_size
+
+define imo_showdbg
+       set $imo = (struct ip_moptions_dbg *)$arg0
+       set $cnt = 0
+
+       printf "Total references:\t%d\n", $imo->imo_refhold_cnt
+       printf "Total releases:\t\t%d\n", $imo->imo_refrele_cnt
+
+       while $cnt < $IMO_TRACE_HIST_SIZE
+               set $ix = 0
+               while $ix < $CTRACE_STACK_SIZE
+                       set $kgm_pc = $imo->imo_refhold[$cnt].pc[$ix]
+                       if $kgm_pc != 0
+                               if $ix == 0
+                                       printf "\nHold [%d] (thread %p):\n", \
+                                           $cnt, \
+                                           $imo->imo_refhold[$cnt].th
+                               end
+                               printf "%4d: ", $ix + 1
+                               pcprint $kgm_pc
+                               printf "\n"
+                       end
+                       set $ix = $ix + 1
+               end
+               set $cnt = $cnt + 1
+       end
+       set $cnt = 0
+       while $cnt < $IMO_TRACE_HIST_SIZE
+               set $ix = 0
+               while $ix < $CTRACE_STACK_SIZE
+                       set $kgm_pc = $imo->imo_refrele[$cnt].pc[$ix]
+                       if $kgm_pc != 0
+                               if $ix == 0
+                                       printf "\nRelease [%d] (thread %p):\n",\
+                                           $cnt, \
+                                           $imo->imo_refrele[$cnt].th
+                               end
+                               printf "%4d: ", $ix + 1
+                               pcprint $kgm_pc
+                               printf "\n"
+                       end
+                       set $ix = $ix + 1
+               end
+               set $cnt = $cnt + 1
+       end
+end
+
+document imo_showdbg
+Syntax: (gdb) imo_showdbg <addr>
+| Given a ip_moptions structure address, print the debug information
+| related to its refcnt.  This requires the interface address debugging
+| to be turned on, by setting the appropriate flags to the "ifa_debug"
+| boot-args parameter.
+end
+
+set $IM6O_TRACE_HIST_SIZE = im6o_trace_hist_size
+
+define im6o_showdbg
+       set $im6o = (struct ip6_moptions_dbg *)$arg0
+       set $cnt = 0
+
+       printf "Total references:\t%d\n", $im6o->im6o_refhold_cnt
+       printf "Total releases:\t\t%d\n", $im6o->im6o_refrele_cnt
+
+       while $cnt < $IM6O_TRACE_HIST_SIZE
+               set $ix = 0
+               while $ix < $CTRACE_STACK_SIZE
+                       set $kgm_pc = $im6o->im6o_refhold[$cnt].pc[$ix]
+                       if $kgm_pc != 0
+                               if $ix == 0
+                                       printf "\nHold [%d] (thread %p):\n", \
+                                           $cnt, \
+                                           $im6o->im6o_refhold[$cnt].th
+                               end
+                               printf "%4d: ", $ix + 1
+                               pcprint $kgm_pc
+                               printf "\n"
+                       end
+                       set $ix = $ix + 1
+               end
+               set $cnt = $cnt + 1
+       end
+       set $cnt = 0
+       while $cnt < $IM6O_TRACE_HIST_SIZE
+               set $ix = 0
+               while $ix < $CTRACE_STACK_SIZE
+                       set $kgm_pc = $im6o->im6o_refrele[$cnt].pc[$ix]
+                       if $kgm_pc != 0
+                               if $ix == 0
+                                       printf "\nRelease [%d] (thread %p):\n",\
+                                           $cnt, \
+                                           $im6o->im6o_refrele[$cnt].th
+                               end
+                               printf "%4d: ", $ix + 1
+                               pcprint $kgm_pc
+                               printf "\n"
+                       end
+                       set $ix = $ix + 1
+               end
+               set $cnt = $cnt + 1
+       end
+end
+
+document im6o_showdbg
+Syntax: (gdb) im6o_showdbg <addr>
+| Given a ip6_moptions structure address, print the debug information
+| related to its refcnt.  This requires the interface address debugging
+| to be turned on, by setting the appropriate flags to the "ifa_debug"
+| boot-args parameter.
+end
+
+document in6ifa_trash
+Syntax: (gdb) in6ifa_trash
+| Walk the list of trash in6_ifaddr entries; this requires interface
+| address debugging to be turned on, by setting the appropriate flags
+| to the "ifa_debug" boot-args parameter.
+end
+
+define inifa_trash
+       set $ifa = (struct in_ifaddr_dbg *)inifa_trash_head.tqh_first
+       set $cnt = 0
+       while $ifa != 0
+               if $cnt == 0
+                   if $kgm_lp64
+                               printf "                 in_ifa ref   hold   rele\n"
+                               printf "      ----------------- --- ------ ------\n"
+                       else
+                               printf "         in_ifa ref   hold   rele\n"
+                               printf "      --------- --- ------ ------\n"
+                       end
+               end
+               printf "%4d: %p %3d %6d %6d ", $cnt + 1, $ifa, \
+                   $ifa->inifa_refhold_cnt - $ifa->inifa_refrele_cnt, \
+                   $ifa->inifa_refhold_cnt, $ifa->inifa_refrele_cnt
+               showsockaddr_in $ifa->inifa.ia_ifa.ifa_addr
+               printf "\n"
+               set $ifa = $ifa->inifa_trash_link.tqe_next
+               set $cnt = $cnt + 1
+       end
+end
+
+document inifa_trash
+Syntax: (gdb) inifa_trash
+| Walk the list of trash in_ifaddr entries; this requires interface
+| address debugging to be turned on, by setting the appropriate flags
+| to the "ifa_debug" boot-args parameter.
+end
+
+define ifma_trash
+       set $ifma = (struct ifmultiaddr_dbg *)ifma_trash_head.tqh_first
+       set $cnt = 0
+       while $ifma != 0
+               if $cnt == 0
+                   if $kgm_lp64
+                               printf "                   ifma ref   hold   rele\n"
+                               printf "      ----------------- --- ------ ------\n"
+                       else
+                               printf "          ifma  ref   hold   rele\n"
+                               printf "      --------- --- ------ ------\n"
+                       end
+               end
+               printf "%4d: %p %3d %6d %6d ", $cnt + 1, $ifma, \
+                   $ifma->ifma_refhold_cnt - $ifma->ifma_refrele_cnt, \
+                   $ifma->ifma_refhold_cnt, $ifma->ifma_refrele_cnt
+               showsockaddr $ifma->ifma.ifma_addr
+               printf " @ %s%d", $ifma->ifma.ifma_ifp->if_name, \
+                   $ifma->ifma.ifma_ifp->if_unit
+               printf "\n"
+               set $ifma = $ifma->ifma_trash_link.tqe_next
+               set $cnt = $cnt + 1
+       end
+end
+
+document ifma_trash
+Syntax: (gdb) ifma_trash
+| Walk the list of trash ifmultiaddr entries; this requires interface
+| address debugging to be turned on, by setting the appropriate flags
+| to the "ifa_debug" boot-args parameter.
+end
+
+define inm_trash
+       set $inm = (struct in_multi_dbg *)inm_trash_head.tqh_first
+       set $cnt = 0
+       while $inm != 0
+               if $cnt == 0
+                   if $kgm_lp64
+                               printf "                    inm ref   hold   rele\n"
+                               printf "      ----------------- --- ------ ------\n"
+                       else
+                               printf "            inm ref   hold   rele\n"
+                               printf "      --------- --- ------ ------\n"
+                       end
+               end
+               printf "%4d: %p %3d %6d %6d ", $cnt + 1, $inm, \
+                   $inm->inm_refhold_cnt - $inm->inm_refrele_cnt, \
+                   $inm->inm_refhold_cnt, $inm->inm_refrele_cnt
+               show_in_addr &($inm->inm.inm_addr)
+               printf "\n"
+               set $inm = $inm->inm_trash_link.tqe_next
+               set $cnt = $cnt + 1
+       end
+end
+
+document inm_trash
+Syntax: (gdb) inm_trash
+| Walk the list of trash in_multi entries; this requires interface
+| address debugging to be turned on, by setting the appropriate flags
+| to the "ifa_debug" boot-args parameter.
+end
+
+define in6m_trash
+       set $in6m = (struct in6_multi_dbg *)in6m_trash_head.tqh_first
+       set $cnt = 0
+       while $in6m != 0
+               if $cnt == 0
+                   if $kgm_lp64
+                               printf "                   in6m ref   hold   rele\n"
+                               printf "      ----------------- --- ------ ------\n"
+                       else
+                               printf "           in6m ref   hold   rele\n"
+                               printf "      --------- --- ------ ------\n"
+                       end
+               end
+               printf "%4d: %p %3d %6d %6d ", $cnt + 1, $in6m, \
+                   $in6m->in6m_refhold_cnt - $in6m->in6m_refrele_cnt, \
+                   $in6m->in6m_refhold_cnt, $in6m->in6m_refrele_cnt
+               show_in_addr &($in6m->in6m.in6m_addr)
+               printf "\n"
+               set $in6m = $in6m->in6m_trash_link.tqe_next
+               set $cnt = $cnt + 1
+       end
+end
+
+document in6m_trash
+Syntax: (gdb) in6m_trash
+| Walk the list of trash in6_multi entries; this requires interface
+| address debugging to be turned on, by setting the appropriate flags
+| to the "ifa_debug" boot-args parameter.
+end
+
+#
+# print all OSMalloc stats 
+
+define ostag_print
+set $kgm_tagp = (OSMallocTag)$arg0
+printf "0x%08x: ", $kgm_tagp
+printf "%8d ",$kgm_tagp->OSMT_refcnt
+printf "%8x ",$kgm_tagp->OSMT_state
+printf "%8x ",$kgm_tagp->OSMT_attr
+printf "%s ",$kgm_tagp->OSMT_name
+printf "\n"
+end
+
+
+define showosmalloc 
+printf "TAG          COUNT     STATE     ATTR     NAME\n"
+set $kgm_tagheadp = (struct _OSMallocTag_ *)&OSMalloc_tag_list
+    set $kgm_tagptr = (struct _OSMallocTag_ * )($kgm_tagheadp->OSMT_link.next)
+    while $kgm_tagptr != $kgm_tagheadp
+       ostag_print $kgm_tagptr
+       set $kgm_tagptr = (struct _OSMallocTag_ *)$kgm_tagptr->OSMT_link.next
+    end
+       printf "\n"
+end
+document showosmalloc
+Syntax: (gdb) showosmalloc
+| Print the outstanding allocation count by OSMallocTags.
+end
+
+
+define systemlog
+    if msgbufp->msg_bufc[msgbufp->msg_bufx] == 0 \
+       && msgbufp->msg_bufc[0] != 0
+        # The buffer hasn't wrapped, so take the easy (and fast!) path
+        printf "%s", msgbufp->msg_bufc
+    else
+        set $kgm_msgbuf = *msgbufp
+        set $kgm_syslog_bufsize = $kgm_msgbuf.msg_size
+        set $kgm_syslog_bufend = $kgm_msgbuf.msg_bufx
+        if $kgm_syslog_bufend >= $kgm_syslog_bufsize
+            set $kgm_syslog_bufend = 0
+        end
+    
+        # print older messages from msg_bufx to end of buffer
+        set $kgm_i = $kgm_syslog_bufend
+        while $kgm_i < $kgm_syslog_bufsize
+            set $kgm_syslog_char = $kgm_msgbuf.msg_bufc[$kgm_i]
+            if $kgm_syslog_char == 0
+                # break out of loop
+                set $kgm_i = $kgm_syslog_bufsize
+            else
+                printf "%c", $kgm_syslog_char
+            end
+            set $kgm_i = $kgm_i + 1
+        end
+        
+        # print newer messages from start of buffer to msg_bufx
+        set $kgm_i = 0
+        while $kgm_i < $kgm_syslog_bufend
+            set $kgm_syslog_char = $kgm_msgbuf.msg_bufc[$kgm_i]
+            if $kgm_syslog_char != 0
+                printf "%c", $kgm_syslog_char
+            end
+            set $kgm_i = $kgm_i + 1
+        end
+    end
+    printf "\n"
+end
+document systemlog
+| Syntax: systemlog
+| Display the kernel's printf ring buffer
+end
+
+
+define hexdump
+       set $kgm_addr = (unsigned char *)$arg0
+       set $kgm_len = $arg1
+       while $kgm_len > 0
+               showptr $kgm_addr
+               printf ": "
+               set $kgm_i = 0
+               while $kgm_i < 16
+                       printf "%02x ", *($kgm_addr+$kgm_i)
+                       set $kgm_i += 1
+               end
+               printf " |"
+               set $kgm_i = 0
+               while $kgm_i < 16
+                       set $kgm_temp = *($kgm_addr+$kgm_i)
+                       if $kgm_temp < 32 || $kgm_temp >= 127
+                               printf "."
+                       else
+                               printf "%c", $kgm_temp
+                       end
+                       set $kgm_i += 1
+               end
+               printf "|\n"
+               set $kgm_addr += 16
+               set $kgm_len -= 16
+       end
+end
+document hexdump
+| Show the contents of memory as a hex/ASCII dump
+| The following is the syntax:
+| (gdb) hexdump <address> <length>
+end
+
+
+define printcolonhex
+    if ($argc == 2) 
+       set $addr = $arg0
+       set $count = $arg1
+       set $li = 0
+       while ($li < $count)
+           if ($li == 0)
+                       printf "%02x", (u_char)$addr[$li]
+           end
+           if ($li != 0)
+                       printf ":%02x", (u_char)$addr[$li]
+           end
+           set $li = $li + 1
+       end
+    end
+end
+
+define showsockaddr_dl
+    set $sdl = (struct sockaddr_dl *)$arg0
+    if ($sdl == 0)
+               printf "(null)           "
+    else
+           if $sdl->sdl_nlen == 0 && $sdl->sdl_alen == 0 && $sdl->sdl_slen == 0
+               printf "link#%3d         ", $sdl->sdl_index
+           else
+                       set $addr = $sdl->sdl_data + $sdl->sdl_nlen
+                       set $count = $sdl->sdl_alen
+                       printcolonhex $addr $count
                end
     end
 end
@@ -5875,17 +7760,27 @@ define showsockaddr_at
     printcolonhex $addr $count
 end
 
+define show_in_addr
+    set $ia = (unsigned char *)$arg0
+    printf "%3u.%03u.%03u.%03u", $ia[0], $ia[1], $ia[2], $ia[3]
+end
+
 define showsockaddr_in
     set $sin = (struct sockaddr_in *)$arg0
     set $sa_bytes = (unsigned char *)&($sin->sin_addr)
-    printf "%3u.%03u.%03u.%03u", $sa_bytes[0], $sa_bytes[1], $sa_bytes[2], $sa_bytes[3]
+    show_in_addr $sa_bytes
+end
+
+define show_in6_addr
+    set $ia = (unsigned char *)$arg0
+    printf "%2x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x", \
+       $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]
 end
 
 define showsockaddr_in6
     set $sin6 = (struct sockaddr_in6 *)$arg0
     set $sa_bytes = $sin6->sin6_addr.__u6_addr.__u6_addr8
-    printf "%2x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x", \
-       $sa_bytes[0], $sa_bytes[1], $sa_bytes[2], $sa_bytes[3], $sa_bytes[4], $sa_bytes[5], $sa_bytes[6], $sa_bytes[7], $sa_bytes[8], $sa_bytes[9], $sa_bytes[10], $sa_bytes[11], $sa_bytes[12], $sa_bytes[13], $sa_bytes[14], $sa_bytes[15]
+    show_in6_addr $sa_bytes
 end
 
 define showsockaddr_un
@@ -5907,7 +7802,7 @@ define showifmultiaddrs
    set $mymulti = $if_multi
    set $myi = 0
    while ($mymulti != 0)
-       printf "%2d. ", $myi
+       printf "%2d. %p ", $myi, $mymulti
        set $sa_family = $mymulti->ifma_addr.sa_family
        if ($sa_family == 2)
            if ($mymulti->ifma_ll != 0)
@@ -5941,6 +7836,48 @@ Syntax showifmultiaddrs <ifp>
 | show the (struct ifnet).if_multiaddrs list of multicast addresses for the given ifp
 end
 
+define showinmultiaddrs
+   set $in_multi = (struct in_multi *)(in_multihead->lh_first)
+   set $mymulti = $in_multi
+   set $myi = 0
+   while ($mymulti != 0)
+       set $ifp = (struct ifnet *)$mymulti->inm_ifp
+       printf "%2d. %p ", $myi, $mymulti
+       show_in_addr &($mymulti->inm_addr)
+       printf " (ifp %p [%s%d] ifma %p) ", $ifp, $ifp->if_name, \
+           $ifp->if_unit, $mymulti->inm_ifma
+       printf "\n"
+       set $mymulti = $mymulti->inm_link.le_next
+       set $myi = $myi + 1
+   end
+end
+
+document showinmultiaddrs
+Syntax showinmultiaddrs
+| show the contents of IPv4 multicast address records
+end
+
+define showin6multiaddrs
+   set $in6_multi = (struct in6_multi *)(in6_multihead->lh_first)
+   set $mymulti = $in6_multi
+   set $myi = 0
+   while ($mymulti != 0)
+       set $ifp = (struct ifnet *)$mymulti->in6m_ifp
+       printf "%2d. %p ", $myi, $mymulti
+       show_in6_addr &($mymulti->in6m_addr)
+       printf " (ifp %p [%s%d] ifma %p) ", $ifp, $ifp->if_name, \
+           $ifp->if_unit, $mymulti->in6m_ifma
+       printf "\n"
+       set $mymulti = $mymulti->in6m_entry.le_next
+       set $myi = $myi + 1
+   end
+end
+
+document showin6multiaddrs
+Syntax showin6multiaddrs
+| show the contents of IPv6 multicast address records
+end
+
 define showsockaddr
     set $mysock = (struct sockaddr *)$arg0
     set $showsockaddr_handled = 0
@@ -6021,10 +7958,10 @@ define showifflags
            end
            printf "POINTTOPOINT"
        end
-#      if ($flags & 0x20)
-#          if ($first == 1)
+##     if ($flags & 0x20)
+##         if ($first == 1)
 #              set $first = 0
-#          else
+##         else
 #              printf ","
 #          end
 #          printf "NOTRAILERS"
@@ -6117,7 +8054,7 @@ define showifaddrs
    set $myifaddr = (struct ifaddr *)$ifp->if_addrhead->tqh_first
    set $myi = 0
    while ($myifaddr != 0)
-       printf "\t%d. ", $myi
+       printf "\t%d. %p ", $myi, $myifaddr
        showsockaddr $myifaddr->ifa_addr
        printf " [%d]\n", $myifaddr->ifa_refcnt
        set $myifaddr = $myifaddr->ifa_link->tqe_next
@@ -6135,7 +8072,7 @@ define ifconfig
    if ($argc == 1)
        set $ifconfig_all = 1
    end
-   set $ifp = (struct ifnet *)(ifnet->tqh_first)
+   set $ifp = (struct ifnet *)(ifnet_head->tqh_first)
    while ($ifp != 0)
        printf "%s%d: flags=%hx", $ifp->if_name, $ifp->if_unit, (u_short)$ifp->if_flags
        showifflags $ifp->if_flags
@@ -6155,6 +8092,44 @@ Syntax: (gdb) ifconfig
 | display ifconfig-like output, and print the (struct ifnet *) pointers for further inspection
 end
 
+set $DLIF_INUSE        = 0x1
+set $DLIF_REUSE        = 0x2
+
+define showifnets
+       set $all = 0
+       if ($argc == 1)
+               set $all = 1
+       end
+       set $dlifp = (struct dlil_ifnet *)(dlil_ifnet_head->tqh_first)
+       while ($dlifp != 0)
+               set $ifp = (struct ifnet *)$dlifp
+               if ($dlifp->dl_if_flags & $DLIF_REUSE)
+                       printf "*"
+               end
+               if ($dlifp->dl_if_flags & $DLIF_INUSE)
+                       printf "%s%d: ", $ifp->if_name, $ifp->if_unit
+               else
+                       printf "[%s%d]: ", $ifp->if_name, $ifp->if_unit
+               end
+               printf "flags=%hx", (u_short)$ifp->if_flags
+               showifflags $ifp->if_flags
+               printf " index %d", $ifp->if_index
+               printf " mtu %d\n", $ifp->if_data.ifi_mtu
+               printf "\t(struct ifnet *)"
+               showptr $ifp
+               printf "\n"
+               if ($all == 1) 
+                       showifaddrs $ifp
+               end
+               set $dlifp = $dlifp->dl_if_link->tqe_next
+       end
+end
+
+document showifnets
+Syntax: (gdb) showifnets
+| Display ifconfig-like output for all attached and detached interfaces
+end
+
 define _show_unix_domain_socket
        set $so = (struct socket *)$arg0
        set $pcb = (struct unpcb *)$so->so_pcb
@@ -6395,7 +8370,7 @@ set $INP_ANONPORT=0x40
 set $INP_RECVIF=0x80
 set $INP_MTUDISC=0x100
 set $INP_STRIPHDR=0x200
-set $INP_FAITH=0x400
+set $INP_RECV_ANYIF=0x400
 set $INP_INADDR_ANY=0x800
 set $INP_RECVTTL=0x1000
 set $INP_UDP_NOCKSUM=0x2000
@@ -6499,8 +8474,8 @@ define _dump_inpcb
        if ($pcb->inp_flags & $INP_STRIPHDR)
                printf "striphdr "
        end
-       if ($pcb->inp_flags & $INP_FAITH)
-               printf "faith "
+       if ($pcb->inp_flags & $INP_RECV_ANYIF)
+               printf "recv_anyif "
        end
        if ($pcb->inp_flags & $INP_INADDR_ANY)
                printf "inaddr_any "
@@ -6568,7 +8543,9 @@ set $UDBHASHSIZE=16
 
 define _dump_pcbinfo
        set $snd_cc = 0
+       set $snd_buf = (unsigned int)0
        set $rcv_cc = 0
+       set $rcv_buf = (unsigned int)0
        set $pcbseen = 0
        set $pcbi = (struct inpcbinfo *)$arg0
        printf "lastport %d lastlow %d lasthi %d\n", \
@@ -6596,7 +8573,23 @@ define _dump_pcbinfo
                                set $so = (struct socket *)$pcb->inp_socket
                                if $so != 0
                                        set $snd_cc += $so->so_snd.sb_cc
-                                       set $rcv_cc += $so-> so_rcv.sb_cc
+                                       set $mp = $so->so_snd.sb_mb
+                                       while $mp
+                                               set $snd_buf += 256
+                                               if ($mp->m_hdr.mh_flags & 0x01)
+                                                       set $snd_buf += $mp->M_dat.MH.MH_dat.MH_ext.ext_size
+                                               end
+                                               set $mp = $mp->m_hdr.mh_next
+                                       end
+                                       set $rcv_cc += $so->so_rcv.sb_cc
+                                       set $mp = $so->so_rcv.sb_mb
+                                       while $mp
+                                               set $rcv_buf += 256
+                                               if ($mp->m_hdr.mh_flags & 0x01)
+                                                       set $rcv_buf += $mp->M_dat.MH.MH_dat.MH_ext.ext_size
+                                               end
+                                               set $mp = $mp->m_hdr.mh_next
+                                       end
                                end
                                set $pcb0 = $pcb0->inp_hash.le_next
                                printf "\n"
@@ -6607,6 +8600,7 @@ define _dump_pcbinfo
                set $head = *(uintptr_t *)$hashbase
        end
        printf "total seen %ld snd_cc %ld rcv_cc %ld\n", $pcbseen, $snd_cc, $rcv_cc
+       printf "total snd_buf %u rcv_buf %u \n", (unsigned int)$snd_buf, (unsigned int)$rcv_buf
        printf "port hash base is %p\n", $pcbi->porthashbase
        set $i = 0
        set $hashbase = $pcbi->porthashbase
@@ -6827,10 +8821,16 @@ define showvnodeint
 
        showptr $kgm_vnode->v_parent
     printf "  "
-       if $kgm_vnode->v_name != 0
+       if ($kgm_vnode->v_name != 0)
                printf "%s\n", $kgm_vnode->v_name
-       else
-               printf "\n"
+       else 
+               # If this is HFS vnode, get name from the cnode
+               if ($kgm_vnode->v_tag == 16) 
+                       set $kgm_cnode = (struct cnode *)$kgm_vnode->v_data
+                       printf "hfs: %s\n", (char *)$kgm_cnode->c_desc->cd_nameptr
+               else 
+                       printf "\n"
+               end
        end
 end
 
@@ -7037,7 +9037,7 @@ define showbootermemorymap
             set $kgm_mptr = (EfiMemoryRange *)((unsigned long)kernelBootArgs->MemoryMap + $kgm_voffset + $kgm_i * $kgm_msize)
 #           p/x *$kgm_mptr
             if $kgm_mptr->Type == 0
-              printf "reserved  "
+              printf "Reserved  "
             end
             if $kgm_mptr->Type == 1
               printf "LoaderCode"
@@ -7058,7 +9058,7 @@ define showbootermemorymap
               printf "RT_data   "
             end
             if $kgm_mptr->Type == 7
-              printf "available "
+              printf "Convention"
             end
             if $kgm_mptr->Type == 8
               printf "Unusable  "
@@ -7100,24 +9100,25 @@ end
 
 
 define showstacksaftertask
-    set $kgm_head_taskp = &default_pset.tasks
+    set $kgm_head_taskp = &tasks
     set $kgm_taskp = (struct task *)$arg0
+    set $kgm_taskp = (struct task *)$kgm_taskp->tasks.next
     while $kgm_taskp != $kgm_head_taskp
-        showtaskheader
-        showtaskint $kgm_taskp
-        set $kgm_head_actp = &($kgm_taskp->threads)
-        set $kgm_actp = (struct thread *)($kgm_taskp->threads.next) 
-        while $kgm_actp != $kgm_head_actp
-            showactheader
-            if ($decode_wait_events > 0)
-               showactint $kgm_actp 1
-            else
-               showactint $kgm_actp 2
-            end
-            set $kgm_actp = (struct thread *)($kgm_actp->task_threads.next)
-        end
-        printf "\n"
-        set $kgm_taskp = (struct task *)($kgm_taskp->pset_tasks.next)
+       showtaskheader
+       showtaskint $kgm_taskp
+       set $kgm_head_actp = &($kgm_taskp->threads)
+       set $kgm_actp = (struct thread *)($kgm_taskp->threads.next)
+       while $kgm_actp != $kgm_head_actp
+           showactheader
+           if ($decode_wait_events > 0)
+              showactint $kgm_actp 1
+           else
+              showactint $kgm_actp 2
+           end
+           set $kgm_actp = (struct thread *)($kgm_actp->task_threads.next)
+       end
+       printf "\n"
+       set $kgm_taskp = (struct task *)($kgm_taskp->tasks.next)
     end
 end
 document showstacksaftertask
@@ -7127,20 +9128,19 @@ Syntax: (gdb) showstacksaftertask <task>
 end
 
 define showpmworkqueueint
-    set $kgm_pm_wq = (IOPMWorkQueue *)$arg0
-    set $kgm_pm_node = (IOService *)$kgm_pm_wq->owner
-    showptr $kgm_pm_wq
-    printf "  "
-    showptr $kgm_pm_node
-    printf "  "
-    printf "%02d  ", $kgm_pm_node->pwrMgt->CurrentPowerState
-    printf "%02d  ", $kgm_pm_node->pwrMgt->MachineState
-    printf "%02d  ", $kgm_pm_node->pwrMgt->WaitReason
-    printf "%s\n", $kgm_pm_node->pwrMgt->Name
-    set $kgm_pm_queue = &($kgm_pm_wq->fWorkQueue)
-    set $kgm_pm_req = (IOPMRequest *)$kgm_pm_queue->next
-    if ((queue_entry_t) $kgm_pm_req != (queue_entry_t) $kgm_pm_queue)
-        printf "\n"
+    set $kgm_pm_workqueue = (IOPMWorkQueue *)$arg0
+    set $kgm_pm_wq = &($kgm_pm_workqueue->fWorkQueue)
+    set $kgm_pm_wqe = (IOServicePM *)$kgm_pm_wq->next
+    while ((queue_entry_t) $kgm_pm_wqe != (queue_entry_t) $kgm_pm_wq)
+        printf "service   "
+        showptrhdrpad
+        printf "  ps  ms  wr  name\n"
+        showptr $kgm_pm_wqe->Owner
+        printf "  "
+        printf "%02d  ", $kgm_pm_wqe->CurrentPowerState
+        printf "%02d  ", $kgm_pm_wqe->MachineState
+        printf "%02d  ", $kgm_pm_wqe->WaitReason
+        printf "%s\n", $kgm_pm_wqe->Name
         printf "request   "
         showptrhdrpad
         printf "  type  next      "
@@ -7148,158 +9148,179 @@ define showpmworkqueueint
         printf "  root      "
         showptrhdrpad
         printf "  work_wait   free_wait\n"
-        while ((queue_entry_t) $kgm_pm_req != (queue_entry_t) $kgm_pm_queue)
-            showptr $kgm_pm_req
-            printf "  0x%02x  ", $kgm_pm_req->fType
-            showptr $kgm_pm_req->fRequestNext
+        set $kgm_pm_rq = &($kgm_pm_wqe->RequestHead)
+        set $kgm_pm_rqe = (IOPMRequest *)$kgm_pm_rq->next
+        while ((queue_entry_t) $kgm_pm_rqe != (queue_entry_t) $kgm_pm_rq)
+            showptr $kgm_pm_rqe
+            printf "  0x%02x  ", $kgm_pm_rqe->fType
+            showptr $kgm_pm_rqe->fRequestNext
             printf "  "
-            showptr $kgm_pm_req->fRequestRoot
-            printf "  0x%08x  0x%08x\n", $kgm_pm_req->fWorkWaitCount, $kgm_pm_req->fFreeWaitCount
+            showptr $kgm_pm_rqe->fRequestRoot
+            printf "  0x%08x  0x%08x\n", $kgm_pm_rqe->fWorkWaitCount, $kgm_pm_rqe->fFreeWaitCount
             showptrhdrpad
             printf "            args  "
-            showptr $kgm_pm_req->fArg0
+            showptr $kgm_pm_rqe->fArg0
             printf "  "
-            showptr $kgm_pm_req->fArg1
+            showptr $kgm_pm_rqe->fArg1
             printf "  "
-            showptr $kgm_pm_req->fArg2
+            showptr $kgm_pm_rqe->fArg2
             printf "\n"
-            set $kgm_pm_req = (IOPMRequest *)$kgm_pm_req->fCommandChain.next
+            set $kgm_pm_rqe = (IOPMRequest *)$kgm_pm_rqe->fCommandChain.next
         end
         printf "\n"
+        set $kgm_pm_wqe = (IOServicePM *)$kgm_pm_wqe->WorkChain.next
+    end
+end
+
+define showpmworkqueue
+    printf "IOPMWorkQueue "
+    showptr gIOPMWorkQueue
+    printf " length "
+    printf "%u", gIOPMWorkQueue->fQueueLength
+    printf "\n"
+    if (gIOPMWorkQueue->fQueueLength > 0)
+        showpmworkqueueint gIOPMWorkQueue
+    end
+end
+
+document showpmworkqueue
+Syntax: (gdb) showpmworkqueue
+| Display the IOPMWorkQueue object
+end
+
+define showioservicepm
+    set $kgm_iopmpriv = (IOServicePM *)$arg0
+    printf "{ "
+    printf "MachineState = %d (", $kgm_iopmpriv->MachineState
+    if ( $kgm_iopmpriv->MachineState == 0 )
+        printf "kIOPM_Finished"
+    else
+    if ( $kgm_iopmpriv->MachineState == 1 )
+        printf "kIOPM_OurChangeTellClientsPowerDown"
+    else
+    if ( $kgm_iopmpriv->MachineState == 2 )
+        printf "kIOPM_OurChangeTellPriorityClientsPowerDown"
+    else
+    if ( $kgm_iopmpriv->MachineState == 3 )
+        printf "kIOPM_OurChangeNotifyInterestedDriversWillChange"
+    else
+    if ( $kgm_iopmpriv->MachineState == 4 )
+        printf "kIOPM_OurChangeSetPowerState"
+    else
+    if ( $kgm_iopmpriv->MachineState == 5 )
+        printf "kIOPM_OurChangeWaitForPowerSettle"
+    else
+    if ( $kgm_iopmpriv->MachineState == 6 )
+        printf "kIOPM_OurChangeNotifyInterestedDriversDidChange"
+    else
+    if ( $kgm_iopmpriv->MachineState == 7 )
+        printf "kIOPM_OurChangeTellCapabilityDidChange"
+    else
+    if ( $kgm_iopmpriv->MachineState == 8 )
+        printf "kIOPM_OurChangeFinish"
+    else
+    if ( $kgm_iopmpriv->MachineState == 9 )
+        printf "Unused_MachineState_9"
+    else
+    if ( $kgm_iopmpriv->MachineState == 10 )
+        printf "kIOPM_ParentChangeTellPriorityClientsPowerDown"
+    else
+    if ( $kgm_iopmpriv->MachineState == 11 )
+        printf "kIOPM_ParentChangeNotifyInterestedDriversWillChange"
+    else
+    if ( $kgm_iopmpriv->MachineState == 12 )
+        printf "kIOPM_ParentChangeSetPowerState"
+    else
+    if ( $kgm_iopmpriv->MachineState == 13 )
+        printf "kIOPM_ParentChangeWaitForPowerSettle"
+    else
+    if ( $kgm_iopmpriv->MachineState == 14)
+        printf "kIOPM_ParentChangeNotifyInterestedDriversDidChange"
+    else
+    if ( $kgm_iopmpriv->MachineState == 15)
+        printf "kIOPM_ParentChangeTellCapabilityDidChange"
+    else
+    if ( $kgm_iopmpriv->MachineState == 16)
+        printf "kIOPM_ParentChangeAcknowledgePowerChange"
+    else
+    if ( $kgm_iopmpriv->MachineState == 17)
+        printf "kIOPM_NotifyChildrenStart"
+    else
+    if ( $kgm_iopmpriv->MachineState == 18)
+        printf "kIOPM_NotifyChildrenOrdered"
+    else
+    if ( $kgm_iopmpriv->MachineState == 19)
+        printf "kIOPM_NotifyChildrenDelayed"
+    else
+    if ( $kgm_iopmpriv->MachineState == 20)
+        printf "kIOPM_SyncTellClientsPowerDown"
+    else
+    if ( $kgm_iopmpriv->MachineState == 21)
+        printf "kIOPM_SyncTellPriorityClientsPowerDown"
+    else
+    if ( $kgm_iopmpriv->MachineState == 22)
+        printf "kIOPM_SyncNotifyWillChange"
+    else
+    if ( $kgm_iopmpriv->MachineState == 23)
+        printf "kIOPM_SyncNotifyDidChange"
+    else
+    if ( $kgm_iopmpriv->MachineState == 24)
+        printf "kIOPM_SyncTellCapabilityDidChange"
+    else
+    if ( $kgm_iopmpriv->MachineState == 25)
+        printf "kIOPM_SyncFinish"
+    else
+    if ( $kgm_iopmpriv->MachineState == 26)
+        printf "kIOPM_TellCapabilityChangeDone"
+    else
+    if ( $kgm_iopmpriv->MachineState == 27)
+        printf "kIOPM_DriverThreadCallDone"
+    else
+        printf "Unknown_MachineState"
+    end
+    end
+    end
+    end
+    end
+    end
+    end
+    end
+    end
+    end
+    end
+    end
+    end
+    end
+    end
+    end
+    end
+    end
+    end
+    end
+    end
+    end
+    end
+    end
+    end
     end
-end
-
-define showallpmworkqueues
-    set $kgm_pm_next = gIOPMWorkLoop->eventChain
-    printf "queue     "
-    showptrhdrpad
-    printf "  owner     "
-    showptrhdrpad
-    printf "  ps  ms  wr  name\n"
-    while ( $kgm_pm_next )
-        set $kgm_vt = *((void **) $kgm_pm_next)
-        if ($kgm_lp64 || $kgm_mtype == $kgm_mtype_arm)
-            set $kgm_vt = $kgm_vt -  2 * sizeof(void *)
-        end
-        if ($kgm_vt == &_ZTV13IOPMWorkQueue)
-            showpmworkqueueint $kgm_pm_next
-        end
-        set $kgm_pm_next = $kgm_pm_next->eventChainNext
     end
-end
-
-document showallpmworkqueues
-Syntax: (gdb) showallpmworkqueues
-| Display info about all IOPMWorkQueue objects
-end
-
-define showioservicepm
-       set $kgm_iopmpriv = (IOServicePM *)$arg0
-       printf "{ "
-       printf "MachineState = %d (", $kgm_iopmpriv->MachineState
-       if ( $kgm_iopmpriv->MachineState == 1 )
-               printf "kIOPM_OurChangeTellClientsPowerDown"
-       else
-               if ( $kgm_iopmpriv->MachineState == 2 )
-                       printf "kIOPM_OurChangeTellPriorityClientsPowerDown"
-               else
-                       if ( $kgm_iopmpriv->MachineState == 3 )
-                               printf "kIOPM_OurChangeNotifyInterestedDriversWillChange"
-                       else
-                               if ( $kgm_iopmpriv->MachineState == 4 )
-                                       printf "kIOPM_OurChangeSetPowerState"
-                               else
-                                       if ( $kgm_iopmpriv->MachineState == 5 )
-                                               printf "kIOPM_OurChangeWaitForPowerSettle"
-                                       else
-                                               if ( $kgm_iopmpriv->MachineState == 6 )
-                                                       printf "kIOPM_OurChangeNotifyInterestedDriversDidChange"
-                                               else
-                                                       if ( $kgm_iopmpriv->MachineState == 7 )
-                                                               printf "kIOPM_OurChangeFinish"
-                                                       else
-                                                               if ( $kgm_iopmpriv->MachineState == 8 )
-                                                                       printf "kIOPM_ParentDownTellPriorityClientsPowerDown"
-                                                               else
-                                                                       if ( $kgm_iopmpriv->MachineState == 9 )
-                                                                               printf "kIOPM_ParentDownNotifyInterestedDriversWillChange"
-                                                                       else
-                                                                               if ( $kgm_iopmpriv->MachineState == 10 )
-                                                                                       printf "Unused_MachineState_10"
-                                                                               else
-                                                                                       if ( $kgm_iopmpriv->MachineState == 11 )
-                                                                                               printf "kIOPM_ParentDownNotifyDidChangeAndAcknowledgeChange"
-                                                                                       else
-                                                                                               if ( $kgm_iopmpriv->MachineState == 12 )
-                                                                                                       printf "kIOPM_ParentDownSetPowerState"
-                                                                                               else
-                                                                                                       if ( $kgm_iopmpriv->MachineState == 13 )
-                                                                                                               printf "kIOPM_ParentDownWaitForPowerSettle"
-                                                                                                       else
-                                                                                                               if ( $kgm_iopmpriv->MachineState == 14 )
-                                                                                                                       printf "kIOPM_ParentDownAcknowledgeChange"
-                                                                                                               else
-                                                                                                                       if ( $kgm_iopmpriv->MachineState == 15)
-                                                                                                                               printf "kIOPM_ParentUpSetPowerState"
-                                                                                                                       else
-                                                                                                                               if ( $kgm_iopmpriv->MachineState == 16)
-                                                                                                                                       printf "Unused_MachineState_16"
-                                                                                                                               else
-                                                                                                                                       if ( $kgm_iopmpriv->MachineState == 17)
-                                                                                                                                               printf "kIOPM_ParentUpWaitForSettleTime"
-                                                                                                                                       else
-                                                                                                                                               if ( $kgm_iopmpriv->MachineState == 18)
-                                                                                                                                                       printf "kIOPM_ParentUpNotifyInterestedDriversDidChange"
-                                                                                                                                               else
-                                                                                                                                                       if ( $kgm_iopmpriv->MachineState == 19)
-                                                                                                                                                               printf "kIOPM_ParentUpAcknowledgePowerChange"
-                                                                                                                                                       else
-                                                                                                                                                               if ( $kgm_iopmpriv->MachineState == 20)
-                                                                                                                                                                       printf "kIOPM_Finished"
-                                                                                else
-                                                                                    if ( $kgm_iopmpriv->MachineState == 21)
-                                                                                        printf "kIOPM_DriverThreadCallDone"
-                                                                                    else
-                                                                                        if ( $kgm_iopmpriv->MachineState == 22)
-                                                                                            printf "kIOPM_NotifyChildrenDone"
-                                                                                        end
-                                                                                    end
-                                                                                                                                                               end
-                                                                                                                                                       end
-                                                                                                                                               end
-                                                                                                                                       end
-                                                                                                                               end
-                                                                                                                       end
-                                                                                                               end
-                                                                                                       end
-                                                                                               end
-                                                                                       end
-                                                                               end
-                                                                       end
-                                                               end
-                                                       end
-                                               end
-                                       end
-                               end
-                       end
-               end
        end
        printf "), "
        
        if ( $kgm_iopmpriv->MachineState != 20 )
         printf "DriverTimer = %d, ",(unsigned int)$kgm_iopmpriv->DriverTimer
         printf "SettleTime  = %d, ",(unsigned int)$kgm_iopmpriv->SettleTimeUS
-        printf "HeadNoteFlags = %08x, ",(unsigned int)$kgm_iopmpriv->HeadNoteFlags
+        printf "HeadNoteFlags = %08x, ",(unsigned int)$kgm_iopmpriv->HeadNoteChangeFlags
         printf "HeadNotePendingAcks = %x, ",(unsigned int)$kgm_iopmpriv->HeadNotePendingAcks
        end
 
-    if ( $kgm_iopmpriv->DeviceOverrides != 0 )
+    if ( $kgm_iopmpriv->DeviceOverrideEnabled != 0 )
         printf"DeviceOverrides, "
     end
        
     printf "DeviceDesire = %d, ",(unsigned int)$kgm_iopmpriv->DeviceDesire
     printf "DesiredPowerState = %d, ",(unsigned int)$kgm_iopmpriv->DesiredPowerState
-    printf "PreviousRequest = %d }\n",(unsigned int)$kgm_iopmpriv->PreviousRequest
+    printf "PreviousRequest = %d }\n",(unsigned int)$kgm_iopmpriv->PreviousRequestPowerFlags
 end
 
 document showioservicepm
@@ -7411,25 +9432,29 @@ Syntax: (gdb) showregistrypmstate
 end
 
 define showstacksafterthread
-    set $kgm_head_taskp = &default_pset.tasks
+    set $kgm_head_taskp = &tasks
     set $kgm_actp = (struct thread *)$arg0
     set $kgm_actp = (struct thread *)($kgm_actp->task_threads.next)
     set $kgm_taskp = (struct task *)$kgm_actp->task
     while $kgm_taskp != $kgm_head_taskp
-        showtaskheader
-        showtaskint $kgm_taskp
-        set $kgm_head_actp = &($kgm_taskp->threads)
-        while $kgm_actp != $kgm_head_actp
-            showactheader
-            if ($decode_wait_events > 0)
-               showactint $kgm_actp 1
-            else
-               showactint $kgm_actp 2
-            end
-            set $kgm_actp = (struct thread *)($kgm_actp->task_threads.next)
-        end
-        printf "\n"
-        set $kgm_taskp = (struct task *)($kgm_taskp->pset_tasks.next) 
+       showtaskheader
+       showtaskint $kgm_taskp
+       set $kgm_head_actp = &($kgm_taskp->threads)
+       if $kgm_actp == 0
+           set $kgm_actp = (struct thread *)($kgm_taskp->threads.next)
+       end
+       while $kgm_actp != $kgm_head_actp
+           showactheader
+           if ($decode_wait_events > 0)
+              showactint $kgm_actp 1
+           else
+              showactint $kgm_actp 2
+           end
+           set $kgm_actp = (struct thread *)($kgm_actp->task_threads.next)
+       end
+       printf "\n"
+       set $kgm_taskp = (struct task *)($kgm_taskp->tasks.next)
+       set $kgm_actp = 0
     end
 end
 
@@ -7522,17 +9547,17 @@ define _pt_step
     set $kgm_entryp = $kgm_pt_paddr + 8*$kgm_pt_index
     readphysint $kgm_entryp 64 $kgm_lcpu_self
     set $entry = $kgm_readphysint_result
-    if $kgm_pt_verbose == 2
+    if $kgm_pt_verbose >= 3
         set $kgm_pte_loop = 0
-       while $kgm_pte_loop < 512
-           set $kgm_pt_paddr_tmp = $kgm_pt_paddr + $kgm_pte_loop*8
-           readphys64 $kgm_pt_paddr_tmp
-           set $kgm_pte_loop = $kgm_pte_loop + 1
-       end
+        while $kgm_pte_loop < 512
+            set $kgm_pt_paddr_tmp = $kgm_pt_paddr + $kgm_pte_loop*8
+            readphys64 $kgm_pt_paddr_tmp
+            set $kgm_pte_loop = $kgm_pte_loop + 1
+        end
     end
     set $kgm_paddr_mask = ~((0xfffULL<<52) | 0xfffULL)
     set $kgm_paddr_largemask = ~((0xfffULL<<52) | 0x1fffffULL)
-    if $kgm_pt_verbose == 0
+    if $kgm_pt_verbose < 2
         if $entry & (0x1 << 0)
             set $kgm_pt_valid = 1
             if $entry & (0x1 << 7)
@@ -7541,7 +9566,7 @@ define _pt_step
             else
                 set $kgm_pt_large = 0
                 set $kgm_pt_paddr = $entry & $kgm_paddr_mask
-            end            
+            end     
         else
             set $kgm_pt_valid = 0
             set $kgm_pt_large = 0
@@ -7550,7 +9575,7 @@ define _pt_step
     else
         printf "0x%016llx:\n\t0x%016llx\n\t", $kgm_entryp, $entry
         if $entry & (0x1 << 0)
-            printf "valid"     
+            printf "valid"      
             set $kgm_pt_paddr = $entry & $kgm_paddr_mask
             set $kgm_pt_valid = 1
         else
@@ -7594,17 +9619,16 @@ define _pt_step
         if $entry & (0x3 << 9)
             printf " avail:0x%x", ($entry >> 9) & 0x3
         end
-        if $entry & (0x1 << 63)
+        if $entry & (0x1ULL << 63)
             printf " noexec" 
         end
         printf "\n"
     end
 end
 
-define _pmap_walk
-    set $kgm_pmap = (pmap_t) $arg0
+define _pml4_walk
+    set $kgm_pt_paddr = $arg0
     set $kgm_vaddr = $arg1
-    set $kgm_pt_paddr = $kgm_pmap->pm_cr3
     set $kgm_pt_valid = $kgm_pt_paddr != 0
     set $kgm_pt_large = 0
     set $kgm_pframe_offset = 0
@@ -7612,7 +9636,7 @@ define _pmap_walk
         # Look up bits 47:39 of the linear address in PML4T
         set $kgm_pt_index = ($kgm_vaddr >> 39) & 0x1ffULL
         set $kgm_pframe_offset = $kgm_vaddr & 0x7fffffffffULL
-        if $kgm_pt_verbose
+        if $kgm_pt_verbose >= 2
             printf "pml4 (index %d):\n", $kgm_pt_index
         end
         _pt_step
@@ -7621,7 +9645,7 @@ define _pmap_walk
         # Look up bits 38:30 of the linear address in PDPT
         set $kgm_pt_index = ($kgm_vaddr >> 30) & 0x1ffULL
         set $kgm_pframe_offset = $kgm_vaddr & 0x3fffffffULL
-        if $kgm_pt_verbose
+        if $kgm_pt_verbose >= 2
             printf "pdpt (index %d):\n", $kgm_pt_index
         end
         _pt_step
@@ -7630,7 +9654,7 @@ define _pmap_walk
         # Look up bits 29:21 of the linear address in PDT
         set $kgm_pt_index = ($kgm_vaddr >> 21) & 0x1ffULL
         set $kgm_pframe_offset = $kgm_vaddr & 0x1fffffULL
-        if $kgm_pt_verbose
+        if $kgm_pt_verbose >= 2
             printf "pdt (index %d):\n", $kgm_pt_index
         end
         _pt_step
@@ -7639,37 +9663,354 @@ define _pmap_walk
         # Look up bits 20:21 of the linear address in PT
         set $kgm_pt_index = ($kgm_vaddr >> 12) & 0x1ffULL
         set $kgm_pframe_offset = $kgm_vaddr & 0xfffULL
-        if $kgm_pt_verbose
+        if $kgm_pt_verbose >= 2
             printf "pt (index %d):\n", $kgm_pt_index
         end
         _pt_step
     end
+
     if $kgm_pt_valid
         set $kgm_paddr = $kgm_pt_paddr + $kgm_pframe_offset
-        readphysint $kgm_paddr 32 $kgm_lcpu_self
-        set $kgm_value = $kgm_readphysint_result
-        printf "phys 0x%016llx: 0x%08x\n", $kgm_paddr, $kgm_value
+        set $kgm_paddr_isvalid = 1
     else
         set $kgm_paddr = 0
-        printf "(no translation)\n"
+        set $kgm_paddr_isvalid = 0
+    end
+
+    if $kgm_pt_verbose >= 1
+        if $kgm_paddr_isvalid
+            readphysint $kgm_paddr 32 $kgm_lcpu_self
+            set $kgm_value = $kgm_readphysint_result
+            printf "phys 0x%016llx: 0x%08x\n", $kgm_paddr, $kgm_value
+        else
+            printf "(no translation)\n"
+        end
     end
 end
 
-define pmap_walk
-    if (($kgm_mtype & $kgm_mtype_x86_mask) != $kgm_mtype_x86_any)
-        printf "Not available for current architecture.\n"
+define _pmap_walk_x86
+    set $kgm_pmap = (pmap_t) $arg0
+    _pml4_walk $kgm_pmap->pm_cr3 $arg1
+end
+
+define _pmap_walk_arm_level1_section
+    set $kgm_tte_p = $arg0
+    set $kgm_tte = *$kgm_tte_p
+    set $kgm_vaddr = $arg1
+
+       # Supersection or just section?
+    if (($kgm_tte & 0x00040000) == 0x00040000)
+        set $kgm_paddr = ($kgm_tte & 0xFF000000) | ($kgm_vaddr & 0x00FFFFFF)
+        set $kgm_paddr_isvalid = 1
+    else
+        set $kgm_paddr = ($kgm_tte & 0xFFF00000) | ($kgm_vaddr & 0x000FFFFF)
+        set $kgm_paddr_isvalid = 1
+    end
+
+    if $kgm_pt_verbose >= 2
+        printf "0x%08x\n\t0x%08x\n\t", (unsigned long)$kgm_tte_p, $kgm_tte
+
+        # bit [1:0] evaluated in _pmap_walk_arm
+
+        # B bit 2
+        set $kgm_b_bit = (($kgm_tte & 0x00000004) >> 2)
+
+        # C bit 3
+        set $kgm_c_bit = (($kgm_tte & 0x00000008) >> 3)
+
+        # XN bit 4
+        if ($kgm_tte & 0x00000010)
+            printf "no-execute" 
+        else
+            printf "execute" 
+        end
+
+        # Domain bit [8:5] if not supersection
+        if (($kgm_tte & 0x00040000) == 0x00000000)
+            printf " domain(%d)", (($kgm_tte & 0x000001e0) >> 5)
+        end
+
+        # IMP bit 9
+        printf " imp(%d)", (($kgm_tte & 0x00000200) >> 9) 
+
+        # AP bit 15 and [11:10], merged to a single 3-bit value
+        set $kgm_access = (($kgm_tte & 0x00000c00) >> 10) | (($kgm_tte & 0x00008000) >> 13)
+        if ($kgm_access == 0x0)
+            printf " noaccess"
+        end
+        if ($kgm_access == 0x1)
+            printf " supervisor(readwrite) user(noaccess)"
+        end
+        if ($kgm_access == 0x2)
+            printf " supervisor(readwrite) user(readonly)"
+        end
+        if ($kgm_access == 0x3)
+            printf " supervisor(readwrite) user(readwrite)"
+        end
+        if ($kgm_access == 0x4)
+            printf " noaccess(reserved)"
+        end
+        if ($kgm_access == 0x5)
+            printf " supervisor(readonly) user(noaccess)"
+        end
+        if ($kgm_access == 0x6)
+            printf " supervisor(readonly) user(readonly)"
+        end
+        if ($kgm_access == 0x7)
+            printf " supervisor(readonly) user(readonly)"
+        end
+
+        # TEX bit [14:12]
+        set $kgm_tex_bits = (($kgm_tte & 0x00007000) >> 12)
+
+        # Print TEX, C, B all together
+        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
+
+        # S bit 16
+        if ($kgm_tte & 0x00010000)
+            printf " shareable" 
+        else
+            printf " not-shareable" 
+        end
+
+        # nG bit 17
+        if ($kgm_tte & 0x00020000)
+            printf " not-global"
+        else
+            printf " global" 
+        end
+
+        # Supersection bit 18
+        if ($kgm_tte & 0x00040000)
+            printf " supersection"
+        else
+            printf " section" 
+        end
+
+        # NS bit 19
+        if ($kgm_tte & 0x00080000)
+            printf " no-secure"
+        else
+            printf " secure" 
+        end
+
+        printf "\n"
+    end
+end
+
+define _pmap_walk_arm_level2
+    set $kgm_tte_p = $arg0
+    set $kgm_tte = *$kgm_tte_p
+    set $kgm_vaddr = $arg1
+
+    set $kgm_pte_pbase = (($kgm_tte & 0xFFFFFC00) - gPhysBase + gVirtBase)
+    set $kgm_pte_index = ($kgm_vaddr >> 12) & 0x000000FF
+    set $kgm_pte_p = &((pt_entry_t *)$kgm_pte_pbase)[$kgm_pte_index]
+    set $kgm_pte = *$kgm_pte_p
+
+    # Print first level symbolically
+    if $kgm_pt_verbose >= 2
+        printf "0x%08x\n\t0x%08x\n\t", (unsigned long)$kgm_tte_p, $kgm_tte
+
+        # bit [1:0] evaluated in _pmap_walk_arm
+
+        # NS bit 3
+        if ($kgm_tte & 0x00000008)
+            printf "no-secure"
+        else
+            printf "secure" 
+        end
+
+        # Domain bit [8:5]
+        printf " domain(%d)", (($kgm_tte & 0x000001e0) >> 5)
+
+        # IMP bit 9
+        printf " imp(%d)", (($kgm_tte & 0x00000200) >> 9) 
+
+        printf "\n"
+    end
+
+    if $kgm_pt_verbose >= 2
+        printf "second-level table (index %d):\n", $kgm_pte_index
+    end
+    if $kgm_pt_verbose >= 3
+        set $kgm_pte_loop = 0
+        while $kgm_pte_loop < 256
+            set $kgm_pte_p_tmp = &((pt_entry_t *)$kgm_pte_pbase)[$kgm_pte_loop]
+            printf "0x%08x:\t0x%08x\n", (unsigned long)$kgm_pte_p_tmp, *$kgm_pte_p_tmp
+            set $kgm_pte_loop = $kgm_pte_loop + 1
+        end
+    end
+
+    if ($kgm_pte & 0x00000003)
+        set $kgm_pve_p = (pv_entry_t *)($kgm_pte_pbase + 0x100*sizeof(pt_entry_t) + $kgm_pte_index*sizeof(pv_entry_t))
+        if ($kgm_pve_p->shadow != 0)
+            set $kgm_spte = $kgm_pve_p->shadow ^ ($kgm_vaddr & ~0xFFF)
+            set $kgm_paddr = ($kgm_spte & 0xFFFFF000) | ($kgm_vaddr & 0xFFF)
+            set $kgm_paddr_isvalid = 1
+        else
+            set $kgm_paddr = (*$kgm_pte_p & 0xFFFFF000) | ($kgm_vaddr & 0xFFF)
+            set $kgm_paddr_isvalid = 1
+        end
     else
-        if $argc != 2
-            printf "pmap_walk <pmap> <vaddr>\n"
+        set $kgm_paddr = 0
+        set $kgm_paddr_isvalid = 0
+    end
+
+    if $kgm_pt_verbose >= 2
+        printf "0x%08x\n\t0x%08x\n\t", (unsigned long)$kgm_pte_p, $kgm_pte
+        if (($kgm_pte & 0x00000003) == 0x00000000)
+            printf "invalid" 
         else
-            if !$kgm_pt_verbose
-                set $kgm_pt_verbose = 1
+            if (($kgm_pte & 0x00000003) == 0x00000001)
+                printf "large"
+
+                # XN bit 15
+                if ($kgm_pte & 0x00008000) == 0x00008000
+                    printf " no-execute"
+                else
+                    printf " execute"
+                end
             else
-                if $kgm_pt_verbose != 2
-                    set $kgm_pt_verbose = 1
+                printf "small"
+
+                # XN bit 0
+                if ($kgm_pte & 0x00000001) == 0x00000001
+                    printf " no-execute"
+                else
+                    printf " execute"
                 end
             end
-            _pmap_walk $arg0 $arg1
+
+            # B bit 2
+            set $kgm_b_bit = (($kgm_pte & 0x00000004) >> 2)
+
+            # C bit 3
+            set $kgm_c_bit = (($kgm_pte & 0x00000008) >> 3)
+
+            # AP bit 9 and [5:4], merged to a single 3-bit value
+            set $kgm_access = (($kgm_pte & 0x00000030) >> 4) | (($kgm_pte & 0x00000200) >> 7)
+            if ($kgm_access == 0x0)
+                printf " noaccess"
+            end
+            if ($kgm_access == 0x1)
+                printf " supervisor(readwrite) user(noaccess)"
+            end
+            if ($kgm_access == 0x2)
+                printf " supervisor(readwrite) user(readonly)"
+            end
+            if ($kgm_access == 0x3)
+                printf " supervisor(readwrite) user(readwrite)"
+            end
+            if ($kgm_access == 0x4)
+                printf " noaccess(reserved)"
+            end
+            if ($kgm_access == 0x5)
+                printf " supervisor(readonly) user(noaccess)"
+            end
+            if ($kgm_access == 0x6)
+                printf " supervisor(readonly) user(readonly)"
+            end
+            if ($kgm_access == 0x7)
+                printf " supervisor(readonly) user(readonly)"
+            end
+
+            # TEX bit [14:12] for large, [8:6] for small
+            if (($kgm_pte & 0x00000003) == 0x00000001)
+                set $kgm_tex_bits = (($kgm_pte & 0x00007000) >> 12)
+            else
+                set $kgm_tex_bits = (($kgm_pte & 0x000001c0) >> 6)
+            end
+
+            # Print TEX, C, B all together
+            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
+
+            # S bit 10
+            if ($kgm_pte & 0x00000400)
+                printf " shareable" 
+            else
+                printf " not-shareable" 
+            end
+
+            # nG bit 11
+            if ($kgm_pte & 0x00000800)
+                printf " not-global"
+            else
+                printf " global" 
+            end
+
+        end
+        printf "\n"
+    end
+end
+
+# See ARM ARM Section B3.3
+define _pmap_walk_arm
+    set $kgm_pmap = (pmap_t) $arg0
+    set $kgm_vaddr = $arg1
+    set $kgm_paddr = 0
+    set $kgm_paddr_isvalid = 0
+
+    # Shift by TTESHIFT (20) to get tte index
+    set $kgm_tte_index = (($kgm_vaddr - $kgm_pmap->min) >> 20)
+    set $kgm_tte_p = &$kgm_pmap->tte[$kgm_tte_index]
+    set $kgm_tte = *$kgm_tte_p
+    if $kgm_pt_verbose >= 2
+        printf "first-level table (index %d):\n", $kgm_tte_index
+    end
+    if $kgm_pt_verbose >= 3
+        set $kgm_tte_loop = 0
+        while $kgm_tte_loop < 4096
+            set $kgm_tte_p_tmp = &$kgm_pmap->tte[$kgm_tte_loop]
+            printf "0x%08x:\t0x%08x\n", (unsigned long)$kgm_tte_p_tmp, *$kgm_tte_p_tmp
+            set $kgm_tte_loop = $kgm_tte_loop + 1
+        end
+    end
+
+    if (($kgm_tte & 0x00000003) == 0x00000001)
+        _pmap_walk_arm_level2 $kgm_tte_p $kgm_vaddr
+    else
+        if (($kgm_tte & 0x00000003) == 0x00000002)
+            _pmap_walk_arm_level1_section $kgm_tte_p $kgm_vaddr
+        else
+            set $kgm_paddr = 0
+            set $kgm_paddr_isvalid = 0
+            if $kgm_pt_verbose >= 2
+                printf "Invalid First-Level Translation Table Entry: 0x%08x\n", $kgm_tte
+            end
+        end
+    end
+
+    if $kgm_pt_verbose >= 1
+        if $kgm_paddr_isvalid
+            readphysint $kgm_paddr 32 $kgm_lcpu_self
+            set $kgm_value = $kgm_readphysint_result
+            printf "phys 0x%016llx: 0x%08x\n", $kgm_paddr, $kgm_value
+        else
+            printf "(no translation)\n"
+        end
+    end
+end
+
+define pmap_walk
+    if $argc != 2
+        printf "pmap_walk <pmap> <vaddr>\n"
+    else
+        if !$kgm_pt_verbose
+            set $kgm_pt_verbose = 2
+        else
+            if $kgm_pt_verbose > 3
+                set $kgm_pt_verbose = 2
+            end
+        end
+        if (($kgm_mtype & $kgm_mtype_x86_mask) == $kgm_mtype_x86_any)
+            _pmap_walk_x86 $arg0 $arg1
+        else
+            if ($kgm_mtype == $kgm_mtype_arm)
+                _pmap_walk_arm $arg0 $arg1
+            else
+                printf "Not available for current architecture.\n"
+            end
         end
     end
 end
@@ -7677,18 +10018,27 @@ end
 document pmap_walk
 Syntax: (gdb) pmap_walk <pmap> <virtual_address>
 | Perform a page-table walk in <pmap> for <virtual_address>.
-| Set $kgm_pt_verbose=2 for full hex dump of page tables.
+| Set:
+|     $kgm_pt_verbose=0 for no output, $kgm_paddr will be set
+|                       if $kgm_paddr_isvalid is 1
+|     $kgm_pt_verbose=1 for final physical address
+|     $kgm_pt_verbose=2 for dump of page table entry.
+|     $kgm_pt_verbose=3 for full hex dump of page tables.
 end
 
 define pmap_vtop
-    if (($kgm_mtype & $kgm_mtype_x86_mask) != $kgm_mtype_x86_any)
-        printf "Not available for current architecture.\n"
+    if $argc != 2
+        printf "pmap_vtop <pamp> <vaddr>\n"
     else
-        if $argc != 2
-            printf "pmap_vtop <pamp> <vaddr>\n"
+        set $kgm_pt_verbose = 1
+        if (($kgm_mtype & $kgm_mtype_x86_mask) == $kgm_mtype_x86_any)
+            _pmap_walk_x86 $arg0 $arg1
         else
-            set $kgm_pt_verbose = 0
-            _pmap_walk $arg0 $arg1
+            if ($kgm_mtype == $kgm_mtype_arm)
+                _pmap_walk_arm $arg0 $arg1
+            else
+                printf "Not available for current architecture.\n"
+            end
         end
     end
 end
@@ -7716,12 +10066,12 @@ define zstack
                printf "\n--------------- "
 
                if (zrecords[$index].z_opcode == 1)
-                       printf "ALLOC "
+                       printf "ALLOC  "
                else
-                       printf "FREE "
+                       printf "FREE  "
                end
-
-               printf " 0x%x : index %d  :  ztime %d -------------\n", zrecords[$index].z_element, $index, zrecords[$index].z_time
+               showptr zrecords[$index].z_element
+               printf " : index %d  :  ztime %d -------------\n", $index, zrecords[$index].z_time
 
                set $frame = 0
 
@@ -7845,7 +10195,7 @@ define findelem
                        zstack $fe_index
 
                        if (zrecords[$fe_index].z_opcode == $fe_prev_op)
-                               printf "***************   DOUBLE OP!   *********************\n
+                               printf "***************   DOUBLE OP!   *********************\n"
                        end
 
                        set $fe_prev_op = zrecords[$fe_index].z_opcode
@@ -7876,7 +10226,12 @@ end
 # in the kernel's address space and use that instead. Don't rely on
 # kdp_pmap between invocations of map/unmap. Since the shadow
 # codepath uses a manual KDP packet, request no more than 128 bytes.
-# Uses $kgm_lp64 for kernel address space size
+# Uses $kgm_lp64 for kernel address space size, and
+# $kgm_readphys_use_kdp/$kgm_readphys_force_physmap to override
+# how the user pages are accessed ($kgm_readphys_force_physmap
+# implies walking the user task's pagetables to get a physical
+# address and then shadowing data from there using the
+# physical mapping of memory).
 define _map_user_data_from_task
     set $kgm_map_user_taskp = (task_t)$arg0
     set $kgm_map_user_map = $kgm_map_user_taskp->map
@@ -7885,47 +10240,117 @@ define _map_user_data_from_task
     set $kgm_map_user_window = 0
     set $kgm_map_switch_map = 0
     
-    if $kgm_lp64
-        set $kgm_map_switch_map = 1
+    if ($kgm_readphys_force_kdp != 0)
+        set $kgm_readphys_use_kdp = 1
     else
-        if !$kgm_map_user_task_64
-            set $kgm_map_switch_map = 1
+        if ($kgm_readphys_force_physmap)
+            set $kgm_readphys_use_kdp = 0
+        else
+            set $kgm_readphys_use_kdp = ( kdp->is_conn > 0 )
         end
     end
-    
-    if ($kgm_map_switch_map)
-        # switch the map safely
-        set $kgm_map_user_window = $arg1
-        set kdp_pmap = $kgm_map_user_pmap
-    else
-        # requires shadowing/copying
 
-        # set up the manual KDP packet
-        set manual_pkt.input = 0
-        set manual_pkt.len = sizeof(kdp_readmem64_req_t)
-        set $kgm_pkt = (kdp_readmem64_req_t *)&manual_pkt.data
-        set $kgm_pkt->hdr.request = KDP_READMEM64
-        set $kgm_pkt->hdr.len = sizeof(kdp_readmem64_req_t)
-        set $kgm_pkt->hdr.is_reply = 0
-        set $kgm_pkt->hdr.seq = 0
-        set $kgm_pkt->hdr.key = 0
-        set $kgm_pkt->address = (uint64_t)$arg1
-        set $kgm_pkt->nbytes = (uint32_t)$arg2
+    if ($kgm_readphys_use_kdp)
 
-        set kdp_pmap = $kgm_map_user_pmap
-        set manual_pkt.input = 1
-        # dummy to make sure manual packet is executed
-        set $kgm_dummy = &_mh_execute_header
-        # Go back to kernel map so that we can access buffer directly
-        set kdp_pmap = 0
+        if $kgm_lp64
+            set $kgm_map_switch_map = 1
+        else
+            if !$kgm_map_user_task_64
+                set $kgm_map_switch_map = 1
+            end
+        end
+    
+        if ($kgm_map_switch_map)
+            # switch the map safely
+            set $kgm_map_user_window = $arg1
+            set kdp_pmap = $kgm_map_user_pmap
+        else
+            # requires shadowing/copying
+
+            # set up the manual KDP packet
+            set manual_pkt.input = 0
+            set manual_pkt.len = sizeof(kdp_readmem64_req_t)
+            set $kgm_pkt = (kdp_readmem64_req_t *)&manual_pkt.data
+            set $kgm_pkt->hdr.request = KDP_READMEM64
+            set $kgm_pkt->hdr.len = sizeof(kdp_readmem64_req_t)
+            set $kgm_pkt->hdr.is_reply = 0
+            set $kgm_pkt->hdr.seq = 0
+            set $kgm_pkt->hdr.key = 0
+            set $kgm_pkt->address = (uint64_t)$arg1
+            set $kgm_pkt->nbytes = (uint32_t)$arg2
+
+            set kdp_pmap = $kgm_map_user_pmap
+            set manual_pkt.input = 1
+            # dummy to make sure manual packet is executed
+            set $kgm_dummy = &_mh_execute_header
+            # Go back to kernel map so that we can access buffer directly
+            set kdp_pmap = 0
+
+            set $kgm_pkt = (kdp_readmem64_reply_t *)&manual_pkt.data
+            if ($kgm_pkt->error == 0)
+                set $kgm_map_user_window = $kgm_pkt->data
+            else
+                set $kgm_map_user_window = 0
+            end
+        end
 
-        set $kgm_pkt = (kdp_readmem64_reply_t *)&manual_pkt.data
-        if ($kgm_pkt->error == 0)
-            set $kgm_map_user_window = $kgm_pkt->data
+    else
+        # without the benefit of a KDP stub on the target, try to
+        # find the user task's physical mapping and memcpy the data.
+        # If it straddles a page boundary, copy in two passes
+        set $kgm_vaddr_range1_start = (unsigned long long)$arg1
+        set $kgm_vaddr_range1_count = (unsigned long long)$arg2
+        if (($kgm_vaddr_range1_start + $kgm_vaddr_range1_count) & 0xFFF) < $kgm_vaddr_range1_count
+            set $kgm_vaddr_range2_start = ($kgm_vaddr_range1_start + $kgm_vaddr_range1_count) & ~((unsigned long long)0xFFF)
+            set $kgm_vaddr_range2_count = $kgm_vaddr_range1_start + $kgm_vaddr_range1_count - $kgm_vaddr_range2_start
+            set $kgm_vaddr_range1_count = $kgm_vaddr_range2_start - $kgm_vaddr_range1_start
         else
-            set $kgm_map_user_window = 0
+            set $kgm_vaddr_range2_start = 0
+            set $kgm_vaddr_range2_count = 0
         end
+        set $kgm_paddr_range1_in_kva = 0
+        set $kgm_paddr_range2_in_kva = 0
 
+        if ($kgm_mtype == $kgm_mtype_x86_64)
+            set $kgm_pt_verbose = 0
+            _pmap_walk_x86 $kgm_map_user_pmap $kgm_vaddr_range1_start
+            if $kgm_paddr_isvalid
+                set $kgm_paddr_range1_in_kva = $kgm_paddr + physmap_base
+            end
+            if $kgm_vaddr_range2_start
+                _pmap_walk_x86 $kgm_map_user_pmap $kgm_vaddr_range2_start
+                if $kgm_paddr_isvalid
+                    set $kgm_paddr_range2_in_kva = $kgm_paddr + physmap_base
+                end
+            end
+        else
+            if ($kgm_mtype == $kgm_mtype_arm)
+                set $kgm_pt_verbose = 0
+                _pmap_walk_arm $kgm_map_user_pmap $kgm_vaddr_range1_start
+                if $kgm_paddr_isvalid
+                   set $kgm_paddr_range1_in_kva = $kgm_paddr - gPhysBase + gVirtBase
+                end
+                if $kgm_vaddr_range2_start
+                    _pmap_walk_arm $kgm_map_user_pmap $kgm_vaddr_range2_start
+                    if $kgm_paddr_isvalid
+                        set $kgm_paddr_range2_in_kva = $kgm_paddr - gPhysBase + gVirtBase
+                    end
+                end
+            else
+                printf "Not available for current architecture.\n"
+                set $kgm_paddr_isvalid = 0
+            end
+        end
+        if $kgm_paddr_range1_in_kva
+            set $kgm_pkt = (kdp_readmem64_reply_t *)&manual_pkt.data
+            memcpy $kgm_pkt->data $kgm_paddr_range1_in_kva $kgm_vaddr_range1_count
+            if $kgm_paddr_range2_in_kva
+                memcpy &$kgm_pkt->data[$kgm_vaddr_range1_count] $kgm_paddr_range2_in_kva $kgm_vaddr_range2_count
+            end
+            set $kgm_map_user_window  = $kgm_pkt->data
+        else
+            set $kgm_map_user_window  = 0
+        end
     end
 end
 
@@ -7937,6 +10362,10 @@ end
 define _print_path_for_image
     set $kgm_print_path_address = (unsigned long long)$arg0
     set $kgm_path_str_notdone = 1
+
+    if ($kgm_print_path_address == 0)
+       set $kgm_path_str_notdone = 0
+    end
     
     while $kgm_path_str_notdone
         _map_user_data_from_task $kgm_taskp $kgm_print_path_address 32
@@ -7950,7 +10379,7 @@ define _print_path_for_image
         
         _unmap_user_data_from_task $kgm_taskp
         
-        # if we terminated on NUL, break out
+        # break out if we terminated on NUL
         if $kgm_path_i < 32
             set $kgm_path_str_notdone = 0
         else
@@ -7959,7 +10388,7 @@ define _print_path_for_image
     end
 end
 
-# uses $kgm_taskp and $kgm_task_64
+# uses $kgm_taskp and $kgm_task_64. May modify $kgm_dyld_load_path
 define _print_image_info
     set $kgm_mh_image_address = (unsigned long long)$arg0
     set $kgm_mh_path_address = (unsigned long long)$arg1
@@ -8040,6 +10469,10 @@ define _print_image_info
 
             loop_break
         else
+            if $kgm_lc_cmd == 0xe
+                set $kgm_load_dylinker_data = $kgm_lc_data
+                set $kgm_dyld_load_path = $kgm_lc_address + *((unsigned int *)$kgm_load_dylinker_data)
+            end
             _unmap_user_data_from_task $kgm_taskp
         end
 
@@ -8089,24 +10522,33 @@ define _print_images_for_dyld_image_info
     set $kgm_task_64 = $arg1
     set $kgm_dyld_all_image_infos_address = (unsigned long long)$arg2
 
-    _map_user_data_from_task $kgm_taskp $kgm_dyld_all_image_infos_address 16
+    _map_user_data_from_task $kgm_taskp $kgm_dyld_all_image_infos_address 112
 
     set $kgm_dyld_all_image_infos = (unsigned int *)$kgm_map_user_window    
-    if ($kgm_dyld_all_image_infos[0] != 6)
-        printf "Invalid version number %d\n", $kgm_dyld_all_image_infos[0]
+    set $kgm_dyld_all_image_infos_version = $kgm_dyld_all_image_infos[0]
+    if ($kgm_dyld_all_image_infos_version > 12)
+        printf "Unknown dyld all_image_infos version number %d\n", $kgm_dyld_all_image_infos_version
     end
     set $kgm_image_info_count = $kgm_dyld_all_image_infos[1]
-    
+
+    set $kgm_dyld_load_path = 0    
     if $kgm_task_64
         set $kgm_image_info_size = 24
         set $kgm_image_info_array_address = ((unsigned long long *)$kgm_dyld_all_image_infos)[1]
+        set $kgm_dyld_load_address = ((unsigned long long *)$kgm_dyld_all_image_infos)[4]
+        set $kgm_dyld_all_image_infos_address_from_struct = ((unsigned long long *)$kgm_dyld_all_image_infos)[13]
     else
         set $kgm_image_info_size = 12
         set $kgm_image_info_array_address = ((unsigned int *)$kgm_dyld_all_image_infos)[2]
+        set $kgm_dyld_load_address = ((unsigned int *)$kgm_dyld_all_image_infos)[5]
+        set $kgm_dyld_all_image_infos_address_from_struct = ((unsigned int *)$kgm_dyld_all_image_infos)[14]
     end
 
     _unmap_user_data_from_task $kgm_taskp
 
+    # Account for ASLR slide before dyld can fix the structure
+    set $kgm_dyld_load_address = $kgm_dyld_load_address + ($kgm_dyld_all_image_infos_address - $kgm_dyld_all_image_infos_address_from_struct)
+
     set $kgm_image_info_i = 0
     while $kgm_image_info_i < $kgm_image_info_count
 
@@ -8127,33 +10569,231 @@ define _print_images_for_dyld_image_info
 
         set $kgm_image_info_i = $kgm_image_info_i + 1
     end
+
+    # $kgm_dyld_load_path may get set when the main executable is processed
+    # printf "[dyld] = image address %llx path address %llx\n", $kgm_dyld_load_address, $kgm_dyld_load_path
+    _print_image_info $kgm_dyld_load_address $kgm_dyld_load_path
+
+end
+
+define showuserlibraries
+       set $kgm_taskp = (task_t)$arg0
+       set $kgm_dyld_image_info = $kgm_taskp->all_image_info_addr
+
+       set $kgm_map = $kgm_taskp->map
+       set $kgm_task_64 = ( $kgm_taskp->taskFeatures[0] & 0x80000000)
+
+       if ($kgm_dyld_image_info != 0)
+               printf "address   "
+               if $kgm_task_64
+                       printf "        "
+               end
+               printf "  type       "
+               printf "  uuid                                  "
+               printf "path\n"
+
+               _print_images_for_dyld_image_info $kgm_taskp $kgm_task_64 $kgm_dyld_image_info
+       else
+               printf "No dyld shared library information available for task\n"
+       end
+end
+document showuserlibraries
+Syntax: (gdb) showuserlibraries <task_t>
+| For a given user task, inspect the dyld shared library state and print 
+| information about all Mach-O images.
 end
 
-define showuserlibraries
-    set $kgm_taskp = (task_t)$arg0
-    set $kgm_dyld_image_info = $kgm_taskp->all_image_info_addr
+define showuserdyldinfo
+       set $kgm_taskp = (task_t)$arg0
+       set $kgm_dyld_all_image_infos_address = (unsigned long long)$kgm_taskp->all_image_info_addr
+
+       set $kgm_map = $kgm_taskp->map
+       set $kgm_task_64 = ( $kgm_taskp->taskFeatures[0] & 0x80000000)
+
+       if ($kgm_dyld_all_image_infos_address != 0)
+
+          _map_user_data_from_task $kgm_taskp $kgm_dyld_all_image_infos_address 112
+
+          set $kgm_dyld_all_image_infos = (unsigned char *)$kgm_map_user_window
+          set $kgm_dyld_all_image_infos_version = ((unsigned int *)$kgm_dyld_all_image_infos)[0]
+          if ($kgm_dyld_all_image_infos_version > 12)
+                 printf "Unknown dyld all_image_infos version number %d\n", $kgm_dyld_all_image_infos_version
+          end
+
+          # Find fields by byte offset. We assume at least version 9 is supported
+          if $kgm_task_64
+                 set $kgm_dyld_all_image_infos_infoArrayCount = *(unsigned int *)(&$kgm_dyld_all_image_infos[4])
+                 set $kgm_dyld_all_image_infos_infoArray = *(unsigned long long *)(&$kgm_dyld_all_image_infos[8])
+                 set $kgm_dyld_all_image_infos_notification = *(unsigned long long *)(&$kgm_dyld_all_image_infos[16])
+                 set $kgm_dyld_all_image_infos_processDetachedFromSharedRegion = *(unsigned char *)(&$kgm_dyld_all_image_infos[24])
+                 set $kgm_dyld_all_image_infos_libSystemInitialized = *(unsigned char *)(&$kgm_dyld_all_image_infos[25])
+                 set $kgm_dyld_all_image_infos_dyldImageLoadAddress = *(unsigned long long *)(&$kgm_dyld_all_image_infos[32])
+                 set $kgm_dyld_all_image_infos_jitInfo = *(unsigned long long *)(&$kgm_dyld_all_image_infos[40])
+                 set $kgm_dyld_all_image_infos_dyldVersion = *(unsigned long long *)(&$kgm_dyld_all_image_infos[48])
+                 set $kgm_dyld_all_image_infos_errorMessage = *(unsigned long long *)(&$kgm_dyld_all_image_infos[56])
+                 set $kgm_dyld_all_image_infos_terminationFlags = *(unsigned long long *)(&$kgm_dyld_all_image_infos[64])
+                 set $kgm_dyld_all_image_infos_coreSymbolicationShmPage = *(unsigned long long *)(&$kgm_dyld_all_image_infos[72])
+                 set $kgm_dyld_all_image_infos_systemOrderFlag = *(unsigned long long *)(&$kgm_dyld_all_image_infos[80])
+                 set $kgm_dyld_all_image_infos_uuidArrayCount = *(unsigned long long *)(&$kgm_dyld_all_image_infos[88])
+                 set $kgm_dyld_all_image_infos_uuidArray = *(unsigned long long *)(&$kgm_dyld_all_image_infos[96])
+                 set $kgm_dyld_all_image_infos_dyldAllImageInfosAddress = *(unsigned long long *)(&$kgm_dyld_all_image_infos[104])
+          else
+                 set $kgm_dyld_all_image_infos_infoArrayCount = *(unsigned int *)(&$kgm_dyld_all_image_infos[4])
+                 set $kgm_dyld_all_image_infos_infoArray = *(unsigned int *)(&$kgm_dyld_all_image_infos[8])
+                 set $kgm_dyld_all_image_infos_notification = *(unsigned int *)(&$kgm_dyld_all_image_infos[12])
+                 set $kgm_dyld_all_image_infos_processDetachedFromSharedRegion = *(unsigned char *)(&$kgm_dyld_all_image_infos[16])
+                 set $kgm_dyld_all_image_infos_libSystemInitialized = *(unsigned char *)(&$kgm_dyld_all_image_infos[17])
+                 set $kgm_dyld_all_image_infos_dyldImageLoadAddress = *(unsigned int *)(&$kgm_dyld_all_image_infos[20])
+                 set $kgm_dyld_all_image_infos_jitInfo = *(unsigned int *)(&$kgm_dyld_all_image_infos[24])
+                 set $kgm_dyld_all_image_infos_dyldVersion = *(unsigned int *)(&$kgm_dyld_all_image_infos[28])
+                 set $kgm_dyld_all_image_infos_errorMessage = *(unsigned int *)(&$kgm_dyld_all_image_infos[32])
+                 set $kgm_dyld_all_image_infos_terminationFlags = *(unsigned int *)(&$kgm_dyld_all_image_infos[36])
+                 set $kgm_dyld_all_image_infos_coreSymbolicationShmPage = *(unsigned int *)(&$kgm_dyld_all_image_infos[40])
+                 set $kgm_dyld_all_image_infos_systemOrderFlag = *(unsigned int *)(&$kgm_dyld_all_image_infos[44])
+                 set $kgm_dyld_all_image_infos_uuidArrayCount = *(unsigned int *)(&$kgm_dyld_all_image_infos[48])
+                 set $kgm_dyld_all_image_infos_uuidArray = *(unsigned int *)(&$kgm_dyld_all_image_infos[52])
+                 set $kgm_dyld_all_image_infos_dyldAllImageInfosAddress = *(unsigned int *)(&$kgm_dyld_all_image_infos[56])
+          end
+
+          _unmap_user_data_from_task $kgm_taskp
+
+          set $kgm_dyld_all_imfo_infos_slide = ( $kgm_dyld_all_image_infos_address - $kgm_dyld_all_image_infos_dyldAllImageInfosAddress )
+          set $kgm_dyld_all_image_infos_dyldVersion_postslide = ( $kgm_dyld_all_image_infos_dyldVersion + $kgm_dyld_all_imfo_infos_slide )
+
+          printf "                        version %u\n", $kgm_dyld_all_image_infos_version
+          printf "                 infoArrayCount %u\n", $kgm_dyld_all_image_infos_infoArrayCount
+          printf "                      infoArray "
+          showuserptr $kgm_dyld_all_image_infos_infoArray
+          printf "\n"
+          printf "                   notification "
+          showuserptr $kgm_dyld_all_image_infos_notification
+          printf "\n"
+          printf "processDetachedFromSharedRegion %d\n", $kgm_dyld_all_image_infos_processDetachedFromSharedRegion
+          printf "           libSystemInitialized %d\n", $kgm_dyld_all_image_infos_libSystemInitialized
+          printf "           dyldImageLoadAddress "
+          showuserptr $kgm_dyld_all_image_infos_dyldImageLoadAddress
+          printf "\n"
+          printf "                        jitInfo "
+          showuserptr $kgm_dyld_all_image_infos_jitInfo
+          printf "\n"
+          printf "                    dyldVersion "
+          showuserptr $kgm_dyld_all_image_infos_dyldVersion
+          printf "\n"
+          printf "                                "
+          _print_path_for_image $kgm_dyld_all_image_infos_dyldVersion_postslide
+          if ($kgm_dyld_all_imfo_infos_slide != 0)
+                 printf " (currently "
+                 showuserptr $kgm_dyld_all_image_infos_dyldVersion_postslide
+                 printf ")"
+          end
+          printf "\n"
+
+          printf "                   errorMessage "
+          showuserptr $kgm_dyld_all_image_infos_errorMessage
+          printf "\n"
+          if $kgm_dyld_all_image_infos_errorMessage != 0
+                 printf "                                "
+                 _print_path_for_image $kgm_dyld_all_image_infos_errorMessage
+                 printf "\n"
+          end
+
+          printf "               terminationFlags "
+          showuserptr $kgm_dyld_all_image_infos_terminationFlags
+          printf "\n"
+          printf "       coreSymbolicationShmPage "
+          showuserptr $kgm_dyld_all_image_infos_coreSymbolicationShmPage
+          printf "\n"
+          printf "                systemOrderFlag "
+          showuserptr $kgm_dyld_all_image_infos_systemOrderFlag
+          printf "\n"
+          printf "                 uuidArrayCount "
+          showuserptr $kgm_dyld_all_image_infos_uuidArrayCount
+          printf "\n"
+          printf "                      uuidArray "
+          showuserptr $kgm_dyld_all_image_infos_uuidArray
+          printf "\n"
+          printf "       dyldAllImageInfosAddress "
+          showuserptr $kgm_dyld_all_image_infos_dyldAllImageInfosAddress
+          printf "\n"
+          printf "                                (currently "
+          showuserptr $kgm_dyld_all_image_infos_address
+          printf ")\n"
+
+          if $kgm_task_64
+                 set $kgm_dyld_all_image_infos_address = $kgm_dyld_all_image_infos_address + 112
+                 _map_user_data_from_task $kgm_taskp $kgm_dyld_all_image_infos_address 64
+                 set $kgm_dyld_all_image_infos_v10 = (unsigned char *)$kgm_map_user_window
+                 set $kgm_dyld_all_image_infos_initialImageCount = *(unsigned long long *)(&$kgm_dyld_all_image_infos_v10[112-112])
+                 set $kgm_dyld_all_image_infos_errorKind = *(unsigned long long *)(&$kgm_dyld_all_image_infos_v10[120-112])
+                 set $kgm_dyld_all_image_infos_errorClientOfDylibPath = *(unsigned long long *)(&$kgm_dyld_all_image_infos_v10[128-112])
+                 set $kgm_dyld_all_image_infos_errorTargetDylibPath = *(unsigned long long *)(&$kgm_dyld_all_image_infos_v10[136-112])
+                 set $kgm_dyld_all_image_infos_errorSymbol = *(unsigned long long *)(&$kgm_dyld_all_image_infos_v10[144-112])
+                 set $kgm_dyld_all_image_infos_sharedCacheSlide = *(unsigned long long *)(&$kgm_dyld_all_image_infos_v10[152-112])
+
+                 _unmap_user_data_from_task $kgm_taskp
+          else
+                 set $kgm_dyld_all_image_infos_address = $kgm_dyld_all_image_infos_address + 60
+                 _map_user_data_from_task $kgm_taskp $kgm_dyld_all_image_infos_address 64
+                 set $kgm_dyld_all_image_infos_v10 = (unsigned char *)$kgm_map_user_window
+                 set $kgm_dyld_all_image_infos_initialImageCount = *(unsigned int *)(&$kgm_dyld_all_image_infos_v10[60-60])
+                 set $kgm_dyld_all_image_infos_errorKind = *(unsigned int *)(&$kgm_dyld_all_image_infos_v10[64-60])
+                 set $kgm_dyld_all_image_infos_errorClientOfDylibPath = *(unsigned int *)(&$kgm_dyld_all_image_infos_v10[68-60])
+                 set $kgm_dyld_all_image_infos_errorTargetDylibPath = *(unsigned int *)(&$kgm_dyld_all_image_infos_v10[72-60])
+                 set $kgm_dyld_all_image_infos_errorSymbol = *(unsigned int *)(&$kgm_dyld_all_image_infos_v10[76-60])
+                 set $kgm_dyld_all_image_infos_sharedCacheSlide = *(unsigned int *)(&$kgm_dyld_all_image_infos_v10[80-60])
+                 _unmap_user_data_from_task $kgm_taskp
+          end
+
+          if $kgm_dyld_all_image_infos_version >= 10
+                 printf "              initialImageCount "
+                 showuserptr $kgm_dyld_all_image_infos_initialImageCount
+                 printf "\n"
+          end
 
-    set $kgm_map = $kgm_taskp->map
-    set $kgm_task_64 = ( $kgm_taskp->taskFeatures[0] & 0x80000000)
+          if $kgm_dyld_all_image_infos_version >= 11
+                 printf "                      errorKind "
+                 showuserptr $kgm_dyld_all_image_infos_errorKind
+                 printf "\n"
+                 printf "         errorClientOfDylibPath "
+                 showuserptr $kgm_dyld_all_image_infos_errorClientOfDylibPath
+                 printf "\n"
+                 if $kgm_dyld_all_image_infos_errorClientOfDylibPath != 0
+                        printf "                                "
+                        _print_path_for_image $kgm_dyld_all_image_infos_errorClientOfDylibPath
+                        printf "\n"
+                 end
+                 printf "           errorTargetDylibPath "
+                 showuserptr $kgm_dyld_all_image_infos_errorTargetDylibPath
+                 printf "\n"
+                 if $kgm_dyld_all_image_infos_errorTargetDylibPath != 0
+                        printf "                                "
+                        _print_path_for_image $kgm_dyld_all_image_infos_errorTargetDylibPath
+                        printf "\n"
+                 end
+                 printf "                    errorSymbol "
+                 showuserptr $kgm_dyld_all_image_infos_errorSymbol
+                 printf "\n"
+                 if $kgm_dyld_all_image_infos_errorSymbol != 0
+                        printf "                                "
+                        _print_path_for_image $kgm_dyld_all_image_infos_errorSymbol
+                        printf "\n"
+                 end
+          end
 
-    if ($kgm_dyld_image_info != 0)
-        printf "address   "
-        if $kgm_task_64
-            printf "        "
-        end
-        printf "  type       "
-        printf "  uuid                                  "
-        printf "path\n"
+          if $kgm_dyld_all_image_infos_version >= 12
+                 printf "               sharedCacheSlide "
+                 showuserptr $kgm_dyld_all_image_infos_sharedCacheSlide
+                 printf "\n"
+          end
 
-        _print_images_for_dyld_image_info $kgm_taskp $kgm_task_64 $kgm_dyld_image_info
-    else
-        printf "No dyld shared library information available for task\n"
-    end
+       else
+               printf "No dyld information available for task\n"
+       end
 end
-document showuserlibraries
-Syntax: (gdb) showuserlibraries <task_t>
-| For a given user task, inspect the dyld shared library state and print 
-| information about all Mach-O images.
+document showuserdyldinfo
+Syntax: (gdb) showuserdyldinfo <task_t>
+| For a given user task, inspect the dyld global info and print
+| out all fields, including error messages.
 end
 
 define showkerneldebugheader
@@ -8450,9 +11090,8 @@ define showkerneldebugbuffercpu
        set $kgm_cpu_number = (int) $arg0
        set $kgm_entry_count = (int) $arg1
        set $kgm_debugentriesfound = 0
-       
-       #if kdebug_flags & KDBG_BFINIT
-       if (kdebug_flags & 0x80000000)  
+       # 0x80000000 == KDBG_BFINIT
+       if (kd_ctrl_page.kdebug_flags & 0x80000000)     
                showkerneldebugheader
                
                if $kgm_entry_count == 0
@@ -8465,16 +11104,17 @@ define showkerneldebugbuffercpu
                else
                        set $kgm_kdbp = &kdbip[$kgm_cpu_number]
                        set $kgm_kdsp = $kgm_kdbp->kd_list_head
-                       while (($kgm_kdsp != 0) && ($kgm_entry_count > 0))
-                               if $kgm_kdsp->kds_readlast != $kgm_kdsp->kds_bufptr
-                                       set $kgm_kds_bufptr = $kgm_kdsp->kds_bufptr
-                                       while (($kgm_kds_bufptr > $kgm_kdsp->kds_readlast) && ($kgm_entry_count > 0))
+                       while (($kgm_kdsp.raw != 0) && ($kgm_entry_count > 0))
+                               set $kgm_kdsp_actual = &kd_bufs[$kgm_kdsp.buffer_index].kdsb_addr[$kgm_kdsp.offset]
+                               if $kgm_kdsp_actual->kds_readlast != $kgm_kdsp_actual->kds_bufindx
+                                       set $kgm_kds_bufptr = &$kgm_kdsp_actual->kds_records[$kgm_kdsp_actual->kds_bufindx]
+                                       while (($kgm_kds_bufptr > &$kgm_kdsp_actual->kds_records[$kgm_kdsp_actual->kds_readlast]) && ($kgm_entry_count > 0))
                                                set $kgm_kds_bufptr = $kgm_kds_bufptr - 1
                                                set $kgm_entry_count = $kgm_entry_count - 1
                                                showkerneldebugbufferentry $kgm_kds_bufptr
                                        end
                                end
-                               set $kgm_kdsp = $kgm_kdsp->kds_next
+                               set $kgm_kdsp = $kgm_kdsp_actual->kds_next
                        end
                end
        else
@@ -8488,9 +11128,8 @@ Syntax:  showkerneldebugbuffercpu <cpu> <count>
 end
 
 define showkerneldebugbuffer
-       
-       #if kdebug_flags & KDBG_BFINIT
-       if (kdebug_flags & 0x80000000)  
+       # 0x80000000 == KDBG_BFINIT
+       if (kd_ctrl_page.kdebug_flags & 0x80000000)     
        
                set $kgm_entrycount = (int) $arg0
        
@@ -8534,19 +11173,30 @@ Syntax: showallvmstats
 | prints a summary of vm statistics in a table format
 end
 
+define memstats
+       if ($kgm_mtype == $kgm_mtype_arm)
+               printf "kern_memorystatus_level:  %8d\n", kern_memorystatus_level
+       end     
+       printf "vm_page_throttled_count:  %8d\n", vm_page_throttled_count 
+       printf "vm_page_active_count:     %8d\n", vm_page_active_count
+       printf "vm_page_inactive_count:   %8d\n", vm_page_inactive_count
+       printf "vm_page_wire_count:       %8d\n", vm_page_wire_count
+       printf "vm_page_free_count:       %8d\n", vm_page_free_count
+       printf "vm_page_purgeable_count:  %8d\n", vm_page_purgeable_count
+       printf "vm_page_inactive_target:  %8d\n", vm_page_inactive_target
+       printf "vm_page_free_target:      %8d\n", vm_page_free_target
+       printf "inuse_ptepages_count:     %8d\n", inuse_ptepages_count
+       printf "vm_page_free_reserved:    %8d\n", vm_page_free_reserved
+end
+
+document memstats
+Syntax: (gdb) memstats 
+| Prints out a summary of various memory statistics. In particular vm_page_wire_count should
+| be greater than 2K or you are under memory pressure.
+end
+
 define show_user_registers
-       if (($kgm_mtype & $kgm_mtype_x86_mask) == $kgm_mtype_x86_any)
-               set $kgm_thread = (thread_t)$arg0
-               if ((*(thread_t)$kgm_thread)->machine.xxx_pcb.iss.flavor == 15)
-                       p/x ($kgm_thread)->machine.xxx_pcb.iss->uss.ss_64
-               else
-                       p/x ($kgm_thread)->machine.xxx_pcb.iss->uss.ss_32
-               end
-       end
-       if ($kgm_mtype == $kgm_mtype_ppc)
-               set $kgm_thread = (thread_t)$arg0
-               p/x *($kgm_thread)->machine.pcb
-       end
+       showuserregisters $arg0
 end
 
 document show_user_registers
@@ -8691,6 +11341,35 @@ Syntax: strcmp_nomalloc <string> <a> [b] [c] [d] [e] [f] [g] [h] [i]
 | strcmp_nomalloc version $kgm_strcmp_arg
 end
 
+define memcpy
+    set $kgm_dst = (unsigned char *)$arg0
+    set $kgm_src = (unsigned char *)$arg1
+    set $kgm_count = $arg2
+
+    # printf "src %p dst %p len %d\n", $kgm_src, $kgm_dst, $kgm_count
+
+    while ($kgm_count >= 8)
+        set *(unsigned long long *)$kgm_dst = *(unsigned long long *)$kgm_src
+
+        set $kgm_dst = $kgm_dst + 8
+        set $kgm_src = $kgm_src + 8
+        set $kgm_count = $kgm_count - 8
+    end
+    while ($kgm_count > 0)
+        set *$kgm_dst = *$kgm_src
+
+        set $kgm_dst = $kgm_dst + 1
+        set $kgm_src = $kgm_src + 1
+        set $kgm_count = $kgm_count - 1
+    end
+end
+
+document memcpy
+Syntax: memcpy <dst> <src> <n>
+| Given two addresses that are accessible by the debugger, perform
+| a memory copy of <n> bytes from <src> to <dst>
+end
+
 # _pci_cfg_addr_value $addr $size
 define _pci_cfg_addr_value
    readphysint $arg0 $arg1 $kgm_lcpu_self
@@ -8730,7 +11409,7 @@ define _pci_cfg_init
          end
        end
 
-       # if the above fails, search for 0:0:0 in likely places.
+       # search for 0:0:0 in likely places if the above fails
        if $kgm_pci_cfg_init == 0
                  set $kgm_pci_cfg_base = 0xF0000000
          while $kgm_pci_cfg_init == 0 && $kgm_pci_cfg_base > 0xA0000000
@@ -9162,6 +11841,8 @@ set $_ioapic_index_ver         = 0x01
 set $_ioapic_index_redir_base  = 0x10
 
 set $_apic_vector_mask         = 0xFF
+set $_apic_timer_tsc_deadline  = 0x40000
+set $_apic_timer_periodic      = 0x20000
 set $_apic_masked              = 0x10000
 set $_apic_trigger_level       = 0x08000
 set $_apic_polarity_high       = 0x02000
@@ -9209,30 +11890,39 @@ end
 define _apic_print
        set $value = $arg0
 
-       printf "[VEC=%3d ", $value & $_apic_vector_mask
+       printf "[VEC=%3d", $value & $_apic_vector_mask
        if $value & $_apic_masked
-         printf "MASK=yes "
+         printf " MASK=yes"
        else
-         printf "MASK=no  "
+         printf " MASK=no "
        end       
 
        if $value & $_apic_trigger_level
-                 printf "TRIG=level "
+                 printf " TRIG=level"
        else
-         printf "TRIG=edge  "
+         printf " TRIG=edge "
        end
 
        if $value & $_apic_polarity_high
-                 printf "POL=high"
+                 printf " POL=high"
        else
-         printf "POL=low "
+         printf " POL=low "
        end
 
        if $value & $_apic_pending
-                 printf " PEND=yes]\n"
+                 printf " PEND=yes"
        else
-         printf " PEND=no ]\n"
+         printf " PEND=no "
+       end
+
+       if $value & $_apic_timer_periodic
+         printf " PERIODIC"
        end
+       if $value & $_apic_timer_tsc_deadline
+         printf " TSC_DEADLINE"
+       end
+
+       printf "]\n"
 end
 
 define ioapic_read32
@@ -10019,6 +12709,31 @@ Syntax: (gdb) showeventsourceobject <prefix> <object>
 | Routine to display information about an IOEventSource subclass.
 end
 
+define showworkloopallocator
+       set $kgm_workloop = (struct IOWorkLoop*)$arg0
+       set $kgm_bt = (void**)$kgm_workloop->reserved->allocationBacktrace
+       set $kgm_bt_count = 0
+       while $kgm_bt_count != (sizeof(IOWorkLoop::ExpansionData.allocationBacktrace) / sizeof(IOWorkLoop::ExpansionData.allocationBacktrace[0]))
+               set $kgm_frame_address = (void*)$kgm_bt[$kgm_bt_count]
+               if $kgm_frame_address != 0
+                       if (((unsigned long) $kgm_frame_address < (unsigned long) &_mh_execute_header || \
+                            (unsigned long) $kgm_frame_address >= (unsigned long) &last_kernel_symbol ) \
+                           && ($kgm_show_kmod_syms == 0))
+                               showkmodaddr $kgm_frame_address
+                       else
+                               output /a $kgm_frame_address
+                       end
+                       printf "\n"
+               end
+               set $kgm_bt_count = $kgm_bt_count + 1
+       end
+end
+document showworkloopallocator
+Syntax: (gdb) showworkloopallocator <workloop>
+| Routine to display the backtrace of the thread which allocated the workloop in question. Only
+| valid on DEBUG kernels.
+end
+
 define showworkloopeventsources
        set $kgm_eventsource = (struct IOEventSource*)$arg0
     while $kgm_eventsource != 0
@@ -10098,10 +12813,27 @@ define showworkloop
        end
        printf "\t\t"
        set $kgm_gateLock = ( struct _IORecursiveLock *)$kgm_workloop->gateLock
-       set $kgm_lockGroup = (struct _lck_grp_*)($kgm_gateLock->group)
-       printf "%s", $kgm_lockGroup->lck_grp_name
-       printf "\n"
-       showworkloopeventsources $kgm_workloop->eventChain
+       if $kgm_gateLock != 0
+               set $kgm_lockGroup = (struct _lck_grp_*)($kgm_gateLock->group)
+               printf "%s", $kgm_lockGroup->lck_grp_name
+       else
+               printf "No WorkLoop Lock found"
+       end
+       printf "\n\n"
+       
+       #Allocation backtrace is only valid on DEBUG kernels.
+       #printf "Allocation path:\n\n"
+       #showworkloopallocator $kgm_workloop
+       #printf "\n\n"
+       
+       if $kgm_workloop->eventChain != 0
+               printf "Active event sources:\n\n"
+               showworkloopeventsources $kgm_workloop->eventChain
+       end
+       if $kgm_workloop->reserved->passiveEventChain != 0
+               printf "Passive event sources:\n"
+               showworkloopeventsources $kgm_workloop->reserved->passiveEventChain
+       end
 end
 document showworkloop
 Syntax: (gdb) showworkloop <thread> <workloop>
@@ -10187,7 +12919,7 @@ Syntax:  showthreadfortid  <thread_id>
 |corresponding to a given thread_id.
 end
 
-define showtaskbusyports
+define showtaskbusyportsint
     set $kgm_isp = ((task_t)$arg0)->itk_space
        set $kgm_iindex = 0
        while ( $kgm_iindex < $kgm_isp->is_table_size )
@@ -10202,6 +12934,10 @@ define showtaskbusyports
        end
 end
 
+define showtaskbusyports
+    showtaskbusyportsint $arg0
+end
+
 document showtaskbusyports
 Syntax:  showtaskbusyports <task>
 |Routine to print information about receive rights belonging to this task that
@@ -10212,7 +12948,7 @@ define showallbusyports
     set $kgm_head_taskp = &tasks
     set $kgm_cur_taskp = (struct task *)($kgm_head_taskp->next)
     while $kgm_cur_taskp != $kgm_head_taskp
-               showtaskbusyports $kgm_cur_taskp
+               showtaskbusyportsint $kgm_cur_taskp
        set $kgm_cur_taskp = (struct task *)($kgm_cur_taskp->tasks.next)
     end
 end
@@ -10223,16 +12959,712 @@ Syntax:  showallbusyports
 |have enqueued messages.
 end
 
-define kdp-connect
-    if $argc > 0
-       kdp-reattach $arg0
+define showallproviders
+    set $kgm_providerp = dtrace_provider
+    while $kgm_providerp
+        p *(dtrace_provider_t *)$kgm_providerp
+        printf "\n"
+        set $kgm_providerp = (dtrace_provider_t *)($kgm_providerp->dtpv_next)
+    end
+end
+
+document showallproviders
+Syntax: showallproviders
+| Display summary listing of all dtrace_providers
+end
+
+define showmodctlheader
+    printf   "modctl    "
+    showptrhdrpad
+    printf "  stale     "
+    showptrhdrpad
+    printf "  symbols   "
+    showptrhdrpad
+    printf "  address   "
+    showptrhdrpad
+    printf "  size      "
+    showptrhdrpad
+    printf "  loadid    loaded  nenabled  flags      name\n"
+end
+
+define showmodctlint
+    set $kgm_modctlp = (struct modctl *)$arg0
+    showptr $kgm_modctlp
+    printf "  "
+    showptr $kgm_modctlp->mod_stale
+    printf "  "
+    showptr $kgm_modctlp->mod_user_symbols
+    printf "  "
+    showptr $kgm_modctlp->mod_address
+    printf "  "
+    showptr $kgm_modctlp->mod_size
+    printf "  "
+    printf "%6d  ", $kgm_modctlp->mod_loadcnt
+    printf "%6d  ", $kgm_modctlp->mod_loaded
+    printf "%6d  ", $kgm_modctlp->mod_nenabled
+    printf "    0x%x  ", $kgm_modctlp->mod_flags
+    printf "%s\n", $kgm_modctlp->mod_modname
+end
+
+define showmodctl
+    showmodctlheader
+    showmodctlint $arg0
+end
+document showmodctl
+Syntax: (gdb) showmodctl <addr>
+| Display info about a dtrace modctl
+end
+
+define showallmodctls
+    showmodctlheader
+    set $kgm_modctlp = (struct modctl *)dtrace_modctl_list
+    while $kgm_modctlp
+        showmodctlint $kgm_modctlp
+        set $kgm_modctlp = $kgm_modctlp->mod_next
+    end
+end
+document showallmodctls
+Syntax: (gdb) showallmodctls
+| Display summary listing of all dtrace modctls
+end
+
+define showfbtprobe
+  printf "Be very patient, this traverses a large list \n"
+  set $kgm_indx = 0
+  set $kgm_found = 0
+  set $kgm_depth = 0
+  while $kgm_indx < fbt_probetab_size && !$kgm_found
+    set $kgm_fbt_probep = (struct fbt_probe *)fbt_probetab[$kgm_indx]
+    set $kgm_depth = 0
+    if $kgm_fbt_probep
+      set $kgm_probeid = (struct fbt_probe *)$kgm_fbt_probep->fbtp_id
+      if $kgm_probeid == $arg0
+        set $kgm_found = 1
+        loop_break
+      else
+       set $kgm_fbt_probep = $kgm_fbt_probep->fbtp_hashnext
+       while $kgm_fbt_probep
+         set $kgm_depth++
+         set $kgm_probeid = (struct fbt_probe *)$kgm_fbt_probep->fbtp_id
+         if $kgm_probeid == $arg0
+           set $kgm_found = 1
+           loop_break
+         else
+           set $kgm_fbt_probep = $kgm_fbt_probep->fbtp_hashnext
+         end
+        end
+      end
+    end
+    if !$kgm_found
+      set $kgm_indx++
     else
-       printf "Attempting to attach to localhost...\n"
-       kdp-reattach localhost
+      printf "fbt_probetab[index=%d], depth=%d, 0x%x\n", $kgm_indx, $kgm_depth, $kgm_fbt_probep
+      printf "(gdb) p *(struct fbt_probe *)0x%x\n", $kgm_fbt_probep
+      p *(struct fbt_probe *)$kgm_fbt_probep
+      set $kgm_fbtp_ctl = (struct fbt_probe *)$kgm_fbt_probep->fbtp_ctl
+      showmodctl $kgm_fbtp_ctl
+      loop_break
+    end
+  end
+end
+document showfbtprobe
+Syntax: (gdb) showfbtprobe <id>
+| Display info about an fbt probe given an id.
+| Traverses fbt_probetab and matches <id> with fbtp_id.
+| The <id> is found using dtrace -l
+end
+
+define showzstacktrace
+       set $kgm_trace = (void*)$arg0
+       if ($argc == 1)
+               set $kgm_trace_size = 15
+       end
+       if ($argc == 2)
+               set $kgm_trace_size = $arg1
+       end
+       set $kgm_trace_current = 0
+       while ($kgm_trace_current < $kgm_trace_size)
+               set $kgm_trace_addr = (void**)$kgm_trace + $kgm_trace_current
+               set $kgm_trace_value = *((void**)$kgm_trace_addr) 
+               #printf "\t\t"
+               output /a $kgm_trace_value
+               set $kgm_trace_current = $kgm_trace_current + 1
+               printf "\n"
+       end
+end
+
+document showzstacktrace
+Syntax:  showzstacktrace <saved stacktrace> [size]
+| Routine to print a stacktrace stored by OSBacktrace.
+| size is optional, defaults to 15.
+end
+
+define showzalloc
+       set $kgm_zallocation = zallocations[$arg0]
+       print $kgm_zallocation
+       showztrace $kgm_zallocation->za_trace_index
+end
+
+document showzalloc
+Syntax:  showzalloc <index>
+| Prints a zallocation from the zallocations array based off its index, 
+| and prints the associated symbolicated backtrace.
+end
+
+define showztrace
+       set $kgm_ztrace = &ztraces[$arg0]
+       showztraceaddr $kgm_ztrace
+end
+
+document showztrace
+Syntax:  showztrace <trace index>
+| Prints the backtrace from the ztraces array at index
+end
+
+define showztraceaddr
+       print *$arg0
+       showzstacktrace $arg0->zt_stack ($arg0)->zt_depth
+end
+
+document showztraceaddr
+Syntax:  showztraceaddr <trace address>
+| Prints the struct ztrace passed in
+end
+
+#TODO: Iterate through the hash table, or make top_ztrace accurate in the face of deallocations (better idea).
+define showtopztrace
+       set $kgm_top_ztrace = top_ztrace
+       printf "Index: %d\n", (top_ztrace - ztraces)
+       showztraceaddr $kgm_top_ztrace
+end
+
+document showtopztrace
+Syntax:  showtopztrace 
+| Shows the ztrace with the biggest size. (according to top_ztrace, not by iterating through the hash table)
+end
+
+define showzallocs
+       set $kgm_zallocation_current_index = 0
+       set $kgm_zallocations_count = 0
+       set $kgm_max_zallocation = zleak_alloc_buckets
+       printf "INDEX  ADDRESS     "
+       if $kgm_lp64
+        printf "         "
+    end
+       printf "TRACE   SIZE\n"
+       while ($kgm_zallocation_current_index < $kgm_max_zallocation)
+               set $kgm_zallocation_current = zallocations[$kgm_zallocation_current_index]
+               if ($kgm_zallocation_current->element != 0)
+                       printf "%5d  %p   ", $kgm_zallocation_current_index, $kgm_zallocation_current->za_element
+                       printf "%5d %6lu\n", $kgm_zallocation_current->za_trace_index, $kgm_zallocation_current->za_size
+                       set $kgm_zallocations_count = $kgm_zallocations_count + 1
+               end
+               set $kgm_zallocation_current_index = $kgm_zallocation_current_index + 1
+       end
+       printf "Total allocations: %d\n", $kgm_zallocations_count
+end
+
+document showzallocs
+Syntax:  showzallocs
+| Prints all allocations in the zallocations table
+end
+
+define showzallocsfortrace
+       set $kgm_zallocation_current_index = 0
+       set $kgm_zallocations_count = 0
+       set $kgm_max_zallocation = zleak_alloc_buckets
+       printf "INDEX  ADDRESS     "
+       if $kgm_lp64
+        printf "         "
+    end
+       printf "SIZE\n"
+       while ($kgm_zallocation_current_index < $kgm_max_zallocation)
+               set $kgm_zallocation_current = zallocations[$kgm_zallocation_current_index]
+               if ($kgm_zallocation_current->element != 0 && $kgm_zallocation_current->za_trace_index == $arg0)
+                       printf "%5d  %p ", $kgm_zallocation_current_index, $kgm_zallocation_current->za_element
+                       printf "%6lu\n", $kgm_zallocation_current->size
+                       set $kgm_zallocations_count = $kgm_zallocations_count + 1
+               end
+               set $kgm_zallocation_current_index = $kgm_zallocation_current_index + 1
+       end
+       printf "Total allocations: %d\n", $kgm_zallocations_count
+end
+
+document showzallocsfortrace
+Syntax:  showzallocsfortrace <trace index>
+| Prints all allocations pointing to the passed in trace's index into ztraces by looking through zallocations table
+end
+
+define showztraces
+       showztracesabove 0
+end
+
+document showztraces
+Syntax:  showztraces
+| Prints all traces with size > 0
+end
+
+define showztracesabove
+       set $kgm_ztrace_current_index = 0
+       set $kgm_ztrace_count = 0
+       set $kgm_max_ztrace = zleak_trace_buckets
+       printf "INDEX    SIZE\n"
+       while ($kgm_ztrace_current_index < $kgm_max_ztrace)
+               set $kgm_ztrace_current = ztraces[$kgm_ztrace_current_index]
+               if ($kgm_ztrace_current->zt_size > $arg0)
+                       printf "%5d  %6lu\n", $kgm_ztrace_current_index, $kgm_ztrace_current->zt_size
+                       set $kgm_ztrace_count = $kgm_ztrace_count + 1
+               end
+               set $kgm_ztrace_current_index = $kgm_ztrace_current_index + 1
+       end
+       printf "Total traces: %d\n", $kgm_ztrace_count
+end
+
+document showztracesabove
+Syntax:  showztracesabove <size>
+| Prints all traces with size greater than X
+end
+
+define showztracehistogram
+       set $kgm_ztrace_current_index = 0
+       set $kgm_ztrace_count = 0
+       set $kgm_max_ztrace = zleak_trace_buckets
+       printf "INDEX  HIT_COUNT  COLLISIONS\n"
+       while ($kgm_ztrace_current_index < $kgm_max_ztrace)
+               set $kgm_ztrace_current = ztraces[$kgm_ztrace_current_index]
+               if ($kgm_ztrace_current->zt_hit_count != 0)
+                       printf "%5d      %5d    %5d\n", $kgm_ztrace_current_index, $kgm_ztrace_current->zt_hit_count, $kgm_ztrace_current->zt_collisions
+                       set $kgm_ztrace_count = $kgm_ztrace_count + 1
+               end
+               set $kgm_ztrace_current_index = $kgm_ztrace_current_index + 1
+       end
+       printf "Total traces: %d\n", $kgm_ztrace_count
+end
+
+document showztracehistogram
+Syntax:  showztracehistogram
+| Prints the histogram of the ztrace table
+end
+
+define showzallochistogram
+       set $kgm_zallocation_current_index = 0
+       set $kgm_zallocations_count = 0
+       set $kgm_max_zallocation = zleak_alloc_buckets
+       printf "INDEX  HIT_COUNT\n"
+       while ($kgm_zallocation_current_index < $kgm_max_zallocation)
+               set $kgm_zallocation_current = zallocations[$kgm_zallocation_current_index]
+               if ($kgm_zallocation_current->za_hit_count != 0)
+                       printf "%5d      %5d\n", $kgm_zallocation_current_index, $kgm_zallocation_current->za_hit_count
+                       set $kgm_zallocations_count = $kgm_zallocations_count + 1
+               end
+               set $kgm_zallocation_current_index = $kgm_zallocation_current_index + 1
+       end
+       printf "Total allocations: %d\n", $kgm_zallocations_count
+end
+
+document showzallochistogram
+Syntax:  showzallochistogram
+| Prints the histogram for the zalloc table
+end
+
+define showzstats
+       printf "z_alloc_collisions: %u, z_trace_collisions: %u\n", z_alloc_collisions, z_trace_collisions
+       printf "z_alloc_overwrites: %u, z_trace_overwrites: %u\n", z_alloc_overwrites, z_trace_overwrites
+       printf "z_alloc_recorded: %u, z_trace_recorded: %u\n", z_alloc_recorded, z_trace_recorded
+end
+
+document showzstats
+Syntax:  showzstats
+| Prints the zone leak detection stats
+end
+
+
+set $kgm_au_sentry_hash_table_size = 97
+
+define showsession1
+  set $p = (struct au_sentry *)$arg0
+  showptr $p
+  printf "  0x%08x  0x%08x  0x%016x", $p->se_auinfo.ai_asid, $p->se_auinfo.ai_auid, $p->se_auinfo.ai_flags
+  printf "  %3ld  %3ld", $p->se_refcnt, $p->se_procnt
+  printf "\n"
+end
+
+define showsessionhdr
+  printf "au_sentry "
+  showptrhdrpad
+  printf "  ASID        AUID        FLAGS               C    P\n"
+end
+
+define showsession
+  showsessionhdr
+  showsession1 $arg0
+end
+
+document showsession
+Syntax:  showsession
+| Display info about a specified audit session
+end
+
+define showallsessions
+  showsessionhdr
+  set $kgm_au_sentry_hash_table = au_sentry_bucket
+  set $i = $kgm_au_sentry_hash_table_size - 1
+  while $i >= 0
+    set $p = $kgm_au_sentry_hash_table[$i].lh_first
+    while $p != 0
+      showsession1 $p
+      set $p = $p->se_link.le_next
+    end
+    set $i = $i - 1
+  end
+end
+
+document showallsessions
+Syntax:  showallsessions
+| Prints the audit sessions in the global hash table
+end
+
+define showauhistorystack
+  set $ii = $arg0
+  set $pp = (void **)$arg1
+  while $ii > 0
+    printf "  "
+    x/i $pp[$ii-1]
+    set $ii = $ii - 1
+  end
+end
+
+define showauhistory1
+  set $p = (struct au_history *)$arg0
+  set $stack_depth = $p->stack_depth
+  set $stack = $p->stack
+  showptr $p->ptr
+  if $p->event == 1
+    printf "    REF"
+  end
+  if $p->event == 2
+    printf "  UNREF"
+  end
+  if $p->event == 3
+    printf "  BIRTH"
+  end
+  if $p->event == 4
+    printf "  DEATH"
+  end
+  if $p->event == 5
+    printf "  FIND"
+  end
+  set $p = &$p->se
+  printf "  0x%08x  0x%08x  0x%016x", $p->se_auinfo.ai_asid, $p->se_auinfo.ai_auid, $p->se_auinfo.ai_flags
+  printf "  %3ld  %3ld", $p->se_refcnt, $p->se_procnt
+  printf "\n"
+  showauhistorystack $stack_depth $stack
+end
+
+define showauhistory
+  set $i = (au_history_index-1) % au_history_size
+  if au_history_index >= au_history_size
+    set $n = au_history_size
+  else
+    set $n = au_history_index
+  end
+  while $n > 0
+    if au_history[$i].ptr != 0 && (0 == $arg0 || au_history[$i].ptr == $arg0)
+      printf "[% 4d]  ", $i
+      showauhistory1 &au_history[$i]
+    end
+    set $n = $n - 1
+    set $i = ($i - 1) % au_history_size
+  end
+end
+
+define showallauhistory
+  showauhistory 0
+end
+
+define showkwqheader
+       printf "        kwq     "
+    showptrhdrpad
+       printf "    kwqaddr     "
+    showptrhdrpad
+    printf "  inqueue  fakecount  highseq  lowseq   flags   lastunlock    p_rwwc"
+    printf "\n          "
+end
+
+define showkwqint
+       printf "              "
+       set $kgm_kwq = (ksyn_wait_queue_t)$arg0
+       showptr $kgm_kwq
+       printf "  "
+       showptr $kgm_kwq->kw_addr
+       printf "   "
+       printf "  %d      ", $kgm_kwq->kw_inqueue
+       printf "    %d  ", $kgm_kwq->kw_fakecount
+       printf "     0x%x  ", $kgm_kwq->kw_highseq
+       printf "  0x%x  ", $kgm_kwq->kw_lowseq
+       printf "  0x%x  ", $kgm_kwq->kw_flags
+       printf "  0x%x  ", $kgm_kwq->kw_lastunlockseq
+       printf "    0x%x  ", $kgm_kwq->kw_pre_rwwc
+       printf "\n"
+end
+
+define show_kwq
+       showkwqheader
+       showkwqint $arg0
+end
+
+document show_kwq
+Syntax: (gdb) show_kwq <kwq>
+| Display info about one ksyn_wait_queue
+end
+
+# Internal routine used by "showpthread_mutex" to abstract possible loads from
+# user space
+define _loadfrommutex
+        if (kdp_pmap == 0)
+                set $kgm_loadval = *(uintptr_t *)$arg0
+        else
+        if ($kgm_x86_abi == 0xe)
+              set $kgm_loadval = *(uint32_t *)$arg0
+        else
+        if ($kgm_x86_abi == 0xf)
+            if ($kgm_mtype == $kgm_mtype_i386)
+                    _loadk32m64 $arg0
+                    set $kgm_loadval = $kgm_k32read64  
+            else
+                    set $kgm_loadval = *(uint32_t *)$arg0
+            end
+        end
+        end
+end
+end
+
+define show_pthreadmutex
+       set $newact = (struct thread *) $arg0
+       set $ourtask = (struct task *)($newact->task)
+       set $our_user_is64 = ($ourtask->taskFeatures[0] & 0x80000000)
+       _kgm_flush_loop
+       set $mutex = (void *)$arg1
+       set kdp_pmap = $newact->task->map->pmap
+       _kgm_flush_loop
+       _kgm_update_loop
+       set $newiss = (x86_saved_state_t *) ($newact->machine.pcb->iss)
+       set $kgm_x86_abi = $newiss.flavor
+       if ($our_user_is64 != 0)
+               printf "\tUser 64Bit\n "
+               printf "\tSignature: "
+               set $nextval = $mutex
+               _loadfrommutex $nextval
+               printf "0x%x\n",$kgm_loadval
+               printf "\tflags: "
+               set $nextval = $mutex + 12
+               _loadfrommutex $nextval
+               printf "0x%x\n",$kgm_loadval
+               printf "\tSeqs: "
+               set $nextval = $mutex + 20
+               _loadfrommutex $nextval
+               printf "0x%x   ",$kgm_loadval
+               set $nextval = $mutex + 24
+               _loadfrommutex $nextval
+               printf "0x%x   ",$kgm_loadval
+               set $nextval = $mutex + 28
+               _loadfrommutex $nextval
+               printf "0x%x\n",$kgm_loadval
+               printf "\ttid[0]: "
+               set $nextval = $mutex + 32
+               _loadfrommutex $nextval
+               printf "0x%x\n",$kgm_loadval
+               printf "\ttid[1]: "
+               set $nextval = $mutex + 36
+               _loadfrommutex $nextval
+               printf "0x%x\n",$kgm_loadval
+       else
+               printf "\tUser 32Bit\n "
+               printf "\tSignature: "
+               set $nextval = $mutex
+               _loadfrommutex $nextval
+               printf "0x%x\n",$kgm_loadval
+               printf "\tflags: "
+               set $nextval = $mutex + 8
+               _loadfrommutex $nextval
+               printf "0x%x\n",$kgm_loadval
+               printf "\tSeqs: "
+               set $nextval = $mutex + 16
+               _loadfrommutex $nextval
+               printf "0x%x   ",$kgm_loadval
+               set $nextval = $mutex + 20
+               _loadfrommutex $nextval
+               printf "0x%x   ",$kgm_loadval
+               set $nextval = $mutex + 24
+               _loadfrommutex $nextval
+               printf "0x%x\n",$kgm_loadval
+               printf "\ttid[0]: "
+               set $nextval = $mutex + 32
+               _loadfrommutex $nextval
+               printf "0x%x\n",$kgm_loadval
+               printf "\ttid[1]: "
+               set $nextval = $mutex + 36
+               _loadfrommutex $nextval
+               printf "0x%x\n",$kgm_loadval
+       end
+       printf "\n"
+       resetstacks
+end
+
+
+document show_pthreadmutex
+Syntax: (gdb) show_pthreadmutex <thread> <user_mutexaddr>
+| Display the mutex contents from userspace.
+end
+
+
+define show_pthreadcondition
+       set $newact = (struct thread *) $arg0
+       set $ourtask = (struct task *)($newact->task)
+       set $our_user_is64 = ($ourtask->taskFeatures[0] & 0x80000000)
+       _kgm_flush_loop
+       set $cond = (void *)$arg1
+       set kdp_pmap = $newact->task->map->pmap
+       _kgm_flush_loop
+       _kgm_update_loop
+       set $newiss = (x86_saved_state_t *) ($newact->machine.pcb->iss)
+       set $kgm_x86_abi = $newiss.flavor
+       if ($our_user_is64 != 0)
+               printf "\tUser 64Bit\n "
+               printf "\tSignature: "
+               set $nextval = $cond
+               _loadfrommutex $nextval
+               printf "0x%x\n",$kgm_loadval
+               printf "\tflags: "
+               set $nextval = $cond + 12
+               _loadfrommutex $nextval
+               printf "0x%x\n",$kgm_loadval
+               printf "\tSeqs: "
+               set $nextval = $cond + 24
+               _loadfrommutex $nextval
+               printf "0x%x   ",$kgm_loadval
+               set $nextval = $cond + 28
+               _loadfrommutex $nextval
+               printf "0x%x   ",$kgm_loadval
+               set $nextval = $cond + 32
+               _loadfrommutex $nextval
+               printf "0x%x\n",$kgm_loadval
+               printf "\tMutex lowaddr: "
+               set $nextval = $cond + 16
+               _loadfrommutex $nextval
+               printf "0x%08x\n",$kgm_loadval
+               printf "\tMutex highaddr: "
+               set $nextval = $cond + 20
+               _loadfrommutex $nextval
+               printf "0x%x\n",$kgm_loadval
+       else
+               printf "\tUser 32Bit\n "
+               printf "\tSignature: "
+               set $nextval = $cond
+               _loadfrommutex $nextval
+               printf "0x%x\n",$kgm_loadval
+               printf "\tflags: "
+               set $nextval = $cond + 8
+               _loadfrommutex $nextval
+               printf "0x%x\n",$kgm_loadval
+               printf "\tSeqs: "
+               set $nextval = $cond + 16
+               _loadfrommutex $nextval
+               printf "0x%x   ",$kgm_loadval
+               set $nextval = $cond + 20
+               _loadfrommutex $nextval
+               printf "0x%x   ",$kgm_loadval
+               set $nextval = $cond + 24
+               _loadfrommutex $nextval
+               printf "0x%x\n",$kgm_loadval
+               printf "\tMutex addr: "
+               set $nextval = $cond + 12
+               _loadfrommutex $nextval
+               printf "0x%x\n",$kgm_loadval
+       end
+       printf "\n"
+       resetstacks
+end
+
+
+document show_pthreadcondition
+Syntax: (gdb) show_pthreadcondition <thread> <user_cvaddr>
+| Display the condition variable contents from userspace.
+end
+
+define processortimers
+    set $kgm_p = processor_list
+    printf "Processor\t\t\t Last dispatch\t\t Next deadline\t\t difference\n"
+    while $kgm_p
+        printf "Processor %d: %p\t", $kgm_p->cpu_id, $kgm_p
+        printf " 0x%016llx\t", $kgm_p->last_dispatch
+        set $kgm_rt_timer = &(cpu_data_ptr[$kgm_p->cpu_id].rtclock_timer)
+        printf " 0x%016llx    \t", $kgm_rt_timer->deadline
+        set $kgm_rt_diff =  ((long long)$kgm_p->last_dispatch) - ((long long)$kgm_rt_timer->deadline)
+        printf " 0x%016llx  ", $kgm_rt_diff
+# normally the $kgm_rt_diff will be close to the last dispatch time, or negative 
+# When it isn't, mark the result as bad. This is a suggestion, not an absolute
+        if ( ($kgm_rt_diff > 0) && ((long long)$kgm_p->last_dispatch) - ($kgm_rt_diff + 1) > 0 )
+            printf "probably BAD\n"
+        else
+            printf "(ok)\n"
+        end
+        # dump the call entries (Intel only)
+        if (($kgm_mtype & $kgm_mtype_x86_mask) == $kgm_mtype_x86_any)
+            printf "Next deadline set at: 0x%016llx. Timer call list:", $kgm_rt_timer->when_set
+            set $kgm_entry = (queue_t *)$kgm_rt_timer->queue
+            if ($kgm_entry == $kgm_rt_timer)
+                printf " (empty)\n"
+            else
+                printf "\n entry:      "
+                showptrhdrpad
+                printf "deadline           soft_deadline      delta      (*func)(param0,param1)\n"
+                while $kgm_entry != $kgm_rt_timer
+                    set $kgm_timer_call = (timer_call_t) $kgm_entry
+                    set $kgm_call_entry = (struct call_entry *) $kgm_entry
+                    printf " "
+                    showptr $kgm_entry
+                    printf ": 0x%016llx 0x%016llx 0x%08x (%p)(%p,%p)\n", \
+                        $kgm_call_entry->deadline, \
+                        $kgm_timer_call->soft_deadline, \
+                        ($kgm_call_entry->deadline - $kgm_timer_call->soft_deadline), \
+                        $kgm_call_entry->func, \
+                        $kgm_call_entry->param0, $kgm_call_entry->param1
+                    set $kgm_entry = $kgm_entry->next
+                end
+            end
+        end
+        set $kgm_p = $kgm_p->processor_list
     end
+    printf "\n"
+end
+
+document processortimers
+Syntax: (gdb) processortimers 
+| Print details of processor timers, noting any timer which might be suspicious
+end
+
+define maplocalcache
+       if ($kgm_mtype == $kgm_mtype_arm)
+               mem 0x80000000 0xefffffff cache
+               set dcache-linesize-power 9
+               printf "GDB memory caching enabled. Be sure to disable by calling flushlocalcache before detaching or connecting to a new device\n"
+       end
+end
+
+document maplocalcache
+Syntax: (gdb) maplocalcache 
+| Sets up memory regions for GDB to cache on read. Significantly increases debug speed over KDP
+end
+
+define flushlocalcache
+       if ($kgm_mtype == $kgm_mtype_arm)
+               delete mem
+               printf "GDB memory caching disabled.\n"
+       end
 end
 
-document kdp-connect
-Syntax: (gdb) kdpconnect <address-of-remote-host>
-| Attach to the machine with given hostname or IP address, or 'localhost' if blank 
+document flushlocalcache
+Syntax: (gdb) flushlocalcache 
+| Clears all memory regions
 end