Kdebug

From The iPhone Wiki
Revision as of 19:09, 16 March 2012 by Morpheus (talk | contribs) (New page on the virtually undocumented kdebug. Watch this space for more :-))
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

KDebug is a XNU built-in debugging facility, which has been around OS X from its early days, and is present - to varying extents - in iOS. In OS X, sc_usage(1), fs_usage(1) and latency(1) make use of it. The facility can be enabled and controlled via sysctl(2) calls.


#define KDEBUG_ENABLE_TRACE   0x1
#define KDEBUG_ENABLE_ENTROPY 0x2
#define KDEBUG_ENABLE_CHUD    0x4


int mib[4];
mib[0] = CTL_KERN;
mib[1] = KERN_KDEBUG;
mib[2] = KERN_KDENABLE;         /* protocol */
mib[3] = /* One of above values, 0 disables */;

if (sysctl(mib, 4, NULL, &needed, NULL, 0) < 0) perror("sysctl, KERN_KDENABLE\n");

kdebug's most useful feature is to enable kernel-level tracing, but can also be enabled for entropy collection (i.e. /dev/random like behavior). The CHUD interfaces are woefully poorly documented, and private to Apple (and probably deserve a future Wiki entry on their own).

In OS X, most of the kdebug functionality can be met (and exceeded) by DTrace. This is not an option with iOS, which does not have DTrace. The kdebug facility, however, is supported. iOS 5.01 has been verified to support it to a similar extent as OS X, including clean compilation and execution of sc_usage(1). The same cannot be said for iOS 4, wherein the binaries compile, but do not execute properly.