Difference between revisions of "Kdebug"

From The iPhone Wiki
Jump to: navigation, search
(New page on the virtually undocumented kdebug. Watch this space for more :-))
 
(edits...)
Line 1: Line 1:
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.
+
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, similar to the following code.
   
 
<pre>
 
<pre>
Line 7: Line 7:
 
#define KDEBUG_ENABLE_CHUD 0x4
 
#define KDEBUG_ENABLE_CHUD 0x4
   
  +
// N.B - must SETBUF before facility can be enabled.
   
 
int mib[4];
 
int mib[4];
 
mib[0] = CTL_KERN;
 
mib[0] = CTL_KERN;
 
mib[1] = KERN_KDEBUG;
 
mib[1] = KERN_KDEBUG;
mib[2] = KERN_KDENABLE; /* protocol */
+
mib[2] = KERN_KDENABLE; /* or a host of other codes from kdebug.h */
 
mib[3] = /* One of above values, 0 disables */;
 
mib[3] = /* One of above values, 0 disables */;
   
Line 17: Line 18:
 
</pre>
 
</pre>
   
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).
+
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).
  +
  +
The user mode header, <sys/kdebug.h> is partial, at best. A complete header can be found in the XNU source code.
   
 
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.
 
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.

Revision as of 19:11, 16 March 2012

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, similar to the following code.


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

// N.B - must SETBUF before facility can be enabled. 

int mib[4];
mib[0] = CTL_KERN;
mib[1] = KERN_KDEBUG;
mib[2] = KERN_KDENABLE;         /* or a host of other codes from kdebug.h */
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).

The user mode header, <sys/kdebug.h> is partial, at best. A complete header can be found in the XNU source code.

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.