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.

469 lines
12 KiB

  1. /*++
  2. Copyright (c) 1992-1995 Microsoft Corporation
  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 "imagehlp.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. #ifdef __cplusplus
  19. extern "C" {
  20. #endif
  21. #if !defined(WDBGAPI)
  22. #define WDBGAPI __stdcall
  23. #endif
  24. #ifndef _WINDEF_
  25. typedef CONST void far *LPCVOID;
  26. #endif
  27. typedef
  28. VOID
  29. (WDBGAPI*PWINDBG_OUTPUT_ROUTINE)(
  30. PCSTR lpFormat,
  31. ...
  32. );
  33. typedef
  34. ULONG
  35. (WDBGAPI*PWINDBG_GET_EXPRESSION)(
  36. PCSTR lpExpression
  37. );
  38. typedef
  39. VOID
  40. (WDBGAPI*PWINDBG_GET_SYMBOL)(
  41. PVOID offset,
  42. PUCHAR pchBuffer,
  43. PULONG pDisplacement
  44. );
  45. typedef
  46. ULONG
  47. (WDBGAPI*PWINDBG_DISASM)(
  48. PULONG lpOffset,
  49. PCSTR lpBuffer,
  50. ULONG fShowEffectiveAddress
  51. );
  52. typedef
  53. ULONG
  54. (WDBGAPI*PWINDBG_CHECK_CONTROL_C)(
  55. VOID
  56. );
  57. typedef
  58. ULONG
  59. (WDBGAPI*PWINDBG_READ_PROCESS_MEMORY_ROUTINE)(
  60. ULONG offset,
  61. PVOID lpBuffer,
  62. ULONG cb,
  63. PULONG lpcbBytesRead
  64. );
  65. typedef
  66. ULONG
  67. (WDBGAPI*PWINDBG_WRITE_PROCESS_MEMORY_ROUTINE)(
  68. ULONG offset,
  69. LPCVOID lpBuffer,
  70. ULONG cb,
  71. PULONG lpcbBytesWritten
  72. );
  73. typedef
  74. ULONG
  75. (WDBGAPI*PWINDBG_GET_THREAD_CONTEXT_ROUTINE)(
  76. ULONG Processor,
  77. PCONTEXT lpContext,
  78. ULONG cbSizeOfContext
  79. );
  80. typedef
  81. ULONG
  82. (WDBGAPI*PWINDBG_SET_THREAD_CONTEXT_ROUTINE)(
  83. ULONG Processor,
  84. PCONTEXT lpContext,
  85. ULONG cbSizeOfContext
  86. );
  87. typedef
  88. ULONG
  89. (WDBGAPI*PWINDBG_IOCTL_ROUTINE)(
  90. USHORT IoctlType,
  91. PVOID lpvData,
  92. ULONG cbSize
  93. );
  94. typedef
  95. ULONG
  96. (WDBGAPI*PWINDBG_OLDKD_READ_PHYSICAL_MEMORY)(
  97. LARGE_INTEGER address,
  98. PVOID buffer,
  99. ULONG count,
  100. PULONG bytesread
  101. );
  102. typedef
  103. ULONG
  104. (WDBGAPI*PWINDBG_OLDKD_WRITE_PHYSICAL_MEMORY)(
  105. LARGE_INTEGER address,
  106. PVOID buffer,
  107. ULONG length,
  108. PULONG byteswritten
  109. );
  110. typedef struct _tagEXTSTACKTRACE {
  111. ULONG FramePointer;
  112. ULONG ProgramCounter;
  113. ULONG ReturnAddress;
  114. ULONG Args[4];
  115. } EXTSTACKTRACE, *PEXTSTACKTRACE;
  116. typedef
  117. ULONG
  118. (*PWINDBG_STACKTRACE_ROUTINE)(
  119. ULONG FramePointer,
  120. ULONG StackPointer,
  121. ULONG ProgramCounter,
  122. PEXTSTACKTRACE StackFrames,
  123. ULONG Frames
  124. );
  125. typedef struct _WINDBG_EXTENSION_APIS {
  126. ULONG nSize;
  127. PWINDBG_OUTPUT_ROUTINE lpOutputRoutine;
  128. PWINDBG_GET_EXPRESSION lpGetExpressionRoutine;
  129. PWINDBG_GET_SYMBOL lpGetSymbolRoutine;
  130. PWINDBG_DISASM lpDisasmRoutine;
  131. PWINDBG_CHECK_CONTROL_C lpCheckControlCRoutine;
  132. PWINDBG_READ_PROCESS_MEMORY_ROUTINE lpReadProcessMemoryRoutine;
  133. PWINDBG_WRITE_PROCESS_MEMORY_ROUTINE lpWriteProcessMemoryRoutine;
  134. PWINDBG_GET_THREAD_CONTEXT_ROUTINE lpGetThreadContextRoutine;
  135. PWINDBG_SET_THREAD_CONTEXT_ROUTINE lpSetThreadContextRoutine;
  136. PWINDBG_IOCTL_ROUTINE lpIoctlRoutine;
  137. PWINDBG_STACKTRACE_ROUTINE lpStackTraceRoutine;
  138. } WINDBG_EXTENSION_APIS, *PWINDBG_EXTENSION_APIS;
  139. typedef struct _WINDBG_OLD_EXTENSION_APIS {
  140. ULONG nSize;
  141. PWINDBG_OUTPUT_ROUTINE lpOutputRoutine;
  142. PWINDBG_GET_EXPRESSION lpGetExpressionRoutine;
  143. PWINDBG_GET_SYMBOL lpGetSymbolRoutine;
  144. PWINDBG_DISASM lpDisasmRoutine;
  145. PWINDBG_CHECK_CONTROL_C lpCheckControlCRoutine;
  146. } WINDBG_OLD_EXTENSION_APIS, *PWINDBG_OLD_EXTENSION_APIS;
  147. typedef struct _WINDBG_OLDKD_EXTENSION_APIS {
  148. ULONG nSize;
  149. PWINDBG_OUTPUT_ROUTINE lpOutputRoutine;
  150. PWINDBG_GET_EXPRESSION lpGetExpressionRoutine;
  151. PWINDBG_GET_SYMBOL lpGetSymbolRoutine;
  152. PWINDBG_DISASM lpDisasmRoutine;
  153. PWINDBG_CHECK_CONTROL_C lpCheckControlCRoutine;
  154. PWINDBG_READ_PROCESS_MEMORY_ROUTINE lpReadVirtualMemRoutine;
  155. PWINDBG_WRITE_PROCESS_MEMORY_ROUTINE lpWriteVirtualMemRoutine;
  156. PWINDBG_OLDKD_READ_PHYSICAL_MEMORY lpReadPhysicalMemRoutine;
  157. PWINDBG_OLDKD_WRITE_PHYSICAL_MEMORY lpWritePhysicalMemRoutine;
  158. } WINDBG_OLDKD_EXTENSION_APIS, *PWINDBG_OLDKD_EXTENSION_APIS;
  159. typedef
  160. VOID
  161. (WDBGAPI*PWINDBG_OLD_EXTENSION_ROUTINE)(
  162. HANDLE hCurrentProcess,
  163. HANDLE hCurrentThread,
  164. ULONG dwCurrentPc,
  165. PWINDBG_EXTENSION_APIS lpExtensionApis,
  166. PCSTR lpArgumentString
  167. );
  168. typedef
  169. VOID
  170. (WDBGAPI*PWINDBG_EXTENSION_ROUTINE)(
  171. HANDLE hCurrentProcess,
  172. HANDLE hCurrentThread,
  173. ULONG dwCurrentPc,
  174. ULONG dwProcessor,
  175. PCSTR lpArgumentString
  176. );
  177. typedef
  178. VOID
  179. (WDBGAPI*PWINDBG_OLDKD_EXTENSION_ROUTINE)(
  180. ULONG dwCurrentPc,
  181. PWINDBG_OLDKD_EXTENSION_APIS lpExtensionApis,
  182. PCSTR lpArgumentString
  183. );
  184. typedef
  185. VOID
  186. (WDBGAPI*PWINDBG_EXTENSION_DLL_INIT)(
  187. PWINDBG_EXTENSION_APIS lpExtensionApis,
  188. USHORT MajorVersion,
  189. USHORT MinorVersion
  190. );
  191. typedef
  192. ULONG
  193. (WDBGAPI*PWINDBG_CHECK_VERSION)(
  194. VOID
  195. );
  196. #define EXT_API_VERSION_NUMBER 3
  197. typedef struct EXT_API_VERSION {
  198. USHORT MajorVersion;
  199. USHORT MinorVersion;
  200. USHORT Revision;
  201. USHORT Reserved;
  202. } EXT_API_VERSION, *LPEXT_API_VERSION;
  203. typedef
  204. LPEXT_API_VERSION
  205. (WDBGAPI*PWINDBG_EXTENSION_API_VERSION)(
  206. VOID
  207. );
  208. #define IG_KD_CONTEXT 1
  209. #define IG_READ_CONTROL_SPACE 2
  210. #define IG_WRITE_CONTROL_SPACE 3
  211. #define IG_READ_IO_SPACE 4
  212. #define IG_WRITE_IO_SPACE 5
  213. #define IG_READ_PHYSICAL 6
  214. #define IG_WRITE_PHYSICAL 7
  215. #define IG_READ_IO_SPACE_EX 8
  216. #define IG_WRITE_IO_SPACE_EX 9
  217. typedef struct _tagPROCESSORINFO {
  218. USHORT Processor; // current processor
  219. USHORT NumberProcessors; // total number of processors
  220. } PROCESSORINFO, *PPROCESSORINFO;
  221. typedef struct _tagREADCONTROLSPACE {
  222. USHORT Processor;
  223. ULONG Address;
  224. ULONG BufLen;
  225. UCHAR Buf[1];
  226. } READCONTROLSPACE, *PREADCONTROLSPACE;
  227. typedef struct _tagIOSPACE {
  228. ULONG Address;
  229. ULONG Length; // 1, 2, or 4 bytes
  230. ULONG Data;
  231. } IOSPACE, *PIOSPACE;
  232. typedef struct _tagIOSPACE_EX {
  233. ULONG Address;
  234. ULONG Length; // 1, 2, or 4 bytes
  235. ULONG Data;
  236. ULONG InterfaceType;
  237. ULONG BusNumber;
  238. ULONG AddressSpace;
  239. } IOSPACE_EX, *PIOSPACE_EX;
  240. typedef struct _tagPHYSICAL {
  241. LARGE_INTEGER Address;
  242. ULONG BufLen;
  243. UCHAR Buf[1];
  244. } PHYSICAL, *PPHYSICAL;
  245. #ifdef __cplusplus
  246. #define CPPMOD extern "C"
  247. #else
  248. #define CPPMOD
  249. #endif
  250. #define DECLARE_API(s) \
  251. CPPMOD VOID \
  252. s( \
  253. HANDLE hCurrentProcess, \
  254. HANDLE hCurrentThread, \
  255. ULONG dwCurrentPc, \
  256. ULONG dwProcessor, \
  257. PCSTR args \
  258. )
  259. #ifndef NOEXTAPI
  260. #define dprintf (ExtensionApis.lpOutputRoutine)
  261. #define GetExpression (ExtensionApis.lpGetExpressionRoutine)
  262. #define GetSymbol (ExtensionApis.lpGetSymbolRoutine)
  263. #define Disassm (ExtensionApis.lpDisasmRoutine)
  264. #define CheckControlC (ExtensionApis.lpCheckControlCRoutine)
  265. #define ReadMemory (ExtensionApis.lpReadProcessMemoryRoutine)
  266. #define WriteMemory (ExtensionApis.lpWriteProcessMemoryRoutine)
  267. #define GetContext (ExtensionApis.lpGetThreadContextRoutine)
  268. #define SetContext (ExtensionApis.lpSetThreadContextRoutine)
  269. #define Ioctl (ExtensionApis.lpIoctlRoutine)
  270. #define StackTrace (ExtensionApis.lpStackTraceRoutine)
  271. #define GetKdContext(ppi) \
  272. Ioctl( IG_KD_CONTEXT, (PVOID)ppi, sizeof(*ppi) )
  273. extern WINDBG_EXTENSION_APIS ExtensionApis;
  274. __inline VOID
  275. ReadControlSpace(
  276. USHORT processor,
  277. ULONG address,
  278. PVOID buf,
  279. ULONG size
  280. )
  281. {
  282. PREADCONTROLSPACE prc;
  283. prc = (PREADCONTROLSPACE)LocalAlloc(LPTR, sizeof(*prc) + size );
  284. ZeroMemory( prc->Buf, size );
  285. prc->Processor = processor;
  286. prc->Address = (ULONG)address;
  287. prc->BufLen = size;
  288. Ioctl( IG_READ_CONTROL_SPACE, (PVOID)prc, sizeof(*prc) + size );
  289. CopyMemory( buf, prc->Buf, size );
  290. LocalFree( prc );
  291. }
  292. __inline VOID
  293. ReadIoSpace(
  294. ULONG address,
  295. PULONG data,
  296. PULONG size
  297. )
  298. {
  299. IOSPACE is;
  300. is.Address = (ULONG)address;
  301. is.Length = *size;
  302. is.Data = 0;
  303. Ioctl( IG_READ_IO_SPACE, (PVOID)&is, sizeof(is) );
  304. *data = is.Data;
  305. *size = is.Length;
  306. }
  307. __inline VOID
  308. WriteIoSpace(
  309. ULONG address,
  310. ULONG data,
  311. PULONG size
  312. )
  313. {
  314. IOSPACE is;
  315. is.Address = (ULONG)address;
  316. is.Length = *size;
  317. is.Data = data;
  318. Ioctl( IG_WRITE_IO_SPACE, (PVOID)&is, sizeof(is) );
  319. *size = is.Length;
  320. }
  321. __inline VOID
  322. ReadIoSpaceEx(
  323. ULONG address,
  324. PULONG data,
  325. PULONG size,
  326. ULONG interfacetype,
  327. ULONG busnumber,
  328. ULONG addressspace
  329. )
  330. {
  331. IOSPACE_EX is;
  332. is.Address = (ULONG)address;
  333. is.Length = *size;
  334. is.Data = 0;
  335. is.InterfaceType = interfacetype;
  336. is.BusNumber = busnumber;
  337. is.AddressSpace = addressspace;
  338. Ioctl( IG_READ_IO_SPACE_EX, (PVOID)&is, sizeof(is) );
  339. *data = is.Data;
  340. *size = is.Length;
  341. }
  342. __inline VOID
  343. WriteIoSpaceEx(
  344. ULONG address,
  345. ULONG data,
  346. PULONG size,
  347. ULONG interfacetype,
  348. ULONG busnumber,
  349. ULONG addressspace
  350. )
  351. {
  352. IOSPACE_EX is;
  353. is.Address = (ULONG)address;
  354. is.Length = *size;
  355. is.Data = data;
  356. is.InterfaceType = interfacetype;
  357. is.BusNumber = busnumber;
  358. is.AddressSpace = addressspace;
  359. Ioctl( IG_WRITE_IO_SPACE_EX, (PVOID)&is, sizeof(is) );
  360. *size = is.Length;
  361. }
  362. __inline VOID
  363. ReadPhysical(
  364. LARGE_INTEGER address,
  365. PVOID buf,
  366. ULONG size,
  367. PULONG sizer
  368. )
  369. {
  370. PPHYSICAL phy;
  371. phy = (PPHYSICAL)LocalAlloc(LPTR, sizeof(*phy) + size );
  372. ZeroMemory( phy->Buf, size );
  373. phy->Address = address;
  374. phy->BufLen = size;
  375. Ioctl( IG_READ_PHYSICAL, (PVOID)phy, sizeof(*phy) + size );
  376. *sizer = phy->BufLen;
  377. CopyMemory( buf, phy->Buf, *sizer );
  378. LocalFree( phy );
  379. }
  380. __inline VOID
  381. WritePhysical(
  382. LARGE_INTEGER address,
  383. PVOID buf,
  384. ULONG size,
  385. PULONG sizew
  386. )
  387. {
  388. PPHYSICAL phy;
  389. phy = (PPHYSICAL)LocalAlloc(LPTR, sizeof(*phy) + size );
  390. ZeroMemory( phy->Buf, size );
  391. phy->Address = address;
  392. phy->BufLen = size;
  393. CopyMemory( phy->Buf, buf, size );
  394. Ioctl( IG_WRITE_PHYSICAL, (PVOID)phy, sizeof(*phy) + size );
  395. *sizew = phy->BufLen;
  396. LocalFree( phy );
  397. }
  398. #endif
  399. #ifdef __cplusplus
  400. }
  401. #endif
  402. #endif // _WDBGEXTS_