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