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.

343 lines
8.6 KiB

  1. /*++
  2. Copyright (c) 1992-1993 Microsoft Corporation
  3. Module Name:
  4. wdbgexts.h
  5. Abstract:
  6. This file contains procedure prototypes and structures needed to port
  7. NTSD debugger extensions so that they can be invoked remotely in WinDbg
  8. command window. This file is to be included by cmdexec0.c and wdbgexts.c.
  9. To maintain compatibilty with NTSD extensions(or to call the original NTSD
  10. extensions like "ntsdexts" without modification), definitions in this file
  11. are incremental by first doing **#include <ntsdexts.h>**.
  12. Author:
  13. Peter Sun (t-petes) 29-July-1992
  14. Environment:
  15. runs in the Win32 WinDbg environment.
  16. Revision History:
  17. --*/
  18. #ifndef _WDBGEXTS_
  19. #define _WDBGEXTS_
  20. #include <ntsdexts.h>
  21. #ifdef __cplusplus
  22. extern "C" {
  23. #endif
  24. typedef LARGE_INTEGER PHYSICAL_ADDRESS, *PPHYSICAL_ADDRESS;
  25. typedef
  26. VOID
  27. (*PWINDBG_OUTPUT_ROUTINE)(
  28. char *,
  29. ...
  30. );
  31. typedef
  32. DWORD
  33. (*PWINDBG_GET_EXPRESSION)(
  34. char *
  35. );
  36. typedef
  37. VOID
  38. (*PWINDBG_GET_SYMBOL)(
  39. LPVOID offset,
  40. PUCHAR pchBuffer,
  41. LPDWORD pDisplacement
  42. );
  43. typedef
  44. DWORD
  45. (*PWINDBG_DISASM)(
  46. LPDWORD lpOffset,
  47. LPSTR lpBuffer,
  48. BOOL fShowEfeectiveAddress
  49. );
  50. typedef
  51. BOOL
  52. (*PWINDBG_CHECK_CONTROL_C)(
  53. VOID
  54. );
  55. typedef
  56. BOOL
  57. (*PWINDBG_READ_PROCESS_MEMORY_ROUTINE)(
  58. DWORD offset,
  59. LPVOID lpBuffer,
  60. DWORD cb,
  61. LPDWORD lpcbBytesRead
  62. );
  63. typedef
  64. BOOL
  65. (*PWINDBG_WRITE_PROCESS_MEMORY_ROUTINE)(
  66. DWORD offset,
  67. LPVOID lpBuffer,
  68. DWORD cb,
  69. LPDWORD lpcbBytesWritten
  70. );
  71. typedef
  72. BOOL
  73. (*PWINDBG_GET_THREAD_CONTEXT_ROUTINE)(
  74. LPCONTEXT lpContext,
  75. DWORD cbSizeOfContext
  76. );
  77. typedef
  78. BOOL
  79. (*PWINDBG_SET_THREAD_CONTEXT_ROUTINE)(
  80. LPCONTEXT lpContext,
  81. DWORD cbSizeOfContext
  82. );
  83. typedef
  84. BOOL
  85. (*PWINDBG_IOCTL_ROUTINE)(
  86. USHORT IoctlType,
  87. LPVOID lpvData,
  88. DWORD cbSize
  89. );
  90. typedef struct _tagEXTSTACKTRACE {
  91. DWORD FramePointer;
  92. DWORD ProgramCounter;
  93. DWORD ReturnAddress;
  94. DWORD Args[4];
  95. } EXTSTACKTRACE, *PEXTSTACKTRACE;
  96. typedef
  97. DWORD
  98. (*PWINDBG_STACKTRACE_ROUTINE)(
  99. DWORD FramePointer,
  100. DWORD StackPointer,
  101. DWORD ProgramCounter,
  102. PEXTSTACKTRACE StackFrames,
  103. DWORD Frames
  104. );
  105. typedef struct _WINDBG_EXTENSION_APIS {
  106. DWORD nSize;
  107. PWINDBG_OUTPUT_ROUTINE lpOutputRoutine;
  108. PWINDBG_GET_EXPRESSION lpGetExpressionRoutine;
  109. PWINDBG_GET_SYMBOL lpGetSymbolRoutine;
  110. PWINDBG_DISASM lpDisasmRoutine;
  111. PWINDBG_CHECK_CONTROL_C lpCheckControlCRoutine;
  112. PWINDBG_READ_PROCESS_MEMORY_ROUTINE lpReadProcessMemoryRoutine;
  113. PWINDBG_WRITE_PROCESS_MEMORY_ROUTINE lpWriteProcessMemoryRoutine;
  114. PWINDBG_GET_THREAD_CONTEXT_ROUTINE lpGetThreadContextRoutine;
  115. PWINDBG_SET_THREAD_CONTEXT_ROUTINE lpSetThreadContextRoutine;
  116. PWINDBG_IOCTL_ROUTINE lpIoctlRoutine;
  117. PWINDBG_STACKTRACE_ROUTINE lpStackTraceRoutine;
  118. } WINDBG_EXTENSION_APIS, *PWINDBG_EXTENSION_APIS;
  119. typedef
  120. VOID
  121. (*PWINDBG_OLD_EXTENSION_ROUTINE)(
  122. HANDLE hCurrentProcess,
  123. HANDLE hCurrentThread,
  124. DWORD dwCurrentPc,
  125. PWINDBG_EXTENSION_APIS lpExtensionApis,
  126. LPSTR lpArgumentString
  127. );
  128. typedef
  129. VOID
  130. (*PWINDBG_EXTENSION_ROUTINE)(
  131. HANDLE hCurrentProcess,
  132. HANDLE hCurrentThread,
  133. DWORD dwCurrentPc,
  134. LPSTR lpArgumentString
  135. );
  136. typedef
  137. VOID
  138. (*PWINDBG_EXTENSION_DLL_INIT)(
  139. PWINDBG_EXTENSION_APIS lpExtensionApis
  140. );
  141. #define IG_KD_CONTEXT 1
  142. #define IG_READ_CONTROL_SPACE 2
  143. #define IG_WRITE_CONTROL_SPACE 3
  144. #define IG_READ_IO_SPACE 4
  145. #define IG_WRITE_IO_SPACE 5
  146. #define IG_READ_PHYSICAL 6
  147. #define IG_WRITE_PHYSICAL 7
  148. #define IG_READ_IO_SPACE_EX 8
  149. #define IG_WRITE_IO_SPACE_EX 9
  150. typedef struct _tagPROCESSORINFO {
  151. USHORT Processor; // current processor
  152. USHORT NumberProcessors; // total number of processors
  153. } PROCESSORINFO, *PPROCESSORINFO;
  154. typedef struct _tagREADCONTROLSPACE {
  155. ULONG Processor;
  156. ULONG Address;
  157. ULONG BufLen;
  158. BYTE Buf[1];
  159. } READCONTROLSPACE, *PREADCONTROLSPACE;
  160. typedef struct _tagIOSPACE {
  161. ULONG Address;
  162. ULONG Length; // 1, 2, or 4 bytes
  163. ULONG Data;
  164. } IOSPACE, *PIOSPACE;
  165. typedef struct _tagIOSPACE_EX {
  166. ULONG Address;
  167. ULONG Length; // 1, 2, or 4 bytes
  168. ULONG Data;
  169. ULONG InterfaceType;
  170. ULONG BusNumber;
  171. ULONG AddressSpace;
  172. } IOSPACE_EX, *PIOSPACE_EX;
  173. typedef struct _tagPHYSICAL {
  174. PHYSICAL_ADDRESS Address;
  175. ULONG BufLen;
  176. BYTE Buf[1];
  177. } PHYSICAL, *PPHYSICAL;
  178. #ifdef WDBGEXTS_NEW
  179. #define dprintf (ExtensionApis.lpOutputRoutine)
  180. #define GetExpression (ExtensionApis.lpGetExpressionRoutine)
  181. #define GetSymbol (ExtensionApis.lpGetSymbolRoutine)
  182. #define Disassm (ExtensionApis.lpDisasmRoutine)
  183. #define CheckControlC (ExtensionApis.lpCheckControlCRoutine)
  184. #define ReadMemory (ExtensionApis.lpReadProcessMemoryRoutine)
  185. #define WriteMemory (ExtensionApis.lpWriteProcessMemoryRoutine)
  186. #define GetContext (ExtensionApis.lpGetThreadContextRoutine)
  187. #define SetContext (ExtensionApis.lpSetThreadContextRoutine)
  188. #define Ioctl (ExtensionApis.lpIoctlRoutine)
  189. #define StackTrace (ExtensionApis.lpStackTraceRoutine)
  190. #define DECLARE_API(s) \
  191. VOID \
  192. s( \
  193. HANDLE hCurrentProcess, \
  194. HANDLE hCurrentThread, \
  195. DWORD dwCurrentPc, \
  196. LPSTR args \
  197. )
  198. #define GetKdContext(ppi) \
  199. Ioctl( IG_KD_CONTEXT, (LPVOID)ppi, sizeof(*ppi) )
  200. #define ReadControlSpace(processor,address,buf,size) \
  201. { \
  202. PREADCONTROLSPACE prc; \
  203. prc = malloc( sizeof(*prc) + size ); \
  204. ZeroMemory( prc->Buf, size ); \
  205. prc->Processor = (DWORD)processor; \
  206. prc->Address = (DWORD)address; \
  207. prc->BufLen = size; \
  208. Ioctl( IG_READ_CONTROL_SPACE, (LPVOID)prc, sizeof(*prc) + size ); \
  209. memcpy( buf, prc->Buf, size ); \
  210. free( prc ); \
  211. }
  212. #define ReadIoSpace(address,data,size) \
  213. { \
  214. IOSPACE is; \
  215. is.Address = (DWORD)address; \
  216. is.Length = *size; \
  217. is.Data = 0; \
  218. Ioctl( IG_READ_IO_SPACE, (LPVOID)&is, sizeof(is) ); \
  219. *data = is.Data; \
  220. *size = is.Length; \
  221. }
  222. #define WriteIoSpace(address,data,size) \
  223. { \
  224. IOSPACE is; \
  225. is.Address = (DWORD)address; \
  226. is.Length = *size; \
  227. is.Data = data; \
  228. Ioctl( IG_WRITE_IO_SPACE, (LPVOID)&is, sizeof(is) ); \
  229. *size = is.Length; \
  230. }
  231. #define ReadIoSpaceEx(address,data,size,interfacetype,busnumber,addressspace) \
  232. { \
  233. IOSPACE_EX is; \
  234. is.Address = (DWORD)address; \
  235. is.Length = *size; \
  236. is.Data = 0; \
  237. is.InterfaceType = interfacetype; \
  238. is.BusNumber = busnumber; \
  239. is.AddressSpace = addressspace; \
  240. Ioctl( IG_READ_IO_SPACE_EX, (LPVOID)&is, sizeof(is) ); \
  241. *data = is.Data; \
  242. *size = is.Length; \
  243. }
  244. #define WriteIoSpaceEx(address,data,size,interfacetype,busnumber,addressspace) \
  245. { \
  246. IOSPACE_EX is; \
  247. is.Address = (DWORD)address; \
  248. is.Length = *size; \
  249. is.Data = data; \
  250. is.InterfaceType = interfacetype; \
  251. is.BusNumber = busnumber; \
  252. is.AddressSpace = addressspace; \
  253. Ioctl( IG_WRITE_IO_SPACE_EX, (LPVOID)&is, sizeof(is) ); \
  254. *size = is.Length; \
  255. }
  256. #define ReadPhysical(address,buf,size,sizer) \
  257. { \
  258. PPHYSICAL phy; \
  259. phy = malloc( sizeof(*phy) + size ); \
  260. ZeroMemory( phy->Buf, size ); \
  261. phy->Address = address; \
  262. phy->BufLen = size; \
  263. Ioctl( IG_READ_PHYSICAL, (LPVOID)phy, sizeof(*phy) + size ); \
  264. *sizer = phy->BufLen; \
  265. memcpy( buf, phy->Buf, *sizer ); \
  266. free( phy ); \
  267. }
  268. #define WritePhysical(address,buf,size,sizew) \
  269. { \
  270. PPHYSICAL phy; \
  271. phy = malloc( sizeof(*phy) + size ); \
  272. ZeroMemory( phy->Buf, size ); \
  273. phy->Address = address; \
  274. phy->BufLen = size; \
  275. memcpy( phy->Buf, buf, size ); \
  276. Ioctl( IG_WRITE_PHYSICAL, (LPVOID)phy, sizeof(*phy) + size ); \
  277. *sizew = phy->BufLen; \
  278. free( phy ); \
  279. }
  280. #endif
  281. #ifdef __cplusplus
  282. }
  283. #endif
  284. #endif // _WDBGEXTS_