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