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