]> git.saurik.com Git - apple/xnu.git/blame - kgmacros
xnu-1228.tar.gz
[apple/xnu.git] / kgmacros
CommitLineData
1c79356b
A
1# Kernel gdb macros
2#
3# These gdb macros should be useful during kernel development in
4# determining what's going on in the kernel.
5#
6# All the convenience variables used by these macros begin with $kgm_
7
0c530ab8
A
8set print asm-demangle on
9set cp-abi gnu-v2
9bccf70c 10
1c79356b
A
11echo Loading Kernel GDB Macros package. Type "help kgm" for more info.\n
12
13define kgm
55e303ae
A
14printf ""
15echo These are the gdb macros for kernel debugging. Type "help kgm" for more info.\n
1c79356b
A
16end
17
18document kgm
19| These are the kernel gdb macros. These gdb macros are intended to be
20| used when debugging a remote kernel via the kdp protocol. Typically, you
21| would connect to your remote target like so:
2d21ac55
A
22| (gdb) target remote-kdp
23| (gdb) attach <name-of-remote-host>
1c79356b
A
24|
25| The following macros are available in this package:
91447636 26| showversion Displays a string describing the remote kernel version
1c79356b 27|
55e303ae
A
28| showalltasks Display a summary listing of all tasks
29| showallthreads Display info about all threads in the system
30| showallstacks Display the stack for each thread in the system
31| showcurrentthreads Display info about the thread running on each cpu
32| showcurrentstacks Display the stack for the thread running on each cpu
1c79356b
A
33| showallvm Display a summary listing of all the vm maps
34| showallvme Display a summary listing of all the vm map entries
35| showallipc Display a summary listing of all the ipc spaces
36| showallrights Display a summary listing of all the ipc rights
37| showallkmods Display a summary listing of all the kernel modules
0c530ab8
A
38|
39| showallclasses Display info about all OSObject subclasses in the system
40| showobject Show info about an OSObject - its vtable ptr and retain count, & more info for simple container classes.
41| showregistry Show info about all registry entries in the current plane
42| showregistryprops Show info about all registry entries in the current plane, and their properties
43| showregistryentry Show info about a registry entry; its properties and descendants in the current plane
44| setregistryplane Set the plane to be used for the iokit registry macros (pass zero for list)
1c79356b 45|
55e303ae
A
46| showtask Display info about the specified task
47| showtaskthreads Display info about the threads in the task
48| showtaskstacks Display the stack for each thread in the task
49| showtaskvm Display info about the specified task's vm_map
50| showtaskvme Display info about the task's vm_map entries
51| showtaskipc Display info about the specified task's ipc space
52| showtaskrights Display info about the task's ipc space entries
1c79356b 53|
55e303ae
A
54| showact Display info about a thread specified by activation
55| showactstack Display the stack for a thread specified by activation
1c79356b 56|
55e303ae 57| showmap Display info about the specified vm_map
1c79356b
A
58| showmapvme Display a summary list of the specified vm_map's entries
59|
55e303ae 60| showipc Display info about the specified ipc space
1c79356b
A
61| showrights Display a summary list of all the rights in an ipc space
62|
55e303ae
A
63| showpid Display info about the process identified by pid
64| showproc Display info about the process identified by proc struct
2d21ac55
A
65| showprocinfo Display detailed info about the process identified by proc struct
66| showprocfiles Given a proc_t pointer, display the list of open file descriptors
67| showproclocks Given a proc_t pointer, display the list of advisory file locks
68| zombproc Print out all procs in the zombie list
69| allproc Print out all process in the system not in the zombie list
70| zombstacks Print out all stacks of tasks that are exiting
71|
72| showinitchild Print out all processes in the system which are children of init process
1c79356b 73|
55e303ae 74| showkmod Display info about a kernel module
1c79356b
A
75| showkmodaddr Given an address, display the kernel module and offset
76|
55e303ae
A
77| dumpcallqueue Dump out all the entries given a queue head
78|
91447636
A
79| showallmtx Display info about mutexes usage
80| showallrwlck Display info about reader/writer locks usage
81|
55e303ae 82| zprint Display info about the memory zones
91447636 83| showioalloc Display info about iokit allocations
55e303ae 84| paniclog Display the panic log info
9bccf70c 85|
55e303ae
A
86| switchtoact Switch to different context specified by activation
87| switchtoctx Switch to different context
91447636
A
88| showuserstack Display numeric backtrace of the user stack for an
89| activation
90|
91| switchtouserthread Switch to the user context of the specified thread
92| resetstacks Return to the original kernel context
93|
9bccf70c 94| resetctx Reset context
55e303ae
A
95| resume_on Resume when detaching from gdb
96| resume_off Don't resume when detaching from gdb
1c79356b 97|
91447636
A
98| sendcore Configure kernel to send a coredump to the specified IP
99| disablecore Configure the kernel to disable coredump transmission
100| switchtocorethread Corefile version of "switchtoact"
101| resetcorectx Corefile version of "resetctx"
0c530ab8
A
102|
103| readphys Reads the specified untranslated address
104| readphys64 Reads the specified untranslated 64-bit address
105|
2d21ac55
A
106| rtentry_showdbg Print the debug information of a route entry
107| rtentry_trash Walk the list of trash route entries
108|
109| mbuf_walkpkt Walk the mbuf packet chain (m_nextpkt)
110| mbuf_walk Walk the mbuf chain (m_next)
111| mbuf_buf2slab Find the slab structure of the corresponding buffer
112| mbuf_buf2mca Find the mcache audit structure of the corresponding mbuf
113| mbuf_showmca Print the contents of an mbuf mcache audit structure
114| mbuf_showactive Print all active/in-use mbuf objects
115| mbuf_showinactive Print all freed/in-cache mbuf objects
116| mbuf_showall Print all mbuf objects
117| mbuf_slabs Print all slabs in the group
118| mbuf_slabstbl Print slabs table
119| mbuf_stat Print extended mbuf allocator statistics
120|
121| mcache_walkobj Walk the mcache object chain (obj_next)
122| mcache_stat Print all mcaches in the system
123| mcache_showcache Display the number of objects in the cache
124|
125| showbootermemorymap Dump phys memory map from EFI
126|
127| systemlog Display the kernel's printf ring buffer
128|
129| showvnodepath Print the path for a vnode
130| showvnodelocks Display list of advisory locks held/blocked on a vnode
131| showallvols Display a summary of mounted volumes
132| showvnode Display info about one vnode
133| showvolvnodes Display info about all vnodes of a given volume
134| showvolbusyvnodes Display info about busy (iocount!=0) vnodes of a given volume
135| showallbusyvnodes Display info about all busy (iocount!=0) vnodes
136| showallvnodes Display info about all vnodes
137| print_vnode Print out the fields of a vnode struct
138| showprocvnodes Print out all the open fds which are vnodes in a process
139| showallprocvnodes Print out all the open fds which are vnodes in any process
140| showmountvnodes Print the vnode list
141| showmountallvnodes Print the vnode inactive list
142| showworkqvnodes Print the vnode worker list
143| shownewvnodes Print the new vnode list
144|
145| ifconfig display ifconfig-like output
146| showifaddrs show the list of addresses for the given ifp
147| showifmultiaddrs show the list of multicast addresses for the given ifp
148|
149| showallpmworkqueues Display info about all IOPMWorkQueue objects
150| showregistrypmstate Display power management state for all IOPower registry entries
151| showioservicepm Display the IOServicePM object
152| showstacksaftertask showallstacks starting after a given task
153| showstacksafterthread showallstacks starting after a given thread
154|
155| showMCAstate Print machine-check register state after MC exception.
156|
157| showallgdbstacks Cause GDB to trace all thread stacks
158| showallgdbcorestacks Corefile equivalent of "showallgdbstacks"
159| kdp-reenter Schedule reentry into the debugger and continue.
160| kdp-reboot Restart remote target
161|
1c79356b
A
162| Type "help <macro>" for more specific help on a particular macro.
163| Type "show user <macro>" to see what the macro is really doing.
164end
165
0c530ab8
A
166# This macro should appear before any symbol references, to facilitate
167# a gdb "source" without a loaded symbol file.
168define showversion
169 printf "%s\n", *(char **)0x501C
170end
171
172document showversion
173Syntax: showversion
174| Read the kernel version string from a fixed address in low
175| memory. Useful if you don't know which kernel is on the other end,
176| and need to find the appropriate symbols. Beware that if you've
177| loaded a symbol file, but aren't connected to a remote target,
178| the version string from the symbol file will be displayed instead.
179| This macro expects to be connected to the remote kernel to function
180| correctly.
181end
182
2d21ac55
A
183set $kgm_mtype = ((struct mach_header)_mh_execute_header).cputype
184
185# This option tells gdb to relax its stack tracing heuristics
186# Useful for debugging across stack switches
187# (to the interrupt stack, for instance). Requires gdb-675 or greater.
188# Don't do this for arm as a workaround to 5486905
189if ($kgm_mtype != 12)
190 set backtrace sanity-checks off
191end
192
0c530ab8
A
193set $kgm_dummy = &proc0
194set $kgm_dummy = &kmod
0c530ab8
A
195
196set $kgm_reg_depth = 0
197set $kgm_reg_plane = (void **) gIOServicePlane
198set $kgm_namekey = (OSSymbol *) 0
199set $kgm_childkey = (OSSymbol *) 0
200
201set $kgm_show_object_addrs = 0
202set $kgm_show_object_retain = 0
203set $kgm_show_props = 0
1c79356b 204
2d21ac55
A
205set $kgm_show_kmod_syms = 0
206
1c79356b
A
207define showkmodheader
208 printf "kmod address size "
209 printf "id refs version name\n"
210end
211
212define showkmodint
213 set $kgm_kmodp = (struct kmod_info *)$arg0
214 printf "0x%08x ", $arg0
215 printf "0x%08x ", $kgm_kmodp->address
216 printf "0x%08x ", $kgm_kmodp->size
217 printf "%3d ", $kgm_kmodp->id
218 printf "%5d ", $kgm_kmodp->reference_count
219 printf "%10s ", &$kgm_kmodp->version
220 printf "%s\n", &$kgm_kmodp->name
221end
222
223set $kgm_kmodmin = 0xffffffff
224set $kgm_fkmodmin = 0x00000000
225set $kgm_kmodmax = 0x00000000
226set $kgm_fkmodmax = 0xffffffff
227set $kgm_pkmod = 0
228set $kgm_pkmodst = 0
229set $kgm_pkmoden = 0
0c530ab8 230define showkmodaddrint
1c79356b
A
231 printf "0x%x" , $arg0
232 if ((unsigned int)$arg0 >= (unsigned int)$kgm_pkmodst) && ((unsigned int)$arg0 <= (unsigned int)$kgm_pkmoden)
233 set $kgm_off = ((unsigned int)$arg0 - (unsigned int)$kgm_pkmodst)
234 printf " <%s + 0x%x>", $kgm_pkmod->name, $kgm_off
235 else
236 if ((unsigned int)$arg0 <= (unsigned int)$kgm_fkmodmax) && ((unsigned int)$arg0 >= (unsigned int)$kgm_fkmodmin)
237 set $kgm_kmodp = (struct kmod_info *)kmod
238 while $kgm_kmodp
239 set $kgm_kmod = *$kgm_kmodp
240 if $kgm_kmod.address && ($kgm_kmod.address < $kgm_kmodmin)
241 set $kgm_kmodmin = $kgm_kmod.address
242 end
243 if ($kgm_kmod.address + $kgm_kmod.size) > $kgm_kmodmax
0c530ab8 244 set $kgm_kmodmax = $kgm_kmod.address + $kgm_kmod.size
1c79356b
A
245 end
246 set $kgm_off = ((unsigned int)$arg0 - (unsigned int)$kgm_kmod.address)
247 if ($kgm_kmod.address <= $arg0) && ($kgm_off <= $kgm_kmod.size)
248 printf " <%s + 0x%x>", $kgm_kmodp->name, $kgm_off
249 set $kgm_pkmod = $kgm_kmodp
250 set $kgm_pkmodst = $kgm_kmod.address
251 set $kgm_pkmoden = $kgm_pkmodst + $kgm_kmod.size
252 set $kgm_kmodp = 0
253 else
254 set $kgm_kmodp = $kgm_kmod.next
255 end
256 end
257 if !$kgm_pkmod
258 set $kgm_fkmodmin = $kgm_kmodmin
259 set $kgm_fkmodmax = $kgm_kmodmax
260 end
261 end
262 end
263end
0c530ab8
A
264
265define showkmodaddr
266 showkmodaddrint $arg0
0c530ab8
A
267end
268
1c79356b 269document showkmodaddr
2d21ac55 270Syntax: (gdb) showkmodaddr <addr>
1c79356b 271| Given an address, print the offset and name for the kmod containing it
1c79356b
A
272end
273
274define showkmod
275 showkmodheader
276 showkmodint $arg0
277end
278document showkmod
2d21ac55 279Syntax: (gdb) showkmod <kmod>
1c79356b 280| Routine to print info about a kernel module
1c79356b
A
281end
282
283define showallkmods
284 showkmodheader
285 set $kgm_kmodp = (struct kmod_info *)kmod
286 while $kgm_kmodp
287 showkmodint $kgm_kmodp
288 set $kgm_kmodp = $kgm_kmodp->next
289 end
290end
291document showallkmods
2d21ac55 292Syntax: (gdb) showallkmods
1c79356b 293| Routine to print a summary listing of all the kernel modules
1c79356b
A
294end
295
296define showactheader
2d21ac55
A
297 printf " thread "
298 printf "processor pri state wait_queue wait_event\n"
1c79356b
A
299end
300
301
302define showactint
91447636
A
303 printf " 0x%08x ", $arg0
304 set $kgm_thread = *(struct thread *)$arg0
2d21ac55 305 printf "0x%08x ", $kgm_thread.last_processor
1c79356b
A
306 printf "%3d ", $kgm_thread.sched_pri
307 set $kgm_state = $kgm_thread.state
308 if $kgm_state & 0x80
309 printf "I"
310 end
311 if $kgm_state & 0x40
312 printf "P"
313 end
314 if $kgm_state & 0x20
315 printf "A"
316 end
317 if $kgm_state & 0x10
318 printf "H"
319 end
320 if $kgm_state & 0x08
321 printf "U"
322 end
323 if $kgm_state & 0x04
324 printf "R"
325 end
326 if $kgm_state & 0x02
327 printf "S"
328 end
329 if $kgm_state & 0x01
330 printf "W\t"
331 printf "0x%08x ", $kgm_thread.wait_queue
0c530ab8 332 if (((unsigned)$kgm_thread.wait_event > (unsigned)sectPRELINKB) \
2d21ac55 333 && ($arg1 != 2) && ($kgm_show_kmod_syms == 0))
0c530ab8
A
334 showkmodaddr $kgm_thread.wait_event
335 else
91447636
A
336 output /a (unsigned) $kgm_thread.wait_event
337 end
2d21ac55
A
338 if ($kgm_thread.uthread != 0)
339 set $kgm_uthread = (struct uthread *)$kgm_thread.uthread
340 if ($kgm_uthread->uu_wmesg != 0)
341 printf " \"%s\"", $kgm_uthread->uu_wmesg
342 end
343 end
1c79356b
A
344 end
345 if $arg1 != 0
346 if ($kgm_thread.kernel_stack != 0)
55e303ae
A
347 if ($kgm_thread.reserved_stack != 0)
348 printf "\n\t\treserved_stack=0x%08x", $kgm_thread.reserved_stack
1c79356b
A
349 end
350 printf "\n\t\tkernel_stack=0x%08x", $kgm_thread.kernel_stack
91447636
A
351 if ($kgm_mtype == 18)
352 set $mysp = $kgm_thread.machine.pcb->save_r1
2d21ac55
A
353 end
354 if ($kgm_mtype == 7)
0c530ab8 355 set $kgm_statep = (struct x86_kernel_state32 *) \
91447636 356 ($kgm_thread->kernel_stack + 0x4000 \
0c530ab8 357 - sizeof(struct x86_kernel_state32))
55e303ae
A
358 set $mysp = $kgm_statep->k_ebp
359 end
2d21ac55
A
360 if ($kgm_mtype == 12)
361 if ($arg0 == $r9)
362 set $mysp = $r7
363 else
364 set $kgm_statep = (struct arm_saved_state *)$kgm_thread.machine.kstackptr
365 set $mysp = $kgm_statep->r[7]
366 end
367 end
0c530ab8 368 set $prevsp = $mysp - 16
1c79356b 369 printf "\n\t\tstacktop=0x%08x", $mysp
91447636
A
370 if ($kgm_mtype == 18)
371 set $stkmask = 0xf
91447636
A
372 else
373 set $stkmask = 0x3
91447636 374 end
0c530ab8 375 set $kgm_return = 0
91447636 376 while ($mysp != 0) && (($mysp & $stkmask) == 0) \
0c530ab8
A
377 && ($mysp != $prevsp) \
378 && ((((unsigned) $mysp ^ (unsigned) $prevsp) < 0x2000) \
379 || (((unsigned)$mysp < ((unsigned) ($kgm_thread->kernel_stack+0x4000))) \
380 && ((unsigned)$mysp > (unsigned) ($kgm_thread->kernel_stack))))
91447636
A
381 printf "\n\t\t0x%08x ", $mysp
382 if ($kgm_mtype == 18)
383 set $kgm_return = *($mysp + 8)
2d21ac55
A
384 end
385 if ($kgm_mtype == 7)
386 set $kgm_return = *($mysp + 4)
387 end
388 if ($kgm_mtype == 12)
91447636
A
389 set $kgm_return = *($mysp + 4)
390 end
2d21ac55
A
391 if (((unsigned) $kgm_return > (unsigned) sectPRELINKB) \
392 && ($kgm_show_kmod_syms == 0))
393 showkmodaddr $kgm_return
394 else
395 output /a (unsigned) $kgm_return
396 end
91447636
A
397 set $prevsp = $mysp
398 set $mysp = * $mysp
1c79356b 399 end
0c530ab8 400 set $kgm_return = 0
1c79356b
A
401 printf "\n\t\tstackbottom=0x%08x", $prevsp
402 else
403 printf "\n\t\t\tcontinuation="
91447636 404 output /a (unsigned) $kgm_thread.continuation
1c79356b
A
405 end
406 printf "\n"
407 else
408 printf "\n"
409 end
1c79356b
A
410end
411
412define showact
413 showactheader
414 showactint $arg0 0
415end
416document showact
2d21ac55 417Syntax: (gdb) showact <activation>
55e303ae 418| Routine to print out the state of a specific thread.
1c79356b
A
419end
420
421
422define showactstack
423 showactheader
424 showactint $arg0 1
425end
426document showactstack
2d21ac55 427Syntax: (gdb) showactstack <activation>
55e303ae 428| Routine to print out the stack of a specific thread.
1c79356b
A
429end
430
431
55e303ae 432define showallthreads
2d21ac55 433 set $kgm_head_taskp = &tasks
9bccf70c 434 set $kgm_taskp = (struct task *)($kgm_head_taskp->next)
1c79356b
A
435 while $kgm_taskp != $kgm_head_taskp
436 showtaskheader
437 showtaskint $kgm_taskp
438 showactheader
55e303ae
A
439 set $kgm_head_actp = &($kgm_taskp->threads)
440 set $kgm_actp = (struct thread *)($kgm_taskp->threads.next)
1c79356b
A
441 while $kgm_actp != $kgm_head_actp
442 showactint $kgm_actp 0
55e303ae 443 set $kgm_actp = (struct thread *)($kgm_actp->task_threads.next)
1c79356b
A
444 end
445 printf "\n"
2d21ac55 446 set $kgm_taskp = (struct task *)($kgm_taskp->tasks.next)
1c79356b
A
447 end
448end
55e303ae 449document showallthreads
2d21ac55 450Syntax: (gdb) showallthreads
55e303ae 451| Routine to print out info about all threads in the system.
55e303ae
A
452end
453
454define showcurrentthreads
2d21ac55 455set $kgm_prp = (struct processor *)processor_list
91447636
A
456 while $kgm_prp != 0
457 if ($kgm_prp)->active_thread != 0
458 set $kgm_actp = ($kgm_prp)->active_thread
55e303ae
A
459 showtaskheader
460 showtaskint ($kgm_actp)->task
461 showactheader
462 showactint $kgm_actp 0
463 printf "\n"
464 end
91447636 465 set $kgm_prp = ($kgm_prp)->processor_list
55e303ae
A
466 end
467end
468document showcurrentthreads
2d21ac55 469Syntax: (gdb) showcurrentthreads
55e303ae 470| Routine to print out info about the thread running on each cpu.
1c79356b
A
471end
472
0c530ab8 473set $decode_wait_events = 0
1c79356b 474define showallstacks
2d21ac55 475 set $kgm_head_taskp = &tasks
9bccf70c 476 set $kgm_taskp = (struct task *)($kgm_head_taskp->next)
1c79356b
A
477 while $kgm_taskp != $kgm_head_taskp
478 showtaskheader
479 showtaskint $kgm_taskp
55e303ae
A
480 set $kgm_head_actp = &($kgm_taskp->threads)
481 set $kgm_actp = (struct thread *)($kgm_taskp->threads.next)
1c79356b
A
482 while $kgm_actp != $kgm_head_actp
483 showactheader
0c530ab8
A
484 if ($decode_wait_events > 0)
485 showactint $kgm_actp 1
486 else
487 showactint $kgm_actp 2
488 end
55e303ae 489 set $kgm_actp = (struct thread *)($kgm_actp->task_threads.next)
1c79356b
A
490 end
491 printf "\n"
2d21ac55 492 set $kgm_taskp = (struct task *)($kgm_taskp->tasks.next)
1c79356b
A
493 end
494end
0c530ab8 495
1c79356b 496document showallstacks
2d21ac55 497Syntax: (gdb) showallstacks
55e303ae 498| Routine to print out the stack for each thread in the system.
0c530ab8
A
499| If the variable $decode_wait_events is non-zero, the routine attempts to
500| interpret thread wait_events as kernel module offsets, which can add to
501| processing time.
1c79356b
A
502end
503
55e303ae 504define showcurrentstacks
91447636
A
505set $kgm_prp = processor_list
506 while $kgm_prp != 0
507 if ($kgm_prp)->active_thread != 0
508 set $kgm_actp = ($kgm_prp)->active_thread
55e303ae
A
509 showtaskheader
510 showtaskint ($kgm_actp)->task
511 showactheader
512 showactint $kgm_actp 1
513 printf "\n"
514 end
91447636 515 set $kgm_prp = ($kgm_prp)->processor_list
55e303ae
A
516 end
517end
0c530ab8 518
55e303ae 519document showcurrentstacks
2d21ac55 520Syntax: (gdb) showcurrentstacks
55e303ae 521| Routine to print out the thread running on each cpu (incl. its stack)
55e303ae
A
522end
523
9bccf70c
A
524define showwaiterheader
525 printf "waiters activation "
526 printf "thread pri state wait_queue wait_event\n"
527end
528
529define showwaitqwaiters
530 set $kgm_w_waitqp = (struct wait_queue *)$arg0
531 set $kgm_w_linksp = &($kgm_w_waitqp->wq_queue)
532 set $kgm_w_wqe = (struct wait_queue_element *)$kgm_w_linksp->next
533 set $kgm_w_found = 0
534 while ( (queue_entry_t)$kgm_w_wqe != (queue_entry_t)$kgm_w_linksp)
535 if ($kgm_w_wqe->wqe_type != &_wait_queue_link)
536 if !$kgm_w_found
537 set $kgm_w_found = 1
538 showwaiterheader
539 end
55e303ae 540 set $kgm_w_shuttle = (struct thread *)$kgm_w_wqe
91447636 541 showactint $kgm_w_shuttle 0
9bccf70c
A
542 end
543 set $kgm_w_wqe = (struct wait_queue_element *)$kgm_w_wqe->wqe_links.next
544 end
545end
546
547define showwaitqwaitercount
548 set $kgm_wc_waitqp = (struct wait_queue *)$arg0
549 set $kgm_wc_linksp = &($kgm_wc_waitqp->wq_queue)
550 set $kgm_wc_wqe = (struct wait_queue_element *)$kgm_wc_linksp->next
551 set $kgm_wc_count = 0
552 while ( (queue_entry_t)$kgm_wc_wqe != (queue_entry_t)$kgm_wc_linksp)
553 if ($kgm_wc_wqe->wqe_type != &_wait_queue_link)
554 set $kgm_wc_count = $kgm_wc_count + 1
555 end
556 set $kgm_wc_wqe = (struct wait_queue_element *)$kgm_wc_wqe->wqe_links.next
557 end
558 printf "0x%08x ", $kgm_wc_count
559end
560
1c79356b 561define showwaitqmembercount
9bccf70c
A
562 set $kgm_mc_waitqsetp = (struct wait_queue_set *)$arg0
563 set $kgm_mc_setlinksp = &($kgm_mc_waitqsetp->wqs_setlinks)
564 set $kgm_mc_wql = (struct wait_queue_link *)$kgm_mc_setlinksp->next
565 set $kgm_mc_count = 0
566 while ( (queue_entry_t)$kgm_mc_wql != (queue_entry_t)$kgm_mc_setlinksp)
567 set $kgm_mc_count = $kgm_mc_count + 1
568 set $kgm_mc_wql = (struct wait_queue_link *)$kgm_mc_wql->wql_setlinks.next
1c79356b 569 end
9bccf70c 570 printf "0x%08x ", $kgm_mc_count
1c79356b
A
571end
572
573
9bccf70c
A
574define showwaitqmemberheader
575 printf "set-members wait_queue interlock "
576 printf "pol type member_cnt waiter_cnt\n"
577end
578
1c79356b 579define showwaitqmemberint
9bccf70c
A
580 set $kgm_m_waitqp = (struct wait_queue *)$arg0
581 printf " 0x%08x ", $kgm_m_waitqp
582 printf "0x%08x ", $kgm_m_waitqp->wq_interlock.lock_data
583 if ($kgm_m_waitqp->wq_fifo)
584 printf "Fifo "
1c79356b 585 else
9bccf70c 586 printf "Prio "
1c79356b 587 end
9bccf70c
A
588 if ($kgm_m_waitqp->wq_type == 0xf1d1)
589 printf "Set "
590 showwaitqmembercount $kgm_m_waitqp
1c79356b 591 else
9bccf70c 592 printf "Que 0x00000000 "
1c79356b 593 end
9bccf70c 594 showwaitqwaitercount $kgm_m_waitqp
1c79356b
A
595 printf "\n"
596end
597
598
9bccf70c
A
599define showwaitqmemberofheader
600 printf "member-of wait_queue interlock "
601 printf "pol type member_cnt waiter_cnt\n"
602end
603
604define showwaitqmemberof
605 set $kgm_mo_waitqp = (struct wait_queue *)$arg0
606 set $kgm_mo_linksp = &($kgm_mo_waitqp->wq_queue)
607 set $kgm_mo_wqe = (struct wait_queue_element *)$kgm_mo_linksp->next
608 set $kgm_mo_found = 0
609 while ( (queue_entry_t)$kgm_mo_wqe != (queue_entry_t)$kgm_mo_linksp)
610 if ($kgm_mo_wqe->wqe_type == &_wait_queue_link)
611 if !$kgm_mo_found
612 set $kgm_mo_found = 1
613 showwaitqmemberofheader
614 end
615 set $kgm_mo_wqlp = (struct wait_queue_link *)$kgm_mo_wqe
616 set $kgm_mo_wqsetp = (struct wait_queue *)($kgm_mo_wqlp->wql_setqueue)
617 showwaitqmemberint $kgm_mo_wqsetp
618 end
619 set $kgm_mo_wqe = (struct wait_queue_element *)$kgm_mo_wqe->wqe_links.next
620 end
621end
622
1c79356b 623define showwaitqmembers
9bccf70c
A
624 set $kgm_ms_waitqsetp = (struct wait_queue_set *)$arg0
625 set $kgm_ms_setlinksp = &($kgm_ms_waitqsetp->wqs_setlinks)
626 set $kgm_ms_wql = (struct wait_queue_link *)$kgm_ms_setlinksp->next
627 set $kgm_ms_found = 0
628 while ( (queue_entry_t)$kgm_ms_wql != (queue_entry_t)$kgm_ms_setlinksp)
629 set $kgm_ms_waitqp = $kgm_ms_wql->wql_element.wqe_queue
630 if !$kgm_ms_found
1c79356b 631 showwaitqmemberheader
9bccf70c 632 set $kgm_ms_found = 1
1c79356b 633 end
9bccf70c
A
634 showwaitqmemberint $kgm_ms_waitqp
635 set $kgm_ms_wql = (struct wait_queue_link *)$kgm_ms_wql->wql_setlinks.next
1c79356b
A
636 end
637end
638
9bccf70c
A
639define showwaitqheader
640 printf "wait_queue ref_count interlock "
641 printf "pol type member_cnt waiter_cnt\n"
642end
643
644define showwaitqint
645 set $kgm_waitqp = (struct wait_queue *)$arg0
646 printf "0x%08x ", $kgm_waitqp
647 if ($kgm_waitqp->wq_type == 0xf1d1)
648 printf "0x%08x ", ((struct wait_queue_set *)$kgm_waitqp)->wqs_refcount
649 else
650 printf "0x00000000 "
651 end
652 printf "0x%08x ", $kgm_waitqp->wq_interlock.lock_data
653 if ($kgm_waitqp->wq_fifo)
654 printf "Fifo "
655 else
656 printf "Prio "
657 end
658 if ($kgm_waitqp->wq_type == 0xf1d1)
659 printf "Set "
660 showwaitqmembercount $kgm_waitqp
661 else
662 printf "Que 0x00000000 "
663 end
664 showwaitqwaitercount $kgm_waitqp
665 printf "\n"
666end
667
1c79356b 668define showwaitq
9bccf70c 669 set $kgm_waitq1p = (wait_queue_t)$arg0
1c79356b 670 showwaitqheader
9bccf70c
A
671 showwaitqint $kgm_waitq1p
672 if ($kgm_waitq1p->wq_type == 0xf1d1)
673 showwaitqmembers $kgm_waitq1p
674 else
675 showwaitqmemberof $kgm_waitq1p
1c79356b 676 end
9bccf70c 677 showwaitqwaiters $kgm_waitq1p
1c79356b
A
678end
679
680define showmapheader
681 printf "vm_map pmap vm_size "
682 printf "#ents rpage hint first_free\n"
683end
684
685define showvmeheader
91447636
A
686 printf " entry start "
687 printf " prot #page object offset\n"
1c79356b
A
688end
689
690define showvmint
691 set $kgm_mapp = (vm_map_t)$arg0
692 set $kgm_map = *$kgm_mapp
693 printf "0x%08x ", $arg0
694 printf "0x%08x ", $kgm_map.pmap
695 printf "0x%08x ", $kgm_map.size
696 printf "%3d ", $kgm_map.hdr.nentries
91447636
A
697 if $kgm_map.pmap
698 printf "%5d ", $kgm_map.pmap->stats.resident_count
699 else
700 printf "<n/a> "
701 end
1c79356b
A
702 printf "0x%08x ", $kgm_map.hint
703 printf "0x%08x\n", $kgm_map.first_free
704 if $arg1 != 0
705 showvmeheader
706 set $kgm_head_vmep = &($kgm_mapp->hdr.links)
707 set $kgm_vmep = $kgm_map.hdr.links.next
708 while (($kgm_vmep != 0) && ($kgm_vmep != $kgm_head_vmep))
709 set $kgm_vme = *$kgm_vmep
91447636
A
710 printf " 0x%08x ", $kgm_vmep
711 printf "0x%016llx ", $kgm_vme.links.start
1c79356b
A
712 printf "%1x", $kgm_vme.protection
713 printf "%1x", $kgm_vme.max_protection
714 if $kgm_vme.inheritance == 0x0
715 printf "S"
716 end
717 if $kgm_vme.inheritance == 0x1
718 printf "C"
719 end
720 if $kgm_vme.inheritance == 0x2
721 printf "-"
722 end
723 if $kgm_vme.inheritance == 0x3
724 printf "D"
725 end
726 if $kgm_vme.is_sub_map
727 printf "s "
728 else
729 if $kgm_vme.needs_copy
730 printf "n "
731 else
732 printf " "
733 end
734 end
735 printf "%5d ",($kgm_vme.links.end - $kgm_vme.links.start) >> 12
736 printf "0x%08x ", $kgm_vme.object.vm_object
91447636 737 printf "0x%016llx\n", $kgm_vme.offset
1c79356b
A
738 set $kgm_vmep = $kgm_vme.links.next
739 end
740 end
741 printf "\n"
742end
743
744
745define showmapvme
746 showmapheader
747 showvmint $arg0 1
748end
749document showmapvme
2d21ac55 750Syntax: (gdb) showmapvme <vm_map>
1c79356b 751| Routine to print out a summary listing of all the entries in a vm_map
1c79356b
A
752end
753
754
755define showmap
756 showmapheader
757 showvmint $arg0 0
758end
759document showmap
2d21ac55 760Syntax: (gdb) showmap <vm_map>
55e303ae 761| Routine to print out info about the specified vm_map
1c79356b
A
762end
763
764define showallvm
2d21ac55 765 set $kgm_head_taskp = &tasks
9bccf70c 766 set $kgm_taskp = (struct task *)($kgm_head_taskp->next)
1c79356b
A
767 while $kgm_taskp != $kgm_head_taskp
768 showtaskheader
769 showmapheader
770 showtaskint $kgm_taskp
771 showvmint $kgm_taskp->map 0
2d21ac55 772 set $kgm_taskp = (struct task *)($kgm_taskp->tasks.next)
1c79356b
A
773 end
774end
775document showallvm
2d21ac55 776Syntax: (gdb) showallvm
1c79356b 777| Routine to print a summary listing of all the vm maps
1c79356b
A
778end
779
780
781define showallvme
2d21ac55 782 set $kgm_head_taskp = &tasks
9bccf70c 783 set $kgm_taskp = (struct task *)($kgm_head_taskp->next)
1c79356b
A
784 while $kgm_taskp != $kgm_head_taskp
785 showtaskheader
786 showmapheader
787 showtaskint $kgm_taskp
788 showvmint $kgm_taskp->map 1
2d21ac55 789 set $kgm_taskp = (struct task *)($kgm_taskp->tasks.next)
1c79356b
A
790 end
791end
792document showallvme
2d21ac55 793Syntax: (gdb) showallvme
1c79356b 794| Routine to print a summary listing of all the vm map entries
1c79356b
A
795end
796
797
798define showipcheader
799 printf "ipc_space is_table table_next "
800 printf "flags tsize splaytree splaybase\n"
801end
802
803define showipceheader
804 printf " name object "
805 printf "rite urefs destname destination\n"
806end
807
808define showipceint
809 set $kgm_ie = *(ipc_entry_t)$arg0
810 printf " 0x%08x ", $arg1
811 printf "0x%08x ", $kgm_ie.ie_object
812 if $kgm_ie.ie_bits & 0x00100000
813 printf "Dead "
814 printf "%5d\n", $kgm_ie.ie_bits & 0xffff
815 else
816 if $kgm_ie.ie_bits & 0x00080000
817 printf "SET "
818 printf "%5d\n", $kgm_ie.ie_bits & 0xffff
819 else
820 if $kgm_ie.ie_bits & 0x00010000
821 if $kgm_ie.ie_bits & 0x00020000
822 printf " SR"
823 else
824 printf " S"
825 end
826 else
827 if $kgm_ie.ie_bits & 0x00020000
828 printf " R"
829 end
830 end
831 if $kgm_ie.ie_bits & 0x00040000
832 printf " O"
833 end
834 if $kgm_ie.index.request
835 printf "n"
836 else
837 printf " "
838 end
839 if $kgm_ie.ie_bits & 0x00800000
840 printf "c"
841 else
842 printf " "
843 end
844 printf "%5d ", $kgm_ie.ie_bits & 0xffff
845 showportdest $kgm_ie.ie_object
846 end
847 end
848end
849
850define showipcint
851 set $kgm_isp = (ipc_space_t)$arg0
852 set $kgm_is = *$kgm_isp
853 printf "0x%08x ", $arg0
854 printf "0x%08x ", $kgm_is.is_table
855 printf "0x%08x ", $kgm_is.is_table_next
856 if $kgm_is.is_growing != 0
857 printf "G"
858 else
859 printf " "
860 end
861 if $kgm_is.is_fast != 0
862 printf "F"
863 else
864 printf " "
865 end
866 if $kgm_is.is_active != 0
867 printf "A "
868 else
869 printf " "
870 end
871 printf "%5d ", $kgm_is.is_table_size
872 printf "0x%08x ", $kgm_is.is_tree_total
873 printf "0x%08x\n", &$kgm_isp->is_tree
874 if $arg1 != 0
875 showipceheader
876 set $kgm_iindex = 0
877 set $kgm_iep = $kgm_is.is_table
878 set $kgm_destspacep = (ipc_space_t)0
879 while ( $kgm_iindex < $kgm_is.is_table_size )
880 set $kgm_ie = *$kgm_iep
881 if $kgm_ie.ie_bits & 0x001f0000
882 set $kgm_name = (($kgm_iindex << 8)|($kgm_ie.ie_bits >> 24))
883 showipceint $kgm_iep $kgm_name
884 end
885 set $kgm_iindex = $kgm_iindex + 1
886 set $kgm_iep = &($kgm_is.is_table[$kgm_iindex])
887 end
888 if $kgm_is.is_tree_total
889 printf "Still need to write tree traversal\n"
890 end
891 end
892 printf "\n"
893end
894
895
896define showipc
897 set $kgm_isp = (ipc_space_t)$arg0
898 showipcheader
899 showipcint $kgm_isp 0
900end
901document showipc
2d21ac55 902Syntax: (gdb) showipc <ipc_space>
1c79356b 903| Routine to print the status of the specified ipc space
1c79356b
A
904end
905
906define showrights
907 set $kgm_isp = (ipc_space_t)$arg0
908 showipcheader
909 showipcint $kgm_isp 1
910end
911document showrights
2d21ac55 912Syntax: (gdb) showrights <ipc_space>
1c79356b 913| Routine to print a summary list of all the rights in a specified ipc space
1c79356b
A
914end
915
916
917define showtaskipc
918 set $kgm_taskp = (task_t)$arg0
919 showtaskheader
920 showipcheader
921 showtaskint $kgm_taskp
922 showipcint $kgm_taskp->itk_space 0
923end
924document showtaskipc
2d21ac55 925Syntax: (gdb) showtaskipc <task>
55e303ae 926| Routine to print info about the ipc space for a task
1c79356b
A
927end
928
929
930define showtaskrights
931 set $kgm_taskp = (task_t)$arg0
932 showtaskheader
933 showipcheader
934 showtaskint $kgm_taskp
935 showipcint $kgm_taskp->itk_space 1
936end
937document showtaskrights
2d21ac55 938Syntax: (gdb) showtaskrights <task>
55e303ae 939| Routine to print info about the ipc rights for a task
1c79356b
A
940end
941
942define showallipc
2d21ac55 943 set $kgm_head_taskp = &tasks
91447636
A
944 set $kgm_cur_taskp = (struct task *)($kgm_head_taskp->next)
945 while $kgm_cur_taskp != $kgm_head_taskp
1c79356b
A
946 showtaskheader
947 showipcheader
91447636
A
948 showtaskint $kgm_cur_taskp
949 showipcint $kgm_cur_taskp->itk_space 0
2d21ac55 950 set $kgm_cur_taskp = (struct task *)($kgm_cur_taskp->tasks.next)
1c79356b
A
951 end
952end
953document showallipc
2d21ac55 954Syntax: (gdb) showallipc
1c79356b 955| Routine to print a summary listing of all the ipc spaces
1c79356b
A
956end
957
958
959define showallrights
2d21ac55 960 set $kgm_head_taskp = &tasks
91447636
A
961 set $kgm_cur_taskp = (struct task *)($kgm_head_taskp->next)
962 while $kgm_cur_taskp != $kgm_head_taskp
1c79356b
A
963 showtaskheader
964 showipcheader
91447636
A
965 showtaskint $kgm_cur_taskp
966 showipcint $kgm_cur_taskp->itk_space 1
2d21ac55 967 set $kgm_cur_taskp = (struct task *)($kgm_cur_taskp->tasks.next)
1c79356b
A
968 end
969end
970document showallrights
2d21ac55 971Syntax: (gdb) showallrights
1c79356b 972| Routine to print a summary listing of all the ipc rights
1c79356b
A
973end
974
975
976define showtaskvm
977 set $kgm_taskp = (task_t)$arg0
978 showtaskheader
979 showmapheader
980 showtaskint $kgm_taskp
981 showvmint $kgm_taskp->map 0
982end
983document showtaskvm
2d21ac55 984Syntax: (gdb) showtaskvm <task>
55e303ae 985| Routine to print out info about a task's vm_map
1c79356b
A
986end
987
988define showtaskvme
989 set $kgm_taskp = (task_t)$arg0
990 showtaskheader
991 showmapheader
992 showtaskint $kgm_taskp
993 showvmint $kgm_taskp->map 1
994end
995document showtaskvme
2d21ac55 996Syntax: (gdb) showtaskvme <task>
55e303ae 997| Routine to print out info about a task's vm_map_entries
1c79356b
A
998end
999
1000
1001define showtaskheader
1002 printf "task vm_map ipc_space #acts "
1003 showprocheader
1004end
1005
1006
1007define showtaskint
9bccf70c 1008 set $kgm_task = *(struct task *)$arg0
1c79356b
A
1009 printf "0x%08x ", $arg0
1010 printf "0x%08x ", $kgm_task.map
1011 printf "0x%08x ", $kgm_task.itk_space
55e303ae 1012 printf "%3d ", $kgm_task.thread_count
1c79356b
A
1013 showprocint $kgm_task.bsd_info
1014end
1015
1016define showtask
1017 showtaskheader
1018 showtaskint $arg0
1019end
1020document showtask
2d21ac55 1021Syntax (gdb) showtask <task>
1c79356b 1022| Routine to print out info about a task.
1c79356b
A
1023end
1024
1025
55e303ae 1026define showtaskthreads
1c79356b 1027 showtaskheader
9bccf70c 1028 set $kgm_taskp = (struct task *)$arg0
1c79356b
A
1029 showtaskint $kgm_taskp
1030 showactheader
55e303ae
A
1031 set $kgm_head_actp = &($kgm_taskp->threads)
1032 set $kgm_actp = (struct thread *)($kgm_taskp->threads.next)
1c79356b
A
1033 while $kgm_actp != $kgm_head_actp
1034 showactint $kgm_actp 0
55e303ae 1035 set $kgm_actp = (struct thread *)($kgm_actp->task_threads.next)
1c79356b
A
1036 end
1037end
55e303ae 1038document showtaskthreads
2d21ac55 1039Syntax: (gdb) showtaskthreads <task>
55e303ae 1040| Routine to print info about the threads in a task.
1c79356b
A
1041end
1042
1043
1044define showtaskstacks
1045 showtaskheader
9bccf70c 1046 set $kgm_taskp = (struct task *)$arg0
1c79356b 1047 showtaskint $kgm_taskp
55e303ae
A
1048 set $kgm_head_actp = &($kgm_taskp->threads)
1049 set $kgm_actp = (struct thread *)($kgm_taskp->threads.next)
1c79356b
A
1050 while $kgm_actp != $kgm_head_actp
1051 showactheader
1052 showactint $kgm_actp 1
55e303ae 1053 set $kgm_actp = (struct thread *)($kgm_actp->task_threads.next)
1c79356b
A
1054 end
1055end
1056document showtaskstacks
2d21ac55 1057Syntax: (gdb) showtaskstacks <task>
55e303ae 1058| Routine to print out the stack for each thread in a task.
1c79356b
A
1059end
1060
1061
1062define showalltasks
1063 showtaskheader
2d21ac55 1064 set $kgm_head_taskp = &tasks
9bccf70c 1065 set $kgm_taskp = (struct task *)($kgm_head_taskp->next)
1c79356b
A
1066 while $kgm_taskp != $kgm_head_taskp
1067 showtaskint $kgm_taskp
2d21ac55 1068 set $kgm_taskp = (struct task *)($kgm_taskp->tasks.next)
1c79356b
A
1069 end
1070end
1071document showalltasks
2d21ac55 1072Syntax: (gdb) showalltasks
1c79356b 1073| Routine to print a summary listing of all the tasks
1c79356b
A
1074end
1075
1076
1077define showprocheader
1078 printf " pid proc command\n"
1079end
1080
1081define showprocint
1082 set $kgm_procp = (struct proc *)$arg0
1083 if $kgm_procp != 0
1084 printf "%5d ", $kgm_procp->p_pid
1085 printf "0x%08x ", $kgm_procp
1086 printf "%s\n", $kgm_procp->p_comm
1087 else
1088 printf " *0* 0x00000000 --\n"
1089 end
1090end
1091
1092define showpid
1093 showtaskheader
2d21ac55 1094 set $kgm_head_taskp = &tasks
9bccf70c 1095 set $kgm_taskp = (struct task *)($kgm_head_taskp->next)
1c79356b
A
1096 while $kgm_taskp != $kgm_head_taskp
1097 set $kgm_procp = (struct proc *)$kgm_taskp->bsd_info
1098 if (($kgm_procp != 0) && ($kgm_procp->p_pid == $arg0))
1099 showtaskint $kgm_taskp
1100 set $kgm_taskp = $kgm_head_taskp
1101 else
2d21ac55 1102 set $kgm_taskp = (struct task *)($kgm_taskp->tasks.next)
1c79356b
A
1103 end
1104 end
1105end
1106document showpid
2d21ac55 1107Syntax: (gdb) showpid <pid>
1c79356b 1108| Routine to print a single process by pid
1c79356b
A
1109end
1110
1111define showproc
1112 showtaskheader
1113 set $kgm_procp = (struct proc *)$arg0
1114 showtaskint $kgm_procp->task $arg1 $arg2
1115end
1116
1117
1118define kdb
1119 set switch_debugger=1
1120 continue
1121end
1122document kdb
1123| kdb - Switch to the inline kernel debugger
1124|
1125| usage: kdb
1126|
1127| The kdb macro allows you to invoke the inline kernel debugger.
1128end
1129
1130define showpsetheader
1131 printf "portset waitqueue recvname "
1132 printf "flags refs recvname process\n"
1133end
1134
1135define showportheader
1136 printf "port mqueue recvname "
1137 printf "flags refs recvname process\n"
1138end
1139
1140define showportmemberheader
9bccf70c 1141 printf "members port recvname "
1c79356b
A
1142 printf "flags refs mqueue msgcount\n"
1143end
1144
1145define showkmsgheader
9bccf70c 1146 printf "messages kmsg size "
1c79356b
A
1147 printf "disp msgid remote-port local-port\n"
1148end
1149
1150define showkmsgint
1151 printf " 0x%08x ", $arg0
1152 set $kgm_kmsgh = ((ipc_kmsg_t)$arg0)->ikm_header
1153 printf "0x%08x ", $kgm_kmsgh.msgh_size
1154 if (($kgm_kmsgh.msgh_bits & 0xff) == 19)
1155 printf "rC"
1156 else
1157 printf "rM"
1158 end
1159 if (($kgm_kmsgh.msgh_bits & 0xff00) == (19 < 8))
1160 printf "lC"
1161 else
1162 printf "lM"
1163 end
1164 if ($kgm_kmsgh.msgh_bits & 0xf0000000)
1165 printf "c"
1166 else
1167 printf "s"
1168 end
9bccf70c 1169 printf "%5d ", $kgm_kmsgh.msgh_id
1c79356b
A
1170 printf "0x%08x ", $kgm_kmsgh.msgh_remote_port
1171 printf "0x%08x\n", $kgm_kmsgh.msgh_local_port
1172end
1173
1174
1175
1176define showkobject
9bccf70c 1177 set $kgm_portp = (struct ipc_port *)$arg0
1c79356b
A
1178 printf "0x%08x kobject(", $kgm_portp->ip_kobject
1179 set $kgm_kotype = ($kgm_portp->ip_object.io_bits & 0x00000fff)
1180 if ($kgm_kotype == 1)
1181 printf "THREAD"
1182 end
1183 if ($kgm_kotype == 2)
1184 printf "TASK"
1185 end
1186 if ($kgm_kotype == 3)
1187 printf "HOST"
1188 end
1189 if ($kgm_kotype == 4)
1190 printf "HOST_PRIV"
1191 end
1192 if ($kgm_kotype == 5)
1193 printf "PROCESSOR"
1194 end
1195 if ($kgm_kotype == 6)
1196 printf "PSET"
1197 end
1198 if ($kgm_kotype == 7)
1199 printf "PSET_NAME"
1200 end
1201 if ($kgm_kotype == 8)
1202 printf "TIMER"
1203 end
1204 if ($kgm_kotype == 9)
1205 printf "PAGER_REQ"
1206 end
1207 if ($kgm_kotype == 10)
1208 printf "DEVICE"
1209 end
1210 if ($kgm_kotype == 11)
1211 printf "XMM_OBJECT"
1212 end
1213 if ($kgm_kotype == 12)
1214 printf "XMM_PAGER"
1215 end
1216 if ($kgm_kotype == 13)
1217 printf "XMM_KERNEL"
1218 end
1219 if ($kgm_kotype == 14)
1220 printf "XMM_REPLY"
1221 end
1222 if ($kgm_kotype == 15)
1223 printf "NOTDEF 15"
1224 end
1225 if ($kgm_kotype == 16)
1226 printf "NOTDEF 16"
1227 end
1228 if ($kgm_kotype == 17)
1229 printf "HOST_SEC"
1230 end
1231 if ($kgm_kotype == 18)
1232 printf "LEDGER"
1233 end
1234 if ($kgm_kotype == 19)
1235 printf "MASTER_DEV"
1236 end
1237 if ($kgm_kotype == 20)
1238 printf "ACTIVATION"
1239 end
1240 if ($kgm_kotype == 21)
1241 printf "SUBSYSTEM"
1242 end
1243 if ($kgm_kotype == 22)
1244 printf "IO_DONE_QUE"
1245 end
1246 if ($kgm_kotype == 23)
1247 printf "SEMAPHORE"
1248 end
1249 if ($kgm_kotype == 24)
1250 printf "LOCK_SET"
1251 end
1252 if ($kgm_kotype == 25)
1253 printf "CLOCK"
1254 end
1255 if ($kgm_kotype == 26)
1256 printf "CLOCK_CTRL"
1257 end
1258 if ($kgm_kotype == 27)
1259 printf "IOKIT_SPARE"
1260 end
1261 if ($kgm_kotype == 28)
1262 printf "NAMED_MEM"
1263 end
1264 if ($kgm_kotype == 29)
1265 printf "IOKIT_CON"
1266 end
1267 if ($kgm_kotype == 30)
1268 printf "IOKIT_OBJ"
1269 end
1270 if ($kgm_kotype == 31)
1271 printf "UPL"
1272 end
1273 printf ")\n"
1274end
1275
1276define showportdestproc
9bccf70c 1277 set $kgm_portp = (struct ipc_port *)$arg0
1c79356b
A
1278 set $kgm_spacep = $kgm_portp->data.receiver
1279# check against the previous cached value - this is slow
1280 if ($kgm_spacep != $kgm_destspacep)
1281 set $kgm_destprocp = (struct proc *)0
2d21ac55 1282 set $kgm_head_taskp = &tasks
91447636
A
1283 set $kgm_desttaskp = (struct task *)($kgm_head_taskp->next)
1284 while (($kgm_destprocp == 0) && ($kgm_desttaskp != $kgm_head_taskp))
1285 set $kgm_destspacep = $kgm_desttaskp->itk_space
1c79356b 1286 if ($kgm_destspacep == $kgm_spacep)
91447636 1287 set $kgm_destprocp = (struct proc *)$kgm_desttaskp->bsd_info
1c79356b 1288 else
2d21ac55 1289 set $kgm_desttaskp = (struct task *)($kgm_desttaskp->tasks.next)
1c79356b
A
1290 end
1291 end
1292 end
1293 if $kgm_destprocp != 0
1294 printf "%s(%d)\n", $kgm_destprocp->p_comm, $kgm_destprocp->p_pid
1295 else
91447636 1296 printf "task 0x%08x\n", $kgm_desttaskp
1c79356b
A
1297 end
1298end
1299
1300define showportdest
9bccf70c 1301 set $kgm_portp = (struct ipc_port *)$arg0
1c79356b
A
1302 set $kgm_spacep = $kgm_portp->data.receiver
1303 if ($kgm_spacep == ipc_space_kernel)
1304 showkobject $kgm_portp
1305 else
1306 if ($kgm_portp->ip_object.io_bits & 0x80000000)
1307 printf "0x%08x ", $kgm_portp->ip_object.io_receiver_name
1308 showportdestproc $kgm_portp
1309 else
1310 printf "0x%08x inactive-port\n", $kgm_portp
1311 end
1312 end
1313end
1314
1315define showportmember
1316 printf " 0x%08x ", $arg0
9bccf70c 1317 set $kgm_portp = (struct ipc_port *)$arg0
1c79356b
A
1318 printf "0x%08x ", $kgm_portp->ip_object.io_receiver_name
1319 if ($kgm_portp->ip_object.io_bits & 0x80000000)
1320 printf "A"
1321 else
1322 printf " "
1323 end
1324 if ($kgm_portp->ip_object.io_bits & 0x7fff0000)
1325 printf "Set "
1326 else
1327 printf "Port"
1328 end
1329 printf "%5d ", $kgm_portp->ip_object.io_references
1330 printf "0x%08x ", &($kgm_portp->ip_messages)
1331 printf "0x%08x\n", $kgm_portp->ip_messages.data.port.msgcount
1332end
1333
1334define showportint
1335 printf "0x%08x ", $arg0
9bccf70c 1336 set $kgm_portp = (struct ipc_port *)$arg0
1c79356b
A
1337 printf "0x%08x ", &($kgm_portp->ip_messages)
1338 printf "0x%08x ", $kgm_portp->ip_object.io_receiver_name
1339 if ($kgm_portp->ip_object.io_bits & 0x80000000)
1340 printf "A"
1341 else
1342 printf "D"
1343 end
1344 printf "Port"
1345 printf "%5d ", $kgm_portp->ip_object.io_references
9bccf70c 1346 set $kgm_destspacep = (struct ipc_space *)0
1c79356b
A
1347 showportdest $kgm_portp
1348 set $kgm_kmsgp = (ipc_kmsg_t)$kgm_portp->ip_messages.data.port.messages.ikmq_base
1349 if $arg1 && $kgm_kmsgp
1350 showkmsgheader
1351 showkmsgint $kgm_kmsgp
1352 set $kgm_kmsgheadp = $kgm_kmsgp
1353 set $kgm_kmsgp = $kgm_kmsgp->ikm_next
1354 while $kgm_kmsgp != $kgm_kmsgheadp
1355 showkmsgint $kgm_kmsgp
1356 set $kgm_kmsgp = $kgm_kmsgp->ikm_next
1357 end
1358 end
1359end
1360
1361define showpsetint
1362 printf "0x%08x ", $arg0
9bccf70c 1363 set $kgm_psetp = (struct ipc_pset *)$arg0
1c79356b
A
1364 printf "0x%08x ", &($kgm_psetp->ips_messages)
1365 printf "0x%08x ", $kgm_psetp->ips_object.io_receiver_name
1366 if ($kgm_psetp->ips_object.io_bits & 0x80000000)
1367 printf "A"
1368 else
1369 printf "D"
1370 end
1371 printf "Set "
1372 printf "%5d ", $kgm_psetp->ips_object.io_references
9bccf70c
A
1373 printf "0x%08x ", $kgm_psetp->ips_object.io_receiver_name
1374 set $kgm_setlinksp = &($kgm_psetp->ips_messages.data.set_queue.wqs_setlinks)
1375 set $kgm_wql = (struct wait_queue_link *)$kgm_setlinksp->next
1c79356b 1376 set $kgm_found = 0
9bccf70c
A
1377 while ( (queue_entry_t)$kgm_wql != (queue_entry_t)$kgm_setlinksp)
1378 set $kgm_portp = (struct ipc_port *)((int)($kgm_wql->wql_element->wqe_queue) - ((int)$kgm_portoff))
1c79356b 1379 if !$kgm_found
9bccf70c
A
1380 set $kgm_destspacep = (struct ipc_space *)0
1381 showportdestproc $kgm_portp
1c79356b
A
1382 showportmemberheader
1383 set $kgm_found = 1
1384 end
1385 showportmember $kgm_portp 0
9bccf70c 1386 set $kgm_wql = (struct wait_queue_link *)$kgm_wql->wql_setlinks.next
1c79356b 1387 end
9bccf70c
A
1388 if !$kgm_found
1389 printf "--n/e--\n"
1c79356b
A
1390 end
1391end
1392
1393define showpset
1394 showpsetheader
1395 showpsetint $arg0 1
1396end
1397
1398define showport
1399 showportheader
1400 showportint $arg0 1
1401end
1402
1403define showipcobject
1404 set $kgm_object = (ipc_object_t)$arg0
1405 if ($kgm_objectp->io_bits & 0x7fff0000)
1406 showpset $kgm_objectp
1407 else
1408 showport $kgm_objectp
1409 end
1410end
1411
1412define showmqueue
9bccf70c
A
1413 set $kgm_mqueue = *(struct ipc_mqueue *)$arg0
1414 set $kgm_psetoff = &(((struct ipc_pset *)0)->ips_messages)
1415 set $kgm_portoff = &(((struct ipc_port *)0)->ip_messages)
1416 if ($kgm_mqueue.data.set_queue.wqs_wait_queue.wq_type == 0xf1d1)
1c79356b
A
1417 set $kgm_pset = (((int)$arg0) - ((int)$kgm_psetoff))
1418 showpsetheader
1419 showpsetint $kgm_pset 1
9bccf70c
A
1420 end
1421 if ($kgm_mqueue.data.set_queue.wqs_wait_queue.wq_type == 0xf1d0)
1c79356b
A
1422 showportheader
1423 set $kgm_port = (((int)$arg0) - ((int)$kgm_portoff))
1424 showportint $kgm_port 1
1425 end
1426end
1427
1428define zprint_one
1429set $kgm_zone = (struct zone *)$arg0
1430
1431printf "0x%08x ", $kgm_zone
1432printf "%8d ",$kgm_zone->count
1433printf "%8x ",$kgm_zone->cur_size
1434printf "%8x ",$kgm_zone->max_size
1435printf "%6d ",$kgm_zone->elem_size
1436printf "%8x ",$kgm_zone->alloc_size
1437printf "%s ",$kgm_zone->zone_name
1438
1439if ($kgm_zone->exhaustible)
1440 printf "H"
1441end
1442if ($kgm_zone->collectable)
1443 printf "C"
1444end
1445if ($kgm_zone->expandable)
1446 printf "X"
1447end
1448printf "\n"
1449end
1450
1451
1452define zprint
1453printf "ZONE COUNT TOT_SZ MAX_SZ ELT_SZ ALLOC_SZ NAME\n"
1454set $kgm_zone_ptr = (struct zone *)first_zone
1455while ($kgm_zone_ptr != 0)
1456 zprint_one $kgm_zone_ptr
1457 set $kgm_zone_ptr = $kgm_zone_ptr->next_zone
1458end
1459printf "\n"
1460end
1461document zprint
2d21ac55 1462Syntax: (gdb) zprint
1c79356b 1463| Routine to print a summary listing of all the kernel zones
1c79356b
A
1464end
1465
91447636 1466define showmtxgrp
2d21ac55 1467set $kgm_mtxgrp = (struct _lck_grp_ *)$arg0
91447636
A
1468
1469if ($kgm_mtxgrp->lck_grp_mtxcnt)
1470printf "0x%08x ", $kgm_mtxgrp
1471printf "%8d ",$kgm_mtxgrp->lck_grp_mtxcnt
1472printf "%12u ",$kgm_mtxgrp->lck_grp_stat.lck_grp_mtx_stat.lck_grp_mtx_util_cnt
1473printf "%8u ",$kgm_mtxgrp->lck_grp_stat.lck_grp_mtx_stat.lck_grp_mtx_miss_cnt
1474printf "%8u ",$kgm_mtxgrp->lck_grp_stat.lck_grp_mtx_stat.lck_grp_mtx_wait_cnt
1475printf "%s ",&$kgm_mtxgrp->lck_grp_name
1476printf "\n"
1477end
1478end
1479
1480
1481define showallmtx
1482printf "LCK GROUP CNT UTIL MISS WAIT NAME\n"
2d21ac55
A
1483set $kgm_mtxgrp_ptr = (struct _lck_grp_ *)&lck_grp_queue
1484set $kgm_mtxgrp_ptr = (struct _lck_grp_ *)$kgm_mtxgrp_ptr->lck_grp_link.next
1485while ($kgm_mtxgrp_ptr != (struct _lck_grp_ *)&lck_grp_queue)
91447636 1486 showmtxgrp $kgm_mtxgrp_ptr
2d21ac55 1487 set $kgm_mtxgrp_ptr = (struct _lck_grp_ *)$kgm_mtxgrp_ptr->lck_grp_link.next
91447636
A
1488end
1489printf "\n"
1490end
1491document showallmtx
2d21ac55 1492Syntax: (gdb) showallmtx
91447636 1493| Routine to print a summary listing of all mutexes
91447636
A
1494end
1495
1496define showrwlckgrp
2d21ac55 1497set $kgm_rwlckgrp = (struct _lck_grp_ *)$arg0
91447636
A
1498
1499if ($kgm_rwlckgrp->lck_grp_rwcnt)
1500printf "0x%08x ", $kgm_rwlckgrp
1501printf "%8d ",$kgm_rwlckgrp->lck_grp_rwcnt
1502printf "%12u ",$kgm_rwlckgrp->lck_grp_stat.lck_grp_rw_stat.lck_grp_rw_util_cnt
1503printf "%8u ",$kgm_rwlckgrp->lck_grp_stat.lck_grp_rw_stat.lck_grp_rw_miss_cnt
1504printf "%8u ",$kgm_rwlckgrp->lck_grp_stat.lck_grp_rw_stat.lck_grp_rw_wait_cnt
1505printf "%s ",&$kgm_rwlckgrp->lck_grp_name
1506printf "\n"
1507end
1508end
1509
1510
1511define showallrwlck
1512printf "LCK GROUP CNT UTIL MISS WAIT NAME\n"
2d21ac55
A
1513set $kgm_rwlckgrp_ptr = (struct _lck_grp_ *)&lck_grp_queue
1514set $kgm_rwlckgrp_ptr = (struct _lck_grp_ *)$kgm_rwlckgrp_ptr->lck_grp_link.next
1515while ($kgm_rwlckgrp_ptr != (struct _lck_grp_ *)&lck_grp_queue)
91447636 1516 showrwlckgrp $kgm_rwlckgrp_ptr
2d21ac55 1517 set $kgm_rwlckgrp_ptr = (struct _lck_grp_ *)$kgm_rwlckgrp_ptr->lck_grp_link.next
91447636
A
1518end
1519printf "\n"
1520end
1521document showallrwlck
2d21ac55 1522Syntax: (gdb) showallrwlck
91447636 1523| Routine to print a summary listing of all read/writer locks
91447636
A
1524end
1525
9bccf70c
A
1526set $kdp_act_counter = 0
1527
2d21ac55
A
1528set $r0_save = 0
1529set $r1_save = 0
1530set $r2_save = 0
1531set $r3_save = 0
1532set $r4_save = 0
1533set $r5_save = 0
1534set $r6_save = 0
1535set $r7_save = 0
1536set $r8_save = 0
1537set $r9_save = 0
1538set $r10_save = 0
1539set $r11_save = 0
1540set $r12_save = 0
1541set $sp_save = 0
1542set $lr_save = 0
1543set $pc_save = 0
1544
1545define showcontext_int
1546 echo Context switched, current instruction pointer:
1547 output/a $pc
1548 echo \n
1549end
1550
9bccf70c 1551define switchtoact
0c530ab8 1552 set $newact = (struct thread *) $arg0
2d21ac55 1553 select 0
0c530ab8
A
1554 if ($newact->kernel_stack == 0)
1555 echo This activation does not have a stack.\n
1556 echo continuation:
1557 output/a (unsigned) $newact.continuation
1558 echo \n
1559 else
91447636 1560 if ($kgm_mtype == 18)
9bccf70c 1561 if ($kdp_act_counter == 0)
0c530ab8 1562 set $kdpstate = (struct savearea *) kdp.saved_state
9bccf70c
A
1563 end
1564 set $kdp_act_counter = $kdp_act_counter + 1
0c530ab8
A
1565 set (struct savearea *) kdp.saved_state=$newact->machine->pcb
1566 flushregs
1567 flushstack
1568 set $pc=$newact->machine->pcb.save_srr0
1569 update
2d21ac55
A
1570 end
1571 if ($kgm_mtype == 7)
0c530ab8
A
1572 set $kdpstatep = (struct x86_saved_state32 *) kdp.saved_state
1573 if ($kdp_act_counter == 0)
1574 set $kdpstate = *($kdpstatep)
1575 end
1576 set $kdp_act_counter = $kdp_act_counter + 1
1577
1578 set $kgm_statep = (struct x86_kernel_state32 *) \
1579 ($newact->kernel_stack + 0x4000 \
1580 - sizeof(struct x86_kernel_state32))
1581 set $kdpstatep->ebx = $kgm_statep->k_ebx
1582 set $kdpstatep->ebp = $kgm_statep->k_ebp
1583 set $kdpstatep->edi = $kgm_statep->k_edi
1584 set $kdpstatep->esi = $kgm_statep->k_esi
1585 set $kdpstatep->eip = $kgm_statep->k_eip
1586 flushregs
1587 flushstack
1588 set $pc = $kgm_statep->k_eip
1589 update
1590 end
2d21ac55
A
1591 if ($kgm_mtype == 12)
1592 set $r0_save = $r0
1593 set $r1_save = $r1
1594 set $r2_save = $r2
1595 set $r3_save = $r3
1596 set $r4_save = $r4
1597 set $r5_save = $r5
1598 set $r6_save = $r6
1599 set $r7_save = $r7
1600 set $r8_save = $r8
1601 set $r9_save = $r9
1602 set $r10_save = $r10
1603 set $r11_save = $r11
1604 set $r12_save = $r12
1605 set $sp_save = $sp
1606 set $lr_save = $lr
1607 set $pc_save = $pc
1608 set $pc_ctx = load_reg+8
1609 set $kgm_statep = (struct arm_saved_state *)((struct thread*)$arg0)->machine.kstackptr
1610 set $r0 = $kgm_statep->r[0]
1611 set $r1 = $kgm_statep->r[1]
1612 set $r2 = $kgm_statep->r[2]
1613 set $r3 = $kgm_statep->r[3]
1614 set $r4 = $kgm_statep->r[4]
1615 set $r5 = $kgm_statep->r[5]
1616 set $r6 = $kgm_statep->r[6]
1617 set $r8 = $kgm_statep->r[8]
1618 set $r9 = $kgm_statep->r[9]
1619 set $r10 = $kgm_statep->r[10]
1620 set $r11 = $kgm_statep->r[11]
1621 set $r12 = $kgm_statep->r[12]
1622 set $sp = $kgm_statep->sp
1623 set $lr = $kgm_statep->lr
1624 set $pc = $pc_ctx
1625 set $r7 = $kgm_statep->r[7]
1626 flushregs
1627 flushstack
1628 end
9bccf70c 1629 end
2d21ac55 1630 showcontext_int
9bccf70c
A
1631end
1632
1633document switchtoact
1634Syntax: switchtoact <address of activation>
1635| This command allows gdb to examine the execution context and call
1636| stack for the specified activation. For example, to view the backtrace
1637| for an activation issue "switchtoact <address>", followed by "bt".
1638| Before resuming execution, issue a "resetctx" command, to
1639| return to the original execution context.
1640end
1641
1642define switchtoctx
2d21ac55 1643 select 0
91447636 1644 if ($kgm_mtype == 18)
9bccf70c
A
1645 if ($kdp_act_counter == 0)
1646 set $kdpstate = (struct savearea *) kdp.saved_state
1647 end
1648 set $kdp_act_counter = $kdp_act_counter + 1
1649 set (struct savearea *) kdp.saved_state=(struct savearea *) $arg0
0c530ab8
A
1650 flushregs
1651 flushstack
9bccf70c
A
1652 set $pc=((struct savearea *) $arg0)->save_srr0
1653 update
2d21ac55
A
1654 else
1655 if ($kgm_mtype == 12)
1656 set $r0_save = $r0
1657 set $r1_save = $r1
1658 set $r2_save = $r2
1659 set $r3_save = $r3
1660 set $r4_save = $r4
1661 set $r5_save = $r5
1662 set $r6_save = $r6
1663 set $r7_save = $r7
1664 set $r8_save = $r8
1665 set $r9_save = $r9
1666 set $r10_save = $r10
1667 set $r11_save = $r11
1668 set $r12_save = $r12
1669 set $sp_save = $sp
1670 set $lr_save = $lr
1671 set $pc_save = $pc
1672 set $kgm_statep = (struct arm_saved_state *)$arg0
1673 set $r0 = $kgm_statep->r[0]
1674 set $r1 = $kgm_statep->r[1]
1675 set $r2 = $kgm_statep->r[2]
1676 set $r3 = $kgm_statep->r[3]
1677 set $r4 = $kgm_statep->r[4]
1678 set $r5 = $kgm_statep->r[5]
1679 set $r6 = $kgm_statep->r[6]
1680 set $r8 = $kgm_statep->r[8]
1681 set $r9 = $kgm_statep->r[9]
1682 set $r10 = $kgm_statep->r[10]
1683 set $r11 = $kgm_statep->r[11]
1684 set $r12 = $kgm_statep->r[12]
1685 set $sp = $kgm_statep->sp
1686 set $lr = $kgm_statep->lr
1687 set $r7 = $kgm_statep->r[7]
1688 set $pc = $kgm_statep->pc
1689 flushregs
1690 flushstack
1691 update
9bccf70c
A
1692 else
1693 echo switchtoctx not implemented for this architecture.\n
1694 end
1695end
1696
1697document switchtoctx
1698Syntax: switchtoctx <address of pcb>
1699| This command allows gdb to examine an execution context and dump the
1700| backtrace for this execution context.
1701| Before resuming execution, issue a "resetctx" command, to
1702| return to the original execution context.
1703end
1704
1705define resetctx
2d21ac55
A
1706 select 0
1707 if ($kdp_act_counter != 0)
91447636 1708 if ($kgm_mtype == 18)
9bccf70c 1709 set (struct savearea *)kdp.saved_state=$kdpstate
0c530ab8
A
1710 flushregs
1711 flushstack
9bccf70c
A
1712 set $pc=((struct savearea *) kdp.saved_state)->save_srr0
1713 update
1714 set $kdp_act_counter = 0
2d21ac55
A
1715 end
1716 if ($kgm_mtype == 7)
0c530ab8
A
1717 set $kdpstatep = (struct x86_saved_state32 *) kdp.saved_state
1718 set *($kdpstatep)=$kdpstate
1719 flushregs
1720 flushstack
1721 set $pc=$kdpstatep->eip
1722 update
1723 set $kdp_act_counter = 0
9bccf70c 1724 end
2d21ac55
A
1725 if ($kgm_mtype == 12)
1726 set $r0 = $r0_save
1727 flushregs
1728 set $r1 = $r1_save
1729 flushregs
1730 set $r2 = $r2_save
1731 flushregs
1732 set $r3 = $r3_save
1733 flushregs
1734 set $r4 = $r4_save
1735 flushregs
1736 set $r5 = $r5_save
1737 flushregs
1738 set $r6 = $r6_save
1739 flushregs
1740 set $r8 = $r8_save
1741 flushregs
1742 set $r9 = $r9_save
1743 flushregs
1744 set $r10 = $r10_save
1745 flushregs
1746 set $r11 = $r11_save
1747 flushregs
1748 set $r12 = $r12_save
1749 flushregs
1750 set $sp = $sp_save
1751 flushregs
1752 set $lr = $lr_save
1753 flushregs
1754 set $pc = $pc_save
1755 flushregs
1756 set $r7 = $r7_save
1757 flushregs
1758 end
1759 showcontext_int
1760 end
9bccf70c
A
1761end
1762
1763document resetctx
1764| Syntax: resetctx
1765| Returns to the original execution context. This command should be
1766| issued if you wish to resume execution after using the "switchtoact"
1767| or "switchtoctx" commands.
1768end
1769
2d21ac55
A
1770# This is a pre-hook for the continue command, to prevent inadvertent attempts
1771# to resume from the context switched to for examination.
1772define hook-continue
1773 resetctx
1774end
1775
1776# This is a pre-hook for the detach command, to prevent inadvertent attempts
1777# to resume from the context switched to for examination.
1778define hook-detach
1779 resetctx
1780end
1781
55e303ae
A
1782define resume_on
1783 set noresume_on_disconnect = 0
1784end
1785
1786document resume_on
1787| Syntax: resume_on
1788| The target system will resume when detaching or exiting from gdb.
1789| This is the default behavior.
1790end
1791
1792define resume_off
1793 set noresume_on_disconnect = 1
1794end
1795
1796document resume_off
1797| Syntax: resume_off
1798| The target system won't resume after detaching from gdb and
1799| can be attached with a new gdb session
1800end
1801
9bccf70c
A
1802define paniclog
1803 set $kgm_panic_bufptr = debug_buf
55e303ae
A
1804 set $kgm_panic_bufptr_max = debug_buf_ptr
1805 while $kgm_panic_bufptr < $kgm_panic_bufptr_max
9bccf70c
A
1806 if *(char *)$kgm_panic_bufptr == 10
1807 printf "\n"
1808 else
1809 printf "%c", *$kgm_panic_bufptr
1810 end
1811 set $kgm_panic_bufptr= (char *)$kgm_panic_bufptr + 1
1812 end
1813end
1814
1815document paniclog
1816| Syntax: paniclog
1817| Display the panic log information
1818|
1819end
55e303ae
A
1820
1821define dumpcallqueue
1822 set $kgm_callhead = (queue_t)&$arg0
1823 set $kgm_call = (struct call_entry *)$kgm_callhead.next
1824 set $kgm_i = 0
1825 while $kgm_call != $kgm_callhead
1826 printf "0x%08x ", $kgm_call
1827 printf "0x%08x 0x%08x ", $kgm_call->param0, $kgm_call->param1
1828 output $kgm_call->state
1829 printf "\t"
1830 output $kgm_call->deadline
1831 printf "\t"
1832 output $kgm_call->func
1833 printf "\n"
1834 set $kgm_i = $kgm_i + 1
1835 set $kgm_call = (struct call_entry *)$kgm_call->q_link.next
1836 end
1837 printf "%d entries\n", $kgm_i
1838end
1839
1840document dumpcallqueue
1841| Syntax: dumpcallqueue <queue head>
1842| Displays the contents of the specified call_entry queue.
1843end
1844
1845define showtaskacts
1846showtaskthreads $arg0
1847end
1848document showtaskacts
1849| See help showtaskthreads.
1850end
1851
1852define showallacts
1853showallthreads
1854end
1855document showallacts
1856| See help showallthreads.
1857end
91447636
A
1858
1859
1860define resetstacks
1861 _kgm_flush_loop
1862 set kdp_pmap = 0
1863 _kgm_flush_loop
1864 resetctx
1865 _kgm_flush_loop
1866 _kgm_update_loop
1867 resetctx
1868 _kgm_update_loop
1869end
1870
1871document resetstacks
1872| Syntax: resetstacks
1873| Internal kgmacro routine used by the "showuserstack" macro
1874| to reset the target pmap to the kernel pmap.
1875end
1876
1877#Barely effective hacks to work around bugs in the "flush" and "update"
1878#gdb commands in Tiger (up to 219); these aren't necessary with Panther
1879#gdb, but do no harm.
1880define _kgm_flush_loop
1881 set $kgm_flush_loop_ctr = 0
1882 while ($kgm_flush_loop_ctr < 30)
0c530ab8
A
1883 flushregs
1884 flushstack
91447636
A
1885 set $kgm_flush_loop_ctr = $kgm_flush_loop_ctr + 1
1886 end
1887end
1888
1889define _kgm_update_loop
1890 set $kgm_update_loop_ctr = 0
1891 while ($kgm_update_loop_ctr < 30)
1892 update
1893 set $kgm_update_loop_ctr = $kgm_update_loop_ctr + 1
1894 end
1895end
1896
0c530ab8
A
1897#This is necessary since gdb often doesn't do backtraces on x86 correctly
1898#in the absence of symbols.The code below in showuserstack and
1899#showx86backtrace also contains several workarouds for the gdb bug where
1900#gdb stops macro evaluation because of spurious "Cannot read memory"
1901#errors on x86. These errors appear on ppc as well, but they don't
1902#always stop macro evaluation.
1903
1904set $kgm_cur_ebp = 0
1905set $kgm_cur_eip = 0
1906
1907define showx86backtrace
1908 if ($kgm_cur_ebp == 0)
1909 set $kgm_cur_ebp = $ebp
1910 end
1911 if ($kgm_cur_eip == 0)
1912 set $kgm_cur_eip = $eip
1913 end
1914 printf "0: EBP: 0x%08x EIP: 0x%08x\n", $kgm_cur_ebp, $kgm_cur_eip
1915 x/i $kgm_cur_eip
1916 set $kgm_prev_ebp = *((uint32_t *) $kgm_cur_ebp)
1917 set $kgm_prev_eip = *((uint32_t *) ($kgm_cur_ebp + 4))
2d21ac55
A
1918 set $kgm_cur_ebp = 0
1919 set $kgm_cur_eip = 0
0c530ab8
A
1920 set $kgm_frameno = 1
1921 while $kgm_prev_ebp != 0
1922 printf "%d: saved EBP: 0x%08x saved EIP: 0x%08x\n", $kgm_frameno, $kgm_prev_ebp, $kgm_prev_eip
1923 x/i $kgm_prev_eip
2d21ac55
A
1924 set $kgm_prev_eip = *((uint32_t *) ($kgm_prev_ebp + 4))
1925 set $kgm_prev_ebp = *((uint32_t *) $kgm_prev_ebp)
0c530ab8
A
1926 set $kgm_frameno = $kgm_frameno + 1
1927 end
0c530ab8
A
1928 set kdp_pmap = 0
1929end
1930
91447636 1931define showuserstack
2d21ac55 1932 select 0
91447636
A
1933 if ($kgm_mtype == 18)
1934 if ($kdp_act_counter == 0)
1935 set $kdpstate = (struct savearea *) kdp.saved_state
1936 end
1937 set $kdp_act_counter = $kdp_act_counter + 1
1938 set $newact = (struct thread *) $arg0
1939 _kgm_flush_loop
1940 set $checkpc = $newact->machine->upcb.save_srr0
1941 if ($checkpc == 0)
1942 echo This activation does not appear to have
1943 echo \20 a valid user context.\n
1944 else
1945 set (struct savearea *) kdp.saved_state=$newact->machine->upcb
1946 set $pc = $checkpc
1947#flush and update seem to be executed lazily by gdb on Tiger, hence the
1948#repeated invocations - see 3743135
1949 _kgm_flush_loop
1950# This works because the new pmap is used only for reads
1951 set kdp_pmap = $newact->task->map->pmap
1952 _kgm_flush_loop
1953 _kgm_update_loop
1954 bt
1955 resetstacks
1956 _kgm_flush_loop
1957 _kgm_update_loop
1958 resetstacks
1959 _kgm_flush_loop
1960 _kgm_update_loop
1961 end
1962 else
0c530ab8 1963 set $newact = (struct thread *) $arg0
2d21ac55
A
1964#This needs to identify 64-bit processes as well
1965 set $newiss = (x86_saved_state32_t) ($newact->machine.pcb->iss.uss.ss_32)
0c530ab8
A
1966 set $checkpc = $newiss.eip
1967 if ($checkpc == 0)
1968 echo This activation does not appear to have
1969 echo \20 a valid user context.\n
1970 else
1971 set $kgm_cur_ebp = $newiss.ebp
1972 set $kgm_cur_eip = $checkpc
1973 printf "You may now issue the showx86backtrace command to see the user space backtrace for this thread (0x%08x); you can also examine memory locations in this address space (pmap 0x%08x) 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", $arg0, $newact->task->map->pmap
1974 set kdp_pmap = $newact->task->map->pmap
1975 _kgm_flush_loop
1976 _kgm_update_loop
1977 end
1978 end
91447636 1979end
91447636
A
1980document showuserstack
1981Syntax: showuserstack <address of thread activation>
1982|This command displays a numeric backtrace for the user space stack of
1983|the given thread activation. It may, of course, fail to display a
1984|complete backtrace if portions of the user stack are not mapped in.
1985|Symbolic backtraces can be obtained either by running gdb on the
1986|user space binary, or a tool such as "symbolicate".
1987|Note that while this command works on Panther's gdb, an issue
1988|with Tiger gdb (3743135) appears to hamper the evaluation of this
1989|macro in some cases.
1990end
1991
1992#Stopgap until gdb can generate the HOSTREBOOT packet
1993define kdp-reboot
2d21ac55 1994#Alternatively, set *(*(unsigned **) 0x2498) = 1 (or 0x5498 on PPC)
91447636
A
1995 set flag_kdp_trigger_reboot = 1
1996 continue
1997end
1998
1999document kdp-reboot
2000Syntax: kdp-reboot
2001|Reboot the remote target machine; not guaranteed to succeed. Requires symbols
2002|until gdb support for the HOSTREBOOT packet is implemented.
2003end
2004
2005define sendcore
2006 set kdp_trigger_core_dump = 1
2007 set kdp_flag |= 0x40
2008 set panicd_ip_str = "$arg0"
2009 set panicd_specified = 1
2d21ac55 2010 set disable_debug_output = 0
91447636
A
2011 set disableConsoleOutput = 0
2012 set logPanicDataToScreen = 1
2013 set reattach_wait = 1
2014 resume_off
2015end
2016
2017document sendcore
2018Syntax: sendcore <IP address>
2019|Configure the kernel to transmit a kernel coredump to a server (kdumpd)
2020|at the specified IP address. This is useful when the remote target has
2021|not been previously configured to transmit coredumps, and you wish to
2022|preserve kernel state for later examination. NOTE: You must issue a "continue"
2023|command after using this macro to trigger the kernel coredump. The kernel
2024|will resume waiting in the debugger after completion of the coredump. You
2025|may disable coredumps by executing the "disablecore" macro.
2026end
2027
2028define disablecore
2029 set kdp_trigger_core_dump = 0
2030 set kdp_flag |= 0x40
2031 set kdp_flag &= ~0x10
2032 set panicd_specified = 0
2033end
2034
2035document disablecore
2036Syntax: disablecore
2037|Reconfigures the kernel so that it no longer transmits kernel coredumps. This
2038|complements the "sendcore" macro, but it may be used if the kernel has been
2039|configured to transmit coredumps through boot-args as well.
2040end
2041
91447636 2042define switchtocorethread
2d21ac55
A
2043 set $newact = (struct thread *) $arg0
2044 select 0
2045 if ($newact->kernel_stack == 0)
2046 echo This thread does not have a stack.\n
2047 echo continuation:
2048 output/a (unsigned) $newact.continuation
2049 echo \n
2050 else
91447636 2051 if ($kgm_mtype == 18)
2d21ac55
A
2052 loadcontext $newact->machine->pcb
2053 flushstack
2054 set $pc = $newact->machine->pcb.save_srr0
91447636 2055 else
2d21ac55
A
2056 set $kgm_cstatep = (struct x86_kernel_state32 *) \
2057 ($newact->kernel_stack + 0x4000 \
2058 - sizeof(struct x86_kernel_state32))
2059 loadcontext $kgm_cstatep
2060 flushstack
2061 end
2062 showcontext_int
91447636
A
2063 end
2064end
2065
2066document switchtocorethread
2067Syntax: switchtocorethread <address of activation>
2068| The corefile equivalent of "switchtoact". When debugging a kernel coredump
2069| file, this command can be used to examine the execution context and stack
2070| trace for a given thread activation. For example, to view the backtrace
2071| for a thread issue "switchtocorethread <address>", followed by "bt".
2072| Before resuming execution, issue a "resetcorectx" command, to
2073| return to the original execution context. Note that this command
2074| requires gdb support, as documented in Radar 3401283.
2075end
2076
2077define loadcontext
2d21ac55
A
2078 select 0
2079 if ($kgm_mtype == 18)
2080 set $kgm_contextp = (struct savearea *) $arg0
2081 set $pc = $kgm_contextp.save_srr0
2082 set $r1 = $kgm_contextp.save_r1
2083 set $lr = $kgm_contextp.save_lr
2084
2085 set $r2 = $kgm_contextp.save_r2
2086 set $r3 = $kgm_contextp.save_r3
2087 set $r4 = $kgm_contextp.save_r4
2088 set $r5 = $kgm_contextp.save_r5
2089 set $r6 = $kgm_contextp.save_r6
2090 set $r7 = $kgm_contextp.save_r7
2091 set $r8 = $kgm_contextp.save_r8
2092 set $r9 = $kgm_contextp.save_r9
2093 set $r10 = $kgm_contextp.save_r10
2094 set $r11 = $kgm_contextp.save_r11
2095 set $r12 = $kgm_contextp.save_r12
2096 set $r13 = $kgm_contextp.save_r13
2097 set $r14 = $kgm_contextp.save_r14
2098 set $r15 = $kgm_contextp.save_r15
2099 set $r16 = $kgm_contextp.save_r16
2100 set $r17 = $kgm_contextp.save_r17
2101 set $r18 = $kgm_contextp.save_r18
2102 set $r19 = $kgm_contextp.save_r19
2103 set $r20 = $kgm_contextp.save_r20
2104 set $r21 = $kgm_contextp.save_r21
2105 set $r22 = $kgm_contextp.save_r22
2106 set $r23 = $kgm_contextp.save_r23
2107 set $r24 = $kgm_contextp.save_r24
2108 set $r25 = $kgm_contextp.save_r25
2109 set $r26 = $kgm_contextp.save_r26
2110 set $r27 = $kgm_contextp.save_r27
2111 set $r28 = $kgm_contextp.save_r28
2112 set $r29 = $kgm_contextp.save_r29
2113 set $r30 = $kgm_contextp.save_r30
2114 set $r31 = $kgm_contextp.save_r31
2115
2116 set $cr = $kgm_contextp.save_cr
2117 set $ctr = $kgm_contextp.save_ctr
2118 else
2119 set $kgm_contextp = (struct x86_kernel_state32 *) $arg0
2120 set $ebx = $kgm_contextp->k_ebx
2121 set $ebp = $kgm_contextp->k_ebp
2122 set $edi = $kgm_contextp->k_edi
2123 set $esi = $kgm_contextp->k_esi
2124 set $eip = $kgm_contextp->k_eip
2125 set $pc = $kgm_contextp->k_eip
2126 end
91447636
A
2127end
2128
2129define resetcorectx
2d21ac55
A
2130 select 0
2131 if ($kgm_mtype == 18)
2132 set $kgm_corecontext = (struct savearea *) kdp.saved_state
2133 loadcontext $kgm_corecontext
2134 else
2135 if ($kgm_mtype == 7)
2136 set $kdpstatep = (struct x86_saved_state32 *) kdp.saved_state
2137 set $ebx = $kdpstatep->ebx
2138 set $ebp = $kdpstatep->ebp
2139 set $edi = $kdpstatep->edi
2140 set $esi = $kdpstatep->esi
2141 set $eip = $kdpstatep->eip
2142 set $eax = $kdpstatep->eax
2143 set $ecx = $kdpstatep->ecx
2144 set $edx = $kdpstatep->edx
2145 flushregs
2146 flushstack
2147 set $pc = $kdpstatep->eip
2148 update
2149 end
2150 end
2151 showcontext_int
91447636
A
2152end
2153
2154document resetcorectx
2155Syntax: resetcorectx
2156| The corefile equivalent of "resetctx". Returns to the original
2157| execution context (that of the active thread at the time of the NMI or
2158| panic). This command should be issued if you wish to resume
2159| execution after using the "switchtocorethread" command.
2160end
2161
2162#Helper function for "showallgdbstacks"
2163
2164define showgdbthread
2165 printf " 0x%08x ", $arg0
2166 set $kgm_thread = *(struct thread *)$arg0
2167 printf "0x%08x ", $arg0
2168 printf "%3d ", $kgm_thread.sched_pri
2169 set $kgm_state = $kgm_thread.state
2170 if $kgm_state & 0x80
2171 printf "I"
2172 end
2173 if $kgm_state & 0x40
2174 printf "P"
2175 end
2176 if $kgm_state & 0x20
2177 printf "A"
2178 end
2179 if $kgm_state & 0x10
2180 printf "H"
2181 end
2182 if $kgm_state & 0x08
2183 printf "U"
2184 end
2185 if $kgm_state & 0x04
2186 printf "R"
2187 end
2188 if $kgm_state & 0x02
2189 printf "S"
2190 end
2191 if $kgm_state & 0x01
2192 printf "W\t"
2193 printf "0x%08x ", $kgm_thread.wait_queue
2194 output /a (unsigned) $kgm_thread.wait_event
2d21ac55
A
2195 if ($kgm_thread.uthread != 0)
2196 set $kgm_uthread = (struct uthread *)$kgm_thread.uthread
2197 if ($kgm_uthread->uu_wmesg != 0)
2198 printf " \"%s\"", $kgm_uthread->uu_wmesg
2199 end
2200 end
91447636
A
2201 end
2202 if $arg1 != 0
2203 if ($kgm_thread.kernel_stack != 0)
2204 if ($kgm_thread.reserved_stack != 0)
2205 printf "\n\t\treserved_stack=0x%08x", $kgm_thread.reserved_stack
2206 end
2207 printf "\n\t\tkernel_stack=0x%08x", $kgm_thread.kernel_stack
2208 if ($kgm_mtype == 18)
2209 set $mysp = $kgm_thread.machine.pcb->save_r1
2d21ac55
A
2210 end
2211 if ($kgm_mtype == 7)
0c530ab8 2212 set $kgm_statep = (struct x86_kernel_state32 *) \
91447636 2213 ($kgm_thread->kernel_stack + 0x4000 \
0c530ab8 2214 - sizeof(struct x86_kernel_state32))
91447636
A
2215 set $mysp = $kgm_statep->k_ebp
2216 end
2d21ac55
A
2217 if ($kgm_mtype == 12)
2218 if ($arg0 == $r9)
2219 set $mysp = $r7
2220 else
2221 set $kgm_statep = (struct arm_saved_state *)$kgm_thread.machine.kstackptr
2222 set $mysp = $kgm_statep->r[7]
2223 end
2224 end
91447636
A
2225 set $prevsp = 0
2226 printf "\n\t\tstacktop=0x%08x", $mysp
2d21ac55
A
2227 if ($arg2 == 0)
2228 switchtoact $arg0
2229 else
2230 switchtocorethread $arg0
2231 end
91447636
A
2232 bt
2233 else
2234 printf "\n\t\t\tcontinuation="
2235 output /a (unsigned) $kgm_thread.continuation
2236 end
2237 printf "\n"
2238 else
2239 printf "\n"
2240 end
2241end
2242
2243#Use of this macro is currently (8/04) blocked by the fact that gdb
2244#stops evaluating macros when encountering an error, such as a failure
2245#to read memory from a certain location. Until this issue (described in
2246#3758949) is addressed, evaluation of this macro may stop upon
2247#encountering such an error.
2248
2249define showallgdbstacks
2d21ac55 2250 set $kgm_head_taskp = &tasks
91447636
A
2251 set $kgm_taskp = (struct task *)($kgm_head_taskp->next)
2252 while $kgm_taskp != $kgm_head_taskp
2253 showtaskheader
2254 showtaskint $kgm_taskp
2255 set $kgm_head_actp = &($kgm_taskp->threads)
2256 set $kgm_actp = (struct thread *)($kgm_taskp->threads.next)
2257 while $kgm_actp != $kgm_head_actp
2258 showactheader
2d21ac55 2259 showgdbthread $kgm_actp 1 0
91447636
A
2260 set $kgm_actp = (struct thread *)($kgm_actp->task_threads.next)
2261 end
2262 printf "\n"
2d21ac55 2263 set $kgm_taskp = (struct task *)($kgm_taskp->tasks.next)
91447636
A
2264 end
2265 resetctx
2266end
2267
2268document showallgdbstacks
2269Syntax: showallgdbstacks
2270| An alternative to "showallstacks". Iterates through the task list and
2271| displays a gdb generated backtrace for each kernel thread. It is
2272| advantageous in that it is much faster than "showallstacks", and
2273| decodes function call arguments and displays source level traces, but
2274| it has the drawback that it doesn't determine if frames belong to
2275| functions from kernel extensions, as with "showallstacks".
2276| This command may terminate prematurely because of a gdb bug
2277| (Radar 3758949), which stops macro evaluation on memory read
2278| errors.
2279end
2280
2d21ac55
A
2281define showallgdbcorestacks
2282 select 0
2283 set $kgm_head_taskp = &tasks
2284 set $kgm_taskp = (struct task *)($kgm_head_taskp->next)
2285 while $kgm_taskp != $kgm_head_taskp
2286 showtaskheader
2287 showtaskint $kgm_taskp
2288 set $kgm_head_actp = &($kgm_taskp->threads)
2289 set $kgm_actp = (struct thread *)($kgm_taskp->threads.next)
2290 while $kgm_actp != $kgm_head_actp
2291 showactheader
2292 showgdbthread $kgm_actp 1 1
2293 set $kgm_actp = (struct thread *)($kgm_actp->task_threads.next)
2294 end
2295 printf "\n"
2296 set $kgm_taskp = (struct task *)($kgm_taskp->tasks.next)
2297 end
2298 resetcorectx
2299end
2300
2301
2302document showallgdbcorestacks
2303Syntax: showallgdbcorestacks
2304|Corefile version of "showallgdbstacks"
2305end
2306
2307
91447636 2308define switchtouserthread
2d21ac55 2309 select 0
91447636
A
2310 if ($kgm_mtype == 18)
2311 if ($kdp_act_counter == 0)
2312 set $kdpstate = (struct savearea *) kdp.saved_state
2313 end
2314 set $kdp_act_counter = $kdp_act_counter + 1
2315 set $newact = (struct thread *) $arg0
2316 _kgm_flush_loop
2317 set $checkpc = $newact->machine->upcb.save_srr0
2318 if ($checkpc == 0)
2319 echo This activation does not appear to have
2320 echo \20 a valid user context.\n
2321 else
2322 set (struct savearea *) kdp.saved_state=$newact->machine->upcb
2323 set $pc = $checkpc
2324#flush and update seem to be executed lazily by gdb on Tiger, hence the
2325#repeated invocations - see 3743135
2326 _kgm_flush_loop
2327# This works because the new pmap is used only for reads
2328 set kdp_pmap = $newact->task->map->pmap
2329 _kgm_flush_loop
2330 _kgm_update_loop
2331 end
2332 else
2333 echo switchtouserthread not implemented for this architecture.\n
2334 end
2335end
2336
2337document switchtouserthread
2338Syntax: switchtouserthread <address of thread>
2339| Analogous to switchtoact, but switches to the user context of a
2340| specified thread address. Similar to the "showuserstack"
2341| command, but this command does not return gdb to the kernel context
2342| immediately. This is to assist with the following (rather risky)
2343| manoeuvre - upon switching to the user context and virtual address
2344| space, the user may choose to call remove-symbol-file on the
2345| mach_kernel symbol file, and then add-symbol-file on the user space
2346| binary's symfile. gdb can then generate symbolic backtraces
2347| for the user space thread. To return to the
2348| kernel context and virtual address space, the process must be
2349| reversed, i.e. call remove-symbol-file on the user space symbols, and
2350| then add-symbol-file on the appropriate mach_kernel, and issue the
2351| "resetstacks" command. Note that gdb may not react kindly to all these
2352| symbol file switches. The same restrictions that apply to "showuserstack"
2353| apply here - pages that have been paged out cannot be read while in the
2354| debugger context, so backtraces may terminate early.
2355| If the virtual addresses in the stack trace do not conflict with those
2356| of symbols in the kernel's address space, it may be sufficient to
2357| just do an add-symbol-file on the user space binary's symbol file.
2358| Note that while this command works on Panther's gdb, an issue
2359| with Tiger gdb (3743135) appears to hamper the evaluation of this
2360| macro in some cases.
2361end
2362
2363define showmetaclass
91447636
A
2364 set $kgm_metaclassp = (OSMetaClass *)$arg0
2365 printf "%-5d", $kgm_metaclassp->instanceCount
2366 printf "x %5d bytes", $kgm_metaclassp->classSize
2367 printf " %s\n", $kgm_metaclassp->className->string
2368end
2369
0c530ab8
A
2370define showstring
2371 printf "\"%s\"", ((OSString *)$arg0)->string
2372end
2373
2374define shownumber
2375 printf "%lld", ((OSNumber *)$arg0)->value
2376end
2377
2378define showboolean
2379 if ($arg0 == gOSBooleanFalse)
2380 printf "No"
2381 else
2382 printf "Yes"
2383 end
2384end
2385
2386define showdata
2387 set $kgm_data = (OSData *)$arg0
2388
2389 printf "<"
2390 set $kgm_datap = (const unsigned char *) $kgm_data->data
2391
2392 set $kgm_printstr = 0
2393 if (0 == (3 & (unsigned int)$kgm_datap) && ($kgm_data->length >= 3))
2394 set $kgm_bytes = *(unsigned int *) $kgm_datap
2395 if (0xffff0000 & $kgm_bytes)
2396 set $kgm_idx = 0
2397 set $kgm_printstr = 1
2398 while ($kgm_idx++ < 4)
2399 set $kgm_bytes = $kgm_bytes >> 8
2400 set $kgm_char = 0xff & $kgm_bytes
2401 if ($kgm_char && (($kgm_char < 0x20) || ($kgm_char > 0x7e)))
2402 set $kgm_printstr = 0
2403 end
2404 end
2405 end
2406 end
2407
2408 set $kgm_idx = 0
2409 if ($kgm_printstr)
2410 set $kgm_quoted = 0
2411 while ($kgm_idx < $kgm_data->length)
2412 set $kgm_char = $kgm_datap[$kgm_idx++]
2413 if ($kgm_char)
2414 if (0 == $kgm_quoted)
2415 set $kgm_quoted = 1
2416 if ($kgm_idx > 1)
2417 printf ",\""
2418 else
2419 printf "\""
2420 end
2421 end
2422 printf "%c", $kgm_char
2423 else
2424 if ($kgm_quoted)
2425 set $kgm_quoted = 0
2426 printf "\""
2427 end
2428 end
2429 end
2430 if ($kgm_quoted)
2431 printf "\""
2432 end
2433 else
2434 if (0 == (3 & (unsigned int)$kgm_datap))
2435 while (($kgm_idx + 3) <= $kgm_data->length)
2436 printf "%08x", *(unsigned int *) &$kgm_datap[$kgm_idx]
2437 set $kgm_idx = $kgm_idx + 4
2438 end
2439 end
2440 while ($kgm_idx < $kgm_data->length)
2441 printf "%02x", $kgm_datap[$kgm_idx++]
2442 end
2443 end
2444 printf ">"
2445end
2446
2447define showdictionaryint
2448 set $kgm$arg0_dict = (OSDictionary *)$arg1
2449
2450 printf "{"
2451 set $kgm$arg0_idx = 0
2452 while ($kgm$arg0_idx < $kgm$arg0_dict->count)
2453 set $kgm_obj = $kgm$arg0_dict->dictionary[$kgm$arg0_idx].key
2454 showobjectint _$arg0 $kgm_obj
2455 printf "="
2456 set $kgm_obj = $kgm$arg0_dict->dictionary[$kgm$arg0_idx++].value
2457 showobjectint _$arg0 $kgm_obj
2458 if ($kgm$arg0_idx < $kgm$arg0_dict->count)
2459 printf ","
2460 end
2461 end
2462 printf "}"
2463end
2464
2465define indent
2466 set $kgm_idx = 0
2467 while ($kgm_idx < $arg0)
2468 if ($arg1 & (1 << $kgm_idx++))
2469 printf "| "
2470 else
2471 printf " "
2472 end
2473 end
2474end
2475
2476define showregdictionary
2477 indent $kgm_reg_depth+2 $arg1
2478 printf "{\n"
2479
2480 set $kgm_reg_idx = 0
2481 while ($kgm_reg_idx < $arg0->count)
2482 indent $kgm_reg_depth+2 $arg1
2483 printf " "
2484 set $kgm_obj = $arg0->dictionary[$kgm_reg_idx].key
2485 showobjectint _ $kgm_obj
2486 printf " = "
2487
2488 set $kgm_obj = $arg0->dictionary[$kgm_reg_idx++].value
2489 showobjectint _ $kgm_obj
2490 printf "\n"
2491 end
2492 indent $kgm_reg_depth+2 $arg1
2493 printf "}\n"
2494end
2495
2496
2497define showarraysetint
2498 set $kgm$arg0_array = (OSArray *)$arg1
2499
2500 set $kgm$arg0_idx = 0
2501 while ($kgm$arg0_idx < $kgm$arg0_array->count)
2502 set $kgm_obj = $kgm$arg0_array->array[$kgm$arg0_idx++]
2503 showobjectint _$arg0 $kgm_obj
2504 if ($kgm$arg0_idx < $kgm$arg0_array->count)
2505 printf ","
2506 end
2507 end
2508end
2509
2510define showarrayint
2511 printf "("
2512 showarraysetint $arg0 $arg1
2513 printf ")"
2514end
2515
2516define showsetint
2517 set $kgm_array = ((OSSet *)$arg1)->members
2518 printf "["
2519 showarraysetint $arg0 $kgm_array
2520 printf "]"
2521end
2522
2523
2524define showobjectint
2525 set $kgm_obj = (OSObject *) $arg1
2526 set $kgm_vt = *((void **) $arg1)
2527
2528 if ($kgm_show_object_addrs)
2529 printf "`object %p, vt ", $arg1
2530 output /a (unsigned) $kgm_vt
2531 if ($kgm_show_object_retain)
2532 printf ", retain count %d, container retain %d", (0xffff & $kgm_obj->retainCount), $kgm_obj->retainCount >> 16
2533 end
2534 printf "` "
2535 end
2536
2537 if ($kgm_vt == _ZTV8OSString)
2538 showstring $arg1
2539 else
2540 if ($kgm_vt == _ZTV8OSSymbol)
2541 showstring $arg1
2542 else
2543 if ($kgm_vt == _ZTV8OSNumber)
2544 shownumber $arg1
2545 else
2546 if ($kgm_vt == _ZTV6OSData)
2547 showdata $arg1
2548 else
2549 if ($kgm_vt == _ZTV9OSBoolean)
2550 showboolean $arg1
2551 else
2552 if ($kgm_vt == _ZTV12OSDictionary)
2553 showdictionaryint _$arg0 $arg1
2554 else
2555 if ($kgm_vt == _ZTV7OSArray)
2556 showarrayint _$arg0 $arg1
2557 else
2558 if ($kgm_vt == _ZTV5OSSet)
2559 showsetint _$arg0 $arg1
2560 else
2561 if ($kgm_show_object_addrs == 0)
2562 printf "`object %p, vt ", $arg1
2563 output /a (unsigned) $kgm_vt
2564 printf "`"
2565 end
2566 end
2567 end
2568 end
2569 end
2570 end
2571 end
2572 end
2573 end
2574end
2575
2576define showobject
2577 set $kgm_save = $kgm_show_object_addrs
2578 set $kgm_show_object_addrs = 1
2579 set $kgm_show_object_retain = 1
2580 showobjectint _ $arg0
2581 set $kgm_show_object_addrs = $kgm_save
2582 set $kgm_show_object_retain = 0
2583 printf "\n"
2584end
2585document showobject
2d21ac55 2586Syntax: (gdb) showobject <object address>
0c530ab8
A
2587| Show info about an OSObject - its vtable ptr and retain count.
2588| If the object is a simple container class, more info will be shown.
0c530ab8
A
2589end
2590
2591define dictget
2592 set $kgm_dictp = (OSDictionary *)$arg0
2593 set $kgm_keyp = (const OSSymbol *)$arg1
2594 set $kgm_idx = 0
2595 set $kgm_result = 0
2596 while (($kgm_idx < $kgm_dictp->count) && ($kgm_result == 0))
2597 if ($kgm_keyp == $kgm_dictp->dictionary[$kgm_idx].key)
2598 set $kgm_result = $kgm_dictp->dictionary[$kgm_idx].value
2599 end
2600 set $kgm_idx = $kgm_idx + 1
2601 end
2602end
2603
2604
2605define showregistryentryrecurse
2606 set $kgm_re = (IOService *)$arg1
2607 set $kgm$arg0_stack = (unsigned long long) $arg2
2608
2609 if ($arg3)
2610 set $kgm$arg0_stack = $kgm$arg0_stack | (1ULL << $kgm_reg_depth)
2611 else
2612 set $kgm$arg0_stack = $kgm$arg0_stack & ~(1ULL << $kgm_reg_depth)
2613 end
2614
2615 dictget $kgm_re->fRegistryTable $kgm_childkey
2616 set $kgm$arg0_child_array = (OSArray *) $kgm_result
2617
2618 if ($kgm$arg0_child_array)
2619 set $kgm$arg0_child_count = $kgm$arg0_child_array->count
2620 else
2621 set $kgm$arg0_child_count = 0
2622 end
2623
2624 if ($kgm$arg0_child_count)
2625 set $kgm$arg0_stack = $kgm$arg0_stack | (2ULL << $kgm_reg_depth)
2626 else
2627 set $kgm$arg0_stack = $kgm$arg0_stack & ~(2ULL << $kgm_reg_depth)
2628 end
2629
2630 indent $kgm_reg_depth $kgm$arg0_stack
2631 printf "+-o "
2632
2633 dictget $kgm_re->fRegistryTable $kgm_namekey
2634 if ($kgm_result == 0)
2635 dictget $kgm_re->fRegistryTable gIONameKey
2636 end
2637 if ($kgm_result == 0)
2638 dictget $kgm_re->fPropertyTable gIOClassKey
2639 end
2640
2641 if ($kgm_result != 0)
2642 printf "%s", ((OSString *)$kgm_result)->string
2643 else
2d21ac55
A
2644 if (((IOService*)$kgm_re)->pwrMgt && ((IOService*)$kgm_re)->pwrMgt->Name)
2645 printf "%s", ((IOService*)$kgm_re)->pwrMgt->Name
0c530ab8
A
2646 else
2647# printf ", guessclass "
2648# guessclass $kgm_re
2649 printf "??"
2650 end
2651 end
2652
2653
2654 printf " <object %p, ", $kgm_re
2655 printf "vtable "
2656 set $kgm_vt = (unsigned) *(void**) $kgm_re
2657 output /a $kgm_vt
2658
2659 if ($kgm_vt != _ZTV15IORegistryEntry)
2660 printf ", "
2661 set $kgm_state = $kgm_re->__state[0]
2662 # kIOServiceRegisteredState
2663 if (0 == ($kgm_state & 2))
2664 printf "!"
2665 end
2666 printf "registered, "
2667 # kIOServiceMatchedState
2668 if (0 == ($kgm_state & 4))
2669 printf "!"
2670 end
2671 printf "matched, "
2672 # kIOServiceInactiveState
2673 if ($kgm_state & 1)
2674 printf "in"
2675 end
2676 printf "active, busy %d, retain count %d", (0xff & $kgm_re->__state[1]), (0xffff & $kgm_re->retainCount)
2677 end
2678 printf ">\n"
2679
2680 if ($kgm_show_props)
2681 set $kgm_props = $kgm_re->fPropertyTable
2682 showregdictionary $kgm_props $kgm$arg0_stack
2683 end
2684
2685 # recurse
2686 if ($kgm$arg0_child_count != 0)
2687
2688 set $kgm_reg_depth = $kgm_reg_depth + 1
2689 set $kgm$arg0_child_idx = 0
2690
2691 while ($kgm$arg0_child_idx < $kgm$arg0_child_count)
2692 set $kgm_re = $kgm$arg0_child_array->array[$kgm$arg0_child_idx++]
2693 set $kgm_more_sib = ($kgm$arg0_child_idx < $kgm$arg0_child_count)
2694 showregistryentryrecurse _$arg0 $kgm_re $kgm$arg0_stack $kgm_more_sib
2695 end
2696
2697 set $kgm_reg_depth = $kgm_reg_depth - 1
2698 end
2699end
2700
2701define showregistryentryint
2702 set $kgm_namekey = (OSSymbol *) $kgm_reg_plane[2]
2703 set $kgm_childkey = (OSSymbol *) $kgm_reg_plane[4]
2704
2705 showregistryentryrecurse _ $arg0 0 0
2706end
2707
2708define showregistry
2709 set $kgm_reg_depth = 0
2710 set $kgm_show_props = 0
2711 showregistryentryint gRegistryRoot
2712end
2713document showregistry
2d21ac55 2714Syntax: (gdb) showregistry
0c530ab8 2715| Show info about all registry entries in the current plane.
0c530ab8
A
2716end
2717
2718define showregistryprops
2719 set $kgm_reg_depth = 0
2720 set $kgm_show_props = 1
2721 showregistryentryint gRegistryRoot
2722end
2723document showregistryprops
2d21ac55 2724Syntax: (gdb) showregistryprops
0c530ab8
A
2725| Show info about all registry entries in the current plane, and their properties.
2726| set $kgm_show_object_addrs = 1 and/or set $kgm_show_object_retain = 1 will display
2727| more verbose information
0c530ab8
A
2728end
2729
2730define showregistryentry
2731 set $kgm_reg_depth = 0
2732 set $kgm_show_props = 1
2733 showregistryentryint $arg0
2734end
2735document showregistryentry
2d21ac55 2736Syntax: (gdb) showregistryentry <object address>
0c530ab8 2737| Show info about a registry entry; its properties and descendants in the current plane.
0c530ab8
A
2738end
2739
2740define setregistryplane
2741 if ($arg0)
2742 set $kgm_reg_plane = (void **) $arg0
2743 else
2744 showobjectint _ gIORegistryPlanes
2745 printf "\n"
2746 end
2747end
2748document setregistryplane
2d21ac55 2749Syntax: (gdb) setregistryplane <plane object address>
0c530ab8
A
2750| Set the plane to be used for the iokit registry macros. An argument of zero will
2751| display known planes.
0c530ab8
A
2752end
2753
2754define guessclass
4452a7af 2755 set $kgm_classidx = 0
0c530ab8
A
2756 set $kgm_lookvt = *((void **) $arg0)
2757 set $kgm_bestvt = (void *) 0
2758 set $kgm_bestidx = 0
2759
4452a7af 2760 while $kgm_classidx < sAllClassesDict->count
6601e61a 2761 set $kgm_meta = (OSMetaClass *) sAllClassesDict->dictionary[$kgm_classidx].value
0c530ab8
A
2762
2763 set $kgm_vt = *((void **) $kgm_meta)
2764
2765 if (($kgm_vt > $kgm_bestvt) && ($kgm_vt < $kgm_lookvt))
2766 set $kgm_bestvt = $kgm_vt
2767 set $kgm_bestidx = $kgm_classidx
2768 end
6601e61a 2769 set $kgm_classidx = $kgm_classidx + 1
4452a7af 2770 end
0c530ab8 2771 printf "%s", sAllClassesDict->dictionary[$kgm_bestidx].key->string
4452a7af 2772end
0c530ab8
A
2773
2774define showallclasses
2775 set $kgm_classidx = 0
2776 while $kgm_classidx < sAllClassesDict->count
2777 set $kgm_meta = (OSMetaClass *) sAllClassesDict->dictionary[$kgm_classidx++].value
2778 showmetaclass $kgm_meta
2779 end
2780end
2781
91447636 2782document showallclasses
2d21ac55 2783Syntax: (gdb) showallclasses
91447636 2784| Show the instance counts and ivar size of all OSObject subclasses. See ioclasscount man page for details.
91447636
A
2785end
2786
2787define showioalloc
2788 printf " Instance allocation = 0x%08lx = %4ld K\n", (int) debug_ivars_size, ((int) debug_ivars_size) / 1024
2789 printf "Container allocation = 0x%08lx = %4ld K\n", (int) debug_container_malloc_size, ((int) debug_container_malloc_size) / 1024
2790 printf " IOMalloc allocation = 0x%08lx = %4ld K\n", (int) debug_iomalloc_size, ((int) debug_iomalloc_size) / 1024
2791 printf " Pageable allocation = 0x%08lx = %4ld K\n", (vm_size_t) debug_iomallocpageable_size, ((vm_size_t) debug_iomallocpageable_size) / 1024
2792end
2793
2794document showioalloc
2d21ac55 2795Syntax: (gdb) showioalloc
91447636 2796| Show some accounting of memory allocated by IOKit allocators. See ioalloccount man page for details.
2d21ac55
A
2797end
2798
2799define showosobjecttracking
2800 set $kgm_next = (OSObjectTracking *) gOSObjectTrackList.next
2801 while $kgm_next != &gOSObjectTrackList
2802 set $obj = (OSObject *) ($kgm_next+1)
2803 showobject $obj
2804 set $kgm_idx = 0
2805 while $kgm_idx < (sizeof($kgm_next->bt) / sizeof($kgm_next->bt[0]))
2806 if ((unsigned) $kgm_next->bt[$kgm_idx] > (unsigned) sectPRELINKB)
2807 showkmodaddr $kgm_next->bt[$kgm_idx]
2808 printf "\n"
2809 else
2810 if ((unsigned) $kgm_next->bt[$kgm_idx] > 0)
2811 output /a (unsigned) $kgm_next->bt[$kgm_idx]
2812 printf "\n"
2813 end
2814 end
2815 set $kgm_idx = $kgm_idx + 1
2816 end
2817 printf "\n"
2818 set $kgm_next = (OSObjectTracking *) $kgm_next->link.next
2819 end
2820end
2821
2822document showosobjecttracking
2823Syntax: (gdb) showosobjecttracking
2824| Show the list of tracked OSObject allocations with backtraces.
2825| Boot with the kOSTraceObjectAlloc (0x00400000) io debug flag set.
2826| Set gOSObjectTrackThread to 1 or a thread_t to capture new OSObjects allocated by a thread or all threads.
91447636 2827end
0c530ab8
A
2828
2829define readphys
2830 set kdp_trans_off = 1
2831 x/x $arg0
2832 set kdp_trans_off = 0
2833end
2834
2835define readphys64
2836 if ($kgm_mtype == 18)
2837 set kdp_src_high32 = ((uint32_t) ($arg0)) >> 32
2838 x/x (uint32_t) (($arg0) & 0x00000000ffffffffUL)
2839 set kdp_src_high32 = 0
2840 else
2841 echo readphys64 not available on this architecture.\n
2842 end
2843end
2844
2845document readphys
2846| The argument is interpreted as a physical address, and the word addressed is
2847| displayed. While this fails if no physical page exists at the given address,
2848| it must be used with caution.
2849end
2850
2851document readphys64
2852| The argument is interpreted as a 64-bit physical address, and the word
2853| addressed is displayed. While this fails if no physical page exists at the
2854| given address, it must be used with caution.
2855end
2d21ac55
A
2856
2857define addkextsyms
2858 shell ls $arg0/* | xargs -n 1 echo add-symbol-file > /tmp/gdb-syms
2859 source /tmp/gdb-syms
2860 set $kgm_show_kmod_syms = 1
2861end
2862
2863document addkextsyms
2864| Takes a directory of symbols for kexts generated with kextcache -y and loads them
2865| into gdb.
2866| (gdb) addkextsyms /path/to/symboldir
2867end
2868
2869define showprocfiles
2870 if ($argc == 1)
2871 _showprocheader
2872 _showprocfiles $arg0
2873 else
2874 printf "| Usage:\n|\n"
2875 help showprocfiles
2876 end
2877end
2878document showprocfiles
2879Syntax: (gdb) showprocfiles <proc_t>
2880| Given a proc_t pointer, display the list of open file descriptors for the
2881| referenced process.
2882end
2883
2884define _showprocheader
2885 printf "fd fileglob fg flags fg type fg data info\n"
2886 printf "----- ---------- ---------- -------- ---------- -------------------\n"
2887end
2888
2889define _showprocfiles
2890 set $kgm_spf_filedesc = ((proc_t)$arg0)->p_fd
2891 set $kgm_spf_last = $kgm_spf_filedesc->fd_lastfile
2892 set $kgm_spf_ofiles = $kgm_spf_filedesc->fd_ofiles
2893 set $kgm_spf_count = 0
2894 while ($kgm_spf_count <= $kgm_spf_last)
2895 if ($kgm_spf_ofiles[$kgm_spf_count] == 0)
2896 # DEBUG: For files that were open, but are now closed
2897 # printf "%-5d FILEPROC_NULL\n", $kgm_spf_count
2898 else
2899 # display fd #, fileglob address, fileglob flags
2900 set $kgm_spf_flags = $kgm_spf_ofiles[$kgm_spf_count].f_flags
2901 set $kgm_spf_fg = $kgm_spf_ofiles[$kgm_spf_count].f_fglob
2902 printf "%-5d 0x%08x 0x%08x ", $kgm_spf_count, $kgm_spf_fg, $kgm_spf_flags
2903 # decode fileglob type
2904 set $kgm_spf_fgt = $kgm_spf_fg->fg_type
2905 if ($kgm_spf_fgt == 1)
2906 printf "VNODE "
2907 end
2908 if ($kgm_spf_fgt == 2)
2909 printf "SOCKET "
2910 end
2911 if ($kgm_spf_fgt == 3)
2912 printf "PSXSHM "
2913 end
2914 if ($kgm_spf_fgt == 4)
2915 printf "PSXSEM "
2916 end
2917 if ($kgm_spf_fgt == 5)
2918 printf "KQUEUE "
2919 end
2920 if ($kgm_spf_fgt == 6)
2921 printf "PIPE "
2922 end
2923 if ($kgm_spf_fgt == 7)
2924 printf "FSEVENTS"
2925 end
2926 if ($kgm_spf_fgt < 1 || $kgm_spf_fgt > 7)
2927 printf "?: %-5d", $kgm_spf_fgt
2928 end
2929
2930 # display fileglob data address and decode interesting fact(s)
2931 # about data, if we know any
2932 set $kgm_spf_fgd = $kgm_spf_fg->fg_data
2933 printf " 0x%08x ", $kgm_spf_fgd
2934 if ($kgm_spf_fgt == 1)
2935 set $kgm_spf_name = ((struct vnode *)$kgm_spf_fgd)->v_name
2936 if ($kgm_spf_name == 0)
2937 printf "(null)"
2938 else
2939 printf "%s", $kgm_spf_name
2940 end
2941 end
2942 printf "\n"
2943 end
2944 set $kgm_spf_count = $kgm_spf_count + 1
2945 end
2946end
2947
2948#
2949# Show all the advisory file locks held by a process for each of the vnode
2950# type files that it has open; do this by walking the per process open file
2951# table and looking at any vnode type fileglob that has a non-NULL lock list
2952# associated with it.
2953#
2954define showproclocks
2955 if ($argc == 1)
2956 _showproclocks $arg0
2957 else
2958 printf "| Usage:\n|\n"
2959 help showproclocks
2960 end
2961end
2962document showproclocks
2963Syntax: (gdb) showproclocks <proc_t>
2964| Given a proc_t pointer, display the list of advisory file locks held by the
2965| referenced process.
2966end
2967
2968define _showproclocks
2969 set $kgm_spl_filedesc = ((proc_t)$arg0)->p_fd
2970 set $kgm_spl_last = $kgm_spl_filedesc->fd_lastfile
2971 set $kgm_spl_ofiles = $kgm_spl_filedesc->fd_ofiles
2972 set $kgm_spl_count = 0
2973 set $kgm_spl_seen = 0
2974 while ($kgm_spl_count <= $kgm_spl_last)
2975 if ($kgm_spl_ofiles[$kgm_spl_count] == 0)
2976 # DEBUG: For files that were open, but are now closed
2977 # printf "%-5d FILEPROC_NULL\n", $kgm_spl_count
2978 else
2979 set $kgm_spl_fg = $kgm_spl_ofiles[$kgm_spl_count].f_fglob
2980 # decode fileglob type
2981 set $kgm_spl_fgt = $kgm_spl_fg->fg_type
2982 if ($kgm_spl_fgt == 1)
2983 set $kgm_spl_fgd = $kgm_spl_fg->fg_data
2984 set $kgm_spl_name = ((struct vnode *)$kgm_spl_fgd)->v_name
2985 set $kgm_spl_vnode = ((vnode_t)$kgm_spl_fgd)
2986 set $kgm_spl_lockiter = $kgm_spl_vnode->v_lockf
2987 if ($kgm_spl_lockiter != 0)
2988 if ($kgm_spl_seen == 0)
2989 _showvnodelockheader
2990 end
2991 set $kgm_spl_seen = $kgm_spl_seen + 1
2992 printf "( fd %d, name ", $kgm_spl_count
2993 if ($kgm_spl_name == 0)
2994 printf "(null) )"
2995 else
2996 printf "%s )\n", $kgm_spl_name
2997 end
2998 _showvnodelocks $kgm_spl_fgd
2999 end
3000 end
3001 end
3002 set $kgm_spl_count = $kgm_spf_count + 1
3003 end
3004 printf "%d total locks for 0x%08x\n", $kgm_spl_seen, $arg0
3005end
3006
3007define showprocinfo
3008 set $kgm_spi_proc = (proc_t)$arg0
3009 printf "Process 0x%08x\n", $kgm_spi_proc
3010 printf " name %s\n", $kgm_spi_proc->p_comm
3011 printf " pid:%.8d", $kgm_spi_proc->p_pid
3012 printf " task:0x%.8x", $kgm_spi_proc->task
3013 printf " p_stat:%.1d", $kgm_spi_proc->p_stat
3014 printf " parent pid:%.8d", $kgm_spi_proc->p_ppid
3015 # decode part of credential
3016 set $kgm_spi_cred = $kgm_spi_proc->p_ucred
3017 if ($kgm_spi_cred != 0)
3018 printf "Cred: euid %d ruid %d svuid %d\n", $kgm_spi_cred->cr_uid, $kgm_spi_cred->cr_ruid, $kgm_spi_cred->cr_svuid
3019 else
3020 printf "Cred: (null)\n"
3021 end
3022 # decode flags
3023 set $kgm_spi_flag = $kgm_spi_proc->p_flag
3024 printf "Flags: 0x%08x\n", $kgm_spi_flag
3025 if ($kgm_spi_flag & 0x00000001)
3026 printf " 0x00000001 - may hold advisory locks\n"
3027 end
3028 if ($kgm_spi_flag & 0x00000002)
3029 printf " 0x00000002 - has a controlling tty\n"
3030 end
3031 if ($kgm_spi_flag & 0x00000004)
3032 printf " 0x00000004 - process is 64 bit\n"
3033 else
3034 printf " !0x00000004 - process is 32 bit\n"
3035 end
3036 if ($kgm_spi_flag & 0x00000008)
3037 printf " 0x00000008 - no SIGCHLD on child stop\n"
3038 end
3039 if ($kgm_spi_flag & 0x00000010)
3040 printf " 0x00000010 - waiting for child exec/exit\n"
3041 end
3042 if ($kgm_spi_flag & 0x00000020)
3043 printf " 0x00000020 - has started profiling\n"
3044 end
3045 if ($kgm_spi_flag & 0x00000040)
3046 printf " 0x00000040 - in select; wakeup/waiting danger\n"
3047 end
3048 if ($kgm_spi_flag & 0x00000080)
3049 printf " 0x00000080 - was stopped and continued\n"
3050 end
3051 if ($kgm_spi_flag & 0x00000100)
3052 printf " 0x00000100 - has set privileges since exec\n"
3053 end
3054 if ($kgm_spi_flag & 0x00000200)
3055 printf " 0x00000200 - system process: no signals, stats, or swap\n"
3056 end
3057 if ($kgm_spi_flag & 0x00000400)
3058 printf " 0x00000400 - timing out during a sleep\n"
3059 end
3060 if ($kgm_spi_flag & 0x00000800)
3061 printf " 0x00000800 - debugged process being traced\n"
3062 end
3063 if ($kgm_spi_flag & 0x00001000)
3064 printf " 0x00001000 - debugging process has waited for child\n"
3065 end
3066 if ($kgm_spi_flag & 0x00002000)
3067 printf " 0x00002000 - exit in progress\n"
3068 end
3069 if ($kgm_spi_flag & 0x00004000)
3070 printf " 0x00004000 - process has called exec\n"
3071 end
3072 if ($kgm_spi_flag & 0x00008000)
3073 printf " 0x00008000 - owe process an addupc() XXX\n"
3074 end
3075 if ($kgm_spi_flag & 0x00010000)
3076 printf " 0x00010000 - affinity for Rosetta children\n"
3077 end
3078 if ($kgm_spi_flag & 0x00020000)
3079 printf " 0x00020000 - wants to run Rosetta\n"
3080 end
3081 if ($kgm_spi_flag & 0x00040000)
3082 printf " 0x00040000 - has wait() in progress\n"
3083 end
3084 if ($kgm_spi_flag & 0x00080000)
3085 printf " 0x00080000 - kdebug tracing on for this process\n"
3086 end
3087 if ($kgm_spi_flag & 0x00100000)
3088 printf " 0x00100000 - blocked due to SIGTTOU or SIGTTIN\n"
3089 end
3090 if ($kgm_spi_flag & 0x00200000)
3091 printf " 0x00200000 - has called reboot()\n"
3092 end
3093 if ($kgm_spi_flag & 0x00400000)
3094 printf " 0x00400000 - is TBE state\n"
3095 end
3096 if ($kgm_spi_flag & 0x00800000)
3097 printf " 0x00800000 - signal exceptions\n"
3098 end
3099 if ($kgm_spi_flag & 0x01000000)
3100 printf " 0x01000000 - being branch traced\n"
3101 end
3102 if ($kgm_spi_flag & 0x02000000)
3103 printf " 0x02000000 - has vfork() children\n"
3104 end
3105 if ($kgm_spi_flag & 0x04000000)
3106 printf " 0x04000000 - not allowed to attach\n"
3107 end
3108 if ($kgm_spi_flag & 0x08000000)
3109 printf " 0x08000000 - vfork() in progress\n"
3110 end
3111 if ($kgm_spi_flag & 0x10000000)
3112 printf " 0x10000000 - no shared libraries\n"
3113 end
3114 if ($kgm_spi_flag & 0x20000000)
3115 printf " 0x20000000 - force quota for root\n"
3116 end
3117 if ($kgm_spi_flag & 0x40000000)
3118 printf " 0x40000000 - no zombies when children exit\n"
3119 end
3120 if ($kgm_spi_flag & 0x80000000)
3121 printf " 0x80000000 - don't hang on remote FS ops\n"
3122 end
3123 # decode state
3124 set $kgm_spi_state = $kgm_spi_proc->p_stat
3125 printf "State: "
3126 if ($kgm_spi_state == 1)
3127 printf "Idle\n"
3128 end
3129 if ($kgm_spi_state == 2)
3130 printf "Run\n"
3131 end
3132 if ($kgm_spi_state == 3)
3133 printf "Sleep\n"
3134 end
3135 if ($kgm_spi_state == 4)
3136 printf "Stop\n"
3137 end
3138 if ($kgm_spi_state == 5)
3139 printf "Zombie\n"
3140 end
3141 if ($kgm_spi_state == 6)
3142 printf "Reaping\n"
3143 end
3144 if ($kgm_spi_state < 1 || $kgm_spi_state > 6)
3145 printf "(Unknown)\n"
3146 end
3147end
3148
3149document showprocinfo
3150Syntax: (gdb) showprocinfo <proc_t>
3151| Displays name, pid, parent and task for a proc_t. Decodes cred, flag and p_stat fields.
3152end
3153
3154#
3155# dump the zombprocs
3156#
3157define zombproc
3158 set $basep = (struct proc *)zombproc->lh_first
3159 set $pp = $basep
3160 while $pp
3161 showprocinfo $pp
3162 set $pp = $pp->p_list.le_next
3163 end
3164end
3165
3166document zombproc
3167Syntax: (gdb) zombproc
3168| Routine to print out all procs in the zombie list
3169end
3170
3171#
3172# dump the zombstacks
3173#
3174define zombstacks
3175 set $basep = (struct proc *)zombproc->lh_first
3176 set $pp = $basep
3177 while $pp
3178 if $pp->p_stat != 5
3179 showtaskstacks $pp->task
3180 end
3181 set $pp = $pp->p_list.le_next
3182 end
3183end
3184
3185document zombstacks
3186Syntax: (gdb) zombstacks
3187| Routine to print out all stacks of tasks that are exiting
3188end
3189
3190
3191#
3192# dump the allprocs
3193#
3194define allproc
3195 set $basep = (struct proc *)allproc->lh_first
3196 set $pp = $basep
3197 while $pp
3198 showprocinfo $pp
3199 set $pp = $pp->p_list.le_next
3200 end
3201end
3202
3203document allproc
3204Syntax: (gdb) allproc
3205| Routine to print out all process in the system
3206| which are not in the zombie list
3207end
3208
3209
3210
3211define print_vnode
3212 set $vp = (struct vnode *)$arg0
3213 printf " "
3214 printf " vp 0x%.8x", $vp
3215 printf " use %d", $vp->v_usecount
3216 printf " io %d", $vp->v_iocount
3217 printf " kuse %d", $vp->v_kusecount
3218 printf " type %d", $vp->v_type
3219 printf " flg 0x%.8x", $vp->v_flag
3220 printf " lflg 0x%.8x", $vp->v_lflag
3221 printf " par 0x%.8x", $vp->v_parent
3222 set $_name = (char *)$vp->v_name
3223 if ($_name != 0)
3224 printf " %s", $_name
3225 end
3226 if ($vp->v_type == VREG) && ($vp->v_un.vu_ubcinfo != 0)
3227 printf " mapped %d", ($vp->v_un.vu_ubcinfo.ui_flags & 0x08) ? 1 : 0
3228 end
3229 printf "\n"
3230end
3231
3232document print_vnode
3233Syntax: (gdb) print_vnode <vnode>
3234| Prints out the fields of a vnode struct
3235end
3236
3237define showprocvnodes
3238 set $pp = (struct proc *)$arg0
3239 set $fdp = (struct filedesc *)$pp->p_fd
3240 set $cvp = $fdp->fd_cdir
3241 set $rvp = $fdp->fd_rdir
3242 if $cvp
3243 printf "Current Working Directory \n"
3244 print_vnode $cvp
3245 printf "\n"
3246 end
3247 if $rvp
3248 printf "Current Root Directory \n"
3249 print_vnode $rvp
3250 printf "\n"
3251 end
3252 set $count = 0
3253 set $fpp = (struct fileproc **)($fdp->fd_ofiles)
3254 set $fpo = (char)($fdp->fd_ofileflags[0])
3255 while $count < $fdp->fd_nfiles
3256 #printf"fpp %x ", *$fpp
3257 if *$fpp
3258 set $fg =(struct fileglob *)((**$fpp)->f_fglob)
3259 if $fg && (($fg)->fg_type == 1)
3260 if $fdp->fd_ofileflags[$count] & 4
3261 printf "U: "
3262 else
3263 printf " "
3264 end
3265 printf "fd = %d ", $count
3266 print_vnode $fg->fg_data
3267 end
3268 end
3269 set $fpp = $fpp + 1
3270 set $count = $count + 1
3271 end
3272end
3273
3274document showprocvnodes
3275Syntax: (gdb) showprocvnodes <proc_address>
3276| Routine to print out all the open fds
3277| which are vnodes in a process
3278end
3279
3280define showallprocvnodes
3281 set $basep = (struct proc *)allproc->lh_first
3282 set $pp = $basep
3283 while $pp
3284 printf "============================================ \n"
3285 showprocinfo $pp
3286 showprocvnodes $pp
3287 set $pp = $pp->p_list.le_next
3288 end
3289end
3290
3291document showallprocvnodes
3292Syntax: (gdb) showallprocvnodes
3293| Routine to print out all the open fds
3294| which are vnodes
3295end
3296
3297
3298#
3299# dump the childrent of a proc
3300#
3301define showinitchild
3302 set $basep = (struct proc *)initproc->p_children.lh_first
3303 set $pp = $basep
3304 while $pp
3305 showprocinfo $pp
3306 set $pp = $pp->p_sibling.le_next
3307 end
3308end
3309
3310document showinitchild
3311Syntax: (gdb) showinitchild
3312| Routine to print out all processes in the system
3313| which are children of init process
3314end
3315
3316
3317define showmountallvnodes
3318 set $mp = (struct mount *)$arg0
3319 set $basevp = (struct vnode *)$mp->mnt_vnodelist.tqh_first
3320 set $vp = $basevp
3321 printf "____________________ Vnode list Queue ---------------\n"
3322 while $vp
3323 print_vnode $vp
3324 set $vp = $vp->v_mntvnodes->tqe_next
3325 end
3326 set $basevp = (struct vnode *)$mp->mnt_workerqueue.tqh_first
3327 set $vp = $basevp
3328 printf "____________________ Worker Queue ---------------\n"
3329 while $vp
3330 print_vnode $vp
3331 set $vp = $vp->v_mntvnodes->tqe_next
3332 end
3333 set $basevp = (struct vnode *)$mp->mnt_newvnodes.tqh_first
3334 set $vp = $basevp
3335 printf "____________________ New vnodes Queue ---------------\n"
3336 while $vp
3337 print_vnode $vp
3338 set $vp = $vp->v_mntvnodes->tqe_next
3339 end
3340end
3341document showmountallvnodes
3342Syntax: showmountallvnodes <struct mount *>
3343| Print the vnode inactive list
3344end
3345
3346
3347define showmountvnodes
3348 set $mp = (struct mount *)$arg0
3349 set $basevp = (struct vnode *)$mp->mnt_vnodelist.tqh_first
3350 set $vp = $basevp
3351 printf "____________________ Vnode list Queue ---------------\n"
3352 while $vp
3353 print_vnode $vp
3354 set $vp = $vp->v_mntvnodes->tqe_next
3355 end
3356end
3357document showmountvnodes
3358Syntax: showmountvnodes <struct mount *>
3359| Print the vnode list
3360end
3361
3362
3363
3364define showworkqvnodes
3365 set $mp = (struct mount *)$arg0
3366 set $basevp = (struct vnode *)$mp->mnt_workerqueue.tqh_first
3367 set $vp = $basevp
3368 printf "____________________ Worker Queue ---------------\n"
3369 while $vp
3370 print_vnode $vp
3371 set $vp = $vp->v_mntvnodes->tqe_next
3372 end
3373end
3374document showworkqvnodes
3375Syntax: showworkqvnodes <struct mount *>
3376| Print the vnode worker list
3377end
3378
3379
3380define shownewvnodes
3381 set $mp = (struct mount *)$arg0
3382 set $basevp = (struct vnode *)$mp->mnt_newvnodes.tqh_first
3383 set $vp = $basevp
3384 printf "____________________ New vnodes Queue ---------------\n"
3385 while $vp
3386 print_vnode $vp
3387 set $vp = $vp->v_mntvnodes->tqe_next
3388 end
3389end
3390
3391document shownewvnodes
3392Syntax: shownewvnodes <struct mount *>
3393| Print the new vnode list
3394end
3395
3396
3397#
3398# print mount point info
3399define print_mount
3400 set $mp = (struct mount *)$arg0
3401 printf " "
3402 printf " mp 0x%.8x", $mp
3403 printf " flag %x", $mp->mnt_flag
3404 printf " kern_flag %x", $mp->mnt_kern_flag
3405 printf " lflag %x", $mp->mnt_lflag
3406 printf " type: %s", $mp->mnt_vfsstat.f_fstypename
3407 printf " mnton: %s", $mp->mnt_vfsstat.f_mntonname
3408 printf " mntfrom: %s", $mp->mnt_vfsstat.f_mntfromname
3409 printf "\n"
3410end
3411
3412define showallmounts
3413 set $mp=(struct mount *)mountlist.tqh_first
3414 while $mp
3415 print_mount $mp
3416 set $mp = $mp->mnt_list.tqe_next
3417 end
3418end
3419
3420document showallmounts
3421Syntax: showallmounts
3422| Print all mount points
3423end
3424
3425define pcprint
3426 set $pc = $arg0
3427 if ((unsigned int)$pc <= (unsigned int) $kgm_fkmodmax) && \
3428 ((unsigned int)$pc >= (unsigned int)$kgm_fkmodmin)
3429 showkmodaddr $pc
3430 else
3431 output/a $pc
3432 end
3433end
3434
3435define mbuf_walkpkt
3436 set $mp = (struct mbuf *)$arg0
3437 set $cnt = 1
3438 set $tot = 0
3439 while $mp
3440 printf "%4d: 0x%08x [len %4d, type %2d, ", $cnt, $mp, \
3441 $mp->m_hdr.mh_len, $mp->m_hdr.mh_type
3442 if mclaudit != 0
3443 mbuf_buf2mca $mp
3444 printf ", "
3445 end
3446 set $tot = $tot + $mp->m_hdr.mh_len
3447 printf "total %d]\n", $tot
3448 set $mp = $mp->m_hdr.mh_nextpkt
3449 set $cnt = $cnt + 1
3450 end
3451end
3452
3453document mbuf_walkpkt
3454Syntax: (gdb) mbuf_walkpkt <addr>
3455| Given an mbuf address, walk its m_nextpkt pointer
3456end
3457
3458define mbuf_walk
3459 set $mp = (struct mbuf *)$arg0
3460 set $cnt = 1
3461 set $tot = 0
3462 while $mp
3463 printf "%4d: 0x%08x [len %4d, type %2d, ", $cnt, $mp, \
3464 $mp->m_hdr.mh_len, $mp->m_hdr.mh_type
3465 if mclaudit != 0
3466 mbuf_buf2mca $mp
3467 printf ", "
3468 end
3469 set $tot = $tot + $mp->m_hdr.mh_len
3470 printf "total %d]\n", $tot
3471 set $mp = $mp->m_hdr.mh_next
3472 set $cnt = $cnt + 1
3473 end
3474end
3475
3476document mbuf_walk
3477Syntax: (gdb) mbuf_walk <addr>
3478| Given an mbuf address, walk its m_next pointer
3479end
3480
3481define mbuf_buf2slab
3482 set $addr = $arg0
3483 set $gix = ((char *)$addr - (char *)mbutl) >> 20
3484 set $ix = ((char *)$addr - (char *)mbutl) >> 11
3485 set $slab = &slabstbl[$gix].slg_slab[$ix]
3486 printf "0x%08x", $slab
3487end
3488
3489document mbuf_buf2slab
3490| Given an mbuf object, find its corresponding slab address.
3491end
3492
3493define mbuf_buf2mca
3494 set $addr = $arg0
3495 set $ix = ((char *)$addr - (char *)mbutl) >> 11
3496 set $clbase = ((union mcluster *)(mbutl + $ix))
3497 set $mclidx = (((char *)$addr - (char *)$clbase) >> 8)
3498 set $mca = mclaudit[$ix].cl_audit[$mclidx]
3499 printf "mca: 0x%08x", $mca
3500end
3501
3502document mbuf_buf2mca
3503Syntax: (gdb) mbuf_buf2mca <addr>
3504| Given an mbuf object, find its buffer audit structure address.
3505| This requires mbuf buffer auditing to be turned on, by setting
3506| the appropriate flags to the "mbuf_debug" boot-args parameter.
3507end
3508
3509define mbuf_showmca
3510 set language c
3511 set $mca = (mcache_audit_t *)$arg0
3512 set $cp = (mcache_t *)$mca->mca_cache
3513 printf "object type:\t\t"
3514 mbuf_mca_ctype $mca 1
3515 printf "\ncontrolling mcache:\t%p (%s)\n", $mca->mca_cache, $cp->mc_name
3516 if $mca->mca_uflags & $MB_SCVALID
3517 set $ix = ((char *)$mca->mca_addr - (char *)mbutl) >> 11
3518 set $clbase = ((union mcluster *)(mbutl + $ix))
3519 set $mclidx = (((char *)$mca->mca_addr - (char *)$clbase) >> 8)
3520 printf "mbuf obj:\t\t%p\n", $mca->mca_addr
3521 printf "mbuf index:\t\t%d (out of 8) in cluster base %p\n", \
3522 $mclidx + 1, $clbase
3523 if $mca->mca_uptr != 0
3524 set $peer_mca = (mcache_audit_t *)$mca->mca_uptr
3525 printf "paired cluster obj:\t%p (mca %p)\n", \
3526 $peer_mca->mca_addr, $peer_mca
3527 end
3528 printf "saved contents:\t\t%p (%d bytes)\n", \
3529 $mca->mca_contents, $mca->mca_contents_size
3530 else
3531 printf "cluster obj:\t\t%p\n", $mca->mca_addr
3532 if $mca->mca_uptr != 0
3533 set $peer_mca = (mcache_audit_t *)$mca->mca_uptr
3534 printf "paired mbuf obj:\t%p (mca %p)\n", \
3535 $peer_mca->mca_addr, $peer_mca
3536 end
3537 end
3538 printf "recent transaction for this buffer (thread %p):\n", \
3539 $mca->mca_thread
3540 set $cnt = 0
3541 while $cnt < $mca->mca_depth
3542 set $pc = $mca->mca_stack[$cnt]
3543 printf "%4d: ", $cnt + 1
3544 pcprint $pc
3545 printf "\n"
3546 set $cnt = $cnt + 1
3547 end
3548 if $mca->mca_pdepth > 0
3549 printf "previous transaction for this buffer (thread %p):\n", \
3550 $mca->mca_pthread
3551 end
3552 set $cnt = 0
3553 while $cnt < $mca->mca_pdepth
3554 set $pc = $mca->mca_pstack[$cnt]
3555 printf "%4d: ", $cnt + 1
3556 pcprint $pc
3557 printf "\n"
3558 set $cnt = $cnt + 1
3559 end
3560 set language auto
3561end
3562
3563document mbuf_showmca
3564Syntax: (gdb) mbuf_showmca <addr>
3565| Given an mbuf/cluster buffer audit structure address, print the audit
3566| records including the stack trace of the last buffer transaction.
3567end
3568
3569set $MCF_NOCPUCACHE = 0x10
3570
3571define mcache_stat
3572 set $head = (mcache_t *)mcache_head
3573 set $mc = $head
3574 printf "cache cache cache buf buf backing (# of retries) bufs\n"
3575 printf "name state addr size align zone wait nowait failed incache\n"
3576 printf "------------------------- -------- ---------- ------ ----- ---------- -------------------------- --------\n"
3577 while $mc != 0
3578 set $bktsize = $mc->mc_cpu.cc_bktsize
3579 printf "%-25s ", $mc->mc_name
3580 if ($mc->mc_flags & $MCF_NOCPUCACHE)
3581 printf "disabled"
3582 else
3583 if $mc->mc_purge_cnt > 0
3584 printf " purging"
3585 else
3586 if $bktsize == 0
3587 printf " offline"
3588 else
3589 printf " online"
3590 end
3591 end
3592 end
3593 printf " 0x%08x %6d %5d ",$mc, \
3594 $mc->mc_bufsize, $mc->mc_align
3595 if $mc->mc_slab_zone != 0
3596 printf "0x%08x", $mc->mc_slab_zone
3597 else
3598 printf " custom"
3599 end
3600 set $tot = 0
3601 set $tot += $mc->mc_full.bl_total * $bktsize
3602 set $ccp = (mcache_cpu_t *)$mc->mc_cpu
3603 set $n = 0
3604 while $n < ncpu
3605 if $ccp->cc_objs > 0
3606 set $tot += $ccp->cc_objs
3607 end
3608 if $ccp->cc_pobjs > 0
3609 set $tot += $ccp->cc_pobjs
3610 end
3611 set $n += 1
3612 set $ccp += 1
3613 end
3614 printf " %8d %8d %8d %8d", $mc->mc_wretry_cnt, \
3615 $mc->mc_nwretry_cnt, $mc->mc_nwfail_cnt, $tot
3616 printf "\n"
3617 set $mc = (mcache_t *)$mc->mc_list.le_next
3618 end
3619end
3620
3621document mcache_stat
3622Syntax: (gdb) mcache_stat
3623| Print all mcaches in the system.
3624end
3625
3626define mcache_showzone
3627 set $mc = (mcache_t *)$arg0
3628 if $mc->mc_slab_zone != 0
3629 printf "%p", $mc->mc_slab_zone
3630 else
3631 printf " custom"
3632end
3633
3634document mcache_showzone
3635Syntax: (gdb) mcache_showzone <mcache_addr>
3636| Print the type of backend (custom or zone) of a mcache.
3637end
3638
3639define mcache_walkobj
3640 set $p = (mcache_obj_t *)$arg0
3641 set $cnt = 1
3642 set $tot = 0
3643 while $p
3644 printf "%4d: 0x%08x\n", $cnt, $p,
3645 set $p = $p->obj_next
3646 set $cnt = $cnt + 1
3647 end
3648end
3649
3650document mcache_walkobj
3651Syntax: (gdb) mcache_walkobj <addr>
3652| Given a mcache object address, walk its obj_next pointer
3653end
3654
3655define mcache_showcache
3656 set $cp = (mcache_t *)$arg0
3657 set $ccp = (mcache_cpu_t *)$cp->mc_cpu
3658 set $bktsize = $cp->mc_cpu.cc_bktsize
3659 set $cnt = 0
3660 set $tot = 0
3661 printf "Showing cache '%s':\n\n", $cp->mc_name
3662 printf " CPU cc_objs cc_pobjs total\n"
3663 printf "---- -------- -------- --------\n"
3664 while $cnt < ncpu
3665 set $objs = $ccp->cc_objs
3666 if $objs <= 0
3667 set $objs = 0
3668 end
3669 set $pobjs = $ccp->cc_pobjs
3670 if $pobjs <= 0
3671 set $pobjs = 0
3672 end
3673 set $tot_cpu = $objs + $pobjs
3674 set $tot += $tot_cpu
3675 printf "%4d %8d %8d %8d\n", $cnt, $objs, $pobjs, $tot_cpu
3676 set $ccp += 1
3677 set $cnt += 1
3678 end
3679 printf " ========\n"
3680 printf " %8d\n", $tot
3681 printf "\n"
3682 set $tot += $cp->mc_full.bl_total * $bktsize
3683 printf "Total # of full buckets (%d objs/bkt):\t%-8d\n", \
3684 $bktsize, $cp->mc_full.bl_total
3685 printf "Total # of objects cached:\t\t%-8d\n", $tot
3686end
3687
3688document mcache_showcache
3689| Display the number of objects in the cache
3690end
3691
3692set $NSLABSPMB = sizeof(mcl_slabg_t)/sizeof(mcl_slab_t)
3693
3694define mbuf_slabstbl
3695 set $x = 0
3696
3697 printf "slot addr slabs range\n"
3698 printf "---- ---------- -----------------------\n"
3699 while $x < maxslabgrp
3700 set $slg = slabstbl[$x]
3701 printf "%3d: ", $x
3702 if $slg == 0
3703 printf "-\n"
3704 else
3705 printf "%p [%p-%p]\n", $slg, &$slg->slg_slab[0], \
3706 &$slg->slg_slab[$NSLABSPMB-1]
3707 end
3708 set $x += 1
3709 end
3710end
3711
3712document mbuf_slabstbl
3713| Display the mbuf slabs table
3714end
3715
3716set $SLF_MAPPED=0x0001
3717set $SLF_PARTIAL=0x0002
3718set $SLF_DETACHED=0x0004
3719
3720define mbuf_slabs
3721 set $slg = (mcl_slabg_t *)$arg0
3722 set $x = 0
3723
3724 printf "slot addr next base C R N size flags\n"
3725 printf "---- ---------- ---------- ---------- -- -- -- ------ -----\n"
3726 while $x < $NSLABSPMB
3727 set $sl = &$slg->slg_slab[$x]
3728 printf "%3d: 0x%08x 0x%08x 0x%08x %2d %2d %2d %6d 0x%04x ", \
3729 $x + 1, $sl, $sl->sl_next, $sl->sl_base, $sl->sl_class, \
3730 $sl->sl_refcnt, $sl->sl_chunks, $sl->sl_len, \
3731 $sl->sl_flags
3732 if $sl->sl_flags != 0
3733 printf "<"
3734 if $sl->sl_flags & $SLF_MAPPED
3735 printf "mapped"
3736 end
3737 if $sl->sl_flags & $SLF_PARTIAL
3738 printf ",partial"
3739 end
3740 if $sl->sl_flags & $SLF_DETACHED
3741 printf ",detached"
3742 end
3743 printf ">"
3744 end
3745 printf "\n"
3746 set $x += 1
3747 end
3748end
3749
3750document mbuf_slabs
3751| Display all mbuf slabs in the group
3752end
3753
3754define mbuf_stat
3755 set $x = 0
3756
3757 printf "class total cached uncached inuse failed waiter notified purge\n"
3758 printf "name objs objs objs / slabs objs alloc count count count count\n"
3759 printf "---------------- -------- -------- ------------------- -------- ---------------- -------- -------- --------\n"
3760 while $x < (sizeof(mbuf_table) / sizeof(mbuf_table[0]))
3761 set $mbt = mbuf_table[$x]
3762 set $mcs = (mb_class_stat_t *)mbuf_table[$x].mtbl_stats
3763 set $tot = 0
3764 set $mc = $mbt->mtbl_cache
3765 set $bktsize = $mc->mc_cpu.cc_bktsize
3766 set $tot += $mc->mc_full.bl_total * $bktsize
3767 set $ccp = (mcache_cpu_t *)$mc->mc_cpu
3768 set $n = 0
3769 while $n < ncpu
3770 if $ccp->cc_objs > 0
3771 set $tot += $ccp->cc_objs
3772 end
3773 if $ccp->cc_pobjs > 0
3774 set $tot += $ccp->cc_pobjs
3775 end
3776 set $n += 1
3777 set $ccp += 1
3778 end
3779
3780 printf "%-16s %8d %8d %8d / %-8d %8d %16llu %8d %8llu %8llu", \
3781 $mcs->mbcl_cname, $mcs->mbcl_total, $tot, \
3782 $mcs->mbcl_infree, $mcs->mbcl_slab_cnt, \
3783 ($mcs->mbcl_total - $tot - $mcs->mbcl_infree), \
3784 $mcs->mbcl_fail_cnt, $mc->mc_waiter_cnt, \
3785 $mcs->mbcl_notified, $mcs->mbcl_purge_cnt
3786 printf "\n"
3787 set $x += 1
3788 end
3789end
3790
3791document mbuf_stat
3792| Print extended mbuf allocator statistics.
3793end
3794
3795set $MB_INUSE = 0x1
3796set $MB_COMP_INUSE = 0x2
3797set $MB_SCVALID = 0x4
3798
3799set $MCLBYTES = 2048
3800set $MSIZE = 256
3801set $NBPG = 4096
3802set $M16KCLBYTES = 16384
3803
3804define mbuf_mca_ctype
3805 set $mca = (mcache_audit_t *)$arg0
3806 set $vopt = $arg1
3807 set $cp = $mca->mca_cache
3808 set $class = (unsigned int)$cp->mc_private
3809 set $csize = mbuf_table[$class].mtbl_stats->mbcl_size
3810 set $done = 0
3811 if $csize == $MSIZE
3812 if $vopt
3813 printf "M (mbuf) "
3814 else
3815 printf "M "
3816 end
3817 set $done = 1
3818 end
3819 if !$done && $csize == $MCLBYTES
3820 if $vopt
3821 printf "CL (2K cluster) "
3822 else
3823 printf "CL "
3824 end
3825 set $done = 1
3826 end
3827 if !$done && $csize == $NBPG
3828 if $vopt
3829 printf "BCL (4K cluster) "
3830 else
3831 printf "BCL "
3832 end
3833 set $done = 1
3834 end
3835 if !$done && $csize == $M16KCLBYTES
3836 if $vopt
3837 printf "JCL (16K cluster) "
3838 else
3839 printf "JCL "
3840 end
3841 set $done = 1
3842 end
3843 if !$done && $csize == ($MSIZE+$MCLBYTES)
3844 if $mca->mca_uflags & $MB_SCVALID
3845 if $mca->mca_uptr
3846 printf "M+CL "
3847 if $vopt
3848 printf "(paired mbuf, 2K cluster)"
3849 end
3850 else
3851 printf "M-CL "
3852 if $vopt
3853 printf "(unpaired mbuf, 2K cluster) "
3854 end
3855 end
3856 else
3857 if $mca->mca_uptr
3858 printf "CL+M "
3859 if $vopt
3860 printf "(paired 2K cluster, mbuf) "
3861 end
3862 else
3863 printf "CL-M "
3864 if $vopt
3865 printf "(paired 2K cluster, mbuf) "
3866 end
3867 end
3868 end
3869 set $done = 1
3870 end
3871 if !$done && $csize == ($MSIZE+$NBPG)
3872 if $mca->mca_uflags & $MB_SCVALID
3873 if $mca->mca_uptr
3874 printf "M+BCL "
3875 if $vopt
3876 printf "(paired mbuf, 4K cluster) "
3877 end
3878 else
3879 printf "M-BCL "
3880 if $vopt
3881 printf "(unpaired mbuf, 4K cluster) "
3882 end
3883 end
3884 else
3885 if $mca->mca_uptr
3886 printf "BCL+M "
3887 if $vopt
3888 printf "(paired 4K cluster, mbuf) "
3889 end
3890 else
3891 printf "BCL-M "
3892 if $vopt
3893 printf "(unpaired 4K cluster, mbuf) "
3894 end
3895 end
3896 end
3897 set $done = 1
3898 end
3899 if !$done && $csize == ($MSIZE+$M16KCLBYTES)
3900 if $mca->mca_uflags & $MB_SCVALID
3901 if $mca->mca_uptr
3902 printf "M+JCL "
3903 if $vopt
3904 printf "(paired mbuf, 16K cluster) "
3905 end
3906 else
3907 printf "M-JCL "
3908 if $vopt
3909 printf "(unpaired mbuf, 16K cluster) "
3910 end
3911 end
3912 else
3913 if $mca->mca_uptr
3914 printf "JCL+M "
3915 if $vopt
3916 printf "(paired 16K cluster, mbuf) "
3917 end
3918 else
3919 printf "JCL-M "
3920 if $vopt
3921 printf "(unpaired 16K cluster, mbuf) "
3922 end
3923 end
3924 end
3925 set $done = 1
3926 end
3927 if !$done
3928 printf "unknown: %s ", $cp->mc_name
3929 end
3930end
3931
3932document mbuf_mca_ctype
3933| This is a helper macro for mbuf_show{active,inactive,all} that prints
3934| out the mbuf object type represented by a given mcache audit structure.
3935end
3936
3937define mbuf_showactive
3938 mbuf_walkallslabs 1 0
3939end
3940
3941document mbuf_showactive
3942Syntax: (gdb) mbuf_showactive
3943| Walk the mbuf objects pool and print only the active ones; this
3944| requires mbuf debugging to be turned on, by setting the appropriate flags
3945| to the "mbuf_debug" boot-args parameter. Active objects are those that
3946| are outstanding (have not returned to the mbuf slab layer) and in use
3947| by the client (have not been freed).
3948end
3949
3950define mbuf_showinactive
3951 mbuf_walkallslabs 0 1
3952end
3953
3954document mbuf_showinactive
3955Syntax: (gdb) mbuf_showinactive
3956| Walk the mbuf objects pool and print only the inactive ones; this
3957| requires mbuf debugging to be turned on, by setting the appropriate flags
3958| to the "mbuf_debug" boot-args parameter. Inactive objects are those that
3959| are outstanding (have not returned to the mbuf slab layer) but have been
3960| freed by the client, i.e. they still reside in the mcache layer ready to
3961| be used for subsequent allocation requests.
3962end
3963
3964define mbuf_showall
3965 mbuf_walkallslabs 1 1
3966end
3967
3968document mbuf_showall
3969Syntax: (gdb) mbuf_showall
3970| Walk the mbuf objects pool and print them all; this requires
3971| mbuf debugging to be turned on, by setting the appropriate flags to the
3972| "mbuf_debug" boot-args parameter.
3973end
3974
3975define mbuf_mcaobjs
3976end
3977
3978define mbuf_walkallslabs
3979 set $show_a = $arg0
3980 set $show_f = $arg1
3981 set $x = 0
3982 set $total = 0
3983 set $total_a = 0
3984 set $total_f = 0
3985
3986 printf "("
3987 if $show_a && !$show_f
3988 printf "Searching only for active "
3989 end
3990 if !$show_a && $show_f
3991 printf "Searching only for inactive "
3992 end
3993 if $show_a && $show_f
3994 printf "Displaying all "
3995 end
3996 printf "objects; this may take a while ...)\n\n"
3997
3998 printf " slab mca obj allocation\n"
3999 printf "slot idx address address address type state\n"
4000 printf "---- ---- ---------- ---------- ---------- ----- -----------\n"
4001
4002 while $x < slabgrp
4003 set $slg = slabstbl[$x]
4004 set $y = 0
4005 set $stop = 0
4006 while $y < $NSLABSPMB && $stop == 0
4007 set $sl = &$slg->slg_slab[$y]
4008 set $base = (char *)$sl->sl_base
4009 set $ix = ($base - (char *)mbutl) >> 11
4010 set $clbase = ((union mcluster *)(mbutl + $ix))
4011 set $mclidx = ($base - (char *)$clbase) >> 8
4012 set $mca = mclaudit[$ix].cl_audit[$mclidx]
4013 set $first = 1
4014
4015 while $mca != 0 && $mca->mca_addr != 0
4016 set $printmca = 0
4017 if $mca->mca_uflags & ($MB_INUSE|$MB_COMP_INUSE)
4018 set $total_a = $total_a + 1
4019 set $printmca = $show_a
4020 else
4021 set $total_f = $total_f + 1
4022 set $printmca = $show_f
4023 end
4024
4025 if $printmca != 0
4026 if $first == 1
4027 printf "%4d %4d 0x%08x ", $x, $y, $sl
4028 else
4029 printf " "
4030 end
4031
4032 printf "0x%08x 0x%08x ", $mca, $mca->mca_addr
4033 mbuf_mca_ctype $mca 0
4034 if $mca->mca_uflags & ($MB_INUSE|$MB_COMP_INUSE)
4035 printf "active "
4036 else
4037 printf " freed "
4038 end
4039 if $first == 1
4040 set $first = 0
4041 end
4042 printf "\n"
4043 set $total = $total + 1
4044 end
4045 set $mca = $mca->mca_next
4046 end
4047 set $y += 1
4048 if $slg->slg_slab[$y].sl_base == 0
4049 set $stop = 1
4050 end
4051 end
4052 set $x += 1
4053 end
4054 if $total && $show_a && $show_f
4055 printf "\ntotal objects:\t%d\n", $total
4056 printf "active/unfreed:\t%d\n", $total_a
4057 printf "freed/in_cache:\t%d\n", $total_f
4058 end
4059end
4060
4061document mbuf_walkallslabs
4062| Walk the mbuf objects pool; this requires mbuf debugging to be
4063| turned on, by setting the appropriate flags to the "mbuf_debug" boot-args
4064| parameter. This is a backend routine for mbuf_show{active,inactive,all}.
4065end
4066
4067define rtentry_trash
4068 set $rtd = (struct rtentry_dbg *)rttrash_head.tqh_first
4069 set $cnt = 0
4070 while $rtd != 0
4071 if $cnt == 0
4072 printf " rtentry_dbg ref flags\n"
4073 printf " ------------ --- ----------\n"
4074 end
4075 printf "%4d: %p %3d 0x%08x\n", $cnt + 1, $rtd, \
4076 $rtd->rtd_refhold_cnt - $rtd->rtd_refrele_cnt, \
4077 $rtd->rtd_entry.rt_flags
4078 set $rtd = $rtd->rtd_trash_link.tqe_next
4079 set $cnt = $cnt + 1
4080 end
4081end
4082
4083document rtentry_trash
4084Syntax: (gdb) rtentry_trash
4085| Walk the list of trash route entries; this requires route entry
4086| debugging to be turned on, by setting the appropriate flags to the
4087| "rte_debug" boot-args parameter.
4088end
4089
4090set $RTD_TRSTACK_SIZE = 8
4091set $RTD_REFHIST_SIZE = 4
4092
4093define rtentry_showdbg
4094 set $rtd = (struct rtentry_dbg *)$arg0
4095 set $cnt = 0
4096
4097 printf "Total holds: %d\n", $rtd->rtd_refhold_cnt
4098 printf "Next hold slot: %d\n", $rtd->rtd_refhold_next
4099 printf "Total releases: %d\n", $rtd->rtd_refrele_cnt
4100 printf "Next release slot: %d\n", $rtd->rtd_refrele_next
4101
4102 set $ix = 0
4103 while $ix < $RTD_TRSTACK_SIZE
4104 set $pc = $rtd->rtd_alloc_stk_pc[$ix]
4105 if $pc != 0
4106 if $ix == 0
4107 printf "\nAlloc (thread %p):\n", \
4108 $rtd->rtd_alloc_thread
4109 end
4110 printf "%4d: ", $ix + 1
4111 pcprint $pc
4112 printf "\n"
4113 end
4114 set $ix = $ix + 1
4115 end
4116 set $ix = 0
4117 while $ix < $RTD_TRSTACK_SIZE
4118 set $pc = $rtd->rtd_free_stk_pc[$ix]
4119 if $pc != 0
4120 if $ix == 0
4121 printf "\nFree: (thread %p)\n", \
4122 $rtd->rtd_free_thread
4123 end
4124 printf "%4d: ", $ix + 1
4125 pcprint $pc
4126 printf "\n"
4127 end
4128 set $ix = $ix + 1
4129 end
4130 while $cnt < $RTD_REFHIST_SIZE
4131 set $ix = 0
4132 while $ix < $RTD_TRSTACK_SIZE
4133 set $pc = $rtd->rtd_refhold[$cnt].pc[$ix]
4134 if $pc != 0
4135 if $ix == 0
4136 printf "\nHold [%d] (thread %p):\n", \
4137 $cnt, $rtd->rtd_refhold[$cnt].th
4138 end
4139 printf "%4d: ", $ix + 1
4140 pcprint $pc
4141 printf "\n"
4142 end
4143 set $ix = $ix + 1
4144 end
4145 set $cnt = $cnt + 1
4146 end
4147 set $cnt = 0
4148 while $cnt < $RTD_REFHIST_SIZE
4149 set $ix = 0
4150 while $ix < $RTD_TRSTACK_SIZE
4151 set $pc = $rtd->rtd_refrele[$cnt].pc[$ix]
4152 if $pc != 0
4153 if $ix == 0
4154 printf "\nRelease [%d] (thread %p):\n",\
4155 $cnt, $rtd->rtd_refrele[$cnt].th
4156 end
4157 printf "%4d: ", $ix + 1
4158 pcprint $pc
4159 printf "\n"
4160 end
4161 set $ix = $ix + 1
4162 end
4163 set $cnt = $cnt + 1
4164 end
4165end
4166
4167document rtentry_showdbg
4168Syntax: (gdb) rtentry_showdbg <addr>
4169| Given a route entry structure address, print the debug information
4170| related to it. This requires route entry debugging to be turned
4171| on, by setting the appropriate flags to the "rte_debug" boot-args
4172| parameter.
4173end
4174
4175#
4176# print all OSMalloc stats
4177
4178define ostag_print
4179set $kgm_tagp = (OSMallocTag)$arg0
4180printf "0x%08x: ", $kgm_tagp
4181printf "%8d ",$kgm_tagp->OSMT_refcnt
4182printf "%8x ",$kgm_tagp->OSMT_state
4183printf "%8x ",$kgm_tagp->OSMT_attr
4184printf "%s ",$kgm_tagp->OSMT_name
4185printf "\n"
4186end
4187
4188
4189define showosmalloc
4190printf "TAG COUNT STATE ATTR NAME\n"
4191set $kgm_tagheadp = (OSMallocTag)&OSMalloc_tag_list
4192 set $kgm_tagptr = (OSMallocTag )($kgm_tagheadp->OSMT_link.next)
4193 while $kgm_tagptr != $kgm_tagheadp
4194 ostag_print $kgm_tagptr
4195 set $kgm_tagptr = (OSMallocTag)$kgm_tagptr->OSMT_link.next
4196 end
4197 printf "\n"
4198end
4199document showosmalloc
4200Syntax: (gdb) showosmalloc
4201| Print the outstanding allocation count by OSMallocTags.
4202end
4203
4204
4205define systemlog
4206 if msgbufp->msg_bufc[msgbufp->msg_bufx] == 0
4207 # The buffer hasn't wrapped, so take the easy (and fast!) path
4208 printf "%s", msgbufp->msg_bufc
4209 else
4210 set $kgm_msgbuf = *msgbufp
4211 set $kgm_syslog_bufsize = $kgm_msgbuf.msg_size
4212 set $kgm_syslog_bufend = $kgm_msgbuf.msg_bufx
4213 if $kgm_syslog_bufend >= $kgm_syslog_bufsize
4214 set $kgm_syslog_bufend = 0
4215 end
4216
4217 # print older messages from msg_bufx to end of buffer
4218 set $kgm_i = $kgm_syslog_bufend
4219 while $kgm_i < $kgm_syslog_bufsize
4220 set $kgm_syslog_char = $kgm_msgbuf.msg_bufc[$kgm_i]
4221 if $kgm_syslog_char == 0
4222 # break out of loop
4223 set $kgm_i = $kgm_syslog_bufsize
4224 else
4225 printf "%c", $kgm_syslog_char
4226 end
4227 set $kgm_i = $kgm_i + 1
4228 end
4229
4230 # print newer messages from start of buffer to msg_bufx
4231 set $kgm_i = 0
4232 while $kgm_i < $kgm_syslog_bufend
4233 set $kgm_syslog_char = $kgm_msgbuf.msg_bufc[$kgm_i]
4234 printf "%c", $kgm_syslog_char
4235 set $kgm_i = $kgm_i + 1
4236 end
4237 end
4238 printf "\n"
4239end
4240document systemlog
4241| Syntax: systemlog
4242| Display the kernel's printf ring buffer
4243end
4244
4245define printvnodepathint_recur
4246 if $arg0 != 0
4247 if ($arg0->v_flag & 0x000001) && ($arg0->v_mount != 0)
4248 if $arg0->v_mount->mnt_vnodecovered != 0
4249 printvnodepathint_recur $arg0->v_mount->mnt_vnodecovered $arg0->v_mount->mnt_vnodecovered->v_name
4250 end
4251 else
4252 printvnodepathint_recur $arg0->v_parent $arg0->v_parent->v_name
4253 printf "/%s", $arg1
4254 end
4255 end
4256end
4257
4258#
4259# Show the locks held on a vnode by range, type, and holder.
4260#
4261define showvnodelocks
4262 if ($argc == 1)
4263 _showvnodelockheader
4264 _showvnodelocks $arg0
4265 else
4266 printf "| Usage:\n|\n"
4267 help showvnodelocks
4268 end
4269end
4270document showvnodelocks
4271| Given a vnodet pointer, display the list of advisory record locks for the
4272| referenced pvnode.
4273| The following is the syntax:
4274| (gdb) showvnodelocks <vnode_t>
4275end
4276
4277define _showvnodelockheader
4278 printf "* type W held by lock type start end\n"
4279 printf "- ----- - ------------- --------- ------------------ ------------------\n"
4280end
4281
4282#
4283# Macro to display a single lock; used to display both held locks and
4284# blocked locks
4285#
4286define _showvnodelock
4287 set $kgm_svl_lock = ((struct lockf *)$arg0)
4288
4289 # decode flags
4290 set $kgm_svl_flags = $kgm_svl_lock->lf_flags
4291 set $kgm_svl_type = $kgm_svl_lock->lf_type
4292 if ($kgm_svl_flags & 0x20)
4293 printf "flock"
4294 end
4295 if ($kgm_svl_flags & 0x40)
4296 printf "posix"
4297 end
4298 if ($kgm_svl_flags & 0x80)
4299 printf "prov "
4300 end
4301 if ($kgm_svl_flags & 0x10)
4302 printf " W "
4303 else
4304 printf " . "
4305 end
4306
4307 # POSIX file vs. advisory range locks
4308 if ($kgm_svl_flags & 0x40)
4309 set $kgm_svl_proc = (proc_t)$kgm_svl_lock->lf_id
4310 printf "PID %8d ", $kgm_svl_proc->p_pid
4311 else
4312 printf "ID 0x%08x ", $kgm_svl_lock->lf_id
4313 end
4314
4315 # lock type
4316 if ($kgm_svl_type == 1)
4317 printf "shared "
4318 else
4319 if ($kgm_svl_type == 3)
4320 printf "exclusive "
4321 else
4322 if ($kgm_svl_type == 2)
4323 printf "unlock "
4324 else
4325 printf "unknown "
4326 end
4327 end
4328 end
4329
4330 # start and stop
4331 printf "0x%016x..", $kgm_svl_lock->lf_start
4332 printf "0x%016x ", $kgm_svl_lock->lf_end
4333 printf "\n"
4334end
4335
4336# Body of showvnodelocks, not including header
4337define _showvnodelocks
4338 set $kgm_svl_vnode = ((vnode_t)$arg0)
4339 set $kgm_svl_lockiter = $kgm_svl_vnode->v_lockf
4340 while ($kgm_svl_lockiter != 0)
4341 # locks that are held
4342 printf "H "
4343 _showvnodelock $kgm_svl_lockiter
4344
4345 # and any locks blocked by them
4346 set $kgm_svl_blocker = $kgm_svl_lockiter->lf_blkhd.tqh_first
4347 while ($kgm_svl_blocker != 0)
4348 printf "> "
4349 _showvnodelock $kgm_svl_blocker
4350 set $kgm_svl_blocker = $kgm_svl_blocker->lf_block.tqe_next
4351 end
4352
4353 # and on to the next one...
4354 set $kgm_svl_lockiter = $kgm_svl_lockiter->lf_next
4355 end
4356end
4357
4358define showvnodepath
4359 set $vp = (struct vnode *)$arg0
4360 if $vp != 0
4361 if ($vp->v_flag & 0x000001) && ($vp->v_mount != 0) && ($vp->v_mount->mnt_flag & 0x00004000)
4362 printf "/"
4363 else
4364 printvnodepathint_recur $vp $vp->v_name
4365 end
4366 end
4367 printf "\n"
4368end
4369
4370document showvnodepath
4371Syntax: (gdb) showvnodepath <vnode>
4372| Prints the path for a vnode
4373end
4374
4375define printcolonhex
4376 if ($argc == 2)
4377 set $addr = $arg0
4378 set $count = $arg1
4379 set $li = 0
4380 while ($li < $count)
4381 if ($li == 0)
4382 printf "%02x", (u_char)$addr[$li]
4383 end
4384 if ($li != 0)
4385 printf ":%02x", (u_char)$addr[$li]
4386 end
4387 set $li = $li + 1
4388 end
4389 end
4390end
4391
4392define showsockaddr_dl
4393 set $sdl = (struct sockaddr_dl *)$arg0
4394 printf "LINK "
4395 if ($sdl == 0)
4396 printf "(null)"
4397 else
4398 set $addr = $sdl->sdl_data + $sdl->sdl_nlen
4399 set $count = $sdl->sdl_alen
4400 printcolonhex $addr $count
4401 end
4402end
4403
4404define showsockaddr_unspec
4405 set $sockaddr = (struct sockaddr *)$arg0
4406 set $addr = $sockaddr->sa_data
4407 set $count = $sockaddr->sa_len - 2
4408 printf "UNSP "
4409 printcolonhex $addr $count
4410end
4411
4412define showsockaddr_at
4413 set $sockaddr = (struct sockaddr *)$arg0
4414 set $addr = $sockaddr->sa_data
4415 set $count = $sockaddr->sa_len - 2
4416 printf "ATLK "
4417 printcolonhex $addr $count
4418end
4419
4420define showsockaddr_in
4421 set $sin = (struct sockaddr_in *)$arg0
4422 set $sa_bytes = (unsigned char *)&($sin->sin_addr)
4423 printf "IPV4 %d.%d.%d.%d", $sa_bytes[0], $sa_bytes[1], $sa_bytes[2], $sa_bytes[3]
4424end
4425
4426define showsockaddr_in6
4427 set $sin6 = (struct sockaddr_in6 *)$arg0
4428 set $sa_bytes = $sin6->sin6_addr.__u6_addr.__u6_addr8
4429 printf "IPV6 %02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x", $sa_bytes[0], $sa_bytes[1], $sa_bytes[2], $sa_bytes[3], $sa_bytes[4], $sa_bytes[5], $sa_bytes[6], $sa_bytes[7], $sa_bytes[8], $sa_bytes[9], $sa_bytes[10], $sa_bytes[11], $sa_bytes[12], $sa_bytes[13], $sa_bytes[14], $sa_bytes[15]
4430end
4431
4432define showifmultiaddrs
4433 set $ifp = (struct ifnet *)$arg0
4434 set $if_multi = (struct ifmultiaddr *)$ifp->if_multiaddrs->lh_first
4435 set $mymulti = $if_multi
4436 set $myi = 0
4437 while ($mymulti != 0)
4438 printf "%2d. ", $myi
4439 set $sa_family = $mymulti->ifma_addr.sa_family
4440 if ($sa_family == 2)
4441 if ($mymulti->ifma_ll != 0)
4442 showsockaddr_dl $mymulti->ifma_ll->ifma_addr
4443 printf " "
4444 end
4445 showsockaddr_in $mymulti->ifma_addr
4446 end
4447 if ($sa_family == 30)
4448 if ($mymulti->ifma_ll != 0)
4449 showsockaddr_dl $mymulti->ifma_ll->ifma_addr
4450 printf " "
4451 end
4452 showsockaddr_in6 $mymulti->ifma_addr
4453 end
4454 if ($sa_family == 18)
4455 showsockaddr_dl $mymulti->ifma_addr
4456 end
4457 if ($sa_family == 0)
4458 showsockaddr_unspec $mymulti->ifma_addr 6
4459 end
4460 printf " [%d]", $mymulti->ifma_refcount
4461 printf "\n"
4462 set $mymulti = $mymulti->ifma_link.le_next
4463 set $myi = $myi + 1
4464 end
4465end
4466
4467document showifmultiaddrs
4468Syntax showifmultiaddrs <ifp>
4469| show the (struct ifnet).if_multiaddrs list of multicast addresses for the given ifp
4470end
4471
4472define showsockaddr
4473 set $mysock = (struct sockaddr *)$arg0
4474 set $showsockaddr_handled = 0
4475 if ($mysock == 0)
4476 printf "(null)"
4477 else
4478 if ($mysock->sa_family == 0)
4479 showsockaddr_unspec $mysock
4480 set $showsockaddr_handled = 1
4481 end
4482 if ($mysock->sa_family == 2)
4483 showsockaddr_in $mysock
4484 set $showsockaddr_handled = 1
4485 end
4486 if ($mysock->sa_family == 30)
4487 showsockaddr_in6 $mysock
4488 set $showsockaddr_handled = 1
4489 end
4490 if ($mysock->sa_family == 18)
4491 showsockaddr_dl $mysock
4492 set $showsockaddr_handled = 1
4493 end
4494 if ($mysock->sa_family == 16)
4495 showsockaddr_at $mysock
4496 set $showsockaddr_handled = 1
4497 end
4498 if ($showsockaddr_handled == 0)
4499 printf "%d ", $mysock->sa_family
4500 set $addr = $mysock->sa_data
4501 set $count = $mysock->sa_len
4502 printcolonhex $addr $count
4503 end
4504 end
4505end
4506
4507define showifflags
4508 set $flags = (u_short)$arg0
4509 set $first = 1
4510 printf "<"
4511 if ($flags & 0x1)
4512 printf "UP"
4513 set $first = 0
4514 end
4515 if ($flags & 0x2)
4516 if ($first == 1)
4517 set $first = 0
4518 else
4519 printf ","
4520 end
4521 printf "BROADCAST"
4522 end
4523 if ($flags & 0x4)
4524 printf "DEBUG"
4525 end
4526 if ($flags & 0x8)
4527 if ($first == 1)
4528 set $first = 0
4529 else
4530 printf ","
4531 end
4532 printf "LOOPBACK"
4533 end
4534 if ($flags & 0x10)
4535 if ($first == 1)
4536 set $first = 0
4537 else
4538 printf ","
4539 end
4540 printf "POINTTOPOINT"
4541 end
4542# if ($flags & 0x20)
4543# if ($first == 1)
4544# set $first = 0
4545# else
4546# printf ","
4547# end
4548# printf "NOTRAILERS"
4549# end
4550 if ($flags & 0x40)
4551 if ($first == 1)
4552 set $first = 0
4553 else
4554 printf ","
4555 end
4556 printf "RUNNING"
4557 end
4558 if ($flags & 0x80)
4559 if ($first == 1)
4560 set $first = 0
4561 else
4562 printf ","
4563 end
4564 printf "NOARP"
4565 end
4566 if ($flags & 0x100)
4567 if ($first == 1)
4568 set $first = 0
4569 else
4570 printf ","
4571 end
4572 printf "PROMISC"
4573 end
4574 if ($flags & 0x200)
4575 if ($first == 1)
4576 set $first = 0
4577 else
4578 printf ","
4579 end
4580 printf "ALLMULTI"
4581 end
4582 if ($flags & 0x400)
4583 if ($first == 1)
4584 set $first = 0
4585 else
4586 printf ","
4587 end
4588 printf "OACTIVE"
4589 end
4590 if ($flags & 0x800)
4591 if ($first == 1)
4592 set $first = 0
4593 else
4594 printf ","
4595 end
4596 printf "SIMPLEX"
4597 end
4598 if ($flags & 0x1000)
4599 if ($first == 1)
4600 set $first = 0
4601 else
4602 printf ","
4603 end
4604 printf "LINK0"
4605 end
4606 if ($flags & 0x2000)
4607 if ($first == 1)
4608 set $first = 0
4609 else
4610 printf ","
4611 end
4612 printf "LINK1"
4613 end
4614 if ($flags & 0x4000)
4615 if ($first == 1)
4616 set $first = 0
4617 else
4618 printf ","
4619 end
4620 printf "LINK2-ALTPHYS"
4621 end
4622 if ($flags & 0x8000)
4623 if ($first == 1)
4624 set $first = 0
4625 else
4626 printf ","
4627 end
4628 printf "MULTICAST"
4629 end
4630 printf ">"
4631end
4632
4633define showifaddrs
4634 set $ifp = (struct ifnet *)$arg0
4635 set $myifaddr = (struct ifaddr *)$ifp->if_addrhead->tqh_first
4636 set $myi = 0
4637 while ($myifaddr != 0)
4638 printf "\t%d. ", $myi
4639 showsockaddr $myifaddr->ifa_addr
4640 printf " [%d]\n", $myifaddr->ifa_refcnt
4641 set $myifaddr = $myifaddr->ifa_link->tqe_next
4642 set $myi = $myi + 1
4643 end
4644end
4645
4646document showifaddrs
4647Syntax: showifaddrs <ifp>
4648| show the (struct ifnet).if_addrhead list of addresses for the given ifp
4649end
4650
4651define ifconfig
4652 set $ifconfig_all = 0
4653 if ($argc == 1)
4654 set $ifconfig_all = 1
4655 end
4656 set $ifp = (struct ifnet *)(ifnet->tqh_first)
4657 while ($ifp != 0)
4658 printf "%s%d: flags=%x", $ifp->if_name, $ifp->if_unit, (u_short)$ifp->if_flags
4659 showifflags $ifp->if_flags
4660 printf " mtu %d\n", $ifp->if_data.ifi_mtu
4661 printf "\t(struct ifnet *)0x%x\n", $ifp
4662 if ($ifconfig_all == 1)
4663 showifaddrs $ifp
4664 end
4665 set $ifp = $ifp->if_link->tqe_next
4666 end
4667end
4668document ifconfig
4669Syntax: (gdb) ifconfig
4670| display ifconfig-like output, and print the (struct ifnet *) pointers for further inspection
4671end
4672
4673define showbpfdtab
4674 set $myi = 0
4675 while ($myi < bpf_dtab_size)
4676 if (bpf_dtab[$myi] != 0)
4677 printf "Address 0x%x, bd_next 0x%x\n", bpf_dtab[$myi], bpf_dtab[$myi]->bd_next
4678 print *bpf_dtab[$myi]
4679 end
4680 set $myi = $myi + 1
4681 end
4682end
4683
4684define showallvols
4685 printf "volume mnt_data mnt_devvp typename mountpoint\n"
4686 set $kgm_vol = (mount_t) mountlist.tqh_first
4687 while $kgm_vol
4688 printf "0x%08x ", $kgm_vol
4689 printf "0x%08x ", $kgm_vol->mnt_data
4690 printf "0x%08x ", $kgm_vol->mnt_devvp
4691 if ($kgm_vol->mnt_vtable->vfc_name[0] == 'h') && \
4692 ($kgm_vol->mnt_vtable->vfc_name[1] == 'f') && \
4693 ($kgm_vol->mnt_vtable->vfc_name[2] == 's') && \
4694 ($kgm_vol->mnt_vtable->vfc_name[3] == '\0')
4695 set $kgm_hfsmount = \
4696 (struct hfsmount *) $kgm_vol->mnt_data
4697 if $kgm_hfsmount->hfs_freezing_proc != 0
4698 printf "FROZEN hfs "
4699 else
4700 printf "hfs "
4701 end
4702 else
4703 printf "%-10s ", $kgm_vol->mnt_vtable->vfc_name
4704 end
4705 printf "%s\n", $kgm_vol->mnt_vfsstat.f_mntonname
4706
4707 set $kgm_vol = (mount_t) $kgm_vol->mnt_list.tqe_next
4708 end
4709end
4710
4711document showallvols
4712Syntax: (gdb) showallvols
4713| Display a summary of mounted volumes
4714end
4715
4716define showvnodeheader
4717 printf "vnode usecount iocount v_data vtype parent name\n"
4718end
4719
4720define showvnodeint
4721 set $kgm_vnode = (vnode_t) $arg0
4722 printf "0x%08x ", $kgm_vnode
4723 printf "%8d ", $kgm_vnode->v_usecount
4724 printf "%7d ", $kgm_vnode->v_iocount
4725# print information about clean/dirty blocks?
4726 printf "0x%08x ", $kgm_vnode->v_data
4727
4728 # print the vtype, using the enum tag
4729 set $kgm_vtype = $kgm_vnode->v_type
4730 if $kgm_vtype == VNON
4731 printf "VNON "
4732 end
4733 if $kgm_vtype == VREG
4734 printf "VREG "
4735 end
4736 if $kgm_vtype == VDIR
4737 printf "VDIR "
4738 end
4739 if $kgm_vtype == VBLK
4740 printf "VBLK "
4741 end
4742 if $kgm_vtype == VCHR
4743 printf "VCHR "
4744 end
4745 if $kgm_vtype == VLNK
4746 printf "VLNK "
4747 end
4748 if $kgm_vtype == VSOCK
4749 printf "VSOCK "
4750 end
4751 if $kgm_vtype == VFIFO
4752 printf "VFIFO "
4753 end
4754 if $kgm_vtype == VBAD
4755 printf "VBAD "
4756 end
4757 if ($kgm_vtype < VNON) || ($kgm_vtype > VBAD)
4758 printf "%5d ", $kgm_vtype
4759 end
4760
4761 printf "0x%08x ", $kgm_vnode->v_parent
4762 if $kgm_vnode->v_name != 0
4763 printf "%s\n", $kgm_vnode->v_name
4764 else
4765 printf "\n"
4766 end
4767end
4768
4769define showvnode
4770 showvnodeheader
4771 showvnodeint $arg0
4772end
4773
4774document showvnode
4775Syntax: (gdb) showvnode <vnode>
4776| Display info about one vnode
4777end
4778
4779define showvolvnodes
4780 showvnodeheader
4781 set $kgm_vol = (mount_t) $arg0
4782 set $kgm_vnode = (vnode_t) $kgm_vol.mnt_vnodelist.tqh_first
4783 while $kgm_vnode
4784 showvnodeint $kgm_vnode
4785 set $kgm_vnode = (vnode_t) $kgm_vnode->v_mntvnodes.tqe_next
4786 end
4787end
4788
4789document showvolvnodes
4790Syntax: (gdb) showvolvnodes <mouont_t>
4791| Display info about all vnodes of a given mount_t
4792end
4793
4794define showvolbusyvnodes
4795 showvnodeheader
4796 set $kgm_vol = (mount_t) $arg0
4797 set $kgm_vnode = (vnode_t) $kgm_vol.mnt_vnodelist.tqh_first
4798 while $kgm_vnode
4799 if $kgm_vnode->v_iocount != 0
4800 showvnodeint $kgm_vnode
4801 end
4802 set $kgm_vnode = (vnode_t) $kgm_vnode->v_mntvnodes.tqe_next
4803 end
4804end
4805
4806document showvolbusyvnodes
4807Syntax: (gdb) showvolbusyvnodes <mount_t>
4808| Display info about busy (iocount!=0) vnodes of a given mount_t
4809end
4810
4811define showallbusyvnodes
4812 showvnodeheader
4813 set $kgm_vol = (mount_t) mountlist.tqh_first
4814 while $kgm_vol
4815 set $kgm_vnode = (vnode_t) $kgm_vol.mnt_vnodelist.tqh_first
4816 while $kgm_vnode
4817 if $kgm_vnode->v_iocount != 0
4818 showvnodeint $kgm_vnode
4819 end
4820 set $kgm_vnode = (vnode_t) $kgm_vnode->v_mntvnodes.tqe_next
4821 end
4822 set $kgm_vol = (mount_t) $kgm_vol->mnt_list.tqe_next
4823 end
4824end
4825
4826document showallbusyvnodes
4827Syntax: (gdb) showallbusyvnodes <vnode>
4828| Display info about all busy (iocount!=0) vnodes
4829end
4830
4831define showallvnodes
4832 showvnodeheader
4833 set $kgm_vol = (mount_t) mountlist.tqh_first
4834 while $kgm_vol
4835 set $kgm_vnode = (vnode_t) $kgm_vol.mnt_vnodelist.tqh_first
4836 while $kgm_vnode
4837 showvnodeint $kgm_vnode
4838 set $kgm_vnode = (vnode_t) $kgm_vnode->v_mntvnodes.tqe_next
4839 end
4840 set $kgm_vol = (mount_t) $kgm_vol->mnt_list.tqe_next
4841 end
4842end
4843
4844document showallvnodes
4845Syntax: (gdb) showallvnodes
4846| Display info about all vnodes
4847end
4848
4849define _showvnodelockheader
4850 printf "* type W held by lock type start end\n"
4851 printf "- ----- - ------------- --------- ------------------ ------------------\n"
4852end
4853
4854define _showvnodelock
4855 set $kgm_svl_lock = ((struct lockf *)$arg0)
4856
4857 # decode flags
4858 set $kgm_svl_flags = $kgm_svl_lock->lf_flags
4859 set $kgm_svl_type = $kgm_svl_lock->lf_type
4860 if ($kgm_svl_flags & 0x20)
4861 printf "flock"
4862 end
4863 if ($kgm_svl_flags & 0x40)
4864 printf "posix"
4865 end
4866 if ($kgm_svl_flags & 0x80)
4867 printf "prov "
4868 end
4869 if ($kgm_svl_flags & 0x10)
4870 printf " W "
4871 else
4872 printf " . "
4873 end
4874
4875 # POSIX file vs. advisory range locks
4876 if ($kgm_svl_flags & 0x40)
4877 set $kgm_svl_proc = (proc_t)$kgm_svl_lock->lf_id
4878 printf "PID %8d ", $kgm_svl_proc->p_pid
4879 else
4880 printf "ID 0x%08x ", $kgm_svl_lock->lf_id
4881 end
4882
4883 # lock type
4884 if ($kgm_svl_type == 1)
4885 printf "shared "
4886 else
4887 if ($kgm_svl_type == 3)
4888 printf "exclusive "
4889 else
4890 if ($kgm_svl_type == 2)
4891 printf "unlock "
4892 else
4893 printf "unknown "
4894 end
4895 end
4896 end
4897
4898 # start and stop
4899 printf "0x%016x..", $kgm_svl_lock->lf_start
4900 printf "0x%016x ", $kgm_svl_lock->lf_end
4901 printf "\n"
4902end
4903# Body of showvnodelocks, not including header
4904define _showvnodelocks
4905 set $kgm_svl_vnode = ((vnode_t)$arg0)
4906 set $kgm_svl_lockiter = $kgm_svl_vnode->v_lockf
4907 while ($kgm_svl_lockiter != 0)
4908 # locks that are held
4909 printf "H "
4910 _showvnodelock $kgm_svl_lockiter
4911
4912 # and any locks blocked by them
4913 set $kgm_svl_blocker = $kgm_svl_lockiter->lf_blkhd.tqh_first
4914 while ($kgm_svl_blocker != 0)
4915 printf "> "
4916 _showvnodelock $kgm_svl_blocker
4917 set $kgm_svl_blocker = $kgm_svl_blocker->lf_block.tqe_next
4918 end
4919
4920 # and on to the next one...
4921 set $kgm_svl_lockiter = $kgm_svl_lockiter->lf_next
4922 end
4923end
4924
4925
4926define showvnodelocks
4927 if ($argc == 1)
4928 _showvnodelockheader
4929 _showvnodelocks $arg0
4930 else
4931 printf "| Usage:\n|\n"
4932 help showvnodelocks
4933 end
4934end
4935
4936document showvnodelocks
4937Syntax: (gdb) showvnodelocks <vnode_t>
4938| Given a vnodet pointer, display the list of advisory record locks for the
4939| referenced pvnodes
4940end
4941
4942define showbootargs
4943 printf "%s\n", (char*)((boot_args*)PE_state.bootArgs).CommandLine
4944end
4945
4946document showbootargs
4947Syntax: showbootargs
4948| Display boot arguments passed to the target kernel
4949end
4950
4951define showbootermemorymap
4952 set $kgm_boot_args = kernelBootArgs
4953 set $kgm_msize = kernelBootArgs->MemoryMapDescriptorSize
4954 set $kgm_mcount = kernelBootArgs->MemoryMapSize / $kgm_msize
4955 set $kgm_i = 0
4956
4957 printf "Type Physical Start Number of Pages\n"
4958 while $kgm_i < $kgm_mcount
4959 set $kgm_mptr = (EfiMemoryRange *)((unsigned long)kernelBootArgs->MemoryMap + $kgm_i * $kgm_msize)
4960# p/x *$kgm_mptr
4961 if $kgm_mptr->Type == 0
4962 printf "reserved "
4963 end
4964 if $kgm_mptr->Type == 1
4965 printf "LoaderCode"
4966 end
4967 if $kgm_mptr->Type == 2
4968 printf "LoaderData"
4969 end
4970 if $kgm_mptr->Type == 3
4971 printf "BS_code "
4972 end
4973 if $kgm_mptr->Type == 4
4974 printf "BS_data "
4975 end
4976 if $kgm_mptr->Type == 5
4977 printf "RT_code "
4978 end
4979 if $kgm_mptr->Type == 6
4980 printf "RT_data "
4981 end
4982 if $kgm_mptr->Type == 7
4983 printf "available "
4984 end
4985 if $kgm_mptr->Type == 8
4986 printf "Unusable "
4987 end
4988 if $kgm_mptr->Type == 9
4989 printf "ACPI_recl "
4990 end
4991 if $kgm_mptr->Type == 10
4992 printf "ACPI_NVS "
4993 end
4994 if $kgm_mptr->Type == 11
4995 printf "MemMapIO "
4996 end
4997 if $kgm_mptr->Type == 12
4998 printf "MemPortIO "
4999 end
5000 if $kgm_mptr->Type == 13
5001 printf "PAL_code "
5002 end
5003 if $kgm_mptr->Type > 13
5004 printf "UNKNOWN "
5005 end
5006
5007 printf " %016llx %016llx\n", $kgm_mptr->PhysicalStart, $kgm_mptr->NumberOfPages
5008 set $kgm_i = $kgm_i + 1
5009 end
5010end
5011
5012document showbootermemorymap
5013Syntax: (gdb) showbootermemorymap
5014| Prints out the phys memory map from kernelBootArgs
5015end
5016
5017
5018define showstacksaftertask
5019 set $kgm_head_taskp = &default_pset.tasks
5020 set $kgm_taskp = (struct task *)$arg0
5021 while $kgm_taskp != $kgm_head_taskp
5022 showtaskheader
5023 showtaskint $kgm_taskp
5024 set $kgm_head_actp = &($kgm_taskp->threads)
5025 set $kgm_actp = (struct thread *)($kgm_taskp->threads.next)
5026 while $kgm_actp != $kgm_head_actp
5027 showactheader
5028 if ($decode_wait_events > 0)
5029 showactint $kgm_actp 1
5030 else
5031 showactint $kgm_actp 2
5032 end
5033 set $kgm_actp = (struct thread *)($kgm_actp->task_threads.next)
5034 end
5035 printf "\n"
5036 set $kgm_taskp = (struct task *)($kgm_taskp->pset_tasks.next)
5037 end
5038end
5039document showstacksaftertask
5040Syntax: (gdb) showstacksaftertask <task>
5041| Routine to print out all stacks (as in showallstacks) starting after a given task
5042| Useful if that gdb refuses to print a certain task's stack.
5043end
5044
5045define showpmworkqueueint
5046 set $kgm_pm_wq = (IOPMWorkQueue *)$arg0
5047 set $kgm_pm_node = (IOService *)$kgm_pm_wq->owner
5048 printf "0x%08x 0x%08x ", $kgm_pm_wq, $kgm_pm_node
5049 printf "%02d ", $kgm_pm_node->pwrMgt->CurrentPowerState
5050 printf "%02d ", $kgm_pm_node->pwrMgt->MachineState
5051 printf "%02d ", $kgm_pm_node->pwrMgt->WaitReason
5052 printf "%s\n", $kgm_pm_node->pwrMgt->Name
5053 set $kgm_pm_queue = &($kgm_pm_wq->fWorkQueue)
5054 set $kgm_pm_req = (IOPMRequest *) $kgm_pm_queue->next
5055 while ( (queue_entry_t) $kgm_pm_req != (queue_entry_t) $kgm_pm_queue)
5056 printf " Request 0x%08x [%02x] Args ", $kgm_pm_req, $kgm_pm_req->fType
5057 printf "0x%08x ", $kgm_pm_req->fArg0
5058 printf "0x%08x ", $kgm_pm_req->fArg1
5059 printf "0x%08x\n", $kgm_pm_req->fArg2
5060 set $kgm_pm_req = (IOPMRequest *)$kgm_pm_req->fCommandChain.next
5061 end
5062end
5063
5064define showallpmworkqueues
5065 set $kgm_pm_next = gIOPMWorkLoop->eventChain
5066 printf "WorkQueue Owner PS MS WT Name\n"
5067 printf "--------------------------------------\n"
5068 while ( $kgm_pm_next )
5069 set $kgm_vt = *((void **) $kgm_pm_next)
5070 if ($kgm_vt == _ZTV13IOPMWorkQueue)
5071 showpmworkqueueint $kgm_pm_next
5072 end
5073 set $kgm_pm_next = $kgm_pm_next->eventChainNext
5074 end
5075end
5076
5077document showallpmworkqueues
5078Syntax: (gdb) showallpmworkqueues
5079| Display info about all IOPMWorkQueue objects
5080end
5081
5082define showioservicepm
5083 set $kgm_iopmpriv = (IOServicePM *)$arg0
5084 printf "{ this object = %08x", $kgm_iopmpriv->Owner
5085 if ( $kgm_iopmpriv->WeAreRoot )
5086 printf " (root)"
5087 end
5088 printf ", "
5089
5090 printf "MachineState = %d (", $kgm_iopmpriv->MachineState
5091 if ( $kgm_iopmpriv->MachineState == 1 )
5092 printf "kIOPM_OurChangeTellClientsPowerDown"
5093 else
5094 if ( $kgm_iopmpriv->MachineState == 2 )
5095 printf "kIOPM_OurChangeTellPriorityClientsPowerDown"
5096 else
5097 if ( $kgm_iopmpriv->MachineState == 3 )
5098 printf "kIOPM_OurChangeNotifyInterestedDriversWillChange"
5099 else
5100 if ( $kgm_iopmpriv->MachineState == 4 )
5101 printf "kIOPM_OurChangeSetPowerState"
5102 else
5103 if ( $kgm_iopmpriv->MachineState == 5 )
5104 printf "kIOPM_OurChangeWaitForPowerSettle"
5105 else
5106 if ( $kgm_iopmpriv->MachineState == 6 )
5107 printf "kIOPM_OurChangeNotifyInterestedDriversDidChange"
5108 else
5109 if ( $kgm_iopmpriv->MachineState == 7 )
5110 printf "kIOPM_OurChangeFinish"
5111 else
5112 if ( $kgm_iopmpriv->MachineState == 8 )
5113 printf "kIOPM_ParentDownTellPriorityClientsPowerDown"
5114 else
5115 if ( $kgm_iopmpriv->MachineState == 9 )
5116 printf "kIOPM_ParentDownNotifyInterestedDriversWillChange"
5117 else
5118 if ( $kgm_iopmpriv->MachineState == 10 )
5119 printf "Unused_MachineState_10"
5120 else
5121 if ( $kgm_iopmpriv->MachineState == 11 )
5122 printf "kIOPM_ParentDownNotifyDidChangeAndAcknowledgeChange"
5123 else
5124 if ( $kgm_iopmpriv->MachineState == 12 )
5125 printf "kIOPM_ParentDownSetPowerState"
5126 else
5127 if ( $kgm_iopmpriv->MachineState == 13 )
5128 printf "kIOPM_ParentDownWaitForPowerSettle"
5129 else
5130 if ( $kgm_iopmpriv->MachineState == 14 )
5131 printf "kIOPM_ParentDownAcknowledgeChange"
5132 else
5133 if ( $kgm_iopmpriv->MachineState == 15)
5134 printf "kIOPM_ParentUpSetPowerState"
5135 else
5136 if ( $kgm_iopmpriv->MachineState == 16)
5137 printf "Unused_MachineState_16"
5138 else
5139 if ( $kgm_iopmpriv->MachineState == 17)
5140 printf "kIOPM_ParentUpWaitForSettleTime"
5141 else
5142 if ( $kgm_iopmpriv->MachineState == 18)
5143 printf "kIOPM_ParentUpNotifyInterestedDriversDidChange"
5144 else
5145 if ( $kgm_iopmpriv->MachineState == 19)
5146 printf "kIOPM_ParentUpAcknowledgePowerChange"
5147 else
5148 if ( $kgm_iopmpriv->MachineState == 20)
5149 printf "kIOPM_Finished"
5150 else
5151 if ( $kgm_iopmpriv->MachineState == 21)
5152 printf "kIOPM_DriverThreadCallDone"
5153 else
5154 if ( $kgm_iopmpriv->MachineState == 22)
5155 printf "kIOPM_NotifyChildrenDone"
5156 end
5157 end
5158 end
5159 end
5160 end
5161 end
5162 end
5163 end
5164 end
5165 end
5166 end
5167 end
5168 end
5169 end
5170 end
5171 end
5172 end
5173 end
5174 end
5175 end
5176 end
5177 end
5178 printf "), "
5179
5180 if ( $kgm_iopmpriv->MachineState != 20 )
5181 printf "DriverTimer = %d, ",(unsigned int)$kgm_iopmpriv->DriverTimer
5182 printf "SettleTime = %d, ",(unsigned int)$kgm_iopmpriv->SettleTimeUS
5183 printf "HeadNoteFlags = %08x, ",(unsigned int)$kgm_iopmpriv->HeadNoteFlags
5184 printf "HeadNoteState = %d, ",(unsigned int)$kgm_iopmpriv->HeadNoteState
5185 printf "HeadNoteOutputFlags = %08x, ",(unsigned int)$kgm_iopmpriv->HeadNoteOutputFlags
5186 printf "HeadNoteDomainState = %08x, ",(unsigned int)$kgm_iopmpriv->HeadNoteDomainState
5187 printf "HeadNoteCapabilityFlags = %08x, ",(unsigned int)$kgm_iopmpriv->HeadNoteCapabilityFlags
5188 printf "HeadNotePendingAcks = %x, ",(unsigned int)$kgm_iopmpriv->HeadNotePendingAcks
5189 end
5190
5191 if ( $kgm_iopmpriv->DeviceOverrides != 0 )
5192 printf"DeviceOverrides, "
5193 end
5194
5195 printf "DriverDesire = %d, ",(unsigned int)$kgm_iopmpriv->DriverDesire
5196 printf "DeviceDesire = %d, ",(unsigned int)$kgm_iopmpriv->DeviceDesire
5197 printf "DesiredPowerState = %d, ",(unsigned int)$kgm_iopmpriv->DesiredPowerState
5198 printf "PreviousRequest = %d }",(unsigned int)$kgm_iopmpriv->PreviousRequest
5199end
5200
5201document showioservicepm
5202Syntax: (gdb) showioservicepm <IOServicePM pointer>
5203| Routine to dump the IOServicePM object
5204end
5205
5206define showregistryentryrecursepmstate
5207 set $kgm_re = (IOService *)$arg1
5208 set $kgm$arg0_stack = (unsigned long long) $arg2
5209
5210 if ($arg3)
5211 set $kgm$arg0_stack = $kgm$arg0_stack | (1ULL << $kgm_reg_depth)
5212 else
5213 set $kgm$arg0_stack = $kgm$arg0_stack & ~(1ULL << $kgm_reg_depth)
5214 end
5215
5216 dictget $kgm_re->fRegistryTable $kgm_childkey
5217 set $kgm$arg0_child_array = (OSArray *) $kgm_result
5218
5219 if ($kgm$arg0_child_array)
5220 set $kgm$arg0_child_count = $kgm$arg0_child_array->count
5221 else
5222 set $kgm$arg0_child_count = 0
5223 end
5224
5225 if ($kgm$arg0_child_count)
5226 set $kgm$arg0_stack = $kgm$arg0_stack | (2ULL << $kgm_reg_depth)
5227 else
5228 set $kgm$arg0_stack = $kgm$arg0_stack & ~(2ULL << $kgm_reg_depth)
5229 end
5230
5231 indent $kgm_reg_depth $kgm$arg0_stack
5232 printf "+-o "
5233
5234 dictget $kgm_re->fRegistryTable $kgm_namekey
5235 if ($kgm_result == 0)
5236 dictget $kgm_re->fRegistryTable gIONameKey
5237 end
5238 if ($kgm_result == 0)
5239 dictget $kgm_re->fPropertyTable gIOClassKey
5240 end
5241
5242 if ($kgm_result != 0)
5243 printf "%s <%p>", ((OSString *)$kgm_result)->string, $kgm_re
5244 else
5245 if (((IOService*)$kgm_re)->pwrMgt && ((IOService*)$kgm_re)->pwrMgt->Name)
5246 printf "%s <%p>", ((IOService*)$kgm_re)->pwrMgt->Name, $kgm_re
5247 else
5248 printf "?? <%p>", $kgm_re
5249 end
5250 end
5251
5252 if (((IOService*)$kgm_re)->pwrMgt )
5253 printf " Current Power State: %ld ", ((IOService*)$kgm_re)->pwrMgt->CurrentPowerState
5254 #printf " Mach State %ld", ((IOService*)$kgm_re)->pwrMgt->MachineState
5255 showioservicepm ((IOService*)$kgm_re)->pwrMgt
5256 end
5257 printf "\n"
5258
5259
5260 # recurse
5261 if ($kgm$arg0_child_count != 0)
5262
5263 set $kgm_reg_depth = $kgm_reg_depth + 1
5264 set $kgm$arg0_child_idx = 0
5265
5266 while ($kgm$arg0_child_idx < $kgm$arg0_child_count)
5267 set $kgm_re = $kgm$arg0_child_array->array[$kgm$arg0_child_idx++]
5268 set $kgm_more_sib = ($kgm$arg0_child_idx < $kgm$arg0_child_count)
5269 showregistryentryrecursepmstate _$arg0 $kgm_re $kgm$arg0_stack $kgm_more_sib
5270 end
5271
5272 set $kgm_reg_depth = $kgm_reg_depth - 1
5273 end
5274end
5275
5276define showregistryentryintpmstate
5277 set $kgm_namekey = (OSSymbol *) $kgm_reg_plane[2]
5278 set $kgm_childkey = (OSSymbol *) $kgm_reg_plane[4]
5279 showregistryentryrecursepmstate _ $arg0 0 0
5280end
5281
5282define showregistrypmstate
5283# setregistryplane gIOPowerPlane
5284 set $kgm_reg_depth = 0
5285 set $kgm_show_props = 1
5286 showregistryentryintpmstate gRegistryRoot
5287end
5288
5289document showregistrypmstate
5290Syntax: (gdb) showregistrypmstate
5291| Routine to dump the PM state of each IOPower registry entry
5292end
5293
5294define showstacksafterthread
5295 set $kgm_head_taskp = &default_pset.tasks
5296 set $kgm_actp = (struct thread *)$arg0
5297 set $kgm_actp = (struct thread *)($kgm_actp->task_threads.next)
5298 set $kgm_taskp = (struct task *)$kgm_actp->task
5299 while $kgm_taskp != $kgm_head_taskp
5300 showtaskheader
5301 showtaskint $kgm_taskp
5302 set $kgm_head_actp = &($kgm_taskp->threads)
5303 while $kgm_actp != $kgm_head_actp
5304 showactheader
5305 if ($decode_wait_events > 0)
5306 showactint $kgm_actp 1
5307 else
5308 showactint $kgm_actp 2
5309 end
5310 set $kgm_actp = (struct thread *)($kgm_actp->task_threads.next)
5311 end
5312 printf "\n"
5313 set $kgm_taskp = (struct task *)($kgm_taskp->pset_tasks.next)
5314 end
5315end
5316
5317document showstacksafterthread
5318Syntax: (gdb) showstacksafterthread <thread>
5319| Routine to print out all stacks (as in showallstacks) starting after a given thread
5320| Useful if that gdb refuses to print a certain task's stack.
5321end
5322
5323define kdp-reenter
5324 set kdp_reentry_deadline = ((unsigned) $arg0)*1000
5325 continue
5326end
5327
5328document kdp-reenter
5329Syntax: (gdb) kdp-reenter <seconds>
5330| Schedules reentry into the debugger after <seconds> seconds, and resumes
5331| the target system.
5332end
5333
5334define _if_present
5335 if (!$arg0)
5336 printf " not"
5337 end
5338 printf " present"
5339end
5340
5341define showMCAstate
5342 if ($kgm_mtype != 7)
5343 printf "Not available for current architecture.\n"
5344 else
5345 printf "MCA"
5346 _if_present mca_MCA_present
5347 printf ", control MSR"
5348 _if_present mca_control_MSR_present
5349 printf ", threshold status"
5350 _if_present mca_threshold_status_present
5351 printf "\n%d error banks, ", mca_error_bank_count
5352 printf "family code 0x%x, ", mca_family
5353 printf "machine-check exception taken: %d\n", mca_exception_taken
5354 set $kgm_cpu = 0
5355 while cpu_data_ptr[$kgm_cpu] != 0
5356 set $kgm_mcp = cpu_data_ptr[$kgm_cpu]->cpu_mca_state
5357 if $kgm_mcp
5358 printf "CPU %d:", $kgm_cpu
5359 printf " mca_mcg_ctl: 0x%016llx", $kgm_mcp->mca_mcg_ctl
5360 printf " mca_mcg_status: 0x%016llx\n", $kgm_mcp->mca_mcg_status.u64
5361 printf "bank "
5362 printf "mca_mci_ctl "
5363 printf "mca_mci_status "
5364 printf "mca_mci_addr "
5365 printf "mca_mci_misc\n"
5366 set $kgm_bank = 0
5367 while $kgm_bank < mca_error_bank_count
5368 set $kgm_bp = &$kgm_mcp->mca_error_bank[$kgm_bank]
5369 printf " %2d:", $kgm_bank
5370 printf " 0x%016llx", $kgm_bp->mca_mci_ctl
5371 printf " 0x%016llx", $kgm_bp->mca_mci_status.u64
5372 printf " 0x%016llx", $kgm_bp->mca_mci_addr
5373 printf " 0x%016llx\n", $kgm_bp->mca_mci_misc
5374 set $kgm_bank = $kgm_bank + 1
5375 end
5376 end
5377 set $kgm_cpu = $kgm_cpu + 1
5378 end
5379 end
5380end
5381
5382document showMCAstate
5383Syntax: showMCAstate
5384| Print machine-check register state after MC exception.
5385end