#include <sys/kdebug_private.h>

sys/kdebug_private.h Kernel.framework

includes: os/base.h, Kernel/stdint.h, Kernel/stdbool.h, sys/cdefs.h, sys/kdebug.h
80 macros · 13 typedefs · 9 structs · 5 functions · 3 enums · 1 variable

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_SSMA

DBG_SECURITY private subclasses
#define DBG_SEC_SSMA 0x02

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_TRACE

Enable tracing.
#define KDEBUG_ENABLE_TRACE 0x001U

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_NONE

No kdebug events are emitted with the macros.
#define KDEBUG_LEVEL_NONE 0

macroKDEBUG_LEVEL_IST

In-System Tracing exposes a limited set of events for release kernels.
#define KDEBUG_LEVEL_IST 1

macroKDEBUG_LEVEL_STANDARD

The default for development kernels.
#define KDEBUG_LEVEL_STANDARD 2

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

size 64, align 8
uint64_ttimestamp
kd_buf_argtypearg1
kd_buf_argtypearg2
kd_buf_argtypearg3
kd_buf_argtypearg4
kd_buf_argtypearg5Always the thread ID.
uint32_tdebugid
uint32_tcpuidEnsure that LP32 and LP64 variants of arm64 use the same kd_buf structure.
kd_buf_argtypeunused

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
Stores the CPU number in a kd_buf trace record. On LP64 and arm64 kernels kd_buf carries the CPU in its own cpuid field; on 32-bit kernels the CPU number is packed into the top byte of the 64-bit timestamp (KDBG_CPU_SHIFT).

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`.
underlying type uint32_t
KDBG_NOWRAP2
KDBG_WRAPPED8

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.
underlying type uint32_t
KDBG_PIDCHECK16
KDBG_MAPINIT32
KDBG_PIDEXCLUDE64
KDBG_LP64256
KDBG_CONTINUOUS_TIME512
KDBG_DISABLE_COPROCS1024
KDBG_MATCH_DISABLE2048
KDBG_TYPEFILTER_CHECK4194304
KDBG_DEBUGID_648388608
KDBG_BUFINIT-2147483648

typedefkdebug_flags_t

typedef enum kdebug_flags_t kdebug_flags_t;

macroKDBG_INIT

Obsolete flags.
#define KDBG_INIT 0x01

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.
size 20, align 4
intnkdbufsSize of buffers in number of events (kd_bufs).
intnologTrue is tracing is disabled, false otherwise.
unsigned intflagsCombined `kdebug_live_flags_t` and `kdebug_state_t`.
intnkdthreadsNumber of threads in the thread map.
intbufidOwning process PID.

typedefkbufinfo_t

typedef struct kbufinfo_t kbufinfo_t;

structkd_cpumap_header

Header for CPU mapping list.
size 8, align 4
uint32_tversion_no
uint32_tcpu_count

typedefkd_cpumap_header

typedef struct kd_cpumap_header kd_cpumap_header;

macroKDBG_CPUMAP_IS_IOP

CPU map entry flags.
#define KDBG_CPUMAP_IS_IOP 0x1

structkd_cpumap_ext

CPU map entries to map `cpuid` from events to names.
size 40, align 4
uint32_tcpu_id
uint32_tflags
char[32]name

typedefkd_cpumap_ext

typedef struct kd_cpumap_ext kd_cpumap_ext;

structkd_event_matcher

Match structured data from events.
size 40, align 8
uint32_tkem_debugid
uint32_tkem_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.
underlying type uint32_t
KDTEST_KERNEL_MACROS1
KDTEST_OLD_TIMESTAMP2
KDTEST_FUTURE_TIMESTAMP3
KDTEST_SETUP_IOP4
KDTEST_SETUP_COPROCESSOR5
KDTEST_CONTINUOUS_TIMESTAMP6
KDTEST_ABSOLUTE_TIMESTAMP7
KDTEST_PAST_EVENT8

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_ENTROPY

Obsolete options for `kdebug_enable`.
#define KDEBUG_ENABLE_ENTROPY 0x002U

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)

macroKDBG_LOCKINIT

Obsolete flags.
#define KDBG_LOCKINIT 0x0080

macroKDBG_RANGECHECK

#define KDBG_RANGECHECK 0x00100000U

macroKDBG_VALCHECK

#define KDBG_VALCHECK 0x00200000U

macroKDBG_CLASSTYPE

Type values for `kd_regtype`.
#define KDBG_CLASSTYPE 0x10000

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

size 20, align 4
unsigned inttype
unsigned intvalue1
unsigned intvalue2
unsigned intvalue3
unsigned intvalue4

typedefkd_regtype

typedef struct kd_regtype kd_regtype;

structkd_threadmap

Entry for the legacy thread map system (replaced by stackshot).
size 32, align 8
uint64_tthreadA thread's unique ID.
intvalidThe process ID (or 1 for `kernproc`).
char[20]commandThe name of the process owning this thread.

typedefkd_threadmap

typedef struct kd_threadmap kd_threadmap;

structkd_cpumap

Legacy CPU map entry.
size 16, align 4
uint32_tcpu_id
uint32_tflags
char[8]name

typedefkd_cpumap

typedef struct kd_cpumap kd_cpumap;

structRAW_header

File header for legacy trace files.
size 24, align 8
intversion_no
intthread_count
uint64_tTOD_secs
uint32_tTOD_usecs

typedefRAW_header

typedef struct RAW_header RAW_header;

macroRAW_VERSION0

Obsolete `version_no` for legacy trace files.
#define RAW_VERSION0 0x55aa0000

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)