HIDDriverKitDebug.h [plain text]
#ifndef HIDDriverKitDebug_h
#define HIDDriverKitDebug_h
#include <stdio.h>
#include <os/log.h>
#include <sys/kdebug.h>
uint32_t gHIDDKDebug();
using _cstr = const char * const;
static constexpr _cstr slash_to_end(_cstr str, _cstr last_slash)
{
return
*str == '\0' ? last_slash :
*str == '/' ? slash_to_end(str + 1, str + 1) : slash_to_end(str + 1, last_slash);
}
static constexpr _cstr slash_to_end(_cstr str)
{
return slash_to_end (str, str);
}
#define __SHORT_FILENAME__ ({constexpr _cstr _fl {slash_to_end(__FILE__)}; _fl;})
#define HIDLog(fmt, args...) \
os_log(OS_LOG_DEFAULT, "[%{public}s:%d]" fmt "\n", __SHORT_FILENAME__, __LINE__, ##args);
#if TARGET_OS_DRIVERKIT
#define HIDLogDebug(fmt, args...) HIDLog(fmt, ##args)
#define HIDLogInfo(fmt, args...) HIDLog(fmt, ##args)
#define HIDLogError(fmt, args...) HIDLog(fmt, ##args)
#define HIDLogFault(fmt, args...) HIDLog(fmt, ##args)
#else
#define HIDLogDebug(fmt, args...) \
os_log_debug(OS_LOG_DEFAULT, "[%{public}s:%d]" fmt "\n", __SHORT_FILENAME__, __LINE__, ##args)
#define HIDLogInfo(fmt, args...) \
os_log_info(OS_LOG_DEFAULT, "[%{public}s:%d]" fmt "\n", __SHORT_FILENAME__, __LINE__, ##args)
#define HIDLogError(fmt, args...) \
os_log_error(OS_LOG_DEFAULT, "[%{public}s:%d]" fmt "\n", __SHORT_FILENAME__, __LINE__, ##args)
#define HIDLogFault(fmt, args...) \
os_log_fault(OS_LOG_DEFAULT, "[%{public}s:%d]" fmt "\n", __SHORT_FILENAME__, __LINE__, ##args)
#endif // TARGET_OS_DRIVERKIT
#define getRegistryID \
^(){uint64_t rid = 0; GetRegistryEntryID(&rid); return rid;}
#define HIDServiceLog(fmt, ...) HIDLog("[0x%llx] " fmt "\n", getRegistryID(), ##__VA_ARGS__)
#define HIDServiceLogInfo(fmt, ...) HIDLogInfo("[0x%llx] " fmt "\n", getRegistryID(), ##__VA_ARGS__)
#define HIDServiceLogError(fmt, ...) HIDLogError("[0x%llx] " fmt "\n", getRegistryID(), ##__VA_ARGS__)
#define HIDServiceLogDebug(fmt, ...) HIDLogDebug("[0x%llx] " fmt "\n", getRegistryID(), ##__VA_ARGS__)
#define HIDServiceLogFault(fmt, ...) HIDLogFault("[0x%llx] " fmt "\n", getRegistryID(), ##__VA_ARGS__)
enum {
kHIDDK_TraceBase = 0x3000,
kHIDDK_ES_HandleReportCB = 0x3001, kHIDDK_Dev_InputReport = 0x3002, kHIDDK_ES_Start = 0x3003, kHIDDK_ES_Stop = 0x3004, kHIDDK_Dev_Start = 0x3005, kHIDDK_Dev_Stop = 0x3006, };
#define HIDTrace(code, a, b, c, d) kdebug_trace(IOKDBG_CODE(DBG_IOHID, code), a, b, c, d)
#define HIDTraceStart(code, a, b, c, d) kdebug_trace(IOKDBG_CODE(DBG_IOHID, code) | DBG_FUNC_START, a, b, c, d)
#define HIDTraceEnd(code, a, b, c, d) kdebug_trace(IOKDBG_CODE(DBG_IOHID, code) | DBG_FUNC_END, a, b, c, d)
#endif