]> git.saurik.com Git - apple/xnu.git/blame - kgmacros
xnu-1699.22.81.tar.gz
[apple/xnu.git] / kgmacros
CommitLineData
6d2010ae 1
1c79356b
A
2# Kernel gdb macros
3#
4# These gdb macros should be useful during kernel development in
5# determining what's going on in the kernel.
6#
7# All the convenience variables used by these macros begin with $kgm_
8
0c530ab8
A
9set print asm-demangle on
10set cp-abi gnu-v2
9bccf70c 11
b0d623f7
A
12# This option tells gdb to relax its stack tracing heuristics
13# Useful for debugging across stack switches
14# (to the interrupt stack, for instance). Requires gdb-675 or greater.
15set backtrace sanity-checks off
16
1c79356b
A
17echo Loading Kernel GDB Macros package. Type "help kgm" for more info.\n
18
19define kgm
55e303ae
A
20printf ""
21echo These are the gdb macros for kernel debugging. Type "help kgm" for more info.\n
1c79356b
A
22end
23
24document kgm
25| These are the kernel gdb macros. These gdb macros are intended to be
26| used when debugging a remote kernel via the kdp protocol. Typically, you
27| would connect to your remote target like so:
2d21ac55
A
28| (gdb) target remote-kdp
29| (gdb) attach <name-of-remote-host>
1c79356b
A
30|
31| The following macros are available in this package:
91447636 32| showversion Displays a string describing the remote kernel version
1c79356b 33|
55e303ae
A
34| showalltasks Display a summary listing of all tasks
35| showallthreads Display info about all threads in the system
36| showallstacks Display the stack for each thread in the system
37| showcurrentthreads Display info about the thread running on each cpu
38| showcurrentstacks Display the stack for the thread running on each cpu
1c79356b
A
39| showallvm Display a summary listing of all the vm maps
40| showallvme Display a summary listing of all the vm map entries
41| showallipc Display a summary listing of all the ipc spaces
6d2010ae 42| showipcsummary Display a summary listing of the ipc spaces of all tasks
1c79356b 43| showallrights Display a summary listing of all the ipc rights
6d2010ae
A
44| showallkexts Display a summary listing of all loaded kexts (alias: showallkmods)
45| showallknownkexts Display a summary listing of all kexts, loaded or not
46| showallbusyports Display a listing of all ports with unread messages
47| showallprocessors Display a listing of all psets and processors
0c530ab8
A
48|
49| showallclasses Display info about all OSObject subclasses in the system
50| showobject Show info about an OSObject - its vtable ptr and retain count, & more info for simple container classes.
51| showregistry Show info about all registry entries in the current plane
52| showregistryprops Show info about all registry entries in the current plane, and their properties
53| showregistryentry Show info about a registry entry; its properties and descendants in the current plane
54| setregistryplane Set the plane to be used for the iokit registry macros (pass zero for list)
1c79356b 55|
b0d623f7
A
56| setfindregistrystr Set the encoded string for matching with
57| findregistryentry or findregistryprop (created from
58| strcmp_arg_pack64)
59| findregistryentry Find a registry entry that matches the encoded string
60| findregistryentries Find all the registry entries that match the encoded string
61| findregistryprop Search the registry entry for a property that matches
62| the encoded string
63|
55e303ae
A
64| showtask Display info about the specified task
65| showtaskthreads Display info about the threads in the task
66| showtaskstacks Display the stack for each thread in the task
67| showtaskvm Display info about the specified task's vm_map
68| showtaskvme Display info about the task's vm_map entries
69| showtaskipc Display info about the specified task's ipc space
70| showtaskrights Display info about the task's ipc space entries
b7266188 71| showtaskrightsbt Display info about the task's ipc space entries with back traces
b0d623f7 72| showtaskbusyports Display all of the task's ports with unread messages
1c79356b 73|
55e303ae
A
74| showact Display info about a thread specified by activation
75| showactstack Display the stack for a thread specified by activation
1c79356b 76|
55e303ae 77| showmap Display info about the specified vm_map
1c79356b
A
78| showmapvme Display a summary list of the specified vm_map's entries
79|
55e303ae 80| showipc Display info about the specified ipc space
1c79356b
A
81| showrights Display a summary list of all the rights in an ipc space
82|
55e303ae
A
83| showpid Display info about the process identified by pid
84| showproc Display info about the process identified by proc struct
2d21ac55
A
85| showprocinfo Display detailed info about the process identified by proc struct
86| showprocfiles Given a proc_t pointer, display the list of open file descriptors
87| showproclocks Given a proc_t pointer, display the list of advisory file locks
88| zombproc Print out all procs in the zombie list
6d2010ae 89| showproctree Show all the processes in a hierarchical tree form
2d21ac55
A
90| allproc Print out all process in the system not in the zombie list
91| zombstacks Print out all stacks of tasks that are exiting
92|
93| showinitchild Print out all processes in the system which are children of init process
1c79356b 94|
6d2010ae
A
95| showkext Display info about a kext (alias: showkmod)
96| showkextaddr Given an address, display the kext and offset (alias: showkmodaddr)
1c79356b 97|
55e303ae
A
98| dumpcallqueue Dump out all the entries given a queue head
99|
91447636
A
100| showallmtx Display info about mutexes usage
101| showallrwlck Display info about reader/writer locks usage
102|
55e303ae 103| zprint Display info about the memory zones
91447636 104| showioalloc Display info about iokit allocations
55e303ae 105| paniclog Display the panic log info
9bccf70c 106|
55e303ae
A
107| switchtoact Switch to different context specified by activation
108| switchtoctx Switch to different context
91447636
A
109| showuserstack Display numeric backtrace of the user stack for an
110| activation
6d2010ae
A
111| showtaskuserstacks Display user stacks for a specified task
112| showuserregisters Display user registers for the specified thread
113| showtaskuserregisters Display user registers for the specified task
91447636
A
114|
115| switchtouserthread Switch to the user context of the specified thread
116| resetstacks Return to the original kernel context
117|
9bccf70c 118| resetctx Reset context
55e303ae
A
119| resume_on Resume when detaching from gdb
120| resume_off Don't resume when detaching from gdb
1c79356b 121|
91447636 122| sendcore Configure kernel to send a coredump to the specified IP
7e4a7d39
A
123| sendsyslog Configure kernel to send a system log to the specified IP
124| sendpaniclog Configure kernel to send a panic log to the specified IP
91447636 125| disablecore Configure the kernel to disable coredump transmission
7e4a7d39
A
126| getdumpinfo Retrieve the current remote dump parameters
127| setdumpinfo Configure the remote dump parameters
128|
91447636
A
129| switchtocorethread Corefile version of "switchtoact"
130| resetcorectx Corefile version of "resetctx"
0c530ab8 131|
b0d623f7
A
132| readphys8 Reads the specified untranslated address (8-bit read)
133| readphys16 Reads the specified untranslated address (16-bit read)
134| readphys32 Reads the specified untranslated address (32-bit read)
135| readphys64 Reads the specified untranslated address (64-bit read)
136| writephys8 Writes to the specified untranslated address (8-bit write)
137| writephys16 Writes to the specified untranslated address (16-bit write)
138| writephys32 Writes to the specified untranslated address (32-bit write)
139| writephys64 Writes to the specified untranslated address (64-bit write)
140|
141| readioport8 Read 8-bits from the specified I/O Port
142| readioport16 Read 16-bits from the specified I/O Port
143| readioport32 Read 32-bits from the specified I/O Port
144| writeioport8 Write 8-bits into the specified I/O Port
145| writeioport16 Write 16-bits into the specified I/O Port
146| writeioport32 Write 32-bits into the specified I/O Port
147|
148| readmsr64 Read 64-bits from the specified MSR
149| writemsr64 Write 64-bits into the specified MSR
0c530ab8 150|
2d21ac55
A
151| rtentry_showdbg Print the debug information of a route entry
152| rtentry_trash Walk the list of trash route entries
153|
b0d623f7
A
154| inifa_showdbg Print the debug information of an IPv4 interface address
155| in6ifa_showdbg Print the debug information of an IPv6 interface address
6d2010ae
A
156| inm_showdbg Print the debug information of an IPv4 multicast address
157| ifma_showdbg Print the debug information of a link multicast address
158| ifpref_showdbg Print the debug information of an interface ref count
159|
160| ndpr_showdbg Print the debug information of a nd_prefix structure
161| nddr_showdbg Print the debug information of a nd_defrouter structure
162|
163| imo_showdbg Print the debug information of a ip_moptions structure
164| im6o_showdbg Print the debug information of a ip6_moptions structure
165|
166| inifa_trash Walk the list of trash in_ifaddr entries
167| in6ifa_trash Walk the list of trash in6_ifaddr entries
168| inm_trash Walk the list of trash in_multi entries
169| in6m_trash Walk the list of trash in6_multi entries
170| ifma_trash Walk the list of trash ifmultiaddr entries
b0d623f7 171|
2d21ac55
A
172| mbuf_walkpkt Walk the mbuf packet chain (m_nextpkt)
173| mbuf_walk Walk the mbuf chain (m_next)
174| mbuf_buf2slab Find the slab structure of the corresponding buffer
175| mbuf_buf2mca Find the mcache audit structure of the corresponding mbuf
176| mbuf_showmca Print the contents of an mbuf mcache audit structure
177| mbuf_showactive Print all active/in-use mbuf objects
178| mbuf_showinactive Print all freed/in-cache mbuf objects
179| mbuf_showall Print all mbuf objects
180| mbuf_slabs Print all slabs in the group
181| mbuf_slabstbl Print slabs table
182| mbuf_stat Print extended mbuf allocator statistics
6d2010ae
A
183| mbuf_countchain Count the length of an mbuf chain
184| mbuf_topleak Print the top suspected mbuf leakers
185| mbuf_traceleak Print the leak information for a given leak address
2d21ac55
A
186|
187| mcache_walkobj Walk the mcache object chain (obj_next)
188| mcache_stat Print all mcaches in the system
189| mcache_showcache Display the number of objects in the cache
190|
b0d623f7 191| showbootargs Display boot arguments passed to the target kernel
2d21ac55
A
192| showbootermemorymap Dump phys memory map from EFI
193|
b0d623f7
A
194| systemlog Display the kernel's printf ring buffer
195|
196| hexdump Show the contents of memory as a hex/ASCII dump
2d21ac55
A
197|
198| showvnodepath Print the path for a vnode
199| showvnodelocks Display list of advisory locks held/blocked on a vnode
b0d623f7
A
200| showvnodedev Display information about a device vnode
201| showtty Display information about a struct tty
2d21ac55
A
202| showallvols Display a summary of mounted volumes
203| showvnode Display info about one vnode
204| showvolvnodes Display info about all vnodes of a given volume
205| showvolbusyvnodes Display info about busy (iocount!=0) vnodes of a given volume
206| showallbusyvnodes Display info about all busy (iocount!=0) vnodes
207| showallvnodes Display info about all vnodes
208| print_vnode Print out the fields of a vnode struct
209| showprocvnodes Print out all the open fds which are vnodes in a process
210| showallprocvnodes Print out all the open fds which are vnodes in any process
211| showmountvnodes Print the vnode list
212| showmountallvnodes Print the vnode inactive list
213| showworkqvnodes Print the vnode worker list
214| shownewvnodes Print the new vnode list
215|
b0d623f7 216| ifconfig display ifconfig-like output
6d2010ae 217| showifnets show the list of attached and detached interfaces
b0d623f7
A
218| showifaddrs show the list of addresses for the given ifp
219| showifmultiaddrs show the list of multicast addresses for the given ifp
6d2010ae
A
220| showinmultiaddrs show the list of IPv4 multicast addresses records
221| showin6multiaddrs show the list of IPv6 multicast addresses records
b0d623f7
A
222|
223| showsocket Display information about a socket
224| showprocsockets Given a proc_t pointer, display information about its sockets
225| showallprocsockets Display information about the sockets of all the processes
226|
227| show_tcp_pcbinfo Display the list of the TCP protocol control blocks
228| show_tcp_timewaitslots Display the list of the TCP protocol control blocks in TIMEWAIT
229| show_udp_pcbinfo Display the list of UDP protocol control blocks
230|
231| show_rt_inet Display the IPv4 routing table
232| show_rt_inet6 Display the IPv6 routing table
2d21ac55 233|
6d2010ae 234| showpmworkqueue Display the IOPMWorkQueue object
2d21ac55
A
235| showregistrypmstate Display power management state for all IOPower registry entries
236| showioservicepm Display the IOServicePM object
237| showstacksaftertask showallstacks starting after a given task
238| showstacksafterthread showallstacks starting after a given thread
239|
240| showMCAstate Print machine-check register state after MC exception.
241|
242| showallgdbstacks Cause GDB to trace all thread stacks
243| showallgdbcorestacks Corefile equivalent of "showallgdbstacks"
244| kdp-reenter Schedule reentry into the debugger and continue.
245| kdp-reboot Restart remote target
6d2010ae 246| kdp-version Get KDP version number
2d21ac55 247|
c910b4d9
A
248| zstack Print zalloc caller stack (zone leak debugging)
249| findoldest Find oldest zone leak debugging record
250| countpcs Print how often a pc occurs in the zone leak log
251|
6d2010ae
A
252| showtopztrace Print the ztrace with the most outstanding allocated memory
253| showztrace Print a backtrace record given its index
254| showzalloc Print an allocation record + stacktrace at index
255| showztraceaddr Print a backtrace record given its address
256| showztracesabove Print all the backtrace records with a size bigger than X
257| showzstacktrace Symbolicate and print a stored OSBacktrace
258|
259| showztraces Finds all in-use traces in the ztraces table
260| showzallocs Finds all in-use allocations in the zallocs table
261| showzstats Shows the statistics gathered about the hash tables
262|
263| showzallocsfortrace Print all the allocations that refer to a trace
264| showztracehistogram Prints a histogram of the ztraces table
265| showzallochistogram Prints a histogram of the zallocs table
266|
b0d623f7
A
267| pmap_walk Perform a page-table walk
268| pmap_vtop Translate a virtual address to physical address
269|
6d2010ae
A
270| showuserdyldinfo Show dyld information and error messages
271| in the target task
272| showuserlibraries Show binary images known by dyld in the
273| target task
274| showallvmstats Prints a summary of vm statistics in a table format
275| memstats Displays memory statistics in a table format
b0d623f7 276|
6d2010ae
A
277| showthreadfortid Displays the address of the thread structure
278| for a given thread_id value.
b0d623f7
A
279|
280| strcmp_nomalloc A version of strcmp that avoids the use of malloc
281| through the use of encoded strings created via
282| strcmp_arg_pack64.
283| strcmp_arg_pack64 Pack a string into a 64-bit quantity for use by
284| strcmp_nomalloc
285|
286| pci_cfg_read8 Read 8-bits from a PCI config space register
287| pci_cfg_read16 Read 16-bits from a PCI config space register
288| pci_cfg_read32 Read 32-bits from a PCI config space register
289| pci_cfg_write8 Write 8-bits into a PCI config space register
290| pci_cfg_write16 Write 16-bits into a PCI config space register
291| pci_cfg_write32 Write 32-bits into a PCI config space register
292| pci_cfg_dump Dump entire config space for a PCI device
293| pci_cfg_scan Perform a scan for PCI devices
294| pci_cfg_dump_all Dump config spaces for all detected PCI devices
295|
296| lapic_read32 Read APIC entry
297| lapic_write32 Write APIC entry
298| lapic_dump Dump APIC entries
299|
300| ioapic_read32 Read IOAPIC entry
301| ioapic_write32 Write IOAPIC entry
302| ioapic_dump Dump IOAPIC entries
c910b4d9 303|
6d2010ae
A
304| showallproviders Display summary listing of all dtrace_providers
305| showallmodctls Display summary listing of all dtrace modctls
306| showmodctl Display info about a dtrace modctl
307| showfbtprobe Display info about an fbt probe given an id (traverses fbt_probetab)
308| processortimers Display all processor timers, noting any inconsistencies
309|
1c79356b
A
310| Type "help <macro>" for more specific help on a particular macro.
311| Type "show user <macro>" to see what the macro is really doing.
312end
313
0c530ab8
A
314# This macro should appear before any symbol references, to facilitate
315# a gdb "source" without a loaded symbol file.
316define showversion
b0d623f7 317 kdp-kernelversion
0c530ab8
A
318end
319
320document showversion
321Syntax: showversion
322| Read the kernel version string from a fixed address in low
323| memory. Useful if you don't know which kernel is on the other end,
324| and need to find the appropriate symbols. Beware that if you've
325| loaded a symbol file, but aren't connected to a remote target,
326| the version string from the symbol file will be displayed instead.
327| This macro expects to be connected to the remote kernel to function
328| correctly.
329end
330
b0d623f7
A
331set $kgm_mtype_ppc = 0x00000012
332set $kgm_mtype_arm = 0x0000000C
2d21ac55 333
b0d623f7
A
334set $kgm_mtype_i386 = 0x00000007
335set $kgm_mtype_x86_64 = 0x01000007
336set $kgm_mtype_x86_any = $kgm_mtype_i386
337set $kgm_mtype_x86_mask = 0xFEFFFFFF
338
339set $kgm_mtype = ((unsigned int *)&_mh_execute_header)[1]
340set $kgm_lp64 = $kgm_mtype & 0x01000000
2d21ac55 341
7e4a7d39
A
342set $kgm_manual_pkt_ppc = 0x549C
343set $kgm_manual_pkt_i386 = 0x249C
344set $kgm_manual_pkt_x86_64 = 0xFFFFFF8000002930
345set $kgm_manual_pkt_arm = 0xFFFF04A0
346
347set $kgm_kdp_pkt_data_len = 128
348
349# part of data packet
350set $kgm_kdp_pkt_hdr_req_off = 0
351set $kgm_kdp_pkt_hdr_seq_off = 1
352set $kgm_kdp_pkt_hdr_len_off = 2
353set $kgm_kdp_pkt_hdr_key_off = 4
354
355# after data packet
356set $kgm_kdp_pkt_len_off = $kgm_kdp_pkt_data_len
357set $kgm_kdp_pkt_input_off = $kgm_kdp_pkt_data_len + 4
358
359set $kgm_kdp_pkt_hostreboot = 0x13
360set $kgm_kdp_pkt_hdr_size = 8
361
6d2010ae
A
362
363set $kgm_readphys_force_kdp = 0
364set $kgm_readphys_force_physmap = 0
365
b0d623f7 366set $kgm_lcpu_self = 0xFFFE
0c530ab8
A
367
368set $kgm_reg_depth = 0
b0d623f7
A
369set $kgm_reg_depth_max = 0xFFFF
370set $kgm_reg_plane = (IORegistryPlane *) gIOServicePlane
0c530ab8
A
371set $kgm_namekey = (OSSymbol *) 0
372set $kgm_childkey = (OSSymbol *) 0
373
374set $kgm_show_object_addrs = 0
375set $kgm_show_object_retain = 0
376set $kgm_show_props = 0
b0d623f7 377set $kgm_show_data_alwaysbytes = 0
1c79356b 378
2d21ac55
A
379set $kgm_show_kmod_syms = 0
380
7e4a7d39
A
381# send a manual packet header that doesn't require knowing the location
382# of everything.
383define manualhdrint
384 set $req = $arg0
385
386 set $hdrp = (uint32_t *) $kgm_manual_pkt_i386
387 if ($kgm_mtype == $kgm_mtype_ppc)
388 set $hdrp = (uint32_t *) $kgm_manual_pkt_ppc
389 set $req = $req << 1 # shift to deal with endiannness
390 end
391 if ($kgm_mtype == $kgm_mtype_x86_64)
392 set $hdrp = (uint64_t *) $kgm_manual_pkt_x86_64
393 end
394 if ($kgm_mtype == $kgm_mtype_arm)
395 set $hdrp = (uint32_t *) $kgm_manual_pkt_arm
396 end
397
398 set $pkt_hdr = *$hdrp
399 set *((uint8_t *) ($pkt_hdr + $kgm_kdp_pkt_input_off)) = 0
400 set *((uint32_t *) ($pkt_hdr + $kgm_kdp_pkt_len_off)) = $kgm_kdp_pkt_hdr_size
401
402 set *((uint8_t *) ($pkt_hdr + $kgm_kdp_pkt_hdr_req_off)) = $req
403 set *((uint8_t *) ($pkt_hdr + $kgm_kdp_pkt_hdr_seq_off)) = 0
404 set *((uint16_t *) ($pkt_hdr + $kgm_kdp_pkt_hdr_len_off)) = $kgm_kdp_pkt_hdr_size
405 set *((uint32_t *) ($pkt_hdr + $kgm_kdp_pkt_hdr_key_off)) = 0
406 set *((uint8_t *) ($pkt_hdr + $kgm_kdp_pkt_input_off)) = 1
407
408 # dummy to make sure manual packet is executed
409 set $kgm_dummy = &_mh_execute_header
410end
411
b0d623f7
A
412# Print a pointer
413define showptr
414 if $kgm_lp64
415 printf "0x%016llx", $arg0
416 else
417 printf "0x%08x", $arg0
418 end
419end
420
421# for headers, leave 8 chars for LP64 pointers
422define showptrhdrpad
423 if $kgm_lp64
424 printf " "
425 end
426end
427
6d2010ae
A
428# Print a userspace pointer, using $kgm_tasp
429define showuserptr
430 set $kgm_userptr_task_64 = ( $kgm_taskp->taskFeatures[0] & 0x80000000)
431 if $kgm_userptr_task_64
432 printf "0x%016llx", $arg0
433 else
434 printf "0x%08x", $arg0
435 end
436end
437
1c79356b 438define showkmodheader
6d2010ae 439 printf "kmod_info "
b0d623f7
A
440 showptrhdrpad
441 printf " address "
442 showptrhdrpad
443 printf " size "
444 showptrhdrpad
445 printf " id refs version name\n"
1c79356b
A
446end
447
448define showkmodint
449 set $kgm_kmodp = (struct kmod_info *)$arg0
b0d623f7
A
450 showptr $kgm_kmodp
451 printf " "
452 showptr $kgm_kmodp->address
453 printf " "
454 showptr $kgm_kmodp->size
455 printf " "
1c79356b
A
456 printf "%3d ", $kgm_kmodp->id
457 printf "%5d ", $kgm_kmodp->reference_count
b0d623f7
A
458 printf "%10s ", $kgm_kmodp->version
459 printf "%s\n", $kgm_kmodp->name
1c79356b
A
460end
461
b0d623f7 462# cached info of the last kext found, to speed up subsequent lookups
1c79356b
A
463set $kgm_pkmod = 0
464set $kgm_pkmodst = 0
465set $kgm_pkmoden = 0
b0d623f7 466
0c530ab8 467define showkmodaddrint
b0d623f7
A
468 showptr $arg0
469 if ((unsigned long)$arg0 >= (unsigned long)$kgm_pkmodst) && ((unsigned long)$arg0 < (unsigned long)$kgm_pkmoden)
470 set $kgm_off = ((unsigned long)$arg0 - (unsigned long)$kgm_pkmodst)
1c79356b
A
471 printf " <%s + 0x%x>", $kgm_pkmod->name, $kgm_off
472 else
b0d623f7
A
473 set $kgm_kmodp = (struct kmod_info *)kmod
474 if ($kgm_mtype == $kgm_mtype_x86_64) && ($arg0 >= (unsigned long)&_mh_execute_header)
475 # kexts are loaded below the kernel for x86_64
476 set $kgm_kmodp = 0
477 end
478 while $kgm_kmodp
479 set $kgm_off = ((unsigned long)$arg0 - (unsigned long)$kgm_kmodp->address)
480 if ($kgm_kmodp->address <= $arg0) && ($kgm_off < $kgm_kmodp->size)
481 printf " <%s + 0x%x>", $kgm_kmodp->name, $kgm_off
482 set $kgm_pkmod = $kgm_kmodp
483 set $kgm_pkmodst = $kgm_kmodp->address
484 set $kgm_pkmoden = $kgm_pkmodst + $kgm_kmodp->size
485 set $kgm_kmodp = 0
486 else
487 set $kgm_kmodp = $kgm_kmodp->next
1c79356b
A
488 end
489 end
490 end
491end
0c530ab8
A
492
493define showkmodaddr
494 showkmodaddrint $arg0
0c530ab8 495end
1c79356b 496document showkmodaddr
2d21ac55 497Syntax: (gdb) showkmodaddr <addr>
1c79356b 498| Given an address, print the offset and name for the kmod containing it
1c79356b
A
499end
500
501define showkmod
502 showkmodheader
503 showkmodint $arg0
504end
505document showkmod
2d21ac55 506Syntax: (gdb) showkmod <kmod>
6d2010ae
A
507| Routine to print info about a kext
508end
509
510define showkext
511 showkmod $arg0
512end
513document showkext
514Syntax: (gdb) showkext <kmod_info_address>
515| Routine to print info about a kext
1c79356b
A
516end
517
518define showallkmods
519 showkmodheader
520 set $kgm_kmodp = (struct kmod_info *)kmod
521 while $kgm_kmodp
522 showkmodint $kgm_kmodp
523 set $kgm_kmodp = $kgm_kmodp->next
524 end
525end
526document showallkmods
2d21ac55 527Syntax: (gdb) showallkmods
6d2010ae
A
528| Routine to print a summary listing of all loaded kexts
529end
530
531define showallkexts
532 showallkmods
533end
534document showallkexts
535Syntax: (gdb) showallkexts
536| Routine to print a summary listing of all loaded kexts
537end
538
539# See OSKextVersion.c for the C code this is based on
540#
541set $KGM_OSKEXT_VERS_MAJ_MULT = 100000000
542set $KGM_OSKEXT_VERS_MIN_MULT = 1000000
543set $KGM_OSKEXT_VERS_REV_MULT = 10000
544set $KGM_OSKEXT_VERS_STAGE_MULT = 1000
545
546define printoskextversion
547 set $vers_scratch = $arg0
548
549 if ($vers_scratch == -1)
550 printf "(invalid)"
551 else
552
553 set $vers_major = $vers_scratch / $KGM_OSKEXT_VERS_MAJ_MULT
554
555 set $vers_scratch = $vers_scratch - ($vers_major * $KGM_OSKEXT_VERS_MAJ_MULT)
556 set $vers_minor = $vers_scratch / $KGM_OSKEXT_VERS_MIN_MULT
557
558 set $vers_scratch = $vers_scratch - ( $vers_minor * $KGM_OSKEXT_VERS_MIN_MULT)
559 set $vers_revision = $vers_scratch / $KGM_OSKEXT_VERS_REV_MULT
560
561 set $vers_scratch = $vers_scratch - ( $vers_revision * $KGM_OSKEXT_VERS_REV_MULT)
562 set $vers_stage = $vers_scratch / $KGM_OSKEXT_VERS_STAGE_MULT
563
564 set $vers_scratch = $vers_scratch - ( $vers_stage * $KGM_OSKEXT_VERS_STAGE_MULT)
565 set $vers_stagelevel = $vers_scratch
566
567 printf "%d.%d", $vers_major, $vers_minor
568 if ($vers_revision > 0)
569 printf ".%d", $vers_revision
570 end
571
572 if ($vers_stage == 1)
573 printf "d"
574 end
575 if ($vers_stage == 3)
576 printf "a"
577 end
578 if ($vers_stage == 5)
579 printf "b"
580 end
581 if ($vers_stage == 7)
582 printf "fc"
583 end
584 if ($vers_stage == 1 || $vers_stage == 3 || $vers_stage == 5 || $vers_stage == 7)
585 printf "%d", $vers_stagelevel
586 end
587 end
588end
589
590define showallknownkexts
591 set $kext_count = sKextsByID->count
592 set $kext_index = 0
593 printf "%d kexts in sKextsByID:\n", $kext_count
594
595 printf "OSKext * "
596 showptrhdrpad
597 printf "load_addr "
598 showptrhdrpad
599
600 printf " id name (version)\n"
601
602 while $kext_index < $kext_count
603 set $kext_id = sKextsByID->dictionary[$kext_index].key->string
604 set $oskext = (OSKext *)sKextsByID->dictionary[$kext_index].value
605
606 showptr $oskext
607 printf " "
608
609 if ($oskext->flags.loaded)
610 showptr $oskext->kmod_info
611 printf " "
612 printf "%3d", $oskext->loadTag
613 else
614 showptrhdrpad
615 printf " -------- "
616 printf " "
617 printf " --"
618 end
619 printf " "
620
621 printf "%.64s (", $kext_id
622 printoskextversion (uint64_t)$oskext->version
623 printf ")\n"
624 set $kext_index = $kext_index + 1
625 end
626end
627document showallknownkexts
628Syntax: (gdb) showallknownkexts
629| Routine to print a summary listing of all kexts, loaded or not
1c79356b
A
630end
631
632define showactheader
b0d623f7
A
633 printf " "
634 showptrhdrpad
635 printf " thread "
636 showptrhdrpad
637 printf " thread_id "
638 showptrhdrpad
639 printf " processor "
640 showptrhdrpad
641 printf " pri io_policy state wait_queue"
642 showptrhdrpad
643 printf " wait_event\n"
1c79356b
A
644end
645
646
647define showactint
b0d623f7
A
648 printf " "
649 showptrhdrpad
91447636 650 set $kgm_thread = *(struct thread *)$arg0
b0d623f7
A
651 showptr $arg0
652 if ($kgm_thread.static_param)
653 printf "[WQ]"
654 else
655 printf " "
656 end
6d2010ae 657 printf " 0x%llx ", $kgm_thread.thread_id
b0d623f7
A
658 showptr $kgm_thread.last_processor
659 printf " %3d ", $kgm_thread.sched_pri
660 if ($kgm_thread.uthread != 0)
661 set $kgm_printed = 0
662 set $kgm_uthread = (struct uthread *)$kgm_thread.uthread
663 if ($kgm_uthread->uu_flag & 0x400)
664 printf "RAGE "
665 else
666 printf " "
667 end
6d2010ae
A
668 set $diskpolicy = 0
669 if ($kgm_thread->ext_actionstate.hw_disk != 0)
670 set $diskpolicy = $kgm_thread->ext_actionstate.hw_disk
671 else
672 if ($kgm_thread->actionstate.hw_disk != 0)
673 set $diskpolicy = $kgm_thread->actionstate.hw_disk
674 end
675 end
676 if ($kgm_thread->ext_actionstate.hw_bg != 0)
677 set $diskpolicy = 5
b0d623f7 678 end
6d2010ae
A
679 if ($kgm_thread->actionstate.hw_bg != 0)
680 set $diskpolicy = 4
681 end
682 if ($diskpolicy == 2)
b0d623f7
A
683 printf "PASS "
684 set $kgm_printed = 1
685 end
6d2010ae 686 if ($diskpolicy == 3)
b0d623f7
A
687 printf "THROT "
688 set $kgm_printed = 1
689 end
6d2010ae
A
690 if ($diskpolicy == 4)
691 printf "BG_THRT "
692 set $kgm_printed = 1
693 end
694 if ($diskpolicy == 5)
695 printf "EBG_THRT"
696 set $kgm_printed = 1
697 end
b0d623f7
A
698 if ($kgm_printed == 0)
699 printf " "
700 end
701 end
1c79356b
A
702 set $kgm_state = $kgm_thread.state
703 if $kgm_state & 0x80
704 printf "I"
705 end
706 if $kgm_state & 0x40
707 printf "P"
708 end
709 if $kgm_state & 0x20
710 printf "A"
711 end
712 if $kgm_state & 0x10
713 printf "H"
714 end
715 if $kgm_state & 0x08
716 printf "U"
717 end
718 if $kgm_state & 0x04
719 printf "R"
720 end
721 if $kgm_state & 0x02
722 printf "S"
723 end
724 if $kgm_state & 0x01
b0d623f7
A
725 printf "W"
726 printf "\t "
727 showptr $kgm_thread.wait_queue
728 printf " "
729 if (((unsigned long)$kgm_thread.wait_event > (unsigned long)&last_kernel_symbol) \
2d21ac55 730 && ($arg1 != 2) && ($kgm_show_kmod_syms == 0))
0c530ab8
A
731 showkmodaddr $kgm_thread.wait_event
732 else
b0d623f7 733 output /a $kgm_thread.wait_event
91447636 734 end
2d21ac55
A
735 if ($kgm_thread.uthread != 0)
736 set $kgm_uthread = (struct uthread *)$kgm_thread.uthread
737 if ($kgm_uthread->uu_wmesg != 0)
b0d623f7 738 printf "\t \"%s\"", $kgm_uthread->uu_wmesg
2d21ac55
A
739 end
740 end
1c79356b 741 end
6d2010ae
A
742 if ($kgm_thread.uthread != 0)
743 set $kgm_uthread = (struct uthread *)$kgm_thread.uthread
744 if ($kgm_uthread->pth_name && $kgm_uthread->pth_name[0])
745 printf "\n\t\tThread Name: %s", $kgm_uthread->pth_name
746 end
747 end
1c79356b
A
748 if $arg1 != 0
749 if ($kgm_thread.kernel_stack != 0)
6d2010ae
A
750 if ($kgm_thread.uthread != 0)
751 printf "\n "
752 set $kgm_uthread = (struct uthread *)$kgm_thread.uthread
753 if ($kgm_uthread->uu_kwe.kwe_kwqqueue != 0)
754 set $kwq = (ksyn_wait_queue_t)$kgm_uthread->uu_kwe.kwe_kwqqueue
755 printf " kwq_lockcount:0x%x; kwq_retval:0x%x", $kgm_uthread->uu_kwe.kwe_lockseq, $kgm_uthread->uu_kwe.kwe_psynchretval
756 printf "\n "
757 show_kwq $kwq
758 printf " "
759 end
760 end
55e303ae 761 if ($kgm_thread.reserved_stack != 0)
b0d623f7
A
762 printf "\n "
763 showptrhdrpad
764 printf " reserved_stack="
765 showptr $kgm_thread.reserved_stack
1c79356b 766 end
b0d623f7
A
767 printf "\n "
768 showptrhdrpad
769 printf " kernel_stack="
770 showptr $kgm_thread.kernel_stack
771 if ($kgm_mtype == $kgm_mtype_ppc)
91447636 772 set $mysp = $kgm_thread.machine.pcb->save_r1
2d21ac55 773 end
b0d623f7
A
774 if (($kgm_mtype & $kgm_mtype_x86_mask) == $kgm_mtype_x86_any)
775 set $kgm_statep = (struct x86_kernel_state *) \
776 ($kgm_thread->kernel_stack + kernel_stack_size \
777 - sizeof(struct x86_kernel_state))
778 if ($kgm_mtype == $kgm_mtype_i386)
779 set $mysp = $kgm_statep->k_ebp
780 else
781 set $mysp = $kgm_statep->k_rbp
782 end
55e303ae 783 end
b0d623f7
A
784 if ($kgm_mtype == $kgm_mtype_arm)
785 if (((unsigned long)$r7 < ((unsigned long) ($kgm_thread->kernel_stack+kernel_stack_size))) \
786 && ((unsigned long)$r7 > (unsigned long) ($kgm_thread->kernel_stack)))
2d21ac55
A
787 set $mysp = $r7
788 else
789 set $kgm_statep = (struct arm_saved_state *)$kgm_thread.machine.kstackptr
790 set $mysp = $kgm_statep->r[7]
791 end
792 end
0c530ab8 793 set $prevsp = $mysp - 16
b0d623f7
A
794 printf "\n "
795 showptrhdrpad
796 printf " stacktop="
797 showptr $mysp
798 if ($kgm_mtype == $kgm_mtype_ppc)
91447636 799 set $stkmask = 0xf
91447636
A
800 else
801 set $stkmask = 0x3
91447636 802 end
0c530ab8 803 set $kgm_return = 0
060df5ea 804 set $kgm_actint_framecount = 0
91447636 805 while ($mysp != 0) && (($mysp & $stkmask) == 0) \
0c530ab8 806 && ($mysp != $prevsp) \
b0d623f7
A
807 && ((((unsigned long) $mysp ^ (unsigned long) $prevsp) < 0x2000) \
808 || (((unsigned long)$mysp < ((unsigned long) ($kgm_thread->kernel_stack+kernel_stack_size))) \
060df5ea
A
809 && ((unsigned long)$mysp > (unsigned long) ($kgm_thread->kernel_stack)))) \
810 && ($kgm_actint_framecount < 128)
b0d623f7 811 printf "\n "
060df5ea 812 set $kgm_actint_framecount = $kgm_actint_framecount + 1
b0d623f7
A
813 showptrhdrpad
814 printf " "
815 showptr $mysp
816 printf " "
817 if ($kgm_mtype == $kgm_mtype_ppc)
91447636 818 set $kgm_return = *($mysp + 8)
2d21ac55 819 end
b0d623f7 820 if ($kgm_mtype == $kgm_mtype_i386)
2d21ac55
A
821 set $kgm_return = *($mysp + 4)
822 end
b0d623f7
A
823 if ($kgm_mtype == $kgm_mtype_x86_64)
824 set $kgm_return = *(unsigned long *)($mysp + 8)
825 end
826 if ($kgm_mtype == $kgm_mtype_arm)
91447636
A
827 set $kgm_return = *($mysp + 4)
828 end
b0d623f7
A
829 if (((unsigned long) $kgm_return < (unsigned long) &_mh_execute_header || \
830 (unsigned long) $kgm_return >= (unsigned long) &last_kernel_symbol ) \
2d21ac55
A
831 && ($kgm_show_kmod_syms == 0))
832 showkmodaddr $kgm_return
833 else
b0d623f7 834 output /a $kgm_return
2d21ac55 835 end
91447636 836 set $prevsp = $mysp
b0d623f7 837 set $mysp = *(unsigned long *)$mysp
1c79356b 838 end
0c530ab8 839 set $kgm_return = 0
b0d623f7
A
840 printf "\n "
841 showptrhdrpad
842 printf " stackbottom="
843 showptr $prevsp
1c79356b 844 else
b0d623f7
A
845 printf "\n "
846 showptrhdrpad
847 printf " continuation="
848 output /a $kgm_thread.continuation
1c79356b
A
849 end
850 printf "\n"
851 else
852 printf "\n"
853 end
1c79356b
A
854end
855
856define showact
857 showactheader
858 showactint $arg0 0
859end
860document showact
2d21ac55 861Syntax: (gdb) showact <activation>
55e303ae 862| Routine to print out the state of a specific thread.
1c79356b
A
863end
864
865
866define showactstack
867 showactheader
868 showactint $arg0 1
869end
870document showactstack
2d21ac55 871Syntax: (gdb) showactstack <activation>
55e303ae 872| Routine to print out the stack of a specific thread.
1c79356b
A
873end
874
875
55e303ae 876define showallthreads
2d21ac55 877 set $kgm_head_taskp = &tasks
9bccf70c 878 set $kgm_taskp = (struct task *)($kgm_head_taskp->next)
1c79356b
A
879 while $kgm_taskp != $kgm_head_taskp
880 showtaskheader
881 showtaskint $kgm_taskp
882 showactheader
55e303ae
A
883 set $kgm_head_actp = &($kgm_taskp->threads)
884 set $kgm_actp = (struct thread *)($kgm_taskp->threads.next)
1c79356b
A
885 while $kgm_actp != $kgm_head_actp
886 showactint $kgm_actp 0
55e303ae 887 set $kgm_actp = (struct thread *)($kgm_actp->task_threads.next)
1c79356b
A
888 end
889 printf "\n"
2d21ac55 890 set $kgm_taskp = (struct task *)($kgm_taskp->tasks.next)
1c79356b
A
891 end
892end
55e303ae 893document showallthreads
2d21ac55 894Syntax: (gdb) showallthreads
55e303ae 895| Routine to print out info about all threads in the system.
55e303ae
A
896end
897
6d2010ae
A
898define showprocessorint
899 set $kgm_processor_int = (struct processor *)$arg0
900 printf "Processor "
901 showptr $kgm_processor_int
902 printf " State %d (cpu_id 0x%x)\n", ($kgm_processor_int)->state, ($kgm_processor_int)->cpu_id
903end
904
55e303ae 905define showcurrentthreads
6d2010ae 906 set $kgm_prp = (struct processor *)processor_list
91447636 907 while $kgm_prp != 0
6d2010ae 908 showprocessorint $kgm_prp
91447636
A
909 if ($kgm_prp)->active_thread != 0
910 set $kgm_actp = ($kgm_prp)->active_thread
55e303ae
A
911 showtaskheader
912 showtaskint ($kgm_actp)->task
913 showactheader
914 showactint $kgm_actp 0
915 printf "\n"
916 end
91447636 917 set $kgm_prp = ($kgm_prp)->processor_list
55e303ae
A
918 end
919end
920document showcurrentthreads
2d21ac55 921Syntax: (gdb) showcurrentthreads
55e303ae 922| Routine to print out info about the thread running on each cpu.
1c79356b
A
923end
924
6d2010ae
A
925
926define _showrunqint
927 set $kgm_runq = (struct run_queue *)$arg0
928
929 printf " Priority Run Queue Info: Count %d\n", $kgm_runq->count
930 set $kgm_runq_queue_i = 0
931 set $kgm_runq_queue_count = sizeof($kgm_runq->queues)/sizeof($kgm_runq->queues[0])
932 while $kgm_runq->count && $kgm_runq_queue_i < $kgm_runq_queue_count
933 set $kgm_runq_queue_head = &$kgm_runq->queues[$kgm_runq_queue_i]
934 set $kgm_runq_queue_p = $kgm_runq_queue_head->next
935 if $kgm_runq_queue_p != $kgm_runq_queue_head
936 set $kgm_runq_queue_this_count = 0
937 while $kgm_runq_queue_p != $kgm_runq_queue_head
938 set $kgm_runq_queue_this_count = $kgm_runq_queue_this_count + 1
939 showtask ((thread_t)$kgm_runq_queue_p)->task
940 showactstack $kgm_runq_queue_p
941 set $kgm_runq_queue_p = $kgm_runq_queue_p->next
942 end
943 printf " Queue Priority %3d [", $kgm_runq_queue_i
944 showptr $kgm_runq_queue_head
945 printf "] Count %d\n", $kgm_runq_queue_this_count
946 end
947 set $kgm_runq_queue_i = $kgm_runq_queue_i + 1
948 end
949
950end
951
952define _showgrrrint
953 set $kgm_grrr_runq = $arg0
954
955 printf " GRRR Info: Count %d Weight %d Current Group ", $kgm_grrr_runq->count, $kgm_grrr_runq->weight
956 showptr $kgm_grrr_runq->current_group
957 printf "\n"
958 set $kgm_grrr_group_i = 0
959 set $kgm_grrr_group_count = sizeof($kgm_grrr_runq->groups)/sizeof($kgm_grrr_runq->groups[0])
960 while $kgm_grrr_runq->count && $kgm_grrr_group_i < $kgm_grrr_group_count
961 set $kgm_grrr_group = &$kgm_grrr_runq->groups[$kgm_grrr_group_i]
962 if $kgm_grrr_group->count > 0
963 printf " Group %3d [", $kgm_grrr_group->index
964 showptr $kgm_grrr_group
965 printf "] Count %d Weight %d\n", $kgm_grrr_group->count, $kgm_grrr_group->weight
966 set $kgm_grrr_group_client_head = &$kgm_grrr_group->clients
967 set $kgm_grrr_group_client = $kgm_grrr_group_client_head->next
968 while $kgm_grrr_group_client != $kgm_grrr_group_client_head
969 # showtask ((thread_t)$kgm_grrr_group_client)->task
970 # showactstack $kgm_grrr_group_client
971 set $kgm_grrr_group_client = $kgm_grrr_group_client->next
972 end
973 end
974 set $kgm_grrr_group_i = $kgm_grrr_group_i + 1
975 end
976end
977
978define showallprocessors
979 set $kgm_pset = &pset0
980
981 set $kgm_show_grrr = 0
982 set $kgm_show_priority_runq = 0
983 set $kgm_show_priority_pset_runq = 0
984 set $kgm_show_fairshare_grrr = 0
985 set $kgm_show_fairshare_list = 0
986
987 if _sched_enum == 1
988 set $kgm_show_priority_runq = 1
989 set $kgm_show_fairshare_list = 1
990 end
991 if _sched_enum == 2
992 set $kgm_show_priority_pset_runq = 1
993 set $kgm_show_fairshare_list = 1
994 end
995 if _sched_enum == 4
996 set $kgm_show_grrr = 1
997 set $kgm_show_fairshare_grrr = 1
998 end
999 if _sched_enum == 5
1000 set $kgm_show_priority_runq = 1
1001 set $kgm_show_fairshare_list = 1
1002 end
1003 if _sched_enum == 6
1004 set $kgm_show_priority_pset_runq = 1
1005 set $kgm_show_fairshare_list = 1
1006 end
1007
1008 while $kgm_pset != 0
1009 printf "Processor Set "
1010 showptr $kgm_pset
1011 printf " Count %d (cpu_id 0x%x-0x%x)\n", ($kgm_pset)->cpu_set_count, ($kgm_pset)->cpu_set_low, ($kgm_pset)->cpu_set_hi
1012 printf " Active Processors:\n"
1013 set $kgm_active_queue_head = &($kgm_pset)->active_queue
1014 set $kgm_active_elt = $kgm_active_queue_head->next
1015 while $kgm_active_elt != $kgm_active_queue_head
1016 set $kgm_processor = (processor_t)$kgm_active_elt
1017 printf " "
1018 showprocessorint $kgm_processor
1019
1020 if $kgm_show_priority_runq
1021 set $kgm_runq = &$kgm_processor->runq
1022 _showrunqint $kgm_runq
1023 end
1024 if $kgm_show_grrr
1025 set $kgm_grrr_runq = &$kgm_processor->grrr_runq
1026 _showgrrrint $kgm_grrr_runq
1027 end
1028
1029 if $kgm_processor->processor_meta != 0 && $kgm_processor->processor_meta->primary == $kgm_processor
1030 set $kgm_processor_meta_idle_head = &$kgm_processor->processor_meta->idle_queue
1031 set $kgm_processor_meta_idle = $kgm_processor_meta_idle_head->next
1032 while $kgm_processor_meta_idle != $kgm_processor_meta_idle_head
1033 printf " Idle Meta Processor: "
1034 showprocessorint $kgm_processor_meta_idle
1035 set $kgm_processor_meta_idle = $kgm_processor_meta_idle->next
1036 end
1037 end
1038
1039 set $kgm_active_elt = $kgm_active_elt->next
1040 end
1041 printf " Idle Processors:\n"
1042 set $kgm_idle_queue_head = &($kgm_pset)->idle_queue
1043 set $kgm_idle_elt = $kgm_idle_queue_head->next
1044 while $kgm_idle_elt != $kgm_idle_queue_head
1045 set $kgm_processor = (processor_t)$kgm_idle_elt
1046 printf " "
1047 showprocessorint $kgm_processor
1048
1049 if $kgm_processor->processor_meta != 0 && $kgm_processor->processor_meta->primary == $kgm_processor
1050 set $kgm_processor_meta_idle_head = &$kgm_processor->processor_meta->idle_queue
1051 set $kgm_processor_meta_idle = $kgm_processor_meta_idle_head->next
1052 while $kgm_processor_meta_idle != $kgm_processor_meta_idle_head
1053 printf " Idle Meta Processor: "
1054 showprocessorint $kgm_processor_meta_idle
1055 set $kgm_processor_meta_idle = $kgm_processor_meta_idle->next
1056 end
1057 end
1058
1059 set $kgm_idle_elt = $kgm_idle_elt->next
1060 end
1061
1062 if $kgm_show_priority_pset_runq
1063 set $kgm_runq = &$kgm_pset->pset_runq
1064 printf "\n"
1065 _showrunqint $kgm_runq
1066 end
1067 set $kgm_pset = ($kgm_pset)->pset_list
1068 end
1069
1070 printf "\n"
1071 printf "Realtime Queue Count %d\n", rt_runq.count
1072 set $kgm_rt_runq_head = &rt_runq.queue
1073 set $kgm_rt_runq = $kgm_rt_runq_head->next
1074 while $kgm_rt_runq != $kgm_rt_runq_head
1075 showtask ((thread_t)$kgm_rt_runq)->task
1076 showact $kgm_rt_runq
1077 set $kgm_rt_runq = $kgm_rt_runq->next
1078 end
1079
1080 printf "\n"
1081 if $kgm_show_fairshare_list
1082 printf "Fair Share Queue Count %d\n", fs_runq.count
1083 set $kgm_fs_runq_head = &fs_runq.queue
1084 set $kgm_fs_runq = $kgm_fs_runq_head->next
1085 while $kgm_fs_runq != $kgm_fs_runq_head
1086 showtask ((thread_t)$kgm_fs_runq)->task
1087 showact $kgm_fs_runq
1088 set $kgm_fs_runq = $kgm_fs_runq->next
1089 end
1090 end
1091 if $kgm_show_fairshare_grrr
1092 printf "Fair Share Queue Count %d\n", fs_grrr_runq.count
1093 set $kgm_fs_grrr = &fs_grrr_runq
1094 _showgrrrint $kgm_fs_grrr
1095 end
1096end
1097document showallprocessors
1098Syntax: (gdb) showallprocessors
1099| Routine to print out info about all psets and processors
1100end
1101
0c530ab8 1102set $decode_wait_events = 0
1c79356b 1103define showallstacks
2d21ac55 1104 set $kgm_head_taskp = &tasks
9bccf70c 1105 set $kgm_taskp = (struct task *)($kgm_head_taskp->next)
1c79356b 1106 while $kgm_taskp != $kgm_head_taskp
6d2010ae 1107 showtaskheader
1c79356b 1108 showtaskint $kgm_taskp
55e303ae 1109 set $kgm_head_actp = &($kgm_taskp->threads)
6d2010ae 1110 set $kgm_actp = (struct thread *)($kgm_taskp->threads.next)
1c79356b
A
1111 while $kgm_actp != $kgm_head_actp
1112 showactheader
0c530ab8
A
1113 if ($decode_wait_events > 0)
1114 showactint $kgm_actp 1
1115 else
1116 showactint $kgm_actp 2
1117 end
6d2010ae
A
1118 set $kgm_actp = (struct thread *)($kgm_actp->task_threads.next)
1119 end
1c79356b 1120 printf "\n"
6d2010ae 1121 set $kgm_taskp = (struct task *)($kgm_taskp->tasks.next)
1c79356b 1122 end
6d2010ae
A
1123
1124 printf "\nZombie Processes:\n"
1125 zombstacks
1c79356b 1126end
0c530ab8 1127
1c79356b 1128document showallstacks
2d21ac55 1129Syntax: (gdb) showallstacks
55e303ae 1130| Routine to print out the stack for each thread in the system.
0c530ab8
A
1131| If the variable $decode_wait_events is non-zero, the routine attempts to
1132| interpret thread wait_events as kernel module offsets, which can add to
1133| processing time.
1c79356b
A
1134end
1135
55e303ae 1136define showcurrentstacks
6d2010ae 1137 set $kgm_prp = processor_list
91447636 1138 while $kgm_prp != 0
6d2010ae 1139 showprocessorint $kgm_prp
91447636
A
1140 if ($kgm_prp)->active_thread != 0
1141 set $kgm_actp = ($kgm_prp)->active_thread
55e303ae
A
1142 showtaskheader
1143 showtaskint ($kgm_actp)->task
1144 showactheader
1145 showactint $kgm_actp 1
1146 printf "\n"
1147 end
91447636 1148 set $kgm_prp = ($kgm_prp)->processor_list
55e303ae
A
1149 end
1150end
0c530ab8 1151
55e303ae 1152document showcurrentstacks
2d21ac55 1153Syntax: (gdb) showcurrentstacks
55e303ae 1154| Routine to print out the thread running on each cpu (incl. its stack)
55e303ae
A
1155end
1156
9bccf70c 1157define showwaiterheader
b0d623f7
A
1158 printf "waiters thread "
1159 printf "processor pri state wait_queue wait_event\n"
9bccf70c
A
1160end
1161
1162define showwaitqwaiters
b0d623f7 1163 set $kgm_w_waitqp = (WaitQueue*)$arg0
9bccf70c 1164 set $kgm_w_linksp = &($kgm_w_waitqp->wq_queue)
b0d623f7 1165 set $kgm_w_wqe = (WaitQueueElement *)$kgm_w_linksp->next
9bccf70c
A
1166 set $kgm_w_found = 0
1167 while ( (queue_entry_t)$kgm_w_wqe != (queue_entry_t)$kgm_w_linksp)
1168 if ($kgm_w_wqe->wqe_type != &_wait_queue_link)
1169 if !$kgm_w_found
1170 set $kgm_w_found = 1
1171 showwaiterheader
1172 end
55e303ae 1173 set $kgm_w_shuttle = (struct thread *)$kgm_w_wqe
91447636 1174 showactint $kgm_w_shuttle 0
9bccf70c 1175 end
b0d623f7 1176 set $kgm_w_wqe = (WaitQueueElement *)$kgm_w_wqe->wqe_links.next
9bccf70c
A
1177 end
1178end
1179
1180define showwaitqwaitercount
b0d623f7 1181 set $kgm_wc_waitqp = (WaitQueue*)$arg0
9bccf70c 1182 set $kgm_wc_linksp = &($kgm_wc_waitqp->wq_queue)
b0d623f7 1183 set $kgm_wc_wqe = (WaitQueueElement *)$kgm_wc_linksp->next
9bccf70c
A
1184 set $kgm_wc_count = 0
1185 while ( (queue_entry_t)$kgm_wc_wqe != (queue_entry_t)$kgm_wc_linksp)
6d2010ae 1186 if ($kgm_wc_wqe->wqe_type != &_wait_queue_link)
9bccf70c
A
1187 set $kgm_wc_count = $kgm_wc_count + 1
1188 end
b0d623f7 1189 set $kgm_wc_wqe = (WaitQueueElement *)$kgm_wc_wqe->wqe_links.next
9bccf70c
A
1190 end
1191 printf "0x%08x ", $kgm_wc_count
1192end
1193
1c79356b 1194define showwaitqmembercount
6d2010ae 1195 set $kgm_mc_waitqsetp = (WaitQueueSet*)$arg0
9bccf70c 1196 set $kgm_mc_setlinksp = &($kgm_mc_waitqsetp->wqs_setlinks)
b0d623f7 1197 set $kgm_mc_wql = (WaitQueueLink *)$kgm_mc_setlinksp->next
9bccf70c
A
1198 set $kgm_mc_count = 0
1199 while ( (queue_entry_t)$kgm_mc_wql != (queue_entry_t)$kgm_mc_setlinksp)
1200 set $kgm_mc_count = $kgm_mc_count + 1
b0d623f7 1201 set $kgm_mc_wql = (WaitQueueLink *)$kgm_mc_wql->wql_setlinks.next
1c79356b 1202 end
9bccf70c 1203 printf "0x%08x ", $kgm_mc_count
1c79356b
A
1204end
1205
1206
9bccf70c
A
1207define showwaitqmemberheader
1208 printf "set-members wait_queue interlock "
1209 printf "pol type member_cnt waiter_cnt\n"
1210end
1211
1c79356b 1212define showwaitqmemberint
b0d623f7 1213 set $kgm_m_waitqp = (WaitQueue*)$arg0
9bccf70c
A
1214 printf " 0x%08x ", $kgm_m_waitqp
1215 printf "0x%08x ", $kgm_m_waitqp->wq_interlock.lock_data
1216 if ($kgm_m_waitqp->wq_fifo)
1217 printf "Fifo "
1c79356b 1218 else
9bccf70c 1219 printf "Prio "
1c79356b 1220 end
9bccf70c
A
1221 if ($kgm_m_waitqp->wq_type == 0xf1d1)
1222 printf "Set "
1223 showwaitqmembercount $kgm_m_waitqp
1c79356b 1224 else
9bccf70c 1225 printf "Que 0x00000000 "
1c79356b 1226 end
9bccf70c 1227 showwaitqwaitercount $kgm_m_waitqp
1c79356b
A
1228 printf "\n"
1229end
1230
1231
9bccf70c
A
1232define showwaitqmemberofheader
1233 printf "member-of wait_queue interlock "
1234 printf "pol type member_cnt waiter_cnt\n"
1235end
1236
1237define showwaitqmemberof
b0d623f7 1238 set $kgm_mo_waitqp = (WaitQueue*)$arg0
9bccf70c 1239 set $kgm_mo_linksp = &($kgm_mo_waitqp->wq_queue)
b0d623f7 1240 set $kgm_mo_wqe = (WaitQueueElement *)$kgm_mo_linksp->next
9bccf70c
A
1241 set $kgm_mo_found = 0
1242 while ( (queue_entry_t)$kgm_mo_wqe != (queue_entry_t)$kgm_mo_linksp)
1243 if ($kgm_mo_wqe->wqe_type == &_wait_queue_link)
1244 if !$kgm_mo_found
1245 set $kgm_mo_found = 1
1246 showwaitqmemberofheader
1247 end
b0d623f7
A
1248 set $kgm_mo_wqlp = (WaitQueueLink *)$kgm_mo_wqe
1249 set $kgm_mo_wqsetp = (WaitQueue*)($kgm_mo_wqlp->wql_setqueue)
9bccf70c
A
1250 showwaitqmemberint $kgm_mo_wqsetp
1251 end
b0d623f7 1252 set $kgm_mo_wqe = (WaitQueueElement *)$kgm_mo_wqe->wqe_links.next
9bccf70c
A
1253 end
1254end
1255
1c79356b 1256define showwaitqmembers
6d2010ae 1257 set $kgm_ms_waitqsetp = (WaitQueueSet*)$arg0
9bccf70c 1258 set $kgm_ms_setlinksp = &($kgm_ms_waitqsetp->wqs_setlinks)
b0d623f7 1259 set $kgm_ms_wql = (WaitQueueLink *)$kgm_ms_setlinksp->next
9bccf70c
A
1260 set $kgm_ms_found = 0
1261 while ( (queue_entry_t)$kgm_ms_wql != (queue_entry_t)$kgm_ms_setlinksp)
1262 set $kgm_ms_waitqp = $kgm_ms_wql->wql_element.wqe_queue
1263 if !$kgm_ms_found
1c79356b 1264 showwaitqmemberheader
9bccf70c 1265 set $kgm_ms_found = 1
1c79356b 1266 end
9bccf70c 1267 showwaitqmemberint $kgm_ms_waitqp
b0d623f7 1268 set $kgm_ms_wql = (WaitQueueLink *)$kgm_ms_wql->wql_setlinks.next
1c79356b
A
1269 end
1270end
1271
9bccf70c 1272define showwaitqheader
6d2010ae 1273 printf "wait_queue ref_count interlock "
9bccf70c
A
1274 printf "pol type member_cnt waiter_cnt\n"
1275end
1276
1277define showwaitqint
6d2010ae 1278 set $kgm_waitqp = (WaitQueue*)$arg0
9bccf70c
A
1279 printf "0x%08x ", $kgm_waitqp
1280 if ($kgm_waitqp->wq_type == 0xf1d1)
6d2010ae 1281 printf "0x%08x ", ((WaitQueueSet*)$kgm_waitqp)->wqs_refcount
9bccf70c
A
1282 else
1283 printf "0x00000000 "
1284 end
1285 printf "0x%08x ", $kgm_waitqp->wq_interlock.lock_data
1286 if ($kgm_waitqp->wq_fifo)
1287 printf "Fifo "
1288 else
1289 printf "Prio "
1290 end
1291 if ($kgm_waitqp->wq_type == 0xf1d1)
1292 printf "Set "
1293 showwaitqmembercount $kgm_waitqp
1294 else
1295 printf "Que 0x00000000 "
1296 end
1297 showwaitqwaitercount $kgm_waitqp
1298 printf "\n"
1299end
1300
1c79356b 1301define showwaitq
b0d623f7 1302 set $kgm_waitq1p = (WaitQueue*)$arg0
1c79356b 1303 showwaitqheader
9bccf70c
A
1304 showwaitqint $kgm_waitq1p
1305 if ($kgm_waitq1p->wq_type == 0xf1d1)
1306 showwaitqmembers $kgm_waitq1p
1307 else
1308 showwaitqmemberof $kgm_waitq1p
1c79356b 1309 end
9bccf70c 1310 showwaitqwaiters $kgm_waitq1p
1c79356b
A
1311end
1312
1313define showmapheader
b0d623f7
A
1314 printf "vm_map "
1315 showptrhdrpad
1316 printf " pmap "
1317 showptrhdrpad
1318 printf " vm_size "
1319 showptrhdrpad
1320 printf " #ents rpage hint "
1321 showptrhdrpad
1322 printf " first_free\n"
1c79356b
A
1323end
1324
1325define showvmeheader
b0d623f7
A
1326 printf " entry "
1327 showptrhdrpad
1328 printf " start prot #page object "
1329 showptrhdrpad
1330 printf " offset\n"
1c79356b
A
1331end
1332
1333define showvmint
1334 set $kgm_mapp = (vm_map_t)$arg0
1335 set $kgm_map = *$kgm_mapp
b0d623f7
A
1336 showptr $arg0
1337 printf " "
1338 showptr $kgm_map.pmap
1339 printf " "
1340 showptr $kgm_map.size
1341 printf " %3d ", $kgm_map.hdr.nentries
91447636
A
1342 if $kgm_map.pmap
1343 printf "%5d ", $kgm_map.pmap->stats.resident_count
1344 else
1345 printf "<n/a> "
1346 end
b0d623f7
A
1347 showptr $kgm_map.hint
1348 printf " "
1349 showptr $kgm_map.first_free
1350 printf "\n"
1c79356b 1351 if $arg1 != 0
b0d623f7
A
1352 showvmeheader
1353 set $kgm_head_vmep = &($kgm_mapp->hdr.links)
1354 set $kgm_vmep = $kgm_map.hdr.links.next
1355 while (($kgm_vmep != 0) && ($kgm_vmep != $kgm_head_vmep))
1356 set $kgm_vme = *$kgm_vmep
1357 printf " "
1358 showptr $kgm_vmep
1359 printf " 0x%016llx ", $kgm_vme.links.start
1360 printf "%1x", $kgm_vme.protection
1361 printf "%1x", $kgm_vme.max_protection
1362 if $kgm_vme.inheritance == 0x0
1363 printf "S"
1364 end
1365 if $kgm_vme.inheritance == 0x1
1366 printf "C"
1367 end
1368 if $kgm_vme.inheritance == 0x2
1369 printf "-"
1370 end
1371 if $kgm_vme.inheritance == 0x3
1372 printf "D"
1373 end
1374 if $kgm_vme.is_sub_map
1375 printf "s "
1376 else
1377 if $kgm_vme.needs_copy
1378 printf "n "
1379 else
1380 printf " "
1381 end
1382 end
1383 printf "%6d ",($kgm_vme.links.end - $kgm_vme.links.start) >> 12
1384 showptr $kgm_vme.object.vm_object
1385 printf " 0x%016llx\n", $kgm_vme.offset
1386 set $kgm_vmep = $kgm_vme.links.next
1c79356b
A
1387 end
1388 end
1389 printf "\n"
1390end
1391
1392
0b4c1975
A
1393define showmapwiredp
1394 set $kgm_mapp = (vm_map_t)$arg0
1395 set $kgm_map = *$kgm_mapp
1396 set $kgm_head_vmep = &($kgm_mapp->hdr.links)
1397 set $kgm_vmep = $kgm_map.hdr.links.next
1398 set $kgm_objp_prev = (struct vm_object *)0
1399 if $arg1 == 0
1400 set $kgm_saw_kernel_obj = 0
1401 set $kgm_wired_count = 0
1402 set $kgm_objp_print_space = 1
1403 else
1404 set $kgm_objp_print_space = 0
1405 end
1406 while (($kgm_vmep != 0) && ($kgm_vmep != $kgm_head_vmep))
1407 set $kgm_vme = *$kgm_vmep
1408 set $kgm_objp = $kgm_vme.object.vm_object
1409 if $kgm_vme.is_sub_map
1410 if $arg1 == 0
1411 set $kgm_mapp_orig = $kgm_mapp
1412 set $kgm_vmep_orig = $kgm_vmep
1413 set $kgm_vme_orig = $kgm_vme
1414 set $kgm_head_vmep_orig = $kgm_head_vmep
1415 printf "\n****"
1416 showptr $kgm_objp
1417 showmapwiredp $kgm_objp 1
1418 set $kgm_vme = $kgm_vme_orig
1419 set $kgm_vmep = $kgm_vmep_orig
1420 set $kgm_mapp = $kgm_mapp_orig
1421 set $kgm_head_vmep = $kgm_head_vmep_orig
1422 set $kgm_objp = (struct vm_object *)0
1423 else
1424 printf "\n????"
1425 showptr $kgm_mapp
1426 printf " "
1427 showptr $kgm_vmep
1428 set $kgm_objp = (struct vm_object *)0
1429 printf "\n"
1430 end
1431 end
1432 if ($kgm_objp == $kgm_objp_prev)
1433 set $kgm_objp = (struct vm_object *)0
1434 end
1435 if $kgm_objp == kernel_object
1436 if $kgm_saw_kernel_obj
1437 set $kgm_objp = (struct vm_object *)0
1438 end
1439 set $kgm_saw_kernel_obj = 1
1440 end
1441 if $kgm_objp && $kgm_objp->wired_page_count
1442 if $kgm_objp_print_space == 1
1443 printf " "
1444 showptr $kgm_mapp
1445 end
1446 set $kgm_objp_print_space = 1
1447 printf " "
1448 showptr $kgm_vmep
1449 printf " 0x%016llx ", $kgm_vme.links.start
1450 printf "%5d", $kgm_vme.alias
1451 printf "%6d ",($kgm_vme.links.end - $kgm_vme.links.start) >> 12
1452 showptr $kgm_objp
1453 printf "[%3d]", $kgm_objp->ref_count
1454 printf "%7d\n", $kgm_objp->wired_page_count
1455 set $kgm_wired_count = $kgm_wired_count + $kgm_objp->wired_page_count
1456 set $kgm_objp_prev = $kgm_objp
1457 end
1458 set $kgm_vmep = $kgm_vme.links.next
1459 end
1460 if $arg1 == 0
1461 printf "total wired count = %d\n", $kgm_wired_count
1462 end
1463end
1464
1465define showmapwired
1466 printf " map "
1467 showptrhdrpad
1468 printf " entry "
1469 showptrhdrpad
1470 printf " start alias #page object "
1471 showptrhdrpad
1472 printf " wired\n"
1473 showmapwiredp $arg0 0
1474end
1475document showmapwired
1476Syntax: (gdb) showmapwired <vm_map>
1477| Routine to print out a summary listing of all the entries with wired pages in a vm_map
1478end
1479
1c79356b
A
1480define showmapvme
1481 showmapheader
1482 showvmint $arg0 1
1483end
1484document showmapvme
2d21ac55 1485Syntax: (gdb) showmapvme <vm_map>
1c79356b 1486| Routine to print out a summary listing of all the entries in a vm_map
1c79356b
A
1487end
1488
1489
1490define showmap
1491 showmapheader
1492 showvmint $arg0 0
1493end
1494document showmap
2d21ac55 1495Syntax: (gdb) showmap <vm_map>
55e303ae 1496| Routine to print out info about the specified vm_map
1c79356b
A
1497end
1498
1499define showallvm
2d21ac55 1500 set $kgm_head_taskp = &tasks
9bccf70c 1501 set $kgm_taskp = (struct task *)($kgm_head_taskp->next)
1c79356b
A
1502 while $kgm_taskp != $kgm_head_taskp
1503 showtaskheader
1504 showmapheader
1505 showtaskint $kgm_taskp
1506 showvmint $kgm_taskp->map 0
2d21ac55 1507 set $kgm_taskp = (struct task *)($kgm_taskp->tasks.next)
1c79356b
A
1508 end
1509end
1510document showallvm
2d21ac55 1511Syntax: (gdb) showallvm
1c79356b 1512| Routine to print a summary listing of all the vm maps
1c79356b
A
1513end
1514
1515
1516define showallvme
2d21ac55 1517 set $kgm_head_taskp = &tasks
9bccf70c 1518 set $kgm_taskp = (struct task *)($kgm_head_taskp->next)
1c79356b
A
1519 while $kgm_taskp != $kgm_head_taskp
1520 showtaskheader
1521 showmapheader
1522 showtaskint $kgm_taskp
1523 showvmint $kgm_taskp->map 1
2d21ac55 1524 set $kgm_taskp = (struct task *)($kgm_taskp->tasks.next)
1c79356b
A
1525 end
1526end
1527document showallvme
2d21ac55 1528Syntax: (gdb) showallvme
1c79356b 1529| Routine to print a summary listing of all the vm map entries
1c79356b
A
1530end
1531
1532
1533define showipcheader
b0d623f7
A
1534 printf "ipc_space "
1535 showptrhdrpad
1536 printf " is_table "
1537 showptrhdrpad
1538 printf " table_next"
1539 showptrhdrpad
6d2010ae
A
1540 printf " flags ports splaysize "
1541 showptrhdrpad
1542 printf "splaybase\n"
1c79356b
A
1543end
1544
1545define showipceheader
6d2010ae 1546 printf " "
b0d623f7 1547 showptrhdrpad
6d2010ae
A
1548 printf "object "
1549 showptrhdrpad
1550 showptrhdrpad
1551 printf "name rite urefs destname "
1552 showptrhdrpad
1553 printf "destination\n"
1c79356b
A
1554end
1555
1556define showipceint
1557 set $kgm_ie = *(ipc_entry_t)$arg0
6d2010ae
A
1558 printf " "
1559 showptrhdrpad
b0d623f7 1560 showptr $kgm_ie.ie_object
6d2010ae
A
1561 showptrhdrpad
1562 printf " 0x%08x ", $arg1
1c79356b 1563 if $kgm_ie.ie_bits & 0x00100000
b0d623f7 1564 printf "Dead "
1c79356b
A
1565 printf "%5d\n", $kgm_ie.ie_bits & 0xffff
1566 else
1567 if $kgm_ie.ie_bits & 0x00080000
b0d623f7 1568 printf "SET "
1c79356b
A
1569 printf "%5d\n", $kgm_ie.ie_bits & 0xffff
1570 else
1571 if $kgm_ie.ie_bits & 0x00010000
b0d623f7
A
1572 if $kgm_ie.ie_bits & 0x00020000
1573 printf " SR"
1574 else
1575 printf " S"
1576 end
1c79356b 1577 else
b0d623f7
A
1578 if $kgm_ie.ie_bits & 0x00020000
1579 printf " R"
1580 end
1c79356b
A
1581 end
1582 if $kgm_ie.ie_bits & 0x00040000
b0d623f7 1583 printf " O"
1c79356b
A
1584 end
1585 if $kgm_ie.index.request
6d2010ae
A
1586 set $kgm_port = (ipc_port_t)$kgm_ie.ie_object
1587 set $kgm_requests = $kgm_port->ip_requests
1588 set $kgm_req_soright = $kgm_requests[$kgm_ie.index.request].notify.port
1589 if $kgm_req_soright
1590# Armed send-possible notification?
1591 if (uintptr_t)$kgm_req_soright & 0x1
1592 printf "s"
1593 else
1594# Delayed send-possible notification?
1595 if (uintptr_t)$kgm_req_soright & 0x2
1596 printf "d"
1597 else
1598# Dead-name notification
1599 printf "n"
1600 end
1601 end
1602 else
1603 printf " "
1604 end
1c79356b
A
1605 else
1606 printf " "
1607 end
6d2010ae 1608# Collision (with tree)?
1c79356b 1609 if $kgm_ie.ie_bits & 0x00800000
b0d623f7 1610 printf "c"
1c79356b 1611 else
b0d623f7 1612 printf " "
1c79356b
A
1613 end
1614 printf "%5d ", $kgm_ie.ie_bits & 0xffff
1615 showportdest $kgm_ie.ie_object
1616 end
1617 end
1618end
1619
1620define showipcint
1621 set $kgm_isp = (ipc_space_t)$arg0
1622 set $kgm_is = *$kgm_isp
b0d623f7
A
1623 showptr $arg0
1624 printf " "
1625 showptr $kgm_is.is_table
1626 printf " "
1627 showptr $kgm_is.is_table_next
1628 printf " "
1c79356b 1629 if $kgm_is.is_growing != 0
b0d623f7 1630 printf "G"
1c79356b 1631 else
b0d623f7 1632 printf " "
1c79356b
A
1633 end
1634 if $kgm_is.is_fast != 0
b0d623f7 1635 printf "F"
1c79356b 1636 else
b0d623f7 1637 printf " "
1c79356b
A
1638 end
1639 if $kgm_is.is_active != 0
b0d623f7 1640 printf "A "
1c79356b 1641 else
b0d623f7 1642 printf " "
1c79356b 1643 end
6d2010ae
A
1644 printf "%5d ", $kgm_is.is_table_size + $kgm_is.is_tree_total
1645 showptr $kgm_is.is_tree_total
1646 printf " "
b0d623f7
A
1647 showptr &$kgm_isp->is_tree
1648 printf "\n"
1c79356b 1649 if $arg1 != 0
b0d623f7
A
1650 showipceheader
1651 set $kgm_iindex = 0
1652 set $kgm_iep = $kgm_is.is_table
1653 set $kgm_destspacep = (ipc_space_t)0
1c79356b 1654 while ( $kgm_iindex < $kgm_is.is_table_size )
b0d623f7
A
1655 set $kgm_ie = *$kgm_iep
1656 if $kgm_ie.ie_bits & 0x001f0000
1657 set $kgm_name = (($kgm_iindex << 8)|($kgm_ie.ie_bits >> 24))
1658 showipceint $kgm_iep $kgm_name
6d2010ae
A
1659 if $arg2 != 0
1660 if $kgm_ie.ie_object != 0 && ($kgm_ie.ie_bits & 0x00070000) && ((ipc_port_t) $kgm_ie.ie_object)->ip_callstack[0] != 0
1661 printf " user bt: "
1662 showportbt $kgm_ie.ie_object $kgm_is.is_task
1663 end
1664 end
b0d623f7
A
1665 end
1666 set $kgm_iindex = $kgm_iindex + 1
1667 set $kgm_iep = &($kgm_is.is_table[$kgm_iindex])
1668 end
1669 if $kgm_is.is_tree_total
1670 printf "Still need to write tree traversal\n"
1671 end
1c79356b
A
1672 end
1673 printf "\n"
1674end
1675
1676
1677define showipc
b0d623f7
A
1678 set $kgm_isp = (ipc_space_t)$arg0
1679 showipcheader
b7266188 1680 showipcint $kgm_isp 0 0
1c79356b
A
1681end
1682document showipc
2d21ac55 1683Syntax: (gdb) showipc <ipc_space>
1c79356b 1684| Routine to print the status of the specified ipc space
1c79356b
A
1685end
1686
1687define showrights
1688 set $kgm_isp = (ipc_space_t)$arg0
b0d623f7 1689 showipcheader
b7266188 1690 showipcint $kgm_isp 1 0
1c79356b
A
1691end
1692document showrights
2d21ac55 1693Syntax: (gdb) showrights <ipc_space>
1c79356b 1694| Routine to print a summary list of all the rights in a specified ipc space
1c79356b
A
1695end
1696
1697
1698define showtaskipc
1699 set $kgm_taskp = (task_t)$arg0
1700 showtaskheader
1c79356b 1701 showtaskint $kgm_taskp
6d2010ae 1702 showipcheader
b7266188 1703 showipcint $kgm_taskp->itk_space 0 0
1c79356b
A
1704end
1705document showtaskipc
2d21ac55 1706Syntax: (gdb) showtaskipc <task>
55e303ae 1707| Routine to print info about the ipc space for a task
1c79356b
A
1708end
1709
1710
1711define showtaskrights
1712 set $kgm_taskp = (task_t)$arg0
1713 showtaskheader
1c79356b 1714 showtaskint $kgm_taskp
6d2010ae 1715 showipcheader
b7266188 1716 showipcint $kgm_taskp->itk_space 1 0
1c79356b
A
1717end
1718document showtaskrights
2d21ac55 1719Syntax: (gdb) showtaskrights <task>
55e303ae 1720| Routine to print info about the ipc rights for a task
1c79356b
A
1721end
1722
b7266188
A
1723define showtaskrightsbt
1724 set $kgm_taskp = (task_t)$arg0
1725 showtaskheader
b7266188 1726 showtaskint $kgm_taskp
6d2010ae 1727 showipcheader
b7266188
A
1728 showipcint $kgm_taskp->itk_space 1 1
1729end
1730document showtaskrightsbt
1731Syntax: (gdb) showtaskrightsbt <task>
1732| Routine to print info about the ipc rights for a task with backtraces
1733end
1734
1c79356b 1735define showallipc
2d21ac55 1736 set $kgm_head_taskp = &tasks
91447636
A
1737 set $kgm_cur_taskp = (struct task *)($kgm_head_taskp->next)
1738 while $kgm_cur_taskp != $kgm_head_taskp
1c79356b 1739 showtaskheader
b0d623f7 1740 showtaskint $kgm_cur_taskp
6d2010ae 1741 showipcheader
b7266188 1742 showipcint $kgm_cur_taskp->itk_space 0 0
2d21ac55 1743 set $kgm_cur_taskp = (struct task *)($kgm_cur_taskp->tasks.next)
1c79356b
A
1744 end
1745end
1746document showallipc
2d21ac55 1747Syntax: (gdb) showallipc
1c79356b 1748| Routine to print a summary listing of all the ipc spaces
1c79356b
A
1749end
1750
6d2010ae
A
1751define showipcsumheader
1752 printf "task "
1753 showptrhdrpad
1754 printf " pid "
1755 printf " #acts "
1756 printf " tsize "
1757 printf "command\n"
1758end
1759
1760define showipcsummaryint
1761 set $kgm_taskp = (struct task *)$arg0
1762 showptr $arg0
1763 printf "%7d", ((struct proc *)$kgm_taskp->bsd_info)->p_pid
1764 printf "%15d", $kgm_taskp->thread_count
1765 printf "%15d", $kgm_cur_taskp->itk_space.is_table_size
1766 printf " %s\n", ((struct proc *)$kgm_taskp->bsd_info)->p_comm
1767end
1768
1769define showipcsummary
1770 showipcsumheader
1771 set $kgm_head_taskp = &tasks
1772 set $kgm_cur_taskp = (struct task *)($kgm_head_taskp->next)
1773 while $kgm_cur_taskp != $kgm_head_taskp
1774 showipcsummaryint $kgm_cur_taskp
1775 set $kgm_cur_taskp = (struct task *)($kgm_cur_taskp->tasks.next)
1776 end
1777end
1778
1779document showipcsummary
1780Syntax: (gdb) showipcsummary
1781| Summarizes the IPC state of all tasks. This is a convenient way to dump
1782| some basic clues about IPC messaging. You can use the output to determine
1783| tasks that are candidates for further investigation.
1784end
1785
1c79356b
A
1786
1787define showallrights
2d21ac55 1788 set $kgm_head_taskp = &tasks
91447636
A
1789 set $kgm_cur_taskp = (struct task *)($kgm_head_taskp->next)
1790 while $kgm_cur_taskp != $kgm_head_taskp
1c79356b 1791 showtaskheader
b0d623f7 1792 showtaskint $kgm_cur_taskp
6d2010ae 1793 showipcheader
b7266188 1794 showipcint $kgm_cur_taskp->itk_space 1 0
2d21ac55 1795 set $kgm_cur_taskp = (struct task *)($kgm_cur_taskp->tasks.next)
1c79356b
A
1796 end
1797end
1798document showallrights
2d21ac55 1799Syntax: (gdb) showallrights
1c79356b 1800| Routine to print a summary listing of all the ipc rights
1c79356b
A
1801end
1802
1803
1804define showtaskvm
1805 set $kgm_taskp = (task_t)$arg0
1806 showtaskheader
1807 showmapheader
1808 showtaskint $kgm_taskp
1809 showvmint $kgm_taskp->map 0
1810end
1811document showtaskvm
2d21ac55 1812Syntax: (gdb) showtaskvm <task>
55e303ae 1813| Routine to print out info about a task's vm_map
1c79356b
A
1814end
1815
1816define showtaskvme
1817 set $kgm_taskp = (task_t)$arg0
1818 showtaskheader
1c79356b 1819 showtaskint $kgm_taskp
6d2010ae 1820 showmapheader
1c79356b
A
1821 showvmint $kgm_taskp->map 1
1822end
1823document showtaskvme
2d21ac55 1824Syntax: (gdb) showtaskvme <task>
55e303ae 1825| Routine to print out info about a task's vm_map_entries
1c79356b
A
1826end
1827
1828
1829define showtaskheader
b0d623f7
A
1830 printf "task "
1831 showptrhdrpad
1832 printf " vm_map "
1833 showptrhdrpad
1834 printf " ipc_space "
1835 showptrhdrpad
1836 printf " #acts "
1c79356b
A
1837 showprocheader
1838end
1839
1840
1841define showtaskint
b0d623f7
A
1842 set $kgm_taskp = (struct task *)$arg0
1843 showptr $arg0
1844 printf " "
1845 showptr $kgm_taskp->map
1846 printf " "
1847 showptr $kgm_taskp->itk_space
1848 printf " %5d ", $kgm_taskp->thread_count
1849 showprocint $kgm_taskp->bsd_info
1c79356b
A
1850end
1851
1852define showtask
1853 showtaskheader
1854 showtaskint $arg0
1855end
1856document showtask
2d21ac55 1857Syntax (gdb) showtask <task>
1c79356b 1858| Routine to print out info about a task.
1c79356b
A
1859end
1860
1861
55e303ae 1862define showtaskthreads
1c79356b 1863 showtaskheader
9bccf70c 1864 set $kgm_taskp = (struct task *)$arg0
1c79356b
A
1865 showtaskint $kgm_taskp
1866 showactheader
55e303ae
A
1867 set $kgm_head_actp = &($kgm_taskp->threads)
1868 set $kgm_actp = (struct thread *)($kgm_taskp->threads.next)
1c79356b
A
1869 while $kgm_actp != $kgm_head_actp
1870 showactint $kgm_actp 0
55e303ae 1871 set $kgm_actp = (struct thread *)($kgm_actp->task_threads.next)
1c79356b
A
1872 end
1873end
55e303ae 1874document showtaskthreads
2d21ac55 1875Syntax: (gdb) showtaskthreads <task>
55e303ae 1876| Routine to print info about the threads in a task.
1c79356b
A
1877end
1878
1879
1880define showtaskstacks
1881 showtaskheader
9bccf70c 1882 set $kgm_taskp = (struct task *)$arg0
1c79356b 1883 showtaskint $kgm_taskp
55e303ae
A
1884 set $kgm_head_actp = &($kgm_taskp->threads)
1885 set $kgm_actp = (struct thread *)($kgm_taskp->threads.next)
1c79356b
A
1886 while $kgm_actp != $kgm_head_actp
1887 showactheader
1888 showactint $kgm_actp 1
55e303ae 1889 set $kgm_actp = (struct thread *)($kgm_actp->task_threads.next)
1c79356b
A
1890 end
1891end
1892document showtaskstacks
2d21ac55 1893Syntax: (gdb) showtaskstacks <task>
55e303ae 1894| Routine to print out the stack for each thread in a task.
1c79356b
A
1895end
1896
6d2010ae
A
1897define showqueue_elems
1898 set $queue_head = (struct queue_entry *)($arg0)
1899 set $queue = (struct queue_entry *)($queue_head->next)
1900 while $queue != $queue_head
1901 showptr $queue
1902 printf " "
1903 set $thread = (struct thread *)$queue
1904 set $task = (struct task *)$thread->task
1905 set $bsd = (struct proc *)$task->bsd_info
1906 set $guy = (char *)$bsd->p_comm
1907 showptr $thread
1908 printf " "
1909 showptr $task
1910 printf " "
1911 showptr $bsd
1912 printf " "
1913 showptr $guy
1914 #printf " %s\n", $kgm_procp->p_comm
1915 printf "\n"
1916 set $queue = (struct queue_entry *)($queue->next)
1917 end
1918end
1c79356b
A
1919
1920define showalltasks
1921 showtaskheader
2d21ac55 1922 set $kgm_head_taskp = &tasks
9bccf70c 1923 set $kgm_taskp = (struct task *)($kgm_head_taskp->next)
1c79356b
A
1924 while $kgm_taskp != $kgm_head_taskp
1925 showtaskint $kgm_taskp
2d21ac55 1926 set $kgm_taskp = (struct task *)($kgm_taskp->tasks.next)
1c79356b
A
1927 end
1928end
1929document showalltasks
2d21ac55 1930Syntax: (gdb) showalltasks
1c79356b 1931| Routine to print a summary listing of all the tasks
b0d623f7
A
1932| wq_state -> reports "number of workq threads", "number of scheduled workq threads", "number of pending work items"
1933| if "number of pending work items" seems stuck at non-zero, it may indicate that the workqueue mechanism is hung
1934| io_policy -> RAGE - rapid aging of vnodes requested
1935| NORM - normal I/O explicitly requested (this is the default)
1936| PASS - passive I/O requested (i.e. I/Os do not affect throttling decisions)
1937| THROT - throttled I/O requested (i.e. thread/task may be throttled after each I/O completes)
1c79356b
A
1938end
1939
1c79356b 1940define showprocheader
6d2010ae 1941 printf " pid process "
b0d623f7 1942 showptrhdrpad
6d2010ae 1943 printf "io_policy wq_state command\n"
1c79356b
A
1944end
1945
1946define showprocint
1947 set $kgm_procp = (struct proc *)$arg0
1948 if $kgm_procp != 0
b0d623f7 1949 set $kgm_printed = 0
1c79356b 1950 printf "%5d ", $kgm_procp->p_pid
b0d623f7
A
1951 showptr $kgm_procp
1952 if ($kgm_procp->p_lflag & 0x400000)
1953 printf " RAGE "
1954 else
1955 printf " "
1956 end
6d2010ae
A
1957 set $ptask = (struct task *)$kgm_procp->task
1958 set $diskpolicy = 0
1959 if ($ptask->ext_actionstate.hw_disk != 0)
1960 set $diskpolicy = $ptask->ext_actionstate.hw_disk
1961 else
1962 if ($ptask->actionstate.hw_disk != 0)
1963 set $diskpolicy = $ptask->actionstate.hw_disk
1964 end
1965 end
1966 if ($ptask->ext_actionstate.hw_bg != 0)
1967 set $diskpolicy = 5
b0d623f7 1968 end
6d2010ae
A
1969 if ($ptask->actionstate.hw_bg != 0)
1970 set $diskpolicy = 4
1971 end
1972 if ($diskpolicy == 2)
1973 printf "PASS "
1974 set $kgm_printed = 1
1975 end
1976 if ($diskpolicy == 3)
1977 printf "THROT "
1978 set $kgm_printed = 1
1979 end
1980 if ($diskpolicy == 4)
1981 printf "BG_THRT "
1982 set $kgm_printed = 1
1983 end
1984 if ($diskpolicy == 5)
1985 printf "EBG_THRT"
1986 set $kgm_printed = 1
b0d623f7
A
1987 end
1988 if ($kgm_printed == 0)
1989 printf " "
1990 end
1991 set $kgm_wqp = (struct workqueue *)$kgm_procp->p_wqptr
1992 if $kgm_wqp != 0
1993 printf " %2d %2d %2d ", $kgm_wqp->wq_nthreads, $kgm_wqp->wq_thidlecount, $kgm_wqp->wq_itemcount
1994 else
1995 printf " "
1996 end
1997 printf " %s\n", $kgm_procp->p_comm
1c79356b 1998 else
b0d623f7
A
1999 printf " *0* "
2000 showptr 0
2001 printf " --\n"
1c79356b
A
2002 end
2003end
2004
2005define showpid
2006 showtaskheader
2d21ac55 2007 set $kgm_head_taskp = &tasks
9bccf70c 2008 set $kgm_taskp = (struct task *)($kgm_head_taskp->next)
1c79356b
A
2009 while $kgm_taskp != $kgm_head_taskp
2010 set $kgm_procp = (struct proc *)$kgm_taskp->bsd_info
2011 if (($kgm_procp != 0) && ($kgm_procp->p_pid == $arg0))
2012 showtaskint $kgm_taskp
2013 set $kgm_taskp = $kgm_head_taskp
2014 else
2d21ac55 2015 set $kgm_taskp = (struct task *)($kgm_taskp->tasks.next)
1c79356b
A
2016 end
2017 end
2018end
2019document showpid
2d21ac55 2020Syntax: (gdb) showpid <pid>
1c79356b 2021| Routine to print a single process by pid
1c79356b
A
2022end
2023
2024define showproc
2025 showtaskheader
2026 set $kgm_procp = (struct proc *)$arg0
b0d623f7 2027 showtaskint $kgm_procp->task
1c79356b
A
2028end
2029
2030
2031define kdb
2032 set switch_debugger=1
2033 continue
2034end
2035document kdb
2036| kdb - Switch to the inline kernel debugger
2037|
2038| usage: kdb
2039|
2040| The kdb macro allows you to invoke the inline kernel debugger.
2041end
2042
2043define showpsetheader
6d2010ae
A
2044 printf "portset "
2045 showptrhdrpad
2046 printf "waitqueue "
2047 showptrhdrpad
2048 showptrhdrpad
2049 printf "recvname flags refs recvname "
2050 showptrhdrpad
2051 printf "process\n"
1c79356b
A
2052end
2053
2054define showportheader
6d2010ae
A
2055 printf "port "
2056 showptrhdrpad
2057 printf "mqueue "
2058 showptrhdrpad
2059 showptrhdrpad
2060 printf "recvname flags refs recvname "
2061 showptrhdrpad
2062 printf "dest\n"
1c79356b
A
2063end
2064
2065define showportmemberheader
6d2010ae
A
2066 printf "members "
2067 showptrhdrpad
2068 printf "port "
2069 showptrhdrpad
2070 showptrhdrpad
2071 printf "recvname "
2072 printf "flags refs mqueue "
2073 showptrhdrpad
2074 printf "msgcount\n"
1c79356b
A
2075end
2076
2077define showkmsgheader
6d2010ae
A
2078 printf "dest-port "
2079 showptrhdrpad
2080 printf "kmsg "
2081 showptrhdrpad
2082 showptrhdrpad
2083 printf "msgid "
2084 printf "disp size "
2085 printf "reply-port "
2086 showptrhdrpad
2087 printf "source\n"
2088end
2089
2090define showkmsgsrcint
2091 set $kgm_kmsgsrchp = ((ipc_kmsg_t)$arg0)->ikm_header
2092# set $kgm_kmsgsrctp = (mach_msg_audit_trailer_t *)((uintptr_t)$kgm_kmsgsrchp + $kgm_kmsgsrchp->msgh_size)
2093# set $kgm_kmsgpid = $kgm_kmsgsrctp->msgh_audit.val[5]
2094 set $kgm_kmsgpid = (pid_t)((uint *)((uintptr_t)$kgm_kmsgsrchp + $kgm_kmsgsrchp->msgh_size))[10]
2095# compare against a well-known or cached value as this may be slow
2096 if ($kgm_kmsgpid == 0)
2097 set $kgm_kmsgsrcpid = (pid_t)0
2098 set $kgm_kmsgsrcprocp = (struct proc *)kernel_task->bsd_info
2099 else
2100 if ($kgm_kmsgpid != $kgm_kmsgsrcpid)
2101 set $kgm_kmsgsrchead_taskp = &tasks
2102 set $kgm_kmsgsrctaskp = (struct task *)($kgm_kmsgsrchead_taskp->next)
2103 while $kgm_kmsgsrctaskp != $kgm_kmsgsrchead_taskp
2104 set $kgm_kmsgsrcprocp = (struct proc *)$kgm_kmsgsrctaskp->bsd_info
2105 set $kgm_kmsgsrcpid = $kgm_kmsgsrcprocp->p_pid
2106 if (($kgm_kmsgsrcprocp != 0) && ($kgm_kmsgsrcprocp->p_pid == $kgm_kmsgpid))
2107 set $kgm_kmsgsrctaskp = $kgm_kmsgsrchead_taskp
2108 else
2109 set $kgm_kmsgsrctaskp = (struct task *)($kgm_kmsgsrctaskp->tasks.next)
2110 end
2111 end
2112 end
2113 end
2114 if ($kgm_kmsgsrcprocp->p_pid == $kgm_kmsgpid)
2115 printf "%s(%d)\n", $kgm_kmsgsrcprocp->p_comm, $kgm_kmsgpid
2116 else
2117 printf "unknown(%d)\n", $kgm_kmsgpid
2118 end
1c79356b
A
2119end
2120
2121define showkmsgint
6d2010ae
A
2122 set $kgm_kmsghp = ((ipc_kmsg_t)$arg0)->ikm_header
2123 set $kgm_kmsgh = *$kgm_kmsghp
2124 if ($arg1 != 0)
2125 printf " "
2126 showptrhdrpad
2127 else
2128 showptr $kgm_kmsgh.msgh_remote_port
2129 end
2130 showptr $arg0
2131 showptrhdrpad
2132 printf " 0x%08x ", $kgm_kmsgh.msgh_id
1c79356b
A
2133 if (($kgm_kmsgh.msgh_bits & 0xff) == 19)
2134 printf "rC"
2135 else
2136 printf "rM"
2137 end
b0d623f7 2138 if (($kgm_kmsgh.msgh_bits & 0xff00) == (19 << 8))
1c79356b
A
2139 printf "lC"
2140 else
2141 printf "lM"
2142 end
2143 if ($kgm_kmsgh.msgh_bits & 0xf0000000)
2144 printf "c"
2145 else
2146 printf "s"
2147 end
6d2010ae
A
2148 printf "%5d ", $kgm_kmsgh.msgh_size
2149 showptr $kgm_kmsgh.msgh_local_port
2150 printf " "
2151 set $kgm_kmsgsrcpid = (pid_t)0
2152 showkmsgsrcint $arg0
1c79356b
A
2153end
2154
6d2010ae
A
2155define showkmsg
2156 showkmsgint $arg0 0
2157end
1c79356b
A
2158
2159define showkobject
9bccf70c 2160 set $kgm_portp = (struct ipc_port *)$arg0
b0d623f7
A
2161 showptr $kgm_portp->ip_kobject
2162 printf " kobject("
1c79356b
A
2163 set $kgm_kotype = ($kgm_portp->ip_object.io_bits & 0x00000fff)
2164 if ($kgm_kotype == 1)
2165 printf "THREAD"
2166 end
2167 if ($kgm_kotype == 2)
2168 printf "TASK"
2169 end
2170 if ($kgm_kotype == 3)
2171 printf "HOST"
2172 end
2173 if ($kgm_kotype == 4)
2174 printf "HOST_PRIV"
2175 end
2176 if ($kgm_kotype == 5)
2177 printf "PROCESSOR"
2178 end
2179 if ($kgm_kotype == 6)
2180 printf "PSET"
2181 end
2182 if ($kgm_kotype == 7)
2183 printf "PSET_NAME"
2184 end
2185 if ($kgm_kotype == 8)
2186 printf "TIMER"
2187 end
2188 if ($kgm_kotype == 9)
2189 printf "PAGER_REQ"
2190 end
2191 if ($kgm_kotype == 10)
2192 printf "DEVICE"
2193 end
2194 if ($kgm_kotype == 11)
2195 printf "XMM_OBJECT"
2196 end
2197 if ($kgm_kotype == 12)
2198 printf "XMM_PAGER"
2199 end
2200 if ($kgm_kotype == 13)
2201 printf "XMM_KERNEL"
2202 end
2203 if ($kgm_kotype == 14)
2204 printf "XMM_REPLY"
2205 end
2206 if ($kgm_kotype == 15)
2207 printf "NOTDEF 15"
2208 end
2209 if ($kgm_kotype == 16)
2210 printf "NOTDEF 16"
2211 end
2212 if ($kgm_kotype == 17)
2213 printf "HOST_SEC"
2214 end
2215 if ($kgm_kotype == 18)
2216 printf "LEDGER"
2217 end
2218 if ($kgm_kotype == 19)
2219 printf "MASTER_DEV"
2220 end
2221 if ($kgm_kotype == 20)
2222 printf "ACTIVATION"
2223 end
2224 if ($kgm_kotype == 21)
2225 printf "SUBSYSTEM"
2226 end
2227 if ($kgm_kotype == 22)
2228 printf "IO_DONE_QUE"
2229 end
2230 if ($kgm_kotype == 23)
2231 printf "SEMAPHORE"
2232 end
2233 if ($kgm_kotype == 24)
2234 printf "LOCK_SET"
2235 end
2236 if ($kgm_kotype == 25)
2237 printf "CLOCK"
2238 end
2239 if ($kgm_kotype == 26)
2240 printf "CLOCK_CTRL"
2241 end
2242 if ($kgm_kotype == 27)
2243 printf "IOKIT_SPARE"
2244 end
2245 if ($kgm_kotype == 28)
2246 printf "NAMED_MEM"
2247 end
2248 if ($kgm_kotype == 29)
2249 printf "IOKIT_CON"
2250 end
2251 if ($kgm_kotype == 30)
2252 printf "IOKIT_OBJ"
2253 end
2254 if ($kgm_kotype == 31)
2255 printf "UPL"
2256 end
d1ecb069
A
2257 if ($kgm_kotype == 34)
2258 printf "FD"
2259 end
1c79356b
A
2260 printf ")\n"
2261end
2262
2263define showportdestproc
9bccf70c 2264 set $kgm_portp = (struct ipc_port *)$arg0
1c79356b
A
2265 set $kgm_spacep = $kgm_portp->data.receiver
2266# check against the previous cached value - this is slow
2267 if ($kgm_spacep != $kgm_destspacep)
2268 set $kgm_destprocp = (struct proc *)0
2d21ac55 2269 set $kgm_head_taskp = &tasks
91447636
A
2270 set $kgm_desttaskp = (struct task *)($kgm_head_taskp->next)
2271 while (($kgm_destprocp == 0) && ($kgm_desttaskp != $kgm_head_taskp))
2272 set $kgm_destspacep = $kgm_desttaskp->itk_space
1c79356b 2273 if ($kgm_destspacep == $kgm_spacep)
91447636 2274 set $kgm_destprocp = (struct proc *)$kgm_desttaskp->bsd_info
1c79356b 2275 else
2d21ac55 2276 set $kgm_desttaskp = (struct task *)($kgm_desttaskp->tasks.next)
1c79356b
A
2277 end
2278 end
2279 end
2280 if $kgm_destprocp != 0
2281 printf "%s(%d)\n", $kgm_destprocp->p_comm, $kgm_destprocp->p_pid
2282 else
b0d623f7
A
2283 printf "task "
2284 showptr $kgm_desttaskp
2285 printf "\n"
1c79356b
A
2286 end
2287end
2288
2289define showportdest
9bccf70c 2290 set $kgm_portp = (struct ipc_port *)$arg0
1c79356b 2291 set $kgm_spacep = $kgm_portp->data.receiver
6d2010ae 2292 if ((uintptr_t)$kgm_spacep == (uintptr_t)ipc_space_kernel)
1c79356b
A
2293 showkobject $kgm_portp
2294 else
2295 if ($kgm_portp->ip_object.io_bits & 0x80000000)
b0d623f7
A
2296 showptr $kgm_portp->ip_messages.data.port.receiver_name
2297 printf " "
1c79356b
A
2298 showportdestproc $kgm_portp
2299 else
b0d623f7
A
2300 showptr $kgm_portp
2301 printf " inactive-port\n"
1c79356b
A
2302 end
2303 end
2304end
2305
2306define showportmember
6d2010ae
A
2307 printf " "
2308 showptrhdrpad
2309 showptr $arg0
2310 showptrhdrpad
9bccf70c 2311 set $kgm_portp = (struct ipc_port *)$arg0
6d2010ae 2312 printf " 0x%08x ", $kgm_portp->ip_messages.data.port.receiver_name
1c79356b
A
2313 if ($kgm_portp->ip_object.io_bits & 0x80000000)
2314 printf "A"
2315 else
2316 printf " "
2317 end
b0d623f7 2318 printf "Port"
1c79356b 2319 printf "%5d ", $kgm_portp->ip_object.io_references
6d2010ae
A
2320 showptr &($kgm_portp->ip_messages)
2321 printf " 0x%08x\n", $kgm_portp->ip_messages.data.port.msgcount
1c79356b
A
2322end
2323
b7266188
A
2324define showportbt
2325 set $kgm_iebt = ((ipc_port_t) $arg0)->ip_callstack
2326 set $kgm_iepid = ((ipc_port_t) $arg0)->ip_spares[0]
2327 set $kgm_procpid = ((proc_t) (((task_t) $arg1)->bsd_info))->p_pid
2328 if $kgm_iebt[0] != 0
2329 showptr $kgm_iebt[0]
2330 set $kgm_iebt_loop_ctr = 1
2331 while ($kgm_iebt_loop_ctr < 16 && $kgm_iebt[$kgm_iebt_loop_ctr])
2332 printf " "
2333 showptr $kgm_iebt[$kgm_iebt_loop_ctr]
2334 set $kgm_iebt_loop_ctr = $kgm_iebt_loop_ctr + 1
2335 end
2336 if $kgm_iepid != $kgm_procpid
2337 printf " (%d)", $kgm_iepid
2338 end
2339 printf "\n"
2340 end
2341end
2342
1c79356b 2343define showportint
6d2010ae
A
2344 showptr $arg0
2345 printf " "
9bccf70c 2346 set $kgm_portp = (struct ipc_port *)$arg0
6d2010ae
A
2347 showptr &($kgm_portp->ip_messages)
2348 showptrhdrpad
2349 printf " 0x%08x ", $kgm_portp->ip_messages.data.port.receiver_name
1c79356b
A
2350 if ($kgm_portp->ip_object.io_bits & 0x80000000)
2351 printf "A"
2352 else
2353 printf "D"
2354 end
2355 printf "Port"
2356 printf "%5d ", $kgm_portp->ip_object.io_references
9bccf70c 2357 set $kgm_destspacep = (struct ipc_space *)0
1c79356b
A
2358 showportdest $kgm_portp
2359 set $kgm_kmsgp = (ipc_kmsg_t)$kgm_portp->ip_messages.data.port.messages.ikmq_base
2360 if $arg1 && $kgm_kmsgp
2361 showkmsgheader
6d2010ae 2362 showkmsgint $kgm_kmsgp 1
1c79356b
A
2363 set $kgm_kmsgheadp = $kgm_kmsgp
2364 set $kgm_kmsgp = $kgm_kmsgp->ikm_next
2365 while $kgm_kmsgp != $kgm_kmsgheadp
6d2010ae 2366 showkmsgint $kgm_kmsgp 1
1c79356b
A
2367 set $kgm_kmsgp = $kgm_kmsgp->ikm_next
2368 end
2369 end
2370end
2371
2372define showpsetint
6d2010ae
A
2373 showptr $arg0
2374 printf " "
9bccf70c 2375 set $kgm_psetp = (struct ipc_pset *)$arg0
6d2010ae
A
2376 showptr &($kgm_psetp->ips_messages)
2377 showptrhdrpad
2378 printf " 0x%08x ", $kgm_psetp->ips_messages.data.pset.local_name
1c79356b
A
2379 if ($kgm_psetp->ips_object.io_bits & 0x80000000)
2380 printf "A"
2381 else
2382 printf "D"
2383 end
2384 printf "Set "
2385 printf "%5d ", $kgm_psetp->ips_object.io_references
6d2010ae
A
2386 showptr $kgm_psetp->ips_messages.data.pset.local_name
2387 printf " "
0b4c1975 2388 set $kgm_setlinksp = &($kgm_psetp->ips_messages.data.pset.set_queue.wqs_setlinks)
b0d623f7 2389 set $kgm_wql = (WaitQueueLink *)$kgm_setlinksp->next
1c79356b 2390 set $kgm_found = 0
9bccf70c 2391 while ( (queue_entry_t)$kgm_wql != (queue_entry_t)$kgm_setlinksp)
6d2010ae 2392 set $kgm_portp = (struct ipc_port *)((uintptr_t)($kgm_wql->wql_element->wqe_queue) - (uintptr_t)$kgm_portoff)
1c79356b 2393 if !$kgm_found
9bccf70c
A
2394 set $kgm_destspacep = (struct ipc_space *)0
2395 showportdestproc $kgm_portp
1c79356b
A
2396 showportmemberheader
2397 set $kgm_found = 1
2398 end
2399 showportmember $kgm_portp 0
b0d623f7 2400 set $kgm_wql = (WaitQueueLink *)$kgm_wql->wql_setlinks.next
1c79356b 2401 end
9bccf70c
A
2402 if !$kgm_found
2403 printf "--n/e--\n"
1c79356b
A
2404 end
2405end
2406
2407define showpset
6d2010ae 2408 set $kgm_portoff = &(((struct ipc_port *)0)->ip_messages)
1c79356b
A
2409 showpsetheader
2410 showpsetint $arg0 1
2411end
2412
2413define showport
2414 showportheader
2415 showportint $arg0 1
2416end
2417
2418define showipcobject
6d2010ae 2419 set $kgm_objectp = (ipc_object_t)$arg0
1c79356b 2420 if ($kgm_objectp->io_bits & 0x7fff0000)
6d2010ae 2421 set $kgm_portoff = &(((struct ipc_port *)0)->ip_messages)
1c79356b
A
2422 showpset $kgm_objectp
2423 else
2424 showport $kgm_objectp
2425 end
2426end
2427
2428define showmqueue
9bccf70c 2429 set $kgm_mqueue = *(struct ipc_mqueue *)$arg0
b0d623f7 2430 if ($kgm_mqueue.data.pset.set_queue.wqs_wait_queue.wq_type == 0xf1d1)
6d2010ae
A
2431 set $kgm_psetoff = &(((struct ipc_pset *)0)->ips_messages)
2432 set $kgm_pset = (((long)$arg0) - ((long)$kgm_psetoff))
1c79356b 2433 showpsetheader
6d2010ae 2434 showpsetint $kgm_pset 1
9bccf70c 2435 end
b0d623f7 2436 if ($kgm_mqueue.data.pset.set_queue.wqs_wait_queue.wq_type == 0xf1d0)
6d2010ae
A
2437 set $kgm_portoff = &(((struct ipc_port *)0)->ip_messages)
2438 set $kgm_port = (((long)$arg0) - ((long)$kgm_portoff))
1c79356b 2439 showportheader
6d2010ae 2440 showportint $kgm_port 1
1c79356b
A
2441 end
2442end
2443
2444define zprint_one
b0d623f7 2445 set $kgm_zone = (struct zone *)$arg0
1c79356b 2446
b0d623f7
A
2447 showptr $kgm_zone
2448 printf " %6d ",$kgm_zone->count
2449 printf "%8x ",$kgm_zone->cur_size
2450 printf "%8x ",$kgm_zone->max_size
2451 printf "%6d ",$kgm_zone->elem_size
2452 printf "%8x ",$kgm_zone->alloc_size
6d2010ae
A
2453 printf " %8d ",$kgm_zone->num_allocs
2454 printf "%8d ",$kgm_zone->num_frees
b0d623f7 2455 printf "%s ",$kgm_zone->zone_name
1c79356b 2456
b0d623f7
A
2457 if ($kgm_zone->exhaustible)
2458 printf "H"
2459 end
2460 if ($kgm_zone->collectable)
2461 printf "C"
2462 end
2463 if ($kgm_zone->expandable)
2464 printf "X"
2465 end
0b4c1975 2466 if ($kgm_zone->noencrypt)
6d2010ae 2467 printf "$"
0b4c1975 2468 end
b0d623f7 2469 printf "\n"
1c79356b
A
2470end
2471
2472
2473define zprint
b0d623f7
A
2474 printf "ZONE "
2475 showptrhdrpad
6d2010ae 2476 printf " COUNT TOT_SZ MAX_SZ ELT_SZ ALLOC_SZ TOT_ALLOC TOT_FREE NAME\n"
b0d623f7
A
2477 set $kgm_zone_ptr = (struct zone *)first_zone
2478 while ($kgm_zone_ptr != 0)
2479 zprint_one $kgm_zone_ptr
2480 set $kgm_zone_ptr = $kgm_zone_ptr->next_zone
2481 end
2482 printf "\n"
1c79356b
A
2483end
2484document zprint
2d21ac55 2485Syntax: (gdb) zprint
1c79356b 2486| Routine to print a summary listing of all the kernel zones
1c79356b
A
2487end
2488
91447636 2489define showmtxgrp
b0d623f7
A
2490 set $kgm_mtxgrp = (struct _lck_grp_ *)$arg0
2491
2492 if ($kgm_mtxgrp->lck_grp_mtxcnt)
2493 showptr $kgm_mtxgrp
2494 printf " %8d ",$kgm_mtxgrp->lck_grp_mtxcnt
2495 printf "%12u ",$kgm_mtxgrp->lck_grp_stat.lck_grp_mtx_stat.lck_grp_mtx_util_cnt
2496 printf "%8u ",$kgm_mtxgrp->lck_grp_stat.lck_grp_mtx_stat.lck_grp_mtx_miss_cnt
2497 printf "%8u ",$kgm_mtxgrp->lck_grp_stat.lck_grp_mtx_stat.lck_grp_mtx_wait_cnt
2498 printf "%s ",&$kgm_mtxgrp->lck_grp_name
2499 printf "\n"
2500 end
91447636
A
2501end
2502
2503
2504define showallmtx
b0d623f7
A
2505 printf "LCK GROUP "
2506 showptrhdrpad
2507 printf " CNT UTIL MISS WAIT NAME\n"
2508 set $kgm_mtxgrp_ptr = (struct _lck_grp_ *)&lck_grp_queue
2509 set $kgm_mtxgrp_ptr = (struct _lck_grp_ *)$kgm_mtxgrp_ptr->lck_grp_link.next
2510 while ($kgm_mtxgrp_ptr != (struct _lck_grp_ *)&lck_grp_queue)
2511 showmtxgrp $kgm_mtxgrp_ptr
2512 set $kgm_mtxgrp_ptr = (struct _lck_grp_ *)$kgm_mtxgrp_ptr->lck_grp_link.next
2513 end
2514 printf "\n"
91447636
A
2515end
2516document showallmtx
2d21ac55 2517Syntax: (gdb) showallmtx
91447636 2518| Routine to print a summary listing of all mutexes
91447636
A
2519end
2520
2521define showrwlckgrp
b0d623f7
A
2522 set $kgm_rwlckgrp = (struct _lck_grp_ *)$arg0
2523
2524 if ($kgm_rwlckgrp->lck_grp_rwcnt)
2525 showptr $kgm_rwlckgrp
2526 printf " %8d ",$kgm_rwlckgrp->lck_grp_rwcnt
2527 printf "%12u ",$kgm_rwlckgrp->lck_grp_stat.lck_grp_rw_stat.lck_grp_rw_util_cnt
2528 printf "%8u ",$kgm_rwlckgrp->lck_grp_stat.lck_grp_rw_stat.lck_grp_rw_miss_cnt
2529 printf "%8u ",$kgm_rwlckgrp->lck_grp_stat.lck_grp_rw_stat.lck_grp_rw_wait_cnt
2530 printf "%s ",&$kgm_rwlckgrp->lck_grp_name
2531 printf "\n"
2532 end
91447636
A
2533end
2534
2535
2536define showallrwlck
b0d623f7
A
2537 printf "LCK GROUP "
2538 showptrhdrpad
2539 printf " CNT UTIL MISS WAIT NAME\n"
2540 set $kgm_rwlckgrp_ptr = (struct _lck_grp_ *)&lck_grp_queue
2541 set $kgm_rwlckgrp_ptr = (struct _lck_grp_ *)$kgm_rwlckgrp_ptr->lck_grp_link.next
2542 while ($kgm_rwlckgrp_ptr != (struct _lck_grp_ *)&lck_grp_queue)
2543 showrwlckgrp $kgm_rwlckgrp_ptr
2544 set $kgm_rwlckgrp_ptr = (struct _lck_grp_ *)$kgm_rwlckgrp_ptr->lck_grp_link.next
2545 end
2546 printf "\n"
91447636
A
2547end
2548document showallrwlck
2d21ac55 2549Syntax: (gdb) showallrwlck
91447636 2550| Routine to print a summary listing of all read/writer locks
91447636
A
2551end
2552
9bccf70c 2553set $kdp_act_counter = 0
6d2010ae 2554set $kdp_arm_act_counter = 0
9bccf70c 2555
2d21ac55
A
2556set $r0_save = 0
2557set $r1_save = 0
2558set $r2_save = 0
2559set $r3_save = 0
2560set $r4_save = 0
2561set $r5_save = 0
2562set $r6_save = 0
2563set $r7_save = 0
2564set $r8_save = 0
2565set $r9_save = 0
2566set $r10_save = 0
2567set $r11_save = 0
2568set $r12_save = 0
2569set $sp_save = 0
2570set $lr_save = 0
2571set $pc_save = 0
2572
2573define showcontext_int
2574 echo Context switched, current instruction pointer:
2575 output/a $pc
2576 echo \n
2577end
2578
9bccf70c 2579define switchtoact
0c530ab8 2580 set $newact = (struct thread *) $arg0
2d21ac55 2581 select 0
0c530ab8
A
2582 if ($newact->kernel_stack == 0)
2583 echo This activation does not have a stack.\n
2584 echo continuation:
2585 output/a (unsigned) $newact.continuation
2586 echo \n
2587 else
6d2010ae
A
2588 if ($kgm_mtype == $kgm_mtype_ppc)
2589 if ($kdp_act_counter == 0)
2590 set $kdpstate = (struct savearea *) kdp.saved_state
2591 end
2592 set $kdp_act_counter = $kdp_act_counter + 1
2593 set (struct savearea *) kdp.saved_state=$newact->machine->pcb
2594 flushregs
2595 flushstack
2596 set $pc=$newact->machine->pcb.save_srr0
2597 update
2598 end
2599 if ($kgm_mtype == $kgm_mtype_i386)
2600 set $kdpstatep = (struct x86_saved_state32 *) kdp.saved_state
2601 if ($kdp_act_counter == 0)
2602 set $kdpstate = *($kdpstatep)
2603 end
2604 set $kdp_act_counter = $kdp_act_counter + 1
2605
2606 set $kgm_statep = (struct x86_kernel_state *) \
2607 ($newact->kernel_stack + kernel_stack_size \
2608 - sizeof(struct x86_kernel_state))
2609 set $kdpstatep->ebx = $kgm_statep->k_ebx
2610 set $kdpstatep->ebp = $kgm_statep->k_ebp
2611 set $kdpstatep->edi = $kgm_statep->k_edi
2612 set $kdpstatep->esi = $kgm_statep->k_esi
2613 set $kdpstatep->eip = $kgm_statep->k_eip
2614 flushregs
2615 flushstack
2616 set $pc = $kgm_statep->k_eip
2617 update
2618 end
2619 if ($kgm_mtype == $kgm_mtype_x86_64)
2620 set $kdpstatep = (struct x86_saved_state64 *) kdp.saved_state
2621 if ($kdp_act_counter == 0)
2622 set $kdpstate = *($kdpstatep)
2623 end
2624 set $kdp_act_counter = $kdp_act_counter + 1
2625
2626 set $kgm_statep = (struct x86_kernel_state *) \
2627 ($newact->kernel_stack + kernel_stack_size \
2628 - sizeof(struct x86_kernel_state))
2629 set $kdpstatep->rbx = $kgm_statep->k_rbx
2630 set $kdpstatep->rbp = $kgm_statep->k_rbp
2631 set $kdpstatep->r12 = $kgm_statep->k_r12
2632 set $kdpstatep->r13 = $kgm_statep->k_r13
2633 set $kdpstatep->r14 = $kgm_statep->k_r14
2634 set $kdpstatep->r15 = $kgm_statep->k_r15
2635 set $kdpstatep->isf.rsp = $kgm_statep->k_rsp
2636 flushregs
2637 flushstack
2638 set $pc = $kgm_statep->k_rip
2639 update
2640 end
2641 if ($kgm_mtype == $kgm_mtype_arm)
2642 set $kdp_arm_act_counter = $kdp_arm_act_counter + 1
2643 if ($kdp_arm_act_counter == 1)
2644 set $r0_save = $r0
2645 set $r1_save = $r1
2646 set $r2_save = $r2
2647 set $r3_save = $r3
2648 set $r4_save = $r4
2649 set $r5_save = $r5
2650 set $r6_save = $r6
2651 set $r7_save = $r7
2652 set $r8_save = $r8
2653 set $r9_save = $r9
2654 set $r10_save = $r10
2655 set $r11_save = $r11
2656 set $r12_save = $r12
2657 set $sp_save = $sp
2658 set $lr_save = $lr
2659 set $pc_save = $pc
2660 end
2661 set $pc_ctx = load_reg+8
2662 set $kgm_statep = (struct arm_saved_state *)((struct thread*)$arg0)->machine.kstackptr
2663 set $r0 = $kgm_statep->r[0]
2664 set $r1 = $kgm_statep->r[1]
2665 set $r2 = $kgm_statep->r[2]
2666 set $r3 = $kgm_statep->r[3]
2667 set $r4 = $kgm_statep->r[4]
2668 set $r5 = $kgm_statep->r[5]
2669 set $r6 = $kgm_statep->r[6]
2670 set $r8 = $kgm_statep->r[8]
2671 set $r9 = $kgm_statep->r[9]
2672 set $r10 = $kgm_statep->r[10]
2673 set $r11 = $kgm_statep->r[11]
2674 set $r12 = $kgm_statep->r[12]
2675 set $sp = $kgm_statep->sp
2676 set $lr = $kgm_statep->lr
2677 set $pc = $pc_ctx
2678 set $r7 = $kgm_statep->r[7]
2679 flushregs
2680 flushstack
2681 end
2682 end
2683 showcontext_int
2684end
2685
2686document switchtoact
2687Syntax: switchtoact <address of activation>
2688| This command allows gdb to examine the execution context and call
2689| stack for the specified activation. For example, to view the backtrace
2690| for an activation issue "switchtoact <address>", followed by "bt".
2691| Before resuming execution, issue a "resetctx" command, to
2692| return to the original execution context.
2693end
2694
2695define switchtoctx
2696 select 0
b0d623f7 2697 if ($kgm_mtype == $kgm_mtype_ppc)
9bccf70c 2698 if ($kdp_act_counter == 0)
6d2010ae 2699 set $kdpstate = (struct savearea *) kdp.saved_state
9bccf70c
A
2700 end
2701 set $kdp_act_counter = $kdp_act_counter + 1
2702 set (struct savearea *) kdp.saved_state=(struct savearea *) $arg0
0c530ab8
A
2703 flushregs
2704 flushstack
9bccf70c
A
2705 set $pc=((struct savearea *) $arg0)->save_srr0
2706 update
2d21ac55 2707 else
b0d623f7 2708 if ($kgm_mtype == $kgm_mtype_arm)
6d2010ae
A
2709 select 0
2710 set $kdp_arm_act_counter = $kdp_arm_act_counter + 1
2711 if ($kdp_arm_act_counter == 1)
2712 set $r0_save = $r0
2713 set $r1_save = $r1
2714 set $r2_save = $r2
2715 set $r3_save = $r3
2716 set $r4_save = $r4
2717 set $r5_save = $r5
2718 set $r6_save = $r6
2719 set $r7_save = $r7
2720 set $r8_save = $r8
2721 set $r9_save = $r9
2722 set $r10_save = $r10
2723 set $r11_save = $r11
2724 set $r12_save = $r12
2725 set $sp_save = $sp
2726 set $lr_save = $lr
2727 set $pc_save = $pc
2728 end
2d21ac55
A
2729 set $kgm_statep = (struct arm_saved_state *)$arg0
2730 set $r0 = $kgm_statep->r[0]
2731 set $r1 = $kgm_statep->r[1]
2732 set $r2 = $kgm_statep->r[2]
2733 set $r3 = $kgm_statep->r[3]
2734 set $r4 = $kgm_statep->r[4]
2735 set $r5 = $kgm_statep->r[5]
2736 set $r6 = $kgm_statep->r[6]
2737 set $r8 = $kgm_statep->r[8]
2738 set $r9 = $kgm_statep->r[9]
2739 set $r10 = $kgm_statep->r[10]
2740 set $r11 = $kgm_statep->r[11]
2741 set $r12 = $kgm_statep->r[12]
2742 set $sp = $kgm_statep->sp
2743 set $lr = $kgm_statep->lr
2744 set $r7 = $kgm_statep->r[7]
2745 set $pc = $kgm_statep->pc
2746 flushregs
2747 flushstack
2748 update
9bccf70c
A
2749 else
2750 echo switchtoctx not implemented for this architecture.\n
2751 end
2752end
2753
2754document switchtoctx
2755Syntax: switchtoctx <address of pcb>
2756| This command allows gdb to examine an execution context and dump the
2757| backtrace for this execution context.
2758| Before resuming execution, issue a "resetctx" command, to
2759| return to the original execution context.
2760end
2761
2762define resetctx
2d21ac55
A
2763 select 0
2764 if ($kdp_act_counter != 0)
6d2010ae
A
2765 if ($kgm_mtype == $kgm_mtype_ppc)
2766 set (struct savearea *)kdp.saved_state=$kdpstate
2767 flushregs
2768 flushstack
2769 set $pc=((struct savearea *) kdp.saved_state)->save_srr0
2770 update
2771 set $kdp_act_counter = 0
2772 end
2773 if ($kgm_mtype == $kgm_mtype_i386)
2774 set $kdpstatep = (struct x86_saved_state32 *) kdp.saved_state
2775 set *($kdpstatep)=$kdpstate
2776 flushregs
2777 flushstack
2778 set $pc=$kdpstatep->eip
2779 update
2780 set $kdp_act_counter = 0
2781 end
2782 if ($kgm_mtype == $kgm_mtype_x86_64)
2783 set $kdpstatep = (struct x86_saved_state64 *) kdp.saved_state
2784 set *($kdpstatep)=$kdpstate
2785 flushregs
2786 flushstack
2787 set $pc=$kdpstatep->isf.rip
2788 update
2789 set $kdp_act_counter = 0
2790 end
2791 showcontext_int
2792 end
2793 if ($kgm_mtype == $kgm_mtype_arm && $kdp_arm_act_counter != 0)
2794 echo Restoring context\n
2d21ac55
A
2795 set $r0 = $r0_save
2796 flushregs
2797 set $r1 = $r1_save
2798 flushregs
2799 set $r2 = $r2_save
2800 flushregs
2801 set $r3 = $r3_save
2802 flushregs
2803 set $r4 = $r4_save
2804 flushregs
2805 set $r5 = $r5_save
2806 flushregs
2807 set $r6 = $r6_save
2808 flushregs
2809 set $r8 = $r8_save
2810 flushregs
2811 set $r9 = $r9_save
2812 flushregs
2813 set $r10 = $r10_save
2814 flushregs
2815 set $r11 = $r11_save
2816 flushregs
2817 set $r12 = $r12_save
2818 flushregs
2819 set $sp = $sp_save
2820 flushregs
2821 set $lr = $lr_save
2822 flushregs
2823 set $pc = $pc_save
2824 flushregs
2825 set $r7 = $r7_save
2826 flushregs
6d2010ae
A
2827 flushstack
2828 update
2829 set $kdp_arm_act_counter = 0
2d21ac55 2830 end
9bccf70c
A
2831end
2832
2833document resetctx
2834| Syntax: resetctx
2835| Returns to the original execution context. This command should be
2836| issued if you wish to resume execution after using the "switchtoact"
2837| or "switchtoctx" commands.
2838end
2839
2d21ac55
A
2840# This is a pre-hook for the continue command, to prevent inadvertent attempts
2841# to resume from the context switched to for examination.
2842define hook-continue
2843 resetctx
2844end
2845
2846# This is a pre-hook for the detach command, to prevent inadvertent attempts
2847# to resume from the context switched to for examination.
2848define hook-detach
2849 resetctx
2850end
2851
55e303ae 2852define resume_on
7e4a7d39
A
2853 set $resume = KDP_DUMPINFO_SETINFO | KDP_DUMPINFO_RESUME
2854 dumpinfoint $resume
55e303ae
A
2855end
2856
2857document resume_on
2858| Syntax: resume_on
2859| The target system will resume when detaching or exiting from gdb.
2860| This is the default behavior.
2861end
2862
2863define resume_off
7e4a7d39
A
2864 set $noresume = KDP_DUMPINFO_SETINFO | KDP_DUMPINFO_NORESUME
2865 dumpinfoint $noresume
55e303ae
A
2866end
2867
2868document resume_off
2869| Syntax: resume_off
2870| The target system won't resume after detaching from gdb and
2871| can be attached with a new gdb session
2872end
2873
9bccf70c
A
2874define paniclog
2875 set $kgm_panic_bufptr = debug_buf
55e303ae
A
2876 set $kgm_panic_bufptr_max = debug_buf_ptr
2877 while $kgm_panic_bufptr < $kgm_panic_bufptr_max
9bccf70c
A
2878 if *(char *)$kgm_panic_bufptr == 10
2879 printf "\n"
2880 else
b0d623f7 2881 printf "%c", *(char *)$kgm_panic_bufptr
9bccf70c
A
2882 end
2883 set $kgm_panic_bufptr= (char *)$kgm_panic_bufptr + 1
2884 end
2885end
2886
2887document paniclog
2888| Syntax: paniclog
2889| Display the panic log information
2890|
2891end
55e303ae
A
2892
2893define dumpcallqueue
b0d623f7
A
2894 set $kgm_callhead = $arg0
2895 set $kgm_callentry = $kgm_callhead->next
55e303ae 2896 set $kgm_i = 0
b0d623f7
A
2897 while $kgm_callentry != $kgm_callhead
2898 set $kgm_call = (struct call_entry *)$kgm_callentry
55e303ae
A
2899 printf "0x%08x ", $kgm_call
2900 printf "0x%08x 0x%08x ", $kgm_call->param0, $kgm_call->param1
55e303ae
A
2901 output $kgm_call->deadline
2902 printf "\t"
2903 output $kgm_call->func
2904 printf "\n"
2905 set $kgm_i = $kgm_i + 1
b0d623f7 2906 set $kgm_callentry = $kgm_callentry->next
55e303ae
A
2907 end
2908 printf "%d entries\n", $kgm_i
2909end
2910
2911document dumpcallqueue
2912| Syntax: dumpcallqueue <queue head>
2913| Displays the contents of the specified call_entry queue.
2914end
2915
2916define showtaskacts
2917showtaskthreads $arg0
2918end
2919document showtaskacts
2920| See help showtaskthreads.
2921end
2922
2923define showallacts
2924showallthreads
2925end
2926document showallacts
2927| See help showallthreads.
2928end
91447636
A
2929
2930
2931define resetstacks
2932 _kgm_flush_loop
2933 set kdp_pmap = 0
2934 _kgm_flush_loop
2935 resetctx
2936 _kgm_flush_loop
2937 _kgm_update_loop
2938 resetctx
2939 _kgm_update_loop
2940end
2941
2942document resetstacks
2943| Syntax: resetstacks
2944| Internal kgmacro routine used by the "showuserstack" macro
2945| to reset the target pmap to the kernel pmap.
2946end
2947
2948#Barely effective hacks to work around bugs in the "flush" and "update"
2949#gdb commands in Tiger (up to 219); these aren't necessary with Panther
2950#gdb, but do no harm.
2951define _kgm_flush_loop
2952 set $kgm_flush_loop_ctr = 0
2953 while ($kgm_flush_loop_ctr < 30)
0c530ab8
A
2954 flushregs
2955 flushstack
91447636
A
2956 set $kgm_flush_loop_ctr = $kgm_flush_loop_ctr + 1
2957 end
2958end
2959
2960define _kgm_update_loop
2961 set $kgm_update_loop_ctr = 0
2962 while ($kgm_update_loop_ctr < 30)
2963 update
2964 set $kgm_update_loop_ctr = $kgm_update_loop_ctr + 1
2965 end
2966end
b0d623f7
A
2967# Internal routine used by "_loadfrom" to read from 64-bit addresses
2968# on 32-bit kernels
2969define _loadk32m64
2970 # set up the manual KDP packet
2971 set manual_pkt.input = 0
2972 set manual_pkt.len = sizeof(kdp_readmem64_req_t)
2973 set $kgm_pkt = (kdp_readmem64_req_t *)&manual_pkt.data
2974 set $kgm_pkt->hdr.request = KDP_READMEM64
2975 set $kgm_pkt->hdr.len = sizeof(kdp_readmem64_req_t)
2976 set $kgm_pkt->hdr.is_reply = 0
2977 set $kgm_pkt->hdr.seq = 0
2978 set $kgm_pkt->hdr.key = 0
2979 set $kgm_pkt->address = (uint64_t)$arg0
2980 set $kgm_pkt->nbytes = sizeof(uint64_t)
2981 set manual_pkt.input = 1
2982 # dummy to make sure manual packet is executed
2983 set $kgm_dummy = &_mh_execute_header
2984 set $kgm_pkt = (kdp_readmem64_reply_t *)&manual_pkt.data
2985 if ($kgm_pkt->error == 0)
2986 set $kgm_k32read64 = *(uint64_t *)$kgm_pkt->data
2987 else
2988 set $kgm_k32read64 = 0
2989 end
2990end
2991
2992# Internal routine used by "showx86backtrace" to abstract possible loads from
2993# user space
2994define _loadfrom
2995 if (kdp_pmap == 0)
2996 set $kgm_loadval = *(uintptr_t *)$arg0
2997 else
2998 if ($kgm_x86_abi == 0xe)
2999 set $kgm_loadval = *(uint32_t *)$arg0
3000 else
3001 if ($kgm_x86_abi == 0xf)
3002 if ($kgm_mtype == $kgm_mtype_i386)
3003 _loadk32m64 $arg0
3004 set $kgm_loadval = $kgm_k32read64
3005 else
3006 set $kgm_loadval = *(uint64_t *)$arg0
3007 end
3008 end
3009 end
3010end
3011end
3012
91447636 3013
0c530ab8
A
3014#This is necessary since gdb often doesn't do backtraces on x86 correctly
3015#in the absence of symbols.The code below in showuserstack and
3016#showx86backtrace also contains several workarouds for the gdb bug where
3017#gdb stops macro evaluation because of spurious "Cannot read memory"
3018#errors on x86. These errors appear on ppc as well, but they don't
3019#always stop macro evaluation.
3020
b0d623f7
A
3021set $kgm_cur_frame = 0
3022set $kgm_cur_pc = 0
3023set $kgm_x86_abi = 0
0c530ab8 3024define showx86backtrace
b0d623f7
A
3025 if ($kgm_mtype == $kgm_mtype_i386)
3026 set $kgm_frame_reg = $ebp
3027 set $kgm_pc = $eip
3028 set $kgm_ret_off = 4
3029 end
3030 if ($kgm_mtype == $kgm_mtype_x86_64)
3031 set $kgm_frame_reg = $rbp
3032 set $kgm_pc = $rip
3033 set $kgm_ret_off = 8
3034 end
3035
3036 if ($kgm_x86_abi == 0xe)
3037 set $kgm_ret_off = 4
3038 end
3039 if ($kgm_x86_abi == 0xf)
3040 set $kgm_ret_off = 8
3041 end
3042
3043 if ($kgm_cur_frame == 0)
3044 set $kgm_cur_frame = $kgm_frame_reg
3045 end
3046 if ($kgm_cur_pc == 0)
3047 set $kgm_cur_pc = $kgm_pc
3048 end
3049 printf "0: Frame: 0x%016llx PC: 0x%016llx\n", $kgm_cur_frame, $kgm_cur_pc
3050 if (!(($kgm_x86_abi == 0xf) && ($kgm_mtype == $kgm_mtype_i386)))
3051 x/i $kgm_cur_pc
3052 end
3053 set $kgm_tmp_frame = $kgm_cur_frame
3054 set $kgm_cur_frame = 0
3055 set $kgm_cur_pc = 0
3056 _loadfrom ($kgm_tmp_frame)
3057 set $kgm_prev_frame = $kgm_loadval
3058 _loadfrom ($kgm_tmp_frame+$kgm_ret_off)
3059 set $kgm_prev_pc = $kgm_loadval
0c530ab8 3060 set $kgm_frameno = 1
6d2010ae 3061 while ($kgm_prev_frame != 0) && ($kgm_prev_frame != 0x0000000800000008)
b0d623f7
A
3062 printf "%d: Saved frame: 0x%016llx Saved PC: 0x%016llx\n", $kgm_frameno, $kgm_prev_frame, $kgm_prev_pc
3063 if (!(($kgm_x86_abi == 0xf) && ($kgm_mtype == $kgm_mtype_i386)))
3064 x/i $kgm_prev_pc
3065 end
3066 _loadfrom ($kgm_prev_frame+$kgm_ret_off)
3067 set $kgm_prev_pc = $kgm_loadval
3068 _loadfrom ($kgm_prev_frame)
3069 set $kgm_prev_frame = $kgm_loadval
0c530ab8
A
3070 set $kgm_frameno = $kgm_frameno + 1
3071 end
0c530ab8 3072 set kdp_pmap = 0
b0d623f7
A
3073 set $kgm_x86_abi = 0
3074end
3075
3076define showx86backtrace2
3077 set $kgm_cur_frame = $arg0
3078 set $kgm_cur_pc = $arg1
3079 showx86backtrace
0c530ab8
A
3080end
3081
91447636 3082define showuserstack
2d21ac55 3083 select 0
b0d623f7 3084 if ($kgm_mtype == $kgm_mtype_ppc)
91447636
A
3085 if ($kdp_act_counter == 0)
3086 set $kdpstate = (struct savearea *) kdp.saved_state
3087 end
3088 set $kdp_act_counter = $kdp_act_counter + 1
3089 set $newact = (struct thread *) $arg0
3090 _kgm_flush_loop
3091 set $checkpc = $newact->machine->upcb.save_srr0
3092 if ($checkpc == 0)
3093 echo This activation does not appear to have
3094 echo \20 a valid user context.\n
3095 else
3096 set (struct savearea *) kdp.saved_state=$newact->machine->upcb
3097 set $pc = $checkpc
3098#flush and update seem to be executed lazily by gdb on Tiger, hence the
3099#repeated invocations - see 3743135
3100 _kgm_flush_loop
3101# This works because the new pmap is used only for reads
3102 set kdp_pmap = $newact->task->map->pmap
3103 _kgm_flush_loop
3104 _kgm_update_loop
3105 bt
3106 resetstacks
3107 _kgm_flush_loop
3108 _kgm_update_loop
3109 resetstacks
3110 _kgm_flush_loop
3111 _kgm_update_loop
3112 end
3113 else
b0d623f7 3114 if (($kgm_mtype & $kgm_mtype_x86_mask) == $kgm_mtype_x86_any)
0c530ab8 3115 set $newact = (struct thread *) $arg0
6d2010ae 3116 set $newiss = (x86_saved_state_t *) ($newact->machine->iss)
b0d623f7
A
3117 set $kgm_x86_abi = $newiss.flavor
3118 if ($newiss.flavor == 0xf)
3119 set $checkpc = $newiss.uss.ss_64.isf.rip
3120 set $checkframe = $newiss.uss.ss_64.rbp
3121
3122 else
3123 set $checkpc = $newiss.uss.ss_32.eip
3124 set $checkframe = $newiss.uss.ss_32.ebp
3125 end
3126
0c530ab8
A
3127 if ($checkpc == 0)
3128 echo This activation does not appear to have
3129 echo \20 a valid user context.\n
3130 else
b0d623f7
A
3131 set $kgm_cur_frame = $checkframe
3132 set $kgm_cur_pc = $checkpc
6d2010ae
A
3133# When have more than one argument is present, don't print usage
3134 if ( $argc == 1 )
3135 printf "You may now issue the showx86backtrace command to see the user space backtrace for this thread ("
3136 showptr $arg0
3137 printf "); you can also examine memory locations in this address space (pmap "
3138 showptr $newact->task->map->pmap
3139 printf ") before issuing the backtrace. This two-step process is necessary to work around various bugs in x86 gdb, which cause it to stop memory evaluation on spurious memory read errors. Additionally, you may need to issue a set kdp_pmap = 0 command after the showx86backtrace completes, to resume reading from the kernel address space.\n"
3140 end
0c530ab8
A
3141 set kdp_pmap = $newact->task->map->pmap
3142 _kgm_flush_loop
3143 _kgm_update_loop
3144 end
6d2010ae
A
3145 else
3146 if ($kgm_mtype == $kgm_mtype_arm)
3147 if (kdp->is_conn > 0)
3148 set $kgm_threadp = (struct thread *)$arg0
3149 set $kgm_saved_pmap = kdp_pmap
3150 showactheader
3151 showactint $kgm_threadp 0
3152 set $kgm_thread_pmap = $kgm_threadp->task->map->pmap
3153 set $kgm_thread_sp = $kgm_threadp.machine->PcbData.r[7]
3154 set kdp_pmap = $kgm_thread_pmap
3155 while ($kgm_thread_sp != 0)
3156 set $link_register = *($kgm_thread_sp + 4)
3157 showptrhdrpad
3158 printf " "
3159 showptr $kgm_thread_sp
3160 printf " "
3161 showptr $link_register
3162 printf "\n"
3163 set $kgm_thread_sp = *$kgm_thread_sp
3164 end
3165 set kdp_pmap = $kgm_saved_pmap
3166 else
3167 echo You must be connected via nanokdp to use this macro\n
3168 end
593a1d5f
A
3169 else
3170 echo showuserstack not supported on this architecture\n
3171 end
0c530ab8 3172 end
6d2010ae 3173 end
91447636 3174end
91447636
A
3175document showuserstack
3176Syntax: showuserstack <address of thread activation>
3177|This command displays a numeric backtrace for the user space stack of
3178|the given thread activation. It may, of course, fail to display a
3179|complete backtrace if portions of the user stack are not mapped in.
3180|Symbolic backtraces can be obtained either by running gdb on the
3181|user space binary, or a tool such as "symbolicate".
3182|Note that while this command works on Panther's gdb, an issue
3183|with Tiger gdb (3743135) appears to hamper the evaluation of this
3184|macro in some cases.
3185end
3186
6d2010ae
A
3187define showtaskuserstacks
3188 set $kgm_taskp = (struct task *)$arg0
3189 set $kgm_head_actp = &($kgm_taskp->threads)
3190 set $kgm_actp = (struct thread *)($kgm_taskp->threads.next)
3191 while $kgm_actp != $kgm_head_actp
3192 printf "For thread "
3193 showptr $kgm_actp
3194 printf "\n"
3195 showuserstack $kgm_actp quiet
3196 if (($kgm_mtype & $kgm_mtype_x86_mask) == $kgm_mtype_x86_any)
3197 showx86backtrace
3198 end
3199 set kdp_pmap=0
3200 set $kgm_actp = (struct thread *)($kgm_actp->task_threads.next)
3201 printf "\n"
3202 end
3203 showuserlibraries $kgm_taskp
3204end
3205document showtaskuserstacks
3206Syntax: (gdb) showtaskuserstacks <task>
3207| Print out the user stack for each thread in a task, followed by the user libraries.
3208end
3209
3210
3211define showuserregisters
3212 set $kgm_threadp = (struct thread *)$arg0
3213 set $kgm_taskp = $kgm_threadp->task
3214 if (($kgm_mtype & $kgm_mtype_x86_mask) == $kgm_mtype_x86_any)
3215 set $newiss = (x86_saved_state_t *) ($kgm_threadp->machine.iss)
3216 set $kgm_x86_abi = $newiss.flavor
3217 if ($newiss.flavor == 0xf)
3218 printf "X86 Thread State (64-bit):\n"
3219 set $kgm_ss64 = $newiss.uss.ss_64
3220
3221 printf " rax: "
3222 showuserptr $kgm_ss64.rax
3223 printf " rbx: "
3224 showuserptr $kgm_ss64.rbx
3225 printf " rcx: "
3226 showuserptr $kgm_ss64.rcx
3227 printf " rdx: "
3228 showuserptr $kgm_ss64.rdx
3229 printf "\n"
3230
3231 printf " rdi: "
3232 showuserptr $kgm_ss64.rdi
3233 printf " rsi: "
3234 showuserptr $kgm_ss64.rsi
3235 printf " rbp: "
3236 showuserptr $kgm_ss64.rbp
3237 printf " rsp: "
3238 showuserptr $kgm_ss64.isf.rsp
3239 printf "\n"
3240
3241 printf " r8: "
3242 showuserptr $kgm_ss64.r8
3243 printf " r9: "
3244 showuserptr $kgm_ss64.r9
3245 printf " r10: "
3246 showuserptr $kgm_ss64.r10
3247 printf " r11: "
3248 showuserptr $kgm_ss64.r11
3249 printf "\n"
3250
3251 printf " r12: "
3252 showuserptr $kgm_ss64.r12
3253 printf " r13: "
3254 showuserptr $kgm_ss64.r13
3255 printf " r14: "
3256 showuserptr $kgm_ss64.r14
3257 printf " r15: "
3258 showuserptr $kgm_ss64.r15
3259 printf "\n"
3260
3261 printf " rip: "
3262 showuserptr $kgm_ss64.isf.rip
3263 printf " rfl: "
3264 showuserptr $kgm_ss64.isf.rflags
3265 printf " cr2: "
3266 showuserptr $kgm_ss64.cr2
3267 printf "\n"
3268 else
3269 printf "X86 Thread State (32-bit):\n"
3270 set $kgm_ss32 = $newiss.uss.ss_32
3271
3272 printf " eax: "
3273 showuserptr $kgm_ss32.eax
3274 printf " ebx: "
3275 showuserptr $kgm_ss32.ebx
3276 printf " ecx: "
3277 showuserptr $kgm_ss32.ecx
3278 printf " edx: "
3279 showuserptr $kgm_ss32.edx
3280 printf "\n"
3281
3282 printf " edi: "
3283 showuserptr $kgm_ss32.edi
3284 printf " esi: "
3285 showuserptr $kgm_ss32.esi
3286 printf " ebp: "
3287 showuserptr $kgm_ss32.ebp
3288 printf " esp: "
3289 showuserptr $kgm_ss32.uesp
3290 printf "\n"
3291
3292 printf " ss: "
3293 showuserptr $kgm_ss32.ss
3294 printf " efl: "
3295 showuserptr $kgm_ss32.efl
3296 printf " eip: "
3297 showuserptr $kgm_ss32.eip
3298 printf " cs: "
3299 showuserptr $kgm_ss32.cs
3300 printf "\n"
3301
3302 printf " ds: "
3303 showuserptr $kgm_ss32.ds
3304 printf " es: "
3305 showuserptr $kgm_ss32.es
3306 printf " fs: "
3307 showuserptr $kgm_ss32.fs
3308 printf " gs: "
3309 showuserptr $kgm_ss32.gs
3310 printf "\n"
3311
3312 printf " cr2: "
3313 showuserptr $kgm_ss32.cr2
3314 printf "\n"
3315 end
3316 else
3317 if ($kgm_mtype == $kgm_mtype_arm)
3318 printf "ARM Thread State:\n"
3319 set $kgm_pcb = (arm_saved_state_t *) ($kgm_threadp->machine.upcb)
3320
3321 printf " r0: "
3322 showuserptr $kgm_pcb.r[0]
3323 printf " r1: "
3324 showuserptr $kgm_pcb.r[1]
3325 printf " r2: "
3326 showuserptr $kgm_pcb.r[2]
3327 printf " r3: "
3328 showuserptr $kgm_pcb.r[3]
3329 printf "\n"
3330
3331 printf " r4: "
3332 showuserptr $kgm_pcb.r[4]
3333 printf " r5: "
3334 showuserptr $kgm_pcb.r[5]
3335 printf " r6: "
3336 showuserptr $kgm_pcb.r[6]
3337 printf " r7: "
3338 showuserptr $kgm_pcb.r[7]
3339 printf "\n"
3340
3341 printf " r8: "
3342 showuserptr $kgm_pcb.r[8]
3343 printf " r9: "
3344 showuserptr $kgm_pcb.r[9]
3345 printf " r10: "
3346 showuserptr $kgm_pcb.r[10]
3347 printf " r11: "
3348 showuserptr $kgm_pcb.r[11]
3349 printf "\n"
3350
3351 printf " ip: "
3352 showuserptr $kgm_pcb.r[12]
3353 printf " sp: "
3354 showuserptr $kgm_pcb.sp
3355 printf " lr: "
3356 showuserptr $kgm_pcb.lr
3357 printf " pc: "
3358 showuserptr $kgm_pcb.pc
3359 printf "\n"
3360
3361 printf " cpsr: "
3362 showuserptr $kgm_pcb.cpsr
3363 printf "\n"
3364 else
3365 echo showuserregisters not supported on this architecture\n
3366 end
3367 end
3368end
3369document showuserregisters
3370Syntax: showuserstack <address of thread>
3371|This command displays the last known user register state
3372|for the thread. This map not be correct for cases where
3373|the thread is currently executing in userspace. However
3374|for threads that have entered the kernel (either explicitly
3375|with a system call or implicitly with a fault), it should
3376|be accurate
3377end
3378
3379define showtaskuserregisters
3380 set $kgm_taskp = (struct task *)$arg0
3381 set $kgm_head_actp = &($kgm_taskp->threads)
3382 set $kgm_actp = (struct thread *)($kgm_taskp->threads.next)
3383 while $kgm_actp != $kgm_head_actp
3384 printf "For thread "
3385 showptr $kgm_actp
3386 printf "\n"
3387 showuserregisters $kgm_actp
3388 set $kgm_actp = (struct thread *)($kgm_actp->task_threads.next)
3389 printf "\n"
3390 end
3391end
3392document showtaskuserregisters
3393Syntax: (gdb) showtaskuserregisters <task>
3394| Print out the user registers for each thread in a task
3395end
3396
91447636 3397define kdp-reboot
7e4a7d39
A
3398# Alternatively, set *(*(unsigned **) 0x2498) = 1
3399# (or 0x5498 on PPC, 0xffffff8000002928 on x86_64, 0xffff049c on arm)
3400 manualhdrint $kgm_kdp_pkt_hostreboot
91447636
A
3401 continue
3402end
3403
3404document kdp-reboot
3405Syntax: kdp-reboot
7e4a7d39
A
3406|Reboot the remote target machine; not guaranteed to succeed.
3407end
3408
3409define kdpversionint
3410 # set up the manual KDP packet
3411 set manual_pkt.input = 0
3412 set manual_pkt.len = sizeof(kdp_version_req_t)
3413 set $kgm_pkt = (kdp_version_req_t *)&manual_pkt.data
3414 set $kgm_pkt->hdr.request = KDP_VERSION
3415 set $kgm_pkt->hdr.len = sizeof(kdp_version_req_t)
3416 set $kgm_pkt->hdr.is_reply = 0
3417 set $kgm_pkt->hdr.seq = 0
3418 set $kgm_pkt->hdr.key = 0
3419 set manual_pkt.input = 1
3420 # dummy to make sure manual packet is executed
3421 set $kgm_dummy = &_mh_execute_header
3422 set $kgm_pkt = (kdp_version_reply_t *)&manual_pkt.data
3423 set $kgm_kdp_version = $kgm_pkt->version
3424 set $kgm_kdp_feature = $kgm_pkt->feature
3425end
3426
3427define kdp-version
3428 kdpversionint
3429 printf "KDP VERSION = %d, FEATURE = 0x%x\n", $kgm_kdp_version, $kgm_kdp_feature
3430end
3431
3432document kdp-version
3433Syntax: kdp-version
3434|Get the KDP protocol version being used by the kernel.
3435end
3436
3437define dumpinfoint
3438 # set up the manual KDP packet
3439 set manual_pkt.input = 0
3440
3441 set manual_pkt.len = sizeof(kdp_dumpinfo_req_t)
6d2010ae 3442 set $kgm_pkt = (kdp_dumpinfo_req_t *)&manual_pkt.data
7e4a7d39
A
3443 set $kgm_pkt->hdr.request = KDP_DUMPINFO
3444 set $kgm_pkt->hdr.len = sizeof(kdp_dumpinfo_req_t)
3445 set $kgm_pkt->hdr.is_reply = 0
3446 set $kgm_pkt->hdr.seq = 0
3447 set $kgm_pkt->hdr.key = 0
3448 set $kgm_pkt->type = $arg0
3449 set $kgm_pkt->name = ""
3450 set $kgm_pkt->destip = ""
3451 set $kgm_pkt->routerip = ""
3452 set $kgm_pkt->port = 0
3453
3454 if $argc > 1
3455 set $kgm_pkt->name = "$arg1"
3456 end
3457 if $argc > 2
3458 set $kgm_pkt->destip = "$arg2"
3459 end
3460 if $argc > 3
3461 set $kgm_pkt->routerip = "$arg3"
3462 end
3463 if $argc > 4
3464 set $kgm_pkt->port = $arg4
3465 end
3466
3467 set manual_pkt.input = 1
3468 # dummy to make sure manual packet is executed
3469 set $kgm_dummy = &_mh_execute_header
91447636
A
3470end
3471
3472define sendcore
7e4a7d39
A
3473 if $argc > 1
3474 dumpinfoint KDP_DUMPINFO_CORE $arg1 $arg0
3475 else
3476 dumpinfoint KDP_DUMPINFO_CORE \0 $arg0
3477 end
91447636
A
3478end
3479
3480document sendcore
7e4a7d39 3481Syntax: sendcore <IP address> [filename]
91447636
A
3482|Configure the kernel to transmit a kernel coredump to a server (kdumpd)
3483|at the specified IP address. This is useful when the remote target has
3484|not been previously configured to transmit coredumps, and you wish to
3485|preserve kernel state for later examination. NOTE: You must issue a "continue"
3486|command after using this macro to trigger the kernel coredump. The kernel
3487|will resume waiting in the debugger after completion of the coredump. You
7e4a7d39
A
3488|may disable coredumps by executing the "disablecore" macro. You can
3489|optionally specify the filename to be used for the generated core file.
3490end
3491
3492define sendsyslog
3493 if $argc > 1
3494 dumpinfoint KDP_DUMPINFO_SYSTEMLOG $arg1 $arg0
3495 else
3496 dumpinfoint KDP_DUMPINFO_SYSTEMLOG \0 $arg0
3497 end
3498end
3499
3500document sendsyslog
3501Syntax: sendsyslog <IP address> [filename]
3502|Configure the kernel to transmit a kernel system log to a server (kdumpd)
3503|at the specified IP address. NOTE: You must issue a "continue"
3504|command after using this macro to trigger the kernel system log. The kernel
3505|will resume waiting in the debugger after completion. You can optionally
3506|specify the name to be used for the generated system log.
3507end
3508
3509define sendpaniclog
3510 if panicstr
3511 if $argc > 1
3512 dumpinfoint KDP_DUMPINFO_PANICLOG $arg1 $arg0
3513 else
3514 dumpinfoint KDP_DUMPINFO_PANICLOG \0 $arg0
3515 end
3516 else
3517 printf "No panic log available.\n"
3518 end
3519end
3520
3521document sendpaniclog
3522Syntax: sendpaniclog <IP address> [filename]
3523|Configure the kernel to transmit a kernel paniclog to a server (kdumpd)
3524|at the specified IP address. NOTE: You must issue a "continue"
3525|command after using this macro to trigger the kernel panic log. The kernel
3526|will resume waiting in the debugger after completion. You can optionally
3527|specify the name to be used for the generated panic log.
3528end
3529
3530define getdumpinfo
3531 dumpinfoint KDP_DUMPINFO_GETINFO
3532 set $kgm_dumpinfo = (kdp_dumpinfo_reply_t *) manual_pkt.data
3533 if $kgm_dumpinfo->type & KDP_DUMPINFO_REBOOT
6d2010ae 3534 printf "Sysem will reboot after kernel info gets dumped.\n"
7e4a7d39
A
3535 else
3536 printf "Sysem will not reboot after kernel info gets dumped.\n"
3537 end
3538 if $kgm_dumpinfo->type & KDP_DUMPINFO_NORESUME
3539 printf "System will allow a re-attach after a KDP disconnect.\n"
3540 else
3541 printf "System will resume after a KDP disconnect.\n"
3542 end
3543 set $kgm_dumpinfo_type = $kgm_dumpinfo->type & KDP_DUMPINFO_MASK
3544 if $kgm_dumpinfo_type == KDP_DUMPINFO_DISABLE
3545 printf "Kernel not setup for remote dumps.\n"
3546 else
3547 printf "Remote dump type: "
3548 if $kgm_dumpinfo_type == KDP_DUMPINFO_CORE
3549 printf "Core file\n"
3550 end
3551 if $kgm_dumpinfo_type == KDP_DUMPINFO_PANICLOG
3552 printf "Panic log\n"
3553 end
3554 if $kgm_dumpinfo_type == KDP_DUMPINFO_SYSTEMLOG
3555 printf "System log\n"
3556 end
3557
3558 printf "Name: "
3559 if $kgm_dumpinfo->name[0] == '\0'
3560 printf "(autogenerated)\n"
3561 else
3562 printf "%s\n", $kgm_dumpinfo->name
3563 end
3564
3565 printf "Network Info: %s[%d] ", $kgm_dumpinfo->destip, $kgm_dumpinfo->port
3566 if $kgm_dumpinfo->routerip[0] == '\0'
3567 printf "\n"
3568 else
3569 printf "Router: %s\n", $kgm_dumpinfo->routerip
3570 end
3571 end
3572end
3573
3574document getdumpinfo
3575Syntax: getdumpinfo
3576|Retrieve the current remote dump settings.
3577end
3578
3579define setdumpinfo
3580 dumpinfoint KDP_DUMPINFO_SETINFO $arg0 $arg1 $arg2 $arg3
3581end
3582
3583document setdumpinfo
3584Syntax: setdumpinfo <filename> <ip> <router> <port>
3585|Configure the current remote dump settings. Specify \0 if you
3586|want to use the defaults (filename) or previously configured
3587|settings (ip/router). Specify 0 for the port if you wish to
3588|use the previously configured/default setting for that.
91447636
A
3589end
3590
3591define disablecore
7e4a7d39 3592 dumpinfoint KDP_DUMPINFO_DISABLE
91447636
A
3593end
3594
3595document disablecore
3596Syntax: disablecore
3597|Reconfigures the kernel so that it no longer transmits kernel coredumps. This
3598|complements the "sendcore" macro, but it may be used if the kernel has been
3599|configured to transmit coredumps through boot-args as well.
3600end
3601
91447636 3602define switchtocorethread
2d21ac55
A
3603 set $newact = (struct thread *) $arg0
3604 select 0
3605 if ($newact->kernel_stack == 0)
3606 echo This thread does not have a stack.\n
3607 echo continuation:
3608 output/a (unsigned) $newact.continuation
3609 echo \n
3610 else
b0d623f7 3611 if ($kgm_mtype == $kgm_mtype_ppc)
2d21ac55
A
3612 loadcontext $newact->machine->pcb
3613 flushstack
3614 set $pc = $newact->machine->pcb.save_srr0
91447636 3615 else
b0d623f7
A
3616 if (($kgm_mtype & $kgm_mtype_x86_mask) == $kgm_mtype_x86_any)
3617 set $kgm_cstatep = (struct x86_kernel_state *) \
3618 ($newact->kernel_stack + kernel_stack_size \
3619 - sizeof(struct x86_kernel_state))
2d21ac55
A
3620 loadcontext $kgm_cstatep
3621 flushstack
593a1d5f
A
3622 else
3623 echo switchtocorethread not supported on this architecture\n
3624 end
2d21ac55
A
3625 end
3626 showcontext_int
91447636
A
3627 end
3628end
3629
3630document switchtocorethread
3631Syntax: switchtocorethread <address of activation>
3632| The corefile equivalent of "switchtoact". When debugging a kernel coredump
3633| file, this command can be used to examine the execution context and stack
3634| trace for a given thread activation. For example, to view the backtrace
3635| for a thread issue "switchtocorethread <address>", followed by "bt".
3636| Before resuming execution, issue a "resetcorectx" command, to
3637| return to the original execution context. Note that this command
3638| requires gdb support, as documented in Radar 3401283.
3639end
3640
3641define loadcontext
2d21ac55 3642 select 0
b0d623f7 3643 if ($kgm_mtype == $kgm_mtype_ppc)
2d21ac55
A
3644 set $kgm_contextp = (struct savearea *) $arg0
3645 set $pc = $kgm_contextp.save_srr0
3646 set $r1 = $kgm_contextp.save_r1
3647 set $lr = $kgm_contextp.save_lr
3648
3649 set $r2 = $kgm_contextp.save_r2
3650 set $r3 = $kgm_contextp.save_r3
3651 set $r4 = $kgm_contextp.save_r4
3652 set $r5 = $kgm_contextp.save_r5
3653 set $r6 = $kgm_contextp.save_r6
3654 set $r7 = $kgm_contextp.save_r7
3655 set $r8 = $kgm_contextp.save_r8
3656 set $r9 = $kgm_contextp.save_r9
3657 set $r10 = $kgm_contextp.save_r10
3658 set $r11 = $kgm_contextp.save_r11
3659 set $r12 = $kgm_contextp.save_r12
3660 set $r13 = $kgm_contextp.save_r13
3661 set $r14 = $kgm_contextp.save_r14
3662 set $r15 = $kgm_contextp.save_r15
3663 set $r16 = $kgm_contextp.save_r16
3664 set $r17 = $kgm_contextp.save_r17
3665 set $r18 = $kgm_contextp.save_r18
3666 set $r19 = $kgm_contextp.save_r19
3667 set $r20 = $kgm_contextp.save_r20
3668 set $r21 = $kgm_contextp.save_r21
3669 set $r22 = $kgm_contextp.save_r22
3670 set $r23 = $kgm_contextp.save_r23
3671 set $r24 = $kgm_contextp.save_r24
3672 set $r25 = $kgm_contextp.save_r25
3673 set $r26 = $kgm_contextp.save_r26
3674 set $r27 = $kgm_contextp.save_r27
3675 set $r28 = $kgm_contextp.save_r28
3676 set $r29 = $kgm_contextp.save_r29
3677 set $r30 = $kgm_contextp.save_r30
3678 set $r31 = $kgm_contextp.save_r31
3679
3680 set $cr = $kgm_contextp.save_cr
3681 set $ctr = $kgm_contextp.save_ctr
3682 else
b0d623f7
A
3683 if ($kgm_mtype == $kgm_mtype_i386)
3684 set $kgm_contextp = (struct x86_kernel_state *) $arg0
2d21ac55
A
3685 set $ebx = $kgm_contextp->k_ebx
3686 set $ebp = $kgm_contextp->k_ebp
3687 set $edi = $kgm_contextp->k_edi
3688 set $esi = $kgm_contextp->k_esi
3689 set $eip = $kgm_contextp->k_eip
3690 set $pc = $kgm_contextp->k_eip
b0d623f7
A
3691 else
3692 if ($kgm_mtype == $kgm_mtype_x86_64)
3693 set $kgm_contextp = (struct x86_kernel_state *) $arg0
3694 set $rbx = $kgm_contextp->k_rbx
3695 set $rbp = $kgm_contextp->k_rbp
3696 set $r12 = $kgm_contextp->k_r12
3697 set $r13 = $kgm_contextp->k_r13
3698 set $r14 = $kgm_contextp->k_r14
3699 set $r15 = $kgm_contextp->k_r15
3700 set $rip = $kgm_contextp->k_rip
3701 set $pc = $kgm_contextp->k_rip
593a1d5f
A
3702 else
3703 echo loadcontext not supported on this architecture\n
3704 end
2d21ac55 3705 end
b0d623f7 3706 end
91447636
A
3707end
3708
3709define resetcorectx
2d21ac55 3710 select 0
b0d623f7 3711 if ($kgm_mtype == $kgm_mtype_ppc)
2d21ac55
A
3712 set $kgm_corecontext = (struct savearea *) kdp.saved_state
3713 loadcontext $kgm_corecontext
3714 else
b0d623f7 3715 if ($kgm_mtype == $kgm_mtype_i386)
2d21ac55
A
3716 set $kdpstatep = (struct x86_saved_state32 *) kdp.saved_state
3717 set $ebx = $kdpstatep->ebx
3718 set $ebp = $kdpstatep->ebp
3719 set $edi = $kdpstatep->edi
3720 set $esi = $kdpstatep->esi
3721 set $eip = $kdpstatep->eip
3722 set $eax = $kdpstatep->eax
3723 set $ecx = $kdpstatep->ecx
3724 set $edx = $kdpstatep->edx
3725 flushregs
3726 flushstack
3727 set $pc = $kdpstatep->eip
3728 update
593a1d5f
A
3729 else
3730 echo resetcorectx not supported on this architecture\n
2d21ac55
A
3731 end
3732 end
3733 showcontext_int
91447636
A
3734end
3735
3736document resetcorectx
3737Syntax: resetcorectx
3738| The corefile equivalent of "resetctx". Returns to the original
3739| execution context (that of the active thread at the time of the NMI or
3740| panic). This command should be issued if you wish to resume
3741| execution after using the "switchtocorethread" command.
3742end
3743
3744#Helper function for "showallgdbstacks"
3745
3746define showgdbthread
3747 printf " 0x%08x ", $arg0
3748 set $kgm_thread = *(struct thread *)$arg0
3749 printf "0x%08x ", $arg0
3750 printf "%3d ", $kgm_thread.sched_pri
3751 set $kgm_state = $kgm_thread.state
3752 if $kgm_state & 0x80
3753 printf "I"
3754 end
3755 if $kgm_state & 0x40
3756 printf "P"
3757 end
3758 if $kgm_state & 0x20
3759 printf "A"
3760 end
3761 if $kgm_state & 0x10
3762 printf "H"
3763 end
3764 if $kgm_state & 0x08
3765 printf "U"
3766 end
3767 if $kgm_state & 0x04
3768 printf "R"
3769 end
3770 if $kgm_state & 0x02
3771 printf "S"
3772 end
3773 if $kgm_state & 0x01
3774 printf "W\t"
3775 printf "0x%08x ", $kgm_thread.wait_queue
3776 output /a (unsigned) $kgm_thread.wait_event
2d21ac55
A
3777 if ($kgm_thread.uthread != 0)
3778 set $kgm_uthread = (struct uthread *)$kgm_thread.uthread
3779 if ($kgm_uthread->uu_wmesg != 0)
3780 printf " \"%s\"", $kgm_uthread->uu_wmesg
3781 end
3782 end
91447636
A
3783 end
3784 if $arg1 != 0
3785 if ($kgm_thread.kernel_stack != 0)
3786 if ($kgm_thread.reserved_stack != 0)
3787 printf "\n\t\treserved_stack=0x%08x", $kgm_thread.reserved_stack
3788 end
3789 printf "\n\t\tkernel_stack=0x%08x", $kgm_thread.kernel_stack
b0d623f7 3790 if ($kgm_mtype == $kgm_mtype_ppc)
91447636 3791 set $mysp = $kgm_thread.machine.pcb->save_r1
2d21ac55 3792 end
b0d623f7
A
3793 if ($kgm_mtype == $kgm_mtype_i386)
3794 set $kgm_statep = (struct x86_kernel_state *) \
3795 ($kgm_thread->kernel_stack + kernel_stack_size \
3796 - sizeof(struct x86_kernel_state))
91447636
A
3797 set $mysp = $kgm_statep->k_ebp
3798 end
b0d623f7
A
3799 if ($kgm_mtype == $kgm_mtype_arm)
3800 if (((unsigned long)$r7 < ((unsigned long) ($kgm_thread->kernel_stack+kernel_stack_size))) \
3801 && ((unsigned long)$r7 > (unsigned long) ($kgm_thread->kernel_stack)))
2d21ac55
A
3802 set $mysp = $r7
3803 else
3804 set $kgm_statep = (struct arm_saved_state *)$kgm_thread.machine.kstackptr
3805 set $mysp = $kgm_statep->r[7]
3806 end
3807 end
91447636
A
3808 set $prevsp = 0
3809 printf "\n\t\tstacktop=0x%08x", $mysp
2d21ac55
A
3810 if ($arg2 == 0)
3811 switchtoact $arg0
3812 else
3813 switchtocorethread $arg0
3814 end
91447636
A
3815 bt
3816 else
3817 printf "\n\t\t\tcontinuation="
3818 output /a (unsigned) $kgm_thread.continuation
3819 end
3820 printf "\n"
3821 else
3822 printf "\n"
3823 end
3824end
3825
3826#Use of this macro is currently (8/04) blocked by the fact that gdb
3827#stops evaluating macros when encountering an error, such as a failure
3828#to read memory from a certain location. Until this issue (described in
3829#3758949) is addressed, evaluation of this macro may stop upon
3830#encountering such an error.
3831
3832define showallgdbstacks
2d21ac55 3833 set $kgm_head_taskp = &tasks
91447636
A
3834 set $kgm_taskp = (struct task *)($kgm_head_taskp->next)
3835 while $kgm_taskp != $kgm_head_taskp
3836 showtaskheader
3837 showtaskint $kgm_taskp
3838 set $kgm_head_actp = &($kgm_taskp->threads)
3839 set $kgm_actp = (struct thread *)($kgm_taskp->threads.next)
3840 while $kgm_actp != $kgm_head_actp
3841 showactheader
2d21ac55 3842 showgdbthread $kgm_actp 1 0
91447636
A
3843 set $kgm_actp = (struct thread *)($kgm_actp->task_threads.next)
3844 end
3845 printf "\n"
2d21ac55 3846 set $kgm_taskp = (struct task *)($kgm_taskp->tasks.next)
91447636
A
3847 end
3848 resetctx
3849end
3850
3851document showallgdbstacks
3852Syntax: showallgdbstacks
3853| An alternative to "showallstacks". Iterates through the task list and
3854| displays a gdb generated backtrace for each kernel thread. It is
3855| advantageous in that it is much faster than "showallstacks", and
3856| decodes function call arguments and displays source level traces, but
3857| it has the drawback that it doesn't determine if frames belong to
3858| functions from kernel extensions, as with "showallstacks".
3859| This command may terminate prematurely because of a gdb bug
3860| (Radar 3758949), which stops macro evaluation on memory read
3861| errors.
3862end
3863
2d21ac55
A
3864define showallgdbcorestacks
3865 select 0
3866 set $kgm_head_taskp = &tasks
3867 set $kgm_taskp = (struct task *)($kgm_head_taskp->next)
3868 while $kgm_taskp != $kgm_head_taskp
3869 showtaskheader
3870 showtaskint $kgm_taskp
3871 set $kgm_head_actp = &($kgm_taskp->threads)
3872 set $kgm_actp = (struct thread *)($kgm_taskp->threads.next)
3873 while $kgm_actp != $kgm_head_actp
3874 showactheader
3875 showgdbthread $kgm_actp 1 1
3876 set $kgm_actp = (struct thread *)($kgm_actp->task_threads.next)
3877 end
3878 printf "\n"
3879 set $kgm_taskp = (struct task *)($kgm_taskp->tasks.next)
3880 end
3881 resetcorectx
3882end
3883
3884
3885document showallgdbcorestacks
3886Syntax: showallgdbcorestacks
3887|Corefile version of "showallgdbstacks"
3888end
3889
3890
91447636 3891define switchtouserthread
2d21ac55 3892 select 0
b0d623f7 3893 if ($kgm_mtype == $kgm_mtype_ppc)
91447636
A
3894 if ($kdp_act_counter == 0)
3895 set $kdpstate = (struct savearea *) kdp.saved_state
3896 end
3897 set $kdp_act_counter = $kdp_act_counter + 1
3898 set $newact = (struct thread *) $arg0
3899 _kgm_flush_loop
3900 set $checkpc = $newact->machine->upcb.save_srr0
3901 if ($checkpc == 0)
3902 echo This activation does not appear to have
3903 echo \20 a valid user context.\n
3904 else
3905 set (struct savearea *) kdp.saved_state=$newact->machine->upcb
3906 set $pc = $checkpc
3907#flush and update seem to be executed lazily by gdb on Tiger, hence the
3908#repeated invocations - see 3743135
3909 _kgm_flush_loop
3910# This works because the new pmap is used only for reads
3911 set kdp_pmap = $newact->task->map->pmap
3912 _kgm_flush_loop
3913 _kgm_update_loop
3914 end
3915 else
3916 echo switchtouserthread not implemented for this architecture.\n
3917 end
3918end
3919
3920document switchtouserthread
3921Syntax: switchtouserthread <address of thread>
3922| Analogous to switchtoact, but switches to the user context of a
3923| specified thread address. Similar to the "showuserstack"
3924| command, but this command does not return gdb to the kernel context
3925| immediately. This is to assist with the following (rather risky)
3926| manoeuvre - upon switching to the user context and virtual address
3927| space, the user may choose to call remove-symbol-file on the
3928| mach_kernel symbol file, and then add-symbol-file on the user space
3929| binary's symfile. gdb can then generate symbolic backtraces
3930| for the user space thread. To return to the
3931| kernel context and virtual address space, the process must be
3932| reversed, i.e. call remove-symbol-file on the user space symbols, and
3933| then add-symbol-file on the appropriate mach_kernel, and issue the
3934| "resetstacks" command. Note that gdb may not react kindly to all these
3935| symbol file switches. The same restrictions that apply to "showuserstack"
3936| apply here - pages that have been paged out cannot be read while in the
3937| debugger context, so backtraces may terminate early.
3938| If the virtual addresses in the stack trace do not conflict with those
3939| of symbols in the kernel's address space, it may be sufficient to
3940| just do an add-symbol-file on the user space binary's symbol file.
3941| Note that while this command works on Panther's gdb, an issue
3942| with Tiger gdb (3743135) appears to hamper the evaluation of this
3943| macro in some cases.
3944end
3945
3946define showmetaclass
91447636
A
3947 set $kgm_metaclassp = (OSMetaClass *)$arg0
3948 printf "%-5d", $kgm_metaclassp->instanceCount
3949 printf "x %5d bytes", $kgm_metaclassp->classSize
3950 printf " %s\n", $kgm_metaclassp->className->string
3951end
3952
0c530ab8
A
3953define showstring
3954 printf "\"%s\"", ((OSString *)$arg0)->string
3955end
3956
3957define shownumber
3958 printf "%lld", ((OSNumber *)$arg0)->value
3959end
3960
3961define showboolean
3962 if ($arg0 == gOSBooleanFalse)
3963 printf "No"
3964 else
3965 printf "Yes"
3966 end
3967end
3968
b0d623f7
A
3969define showdatabytes
3970 set $kgm_data = (OSData *)$arg0
3971
3972 printf "<"
3973 set $kgm_datap = (const unsigned char *) $kgm_data->data
3974 set $kgm_idx = 0
3975 while ( $kgm_idx < $kgm_data->length )
3976 printf "%02X", *$kgm_datap
3977 set $kgm_datap = $kgm_datap + 1
3978 set $kgm_idx = $kgm_idx + 1
3979 end
3980 printf ">\n"
3981end
3982
0c530ab8
A
3983define showdata
3984 set $kgm_data = (OSData *)$arg0
3985
3986 printf "<"
3987 set $kgm_datap = (const unsigned char *) $kgm_data->data
3988
3989 set $kgm_printstr = 0
3990 if (0 == (3 & (unsigned int)$kgm_datap) && ($kgm_data->length >= 3))
3991 set $kgm_bytes = *(unsigned int *) $kgm_datap
3992 if (0xffff0000 & $kgm_bytes)
3993 set $kgm_idx = 0
3994 set $kgm_printstr = 1
3995 while ($kgm_idx++ < 4)
3996 set $kgm_bytes = $kgm_bytes >> 8
3997 set $kgm_char = 0xff & $kgm_bytes
3998 if ($kgm_char && (($kgm_char < 0x20) || ($kgm_char > 0x7e)))
3999 set $kgm_printstr = 0
4000 end
4001 end
4002 end
4003 end
4004
4005 set $kgm_idx = 0
4006 if ($kgm_printstr)
4007 set $kgm_quoted = 0
4008 while ($kgm_idx < $kgm_data->length)
4009 set $kgm_char = $kgm_datap[$kgm_idx++]
4010 if ($kgm_char)
4011 if (0 == $kgm_quoted)
4012 set $kgm_quoted = 1
4013 if ($kgm_idx > 1)
4014 printf ",\""
4015 else
4016 printf "\""
4017 end
4018 end
4019 printf "%c", $kgm_char
4020 else
4021 if ($kgm_quoted)
4022 set $kgm_quoted = 0
4023 printf "\""
4024 end
4025 end
4026 end
4027 if ($kgm_quoted)
4028 printf "\""
4029 end
4030 else
4031 if (0 == (3 & (unsigned int)$kgm_datap))
4032 while (($kgm_idx + 3) <= $kgm_data->length)
4033 printf "%08x", *(unsigned int *) &$kgm_datap[$kgm_idx]
4034 set $kgm_idx = $kgm_idx + 4
4035 end
4036 end
4037 while ($kgm_idx < $kgm_data->length)
4038 printf "%02x", $kgm_datap[$kgm_idx++]
4039 end
4040 end
4041 printf ">"
4042end
4043
4044define showdictionaryint
4045 set $kgm$arg0_dict = (OSDictionary *)$arg1
4046
4047 printf "{"
4048 set $kgm$arg0_idx = 0
4049 while ($kgm$arg0_idx < $kgm$arg0_dict->count)
4050 set $kgm_obj = $kgm$arg0_dict->dictionary[$kgm$arg0_idx].key
4051 showobjectint _$arg0 $kgm_obj
4052 printf "="
4053 set $kgm_obj = $kgm$arg0_dict->dictionary[$kgm$arg0_idx++].value
4054 showobjectint _$arg0 $kgm_obj
4055 if ($kgm$arg0_idx < $kgm$arg0_dict->count)
4056 printf ","
4057 end
4058 end
4059 printf "}"
4060end
4061
4062define indent
4063 set $kgm_idx = 0
4064 while ($kgm_idx < $arg0)
4065 if ($arg1 & (1 << $kgm_idx++))
4066 printf "| "
4067 else
4068 printf " "
4069 end
4070 end
4071end
4072
4073define showregdictionary
4074 indent $kgm_reg_depth+2 $arg1
4075 printf "{\n"
4076
4077 set $kgm_reg_idx = 0
4078 while ($kgm_reg_idx < $arg0->count)
4079 indent $kgm_reg_depth+2 $arg1
4080 printf " "
4081 set $kgm_obj = $arg0->dictionary[$kgm_reg_idx].key
4082 showobjectint _ $kgm_obj
4083 printf " = "
4084
4085 set $kgm_obj = $arg0->dictionary[$kgm_reg_idx++].value
4086 showobjectint _ $kgm_obj
4087 printf "\n"
4088 end
4089 indent $kgm_reg_depth+2 $arg1
4090 printf "}\n"
4091end
4092
4093
6d2010ae
A
4094define showorderedsetarrayint
4095 set $kgm$arg0_array = (_Element *)$arg1
4096 set $kgm$arg0_count = $arg2
4097
4098 set $kgm$arg0_idx = 0
4099 while ($kgm$arg0_idx < $kgm$arg0_count)
4100 set $kgm_obj = $kgm$arg0_array[$kgm$arg0_idx++]
4101 showobjectint _$arg0 $kgm_obj
4102 if ($kgm$arg0_idx < $kgm$arg0_count)
4103 printf ","
4104 end
4105 end
4106end
4107
4108define showorderedsetint
4109 set $kgm_array = ((OSOrderedSet *)$arg1)->array
4110 set $count = ((OSOrderedSet *)$arg1)->count
4111 printf "["
4112 showorderedsetarrayint $arg0 $kgm_array $count
4113 printf "]"
4114end
4115
0c530ab8
A
4116define showarraysetint
4117 set $kgm$arg0_array = (OSArray *)$arg1
4118
4119 set $kgm$arg0_idx = 0
4120 while ($kgm$arg0_idx < $kgm$arg0_array->count)
4121 set $kgm_obj = $kgm$arg0_array->array[$kgm$arg0_idx++]
4122 showobjectint _$arg0 $kgm_obj
4123 if ($kgm$arg0_idx < $kgm$arg0_array->count)
4124 printf ","
4125 end
4126 end
4127end
4128
4129define showarrayint
4130 printf "("
4131 showarraysetint $arg0 $arg1
4132 printf ")"
4133end
4134
4135define showsetint
4136 set $kgm_array = ((OSSet *)$arg1)->members
4137 printf "["
4138 showarraysetint $arg0 $kgm_array
4139 printf "]"
4140end
4141
4142
4143define showobjectint
4144 set $kgm_obj = (OSObject *) $arg1
4145 set $kgm_vt = *((void **) $arg1)
4146
b0d623f7 4147 if ($kgm_lp64 || $kgm_mtype == $kgm_mtype_arm)
c910b4d9
A
4148 set $kgm_vt = $kgm_vt - 2 * sizeof(void *)
4149 end
4150
0c530ab8 4151 if ($kgm_show_object_addrs)
b0d623f7
A
4152 printf "`object "
4153 showptr $arg1
4154 printf ", vt "
4155 output /a (unsigned long) $kgm_vt
4156 if ($kgm_show_object_retain)
4157 printf ", retain count %d, container retain %d", (0xffff & $kgm_obj->retainCount), $kgm_obj->retainCount >> 16
4158 end
4159 printf "` "
0c530ab8
A
4160 end
4161
b0d623f7
A
4162 # No multiple-inheritance
4163 set $kgm_shown = 0
4164 if ($kgm_vt == &_ZTV8OSString)
4165 showstring $arg1
4166 set $kgm_shown = 1
4167 end
4168 if ($kgm_vt == &_ZTV8OSSymbol)
0c530ab8 4169 showstring $arg1
b0d623f7
A
4170 set $kgm_shown = 1
4171 end
4172 if ($kgm_vt == &_ZTV8OSNumber)
0c530ab8 4173 shownumber $arg1
b0d623f7
A
4174 set $kgm_shown = 1
4175 end
4176 if ($kgm_vt == &_ZTV6OSData)
4177 if $kgm_show_data_alwaysbytes == 1
4178 showdatabytes $arg1
4179 else
4180 showdata $arg1
4181 end
4182 set $kgm_shown = 1
4183 end
4184 if ($kgm_vt == &_ZTV9OSBoolean)
4185 showboolean $arg1
4186 set $kgm_shown = 1
4187 end
4188 if ($kgm_vt == &_ZTV12OSDictionary)
4189 showdictionaryint _$arg0 $arg1
4190 set $kgm_shown = 1
4191 end
4192 if ($kgm_vt == &_ZTV7OSArray)
4193 showarrayint _$arg0 $arg1
4194 set $kgm_shown = 1
4195 end
4196 if ($kgm_vt == &_ZTV5OSSet)
4197 showsetint _$arg0 $arg1
4198 set $kgm_shown = 1
4199 end
6d2010ae
A
4200 if ($kgm_vt == &_ZTV12OSOrderedSet)
4201 showorderedsetint _$arg0 $arg1
4202 set $kgm_shown = 1
4203 end
b0d623f7
A
4204
4205 if ($kgm_shown != 1)
4206 if ($kgm_show_object_addrs == 0)
4207 printf "`object "
4208 showptr $arg1
4209 printf ", vt "
4210 output /a (unsigned long) $kgm_vt
4211 printf "`"
4212 end
0c530ab8
A
4213 end
4214end
4215
4216define showobject
4217 set $kgm_save = $kgm_show_object_addrs
4218 set $kgm_show_object_addrs = 1
4219 set $kgm_show_object_retain = 1
4220 showobjectint _ $arg0
4221 set $kgm_show_object_addrs = $kgm_save
4222 set $kgm_show_object_retain = 0
4223 printf "\n"
4224end
4225document showobject
2d21ac55 4226Syntax: (gdb) showobject <object address>
0c530ab8
A
4227| Show info about an OSObject - its vtable ptr and retain count.
4228| If the object is a simple container class, more info will be shown.
0c530ab8
A
4229end
4230
4231define dictget
4232 set $kgm_dictp = (OSDictionary *)$arg0
4233 set $kgm_keyp = (const OSSymbol *)$arg1
4234 set $kgm_idx = 0
4235 set $kgm_result = 0
4236 while (($kgm_idx < $kgm_dictp->count) && ($kgm_result == 0))
4237 if ($kgm_keyp == $kgm_dictp->dictionary[$kgm_idx].key)
4238 set $kgm_result = $kgm_dictp->dictionary[$kgm_idx].value
4239 end
4240 set $kgm_idx = $kgm_idx + 1
4241 end
4242end
4243
4244
b0d623f7 4245define _registryentryrecurseinit
0c530ab8
A
4246 set $kgm_re = (IOService *)$arg1
4247 set $kgm$arg0_stack = (unsigned long long) $arg2
4248
4249 if ($arg3)
4250 set $kgm$arg0_stack = $kgm$arg0_stack | (1ULL << $kgm_reg_depth)
4251 else
4252 set $kgm$arg0_stack = $kgm$arg0_stack & ~(1ULL << $kgm_reg_depth)
4253 end
4254
4255 dictget $kgm_re->fRegistryTable $kgm_childkey
4256 set $kgm$arg0_child_array = (OSArray *) $kgm_result
4257
4258 if ($kgm$arg0_child_array)
4259 set $kgm$arg0_child_count = $kgm$arg0_child_array->count
4260 else
4261 set $kgm$arg0_child_count = 0
4262 end
4263
4264 if ($kgm$arg0_child_count)
4265 set $kgm$arg0_stack = $kgm$arg0_stack | (2ULL << $kgm_reg_depth)
4266 else
4267 set $kgm$arg0_stack = $kgm$arg0_stack & ~(2ULL << $kgm_reg_depth)
4268 end
b0d623f7 4269end
0c530ab8 4270
b0d623f7
A
4271define findregistryentryrecurse
4272 set $kgm_registry_entry = 0
4273 _registryentryrecurseinit $arg0 $arg1 $arg2 $arg3
0c530ab8
A
4274
4275 dictget $kgm_re->fRegistryTable $kgm_namekey
4276 if ($kgm_result == 0)
4277 dictget $kgm_re->fRegistryTable gIONameKey
4278 end
4279 if ($kgm_result == 0)
4280 dictget $kgm_re->fPropertyTable gIOClassKey
4281 end
4282
4283 if ($kgm_result != 0)
b0d623f7
A
4284 set $str = ((OSString *) $kgm_result)->string
4285 strcmp_nomalloc $str $kgm_reg_find_str0 $kgm_reg_find_str1 $kgm_reg_find_str2 $kgm_reg_find_str3 $kgm_reg_find_str4 $kgm_reg_find_str5 $kgm_reg_find_str6 $kgm_reg_find_str7 $kgm_reg_find_str8
4286 if $kgm_findregistry_verbose
4287 echo .
4288 end
0c530ab8 4289
b0d623f7
A
4290 if $kgm_strcmp_result == 0
4291 if $kgm_findregistry_verbose
4292 printf "\n%s:\n | ", ((OSString *) $kgm_result)->string
4293 showobject $kgm_re
4294 printf " | "
4295 print $kgm_re
4296 end
4297
6d2010ae 4298 # don't populate $kgm_registry_entry if we want to show everything
b0d623f7
A
4299 if !$kgm_findregistry_continue
4300 set $kgm_registry_entry = $kgm_re
4301 end
4302 end
4303 end
0c530ab8 4304
b0d623f7
A
4305 # recurse
4306 if (!$kgm_registry_entry && ($kgm$arg0_child_count != 0))
4307 set $kgm_reg_depth = $kgm_reg_depth + 1
4308 set $kgm$arg0_child_idx = 0
4309
4310 while ($kgm$arg0_child_idx < $kgm$arg0_child_count)
4311 set $kgm_re = $kgm$arg0_child_array->array[$kgm$arg0_child_idx++]
4312 set $kgm_more_sib = ($kgm$arg0_child_idx < $kgm$arg0_child_count)
4313 if $kgm_reg_depth >= $kgm_reg_depth_max + 1
4314 loop_break
4315 end
4316 findregistryentryrecurse _$arg0 $kgm_re $kgm$arg0_stack $kgm_more_sib
4317 if $kgm_registry_entry
4318 loop_break
4319 end
4320 end
4321 set $kgm_reg_depth = $kgm_reg_depth - 1
c910b4d9 4322 end
b0d623f7 4323end
0c530ab8 4324
b0d623f7
A
4325define findregdictvalue
4326 set $kgm_registry_value = 0
4327 set $kgm_reg_idx = 0
4328 while ($kgm_reg_idx < $arg0->count)
4329 set $kgm_obj = $arg0->dictionary + $kgm_reg_idx
4330 set $str = ((OSString *)$kgm_obj->key)->string
4331 strcmp_nomalloc $str $kgm_reg_find_str0 $kgm_reg_find_str1 $kgm_reg_find_str2 $kgm_reg_find_str3 $kgm_reg_find_str4 $kgm_reg_find_str5 $kgm_reg_find_str6 $kgm_reg_find_str7 $kgm_reg_find_str8
4332
4333 if $kgm_strcmp_result == 0
4334 set $kgm_registry_value = $kgm_obj->value
4335 if $kgm_findregistry_verbose
4336 showobject $kgm_registry_value
4337 print $kgm_registry_value
4338 end
4339 loop_break
0c530ab8 4340 end
b0d623f7 4341 set $kgm_reg_idx = $kgm_reg_idx + 1
0c530ab8 4342 end
b0d623f7 4343end
0c530ab8 4344
b0d623f7
A
4345define setfindregistrystr
4346 set $kgm_reg_find_str0 = 0
4347 set $kgm_reg_find_str1 = 0
4348 set $kgm_reg_find_str2 = 0
4349 set $kgm_reg_find_str3 = 0
4350 set $kgm_reg_find_str4 = 0
4351 set $kgm_reg_find_str5 = 0
4352 set $kgm_reg_find_str6 = 0
4353 set $kgm_reg_find_str7 = 0
4354 set $kgm_reg_find_str8 = 0
4355
4356 if $argc > 0
4357 set $kgm_reg_find_str0 = $arg0
4358 end
4359 if $argc > 1
4360 set $kgm_reg_find_str1 = $arg1
4361 end
4362 if $argc > 2
4363 set $kgm_reg_find_str2 = $arg2
4364 end
4365 if $argc > 3
4366 set $kgm_reg_find_str3 = $arg3
4367 end
4368 if $argc > 4
4369 set $kgm_reg_find_str4 = $arg4
4370 end
4371 if $argc > 5
4372 set $kgm_reg_find_str5 = $arg5
4373 end
4374 if $argc > 6
4375 set $kgm_reg_find_str6 = $arg6
4376 end
4377 if $argc > 7
4378 set $kgm_reg_find_str7 = $arg7
4379 end
4380 if $argc > 8
4381 set $kgm_reg_find_str8 = $arg8
4382 end
4383end
4384
4385document setfindregistrystr
4386Syntax: (gdb) setfindregistrystr [a] [b] [c] [d] [e] [f] [g] [h] [i]
4387| Store an encoded string into up to 9 arguments for use by
4388| findregistryprop or findregistryentry. The arguments are created
4389| through calls to strcmp_arg_pack64
4390end
4391
4392define _findregistryprop
4393 set $reg = (IOService *) $arg0
4394 set $kgm_props = $reg->fPropertyTable
4395 set $kgm_findregistry_verbose = 0
4396
4397 findregdictvalue $kgm_props
4398end
4399
4400define findregistryprop
4401 set $reg = (IOService *) $arg0
4402 set $kgm_props = $reg->fPropertyTable
4403
4404 set $kgm_findregistry_verbose = 1
4405 findregdictvalue $kgm_props
4406end
4407
4408document findregistryprop
4409Syntax: (gdb) findregistryprop <entry>
4410| Given a registry entry, print out the contents for the property that matches
4411| the encoded string specified via setfindregistrystr.
4412|
4413| For example, the following will print out the "intel-pic" property stored in
4414| the AppleACPIPlatformExpert registry entry $pe_entry:
4415| strcmp_arg_pack64 'i' 'n' 't' 'e' 'l' '-' 'p' 'i'
4416| set $intel_pi = $kgm_strcmp_arg
4417| strcmp_arg_pack64 'c' 0 0 0 0 0 0 0
4418| set $c = $kgm_strcmp_arg
4419| setfindregistrystr $intel_pi $c
4420| findregistryprop $pe_entry
4421end
4422
4423define findregistryentryint
7e4a7d39
A
4424 if !$kgm_reg_plane
4425 set $kgm_reg_plane = (IORegistryPlane *) gIOServicePlane
4426 end
4427
4428 if !$kgm_reg_plane
4429 printf "Please load kgmacros after KDP attaching to the target.\n"
4430 else
4431 set $kgm_namekey = (OSSymbol *) $kgm_reg_plane->nameKey
4432 set $kgm_childkey = (OSSymbol *) $kgm_reg_plane->keys[1]
4433 if $kgm_findregistry_verbose
4434 printf "Searching"
4435 end
4436 findregistryentryrecurse _ $arg0 0 0
b0d623f7 4437 end
b0d623f7
A
4438end
4439
4440define _findregistryentry
4441 set $kgm_findregistry_verbose = 0
4442 set $kgm_findregistry_continue = 0
4443 set $kgm_reg_depth = 0
4444
4445 findregistryentryint gRegistryRoot
4446end
4447
4448define findregistryentry
4449 set $kgm_findregistry_verbose = 1
4450 set $kgm_findregistry_continue = 0
4451 set $kgm_reg_depth = 0
4452
4453 findregistryentryint gRegistryRoot
4454end
4455
4456define findregistryentries
4457 set $kgm_findregistry_verbose = 1
4458 set $kgm_findregistry_continue = 1
4459 set $kgm_reg_depth = 0
4460
4461 findregistryentryint gRegistryRoot
4462end
4463
4464document findregistryentry
4465Syntax: (gdb) findregistryentry
4466| Search for a registry entry that matches the encoded string specified through
4467| setfindregistrystr. You can alter the search depth through use of
4468| $kgm_reg_depth_max.
4469|
4470| For example, the following will pull out the AppleACPIPlatformExpert registry
4471| entry:
4472| strcmp_arg_pack64 'A' 'p' 'p' 'l' 'e' 'A' 'C' 'P'
4473| set $AppleACP = $kgm_strcmp_arg
4474| strcmp_arg_pack64 'I' 'P' 'l' 'a' 't' 'f' 'o' 'r'
4475| set $IPlatfor = $kgm_strcmp_arg
4476| strcmp_arg_pack64 'm' 'E' 'x' 'p' 'e' 'r' 't' 0
4477| set $mExpert = $kgm_strcmp_arg
4478| setfindregistrystr $AppleACP $IPlatfor $mExpert
4479| findregistryentry
4480end
4481
4482document findregistryentries
4483Syntax: (gdb) findregistryentries
4484| Search for all registry entries that match the encoded string specified through
4485| setfindregistrystr. You can alter the search depth through use of
4486| $kgm_reg_depth_max. See findregistryentry for an example of how to encode a string.
4487end
4488
4489
4490define showregistryentryrecurse
4491 _registryentryrecurseinit $arg0 $arg1 $arg2 $arg3
4492
4493 indent $kgm_reg_depth $kgm$arg0_stack
4494 printf "+-o "
4495
4496 dictget $kgm_re->fRegistryTable $kgm_namekey
4497 if ($kgm_result == 0)
4498 dictget $kgm_re->fRegistryTable gIONameKey
4499 end
4500 if ($kgm_result == 0)
4501 dictget $kgm_re->fPropertyTable gIOClassKey
4502 end
4503
4504 if ($kgm_result != 0)
4505 printf "%s", ((OSString *)$kgm_result)->string
4506 else
4507 if (((IOService*)$kgm_re)->pwrMgt && ((IOService*)$kgm_re)->pwrMgt->Name)
4508 printf "%s", ((IOService*)$kgm_re)->pwrMgt->Name
4509 else
4510# printf ", guessclass "
4511# guessclass $kgm_re
4512 printf "??"
4513 end
4514 end
4515
4516
4517 printf " <object "
4518 showptr $kgm_re
4519 printf ", id 0x%llx, ", $kgm_re->IORegistryEntry::reserved->fRegistryEntryID
4520 printf "vtable "
4521 set $kgm_vt = (unsigned long) *(void**) $kgm_re
4522 if ($kgm_lp64 || $kgm_mtype == $kgm_mtype_arm)
4523 set $kgm_vt = $kgm_vt - 2 * sizeof(void *)
4524 end
4525 output /a $kgm_vt
4526
4527 if ($kgm_vt != &_ZTV15IORegistryEntry)
4528 printf ", "
4529 set $kgm_state = $kgm_re->__state[0]
4530 # kIOServiceRegisteredState
4531 if (0 == ($kgm_state & 2))
4532 printf "!"
4533 end
4534 printf "registered, "
4535 # kIOServiceMatchedState
4536 if (0 == ($kgm_state & 4))
4537 printf "!"
4538 end
4539 printf "matched, "
4540 # kIOServiceInactiveState
4541 if ($kgm_state & 1)
4542 printf "in"
4543 end
4544 printf "active, busy %d, retain count %d", (0xff & $kgm_re->__state[1]), (0xffff & $kgm_re->retainCount)
4545 end
4546 printf ">\n"
4547
4548 if ($kgm_show_props)
4549 set $kgm_props = $kgm_re->fPropertyTable
4550 showregdictionary $kgm_props $kgm$arg0_stack
0c530ab8
A
4551 end
4552
4553 # recurse
4554 if ($kgm$arg0_child_count != 0)
4555
b0d623f7
A
4556 set $kgm_reg_depth = $kgm_reg_depth + 1
4557 set $kgm$arg0_child_idx = 0
0c530ab8 4558
b0d623f7
A
4559 while ($kgm$arg0_child_idx < $kgm$arg0_child_count)
4560 set $kgm_re = $kgm$arg0_child_array->array[$kgm$arg0_child_idx++]
4561 set $kgm_more_sib = ($kgm$arg0_child_idx < $kgm$arg0_child_count)
4562 if $kgm_reg_depth >= $kgm_reg_depth_max + 1
4563 loop_break
4564 end
4565 showregistryentryrecurse _$arg0 $kgm_re $kgm$arg0_stack $kgm_more_sib
4566 end
0c530ab8 4567
b0d623f7 4568 set $kgm_reg_depth = $kgm_reg_depth - 1
0c530ab8
A
4569 end
4570end
4571
4572define showregistryentryint
7e4a7d39
A
4573 if !$kgm_reg_plane
4574 set $kgm_reg_plane = (IORegistryPlane *) gIOServicePlane
4575 end
0c530ab8 4576
7e4a7d39
A
4577 if !$kgm_reg_plane
4578 printf "Please load kgmacros after KDP attaching to the target.\n"
4579 else
4580 set $kgm_namekey = (OSSymbol *) $kgm_reg_plane->nameKey
4581 set $kgm_childkey = (OSSymbol *) $kgm_reg_plane->keys[1]
4582 showregistryentryrecurse _ $arg0 0 0
4583 end
0c530ab8
A
4584end
4585
4586define showregistry
4587 set $kgm_reg_depth = 0
4588 set $kgm_show_props = 0
4589 showregistryentryint gRegistryRoot
4590end
4591document showregistry
2d21ac55 4592Syntax: (gdb) showregistry
b0d623f7
A
4593| Show info about all registry entries in the current plane. You can specify the maximum
4594| display depth with $kgm_reg_depth_max.
0c530ab8
A
4595end
4596
4597define showregistryprops
4598 set $kgm_reg_depth = 0
4599 set $kgm_show_props = 1
4600 showregistryentryint gRegistryRoot
4601end
4602document showregistryprops
2d21ac55 4603Syntax: (gdb) showregistryprops
0c530ab8
A
4604| Show info about all registry entries in the current plane, and their properties.
4605| set $kgm_show_object_addrs = 1 and/or set $kgm_show_object_retain = 1 will display
4606| more verbose information
0c530ab8
A
4607end
4608
4609define showregistryentry
4610 set $kgm_reg_depth = 0
4611 set $kgm_show_props = 1
4612 showregistryentryint $arg0
4613end
4614document showregistryentry
2d21ac55 4615Syntax: (gdb) showregistryentry <object address>
0c530ab8 4616| Show info about a registry entry; its properties and descendants in the current plane.
0c530ab8
A
4617end
4618
4619define setregistryplane
b0d623f7
A
4620 if ($arg0 != 0)
4621 set $kgm_reg_plane = (IORegistryPlane *) $arg0
0c530ab8 4622 else
b0d623f7
A
4623 showobjectint _ gIORegistryPlanes
4624 printf "\n"
0c530ab8
A
4625 end
4626end
4627document setregistryplane
2d21ac55 4628Syntax: (gdb) setregistryplane <plane object address>
0c530ab8
A
4629| Set the plane to be used for the iokit registry macros. An argument of zero will
4630| display known planes.
0c530ab8
A
4631end
4632
4633define guessclass
4452a7af 4634 set $kgm_classidx = 0
0c530ab8
A
4635 set $kgm_lookvt = *((void **) $arg0)
4636 set $kgm_bestvt = (void *) 0
4637 set $kgm_bestidx = 0
4638
4452a7af 4639 while $kgm_classidx < sAllClassesDict->count
6601e61a 4640 set $kgm_meta = (OSMetaClass *) sAllClassesDict->dictionary[$kgm_classidx].value
0c530ab8
A
4641
4642 set $kgm_vt = *((void **) $kgm_meta)
4643
4644 if (($kgm_vt > $kgm_bestvt) && ($kgm_vt < $kgm_lookvt))
4645 set $kgm_bestvt = $kgm_vt
4646 set $kgm_bestidx = $kgm_classidx
4647 end
6601e61a 4648 set $kgm_classidx = $kgm_classidx + 1
4452a7af 4649 end
0c530ab8 4650 printf "%s", sAllClassesDict->dictionary[$kgm_bestidx].key->string
4452a7af 4651end
0c530ab8
A
4652
4653define showallclasses
4654 set $kgm_classidx = 0
4655 while $kgm_classidx < sAllClassesDict->count
4656 set $kgm_meta = (OSMetaClass *) sAllClassesDict->dictionary[$kgm_classidx++].value
4657 showmetaclass $kgm_meta
4658 end
4659end
4660
91447636 4661document showallclasses
2d21ac55 4662Syntax: (gdb) showallclasses
91447636 4663| Show the instance counts and ivar size of all OSObject subclasses. See ioclasscount man page for details.
91447636
A
4664end
4665
4666define showioalloc
4667 printf " Instance allocation = 0x%08lx = %4ld K\n", (int) debug_ivars_size, ((int) debug_ivars_size) / 1024
4668 printf "Container allocation = 0x%08lx = %4ld K\n", (int) debug_container_malloc_size, ((int) debug_container_malloc_size) / 1024
4669 printf " IOMalloc allocation = 0x%08lx = %4ld K\n", (int) debug_iomalloc_size, ((int) debug_iomalloc_size) / 1024
4670 printf " Pageable allocation = 0x%08lx = %4ld K\n", (vm_size_t) debug_iomallocpageable_size, ((vm_size_t) debug_iomallocpageable_size) / 1024
4671end
4672
4673document showioalloc
2d21ac55 4674Syntax: (gdb) showioalloc
91447636 4675| Show some accounting of memory allocated by IOKit allocators. See ioalloccount man page for details.
2d21ac55
A
4676end
4677
4678define showosobjecttracking
4679 set $kgm_next = (OSObjectTracking *) gOSObjectTrackList.next
4680 while $kgm_next != &gOSObjectTrackList
4681 set $obj = (OSObject *) ($kgm_next+1)
4682 showobject $obj
4683 set $kgm_idx = 0
4684 while $kgm_idx < (sizeof($kgm_next->bt) / sizeof($kgm_next->bt[0]))
b0d623f7 4685 if ((unsigned long) $kgm_next->bt[$kgm_idx] > (unsigned long) &last_kernel_symbol)
2d21ac55
A
4686 showkmodaddr $kgm_next->bt[$kgm_idx]
4687 printf "\n"
4688 else
b0d623f7
A
4689 if ((unsigned long) $kgm_next->bt[$kgm_idx] > 0)
4690 output /a $kgm_next->bt[$kgm_idx]
2d21ac55
A
4691 printf "\n"
4692 end
4693 end
4694 set $kgm_idx = $kgm_idx + 1
4695 end
4696 printf "\n"
4697 set $kgm_next = (OSObjectTracking *) $kgm_next->link.next
4698 end
4699end
4700
4701document showosobjecttracking
4702Syntax: (gdb) showosobjecttracking
4703| Show the list of tracked OSObject allocations with backtraces.
4704| Boot with the kOSTraceObjectAlloc (0x00400000) io debug flag set.
4705| Set gOSObjectTrackThread to 1 or a thread_t to capture new OSObjects allocated by a thread or all threads.
91447636 4706end
0c530ab8 4707
6d2010ae
A
4708# $kgm_readphys_force_kdp and $kgm_readphys_force_physmap
4709# can respectively cause physical memory access to use
4710# a KDP manual packet or the physical memory mapping
4711# even if the default behavior would be otherwise.
b0d623f7 4712define readphysint
6d2010ae
A
4713 set $kgm_readphysint_result = 0xBAD10AD
4714
4715 if ($kgm_readphys_force_kdp != 0)
4716 set $kgm_readphys_use_kdp = 1
4717 else
4718 if ($kgm_readphys_force_physmap)
4719 set $kgm_readphys_use_kdp = 0
4720 else
4721 set $kgm_readphys_use_kdp = ( kdp->is_conn > 0 )
4722 end
4723 end
4724
4725 if ($kgm_readphys_use_kdp)
4726
4727 # set up the manual KDP packet
4728 set manual_pkt.input = 0
4729 set manual_pkt.len = sizeof(kdp_readphysmem64_req_t)
4730 set $kgm_pkt = (kdp_readphysmem64_req_t *)&manual_pkt.data
4731 set $kgm_pkt->hdr.request = KDP_READPHYSMEM64
4732 set $kgm_pkt->hdr.len = sizeof(kdp_readphysmem64_req_t)
4733 set $kgm_pkt->hdr.is_reply = 0
4734 set $kgm_pkt->hdr.seq = 0
4735 set $kgm_pkt->hdr.key = 0
4736 set $kgm_pkt->address = (uint64_t)$arg0
4737 set $kgm_pkt->nbytes = $arg1 >> 3
4738 set $kgm_pkt->lcpu = $arg2
4739 set manual_pkt.input = 1
4740 # dummy to make sure manual packet is executed
4741 set $kgm_dummy = &_mh_execute_header
4742 set $kgm_pkt = (kdp_readphysmem64_reply_t *)&manual_pkt.data
4743 if ($kgm_pkt->error == 0)
4744 if $arg1 == 8
4745 set $kgm_readphysint_result = *((uint8_t *)$kgm_pkt->data)
4746 end
4747 if $arg1 == 16
4748 set $kgm_readphysint_result = *((uint16_t *)$kgm_pkt->data)
4749 end
4750 if $arg1 == 32
4751 set $kgm_readphysint_result = *((uint32_t *)$kgm_pkt->data)
4752 end
4753 if $arg1 == 64
4754 set $kgm_readphysint_result = *((uint64_t *)$kgm_pkt->data)
4755 end
4756 end
4757
4758 else
4759 # No KDP. Attempt to use physical memory mapping
4760
4761 if ($kgm_mtype == $kgm_mtype_x86_64)
4762 set $kgm_readphys_paddr_in_kva = (unsigned long long)$arg0 + (((unsigned long long)-1 << 47) | ((unsigned long long)509 << 39))
4763 else
4764 if ($kgm_mtype == $kgm_mtype_arm)
4765 set $kgm_readphys_paddr_in_kva = (unsigned long long)$arg0 - gPhysBase + gVirtBase
4766 else
4767 printf "readphys not available for current architecture.\n"
4768 set $kgm_readphys_paddr_in_kva = 0
4769 end
4770 end
4771 if $kgm_readphys_paddr_in_kva
4772 if $arg1 == 8
4773 set $kgm_readphysint_result = *((uint8_t *)$kgm_readphys_paddr_in_kva)
4774 end
4775 if $arg1 == 16
4776 set $kgm_readphysint_result = *((uint16_t *)$kgm_readphys_paddr_in_kva)
4777 end
4778 if $arg1 == 32
4779 set $kgm_readphysint_result = *((uint32_t *)$kgm_readphys_paddr_in_kva)
4780 end
4781 if $arg1 == 64
4782 set $kgm_readphysint_result = *((uint64_t *)$kgm_readphys_paddr_in_kva)
4783 end
4784 end
4785 end
b0d623f7
A
4786end
4787
4788define readphys8
4789 readphysint $arg0 8 $kgm_lcpu_self
4790 output /a $arg0
4791 printf ":\t0x%02hhx\n", $kgm_readphysint_result
4792 set $kgm_readphys_result = (uint64_t)$kgm_readphysint_result
4793end
4794
4795define readphys16
4796 readphysint $arg0 16 $kgm_lcpu_self
4797 output /a $arg0
4798 printf ":\t0x%04hx\n", $kgm_readphysint_result
4799 set $kgm_readphys_result = (uint64_t)$kgm_readphysint_result
4800end
4801
4802define readphys32
4803 readphysint $arg0 32 $kgm_lcpu_self
4804 output /a $arg0
4805 printf ":\t0x%08x\n", $kgm_readphysint_result
4806 set $kgm_readphys_result = (uint64_t)$kgm_readphysint_result
0c530ab8
A
4807end
4808
4809define readphys64
b0d623f7
A
4810 readphysint $arg0 64 $kgm_lcpu_self
4811 output /a $arg0
4812 printf ":\t0x%016llx\n", $kgm_readphysint_result
4813 set $kgm_readphys_result = (uint64_t)$kgm_readphysint_result
4814end
4815
4816define readphys
4817 readphys32 $arg0
4818end
4819
4820document readphys8
4821| See readphys64
4822end
4823
4824document readphys16
4825| See readphys64
0c530ab8
A
4826end
4827
b0d623f7
A
4828document readphys32
4829| See readphys64
0c530ab8
A
4830end
4831
4832document readphys64
b0d623f7
A
4833| The argument is interpreted as a physical address, and the 64-bit word
4834| addressed is displayed. Saves 64-bit result in $kgm_readphys_result.
4835end
4836
4837define writephysint
4838 # set up the manual KDP packet
4839 set manual_pkt.input = 0
4840 set manual_pkt.len = sizeof(kdp_writephysmem64_req_t)
4841 set $kgm_pkt = (kdp_writephysmem64_req_t *)&manual_pkt.data
4842 set $kgm_pkt->hdr.request = KDP_WRITEPHYSMEM64
4843 set $kgm_pkt->hdr.len = sizeof(kdp_writephysmem64_req_t)
4844 set $kgm_pkt->hdr.is_reply = 0
4845 set $kgm_pkt->hdr.seq = 0
4846 set $kgm_pkt->hdr.key = 0
4847 set $kgm_pkt->address = (uint64_t)$arg0
4848 set $kgm_pkt->nbytes = $arg1 >> 3
4849 set $kgm_pkt->lcpu = $arg3
4850 if $arg1 == 8
4851 set *(uint8_t *)$kgm_pkt->data = (uint8_t)$arg2
4852 end
4853 if $arg1 == 16
4854 set *(uint16_t *)$kgm_pkt->data = (uint16_t)$arg2
4855 end
4856 if $arg1 == 32
4857 set *(uint32_t *)$kgm_pkt->data = (uint32_t)$arg2
4858 end
4859 if $arg1 == 64
4860 set *(uint64_t *)$kgm_pkt->data = (uint64_t)$arg2
4861 end
4862 set manual_pkt.input = 1
4863 # dummy to make sure manual packet is executed
4864 set $kgm_dummy = &_mh_execute_header
4865 set $kgm_pkt = (kdp_writephysmem64_reply_t *)&manual_pkt.data
4866 set $kgm_writephysint_result = $kgm_pkt->error
4867end
4868
4869define writephys8
4870 writephysint $arg0 8 $arg1 $kgm_lcpu_self
4871end
4872
4873define writephys16
4874 writephysint $arg0 16 $arg1 $kgm_lcpu_self
4875end
4876
4877define writephys32
4878 writephysint $arg0 32 $arg1 $kgm_lcpu_self
4879end
4880
4881define writephys64
4882 writephysint $arg0 64 $arg1 $kgm_lcpu_self
4883end
4884
4885document writephys8
4886| See writephys64
4887end
4888
4889document writephys16
4890| See writephys64
4891end
4892
4893document writephys32
4894| See writephys64
4895end
4896
4897document writephys64
4898| The argument is interpreted as a physical address, and the second argument is
4899| written to that address as a 64-bit word.
0c530ab8 4900end
2d21ac55
A
4901
4902define addkextsyms
6d2010ae
A
4903 shell echo cd `pwd` > /tmp/gdb-cd
4904 cd $arg0
4905 source kcbmacros
4906 source /tmp/gdb-cd
2d21ac55
A
4907 set $kgm_show_kmod_syms = 1
4908end
4909
4910document addkextsyms
4911| Takes a directory of symbols for kexts generated with kextcache -y and loads them
4912| into gdb.
4913| (gdb) addkextsyms /path/to/symboldir
4914end
4915
4916define showprocfiles
4917 if ($argc == 1)
4918 _showprocheader
4919 _showprocfiles $arg0
4920 else
4921 printf "| Usage:\n|\n"
4922 help showprocfiles
4923 end
4924end
4925document showprocfiles
4926Syntax: (gdb) showprocfiles <proc_t>
4927| Given a proc_t pointer, display the list of open file descriptors for the
4928| referenced process.
4929end
4930
4931define _showprocheader
b0d623f7
A
4932 printf "fd fileglob "
4933 showptrhdrpad
4934 printf " fg flags fg type fg data "
4935 showptrhdrpad
4936 printf " info\n"
4937 printf "----- ----------"
4938 if $kgm_lp64
4939 printf "--------"
4940 end
4941 printf " ---------- -------- ----------"
4942 if $kgm_lp64
4943 printf "--------"
4944 end
4945 printf " -------------------\n"
2d21ac55
A
4946end
4947
4948define _showprocfiles
4949 set $kgm_spf_filedesc = ((proc_t)$arg0)->p_fd
4950 set $kgm_spf_last = $kgm_spf_filedesc->fd_lastfile
4951 set $kgm_spf_ofiles = $kgm_spf_filedesc->fd_ofiles
4952 set $kgm_spf_count = 0
4953 while ($kgm_spf_count <= $kgm_spf_last)
4954 if ($kgm_spf_ofiles[$kgm_spf_count] == 0)
4955 # DEBUG: For files that were open, but are now closed
4956 # printf "%-5d FILEPROC_NULL\n", $kgm_spf_count
4957 else
4958 # display fd #, fileglob address, fileglob flags
4959 set $kgm_spf_flags = $kgm_spf_ofiles[$kgm_spf_count].f_flags
4960 set $kgm_spf_fg = $kgm_spf_ofiles[$kgm_spf_count].f_fglob
b0d623f7
A
4961 printf "%-5d ", $kgm_spf_count
4962 showptr $kgm_spf_fg
4963 printf " 0x%08x ", $kgm_spf_flags
2d21ac55
A
4964 # decode fileglob type
4965 set $kgm_spf_fgt = $kgm_spf_fg->fg_type
4966 if ($kgm_spf_fgt == 1)
4967 printf "VNODE "
4968 end
4969 if ($kgm_spf_fgt == 2)
4970 printf "SOCKET "
4971 end
4972 if ($kgm_spf_fgt == 3)
4973 printf "PSXSHM "
4974 end
4975 if ($kgm_spf_fgt == 4)
4976 printf "PSXSEM "
4977 end
4978 if ($kgm_spf_fgt == 5)
4979 printf "KQUEUE "
4980 end
4981 if ($kgm_spf_fgt == 6)
4982 printf "PIPE "
4983 end
4984 if ($kgm_spf_fgt == 7)
4985 printf "FSEVENTS"
4986 end
4987 if ($kgm_spf_fgt < 1 || $kgm_spf_fgt > 7)
4988 printf "?: %-5d", $kgm_spf_fgt
4989 end
4990
4991 # display fileglob data address and decode interesting fact(s)
4992 # about data, if we know any
4993 set $kgm_spf_fgd = $kgm_spf_fg->fg_data
b0d623f7
A
4994 printf " "
4995 showptr $kgm_spf_fgd
4996 printf " "
2d21ac55
A
4997 if ($kgm_spf_fgt == 1)
4998 set $kgm_spf_name = ((struct vnode *)$kgm_spf_fgd)->v_name
4999 if ($kgm_spf_name == 0)
5000 printf "(null)"
5001 else
5002 printf "%s", $kgm_spf_name
5003 end
5004 end
5005 printf "\n"
5006 end
5007 set $kgm_spf_count = $kgm_spf_count + 1
5008 end
5009end
5010
5011#
5012# Show all the advisory file locks held by a process for each of the vnode
5013# type files that it has open; do this by walking the per process open file
5014# table and looking at any vnode type fileglob that has a non-NULL lock list
5015# associated with it.
5016#
5017define showproclocks
5018 if ($argc == 1)
5019 _showproclocks $arg0
5020 else
5021 printf "| Usage:\n|\n"
5022 help showproclocks
5023 end
5024end
5025document showproclocks
5026Syntax: (gdb) showproclocks <proc_t>
5027| Given a proc_t pointer, display the list of advisory file locks held by the
5028| referenced process.
5029end
5030
5031define _showproclocks
5032 set $kgm_spl_filedesc = ((proc_t)$arg0)->p_fd
5033 set $kgm_spl_last = $kgm_spl_filedesc->fd_lastfile
5034 set $kgm_spl_ofiles = $kgm_spl_filedesc->fd_ofiles
5035 set $kgm_spl_count = 0
5036 set $kgm_spl_seen = 0
5037 while ($kgm_spl_count <= $kgm_spl_last)
5038 if ($kgm_spl_ofiles[$kgm_spl_count] == 0)
5039 # DEBUG: For files that were open, but are now closed
5040 # printf "%-5d FILEPROC_NULL\n", $kgm_spl_count
5041 else
5042 set $kgm_spl_fg = $kgm_spl_ofiles[$kgm_spl_count].f_fglob
5043 # decode fileglob type
5044 set $kgm_spl_fgt = $kgm_spl_fg->fg_type
5045 if ($kgm_spl_fgt == 1)
5046 set $kgm_spl_fgd = $kgm_spl_fg->fg_data
5047 set $kgm_spl_name = ((struct vnode *)$kgm_spl_fgd)->v_name
5048 set $kgm_spl_vnode = ((vnode_t)$kgm_spl_fgd)
5049 set $kgm_spl_lockiter = $kgm_spl_vnode->v_lockf
5050 if ($kgm_spl_lockiter != 0)
5051 if ($kgm_spl_seen == 0)
5052 _showvnodelockheader
5053 end
5054 set $kgm_spl_seen = $kgm_spl_seen + 1
5055 printf "( fd %d, name ", $kgm_spl_count
5056 if ($kgm_spl_name == 0)
5057 printf "(null) )"
5058 else
5059 printf "%s )\n", $kgm_spl_name
5060 end
5061 _showvnodelocks $kgm_spl_fgd
5062 end
5063 end
5064 end
5065 set $kgm_spl_count = $kgm_spf_count + 1
5066 end
b0d623f7
A
5067 printf "%d total locks for ", $kgm_spl_seen
5068 showptr $arg0
5069 printf "\n"
2d21ac55
A
5070end
5071
5072define showprocinfo
5073 set $kgm_spi_proc = (proc_t)$arg0
b0d623f7
A
5074 printf "Process "
5075 showptr $kgm_spi_proc
5076 printf "\n"
2d21ac55 5077 printf " name %s\n", $kgm_spi_proc->p_comm
b0d623f7
A
5078 printf " pid:%.8d", $kgm_spi_proc->p_pid
5079 printf " task:"
5080 showptr $kgm_spi_proc->task
5081 printf " p_stat:%.1d", $kgm_spi_proc->p_stat
5082 printf " parent pid:%.8d", $kgm_spi_proc->p_ppid
5083 printf "\n"
2d21ac55
A
5084 # decode part of credential
5085 set $kgm_spi_cred = $kgm_spi_proc->p_ucred
5086 if ($kgm_spi_cred != 0)
6d2010ae 5087 printf "Cred: euid %d ruid %d svuid %d\n", $kgm_spi_cred->cr_posix.cr_uid, $kgm_spi_cred->cr_posix.cr_ruid, $kgm_spi_cred->cr_posix.cr_svuid
2d21ac55
A
5088 else
5089 printf "Cred: (null)\n"
5090 end
5091 # decode flags
5092 set $kgm_spi_flag = $kgm_spi_proc->p_flag
5093 printf "Flags: 0x%08x\n", $kgm_spi_flag
5094 if ($kgm_spi_flag & 0x00000001)
5095 printf " 0x00000001 - may hold advisory locks\n"
5096 end
5097 if ($kgm_spi_flag & 0x00000002)
5098 printf " 0x00000002 - has a controlling tty\n"
5099 end
5100 if ($kgm_spi_flag & 0x00000004)
5101 printf " 0x00000004 - process is 64 bit\n"
5102 else
5103 printf " !0x00000004 - process is 32 bit\n"
5104 end
5105 if ($kgm_spi_flag & 0x00000008)
5106 printf " 0x00000008 - no SIGCHLD on child stop\n"
5107 end
5108 if ($kgm_spi_flag & 0x00000010)
5109 printf " 0x00000010 - waiting for child exec/exit\n"
5110 end
5111 if ($kgm_spi_flag & 0x00000020)
5112 printf " 0x00000020 - has started profiling\n"
5113 end
5114 if ($kgm_spi_flag & 0x00000040)
5115 printf " 0x00000040 - in select; wakeup/waiting danger\n"
5116 end
5117 if ($kgm_spi_flag & 0x00000080)
5118 printf " 0x00000080 - was stopped and continued\n"
5119 end
5120 if ($kgm_spi_flag & 0x00000100)
5121 printf " 0x00000100 - has set privileges since exec\n"
5122 end
5123 if ($kgm_spi_flag & 0x00000200)
5124 printf " 0x00000200 - system process: no signals, stats, or swap\n"
5125 end
5126 if ($kgm_spi_flag & 0x00000400)
5127 printf " 0x00000400 - timing out during a sleep\n"
5128 end
5129 if ($kgm_spi_flag & 0x00000800)
5130 printf " 0x00000800 - debugged process being traced\n"
5131 end
5132 if ($kgm_spi_flag & 0x00001000)
5133 printf " 0x00001000 - debugging process has waited for child\n"
5134 end
5135 if ($kgm_spi_flag & 0x00002000)
5136 printf " 0x00002000 - exit in progress\n"
5137 end
5138 if ($kgm_spi_flag & 0x00004000)
5139 printf " 0x00004000 - process has called exec\n"
5140 end
5141 if ($kgm_spi_flag & 0x00008000)
5142 printf " 0x00008000 - owe process an addupc() XXX\n"
5143 end
5144 if ($kgm_spi_flag & 0x00010000)
5145 printf " 0x00010000 - affinity for Rosetta children\n"
5146 end
5147 if ($kgm_spi_flag & 0x00020000)
5148 printf " 0x00020000 - wants to run Rosetta\n"
5149 end
5150 if ($kgm_spi_flag & 0x00040000)
5151 printf " 0x00040000 - has wait() in progress\n"
5152 end
5153 if ($kgm_spi_flag & 0x00080000)
5154 printf " 0x00080000 - kdebug tracing on for this process\n"
5155 end
5156 if ($kgm_spi_flag & 0x00100000)
5157 printf " 0x00100000 - blocked due to SIGTTOU or SIGTTIN\n"
5158 end
5159 if ($kgm_spi_flag & 0x00200000)
5160 printf " 0x00200000 - has called reboot()\n"
5161 end
5162 if ($kgm_spi_flag & 0x00400000)
5163 printf " 0x00400000 - is TBE state\n"
5164 end
5165 if ($kgm_spi_flag & 0x00800000)
5166 printf " 0x00800000 - signal exceptions\n"
5167 end
5168 if ($kgm_spi_flag & 0x01000000)
b0d623f7 5169 printf " 0x01000000 - has thread cwd\n"
2d21ac55
A
5170 end
5171 if ($kgm_spi_flag & 0x02000000)
5172 printf " 0x02000000 - has vfork() children\n"
5173 end
5174 if ($kgm_spi_flag & 0x04000000)
5175 printf " 0x04000000 - not allowed to attach\n"
5176 end
5177 if ($kgm_spi_flag & 0x08000000)
5178 printf " 0x08000000 - vfork() in progress\n"
5179 end
5180 if ($kgm_spi_flag & 0x10000000)
5181 printf " 0x10000000 - no shared libraries\n"
5182 end
5183 if ($kgm_spi_flag & 0x20000000)
5184 printf " 0x20000000 - force quota for root\n"
5185 end
5186 if ($kgm_spi_flag & 0x40000000)
5187 printf " 0x40000000 - no zombies when children exit\n"
5188 end
5189 if ($kgm_spi_flag & 0x80000000)
5190 printf " 0x80000000 - don't hang on remote FS ops\n"
5191 end
5192 # decode state
5193 set $kgm_spi_state = $kgm_spi_proc->p_stat
5194 printf "State: "
5195 if ($kgm_spi_state == 1)
5196 printf "Idle\n"
5197 end
5198 if ($kgm_spi_state == 2)
5199 printf "Run\n"
5200 end
5201 if ($kgm_spi_state == 3)
5202 printf "Sleep\n"
5203 end
5204 if ($kgm_spi_state == 4)
5205 printf "Stop\n"
5206 end
5207 if ($kgm_spi_state == 5)
5208 printf "Zombie\n"
5209 end
5210 if ($kgm_spi_state == 6)
5211 printf "Reaping\n"
5212 end
5213 if ($kgm_spi_state < 1 || $kgm_spi_state > 6)
5214 printf "(Unknown)\n"
5215 end
5216end
5217
5218document showprocinfo
5219Syntax: (gdb) showprocinfo <proc_t>
5220| Displays name, pid, parent and task for a proc_t. Decodes cred, flag and p_stat fields.
5221end
5222
5223#
5224# dump the zombprocs
5225#
5226define zombproc
5227 set $basep = (struct proc *)zombproc->lh_first
5228 set $pp = $basep
5229 while $pp
5230 showprocinfo $pp
5231 set $pp = $pp->p_list.le_next
5232 end
5233end
5234
5235document zombproc
5236Syntax: (gdb) zombproc
5237| Routine to print out all procs in the zombie list
5238end
5239
5240#
5241# dump the zombstacks
5242#
5243define zombstacks
5244 set $basep = (struct proc *)zombproc->lh_first
5245 set $pp = $basep
5246 while $pp
5247 if $pp->p_stat != 5
5248 showtaskstacks $pp->task
5249 end
5250 set $pp = $pp->p_list.le_next
5251 end
5252end
5253
5254document zombstacks
5255Syntax: (gdb) zombstacks
5256| Routine to print out all stacks of tasks that are exiting
5257end
5258
5259
5260#
5261# dump the allprocs
5262#
5263define allproc
5264 set $basep = (struct proc *)allproc->lh_first
5265 set $pp = $basep
5266 while $pp
5267 showprocinfo $pp
5268 set $pp = $pp->p_list.le_next
5269 end
5270end
5271
5272document allproc
5273Syntax: (gdb) allproc
5274| Routine to print out all process in the system
5275| which are not in the zombie list
5276end
6d2010ae
A
5277define showprocsiblingint
5278 set $kgm_sibling_ptr = (struct proc *)$arg0
5279 set $kgm_lx = $arg1
5280 while $kgm_lx
5281 printf "| "
5282 set $kgm_lx = $kgm_lx-3
5283 end
5284 printf "|--%d %s [ 0x%llx ]\n", $kgm_sibling_ptr->p_pid, $kgm_sibling_ptr->p_comm, $kgm_sibling_ptr
5285end
5286define showproctreeint
5287#Initialize all the set variables used in this macro
5288 set $kgm_basep1 = 0
5289 set $kgm_sibling_ptr = 0
5290 set $kgm_lx = 0
5291 set $kgm_tmp_base = 0
5292 set $kgm_head_ptr = 0
5293 set $kgm_search_pid = 0
5294 set $kgm_rev = 0
5295 set $kgm_x = 0
5296
5297 set $kgm_basep1 = (struct proc *)allproc->lh_first
5298 if ($arg0 == 0)
5299 set $kgm_head_ptr = (struct proc *)initproc
5300 end
5301 if ($arg0 > 0)
5302 set $kgm_tmp_base = (struct proc *)allproc->lh_first
5303 set $kgm_search_pid = $arg0
5304 while $kgm_tmp_base
5305 if ( $kgm_tmp_base->p_pid == $kgm_search_pid)
5306 if ($kgm_tmp_base->p_childrencnt > 0)
5307 set $kgm_head_ptr = $kgm_tmp_base->p_children.lh_first
5308 else
5309 set $kgm_head_ptr = 0
5310 printf "No children present for PID=%d", $kgm_search_pid
5311 end
5312 loop_break
5313 end
5314 set $kgm_tmp_base = $kgm_tmp_base->p_list.le_next
5315 end
5316 end
5317 set $kgm_rev = 0
5318 set $kgm_x = 0
5319 if ($kgm_head_ptr)
5320 printf "PID PROCESS POINTER]\n"
5321 printf "=== ======= =======\n"
5322 printf "%d %s [ 0x%llx ]\n", $kgm_head_ptr->p_ppid, $kgm_head_ptr->p_pptr->p_comm, $kgm_head_ptr
5323 printf "|--%d %s [ 0x%llx ]\n", $kgm_head_ptr->p_pid, $kgm_head_ptr->p_comm, $kgm_head_ptr
5324 end
5325 while ($kgm_head_ptr)
5326 #Is childrencnt = 0? YES {=> no children}
5327 if ($kgm_head_ptr->p_childrencnt == 0)
5328 # Does it have sibling?
5329 if($kgm_head_ptr->p_sibling.le_next == 0)
5330 #No, it does not have sibling, so go back to its parent which will go to its sibling
5331 if($kgm_head_ptr == $kgm_head_ptr->p_pptr)
5332 loop_break
5333 end
5334 set $kgm_head_ptr = $kgm_head_ptr->p_pptr
5335 if ($kgm_head_ptr == $kgm_tmp_base)
5336 loop_break
5337 end
5338 if ($kgm_x > 3)
5339 set $kgm_x = $kgm_x - 3
5340 end
5341 set $kgm_rev = 1
5342 end
5343 if($kgm_head_ptr->p_sibling.le_next != 0)
5344 # Yes, it has sibling. So print sibling
5345 set $kgm_rev = 0
5346 showprocsiblingint $kgm_head_ptr->p_sibling.le_next $kgm_x
5347 set $kgm_head_ptr = $kgm_head_ptr->p_sibling.le_next
5348 end
5349 # childrencnt != 0 {=> it has children}
5350 else
5351 if ($kgm_rev == 1)
5352 if($kgm_head_ptr->p_sibling.le_next == 0)
5353 #No, it does not have sibling, so go back to its parent which will go to its sibling
5354 if($kgm_head_ptr == $kgm_head_ptr->p_pptr)
5355 loop_break
5356 end
5357 set $kgm_head_ptr = $kgm_head_ptr->p_pptr
5358 if ($kgm_head_ptr == $kgm_tmp_base)
5359 loop_break
5360 end
2d21ac55 5361
6d2010ae
A
5362 if ($kgm_x > 3)
5363 set $kgm_x = $kgm_x - 3
5364 end
5365 set $kgm_rev = 1
5366 end
5367 if($kgm_head_ptr->p_sibling.le_next != 0)
5368 set $kgm_rev = 0
5369 # Yes, it has sibling. So print sibling
5370 showprocsiblingint $kgm_head_ptr->p_sibling.le_next $kgm_x
5371 set $kgm_head_ptr = $kgm_head_ptr->p_sibling.le_next
5372 end
5373 else
5374 set $kgm_head_ptr = $kgm_head_ptr->p_children.lh_first
5375 set $kgm_x = $kgm_x + 3
5376 set $kgm_lx = $kgm_x
5377 while $kgm_lx
5378 printf "| "
5379 set $kgm_lx = $kgm_lx-3
5380 end
5381 printf "|--%d %s [ 0x%llx ] \n", $kgm_head_ptr->p_pid, $kgm_head_ptr->p_comm, $kgm_head_ptr
5382 end
5383 end
5384 end
5385 printf "\n"
5386#Unset all the set variables used in this macro
5387 set $kgm_basep1 = 0
5388 set $kgm_sibling_ptr = 0
5389 set $kgm_lx = 0
5390 set $kgm_tmp_base = 0
5391 set $kgm_head_ptr = 0
5392 set $kgm_search_pid = 0
5393 set $kgm_rev = 0
5394 set $kgm_x = 0
5395end
5396define showproctree
5397 if ($argc > 0)
5398 showproctreeint $arg0
5399 else
5400 showproctreeint 0
5401 end
5402end
5403document showproctree
5404Syntax: (gdb) showproctree <pid>
5405| Routine to print the processes in the system in a hierarchical tree form. This routine does not print zombie processes.
5406| If no argument is given, showproctree will print all the processes in the system.
5407| If pid is specified, showproctree prints all the descendants of the indicated process
5408end
2d21ac55
A
5409
5410
5411define print_vnode
5412 set $vp = (struct vnode *)$arg0
5413 printf " "
b0d623f7
A
5414 printf " vp "
5415 showptr $vp
2d21ac55
A
5416 printf " use %d", $vp->v_usecount
5417 printf " io %d", $vp->v_iocount
5418 printf " kuse %d", $vp->v_kusecount
5419 printf " type %d", $vp->v_type
5420 printf " flg 0x%.8x", $vp->v_flag
5421 printf " lflg 0x%.8x", $vp->v_lflag
b0d623f7
A
5422 printf " par "
5423 showptr $vp->v_parent
2d21ac55
A
5424 set $_name = (char *)$vp->v_name
5425 if ($_name != 0)
5426 printf " %s", $_name
5427 end
5428 if ($vp->v_type == VREG) && ($vp->v_un.vu_ubcinfo != 0)
5429 printf " mapped %d", ($vp->v_un.vu_ubcinfo.ui_flags & 0x08) ? 1 : 0
5430 end
5431 printf "\n"
5432end
5433
5434document print_vnode
5435Syntax: (gdb) print_vnode <vnode>
5436| Prints out the fields of a vnode struct
5437end
5438
5439define showprocvnodes
5440 set $pp = (struct proc *)$arg0
5441 set $fdp = (struct filedesc *)$pp->p_fd
5442 set $cvp = $fdp->fd_cdir
5443 set $rvp = $fdp->fd_rdir
5444 if $cvp
5445 printf "Current Working Directory \n"
5446 print_vnode $cvp
5447 printf "\n"
5448 end
5449 if $rvp
5450 printf "Current Root Directory \n"
5451 print_vnode $rvp
5452 printf "\n"
5453 end
5454 set $count = 0
5455 set $fpp = (struct fileproc **)($fdp->fd_ofiles)
5456 set $fpo = (char)($fdp->fd_ofileflags[0])
5457 while $count < $fdp->fd_nfiles
5458 #printf"fpp %x ", *$fpp
5459 if *$fpp
5460 set $fg =(struct fileglob *)((**$fpp)->f_fglob)
5461 if $fg && (($fg)->fg_type == 1)
5462 if $fdp->fd_ofileflags[$count] & 4
5463 printf "U: "
5464 else
5465 printf " "
5466 end
5467 printf "fd = %d ", $count
5468 print_vnode $fg->fg_data
5469 end
5470 end
5471 set $fpp = $fpp + 1
5472 set $count = $count + 1
5473 end
5474end
5475
5476document showprocvnodes
5477Syntax: (gdb) showprocvnodes <proc_address>
5478| Routine to print out all the open fds
5479| which are vnodes in a process
5480end
5481
5482define showallprocvnodes
5483 set $basep = (struct proc *)allproc->lh_first
5484 set $pp = $basep
5485 while $pp
5486 printf "============================================ \n"
5487 showprocinfo $pp
5488 showprocvnodes $pp
5489 set $pp = $pp->p_list.le_next
5490 end
5491end
5492
5493document showallprocvnodes
5494Syntax: (gdb) showallprocvnodes
5495| Routine to print out all the open fds
5496| which are vnodes
5497end
5498
5499
5500#
5501# dump the childrent of a proc
5502#
5503define showinitchild
5504 set $basep = (struct proc *)initproc->p_children.lh_first
5505 set $pp = $basep
5506 while $pp
5507 showprocinfo $pp
5508 set $pp = $pp->p_sibling.le_next
5509 end
5510end
5511
5512document showinitchild
5513Syntax: (gdb) showinitchild
5514| Routine to print out all processes in the system
5515| which are children of init process
5516end
5517
5518
5519define showmountallvnodes
5520 set $mp = (struct mount *)$arg0
5521 set $basevp = (struct vnode *)$mp->mnt_vnodelist.tqh_first
5522 set $vp = $basevp
5523 printf "____________________ Vnode list Queue ---------------\n"
5524 while $vp
5525 print_vnode $vp
5526 set $vp = $vp->v_mntvnodes->tqe_next
5527 end
5528 set $basevp = (struct vnode *)$mp->mnt_workerqueue.tqh_first
5529 set $vp = $basevp
5530 printf "____________________ Worker Queue ---------------\n"
5531 while $vp
5532 print_vnode $vp
5533 set $vp = $vp->v_mntvnodes->tqe_next
5534 end
5535 set $basevp = (struct vnode *)$mp->mnt_newvnodes.tqh_first
5536 set $vp = $basevp
5537 printf "____________________ New vnodes Queue ---------------\n"
5538 while $vp
5539 print_vnode $vp
5540 set $vp = $vp->v_mntvnodes->tqe_next
5541 end
5542end
5543document showmountallvnodes
5544Syntax: showmountallvnodes <struct mount *>
5545| Print the vnode inactive list
5546end
5547
5548
5549define showmountvnodes
5550 set $mp = (struct mount *)$arg0
5551 set $basevp = (struct vnode *)$mp->mnt_vnodelist.tqh_first
5552 set $vp = $basevp
5553 printf "____________________ Vnode list Queue ---------------\n"
5554 while $vp
5555 print_vnode $vp
5556 set $vp = $vp->v_mntvnodes->tqe_next
5557 end
5558end
5559document showmountvnodes
5560Syntax: showmountvnodes <struct mount *>
5561| Print the vnode list
5562end
5563
5564
5565
5566define showworkqvnodes
5567 set $mp = (struct mount *)$arg0
5568 set $basevp = (struct vnode *)$mp->mnt_workerqueue.tqh_first
5569 set $vp = $basevp
5570 printf "____________________ Worker Queue ---------------\n"
5571 while $vp
5572 print_vnode $vp
5573 set $vp = $vp->v_mntvnodes->tqe_next
5574 end
5575end
5576document showworkqvnodes
5577Syntax: showworkqvnodes <struct mount *>
5578| Print the vnode worker list
5579end
5580
5581
5582define shownewvnodes
5583 set $mp = (struct mount *)$arg0
5584 set $basevp = (struct vnode *)$mp->mnt_newvnodes.tqh_first
5585 set $vp = $basevp
5586 printf "____________________ New vnodes Queue ---------------\n"
5587 while $vp
5588 print_vnode $vp
5589 set $vp = $vp->v_mntvnodes->tqe_next
5590 end
5591end
5592
5593document shownewvnodes
5594Syntax: shownewvnodes <struct mount *>
5595| Print the new vnode list
5596end
5597
5598
5599#
5600# print mount point info
5601define print_mount
5602 set $mp = (struct mount *)$arg0
5603 printf " "
b0d623f7
A
5604 printf " mp "
5605 showptr $mp
2d21ac55
A
5606 printf " flag %x", $mp->mnt_flag
5607 printf " kern_flag %x", $mp->mnt_kern_flag
5608 printf " lflag %x", $mp->mnt_lflag
5609 printf " type: %s", $mp->mnt_vfsstat.f_fstypename
5610 printf " mnton: %s", $mp->mnt_vfsstat.f_mntonname
5611 printf " mntfrom: %s", $mp->mnt_vfsstat.f_mntfromname
5612 printf "\n"
5613end
5614
5615define showallmounts
5616 set $mp=(struct mount *)mountlist.tqh_first
5617 while $mp
5618 print_mount $mp
5619 set $mp = $mp->mnt_list.tqe_next
5620 end
5621end
5622
5623document showallmounts
5624Syntax: showallmounts
5625| Print all mount points
5626end
5627
5628define pcprint
b0d623f7
A
5629 if (((unsigned long) $arg0 < (unsigned long) &_mh_execute_header || \
5630 (unsigned long) $arg0 >= (unsigned long) &last_kernel_symbol ))
5631 showkmodaddr $arg0
2d21ac55 5632 else
b0d623f7 5633 output /a $arg0
2d21ac55
A
5634 end
5635end
5636
5637define mbuf_walkpkt
5638 set $mp = (struct mbuf *)$arg0
5639 set $cnt = 1
5640 set $tot = 0
5641 while $mp
b0d623f7 5642 printf "%4d: %p [len %4d, type %2d, ", $cnt, $mp, \
2d21ac55
A
5643 $mp->m_hdr.mh_len, $mp->m_hdr.mh_type
5644 if mclaudit != 0
5645 mbuf_buf2mca $mp
5646 printf ", "
5647 end
5648 set $tot = $tot + $mp->m_hdr.mh_len
5649 printf "total %d]\n", $tot
5650 set $mp = $mp->m_hdr.mh_nextpkt
5651 set $cnt = $cnt + 1
5652 end
5653end
5654
5655document mbuf_walkpkt
5656Syntax: (gdb) mbuf_walkpkt <addr>
5657| Given an mbuf address, walk its m_nextpkt pointer
5658end
5659
5660define mbuf_walk
5661 set $mp = (struct mbuf *)$arg0
5662 set $cnt = 1
5663 set $tot = 0
5664 while $mp
b0d623f7 5665 printf "%4d: %p [len %4d, type %2d, ", $cnt, $mp, \
2d21ac55
A
5666 $mp->m_hdr.mh_len, $mp->m_hdr.mh_type
5667 if mclaudit != 0
5668 mbuf_buf2mca $mp
5669 printf ", "
5670 end
5671 set $tot = $tot + $mp->m_hdr.mh_len
5672 printf "total %d]\n", $tot
5673 set $mp = $mp->m_hdr.mh_next
5674 set $cnt = $cnt + 1
5675 end
5676end
5677
5678document mbuf_walk
5679Syntax: (gdb) mbuf_walk <addr>
5680| Given an mbuf address, walk its m_next pointer
5681end
5682
5683define mbuf_buf2slab
5684 set $addr = $arg0
5685 set $gix = ((char *)$addr - (char *)mbutl) >> 20
6d2010ae 5686 set $ix = ((char *)$addr - (char *)slabstbl[$gix].slg_slab[0].sl_base) >> 12
2d21ac55 5687 set $slab = &slabstbl[$gix].slg_slab[$ix]
6d2010ae
A
5688 if $kgm_lp64
5689 printf "0x%-16llx", $slab
5690 else
5691 printf "0x%-8x", $slab
5692 end
2d21ac55
A
5693end
5694
5695document mbuf_buf2slab
5696| Given an mbuf object, find its corresponding slab address.
5697end
5698
5699define mbuf_buf2mca
5700 set $addr = $arg0
6d2010ae
A
5701 set $ix = ((char *)$addr - (char *)mbutl) >> 12
5702 set $clbase = ((union mbigcluster *)mbutl) + $ix
2d21ac55
A
5703 set $mclidx = (((char *)$addr - (char *)$clbase) >> 8)
5704 set $mca = mclaudit[$ix].cl_audit[$mclidx]
6d2010ae
A
5705 if $kgm_lp64
5706 printf "mca: 0x%-16llx", $mca
5707 else
5708 printf "mca: 0x%-8x", $mca
5709 end
2d21ac55
A
5710end
5711
5712document mbuf_buf2mca
5713Syntax: (gdb) mbuf_buf2mca <addr>
5714| Given an mbuf object, find its buffer audit structure address.
5715| This requires mbuf buffer auditing to be turned on, by setting
5716| the appropriate flags to the "mbuf_debug" boot-args parameter.
5717end
5718
5719define mbuf_showmca
5720 set language c
5721 set $mca = (mcache_audit_t *)$arg0
5722 set $cp = (mcache_t *)$mca->mca_cache
5723 printf "object type:\t\t"
5724 mbuf_mca_ctype $mca 1
5725 printf "\ncontrolling mcache:\t%p (%s)\n", $mca->mca_cache, $cp->mc_name
5726 if $mca->mca_uflags & $MB_SCVALID
6d2010ae
A
5727 set $ix = ((char *)$mca->mca_addr - (char *)mbutl) >> 12
5728 set $clbase = ((union mbigcluster *)mbutl) + $ix
2d21ac55
A
5729 set $mclidx = (((char *)$mca->mca_addr - (char *)$clbase) >> 8)
5730 printf "mbuf obj:\t\t%p\n", $mca->mca_addr
6d2010ae 5731 printf "mbuf index:\t\t%d (out of 16) in cluster base %p\n", \
2d21ac55
A
5732 $mclidx + 1, $clbase
5733 if $mca->mca_uptr != 0
5734 set $peer_mca = (mcache_audit_t *)$mca->mca_uptr
5735 printf "paired cluster obj:\t%p (mca %p)\n", \
5736 $peer_mca->mca_addr, $peer_mca
5737 end
5738 printf "saved contents:\t\t%p (%d bytes)\n", \
5739 $mca->mca_contents, $mca->mca_contents_size
5740 else
5741 printf "cluster obj:\t\t%p\n", $mca->mca_addr
5742 if $mca->mca_uptr != 0
5743 set $peer_mca = (mcache_audit_t *)$mca->mca_uptr
5744 printf "paired mbuf obj:\t%p (mca %p)\n", \
5745 $peer_mca->mca_addr, $peer_mca
5746 end
5747 end
5748 printf "recent transaction for this buffer (thread %p):\n", \
5749 $mca->mca_thread
5750 set $cnt = 0
5751 while $cnt < $mca->mca_depth
b0d623f7 5752 set $kgm_pc = $mca->mca_stack[$cnt]
2d21ac55 5753 printf "%4d: ", $cnt + 1
b0d623f7 5754 pcprint $kgm_pc
2d21ac55
A
5755 printf "\n"
5756 set $cnt = $cnt + 1
5757 end
5758 if $mca->mca_pdepth > 0
5759 printf "previous transaction for this buffer (thread %p):\n", \
5760 $mca->mca_pthread
5761 end
5762 set $cnt = 0
5763 while $cnt < $mca->mca_pdepth
b0d623f7 5764 set $kgm_pc = $mca->mca_pstack[$cnt]
2d21ac55 5765 printf "%4d: ", $cnt + 1
b0d623f7 5766 pcprint $kgm_pc
2d21ac55
A
5767 printf "\n"
5768 set $cnt = $cnt + 1
5769 end
5770 set language auto
5771end
5772
5773document mbuf_showmca
5774Syntax: (gdb) mbuf_showmca <addr>
5775| Given an mbuf/cluster buffer audit structure address, print the audit
5776| records including the stack trace of the last buffer transaction.
5777end
5778
6d2010ae
A
5779define mbuf_topleak
5780 set language c
5781 set $topcnt = 0
5782 if $arg0 < 5
5783 set $maxcnt = $arg0
5784 else
5785 set $maxcnt = 5
5786 end
5787 while $topcnt < $maxcnt
5788 mbuf_traceleak mleak_top_trace[$topcnt]
5789 set $topcnt = $topcnt + 1
5790 end
5791 set language auto
5792end
5793
5794document mbuf_topleak
5795Syntax: (gdb) mbuf_topleak <num>
5796| Prints information about the top <num> suspected mbuf leakers
5797| where <num> is a value <= 5
5798end
5799
5800define mbuf_traceleak
5801 set language c
5802 set $trace = (struct mtrace *) $arg0
5803 if $trace->allocs != 0
5804 printf "%p:%d outstanding allocs\n", $trace, $trace->allocs
5805 printf "backtrace saved %d deep:\n", $trace->depth
5806 if $trace->depth != 0
5807 set $cnt = 0
5808 while $cnt < $trace->depth
5809 printf "%4d: ", $cnt + 1
5810 pcprint $trace->addr[$cnt]
5811 printf "\n"
5812 set $cnt = $cnt + 1
5813 end
5814 end
5815 end
5816 set language auto
5817end
5818
5819document mbuf_traceleak
5820Syntax: (gdb) mbuf_traceleak <addr>
5821| Given an mbuf leak trace (mtrace) structure address, print out the
5822| stored information with that trace
5823end
5824
5825set $MCF_NOCPUCACHE = 0x10
5826
5827define mcache_stat
5828 set $head = (mcache_t *)mcache_head
2d21ac55 5829 set $mc = $head
b0d623f7
A
5830
5831 if $kgm_lp64
5832 printf "cache cache cache buf buf backing (# of retries) bufs\n"
5833 printf "name state addr size align zone wait nowait failed incache\n"
5834 printf "------------------------- -------- ------------------ ------ ----- ------------------ -------------------------- --------\n"
5835 else
5836 printf "cache cache cache buf buf backing (# of retries) bufs\n"
5837 printf "name state addr size align zone wait nowait failed incache\n"
5838 printf "------------------------- -------- ---------- ------ ----- ---------- -------------------------- --------\n"
5839 end
2d21ac55
A
5840 while $mc != 0
5841 set $bktsize = $mc->mc_cpu.cc_bktsize
5842 printf "%-25s ", $mc->mc_name
5843 if ($mc->mc_flags & $MCF_NOCPUCACHE)
5844 printf "disabled"
5845 else
5846 if $mc->mc_purge_cnt > 0
5847 printf " purging"
5848 else
5849 if $bktsize == 0
5850 printf " offline"
5851 else
5852 printf " online"
5853 end
5854 end
5855 end
b0d623f7 5856 printf " %p %6d %5d ",$mc, \
2d21ac55
A
5857 $mc->mc_bufsize, $mc->mc_align
5858 if $mc->mc_slab_zone != 0
b0d623f7 5859 printf "%p", $mc->mc_slab_zone
2d21ac55 5860 else
b0d623f7
A
5861 if $kgm_lp64
5862 printf " custom"
5863 else
5864 printf " custom"
5865 end
2d21ac55
A
5866 end
5867 set $tot = 0
5868 set $tot += $mc->mc_full.bl_total * $bktsize
5869 set $ccp = (mcache_cpu_t *)$mc->mc_cpu
5870 set $n = 0
5871 while $n < ncpu
5872 if $ccp->cc_objs > 0
5873 set $tot += $ccp->cc_objs
5874 end
5875 if $ccp->cc_pobjs > 0
5876 set $tot += $ccp->cc_pobjs
5877 end
5878 set $n += 1
5879 set $ccp += 1
5880 end
5881 printf " %8d %8d %8d %8d", $mc->mc_wretry_cnt, \
5882 $mc->mc_nwretry_cnt, $mc->mc_nwfail_cnt, $tot
5883 printf "\n"
5884 set $mc = (mcache_t *)$mc->mc_list.le_next
5885 end
5886end
5887
5888document mcache_stat
5889Syntax: (gdb) mcache_stat
5890| Print all mcaches in the system.
5891end
5892
5893define mcache_showzone
5894 set $mc = (mcache_t *)$arg0
5895 if $mc->mc_slab_zone != 0
5896 printf "%p", $mc->mc_slab_zone
5897 else
5898 printf " custom"
5899end
5900
5901document mcache_showzone
5902Syntax: (gdb) mcache_showzone <mcache_addr>
5903| Print the type of backend (custom or zone) of a mcache.
5904end
5905
5906define mcache_walkobj
5907 set $p = (mcache_obj_t *)$arg0
5908 set $cnt = 1
5909 set $tot = 0
5910 while $p
b0d623f7 5911 printf "%4d: %p\n", $cnt, $p,
2d21ac55
A
5912 set $p = $p->obj_next
5913 set $cnt = $cnt + 1
5914 end
5915end
5916
5917document mcache_walkobj
5918Syntax: (gdb) mcache_walkobj <addr>
5919| Given a mcache object address, walk its obj_next pointer
5920end
5921
5922define mcache_showcache
5923 set $cp = (mcache_t *)$arg0
5924 set $ccp = (mcache_cpu_t *)$cp->mc_cpu
5925 set $bktsize = $cp->mc_cpu.cc_bktsize
5926 set $cnt = 0
5927 set $tot = 0
5928 printf "Showing cache '%s':\n\n", $cp->mc_name
5929 printf " CPU cc_objs cc_pobjs total\n"
5930 printf "---- -------- -------- --------\n"
5931 while $cnt < ncpu
5932 set $objs = $ccp->cc_objs
5933 if $objs <= 0
5934 set $objs = 0
5935 end
5936 set $pobjs = $ccp->cc_pobjs
5937 if $pobjs <= 0
5938 set $pobjs = 0
5939 end
5940 set $tot_cpu = $objs + $pobjs
5941 set $tot += $tot_cpu
5942 printf "%4d %8d %8d %8d\n", $cnt, $objs, $pobjs, $tot_cpu
5943 set $ccp += 1
5944 set $cnt += 1
5945 end
5946 printf " ========\n"
5947 printf " %8d\n", $tot
5948 printf "\n"
5949 set $tot += $cp->mc_full.bl_total * $bktsize
5950 printf "Total # of full buckets (%d objs/bkt):\t%-8d\n", \
5951 $bktsize, $cp->mc_full.bl_total
5952 printf "Total # of objects cached:\t\t%-8d\n", $tot
5953end
5954
5955document mcache_showcache
5956| Display the number of objects in the cache
5957end
5958
5959set $NSLABSPMB = sizeof(mcl_slabg_t)/sizeof(mcl_slab_t)
5960
5961define mbuf_slabstbl
5962 set $x = 0
5963
6d2010ae
A
5964 if $kgm_lp64
5965 printf "slot slabg slabs range\n"
5966 printf "---- ------------------ -------------------------------------------\n"
5967 else
5968 printf "slot slabg slabs range\n"
5969 printf "---- ---------- ---------------------------\n"
5970 end
2d21ac55
A
5971 while $x < maxslabgrp
5972 set $slg = slabstbl[$x]
5973 printf "%3d: ", $x
5974 if $slg == 0
5975 printf "-\n"
5976 else
6d2010ae
A
5977 if $kgm_lp64
5978 printf "0x%-16llx [ 0x%-16llx - 0x%-16llx ]\n", $slg, &$slg->slg_slab[0], \
5979 &$slg->slg_slab[$NSLABSPMB-1]
5980 else
5981 printf "0x%-8x [ 0x%-8x - 0x%-8x ]\n", $slg, &$slg->slg_slab[0], \
5982 &$slg->slg_slab[$NSLABSPMB-1]
5983 end
2d21ac55
A
5984 end
5985 set $x += 1
5986 end
5987end
5988
5989document mbuf_slabstbl
5990| Display the mbuf slabs table
5991end
5992
5993set $SLF_MAPPED=0x0001
5994set $SLF_PARTIAL=0x0002
5995set $SLF_DETACHED=0x0004
5996
5997define mbuf_slabs
5998 set $slg = (mcl_slabg_t *)$arg0
5999 set $x = 0
6000
6d2010ae
A
6001 if $kgm_lp64
6002 printf "slot slab next obj mca C R N size flags\n"
6003 printf "---- ------------------ ------------------ ------------------ ------------------ -- -- -- ------ -----\n"
b0d623f7 6004 else
6d2010ae
A
6005 printf "slot slab next obj mca C R N size flags\n"
6006 printf "---- ---------- ---------- ---------- ---------- -- -- -- ------ -----\n"
b0d623f7 6007 end
2d21ac55
A
6008 while $x < $NSLABSPMB
6009 set $sl = &$slg->slg_slab[$x]
6d2010ae
A
6010 set $mca = 0
6011 set $obj = $sl->sl_base
6012
6013 if mclaudit != 0
6014 set $ix = ((char *)$obj - (char *)mbutl) >> 12
6015 set $clbase = ((union mbigcluster *)mbutl) + $ix
6016 set $mclidx = (((char *)$obj - (char *)$clbase) >> 8)
6017 set $mca = mclaudit[$ix].cl_audit[$mclidx]
6018 end
6019
6020 if $kgm_lp64
6021 printf "%3d: 0x%-16llx 0x%-16llx 0x%-16llx 0x%-16llx %2d %2d %2d %6d 0x%04x ", \
6022 $x + 1, $sl, $sl->sl_next, $obj, $mca, $sl->sl_class, \
6023 $sl->sl_refcnt, $sl->sl_chunks, $sl->sl_len, \
6024 $sl->sl_flags
6025 else
6026 printf "%3d: 0x%-8x 0x%-8x 0x%-8x 0x%-8x %2d %2d %2d %6d 0x%04x ", \
6027 $x + 1, $sl, $sl->sl_next, $obj, $mca, $sl->sl_class, \
6028 $sl->sl_refcnt, $sl->sl_chunks, $sl->sl_len, \
6029 $sl->sl_flags
6030 end
2d21ac55
A
6031 if $sl->sl_flags != 0
6032 printf "<"
6033 if $sl->sl_flags & $SLF_MAPPED
6034 printf "mapped"
6035 end
6036 if $sl->sl_flags & $SLF_PARTIAL
6037 printf ",partial"
6038 end
6039 if $sl->sl_flags & $SLF_DETACHED
6040 printf ",detached"
6041 end
6042 printf ">"
6043 end
6044 printf "\n"
6d2010ae
A
6045
6046 if $sl->sl_chunks > 1
6047 set $z = 1
6048 set $c = $sl->sl_len / $sl->sl_chunks
6049
6050 while $z < $sl->sl_chunks
6051 set $obj = $sl->sl_base + ($c * $z)
6052 set $mca = 0
6053
6054 if mclaudit != 0
6055 set $ix = ((char *)$obj - (char *)mbutl) >> 12
6056 set $clbase = ((union mbigcluster *)mbutl) + $ix
6057 set $mclidx = (((char *)$obj - (char *)$clbase) >> 8)
6058 set $mca = mclaudit[$ix].cl_audit[$mclidx]
6059 end
6060
6061 if $kgm_lp64
6062 printf " 0x%-16llx 0x%-16llx\n", $obj, $mca
6063 else
6064 printf " 0x%-8x 0x%-8x\n", $obj, $mca
6065 end
6066 set $z += 1
6067 end
6068 end
6069
2d21ac55
A
6070 set $x += 1
6071 end
6072end
6073
6074document mbuf_slabs
6075| Display all mbuf slabs in the group
6076end
6077
6078define mbuf_stat
6079 set $x = 0
6080
6081 printf "class total cached uncached inuse failed waiter notified purge\n"
6082 printf "name objs objs objs / slabs objs alloc count count count count\n"
6083 printf "---------------- -------- -------- ------------------- -------- ---------------- -------- -------- --------\n"
6084 while $x < (sizeof(mbuf_table) / sizeof(mbuf_table[0]))
6085 set $mbt = mbuf_table[$x]
6086 set $mcs = (mb_class_stat_t *)mbuf_table[$x].mtbl_stats
6087 set $tot = 0
6088 set $mc = $mbt->mtbl_cache
6089 set $bktsize = $mc->mc_cpu.cc_bktsize
6090 set $tot += $mc->mc_full.bl_total * $bktsize
6091 set $ccp = (mcache_cpu_t *)$mc->mc_cpu
6092 set $n = 0
6093 while $n < ncpu
6094 if $ccp->cc_objs > 0
6095 set $tot += $ccp->cc_objs
6096 end
6097 if $ccp->cc_pobjs > 0
6098 set $tot += $ccp->cc_pobjs
6099 end
6100 set $n += 1
6101 set $ccp += 1
6102 end
6103
6104 printf "%-16s %8d %8d %8d / %-8d %8d %16llu %8d %8llu %8llu", \
6105 $mcs->mbcl_cname, $mcs->mbcl_total, $tot, \
6106 $mcs->mbcl_infree, $mcs->mbcl_slab_cnt, \
6107 ($mcs->mbcl_total - $tot - $mcs->mbcl_infree), \
6108 $mcs->mbcl_fail_cnt, $mc->mc_waiter_cnt, \
6109 $mcs->mbcl_notified, $mcs->mbcl_purge_cnt
6110 printf "\n"
6111 set $x += 1
6112 end
6113end
6114
6115document mbuf_stat
6116| Print extended mbuf allocator statistics.
6117end
6118
6119set $MB_INUSE = 0x1
6120set $MB_COMP_INUSE = 0x2
6121set $MB_SCVALID = 0x4
6122
6123set $MCLBYTES = 2048
6124set $MSIZE = 256
6125set $NBPG = 4096
6126set $M16KCLBYTES = 16384
6127
6128define mbuf_mca_ctype
6129 set $mca = (mcache_audit_t *)$arg0
6130 set $vopt = $arg1
6131 set $cp = $mca->mca_cache
6132 set $class = (unsigned int)$cp->mc_private
6133 set $csize = mbuf_table[$class].mtbl_stats->mbcl_size
6134 set $done = 0
6135 if $csize == $MSIZE
6136 if $vopt
6137 printf "M (mbuf) "
6138 else
6139 printf "M "
6140 end
6141 set $done = 1
6142 end
6143 if !$done && $csize == $MCLBYTES
6144 if $vopt
6145 printf "CL (2K cluster) "
6146 else
6147 printf "CL "
6148 end
6149 set $done = 1
6150 end
6151 if !$done && $csize == $NBPG
6152 if $vopt
6153 printf "BCL (4K cluster) "
6154 else
6155 printf "BCL "
6156 end
6157 set $done = 1
6158 end
6159 if !$done && $csize == $M16KCLBYTES
6160 if $vopt
6161 printf "JCL (16K cluster) "
6162 else
6163 printf "JCL "
6164 end
6165 set $done = 1
6166 end
6167 if !$done && $csize == ($MSIZE+$MCLBYTES)
6168 if $mca->mca_uflags & $MB_SCVALID
6169 if $mca->mca_uptr
6170 printf "M+CL "
6171 if $vopt
6172 printf "(paired mbuf, 2K cluster)"
6173 end
6174 else
6175 printf "M-CL "
6176 if $vopt
6177 printf "(unpaired mbuf, 2K cluster) "
6178 end
6179 end
6180 else
6181 if $mca->mca_uptr
6182 printf "CL+M "
6183 if $vopt
6184 printf "(paired 2K cluster, mbuf) "
6185 end
6186 else
6187 printf "CL-M "
6188 if $vopt
6189 printf "(paired 2K cluster, mbuf) "
6190 end
6191 end
6192 end
6193 set $done = 1
6194 end
6195 if !$done && $csize == ($MSIZE+$NBPG)
6196 if $mca->mca_uflags & $MB_SCVALID
6197 if $mca->mca_uptr
6198 printf "M+BCL "
6199 if $vopt
6200 printf "(paired mbuf, 4K cluster) "
6201 end
6202 else
6203 printf "M-BCL "
6204 if $vopt
6205 printf "(unpaired mbuf, 4K cluster) "
6206 end
6207 end
6208 else
6209 if $mca->mca_uptr
6210 printf "BCL+M "
6211 if $vopt
6212 printf "(paired 4K cluster, mbuf) "
6213 end
6214 else
6215 printf "BCL-M "
6216 if $vopt
6217 printf "(unpaired 4K cluster, mbuf) "
6218 end
6219 end
6220 end
6221 set $done = 1
6222 end
6223 if !$done && $csize == ($MSIZE+$M16KCLBYTES)
6224 if $mca->mca_uflags & $MB_SCVALID
6225 if $mca->mca_uptr
6226 printf "M+JCL "
6227 if $vopt
6228 printf "(paired mbuf, 16K cluster) "
6229 end
6230 else
6231 printf "M-JCL "
6232 if $vopt
6233 printf "(unpaired mbuf, 16K cluster) "
6234 end
6235 end
6236 else
6237 if $mca->mca_uptr
6238 printf "JCL+M "
6239 if $vopt
6240 printf "(paired 16K cluster, mbuf) "
6241 end
6242 else
6243 printf "JCL-M "
6244 if $vopt
6245 printf "(unpaired 16K cluster, mbuf) "
6246 end
6247 end
6248 end
6249 set $done = 1
6250 end
6251 if !$done
6252 printf "unknown: %s ", $cp->mc_name
6253 end
6254end
6255
6256document mbuf_mca_ctype
6257| This is a helper macro for mbuf_show{active,inactive,all} that prints
6258| out the mbuf object type represented by a given mcache audit structure.
6259end
6260
6261define mbuf_showactive
b0d623f7
A
6262 if $argc == 0
6263 mbuf_walkallslabs 1 0
6264 else
6265 mbuf_walkallslabs 1 0 $arg0
6266 end
2d21ac55
A
6267end
6268
6269document mbuf_showactive
6270Syntax: (gdb) mbuf_showactive
6271| Walk the mbuf objects pool and print only the active ones; this
6272| requires mbuf debugging to be turned on, by setting the appropriate flags
6273| to the "mbuf_debug" boot-args parameter. Active objects are those that
6274| are outstanding (have not returned to the mbuf slab layer) and in use
6275| by the client (have not been freed).
6276end
6277
6278define mbuf_showinactive
6279 mbuf_walkallslabs 0 1
6280end
6281
6282document mbuf_showinactive
6283Syntax: (gdb) mbuf_showinactive
6284| Walk the mbuf objects pool and print only the inactive ones; this
6285| requires mbuf debugging to be turned on, by setting the appropriate flags
6286| to the "mbuf_debug" boot-args parameter. Inactive objects are those that
6287| are outstanding (have not returned to the mbuf slab layer) but have been
6288| freed by the client, i.e. they still reside in the mcache layer ready to
6289| be used for subsequent allocation requests.
6290end
6291
6292define mbuf_showall
6293 mbuf_walkallslabs 1 1
6294end
6295
6296document mbuf_showall
6297Syntax: (gdb) mbuf_showall
6298| Walk the mbuf objects pool and print them all; this requires
6299| mbuf debugging to be turned on, by setting the appropriate flags to the
6300| "mbuf_debug" boot-args parameter.
6301end
6302
6303define mbuf_mcaobjs
6304end
6305
6306define mbuf_walkallslabs
6307 set $show_a = $arg0
6308 set $show_f = $arg1
b0d623f7
A
6309 if $argc == 3
6310 set $show_tr = $arg2
6311 else
6312 set $show_tr = 0
6313 end
2d21ac55
A
6314 set $x = 0
6315 set $total = 0
6316 set $total_a = 0
6317 set $total_f = 0
6318
6319 printf "("
6320 if $show_a && !$show_f
6321 printf "Searching only for active "
6322 end
6323 if !$show_a && $show_f
6324 printf "Searching only for inactive "
6325 end
6326 if $show_a && $show_f
6327 printf "Displaying all "
6328 end
6329 printf "objects; this may take a while ...)\n\n"
6330
6d2010ae 6331 if $kgm_lp64
b0d623f7
A
6332 printf " slab mca obj allocation\n"
6333 printf "slot idx address address address type state\n"
6334 printf "---- ---- ------------------ ------------------ ------------------ ----- -----------\n"
6335 else
6336 printf " slab mca obj allocation\n"
6337 printf "slot idx address address address type state\n"
6338 printf "---- ---- ---------- ---------- ---------- ----- -----------\n"
6339 end
6340
2d21ac55
A
6341 while $x < slabgrp
6342 set $slg = slabstbl[$x]
6343 set $y = 0
6344 set $stop = 0
6345 while $y < $NSLABSPMB && $stop == 0
6346 set $sl = &$slg->slg_slab[$y]
6347 set $base = (char *)$sl->sl_base
6d2010ae
A
6348 set $ix = ($base - (char *)mbutl) >> 12
6349 set $clbase = ((union mbigcluster *)mbutl) + $ix
2d21ac55
A
6350 set $mclidx = ($base - (char *)$clbase) >> 8
6351 set $mca = mclaudit[$ix].cl_audit[$mclidx]
6352 set $first = 1
6353
6354 while $mca != 0 && $mca->mca_addr != 0
6355 set $printmca = 0
6356 if $mca->mca_uflags & ($MB_INUSE|$MB_COMP_INUSE)
6357 set $total_a = $total_a + 1
6358 set $printmca = $show_a
6359 else
6360 set $total_f = $total_f + 1
6361 set $printmca = $show_f
6362 end
6363
6364 if $printmca != 0
6365 if $first == 1
6d2010ae
A
6366 if $kgm_lp64
6367 printf "%4d %4d 0x%-16llx ", $x, $y, $sl
6368 else
6369 printf "%4d %4d 0x%-8x ", $x, $y, $sl
6370 end
2d21ac55 6371 else
b0d623f7
A
6372 if $kgm_lp64
6373 printf " "
6374 else
6375 printf " "
6376 end
2d21ac55
A
6377 end
6378
6d2010ae
A
6379 if $kgm_lp64
6380 printf "0x%-16llx 0x%-16llx ", $mca, $mca->mca_addr
6381 else
6382 printf "0x%-8x 0x%-8x ", $mca, $mca->mca_addr
6383 end
6384
2d21ac55
A
6385 mbuf_mca_ctype $mca 0
6386 if $mca->mca_uflags & ($MB_INUSE|$MB_COMP_INUSE)
6387 printf "active "
6388 else
6389 printf " freed "
6390 end
6391 if $first == 1
6392 set $first = 0
6393 end
6394 printf "\n"
6395 set $total = $total + 1
b0d623f7
A
6396
6397 if $show_tr != 0
6398 printf "recent transaction for this buffer (thread %p):\n", \
6399 $mca->mca_thread
6400 set $cnt = 0
6401 while $cnt < $mca->mca_depth
6402 set $kgm_pc = $mca->mca_stack[$cnt]
6403 printf "%4d: ", $cnt + 1
6404 pcprint $kgm_pc
6405 printf "\n"
6406 set $cnt = $cnt + 1
6407 end
6408 end
2d21ac55 6409 end
b0d623f7 6410
2d21ac55
A
6411 set $mca = $mca->mca_next
6412 end
6413 set $y += 1
6414 if $slg->slg_slab[$y].sl_base == 0
6415 set $stop = 1
6416 end
6417 end
6418 set $x += 1
6419 end
6420 if $total && $show_a && $show_f
6421 printf "\ntotal objects:\t%d\n", $total
6422 printf "active/unfreed:\t%d\n", $total_a
6423 printf "freed/in_cache:\t%d\n", $total_f
6424 end
6425end
6426
6427document mbuf_walkallslabs
6428| Walk the mbuf objects pool; this requires mbuf debugging to be
6429| turned on, by setting the appropriate flags to the "mbuf_debug" boot-args
6430| parameter. This is a backend routine for mbuf_show{active,inactive,all}.
6431end
6432
6d2010ae
A
6433define mbuf_countchain
6434 set $mp = (struct mbuf *)$arg0
6435
6436 set $pkt = 0
6437 set $nxt = 0
6438
6439 while $mp != 0
6440 set $pkt = $pkt + 1
6441
6442 set $mn = (struct mbuf *)$mp->m_hdr.mh_next
6443 while $mn != 0
6444 set $nxt = $nxt + 1
6445
6446 set $mn = (struct mbuf *)$mn->m_hdr.mh_next
6447 end
6448
6449 set $mp = $mp->m_hdr.mh_nextpkt
6450
6451 if (($pkt + $nxt) % 50) == 0
6452 printf "... %d\n", $pkt + $nxt
6453 end
6454 end
6455
6456 printf "\ntotal: %d (via m_next: %d)\n", $pkt + $nxt, $nxt
6457end
6458
6459document mbuf_countchain
6460Syntax: mbuf_countchain <addr>
6461| Count the total number of mbufs chained from the given the address of an mbuf.
6462| The routine follows both the m_next pointers and m_nextpkt pointers.
6463end
6464
b0d623f7
A
6465set $RTF_UP = 0x1
6466set $RTF_GATEWAY = 0x2
6467set $RTF_HOST = 0x4
6468set $RTF_REJECT = 0x8
6469set $RTF_DYNAMIC = 0x10
6470set $RTF_MODIFIED = 0x20
6471set $RTF_DONE = 0x40
6472set $RTF_DELCLONE = 0x80
6473set $RTF_CLONING = 0x100
6474set $RTF_XRESOLVE = 0x200
6475set $RTF_LLINFO = 0x400
6476set $RTF_STATIC = 0x800
6477set $RTF_BLACKHOLE = 0x1000
6478set $RTF_PROTO2 = 0x4000
6479set $RTF_PROTO1 = 0x8000
6480set $RTF_PRCLONING = 0x10000
6481set $RTF_WASCLONED = 0x20000
6482set $RTF_PROTO3 = 0x40000
6483set $RTF_PINNED = 0x100000
6484set $RTF_LOCAL = 0x200000
6485set $RTF_BROADCAST = 0x400000
6486set $RTF_MULTICAST = 0x800000
6487set $RTF_IFSCOPE = 0x1000000
6488set $RTF_CONDEMNED = 0x2000000
6489
6490set $AF_INET = 2
6491set $AF_INET6 = 30
6492set $AF_LINK = 18
6493
6494define rtentry_prdetails
6495 set $rt = (struct rtentry *)$arg0
6496 set $is_v6 = 0
6497
6498 set $dst = (struct sockaddr *)$rt->rt_nodes->rn_u.rn_leaf.rn_Key
6499 if $dst->sa_family == $AF_INET
6500 showsockaddr_in $dst
6501 printf " "
6502 else
6503 if $dst->sa_family == $AF_INET6
6504 showsockaddr_in6 $dst
6505 printf " "
6506 set $is_v6 = 1
6507 else
6508 if $dst->sa_family == $AF_LINK
6509 showsockaddr_dl $dst
6510 printf " "
6511 else
6512 showsockaddr_unspec $dst
6513 end
6514 end
6515 end
6516
6517 set $dst = (struct sockaddr *)$rt->rt_gateway
6518 if $dst->sa_family == $AF_INET
6519 showsockaddr_in $dst
6520 printf " "
6521 else
6522 if $dst->sa_family == $AF_INET6
6523 set $is_v6 = 1
6524 showsockaddr_in6 $dst
6525 printf " "
6526 else
6527 if $dst->sa_family == $AF_LINK
6528 showsockaddr_dl $dst
6529 if $is_v6
6530 printf " "
6531 else
6532 printf " "
6533 end
6534 else
6535 showsockaddr_unspec $dst
6536 end
6537 end
6538 end
6539
6540 if $rt->rt_flags & $RTF_WASCLONED
6541 if $kgm_lp64
6542 printf "%18p ", $rt->rt_parent
6543 else
6544 printf "%10p ", $rt->rt_parent
6545 end
6546 else
6547 if $kgm_lp64
6548 printf " "
6549 else
6550 printf " "
6551 end
6552 end
6553
6554 printf "%6u %8u ", $rt->rt_refcnt, $rt->rt_rmx.rmx_pksent
6555
6556 if $rt->rt_flags & $RTF_UP
6557 printf "U"
6558 end
6559 if $rt->rt_flags & $RTF_GATEWAY
6560 printf "G"
6561 end
6562 if $rt->rt_flags & $RTF_HOST
6563 printf "H"
6564 end
6565 if $rt->rt_flags & $RTF_REJECT
6566 printf "R"
6567 end
6568 if $rt->rt_flags & $RTF_DYNAMIC
6569 printf "D"
6570 end
6571 if $rt->rt_flags & $RTF_MODIFIED
6572 printf "M"
6573 end
6574 if $rt->rt_flags & $RTF_CLONING
6575 printf "C"
6576 end
6577 if $rt->rt_flags & $RTF_PRCLONING
6578 printf "c"
6579 end
6580 if $rt->rt_flags & $RTF_LLINFO
6581 printf "L"
6582 end
6583 if $rt->rt_flags & $RTF_STATIC
6584 printf "S"
6585 end
6586 if $rt->rt_flags & $RTF_PROTO1
6587 printf "1"
6588 end
6589 if $rt->rt_flags & $RTF_PROTO2
6590 printf "2"
6591 end
6592 if $rt->rt_flags & $RTF_PROTO3
6593 printf "3"
6594 end
6595 if $rt->rt_flags & $RTF_WASCLONED
6596 printf "W"
6597 end
6598 if $rt->rt_flags & $RTF_BROADCAST
6599 printf "b"
6600 end
6601 if $rt->rt_flags & $RTF_MULTICAST
6602 printf "m"
6603 end
6604 if $rt->rt_flags & $RTF_XRESOLVE
6605 printf "X"
6606 end
6607 if $rt->rt_flags & $RTF_BLACKHOLE
6608 printf "B"
6609 end
6610 if $rt->rt_flags & $RTF_IFSCOPE
6611 printf "I"
6612 end
6613
6614 printf "/%s%d", $rt->rt_ifp->if_name, $rt->rt_ifp->if_unit
6615end
6616
6617set $RNF_ROOT = 2
6618
6619define _rttable_dump
6620 set $rnh = $arg0
6621 set $rn = (struct radix_node *)$rnh->rnh_treetop
6622 set $rnh_cnt = $rnh->rnh_cnt
6623
6624 while $rn->rn_bit >= 0
6625 set $rn = $rn->rn_u.rn_node.rn_L
6626 end
6627
6628 while 1
6629 set $base = (struct radix_node *)$rn
6630 while ($rn->rn_parent->rn_u.rn_node.rn_R == $rn) && ($rn->rn_flags & $RNF_ROOT) == 0
6631 set $rn = $rn->rn_parent
6632 end
6633 set $rn = $rn->rn_parent->rn_u.rn_node.rn_R
6634 while $rn->rn_bit >= 0
6635 set $rn = $rn->rn_u.rn_node.rn_L
6636 end
6637 set $next = $rn
6638 while $base != 0
6639 set $rn = $base
6640 set $base = $rn->rn_u.rn_leaf.rn_Dupedkey
6641 if ($rn->rn_flags & $RNF_ROOT) == 0
6642
6643 set $rt = (struct rtentry *)$rn
6644
6645 if $kgm_lp64
6646 printf "%18p ", $rt
6647 else
6648 printf "%10p ", $rt
6649 end
6650 rtentry_prdetails $rt
6651 printf "\n"
6652
6653 end
6654 end
6655 set $rn = $next
6656 if ($rn->rn_flags & $RNF_ROOT) != 0
6657 loop_break
6658 end
6659 end
6660end
6661
6662
6663define show_rt_inet
6664 if $kgm_lp64
6665 printf " rtentry dst gw parent Refs Use flags/if\n"
6666 printf " ----------------- --------------- ----------------- ------------------ ------ -------- -----------\n"
6667 else
6668 printf " rtentry dst gw parent Refs Use flags/if\n"
6669 printf " --------- --------------- ----------------- ---------- ------ -------- -----------\n"
6670 end
6671 _rttable_dump rt_tables[2]
6672end
6673
6674document show_rt_inet
6675Syntax: (gdb) show_rt_inet
6676| Show the entries of the IPv4 routing table.
6677end
6678
6679define show_rt_inet6
6680 if $kgm_lp64
6681 printf " rtentry dst gw parent Refs Use flags/if\n"
6682 printf " ----------------- --------------------------------------- --------------------------------------- ------------------ ------ -------- -----------\n"
6683 else
6684 printf " rtentry dst gw parent Refs Use flags/if\n"
6685 printf " --------- --------------------------------------- --------------------------------------- ---------- ------ -------- -----------\n"
6686 end
6687 _rttable_dump rt_tables[30]
6688end
6689
6690document show_rt_inet6
6691Syntax: (gdb) show_rt_inet6
6692| Show the entries of the IPv6 routing table.
6693end
6694
2d21ac55
A
6695define rtentry_trash
6696 set $rtd = (struct rtentry_dbg *)rttrash_head.tqh_first
6697 set $cnt = 0
6698 while $rtd != 0
6699 if $cnt == 0
b0d623f7
A
6700 if $kgm_lp64
6701 printf " rtentry ref hold rele dst gw parent flags/if\n"
6702 printf " ----------------- --- ------ ------ --------------- ----- ------------------ -----------\n"
6703 else
6704 printf " rtentry ref hold rele dst gw parent flags/if\n"
6705 printf " --------- --- ------ ------ --------------- ----- ---------- -----------\n"
6706 end
2d21ac55 6707 end
b0d623f7 6708 printf "%4d: %p %3d %6d %6d ", $cnt + 1, $rtd, \
2d21ac55 6709 $rtd->rtd_refhold_cnt - $rtd->rtd_refrele_cnt, \
b0d623f7
A
6710 $rtd->rtd_refhold_cnt, $rtd->rtd_refrele_cnt
6711 rtentry_prdetails $rtd
6712 printf "\n"
2d21ac55
A
6713 set $rtd = $rtd->rtd_trash_link.tqe_next
6714 set $cnt = $cnt + 1
6715 end
6716end
6717
6718document rtentry_trash
6719Syntax: (gdb) rtentry_trash
6720| Walk the list of trash route entries; this requires route entry
6721| debugging to be turned on, by setting the appropriate flags to the
6722| "rte_debug" boot-args parameter.
6723end
6724
b0d623f7
A
6725set $CTRACE_STACK_SIZE = ctrace_stack_size
6726set $CTRACE_HIST_SIZE = ctrace_hist_size
2d21ac55
A
6727
6728define rtentry_showdbg
6729 set $rtd = (struct rtentry_dbg *)$arg0
6730 set $cnt = 0
6731
b0d623f7
A
6732 printf "Total holds:\t%d\n", $rtd->rtd_refhold_cnt
6733 printf "Total releases:\t%d\n", $rtd->rtd_refrele_cnt
2d21ac55
A
6734
6735 set $ix = 0
b0d623f7
A
6736 while $ix < $CTRACE_STACK_SIZE
6737 set $kgm_pc = $rtd->rtd_alloc.pc[$ix]
6738 if $kgm_pc != 0
2d21ac55
A
6739 if $ix == 0
6740 printf "\nAlloc (thread %p):\n", \
b0d623f7 6741 $rtd->rtd_alloc.th
2d21ac55
A
6742 end
6743 printf "%4d: ", $ix + 1
b0d623f7 6744 pcprint $kgm_pc
2d21ac55
A
6745 printf "\n"
6746 end
6747 set $ix = $ix + 1
6748 end
6749 set $ix = 0
b0d623f7
A
6750 while $ix < $CTRACE_STACK_SIZE
6751 set $kgm_pc = $rtd->rtd_free.pc[$ix]
6752 if $kgm_pc != 0
2d21ac55
A
6753 if $ix == 0
6754 printf "\nFree: (thread %p)\n", \
b0d623f7 6755 $rtd->rtd_free.th
2d21ac55
A
6756 end
6757 printf "%4d: ", $ix + 1
b0d623f7 6758 pcprint $kgm_pc
2d21ac55
A
6759 printf "\n"
6760 end
6761 set $ix = $ix + 1
6762 end
b0d623f7 6763 while $cnt < $CTRACE_HIST_SIZE
2d21ac55 6764 set $ix = 0
b0d623f7
A
6765 while $ix < $CTRACE_STACK_SIZE
6766 set $kgm_pc = $rtd->rtd_refhold[$cnt].pc[$ix]
6767 if $kgm_pc != 0
2d21ac55
A
6768 if $ix == 0
6769 printf "\nHold [%d] (thread %p):\n", \
6770 $cnt, $rtd->rtd_refhold[$cnt].th
6771 end
6772 printf "%4d: ", $ix + 1
b0d623f7 6773 pcprint $kgm_pc
2d21ac55
A
6774 printf "\n"
6775 end
6776 set $ix = $ix + 1
6777 end
6778 set $cnt = $cnt + 1
6779 end
6780 set $cnt = 0
b0d623f7 6781 while $cnt < $CTRACE_HIST_SIZE
2d21ac55 6782 set $ix = 0
b0d623f7
A
6783 while $ix < $CTRACE_STACK_SIZE
6784 set $kgm_pc = $rtd->rtd_refrele[$cnt].pc[$ix]
6785 if $kgm_pc != 0
2d21ac55
A
6786 if $ix == 0
6787 printf "\nRelease [%d] (thread %p):\n",\
6788 $cnt, $rtd->rtd_refrele[$cnt].th
6789 end
6790 printf "%4d: ", $ix + 1
b0d623f7 6791 pcprint $kgm_pc
2d21ac55
A
6792 printf "\n"
6793 end
6794 set $ix = $ix + 1
6795 end
6796 set $cnt = $cnt + 1
6797 end
b0d623f7
A
6798
6799 printf "\nTotal locks:\t%d\n", $rtd->rtd_lock_cnt
6800 printf "Total unlocks:\t%d\n", $rtd->rtd_unlock_cnt
6801
6802 set $cnt = 0
6803 while $cnt < $CTRACE_HIST_SIZE
6804 set $ix = 0
6805 while $ix < $CTRACE_STACK_SIZE
6806 set $kgm_pc = $rtd->rtd_lock[$cnt].pc[$ix]
6807 if $kgm_pc != 0
6808 if $ix == 0
6809 printf "\nLock [%d] (thread %p):\n",\
6810 $cnt, $rtd->rtd_lock[$cnt].th
6811 end
6812 printf "%4d: ", $ix + 1
6813 pcprint $kgm_pc
6814 printf "\n"
6815 end
6816 set $ix = $ix + 1
6817 end
6818 set $cnt = $cnt + 1
6819 end
6820 set $cnt = 0
6821 while $cnt < $CTRACE_HIST_SIZE
6822 set $ix = 0
6823 while $ix < $CTRACE_STACK_SIZE
6824 set $kgm_pc = $rtd->rtd_unlock[$cnt].pc[$ix]
6825 if $kgm_pc != 0
6826 if $ix == 0
6827 printf "\nUnlock [%d] (thread %p):\n",\
6828 $cnt, $rtd->rtd_unlock[$cnt].th
6829 end
6830 printf "%4d: ", $ix + 1
6831 pcprint $kgm_pc
6832 printf "\n"
6833 end
6834 set $ix = $ix + 1
6835 end
6836 set $cnt = $cnt + 1
6837 end
6838end
6839
6840document rtentry_showdbg
6841Syntax: (gdb) rtentry_showdbg <addr>
6842| Given a route entry structure address, print the debug information
6843| related to it. This requires route entry debugging to be turned
6844| on, by setting the appropriate flags to the "rte_debug" boot-args
6845| parameter.
6846end
6847
6d2010ae
A
6848set $INIFA_TRACE_HIST_SIZE = inifa_trace_hist_size
6849
b0d623f7
A
6850define inifa_showdbg
6851 set $inifa = (struct in_ifaddr_dbg *)$arg0
6852 set $cnt = 0
6853
6854 printf "Total holds:\t%d\n", $inifa->inifa_refhold_cnt
6855 printf "Total releases:\t%d\n", $inifa->inifa_refrele_cnt
6856
6857 set $ix = 0
6858 while $ix < $CTRACE_STACK_SIZE
6859 set $kgm_pc = $inifa->inifa_alloc.pc[$ix]
6860 if $kgm_pc != 0
6861 if $ix == 0
6862 printf "\nAlloc (thread %p):\n", \
6863 $inifa->inifa_alloc.th
6864 end
6865 printf "%4d: ", $ix + 1
6866 pcprint $kgm_pc
6867 printf "\n"
6868 end
6869 set $ix = $ix + 1
6870 end
6871 set $ix = 0
6872 while $ix < $CTRACE_STACK_SIZE
6873 set $kgm_pc = $inifa->inifa_free.pc[$ix]
6874 if $kgm_pc != 0
6875 if $ix == 0
6876 printf "\nFree: (thread %p)\n", \
6877 $inifa->inifa_free.th
6878 end
6879 printf "%4d: ", $ix + 1
6880 pcprint $kgm_pc
6881 printf "\n"
6882 end
6883 set $ix = $ix + 1
6884 end
6d2010ae 6885 while $cnt < $INIFA_TRACE_HIST_SIZE
b0d623f7
A
6886 set $ix = 0
6887 while $ix < $CTRACE_STACK_SIZE
6888 set $kgm_pc = $inifa->inifa_refhold[$cnt].pc[$ix]
6889 if $kgm_pc != 0
6890 if $ix == 0
6891 printf "\nHold [%d] (thread %p):\n", \
6892 $cnt, $inifa->inifa_refhold[$cnt].th
6893 end
6894 printf "%4d: ", $ix + 1
6895 pcprint $kgm_pc
6896 printf "\n"
6897 end
6898 set $ix = $ix + 1
6899 end
6900 set $cnt = $cnt + 1
6901 end
6902 set $cnt = 0
6d2010ae 6903 while $cnt < $INIFA_TRACE_HIST_SIZE
b0d623f7
A
6904 set $ix = 0
6905 while $ix < $CTRACE_STACK_SIZE
6906 set $kgm_pc = $inifa->inifa_refrele[$cnt].pc[$ix]
6907 if $kgm_pc != 0
6908 if $ix == 0
6909 printf "\nRelease [%d] (thread %p):\n",\
6910 $cnt, $inifa->inifa_refrele[$cnt].th
6911 end
6912 printf "%4d: ", $ix + 1
6913 pcprint $kgm_pc
6914 printf "\n"
6915 end
6916 set $ix = $ix + 1
6917 end
6918 set $cnt = $cnt + 1
6919 end
6920end
6921
6922document inifa_showdbg
6923Syntax: (gdb) inifa_showdbg <addr>
6924| Given an IPv4 interface structure address, print the debug information
6925| related to it. This requires interface address debugging to be turned
6926| on, by setting the appropriate flags to the "ifa_debug" boot-args
6927| parameter.
6928end
6929
6d2010ae
A
6930set $IN6IFA_TRACE_HIST_SIZE = in6ifa_trace_hist_size
6931
b0d623f7
A
6932define in6ifa_showdbg
6933 set $in6ifa = (struct in6_ifaddr_dbg *)$arg0
6934 set $cnt = 0
6935
6936 printf "Total holds:\t%d\n", $in6ifa->in6ifa_refhold_cnt
6937 printf "Total releases:\t%d\n", $in6ifa->in6ifa_refrele_cnt
6938
6939 set $ix = 0
6940 while $ix < $CTRACE_STACK_SIZE
6941 set $kgm_pc = $in6ifa->in6ifa_alloc.pc[$ix]
6942 if $kgm_pc != 0
6943 if $ix == 0
6944 printf "\nAlloc (thread %p):\n", \
6945 $in6ifa->in6ifa_alloc.th
6946 end
6947 printf "%4d: ", $ix + 1
6948 pcprint $kgm_pc
6949 printf "\n"
6950 end
6951 set $ix = $ix + 1
6952 end
6953 set $ix = 0
6954 while $ix < $CTRACE_STACK_SIZE
6955 set $kgm_pc = $in6ifa->in6ifa_free.pc[$ix]
6956 if $kgm_pc != 0
6957 if $ix == 0
6958 printf "\nFree: (thread %p)\n", \
6959 $in6ifa->in6ifa_free.th
6960 end
6961 printf "%4d: ", $ix + 1
6962 pcprint $kgm_pc
6963 printf "\n"
6964 end
6965 set $ix = $ix + 1
6966 end
6d2010ae 6967 while $cnt < $IN6IFA_TRACE_HIST_SIZE
b0d623f7
A
6968 set $ix = 0
6969 while $ix < $CTRACE_STACK_SIZE
6970 set $kgm_pc = $in6ifa->in6ifa_refhold[$cnt].pc[$ix]
6971 if $kgm_pc != 0
6972 if $ix == 0
6973 printf "\nHold [%d] (thread %p):\n", \
6974 $cnt, $in6ifa->in6ifa_refhold[$cnt].th
6975 end
6976 printf "%4d: ", $ix + 1
6977 pcprint $kgm_pc
6978 printf "\n"
6979 end
6980 set $ix = $ix + 1
6981 end
6982 set $cnt = $cnt + 1
6983 end
6984 set $cnt = 0
6d2010ae
A
6985 while $cnt < $IN6IFA_TRACE_HIST_SIZE
6986 set $ix = 0
6987 while $ix < $CTRACE_STACK_SIZE
6988 set $kgm_pc = $in6ifa->in6ifa_refrele[$cnt].pc[$ix]
6989 if $kgm_pc != 0
6990 if $ix == 0
6991 printf "\nRelease [%d] (thread %p):\n",\
6992 $cnt, $in6ifa->in6ifa_refrele[$cnt].th
6993 end
6994 printf "%4d: ", $ix + 1
6995 pcprint $kgm_pc
6996 printf "\n"
6997 end
6998 set $ix = $ix + 1
6999 end
7000 set $cnt = $cnt + 1
7001 end
7002end
7003
7004document in6ifa_showdbg
7005Syntax: (gdb) in6ifa_showdbg <addr>
7006| Given an IPv6 interface structure address, print the debug information
7007| related to it. This requires interface address debugging to be turned
7008| on, by setting the appropriate flags to the "ifa_debug" boot-args
7009| parameter.
7010end
7011
7012set $IFMA_TRACE_HIST_SIZE = ifma_trace_hist_size
7013
7014define ifma_showdbg
7015 set $ifma = (struct ifmultiaddr_dbg *)$arg0
7016 set $cnt = 0
7017
7018 printf "Total holds:\t%d\n", $ifma->ifma_refhold_cnt
7019 printf "Total releases:\t%d\n", $ifma->ifma_refrele_cnt
7020
7021 while $cnt < $IFMA_TRACE_HIST_SIZE
7022 set $ix = 0
7023 while $ix < $CTRACE_STACK_SIZE
7024 set $kgm_pc = $ifma->ifma_refhold[$cnt].pc[$ix]
7025 if $kgm_pc != 0
7026 if $ix == 0
7027 printf "\nHold [%d] (thread %p):\n", \
7028 $cnt, $ifma->ifma_refhold[$cnt].th
7029 end
7030 printf "%4d: ", $ix + 1
7031 pcprint $kgm_pc
7032 printf "\n"
7033 end
7034 set $ix = $ix + 1
7035 end
7036 set $cnt = $cnt + 1
7037 end
7038 set $cnt = 0
7039 while $cnt < $IFMA_TRACE_HIST_SIZE
7040 set $ix = 0
7041 while $ix < $CTRACE_STACK_SIZE
7042 set $kgm_pc = $ifma->ifma_refrele[$cnt].pc[$ix]
7043 if $kgm_pc != 0
7044 if $ix == 0
7045 printf "\nRelease [%d] (thread %p):\n",\
7046 $cnt, $ifma->ifma_refrele[$cnt].th
7047 end
7048 printf "%4d: ", $ix + 1
7049 pcprint $kgm_pc
7050 printf "\n"
7051 end
7052 set $ix = $ix + 1
7053 end
7054 set $cnt = $cnt + 1
7055 end
7056end
7057
7058document ifma_showdbg
7059Syntax: (gdb) ifma_showdbg <addr>
7060| Given a link multicast structure address, print the debug information
7061| related to it. This requires interface address debugging to be turned
7062| on, by setting the appropriate flags to the "ifa_debug" boot-args
7063| parameter.
7064end
7065
7066set $INM_TRACE_HIST_SIZE = inm_trace_hist_size
7067
7068define inm_showdbg
7069 set $inm = (struct in_multi_dbg *)$arg0
7070 set $cnt = 0
7071
7072 printf "Total holds:\t%d\n", $inm->inm_refhold_cnt
7073 printf "Total releases:\t%d\n", $inm->inm_refrele_cnt
7074
7075 while $cnt < $INM_TRACE_HIST_SIZE
7076 set $ix = 0
7077 while $ix < $CTRACE_STACK_SIZE
7078 set $kgm_pc = $inm->inm_refhold[$cnt].pc[$ix]
7079 if $kgm_pc != 0
7080 if $ix == 0
7081 printf "\nHold [%d] (thread %p):\n", \
7082 $cnt, $inm->inm_refhold[$cnt].th
7083 end
7084 printf "%4d: ", $ix + 1
7085 pcprint $kgm_pc
7086 printf "\n"
7087 end
7088 set $ix = $ix + 1
7089 end
7090 set $cnt = $cnt + 1
7091 end
7092 set $cnt = 0
7093 while $cnt < $INM_TRACE_HIST_SIZE
7094 set $ix = 0
7095 while $ix < $CTRACE_STACK_SIZE
7096 set $kgm_pc = $inm->inm_refrele[$cnt].pc[$ix]
7097 if $kgm_pc != 0
7098 if $ix == 0
7099 printf "\nRelease [%d] (thread %p):\n",\
7100 $cnt, $inm->inm_refrele[$cnt].th
7101 end
7102 printf "%4d: ", $ix + 1
7103 pcprint $kgm_pc
7104 printf "\n"
7105 end
7106 set $ix = $ix + 1
7107 end
7108 set $cnt = $cnt + 1
7109 end
7110end
7111
7112document inm_showdbg
7113Syntax: (gdb) inm_showdbg <addr>
7114| Given an IPv4 multicast structure address, print the debug information
7115| related to it. This requires interface address debugging to be turned
7116| on, by setting the appropriate flags to the "ifa_debug" boot-args
7117| parameter.
7118end
7119
7120set $IF_REF_TRACE_HIST_SIZE = if_ref_trace_hist_size
7121
7122define ifpref_showdbg
7123 set $dl_if = (struct dlil_ifnet_dbg *)$arg0
7124 set $cnt = 0
7125
7126 printf "Total references:\t%d\n", $dl_if->dldbg_if_refhold_cnt
7127 printf "Total releases:\t\t%d\n", $dl_if->dldbg_if_refrele_cnt
7128
7129 while $cnt < $IF_REF_TRACE_HIST_SIZE
7130 set $ix = 0
7131 while $ix < $CTRACE_STACK_SIZE
7132 set $kgm_pc = $dl_if->dldbg_if_refhold[$cnt].pc[$ix]
7133 if $kgm_pc != 0
7134 if $ix == 0
7135 printf "\nHold [%d] (thread %p):\n", \
7136 $cnt, \
7137 $dl_if->dldbg_if_refhold[$cnt].th
7138 end
7139 printf "%4d: ", $ix + 1
7140 pcprint $kgm_pc
7141 printf "\n"
7142 end
7143 set $ix = $ix + 1
7144 end
7145 set $cnt = $cnt + 1
7146 end
7147 set $cnt = 0
7148 while $cnt < $IF_REF_TRACE_HIST_SIZE
7149 set $ix = 0
7150 while $ix < $CTRACE_STACK_SIZE
7151 set $kgm_pc = $dl_if->dldbg_if_refrele[$cnt].pc[$ix]
7152 if $kgm_pc != 0
7153 if $ix == 0
7154 printf "\nRelease [%d] (thread %p):\n",\
7155 $cnt, \
7156 $dl_if->dldbg_if_refrele[$cnt].th
7157 end
7158 printf "%4d: ", $ix + 1
7159 pcprint $kgm_pc
7160 printf "\n"
7161 end
7162 set $ix = $ix + 1
7163 end
7164 set $cnt = $cnt + 1
7165 end
7166end
7167
7168document ifpref_showdbg
7169Syntax: (gdb) ifpref_showdbg <addr>
7170| Given an ifnet structure address, print the debug information
7171| related to its refcnt. This requires ifnet debugging to be turned
7172| on, by setting the appropriate flags to the "ifnet_debug" boot-args
7173| parameter.
7174end
7175
7176define in6ifa_trash
7177 set $ifa = (struct in6_ifaddr_dbg *)in6ifa_trash_head.tqh_first
7178 set $cnt = 0
7179 while $ifa != 0
7180 if $cnt == 0
7181 if $kgm_lp64
7182 printf " in6_ifa ref hold rele\n"
7183 printf " ----------------- --- ------ ------\n"
7184 else
7185 printf " in6_ifa ref hold rele\n"
7186 printf " --------- --- ------ ------\n"
7187 end
7188 end
7189 printf "%4d: %p %3d %6d %6d ", $cnt + 1, $ifa, \
7190 $ifa->in6ifa_refhold_cnt - $ifa->in6ifa_refrele_cnt, \
7191 $ifa->in6ifa_refhold_cnt, $ifa->in6ifa_refrele_cnt
7192 showsockaddr_in6 $ifa->in6ifa.ia_ifa.ifa_addr
7193 printf "\n"
7194 set $ifa = $ifa->in6ifa_trash_link.tqe_next
7195 set $cnt = $cnt + 1
7196 end
7197end
7198
7199set $NDPR_TRACE_HIST_SIZE = ndpr_trace_hist_size
7200
7201define ndpr_showdbg
7202 set $ndpr = (struct nd_prefix_dbg *)$arg0
7203 set $cnt = 0
7204
7205 printf "Total references:\t%d\n", $ndpr->ndpr_refhold_cnt
7206 printf "Total releases:\t\t%d\n", $ndpr->ndpr_refrele_cnt
7207
7208 while $cnt < $NDPR_TRACE_HIST_SIZE
7209 set $ix = 0
7210 while $ix < $CTRACE_STACK_SIZE
7211 set $kgm_pc = $ndpr->ndpr_refhold[$cnt].pc[$ix]
7212 if $kgm_pc != 0
7213 if $ix == 0
7214 printf "\nHold [%d] (thread %p):\n", \
7215 $cnt, \
7216 $ndpr->ndpr_refhold[$cnt].th
7217 end
7218 printf "%4d: ", $ix + 1
7219 pcprint $kgm_pc
7220 printf "\n"
7221 end
7222 set $ix = $ix + 1
7223 end
7224 set $cnt = $cnt + 1
7225 end
7226 set $cnt = 0
7227 while $cnt < $NDPR_TRACE_HIST_SIZE
7228 set $ix = 0
7229 while $ix < $CTRACE_STACK_SIZE
7230 set $kgm_pc = $ndpr->ndpr_refrele[$cnt].pc[$ix]
7231 if $kgm_pc != 0
7232 if $ix == 0
7233 printf "\nRelease [%d] (thread %p):\n",\
7234 $cnt, \
7235 $ndpr->ndpr_refrele[$cnt].th
7236 end
7237 printf "%4d: ", $ix + 1
7238 pcprint $kgm_pc
7239 printf "\n"
7240 end
7241 set $ix = $ix + 1
7242 end
7243 set $cnt = $cnt + 1
7244 end
7245end
7246
7247document ndpr_showdbg
7248Syntax: (gdb) ndpr_showdbg <addr>
7249| Given a nd_prefix structure address, print the debug information
7250| related to its refcnt. This requires the interface address debugging
7251| to be turned on, by setting the appropriate flags to the "ifa_debug"
7252| boot-args parameter.
7253end
7254
7255set $NDDR_TRACE_HIST_SIZE = nddr_trace_hist_size
7256
7257define nddr_showdbg
7258 set $nddr = (struct nd_defrouter_dbg *)$arg0
7259 set $cnt = 0
7260
7261 printf "Total references:\t%d\n", $nddr->nddr_refhold_cnt
7262 printf "Total releases:\t\t%d\n", $nddr->nddr_refrele_cnt
7263
7264 while $cnt < $NDDR_TRACE_HIST_SIZE
7265 set $ix = 0
7266 while $ix < $CTRACE_STACK_SIZE
7267 set $kgm_pc = $nddr->nddr_refhold[$cnt].pc[$ix]
7268 if $kgm_pc != 0
7269 if $ix == 0
7270 printf "\nHold [%d] (thread %p):\n", \
7271 $cnt, \
7272 $nddr->nddr_refhold[$cnt].th
7273 end
7274 printf "%4d: ", $ix + 1
7275 pcprint $kgm_pc
7276 printf "\n"
7277 end
7278 set $ix = $ix + 1
7279 end
7280 set $cnt = $cnt + 1
7281 end
7282 set $cnt = 0
7283 while $cnt < $NDDR_TRACE_HIST_SIZE
7284 set $ix = 0
7285 while $ix < $CTRACE_STACK_SIZE
7286 set $kgm_pc = $nddr->nddr_refrele[$cnt].pc[$ix]
7287 if $kgm_pc != 0
7288 if $ix == 0
7289 printf "\nRelease [%d] (thread %p):\n",\
7290 $cnt, \
7291 $nddr->nddr_refrele[$cnt].th
7292 end
7293 printf "%4d: ", $ix + 1
7294 pcprint $kgm_pc
7295 printf "\n"
7296 end
7297 set $ix = $ix + 1
7298 end
7299 set $cnt = $cnt + 1
7300 end
7301end
7302
7303document nddr_showdbg
7304Syntax: (gdb) nddr_showdbg <addr>
7305| Given a nd_defrouter structure address, print the debug information
7306| related to its refcnt. This requires the interface address debugging
7307| to be turned on, by setting the appropriate flags to the "ifa_debug"
7308| boot-args parameter.
7309end
7310set $IMO_TRACE_HIST_SIZE = imo_trace_hist_size
7311
7312define imo_showdbg
7313 set $imo = (struct ip_moptions_dbg *)$arg0
7314 set $cnt = 0
7315
7316 printf "Total references:\t%d\n", $imo->imo_refhold_cnt
7317 printf "Total releases:\t\t%d\n", $imo->imo_refrele_cnt
7318
7319 while $cnt < $IMO_TRACE_HIST_SIZE
7320 set $ix = 0
7321 while $ix < $CTRACE_STACK_SIZE
7322 set $kgm_pc = $imo->imo_refhold[$cnt].pc[$ix]
7323 if $kgm_pc != 0
7324 if $ix == 0
7325 printf "\nHold [%d] (thread %p):\n", \
7326 $cnt, \
7327 $imo->imo_refhold[$cnt].th
7328 end
7329 printf "%4d: ", $ix + 1
7330 pcprint $kgm_pc
7331 printf "\n"
7332 end
7333 set $ix = $ix + 1
7334 end
7335 set $cnt = $cnt + 1
7336 end
7337 set $cnt = 0
7338 while $cnt < $IMO_TRACE_HIST_SIZE
7339 set $ix = 0
7340 while $ix < $CTRACE_STACK_SIZE
7341 set $kgm_pc = $imo->imo_refrele[$cnt].pc[$ix]
7342 if $kgm_pc != 0
7343 if $ix == 0
7344 printf "\nRelease [%d] (thread %p):\n",\
7345 $cnt, \
7346 $imo->imo_refrele[$cnt].th
7347 end
7348 printf "%4d: ", $ix + 1
7349 pcprint $kgm_pc
7350 printf "\n"
7351 end
7352 set $ix = $ix + 1
7353 end
7354 set $cnt = $cnt + 1
7355 end
7356end
7357
7358document imo_showdbg
7359Syntax: (gdb) imo_showdbg <addr>
7360| Given a ip_moptions structure address, print the debug information
7361| related to its refcnt. This requires the interface address debugging
7362| to be turned on, by setting the appropriate flags to the "ifa_debug"
7363| boot-args parameter.
7364end
7365
7366set $IM6O_TRACE_HIST_SIZE = im6o_trace_hist_size
7367
7368define im6o_showdbg
7369 set $im6o = (struct ip6_moptions_dbg *)$arg0
7370 set $cnt = 0
7371
7372 printf "Total references:\t%d\n", $im6o->im6o_refhold_cnt
7373 printf "Total releases:\t\t%d\n", $im6o->im6o_refrele_cnt
7374
7375 while $cnt < $IM6O_TRACE_HIST_SIZE
7376 set $ix = 0
7377 while $ix < $CTRACE_STACK_SIZE
7378 set $kgm_pc = $im6o->im6o_refhold[$cnt].pc[$ix]
7379 if $kgm_pc != 0
7380 if $ix == 0
7381 printf "\nHold [%d] (thread %p):\n", \
7382 $cnt, \
7383 $im6o->im6o_refhold[$cnt].th
7384 end
7385 printf "%4d: ", $ix + 1
7386 pcprint $kgm_pc
7387 printf "\n"
7388 end
7389 set $ix = $ix + 1
7390 end
7391 set $cnt = $cnt + 1
7392 end
7393 set $cnt = 0
7394 while $cnt < $IM6O_TRACE_HIST_SIZE
7395 set $ix = 0
7396 while $ix < $CTRACE_STACK_SIZE
7397 set $kgm_pc = $im6o->im6o_refrele[$cnt].pc[$ix]
7398 if $kgm_pc != 0
7399 if $ix == 0
7400 printf "\nRelease [%d] (thread %p):\n",\
7401 $cnt, \
7402 $im6o->im6o_refrele[$cnt].th
7403 end
7404 printf "%4d: ", $ix + 1
7405 pcprint $kgm_pc
7406 printf "\n"
7407 end
7408 set $ix = $ix + 1
7409 end
7410 set $cnt = $cnt + 1
7411 end
7412end
7413
7414document im6o_showdbg
7415Syntax: (gdb) im6o_showdbg <addr>
7416| Given a ip6_moptions structure address, print the debug information
7417| related to its refcnt. This requires the interface address debugging
7418| to be turned on, by setting the appropriate flags to the "ifa_debug"
7419| boot-args parameter.
7420end
7421
7422document in6ifa_trash
7423Syntax: (gdb) in6ifa_trash
7424| Walk the list of trash in6_ifaddr entries; this requires interface
7425| address debugging to be turned on, by setting the appropriate flags
7426| to the "ifa_debug" boot-args parameter.
7427end
7428
7429define inifa_trash
7430 set $ifa = (struct in_ifaddr_dbg *)inifa_trash_head.tqh_first
7431 set $cnt = 0
7432 while $ifa != 0
7433 if $cnt == 0
7434 if $kgm_lp64
7435 printf " in_ifa ref hold rele\n"
7436 printf " ----------------- --- ------ ------\n"
7437 else
7438 printf " in_ifa ref hold rele\n"
7439 printf " --------- --- ------ ------\n"
7440 end
7441 end
7442 printf "%4d: %p %3d %6d %6d ", $cnt + 1, $ifa, \
7443 $ifa->inifa_refhold_cnt - $ifa->inifa_refrele_cnt, \
7444 $ifa->inifa_refhold_cnt, $ifa->inifa_refrele_cnt
7445 showsockaddr_in $ifa->inifa.ia_ifa.ifa_addr
7446 printf "\n"
7447 set $ifa = $ifa->inifa_trash_link.tqe_next
7448 set $cnt = $cnt + 1
7449 end
7450end
7451
7452document inifa_trash
7453Syntax: (gdb) inifa_trash
7454| Walk the list of trash in_ifaddr entries; this requires interface
7455| address debugging to be turned on, by setting the appropriate flags
7456| to the "ifa_debug" boot-args parameter.
7457end
7458
7459define ifma_trash
7460 set $ifma = (struct ifmultiaddr_dbg *)ifma_trash_head.tqh_first
7461 set $cnt = 0
7462 while $ifma != 0
7463 if $cnt == 0
7464 if $kgm_lp64
7465 printf " ifma ref hold rele\n"
7466 printf " ----------------- --- ------ ------\n"
7467 else
7468 printf " ifma ref hold rele\n"
7469 printf " --------- --- ------ ------\n"
7470 end
7471 end
7472 printf "%4d: %p %3d %6d %6d ", $cnt + 1, $ifma, \
7473 $ifma->ifma_refhold_cnt - $ifma->ifma_refrele_cnt, \
7474 $ifma->ifma_refhold_cnt, $ifma->ifma_refrele_cnt
7475 showsockaddr $ifma->ifma.ifma_addr
7476 printf " @ %s%d", $ifma->ifma.ifma_ifp->if_name, \
7477 $ifma->ifma.ifma_ifp->if_unit
7478 printf "\n"
7479 set $ifma = $ifma->ifma_trash_link.tqe_next
7480 set $cnt = $cnt + 1
7481 end
7482end
7483
7484document ifma_trash
7485Syntax: (gdb) ifma_trash
7486| Walk the list of trash ifmultiaddr entries; this requires interface
7487| address debugging to be turned on, by setting the appropriate flags
7488| to the "ifa_debug" boot-args parameter.
7489end
7490
7491define inm_trash
7492 set $inm = (struct in_multi_dbg *)inm_trash_head.tqh_first
7493 set $cnt = 0
7494 while $inm != 0
7495 if $cnt == 0
7496 if $kgm_lp64
7497 printf " inm ref hold rele\n"
7498 printf " ----------------- --- ------ ------\n"
7499 else
7500 printf " inm ref hold rele\n"
7501 printf " --------- --- ------ ------\n"
7502 end
7503 end
7504 printf "%4d: %p %3d %6d %6d ", $cnt + 1, $inm, \
7505 $inm->inm_refhold_cnt - $inm->inm_refrele_cnt, \
7506 $inm->inm_refhold_cnt, $inm->inm_refrele_cnt
7507 show_in_addr &($inm->inm.inm_addr)
7508 printf "\n"
7509 set $inm = $inm->inm_trash_link.tqe_next
7510 set $cnt = $cnt + 1
7511 end
7512end
7513
7514document inm_trash
7515Syntax: (gdb) inm_trash
7516| Walk the list of trash in_multi entries; this requires interface
7517| address debugging to be turned on, by setting the appropriate flags
7518| to the "ifa_debug" boot-args parameter.
7519end
7520
7521define in6m_trash
7522 set $in6m = (struct in6_multi_dbg *)in6m_trash_head.tqh_first
7523 set $cnt = 0
7524 while $in6m != 0
7525 if $cnt == 0
7526 if $kgm_lp64
7527 printf " in6m ref hold rele\n"
7528 printf " ----------------- --- ------ ------\n"
7529 else
7530 printf " in6m ref hold rele\n"
7531 printf " --------- --- ------ ------\n"
b0d623f7 7532 end
b0d623f7 7533 end
6d2010ae
A
7534 printf "%4d: %p %3d %6d %6d ", $cnt + 1, $in6m, \
7535 $in6m->in6m_refhold_cnt - $in6m->in6m_refrele_cnt, \
7536 $in6m->in6m_refhold_cnt, $in6m->in6m_refrele_cnt
7537 show_in_addr &($in6m->in6m.in6m_addr)
7538 printf "\n"
7539 set $in6m = $in6m->in6m_trash_link.tqe_next
b0d623f7
A
7540 set $cnt = $cnt + 1
7541 end
7542end
7543
6d2010ae
A
7544document in6m_trash
7545Syntax: (gdb) in6m_trash
7546| Walk the list of trash in6_multi entries; this requires interface
7547| address debugging to be turned on, by setting the appropriate flags
7548| to the "ifa_debug" boot-args parameter.
b0d623f7
A
7549end
7550
7551#
7552# print all OSMalloc stats
7553
7554define ostag_print
7555set $kgm_tagp = (OSMallocTag)$arg0
7556printf "0x%08x: ", $kgm_tagp
7557printf "%8d ",$kgm_tagp->OSMT_refcnt
7558printf "%8x ",$kgm_tagp->OSMT_state
7559printf "%8x ",$kgm_tagp->OSMT_attr
7560printf "%s ",$kgm_tagp->OSMT_name
7561printf "\n"
7562end
2d21ac55
A
7563
7564
7565define showosmalloc
7566printf "TAG COUNT STATE ATTR NAME\n"
6d2010ae
A
7567set $kgm_tagheadp = (struct _OSMallocTag_ *)&OSMalloc_tag_list
7568 set $kgm_tagptr = (struct _OSMallocTag_ * )($kgm_tagheadp->OSMT_link.next)
2d21ac55
A
7569 while $kgm_tagptr != $kgm_tagheadp
7570 ostag_print $kgm_tagptr
6d2010ae 7571 set $kgm_tagptr = (struct _OSMallocTag_ *)$kgm_tagptr->OSMT_link.next
2d21ac55
A
7572 end
7573 printf "\n"
7574end
7575document showosmalloc
7576Syntax: (gdb) showosmalloc
7577| Print the outstanding allocation count by OSMallocTags.
7578end
7579
7580
7581define systemlog
6d2010ae
A
7582 if msgbufp->msg_bufc[msgbufp->msg_bufx] == 0 \
7583 && msgbufp->msg_bufc[0] != 0
2d21ac55
A
7584 # The buffer hasn't wrapped, so take the easy (and fast!) path
7585 printf "%s", msgbufp->msg_bufc
7586 else
7587 set $kgm_msgbuf = *msgbufp
7588 set $kgm_syslog_bufsize = $kgm_msgbuf.msg_size
7589 set $kgm_syslog_bufend = $kgm_msgbuf.msg_bufx
7590 if $kgm_syslog_bufend >= $kgm_syslog_bufsize
7591 set $kgm_syslog_bufend = 0
7592 end
7593
7594 # print older messages from msg_bufx to end of buffer
7595 set $kgm_i = $kgm_syslog_bufend
7596 while $kgm_i < $kgm_syslog_bufsize
7597 set $kgm_syslog_char = $kgm_msgbuf.msg_bufc[$kgm_i]
7598 if $kgm_syslog_char == 0
7599 # break out of loop
7600 set $kgm_i = $kgm_syslog_bufsize
7601 else
7602 printf "%c", $kgm_syslog_char
7603 end
7604 set $kgm_i = $kgm_i + 1
7605 end
7606
7607 # print newer messages from start of buffer to msg_bufx
7608 set $kgm_i = 0
7609 while $kgm_i < $kgm_syslog_bufend
7610 set $kgm_syslog_char = $kgm_msgbuf.msg_bufc[$kgm_i]
6d2010ae
A
7611 if $kgm_syslog_char != 0
7612 printf "%c", $kgm_syslog_char
7613 end
2d21ac55
A
7614 set $kgm_i = $kgm_i + 1
7615 end
7616 end
7617 printf "\n"
7618end
7619document systemlog
7620| Syntax: systemlog
7621| Display the kernel's printf ring buffer
7622end
7623
b0d623f7
A
7624
7625define hexdump
7626 set $kgm_addr = (unsigned char *)$arg0
7627 set $kgm_len = $arg1
7628 while $kgm_len > 0
7629 showptr $kgm_addr
7630 printf ": "
7631 set $kgm_i = 0
7632 while $kgm_i < 16
7633 printf "%02x ", *($kgm_addr+$kgm_i)
7634 set $kgm_i += 1
7635 end
7636 printf " |"
7637 set $kgm_i = 0
7638 while $kgm_i < 16
7639 set $kgm_temp = *($kgm_addr+$kgm_i)
7640 if $kgm_temp < 32 || $kgm_temp >= 127
7641 printf "."
7642 else
7643 printf "%c", $kgm_temp
2d21ac55 7644 end
b0d623f7 7645 set $kgm_i += 1
2d21ac55 7646 end
b0d623f7
A
7647 printf "|\n"
7648 set $kgm_addr += 16
7649 set $kgm_len -= 16
2d21ac55
A
7650 end
7651end
b0d623f7
A
7652document hexdump
7653| Show the contents of memory as a hex/ASCII dump
2d21ac55 7654| The following is the syntax:
b0d623f7 7655| (gdb) hexdump <address> <length>
2d21ac55
A
7656end
7657
2d21ac55 7658
b0d623f7
A
7659define printcolonhex
7660 if ($argc == 2)
7661 set $addr = $arg0
7662 set $count = $arg1
7663 set $li = 0
7664 while ($li < $count)
7665 if ($li == 0)
7666 printf "%02x", (u_char)$addr[$li]
7667 end
7668 if ($li != 0)
7669 printf ":%02x", (u_char)$addr[$li]
7670 end
7671 set $li = $li + 1
7672 end
2d21ac55 7673 end
b0d623f7 7674end
2d21ac55 7675
b0d623f7
A
7676define showsockaddr_dl
7677 set $sdl = (struct sockaddr_dl *)$arg0
7678 if ($sdl == 0)
7679 printf "(null) "
2d21ac55 7680 else
b0d623f7
A
7681 if $sdl->sdl_nlen == 0 && $sdl->sdl_alen == 0 && $sdl->sdl_slen == 0
7682 printf "link#%3d ", $sdl->sdl_index
2d21ac55 7683 else
b0d623f7
A
7684 set $addr = $sdl->sdl_data + $sdl->sdl_nlen
7685 set $count = $sdl->sdl_alen
7686 printcolonhex $addr $count
7687 end
2d21ac55 7688 end
b0d623f7 7689end
2d21ac55 7690
b0d623f7
A
7691define showsockaddr_unspec
7692 set $sockaddr = (struct sockaddr *)$arg0
7693 set $addr = $sockaddr->sa_data
7694 set $count = $sockaddr->sa_len - 2
7695 printcolonhex $addr $count
2d21ac55
A
7696end
7697
b0d623f7
A
7698define showsockaddr_at
7699 set $sockaddr = (struct sockaddr *)$arg0
7700 set $addr = $sockaddr->sa_data
7701 set $count = $sockaddr->sa_len - 2
7702 printcolonhex $addr $count
7703end
2d21ac55 7704
6d2010ae
A
7705define show_in_addr
7706 set $ia = (unsigned char *)$arg0
7707 printf "%3u.%03u.%03u.%03u", $ia[0], $ia[1], $ia[2], $ia[3]
7708end
7709
2d21ac55
A
7710define showsockaddr_in
7711 set $sin = (struct sockaddr_in *)$arg0
7712 set $sa_bytes = (unsigned char *)&($sin->sin_addr)
6d2010ae
A
7713 show_in_addr $sa_bytes
7714end
7715
7716define show_in6_addr
7717 set $ia = (unsigned char *)$arg0
7718 printf "%2x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x", \
7719 $ia[0], $ia[1], $ia[2], $ia[3], $ia[4], $ia[5], $ia[6], $ia[7], $ia[8], $ia[9], $ia[10], $ia[11], $ia[12], $ia[13], $ia[14], $ia[15]
2d21ac55
A
7720end
7721
7722define showsockaddr_in6
7723 set $sin6 = (struct sockaddr_in6 *)$arg0
7724 set $sa_bytes = $sin6->sin6_addr.__u6_addr.__u6_addr8
6d2010ae 7725 show_in6_addr $sa_bytes
b0d623f7
A
7726end
7727
7728define showsockaddr_un
7729 set $sun = (struct sockaddr_un *)$arg0
7730 if $sun == 0
7731 printf "(null)"
7732 else
7733 if $sun->sun_path[0] == 0
7734 printf "\"\""
7735 else
7736 printf "%s", $sun->sun_path
7737 end
7738 end
2d21ac55
A
7739end
7740
7741define showifmultiaddrs
7742 set $ifp = (struct ifnet *)$arg0
7743 set $if_multi = (struct ifmultiaddr *)$ifp->if_multiaddrs->lh_first
7744 set $mymulti = $if_multi
7745 set $myi = 0
7746 while ($mymulti != 0)
6d2010ae 7747 printf "%2d. %p ", $myi, $mymulti
2d21ac55
A
7748 set $sa_family = $mymulti->ifma_addr.sa_family
7749 if ($sa_family == 2)
7750 if ($mymulti->ifma_ll != 0)
7751 showsockaddr_dl $mymulti->ifma_ll->ifma_addr
7752 printf " "
7753 end
7754 showsockaddr_in $mymulti->ifma_addr
7755 end
7756 if ($sa_family == 30)
7757 if ($mymulti->ifma_ll != 0)
7758 showsockaddr_dl $mymulti->ifma_ll->ifma_addr
7759 printf " "
7760 end
7761 showsockaddr_in6 $mymulti->ifma_addr
7762 end
7763 if ($sa_family == 18)
7764 showsockaddr_dl $mymulti->ifma_addr
7765 end
7766 if ($sa_family == 0)
7767 showsockaddr_unspec $mymulti->ifma_addr 6
7768 end
7769 printf " [%d]", $mymulti->ifma_refcount
7770 printf "\n"
7771 set $mymulti = $mymulti->ifma_link.le_next
7772 set $myi = $myi + 1
7773 end
7774end
7775
7776document showifmultiaddrs
7777Syntax showifmultiaddrs <ifp>
7778| show the (struct ifnet).if_multiaddrs list of multicast addresses for the given ifp
7779end
7780
6d2010ae
A
7781define showinmultiaddrs
7782 set $in_multi = (struct in_multi *)(in_multihead->lh_first)
7783 set $mymulti = $in_multi
7784 set $myi = 0
7785 while ($mymulti != 0)
7786 set $ifp = (struct ifnet *)$mymulti->inm_ifp
7787 printf "%2d. %p ", $myi, $mymulti
7788 show_in_addr &($mymulti->inm_addr)
7789 printf " (ifp %p [%s%d] ifma %p) ", $ifp, $ifp->if_name, \
7790 $ifp->if_unit, $mymulti->inm_ifma
7791 printf "\n"
7792 set $mymulti = $mymulti->inm_link.le_next
7793 set $myi = $myi + 1
7794 end
7795end
7796
7797document showinmultiaddrs
7798Syntax showinmultiaddrs
7799| show the contents of IPv4 multicast address records
7800end
7801
7802define showin6multiaddrs
7803 set $in6_multi = (struct in6_multi *)(in6_multihead->lh_first)
7804 set $mymulti = $in6_multi
7805 set $myi = 0
7806 while ($mymulti != 0)
7807 set $ifp = (struct ifnet *)$mymulti->in6m_ifp
7808 printf "%2d. %p ", $myi, $mymulti
7809 show_in6_addr &($mymulti->in6m_addr)
7810 printf " (ifp %p [%s%d] ifma %p) ", $ifp, $ifp->if_name, \
7811 $ifp->if_unit, $mymulti->in6m_ifma
7812 printf "\n"
7813 set $mymulti = $mymulti->in6m_entry.le_next
7814 set $myi = $myi + 1
7815 end
7816end
7817
7818document showin6multiaddrs
7819Syntax showin6multiaddrs
7820| show the contents of IPv6 multicast address records
7821end
7822
2d21ac55
A
7823define showsockaddr
7824 set $mysock = (struct sockaddr *)$arg0
7825 set $showsockaddr_handled = 0
7826 if ($mysock == 0)
7827 printf "(null)"
7828 else
7829 if ($mysock->sa_family == 0)
b0d623f7 7830 printf "UNSPC"
2d21ac55
A
7831 showsockaddr_unspec $mysock
7832 set $showsockaddr_handled = 1
7833 end
b0d623f7
A
7834 if ($mysock->sa_family == 1)
7835 printf "UNIX "
7836 showsockaddr_un $mysock
7837 set $showsockaddr_handled = 1
7838 end
2d21ac55 7839 if ($mysock->sa_family == 2)
b0d623f7 7840 printf "INET "
2d21ac55
A
7841 showsockaddr_in $mysock
7842 set $showsockaddr_handled = 1
7843 end
7844 if ($mysock->sa_family == 30)
b0d623f7 7845 printf "INET6 "
2d21ac55
A
7846 showsockaddr_in6 $mysock
7847 set $showsockaddr_handled = 1
7848 end
7849 if ($mysock->sa_family == 18)
b0d623f7 7850 printf "LINK "
2d21ac55
A
7851 showsockaddr_dl $mysock
7852 set $showsockaddr_handled = 1
7853 end
7854 if ($mysock->sa_family == 16)
b0d623f7 7855 printf "ATLK "
2d21ac55
A
7856 showsockaddr_at $mysock
7857 set $showsockaddr_handled = 1
7858 end
7859 if ($showsockaddr_handled == 0)
b0d623f7 7860 printf "FAM %d ", $mysock->sa_family
2d21ac55
A
7861 set $addr = $mysock->sa_data
7862 set $count = $mysock->sa_len
7863 printcolonhex $addr $count
7864 end
7865 end
7866end
7867
7868define showifflags
7869 set $flags = (u_short)$arg0
7870 set $first = 1
7871 printf "<"
7872 if ($flags & 0x1)
7873 printf "UP"
7874 set $first = 0
7875 end
7876 if ($flags & 0x2)
7877 if ($first == 1)
7878 set $first = 0
7879 else
7880 printf ","
7881 end
7882 printf "BROADCAST"
7883 end
7884 if ($flags & 0x4)
7885 printf "DEBUG"
7886 end
7887 if ($flags & 0x8)
7888 if ($first == 1)
7889 set $first = 0
7890 else
7891 printf ","
7892 end
7893 printf "LOOPBACK"
7894 end
7895 if ($flags & 0x10)
7896 if ($first == 1)
7897 set $first = 0
7898 else
7899 printf ","
7900 end
7901 printf "POINTTOPOINT"
7902 end
6d2010ae
A
7903## if ($flags & 0x20)
7904## if ($first == 1)
2d21ac55 7905# set $first = 0
6d2010ae 7906## else
2d21ac55
A
7907# printf ","
7908# end
7909# printf "NOTRAILERS"
7910# end
7911 if ($flags & 0x40)
7912 if ($first == 1)
7913 set $first = 0
7914 else
7915 printf ","
7916 end
7917 printf "RUNNING"
7918 end
7919 if ($flags & 0x80)
7920 if ($first == 1)
7921 set $first = 0
7922 else
7923 printf ","
7924 end
7925 printf "NOARP"
7926 end
7927 if ($flags & 0x100)
7928 if ($first == 1)
7929 set $first = 0
7930 else
7931 printf ","
7932 end
7933 printf "PROMISC"
7934 end
7935 if ($flags & 0x200)
7936 if ($first == 1)
7937 set $first = 0
7938 else
7939 printf ","
7940 end
7941 printf "ALLMULTI"
7942 end
7943 if ($flags & 0x400)
7944 if ($first == 1)
7945 set $first = 0
7946 else
7947 printf ","
7948 end
7949 printf "OACTIVE"
7950 end
7951 if ($flags & 0x800)
7952 if ($first == 1)
7953 set $first = 0
7954 else
7955 printf ","
7956 end
7957 printf "SIMPLEX"
7958 end
7959 if ($flags & 0x1000)
7960 if ($first == 1)
7961 set $first = 0
7962 else
7963 printf ","
7964 end
7965 printf "LINK0"
7966 end
7967 if ($flags & 0x2000)
7968 if ($first == 1)
7969 set $first = 0
7970 else
7971 printf ","
7972 end
7973 printf "LINK1"
7974 end
7975 if ($flags & 0x4000)
7976 if ($first == 1)
7977 set $first = 0
7978 else
7979 printf ","
7980 end
7981 printf "LINK2-ALTPHYS"
7982 end
7983 if ($flags & 0x8000)
7984 if ($first == 1)
7985 set $first = 0
7986 else
7987 printf ","
7988 end
7989 printf "MULTICAST"
7990 end
7991 printf ">"
7992end
7993
7994define showifaddrs
7995 set $ifp = (struct ifnet *)$arg0
7996 set $myifaddr = (struct ifaddr *)$ifp->if_addrhead->tqh_first
7997 set $myi = 0
7998 while ($myifaddr != 0)
6d2010ae 7999 printf "\t%d. %p ", $myi, $myifaddr
2d21ac55
A
8000 showsockaddr $myifaddr->ifa_addr
8001 printf " [%d]\n", $myifaddr->ifa_refcnt
8002 set $myifaddr = $myifaddr->ifa_link->tqe_next
8003 set $myi = $myi + 1
8004 end
8005end
8006
8007document showifaddrs
8008Syntax: showifaddrs <ifp>
8009| show the (struct ifnet).if_addrhead list of addresses for the given ifp
8010end
8011
8012define ifconfig
8013 set $ifconfig_all = 0
8014 if ($argc == 1)
8015 set $ifconfig_all = 1
8016 end
6d2010ae 8017 set $ifp = (struct ifnet *)(ifnet_head->tqh_first)
2d21ac55 8018 while ($ifp != 0)
b0d623f7 8019 printf "%s%d: flags=%hx", $ifp->if_name, $ifp->if_unit, (u_short)$ifp->if_flags
2d21ac55 8020 showifflags $ifp->if_flags
b0d623f7 8021 printf " index %d", $ifp->if_index
2d21ac55 8022 printf " mtu %d\n", $ifp->if_data.ifi_mtu
b0d623f7
A
8023 printf "\t(struct ifnet *)"
8024 showptr $ifp
8025 printf "\n"
2d21ac55
A
8026 if ($ifconfig_all == 1)
8027 showifaddrs $ifp
b0d623f7 8028 end
2d21ac55
A
8029 set $ifp = $ifp->if_link->tqe_next
8030 end
8031end
8032document ifconfig
8033Syntax: (gdb) ifconfig
8034| display ifconfig-like output, and print the (struct ifnet *) pointers for further inspection
8035end
8036
6d2010ae
A
8037set $DLIF_INUSE = 0x1
8038set $DLIF_REUSE = 0x2
8039
8040define showifnets
8041 set $all = 0
8042 if ($argc == 1)
8043 set $all = 1
8044 end
8045 set $dlifp = (struct dlil_ifnet *)(dlil_ifnet_head->tqh_first)
8046 while ($dlifp != 0)
8047 set $ifp = (struct ifnet *)$dlifp
8048 if ($dlifp->dl_if_flags & $DLIF_REUSE)
8049 printf "*"
8050 end
8051 if ($dlifp->dl_if_flags & $DLIF_INUSE)
8052 printf "%s%d: ", $ifp->if_name, $ifp->if_unit
8053 else
8054 printf "[%s%d]: ", $ifp->if_name, $ifp->if_unit
8055 end
8056 printf "flags=%hx", (u_short)$ifp->if_flags
8057 showifflags $ifp->if_flags
8058 printf " index %d", $ifp->if_index
8059 printf " mtu %d\n", $ifp->if_data.ifi_mtu
8060 printf "\t(struct ifnet *)"
8061 showptr $ifp
8062 printf "\n"
8063 if ($all == 1)
8064 showifaddrs $ifp
8065 end
8066 set $dlifp = $dlifp->dl_if_link->tqe_next
8067 end
8068end
8069
8070document showifnets
8071Syntax: (gdb) showifnets
8072| Display ifconfig-like output for all attached and detached interfaces
8073end
8074
b0d623f7
A
8075define _show_unix_domain_socket
8076 set $so = (struct socket *)$arg0
8077 set $pcb = (struct unpcb *)$so->so_pcb
8078 if $pcb == 0
8079 printf "unpcb: (null) "
8080 else
8081 printf "unpcb: %p ", $pcb
8082 printf "unp_vnode: %p ", $pcb->unp_vnode
8083 printf "unp_conn: %p ", $pcb->unp_conn
8084 printf "unp_addr: "
8085 showsockaddr_un $pcb->unp_addr
2d21ac55 8086 end
2d21ac55
A
8087end
8088
b0d623f7
A
8089define _show_in_port
8090 set $str = (unsigned char *)$arg0
8091 set $port = *(unsigned short *)$arg0
8092
8093 if (((($port & 0xff00) >> 8) == $str[0])) && ((($port & 0x00ff) == $str[1]))
8094 #printf "big endian "
8095 printf ":%d ", $port
8096 else
8097 #printf "little endian "
8098 printf ":%d ", (($port & 0xff00) >> 8) | (($port & 0x00ff) << 8)
2d21ac55
A
8099 end
8100end
8101
b0d623f7
A
8102define _show_in_addr_4in6
8103 set $ia = (unsigned char *)$arg0
8104 if $ia
8105 printf "%3u.%03u.%03u.%03u", $ia[0], $ia[1], $ia[2], $ia[3]
8106 end
2d21ac55
A
8107end
8108
b0d623f7
A
8109define _show_in6_addr
8110 set $ia = (unsigned char *)$arg0
8111 if $ia
8112 printf "%2x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x", \
8113 $ia[0], $ia[1], $ia[2], $ia[3], $ia[4], $ia[5], $ia[6], $ia[7], \
8114 $ia[8], $ia[9], $ia[10], $ia[11], $ia[12], $ia[13], $ia[14], $ia[15]
8115 end
2d21ac55
A
8116end
8117
b0d623f7
A
8118define _showtcpstate
8119 set $tp = (struct tcpcb *)$arg0
8120 if $tp
8121 if $tp->t_state == 0
8122 printf "CLOSED "
8123 end
8124 if $tp->t_state == 1
8125 printf "LISTEN "
8126 end
8127 if $tp->t_state == 2
8128 printf "SYN_SENT "
8129 end
8130 if $tp->t_state == 3
8131 printf "SYN_RCVD "
8132 end
8133 if $tp->t_state == 4
8134 printf "ESTABLISHED "
8135 end
8136 if $tp->t_state == 5
8137 printf "CLOSE_WAIT "
8138 end
8139 if $tp->t_state == 6
8140 printf "FIN_WAIT_1 "
8141 end
8142 if $tp->t_state == 7
8143 printf "CLOSING "
8144 end
8145 if $tp->t_state == 8
8146 printf "LAST_ACK "
8147 end
8148 if $tp->t_state == 9
8149 printf "FIN_WAIT_2 "
8150 end
8151 if $tp->t_state == 10
8152 printf "TIME_WAIT "
8153 end
2d21ac55 8154 end
b0d623f7
A
8155end
8156
8157define _showsockprotocol
8158 set $so = (struct socket *)$arg0
8159 set $inpcb = (struct inpcb *)$so->so_pcb
8160
8161 if $so->so_proto->pr_protocol == 6
8162 printf "TCP "
8163 _showtcpstate $inpcb->inp_ppcb
2d21ac55 8164 end
b0d623f7
A
8165 if $so->so_proto->pr_protocol == 17
8166 printf "UDP "
2d21ac55 8167 end
b0d623f7
A
8168 if $so->so_proto->pr_protocol == 1
8169 printf "ICMP "
2d21ac55 8170 end
b0d623f7
A
8171 if $so->so_proto->pr_protocol == 254
8172 printf "DIVERT "
2d21ac55 8173 end
b0d623f7
A
8174 if $so->so_proto->pr_protocol == 255
8175 printf "RAW "
2d21ac55 8176 end
b0d623f7 8177end
2d21ac55 8178
b0d623f7
A
8179define _show_ipv4_socket
8180 set $so = (struct socket *)$arg0
8181 set $inpcb = (struct inpcb *)$so->so_pcb
8182 if $inpcb == 0
8183 printf "inpcb: (null) "
2d21ac55 8184 else
b0d623f7
A
8185 printf "inpcb: %p ", $inpcb
8186
8187 _showsockprotocol $so
8188
8189 _show_in_addr_4in6 &$inpcb->inp_dependladdr.inp46_local
8190 _show_in_port &$inpcb->inp_lport
8191 printf "-> "
8192 _show_in_addr_4in6 &$inpcb->inp_dependfaddr.inp46_foreign
8193 _show_in_port &$inpcb->inp_fport
2d21ac55
A
8194 end
8195end
8196
b0d623f7
A
8197define _show_ipv6_socket
8198 set $so = (struct socket *)$arg0
8199 set $pcb = (struct inpcb *)$so->so_pcb
8200 if $pcb == 0
8201 printf "inpcb: (null) "
8202 else
8203 printf "inpcb: %p ", $pcb
2d21ac55 8204
b0d623f7 8205 _showsockprotocol $so
2d21ac55 8206
b0d623f7
A
8207 _show_in6_addr &$pcb->inp_dependladdr.inp6_local
8208 _show_in_port &$pcb->inp_lport
8209 printf "-> "
8210 _show_in6_addr &$pcb->inp_dependfaddr.inp6_foreign
8211 _show_in_port &$pcb->inp_fport
2d21ac55
A
8212 end
8213end
8214
2d21ac55 8215
b0d623f7
A
8216define showsocket
8217 set $so = (struct socket *)$arg0
8218 if $so == 0
8219 printf "so: (null) "
8220 else
8221 printf "so: %p ", $so
8222 if $so && $so->so_proto && $so->so_proto->pr_domain
8223 set $domain = (struct domain *) $so->so_proto->pr_domain
2d21ac55 8224
b0d623f7
A
8225 printf "%s ", $domain->dom_name
8226 if $domain->dom_family == 1
8227 _show_unix_domain_socket $so
8228 end
8229 if $domain->dom_family == 2
8230 _show_ipv4_socket $so
8231 end
8232 if $domain->dom_family == 30
8233 _show_ipv6_socket $so
2d21ac55 8234 end
2d21ac55 8235 end
2d21ac55 8236 end
b0d623f7 8237 printf "\n"
2d21ac55 8238end
b0d623f7
A
8239document showsocket
8240Syntax: (gdb) showsocket <socket_address>
8241| Routine to print out a socket
2d21ac55
A
8242end
8243
b0d623f7
A
8244define showprocsockets
8245 set $pp = (struct proc *)$arg0
8246 set $fdp = (struct filedesc *)$pp->p_fd
8247
8248 set $count = 0
8249 set $fpp = (struct fileproc **)($fdp->fd_ofiles)
8250 set $fpo = (char)($fdp->fd_ofileflags[0])
8251 while $count < $fdp->fd_nfiles
8252 if *$fpp
8253 set $fg =(struct fileglob *)((**$fpp)->f_fglob)
8254 if $fg && (($fg)->fg_type == 2)
8255 if $fdp->fd_ofileflags[$count] & 4
8256 printf "U: "
8257 else
8258 printf " "
8259 end
8260 printf "fd = %d ", $count
8261 if $fg->fg_data
8262 showsocket $fg->fg_data
8263 else
8264 printf "\n"
8265 end
8266 end
2d21ac55 8267 end
b0d623f7
A
8268 set $fpp = $fpp + 1
8269 set $count = $count + 1
2d21ac55
A
8270 end
8271end
b0d623f7
A
8272document showprocsockets
8273Syntax: (gdb) showprocsockets <proc_address>
8274| Routine to print out all the open fds
8275| which are sockets in a process
2d21ac55
A
8276end
8277
b0d623f7
A
8278define showallprocsockets
8279 set $basep = (struct proc *)allproc->lh_first
8280 set $pp = $basep
8281 while $pp
8282 printf "============================================ \n"
8283 showproc $pp
8284 showprocsockets $pp
8285 set $pp = $pp->p_list.le_next
8286 end
2d21ac55 8287end
b0d623f7
A
8288document showallprocsockets
8289Syntax: (gdb) showallprocsockets
8290| Routine to print out all the open fds
8291| which are sockets
8292end
8293
8294define _print_ntohs
8295 set $port = (unsigned short)$arg0
8296 set $port = (unsigned short)((($arg0 & 0xff00) >> 8) & 0xff)
8297 set $port |= (unsigned short)(($arg0 & 0xff) << 8)
8298 printf "%5d", $port
8299end
8300
8301set $INPCB_STATE_INUSE=0x1
8302set $INPCB_STATE_CACHED=0x2
8303set $INPCB_STATE_DEAD=0x3
8304
8305set $INP_RECVOPTS=0x01
8306set $INP_RECVRETOPTS=0x02
8307set $INP_RECVDSTADDR=0x04
8308set $INP_HDRINCL=0x08
8309set $INP_HIGHPORT=0x10
8310set $INP_LOWPORT=0x20
8311set $INP_ANONPORT=0x40
8312set $INP_RECVIF=0x80
8313set $INP_MTUDISC=0x100
8314set $INP_STRIPHDR=0x200
8315set $INP_FAITH=0x400
8316set $INP_INADDR_ANY=0x800
8317set $INP_RECVTTL=0x1000
8318set $INP_UDP_NOCKSUM=0x2000
8319set $IN6P_IPV6_V6ONLY=0x008000
8320set $IN6P_PKTINFO=0x010000
8321set $IN6P_HOPLIMIT=0x020000
8322set $IN6P_HOPOPTS=0x040000
8323set $IN6P_DSTOPTS=0x080000
8324set $IN6P_RTHDR=0x100000
8325set $IN6P_RTHDRDSTOPTS=0x200000
8326set $IN6P_AUTOFLOWLABEL=0x800000
8327set $IN6P_BINDV6ONLY=0x10000000
8328
8329set $INP_IPV4=0x1
8330set $INP_IPV6=0x2
8331
8332set $IPPROTO_TCP=6
8333set $IPPROTO_UDP=17
8334
8335define _dump_inpcb
8336 set $pcb = (struct inpcb *)$arg0
8337 if $kgm_lp64
8338 printf "%18p", $pcb
8339 else
8340 printf "%10p ", $pcb
8341 end
8342 if $arg1 == $IPPROTO_TCP
8343 printf "tcp"
8344 else
8345 if $arg1 == $IPPROTO_UDP
8346 printf "udp"
8347 else
8348 printf "%2d.", $arg1
8349 end
8350 end
8351 if ($pcb->inp_vflag & $INP_IPV4)
8352 printf "4 "
8353 end
8354 if ($pcb->inp_vflag & $INP_IPV6)
8355 printf "6 "
8356 end
2d21ac55 8357
b0d623f7
A
8358 if ($pcb->inp_vflag & $INP_IPV4)
8359 printf " "
8360 _show_in_addr &$pcb->inp_dependladdr.inp46_local.ia46_addr4
2d21ac55 8361 else
b0d623f7 8362 _show_in6_addr &$pcb->inp_dependladdr.inp6_local
2d21ac55 8363 end
b0d623f7
A
8364 printf " "
8365 _print_ntohs $pcb->inp_lport
8366 printf " "
8367 if ($pcb->inp_vflag & $INP_IPV4)
8368 printf " "
8369 _show_in_addr &($pcb->inp_dependfaddr.inp46_foreign.ia46_addr4)
8370 else
8371 _show_in6_addr &($pcb->inp_dependfaddr.inp6_foreign)
8372 end
8373 printf " "
8374 _print_ntohs $pcb->inp_fport
8375 printf " "
2d21ac55 8376
b0d623f7
A
8377 if $arg1 == $IPPROTO_TCP
8378 _showtcpstate $pcb->inp_ppcb
8379 end
2d21ac55 8380
b0d623f7
A
8381# printf "phd "
8382# set $phd = $pcb->inp_phd
8383# while $phd != 0
8384# printf " "
8385# _print_ntohs $phd->phd_port
8386# set $phd = $phd->phd_hash.le_next
8387# end
8388# printf ", "
8389 if ($pcb->inp_flags & $INP_RECVOPTS)
8390 printf "recvopts "
8391 end
8392 if ($pcb->inp_flags & $INP_RECVRETOPTS)
8393 printf "recvretopts "
8394 end
8395 if ($pcb->inp_flags & $INP_RECVDSTADDR)
8396 printf "recvdstaddr "
8397 end
8398 if ($pcb->inp_flags & $INP_HDRINCL)
8399 printf "hdrincl "
8400 end
8401 if ($pcb->inp_flags & $INP_HIGHPORT)
8402 printf "highport "
8403 end
8404 if ($pcb->inp_flags & $INP_LOWPORT)
8405 printf "lowport "
8406 end
8407 if ($pcb->inp_flags & $INP_ANONPORT)
8408 printf "anonport "
8409 end
8410 if ($pcb->inp_flags & $INP_RECVIF)
8411 printf "recvif "
8412 end
8413 if ($pcb->inp_flags & $INP_MTUDISC)
8414 printf "mtudisc "
8415 end
8416 if ($pcb->inp_flags & $INP_STRIPHDR)
8417 printf "striphdr "
8418 end
8419 if ($pcb->inp_flags & $INP_FAITH)
8420 printf "faith "
8421 end
8422 if ($pcb->inp_flags & $INP_INADDR_ANY)
8423 printf "inaddr_any "
8424 end
8425 if ($pcb->inp_flags & $INP_RECVTTL)
8426 printf "recvttl "
8427 end
8428 if ($pcb->inp_flags & $INP_UDP_NOCKSUM)
8429 printf "nocksum "
2d21ac55 8430 end
b0d623f7
A
8431 if ($pcb->inp_flags & $IN6P_IPV6_V6ONLY)
8432 printf "v6only "
8433 end
8434 if ($pcb->inp_flags & $IN6P_PKTINFO)
8435 printf "pktinfo "
8436 end
8437 if ($pcb->inp_flags & $IN6P_HOPLIMIT)
8438 printf "hoplimit "
8439 end
8440 if ($pcb->inp_flags & $IN6P_HOPOPTS)
8441 printf "hopopts "
8442 end
8443 if ($pcb->inp_flags & $IN6P_DSTOPTS)
8444 printf "dstopts "
8445 end
8446 if ($pcb->inp_flags & $IN6P_RTHDR)
8447 printf "rthdr "
8448 end
8449 if ($pcb->inp_flags & $IN6P_RTHDRDSTOPTS)
8450 printf "rthdrdstopts "
8451 end
8452 if ($pcb->inp_flags & $IN6P_AUTOFLOWLABEL)
8453 printf "autoflowlabel "
8454 end
8455 if ($pcb->inp_flags & $IN6P_BINDV6ONLY)
8456 printf "bindv6only "
8457 end
8458 set $so = (struct socket *)$pcb->inp_socket
8459 if $so != 0
8460 printf "[so=%p s=%ld r=%ld usecnt=%ld] ", $so, $so->so_snd.sb_cc, \
8461 $so->so_rcv.sb_cc, $so->so_usecount
8462 end
8463 if ($pcb->inp_state == 0 || $pcb->inp_state == $INPCB_STATE_INUSE)
8464 printf "inuse, "
8465 else
8466 if ($pcb->inp_state == $INPCB_STATE_CACHED)
8467 printf "cached, "
8468 else
8469 if ($pcb->inp_state == $INPCB_STATE_DEAD)
8470 printf "dead, "
8471 else
8472 printf "unknown (%d), ", $pcb->inp_state
8473 end
8474 end
8475 end
8476end
2d21ac55 8477
b0d623f7
A
8478define _dump_inpcbport
8479 set $ppcb = (struct inpcbport *)$arg0
8480 printf "%p: lport ", $ppcb
8481 _print_ntohs $ppcb->phd_port
2d21ac55
A
8482end
8483
b0d623f7 8484set $UDBHASHSIZE=16
2d21ac55 8485
b0d623f7
A
8486define _dump_pcbinfo
8487 set $snd_cc = 0
6d2010ae 8488 set $snd_buf = (unsigned int)0
b0d623f7 8489 set $rcv_cc = 0
6d2010ae 8490 set $rcv_buf = (unsigned int)0
b0d623f7
A
8491 set $pcbseen = 0
8492 set $pcbi = (struct inpcbinfo *)$arg0
8493 printf "lastport %d lastlow %d lasthi %d\n", \
8494 $pcbi->lastport, $pcbi->lastlow, $pcbi->lasthi
8495 printf "active pcb count is %d\n", $pcbi->ipi_count
8496 set $hashsize = $pcbi->hashmask + 1
8497 printf "hash size is %d\n", $hashsize
8498 printf "hash base %p has the following inpcb(s):\n", $pcbi->hashbase
8499 if $kgm_lp64
8500 printf "pcb prot source address port destination address port\n"
8501 printf "------------------ ---- --------------------------------------- ----- --------------------------------------- -----\n"
8502 else
8503 printf "pcb prot source address port destination address port\n"
8504 printf "---------- ---- --------------------------------------- ----- --------------------------------------- -----\n"
8505 end
8506 set $i = 0
8507 set $hashbase = $pcbi->hashbase
8508 set $head = *(uintptr_t *)$hashbase
8509 while $i < $hashsize
8510 if $head != 0
8511 set $pcb0 = (struct inpcb *)$head
8512 while $pcb0 != 0
8513 set $pcbseen += 1
8514 _dump_inpcb $pcb0 $arg1
8515 set $so = (struct socket *)$pcb->inp_socket
8516 if $so != 0
8517 set $snd_cc += $so->so_snd.sb_cc
6d2010ae
A
8518 set $mp = $so->so_snd.sb_mb
8519 while $mp
8520 set $snd_buf += 256
8521 if ($mp->m_hdr.mh_flags & 0x01)
8522 set $snd_buf += $mp->M_dat.MH.MH_dat.MH_ext.ext_size
8523 end
8524 set $mp = $mp->m_hdr.mh_next
8525 end
8526 set $rcv_cc += $so->so_rcv.sb_cc
8527 set $mp = $so->so_rcv.sb_mb
8528 while $mp
8529 set $rcv_buf += 256
8530 if ($mp->m_hdr.mh_flags & 0x01)
8531 set $rcv_buf += $mp->M_dat.MH.MH_dat.MH_ext.ext_size
8532 end
8533 set $mp = $mp->m_hdr.mh_next
8534 end
b0d623f7
A
8535 end
8536 set $pcb0 = $pcb0->inp_hash.le_next
8537 printf "\n"
8538 end
8539 end
8540 set $i += 1
8541 set $hashbase += 1
8542 set $head = *(uintptr_t *)$hashbase
8543 end
8544 printf "total seen %ld snd_cc %ld rcv_cc %ld\n", $pcbseen, $snd_cc, $rcv_cc
6d2010ae 8545 printf "total snd_buf %u rcv_buf %u \n", (unsigned int)$snd_buf, (unsigned int)$rcv_buf
b0d623f7
A
8546 printf "port hash base is %p\n", $pcbi->porthashbase
8547 set $i = 0
8548 set $hashbase = $pcbi->porthashbase
8549 set $head = *(uintptr_t *)$hashbase
8550 while $i < $hashsize
8551 if $head != 0
8552 set $pcb0 = (struct inpcbport *)$head
8553 while $pcb0 != 0
8554 printf "\t"
8555 _dump_inpcbport $pcb0
8556 printf "\n"
8557 set $pcb0 = $pcb0->phd_hash.le_next
8558 end
8559 end
8560 set $i += 1
8561 set $hashbase += 1
8562 set $head = *(uintptr_t *)$hashbase
8563 end
2d21ac55
A
8564end
8565
b0d623f7 8566set $N_TIME_WAIT_SLOTS=128
2d21ac55 8567
b0d623f7
A
8568define show_tcp_timewaitslots
8569 set $slot = -1
8570 set $all = 0
8571 if $argc == 1
8572 if (int)$arg0 == -1
8573 set $all = 1
8574 else
8575 set $slot = (int)$arg0
8576 end
8577 end
8578 printf "time wait slot size %d cur_tw_slot %ld\n", $N_TIME_WAIT_SLOTS, cur_tw_slot
8579 set $i = 0
8580 while $i < $N_TIME_WAIT_SLOTS
8581 set $perslot = 0
8582 set $head = (uintptr_t *)time_wait_slots[$i]
8583 if $i == $slot || $slot == -1
8584 if $head != 0
8585 set $pcb0 = (struct inpcb *)$head
8586 while $pcb0 != 0
8587 set $perslot += 1
8588 set $pcb0 = $pcb0->inp_list.le_next
8589 end
8590 end
8591 printf " slot %ld count %ld\n", $i, $perslot
8592 end
8593 if $all || $i == $slot
8594 if $head != 0
8595 set $pcb0 = (struct inpcb *)$head
8596 while $pcb0 != 0
8597 printf "\t"
8598 _dump_inpcb $pcb0 $IPPROTO_TCP
8599 printf "\n"
8600 set $pcb0 = $pcb0->inp_list.le_next
8601 end
8602 end
8603 end
8604 set $i += 1
8605 end
2d21ac55 8606end
b0d623f7
A
8607document show_tcp_timewaitslots
8608Syntax: (gdb) show_tcp_timewaitslots
8609| Print the list of TCP protocol control block in the TIMEWAIT state
8610| Pass -1 to see the list of PCB for each slot
8611| Pass a slot number to see information for that slot with the list of PCB
2d21ac55
A
8612end
8613
b0d623f7
A
8614define show_tcp_pcbinfo
8615 _dump_pcbinfo &tcbinfo $IPPROTO_TCP
2d21ac55 8616end
b0d623f7
A
8617document show_tcp_pcbinfo
8618Syntax: (gdb) show_tcp_pcbinfo
8619| Print the list of TCP protocol control block information
2d21ac55
A
8620end
8621
8622
b0d623f7
A
8623define show_udp_pcbinfo
8624 _dump_pcbinfo &udbinfo $IPPROTO_UDP
2d21ac55 8625end
b0d623f7
A
8626document show_udp_pcbinfo
8627Syntax: (gdb) show_udp_pcbinfo
8628| Print the list of UDP protocol control block information
2d21ac55
A
8629end
8630
b0d623f7
A
8631define showbpfdtab
8632 set $myi = 0
8633 while ($myi < bpf_dtab_size)
8634 if (bpf_dtab[$myi] != 0)
8635 printf "Address 0x%x, bd_next 0x%x\n", bpf_dtab[$myi], bpf_dtab[$myi]->bd_next
8636 print *bpf_dtab[$myi]
8637 end
8638 set $myi = $myi + 1
2d21ac55
A
8639 end
8640end
8641
b0d623f7
A
8642define printvnodepathint_recur
8643 if $arg0 != 0
8644 if ($arg0->v_flag & 0x000001) && ($arg0->v_mount != 0)
8645 if $arg0->v_mount->mnt_vnodecovered != 0
8646 printvnodepathint_recur $arg0->v_mount->mnt_vnodecovered $arg0->v_mount->mnt_vnodecovered->v_name
8647 end
8648 else
8649 printvnodepathint_recur $arg0->v_parent $arg0->v_parent->v_name
8650 printf "/%s", $arg1
8651 end
8652 end
8653end
8654
8655define showvnodepath
8656 set $vp = (struct vnode *)$arg0
8657 if $vp != 0
8658 if ($vp->v_flag & 0x000001) && ($vp->v_mount != 0) && ($vp->v_mount->mnt_flag & 0x00004000)
8659 printf "/"
8660 else
8661 printvnodepathint_recur $vp $vp->v_name
8662 end
8663 end
8664 printf "\n"
8665end
8666
8667document showvnodepath
8668Syntax: (gdb) showvnodepath <vnode>
8669| Prints the path for a vnode
8670end
8671
8672define showallvols
8673 printf "volume "
8674 showptrhdrpad
8675 printf " mnt_data "
8676 showptrhdrpad
8677 printf " mnt_devvp "
8678 showptrhdrpad
8679 printf " typename mountpoint\n"
8680 set $kgm_vol = (mount_t) mountlist.tqh_first
8681 while $kgm_vol
8682 showptr $kgm_vol
8683 printf " "
8684 showptr $kgm_vol->mnt_data
8685 printf " "
8686 showptr $kgm_vol->mnt_devvp
8687 printf " "
8688 if ($kgm_vol->mnt_vtable->vfc_name[0] == 'h') && \
8689 ($kgm_vol->mnt_vtable->vfc_name[1] == 'f') && \
8690 ($kgm_vol->mnt_vtable->vfc_name[2] == 's') && \
8691 ($kgm_vol->mnt_vtable->vfc_name[3] == '\0')
8692 set $kgm_hfsmount = \
8693 (struct hfsmount *) $kgm_vol->mnt_data
8694 if $kgm_hfsmount->hfs_freezing_proc != 0
8695 printf "FROZEN hfs "
8696 else
8697 printf "hfs "
8698 end
8699 else
8700 printf "%-10s ", $kgm_vol->mnt_vtable->vfc_name
8701 end
8702 printf "%s\n", $kgm_vol->mnt_vfsstat.f_mntonname
8703
8704 set $kgm_vol = (mount_t) $kgm_vol->mnt_list.tqe_next
8705 end
8706end
8707
8708document showallvols
8709Syntax: (gdb) showallvols
8710| Display a summary of mounted volumes
8711end
8712
8713define showvnodeheader
8714 printf "vnode "
8715 showptrhdrpad
8716 printf " usecount iocount v_data "
8717 showptrhdrpad
8718 printf " vtype parent "
8719 showptrhdrpad
8720 printf " name\n"
8721end
8722
8723define showvnodeint
8724 set $kgm_vnode = (vnode_t) $arg0
8725 showptr $kgm_vnode
8726 printf " %8d ", $kgm_vnode->v_usecount
8727 printf "%7d ", $kgm_vnode->v_iocount
8728# print information about clean/dirty blocks?
8729 showptr $kgm_vnode->v_data
8730 printf " "
8731 # print the vtype, using the enum tag
8732 set $kgm_vtype = $kgm_vnode->v_type
8733 if $kgm_vtype == VNON
8734 printf "VNON "
8735 end
8736 if $kgm_vtype == VREG
8737 printf "VREG "
8738 end
8739 if $kgm_vtype == VDIR
8740 printf "VDIR "
8741 end
8742 if $kgm_vtype == VBLK
8743 printf "VBLK "
8744 end
8745 if $kgm_vtype == VCHR
8746 printf "VCHR "
8747 end
8748 if $kgm_vtype == VLNK
8749 printf "VLNK "
8750 end
8751 if $kgm_vtype == VSOCK
8752 printf "VSOCK "
8753 end
8754 if $kgm_vtype == VFIFO
8755 printf "VFIFO "
8756 end
8757 if $kgm_vtype == VBAD
8758 printf "VBAD "
8759 end
8760 if ($kgm_vtype < VNON) || ($kgm_vtype > VBAD)
8761 printf "%5d ", $kgm_vtype
8762 end
8763
8764 showptr $kgm_vnode->v_parent
8765 printf " "
6d2010ae 8766 if ($kgm_vnode->v_name != 0)
b0d623f7 8767 printf "%s\n", $kgm_vnode->v_name
6d2010ae
A
8768 else
8769 # If this is HFS vnode, get name from the cnode
8770 if ($kgm_vnode->v_tag == 16)
8771 set $kgm_cnode = (struct cnode *)$kgm_vnode->v_data
8772 printf "hfs: %s\n", (char *)$kgm_cnode->c_desc->cd_nameptr
8773 else
8774 printf "\n"
8775 end
b0d623f7
A
8776 end
8777end
8778
8779define showvnode
8780 showvnodeheader
8781 showvnodeint $arg0
8782end
8783
8784document showvnode
8785Syntax: (gdb) showvnode <vnode>
8786| Display info about one vnode
8787end
8788
8789define showvolvnodes
8790 showvnodeheader
8791 set $kgm_vol = (mount_t) $arg0
8792 set $kgm_vnode = (vnode_t) $kgm_vol.mnt_vnodelist.tqh_first
8793 while $kgm_vnode
8794 showvnodeint $kgm_vnode
8795 set $kgm_vnode = (vnode_t) $kgm_vnode->v_mntvnodes.tqe_next
8796 end
8797end
8798
8799document showvolvnodes
8800Syntax: (gdb) showvolvnodes <mouont_t>
8801| Display info about all vnodes of a given mount_t
8802end
8803
8804define showvolbusyvnodes
8805 showvnodeheader
8806 set $kgm_vol = (mount_t) $arg0
8807 set $kgm_vnode = (vnode_t) $kgm_vol.mnt_vnodelist.tqh_first
8808 while $kgm_vnode
8809 if $kgm_vnode->v_iocount != 0
8810 showvnodeint $kgm_vnode
8811 end
8812 set $kgm_vnode = (vnode_t) $kgm_vnode->v_mntvnodes.tqe_next
8813 end
8814end
8815
8816document showvolbusyvnodes
8817Syntax: (gdb) showvolbusyvnodes <mount_t>
8818| Display info about busy (iocount!=0) vnodes of a given mount_t
8819end
8820
8821define showallbusyvnodes
8822 showvnodeheader
8823 set $kgm_vol = (mount_t) mountlist.tqh_first
8824 while $kgm_vol
8825 set $kgm_vnode = (vnode_t) $kgm_vol.mnt_vnodelist.tqh_first
8826 while $kgm_vnode
8827 if $kgm_vnode->v_iocount != 0
8828 showvnodeint $kgm_vnode
8829 end
8830 set $kgm_vnode = (vnode_t) $kgm_vnode->v_mntvnodes.tqe_next
8831 end
8832 set $kgm_vol = (mount_t) $kgm_vol->mnt_list.tqe_next
8833 end
8834end
8835
8836document showallbusyvnodes
8837Syntax: (gdb) showallbusyvnodes <vnode>
8838| Display info about all busy (iocount!=0) vnodes
8839end
8840
8841define showallvnodes
8842 showvnodeheader
8843 set $kgm_vol = (mount_t) mountlist.tqh_first
8844 while $kgm_vol
8845 set $kgm_vnode = (vnode_t) $kgm_vol.mnt_vnodelist.tqh_first
8846 while $kgm_vnode
8847 showvnodeint $kgm_vnode
8848 set $kgm_vnode = (vnode_t) $kgm_vnode->v_mntvnodes.tqe_next
8849 end
8850 set $kgm_vol = (mount_t) $kgm_vol->mnt_list.tqe_next
8851 end
8852end
8853
8854document showallvnodes
8855Syntax: (gdb) showallvnodes
8856| Display info about all vnodes
8857end
8858
8859define _showvnodelockheader
8860 printf "* type W held by lock type start end\n"
8861 printf "- ----- - ------------- --------- ------------------ ------------------\n"
8862end
8863
8864define _showvnodelock
8865 set $kgm_svl_lock = ((struct lockf *)$arg0)
8866
8867 # decode flags
8868 set $kgm_svl_flags = $kgm_svl_lock->lf_flags
8869 set $kgm_svl_type = $kgm_svl_lock->lf_type
8870 if ($kgm_svl_flags & 0x20)
8871 printf "flock"
8872 end
8873 if ($kgm_svl_flags & 0x40)
8874 printf "posix"
8875 end
8876 if ($kgm_svl_flags & 0x80)
8877 printf "prov "
8878 end
8879 if ($kgm_svl_flags & 0x10)
8880 printf " W "
8881 else
8882 printf " . "
8883 end
8884
8885 # POSIX file vs. advisory range locks
8886 if ($kgm_svl_flags & 0x40)
8887 set $kgm_svl_proc = (proc_t)$kgm_svl_lock->lf_id
8888 printf "PID %8d ", $kgm_svl_proc->p_pid
8889 else
8890 printf "ID 0x%08x ", $kgm_svl_lock->lf_id
8891 end
8892
8893 # lock type
8894 if ($kgm_svl_type == 1)
8895 printf "shared "
8896 else
8897 if ($kgm_svl_type == 3)
8898 printf "exclusive "
8899 else
8900 if ($kgm_svl_type == 2)
8901 printf "unlock "
8902 else
8903 printf "unknown "
8904 end
8905 end
8906 end
8907
8908 # start and stop
8909 printf "0x%016x..", $kgm_svl_lock->lf_start
8910 printf "0x%016x ", $kgm_svl_lock->lf_end
8911 printf "\n"
8912end
8913# Body of showvnodelocks, not including header
8914define _showvnodelocks
8915 set $kgm_svl_vnode = ((vnode_t)$arg0)
8916 set $kgm_svl_lockiter = $kgm_svl_vnode->v_lockf
8917 while ($kgm_svl_lockiter != 0)
8918 # locks that are held
8919 printf "H "
8920 _showvnodelock $kgm_svl_lockiter
8921
8922 # and any locks blocked by them
8923 set $kgm_svl_blocker = $kgm_svl_lockiter->lf_blkhd.tqh_first
8924 while ($kgm_svl_blocker != 0)
8925 printf "> "
8926 _showvnodelock $kgm_svl_blocker
8927 set $kgm_svl_blocker = $kgm_svl_blocker->lf_block.tqe_next
8928 end
8929
8930 # and on to the next one...
8931 set $kgm_svl_lockiter = $kgm_svl_lockiter->lf_next
8932 end
8933end
8934
8935
8936define showvnodelocks
8937 if ($argc == 1)
8938 _showvnodelockheader
8939 _showvnodelocks $arg0
8940 else
8941 printf "| Usage:\n|\n"
8942 help showvnodelocks
8943 end
8944end
8945
8946document showvnodelocks
8947Syntax: (gdb) showvnodelocks <vnode_t>
8948| Given a vnodet pointer, display the list of advisory record locks for the
8949| referenced pvnodes
8950end
8951
8952define showbootargs
8953 printf "%s\n", (char*)((boot_args*)PE_state.bootArgs).CommandLine
8954end
8955
8956document showbootargs
8957Syntax: showbootargs
8958| Display boot arguments passed to the target kernel
8959end
8960
8961define showbootermemorymap
8962 if ($kgm_mtype == $kgm_mtype_i386)
8963 set $kgm_voffset = 0
8964 else
8965 if ($kgm_mtype == $kgm_mtype_x86_64)
8966 set $kgm_voffset = 0xFFFFFF8000000000ULL
8967 else
8968 echo showbootermemorymap not supported on this architecture
8969 end
8970 end
8971
8972 set $kgm_boot_args = kernelBootArgs
8973 set $kgm_msize = kernelBootArgs->MemoryMapDescriptorSize
8974 set $kgm_mcount = kernelBootArgs->MemoryMapSize / $kgm_msize
8975 set $kgm_i = 0
8976
8977 printf "Type Physical Start Number of Pages Virtual Start Attributes\n"
8978 while $kgm_i < $kgm_mcount
8979 set $kgm_mptr = (EfiMemoryRange *)((unsigned long)kernelBootArgs->MemoryMap + $kgm_voffset + $kgm_i * $kgm_msize)
8980# p/x *$kgm_mptr
8981 if $kgm_mptr->Type == 0
060df5ea 8982 printf "Reserved "
b0d623f7
A
8983 end
8984 if $kgm_mptr->Type == 1
8985 printf "LoaderCode"
8986 end
8987 if $kgm_mptr->Type == 2
8988 printf "LoaderData"
8989 end
8990 if $kgm_mptr->Type == 3
8991 printf "BS_code "
8992 end
8993 if $kgm_mptr->Type == 4
8994 printf "BS_data "
8995 end
8996 if $kgm_mptr->Type == 5
8997 printf "RT_code "
8998 end
8999 if $kgm_mptr->Type == 6
9000 printf "RT_data "
9001 end
9002 if $kgm_mptr->Type == 7
060df5ea 9003 printf "Convention"
b0d623f7
A
9004 end
9005 if $kgm_mptr->Type == 8
9006 printf "Unusable "
9007 end
9008 if $kgm_mptr->Type == 9
9009 printf "ACPI_recl "
9010 end
9011 if $kgm_mptr->Type == 10
9012 printf "ACPI_NVS "
9013 end
9014 if $kgm_mptr->Type == 11
9015 printf "MemMapIO "
9016 end
9017 if $kgm_mptr->Type == 12
9018 printf "MemPortIO "
9019 end
9020 if $kgm_mptr->Type == 13
9021 printf "PAL_code "
9022 end
9023 if $kgm_mptr->Type > 13
9024 printf "UNKNOWN "
9025 end
9026
9027 printf " %016llx %016llx", $kgm_mptr->PhysicalStart, $kgm_mptr->NumberOfPages
9028 if $kgm_mptr->VirtualStart != 0
9029 printf " %016llx", $kgm_mptr->VirtualStart
9030 else
9031 printf " "
9032 end
9033 printf " %016llx\n", $kgm_mptr->Attribute
9034 set $kgm_i = $kgm_i + 1
9035 end
9036end
9037
9038document showbootermemorymap
9039Syntax: (gdb) showbootermemorymap
9040| Prints out the phys memory map from kernelBootArgs
9041end
9042
9043
9044define showstacksaftertask
6d2010ae 9045 set $kgm_head_taskp = &tasks
b0d623f7 9046 set $kgm_taskp = (struct task *)$arg0
6d2010ae 9047 set $kgm_taskp = (struct task *)$kgm_taskp->tasks.next
b0d623f7 9048 while $kgm_taskp != $kgm_head_taskp
6d2010ae
A
9049 showtaskheader
9050 showtaskint $kgm_taskp
9051 set $kgm_head_actp = &($kgm_taskp->threads)
9052 set $kgm_actp = (struct thread *)($kgm_taskp->threads.next)
9053 while $kgm_actp != $kgm_head_actp
9054 showactheader
9055 if ($decode_wait_events > 0)
9056 showactint $kgm_actp 1
9057 else
9058 showactint $kgm_actp 2
9059 end
9060 set $kgm_actp = (struct thread *)($kgm_actp->task_threads.next)
9061 end
9062 printf "\n"
9063 set $kgm_taskp = (struct task *)($kgm_taskp->tasks.next)
b0d623f7
A
9064 end
9065end
9066document showstacksaftertask
9067Syntax: (gdb) showstacksaftertask <task>
9068| Routine to print out all stacks (as in showallstacks) starting after a given task
9069| Useful if that gdb refuses to print a certain task's stack.
9070end
9071
9072define showpmworkqueueint
6d2010ae
A
9073 set $kgm_pm_workqueue = (IOPMWorkQueue *)$arg0
9074 set $kgm_pm_wq = &($kgm_pm_workqueue->fWorkQueue)
9075 set $kgm_pm_wqe = (IOServicePM *)$kgm_pm_wq->next
9076 while ((queue_entry_t) $kgm_pm_wqe != (queue_entry_t) $kgm_pm_wq)
9077 printf "service "
9078 showptrhdrpad
9079 printf " ps ms wr name\n"
9080 showptr $kgm_pm_wqe->Owner
9081 printf " "
9082 printf "%02d ", $kgm_pm_wqe->CurrentPowerState
9083 printf "%02d ", $kgm_pm_wqe->MachineState
9084 printf "%02d ", $kgm_pm_wqe->WaitReason
9085 printf "%s\n", $kgm_pm_wqe->Name
b0d623f7
A
9086 printf "request "
9087 showptrhdrpad
9088 printf " type next "
9089 showptrhdrpad
9090 printf " root "
9091 showptrhdrpad
9092 printf " work_wait free_wait\n"
6d2010ae
A
9093 set $kgm_pm_rq = &($kgm_pm_wqe->RequestHead)
9094 set $kgm_pm_rqe = (IOPMRequest *)$kgm_pm_rq->next
9095 while ((queue_entry_t) $kgm_pm_rqe != (queue_entry_t) $kgm_pm_rq)
9096 showptr $kgm_pm_rqe
9097 printf " 0x%02x ", $kgm_pm_rqe->fType
9098 showptr $kgm_pm_rqe->fRequestNext
b0d623f7 9099 printf " "
6d2010ae
A
9100 showptr $kgm_pm_rqe->fRequestRoot
9101 printf " 0x%08x 0x%08x\n", $kgm_pm_rqe->fWorkWaitCount, $kgm_pm_rqe->fFreeWaitCount
b0d623f7
A
9102 showptrhdrpad
9103 printf " args "
6d2010ae 9104 showptr $kgm_pm_rqe->fArg0
b0d623f7 9105 printf " "
6d2010ae 9106 showptr $kgm_pm_rqe->fArg1
b0d623f7 9107 printf " "
6d2010ae 9108 showptr $kgm_pm_rqe->fArg2
b0d623f7 9109 printf "\n"
6d2010ae 9110 set $kgm_pm_rqe = (IOPMRequest *)$kgm_pm_rqe->fCommandChain.next
b0d623f7
A
9111 end
9112 printf "\n"
6d2010ae 9113 set $kgm_pm_wqe = (IOServicePM *)$kgm_pm_wqe->WorkChain.next
b0d623f7
A
9114 end
9115end
9116
6d2010ae
A
9117define showpmworkqueue
9118 printf "IOPMWorkQueue "
9119 showptr gIOPMWorkQueue
9120 printf " length "
9121 printf "%u", gIOPMWorkQueue->fQueueLength
9122 printf "\n"
9123 if (gIOPMWorkQueue->fQueueLength > 0)
9124 showpmworkqueueint gIOPMWorkQueue
b0d623f7
A
9125 end
9126end
9127
6d2010ae
A
9128document showpmworkqueue
9129Syntax: (gdb) showpmworkqueue
9130| Display the IOPMWorkQueue object
b0d623f7
A
9131end
9132
9133define showioservicepm
6d2010ae
A
9134 set $kgm_iopmpriv = (IOServicePM *)$arg0
9135 printf "{ "
9136 printf "MachineState = %d (", $kgm_iopmpriv->MachineState
9137 if ( $kgm_iopmpriv->MachineState == 0 )
9138 printf "kIOPM_Finished"
9139 else
9140 if ( $kgm_iopmpriv->MachineState == 1 )
9141 printf "kIOPM_OurChangeTellClientsPowerDown"
9142 else
9143 if ( $kgm_iopmpriv->MachineState == 2 )
9144 printf "kIOPM_OurChangeTellPriorityClientsPowerDown"
9145 else
9146 if ( $kgm_iopmpriv->MachineState == 3 )
9147 printf "kIOPM_OurChangeNotifyInterestedDriversWillChange"
9148 else
9149 if ( $kgm_iopmpriv->MachineState == 4 )
9150 printf "kIOPM_OurChangeSetPowerState"
9151 else
9152 if ( $kgm_iopmpriv->MachineState == 5 )
9153 printf "kIOPM_OurChangeWaitForPowerSettle"
9154 else
9155 if ( $kgm_iopmpriv->MachineState == 6 )
9156 printf "kIOPM_OurChangeNotifyInterestedDriversDidChange"
9157 else
9158 if ( $kgm_iopmpriv->MachineState == 7 )
9159 printf "kIOPM_OurChangeTellCapabilityDidChange"
9160 else
9161 if ( $kgm_iopmpriv->MachineState == 8 )
9162 printf "kIOPM_OurChangeFinish"
9163 else
9164 if ( $kgm_iopmpriv->MachineState == 9 )
9165 printf "Unused_MachineState_9"
9166 else
9167 if ( $kgm_iopmpriv->MachineState == 10 )
9168 printf "kIOPM_ParentChangeTellPriorityClientsPowerDown"
9169 else
9170 if ( $kgm_iopmpriv->MachineState == 11 )
9171 printf "kIOPM_ParentChangeNotifyInterestedDriversWillChange"
9172 else
9173 if ( $kgm_iopmpriv->MachineState == 12 )
9174 printf "kIOPM_ParentChangeSetPowerState"
9175 else
9176 if ( $kgm_iopmpriv->MachineState == 13 )
9177 printf "kIOPM_ParentChangeWaitForPowerSettle"
9178 else
9179 if ( $kgm_iopmpriv->MachineState == 14)
9180 printf "kIOPM_ParentChangeNotifyInterestedDriversDidChange"
9181 else
9182 if ( $kgm_iopmpriv->MachineState == 15)
9183 printf "kIOPM_ParentChangeTellCapabilityDidChange"
9184 else
9185 if ( $kgm_iopmpriv->MachineState == 16)
9186 printf "kIOPM_ParentChangeAcknowledgePowerChange"
9187 else
9188 if ( $kgm_iopmpriv->MachineState == 17)
9189 printf "kIOPM_NotifyChildrenStart"
9190 else
9191 if ( $kgm_iopmpriv->MachineState == 18)
9192 printf "kIOPM_NotifyChildrenOrdered"
9193 else
9194 if ( $kgm_iopmpriv->MachineState == 19)
9195 printf "kIOPM_NotifyChildrenDelayed"
9196 else
9197 if ( $kgm_iopmpriv->MachineState == 20)
9198 printf "kIOPM_SyncTellClientsPowerDown"
9199 else
9200 if ( $kgm_iopmpriv->MachineState == 21)
9201 printf "kIOPM_SyncTellPriorityClientsPowerDown"
9202 else
9203 if ( $kgm_iopmpriv->MachineState == 22)
9204 printf "kIOPM_SyncNotifyWillChange"
9205 else
9206 if ( $kgm_iopmpriv->MachineState == 23)
9207 printf "kIOPM_SyncNotifyDidChange"
9208 else
9209 if ( $kgm_iopmpriv->MachineState == 24)
9210 printf "kIOPM_SyncTellCapabilityDidChange"
9211 else
9212 if ( $kgm_iopmpriv->MachineState == 25)
9213 printf "kIOPM_SyncFinish"
9214 else
9215 if ( $kgm_iopmpriv->MachineState == 26)
9216 printf "kIOPM_TellCapabilityChangeDone"
9217 else
9218 if ( $kgm_iopmpriv->MachineState == 27)
9219 printf "kIOPM_DriverThreadCallDone"
9220 else
9221 printf "Unknown_MachineState"
9222 end
9223 end
9224 end
9225 end
9226 end
9227 end
9228 end
9229 end
9230 end
9231 end
9232 end
9233 end
9234 end
9235 end
9236 end
9237 end
9238 end
9239 end
9240 end
9241 end
9242 end
9243 end
9244 end
9245 end
9246 end
9247 end
9248 end
b0d623f7
A
9249 end
9250 printf "), "
9251
9252 if ( $kgm_iopmpriv->MachineState != 20 )
9253 printf "DriverTimer = %d, ",(unsigned int)$kgm_iopmpriv->DriverTimer
9254 printf "SettleTime = %d, ",(unsigned int)$kgm_iopmpriv->SettleTimeUS
6d2010ae 9255 printf "HeadNoteFlags = %08x, ",(unsigned int)$kgm_iopmpriv->HeadNoteChangeFlags
b0d623f7
A
9256 printf "HeadNotePendingAcks = %x, ",(unsigned int)$kgm_iopmpriv->HeadNotePendingAcks
9257 end
9258
6d2010ae 9259 if ( $kgm_iopmpriv->DeviceOverrideEnabled != 0 )
b0d623f7
A
9260 printf"DeviceOverrides, "
9261 end
9262
9263 printf "DeviceDesire = %d, ",(unsigned int)$kgm_iopmpriv->DeviceDesire
9264 printf "DesiredPowerState = %d, ",(unsigned int)$kgm_iopmpriv->DesiredPowerState
6d2010ae 9265 printf "PreviousRequest = %d }\n",(unsigned int)$kgm_iopmpriv->PreviousRequestPowerFlags
b0d623f7
A
9266end
9267
9268document showioservicepm
9269Syntax: (gdb) showioservicepm <IOServicePM pointer>
9270| Routine to dump the IOServicePM object
9271end
9272
9273define showregistryentryrecursepmstate
9274 set $kgm_re = (IOService *)$arg1
9275 set $kgm$arg0_stack = (unsigned long long) $arg2
9276
9277 if ($arg3)
9278 set $kgm$arg0_stack = $kgm$arg0_stack | (1ULL << $kgm_reg_depth)
9279 else
9280 set $kgm$arg0_stack = $kgm$arg0_stack & ~(1ULL << $kgm_reg_depth)
9281 end
9282
9283 dictget $kgm_re->fRegistryTable $kgm_childkey
9284 set $kgm$arg0_child_array = (OSArray *) $kgm_result
9285
9286 if ($kgm$arg0_child_array)
9287 set $kgm$arg0_child_count = $kgm$arg0_child_array->count
9288 else
9289 set $kgm$arg0_child_count = 0
9290 end
9291
9292 if ($kgm$arg0_child_count)
9293 set $kgm$arg0_stack = $kgm$arg0_stack | (2ULL << $kgm_reg_depth)
9294 else
9295 set $kgm$arg0_stack = $kgm$arg0_stack & ~(2ULL << $kgm_reg_depth)
9296 end
9297
9298 indent $kgm_reg_depth $kgm$arg0_stack
9299 printf "+-o "
9300
9301 dictget $kgm_re->fRegistryTable $kgm_namekey
9302 if ($kgm_result == 0)
9303 dictget $kgm_re->fRegistryTable gIONameKey
9304 end
9305 if ($kgm_result == 0)
9306 dictget $kgm_re->fPropertyTable gIOClassKey
9307 end
9308
9309 if ($kgm_result != 0)
9310 printf "%s <%p>", ((OSString *)$kgm_result)->string, $kgm_re
9311 else
9312 if (((IOService*)$kgm_re)->pwrMgt && ((IOService*)$kgm_re)->pwrMgt->Name)
9313 printf "%s <", ((IOService*)$kgm_re)->pwrMgt->Name
9314 showptr $kgm_re
9315 printf ">"
9316 else
9317 printf "?? <"
9318 showptr $kgm_re
9319 printf ">"
9320 end
9321 end
9322
9323 if (((IOService*)$kgm_re)->pwrMgt )
9324 printf " Current Power State: %ld ", ((IOService*)$kgm_re)->pwrMgt->CurrentPowerState
9325 #printf " Mach State %ld", ((IOService*)$kgm_re)->pwrMgt->MachineState
9326 showioservicepm ((IOService*)$kgm_re)->pwrMgt
9327 end
9328 printf "\n"
9329
9330
9331 # recurse
9332 if ($kgm$arg0_child_count != 0)
9333
9334 set $kgm_reg_depth = $kgm_reg_depth + 1
9335 set $kgm$arg0_child_idx = 0
9336
9337 while ($kgm$arg0_child_idx < $kgm$arg0_child_count)
9338 set $kgm_re = $kgm$arg0_child_array->array[$kgm$arg0_child_idx++]
9339 set $kgm_more_sib = ($kgm$arg0_child_idx < $kgm$arg0_child_count)
9340 if $kgm_reg_depth >= $kgm_reg_depth_max + 1
9341 loop_break
9342 end
9343 showregistryentryrecursepmstate _$arg0 $kgm_re $kgm$arg0_stack $kgm_more_sib
9344 end
9345
9346 set $kgm_reg_depth = $kgm_reg_depth - 1
9347 end
9348end
9349
9350define showregistryentryintpmstate
7e4a7d39
A
9351 if !$kgm_reg_plane
9352 set $kgm_reg_plane = (IORegistryPlane *) gIOServicePlane
9353 end
9354
9355 if !$kgm_reg_plane
9356 printf "Please load kgmacros after KDP attaching to the target.\n"
9357 else
9358 set $kgm_namekey = (OSSymbol *) $kgm_reg_plane->nameKey
9359 set $kgm_childkey = (OSSymbol *) $kgm_reg_plane->keys[1]
9360 showregistryentryrecursepmstate _ $arg0 0 0
9361 end
b0d623f7
A
9362end
9363
9364define showregistrypmstate
9365# setregistryplane gIOPowerPlane
9366 set $kgm_reg_depth = 0
9367 set $kgm_show_props = 1
9368 showregistryentryintpmstate gRegistryRoot
9369end
9370
9371document showregistrypmstate
9372Syntax: (gdb) showregistrypmstate
9373| Routine to dump the PM state of each IOPower registry entry
9374end
9375
9376define showstacksafterthread
6d2010ae 9377 set $kgm_head_taskp = &tasks
b0d623f7
A
9378 set $kgm_actp = (struct thread *)$arg0
9379 set $kgm_actp = (struct thread *)($kgm_actp->task_threads.next)
9380 set $kgm_taskp = (struct task *)$kgm_actp->task
9381 while $kgm_taskp != $kgm_head_taskp
6d2010ae
A
9382 showtaskheader
9383 showtaskint $kgm_taskp
9384 set $kgm_head_actp = &($kgm_taskp->threads)
9385 if $kgm_actp == 0
9386 set $kgm_actp = (struct thread *)($kgm_taskp->threads.next)
9387 end
9388 while $kgm_actp != $kgm_head_actp
9389 showactheader
9390 if ($decode_wait_events > 0)
9391 showactint $kgm_actp 1
9392 else
9393 showactint $kgm_actp 2
9394 end
9395 set $kgm_actp = (struct thread *)($kgm_actp->task_threads.next)
9396 end
9397 printf "\n"
9398 set $kgm_taskp = (struct task *)($kgm_taskp->tasks.next)
9399 set $kgm_actp = 0
b0d623f7
A
9400 end
9401end
9402
9403document showstacksafterthread
9404Syntax: (gdb) showstacksafterthread <thread>
9405| Routine to print out all stacks (as in showallstacks) starting after a given thread
9406| Useful if that gdb refuses to print a certain task's stack.
9407end
9408
9409define kdp-reenter
9410 set kdp_reentry_deadline = ((unsigned) $arg0)*1000
9411 continue
9412end
9413
9414document kdp-reenter
9415Syntax: (gdb) kdp-reenter <seconds>
9416| Schedules reentry into the debugger after <seconds> seconds, and resumes
9417| the target system.
9418end
9419
9420define _if_present
9421 if (!$arg0)
9422 printf " not"
9423 end
9424 printf " present"
9425end
9426
9427define showMCAstate
9428 if (($kgm_mtype & $kgm_mtype_x86_mask) != $kgm_mtype_x86_any)
9429 printf "Not available for current architecture.\n"
9430 else
9431 printf "MCA"
9432 _if_present mca_MCA_present
9433 printf ", control MSR"
9434 _if_present mca_control_MSR_present
9435 printf ", threshold status"
9436 _if_present mca_threshold_status_present
9437 printf "\n%d error banks, ", mca_error_bank_count
9438 printf "family code 0x%x, ", mca_family
9439 printf "machine-check dump state: %d\n", mca_dump_state
9440 set $kgm_cpu = 0
9441 while cpu_data_ptr[$kgm_cpu] != 0
9442 set $kgm_mcp = cpu_data_ptr[$kgm_cpu]->cpu_mca_state
9443 if $kgm_mcp
9444 printf "CPU %d:", $kgm_cpu
9445 printf " mca_mcg_ctl: 0x%016llx", $kgm_mcp->mca_mcg_ctl
9446 printf " mca_mcg_status: 0x%016llx\n", $kgm_mcp->mca_mcg_status.u64
9447 printf "bank "
9448 printf "mca_mci_ctl "
9449 printf "mca_mci_status "
9450 printf "mca_mci_addr "
9451 printf "mca_mci_misc\n"
9452 set $kgm_bank = 0
9453 while $kgm_bank < mca_error_bank_count
9454 set $kgm_bp = &$kgm_mcp->mca_error_bank[$kgm_bank]
9455 printf " %2d:", $kgm_bank
9456 printf " 0x%016llx", $kgm_bp->mca_mci_ctl
9457 printf " 0x%016llx", $kgm_bp->mca_mci_status.u64
9458 printf " 0x%016llx", $kgm_bp->mca_mci_addr
9459 printf " 0x%016llx\n", $kgm_bp->mca_mci_misc
9460 set $kgm_bank = $kgm_bank + 1
9461 end
9462 end
9463 set $kgm_cpu = $kgm_cpu + 1
9464 end
9465 end
9466end
9467
9468document showMCAstate
9469Syntax: showMCAstate
9470| Print machine-check register state after MC exception.
9471end
9472
9473define _pt_step
9474 #
9475 # Step to lower-level page table and print attributes
9476 # $kgm_pt_paddr: current page table entry physical address
9477 # $kgm_pt_index: current page table entry index (0..511)
9478 # returns
9479 # $kgm_pt_paddr: next level page table entry physical address
9480 # or null if invalid
9481 # $kgm_pt_valid: 1 if $kgm_pt_paddr is valid, 0 if the walk
9482 # should be aborted
9483 # $kgm_pt_large: 1 if kgm_pt_paddr is a page frame address
9484 # of a large page and not another page table entry
9485 # For $kgm_pt_verbose = 0: print nothing
9486 # 1: print basic information
9487 # 2: print basic information and hex table dump
9488 #
9489 set $kgm_entryp = $kgm_pt_paddr + 8*$kgm_pt_index
9490 readphysint $kgm_entryp 64 $kgm_lcpu_self
9491 set $entry = $kgm_readphysint_result
6d2010ae 9492 if $kgm_pt_verbose >= 3
b0d623f7 9493 set $kgm_pte_loop = 0
6d2010ae
A
9494 while $kgm_pte_loop < 512
9495 set $kgm_pt_paddr_tmp = $kgm_pt_paddr + $kgm_pte_loop*8
9496 readphys64 $kgm_pt_paddr_tmp
9497 set $kgm_pte_loop = $kgm_pte_loop + 1
9498 end
b0d623f7
A
9499 end
9500 set $kgm_paddr_mask = ~((0xfffULL<<52) | 0xfffULL)
9501 set $kgm_paddr_largemask = ~((0xfffULL<<52) | 0x1fffffULL)
6d2010ae 9502 if $kgm_pt_verbose < 2
b0d623f7
A
9503 if $entry & (0x1 << 0)
9504 set $kgm_pt_valid = 1
9505 if $entry & (0x1 << 7)
9506 set $kgm_pt_large = 1
9507 set $kgm_pt_paddr = $entry & $kgm_paddr_largemask
9508 else
9509 set $kgm_pt_large = 0
9510 set $kgm_pt_paddr = $entry & $kgm_paddr_mask
6d2010ae 9511 end
b0d623f7
A
9512 else
9513 set $kgm_pt_valid = 0
9514 set $kgm_pt_large = 0
9515 set $kgm_pt_paddr = 0
9516 end
9517 else
9518 printf "0x%016llx:\n\t0x%016llx\n\t", $kgm_entryp, $entry
9519 if $entry & (0x1 << 0)
6d2010ae 9520 printf "valid"
b0d623f7
A
9521 set $kgm_pt_paddr = $entry & $kgm_paddr_mask
9522 set $kgm_pt_valid = 1
9523 else
9524 printf "invalid"
9525 set $kgm_pt_paddr = 0
9526 set $kgm_pt_valid = 0
9527 # stop decoding other bits
9528 set $entry = 0
9529 end
9530 if $entry & (0x1 << 1)
9531 printf " writeable"
9532 else
9533 printf " read-only"
9534 end
9535 if $entry & (0x1 << 2)
9536 printf " user"
9537 else
9538 printf " supervisor"
9539 end
9540 if $entry & (0x1 << 3)
9541 printf " PWT"
9542 end
9543 if $entry & (0x1 << 4)
9544 printf " PCD"
9545 end
9546 if $entry & (0x1 << 5)
9547 printf " accessed"
9548 end
9549 if $entry & (0x1 << 6)
9550 printf " dirty"
9551 end
9552 if $entry & (0x1 << 7)
9553 printf " large"
9554 set $kgm_pt_large = 1
9555 else
9556 set $kgm_pt_large = 0
9557 end
9558 if $entry & (0x1 << 8)
9559 printf " global"
9560 end
9561 if $entry & (0x3 << 9)
9562 printf " avail:0x%x", ($entry >> 9) & 0x3
9563 end
6d2010ae 9564 if $entry & (0x1ULL << 63)
b0d623f7
A
9565 printf " noexec"
9566 end
9567 printf "\n"
9568 end
9569end
9570
6d2010ae
A
9571define _pml4_walk
9572 set $kgm_pt_paddr = $arg0
b0d623f7 9573 set $kgm_vaddr = $arg1
b0d623f7
A
9574 set $kgm_pt_valid = $kgm_pt_paddr != 0
9575 set $kgm_pt_large = 0
9576 set $kgm_pframe_offset = 0
9577 if $kgm_pt_valid && cpu_64bit
9578 # Look up bits 47:39 of the linear address in PML4T
9579 set $kgm_pt_index = ($kgm_vaddr >> 39) & 0x1ffULL
9580 set $kgm_pframe_offset = $kgm_vaddr & 0x7fffffffffULL
6d2010ae 9581 if $kgm_pt_verbose >= 2
b0d623f7
A
9582 printf "pml4 (index %d):\n", $kgm_pt_index
9583 end
9584 _pt_step
9585 end
9586 if $kgm_pt_valid
9587 # Look up bits 38:30 of the linear address in PDPT
9588 set $kgm_pt_index = ($kgm_vaddr >> 30) & 0x1ffULL
9589 set $kgm_pframe_offset = $kgm_vaddr & 0x3fffffffULL
6d2010ae 9590 if $kgm_pt_verbose >= 2
b0d623f7
A
9591 printf "pdpt (index %d):\n", $kgm_pt_index
9592 end
9593 _pt_step
9594 end
9595 if $kgm_pt_valid && !$kgm_pt_large
9596 # Look up bits 29:21 of the linear address in PDT
9597 set $kgm_pt_index = ($kgm_vaddr >> 21) & 0x1ffULL
9598 set $kgm_pframe_offset = $kgm_vaddr & 0x1fffffULL
6d2010ae 9599 if $kgm_pt_verbose >= 2
b0d623f7
A
9600 printf "pdt (index %d):\n", $kgm_pt_index
9601 end
9602 _pt_step
9603 end
9604 if $kgm_pt_valid && !$kgm_pt_large
9605 # Look up bits 20:21 of the linear address in PT
9606 set $kgm_pt_index = ($kgm_vaddr >> 12) & 0x1ffULL
9607 set $kgm_pframe_offset = $kgm_vaddr & 0xfffULL
6d2010ae 9608 if $kgm_pt_verbose >= 2
b0d623f7
A
9609 printf "pt (index %d):\n", $kgm_pt_index
9610 end
9611 _pt_step
9612 end
6d2010ae 9613
b0d623f7
A
9614 if $kgm_pt_valid
9615 set $kgm_paddr = $kgm_pt_paddr + $kgm_pframe_offset
6d2010ae 9616 set $kgm_paddr_isvalid = 1
b0d623f7
A
9617 else
9618 set $kgm_paddr = 0
6d2010ae
A
9619 set $kgm_paddr_isvalid = 0
9620 end
9621
9622 if $kgm_pt_verbose >= 1
9623 if $kgm_paddr_isvalid
9624 readphysint $kgm_paddr 32 $kgm_lcpu_self
9625 set $kgm_value = $kgm_readphysint_result
9626 printf "phys 0x%016llx: 0x%08x\n", $kgm_paddr, $kgm_value
9627 else
9628 printf "(no translation)\n"
9629 end
b0d623f7
A
9630 end
9631end
9632
6d2010ae
A
9633define _pmap_walk_x86
9634 set $kgm_pmap = (pmap_t) $arg0
9635 _pml4_walk $kgm_pmap->pm_cr3 $arg1
9636end
9637
9638define _pmap_walk_arm
9639 set $kgm_paddr = 0
9640 set $kgm_paddr_isvalid = 0
9641end
9642
b0d623f7 9643define pmap_walk
6d2010ae
A
9644 if $argc != 2
9645 printf "pmap_walk <pmap> <vaddr>\n"
b0d623f7 9646 else
6d2010ae
A
9647 if !$kgm_pt_verbose
9648 set $kgm_pt_verbose = 2
9649 else
9650 if $kgm_pt_verbose > 3
9651 set $kgm_pt_verbose = 2
9652 end
9653 end
9654 if (($kgm_mtype & $kgm_mtype_x86_mask) == $kgm_mtype_x86_any)
9655 _pmap_walk_x86 $arg0 $arg1
b0d623f7 9656 else
6d2010ae
A
9657 if ($kgm_mtype == $kgm_mtype_arm)
9658 _pmap_walk_arm $arg0 $arg1
b0d623f7 9659 else
6d2010ae 9660 printf "Not available for current architecture.\n"
b0d623f7 9661 end
b0d623f7
A
9662 end
9663 end
9664end
9665
9666document pmap_walk
9667Syntax: (gdb) pmap_walk <pmap> <virtual_address>
9668| Perform a page-table walk in <pmap> for <virtual_address>.
6d2010ae
A
9669| Set:
9670| $kgm_pt_verbose=0 for no output, $kgm_paddr will be set
9671| if $kgm_paddr_isvalid is 1
9672| $kgm_pt_verbose=1 for final physical address
9673| $kgm_pt_verbose=2 for dump of page table entry.
9674| $kgm_pt_verbose=3 for full hex dump of page tables.
b0d623f7
A
9675end
9676
9677define pmap_vtop
6d2010ae
A
9678 if $argc != 2
9679 printf "pmap_vtop <pamp> <vaddr>\n"
b0d623f7 9680 else
6d2010ae
A
9681 set $kgm_pt_verbose = 1
9682 if (($kgm_mtype & $kgm_mtype_x86_mask) == $kgm_mtype_x86_any)
9683 _pmap_walk_x86 $arg0 $arg1
b0d623f7 9684 else
6d2010ae
A
9685 if ($kgm_mtype == $kgm_mtype_arm)
9686 _pmap_walk_arm $arg0 $arg1
9687 else
9688 printf "Not available for current architecture.\n"
9689 end
b0d623f7
A
9690 end
9691 end
9692end
9693
9694document pmap_vtop
9695Syntax: (gdb) pmap_vtop <pmap> <virtual_address>
9696| For page-tables in <pmap> translate <virtual_address> to physical address.
9697end
9698
9699define zstack
9700 set $index = $arg0
9701
9702 if (log_records == 0)
9703 set $count = 0
9704 printf "Zone logging not enabled. Add 'zlog=<zone name>' to boot-args.\n"
9705 else
9706 if ($argc == 2)
9707 set $count = $arg1
9708 else
9709 set $count = 1
9710 end
9711 end
9712
9713 while ($count)
9714 printf "\n--------------- "
9715
9716 if (zrecords[$index].z_opcode == 1)
9717 printf "ALLOC "
9718 else
9719 printf "FREE "
9720 end
9721
9722 printf " 0x%x : index %d : ztime %d -------------\n", zrecords[$index].z_element, $index, zrecords[$index].z_time
9723
9724 set $frame = 0
9725
9726 while ($frame < 15)
9727 set $frame_pc = zrecords[$index].z_pc[$frame]
9728
9729 if ($frame_pc == 0)
9730 loop_break
9731 end
9732
9733 x/i $frame_pc
9734 set $frame = $frame + 1
9735 end
9736
9737 set $index = $index + 1
9738 set $count = $count - 1
9739 end
9740end
9741
9742document zstack
9743Syntax: (gdb) zstack <index> [<count>]
9744| Zone leak debugging: print the stack trace of log element at <index>.
9745| If a <count> is supplied, it prints <count> log elements starting at <index>.
9746|
9747| The suggested usage is to look at indexes below zcurrent and look for common stack traces.
9748| The stack trace that occurs the most is probably the cause of the leak. Find the pc of the
9749| function calling into zalloc and use the countpcs kgmacro to find out how often that pc occurs in the log.
9750| The pc occuring in a high percentage of records is most likely the source of the leak.
9751|
9752| The findoldest kgmacro is also useful for leak debugging since it identifies the oldest record
9753| in the log, which may indicate the leaker.
9754end
9755
9756define findoldest
9757 set $index = 0
9758 set $count = log_records
9759 set $cur_min = 2000000000
9760 set $cur_index = 0
9761
9762 if (log_records == 0)
9763 printf "Zone logging not enabled. Add 'zlog=<zone name>' to boot-args.\n"
9764 else
9765
9766 while ($count)
9767 if (zrecords[$index].z_element && zrecords[$index].z_time < $cur_min)
9768 set $cur_index = $index
9769 set $cur_min = zrecords[$index].z_time
9770 end
9771
9772 set $count = $count - 1
9773 set $index = $index + 1
9774 end
9775
9776 printf "oldest record is at log index %d:\n", $cur_index
9777 zstack $cur_index
9778 end
9779end
9780
9781document findoldest
9782Syntax: (gdb) findoldest
9783| Zone leak debugging: find and print the oldest record in the log. Note that this command
9784| can take several minutes to run since it uses linear search.
9785|
9786| Once it prints a stack trace, find the pc of the caller above all the zalloc, kalloc and
9787| IOKit layers. Then use the countpcs kgmacro to see how often this caller has allocated
9788| memory. A caller with a high percentage of records in the log is probably the leaker.
9789end
9790
9791define countpcs
9792 set $target_pc = $arg0
9793 set $index = 0
9794 set $count = log_records
9795 set $found = 0
9796
9797 if (log_records == 0)
9798 printf "Zone logging not enabled. Add 'zlog=<zone name>' to boot-args.\n"
9799 else
9800
9801 while ($count)
9802 set $frame = 0
9803
9804 if (zrecords[$index].z_element != 0)
9805 while ($frame < 15)
9806 if (zrecords[$index].z_pc[$frame] == $target_pc)
9807 set $found = $found + 1
9808 set $frame = 15
9809 end
9810
9811 set $frame = $frame + 1
9812 end
9813 end
9814
9815 set $index = $index + 1
9816 set $count = $count - 1
9817 end
9818
9819 printf "occurred %d times in log (%d%c of records)\n", $found, ($found * 100) / zrecorded, '%'
9820 end
9821end
9822
9823document countpcs
9824Syntax: (gdb) countpcs <pc>
9825| Zone leak debugging: search the log and print a count of all log entries that contain the given <pc>
9826| in the stack trace. This is useful for verifying a suspected <pc> as being the source of
9827| the leak. If a high percentage of the log entries contain the given <pc>, then it's most
9828| likely the source of the leak. Note that this command can take several minutes to run.
9829end
9830
9831define findelem
9832 set $fe_index = zcurrent
9833 set $fe_count = log_records
9834 set $fe_elem = $arg0
9835 set $fe_prev_op = -1
9836
9837 if (log_records == 0)
9838 printf "Zone logging not enabled. Add 'zlog=<zone name>' to boot-args.\n"
9839 end
9840
9841 while ($fe_count)
9842 if (zrecords[$fe_index].z_element == $fe_elem)
9843 zstack $fe_index
9844
9845 if (zrecords[$fe_index].z_opcode == $fe_prev_op)
9846 printf "*************** DOUBLE OP! *********************\n
9847 end
9848
9849 set $fe_prev_op = zrecords[$fe_index].z_opcode
9850 end
9851
9852 set $fe_count = $fe_count - 1
9853 set $fe_index = $fe_index + 1
9854
9855 if ($fe_index >= log_records)
9856 set $fe_index = 0
9857 end
9858 end
9859end
9860
9861document findelem
9862Syntax: (gdb) findelem <elem addr>
9863| Zone corruption debugging: search the log and print out the stack traces for all log entries that
9864| refer to the given zone element. When the kernel panics due to a corrupted zone element, get the
9865| element address and use this macro. This will show you the stack traces of all logged zalloc and
9866| zfree operations which tells you who touched the element in the recent past. This also makes
9867| double-frees readily apparent.
9868end
9869
9870
9871# This implements a shadowing scheme in kgmacros. If the
9872# current user data can be accessed by simply changing kdp_pmap,
9873# that is used. Otherwise, we copy data into a temporary buffer
9874# in the kernel's address space and use that instead. Don't rely on
9875# kdp_pmap between invocations of map/unmap. Since the shadow
9876# codepath uses a manual KDP packet, request no more than 128 bytes.
6d2010ae
A
9877# Uses $kgm_lp64 for kernel address space size, and
9878# $kgm_readphys_use_kdp/$kgm_readphys_force_physmap to override
9879# how the user pages are accessed ($kgm_readphys_force_physmap
9880# implies walking the user task's pagetables to get a physical
9881# address and then shadowing data from there using the
9882# physical mapping of memory).
b0d623f7
A
9883define _map_user_data_from_task
9884 set $kgm_map_user_taskp = (task_t)$arg0
9885 set $kgm_map_user_map = $kgm_map_user_taskp->map
9886 set $kgm_map_user_pmap = $kgm_map_user_map->pmap
9887 set $kgm_map_user_task_64 = ( $kgm_map_user_taskp->taskFeatures[0] & 0x80000000)
9888 set $kgm_map_user_window = 0
9889 set $kgm_map_switch_map = 0
9890
6d2010ae
A
9891 if ($kgm_readphys_force_kdp != 0)
9892 set $kgm_readphys_use_kdp = 1
b0d623f7 9893 else
6d2010ae
A
9894 if ($kgm_readphys_force_physmap)
9895 set $kgm_readphys_use_kdp = 0
9896 else
9897 set $kgm_readphys_use_kdp = ( kdp->is_conn > 0 )
b0d623f7
A
9898 end
9899 end
b0d623f7 9900
6d2010ae 9901 if ($kgm_readphys_use_kdp)
b0d623f7 9902
6d2010ae
A
9903 if $kgm_lp64
9904 set $kgm_map_switch_map = 1
9905 else
9906 if !$kgm_map_user_task_64
9907 set $kgm_map_switch_map = 1
9908 end
9909 end
9910
9911 if ($kgm_map_switch_map)
9912 # switch the map safely
9913 set $kgm_map_user_window = $arg1
9914 set kdp_pmap = $kgm_map_user_pmap
9915 else
9916 # requires shadowing/copying
9917
9918 # set up the manual KDP packet
9919 set manual_pkt.input = 0
9920 set manual_pkt.len = sizeof(kdp_readmem64_req_t)
9921 set $kgm_pkt = (kdp_readmem64_req_t *)&manual_pkt.data
9922 set $kgm_pkt->hdr.request = KDP_READMEM64
9923 set $kgm_pkt->hdr.len = sizeof(kdp_readmem64_req_t)
9924 set $kgm_pkt->hdr.is_reply = 0
9925 set $kgm_pkt->hdr.seq = 0
9926 set $kgm_pkt->hdr.key = 0
9927 set $kgm_pkt->address = (uint64_t)$arg1
9928 set $kgm_pkt->nbytes = (uint32_t)$arg2
9929
9930 set kdp_pmap = $kgm_map_user_pmap
9931 set manual_pkt.input = 1
9932 # dummy to make sure manual packet is executed
9933 set $kgm_dummy = &_mh_execute_header
9934 # Go back to kernel map so that we can access buffer directly
9935 set kdp_pmap = 0
9936
9937 set $kgm_pkt = (kdp_readmem64_reply_t *)&manual_pkt.data
9938 if ($kgm_pkt->error == 0)
9939 set $kgm_map_user_window = $kgm_pkt->data
9940 else
9941 set $kgm_map_user_window = 0
9942 end
9943 end
b0d623f7 9944
6d2010ae
A
9945 else
9946 # without the benefit of a KDP stub on the target, try to
9947 # find the user task's physical mapping and memcpy the data.
9948 # If it straddles a page boundary, copy in two passes
9949 set $kgm_vaddr_range1_start = (unsigned long long)$arg1
9950 set $kgm_vaddr_range1_count = (unsigned long long)$arg2
9951 if (($kgm_vaddr_range1_start + $kgm_vaddr_range1_count) & 0xFFF) < $kgm_vaddr_range1_count
9952 set $kgm_vaddr_range2_start = ($kgm_vaddr_range1_start + $kgm_vaddr_range1_count) & ~((unsigned long long)0xFFF)
9953 set $kgm_vaddr_range2_count = $kgm_vaddr_range1_start + $kgm_vaddr_range1_count - $kgm_vaddr_range2_start
9954 set $kgm_vaddr_range1_count = $kgm_vaddr_range2_start - $kgm_vaddr_range1_start
b0d623f7 9955 else
6d2010ae
A
9956 set $kgm_vaddr_range2_start = 0
9957 set $kgm_vaddr_range2_count = 0
b0d623f7 9958 end
6d2010ae
A
9959 set $kgm_paddr_range1_in_kva = 0
9960 set $kgm_paddr_range2_in_kva = 0
b0d623f7 9961
6d2010ae
A
9962 if ($kgm_mtype == $kgm_mtype_x86_64)
9963 set $kgm_pt_verbose = 0
9964 _pmap_walk_x86 $kgm_map_user_pmap $kgm_vaddr_range1_start
9965 if $kgm_paddr_isvalid
9966 set $kgm_paddr_range1_in_kva = $kgm_paddr + (((unsigned long long)-1 << 47) | ((unsigned long long)509 << 39))
9967 end
9968 if $kgm_vaddr_range2_start
9969 _pmap_walk_x86 $kgm_map_user_pmap $kgm_vaddr_range2_start
9970 if $kgm_paddr_isvalid
9971 set $kgm_paddr_range2_in_kva = $kgm_paddr + (((unsigned long long)-1 << 47) | ((unsigned long long)509 << 39))
9972 end
9973 end
9974 else
9975 if ($kgm_mtype == $kgm_mtype_arm)
9976 set $kgm_pt_verbose = 0
9977 _pmap_walk_arm $kgm_map_user_pmap $kgm_vaddr_range1_start
9978 if $kgm_paddr_isvalid
9979 set $kgm_paddr_range1_in_kva = $kgm_paddr - gPhysBase + gVirtBase
9980 end
9981 if $kgm_vaddr_range2_start
9982 _pmap_walk_arm $kgm_map_user_pmap $kgm_vaddr_range2_start
9983 if $kgm_paddr_isvalid
9984 set $kgm_paddr_range2_in_kva = $kgm_paddr - gPhysBase + gVirtBase
9985 end
9986 end
9987 else
9988 printf "Not available for current architecture.\n"
9989 set $kgm_paddr_isvalid = 0
9990 end
9991 end
9992 if $kgm_paddr_range1_in_kva
9993 set $kgm_pkt = (kdp_readmem64_reply_t *)&manual_pkt.data
9994 memcpy $kgm_pkt->data $kgm_paddr_range1_in_kva $kgm_vaddr_range1_count
9995 if $kgm_paddr_range2_in_kva
9996 memcpy &$kgm_pkt->data[$kgm_vaddr_range1_count] $kgm_paddr_range2_in_kva $kgm_vaddr_range2_count
9997 end
9998 set $kgm_map_user_window = $kgm_pkt->data
9999 else
10000 set $kgm_map_user_window = 0
10001 end
b0d623f7
A
10002 end
10003end
10004
10005define _unmap_user_data_from_task
10006 set kdp_pmap = 0
10007end
10008
10009# uses $kgm_taskp. Maps 32 bytes at a time and prints it
10010define _print_path_for_image
10011 set $kgm_print_path_address = (unsigned long long)$arg0
10012 set $kgm_path_str_notdone = 1
6d2010ae
A
10013
10014 if ($kgm_print_path_address == 0)
10015 set $kgm_path_str_notdone = 0
10016 end
b0d623f7
A
10017
10018 while $kgm_path_str_notdone
10019 _map_user_data_from_task $kgm_taskp $kgm_print_path_address 32
10020
10021 set $kgm_print_path_ptr = (char *)$kgm_map_user_window
10022 set $kgm_path_i = 0
10023 while ($kgm_path_i < 32 && $kgm_print_path_ptr[$kgm_path_i] != '\0')
10024 set $kgm_path_i = $kgm_path_i + 1
10025 end
10026 printf "%.32s", $kgm_print_path_ptr
10027
10028 _unmap_user_data_from_task $kgm_taskp
10029
6d2010ae 10030 # break out if we terminated on NUL
b0d623f7
A
10031 if $kgm_path_i < 32
10032 set $kgm_path_str_notdone = 0
10033 else
10034 set $kgm_print_path_address = $kgm_print_path_address + 32
10035 end
10036 end
10037end
10038
6d2010ae 10039# uses $kgm_taskp and $kgm_task_64. May modify $kgm_dyld_load_path
b0d623f7
A
10040define _print_image_info
10041 set $kgm_mh_image_address = (unsigned long long)$arg0
10042 set $kgm_mh_path_address = (unsigned long long)$arg1
10043
10044 # 32 bytes enough for mach_header/mach_header_64
10045 _map_user_data_from_task $kgm_taskp $kgm_mh_image_address 32
10046
10047 set $kgm_mh_ptr = (unsigned int*)$kgm_map_user_window
10048 set $kgm_mh_magic = $kgm_mh_ptr[0]
10049 set $kgm_mh_cputype = $kgm_mh_ptr[1]
10050 set $kgm_mh_cpusubtype = $kgm_mh_ptr[2]
10051 set $kgm_mh_filetype = $kgm_mh_ptr[3]
10052 set $kgm_mh_ncmds = $kgm_mh_ptr[4]
10053 set $kgm_mh_sizeofcmds = $kgm_mh_ptr[5]
10054 set $kgm_mh_flags = $kgm_mh_ptr[6]
10055
10056 _unmap_user_data_from_task $kgm_taskp
10057
10058 if $kgm_mh_magic == 0xfeedfacf
10059 set $kgm_mh_64 = 1
10060 set $kgm_lc_address = $kgm_mh_image_address + 32
10061 else
10062 set $kgm_mh_64 = 0
10063 set $kgm_lc_address = $kgm_mh_image_address + 28
10064 end
10065
10066 set $kgm_lc_idx = 0
10067 set $kgm_uuid_data = 0
10068 while $kgm_lc_idx < $kgm_mh_ncmds
10069
10070 # 24 bytes is size of uuid_command
10071 _map_user_data_from_task $kgm_taskp $kgm_lc_address 24
10072
10073 set $kgm_lc_ptr = (unsigned int *)$kgm_map_user_window
10074 set $kgm_lc_cmd = $kgm_lc_ptr[0]
10075 set $kgm_lc_cmd_size = $kgm_lc_ptr[1]
10076 set $kgm_lc_data = (unsigned char *)$kgm_lc_ptr + 8
10077
10078 if $kgm_lc_cmd == 0x1b
10079 set $kgm_uuid_data = $kgm_lc_data
10080 if $kgm_mh_64
10081 printf "0x%016llx ", $kgm_mh_image_address
10082 else
10083 printf "0x%08x ", $kgm_mh_image_address
10084 end
10085
10086 set $kgm_printed_type = 0
10087 if $kgm_mh_filetype == 0x2
10088 printf "MH_EXECUTE "
10089 set $kgm_printed_type = 1
10090 end
10091 if $kgm_mh_filetype == 0x6
10092 printf "MH_DYLIB "
10093 set $kgm_printed_type = 1
10094 end
10095 if $kgm_mh_filetype == 0x7
10096 printf "MH_DYLINKER "
10097 set $kgm_printed_type = 1
10098 end
10099 if $kgm_mh_filetype == 0x8
10100 printf "MH_BUNDLE "
10101 set $kgm_printed_type = 1
10102 end
10103 if !$kgm_printed_type
10104 printf "UNKNOWN "
10105 end
10106 printf "%02.2X%02.2X%02.2X%02.2X-", $kgm_uuid_data[0], $kgm_uuid_data[1], $kgm_uuid_data[2], $kgm_uuid_data[3]
10107 printf "%02.2X%02.2X-", $kgm_uuid_data[4], $kgm_uuid_data[5]
10108 printf "%02.2X%02.2X-", $kgm_uuid_data[6], $kgm_uuid_data[7]
10109 printf "%02.2X%02.2X-", $kgm_uuid_data[8], $kgm_uuid_data[9]
10110 printf "%02.2X%02.2X%02.2X%02.2X%02.2X%02.2X", $kgm_uuid_data[10], $kgm_uuid_data[11], $kgm_uuid_data[12], $kgm_uuid_data[13], $kgm_uuid_data[14], $kgm_uuid_data[15]
10111
10112 _unmap_user_data_from_task $kgm_taskp
10113
10114 printf " "
10115 _print_path_for_image $kgm_mh_path_address
10116 printf "\n"
10117
10118 loop_break
10119 else
6d2010ae
A
10120 if $kgm_lc_cmd == 0xe
10121 set $kgm_load_dylinker_data = $kgm_lc_data
10122 set $kgm_dyld_load_path = $kgm_lc_address + *((unsigned int *)$kgm_load_dylinker_data)
10123 end
b0d623f7
A
10124 _unmap_user_data_from_task $kgm_taskp
10125 end
10126
10127 set $kgm_lc_address = $kgm_lc_address + $kgm_lc_cmd_size
10128 set $kgm_lc_idx = $kgm_lc_idx + 1
10129 end
10130
10131 if (!$kgm_uuid_data)
10132 # didn't find LC_UUID, for a dylib, just print out basic info
10133 if $kgm_mh_64
10134 printf "0x%016llx ", $kgm_mh_image_address
10135 else
10136 printf "0x%08x ", $kgm_mh_image_address
10137 end
10138 set $kgm_printed_type = 0
10139 if $kgm_mh_filetype == 0x2
10140 printf "MH_EXECUTE "
10141 set $kgm_printed_type = 1
10142 end
10143 if $kgm_mh_filetype == 0x6
10144 printf "MH_DYLIB "
10145 set $kgm_printed_type = 1
10146 end
10147 if $kgm_mh_filetype == 0x7
10148 printf "MH_DYLINKER "
10149 set $kgm_printed_type = 1
10150 end
10151 if $kgm_mh_filetype == 0x8
10152 printf "MH_BUNDLE "
10153 set $kgm_printed_type = 1
10154 end
10155 if !$kgm_printed_type
10156 printf "UNKNOWN "
10157 end
10158 printf " ",
10159
10160 printf " "
10161 _print_path_for_image $kgm_mh_path_address
10162 printf "\n"
10163
10164 end
10165
10166end
10167
10168define _print_images_for_dyld_image_info
10169 set $kgm_taskp = $arg0
10170 set $kgm_task_64 = $arg1
10171 set $kgm_dyld_all_image_infos_address = (unsigned long long)$arg2
10172
6d2010ae 10173 _map_user_data_from_task $kgm_taskp $kgm_dyld_all_image_infos_address 112
b0d623f7
A
10174
10175 set $kgm_dyld_all_image_infos = (unsigned int *)$kgm_map_user_window
6d2010ae
A
10176 set $kgm_dyld_all_image_infos_version = $kgm_dyld_all_image_infos[0]
10177 if ($kgm_dyld_all_image_infos_version > 12)
10178 printf "Unknown dyld all_image_infos version number %d\n", $kgm_dyld_all_image_infos_version
b0d623f7
A
10179 end
10180 set $kgm_image_info_count = $kgm_dyld_all_image_infos[1]
6d2010ae
A
10181
10182 set $kgm_dyld_load_path = 0
b0d623f7
A
10183 if $kgm_task_64
10184 set $kgm_image_info_size = 24
10185 set $kgm_image_info_array_address = ((unsigned long long *)$kgm_dyld_all_image_infos)[1]
6d2010ae 10186 set $kgm_dyld_load_address = ((unsigned long long *)$kgm_dyld_all_image_infos)[4]
b0d623f7
A
10187 else
10188 set $kgm_image_info_size = 12
10189 set $kgm_image_info_array_address = ((unsigned int *)$kgm_dyld_all_image_infos)[2]
6d2010ae 10190 set $kgm_dyld_load_address = ((unsigned int *)$kgm_dyld_all_image_infos)[5]
b0d623f7
A
10191 end
10192
10193 _unmap_user_data_from_task $kgm_taskp
10194
10195 set $kgm_image_info_i = 0
10196 while $kgm_image_info_i < $kgm_image_info_count
10197
10198 set $kgm_image_info_address = $kgm_image_info_array_address + $kgm_image_info_size*$kgm_image_info_i
10199
10200 _map_user_data_from_task $kgm_taskp $kgm_image_info_address $kgm_image_info_size
10201 if $kgm_task_64
10202 set $kgm_image_info_addr = ((unsigned long long *)$kgm_map_user_window)[0]
10203 set $kgm_image_info_path = ((unsigned long long *)$kgm_map_user_window)[1]
10204 else
10205 set $kgm_image_info_addr = ((unsigned int *)$kgm_map_user_window)[0]
10206 set $kgm_image_info_path = ((unsigned int *)$kgm_map_user_window)[1]
10207 end
10208 _unmap_user_data_from_task $kgm_taskp
10209
10210 # printf "[%d] = image address %llx path address %llx\n", $kgm_image_info_i, $kgm_image_info_addr, $kgm_image_info_path
10211 _print_image_info $kgm_image_info_addr $kgm_image_info_path
10212
10213 set $kgm_image_info_i = $kgm_image_info_i + 1
10214 end
6d2010ae
A
10215
10216 # $kgm_dyld_load_path may get set when the main executable is processed
10217 # printf "[dyld] = image address %llx path address %llx\n", $kgm_dyld_load_address, $kgm_dyld_load_path
10218 _print_image_info $kgm_dyld_load_address $kgm_dyld_load_path
10219
b0d623f7
A
10220end
10221
10222define showuserlibraries
6d2010ae
A
10223 set $kgm_taskp = (task_t)$arg0
10224 set $kgm_dyld_image_info = $kgm_taskp->all_image_info_addr
b0d623f7 10225
6d2010ae
A
10226 set $kgm_map = $kgm_taskp->map
10227 set $kgm_task_64 = ( $kgm_taskp->taskFeatures[0] & 0x80000000)
b0d623f7 10228
6d2010ae
A
10229 if ($kgm_dyld_image_info != 0)
10230 printf "address "
10231 if $kgm_task_64
10232 printf " "
10233 end
10234 printf " type "
10235 printf " uuid "
10236 printf "path\n"
b0d623f7 10237
6d2010ae
A
10238 _print_images_for_dyld_image_info $kgm_taskp $kgm_task_64 $kgm_dyld_image_info
10239 else
10240 printf "No dyld shared library information available for task\n"
10241 end
b0d623f7
A
10242end
10243document showuserlibraries
10244Syntax: (gdb) showuserlibraries <task_t>
10245| For a given user task, inspect the dyld shared library state and print
10246| information about all Mach-O images.
10247end
10248
6d2010ae
A
10249define showuserdyldinfo
10250 set $kgm_taskp = (task_t)$arg0
10251 set $kgm_dyld_all_image_infos_address = (unsigned long long)$kgm_taskp->all_image_info_addr
10252
10253 set $kgm_map = $kgm_taskp->map
10254 set $kgm_task_64 = ( $kgm_taskp->taskFeatures[0] & 0x80000000)
10255
10256 if ($kgm_dyld_all_image_infos_address != 0)
10257
10258 _map_user_data_from_task $kgm_taskp $kgm_dyld_all_image_infos_address 112
10259
10260 set $kgm_dyld_all_image_infos = (unsigned char *)$kgm_map_user_window
10261 set $kgm_dyld_all_image_infos_version = ((unsigned int *)$kgm_dyld_all_image_infos)[0]
10262 if ($kgm_dyld_all_image_infos_version > 12)
10263 printf "Unknown dyld all_image_infos version number %d\n", $kgm_dyld_all_image_infos_version
10264 end
10265
10266 # Find fields by byte offset. We assume at least version 9 is supported
10267 if $kgm_task_64
10268 set $kgm_dyld_all_image_infos_infoArrayCount = *(unsigned int *)(&$kgm_dyld_all_image_infos[4])
10269 set $kgm_dyld_all_image_infos_infoArray = *(unsigned long long *)(&$kgm_dyld_all_image_infos[8])
10270 set $kgm_dyld_all_image_infos_notification = *(unsigned long long *)(&$kgm_dyld_all_image_infos[16])
10271 set $kgm_dyld_all_image_infos_processDetachedFromSharedRegion = *(unsigned char *)(&$kgm_dyld_all_image_infos[24])
10272 set $kgm_dyld_all_image_infos_libSystemInitialized = *(unsigned char *)(&$kgm_dyld_all_image_infos[25])
10273 set $kgm_dyld_all_image_infos_dyldImageLoadAddress = *(unsigned long long *)(&$kgm_dyld_all_image_infos[32])
10274 set $kgm_dyld_all_image_infos_jitInfo = *(unsigned long long *)(&$kgm_dyld_all_image_infos[40])
10275 set $kgm_dyld_all_image_infos_dyldVersion = *(unsigned long long *)(&$kgm_dyld_all_image_infos[48])
10276 set $kgm_dyld_all_image_infos_errorMessage = *(unsigned long long *)(&$kgm_dyld_all_image_infos[56])
10277 set $kgm_dyld_all_image_infos_terminationFlags = *(unsigned long long *)(&$kgm_dyld_all_image_infos[64])
10278 set $kgm_dyld_all_image_infos_coreSymbolicationShmPage = *(unsigned long long *)(&$kgm_dyld_all_image_infos[72])
10279 set $kgm_dyld_all_image_infos_systemOrderFlag = *(unsigned long long *)(&$kgm_dyld_all_image_infos[80])
10280 set $kgm_dyld_all_image_infos_uuidArrayCount = *(unsigned long long *)(&$kgm_dyld_all_image_infos[88])
10281 set $kgm_dyld_all_image_infos_uuidArray = *(unsigned long long *)(&$kgm_dyld_all_image_infos[96])
10282 set $kgm_dyld_all_image_infos_dyldAllImageInfosAddress = *(unsigned long long *)(&$kgm_dyld_all_image_infos[104])
10283 else
10284 set $kgm_dyld_all_image_infos_infoArrayCount = *(unsigned int *)(&$kgm_dyld_all_image_infos[4])
10285 set $kgm_dyld_all_image_infos_infoArray = *(unsigned int *)(&$kgm_dyld_all_image_infos[8])
10286 set $kgm_dyld_all_image_infos_notification = *(unsigned int *)(&$kgm_dyld_all_image_infos[12])
10287 set $kgm_dyld_all_image_infos_processDetachedFromSharedRegion = *(unsigned char *)(&$kgm_dyld_all_image_infos[16])
10288 set $kgm_dyld_all_image_infos_libSystemInitialized = *(unsigned char *)(&$kgm_dyld_all_image_infos[17])
10289 set $kgm_dyld_all_image_infos_dyldImageLoadAddress = *(unsigned int *)(&$kgm_dyld_all_image_infos[20])
10290 set $kgm_dyld_all_image_infos_jitInfo = *(unsigned int *)(&$kgm_dyld_all_image_infos[24])
10291 set $kgm_dyld_all_image_infos_dyldVersion = *(unsigned int *)(&$kgm_dyld_all_image_infos[28])
10292 set $kgm_dyld_all_image_infos_errorMessage = *(unsigned int *)(&$kgm_dyld_all_image_infos[32])
10293 set $kgm_dyld_all_image_infos_terminationFlags = *(unsigned int *)(&$kgm_dyld_all_image_infos[36])
10294 set $kgm_dyld_all_image_infos_coreSymbolicationShmPage = *(unsigned int *)(&$kgm_dyld_all_image_infos[40])
10295 set $kgm_dyld_all_image_infos_systemOrderFlag = *(unsigned int *)(&$kgm_dyld_all_image_infos[44])
10296 set $kgm_dyld_all_image_infos_uuidArrayCount = *(unsigned int *)(&$kgm_dyld_all_image_infos[48])
10297 set $kgm_dyld_all_image_infos_uuidArray = *(unsigned int *)(&$kgm_dyld_all_image_infos[52])
10298 set $kgm_dyld_all_image_infos_dyldAllImageInfosAddress = *(unsigned int *)(&$kgm_dyld_all_image_infos[56])
10299 end
10300
10301 _unmap_user_data_from_task $kgm_taskp
10302
10303 printf " version %u\n", $kgm_dyld_all_image_infos_version
10304 printf " infoArrayCount %u\n", $kgm_dyld_all_image_infos_infoArrayCount
10305 printf " infoArray "
10306 showuserptr $kgm_dyld_all_image_infos_infoArray
10307 printf "\n"
10308 printf " notification "
10309 showuserptr $kgm_dyld_all_image_infos_notification
10310 printf "\n"
10311 printf "processDetachedFromSharedRegion %d\n", $kgm_dyld_all_image_infos_processDetachedFromSharedRegion
10312 printf " libSystemInitialized %d\n", $kgm_dyld_all_image_infos_libSystemInitialized
10313 printf " dyldImageLoadAddress "
10314 showuserptr $kgm_dyld_all_image_infos_dyldImageLoadAddress
10315 printf "\n"
10316 printf " jitInfo "
10317 showuserptr $kgm_dyld_all_image_infos_jitInfo
10318 printf "\n"
10319 printf " dyldVersion "
10320 showuserptr $kgm_dyld_all_image_infos_dyldVersion
10321 printf "\n"
10322 printf " "
10323 _print_path_for_image $kgm_dyld_all_image_infos_dyldVersion
10324 printf "\n"
10325
10326 printf " errorMessage "
10327 showuserptr $kgm_dyld_all_image_infos_errorMessage
10328 printf "\n"
10329 if $kgm_dyld_all_image_infos_errorMessage != 0
10330 printf " "
10331 _print_path_for_image $kgm_dyld_all_image_infos_errorMessage
10332 printf "\n"
10333 end
10334
10335 printf " terminationFlags "
10336 showuserptr $kgm_dyld_all_image_infos_terminationFlags
10337 printf "\n"
10338 printf " coreSymbolicationShmPage "
10339 showuserptr $kgm_dyld_all_image_infos_coreSymbolicationShmPage
10340 printf "\n"
10341 printf " systemOrderFlag "
10342 showuserptr $kgm_dyld_all_image_infos_systemOrderFlag
10343 printf "\n"
10344 printf " uuidArrayCount "
10345 showuserptr $kgm_dyld_all_image_infos_uuidArrayCount
10346 printf "\n"
10347 printf " uuidArray "
10348 showuserptr $kgm_dyld_all_image_infos_uuidArray
10349 printf "\n"
10350 printf " dyldAllImageInfosAddress "
10351 showuserptr $kgm_dyld_all_image_infos_dyldAllImageInfosAddress
10352 printf "\n"
10353 printf " (currently "
10354 showuserptr $kgm_dyld_all_image_infos_address
10355 printf ")\n"
10356
10357 if $kgm_task_64
10358 set $kgm_dyld_all_image_infos_address = $kgm_dyld_all_image_infos_address + 112
10359 _map_user_data_from_task $kgm_taskp $kgm_dyld_all_image_infos_address 64
10360 set $kgm_dyld_all_image_infos_v10 = (unsigned char *)$kgm_map_user_window
10361 set $kgm_dyld_all_image_infos_initialImageCount = *(unsigned long long *)(&$kgm_dyld_all_image_infos_v10[112-112])
10362 set $kgm_dyld_all_image_infos_errorKind = *(unsigned long long *)(&$kgm_dyld_all_image_infos_v10[120-112])
10363 set $kgm_dyld_all_image_infos_errorClientOfDylibPath = *(unsigned long long *)(&$kgm_dyld_all_image_infos_v10[128-112])
10364 set $kgm_dyld_all_image_infos_errorTargetDylibPath = *(unsigned long long *)(&$kgm_dyld_all_image_infos_v10[136-112])
10365 set $kgm_dyld_all_image_infos_errorSymbol = *(unsigned long long *)(&$kgm_dyld_all_image_infos_v10[144-112])
10366 set $kgm_dyld_all_image_infos_sharedCacheSlide = *(unsigned long long *)(&$kgm_dyld_all_image_infos_v10[152-112])
10367
10368 _unmap_user_data_from_task $kgm_taskp
10369 else
10370 set $kgm_dyld_all_image_infos_address = $kgm_dyld_all_image_infos_address + 60
10371 _map_user_data_from_task $kgm_taskp $kgm_dyld_all_image_infos_address 64
10372 set $kgm_dyld_all_image_infos_v10 = (unsigned char *)$kgm_map_user_window
10373 set $kgm_dyld_all_image_infos_initialImageCount = *(unsigned int *)(&$kgm_dyld_all_image_infos_v10[60-60])
10374 set $kgm_dyld_all_image_infos_errorKind = *(unsigned int *)(&$kgm_dyld_all_image_infos_v10[64-60])
10375 set $kgm_dyld_all_image_infos_errorClientOfDylibPath = *(unsigned int *)(&$kgm_dyld_all_image_infos_v10[68-60])
10376 set $kgm_dyld_all_image_infos_errorTargetDylibPath = *(unsigned int *)(&$kgm_dyld_all_image_infos_v10[72-60])
10377 set $kgm_dyld_all_image_infos_errorSymbol = *(unsigned int *)(&$kgm_dyld_all_image_infos_v10[76-60])
10378 set $kgm_dyld_all_image_infos_sharedCacheSlide = *(unsigned int *)(&$kgm_dyld_all_image_infos_v10[80-60])
10379 _unmap_user_data_from_task $kgm_taskp
10380 end
10381
10382 if $kgm_dyld_all_image_infos_version >= 10
10383 printf " initialImageCount "
10384 showuserptr $kgm_dyld_all_image_infos_initialImageCount
10385 printf "\n"
10386 end
10387
10388 if $kgm_dyld_all_image_infos_version >= 11
10389 printf " errorKind "
10390 showuserptr $kgm_dyld_all_image_infos_errorKind
10391 printf "\n"
10392 printf " errorClientOfDylibPath "
10393 showuserptr $kgm_dyld_all_image_infos_errorClientOfDylibPath
10394 printf "\n"
10395 if $kgm_dyld_all_image_infos_errorClientOfDylibPath != 0
10396 printf " "
10397 _print_path_for_image $kgm_dyld_all_image_infos_errorClientOfDylibPath
10398 printf "\n"
10399 end
10400 printf " errorTargetDylibPath "
10401 showuserptr $kgm_dyld_all_image_infos_errorTargetDylibPath
10402 printf "\n"
10403 if $kgm_dyld_all_image_infos_errorTargetDylibPath != 0
10404 printf " "
10405 _print_path_for_image $kgm_dyld_all_image_infos_errorTargetDylibPath
10406 printf "\n"
10407 end
10408 printf " errorSymbol "
10409 showuserptr $kgm_dyld_all_image_infos_errorSymbol
10410 printf "\n"
10411 if $kgm_dyld_all_image_infos_errorSymbol != 0
10412 printf " "
10413 _print_path_for_image $kgm_dyld_all_image_infos_errorSymbol
10414 printf "\n"
10415 end
10416 end
10417
10418 if $kgm_dyld_all_image_infos_version >= 12
10419 printf " sharedCacheSlide "
10420 showuserptr $kgm_dyld_all_image_infos_sharedCacheSlide
10421 printf "\n"
10422 end
10423
10424 else
10425 printf "No dyld information available for task\n"
10426 end
10427end
10428document showuserdyldinfo
10429Syntax: (gdb) showuserdyldinfo <task_t>
10430| For a given user task, inspect the dyld global info and print
10431| out all fields, including error messages.
10432end
10433
b0d623f7
A
10434define showkerneldebugheader
10435 printf "kd_buf "
10436 showptrhdrpad
10437 printf "CPU Thread "
10438 showptrhdrpad
10439 printf "Timestamp S/E Class Sub Code Code Specific Info\n"
10440end
10441
10442define _printevflags
10443 if $arg0 & 1
10444 printf "EV_RE "
10445 end
10446 if $arg0 & 2
10447 printf "EV_WR "
10448 end
10449 if $arg0 & 4
10450 printf "EV_EX "
10451 end
10452 if $arg0 & 8
10453 printf "EV_RM "
10454 end
10455
10456 if $arg0 & 0x00100
10457 printf "EV_RBYTES "
10458 end
10459 if $arg0 & 0x00200
10460 printf "EV_WBYTES "
10461 end
10462 if $arg0 & 0x00400
10463 printf "EV_RCLOSED "
10464 end
10465 if $arg0 & 0x00800
10466 printf "EV_RCONN "
10467 end
10468 if $arg0 & 0x01000
10469 printf "EV_WCLOSED "
10470 end
10471 if $arg0 & 0x02000
10472 printf "EV_WCONN "
10473 end
10474 if $arg0 & 0x04000
10475 printf "EV_OOB "
10476 end
10477 if $arg0 & 0x08000
10478 printf "EV_FIN "
10479 end
10480 if $arg0 & 0x10000
10481 printf "EV_RESET "
10482 end
10483 if $arg0 & 0x20000
10484 printf "EV_TIMEOUT "
10485 end
10486end
10487
10488define showkerneldebugbufferentry
10489 set $kgm_kdebug_entry = (kd_buf *) $arg0
10490
10491 set $kgm_debugid = $kgm_kdebug_entry->debugid
10492 set $kgm_kdebug_arg1 = $kgm_kdebug_entry->arg1
10493 set $kgm_kdebug_arg2 = $kgm_kdebug_entry->arg2
10494 set $kgm_kdebug_arg3 = $kgm_kdebug_entry->arg3
10495 set $kgm_kdebug_arg4 = $kgm_kdebug_entry->arg4
10496
10497 if $kgm_lp64
10498 set $kgm_kdebug_cpu = $kgm_kdebug_entry->cpuid
10499 set $kgm_ts_hi = ($kgm_kdebug_entry->timestamp >> 32) & 0xFFFFFFFF
10500 set $kgm_ts_lo = $kgm_kdebug_entry->timestamp & 0xFFFFFFFF
10501 else
10502 set $kgm_kdebug_cpu = ($kgm_kdebug_entry->timestamp >> 56)
10503 set $kgm_ts_hi = ($kgm_kdebug_entry->timestamp >> 32) & 0x00FFFFFF
10504 set $kgm_ts_lo = $kgm_kdebug_entry->timestamp & 0xFFFFFFFF
10505 end
10506
10507 set $kgm_kdebug_class = ($kgm_debugid >> 24) & 0x000FF
10508 set $kgm_kdebug_subclass = ($kgm_debugid >> 16) & 0x000FF
10509 set $kgm_kdebug_code = ($kgm_debugid >> 2) & 0x03FFF
10510 set $kgm_kdebug_qual = ($kgm_debugid ) & 0x00003
10511
10512 if $kgm_kdebug_qual == 0
10513 set $kgm_kdebug_qual = '-'
10514 else
10515 if $kgm_kdebug_qual == 1
10516 set $kgm_kdebug_qual = 'S'
10517 else
10518 if $kgm_kdebug_qual == 2
10519 set $kgm_kdebug_qual = 'E'
10520 else
10521 if $kgm_kdebug_qual == 3
10522 set $kgm_kdebug_qual = '?'
10523 end
10524 end
10525 end
10526 end
10527
10528 # preamble and qual
10529
10530 showptr $kgm_kdebug_entry
10531 printf " %d ", $kgm_kdebug_cpu
10532 showptr $kgm_kdebug_entry->arg5
10533 printf " 0x%08X%08X %c ", $kgm_ts_hi, $kgm_ts_lo, $kgm_kdebug_qual
10534
10535 # class
10536
10537 if $kgm_kdebug_class == 1
10538 printf "MACH"
10539 else
10540 if $kgm_kdebug_class == 2
10541 printf "NET "
10542 else
10543 if $kgm_kdebug_class == 3
10544 printf "FS "
10545 else
10546 if $kgm_kdebug_class == 4
10547 printf "BSD "
10548 else
10549 if $kgm_kdebug_class == 5
10550 printf "IOK "
10551 else
10552 if $kgm_kdebug_class == 6
10553 printf "DRVR"
10554 else
10555 if $kgm_kdebug_class == 7
10556 printf "TRAC"
10557 else
10558 if $kgm_kdebug_class == 8
10559 printf "DLIL"
10560 else
10561 if $kgm_kdebug_class == 8
10562 printf "SEC "
10563 else
10564 if $kgm_kdebug_class == 20
10565 printf "MISC"
10566 else
10567 if $kgm_kdebug_class == 31
10568 printf "DYLD"
10569 else
10570 if $kgm_kdebug_class == 32
10571 printf "QT "
10572 else
10573 if $kgm_kdebug_class == 33
10574 printf "APPS"
10575 else
10576 if $kgm_kdebug_class == 255
10577 printf "MIG "
10578 else
10579 printf "0x%02X", $kgm_kdebug_class
10580 end
10581 end
10582 end
10583 end
10584 end
10585 end
10586 end
10587 end
10588 end
10589 end
10590 end
10591 end
10592 end
10593 end
10594
10595 # subclass and code
10596
10597 printf " 0x%02X %5d ", $kgm_kdebug_subclass, $kgm_kdebug_code
10598
10599 # space for debugid-specific processing
10600
10601 # EVPROC from bsd/kern/sys_generic.c
10602
10603 # MISCDBG_CODE(DBG_EVENT,DBG_WAIT)
10604 if $kgm_debugid == 0x14100048
10605 printf "waitevent "
10606 if $kgm_kdebug_arg1 == 1
10607 printf "before sleep"
10608 else
10609 if $kgm_kdebug_arg1 == 2
10610 printf "after sleep"
10611 else
10612 printf "????????????"
10613 end
10614 end
10615 printf " chan=0x%08X ", $kgm_kdebug_arg2
10616 else
10617 # MISCDBG_CODE(DBG_EVENT,DBG_WAIT|DBG_FUNC_START)
10618 if $kgm_debugid == 0x14100049
10619 printf "waitevent "
10620 else
10621 # MISCDBG_CODE(DBG_EVENT,DBG_WAIT|DBG_FUNC_END)
10622 if $kgm_debugid == 0x1410004a
10623 printf "waitevent error=%d ", $kgm_kdebug_arg1
10624 printf "eqp=0x%08X ", $kgm_kdebug_arg4
10625 _printevflags $kgm_kdebug_arg3
10626 printf "er_handle=%d ", $kgm_kdebug_arg2
10627 else
10628 # MISCDBG_CODE(DBG_EVENT,DBG_DEQUEUE|DBG_FUNC_START)
10629 if $kgm_debugid == 0x14100059
10630 printf "evprocdeque proc=0x%08X ", $kgm_kdebug_arg1
10631 if $kgm_kdebug_arg2 == 0
10632 printf "remove first "
10633 else
10634 printf "remove 0x%08X ", $kgm_kdebug_arg2
10635 end
10636 else
10637 # MISCDBG_CODE(DBG_EVENT,DBG_DEQUEUE|DBG_FUNC_END)
10638 if $kgm_debugid == 0x1410005a
10639 printf "evprocdeque "
10640 if $kgm_kdebug_arg1 == 0
10641 printf "result=NULL "
10642 else
10643 printf "result=0x%08X ", $kgm_kdebug_arg1
10644 end
10645 else
10646 # MISCDBG_CODE(DBG_EVENT,DBG_POST|DBG_FUNC_START)
10647 if $kgm_debugid == 0x14100041
10648 printf "postevent "
10649 _printevflags $kgm_kdebug_arg1
10650 else
10651 # MISCDBG_CODE(DBG_EVENT,DBG_POST)
10652 if $kgm_debugid == 0x14100040
10653 printf "postevent "
10654 printf "evq=0x%08X ", $kgm_kdebug_arg1
10655 printf "er_eventbits="
10656 _printevflags $kgm_kdebug_arg2
10657 printf "mask="
10658 _printevflags $kgm_kdebug_arg3
10659 else
10660 # MISCDBG_CODE(DBG_EVENT,DBG_POST|DBG_FUNC_END)
10661 if $kgm_debugid == 0x14100042
10662 printf "postevent "
10663 else
10664 # MISCDBG_CODE(DBG_EVENT,DBG_ENQUEUE|DBG_FUNC_START)
10665 if $kgm_debugid == 0x14100055
10666 printf "evprocenque eqp=0x%08d ", $kgm_kdebug_arg1
10667 if $kgm_kdebug_arg2 & 1
10668 printf "EV_QUEUED "
10669 end
10670 _printevflags $kgm_kdebug_arg3
10671 else
10672
10673 # MISCDBG_CODE(DBG_EVENT,DBG_EWAKEUP)
10674 if $kgm_debugid == 0x14100050
10675 printf "evprocenque before wakeup eqp=0x%08d ", $kgm_kdebug_arg4
10676 else
10677 # MISCDBG_CODE(DBG_EVENT,DBG_ENQUEUE|DBG_FUNC_END)
10678 if $kgm_debugid == 0x14100056
10679 printf "evprocenque "
10680 else
10681 # MISCDBG_CODE(DBG_EVENT,DBG_MOD|DBG_FUNC_START)
10682 if $kgm_debugid == 0x1410004d
10683 printf "modwatch "
10684 else
10685 # MISCDBG_CODE(DBG_EVENT,DBG_MOD)
10686 if $kgm_debugid == 0x1410004c
10687 printf "modwatch er_handle=%d ", $kgm_kdebug_arg1
10688 _printevflags $kgm_kdebug_arg2
10689 printf "evq=0x%08X ", $kgm_kdebug_arg3
10690 else
10691 # MISCDBG_CODE(DBG_EVENT,DBG_MOD|DBG_FUNC_END)
10692 if $kgm_debugid == 0x1410004e
10693 printf "modwatch er_handle=%d ", $kgm_kdebug_arg1
10694 printf "ee_eventmask="
10695 _printevflags $kgm_kdebug_arg2
10696 printf "sp=0x%08X ", $kgm_kdebug_arg3
10697 printf "flag="
10698 _printevflags $kgm_kdebug_arg4
10699 else
10700 printf "arg1=0x%08X ", $kgm_kdebug_arg1
10701 printf "arg2=0x%08X ", $kgm_kdebug_arg2
10702 printf "arg3=0x%08X ", $kgm_kdebug_arg3
10703 printf "arg4=0x%08X ", $kgm_kdebug_arg4
10704 end
10705 end
10706 end
10707 end
10708 end
10709 end
10710 end
10711 end
10712 end
10713 end
10714 end
10715 end
10716 end
10717 end
10718
10719 # finish up
10720
10721 printf "\n"
10722end
10723
10724define showkerneldebugbuffercpu
10725 set $kgm_cpu_number = (int) $arg0
10726 set $kgm_entry_count = (int) $arg1
10727 set $kgm_debugentriesfound = 0
10728
6d2010ae 10729 if (kdebug_flags & 0x80000000) # 0x80000000 == KDBG_BFINIT
b0d623f7
A
10730 showkerneldebugheader
10731
10732 if $kgm_entry_count == 0
10733 printf "<count> is 0, dumping 50 entries\n"
10734 set $kgm_entry_count = 50
10735 end
10736
10737 if $kgm_cpu_number >= kd_cpus
10738 printf "cpu number too big\n"
10739 else
10740 set $kgm_kdbp = &kdbip[$kgm_cpu_number]
10741 set $kgm_kdsp = $kgm_kdbp->kd_list_head
10742 while (($kgm_kdsp != 0) && ($kgm_entry_count > 0))
10743 if $kgm_kdsp->kds_readlast != $kgm_kdsp->kds_bufptr
10744 set $kgm_kds_bufptr = $kgm_kdsp->kds_bufptr
10745 while (($kgm_kds_bufptr > $kgm_kdsp->kds_readlast) && ($kgm_entry_count > 0))
10746 set $kgm_kds_bufptr = $kgm_kds_bufptr - 1
10747 set $kgm_entry_count = $kgm_entry_count - 1
10748 showkerneldebugbufferentry $kgm_kds_bufptr
10749 end
10750 end
10751 set $kgm_kdsp = $kgm_kdsp->kds_next
10752 end
10753 end
10754 else
10755 printf "Trace buffer not enabled\n"
10756 end
10757end
10758
10759document showkerneldebugbuffercpu
10760Syntax: showkerneldebugbuffercpu <cpu> <count>
10761| Prints the last N entries in the kernel debug buffer for CPU x.
10762end
10763
10764define showkerneldebugbuffer
10765
6d2010ae 10766 if (kdebug_flags & 0x80000000) # 0x80000000 == KDBG_BFINIT
b0d623f7
A
10767
10768 set $kgm_entrycount = (int) $arg0
10769
10770 if $kgm_entrycount == 0
10771 printf "<count> is 0, dumping 50 entries per cpu\n"
10772 set $kgm_entrycount = 50
10773 end
10774
10775 set $kgm_cpu = (int) 0
10776
10777 while $kgm_cpu < kd_cpus
10778 showkerneldebugbuffercpu $kgm_cpu $kgm_entrycount
10779 set $kgm_cpu = $kgm_cpu + 1
10780 end
10781 else
10782 printf "Trace buffer not enabled\n"
10783 end
10784end
10785
10786document showkerneldebugbuffer
10787Syntax: showkerneldebugbuffer <count>
10788| Prints the last N entries in the kernel debug buffer per cpu. i.e. showkerneldebugbuffer 50 will
10789| display the last 50 entries in each CPU's debug buffer.
10790end
10791
10792define showallvmstats
10793 printf " pid command #ents wired vsize rsize max rsize\n"
10794 printf " (pages) (pages) (pages) (pages)\n"
10795 set $kgm_head_taskp = &tasks
10796 set $kgm_taskp = (struct task *)($kgm_head_taskp->next)
10797 while $kgm_taskp != $kgm_head_taskp
10798 set $kgm_procp = (struct proc *)($kgm_taskp->bsd_info)
10799 set $kgm_mapp = (struct _vm_map *)($kgm_taskp->map)
10800 printf "%8d %17s %8d %15d %15d %15d %15d\n", $kgm_procp->p_pid, $kgm_procp->p_comm, $kgm_mapp->hdr.nentries, $kgm_mapp->pmap->stats.wired_count, $kgm_mapp->size >> 12, $kgm_mapp->pmap->stats.resident_count, $kgm_mapp->pmap->stats.resident_max
10801 set $kgm_taskp = (struct task *)($kgm_taskp->tasks.next)
10802 end
10803end
10804
10805document showallvmstats
10806Syntax: showallvmstats
10807| prints a summary of vm statistics in a table format
10808end
10809
6d2010ae
A
10810define memstats
10811 if ($kgm_mtype == $kgm_mtype_arm)
10812 printf "kern_memorystatus_level: %8d\n", kern_memorystatus_level
10813 end
10814 printf "vm_page_throttled_count: %8d\n", vm_page_throttled_count
10815 printf "vm_page_active_count: %8d\n", vm_page_active_count
10816 printf "vm_page_inactive_count: %8d\n", vm_page_inactive_count
10817 printf "vm_page_wire_count: %8d\n", vm_page_wire_count
10818 printf "vm_page_free_count: %8d\n", vm_page_free_count
10819 printf "vm_page_purgeable_count: %8d\n", vm_page_purgeable_count
10820 printf "vm_page_inactive_target: %8d\n", vm_page_inactive_target
10821 printf "vm_page_free_target: %8d\n", vm_page_free_target
10822 printf "inuse_ptepages_count: %8d\n", inuse_ptepages_count
10823 printf "vm_page_free_reserved: %8d\n", vm_page_free_reserved
10824end
10825
10826document memstats
10827Syntax: (gdb) memstats
10828| Prints out a summary of various memory statistics. In particular vm_page_wire_count should
10829| be greater than 2K or you are under memory pressure.
10830end
10831
b0d623f7 10832define show_user_registers
6d2010ae 10833 showuserregisters $arg0
b0d623f7
A
10834end
10835
10836document show_user_registers
10837Syntax: show_user_registers <thread_address>
10838| Display user registers associated with a kernel thread
10839| properly displays the 32 bit or 64 bit registers for intel architecture
10840end
10841
10842define _cmp
10843 set $cmp0 = $arg0
10844 set $cmp1 = $arg1
10845
10846 # check for end of string. cmp0 can be longer than cmp1. it
10847 # can't be shorter.
10848 if $cmp1 == '\0'
10849 set $kgm_strcmp_result = 0
10850 set $kgm_strcmp_done = 1
10851 end
10852
10853 if !$kgm_strcmp_done && $cmp0 == '\0'
10854 set $kgm_strcmp_result = -1
10855 set $kgm_strcmp_done = 1
10856 end
10857
10858 # do they match?
10859 if !$kgm_strcmp_done
10860 set $kgm_strcmp_result = (uint8_t) $cmp0 - (uint8_t) $cmp1
10861 if $kgm_strcmp_result != 0
10862 set $kgm_strcmp_done = 1
10863 end
10864 end
10865end
10866
10867define _cmp_arg64
10868 set $cmp = $arg1
10869 set $masked = $cmp & 0xFF
10870 _cmp $arg0[0] $masked
10871
10872 if !$kgm_strcmp_done
10873 set $cmp = $cmp >> 8
10874 set $masked = $cmp & 0xFF
10875 _cmp $arg0[1] $masked
10876 end
10877 if !$kgm_strcmp_done
10878 set $cmp = $cmp >> 8
10879 set $masked = $cmp & 0xFF
10880 _cmp $arg0[2] $masked
10881 end
10882 if !$kgm_strcmp_done
10883 set $cmp = $cmp >> 8
10884 set $masked = $cmp & 0xFF
10885 _cmp $arg0[3] $masked
10886 end
10887 if !$kgm_strcmp_done
10888 set $cmp = $cmp >> 8
10889 set $masked = $cmp & 0xFF
10890 _cmp $arg0[4] $masked
10891 end
10892 if !$kgm_strcmp_done
10893 set $cmp = $cmp >> 8
10894 set $masked = $cmp & 0xFF
10895 _cmp $arg0[5] $masked
10896 end
10897 if !$kgm_strcmp_done
10898 set $cmp = $cmp >> 8
10899 set $masked = $cmp & 0xFF
10900 _cmp $arg0[6] $masked
10901 end
10902 if !$kgm_strcmp_done
10903 set $cmp = $cmp >> 8
10904 set $masked = $cmp & 0xFF
10905 _cmp $arg0[7] $masked
10906 end
10907end
10908
10909define strcmp_arg_pack64
10910 set $kgm_strcmp_arg = ((((((((((((((uint64_t) $arg7 << 8) | $arg6) << 8) | $arg5) << 8) | $arg4) << 8) | $arg3) << 8) | $arg2) << 8) | $arg1) << 8) | $arg0
10911end
10912
10913document strcmp_arg_pack64
10914Syntax: strcmp_arg_pack64 <a> <b> <c> <d> <e <f> <g> <h>
10915| Packs a string given as 8 character arguments into a 64-bit int stored in
10916| $kgm_strcmp_arg. Use 0 or '\0' for unused arguments. The encoded string
10917| is suitable for use by strcmp_nomalloc and setfindregistrystr.
10918| e.g., strcmp_arg_pack64 'H' 'e' 'l' 'l' 'o' 0 0 0
10919| packs "Hello" into $kgm_strcmp_arg.
10920|
10921end
10922
10923define strcmp_nomalloc
10924 set $str = $arg0
10925 set $count = $argc - 1
10926
10927 set $kgm_strcmp_result = 0
10928 set $kgm_strcmp_done = 0
10929
10930 if $count > 0
10931 _cmp_arg64 $str $arg1
10932 end
10933 if !$kgm_strcmp_done && $count > 1
10934 set $str = $str + 8
10935 _cmp_arg64 $str $arg2
10936 end
10937 if !$kgm_strcmp_done && $count > 2
10938 set $str = $str + 8
10939 _cmp_arg64 $str $arg3
10940 end
10941 if !$kgm_strcmp_done && $count > 3
10942 set $str = $str + 8
10943 _cmp_arg64 $str $arg4
10944 end
10945 if !$kgm_strcmp_done && $count > 4
10946 set $str = $str + 8
10947 _cmp_arg64 $str $arg5
10948 end
10949 if !$kgm_strcmp_done && $count > 5
10950 set $str = $str + 8
10951 _cmp_arg64 $str $arg6
10952 end
10953 if !$kgm_strcmp_done && $count > 6
10954 set $str = $str + 8
10955 _cmp_arg64 $str $arg7
10956 end
10957 if !$kgm_strcmp_done && $count > 7
10958 set $str = $str + 8
10959 _cmp_arg64 $str $arg8
10960 end
10961 if !$kgm_strcmp_done && $count > 8
10962 set $str = $str + 8
10963 _cmp_arg64 $str $arg9
10964 end
10965end
10966
10967document strcmp_nomalloc
10968Syntax: strcmp_nomalloc <string> <a> [b] [c] [d] [e] [f] [g] [h] [i]
10969| Given a pre-allocated <string>, perform a string compare with the
10970| encoded string stored in arguments a - i. The result is stored in
10971| $kgm_strcmp_result.
10972|
10973| For example, the following will result in $kgm_strcmp_result == 0:
10974| strcmp_arg_pack64 'D' 'a' 'r' 'w' 'i' 'n' ' ' 'K'
10975| strcmp_nomalloc version $kgm_strcmp_arg
10976end
10977
6d2010ae
A
10978define memcpy
10979 set $kgm_dst = (unsigned char *)$arg0
10980 set $kgm_src = (unsigned char *)$arg1
10981 set $kgm_count = $arg2
10982
10983 # printf "src %p dst %p len %d\n", $kgm_src, $kgm_dst, $kgm_count
10984
10985 while ($kgm_count >= 8)
10986 set *(unsigned long long *)$kgm_dst = *(unsigned long long *)$kgm_src
10987
10988 set $kgm_dst = $kgm_dst + 8
10989 set $kgm_src = $kgm_src + 8
10990 set $kgm_count = $kgm_count - 8
10991 end
10992 while ($kgm_count > 0)
10993 set *$kgm_dst = *$kgm_src
10994
10995 set $kgm_dst = $kgm_dst + 1
10996 set $kgm_src = $kgm_src + 1
10997 set $kgm_count = $kgm_count - 1
10998 end
10999end
11000
11001document memcpy
11002Syntax: memcpy <dst> <src> <n>
11003| Given two addresses that are accessible by the debugger, perform
11004| a memory copy of <n> bytes from <src> to <dst>
11005end
11006
b0d623f7
A
11007# _pci_cfg_addr_value $addr $size
11008define _pci_cfg_addr_value
11009 readphysint $arg0 $arg1 $kgm_lcpu_self
11010 set $kgm_pci_cfg_value = $kgm_readphysint_result
11011end
11012
11013
11014set $kgm_pci_cfg_init = 0
11015define _pci_cfg_init
11016 # get this from the registry if it exists there
11017 if $kgm_pci_cfg_init == 0
11018 strcmp_arg_pack64 'A' 'p' 'p' 'l' 'e' 'A' 'C' 'P'
11019 set $AppleACP = $kgm_strcmp_arg
11020 strcmp_arg_pack64 'I' 'P' 'l' 'a' 't' 'f' 'o' 'r'
11021 set $IPlatfor = $kgm_strcmp_arg
11022 strcmp_arg_pack64 'm' 'E' 'x' 'p' 'e' 'r' 't' 0
11023 set $mExpert = $kgm_strcmp_arg
11024 setfindregistrystr $AppleACP $IPlatfor $mExpert
11025
11026 set $olddepth = $kgm_reg_depth_max
11027 set $kgm_reg_depth_max = 2
11028 _findregistryentry
11029 set $kgm_reg_depth_max = $olddepth
11030
11031 if $kgm_registry_entry
11032 strcmp_arg_pack64 'a' 'c' 'p' 'i' '-' 'm' 'm' 'c'
11033 set $acpi_mmc = $kgm_strcmp_arg
11034 strcmp_arg_pack64 'f' 'g' '-' 's' 'e' 'g' '0' 0
11035 set $fg_seg0 = $kgm_strcmp_arg
11036 setfindregistrystr $acpi_mmc $fg_seg0
11037
11038 _findregistryprop $kgm_registry_entry
11039 if $kgm_registry_value
11040 set $kgm_pci_cfg_base = ((OSNumber *) $kgm_registry_value)->value
11041 set $kgm_pci_cfg_init = 1
11042 end
11043 end
11044 end
11045
6d2010ae 11046 # search for 0:0:0 in likely places if the above fails
b0d623f7
A
11047 if $kgm_pci_cfg_init == 0
11048 set $kgm_pci_cfg_base = 0xF0000000
11049 while $kgm_pci_cfg_init == 0 && $kgm_pci_cfg_base > 0xA0000000
11050 _pci_cfg_addr_value $kgm_pci_cfg_base 8
11051 if $kgm_pci_cfg_value > 0x0 && $kgm_pci_cfg_value < 0xFF
11052 set $kgm_pci_cfg_init = 1
11053 else
11054 set $kgm_pci_cfg_base = $kgm_pci_cfg_base - 0x10000000
11055 end
11056 end
11057 end
11058end
11059
11060# _pci_cfg_addr $bus $dev $fcn $off
11061define _pci_cfg_addr
11062 set $bus = $arg0
11063 set $dev = $arg1
11064 set $fcn = $arg2
11065 set $off = $arg3
11066
11067 _pci_cfg_init
11068 set $kgm_pci_cfg_addr = $kgm_pci_cfg_base | ($bus << 20) | ($dev << 15) | ($fcn << 12) | $off
11069end
11070
11071define _pci_cfg_value
11072 _pci_cfg_addr $arg0 $arg1 $arg2 $arg3
11073 _pci_cfg_addr_value $kgm_pci_cfg_addr $arg4
11074end
11075
11076define pci_cfg_read8
11077 _pci_cfg_value $arg0 $arg1 $arg2 $arg3 8
11078 printf "%08X: %02X\n", $kgm_pci_cfg_addr, $kgm_pci_cfg_value
11079end
11080
11081define pci_cfg_read16
11082 _pci_cfg_value $arg0 $arg1 $arg2 $arg3 16
11083 printf "%08X: %04X\n", $kgm_pci_cfg_addr, $kgm_pci_cfg_value
11084end
11085
11086define pci_cfg_read32
11087 _pci_cfg_value $arg0 $arg1 $arg2 $arg3 32
11088 printf "%08X: %08X\n", $kgm_pci_cfg_addr, $kgm_pci_cfg_value
11089end
11090
11091document pci_cfg_read8
11092Syntax: (gdb) pci_cfg_read8 <bus> <dev> <fcn> <off>
11093| read 8 bits for the given <off> of the pci device located at
11094| <bus>:<dev>:<fcn>.
11095end
11096
11097document pci_cfg_read16
11098Syntax: (gdb) pci_cfg_read <bus> <dev> <fcn> <off>
11099| read 16 bits for the given <off> of the pci device located at
11100| <bus>:<dev>:<fcn>.
11101end
11102
11103document pci_cfg_read32
11104Syntax: (gdb) pci_cfg_read <bus> <dev> <fcn> <off>
11105| read 32 bits for the given <off> of the pci device located at
11106| <bus>:<dev>:<fcn>.
11107end
11108
11109define pci_cfg_write8
11110 _pci_cfg_addr $arg0 $arg1 $arg2 $arg3
11111 writephysint $kgm_pci_cfg_addr 8 $arg4 $kgm_lcpu_self
11112end
11113
11114define pci_cfg_write16
11115 _pci_cfg_addr $arg0 $arg1 $arg2 $arg3
11116 writephysint $kgm_pci_cfg_addr 16 $arg4 $kgm_lcpu_self
11117end
11118
11119define pci_cfg_write32
11120 _pci_cfg_addr $arg0 $arg1 $arg2 $arg3
11121 writephysint $kgm_pci_cfg_addr 32 $arg4 $kgm_lcpu_self
11122end
11123
11124document pci_cfg_write8
11125Syntax: (gdb) pci_cfg_write8 <bus> <dev> <fcn> <off> <value>
11126| write an 8-bit <value> into the given <off> of the pci device located at
11127| <bus>:<dev>:<fcn>.
11128end
11129
11130document pci_cfg_write16
11131Syntax: (gdb) pci_cfg_write16 <bus> <dev> <fcn> <off> <value>
11132| write a 16-bit <value> into the given <off> of the pci device located at
11133| <bus>:<dev>:<fcn>.
11134end
11135
11136document pci_cfg_write32
11137Syntax: (gdb) pci_cfg_write32 <bus> <dev> <fcn> <off> <value>
11138| write a 32-bit <value> into the given <off> of the pci device located at
11139| <bus>:<dev>:<fcn>.
11140end
11141
11142
11143define pci_cfg_dump
11144 set $bus = $arg0
11145 set $dev = $arg1
11146 set $fcn = $arg2
11147 set $off = 0
11148
11149 # check for a valid pci device
11150 _pci_cfg_value $bus $dev $fcn $off 8
11151 if $kgm_pci_cfg_value > 0x0 && $kgm_pci_cfg_value < 0xff
11152 printf " address: 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F\n"
11153 printf "---------------------------------------------------------"
11154
11155 while $off < 256
11156 _pci_cfg_value $bus $dev $fcn $off 32
11157 if ($off & 0xF) == 0
11158 printf "\n%08X: ", $kgm_pci_cfg_addr
11159 end
11160 printf "%02X %02X %02X %02X ", $kgm_pci_cfg_value & 0xFF, ($kgm_pci_cfg_value >> 8) & 0xFF, ($kgm_pci_cfg_value >> 16) & 0xFF, ($kgm_pci_cfg_value >> 24) & 0xFF
11161 set $off = $off + 4
11162 end
11163 printf "\n"
11164
11165 # check for pcie extended capability config space
11166 _pci_cfg_value $bus $dev $fcn $off 8
11167 if $kgm_pci_cfg_value < 0xff
11168 while $off < 4096
11169 _pci_cfg_value $bus $dev $fcn $off 32
11170 if ($off & 0xF) == 0
11171 printf "\n%08X: ", $kgm_pci_cfg_addr
11172 end
11173 printf "%02X %02X %02X %02X ", $kgm_pci_cfg_value & 0xFF, ($kgm_pci_cfg_value >> 8) & 0xFF, ($kgm_pci_cfg_value >> 16) & 0xFF, ($kgm_pci_cfg_value >> 24) & 0xFF
11174 set $off = $off + 4
11175 end
11176 printf "\n"
11177 end
11178 end
11179end
11180
11181document pci_cfg_dump
11182Syntax: (gdb) pci_cfg_dump <bus> <dev> <fcn>
11183| dump config space for the pci device located at <bus>:<dev>:<fcn>
11184| if you specify an invalid/inaccessible pci device, nothing will be
11185| printed out.
11186end
11187
11188set $kgm_pci_cfg_bus_start = 0
11189set $kgm_pci_cfg_bus_max = 8
11190set $kgm_pci_cfg_device_max = 32
11191set $kgm_pci_cfg_function_max = 8
11192define _pci_cfg_scan
11193 set $dump = $arg0
11194
11195 set $bus = $kgm_pci_cfg_bus_start
11196 while $bus < $kgm_pci_cfg_bus_max
11197 # check for bus:0:0 to see if we should
11198 # probe this bus further
11199 _pci_cfg_value $bus 0x0 0x0 0x0 32
11200 if $kgm_pci_cfg_value > 0 && $kgm_pci_cfg_value < 0xFFFFFFFF
11201
11202 set $dev = 0
11203 while $dev < $kgm_pci_cfg_device_max
11204
11205 set $fcn = 0
11206 while $fcn < $kgm_pci_cfg_function_max
11207 _pci_cfg_value $bus $dev $fcn 0x0 32
11208 if $kgm_pci_cfg_value > 0 && $kgm_pci_cfg_value < 0xFFFFFFFF
11209 if $dump == 0
11210 printf "%03X:%03X:%03X: %02X%02X %02X%02X", $bus, $dev, $fcn, ($kgm_pci_cfg_value >> 8) & 0xFF, $kgm_pci_cfg_value & 0xFF, ($kgm_pci_cfg_value >> 24) & 0xFF, ($kgm_pci_cfg_value >> 16) & 0xFF
11211 _pci_cfg_value $bus $dev $fcn 0x8 32
11212 printf " %02X | %02X%02X%02X\n", $kgm_pci_cfg_value & 0xFF, ($kgm_pci_cfg_value >> 24) & 0xFF, ($kgm_pci_cfg_value >> 16) & 0xFF, ($kgm_pci_cfg_value >> 8) & 0xFF
11213 else
11214 printf " device: %03X:%03X:%03X\n", $bus, $dev, $fcn
11215 pci_cfg_dump $bus $dev $fcn
11216 printf "\n"
11217 end
11218 end
11219 set $fcn = $fcn + 1
11220 end
11221 set $dev = $dev + 1
11222 end
11223 end
11224 set $bus = $bus + 1
11225 end
11226end
11227
11228define pci_cfg_dump_all
11229 _pci_cfg_scan 1
11230end
11231
11232document pci_cfg_dump_all
11233Syntax: (gdb) pci_cfg_dump_all
11234| dump config spaces for scanned pci devices. the number of busses to scan
11235| is stored in $kgm_pci_cfg_bus_max. the default for that is 8. you can also
11236| specify the starting bus with $kgm_pci_cfg_bus_start.
11237end
11238
11239define pci_cfg_scan
11240 printf "bus:dev:fcn: vendor device rev | class\n"
11241 printf "---------------------------------------\n"
11242 _pci_cfg_scan 0
11243end
11244
11245document pci_cfg_scan
11246Syntax: (gdb) pci_cfg_scan
11247| scan for pci devices. the number of busses to scan is stored in
11248| $kgm_pci_cfg_bus_max. the default for that is 8. you can also specify the
11249| starting bus with $kgm_pci_cfg_bus_start.
11250end
11251
11252define readioportint
11253 set $kgm_readioportint_result = 0xBAD10AD
11254 # set up the manual KDP packet
11255 set manual_pkt.input = 0
11256 set manual_pkt.len = sizeof(kdp_readioport_req_t)
11257 set $kgm_pkt = (kdp_readioport_req_t *)&manual_pkt.data
11258 set $kgm_pkt->hdr.request = KDP_READIOPORT
11259 set $kgm_pkt->hdr.len = sizeof(kdp_readioport_req_t)
11260 set $kgm_pkt->hdr.is_reply = 0
11261 set $kgm_pkt->hdr.seq = 0
11262 set $kgm_pkt->hdr.key = 0
11263 set $kgm_pkt->address = (uint16_t)$arg0
11264 set $kgm_pkt->nbytes = $arg1 >> 3
11265 set $kgm_pkt->lcpu = (uint16_t)$arg2
11266 set manual_pkt.input = 1
11267 # dummy to make sure manual packet is executed
11268 set $kgm_dummy = &_mh_execute_header
11269 set $kgm_pkt = (kdp_readioport_reply_t *)&manual_pkt.data
11270 if ($kgm_pkt->error == 0)
11271 if $arg1 == 8
11272 set $kgm_readioportint_result = *((uint8_t *) $kgm_pkt->data)
11273 end
11274 if $arg1 == 16
11275 set $kgm_readioportint_result = *((uint16_t *) $kgm_pkt->data)
11276 end
11277 if $arg1 == 32
11278 set $kgm_readioportint_result = *((uint32_t *) $kgm_pkt->data)
11279 end
11280 end
11281end
11282
11283define readioport8
11284 set $lcpu = $kgm_lcpu_self
11285 if $argc > 1
11286 set $lcpu = $arg1
11287 end
11288 readioportint $arg0 8 $lcpu
11289 output /a $arg0
11290 printf ":\t0x%02hhx\n", $kgm_readioportint_result
11291end
11292
11293define readioport16
11294 set $lcpu = $kgm_lcpu_self
11295 if $argc > 1
11296 set $lcpu = $arg1
11297 end
11298 readioportint $arg0 16 $lcpu
11299 output /a $arg0
11300 printf ":\t0x%04hx\n", $kgm_readioportint_result
11301end
11302
11303define readioport32
11304 set $lcpu = $kgm_lcpu_self
11305 if $argc > 1
11306 set $lcpu = $arg1
11307 end
11308 readioportint $arg0 32 $lcpu
11309 output /a $arg0
11310 printf ":\t0x%08x\n", $kgm_readioportint_result
11311end
11312
11313document readioport8
11314| See readioport32.
11315end
11316
11317document readioport16
11318| See readioport32.
11319end
11320
11321document readioport32
11322Syntax: (gdb) readioport32 <port> [lcpu (kernel's numbering convention)]
11323| Read value stored in the specified IO port. The CPU can be optionally
11324| specified as well.
11325end
11326
11327define writeioportint
11328 # set up the manual KDP packet
11329 set manual_pkt.input = 0
11330 set manual_pkt.len = sizeof(kdp_writeioport_req_t)
11331 set $kgm_pkt = (kdp_writeioport_req_t *)&manual_pkt.data
11332 set $kgm_pkt->hdr.request = KDP_WRITEIOPORT
11333 set $kgm_pkt->hdr.len = sizeof(kdp_writeioport_req_t)
11334 set $kgm_pkt->hdr.is_reply = 0
11335 set $kgm_pkt->hdr.seq = 0
11336 set $kgm_pkt->hdr.key = 0
11337 set $kgm_pkt->address = (uint16_t)$arg0
11338 set $kgm_pkt->nbytes = $arg1 >> 3
11339 set $kgm_pkt->lcpu = (uint16_t)$arg3
11340 if $arg1 == 8
11341 set *(uint8_t *)$kgm_pkt->data = (uint8_t)$arg2
11342 end
11343 if $arg1 == 16
11344 set *(uint16_t *)$kgm_pkt->data = (uint16_t)$arg2
11345 end
11346 if $arg1 == 32
11347 set *(uint32_t *)$kgm_pkt->data = (uint32_t)$arg2
11348 end
11349 set manual_pkt.input = 1
11350 # dummy to make sure manual packet is executed
11351 set $kgm_dummy = &_mh_execute_header
11352 set $kgm_pkt = (kdp_writeioport_reply_t *)&manual_pkt.data
11353 set $kgm_writeioportint_result = $kgm_pkt->error
11354end
11355
11356define writeioport8
11357 set $lcpu = $kgm_lcpu_self
11358 if $argc > 2
11359 set $lcpu = $arg2
11360 end
11361 writeioportint $arg0 8 $arg1 $lcpu
11362end
11363
11364define writeioport16
11365 set $lcpu = $kgm_lcpu_self
11366 if $argc > 2
11367 set $lcpu = $arg2
11368 end
11369 writeioportint $arg0 16 $arg1 $lcpu
11370end
11371
11372define writeioport32
11373 set $lcpu = $kgm_lcpu_self
11374 if $argc > 2
11375 set $lcpu = $arg2
11376 end
11377 writeioportint $arg0 32 $arg1 $lcpu
11378end
11379
11380document writeioport8
11381| See writeioport32.
11382end
11383
11384document writeioport16
11385| See writeioport32.
11386end
11387
11388document writeioport32
11389Syntax: (gdb) writeioport32 <port> <value> [lcpu (kernel's numbering convention)]
11390| Write the value to the specified IO port. The size of the value is
11391| determined by the name of the command. The CPU used can be optionally
11392| specified.
11393end
11394
11395define readmsr64int
11396 set $kgm_readmsr64int_result = 0xBAD10AD
11397 # set up the manual KDP packet
11398 set manual_pkt.input = 0
11399 set manual_pkt.len = sizeof(kdp_readmsr64_req_t)
11400 set $kgm_pkt = (kdp_readmsr64_req_t *)&manual_pkt.data
11401 set $kgm_pkt->hdr.request = KDP_READMSR64
11402 set $kgm_pkt->hdr.len = sizeof(kdp_readmsr64_req_t)
11403 set $kgm_pkt->hdr.is_reply = 0
11404 set $kgm_pkt->hdr.seq = 0
11405 set $kgm_pkt->hdr.key = 0
11406 set $kgm_pkt->address = (uint32_t)$arg0
11407 set $kgm_pkt->lcpu = (uint16_t)$arg1
11408 set manual_pkt.input = 1
11409 # dummy to make sure manual packet is executed
11410 set $kgm_dummy = &_mh_execute_header
11411 set $kgm_pkt = (kdp_readmsr64_reply_t *)&manual_pkt.data
11412 if ($kgm_pkt->error == 0)
11413 set $kgm_readmsr64int_result = *((uint64_t *) $kgm_pkt->data)
11414 end
11415end
11416
11417define readmsr64
11418 set $lcpu = $kgm_lcpu_self
11419 if $argc > 1
11420 set $lcpu = $arg1
11421 end
11422 readmsr64int $arg0 $lcpu
11423 output /a $arg0
11424 printf ":\t0x%016llx\n", $kgm_readmsr64int_result
11425end
11426
11427define writemsr64int
11428 # set up the manual KDP packet
11429 set manual_pkt.input = 0
11430 set manual_pkt.len = sizeof(kdp_writemsr64_req_t)
11431 set $kgm_pkt = (kdp_writemsr64_req_t *)&manual_pkt.data
11432 set $kgm_pkt->hdr.request = KDP_WRITEMSR64
11433 set $kgm_pkt->hdr.len = sizeof(kdp_writemsr64_req_t)
11434 set $kgm_pkt->hdr.is_reply = 0
11435 set $kgm_pkt->hdr.seq = 0
11436 set $kgm_pkt->hdr.key = 0
11437 set $kgm_pkt->address = (uint32_t)$arg0
11438 set $kgm_pkt->lcpu = (uint16_t)$arg2
11439 set *(uint64_t *)$kgm_pkt->data = (uint64_t)$arg1
11440 set manual_pkt.input = 1
11441 # dummy to make sure manual packet is executed
11442 set $kgm_dummy = &_mh_execute_header
11443 set $kgm_pkt = (kdp_writemsr64_reply_t *)&manual_pkt.data
11444 set $kgm_writemsr64int_result = $kgm_pkt->error
11445end
11446
11447define writemsr64
11448 set $lcpu = $kgm_lcpu_self
11449 if $argc > 2
11450 set $lcpu = $arg2
11451 end
11452 writemsr64int $arg0 $arg1 $lcpu
11453end
11454
11455document writemsr64
11456Syntax: (gdb) writemsr64 <msr> <value> [lcpu (kernel's numbering convention)]
11457| Write <value> to the specified MSR. The CPU can be optionally specified.
2d21ac55
A
11458end
11459
b0d623f7
A
11460document readmsr64
11461Syntax: (gdb) readmsr64 <msr> [lcpu (kernel's numbering convention)]
11462| Read the specified MSR. The CPU can be optionally specified.
2d21ac55
A
11463end
11464
b0d623f7
A
11465# default if we can't find a registry entry
11466set $kgm_ioapic_addr = 0xFEC00000
11467set $kgm_ioapic_init = 0
2d21ac55 11468
b0d623f7
A
11469set $_ioapic_index_off = 0x00
11470set $_ioapic_data_off = 0x10
11471set $_ioapic_eoi_off = 0x40
11472
11473set $_ioapic_index_id = 0x00
11474set $_ioapic_index_ver = 0x01
11475set $_ioapic_index_redir_base = 0x10
11476
11477set $_apic_vector_mask = 0xFF
060df5ea
A
11478set $_apic_timer_tsc_deadline = 0x40000
11479set $_apic_timer_periodic = 0x20000
b0d623f7
A
11480set $_apic_masked = 0x10000
11481set $_apic_trigger_level = 0x08000
11482set $_apic_polarity_high = 0x02000
11483set $_apic_pending = 0x01000
11484
11485define _ioapic_init
11486 if $kgm_ioapic_init == 0
11487 strcmp_arg_pack64 'i' 'o' '-' 'a' 'p' 'i' 'c' 0
11488 setfindregistrystr $kgm_strcmp_arg
11489
11490 set $olddepth = $kgm_reg_depth_max
11491 set $kgm_reg_depth_max = 3
11492 _findregistryentry
11493 set $kgm_reg_depth_max = $olddepth
11494
11495 if $kgm_registry_entry
11496 strcmp_arg_pack64 'P' 'h' 'y' 's' 'i' 'c' 'a' 'l'
11497 set $Physical = $kgm_strcmp_arg
11498 strcmp_arg_pack64 ' ' 'A' 'd' 'd' 'r' 'e' 's' 's'
11499 set $_Address = $kgm_strcmp_arg
11500 setfindregistrystr $Physical $_Address
11501
11502 _findregistryprop $kgm_registry_entry
11503 if $kgm_registry_value
11504 set $kgm_ioapic_addr = ((OSNumber *) $kgm_registry_value)->value
11505 end
11506 end
11507 set $kgm_ioapic_index_addr = $kgm_ioapic_addr + $_ioapic_index_off
11508 set $kgm_ioapic_data_addr = $kgm_ioapic_addr + $_ioapic_data_off
11509 set $kgm_ioapic_init = 1
11510 end
2d21ac55
A
11511end
11512
b0d623f7
A
11513define _ioapic_addr_value
11514 _ioapic_init
11515 writephysint $kgm_ioapic_index_addr 8 $arg0 $kgm_lcpu_self
11516 if $argc > 1
11517 writephysint $kgm_ioapic_data_addr 32 $arg1 $kgm_lcpu_self
11518 else
11519 readphysint $kgm_ioapic_data_addr 32 $kgm_lcpu_self
11520 set $kgm_ioapic_value = $kgm_readphysint_result
11521 end
2d21ac55
A
11522end
11523
b0d623f7
A
11524define _apic_print
11525 set $value = $arg0
2d21ac55 11526
060df5ea 11527 printf "[VEC=%3d", $value & $_apic_vector_mask
b0d623f7 11528 if $value & $_apic_masked
060df5ea 11529 printf " MASK=yes"
b0d623f7 11530 else
060df5ea 11531 printf " MASK=no "
b0d623f7 11532 end
2d21ac55 11533
b0d623f7 11534 if $value & $_apic_trigger_level
060df5ea 11535 printf " TRIG=level"
b0d623f7 11536 else
060df5ea 11537 printf " TRIG=edge "
b0d623f7 11538 end
2d21ac55 11539
b0d623f7 11540 if $value & $_apic_polarity_high
060df5ea 11541 printf " POL=high"
b0d623f7 11542 else
060df5ea 11543 printf " POL=low "
b0d623f7 11544 end
2d21ac55 11545
b0d623f7 11546 if $value & $_apic_pending
060df5ea 11547 printf " PEND=yes"
b0d623f7 11548 else
060df5ea 11549 printf " PEND=no "
b0d623f7 11550 end
060df5ea
A
11551
11552 if $value & $_apic_timer_periodic
11553 printf " PERIODIC"
11554 end
11555 if $value & $_apic_timer_tsc_deadline
11556 printf " TSC_DEADLINE"
11557 end
11558
11559 printf "]\n"
b0d623f7 11560end
2d21ac55 11561
b0d623f7
A
11562define ioapic_read32
11563 if (($kgm_mtype & $kgm_mtype_x86_mask) != $kgm_mtype_x86_any)
11564 printf "ioapic_read32 not supported on this architecture.\n"
11565 else
11566 _ioapic_addr_value $arg0
11567 printf "IOAPIC[0x%02X]: 0x%08X\n", $arg0, $kgm_ioapic_value
11568 end
11569end
2d21ac55 11570
b0d623f7
A
11571document ioapic_read32
11572Syntax: (gdb) ioapic_read <offset>
11573| Read the IOAPIC register at the offset specified.
11574end
2d21ac55 11575
b0d623f7
A
11576define ioapic_write32
11577 if (($kgm_mtype & $kgm_mtype_x86_mask) != $kgm_mtype_x86_any)
11578 printf "ioapic_write32 not supported on this architecture.\n"
11579 else
11580 _ioapic_addr_value $arg0 $arg1
11581 end
11582end
2d21ac55 11583
b0d623f7
A
11584document ioapic_write32
11585Syntax: (gdb) ioapic_write32 <offset> <value>
11586| Write the IOAPIC register at the offset specified.
11587end
2d21ac55 11588
b0d623f7
A
11589define ioapic_dump
11590 if (($kgm_mtype & $kgm_mtype_x86_mask) != $kgm_mtype_x86_any)
11591 printf "ioapic_dump not supported on this architecture.\n"
11592 else
11593 # id
11594 _ioapic_addr_value $_ioapic_index_id
11595 printf "IOAPIC[0x%02X] ID: 0x%08X\n", $_ioapic_index_id, $kgm_ioapic_value
2d21ac55 11596
b0d623f7
A
11597 # version
11598 _ioapic_addr_value $_ioapic_index_ver
11599 set $maxredir = (($kgm_ioapic_value & 0xFF0000) >> 16) + 1
2d21ac55 11600
b0d623f7
A
11601 printf "IOAPIC[0x%02X] VERSION: 0x%08X [", $_ioapic_index_ver, $kgm_ioapic_value
11602 printf "MAXREDIR=%02d PRQ=%d VERSION=0x%02X]\n", $maxredir, ($kgm_ioapic_value >> 15) & 0x1, $kgm_ioapic_value & 0xFF
11603
11604 # all the redir entries
11605 set $i = 0
11606 while $i < $maxredir
11607 set $addr0 = $_ioapic_index_redir_base + ($i << 1)
11608 set $addr1 = $addr0 + 1
11609 _ioapic_addr_value $addr1
11610 printf "IOAPIC[0x%02X] IOREDIR%02d: 0x%08X", $addr0, $i, $kgm_ioapic_value
11611
11612 _ioapic_addr_value $addr0
11613 printf "%08X ", $kgm_ioapic_value
11614 _apic_print $kgm_ioapic_value
11615 set $i = $i + 1
11616 end
11617 end
11618end
2d21ac55 11619
b0d623f7
A
11620document ioapic_dump
11621Syntax: (gdb) ioapic_dump
11622| Dump all the IOAPIC entries.
11623end
11624
11625
11626set $_lapic_base_addr = 0xFEE00000
11627set $_lapic_id = 0x20
11628set $_lapic_version = 0x30
11629set $_lapic_tpr = 0x80
11630set $_lapic_apr = 0x90
11631set $_lapic_ppr = 0xA0
11632set $_lapic_eoi = 0xB0
11633set $_lapic_ldr = 0xD0
11634set $_lapic_dfr = 0xE0
11635set $_lapic_sivr = 0xF0
11636
11637set $_lapic_isr_size = 0x10
11638set $_lapic_isr_num = 8
11639set $_lapic_isr0 = 0x100
11640set $_lapic_tmr0 = 0x180
11641set $_lapic_irr0 = 0x200
11642
11643set $_lapic_esr = 0x280
11644set $_lapic_esr_register = 0x80
11645set $_lapic_esr_recv_vect = 0x40
11646set $_lapic_esr_send_vect = 0x20
11647
11648set $_lapic_icr0 = 0x300
11649set $_lapic_icr1 = 0x310
11650
11651set $_lapic_lvt_timer = 0x320
11652set $_lapic_lvt_thermal = 0x330
11653set $_lapic_lvt_pmcr = 0x340
11654set $_lapic_lvt_lint0 = 0x350
11655set $_lapic_lvt_lint1 = 0x360
11656set $_lapic_lvt_error = 0x370
11657
11658set $_lapic_icr = 0x380
11659set $_lapic_ccr = 0x390
11660set $_lapic_dcr = 0x3E0
11661
11662set $_apic_cfg_msr = 0x1B
11663set $_apic_cfg_msr_x2EN = 0x00000C00
11664set $_x2apic_enabled = -1
11665
11666# _lapic_addr $offset returns the actual address to use
11667define _lapic_addr
11668 if $_x2apic_enabled < 0
11669 readmsr64int $_apic_cfg_msr $kgm_lcpu_self
11670 if ($kgm_readmsr64int_result & $_apic_cfg_msr_x2EN) == $_apic_cfg_msr_x2EN
11671 set $_x2apic_enabled = 1
11672 else
11673 set $_x2apic_enabled = 0
11674 end
11675 end
11676
11677 if $_x2apic_enabled
11678 # x2APIC addresses are MSRs that use xAPIC offsets that
11679 # are 4-bit shifted
11680 set $kgm_lapic_addr = $arg0 >> 4
11681 else
11682 set $kgm_lapic_addr = $_lapic_base_addr + $arg0
11683 end
2d21ac55
A
11684end
11685
b0d623f7
A
11686# _lapic_addr_value $offset $lcpu
11687define _lapic_addr_value
11688 _lapic_addr $arg0
11689 if $_x2apic_enabled
11690 readmsr64int $kgm_lapic_addr $arg1
11691 set $kgm_lapic_value = $kgm_readmsr64int_result
11692 else
11693 readphysint $kgm_lapic_addr 32 $arg1
11694 set $kgm_lapic_value = $kgm_readphysint_result
11695 end
2d21ac55
A
11696end
11697
b0d623f7
A
11698# lapic_read32 $offset [$lcpu]
11699define lapic_read32
11700 if (($kgm_mtype & $kgm_mtype_x86_mask) != $kgm_mtype_x86_any)
11701 printf "lapic_read32 not supported on this architecture.\n"
11702 else
11703 set $lcpu = $kgm_lcpu_self
11704 if $argc > 1
11705 set $lcpu = $arg1
11706 end
11707 _lapic_addr_value $arg0 $lcpu
11708 printf "LAPIC[0x%03X]: 0x%08X\n", $arg0, $kgm_lapic_value
11709 end
2d21ac55
A
11710end
11711
b0d623f7
A
11712document lapic_read32
11713Syntax: (gdb) apic_read32_cpu <offset> [lcpu (kernel's numbering convention)]
11714| Read the LAPIC register at the offset specified. The CPU can be optionally
11715| specified.
2d21ac55
A
11716end
11717
b0d623f7
A
11718# lapic_write32 $offset $value [$lcpu]
11719define lapic_write32
11720 if (($kgm_mtype & $kgm_mtype_x86_mask) != $kgm_mtype_x86_any)
11721 printf "lapic_write32_cpu not supported on this architecture.\n"
11722 else
11723 set $lcpu = $kgm_lcpu_self
11724 if $argc > 2
11725 set $lcpu = $arg2
11726 end
11727
11728 _lapic_addr $arg0
11729 if $_x2apic_enabled
11730 writemsr64int $kgm_lapic_addr $arg1 $lcpu
11731 else
11732 writephysint $kgm_lapic_addr 32 $arg1 $lcpu
11733 end
11734 end
11735end
11736
11737document lapic_write32
11738Syntax: (gdb) lapic_write32 <offset> <value> [lcpu (kernel's numbering convention)]
11739| Write the LAPIC register at the offset specified. The CPU can be optionally
11740| specified.
2d21ac55
A
11741end
11742
b0d623f7
A
11743# lapic_dump [lcpu]
11744define lapic_dump
11745 if (($kgm_mtype & $kgm_mtype_x86_mask) != $kgm_mtype_x86_any)
11746 printf "lapic_dump not supported on this architecture.\n"
11747 else
11748 set $lcpu = $kgm_lcpu_self
11749 if $argc > 0
11750 set $lcpu = $arg0
11751 end
11752
11753 _lapic_addr_value $_lapic_id $lcpu
11754
11755 # the above also figures out if we're using an xAPIC or an x2APIC
11756 printf "LAPIC operating mode: "
11757 if $_x2apic_enabled
11758 printf " x2APIC\n"
11759 else
11760 printf " xAPIC\n"
11761 end
11762
11763 printf "LAPIC[0x%03X] ID: 0x%08X\n", $_lapic_id, $kgm_lapic_value
11764
11765 _lapic_addr_value $_lapic_version $lcpu
11766 set $lvt_num = ($kgm_lapic_value >> 16) + 1
11767 printf "LAPIC[0x%03X] VERSION: 0x%08X [VERSION=%d MaxLVT=%d]\n", $_lapic_version, $kgm_lapic_value, $kgm_lapic_value & 0xFF, $lvt_num
11768
11769 _lapic_addr_value $_lapic_tpr $lcpu
11770 printf "LAPIC[0x%03X] TASK PRIORITY: 0x%08X\n", $_lapic_tpr, $kgm_lapic_value
11771
11772 _lapic_addr_value $_lapic_ppr $lcpu
11773 printf "LAPIC[0x%03X] PROCESSOR PRIORITY: 0x%08X\n", $_lapic_ppr, $kgm_lapic_value
11774
11775 _lapic_addr_value $_lapic_ldr $lcpu
11776 printf "LAPIC[0x%03X] LOGICAL DEST: 0x%08X\n", $_lapic_ldr, $kgm_lapic_value
11777
11778 _lapic_addr_value $_lapic_dfr $lcpu
11779 printf "LAPIC[0x%03X] DEST FORMAT: 0x%08X\n", $_lapic_dfr, $kgm_lapic_value
11780
11781 _lapic_addr_value $_lapic_sivr $lcpu
11782 printf "LAPIC[0x%03X] SPURIOUS VECTOR: 0x%08X [VEC=%3d ENABLED=%d]\n", $_lapic_sivr, $kgm_lapic_value, $kgm_lapic_value & $_apic_vector_mask, ($kgm_lapic_value & 0x100) >> 8,
11783
11784 set $i = 0
11785 while $i < $_lapic_isr_num
11786 set $addr = $_lapic_isr0 + $i * $_lapic_isr_size
11787 _lapic_addr_value $addr $lcpu
11788 printf "LAPIC[0x%03X] ISR[%03d:%03d]: 0x%08X\n", $addr, 32*($i + 1) - 1, 32*$i, $kgm_lapic_value
11789 set $i = $i + 1
11790 end
11791
11792 set $i = 0
11793 while $i < $_lapic_isr_num
11794 set $addr = $_lapic_tmr0 + $i * $_lapic_isr_size
11795 _lapic_addr_value $addr $lcpu
11796 printf "LAPIC[0x%03X] TMR[%03d:%03d]: 0x%08X\n", $addr, 32*($i + 1) - 1, 32*$i, $kgm_lapic_value
11797 set $i = $i + 1
11798 end
2d21ac55 11799
b0d623f7
A
11800 set $i = 0
11801 while $i < $_lapic_isr_num
11802 set $addr = $_lapic_irr0 + $i * $_lapic_isr_size
11803 _lapic_addr_value $addr $lcpu
11804 printf "LAPIC[0x%03X] IRR[%03d:%03d]: 0x%08X\n", $addr, 32*($i + 1) - 1, 32*$i, $kgm_lapic_value
11805 set $i = $i + 1
11806 end
2d21ac55 11807
b0d623f7
A
11808 _lapic_addr_value $_lapic_esr $lcpu
11809 printf "LAPIC[0x%03X] ERROR STATUS: 0x%08X ", $_lapic_esr, $kgm_lapic_value
11810 if $kgm_lapic_value
11811 printf "["
11812 end
11813 if $kgm_lapic_value & $_lapic_esr_register
11814 printf "Register "
11815 end
11816 if $kgm_lapic_value & $_lapic_esr_recv_vect
11817 printf "Received Vector "
11818 end
11819 if $kgm_lapic_value & $_lapic_esr_send_vect
11820 printf "Send Vector"
11821 end
11822 if $kgm_lapic_value
11823 printf "]"
11824 end
11825 printf "\n"
11826
11827 _lapic_addr_value $_lapic_icr1 $lcpu
11828 printf "LAPIC[0x%03X] Interrupt Command: 0x%08X [DEST=%d]\n", $_lapic_icr0, $kgm_lapic_value, $kgm_lapic_value >> 24
11829 _lapic_addr_value $_lapic_icr0 $lcpu
11830 printf " 0x%08X ", $kgm_lapic_value
11831 _apic_print $kgm_lapic_value
11832
11833 if $lvt_num > 0
11834 _lapic_addr_value $_lapic_lvt_timer $lcpu
11835 printf "LAPIC[0x%03X] LVT Timer: 0x%08X ", $_lapic_lvt_timer, $kgm_lapic_value
11836 _apic_print $kgm_lapic_value
11837 end
2d21ac55 11838
b0d623f7
A
11839 if $lvt_num > 1
11840 _lapic_addr_value $_lapic_lvt_lint0 $lcpu
11841 printf "LAPIC[0x%03X] LVT LINT0: 0x%08X ", $_lapic_lvt_lint0, $kgm_lapic_value
11842 _apic_print $kgm_lapic_value
11843 end
2d21ac55 11844
b0d623f7
A
11845 if $lvt_num > 2
11846 _lapic_addr_value $_lapic_lvt_lint1 $lcpu
11847 printf "LAPIC[0x%03X] LVT LINT1: 0x%08X ", $_lapic_lvt_lint1, $kgm_lapic_value
11848 _apic_print $kgm_lapic_value
11849 end
11850
11851 if $lvt_num > 3
11852 _lapic_addr_value $_lapic_lvt_error $lcpu
11853 printf "LAPIC[0x%03X] LVT Error: 0x%08X ", $_lapic_lvt_error, $kgm_lapic_value
11854 _apic_print $kgm_lapic_value
11855 end
11856
11857 if $lvt_num > 4
11858 _lapic_addr_value $_lapic_lvt_pmcr $lcpu
11859 printf "LAPIC[0x%03X] LVT PerfMon: 0x%08X ", $_lapic_lvt_pmcr, $kgm_lapic_value
11860 _apic_print $kgm_lapic_value
11861 end
11862
11863 if $lvt_num > 5
11864 _lapic_addr_value $_lapic_lvt_thermal $lcpu
11865 printf "LAPIC[0x%03X] LVT Thermal: 0x%08X ", $_lapic_lvt_thermal, $kgm_lapic_value
11866 _apic_print $kgm_lapic_value
11867 end
11868
11869 _lapic_addr_value $_lapic_dcr $lcpu
11870 printf "LAPIC[0x%03X] Timer Divide: 0x%08X [Divide by ", $_lapic_dcr, $kgm_lapic_value
11871 set $kgm_lapic_value = ($kgm_lapic_value & 0x8) >> 1 | $kgm_lapic_value & 0x3
11872 if $kgm_lapic_value == 0x7
11873 printf "1]\n"
11874 else
11875 printf "%d]\n", 2 << $kgm_lapic_value
11876 end
11877
11878 _lapic_addr_value $_lapic_icr $lcpu
11879 printf "LAPIC[0x%03X] Timer Init Count: 0x%08X\n", $_lapic_icr, $kgm_lapic_value
11880
11881 _lapic_addr_value $_lapic_ccr $lcpu
11882 printf "LAPIC[0x%03X] Timer Cur Count: 0x%08X\n", $_lapic_ccr, $kgm_lapic_value
11883 end
2d21ac55
A
11884end
11885
b0d623f7
A
11886document lapic_dump
11887Syntax: (gdb) lapic_dump [lcpu (kernel's numbering convention)]
11888| Dump all the LAPIC entries. The CPU can be optionally specified.
11889end
11890
11891define showknoteheader
11892 printf " knote filter ident kn_ptr status\n"
2d21ac55 11893end
4a3eedf9 11894
b0d623f7
A
11895define showknoteint
11896 set $kgm_knotep = ((struct knote *) $arg0)
11897 printf " "
11898 showptr $kgm_knotep
11899 printf " "
11900 set $kgm_filt = -$kgm_knotep->kn_kevent.filter
11901 if ($kgm_filt == 1)
11902 printf "EVFILT_READ "
4a3eedf9 11903 end
b0d623f7
A
11904 if ($kgm_filt == 2)
11905 printf "EVFILT_WRITE "
4a3eedf9 11906 end
b0d623f7
A
11907 if ($kgm_filt == 3)
11908 printf "EVFILT_AIO "
4a3eedf9 11909 end
b0d623f7
A
11910 if ($kgm_filt == 4)
11911 printf "EVFILT_VNODE "
4a3eedf9 11912 end
b0d623f7
A
11913 if ($kgm_filt == 5)
11914 printf "EVFILT_PROC "
4a3eedf9 11915 end
b0d623f7
A
11916 if ($kgm_filt == 6)
11917 printf "EVFILT_SIGNAL "
4a3eedf9 11918 end
b0d623f7
A
11919 if ($kgm_filt == 7)
11920 printf "EVFILT_TIMER "
4a3eedf9 11921 end
b0d623f7
A
11922 if ($kgm_filt == 8)
11923 printf "EVFILT_MACHPORT"
4a3eedf9 11924 end
b0d623f7
A
11925 if ($kgm_filt == 9)
11926 printf "EVFILT_FS "
11927 end
11928 if ($kgm_filt == 10)
11929 printf "EVFILT_USER "
11930 end
11931 if ($kgm_filt == 11)
11932 printf "EVFILT_SESSION "
11933 end
11934 printf "%7d ", $kgm_knotep->kn_kevent.ident
11935 showptr $kgm_knotep->kn_ptr.p_fp
11936 printf " "
11937 if ($kgm_knotep->kn_status == 0)
11938 printf "-"
4a3eedf9 11939 else
b0d623f7
A
11940 if ($kgm_knotep->kn_status & 0x01)
11941 printf "A"
11942 end
11943 if ($kgm_knotep->kn_status & 0x02)
11944 printf "Q"
11945 end
11946 if ($kgm_knotep->kn_status & 0x04)
11947 printf "Dis"
11948 end
11949 if ($kgm_knotep->kn_status & 0x08)
11950 printf "Dr"
11951 end
11952 if ($kgm_knotep->kn_status & 0x10)
11953 printf "Uw"
11954 end
11955 if ($kgm_knotep->kn_status & 0x20)
11956 printf "Att"
11957 end
11958 if ($kgm_knotep->kn_status & 0x40)
11959 printf "Stq"
11960 end
4a3eedf9 11961 end
b0d623f7 11962 printf "\n"
4a3eedf9
A
11963end
11964
b0d623f7
A
11965define showprocknotes
11966 showknoteheader
11967 set $kgm_fdp = ((proc_t)$arg0)->p_fd
11968 set $kgm_knlist = $kgm_fdp->fd_knlist
11969 set $i = 0
11970 while (($i < $kgm_fdp->fd_knlistsize) && ($kgm_knlist != 0))
11971 set $kgm_kn = ((struct knote *)$kgm_knlist[$i].slh_first)
11972 while ($kgm_kn != 0)
11973 showknoteint $kgm_kn
11974 set $kgm_kn = ((struct knote *)$kgm_kn->kn_link.sle_next)
c910b4d9 11975 end
b0d623f7
A
11976 set $i = $i + 1
11977 end
11978 set $kgm_knhash = $kgm_fdp->fd_knhash
11979 set $i = 0
11980 while (($i < $kgm_fdp->fd_knhashmask + 1) && ($kgm_knhash != 0))
11981 set $kgm_kn = ((struct knote *)$kgm_knhash[$i].slh_first)
11982 while ($kgm_kn != 0)
11983 showknoteint $kgm_kn
11984 set $kgm_kn = ((struct knote *)$kgm_kn->kn_link.sle_next)
11985 end
11986 set $i = $i + 1
11987 end
11988end
c910b4d9 11989
b0d623f7
A
11990define showallknotes
11991 set $kgm_head_taskp = &tasks
11992 set $kgm_taskp = (struct task *)($kgm_head_taskp->next)
11993 while $kgm_taskp != $kgm_head_taskp
11994 showtaskheader
11995 showtaskint $kgm_taskp
11996 showprocknotes $kgm_taskp->bsd_info
11997 set $kgm_taskp = (struct task *)($kgm_taskp->tasks.next)
11998 end
11999end
12000document showprocknotes
12001Syntax: showprocknotes <proc>
12002| Displays filter and status information for every kevent registered for
12003| the process.
12004end
c910b4d9 12005
b0d623f7
A
12006#
12007# Device node related debug macros
12008#
c910b4d9 12009
b0d623f7
A
12010define _showtty
12011 set $kgm_tty = (struct tty *) $arg0
12012 printf "tty struct at "
12013 showptr $kgm_tty
12014 printf "\n"
12015 printf "-last input to raw queue:\n"
12016 p $kgm_tty->t_rawq->c_cs
12017 printf "-last input to canonical queue:\n"
12018 p $kgm_tty->t_canq->c_cs
12019 printf "-last output data:\n"
12020 p $kgm_tty->t_outq->c_cs
12021 printf "state:\n"
12022 if ($kgm_tty->t_state & 0x00000001)
12023 printf " TS_SO_OLOWAT (Wake up when output <= low water)\n"
12024 end
12025 if ($kgm_tty->t_state & 0x00000002)
12026 printf " TS_ASYNC (async I/O mode)\n"
12027 else
12028 printf " - (synchronous I/O mode)\n"
12029 end
12030 if ($kgm_tty->t_state & 0x00000004)
12031 printf " TS_BUSY (Draining output)\n"
12032 end
12033 if ($kgm_tty->t_state & 0x00000008)
12034 printf " TS_CARR_ON (Carrier is present)\n"
12035 else
12036 printf " - (Carrier is NOT present)\n"
12037 end
12038 if ($kgm_tty->t_state & 0x00000010)
12039 printf " TS_FLUSH (Outq has been flushed during DMA)\n"
12040 end
12041 if ($kgm_tty->t_state & 0x00000020)
12042 printf " TS_ISOPEN (Open has completed)\n"
12043 else
12044 printf " - (Open has NOT completed)\n"
12045 end
12046 if ($kgm_tty->t_state & 0x00000040)
12047 printf " TS_TBLOCK (Further input blocked)\n"
12048 end
12049 if ($kgm_tty->t_state & 0x00000080)
12050 printf " TS_TIMEOUT (Wait for output char processing)\n"
12051 end
12052 if ($kgm_tty->t_state & 0x00000100)
12053 printf " TS_TTSTOP (Output paused)\n"
12054 end
12055 if ($kgm_tty->t_state & 0x00000200)
12056 printf " TS_WOPEN (Open in progress)\n"
12057 end
12058 if ($kgm_tty->t_state & 0x00000400)
12059 printf " TS_XCLUDE (Tty requires exclusivity)\n"
12060 end
12061 if ($kgm_tty->t_state & 0x00000800)
12062 printf " TS_BKSL (State for lowercase \\ work)\n"
12063 end
12064 if ($kgm_tty->t_state & 0x00001000)
12065 printf " TS_CNTTB (Counting tab width, ignore FLUSHO)\n"
12066 end
12067 if ($kgm_tty->t_state & 0x00002000)
12068 printf " TS_ERASE (Within a \\.../ for PRTRUB)\n"
12069 end
12070 if ($kgm_tty->t_state & 0x00004000)
12071 printf " TS_LNCH (Next character is literal)\n"
12072 end
12073 if ($kgm_tty->t_state & 0x00008000)
12074 printf " TS_TYPEN (Retyping suspended input (PENDIN))\n"
12075 end
12076 if ($kgm_tty->t_state & 0x00010000)
12077 printf " TS_CAN_BYPASS_L_RINT (Device in "raw" mode)\n"
12078 end
12079 if ($kgm_tty->t_state & 0x00020000)
12080 printf " TS_CONNECTED (Connection open)\n"
12081 else
12082 printf " - (Connection NOT open)\n"
12083 end
12084 if ($kgm_tty->t_state & 0x00040000)
12085 printf " TS_SNOOP (Device is being snooped on)\n"
12086 end
12087 if ($kgm_tty->t_state & 0x80000)
12088 printf " TS_SO_OCOMPLETE (Wake up when output completes)\n"
12089 end
12090 if ($kgm_tty->t_state & 0x00100000)
12091 printf " TS_ZOMBIE (Connection lost)\n"
12092 end
12093 if ($kgm_tty->t_state & 0x00200000)
12094 printf " TS_CAR_OFLOW (For MDMBUF - handle in driver)\n"
12095 end
12096 if ($kgm_tty->t_state & 0x00400000)
12097 printf " TS_CTS_OFLOW (For CCTS_OFLOW - handle in driver)\n"
12098 end
12099 if ($kgm_tty->t_state & 0x00800000)
12100 printf " TS_DSR_OFLOW (For CDSR_OFLOW - handle in driver)\n"
12101 end
12102 # xxx todo: do we care about decoding flags?
12103 printf "flags: 0x%08x\n", $kgm_tty->t_flags
12104 printf "foreground process group: "
12105 showptr $kgm_tty->t_pgrp
12106 printf "\n"
12107 printf "enclosing session: "
12108 showptr $kgm_tty->t_session
12109 printf "\n"
12110 printf "Termios:\n"
12111 # XXX todo: decode these flags, someday
12112 printf " Input flags: 0x%08x\n", $kgm_tty->t_termios.c_iflag
12113 printf " Output flags: 0x%08x\n", $kgm_tty->t_termios.c_oflag
12114 printf " Control flags: 0x%08x\n", $kgm_tty->t_termios.c_cflag
12115 printf " Local flags: 0x%08x\n", $kgm_tty->t_termios.c_lflag
12116 printf " Input speed: %d\n", $kgm_tty->t_termios.c_ispeed
12117 printf " Output speed: %d\n", $kgm_tty->t_termios.c_ospeed
12118 # XXX todo: useful to decode t_winsize? t_iokit? c_cc? anything else?
12119 printf "high watermark: %d bytes\n", $kgm_tty->t_hiwat
12120 printf "low watermark: %d bytes\n", $kgm_tty->t_lowat
12121end
12122
12123define _showwhohas
12124 # _showwhohas <major> <minor>
12125 printf "fd "
12126 printf "fileglob "
12127showptrhdrpad
12128 printf "vnode "
12129showptrhdrpad
12130 printf "process "
12131showptrhdrpad
12132 printf "name\n"
12133
12134 set $kgm_swh_devnode_dev = (((int) $arg0) << 24) | (int) $arg1
12135 # iterate all tasks to iterate all processes to iterate all
12136 # open files in each process to see who has a given major/minor
12137 # device open
12138 set $kgm_taskp = (struct task *)($kgm_head_taskp->next)
12139 while $kgm_taskp != $kgm_head_taskp
12140 set $kgm_procp = (proc_t) $kgm_taskp->bsd_info
12141 set $kgm_spf_filedesc = $kgm_procp->p_fd
12142 set $kgm_spf_last = $kgm_spf_filedesc->fd_lastfile
12143 set $kgm_spf_ofiles = $kgm_spf_filedesc->fd_ofiles
12144 set $kgm_spf_count = 0
12145 while (($kgm_spf_ofiles != 0) && ($kgm_spf_count <= $kgm_spf_last))
12146 # only files currently open
12147 if ($kgm_spf_ofiles[$kgm_spf_count] != 0)
12148 set $kgm_spf_fg = $kgm_spf_ofiles[$kgm_spf_count].f_fglob
12149 if ($kgm_spf_fg->fg_type == 1)
12150 # display fd #, fileglob & vnode address, proc name
12151 set $kgm_swh_m_vnode = (vnode_t) $kgm_spf_fg->fg_data
12152 set $kgm_swh_m_vtype = (enum vtype) $kgm_swh_m_vnode->v_type
12153 if (($kgm_swh_m_vtype == VBLK) || ($kgm_swh_m_vtype == VCHR)) && ((((devnode_t *)$kgm_swh_m_vnode->v_data)->dn_typeinfo.dev) == $kgm_swh_devnode_dev)
12154 printf "%-5d ", $kgm_spf_count
12155 showptr $kgm_spf_fg
12156 printf " "
12157 showptr $kgm_swh_m_vnode
12158 printf " "
12159 showptr $kgm_procp
12160 printf " %s\n", $kgm_procp->p_comm
12161 end
c910b4d9 12162 end
b0d623f7
A
12163 end
12164 set $kgm_spf_count = $kgm_spf_count + 1
c910b4d9
A
12165 end
12166
b0d623f7 12167 set $kgm_taskp = (struct task *)($kgm_taskp->tasks.next)
c910b4d9
A
12168 end
12169end
12170
b0d623f7
A
12171define _showvnodedev_cpty
12172 set $kgm_ptmx_major = (int) $arg0
12173 set $kgm_ptmx_minor = (int) $arg1
12174 set $kgm_ptmx_ioctl = _state.pis_ioctl_list[$kgm_ptmx_minor]
12175 set $kgm_ptmx_ioctl = _state.pis_ioctl_list[$kgm_ptmx_minor]
12176 printf " ptmx_ioctl struct at "
12177 showptr $kgm_ptmx_ioctl
12178 printf "\n"
12179 printf " flags:\n"
12180 if ($kgm_ptmx_ioctl->pt_flags & 0x0008)
12181 printf " PF_PKT (packet mode)\n"
12182 end
12183 if ($kgm_ptmx_ioctl->pt_flags & 0x0010)
12184 printf " PF_STOPPED (user told stopped)\n"
12185 end
12186 if ($kgm_ptmx_ioctl->pt_flags & 0x0020)
12187 printf " PF_REMOTE (remote and flow controlled input)\n"
12188 end
12189 if ($kgm_ptmx_ioctl->pt_flags & 0x0040)
12190 printf " PF_NOSTOP"
12191 end
12192 if ($kgm_ptmx_ioctl->pt_flags & 0x0080)
12193 printf " PF_UCNTL (user control mode)\n"
12194 end
12195 if ($kgm_ptmx_ioctl->pt_flags & 0x0100)
12196 printf " PF_UNLOCKED (slave unlock - master open resets)\n"
12197 end
12198 if ($kgm_ptmx_ioctl->pt_flags & 0x0200)
12199 printf " PF_OPEN_M (master is open)\n"
12200 # XXX we should search for who has the master open, but
12201 # XXX each master gets the same minor, even though it
12202 # XXX gets a different vnode. we chold probably change
12203 # XXX this, but to do it we would need some way of
12204 # XXX expressing the information in the vnode structure
12205 # XXX somewhere. If we *did* change it, it would buy us
12206 # XXX the ability to determine who has the corresponding
12207 # XXX master end of the pty open
12208 else
12209 printf " PF_OPEN_M (master is closed)\n"
12210 end
12211 if ($kgm_ptmx_ioctl->pt_flags & 0x0400)
12212 printf " PF_OPEN_S (slave is open)\n"
12213 printf "---vvvvv--- fds open on this device ---vvvvv---\n"
12214 _showwhohas ($kgm_ptmx_major) ($kgm_ptmx_minor)
12215 printf "---^^^^^--- fds open on this device ---^^^^^---\n"
12216 else
12217 printf " - (slave is closed)\n"
12218 end
12219 printf "TTY Specific Information\n"
12220 _showtty $kgm_ptmx_ioctl->pt_tty
c910b4d9
A
12221end
12222
b0d623f7
A
12223define showvnodedev
12224 if ($argc == 1)
12225 set $kgm_vnode = (vnode_t) $arg0
12226 set $kgm_vtype = (enum vtype) $kgm_vnode->v_type
12227 if (($kgm_vtype == VBLK) || ($kgm_vtype == VCHR))
12228 set $kgm_devnode = (devnode_t *) $kgm_vnode->v_data
12229 set $kgm_devnode_dev = $kgm_devnode->dn_typeinfo.dev
12230 set $kgm_devnode_major = ($kgm_devnode_dev >> 24) & 0xff
12231 set $kgm_devnode_minor = $kgm_devnode_dev & 0x00ffffff
12232
12233 # boilerplate device information for a vnode
12234 printf "Device Info:\n"
12235 printf " vnode: "
12236 showptr $kgm_vnode
12237 printf "\n"
12238 printf " type: "
12239 if ($kgm_vtype == VBLK)
12240 printf "VBLK "
12241 end
12242 if ($kgm_vtype == VCHR)
12243 printf "VCHR"
12244 end
12245 printf "\n"
12246 printf " name: %s\n", $kgm_vnode->v_name
12247 printf " major, minor: %d, %d\n", $kgm_devnode_major, $kgm_devnode_minor
12248 printf " mode 0%o\n", $kgm_devnode->dn_mode
12249 printf " owner (u,g): %d %d", $kgm_devnode->dn_uid, $kgm_devnode->dn_gid
12250 printf "\n"
c910b4d9 12251
b0d623f7
A
12252 # decode device specific data
12253 printf "Device Specific Information: "
12254 if ($kgm_vtype == VBLK)
12255 printf " Sorry, I do not know how to decode block devices yet!\n"
12256 printf " Maybe you can write me!"
12257 end
12258 if ($kgm_vtype == VCHR)
12259 # Device information; this is scanty
12260 # range check
12261 if ($kgm_devnode_major > 42) || ($kgm_devnode_major < 0)
12262 printf "Invalid major #\n"
12263 else
12264 # static assignments in conf
12265 if ($kgm_devnode_major == 0)
12266 printf "Console mux device\n"
12267 else
12268 if ($kgm_devnode_major == 2)
12269 printf "Current tty alias\n"
12270 else
12271 if ($kgm_devnode_major == 3)
12272 printf "NULL device\n"
12273 else
12274 if ($kgm_devnode_major == 4)
12275 printf "Old pty slave\n"
12276 else
12277 if ($kgm_devnode_major == 5)
12278 printf "Old pty master\n"
12279 else
12280 if ($kgm_devnode_major == 6)
12281 printf "Kernel log\n"
12282 else
12283 if ($kgm_devnode_major == 12)
12284 printf "Memory devices\n"
12285 else
12286 # Statically linked dynamic assignments
12287 if cdevsw[$kgm_devnode_major].d_open == ptmx_open
12288 printf "Cloning pty master\n"
12289 _showvnodedev_cpty ($kgm_devnode_major) ($kgm_devnode_minor)
12290 else
12291 if cdevsw[$kgm_devnode_major].d_open == ptsd_open
12292 printf "Cloning pty slave\n"
12293 _showvnodedev_cpty ($kgm_devnode_major) ($kgm_devnode_minor)
12294 else
12295 printf "RESERVED SLOT\n"
12296 end
12297 end
12298 end
12299 end
12300 end
12301 end
12302 end
12303 end
12304 end
c910b4d9 12305 end
c910b4d9 12306 end
b0d623f7
A
12307 else
12308 showptr $kgm_vnode
12309 printf " is not a device\n"
c910b4d9 12310 end
b0d623f7
A
12311 else
12312 printf "| Usage:\n|\n"
12313 help showvnodedev
12314 end
c910b4d9 12315end
b0d623f7
A
12316document showvnodedev
12317Syntax: (gdb) showvnodedev <vnode>
12318| showvnodedev Display information about a device vnode
c910b4d9
A
12319end
12320
b0d623f7
A
12321define showtty
12322 if ($argc == 1)
12323 _showtty $arg0
12324 else
12325 printf "| Usage:\n|\n"
12326 help showtty
12327 end
12328end
12329document showtty
12330Syntax: (gdb) showtty <tty struct>
12331| showtty Display information about a struct tty
12332end
c910b4d9 12333
b0d623f7
A
12334define showeventsourceobject
12335 set $kgm_vt = *((void **) $arg1)
12336 if $kgm_lp64
12337 set $kgm_vt = $kgm_vt - 16
12338 end
12339 pcprint $kgm_vt
12340end
12341document showeventsourceobject
12342Syntax: (gdb) showeventsourceobject <prefix> <object>
12343| Routine to display information about an IOEventSource subclass.
12344end
12345
6d2010ae
A
12346define showworkloopallocator
12347 set $kgm_workloop = (struct IOWorkLoop*)$arg0
12348 set $kgm_bt = (void**)$kgm_workloop->reserved->allocationBacktrace
12349 set $kgm_bt_count = 0
12350 while $kgm_bt_count != (sizeof(IOWorkLoop::ExpansionData.allocationBacktrace) / sizeof(IOWorkLoop::ExpansionData.allocationBacktrace[0]))
12351 set $kgm_frame_address = (void*)$kgm_bt[$kgm_bt_count]
12352 if $kgm_frame_address != 0
12353 if (((unsigned long) $kgm_frame_address < (unsigned long) &_mh_execute_header || \
12354 (unsigned long) $kgm_frame_address >= (unsigned long) &last_kernel_symbol ) \
12355 && ($kgm_show_kmod_syms == 0))
12356 showkmodaddr $kgm_frame_address
12357 else
12358 output /a $kgm_frame_address
12359 end
12360 printf "\n"
12361 end
12362 set $kgm_bt_count = $kgm_bt_count + 1
12363 end
12364end
12365document showworkloopallocator
12366Syntax: (gdb) showworkloopallocator <workloop>
12367| Routine to display the backtrace of the thread which allocated the workloop in question. Only
12368| valid on DEBUG kernels.
12369end
12370
b0d623f7
A
12371define showworkloopeventsources
12372 set $kgm_eventsource = (struct IOEventSource*)$arg0
12373 while $kgm_eventsource != 0
12374 printf " "
12375 printf "EventSource:\t"
12376 showptr $kgm_eventsource
12377 printf " Description: "
12378 showeventsourceobject _ $kgm_eventsource
12379 printf "\n"
12380 if $kgm_eventsource->action != 0
12381 printf " "
12382 printf "Action: \t"
12383 pcprint $kgm_eventsource->action
12384 printf "\n"
12385 end
12386 if $kgm_eventsource->owner != 0
12387 printf " "
12388 printf "Owner: \t"
12389 showptr $kgm_eventsource->owner
12390 printf " Description: "
12391 showeventsourceobject _ $kgm_eventsource->owner
12392 printf "\n"
12393 end
12394 set $kgm_eventsource = $kgm_eventsource->eventChainNext
12395 printf "\n"
12396 end
12397end
12398document showworkloopeventsources
12399Syntax: (gdb) showworkloopeventsources
12400| Routine to walk an IOEventSource chain associated with an IOWorkLoop and print information
12401| about each event source in the chain.
12402end
12403
12404define showworkloopheader
12405 printf "thread "
12406 showptrhdrpad
12407 printf " workloop "
12408 showptrhdrpad
12409 printf " pri state\tLockGroupName\n"
12410end
12411document showworkloopheader
12412Syntax: (gdb) showworkloopheader
12413| Routine to print out header info about an IOKit workloop.
12414end
12415
12416define showworkloop
12417 set $kgm_workloopthread = (struct thread*)$arg0
12418 set $kgm_workloop = (struct IOWorkLoop*)$arg1
12419 showptr $kgm_workloopthread
12420 printf " "
12421 showptr $kgm_workloop
12422 printf " %3d ", $kgm_workloopthread.sched_pri
12423 set $kgm_state = $kgm_workloopthread.state
12424 if $kgm_state & 0x80
12425 printf "I"
12426 end
12427 if $kgm_state & 0x40
12428 printf "P"
12429 end
12430 if $kgm_state & 0x20
12431 printf "A"
12432 end
12433 if $kgm_state & 0x10
12434 printf "H"
12435 end
12436 if $kgm_state & 0x08
12437 printf "U"
12438 end
12439 if $kgm_state & 0x04
12440 printf "R"
12441 end
12442 if $kgm_state & 0x02
12443 printf "S"
12444 end
12445 if $kgm_state & 0x01
12446 printf "W"
12447 end
12448 printf "\t\t"
12449 set $kgm_gateLock = ( struct _IORecursiveLock *)$kgm_workloop->gateLock
6d2010ae
A
12450 if $kgm_gateLock != 0
12451 set $kgm_lockGroup = (struct _lck_grp_*)($kgm_gateLock->group)
12452 printf "%s", $kgm_lockGroup->lck_grp_name
12453 else
12454 printf "No WorkLoop Lock found"
12455 end
12456 printf "\n\n"
12457
12458 #Allocation backtrace is only valid on DEBUG kernels.
12459 #printf "Allocation path:\n\n"
12460 #showworkloopallocator $kgm_workloop
12461 #printf "\n\n"
12462
12463 if $kgm_workloop->eventChain != 0
12464 printf "Active event sources:\n\n"
12465 showworkloopeventsources $kgm_workloop->eventChain
12466 end
12467 if $kgm_workloop->reserved->passiveEventChain != 0
12468 printf "Passive event sources:\n"
12469 showworkloopeventsources $kgm_workloop->reserved->passiveEventChain
12470 end
b0d623f7
A
12471end
12472document showworkloop
12473Syntax: (gdb) showworkloop <thread> <workloop>
12474| Routine to print out info about an IOKit workloop.
12475end
c910b4d9 12476
b0d623f7
A
12477define showallworkloopthreads
12478 set $kgm_head_taskp = &tasks
12479 set $kgm_taskp = (struct task *)($kgm_head_taskp->next)
12480 set $kgm_head_actp = &($kgm_taskp->threads)
12481 set $kgm_actp = (struct thread *)($kgm_taskp->threads.next)
12482 while $kgm_actp != $kgm_head_actp
12483 if ($kgm_actp->continuation == _ZN10IOWorkLoop10threadMainEv)
12484 showworkloopheader
12485 showworkloop $kgm_actp $kgm_actp->parameter
12486 else
12487 if ($kgm_actp->kernel_stack != 0)
12488 if ($kgm_mtype == $kgm_mtype_x86_64)
12489 #Warning: Grokking stack looking for hopeful workloops until we squirrel some info in thread_t.
12490 set $kgm_workloop = *((struct IOWorkLoop **)($kgm_actp->kernel_stack + kernel_stack_size - 0xB8))
12491 else
12492 if ($kgm_mtype == $kgm_mtype_i386)
12493 set $kgm_workloop = *((struct IOWorkLoop **)($kgm_actp->kernel_stack + kernel_stack_size - 0x3C))
12494 end
12495 end
12496 if ($kgm_workloop != 0)
12497 set $kgm_vt = *((void **) $kgm_workloop)
12498 if $kgm_lp64
12499 set $kgm_vt = $kgm_vt - 16
12500 end
12501 if ($kgm_vt == &_ZTV10IOWorkLoop)
12502 showworkloopheader
12503 showworkloop $kgm_actp $kgm_workloop
c910b4d9 12504 end
c910b4d9
A
12505 end
12506 end
c910b4d9 12507 end
b0d623f7 12508 set $kgm_actp = (struct thread *)($kgm_actp->task_threads.next)
c910b4d9 12509 end
b0d623f7 12510 printf "\n"
c910b4d9 12511end
b0d623f7
A
12512document showallworkloopthreads
12513Syntax: (gdb) showallworkloopthreads
12514| Routine to print out info about all IOKit workloop threads in the system. This macro will find
12515| all IOWorkLoop threads blocked in continuations and on i386 and x86_64 systems will make a
12516| best-effort guess to find any workloops that are actually not blocked in a continuation. For a
12517| complete list, it is best to compare the output of this macro against the output of 'showallstacks'.
c910b4d9 12518end
7e4a7d39 12519
b0d623f7
A
12520define showthreadfortid
12521 set $kgm_id_found = 0
12522
12523 set $kgm_head_taskp = &tasks
12524 set $kgm_taskp = (struct task *)($kgm_head_taskp->next)
12525 while $kgm_taskp != $kgm_head_taskp
12526 set $kgm_head_actp = &($kgm_taskp->threads)
12527 set $kgm_actp = (struct thread *)($kgm_taskp->threads.next)
12528 while $kgm_actp != $kgm_head_actp
12529 set $kgm_thread = *(struct thread *)$kgm_actp
12530 set $kgm_thread_id = $kgm_thread.thread_id
12531 if ($kgm_thread_id == $arg0)
12532 showptr $kgm_actp
12533 printf "\n"
12534 set $kgm_id_found = 1
12535 loop_break
12536 end
12537 set $kgm_actp = (struct thread *)($kgm_actp->task_threads.next)
12538 end
12539 if ($kgm_id_found == 1)
12540 loop_break
12541 end
12542 set $kgm_taskp = (struct task *)($kgm_taskp->tasks.next)
c910b4d9 12543 end
b0d623f7
A
12544 if ($kgm_id_found == 0)
12545 printf "Not a valid thread_id\n"
12546 end
12547end
c910b4d9 12548
b0d623f7
A
12549document showthreadfortid
12550Syntax: showthreadfortid <thread_id>
12551|The thread structure contains a unique thread_id value for each thread.
12552|This command is used to retrieve the address of the thread structure(thread_t)
12553|corresponding to a given thread_id.
12554end
c910b4d9 12555
6d2010ae 12556define showtaskbusyportsint
b0d623f7
A
12557 set $kgm_isp = ((task_t)$arg0)->itk_space
12558 set $kgm_iindex = 0
12559 while ( $kgm_iindex < $kgm_isp->is_table_size )
12560 set $kgm_iep = &($kgm_isp->is_table[$kgm_iindex])
12561 if $kgm_iep->ie_bits & 0x00020000
12562 set $kgm_port = ((ipc_port_t)$kgm_iep->ie_object)
12563 if $kgm_port->ip_messages.data.port.msgcount > 0
12564 showport $kgm_port
c910b4d9 12565 end
c910b4d9 12566 end
b0d623f7
A
12567 set $kgm_iindex = $kgm_iindex + 1
12568 end
12569end
c910b4d9 12570
6d2010ae
A
12571define showtaskbusyports
12572 showtaskbusyportsint $arg0
12573end
12574
b0d623f7
A
12575document showtaskbusyports
12576Syntax: showtaskbusyports <task>
12577|Routine to print information about receive rights belonging to this task that
12578|have enqueued messages. This is often a sign of a blocked or hung process.
12579end
c910b4d9 12580
b0d623f7
A
12581define showallbusyports
12582 set $kgm_head_taskp = &tasks
12583 set $kgm_cur_taskp = (struct task *)($kgm_head_taskp->next)
12584 while $kgm_cur_taskp != $kgm_head_taskp
6d2010ae 12585 showtaskbusyportsint $kgm_cur_taskp
b0d623f7
A
12586 set $kgm_cur_taskp = (struct task *)($kgm_cur_taskp->tasks.next)
12587 end
c910b4d9
A
12588end
12589
b0d623f7
A
12590document showallbusyports
12591Syntax: showallbusyports
12592|Routine to print information about all receive rights on the system that
12593|have enqueued messages.
c910b4d9 12594end
b7266188 12595
6d2010ae
A
12596define showallproviders
12597 set $kgm_providerp = dtrace_provider
12598 while $kgm_providerp
12599 p *(dtrace_provider_t *)$kgm_providerp
12600 printf "\n"
12601 set $kgm_providerp = (dtrace_provider_t *)($kgm_providerp->dtpv_next)
12602 end
12603end
12604
12605document showallproviders
12606Syntax: showallproviders
12607| Display summary listing of all dtrace_providers
12608end
12609
12610define showmodctlheader
12611 printf "modctl "
12612 showptrhdrpad
12613 printf " stale "
12614 showptrhdrpad
12615 printf " symbols "
12616 showptrhdrpad
12617 printf " address "
12618 showptrhdrpad
12619 printf " size "
12620 showptrhdrpad
12621 printf " loadid loaded nenabled flags name\n"
12622end
12623
12624define showmodctlint
12625 set $kgm_modctlp = (struct modctl *)$arg0
12626 showptr $kgm_modctlp
12627 printf " "
12628 showptr $kgm_modctlp->mod_stale
12629 printf " "
12630 showptr $kgm_modctlp->mod_user_symbols
12631 printf " "
12632 showptr $kgm_modctlp->mod_address
12633 printf " "
12634 showptr $kgm_modctlp->mod_size
12635 printf " "
12636 printf "%6d ", $kgm_modctlp->mod_loadcnt
12637 printf "%6d ", $kgm_modctlp->mod_loaded
12638 printf "%6d ", $kgm_modctlp->mod_nenabled
12639 printf " 0x%x ", $kgm_modctlp->mod_flags
12640 printf "%s\n", $kgm_modctlp->mod_modname
12641end
12642
12643define showmodctl
12644 showmodctlheader
12645 showmodctlint $arg0
12646end
12647document showmodctl
12648Syntax: (gdb) showmodctl <addr>
12649| Display info about a dtrace modctl
12650end
12651
12652define showallmodctls
12653 showmodctlheader
12654 set $kgm_modctlp = (struct modctl *)dtrace_modctl_list
12655 while $kgm_modctlp
12656 showmodctlint $kgm_modctlp
12657 set $kgm_modctlp = $kgm_modctlp->mod_next
12658 end
12659end
12660document showallmodctls
12661Syntax: (gdb) showallmodctls
12662| Display summary listing of all dtrace modctls
12663end
12664
12665define showfbtprobe
12666 printf "Be very patient, this traverses a large list \n"
12667 set $kgm_indx = 0
12668 set $kgm_found = 0
12669 set $kgm_depth = 0
12670 while $kgm_indx < fbt_probetab_size && !$kgm_found
12671 set $kgm_fbt_probep = (struct fbt_probe *)fbt_probetab[$kgm_indx]
12672 set $kgm_depth = 0
12673 if $kgm_fbt_probep
12674 set $kgm_probeid = (struct fbt_probe *)$kgm_fbt_probep->fbtp_id
12675 if $kgm_probeid == $arg0
12676 set $kgm_found = 1
12677 loop_break
12678 else
12679 set $kgm_fbt_probep = $kgm_fbt_probep->fbtp_hashnext
12680 while $kgm_fbt_probep
12681 set $kgm_depth++
12682 set $kgm_probeid = (struct fbt_probe *)$kgm_fbt_probep->fbtp_id
12683 if $kgm_probeid == $arg0
12684 set $kgm_found = 1
12685 loop_break
12686 else
12687 set $kgm_fbt_probep = $kgm_fbt_probep->fbtp_hashnext
12688 end
12689 end
12690 end
12691 end
12692 if !$kgm_found
12693 set $kgm_indx++
b7266188 12694 else
6d2010ae
A
12695 printf "fbt_probetab[index=%d], depth=%d, 0x%x\n", $kgm_indx, $kgm_depth, $kgm_fbt_probep
12696 printf "(gdb) p *(struct fbt_probe *)0x%x\n", $kgm_fbt_probep
12697 p *(struct fbt_probe *)$kgm_fbt_probep
12698 set $kgm_fbtp_ctl = (struct fbt_probe *)$kgm_fbt_probep->fbtp_ctl
12699 showmodctl $kgm_fbtp_ctl
12700 loop_break
12701 end
12702 end
12703end
12704document showfbtprobe
12705Syntax: (gdb) showfbtprobe <id>
12706| Display info about an fbt probe given an id.
12707| Traverses fbt_probetab and matches <id> with fbtp_id.
12708| The <id> is found using dtrace -l
12709end
12710
12711define showzstacktrace
12712 set $kgm_trace = (void*)$arg0
12713 if ($argc == 1)
12714 set $kgm_trace_size = 15
12715 end
12716 if ($argc == 2)
12717 set $kgm_trace_size = $arg1
12718 end
12719 set $kgm_trace_current = 0
12720 while ($kgm_trace_current < $kgm_trace_size)
12721 set $kgm_trace_addr = (void**)$kgm_trace + $kgm_trace_current
12722 set $kgm_trace_value = *((void**)$kgm_trace_addr)
12723 #printf "\t\t"
12724 output /a $kgm_trace_value
12725 set $kgm_trace_current = $kgm_trace_current + 1
12726 printf "\n"
12727 end
12728end
12729
12730document showzstacktrace
12731Syntax: showzstacktrace <saved stacktrace> [size]
12732| Routine to print a stacktrace stored by OSBacktrace.
12733| size is optional, defaults to 15.
12734end
12735
12736define showzalloc
12737 set $kgm_zallocation = zallocations[$arg0]
12738 print $kgm_zallocation
12739 showztrace $kgm_zallocation->za_trace_index
12740end
12741
12742document showzalloc
12743Syntax: showzalloc <index>
12744| Prints a zallocation from the zallocations array based off its index,
12745| and prints the associated symbolicated backtrace.
12746end
12747
12748define showztrace
12749 set $kgm_ztrace = &ztraces[$arg0]
12750 showztraceaddr $kgm_ztrace
12751end
12752
12753document showztrace
12754Syntax: showztrace <trace index>
12755| Prints the backtrace from the ztraces array at index
12756end
12757
12758define showztraceaddr
12759 print *$arg0
12760 showzstacktrace $arg0->zt_stack ($arg0)->zt_depth
12761end
12762
12763document showztraceaddr
12764Syntax: showztraceaddr <trace address>
12765| Prints the struct ztrace passed in
12766end
12767
12768#TODO: Iterate through the hash table, or make top_ztrace accurate in the face of deallocations (better idea).
12769define showtopztrace
12770 set $kgm_top_ztrace = top_ztrace
12771 printf "Index: %d\n", (top_ztrace - ztraces)
12772 showztraceaddr $kgm_top_ztrace
12773end
12774
12775document showtopztrace
12776Syntax: showtopztrace
12777| Shows the ztrace with the biggest size. (according to top_ztrace, not by iterating through the hash table)
12778end
12779
12780define showzallocs
12781 set $kgm_zallocation_current_index = 0
12782 set $kgm_zallocations_count = 0
12783 set $kgm_max_zallocation = zleak_alloc_buckets
12784 printf "INDEX ADDRESS "
12785 if $kgm_lp64
12786 printf " "
12787 end
12788 printf "TRACE SIZE\n"
12789 while ($kgm_zallocation_current_index < $kgm_max_zallocation)
12790 set $kgm_zallocation_current = zallocations[$kgm_zallocation_current_index]
12791 if ($kgm_zallocation_current->element != 0)
12792 printf "%5d %p ", $kgm_zallocation_current_index, $kgm_zallocation_current->za_element
12793 printf "%5d %6lu\n", $kgm_zallocation_current->za_trace_index, $kgm_zallocation_current->za_size
12794 set $kgm_zallocations_count = $kgm_zallocations_count + 1
12795 end
12796 set $kgm_zallocation_current_index = $kgm_zallocation_current_index + 1
12797 end
12798 printf "Total allocations: %d\n", $kgm_zallocations_count
12799end
12800
12801document showzallocs
12802Syntax: showzallocs
12803| Prints all allocations in the zallocations table
12804end
12805
12806define showzallocsfortrace
12807 set $kgm_zallocation_current_index = 0
12808 set $kgm_zallocations_count = 0
12809 set $kgm_max_zallocation = zleak_alloc_buckets
12810 printf "INDEX ADDRESS "
12811 if $kgm_lp64
12812 printf " "
12813 end
12814 printf "SIZE\n"
12815 while ($kgm_zallocation_current_index < $kgm_max_zallocation)
12816 set $kgm_zallocation_current = zallocations[$kgm_zallocation_current_index]
12817 if ($kgm_zallocation_current->element != 0 && $kgm_zallocation_current->za_trace_index == $arg0)
12818 printf "%5d %p ", $kgm_zallocation_current_index, $kgm_zallocation_current->za_element
12819 printf "%6lu\n", $kgm_zallocation_current->size
12820 set $kgm_zallocations_count = $kgm_zallocations_count + 1
12821 end
12822 set $kgm_zallocation_current_index = $kgm_zallocation_current_index + 1
12823 end
12824 printf "Total allocations: %d\n", $kgm_zallocations_count
12825end
12826
12827document showzallocsfortrace
12828Syntax: showzallocsfortrace <trace index>
12829| Prints all allocations pointing to the passed in trace's index into ztraces by looking through zallocations table
12830end
12831
12832define showztraces
12833 showztracesabove 0
12834end
12835
12836document showztraces
12837Syntax: showztraces
12838| Prints all traces with size > 0
12839end
12840
12841define showztracesabove
12842 set $kgm_ztrace_current_index = 0
12843 set $kgm_ztrace_count = 0
12844 set $kgm_max_ztrace = zleak_trace_buckets
12845 printf "INDEX SIZE\n"
12846 while ($kgm_ztrace_current_index < $kgm_max_ztrace)
12847 set $kgm_ztrace_current = ztraces[$kgm_ztrace_current_index]
12848 if ($kgm_ztrace_current->zt_size > $arg0)
12849 printf "%5d %6lu\n", $kgm_ztrace_current_index, $kgm_ztrace_current->zt_size
12850 set $kgm_ztrace_count = $kgm_ztrace_count + 1
12851 end
12852 set $kgm_ztrace_current_index = $kgm_ztrace_current_index + 1
12853 end
12854 printf "Total traces: %d\n", $kgm_ztrace_count
12855end
12856
12857document showztracesabove
12858Syntax: showztracesabove <size>
12859| Prints all traces with size greater than X
12860end
12861
12862define showztracehistogram
12863 set $kgm_ztrace_current_index = 0
12864 set $kgm_ztrace_count = 0
12865 set $kgm_max_ztrace = zleak_trace_buckets
12866 printf "INDEX HIT_COUNT COLLISIONS\n"
12867 while ($kgm_ztrace_current_index < $kgm_max_ztrace)
12868 set $kgm_ztrace_current = ztraces[$kgm_ztrace_current_index]
12869 if ($kgm_ztrace_current->zt_hit_count != 0)
12870 printf "%5d %5d %5d\n", $kgm_ztrace_current_index, $kgm_ztrace_current->zt_hit_count, $kgm_ztrace_current->zt_collisions
12871 set $kgm_ztrace_count = $kgm_ztrace_count + 1
12872 end
12873 set $kgm_ztrace_current_index = $kgm_ztrace_current_index + 1
12874 end
12875 printf "Total traces: %d\n", $kgm_ztrace_count
12876end
12877
12878document showztracehistogram
12879Syntax: showztracehistogram
12880| Prints the histogram of the ztrace table
12881end
12882
12883define showzallochistogram
12884 set $kgm_zallocation_current_index = 0
12885 set $kgm_zallocations_count = 0
12886 set $kgm_max_zallocation = zleak_alloc_buckets
12887 printf "INDEX HIT_COUNT\n"
12888 while ($kgm_zallocation_current_index < $kgm_max_zallocation)
12889 set $kgm_zallocation_current = zallocations[$kgm_zallocation_current_index]
12890 if ($kgm_zallocation_current->za_hit_count != 0)
12891 printf "%5d %5d\n", $kgm_zallocation_current_index, $kgm_zallocation_current->za_hit_count
12892 set $kgm_zallocations_count = $kgm_zallocations_count + 1
12893 end
12894 set $kgm_zallocation_current_index = $kgm_zallocation_current_index + 1
12895 end
12896 printf "Total allocations: %d\n", $kgm_zallocations_count
12897end
12898
12899document showzallochistogram
12900Syntax: showzallochistogram
12901| Prints the histogram for the zalloc table
12902end
12903
12904define showzstats
12905 printf "z_alloc_collisions: %u, z_trace_collisions: %u\n", z_alloc_collisions, z_trace_collisions
12906 printf "z_alloc_overwrites: %u, z_trace_overwrites: %u\n", z_alloc_overwrites, z_trace_overwrites
12907 printf "z_alloc_recorded: %u, z_trace_recorded: %u\n", z_alloc_recorded, z_trace_recorded
12908end
12909
12910document showzstats
12911Syntax: showzstats
12912| Prints the zone leak detection stats
12913end
12914
12915
12916set $kgm_au_sentry_hash_table_size = 97
12917
12918define showsession1
12919 set $p = (struct au_sentry *)$arg0
12920 showptr $p
12921 printf " 0x%08x 0x%08x 0x%016x", $p->se_auinfo.ai_asid, $p->se_auinfo.ai_auid, $p->se_auinfo.ai_flags
12922 printf " %3ld %3ld", $p->se_refcnt, $p->se_procnt
12923 printf "\n"
12924end
12925
12926define showsessionhdr
12927 printf "au_sentry "
12928 showptrhdrpad
12929 printf " ASID AUID FLAGS C P\n"
12930end
12931
12932define showsession
12933 showsessionhdr
12934 showsession1 $arg0
12935end
12936
12937document showsession
12938Syntax: showsession
12939| Display info about a specified audit session
12940end
12941
12942define showallsessions
12943 showsessionhdr
12944 set $kgm_au_sentry_hash_table = au_sentry_bucket
12945 set $i = $kgm_au_sentry_hash_table_size - 1
12946 while $i >= 0
12947 set $p = $kgm_au_sentry_hash_table[$i].lh_first
12948 while $p != 0
12949 showsession1 $p
12950 set $p = $p->se_link.le_next
12951 end
12952 set $i = $i - 1
12953 end
12954end
12955
12956document showallsessions
12957Syntax: showallsessions
12958| Prints the audit sessions in the global hash table
12959end
12960
12961define showauhistorystack
12962 set $ii = $arg0
12963 set $pp = (void **)$arg1
12964 while $ii > 0
12965 printf " "
12966 x/i $pp[$ii-1]
12967 set $ii = $ii - 1
12968 end
12969end
12970
12971define showauhistory1
12972 set $p = (struct au_history *)$arg0
12973 set $stack_depth = $p->stack_depth
12974 set $stack = $p->stack
12975 showptr $p->ptr
12976 if $p->event == 1
12977 printf " REF"
12978 end
12979 if $p->event == 2
12980 printf " UNREF"
12981 end
12982 if $p->event == 3
12983 printf " BIRTH"
12984 end
12985 if $p->event == 4
12986 printf " DEATH"
12987 end
12988 if $p->event == 5
12989 printf " FIND"
12990 end
12991 set $p = &$p->se
12992 printf " 0x%08x 0x%08x 0x%016x", $p->se_auinfo.ai_asid, $p->se_auinfo.ai_auid, $p->se_auinfo.ai_flags
12993 printf " %3ld %3ld", $p->se_refcnt, $p->se_procnt
12994 printf "\n"
12995 showauhistorystack $stack_depth $stack
12996end
12997
12998define showauhistory
12999 set $i = (au_history_index-1) % au_history_size
13000 if au_history_index >= au_history_size
13001 set $n = au_history_size
13002 else
13003 set $n = au_history_index
13004 end
13005 while $n > 0
13006 if au_history[$i].ptr != 0 && (0 == $arg0 || au_history[$i].ptr == $arg0)
13007 printf "[% 4d] ", $i
13008 showauhistory1 &au_history[$i]
13009 end
13010 set $n = $n - 1
13011 set $i = ($i - 1) % au_history_size
13012 end
13013end
13014
13015define showallauhistory
13016 showauhistory 0
13017end
13018
13019define showkwqheader
13020 printf " kwq "
13021 showptrhdrpad
13022 printf " kwqaddr "
13023 showptrhdrpad
13024 printf " inqueue fakecount highseq lowseq flags lastunlock p_rwwc"
13025 printf "\n "
13026end
13027
13028define showkwqint
13029 printf " "
13030 set $kgm_kwq = (ksyn_wait_queue_t)$arg0
13031 showptr $kgm_kwq
13032 printf " "
13033 showptr $kgm_kwq->kw_addr
13034 printf " "
13035 printf " %d ", $kgm_kwq->kw_inqueue
13036 printf " %d ", $kgm_kwq->kw_fakecount
13037 printf " 0x%x ", $kgm_kwq->kw_highseq
13038 printf " 0x%x ", $kgm_kwq->kw_lowseq
13039 printf " 0x%x ", $kgm_kwq->kw_flags
13040 printf " 0x%x ", $kgm_kwq->kw_lastunlockseq
13041 printf " 0x%x ", $kgm_kwq->kw_pre_rwwc
13042 printf "\n"
13043end
13044
13045define show_kwq
13046 showkwqheader
13047 showkwqint $arg0
13048end
13049
13050document show_kwq
13051Syntax: (gdb) show_kwq <kwq>
13052| Display info about one ksyn_wait_queue
13053end
13054
13055# Internal routine used by "showpthread_mutex" to abstract possible loads from
13056# user space
13057define _loadfrommutex
13058 if (kdp_pmap == 0)
13059 set $kgm_loadval = *(uintptr_t *)$arg0
13060 else
13061 if ($kgm_x86_abi == 0xe)
13062 set $kgm_loadval = *(uint32_t *)$arg0
13063 else
13064 if ($kgm_x86_abi == 0xf)
13065 if ($kgm_mtype == $kgm_mtype_i386)
13066 _loadk32m64 $arg0
13067 set $kgm_loadval = $kgm_k32read64
13068 else
13069 set $kgm_loadval = *(uint32_t *)$arg0
13070 end
13071 end
13072 end
13073end
13074end
13075
13076define show_pthreadmutex
13077 set $newact = (struct thread *) $arg0
13078 set $ourtask = (struct task *)($newact->task)
13079 set $our_user_is64 = ($ourtask->taskFeatures[0] & 0x80000000)
13080 _kgm_flush_loop
13081 set $mutex = (void *)$arg1
13082 set kdp_pmap = $newact->task->map->pmap
13083 _kgm_flush_loop
13084 _kgm_update_loop
13085 set $newiss = (x86_saved_state_t *) ($newact->machine.pcb->iss)
13086 set $kgm_x86_abi = $newiss.flavor
13087 if ($our_user_is64 != 0)
13088 printf "\tUser 64Bit\n "
13089 printf "\tSignature: "
13090 set $nextval = $mutex
13091 _loadfrommutex $nextval
13092 printf "0x%x\n",$kgm_loadval
13093 printf "\tflags: "
13094 set $nextval = $mutex + 12
13095 _loadfrommutex $nextval
13096 printf "0x%x\n",$kgm_loadval
13097 printf "\tSeqs: "
13098 set $nextval = $mutex + 20
13099 _loadfrommutex $nextval
13100 printf "0x%x ",$kgm_loadval
13101 set $nextval = $mutex + 24
13102 _loadfrommutex $nextval
13103 printf "0x%x ",$kgm_loadval
13104 set $nextval = $mutex + 28
13105 _loadfrommutex $nextval
13106 printf "0x%x\n",$kgm_loadval
13107 printf "\ttid[0]: "
13108 set $nextval = $mutex + 32
13109 _loadfrommutex $nextval
13110 printf "0x%x\n",$kgm_loadval
13111 printf "\ttid[1]: "
13112 set $nextval = $mutex + 36
13113 _loadfrommutex $nextval
13114 printf "0x%x\n",$kgm_loadval
13115 else
13116 printf "\tUser 32Bit\n "
13117 printf "\tSignature: "
13118 set $nextval = $mutex
13119 _loadfrommutex $nextval
13120 printf "0x%x\n",$kgm_loadval
13121 printf "\tflags: "
13122 set $nextval = $mutex + 8
13123 _loadfrommutex $nextval
13124 printf "0x%x\n",$kgm_loadval
13125 printf "\tSeqs: "
13126 set $nextval = $mutex + 16
13127 _loadfrommutex $nextval
13128 printf "0x%x ",$kgm_loadval
13129 set $nextval = $mutex + 20
13130 _loadfrommutex $nextval
13131 printf "0x%x ",$kgm_loadval
13132 set $nextval = $mutex + 24
13133 _loadfrommutex $nextval
13134 printf "0x%x\n",$kgm_loadval
13135 printf "\ttid[0]: "
13136 set $nextval = $mutex + 32
13137 _loadfrommutex $nextval
13138 printf "0x%x\n",$kgm_loadval
13139 printf "\ttid[1]: "
13140 set $nextval = $mutex + 36
13141 _loadfrommutex $nextval
13142 printf "0x%x\n",$kgm_loadval
13143 end
13144 printf "\n"
13145 resetstacks
13146end
13147
13148
13149document show_pthreadmutex
13150Syntax: (gdb) show_pthreadmutex <thread> <user_mutexaddr>
13151| Display the mutex contents from userspace.
13152end
13153
13154
13155define show_pthreadcondition
13156 set $newact = (struct thread *) $arg0
13157 set $ourtask = (struct task *)($newact->task)
13158 set $our_user_is64 = ($ourtask->taskFeatures[0] & 0x80000000)
13159 _kgm_flush_loop
13160 set $cond = (void *)$arg1
13161 set kdp_pmap = $newact->task->map->pmap
13162 _kgm_flush_loop
13163 _kgm_update_loop
13164 set $newiss = (x86_saved_state_t *) ($newact->machine.pcb->iss)
13165 set $kgm_x86_abi = $newiss.flavor
13166 if ($our_user_is64 != 0)
13167 printf "\tUser 64Bit\n "
13168 printf "\tSignature: "
13169 set $nextval = $cond
13170 _loadfrommutex $nextval
13171 printf "0x%x\n",$kgm_loadval
13172 printf "\tflags: "
13173 set $nextval = $cond + 12
13174 _loadfrommutex $nextval
13175 printf "0x%x\n",$kgm_loadval
13176 printf "\tSeqs: "
13177 set $nextval = $cond + 24
13178 _loadfrommutex $nextval
13179 printf "0x%x ",$kgm_loadval
13180 set $nextval = $cond + 28
13181 _loadfrommutex $nextval
13182 printf "0x%x ",$kgm_loadval
13183 set $nextval = $cond + 32
13184 _loadfrommutex $nextval
13185 printf "0x%x\n",$kgm_loadval
13186 printf "\tMutex lowaddr: "
13187 set $nextval = $cond + 16
13188 _loadfrommutex $nextval
13189 printf "0x%08x\n",$kgm_loadval
13190 printf "\tMutex highaddr: "
13191 set $nextval = $cond + 20
13192 _loadfrommutex $nextval
13193 printf "0x%x\n",$kgm_loadval
13194 else
13195 printf "\tUser 32Bit\n "
13196 printf "\tSignature: "
13197 set $nextval = $cond
13198 _loadfrommutex $nextval
13199 printf "0x%x\n",$kgm_loadval
13200 printf "\tflags: "
13201 set $nextval = $cond + 8
13202 _loadfrommutex $nextval
13203 printf "0x%x\n",$kgm_loadval
13204 printf "\tSeqs: "
13205 set $nextval = $cond + 16
13206 _loadfrommutex $nextval
13207 printf "0x%x ",$kgm_loadval
13208 set $nextval = $cond + 20
13209 _loadfrommutex $nextval
13210 printf "0x%x ",$kgm_loadval
13211 set $nextval = $cond + 24
13212 _loadfrommutex $nextval
13213 printf "0x%x\n",$kgm_loadval
13214 printf "\tMutex addr: "
13215 set $nextval = $cond + 12
13216 _loadfrommutex $nextval
13217 printf "0x%x\n",$kgm_loadval
13218 end
13219 printf "\n"
13220 resetstacks
13221end
13222
13223
13224document show_pthreadcondition
13225Syntax: (gdb) show_pthreadcondition <thread> <user_cvaddr>
13226| Display the condition variable contents from userspace.
13227end
13228
13229define processortimers
13230 set $kgm_p = processor_list
13231 printf "Processor\t\t\t Last dispatch\t\t Next deadline\t\t difference\n"
13232 while $kgm_p
13233 printf "Processor %d: %p\t", $kgm_p->cpu_id, $kgm_p
13234 printf " 0x%016llx\t", $kgm_p->last_dispatch
13235 set $kgm_rt_timer = &(cpu_data_ptr[$kgm_p->cpu_id].rtclock_timer)
13236 printf " 0x%016llx \t", $kgm_rt_timer->deadline
13237 set $kgm_rt_diff = ((long long)$kgm_p->last_dispatch) - ((long long)$kgm_rt_timer->deadline)
13238 printf " 0x%016llx ", $kgm_rt_diff
13239# normally the $kgm_rt_diff will be close to the last dispatch time, or negative
13240# When it isn't, mark the result as bad. This is a suggestion, not an absolute
13241 if ( ($kgm_rt_diff > 0) && ((long long)$kgm_p->last_dispatch) - ($kgm_rt_diff + 1) > 0 )
13242 printf "probably BAD\n"
13243 else
13244 printf "(ok)\n"
13245 end
13246 # dump the call entries (Intel only)
13247 if (($kgm_mtype & $kgm_mtype_x86_mask) == $kgm_mtype_x86_any)
13248 printf "Next deadline set at: 0x%016llx. Timer call list:", $kgm_rt_timer->when_set
13249 set $kgm_entry = (queue_t *)$kgm_rt_timer->queue
13250 if ($kgm_entry == $kgm_rt_timer)
13251 printf " (empty)\n"
13252 else
13253 printf "\n entry: "
13254 showptrhdrpad
13255 printf "deadline soft_deadline delta (*func)(param0,param1)\n"
13256 while $kgm_entry != $kgm_rt_timer
13257 set $kgm_timer_call = (timer_call_t) $kgm_entry
13258 set $kgm_call_entry = (struct call_entry *) $kgm_entry
13259 printf " "
13260 showptr $kgm_entry
13261 printf ": 0x%016llx 0x%016llx 0x%08x (%p)(%p,%p)\n", \
13262 $kgm_call_entry->deadline, \
13263 $kgm_timer_call->soft_deadline, \
13264 ($kgm_call_entry->deadline - $kgm_timer_call->soft_deadline), \
13265 $kgm_call_entry->func, \
13266 $kgm_call_entry->param0, $kgm_call_entry->param1
13267 set $kgm_entry = $kgm_entry->next
13268 end
13269 end
13270 end
13271 set $kgm_p = $kgm_p->processor_list
b7266188 13272 end
6d2010ae 13273 printf "\n"
b7266188
A
13274end
13275
6d2010ae
A
13276document processortimers
13277Syntax: (gdb) processortimers
13278| Print details of processor timers, noting any timer which might be suspicious
b7266188 13279end
6d2010ae
A
13280
13281