4 # These gdb macros should be useful during kernel development in
5 # determining what's going on in the kernel.
7 # All the convenience variables used by these macros begin with $kgm_
10 #Display version string, a pointer to which is pinned at 0x501C in the kernel's
17 | Read the kernel version string from a fixed address in low
18 | memory. Useful if you don't know which kernel is on the other end,
19 | and need to find the appropriate symbols. Beware that if you've
20 | loaded a symbol file, but aren't connected to a remote target,
21 | the version string from the symbol file will be displayed instead.
22 | This macro expects to be connected to the remote kernel to function
26 set $kgm_dummy = &proc0
27 set $kgm_dummy = &kmod
28 set $kgm_mtype = ((struct mach_header)_mh_execute_header).cputype
30 echo Loading Kernel GDB Macros package. Type "help kgm" for more info.\n
34 echo These are the gdb macros for kernel debugging. Type "help kgm" for more info.\n
38 | These are the kernel gdb macros. These gdb macros are intended to be
39 | used when debugging a remote kernel via the kdp protocol. Typically, you
40 | would connect to your remote target like so:
41 | (gdb) target remote-kdp
42 | (gdb) attach <name-of-remote-host>
44 | The following macros are available in this package:
45 | showversion Displays a string describing the remote kernel version
47 | showalltasks Display a summary listing of all tasks
48 | showallthreads Display info about all threads in the system
49 | showallstacks Display the stack for each thread in the system
50 | showcurrentthreads Display info about the thread running on each cpu
51 | showcurrentstacks Display the stack for the thread running on each cpu
52 | showallvm Display a summary listing of all the vm maps
53 | showallvme Display a summary listing of all the vm map entries
54 | showallipc Display a summary listing of all the ipc spaces
55 | showallrights Display a summary listing of all the ipc rights
56 | showallkmods Display a summary listing of all the kernel modules
57 | showallclasses Display info about all OSObject subclasses in the system
59 | showtask Display info about the specified task
60 | showtaskthreads Display info about the threads in the task
61 | showtaskstacks Display the stack for each thread in the task
62 | showtaskvm Display info about the specified task's vm_map
63 | showtaskvme Display info about the task's vm_map entries
64 | showtaskipc Display info about the specified task's ipc space
65 | showtaskrights Display info about the task's ipc space entries
67 | showact Display info about a thread specified by activation
68 | showactstack Display the stack for a thread specified by activation
70 | showmap Display info about the specified vm_map
71 | showmapvme Display a summary list of the specified vm_map's entries
73 | showipc Display info about the specified ipc space
74 | showrights Display a summary list of all the rights in an ipc space
76 | showpid Display info about the process identified by pid
77 | showproc Display info about the process identified by proc struct
79 | showkmod Display info about a kernel module
80 | showkmodaddr Given an address, display the kernel module and offset
82 | dumpcallqueue Dump out all the entries given a queue head
84 | showallmtx Display info about mutexes usage
85 | showallrwlck Display info about reader/writer locks usage
87 | zprint Display info about the memory zones
88 | showioalloc Display info about iokit allocations
89 | paniclog Display the panic log info
91 | switchtoact Switch to different context specified by activation
92 | switchtoctx Switch to different context
93 | showuserstack Display numeric backtrace of the user stack for an
96 | switchtouserthread Switch to the user context of the specified thread
97 | resetstacks Return to the original kernel context
99 | resetctx Reset context
100 | resume_on Resume when detaching from gdb
101 | resume_off Don't resume when detaching from gdb
103 | sendcore Configure kernel to send a coredump to the specified IP
104 | disablecore Configure the kernel to disable coredump transmission
105 | switchtocorethread Corefile version of "switchtoact"
106 | resetcorectx Corefile version of "resetctx"
108 | kdp-reboot Restart remote target
110 | Type "help <macro>" for more specific help on a particular macro.
111 | Type "show user <macro>" to see what the macro is really doing.
115 define showkmodheader
116 printf "kmod address size "
117 printf "id refs version name\n"
121 set $kgm_kmodp = (struct kmod_info *)$arg0
122 printf "0x%08x ", $arg0
123 printf "0x%08x ", $kgm_kmodp->address
124 printf "0x%08x ", $kgm_kmodp->size
125 printf "%3d ", $kgm_kmodp->id
126 printf "%5d ", $kgm_kmodp->reference_count
127 printf "%10s ", &$kgm_kmodp->version
128 printf "%s\n", &$kgm_kmodp->name
131 set $kgm_kmodmin = 0xffffffff
132 set $kgm_fkmodmin = 0x00000000
133 set $kgm_kmodmax = 0x00000000
134 set $kgm_fkmodmax = 0xffffffff
139 printf "0x%x" , $arg0
140 if ((unsigned int)$arg0 >= (unsigned int)$kgm_pkmodst) && ((unsigned int)$arg0 <= (unsigned int)$kgm_pkmoden)
141 set $kgm_off = ((unsigned int)$arg0 - (unsigned int)$kgm_pkmodst)
142 printf " <%s + 0x%x>", $kgm_pkmod->name, $kgm_off
144 if ((unsigned int)$arg0 <= (unsigned int)$kgm_fkmodmax) && ((unsigned int)$arg0 >= (unsigned int)$kgm_fkmodmin)
145 set $kgm_kmodp = (struct kmod_info *)kmod
147 set $kgm_kmod = *$kgm_kmodp
148 if $kgm_kmod.address && ($kgm_kmod.address < $kgm_kmodmin)
149 set $kgm_kmodmin = $kgm_kmod.address
151 if ($kgm_kmod.address + $kgm_kmod.size) > $kgm_kmodmax
152 set $kgm_kmodmax = $kgm_kmod.address
154 set $kgm_off = ((unsigned int)$arg0 - (unsigned int)$kgm_kmod.address)
155 if ($kgm_kmod.address <= $arg0) && ($kgm_off <= $kgm_kmod.size)
156 printf " <%s + 0x%x>", $kgm_kmodp->name, $kgm_off
157 set $kgm_pkmod = $kgm_kmodp
158 set $kgm_pkmodst = $kgm_kmod.address
159 set $kgm_pkmoden = $kgm_pkmodst + $kgm_kmod.size
162 set $kgm_kmodp = $kgm_kmod.next
166 set $kgm_fkmodmin = $kgm_kmodmin
167 set $kgm_fkmodmax = $kgm_kmodmax
172 document showkmodaddr
173 | Given an address, print the offset and name for the kmod containing it
174 | The following is the syntax:
175 | (gdb) showkmodaddr <addr>
183 | Routine to print info about a kernel module
184 | The following is the syntax:
185 | (gdb) showkmod <kmod>
190 set $kgm_kmodp = (struct kmod_info *)kmod
192 showkmodint $kgm_kmodp
193 set $kgm_kmodp = $kgm_kmodp->next
196 document showallkmods
197 | Routine to print a summary listing of all the kernel modules
198 | The following is the syntax:
203 printf " activation "
204 printf "thread pri state wait_queue wait_event\n"
209 printf " 0x%08x ", $arg0
210 set $kgm_thread = *(struct thread *)$arg0
211 printf "0x%08x ", $arg0
212 printf "%3d ", $kgm_thread.sched_pri
213 set $kgm_state = $kgm_thread.state
237 printf "0x%08x ", $kgm_thread.wait_queue
239 if ((unsigned)$kgm_thread.wait_event > (unsigned)sectPRELINKB)
240 showkmodaddr $kgm_thread.wait_event
242 output /a (unsigned) $kgm_thread.wait_event
246 if ($kgm_thread.kernel_stack != 0)
247 if ($kgm_thread.reserved_stack != 0)
248 printf "\n\t\treserved_stack=0x%08x", $kgm_thread.reserved_stack
250 printf "\n\t\tkernel_stack=0x%08x", $kgm_thread.kernel_stack
251 if ($kgm_mtype == 18)
252 set $mysp = $kgm_thread.machine.pcb->save_r1
254 set $kgm_statep = (struct i386_kernel_state *) \
255 ($kgm_thread->kernel_stack + 0x4000 \
256 - sizeof(struct i386_kernel_state))
257 set $mysp = $kgm_statep->k_ebp
260 printf "\n\t\tstacktop=0x%08x", $mysp
261 if ($kgm_mtype == 18)
263 set $stklimit = 0xb0000000
266 set $stklimit = 0xfc000000
268 while ($mysp != 0) && (($mysp & $stkmask) == 0) \
269 && ($mysp < $stklimit) \
270 && ((unsigned)$mysp > (unsigned)$prevsp)
271 printf "\n\t\t0x%08x ", $mysp
272 if ($kgm_mtype == 18)
273 set $kgm_return = *($mysp + 8)
275 set $kgm_return = *($mysp + 4)
277 if ((unsigned) $kgm_return > (unsigned) sectPRELINKB)
278 showkmodaddr $kgm_return
280 output /a (unsigned) $kgm_return
285 printf "\n\t\tstackbottom=0x%08x", $prevsp
287 printf "\n\t\t\tcontinuation="
288 output /a (unsigned) $kgm_thread.continuation
301 | Routine to print out the state of a specific thread.
302 | The following is the syntax:
303 | (gdb) showact <activation>
311 document showactstack
312 | Routine to print out the stack of a specific thread.
313 | The following is the syntax:
314 | (gdb) showactstack <activation>
318 define showallthreads
319 set $kgm_head_taskp = &default_pset.tasks
320 set $kgm_taskp = (struct task *)($kgm_head_taskp->next)
321 while $kgm_taskp != $kgm_head_taskp
323 showtaskint $kgm_taskp
325 set $kgm_head_actp = &($kgm_taskp->threads)
326 set $kgm_actp = (struct thread *)($kgm_taskp->threads.next)
327 while $kgm_actp != $kgm_head_actp
328 showactint $kgm_actp 0
329 set $kgm_actp = (struct thread *)($kgm_actp->task_threads.next)
332 set $kgm_taskp = (struct task *)($kgm_taskp->pset_tasks.next)
335 document showallthreads
336 | Routine to print out info about all threads in the system.
337 | The following is the syntax:
338 | (gdb) showallthreads
341 define showcurrentthreads
342 set $kgm_prp = processor_list
344 if ($kgm_prp)->active_thread != 0
345 set $kgm_actp = ($kgm_prp)->active_thread
347 showtaskint ($kgm_actp)->task
349 showactint $kgm_actp 0
352 set $kgm_prp = ($kgm_prp)->processor_list
355 document showcurrentthreads
356 | Routine to print out info about the thread running on each cpu.
357 | The following is the syntax:
358 | (gdb) showcurrentthreads
362 set $kgm_head_taskp = &default_pset.tasks
363 set $kgm_taskp = (struct task *)($kgm_head_taskp->next)
364 while $kgm_taskp != $kgm_head_taskp
366 showtaskint $kgm_taskp
367 set $kgm_head_actp = &($kgm_taskp->threads)
368 set $kgm_actp = (struct thread *)($kgm_taskp->threads.next)
369 while $kgm_actp != $kgm_head_actp
371 showactint $kgm_actp 1
372 set $kgm_actp = (struct thread *)($kgm_actp->task_threads.next)
375 set $kgm_taskp = (struct task *)($kgm_taskp->pset_tasks.next)
378 document showallstacks
379 | Routine to print out the stack for each thread in the system.
380 | The following is the syntax:
381 | (gdb) showallstacks
384 define showcurrentstacks
385 set $kgm_prp = processor_list
387 if ($kgm_prp)->active_thread != 0
388 set $kgm_actp = ($kgm_prp)->active_thread
390 showtaskint ($kgm_actp)->task
392 showactint $kgm_actp 1
395 set $kgm_prp = ($kgm_prp)->processor_list
398 document showcurrentstacks
399 | Routine to print out the thread running on each cpu (incl. its stack)
400 | The following is the syntax:
401 | (gdb) showcurrentstacks
404 define showwaiterheader
405 printf "waiters activation "
406 printf "thread pri state wait_queue wait_event\n"
409 define showwaitqwaiters
410 set $kgm_w_waitqp = (struct wait_queue *)$arg0
411 set $kgm_w_linksp = &($kgm_w_waitqp->wq_queue)
412 set $kgm_w_wqe = (struct wait_queue_element *)$kgm_w_linksp->next
414 while ( (queue_entry_t)$kgm_w_wqe != (queue_entry_t)$kgm_w_linksp)
415 if ($kgm_w_wqe->wqe_type != &_wait_queue_link)
420 set $kgm_w_shuttle = (struct thread *)$kgm_w_wqe
421 showactint $kgm_w_shuttle 0
423 set $kgm_w_wqe = (struct wait_queue_element *)$kgm_w_wqe->wqe_links.next
427 define showwaitqwaitercount
428 set $kgm_wc_waitqp = (struct wait_queue *)$arg0
429 set $kgm_wc_linksp = &($kgm_wc_waitqp->wq_queue)
430 set $kgm_wc_wqe = (struct wait_queue_element *)$kgm_wc_linksp->next
431 set $kgm_wc_count = 0
432 while ( (queue_entry_t)$kgm_wc_wqe != (queue_entry_t)$kgm_wc_linksp)
433 if ($kgm_wc_wqe->wqe_type != &_wait_queue_link)
434 set $kgm_wc_count = $kgm_wc_count + 1
436 set $kgm_wc_wqe = (struct wait_queue_element *)$kgm_wc_wqe->wqe_links.next
438 printf "0x%08x ", $kgm_wc_count
441 define showwaitqmembercount
442 set $kgm_mc_waitqsetp = (struct wait_queue_set *)$arg0
443 set $kgm_mc_setlinksp = &($kgm_mc_waitqsetp->wqs_setlinks)
444 set $kgm_mc_wql = (struct wait_queue_link *)$kgm_mc_setlinksp->next
445 set $kgm_mc_count = 0
446 while ( (queue_entry_t)$kgm_mc_wql != (queue_entry_t)$kgm_mc_setlinksp)
447 set $kgm_mc_count = $kgm_mc_count + 1
448 set $kgm_mc_wql = (struct wait_queue_link *)$kgm_mc_wql->wql_setlinks.next
450 printf "0x%08x ", $kgm_mc_count
454 define showwaitqmemberheader
455 printf "set-members wait_queue interlock "
456 printf "pol type member_cnt waiter_cnt\n"
459 define showwaitqmemberint
460 set $kgm_m_waitqp = (struct wait_queue *)$arg0
461 printf " 0x%08x ", $kgm_m_waitqp
462 printf "0x%08x ", $kgm_m_waitqp->wq_interlock.lock_data
463 if ($kgm_m_waitqp->wq_fifo)
468 if ($kgm_m_waitqp->wq_type == 0xf1d1)
470 showwaitqmembercount $kgm_m_waitqp
472 printf "Que 0x00000000 "
474 showwaitqwaitercount $kgm_m_waitqp
479 define showwaitqmemberofheader
480 printf "member-of wait_queue interlock "
481 printf "pol type member_cnt waiter_cnt\n"
484 define showwaitqmemberof
485 set $kgm_mo_waitqp = (struct wait_queue *)$arg0
486 set $kgm_mo_linksp = &($kgm_mo_waitqp->wq_queue)
487 set $kgm_mo_wqe = (struct wait_queue_element *)$kgm_mo_linksp->next
488 set $kgm_mo_found = 0
489 while ( (queue_entry_t)$kgm_mo_wqe != (queue_entry_t)$kgm_mo_linksp)
490 if ($kgm_mo_wqe->wqe_type == &_wait_queue_link)
492 set $kgm_mo_found = 1
493 showwaitqmemberofheader
495 set $kgm_mo_wqlp = (struct wait_queue_link *)$kgm_mo_wqe
496 set $kgm_mo_wqsetp = (struct wait_queue *)($kgm_mo_wqlp->wql_setqueue)
497 showwaitqmemberint $kgm_mo_wqsetp
499 set $kgm_mo_wqe = (struct wait_queue_element *)$kgm_mo_wqe->wqe_links.next
503 define showwaitqmembers
504 set $kgm_ms_waitqsetp = (struct wait_queue_set *)$arg0
505 set $kgm_ms_setlinksp = &($kgm_ms_waitqsetp->wqs_setlinks)
506 set $kgm_ms_wql = (struct wait_queue_link *)$kgm_ms_setlinksp->next
507 set $kgm_ms_found = 0
508 while ( (queue_entry_t)$kgm_ms_wql != (queue_entry_t)$kgm_ms_setlinksp)
509 set $kgm_ms_waitqp = $kgm_ms_wql->wql_element.wqe_queue
511 showwaitqmemberheader
512 set $kgm_ms_found = 1
514 showwaitqmemberint $kgm_ms_waitqp
515 set $kgm_ms_wql = (struct wait_queue_link *)$kgm_ms_wql->wql_setlinks.next
519 define showwaitqheader
520 printf "wait_queue ref_count interlock "
521 printf "pol type member_cnt waiter_cnt\n"
525 set $kgm_waitqp = (struct wait_queue *)$arg0
526 printf "0x%08x ", $kgm_waitqp
527 if ($kgm_waitqp->wq_type == 0xf1d1)
528 printf "0x%08x ", ((struct wait_queue_set *)$kgm_waitqp)->wqs_refcount
532 printf "0x%08x ", $kgm_waitqp->wq_interlock.lock_data
533 if ($kgm_waitqp->wq_fifo)
538 if ($kgm_waitqp->wq_type == 0xf1d1)
540 showwaitqmembercount $kgm_waitqp
542 printf "Que 0x00000000 "
544 showwaitqwaitercount $kgm_waitqp
549 set $kgm_waitq1p = (wait_queue_t)$arg0
551 showwaitqint $kgm_waitq1p
552 if ($kgm_waitq1p->wq_type == 0xf1d1)
553 showwaitqmembers $kgm_waitq1p
555 showwaitqmemberof $kgm_waitq1p
557 showwaitqwaiters $kgm_waitq1p
561 printf "vm_map pmap vm_size "
562 printf "#ents rpage hint first_free\n"
566 printf " entry start "
567 printf " prot #page object offset\n"
571 set $kgm_mapp = (vm_map_t)$arg0
572 set $kgm_map = *$kgm_mapp
573 printf "0x%08x ", $arg0
574 printf "0x%08x ", $kgm_map.pmap
575 printf "0x%08x ", $kgm_map.size
576 printf "%3d ", $kgm_map.hdr.nentries
578 printf "%5d ", $kgm_map.pmap->stats.resident_count
582 printf "0x%08x ", $kgm_map.hint
583 printf "0x%08x\n", $kgm_map.first_free
586 set $kgm_head_vmep = &($kgm_mapp->hdr.links)
587 set $kgm_vmep = $kgm_map.hdr.links.next
588 while (($kgm_vmep != 0) && ($kgm_vmep != $kgm_head_vmep))
589 set $kgm_vme = *$kgm_vmep
590 printf " 0x%08x ", $kgm_vmep
591 printf "0x%016llx ", $kgm_vme.links.start
592 printf "%1x", $kgm_vme.protection
593 printf "%1x", $kgm_vme.max_protection
594 if $kgm_vme.inheritance == 0x0
597 if $kgm_vme.inheritance == 0x1
600 if $kgm_vme.inheritance == 0x2
603 if $kgm_vme.inheritance == 0x3
606 if $kgm_vme.is_sub_map
609 if $kgm_vme.needs_copy
615 printf "%5d ",($kgm_vme.links.end - $kgm_vme.links.start) >> 12
616 printf "0x%08x ", $kgm_vme.object.vm_object
617 printf "0x%016llx\n", $kgm_vme.offset
618 set $kgm_vmep = $kgm_vme.links.next
630 | Routine to print out a summary listing of all the entries in a vm_map
631 | The following is the syntax:
632 | (gdb) showmapvme <vm_map>
641 | Routine to print out info about the specified vm_map
642 | The following is the syntax:
643 | (gdb) showmap <vm_map>
647 set $kgm_head_taskp = &default_pset.tasks
648 set $kgm_taskp = (struct task *)($kgm_head_taskp->next)
649 while $kgm_taskp != $kgm_head_taskp
652 showtaskint $kgm_taskp
653 showvmint $kgm_taskp->map 0
654 set $kgm_taskp = (struct task *)($kgm_taskp->pset_tasks.next)
658 | Routine to print a summary listing of all the vm maps
659 | The following is the syntax:
665 set $kgm_head_taskp = &default_pset.tasks
666 set $kgm_taskp = (struct task *)($kgm_head_taskp->next)
667 while $kgm_taskp != $kgm_head_taskp
670 showtaskint $kgm_taskp
671 showvmint $kgm_taskp->map 1
672 set $kgm_taskp = (struct task *)($kgm_taskp->pset_tasks.next)
676 | Routine to print a summary listing of all the vm map entries
677 | The following is the syntax:
683 printf "ipc_space is_table table_next "
684 printf "flags tsize splaytree splaybase\n"
687 define showipceheader
688 printf " name object "
689 printf "rite urefs destname destination\n"
693 set $kgm_ie = *(ipc_entry_t)$arg0
694 printf " 0x%08x ", $arg1
695 printf "0x%08x ", $kgm_ie.ie_object
696 if $kgm_ie.ie_bits & 0x00100000
698 printf "%5d\n", $kgm_ie.ie_bits & 0xffff
700 if $kgm_ie.ie_bits & 0x00080000
702 printf "%5d\n", $kgm_ie.ie_bits & 0xffff
704 if $kgm_ie.ie_bits & 0x00010000
705 if $kgm_ie.ie_bits & 0x00020000
711 if $kgm_ie.ie_bits & 0x00020000
715 if $kgm_ie.ie_bits & 0x00040000
718 if $kgm_ie.index.request
723 if $kgm_ie.ie_bits & 0x00800000
728 printf "%5d ", $kgm_ie.ie_bits & 0xffff
729 showportdest $kgm_ie.ie_object
735 set $kgm_isp = (ipc_space_t)$arg0
736 set $kgm_is = *$kgm_isp
737 printf "0x%08x ", $arg0
738 printf "0x%08x ", $kgm_is.is_table
739 printf "0x%08x ", $kgm_is.is_table_next
740 if $kgm_is.is_growing != 0
745 if $kgm_is.is_fast != 0
750 if $kgm_is.is_active != 0
755 printf "%5d ", $kgm_is.is_table_size
756 printf "0x%08x ", $kgm_is.is_tree_total
757 printf "0x%08x\n", &$kgm_isp->is_tree
761 set $kgm_iep = $kgm_is.is_table
762 set $kgm_destspacep = (ipc_space_t)0
763 while ( $kgm_iindex < $kgm_is.is_table_size )
764 set $kgm_ie = *$kgm_iep
765 if $kgm_ie.ie_bits & 0x001f0000
766 set $kgm_name = (($kgm_iindex << 8)|($kgm_ie.ie_bits >> 24))
767 showipceint $kgm_iep $kgm_name
769 set $kgm_iindex = $kgm_iindex + 1
770 set $kgm_iep = &($kgm_is.is_table[$kgm_iindex])
772 if $kgm_is.is_tree_total
773 printf "Still need to write tree traversal\n"
781 set $kgm_isp = (ipc_space_t)$arg0
783 showipcint $kgm_isp 0
786 | Routine to print the status of the specified ipc space
787 | The following is the syntax:
788 | (gdb) showipc <ipc_space>
792 set $kgm_isp = (ipc_space_t)$arg0
794 showipcint $kgm_isp 1
797 | Routine to print a summary list of all the rights in a specified ipc space
798 | The following is the syntax:
799 | (gdb) showrights <ipc_space>
804 set $kgm_taskp = (task_t)$arg0
807 showtaskint $kgm_taskp
808 showipcint $kgm_taskp->itk_space 0
811 | Routine to print info about the ipc space for a task
812 | The following is the syntax:
813 | (gdb) showtaskipc <task>
817 define showtaskrights
818 set $kgm_taskp = (task_t)$arg0
821 showtaskint $kgm_taskp
822 showipcint $kgm_taskp->itk_space 1
824 document showtaskrights
825 | Routine to print info about the ipc rights for a task
826 | The following is the syntax:
827 | (gdb) showtaskrights <task>
831 set $kgm_head_taskp = &default_pset.tasks
832 set $kgm_cur_taskp = (struct task *)($kgm_head_taskp->next)
833 while $kgm_cur_taskp != $kgm_head_taskp
836 showtaskint $kgm_cur_taskp
837 showipcint $kgm_cur_taskp->itk_space 0
838 set $kgm_cur_taskp = (struct task *)($kgm_cur_taskp->pset_tasks.next)
842 | Routine to print a summary listing of all the ipc spaces
843 | The following is the syntax:
849 set $kgm_head_taskp = &default_pset.tasks
850 set $kgm_cur_taskp = (struct task *)($kgm_head_taskp->next)
851 while $kgm_cur_taskp != $kgm_head_taskp
854 showtaskint $kgm_cur_taskp
855 showipcint $kgm_cur_taskp->itk_space 1
856 set $kgm_cur_taskp = (struct task *)($kgm_cur_taskp->pset_tasks.next)
859 document showallrights
860 | Routine to print a summary listing of all the ipc rights
861 | The following is the syntax:
862 | (gdb) showallrights
867 set $kgm_taskp = (task_t)$arg0
870 showtaskint $kgm_taskp
871 showvmint $kgm_taskp->map 0
874 | Routine to print out info about a task's vm_map
875 | The following is the syntax:
876 | (gdb) showtaskvm <task>
880 set $kgm_taskp = (task_t)$arg0
883 showtaskint $kgm_taskp
884 showvmint $kgm_taskp->map 1
887 | Routine to print out info about a task's vm_map_entries
888 | The following is the syntax:
889 | (gdb) showtaskvme <task>
893 define showtaskheader
894 printf "task vm_map ipc_space #acts "
900 set $kgm_task = *(struct task *)$arg0
901 printf "0x%08x ", $arg0
902 printf "0x%08x ", $kgm_task.map
903 printf "0x%08x ", $kgm_task.itk_space
904 printf "%3d ", $kgm_task.thread_count
905 showprocint $kgm_task.bsd_info
913 | Routine to print out info about a task.
914 | The following is the syntax:
915 | (gdb) showtask <task>
919 define showtaskthreads
921 set $kgm_taskp = (struct task *)$arg0
922 showtaskint $kgm_taskp
924 set $kgm_head_actp = &($kgm_taskp->threads)
925 set $kgm_actp = (struct thread *)($kgm_taskp->threads.next)
926 while $kgm_actp != $kgm_head_actp
927 showactint $kgm_actp 0
928 set $kgm_actp = (struct thread *)($kgm_actp->task_threads.next)
931 document showtaskthreads
932 | Routine to print info about the threads in a task.
933 | The following is the syntax:
934 | (gdb) showtaskthreads <task>
938 define showtaskstacks
940 set $kgm_taskp = (struct task *)$arg0
941 showtaskint $kgm_taskp
942 set $kgm_head_actp = &($kgm_taskp->threads)
943 set $kgm_actp = (struct thread *)($kgm_taskp->threads.next)
944 while $kgm_actp != $kgm_head_actp
946 showactint $kgm_actp 1
947 set $kgm_actp = (struct thread *)($kgm_actp->task_threads.next)
950 document showtaskstacks
951 | Routine to print out the stack for each thread in a task.
952 | The following is the syntax:
953 | (gdb) showtaskstacks <task>
959 set $kgm_head_taskp = &default_pset.tasks
960 set $kgm_taskp = (struct task *)($kgm_head_taskp->next)
961 while $kgm_taskp != $kgm_head_taskp
962 showtaskint $kgm_taskp
963 set $kgm_taskp = (struct task *)($kgm_taskp->pset_tasks.next)
966 document showalltasks
967 | Routine to print a summary listing of all the tasks
968 | The following is the syntax:
973 define showprocheader
974 printf " pid proc command\n"
978 set $kgm_procp = (struct proc *)$arg0
980 printf "%5d ", $kgm_procp->p_pid
981 printf "0x%08x ", $kgm_procp
982 printf "%s\n", $kgm_procp->p_comm
984 printf " *0* 0x00000000 --\n"
990 set $kgm_head_taskp = &default_pset.tasks
991 set $kgm_taskp = (struct task *)($kgm_head_taskp->next)
992 while $kgm_taskp != $kgm_head_taskp
993 set $kgm_procp = (struct proc *)$kgm_taskp->bsd_info
994 if (($kgm_procp != 0) && ($kgm_procp->p_pid == $arg0))
995 showtaskint $kgm_taskp
996 set $kgm_taskp = $kgm_head_taskp
998 set $kgm_taskp = (struct task *)($kgm_taskp->pset_tasks.next)
1003 | Routine to print a single process by pid
1004 | The following is the syntax:
1005 | (gdb) showpid <pid>
1010 set $kgm_procp = (struct proc *)$arg0
1011 showtaskint $kgm_procp->task $arg1 $arg2
1016 set switch_debugger=1
1020 | kdb - Switch to the inline kernel debugger
1024 | The kdb macro allows you to invoke the inline kernel debugger.
1027 define showpsetheader
1028 printf "portset waitqueue recvname "
1029 printf "flags refs recvname process\n"
1032 define showportheader
1033 printf "port mqueue recvname "
1034 printf "flags refs recvname process\n"
1037 define showportmemberheader
1038 printf "members port recvname "
1039 printf "flags refs mqueue msgcount\n"
1042 define showkmsgheader
1043 printf "messages kmsg size "
1044 printf "disp msgid remote-port local-port\n"
1048 printf " 0x%08x ", $arg0
1049 set $kgm_kmsgh = ((ipc_kmsg_t)$arg0)->ikm_header
1050 printf "0x%08x ", $kgm_kmsgh.msgh_size
1051 if (($kgm_kmsgh.msgh_bits & 0xff) == 19)
1056 if (($kgm_kmsgh.msgh_bits & 0xff00) == (19 < 8))
1061 if ($kgm_kmsgh.msgh_bits & 0xf0000000)
1066 printf "%5d ", $kgm_kmsgh.msgh_id
1067 printf "0x%08x ", $kgm_kmsgh.msgh_remote_port
1068 printf "0x%08x\n", $kgm_kmsgh.msgh_local_port
1074 set $kgm_portp = (struct ipc_port *)$arg0
1075 printf "0x%08x kobject(", $kgm_portp->ip_kobject
1076 set $kgm_kotype = ($kgm_portp->ip_object.io_bits & 0x00000fff)
1077 if ($kgm_kotype == 1)
1080 if ($kgm_kotype == 2)
1083 if ($kgm_kotype == 3)
1086 if ($kgm_kotype == 4)
1089 if ($kgm_kotype == 5)
1092 if ($kgm_kotype == 6)
1095 if ($kgm_kotype == 7)
1098 if ($kgm_kotype == 8)
1101 if ($kgm_kotype == 9)
1104 if ($kgm_kotype == 10)
1107 if ($kgm_kotype == 11)
1110 if ($kgm_kotype == 12)
1113 if ($kgm_kotype == 13)
1116 if ($kgm_kotype == 14)
1119 if ($kgm_kotype == 15)
1122 if ($kgm_kotype == 16)
1125 if ($kgm_kotype == 17)
1128 if ($kgm_kotype == 18)
1131 if ($kgm_kotype == 19)
1134 if ($kgm_kotype == 20)
1137 if ($kgm_kotype == 21)
1140 if ($kgm_kotype == 22)
1141 printf "IO_DONE_QUE"
1143 if ($kgm_kotype == 23)
1146 if ($kgm_kotype == 24)
1149 if ($kgm_kotype == 25)
1152 if ($kgm_kotype == 26)
1155 if ($kgm_kotype == 27)
1156 printf "IOKIT_SPARE"
1158 if ($kgm_kotype == 28)
1161 if ($kgm_kotype == 29)
1164 if ($kgm_kotype == 30)
1167 if ($kgm_kotype == 31)
1173 define showportdestproc
1174 set $kgm_portp = (struct ipc_port *)$arg0
1175 set $kgm_spacep = $kgm_portp->data.receiver
1176 # check against the previous cached value - this is slow
1177 if ($kgm_spacep != $kgm_destspacep)
1178 set $kgm_destprocp = (struct proc *)0
1179 set $kgm_head_taskp = &default_pset.tasks
1180 set $kgm_desttaskp = (struct task *)($kgm_head_taskp->next)
1181 while (($kgm_destprocp == 0) && ($kgm_desttaskp != $kgm_head_taskp))
1182 set $kgm_destspacep = $kgm_desttaskp->itk_space
1183 if ($kgm_destspacep == $kgm_spacep)
1184 set $kgm_destprocp = (struct proc *)$kgm_desttaskp->bsd_info
1186 set $kgm_desttaskp = (struct task *)($kgm_desttaskp->pset_tasks.next)
1190 if $kgm_destprocp != 0
1191 printf "%s(%d)\n", $kgm_destprocp->p_comm, $kgm_destprocp->p_pid
1193 printf "task 0x%08x\n", $kgm_desttaskp
1198 set $kgm_portp = (struct ipc_port *)$arg0
1199 set $kgm_spacep = $kgm_portp->data.receiver
1200 if ($kgm_spacep == ipc_space_kernel)
1201 showkobject $kgm_portp
1203 if ($kgm_portp->ip_object.io_bits & 0x80000000)
1204 printf "0x%08x ", $kgm_portp->ip_object.io_receiver_name
1205 showportdestproc $kgm_portp
1207 printf "0x%08x inactive-port\n", $kgm_portp
1212 define showportmember
1213 printf " 0x%08x ", $arg0
1214 set $kgm_portp = (struct ipc_port *)$arg0
1215 printf "0x%08x ", $kgm_portp->ip_object.io_receiver_name
1216 if ($kgm_portp->ip_object.io_bits & 0x80000000)
1221 if ($kgm_portp->ip_object.io_bits & 0x7fff0000)
1226 printf "%5d ", $kgm_portp->ip_object.io_references
1227 printf "0x%08x ", &($kgm_portp->ip_messages)
1228 printf "0x%08x\n", $kgm_portp->ip_messages.data.port.msgcount
1232 printf "0x%08x ", $arg0
1233 set $kgm_portp = (struct ipc_port *)$arg0
1234 printf "0x%08x ", &($kgm_portp->ip_messages)
1235 printf "0x%08x ", $kgm_portp->ip_object.io_receiver_name
1236 if ($kgm_portp->ip_object.io_bits & 0x80000000)
1242 printf "%5d ", $kgm_portp->ip_object.io_references
1243 set $kgm_destspacep = (struct ipc_space *)0
1244 showportdest $kgm_portp
1245 set $kgm_kmsgp = (ipc_kmsg_t)$kgm_portp->ip_messages.data.port.messages.ikmq_base
1246 if $arg1 && $kgm_kmsgp
1248 showkmsgint $kgm_kmsgp
1249 set $kgm_kmsgheadp = $kgm_kmsgp
1250 set $kgm_kmsgp = $kgm_kmsgp->ikm_next
1251 while $kgm_kmsgp != $kgm_kmsgheadp
1252 showkmsgint $kgm_kmsgp
1253 set $kgm_kmsgp = $kgm_kmsgp->ikm_next
1259 printf "0x%08x ", $arg0
1260 set $kgm_psetp = (struct ipc_pset *)$arg0
1261 printf "0x%08x ", &($kgm_psetp->ips_messages)
1262 printf "0x%08x ", $kgm_psetp->ips_object.io_receiver_name
1263 if ($kgm_psetp->ips_object.io_bits & 0x80000000)
1269 printf "%5d ", $kgm_psetp->ips_object.io_references
1270 printf "0x%08x ", $kgm_psetp->ips_object.io_receiver_name
1271 set $kgm_setlinksp = &($kgm_psetp->ips_messages.data.set_queue.wqs_setlinks)
1272 set $kgm_wql = (struct wait_queue_link *)$kgm_setlinksp->next
1274 while ( (queue_entry_t)$kgm_wql != (queue_entry_t)$kgm_setlinksp)
1275 set $kgm_portp = (struct ipc_port *)((int)($kgm_wql->wql_element->wqe_queue) - ((int)$kgm_portoff))
1277 set $kgm_destspacep = (struct ipc_space *)0
1278 showportdestproc $kgm_portp
1279 showportmemberheader
1282 showportmember $kgm_portp 0
1283 set $kgm_wql = (struct wait_queue_link *)$kgm_wql->wql_setlinks.next
1300 define showipcobject
1301 set $kgm_object = (ipc_object_t)$arg0
1302 if ($kgm_objectp->io_bits & 0x7fff0000)
1303 showpset $kgm_objectp
1305 showport $kgm_objectp
1310 set $kgm_mqueue = *(struct ipc_mqueue *)$arg0
1311 set $kgm_psetoff = &(((struct ipc_pset *)0)->ips_messages)
1312 set $kgm_portoff = &(((struct ipc_port *)0)->ip_messages)
1313 if ($kgm_mqueue.data.set_queue.wqs_wait_queue.wq_type == 0xf1d1)
1314 set $kgm_pset = (((int)$arg0) - ((int)$kgm_psetoff))
1316 showpsetint $kgm_pset 1
1318 if ($kgm_mqueue.data.set_queue.wqs_wait_queue.wq_type == 0xf1d0)
1320 set $kgm_port = (((int)$arg0) - ((int)$kgm_portoff))
1321 showportint $kgm_port 1
1326 set $kgm_zone = (struct zone *)$arg0
1328 printf "0x%08x ", $kgm_zone
1329 printf "%8d ",$kgm_zone->count
1330 printf "%8x ",$kgm_zone->cur_size
1331 printf "%8x ",$kgm_zone->max_size
1332 printf "%6d ",$kgm_zone->elem_size
1333 printf "%8x ",$kgm_zone->alloc_size
1334 printf "%s ",$kgm_zone->zone_name
1336 if ($kgm_zone->exhaustible)
1339 if ($kgm_zone->collectable)
1342 if ($kgm_zone->expandable)
1350 printf "ZONE COUNT TOT_SZ MAX_SZ ELT_SZ ALLOC_SZ NAME\n"
1351 set $kgm_zone_ptr = (struct zone *)first_zone
1352 while ($kgm_zone_ptr != 0)
1353 zprint_one $kgm_zone_ptr
1354 set $kgm_zone_ptr = $kgm_zone_ptr->next_zone
1359 | Routine to print a summary listing of all the kernel zones
1360 | The following is the syntax:
1365 set $kgm_mtxgrp = (lck_grp_t *)$arg0
1367 if ($kgm_mtxgrp->lck_grp_mtxcnt)
1368 printf "0x%08x ", $kgm_mtxgrp
1369 printf "%8d ",$kgm_mtxgrp->lck_grp_mtxcnt
1370 printf "%12u ",$kgm_mtxgrp->lck_grp_stat.lck_grp_mtx_stat.lck_grp_mtx_util_cnt
1371 printf "%8u ",$kgm_mtxgrp->lck_grp_stat.lck_grp_mtx_stat.lck_grp_mtx_miss_cnt
1372 printf "%8u ",$kgm_mtxgrp->lck_grp_stat.lck_grp_mtx_stat.lck_grp_mtx_wait_cnt
1373 printf "%s ",&$kgm_mtxgrp->lck_grp_name
1380 printf "LCK GROUP CNT UTIL MISS WAIT NAME\n"
1381 set $kgm_mtxgrp_ptr = (lck_grp_t *)&lck_grp_queue
1382 set $kgm_mtxgrp_ptr = (lck_grp_t *)$kgm_mtxgrp_ptr->lck_grp_link.next
1383 while ($kgm_mtxgrp_ptr != (lck_grp_t *)&lck_grp_queue)
1384 showmtxgrp $kgm_mtxgrp_ptr
1385 set $kgm_mtxgrp_ptr = (lck_grp_t *)$kgm_mtxgrp_ptr->lck_grp_link.next
1390 | Routine to print a summary listing of all mutexes
1391 | The following is the syntax:
1396 set $kgm_rwlckgrp = (lck_grp_t *)$arg0
1398 if ($kgm_rwlckgrp->lck_grp_rwcnt)
1399 printf "0x%08x ", $kgm_rwlckgrp
1400 printf "%8d ",$kgm_rwlckgrp->lck_grp_rwcnt
1401 printf "%12u ",$kgm_rwlckgrp->lck_grp_stat.lck_grp_rw_stat.lck_grp_rw_util_cnt
1402 printf "%8u ",$kgm_rwlckgrp->lck_grp_stat.lck_grp_rw_stat.lck_grp_rw_miss_cnt
1403 printf "%8u ",$kgm_rwlckgrp->lck_grp_stat.lck_grp_rw_stat.lck_grp_rw_wait_cnt
1404 printf "%s ",&$kgm_rwlckgrp->lck_grp_name
1411 printf "LCK GROUP CNT UTIL MISS WAIT NAME\n"
1412 set $kgm_rwlckgrp_ptr = (lck_grp_t *)&lck_grp_queue
1413 set $kgm_rwlckgrp_ptr = (lck_grp_t *)$kgm_rwlckgrp_ptr->lck_grp_link.next
1414 while ($kgm_rwlckgrp_ptr != (lck_grp_t *)&lck_grp_queue)
1415 showrwlckgrp $kgm_rwlckgrp_ptr
1416 set $kgm_rwlckgrp_ptr = (lck_grp_t *)$kgm_rwlckgrp_ptr->lck_grp_link.next
1420 document showallrwlck
1421 | Routine to print a summary listing of all read/writer locks
1422 | The following is the syntax:
1423 | (gdb) showallrwlck
1426 set $kdp_act_counter = 0
1429 if ($kgm_mtype == 18)
1430 if ($kdp_act_counter == 0)
1431 set $kdpstate = (struct savearea *) kdp.saved_state
1433 set $kdp_act_counter = $kdp_act_counter + 1
1434 set $newact = (struct thread *) $arg0
1435 if ($newact->kernel_stack == 0)
1436 echo This activation does not have a stack.\n
1438 output/a (unsigned) $newact.continuation
1441 set (struct savearea *) kdp.saved_state=$newact->machine->pcb
1443 set $pc=$newact->machine->pcb.save_srr0
1447 echo switchtoact not implemented for this architecture.\n
1451 document switchtoact
1452 Syntax: switchtoact <address of activation>
1453 | This command allows gdb to examine the execution context and call
1454 | stack for the specified activation. For example, to view the backtrace
1455 | for an activation issue "switchtoact <address>", followed by "bt".
1456 | Before resuming execution, issue a "resetctx" command, to
1457 | return to the original execution context.
1461 if ($kgm_mtype == 18)
1462 if ($kdp_act_counter == 0)
1463 set $kdpstate = (struct savearea *) kdp.saved_state
1465 set $kdp_act_counter = $kdp_act_counter + 1
1466 set (struct savearea *) kdp.saved_state=(struct savearea *) $arg0
1468 set $pc=((struct savearea *) $arg0)->save_srr0
1471 echo switchtoctx not implemented for this architecture.\n
1475 document switchtoctx
1476 Syntax: switchtoctx <address of pcb>
1477 | This command allows gdb to examine an execution context and dump the
1478 | backtrace for this execution context.
1479 | Before resuming execution, issue a "resetctx" command, to
1480 | return to the original execution context.
1484 if ($kgm_mtype == 18)
1485 set (struct savearea *)kdp.saved_state=$kdpstate
1487 set $pc=((struct savearea *) kdp.saved_state)->save_srr0
1489 set $kdp_act_counter = 0
1491 echo resetctx not implemented for this architecture.\n
1497 | Returns to the original execution context. This command should be
1498 | issued if you wish to resume execution after using the "switchtoact"
1499 | or "switchtoctx" commands.
1503 set noresume_on_disconnect = 0
1508 | The target system will resume when detaching or exiting from gdb.
1509 | This is the default behavior.
1513 set noresume_on_disconnect = 1
1517 | Syntax: resume_off
1518 | The target system won't resume after detaching from gdb and
1519 | can be attached with a new gdb session
1523 set $kgm_panic_bufptr = debug_buf
1524 set $kgm_panic_bufptr_max = debug_buf_ptr
1525 while $kgm_panic_bufptr < $kgm_panic_bufptr_max
1526 if *(char *)$kgm_panic_bufptr == 10
1529 printf "%c", *$kgm_panic_bufptr
1531 set $kgm_panic_bufptr= (char *)$kgm_panic_bufptr + 1
1537 | Display the panic log information
1541 define dumpcallqueue
1542 set $kgm_callhead = (queue_t)&$arg0
1543 set $kgm_call = (struct call_entry *)$kgm_callhead.next
1545 while $kgm_call != $kgm_callhead
1546 printf "0x%08x ", $kgm_call
1547 printf "0x%08x 0x%08x ", $kgm_call->param0, $kgm_call->param1
1548 output $kgm_call->state
1550 output $kgm_call->deadline
1552 output $kgm_call->func
1554 set $kgm_i = $kgm_i + 1
1555 set $kgm_call = (struct call_entry *)$kgm_call->q_link.next
1557 printf "%d entries\n", $kgm_i
1560 document dumpcallqueue
1561 | Syntax: dumpcallqueue <queue head>
1562 | Displays the contents of the specified call_entry queue.
1566 showtaskthreads $arg0
1568 document showtaskacts
1569 | See help showtaskthreads.
1575 document showallacts
1576 | See help showallthreads.
1591 document resetstacks
1592 | Syntax: resetstacks
1593 | Internal kgmacro routine used by the "showuserstack" macro
1594 | to reset the target pmap to the kernel pmap.
1597 #Barely effective hacks to work around bugs in the "flush" and "update"
1598 #gdb commands in Tiger (up to 219); these aren't necessary with Panther
1599 #gdb, but do no harm.
1600 define _kgm_flush_loop
1601 set $kgm_flush_loop_ctr = 0
1602 while ($kgm_flush_loop_ctr < 30)
1604 set $kgm_flush_loop_ctr = $kgm_flush_loop_ctr + 1
1608 define _kgm_update_loop
1609 set $kgm_update_loop_ctr = 0
1610 while ($kgm_update_loop_ctr < 30)
1612 set $kgm_update_loop_ctr = $kgm_update_loop_ctr + 1
1616 define showuserstack
1617 if ($kgm_mtype == 18)
1618 if ($kdp_act_counter == 0)
1619 set $kdpstate = (struct savearea *) kdp.saved_state
1621 set $kdp_act_counter = $kdp_act_counter + 1
1622 set $newact = (struct thread *) $arg0
1624 set $checkpc = $newact->machine->upcb.save_srr0
1626 echo This activation does not appear to have
1627 echo \20 a valid user context.\n
1629 set (struct savearea *) kdp.saved_state=$newact->machine->upcb
1631 #flush and update seem to be executed lazily by gdb on Tiger, hence the
1632 #repeated invocations - see 3743135
1634 # This works because the new pmap is used only for reads
1635 set kdp_pmap = $newact->task->map->pmap
1647 echo showuserstack not implemented for this architecture.\n
1651 document showuserstack
1652 Syntax: showuserstack <address of thread activation>
1653 |This command displays a numeric backtrace for the user space stack of
1654 |the given thread activation. It may, of course, fail to display a
1655 |complete backtrace if portions of the user stack are not mapped in.
1656 |Symbolic backtraces can be obtained either by running gdb on the
1657 |user space binary, or a tool such as "symbolicate".
1658 |Note that while this command works on Panther's gdb, an issue
1659 |with Tiger gdb (3743135) appears to hamper the evaluation of this
1660 |macro in some cases.
1663 #Stopgap until gdb can generate the HOSTREBOOT packet
1665 set flag_kdp_trigger_reboot = 1
1671 |Reboot the remote target machine; not guaranteed to succeed. Requires symbols
1672 |until gdb support for the HOSTREBOOT packet is implemented.
1676 set kdp_trigger_core_dump = 1
1677 set kdp_flag |= 0x40
1678 set panicd_ip_str = "$arg0"
1679 set panicd_specified = 1
1680 set disableDebugOuput = 0
1681 set disableConsoleOutput = 0
1682 set logPanicDataToScreen = 1
1683 set reattach_wait = 1
1688 Syntax: sendcore <IP address>
1689 |Configure the kernel to transmit a kernel coredump to a server (kdumpd)
1690 |at the specified IP address. This is useful when the remote target has
1691 |not been previously configured to transmit coredumps, and you wish to
1692 |preserve kernel state for later examination. NOTE: You must issue a "continue"
1693 |command after using this macro to trigger the kernel coredump. The kernel
1694 |will resume waiting in the debugger after completion of the coredump. You
1695 |may disable coredumps by executing the "disablecore" macro.
1699 set kdp_trigger_core_dump = 0
1700 set kdp_flag |= 0x40
1701 set kdp_flag &= ~0x10
1702 set panicd_specified = 0
1705 document disablecore
1707 |Reconfigures the kernel so that it no longer transmits kernel coredumps. This
1708 |complements the "sendcore" macro, but it may be used if the kernel has been
1709 |configured to transmit coredumps through boot-args as well.
1712 #Use of this macro requires the gdb submission from 3401283
1713 define switchtocorethread
1714 if ($kgm_mtype == 18)
1715 if ($kdp_act_counter == 0)
1716 set $kdpstate = (struct savearea *) kdp.saved_state
1718 set $kdp_act_counter = $kdp_act_counter + 1
1719 set $newact = (struct thread *) $arg0
1720 if ($newact->kernel_stack == 0)
1721 echo This thread does not have a stack.\n
1723 output/a (unsigned) $newact.continuation
1726 loadcontext $newact->machine->pcb
1727 # flushstack will be introduced in a gdb version > gdb-357
1729 set $pc = $newact->machine->pcb.save_srr0
1732 echo switchtocorethread not implemented for this architecture.\n
1736 document switchtocorethread
1737 Syntax: switchtocorethread <address of activation>
1738 | The corefile equivalent of "switchtoact". When debugging a kernel coredump
1739 | file, this command can be used to examine the execution context and stack
1740 | trace for a given thread activation. For example, to view the backtrace
1741 | for a thread issue "switchtocorethread <address>", followed by "bt".
1742 | Before resuming execution, issue a "resetcorectx" command, to
1743 | return to the original execution context. Note that this command
1744 | requires gdb support, as documented in Radar 3401283.
1748 set $pc = $arg0.save_srr0
1749 set $r1 = $arg0.save_r1
1750 set $lr = $arg0.save_lr
1752 set $r2 = $arg0.save_r2
1753 set $r3 = $arg0.save_r3
1754 set $r4 = $arg0.save_r4
1755 set $r5 = $arg0.save_r5
1756 set $r6 = $arg0.save_r6
1757 set $r7 = $arg0.save_r7
1758 set $r8 = $arg0.save_r8
1759 set $r9 = $arg0.save_r9
1760 set $r10 = $arg0.save_r10
1761 set $r11 = $arg0.save_r11
1762 set $r12 = $arg0.save_r12
1763 set $r13 = $arg0.save_r13
1764 set $r14 = $arg0.save_r14
1765 set $r15 = $arg0.save_r15
1766 set $r16 = $arg0.save_r16
1767 set $r17 = $arg0.save_r17
1768 set $r18 = $arg0.save_r18
1769 set $r19 = $arg0.save_r19
1770 set $r20 = $arg0.save_r20
1771 set $r21 = $arg0.save_r21
1772 set $r22 = $arg0.save_r22
1773 set $r23 = $arg0.save_r23
1774 set $r24 = $arg0.save_r24
1775 set $r25 = $arg0.save_r25
1776 set $r26 = $arg0.save_r26
1777 set $r27 = $arg0.save_r27
1778 set $r28 = $arg0.save_r28
1779 set $r29 = $arg0.save_r29
1780 set $r30 = $arg0.save_r30
1781 set $r31 = $arg0.save_r31
1783 set $cr = $arg0.save_cr
1784 set $ctr = $arg0.save_ctr
1788 set $kgm_corecontext = (struct savearea *) kdp.saved_state
1789 loadcontext $kgm_corecontext
1790 # Maintaining this act counter wouldn't be necessary if we just initialized
1791 # $kdpstate at the beginning of the macro..
1792 set $kdp_act_counter = 0
1795 document resetcorectx
1796 Syntax: resetcorectx
1797 | The corefile equivalent of "resetctx". Returns to the original
1798 | execution context (that of the active thread at the time of the NMI or
1799 | panic). This command should be issued if you wish to resume
1800 | execution after using the "switchtocorethread" command.
1803 #Helper function for "showallgdbstacks"
1805 define showgdbthread
1806 printf " 0x%08x ", $arg0
1807 set $kgm_thread = *(struct thread *)$arg0
1808 printf "0x%08x ", $arg0
1809 printf "%3d ", $kgm_thread.sched_pri
1810 set $kgm_state = $kgm_thread.state
1811 if $kgm_state & 0x80
1814 if $kgm_state & 0x40
1817 if $kgm_state & 0x20
1820 if $kgm_state & 0x10
1823 if $kgm_state & 0x08
1826 if $kgm_state & 0x04
1829 if $kgm_state & 0x02
1832 if $kgm_state & 0x01
1834 printf "0x%08x ", $kgm_thread.wait_queue
1835 output /a (unsigned) $kgm_thread.wait_event
1838 if ($kgm_thread.kernel_stack != 0)
1839 if ($kgm_thread.reserved_stack != 0)
1840 printf "\n\t\treserved_stack=0x%08x", $kgm_thread.reserved_stack
1842 printf "\n\t\tkernel_stack=0x%08x", $kgm_thread.kernel_stack
1843 if ($kgm_mtype == 18)
1844 set $mysp = $kgm_thread.machine.pcb->save_r1
1846 set $kgm_statep = (struct i386_kernel_state *) \
1847 ($kgm_thread->kernel_stack + 0x4000 \
1848 - sizeof(struct i386_kernel_state))
1849 set $mysp = $kgm_statep->k_ebp
1852 printf "\n\t\tstacktop=0x%08x", $mysp
1856 printf "\n\t\t\tcontinuation="
1857 output /a (unsigned) $kgm_thread.continuation
1865 #Use of this macro is currently (8/04) blocked by the fact that gdb
1866 #stops evaluating macros when encountering an error, such as a failure
1867 #to read memory from a certain location. Until this issue (described in
1868 #3758949) is addressed, evaluation of this macro may stop upon
1869 #encountering such an error.
1871 define showallgdbstacks
1872 set $kgm_head_taskp = &default_pset.tasks
1873 set $kgm_taskp = (struct task *)($kgm_head_taskp->next)
1874 while $kgm_taskp != $kgm_head_taskp
1876 showtaskint $kgm_taskp
1877 set $kgm_head_actp = &($kgm_taskp->threads)
1878 set $kgm_actp = (struct thread *)($kgm_taskp->threads.next)
1879 while $kgm_actp != $kgm_head_actp
1881 showgdbthread $kgm_actp 1
1882 set $kgm_actp = (struct thread *)($kgm_actp->task_threads.next)
1885 set $kgm_taskp = (struct task *)($kgm_taskp->pset_tasks.next)
1890 document showallgdbstacks
1891 Syntax: showallgdbstacks
1892 | An alternative to "showallstacks". Iterates through the task list and
1893 | displays a gdb generated backtrace for each kernel thread. It is
1894 | advantageous in that it is much faster than "showallstacks", and
1895 | decodes function call arguments and displays source level traces, but
1896 | it has the drawback that it doesn't determine if frames belong to
1897 | functions from kernel extensions, as with "showallstacks".
1898 | This command may terminate prematurely because of a gdb bug
1899 | (Radar 3758949), which stops macro evaluation on memory read
1903 define switchtouserthread
1904 if ($kgm_mtype == 18)
1905 if ($kdp_act_counter == 0)
1906 set $kdpstate = (struct savearea *) kdp.saved_state
1908 set $kdp_act_counter = $kdp_act_counter + 1
1909 set $newact = (struct thread *) $arg0
1911 set $checkpc = $newact->machine->upcb.save_srr0
1913 echo This activation does not appear to have
1914 echo \20 a valid user context.\n
1916 set (struct savearea *) kdp.saved_state=$newact->machine->upcb
1918 #flush and update seem to be executed lazily by gdb on Tiger, hence the
1919 #repeated invocations - see 3743135
1921 # This works because the new pmap is used only for reads
1922 set kdp_pmap = $newact->task->map->pmap
1927 echo switchtouserthread not implemented for this architecture.\n
1931 document switchtouserthread
1932 Syntax: switchtouserthread <address of thread>
1933 | Analogous to switchtoact, but switches to the user context of a
1934 | specified thread address. Similar to the "showuserstack"
1935 | command, but this command does not return gdb to the kernel context
1936 | immediately. This is to assist with the following (rather risky)
1937 | manoeuvre - upon switching to the user context and virtual address
1938 | space, the user may choose to call remove-symbol-file on the
1939 | mach_kernel symbol file, and then add-symbol-file on the user space
1940 | binary's symfile. gdb can then generate symbolic backtraces
1941 | for the user space thread. To return to the
1942 | kernel context and virtual address space, the process must be
1943 | reversed, i.e. call remove-symbol-file on the user space symbols, and
1944 | then add-symbol-file on the appropriate mach_kernel, and issue the
1945 | "resetstacks" command. Note that gdb may not react kindly to all these
1946 | symbol file switches. The same restrictions that apply to "showuserstack"
1947 | apply here - pages that have been paged out cannot be read while in the
1948 | debugger context, so backtraces may terminate early.
1949 | If the virtual addresses in the stack trace do not conflict with those
1950 | of symbols in the kernel's address space, it may be sufficient to
1951 | just do an add-symbol-file on the user space binary's symbol file.
1952 | Note that while this command works on Panther's gdb, an issue
1953 | with Tiger gdb (3743135) appears to hamper the evaluation of this
1954 | macro in some cases.
1957 define showmetaclass
1959 set $kgm_metaclassp = (OSMetaClass *)$arg0
1960 printf "%-5d", $kgm_metaclassp->instanceCount
1961 printf "x %5d bytes", $kgm_metaclassp->classSize
1962 printf " %s\n", $kgm_metaclassp->className->string
1965 define showallclasses
1967 set $kgm_classidx = 0
1968 while $kgm_classidx < sAllClassesDict->count
1969 set $kgm_meta = (OSMetaClass *) sAllClassesDict->dictionary[$kgm_classidx].value
1970 showmetaclass $kgm_meta
1971 set $kgm_classidx = $kgm_classidx + 1
1974 document showallclasses
1975 | Show the instance counts and ivar size of all OSObject subclasses. See ioclasscount man page for details.
1976 | The following is the syntax:
1977 | (gdb) showallclasses
1981 printf " Instance allocation = 0x%08lx = %4ld K\n", (int) debug_ivars_size, ((int) debug_ivars_size) / 1024
1982 printf "Container allocation = 0x%08lx = %4ld K\n", (int) debug_container_malloc_size, ((int) debug_container_malloc_size) / 1024
1983 printf " IOMalloc allocation = 0x%08lx = %4ld K\n", (int) debug_iomalloc_size, ((int) debug_iomalloc_size) / 1024
1984 printf " Pageable allocation = 0x%08lx = %4ld K\n", (vm_size_t) debug_iomallocpageable_size, ((vm_size_t) debug_iomallocpageable_size) / 1024
1987 document showioalloc
1988 | Show some accounting of memory allocated by IOKit allocators. See ioalloccount man page for details.
1989 | The following is the syntax: