📄 kdp.h
字号:
/*++Copyright (c) 1990-2000 Microsoft Corporation. All rights reserved.Module Name: kdp.hAbstract: Private include file for the Kernel Debugger subcomponentEnvironment: WinCE--*/#include "kernel.h"#include "string.h"#include "kdpcpu.h"#include "dbg.h"typedef ULONG NTSTATUS;#define MmDbgReadCheck(Address) VerifyAddress(Address)#define MmDbgWriteCheck(Address) VerifyAddress(Address)#define MmDbgTranslatePhysicalAddress(Address) (Address)#define PAGE_ALIGN(Va) ((ULONG)(Va) & ~(PAGE_SIZE - 1))#define BYTE_OFFSET(Va) ((ULONG)(Va) & (PAGE_SIZE - 1))//// Ke stub routines and definitions//#if defined(x86)//// There is no need to sweep the i386 cache because it is unified (no// distinction is made between instruction and data entries).// #define KeSweepCurrentIcache()#elif defined(SHx)//// There is no need to sweep the SH3 cache because it is unified (no// distinction is made between instruction and data entries).// extern void FlushCache (void);#define KeSweepCurrentIcache() FlushCache()#elseextern void FlushICache (void);#define KeSweepCurrentIcache() FlushICache()#endif//// GetVersion API (VER_PRODUCTBUILD found in sdk/inc/ntverp.h)//#define VER_PRODUCTBUILD 1169#define STATUS_SYSTEM_BREAK ((NTSTATUS)0x80000114L) //// TRAPA / BREAK immediate field value for breakpoints//#define DEBUGBREAK_LOAD_SYMBOLS_BREAKPOINT 0#define DEBUGBREAK_STOP_BREAKPOINT 1#define DEBUG_PROCESS_SWITCH_BREAKPOINT 2#define DEBUG_THREAD_SWITCH_BREAKPOINT 3#define DEBUG_BREAK_IN 4#define DEBUG_REGISTER_BREAKPOINT 5#define DEBUGBREAK_UNLOAD_SYMBOLS_BREAKPOINT 6//// DbgKd APIs are for the portable kernel debugger////// KD_PACKETS are the low level data format used in KD. All packets// begin with a packet leader, byte count, packet type. The sequence// for accepting a packet is://// - read 4 bytes to get packet leader. If read times out (10 seconds)// with a short read, or if packet leader is incorrect, then retry// the read.//// - next read 2 byte packet type. If read times out (10 seconds) with// a short read, or if packet type is bad, then start again looking// for a packet leader. //// - next read 2 byte byte count. If read times out (10 seconds) with// a short read, or if byte count is greater than PACKET_MAX_SIZE,// then start again looking for a packet leader.// Byte Count is 0 in case of a Control Packet//// - next read 4 byte packet Id. If read times out (10 seconds)// with a short read, or if packet Id is not what we expect, then// ask for resend and restart again looking for a packet leader.// In the case of a Reset or Resend Control Packet, the packet Id// has no meaning //// - next read 4 byte packet data checksum.// In the case of a Control Packet, the packet data checksum has no // meaning //// - The packet data immediately follows the packet header (not if control// packet). There should be ByteCount bytes following the packet header. // Read the packet data, if read times out (10 seconds) then start again // looking for a packet leader.//// - The trailing byte immediately follows the packet data (not if control// packet).//typedef struct _KD_PACKET { ULONG PacketLeader; USHORT PacketType; USHORT ByteCount; ULONG PacketId; ULONG Checksum;} KD_PACKET, *PKD_PACKET;#define PACKET_MAX_SIZE 4000#define INITIAL_PACKET_ID 0x80800000 // DON't use 0#define SYNC_PACKET_ID 0x00000800 // Or in with INITIAL_PACKET_ID // to force a packet ID reset.//// BreakIn packet//#define BREAKIN_PACKET 0x15151515#define BREAKIN_PACKET_BYTE 0x15//// Packet lead in sequence//#define PACKET_LEADER 0x1f1f1f1f //0x77000077#define PACKET_LEADER_BYTE 0x1f#define CONTROL_PACKET_LEADER 0x12121212#define CONTROL_PACKET_LEADER_BYTE 0x12 //Must be greater than MAX packet type//// Packet Trailing Byte//#define PACKET_TRAILING_BYTE 0xAA//// Packet Types//#define PACKET_TYPE_UNUSED 0#define PACKET_TYPE_KD_STATE_CHANGE 1#define PACKET_TYPE_KD_STATE_MANIPULATE 2#define PACKET_TYPE_KD_DEBUG_IO 3#define PACKET_TYPE_KD_ACKNOWLEDGE 4 // Packet-control type#define PACKET_TYPE_KD_RESEND 5 // Packet-control type#define PACKET_TYPE_KD_RESET 6 // Packet-control type#define PACKET_TYPE_MAX 7//// If the packet type is PACKET_TYPE_KD_STATE_CHANGE, then// the format of the packet data is as follows://#define DbgKdExceptionStateChange 0x00003030L#define DbgKdLoadSymbolsStateChange 0x00003031L//// Pathname Data follows directly//typedef struct _DBGKM_EXCEPTION { EXCEPTION_RECORD ExceptionRecord; ULONG FirstChance;} DBGKM_EXCEPTION, *PDBGKM_EXCEPTION;typedef struct _DBGKD_LOAD_SYMBOLS { ULONG PathNameLength; PVOID BaseOfDll; ULONG ProcessId; ULONG CheckSum; ULONG SizeOfImage; BOOLEAN UnloadSymbols;} DBGKD_LOAD_SYMBOLS, *PDBGKD_LOAD_SYMBOLS;typedef struct _DBGKD_WAIT_STATE_CHANGE { ULONG NewState; USHORT ProcessorType; USHORT Processor; ULONG NumberProcessors; PVOID Thread; PVOID ProgramCounter; union { DBGKM_EXCEPTION Exception; DBGKD_LOAD_SYMBOLS LoadSymbols; } u; DBGKD_CONTROL_REPORT ControlReport;#if defined(MIPS) DWORD Pad;#endif CONTEXT Context;#if defined(SH3e) || defined(SH4) DEBUG_REGISTERS DebugRegisters;#endif } DBGKD_WAIT_STATE_CHANGE, *PDBGKD_WAIT_STATE_CHANGE;//// If the packet type is PACKET_TYPE_KD_STATE_MANIPULATE, then// the format of the packet data is as follows://// Api Numbers for state manipulation//#define DbgKdReadVirtualMemoryApi 0x00003130L#define DbgKdWriteVirtualMemoryApi 0x00003131L#define DbgKdGetContextApi 0x00003132L#define DbgKdSetContextApi 0x00003133L#define DbgKdWriteBreakPointApi 0x00003134L#define DbgKdRestoreBreakPointApi 0x00003135L#define DbgKdContinueApi 0x00003136L#define DbgKdReadControlSpaceApi 0x00003137L#define DbgKdWriteControlSpaceApi 0x00003138L#define DbgKdReadIoSpaceApi 0x00003139L#define DbgKdWriteIoSpaceApi 0x0000313AL#define DbgKdRebootApi 0x0000313BL#define DbgKdContinueApi2 0x0000313CL#define DbgKdReadPhysicalMemoryApi 0x0000313DL#define DbgKdWritePhysicalMemoryApi 0x0000313EL#define DbgKdQuerySpecialCallsApi 0x0000313FL#define DbgKdSetSpecialCallApi 0x00003140L#define DbgKdClearSpecialCallsApi 0x00003141L#define DbgKdSetInternalBreakPointApi 0x00003142L#define DbgKdGetInternalBreakPointApi 0x00003143L#define DbgKdReadIoSpaceExtendedApi 0x00003144L#define DbgKdWriteIoSpaceExtendedApi 0x00003145L#define DbgKdGetVersionApi 0x00003146L#define DbgKdWriteBreakPointExApi 0x00003147L#define DbgKdRestoreBreakPointExApi 0x00003148L#define DbgKdCauseBugCheckApi 0x00003149L#define DbgKdSwitchProcessor 0x00003150L#define DbgKdPageInApi 0x00003151L#define DbgKdReadMachineSpecificRegister 0x00003152L#define DbgKdWriteMachineSpecificRegister 0x00003153L#define DbgKdManipulateBreakpoint 0x00003154L#define DbgKdTerminateApi 0x00003155L// end//// Response is a read memory message with data following//typedef struct _DBGKD_READ_MEMORY { PVOID TargetBaseAddress; ULONG TransferCount; ULONG ActualBytesRead;} DBGKD_READ_MEMORY, *PDBGKD_READ_MEMORY;//// Data follows directly//typedef struct _DBGKD_WRITE_MEMORY { PVOID TargetBaseAddress; ULONG TransferCount; ULONG ActualBytesWritten;} DBGKD_WRITE_MEMORY, *PDBGKD_WRITE_MEMORY;//// Response is a get context message with a full context record following//typedef struct _DBGKD_GET_CONTEXT { ULONG ContextFlags;} DBGKD_GET_CONTEXT, *PDBGKD_GET_CONTEXT;//// Full Context record follows//typedef struct _DBGKD_SET_CONTEXT { ULONG ContextFlags;} DBGKD_SET_CONTEXT, *PDBGKD_SET_CONTEXT;typedef struct _DBGKD_WRITE_BREAKPOINT { PVOID BreakPointAddress; ULONG BreakPointHandle;} DBGKD_WRITE_BREAKPOINT, *PDBGKD_WRITE_BREAKPOINT;typedef struct _DBGKD_RESTORE_BREAKPOINT { ULONG BreakPointHandle;} DBGKD_RESTORE_BREAKPOINT, *PDBGKD_RESTORE_BREAKPOINT;typedef struct _DBGKD_BREAKPOINTEX { ULONG BreakPointCount; NTSTATUS ContinueStatus;} DBGKD_BREAKPOINTEX, *PDBGKD_BREAKPOINTEX;typedef struct _DBGKD_CONTINUE { NTSTATUS ContinueStatus;} DBGKD_CONTINUE, *PDBGKD_CONTINUE;typedef struct _DBGKD_CONTINUE2 { NTSTATUS ContinueStatus; DBGKD_CONTROL_SET ControlSet;} DBGKD_CONTINUE2, *PDBGKD_CONTINUE2;typedef struct _DBGKD_READ_WRITE_IO { ULONG DataSize; // 1, 2, 4 PVOID IoAddress; ULONG DataValue;} DBGKD_READ_WRITE_IO, *PDBGKD_READ_WRITE_IO;typedef struct _DBGKD_READ_WRITE_IO_EXTENDED { ULONG DataSize; // 1, 2, 4 ULONG InterfaceType; ULONG BusNumber; ULONG AddressSpace; PVOID IoAddress; ULONG DataValue;} DBGKD_READ_WRITE_IO_EXTENDED, *PDBGKD_READ_WRITE_IO_EXTENDED;typedef struct _DBGKD_READ_WRITE_MSR { ULONG Msr; ULONG DataValueLow; ULONG DataValueHigh;} DBGKD_READ_WRITE_MSR, *PDBGKD_READ_WRITE_MSR;typedef struct _DBGKD_QUERY_SPECIAL_CALLS { ULONG NumberOfSpecialCalls; // ULONG SpecialCalls[];} DBGKD_QUERY_SPECIAL_CALLS, *PDBGKD_QUERY_SPECIAL_CALLS;typedef struct _DBGKD_SET_SPECIAL_CALL { ULONG SpecialCall;} DBGKD_SET_SPECIAL_CALL, *PDBGKD_SET_SPECIAL_CALL;typedef struct _DBGKD_SET_INTERNAL_BREAKPOINT { ULONG BreakpointAddress; ULONG Flags;} DBGKD_SET_INTERNAL_BREAKPOINT, *PDBGKD_SET_INTERNAL_BREAKPOINT;typedef struct _DBGKD_GET_INTERNAL_BREAKPOINT { ULONG BreakpointAddress; ULONG Flags; ULONG Calls; ULONG MaxCallsPerPeriod; ULONG MinInstructions; ULONG MaxInstructions; ULONG TotalInstructions;} DBGKD_GET_INTERNAL_BREAKPOINT, *PDBGKD_GET_INTERNAL_BREAKPOINT;#define DBGKD_INTERNAL_BP_FLAG_COUNTONLY 0x00000001 // don't count instructions#define DBGKD_INTERNAL_BP_FLAG_INVALID 0x00000002 // disabled BP#define DBGKD_INTERNAL_BP_FLAG_SUSPENDED 0x00000004 // temporarily suspended#define DBGKD_INTERNAL_BP_FLAG_DYING 0x00000008 // kill on exittypedef struct _DBGKD_GET_VERSION { USHORT MajorVersion; USHORT MinorVersion; USHORT ProtocolVersion; USHORT Flags; ULONG KernBase; ULONG PsLoadedModuleList; USHORT MachineType; // Processor Architecture (SHx, Intel x86, MIPS ...) // // help for walking stacks with user callbacks: // // // The address of the thread structure is provided in the // WAIT_STATE_CHANGE packet. This is the offset from the base of // the thread structure to the pointer to the kernel stack frame // for the currently active usermode callback. // USHORT ThCallbackStack; // offset in thread data // // these values are offsets into that frame: // USHORT NextCallback; // saved pointer to next callback frame USHORT FramePointer; // saved frame pointer // // Address of the kernel callout routine. // ULONG KiCallUserMode; // kernel routine // // Address of the usermode entry point for callbacks. // ULONG KeUserCallbackDispatcher; // address in ntdll ULONG dwProcessorName; // this one is used and is assigned to CEProcessorType ULONG KernDataSectionOffset; // Relocated Kernel Data Section Offset} DBGKD_GET_VERSION, *PDBGKD_GET_VERSION;#define DBGKD_VERS_FLAG_MP 0x0001 // kernel is MP builttypedef struct _DBGKD_PAGEIN { ULONG Address; ULONG ContinueStatus;} DBGKD_PAGEIN, *PDBGKD_PAGEIN;#define DBGKD_MBP_FLAG_SET 0x00000001 // Set#define DBGKD_MBP_FLAG_RESTORE 0x00000002 // Restore// If both SET and RESTORE bits are not set then assumption is that it is a query.#define DBGKD_MBP_HARDWARE 0x00000004 // Specify it is hardware#define DBGKD_MBP_SOFTWARE 0x00000008 // Specify it as software// If both HARDWARE & SOFTWARE is not set that it is a don't Care.// On a query this can be UNKNOWN.#define DBGKD_MBP_FLAG_CP 0X80000000 // Hardware Code Breakpoint#define DBGKD_MBP_FLAG_DP 0X40000000 // Hardware Data Breakpoint// If both of CP or DP is not set than the assumption is that it is a temp breakpoint#define DBGKD_MBP_16BIT 0x00000010 // Is it a 16 bit breakpoint ?typedef struct _DBGKD_MANIPULATE_BREAKPOINT { ULONG Count; NTSTATUS ContinueStatus;} DBGKD_MANIPULATE_BREAKPOINT, *PDBGKD_MANIPULATE_BREAKPOINT;typedef struct _DBGKD_MANIPULATE_BREAKPOINT_DATA { ULONG Flags; ULONG Address; ULONG Handle;} DBGKD_MANIPULATE_BREAKPOINT_DATA, *PDBGKD_MANIPULATE_BREAKPOINT_DATA;typedef struct _DBGKD_MANIPULATE_STATE { ULONG ApiNumber; USHORT ProcessorType; USHORT Processor; NTSTATUS ReturnStatus; union { DBGKD_READ_MEMORY ReadMemory; DBGKD_WRITE_MEMORY WriteMemory; DBGKD_GET_CONTEXT GetContext; DBGKD_SET_CONTEXT SetContext; DBGKD_WRITE_BREAKPOINT WriteBreakPoint; DBGKD_RESTORE_BREAKPOINT RestoreBreakPoint; DBGKD_CONTINUE Continue; DBGKD_CONTINUE2 Continue2; DBGKD_READ_WRITE_IO ReadWriteIo; DBGKD_READ_WRITE_IO_EXTENDED ReadWriteIoExtended; DBGKD_QUERY_SPECIAL_CALLS QuerySpecialCalls; DBGKD_SET_SPECIAL_CALL SetSpecialCall; DBGKD_SET_INTERNAL_BREAKPOINT SetInternalBreakpoint; DBGKD_GET_INTERNAL_BREAKPOINT GetInternalBreakpoint; DBGKD_GET_VERSION GetVersion; DBGKD_BREAKPOINTEX BreakPointEx; DBGKD_PAGEIN PageIn; DBGKD_READ_WRITE_MSR ReadWriteMsr; DBGKD_MANIPULATE_BREAKPOINT ManipulateBreakPoint; } u;} DBGKD_MANIPULATE_STATE, *PDBGKD_MANIPULATE_STATE;//// If the packet type is PACKET_TYPE_KD_DEBUG_IO, then// the format of the packet data is as follows://#define DbgKdPrintStringApi 0x00003230L#define DbgKdGetStringApi 0x00003231L//// For print string, the Null terminated string to print// immediately follows the message//typedef struct _DBGKD_PRINT_STRING { ULONG LengthOfString;} DBGKD_PRINT_STRING, *PDBGKD_PRINT_STRING;//// For get string, the Null terminated promt string// immediately follows the message. The LengthOfStringRead// field initially contains the maximum number of characters// to read. Upon reply, this contains the number of bytes actually// read. The data read immediately follows the message.////typedef struct _DBGKD_GET_STRING { ULONG LengthOfPromptString; ULONG LengthOfStringRead;} DBGKD_GET_STRING, *PDBGKD_GET_STRING;typedef struct _DBGKD_DEBUG_IO { ULONG ApiNumber; USHORT ProcessorType; USHORT Processor; union { DBGKD_PRINT_STRING PrintString; DBGKD_GET_STRING GetString; } u;} DBGKD_DEBUG_IO, *PDBGKD_DEBUG_IO;//// Status Constants for reading data from comport//#define CP_GET_SUCCESS 0#define CP_GET_NODATA 1#define CP_GET_ERROR 2//// Data structure for passing information to KdpReportLoadSymbolsStateChange// function via the debug trap//typedef struct _KD_SYMBOLS_INFO {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -