1 #pragma once 2 #include "../kd/kd.h" 3 4 /* TYPES *********************************************************************/ 5 6 /* from kdb.c */ 7 typedef CONTEXT KDB_KTRAP_FRAME, *PKDB_KTRAP_FRAME; 8 9 typedef enum _KDB_BREAKPOINT_TYPE 10 { 11 KdbBreakPointNone = 0, 12 KdbBreakPointSoftware, 13 KdbBreakPointHardware, 14 KdbBreakPointTemporary 15 } KDB_BREAKPOINT_TYPE; 16 17 typedef enum _KDB_ACCESS_TYPE 18 { 19 KdbAccessRead, 20 KdbAccessWrite, 21 KdbAccessReadWrite, 22 KdbAccessExec 23 } KDB_ACCESS_TYPE; 24 25 typedef struct _KDB_BREAKPOINT 26 { 27 KDB_BREAKPOINT_TYPE Type; /* Type of breakpoint */ 28 BOOLEAN Enabled; /* Whether the bp is enabled */ 29 ULONG_PTR Address; /* Address of the breakpoint */ 30 BOOLEAN Global; /* Whether the breakpoint is global or local to a process */ 31 PEPROCESS Process; /* Owning process */ 32 PCHAR ConditionExpression; 33 PVOID Condition; 34 union { 35 /* KdbBreakPointSoftware */ 36 UCHAR SavedInstruction; 37 /* KdbBreakPointHardware */ 38 struct { 39 UCHAR DebugReg : 2; 40 UCHAR Size : 3; 41 KDB_ACCESS_TYPE AccessType; 42 } Hw; 43 } Data; 44 } KDB_BREAKPOINT, *PKDB_BREAKPOINT; 45 46 typedef enum _KDB_ENTER_CONDITION 47 { 48 KdbDoNotEnter, 49 KdbEnterAlways, 50 KdbEnterFromKmode, 51 KdbEnterFromUmode 52 } KDB_ENTER_CONDITION; 53 54 /* These values MUST be nonzero. They're used as bit masks. */ 55 typedef enum _KDB_OUTPUT_SETTINGS 56 { 57 KD_DEBUG_KDSERIAL = 1, 58 KD_DEBUG_KDNOECHO = 2 59 } KDB_OUTPUT_SETTINGS; 60 61 /* FUNCTIONS *****************************************************************/ 62 63 /* from i386/i386-dis.c */ 64 65 LONG 66 KdbpDisassemble( 67 IN ULONG_PTR Address, 68 IN ULONG IntelSyntax); 69 70 LONG 71 KdbpGetInstLength( 72 IN ULONG_PTR Address); 73 74 /* from i386/kdb_help.S */ 75 76 VOID NTAPI 77 KdbpStackSwitchAndCall( 78 IN PVOID NewStack, 79 IN VOID (*Function)(VOID)); 80 81 /* from kdb_cli.c */ 82 83 extern PCHAR KdbInitFileBuffer; 84 85 NTSTATUS 86 NTAPI 87 KdbInitialize( 88 _In_ PKD_DISPATCH_TABLE DispatchTable, 89 _In_ ULONG BootPhase); 90 91 BOOLEAN 92 NTAPI 93 KdbRegisterCliCallback( 94 PVOID Callback, 95 BOOLEAN Deregister); 96 97 NTSTATUS 98 KdbpCliInit(VOID); 99 100 VOID 101 KdbpCliMainLoop( 102 IN BOOLEAN EnteredOnSingleStep); 103 104 VOID 105 KdbpCliInterpretInitFile(VOID); 106 107 VOID 108 KdbpCommandHistoryAppend( 109 _In_ PCSTR Command); 110 111 PCSTR 112 KdbGetHistoryEntry( 113 _Inout_ PLONG NextIndex, 114 _In_ BOOLEAN Next); 115 116 VOID 117 KdbpPager( 118 _In_ PCHAR Buffer, 119 _In_ ULONG BufLength); 120 121 VOID 122 KdbpPrint( 123 _In_ PSTR Format, 124 _In_ ...); 125 126 VOID 127 KdbpPrintUnicodeString( 128 _In_ PCUNICODE_STRING String); 129 130 BOOLEAN 131 NTAPI 132 KdbpGetHexNumber( 133 IN PCHAR pszNum, 134 OUT ULONG_PTR *pulValue); 135 136 /* from kdb_expr.c */ 137 138 BOOLEAN 139 KdbpRpnEvaluateExpression( 140 IN PCHAR Expression, 141 IN PKDB_KTRAP_FRAME TrapFrame, 142 OUT PULONGLONG Result, 143 OUT PLONG ErrOffset OPTIONAL, 144 OUT PCHAR ErrMsg OPTIONAL); 145 146 PVOID 147 KdbpRpnParseExpression( 148 IN PCHAR Expression, 149 OUT PLONG ErrOffset OPTIONAL, 150 OUT PCHAR ErrMsg OPTIONAL); 151 152 BOOLEAN 153 KdbpRpnEvaluateParsedExpression( 154 IN PVOID Expression, 155 IN PKDB_KTRAP_FRAME TrapFrame, 156 OUT PULONGLONG Result, 157 OUT PLONG ErrOffset OPTIONAL, 158 OUT PCHAR ErrMsg OPTIONAL); 159 160 /* from kdb_symbols.c */ 161 162 BOOLEAN 163 KdbpSymFindModule( 164 IN PVOID Address OPTIONAL, 165 IN INT Index OPTIONAL, 166 OUT PLDR_DATA_TABLE_ENTRY* pLdrEntry); 167 168 BOOLEAN 169 KdbSymPrintAddress( 170 IN PVOID Address, 171 IN PCONTEXT Context); 172 173 VOID 174 KdbSymProcessSymbols( 175 _Inout_ PLDR_DATA_TABLE_ENTRY LdrEntry, 176 _In_ BOOLEAN Load); 177 178 BOOLEAN 179 KdbSymInit( 180 _In_ ULONG BootPhase); 181 182 /* from kdb.c */ 183 184 extern PEPROCESS KdbCurrentProcess; 185 extern PETHREAD KdbCurrentThread; 186 extern LONG KdbLastBreakPointNr; 187 extern ULONG KdbNumSingleSteps; 188 extern BOOLEAN KdbSingleStepOver; 189 extern PKDB_KTRAP_FRAME KdbCurrentTrapFrame; 190 extern ULONG KdbDebugState; 191 192 LONG 193 KdbpGetNextBreakPointNr( 194 IN ULONG Start OPTIONAL); 195 196 BOOLEAN 197 KdbpGetBreakPointInfo( 198 IN ULONG BreakPointNr, 199 OUT ULONG_PTR *Address OPTIONAL, 200 OUT KDB_BREAKPOINT_TYPE *Type OPTIONAL, 201 OUT UCHAR *Size OPTIONAL, 202 OUT KDB_ACCESS_TYPE *AccessType OPTIONAL, 203 OUT UCHAR *DebugReg OPTIONAL, 204 OUT BOOLEAN *Enabled OPTIONAL, 205 OUT BOOLEAN *Global OPTIONAL, 206 OUT PEPROCESS *Process OPTIONAL, 207 OUT PCHAR *ConditionExpression OPTIONAL); 208 209 NTSTATUS 210 KdbpInsertBreakPoint( 211 IN ULONG_PTR Address, 212 IN KDB_BREAKPOINT_TYPE Type, 213 IN UCHAR Size OPTIONAL, 214 IN KDB_ACCESS_TYPE AccessType OPTIONAL, 215 IN PCHAR ConditionExpression OPTIONAL, 216 IN BOOLEAN Global, 217 OUT PLONG BreakPointNr OPTIONAL); 218 219 BOOLEAN 220 KdbpDeleteBreakPoint( 221 IN LONG BreakPointNr OPTIONAL, 222 IN OUT PKDB_BREAKPOINT BreakPoint OPTIONAL); 223 224 BOOLEAN 225 KdbpEnableBreakPoint( 226 IN LONG BreakPointNr OPTIONAL, 227 IN OUT PKDB_BREAKPOINT BreakPoint OPTIONAL); 228 229 BOOLEAN 230 KdbpDisableBreakPoint( 231 IN LONG BreakPointNr OPTIONAL, 232 IN OUT PKDB_BREAKPOINT BreakPoint OPTIONAL); 233 234 BOOLEAN 235 KdbpGetEnterCondition( 236 IN LONG ExceptionNr, 237 IN BOOLEAN FirstChance, 238 OUT KDB_ENTER_CONDITION *Condition); 239 240 BOOLEAN 241 KdbpSetEnterCondition( 242 IN LONG ExceptionNr, 243 IN BOOLEAN FirstChance, 244 IN KDB_ENTER_CONDITION Condition); 245 246 BOOLEAN 247 KdbpAttachToThread( 248 PVOID ThreadId); 249 250 BOOLEAN 251 KdbpAttachToProcess( 252 PVOID ProcessId); 253 254 VOID 255 NTAPI 256 KdbpGetCommandLineSettings(PCHAR p1); 257 258 KD_CONTINUE_TYPE 259 KdbEnterDebuggerException(IN PEXCEPTION_RECORD64 ExceptionRecord, 260 IN KPROCESSOR_MODE PreviousMode, 261 IN OUT PCONTEXT Context, 262 IN BOOLEAN FirstChance); 263 264 /* other functions */ 265 266 BOOLEAN 267 NTAPI 268 KdpSafeReadMemory( 269 IN ULONG_PTR Addr, 270 IN LONG Len, 271 OUT PVOID Value 272 ); 273 274 BOOLEAN 275 NTAPI 276 KdpSafeWriteMemory( 277 IN ULONG_PTR Addr, 278 IN LONG Len, 279 IN ULONGLONG Value 280 ); 281 282 NTSTATUS 283 KdbpSafeReadMemory(OUT PVOID Dest, 284 IN PVOID Src, 285 IN ULONG Bytes); 286 287 NTSTATUS 288 KdbpSafeWriteMemory(OUT PVOID Dest, 289 IN PVOID Src, 290 IN ULONG Bytes); 291 292 #define KdbpGetCharKeyboard(ScanCode) KdbpTryGetCharKeyboard((ScanCode), 0) 293 CHAR 294 KdbpTryGetCharKeyboard(PULONG ScanCode, ULONG Retry); 295 296 #define KdbpGetCharSerial() KdbpTryGetCharSerial(0) 297 CHAR 298 KdbpTryGetCharSerial( 299 _In_ ULONG Retry); 300 301 VOID 302 KdbpSendCommandSerial( 303 _In_ PCSTR Command); 304 305 VOID 306 KbdDisableMouse(VOID); 307 308 VOID 309 KbdEnableMouse(VOID); 310