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.

317 lines
8.4 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. dumpers.hxx
  5. Abstract:
  6. This header file declares type dumper classes.
  7. Author:
  8. JasonHa
  9. --*/
  10. #ifndef _DUMPERS_HXX_
  11. #define _DUMPERS_HXX_
  12. class ScanDumper;
  13. class PrintfFormat;
  14. template <class T, int Spec> class PrintfTypeFormat;
  15. template <class T, int PrintSpec> class ArrayDumper;
  16. /**************************************************************************\
  17. *
  18. * class ScanDumper
  19. *
  20. \**************************************************************************/
  21. ULONG WallArrayEntryCallback(PFIELD_INFO pField, ScanDumper *pScanDumper);
  22. ULONG LeftWallCallback( PFIELD_INFO pField, ScanDumper *pScanDumper);
  23. ULONG RightWallCallback( PFIELD_INFO pField, ScanDumper *pScanDumper);
  24. #define SCAN_CWALLS 0
  25. #define SCAN_YTOP 1
  26. #define SCAN_YBOTTOM 2
  27. #define SCAN_AI_X_ADDR 3
  28. #define SCAN_FIELDS_LENGTH 4
  29. extern const FIELD_INFO ScanFieldsInit[SCAN_FIELDS_LENGTH];
  30. extern const SYM_DUMP_PARAM ScanSymInit;
  31. extern const FIELD_INFO WallFieldsInit[1];
  32. extern const SYM_DUMP_PARAM WallSymInit;
  33. #define SCAN_DUMPER_NO_PRINT 0x00000001
  34. #define SCAN_DUMPER_FORCE 0x00000002
  35. #define SCAN_DUMPER_FROM_TAIL 0x00000004
  36. #define SCAN_VALID_AT_START 0x00000001
  37. #define SCAN_VALID_AT_END 0x00000002
  38. #define SCAN_VALID_NO_ERROR_PRINT 0x00000004
  39. #define SCAN_VALID_DEFAULT SCAN_VALID_AT_START
  40. #define SCAN_VALID_EXCLUSIVE 0x00000000
  41. #define SCAN_VALID_INCLUSIVE (SCAN_VALID_AT_START | SCAN_VALID_AT_END)
  42. class ScanDumper
  43. {
  44. public:
  45. ScanDumper(ULONG64 HeadScanAddr = 0,
  46. ULONG64 TailScanAddr = -1,
  47. ULONG ScanCount = 0,
  48. ULONG64 AllocationBase = -1,
  49. ULONG64 AllocationLimit = -1,
  50. ULONG Flags = 0);
  51. // Will dump Count scans since head scan or last scan dumped.
  52. // If FROM_TAIL flag used begin dump at tail scan or last scna dumped.
  53. BOOL DumpScans(ULONG Count = 1);
  54. // Below several functions can be used hand
  55. // scans/walls to ScanDumper one at a time.
  56. // Mark start of scan dump
  57. void Reset() { block = 0; scan = -1; Bottom = NEG_INFINITY; Valid = TRUE; };
  58. // Set yTop, yBottom and expected number of walls
  59. BOOL ScanAdvance(LONG Top, LONG Bottom, ULONG NumWalls)
  60. {
  61. return (Reverse ?
  62. PrevScan(Top, Bottom, NumWalls) :
  63. NextScan(Top, Bottom, NumWalls));
  64. }
  65. // Set yTop, yBottom and expected number of walls
  66. // Validate yTop and yBottom as next sequential scan
  67. BOOL NextScan(LONG NextTop, LONG NextBottom, ULONG NumWalls);
  68. // Set yTop, yBottom and expected number of walls
  69. // Validate yTop and yBottom as previous sequential scan
  70. BOOL PrevScan(LONG PrevTop, LONG PrevBottom, ULONG NumWalls);
  71. // Specify walls in order alternating between left and right.
  72. // Sending cWalls2 member should be sent to NextLeftWall
  73. ULONG NextLeftWall(LONG NextLeft);
  74. ULONG NextRightWall(LONG NextLeft);
  75. // Check if address is within below allocation limit.
  76. ULONG ValidateAddress(ULONG64 Address, const char *pszAddrName = NULL, ULONG Flags = SCAN_VALID_DEFAULT);
  77. // Have all checks passed since creation or Reset()?
  78. BOOL IsValid() { return Valid; }
  79. public:
  80. ULONG64 ScanAddr;
  81. LONG block;
  82. LONG scan;
  83. LONG Top;
  84. LONG Bottom;
  85. LONG Left;
  86. LONG PrevRight;
  87. ULONG cWalls;
  88. ULONG64 FirstScanAddr;
  89. ULONG64 LastScanAddr;
  90. ULONG ScanLimit;
  91. BOOL NegativeScanCount;
  92. ULONG64 AddressBase;
  93. ULONG64 AddressLimit;
  94. BOOL PrintBlocks;
  95. BOOL ForceDump;
  96. BOOL Reverse;
  97. private:
  98. BOOL CanDump;
  99. ULONG wall;
  100. FIELD_INFO ScanFields[SCAN_FIELDS_LENGTH];
  101. SYM_DUMP_PARAM ScanSym;
  102. FIELD_INFO ListWallSize;
  103. FIELD_INFO WallFields[1];
  104. SYM_DUMP_PARAM WallSym;
  105. SYM_DUMP_PARAM cWalls2Sym;
  106. ULONG ScanSize;
  107. ULONG cWallsSize;
  108. ULONG IXSize;
  109. BOOL PrintProgress;
  110. ULONG ProgressCount;
  111. BOOL Valid;
  112. };
  113. /**************************************************************************\
  114. *
  115. * class PrintfFormat
  116. *
  117. \**************************************************************************/
  118. class PrintfFormat
  119. {
  120. public:
  121. PrintfFormat()
  122. {
  123. Width = -1;
  124. IsDirty = TRUE;
  125. Format[0] = 0;
  126. }
  127. const char *GetFormat()
  128. {
  129. if (IsDirty)
  130. {
  131. ComposeFormat();
  132. }
  133. return Format;
  134. };
  135. operator const char *()
  136. {
  137. return GetFormat();
  138. }
  139. void SetWidth(int PrintWidth = -1)
  140. {
  141. IsDirty = TRUE;
  142. Width = PrintWidth;
  143. };
  144. protected:
  145. virtual void ComposeFormat() = 0;
  146. int Width;
  147. BOOL IsDirty;
  148. char Format[24];
  149. };
  150. /**************************************************************************\
  151. *
  152. * class PrintfTypeFormat
  153. *
  154. \**************************************************************************/
  155. #define PRINT_FORMAT_CHARACTER 0x0001
  156. #define PRINT_FORMAT_HEX 0x0002
  157. #define PRINT_FORMAT_SIGNED 0x0004
  158. #define PRINT_FORMAT_UNSIGNED 0x0008
  159. #define PRINT_FORMAT_POINTER 0x0010
  160. #define PRINT_FORMAT_CHARARRAY 0x0020
  161. #define PRINT_FORMAT_1BYTE 0x0100
  162. #define PRINT_FORMAT_2BYTES 0x0200
  163. #define PRINT_FORMAT_4BYTES 0x0400
  164. #define PRINT_FORMAT_8BYTES 0x0800
  165. #define PRINT_FORMAT_CHAR (PRINT_FORMAT_CHARACTER | PRINT_FORMAT_1BYTE )
  166. #define PRINT_FORMAT_WCHAR (PRINT_FORMAT_CHARACTER | PRINT_FORMAT_2BYTES )
  167. #define PRINT_FORMAT_STRING (PRINT_FORMAT_CHARARRAY | PRINT_FORMAT_1BYTE )
  168. #define PRINT_FORMAT_WSTRING (PRINT_FORMAT_CHARARRAY | PRINT_FORMAT_2BYTES )
  169. #define PRINT_FORMAT_BYTE (PRINT_FORMAT_HEX | PRINT_FORMAT_1BYTE )
  170. #define PRINT_FORMAT_WORD (PRINT_FORMAT_HEX | PRINT_FORMAT_2BYTES )
  171. #define PRINT_FORMAT_DWORD (PRINT_FORMAT_HEX | PRINT_FORMAT_4BYTES )
  172. #define PRINT_FORMAT_DWORD64 (PRINT_FORMAT_HEX | PRINT_FORMAT_8BYTES )
  173. #define PRINT_FORMAT_SHORT (PRINT_FORMAT_SIGNED | PRINT_FORMAT_2BYTES )
  174. #define PRINT_FORMAT_LONG (PRINT_FORMAT_SIGNED | PRINT_FORMAT_4BYTES )
  175. #define PRINT_FORMAT_LONG64 (PRINT_FORMAT_SIGNED | PRINT_FORMAT_8BYTES )
  176. #define PRINT_FORMAT_USHORT (PRINT_FORMAT_UNSIGNED | PRINT_FORMAT_2BYTES )
  177. #define PRINT_FORMAT_ULONG (PRINT_FORMAT_UNSIGNED | PRINT_FORMAT_4BYTES )
  178. #define PRINT_FORMAT_ULONG64 (PRINT_FORMAT_UNSIGNED | PRINT_FORMAT_8BYTES )
  179. #define FormatTemplate(Type) Type, PRINT_FORMAT_##Type
  180. template <class T, int Spec = PRINT_FORMAT_DWORD>
  181. class PrintfTypeFormat : public PrintfFormat
  182. {
  183. public:
  184. PrintfTypeFormat();
  185. protected:
  186. void ComposeFormat();
  187. };
  188. /**************************************************************************\
  189. *
  190. * class ArrayDumper
  191. *
  192. \**************************************************************************/
  193. #define DecArrayDumper(Name, Type) ArrayDumper<FormatTemplate(Type)> Name(Client);
  194. template <class T, int PrintSpec>
  195. class ArrayDumper : public ExtApiClass
  196. {
  197. public:
  198. ArrayDumper(PDEBUG_CLIENT DbgClient = NULL) : ExtApiClass(DbgClient) {
  199. Length = 0;
  200. ArrayBuffer = NULL;
  201. Dummy = (T)0;
  202. }
  203. ~ArrayDumper() {
  204. HeapFree(GetProcessHeap(), 0, ArrayBuffer);
  205. }
  206. BOOL ReadArray(const char * SymbolName);
  207. ULONG GetLength() { return Length; };
  208. T& operator[](ULONG Index) {
  209. return (Index < Length) ? ArrayBuffer[Index] : Dummy;
  210. }
  211. const char * GetPrintFormat() {
  212. return (const char *)PrintFormat;
  213. }
  214. const char * SetPrintFormat(int Width)
  215. {
  216. PrintFormat.SetWidth(Width);
  217. return GetPrintFormat();
  218. }
  219. BOOL PrintAt(ULONG Index)
  220. {
  221. if (Index < Length)
  222. {
  223. ExtOut(PrintFormat, ArrayBuffer[Index]);
  224. return TRUE;
  225. }
  226. ExtVerb("Warning: Attempting to print beyond array bounds.\n");
  227. return FALSE;
  228. }
  229. const char *GetStringValueAt(ULONG Index) { return StringValue; };
  230. private:
  231. ULONG Length;
  232. T *ArrayBuffer;
  233. T Dummy;
  234. char StringValue[24];
  235. PrintfTypeFormat<T, PrintSpec> PrintFormat;
  236. };
  237. #endif _DUMPERS_HXX_