1 #pragma once 2 #include "internal/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 BOOLEAN 86 NTAPI 87 KdbRegisterCliCallback( 88 PVOID Callback, 89 BOOLEAN Deregister); 90 91 VOID 92 KdbpCliInit(VOID); 93 94 VOID 95 KdbpCliMainLoop( 96 IN BOOLEAN EnteredOnSingleStep); 97 98 VOID 99 KdbpCliInterpretInitFile(VOID); 100 101 SIZE_T 102 KdbpReadCommand( 103 _Out_ PCHAR Buffer, 104 _In_ SIZE_T Size); 105 106 VOID 107 KdbpPager( 108 _In_ PCHAR Buffer, 109 _In_ ULONG BufLength); 110 111 VOID 112 KdbpPrint( 113 _In_ PSTR Format, 114 _In_ ...); 115 116 VOID 117 KdbpPrintUnicodeString( 118 _In_ PCUNICODE_STRING String); 119 120 BOOLEAN 121 NTAPI 122 KdbpGetHexNumber( 123 IN PCHAR pszNum, 124 OUT ULONG_PTR *pulValue); 125 126 /* from kdb_expr.c */ 127 128 BOOLEAN 129 KdbpRpnEvaluateExpression( 130 IN PCHAR Expression, 131 IN PKDB_KTRAP_FRAME TrapFrame, 132 OUT PULONGLONG Result, 133 OUT PLONG ErrOffset OPTIONAL, 134 OUT PCHAR ErrMsg OPTIONAL); 135 136 PVOID 137 KdbpRpnParseExpression( 138 IN PCHAR Expression, 139 OUT PLONG ErrOffset OPTIONAL, 140 OUT PCHAR ErrMsg OPTIONAL); 141 142 BOOLEAN 143 KdbpRpnEvaluateParsedExpression( 144 IN PVOID Expression, 145 IN PKDB_KTRAP_FRAME TrapFrame, 146 OUT PULONGLONG Result, 147 OUT PLONG ErrOffset OPTIONAL, 148 OUT PCHAR ErrMsg OPTIONAL); 149 150 /* from kdb_symbols.c */ 151 152 BOOLEAN 153 KdbpSymFindModule( 154 IN PVOID Address OPTIONAL, 155 IN INT Index OPTIONAL, 156 OUT PLDR_DATA_TABLE_ENTRY* pLdrEntry); 157 158 BOOLEAN 159 KdbSymPrintAddress( 160 IN PVOID Address, 161 IN PCONTEXT Context 162 ); 163 164 VOID 165 KdbSymProcessSymbols( 166 _Inout_ PLDR_DATA_TABLE_ENTRY LdrEntry, 167 _In_ BOOLEAN Load); 168 169 /* from kdb.c */ 170 171 extern PEPROCESS KdbCurrentProcess; 172 extern PETHREAD KdbCurrentThread; 173 extern LONG KdbLastBreakPointNr; 174 extern ULONG KdbNumSingleSteps; 175 extern BOOLEAN KdbSingleStepOver; 176 extern PKDB_KTRAP_FRAME KdbCurrentTrapFrame; 177 extern ULONG KdbDebugState; 178 179 LONG 180 KdbpGetNextBreakPointNr( 181 IN ULONG Start OPTIONAL); 182 183 BOOLEAN 184 KdbpGetBreakPointInfo( 185 IN ULONG BreakPointNr, 186 OUT ULONG_PTR *Address OPTIONAL, 187 OUT KDB_BREAKPOINT_TYPE *Type OPTIONAL, 188 OUT UCHAR *Size OPTIONAL, 189 OUT KDB_ACCESS_TYPE *AccessType OPTIONAL, 190 OUT UCHAR *DebugReg OPTIONAL, 191 OUT BOOLEAN *Enabled OPTIONAL, 192 OUT BOOLEAN *Global OPTIONAL, 193 OUT PEPROCESS *Process OPTIONAL, 194 OUT PCHAR *ConditionExpression OPTIONAL); 195 196 NTSTATUS 197 KdbpInsertBreakPoint( 198 IN ULONG_PTR Address, 199 IN KDB_BREAKPOINT_TYPE Type, 200 IN UCHAR Size OPTIONAL, 201 IN KDB_ACCESS_TYPE AccessType OPTIONAL, 202 IN PCHAR ConditionExpression OPTIONAL, 203 IN BOOLEAN Global, 204 OUT PLONG BreakPointNr OPTIONAL); 205 206 BOOLEAN 207 KdbpDeleteBreakPoint( 208 IN LONG BreakPointNr OPTIONAL, 209 IN OUT PKDB_BREAKPOINT BreakPoint OPTIONAL); 210 211 BOOLEAN 212 KdbpEnableBreakPoint( 213 IN LONG BreakPointNr OPTIONAL, 214 IN OUT PKDB_BREAKPOINT BreakPoint OPTIONAL); 215 216 BOOLEAN 217 KdbpDisableBreakPoint( 218 IN LONG BreakPointNr OPTIONAL, 219 IN OUT PKDB_BREAKPOINT BreakPoint OPTIONAL); 220 221 BOOLEAN 222 KdbpGetEnterCondition( 223 IN LONG ExceptionNr, 224 IN BOOLEAN FirstChance, 225 OUT KDB_ENTER_CONDITION *Condition); 226 227 BOOLEAN 228 KdbpSetEnterCondition( 229 IN LONG ExceptionNr, 230 IN BOOLEAN FirstChance, 231 IN KDB_ENTER_CONDITION Condition); 232 233 BOOLEAN 234 KdbpAttachToThread( 235 PVOID ThreadId); 236 237 BOOLEAN 238 KdbpAttachToProcess( 239 PVOID ProcessId); 240 241 VOID 242 NTAPI 243 KdbpGetCommandLineSettings(PCHAR p1); 244 245 KD_CONTINUE_TYPE 246 KdbEnterDebuggerException(IN PEXCEPTION_RECORD64 ExceptionRecord, 247 IN KPROCESSOR_MODE PreviousMode, 248 IN OUT PCONTEXT Context, 249 IN BOOLEAN FirstChance); 250 251 KD_CONTINUE_TYPE 252 KdbEnterDebuggerFirstChanceException( 253 IN OUT PKTRAP_FRAME TrapFrame); 254 255 /* other functions */ 256 257 NTSTATUS 258 KdbpSafeReadMemory(OUT PVOID Dest, 259 IN PVOID Src, 260 IN ULONG Bytes); 261 262 NTSTATUS 263 KdbpSafeWriteMemory(OUT PVOID Dest, 264 IN PVOID Src, 265 IN ULONG Bytes); 266 267 #define KdbpGetCharKeyboard(ScanCode) KdbpTryGetCharKeyboard(ScanCode, 0) 268 CHAR 269 KdbpTryGetCharKeyboard(PULONG ScanCode, ULONG Retry); 270 271 #define KdbpGetCharSerial() KdbpTryGetCharSerial(0) 272 CHAR 273 KdbpTryGetCharSerial(ULONG Retry); 274 275 VOID 276 KbdDisableMouse(VOID); 277 278 VOID 279 KbdEnableMouse(VOID); 280