Source code of Windows XP (NT5)
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.

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