Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

230 lines
7.6 KiB

  1. /*++
  2. Copyright (c) 1990, 1998 Microsoft Corporation
  3. Module Name:
  4. ptdbgext.h
  5. *WAS* kdextlib.h
  6. Abstract:
  7. Kernel Debugger extensions to allow the quick creation of CDB/Windbg
  8. debugger extensions. Used in conjunction with the following:
  9. transdbg.h - Minimal debugging extension helper macros
  10. ptdbgext.h - Auto dump of classes and structures
  11. _dbgdump.h - Used to define struct/class descriptors in 1 pass
  12. Author:
  13. Balan Sethu Raman (SethuR) 11-May-1994
  14. Revision History:
  15. 11-Nov-1994 SethuR Created
  16. 21-Aug-1995 Milans Copied for use in Mup Kernel Extensions
  17. 19-April-1998 Mikeswa Modified for Exchange Platinum Transport
  18. --*/
  19. #ifndef _PTDBGEXT_H_
  20. #define _PTDBGEXT_H_
  21. #include <windef.h>
  22. #include <transdbg.h>
  23. #ifndef PTDBGEXT_USE_FRIEND_CLASSES
  24. #include <_dbgdump.h>
  25. #endif //PTDBGEXT_USE_FRIEND_CLASSES
  26. #ifdef __cplusplus
  27. extern "C" {
  28. #endif //__cplusplus
  29. //If you not include ntdefs.h, you will need this, otherwise set _ANSI_UNICODE_STRINGS_DEFINED_
  30. #ifndef _ANSI_UNICODE_STRINGS_DEFINED_
  31. //Define string types needed
  32. typedef struct _ANSI_STRING {
  33. USHORT Length;
  34. USHORT MaximumLength;
  35. PCHAR Buffer;
  36. } ANSI_STRING;
  37. typedef ANSI_STRING *PANSI_STRING;
  38. typedef struct _UNICODE_STRING {
  39. USHORT Length;
  40. USHORT MaximumLength;
  41. PWSTR Buffer;
  42. } UNICODE_STRING;
  43. typedef UNICODE_STRING *PUNICODE_STRING;
  44. typedef const UNICODE_STRING *PCUNICODE_STRING;
  45. #define UNICODE_NULL ((WCHAR)0) // winnt
  46. #endif //_ANSI_UNICODE_STRINGS_DEFINED_
  47. #define PT_DEBUG_EXTENSION(x) TRANS_DEBUG_EXTENSION(x)
  48. //Define potentially exported functions... include those you want to expose in your def file
  49. extern PT_DEBUG_EXTENSION(_help); //display help based on ExtensionNames & Extensions
  50. extern PT_DEBUG_EXTENSION(_dump); //Dumps structs/classes as defined by macros in _dbgdump.h
  51. extern PT_DEBUG_EXTENSION(_dumpoffsets); //Dumps offsets of structs/classes as defined by macros in _dbgdump.h
  52. #define DEFINE_EXPORTED_FUNCTIONS \
  53. PT_DEBUG_EXTENSION(help) { _help(DebugArgs);}; \
  54. PT_DEBUG_EXTENSION(dump) { _dump(DebugArgs);};
  55. //
  56. // The help strings printed out
  57. //
  58. extern LPSTR ExtensionNames[];
  59. extern LPSTR Extensions[];
  60. //
  61. // The FIELD_DESCRIPTOR data structure is used to describe the field in a structure sufficiently
  62. // for displaying information during debugging. The three pieces of information that are required
  63. // are 1) the name of the field, 2) the offset in the corresponding structure and 3) a type descriptor.
  64. // The type descriptor covers most primitive types.
  65. //
  66. // There are some types that can benefit from some auxillary information in the descriptors. A
  67. // case in point is the "enum" defeinition. Merely printing out a numerical value for an enum
  68. // type will invariably force the person using these extensions to refer to the corresponding
  69. // include file. In order to avoid this we will accept an additional array for enum types that
  70. // contains a textual description of the numerical value. A "bit mask" type falls in the same
  71. // category. For the puposes of this extension lib, a "enum" and "bit mask" may be
  72. // interchanged. The key difference is that an "enum" will tested for a single value, while
  73. // a "bit mask" will be testes using a bitwise OR against all values. The ENUM_VALUE_DESCRIPTOR
  74. // and BIT_MASK_DESCRIPTOR are interchangable.
  75. //
  76. // The macros to define the necessary structures can be found in _dbgdump.h.
  77. //
  78. typedef struct _ENUM_VALUE_DESCRIPTOR {
  79. ULONG EnumValue;
  80. LPSTR EnumName;
  81. } ENUM_VALUE_DESCRIPTOR;
  82. typedef struct _BIT_MASK_DESCRIPTOR {
  83. ULONG BitmaskValue;
  84. LPSTR BitmaskName;
  85. } BIT_MASK_DESCRIPTOR;
  86. typedef enum _FIELD_TYPE_CLASS {
  87. FieldTypeByte,
  88. FieldTypeChar,
  89. FieldTypeBoolean,
  90. FieldTypeBool,
  91. FieldTypeULong,
  92. FieldTypeLong,
  93. FieldTypeUShort,
  94. FieldTypeShort,
  95. FieldTypeGuid,
  96. FieldTypePointer,
  97. FieldTypePWStr, //used for LPWSTR fields
  98. FieldTypePStr, //used for LPSTR fields
  99. FieldTypeWStrBuffer, //used for WCHAR[] fields
  100. FieldTypeStrBuffer, //used for CHAR[] fields
  101. FieldTypeUnicodeString,
  102. FieldTypeAnsiString,
  103. FieldTypeSymbol,
  104. FieldTypeEnum,
  105. FieldTypeByteBitMask,
  106. FieldTypeWordBitMask,
  107. FieldTypeDWordBitMask,
  108. FieldTypeFloat,
  109. FieldTypeDouble,
  110. FieldTypeStruct,
  111. FieldTypeLargeInteger,
  112. FieldTypeClassSignature,
  113. FieldTypeDword,
  114. FieldTypeListEntry,
  115. FieldTypeFiletime, //Displays file time in human-readable format
  116. FieldTypeLocalizedFiletime, //As above, but adjusts for TZ first
  117. FieldTypeEmbeddedStruct, //dumps an embedded structure (4th param is struct array)
  118. FieldTypeNULL
  119. } FIELD_TYPE_CLASS, *PFIELD_TYPE_CLASS;
  120. typedef struct _FIELD_DESCRIPTOR_ {
  121. FIELD_TYPE_CLASS FieldType; // The type of variable to be printed
  122. LPSTR Name; // The name of the field
  123. ULONG Offset; // The offset of the field in the structure
  124. union {
  125. VOID *pDescriptor; // Generic Auxillary information - used by Field4 macro
  126. ENUM_VALUE_DESCRIPTOR *pEnumValueDescriptor; // Auxillary information for enumerated types.
  127. BIT_MASK_DESCRIPTOR *pBitMaskDescriptor; // Auxillary information for bitmasks.
  128. VOID *pStructDescriptor;
  129. } AuxillaryInfo;
  130. } FIELD_DESCRIPTOR;
  131. #define NULL_FIELD {FieldTypeNULL, NULL, 0, NULL}
  132. //
  133. // The structs that are displayed by the debugger extensions are further
  134. // described in another array. Each entry in the array contains the name of
  135. // the structure and the associated Field descriptor list.
  136. //
  137. typedef struct _STRUCT_DESCRITOR_ {
  138. LPSTR StructName;
  139. ULONG StructSize;
  140. FIELD_DESCRIPTOR *FieldDescriptors;
  141. } STRUCT_DESCRIPTOR;
  142. //
  143. // The array of structs handled by the debugger extension.
  144. //
  145. extern STRUCT_DESCRIPTOR Structs[];
  146. extern PWINDBG_OUTPUT_ROUTINE g_lpOutputRoutine;
  147. extern PWINDBG_GET_EXPRESSION g_lpGetExpressionRoutine;
  148. extern PWINDBG_GET_SYMBOL g_lpGetSymbolRoutine;
  149. extern PWINDBG_READ_PROCESS_MEMORY_ROUTINE g_lpReadMemoryRoutine;
  150. extern HANDLE g_hCurrentProcess;
  151. typedef PWINDBG_OLD_EXTENSION_ROUTINE PEXTLIB_INIT_ROUTINE;
  152. extern PEXTLIB_INIT_ROUTINE g_pExtensionInitRoutine;
  153. #define SETCALLBACKS() \
  154. g_lpOutputRoutine = pExtensionApis->lpOutputRoutine; \
  155. g_lpGetExpressionRoutine = pExtensionApis->lpGetExpressionRoutine; \
  156. g_lpGetSymbolRoutine = pExtensionApis->lpGetSymbolRoutine; \
  157. g_hCurrentProcess = hCurrentProcess; \
  158. g_lpReadMemoryRoutine = \
  159. ((pExtensionApis->nSize == sizeof(WINDBG_OLD_EXTENSION_APIS)) ? \
  160. NULL : pExtensionApis->lpReadProcessMemoryRoutine); \
  161. g_pExtensionInitRoutine ? (g_pExtensionInitRoutine)(dwCurrentPc, pExtensionApis, szArg) : 0;
  162. #define KdExtReadMemory(a,b,c,d) \
  163. ((g_lpReadMemoryRoutine) ? \
  164. g_lpReadMemoryRoutine( (DWORD_PTR)(a), (b), (c), ((DWORD *)d) ) \
  165. : ReadProcessMemory( g_hCurrentProcess, (LPCVOID)(a), (b), (c), (d) )) \
  166. #define PRINTF g_lpOutputRoutine
  167. VOID
  168. PrintStructFields(
  169. DWORD_PTR dwAddress,
  170. VOID *ptr,
  171. FIELD_DESCRIPTOR *pFieldDescriptors,
  172. DWORD cIndentLevel
  173. );
  174. BOOL
  175. PrintStringW(
  176. LPSTR msg,
  177. PUNICODE_STRING puStr,
  178. BOOL nl
  179. );
  180. BOOLEAN
  181. GetData(
  182. DWORD_PTR dwAddress,
  183. PVOID ptr,
  184. ULONG size
  185. );
  186. #ifdef __cplusplus
  187. }
  188. #endif //__cplusplus
  189. #endif // _PTDBGEXT_H_