00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
#include "kdp.h"
00025
00026
00027 BOOLEAN
00028 KdpTrap (
00029 IN PKTRAP_FRAME TrapFrame,
00030 IN PKEXCEPTION_FRAME ExceptionFrame,
00031 IN PEXCEPTION_RECORD ExceptionRecord,
00032 IN PCONTEXT ContextRecord,
00033 IN KPROCESSOR_MODE PreviousMode,
00034 IN BOOLEAN SecondChance
00035 )
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069 {
00070
00071 BOOLEAN Completion;
00072 BOOLEAN Enable;
00073 BOOLEAN UnloadSymbols =
FALSE;
00074 STRING Input;
00075 ULONGLONG OldFir;
00076 STRING Output;
00077 PKPRCB Prcb;
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
if ((ExceptionRecord->ExceptionCode == STATUS_BREAKPOINT) &&
00089 (ExceptionRecord->ExceptionInformation[0] >= DEBUG_PRINT_BREAKPOINT)){
00090
00091
00092
00093
00094
00095
switch (ExceptionRecord->ExceptionInformation[0]) {
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
case DEBUG_PRINT_BREAKPOINT:
00107 ContextRecord->Fir += 4;
00108 Output.Buffer = (PCHAR)ContextRecord->IntA0;
00109 Output.Length = (
USHORT)ContextRecord->IntA1;
00110
00111
KdLogDbgPrint(&Output);
00112
00113
if (
KdDebuggerNotPresent ==
FALSE) {
00114
00115 Enable =
KdEnterDebugger(TrapFrame, ExceptionFrame);
00116
if (
KdpPrintString(&Output)) {
00117 ContextRecord->IntV0 = (ULONG)STATUS_BREAKPOINT;
00118 }
else {
00119 ContextRecord->IntV0 = (ULONG)STATUS_SUCCESS;
00120 }
00121
KdExitDebugger(Enable);
00122
00123 }
else {
00124 ContextRecord->IntV0 = (ULONG)STATUS_DEVICE_NOT_CONNECTED;
00125 }
00126
00127
return TRUE;
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
case BREAKIN_BREAKPOINT:
00138 ContextRecord->Fir += 4;
00139
break;
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
case DEBUG_PROMPT_BREAKPOINT:
00151 ContextRecord->Fir += 4;
00152 Output.Buffer = (PCHAR)ContextRecord->IntA0;
00153 Output.Length = (
USHORT)ContextRecord->IntA1;
00154 Input.Buffer = (PCHAR)ContextRecord->IntA2;
00155 Input.MaximumLength = (
USHORT)ContextRecord->IntA3;
00156
00157
KdLogDbgPrint(&Output);
00158
00159 Enable =
KdEnterDebugger(TrapFrame, ExceptionFrame);
00160
00161
KdpPromptString(&Output, &Input);
00162
00163 ContextRecord->IntV0 = Input.Length;
00164
00165
KdExitDebugger(Enable);
00166
return TRUE;
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
case DEBUG_UNLOAD_SYMBOLS_BREAKPOINT:
00179 UnloadSymbols =
TRUE;
00180
00181
00182
00183
00184
00185
case DEBUG_LOAD_SYMBOLS_BREAKPOINT:
00186 Enable =
KdEnterDebugger(TrapFrame, ExceptionFrame);
00187 Prcb =
KeGetCurrentPrcb();
00188 OldFir = ContextRecord->Fir;
00189 RtlCopyMemory(&Prcb->ProcessorState.ContextFrame,
00190 ContextRecord,
00191
sizeof(CONTEXT));
00192
00193
if (
KdDebuggerNotPresent ==
FALSE) {
00194
KdpReportLoadSymbolsStateChange((PSTRING)ContextRecord->IntA0,
00195 (
PKD_SYMBOLS_INFO) ContextRecord->IntA1,
00196 UnloadSymbols,
00197 &Prcb->ProcessorState.ContextFrame);
00198
00199 }
00200
00201 RtlCopyMemory(ContextRecord,
00202 &Prcb->ProcessorState.ContextFrame,
00203
sizeof(CONTEXT));
00204
00205
KdExitDebugger(Enable);
00206
00207
00208
00209
00210
00211
00212
if (ContextRecord->Fir == OldFir) {
00213 ContextRecord->Fir += 4;
00214 }
00215
00216
return TRUE;
00217
00218
00219
00220
00221
00222
default:
00223
break;
00224 }
00225 }
00226
00227
00228
00229
00230
00231 Enable =
KdEnterDebugger(TrapFrame, ExceptionFrame);
00232 Prcb =
KeGetCurrentPrcb();
00233
00234 RtlCopyMemory(&Prcb->ProcessorState.ContextFrame,
00235 ContextRecord,
00236 sizeof (CONTEXT));
00237
00238 Completion =
KdpReportExceptionStateChange(ExceptionRecord,
00239 &Prcb->ProcessorState.ContextFrame,
00240 SecondChance);
00241
00242 RtlCopyMemory(ContextRecord,
00243 &Prcb->ProcessorState.ContextFrame,
00244
sizeof(CONTEXT));
00245
00246
KdExitDebugger(Enable);
00247
00248
KdpControlCPressed =
FALSE;
00249
00250
00251
00252
00253
00254
00255
00256
if( SecondChance ){
00257
return Completion;
00258 }
else {
00259
return TRUE;
00260 }
00261 }
00262
00263 BOOLEAN
00264 KdIsThisAKdTrap (
00265 IN PEXCEPTION_RECORD ExceptionRecord,
00266 IN PCONTEXT ContextRecord,
00267 IN KPROCESSOR_MODE PreviousMode
00268 )
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293 {
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
switch (ExceptionRecord->ExceptionInformation[0]) {
00306
00307
00308
00309
00310
00311
case KERNEL_BREAKPOINT:
00312
case BREAKIN_BREAKPOINT:
00313
#if DEVL
00314
return TRUE;
00315
#else
00316
if (PreviousMode ==
KernelMode) {
00317
return TRUE;
00318
00319 }
else {
00320
return FALSE;
00321 }
00322
#endif
00323
00324
00325
00326
00327
00328
case DEBUG_PRINT_BREAKPOINT:
00329
return TRUE;
00330
00331
00332
00333
00334
case DEBUG_PROMPT_BREAKPOINT:
00335
return TRUE;
00336
00337
00338
00339
00340
00341
case DEBUG_STOP_BREAKPOINT:
00342
#if DEVL
00343
return TRUE;
00344
#else
00345
if (PreviousMode ==
KernelMode) {
00346
return TRUE;
00347
00348 }
else {
00349
return FALSE;
00350 }
00351
#endif
00352
00353
00354
00355
00356
00357
case DEBUG_LOAD_SYMBOLS_BREAKPOINT:
00358
if (PreviousMode ==
KernelMode) {
00359
return TRUE;
00360
00361 }
else {
00362
return FALSE;
00363 }
00364
00365
00366
00367
00368
00369
case DEBUG_UNLOAD_SYMBOLS_BREAKPOINT:
00370
if (PreviousMode ==
KernelMode) {
00371
return TRUE;
00372
00373 }
else {
00374
return FALSE;
00375 }
00376
00377
00378
00379
00380
default:
00381
return FALSE;
00382 }
00383 }
00384
00385 BOOLEAN
00386 KdpStub (
00387 IN PKTRAP_FRAME TrapFrame,
00388 IN PKEXCEPTION_FRAME ExceptionFrame,
00389 IN PEXCEPTION_RECORD ExceptionRecord,
00390 IN PCONTEXT ContextRecord,
00391 IN KPROCESSOR_MODE PreviousMode,
00392 IN BOOLEAN SecondChance
00393 )
00394
00395
00396
00397
00398
00399
00400
00401
00402
00403
00404
00405
00406
00407
00408
00409
00410
00411
00412
00413
00414
00415
00416
00417
00418
00419
00420
00421
00422
00423
00424
00425
00426
00427 {
00428
00429 ULONG_PTR BreakpointCode;
00430
00431
00432
00433
00434
00435
00436
00437 BreakpointCode = ExceptionRecord->ExceptionInformation[0];
00438
00439
00440
00441
00442
00443
00444
if ((BreakpointCode == DEBUG_PRINT_BREAKPOINT) ||
00445 (BreakpointCode == DEBUG_LOAD_SYMBOLS_BREAKPOINT) ||
00446 (BreakpointCode == DEBUG_UNLOAD_SYMBOLS_BREAKPOINT) ||
00447 (BreakpointCode ==
KERNEL_BREAKPOINT)) {
00448 ContextRecord->Fir += 4;
00449
return TRUE;
00450 }
else {
00451
if ( (BreakpointCode == DEBUG_STOP_BREAKPOINT) &&
00452 (PreviousMode ==
KernelMode) ){
00453 ContextRecord->Fir += 4;
00454
return TRUE;
00455 }
else {
00456
return FALSE;
00457 }
00458 }
00459 }