]> git.saurik.com Git - apple/xnu.git/blame - kgmacros
xnu-1504.15.3.tar.gz
[apple/xnu.git] / kgmacros
CommitLineData
1c79356b
A
1# Kernel gdb macros
2#
3# These gdb macros should be useful during kernel development in
4# determining what's going on in the kernel.
5#
6# All the convenience variables used by these macros begin with $kgm_
7
0c530ab8
A
8set print asm-demangle on
9set cp-abi gnu-v2
9bccf70c 10
b0d623f7
A
11# This option tells gdb to relax its stack tracing heuristics
12# Useful for debugging across stack switches
13# (to the interrupt stack, for instance). Requires gdb-675 or greater.
14set backtrace sanity-checks off
15
1c79356b
A
16echo Loading Kernel GDB Macros package. Type "help kgm" for more info.\n
17
18define kgm
55e303ae
A
19printf ""
20echo These are the gdb macros for kernel debugging. Type "help kgm" for more info.\n
1c79356b
A
21end
22
23document kgm
24| These are the kernel gdb macros. These gdb macros are intended to be
25| used when debugging a remote kernel via the kdp protocol. Typically, you
26| would connect to your remote target like so:
2d21ac55
A
27| (gdb) target remote-kdp
28| (gdb) attach <name-of-remote-host>
1c79356b
A
29|
30| The following macros are available in this package:
91447636 31| showversion Displays a string describing the remote kernel version
1c79356b 32|
55e303ae
A
33| showalltasks Display a summary listing of all tasks
34| showallthreads Display info about all threads in the system
35| showallstacks Display the stack for each thread in the system
36| showcurrentthreads Display info about the thread running on each cpu
37| showcurrentstacks Display the stack for the thread running on each cpu
1c79356b
A
38| showallvm Display a summary listing of all the vm maps
39| showallvme Display a summary listing of all the vm map entries
40| showallipc Display a summary listing of all the ipc spaces
41| showallrights Display a summary listing of all the ipc rights
42| showallkmods Display a summary listing of all the kernel modules
b0d623f7 43| showallbusyports Display a listing of all ports with unread messages
0c530ab8
A
44|
45| showallclasses Display info about all OSObject subclasses in the system
46| showobject Show info about an OSObject - its vtable ptr and retain count, & more info for simple container classes.
47| showregistry Show info about all registry entries in the current plane
48| showregistryprops Show info about all registry entries in the current plane, and their properties
49| showregistryentry Show info about a registry entry; its properties and descendants in the current plane
50| setregistryplane Set the plane to be used for the iokit registry macros (pass zero for list)
1c79356b 51|
b0d623f7
A
52| setfindregistrystr Set the encoded string for matching with
53| findregistryentry or findregistryprop (created from
54| strcmp_arg_pack64)
55| findregistryentry Find a registry entry that matches the encoded string
56| findregistryentries Find all the registry entries that match the encoded string
57| findregistryprop Search the registry entry for a property that matches
58| the encoded string
59|
55e303ae
A
60| showtask Display info about the specified task
61| showtaskthreads Display info about the threads in the task
62| showtaskstacks Display the stack for each thread in the task
63| showtaskvm Display info about the specified task's vm_map
64| showtaskvme Display info about the task's vm_map entries
65| showtaskipc Display info about the specified task's ipc space
66| showtaskrights Display info about the task's ipc space entries
b7266188 67| showtaskrightsbt Display info about the task's ipc space entries with back traces
b0d623f7 68| showtaskbusyports Display all of the task's ports with unread messages
1c79356b 69|
55e303ae
A
70| showact Display info about a thread specified by activation
71| showactstack Display the stack for a thread specified by activation
1c79356b 72|
55e303ae 73| showmap Display info about the specified vm_map
1c79356b
A
74| showmapvme Display a summary list of the specified vm_map's entries
75|
55e303ae 76| showipc Display info about the specified ipc space
1c79356b
A
77| showrights Display a summary list of all the rights in an ipc space
78|
55e303ae
A
79| showpid Display info about the process identified by pid
80| showproc Display info about the process identified by proc struct
2d21ac55
A
81| showprocinfo Display detailed info about the process identified by proc struct
82| showprocfiles Given a proc_t pointer, display the list of open file descriptors
83| showproclocks Given a proc_t pointer, display the list of advisory file locks
84| zombproc Print out all procs in the zombie list
85| allproc Print out all process in the system not in the zombie list
86| zombstacks Print out all stacks of tasks that are exiting
87|
88| showinitchild Print out all processes in the system which are children of init process
1c79356b 89|
55e303ae 90| showkmod Display info about a kernel module
1c79356b
A
91| showkmodaddr Given an address, display the kernel module and offset
92|
55e303ae
A
93| dumpcallqueue Dump out all the entries given a queue head
94|
91447636
A
95| showallmtx Display info about mutexes usage
96| showallrwlck Display info about reader/writer locks usage
97|
55e303ae 98| zprint Display info about the memory zones
91447636 99| showioalloc Display info about iokit allocations
55e303ae 100| paniclog Display the panic log info
9bccf70c 101|
55e303ae
A
102| switchtoact Switch to different context specified by activation
103| switchtoctx Switch to different context
91447636
A
104| showuserstack Display numeric backtrace of the user stack for an
105| activation
106|
107| switchtouserthread Switch to the user context of the specified thread
108| resetstacks Return to the original kernel context
109|
9bccf70c 110| resetctx Reset context
55e303ae
A
111| resume_on Resume when detaching from gdb
112| resume_off Don't resume when detaching from gdb
1c79356b 113|
91447636 114| sendcore Configure kernel to send a coredump to the specified IP
7e4a7d39
A
115| sendsyslog Configure kernel to send a system log to the specified IP
116| sendpaniclog Configure kernel to send a panic log to the specified IP
91447636 117| disablecore Configure the kernel to disable coredump transmission
7e4a7d39
A
118| getdumpinfo Retrieve the current remote dump parameters
119| setdumpinfo Configure the remote dump parameters
120|
91447636
A
121| switchtocorethread Corefile version of "switchtoact"
122| resetcorectx Corefile version of "resetctx"
0c530ab8 123|
b0d623f7
A
124| readphys8 Reads the specified untranslated address (8-bit read)
125| readphys16 Reads the specified untranslated address (16-bit read)
126| readphys32 Reads the specified untranslated address (32-bit read)
127| readphys64 Reads the specified untranslated address (64-bit read)
128| writephys8 Writes to the specified untranslated address (8-bit write)
129| writephys16 Writes to the specified untranslated address (16-bit write)
130| writephys32 Writes to the specified untranslated address (32-bit write)
131| writephys64 Writes to the specified untranslated address (64-bit write)
132|
133| readioport8 Read 8-bits from the specified I/O Port
134| readioport16 Read 16-bits from the specified I/O Port
135| readioport32 Read 32-bits from the specified I/O Port
136| writeioport8 Write 8-bits into the specified I/O Port
137| writeioport16 Write 16-bits into the specified I/O Port
138| writeioport32 Write 32-bits into the specified I/O Port
139|
140| readmsr64 Read 64-bits from the specified MSR
141| writemsr64 Write 64-bits into the specified MSR
0c530ab8 142|
2d21ac55
A
143| rtentry_showdbg Print the debug information of a route entry
144| rtentry_trash Walk the list of trash route entries
145|
b0d623f7
A
146| inifa_showdbg Print the debug information of an IPv4 interface address
147| in6ifa_showdbg Print the debug information of an IPv6 interface address
148|
2d21ac55
A
149| mbuf_walkpkt Walk the mbuf packet chain (m_nextpkt)
150| mbuf_walk Walk the mbuf chain (m_next)
151| mbuf_buf2slab Find the slab structure of the corresponding buffer
152| mbuf_buf2mca Find the mcache audit structure of the corresponding mbuf
153| mbuf_showmca Print the contents of an mbuf mcache audit structure
154| mbuf_showactive Print all active/in-use mbuf objects
155| mbuf_showinactive Print all freed/in-cache mbuf objects
156| mbuf_showall Print all mbuf objects
157| mbuf_slabs Print all slabs in the group
158| mbuf_slabstbl Print slabs table
159| mbuf_stat Print extended mbuf allocator statistics
160|
161| mcache_walkobj Walk the mcache object chain (obj_next)
162| mcache_stat Print all mcaches in the system
163| mcache_showcache Display the number of objects in the cache
164|
b0d623f7 165| showbootargs Display boot arguments passed to the target kernel
2d21ac55
A
166| showbootermemorymap Dump phys memory map from EFI
167|
b0d623f7
A
168| systemlog Display the kernel's printf ring buffer
169|
170| hexdump Show the contents of memory as a hex/ASCII dump
2d21ac55
A
171|
172| showvnodepath Print the path for a vnode
173| showvnodelocks Display list of advisory locks held/blocked on a vnode
b0d623f7
A
174| showvnodedev Display information about a device vnode
175| showtty Display information about a struct tty
2d21ac55
A
176| showallvols Display a summary of mounted volumes
177| showvnode Display info about one vnode
178| showvolvnodes Display info about all vnodes of a given volume
179| showvolbusyvnodes Display info about busy (iocount!=0) vnodes of a given volume
180| showallbusyvnodes Display info about all busy (iocount!=0) vnodes
181| showallvnodes Display info about all vnodes
182| print_vnode Print out the fields of a vnode struct
183| showprocvnodes Print out all the open fds which are vnodes in a process
184| showallprocvnodes Print out all the open fds which are vnodes in any process
185| showmountvnodes Print the vnode list
186| showmountallvnodes Print the vnode inactive list
187| showworkqvnodes Print the vnode worker list
188| shownewvnodes Print the new vnode list
189|
b0d623f7
A
190| ifconfig display ifconfig-like output
191| showifaddrs show the list of addresses for the given ifp
192| showifmultiaddrs show the list of multicast addresses for the given ifp
193|
194| showsocket Display information about a socket
195| showprocsockets Given a proc_t pointer, display information about its sockets
196| showallprocsockets Display information about the sockets of all the processes
197|
198| show_tcp_pcbinfo Display the list of the TCP protocol control blocks
199| show_tcp_timewaitslots Display the list of the TCP protocol control blocks in TIMEWAIT
200| show_udp_pcbinfo Display the list of UDP protocol control blocks
201|
202| show_rt_inet Display the IPv4 routing table
203| show_rt_inet6 Display the IPv6 routing table
2d21ac55
A
204|
205| showallpmworkqueues Display info about all IOPMWorkQueue objects
206| showregistrypmstate Display power management state for all IOPower registry entries
207| showioservicepm Display the IOServicePM object
208| showstacksaftertask showallstacks starting after a given task
209| showstacksafterthread showallstacks starting after a given thread
210|
211| showMCAstate Print machine-check register state after MC exception.
212|
213| showallgdbstacks Cause GDB to trace all thread stacks
214| showallgdbcorestacks Corefile equivalent of "showallgdbstacks"
215| kdp-reenter Schedule reentry into the debugger and continue.
216| kdp-reboot Restart remote target
b7266188
A
217| kdp-version Get KDP version number
218| kdp-connect "shorthand" connection macro
2d21ac55 219|
c910b4d9
A
220| zstack Print zalloc caller stack (zone leak debugging)
221| findoldest Find oldest zone leak debugging record
222| countpcs Print how often a pc occurs in the zone leak log
223|
b0d623f7
A
224| pmap_walk Perform a page-table walk
225| pmap_vtop Translate a virtual address to physical address
226|
227| showuserlibraries Show binary images known by dyld in the target task
228|
229| showthreadfortid Displays the address of the thread structure for a given thread_id value.
230|
231| strcmp_nomalloc A version of strcmp that avoids the use of malloc
232| through the use of encoded strings created via
233| strcmp_arg_pack64.
234| strcmp_arg_pack64 Pack a string into a 64-bit quantity for use by
235| strcmp_nomalloc
236|
237| pci_cfg_read8 Read 8-bits from a PCI config space register
238| pci_cfg_read16 Read 16-bits from a PCI config space register
239| pci_cfg_read32 Read 32-bits from a PCI config space register
240| pci_cfg_write8 Write 8-bits into a PCI config space register
241| pci_cfg_write16 Write 16-bits into a PCI config space register
242| pci_cfg_write32 Write 32-bits into a PCI config space register
243| pci_cfg_dump Dump entire config space for a PCI device
244| pci_cfg_scan Perform a scan for PCI devices
245| pci_cfg_dump_all Dump config spaces for all detected PCI devices
246|
247| lapic_read32 Read APIC entry
248| lapic_write32 Write APIC entry
249| lapic_dump Dump APIC entries
250|
251| ioapic_read32 Read IOAPIC entry
252| ioapic_write32 Write IOAPIC entry
253| ioapic_dump Dump IOAPIC entries
c910b4d9 254|
1c79356b
A
255| Type "help <macro>" for more specific help on a particular macro.
256| Type "show user <macro>" to see what the macro is really doing.
257end
258
0c530ab8
A
259# This macro should appear before any symbol references, to facilitate
260# a gdb "source" without a loaded symbol file.
261define showversion
b0d623f7 262 kdp-kernelversion
0c530ab8
A
263end
264
265document showversion
266Syntax: showversion
267| Read the kernel version string from a fixed address in low
268| memory. Useful if you don't know which kernel is on the other end,
269| and need to find the appropriate symbols. Beware that if you've
270| loaded a symbol file, but aren't connected to a remote target,
271| the version string from the symbol file will be displayed instead.
272| This macro expects to be connected to the remote kernel to function
273| correctly.
274end
275
b0d623f7
A
276set $kgm_mtype_ppc = 0x00000012
277set $kgm_mtype_arm = 0x0000000C
2d21ac55 278
b0d623f7
A
279set $kgm_mtype_i386 = 0x00000007
280set $kgm_mtype_x86_64 = 0x01000007
281set $kgm_mtype_x86_any = $kgm_mtype_i386
282set $kgm_mtype_x86_mask = 0xFEFFFFFF
283
284set $kgm_mtype = ((unsigned int *)&_mh_execute_header)[1]
285set $kgm_lp64 = $kgm_mtype & 0x01000000
2d21ac55 286
7e4a7d39
A
287set $kgm_manual_pkt_ppc = 0x549C
288set $kgm_manual_pkt_i386 = 0x249C
289set $kgm_manual_pkt_x86_64 = 0xFFFFFF8000002930
290set $kgm_manual_pkt_arm = 0xFFFF04A0
291
292set $kgm_kdp_pkt_data_len = 128
293
294# part of data packet
295set $kgm_kdp_pkt_hdr_req_off = 0
296set $kgm_kdp_pkt_hdr_seq_off = 1
297set $kgm_kdp_pkt_hdr_len_off = 2
298set $kgm_kdp_pkt_hdr_key_off = 4
299
300# after data packet
301set $kgm_kdp_pkt_len_off = $kgm_kdp_pkt_data_len
302set $kgm_kdp_pkt_input_off = $kgm_kdp_pkt_data_len + 4
303
304set $kgm_kdp_pkt_hostreboot = 0x13
305set $kgm_kdp_pkt_hdr_size = 8
306
b0d623f7 307set $kgm_lcpu_self = 0xFFFE
0c530ab8
A
308
309set $kgm_reg_depth = 0
b0d623f7
A
310set $kgm_reg_depth_max = 0xFFFF
311set $kgm_reg_plane = (IORegistryPlane *) gIOServicePlane
0c530ab8
A
312set $kgm_namekey = (OSSymbol *) 0
313set $kgm_childkey = (OSSymbol *) 0
314
315set $kgm_show_object_addrs = 0
316set $kgm_show_object_retain = 0
317set $kgm_show_props = 0
b0d623f7 318set $kgm_show_data_alwaysbytes = 0
1c79356b 319
2d21ac55
A
320set $kgm_show_kmod_syms = 0
321
7e4a7d39
A
322# send a manual packet header that doesn't require knowing the location
323# of everything.
324define manualhdrint
325 set $req = $arg0
326
327 set $hdrp = (uint32_t *) $kgm_manual_pkt_i386
328 if ($kgm_mtype == $kgm_mtype_ppc)
329 set $hdrp = (uint32_t *) $kgm_manual_pkt_ppc
330 set $req = $req << 1 # shift to deal with endiannness
331 end
332 if ($kgm_mtype == $kgm_mtype_x86_64)
333 set $hdrp = (uint64_t *) $kgm_manual_pkt_x86_64
334 end
335 if ($kgm_mtype == $kgm_mtype_arm)
336 set $hdrp = (uint32_t *) $kgm_manual_pkt_arm
337 end
338
339 set $pkt_hdr = *$hdrp
340 set *((uint8_t *) ($pkt_hdr + $kgm_kdp_pkt_input_off)) = 0
341 set *((uint32_t *) ($pkt_hdr + $kgm_kdp_pkt_len_off)) = $kgm_kdp_pkt_hdr_size
342
343 set *((uint8_t *) ($pkt_hdr + $kgm_kdp_pkt_hdr_req_off)) = $req
344 set *((uint8_t *) ($pkt_hdr + $kgm_kdp_pkt_hdr_seq_off)) = 0
345 set *((uint16_t *) ($pkt_hdr + $kgm_kdp_pkt_hdr_len_off)) = $kgm_kdp_pkt_hdr_size
346 set *((uint32_t *) ($pkt_hdr + $kgm_kdp_pkt_hdr_key_off)) = 0
347 set *((uint8_t *) ($pkt_hdr + $kgm_kdp_pkt_input_off)) = 1
348
349 # dummy to make sure manual packet is executed
350 set $kgm_dummy = &_mh_execute_header
351end
352
b0d623f7
A
353# Print a pointer
354define showptr
355 if $kgm_lp64
356 printf "0x%016llx", $arg0
357 else
358 printf "0x%08x", $arg0
359 end
360end
361
362# for headers, leave 8 chars for LP64 pointers
363define showptrhdrpad
364 if $kgm_lp64
365 printf " "
366 end
367end
368
1c79356b 369define showkmodheader
b0d623f7
A
370 printf "kmod "
371 showptrhdrpad
372 printf " address "
373 showptrhdrpad
374 printf " size "
375 showptrhdrpad
376 printf " id refs version name\n"
1c79356b
A
377end
378
379define showkmodint
380 set $kgm_kmodp = (struct kmod_info *)$arg0
b0d623f7
A
381 showptr $kgm_kmodp
382 printf " "
383 showptr $kgm_kmodp->address
384 printf " "
385 showptr $kgm_kmodp->size
386 printf " "
1c79356b
A
387 printf "%3d ", $kgm_kmodp->id
388 printf "%5d ", $kgm_kmodp->reference_count
b0d623f7
A
389 printf "%10s ", $kgm_kmodp->version
390 printf "%s\n", $kgm_kmodp->name
1c79356b
A
391end
392
b0d623f7 393# cached info of the last kext found, to speed up subsequent lookups
1c79356b
A
394set $kgm_pkmod = 0
395set $kgm_pkmodst = 0
396set $kgm_pkmoden = 0
b0d623f7 397
0c530ab8 398define showkmodaddrint
b0d623f7
A
399 showptr $arg0
400 if ((unsigned long)$arg0 >= (unsigned long)$kgm_pkmodst) && ((unsigned long)$arg0 < (unsigned long)$kgm_pkmoden)
401 set $kgm_off = ((unsigned long)$arg0 - (unsigned long)$kgm_pkmodst)
1c79356b
A
402 printf " <%s + 0x%x>", $kgm_pkmod->name, $kgm_off
403 else
b0d623f7
A
404 set $kgm_kmodp = (struct kmod_info *)kmod
405 if ($kgm_mtype == $kgm_mtype_x86_64) && ($arg0 >= (unsigned long)&_mh_execute_header)
406 # kexts are loaded below the kernel for x86_64
407 set $kgm_kmodp = 0
408 end
409 while $kgm_kmodp
410 set $kgm_off = ((unsigned long)$arg0 - (unsigned long)$kgm_kmodp->address)
411 if ($kgm_kmodp->address <= $arg0) && ($kgm_off < $kgm_kmodp->size)
412 printf " <%s + 0x%x>", $kgm_kmodp->name, $kgm_off
413 set $kgm_pkmod = $kgm_kmodp
414 set $kgm_pkmodst = $kgm_kmodp->address
415 set $kgm_pkmoden = $kgm_pkmodst + $kgm_kmodp->size
416 set $kgm_kmodp = 0
417 else
418 set $kgm_kmodp = $kgm_kmodp->next
1c79356b
A
419 end
420 end
421 end
422end
0c530ab8
A
423
424define showkmodaddr
425 showkmodaddrint $arg0
0c530ab8
A
426end
427
1c79356b 428document showkmodaddr
2d21ac55 429Syntax: (gdb) showkmodaddr <addr>
1c79356b 430| Given an address, print the offset and name for the kmod containing it
1c79356b
A
431end
432
433define showkmod
434 showkmodheader
435 showkmodint $arg0
436end
437document showkmod
2d21ac55 438Syntax: (gdb) showkmod <kmod>
1c79356b 439| Routine to print info about a kernel module
1c79356b
A
440end
441
442define showallkmods
443 showkmodheader
444 set $kgm_kmodp = (struct kmod_info *)kmod
445 while $kgm_kmodp
446 showkmodint $kgm_kmodp
447 set $kgm_kmodp = $kgm_kmodp->next
448 end
449end
450document showallkmods
2d21ac55 451Syntax: (gdb) showallkmods
1c79356b 452| Routine to print a summary listing of all the kernel modules
1c79356b
A
453end
454
455define showactheader
b0d623f7
A
456 printf " "
457 showptrhdrpad
458 printf " thread "
459 showptrhdrpad
460 printf " thread_id "
461 showptrhdrpad
462 printf " processor "
463 showptrhdrpad
464 printf " pri io_policy state wait_queue"
465 showptrhdrpad
466 printf " wait_event\n"
1c79356b
A
467end
468
469
470define showactint
b0d623f7
A
471 printf " "
472 showptrhdrpad
91447636 473 set $kgm_thread = *(struct thread *)$arg0
b0d623f7
A
474 showptr $arg0
475 if ($kgm_thread.static_param)
476 printf "[WQ]"
477 else
478 printf " "
479 end
480 printf " %7ld ", $kgm_thread.thread_id
481 showptr $kgm_thread.last_processor
482 printf " %3d ", $kgm_thread.sched_pri
483 if ($kgm_thread.uthread != 0)
484 set $kgm_printed = 0
485 set $kgm_uthread = (struct uthread *)$kgm_thread.uthread
486 if ($kgm_uthread->uu_flag & 0x400)
487 printf "RAGE "
488 else
489 printf " "
490 end
491 if ($kgm_uthread->uu_iopol_disk == 1)
492 printf "NORM "
493 set $kgm_printed = 1
494 end
495 if ($kgm_uthread->uu_iopol_disk == 2)
496 printf "PASS "
497 set $kgm_printed = 1
498 end
499 if ($kgm_uthread->uu_iopol_disk == 3)
500 printf "THROT "
501 set $kgm_printed = 1
502 end
503 if ($kgm_printed == 0)
504 printf " "
505 end
506 end
1c79356b
A
507 set $kgm_state = $kgm_thread.state
508 if $kgm_state & 0x80
509 printf "I"
510 end
511 if $kgm_state & 0x40
512 printf "P"
513 end
514 if $kgm_state & 0x20
515 printf "A"
516 end
517 if $kgm_state & 0x10
518 printf "H"
519 end
520 if $kgm_state & 0x08
521 printf "U"
522 end
523 if $kgm_state & 0x04
524 printf "R"
525 end
526 if $kgm_state & 0x02
527 printf "S"
528 end
529 if $kgm_state & 0x01
b0d623f7
A
530 printf "W"
531 printf "\t "
532 showptr $kgm_thread.wait_queue
533 printf " "
534 if (((unsigned long)$kgm_thread.wait_event > (unsigned long)&last_kernel_symbol) \
2d21ac55 535 && ($arg1 != 2) && ($kgm_show_kmod_syms == 0))
0c530ab8
A
536 showkmodaddr $kgm_thread.wait_event
537 else
b0d623f7 538 output /a $kgm_thread.wait_event
91447636 539 end
2d21ac55
A
540 if ($kgm_thread.uthread != 0)
541 set $kgm_uthread = (struct uthread *)$kgm_thread.uthread
542 if ($kgm_uthread->uu_wmesg != 0)
b0d623f7 543 printf "\t \"%s\"", $kgm_uthread->uu_wmesg
2d21ac55
A
544 end
545 end
1c79356b
A
546 end
547 if $arg1 != 0
548 if ($kgm_thread.kernel_stack != 0)
55e303ae 549 if ($kgm_thread.reserved_stack != 0)
b0d623f7
A
550 printf "\n "
551 showptrhdrpad
552 printf " reserved_stack="
553 showptr $kgm_thread.reserved_stack
1c79356b 554 end
b0d623f7
A
555 printf "\n "
556 showptrhdrpad
557 printf " kernel_stack="
558 showptr $kgm_thread.kernel_stack
559 if ($kgm_mtype == $kgm_mtype_ppc)
91447636 560 set $mysp = $kgm_thread.machine.pcb->save_r1
2d21ac55 561 end
b0d623f7
A
562 if (($kgm_mtype & $kgm_mtype_x86_mask) == $kgm_mtype_x86_any)
563 set $kgm_statep = (struct x86_kernel_state *) \
564 ($kgm_thread->kernel_stack + kernel_stack_size \
565 - sizeof(struct x86_kernel_state))
566 if ($kgm_mtype == $kgm_mtype_i386)
567 set $mysp = $kgm_statep->k_ebp
568 else
569 set $mysp = $kgm_statep->k_rbp
570 end
55e303ae 571 end
b0d623f7
A
572 if ($kgm_mtype == $kgm_mtype_arm)
573 if (((unsigned long)$r7 < ((unsigned long) ($kgm_thread->kernel_stack+kernel_stack_size))) \
574 && ((unsigned long)$r7 > (unsigned long) ($kgm_thread->kernel_stack)))
2d21ac55
A
575 set $mysp = $r7
576 else
577 set $kgm_statep = (struct arm_saved_state *)$kgm_thread.machine.kstackptr
578 set $mysp = $kgm_statep->r[7]
579 end
580 end
0c530ab8 581 set $prevsp = $mysp - 16
b0d623f7
A
582 printf "\n "
583 showptrhdrpad
584 printf " stacktop="
585 showptr $mysp
586 if ($kgm_mtype == $kgm_mtype_ppc)
91447636 587 set $stkmask = 0xf
91447636
A
588 else
589 set $stkmask = 0x3
91447636 590 end
0c530ab8 591 set $kgm_return = 0
060df5ea 592 set $kgm_actint_framecount = 0
91447636 593 while ($mysp != 0) && (($mysp & $stkmask) == 0) \
0c530ab8 594 && ($mysp != $prevsp) \
b0d623f7
A
595 && ((((unsigned long) $mysp ^ (unsigned long) $prevsp) < 0x2000) \
596 || (((unsigned long)$mysp < ((unsigned long) ($kgm_thread->kernel_stack+kernel_stack_size))) \
060df5ea
A
597 && ((unsigned long)$mysp > (unsigned long) ($kgm_thread->kernel_stack)))) \
598 && ($kgm_actint_framecount < 128)
b0d623f7 599 printf "\n "
060df5ea 600 set $kgm_actint_framecount = $kgm_actint_framecount + 1
b0d623f7
A
601 showptrhdrpad
602 printf " "
603 showptr $mysp
604 printf " "
605 if ($kgm_mtype == $kgm_mtype_ppc)
91447636 606 set $kgm_return = *($mysp + 8)
2d21ac55 607 end
b0d623f7 608 if ($kgm_mtype == $kgm_mtype_i386)
2d21ac55
A
609 set $kgm_return = *($mysp + 4)
610 end
b0d623f7
A
611 if ($kgm_mtype == $kgm_mtype_x86_64)
612 set $kgm_return = *(unsigned long *)($mysp + 8)
613 end
614 if ($kgm_mtype == $kgm_mtype_arm)
91447636
A
615 set $kgm_return = *($mysp + 4)
616 end
b0d623f7
A
617 if (((unsigned long) $kgm_return < (unsigned long) &_mh_execute_header || \
618 (unsigned long) $kgm_return >= (unsigned long) &last_kernel_symbol ) \
2d21ac55
A
619 && ($kgm_show_kmod_syms == 0))
620 showkmodaddr $kgm_return
621 else
b0d623f7 622 output /a $kgm_return
2d21ac55 623 end
91447636 624 set $prevsp = $mysp
b0d623f7 625 set $mysp = *(unsigned long *)$mysp
1c79356b 626 end
0c530ab8 627 set $kgm_return = 0
b0d623f7
A
628 printf "\n "
629 showptrhdrpad
630 printf " stackbottom="
631 showptr $prevsp
1c79356b 632 else
b0d623f7
A
633 printf "\n "
634 showptrhdrpad
635 printf " continuation="
636 output /a $kgm_thread.continuation
1c79356b
A
637 end
638 printf "\n"
639 else
640 printf "\n"
641 end
1c79356b
A
642end
643
644define showact
645 showactheader
646 showactint $arg0 0
647end
648document showact
2d21ac55 649Syntax: (gdb) showact <activation>
55e303ae 650| Routine to print out the state of a specific thread.
1c79356b
A
651end
652
653
654define showactstack
655 showactheader
656 showactint $arg0 1
657end
658document showactstack
2d21ac55 659Syntax: (gdb) showactstack <activation>
55e303ae 660| Routine to print out the stack of a specific thread.
1c79356b
A
661end
662
663
55e303ae 664define showallthreads
2d21ac55 665 set $kgm_head_taskp = &tasks
9bccf70c 666 set $kgm_taskp = (struct task *)($kgm_head_taskp->next)
1c79356b
A
667 while $kgm_taskp != $kgm_head_taskp
668 showtaskheader
669 showtaskint $kgm_taskp
670 showactheader
55e303ae
A
671 set $kgm_head_actp = &($kgm_taskp->threads)
672 set $kgm_actp = (struct thread *)($kgm_taskp->threads.next)
1c79356b
A
673 while $kgm_actp != $kgm_head_actp
674 showactint $kgm_actp 0
55e303ae 675 set $kgm_actp = (struct thread *)($kgm_actp->task_threads.next)
1c79356b
A
676 end
677 printf "\n"
2d21ac55 678 set $kgm_taskp = (struct task *)($kgm_taskp->tasks.next)
1c79356b
A
679 end
680end
55e303ae 681document showallthreads
2d21ac55 682Syntax: (gdb) showallthreads
55e303ae 683| Routine to print out info about all threads in the system.
55e303ae
A
684end
685
686define showcurrentthreads
2d21ac55 687set $kgm_prp = (struct processor *)processor_list
91447636 688 while $kgm_prp != 0
b0d623f7 689 printf "Processor 0x%08x State %d (cpu_id %x)\n", $kgm_prp, ($kgm_prp)->state, ($kgm_prp)->cpu_id
91447636
A
690 if ($kgm_prp)->active_thread != 0
691 set $kgm_actp = ($kgm_prp)->active_thread
55e303ae
A
692 showtaskheader
693 showtaskint ($kgm_actp)->task
694 showactheader
695 showactint $kgm_actp 0
696 printf "\n"
697 end
91447636 698 set $kgm_prp = ($kgm_prp)->processor_list
55e303ae
A
699 end
700end
701document showcurrentthreads
2d21ac55 702Syntax: (gdb) showcurrentthreads
55e303ae 703| Routine to print out info about the thread running on each cpu.
1c79356b
A
704end
705
0c530ab8 706set $decode_wait_events = 0
1c79356b 707define showallstacks
2d21ac55 708 set $kgm_head_taskp = &tasks
9bccf70c 709 set $kgm_taskp = (struct task *)($kgm_head_taskp->next)
1c79356b
A
710 while $kgm_taskp != $kgm_head_taskp
711 showtaskheader
712 showtaskint $kgm_taskp
55e303ae
A
713 set $kgm_head_actp = &($kgm_taskp->threads)
714 set $kgm_actp = (struct thread *)($kgm_taskp->threads.next)
1c79356b
A
715 while $kgm_actp != $kgm_head_actp
716 showactheader
0c530ab8
A
717 if ($decode_wait_events > 0)
718 showactint $kgm_actp 1
719 else
720 showactint $kgm_actp 2
721 end
55e303ae 722 set $kgm_actp = (struct thread *)($kgm_actp->task_threads.next)
1c79356b
A
723 end
724 printf "\n"
2d21ac55 725 set $kgm_taskp = (struct task *)($kgm_taskp->tasks.next)
1c79356b
A
726 end
727end
0c530ab8 728
1c79356b 729document showallstacks
2d21ac55 730Syntax: (gdb) showallstacks
55e303ae 731| Routine to print out the stack for each thread in the system.
0c530ab8
A
732| If the variable $decode_wait_events is non-zero, the routine attempts to
733| interpret thread wait_events as kernel module offsets, which can add to
734| processing time.
1c79356b
A
735end
736
55e303ae 737define showcurrentstacks
91447636
A
738set $kgm_prp = processor_list
739 while $kgm_prp != 0
b0d623f7 740 printf "Processor 0x%08x State %d (cpu_id %x)\n", $kgm_prp, ($kgm_prp)->state, ($kgm_prp)->cpu_id
91447636
A
741 if ($kgm_prp)->active_thread != 0
742 set $kgm_actp = ($kgm_prp)->active_thread
55e303ae
A
743 showtaskheader
744 showtaskint ($kgm_actp)->task
745 showactheader
746 showactint $kgm_actp 1
747 printf "\n"
748 end
91447636 749 set $kgm_prp = ($kgm_prp)->processor_list
55e303ae
A
750 end
751end
0c530ab8 752
55e303ae 753document showcurrentstacks
2d21ac55 754Syntax: (gdb) showcurrentstacks
55e303ae 755| Routine to print out the thread running on each cpu (incl. its stack)
55e303ae
A
756end
757
9bccf70c 758define showwaiterheader
b0d623f7
A
759 printf "waiters thread "
760 printf "processor pri state wait_queue wait_event\n"
9bccf70c
A
761end
762
763define showwaitqwaiters
b0d623f7 764 set $kgm_w_waitqp = (WaitQueue*)$arg0
9bccf70c 765 set $kgm_w_linksp = &($kgm_w_waitqp->wq_queue)
b0d623f7 766 set $kgm_w_wqe = (WaitQueueElement *)$kgm_w_linksp->next
9bccf70c
A
767 set $kgm_w_found = 0
768 while ( (queue_entry_t)$kgm_w_wqe != (queue_entry_t)$kgm_w_linksp)
769 if ($kgm_w_wqe->wqe_type != &_wait_queue_link)
770 if !$kgm_w_found
771 set $kgm_w_found = 1
772 showwaiterheader
773 end
55e303ae 774 set $kgm_w_shuttle = (struct thread *)$kgm_w_wqe
91447636 775 showactint $kgm_w_shuttle 0
9bccf70c 776 end
b0d623f7 777 set $kgm_w_wqe = (WaitQueueElement *)$kgm_w_wqe->wqe_links.next
9bccf70c
A
778 end
779end
780
781define showwaitqwaitercount
b0d623f7 782 set $kgm_wc_waitqp = (WaitQueue*)$arg0
9bccf70c 783 set $kgm_wc_linksp = &($kgm_wc_waitqp->wq_queue)
b0d623f7 784 set $kgm_wc_wqe = (WaitQueueElement *)$kgm_wc_linksp->next
9bccf70c
A
785 set $kgm_wc_count = 0
786 while ( (queue_entry_t)$kgm_wc_wqe != (queue_entry_t)$kgm_wc_linksp)
0b4c1975 787 if ($kgm_wc_wqe->wqe_type != &_wait_queue_link) && ($kgm_wc_wqe->wqe_type != &_wait_queue_link_noalloc)
9bccf70c
A
788 set $kgm_wc_count = $kgm_wc_count + 1
789 end
b0d623f7 790 set $kgm_wc_wqe = (WaitQueueElement *)$kgm_wc_wqe->wqe_links.next
9bccf70c
A
791 end
792 printf "0x%08x ", $kgm_wc_count
793end
794
1c79356b 795define showwaitqmembercount
0b4c1975 796 set $kgm_mc_waitqsetp = (struct wait_queue_set *)$arg0
9bccf70c 797 set $kgm_mc_setlinksp = &($kgm_mc_waitqsetp->wqs_setlinks)
b0d623f7 798 set $kgm_mc_wql = (WaitQueueLink *)$kgm_mc_setlinksp->next
9bccf70c
A
799 set $kgm_mc_count = 0
800 while ( (queue_entry_t)$kgm_mc_wql != (queue_entry_t)$kgm_mc_setlinksp)
801 set $kgm_mc_count = $kgm_mc_count + 1
b0d623f7 802 set $kgm_mc_wql = (WaitQueueLink *)$kgm_mc_wql->wql_setlinks.next
1c79356b 803 end
9bccf70c 804 printf "0x%08x ", $kgm_mc_count
1c79356b
A
805end
806
807
9bccf70c
A
808define showwaitqmemberheader
809 printf "set-members wait_queue interlock "
810 printf "pol type member_cnt waiter_cnt\n"
811end
812
1c79356b 813define showwaitqmemberint
b0d623f7 814 set $kgm_m_waitqp = (WaitQueue*)$arg0
9bccf70c
A
815 printf " 0x%08x ", $kgm_m_waitqp
816 printf "0x%08x ", $kgm_m_waitqp->wq_interlock.lock_data
817 if ($kgm_m_waitqp->wq_fifo)
818 printf "Fifo "
1c79356b 819 else
9bccf70c 820 printf "Prio "
1c79356b 821 end
9bccf70c
A
822 if ($kgm_m_waitqp->wq_type == 0xf1d1)
823 printf "Set "
824 showwaitqmembercount $kgm_m_waitqp
1c79356b 825 else
9bccf70c 826 printf "Que 0x00000000 "
1c79356b 827 end
9bccf70c 828 showwaitqwaitercount $kgm_m_waitqp
1c79356b
A
829 printf "\n"
830end
831
832
9bccf70c
A
833define showwaitqmemberofheader
834 printf "member-of wait_queue interlock "
835 printf "pol type member_cnt waiter_cnt\n"
836end
837
838define showwaitqmemberof
b0d623f7 839 set $kgm_mo_waitqp = (WaitQueue*)$arg0
9bccf70c 840 set $kgm_mo_linksp = &($kgm_mo_waitqp->wq_queue)
b0d623f7 841 set $kgm_mo_wqe = (WaitQueueElement *)$kgm_mo_linksp->next
9bccf70c
A
842 set $kgm_mo_found = 0
843 while ( (queue_entry_t)$kgm_mo_wqe != (queue_entry_t)$kgm_mo_linksp)
844 if ($kgm_mo_wqe->wqe_type == &_wait_queue_link)
845 if !$kgm_mo_found
846 set $kgm_mo_found = 1
847 showwaitqmemberofheader
848 end
b0d623f7
A
849 set $kgm_mo_wqlp = (WaitQueueLink *)$kgm_mo_wqe
850 set $kgm_mo_wqsetp = (WaitQueue*)($kgm_mo_wqlp->wql_setqueue)
9bccf70c
A
851 showwaitqmemberint $kgm_mo_wqsetp
852 end
b0d623f7 853 set $kgm_mo_wqe = (WaitQueueElement *)$kgm_mo_wqe->wqe_links.next
9bccf70c
A
854 end
855end
856
1c79356b 857define showwaitqmembers
0b4c1975 858 set $kgm_ms_waitqsetp = (struct wait_queue_set *)$arg0
9bccf70c 859 set $kgm_ms_setlinksp = &($kgm_ms_waitqsetp->wqs_setlinks)
b0d623f7 860 set $kgm_ms_wql = (WaitQueueLink *)$kgm_ms_setlinksp->next
9bccf70c
A
861 set $kgm_ms_found = 0
862 while ( (queue_entry_t)$kgm_ms_wql != (queue_entry_t)$kgm_ms_setlinksp)
863 set $kgm_ms_waitqp = $kgm_ms_wql->wql_element.wqe_queue
864 if !$kgm_ms_found
1c79356b 865 showwaitqmemberheader
9bccf70c 866 set $kgm_ms_found = 1
1c79356b 867 end
9bccf70c 868 showwaitqmemberint $kgm_ms_waitqp
b0d623f7 869 set $kgm_ms_wql = (WaitQueueLink *)$kgm_ms_wql->wql_setlinks.next
1c79356b
A
870 end
871end
872
9bccf70c 873define showwaitqheader
0b4c1975 874 printf "wait_queue prepostq interlock "
9bccf70c
A
875 printf "pol type member_cnt waiter_cnt\n"
876end
877
878define showwaitqint
0b4c1975 879 set $kgm_waitqp = (WaitQueue *)$arg0
9bccf70c
A
880 printf "0x%08x ", $kgm_waitqp
881 if ($kgm_waitqp->wq_type == 0xf1d1)
0b4c1975 882 printf "0x%08x ", &((struct wait_queue_set *)$kgm_waitqp)->wqs_preposts
9bccf70c
A
883 else
884 printf "0x00000000 "
885 end
886 printf "0x%08x ", $kgm_waitqp->wq_interlock.lock_data
887 if ($kgm_waitqp->wq_fifo)
888 printf "Fifo "
889 else
890 printf "Prio "
891 end
892 if ($kgm_waitqp->wq_type == 0xf1d1)
893 printf "Set "
894 showwaitqmembercount $kgm_waitqp
895 else
896 printf "Que 0x00000000 "
897 end
898 showwaitqwaitercount $kgm_waitqp
899 printf "\n"
900end
901
1c79356b 902define showwaitq
b0d623f7 903 set $kgm_waitq1p = (WaitQueue*)$arg0
1c79356b 904 showwaitqheader
9bccf70c
A
905 showwaitqint $kgm_waitq1p
906 if ($kgm_waitq1p->wq_type == 0xf1d1)
907 showwaitqmembers $kgm_waitq1p
908 else
909 showwaitqmemberof $kgm_waitq1p
1c79356b 910 end
9bccf70c 911 showwaitqwaiters $kgm_waitq1p
1c79356b
A
912end
913
914define showmapheader
b0d623f7
A
915 printf "vm_map "
916 showptrhdrpad
917 printf " pmap "
918 showptrhdrpad
919 printf " vm_size "
920 showptrhdrpad
921 printf " #ents rpage hint "
922 showptrhdrpad
923 printf " first_free\n"
1c79356b
A
924end
925
926define showvmeheader
b0d623f7
A
927 printf " entry "
928 showptrhdrpad
929 printf " start prot #page object "
930 showptrhdrpad
931 printf " offset\n"
1c79356b
A
932end
933
934define showvmint
935 set $kgm_mapp = (vm_map_t)$arg0
936 set $kgm_map = *$kgm_mapp
b0d623f7
A
937 showptr $arg0
938 printf " "
939 showptr $kgm_map.pmap
940 printf " "
941 showptr $kgm_map.size
942 printf " %3d ", $kgm_map.hdr.nentries
91447636
A
943 if $kgm_map.pmap
944 printf "%5d ", $kgm_map.pmap->stats.resident_count
945 else
946 printf "<n/a> "
947 end
b0d623f7
A
948 showptr $kgm_map.hint
949 printf " "
950 showptr $kgm_map.first_free
951 printf "\n"
1c79356b 952 if $arg1 != 0
b0d623f7
A
953 showvmeheader
954 set $kgm_head_vmep = &($kgm_mapp->hdr.links)
955 set $kgm_vmep = $kgm_map.hdr.links.next
956 while (($kgm_vmep != 0) && ($kgm_vmep != $kgm_head_vmep))
957 set $kgm_vme = *$kgm_vmep
958 printf " "
959 showptr $kgm_vmep
960 printf " 0x%016llx ", $kgm_vme.links.start
961 printf "%1x", $kgm_vme.protection
962 printf "%1x", $kgm_vme.max_protection
963 if $kgm_vme.inheritance == 0x0
964 printf "S"
965 end
966 if $kgm_vme.inheritance == 0x1
967 printf "C"
968 end
969 if $kgm_vme.inheritance == 0x2
970 printf "-"
971 end
972 if $kgm_vme.inheritance == 0x3
973 printf "D"
974 end
975 if $kgm_vme.is_sub_map
976 printf "s "
977 else
978 if $kgm_vme.needs_copy
979 printf "n "
980 else
981 printf " "
982 end
983 end
984 printf "%6d ",($kgm_vme.links.end - $kgm_vme.links.start) >> 12
985 showptr $kgm_vme.object.vm_object
986 printf " 0x%016llx\n", $kgm_vme.offset
987 set $kgm_vmep = $kgm_vme.links.next
1c79356b
A
988 end
989 end
990 printf "\n"
991end
992
993
0b4c1975
A
994define showmapwiredp
995 set $kgm_mapp = (vm_map_t)$arg0
996 set $kgm_map = *$kgm_mapp
997 set $kgm_head_vmep = &($kgm_mapp->hdr.links)
998 set $kgm_vmep = $kgm_map.hdr.links.next
999 set $kgm_objp_prev = (struct vm_object *)0
1000 if $arg1 == 0
1001 set $kgm_saw_kernel_obj = 0
1002 set $kgm_wired_count = 0
1003 set $kgm_objp_print_space = 1
1004 else
1005 set $kgm_objp_print_space = 0
1006 end
1007 while (($kgm_vmep != 0) && ($kgm_vmep != $kgm_head_vmep))
1008 set $kgm_vme = *$kgm_vmep
1009 set $kgm_objp = $kgm_vme.object.vm_object
1010 if $kgm_vme.is_sub_map
1011 if $arg1 == 0
1012 set $kgm_mapp_orig = $kgm_mapp
1013 set $kgm_vmep_orig = $kgm_vmep
1014 set $kgm_vme_orig = $kgm_vme
1015 set $kgm_head_vmep_orig = $kgm_head_vmep
1016 printf "\n****"
1017 showptr $kgm_objp
1018 showmapwiredp $kgm_objp 1
1019 set $kgm_vme = $kgm_vme_orig
1020 set $kgm_vmep = $kgm_vmep_orig
1021 set $kgm_mapp = $kgm_mapp_orig
1022 set $kgm_head_vmep = $kgm_head_vmep_orig
1023 set $kgm_objp = (struct vm_object *)0
1024 else
1025 printf "\n????"
1026 showptr $kgm_mapp
1027 printf " "
1028 showptr $kgm_vmep
1029 set $kgm_objp = (struct vm_object *)0
1030 printf "\n"
1031 end
1032 end
1033 if ($kgm_objp == $kgm_objp_prev)
1034 set $kgm_objp = (struct vm_object *)0
1035 end
1036 if $kgm_objp == kernel_object
1037 if $kgm_saw_kernel_obj
1038 set $kgm_objp = (struct vm_object *)0
1039 end
1040 set $kgm_saw_kernel_obj = 1
1041 end
1042 if $kgm_objp && $kgm_objp->wired_page_count
1043 if $kgm_objp_print_space == 1
1044 printf " "
1045 showptr $kgm_mapp
1046 end
1047 set $kgm_objp_print_space = 1
1048 printf " "
1049 showptr $kgm_vmep
1050 printf " 0x%016llx ", $kgm_vme.links.start
1051 printf "%5d", $kgm_vme.alias
1052 printf "%6d ",($kgm_vme.links.end - $kgm_vme.links.start) >> 12
1053 showptr $kgm_objp
1054 printf "[%3d]", $kgm_objp->ref_count
1055 printf "%7d\n", $kgm_objp->wired_page_count
1056 set $kgm_wired_count = $kgm_wired_count + $kgm_objp->wired_page_count
1057 set $kgm_objp_prev = $kgm_objp
1058 end
1059 set $kgm_vmep = $kgm_vme.links.next
1060 end
1061 if $arg1 == 0
1062 printf "total wired count = %d\n", $kgm_wired_count
1063 end
1064end
1065
1066define showmapwired
1067 printf " map "
1068 showptrhdrpad
1069 printf " entry "
1070 showptrhdrpad
1071 printf " start alias #page object "
1072 showptrhdrpad
1073 printf " wired\n"
1074 showmapwiredp $arg0 0
1075end
1076document showmapwired
1077Syntax: (gdb) showmapwired <vm_map>
1078| Routine to print out a summary listing of all the entries with wired pages in a vm_map
1079end
1080
1c79356b
A
1081define showmapvme
1082 showmapheader
1083 showvmint $arg0 1
1084end
1085document showmapvme
2d21ac55 1086Syntax: (gdb) showmapvme <vm_map>
1c79356b 1087| Routine to print out a summary listing of all the entries in a vm_map
1c79356b
A
1088end
1089
1090
1091define showmap
1092 showmapheader
1093 showvmint $arg0 0
1094end
1095document showmap
2d21ac55 1096Syntax: (gdb) showmap <vm_map>
55e303ae 1097| Routine to print out info about the specified vm_map
1c79356b
A
1098end
1099
1100define showallvm
2d21ac55 1101 set $kgm_head_taskp = &tasks
9bccf70c 1102 set $kgm_taskp = (struct task *)($kgm_head_taskp->next)
1c79356b
A
1103 while $kgm_taskp != $kgm_head_taskp
1104 showtaskheader
1105 showmapheader
1106 showtaskint $kgm_taskp
1107 showvmint $kgm_taskp->map 0
2d21ac55 1108 set $kgm_taskp = (struct task *)($kgm_taskp->tasks.next)
1c79356b
A
1109 end
1110end
1111document showallvm
2d21ac55 1112Syntax: (gdb) showallvm
1c79356b 1113| Routine to print a summary listing of all the vm maps
1c79356b
A
1114end
1115
1116
1117define showallvme
2d21ac55 1118 set $kgm_head_taskp = &tasks
9bccf70c 1119 set $kgm_taskp = (struct task *)($kgm_head_taskp->next)
1c79356b
A
1120 while $kgm_taskp != $kgm_head_taskp
1121 showtaskheader
1122 showmapheader
1123 showtaskint $kgm_taskp
1124 showvmint $kgm_taskp->map 1
2d21ac55 1125 set $kgm_taskp = (struct task *)($kgm_taskp->tasks.next)
1c79356b
A
1126 end
1127end
1128document showallvme
2d21ac55 1129Syntax: (gdb) showallvme
1c79356b 1130| Routine to print a summary listing of all the vm map entries
1c79356b
A
1131end
1132
1133
1134define showipcheader
b0d623f7
A
1135 printf "ipc_space "
1136 showptrhdrpad
1137 printf " is_table "
1138 showptrhdrpad
1139 printf " table_next"
1140 showptrhdrpad
1141 printf " flags tsize splaytree splaybase\n"
1c79356b
A
1142end
1143
1144define showipceheader
b0d623f7
A
1145 printf " name object "
1146 showptrhdrpad
1147 printf " rite urefs destname destination\n"
1c79356b
A
1148end
1149
1150define showipceint
1151 set $kgm_ie = *(ipc_entry_t)$arg0
1152 printf " 0x%08x ", $arg1
b0d623f7
A
1153 showptr $kgm_ie.ie_object
1154 printf " "
1c79356b 1155 if $kgm_ie.ie_bits & 0x00100000
b0d623f7 1156 printf "Dead "
1c79356b
A
1157 printf "%5d\n", $kgm_ie.ie_bits & 0xffff
1158 else
1159 if $kgm_ie.ie_bits & 0x00080000
b0d623f7 1160 printf "SET "
1c79356b
A
1161 printf "%5d\n", $kgm_ie.ie_bits & 0xffff
1162 else
1163 if $kgm_ie.ie_bits & 0x00010000
b0d623f7
A
1164 if $kgm_ie.ie_bits & 0x00020000
1165 printf " SR"
1166 else
1167 printf " S"
1168 end
1c79356b 1169 else
b0d623f7
A
1170 if $kgm_ie.ie_bits & 0x00020000
1171 printf " R"
1172 end
1c79356b
A
1173 end
1174 if $kgm_ie.ie_bits & 0x00040000
b0d623f7 1175 printf " O"
1c79356b
A
1176 end
1177 if $kgm_ie.index.request
b0d623f7 1178 printf "n"
1c79356b
A
1179 else
1180 printf " "
1181 end
1182 if $kgm_ie.ie_bits & 0x00800000
b0d623f7 1183 printf "c"
1c79356b 1184 else
b0d623f7 1185 printf " "
1c79356b
A
1186 end
1187 printf "%5d ", $kgm_ie.ie_bits & 0xffff
1188 showportdest $kgm_ie.ie_object
1189 end
1190 end
1191end
1192
1193define showipcint
1194 set $kgm_isp = (ipc_space_t)$arg0
1195 set $kgm_is = *$kgm_isp
b0d623f7
A
1196 showptr $arg0
1197 printf " "
1198 showptr $kgm_is.is_table
1199 printf " "
1200 showptr $kgm_is.is_table_next
1201 printf " "
1c79356b 1202 if $kgm_is.is_growing != 0
b0d623f7 1203 printf "G"
1c79356b 1204 else
b0d623f7 1205 printf " "
1c79356b
A
1206 end
1207 if $kgm_is.is_fast != 0
b0d623f7 1208 printf "F"
1c79356b 1209 else
b0d623f7 1210 printf " "
1c79356b
A
1211 end
1212 if $kgm_is.is_active != 0
b0d623f7 1213 printf "A "
1c79356b 1214 else
b0d623f7 1215 printf " "
1c79356b
A
1216 end
1217 printf "%5d ", $kgm_is.is_table_size
1218 printf "0x%08x ", $kgm_is.is_tree_total
b0d623f7
A
1219 showptr &$kgm_isp->is_tree
1220 printf "\n"
1c79356b 1221 if $arg1 != 0
b0d623f7
A
1222 showipceheader
1223 set $kgm_iindex = 0
1224 set $kgm_iep = $kgm_is.is_table
1225 set $kgm_destspacep = (ipc_space_t)0
1c79356b 1226 while ( $kgm_iindex < $kgm_is.is_table_size )
b0d623f7
A
1227 set $kgm_ie = *$kgm_iep
1228 if $kgm_ie.ie_bits & 0x001f0000
1229 set $kgm_name = (($kgm_iindex << 8)|($kgm_ie.ie_bits >> 24))
1230 showipceint $kgm_iep $kgm_name
0b4c1975
A
1231 if $arg2 != 0 && ipc_portbt != 0
1232 if $kgm_ie.ie_object != 0 && ($kgm_ie.ie_bits & 0x00070000) && ((ipc_port_t) $kgm_ie.ie_object)->ip_callstack[0] != 0
1233 printf " user bt: "
1234 showportbt $kgm_ie.ie_object $kgm_is.is_task
1235 end
b7266188 1236 end
b0d623f7
A
1237 end
1238 set $kgm_iindex = $kgm_iindex + 1
1239 set $kgm_iep = &($kgm_is.is_table[$kgm_iindex])
1240 end
1241 if $kgm_is.is_tree_total
1242 printf "Still need to write tree traversal\n"
1243 end
1c79356b
A
1244 end
1245 printf "\n"
1246end
1247
1248
1249define showipc
b0d623f7
A
1250 set $kgm_isp = (ipc_space_t)$arg0
1251 showipcheader
b7266188 1252 showipcint $kgm_isp 0 0
1c79356b
A
1253end
1254document showipc
2d21ac55 1255Syntax: (gdb) showipc <ipc_space>
1c79356b 1256| Routine to print the status of the specified ipc space
1c79356b
A
1257end
1258
1259define showrights
1260 set $kgm_isp = (ipc_space_t)$arg0
b0d623f7 1261 showipcheader
b7266188 1262 showipcint $kgm_isp 1 0
1c79356b
A
1263end
1264document showrights
2d21ac55 1265Syntax: (gdb) showrights <ipc_space>
1c79356b 1266| Routine to print a summary list of all the rights in a specified ipc space
1c79356b
A
1267end
1268
1269
1270define showtaskipc
1271 set $kgm_taskp = (task_t)$arg0
1272 showtaskheader
1273 showipcheader
1274 showtaskint $kgm_taskp
b7266188 1275 showipcint $kgm_taskp->itk_space 0 0
1c79356b
A
1276end
1277document showtaskipc
2d21ac55 1278Syntax: (gdb) showtaskipc <task>
55e303ae 1279| Routine to print info about the ipc space for a task
1c79356b
A
1280end
1281
1282
1283define showtaskrights
1284 set $kgm_taskp = (task_t)$arg0
1285 showtaskheader
b0d623f7 1286 showipcheader
1c79356b 1287 showtaskint $kgm_taskp
b7266188 1288 showipcint $kgm_taskp->itk_space 1 0
1c79356b
A
1289end
1290document showtaskrights
2d21ac55 1291Syntax: (gdb) showtaskrights <task>
55e303ae 1292| Routine to print info about the ipc rights for a task
1c79356b
A
1293end
1294
b7266188
A
1295define showtaskrightsbt
1296 set $kgm_taskp = (task_t)$arg0
1297 showtaskheader
1298 showipcheader
1299 showtaskint $kgm_taskp
1300 showipcint $kgm_taskp->itk_space 1 1
1301end
1302document showtaskrightsbt
1303Syntax: (gdb) showtaskrightsbt <task>
1304| Routine to print info about the ipc rights for a task with backtraces
1305end
1306
1c79356b 1307define showallipc
2d21ac55 1308 set $kgm_head_taskp = &tasks
91447636
A
1309 set $kgm_cur_taskp = (struct task *)($kgm_head_taskp->next)
1310 while $kgm_cur_taskp != $kgm_head_taskp
1c79356b
A
1311 showtaskheader
1312 showipcheader
b0d623f7 1313 showtaskint $kgm_cur_taskp
b7266188 1314 showipcint $kgm_cur_taskp->itk_space 0 0
2d21ac55 1315 set $kgm_cur_taskp = (struct task *)($kgm_cur_taskp->tasks.next)
1c79356b
A
1316 end
1317end
1318document showallipc
2d21ac55 1319Syntax: (gdb) showallipc
1c79356b 1320| Routine to print a summary listing of all the ipc spaces
1c79356b
A
1321end
1322
1323
1324define showallrights
2d21ac55 1325 set $kgm_head_taskp = &tasks
91447636
A
1326 set $kgm_cur_taskp = (struct task *)($kgm_head_taskp->next)
1327 while $kgm_cur_taskp != $kgm_head_taskp
1c79356b
A
1328 showtaskheader
1329 showipcheader
b0d623f7 1330 showtaskint $kgm_cur_taskp
b7266188 1331 showipcint $kgm_cur_taskp->itk_space 1 0
2d21ac55 1332 set $kgm_cur_taskp = (struct task *)($kgm_cur_taskp->tasks.next)
1c79356b
A
1333 end
1334end
1335document showallrights
2d21ac55 1336Syntax: (gdb) showallrights
1c79356b 1337| Routine to print a summary listing of all the ipc rights
1c79356b
A
1338end
1339
1340
1341define showtaskvm
1342 set $kgm_taskp = (task_t)$arg0
1343 showtaskheader
1344 showmapheader
1345 showtaskint $kgm_taskp
1346 showvmint $kgm_taskp->map 0
1347end
1348document showtaskvm
2d21ac55 1349Syntax: (gdb) showtaskvm <task>
55e303ae 1350| Routine to print out info about a task's vm_map
1c79356b
A
1351end
1352
1353define showtaskvme
1354 set $kgm_taskp = (task_t)$arg0
1355 showtaskheader
1356 showmapheader
1357 showtaskint $kgm_taskp
1358 showvmint $kgm_taskp->map 1
1359end
1360document showtaskvme
2d21ac55 1361Syntax: (gdb) showtaskvme <task>
55e303ae 1362| Routine to print out info about a task's vm_map_entries
1c79356b
A
1363end
1364
1365
1366define showtaskheader
b0d623f7
A
1367 printf "task "
1368 showptrhdrpad
1369 printf " vm_map "
1370 showptrhdrpad
1371 printf " ipc_space "
1372 showptrhdrpad
1373 printf " #acts "
1c79356b
A
1374 showprocheader
1375end
1376
1377
1378define showtaskint
b0d623f7
A
1379 set $kgm_taskp = (struct task *)$arg0
1380 showptr $arg0
1381 printf " "
1382 showptr $kgm_taskp->map
1383 printf " "
1384 showptr $kgm_taskp->itk_space
1385 printf " %5d ", $kgm_taskp->thread_count
1386 showprocint $kgm_taskp->bsd_info
1c79356b
A
1387end
1388
1389define showtask
1390 showtaskheader
1391 showtaskint $arg0
1392end
1393document showtask
2d21ac55 1394Syntax (gdb) showtask <task>
1c79356b 1395| Routine to print out info about a task.
1c79356b
A
1396end
1397
1398
55e303ae 1399define showtaskthreads
1c79356b 1400 showtaskheader
9bccf70c 1401 set $kgm_taskp = (struct task *)$arg0
1c79356b
A
1402 showtaskint $kgm_taskp
1403 showactheader
55e303ae
A
1404 set $kgm_head_actp = &($kgm_taskp->threads)
1405 set $kgm_actp = (struct thread *)($kgm_taskp->threads.next)
1c79356b
A
1406 while $kgm_actp != $kgm_head_actp
1407 showactint $kgm_actp 0
55e303ae 1408 set $kgm_actp = (struct thread *)($kgm_actp->task_threads.next)
1c79356b
A
1409 end
1410end
55e303ae 1411document showtaskthreads
2d21ac55 1412Syntax: (gdb) showtaskthreads <task>
55e303ae 1413| Routine to print info about the threads in a task.
1c79356b
A
1414end
1415
1416
1417define showtaskstacks
1418 showtaskheader
9bccf70c 1419 set $kgm_taskp = (struct task *)$arg0
1c79356b 1420 showtaskint $kgm_taskp
55e303ae
A
1421 set $kgm_head_actp = &($kgm_taskp->threads)
1422 set $kgm_actp = (struct thread *)($kgm_taskp->threads.next)
1c79356b
A
1423 while $kgm_actp != $kgm_head_actp
1424 showactheader
1425 showactint $kgm_actp 1
55e303ae 1426 set $kgm_actp = (struct thread *)($kgm_actp->task_threads.next)
1c79356b
A
1427 end
1428end
1429document showtaskstacks
2d21ac55 1430Syntax: (gdb) showtaskstacks <task>
55e303ae 1431| Routine to print out the stack for each thread in a task.
1c79356b
A
1432end
1433
1434
1435define showalltasks
1436 showtaskheader
2d21ac55 1437 set $kgm_head_taskp = &tasks
9bccf70c 1438 set $kgm_taskp = (struct task *)($kgm_head_taskp->next)
1c79356b
A
1439 while $kgm_taskp != $kgm_head_taskp
1440 showtaskint $kgm_taskp
2d21ac55 1441 set $kgm_taskp = (struct task *)($kgm_taskp->tasks.next)
1c79356b
A
1442 end
1443end
1444document showalltasks
2d21ac55 1445Syntax: (gdb) showalltasks
1c79356b 1446| Routine to print a summary listing of all the tasks
b0d623f7
A
1447| wq_state -> reports "number of workq threads", "number of scheduled workq threads", "number of pending work items"
1448| if "number of pending work items" seems stuck at non-zero, it may indicate that the workqueue mechanism is hung
1449| io_policy -> RAGE - rapid aging of vnodes requested
1450| NORM - normal I/O explicitly requested (this is the default)
1451| PASS - passive I/O requested (i.e. I/Os do not affect throttling decisions)
1452| THROT - throttled I/O requested (i.e. thread/task may be throttled after each I/O completes)
1c79356b
A
1453end
1454
1c79356b 1455define showprocheader
b0d623f7
A
1456 printf " pid process io_policy wq_state"
1457 showptrhdrpad
1458 printf " command\n"
1c79356b
A
1459end
1460
1461define showprocint
1462 set $kgm_procp = (struct proc *)$arg0
1463 if $kgm_procp != 0
b0d623f7 1464 set $kgm_printed = 0
1c79356b 1465 printf "%5d ", $kgm_procp->p_pid
b0d623f7
A
1466 showptr $kgm_procp
1467 if ($kgm_procp->p_lflag & 0x400000)
1468 printf " RAGE "
1469 else
1470 printf " "
1471 end
1472 if ($kgm_procp->p_iopol_disk == 1)
1473 printf "NORM "
1474 set $kgm_printed = 1
1475 end
1476 if ($kgm_procp->p_iopol_disk == 2)
1477 printf "PASS "
1478 set $kgm_printed = 1
1479 end
1480 if ($kgm_procp->p_iopol_disk == 3)
1481 printf "THROT "
1482 set $kgm_printed = 1
1483 end
1484 if ($kgm_printed == 0)
1485 printf " "
1486 end
1487 set $kgm_wqp = (struct workqueue *)$kgm_procp->p_wqptr
1488 if $kgm_wqp != 0
1489 printf " %2d %2d %2d ", $kgm_wqp->wq_nthreads, $kgm_wqp->wq_thidlecount, $kgm_wqp->wq_itemcount
1490 else
1491 printf " "
1492 end
1493 printf " %s\n", $kgm_procp->p_comm
1c79356b 1494 else
b0d623f7
A
1495 printf " *0* "
1496 showptr 0
1497 printf " --\n"
1c79356b
A
1498 end
1499end
1500
1501define showpid
1502 showtaskheader
2d21ac55 1503 set $kgm_head_taskp = &tasks
9bccf70c 1504 set $kgm_taskp = (struct task *)($kgm_head_taskp->next)
1c79356b
A
1505 while $kgm_taskp != $kgm_head_taskp
1506 set $kgm_procp = (struct proc *)$kgm_taskp->bsd_info
1507 if (($kgm_procp != 0) && ($kgm_procp->p_pid == $arg0))
1508 showtaskint $kgm_taskp
1509 set $kgm_taskp = $kgm_head_taskp
1510 else
2d21ac55 1511 set $kgm_taskp = (struct task *)($kgm_taskp->tasks.next)
1c79356b
A
1512 end
1513 end
1514end
1515document showpid
2d21ac55 1516Syntax: (gdb) showpid <pid>
1c79356b 1517| Routine to print a single process by pid
1c79356b
A
1518end
1519
1520define showproc
1521 showtaskheader
1522 set $kgm_procp = (struct proc *)$arg0
b0d623f7 1523 showtaskint $kgm_procp->task
1c79356b
A
1524end
1525
1526
1527define kdb
1528 set switch_debugger=1
1529 continue
1530end
1531document kdb
1532| kdb - Switch to the inline kernel debugger
1533|
1534| usage: kdb
1535|
1536| The kdb macro allows you to invoke the inline kernel debugger.
1537end
1538
1539define showpsetheader
1540 printf "portset waitqueue recvname "
1541 printf "flags refs recvname process\n"
1542end
1543
1544define showportheader
1545 printf "port mqueue recvname "
1546 printf "flags refs recvname process\n"
1547end
1548
1549define showportmemberheader
9bccf70c 1550 printf "members port recvname "
1c79356b
A
1551 printf "flags refs mqueue msgcount\n"
1552end
1553
1554define showkmsgheader
9bccf70c 1555 printf "messages kmsg size "
1c79356b
A
1556 printf "disp msgid remote-port local-port\n"
1557end
1558
1559define showkmsgint
1560 printf " 0x%08x ", $arg0
1561 set $kgm_kmsgh = ((ipc_kmsg_t)$arg0)->ikm_header
1562 printf "0x%08x ", $kgm_kmsgh.msgh_size
1563 if (($kgm_kmsgh.msgh_bits & 0xff) == 19)
1564 printf "rC"
1565 else
1566 printf "rM"
1567 end
b0d623f7 1568 if (($kgm_kmsgh.msgh_bits & 0xff00) == (19 << 8))
1c79356b
A
1569 printf "lC"
1570 else
1571 printf "lM"
1572 end
1573 if ($kgm_kmsgh.msgh_bits & 0xf0000000)
1574 printf "c"
1575 else
1576 printf "s"
1577 end
9bccf70c 1578 printf "%5d ", $kgm_kmsgh.msgh_id
1c79356b
A
1579 printf "0x%08x ", $kgm_kmsgh.msgh_remote_port
1580 printf "0x%08x\n", $kgm_kmsgh.msgh_local_port
1581end
1582
1583
1584
1585define showkobject
9bccf70c 1586 set $kgm_portp = (struct ipc_port *)$arg0
b0d623f7
A
1587 showptr $kgm_portp->ip_kobject
1588 printf " kobject("
1c79356b
A
1589 set $kgm_kotype = ($kgm_portp->ip_object.io_bits & 0x00000fff)
1590 if ($kgm_kotype == 1)
1591 printf "THREAD"
1592 end
1593 if ($kgm_kotype == 2)
1594 printf "TASK"
1595 end
1596 if ($kgm_kotype == 3)
1597 printf "HOST"
1598 end
1599 if ($kgm_kotype == 4)
1600 printf "HOST_PRIV"
1601 end
1602 if ($kgm_kotype == 5)
1603 printf "PROCESSOR"
1604 end
1605 if ($kgm_kotype == 6)
1606 printf "PSET"
1607 end
1608 if ($kgm_kotype == 7)
1609 printf "PSET_NAME"
1610 end
1611 if ($kgm_kotype == 8)
1612 printf "TIMER"
1613 end
1614 if ($kgm_kotype == 9)
1615 printf "PAGER_REQ"
1616 end
1617 if ($kgm_kotype == 10)
1618 printf "DEVICE"
1619 end
1620 if ($kgm_kotype == 11)
1621 printf "XMM_OBJECT"
1622 end
1623 if ($kgm_kotype == 12)
1624 printf "XMM_PAGER"
1625 end
1626 if ($kgm_kotype == 13)
1627 printf "XMM_KERNEL"
1628 end
1629 if ($kgm_kotype == 14)
1630 printf "XMM_REPLY"
1631 end
1632 if ($kgm_kotype == 15)
1633 printf "NOTDEF 15"
1634 end
1635 if ($kgm_kotype == 16)
1636 printf "NOTDEF 16"
1637 end
1638 if ($kgm_kotype == 17)
1639 printf "HOST_SEC"
1640 end
1641 if ($kgm_kotype == 18)
1642 printf "LEDGER"
1643 end
1644 if ($kgm_kotype == 19)
1645 printf "MASTER_DEV"
1646 end
1647 if ($kgm_kotype == 20)
1648 printf "ACTIVATION"
1649 end
1650 if ($kgm_kotype == 21)
1651 printf "SUBSYSTEM"
1652 end
1653 if ($kgm_kotype == 22)
1654 printf "IO_DONE_QUE"
1655 end
1656 if ($kgm_kotype == 23)
1657 printf "SEMAPHORE"
1658 end
1659 if ($kgm_kotype == 24)
1660 printf "LOCK_SET"
1661 end
1662 if ($kgm_kotype == 25)
1663 printf "CLOCK"
1664 end
1665 if ($kgm_kotype == 26)
1666 printf "CLOCK_CTRL"
1667 end
1668 if ($kgm_kotype == 27)
1669 printf "IOKIT_SPARE"
1670 end
1671 if ($kgm_kotype == 28)
1672 printf "NAMED_MEM"
1673 end
1674 if ($kgm_kotype == 29)
1675 printf "IOKIT_CON"
1676 end
1677 if ($kgm_kotype == 30)
1678 printf "IOKIT_OBJ"
1679 end
1680 if ($kgm_kotype == 31)
1681 printf "UPL"
1682 end
d1ecb069
A
1683 if ($kgm_kotype == 34)
1684 printf "FD"
1685 end
1c79356b
A
1686 printf ")\n"
1687end
1688
1689define showportdestproc
9bccf70c 1690 set $kgm_portp = (struct ipc_port *)$arg0
1c79356b
A
1691 set $kgm_spacep = $kgm_portp->data.receiver
1692# check against the previous cached value - this is slow
1693 if ($kgm_spacep != $kgm_destspacep)
1694 set $kgm_destprocp = (struct proc *)0
2d21ac55 1695 set $kgm_head_taskp = &tasks
91447636
A
1696 set $kgm_desttaskp = (struct task *)($kgm_head_taskp->next)
1697 while (($kgm_destprocp == 0) && ($kgm_desttaskp != $kgm_head_taskp))
1698 set $kgm_destspacep = $kgm_desttaskp->itk_space
1c79356b 1699 if ($kgm_destspacep == $kgm_spacep)
91447636 1700 set $kgm_destprocp = (struct proc *)$kgm_desttaskp->bsd_info
1c79356b 1701 else
2d21ac55 1702 set $kgm_desttaskp = (struct task *)($kgm_desttaskp->tasks.next)
1c79356b
A
1703 end
1704 end
1705 end
1706 if $kgm_destprocp != 0
1707 printf "%s(%d)\n", $kgm_destprocp->p_comm, $kgm_destprocp->p_pid
1708 else
b0d623f7
A
1709 printf "task "
1710 showptr $kgm_desttaskp
1711 printf "\n"
1c79356b
A
1712 end
1713end
1714
1715define showportdest
9bccf70c 1716 set $kgm_portp = (struct ipc_port *)$arg0
1c79356b
A
1717 set $kgm_spacep = $kgm_portp->data.receiver
1718 if ($kgm_spacep == ipc_space_kernel)
1719 showkobject $kgm_portp
1720 else
1721 if ($kgm_portp->ip_object.io_bits & 0x80000000)
b0d623f7
A
1722 showptr $kgm_portp->ip_messages.data.port.receiver_name
1723 printf " "
1c79356b
A
1724 showportdestproc $kgm_portp
1725 else
b0d623f7
A
1726 showptr $kgm_portp
1727 printf " inactive-port\n"
1c79356b
A
1728 end
1729 end
1730end
1731
1732define showportmember
1733 printf " 0x%08x ", $arg0
9bccf70c 1734 set $kgm_portp = (struct ipc_port *)$arg0
b0d623f7 1735 printf "0x%08x ", $kgm_portp->ip_messages.data.port.receiver_name
1c79356b
A
1736 if ($kgm_portp->ip_object.io_bits & 0x80000000)
1737 printf "A"
1738 else
1739 printf " "
1740 end
b0d623f7 1741 printf "Port"
1c79356b
A
1742 printf "%5d ", $kgm_portp->ip_object.io_references
1743 printf "0x%08x ", &($kgm_portp->ip_messages)
1744 printf "0x%08x\n", $kgm_portp->ip_messages.data.port.msgcount
1745end
1746
b7266188
A
1747define showportbt
1748 set $kgm_iebt = ((ipc_port_t) $arg0)->ip_callstack
1749 set $kgm_iepid = ((ipc_port_t) $arg0)->ip_spares[0]
1750 set $kgm_procpid = ((proc_t) (((task_t) $arg1)->bsd_info))->p_pid
1751 if $kgm_iebt[0] != 0
1752 showptr $kgm_iebt[0]
1753 set $kgm_iebt_loop_ctr = 1
1754 while ($kgm_iebt_loop_ctr < 16 && $kgm_iebt[$kgm_iebt_loop_ctr])
1755 printf " "
1756 showptr $kgm_iebt[$kgm_iebt_loop_ctr]
1757 set $kgm_iebt_loop_ctr = $kgm_iebt_loop_ctr + 1
1758 end
1759 if $kgm_iepid != $kgm_procpid
1760 printf " (%d)", $kgm_iepid
1761 end
1762 printf "\n"
1763 end
1764end
1765
1c79356b
A
1766define showportint
1767 printf "0x%08x ", $arg0
9bccf70c 1768 set $kgm_portp = (struct ipc_port *)$arg0
1c79356b 1769 printf "0x%08x ", &($kgm_portp->ip_messages)
b0d623f7 1770 printf "0x%08x ", $kgm_portp->ip_messages.data.port.receiver_name
1c79356b
A
1771 if ($kgm_portp->ip_object.io_bits & 0x80000000)
1772 printf "A"
1773 else
1774 printf "D"
1775 end
1776 printf "Port"
1777 printf "%5d ", $kgm_portp->ip_object.io_references
9bccf70c 1778 set $kgm_destspacep = (struct ipc_space *)0
1c79356b
A
1779 showportdest $kgm_portp
1780 set $kgm_kmsgp = (ipc_kmsg_t)$kgm_portp->ip_messages.data.port.messages.ikmq_base
1781 if $arg1 && $kgm_kmsgp
1782 showkmsgheader
1783 showkmsgint $kgm_kmsgp
1784 set $kgm_kmsgheadp = $kgm_kmsgp
1785 set $kgm_kmsgp = $kgm_kmsgp->ikm_next
1786 while $kgm_kmsgp != $kgm_kmsgheadp
1787 showkmsgint $kgm_kmsgp
1788 set $kgm_kmsgp = $kgm_kmsgp->ikm_next
1789 end
1790 end
1791end
1792
1793define showpsetint
1794 printf "0x%08x ", $arg0
9bccf70c 1795 set $kgm_psetp = (struct ipc_pset *)$arg0
1c79356b 1796 printf "0x%08x ", &($kgm_psetp->ips_messages)
b0d623f7 1797 printf "0x%08x ", $kgm_psetp->ips_messages.data.pset.local_name
1c79356b
A
1798 if ($kgm_psetp->ips_object.io_bits & 0x80000000)
1799 printf "A"
1800 else
1801 printf "D"
1802 end
1803 printf "Set "
1804 printf "%5d ", $kgm_psetp->ips_object.io_references
b0d623f7 1805 printf "0x%08x ", $kgm_psetp->ips_messages.data.pset.local_name
0b4c1975 1806 set $kgm_setlinksp = &($kgm_psetp->ips_messages.data.pset.set_queue.wqs_setlinks)
b0d623f7 1807 set $kgm_wql = (WaitQueueLink *)$kgm_setlinksp->next
1c79356b 1808 set $kgm_found = 0
9bccf70c 1809 while ( (queue_entry_t)$kgm_wql != (queue_entry_t)$kgm_setlinksp)
0b4c1975 1810 set $kgm_portp = (struct ipc_port *)((uintptr_t)$kgm_wql->wql_element.wqe_queue - $kgm_portoff)
1c79356b 1811 if !$kgm_found
9bccf70c
A
1812 set $kgm_destspacep = (struct ipc_space *)0
1813 showportdestproc $kgm_portp
1c79356b
A
1814 showportmemberheader
1815 set $kgm_found = 1
1816 end
1817 showportmember $kgm_portp 0
b0d623f7 1818 set $kgm_wql = (WaitQueueLink *)$kgm_wql->wql_setlinks.next
1c79356b 1819 end
9bccf70c
A
1820 if !$kgm_found
1821 printf "--n/e--\n"
1c79356b
A
1822 end
1823end
1824
1825define showpset
1826 showpsetheader
1827 showpsetint $arg0 1
1828end
1829
1830define showport
1831 showportheader
1832 showportint $arg0 1
1833end
1834
1835define showipcobject
1836 set $kgm_object = (ipc_object_t)$arg0
1837 if ($kgm_objectp->io_bits & 0x7fff0000)
1838 showpset $kgm_objectp
1839 else
1840 showport $kgm_objectp
1841 end
1842end
1843
1844define showmqueue
9bccf70c 1845 set $kgm_mqueue = *(struct ipc_mqueue *)$arg0
0b4c1975
A
1846 set $kgm_psetoff = (uintptr_t)&(((struct ipc_pset *)0)->ips_messages)
1847 set $kgm_portoff = (uintptr_t)&(((struct ipc_port *)0)->ip_messages)
b0d623f7 1848 if ($kgm_mqueue.data.pset.set_queue.wqs_wait_queue.wq_type == 0xf1d1)
0b4c1975 1849 set $kgm_psetp = (struct ipc_pset *)(((uintptr_t)$arg0) - $kgm_psetoff)
1c79356b 1850 showpsetheader
0b4c1975 1851 showpsetint $kgm_psetp 1
9bccf70c 1852 end
b0d623f7 1853 if ($kgm_mqueue.data.pset.set_queue.wqs_wait_queue.wq_type == 0xf1d0)
0b4c1975 1854 set $kgm_portp = (struct ipc_port *)(((uintptr_t)$arg0) - $kgm_portoff)
1c79356b 1855 showportheader
0b4c1975 1856 showportint $kgm_portp 1
1c79356b
A
1857 end
1858end
1859
1860define zprint_one
b0d623f7 1861 set $kgm_zone = (struct zone *)$arg0
1c79356b 1862
b0d623f7
A
1863 showptr $kgm_zone
1864 printf " %6d ",$kgm_zone->count
1865 printf "%8x ",$kgm_zone->cur_size
1866 printf "%8x ",$kgm_zone->max_size
1867 printf "%6d ",$kgm_zone->elem_size
1868 printf "%8x ",$kgm_zone->alloc_size
1869 printf "%s ",$kgm_zone->zone_name
1c79356b 1870
b0d623f7
A
1871 if ($kgm_zone->exhaustible)
1872 printf "H"
1873 end
1874 if ($kgm_zone->collectable)
1875 printf "C"
1876 end
1877 if ($kgm_zone->expandable)
1878 printf "X"
1879 end
0b4c1975
A
1880 if ($kgm_zone->noencrypt)
1881 printf "$"
1882 end
b0d623f7 1883 printf "\n"
1c79356b
A
1884end
1885
1886
1887define zprint
b0d623f7
A
1888 printf "ZONE "
1889 showptrhdrpad
1890 printf " COUNT TOT_SZ MAX_SZ ELT_SZ ALLOC_SZ NAME\n"
1891 set $kgm_zone_ptr = (struct zone *)first_zone
1892 while ($kgm_zone_ptr != 0)
1893 zprint_one $kgm_zone_ptr
1894 set $kgm_zone_ptr = $kgm_zone_ptr->next_zone
1895 end
1896 printf "\n"
1c79356b
A
1897end
1898document zprint
2d21ac55 1899Syntax: (gdb) zprint
1c79356b 1900| Routine to print a summary listing of all the kernel zones
1c79356b
A
1901end
1902
91447636 1903define showmtxgrp
b0d623f7
A
1904 set $kgm_mtxgrp = (struct _lck_grp_ *)$arg0
1905
1906 if ($kgm_mtxgrp->lck_grp_mtxcnt)
1907 showptr $kgm_mtxgrp
1908 printf " %8d ",$kgm_mtxgrp->lck_grp_mtxcnt
1909 printf "%12u ",$kgm_mtxgrp->lck_grp_stat.lck_grp_mtx_stat.lck_grp_mtx_util_cnt
1910 printf "%8u ",$kgm_mtxgrp->lck_grp_stat.lck_grp_mtx_stat.lck_grp_mtx_miss_cnt
1911 printf "%8u ",$kgm_mtxgrp->lck_grp_stat.lck_grp_mtx_stat.lck_grp_mtx_wait_cnt
1912 printf "%s ",&$kgm_mtxgrp->lck_grp_name
1913 printf "\n"
1914 end
91447636
A
1915end
1916
1917
1918define showallmtx
b0d623f7
A
1919 printf "LCK GROUP "
1920 showptrhdrpad
1921 printf " CNT UTIL MISS WAIT NAME\n"
1922 set $kgm_mtxgrp_ptr = (struct _lck_grp_ *)&lck_grp_queue
1923 set $kgm_mtxgrp_ptr = (struct _lck_grp_ *)$kgm_mtxgrp_ptr->lck_grp_link.next
1924 while ($kgm_mtxgrp_ptr != (struct _lck_grp_ *)&lck_grp_queue)
1925 showmtxgrp $kgm_mtxgrp_ptr
1926 set $kgm_mtxgrp_ptr = (struct _lck_grp_ *)$kgm_mtxgrp_ptr->lck_grp_link.next
1927 end
1928 printf "\n"
91447636
A
1929end
1930document showallmtx
2d21ac55 1931Syntax: (gdb) showallmtx
91447636 1932| Routine to print a summary listing of all mutexes
91447636
A
1933end
1934
1935define showrwlckgrp
b0d623f7
A
1936 set $kgm_rwlckgrp = (struct _lck_grp_ *)$arg0
1937
1938 if ($kgm_rwlckgrp->lck_grp_rwcnt)
1939 showptr $kgm_rwlckgrp
1940 printf " %8d ",$kgm_rwlckgrp->lck_grp_rwcnt
1941 printf "%12u ",$kgm_rwlckgrp->lck_grp_stat.lck_grp_rw_stat.lck_grp_rw_util_cnt
1942 printf "%8u ",$kgm_rwlckgrp->lck_grp_stat.lck_grp_rw_stat.lck_grp_rw_miss_cnt
1943 printf "%8u ",$kgm_rwlckgrp->lck_grp_stat.lck_grp_rw_stat.lck_grp_rw_wait_cnt
1944 printf "%s ",&$kgm_rwlckgrp->lck_grp_name
1945 printf "\n"
1946 end
91447636
A
1947end
1948
1949
1950define showallrwlck
b0d623f7
A
1951 printf "LCK GROUP "
1952 showptrhdrpad
1953 printf " CNT UTIL MISS WAIT NAME\n"
1954 set $kgm_rwlckgrp_ptr = (struct _lck_grp_ *)&lck_grp_queue
1955 set $kgm_rwlckgrp_ptr = (struct _lck_grp_ *)$kgm_rwlckgrp_ptr->lck_grp_link.next
1956 while ($kgm_rwlckgrp_ptr != (struct _lck_grp_ *)&lck_grp_queue)
1957 showrwlckgrp $kgm_rwlckgrp_ptr
1958 set $kgm_rwlckgrp_ptr = (struct _lck_grp_ *)$kgm_rwlckgrp_ptr->lck_grp_link.next
1959 end
1960 printf "\n"
91447636
A
1961end
1962document showallrwlck
2d21ac55 1963Syntax: (gdb) showallrwlck
91447636 1964| Routine to print a summary listing of all read/writer locks
91447636
A
1965end
1966
9bccf70c
A
1967set $kdp_act_counter = 0
1968
2d21ac55
A
1969set $r0_save = 0
1970set $r1_save = 0
1971set $r2_save = 0
1972set $r3_save = 0
1973set $r4_save = 0
1974set $r5_save = 0
1975set $r6_save = 0
1976set $r7_save = 0
1977set $r8_save = 0
1978set $r9_save = 0
1979set $r10_save = 0
1980set $r11_save = 0
1981set $r12_save = 0
1982set $sp_save = 0
1983set $lr_save = 0
1984set $pc_save = 0
1985
1986define showcontext_int
1987 echo Context switched, current instruction pointer:
1988 output/a $pc
1989 echo \n
1990end
1991
9bccf70c 1992define switchtoact
0c530ab8 1993 set $newact = (struct thread *) $arg0
2d21ac55 1994 select 0
0c530ab8
A
1995 if ($newact->kernel_stack == 0)
1996 echo This activation does not have a stack.\n
1997 echo continuation:
1998 output/a (unsigned) $newact.continuation
1999 echo \n
2000 else
b0d623f7 2001 if ($kgm_mtype == $kgm_mtype_ppc)
9bccf70c 2002 if ($kdp_act_counter == 0)
0c530ab8 2003 set $kdpstate = (struct savearea *) kdp.saved_state
9bccf70c
A
2004 end
2005 set $kdp_act_counter = $kdp_act_counter + 1
0c530ab8
A
2006 set (struct savearea *) kdp.saved_state=$newact->machine->pcb
2007 flushregs
2008 flushstack
2009 set $pc=$newact->machine->pcb.save_srr0
2010 update
2d21ac55 2011 end
b0d623f7 2012 if ($kgm_mtype == $kgm_mtype_i386)
0c530ab8
A
2013 set $kdpstatep = (struct x86_saved_state32 *) kdp.saved_state
2014 if ($kdp_act_counter == 0)
7e4a7d39 2015 set $kdpstate = *($kdpstatep)
0c530ab8
A
2016 end
2017 set $kdp_act_counter = $kdp_act_counter + 1
2018
b0d623f7
A
2019 set $kgm_statep = (struct x86_kernel_state *) \
2020 ($newact->kernel_stack + kernel_stack_size \
2021 - sizeof(struct x86_kernel_state))
7e4a7d39 2022 set $kdpstatep->ebx = $kgm_statep->k_ebx
0c530ab8
A
2023 set $kdpstatep->ebp = $kgm_statep->k_ebp
2024 set $kdpstatep->edi = $kgm_statep->k_edi
2025 set $kdpstatep->esi = $kgm_statep->k_esi
7e4a7d39 2026 set $kdpstatep->eip = $kgm_statep->k_eip
0c530ab8
A
2027 flushregs
2028 flushstack
2029 set $pc = $kgm_statep->k_eip
2030 update
2031 end
b0d623f7
A
2032 if ($kgm_mtype == $kgm_mtype_x86_64)
2033 set $kdpstatep = (struct x86_saved_state64 *) kdp.saved_state
2034 if ($kdp_act_counter == 0)
7e4a7d39 2035 set $kdpstate = *($kdpstatep)
b0d623f7
A
2036 end
2037 set $kdp_act_counter = $kdp_act_counter + 1
2038
2039 set $kgm_statep = (struct x86_kernel_state *) \
2040 ($newact->kernel_stack + kernel_stack_size \
2041 - sizeof(struct x86_kernel_state))
7e4a7d39
A
2042 set $kdpstatep->rbx = $kgm_statep->k_rbx
2043 set $kdpstatep->rbp = $kgm_statep->k_rbp
2044 set $kdpstatep->r12 = $kgm_statep->k_r12
2045 set $kdpstatep->r13 = $kgm_statep->k_r13
2046 set $kdpstatep->r14 = $kgm_statep->k_r14
2047 set $kdpstatep->r15 = $kgm_statep->k_r15
2048 set $kdpstatep->isf.rsp = $kgm_statep->k_rsp
b0d623f7
A
2049 flushregs
2050 flushstack
2051 set $pc = $kgm_statep->k_rip
2052 update
2053 end
2054 if ($kgm_mtype == $kgm_mtype_arm)
2d21ac55
A
2055 set $r0_save = $r0
2056 set $r1_save = $r1
2057 set $r2_save = $r2
2058 set $r3_save = $r3
2059 set $r4_save = $r4
2060 set $r5_save = $r5
2061 set $r6_save = $r6
2062 set $r7_save = $r7
2063 set $r8_save = $r8
2064 set $r9_save = $r9
2065 set $r10_save = $r10
2066 set $r11_save = $r11
2067 set $r12_save = $r12
2068 set $sp_save = $sp
2069 set $lr_save = $lr
2070 set $pc_save = $pc
2071 set $pc_ctx = load_reg+8
2072 set $kgm_statep = (struct arm_saved_state *)((struct thread*)$arg0)->machine.kstackptr
2073 set $r0 = $kgm_statep->r[0]
2074 set $r1 = $kgm_statep->r[1]
2075 set $r2 = $kgm_statep->r[2]
2076 set $r3 = $kgm_statep->r[3]
2077 set $r4 = $kgm_statep->r[4]
2078 set $r5 = $kgm_statep->r[5]
2079 set $r6 = $kgm_statep->r[6]
2080 set $r8 = $kgm_statep->r[8]
2081 set $r9 = $kgm_statep->r[9]
2082 set $r10 = $kgm_statep->r[10]
2083 set $r11 = $kgm_statep->r[11]
2084 set $r12 = $kgm_statep->r[12]
2085 set $sp = $kgm_statep->sp
2086 set $lr = $kgm_statep->lr
2087 set $pc = $pc_ctx
2088 set $r7 = $kgm_statep->r[7]
2089 flushregs
2090 flushstack
2091 end
9bccf70c 2092 end
2d21ac55 2093 showcontext_int
9bccf70c
A
2094end
2095
2096document switchtoact
2097Syntax: switchtoact <address of activation>
2098| This command allows gdb to examine the execution context and call
2099| stack for the specified activation. For example, to view the backtrace
2100| for an activation issue "switchtoact <address>", followed by "bt".
2101| Before resuming execution, issue a "resetctx" command, to
2102| return to the original execution context.
2103end
2104
2105define switchtoctx
2d21ac55 2106 select 0
b0d623f7 2107 if ($kgm_mtype == $kgm_mtype_ppc)
9bccf70c 2108 if ($kdp_act_counter == 0)
7e4a7d39 2109 set $kdpstate = (struct savearea *) kdp.saved_state
9bccf70c
A
2110 end
2111 set $kdp_act_counter = $kdp_act_counter + 1
2112 set (struct savearea *) kdp.saved_state=(struct savearea *) $arg0
0c530ab8
A
2113 flushregs
2114 flushstack
9bccf70c
A
2115 set $pc=((struct savearea *) $arg0)->save_srr0
2116 update
2d21ac55 2117 else
b0d623f7
A
2118 if ($kgm_mtype == $kgm_mtype_arm)
2119 set arm disassembler std
2120 select-frame 0
2d21ac55
A
2121 set $r0_save = $r0
2122 set $r1_save = $r1
2123 set $r2_save = $r2
2124 set $r3_save = $r3
2125 set $r4_save = $r4
2126 set $r5_save = $r5
2127 set $r6_save = $r6
2128 set $r7_save = $r7
2129 set $r8_save = $r8
2130 set $r9_save = $r9
2131 set $r10_save = $r10
2132 set $r11_save = $r11
2133 set $r12_save = $r12
2134 set $sp_save = $sp
2135 set $lr_save = $lr
2136 set $pc_save = $pc
2137 set $kgm_statep = (struct arm_saved_state *)$arg0
2138 set $r0 = $kgm_statep->r[0]
2139 set $r1 = $kgm_statep->r[1]
2140 set $r2 = $kgm_statep->r[2]
2141 set $r3 = $kgm_statep->r[3]
2142 set $r4 = $kgm_statep->r[4]
2143 set $r5 = $kgm_statep->r[5]
2144 set $r6 = $kgm_statep->r[6]
2145 set $r8 = $kgm_statep->r[8]
2146 set $r9 = $kgm_statep->r[9]
2147 set $r10 = $kgm_statep->r[10]
2148 set $r11 = $kgm_statep->r[11]
2149 set $r12 = $kgm_statep->r[12]
2150 set $sp = $kgm_statep->sp
2151 set $lr = $kgm_statep->lr
2152 set $r7 = $kgm_statep->r[7]
2153 set $pc = $kgm_statep->pc
2154 flushregs
2155 flushstack
2156 update
9bccf70c
A
2157 else
2158 echo switchtoctx not implemented for this architecture.\n
2159 end
2160end
2161
2162document switchtoctx
2163Syntax: switchtoctx <address of pcb>
2164| This command allows gdb to examine an execution context and dump the
2165| backtrace for this execution context.
2166| Before resuming execution, issue a "resetctx" command, to
2167| return to the original execution context.
2168end
2169
2170define resetctx
2d21ac55
A
2171 select 0
2172 if ($kdp_act_counter != 0)
b0d623f7 2173 if ($kgm_mtype == $kgm_mtype_ppc)
9bccf70c 2174 set (struct savearea *)kdp.saved_state=$kdpstate
0c530ab8
A
2175 flushregs
2176 flushstack
9bccf70c
A
2177 set $pc=((struct savearea *) kdp.saved_state)->save_srr0
2178 update
2179 set $kdp_act_counter = 0
2d21ac55 2180 end
b0d623f7 2181 if ($kgm_mtype == $kgm_mtype_i386)
0c530ab8
A
2182 set $kdpstatep = (struct x86_saved_state32 *) kdp.saved_state
2183 set *($kdpstatep)=$kdpstate
2184 flushregs
2185 flushstack
2186 set $pc=$kdpstatep->eip
2187 update
2188 set $kdp_act_counter = 0
9bccf70c 2189 end
b0d623f7
A
2190 if ($kgm_mtype == $kgm_mtype_x86_64)
2191 set $kdpstatep = (struct x86_saved_state64 *) kdp.saved_state
2192 set *($kdpstatep)=$kdpstate
2193 flushregs
2194 flushstack
2195 set $pc=$kdpstatep->isf.rip
2196 update
2197 set $kdp_act_counter = 0
2198 end
2199 if ($kgm_mtype == $kgm_mtype_arm)
2d21ac55
A
2200 set $r0 = $r0_save
2201 flushregs
2202 set $r1 = $r1_save
2203 flushregs
2204 set $r2 = $r2_save
2205 flushregs
2206 set $r3 = $r3_save
2207 flushregs
2208 set $r4 = $r4_save
2209 flushregs
2210 set $r5 = $r5_save
2211 flushregs
2212 set $r6 = $r6_save
2213 flushregs
2214 set $r8 = $r8_save
2215 flushregs
2216 set $r9 = $r9_save
2217 flushregs
2218 set $r10 = $r10_save
2219 flushregs
2220 set $r11 = $r11_save
2221 flushregs
2222 set $r12 = $r12_save
2223 flushregs
2224 set $sp = $sp_save
2225 flushregs
2226 set $lr = $lr_save
2227 flushregs
2228 set $pc = $pc_save
2229 flushregs
2230 set $r7 = $r7_save
2231 flushregs
2232 end
2233 showcontext_int
2234 end
9bccf70c
A
2235end
2236
2237document resetctx
2238| Syntax: resetctx
2239| Returns to the original execution context. This command should be
2240| issued if you wish to resume execution after using the "switchtoact"
2241| or "switchtoctx" commands.
2242end
2243
2d21ac55
A
2244# This is a pre-hook for the continue command, to prevent inadvertent attempts
2245# to resume from the context switched to for examination.
2246define hook-continue
2247 resetctx
2248end
2249
2250# This is a pre-hook for the detach command, to prevent inadvertent attempts
2251# to resume from the context switched to for examination.
2252define hook-detach
2253 resetctx
2254end
2255
55e303ae 2256define resume_on
7e4a7d39
A
2257 set $resume = KDP_DUMPINFO_SETINFO | KDP_DUMPINFO_RESUME
2258 dumpinfoint $resume
55e303ae
A
2259end
2260
2261document resume_on
2262| Syntax: resume_on
2263| The target system will resume when detaching or exiting from gdb.
2264| This is the default behavior.
2265end
2266
2267define resume_off
7e4a7d39
A
2268 set $noresume = KDP_DUMPINFO_SETINFO | KDP_DUMPINFO_NORESUME
2269 dumpinfoint $noresume
55e303ae
A
2270end
2271
2272document resume_off
2273| Syntax: resume_off
2274| The target system won't resume after detaching from gdb and
2275| can be attached with a new gdb session
2276end
2277
9bccf70c
A
2278define paniclog
2279 set $kgm_panic_bufptr = debug_buf
55e303ae
A
2280 set $kgm_panic_bufptr_max = debug_buf_ptr
2281 while $kgm_panic_bufptr < $kgm_panic_bufptr_max
9bccf70c
A
2282 if *(char *)$kgm_panic_bufptr == 10
2283 printf "\n"
2284 else
b0d623f7 2285 printf "%c", *(char *)$kgm_panic_bufptr
9bccf70c
A
2286 end
2287 set $kgm_panic_bufptr= (char *)$kgm_panic_bufptr + 1
2288 end
2289end
2290
2291document paniclog
2292| Syntax: paniclog
2293| Display the panic log information
2294|
2295end
55e303ae
A
2296
2297define dumpcallqueue
b0d623f7
A
2298 set $kgm_callhead = $arg0
2299 set $kgm_callentry = $kgm_callhead->next
55e303ae 2300 set $kgm_i = 0
b0d623f7
A
2301 while $kgm_callentry != $kgm_callhead
2302 set $kgm_call = (struct call_entry *)$kgm_callentry
55e303ae
A
2303 printf "0x%08x ", $kgm_call
2304 printf "0x%08x 0x%08x ", $kgm_call->param0, $kgm_call->param1
55e303ae
A
2305 output $kgm_call->deadline
2306 printf "\t"
2307 output $kgm_call->func
2308 printf "\n"
2309 set $kgm_i = $kgm_i + 1
b0d623f7 2310 set $kgm_callentry = $kgm_callentry->next
55e303ae
A
2311 end
2312 printf "%d entries\n", $kgm_i
2313end
2314
2315document dumpcallqueue
2316| Syntax: dumpcallqueue <queue head>
2317| Displays the contents of the specified call_entry queue.
2318end
2319
2320define showtaskacts
2321showtaskthreads $arg0
2322end
2323document showtaskacts
2324| See help showtaskthreads.
2325end
2326
2327define showallacts
2328showallthreads
2329end
2330document showallacts
2331| See help showallthreads.
2332end
91447636
A
2333
2334
2335define resetstacks
2336 _kgm_flush_loop
2337 set kdp_pmap = 0
2338 _kgm_flush_loop
2339 resetctx
2340 _kgm_flush_loop
2341 _kgm_update_loop
2342 resetctx
2343 _kgm_update_loop
2344end
2345
2346document resetstacks
2347| Syntax: resetstacks
2348| Internal kgmacro routine used by the "showuserstack" macro
2349| to reset the target pmap to the kernel pmap.
2350end
2351
2352#Barely effective hacks to work around bugs in the "flush" and "update"
2353#gdb commands in Tiger (up to 219); these aren't necessary with Panther
2354#gdb, but do no harm.
2355define _kgm_flush_loop
2356 set $kgm_flush_loop_ctr = 0
2357 while ($kgm_flush_loop_ctr < 30)
0c530ab8
A
2358 flushregs
2359 flushstack
91447636
A
2360 set $kgm_flush_loop_ctr = $kgm_flush_loop_ctr + 1
2361 end
2362end
2363
2364define _kgm_update_loop
2365 set $kgm_update_loop_ctr = 0
2366 while ($kgm_update_loop_ctr < 30)
2367 update
2368 set $kgm_update_loop_ctr = $kgm_update_loop_ctr + 1
2369 end
2370end
b0d623f7
A
2371# Internal routine used by "_loadfrom" to read from 64-bit addresses
2372# on 32-bit kernels
2373define _loadk32m64
2374 # set up the manual KDP packet
2375 set manual_pkt.input = 0
2376 set manual_pkt.len = sizeof(kdp_readmem64_req_t)
2377 set $kgm_pkt = (kdp_readmem64_req_t *)&manual_pkt.data
2378 set $kgm_pkt->hdr.request = KDP_READMEM64
2379 set $kgm_pkt->hdr.len = sizeof(kdp_readmem64_req_t)
2380 set $kgm_pkt->hdr.is_reply = 0
2381 set $kgm_pkt->hdr.seq = 0
2382 set $kgm_pkt->hdr.key = 0
2383 set $kgm_pkt->address = (uint64_t)$arg0
2384 set $kgm_pkt->nbytes = sizeof(uint64_t)
2385 set manual_pkt.input = 1
2386 # dummy to make sure manual packet is executed
2387 set $kgm_dummy = &_mh_execute_header
2388 set $kgm_pkt = (kdp_readmem64_reply_t *)&manual_pkt.data
2389 if ($kgm_pkt->error == 0)
2390 set $kgm_k32read64 = *(uint64_t *)$kgm_pkt->data
2391 else
2392 set $kgm_k32read64 = 0
2393 end
2394end
2395
2396# Internal routine used by "showx86backtrace" to abstract possible loads from
2397# user space
2398define _loadfrom
2399 if (kdp_pmap == 0)
2400 set $kgm_loadval = *(uintptr_t *)$arg0
2401 else
2402 if ($kgm_x86_abi == 0xe)
2403 set $kgm_loadval = *(uint32_t *)$arg0
2404 else
2405 if ($kgm_x86_abi == 0xf)
2406 if ($kgm_mtype == $kgm_mtype_i386)
2407 _loadk32m64 $arg0
2408 set $kgm_loadval = $kgm_k32read64
2409 else
2410 set $kgm_loadval = *(uint64_t *)$arg0
2411 end
2412 end
2413 end
2414end
2415end
2416
91447636 2417
0c530ab8
A
2418#This is necessary since gdb often doesn't do backtraces on x86 correctly
2419#in the absence of symbols.The code below in showuserstack and
2420#showx86backtrace also contains several workarouds for the gdb bug where
2421#gdb stops macro evaluation because of spurious "Cannot read memory"
2422#errors on x86. These errors appear on ppc as well, but they don't
2423#always stop macro evaluation.
2424
b0d623f7
A
2425set $kgm_cur_frame = 0
2426set $kgm_cur_pc = 0
2427set $kgm_x86_abi = 0
0c530ab8 2428define showx86backtrace
b0d623f7
A
2429 if ($kgm_mtype == $kgm_mtype_i386)
2430 set $kgm_frame_reg = $ebp
2431 set $kgm_pc = $eip
2432 set $kgm_ret_off = 4
2433 end
2434 if ($kgm_mtype == $kgm_mtype_x86_64)
2435 set $kgm_frame_reg = $rbp
2436 set $kgm_pc = $rip
2437 set $kgm_ret_off = 8
2438 end
2439
2440 if ($kgm_x86_abi == 0xe)
2441 set $kgm_ret_off = 4
2442 end
2443 if ($kgm_x86_abi == 0xf)
2444 set $kgm_ret_off = 8
2445 end
2446
2447 if ($kgm_cur_frame == 0)
2448 set $kgm_cur_frame = $kgm_frame_reg
2449 end
2450 if ($kgm_cur_pc == 0)
2451 set $kgm_cur_pc = $kgm_pc
2452 end
2453 printf "0: Frame: 0x%016llx PC: 0x%016llx\n", $kgm_cur_frame, $kgm_cur_pc
2454 if (!(($kgm_x86_abi == 0xf) && ($kgm_mtype == $kgm_mtype_i386)))
2455 x/i $kgm_cur_pc
2456 end
2457 set $kgm_tmp_frame = $kgm_cur_frame
2458 set $kgm_cur_frame = 0
2459 set $kgm_cur_pc = 0
2460 _loadfrom ($kgm_tmp_frame)
2461 set $kgm_prev_frame = $kgm_loadval
2462 _loadfrom ($kgm_tmp_frame+$kgm_ret_off)
2463 set $kgm_prev_pc = $kgm_loadval
0c530ab8 2464 set $kgm_frameno = 1
b0d623f7
A
2465 while $kgm_prev_frame != 0
2466 printf "%d: Saved frame: 0x%016llx Saved PC: 0x%016llx\n", $kgm_frameno, $kgm_prev_frame, $kgm_prev_pc
2467 if (!(($kgm_x86_abi == 0xf) && ($kgm_mtype == $kgm_mtype_i386)))
2468 x/i $kgm_prev_pc
2469 end
2470 _loadfrom ($kgm_prev_frame+$kgm_ret_off)
2471 set $kgm_prev_pc = $kgm_loadval
2472 _loadfrom ($kgm_prev_frame)
2473 set $kgm_prev_frame = $kgm_loadval
0c530ab8
A
2474 set $kgm_frameno = $kgm_frameno + 1
2475 end
0c530ab8 2476 set kdp_pmap = 0
b0d623f7
A
2477 set $kgm_x86_abi = 0
2478end
2479
2480define showx86backtrace2
2481 set $kgm_cur_frame = $arg0
2482 set $kgm_cur_pc = $arg1
2483 showx86backtrace
0c530ab8
A
2484end
2485
91447636 2486define showuserstack
2d21ac55 2487 select 0
b0d623f7 2488 if ($kgm_mtype == $kgm_mtype_ppc)
91447636
A
2489 if ($kdp_act_counter == 0)
2490 set $kdpstate = (struct savearea *) kdp.saved_state
2491 end
2492 set $kdp_act_counter = $kdp_act_counter + 1
2493 set $newact = (struct thread *) $arg0
2494 _kgm_flush_loop
2495 set $checkpc = $newact->machine->upcb.save_srr0
2496 if ($checkpc == 0)
2497 echo This activation does not appear to have
2498 echo \20 a valid user context.\n
2499 else
2500 set (struct savearea *) kdp.saved_state=$newact->machine->upcb
2501 set $pc = $checkpc
2502#flush and update seem to be executed lazily by gdb on Tiger, hence the
2503#repeated invocations - see 3743135
2504 _kgm_flush_loop
2505# This works because the new pmap is used only for reads
2506 set kdp_pmap = $newact->task->map->pmap
2507 _kgm_flush_loop
2508 _kgm_update_loop
2509 bt
2510 resetstacks
2511 _kgm_flush_loop
2512 _kgm_update_loop
2513 resetstacks
2514 _kgm_flush_loop
2515 _kgm_update_loop
2516 end
2517 else
b0d623f7 2518 if (($kgm_mtype & $kgm_mtype_x86_mask) == $kgm_mtype_x86_any)
0c530ab8 2519 set $newact = (struct thread *) $arg0
b0d623f7
A
2520 set $newiss = (x86_saved_state_t *) ($newact->machine.pcb->iss)
2521 set $kgm_x86_abi = $newiss.flavor
2522 if ($newiss.flavor == 0xf)
2523 set $checkpc = $newiss.uss.ss_64.isf.rip
2524 set $checkframe = $newiss.uss.ss_64.rbp
2525
2526 else
2527 set $checkpc = $newiss.uss.ss_32.eip
2528 set $checkframe = $newiss.uss.ss_32.ebp
2529 end
2530
0c530ab8
A
2531 if ($checkpc == 0)
2532 echo This activation does not appear to have
2533 echo \20 a valid user context.\n
2534 else
b0d623f7
A
2535 set $kgm_cur_frame = $checkframe
2536 set $kgm_cur_pc = $checkpc
2537 printf "You may now issue the showx86backtrace command to see the user space backtrace for this thread ("
2538 showptr $arg0
2539 printf "); you can also examine memory locations in this address space (pmap "
2540 showptr $newact->task->map->pmap
2541 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"
0c530ab8
A
2542 set kdp_pmap = $newact->task->map->pmap
2543 _kgm_flush_loop
2544 _kgm_update_loop
2545 end
593a1d5f
A
2546 else
2547 echo showuserstack not supported on this architecture\n
2548 end
0c530ab8 2549 end
91447636 2550end
91447636
A
2551document showuserstack
2552Syntax: showuserstack <address of thread activation>
2553|This command displays a numeric backtrace for the user space stack of
2554|the given thread activation. It may, of course, fail to display a
2555|complete backtrace if portions of the user stack are not mapped in.
2556|Symbolic backtraces can be obtained either by running gdb on the
2557|user space binary, or a tool such as "symbolicate".
2558|Note that while this command works on Panther's gdb, an issue
2559|with Tiger gdb (3743135) appears to hamper the evaluation of this
2560|macro in some cases.
2561end
2562
91447636 2563define kdp-reboot
7e4a7d39
A
2564# Alternatively, set *(*(unsigned **) 0x2498) = 1
2565# (or 0x5498 on PPC, 0xffffff8000002928 on x86_64, 0xffff049c on arm)
2566 manualhdrint $kgm_kdp_pkt_hostreboot
91447636
A
2567 continue
2568end
2569
2570document kdp-reboot
2571Syntax: kdp-reboot
7e4a7d39
A
2572|Reboot the remote target machine; not guaranteed to succeed.
2573end
2574
2575define kdpversionint
2576 # set up the manual KDP packet
2577 set manual_pkt.input = 0
2578 set manual_pkt.len = sizeof(kdp_version_req_t)
2579 set $kgm_pkt = (kdp_version_req_t *)&manual_pkt.data
2580 set $kgm_pkt->hdr.request = KDP_VERSION
2581 set $kgm_pkt->hdr.len = sizeof(kdp_version_req_t)
2582 set $kgm_pkt->hdr.is_reply = 0
2583 set $kgm_pkt->hdr.seq = 0
2584 set $kgm_pkt->hdr.key = 0
2585 set manual_pkt.input = 1
2586 # dummy to make sure manual packet is executed
2587 set $kgm_dummy = &_mh_execute_header
2588 set $kgm_pkt = (kdp_version_reply_t *)&manual_pkt.data
2589 set $kgm_kdp_version = $kgm_pkt->version
2590 set $kgm_kdp_feature = $kgm_pkt->feature
2591end
2592
2593define kdp-version
2594 kdpversionint
2595 printf "KDP VERSION = %d, FEATURE = 0x%x\n", $kgm_kdp_version, $kgm_kdp_feature
2596end
2597
2598document kdp-version
2599Syntax: kdp-version
2600|Get the KDP protocol version being used by the kernel.
2601end
2602
2603define dumpinfoint
2604 # set up the manual KDP packet
2605 set manual_pkt.input = 0
2606
2607 set manual_pkt.len = sizeof(kdp_dumpinfo_req_t)
2608 set $kgm_pkt = (kdp_dumpinfo_req_t *)manual_pkt.data
2609 set $kgm_pkt->hdr.request = KDP_DUMPINFO
2610 set $kgm_pkt->hdr.len = sizeof(kdp_dumpinfo_req_t)
2611 set $kgm_pkt->hdr.is_reply = 0
2612 set $kgm_pkt->hdr.seq = 0
2613 set $kgm_pkt->hdr.key = 0
2614 set $kgm_pkt->type = $arg0
2615 set $kgm_pkt->name = ""
2616 set $kgm_pkt->destip = ""
2617 set $kgm_pkt->routerip = ""
2618 set $kgm_pkt->port = 0
2619
2620 if $argc > 1
2621 set $kgm_pkt->name = "$arg1"
2622 end
2623 if $argc > 2
2624 set $kgm_pkt->destip = "$arg2"
2625 end
2626 if $argc > 3
2627 set $kgm_pkt->routerip = "$arg3"
2628 end
2629 if $argc > 4
2630 set $kgm_pkt->port = $arg4
2631 end
2632
2633 set manual_pkt.input = 1
2634 # dummy to make sure manual packet is executed
2635 set $kgm_dummy = &_mh_execute_header
91447636
A
2636end
2637
2638define sendcore
7e4a7d39
A
2639 if $argc > 1
2640 dumpinfoint KDP_DUMPINFO_CORE $arg1 $arg0
2641 else
2642 dumpinfoint KDP_DUMPINFO_CORE \0 $arg0
2643 end
91447636
A
2644end
2645
2646document sendcore
7e4a7d39 2647Syntax: sendcore <IP address> [filename]
91447636
A
2648|Configure the kernel to transmit a kernel coredump to a server (kdumpd)
2649|at the specified IP address. This is useful when the remote target has
2650|not been previously configured to transmit coredumps, and you wish to
2651|preserve kernel state for later examination. NOTE: You must issue a "continue"
2652|command after using this macro to trigger the kernel coredump. The kernel
2653|will resume waiting in the debugger after completion of the coredump. You
7e4a7d39
A
2654|may disable coredumps by executing the "disablecore" macro. You can
2655|optionally specify the filename to be used for the generated core file.
2656end
2657
2658define sendsyslog
2659 if $argc > 1
2660 dumpinfoint KDP_DUMPINFO_SYSTEMLOG $arg1 $arg0
2661 else
2662 dumpinfoint KDP_DUMPINFO_SYSTEMLOG \0 $arg0
2663 end
2664end
2665
2666document sendsyslog
2667Syntax: sendsyslog <IP address> [filename]
2668|Configure the kernel to transmit a kernel system log to a server (kdumpd)
2669|at the specified IP address. NOTE: You must issue a "continue"
2670|command after using this macro to trigger the kernel system log. The kernel
2671|will resume waiting in the debugger after completion. You can optionally
2672|specify the name to be used for the generated system log.
2673end
2674
2675define sendpaniclog
2676 if panicstr
2677 if $argc > 1
2678 dumpinfoint KDP_DUMPINFO_PANICLOG $arg1 $arg0
2679 else
2680 dumpinfoint KDP_DUMPINFO_PANICLOG \0 $arg0
2681 end
2682 else
2683 printf "No panic log available.\n"
2684 end
2685end
2686
2687document sendpaniclog
2688Syntax: sendpaniclog <IP address> [filename]
2689|Configure the kernel to transmit a kernel paniclog to a server (kdumpd)
2690|at the specified IP address. NOTE: You must issue a "continue"
2691|command after using this macro to trigger the kernel panic log. The kernel
2692|will resume waiting in the debugger after completion. You can optionally
2693|specify the name to be used for the generated panic log.
2694end
2695
2696define getdumpinfo
2697 dumpinfoint KDP_DUMPINFO_GETINFO
2698 set $kgm_dumpinfo = (kdp_dumpinfo_reply_t *) manual_pkt.data
2699 if $kgm_dumpinfo->type & KDP_DUMPINFO_REBOOT
b7266188 2700 printf "System will reboot after kernel info gets dumped.\n"
7e4a7d39
A
2701 else
2702 printf "Sysem will not reboot after kernel info gets dumped.\n"
2703 end
2704 if $kgm_dumpinfo->type & KDP_DUMPINFO_NORESUME
2705 printf "System will allow a re-attach after a KDP disconnect.\n"
2706 else
2707 printf "System will resume after a KDP disconnect.\n"
2708 end
2709 set $kgm_dumpinfo_type = $kgm_dumpinfo->type & KDP_DUMPINFO_MASK
2710 if $kgm_dumpinfo_type == KDP_DUMPINFO_DISABLE
2711 printf "Kernel not setup for remote dumps.\n"
2712 else
2713 printf "Remote dump type: "
2714 if $kgm_dumpinfo_type == KDP_DUMPINFO_CORE
2715 printf "Core file\n"
2716 end
2717 if $kgm_dumpinfo_type == KDP_DUMPINFO_PANICLOG
2718 printf "Panic log\n"
2719 end
2720 if $kgm_dumpinfo_type == KDP_DUMPINFO_SYSTEMLOG
2721 printf "System log\n"
2722 end
2723
2724 printf "Name: "
2725 if $kgm_dumpinfo->name[0] == '\0'
2726 printf "(autogenerated)\n"
2727 else
2728 printf "%s\n", $kgm_dumpinfo->name
2729 end
2730
2731 printf "Network Info: %s[%d] ", $kgm_dumpinfo->destip, $kgm_dumpinfo->port
2732 if $kgm_dumpinfo->routerip[0] == '\0'
2733 printf "\n"
2734 else
2735 printf "Router: %s\n", $kgm_dumpinfo->routerip
2736 end
2737 end
2738end
2739
2740document getdumpinfo
2741Syntax: getdumpinfo
2742|Retrieve the current remote dump settings.
2743end
2744
2745define setdumpinfo
2746 dumpinfoint KDP_DUMPINFO_SETINFO $arg0 $arg1 $arg2 $arg3
2747end
2748
2749document setdumpinfo
2750Syntax: setdumpinfo <filename> <ip> <router> <port>
2751|Configure the current remote dump settings. Specify \0 if you
2752|want to use the defaults (filename) or previously configured
2753|settings (ip/router). Specify 0 for the port if you wish to
2754|use the previously configured/default setting for that.
91447636
A
2755end
2756
2757define disablecore
7e4a7d39 2758 dumpinfoint KDP_DUMPINFO_DISABLE
91447636
A
2759end
2760
2761document disablecore
2762Syntax: disablecore
2763|Reconfigures the kernel so that it no longer transmits kernel coredumps. This
2764|complements the "sendcore" macro, but it may be used if the kernel has been
2765|configured to transmit coredumps through boot-args as well.
2766end
2767
91447636 2768define switchtocorethread
2d21ac55
A
2769 set $newact = (struct thread *) $arg0
2770 select 0
2771 if ($newact->kernel_stack == 0)
2772 echo This thread does not have a stack.\n
2773 echo continuation:
2774 output/a (unsigned) $newact.continuation
2775 echo \n
2776 else
b0d623f7 2777 if ($kgm_mtype == $kgm_mtype_ppc)
2d21ac55
A
2778 loadcontext $newact->machine->pcb
2779 flushstack
2780 set $pc = $newact->machine->pcb.save_srr0
91447636 2781 else
b0d623f7
A
2782 if (($kgm_mtype & $kgm_mtype_x86_mask) == $kgm_mtype_x86_any)
2783 set $kgm_cstatep = (struct x86_kernel_state *) \
2784 ($newact->kernel_stack + kernel_stack_size \
2785 - sizeof(struct x86_kernel_state))
2d21ac55
A
2786 loadcontext $kgm_cstatep
2787 flushstack
593a1d5f
A
2788 else
2789 echo switchtocorethread not supported on this architecture\n
2790 end
2d21ac55
A
2791 end
2792 showcontext_int
91447636
A
2793 end
2794end
2795
2796document switchtocorethread
2797Syntax: switchtocorethread <address of activation>
2798| The corefile equivalent of "switchtoact". When debugging a kernel coredump
2799| file, this command can be used to examine the execution context and stack
2800| trace for a given thread activation. For example, to view the backtrace
2801| for a thread issue "switchtocorethread <address>", followed by "bt".
2802| Before resuming execution, issue a "resetcorectx" command, to
2803| return to the original execution context. Note that this command
2804| requires gdb support, as documented in Radar 3401283.
2805end
2806
2807define loadcontext
2d21ac55 2808 select 0
b0d623f7 2809 if ($kgm_mtype == $kgm_mtype_ppc)
2d21ac55
A
2810 set $kgm_contextp = (struct savearea *) $arg0
2811 set $pc = $kgm_contextp.save_srr0
2812 set $r1 = $kgm_contextp.save_r1
2813 set $lr = $kgm_contextp.save_lr
2814
2815 set $r2 = $kgm_contextp.save_r2
2816 set $r3 = $kgm_contextp.save_r3
2817 set $r4 = $kgm_contextp.save_r4
2818 set $r5 = $kgm_contextp.save_r5
2819 set $r6 = $kgm_contextp.save_r6
2820 set $r7 = $kgm_contextp.save_r7
2821 set $r8 = $kgm_contextp.save_r8
2822 set $r9 = $kgm_contextp.save_r9
2823 set $r10 = $kgm_contextp.save_r10
2824 set $r11 = $kgm_contextp.save_r11
2825 set $r12 = $kgm_contextp.save_r12
2826 set $r13 = $kgm_contextp.save_r13
2827 set $r14 = $kgm_contextp.save_r14
2828 set $r15 = $kgm_contextp.save_r15
2829 set $r16 = $kgm_contextp.save_r16
2830 set $r17 = $kgm_contextp.save_r17
2831 set $r18 = $kgm_contextp.save_r18
2832 set $r19 = $kgm_contextp.save_r19
2833 set $r20 = $kgm_contextp.save_r20
2834 set $r21 = $kgm_contextp.save_r21
2835 set $r22 = $kgm_contextp.save_r22
2836 set $r23 = $kgm_contextp.save_r23
2837 set $r24 = $kgm_contextp.save_r24
2838 set $r25 = $kgm_contextp.save_r25
2839 set $r26 = $kgm_contextp.save_r26
2840 set $r27 = $kgm_contextp.save_r27
2841 set $r28 = $kgm_contextp.save_r28
2842 set $r29 = $kgm_contextp.save_r29
2843 set $r30 = $kgm_contextp.save_r30
2844 set $r31 = $kgm_contextp.save_r31
2845
2846 set $cr = $kgm_contextp.save_cr
2847 set $ctr = $kgm_contextp.save_ctr
2848 else
b0d623f7
A
2849 if ($kgm_mtype == $kgm_mtype_i386)
2850 set $kgm_contextp = (struct x86_kernel_state *) $arg0
2d21ac55
A
2851 set $ebx = $kgm_contextp->k_ebx
2852 set $ebp = $kgm_contextp->k_ebp
2853 set $edi = $kgm_contextp->k_edi
2854 set $esi = $kgm_contextp->k_esi
2855 set $eip = $kgm_contextp->k_eip
2856 set $pc = $kgm_contextp->k_eip
b0d623f7
A
2857 else
2858 if ($kgm_mtype == $kgm_mtype_x86_64)
2859 set $kgm_contextp = (struct x86_kernel_state *) $arg0
2860 set $rbx = $kgm_contextp->k_rbx
2861 set $rbp = $kgm_contextp->k_rbp
2862 set $r12 = $kgm_contextp->k_r12
2863 set $r13 = $kgm_contextp->k_r13
2864 set $r14 = $kgm_contextp->k_r14
2865 set $r15 = $kgm_contextp->k_r15
2866 set $rip = $kgm_contextp->k_rip
2867 set $pc = $kgm_contextp->k_rip
593a1d5f
A
2868 else
2869 echo loadcontext not supported on this architecture\n
2870 end
2d21ac55 2871 end
b0d623f7 2872 end
91447636
A
2873end
2874
2875define resetcorectx
2d21ac55 2876 select 0
b0d623f7 2877 if ($kgm_mtype == $kgm_mtype_ppc)
2d21ac55
A
2878 set $kgm_corecontext = (struct savearea *) kdp.saved_state
2879 loadcontext $kgm_corecontext
2880 else
b0d623f7 2881 if ($kgm_mtype == $kgm_mtype_i386)
2d21ac55
A
2882 set $kdpstatep = (struct x86_saved_state32 *) kdp.saved_state
2883 set $ebx = $kdpstatep->ebx
2884 set $ebp = $kdpstatep->ebp
2885 set $edi = $kdpstatep->edi
2886 set $esi = $kdpstatep->esi
2887 set $eip = $kdpstatep->eip
2888 set $eax = $kdpstatep->eax
2889 set $ecx = $kdpstatep->ecx
2890 set $edx = $kdpstatep->edx
2891 flushregs
2892 flushstack
2893 set $pc = $kdpstatep->eip
2894 update
593a1d5f
A
2895 else
2896 echo resetcorectx not supported on this architecture\n
2d21ac55
A
2897 end
2898 end
2899 showcontext_int
91447636
A
2900end
2901
2902document resetcorectx
2903Syntax: resetcorectx
2904| The corefile equivalent of "resetctx". Returns to the original
2905| execution context (that of the active thread at the time of the NMI or
2906| panic). This command should be issued if you wish to resume
2907| execution after using the "switchtocorethread" command.
2908end
2909
2910#Helper function for "showallgdbstacks"
2911
2912define showgdbthread
2913 printf " 0x%08x ", $arg0
2914 set $kgm_thread = *(struct thread *)$arg0
2915 printf "0x%08x ", $arg0
2916 printf "%3d ", $kgm_thread.sched_pri
2917 set $kgm_state = $kgm_thread.state
2918 if $kgm_state & 0x80
2919 printf "I"
2920 end
2921 if $kgm_state & 0x40
2922 printf "P"
2923 end
2924 if $kgm_state & 0x20
2925 printf "A"
2926 end
2927 if $kgm_state & 0x10
2928 printf "H"
2929 end
2930 if $kgm_state & 0x08
2931 printf "U"
2932 end
2933 if $kgm_state & 0x04
2934 printf "R"
2935 end
2936 if $kgm_state & 0x02
2937 printf "S"
2938 end
2939 if $kgm_state & 0x01
2940 printf "W\t"
2941 printf "0x%08x ", $kgm_thread.wait_queue
2942 output /a (unsigned) $kgm_thread.wait_event
2d21ac55
A
2943 if ($kgm_thread.uthread != 0)
2944 set $kgm_uthread = (struct uthread *)$kgm_thread.uthread
2945 if ($kgm_uthread->uu_wmesg != 0)
2946 printf " \"%s\"", $kgm_uthread->uu_wmesg
2947 end
2948 end
91447636
A
2949 end
2950 if $arg1 != 0
2951 if ($kgm_thread.kernel_stack != 0)
2952 if ($kgm_thread.reserved_stack != 0)
2953 printf "\n\t\treserved_stack=0x%08x", $kgm_thread.reserved_stack
2954 end
2955 printf "\n\t\tkernel_stack=0x%08x", $kgm_thread.kernel_stack
b0d623f7 2956 if ($kgm_mtype == $kgm_mtype_ppc)
91447636 2957 set $mysp = $kgm_thread.machine.pcb->save_r1
2d21ac55 2958 end
b0d623f7
A
2959 if ($kgm_mtype == $kgm_mtype_i386)
2960 set $kgm_statep = (struct x86_kernel_state *) \
2961 ($kgm_thread->kernel_stack + kernel_stack_size \
2962 - sizeof(struct x86_kernel_state))
91447636
A
2963 set $mysp = $kgm_statep->k_ebp
2964 end
b0d623f7
A
2965 if ($kgm_mtype == $kgm_mtype_arm)
2966 if (((unsigned long)$r7 < ((unsigned long) ($kgm_thread->kernel_stack+kernel_stack_size))) \
2967 && ((unsigned long)$r7 > (unsigned long) ($kgm_thread->kernel_stack)))
2d21ac55
A
2968 set $mysp = $r7
2969 else
2970 set $kgm_statep = (struct arm_saved_state *)$kgm_thread.machine.kstackptr
2971 set $mysp = $kgm_statep->r[7]
2972 end
2973 end
91447636
A
2974 set $prevsp = 0
2975 printf "\n\t\tstacktop=0x%08x", $mysp
2d21ac55
A
2976 if ($arg2 == 0)
2977 switchtoact $arg0
2978 else
2979 switchtocorethread $arg0
2980 end
91447636
A
2981 bt
2982 else
2983 printf "\n\t\t\tcontinuation="
2984 output /a (unsigned) $kgm_thread.continuation
2985 end
2986 printf "\n"
2987 else
2988 printf "\n"
2989 end
2990end
2991
2992#Use of this macro is currently (8/04) blocked by the fact that gdb
2993#stops evaluating macros when encountering an error, such as a failure
2994#to read memory from a certain location. Until this issue (described in
2995#3758949) is addressed, evaluation of this macro may stop upon
2996#encountering such an error.
2997
2998define showallgdbstacks
2d21ac55 2999 set $kgm_head_taskp = &tasks
91447636
A
3000 set $kgm_taskp = (struct task *)($kgm_head_taskp->next)
3001 while $kgm_taskp != $kgm_head_taskp
3002 showtaskheader
3003 showtaskint $kgm_taskp
3004 set $kgm_head_actp = &($kgm_taskp->threads)
3005 set $kgm_actp = (struct thread *)($kgm_taskp->threads.next)
3006 while $kgm_actp != $kgm_head_actp
3007 showactheader
2d21ac55 3008 showgdbthread $kgm_actp 1 0
91447636
A
3009 set $kgm_actp = (struct thread *)($kgm_actp->task_threads.next)
3010 end
3011 printf "\n"
2d21ac55 3012 set $kgm_taskp = (struct task *)($kgm_taskp->tasks.next)
91447636
A
3013 end
3014 resetctx
3015end
3016
3017document showallgdbstacks
3018Syntax: showallgdbstacks
3019| An alternative to "showallstacks". Iterates through the task list and
3020| displays a gdb generated backtrace for each kernel thread. It is
3021| advantageous in that it is much faster than "showallstacks", and
3022| decodes function call arguments and displays source level traces, but
3023| it has the drawback that it doesn't determine if frames belong to
3024| functions from kernel extensions, as with "showallstacks".
3025| This command may terminate prematurely because of a gdb bug
3026| (Radar 3758949), which stops macro evaluation on memory read
3027| errors.
3028end
3029
2d21ac55
A
3030define showallgdbcorestacks
3031 select 0
3032 set $kgm_head_taskp = &tasks
3033 set $kgm_taskp = (struct task *)($kgm_head_taskp->next)
3034 while $kgm_taskp != $kgm_head_taskp
3035 showtaskheader
3036 showtaskint $kgm_taskp
3037 set $kgm_head_actp = &($kgm_taskp->threads)
3038 set $kgm_actp = (struct thread *)($kgm_taskp->threads.next)
3039 while $kgm_actp != $kgm_head_actp
3040 showactheader
3041 showgdbthread $kgm_actp 1 1
3042 set $kgm_actp = (struct thread *)($kgm_actp->task_threads.next)
3043 end
3044 printf "\n"
3045 set $kgm_taskp = (struct task *)($kgm_taskp->tasks.next)
3046 end
3047 resetcorectx
3048end
3049
3050
3051document showallgdbcorestacks
3052Syntax: showallgdbcorestacks
3053|Corefile version of "showallgdbstacks"
3054end
3055
3056
91447636 3057define switchtouserthread
2d21ac55 3058 select 0
b0d623f7 3059 if ($kgm_mtype == $kgm_mtype_ppc)
91447636
A
3060 if ($kdp_act_counter == 0)
3061 set $kdpstate = (struct savearea *) kdp.saved_state
3062 end
3063 set $kdp_act_counter = $kdp_act_counter + 1
3064 set $newact = (struct thread *) $arg0
3065 _kgm_flush_loop
3066 set $checkpc = $newact->machine->upcb.save_srr0
3067 if ($checkpc == 0)
3068 echo This activation does not appear to have
3069 echo \20 a valid user context.\n
3070 else
3071 set (struct savearea *) kdp.saved_state=$newact->machine->upcb
3072 set $pc = $checkpc
3073#flush and update seem to be executed lazily by gdb on Tiger, hence the
3074#repeated invocations - see 3743135
3075 _kgm_flush_loop
3076# This works because the new pmap is used only for reads
3077 set kdp_pmap = $newact->task->map->pmap
3078 _kgm_flush_loop
3079 _kgm_update_loop
3080 end
3081 else
3082 echo switchtouserthread not implemented for this architecture.\n
3083 end
3084end
3085
3086document switchtouserthread
3087Syntax: switchtouserthread <address of thread>
3088| Analogous to switchtoact, but switches to the user context of a
3089| specified thread address. Similar to the "showuserstack"
3090| command, but this command does not return gdb to the kernel context
3091| immediately. This is to assist with the following (rather risky)
3092| manoeuvre - upon switching to the user context and virtual address
3093| space, the user may choose to call remove-symbol-file on the
3094| mach_kernel symbol file, and then add-symbol-file on the user space
3095| binary's symfile. gdb can then generate symbolic backtraces
3096| for the user space thread. To return to the
3097| kernel context and virtual address space, the process must be
3098| reversed, i.e. call remove-symbol-file on the user space symbols, and
3099| then add-symbol-file on the appropriate mach_kernel, and issue the
3100| "resetstacks" command. Note that gdb may not react kindly to all these
3101| symbol file switches. The same restrictions that apply to "showuserstack"
3102| apply here - pages that have been paged out cannot be read while in the
3103| debugger context, so backtraces may terminate early.
3104| If the virtual addresses in the stack trace do not conflict with those
3105| of symbols in the kernel's address space, it may be sufficient to
3106| just do an add-symbol-file on the user space binary's symbol file.
3107| Note that while this command works on Panther's gdb, an issue
3108| with Tiger gdb (3743135) appears to hamper the evaluation of this
3109| macro in some cases.
3110end
3111
3112define showmetaclass
91447636
A
3113 set $kgm_metaclassp = (OSMetaClass *)$arg0
3114 printf "%-5d", $kgm_metaclassp->instanceCount
3115 printf "x %5d bytes", $kgm_metaclassp->classSize
3116 printf " %s\n", $kgm_metaclassp->className->string
3117end
3118
0c530ab8
A
3119define showstring
3120 printf "\"%s\"", ((OSString *)$arg0)->string
3121end
3122
3123define shownumber
3124 printf "%lld", ((OSNumber *)$arg0)->value
3125end
3126
3127define showboolean
3128 if ($arg0 == gOSBooleanFalse)
3129 printf "No"
3130 else
3131 printf "Yes"
3132 end
3133end
3134
b0d623f7
A
3135define showdatabytes
3136 set $kgm_data = (OSData *)$arg0
3137
3138 printf "<"
3139 set $kgm_datap = (const unsigned char *) $kgm_data->data
3140 set $kgm_idx = 0
3141 while ( $kgm_idx < $kgm_data->length )
3142 printf "%02X", *$kgm_datap
3143 set $kgm_datap = $kgm_datap + 1
3144 set $kgm_idx = $kgm_idx + 1
3145 end
3146 printf ">\n"
3147end
3148
0c530ab8
A
3149define showdata
3150 set $kgm_data = (OSData *)$arg0
3151
3152 printf "<"
3153 set $kgm_datap = (const unsigned char *) $kgm_data->data
3154
3155 set $kgm_printstr = 0
3156 if (0 == (3 & (unsigned int)$kgm_datap) && ($kgm_data->length >= 3))
3157 set $kgm_bytes = *(unsigned int *) $kgm_datap
3158 if (0xffff0000 & $kgm_bytes)
3159 set $kgm_idx = 0
3160 set $kgm_printstr = 1
3161 while ($kgm_idx++ < 4)
3162 set $kgm_bytes = $kgm_bytes >> 8
3163 set $kgm_char = 0xff & $kgm_bytes
3164 if ($kgm_char && (($kgm_char < 0x20) || ($kgm_char > 0x7e)))
3165 set $kgm_printstr = 0
3166 end
3167 end
3168 end
3169 end
3170
3171 set $kgm_idx = 0
3172 if ($kgm_printstr)
3173 set $kgm_quoted = 0
3174 while ($kgm_idx < $kgm_data->length)
3175 set $kgm_char = $kgm_datap[$kgm_idx++]
3176 if ($kgm_char)
3177 if (0 == $kgm_quoted)
3178 set $kgm_quoted = 1
3179 if ($kgm_idx > 1)
3180 printf ",\""
3181 else
3182 printf "\""
3183 end
3184 end
3185 printf "%c", $kgm_char
3186 else
3187 if ($kgm_quoted)
3188 set $kgm_quoted = 0
3189 printf "\""
3190 end
3191 end
3192 end
3193 if ($kgm_quoted)
3194 printf "\""
3195 end
3196 else
3197 if (0 == (3 & (unsigned int)$kgm_datap))
3198 while (($kgm_idx + 3) <= $kgm_data->length)
3199 printf "%08x", *(unsigned int *) &$kgm_datap[$kgm_idx]
3200 set $kgm_idx = $kgm_idx + 4
3201 end
3202 end
3203 while ($kgm_idx < $kgm_data->length)
3204 printf "%02x", $kgm_datap[$kgm_idx++]
3205 end
3206 end
3207 printf ">"
3208end
3209
3210define showdictionaryint
3211 set $kgm$arg0_dict = (OSDictionary *)$arg1
3212
3213 printf "{"
3214 set $kgm$arg0_idx = 0
3215 while ($kgm$arg0_idx < $kgm$arg0_dict->count)
3216 set $kgm_obj = $kgm$arg0_dict->dictionary[$kgm$arg0_idx].key
3217 showobjectint _$arg0 $kgm_obj
3218 printf "="
3219 set $kgm_obj = $kgm$arg0_dict->dictionary[$kgm$arg0_idx++].value
3220 showobjectint _$arg0 $kgm_obj
3221 if ($kgm$arg0_idx < $kgm$arg0_dict->count)
3222 printf ","
3223 end
3224 end
3225 printf "}"
3226end
3227
3228define indent
3229 set $kgm_idx = 0
3230 while ($kgm_idx < $arg0)
3231 if ($arg1 & (1 << $kgm_idx++))
3232 printf "| "
3233 else
3234 printf " "
3235 end
3236 end
3237end
3238
3239define showregdictionary
3240 indent $kgm_reg_depth+2 $arg1
3241 printf "{\n"
3242
3243 set $kgm_reg_idx = 0
3244 while ($kgm_reg_idx < $arg0->count)
3245 indent $kgm_reg_depth+2 $arg1
3246 printf " "
3247 set $kgm_obj = $arg0->dictionary[$kgm_reg_idx].key
3248 showobjectint _ $kgm_obj
3249 printf " = "
3250
3251 set $kgm_obj = $arg0->dictionary[$kgm_reg_idx++].value
3252 showobjectint _ $kgm_obj
3253 printf "\n"
3254 end
3255 indent $kgm_reg_depth+2 $arg1
3256 printf "}\n"
3257end
3258
3259
3260define showarraysetint
3261 set $kgm$arg0_array = (OSArray *)$arg1
3262
3263 set $kgm$arg0_idx = 0
3264 while ($kgm$arg0_idx < $kgm$arg0_array->count)
3265 set $kgm_obj = $kgm$arg0_array->array[$kgm$arg0_idx++]
3266 showobjectint _$arg0 $kgm_obj
3267 if ($kgm$arg0_idx < $kgm$arg0_array->count)
3268 printf ","
3269 end
3270 end
3271end
3272
3273define showarrayint
3274 printf "("
3275 showarraysetint $arg0 $arg1
3276 printf ")"
3277end
3278
3279define showsetint
3280 set $kgm_array = ((OSSet *)$arg1)->members
3281 printf "["
3282 showarraysetint $arg0 $kgm_array
3283 printf "]"
3284end
3285
3286
3287define showobjectint
3288 set $kgm_obj = (OSObject *) $arg1
3289 set $kgm_vt = *((void **) $arg1)
3290
b0d623f7 3291 if ($kgm_lp64 || $kgm_mtype == $kgm_mtype_arm)
c910b4d9
A
3292 set $kgm_vt = $kgm_vt - 2 * sizeof(void *)
3293 end
3294
0c530ab8 3295 if ($kgm_show_object_addrs)
b0d623f7
A
3296 printf "`object "
3297 showptr $arg1
3298 printf ", vt "
3299 output /a (unsigned long) $kgm_vt
3300 if ($kgm_show_object_retain)
3301 printf ", retain count %d, container retain %d", (0xffff & $kgm_obj->retainCount), $kgm_obj->retainCount >> 16
3302 end
3303 printf "` "
0c530ab8
A
3304 end
3305
b0d623f7
A
3306 # No multiple-inheritance
3307 set $kgm_shown = 0
3308 if ($kgm_vt == &_ZTV8OSString)
3309 showstring $arg1
3310 set $kgm_shown = 1
3311 end
3312 if ($kgm_vt == &_ZTV8OSSymbol)
0c530ab8 3313 showstring $arg1
b0d623f7
A
3314 set $kgm_shown = 1
3315 end
3316 if ($kgm_vt == &_ZTV8OSNumber)
0c530ab8 3317 shownumber $arg1
b0d623f7
A
3318 set $kgm_shown = 1
3319 end
3320 if ($kgm_vt == &_ZTV6OSData)
3321 if $kgm_show_data_alwaysbytes == 1
3322 showdatabytes $arg1
3323 else
3324 showdata $arg1
3325 end
3326 set $kgm_shown = 1
3327 end
3328 if ($kgm_vt == &_ZTV9OSBoolean)
3329 showboolean $arg1
3330 set $kgm_shown = 1
3331 end
3332 if ($kgm_vt == &_ZTV12OSDictionary)
3333 showdictionaryint _$arg0 $arg1
3334 set $kgm_shown = 1
3335 end
3336 if ($kgm_vt == &_ZTV7OSArray)
3337 showarrayint _$arg0 $arg1
3338 set $kgm_shown = 1
3339 end
3340 if ($kgm_vt == &_ZTV5OSSet)
3341 showsetint _$arg0 $arg1
3342 set $kgm_shown = 1
3343 end
3344
3345 if ($kgm_shown != 1)
3346 if ($kgm_show_object_addrs == 0)
3347 printf "`object "
3348 showptr $arg1
3349 printf ", vt "
3350 output /a (unsigned long) $kgm_vt
3351 printf "`"
3352 end
0c530ab8
A
3353 end
3354end
3355
3356define showobject
3357 set $kgm_save = $kgm_show_object_addrs
3358 set $kgm_show_object_addrs = 1
3359 set $kgm_show_object_retain = 1
3360 showobjectint _ $arg0
3361 set $kgm_show_object_addrs = $kgm_save
3362 set $kgm_show_object_retain = 0
3363 printf "\n"
3364end
3365document showobject
2d21ac55 3366Syntax: (gdb) showobject <object address>
0c530ab8
A
3367| Show info about an OSObject - its vtable ptr and retain count.
3368| If the object is a simple container class, more info will be shown.
0c530ab8
A
3369end
3370
3371define dictget
3372 set $kgm_dictp = (OSDictionary *)$arg0
3373 set $kgm_keyp = (const OSSymbol *)$arg1
3374 set $kgm_idx = 0
3375 set $kgm_result = 0
3376 while (($kgm_idx < $kgm_dictp->count) && ($kgm_result == 0))
3377 if ($kgm_keyp == $kgm_dictp->dictionary[$kgm_idx].key)
3378 set $kgm_result = $kgm_dictp->dictionary[$kgm_idx].value
3379 end
3380 set $kgm_idx = $kgm_idx + 1
3381 end
3382end
3383
3384
b0d623f7 3385define _registryentryrecurseinit
0c530ab8
A
3386 set $kgm_re = (IOService *)$arg1
3387 set $kgm$arg0_stack = (unsigned long long) $arg2
3388
3389 if ($arg3)
3390 set $kgm$arg0_stack = $kgm$arg0_stack | (1ULL << $kgm_reg_depth)
3391 else
3392 set $kgm$arg0_stack = $kgm$arg0_stack & ~(1ULL << $kgm_reg_depth)
3393 end
3394
3395 dictget $kgm_re->fRegistryTable $kgm_childkey
3396 set $kgm$arg0_child_array = (OSArray *) $kgm_result
3397
3398 if ($kgm$arg0_child_array)
3399 set $kgm$arg0_child_count = $kgm$arg0_child_array->count
3400 else
3401 set $kgm$arg0_child_count = 0
3402 end
3403
3404 if ($kgm$arg0_child_count)
3405 set $kgm$arg0_stack = $kgm$arg0_stack | (2ULL << $kgm_reg_depth)
3406 else
3407 set $kgm$arg0_stack = $kgm$arg0_stack & ~(2ULL << $kgm_reg_depth)
3408 end
b0d623f7 3409end
0c530ab8 3410
b0d623f7
A
3411define findregistryentryrecurse
3412 set $kgm_registry_entry = 0
3413 _registryentryrecurseinit $arg0 $arg1 $arg2 $arg3
0c530ab8
A
3414
3415 dictget $kgm_re->fRegistryTable $kgm_namekey
3416 if ($kgm_result == 0)
3417 dictget $kgm_re->fRegistryTable gIONameKey
3418 end
3419 if ($kgm_result == 0)
3420 dictget $kgm_re->fPropertyTable gIOClassKey
3421 end
3422
3423 if ($kgm_result != 0)
b0d623f7
A
3424 set $str = ((OSString *) $kgm_result)->string
3425 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
3426 if $kgm_findregistry_verbose
3427 echo .
3428 end
0c530ab8 3429
b0d623f7
A
3430 if $kgm_strcmp_result == 0
3431 if $kgm_findregistry_verbose
3432 printf "\n%s:\n | ", ((OSString *) $kgm_result)->string
3433 showobject $kgm_re
3434 printf " | "
3435 print $kgm_re
3436 end
3437
3438 # if we want to show everything, then don't populate $kgm_registry_entry
3439 if !$kgm_findregistry_continue
3440 set $kgm_registry_entry = $kgm_re
3441 end
3442 end
3443 end
0c530ab8 3444
b0d623f7
A
3445 # recurse
3446 if (!$kgm_registry_entry && ($kgm$arg0_child_count != 0))
3447 set $kgm_reg_depth = $kgm_reg_depth + 1
3448 set $kgm$arg0_child_idx = 0
3449
3450 while ($kgm$arg0_child_idx < $kgm$arg0_child_count)
3451 set $kgm_re = $kgm$arg0_child_array->array[$kgm$arg0_child_idx++]
3452 set $kgm_more_sib = ($kgm$arg0_child_idx < $kgm$arg0_child_count)
3453 if $kgm_reg_depth >= $kgm_reg_depth_max + 1
3454 loop_break
3455 end
3456 findregistryentryrecurse _$arg0 $kgm_re $kgm$arg0_stack $kgm_more_sib
3457 if $kgm_registry_entry
3458 loop_break
3459 end
3460 end
3461 set $kgm_reg_depth = $kgm_reg_depth - 1
c910b4d9 3462 end
b0d623f7 3463end
0c530ab8 3464
b0d623f7
A
3465define findregdictvalue
3466 set $kgm_registry_value = 0
3467 set $kgm_reg_idx = 0
3468 while ($kgm_reg_idx < $arg0->count)
3469 set $kgm_obj = $arg0->dictionary + $kgm_reg_idx
3470 set $str = ((OSString *)$kgm_obj->key)->string
3471 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
3472
3473 if $kgm_strcmp_result == 0
3474 set $kgm_registry_value = $kgm_obj->value
3475 if $kgm_findregistry_verbose
3476 showobject $kgm_registry_value
3477 print $kgm_registry_value
3478 end
3479 loop_break
0c530ab8 3480 end
b0d623f7 3481 set $kgm_reg_idx = $kgm_reg_idx + 1
0c530ab8 3482 end
b0d623f7 3483end
0c530ab8 3484
b0d623f7
A
3485define setfindregistrystr
3486 set $kgm_reg_find_str0 = 0
3487 set $kgm_reg_find_str1 = 0
3488 set $kgm_reg_find_str2 = 0
3489 set $kgm_reg_find_str3 = 0
3490 set $kgm_reg_find_str4 = 0
3491 set $kgm_reg_find_str5 = 0
3492 set $kgm_reg_find_str6 = 0
3493 set $kgm_reg_find_str7 = 0
3494 set $kgm_reg_find_str8 = 0
3495
3496 if $argc > 0
3497 set $kgm_reg_find_str0 = $arg0
3498 end
3499 if $argc > 1
3500 set $kgm_reg_find_str1 = $arg1
3501 end
3502 if $argc > 2
3503 set $kgm_reg_find_str2 = $arg2
3504 end
3505 if $argc > 3
3506 set $kgm_reg_find_str3 = $arg3
3507 end
3508 if $argc > 4
3509 set $kgm_reg_find_str4 = $arg4
3510 end
3511 if $argc > 5
3512 set $kgm_reg_find_str5 = $arg5
3513 end
3514 if $argc > 6
3515 set $kgm_reg_find_str6 = $arg6
3516 end
3517 if $argc > 7
3518 set $kgm_reg_find_str7 = $arg7
3519 end
3520 if $argc > 8
3521 set $kgm_reg_find_str8 = $arg8
3522 end
3523end
3524
3525document setfindregistrystr
3526Syntax: (gdb) setfindregistrystr [a] [b] [c] [d] [e] [f] [g] [h] [i]
3527| Store an encoded string into up to 9 arguments for use by
3528| findregistryprop or findregistryentry. The arguments are created
3529| through calls to strcmp_arg_pack64
3530end
3531
3532define _findregistryprop
3533 set $reg = (IOService *) $arg0
3534 set $kgm_props = $reg->fPropertyTable
3535 set $kgm_findregistry_verbose = 0
3536
3537 findregdictvalue $kgm_props
3538end
3539
3540define findregistryprop
3541 set $reg = (IOService *) $arg0
3542 set $kgm_props = $reg->fPropertyTable
3543
3544 set $kgm_findregistry_verbose = 1
3545 findregdictvalue $kgm_props
3546end
3547
3548document findregistryprop
3549Syntax: (gdb) findregistryprop <entry>
3550| Given a registry entry, print out the contents for the property that matches
3551| the encoded string specified via setfindregistrystr.
3552|
3553| For example, the following will print out the "intel-pic" property stored in
3554| the AppleACPIPlatformExpert registry entry $pe_entry:
3555| strcmp_arg_pack64 'i' 'n' 't' 'e' 'l' '-' 'p' 'i'
3556| set $intel_pi = $kgm_strcmp_arg
3557| strcmp_arg_pack64 'c' 0 0 0 0 0 0 0
3558| set $c = $kgm_strcmp_arg
3559| setfindregistrystr $intel_pi $c
3560| findregistryprop $pe_entry
3561end
3562
3563define findregistryentryint
7e4a7d39
A
3564 if !$kgm_reg_plane
3565 set $kgm_reg_plane = (IORegistryPlane *) gIOServicePlane
3566 end
3567
3568 if !$kgm_reg_plane
3569 printf "Please load kgmacros after KDP attaching to the target.\n"
3570 else
3571 set $kgm_namekey = (OSSymbol *) $kgm_reg_plane->nameKey
3572 set $kgm_childkey = (OSSymbol *) $kgm_reg_plane->keys[1]
3573 if $kgm_findregistry_verbose
3574 printf "Searching"
3575 end
3576 findregistryentryrecurse _ $arg0 0 0
b0d623f7 3577 end
b0d623f7
A
3578end
3579
3580define _findregistryentry
3581 set $kgm_findregistry_verbose = 0
3582 set $kgm_findregistry_continue = 0
3583 set $kgm_reg_depth = 0
3584
3585 findregistryentryint gRegistryRoot
3586end
3587
3588define findregistryentry
3589 set $kgm_findregistry_verbose = 1
3590 set $kgm_findregistry_continue = 0
3591 set $kgm_reg_depth = 0
3592
3593 findregistryentryint gRegistryRoot
3594end
3595
3596define findregistryentries
3597 set $kgm_findregistry_verbose = 1
3598 set $kgm_findregistry_continue = 1
3599 set $kgm_reg_depth = 0
3600
3601 findregistryentryint gRegistryRoot
3602end
3603
3604document findregistryentry
3605Syntax: (gdb) findregistryentry
3606| Search for a registry entry that matches the encoded string specified through
3607| setfindregistrystr. You can alter the search depth through use of
3608| $kgm_reg_depth_max.
3609|
3610| For example, the following will pull out the AppleACPIPlatformExpert registry
3611| entry:
3612| strcmp_arg_pack64 'A' 'p' 'p' 'l' 'e' 'A' 'C' 'P'
3613| set $AppleACP = $kgm_strcmp_arg
3614| strcmp_arg_pack64 'I' 'P' 'l' 'a' 't' 'f' 'o' 'r'
3615| set $IPlatfor = $kgm_strcmp_arg
3616| strcmp_arg_pack64 'm' 'E' 'x' 'p' 'e' 'r' 't' 0
3617| set $mExpert = $kgm_strcmp_arg
3618| setfindregistrystr $AppleACP $IPlatfor $mExpert
3619| findregistryentry
3620end
3621
3622document findregistryentries
3623Syntax: (gdb) findregistryentries
3624| Search for all registry entries that match the encoded string specified through
3625| setfindregistrystr. You can alter the search depth through use of
3626| $kgm_reg_depth_max. See findregistryentry for an example of how to encode a string.
3627end
3628
3629
3630define showregistryentryrecurse
3631 _registryentryrecurseinit $arg0 $arg1 $arg2 $arg3
3632
3633 indent $kgm_reg_depth $kgm$arg0_stack
3634 printf "+-o "
3635
3636 dictget $kgm_re->fRegistryTable $kgm_namekey
3637 if ($kgm_result == 0)
3638 dictget $kgm_re->fRegistryTable gIONameKey
3639 end
3640 if ($kgm_result == 0)
3641 dictget $kgm_re->fPropertyTable gIOClassKey
3642 end
3643
3644 if ($kgm_result != 0)
3645 printf "%s", ((OSString *)$kgm_result)->string
3646 else
3647 if (((IOService*)$kgm_re)->pwrMgt && ((IOService*)$kgm_re)->pwrMgt->Name)
3648 printf "%s", ((IOService*)$kgm_re)->pwrMgt->Name
3649 else
3650# printf ", guessclass "
3651# guessclass $kgm_re
3652 printf "??"
3653 end
3654 end
3655
3656
3657 printf " <object "
3658 showptr $kgm_re
3659 printf ", id 0x%llx, ", $kgm_re->IORegistryEntry::reserved->fRegistryEntryID
3660 printf "vtable "
3661 set $kgm_vt = (unsigned long) *(void**) $kgm_re
3662 if ($kgm_lp64 || $kgm_mtype == $kgm_mtype_arm)
3663 set $kgm_vt = $kgm_vt - 2 * sizeof(void *)
3664 end
3665 output /a $kgm_vt
3666
3667 if ($kgm_vt != &_ZTV15IORegistryEntry)
3668 printf ", "
3669 set $kgm_state = $kgm_re->__state[0]
3670 # kIOServiceRegisteredState
3671 if (0 == ($kgm_state & 2))
3672 printf "!"
3673 end
3674 printf "registered, "
3675 # kIOServiceMatchedState
3676 if (0 == ($kgm_state & 4))
3677 printf "!"
3678 end
3679 printf "matched, "
3680 # kIOServiceInactiveState
3681 if ($kgm_state & 1)
3682 printf "in"
3683 end
3684 printf "active, busy %d, retain count %d", (0xff & $kgm_re->__state[1]), (0xffff & $kgm_re->retainCount)
3685 end
3686 printf ">\n"
3687
3688 if ($kgm_show_props)
3689 set $kgm_props = $kgm_re->fPropertyTable
3690 showregdictionary $kgm_props $kgm$arg0_stack
0c530ab8
A
3691 end
3692
3693 # recurse
3694 if ($kgm$arg0_child_count != 0)
3695
b0d623f7
A
3696 set $kgm_reg_depth = $kgm_reg_depth + 1
3697 set $kgm$arg0_child_idx = 0
0c530ab8 3698
b0d623f7
A
3699 while ($kgm$arg0_child_idx < $kgm$arg0_child_count)
3700 set $kgm_re = $kgm$arg0_child_array->array[$kgm$arg0_child_idx++]
3701 set $kgm_more_sib = ($kgm$arg0_child_idx < $kgm$arg0_child_count)
3702 if $kgm_reg_depth >= $kgm_reg_depth_max + 1
3703 loop_break
3704 end
3705 showregistryentryrecurse _$arg0 $kgm_re $kgm$arg0_stack $kgm_more_sib
3706 end
0c530ab8 3707
b0d623f7 3708 set $kgm_reg_depth = $kgm_reg_depth - 1
0c530ab8
A
3709 end
3710end
3711
3712define showregistryentryint
7e4a7d39
A
3713 if !$kgm_reg_plane
3714 set $kgm_reg_plane = (IORegistryPlane *) gIOServicePlane
3715 end
0c530ab8 3716
7e4a7d39
A
3717 if !$kgm_reg_plane
3718 printf "Please load kgmacros after KDP attaching to the target.\n"
3719 else
3720 set $kgm_namekey = (OSSymbol *) $kgm_reg_plane->nameKey
3721 set $kgm_childkey = (OSSymbol *) $kgm_reg_plane->keys[1]
3722 showregistryentryrecurse _ $arg0 0 0
3723 end
0c530ab8
A
3724end
3725
3726define showregistry
3727 set $kgm_reg_depth = 0
3728 set $kgm_show_props = 0
3729 showregistryentryint gRegistryRoot
3730end
3731document showregistry
2d21ac55 3732Syntax: (gdb) showregistry
b0d623f7
A
3733| Show info about all registry entries in the current plane. You can specify the maximum
3734| display depth with $kgm_reg_depth_max.
0c530ab8
A
3735end
3736
3737define showregistryprops
3738 set $kgm_reg_depth = 0
3739 set $kgm_show_props = 1
3740 showregistryentryint gRegistryRoot
3741end
3742document showregistryprops
2d21ac55 3743Syntax: (gdb) showregistryprops
0c530ab8
A
3744| Show info about all registry entries in the current plane, and their properties.
3745| set $kgm_show_object_addrs = 1 and/or set $kgm_show_object_retain = 1 will display
3746| more verbose information
0c530ab8
A
3747end
3748
3749define showregistryentry
3750 set $kgm_reg_depth = 0
3751 set $kgm_show_props = 1
3752 showregistryentryint $arg0
3753end
3754document showregistryentry
2d21ac55 3755Syntax: (gdb) showregistryentry <object address>
0c530ab8 3756| Show info about a registry entry; its properties and descendants in the current plane.
0c530ab8
A
3757end
3758
3759define setregistryplane
b0d623f7
A
3760 if ($arg0 != 0)
3761 set $kgm_reg_plane = (IORegistryPlane *) $arg0
0c530ab8 3762 else
b0d623f7
A
3763 showobjectint _ gIORegistryPlanes
3764 printf "\n"
0c530ab8
A
3765 end
3766end
3767document setregistryplane
2d21ac55 3768Syntax: (gdb) setregistryplane <plane object address>
0c530ab8
A
3769| Set the plane to be used for the iokit registry macros. An argument of zero will
3770| display known planes.
0c530ab8
A
3771end
3772
3773define guessclass
4452a7af 3774 set $kgm_classidx = 0
0c530ab8
A
3775 set $kgm_lookvt = *((void **) $arg0)
3776 set $kgm_bestvt = (void *) 0
3777 set $kgm_bestidx = 0
3778
4452a7af 3779 while $kgm_classidx < sAllClassesDict->count
6601e61a 3780 set $kgm_meta = (OSMetaClass *) sAllClassesDict->dictionary[$kgm_classidx].value
0c530ab8
A
3781
3782 set $kgm_vt = *((void **) $kgm_meta)
3783
3784 if (($kgm_vt > $kgm_bestvt) && ($kgm_vt < $kgm_lookvt))
3785 set $kgm_bestvt = $kgm_vt
3786 set $kgm_bestidx = $kgm_classidx
3787 end
6601e61a 3788 set $kgm_classidx = $kgm_classidx + 1
4452a7af 3789 end
0c530ab8 3790 printf "%s", sAllClassesDict->dictionary[$kgm_bestidx].key->string
4452a7af 3791end
0c530ab8
A
3792
3793define showallclasses
3794 set $kgm_classidx = 0
3795 while $kgm_classidx < sAllClassesDict->count
3796 set $kgm_meta = (OSMetaClass *) sAllClassesDict->dictionary[$kgm_classidx++].value
3797 showmetaclass $kgm_meta
3798 end
3799end
3800
91447636 3801document showallclasses
2d21ac55 3802Syntax: (gdb) showallclasses
91447636 3803| Show the instance counts and ivar size of all OSObject subclasses. See ioclasscount man page for details.
91447636
A
3804end
3805
3806define showioalloc
3807 printf " Instance allocation = 0x%08lx = %4ld K\n", (int) debug_ivars_size, ((int) debug_ivars_size) / 1024
3808 printf "Container allocation = 0x%08lx = %4ld K\n", (int) debug_container_malloc_size, ((int) debug_container_malloc_size) / 1024
3809 printf " IOMalloc allocation = 0x%08lx = %4ld K\n", (int) debug_iomalloc_size, ((int) debug_iomalloc_size) / 1024
3810 printf " Pageable allocation = 0x%08lx = %4ld K\n", (vm_size_t) debug_iomallocpageable_size, ((vm_size_t) debug_iomallocpageable_size) / 1024
3811end
3812
3813document showioalloc
2d21ac55 3814Syntax: (gdb) showioalloc
91447636 3815| Show some accounting of memory allocated by IOKit allocators. See ioalloccount man page for details.
2d21ac55
A
3816end
3817
3818define showosobjecttracking
3819 set $kgm_next = (OSObjectTracking *) gOSObjectTrackList.next
3820 while $kgm_next != &gOSObjectTrackList
3821 set $obj = (OSObject *) ($kgm_next+1)
3822 showobject $obj
3823 set $kgm_idx = 0
3824 while $kgm_idx < (sizeof($kgm_next->bt) / sizeof($kgm_next->bt[0]))
b0d623f7 3825 if ((unsigned long) $kgm_next->bt[$kgm_idx] > (unsigned long) &last_kernel_symbol)
2d21ac55
A
3826 showkmodaddr $kgm_next->bt[$kgm_idx]
3827 printf "\n"
3828 else
b0d623f7
A
3829 if ((unsigned long) $kgm_next->bt[$kgm_idx] > 0)
3830 output /a $kgm_next->bt[$kgm_idx]
2d21ac55
A
3831 printf "\n"
3832 end
3833 end
3834 set $kgm_idx = $kgm_idx + 1
3835 end
3836 printf "\n"
3837 set $kgm_next = (OSObjectTracking *) $kgm_next->link.next
3838 end
3839end
3840
3841document showosobjecttracking
3842Syntax: (gdb) showosobjecttracking
3843| Show the list of tracked OSObject allocations with backtraces.
3844| Boot with the kOSTraceObjectAlloc (0x00400000) io debug flag set.
3845| Set gOSObjectTrackThread to 1 or a thread_t to capture new OSObjects allocated by a thread or all threads.
91447636 3846end
0c530ab8 3847
b0d623f7
A
3848define readphysint
3849 set $kgm_readphysint_result = 0xBAD10AD
3850 # set up the manual KDP packet
3851 set manual_pkt.input = 0
3852 set manual_pkt.len = sizeof(kdp_readphysmem64_req_t)
3853 set $kgm_pkt = (kdp_readphysmem64_req_t *)&manual_pkt.data
3854 set $kgm_pkt->hdr.request = KDP_READPHYSMEM64
3855 set $kgm_pkt->hdr.len = sizeof(kdp_readphysmem64_req_t)
3856 set $kgm_pkt->hdr.is_reply = 0
3857 set $kgm_pkt->hdr.seq = 0
3858 set $kgm_pkt->hdr.key = 0
3859 set $kgm_pkt->address = (uint64_t)$arg0
3860 set $kgm_pkt->nbytes = $arg1 >> 3
3861 set $kgm_pkt->lcpu = $arg2
3862 set manual_pkt.input = 1
3863 # dummy to make sure manual packet is executed
3864 set $kgm_dummy = &_mh_execute_header
3865 set $kgm_pkt = (kdp_readphysmem64_reply_t *)&manual_pkt.data
3866 if ($kgm_pkt->error == 0)
3867 if $arg1 == 8
3868 set $kgm_readphysint_result = *((uint8_t *)$kgm_pkt->data)
3869 end
3870 if $arg1 == 16
3871 set $kgm_readphysint_result = *((uint16_t *)$kgm_pkt->data)
3872 end
3873 if $arg1 == 32
3874 set $kgm_readphysint_result = *((uint32_t *)$kgm_pkt->data)
3875 end
3876 if $arg1 == 64
3877 set $kgm_readphysint_result = *((uint64_t *)$kgm_pkt->data)
3878 end
3879 end
3880end
3881
3882define readphys8
3883 readphysint $arg0 8 $kgm_lcpu_self
3884 output /a $arg0
3885 printf ":\t0x%02hhx\n", $kgm_readphysint_result
3886 set $kgm_readphys_result = (uint64_t)$kgm_readphysint_result
3887end
3888
3889define readphys16
3890 readphysint $arg0 16 $kgm_lcpu_self
3891 output /a $arg0
3892 printf ":\t0x%04hx\n", $kgm_readphysint_result
3893 set $kgm_readphys_result = (uint64_t)$kgm_readphysint_result
3894end
3895
3896define readphys32
3897 readphysint $arg0 32 $kgm_lcpu_self
3898 output /a $arg0
3899 printf ":\t0x%08x\n", $kgm_readphysint_result
3900 set $kgm_readphys_result = (uint64_t)$kgm_readphysint_result
0c530ab8
A
3901end
3902
3903define readphys64
b0d623f7
A
3904 readphysint $arg0 64 $kgm_lcpu_self
3905 output /a $arg0
3906 printf ":\t0x%016llx\n", $kgm_readphysint_result
3907 set $kgm_readphys_result = (uint64_t)$kgm_readphysint_result
3908end
3909
3910define readphys
3911 readphys32 $arg0
3912end
3913
3914document readphys8
3915| See readphys64
3916end
3917
3918document readphys16
3919| See readphys64
0c530ab8
A
3920end
3921
b0d623f7
A
3922document readphys32
3923| See readphys64
0c530ab8
A
3924end
3925
3926document readphys64
b0d623f7
A
3927| The argument is interpreted as a physical address, and the 64-bit word
3928| addressed is displayed. Saves 64-bit result in $kgm_readphys_result.
3929end
3930
3931define writephysint
3932 # set up the manual KDP packet
3933 set manual_pkt.input = 0
3934 set manual_pkt.len = sizeof(kdp_writephysmem64_req_t)
3935 set $kgm_pkt = (kdp_writephysmem64_req_t *)&manual_pkt.data
3936 set $kgm_pkt->hdr.request = KDP_WRITEPHYSMEM64
3937 set $kgm_pkt->hdr.len = sizeof(kdp_writephysmem64_req_t)
3938 set $kgm_pkt->hdr.is_reply = 0
3939 set $kgm_pkt->hdr.seq = 0
3940 set $kgm_pkt->hdr.key = 0
3941 set $kgm_pkt->address = (uint64_t)$arg0
3942 set $kgm_pkt->nbytes = $arg1 >> 3
3943 set $kgm_pkt->lcpu = $arg3
3944 if $arg1 == 8
3945 set *(uint8_t *)$kgm_pkt->data = (uint8_t)$arg2
3946 end
3947 if $arg1 == 16
3948 set *(uint16_t *)$kgm_pkt->data = (uint16_t)$arg2
3949 end
3950 if $arg1 == 32
3951 set *(uint32_t *)$kgm_pkt->data = (uint32_t)$arg2
3952 end
3953 if $arg1 == 64
3954 set *(uint64_t *)$kgm_pkt->data = (uint64_t)$arg2
3955 end
3956 set manual_pkt.input = 1
3957 # dummy to make sure manual packet is executed
3958 set $kgm_dummy = &_mh_execute_header
3959 set $kgm_pkt = (kdp_writephysmem64_reply_t *)&manual_pkt.data
3960 set $kgm_writephysint_result = $kgm_pkt->error
3961end
3962
3963define writephys8
3964 writephysint $arg0 8 $arg1 $kgm_lcpu_self
3965end
3966
3967define writephys16
3968 writephysint $arg0 16 $arg1 $kgm_lcpu_self
3969end
3970
3971define writephys32
3972 writephysint $arg0 32 $arg1 $kgm_lcpu_self
3973end
3974
3975define writephys64
3976 writephysint $arg0 64 $arg1 $kgm_lcpu_self
3977end
3978
3979document writephys8
3980| See writephys64
3981end
3982
3983document writephys16
3984| See writephys64
3985end
3986
3987document writephys32
3988| See writephys64
3989end
3990
3991document writephys64
3992| The argument is interpreted as a physical address, and the second argument is
3993| written to that address as a 64-bit word.
0c530ab8 3994end
2d21ac55
A
3995
3996define addkextsyms
3997 shell ls $arg0/* | xargs -n 1 echo add-symbol-file > /tmp/gdb-syms
3998 source /tmp/gdb-syms
3999 set $kgm_show_kmod_syms = 1
4000end
4001
4002document addkextsyms
4003| Takes a directory of symbols for kexts generated with kextcache -y and loads them
4004| into gdb.
4005| (gdb) addkextsyms /path/to/symboldir
4006end
4007
4008define showprocfiles
4009 if ($argc == 1)
4010 _showprocheader
4011 _showprocfiles $arg0
4012 else
4013 printf "| Usage:\n|\n"
4014 help showprocfiles
4015 end
4016end
4017document showprocfiles
4018Syntax: (gdb) showprocfiles <proc_t>
4019| Given a proc_t pointer, display the list of open file descriptors for the
4020| referenced process.
4021end
4022
4023define _showprocheader
b0d623f7
A
4024 printf "fd fileglob "
4025 showptrhdrpad
4026 printf " fg flags fg type fg data "
4027 showptrhdrpad
4028 printf " info\n"
4029 printf "----- ----------"
4030 if $kgm_lp64
4031 printf "--------"
4032 end
4033 printf " ---------- -------- ----------"
4034 if $kgm_lp64
4035 printf "--------"
4036 end
4037 printf " -------------------\n"
2d21ac55
A
4038end
4039
4040define _showprocfiles
4041 set $kgm_spf_filedesc = ((proc_t)$arg0)->p_fd
4042 set $kgm_spf_last = $kgm_spf_filedesc->fd_lastfile
4043 set $kgm_spf_ofiles = $kgm_spf_filedesc->fd_ofiles
4044 set $kgm_spf_count = 0
4045 while ($kgm_spf_count <= $kgm_spf_last)
4046 if ($kgm_spf_ofiles[$kgm_spf_count] == 0)
4047 # DEBUG: For files that were open, but are now closed
4048 # printf "%-5d FILEPROC_NULL\n", $kgm_spf_count
4049 else
4050 # display fd #, fileglob address, fileglob flags
4051 set $kgm_spf_flags = $kgm_spf_ofiles[$kgm_spf_count].f_flags
4052 set $kgm_spf_fg = $kgm_spf_ofiles[$kgm_spf_count].f_fglob
b0d623f7
A
4053 printf "%-5d ", $kgm_spf_count
4054 showptr $kgm_spf_fg
4055 printf " 0x%08x ", $kgm_spf_flags
2d21ac55
A
4056 # decode fileglob type
4057 set $kgm_spf_fgt = $kgm_spf_fg->fg_type
4058 if ($kgm_spf_fgt == 1)
4059 printf "VNODE "
4060 end
4061 if ($kgm_spf_fgt == 2)
4062 printf "SOCKET "
4063 end
4064 if ($kgm_spf_fgt == 3)
4065 printf "PSXSHM "
4066 end
4067 if ($kgm_spf_fgt == 4)
4068 printf "PSXSEM "
4069 end
4070 if ($kgm_spf_fgt == 5)
4071 printf "KQUEUE "
4072 end
4073 if ($kgm_spf_fgt == 6)
4074 printf "PIPE "
4075 end
4076 if ($kgm_spf_fgt == 7)
4077 printf "FSEVENTS"
4078 end
4079 if ($kgm_spf_fgt < 1 || $kgm_spf_fgt > 7)
4080 printf "?: %-5d", $kgm_spf_fgt
4081 end
4082
4083 # display fileglob data address and decode interesting fact(s)
4084 # about data, if we know any
4085 set $kgm_spf_fgd = $kgm_spf_fg->fg_data
b0d623f7
A
4086 printf " "
4087 showptr $kgm_spf_fgd
4088 printf " "
2d21ac55
A
4089 if ($kgm_spf_fgt == 1)
4090 set $kgm_spf_name = ((struct vnode *)$kgm_spf_fgd)->v_name
4091 if ($kgm_spf_name == 0)
4092 printf "(null)"
4093 else
4094 printf "%s", $kgm_spf_name
4095 end
4096 end
4097 printf "\n"
4098 end
4099 set $kgm_spf_count = $kgm_spf_count + 1
4100 end
4101end
4102
4103#
4104# Show all the advisory file locks held by a process for each of the vnode
4105# type files that it has open; do this by walking the per process open file
4106# table and looking at any vnode type fileglob that has a non-NULL lock list
4107# associated with it.
4108#
4109define showproclocks
4110 if ($argc == 1)
4111 _showproclocks $arg0
4112 else
4113 printf "| Usage:\n|\n"
4114 help showproclocks
4115 end
4116end
4117document showproclocks
4118Syntax: (gdb) showproclocks <proc_t>
4119| Given a proc_t pointer, display the list of advisory file locks held by the
4120| referenced process.
4121end
4122
4123define _showproclocks
4124 set $kgm_spl_filedesc = ((proc_t)$arg0)->p_fd
4125 set $kgm_spl_last = $kgm_spl_filedesc->fd_lastfile
4126 set $kgm_spl_ofiles = $kgm_spl_filedesc->fd_ofiles
4127 set $kgm_spl_count = 0
4128 set $kgm_spl_seen = 0
4129 while ($kgm_spl_count <= $kgm_spl_last)
4130 if ($kgm_spl_ofiles[$kgm_spl_count] == 0)
4131 # DEBUG: For files that were open, but are now closed
4132 # printf "%-5d FILEPROC_NULL\n", $kgm_spl_count
4133 else
4134 set $kgm_spl_fg = $kgm_spl_ofiles[$kgm_spl_count].f_fglob
4135 # decode fileglob type
4136 set $kgm_spl_fgt = $kgm_spl_fg->fg_type
4137 if ($kgm_spl_fgt == 1)
4138 set $kgm_spl_fgd = $kgm_spl_fg->fg_data
4139 set $kgm_spl_name = ((struct vnode *)$kgm_spl_fgd)->v_name
4140 set $kgm_spl_vnode = ((vnode_t)$kgm_spl_fgd)
4141 set $kgm_spl_lockiter = $kgm_spl_vnode->v_lockf
4142 if ($kgm_spl_lockiter != 0)
4143 if ($kgm_spl_seen == 0)
4144 _showvnodelockheader
4145 end
4146 set $kgm_spl_seen = $kgm_spl_seen + 1
4147 printf "( fd %d, name ", $kgm_spl_count
4148 if ($kgm_spl_name == 0)
4149 printf "(null) )"
4150 else
4151 printf "%s )\n", $kgm_spl_name
4152 end
4153 _showvnodelocks $kgm_spl_fgd
4154 end
4155 end
4156 end
4157 set $kgm_spl_count = $kgm_spf_count + 1
4158 end
b0d623f7
A
4159 printf "%d total locks for ", $kgm_spl_seen
4160 showptr $arg0
4161 printf "\n"
2d21ac55
A
4162end
4163
4164define showprocinfo
4165 set $kgm_spi_proc = (proc_t)$arg0
b0d623f7
A
4166 printf "Process "
4167 showptr $kgm_spi_proc
4168 printf "\n"
2d21ac55 4169 printf " name %s\n", $kgm_spi_proc->p_comm
b0d623f7
A
4170 printf " pid:%.8d", $kgm_spi_proc->p_pid
4171 printf " task:"
4172 showptr $kgm_spi_proc->task
4173 printf " p_stat:%.1d", $kgm_spi_proc->p_stat
4174 printf " parent pid:%.8d", $kgm_spi_proc->p_ppid
4175 printf "\n"
2d21ac55
A
4176 # decode part of credential
4177 set $kgm_spi_cred = $kgm_spi_proc->p_ucred
4178 if ($kgm_spi_cred != 0)
4179 printf "Cred: euid %d ruid %d svuid %d\n", $kgm_spi_cred->cr_uid, $kgm_spi_cred->cr_ruid, $kgm_spi_cred->cr_svuid
4180 else
4181 printf "Cred: (null)\n"
4182 end
4183 # decode flags
4184 set $kgm_spi_flag = $kgm_spi_proc->p_flag
4185 printf "Flags: 0x%08x\n", $kgm_spi_flag
4186 if ($kgm_spi_flag & 0x00000001)
4187 printf " 0x00000001 - may hold advisory locks\n"
4188 end
4189 if ($kgm_spi_flag & 0x00000002)
4190 printf " 0x00000002 - has a controlling tty\n"
4191 end
4192 if ($kgm_spi_flag & 0x00000004)
4193 printf " 0x00000004 - process is 64 bit\n"
4194 else
4195 printf " !0x00000004 - process is 32 bit\n"
4196 end
4197 if ($kgm_spi_flag & 0x00000008)
4198 printf " 0x00000008 - no SIGCHLD on child stop\n"
4199 end
4200 if ($kgm_spi_flag & 0x00000010)
4201 printf " 0x00000010 - waiting for child exec/exit\n"
4202 end
4203 if ($kgm_spi_flag & 0x00000020)
4204 printf " 0x00000020 - has started profiling\n"
4205 end
4206 if ($kgm_spi_flag & 0x00000040)
4207 printf " 0x00000040 - in select; wakeup/waiting danger\n"
4208 end
4209 if ($kgm_spi_flag & 0x00000080)
4210 printf " 0x00000080 - was stopped and continued\n"
4211 end
4212 if ($kgm_spi_flag & 0x00000100)
4213 printf " 0x00000100 - has set privileges since exec\n"
4214 end
4215 if ($kgm_spi_flag & 0x00000200)
4216 printf " 0x00000200 - system process: no signals, stats, or swap\n"
4217 end
4218 if ($kgm_spi_flag & 0x00000400)
4219 printf " 0x00000400 - timing out during a sleep\n"
4220 end
4221 if ($kgm_spi_flag & 0x00000800)
4222 printf " 0x00000800 - debugged process being traced\n"
4223 end
4224 if ($kgm_spi_flag & 0x00001000)
4225 printf " 0x00001000 - debugging process has waited for child\n"
4226 end
4227 if ($kgm_spi_flag & 0x00002000)
4228 printf " 0x00002000 - exit in progress\n"
4229 end
4230 if ($kgm_spi_flag & 0x00004000)
4231 printf " 0x00004000 - process has called exec\n"
4232 end
4233 if ($kgm_spi_flag & 0x00008000)
4234 printf " 0x00008000 - owe process an addupc() XXX\n"
4235 end
4236 if ($kgm_spi_flag & 0x00010000)
4237 printf " 0x00010000 - affinity for Rosetta children\n"
4238 end
4239 if ($kgm_spi_flag & 0x00020000)
4240 printf " 0x00020000 - wants to run Rosetta\n"
4241 end
4242 if ($kgm_spi_flag & 0x00040000)
4243 printf " 0x00040000 - has wait() in progress\n"
4244 end
4245 if ($kgm_spi_flag & 0x00080000)
4246 printf " 0x00080000 - kdebug tracing on for this process\n"
4247 end
4248 if ($kgm_spi_flag & 0x00100000)
4249 printf " 0x00100000 - blocked due to SIGTTOU or SIGTTIN\n"
4250 end
4251 if ($kgm_spi_flag & 0x00200000)
4252 printf " 0x00200000 - has called reboot()\n"
4253 end
4254 if ($kgm_spi_flag & 0x00400000)
4255 printf " 0x00400000 - is TBE state\n"
4256 end
4257 if ($kgm_spi_flag & 0x00800000)
4258 printf " 0x00800000 - signal exceptions\n"
4259 end
4260 if ($kgm_spi_flag & 0x01000000)
b0d623f7 4261 printf " 0x01000000 - has thread cwd\n"
2d21ac55
A
4262 end
4263 if ($kgm_spi_flag & 0x02000000)
4264 printf " 0x02000000 - has vfork() children\n"
4265 end
4266 if ($kgm_spi_flag & 0x04000000)
4267 printf " 0x04000000 - not allowed to attach\n"
4268 end
4269 if ($kgm_spi_flag & 0x08000000)
4270 printf " 0x08000000 - vfork() in progress\n"
4271 end
4272 if ($kgm_spi_flag & 0x10000000)
4273 printf " 0x10000000 - no shared libraries\n"
4274 end
4275 if ($kgm_spi_flag & 0x20000000)
4276 printf " 0x20000000 - force quota for root\n"
4277 end
4278 if ($kgm_spi_flag & 0x40000000)
4279 printf " 0x40000000 - no zombies when children exit\n"
4280 end
4281 if ($kgm_spi_flag & 0x80000000)
4282 printf " 0x80000000 - don't hang on remote FS ops\n"
4283 end
4284 # decode state
4285 set $kgm_spi_state = $kgm_spi_proc->p_stat
4286 printf "State: "
4287 if ($kgm_spi_state == 1)
4288 printf "Idle\n"
4289 end
4290 if ($kgm_spi_state == 2)
4291 printf "Run\n"
4292 end
4293 if ($kgm_spi_state == 3)
4294 printf "Sleep\n"
4295 end
4296 if ($kgm_spi_state == 4)
4297 printf "Stop\n"
4298 end
4299 if ($kgm_spi_state == 5)
4300 printf "Zombie\n"
4301 end
4302 if ($kgm_spi_state == 6)
4303 printf "Reaping\n"
4304 end
4305 if ($kgm_spi_state < 1 || $kgm_spi_state > 6)
4306 printf "(Unknown)\n"
4307 end
4308end
4309
4310document showprocinfo
4311Syntax: (gdb) showprocinfo <proc_t>
4312| Displays name, pid, parent and task for a proc_t. Decodes cred, flag and p_stat fields.
4313end
4314
4315#
4316# dump the zombprocs
4317#
4318define zombproc
4319 set $basep = (struct proc *)zombproc->lh_first
4320 set $pp = $basep
4321 while $pp
4322 showprocinfo $pp
4323 set $pp = $pp->p_list.le_next
4324 end
4325end
4326
4327document zombproc
4328Syntax: (gdb) zombproc
4329| Routine to print out all procs in the zombie list
4330end
4331
4332#
4333# dump the zombstacks
4334#
4335define zombstacks
4336 set $basep = (struct proc *)zombproc->lh_first
4337 set $pp = $basep
4338 while $pp
4339 if $pp->p_stat != 5
4340 showtaskstacks $pp->task
4341 end
4342 set $pp = $pp->p_list.le_next
4343 end
4344end
4345
4346document zombstacks
4347Syntax: (gdb) zombstacks
4348| Routine to print out all stacks of tasks that are exiting
4349end
4350
4351
4352#
4353# dump the allprocs
4354#
4355define allproc
4356 set $basep = (struct proc *)allproc->lh_first
4357 set $pp = $basep
4358 while $pp
4359 showprocinfo $pp
4360 set $pp = $pp->p_list.le_next
4361 end
4362end
4363
4364document allproc
4365Syntax: (gdb) allproc
4366| Routine to print out all process in the system
4367| which are not in the zombie list
4368end
4369
4370
4371
4372define print_vnode
4373 set $vp = (struct vnode *)$arg0
4374 printf " "
b0d623f7
A
4375 printf " vp "
4376 showptr $vp
2d21ac55
A
4377 printf " use %d", $vp->v_usecount
4378 printf " io %d", $vp->v_iocount
4379 printf " kuse %d", $vp->v_kusecount
4380 printf " type %d", $vp->v_type
4381 printf " flg 0x%.8x", $vp->v_flag
4382 printf " lflg 0x%.8x", $vp->v_lflag
b0d623f7
A
4383 printf " par "
4384 showptr $vp->v_parent
2d21ac55
A
4385 set $_name = (char *)$vp->v_name
4386 if ($_name != 0)
4387 printf " %s", $_name
4388 end
4389 if ($vp->v_type == VREG) && ($vp->v_un.vu_ubcinfo != 0)
4390 printf " mapped %d", ($vp->v_un.vu_ubcinfo.ui_flags & 0x08) ? 1 : 0
4391 end
4392 printf "\n"
4393end
4394
4395document print_vnode
4396Syntax: (gdb) print_vnode <vnode>
4397| Prints out the fields of a vnode struct
4398end
4399
4400define showprocvnodes
4401 set $pp = (struct proc *)$arg0
4402 set $fdp = (struct filedesc *)$pp->p_fd
4403 set $cvp = $fdp->fd_cdir
4404 set $rvp = $fdp->fd_rdir
4405 if $cvp
4406 printf "Current Working Directory \n"
4407 print_vnode $cvp
4408 printf "\n"
4409 end
4410 if $rvp
4411 printf "Current Root Directory \n"
4412 print_vnode $rvp
4413 printf "\n"
4414 end
4415 set $count = 0
4416 set $fpp = (struct fileproc **)($fdp->fd_ofiles)
4417 set $fpo = (char)($fdp->fd_ofileflags[0])
4418 while $count < $fdp->fd_nfiles
4419 #printf"fpp %x ", *$fpp
4420 if *$fpp
4421 set $fg =(struct fileglob *)((**$fpp)->f_fglob)
4422 if $fg && (($fg)->fg_type == 1)
4423 if $fdp->fd_ofileflags[$count] & 4
4424 printf "U: "
4425 else
4426 printf " "
4427 end
4428 printf "fd = %d ", $count
4429 print_vnode $fg->fg_data
4430 end
4431 end
4432 set $fpp = $fpp + 1
4433 set $count = $count + 1
4434 end
4435end
4436
4437document showprocvnodes
4438Syntax: (gdb) showprocvnodes <proc_address>
4439| Routine to print out all the open fds
4440| which are vnodes in a process
4441end
4442
4443define showallprocvnodes
4444 set $basep = (struct proc *)allproc->lh_first
4445 set $pp = $basep
4446 while $pp
4447 printf "============================================ \n"
4448 showprocinfo $pp
4449 showprocvnodes $pp
4450 set $pp = $pp->p_list.le_next
4451 end
4452end
4453
4454document showallprocvnodes
4455Syntax: (gdb) showallprocvnodes
4456| Routine to print out all the open fds
4457| which are vnodes
4458end
4459
4460
4461#
4462# dump the childrent of a proc
4463#
4464define showinitchild
4465 set $basep = (struct proc *)initproc->p_children.lh_first
4466 set $pp = $basep
4467 while $pp
4468 showprocinfo $pp
4469 set $pp = $pp->p_sibling.le_next
4470 end
4471end
4472
4473document showinitchild
4474Syntax: (gdb) showinitchild
4475| Routine to print out all processes in the system
4476| which are children of init process
4477end
4478
4479
4480define showmountallvnodes
4481 set $mp = (struct mount *)$arg0
4482 set $basevp = (struct vnode *)$mp->mnt_vnodelist.tqh_first
4483 set $vp = $basevp
4484 printf "____________________ Vnode list Queue ---------------\n"
4485 while $vp
4486 print_vnode $vp
4487 set $vp = $vp->v_mntvnodes->tqe_next
4488 end
4489 set $basevp = (struct vnode *)$mp->mnt_workerqueue.tqh_first
4490 set $vp = $basevp
4491 printf "____________________ Worker Queue ---------------\n"
4492 while $vp
4493 print_vnode $vp
4494 set $vp = $vp->v_mntvnodes->tqe_next
4495 end
4496 set $basevp = (struct vnode *)$mp->mnt_newvnodes.tqh_first
4497 set $vp = $basevp
4498 printf "____________________ New vnodes Queue ---------------\n"
4499 while $vp
4500 print_vnode $vp
4501 set $vp = $vp->v_mntvnodes->tqe_next
4502 end
4503end
4504document showmountallvnodes
4505Syntax: showmountallvnodes <struct mount *>
4506| Print the vnode inactive list
4507end
4508
4509
4510define showmountvnodes
4511 set $mp = (struct mount *)$arg0
4512 set $basevp = (struct vnode *)$mp->mnt_vnodelist.tqh_first
4513 set $vp = $basevp
4514 printf "____________________ Vnode list Queue ---------------\n"
4515 while $vp
4516 print_vnode $vp
4517 set $vp = $vp->v_mntvnodes->tqe_next
4518 end
4519end
4520document showmountvnodes
4521Syntax: showmountvnodes <struct mount *>
4522| Print the vnode list
4523end
4524
4525
4526
4527define showworkqvnodes
4528 set $mp = (struct mount *)$arg0
4529 set $basevp = (struct vnode *)$mp->mnt_workerqueue.tqh_first
4530 set $vp = $basevp
4531 printf "____________________ Worker Queue ---------------\n"
4532 while $vp
4533 print_vnode $vp
4534 set $vp = $vp->v_mntvnodes->tqe_next
4535 end
4536end
4537document showworkqvnodes
4538Syntax: showworkqvnodes <struct mount *>
4539| Print the vnode worker list
4540end
4541
4542
4543define shownewvnodes
4544 set $mp = (struct mount *)$arg0
4545 set $basevp = (struct vnode *)$mp->mnt_newvnodes.tqh_first
4546 set $vp = $basevp
4547 printf "____________________ New vnodes Queue ---------------\n"
4548 while $vp
4549 print_vnode $vp
4550 set $vp = $vp->v_mntvnodes->tqe_next
4551 end
4552end
4553
4554document shownewvnodes
4555Syntax: shownewvnodes <struct mount *>
4556| Print the new vnode list
4557end
4558
4559
4560#
4561# print mount point info
4562define print_mount
4563 set $mp = (struct mount *)$arg0
4564 printf " "
b0d623f7
A
4565 printf " mp "
4566 showptr $mp
2d21ac55
A
4567 printf " flag %x", $mp->mnt_flag
4568 printf " kern_flag %x", $mp->mnt_kern_flag
4569 printf " lflag %x", $mp->mnt_lflag
4570 printf " type: %s", $mp->mnt_vfsstat.f_fstypename
4571 printf " mnton: %s", $mp->mnt_vfsstat.f_mntonname
4572 printf " mntfrom: %s", $mp->mnt_vfsstat.f_mntfromname
4573 printf "\n"
4574end
4575
4576define showallmounts
4577 set $mp=(struct mount *)mountlist.tqh_first
4578 while $mp
4579 print_mount $mp
4580 set $mp = $mp->mnt_list.tqe_next
4581 end
4582end
4583
4584document showallmounts
4585Syntax: showallmounts
4586| Print all mount points
4587end
4588
4589define pcprint
b0d623f7
A
4590 if (((unsigned long) $arg0 < (unsigned long) &_mh_execute_header || \
4591 (unsigned long) $arg0 >= (unsigned long) &last_kernel_symbol ))
4592 showkmodaddr $arg0
2d21ac55 4593 else
b0d623f7 4594 output /a $arg0
2d21ac55
A
4595 end
4596end
4597
4598define mbuf_walkpkt
4599 set $mp = (struct mbuf *)$arg0
4600 set $cnt = 1
4601 set $tot = 0
4602 while $mp
b0d623f7 4603 printf "%4d: %p [len %4d, type %2d, ", $cnt, $mp, \
2d21ac55
A
4604 $mp->m_hdr.mh_len, $mp->m_hdr.mh_type
4605 if mclaudit != 0
4606 mbuf_buf2mca $mp
4607 printf ", "
4608 end
4609 set $tot = $tot + $mp->m_hdr.mh_len
4610 printf "total %d]\n", $tot
4611 set $mp = $mp->m_hdr.mh_nextpkt
4612 set $cnt = $cnt + 1
4613 end
4614end
4615
4616document mbuf_walkpkt
4617Syntax: (gdb) mbuf_walkpkt <addr>
4618| Given an mbuf address, walk its m_nextpkt pointer
4619end
4620
4621define mbuf_walk
4622 set $mp = (struct mbuf *)$arg0
4623 set $cnt = 1
4624 set $tot = 0
4625 while $mp
b0d623f7 4626 printf "%4d: %p [len %4d, type %2d, ", $cnt, $mp, \
2d21ac55
A
4627 $mp->m_hdr.mh_len, $mp->m_hdr.mh_type
4628 if mclaudit != 0
4629 mbuf_buf2mca $mp
4630 printf ", "
4631 end
4632 set $tot = $tot + $mp->m_hdr.mh_len
4633 printf "total %d]\n", $tot
4634 set $mp = $mp->m_hdr.mh_next
4635 set $cnt = $cnt + 1
4636 end
4637end
4638
4639document mbuf_walk
4640Syntax: (gdb) mbuf_walk <addr>
4641| Given an mbuf address, walk its m_next pointer
4642end
4643
4644define mbuf_buf2slab
4645 set $addr = $arg0
4646 set $gix = ((char *)$addr - (char *)mbutl) >> 20
4647 set $ix = ((char *)$addr - (char *)mbutl) >> 11
4648 set $slab = &slabstbl[$gix].slg_slab[$ix]
b0d623f7 4649 printf "%p", $slab
2d21ac55
A
4650end
4651
4652document mbuf_buf2slab
4653| Given an mbuf object, find its corresponding slab address.
4654end
4655
4656define mbuf_buf2mca
4657 set $addr = $arg0
4658 set $ix = ((char *)$addr - (char *)mbutl) >> 11
4659 set $clbase = ((union mcluster *)(mbutl + $ix))
4660 set $mclidx = (((char *)$addr - (char *)$clbase) >> 8)
4661 set $mca = mclaudit[$ix].cl_audit[$mclidx]
b0d623f7 4662 printf "mca: %p", $mca
2d21ac55
A
4663end
4664
4665document mbuf_buf2mca
4666Syntax: (gdb) mbuf_buf2mca <addr>
4667| Given an mbuf object, find its buffer audit structure address.
4668| This requires mbuf buffer auditing to be turned on, by setting
4669| the appropriate flags to the "mbuf_debug" boot-args parameter.
4670end
4671
4672define mbuf_showmca
4673 set language c
4674 set $mca = (mcache_audit_t *)$arg0
4675 set $cp = (mcache_t *)$mca->mca_cache
4676 printf "object type:\t\t"
4677 mbuf_mca_ctype $mca 1
4678 printf "\ncontrolling mcache:\t%p (%s)\n", $mca->mca_cache, $cp->mc_name
4679 if $mca->mca_uflags & $MB_SCVALID
4680 set $ix = ((char *)$mca->mca_addr - (char *)mbutl) >> 11
4681 set $clbase = ((union mcluster *)(mbutl + $ix))
4682 set $mclidx = (((char *)$mca->mca_addr - (char *)$clbase) >> 8)
4683 printf "mbuf obj:\t\t%p\n", $mca->mca_addr
4684 printf "mbuf index:\t\t%d (out of 8) in cluster base %p\n", \
4685 $mclidx + 1, $clbase
4686 if $mca->mca_uptr != 0
4687 set $peer_mca = (mcache_audit_t *)$mca->mca_uptr
4688 printf "paired cluster obj:\t%p (mca %p)\n", \
4689 $peer_mca->mca_addr, $peer_mca
4690 end
4691 printf "saved contents:\t\t%p (%d bytes)\n", \
4692 $mca->mca_contents, $mca->mca_contents_size
4693 else
4694 printf "cluster obj:\t\t%p\n", $mca->mca_addr
4695 if $mca->mca_uptr != 0
4696 set $peer_mca = (mcache_audit_t *)$mca->mca_uptr
4697 printf "paired mbuf obj:\t%p (mca %p)\n", \
4698 $peer_mca->mca_addr, $peer_mca
4699 end
4700 end
4701 printf "recent transaction for this buffer (thread %p):\n", \
4702 $mca->mca_thread
4703 set $cnt = 0
4704 while $cnt < $mca->mca_depth
b0d623f7 4705 set $kgm_pc = $mca->mca_stack[$cnt]
2d21ac55 4706 printf "%4d: ", $cnt + 1
b0d623f7 4707 pcprint $kgm_pc
2d21ac55
A
4708 printf "\n"
4709 set $cnt = $cnt + 1
4710 end
4711 if $mca->mca_pdepth > 0
4712 printf "previous transaction for this buffer (thread %p):\n", \
4713 $mca->mca_pthread
4714 end
4715 set $cnt = 0
4716 while $cnt < $mca->mca_pdepth
b0d623f7 4717 set $kgm_pc = $mca->mca_pstack[$cnt]
2d21ac55 4718 printf "%4d: ", $cnt + 1
b0d623f7 4719 pcprint $kgm_pc
2d21ac55
A
4720 printf "\n"
4721 set $cnt = $cnt + 1
4722 end
4723 set language auto
4724end
4725
4726document mbuf_showmca
4727Syntax: (gdb) mbuf_showmca <addr>
4728| Given an mbuf/cluster buffer audit structure address, print the audit
4729| records including the stack trace of the last buffer transaction.
4730end
4731
4732set $MCF_NOCPUCACHE = 0x10
4733
4734define mcache_stat
4735 set $head = (mcache_t *)mcache_head
4736 set $mc = $head
b0d623f7
A
4737
4738 if $kgm_lp64
4739 printf "cache cache cache buf buf backing (# of retries) bufs\n"
4740 printf "name state addr size align zone wait nowait failed incache\n"
4741 printf "------------------------- -------- ------------------ ------ ----- ------------------ -------------------------- --------\n"
4742 else
4743 printf "cache cache cache buf buf backing (# of retries) bufs\n"
4744 printf "name state addr size align zone wait nowait failed incache\n"
4745 printf "------------------------- -------- ---------- ------ ----- ---------- -------------------------- --------\n"
4746 end
2d21ac55
A
4747 while $mc != 0
4748 set $bktsize = $mc->mc_cpu.cc_bktsize
4749 printf "%-25s ", $mc->mc_name
4750 if ($mc->mc_flags & $MCF_NOCPUCACHE)
4751 printf "disabled"
4752 else
4753 if $mc->mc_purge_cnt > 0
4754 printf " purging"
4755 else
4756 if $bktsize == 0
4757 printf " offline"
4758 else
4759 printf " online"
4760 end
4761 end
4762 end
b0d623f7 4763 printf " %p %6d %5d ",$mc, \
2d21ac55
A
4764 $mc->mc_bufsize, $mc->mc_align
4765 if $mc->mc_slab_zone != 0
b0d623f7 4766 printf "%p", $mc->mc_slab_zone
2d21ac55 4767 else
b0d623f7
A
4768 if $kgm_lp64
4769 printf " custom"
4770 else
4771 printf " custom"
4772 end
2d21ac55
A
4773 end
4774 set $tot = 0
4775 set $tot += $mc->mc_full.bl_total * $bktsize
4776 set $ccp = (mcache_cpu_t *)$mc->mc_cpu
4777 set $n = 0
4778 while $n < ncpu
4779 if $ccp->cc_objs > 0
4780 set $tot += $ccp->cc_objs
4781 end
4782 if $ccp->cc_pobjs > 0
4783 set $tot += $ccp->cc_pobjs
4784 end
4785 set $n += 1
4786 set $ccp += 1
4787 end
4788 printf " %8d %8d %8d %8d", $mc->mc_wretry_cnt, \
4789 $mc->mc_nwretry_cnt, $mc->mc_nwfail_cnt, $tot
4790 printf "\n"
4791 set $mc = (mcache_t *)$mc->mc_list.le_next
4792 end
4793end
4794
4795document mcache_stat
4796Syntax: (gdb) mcache_stat
4797| Print all mcaches in the system.
4798end
4799
4800define mcache_showzone
4801 set $mc = (mcache_t *)$arg0
4802 if $mc->mc_slab_zone != 0
4803 printf "%p", $mc->mc_slab_zone
4804 else
4805 printf " custom"
4806end
4807
4808document mcache_showzone
4809Syntax: (gdb) mcache_showzone <mcache_addr>
4810| Print the type of backend (custom or zone) of a mcache.
4811end
4812
4813define mcache_walkobj
4814 set $p = (mcache_obj_t *)$arg0
4815 set $cnt = 1
4816 set $tot = 0
4817 while $p
b0d623f7 4818 printf "%4d: %p\n", $cnt, $p,
2d21ac55
A
4819 set $p = $p->obj_next
4820 set $cnt = $cnt + 1
4821 end
4822end
4823
4824document mcache_walkobj
4825Syntax: (gdb) mcache_walkobj <addr>
4826| Given a mcache object address, walk its obj_next pointer
4827end
4828
4829define mcache_showcache
4830 set $cp = (mcache_t *)$arg0
4831 set $ccp = (mcache_cpu_t *)$cp->mc_cpu
4832 set $bktsize = $cp->mc_cpu.cc_bktsize
4833 set $cnt = 0
4834 set $tot = 0
4835 printf "Showing cache '%s':\n\n", $cp->mc_name
4836 printf " CPU cc_objs cc_pobjs total\n"
4837 printf "---- -------- -------- --------\n"
4838 while $cnt < ncpu
4839 set $objs = $ccp->cc_objs
4840 if $objs <= 0
4841 set $objs = 0
4842 end
4843 set $pobjs = $ccp->cc_pobjs
4844 if $pobjs <= 0
4845 set $pobjs = 0
4846 end
4847 set $tot_cpu = $objs + $pobjs
4848 set $tot += $tot_cpu
4849 printf "%4d %8d %8d %8d\n", $cnt, $objs, $pobjs, $tot_cpu
4850 set $ccp += 1
4851 set $cnt += 1
4852 end
4853 printf " ========\n"
4854 printf " %8d\n", $tot
4855 printf "\n"
4856 set $tot += $cp->mc_full.bl_total * $bktsize
4857 printf "Total # of full buckets (%d objs/bkt):\t%-8d\n", \
4858 $bktsize, $cp->mc_full.bl_total
4859 printf "Total # of objects cached:\t\t%-8d\n", $tot
4860end
4861
4862document mcache_showcache
4863| Display the number of objects in the cache
4864end
4865
4866set $NSLABSPMB = sizeof(mcl_slabg_t)/sizeof(mcl_slab_t)
4867
4868define mbuf_slabstbl
4869 set $x = 0
4870
4871 printf "slot addr slabs range\n"
4872 printf "---- ---------- -----------------------\n"
4873 while $x < maxslabgrp
4874 set $slg = slabstbl[$x]
4875 printf "%3d: ", $x
4876 if $slg == 0
4877 printf "-\n"
4878 else
4879 printf "%p [%p-%p]\n", $slg, &$slg->slg_slab[0], \
4880 &$slg->slg_slab[$NSLABSPMB-1]
4881 end
4882 set $x += 1
4883 end
4884end
4885
4886document mbuf_slabstbl
4887| Display the mbuf slabs table
4888end
4889
4890set $SLF_MAPPED=0x0001
4891set $SLF_PARTIAL=0x0002
4892set $SLF_DETACHED=0x0004
4893
4894define mbuf_slabs
4895 set $slg = (mcl_slabg_t *)$arg0
4896 set $x = 0
4897
b0d623f7
A
4898 if $kgm_lp64
4899 printf "slot addr next base C R N size flags\n"
4900 printf "---- ------------------ ------------------ ------------------ -- -- -- ------ -----\n"
4901 else
4902 printf "slot addr next base C R N size flags\n"
4903 printf "---- ---------- ---------- ---------- -- -- -- ------ -----\n"
4904 end
2d21ac55
A
4905 while $x < $NSLABSPMB
4906 set $sl = &$slg->slg_slab[$x]
b0d623f7 4907 printf "%3d: %p %p %p %2d %2d %2d %6d 0x%04x ", \
2d21ac55
A
4908 $x + 1, $sl, $sl->sl_next, $sl->sl_base, $sl->sl_class, \
4909 $sl->sl_refcnt, $sl->sl_chunks, $sl->sl_len, \
4910 $sl->sl_flags
4911 if $sl->sl_flags != 0
4912 printf "<"
4913 if $sl->sl_flags & $SLF_MAPPED
4914 printf "mapped"
4915 end
4916 if $sl->sl_flags & $SLF_PARTIAL
4917 printf ",partial"
4918 end
4919 if $sl->sl_flags & $SLF_DETACHED
4920 printf ",detached"
4921 end
4922 printf ">"
4923 end
4924 printf "\n"
4925 set $x += 1
4926 end
4927end
4928
4929document mbuf_slabs
4930| Display all mbuf slabs in the group
4931end
4932
4933define mbuf_stat
4934 set $x = 0
4935
4936 printf "class total cached uncached inuse failed waiter notified purge\n"
4937 printf "name objs objs objs / slabs objs alloc count count count count\n"
4938 printf "---------------- -------- -------- ------------------- -------- ---------------- -------- -------- --------\n"
4939 while $x < (sizeof(mbuf_table) / sizeof(mbuf_table[0]))
4940 set $mbt = mbuf_table[$x]
4941 set $mcs = (mb_class_stat_t *)mbuf_table[$x].mtbl_stats
4942 set $tot = 0
4943 set $mc = $mbt->mtbl_cache
4944 set $bktsize = $mc->mc_cpu.cc_bktsize
4945 set $tot += $mc->mc_full.bl_total * $bktsize
4946 set $ccp = (mcache_cpu_t *)$mc->mc_cpu
4947 set $n = 0
4948 while $n < ncpu
4949 if $ccp->cc_objs > 0
4950 set $tot += $ccp->cc_objs
4951 end
4952 if $ccp->cc_pobjs > 0
4953 set $tot += $ccp->cc_pobjs
4954 end
4955 set $n += 1
4956 set $ccp += 1
4957 end
4958
4959 printf "%-16s %8d %8d %8d / %-8d %8d %16llu %8d %8llu %8llu", \
4960 $mcs->mbcl_cname, $mcs->mbcl_total, $tot, \
4961 $mcs->mbcl_infree, $mcs->mbcl_slab_cnt, \
4962 ($mcs->mbcl_total - $tot - $mcs->mbcl_infree), \
4963 $mcs->mbcl_fail_cnt, $mc->mc_waiter_cnt, \
4964 $mcs->mbcl_notified, $mcs->mbcl_purge_cnt
4965 printf "\n"
4966 set $x += 1
4967 end
4968end
4969
4970document mbuf_stat
4971| Print extended mbuf allocator statistics.
4972end
4973
4974set $MB_INUSE = 0x1
4975set $MB_COMP_INUSE = 0x2
4976set $MB_SCVALID = 0x4
4977
4978set $MCLBYTES = 2048
4979set $MSIZE = 256
4980set $NBPG = 4096
4981set $M16KCLBYTES = 16384
4982
4983define mbuf_mca_ctype
4984 set $mca = (mcache_audit_t *)$arg0
4985 set $vopt = $arg1
4986 set $cp = $mca->mca_cache
4987 set $class = (unsigned int)$cp->mc_private
4988 set $csize = mbuf_table[$class].mtbl_stats->mbcl_size
4989 set $done = 0
4990 if $csize == $MSIZE
4991 if $vopt
4992 printf "M (mbuf) "
4993 else
4994 printf "M "
4995 end
4996 set $done = 1
4997 end
4998 if !$done && $csize == $MCLBYTES
4999 if $vopt
5000 printf "CL (2K cluster) "
5001 else
5002 printf "CL "
5003 end
5004 set $done = 1
5005 end
5006 if !$done && $csize == $NBPG
5007 if $vopt
5008 printf "BCL (4K cluster) "
5009 else
5010 printf "BCL "
5011 end
5012 set $done = 1
5013 end
5014 if !$done && $csize == $M16KCLBYTES
5015 if $vopt
5016 printf "JCL (16K cluster) "
5017 else
5018 printf "JCL "
5019 end
5020 set $done = 1
5021 end
5022 if !$done && $csize == ($MSIZE+$MCLBYTES)
5023 if $mca->mca_uflags & $MB_SCVALID
5024 if $mca->mca_uptr
5025 printf "M+CL "
5026 if $vopt
5027 printf "(paired mbuf, 2K cluster)"
5028 end
5029 else
5030 printf "M-CL "
5031 if $vopt
5032 printf "(unpaired mbuf, 2K cluster) "
5033 end
5034 end
5035 else
5036 if $mca->mca_uptr
5037 printf "CL+M "
5038 if $vopt
5039 printf "(paired 2K cluster, mbuf) "
5040 end
5041 else
5042 printf "CL-M "
5043 if $vopt
5044 printf "(paired 2K cluster, mbuf) "
5045 end
5046 end
5047 end
5048 set $done = 1
5049 end
5050 if !$done && $csize == ($MSIZE+$NBPG)
5051 if $mca->mca_uflags & $MB_SCVALID
5052 if $mca->mca_uptr
5053 printf "M+BCL "
5054 if $vopt
5055 printf "(paired mbuf, 4K cluster) "
5056 end
5057 else
5058 printf "M-BCL "
5059 if $vopt
5060 printf "(unpaired mbuf, 4K cluster) "
5061 end
5062 end
5063 else
5064 if $mca->mca_uptr
5065 printf "BCL+M "
5066 if $vopt
5067 printf "(paired 4K cluster, mbuf) "
5068 end
5069 else
5070 printf "BCL-M "
5071 if $vopt
5072 printf "(unpaired 4K cluster, mbuf) "
5073 end
5074 end
5075 end
5076 set $done = 1
5077 end
5078 if !$done && $csize == ($MSIZE+$M16KCLBYTES)
5079 if $mca->mca_uflags & $MB_SCVALID
5080 if $mca->mca_uptr
5081 printf "M+JCL "
5082 if $vopt
5083 printf "(paired mbuf, 16K cluster) "
5084 end
5085 else
5086 printf "M-JCL "
5087 if $vopt
5088 printf "(unpaired mbuf, 16K cluster) "
5089 end
5090 end
5091 else
5092 if $mca->mca_uptr
5093 printf "JCL+M "
5094 if $vopt
5095 printf "(paired 16K cluster, mbuf) "
5096 end
5097 else
5098 printf "JCL-M "
5099 if $vopt
5100 printf "(unpaired 16K cluster, mbuf) "
5101 end
5102 end
5103 end
5104 set $done = 1
5105 end
5106 if !$done
5107 printf "unknown: %s ", $cp->mc_name
5108 end
5109end
5110
5111document mbuf_mca_ctype
5112| This is a helper macro for mbuf_show{active,inactive,all} that prints
5113| out the mbuf object type represented by a given mcache audit structure.
5114end
5115
5116define mbuf_showactive
b0d623f7
A
5117 if $argc == 0
5118 mbuf_walkallslabs 1 0
5119 else
5120 mbuf_walkallslabs 1 0 $arg0
5121 end
2d21ac55
A
5122end
5123
5124document mbuf_showactive
5125Syntax: (gdb) mbuf_showactive
5126| Walk the mbuf objects pool and print only the active ones; this
5127| requires mbuf debugging to be turned on, by setting the appropriate flags
5128| to the "mbuf_debug" boot-args parameter. Active objects are those that
5129| are outstanding (have not returned to the mbuf slab layer) and in use
5130| by the client (have not been freed).
5131end
5132
5133define mbuf_showinactive
5134 mbuf_walkallslabs 0 1
5135end
5136
5137document mbuf_showinactive
5138Syntax: (gdb) mbuf_showinactive
5139| Walk the mbuf objects pool and print only the inactive ones; this
5140| requires mbuf debugging to be turned on, by setting the appropriate flags
5141| to the "mbuf_debug" boot-args parameter. Inactive objects are those that
5142| are outstanding (have not returned to the mbuf slab layer) but have been
5143| freed by the client, i.e. they still reside in the mcache layer ready to
5144| be used for subsequent allocation requests.
5145end
5146
5147define mbuf_showall
5148 mbuf_walkallslabs 1 1
5149end
5150
5151document mbuf_showall
5152Syntax: (gdb) mbuf_showall
5153| Walk the mbuf objects pool and print them all; this requires
5154| mbuf debugging to be turned on, by setting the appropriate flags to the
5155| "mbuf_debug" boot-args parameter.
5156end
5157
5158define mbuf_mcaobjs
5159end
5160
5161define mbuf_walkallslabs
5162 set $show_a = $arg0
5163 set $show_f = $arg1
b0d623f7
A
5164 if $argc == 3
5165 set $show_tr = $arg2
5166 else
5167 set $show_tr = 0
5168 end
2d21ac55
A
5169 set $x = 0
5170 set $total = 0
5171 set $total_a = 0
5172 set $total_f = 0
5173
5174 printf "("
5175 if $show_a && !$show_f
5176 printf "Searching only for active "
5177 end
5178 if !$show_a && $show_f
5179 printf "Searching only for inactive "
5180 end
5181 if $show_a && $show_f
5182 printf "Displaying all "
5183 end
5184 printf "objects; this may take a while ...)\n\n"
5185
b0d623f7
A
5186 if $kgm_lp64
5187 printf " slab mca obj allocation\n"
5188 printf "slot idx address address address type state\n"
5189 printf "---- ---- ------------------ ------------------ ------------------ ----- -----------\n"
5190 else
5191 printf " slab mca obj allocation\n"
5192 printf "slot idx address address address type state\n"
5193 printf "---- ---- ---------- ---------- ---------- ----- -----------\n"
5194 end
5195
2d21ac55
A
5196 while $x < slabgrp
5197 set $slg = slabstbl[$x]
5198 set $y = 0
5199 set $stop = 0
5200 while $y < $NSLABSPMB && $stop == 0
5201 set $sl = &$slg->slg_slab[$y]
5202 set $base = (char *)$sl->sl_base
5203 set $ix = ($base - (char *)mbutl) >> 11
5204 set $clbase = ((union mcluster *)(mbutl + $ix))
5205 set $mclidx = ($base - (char *)$clbase) >> 8
5206 set $mca = mclaudit[$ix].cl_audit[$mclidx]
5207 set $first = 1
5208
5209 while $mca != 0 && $mca->mca_addr != 0
5210 set $printmca = 0
5211 if $mca->mca_uflags & ($MB_INUSE|$MB_COMP_INUSE)
5212 set $total_a = $total_a + 1
5213 set $printmca = $show_a
5214 else
5215 set $total_f = $total_f + 1
5216 set $printmca = $show_f
5217 end
5218
5219 if $printmca != 0
5220 if $first == 1
b0d623f7 5221 printf "%4d %4d %p ", $x, $y, $sl
2d21ac55 5222 else
b0d623f7
A
5223 if $kgm_lp64
5224 printf " "
5225 else
5226 printf " "
5227 end
2d21ac55
A
5228 end
5229
b0d623f7 5230 printf "%p %p ", $mca, $mca->mca_addr
2d21ac55
A
5231 mbuf_mca_ctype $mca 0
5232 if $mca->mca_uflags & ($MB_INUSE|$MB_COMP_INUSE)
5233 printf "active "
5234 else
5235 printf " freed "
5236 end
5237 if $first == 1
5238 set $first = 0
5239 end
5240 printf "\n"
5241 set $total = $total + 1
b0d623f7
A
5242
5243 if $show_tr != 0
5244 printf "recent transaction for this buffer (thread %p):\n", \
5245 $mca->mca_thread
5246 set $cnt = 0
5247 while $cnt < $mca->mca_depth
5248 set $kgm_pc = $mca->mca_stack[$cnt]
5249 printf "%4d: ", $cnt + 1
5250 pcprint $kgm_pc
5251 printf "\n"
5252 set $cnt = $cnt + 1
5253 end
5254 end
2d21ac55 5255 end
b0d623f7 5256
2d21ac55
A
5257 set $mca = $mca->mca_next
5258 end
5259 set $y += 1
5260 if $slg->slg_slab[$y].sl_base == 0
5261 set $stop = 1
5262 end
5263 end
5264 set $x += 1
5265 end
5266 if $total && $show_a && $show_f
5267 printf "\ntotal objects:\t%d\n", $total
5268 printf "active/unfreed:\t%d\n", $total_a
5269 printf "freed/in_cache:\t%d\n", $total_f
5270 end
5271end
5272
5273document mbuf_walkallslabs
5274| Walk the mbuf objects pool; this requires mbuf debugging to be
5275| turned on, by setting the appropriate flags to the "mbuf_debug" boot-args
5276| parameter. This is a backend routine for mbuf_show{active,inactive,all}.
5277end
5278
b0d623f7
A
5279set $RTF_UP = 0x1
5280set $RTF_GATEWAY = 0x2
5281set $RTF_HOST = 0x4
5282set $RTF_REJECT = 0x8
5283set $RTF_DYNAMIC = 0x10
5284set $RTF_MODIFIED = 0x20
5285set $RTF_DONE = 0x40
5286set $RTF_DELCLONE = 0x80
5287set $RTF_CLONING = 0x100
5288set $RTF_XRESOLVE = 0x200
5289set $RTF_LLINFO = 0x400
5290set $RTF_STATIC = 0x800
5291set $RTF_BLACKHOLE = 0x1000
5292set $RTF_PROTO2 = 0x4000
5293set $RTF_PROTO1 = 0x8000
5294set $RTF_PRCLONING = 0x10000
5295set $RTF_WASCLONED = 0x20000
5296set $RTF_PROTO3 = 0x40000
5297set $RTF_PINNED = 0x100000
5298set $RTF_LOCAL = 0x200000
5299set $RTF_BROADCAST = 0x400000
5300set $RTF_MULTICAST = 0x800000
5301set $RTF_IFSCOPE = 0x1000000
5302set $RTF_CONDEMNED = 0x2000000
5303
5304set $AF_INET = 2
5305set $AF_INET6 = 30
5306set $AF_LINK = 18
5307
5308define rtentry_prdetails
5309 set $rt = (struct rtentry *)$arg0
5310 set $is_v6 = 0
5311
5312 set $dst = (struct sockaddr *)$rt->rt_nodes->rn_u.rn_leaf.rn_Key
5313 if $dst->sa_family == $AF_INET
5314 showsockaddr_in $dst
5315 printf " "
5316 else
5317 if $dst->sa_family == $AF_INET6
5318 showsockaddr_in6 $dst
5319 printf " "
5320 set $is_v6 = 1
5321 else
5322 if $dst->sa_family == $AF_LINK
5323 showsockaddr_dl $dst
5324 printf " "
5325 else
5326 showsockaddr_unspec $dst
5327 end
5328 end
5329 end
5330
5331 set $dst = (struct sockaddr *)$rt->rt_gateway
5332 if $dst->sa_family == $AF_INET
5333 showsockaddr_in $dst
5334 printf " "
5335 else
5336 if $dst->sa_family == $AF_INET6
5337 set $is_v6 = 1
5338 showsockaddr_in6 $dst
5339 printf " "
5340 else
5341 if $dst->sa_family == $AF_LINK
5342 showsockaddr_dl $dst
5343 if $is_v6
5344 printf " "
5345 else
5346 printf " "
5347 end
5348 else
5349 showsockaddr_unspec $dst
5350 end
5351 end
5352 end
5353
5354 if $rt->rt_flags & $RTF_WASCLONED
5355 if $kgm_lp64
5356 printf "%18p ", $rt->rt_parent
5357 else
5358 printf "%10p ", $rt->rt_parent
5359 end
5360 else
5361 if $kgm_lp64
5362 printf " "
5363 else
5364 printf " "
5365 end
5366 end
5367
5368 printf "%6u %8u ", $rt->rt_refcnt, $rt->rt_rmx.rmx_pksent
5369
5370 if $rt->rt_flags & $RTF_UP
5371 printf "U"
5372 end
5373 if $rt->rt_flags & $RTF_GATEWAY
5374 printf "G"
5375 end
5376 if $rt->rt_flags & $RTF_HOST
5377 printf "H"
5378 end
5379 if $rt->rt_flags & $RTF_REJECT
5380 printf "R"
5381 end
5382 if $rt->rt_flags & $RTF_DYNAMIC
5383 printf "D"
5384 end
5385 if $rt->rt_flags & $RTF_MODIFIED
5386 printf "M"
5387 end
5388 if $rt->rt_flags & $RTF_CLONING
5389 printf "C"
5390 end
5391 if $rt->rt_flags & $RTF_PRCLONING
5392 printf "c"
5393 end
5394 if $rt->rt_flags & $RTF_LLINFO
5395 printf "L"
5396 end
5397 if $rt->rt_flags & $RTF_STATIC
5398 printf "S"
5399 end
5400 if $rt->rt_flags & $RTF_PROTO1
5401 printf "1"
5402 end
5403 if $rt->rt_flags & $RTF_PROTO2
5404 printf "2"
5405 end
5406 if $rt->rt_flags & $RTF_PROTO3
5407 printf "3"
5408 end
5409 if $rt->rt_flags & $RTF_WASCLONED
5410 printf "W"
5411 end
5412 if $rt->rt_flags & $RTF_BROADCAST
5413 printf "b"
5414 end
5415 if $rt->rt_flags & $RTF_MULTICAST
5416 printf "m"
5417 end
5418 if $rt->rt_flags & $RTF_XRESOLVE
5419 printf "X"
5420 end
5421 if $rt->rt_flags & $RTF_BLACKHOLE
5422 printf "B"
5423 end
5424 if $rt->rt_flags & $RTF_IFSCOPE
5425 printf "I"
5426 end
5427
5428 printf "/%s%d", $rt->rt_ifp->if_name, $rt->rt_ifp->if_unit
5429end
5430
5431set $RNF_ROOT = 2
5432
5433define _rttable_dump
5434 set $rnh = $arg0
5435 set $rn = (struct radix_node *)$rnh->rnh_treetop
5436 set $rnh_cnt = $rnh->rnh_cnt
5437
5438 while $rn->rn_bit >= 0
5439 set $rn = $rn->rn_u.rn_node.rn_L
5440 end
5441
5442 while 1
5443 set $base = (struct radix_node *)$rn
5444 while ($rn->rn_parent->rn_u.rn_node.rn_R == $rn) && ($rn->rn_flags & $RNF_ROOT) == 0
5445 set $rn = $rn->rn_parent
5446 end
5447 set $rn = $rn->rn_parent->rn_u.rn_node.rn_R
5448 while $rn->rn_bit >= 0
5449 set $rn = $rn->rn_u.rn_node.rn_L
5450 end
5451 set $next = $rn
5452 while $base != 0
5453 set $rn = $base
5454 set $base = $rn->rn_u.rn_leaf.rn_Dupedkey
5455 if ($rn->rn_flags & $RNF_ROOT) == 0
5456
5457 set $rt = (struct rtentry *)$rn
5458
5459 if $kgm_lp64
5460 printf "%18p ", $rt
5461 else
5462 printf "%10p ", $rt
5463 end
5464 rtentry_prdetails $rt
5465 printf "\n"
5466
5467 end
5468 end
5469 set $rn = $next
5470 if ($rn->rn_flags & $RNF_ROOT) != 0
5471 loop_break
5472 end
5473 end
5474end
5475
5476
5477define show_rt_inet
5478 if $kgm_lp64
5479 printf " rtentry dst gw parent Refs Use flags/if\n"
5480 printf " ----------------- --------------- ----------------- ------------------ ------ -------- -----------\n"
5481 else
5482 printf " rtentry dst gw parent Refs Use flags/if\n"
5483 printf " --------- --------------- ----------------- ---------- ------ -------- -----------\n"
5484 end
5485 _rttable_dump rt_tables[2]
5486end
5487
5488document show_rt_inet
5489Syntax: (gdb) show_rt_inet
5490| Show the entries of the IPv4 routing table.
5491end
5492
5493define show_rt_inet6
5494 if $kgm_lp64
5495 printf " rtentry dst gw parent Refs Use flags/if\n"
5496 printf " ----------------- --------------------------------------- --------------------------------------- ------------------ ------ -------- -----------\n"
5497 else
5498 printf " rtentry dst gw parent Refs Use flags/if\n"
5499 printf " --------- --------------------------------------- --------------------------------------- ---------- ------ -------- -----------\n"
5500 end
5501 _rttable_dump rt_tables[30]
5502end
5503
5504document show_rt_inet6
5505Syntax: (gdb) show_rt_inet6
5506| Show the entries of the IPv6 routing table.
5507end
5508
2d21ac55
A
5509define rtentry_trash
5510 set $rtd = (struct rtentry_dbg *)rttrash_head.tqh_first
5511 set $cnt = 0
5512 while $rtd != 0
5513 if $cnt == 0
b0d623f7
A
5514 if $kgm_lp64
5515 printf " rtentry ref hold rele dst gw parent flags/if\n"
5516 printf " ----------------- --- ------ ------ --------------- ----- ------------------ -----------\n"
5517 else
5518 printf " rtentry ref hold rele dst gw parent flags/if\n"
5519 printf " --------- --- ------ ------ --------------- ----- ---------- -----------\n"
5520 end
2d21ac55 5521 end
b0d623f7 5522 printf "%4d: %p %3d %6d %6d ", $cnt + 1, $rtd, \
2d21ac55 5523 $rtd->rtd_refhold_cnt - $rtd->rtd_refrele_cnt, \
b0d623f7
A
5524 $rtd->rtd_refhold_cnt, $rtd->rtd_refrele_cnt
5525 rtentry_prdetails $rtd
5526 printf "\n"
2d21ac55
A
5527 set $rtd = $rtd->rtd_trash_link.tqe_next
5528 set $cnt = $cnt + 1
5529 end
5530end
5531
5532document rtentry_trash
5533Syntax: (gdb) rtentry_trash
5534| Walk the list of trash route entries; this requires route entry
5535| debugging to be turned on, by setting the appropriate flags to the
5536| "rte_debug" boot-args parameter.
5537end
5538
b0d623f7
A
5539set $CTRACE_STACK_SIZE = ctrace_stack_size
5540set $CTRACE_HIST_SIZE = ctrace_hist_size
2d21ac55
A
5541
5542define rtentry_showdbg
5543 set $rtd = (struct rtentry_dbg *)$arg0
5544 set $cnt = 0
5545
b0d623f7
A
5546 printf "Total holds:\t%d\n", $rtd->rtd_refhold_cnt
5547 printf "Total releases:\t%d\n", $rtd->rtd_refrele_cnt
2d21ac55
A
5548
5549 set $ix = 0
b0d623f7
A
5550 while $ix < $CTRACE_STACK_SIZE
5551 set $kgm_pc = $rtd->rtd_alloc.pc[$ix]
5552 if $kgm_pc != 0
2d21ac55
A
5553 if $ix == 0
5554 printf "\nAlloc (thread %p):\n", \
b0d623f7 5555 $rtd->rtd_alloc.th
2d21ac55
A
5556 end
5557 printf "%4d: ", $ix + 1
b0d623f7 5558 pcprint $kgm_pc
2d21ac55
A
5559 printf "\n"
5560 end
5561 set $ix = $ix + 1
5562 end
5563 set $ix = 0
b0d623f7
A
5564 while $ix < $CTRACE_STACK_SIZE
5565 set $kgm_pc = $rtd->rtd_free.pc[$ix]
5566 if $kgm_pc != 0
2d21ac55
A
5567 if $ix == 0
5568 printf "\nFree: (thread %p)\n", \
b0d623f7 5569 $rtd->rtd_free.th
2d21ac55
A
5570 end
5571 printf "%4d: ", $ix + 1
b0d623f7 5572 pcprint $kgm_pc
2d21ac55
A
5573 printf "\n"
5574 end
5575 set $ix = $ix + 1
5576 end
b0d623f7 5577 while $cnt < $CTRACE_HIST_SIZE
2d21ac55 5578 set $ix = 0
b0d623f7
A
5579 while $ix < $CTRACE_STACK_SIZE
5580 set $kgm_pc = $rtd->rtd_refhold[$cnt].pc[$ix]
5581 if $kgm_pc != 0
2d21ac55
A
5582 if $ix == 0
5583 printf "\nHold [%d] (thread %p):\n", \
5584 $cnt, $rtd->rtd_refhold[$cnt].th
5585 end
5586 printf "%4d: ", $ix + 1
b0d623f7 5587 pcprint $kgm_pc
2d21ac55
A
5588 printf "\n"
5589 end
5590 set $ix = $ix + 1
5591 end
5592 set $cnt = $cnt + 1
5593 end
5594 set $cnt = 0
b0d623f7 5595 while $cnt < $CTRACE_HIST_SIZE
2d21ac55 5596 set $ix = 0
b0d623f7
A
5597 while $ix < $CTRACE_STACK_SIZE
5598 set $kgm_pc = $rtd->rtd_refrele[$cnt].pc[$ix]
5599 if $kgm_pc != 0
2d21ac55
A
5600 if $ix == 0
5601 printf "\nRelease [%d] (thread %p):\n",\
5602 $cnt, $rtd->rtd_refrele[$cnt].th
5603 end
5604 printf "%4d: ", $ix + 1
b0d623f7 5605 pcprint $kgm_pc
2d21ac55
A
5606 printf "\n"
5607 end
5608 set $ix = $ix + 1
5609 end
5610 set $cnt = $cnt + 1
5611 end
b0d623f7
A
5612
5613 printf "\nTotal locks:\t%d\n", $rtd->rtd_lock_cnt
5614 printf "Total unlocks:\t%d\n", $rtd->rtd_unlock_cnt
5615
5616 set $cnt = 0
5617 while $cnt < $CTRACE_HIST_SIZE
5618 set $ix = 0
5619 while $ix < $CTRACE_STACK_SIZE
5620 set $kgm_pc = $rtd->rtd_lock[$cnt].pc[$ix]
5621 if $kgm_pc != 0
5622 if $ix == 0
5623 printf "\nLock [%d] (thread %p):\n",\
5624 $cnt, $rtd->rtd_lock[$cnt].th
5625 end
5626 printf "%4d: ", $ix + 1
5627 pcprint $kgm_pc
5628 printf "\n"
5629 end
5630 set $ix = $ix + 1
5631 end
5632 set $cnt = $cnt + 1
5633 end
5634 set $cnt = 0
5635 while $cnt < $CTRACE_HIST_SIZE
5636 set $ix = 0
5637 while $ix < $CTRACE_STACK_SIZE
5638 set $kgm_pc = $rtd->rtd_unlock[$cnt].pc[$ix]
5639 if $kgm_pc != 0
5640 if $ix == 0
5641 printf "\nUnlock [%d] (thread %p):\n",\
5642 $cnt, $rtd->rtd_unlock[$cnt].th
5643 end
5644 printf "%4d: ", $ix + 1
5645 pcprint $kgm_pc
5646 printf "\n"
5647 end
5648 set $ix = $ix + 1
5649 end
5650 set $cnt = $cnt + 1
5651 end
5652end
5653
5654document rtentry_showdbg
5655Syntax: (gdb) rtentry_showdbg <addr>
5656| Given a route entry structure address, print the debug information
5657| related to it. This requires route entry debugging to be turned
5658| on, by setting the appropriate flags to the "rte_debug" boot-args
5659| parameter.
5660end
5661
5662define inifa_showdbg
5663 set $inifa = (struct in_ifaddr_dbg *)$arg0
5664 set $cnt = 0
5665
5666 printf "Total holds:\t%d\n", $inifa->inifa_refhold_cnt
5667 printf "Total releases:\t%d\n", $inifa->inifa_refrele_cnt
5668
5669 set $ix = 0
5670 while $ix < $CTRACE_STACK_SIZE
5671 set $kgm_pc = $inifa->inifa_alloc.pc[$ix]
5672 if $kgm_pc != 0
5673 if $ix == 0
5674 printf "\nAlloc (thread %p):\n", \
5675 $inifa->inifa_alloc.th
5676 end
5677 printf "%4d: ", $ix + 1
5678 pcprint $kgm_pc
5679 printf "\n"
5680 end
5681 set $ix = $ix + 1
5682 end
5683 set $ix = 0
5684 while $ix < $CTRACE_STACK_SIZE
5685 set $kgm_pc = $inifa->inifa_free.pc[$ix]
5686 if $kgm_pc != 0
5687 if $ix == 0
5688 printf "\nFree: (thread %p)\n", \
5689 $inifa->inifa_free.th
5690 end
5691 printf "%4d: ", $ix + 1
5692 pcprint $kgm_pc
5693 printf "\n"
5694 end
5695 set $ix = $ix + 1
5696 end
5697 while $cnt < $CTRACE_HIST_SIZE
5698 set $ix = 0
5699 while $ix < $CTRACE_STACK_SIZE
5700 set $kgm_pc = $inifa->inifa_refhold[$cnt].pc[$ix]
5701 if $kgm_pc != 0
5702 if $ix == 0
5703 printf "\nHold [%d] (thread %p):\n", \
5704 $cnt, $inifa->inifa_refhold[$cnt].th
5705 end
5706 printf "%4d: ", $ix + 1
5707 pcprint $kgm_pc
5708 printf "\n"
5709 end
5710 set $ix = $ix + 1
5711 end
5712 set $cnt = $cnt + 1
5713 end
5714 set $cnt = 0
5715 while $cnt < $CTRACE_HIST_SIZE
5716 set $ix = 0
5717 while $ix < $CTRACE_STACK_SIZE
5718 set $kgm_pc = $inifa->inifa_refrele[$cnt].pc[$ix]
5719 if $kgm_pc != 0
5720 if $ix == 0
5721 printf "\nRelease [%d] (thread %p):\n",\
5722 $cnt, $inifa->inifa_refrele[$cnt].th
5723 end
5724 printf "%4d: ", $ix + 1
5725 pcprint $kgm_pc
5726 printf "\n"
5727 end
5728 set $ix = $ix + 1
5729 end
5730 set $cnt = $cnt + 1
5731 end
5732end
5733
5734document inifa_showdbg
5735Syntax: (gdb) inifa_showdbg <addr>
5736| Given an IPv4 interface structure address, print the debug information
5737| related to it. This requires interface address debugging to be turned
5738| on, by setting the appropriate flags to the "ifa_debug" boot-args
5739| parameter.
5740end
5741
5742define in6ifa_showdbg
5743 set $in6ifa = (struct in6_ifaddr_dbg *)$arg0
5744 set $cnt = 0
5745
5746 printf "Total holds:\t%d\n", $in6ifa->in6ifa_refhold_cnt
5747 printf "Total releases:\t%d\n", $in6ifa->in6ifa_refrele_cnt
5748
5749 set $ix = 0
5750 while $ix < $CTRACE_STACK_SIZE
5751 set $kgm_pc = $in6ifa->in6ifa_alloc.pc[$ix]
5752 if $kgm_pc != 0
5753 if $ix == 0
5754 printf "\nAlloc (thread %p):\n", \
5755 $in6ifa->in6ifa_alloc.th
5756 end
5757 printf "%4d: ", $ix + 1
5758 pcprint $kgm_pc
5759 printf "\n"
5760 end
5761 set $ix = $ix + 1
5762 end
5763 set $ix = 0
5764 while $ix < $CTRACE_STACK_SIZE
5765 set $kgm_pc = $in6ifa->in6ifa_free.pc[$ix]
5766 if $kgm_pc != 0
5767 if $ix == 0
5768 printf "\nFree: (thread %p)\n", \
5769 $in6ifa->in6ifa_free.th
5770 end
5771 printf "%4d: ", $ix + 1
5772 pcprint $kgm_pc
5773 printf "\n"
5774 end
5775 set $ix = $ix + 1
5776 end
5777 while $cnt < $CTRACE_HIST_SIZE
5778 set $ix = 0
5779 while $ix < $CTRACE_STACK_SIZE
5780 set $kgm_pc = $in6ifa->in6ifa_refhold[$cnt].pc[$ix]
5781 if $kgm_pc != 0
5782 if $ix == 0
5783 printf "\nHold [%d] (thread %p):\n", \
5784 $cnt, $in6ifa->in6ifa_refhold[$cnt].th
5785 end
5786 printf "%4d: ", $ix + 1
5787 pcprint $kgm_pc
5788 printf "\n"
5789 end
5790 set $ix = $ix + 1
5791 end
5792 set $cnt = $cnt + 1
5793 end
5794 set $cnt = 0
5795 while $cnt < $CTRACE_HIST_SIZE
5796 set $ix = 0
5797 while $ix < $CTRACE_STACK_SIZE
5798 set $kgm_pc = $in6ifa->in6ifa_refrele[$cnt].pc[$ix]
5799 if $kgm_pc != 0
5800 if $ix == 0
5801 printf "\nRelease [%d] (thread %p):\n",\
5802 $cnt, $in6ifa->in6ifa_refrele[$cnt].th
5803 end
5804 printf "%4d: ", $ix + 1
5805 pcprint $kgm_pc
5806 printf "\n"
5807 end
5808 set $ix = $ix + 1
5809 end
5810 set $cnt = $cnt + 1
5811 end
5812end
5813
5814document in6ifa_showdbg
5815Syntax: (gdb) in6ifa_showdbg <addr>
5816| Given an IPv6 interface structure address, print the debug information
5817| related to it. This requires interface address debugging to be turned
5818| on, by setting the appropriate flags to the "ifa_debug" boot-args
5819| parameter.
5820end
5821
5822#
5823# print all OSMalloc stats
5824
5825define ostag_print
5826set $kgm_tagp = (OSMallocTag)$arg0
5827printf "0x%08x: ", $kgm_tagp
5828printf "%8d ",$kgm_tagp->OSMT_refcnt
5829printf "%8x ",$kgm_tagp->OSMT_state
5830printf "%8x ",$kgm_tagp->OSMT_attr
5831printf "%s ",$kgm_tagp->OSMT_name
5832printf "\n"
5833end
2d21ac55
A
5834
5835
5836define showosmalloc
5837printf "TAG COUNT STATE ATTR NAME\n"
5838set $kgm_tagheadp = (OSMallocTag)&OSMalloc_tag_list
5839 set $kgm_tagptr = (OSMallocTag )($kgm_tagheadp->OSMT_link.next)
5840 while $kgm_tagptr != $kgm_tagheadp
5841 ostag_print $kgm_tagptr
5842 set $kgm_tagptr = (OSMallocTag)$kgm_tagptr->OSMT_link.next
5843 end
5844 printf "\n"
5845end
5846document showosmalloc
5847Syntax: (gdb) showosmalloc
5848| Print the outstanding allocation count by OSMallocTags.
5849end
5850
5851
5852define systemlog
5853 if msgbufp->msg_bufc[msgbufp->msg_bufx] == 0
5854 # The buffer hasn't wrapped, so take the easy (and fast!) path
5855 printf "%s", msgbufp->msg_bufc
5856 else
5857 set $kgm_msgbuf = *msgbufp
5858 set $kgm_syslog_bufsize = $kgm_msgbuf.msg_size
5859 set $kgm_syslog_bufend = $kgm_msgbuf.msg_bufx
5860 if $kgm_syslog_bufend >= $kgm_syslog_bufsize
5861 set $kgm_syslog_bufend = 0
5862 end
5863
5864 # print older messages from msg_bufx to end of buffer
5865 set $kgm_i = $kgm_syslog_bufend
5866 while $kgm_i < $kgm_syslog_bufsize
5867 set $kgm_syslog_char = $kgm_msgbuf.msg_bufc[$kgm_i]
5868 if $kgm_syslog_char == 0
5869 # break out of loop
5870 set $kgm_i = $kgm_syslog_bufsize
5871 else
5872 printf "%c", $kgm_syslog_char
5873 end
5874 set $kgm_i = $kgm_i + 1
5875 end
5876
5877 # print newer messages from start of buffer to msg_bufx
5878 set $kgm_i = 0
5879 while $kgm_i < $kgm_syslog_bufend
5880 set $kgm_syslog_char = $kgm_msgbuf.msg_bufc[$kgm_i]
5881 printf "%c", $kgm_syslog_char
5882 set $kgm_i = $kgm_i + 1
5883 end
5884 end
5885 printf "\n"
5886end
5887document systemlog
5888| Syntax: systemlog
5889| Display the kernel's printf ring buffer
5890end
5891
b0d623f7
A
5892
5893define hexdump
5894 set $kgm_addr = (unsigned char *)$arg0
5895 set $kgm_len = $arg1
5896 while $kgm_len > 0
5897 showptr $kgm_addr
5898 printf ": "
5899 set $kgm_i = 0
5900 while $kgm_i < 16
5901 printf "%02x ", *($kgm_addr+$kgm_i)
5902 set $kgm_i += 1
5903 end
5904 printf " |"
5905 set $kgm_i = 0
5906 while $kgm_i < 16
5907 set $kgm_temp = *($kgm_addr+$kgm_i)
5908 if $kgm_temp < 32 || $kgm_temp >= 127
5909 printf "."
5910 else
5911 printf "%c", $kgm_temp
2d21ac55 5912 end
b0d623f7 5913 set $kgm_i += 1
2d21ac55 5914 end
b0d623f7
A
5915 printf "|\n"
5916 set $kgm_addr += 16
5917 set $kgm_len -= 16
2d21ac55
A
5918 end
5919end
b0d623f7
A
5920document hexdump
5921| Show the contents of memory as a hex/ASCII dump
2d21ac55 5922| The following is the syntax:
b0d623f7 5923| (gdb) hexdump <address> <length>
2d21ac55
A
5924end
5925
2d21ac55 5926
b0d623f7
A
5927define printcolonhex
5928 if ($argc == 2)
5929 set $addr = $arg0
5930 set $count = $arg1
5931 set $li = 0
5932 while ($li < $count)
5933 if ($li == 0)
5934 printf "%02x", (u_char)$addr[$li]
5935 end
5936 if ($li != 0)
5937 printf ":%02x", (u_char)$addr[$li]
5938 end
5939 set $li = $li + 1
5940 end
2d21ac55 5941 end
b0d623f7 5942end
2d21ac55 5943
b0d623f7
A
5944define showsockaddr_dl
5945 set $sdl = (struct sockaddr_dl *)$arg0
5946 if ($sdl == 0)
5947 printf "(null) "
2d21ac55 5948 else
b0d623f7
A
5949 if $sdl->sdl_nlen == 0 && $sdl->sdl_alen == 0 && $sdl->sdl_slen == 0
5950 printf "link#%3d ", $sdl->sdl_index
2d21ac55 5951 else
b0d623f7
A
5952 set $addr = $sdl->sdl_data + $sdl->sdl_nlen
5953 set $count = $sdl->sdl_alen
5954 printcolonhex $addr $count
5955 end
2d21ac55 5956 end
b0d623f7 5957end
2d21ac55 5958
b0d623f7
A
5959define showsockaddr_unspec
5960 set $sockaddr = (struct sockaddr *)$arg0
5961 set $addr = $sockaddr->sa_data
5962 set $count = $sockaddr->sa_len - 2
5963 printcolonhex $addr $count
2d21ac55
A
5964end
5965
b0d623f7
A
5966define showsockaddr_at
5967 set $sockaddr = (struct sockaddr *)$arg0
5968 set $addr = $sockaddr->sa_data
5969 set $count = $sockaddr->sa_len - 2
5970 printcolonhex $addr $count
5971end
2d21ac55
A
5972
5973define showsockaddr_in
5974 set $sin = (struct sockaddr_in *)$arg0
5975 set $sa_bytes = (unsigned char *)&($sin->sin_addr)
b0d623f7 5976 printf "%3u.%03u.%03u.%03u", $sa_bytes[0], $sa_bytes[1], $sa_bytes[2], $sa_bytes[3]
2d21ac55
A
5977end
5978
5979define showsockaddr_in6
5980 set $sin6 = (struct sockaddr_in6 *)$arg0
5981 set $sa_bytes = $sin6->sin6_addr.__u6_addr.__u6_addr8
b0d623f7
A
5982 printf "%2x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x", \
5983 $sa_bytes[0], $sa_bytes[1], $sa_bytes[2], $sa_bytes[3], $sa_bytes[4], $sa_bytes[5], $sa_bytes[6], $sa_bytes[7], $sa_bytes[8], $sa_bytes[9], $sa_bytes[10], $sa_bytes[11], $sa_bytes[12], $sa_bytes[13], $sa_bytes[14], $sa_bytes[15]
5984end
5985
5986define showsockaddr_un
5987 set $sun = (struct sockaddr_un *)$arg0
5988 if $sun == 0
5989 printf "(null)"
5990 else
5991 if $sun->sun_path[0] == 0
5992 printf "\"\""
5993 else
5994 printf "%s", $sun->sun_path
5995 end
5996 end
2d21ac55
A
5997end
5998
5999define showifmultiaddrs
6000 set $ifp = (struct ifnet *)$arg0
6001 set $if_multi = (struct ifmultiaddr *)$ifp->if_multiaddrs->lh_first
6002 set $mymulti = $if_multi
6003 set $myi = 0
6004 while ($mymulti != 0)
6005 printf "%2d. ", $myi
6006 set $sa_family = $mymulti->ifma_addr.sa_family
6007 if ($sa_family == 2)
6008 if ($mymulti->ifma_ll != 0)
6009 showsockaddr_dl $mymulti->ifma_ll->ifma_addr
6010 printf " "
6011 end
6012 showsockaddr_in $mymulti->ifma_addr
6013 end
6014 if ($sa_family == 30)
6015 if ($mymulti->ifma_ll != 0)
6016 showsockaddr_dl $mymulti->ifma_ll->ifma_addr
6017 printf " "
6018 end
6019 showsockaddr_in6 $mymulti->ifma_addr
6020 end
6021 if ($sa_family == 18)
6022 showsockaddr_dl $mymulti->ifma_addr
6023 end
6024 if ($sa_family == 0)
6025 showsockaddr_unspec $mymulti->ifma_addr 6
6026 end
6027 printf " [%d]", $mymulti->ifma_refcount
6028 printf "\n"
6029 set $mymulti = $mymulti->ifma_link.le_next
6030 set $myi = $myi + 1
6031 end
6032end
6033
6034document showifmultiaddrs
6035Syntax showifmultiaddrs <ifp>
6036| show the (struct ifnet).if_multiaddrs list of multicast addresses for the given ifp
6037end
6038
6039define showsockaddr
6040 set $mysock = (struct sockaddr *)$arg0
6041 set $showsockaddr_handled = 0
6042 if ($mysock == 0)
6043 printf "(null)"
6044 else
6045 if ($mysock->sa_family == 0)
b0d623f7 6046 printf "UNSPC"
2d21ac55
A
6047 showsockaddr_unspec $mysock
6048 set $showsockaddr_handled = 1
6049 end
b0d623f7
A
6050 if ($mysock->sa_family == 1)
6051 printf "UNIX "
6052 showsockaddr_un $mysock
6053 set $showsockaddr_handled = 1
6054 end
2d21ac55 6055 if ($mysock->sa_family == 2)
b0d623f7 6056 printf "INET "
2d21ac55
A
6057 showsockaddr_in $mysock
6058 set $showsockaddr_handled = 1
6059 end
6060 if ($mysock->sa_family == 30)
b0d623f7 6061 printf "INET6 "
2d21ac55
A
6062 showsockaddr_in6 $mysock
6063 set $showsockaddr_handled = 1
6064 end
6065 if ($mysock->sa_family == 18)
b0d623f7 6066 printf "LINK "
2d21ac55
A
6067 showsockaddr_dl $mysock
6068 set $showsockaddr_handled = 1
6069 end
6070 if ($mysock->sa_family == 16)
b0d623f7 6071 printf "ATLK "
2d21ac55
A
6072 showsockaddr_at $mysock
6073 set $showsockaddr_handled = 1
6074 end
6075 if ($showsockaddr_handled == 0)
b0d623f7 6076 printf "FAM %d ", $mysock->sa_family
2d21ac55
A
6077 set $addr = $mysock->sa_data
6078 set $count = $mysock->sa_len
6079 printcolonhex $addr $count
6080 end
6081 end
6082end
6083
6084define showifflags
6085 set $flags = (u_short)$arg0
6086 set $first = 1
6087 printf "<"
6088 if ($flags & 0x1)
6089 printf "UP"
6090 set $first = 0
6091 end
6092 if ($flags & 0x2)
6093 if ($first == 1)
6094 set $first = 0
6095 else
6096 printf ","
6097 end
6098 printf "BROADCAST"
6099 end
6100 if ($flags & 0x4)
6101 printf "DEBUG"
6102 end
6103 if ($flags & 0x8)
6104 if ($first == 1)
6105 set $first = 0
6106 else
6107 printf ","
6108 end
6109 printf "LOOPBACK"
6110 end
6111 if ($flags & 0x10)
6112 if ($first == 1)
6113 set $first = 0
6114 else
6115 printf ","
6116 end
6117 printf "POINTTOPOINT"
6118 end
6119# if ($flags & 0x20)
6120# if ($first == 1)
6121# set $first = 0
6122# else
6123# printf ","
6124# end
6125# printf "NOTRAILERS"
6126# end
6127 if ($flags & 0x40)
6128 if ($first == 1)
6129 set $first = 0
6130 else
6131 printf ","
6132 end
6133 printf "RUNNING"
6134 end
6135 if ($flags & 0x80)
6136 if ($first == 1)
6137 set $first = 0
6138 else
6139 printf ","
6140 end
6141 printf "NOARP"
6142 end
6143 if ($flags & 0x100)
6144 if ($first == 1)
6145 set $first = 0
6146 else
6147 printf ","
6148 end
6149 printf "PROMISC"
6150 end
6151 if ($flags & 0x200)
6152 if ($first == 1)
6153 set $first = 0
6154 else
6155 printf ","
6156 end
6157 printf "ALLMULTI"
6158 end
6159 if ($flags & 0x400)
6160 if ($first == 1)
6161 set $first = 0
6162 else
6163 printf ","
6164 end
6165 printf "OACTIVE"
6166 end
6167 if ($flags & 0x800)
6168 if ($first == 1)
6169 set $first = 0
6170 else
6171 printf ","
6172 end
6173 printf "SIMPLEX"
6174 end
6175 if ($flags & 0x1000)
6176 if ($first == 1)
6177 set $first = 0
6178 else
6179 printf ","
6180 end
6181 printf "LINK0"
6182 end
6183 if ($flags & 0x2000)
6184 if ($first == 1)
6185 set $first = 0
6186 else
6187 printf ","
6188 end
6189 printf "LINK1"
6190 end
6191 if ($flags & 0x4000)
6192 if ($first == 1)
6193 set $first = 0
6194 else
6195 printf ","
6196 end
6197 printf "LINK2-ALTPHYS"
6198 end
6199 if ($flags & 0x8000)
6200 if ($first == 1)
6201 set $first = 0
6202 else
6203 printf ","
6204 end
6205 printf "MULTICAST"
6206 end
6207 printf ">"
6208end
6209
6210define showifaddrs
6211 set $ifp = (struct ifnet *)$arg0
6212 set $myifaddr = (struct ifaddr *)$ifp->if_addrhead->tqh_first
6213 set $myi = 0
6214 while ($myifaddr != 0)
6215 printf "\t%d. ", $myi
6216 showsockaddr $myifaddr->ifa_addr
6217 printf " [%d]\n", $myifaddr->ifa_refcnt
6218 set $myifaddr = $myifaddr->ifa_link->tqe_next
6219 set $myi = $myi + 1
6220 end
6221end
6222
6223document showifaddrs
6224Syntax: showifaddrs <ifp>
6225| show the (struct ifnet).if_addrhead list of addresses for the given ifp
6226end
6227
6228define ifconfig
6229 set $ifconfig_all = 0
6230 if ($argc == 1)
6231 set $ifconfig_all = 1
6232 end
6233 set $ifp = (struct ifnet *)(ifnet->tqh_first)
6234 while ($ifp != 0)
b0d623f7 6235 printf "%s%d: flags=%hx", $ifp->if_name, $ifp->if_unit, (u_short)$ifp->if_flags
2d21ac55 6236 showifflags $ifp->if_flags
b0d623f7 6237 printf " index %d", $ifp->if_index
2d21ac55 6238 printf " mtu %d\n", $ifp->if_data.ifi_mtu
b0d623f7
A
6239 printf "\t(struct ifnet *)"
6240 showptr $ifp
6241 printf "\n"
2d21ac55
A
6242 if ($ifconfig_all == 1)
6243 showifaddrs $ifp
b0d623f7 6244 end
2d21ac55
A
6245 set $ifp = $ifp->if_link->tqe_next
6246 end
6247end
6248document ifconfig
6249Syntax: (gdb) ifconfig
6250| display ifconfig-like output, and print the (struct ifnet *) pointers for further inspection
6251end
6252
b0d623f7
A
6253define _show_unix_domain_socket
6254 set $so = (struct socket *)$arg0
6255 set $pcb = (struct unpcb *)$so->so_pcb
6256 if $pcb == 0
6257 printf "unpcb: (null) "
6258 else
6259 printf "unpcb: %p ", $pcb
6260 printf "unp_vnode: %p ", $pcb->unp_vnode
6261 printf "unp_conn: %p ", $pcb->unp_conn
6262 printf "unp_addr: "
6263 showsockaddr_un $pcb->unp_addr
2d21ac55 6264 end
2d21ac55
A
6265end
6266
b0d623f7
A
6267define _show_in_port
6268 set $str = (unsigned char *)$arg0
6269 set $port = *(unsigned short *)$arg0
6270
6271 if (((($port & 0xff00) >> 8) == $str[0])) && ((($port & 0x00ff) == $str[1]))
6272 #printf "big endian "
6273 printf ":%d ", $port
6274 else
6275 #printf "little endian "
6276 printf ":%d ", (($port & 0xff00) >> 8) | (($port & 0x00ff) << 8)
2d21ac55
A
6277 end
6278end
6279
b0d623f7
A
6280define _show_in_addr_4in6
6281 set $ia = (unsigned char *)$arg0
6282 if $ia
6283 printf "%3u.%03u.%03u.%03u", $ia[0], $ia[1], $ia[2], $ia[3]
6284 end
2d21ac55
A
6285end
6286
b0d623f7
A
6287define _show_in6_addr
6288 set $ia = (unsigned char *)$arg0
6289 if $ia
6290 printf "%2x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x", \
6291 $ia[0], $ia[1], $ia[2], $ia[3], $ia[4], $ia[5], $ia[6], $ia[7], \
6292 $ia[8], $ia[9], $ia[10], $ia[11], $ia[12], $ia[13], $ia[14], $ia[15]
6293 end
2d21ac55
A
6294end
6295
b0d623f7
A
6296define _showtcpstate
6297 set $tp = (struct tcpcb *)$arg0
6298 if $tp
6299 if $tp->t_state == 0
6300 printf "CLOSED "
6301 end
6302 if $tp->t_state == 1
6303 printf "LISTEN "
6304 end
6305 if $tp->t_state == 2
6306 printf "SYN_SENT "
6307 end
6308 if $tp->t_state == 3
6309 printf "SYN_RCVD "
6310 end
6311 if $tp->t_state == 4
6312 printf "ESTABLISHED "
6313 end
6314 if $tp->t_state == 5
6315 printf "CLOSE_WAIT "
6316 end
6317 if $tp->t_state == 6
6318 printf "FIN_WAIT_1 "
6319 end
6320 if $tp->t_state == 7
6321 printf "CLOSING "
6322 end
6323 if $tp->t_state == 8
6324 printf "LAST_ACK "
6325 end
6326 if $tp->t_state == 9
6327 printf "FIN_WAIT_2 "
6328 end
6329 if $tp->t_state == 10
6330 printf "TIME_WAIT "
6331 end
2d21ac55 6332 end
b0d623f7
A
6333end
6334
6335define _showsockprotocol
6336 set $so = (struct socket *)$arg0
6337 set $inpcb = (struct inpcb *)$so->so_pcb
6338
6339 if $so->so_proto->pr_protocol == 6
6340 printf "TCP "
6341 _showtcpstate $inpcb->inp_ppcb
2d21ac55 6342 end
b0d623f7
A
6343 if $so->so_proto->pr_protocol == 17
6344 printf "UDP "
2d21ac55 6345 end
b0d623f7
A
6346 if $so->so_proto->pr_protocol == 1
6347 printf "ICMP "
2d21ac55 6348 end
b0d623f7
A
6349 if $so->so_proto->pr_protocol == 254
6350 printf "DIVERT "
2d21ac55 6351 end
b0d623f7
A
6352 if $so->so_proto->pr_protocol == 255
6353 printf "RAW "
2d21ac55 6354 end
b0d623f7 6355end
2d21ac55 6356
b0d623f7
A
6357define _show_ipv4_socket
6358 set $so = (struct socket *)$arg0
6359 set $inpcb = (struct inpcb *)$so->so_pcb
6360 if $inpcb == 0
6361 printf "inpcb: (null) "
2d21ac55 6362 else
b0d623f7
A
6363 printf "inpcb: %p ", $inpcb
6364
6365 _showsockprotocol $so
6366
6367 _show_in_addr_4in6 &$inpcb->inp_dependladdr.inp46_local
6368 _show_in_port &$inpcb->inp_lport
6369 printf "-> "
6370 _show_in_addr_4in6 &$inpcb->inp_dependfaddr.inp46_foreign
6371 _show_in_port &$inpcb->inp_fport
2d21ac55
A
6372 end
6373end
6374
b0d623f7
A
6375define _show_ipv6_socket
6376 set $so = (struct socket *)$arg0
6377 set $pcb = (struct inpcb *)$so->so_pcb
6378 if $pcb == 0
6379 printf "inpcb: (null) "
6380 else
6381 printf "inpcb: %p ", $pcb
2d21ac55 6382
b0d623f7 6383 _showsockprotocol $so
2d21ac55 6384
b0d623f7
A
6385 _show_in6_addr &$pcb->inp_dependladdr.inp6_local
6386 _show_in_port &$pcb->inp_lport
6387 printf "-> "
6388 _show_in6_addr &$pcb->inp_dependfaddr.inp6_foreign
6389 _show_in_port &$pcb->inp_fport
2d21ac55
A
6390 end
6391end
6392
2d21ac55 6393
b0d623f7
A
6394define showsocket
6395 set $so = (struct socket *)$arg0
6396 if $so == 0
6397 printf "so: (null) "
6398 else
6399 printf "so: %p ", $so
6400 if $so && $so->so_proto && $so->so_proto->pr_domain
6401 set $domain = (struct domain *) $so->so_proto->pr_domain
2d21ac55 6402
b0d623f7
A
6403 printf "%s ", $domain->dom_name
6404 if $domain->dom_family == 1
6405 _show_unix_domain_socket $so
6406 end
6407 if $domain->dom_family == 2
6408 _show_ipv4_socket $so
6409 end
6410 if $domain->dom_family == 30
6411 _show_ipv6_socket $so
2d21ac55 6412 end
2d21ac55 6413 end
2d21ac55 6414 end
b0d623f7 6415 printf "\n"
2d21ac55 6416end
b0d623f7
A
6417document showsocket
6418Syntax: (gdb) showsocket <socket_address>
6419| Routine to print out a socket
2d21ac55
A
6420end
6421
b0d623f7
A
6422define showprocsockets
6423 set $pp = (struct proc *)$arg0
6424 set $fdp = (struct filedesc *)$pp->p_fd
6425
6426 set $count = 0
6427 set $fpp = (struct fileproc **)($fdp->fd_ofiles)
6428 set $fpo = (char)($fdp->fd_ofileflags[0])
6429 while $count < $fdp->fd_nfiles
6430 if *$fpp
6431 set $fg =(struct fileglob *)((**$fpp)->f_fglob)
6432 if $fg && (($fg)->fg_type == 2)
6433 if $fdp->fd_ofileflags[$count] & 4
6434 printf "U: "
6435 else
6436 printf " "
6437 end
6438 printf "fd = %d ", $count
6439 if $fg->fg_data
6440 showsocket $fg->fg_data
6441 else
6442 printf "\n"
6443 end
6444 end
2d21ac55 6445 end
b0d623f7
A
6446 set $fpp = $fpp + 1
6447 set $count = $count + 1
2d21ac55
A
6448 end
6449end
b0d623f7
A
6450document showprocsockets
6451Syntax: (gdb) showprocsockets <proc_address>
6452| Routine to print out all the open fds
6453| which are sockets in a process
2d21ac55
A
6454end
6455
b0d623f7
A
6456define showallprocsockets
6457 set $basep = (struct proc *)allproc->lh_first
6458 set $pp = $basep
6459 while $pp
6460 printf "============================================ \n"
6461 showproc $pp
6462 showprocsockets $pp
6463 set $pp = $pp->p_list.le_next
6464 end
2d21ac55 6465end
b0d623f7
A
6466document showallprocsockets
6467Syntax: (gdb) showallprocsockets
6468| Routine to print out all the open fds
6469| which are sockets
6470end
6471
6472define _print_ntohs
6473 set $port = (unsigned short)$arg0
6474 set $port = (unsigned short)((($arg0 & 0xff00) >> 8) & 0xff)
6475 set $port |= (unsigned short)(($arg0 & 0xff) << 8)
6476 printf "%5d", $port
6477end
6478
6479set $INPCB_STATE_INUSE=0x1
6480set $INPCB_STATE_CACHED=0x2
6481set $INPCB_STATE_DEAD=0x3
6482
6483set $INP_RECVOPTS=0x01
6484set $INP_RECVRETOPTS=0x02
6485set $INP_RECVDSTADDR=0x04
6486set $INP_HDRINCL=0x08
6487set $INP_HIGHPORT=0x10
6488set $INP_LOWPORT=0x20
6489set $INP_ANONPORT=0x40
6490set $INP_RECVIF=0x80
6491set $INP_MTUDISC=0x100
6492set $INP_STRIPHDR=0x200
6493set $INP_FAITH=0x400
6494set $INP_INADDR_ANY=0x800
6495set $INP_RECVTTL=0x1000
6496set $INP_UDP_NOCKSUM=0x2000
6497set $IN6P_IPV6_V6ONLY=0x008000
6498set $IN6P_PKTINFO=0x010000
6499set $IN6P_HOPLIMIT=0x020000
6500set $IN6P_HOPOPTS=0x040000
6501set $IN6P_DSTOPTS=0x080000
6502set $IN6P_RTHDR=0x100000
6503set $IN6P_RTHDRDSTOPTS=0x200000
6504set $IN6P_AUTOFLOWLABEL=0x800000
6505set $IN6P_BINDV6ONLY=0x10000000
6506
6507set $INP_IPV4=0x1
6508set $INP_IPV6=0x2
6509
6510set $IPPROTO_TCP=6
6511set $IPPROTO_UDP=17
6512
6513define _dump_inpcb
6514 set $pcb = (struct inpcb *)$arg0
6515 if $kgm_lp64
6516 printf "%18p", $pcb
6517 else
6518 printf "%10p ", $pcb
6519 end
6520 if $arg1 == $IPPROTO_TCP
6521 printf "tcp"
6522 else
6523 if $arg1 == $IPPROTO_UDP
6524 printf "udp"
6525 else
6526 printf "%2d.", $arg1
6527 end
6528 end
6529 if ($pcb->inp_vflag & $INP_IPV4)
6530 printf "4 "
6531 end
6532 if ($pcb->inp_vflag & $INP_IPV6)
6533 printf "6 "
6534 end
2d21ac55 6535
b0d623f7
A
6536 if ($pcb->inp_vflag & $INP_IPV4)
6537 printf " "
6538 _show_in_addr &$pcb->inp_dependladdr.inp46_local.ia46_addr4
2d21ac55 6539 else
b0d623f7 6540 _show_in6_addr &$pcb->inp_dependladdr.inp6_local
2d21ac55 6541 end
b0d623f7
A
6542 printf " "
6543 _print_ntohs $pcb->inp_lport
6544 printf " "
6545 if ($pcb->inp_vflag & $INP_IPV4)
6546 printf " "
6547 _show_in_addr &($pcb->inp_dependfaddr.inp46_foreign.ia46_addr4)
6548 else
6549 _show_in6_addr &($pcb->inp_dependfaddr.inp6_foreign)
6550 end
6551 printf " "
6552 _print_ntohs $pcb->inp_fport
6553 printf " "
2d21ac55 6554
b0d623f7
A
6555 if $arg1 == $IPPROTO_TCP
6556 _showtcpstate $pcb->inp_ppcb
6557 end
2d21ac55 6558
b0d623f7
A
6559# printf "phd "
6560# set $phd = $pcb->inp_phd
6561# while $phd != 0
6562# printf " "
6563# _print_ntohs $phd->phd_port
6564# set $phd = $phd->phd_hash.le_next
6565# end
6566# printf ", "
6567 if ($pcb->inp_flags & $INP_RECVOPTS)
6568 printf "recvopts "
6569 end
6570 if ($pcb->inp_flags & $INP_RECVRETOPTS)
6571 printf "recvretopts "
6572 end
6573 if ($pcb->inp_flags & $INP_RECVDSTADDR)
6574 printf "recvdstaddr "
6575 end
6576 if ($pcb->inp_flags & $INP_HDRINCL)
6577 printf "hdrincl "
6578 end
6579 if ($pcb->inp_flags & $INP_HIGHPORT)
6580 printf "highport "
6581 end
6582 if ($pcb->inp_flags & $INP_LOWPORT)
6583 printf "lowport "
6584 end
6585 if ($pcb->inp_flags & $INP_ANONPORT)
6586 printf "anonport "
6587 end
6588 if ($pcb->inp_flags & $INP_RECVIF)
6589 printf "recvif "
6590 end
6591 if ($pcb->inp_flags & $INP_MTUDISC)
6592 printf "mtudisc "
6593 end
6594 if ($pcb->inp_flags & $INP_STRIPHDR)
6595 printf "striphdr "
6596 end
6597 if ($pcb->inp_flags & $INP_FAITH)
6598 printf "faith "
6599 end
6600 if ($pcb->inp_flags & $INP_INADDR_ANY)
6601 printf "inaddr_any "
6602 end
6603 if ($pcb->inp_flags & $INP_RECVTTL)
6604 printf "recvttl "
6605 end
6606 if ($pcb->inp_flags & $INP_UDP_NOCKSUM)
6607 printf "nocksum "
2d21ac55 6608 end
b0d623f7
A
6609 if ($pcb->inp_flags & $IN6P_IPV6_V6ONLY)
6610 printf "v6only "
6611 end
6612 if ($pcb->inp_flags & $IN6P_PKTINFO)
6613 printf "pktinfo "
6614 end
6615 if ($pcb->inp_flags & $IN6P_HOPLIMIT)
6616 printf "hoplimit "
6617 end
6618 if ($pcb->inp_flags & $IN6P_HOPOPTS)
6619 printf "hopopts "
6620 end
6621 if ($pcb->inp_flags & $IN6P_DSTOPTS)
6622 printf "dstopts "
6623 end
6624 if ($pcb->inp_flags & $IN6P_RTHDR)
6625 printf "rthdr "
6626 end
6627 if ($pcb->inp_flags & $IN6P_RTHDRDSTOPTS)
6628 printf "rthdrdstopts "
6629 end
6630 if ($pcb->inp_flags & $IN6P_AUTOFLOWLABEL)
6631 printf "autoflowlabel "
6632 end
6633 if ($pcb->inp_flags & $IN6P_BINDV6ONLY)
6634 printf "bindv6only "
6635 end
6636 set $so = (struct socket *)$pcb->inp_socket
6637 if $so != 0
6638 printf "[so=%p s=%ld r=%ld usecnt=%ld] ", $so, $so->so_snd.sb_cc, \
6639 $so->so_rcv.sb_cc, $so->so_usecount
6640 end
6641 if ($pcb->inp_state == 0 || $pcb->inp_state == $INPCB_STATE_INUSE)
6642 printf "inuse, "
6643 else
6644 if ($pcb->inp_state == $INPCB_STATE_CACHED)
6645 printf "cached, "
6646 else
6647 if ($pcb->inp_state == $INPCB_STATE_DEAD)
6648 printf "dead, "
6649 else
6650 printf "unknown (%d), ", $pcb->inp_state
6651 end
6652 end
6653 end
6654end
2d21ac55 6655
b0d623f7
A
6656define _dump_inpcbport
6657 set $ppcb = (struct inpcbport *)$arg0
6658 printf "%p: lport ", $ppcb
6659 _print_ntohs $ppcb->phd_port
2d21ac55
A
6660end
6661
b0d623f7 6662set $UDBHASHSIZE=16
2d21ac55 6663
b0d623f7
A
6664define _dump_pcbinfo
6665 set $snd_cc = 0
6666 set $rcv_cc = 0
6667 set $pcbseen = 0
6668 set $pcbi = (struct inpcbinfo *)$arg0
6669 printf "lastport %d lastlow %d lasthi %d\n", \
6670 $pcbi->lastport, $pcbi->lastlow, $pcbi->lasthi
6671 printf "active pcb count is %d\n", $pcbi->ipi_count
6672 set $hashsize = $pcbi->hashmask + 1
6673 printf "hash size is %d\n", $hashsize
6674 printf "hash base %p has the following inpcb(s):\n", $pcbi->hashbase
6675 if $kgm_lp64
6676 printf "pcb prot source address port destination address port\n"
6677 printf "------------------ ---- --------------------------------------- ----- --------------------------------------- -----\n"
6678 else
6679 printf "pcb prot source address port destination address port\n"
6680 printf "---------- ---- --------------------------------------- ----- --------------------------------------- -----\n"
6681 end
6682 set $i = 0
6683 set $hashbase = $pcbi->hashbase
6684 set $head = *(uintptr_t *)$hashbase
6685 while $i < $hashsize
6686 if $head != 0
6687 set $pcb0 = (struct inpcb *)$head
6688 while $pcb0 != 0
6689 set $pcbseen += 1
6690 _dump_inpcb $pcb0 $arg1
6691 set $so = (struct socket *)$pcb->inp_socket
6692 if $so != 0
6693 set $snd_cc += $so->so_snd.sb_cc
6694 set $rcv_cc += $so-> so_rcv.sb_cc
6695 end
6696 set $pcb0 = $pcb0->inp_hash.le_next
6697 printf "\n"
6698 end
6699 end
6700 set $i += 1
6701 set $hashbase += 1
6702 set $head = *(uintptr_t *)$hashbase
6703 end
6704 printf "total seen %ld snd_cc %ld rcv_cc %ld\n", $pcbseen, $snd_cc, $rcv_cc
6705 printf "port hash base is %p\n", $pcbi->porthashbase
6706 set $i = 0
6707 set $hashbase = $pcbi->porthashbase
6708 set $head = *(uintptr_t *)$hashbase
6709 while $i < $hashsize
6710 if $head != 0
6711 set $pcb0 = (struct inpcbport *)$head
6712 while $pcb0 != 0
6713 printf "\t"
6714 _dump_inpcbport $pcb0
6715 printf "\n"
6716 set $pcb0 = $pcb0->phd_hash.le_next
6717 end
6718 end
6719 set $i += 1
6720 set $hashbase += 1
6721 set $head = *(uintptr_t *)$hashbase
6722 end
2d21ac55
A
6723end
6724
b0d623f7 6725set $N_TIME_WAIT_SLOTS=128
2d21ac55 6726
b0d623f7
A
6727define show_tcp_timewaitslots
6728 set $slot = -1
6729 set $all = 0
6730 if $argc == 1
6731 if (int)$arg0 == -1
6732 set $all = 1
6733 else
6734 set $slot = (int)$arg0
6735 end
6736 end
6737 printf "time wait slot size %d cur_tw_slot %ld\n", $N_TIME_WAIT_SLOTS, cur_tw_slot
6738 set $i = 0
6739 while $i < $N_TIME_WAIT_SLOTS
6740 set $perslot = 0
6741 set $head = (uintptr_t *)time_wait_slots[$i]
6742 if $i == $slot || $slot == -1
6743 if $head != 0
6744 set $pcb0 = (struct inpcb *)$head
6745 while $pcb0 != 0
6746 set $perslot += 1
6747 set $pcb0 = $pcb0->inp_list.le_next
6748 end
6749 end
6750 printf " slot %ld count %ld\n", $i, $perslot
6751 end
6752 if $all || $i == $slot
6753 if $head != 0
6754 set $pcb0 = (struct inpcb *)$head
6755 while $pcb0 != 0
6756 printf "\t"
6757 _dump_inpcb $pcb0 $IPPROTO_TCP
6758 printf "\n"
6759 set $pcb0 = $pcb0->inp_list.le_next
6760 end
6761 end
6762 end
6763 set $i += 1
6764 end
2d21ac55 6765end
b0d623f7
A
6766document show_tcp_timewaitslots
6767Syntax: (gdb) show_tcp_timewaitslots
6768| Print the list of TCP protocol control block in the TIMEWAIT state
6769| Pass -1 to see the list of PCB for each slot
6770| Pass a slot number to see information for that slot with the list of PCB
2d21ac55
A
6771end
6772
b0d623f7
A
6773define show_tcp_pcbinfo
6774 _dump_pcbinfo &tcbinfo $IPPROTO_TCP
2d21ac55 6775end
b0d623f7
A
6776document show_tcp_pcbinfo
6777Syntax: (gdb) show_tcp_pcbinfo
6778| Print the list of TCP protocol control block information
2d21ac55
A
6779end
6780
6781
b0d623f7
A
6782define show_udp_pcbinfo
6783 _dump_pcbinfo &udbinfo $IPPROTO_UDP
2d21ac55 6784end
b0d623f7
A
6785document show_udp_pcbinfo
6786Syntax: (gdb) show_udp_pcbinfo
6787| Print the list of UDP protocol control block information
2d21ac55
A
6788end
6789
b0d623f7
A
6790define showbpfdtab
6791 set $myi = 0
6792 while ($myi < bpf_dtab_size)
6793 if (bpf_dtab[$myi] != 0)
6794 printf "Address 0x%x, bd_next 0x%x\n", bpf_dtab[$myi], bpf_dtab[$myi]->bd_next
6795 print *bpf_dtab[$myi]
6796 end
6797 set $myi = $myi + 1
2d21ac55
A
6798 end
6799end
6800
b0d623f7
A
6801define printvnodepathint_recur
6802 if $arg0 != 0
6803 if ($arg0->v_flag & 0x000001) && ($arg0->v_mount != 0)
6804 if $arg0->v_mount->mnt_vnodecovered != 0
6805 printvnodepathint_recur $arg0->v_mount->mnt_vnodecovered $arg0->v_mount->mnt_vnodecovered->v_name
6806 end
6807 else
6808 printvnodepathint_recur $arg0->v_parent $arg0->v_parent->v_name
6809 printf "/%s", $arg1
6810 end
6811 end
6812end
6813
6814define showvnodepath
6815 set $vp = (struct vnode *)$arg0
6816 if $vp != 0
6817 if ($vp->v_flag & 0x000001) && ($vp->v_mount != 0) && ($vp->v_mount->mnt_flag & 0x00004000)
6818 printf "/"
6819 else
6820 printvnodepathint_recur $vp $vp->v_name
6821 end
6822 end
6823 printf "\n"
6824end
6825
6826document showvnodepath
6827Syntax: (gdb) showvnodepath <vnode>
6828| Prints the path for a vnode
6829end
6830
6831define showallvols
6832 printf "volume "
6833 showptrhdrpad
6834 printf " mnt_data "
6835 showptrhdrpad
6836 printf " mnt_devvp "
6837 showptrhdrpad
6838 printf " typename mountpoint\n"
6839 set $kgm_vol = (mount_t) mountlist.tqh_first
6840 while $kgm_vol
6841 showptr $kgm_vol
6842 printf " "
6843 showptr $kgm_vol->mnt_data
6844 printf " "
6845 showptr $kgm_vol->mnt_devvp
6846 printf " "
6847 if ($kgm_vol->mnt_vtable->vfc_name[0] == 'h') && \
6848 ($kgm_vol->mnt_vtable->vfc_name[1] == 'f') && \
6849 ($kgm_vol->mnt_vtable->vfc_name[2] == 's') && \
6850 ($kgm_vol->mnt_vtable->vfc_name[3] == '\0')
6851 set $kgm_hfsmount = \
6852 (struct hfsmount *) $kgm_vol->mnt_data
6853 if $kgm_hfsmount->hfs_freezing_proc != 0
6854 printf "FROZEN hfs "
6855 else
6856 printf "hfs "
6857 end
6858 else
6859 printf "%-10s ", $kgm_vol->mnt_vtable->vfc_name
6860 end
6861 printf "%s\n", $kgm_vol->mnt_vfsstat.f_mntonname
6862
6863 set $kgm_vol = (mount_t) $kgm_vol->mnt_list.tqe_next
6864 end
6865end
6866
6867document showallvols
6868Syntax: (gdb) showallvols
6869| Display a summary of mounted volumes
6870end
6871
6872define showvnodeheader
6873 printf "vnode "
6874 showptrhdrpad
6875 printf " usecount iocount v_data "
6876 showptrhdrpad
6877 printf " vtype parent "
6878 showptrhdrpad
6879 printf " name\n"
6880end
6881
6882define showvnodeint
6883 set $kgm_vnode = (vnode_t) $arg0
6884 showptr $kgm_vnode
6885 printf " %8d ", $kgm_vnode->v_usecount
6886 printf "%7d ", $kgm_vnode->v_iocount
6887# print information about clean/dirty blocks?
6888 showptr $kgm_vnode->v_data
6889 printf " "
6890 # print the vtype, using the enum tag
6891 set $kgm_vtype = $kgm_vnode->v_type
6892 if $kgm_vtype == VNON
6893 printf "VNON "
6894 end
6895 if $kgm_vtype == VREG
6896 printf "VREG "
6897 end
6898 if $kgm_vtype == VDIR
6899 printf "VDIR "
6900 end
6901 if $kgm_vtype == VBLK
6902 printf "VBLK "
6903 end
6904 if $kgm_vtype == VCHR
6905 printf "VCHR "
6906 end
6907 if $kgm_vtype == VLNK
6908 printf "VLNK "
6909 end
6910 if $kgm_vtype == VSOCK
6911 printf "VSOCK "
6912 end
6913 if $kgm_vtype == VFIFO
6914 printf "VFIFO "
6915 end
6916 if $kgm_vtype == VBAD
6917 printf "VBAD "
6918 end
6919 if ($kgm_vtype < VNON) || ($kgm_vtype > VBAD)
6920 printf "%5d ", $kgm_vtype
6921 end
6922
6923 showptr $kgm_vnode->v_parent
6924 printf " "
6925 if $kgm_vnode->v_name != 0
6926 printf "%s\n", $kgm_vnode->v_name
6927 else
6928 printf "\n"
6929 end
6930end
6931
6932define showvnode
6933 showvnodeheader
6934 showvnodeint $arg0
6935end
6936
6937document showvnode
6938Syntax: (gdb) showvnode <vnode>
6939| Display info about one vnode
6940end
6941
6942define showvolvnodes
6943 showvnodeheader
6944 set $kgm_vol = (mount_t) $arg0
6945 set $kgm_vnode = (vnode_t) $kgm_vol.mnt_vnodelist.tqh_first
6946 while $kgm_vnode
6947 showvnodeint $kgm_vnode
6948 set $kgm_vnode = (vnode_t) $kgm_vnode->v_mntvnodes.tqe_next
6949 end
6950end
6951
6952document showvolvnodes
6953Syntax: (gdb) showvolvnodes <mouont_t>
6954| Display info about all vnodes of a given mount_t
6955end
6956
6957define showvolbusyvnodes
6958 showvnodeheader
6959 set $kgm_vol = (mount_t) $arg0
6960 set $kgm_vnode = (vnode_t) $kgm_vol.mnt_vnodelist.tqh_first
6961 while $kgm_vnode
6962 if $kgm_vnode->v_iocount != 0
6963 showvnodeint $kgm_vnode
6964 end
6965 set $kgm_vnode = (vnode_t) $kgm_vnode->v_mntvnodes.tqe_next
6966 end
6967end
6968
6969document showvolbusyvnodes
6970Syntax: (gdb) showvolbusyvnodes <mount_t>
6971| Display info about busy (iocount!=0) vnodes of a given mount_t
6972end
6973
6974define showallbusyvnodes
6975 showvnodeheader
6976 set $kgm_vol = (mount_t) mountlist.tqh_first
6977 while $kgm_vol
6978 set $kgm_vnode = (vnode_t) $kgm_vol.mnt_vnodelist.tqh_first
6979 while $kgm_vnode
6980 if $kgm_vnode->v_iocount != 0
6981 showvnodeint $kgm_vnode
6982 end
6983 set $kgm_vnode = (vnode_t) $kgm_vnode->v_mntvnodes.tqe_next
6984 end
6985 set $kgm_vol = (mount_t) $kgm_vol->mnt_list.tqe_next
6986 end
6987end
6988
6989document showallbusyvnodes
6990Syntax: (gdb) showallbusyvnodes <vnode>
6991| Display info about all busy (iocount!=0) vnodes
6992end
6993
6994define showallvnodes
6995 showvnodeheader
6996 set $kgm_vol = (mount_t) mountlist.tqh_first
6997 while $kgm_vol
6998 set $kgm_vnode = (vnode_t) $kgm_vol.mnt_vnodelist.tqh_first
6999 while $kgm_vnode
7000 showvnodeint $kgm_vnode
7001 set $kgm_vnode = (vnode_t) $kgm_vnode->v_mntvnodes.tqe_next
7002 end
7003 set $kgm_vol = (mount_t) $kgm_vol->mnt_list.tqe_next
7004 end
7005end
7006
7007document showallvnodes
7008Syntax: (gdb) showallvnodes
7009| Display info about all vnodes
7010end
7011
7012define _showvnodelockheader
7013 printf "* type W held by lock type start end\n"
7014 printf "- ----- - ------------- --------- ------------------ ------------------\n"
7015end
7016
7017define _showvnodelock
7018 set $kgm_svl_lock = ((struct lockf *)$arg0)
7019
7020 # decode flags
7021 set $kgm_svl_flags = $kgm_svl_lock->lf_flags
7022 set $kgm_svl_type = $kgm_svl_lock->lf_type
7023 if ($kgm_svl_flags & 0x20)
7024 printf "flock"
7025 end
7026 if ($kgm_svl_flags & 0x40)
7027 printf "posix"
7028 end
7029 if ($kgm_svl_flags & 0x80)
7030 printf "prov "
7031 end
7032 if ($kgm_svl_flags & 0x10)
7033 printf " W "
7034 else
7035 printf " . "
7036 end
7037
7038 # POSIX file vs. advisory range locks
7039 if ($kgm_svl_flags & 0x40)
7040 set $kgm_svl_proc = (proc_t)$kgm_svl_lock->lf_id
7041 printf "PID %8d ", $kgm_svl_proc->p_pid
7042 else
7043 printf "ID 0x%08x ", $kgm_svl_lock->lf_id
7044 end
7045
7046 # lock type
7047 if ($kgm_svl_type == 1)
7048 printf "shared "
7049 else
7050 if ($kgm_svl_type == 3)
7051 printf "exclusive "
7052 else
7053 if ($kgm_svl_type == 2)
7054 printf "unlock "
7055 else
7056 printf "unknown "
7057 end
7058 end
7059 end
7060
7061 # start and stop
7062 printf "0x%016x..", $kgm_svl_lock->lf_start
7063 printf "0x%016x ", $kgm_svl_lock->lf_end
7064 printf "\n"
7065end
7066# Body of showvnodelocks, not including header
7067define _showvnodelocks
7068 set $kgm_svl_vnode = ((vnode_t)$arg0)
7069 set $kgm_svl_lockiter = $kgm_svl_vnode->v_lockf
7070 while ($kgm_svl_lockiter != 0)
7071 # locks that are held
7072 printf "H "
7073 _showvnodelock $kgm_svl_lockiter
7074
7075 # and any locks blocked by them
7076 set $kgm_svl_blocker = $kgm_svl_lockiter->lf_blkhd.tqh_first
7077 while ($kgm_svl_blocker != 0)
7078 printf "> "
7079 _showvnodelock $kgm_svl_blocker
7080 set $kgm_svl_blocker = $kgm_svl_blocker->lf_block.tqe_next
7081 end
7082
7083 # and on to the next one...
7084 set $kgm_svl_lockiter = $kgm_svl_lockiter->lf_next
7085 end
7086end
7087
7088
7089define showvnodelocks
7090 if ($argc == 1)
7091 _showvnodelockheader
7092 _showvnodelocks $arg0
7093 else
7094 printf "| Usage:\n|\n"
7095 help showvnodelocks
7096 end
7097end
7098
7099document showvnodelocks
7100Syntax: (gdb) showvnodelocks <vnode_t>
7101| Given a vnodet pointer, display the list of advisory record locks for the
7102| referenced pvnodes
7103end
7104
7105define showbootargs
7106 printf "%s\n", (char*)((boot_args*)PE_state.bootArgs).CommandLine
7107end
7108
7109document showbootargs
7110Syntax: showbootargs
7111| Display boot arguments passed to the target kernel
7112end
7113
7114define showbootermemorymap
7115 if ($kgm_mtype == $kgm_mtype_i386)
7116 set $kgm_voffset = 0
7117 else
7118 if ($kgm_mtype == $kgm_mtype_x86_64)
7119 set $kgm_voffset = 0xFFFFFF8000000000ULL
7120 else
7121 echo showbootermemorymap not supported on this architecture
7122 end
7123 end
7124
7125 set $kgm_boot_args = kernelBootArgs
7126 set $kgm_msize = kernelBootArgs->MemoryMapDescriptorSize
7127 set $kgm_mcount = kernelBootArgs->MemoryMapSize / $kgm_msize
7128 set $kgm_i = 0
7129
7130 printf "Type Physical Start Number of Pages Virtual Start Attributes\n"
7131 while $kgm_i < $kgm_mcount
7132 set $kgm_mptr = (EfiMemoryRange *)((unsigned long)kernelBootArgs->MemoryMap + $kgm_voffset + $kgm_i * $kgm_msize)
7133# p/x *$kgm_mptr
7134 if $kgm_mptr->Type == 0
060df5ea 7135 printf "Reserved "
b0d623f7
A
7136 end
7137 if $kgm_mptr->Type == 1
7138 printf "LoaderCode"
7139 end
7140 if $kgm_mptr->Type == 2
7141 printf "LoaderData"
7142 end
7143 if $kgm_mptr->Type == 3
7144 printf "BS_code "
7145 end
7146 if $kgm_mptr->Type == 4
7147 printf "BS_data "
7148 end
7149 if $kgm_mptr->Type == 5
7150 printf "RT_code "
7151 end
7152 if $kgm_mptr->Type == 6
7153 printf "RT_data "
7154 end
7155 if $kgm_mptr->Type == 7
060df5ea 7156 printf "Convention"
b0d623f7
A
7157 end
7158 if $kgm_mptr->Type == 8
7159 printf "Unusable "
7160 end
7161 if $kgm_mptr->Type == 9
7162 printf "ACPI_recl "
7163 end
7164 if $kgm_mptr->Type == 10
7165 printf "ACPI_NVS "
7166 end
7167 if $kgm_mptr->Type == 11
7168 printf "MemMapIO "
7169 end
7170 if $kgm_mptr->Type == 12
7171 printf "MemPortIO "
7172 end
7173 if $kgm_mptr->Type == 13
7174 printf "PAL_code "
7175 end
7176 if $kgm_mptr->Type > 13
7177 printf "UNKNOWN "
7178 end
7179
7180 printf " %016llx %016llx", $kgm_mptr->PhysicalStart, $kgm_mptr->NumberOfPages
7181 if $kgm_mptr->VirtualStart != 0
7182 printf " %016llx", $kgm_mptr->VirtualStart
7183 else
7184 printf " "
7185 end
7186 printf " %016llx\n", $kgm_mptr->Attribute
7187 set $kgm_i = $kgm_i + 1
7188 end
7189end
7190
7191document showbootermemorymap
7192Syntax: (gdb) showbootermemorymap
7193| Prints out the phys memory map from kernelBootArgs
7194end
7195
7196
7197define showstacksaftertask
7198 set $kgm_head_taskp = &default_pset.tasks
7199 set $kgm_taskp = (struct task *)$arg0
7200 while $kgm_taskp != $kgm_head_taskp
7201 showtaskheader
7202 showtaskint $kgm_taskp
7203 set $kgm_head_actp = &($kgm_taskp->threads)
7204 set $kgm_actp = (struct thread *)($kgm_taskp->threads.next)
7205 while $kgm_actp != $kgm_head_actp
7206 showactheader
7207 if ($decode_wait_events > 0)
7208 showactint $kgm_actp 1
7209 else
7210 showactint $kgm_actp 2
7211 end
7212 set $kgm_actp = (struct thread *)($kgm_actp->task_threads.next)
7213 end
7214 printf "\n"
7215 set $kgm_taskp = (struct task *)($kgm_taskp->pset_tasks.next)
7216 end
7217end
7218document showstacksaftertask
7219Syntax: (gdb) showstacksaftertask <task>
7220| Routine to print out all stacks (as in showallstacks) starting after a given task
7221| Useful if that gdb refuses to print a certain task's stack.
7222end
7223
7224define showpmworkqueueint
7225 set $kgm_pm_wq = (IOPMWorkQueue *)$arg0
7226 set $kgm_pm_node = (IOService *)$kgm_pm_wq->owner
7227 showptr $kgm_pm_wq
7228 printf " "
7229 showptr $kgm_pm_node
7230 printf " "
7231 printf "%02d ", $kgm_pm_node->pwrMgt->CurrentPowerState
7232 printf "%02d ", $kgm_pm_node->pwrMgt->MachineState
7233 printf "%02d ", $kgm_pm_node->pwrMgt->WaitReason
7234 printf "%s\n", $kgm_pm_node->pwrMgt->Name
7235 set $kgm_pm_queue = &($kgm_pm_wq->fWorkQueue)
7236 set $kgm_pm_req = (IOPMRequest *)$kgm_pm_queue->next
7237 if ((queue_entry_t) $kgm_pm_req != (queue_entry_t) $kgm_pm_queue)
7238 printf "\n"
7239 printf "request "
7240 showptrhdrpad
7241 printf " type next "
7242 showptrhdrpad
7243 printf " root "
7244 showptrhdrpad
7245 printf " work_wait free_wait\n"
7246 while ((queue_entry_t) $kgm_pm_req != (queue_entry_t) $kgm_pm_queue)
7247 showptr $kgm_pm_req
7248 printf " 0x%02x ", $kgm_pm_req->fType
7249 showptr $kgm_pm_req->fRequestNext
7250 printf " "
7251 showptr $kgm_pm_req->fRequestRoot
7252 printf " 0x%08x 0x%08x\n", $kgm_pm_req->fWorkWaitCount, $kgm_pm_req->fFreeWaitCount
7253 showptrhdrpad
7254 printf " args "
7255 showptr $kgm_pm_req->fArg0
7256 printf " "
7257 showptr $kgm_pm_req->fArg1
7258 printf " "
7259 showptr $kgm_pm_req->fArg2
7260 printf "\n"
7261 set $kgm_pm_req = (IOPMRequest *)$kgm_pm_req->fCommandChain.next
7262 end
7263 printf "\n"
7264 end
7265end
7266
7267define showallpmworkqueues
7268 set $kgm_pm_next = gIOPMWorkLoop->eventChain
7269 printf "queue "
7270 showptrhdrpad
7271 printf " owner "
7272 showptrhdrpad
7273 printf " ps ms wr name\n"
7274 while ( $kgm_pm_next )
7275 set $kgm_vt = *((void **) $kgm_pm_next)
7276 if ($kgm_lp64 || $kgm_mtype == $kgm_mtype_arm)
7277 set $kgm_vt = $kgm_vt - 2 * sizeof(void *)
7278 end
7279 if ($kgm_vt == &_ZTV13IOPMWorkQueue)
7280 showpmworkqueueint $kgm_pm_next
7281 end
7282 set $kgm_pm_next = $kgm_pm_next->eventChainNext
7283 end
7284end
7285
7286document showallpmworkqueues
7287Syntax: (gdb) showallpmworkqueues
7288| Display info about all IOPMWorkQueue objects
7289end
7290
7291define showioservicepm
7292 set $kgm_iopmpriv = (IOServicePM *)$arg0
7293 printf "{ "
7294 printf "MachineState = %d (", $kgm_iopmpriv->MachineState
7295 if ( $kgm_iopmpriv->MachineState == 1 )
7296 printf "kIOPM_OurChangeTellClientsPowerDown"
7297 else
7298 if ( $kgm_iopmpriv->MachineState == 2 )
7299 printf "kIOPM_OurChangeTellPriorityClientsPowerDown"
7300 else
7301 if ( $kgm_iopmpriv->MachineState == 3 )
7302 printf "kIOPM_OurChangeNotifyInterestedDriversWillChange"
7303 else
7304 if ( $kgm_iopmpriv->MachineState == 4 )
7305 printf "kIOPM_OurChangeSetPowerState"
7306 else
7307 if ( $kgm_iopmpriv->MachineState == 5 )
7308 printf "kIOPM_OurChangeWaitForPowerSettle"
7309 else
7310 if ( $kgm_iopmpriv->MachineState == 6 )
7311 printf "kIOPM_OurChangeNotifyInterestedDriversDidChange"
7312 else
7313 if ( $kgm_iopmpriv->MachineState == 7 )
7314 printf "kIOPM_OurChangeFinish"
7315 else
7316 if ( $kgm_iopmpriv->MachineState == 8 )
7317 printf "kIOPM_ParentDownTellPriorityClientsPowerDown"
7318 else
7319 if ( $kgm_iopmpriv->MachineState == 9 )
7320 printf "kIOPM_ParentDownNotifyInterestedDriversWillChange"
7321 else
7322 if ( $kgm_iopmpriv->MachineState == 10 )
7323 printf "Unused_MachineState_10"
7324 else
7325 if ( $kgm_iopmpriv->MachineState == 11 )
7326 printf "kIOPM_ParentDownNotifyDidChangeAndAcknowledgeChange"
7327 else
7328 if ( $kgm_iopmpriv->MachineState == 12 )
7329 printf "kIOPM_ParentDownSetPowerState"
7330 else
7331 if ( $kgm_iopmpriv->MachineState == 13 )
7332 printf "kIOPM_ParentDownWaitForPowerSettle"
7333 else
7334 if ( $kgm_iopmpriv->MachineState == 14 )
7335 printf "kIOPM_ParentDownAcknowledgeChange"
7336 else
7337 if ( $kgm_iopmpriv->MachineState == 15)
7338 printf "kIOPM_ParentUpSetPowerState"
7339 else
7340 if ( $kgm_iopmpriv->MachineState == 16)
7341 printf "Unused_MachineState_16"
7342 else
7343 if ( $kgm_iopmpriv->MachineState == 17)
7344 printf "kIOPM_ParentUpWaitForSettleTime"
7345 else
7346 if ( $kgm_iopmpriv->MachineState == 18)
7347 printf "kIOPM_ParentUpNotifyInterestedDriversDidChange"
7348 else
7349 if ( $kgm_iopmpriv->MachineState == 19)
7350 printf "kIOPM_ParentUpAcknowledgePowerChange"
7351 else
7352 if ( $kgm_iopmpriv->MachineState == 20)
7353 printf "kIOPM_Finished"
7354 else
7355 if ( $kgm_iopmpriv->MachineState == 21)
7356 printf "kIOPM_DriverThreadCallDone"
7357 else
7358 if ( $kgm_iopmpriv->MachineState == 22)
7359 printf "kIOPM_NotifyChildrenDone"
7360 end
7361 end
7362 end
7363 end
7364 end
7365 end
7366 end
7367 end
7368 end
7369 end
7370 end
7371 end
7372 end
7373 end
7374 end
7375 end
7376 end
7377 end
7378 end
7379 end
7380 end
7381 end
7382 printf "), "
7383
7384 if ( $kgm_iopmpriv->MachineState != 20 )
7385 printf "DriverTimer = %d, ",(unsigned int)$kgm_iopmpriv->DriverTimer
7386 printf "SettleTime = %d, ",(unsigned int)$kgm_iopmpriv->SettleTimeUS
7387 printf "HeadNoteFlags = %08x, ",(unsigned int)$kgm_iopmpriv->HeadNoteFlags
7388 printf "HeadNotePendingAcks = %x, ",(unsigned int)$kgm_iopmpriv->HeadNotePendingAcks
7389 end
7390
7391 if ( $kgm_iopmpriv->DeviceOverrides != 0 )
7392 printf"DeviceOverrides, "
7393 end
7394
7395 printf "DeviceDesire = %d, ",(unsigned int)$kgm_iopmpriv->DeviceDesire
7396 printf "DesiredPowerState = %d, ",(unsigned int)$kgm_iopmpriv->DesiredPowerState
7397 printf "PreviousRequest = %d }\n",(unsigned int)$kgm_iopmpriv->PreviousRequest
7398end
7399
7400document showioservicepm
7401Syntax: (gdb) showioservicepm <IOServicePM pointer>
7402| Routine to dump the IOServicePM object
7403end
7404
7405define showregistryentryrecursepmstate
7406 set $kgm_re = (IOService *)$arg1
7407 set $kgm$arg0_stack = (unsigned long long) $arg2
7408
7409 if ($arg3)
7410 set $kgm$arg0_stack = $kgm$arg0_stack | (1ULL << $kgm_reg_depth)
7411 else
7412 set $kgm$arg0_stack = $kgm$arg0_stack & ~(1ULL << $kgm_reg_depth)
7413 end
7414
7415 dictget $kgm_re->fRegistryTable $kgm_childkey
7416 set $kgm$arg0_child_array = (OSArray *) $kgm_result
7417
7418 if ($kgm$arg0_child_array)
7419 set $kgm$arg0_child_count = $kgm$arg0_child_array->count
7420 else
7421 set $kgm$arg0_child_count = 0
7422 end
7423
7424 if ($kgm$arg0_child_count)
7425 set $kgm$arg0_stack = $kgm$arg0_stack | (2ULL << $kgm_reg_depth)
7426 else
7427 set $kgm$arg0_stack = $kgm$arg0_stack & ~(2ULL << $kgm_reg_depth)
7428 end
7429
7430 indent $kgm_reg_depth $kgm$arg0_stack
7431 printf "+-o "
7432
7433 dictget $kgm_re->fRegistryTable $kgm_namekey
7434 if ($kgm_result == 0)
7435 dictget $kgm_re->fRegistryTable gIONameKey
7436 end
7437 if ($kgm_result == 0)
7438 dictget $kgm_re->fPropertyTable gIOClassKey
7439 end
7440
7441 if ($kgm_result != 0)
7442 printf "%s <%p>", ((OSString *)$kgm_result)->string, $kgm_re
7443 else
7444 if (((IOService*)$kgm_re)->pwrMgt && ((IOService*)$kgm_re)->pwrMgt->Name)
7445 printf "%s <", ((IOService*)$kgm_re)->pwrMgt->Name
7446 showptr $kgm_re
7447 printf ">"
7448 else
7449 printf "?? <"
7450 showptr $kgm_re
7451 printf ">"
7452 end
7453 end
7454
7455 if (((IOService*)$kgm_re)->pwrMgt )
7456 printf " Current Power State: %ld ", ((IOService*)$kgm_re)->pwrMgt->CurrentPowerState
7457 #printf " Mach State %ld", ((IOService*)$kgm_re)->pwrMgt->MachineState
7458 showioservicepm ((IOService*)$kgm_re)->pwrMgt
7459 end
7460 printf "\n"
7461
7462
7463 # recurse
7464 if ($kgm$arg0_child_count != 0)
7465
7466 set $kgm_reg_depth = $kgm_reg_depth + 1
7467 set $kgm$arg0_child_idx = 0
7468
7469 while ($kgm$arg0_child_idx < $kgm$arg0_child_count)
7470 set $kgm_re = $kgm$arg0_child_array->array[$kgm$arg0_child_idx++]
7471 set $kgm_more_sib = ($kgm$arg0_child_idx < $kgm$arg0_child_count)
7472 if $kgm_reg_depth >= $kgm_reg_depth_max + 1
7473 loop_break
7474 end
7475 showregistryentryrecursepmstate _$arg0 $kgm_re $kgm$arg0_stack $kgm_more_sib
7476 end
7477
7478 set $kgm_reg_depth = $kgm_reg_depth - 1
7479 end
7480end
7481
7482define showregistryentryintpmstate
7e4a7d39
A
7483 if !$kgm_reg_plane
7484 set $kgm_reg_plane = (IORegistryPlane *) gIOServicePlane
7485 end
7486
7487 if !$kgm_reg_plane
7488 printf "Please load kgmacros after KDP attaching to the target.\n"
7489 else
7490 set $kgm_namekey = (OSSymbol *) $kgm_reg_plane->nameKey
7491 set $kgm_childkey = (OSSymbol *) $kgm_reg_plane->keys[1]
7492 showregistryentryrecursepmstate _ $arg0 0 0
7493 end
b0d623f7
A
7494end
7495
7496define showregistrypmstate
7497# setregistryplane gIOPowerPlane
7498 set $kgm_reg_depth = 0
7499 set $kgm_show_props = 1
7500 showregistryentryintpmstate gRegistryRoot
7501end
7502
7503document showregistrypmstate
7504Syntax: (gdb) showregistrypmstate
7505| Routine to dump the PM state of each IOPower registry entry
7506end
7507
7508define showstacksafterthread
7509 set $kgm_head_taskp = &default_pset.tasks
7510 set $kgm_actp = (struct thread *)$arg0
7511 set $kgm_actp = (struct thread *)($kgm_actp->task_threads.next)
7512 set $kgm_taskp = (struct task *)$kgm_actp->task
7513 while $kgm_taskp != $kgm_head_taskp
7514 showtaskheader
7515 showtaskint $kgm_taskp
7516 set $kgm_head_actp = &($kgm_taskp->threads)
7517 while $kgm_actp != $kgm_head_actp
7518 showactheader
7519 if ($decode_wait_events > 0)
7520 showactint $kgm_actp 1
7521 else
7522 showactint $kgm_actp 2
7523 end
7524 set $kgm_actp = (struct thread *)($kgm_actp->task_threads.next)
7525 end
7526 printf "\n"
7527 set $kgm_taskp = (struct task *)($kgm_taskp->pset_tasks.next)
7528 end
7529end
7530
7531document showstacksafterthread
7532Syntax: (gdb) showstacksafterthread <thread>
7533| Routine to print out all stacks (as in showallstacks) starting after a given thread
7534| Useful if that gdb refuses to print a certain task's stack.
7535end
7536
7537define kdp-reenter
7538 set kdp_reentry_deadline = ((unsigned) $arg0)*1000
7539 continue
7540end
7541
7542document kdp-reenter
7543Syntax: (gdb) kdp-reenter <seconds>
7544| Schedules reentry into the debugger after <seconds> seconds, and resumes
7545| the target system.
7546end
7547
7548define _if_present
7549 if (!$arg0)
7550 printf " not"
7551 end
7552 printf " present"
7553end
7554
7555define showMCAstate
7556 if (($kgm_mtype & $kgm_mtype_x86_mask) != $kgm_mtype_x86_any)
7557 printf "Not available for current architecture.\n"
7558 else
7559 printf "MCA"
7560 _if_present mca_MCA_present
7561 printf ", control MSR"
7562 _if_present mca_control_MSR_present
7563 printf ", threshold status"
7564 _if_present mca_threshold_status_present
7565 printf "\n%d error banks, ", mca_error_bank_count
7566 printf "family code 0x%x, ", mca_family
7567 printf "machine-check dump state: %d\n", mca_dump_state
7568 set $kgm_cpu = 0
7569 while cpu_data_ptr[$kgm_cpu] != 0
7570 set $kgm_mcp = cpu_data_ptr[$kgm_cpu]->cpu_mca_state
7571 if $kgm_mcp
7572 printf "CPU %d:", $kgm_cpu
7573 printf " mca_mcg_ctl: 0x%016llx", $kgm_mcp->mca_mcg_ctl
7574 printf " mca_mcg_status: 0x%016llx\n", $kgm_mcp->mca_mcg_status.u64
7575 printf "bank "
7576 printf "mca_mci_ctl "
7577 printf "mca_mci_status "
7578 printf "mca_mci_addr "
7579 printf "mca_mci_misc\n"
7580 set $kgm_bank = 0
7581 while $kgm_bank < mca_error_bank_count
7582 set $kgm_bp = &$kgm_mcp->mca_error_bank[$kgm_bank]
7583 printf " %2d:", $kgm_bank
7584 printf " 0x%016llx", $kgm_bp->mca_mci_ctl
7585 printf " 0x%016llx", $kgm_bp->mca_mci_status.u64
7586 printf " 0x%016llx", $kgm_bp->mca_mci_addr
7587 printf " 0x%016llx\n", $kgm_bp->mca_mci_misc
7588 set $kgm_bank = $kgm_bank + 1
7589 end
7590 end
7591 set $kgm_cpu = $kgm_cpu + 1
7592 end
7593 end
7594end
7595
7596document showMCAstate
7597Syntax: showMCAstate
7598| Print machine-check register state after MC exception.
7599end
7600
7601define _pt_step
7602 #
7603 # Step to lower-level page table and print attributes
7604 # $kgm_pt_paddr: current page table entry physical address
7605 # $kgm_pt_index: current page table entry index (0..511)
7606 # returns
7607 # $kgm_pt_paddr: next level page table entry physical address
7608 # or null if invalid
7609 # $kgm_pt_valid: 1 if $kgm_pt_paddr is valid, 0 if the walk
7610 # should be aborted
7611 # $kgm_pt_large: 1 if kgm_pt_paddr is a page frame address
7612 # of a large page and not another page table entry
7613 # For $kgm_pt_verbose = 0: print nothing
7614 # 1: print basic information
7615 # 2: print basic information and hex table dump
7616 #
7617 set $kgm_entryp = $kgm_pt_paddr + 8*$kgm_pt_index
7618 readphysint $kgm_entryp 64 $kgm_lcpu_self
7619 set $entry = $kgm_readphysint_result
7620 if $kgm_pt_verbose == 2
7621 set $kgm_pte_loop = 0
7622 while $kgm_pte_loop < 512
7623 set $kgm_pt_paddr_tmp = $kgm_pt_paddr + $kgm_pte_loop*8
7624 readphys64 $kgm_pt_paddr_tmp
7625 set $kgm_pte_loop = $kgm_pte_loop + 1
7626 end
7627 end
7628 set $kgm_paddr_mask = ~((0xfffULL<<52) | 0xfffULL)
7629 set $kgm_paddr_largemask = ~((0xfffULL<<52) | 0x1fffffULL)
7630 if $kgm_pt_verbose == 0
7631 if $entry & (0x1 << 0)
7632 set $kgm_pt_valid = 1
7633 if $entry & (0x1 << 7)
7634 set $kgm_pt_large = 1
7635 set $kgm_pt_paddr = $entry & $kgm_paddr_largemask
7636 else
7637 set $kgm_pt_large = 0
7638 set $kgm_pt_paddr = $entry & $kgm_paddr_mask
7639 end
7640 else
7641 set $kgm_pt_valid = 0
7642 set $kgm_pt_large = 0
7643 set $kgm_pt_paddr = 0
7644 end
7645 else
7646 printf "0x%016llx:\n\t0x%016llx\n\t", $kgm_entryp, $entry
7647 if $entry & (0x1 << 0)
7648 printf "valid"
7649 set $kgm_pt_paddr = $entry & $kgm_paddr_mask
7650 set $kgm_pt_valid = 1
7651 else
7652 printf "invalid"
7653 set $kgm_pt_paddr = 0
7654 set $kgm_pt_valid = 0
7655 # stop decoding other bits
7656 set $entry = 0
7657 end
7658 if $entry & (0x1 << 1)
7659 printf " writeable"
7660 else
7661 printf " read-only"
7662 end
7663 if $entry & (0x1 << 2)
7664 printf " user"
7665 else
7666 printf " supervisor"
7667 end
7668 if $entry & (0x1 << 3)
7669 printf " PWT"
7670 end
7671 if $entry & (0x1 << 4)
7672 printf " PCD"
7673 end
7674 if $entry & (0x1 << 5)
7675 printf " accessed"
7676 end
7677 if $entry & (0x1 << 6)
7678 printf " dirty"
7679 end
7680 if $entry & (0x1 << 7)
7681 printf " large"
7682 set $kgm_pt_large = 1
7683 else
7684 set $kgm_pt_large = 0
7685 end
7686 if $entry & (0x1 << 8)
7687 printf " global"
7688 end
7689 if $entry & (0x3 << 9)
7690 printf " avail:0x%x", ($entry >> 9) & 0x3
7691 end
7692 if $entry & (0x1 << 63)
7693 printf " noexec"
7694 end
7695 printf "\n"
7696 end
7697end
7698
7699define _pmap_walk
7700 set $kgm_pmap = (pmap_t) $arg0
7701 set $kgm_vaddr = $arg1
7702 set $kgm_pt_paddr = $kgm_pmap->pm_cr3
7703 set $kgm_pt_valid = $kgm_pt_paddr != 0
7704 set $kgm_pt_large = 0
7705 set $kgm_pframe_offset = 0
7706 if $kgm_pt_valid && cpu_64bit
7707 # Look up bits 47:39 of the linear address in PML4T
7708 set $kgm_pt_index = ($kgm_vaddr >> 39) & 0x1ffULL
7709 set $kgm_pframe_offset = $kgm_vaddr & 0x7fffffffffULL
7710 if $kgm_pt_verbose
7711 printf "pml4 (index %d):\n", $kgm_pt_index
7712 end
7713 _pt_step
7714 end
7715 if $kgm_pt_valid
7716 # Look up bits 38:30 of the linear address in PDPT
7717 set $kgm_pt_index = ($kgm_vaddr >> 30) & 0x1ffULL
7718 set $kgm_pframe_offset = $kgm_vaddr & 0x3fffffffULL
7719 if $kgm_pt_verbose
7720 printf "pdpt (index %d):\n", $kgm_pt_index
7721 end
7722 _pt_step
7723 end
7724 if $kgm_pt_valid && !$kgm_pt_large
7725 # Look up bits 29:21 of the linear address in PDT
7726 set $kgm_pt_index = ($kgm_vaddr >> 21) & 0x1ffULL
7727 set $kgm_pframe_offset = $kgm_vaddr & 0x1fffffULL
7728 if $kgm_pt_verbose
7729 printf "pdt (index %d):\n", $kgm_pt_index
7730 end
7731 _pt_step
7732 end
7733 if $kgm_pt_valid && !$kgm_pt_large
7734 # Look up bits 20:21 of the linear address in PT
7735 set $kgm_pt_index = ($kgm_vaddr >> 12) & 0x1ffULL
7736 set $kgm_pframe_offset = $kgm_vaddr & 0xfffULL
7737 if $kgm_pt_verbose
7738 printf "pt (index %d):\n", $kgm_pt_index
7739 end
7740 _pt_step
7741 end
7742 if $kgm_pt_valid
7743 set $kgm_paddr = $kgm_pt_paddr + $kgm_pframe_offset
7744 readphysint $kgm_paddr 32 $kgm_lcpu_self
7745 set $kgm_value = $kgm_readphysint_result
7746 printf "phys 0x%016llx: 0x%08x\n", $kgm_paddr, $kgm_value
7747 else
7748 set $kgm_paddr = 0
7749 printf "(no translation)\n"
7750 end
7751end
7752
7753define pmap_walk
7754 if (($kgm_mtype & $kgm_mtype_x86_mask) != $kgm_mtype_x86_any)
7755 printf "Not available for current architecture.\n"
7756 else
7757 if $argc != 2
7758 printf "pmap_walk <pmap> <vaddr>\n"
7759 else
7760 if !$kgm_pt_verbose
7761 set $kgm_pt_verbose = 1
7762 else
7763 if $kgm_pt_verbose != 2
7764 set $kgm_pt_verbose = 1
7765 end
7766 end
7767 _pmap_walk $arg0 $arg1
7768 end
7769 end
7770end
7771
7772document pmap_walk
7773Syntax: (gdb) pmap_walk <pmap> <virtual_address>
7774| Perform a page-table walk in <pmap> for <virtual_address>.
7775| Set $kgm_pt_verbose=2 for full hex dump of page tables.
7776end
7777
7778define pmap_vtop
7779 if (($kgm_mtype & $kgm_mtype_x86_mask) != $kgm_mtype_x86_any)
7780 printf "Not available for current architecture.\n"
7781 else
7782 if $argc != 2
7783 printf "pmap_vtop <pamp> <vaddr>\n"
7784 else
7785 set $kgm_pt_verbose = 0
7786 _pmap_walk $arg0 $arg1
7787 end
7788 end
7789end
7790
7791document pmap_vtop
7792Syntax: (gdb) pmap_vtop <pmap> <virtual_address>
7793| For page-tables in <pmap> translate <virtual_address> to physical address.
7794end
7795
7796define zstack
7797 set $index = $arg0
7798
7799 if (log_records == 0)
7800 set $count = 0
7801 printf "Zone logging not enabled. Add 'zlog=<zone name>' to boot-args.\n"
7802 else
7803 if ($argc == 2)
7804 set $count = $arg1
7805 else
7806 set $count = 1
7807 end
7808 end
7809
7810 while ($count)
7811 printf "\n--------------- "
7812
7813 if (zrecords[$index].z_opcode == 1)
7814 printf "ALLOC "
7815 else
7816 printf "FREE "
7817 end
7818
7819 printf " 0x%x : index %d : ztime %d -------------\n", zrecords[$index].z_element, $index, zrecords[$index].z_time
7820
7821 set $frame = 0
7822
7823 while ($frame < 15)
7824 set $frame_pc = zrecords[$index].z_pc[$frame]
7825
7826 if ($frame_pc == 0)
7827 loop_break
7828 end
7829
7830 x/i $frame_pc
7831 set $frame = $frame + 1
7832 end
7833
7834 set $index = $index + 1
7835 set $count = $count - 1
7836 end
7837end
7838
7839document zstack
7840Syntax: (gdb) zstack <index> [<count>]
7841| Zone leak debugging: print the stack trace of log element at <index>.
7842| If a <count> is supplied, it prints <count> log elements starting at <index>.
7843|
7844| The suggested usage is to look at indexes below zcurrent and look for common stack traces.
7845| The stack trace that occurs the most is probably the cause of the leak. Find the pc of the
7846| function calling into zalloc and use the countpcs kgmacro to find out how often that pc occurs in the log.
7847| The pc occuring in a high percentage of records is most likely the source of the leak.
7848|
7849| The findoldest kgmacro is also useful for leak debugging since it identifies the oldest record
7850| in the log, which may indicate the leaker.
7851end
7852
7853define findoldest
7854 set $index = 0
7855 set $count = log_records
7856 set $cur_min = 2000000000
7857 set $cur_index = 0
7858
7859 if (log_records == 0)
7860 printf "Zone logging not enabled. Add 'zlog=<zone name>' to boot-args.\n"
7861 else
7862
7863 while ($count)
7864 if (zrecords[$index].z_element && zrecords[$index].z_time < $cur_min)
7865 set $cur_index = $index
7866 set $cur_min = zrecords[$index].z_time
7867 end
7868
7869 set $count = $count - 1
7870 set $index = $index + 1
7871 end
7872
7873 printf "oldest record is at log index %d:\n", $cur_index
7874 zstack $cur_index
7875 end
7876end
7877
7878document findoldest
7879Syntax: (gdb) findoldest
7880| Zone leak debugging: find and print the oldest record in the log. Note that this command
7881| can take several minutes to run since it uses linear search.
7882|
7883| Once it prints a stack trace, find the pc of the caller above all the zalloc, kalloc and
7884| IOKit layers. Then use the countpcs kgmacro to see how often this caller has allocated
7885| memory. A caller with a high percentage of records in the log is probably the leaker.
7886end
7887
7888define countpcs
7889 set $target_pc = $arg0
7890 set $index = 0
7891 set $count = log_records
7892 set $found = 0
7893
7894 if (log_records == 0)
7895 printf "Zone logging not enabled. Add 'zlog=<zone name>' to boot-args.\n"
7896 else
7897
7898 while ($count)
7899 set $frame = 0
7900
7901 if (zrecords[$index].z_element != 0)
7902 while ($frame < 15)
7903 if (zrecords[$index].z_pc[$frame] == $target_pc)
7904 set $found = $found + 1
7905 set $frame = 15
7906 end
7907
7908 set $frame = $frame + 1
7909 end
7910 end
7911
7912 set $index = $index + 1
7913 set $count = $count - 1
7914 end
7915
7916 printf "occurred %d times in log (%d%c of records)\n", $found, ($found * 100) / zrecorded, '%'
7917 end
7918end
7919
7920document countpcs
7921Syntax: (gdb) countpcs <pc>
7922| Zone leak debugging: search the log and print a count of all log entries that contain the given <pc>
7923| in the stack trace. This is useful for verifying a suspected <pc> as being the source of
7924| the leak. If a high percentage of the log entries contain the given <pc>, then it's most
7925| likely the source of the leak. Note that this command can take several minutes to run.
7926end
7927
7928define findelem
7929 set $fe_index = zcurrent
7930 set $fe_count = log_records
7931 set $fe_elem = $arg0
7932 set $fe_prev_op = -1
7933
7934 if (log_records == 0)
7935 printf "Zone logging not enabled. Add 'zlog=<zone name>' to boot-args.\n"
7936 end
7937
7938 while ($fe_count)
7939 if (zrecords[$fe_index].z_element == $fe_elem)
7940 zstack $fe_index
7941
7942 if (zrecords[$fe_index].z_opcode == $fe_prev_op)
7943 printf "*************** DOUBLE OP! *********************\n
7944 end
7945
7946 set $fe_prev_op = zrecords[$fe_index].z_opcode
7947 end
7948
7949 set $fe_count = $fe_count - 1
7950 set $fe_index = $fe_index + 1
7951
7952 if ($fe_index >= log_records)
7953 set $fe_index = 0
7954 end
7955 end
7956end
7957
7958document findelem
7959Syntax: (gdb) findelem <elem addr>
7960| Zone corruption debugging: search the log and print out the stack traces for all log entries that
7961| refer to the given zone element. When the kernel panics due to a corrupted zone element, get the
7962| element address and use this macro. This will show you the stack traces of all logged zalloc and
7963| zfree operations which tells you who touched the element in the recent past. This also makes
7964| double-frees readily apparent.
7965end
7966
7967
7968# This implements a shadowing scheme in kgmacros. If the
7969# current user data can be accessed by simply changing kdp_pmap,
7970# that is used. Otherwise, we copy data into a temporary buffer
7971# in the kernel's address space and use that instead. Don't rely on
7972# kdp_pmap between invocations of map/unmap. Since the shadow
7973# codepath uses a manual KDP packet, request no more than 128 bytes.
7974# Uses $kgm_lp64 for kernel address space size
7975define _map_user_data_from_task
7976 set $kgm_map_user_taskp = (task_t)$arg0
7977 set $kgm_map_user_map = $kgm_map_user_taskp->map
7978 set $kgm_map_user_pmap = $kgm_map_user_map->pmap
7979 set $kgm_map_user_task_64 = ( $kgm_map_user_taskp->taskFeatures[0] & 0x80000000)
7980 set $kgm_map_user_window = 0
7981 set $kgm_map_switch_map = 0
7982
7983 if $kgm_lp64
7984 set $kgm_map_switch_map = 1
7985 else
7986 if !$kgm_map_user_task_64
7987 set $kgm_map_switch_map = 1
7988 end
7989 end
7990
7991 if ($kgm_map_switch_map)
7992 # switch the map safely
7993 set $kgm_map_user_window = $arg1
7994 set kdp_pmap = $kgm_map_user_pmap
7995 else
7996 # requires shadowing/copying
7997
7998 # set up the manual KDP packet
7999 set manual_pkt.input = 0
8000 set manual_pkt.len = sizeof(kdp_readmem64_req_t)
8001 set $kgm_pkt = (kdp_readmem64_req_t *)&manual_pkt.data
8002 set $kgm_pkt->hdr.request = KDP_READMEM64
8003 set $kgm_pkt->hdr.len = sizeof(kdp_readmem64_req_t)
8004 set $kgm_pkt->hdr.is_reply = 0
8005 set $kgm_pkt->hdr.seq = 0
8006 set $kgm_pkt->hdr.key = 0
8007 set $kgm_pkt->address = (uint64_t)$arg1
8008 set $kgm_pkt->nbytes = (uint32_t)$arg2
8009
8010 set kdp_pmap = $kgm_map_user_pmap
8011 set manual_pkt.input = 1
8012 # dummy to make sure manual packet is executed
8013 set $kgm_dummy = &_mh_execute_header
8014 # Go back to kernel map so that we can access buffer directly
8015 set kdp_pmap = 0
8016
8017 set $kgm_pkt = (kdp_readmem64_reply_t *)&manual_pkt.data
8018 if ($kgm_pkt->error == 0)
8019 set $kgm_map_user_window = $kgm_pkt->data
8020 else
8021 set $kgm_map_user_window = 0
8022 end
8023
8024 end
8025end
8026
8027define _unmap_user_data_from_task
8028 set kdp_pmap = 0
8029end
8030
8031# uses $kgm_taskp. Maps 32 bytes at a time and prints it
8032define _print_path_for_image
8033 set $kgm_print_path_address = (unsigned long long)$arg0
8034 set $kgm_path_str_notdone = 1
8035
8036 while $kgm_path_str_notdone
8037 _map_user_data_from_task $kgm_taskp $kgm_print_path_address 32
8038
8039 set $kgm_print_path_ptr = (char *)$kgm_map_user_window
8040 set $kgm_path_i = 0
8041 while ($kgm_path_i < 32 && $kgm_print_path_ptr[$kgm_path_i] != '\0')
8042 set $kgm_path_i = $kgm_path_i + 1
8043 end
8044 printf "%.32s", $kgm_print_path_ptr
8045
8046 _unmap_user_data_from_task $kgm_taskp
8047
8048 # if we terminated on NUL, break out
8049 if $kgm_path_i < 32
8050 set $kgm_path_str_notdone = 0
8051 else
8052 set $kgm_print_path_address = $kgm_print_path_address + 32
8053 end
8054 end
8055end
8056
8057# uses $kgm_taskp and $kgm_task_64
8058define _print_image_info
8059 set $kgm_mh_image_address = (unsigned long long)$arg0
8060 set $kgm_mh_path_address = (unsigned long long)$arg1
8061
8062 # 32 bytes enough for mach_header/mach_header_64
8063 _map_user_data_from_task $kgm_taskp $kgm_mh_image_address 32
8064
8065 set $kgm_mh_ptr = (unsigned int*)$kgm_map_user_window
8066 set $kgm_mh_magic = $kgm_mh_ptr[0]
8067 set $kgm_mh_cputype = $kgm_mh_ptr[1]
8068 set $kgm_mh_cpusubtype = $kgm_mh_ptr[2]
8069 set $kgm_mh_filetype = $kgm_mh_ptr[3]
8070 set $kgm_mh_ncmds = $kgm_mh_ptr[4]
8071 set $kgm_mh_sizeofcmds = $kgm_mh_ptr[5]
8072 set $kgm_mh_flags = $kgm_mh_ptr[6]
8073
8074 _unmap_user_data_from_task $kgm_taskp
8075
8076 if $kgm_mh_magic == 0xfeedfacf
8077 set $kgm_mh_64 = 1
8078 set $kgm_lc_address = $kgm_mh_image_address + 32
8079 else
8080 set $kgm_mh_64 = 0
8081 set $kgm_lc_address = $kgm_mh_image_address + 28
8082 end
8083
8084 set $kgm_lc_idx = 0
8085 set $kgm_uuid_data = 0
8086 while $kgm_lc_idx < $kgm_mh_ncmds
8087
8088 # 24 bytes is size of uuid_command
8089 _map_user_data_from_task $kgm_taskp $kgm_lc_address 24
8090
8091 set $kgm_lc_ptr = (unsigned int *)$kgm_map_user_window
8092 set $kgm_lc_cmd = $kgm_lc_ptr[0]
8093 set $kgm_lc_cmd_size = $kgm_lc_ptr[1]
8094 set $kgm_lc_data = (unsigned char *)$kgm_lc_ptr + 8
8095
8096 if $kgm_lc_cmd == 0x1b
8097 set $kgm_uuid_data = $kgm_lc_data
8098 if $kgm_mh_64
8099 printf "0x%016llx ", $kgm_mh_image_address
8100 else
8101 printf "0x%08x ", $kgm_mh_image_address
8102 end
8103
8104 set $kgm_printed_type = 0
8105 if $kgm_mh_filetype == 0x2
8106 printf "MH_EXECUTE "
8107 set $kgm_printed_type = 1
8108 end
8109 if $kgm_mh_filetype == 0x6
8110 printf "MH_DYLIB "
8111 set $kgm_printed_type = 1
8112 end
8113 if $kgm_mh_filetype == 0x7
8114 printf "MH_DYLINKER "
8115 set $kgm_printed_type = 1
8116 end
8117 if $kgm_mh_filetype == 0x8
8118 printf "MH_BUNDLE "
8119 set $kgm_printed_type = 1
8120 end
8121 if !$kgm_printed_type
8122 printf "UNKNOWN "
8123 end
8124 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]
8125 printf "%02.2X%02.2X-", $kgm_uuid_data[4], $kgm_uuid_data[5]
8126 printf "%02.2X%02.2X-", $kgm_uuid_data[6], $kgm_uuid_data[7]
8127 printf "%02.2X%02.2X-", $kgm_uuid_data[8], $kgm_uuid_data[9]
8128 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]
8129
8130 _unmap_user_data_from_task $kgm_taskp
8131
8132 printf " "
8133 _print_path_for_image $kgm_mh_path_address
8134 printf "\n"
8135
8136 loop_break
8137 else
8138 _unmap_user_data_from_task $kgm_taskp
8139 end
8140
8141 set $kgm_lc_address = $kgm_lc_address + $kgm_lc_cmd_size
8142 set $kgm_lc_idx = $kgm_lc_idx + 1
8143 end
8144
8145 if (!$kgm_uuid_data)
8146 # didn't find LC_UUID, for a dylib, just print out basic info
8147 if $kgm_mh_64
8148 printf "0x%016llx ", $kgm_mh_image_address
8149 else
8150 printf "0x%08x ", $kgm_mh_image_address
8151 end
8152 set $kgm_printed_type = 0
8153 if $kgm_mh_filetype == 0x2
8154 printf "MH_EXECUTE "
8155 set $kgm_printed_type = 1
8156 end
8157 if $kgm_mh_filetype == 0x6
8158 printf "MH_DYLIB "
8159 set $kgm_printed_type = 1
8160 end
8161 if $kgm_mh_filetype == 0x7
8162 printf "MH_DYLINKER "
8163 set $kgm_printed_type = 1
8164 end
8165 if $kgm_mh_filetype == 0x8
8166 printf "MH_BUNDLE "
8167 set $kgm_printed_type = 1
8168 end
8169 if !$kgm_printed_type
8170 printf "UNKNOWN "
8171 end
8172 printf " ",
8173
8174 printf " "
8175 _print_path_for_image $kgm_mh_path_address
8176 printf "\n"
8177
8178 end
8179
8180end
8181
8182define _print_images_for_dyld_image_info
8183 set $kgm_taskp = $arg0
8184 set $kgm_task_64 = $arg1
8185 set $kgm_dyld_all_image_infos_address = (unsigned long long)$arg2
8186
8187 _map_user_data_from_task $kgm_taskp $kgm_dyld_all_image_infos_address 16
8188
8189 set $kgm_dyld_all_image_infos = (unsigned int *)$kgm_map_user_window
8190 if ($kgm_dyld_all_image_infos[0] != 6)
8191 printf "Invalid version number %d\n", $kgm_dyld_all_image_infos[0]
8192 end
8193 set $kgm_image_info_count = $kgm_dyld_all_image_infos[1]
8194
8195 if $kgm_task_64
8196 set $kgm_image_info_size = 24
8197 set $kgm_image_info_array_address = ((unsigned long long *)$kgm_dyld_all_image_infos)[1]
8198 else
8199 set $kgm_image_info_size = 12
8200 set $kgm_image_info_array_address = ((unsigned int *)$kgm_dyld_all_image_infos)[2]
8201 end
8202
8203 _unmap_user_data_from_task $kgm_taskp
8204
8205 set $kgm_image_info_i = 0
8206 while $kgm_image_info_i < $kgm_image_info_count
8207
8208 set $kgm_image_info_address = $kgm_image_info_array_address + $kgm_image_info_size*$kgm_image_info_i
8209
8210 _map_user_data_from_task $kgm_taskp $kgm_image_info_address $kgm_image_info_size
8211 if $kgm_task_64
8212 set $kgm_image_info_addr = ((unsigned long long *)$kgm_map_user_window)[0]
8213 set $kgm_image_info_path = ((unsigned long long *)$kgm_map_user_window)[1]
8214 else
8215 set $kgm_image_info_addr = ((unsigned int *)$kgm_map_user_window)[0]
8216 set $kgm_image_info_path = ((unsigned int *)$kgm_map_user_window)[1]
8217 end
8218 _unmap_user_data_from_task $kgm_taskp
8219
8220 # printf "[%d] = image address %llx path address %llx\n", $kgm_image_info_i, $kgm_image_info_addr, $kgm_image_info_path
8221 _print_image_info $kgm_image_info_addr $kgm_image_info_path
8222
8223 set $kgm_image_info_i = $kgm_image_info_i + 1
8224 end
8225end
8226
8227define showuserlibraries
8228 set $kgm_taskp = (task_t)$arg0
8229 set $kgm_dyld_image_info = $kgm_taskp->all_image_info_addr
8230
8231 set $kgm_map = $kgm_taskp->map
8232 set $kgm_task_64 = ( $kgm_taskp->taskFeatures[0] & 0x80000000)
8233
8234 if ($kgm_dyld_image_info != 0)
8235 printf "address "
8236 if $kgm_task_64
8237 printf " "
8238 end
8239 printf " type "
8240 printf " uuid "
8241 printf "path\n"
8242
8243 _print_images_for_dyld_image_info $kgm_taskp $kgm_task_64 $kgm_dyld_image_info
8244 else
8245 printf "No dyld shared library information available for task\n"
8246 end
8247end
8248document showuserlibraries
8249Syntax: (gdb) showuserlibraries <task_t>
8250| For a given user task, inspect the dyld shared library state and print
8251| information about all Mach-O images.
8252end
8253
8254define showkerneldebugheader
8255 printf "kd_buf "
8256 showptrhdrpad
8257 printf "CPU Thread "
8258 showptrhdrpad
8259 printf "Timestamp S/E Class Sub Code Code Specific Info\n"
8260end
8261
8262define _printevflags
8263 if $arg0 & 1
8264 printf "EV_RE "
8265 end
8266 if $arg0 & 2
8267 printf "EV_WR "
8268 end
8269 if $arg0 & 4
8270 printf "EV_EX "
8271 end
8272 if $arg0 & 8
8273 printf "EV_RM "
8274 end
8275
8276 if $arg0 & 0x00100
8277 printf "EV_RBYTES "
8278 end
8279 if $arg0 & 0x00200
8280 printf "EV_WBYTES "
8281 end
8282 if $arg0 & 0x00400
8283 printf "EV_RCLOSED "
8284 end
8285 if $arg0 & 0x00800
8286 printf "EV_RCONN "
8287 end
8288 if $arg0 & 0x01000
8289 printf "EV_WCLOSED "
8290 end
8291 if $arg0 & 0x02000
8292 printf "EV_WCONN "
8293 end
8294 if $arg0 & 0x04000
8295 printf "EV_OOB "
8296 end
8297 if $arg0 & 0x08000
8298 printf "EV_FIN "
8299 end
8300 if $arg0 & 0x10000
8301 printf "EV_RESET "
8302 end
8303 if $arg0 & 0x20000
8304 printf "EV_TIMEOUT "
8305 end
8306end
8307
8308define showkerneldebugbufferentry
8309 set $kgm_kdebug_entry = (kd_buf *) $arg0
8310
8311 set $kgm_debugid = $kgm_kdebug_entry->debugid
8312 set $kgm_kdebug_arg1 = $kgm_kdebug_entry->arg1
8313 set $kgm_kdebug_arg2 = $kgm_kdebug_entry->arg2
8314 set $kgm_kdebug_arg3 = $kgm_kdebug_entry->arg3
8315 set $kgm_kdebug_arg4 = $kgm_kdebug_entry->arg4
8316
8317 if $kgm_lp64
8318 set $kgm_kdebug_cpu = $kgm_kdebug_entry->cpuid
8319 set $kgm_ts_hi = ($kgm_kdebug_entry->timestamp >> 32) & 0xFFFFFFFF
8320 set $kgm_ts_lo = $kgm_kdebug_entry->timestamp & 0xFFFFFFFF
8321 else
8322 set $kgm_kdebug_cpu = ($kgm_kdebug_entry->timestamp >> 56)
8323 set $kgm_ts_hi = ($kgm_kdebug_entry->timestamp >> 32) & 0x00FFFFFF
8324 set $kgm_ts_lo = $kgm_kdebug_entry->timestamp & 0xFFFFFFFF
8325 end
8326
8327 set $kgm_kdebug_class = ($kgm_debugid >> 24) & 0x000FF
8328 set $kgm_kdebug_subclass = ($kgm_debugid >> 16) & 0x000FF
8329 set $kgm_kdebug_code = ($kgm_debugid >> 2) & 0x03FFF
8330 set $kgm_kdebug_qual = ($kgm_debugid ) & 0x00003
8331
8332 if $kgm_kdebug_qual == 0
8333 set $kgm_kdebug_qual = '-'
8334 else
8335 if $kgm_kdebug_qual == 1
8336 set $kgm_kdebug_qual = 'S'
8337 else
8338 if $kgm_kdebug_qual == 2
8339 set $kgm_kdebug_qual = 'E'
8340 else
8341 if $kgm_kdebug_qual == 3
8342 set $kgm_kdebug_qual = '?'
8343 end
8344 end
8345 end
8346 end
8347
8348 # preamble and qual
8349
8350 showptr $kgm_kdebug_entry
8351 printf " %d ", $kgm_kdebug_cpu
8352 showptr $kgm_kdebug_entry->arg5
8353 printf " 0x%08X%08X %c ", $kgm_ts_hi, $kgm_ts_lo, $kgm_kdebug_qual
8354
8355 # class
8356
8357 if $kgm_kdebug_class == 1
8358 printf "MACH"
8359 else
8360 if $kgm_kdebug_class == 2
8361 printf "NET "
8362 else
8363 if $kgm_kdebug_class == 3
8364 printf "FS "
8365 else
8366 if $kgm_kdebug_class == 4
8367 printf "BSD "
8368 else
8369 if $kgm_kdebug_class == 5
8370 printf "IOK "
8371 else
8372 if $kgm_kdebug_class == 6
8373 printf "DRVR"
8374 else
8375 if $kgm_kdebug_class == 7
8376 printf "TRAC"
8377 else
8378 if $kgm_kdebug_class == 8
8379 printf "DLIL"
8380 else
8381 if $kgm_kdebug_class == 8
8382 printf "SEC "
8383 else
8384 if $kgm_kdebug_class == 20
8385 printf "MISC"
8386 else
8387 if $kgm_kdebug_class == 31
8388 printf "DYLD"
8389 else
8390 if $kgm_kdebug_class == 32
8391 printf "QT "
8392 else
8393 if $kgm_kdebug_class == 33
8394 printf "APPS"
8395 else
8396 if $kgm_kdebug_class == 255
8397 printf "MIG "
8398 else
8399 printf "0x%02X", $kgm_kdebug_class
8400 end
8401 end
8402 end
8403 end
8404 end
8405 end
8406 end
8407 end
8408 end
8409 end
8410 end
8411 end
8412 end
8413 end
8414
8415 # subclass and code
8416
8417 printf " 0x%02X %5d ", $kgm_kdebug_subclass, $kgm_kdebug_code
8418
8419 # space for debugid-specific processing
8420
8421 # EVPROC from bsd/kern/sys_generic.c
8422
8423 # MISCDBG_CODE(DBG_EVENT,DBG_WAIT)
8424 if $kgm_debugid == 0x14100048
8425 printf "waitevent "
8426 if $kgm_kdebug_arg1 == 1
8427 printf "before sleep"
8428 else
8429 if $kgm_kdebug_arg1 == 2
8430 printf "after sleep"
8431 else
8432 printf "????????????"
8433 end
8434 end
8435 printf " chan=0x%08X ", $kgm_kdebug_arg2
8436 else
8437 # MISCDBG_CODE(DBG_EVENT,DBG_WAIT|DBG_FUNC_START)
8438 if $kgm_debugid == 0x14100049
8439 printf "waitevent "
8440 else
8441 # MISCDBG_CODE(DBG_EVENT,DBG_WAIT|DBG_FUNC_END)
8442 if $kgm_debugid == 0x1410004a
8443 printf "waitevent error=%d ", $kgm_kdebug_arg1
8444 printf "eqp=0x%08X ", $kgm_kdebug_arg4
8445 _printevflags $kgm_kdebug_arg3
8446 printf "er_handle=%d ", $kgm_kdebug_arg2
8447 else
8448 # MISCDBG_CODE(DBG_EVENT,DBG_DEQUEUE|DBG_FUNC_START)
8449 if $kgm_debugid == 0x14100059
8450 printf "evprocdeque proc=0x%08X ", $kgm_kdebug_arg1
8451 if $kgm_kdebug_arg2 == 0
8452 printf "remove first "
8453 else
8454 printf "remove 0x%08X ", $kgm_kdebug_arg2
8455 end
8456 else
8457 # MISCDBG_CODE(DBG_EVENT,DBG_DEQUEUE|DBG_FUNC_END)
8458 if $kgm_debugid == 0x1410005a
8459 printf "evprocdeque "
8460 if $kgm_kdebug_arg1 == 0
8461 printf "result=NULL "
8462 else
8463 printf "result=0x%08X ", $kgm_kdebug_arg1
8464 end
8465 else
8466 # MISCDBG_CODE(DBG_EVENT,DBG_POST|DBG_FUNC_START)
8467 if $kgm_debugid == 0x14100041
8468 printf "postevent "
8469 _printevflags $kgm_kdebug_arg1
8470 else
8471 # MISCDBG_CODE(DBG_EVENT,DBG_POST)
8472 if $kgm_debugid == 0x14100040
8473 printf "postevent "
8474 printf "evq=0x%08X ", $kgm_kdebug_arg1
8475 printf "er_eventbits="
8476 _printevflags $kgm_kdebug_arg2
8477 printf "mask="
8478 _printevflags $kgm_kdebug_arg3
8479 else
8480 # MISCDBG_CODE(DBG_EVENT,DBG_POST|DBG_FUNC_END)
8481 if $kgm_debugid == 0x14100042
8482 printf "postevent "
8483 else
8484 # MISCDBG_CODE(DBG_EVENT,DBG_ENQUEUE|DBG_FUNC_START)
8485 if $kgm_debugid == 0x14100055
8486 printf "evprocenque eqp=0x%08d ", $kgm_kdebug_arg1
8487 if $kgm_kdebug_arg2 & 1
8488 printf "EV_QUEUED "
8489 end
8490 _printevflags $kgm_kdebug_arg3
8491 else
8492
8493 # MISCDBG_CODE(DBG_EVENT,DBG_EWAKEUP)
8494 if $kgm_debugid == 0x14100050
8495 printf "evprocenque before wakeup eqp=0x%08d ", $kgm_kdebug_arg4
8496 else
8497 # MISCDBG_CODE(DBG_EVENT,DBG_ENQUEUE|DBG_FUNC_END)
8498 if $kgm_debugid == 0x14100056
8499 printf "evprocenque "
8500 else
8501 # MISCDBG_CODE(DBG_EVENT,DBG_MOD|DBG_FUNC_START)
8502 if $kgm_debugid == 0x1410004d
8503 printf "modwatch "
8504 else
8505 # MISCDBG_CODE(DBG_EVENT,DBG_MOD)
8506 if $kgm_debugid == 0x1410004c
8507 printf "modwatch er_handle=%d ", $kgm_kdebug_arg1
8508 _printevflags $kgm_kdebug_arg2
8509 printf "evq=0x%08X ", $kgm_kdebug_arg3
8510 else
8511 # MISCDBG_CODE(DBG_EVENT,DBG_MOD|DBG_FUNC_END)
8512 if $kgm_debugid == 0x1410004e
8513 printf "modwatch er_handle=%d ", $kgm_kdebug_arg1
8514 printf "ee_eventmask="
8515 _printevflags $kgm_kdebug_arg2
8516 printf "sp=0x%08X ", $kgm_kdebug_arg3
8517 printf "flag="
8518 _printevflags $kgm_kdebug_arg4
8519 else
8520 printf "arg1=0x%08X ", $kgm_kdebug_arg1
8521 printf "arg2=0x%08X ", $kgm_kdebug_arg2
8522 printf "arg3=0x%08X ", $kgm_kdebug_arg3
8523 printf "arg4=0x%08X ", $kgm_kdebug_arg4
8524 end
8525 end
8526 end
8527 end
8528 end
8529 end
8530 end
8531 end
8532 end
8533 end
8534 end
8535 end
8536 end
8537 end
8538
8539 # finish up
8540
8541 printf "\n"
8542end
8543
8544define showkerneldebugbuffercpu
8545 set $kgm_cpu_number = (int) $arg0
8546 set $kgm_entry_count = (int) $arg1
8547 set $kgm_debugentriesfound = 0
8548
8549 #if kdebug_flags & KDBG_BFINIT
8550 if (kdebug_flags & 0x80000000)
8551 showkerneldebugheader
8552
8553 if $kgm_entry_count == 0
8554 printf "<count> is 0, dumping 50 entries\n"
8555 set $kgm_entry_count = 50
8556 end
8557
8558 if $kgm_cpu_number >= kd_cpus
8559 printf "cpu number too big\n"
8560 else
8561 set $kgm_kdbp = &kdbip[$kgm_cpu_number]
8562 set $kgm_kdsp = $kgm_kdbp->kd_list_head
8563 while (($kgm_kdsp != 0) && ($kgm_entry_count > 0))
8564 if $kgm_kdsp->kds_readlast != $kgm_kdsp->kds_bufptr
8565 set $kgm_kds_bufptr = $kgm_kdsp->kds_bufptr
8566 while (($kgm_kds_bufptr > $kgm_kdsp->kds_readlast) && ($kgm_entry_count > 0))
8567 set $kgm_kds_bufptr = $kgm_kds_bufptr - 1
8568 set $kgm_entry_count = $kgm_entry_count - 1
8569 showkerneldebugbufferentry $kgm_kds_bufptr
8570 end
8571 end
8572 set $kgm_kdsp = $kgm_kdsp->kds_next
8573 end
8574 end
8575 else
8576 printf "Trace buffer not enabled\n"
8577 end
8578end
8579
8580document showkerneldebugbuffercpu
8581Syntax: showkerneldebugbuffercpu <cpu> <count>
8582| Prints the last N entries in the kernel debug buffer for CPU x.
8583end
8584
8585define showkerneldebugbuffer
8586
8587 #if kdebug_flags & KDBG_BFINIT
8588 if (kdebug_flags & 0x80000000)
8589
8590 set $kgm_entrycount = (int) $arg0
8591
8592 if $kgm_entrycount == 0
8593 printf "<count> is 0, dumping 50 entries per cpu\n"
8594 set $kgm_entrycount = 50
8595 end
8596
8597 set $kgm_cpu = (int) 0
8598
8599 while $kgm_cpu < kd_cpus
8600 showkerneldebugbuffercpu $kgm_cpu $kgm_entrycount
8601 set $kgm_cpu = $kgm_cpu + 1
8602 end
8603 else
8604 printf "Trace buffer not enabled\n"
8605 end
8606end
8607
8608document showkerneldebugbuffer
8609Syntax: showkerneldebugbuffer <count>
8610| Prints the last N entries in the kernel debug buffer per cpu. i.e. showkerneldebugbuffer 50 will
8611| display the last 50 entries in each CPU's debug buffer.
8612end
8613
8614define showallvmstats
8615 printf " pid command #ents wired vsize rsize max rsize\n"
8616 printf " (pages) (pages) (pages) (pages)\n"
8617 set $kgm_head_taskp = &tasks
8618 set $kgm_taskp = (struct task *)($kgm_head_taskp->next)
8619 while $kgm_taskp != $kgm_head_taskp
8620 set $kgm_procp = (struct proc *)($kgm_taskp->bsd_info)
8621 set $kgm_mapp = (struct _vm_map *)($kgm_taskp->map)
8622 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
8623 set $kgm_taskp = (struct task *)($kgm_taskp->tasks.next)
8624 end
8625end
8626
8627document showallvmstats
8628Syntax: showallvmstats
8629| prints a summary of vm statistics in a table format
8630end
8631
8632define show_user_registers
8633 if (($kgm_mtype & $kgm_mtype_x86_mask) == $kgm_mtype_x86_any)
8634 set $kgm_thread = (thread_t)$arg0
8635 if ((*(thread_t)$kgm_thread)->machine.xxx_pcb.iss.flavor == 15)
8636 p/x ($kgm_thread)->machine.xxx_pcb.iss->uss.ss_64
8637 else
8638 p/x ($kgm_thread)->machine.xxx_pcb.iss->uss.ss_32
8639 end
8640 end
8641 if ($kgm_mtype == $kgm_mtype_ppc)
8642 set $kgm_thread = (thread_t)$arg0
8643 p/x *($kgm_thread)->machine.pcb
8644 end
8645end
8646
8647document show_user_registers
8648Syntax: show_user_registers <thread_address>
8649| Display user registers associated with a kernel thread
8650| properly displays the 32 bit or 64 bit registers for intel architecture
8651end
8652
8653define _cmp
8654 set $cmp0 = $arg0
8655 set $cmp1 = $arg1
8656
8657 # check for end of string. cmp0 can be longer than cmp1. it
8658 # can't be shorter.
8659 if $cmp1 == '\0'
8660 set $kgm_strcmp_result = 0
8661 set $kgm_strcmp_done = 1
8662 end
8663
8664 if !$kgm_strcmp_done && $cmp0 == '\0'
8665 set $kgm_strcmp_result = -1
8666 set $kgm_strcmp_done = 1
8667 end
8668
8669 # do they match?
8670 if !$kgm_strcmp_done
8671 set $kgm_strcmp_result = (uint8_t) $cmp0 - (uint8_t) $cmp1
8672 if $kgm_strcmp_result != 0
8673 set $kgm_strcmp_done = 1
8674 end
8675 end
8676end
8677
8678define _cmp_arg64
8679 set $cmp = $arg1
8680 set $masked = $cmp & 0xFF
8681 _cmp $arg0[0] $masked
8682
8683 if !$kgm_strcmp_done
8684 set $cmp = $cmp >> 8
8685 set $masked = $cmp & 0xFF
8686 _cmp $arg0[1] $masked
8687 end
8688 if !$kgm_strcmp_done
8689 set $cmp = $cmp >> 8
8690 set $masked = $cmp & 0xFF
8691 _cmp $arg0[2] $masked
8692 end
8693 if !$kgm_strcmp_done
8694 set $cmp = $cmp >> 8
8695 set $masked = $cmp & 0xFF
8696 _cmp $arg0[3] $masked
8697 end
8698 if !$kgm_strcmp_done
8699 set $cmp = $cmp >> 8
8700 set $masked = $cmp & 0xFF
8701 _cmp $arg0[4] $masked
8702 end
8703 if !$kgm_strcmp_done
8704 set $cmp = $cmp >> 8
8705 set $masked = $cmp & 0xFF
8706 _cmp $arg0[5] $masked
8707 end
8708 if !$kgm_strcmp_done
8709 set $cmp = $cmp >> 8
8710 set $masked = $cmp & 0xFF
8711 _cmp $arg0[6] $masked
8712 end
8713 if !$kgm_strcmp_done
8714 set $cmp = $cmp >> 8
8715 set $masked = $cmp & 0xFF
8716 _cmp $arg0[7] $masked
8717 end
8718end
8719
8720define strcmp_arg_pack64
8721 set $kgm_strcmp_arg = ((((((((((((((uint64_t) $arg7 << 8) | $arg6) << 8) | $arg5) << 8) | $arg4) << 8) | $arg3) << 8) | $arg2) << 8) | $arg1) << 8) | $arg0
8722end
8723
8724document strcmp_arg_pack64
8725Syntax: strcmp_arg_pack64 <a> <b> <c> <d> <e <f> <g> <h>
8726| Packs a string given as 8 character arguments into a 64-bit int stored in
8727| $kgm_strcmp_arg. Use 0 or '\0' for unused arguments. The encoded string
8728| is suitable for use by strcmp_nomalloc and setfindregistrystr.
8729| e.g., strcmp_arg_pack64 'H' 'e' 'l' 'l' 'o' 0 0 0
8730| packs "Hello" into $kgm_strcmp_arg.
8731|
8732end
8733
8734define strcmp_nomalloc
8735 set $str = $arg0
8736 set $count = $argc - 1
8737
8738 set $kgm_strcmp_result = 0
8739 set $kgm_strcmp_done = 0
8740
8741 if $count > 0
8742 _cmp_arg64 $str $arg1
8743 end
8744 if !$kgm_strcmp_done && $count > 1
8745 set $str = $str + 8
8746 _cmp_arg64 $str $arg2
8747 end
8748 if !$kgm_strcmp_done && $count > 2
8749 set $str = $str + 8
8750 _cmp_arg64 $str $arg3
8751 end
8752 if !$kgm_strcmp_done && $count > 3
8753 set $str = $str + 8
8754 _cmp_arg64 $str $arg4
8755 end
8756 if !$kgm_strcmp_done && $count > 4
8757 set $str = $str + 8
8758 _cmp_arg64 $str $arg5
8759 end
8760 if !$kgm_strcmp_done && $count > 5
8761 set $str = $str + 8
8762 _cmp_arg64 $str $arg6
8763 end
8764 if !$kgm_strcmp_done && $count > 6
8765 set $str = $str + 8
8766 _cmp_arg64 $str $arg7
8767 end
8768 if !$kgm_strcmp_done && $count > 7
8769 set $str = $str + 8
8770 _cmp_arg64 $str $arg8
8771 end
8772 if !$kgm_strcmp_done && $count > 8
8773 set $str = $str + 8
8774 _cmp_arg64 $str $arg9
8775 end
8776end
8777
8778document strcmp_nomalloc
8779Syntax: strcmp_nomalloc <string> <a> [b] [c] [d] [e] [f] [g] [h] [i]
8780| Given a pre-allocated <string>, perform a string compare with the
8781| encoded string stored in arguments a - i. The result is stored in
8782| $kgm_strcmp_result.
8783|
8784| For example, the following will result in $kgm_strcmp_result == 0:
8785| strcmp_arg_pack64 'D' 'a' 'r' 'w' 'i' 'n' ' ' 'K'
8786| strcmp_nomalloc version $kgm_strcmp_arg
8787end
8788
8789# _pci_cfg_addr_value $addr $size
8790define _pci_cfg_addr_value
8791 readphysint $arg0 $arg1 $kgm_lcpu_self
8792 set $kgm_pci_cfg_value = $kgm_readphysint_result
8793end
8794
8795
8796set $kgm_pci_cfg_init = 0
8797define _pci_cfg_init
8798 # get this from the registry if it exists there
8799 if $kgm_pci_cfg_init == 0
8800 strcmp_arg_pack64 'A' 'p' 'p' 'l' 'e' 'A' 'C' 'P'
8801 set $AppleACP = $kgm_strcmp_arg
8802 strcmp_arg_pack64 'I' 'P' 'l' 'a' 't' 'f' 'o' 'r'
8803 set $IPlatfor = $kgm_strcmp_arg
8804 strcmp_arg_pack64 'm' 'E' 'x' 'p' 'e' 'r' 't' 0
8805 set $mExpert = $kgm_strcmp_arg
8806 setfindregistrystr $AppleACP $IPlatfor $mExpert
8807
8808 set $olddepth = $kgm_reg_depth_max
8809 set $kgm_reg_depth_max = 2
8810 _findregistryentry
8811 set $kgm_reg_depth_max = $olddepth
8812
8813 if $kgm_registry_entry
8814 strcmp_arg_pack64 'a' 'c' 'p' 'i' '-' 'm' 'm' 'c'
8815 set $acpi_mmc = $kgm_strcmp_arg
8816 strcmp_arg_pack64 'f' 'g' '-' 's' 'e' 'g' '0' 0
8817 set $fg_seg0 = $kgm_strcmp_arg
8818 setfindregistrystr $acpi_mmc $fg_seg0
8819
8820 _findregistryprop $kgm_registry_entry
8821 if $kgm_registry_value
8822 set $kgm_pci_cfg_base = ((OSNumber *) $kgm_registry_value)->value
8823 set $kgm_pci_cfg_init = 1
8824 end
8825 end
8826 end
8827
8828 # if the above fails, search for 0:0:0 in likely places.
8829 if $kgm_pci_cfg_init == 0
8830 set $kgm_pci_cfg_base = 0xF0000000
8831 while $kgm_pci_cfg_init == 0 && $kgm_pci_cfg_base > 0xA0000000
8832 _pci_cfg_addr_value $kgm_pci_cfg_base 8
8833 if $kgm_pci_cfg_value > 0x0 && $kgm_pci_cfg_value < 0xFF
8834 set $kgm_pci_cfg_init = 1
8835 else
8836 set $kgm_pci_cfg_base = $kgm_pci_cfg_base - 0x10000000
8837 end
8838 end
8839 end
8840end
8841
8842# _pci_cfg_addr $bus $dev $fcn $off
8843define _pci_cfg_addr
8844 set $bus = $arg0
8845 set $dev = $arg1
8846 set $fcn = $arg2
8847 set $off = $arg3
8848
8849 _pci_cfg_init
8850 set $kgm_pci_cfg_addr = $kgm_pci_cfg_base | ($bus << 20) | ($dev << 15) | ($fcn << 12) | $off
8851end
8852
8853define _pci_cfg_value
8854 _pci_cfg_addr $arg0 $arg1 $arg2 $arg3
8855 _pci_cfg_addr_value $kgm_pci_cfg_addr $arg4
8856end
8857
8858define pci_cfg_read8
8859 _pci_cfg_value $arg0 $arg1 $arg2 $arg3 8
8860 printf "%08X: %02X\n", $kgm_pci_cfg_addr, $kgm_pci_cfg_value
8861end
8862
8863define pci_cfg_read16
8864 _pci_cfg_value $arg0 $arg1 $arg2 $arg3 16
8865 printf "%08X: %04X\n", $kgm_pci_cfg_addr, $kgm_pci_cfg_value
8866end
8867
8868define pci_cfg_read32
8869 _pci_cfg_value $arg0 $arg1 $arg2 $arg3 32
8870 printf "%08X: %08X\n", $kgm_pci_cfg_addr, $kgm_pci_cfg_value
8871end
8872
8873document pci_cfg_read8
8874Syntax: (gdb) pci_cfg_read8 <bus> <dev> <fcn> <off>
8875| read 8 bits for the given <off> of the pci device located at
8876| <bus>:<dev>:<fcn>.
8877end
8878
8879document pci_cfg_read16
8880Syntax: (gdb) pci_cfg_read <bus> <dev> <fcn> <off>
8881| read 16 bits for the given <off> of the pci device located at
8882| <bus>:<dev>:<fcn>.
8883end
8884
8885document pci_cfg_read32
8886Syntax: (gdb) pci_cfg_read <bus> <dev> <fcn> <off>
8887| read 32 bits for the given <off> of the pci device located at
8888| <bus>:<dev>:<fcn>.
8889end
8890
8891define pci_cfg_write8
8892 _pci_cfg_addr $arg0 $arg1 $arg2 $arg3
8893 writephysint $kgm_pci_cfg_addr 8 $arg4 $kgm_lcpu_self
8894end
8895
8896define pci_cfg_write16
8897 _pci_cfg_addr $arg0 $arg1 $arg2 $arg3
8898 writephysint $kgm_pci_cfg_addr 16 $arg4 $kgm_lcpu_self
8899end
8900
8901define pci_cfg_write32
8902 _pci_cfg_addr $arg0 $arg1 $arg2 $arg3
8903 writephysint $kgm_pci_cfg_addr 32 $arg4 $kgm_lcpu_self
8904end
8905
8906document pci_cfg_write8
8907Syntax: (gdb) pci_cfg_write8 <bus> <dev> <fcn> <off> <value>
8908| write an 8-bit <value> into the given <off> of the pci device located at
8909| <bus>:<dev>:<fcn>.
8910end
8911
8912document pci_cfg_write16
8913Syntax: (gdb) pci_cfg_write16 <bus> <dev> <fcn> <off> <value>
8914| write a 16-bit <value> into the given <off> of the pci device located at
8915| <bus>:<dev>:<fcn>.
8916end
8917
8918document pci_cfg_write32
8919Syntax: (gdb) pci_cfg_write32 <bus> <dev> <fcn> <off> <value>
8920| write a 32-bit <value> into the given <off> of the pci device located at
8921| <bus>:<dev>:<fcn>.
8922end
8923
8924
8925define pci_cfg_dump
8926 set $bus = $arg0
8927 set $dev = $arg1
8928 set $fcn = $arg2
8929 set $off = 0
8930
8931 # check for a valid pci device
8932 _pci_cfg_value $bus $dev $fcn $off 8
8933 if $kgm_pci_cfg_value > 0x0 && $kgm_pci_cfg_value < 0xff
8934 printf " address: 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F\n"
8935 printf "---------------------------------------------------------"
8936
8937 while $off < 256
8938 _pci_cfg_value $bus $dev $fcn $off 32
8939 if ($off & 0xF) == 0
8940 printf "\n%08X: ", $kgm_pci_cfg_addr
8941 end
8942 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
8943 set $off = $off + 4
8944 end
8945 printf "\n"
8946
8947 # check for pcie extended capability config space
8948 _pci_cfg_value $bus $dev $fcn $off 8
8949 if $kgm_pci_cfg_value < 0xff
8950 while $off < 4096
8951 _pci_cfg_value $bus $dev $fcn $off 32
8952 if ($off & 0xF) == 0
8953 printf "\n%08X: ", $kgm_pci_cfg_addr
8954 end
8955 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
8956 set $off = $off + 4
8957 end
8958 printf "\n"
8959 end
8960 end
8961end
8962
8963document pci_cfg_dump
8964Syntax: (gdb) pci_cfg_dump <bus> <dev> <fcn>
8965| dump config space for the pci device located at <bus>:<dev>:<fcn>
8966| if you specify an invalid/inaccessible pci device, nothing will be
8967| printed out.
8968end
8969
8970set $kgm_pci_cfg_bus_start = 0
8971set $kgm_pci_cfg_bus_max = 8
8972set $kgm_pci_cfg_device_max = 32
8973set $kgm_pci_cfg_function_max = 8
8974define _pci_cfg_scan
8975 set $dump = $arg0
8976
8977 set $bus = $kgm_pci_cfg_bus_start
8978 while $bus < $kgm_pci_cfg_bus_max
8979 # check for bus:0:0 to see if we should
8980 # probe this bus further
8981 _pci_cfg_value $bus 0x0 0x0 0x0 32
8982 if $kgm_pci_cfg_value > 0 && $kgm_pci_cfg_value < 0xFFFFFFFF
8983
8984 set $dev = 0
8985 while $dev < $kgm_pci_cfg_device_max
8986
8987 set $fcn = 0
8988 while $fcn < $kgm_pci_cfg_function_max
8989 _pci_cfg_value $bus $dev $fcn 0x0 32
8990 if $kgm_pci_cfg_value > 0 && $kgm_pci_cfg_value < 0xFFFFFFFF
8991 if $dump == 0
8992 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
8993 _pci_cfg_value $bus $dev $fcn 0x8 32
8994 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
8995 else
8996 printf " device: %03X:%03X:%03X\n", $bus, $dev, $fcn
8997 pci_cfg_dump $bus $dev $fcn
8998 printf "\n"
8999 end
9000 end
9001 set $fcn = $fcn + 1
9002 end
9003 set $dev = $dev + 1
9004 end
9005 end
9006 set $bus = $bus + 1
9007 end
9008end
9009
9010define pci_cfg_dump_all
9011 _pci_cfg_scan 1
9012end
9013
9014document pci_cfg_dump_all
9015Syntax: (gdb) pci_cfg_dump_all
9016| dump config spaces for scanned pci devices. the number of busses to scan
9017| is stored in $kgm_pci_cfg_bus_max. the default for that is 8. you can also
9018| specify the starting bus with $kgm_pci_cfg_bus_start.
9019end
9020
9021define pci_cfg_scan
9022 printf "bus:dev:fcn: vendor device rev | class\n"
9023 printf "---------------------------------------\n"
9024 _pci_cfg_scan 0
9025end
9026
9027document pci_cfg_scan
9028Syntax: (gdb) pci_cfg_scan
9029| scan for pci devices. the number of busses to scan is stored in
9030| $kgm_pci_cfg_bus_max. the default for that is 8. you can also specify the
9031| starting bus with $kgm_pci_cfg_bus_start.
9032end
9033
9034define readioportint
9035 set $kgm_readioportint_result = 0xBAD10AD
9036 # set up the manual KDP packet
9037 set manual_pkt.input = 0
9038 set manual_pkt.len = sizeof(kdp_readioport_req_t)
9039 set $kgm_pkt = (kdp_readioport_req_t *)&manual_pkt.data
9040 set $kgm_pkt->hdr.request = KDP_READIOPORT
9041 set $kgm_pkt->hdr.len = sizeof(kdp_readioport_req_t)
9042 set $kgm_pkt->hdr.is_reply = 0
9043 set $kgm_pkt->hdr.seq = 0
9044 set $kgm_pkt->hdr.key = 0
9045 set $kgm_pkt->address = (uint16_t)$arg0
9046 set $kgm_pkt->nbytes = $arg1 >> 3
9047 set $kgm_pkt->lcpu = (uint16_t)$arg2
9048 set manual_pkt.input = 1
9049 # dummy to make sure manual packet is executed
9050 set $kgm_dummy = &_mh_execute_header
9051 set $kgm_pkt = (kdp_readioport_reply_t *)&manual_pkt.data
9052 if ($kgm_pkt->error == 0)
9053 if $arg1 == 8
9054 set $kgm_readioportint_result = *((uint8_t *) $kgm_pkt->data)
9055 end
9056 if $arg1 == 16
9057 set $kgm_readioportint_result = *((uint16_t *) $kgm_pkt->data)
9058 end
9059 if $arg1 == 32
9060 set $kgm_readioportint_result = *((uint32_t *) $kgm_pkt->data)
9061 end
9062 end
9063end
9064
9065define readioport8
9066 set $lcpu = $kgm_lcpu_self
9067 if $argc > 1
9068 set $lcpu = $arg1
9069 end
9070 readioportint $arg0 8 $lcpu
9071 output /a $arg0
9072 printf ":\t0x%02hhx\n", $kgm_readioportint_result
9073end
9074
9075define readioport16
9076 set $lcpu = $kgm_lcpu_self
9077 if $argc > 1
9078 set $lcpu = $arg1
9079 end
9080 readioportint $arg0 16 $lcpu
9081 output /a $arg0
9082 printf ":\t0x%04hx\n", $kgm_readioportint_result
9083end
9084
9085define readioport32
9086 set $lcpu = $kgm_lcpu_self
9087 if $argc > 1
9088 set $lcpu = $arg1
9089 end
9090 readioportint $arg0 32 $lcpu
9091 output /a $arg0
9092 printf ":\t0x%08x\n", $kgm_readioportint_result
9093end
9094
9095document readioport8
9096| See readioport32.
9097end
9098
9099document readioport16
9100| See readioport32.
9101end
9102
9103document readioport32
9104Syntax: (gdb) readioport32 <port> [lcpu (kernel's numbering convention)]
9105| Read value stored in the specified IO port. The CPU can be optionally
9106| specified as well.
9107end
9108
9109define writeioportint
9110 # set up the manual KDP packet
9111 set manual_pkt.input = 0
9112 set manual_pkt.len = sizeof(kdp_writeioport_req_t)
9113 set $kgm_pkt = (kdp_writeioport_req_t *)&manual_pkt.data
9114 set $kgm_pkt->hdr.request = KDP_WRITEIOPORT
9115 set $kgm_pkt->hdr.len = sizeof(kdp_writeioport_req_t)
9116 set $kgm_pkt->hdr.is_reply = 0
9117 set $kgm_pkt->hdr.seq = 0
9118 set $kgm_pkt->hdr.key = 0
9119 set $kgm_pkt->address = (uint16_t)$arg0
9120 set $kgm_pkt->nbytes = $arg1 >> 3
9121 set $kgm_pkt->lcpu = (uint16_t)$arg3
9122 if $arg1 == 8
9123 set *(uint8_t *)$kgm_pkt->data = (uint8_t)$arg2
9124 end
9125 if $arg1 == 16
9126 set *(uint16_t *)$kgm_pkt->data = (uint16_t)$arg2
9127 end
9128 if $arg1 == 32
9129 set *(uint32_t *)$kgm_pkt->data = (uint32_t)$arg2
9130 end
9131 set manual_pkt.input = 1
9132 # dummy to make sure manual packet is executed
9133 set $kgm_dummy = &_mh_execute_header
9134 set $kgm_pkt = (kdp_writeioport_reply_t *)&manual_pkt.data
9135 set $kgm_writeioportint_result = $kgm_pkt->error
9136end
9137
9138define writeioport8
9139 set $lcpu = $kgm_lcpu_self
9140 if $argc > 2
9141 set $lcpu = $arg2
9142 end
9143 writeioportint $arg0 8 $arg1 $lcpu
9144end
9145
9146define writeioport16
9147 set $lcpu = $kgm_lcpu_self
9148 if $argc > 2
9149 set $lcpu = $arg2
9150 end
9151 writeioportint $arg0 16 $arg1 $lcpu
9152end
9153
9154define writeioport32
9155 set $lcpu = $kgm_lcpu_self
9156 if $argc > 2
9157 set $lcpu = $arg2
9158 end
9159 writeioportint $arg0 32 $arg1 $lcpu
9160end
9161
9162document writeioport8
9163| See writeioport32.
9164end
9165
9166document writeioport16
9167| See writeioport32.
9168end
9169
9170document writeioport32
9171Syntax: (gdb) writeioport32 <port> <value> [lcpu (kernel's numbering convention)]
9172| Write the value to the specified IO port. The size of the value is
9173| determined by the name of the command. The CPU used can be optionally
9174| specified.
9175end
9176
9177define readmsr64int
9178 set $kgm_readmsr64int_result = 0xBAD10AD
9179 # set up the manual KDP packet
9180 set manual_pkt.input = 0
9181 set manual_pkt.len = sizeof(kdp_readmsr64_req_t)
9182 set $kgm_pkt = (kdp_readmsr64_req_t *)&manual_pkt.data
9183 set $kgm_pkt->hdr.request = KDP_READMSR64
9184 set $kgm_pkt->hdr.len = sizeof(kdp_readmsr64_req_t)
9185 set $kgm_pkt->hdr.is_reply = 0
9186 set $kgm_pkt->hdr.seq = 0
9187 set $kgm_pkt->hdr.key = 0
9188 set $kgm_pkt->address = (uint32_t)$arg0
9189 set $kgm_pkt->lcpu = (uint16_t)$arg1
9190 set manual_pkt.input = 1
9191 # dummy to make sure manual packet is executed
9192 set $kgm_dummy = &_mh_execute_header
9193 set $kgm_pkt = (kdp_readmsr64_reply_t *)&manual_pkt.data
9194 if ($kgm_pkt->error == 0)
9195 set $kgm_readmsr64int_result = *((uint64_t *) $kgm_pkt->data)
9196 end
9197end
9198
9199define readmsr64
9200 set $lcpu = $kgm_lcpu_self
9201 if $argc > 1
9202 set $lcpu = $arg1
9203 end
9204 readmsr64int $arg0 $lcpu
9205 output /a $arg0
9206 printf ":\t0x%016llx\n", $kgm_readmsr64int_result
9207end
9208
9209define writemsr64int
9210 # set up the manual KDP packet
9211 set manual_pkt.input = 0
9212 set manual_pkt.len = sizeof(kdp_writemsr64_req_t)
9213 set $kgm_pkt = (kdp_writemsr64_req_t *)&manual_pkt.data
9214 set $kgm_pkt->hdr.request = KDP_WRITEMSR64
9215 set $kgm_pkt->hdr.len = sizeof(kdp_writemsr64_req_t)
9216 set $kgm_pkt->hdr.is_reply = 0
9217 set $kgm_pkt->hdr.seq = 0
9218 set $kgm_pkt->hdr.key = 0
9219 set $kgm_pkt->address = (uint32_t)$arg0
9220 set $kgm_pkt->lcpu = (uint16_t)$arg2
9221 set *(uint64_t *)$kgm_pkt->data = (uint64_t)$arg1
9222 set manual_pkt.input = 1
9223 # dummy to make sure manual packet is executed
9224 set $kgm_dummy = &_mh_execute_header
9225 set $kgm_pkt = (kdp_writemsr64_reply_t *)&manual_pkt.data
9226 set $kgm_writemsr64int_result = $kgm_pkt->error
9227end
9228
9229define writemsr64
9230 set $lcpu = $kgm_lcpu_self
9231 if $argc > 2
9232 set $lcpu = $arg2
9233 end
9234 writemsr64int $arg0 $arg1 $lcpu
9235end
9236
9237document writemsr64
9238Syntax: (gdb) writemsr64 <msr> <value> [lcpu (kernel's numbering convention)]
9239| Write <value> to the specified MSR. The CPU can be optionally specified.
2d21ac55
A
9240end
9241
b0d623f7
A
9242document readmsr64
9243Syntax: (gdb) readmsr64 <msr> [lcpu (kernel's numbering convention)]
9244| Read the specified MSR. The CPU can be optionally specified.
2d21ac55
A
9245end
9246
b0d623f7
A
9247# default if we can't find a registry entry
9248set $kgm_ioapic_addr = 0xFEC00000
9249set $kgm_ioapic_init = 0
2d21ac55 9250
b0d623f7
A
9251set $_ioapic_index_off = 0x00
9252set $_ioapic_data_off = 0x10
9253set $_ioapic_eoi_off = 0x40
9254
9255set $_ioapic_index_id = 0x00
9256set $_ioapic_index_ver = 0x01
9257set $_ioapic_index_redir_base = 0x10
9258
9259set $_apic_vector_mask = 0xFF
060df5ea
A
9260set $_apic_timer_tsc_deadline = 0x40000
9261set $_apic_timer_periodic = 0x20000
b0d623f7
A
9262set $_apic_masked = 0x10000
9263set $_apic_trigger_level = 0x08000
9264set $_apic_polarity_high = 0x02000
9265set $_apic_pending = 0x01000
9266
9267define _ioapic_init
9268 if $kgm_ioapic_init == 0
9269 strcmp_arg_pack64 'i' 'o' '-' 'a' 'p' 'i' 'c' 0
9270 setfindregistrystr $kgm_strcmp_arg
9271
9272 set $olddepth = $kgm_reg_depth_max
9273 set $kgm_reg_depth_max = 3
9274 _findregistryentry
9275 set $kgm_reg_depth_max = $olddepth
9276
9277 if $kgm_registry_entry
9278 strcmp_arg_pack64 'P' 'h' 'y' 's' 'i' 'c' 'a' 'l'
9279 set $Physical = $kgm_strcmp_arg
9280 strcmp_arg_pack64 ' ' 'A' 'd' 'd' 'r' 'e' 's' 's'
9281 set $_Address = $kgm_strcmp_arg
9282 setfindregistrystr $Physical $_Address
9283
9284 _findregistryprop $kgm_registry_entry
9285 if $kgm_registry_value
9286 set $kgm_ioapic_addr = ((OSNumber *) $kgm_registry_value)->value
9287 end
9288 end
9289 set $kgm_ioapic_index_addr = $kgm_ioapic_addr + $_ioapic_index_off
9290 set $kgm_ioapic_data_addr = $kgm_ioapic_addr + $_ioapic_data_off
9291 set $kgm_ioapic_init = 1
9292 end
2d21ac55
A
9293end
9294
b0d623f7
A
9295define _ioapic_addr_value
9296 _ioapic_init
9297 writephysint $kgm_ioapic_index_addr 8 $arg0 $kgm_lcpu_self
9298 if $argc > 1
9299 writephysint $kgm_ioapic_data_addr 32 $arg1 $kgm_lcpu_self
9300 else
9301 readphysint $kgm_ioapic_data_addr 32 $kgm_lcpu_self
9302 set $kgm_ioapic_value = $kgm_readphysint_result
9303 end
2d21ac55
A
9304end
9305
b0d623f7
A
9306define _apic_print
9307 set $value = $arg0
2d21ac55 9308
060df5ea 9309 printf "[VEC=%3d", $value & $_apic_vector_mask
b0d623f7 9310 if $value & $_apic_masked
060df5ea 9311 printf " MASK=yes"
b0d623f7 9312 else
060df5ea 9313 printf " MASK=no "
b0d623f7 9314 end
2d21ac55 9315
b0d623f7 9316 if $value & $_apic_trigger_level
060df5ea 9317 printf " TRIG=level"
b0d623f7 9318 else
060df5ea 9319 printf " TRIG=edge "
b0d623f7 9320 end
2d21ac55 9321
b0d623f7 9322 if $value & $_apic_polarity_high
060df5ea 9323 printf " POL=high"
b0d623f7 9324 else
060df5ea 9325 printf " POL=low "
b0d623f7 9326 end
2d21ac55 9327
b0d623f7 9328 if $value & $_apic_pending
060df5ea 9329 printf " PEND=yes"
b0d623f7 9330 else
060df5ea 9331 printf " PEND=no "
b0d623f7 9332 end
060df5ea
A
9333
9334 if $value & $_apic_timer_periodic
9335 printf " PERIODIC"
9336 end
9337 if $value & $_apic_timer_tsc_deadline
9338 printf " TSC_DEADLINE"
9339 end
9340
9341 printf "]\n"
b0d623f7 9342end
2d21ac55 9343
b0d623f7
A
9344define ioapic_read32
9345 if (($kgm_mtype & $kgm_mtype_x86_mask) != $kgm_mtype_x86_any)
9346 printf "ioapic_read32 not supported on this architecture.\n"
9347 else
9348 _ioapic_addr_value $arg0
9349 printf "IOAPIC[0x%02X]: 0x%08X\n", $arg0, $kgm_ioapic_value
9350 end
9351end
2d21ac55 9352
b0d623f7
A
9353document ioapic_read32
9354Syntax: (gdb) ioapic_read <offset>
9355| Read the IOAPIC register at the offset specified.
9356end
2d21ac55 9357
b0d623f7
A
9358define ioapic_write32
9359 if (($kgm_mtype & $kgm_mtype_x86_mask) != $kgm_mtype_x86_any)
9360 printf "ioapic_write32 not supported on this architecture.\n"
9361 else
9362 _ioapic_addr_value $arg0 $arg1
9363 end
9364end
2d21ac55 9365
b0d623f7
A
9366document ioapic_write32
9367Syntax: (gdb) ioapic_write32 <offset> <value>
9368| Write the IOAPIC register at the offset specified.
9369end
2d21ac55 9370
b0d623f7
A
9371define ioapic_dump
9372 if (($kgm_mtype & $kgm_mtype_x86_mask) != $kgm_mtype_x86_any)
9373 printf "ioapic_dump not supported on this architecture.\n"
9374 else
9375 # id
9376 _ioapic_addr_value $_ioapic_index_id
9377 printf "IOAPIC[0x%02X] ID: 0x%08X\n", $_ioapic_index_id, $kgm_ioapic_value
2d21ac55 9378
b0d623f7
A
9379 # version
9380 _ioapic_addr_value $_ioapic_index_ver
9381 set $maxredir = (($kgm_ioapic_value & 0xFF0000) >> 16) + 1
2d21ac55 9382
b0d623f7
A
9383 printf "IOAPIC[0x%02X] VERSION: 0x%08X [", $_ioapic_index_ver, $kgm_ioapic_value
9384 printf "MAXREDIR=%02d PRQ=%d VERSION=0x%02X]\n", $maxredir, ($kgm_ioapic_value >> 15) & 0x1, $kgm_ioapic_value & 0xFF
9385
9386 # all the redir entries
9387 set $i = 0
9388 while $i < $maxredir
9389 set $addr0 = $_ioapic_index_redir_base + ($i << 1)
9390 set $addr1 = $addr0 + 1
9391 _ioapic_addr_value $addr1
9392 printf "IOAPIC[0x%02X] IOREDIR%02d: 0x%08X", $addr0, $i, $kgm_ioapic_value
9393
9394 _ioapic_addr_value $addr0
9395 printf "%08X ", $kgm_ioapic_value
9396 _apic_print $kgm_ioapic_value
9397 set $i = $i + 1
9398 end
9399 end
9400end
2d21ac55 9401
b0d623f7
A
9402document ioapic_dump
9403Syntax: (gdb) ioapic_dump
9404| Dump all the IOAPIC entries.
9405end
9406
9407
9408set $_lapic_base_addr = 0xFEE00000
9409set $_lapic_id = 0x20
9410set $_lapic_version = 0x30
9411set $_lapic_tpr = 0x80
9412set $_lapic_apr = 0x90
9413set $_lapic_ppr = 0xA0
9414set $_lapic_eoi = 0xB0
9415set $_lapic_ldr = 0xD0
9416set $_lapic_dfr = 0xE0
9417set $_lapic_sivr = 0xF0
9418
9419set $_lapic_isr_size = 0x10
9420set $_lapic_isr_num = 8
9421set $_lapic_isr0 = 0x100
9422set $_lapic_tmr0 = 0x180
9423set $_lapic_irr0 = 0x200
9424
9425set $_lapic_esr = 0x280
9426set $_lapic_esr_register = 0x80
9427set $_lapic_esr_recv_vect = 0x40
9428set $_lapic_esr_send_vect = 0x20
9429
9430set $_lapic_icr0 = 0x300
9431set $_lapic_icr1 = 0x310
9432
9433set $_lapic_lvt_timer = 0x320
9434set $_lapic_lvt_thermal = 0x330
9435set $_lapic_lvt_pmcr = 0x340
9436set $_lapic_lvt_lint0 = 0x350
9437set $_lapic_lvt_lint1 = 0x360
9438set $_lapic_lvt_error = 0x370
9439
9440set $_lapic_icr = 0x380
9441set $_lapic_ccr = 0x390
9442set $_lapic_dcr = 0x3E0
9443
9444set $_apic_cfg_msr = 0x1B
9445set $_apic_cfg_msr_x2EN = 0x00000C00
9446set $_x2apic_enabled = -1
9447
9448# _lapic_addr $offset returns the actual address to use
9449define _lapic_addr
9450 if $_x2apic_enabled < 0
9451 readmsr64int $_apic_cfg_msr $kgm_lcpu_self
9452 if ($kgm_readmsr64int_result & $_apic_cfg_msr_x2EN) == $_apic_cfg_msr_x2EN
9453 set $_x2apic_enabled = 1
9454 else
9455 set $_x2apic_enabled = 0
9456 end
9457 end
9458
9459 if $_x2apic_enabled
9460 # x2APIC addresses are MSRs that use xAPIC offsets that
9461 # are 4-bit shifted
9462 set $kgm_lapic_addr = $arg0 >> 4
9463 else
9464 set $kgm_lapic_addr = $_lapic_base_addr + $arg0
9465 end
2d21ac55
A
9466end
9467
b0d623f7
A
9468# _lapic_addr_value $offset $lcpu
9469define _lapic_addr_value
9470 _lapic_addr $arg0
9471 if $_x2apic_enabled
9472 readmsr64int $kgm_lapic_addr $arg1
9473 set $kgm_lapic_value = $kgm_readmsr64int_result
9474 else
9475 readphysint $kgm_lapic_addr 32 $arg1
9476 set $kgm_lapic_value = $kgm_readphysint_result
9477 end
2d21ac55
A
9478end
9479
b0d623f7
A
9480# lapic_read32 $offset [$lcpu]
9481define lapic_read32
9482 if (($kgm_mtype & $kgm_mtype_x86_mask) != $kgm_mtype_x86_any)
9483 printf "lapic_read32 not supported on this architecture.\n"
9484 else
9485 set $lcpu = $kgm_lcpu_self
9486 if $argc > 1
9487 set $lcpu = $arg1
9488 end
9489 _lapic_addr_value $arg0 $lcpu
9490 printf "LAPIC[0x%03X]: 0x%08X\n", $arg0, $kgm_lapic_value
9491 end
2d21ac55
A
9492end
9493
b0d623f7
A
9494document lapic_read32
9495Syntax: (gdb) apic_read32_cpu <offset> [lcpu (kernel's numbering convention)]
9496| Read the LAPIC register at the offset specified. The CPU can be optionally
9497| specified.
2d21ac55
A
9498end
9499
b0d623f7
A
9500# lapic_write32 $offset $value [$lcpu]
9501define lapic_write32
9502 if (($kgm_mtype & $kgm_mtype_x86_mask) != $kgm_mtype_x86_any)
9503 printf "lapic_write32_cpu not supported on this architecture.\n"
9504 else
9505 set $lcpu = $kgm_lcpu_self
9506 if $argc > 2
9507 set $lcpu = $arg2
9508 end
9509
9510 _lapic_addr $arg0
9511 if $_x2apic_enabled
9512 writemsr64int $kgm_lapic_addr $arg1 $lcpu
9513 else
9514 writephysint $kgm_lapic_addr 32 $arg1 $lcpu
9515 end
9516 end
9517end
9518
9519document lapic_write32
9520Syntax: (gdb) lapic_write32 <offset> <value> [lcpu (kernel's numbering convention)]
9521| Write the LAPIC register at the offset specified. The CPU can be optionally
9522| specified.
2d21ac55
A
9523end
9524
b0d623f7
A
9525# lapic_dump [lcpu]
9526define lapic_dump
9527 if (($kgm_mtype & $kgm_mtype_x86_mask) != $kgm_mtype_x86_any)
9528 printf "lapic_dump not supported on this architecture.\n"
9529 else
9530 set $lcpu = $kgm_lcpu_self
9531 if $argc > 0
9532 set $lcpu = $arg0
9533 end
9534
9535 _lapic_addr_value $_lapic_id $lcpu
9536
9537 # the above also figures out if we're using an xAPIC or an x2APIC
9538 printf "LAPIC operating mode: "
9539 if $_x2apic_enabled
9540 printf " x2APIC\n"
9541 else
9542 printf " xAPIC\n"
9543 end
9544
9545 printf "LAPIC[0x%03X] ID: 0x%08X\n", $_lapic_id, $kgm_lapic_value
9546
9547 _lapic_addr_value $_lapic_version $lcpu
9548 set $lvt_num = ($kgm_lapic_value >> 16) + 1
9549 printf "LAPIC[0x%03X] VERSION: 0x%08X [VERSION=%d MaxLVT=%d]\n", $_lapic_version, $kgm_lapic_value, $kgm_lapic_value & 0xFF, $lvt_num
9550
9551 _lapic_addr_value $_lapic_tpr $lcpu
9552 printf "LAPIC[0x%03X] TASK PRIORITY: 0x%08X\n", $_lapic_tpr, $kgm_lapic_value
9553
9554 _lapic_addr_value $_lapic_ppr $lcpu
9555 printf "LAPIC[0x%03X] PROCESSOR PRIORITY: 0x%08X\n", $_lapic_ppr, $kgm_lapic_value
9556
9557 _lapic_addr_value $_lapic_ldr $lcpu
9558 printf "LAPIC[0x%03X] LOGICAL DEST: 0x%08X\n", $_lapic_ldr, $kgm_lapic_value
9559
9560 _lapic_addr_value $_lapic_dfr $lcpu
9561 printf "LAPIC[0x%03X] DEST FORMAT: 0x%08X\n", $_lapic_dfr, $kgm_lapic_value
9562
9563 _lapic_addr_value $_lapic_sivr $lcpu
9564 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,
9565
9566 set $i = 0
9567 while $i < $_lapic_isr_num
9568 set $addr = $_lapic_isr0 + $i * $_lapic_isr_size
9569 _lapic_addr_value $addr $lcpu
9570 printf "LAPIC[0x%03X] ISR[%03d:%03d]: 0x%08X\n", $addr, 32*($i + 1) - 1, 32*$i, $kgm_lapic_value
9571 set $i = $i + 1
9572 end
9573
9574 set $i = 0
9575 while $i < $_lapic_isr_num
9576 set $addr = $_lapic_tmr0 + $i * $_lapic_isr_size
9577 _lapic_addr_value $addr $lcpu
9578 printf "LAPIC[0x%03X] TMR[%03d:%03d]: 0x%08X\n", $addr, 32*($i + 1) - 1, 32*$i, $kgm_lapic_value
9579 set $i = $i + 1
9580 end
2d21ac55 9581
b0d623f7
A
9582 set $i = 0
9583 while $i < $_lapic_isr_num
9584 set $addr = $_lapic_irr0 + $i * $_lapic_isr_size
9585 _lapic_addr_value $addr $lcpu
9586 printf "LAPIC[0x%03X] IRR[%03d:%03d]: 0x%08X\n", $addr, 32*($i + 1) - 1, 32*$i, $kgm_lapic_value
9587 set $i = $i + 1
9588 end
2d21ac55 9589
b0d623f7
A
9590 _lapic_addr_value $_lapic_esr $lcpu
9591 printf "LAPIC[0x%03X] ERROR STATUS: 0x%08X ", $_lapic_esr, $kgm_lapic_value
9592 if $kgm_lapic_value
9593 printf "["
9594 end
9595 if $kgm_lapic_value & $_lapic_esr_register
9596 printf "Register "
9597 end
9598 if $kgm_lapic_value & $_lapic_esr_recv_vect
9599 printf "Received Vector "
9600 end
9601 if $kgm_lapic_value & $_lapic_esr_send_vect
9602 printf "Send Vector"
9603 end
9604 if $kgm_lapic_value
9605 printf "]"
9606 end
9607 printf "\n"
9608
9609 _lapic_addr_value $_lapic_icr1 $lcpu
9610 printf "LAPIC[0x%03X] Interrupt Command: 0x%08X [DEST=%d]\n", $_lapic_icr0, $kgm_lapic_value, $kgm_lapic_value >> 24
9611 _lapic_addr_value $_lapic_icr0 $lcpu
9612 printf " 0x%08X ", $kgm_lapic_value
9613 _apic_print $kgm_lapic_value
9614
9615 if $lvt_num > 0
9616 _lapic_addr_value $_lapic_lvt_timer $lcpu
9617 printf "LAPIC[0x%03X] LVT Timer: 0x%08X ", $_lapic_lvt_timer, $kgm_lapic_value
9618 _apic_print $kgm_lapic_value
9619 end
2d21ac55 9620
b0d623f7
A
9621 if $lvt_num > 1
9622 _lapic_addr_value $_lapic_lvt_lint0 $lcpu
9623 printf "LAPIC[0x%03X] LVT LINT0: 0x%08X ", $_lapic_lvt_lint0, $kgm_lapic_value
9624 _apic_print $kgm_lapic_value
9625 end
2d21ac55 9626
b0d623f7
A
9627 if $lvt_num > 2
9628 _lapic_addr_value $_lapic_lvt_lint1 $lcpu
9629 printf "LAPIC[0x%03X] LVT LINT1: 0x%08X ", $_lapic_lvt_lint1, $kgm_lapic_value
9630 _apic_print $kgm_lapic_value
9631 end
9632
9633 if $lvt_num > 3
9634 _lapic_addr_value $_lapic_lvt_error $lcpu
9635 printf "LAPIC[0x%03X] LVT Error: 0x%08X ", $_lapic_lvt_error, $kgm_lapic_value
9636 _apic_print $kgm_lapic_value
9637 end
9638
9639 if $lvt_num > 4
9640 _lapic_addr_value $_lapic_lvt_pmcr $lcpu
9641 printf "LAPIC[0x%03X] LVT PerfMon: 0x%08X ", $_lapic_lvt_pmcr, $kgm_lapic_value
9642 _apic_print $kgm_lapic_value
9643 end
9644
9645 if $lvt_num > 5
9646 _lapic_addr_value $_lapic_lvt_thermal $lcpu
9647 printf "LAPIC[0x%03X] LVT Thermal: 0x%08X ", $_lapic_lvt_thermal, $kgm_lapic_value
9648 _apic_print $kgm_lapic_value
9649 end
9650
9651 _lapic_addr_value $_lapic_dcr $lcpu
9652 printf "LAPIC[0x%03X] Timer Divide: 0x%08X [Divide by ", $_lapic_dcr, $kgm_lapic_value
9653 set $kgm_lapic_value = ($kgm_lapic_value & 0x8) >> 1 | $kgm_lapic_value & 0x3
9654 if $kgm_lapic_value == 0x7
9655 printf "1]\n"
9656 else
9657 printf "%d]\n", 2 << $kgm_lapic_value
9658 end
9659
9660 _lapic_addr_value $_lapic_icr $lcpu
9661 printf "LAPIC[0x%03X] Timer Init Count: 0x%08X\n", $_lapic_icr, $kgm_lapic_value
9662
9663 _lapic_addr_value $_lapic_ccr $lcpu
9664 printf "LAPIC[0x%03X] Timer Cur Count: 0x%08X\n", $_lapic_ccr, $kgm_lapic_value
9665 end
2d21ac55
A
9666end
9667
b0d623f7
A
9668document lapic_dump
9669Syntax: (gdb) lapic_dump [lcpu (kernel's numbering convention)]
9670| Dump all the LAPIC entries. The CPU can be optionally specified.
9671end
9672
9673define showknoteheader
9674 printf " knote filter ident kn_ptr status\n"
2d21ac55 9675end
4a3eedf9 9676
b0d623f7
A
9677define showknoteint
9678 set $kgm_knotep = ((struct knote *) $arg0)
9679 printf " "
9680 showptr $kgm_knotep
9681 printf " "
9682 set $kgm_filt = -$kgm_knotep->kn_kevent.filter
9683 if ($kgm_filt == 1)
9684 printf "EVFILT_READ "
4a3eedf9 9685 end
b0d623f7
A
9686 if ($kgm_filt == 2)
9687 printf "EVFILT_WRITE "
4a3eedf9 9688 end
b0d623f7
A
9689 if ($kgm_filt == 3)
9690 printf "EVFILT_AIO "
4a3eedf9 9691 end
b0d623f7
A
9692 if ($kgm_filt == 4)
9693 printf "EVFILT_VNODE "
4a3eedf9 9694 end
b0d623f7
A
9695 if ($kgm_filt == 5)
9696 printf "EVFILT_PROC "
4a3eedf9 9697 end
b0d623f7
A
9698 if ($kgm_filt == 6)
9699 printf "EVFILT_SIGNAL "
4a3eedf9 9700 end
b0d623f7
A
9701 if ($kgm_filt == 7)
9702 printf "EVFILT_TIMER "
4a3eedf9 9703 end
b0d623f7
A
9704 if ($kgm_filt == 8)
9705 printf "EVFILT_MACHPORT"
4a3eedf9 9706 end
b0d623f7
A
9707 if ($kgm_filt == 9)
9708 printf "EVFILT_FS "
9709 end
9710 if ($kgm_filt == 10)
9711 printf "EVFILT_USER "
9712 end
9713 if ($kgm_filt == 11)
9714 printf "EVFILT_SESSION "
9715 end
9716 printf "%7d ", $kgm_knotep->kn_kevent.ident
9717 showptr $kgm_knotep->kn_ptr.p_fp
9718 printf " "
9719 if ($kgm_knotep->kn_status == 0)
9720 printf "-"
4a3eedf9 9721 else
b0d623f7
A
9722 if ($kgm_knotep->kn_status & 0x01)
9723 printf "A"
9724 end
9725 if ($kgm_knotep->kn_status & 0x02)
9726 printf "Q"
9727 end
9728 if ($kgm_knotep->kn_status & 0x04)
9729 printf "Dis"
9730 end
9731 if ($kgm_knotep->kn_status & 0x08)
9732 printf "Dr"
9733 end
9734 if ($kgm_knotep->kn_status & 0x10)
9735 printf "Uw"
9736 end
9737 if ($kgm_knotep->kn_status & 0x20)
9738 printf "Att"
9739 end
9740 if ($kgm_knotep->kn_status & 0x40)
9741 printf "Stq"
9742 end
4a3eedf9 9743 end
b0d623f7 9744 printf "\n"
4a3eedf9
A
9745end
9746
b0d623f7
A
9747define showprocknotes
9748 showknoteheader
9749 set $kgm_fdp = ((proc_t)$arg0)->p_fd
9750 set $kgm_knlist = $kgm_fdp->fd_knlist
9751 set $i = 0
9752 while (($i < $kgm_fdp->fd_knlistsize) && ($kgm_knlist != 0))
9753 set $kgm_kn = ((struct knote *)$kgm_knlist[$i].slh_first)
9754 while ($kgm_kn != 0)
9755 showknoteint $kgm_kn
9756 set $kgm_kn = ((struct knote *)$kgm_kn->kn_link.sle_next)
c910b4d9 9757 end
b0d623f7
A
9758 set $i = $i + 1
9759 end
9760 set $kgm_knhash = $kgm_fdp->fd_knhash
9761 set $i = 0
9762 while (($i < $kgm_fdp->fd_knhashmask + 1) && ($kgm_knhash != 0))
9763 set $kgm_kn = ((struct knote *)$kgm_knhash[$i].slh_first)
9764 while ($kgm_kn != 0)
9765 showknoteint $kgm_kn
9766 set $kgm_kn = ((struct knote *)$kgm_kn->kn_link.sle_next)
9767 end
9768 set $i = $i + 1
9769 end
9770end
c910b4d9 9771
b0d623f7
A
9772define showallknotes
9773 set $kgm_head_taskp = &tasks
9774 set $kgm_taskp = (struct task *)($kgm_head_taskp->next)
9775 while $kgm_taskp != $kgm_head_taskp
9776 showtaskheader
9777 showtaskint $kgm_taskp
9778 showprocknotes $kgm_taskp->bsd_info
9779 set $kgm_taskp = (struct task *)($kgm_taskp->tasks.next)
9780 end
9781end
9782document showprocknotes
9783Syntax: showprocknotes <proc>
9784| Displays filter and status information for every kevent registered for
9785| the process.
9786end
c910b4d9 9787
b0d623f7
A
9788#
9789# Device node related debug macros
9790#
c910b4d9 9791
b0d623f7
A
9792define _showtty
9793 set $kgm_tty = (struct tty *) $arg0
9794 printf "tty struct at "
9795 showptr $kgm_tty
9796 printf "\n"
9797 printf "-last input to raw queue:\n"
9798 p $kgm_tty->t_rawq->c_cs
9799 printf "-last input to canonical queue:\n"
9800 p $kgm_tty->t_canq->c_cs
9801 printf "-last output data:\n"
9802 p $kgm_tty->t_outq->c_cs
9803 printf "state:\n"
9804 if ($kgm_tty->t_state & 0x00000001)
9805 printf " TS_SO_OLOWAT (Wake up when output <= low water)\n"
9806 end
9807 if ($kgm_tty->t_state & 0x00000002)
9808 printf " TS_ASYNC (async I/O mode)\n"
9809 else
9810 printf " - (synchronous I/O mode)\n"
9811 end
9812 if ($kgm_tty->t_state & 0x00000004)
9813 printf " TS_BUSY (Draining output)\n"
9814 end
9815 if ($kgm_tty->t_state & 0x00000008)
9816 printf " TS_CARR_ON (Carrier is present)\n"
9817 else
9818 printf " - (Carrier is NOT present)\n"
9819 end
9820 if ($kgm_tty->t_state & 0x00000010)
9821 printf " TS_FLUSH (Outq has been flushed during DMA)\n"
9822 end
9823 if ($kgm_tty->t_state & 0x00000020)
9824 printf " TS_ISOPEN (Open has completed)\n"
9825 else
9826 printf " - (Open has NOT completed)\n"
9827 end
9828 if ($kgm_tty->t_state & 0x00000040)
9829 printf " TS_TBLOCK (Further input blocked)\n"
9830 end
9831 if ($kgm_tty->t_state & 0x00000080)
9832 printf " TS_TIMEOUT (Wait for output char processing)\n"
9833 end
9834 if ($kgm_tty->t_state & 0x00000100)
9835 printf " TS_TTSTOP (Output paused)\n"
9836 end
9837 if ($kgm_tty->t_state & 0x00000200)
9838 printf " TS_WOPEN (Open in progress)\n"
9839 end
9840 if ($kgm_tty->t_state & 0x00000400)
9841 printf " TS_XCLUDE (Tty requires exclusivity)\n"
9842 end
9843 if ($kgm_tty->t_state & 0x00000800)
9844 printf " TS_BKSL (State for lowercase \\ work)\n"
9845 end
9846 if ($kgm_tty->t_state & 0x00001000)
9847 printf " TS_CNTTB (Counting tab width, ignore FLUSHO)\n"
9848 end
9849 if ($kgm_tty->t_state & 0x00002000)
9850 printf " TS_ERASE (Within a \\.../ for PRTRUB)\n"
9851 end
9852 if ($kgm_tty->t_state & 0x00004000)
9853 printf " TS_LNCH (Next character is literal)\n"
9854 end
9855 if ($kgm_tty->t_state & 0x00008000)
9856 printf " TS_TYPEN (Retyping suspended input (PENDIN))\n"
9857 end
9858 if ($kgm_tty->t_state & 0x00010000)
9859 printf " TS_CAN_BYPASS_L_RINT (Device in "raw" mode)\n"
9860 end
9861 if ($kgm_tty->t_state & 0x00020000)
9862 printf " TS_CONNECTED (Connection open)\n"
9863 else
9864 printf " - (Connection NOT open)\n"
9865 end
9866 if ($kgm_tty->t_state & 0x00040000)
9867 printf " TS_SNOOP (Device is being snooped on)\n"
9868 end
9869 if ($kgm_tty->t_state & 0x80000)
9870 printf " TS_SO_OCOMPLETE (Wake up when output completes)\n"
9871 end
9872 if ($kgm_tty->t_state & 0x00100000)
9873 printf " TS_ZOMBIE (Connection lost)\n"
9874 end
9875 if ($kgm_tty->t_state & 0x00200000)
9876 printf " TS_CAR_OFLOW (For MDMBUF - handle in driver)\n"
9877 end
9878 if ($kgm_tty->t_state & 0x00400000)
9879 printf " TS_CTS_OFLOW (For CCTS_OFLOW - handle in driver)\n"
9880 end
9881 if ($kgm_tty->t_state & 0x00800000)
9882 printf " TS_DSR_OFLOW (For CDSR_OFLOW - handle in driver)\n"
9883 end
9884 # xxx todo: do we care about decoding flags?
9885 printf "flags: 0x%08x\n", $kgm_tty->t_flags
9886 printf "foreground process group: "
9887 showptr $kgm_tty->t_pgrp
9888 printf "\n"
9889 printf "enclosing session: "
9890 showptr $kgm_tty->t_session
9891 printf "\n"
9892 printf "Termios:\n"
9893 # XXX todo: decode these flags, someday
9894 printf " Input flags: 0x%08x\n", $kgm_tty->t_termios.c_iflag
9895 printf " Output flags: 0x%08x\n", $kgm_tty->t_termios.c_oflag
9896 printf " Control flags: 0x%08x\n", $kgm_tty->t_termios.c_cflag
9897 printf " Local flags: 0x%08x\n", $kgm_tty->t_termios.c_lflag
9898 printf " Input speed: %d\n", $kgm_tty->t_termios.c_ispeed
9899 printf " Output speed: %d\n", $kgm_tty->t_termios.c_ospeed
9900 # XXX todo: useful to decode t_winsize? t_iokit? c_cc? anything else?
9901 printf "high watermark: %d bytes\n", $kgm_tty->t_hiwat
9902 printf "low watermark: %d bytes\n", $kgm_tty->t_lowat
9903end
9904
9905define _showwhohas
9906 # _showwhohas <major> <minor>
9907 printf "fd "
9908 printf "fileglob "
9909showptrhdrpad
9910 printf "vnode "
9911showptrhdrpad
9912 printf "process "
9913showptrhdrpad
9914 printf "name\n"
9915
9916 set $kgm_swh_devnode_dev = (((int) $arg0) << 24) | (int) $arg1
9917 # iterate all tasks to iterate all processes to iterate all
9918 # open files in each process to see who has a given major/minor
9919 # device open
9920 set $kgm_taskp = (struct task *)($kgm_head_taskp->next)
9921 while $kgm_taskp != $kgm_head_taskp
9922 set $kgm_procp = (proc_t) $kgm_taskp->bsd_info
9923 set $kgm_spf_filedesc = $kgm_procp->p_fd
9924 set $kgm_spf_last = $kgm_spf_filedesc->fd_lastfile
9925 set $kgm_spf_ofiles = $kgm_spf_filedesc->fd_ofiles
9926 set $kgm_spf_count = 0
9927 while (($kgm_spf_ofiles != 0) && ($kgm_spf_count <= $kgm_spf_last))
9928 # only files currently open
9929 if ($kgm_spf_ofiles[$kgm_spf_count] != 0)
9930 set $kgm_spf_fg = $kgm_spf_ofiles[$kgm_spf_count].f_fglob
9931 if ($kgm_spf_fg->fg_type == 1)
9932 # display fd #, fileglob & vnode address, proc name
9933 set $kgm_swh_m_vnode = (vnode_t) $kgm_spf_fg->fg_data
9934 set $kgm_swh_m_vtype = (enum vtype) $kgm_swh_m_vnode->v_type
9935 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)
9936 printf "%-5d ", $kgm_spf_count
9937 showptr $kgm_spf_fg
9938 printf " "
9939 showptr $kgm_swh_m_vnode
9940 printf " "
9941 showptr $kgm_procp
9942 printf " %s\n", $kgm_procp->p_comm
9943 end
c910b4d9 9944 end
b0d623f7
A
9945 end
9946 set $kgm_spf_count = $kgm_spf_count + 1
c910b4d9
A
9947 end
9948
b0d623f7 9949 set $kgm_taskp = (struct task *)($kgm_taskp->tasks.next)
c910b4d9
A
9950 end
9951end
9952
b0d623f7
A
9953define _showvnodedev_cpty
9954 set $kgm_ptmx_major = (int) $arg0
9955 set $kgm_ptmx_minor = (int) $arg1
9956 set $kgm_ptmx_ioctl = _state.pis_ioctl_list[$kgm_ptmx_minor]
9957 set $kgm_ptmx_ioctl = _state.pis_ioctl_list[$kgm_ptmx_minor]
9958 printf " ptmx_ioctl struct at "
9959 showptr $kgm_ptmx_ioctl
9960 printf "\n"
9961 printf " flags:\n"
9962 if ($kgm_ptmx_ioctl->pt_flags & 0x0008)
9963 printf " PF_PKT (packet mode)\n"
9964 end
9965 if ($kgm_ptmx_ioctl->pt_flags & 0x0010)
9966 printf " PF_STOPPED (user told stopped)\n"
9967 end
9968 if ($kgm_ptmx_ioctl->pt_flags & 0x0020)
9969 printf " PF_REMOTE (remote and flow controlled input)\n"
9970 end
9971 if ($kgm_ptmx_ioctl->pt_flags & 0x0040)
9972 printf " PF_NOSTOP"
9973 end
9974 if ($kgm_ptmx_ioctl->pt_flags & 0x0080)
9975 printf " PF_UCNTL (user control mode)\n"
9976 end
9977 if ($kgm_ptmx_ioctl->pt_flags & 0x0100)
9978 printf " PF_UNLOCKED (slave unlock - master open resets)\n"
9979 end
9980 if ($kgm_ptmx_ioctl->pt_flags & 0x0200)
9981 printf " PF_OPEN_M (master is open)\n"
9982 # XXX we should search for who has the master open, but
9983 # XXX each master gets the same minor, even though it
9984 # XXX gets a different vnode. we chold probably change
9985 # XXX this, but to do it we would need some way of
9986 # XXX expressing the information in the vnode structure
9987 # XXX somewhere. If we *did* change it, it would buy us
9988 # XXX the ability to determine who has the corresponding
9989 # XXX master end of the pty open
9990 else
9991 printf " PF_OPEN_M (master is closed)\n"
9992 end
9993 if ($kgm_ptmx_ioctl->pt_flags & 0x0400)
9994 printf " PF_OPEN_S (slave is open)\n"
9995 printf "---vvvvv--- fds open on this device ---vvvvv---\n"
9996 _showwhohas ($kgm_ptmx_major) ($kgm_ptmx_minor)
9997 printf "---^^^^^--- fds open on this device ---^^^^^---\n"
9998 else
9999 printf " - (slave is closed)\n"
10000 end
10001 printf "TTY Specific Information\n"
10002 _showtty $kgm_ptmx_ioctl->pt_tty
c910b4d9
A
10003end
10004
b0d623f7
A
10005define showvnodedev
10006 if ($argc == 1)
10007 set $kgm_vnode = (vnode_t) $arg0
10008 set $kgm_vtype = (enum vtype) $kgm_vnode->v_type
10009 if (($kgm_vtype == VBLK) || ($kgm_vtype == VCHR))
10010 set $kgm_devnode = (devnode_t *) $kgm_vnode->v_data
10011 set $kgm_devnode_dev = $kgm_devnode->dn_typeinfo.dev
10012 set $kgm_devnode_major = ($kgm_devnode_dev >> 24) & 0xff
10013 set $kgm_devnode_minor = $kgm_devnode_dev & 0x00ffffff
10014
10015 # boilerplate device information for a vnode
10016 printf "Device Info:\n"
10017 printf " vnode: "
10018 showptr $kgm_vnode
10019 printf "\n"
10020 printf " type: "
10021 if ($kgm_vtype == VBLK)
10022 printf "VBLK "
10023 end
10024 if ($kgm_vtype == VCHR)
10025 printf "VCHR"
10026 end
10027 printf "\n"
10028 printf " name: %s\n", $kgm_vnode->v_name
10029 printf " major, minor: %d, %d\n", $kgm_devnode_major, $kgm_devnode_minor
10030 printf " mode 0%o\n", $kgm_devnode->dn_mode
10031 printf " owner (u,g): %d %d", $kgm_devnode->dn_uid, $kgm_devnode->dn_gid
10032 printf "\n"
c910b4d9 10033
b0d623f7
A
10034 # decode device specific data
10035 printf "Device Specific Information: "
10036 if ($kgm_vtype == VBLK)
10037 printf " Sorry, I do not know how to decode block devices yet!\n"
10038 printf " Maybe you can write me!"
10039 end
10040 if ($kgm_vtype == VCHR)
10041 # Device information; this is scanty
10042 # range check
10043 if ($kgm_devnode_major > 42) || ($kgm_devnode_major < 0)
10044 printf "Invalid major #\n"
10045 else
10046 # static assignments in conf
10047 if ($kgm_devnode_major == 0)
10048 printf "Console mux device\n"
10049 else
10050 if ($kgm_devnode_major == 2)
10051 printf "Current tty alias\n"
10052 else
10053 if ($kgm_devnode_major == 3)
10054 printf "NULL device\n"
10055 else
10056 if ($kgm_devnode_major == 4)
10057 printf "Old pty slave\n"
10058 else
10059 if ($kgm_devnode_major == 5)
10060 printf "Old pty master\n"
10061 else
10062 if ($kgm_devnode_major == 6)
10063 printf "Kernel log\n"
10064 else
10065 if ($kgm_devnode_major == 12)
10066 printf "Memory devices\n"
10067 else
10068 # Statically linked dynamic assignments
10069 if cdevsw[$kgm_devnode_major].d_open == ptmx_open
10070 printf "Cloning pty master\n"
10071 _showvnodedev_cpty ($kgm_devnode_major) ($kgm_devnode_minor)
10072 else
10073 if cdevsw[$kgm_devnode_major].d_open == ptsd_open
10074 printf "Cloning pty slave\n"
10075 _showvnodedev_cpty ($kgm_devnode_major) ($kgm_devnode_minor)
10076 else
10077 printf "RESERVED SLOT\n"
10078 end
10079 end
10080 end
10081 end
10082 end
10083 end
10084 end
10085 end
10086 end
c910b4d9 10087 end
c910b4d9 10088 end
b0d623f7
A
10089 else
10090 showptr $kgm_vnode
10091 printf " is not a device\n"
c910b4d9 10092 end
b0d623f7
A
10093 else
10094 printf "| Usage:\n|\n"
10095 help showvnodedev
10096 end
c910b4d9 10097end
b0d623f7
A
10098document showvnodedev
10099Syntax: (gdb) showvnodedev <vnode>
10100| showvnodedev Display information about a device vnode
c910b4d9
A
10101end
10102
b0d623f7
A
10103define showtty
10104 if ($argc == 1)
10105 _showtty $arg0
10106 else
10107 printf "| Usage:\n|\n"
10108 help showtty
10109 end
10110end
10111document showtty
10112Syntax: (gdb) showtty <tty struct>
10113| showtty Display information about a struct tty
10114end
c910b4d9 10115
b0d623f7
A
10116define showeventsourceobject
10117 set $kgm_vt = *((void **) $arg1)
10118 if $kgm_lp64
10119 set $kgm_vt = $kgm_vt - 16
10120 end
10121 pcprint $kgm_vt
10122end
10123document showeventsourceobject
10124Syntax: (gdb) showeventsourceobject <prefix> <object>
10125| Routine to display information about an IOEventSource subclass.
10126end
10127
10128define showworkloopeventsources
10129 set $kgm_eventsource = (struct IOEventSource*)$arg0
10130 while $kgm_eventsource != 0
10131 printf " "
10132 printf "EventSource:\t"
10133 showptr $kgm_eventsource
10134 printf " Description: "
10135 showeventsourceobject _ $kgm_eventsource
10136 printf "\n"
10137 if $kgm_eventsource->action != 0
10138 printf " "
10139 printf "Action: \t"
10140 pcprint $kgm_eventsource->action
10141 printf "\n"
10142 end
10143 if $kgm_eventsource->owner != 0
10144 printf " "
10145 printf "Owner: \t"
10146 showptr $kgm_eventsource->owner
10147 printf " Description: "
10148 showeventsourceobject _ $kgm_eventsource->owner
10149 printf "\n"
10150 end
10151 set $kgm_eventsource = $kgm_eventsource->eventChainNext
10152 printf "\n"
10153 end
10154end
10155document showworkloopeventsources
10156Syntax: (gdb) showworkloopeventsources
10157| Routine to walk an IOEventSource chain associated with an IOWorkLoop and print information
10158| about each event source in the chain.
10159end
10160
10161define showworkloopheader
10162 printf "thread "
10163 showptrhdrpad
10164 printf " workloop "
10165 showptrhdrpad
10166 printf " pri state\tLockGroupName\n"
10167end
10168document showworkloopheader
10169Syntax: (gdb) showworkloopheader
10170| Routine to print out header info about an IOKit workloop.
10171end
10172
10173define showworkloop
10174 set $kgm_workloopthread = (struct thread*)$arg0
10175 set $kgm_workloop = (struct IOWorkLoop*)$arg1
10176 showptr $kgm_workloopthread
10177 printf " "
10178 showptr $kgm_workloop
10179 printf " %3d ", $kgm_workloopthread.sched_pri
10180 set $kgm_state = $kgm_workloopthread.state
10181 if $kgm_state & 0x80
10182 printf "I"
10183 end
10184 if $kgm_state & 0x40
10185 printf "P"
10186 end
10187 if $kgm_state & 0x20
10188 printf "A"
10189 end
10190 if $kgm_state & 0x10
10191 printf "H"
10192 end
10193 if $kgm_state & 0x08
10194 printf "U"
10195 end
10196 if $kgm_state & 0x04
10197 printf "R"
10198 end
10199 if $kgm_state & 0x02
10200 printf "S"
10201 end
10202 if $kgm_state & 0x01
10203 printf "W"
10204 end
10205 printf "\t\t"
10206 set $kgm_gateLock = ( struct _IORecursiveLock *)$kgm_workloop->gateLock
10207 set $kgm_lockGroup = (struct _lck_grp_*)($kgm_gateLock->group)
10208 printf "%s", $kgm_lockGroup->lck_grp_name
10209 printf "\n"
10210 showworkloopeventsources $kgm_workloop->eventChain
10211end
10212document showworkloop
10213Syntax: (gdb) showworkloop <thread> <workloop>
10214| Routine to print out info about an IOKit workloop.
10215end
c910b4d9 10216
b0d623f7
A
10217define showallworkloopthreads
10218 set $kgm_head_taskp = &tasks
10219 set $kgm_taskp = (struct task *)($kgm_head_taskp->next)
10220 set $kgm_head_actp = &($kgm_taskp->threads)
10221 set $kgm_actp = (struct thread *)($kgm_taskp->threads.next)
10222 while $kgm_actp != $kgm_head_actp
10223 if ($kgm_actp->continuation == _ZN10IOWorkLoop10threadMainEv)
10224 showworkloopheader
10225 showworkloop $kgm_actp $kgm_actp->parameter
10226 else
10227 if ($kgm_actp->kernel_stack != 0)
10228 if ($kgm_mtype == $kgm_mtype_x86_64)
10229 #Warning: Grokking stack looking for hopeful workloops until we squirrel some info in thread_t.
10230 set $kgm_workloop = *((struct IOWorkLoop **)($kgm_actp->kernel_stack + kernel_stack_size - 0xB8))
10231 else
10232 if ($kgm_mtype == $kgm_mtype_i386)
10233 set $kgm_workloop = *((struct IOWorkLoop **)($kgm_actp->kernel_stack + kernel_stack_size - 0x3C))
10234 end
10235 end
10236 if ($kgm_workloop != 0)
10237 set $kgm_vt = *((void **) $kgm_workloop)
10238 if $kgm_lp64
10239 set $kgm_vt = $kgm_vt - 16
10240 end
10241 if ($kgm_vt == &_ZTV10IOWorkLoop)
10242 showworkloopheader
10243 showworkloop $kgm_actp $kgm_workloop
c910b4d9 10244 end
c910b4d9
A
10245 end
10246 end
c910b4d9 10247 end
b0d623f7 10248 set $kgm_actp = (struct thread *)($kgm_actp->task_threads.next)
c910b4d9 10249 end
b0d623f7 10250 printf "\n"
c910b4d9 10251end
b0d623f7
A
10252document showallworkloopthreads
10253Syntax: (gdb) showallworkloopthreads
10254| Routine to print out info about all IOKit workloop threads in the system. This macro will find
10255| all IOWorkLoop threads blocked in continuations and on i386 and x86_64 systems will make a
10256| best-effort guess to find any workloops that are actually not blocked in a continuation. For a
10257| complete list, it is best to compare the output of this macro against the output of 'showallstacks'.
c910b4d9 10258end
7e4a7d39 10259
b0d623f7
A
10260define showthreadfortid
10261 set $kgm_id_found = 0
10262
10263 set $kgm_head_taskp = &tasks
10264 set $kgm_taskp = (struct task *)($kgm_head_taskp->next)
10265 while $kgm_taskp != $kgm_head_taskp
10266 set $kgm_head_actp = &($kgm_taskp->threads)
10267 set $kgm_actp = (struct thread *)($kgm_taskp->threads.next)
10268 while $kgm_actp != $kgm_head_actp
10269 set $kgm_thread = *(struct thread *)$kgm_actp
10270 set $kgm_thread_id = $kgm_thread.thread_id
10271 if ($kgm_thread_id == $arg0)
10272 showptr $kgm_actp
10273 printf "\n"
10274 set $kgm_id_found = 1
10275 loop_break
10276 end
10277 set $kgm_actp = (struct thread *)($kgm_actp->task_threads.next)
10278 end
10279 if ($kgm_id_found == 1)
10280 loop_break
10281 end
10282 set $kgm_taskp = (struct task *)($kgm_taskp->tasks.next)
c910b4d9 10283 end
b0d623f7
A
10284 if ($kgm_id_found == 0)
10285 printf "Not a valid thread_id\n"
10286 end
10287end
c910b4d9 10288
b0d623f7
A
10289document showthreadfortid
10290Syntax: showthreadfortid <thread_id>
10291|The thread structure contains a unique thread_id value for each thread.
10292|This command is used to retrieve the address of the thread structure(thread_t)
10293|corresponding to a given thread_id.
10294end
c910b4d9 10295
b0d623f7
A
10296define showtaskbusyports
10297 set $kgm_isp = ((task_t)$arg0)->itk_space
10298 set $kgm_iindex = 0
10299 while ( $kgm_iindex < $kgm_isp->is_table_size )
10300 set $kgm_iep = &($kgm_isp->is_table[$kgm_iindex])
10301 if $kgm_iep->ie_bits & 0x00020000
10302 set $kgm_port = ((ipc_port_t)$kgm_iep->ie_object)
10303 if $kgm_port->ip_messages.data.port.msgcount > 0
10304 showport $kgm_port
c910b4d9 10305 end
c910b4d9 10306 end
b0d623f7
A
10307 set $kgm_iindex = $kgm_iindex + 1
10308 end
10309end
c910b4d9 10310
b0d623f7
A
10311document showtaskbusyports
10312Syntax: showtaskbusyports <task>
10313|Routine to print information about receive rights belonging to this task that
10314|have enqueued messages. This is often a sign of a blocked or hung process.
10315end
c910b4d9 10316
b0d623f7
A
10317define showallbusyports
10318 set $kgm_head_taskp = &tasks
10319 set $kgm_cur_taskp = (struct task *)($kgm_head_taskp->next)
10320 while $kgm_cur_taskp != $kgm_head_taskp
10321 showtaskbusyports $kgm_cur_taskp
10322 set $kgm_cur_taskp = (struct task *)($kgm_cur_taskp->tasks.next)
10323 end
c910b4d9
A
10324end
10325
b0d623f7
A
10326document showallbusyports
10327Syntax: showallbusyports
10328|Routine to print information about all receive rights on the system that
10329|have enqueued messages.
c910b4d9 10330end
b7266188
A
10331
10332define kdp-connect
10333 if $argc > 0
10334 kdp-reattach $arg0
10335 else
10336 printf "Attempting to attach to localhost...\n"
10337 kdp-reattach localhost
10338 end
10339end
10340
10341document kdp-connect
10342Syntax: (gdb) kdpconnect <address-of-remote-host>
10343| Attach to the machine with given hostname or IP address, or 'localhost' if blank
10344end