home *** CD-ROM | disk | FTP | other *** search
/ Programmer Plus 2007 / Programmer-Plus-2007.iso / Programming / Compilers / digital marsC compier / dm / include / win32 / Wdbgexts.h < prev    next >
Encoding:
C/C++ Source or Header  |  1996-08-08  |  13.0 KB  |  522 lines

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