#define DbgKdCommandStringStateChange 0x00003032
#define DbgKdMaximumStateChange 0x00003033
+//
+// This is combined with the basic state change code
+// if the state is from an alternate source
+//
+#define DbgKdAlternateStateChange 0x00010000
+
//
// Manipulate Types
//
#define DbgKdPrintStringApi 0x00003230
#define DbgKdGetStringApi 0x00003231
+//
+// Trace I/O Types
+//
+#define DbgKdPrintTraceApi 0x00003330
+
+//
+// Control Request Types
+//
+#define DbgKdRequestHardwareBp 0x00004300
+#define DbgKdReleaseHardwareBp 0x00004301
+
+//
+// File I/O Types
+//
+#define DbgKdCreateFileApi 0x00003430
+#define DbgKdReadFileApi 0x00003431
+#define DbgKdWriteFileApi 0x00003432
+#define DbgKdCloseFileApi 0x00003433
+
//
// Control Report Flags
//
#define REPORT_INCLUDES_SEGS 0x0001
-#define REPORT_INCLUDES_CS 0x0002
+#define REPORT_STANDARD_CS 0x0002
//
// Protocol Versions
#define DBGKD_QUERY_MEMORY_EXECUTE 0x04
#define DBGKD_QUERY_MEMORY_FIXED 0x08
+//
+// Internal Breakpoint Flags
+//
+#define DBGKD_INTERNAL_BP_FLAG_COUNTONLY 0x01
+#define DBGKD_INTERNAL_BP_FLAG_INVALID 0x02
+#define DBGKD_INTERNAL_BP_FLAG_SUSPENDED 0x04
+#define DBGKD_INTERNAL_BP_FLAG_DYING 0x08
+
+//
+// Fill Memory Flags
+//
+#define DBGKD_FILL_MEMORY_VIRTUAL 0x01
+#define DBGKD_FILL_MEMORY_PHYSICAL 0x02
+
+//
+// Physical Memory Caching Flags
+//
+#define DBGKD_CACHING_DEFAULT 0
+#define DBGKD_CACHING_CACHED 1
+#define DBGKD_CACHING_UNCACHED 2
+#define DBGKD_CACHING_WRITE_COMBINED 3
+
+//
+// Partition Switch Flags
+//
+#define DBGKD_PARTITION_DEFAULT 0x00
+#define DBGKD_PARTITION_ALTERNATE 0x01
+
+//
+// Control Space types
+//
+#define DEBUG_CONTROL_SPACE_KPCR 0
+#define DEBUG_CONTROL_SPACE_KPRCB 1
+#define DEBUG_CONTROL_SPACE_KSPECIAL 2
+#define DEBUG_CONTROL_SPACE_KTHREAD 3
+#define X86_DEBUG_CONTROL_SPACE_KSPECIAL 716
+
+
//
// KD Packet Structure
//
ULONG CurrentSymbolEnd;
} X86_DBGKD_CONTROL_SET, *PX86_DBGKD_CONTROL_SET;
+typedef struct _ALPHA_DBGKD_CONTROL_SET
+{
+ ULONG __padding;
+} ALPHA_DBGKD_CONTROL_SET, *PALPHA_DBGKD_CONTROL_SET;
+
typedef struct _IA64_DBGKD_CONTROL_SET
{
ULONG Continue;
ULONG64 CurrentSymbolEnd;
} AMD64_DBGKD_CONTROL_SET, *PAMD64_DBGKD_CONTROL_SET;
+typedef struct _ARM_DBGKD_CONTROL_SET
+{
+ ULONG Continue;
+ ULONG CurrentSymbolStart;
+ ULONG CurrentSymbolEnd;
+} ARM_DBGKD_CONTROL_SET, *PARM_DBGKD_CONTROL_SET;
+
typedef struct _DBGKD_ANY_CONTROL_SET
{
union
{
X86_DBGKD_CONTROL_SET X86ControlSet;
+ ALPHA_DBGKD_CONTROL_SET AlphaControlSet;
IA64_DBGKD_CONTROL_SET IA64ControlSet;
AMD64_DBGKD_CONTROL_SET Amd64ControlSet;
+ ARM_DBGKD_CONTROL_SET ARMControlSet;
};
} DBGKD_ANY_CONTROL_SET, *PDBGKD_ANY_CONTROL_SET;
#include <poppack.h>
-typedef X86_DBGKD_CONTROL_SET DBGKD_CONTROL_SET;
+#if defined(_M_IX86)
+typedef X86_DBGKD_CONTROL_SET DBGKD_CONTROL_SET, *PDBGKD_CONTROL_SET;
+#elif defined(_M_AMD64)
+typedef AMD64_DBGKD_CONTROL_SET DBGKD_CONTROL_SET, *PDBGKD_CONTROL_SET;
+#elif defined(_M_ARM)
+typedef ARM_DBGKD_CONTROL_SET DBGKD_CONTROL_SET, *PDBGKD_CONTROL_SET;
+#else
+#error Unsupported Architecture
+#endif
//
// DBGKM Structure for Exceptions
//
+typedef struct _DBGKM_EXCEPTION32
+{
+ EXCEPTION_RECORD32 ExceptionRecord;
+ ULONG FirstChance;
+} DBGKM_EXCEPTION32, *PDBGKM_EXCEPTION32;
+
typedef struct _DBGKM_EXCEPTION64
{
EXCEPTION_RECORD64 ExceptionRecord;
//
// DBGKD Structure for State Change
//
-typedef struct _DBGKD_CONTROL_REPORT
+typedef struct _X86_DBGKD_CONTROL_REPORT
{
- ULONG Dr6;
- ULONG Dr7;
+ ULONG Dr6;
+ ULONG Dr7;
+ USHORT InstructionCount;
+ USHORT ReportFlags;
+ UCHAR InstructionStream[DBGKD_MAXSTREAM];
+ USHORT SegCs;
+ USHORT SegDs;
+ USHORT SegEs;
+ USHORT SegFs;
+ ULONG EFlags;
+} X86_DBGKD_CONTROL_REPORT, *PX86_DBGKD_CONTROL_REPORT;
+
+typedef struct _ALPHA_DBGKD_CONTROL_REPORT
+{
+ ULONG InstructionCount;
+ UCHAR InstructionStream[DBGKD_MAXSTREAM];
+} ALPHA_DBGKD_CONTROL_REPORT, *PALPHA_DBGKD_CONTROL_REPORT;
+
+typedef struct _IA64_DBGKD_CONTROL_REPORT
+{
+ ULONG InstructionCount;
+ UCHAR InstructionStream[DBGKD_MAXSTREAM];
+} IA64_DBGKD_CONTROL_REPORT, *PIA64_DBGKD_CONTROL_REPORT;
+
+typedef struct _AMD64_DBGKD_CONTROL_REPORT
+{
+ ULONG64 Dr6;
+ ULONG64 Dr7;
+ ULONG EFlags;
USHORT InstructionCount;
USHORT ReportFlags;
UCHAR InstructionStream[DBGKD_MAXSTREAM];
USHORT SegDs;
USHORT SegEs;
USHORT SegFs;
- ULONG EFlags;
-} DBGKD_CONTROL_REPORT, *PDBGKD_CONTROL_REPORT;
+} AMD64_DBGKD_CONTROL_REPORT, *PAMD64_DBGKD_CONTROL_REPORT;
+
+typedef struct _ARM_DBGKD_CONTROL_REPORT
+{
+ ULONG Cpsr;
+ ULONG InstructionCount;
+ UCHAR InstructionStream[DBGKD_MAXSTREAM];
+} ARM_DBGKD_CONTROL_REPORT, *PARM_DBGKD_CONTROL_REPORT;
+
+typedef struct _DBGKD_ANY_CONTROL_REPORT
+{
+ union
+ {
+ X86_DBGKD_CONTROL_REPORT X86ControlReport;
+ ALPHA_DBGKD_CONTROL_REPORT AlphaControlReport;
+ IA64_DBGKD_CONTROL_REPORT IA64ControlReport;
+ AMD64_DBGKD_CONTROL_REPORT Amd64ControlReport;
+ ARM_DBGKD_CONTROL_REPORT ARMControlReport;
+ };
+} DBGKD_ANY_CONTROL_REPORT, *PDBGKD_ANY_CONTROL_REPORT;
+
+#if defined(_M_IX86)
+typedef X86_DBGKD_CONTROL_REPORT DBGKD_CONTROL_REPORT, *PDBGKD_CONTROL_REPORT;
+#elif defined(_M_AMD64)
+typedef AMD64_DBGKD_CONTROL_REPORT DBGKD_CONTROL_REPORT, *PDBGKD_CONTROL_REPORT;
+#elif defined(_M_ARM)
+typedef ARM_DBGKD_CONTROL_REPORT DBGKD_CONTROL_REPORT, *PDBGKD_CONTROL_REPORT;
+#else
+#error Unsupported Architecture
+#endif
//
// DBGKD Structure for Debug I/O Type Print String
} u;
} DBGKD_DEBUG_IO, *PDBGKD_DEBUG_IO;
+//
+// DBGkD Structure for Command String
+//
+typedef struct _DBGKD_COMMAND_STRING
+{
+ ULONG Flags;
+ ULONG Reserved1;
+ ULONG64 Reserved2[7];
+} DBGKD_COMMAND_STRING, *PDBGKD_COMMAND_STRING;
+
//
// DBGKD Structure for Load Symbols
//
+typedef struct _DBGKD_LOAD_SYMBOLS32
+{
+ ULONG PathNameLength;
+ ULONG BaseOfDll;
+ ULONG ProcessId;
+ ULONG CheckSum;
+ ULONG SizeOfImage;
+ BOOLEAN UnloadSymbols;
+} DBGKD_LOAD_SYMBOLS32, *PDBGKD_LOAD_SYMBOLS32;
+
typedef struct _DBGKD_LOAD_SYMBOLS64
{
ULONG PathNameLength;
//
// DBGKD Structure for Wait State Change
//
+
+typedef struct _DBGKD_WAIT_STATE_CHANGE32
+{
+ ULONG NewState;
+ USHORT ProcessorLevel;
+ USHORT Processor;
+ ULONG NumberProcessors;
+ ULONG Thread;
+ ULONG ProgramCounter;
+ union
+ {
+ DBGKM_EXCEPTION32 Exception;
+ DBGKD_LOAD_SYMBOLS32 LoadSymbols;
+ } u;
+ DBGKD_CONTROL_REPORT ControlReport;
+ CONTEXT Context;
+} DBGKD_WAIT_STATE_CHANGE32, *PDBGKD_WAIT_STATE_CHANGE32;
+
typedef struct _DBGKD_WAIT_STATE_CHANGE64
{
ULONG NewState;
CONTEXT Context;
} DBGKD_WAIT_STATE_CHANGE64, *PDBGKD_WAIT_STATE_CHANGE64;
+typedef struct _DBGKD_ANY_WAIT_STATE_CHANGE
+{
+ ULONG NewState;
+ USHORT ProcessorLevel;
+ USHORT Processor;
+ ULONG NumberProcessors;
+ ULONG64 Thread;
+ ULONG64 ProgramCounter;
+ union
+ {
+ DBGKM_EXCEPTION64 Exception;
+ DBGKD_LOAD_SYMBOLS64 LoadSymbols;
+ DBGKD_COMMAND_STRING CommandString;
+ } u;
+ union
+ {
+ DBGKD_CONTROL_REPORT ControlReport;
+ DBGKD_ANY_CONTROL_REPORT AnyControlReport;
+ };
+} DBGKD_ANY_WAIT_STATE_CHANGE, *PDBGKD_ANY_WAIT_STATE_CHANGE;
+
//
// DBGKD Manipulate Structures
//
+typedef struct _DBGKD_READ_MEMORY32
+{
+ ULONG TargetBaseAddress;
+ ULONG TransferCount;
+ ULONG ActualBytesRead;
+} DBGKD_READ_MEMORY32, *PDBGKD_READ_MEMORY32;
+
typedef struct _DBGKD_READ_MEMORY64
{
ULONG64 TargetBaseAddress;
ULONG ActualBytesRead;
} DBGKD_READ_MEMORY64, *PDBGKD_READ_MEMORY64;
+typedef struct _DBGKD_WRITE_MEMORY32
+{
+ ULONG TargetBaseAddress;
+ ULONG TransferCount;
+ ULONG ActualBytesWritten;
+} DBGKD_WRITE_MEMORY32, *PDBGKD_WRITE_MEMORY32;
+
typedef struct _DBGKD_WRITE_MEMORY64
{
ULONG64 TargetBaseAddress;
ULONG ContextFlags;
} DBGKD_SET_CONTEXT, *PDBGKD_SET_CONTEXT;
+typedef struct _DBGKD_WRITE_BREAKPOINT32
+{
+ ULONG BreakPointAddress;
+ ULONG BreakPointHandle;
+} DBGKD_WRITE_BREAKPOINT32, *PDBGKD_WRITE_BREAKPOINT32;
+
typedef struct _DBGKD_WRITE_BREAKPOINT64
{
ULONG64 BreakPointAddress;
} DBGKD_CONTINUE2, *PDBGKD_CONTINUE2;
#include <poppack.h>
+typedef struct _DBGKD_READ_WRITE_IO32
+{
+ ULONG IoAddress;
+ ULONG DataSize;
+ ULONG DataValue;
+} DBGKD_READ_WRITE_IO32, *PDBGKD_READ_WRITE_IO32;
+
typedef struct _DBGKD_READ_WRITE_IO64
{
ULONG64 IoAddress;
ULONG DataValue;
} DBGKD_READ_WRITE_IO64, *PDBGKD_READ_WRITE_IO64;
+typedef struct _DBGKD_READ_WRITE_IO_EXTENDED32
+{
+ ULONG DataSize;
+ ULONG InterfaceType;
+ ULONG BusNumber;
+ ULONG AddressSpace;
+ ULONG IoAddress;
+ ULONG DataValue;
+} DBGKD_READ_WRITE_IO_EXTENDED32, *PDBGKD_READ_WRITE_IO_EXTENDED32;
+
typedef struct _DBGKD_READ_WRITE_IO_EXTENDED64
{
ULONG DataSize;
ULONG NumberOfSpecialCalls;
} DBGKD_QUERY_SPECIAL_CALLS, *PDBGKD_QUERY_SPECIAL_CALLS;
+typedef struct _DBGKD_SET_SPECIAL_CALL32
+{
+ ULONG SpecialCall;
+} DBGKD_SET_SPECIAL_CALL32, *PDBGKD_SET_SPECIAL_CALL32;
+
typedef struct _DBGKD_SET_SPECIAL_CALL64
{
ULONG64 SpecialCall;
} DBGKD_SET_SPECIAL_CALL64, *PDBGKD_SET_SPECIAL_CALL64;
+typedef struct _DBGKD_SET_INTERNAL_BREAKPOINT32
+{
+ ULONG BreakpointAddress;
+ ULONG Flags;
+} DBGKD_SET_INTERNAL_BREAKPOINT32, *PDBGKD_SET_INTERNAL_BREAKPOINT32;
+
typedef struct _DBGKD_SET_INTERNAL_BREAKPOINT64
{
ULONG64 BreakpointAddress;
ULONG Flags;
} DBGKD_SET_INTERNAL_BREAKPOINT64, *PDBGKD_SET_INTERNAL_BREAKPOINT64;
+typedef struct _DBGKD_GET_INTERNAL_BREAKPOINT32
+{
+ ULONG BreakpointAddress;
+ ULONG Flags;
+ ULONG Calls;
+ ULONG MaxCallsPerPeriod;
+ ULONG MinInstructions;
+ ULONG MaxInstructions;
+ ULONG TotalInstructions;
+} DBGKD_GET_INTERNAL_BREAKPOINT32, *PDBGKD_GET_INTERNAL_BREAKPOINT32;
+
typedef struct _DBGKD_GET_INTERNAL_BREAKPOINT64
{
ULONG64 BreakpointAddress;
//
// DBGKD Structure for Manipulate
//
+typedef struct _DBGKD_MANIPULATE_STATE32
+{
+ ULONG ApiNumber;
+ USHORT ProcessorLevel;
+ USHORT Processor;
+ NTSTATUS ReturnStatus;
+ union
+ {
+ DBGKD_READ_MEMORY32 ReadMemory;
+ DBGKD_WRITE_MEMORY32 WriteMemory;
+ DBGKD_READ_MEMORY64 ReadMemory64;
+ DBGKD_WRITE_MEMORY64 WriteMemory64;
+ DBGKD_GET_CONTEXT GetContext;
+ DBGKD_SET_CONTEXT SetContext;
+ DBGKD_WRITE_BREAKPOINT32 WriteBreakPoint;
+ DBGKD_RESTORE_BREAKPOINT RestoreBreakPoint;
+ DBGKD_CONTINUE Continue;
+ DBGKD_CONTINUE2 Continue2;
+ DBGKD_READ_WRITE_IO32 ReadWriteIo;
+ DBGKD_READ_WRITE_IO_EXTENDED32 ReadWriteIoExtended;
+ DBGKD_QUERY_SPECIAL_CALLS QuerySpecialCalls;
+ DBGKD_SET_SPECIAL_CALL32 SetSpecialCall;
+ DBGKD_SET_INTERNAL_BREAKPOINT32 SetInternalBreakpoint;
+ DBGKD_GET_INTERNAL_BREAKPOINT32 GetInternalBreakpoint;
+ DBGKD_GET_VERSION32 GetVersion32;
+ DBGKD_BREAKPOINTEX BreakPointEx;
+ DBGKD_READ_WRITE_MSR ReadWriteMsr;
+ DBGKD_SEARCH_MEMORY SearchMemory;
+ DBGKD_GET_SET_BUS_DATA GetSetBusData;
+ DBGKD_FILL_MEMORY FillMemory;
+ DBGKD_QUERY_MEMORY QueryMemory;
+ DBGKD_SWITCH_PARTITION SwitchPartition;
+ } u;
+} DBGKD_MANIPULATE_STATE32, *PDBGKD_MANIPULATE_STATE32;
+
typedef struct _DBGKD_MANIPULATE_STATE64
{
ULONG ApiNumber;
} u;
} DBGKD_MANIPULATE_STATE64, *PDBGKD_MANIPULATE_STATE64;
+//
+// File I/O Structure
+//
+typedef struct _DBGKD_CREATE_FILE
+{
+ ULONG DesiredAccess;
+ ULONG FileAttributes;
+ ULONG ShareAccess;
+ ULONG CreateDisposition;
+ ULONG CreateOptions;
+ ULONG64 Handle;
+ ULONG64 Length;
+} DBGKD_CREATE_FILE, *PDBGKD_CREATE_FILE;
+
+typedef struct _DBGKD_READ_FILE
+{
+ ULONG64 Handle;
+ ULONG64 Offset;
+ ULONG Length;
+} DBGKD_READ_FILE, *PDBGKD_READ_FILE;
+
+typedef struct _DBGKD_WRITE_FILE
+{
+ ULONG64 Handle;
+ ULONG64 Offset;
+ ULONG Length;
+} DBGKD_WRITE_FILE, *PDBGKD_WRITE_FILE;
+
+typedef struct _DBGKD_CLOSE_FILE
+{
+ ULONG64 Handle;
+} DBGKD_CLOSE_FILE, *PDBGKD_CLOSE_FILE;
+
+typedef struct _DBGKD_FILE_IO
+{
+ ULONG ApiNumber;
+ ULONG Status;
+ union
+ {
+ ULONG64 ReserveSpace[7];
+ DBGKD_CREATE_FILE CreateFile;
+ DBGKD_READ_FILE ReadFile;
+ DBGKD_WRITE_FILE WriteFile;
+ DBGKD_CLOSE_FILE CloseFile;
+ } u;
+} DBGKD_FILE_IO, *PDBGKD_FILE_IO;
+
+
+//
+// Control Request Structure
+//
+typedef struct _DBGKD_REQUEST_BREAKPOINT
+{
+ ULONG HardwareBreakPointNumber;
+ ULONG Available;
+} DBGKD_REQUEST_BREAKPOINT, *PDBGKD_REQUEST_BREAKPOINT;
+
+typedef struct _DBGKD_RELEASE_BREAKPOINT
+{
+ ULONG HardwareBreakPointNumber;
+ ULONG Released;
+} DBGKD_RELEASE_BREAKPOINT, *PDBGKD_RELEASE_BREAKPOINT;
+
+typedef struct _DBGKD_CONTROL_REQUEST
+{
+ ULONG ApiNumber;
+ union
+ {
+ DBGKD_REQUEST_BREAKPOINT RequestBreakpoint;
+ DBGKD_RELEASE_BREAKPOINT ReleaseBreakpoint;
+ } u;
+} DBGKD_CONTROL_REQUEST, *PDBGKD_CONTROL_REQUEST;
+
+//
+// Trace I/O Structure
+//
+typedef struct _DBGKD_PRINT_TRACE
+{
+ ULONG LengthOfData;
+} DBGKD_PRINT_TRACE, *PDBGKD_PRINT_TRACE;
+
+typedef struct _DBGKD_TRACE_IO
+{
+ ULONG ApiNumber;
+ USHORT ProcessorLevel;
+ USHORT Processor;
+ union
+ {
+ ULONG64 ReserveSpace[7];
+ DBGKD_PRINT_TRACE PrintTrace;
+ } u;
+} DBGKD_TRACE_IO, *PDBGKD_TRACE_IO;
+
+#if defined(_M_AMD64)
+
+#define CopyExceptionRecord(Ex64From, Ex64To) \
+ RtlCopyMemory(Ex64To, Ex64From, sizeof(EXCEPTION_RECORD64))
+
+#else
+
FORCEINLINE
VOID
ExceptionRecord32To64(IN PEXCEPTION_RECORD32 Ex32,
}
}
+#define CopyExceptionRecord(Ex32From, Ex64To) \
+ ExceptionRecord32To64((PEXCEPTION_RECORD32)Ex32From, Ex64To)
+
+#endif
+
#endif