+define showstring
+ printf "\"%s\"", ((OSString *)$arg0)->string
+end
+
+define shownumber
+ printf "%lld", ((OSNumber *)$arg0)->value
+end
+
+define showboolean
+ if ($arg0 == gOSBooleanFalse)
+ printf "No"
+ else
+ printf "Yes"
+ end
+end
+
+define showdata
+ set $kgm_data = (OSData *)$arg0
+
+ printf "<"
+ set $kgm_datap = (const unsigned char *) $kgm_data->data
+
+ set $kgm_printstr = 0
+ if (0 == (3 & (unsigned int)$kgm_datap) && ($kgm_data->length >= 3))
+ set $kgm_bytes = *(unsigned int *) $kgm_datap
+ if (0xffff0000 & $kgm_bytes)
+ set $kgm_idx = 0
+ set $kgm_printstr = 1
+ while ($kgm_idx++ < 4)
+ set $kgm_bytes = $kgm_bytes >> 8
+ set $kgm_char = 0xff & $kgm_bytes
+ if ($kgm_char && (($kgm_char < 0x20) || ($kgm_char > 0x7e)))
+ set $kgm_printstr = 0
+ end
+ end
+ end
+ end
+
+ set $kgm_idx = 0
+ if ($kgm_printstr)
+ set $kgm_quoted = 0
+ while ($kgm_idx < $kgm_data->length)
+ set $kgm_char = $kgm_datap[$kgm_idx++]
+ if ($kgm_char)
+ if (0 == $kgm_quoted)
+ set $kgm_quoted = 1
+ if ($kgm_idx > 1)
+ printf ",\""
+ else
+ printf "\""
+ end
+ end
+ printf "%c", $kgm_char
+ else
+ if ($kgm_quoted)
+ set $kgm_quoted = 0
+ printf "\""
+ end
+ end
+ end
+ if ($kgm_quoted)
+ printf "\""
+ end
+ else
+ if (0 == (3 & (unsigned int)$kgm_datap))
+ while (($kgm_idx + 3) <= $kgm_data->length)
+ printf "%08x", *(unsigned int *) &$kgm_datap[$kgm_idx]
+ set $kgm_idx = $kgm_idx + 4
+ end
+ end
+ while ($kgm_idx < $kgm_data->length)
+ printf "%02x", $kgm_datap[$kgm_idx++]
+ end
+ end
+ printf ">"
+end
+
+define showdictionaryint
+ set $kgm$arg0_dict = (OSDictionary *)$arg1
+
+ printf "{"
+ set $kgm$arg0_idx = 0
+ while ($kgm$arg0_idx < $kgm$arg0_dict->count)
+ set $kgm_obj = $kgm$arg0_dict->dictionary[$kgm$arg0_idx].key
+ showobjectint _$arg0 $kgm_obj
+ printf "="
+ set $kgm_obj = $kgm$arg0_dict->dictionary[$kgm$arg0_idx++].value
+ showobjectint _$arg0 $kgm_obj
+ if ($kgm$arg0_idx < $kgm$arg0_dict->count)
+ printf ","
+ end
+ end
+ printf "}"
+end
+
+define indent
+ set $kgm_idx = 0
+ while ($kgm_idx < $arg0)
+ if ($arg1 & (1 << $kgm_idx++))
+ printf "| "
+ else
+ printf " "
+ end
+ end
+end
+
+define showregdictionary
+ indent $kgm_reg_depth+2 $arg1
+ printf "{\n"
+
+ set $kgm_reg_idx = 0
+ while ($kgm_reg_idx < $arg0->count)
+ indent $kgm_reg_depth+2 $arg1
+ printf " "
+ set $kgm_obj = $arg0->dictionary[$kgm_reg_idx].key
+ showobjectint _ $kgm_obj
+ printf " = "
+
+ set $kgm_obj = $arg0->dictionary[$kgm_reg_idx++].value
+ showobjectint _ $kgm_obj
+ printf "\n"
+ end
+ indent $kgm_reg_depth+2 $arg1
+ printf "}\n"
+end
+
+
+define showarraysetint
+ set $kgm$arg0_array = (OSArray *)$arg1
+
+ set $kgm$arg0_idx = 0
+ while ($kgm$arg0_idx < $kgm$arg0_array->count)
+ set $kgm_obj = $kgm$arg0_array->array[$kgm$arg0_idx++]
+ showobjectint _$arg0 $kgm_obj
+ if ($kgm$arg0_idx < $kgm$arg0_array->count)
+ printf ","
+ end
+ end
+end
+
+define showarrayint
+ printf "("
+ showarraysetint $arg0 $arg1
+ printf ")"
+end
+
+define showsetint
+ set $kgm_array = ((OSSet *)$arg1)->members
+ printf "["
+ showarraysetint $arg0 $kgm_array
+ printf "]"
+end
+
+
+define showobjectint
+ set $kgm_obj = (OSObject *) $arg1
+ set $kgm_vt = *((void **) $arg1)
+
+ if ($kgm_show_object_addrs)
+ printf "`object %p, vt ", $arg1
+ output /a (unsigned) $kgm_vt
+ if ($kgm_show_object_retain)
+ printf ", retain count %d, container retain %d", (0xffff & $kgm_obj->retainCount), $kgm_obj->retainCount >> 16
+ end
+ printf "` "
+ end
+
+ if ($kgm_vt == _ZTV8OSString)
+ showstring $arg1
+ else
+ if ($kgm_vt == _ZTV8OSSymbol)
+ showstring $arg1
+ else
+ if ($kgm_vt == _ZTV8OSNumber)
+ shownumber $arg1
+ else
+ if ($kgm_vt == _ZTV6OSData)
+ showdata $arg1
+ else
+ if ($kgm_vt == _ZTV9OSBoolean)
+ showboolean $arg1
+ else
+ if ($kgm_vt == _ZTV12OSDictionary)
+ showdictionaryint _$arg0 $arg1
+ else
+ if ($kgm_vt == _ZTV7OSArray)
+ showarrayint _$arg0 $arg1
+ else
+ if ($kgm_vt == _ZTV5OSSet)
+ showsetint _$arg0 $arg1
+ else
+ if ($kgm_show_object_addrs == 0)
+ printf "`object %p, vt ", $arg1
+ output /a (unsigned) $kgm_vt
+ printf "`"
+ end
+ end
+ end
+ end
+ end
+ end
+ end
+ end
+ end
+end
+
+define showobject
+ set $kgm_save = $kgm_show_object_addrs
+ set $kgm_show_object_addrs = 1
+ set $kgm_show_object_retain = 1
+ showobjectint _ $arg0
+ set $kgm_show_object_addrs = $kgm_save
+ set $kgm_show_object_retain = 0
+ printf "\n"
+end
+document showobject
+| Show info about an OSObject - its vtable ptr and retain count.
+| If the object is a simple container class, more info will be shown.
+| The following is the syntax:
+| (gdb) showobject <object address>
+end
+
+define dictget
+ set $kgm_dictp = (OSDictionary *)$arg0
+ set $kgm_keyp = (const OSSymbol *)$arg1
+ set $kgm_idx = 0
+ set $kgm_result = 0
+ while (($kgm_idx < $kgm_dictp->count) && ($kgm_result == 0))
+ if ($kgm_keyp == $kgm_dictp->dictionary[$kgm_idx].key)
+ set $kgm_result = $kgm_dictp->dictionary[$kgm_idx].value
+ end
+ set $kgm_idx = $kgm_idx + 1
+ end
+end
+
+
+define showregistryentryrecurse
+ set $kgm_re = (IOService *)$arg1
+ set $kgm$arg0_stack = (unsigned long long) $arg2
+
+ if ($arg3)
+ set $kgm$arg0_stack = $kgm$arg0_stack | (1ULL << $kgm_reg_depth)
+ else
+ set $kgm$arg0_stack = $kgm$arg0_stack & ~(1ULL << $kgm_reg_depth)
+ end
+
+ dictget $kgm_re->fRegistryTable $kgm_childkey
+ set $kgm$arg0_child_array = (OSArray *) $kgm_result
+
+ if ($kgm$arg0_child_array)
+ set $kgm$arg0_child_count = $kgm$arg0_child_array->count
+ else
+ set $kgm$arg0_child_count = 0
+ end
+
+ if ($kgm$arg0_child_count)
+ set $kgm$arg0_stack = $kgm$arg0_stack | (2ULL << $kgm_reg_depth)
+ else
+ set $kgm$arg0_stack = $kgm$arg0_stack & ~(2ULL << $kgm_reg_depth)
+ end
+
+ indent $kgm_reg_depth $kgm$arg0_stack
+ printf "+-o "
+
+ dictget $kgm_re->fRegistryTable $kgm_namekey
+ if ($kgm_result == 0)
+ dictget $kgm_re->fRegistryTable gIONameKey
+ end
+ if ($kgm_result == 0)
+ dictget $kgm_re->fPropertyTable gIOClassKey
+ end
+
+ if ($kgm_result != 0)
+ printf "%s", ((OSString *)$kgm_result)->string
+ else
+ if (((IOService*)$kgm_re)->pm_vars && ((IOService*)$kgm_re)->pm_vars->ourName)
+ printf "%s", ((IOService*)$kgm_re)->pm_vars->ourName
+ else
+# printf ", guessclass "
+# guessclass $kgm_re
+ printf "??"
+ end
+ end
+
+
+ printf " <object %p, ", $kgm_re
+ printf "vtable "
+ set $kgm_vt = (unsigned) *(void**) $kgm_re
+ output /a $kgm_vt
+
+ if ($kgm_vt != _ZTV15IORegistryEntry)
+ printf ", "
+ set $kgm_state = $kgm_re->__state[0]
+ # kIOServiceRegisteredState
+ if (0 == ($kgm_state & 2))
+ printf "!"
+ end
+ printf "registered, "
+ # kIOServiceMatchedState
+ if (0 == ($kgm_state & 4))
+ printf "!"
+ end
+ printf "matched, "
+ # kIOServiceInactiveState
+ if ($kgm_state & 1)
+ printf "in"
+ end
+ printf "active, busy %d, retain count %d", (0xff & $kgm_re->__state[1]), (0xffff & $kgm_re->retainCount)
+ end
+ printf ">\n"
+
+ if ($kgm_show_props)
+ set $kgm_props = $kgm_re->fPropertyTable
+ showregdictionary $kgm_props $kgm$arg0_stack
+ end
+
+ # recurse
+ if ($kgm$arg0_child_count != 0)
+
+ set $kgm_reg_depth = $kgm_reg_depth + 1
+ set $kgm$arg0_child_idx = 0
+
+ while ($kgm$arg0_child_idx < $kgm$arg0_child_count)
+ set $kgm_re = $kgm$arg0_child_array->array[$kgm$arg0_child_idx++]
+ set $kgm_more_sib = ($kgm$arg0_child_idx < $kgm$arg0_child_count)
+ showregistryentryrecurse _$arg0 $kgm_re $kgm$arg0_stack $kgm_more_sib
+ end
+
+ set $kgm_reg_depth = $kgm_reg_depth - 1
+ end
+end
+
+define showregistryentryint
+ set $kgm_namekey = (OSSymbol *) $kgm_reg_plane[2]
+ set $kgm_childkey = (OSSymbol *) $kgm_reg_plane[4]
+
+ showregistryentryrecurse _ $arg0 0 0
+end
+
+define showregistry
+ set $kgm_reg_depth = 0
+ set $kgm_show_props = 0
+ showregistryentryint gRegistryRoot
+end
+document showregistry
+| Show info about all registry entries in the current plane.
+| The following is the syntax:
+| (gdb) showregistry
+end
+
+define showregistryprops
+ set $kgm_reg_depth = 0
+ set $kgm_show_props = 1
+ showregistryentryint gRegistryRoot
+end
+document showregistryprops
+| Show info about all registry entries in the current plane, and their properties.
+| set $kgm_show_object_addrs = 1 and/or set $kgm_show_object_retain = 1 will display
+| more verbose information
+| The following is the syntax:
+| (gdb) showregistryprops
+end
+
+define showregistryentry
+ set $kgm_reg_depth = 0
+ set $kgm_show_props = 1
+ showregistryentryint $arg0
+end
+document showregistryentry
+| Show info about a registry entry; its properties and descendants in the current plane.
+| The following is the syntax:
+| (gdb) showregistryentry <object address>
+end
+
+define setregistryplane
+ if ($arg0)
+ set $kgm_reg_plane = (void **) $arg0
+ else
+ showobjectint _ gIORegistryPlanes
+ printf "\n"
+ end
+end
+document setregistryplane
+| Set the plane to be used for the iokit registry macros. An argument of zero will
+| display known planes.
+| The following is the syntax:
+| (gdb) setregistryplane <plane object address>
+end
+
+define guessclass