00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
#include "ntos.h"
00023
#include "ki.h"
00024 #define NOEXTAPI
00025
#include "wdbgexts.h"
00026
#include "ntdbg.h"
00027
#include "string.h"
00028
#include "stdlib.h"
00029
00030
00031
#if defined(_ALPHA_)
00032
00033
#include "alphaops.h"
00034
00035
00036
00037
00038
00039
00040
00041
00042 PKPCR
KdpGetPcr();
00043
00044 ULONG
KdpReadInternalProcessorState(PVOID, ULONG);
00045 ULONG
KdpReadInternalProcessorCounters(PVOID, ULONG);
00046
00047
struct _KPRCB *
00048
KdpGetCurrentPrcb();
00049
00050
struct _KTHREAD *
00051
KdpGetCurrentThread();
00052
00053
00054
00055
00056
#undef KiPcr
00057
#define KiPcr KdpGetPcr()
00058
00059
#undef KeGetPcr
00060
#undef KeGetCurrentPrcb
00061
#undef KeGetCurrentThread
00062
#undef KeIsExecutingDpc
00063
#define KeGetPcr() KdpGetPcr()
00064
#define KeGetCurrentPrcb() KdpGetCurrentPrcb()
00065
#define KeGetCurrentThread() KdpGetCurrentThread()
00066
00067
00068
00069
00070
00071
#define KDP_BREAKPOINT_TYPE ULONG
00072
00073
00074
#define KDP_BREAKPOINT_ALIGN 3
00075
00076
00077
#define KDP_BREAKPOINT_VALUE KBPT_FUNC
00078
00079
00080
#elif defined(_IA64_)
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
#define KDP_BREAKPOINT_TYPE ULONGLONG // 64-bit ULONGLONG type is needed to cover 41-bit EM break instruction.
00123
#define KDP_BREAKPOINT_ALIGN 0x3 // An EM address consists of bundle and slot number and is 32-bit aligned.
00124
#define KDP_BREAKPOINT_VALUE (BREAK_INSTR | (DEBUG_STOP_BREAKPOINT << 6))
00125
00126
#elif defined(_X86_)
00127
00128
#define KDP_BREAKPOINT_TYPE UCHAR
00129
#define KDP_BREAKPOINT_ALIGN 0
00130
#define KDP_BREAKPOINT_VALUE 0xcc
00131
00132
#endif
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145 #define GLOBAL_BREAKPOINT_LIMIT 1610612736L // 1.5gigabytes
00146
00147
00148
00149
00150
00151 #define KD_BREAKPOINT_IN_USE 0x00000001
00152 #define KD_BREAKPOINT_NEEDS_WRITE 0x00000002
00153 #define KD_BREAKPOINT_SUSPENDED 0x00000004
00154 #define KD_BREAKPOINT_NEEDS_REPLACE 0x00000008
00155
00156 #define KD_BREAKPOINT_STATE_MASK 0x0000000f
00157 #define KD_BREAKPOINT_IA64_MASK 0x000f0000
00158 #define KD_BREAKPOINT_IA64_MODE 0x00010000 // IA64 mode
00159 #define KD_BREAKPOINT_IA64_MOVL 0x00020000 // MOVL instruction displaced
00160
00161
00162
00163
00164
00165 #define KDP_PACKET_RECEIVED 0
00166 #define KDP_PACKET_TIMEOUT 1
00167 #define KDP_PACKET_RESEND 2
00168
00169
00170
typedef struct _BREAKPOINT_ENTRY {
00171 ULONG
Flags;
00172 ULONG_PTR
DirectoryTableBase;
00173 PVOID
Address;
00174 KDP_BREAKPOINT_TYPE Content;
00175 }
BREAKPOINT_ENTRY, *
PBREAKPOINT_ENTRY;
00176
00177
00178
00179
00180
00181
00182 #define MAXIMUM_RETRIES 20
00183
00184 #define DBGKD_MAX_SPECIAL_CALLS 10
00185
00186
typedef struct _TRACE_DATA_SYM {
00187 ULONG
SymMin;
00188 ULONG
SymMax;
00189 }
TRACE_DATA_SYM, *
PTRACE_DATA_SYM;
00190
00191
00192
00193
00194
00195
VOID
00196
KdpReboot (
00197 VOID
00198 );
00199
00200 BOOLEAN
00201
KdpPrintString (
00202 IN PSTRING Output
00203 );
00204
00205 BOOLEAN
00206
KdpPromptString (
00207 IN PSTRING Output,
00208 IN OUT PSTRING Input
00209 );
00210
00211 ULONG
00212
KdpAddBreakpoint (
00213 IN PVOID Address
00214 );
00215
00216 BOOLEAN
00217
KdpDeleteBreakpoint (
00218 IN ULONG Handle
00219 );
00220
00221 BOOLEAN
00222
KdpDeleteBreakpointRange (
00223 IN PVOID Lower,
00224 IN PVOID Upper
00225 );
00226
00227
#if defined(_IA64_)
00228
00229 BOOLEAN
00230 KdpSuspendBreakpointRange (
00231 IN PVOID Lower,
00232 IN PVOID Upper
00233 );
00234
00235 BOOLEAN
00236 KdpRestoreBreakpointRange (
00237 IN PVOID Lower,
00238 IN PVOID Upper
00239 );
00240
#endif
00241
00242
#if i386
00243
00244
NTSTATUS
00245 KdGetTraceInformation (
00246 OUT PVOID TraceInformation,
00247 IN ULONG TraceInformationLength,
00248 OUT PULONG RequiredLength
00249 );
00250
00251
VOID
00252 KdSetInternalBreakpoint (
00253 IN PDBGKD_MANIPULATE_STATE64 m
00254 );
00255
00256
#endif
00257
00258
NTSTATUS
00259
KdQuerySpecialCalls (
00260 IN PDBGKD_MANIPULATE_STATE64 m,
00261 IN ULONG Length,
00262 OUT PULONG RequiredLength
00263 );
00264
00265
VOID
00266
KdSetSpecialCall (
00267 IN PDBGKD_MANIPULATE_STATE64 m,
00268 IN PCONTEXT ContextRecord
00269 );
00270
00271
VOID
00272
KdClearSpecialCalls (
00273 VOID
00274 );
00275
00276 ULONG
00277
KdpMoveMemory (
00278 IN PCHAR Destination,
00279 IN PCHAR Source,
00280 IN ULONG Length
00281 );
00282
00283
VOID
00284
KdpQuickMoveMemory (
00285 IN PCHAR Destination,
00286 IN PCHAR Source,
00287 IN ULONG Length
00288 );
00289
00290 ULONG
00291
KdpReceivePacket (
00292 IN ULONG ExpectedPacketType,
00293 OUT PSTRING MessageHeader,
00294 OUT PSTRING MessageData,
00295 OUT PULONG DataLength
00296 );
00297
00298
VOID
00299
KdpSetLoadState(
00300 IN PDBGKD_WAIT_STATE_CHANGE64 WaitStateChange,
00301 IN PCONTEXT ContextRecord
00302 );
00303
00304
VOID
00305
KdpSetStateChange(
00306 IN PDBGKD_WAIT_STATE_CHANGE64 WaitStateChange,
00307 IN PEXCEPTION_RECORD ExceptionRecord,
00308 IN PCONTEXT ContextRecord,
00309 IN BOOLEAN SecondChance
00310 );
00311
00312
VOID
00313
KdpGetStateChange(
00314 IN PDBGKD_MANIPULATE_STATE64 ManipulateState,
00315 IN PCONTEXT ContextRecord
00316 );
00317
00318
VOID
00319
KdpSendPacket (
00320 IN ULONG PacketType,
00321 IN PSTRING MessageHeader,
00322 IN PSTRING MessageData OPTIONAL
00323 );
00324
00325 BOOLEAN
00326
KdpStub (
00327 IN PKTRAP_FRAME TrapFrame,
00328 IN PKEXCEPTION_FRAME ExceptionFrame,
00329 IN PEXCEPTION_RECORD ExceptionRecord,
00330 IN PCONTEXT ContextRecord,
00331 IN KPROCESSOR_MODE PreviousMode,
00332 IN BOOLEAN SecondChance
00333 );
00334
00335 BOOLEAN
00336
KdpTrap (
00337 IN PKTRAP_FRAME TrapFrame,
00338 IN PKEXCEPTION_FRAME ExceptionFrame,
00339 IN PEXCEPTION_RECORD ExceptionRecord64,
00340 IN PCONTEXT ContextRecord,
00341 IN KPROCESSOR_MODE PreviousMode,
00342 IN BOOLEAN SecondChance
00343 );
00344
00345 BOOLEAN
00346
KdpSwitchProcessor (
00347 IN PEXCEPTION_RECORD ExceptionRecord,
00348 IN OUT PCONTEXT ContextRecord,
00349 IN BOOLEAN SecondChance
00350 );
00351
00352 BOOLEAN
00353
KdpReportExceptionStateChange (
00354 IN PEXCEPTION_RECORD ExceptionRecord,
00355 IN OUT PCONTEXT ContextRecord,
00356 IN BOOLEAN SecondChance
00357 );
00358
00359 BOOLEAN
00360
KdpReportLoadSymbolsStateChange (
00361 IN PSTRING PathName,
00362 IN
PKD_SYMBOLS_INFO SymbolInfo,
00363 IN BOOLEAN UnloadSymbols,
00364 IN OUT PCONTEXT ContextRecord
00365 );
00366
00367
KCONTINUE_STATUS
00368
KdpSendWaitContinue(
00369 IN ULONG PacketType,
00370 IN PSTRING MessageHeader,
00371 IN PSTRING MessageData OPTIONAL,
00372 IN OUT PCONTEXT ContextRecord
00373 );
00374
00375
VOID
00376
KdpReadVirtualMemory(
00377 IN PDBGKD_MANIPULATE_STATE64 m,
00378 IN PSTRING AdditionalData,
00379 IN PCONTEXT Context
00380 );
00381
00382
#if 0
00383
VOID
00384
KdpReadVirtualMemory64(
00385 IN PDBGKD_MANIPULATE_STATE64 m,
00386 IN PSTRING AdditionalData,
00387 IN PCONTEXT Context
00388 );
00389
#endif
00390
00391
VOID
00392
KdpWriteVirtualMemory(
00393 IN PDBGKD_MANIPULATE_STATE64 m,
00394 IN PSTRING AdditionalData,
00395 IN PCONTEXT Context
00396 );
00397
00398
#if 0
00399
VOID
00400
KdpWriteVirtualMemory64(
00401 IN PDBGKD_MANIPULATE_STATE64 m,
00402 IN PSTRING AdditionalData,
00403 IN PCONTEXT Context
00404 );
00405
#endif
00406
00407
VOID
00408
KdpReadPhysicalMemory(
00409 IN PDBGKD_MANIPULATE_STATE64 m,
00410 IN PSTRING AdditionalData,
00411 IN PCONTEXT Context
00412 );
00413
00414
VOID
00415
KdpWritePhysicalMemory(
00416 IN PDBGKD_MANIPULATE_STATE64 m,
00417 IN PSTRING AdditionalData,
00418 IN PCONTEXT Context
00419 );
00420
00421
VOID
00422
KdpCheckLowMemory(
00423 IN PDBGKD_MANIPULATE_STATE64 m
00424 );
00425
00426
VOID
00427
KdpGetContext(
00428 IN PDBGKD_MANIPULATE_STATE64 m,
00429 IN PSTRING AdditionalData,
00430 IN PCONTEXT Context
00431 );
00432
00433
VOID
00434
KdpSetContext(
00435 IN PDBGKD_MANIPULATE_STATE64 m,
00436 IN PSTRING AdditionalData,
00437 IN PCONTEXT Context
00438 );
00439
00440
VOID
00441
KdpWriteBreakpoint(
00442 IN PDBGKD_MANIPULATE_STATE64 m,
00443 IN PSTRING AdditionalData,
00444 IN PCONTEXT Context
00445 );
00446
00447
VOID
00448
KdpRestoreBreakpoint(
00449 IN PDBGKD_MANIPULATE_STATE64 m,
00450 IN PSTRING AdditionalData,
00451 IN PCONTEXT Context
00452 );
00453
00454
VOID
00455
KdpReadControlSpace(
00456 IN PDBGKD_MANIPULATE_STATE64 m,
00457 IN PSTRING AdditionalData,
00458 IN PCONTEXT Context
00459 );
00460
00461
VOID
00462
KdpWriteControlSpace(
00463 IN PDBGKD_MANIPULATE_STATE64 m,
00464 IN PSTRING AdditionalData,
00465 IN PCONTEXT Context
00466 );
00467
00468
VOID
00469
KdpReadIoSpace(
00470 IN PDBGKD_MANIPULATE_STATE64 m,
00471 IN PSTRING AdditionalData,
00472 IN PCONTEXT Context
00473 );
00474
00475
VOID
00476
KdpReadMachineSpecificRegister(
00477 IN PDBGKD_MANIPULATE_STATE64 m,
00478 IN PSTRING AdditionalData,
00479 IN PCONTEXT Context
00480 );
00481
00482
VOID
00483
KdpWriteIoSpace(
00484 IN PDBGKD_MANIPULATE_STATE64 m,
00485 IN PSTRING AdditionalData,
00486 IN PCONTEXT Context
00487 );
00488
00489
VOID
00490
KdpWriteMachineSpecificRegister(
00491 IN PDBGKD_MANIPULATE_STATE64 m,
00492 IN PSTRING AdditionalData,
00493 IN PCONTEXT Context
00494 );
00495
00496
#ifdef _ALPHA_
00497
00498
VOID
00499
KdpReadIoSpaceExtended (
00500 IN PDBGKD_MANIPULATE_STATE64 m,
00501 IN PSTRING AdditionalData,
00502 IN PCONTEXT Context
00503 );
00504
00505
VOID
00506
KdpWriteIoSpaceExtended (
00507 IN PDBGKD_MANIPULATE_STATE64 m,
00508 IN PSTRING AdditionalData,
00509 IN PCONTEXT Context
00510 );
00511
00512
VOID
00513
KdpGetBusData (
00514 IN PDBGKD_MANIPULATE_STATE64 m,
00515 IN PSTRING AdditionalData,
00516 IN PCONTEXT Context
00517 );
00518
00519
VOID
00520
KdpSetBusData (
00521 IN PDBGKD_MANIPULATE_STATE64 m,
00522 IN PSTRING AdditionalData,
00523 IN PCONTEXT Context
00524 );
00525
00526
#endif
00527
00528
00529
VOID
00530
KdpSuspendBreakpoint (
00531 ULONG Handle
00532 );
00533
00534
VOID
00535
KdpSuspendAllBreakpoints (
00536 VOID
00537 );
00538
00539
VOID
00540
KdpRestoreAllBreakpoints (
00541 VOID
00542 );
00543
00544
VOID
00545
KdpTimeSlipDpcRoutine (
00546
PKDPC Dpc,
00547 PVOID DeferredContext,
00548 PVOID SystemArgument1,
00549 PVOID SystemArgument2
00550 );
00551
00552
VOID
00553
KdpTimeSlipWork (
00554 IN PVOID Context
00555 );
00556
00557
00558
00559
00560
00561
00562
00563
00564
VOID
00565
RtlpBreakWithStatusInstruction (
00566 VOID
00567 );
00568
00569
00570
00571
00572
00573 #define KDP_MESSAGE_BUFFER_SIZE 4096
00574
00575 extern BREAKPOINT_ENTRY KdpBreakpointTable[BREAKPOINT_TABLE_SIZE];
00576 extern BOOLEAN
KdpControlCPending;
00577 extern KSPIN_LOCK
KdpDebuggerLock;
00578 extern PKDEBUG_ROUTINE KiDebugRoutine;
00579 extern PKDEBUG_SWITCH_ROUTINE KiDebugSwitchRoutine;
00580 extern KDP_BREAKPOINT_TYPE KdpBreakpointInstruction;
00581 extern UCHAR
KdpMessageBuffer[
KDP_MESSAGE_BUFFER_SIZE];
00582 extern UCHAR
KdpPathBuffer[
KDP_MESSAGE_BUFFER_SIZE];
00583 extern ULONG
KdpOweBreakpoint;
00584 extern ULONG
KdpNextPacketIdToSend;
00585 extern ULONG
KdpPacketIdExpected;
00586
00587 extern LARGE_INTEGER
KdPerformanceCounterRate;
00588 extern LARGE_INTEGER
KdTimerStart;
00589 extern LARGE_INTEGER
KdTimerStop;
00590 extern LARGE_INTEGER
KdTimerDifference;
00591
00592 extern BOOLEAN
BreakpointsSuspended;
00593 extern PVOID
KdpNtosImageBase;
00594 extern LIST_ENTRY
KdpDebuggerDataListHead;
00595
00596
typedef struct {
00597 ULONG64 Addr;
00598 ULONG Flags;
00599 ULONG Calls;
00600 ULONG CallsLastCheck;
00601 ULONG MaxCallsPerPeriod;
00602 ULONG MinInstructions;
00603 ULONG MaxInstructions;
00604 ULONG TotalInstructions;
00605 ULONG
Handle;
00606 PVOID Thread;
00607 ULONG64 ReturnAddress;
00608 }
DBGKD_INTERNAL_BREAKPOINT, *
PDBGKD_INTERNAL_BREAKPOINT;
00609
00610
00611 #define DBGKD_MAX_INTERNAL_BREAKPOINTS 20
00612 extern DBGKD_INTERNAL_BREAKPOINT KdpInternalBPs[
DBGKD_MAX_INTERNAL_BREAKPOINTS];
00613
00614 extern ULONG_PTR
KdpCurrentSymbolStart;
00615 extern ULONG_PTR
KdpCurrentSymbolEnd;
00616 extern LONG
KdpNextCallLevelChange;
00617 extern ULONG_PTR
KdSpecialCalls[];
00618 extern ULONG
KdNumberOfSpecialCalls;
00619 extern ULONG_PTR
InitialSP;
00620 extern ULONG
KdpNumInternalBreakpoints;
00621 extern KTIMER InternalBreakpointTimer;
00622 extern KDPC InternalBreakpointCheckDpc;
00623 extern BOOLEAN
KdpPortLocked;
00624 extern LARGE_INTEGER
KdpTimeEntered;
00625
00626 extern DBGKD_TRACE_DATA
TraceDataBuffer[];
00627 extern ULONG
TraceDataBufferPosition;
00628 extern TRACE_DATA_SYM TraceDataSyms[];
00629 extern UCHAR
NextTraceDataSym;
00630 extern UCHAR
NumTraceDataSyms;
00631 extern ULONG
IntBPsSkipping;
00632 extern BOOLEAN
WatchStepOver;
00633 extern PVOID
WSOThread;
00634 extern ULONG_PTR
WSOEsp;
00635 extern ULONG
WatchStepOverHandle;
00636 extern ULONG_PTR
WatchStepOverBreakAddr;
00637 extern BOOLEAN
WatchStepOverSuspended;
00638 extern ULONG
InstructionsTraced;
00639 extern BOOLEAN
SymbolRecorded;
00640 extern LONG
CallLevelChange;
00641 extern LONG_PTR
oldpc;
00642 extern BOOLEAN
InstrCountInternal;
00643
extern BOOLEAN
BreakpointsSuspended;
00644
extern BOOLEAN
KdpControlCPending;
00645 extern BOOLEAN
KdpControlCPressed;
00646 extern ULONG
KdpRetryCount;
00647 extern ULONG
KdpNumberRetries;
00648 extern ULONG
KdpDefaultRetries;
00649
00650
extern KDP_BREAKPOINT_TYPE KdpBreakpointInstruction;
00651
extern ULONG
KdpOweBreakpoint;
00652
extern ULONG
KdpNextPacketIdToSend;
00653
extern ULONG
KdpPacketIdExpected;
00654
extern PVOID
KdpNtosImageBase;
00655 extern UCHAR
KdPrintCircularBuffer[
KDPRINTBUFFERSIZE];
00656 extern PUCHAR
KdPrintWritePointer;
00657 extern ULONG
KdPrintRolloverCount;
00658 extern KSPIN_LOCK
KdpPrintSpinLock;
00659 extern DEBUG_PARAMETERS KdDebugParameters;
00660 extern KSPIN_LOCK
KdpDataSpinLock;
00661
extern LIST_ENTRY
KdpDebuggerDataListHead;
00662 extern KDDEBUGGER_DATA64
KdDebuggerDataBlock;
00663 extern KDPC KdpTimeSlipDpc;
00664 extern WORK_QUEUE_ITEM KdpTimeSlipWorkItem;
00665 extern KTIMER KdpTimeSlipTimer;
00666 extern ULONG
KdpTimeSlipPending;
00667 extern KSPIN_LOCK
KdpTimeSlipEventLock;
00668 extern PVOID
KdpTimeSlipEvent;
00669 extern BOOLEAN
KdpDebuggerStructuresInitialized;
00670 extern ULONG
KdEnteredDebugger;
00671
00672
00673
00674
00675
00676
00677
00678
00679
00680
00681
00682
00683
00684
00685
00686
00687 #define SEARCH_PAGE_HIT_DATABASE_SIZE PAGE_SIZE
00688
00689 extern PFN_NUMBER
KdpSearchPageHits[
SEARCH_PAGE_HIT_DATABASE_SIZE];
00690 extern ULONG
KdpSearchPageHitOffsets[
SEARCH_PAGE_HIT_DATABASE_SIZE];
00691
00692 extern ULONG
KdpSearchPageHitIndex;
00693
00694
00695
00696
00697
00698
00699
00700
00701 extern LOGICAL
KdpSearchInProgress;
00702
00703
00704
00705
00706
00707
00708 extern PFN_NUMBER
KdpSearchStartPageFrame;
00709 extern PFN_NUMBER
KdpSearchEndPageFrame;
00710
00711 extern ULONG_PTR
KdpSearchAddressRangeStart;
00712 extern ULONG_PTR
KdpSearchAddressRangeEnd;
00713
00714
00715
00716
00717
00718
00719 #define KDP_SEARCH_SYMBOL_CHECK 0xABCDDCBA
00720
00721 extern ULONG
KdpSearchCheckPoint;
00722
00723
00724
00725
00726
00727 #define KDP_SEARCH_ALL_OFFSETS_IN_PAGE 0x0001
00728
00729
00730
00731
00732
00733
00734
00735
VOID
00736
KdpInitCom(
00737 VOID
00738 );
00739
00740
VOID
00741
KdpPortLock(
00742 VOID
00743 );
00744
00745
VOID
00746
KdpPortUnlock(
00747 VOID
00748 );
00749
00750 BOOLEAN
00751
KdpPollBreakInWithPortLock(
00752 VOID
00753 );
00754
00755
USHORT
00756
KdpReceivePacketLeader (
00757 IN ULONG PacketType,
00758 OUT PULONG PacketLeader
00759 );
00760
00761
#if DBG
00762
00763
#include <stdio.h>
00764
#define DPRINT(s) KdpDprintf s
00765
00766
VOID
00767 KdpDprintf(
00768 IN PCHAR f,
00769 ...
00770 );
00771
00772
#else
00773
00774 #define DPRINT(s)
00775
00776
#endif
00777
00778