Kernel和Driver可以通过DbgPrint或DbgPrintEx打log.
KdPrint和KdPrintEx也是可行的,不过用法有差异。
MSDN: KdPrint is identical to the DbgPrint routine in code that is compiled for a debug configuration. This routine has no effect if compiled for a release configuration. Only kernel-mode drivers can call the KdPrint routine.
DbgPrint输出log
Windows内核并不会把Kernel log用UART输出,而是通过系统服务(int 2dh)的方式输出。
- DbgPrint --> vDbgPrintExWithPrefixInternal
- --> DebugPrint
- --> DebugService
注意,此处Service参数传入BREAKPOINT_PRINT, 表示输出log.
int 2dh 进入_KiDebugService例程.
之后在汇编代码里面周转了很久,最终根据BREAKPOINT_PRINT决定输出log.
DbgPrint的实现确实不走寻常路!
DbgView工具查看Kernel log
DebugView - Windows Sysinternals | Microsoft Learn
按官方的说法,DbgView不仅可以抓Userspace log, 也可以抓Kernel log.
DbgView抓Kernel log原理