#include <sys/kdebug_private.h>
sys/kdebug_private.h
macroBSD_KDEBUG_PRIVATE_H
#define BSD_KDEBUG_PRIVATE_H
macroDBG_PPT
#define DBG_PPT 36
macroDBG_PERFCTRL
#define DBG_PERFCTRL 39
macroDBG_CLPC
#define DBG_CLPC 50
macroDBG_MUSE
#define DBG_MUSE 52
macroDBG_ANS
#define DBG_ANS 128
macroDBG_SIO
#define DBG_SIO 129
macroDBG_SEP
#define DBG_SEP 130
macroDBG_ISP
#define DBG_ISP 131
macroDBG_OSCAR
#define DBG_OSCAR 132
macroDBG_EMBEDDEDGFX
#define DBG_EMBEDDEDGFX 133
macroDBG_PMP
#define DBG_PMP 134
macroDBG_RTKIT
#define DBG_RTKIT 135
macroDBG_DCP
#define DBG_DCP 136
macroDBG_KMP
#define DBG_KMP 137
macroDBG_SKYWALK_ALWAYSON
DBG_SKYWALK is the same as DBG_DLIL, so don't reuse subclasses
#define DBG_SKYWALK_ALWAYSON 0x10
macroDBG_SKYWALK_FLOWSWITCH
#define DBG_SKYWALK_FLOWSWITCH 0x11
macroDBG_SKYWALK_NETIF
#define DBG_SKYWALK_NETIF 0x12
macroDBG_SKYWALK_CHANNEL
#define DBG_SKYWALK_CHANNEL 0x13
macroDBG_SKYWALK_PACKET
#define DBG_SKYWALK_PACKET 0x14
macroDBG_AQM_ALWAYSON
DBG_AQM is the same as DBG_DLIL and DBG_SKYWALK, so don't reuse subclasses
#define DBG_AQM_ALWAYSON 0x30
macroDBG_AQM_STATS
#define DBG_AQM_STATS 0x31
macroPPT_TEST
#define PPT_TEST 0x01
macroPPT_JETSAM_HIWAT
#define PPT_JETSAM_HIWAT 0x02
macroPPT_JETSAM_TOPPROC
#define PPT_JETSAM_TOPPROC 0x03
macroDBG_SEC_ERM
#define DBG_SEC_ERM 0x03
macroSKYWALKDBG_CODE
#define SKYWALKDBG_CODE(SubClass, code) KDBG_CODE(DBG_DLIL, SubClass, code)
macroPPTDBG_CODE
#define PPTDBG_CODE(SubClass, code) KDBG_CODE(DBG_PPT, SubClass, code)
macroPERFCTRL_CODE
#define PERFCTRL_CODE(SubClass, code) KDBG_CODE(DBG_PERFCTRL, SubClass, code)
macroAQMDBG_CODE
#define AQMDBG_CODE(SubClass, code) KDBG_CODE(DBG_DLIL, SubClass, code)
variablekdebug_enable
extern unsigned int kdebug_enable
macroKDEBUG_ENABLE_CONT_TIME
Whether timestamps are continuous times or absolute times.
#define KDEBUG_ENABLE_CONT_TIME 0x020U
macroKDEBUG_TRACE
#define KDEBUG_TRACE (KDEBUG_ENABLE_TRACE)
macroKDEBUG_LEVEL_IST
In-System Tracing exposes a limited set of events for release kernels.
#define KDEBUG_LEVEL_IST 1
macroKDEBUG_LEVEL_FULL
Truly verbose, debug-level logging, only set manually.
#define KDEBUG_LEVEL_FULL 3
macroKDEBUG_LEVEL
#define KDEBUG_LEVEL KDEBUG_LEVEL_STANDARD
typedefkd_buf_argtype
Ensure that LP32 and LP64 variants of arm64 use the same kd_buf structure.
typedef uint64_t kd_buf_argtype
structkd_buf
| uint64_t | timestamp | |
| kd_buf_argtype | arg1 | |
| kd_buf_argtype | arg2 | |
| kd_buf_argtype | arg3 | |
| kd_buf_argtype | arg4 | |
| kd_buf_argtype | arg5 | Always the thread ID. |
| uint32_t | debugid | |
| uint32_t | cpuid | Ensure that LP32 and LP64 variants of arm64 use the same kd_buf structure. |
| kd_buf_argtype | unused |
typedefkd_buf
typedef struct kd_buf kd_buf;
macroKDBG_TIMESTAMP_MASK
#define KDBG_TIMESTAMP_MASK 0xffffffffffffffffULL
functionkdbg_set_cpu
static inline void kdbg_set_cpu(kd_buf *kp, int cpu)
▾
claude-fable-5, 2026-08-23 · not from Apple sources · verified against xnu bsd/sys/kdebug_private.h
functionkdbg_get_cpu
static inline int kdbg_get_cpu(kd_buf *kp)
▾
claude-fable-5, 2026-08-23 · not from Apple sources · verified against xnu bsd/sys/kdebug_private.h
Returns the CPU number recorded in a kd_buf trace record, from the cpuid field on LP64 and arm64 kernels or from the top byte of the timestamp on 32-bit kernels.
functionkdbg_set_timestamp
static inline void kdbg_set_timestamp(kd_buf *kp, uint64_t thetime)
▾
claude-fable-5, 2026-08-23 · not from Apple sources · verified against xnu bsd/sys/kdebug_private.h
Stores the timestamp in a kd_buf trace record, masked with KDBG_TIMESTAMP_MASK. On 32-bit kernels only the low 56 bits are used, since the top byte of the field holds the CPU number; on LP64 and arm64 kernels the full 64 bits are stored.
functionkdbg_get_timestamp
static inline uint64_t kdbg_get_timestamp(kd_buf *kp)
▾
claude-fable-5, 2026-08-23 · not from Apple sources · verified against xnu bsd/sys/kdebug_private.h
Returns the timestamp recorded in a kd_buf trace record, masked with KDBG_TIMESTAMP_MASK to strip the CPU number byte on 32-bit kernels.
functionkdbg_set_timestamp_and_cpu
static inline void kdbg_set_timestamp_and_cpu(kd_buf *kp, uint64_t thetime, int cpu)
▾
claude-fable-5, 2026-08-23 · not from Apple sources · verified against xnu bsd/sys/kdebug_private.h
Stores both the timestamp and the CPU number in a kd_buf trace record in one operation; equivalent to kdbg_set_timestamp followed by kdbg_set_cpu.
macroKDBG_TYPEFILTER_BITMAP_SIZE
8KB, one bit for each possible class/subclass combination.
#define KDBG_TYPEFILTER_BITMAP_SIZE ((256 * 256) / 8)
enumkdebug_live_flags_t
Settings that may need to be changed while tracing, protected by the storage
lock or the ktrace lock if tracing is disabled.
These flags must not overlap with `kdebug_flags_t`.
| KDBG_NOWRAP | 2 | |
| KDBG_WRAPPED | 8 |
typedefkdebug_live_flags_t
typedef enum kdebug_live_flags_t kdebug_live_flags_t;
enumkdebug_flags_t
Mostly configuration options, protected by the ktrace lock.
| KDBG_PIDCHECK | 16 | |
| KDBG_MAPINIT | 32 | |
| KDBG_PIDEXCLUDE | 64 | |
| KDBG_LP64 | 256 | |
| KDBG_CONTINUOUS_TIME | 512 | |
| KDBG_DISABLE_COPROCS | 1024 | |
| KDBG_MATCH_DISABLE | 2048 | |
| KDBG_TYPEFILTER_CHECK | 4194304 | |
| KDBG_DEBUGID_64 | 8388608 | |
| KDBG_BUFINIT | -2147483648 |
typedefkdebug_flags_t
typedef enum kdebug_flags_t kdebug_flags_t;
macroKDBG_FREERUN
#define KDBG_FREERUN 0x04
macroKDBG_USERFLAGS
Flags in `kdebug_live_flags_t` and `kdebug_flags_t` that can be modified by
user space.
#define KDBG_USERFLAGS (KDBG_NOWRAP | KDBG_CONTINUOUS_TIME | KDBG_DISABLE_COPROCS | KDBG_MATCH_DISABLE)
structkbufinfo_t
Information about kdebug for user space consumption.
| int | nkdbufs | Size of buffers in number of events (kd_bufs). |
| int | nolog | True is tracing is disabled, false otherwise. |
| unsigned int | flags | Combined `kdebug_live_flags_t` and `kdebug_state_t`. |
| int | nkdthreads | Number of threads in the thread map. |
| int | bufid | Owning process PID. |
typedefkbufinfo_t
typedef struct kbufinfo_t kbufinfo_t;
typedefkd_cpumap_header
typedef struct kd_cpumap_header kd_cpumap_header;
structkd_cpumap_ext
CPU map entries to map `cpuid` from events to names.
| uint32_t | cpu_id | |
| uint32_t | flags | |
| char[32] | name |
typedefkd_cpumap_ext
typedef struct kd_cpumap_ext kd_cpumap_ext;
structkd_event_matcher
Match structured data from events.
| uint32_t | kem_debugid | |
| uint32_t | kem_padding | |
| uint64_t[4] | kem_args |
typedefkd_event_matcher
typedef struct kd_event_matcher kd_event_matcher;
macroKDEBUG_COMMPAGE_ENABLE_TRACE
Options for `kdebug_enable` in the comm-page.
#define KDEBUG_COMMPAGE_ENABLE_TRACE 0x1
macroKDEBUG_COMMPAGE_ENABLE_TYPEFILTER
#define KDEBUG_COMMPAGE_ENABLE_TYPEFILTER 0x2
macroKDEBUG_COMMPAGE_CONTINUOUS
#define KDEBUG_COMMPAGE_CONTINUOUS 0x4
enumkdebug_test_t
Test scenarios.
| KDTEST_KERNEL_MACROS | 1 | |
| KDTEST_OLD_TIMESTAMP | 2 | |
| KDTEST_FUTURE_TIMESTAMP | 3 | |
| KDTEST_SETUP_IOP | 4 | |
| KDTEST_SETUP_COPROCESSOR | 5 | |
| KDTEST_CONTINUOUS_TIMESTAMP | 6 | |
| KDTEST_ABSOLUTE_TIMESTAMP | 7 | |
| KDTEST_PAST_EVENT | 8 |
typedefkdebug_test_t
typedef enum kdebug_test_t kdebug_test_t;
macroKERNEL_DEBUG
Some Apple-internal clients try to use the kernel macros in user space.
#define KERNEL_DEBUG(...) do { } while (0)macroKDEBUG_ENABLE_CHUD
#define KDEBUG_ENABLE_CHUD 0x004U
macroKDEBUG_ENABLE_PPT
#define KDEBUG_ENABLE_PPT 0x008U
macroKDEBUG_ENABLE_SERIAL
#define KDEBUG_ENABLE_SERIAL 0x010U
macroKDEBUG_PPT
#define KDEBUG_PPT (KDEBUG_ENABLE_PPT)
macroKDEBUG_COMMON
#define KDEBUG_COMMON (KDEBUG_ENABLE_TRACE | KDEBUG_ENABLE_PPT)
macroKDBG_RANGECHECK
#define KDBG_RANGECHECK 0x00100000U
macroKDBG_VALCHECK
#define KDBG_VALCHECK 0x00200000U
macroKDBG_SUBCLSTYPE
#define KDBG_SUBCLSTYPE 0x20000
macroKDBG_RANGETYPE
#define KDBG_RANGETYPE 0x40000
macroKDBG_TYPENONE
#define KDBG_TYPENONE 0x80000
macroKDBG_CKTYPES
#define KDBG_CKTYPES 0xF0000
structkd_regtype
| unsigned int | type | |
| unsigned int | value1 | |
| unsigned int | value2 | |
| unsigned int | value3 | |
| unsigned int | value4 |
typedefkd_regtype
typedef struct kd_regtype kd_regtype;
structkd_threadmap
Entry for the legacy thread map system (replaced by stackshot).
| uint64_t | thread | A thread's unique ID. |
| int | valid | The process ID (or 1 for `kernproc`). |
| char[20] | command | The name of the process owning this thread. |
typedefkd_threadmap
typedef struct kd_threadmap kd_threadmap;
typedefkd_cpumap
typedef struct kd_cpumap kd_cpumap;
structRAW_header
File header for legacy trace files.
| int | version_no | |
| int | thread_count | |
| uint64_t | TOD_secs | |
| uint32_t | TOD_usecs |
typedefRAW_header
typedef struct RAW_header RAW_header;
macroRAW_VERSION1
#define RAW_VERSION1 0x55aa0101
macroRAW_VERSION2
#define RAW_VERSION2 0x55aa0200
macrokEnTrCompKernel
#define kEnTrCompKernel 2
macrokEnTrActKernSocket
#define kEnTrActKernSocket 1
macrokEnTrActKernSockRead
#define kEnTrActKernSockRead 2
macrokEnTrActKernSockWrite
#define kEnTrActKernSockWrite 3
macrokEnTrActKernPoll
#define kEnTrActKernPoll 10
macrokEnTrActKernSelect
#define kEnTrActKernSelect 11
macrokEnTrActKernKQWait
#define kEnTrActKernKQWait 12
macrokEnTrEvUnblocked
#define kEnTrEvUnblocked 256
macrokEnTrFlagNonBlocking
#define kEnTrFlagNonBlocking 0x1
macrokEnTrFlagNoWork
#define kEnTrFlagNoWork 0x2
macroENTR_SHOULDTRACE
#define ENTR_SHOULDTRACE kdebug_enable
macroENTR_KDTRACE
#define ENTR_KDTRACE(component, opcode, lifespan, id, quality, value) do {
uint32_t kdcode__;
uintptr_t highval__, lowval__, mask__ = 0xffffffff;
kdcode__ = KDBG_CODE(DBG_ENERGYTRACE,component,opcode)|(lifespan);
highval__ = ((value) >> 32) & mask__;
lowval__ = (value) & mask__;
ENTR_KDTRACEFUNC(kdcode__, id, quality, highval__, lowval__);
} while(0)macrokEnTrModAssociate
#define kEnTrModAssociate (1 << 28)
macroENTR_KDASSOCIATE
#define ENTR_KDASSOCIATE(par_comp, par_opcode, par_act_id, sub_comp, sub_opcode, sub_act_id) do {
unsigned sub_compcode = ((unsigned)sub_comp << 16) | sub_opcode;
ENTR_KDTRACEFUNC(KDBG_CODE(DBG_ENERGYTRACE,par_comp,par_opcode),
par_act_id, kEnTrModAssociate, sub_compcode,
sub_act_id);
} while(0)