home *** CD-ROM | disk | FTP | other *** search
/ Power GUI Programming with VisualAge C++ / powergui.iso / trialva / ibmcppw / sdk / winh / wdbgexts.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-07-11  |  11.9 KB  |  470 lines

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