Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

955 lines
22 KiB

  1. /*++
  2. Copyright (c) 1990-2001 Microsoft Corporation
  3. Module Name:
  4. kdp.h
  5. Abstract:
  6. Private include file for the Kernel Debugger subcomponent
  7. of the NTOS project
  8. Author:
  9. Mike O'Leary (mikeol) 29-June-1989
  10. Revision History:
  11. --*/
  12. #pragma warning(disable:4201) // nameless struct/union
  13. #pragma warning(disable:4214) // bit field types other than int
  14. #pragma warning(disable:4115) // named type definition in parentheses
  15. #pragma warning(disable:4127) // condition expression is constant
  16. #include "ntos.h"
  17. #include "ki.h"
  18. #define NOEXTAPI
  19. #include "wdbgexts.h"
  20. #include "ntdbg.h"
  21. #include "string.h"
  22. #include "stdlib.h"
  23. #include "kddll.h"
  24. #if defined(_ALPHA_)
  25. #include "alphaops.h"
  26. //
  27. // Define KD private PCR routines.
  28. //
  29. // Using the following private KD routines allows the kernel debugger to
  30. // step over breakpoints in modules that call the standard PCR routines.
  31. //
  32. PKPCR KdpGetPcr();
  33. ULONG KdpReadInternalProcessorState(PVOID, ULONG);
  34. ULONG KdpReadInternalProcessorCounters(PVOID, ULONG);
  35. struct _KPRCB *
  36. KdpGetCurrentPrcb();
  37. struct _KTHREAD *
  38. KdpGetCurrentThread();
  39. //
  40. // Redefine the standard PCR routines
  41. //
  42. #undef KiPcr
  43. #define KiPcr KdpGetPcr()
  44. #undef KeGetPcr
  45. #undef KeGetCurrentPrcb
  46. #undef KeGetCurrentThread
  47. #undef KeIsExecutingDpc
  48. #define KeGetPcr() KdpGetPcr()
  49. #define KeGetCurrentPrcb() KdpGetCurrentPrcb()
  50. #define KeGetCurrentThread() KdpGetCurrentThread()
  51. //
  52. // Define TYPES
  53. //
  54. #define KDP_BREAKPOINT_TYPE ULONG
  55. #define KDP_BREAKPOINT_BUFFER sizeof(ULONG)
  56. // longword aligned
  57. #define KDP_BREAKPOINT_ALIGN 3
  58. #define KDP_BREAKPOINT_INSTR_ALIGN 3
  59. // actual instruction is "call_pal kbpt"
  60. #define KDP_BREAKPOINT_VALUE KBPT_FUNC
  61. #elif defined(_IA64_)
  62. // IA64 instruction is in a 128-bit bundle. Each bundle consists of 3 instruction slots.
  63. // Each instruction slot is 41-bit long.
  64. //
  65. //
  66. // 127 87 86 46 45 5 4 1 0
  67. // ------------------------------------------------------------
  68. // | slot 2 | slot 1 | slot 0 |template|S|
  69. // ------------------------------------------------------------
  70. //
  71. // 127 96 95 64 63 32 31 0
  72. // ------------------------------------------------------------
  73. // | byte 3 | byte 2 | byte 1 | byte 0 |
  74. // ------------------------------------------------------------
  75. //
  76. // This presents two incompatibilities with conventional processors:
  77. // 1. The IA64 IP address is at the bundle bundary. The instruction slot number is
  78. // stored in ISR.ei at the time of exception.
  79. // 2. The 41-bit instruction format is not byte-aligned.
  80. //
  81. // Break instruction insertion must be done with proper bit-shifting to align with the selected
  82. // instruction slot. Further, to insert break instruction insertion at a specific slot, we must
  83. // be able to specify instruction slot as part of the address. We therefore define an EM address as
  84. // bundle address + slot number with the least significant two bit always zero:
  85. //
  86. // 31 4 3 2 1 0
  87. // --------------------------------
  88. // | bundle address |slot#|0 0|
  89. // --------------------------------
  90. //
  91. // The EM address as defined is the byte-aligned address that is closest to the actual instruction slot.
  92. // i.e., The EM instruction address of slot #0 is equal to bundle address.
  93. // slot #1 is equal to bundle address + 4.
  94. // slot #2 is equal to bundle address + 8.
  95. //
  96. // Upon exception, the bundle address is kept in IIP, and the instruction slot which caused
  97. // the exception is in ISR.ei. Kernel exception handler will construct the flat address and
  98. // export it in ExceptionRecord.ExceptionAddress.
  99. #define KDP_BREAKPOINT_TYPE ULONGLONG // 64-bit ULONGLONG type is needed to cover 41-bit EM break instruction.
  100. #define KDP_BREAKPOINT_BUFFER (2 * sizeof(ULONGLONG))
  101. #define KDP_BREAKPOINT_ALIGN 0x3 // An EM address consists of bundle and slot number and is 32-bit aligned.
  102. #define KDP_BREAKPOINT_INSTR_ALIGN 0xf
  103. #define KDP_BREAKPOINT_VALUE (BREAK_INSTR | (BREAKPOINT_STOP << 6))
  104. #elif defined(_X86_) || defined(_AMD64_)
  105. #define KDP_BREAKPOINT_TYPE UCHAR
  106. #define KDP_BREAKPOINT_BUFFER sizeof(UCHAR)
  107. #define KDP_BREAKPOINT_ALIGN 0
  108. #define KDP_BREAKPOINT_INSTR_ALIGN 0
  109. #define KDP_BREAKPOINT_VALUE 0xcc
  110. #endif
  111. //
  112. // Define constants.
  113. //
  114. //
  115. // Addresses above GLOBAL_BREAKPOINT_LIMIT are either in system space
  116. // or part of dynlink, so we treat them as global.
  117. //
  118. #define GLOBAL_BREAKPOINT_LIMIT 1610612736L // 1.5gigabytes
  119. //
  120. // Define breakpoint table entry structure.
  121. //
  122. #define KD_BREAKPOINT_IN_USE 0x00000001
  123. #define KD_BREAKPOINT_NEEDS_WRITE 0x00000002
  124. #define KD_BREAKPOINT_SUSPENDED 0x00000004
  125. #define KD_BREAKPOINT_NEEDS_REPLACE 0x00000008
  126. // IA64 specific defines
  127. #define KD_BREAKPOINT_STATE_MASK 0x0000000f
  128. #define KD_BREAKPOINT_IA64_MASK 0x000f0000
  129. #define KD_BREAKPOINT_IA64_MODE 0x00010000 // IA64 mode
  130. #define KD_BREAKPOINT_IA64_MOVL 0x00020000 // MOVL instruction displaced
  131. typedef struct _BREAKPOINT_ENTRY {
  132. ULONG Flags;
  133. ULONG_PTR DirectoryTableBase;
  134. PVOID Address;
  135. KDP_BREAKPOINT_TYPE Content;
  136. } BREAKPOINT_ENTRY, *PBREAKPOINT_ENTRY;
  137. //
  138. // Misc defines
  139. //
  140. #define MAXIMUM_RETRIES 20
  141. #define DBGKD_MAX_SPECIAL_CALLS 10
  142. typedef struct _TRACE_DATA_SYM {
  143. ULONG SymMin;
  144. ULONG SymMax;
  145. } TRACE_DATA_SYM, *PTRACE_DATA_SYM;
  146. #define KD_MAX_REMOTE_FILES 16
  147. typedef struct _KD_REMOTE_FILE {
  148. ULONG64 RemoteHandle;
  149. } KD_REMOTE_FILE, *PKD_REMOTE_FILE;
  150. //
  151. // Define function prototypes.
  152. //
  153. NTSTATUS
  154. KdpPrint(
  155. IN ULONG ComponentId,
  156. IN ULONG Level,
  157. IN PCHAR Message,
  158. IN USHORT Length,
  159. IN KPROCESSOR_MODE PreviousMode,
  160. IN PKTRAP_FRAME TrapFrame,
  161. IN PKEXCEPTION_FRAME ExceptionFrame,
  162. OUT PBOOLEAN Completion
  163. );
  164. BOOLEAN
  165. KdpPrintString (
  166. IN PSTRING Output
  167. );
  168. USHORT
  169. KdpPrompt(
  170. IN PCHAR Message,
  171. IN USHORT MessageLength,
  172. IN OUT PCHAR Reply,
  173. IN USHORT ReplyLength,
  174. IN KPROCESSOR_MODE PreviousMode,
  175. IN PKTRAP_FRAME TrapFrame,
  176. IN PKEXCEPTION_FRAME ExceptionFrame
  177. );
  178. BOOLEAN
  179. KdpPromptString (
  180. IN PSTRING Output,
  181. IN OUT PSTRING Input
  182. );
  183. BOOLEAN
  184. KdpReport(
  185. IN PKTRAP_FRAME TrapFrame,
  186. IN PKEXCEPTION_FRAME ExceptionFrame,
  187. IN PEXCEPTION_RECORD ExceptionRecord,
  188. IN PCONTEXT ContextRecord,
  189. IN KPROCESSOR_MODE PreviousMode,
  190. IN BOOLEAN SecondChance
  191. );
  192. VOID
  193. KdpSymbol(
  194. IN PSTRING String,
  195. IN PKD_SYMBOLS_INFO Symbol,
  196. IN BOOLEAN Unload,
  197. IN KPROCESSOR_MODE PreviousMode,
  198. IN PCONTEXT ContextRecord,
  199. IN PKTRAP_FRAME TrapFrame,
  200. IN PKEXCEPTION_FRAME ExceptionFrame
  201. );
  202. VOID
  203. KdpCommandString(
  204. IN PSTRING Name,
  205. IN PSTRING Command,
  206. IN KPROCESSOR_MODE PreviousMode,
  207. IN PCONTEXT ContextRecord,
  208. IN PKTRAP_FRAME TrapFrame,
  209. IN PKEXCEPTION_FRAME ExceptionFrame
  210. );
  211. ULONG
  212. KdpAddBreakpoint (
  213. IN PVOID Address
  214. );
  215. BOOLEAN
  216. KdpDeleteBreakpoint (
  217. IN ULONG Handle
  218. );
  219. BOOLEAN
  220. KdpDeleteBreakpointRange (
  221. IN PVOID Lower,
  222. IN PVOID Upper
  223. );
  224. #if defined(_IA64_)
  225. BOOLEAN
  226. KdpSuspendBreakpointRange (
  227. IN PVOID Lower,
  228. IN PVOID Upper
  229. );
  230. BOOLEAN
  231. KdpRestoreBreakpointRange (
  232. IN PVOID Lower,
  233. IN PVOID Upper
  234. );
  235. #endif
  236. #if i386
  237. BOOLEAN
  238. KdpCheckTracePoint(
  239. IN PEXCEPTION_RECORD ExceptionRecord,
  240. IN OUT PCONTEXT ContextRecord
  241. );
  242. NTSTATUS
  243. KdGetTraceInformation (
  244. OUT PVOID TraceInformation,
  245. IN ULONG TraceInformationLength,
  246. OUT PULONG RequiredLength
  247. );
  248. VOID
  249. KdSetInternalBreakpoint (
  250. IN PDBGKD_MANIPULATE_STATE64 m
  251. );
  252. #endif
  253. NTSTATUS
  254. KdQuerySpecialCalls (
  255. IN PDBGKD_MANIPULATE_STATE64 m,
  256. IN ULONG Length,
  257. OUT PULONG RequiredLength
  258. );
  259. VOID
  260. KdSetSpecialCall (
  261. IN PDBGKD_MANIPULATE_STATE64 m,
  262. IN PCONTEXT ContextRecord
  263. );
  264. VOID
  265. KdClearSpecialCalls (
  266. VOID
  267. );
  268. VOID
  269. KdpQuickMoveMemory (
  270. IN PCHAR Destination,
  271. IN PCHAR Source,
  272. IN ULONG Length
  273. );
  274. NTSTATUS
  275. KdpCopyMemoryChunks(
  276. ULONG64 Address,
  277. PVOID Buffer,
  278. ULONG TotalSize,
  279. ULONG ChunkSize,
  280. ULONG Flags,
  281. PULONG ActualSize OPTIONAL
  282. );
  283. //
  284. // KdpCopyMemoryChunks always copies between an untrusted address
  285. // and a trusted buffer. The following two macros express a read
  286. // form of this and a write form in a way similar to RtlCopyMemory
  287. // for convenient replacement of RtlCopyMemory calls.
  288. //
  289. // Read memory from an untrusted pointer into a trusted buffer.
  290. #define KdpCopyFromPtr(Dst, Src, Size, Done) \
  291. KdpCopyMemoryChunks((ULONG_PTR)(Src), Dst, Size, 0, \
  292. MMDBG_COPY_UNSAFE, Done)
  293. // Write memory from a trusted buffer through an untrusted pointer.
  294. #define KdpCopyToPtr(Dst, Src, Size, Done) \
  295. KdpCopyMemoryChunks((ULONG_PTR)(Dst), Src, Size, 0, \
  296. MMDBG_COPY_WRITE | MMDBG_COPY_UNSAFE, Done)
  297. ULONG
  298. KdpReceivePacket (
  299. IN ULONG ExpectedPacketType,
  300. OUT PSTRING MessageHeader,
  301. OUT PSTRING MessageData,
  302. OUT PULONG DataLength
  303. );
  304. NTSTATUS
  305. KdpAllowDisable(
  306. VOID
  307. );
  308. VOID
  309. KdpSetContextState(
  310. IN OUT PDBGKD_ANY_WAIT_STATE_CHANGE WaitStateChange,
  311. IN PCONTEXT ContextRecord
  312. );
  313. VOID
  314. KdpSetStateChange(
  315. IN OUT PDBGKD_ANY_WAIT_STATE_CHANGE WaitStateChange,
  316. IN PEXCEPTION_RECORD ExceptionRecord,
  317. IN PCONTEXT ContextRecord,
  318. IN BOOLEAN SecondChance
  319. );
  320. VOID
  321. KdpGetStateChange(
  322. IN PDBGKD_MANIPULATE_STATE64 ManipulateState,
  323. IN PCONTEXT ContextRecord
  324. );
  325. VOID
  326. KdpSendPacket (
  327. IN ULONG PacketType,
  328. IN PSTRING MessageHeader,
  329. IN PSTRING MessageData OPTIONAL
  330. );
  331. BOOLEAN
  332. KdpTrap (
  333. IN PKTRAP_FRAME TrapFrame,
  334. IN PKEXCEPTION_FRAME ExceptionFrame,
  335. IN PEXCEPTION_RECORD ExceptionRecord64,
  336. IN PCONTEXT ContextRecord,
  337. IN KPROCESSOR_MODE PreviousMode,
  338. IN BOOLEAN SecondChance
  339. );
  340. BOOLEAN
  341. KdpSwitchProcessor (
  342. IN PEXCEPTION_RECORD ExceptionRecord,
  343. IN OUT PCONTEXT ContextRecord,
  344. IN BOOLEAN SecondChance
  345. );
  346. BOOLEAN
  347. KdpReportExceptionStateChange (
  348. IN PEXCEPTION_RECORD ExceptionRecord,
  349. IN OUT PCONTEXT ContextRecord,
  350. IN BOOLEAN SecondChance
  351. );
  352. BOOLEAN
  353. KdpReportLoadSymbolsStateChange (
  354. IN PSTRING PathName,
  355. IN PKD_SYMBOLS_INFO SymbolInfo,
  356. IN BOOLEAN UnloadSymbols,
  357. IN OUT PCONTEXT ContextRecord
  358. );
  359. VOID
  360. KdpReportCommandStringStateChange (
  361. IN PSTRING Name,
  362. IN PSTRING Command,
  363. IN OUT PCONTEXT ContextRecord
  364. );
  365. KCONTINUE_STATUS
  366. KdpSendWaitContinue(
  367. IN ULONG PacketType,
  368. IN PSTRING MessageHeader,
  369. IN PSTRING MessageData OPTIONAL,
  370. IN OUT PCONTEXT ContextRecord
  371. );
  372. VOID
  373. KdpReadVirtualMemory(
  374. IN PDBGKD_MANIPULATE_STATE64 m,
  375. IN PSTRING AdditionalData,
  376. IN PCONTEXT Context
  377. );
  378. #if 0
  379. VOID
  380. KdpReadVirtualMemory64(
  381. IN PDBGKD_MANIPULATE_STATE64 m,
  382. IN PSTRING AdditionalData,
  383. IN PCONTEXT Context
  384. );
  385. #endif
  386. VOID
  387. KdpWriteVirtualMemory(
  388. IN PDBGKD_MANIPULATE_STATE64 m,
  389. IN PSTRING AdditionalData,
  390. IN PCONTEXT Context
  391. );
  392. #if 0
  393. VOID
  394. KdpWriteVirtualMemory64(
  395. IN PDBGKD_MANIPULATE_STATE64 m,
  396. IN PSTRING AdditionalData,
  397. IN PCONTEXT Context
  398. );
  399. #endif
  400. VOID
  401. KdpReadPhysicalMemory(
  402. IN PDBGKD_MANIPULATE_STATE64 m,
  403. IN PSTRING AdditionalData,
  404. IN PCONTEXT Context
  405. );
  406. VOID
  407. KdpWritePhysicalMemory(
  408. IN PDBGKD_MANIPULATE_STATE64 m,
  409. IN PSTRING AdditionalData,
  410. IN PCONTEXT Context
  411. );
  412. VOID
  413. KdpCheckLowMemory(
  414. IN PDBGKD_MANIPULATE_STATE64 m
  415. );
  416. VOID
  417. KdpGetContext(
  418. IN PDBGKD_MANIPULATE_STATE64 m,
  419. IN PSTRING AdditionalData,
  420. IN PCONTEXT Context
  421. );
  422. VOID
  423. KdpSetContext(
  424. IN PDBGKD_MANIPULATE_STATE64 m,
  425. IN PSTRING AdditionalData,
  426. IN PCONTEXT Context
  427. );
  428. VOID
  429. KdpWriteBreakpoint(
  430. IN PDBGKD_MANIPULATE_STATE64 m,
  431. IN PSTRING AdditionalData,
  432. IN PCONTEXT Context
  433. );
  434. VOID
  435. KdpRestoreBreakpoint(
  436. IN PDBGKD_MANIPULATE_STATE64 m,
  437. IN PSTRING AdditionalData,
  438. IN PCONTEXT Context
  439. );
  440. VOID
  441. KdpReadControlSpace(
  442. IN PDBGKD_MANIPULATE_STATE64 m,
  443. IN PSTRING AdditionalData,
  444. IN PCONTEXT Context
  445. );
  446. VOID
  447. KdpWriteControlSpace(
  448. IN PDBGKD_MANIPULATE_STATE64 m,
  449. IN PSTRING AdditionalData,
  450. IN PCONTEXT Context
  451. );
  452. VOID
  453. KdpReadIoSpace(
  454. IN PDBGKD_MANIPULATE_STATE64 m,
  455. IN PSTRING AdditionalData,
  456. IN PCONTEXT Context
  457. );
  458. VOID
  459. KdpWriteIoSpace(
  460. IN PDBGKD_MANIPULATE_STATE64 m,
  461. IN PSTRING AdditionalData,
  462. IN PCONTEXT Context
  463. );
  464. VOID
  465. KdpReadIoSpaceExtended (
  466. IN PDBGKD_MANIPULATE_STATE64 m,
  467. IN PSTRING AdditionalData,
  468. IN PCONTEXT Context
  469. );
  470. VOID
  471. KdpWriteIoSpaceExtended (
  472. IN PDBGKD_MANIPULATE_STATE64 m,
  473. IN PSTRING AdditionalData,
  474. IN PCONTEXT Context
  475. );
  476. VOID
  477. KdpReadMachineSpecificRegister(
  478. IN PDBGKD_MANIPULATE_STATE64 m,
  479. IN PSTRING AdditionalData,
  480. IN PCONTEXT Context
  481. );
  482. VOID
  483. KdpWriteMachineSpecificRegister(
  484. IN PDBGKD_MANIPULATE_STATE64 m,
  485. IN PSTRING AdditionalData,
  486. IN PCONTEXT Context
  487. );
  488. VOID
  489. KdpGetBusData (
  490. IN PDBGKD_MANIPULATE_STATE64 m,
  491. IN PSTRING AdditionalData,
  492. IN PCONTEXT Context
  493. );
  494. VOID
  495. KdpSetBusData (
  496. IN PDBGKD_MANIPULATE_STATE64 m,
  497. IN PSTRING AdditionalData,
  498. IN PCONTEXT Context
  499. );
  500. VOID
  501. KdpSendTraceData(
  502. PSTRING Data
  503. );
  504. VOID
  505. KdpSuspendBreakpoint (
  506. ULONG Handle
  507. );
  508. VOID
  509. KdpSuspendAllBreakpoints (
  510. VOID
  511. );
  512. VOID
  513. KdpRestoreAllBreakpoints (
  514. VOID
  515. );
  516. #if !defined(_TRUSTED_WINDOWS_)
  517. VOID
  518. KdpTimeSlipDpcRoutine (
  519. PKDPC Dpc,
  520. PVOID DeferredContext,
  521. PVOID SystemArgument1,
  522. PVOID SystemArgument2
  523. );
  524. VOID
  525. KdpTimeSlipWork (
  526. IN PVOID Context
  527. );
  528. #endif
  529. //
  530. // Routines shared between the debugger and
  531. // NtSystemDebugControl.
  532. //
  533. VOID
  534. KdpSysGetVersion(
  535. PDBGKD_GET_VERSION64 Version
  536. );
  537. NTSTATUS
  538. KdpSysReadControlSpace(
  539. ULONG Processor,
  540. ULONG64 Address,
  541. PVOID Buffer,
  542. ULONG Request,
  543. PULONG Actual
  544. );
  545. NTSTATUS
  546. KdpSysWriteControlSpace(
  547. ULONG Processor,
  548. ULONG64 Address,
  549. PVOID Buffer,
  550. ULONG Request,
  551. PULONG Actual
  552. );
  553. NTSTATUS
  554. KdpSysReadIoSpace(
  555. INTERFACE_TYPE InterfaceType,
  556. ULONG BusNumber,
  557. ULONG AddressSpace,
  558. ULONG64 Address,
  559. PVOID Buffer,
  560. ULONG Request,
  561. PULONG Actual
  562. );
  563. NTSTATUS
  564. KdpSysWriteIoSpace(
  565. INTERFACE_TYPE InterfaceType,
  566. ULONG BusNumber,
  567. ULONG AddressSpace,
  568. ULONG64 Address,
  569. PVOID Buffer,
  570. ULONG Request,
  571. PULONG Actual
  572. );
  573. NTSTATUS
  574. KdpSysReadMsr(
  575. ULONG Msr,
  576. PULONG64 Data
  577. );
  578. NTSTATUS
  579. KdpSysWriteMsr(
  580. ULONG Msr,
  581. PULONG64 Data
  582. );
  583. NTSTATUS
  584. KdpSysReadBusData(
  585. BUS_DATA_TYPE BusDataType,
  586. ULONG BusNumber,
  587. ULONG SlotNumber,
  588. ULONG Address,
  589. PVOID Buffer,
  590. ULONG Request,
  591. PULONG Actual
  592. );
  593. NTSTATUS
  594. KdpSysWriteBusData(
  595. BUS_DATA_TYPE BusDataType,
  596. ULONG BusNumber,
  597. ULONG SlotNumber,
  598. ULONG Address,
  599. PVOID Buffer,
  600. ULONG Request,
  601. PULONG Actual
  602. );
  603. NTSTATUS
  604. KdpSysCheckLowMemory(
  605. ULONG MmFlags
  606. );
  607. //
  608. // Define dummy prototype so the address of the standard breakpoint instruction
  609. // can be captured.
  610. //
  611. // N.B. This function is NEVER called.
  612. //
  613. VOID
  614. RtlpBreakWithStatusInstruction (
  615. VOID
  616. );
  617. //
  618. // Define external references.
  619. //
  620. #define KDP_MESSAGE_BUFFER_SIZE 4096
  621. extern BREAKPOINT_ENTRY KdpBreakpointTable[BREAKPOINT_TABLE_SIZE];
  622. extern KD_REMOTE_FILE KdpRemoteFiles[KD_MAX_REMOTE_FILES];
  623. extern KSPIN_LOCK KdpDebuggerLock;
  624. extern PKDEBUG_ROUTINE KiDebugRoutine;
  625. extern PKDEBUG_SWITCH_ROUTINE KiDebugSwitchRoutine;
  626. extern KDP_BREAKPOINT_TYPE KdpBreakpointInstruction;
  627. extern UCHAR DECLSPEC_ALIGN(8) KdpMessageBuffer[KDP_MESSAGE_BUFFER_SIZE];
  628. extern UCHAR KdpPathBuffer[KDP_MESSAGE_BUFFER_SIZE];
  629. extern BOOLEAN KdpOweBreakpoint;
  630. extern LARGE_INTEGER KdPerformanceCounterRate;
  631. extern LARGE_INTEGER KdTimerStart;
  632. extern LARGE_INTEGER KdTimerStop;
  633. extern LARGE_INTEGER KdTimerDifference;
  634. extern ULONG KdComponentTableSize;
  635. extern PULONG KdComponentTable[];
  636. extern BOOLEAN BreakpointsSuspended;
  637. extern LIST_ENTRY KdpDebuggerDataListHead;
  638. typedef struct {
  639. ULONG64 Addr; // pc address of breakpoint
  640. ULONG Flags; // Flags bits
  641. ULONG Calls; // # of times traced routine called
  642. ULONG CallsLastCheck; // # of calls at last periodic (1s) check
  643. ULONG MaxCallsPerPeriod;
  644. ULONG MinInstructions; // largest number of instructions for 1 call
  645. ULONG MaxInstructions; // smallest # of instructions for 1 call
  646. ULONG TotalInstructions; // total instructions for all calls
  647. ULONG Handle; // handle in (regular) bpt table
  648. PVOID Thread; // Thread that's skipping this BP
  649. ULONG64 ReturnAddress; // return address (if not COUNTONLY)
  650. } DBGKD_INTERNAL_BREAKPOINT, *PDBGKD_INTERNAL_BREAKPOINT;
  651. extern DBGKD_INTERNAL_BREAKPOINT KdpInternalBPs[DBGKD_MAX_INTERNAL_BREAKPOINTS];
  652. extern ULONG_PTR KdpCurrentSymbolStart;
  653. extern ULONG_PTR KdpCurrentSymbolEnd;
  654. extern LONG KdpNextCallLevelChange;
  655. extern ULONG_PTR KdSpecialCalls[];
  656. extern ULONG KdNumberOfSpecialCalls;
  657. extern ULONG_PTR InitialSP;
  658. extern ULONG KdpNumInternalBreakpoints;
  659. extern KTIMER InternalBreakpointTimer;
  660. extern KDPC InternalBreakpointCheckDpc;
  661. extern BOOLEAN KdpPortLocked;
  662. extern LARGE_INTEGER KdpTimeEntered;
  663. extern DBGKD_TRACE_DATA TraceDataBuffer[];
  664. extern ULONG TraceDataBufferPosition;
  665. extern TRACE_DATA_SYM TraceDataSyms[];
  666. extern UCHAR NextTraceDataSym;
  667. extern UCHAR NumTraceDataSyms;
  668. extern ULONG IntBPsSkipping;
  669. extern BOOLEAN WatchStepOver;
  670. extern BOOLEAN BreakPointTimerStarted;
  671. extern PVOID WSOThread;
  672. extern ULONG_PTR WSOEsp;
  673. extern ULONG WatchStepOverHandle;
  674. extern ULONG_PTR WatchStepOverBreakAddr;
  675. extern BOOLEAN WatchStepOverSuspended;
  676. extern ULONG InstructionsTraced;
  677. extern BOOLEAN SymbolRecorded;
  678. extern LONG CallLevelChange;
  679. extern LONG_PTR oldpc;
  680. extern BOOLEAN InstrCountInternal;
  681. extern BOOLEAN BreakpointsSuspended;
  682. extern BOOLEAN KdpControlCPressed;
  683. extern KD_CONTEXT KdpContext;
  684. extern KDP_BREAKPOINT_TYPE KdpBreakpointInstruction;
  685. extern UCHAR KdPrintDefaultCircularBuffer[KDPRINTDEFAULTBUFFERSIZE];
  686. extern PUCHAR KdPrintCircularBuffer;
  687. extern PUCHAR KdPrintWritePointer;
  688. extern ULONG KdPrintRolloverCount;
  689. extern ULONG KdPrintBufferChanges;
  690. extern KSPIN_LOCK KdpPrintSpinLock;
  691. extern KSPIN_LOCK KdpDataSpinLock;
  692. extern LIST_ENTRY KdpDebuggerDataListHead;
  693. extern DBGKD_GET_VERSION64 KdVersionBlock;
  694. extern KDDEBUGGER_DATA64 KdDebuggerDataBlock;
  695. extern KDPC KdpTimeSlipDpc;
  696. extern WORK_QUEUE_ITEM KdpTimeSlipWorkItem;
  697. extern KTIMER KdpTimeSlipTimer;
  698. extern ULONG KdpTimeSlipPending;
  699. extern KSPIN_LOCK KdpTimeSlipEventLock;
  700. extern PVOID KdpTimeSlipEvent;
  701. extern BOOLEAN KdpDebuggerStructuresInitialized;
  702. extern ULONG KdEnteredDebugger;
  703. extern BOOLEAN KdPreviouslyEnabled;
  704. //
  705. // !search support (page hit database)
  706. //
  707. //
  708. // Hit database where search results are stored (kddata.c).
  709. // The debugger extensions know how to extract the information
  710. // from here.
  711. //
  712. // Note that the size of the hit database is large enough to
  713. // accomodate any searches because the !search extension works
  714. // in batches of pages < PAGE_SIZE and for every page we register only
  715. // one hit.
  716. //
  717. #define SEARCH_PAGE_HIT_DATABASE_SIZE PAGE_SIZE
  718. extern PFN_NUMBER KdpSearchPageHits[SEARCH_PAGE_HIT_DATABASE_SIZE];
  719. extern ULONG KdpSearchPageHitOffsets[SEARCH_PAGE_HIT_DATABASE_SIZE];
  720. extern ULONG KdpSearchPageHitIndex;
  721. //
  722. // Set to true while a physical memory search is in progress.
  723. // Reset at the end of the search. This is done in the debugger
  724. // extension and it is a flag used by KdpCheckLowMemory to get
  725. // onto a different code path.
  726. //
  727. extern LOGICAL KdpSearchInProgress;
  728. //
  729. // These variables store the current state of the search operation.
  730. // They can be used to restore an interrupted search.
  731. //
  732. extern PFN_NUMBER KdpSearchStartPageFrame;
  733. extern PFN_NUMBER KdpSearchEndPageFrame;
  734. extern ULONG_PTR KdpSearchAddressRangeStart;
  735. extern ULONG_PTR KdpSearchAddressRangeEnd;
  736. extern PFN_NUMBER KdpSearchPfnValue;
  737. //
  738. // Checkpoint variable used to test if we have the right
  739. // debugging symbols.
  740. //
  741. #define KDP_SEARCH_SYMBOL_CHECK 0xABCDDCBA
  742. extern ULONG KdpSearchCheckPoint;
  743. //
  744. // Page search flags
  745. //
  746. #define KDP_SEARCH_ALL_OFFSETS_IN_PAGE 0x0001
  747. //
  748. // Private procedure prototypes
  749. //
  750. BOOLEAN
  751. KdpAcquireBreakpoint(
  752. IN ULONG Number
  753. );
  754. VOID
  755. KdpInitCom(
  756. VOID
  757. );
  758. VOID
  759. KdpPortLock(
  760. VOID
  761. );
  762. VOID
  763. KdpPortUnlock(
  764. VOID
  765. );
  766. BOOLEAN
  767. KdpPollBreakInWithPortLock(
  768. VOID
  769. );
  770. USHORT
  771. KdpReceivePacketLeader (
  772. IN ULONG PacketType,
  773. OUT PULONG PacketLeader
  774. );
  775. #if DBG
  776. #include <stdio.h>
  777. #define DPRINT(s) KdpDprintf s
  778. VOID
  779. KdpDprintf(
  780. IN PCHAR f,
  781. ...
  782. );
  783. #else
  784. #define DPRINT(s)
  785. #endif