home *** CD-ROM | disk | FTP | other *** search
/ PC Plus SuperCD (UK) 2000 May / PCP163A.iso / Runimage / Cbuilder4 / Include / WDBGEXTS.H < prev    next >
Encoding:
C/C++ Source or Header  |  1999-01-26  |  15.3 KB  |  628 lines

  1. /*++
  2.  
  3. Copyright 1992 - 1998 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. #pragma option push -b -a8 -pc -A- /*P_O_Push_S*/
  30. #define _WDBGEXTS_
  31.  
  32. #ifdef __cplusplus
  33. extern "C" {
  34. #endif
  35.  
  36. #if !defined(WDBGAPI)
  37. #define WDBGAPI __stdcall
  38. #endif
  39.  
  40. #ifndef _WINDEF_
  41. typedef CONST void far *LPCVOID;
  42. #endif
  43.  
  44.  
  45. typedef
  46. VOID
  47. (WDBGAPI*PWINDBG_OUTPUT_ROUTINE)(
  48.     PCSTR lpFormat,
  49.     ...
  50.     );
  51.  
  52. typedef
  53. ULONG
  54. (WDBGAPI*PWINDBG_GET_EXPRESSION)(
  55.     PCSTR lpExpression
  56.     );
  57.  
  58. typedef
  59. VOID
  60. (WDBGAPI*PWINDBG_GET_SYMBOL)(
  61.     PVOID   offset,
  62.     PUCHAR  pchBuffer,
  63.     PULONG  pDisplacement
  64.     );
  65.  
  66. typedef
  67. ULONG
  68. (WDBGAPI*PWINDBG_DISASM)(
  69.     PULONG lpOffset,
  70.     PCSTR  lpBuffer,
  71.     ULONG  fShowEffectiveAddress
  72.     );
  73.  
  74. typedef
  75. ULONG
  76. (WDBGAPI*PWINDBG_CHECK_CONTROL_C)(
  77.     VOID
  78.     );
  79.  
  80. typedef
  81. ULONG
  82. (WDBGAPI*PWINDBG_READ_PROCESS_MEMORY_ROUTINE)(
  83.     ULONG  offset,
  84.     PVOID  lpBuffer,
  85.     ULONG  cb,
  86.     PULONG lpcbBytesRead
  87.     );
  88.  
  89. typedef
  90. ULONG
  91. (WDBGAPI*PWINDBG_WRITE_PROCESS_MEMORY_ROUTINE)(
  92.     ULONG   offset,
  93.     LPCVOID lpBuffer,
  94.     ULONG   cb,
  95.     PULONG  lpcbBytesWritten
  96.     );
  97.  
  98. typedef
  99. ULONG
  100. (WDBGAPI*PWINDBG_GET_THREAD_CONTEXT_ROUTINE)(
  101.     ULONG       Processor,
  102.     PCONTEXT    lpContext,
  103.     ULONG       cbSizeOfContext
  104.     );
  105.  
  106. typedef
  107. ULONG
  108. (WDBGAPI*PWINDBG_SET_THREAD_CONTEXT_ROUTINE)(
  109.     ULONG       Processor,
  110.     PCONTEXT    lpContext,
  111.     ULONG       cbSizeOfContext
  112.     );
  113.  
  114. typedef
  115. ULONG
  116. (WDBGAPI*PWINDBG_IOCTL_ROUTINE)(
  117.     USHORT   IoctlType,
  118.     PVOID    lpvData,
  119.     ULONG    cbSize
  120.     );
  121.  
  122. typedef
  123. ULONG
  124. (WDBGAPI*PWINDBG_OLDKD_READ_PHYSICAL_MEMORY)(
  125.     LARGE_INTEGER    address,
  126.     PVOID            buffer,
  127.     ULONG            count,
  128.     PULONG           bytesread
  129.     );
  130.  
  131. typedef
  132. ULONG
  133. (WDBGAPI*PWINDBG_OLDKD_WRITE_PHYSICAL_MEMORY)(
  134.     LARGE_INTEGER    address,
  135.     PVOID            buffer,
  136.     ULONG            length,
  137.     PULONG           byteswritten
  138.     );
  139.  
  140.  
  141. typedef struct _tagEXTSTACKTRACE {
  142.     ULONG       FramePointer;
  143.     ULONG       ProgramCounter;
  144.     ULONG       ReturnAddress;
  145.     ULONG       Args[4];
  146. } EXTSTACKTRACE, *PEXTSTACKTRACE;
  147.  
  148.  
  149. typedef
  150. ULONG
  151. (*PWINDBG_STACKTRACE_ROUTINE)(
  152.     ULONG             FramePointer,
  153.     ULONG             StackPointer,
  154.     ULONG             ProgramCounter,
  155.     PEXTSTACKTRACE    StackFrames,
  156.     ULONG             Frames
  157.     );
  158.  
  159. typedef struct _WINDBG_EXTENSION_APIS {
  160.     ULONG                                  nSize;
  161.     PWINDBG_OUTPUT_ROUTINE                 lpOutputRoutine;
  162.     PWINDBG_GET_EXPRESSION                 lpGetExpressionRoutine;
  163.     PWINDBG_GET_SYMBOL                     lpGetSymbolRoutine;
  164.     PWINDBG_DISASM                         lpDisasmRoutine;
  165.     PWINDBG_CHECK_CONTROL_C                lpCheckControlCRoutine;
  166.     PWINDBG_READ_PROCESS_MEMORY_ROUTINE    lpReadProcessMemoryRoutine;
  167.     PWINDBG_WRITE_PROCESS_MEMORY_ROUTINE   lpWriteProcessMemoryRoutine;
  168.     PWINDBG_GET_THREAD_CONTEXT_ROUTINE     lpGetThreadContextRoutine;
  169.     PWINDBG_SET_THREAD_CONTEXT_ROUTINE     lpSetThreadContextRoutine;
  170.     PWINDBG_IOCTL_ROUTINE                  lpIoctlRoutine;
  171.     PWINDBG_STACKTRACE_ROUTINE             lpStackTraceRoutine;
  172. } WINDBG_EXTENSION_APIS, *PWINDBG_EXTENSION_APIS;
  173.  
  174. typedef struct _WINDBG_OLD_EXTENSION_APIS {
  175.     ULONG                                  nSize;
  176.     PWINDBG_OUTPUT_ROUTINE                 lpOutputRoutine;
  177.     PWINDBG_GET_EXPRESSION                 lpGetExpressionRoutine;
  178.     PWINDBG_GET_SYMBOL                     lpGetSymbolRoutine;
  179.     PWINDBG_DISASM                         lpDisasmRoutine;
  180.     PWINDBG_CHECK_CONTROL_C                lpCheckControlCRoutine;
  181. } WINDBG_OLD_EXTENSION_APIS, *PWINDBG_OLD_EXTENSION_APIS;
  182.  
  183. typedef struct _WINDBG_OLDKD_EXTENSION_APIS {
  184.     ULONG                                  nSize;
  185.     PWINDBG_OUTPUT_ROUTINE                 lpOutputRoutine;
  186.     PWINDBG_GET_EXPRESSION                 lpGetExpressionRoutine;
  187.     PWINDBG_GET_SYMBOL                     lpGetSymbolRoutine;
  188.     PWINDBG_DISASM                         lpDisasmRoutine;
  189.     PWINDBG_CHECK_CONTROL_C                lpCheckControlCRoutine;
  190.     PWINDBG_READ_PROCESS_MEMORY_ROUTINE    lpReadVirtualMemRoutine;
  191.     PWINDBG_WRITE_PROCESS_MEMORY_ROUTINE   lpWriteVirtualMemRoutine;
  192.     PWINDBG_OLDKD_READ_PHYSICAL_MEMORY     lpReadPhysicalMemRoutine;
  193.     PWINDBG_OLDKD_WRITE_PHYSICAL_MEMORY    lpWritePhysicalMemRoutine;
  194. } WINDBG_OLDKD_EXTENSION_APIS, *PWINDBG_OLDKD_EXTENSION_APIS;
  195.  
  196. typedef
  197. VOID
  198. (WDBGAPI*PWINDBG_OLD_EXTENSION_ROUTINE)(
  199.     HANDLE                  hCurrentProcess,
  200.     HANDLE                  hCurrentThread,
  201.     ULONG                   dwCurrentPc,
  202.     PWINDBG_EXTENSION_APIS  lpExtensionApis,
  203.     PCSTR                   lpArgumentString
  204.     );
  205.  
  206. typedef
  207. VOID
  208. (WDBGAPI*PWINDBG_EXTENSION_ROUTINE)(
  209.     HANDLE                  hCurrentProcess,
  210.     HANDLE                  hCurrentThread,
  211.     ULONG                   dwCurrentPc,
  212.     ULONG                   dwProcessor,
  213.     PCSTR                   lpArgumentString
  214.     );
  215.  
  216. typedef
  217. VOID
  218. (WDBGAPI*PWINDBG_OLDKD_EXTENSION_ROUTINE)(
  219.     ULONG                        dwCurrentPc,
  220.     PWINDBG_OLDKD_EXTENSION_APIS lpExtensionApis,
  221.     PCSTR                        lpArgumentString
  222.     );
  223.  
  224. typedef
  225. VOID
  226. (WDBGAPI*PWINDBG_EXTENSION_DLL_INIT)(
  227.     PWINDBG_EXTENSION_APIS lpExtensionApis,
  228.     USHORT                 MajorVersion,
  229.     USHORT                 MinorVersion
  230.     );
  231.  
  232. typedef
  233. ULONG
  234. (WDBGAPI*PWINDBG_CHECK_VERSION)(
  235.     VOID
  236.     );
  237.  
  238. #define EXT_API_VERSION_NUMBER 5
  239.  
  240. typedef struct EXT_API_VERSION {
  241.     USHORT  MajorVersion;
  242.     USHORT  MinorVersion;
  243.     USHORT  Revision;
  244.     USHORT  Reserved;
  245. } EXT_API_VERSION, *LPEXT_API_VERSION;
  246.  
  247. typedef
  248. LPEXT_API_VERSION
  249. (WDBGAPI*PWINDBG_EXTENSION_API_VERSION)(
  250.     VOID
  251.     );
  252.  
  253. #define IG_KD_CONTEXT               1
  254. #define IG_READ_CONTROL_SPACE       2
  255. #define IG_WRITE_CONTROL_SPACE      3
  256. #define IG_READ_IO_SPACE            4
  257. #define IG_WRITE_IO_SPACE           5
  258. #define IG_READ_PHYSICAL            6
  259. #define IG_WRITE_PHYSICAL           7
  260. #define IG_READ_IO_SPACE_EX         8
  261. #define IG_WRITE_IO_SPACE_EX        9
  262. #define IG_KSTACK_HELP             10   // obsolete
  263. #define IG_SET_THREAD              11
  264. #define IG_READ_MSR                12
  265. #define IG_WRITE_MSR               13
  266. #define IG_GET_DEBUGGER_DATA       14
  267. #define IG_GET_KERNEL_VERSION      15
  268. #define IG_RELOAD_SYMBOLS          16
  269. #define IG_GET_SET_SYMPATH         17
  270. #define IG_GET_EXCEPTION_RECORD    18
  271.  
  272. typedef struct _tagPROCESSORINFO {
  273.     USHORT      Processor;                // current processor
  274.     USHORT      NumberProcessors;         // total number of processors
  275. } PROCESSORINFO, *PPROCESSORINFO;
  276.  
  277. typedef struct _tagREADCONTROLSPACE {
  278.     USHORT      Processor;
  279.     ULONG       Address;
  280.     ULONG       BufLen;
  281.     UCHAR       Buf[1];
  282. } READCONTROLSPACE, *PREADCONTROLSPACE;
  283.  
  284. typedef struct _tagIOSPACE {
  285.     ULONG       Address;
  286.     ULONG       Length;                   // 1, 2, or 4 bytes
  287.     ULONG       Data;
  288. } IOSPACE, *PIOSPACE;
  289.  
  290. typedef struct _tagIOSPACE_EX {
  291.     ULONG       Address;
  292.     ULONG       Length;                   // 1, 2, or 4 bytes
  293.     ULONG       Data;
  294.     ULONG       InterfaceType;
  295.     ULONG       BusNumber;
  296.     ULONG       AddressSpace;
  297. } IOSPACE_EX, *PIOSPACE_EX;
  298.  
  299. typedef struct _tagPHYSICAL {
  300.     LARGE_INTEGER          Address;
  301.     ULONG                  BufLen;
  302.     UCHAR                  Buf[1];
  303. } PHYSICAL, *PPHYSICAL;
  304.  
  305. typedef struct _tagREAD_WRITE_MSR {
  306.     ULONG       Msr;
  307.     LONGLONG    Value;
  308. } READ_WRITE_MSR, *PREAD_WRITE_MSR;
  309.  
  310. typedef struct _tagGET_SET_SYMPATH {
  311.     PCSTR       Args;       // args to !reload command
  312.     PSTR        Result;     // returns new path
  313.     int         Length;     // Length of result buffer
  314. } GET_SET_SYMPATH, *PGET_SET_SYMPATH;
  315.  
  316. #ifdef __cplusplus
  317. #define CPPMOD extern "C"
  318. #else
  319. #define CPPMOD
  320. #endif
  321.  
  322.  
  323. #define DECLARE_API(s)                             \
  324.     CPPMOD VOID                                    \
  325.     s(                                             \
  326.         HANDLE                 hCurrentProcess,    \
  327.         HANDLE                 hCurrentThread,     \
  328.         ULONG                  dwCurrentPc,        \
  329.         ULONG                  dwProcessor,        \
  330.         PCSTR                  args                \
  331.      )
  332.  
  333. #ifndef NOEXTAPI
  334.  
  335. #define dprintf          (ExtensionApis.lpOutputRoutine)
  336. #define GetExpression    (ExtensionApis.lpGetExpressionRoutine)
  337. #define GetSymbol        (ExtensionApis.lpGetSymbolRoutine)
  338. #define Disassm          (ExtensionApis.lpDisasmRoutine)
  339. #define CheckControlC    (ExtensionApis.lpCheckControlCRoutine)
  340. #define ReadMemory       (ExtensionApis.lpReadProcessMemoryRoutine)
  341. #define WriteMemory      (ExtensionApis.lpWriteProcessMemoryRoutine)
  342. #define GetContext       (ExtensionApis.lpGetThreadContextRoutine)
  343. #define SetContext       (ExtensionApis.lpSetThreadContextRoutine)
  344. #define Ioctl            (ExtensionApis.lpIoctlRoutine)
  345. #define StackTrace       (ExtensionApis.lpStackTraceRoutine)
  346.  
  347.  
  348. #define GetKdContext(ppi) \
  349.     Ioctl( IG_KD_CONTEXT, (PVOID)ppi, sizeof(*ppi) )
  350.  
  351. //
  352. // BOOL
  353. // GetDebuggerData(
  354. //     ULONG Tag,
  355. //     PVOID Buf,
  356. //     ULONG Size
  357. //     )
  358. //
  359. /*++
  360.  
  361. Routine Description:
  362.  
  363.  
  364.  
  365. Arguments:
  366.  
  367.  
  368.  
  369. Return Value:
  370.  
  371.  
  372.  
  373. --*/
  374.  
  375. #define GetDebuggerData(TAG, BUF, SIZE)                             \
  376.       ( (((PDBGKD_DEBUG_DATA_HEADER)(BUF))->OwnerTag = (TAG)),      \
  377.         (((PDBGKD_DEBUG_DATA_HEADER)(BUF))->Size = (SIZE)),         \
  378.         Ioctl( IG_GET_DEBUGGER_DATA, (PVOID)(BUF), (SIZE) ) )
  379.  
  380. extern WINDBG_EXTENSION_APIS ExtensionApis;
  381.  
  382. __inline VOID
  383. ReadControlSpace(
  384.     USHORT  processor,
  385.     ULONG   address,
  386.     PVOID   buf,
  387.     ULONG   size
  388.     )
  389. {
  390.     PREADCONTROLSPACE prc;
  391.     prc = (PREADCONTROLSPACE)LocalAlloc(LPTR, sizeof(*prc) + size );
  392.     ZeroMemory( prc->Buf, size );
  393.     prc->Processor = processor;
  394.     prc->Address = (ULONG)address;
  395.     prc->BufLen = size;
  396.     Ioctl( IG_READ_CONTROL_SPACE, (PVOID)prc, sizeof(*prc) + size );
  397.     CopyMemory( buf, prc->Buf, size );
  398.     LocalFree( prc );
  399. }
  400.  
  401. __inline VOID
  402. ReadIoSpace(
  403.     ULONG   address,
  404.     PULONG  data,
  405.     PULONG  size
  406.     )
  407. {
  408.     IOSPACE is;
  409.     is.Address = (ULONG)address;
  410.     is.Length = *size;
  411.     Ioctl( IG_READ_IO_SPACE, (PVOID)&is, sizeof(is) );
  412.     memcpy(data, &is.Data, is.Length);
  413.     *size = is.Length;
  414. }
  415.  
  416. __inline VOID
  417. WriteIoSpace(
  418.     ULONG   address,
  419.     ULONG   data,
  420.     PULONG  size
  421.     )
  422. {
  423.     IOSPACE is;
  424.     is.Address = (ULONG)address;
  425.     is.Length = *size;
  426.     is.Data = data;
  427.     Ioctl( IG_WRITE_IO_SPACE, (PVOID)&is, sizeof(is) );
  428.     *size = is.Length;
  429. }
  430.  
  431. __inline VOID
  432. ReadIoSpaceEx(
  433.     ULONG   address,
  434.     PULONG  data,
  435.     PULONG  size,
  436.     ULONG   interfacetype,
  437.     ULONG   busnumber,
  438.     ULONG   addressspace
  439.     )
  440. {
  441.     IOSPACE_EX is;
  442.     is.Address = (ULONG)address;
  443.     is.Length = *size;
  444.     is.Data = 0;
  445.     is.InterfaceType = interfacetype;
  446.     is.BusNumber = busnumber;
  447.     is.AddressSpace = addressspace;
  448.     Ioctl( IG_READ_IO_SPACE_EX, (PVOID)&is, sizeof(is) );
  449.     *data = is.Data;
  450.     *size = is.Length;
  451. }
  452.  
  453. __inline VOID
  454. WriteIoSpaceEx(
  455.     ULONG   address,
  456.     ULONG   data,
  457.     PULONG  size,
  458.     ULONG   interfacetype,
  459.     ULONG   busnumber,
  460.     ULONG   addressspace
  461.     )
  462. {
  463.     IOSPACE_EX is;
  464.     is.Address = (ULONG)address;
  465.     is.Length = *size;
  466.     is.Data = data;
  467.     is.InterfaceType = interfacetype;
  468.     is.BusNumber = busnumber;
  469.     is.AddressSpace = addressspace;
  470.     Ioctl( IG_WRITE_IO_SPACE_EX, (PVOID)&is, sizeof(is) );
  471.     *size = is.Length;
  472. }
  473.  
  474. __inline VOID
  475. ReadPhysical(
  476.     LARGE_INTEGER       address,
  477.     PVOID               buf,
  478.     ULONG               size,
  479.     PULONG              sizer
  480.     )
  481. {
  482.     PPHYSICAL phy;
  483.     phy = (PPHYSICAL)LocalAlloc(LPTR,  sizeof(*phy) + size );
  484.     ZeroMemory( phy->Buf, size );
  485.     phy->Address = address;
  486.     phy->BufLen = size;
  487.     Ioctl( IG_READ_PHYSICAL, (PVOID)phy, sizeof(*phy) + size );
  488.     *sizer = phy->BufLen;
  489.     CopyMemory( buf, phy->Buf, *sizer );
  490.     LocalFree( phy );
  491. }
  492.  
  493. __inline VOID
  494. WritePhysical(
  495.     LARGE_INTEGER       address,
  496.     PVOID               buf,
  497.     ULONG               size,
  498.     PULONG              sizew
  499.     )
  500. {
  501.     PPHYSICAL phy;
  502.     phy = (PPHYSICAL)LocalAlloc(LPTR, sizeof(*phy) + size );
  503.     ZeroMemory( phy->Buf, size );
  504.     phy->Address = address;
  505.     phy->BufLen = size;
  506.     CopyMemory( phy->Buf, buf, size );
  507.     Ioctl( IG_WRITE_PHYSICAL, (PVOID)phy, sizeof(*phy) + size );
  508.     *sizew = phy->BufLen;
  509.     LocalFree( phy );
  510. }
  511.  
  512. __inline VOID
  513. SetThreadForOperation(
  514.     PULONG Thread
  515.     )
  516. {
  517.     Ioctl(IG_SET_THREAD, (PVOID)Thread, sizeof(ULONG));
  518. }
  519.  
  520. __inline VOID
  521. ReadMsr(
  522.     ULONG       MsrReg,
  523.     ULONGLONG   *MsrValue
  524.     )
  525. {
  526.     PREAD_WRITE_MSR msr;
  527.     LARGE_INTEGER li;
  528.  
  529.     msr = (PREAD_WRITE_MSR)LocalAlloc(LPTR,  sizeof(*msr));
  530.     msr->Msr = MsrReg;
  531.     Ioctl( IG_READ_MSR, (PVOID)msr, sizeof(*msr) );
  532.  
  533.     *MsrValue = msr->Value;
  534.     LocalFree( msr );
  535. }
  536.  
  537. __inline VOID
  538. WriteMsr(
  539.     ULONG       MsrReg,
  540.     ULONGLONG   MsrValue
  541.     )
  542. {
  543.     PREAD_WRITE_MSR msr;
  544.  
  545.     msr = (PREAD_WRITE_MSR)LocalAlloc(LPTR,  sizeof(*msr));
  546.     msr->Msr = MsrReg;
  547.     msr->Value = MsrValue;
  548.     Ioctl( IG_WRITE_MSR, (PVOID)msr, sizeof(*msr) );
  549.     LocalFree( msr );
  550. }
  551.  
  552. __inline VOID
  553. ReloadSymbols(
  554.     IN PSTR Arg OPTIONAL
  555.     )
  556. /*++
  557.  
  558. Routine Description:
  559.  
  560.     Calls the debugger to reload symbols.
  561.  
  562. Arguments:
  563.  
  564.     Args - Supplies the tail of a !reload command string.
  565.  
  566.         !reload [flags] [module[=address]]
  567.         flags:   /n  do not load from usermode list
  568.                  /u  unload symbols, no reload
  569.                  /v  verbose
  570.  
  571.         A value of NULL is equivalent to an empty string
  572.  
  573. Return Value:
  574.  
  575.     None
  576.  
  577. --*/
  578. {
  579.     Ioctl(IG_RELOAD_SYMBOLS, (PVOID)Arg, Arg?(strlen(Arg)+1):0);
  580. }
  581.  
  582. __inline VOID
  583. GetSetSympath(
  584.     IN PSTR Arg,
  585.     OUT PSTR Result OPTIONAL,
  586.     IN int Length
  587.     )
  588. /*++
  589.  
  590. Routine Description:
  591.  
  592.     Calls the debugger to set or retrieve symbol search path.
  593.  
  594. Arguments:
  595.  
  596.     Arg - Supplies new search path.  If Arg is NULL or string is empty,
  597.             the search path is not changed and the current setting is
  598.             returned in Result.  When the symbol search path is changed,
  599.             a call to ReloadSymbols is made implicitly.
  600.  
  601.     Result - OPTIONAL Returns the symbol search path setting.
  602.  
  603.     Length - Supplies the size of the buffer supplied by Result.
  604.  
  605. Return Value:
  606.  
  607.     None
  608.  
  609. --*/
  610. {
  611.     GET_SET_SYMPATH gss;
  612.     gss.Args = Arg;
  613.     gss.Result = Result;
  614.     gss.Length = Length;
  615.     Ioctl(IG_GET_SET_SYMPATH, (PVOID)&gss, sizeof(gss));
  616. }
  617.  
  618.  
  619. #endif
  620.  
  621.  
  622. #ifdef __cplusplus
  623. }
  624. #endif
  625.  
  626. #pragma option pop /*P_O_Pop*/
  627. #endif // _WDBGEXTS_
  628.