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