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.

2376 lines
59 KiB

  1. /*++
  2. Copyright (c) Microsoft Corporation. All rights reserved.
  3. Module Name:
  4. wdbgexts.h
  5. Abstract:
  6. This file contains the necessary prototypes and data types for a user
  7. to write a debugger extension DLL. This header file is also included
  8. by the NT debuggers (WINDBG & KD).
  9. This header file must be included after "windows.h" and "dbghelp.h".
  10. Please see the NT DDK documentation for specific information about
  11. how to write your own debugger extension DLL.
  12. Environment:
  13. Win32 only.
  14. Revision History:
  15. --*/
  16. #ifndef _WDBGEXTS_
  17. #define _WDBGEXTS_
  18. #if _MSC_VER > 1000
  19. #pragma once
  20. #endif
  21. #ifdef __cplusplus
  22. extern "C" {
  23. #endif
  24. #if !defined(WDBGAPI)
  25. #define WDBGAPI __stdcall
  26. #endif
  27. #if !defined(WDBGAPIV)
  28. #define WDBGAPIV __cdecl
  29. #endif
  30. #ifndef _WINDEF_
  31. typedef CONST void *LPCVOID;
  32. #endif
  33. #ifndef _ULONGLONG_
  34. typedef unsigned __int64 ULONGLONG;
  35. typedef ULONGLONG *PULONGLONG;
  36. #endif
  37. typedef
  38. VOID
  39. (WDBGAPIV*PWINDBG_OUTPUT_ROUTINE)(
  40. PCSTR lpFormat,
  41. ...
  42. );
  43. typedef
  44. ULONG_PTR
  45. (WDBGAPI*PWINDBG_GET_EXPRESSION)(
  46. PCSTR lpExpression
  47. );
  48. typedef
  49. ULONG
  50. (WDBGAPI*PWINDBG_GET_EXPRESSION32)(
  51. PCSTR lpExpression
  52. );
  53. typedef
  54. ULONG64
  55. (WDBGAPI*PWINDBG_GET_EXPRESSION64)(
  56. PCSTR lpExpression
  57. );
  58. typedef
  59. VOID
  60. (WDBGAPI*PWINDBG_GET_SYMBOL)(
  61. PVOID offset,
  62. PCHAR pchBuffer,
  63. ULONG_PTR *pDisplacement
  64. );
  65. typedef
  66. VOID
  67. (WDBGAPI*PWINDBG_GET_SYMBOL32)(
  68. ULONG offset,
  69. PCHAR pchBuffer,
  70. PULONG pDisplacement
  71. );
  72. typedef
  73. VOID
  74. (WDBGAPI*PWINDBG_GET_SYMBOL64)(
  75. ULONG64 offset,
  76. PCHAR pchBuffer,
  77. PULONG64 pDisplacement
  78. );
  79. typedef
  80. ULONG
  81. (WDBGAPI*PWINDBG_DISASM)(
  82. ULONG_PTR *lpOffset,
  83. PCSTR lpBuffer,
  84. ULONG fShowEffectiveAddress
  85. );
  86. typedef
  87. ULONG
  88. (WDBGAPI*PWINDBG_DISASM32)(
  89. ULONG *lpOffset,
  90. PCSTR lpBuffer,
  91. ULONG fShowEffectiveAddress
  92. );
  93. typedef
  94. ULONG
  95. (WDBGAPI*PWINDBG_DISASM64)(
  96. ULONG64 *lpOffset,
  97. PCSTR lpBuffer,
  98. ULONG fShowEffectiveAddress
  99. );
  100. typedef
  101. ULONG
  102. (WDBGAPI*PWINDBG_CHECK_CONTROL_C)(
  103. VOID
  104. );
  105. typedef
  106. ULONG
  107. (WDBGAPI*PWINDBG_READ_PROCESS_MEMORY_ROUTINE)(
  108. ULONG_PTR offset,
  109. PVOID lpBuffer,
  110. ULONG cb,
  111. PULONG lpcbBytesRead
  112. );
  113. typedef
  114. ULONG
  115. (WDBGAPI*PWINDBG_READ_PROCESS_MEMORY_ROUTINE32)(
  116. ULONG offset,
  117. PVOID lpBuffer,
  118. ULONG cb,
  119. PULONG lpcbBytesRead
  120. );
  121. typedef
  122. ULONG
  123. (WDBGAPI*PWINDBG_READ_PROCESS_MEMORY_ROUTINE64)(
  124. ULONG64 offset,
  125. PVOID lpBuffer,
  126. ULONG cb,
  127. PULONG lpcbBytesRead
  128. );
  129. typedef
  130. ULONG
  131. (WDBGAPI*PWINDBG_WRITE_PROCESS_MEMORY_ROUTINE)(
  132. ULONG_PTR offset,
  133. LPCVOID lpBuffer,
  134. ULONG cb,
  135. PULONG lpcbBytesWritten
  136. );
  137. typedef
  138. ULONG
  139. (WDBGAPI*PWINDBG_WRITE_PROCESS_MEMORY_ROUTINE32)(
  140. ULONG offset,
  141. LPCVOID lpBuffer,
  142. ULONG cb,
  143. PULONG lpcbBytesWritten
  144. );
  145. typedef
  146. ULONG
  147. (WDBGAPI*PWINDBG_WRITE_PROCESS_MEMORY_ROUTINE64)(
  148. ULONG64 offset,
  149. LPCVOID lpBuffer,
  150. ULONG cb,
  151. PULONG lpcbBytesWritten
  152. );
  153. typedef
  154. ULONG
  155. (WDBGAPI*PWINDBG_GET_THREAD_CONTEXT_ROUTINE)(
  156. ULONG Processor,
  157. PCONTEXT lpContext,
  158. ULONG cbSizeOfContext
  159. );
  160. typedef
  161. ULONG
  162. (WDBGAPI*PWINDBG_SET_THREAD_CONTEXT_ROUTINE)(
  163. ULONG Processor,
  164. PCONTEXT lpContext,
  165. ULONG cbSizeOfContext
  166. );
  167. typedef
  168. ULONG
  169. (WDBGAPI*PWINDBG_IOCTL_ROUTINE)(
  170. USHORT IoctlType,
  171. PVOID lpvData,
  172. ULONG cbSize
  173. );
  174. typedef
  175. ULONG
  176. (WDBGAPI*PWINDBG_OLDKD_READ_PHYSICAL_MEMORY)(
  177. ULONGLONG address,
  178. PVOID buffer,
  179. ULONG count,
  180. PULONG bytesread
  181. );
  182. typedef
  183. ULONG
  184. (WDBGAPI*PWINDBG_OLDKD_WRITE_PHYSICAL_MEMORY)(
  185. ULONGLONG address,
  186. PVOID buffer,
  187. ULONG length,
  188. PULONG byteswritten
  189. );
  190. typedef struct _EXTSTACKTRACE {
  191. ULONG FramePointer;
  192. ULONG ProgramCounter;
  193. ULONG ReturnAddress;
  194. ULONG Args[4];
  195. } EXTSTACKTRACE, *PEXTSTACKTRACE;
  196. typedef struct _EXTSTACKTRACE32 {
  197. ULONG FramePointer;
  198. ULONG ProgramCounter;
  199. ULONG ReturnAddress;
  200. ULONG Args[4];
  201. } EXTSTACKTRACE32, *PEXTSTACKTRACE32;
  202. typedef struct _EXTSTACKTRACE64 {
  203. ULONG64 FramePointer;
  204. ULONG64 ProgramCounter;
  205. ULONG64 ReturnAddress;
  206. ULONG64 Args[4];
  207. } EXTSTACKTRACE64, *PEXTSTACKTRACE64;
  208. typedef
  209. ULONG
  210. (*PWINDBG_STACKTRACE_ROUTINE)(
  211. ULONG FramePointer,
  212. ULONG StackPointer,
  213. ULONG ProgramCounter,
  214. PEXTSTACKTRACE StackFrames,
  215. ULONG Frames
  216. );
  217. typedef
  218. ULONG
  219. (*PWINDBG_STACKTRACE_ROUTINE32)(
  220. ULONG FramePointer,
  221. ULONG StackPointer,
  222. ULONG ProgramCounter,
  223. PEXTSTACKTRACE32 StackFrames,
  224. ULONG Frames
  225. );
  226. typedef
  227. ULONG
  228. (*PWINDBG_STACKTRACE_ROUTINE64)(
  229. ULONG64 FramePointer,
  230. ULONG64 StackPointer,
  231. ULONG64 ProgramCounter,
  232. PEXTSTACKTRACE64 StackFrames,
  233. ULONG Frames
  234. );
  235. typedef struct _WINDBG_EXTENSION_APIS {
  236. ULONG nSize;
  237. PWINDBG_OUTPUT_ROUTINE lpOutputRoutine;
  238. PWINDBG_GET_EXPRESSION lpGetExpressionRoutine;
  239. PWINDBG_GET_SYMBOL lpGetSymbolRoutine;
  240. PWINDBG_DISASM lpDisasmRoutine;
  241. PWINDBG_CHECK_CONTROL_C lpCheckControlCRoutine;
  242. PWINDBG_READ_PROCESS_MEMORY_ROUTINE lpReadProcessMemoryRoutine;
  243. PWINDBG_WRITE_PROCESS_MEMORY_ROUTINE lpWriteProcessMemoryRoutine;
  244. PWINDBG_GET_THREAD_CONTEXT_ROUTINE lpGetThreadContextRoutine;
  245. PWINDBG_SET_THREAD_CONTEXT_ROUTINE lpSetThreadContextRoutine;
  246. PWINDBG_IOCTL_ROUTINE lpIoctlRoutine;
  247. PWINDBG_STACKTRACE_ROUTINE lpStackTraceRoutine;
  248. } WINDBG_EXTENSION_APIS, *PWINDBG_EXTENSION_APIS;
  249. typedef struct _WINDBG_EXTENSION_APIS32 {
  250. ULONG nSize;
  251. PWINDBG_OUTPUT_ROUTINE lpOutputRoutine;
  252. PWINDBG_GET_EXPRESSION32 lpGetExpressionRoutine;
  253. PWINDBG_GET_SYMBOL32 lpGetSymbolRoutine;
  254. PWINDBG_DISASM32 lpDisasmRoutine;
  255. PWINDBG_CHECK_CONTROL_C lpCheckControlCRoutine;
  256. PWINDBG_READ_PROCESS_MEMORY_ROUTINE32 lpReadProcessMemoryRoutine;
  257. PWINDBG_WRITE_PROCESS_MEMORY_ROUTINE32 lpWriteProcessMemoryRoutine;
  258. PWINDBG_GET_THREAD_CONTEXT_ROUTINE lpGetThreadContextRoutine;
  259. PWINDBG_SET_THREAD_CONTEXT_ROUTINE lpSetThreadContextRoutine;
  260. PWINDBG_IOCTL_ROUTINE lpIoctlRoutine;
  261. PWINDBG_STACKTRACE_ROUTINE32 lpStackTraceRoutine;
  262. } WINDBG_EXTENSION_APIS32, *PWINDBG_EXTENSION_APIS32;
  263. typedef struct _WINDBG_EXTENSION_APIS64 {
  264. ULONG nSize;
  265. PWINDBG_OUTPUT_ROUTINE lpOutputRoutine;
  266. PWINDBG_GET_EXPRESSION64 lpGetExpressionRoutine;
  267. PWINDBG_GET_SYMBOL64 lpGetSymbolRoutine;
  268. PWINDBG_DISASM64 lpDisasmRoutine;
  269. PWINDBG_CHECK_CONTROL_C lpCheckControlCRoutine;
  270. PWINDBG_READ_PROCESS_MEMORY_ROUTINE64 lpReadProcessMemoryRoutine;
  271. PWINDBG_WRITE_PROCESS_MEMORY_ROUTINE64 lpWriteProcessMemoryRoutine;
  272. PWINDBG_GET_THREAD_CONTEXT_ROUTINE lpGetThreadContextRoutine;
  273. PWINDBG_SET_THREAD_CONTEXT_ROUTINE lpSetThreadContextRoutine;
  274. PWINDBG_IOCTL_ROUTINE lpIoctlRoutine;
  275. PWINDBG_STACKTRACE_ROUTINE64 lpStackTraceRoutine;
  276. } WINDBG_EXTENSION_APIS64, *PWINDBG_EXTENSION_APIS64;
  277. typedef struct _WINDBG_OLD_EXTENSION_APIS {
  278. ULONG nSize;
  279. PWINDBG_OUTPUT_ROUTINE lpOutputRoutine;
  280. PWINDBG_GET_EXPRESSION lpGetExpressionRoutine;
  281. PWINDBG_GET_SYMBOL lpGetSymbolRoutine;
  282. PWINDBG_DISASM lpDisasmRoutine;
  283. PWINDBG_CHECK_CONTROL_C lpCheckControlCRoutine;
  284. } WINDBG_OLD_EXTENSION_APIS, *PWINDBG_OLD_EXTENSION_APIS;
  285. typedef struct _WINDBG_OLDKD_EXTENSION_APIS {
  286. ULONG nSize;
  287. PWINDBG_OUTPUT_ROUTINE lpOutputRoutine;
  288. PWINDBG_GET_EXPRESSION32 lpGetExpressionRoutine;
  289. PWINDBG_GET_SYMBOL32 lpGetSymbolRoutine;
  290. PWINDBG_DISASM32 lpDisasmRoutine;
  291. PWINDBG_CHECK_CONTROL_C lpCheckControlCRoutine;
  292. PWINDBG_READ_PROCESS_MEMORY_ROUTINE32 lpReadVirtualMemRoutine;
  293. PWINDBG_WRITE_PROCESS_MEMORY_ROUTINE32 lpWriteVirtualMemRoutine;
  294. PWINDBG_OLDKD_READ_PHYSICAL_MEMORY lpReadPhysicalMemRoutine;
  295. PWINDBG_OLDKD_WRITE_PHYSICAL_MEMORY lpWritePhysicalMemRoutine;
  296. } WINDBG_OLDKD_EXTENSION_APIS, *PWINDBG_OLDKD_EXTENSION_APIS;
  297. typedef
  298. VOID
  299. (WDBGAPI*PWINDBG_OLD_EXTENSION_ROUTINE)(
  300. ULONG dwCurrentPc,
  301. PWINDBG_EXTENSION_APIS lpExtensionApis,
  302. PCSTR lpArgumentString
  303. );
  304. typedef
  305. VOID
  306. (WDBGAPI*PWINDBG_EXTENSION_ROUTINE)(
  307. HANDLE hCurrentProcess,
  308. HANDLE hCurrentThread,
  309. ULONG dwCurrentPc,
  310. ULONG dwProcessor,
  311. PCSTR lpArgumentString
  312. );
  313. typedef
  314. VOID
  315. (WDBGAPI*PWINDBG_EXTENSION_ROUTINE32)(
  316. HANDLE hCurrentProcess,
  317. HANDLE hCurrentThread,
  318. ULONG dwCurrentPc,
  319. ULONG dwProcessor,
  320. PCSTR lpArgumentString
  321. );
  322. typedef
  323. VOID
  324. (WDBGAPI*PWINDBG_EXTENSION_ROUTINE64)(
  325. HANDLE hCurrentProcess,
  326. HANDLE hCurrentThread,
  327. ULONG64 dwCurrentPc,
  328. ULONG dwProcessor,
  329. PCSTR lpArgumentString
  330. );
  331. typedef
  332. VOID
  333. (WDBGAPI*PWINDBG_OLDKD_EXTENSION_ROUTINE)(
  334. ULONG dwCurrentPc,
  335. PWINDBG_OLDKD_EXTENSION_APIS lpExtensionApis,
  336. PCSTR lpArgumentString
  337. );
  338. typedef
  339. VOID
  340. (WDBGAPI*PWINDBG_EXTENSION_DLL_INIT)(
  341. PWINDBG_EXTENSION_APIS lpExtensionApis,
  342. USHORT MajorVersion,
  343. USHORT MinorVersion
  344. );
  345. typedef
  346. VOID
  347. (WDBGAPI*PWINDBG_EXTENSION_DLL_INIT32)(
  348. PWINDBG_EXTENSION_APIS32 lpExtensionApis,
  349. USHORT MajorVersion,
  350. USHORT MinorVersion
  351. );
  352. typedef
  353. VOID
  354. (WDBGAPI*PWINDBG_EXTENSION_DLL_INIT64)(
  355. PWINDBG_EXTENSION_APIS64 lpExtensionApis,
  356. USHORT MajorVersion,
  357. USHORT MinorVersion
  358. );
  359. typedef
  360. ULONG
  361. (WDBGAPI*PWINDBG_CHECK_VERSION)(
  362. VOID
  363. );
  364. #define EXT_API_VERSION_NUMBER 5
  365. #define EXT_API_VERSION_NUMBER32 5
  366. #define EXT_API_VERSION_NUMBER64 6
  367. typedef struct EXT_API_VERSION {
  368. USHORT MajorVersion;
  369. USHORT MinorVersion;
  370. USHORT Revision;
  371. USHORT Reserved;
  372. } EXT_API_VERSION, *LPEXT_API_VERSION;
  373. typedef
  374. LPEXT_API_VERSION
  375. (WDBGAPI*PWINDBG_EXTENSION_API_VERSION)(
  376. VOID
  377. );
  378. #define IG_KD_CONTEXT 1
  379. #define IG_READ_CONTROL_SPACE 2
  380. #define IG_WRITE_CONTROL_SPACE 3
  381. #define IG_READ_IO_SPACE 4
  382. #define IG_WRITE_IO_SPACE 5
  383. #define IG_READ_PHYSICAL 6
  384. #define IG_WRITE_PHYSICAL 7
  385. #define IG_READ_IO_SPACE_EX 8
  386. #define IG_WRITE_IO_SPACE_EX 9
  387. #define IG_KSTACK_HELP 10 // obsolete
  388. #define IG_SET_THREAD 11
  389. #define IG_READ_MSR 12
  390. #define IG_WRITE_MSR 13
  391. #define IG_GET_DEBUGGER_DATA 14
  392. #define IG_GET_KERNEL_VERSION 15
  393. #define IG_RELOAD_SYMBOLS 16
  394. #define IG_GET_SET_SYMPATH 17
  395. #define IG_GET_EXCEPTION_RECORD 18
  396. #define IG_IS_PTR64 19
  397. #define IG_GET_BUS_DATA 20
  398. #define IG_SET_BUS_DATA 21
  399. #define IG_DUMP_SYMBOL_INFO 22
  400. #define IG_LOWMEM_CHECK 23
  401. #define IG_SEARCH_MEMORY 24
  402. #define IG_GET_CURRENT_THREAD 25
  403. #define IG_GET_CURRENT_PROCESS 26
  404. #define IG_GET_TYPE_SIZE 27
  405. #define IG_GET_CURRENT_PROCESS_HANDLE 28
  406. #define IG_GET_INPUT_LINE 29
  407. #define IG_GET_EXPRESSION_EX 30
  408. #define IG_TRANSLATE_VIRTUAL_TO_PHYSICAL 31
  409. #define IG_GET_CACHE_SIZE 32
  410. #define IG_READ_PHYSICAL_WITH_FLAGS 33
  411. #define IG_WRITE_PHYSICAL_WITH_FLAGS 34
  412. #define IG_GET_TEB_ADDRESS 128
  413. #define IG_GET_PEB_ADDRESS 129
  414. typedef struct _PROCESSORINFO {
  415. USHORT Processor; // current processor
  416. USHORT NumberProcessors; // total number of processors
  417. } PROCESSORINFO, *PPROCESSORINFO;
  418. typedef struct _READCONTROLSPACE {
  419. USHORT Processor;
  420. ULONG Address;
  421. ULONG BufLen;
  422. UCHAR Buf[1];
  423. } READCONTROLSPACE, *PREADCONTROLSPACE;
  424. typedef struct _READCONTROLSPACE32 {
  425. USHORT Processor;
  426. ULONG Address;
  427. ULONG BufLen;
  428. UCHAR Buf[1];
  429. } READCONTROLSPACE32, *PREADCONTROLSPACE32;
  430. typedef struct _READCONTROLSPACE64 {
  431. USHORT Processor;
  432. ULONG64 Address;
  433. ULONG BufLen;
  434. UCHAR Buf[1];
  435. } READCONTROLSPACE64, *PREADCONTROLSPACE64;
  436. typedef struct _IOSPACE {
  437. ULONG Address;
  438. ULONG Length; // 1, 2, or 4 bytes
  439. ULONG Data;
  440. } IOSPACE, *PIOSPACE;
  441. typedef struct _IOSPACE32 {
  442. ULONG Address;
  443. ULONG Length; // 1, 2, or 4 bytes
  444. ULONG Data;
  445. } IOSPACE32, *PIOSPACE32;
  446. typedef struct _IOSPACE64 {
  447. ULONG64 Address;
  448. ULONG Length; // 1, 2, or 4 bytes
  449. ULONG Data;
  450. } IOSPACE64, *PIOSPACE64;
  451. typedef struct _IOSPACE_EX {
  452. ULONG Address;
  453. ULONG Length; // 1, 2, or 4 bytes
  454. ULONG Data;
  455. ULONG InterfaceType;
  456. ULONG BusNumber;
  457. ULONG AddressSpace;
  458. } IOSPACE_EX, *PIOSPACE_EX;
  459. typedef struct _IOSPACE_EX32 {
  460. ULONG Address;
  461. ULONG Length; // 1, 2, or 4 bytes
  462. ULONG Data;
  463. ULONG InterfaceType;
  464. ULONG BusNumber;
  465. ULONG AddressSpace;
  466. } IOSPACE_EX32, *PIOSPACE_EX32;
  467. typedef struct _IOSPACE_EX64 {
  468. ULONG64 Address;
  469. ULONG Length; // 1, 2, or 4 bytes
  470. ULONG Data;
  471. ULONG InterfaceType;
  472. ULONG BusNumber;
  473. ULONG AddressSpace;
  474. } IOSPACE_EX64, *PIOSPACE_EX64;
  475. typedef struct _GETSETBUSDATA {
  476. ULONG BusDataType;
  477. ULONG BusNumber;
  478. ULONG SlotNumber;
  479. PVOID Buffer;
  480. ULONG Offset;
  481. ULONG Length;
  482. } BUSDATA, *PBUSDATA;
  483. typedef struct _SEARCHMEMORY {
  484. ULONG64 SearchAddress;
  485. ULONG64 SearchLength;
  486. ULONG64 FoundAddress;
  487. ULONG PatternLength;
  488. PVOID Pattern;
  489. } SEARCHMEMORY, *PSEARCHMEMORY;
  490. typedef struct _PHYSICAL {
  491. ULONGLONG Address;
  492. ULONG BufLen;
  493. UCHAR Buf[1];
  494. } PHYSICAL, *PPHYSICAL;
  495. #define PHYS_FLAG_DEFAULT 0
  496. #define PHYS_FLAG_CACHED 1
  497. #define PHYS_FLAG_UNCACHED 2
  498. #define PHYS_FLAG_WRITE_COMBINED 3
  499. typedef struct _PHYSICAL_WITH_FLAGS {
  500. ULONGLONG Address;
  501. ULONG BufLen;
  502. ULONG Flags;
  503. UCHAR Buf[1];
  504. } PHYSICAL_WITH_FLAGS, *PPHYSICAL_WITH_FLAGS;
  505. typedef struct _READ_WRITE_MSR {
  506. ULONG Msr;
  507. LONGLONG Value;
  508. } READ_WRITE_MSR, *PREAD_WRITE_MSR;
  509. typedef struct _GET_SET_SYMPATH {
  510. PCSTR Args; // args to !reload command
  511. PSTR Result; // returns new path
  512. int Length; // Length of result buffer
  513. } GET_SET_SYMPATH, *PGET_SET_SYMPATH;
  514. typedef struct _GET_TEB_ADDRESS {
  515. ULONGLONG Address;
  516. } GET_TEB_ADDRESS, *PGET_TEB_ADDRESS;
  517. typedef struct _GET_PEB_ADDRESS {
  518. ULONG64 CurrentThread;
  519. ULONGLONG Address;
  520. } GET_PEB_ADDRESS, *PGET_PEB_ADDRESS;
  521. typedef struct _GET_CURRENT_THREAD_ADDRESS {
  522. ULONG Processor;
  523. ULONG64 Address;
  524. } GET_CURRENT_THREAD_ADDRESS, *PGET_CURRENT_THREAD_ADDRESS;
  525. typedef struct _GET_CURRENT_PROCESS_ADDRESS {
  526. ULONG Processor;
  527. ULONG64 CurrentThread;
  528. ULONG64 Address;
  529. } GET_CURRENT_PROCESS_ADDRESS, *PGET_CURRENT_PROCESS_ADDRESS;
  530. typedef struct _GET_INPUT_LINE {
  531. PCSTR Prompt;
  532. PSTR Buffer;
  533. ULONG BufferSize;
  534. ULONG InputSize;
  535. } GET_INPUT_LINE, *PGET_INPUT_LINE;
  536. typedef struct _GET_EXPRESSION_EX {
  537. PCSTR Expression;
  538. PCSTR Remainder;
  539. ULONG64 Value;
  540. } GET_EXPRESSION_EX, *PGET_EXPRESSION_EX;
  541. typedef struct _TRANSLATE_VIRTUAL_TO_PHYSICAL {
  542. ULONG64 Virtual;
  543. ULONG64 Physical;
  544. } TRANSLATE_VIRTUAL_TO_PHYSICAL, *PTRANSLATE_VIRTUAL_TO_PHYSICAL;
  545. //
  546. // If DBGKD_VERS_FLAG_DATA is set in Flags, info should be retrieved from
  547. // the KDDEBUGGER_DATA block rather than from the DBGKD_GET_VERSION
  548. // packet. The data will remain in the version packet for a while to
  549. // reduce compatibility problems.
  550. //
  551. #define DBGKD_VERS_FLAG_MP 0x0001 // kernel is MP built
  552. #define DBGKD_VERS_FLAG_DATA 0x0002 // DebuggerDataList is valid
  553. #define DBGKD_VERS_FLAG_PTR64 0x0004 // native pointers are 64 bits
  554. #define DBGKD_VERS_FLAG_NOMM 0x0008 // No MM - don't decode PTEs
  555. #define DBGKD_VERS_FLAG_HSS 0x0010 // hardware stepping support
  556. #define KDBG_TAG 'GBDK'
  557. // **********************************************************************
  558. // DO NOT CHANGE THESE 32 BIT STRUCTURES!
  559. // ONLY MAKE CHAGES TO THE 64 BIT VERSION BELOW!!
  560. // **********************************************************************
  561. //
  562. // The following structure has changed in more than pointer size.
  563. //
  564. // This is the version packet for pre-NT5 Beta 2 systems.
  565. // For now, it is also still used on x86
  566. //
  567. typedef struct _DBGKD_GET_VERSION32 {
  568. USHORT MajorVersion;
  569. USHORT MinorVersion;
  570. USHORT ProtocolVersion;
  571. USHORT Flags;
  572. ULONG KernBase;
  573. ULONG PsLoadedModuleList;
  574. USHORT MachineType;
  575. //
  576. // help for walking stacks with user callbacks:
  577. //
  578. //
  579. // The address of the thread structure is provided in the
  580. // WAIT_STATE_CHANGE packet. This is the offset from the base of
  581. // the thread structure to the pointer to the kernel stack frame
  582. // for the currently active usermode callback.
  583. //
  584. USHORT ThCallbackStack; // offset in thread data
  585. //
  586. // these values are offsets into that frame:
  587. //
  588. USHORT NextCallback; // saved pointer to next callback frame
  589. USHORT FramePointer; // saved frame pointer
  590. //
  591. // Address of the kernel callout routine.
  592. //
  593. ULONG KiCallUserMode; // kernel routine
  594. //
  595. // Address of the usermode entry point for callbacks.
  596. //
  597. ULONG KeUserCallbackDispatcher; // address in ntdll
  598. //
  599. // DbgBreakPointWithStatus is a function which takes a ULONG argument
  600. // and hits a breakpoint. This field contains the address of the
  601. // breakpoint instruction. When the debugger sees a breakpoint
  602. // at this address, it may retrieve the argument from the first
  603. // argument register, or on x86 the eax register.
  604. //
  605. ULONG BreakpointWithStatus; // address of breakpoint
  606. //
  607. // Components may register a debug data block for use by
  608. // debugger extensions. This is the address of the list head.
  609. //
  610. ULONG DebuggerDataList;
  611. } DBGKD_GET_VERSION32, *PDBGKD_GET_VERSION32;
  612. //
  613. // This is the debugger data packet for pre NT5 Beta 2 systems.
  614. // For now, it is still used on x86
  615. //
  616. typedef struct _DBGKD_DEBUG_DATA_HEADER32 {
  617. LIST_ENTRY32 List;
  618. ULONG OwnerTag;
  619. ULONG Size;
  620. } DBGKD_DEBUG_DATA_HEADER32, *PDBGKD_DEBUG_DATA_HEADER32;
  621. typedef struct _KDDEBUGGER_DATA32 {
  622. DBGKD_DEBUG_DATA_HEADER32 Header;
  623. ULONG KernBase;
  624. ULONG BreakpointWithStatus; // address of breakpoint
  625. ULONG SavedContext;
  626. USHORT ThCallbackStack; // offset in thread data
  627. USHORT NextCallback; // saved pointer to next callback frame
  628. USHORT FramePointer; // saved frame pointer
  629. USHORT PaeEnabled:1;
  630. ULONG KiCallUserMode; // kernel routine
  631. ULONG KeUserCallbackDispatcher; // address in ntdll
  632. ULONG PsLoadedModuleList;
  633. ULONG PsActiveProcessHead;
  634. ULONG PspCidTable;
  635. ULONG ExpSystemResourcesList;
  636. ULONG ExpPagedPoolDescriptor;
  637. ULONG ExpNumberOfPagedPools;
  638. ULONG KeTimeIncrement;
  639. ULONG KeBugCheckCallbackListHead;
  640. ULONG KiBugcheckData;
  641. ULONG IopErrorLogListHead;
  642. ULONG ObpRootDirectoryObject;
  643. ULONG ObpTypeObjectType;
  644. ULONG MmSystemCacheStart;
  645. ULONG MmSystemCacheEnd;
  646. ULONG MmSystemCacheWs;
  647. ULONG MmPfnDatabase;
  648. ULONG MmSystemPtesStart;
  649. ULONG MmSystemPtesEnd;
  650. ULONG MmSubsectionBase;
  651. ULONG MmNumberOfPagingFiles;
  652. ULONG MmLowestPhysicalPage;
  653. ULONG MmHighestPhysicalPage;
  654. ULONG MmNumberOfPhysicalPages;
  655. ULONG MmMaximumNonPagedPoolInBytes;
  656. ULONG MmNonPagedSystemStart;
  657. ULONG MmNonPagedPoolStart;
  658. ULONG MmNonPagedPoolEnd;
  659. ULONG MmPagedPoolStart;
  660. ULONG MmPagedPoolEnd;
  661. ULONG MmPagedPoolInformation;
  662. ULONG MmPageSize;
  663. ULONG MmSizeOfPagedPoolInBytes;
  664. ULONG MmTotalCommitLimit;
  665. ULONG MmTotalCommittedPages;
  666. ULONG MmSharedCommit;
  667. ULONG MmDriverCommit;
  668. ULONG MmProcessCommit;
  669. ULONG MmPagedPoolCommit;
  670. ULONG MmExtendedCommit;
  671. ULONG MmZeroedPageListHead;
  672. ULONG MmFreePageListHead;
  673. ULONG MmStandbyPageListHead;
  674. ULONG MmModifiedPageListHead;
  675. ULONG MmModifiedNoWritePageListHead;
  676. ULONG MmAvailablePages;
  677. ULONG MmResidentAvailablePages;
  678. ULONG PoolTrackTable;
  679. ULONG NonPagedPoolDescriptor;
  680. ULONG MmHighestUserAddress;
  681. ULONG MmSystemRangeStart;
  682. ULONG MmUserProbeAddress;
  683. ULONG KdPrintCircularBuffer;
  684. ULONG KdPrintCircularBufferEnd;
  685. ULONG KdPrintWritePointer;
  686. ULONG KdPrintRolloverCount;
  687. ULONG MmLoadedUserImageList;
  688. } KDDEBUGGER_DATA32, *PKDDEBUGGER_DATA32;
  689. // **********************************************************************
  690. //
  691. // DO NOT CHANGE KDDEBUGGER_DATA32!!
  692. // ONLY MAKE CHANGES TO KDDEBUGGER_DATA64!!!
  693. //
  694. // **********************************************************************
  695. enum
  696. {
  697. DBGKD_SIMULATION_NONE,
  698. DBGKD_SIMULATION_EXDI
  699. };
  700. typedef struct _DBGKD_GET_VERSION64 {
  701. USHORT MajorVersion;
  702. USHORT MinorVersion;
  703. USHORT ProtocolVersion;
  704. USHORT Flags;
  705. USHORT MachineType;
  706. //
  707. // Protocol command support descriptions.
  708. // These allow the debugger to automatically
  709. // adapt to different levels of command support
  710. // in different kernels.
  711. //
  712. // One beyond highest packet type understood, zero based.
  713. UCHAR MaxPacketType;
  714. // One beyond highest state change understood, zero based.
  715. UCHAR MaxStateChange;
  716. // One beyond highest state manipulate message understood, zero based.
  717. UCHAR MaxManipulate;
  718. // Kind of execution environment the kernel is running in,
  719. // such as a real machine or a simulator. Written back
  720. // by the simulation if one exists.
  721. UCHAR Simulation;
  722. USHORT Unused[1];
  723. ULONG64 KernBase;
  724. ULONG64 PsLoadedModuleList;
  725. //
  726. // Components may register a debug data block for use by
  727. // debugger extensions. This is the address of the list head.
  728. //
  729. // There will always be an entry for the debugger.
  730. //
  731. ULONG64 DebuggerDataList;
  732. } DBGKD_GET_VERSION64, *PDBGKD_GET_VERSION64;
  733. //
  734. // This structure is used by the debugger for all targets
  735. // It is the same size as DBGKD_DATA_HEADER on all systems
  736. //
  737. typedef struct _DBGKD_DEBUG_DATA_HEADER64 {
  738. //
  739. // Link to other blocks
  740. //
  741. LIST_ENTRY64 List;
  742. //
  743. // This is a unique tag to identify the owner of the block.
  744. // If your component only uses one pool tag, use it for this, too.
  745. //
  746. ULONG OwnerTag;
  747. //
  748. // This must be initialized to the size of the data block,
  749. // including this structure.
  750. //
  751. ULONG Size;
  752. } DBGKD_DEBUG_DATA_HEADER64, *PDBGKD_DEBUG_DATA_HEADER64;
  753. //
  754. // This structure is the same size on all systems. The only field
  755. // which must be translated by the debugger is Header.List.
  756. //
  757. //
  758. // DO NOT ADD OR REMOVE FIELDS FROM THE MIDDLE OF THIS STRUCTURE!!!
  759. //
  760. // If you remove a field, replace it with an "unused" placeholder.
  761. // Do not reuse fields until there has been enough time for old debuggers
  762. // and extensions to age out.
  763. //
  764. typedef struct _KDDEBUGGER_DATA64 {
  765. DBGKD_DEBUG_DATA_HEADER64 Header;
  766. //
  767. // Base address of kernel image
  768. //
  769. ULONG64 KernBase;
  770. //
  771. // DbgBreakPointWithStatus is a function which takes an argument
  772. // and hits a breakpoint. This field contains the address of the
  773. // breakpoint instruction. When the debugger sees a breakpoint
  774. // at this address, it may retrieve the argument from the first
  775. // argument register, or on x86 the eax register.
  776. //
  777. ULONG64 BreakpointWithStatus; // address of breakpoint
  778. //
  779. // Address of the saved context record during a bugcheck
  780. //
  781. // N.B. This is an automatic in KeBugcheckEx's frame, and
  782. // is only valid after a bugcheck.
  783. //
  784. ULONG64 SavedContext;
  785. //
  786. // help for walking stacks with user callbacks:
  787. //
  788. //
  789. // The address of the thread structure is provided in the
  790. // WAIT_STATE_CHANGE packet. This is the offset from the base of
  791. // the thread structure to the pointer to the kernel stack frame
  792. // for the currently active usermode callback.
  793. //
  794. USHORT ThCallbackStack; // offset in thread data
  795. //
  796. // these values are offsets into that frame:
  797. //
  798. USHORT NextCallback; // saved pointer to next callback frame
  799. USHORT FramePointer; // saved frame pointer
  800. //
  801. // pad to a quad boundary
  802. //
  803. USHORT PaeEnabled:1;
  804. //
  805. // Address of the kernel callout routine.
  806. //
  807. ULONG64 KiCallUserMode; // kernel routine
  808. //
  809. // Address of the usermode entry point for callbacks.
  810. //
  811. ULONG64 KeUserCallbackDispatcher; // address in ntdll
  812. //
  813. // Addresses of various kernel data structures and lists
  814. // that are of interest to the kernel debugger.
  815. //
  816. ULONG64 PsLoadedModuleList;
  817. ULONG64 PsActiveProcessHead;
  818. ULONG64 PspCidTable;
  819. ULONG64 ExpSystemResourcesList;
  820. ULONG64 ExpPagedPoolDescriptor;
  821. ULONG64 ExpNumberOfPagedPools;
  822. ULONG64 KeTimeIncrement;
  823. ULONG64 KeBugCheckCallbackListHead;
  824. ULONG64 KiBugcheckData;
  825. ULONG64 IopErrorLogListHead;
  826. ULONG64 ObpRootDirectoryObject;
  827. ULONG64 ObpTypeObjectType;
  828. ULONG64 MmSystemCacheStart;
  829. ULONG64 MmSystemCacheEnd;
  830. ULONG64 MmSystemCacheWs;
  831. ULONG64 MmPfnDatabase;
  832. ULONG64 MmSystemPtesStart;
  833. ULONG64 MmSystemPtesEnd;
  834. ULONG64 MmSubsectionBase;
  835. ULONG64 MmNumberOfPagingFiles;
  836. ULONG64 MmLowestPhysicalPage;
  837. ULONG64 MmHighestPhysicalPage;
  838. ULONG64 MmNumberOfPhysicalPages;
  839. ULONG64 MmMaximumNonPagedPoolInBytes;
  840. ULONG64 MmNonPagedSystemStart;
  841. ULONG64 MmNonPagedPoolStart;
  842. ULONG64 MmNonPagedPoolEnd;
  843. ULONG64 MmPagedPoolStart;
  844. ULONG64 MmPagedPoolEnd;
  845. ULONG64 MmPagedPoolInformation;
  846. ULONG64 MmPageSize;
  847. ULONG64 MmSizeOfPagedPoolInBytes;
  848. ULONG64 MmTotalCommitLimit;
  849. ULONG64 MmTotalCommittedPages;
  850. ULONG64 MmSharedCommit;
  851. ULONG64 MmDriverCommit;
  852. ULONG64 MmProcessCommit;
  853. ULONG64 MmPagedPoolCommit;
  854. ULONG64 MmExtendedCommit;
  855. ULONG64 MmZeroedPageListHead;
  856. ULONG64 MmFreePageListHead;
  857. ULONG64 MmStandbyPageListHead;
  858. ULONG64 MmModifiedPageListHead;
  859. ULONG64 MmModifiedNoWritePageListHead;
  860. ULONG64 MmAvailablePages;
  861. ULONG64 MmResidentAvailablePages;
  862. ULONG64 PoolTrackTable;
  863. ULONG64 NonPagedPoolDescriptor;
  864. ULONG64 MmHighestUserAddress;
  865. ULONG64 MmSystemRangeStart;
  866. ULONG64 MmUserProbeAddress;
  867. ULONG64 KdPrintCircularBuffer;
  868. ULONG64 KdPrintCircularBufferEnd;
  869. ULONG64 KdPrintWritePointer;
  870. ULONG64 KdPrintRolloverCount;
  871. ULONG64 MmLoadedUserImageList;
  872. // NT 5.1 Addition
  873. ULONG64 NtBuildLab;
  874. ULONG64 KiNormalSystemCall;
  875. // NT 5.0 QFE addition
  876. ULONG64 KiProcessorBlock;
  877. ULONG64 MmUnloadedDrivers;
  878. ULONG64 MmLastUnloadedDriver;
  879. ULONG64 MmTriageActionTaken;
  880. ULONG64 MmSpecialPoolTag;
  881. ULONG64 KernelVerifier;
  882. ULONG64 MmVerifierData;
  883. ULONG64 MmAllocatedNonPagedPool;
  884. ULONG64 MmPeakCommitment;
  885. ULONG64 MmTotalCommitLimitMaximum;
  886. ULONG64 CmNtCSDVersion;
  887. // NT 5.1 Addition
  888. ULONG64 MmPhysicalMemoryBlock;
  889. ULONG64 MmSessionBase;
  890. ULONG64 MmSessionSize;
  891. ULONG64 MmSystemParentTablePage;
  892. } KDDEBUGGER_DATA64, *PKDDEBUGGER_DATA64;
  893. /************************************
  894. Type Dump Ioctl
  895. *************************************/
  896. //
  897. // Fields are not indented if this is set
  898. //
  899. #define DBG_DUMP_NO_INDENT 0x00000001
  900. //
  901. // Offsets are not printed if this is set
  902. //
  903. #define DBG_DUMP_NO_OFFSET 0x00000002
  904. //
  905. // Verbose output
  906. //
  907. #define DBG_DUMP_VERBOSE 0x00000004
  908. //
  909. // Callback is done for each of fields
  910. //
  911. #define DBG_DUMP_CALL_FOR_EACH 0x00000008
  912. //
  913. // A list of type is dumped, listLink should have info about next element pointer
  914. //
  915. #define DBG_DUMP_LIST 0x00000020
  916. //
  917. // Nothing is printed if this is set (only callbacks and data copies done)
  918. //
  919. #define DBG_DUMP_NO_PRINT 0x00000040
  920. //
  921. // Ioctl returns the size as usual, but will not do field prints/callbacks if this is set
  922. //
  923. #define DBG_DUMP_GET_SIZE_ONLY 0x00000080
  924. //
  925. // Specifies how much deep into structs we can go
  926. //
  927. #define DBG_DUMP_RECUR_LEVEL(l) ((l & 0xf) << 8)
  928. //
  929. // No newlines are printed after each field
  930. //
  931. #define DBG_DUMP_COMPACT_OUT 0x00002000
  932. //
  933. // An array of type is dumped, number of elements can be specified in listLink->size
  934. //
  935. #define DBG_DUMP_ARRAY 0x00008000
  936. //
  937. // The specified addr value is actually the address of field listLink->fName
  938. //
  939. #define DBG_DUMP_ADDRESS_OF_FIELD 0x00010000
  940. //
  941. // The specified addr value is actually the adress at the end of type
  942. //
  943. #define DBG_DUMP_ADDRESS_AT_END 0x00020000
  944. //
  945. // This could be used to copy only the primitive types like ULONG, PVOID etc.
  946. // - will not work with structures/unions
  947. //
  948. #define DBG_DUMP_COPY_TYPE_DATA 0x00040000
  949. //
  950. // Flag to allow read directly from physical memory
  951. //
  952. #define DBG_DUMP_READ_PHYSICAL 0x00080000
  953. //
  954. // This causes a function type to be dumped in format function(arg1, arg2, ...)
  955. //
  956. #define DBG_DUMP_FUNCTION_FORMAT 0x00100000
  957. //
  958. // This recurses on a struct but doesn't expand pointers
  959. //
  960. #define DBG_DUMP_BLOCK_RECURSE 0x00200000
  961. //
  962. // Obsolete defs
  963. //
  964. #define DBG_RETURN_TYPE 0
  965. #define DBG_RETURN_SUBTYPES 0
  966. #define DBG_RETURN_TYPE_VALUES 0
  967. //
  968. // Dump and callback optons for fields - Options used in FIELD_INFO.fOptions
  969. //
  970. //
  971. // Callback is done before printing the field if this is set
  972. //
  973. #define DBG_DUMP_FIELD_CALL_BEFORE_PRINT 0x00000001
  974. //
  975. // No callback is done
  976. //
  977. #define DBG_DUMP_FIELD_NO_CALLBACK_REQ 0x00000002
  978. //
  979. // Subfields of the fields are processesed
  980. //
  981. #define DBG_DUMP_FIELD_RECUR_ON_THIS 0x00000004
  982. //
  983. // fName must match completely for the field to be dumped instead just a prefix
  984. // match by default
  985. //
  986. #define DBG_DUMP_FIELD_FULL_NAME 0x00000008
  987. //
  988. // This causes array elements of an array field to be printed
  989. //
  990. #define DBG_DUMP_FIELD_ARRAY 0x00000010
  991. //
  992. // The data of the field is copied into fieldCallBack
  993. //
  994. #define DBG_DUMP_FIELD_COPY_FIELD_DATA 0x00000020
  995. //
  996. // In callback or when Ioctl returns, the FIELD_INFO.address has the address of field.
  997. // If no address is supplied for the type, it contains total offset of the field.
  998. //
  999. #define DBG_DUMP_FIELD_RETURN_ADDRESS 0x00001000
  1000. //
  1001. // Return the offset and size in bits instead of bytes is case of Bitfield
  1002. //
  1003. #define DBG_DUMP_FIELD_SIZE_IN_BITS 0x00002000
  1004. //
  1005. // Nothing is printed for field if this is set (only callbacks and data copies done)
  1006. //
  1007. #define DBG_DUMP_FIELD_NO_PRINT 0x00004000
  1008. //
  1009. // If the field is a pointer, it is dumped as a string, ANSI, WCHAR, MULTI or GUID
  1010. // depending on following options
  1011. //
  1012. #define DBG_DUMP_FIELD_DEFAULT_STRING 0x00010000
  1013. #define DBG_DUMP_FIELD_WCHAR_STRING 0x00020000
  1014. #define DBG_DUMP_FIELD_MULTI_STRING 0x00040000
  1015. #define DBG_DUMP_FIELD_GUID_STRING 0x00080000
  1016. //
  1017. // Error status returned on TYPE DUMP Ioctl failure
  1018. //
  1019. #define MEMORY_READ_ERROR 0x01
  1020. #define SYMBOL_TYPE_INDEX_NOT_FOUND 0x02
  1021. #define SYMBOL_TYPE_INFO_NOT_FOUND 0x03
  1022. #define FIELDS_DID_NOT_MATCH 0x04
  1023. #define NULL_SYM_DUMP_PARAM 0x05
  1024. #define NULL_FIELD_NAME 0x06
  1025. #define INCORRECT_VERSION_INFO 0x07
  1026. #define EXIT_ON_CONTROLC 0x08
  1027. #define CANNOT_ALLOCATE_MEMORY 0x09
  1028. #define INSUFFICIENT_SPACE_TO_COPY 0x0a
  1029. //////////////////////////////////////////////////////////////////////////*/
  1030. typedef
  1031. ULONG
  1032. (WDBGAPI*PSYM_DUMP_FIELD_CALLBACK)(
  1033. struct _FIELD_INFO *pField,
  1034. PVOID UserContext
  1035. );
  1036. typedef struct _FIELD_INFO {
  1037. PUCHAR fName; // Name of the field
  1038. PUCHAR printName; // Name to be printed at dump
  1039. ULONG size; // Size of the field
  1040. ULONG fOptions; // Dump Options for the field
  1041. ULONG64 address; // address of the field
  1042. PVOID fieldCallBack; // Return info or callBack routine for the field
  1043. } FIELD_INFO, *PFIELD_INFO;
  1044. typedef struct _SYM_DUMP_PARAM {
  1045. ULONG size; // size of this struct
  1046. PUCHAR sName; // type name
  1047. ULONG Options; // Dump options
  1048. ULONG64 addr; // Address to take data for type
  1049. PFIELD_INFO listLink; // fName here would be used to do list dump
  1050. PVOID Context; // Usercontext passed to CallbackRoutine
  1051. PSYM_DUMP_FIELD_CALLBACK CallbackRoutine;
  1052. // Routine called back
  1053. ULONG nFields; // # elements in Fields
  1054. PFIELD_INFO Fields; // Used to return information about field
  1055. } SYM_DUMP_PARAM, *PSYM_DUMP_PARAM;
  1056. #ifdef __cplusplus
  1057. #define CPPMOD extern "C"
  1058. #else
  1059. #define CPPMOD
  1060. #endif
  1061. #ifndef NOEXTAPI
  1062. #if defined(KDEXT_64BIT)
  1063. #define WINDBG_EXTENSION_APIS WINDBG_EXTENSION_APIS64
  1064. #define PWINDBG_EXTENSION_APIS PWINDBG_EXTENSION_APIS64
  1065. #define DECLARE_API(s) DECLARE_API64(s)
  1066. #elif defined(KDEXT_32BIT)
  1067. #define WINDBG_EXTENSION_APIS WINDBG_EXTENSION_APIS32
  1068. #define PWINDBG_EXTENSION_APIS PWINDBG_EXTENSION_APIS32
  1069. #define DECLARE_API(s) DECLARE_API32(s)
  1070. #else
  1071. #define DECLARE_API(s) \
  1072. CPPMOD VOID \
  1073. s( \
  1074. HANDLE hCurrentProcess, \
  1075. HANDLE hCurrentThread, \
  1076. ULONG dwCurrentPc, \
  1077. ULONG dwProcessor, \
  1078. PCSTR args \
  1079. )
  1080. #endif
  1081. #define DECLARE_API32(s) \
  1082. CPPMOD VOID \
  1083. s( \
  1084. HANDLE hCurrentProcess, \
  1085. HANDLE hCurrentThread, \
  1086. ULONG dwCurrentPc, \
  1087. ULONG dwProcessor, \
  1088. PCSTR args \
  1089. )
  1090. #define DECLARE_API64(s) \
  1091. CPPMOD VOID \
  1092. s( \
  1093. HANDLE hCurrentProcess, \
  1094. HANDLE hCurrentThread, \
  1095. ULONG64 dwCurrentPc, \
  1096. ULONG dwProcessor, \
  1097. PCSTR args \
  1098. )
  1099. extern WINDBG_EXTENSION_APIS ExtensionApis;
  1100. #define dprintf (ExtensionApis.lpOutputRoutine)
  1101. #define GetExpression (ExtensionApis.lpGetExpressionRoutine)
  1102. #define CheckControlC (ExtensionApis.lpCheckControlCRoutine)
  1103. #define GetContext (ExtensionApis.lpGetThreadContextRoutine)
  1104. #define SetContext (ExtensionApis.lpSetThreadContextRoutine)
  1105. #define Ioctl (ExtensionApis.lpIoctlRoutine)
  1106. #define Disasm (ExtensionApis.lpDisasmRoutine)
  1107. #define GetSymbol (ExtensionApis.lpGetSymbolRoutine)
  1108. #define ReadMemory (ExtensionApis.lpReadProcessMemoryRoutine)
  1109. #define WriteMemory (ExtensionApis.lpWriteProcessMemoryRoutine)
  1110. #define StackTrace (ExtensionApis.lpStackTraceRoutine)
  1111. #define GetKdContext(ppi) \
  1112. Ioctl( IG_KD_CONTEXT, (PVOID)ppi, sizeof(*ppi) )
  1113. //
  1114. // BOOL
  1115. // GetDebuggerData(
  1116. // ULONG Tag,
  1117. // PVOID Buf,
  1118. // ULONG Size
  1119. // )
  1120. //
  1121. #define GetDebuggerData(TAG, BUF, SIZE) \
  1122. ( (((PDBGKD_DEBUG_DATA_HEADER64)(BUF))->OwnerTag = (TAG)), \
  1123. (((PDBGKD_DEBUG_DATA_HEADER64)(BUF))->Size = (SIZE)), \
  1124. Ioctl( IG_GET_DEBUGGER_DATA, (PVOID)(BUF), (SIZE) ) )
  1125. // Check if LocalAlloc is prototyped
  1126. //#ifdef _WINBASE_
  1127. __inline VOID
  1128. ReadPhysical(
  1129. ULONG64 address,
  1130. PVOID buf,
  1131. ULONG size,
  1132. PULONG sizer
  1133. )
  1134. {
  1135. PPHYSICAL phy;
  1136. *sizer = 0;
  1137. phy = (PPHYSICAL)LocalAlloc(LPTR, sizeof(*phy) + size );
  1138. if (phy) {
  1139. ZeroMemory( phy->Buf, size );
  1140. phy->Address = address;
  1141. phy->BufLen = size;
  1142. Ioctl( IG_READ_PHYSICAL, (PVOID)phy, sizeof(*phy) + size );
  1143. *sizer = phy->BufLen;
  1144. CopyMemory( buf, phy->Buf, *sizer );
  1145. LocalFree( phy );
  1146. }
  1147. }
  1148. __inline VOID
  1149. WritePhysical(
  1150. ULONG64 address,
  1151. PVOID buf,
  1152. ULONG size,
  1153. PULONG sizew
  1154. )
  1155. {
  1156. PPHYSICAL phy;
  1157. *sizew = 0;
  1158. phy = (PPHYSICAL)LocalAlloc(LPTR, sizeof(*phy) + size );
  1159. if (phy) {
  1160. ZeroMemory( phy->Buf, size );
  1161. phy->Address = address;
  1162. phy->BufLen = size;
  1163. CopyMemory( phy->Buf, buf, size );
  1164. Ioctl( IG_WRITE_PHYSICAL, (PVOID)phy, sizeof(*phy) + size );
  1165. *sizew = phy->BufLen;
  1166. LocalFree( phy );
  1167. }
  1168. }
  1169. __inline VOID
  1170. ReadPhysicalWithFlags(
  1171. ULONG64 address,
  1172. PVOID buf,
  1173. ULONG size,
  1174. ULONG flags,
  1175. PULONG sizer
  1176. )
  1177. {
  1178. PPHYSICAL_WITH_FLAGS phy;
  1179. *sizer = 0;
  1180. phy = (PPHYSICAL_WITH_FLAGS)LocalAlloc(LPTR, sizeof(*phy) + size );
  1181. if (phy) {
  1182. ZeroMemory( phy->Buf, size );
  1183. phy->Address = address;
  1184. phy->BufLen = size;
  1185. phy->Flags = flags;
  1186. Ioctl( IG_READ_PHYSICAL_WITH_FLAGS, (PVOID)phy, sizeof(*phy) + size );
  1187. *sizer = phy->BufLen;
  1188. CopyMemory( buf, phy->Buf, *sizer );
  1189. LocalFree( phy );
  1190. }
  1191. }
  1192. __inline VOID
  1193. WritePhysicalWithFlags(
  1194. ULONG64 address,
  1195. PVOID buf,
  1196. ULONG size,
  1197. ULONG flags,
  1198. PULONG sizew
  1199. )
  1200. {
  1201. PPHYSICAL_WITH_FLAGS phy;
  1202. *sizew = 0;
  1203. phy = (PPHYSICAL_WITH_FLAGS)LocalAlloc(LPTR, sizeof(*phy) + size );
  1204. if (phy) {
  1205. ZeroMemory( phy->Buf, size );
  1206. phy->Address = address;
  1207. phy->BufLen = size;
  1208. phy->Flags = flags;
  1209. CopyMemory( phy->Buf, buf, size );
  1210. Ioctl( IG_WRITE_PHYSICAL_WITH_FLAGS, (PVOID)phy, sizeof(*phy) + size );
  1211. *sizew = phy->BufLen;
  1212. LocalFree( phy );
  1213. }
  1214. }
  1215. __inline VOID
  1216. ReadMsr(
  1217. ULONG MsrReg,
  1218. ULONGLONG *MsrValue
  1219. )
  1220. {
  1221. READ_WRITE_MSR msr;
  1222. msr.Msr = MsrReg;
  1223. Ioctl( IG_READ_MSR, (PVOID)&msr, sizeof(msr) );
  1224. *MsrValue = msr.Value;
  1225. }
  1226. __inline VOID
  1227. WriteMsr(
  1228. ULONG MsrReg,
  1229. ULONGLONG MsrValue
  1230. )
  1231. {
  1232. READ_WRITE_MSR msr;
  1233. msr.Msr = MsrReg;
  1234. msr.Value = MsrValue;
  1235. Ioctl( IG_WRITE_MSR, (PVOID)&msr, sizeof(msr) );
  1236. }
  1237. __inline VOID
  1238. SetThreadForOperation(
  1239. ULONG_PTR * Thread
  1240. )
  1241. {
  1242. Ioctl(IG_SET_THREAD, (PVOID)Thread, sizeof(PULONG));
  1243. }
  1244. __inline VOID
  1245. SetThreadForOperation32(
  1246. ULONG Thread
  1247. )
  1248. {
  1249. Ioctl(IG_SET_THREAD, (PVOID)LongToPtr(Thread), sizeof(ULONG));
  1250. }
  1251. __inline VOID
  1252. SetThreadForOperation64(
  1253. PULONG64 Thread
  1254. )
  1255. {
  1256. Ioctl(IG_SET_THREAD, (PVOID)Thread, sizeof(ULONG64));
  1257. }
  1258. __inline VOID
  1259. ReadControlSpace(
  1260. USHORT processor,
  1261. ULONG address,
  1262. PVOID buf,
  1263. ULONG size
  1264. )
  1265. {
  1266. PREADCONTROLSPACE prc;
  1267. prc = (PREADCONTROLSPACE)LocalAlloc(LPTR, sizeof(*prc) + size );
  1268. if (prc) {
  1269. ZeroMemory( prc->Buf, size );
  1270. prc->Processor = processor;
  1271. prc->Address = address;
  1272. prc->BufLen = size;
  1273. Ioctl( IG_READ_CONTROL_SPACE, (PVOID)prc, sizeof(*prc) + size );
  1274. CopyMemory( buf, prc->Buf, size );
  1275. LocalFree( prc );
  1276. }
  1277. }
  1278. __inline VOID
  1279. ReadControlSpace32(
  1280. USHORT processor,
  1281. ULONG address,
  1282. PVOID buf,
  1283. ULONG size
  1284. )
  1285. {
  1286. PREADCONTROLSPACE32 prc;
  1287. prc = (PREADCONTROLSPACE32)LocalAlloc(LPTR, sizeof(*prc) + size );
  1288. if (prc) {
  1289. ZeroMemory( prc->Buf, size );
  1290. prc->Processor = processor;
  1291. prc->Address = address;
  1292. prc->BufLen = size;
  1293. Ioctl( IG_READ_CONTROL_SPACE, (PVOID)prc, sizeof(*prc) + size );
  1294. CopyMemory( buf, prc->Buf, size );
  1295. LocalFree( prc );
  1296. }
  1297. }
  1298. #define ReadTypedControlSpace32( _Proc, _Addr, _Buf ) \
  1299. ReadControlSpace64( (USHORT)(_Proc), (ULONG)(_Addr), (PVOID)&(_Buf), (ULONG)sizeof(_Buf) )
  1300. __inline VOID
  1301. ReadControlSpace64(
  1302. USHORT processor,
  1303. ULONG64 address,
  1304. PVOID buf,
  1305. ULONG size
  1306. )
  1307. {
  1308. PREADCONTROLSPACE64 prc;
  1309. prc = (PREADCONTROLSPACE64)LocalAlloc(LPTR, sizeof(*prc) + size );
  1310. if (prc) {
  1311. ZeroMemory( prc->Buf, size );
  1312. prc->Processor = processor;
  1313. prc->Address = address;
  1314. prc->BufLen = size;
  1315. Ioctl( IG_READ_CONTROL_SPACE, (PVOID)prc, sizeof(*prc) + size );
  1316. CopyMemory( buf, prc->Buf, size );
  1317. LocalFree( prc );
  1318. }
  1319. }
  1320. #define ReadTypedControlSpace64( _Proc, _Addr, _Buf ) \
  1321. ReadControlSpace64( (USHORT)(_Proc), (ULONG64)(_Addr), (PVOID)&(_Buf), (ULONG)sizeof(_Buf) )
  1322. __inline VOID
  1323. WriteControlSpace(
  1324. USHORT processor,
  1325. ULONG address,
  1326. PVOID buf,
  1327. ULONG size
  1328. )
  1329. {
  1330. PREADCONTROLSPACE64 prc;
  1331. prc = (PREADCONTROLSPACE64)LocalAlloc(LPTR, sizeof(*prc) + size );
  1332. if (prc) {
  1333. ZeroMemory( prc->Buf, size );
  1334. prc->Processor = processor;
  1335. prc->Address = address;
  1336. prc->BufLen = size;
  1337. CopyMemory( prc->Buf, buf, size );
  1338. Ioctl( IG_WRITE_CONTROL_SPACE, (PVOID)prc, sizeof(*prc) + size );
  1339. LocalFree( prc );
  1340. }
  1341. }
  1342. // #endif // _WINBASE_
  1343. __inline VOID
  1344. ReadIoSpace(
  1345. ULONG address,
  1346. PULONG data,
  1347. PULONG size
  1348. )
  1349. {
  1350. IOSPACE is;
  1351. is.Address = address;
  1352. is.Length = *size;
  1353. Ioctl( IG_READ_IO_SPACE, (PVOID)&is, sizeof(is) );
  1354. memcpy(data, &is.Data, is.Length);
  1355. *size = is.Length;
  1356. }
  1357. __inline VOID
  1358. ReadIoSpace32(
  1359. ULONG address,
  1360. PULONG data,
  1361. PULONG size
  1362. )
  1363. {
  1364. IOSPACE32 is;
  1365. is.Address = address;
  1366. is.Length = *size;
  1367. Ioctl( IG_READ_IO_SPACE, (PVOID)&is, sizeof(is) );
  1368. memcpy(data, &is.Data, is.Length);
  1369. *size = is.Length;
  1370. }
  1371. __inline VOID
  1372. ReadIoSpace64(
  1373. ULONG64 address,
  1374. PULONG data,
  1375. PULONG size
  1376. )
  1377. {
  1378. IOSPACE64 is;
  1379. is.Address = address;
  1380. is.Length = *size;
  1381. Ioctl( IG_READ_IO_SPACE, (PVOID)&is, sizeof(is) );
  1382. memcpy(data, &is.Data, is.Length);
  1383. *size = is.Length;
  1384. }
  1385. __inline VOID
  1386. WriteIoSpace(
  1387. ULONG address,
  1388. ULONG data,
  1389. PULONG size
  1390. )
  1391. {
  1392. IOSPACE is;
  1393. is.Address = (ULONG)address;
  1394. is.Length = *size;
  1395. is.Data = data;
  1396. Ioctl( IG_WRITE_IO_SPACE, (PVOID)&is, sizeof(is) );
  1397. *size = is.Length;
  1398. }
  1399. __inline VOID
  1400. WriteIoSpace32(
  1401. ULONG address,
  1402. ULONG data,
  1403. PULONG size
  1404. )
  1405. {
  1406. IOSPACE32 is;
  1407. is.Address = address;
  1408. is.Length = *size;
  1409. is.Data = data;
  1410. Ioctl( IG_WRITE_IO_SPACE, (PVOID)&is, sizeof(is) );
  1411. *size = is.Length;
  1412. }
  1413. __inline VOID
  1414. WriteIoSpace64(
  1415. ULONG64 address,
  1416. ULONG data,
  1417. PULONG size
  1418. )
  1419. {
  1420. IOSPACE64 is;
  1421. is.Address = address;
  1422. is.Length = *size;
  1423. is.Data = data;
  1424. Ioctl( IG_WRITE_IO_SPACE, (PVOID)&is, sizeof(is) );
  1425. *size = is.Length;
  1426. }
  1427. __inline VOID
  1428. ReadIoSpaceEx(
  1429. ULONG address,
  1430. PULONG data,
  1431. PULONG size,
  1432. ULONG interfacetype,
  1433. ULONG busnumber,
  1434. ULONG addressspace
  1435. )
  1436. {
  1437. IOSPACE_EX is;
  1438. is.Address = (ULONG)address;
  1439. is.Length = *size;
  1440. is.Data = 0;
  1441. is.InterfaceType = interfacetype;
  1442. is.BusNumber = busnumber;
  1443. is.AddressSpace = addressspace;
  1444. Ioctl( IG_READ_IO_SPACE_EX, (PVOID)&is, sizeof(is) );
  1445. *data = is.Data;
  1446. *size = is.Length;
  1447. }
  1448. __inline VOID
  1449. ReadIoSpaceEx32(
  1450. ULONG address,
  1451. PULONG data,
  1452. PULONG size,
  1453. ULONG interfacetype,
  1454. ULONG busnumber,
  1455. ULONG addressspace
  1456. )
  1457. {
  1458. IOSPACE_EX32 is;
  1459. is.Address = address;
  1460. is.Length = *size;
  1461. is.Data = 0;
  1462. is.InterfaceType = interfacetype;
  1463. is.BusNumber = busnumber;
  1464. is.AddressSpace = addressspace;
  1465. Ioctl( IG_READ_IO_SPACE_EX, (PVOID)&is, sizeof(is) );
  1466. *data = is.Data;
  1467. *size = is.Length;
  1468. }
  1469. __inline VOID
  1470. ReadIoSpaceEx64(
  1471. ULONG64 address,
  1472. PULONG data,
  1473. PULONG size,
  1474. ULONG interfacetype,
  1475. ULONG busnumber,
  1476. ULONG addressspace
  1477. )
  1478. {
  1479. IOSPACE_EX64 is;
  1480. is.Address = address;
  1481. is.Length = *size;
  1482. is.Data = 0;
  1483. is.InterfaceType = interfacetype;
  1484. is.BusNumber = busnumber;
  1485. is.AddressSpace = addressspace;
  1486. Ioctl( IG_READ_IO_SPACE_EX, (PVOID)&is, sizeof(is) );
  1487. *data = is.Data;
  1488. *size = is.Length;
  1489. }
  1490. __inline VOID
  1491. WriteIoSpaceEx(
  1492. ULONG address,
  1493. ULONG data,
  1494. PULONG size,
  1495. ULONG interfacetype,
  1496. ULONG busnumber,
  1497. ULONG addressspace
  1498. )
  1499. {
  1500. IOSPACE_EX is;
  1501. is.Address = (ULONG)address;
  1502. is.Length = *size;
  1503. is.Data = data;
  1504. is.InterfaceType = interfacetype;
  1505. is.BusNumber = busnumber;
  1506. is.AddressSpace = addressspace;
  1507. Ioctl( IG_WRITE_IO_SPACE_EX, (PVOID)&is, sizeof(is) );
  1508. *size = is.Length;
  1509. }
  1510. __inline VOID
  1511. WriteIoSpaceEx32(
  1512. ULONG address,
  1513. ULONG data,
  1514. PULONG size,
  1515. ULONG interfacetype,
  1516. ULONG busnumber,
  1517. ULONG addressspace
  1518. )
  1519. {
  1520. IOSPACE_EX32 is;
  1521. is.Address = address;
  1522. is.Length = *size;
  1523. is.Data = data;
  1524. is.InterfaceType = interfacetype;
  1525. is.BusNumber = busnumber;
  1526. is.AddressSpace = addressspace;
  1527. Ioctl( IG_WRITE_IO_SPACE_EX, (PVOID)&is, sizeof(is) );
  1528. *size = is.Length;
  1529. }
  1530. __inline VOID
  1531. WriteIoSpaceEx64(
  1532. ULONG64 address,
  1533. ULONG data,
  1534. PULONG size,
  1535. ULONG interfacetype,
  1536. ULONG busnumber,
  1537. ULONG addressspace
  1538. )
  1539. {
  1540. IOSPACE_EX64 is;
  1541. is.Address = address;
  1542. is.Length = *size;
  1543. is.Data = data;
  1544. is.InterfaceType = interfacetype;
  1545. is.BusNumber = busnumber;
  1546. is.AddressSpace = addressspace;
  1547. Ioctl( IG_WRITE_IO_SPACE_EX, (PVOID)&is, sizeof(is) );
  1548. *size = is.Length;
  1549. }
  1550. __inline VOID
  1551. ReloadSymbols(
  1552. IN PSTR Arg OPTIONAL
  1553. )
  1554. /*++
  1555. Routine Description:
  1556. Calls the debugger to reload symbols.
  1557. Arguments:
  1558. Args - Supplies the tail of a !reload command string.
  1559. !reload [flags] [module[=address]]
  1560. flags: /n do not load from usermode list
  1561. /u unload symbols, no reload
  1562. /v verbose
  1563. A value of NULL is equivalent to an empty string
  1564. Return Value:
  1565. None
  1566. --*/
  1567. {
  1568. Ioctl(IG_RELOAD_SYMBOLS, (PVOID)Arg, Arg?((ULONG)strlen(Arg)+1):0);
  1569. }
  1570. __inline VOID
  1571. GetSetSympath(
  1572. IN PSTR Arg,
  1573. OUT PSTR Result OPTIONAL,
  1574. IN int Length
  1575. )
  1576. /*++
  1577. Routine Description:
  1578. Calls the debugger to set or retrieve symbol search path.
  1579. Arguments:
  1580. Arg - Supplies new search path. If Arg is NULL or string is empty,
  1581. the search path is not changed and the current setting is
  1582. returned in Result. When the symbol search path is changed,
  1583. a call to ReloadSymbols is made implicitly.
  1584. Result - OPTIONAL Returns the symbol search path setting.
  1585. Length - Supplies the size of the buffer supplied by Result.
  1586. Return Value:
  1587. None
  1588. --*/
  1589. {
  1590. GET_SET_SYMPATH gss;
  1591. gss.Args = Arg;
  1592. gss.Result = Result;
  1593. gss.Length = Length;
  1594. Ioctl(IG_GET_SET_SYMPATH, (PVOID)&gss, sizeof(gss));
  1595. }
  1596. #if defined(KDEXT_64BIT)
  1597. __inline
  1598. ULONG
  1599. IsPtr64(
  1600. void
  1601. )
  1602. {
  1603. static ULONG flag = (ULONG)-1;
  1604. ULONG dw;
  1605. if (flag == (ULONG)-1) {
  1606. if (Ioctl(IG_IS_PTR64, &dw, sizeof(dw))) {
  1607. flag = ((dw != 0) ? 1 : 0);
  1608. } else {
  1609. flag = 0;
  1610. }
  1611. }
  1612. return flag;
  1613. }
  1614. __inline
  1615. ULONG
  1616. ReadListEntry(
  1617. ULONG64 Address,
  1618. PLIST_ENTRY64 List
  1619. )
  1620. {
  1621. ULONG cb;
  1622. if (IsPtr64()) {
  1623. return (ReadMemory(Address, (PVOID)List, sizeof(*List), &cb) && cb == sizeof(*List));
  1624. } else {
  1625. LIST_ENTRY32 List32;
  1626. ULONG Status;
  1627. Status = ReadMemory(Address,
  1628. (PVOID)&List32,
  1629. sizeof(List32),
  1630. &cb);
  1631. if (Status && cb == sizeof(List32)) {
  1632. List->Flink = (ULONG64)(LONG64)(LONG)List32.Flink;
  1633. List->Blink = (ULONG64)(LONG64)(LONG)List32.Blink;
  1634. return 1;
  1635. }
  1636. return 0;
  1637. }
  1638. }
  1639. __inline
  1640. ULONG
  1641. ReadPointer(
  1642. ULONG64 Address,
  1643. PULONG64 Pointer
  1644. )
  1645. {
  1646. ULONG cb;
  1647. if (IsPtr64()) {
  1648. return (ReadMemory(Address, (PVOID)Pointer, sizeof(*Pointer), &cb) && cb == sizeof(*Pointer));
  1649. } else {
  1650. ULONG Pointer32;
  1651. ULONG Status;
  1652. Status = ReadMemory(Address,
  1653. (PVOID)&Pointer32,
  1654. sizeof(Pointer32),
  1655. &cb);
  1656. if (Status && cb == sizeof(Pointer32)) {
  1657. *Pointer = (ULONG64)(LONG64)(LONG)Pointer32;
  1658. return 1;
  1659. }
  1660. return 0;
  1661. }
  1662. }
  1663. __inline
  1664. ULONG
  1665. WritePointer(
  1666. ULONG64 Address,
  1667. ULONG64 Pointer
  1668. )
  1669. {
  1670. ULONG cb;
  1671. if (IsPtr64()) {
  1672. return (WriteMemory(Address, &Pointer, sizeof(Pointer), &cb) && cb == sizeof(Pointer));
  1673. } else {
  1674. ULONG Pointer32 = (ULONG)Pointer;
  1675. ULONG Status;
  1676. Status = WriteMemory(Address,
  1677. &Pointer32,
  1678. sizeof(Pointer32),
  1679. &cb);
  1680. return (Status && cb == sizeof(Pointer32)) ? 1 : 0;
  1681. }
  1682. }
  1683. /**
  1684. This does Ioctl call for type info and returns size of the type on success.
  1685. **/
  1686. __inline
  1687. ULONG
  1688. GetTypeSize (
  1689. IN LPCSTR Type
  1690. )
  1691. {
  1692. SYM_DUMP_PARAM Sym = {
  1693. sizeof (SYM_DUMP_PARAM), (PUCHAR)Type, DBG_DUMP_NO_PRINT | DBG_DUMP_GET_SIZE_ONLY, 0,
  1694. NULL, NULL, NULL, 0, NULL
  1695. };
  1696. return Ioctl( IG_GET_TYPE_SIZE, &Sym, Sym.size );
  1697. }
  1698. /**
  1699. GetFieldData
  1700. Copies the value of the specified field into pOutValue assuming TypeAddress
  1701. points to start of the type in debugee.
  1702. If the Field is NULL and the size of Type is <= 8 Whole type value is read into
  1703. pOutValue. This is to allow to read in primitive types suchas ULONG, PVOID etc.
  1704. If address is zero this considers Type a global variable.
  1705. It raises an exception if OutSize is less than size to be copied.
  1706. Returns 0 on success, errorvalue (defined with SYM_DUMP_PARAM) otherwise.
  1707. **/
  1708. __inline
  1709. ULONG
  1710. GetFieldData (
  1711. IN ULONG64 TypeAddress,
  1712. IN LPCSTR Type,
  1713. IN LPCSTR Field,
  1714. IN ULONG OutSize,
  1715. OUT PVOID pOutValue
  1716. )
  1717. {
  1718. FIELD_INFO flds = {(PUCHAR)Field, NULL, 0, DBG_DUMP_FIELD_FULL_NAME | DBG_DUMP_FIELD_COPY_FIELD_DATA | DBG_DUMP_FIELD_RETURN_ADDRESS, 0, pOutValue};
  1719. SYM_DUMP_PARAM Sym = {
  1720. sizeof (SYM_DUMP_PARAM), (PUCHAR)Type, DBG_DUMP_NO_PRINT, TypeAddress,
  1721. NULL, NULL, NULL, 1, &flds
  1722. };
  1723. ULONG RetVal;
  1724. if (!Field) {
  1725. Sym.nFields =0; Sym.Options |= DBG_DUMP_COPY_TYPE_DATA;
  1726. Sym.Context = pOutValue;
  1727. }
  1728. ZeroMemory(pOutValue, OutSize);
  1729. RetVal = Ioctl( IG_DUMP_SYMBOL_INFO, &Sym, Sym.size );
  1730. if (OutSize < ((Field == NULL) ? 8 : flds.size)) {
  1731. // Fail
  1732. dprintf("Not enough space to read %s-%s\n", Type, Field);
  1733. RaiseException(EXCEPTION_ACCESS_VIOLATION, 0, 0, NULL);
  1734. return 0;
  1735. }
  1736. return RetVal;
  1737. }
  1738. //
  1739. // Typecast the buffer where value is to be read
  1740. //
  1741. #define GetFieldValue(Addr, Type, Field, OutValue) \
  1742. GetFieldData(Addr, Type, Field, sizeof(OutValue), (PVOID) &(OutValue))
  1743. //
  1744. // Used to read in value of a short (<= 8 bytes) fields
  1745. //
  1746. __inline
  1747. ULONG64
  1748. GetShortField (
  1749. IN ULONG64 TypeAddress,
  1750. IN LPCSTR Name,
  1751. IN USHORT StoreAddress
  1752. )
  1753. {
  1754. static ULONG64 SavedAddress;
  1755. static PUCHAR SavedName;
  1756. static ULONG ReadPhysical;
  1757. FIELD_INFO flds = {(PUCHAR) Name, NULL, 0, DBG_DUMP_FIELD_FULL_NAME, 0, NULL};
  1758. SYM_DUMP_PARAM Sym = {
  1759. sizeof (SYM_DUMP_PARAM), SavedName, DBG_DUMP_NO_PRINT | ((StoreAddress & 2) ? DBG_DUMP_READ_PHYSICAL : 0),
  1760. SavedAddress, NULL, NULL, NULL, 1, &flds
  1761. };
  1762. if (StoreAddress) {
  1763. Sym.sName = (PUCHAR) Name;
  1764. Sym.nFields = 0;
  1765. SavedName = (PUCHAR) Name;
  1766. Sym.addr = SavedAddress = TypeAddress;
  1767. ReadPhysical = (StoreAddress & 2);
  1768. return SavedAddress ? Ioctl( IG_DUMP_SYMBOL_INFO, &Sym, Sym.size ) : MEMORY_READ_ERROR; // zero on success
  1769. } else {
  1770. Sym.Options |= ReadPhysical ? DBG_DUMP_READ_PHYSICAL : 0;
  1771. }
  1772. if (!Ioctl( IG_DUMP_SYMBOL_INFO, &Sym, Sym.size )) {
  1773. return flds.address;
  1774. }
  1775. return 0;
  1776. }
  1777. //
  1778. // Stores the address and type name for future reads
  1779. //
  1780. #define InitTypeRead(Addr, Type) GetShortField(Addr, #Type, 1)
  1781. //
  1782. // Stores the address and type name for future reads
  1783. //
  1784. #define InitTypeReadPhysical(Addr, Type) GetShortField(Addr, #Type, 3)
  1785. //
  1786. // Returns the field's value as ULONG64 if size of field is <= sizeof (ULONG64)
  1787. //
  1788. #define ReadField(Field) GetShortField(0, #Field, 0)
  1789. //
  1790. // Read in a pointer value
  1791. //
  1792. __inline
  1793. ULONG
  1794. ReadPtr(
  1795. ULONG64 Addr,
  1796. PULONG64 pPointer
  1797. )
  1798. {
  1799. return GetFieldData(Addr, "PVOID", NULL, sizeof(ULONG64), (PVOID) pPointer);
  1800. }
  1801. /*
  1802. * ListType
  1803. *
  1804. * Routine ListType gives a callback on each element in the list of Type.
  1805. *
  1806. * Type : Name of the type to be listed
  1807. *
  1808. * NextPointer : Name of field which gives address of next element in list
  1809. *
  1810. * Context, CallbackRoutine :
  1811. * Context and the callback routine. The address field in PFIELD_INFO
  1812. * parameter of callback contains the address of next Type element in list.
  1813. *
  1814. * Address, ListByFieldAddress :
  1815. * if ListByFieldAddress is 0, Adress is the address of first element of Type List.
  1816. *
  1817. * Lists by LIST_ENTRY are also handled implicitly (by Ioctl). If the NextPointer
  1818. * is a pointer to LIST_ENTRY type, the type address is properly calculated by
  1819. * subtracting the offsets.
  1820. *
  1821. * If ListByFieldAddress is 1, the Address is considered to be the address of field
  1822. * "NextPointer" of the first Type element and first element address is derived
  1823. * from it.
  1824. *
  1825. */
  1826. __inline
  1827. ULONG
  1828. ListType (
  1829. IN LPCSTR Type,
  1830. IN ULONG64 Address,
  1831. IN USHORT ListByFieldAddress,
  1832. IN LPCSTR NextPointer,
  1833. IN PVOID Context,
  1834. IN PSYM_DUMP_FIELD_CALLBACK CallbackRoutine
  1835. )
  1836. {
  1837. FIELD_INFO flds = {(PUCHAR)NextPointer, NULL, 0, 0, 0, NULL};
  1838. SYM_DUMP_PARAM Sym = {
  1839. sizeof (SYM_DUMP_PARAM), (PUCHAR) Type, DBG_DUMP_NO_PRINT | DBG_DUMP_LIST, Address,
  1840. &flds, Context, CallbackRoutine, 0, NULL
  1841. };
  1842. if (ListByFieldAddress==1) {
  1843. //
  1844. // Address is the address of "NextPointer"
  1845. //
  1846. Sym.Options |= DBG_DUMP_ADDRESS_OF_FIELD;
  1847. }
  1848. return Ioctl( IG_DUMP_SYMBOL_INFO, &Sym, Sym.size );
  1849. }
  1850. /**
  1851. Routine to get offset of a "Field" of "Type" on a debugee machine. This uses
  1852. Ioctl call for type info.
  1853. Returns 0 on success, Ioctl error value otherwise.
  1854. **/
  1855. __inline
  1856. ULONG
  1857. GetFieldOffset (
  1858. IN LPCSTR Type,
  1859. IN LPCSTR Field,
  1860. OUT PULONG pOffset
  1861. )
  1862. {
  1863. FIELD_INFO flds = {
  1864. (PUCHAR)Field,
  1865. (PUCHAR)"",
  1866. 0,
  1867. DBG_DUMP_FIELD_FULL_NAME | DBG_DUMP_FIELD_RETURN_ADDRESS,
  1868. 0,
  1869. NULL};
  1870. SYM_DUMP_PARAM Sym = {
  1871. sizeof (SYM_DUMP_PARAM),
  1872. (PUCHAR)Type,
  1873. DBG_DUMP_NO_PRINT,
  1874. 0,
  1875. NULL,
  1876. NULL,
  1877. NULL,
  1878. 1,
  1879. &flds
  1880. };
  1881. ULONG Err;
  1882. Sym.nFields = 1;
  1883. Err = Ioctl( IG_DUMP_SYMBOL_INFO, &Sym, Sym.size );
  1884. *pOffset = (ULONG) (flds.address - Sym.addr);
  1885. return Err;
  1886. }
  1887. #endif // defined(KDEXT_64BIT)
  1888. __inline VOID
  1889. GetCurrentProcessHandle(
  1890. PHANDLE hp
  1891. )
  1892. {
  1893. Ioctl(IG_GET_CURRENT_PROCESS_HANDLE, hp, sizeof(HANDLE));
  1894. }
  1895. __inline VOID
  1896. GetTebAddress(
  1897. PULONGLONG Address
  1898. )
  1899. {
  1900. GET_TEB_ADDRESS gpt;
  1901. gpt.Address = 0;
  1902. Ioctl(IG_GET_TEB_ADDRESS, (PVOID)&gpt, sizeof(gpt));
  1903. *Address = gpt.Address;
  1904. }
  1905. __inline VOID
  1906. GetPebAddress(
  1907. ULONG64 CurrentThread,
  1908. PULONGLONG Address
  1909. )
  1910. {
  1911. GET_PEB_ADDRESS gpt;
  1912. gpt.CurrentThread = CurrentThread;
  1913. gpt.Address = 0;
  1914. Ioctl(IG_GET_PEB_ADDRESS, (PVOID)&gpt, sizeof(gpt));
  1915. *Address = gpt.Address;
  1916. }
  1917. __inline VOID
  1918. GetCurrentThreadAddr(
  1919. DWORD Processor,
  1920. PULONG64 Address
  1921. )
  1922. {
  1923. GET_CURRENT_THREAD_ADDRESS ct;
  1924. ct.Processor = Processor;
  1925. Ioctl(IG_GET_CURRENT_THREAD, (PVOID)&ct, sizeof(ct));
  1926. *Address = ct.Address;
  1927. }
  1928. __inline VOID
  1929. GetCurrentProcessAddr(
  1930. DWORD Processor,
  1931. ULONG64 CurrentThread,
  1932. PULONG64 Address
  1933. )
  1934. {
  1935. GET_CURRENT_PROCESS_ADDRESS cp;
  1936. cp.Processor = Processor;
  1937. cp.CurrentThread = CurrentThread;
  1938. Ioctl(IG_GET_CURRENT_PROCESS, (PVOID)&cp, sizeof(cp));
  1939. *Address = cp.Address;
  1940. }
  1941. __inline VOID
  1942. SearchMemory(
  1943. ULONG64 SearchAddress,
  1944. ULONG64 SearchLength,
  1945. ULONG PatternLength,
  1946. PVOID Pattern,
  1947. PULONG64 FoundAddress
  1948. )
  1949. {
  1950. SEARCHMEMORY sm;
  1951. sm.SearchAddress = SearchAddress;
  1952. sm.SearchLength = SearchLength;
  1953. sm.FoundAddress = 0;
  1954. sm.PatternLength = PatternLength;
  1955. sm.Pattern = Pattern;
  1956. Ioctl(IG_SEARCH_MEMORY, (PVOID)&sm, sizeof(sm));
  1957. *FoundAddress = sm.FoundAddress;
  1958. }
  1959. __inline ULONG
  1960. GetInputLine(
  1961. PCSTR Prompt,
  1962. PSTR Buffer,
  1963. ULONG BufferSize
  1964. )
  1965. {
  1966. GET_INPUT_LINE InLine;
  1967. InLine.Prompt = Prompt;
  1968. InLine.Buffer = Buffer;
  1969. InLine.BufferSize = BufferSize;
  1970. if (Ioctl(IG_GET_INPUT_LINE, (PVOID)&InLine, sizeof(InLine)))
  1971. {
  1972. return InLine.InputSize;
  1973. }
  1974. else
  1975. {
  1976. return 0;
  1977. }
  1978. }
  1979. __inline BOOL
  1980. GetExpressionEx(
  1981. PCSTR Expression,
  1982. ULONG64* Value,
  1983. PCSTR* Remainder
  1984. )
  1985. {
  1986. GET_EXPRESSION_EX Expr;
  1987. Expr.Expression = Expression;
  1988. if (Ioctl(IG_GET_EXPRESSION_EX, (PVOID)&Expr, sizeof(Expr)))
  1989. {
  1990. *Value = Expr.Value;
  1991. if (Remainder != NULL)
  1992. {
  1993. *Remainder = Expr.Remainder;
  1994. }
  1995. return TRUE;
  1996. }
  1997. return FALSE;
  1998. }
  1999. __inline BOOL
  2000. TranslateVirtualToPhysical(
  2001. ULONG64 Virtual,
  2002. ULONG64* Physical
  2003. )
  2004. {
  2005. TRANSLATE_VIRTUAL_TO_PHYSICAL VToP;
  2006. VToP.Virtual = Virtual;
  2007. if (Ioctl(IG_TRANSLATE_VIRTUAL_TO_PHYSICAL, (PVOID)&VToP, sizeof(VToP)))
  2008. {
  2009. *Physical = VToP.Physical;
  2010. return TRUE;
  2011. }
  2012. return FALSE;
  2013. }
  2014. __inline BOOL
  2015. GetDebuggerCacheSize(
  2016. OUT PULONG64 CacheSize
  2017. )
  2018. {
  2019. return Ioctl(IG_GET_CACHE_SIZE, (PVOID) CacheSize, sizeof(ULONG64));
  2020. }
  2021. #endif
  2022. #ifdef __cplusplus
  2023. }
  2024. #endif
  2025. #endif // _WDBGEXTS_