+ printf "fbt_probetab[index=%d], depth=%d, 0x%x\n", $kgm_indx, $kgm_depth, $kgm_fbt_probep
+ printf "(gdb) p *(struct fbt_probe *)0x%x\n", $kgm_fbt_probep
+ p *(struct fbt_probe *)$kgm_fbt_probep
+ set $kgm_fbtp_ctl = (struct fbt_probe *)$kgm_fbt_probep->fbtp_ctl
+ showmodctl $kgm_fbtp_ctl
+ loop_break
+ end
+ end
+end
+document showfbtprobe
+Syntax: (gdb) showfbtprobe <id>
+| Display info about an fbt probe given an id.
+| Traverses fbt_probetab and matches <id> with fbtp_id.
+| The <id> is found using dtrace -l
+end
+
+define showzstacktrace
+ set $kgm_trace = (void*)$arg0
+ if ($argc == 1)
+ set $kgm_trace_size = 15
+ end
+ if ($argc == 2)
+ set $kgm_trace_size = $arg1
+ end
+ set $kgm_trace_current = 0
+ while ($kgm_trace_current < $kgm_trace_size)
+ set $kgm_trace_addr = (void**)$kgm_trace + $kgm_trace_current
+ set $kgm_trace_value = *((void**)$kgm_trace_addr)
+ #printf "\t\t"
+ output /a $kgm_trace_value
+ set $kgm_trace_current = $kgm_trace_current + 1
+ printf "\n"
+ end
+end
+
+document showzstacktrace
+Syntax: showzstacktrace <saved stacktrace> [size]
+| Routine to print a stacktrace stored by OSBacktrace.
+| size is optional, defaults to 15.
+end
+
+define showzalloc
+ set $kgm_zallocation = zallocations[$arg0]
+ print $kgm_zallocation
+ showztrace $kgm_zallocation->za_trace_index
+end
+
+document showzalloc
+Syntax: showzalloc <index>
+| Prints a zallocation from the zallocations array based off its index,
+| and prints the associated symbolicated backtrace.
+end
+
+define showztrace
+ set $kgm_ztrace = &ztraces[$arg0]
+ showztraceaddr $kgm_ztrace
+end
+
+document showztrace
+Syntax: showztrace <trace index>
+| Prints the backtrace from the ztraces array at index
+end
+
+define showztraceaddr
+ print *$arg0
+ showzstacktrace $arg0->zt_stack ($arg0)->zt_depth
+end
+
+document showztraceaddr
+Syntax: showztraceaddr <trace address>
+| Prints the struct ztrace passed in
+end
+
+#TODO: Iterate through the hash table, or make top_ztrace accurate in the face of deallocations (better idea).
+define showtopztrace
+ set $kgm_top_ztrace = top_ztrace
+ printf "Index: %d\n", (top_ztrace - ztraces)
+ showztraceaddr $kgm_top_ztrace
+end
+
+document showtopztrace
+Syntax: showtopztrace
+| Shows the ztrace with the biggest size. (according to top_ztrace, not by iterating through the hash table)
+end
+
+define showzallocs
+ set $kgm_zallocation_current_index = 0
+ set $kgm_zallocations_count = 0
+ set $kgm_max_zallocation = zleak_alloc_buckets
+ printf "INDEX ADDRESS "
+ if $kgm_lp64
+ printf " "
+ end
+ printf "TRACE SIZE\n"
+ while ($kgm_zallocation_current_index < $kgm_max_zallocation)
+ set $kgm_zallocation_current = zallocations[$kgm_zallocation_current_index]
+ if ($kgm_zallocation_current->element != 0)
+ printf "%5d %p ", $kgm_zallocation_current_index, $kgm_zallocation_current->za_element
+ printf "%5d %6lu\n", $kgm_zallocation_current->za_trace_index, $kgm_zallocation_current->za_size
+ set $kgm_zallocations_count = $kgm_zallocations_count + 1
+ end
+ set $kgm_zallocation_current_index = $kgm_zallocation_current_index + 1
+ end
+ printf "Total allocations: %d\n", $kgm_zallocations_count
+end
+
+document showzallocs
+Syntax: showzallocs
+| Prints all allocations in the zallocations table
+end
+
+define showzallocsfortrace
+ set $kgm_zallocation_current_index = 0
+ set $kgm_zallocations_count = 0
+ set $kgm_max_zallocation = zleak_alloc_buckets
+ printf "INDEX ADDRESS "
+ if $kgm_lp64
+ printf " "
+ end
+ printf "SIZE\n"
+ while ($kgm_zallocation_current_index < $kgm_max_zallocation)
+ set $kgm_zallocation_current = zallocations[$kgm_zallocation_current_index]
+ if ($kgm_zallocation_current->element != 0 && $kgm_zallocation_current->za_trace_index == $arg0)
+ printf "%5d %p ", $kgm_zallocation_current_index, $kgm_zallocation_current->za_element
+ printf "%6lu\n", $kgm_zallocation_current->size
+ set $kgm_zallocations_count = $kgm_zallocations_count + 1
+ end
+ set $kgm_zallocation_current_index = $kgm_zallocation_current_index + 1
+ end
+ printf "Total allocations: %d\n", $kgm_zallocations_count
+end
+
+document showzallocsfortrace
+Syntax: showzallocsfortrace <trace index>
+| Prints all allocations pointing to the passed in trace's index into ztraces by looking through zallocations table
+end
+
+define showztraces
+ showztracesabove 0
+end
+
+document showztraces
+Syntax: showztraces
+| Prints all traces with size > 0
+end
+
+define showztracesabove
+ set $kgm_ztrace_current_index = 0
+ set $kgm_ztrace_count = 0
+ set $kgm_max_ztrace = zleak_trace_buckets
+ printf "INDEX SIZE\n"
+ while ($kgm_ztrace_current_index < $kgm_max_ztrace)
+ set $kgm_ztrace_current = ztraces[$kgm_ztrace_current_index]
+ if ($kgm_ztrace_current->zt_size > $arg0)
+ printf "%5d %6lu\n", $kgm_ztrace_current_index, $kgm_ztrace_current->zt_size
+ set $kgm_ztrace_count = $kgm_ztrace_count + 1
+ end
+ set $kgm_ztrace_current_index = $kgm_ztrace_current_index + 1
+ end
+ printf "Total traces: %d\n", $kgm_ztrace_count
+end
+
+document showztracesabove
+Syntax: showztracesabove <size>
+| Prints all traces with size greater than X
+end
+
+define showztracehistogram
+ set $kgm_ztrace_current_index = 0
+ set $kgm_ztrace_count = 0
+ set $kgm_max_ztrace = zleak_trace_buckets
+ printf "INDEX HIT_COUNT COLLISIONS\n"
+ while ($kgm_ztrace_current_index < $kgm_max_ztrace)
+ set $kgm_ztrace_current = ztraces[$kgm_ztrace_current_index]
+ if ($kgm_ztrace_current->zt_hit_count != 0)
+ printf "%5d %5d %5d\n", $kgm_ztrace_current_index, $kgm_ztrace_current->zt_hit_count, $kgm_ztrace_current->zt_collisions
+ set $kgm_ztrace_count = $kgm_ztrace_count + 1
+ end
+ set $kgm_ztrace_current_index = $kgm_ztrace_current_index + 1
+ end
+ printf "Total traces: %d\n", $kgm_ztrace_count
+end
+
+document showztracehistogram
+Syntax: showztracehistogram
+| Prints the histogram of the ztrace table
+end
+
+define showzallochistogram
+ set $kgm_zallocation_current_index = 0
+ set $kgm_zallocations_count = 0
+ set $kgm_max_zallocation = zleak_alloc_buckets
+ printf "INDEX HIT_COUNT\n"
+ while ($kgm_zallocation_current_index < $kgm_max_zallocation)
+ set $kgm_zallocation_current = zallocations[$kgm_zallocation_current_index]
+ if ($kgm_zallocation_current->za_hit_count != 0)
+ printf "%5d %5d\n", $kgm_zallocation_current_index, $kgm_zallocation_current->za_hit_count
+ set $kgm_zallocations_count = $kgm_zallocations_count + 1
+ end
+ set $kgm_zallocation_current_index = $kgm_zallocation_current_index + 1
+ end
+ printf "Total allocations: %d\n", $kgm_zallocations_count
+end
+
+document showzallochistogram
+Syntax: showzallochistogram
+| Prints the histogram for the zalloc table
+end
+
+define showzstats
+ printf "z_alloc_collisions: %u, z_trace_collisions: %u\n", z_alloc_collisions, z_trace_collisions
+ printf "z_alloc_overwrites: %u, z_trace_overwrites: %u\n", z_alloc_overwrites, z_trace_overwrites
+ printf "z_alloc_recorded: %u, z_trace_recorded: %u\n", z_alloc_recorded, z_trace_recorded
+end
+
+document showzstats
+Syntax: showzstats
+| Prints the zone leak detection stats
+end
+
+
+set $kgm_au_sentry_hash_table_size = 97
+
+define showsession1
+ set $p = (struct au_sentry *)$arg0
+ showptr $p
+ printf " 0x%08x 0x%08x 0x%016x", $p->se_auinfo.ai_asid, $p->se_auinfo.ai_auid, $p->se_auinfo.ai_flags
+ printf " %3ld %3ld", $p->se_refcnt, $p->se_procnt
+ printf "\n"
+end
+
+define showsessionhdr
+ printf "au_sentry "
+ showptrhdrpad
+ printf " ASID AUID FLAGS C P\n"
+end
+
+define showsession
+ showsessionhdr
+ showsession1 $arg0
+end
+
+document showsession
+Syntax: showsession
+| Display info about a specified audit session
+end
+
+define showallsessions
+ showsessionhdr
+ set $kgm_au_sentry_hash_table = au_sentry_bucket
+ set $i = $kgm_au_sentry_hash_table_size - 1
+ while $i >= 0
+ set $p = $kgm_au_sentry_hash_table[$i].lh_first
+ while $p != 0
+ showsession1 $p
+ set $p = $p->se_link.le_next
+ end
+ set $i = $i - 1
+ end
+end
+
+document showallsessions
+Syntax: showallsessions
+| Prints the audit sessions in the global hash table
+end
+
+define showauhistorystack
+ set $ii = $arg0
+ set $pp = (void **)$arg1
+ while $ii > 0
+ printf " "
+ x/i $pp[$ii-1]
+ set $ii = $ii - 1
+ end
+end
+
+define showauhistory1
+ set $p = (struct au_history *)$arg0
+ set $stack_depth = $p->stack_depth
+ set $stack = $p->stack
+ showptr $p->ptr
+ if $p->event == 1
+ printf " REF"
+ end
+ if $p->event == 2
+ printf " UNREF"
+ end
+ if $p->event == 3
+ printf " BIRTH"
+ end
+ if $p->event == 4
+ printf " DEATH"
+ end
+ if $p->event == 5
+ printf " FIND"
+ end
+ set $p = &$p->se
+ printf " 0x%08x 0x%08x 0x%016x", $p->se_auinfo.ai_asid, $p->se_auinfo.ai_auid, $p->se_auinfo.ai_flags
+ printf " %3ld %3ld", $p->se_refcnt, $p->se_procnt
+ printf "\n"
+ showauhistorystack $stack_depth $stack
+end
+
+define showauhistory
+ set $i = (au_history_index-1) % au_history_size
+ if au_history_index >= au_history_size
+ set $n = au_history_size
+ else
+ set $n = au_history_index
+ end
+ while $n > 0
+ if au_history[$i].ptr != 0 && (0 == $arg0 || au_history[$i].ptr == $arg0)
+ printf "[% 4d] ", $i
+ showauhistory1 &au_history[$i]
+ end
+ set $n = $n - 1
+ set $i = ($i - 1) % au_history_size
+ end
+end
+
+define showallauhistory
+ showauhistory 0
+end
+
+define showkwqheader
+ printf " kwq "
+ showptrhdrpad
+ printf " kwqaddr "
+ showptrhdrpad
+ printf " inqueue fakecount highseq lowseq flags lastunlock p_rwwc"
+ printf "\n "
+end
+
+define showkwqint
+ printf " "
+ set $kgm_kwq = (ksyn_wait_queue_t)$arg0
+ showptr $kgm_kwq
+ printf " "
+ showptr $kgm_kwq->kw_addr
+ printf " "
+ printf " %d ", $kgm_kwq->kw_inqueue
+ printf " %d ", $kgm_kwq->kw_fakecount
+ printf " 0x%x ", $kgm_kwq->kw_highseq
+ printf " 0x%x ", $kgm_kwq->kw_lowseq
+ printf " 0x%x ", $kgm_kwq->kw_flags
+ printf " 0x%x ", $kgm_kwq->kw_lastunlockseq
+ printf " 0x%x ", $kgm_kwq->kw_pre_rwwc
+ printf "\n"
+end
+
+define show_kwq
+ showkwqheader
+ showkwqint $arg0
+end
+
+document show_kwq
+Syntax: (gdb) show_kwq <kwq>
+| Display info about one ksyn_wait_queue
+end
+
+# Internal routine used by "showpthread_mutex" to abstract possible loads from
+# user space
+define _loadfrommutex
+ if (kdp_pmap == 0)
+ set $kgm_loadval = *(uintptr_t *)$arg0
+ else
+ if ($kgm_x86_abi == 0xe)
+ set $kgm_loadval = *(uint32_t *)$arg0
+ else
+ if ($kgm_x86_abi == 0xf)
+ if ($kgm_mtype == $kgm_mtype_i386)
+ _loadk32m64 $arg0
+ set $kgm_loadval = $kgm_k32read64
+ else
+ set $kgm_loadval = *(uint32_t *)$arg0
+ end
+ end
+ end
+end
+end
+
+define show_pthreadmutex
+ set $newact = (struct thread *) $arg0
+ set $ourtask = (struct task *)($newact->task)
+ set $our_user_is64 = ($ourtask->taskFeatures[0] & 0x80000000)
+ _kgm_flush_loop
+ set $mutex = (void *)$arg1
+ set kdp_pmap = $newact->task->map->pmap
+ _kgm_flush_loop
+ _kgm_update_loop
+ set $newiss = (x86_saved_state_t *) ($newact->machine.pcb->iss)
+ set $kgm_x86_abi = $newiss.flavor
+ if ($our_user_is64 != 0)
+ printf "\tUser 64Bit\n "
+ printf "\tSignature: "
+ set $nextval = $mutex
+ _loadfrommutex $nextval
+ printf "0x%x\n",$kgm_loadval
+ printf "\tflags: "
+ set $nextval = $mutex + 12
+ _loadfrommutex $nextval
+ printf "0x%x\n",$kgm_loadval
+ printf "\tSeqs: "
+ set $nextval = $mutex + 20
+ _loadfrommutex $nextval
+ printf "0x%x ",$kgm_loadval
+ set $nextval = $mutex + 24
+ _loadfrommutex $nextval
+ printf "0x%x ",$kgm_loadval
+ set $nextval = $mutex + 28
+ _loadfrommutex $nextval
+ printf "0x%x\n",$kgm_loadval
+ printf "\ttid[0]: "
+ set $nextval = $mutex + 32
+ _loadfrommutex $nextval
+ printf "0x%x\n",$kgm_loadval
+ printf "\ttid[1]: "
+ set $nextval = $mutex + 36
+ _loadfrommutex $nextval
+ printf "0x%x\n",$kgm_loadval
+ else
+ printf "\tUser 32Bit\n "
+ printf "\tSignature: "
+ set $nextval = $mutex
+ _loadfrommutex $nextval
+ printf "0x%x\n",$kgm_loadval
+ printf "\tflags: "
+ set $nextval = $mutex + 8
+ _loadfrommutex $nextval
+ printf "0x%x\n",$kgm_loadval
+ printf "\tSeqs: "
+ set $nextval = $mutex + 16
+ _loadfrommutex $nextval
+ printf "0x%x ",$kgm_loadval
+ set $nextval = $mutex + 20
+ _loadfrommutex $nextval
+ printf "0x%x ",$kgm_loadval
+ set $nextval = $mutex + 24
+ _loadfrommutex $nextval
+ printf "0x%x\n",$kgm_loadval
+ printf "\ttid[0]: "
+ set $nextval = $mutex + 32
+ _loadfrommutex $nextval
+ printf "0x%x\n",$kgm_loadval
+ printf "\ttid[1]: "
+ set $nextval = $mutex + 36
+ _loadfrommutex $nextval
+ printf "0x%x\n",$kgm_loadval
+ end
+ printf "\n"
+ resetstacks
+end
+
+
+document show_pthreadmutex
+Syntax: (gdb) show_pthreadmutex <thread> <user_mutexaddr>
+| Display the mutex contents from userspace.
+end
+
+
+define show_pthreadcondition
+ set $newact = (struct thread *) $arg0
+ set $ourtask = (struct task *)($newact->task)
+ set $our_user_is64 = ($ourtask->taskFeatures[0] & 0x80000000)
+ _kgm_flush_loop
+ set $cond = (void *)$arg1
+ set kdp_pmap = $newact->task->map->pmap
+ _kgm_flush_loop
+ _kgm_update_loop
+ set $newiss = (x86_saved_state_t *) ($newact->machine.pcb->iss)
+ set $kgm_x86_abi = $newiss.flavor
+ if ($our_user_is64 != 0)
+ printf "\tUser 64Bit\n "
+ printf "\tSignature: "
+ set $nextval = $cond
+ _loadfrommutex $nextval
+ printf "0x%x\n",$kgm_loadval
+ printf "\tflags: "
+ set $nextval = $cond + 12
+ _loadfrommutex $nextval
+ printf "0x%x\n",$kgm_loadval
+ printf "\tSeqs: "
+ set $nextval = $cond + 24
+ _loadfrommutex $nextval
+ printf "0x%x ",$kgm_loadval
+ set $nextval = $cond + 28
+ _loadfrommutex $nextval
+ printf "0x%x ",$kgm_loadval
+ set $nextval = $cond + 32
+ _loadfrommutex $nextval
+ printf "0x%x\n",$kgm_loadval
+ printf "\tMutex lowaddr: "
+ set $nextval = $cond + 16
+ _loadfrommutex $nextval
+ printf "0x%08x\n",$kgm_loadval
+ printf "\tMutex highaddr: "
+ set $nextval = $cond + 20
+ _loadfrommutex $nextval
+ printf "0x%x\n",$kgm_loadval
+ else
+ printf "\tUser 32Bit\n "
+ printf "\tSignature: "
+ set $nextval = $cond
+ _loadfrommutex $nextval
+ printf "0x%x\n",$kgm_loadval
+ printf "\tflags: "
+ set $nextval = $cond + 8
+ _loadfrommutex $nextval
+ printf "0x%x\n",$kgm_loadval
+ printf "\tSeqs: "
+ set $nextval = $cond + 16
+ _loadfrommutex $nextval
+ printf "0x%x ",$kgm_loadval
+ set $nextval = $cond + 20
+ _loadfrommutex $nextval
+ printf "0x%x ",$kgm_loadval
+ set $nextval = $cond + 24
+ _loadfrommutex $nextval
+ printf "0x%x\n",$kgm_loadval
+ printf "\tMutex addr: "
+ set $nextval = $cond + 12
+ _loadfrommutex $nextval
+ printf "0x%x\n",$kgm_loadval
+ end
+ printf "\n"
+ resetstacks
+end
+
+
+document show_pthreadcondition
+Syntax: (gdb) show_pthreadcondition <thread> <user_cvaddr>
+| Display the condition variable contents from userspace.
+end
+
+define processortimers
+ set $kgm_p = processor_list
+ printf "Processor\t\t\t Last dispatch\t\t Next deadline\t\t difference\n"
+ while $kgm_p
+ printf "Processor %d: %p\t", $kgm_p->cpu_id, $kgm_p
+ printf " 0x%016llx\t", $kgm_p->last_dispatch
+ set $kgm_rt_timer = &(cpu_data_ptr[$kgm_p->cpu_id].rtclock_timer)
+ printf " 0x%016llx \t", $kgm_rt_timer->deadline
+ set $kgm_rt_diff = ((long long)$kgm_p->last_dispatch) - ((long long)$kgm_rt_timer->deadline)
+ printf " 0x%016llx ", $kgm_rt_diff
+# normally the $kgm_rt_diff will be close to the last dispatch time, or negative
+# When it isn't, mark the result as bad. This is a suggestion, not an absolute
+ if ( ($kgm_rt_diff > 0) && ((long long)$kgm_p->last_dispatch) - ($kgm_rt_diff + 1) > 0 )
+ printf "probably BAD\n"
+ else
+ printf "(ok)\n"
+ end
+ # dump the call entries (Intel only)
+ if (($kgm_mtype & $kgm_mtype_x86_mask) == $kgm_mtype_x86_any)
+ printf "Next deadline set at: 0x%016llx. Timer call list:", $kgm_rt_timer->when_set
+ set $kgm_entry = (queue_t *)$kgm_rt_timer->queue
+ if ($kgm_entry == $kgm_rt_timer)
+ printf " (empty)\n"
+ else
+ printf "\n entry: "
+ showptrhdrpad
+ printf "deadline soft_deadline delta (*func)(param0,param1)\n"
+ while $kgm_entry != $kgm_rt_timer
+ set $kgm_timer_call = (timer_call_t) $kgm_entry
+ set $kgm_call_entry = (struct call_entry *) $kgm_entry
+ printf " "
+ showptr $kgm_entry
+ printf ": 0x%016llx 0x%016llx 0x%08x (%p)(%p,%p)\n", \
+ $kgm_call_entry->deadline, \
+ $kgm_timer_call->soft_deadline, \
+ ($kgm_call_entry->deadline - $kgm_timer_call->soft_deadline), \
+ $kgm_call_entry->func, \
+ $kgm_call_entry->param0, $kgm_call_entry->param1
+ set $kgm_entry = $kgm_entry->next
+ end
+ end
+ end
+ set $kgm_p = $kgm_p->processor_list