#include <libkern/OSDebug.h>

libkern/OSDebug.h

4 functions

functionOSReportWithBacktrace

__printflike(1, 2)
extern void OSReportWithBacktrace(const char *str, ...)
Report a message with a 4 entry backtrace - very slow

functionOSBacktrace

extern unsigned OSBacktrace(void **bt, unsigned maxAddrs)
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu libkern/gen/OSDebug.cpp
Records a backtrace of the calling thread's kernel stack by walking frame pointers, storing up to maxAddrs return addresses into bt. Each candidate frame pointer and return address is validated (alignment, kernel address range, mapped translation) before being followed; the walk stops at the first invalid or non-monotonic frame. Remaining slots in bt are filled with NULL. Returns the number of addresses captured, or 0 if there is no current thread. Used by OSReportWithBacktrace and by allocation-debugging code.

functionOSPrintBacktrace

extern void OSPrintBacktrace(void)
Simple dump of 20 backtrace entries

functionOSKernelStackRemaining

vm_offset_t OSKernelStackRemaining(void)
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu iokit/Kernel/IOLib.cpp
Returns the number of bytes of unused stack remaining below the current stack pointer on the calling thread's kernel stack (via ml_stack_remaining). Drivers use it to decide whether deep call paths must be deferred to a thread call with a fresh stack.