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.

282 lines
7.7 KiB

  1. /*++
  2. Copyright (C) Microsoft Corporation, 1997 - 2001
  3. Module Name:
  4. rpcexts.h
  5. Abstract:
  6. Common stuff for RPC debugger extensions
  7. Author:
  8. Mario Goertzel [MarioGo]
  9. Revision History:
  10. MarioGo 3/21/1997 Bits 'n pieces
  11. GrigoriK 3/2001 Rewrote to support type information
  12. --*/
  13. #ifndef _RPCEXTS_HXX_
  14. #define _RPCEXTS_HXX_
  15. extern BOOL bUnextend;
  16. #define Unextend(Val) if (bUnextend) Val = (ULONG64)(ULONG)Val
  17. // Reads a pointer, and then unextends the top 32 bits if the platform
  18. // is not 64-bit.
  19. BOOL ReadPtrUnextend(ULONG64 Addr, PULONG64 pVal);
  20. #define MIN(x, y) ( ((x) < (y)) ? x:y )
  21. #define MAX(x, y) ( ((x) >= (y)) ? x:y )
  22. #define MY_DECLARE_API(_x_) \
  23. DECLARE_API( _x_ )\
  24. {\
  25. ULONG64 qwAddr;\
  26. qwAddr = GetExpression(args);\
  27. if ( !qwAddr ) {\
  28. dprintf("Error: Failure to get address\n");\
  29. return;\
  30. }\
  31. do_##_x_(qwAddr);\
  32. return;}
  33. extern BOOL fUseTypeInfo;
  34. extern int AddressSize;
  35. extern BOOL fSpew;
  36. // The maximum number of items from a dictionary that we will print.
  37. // This prevents huge loops when symbols are busted.
  38. #define MAX_ITEMS_IN_DICTIONARY (128)
  39. #define GET_RPC_VAR(VarName) \
  40. fUseTypeInfo ? GetVar("RPCRT4!"#VarName) : VarName
  41. #define GET_TYPE_SIZE(Type, TypeName) \
  42. fUseTypeInfo ? GetTypeSize(#TypeName) : sizeof(Type)
  43. #define PRINT_SIZE(Type, TypeName) \
  44. dprintf(#Type" - 0x%x\n", GET_TYPE_SIZE(Type, TypeName));
  45. #define PRINT_RPC_TYPE_SIZE(Type) \
  46. dprintf(#Type" - 0x%x\n", GET_TYPE_SIZE(Type, RPCRT4!Type));
  47. #define GET_MEMBER_TYPE_INFO(Addr, TypeString, FieldString, ULONG64Value) \
  48. { \
  49. if (GetFieldValue(Addr, #TypeString, #FieldString, ULONG64Value)) \
  50. { \
  51. dprintf("Unable to get field "#FieldString" of type "#TypeString" at 0x%I64x\n", Addr); \
  52. return; \
  53. } \
  54. Unextend(ULONG64Value); \
  55. }
  56. #define GET_MEMBER_TYPE_INFO_NORET(Addr, TypeString, FieldString, ULONG64Value) \
  57. { \
  58. if (GetFieldValue(Addr, #TypeString, #FieldString, ULONG64Value)) \
  59. { \
  60. dprintf("Unable to get field "#FieldString" of type "#TypeString" at 0x%I64x\n", Addr); \
  61. } \
  62. Unextend(ULONG64Value); \
  63. }
  64. #define GET_MEMBER_TYPE_INFO_NORET_NOSPEW(Addr, TypeString, FieldString, ULONG64Value) \
  65. { \
  66. if (GetFieldValue(Addr, #TypeString, #FieldString, ULONG64Value)) \
  67. { \
  68. if (fSpew) \
  69. { \
  70. dprintf("Unable to get field "#FieldString" of type "#TypeString" at 0x%I64x\n", Addr); \
  71. dprintf("Disabling debugger spew...\n"); \
  72. fSpew = FALSE; \
  73. } \
  74. } \
  75. Unextend(ULONG64Value); \
  76. }
  77. #define GET_MEMBER_HARDCODED(Addr, Type, Field, ULONG64Value) \
  78. { \
  79. if (ReadPtrUnextend((ULONG64)&(((Type*)Addr)->Field), &ULONG64Value)) \
  80. { \
  81. dprintf("Unable to read address 0x%I64x\n", &(((Type*)Addr)->Field)); \
  82. return; \
  83. } \
  84. Unextend(ULONG64Value); \
  85. }
  86. #define GET_MEMBER_HARDCODED_NORET(Addr, Type, Field, ULONG64Value) \
  87. { \
  88. if (ReadPtrUnextend((ULONG64)&(((Type*)Addr)->Field), &ULONG64Value)) \
  89. { \
  90. dprintf("Unable to read address 0x%I64x\n", &(((Type*)Addr)->Field)); \
  91. } \
  92. }
  93. #define GET_MEMBER_HARDCODED_NORET_NOSPEW(Addr, Type, Field, ULONG64Value) \
  94. { \
  95. if (ReadPtrUnextend((ULONG64)&(((Type*)Addr)->Field), &ULONG64Value)) \
  96. { \
  97. if (fSpew) \
  98. { \
  99. dprintf("Unable to read address 0x%I64x\n", &(((Type*)Addr)->Field)); \
  100. dprintf("Disabling debugger spew...\n"); \
  101. fSpew = FALSE; \
  102. } \
  103. } \
  104. Unextend(ULONG64Value); \
  105. }
  106. #define GET_MEMBER(Addr, Type, TypeString, Field, ULONG64Value) \
  107. { \
  108. if (fUseTypeInfo) \
  109. { \
  110. GET_MEMBER_TYPE_INFO(Addr, TypeString, Field, ULONG64Value); \
  111. } \
  112. else \
  113. { \
  114. GET_MEMBER_HARDCODED(Addr, Type, Field, ULONG64Value); \
  115. } \
  116. }
  117. #define GET_MEMBER_NORET(Addr, Type, TypeString, Field, ULONG64Value) \
  118. { \
  119. if (fUseTypeInfo) \
  120. { \
  121. GET_MEMBER_TYPE_INFO_NORET(Addr, TypeString, Field, ULONG64Value); \
  122. } \
  123. else \
  124. { \
  125. GET_MEMBER_HARDCODED_NORET(Addr, Type, Field, ULONG64Value); \
  126. } \
  127. }
  128. #define GET_MEMBER_NORET_NOSPEW(Addr, Type, TypeString, Field, ULONG64Value) \
  129. { \
  130. if (fUseTypeInfo) \
  131. { \
  132. GET_MEMBER_TYPE_INFO_NORET_NOSPEW(Addr, TypeString, Field, ULONG64Value); \
  133. } \
  134. else \
  135. { \
  136. GET_MEMBER_HARDCODED_NORET_NOSPEW(Addr, Type, Field, ULONG64Value); \
  137. } \
  138. }
  139. #define PRINT_MEMBER(Addr, Type, TypeString, Field, ULONG64Value) \
  140. { \
  141. GET_MEMBER(Addr, Type, TypeString, Field, ULONG64Value); \
  142. dprintf(#Field" - 0x%I64x\n", ULONG64Value); \
  143. }
  144. #define PRINT_MEMBER_DECIMAL_AND_HEX(Addr, Type, TypeString, Field, ULONG64Value) \
  145. { \
  146. GET_MEMBER(Addr, Type, TypeString, Field, ULONG64Value); \
  147. dprintf(#Field" - %I64d 0x%I64x\n", ULONG64Value, ULONG64Value); \
  148. }
  149. #define PRINT_MEMBER_WITH_LABEL(Addr, Type, TypeString, Field, Label, ULONG64Value) \
  150. { \
  151. GET_MEMBER(Addr, Type, TypeString, Field, ULONG64Value); \
  152. dprintf("%s - 0x%I64x\n", Label, ULONG64Value); \
  153. }
  154. #define PRINT_MEMBER_BOOLEAN(Addr, Type, TypeString, Field, ULONG64Value) \
  155. { \
  156. GET_MEMBER(Addr, Type, TypeString, Field, ULONG64Value); \
  157. dprintf(#Field" - %s\n", BoolString((BOOL)ULONG64Value)); \
  158. }
  159. #define PRINT_MEMBER_BOOLEAN_WITH_LABEL(Addr, Type, TypeString, Field, Label, ULONG64Value) \
  160. { \
  161. GET_MEMBER(Addr, Type, TypeString, Field, ULONG64Value); \
  162. dprintf("%s - %s\n", Label, BoolString((BOOL)ULONG64Value)); \
  163. }
  164. #define PRINT_MEMBER_SYMBOL(Addr, Type, TypeString, Field, ULONG64Value) \
  165. { \
  166. GET_MEMBER(Addr, Type, TypeString, Field, ULONG64Value); \
  167. dprintf(#Field" - %s\n", MapSymbol(ULONG64Value)); \
  168. }
  169. #define PRINT_OFFSET(yy, _x_) \
  170. {dprintf(#_x_" - 0x%x\n", ((ULONG_PTR)qwAddr+offsetof(yy, _x_)));}
  171. #define GET_OFFSET_OF(Type, TypeString, Field, Offset) \
  172. { \
  173. if (fUseTypeInfo) \
  174. { \
  175. GetFieldOffset(#TypeString, #Field, Offset); \
  176. } \
  177. else \
  178. { \
  179. *Offset = offsetof(Type, Field); \
  180. } \
  181. }
  182. #define GET_ADDRESS_OF(qwAddr, Type, TypeString, Field, FieldAddr, ULONGtmp) \
  183. { \
  184. GET_OFFSET_OF(Type, TypeString, Field, &ULONGtmp); \
  185. FieldAddr = qwAddr + ULONGtmp; \
  186. }
  187. #define PRINT_ADDRESS_OF(qwAddr, Type, TypeString, Field, ULONGtmp) \
  188. { \
  189. GET_OFFSET_OF(Type, TypeString, Field, &ULONGtmp); \
  190. dprintf(#Field" - 0x%I64x\n", qwAddr + ULONGtmp); \
  191. }
  192. #define PRINT_ADDRESS_OF_WITH_LABEL(qwAddr, Type, TypeString, Field, Label, ULONGtmp) \
  193. { \
  194. GET_OFFSET_OF(Type, TypeString, Field, &ULONGtmp); \
  195. dprintf(Label" - 0x%I64x\n", qwAddr + ULONGtmp); \
  196. }
  197. extern ULONG GetTypeSize(PUCHAR TypeName);
  198. extern ULONG64 GetVar(PCSTR VarName);
  199. extern char *
  200. BoolString(
  201. BOOL Value
  202. );
  203. extern
  204. PCHAR
  205. MapSymbol(ULONG64);
  206. extern
  207. RPC_CHAR *
  208. ReadProcessRpcChar(
  209. ULONG64 qwAddr
  210. );
  211. extern
  212. BOOL
  213. GetData(IN ULONG64 qwAddress, IN LPVOID ptr, IN ULONG size);
  214. extern
  215. char *
  216. strtok(
  217. char *String
  218. );
  219. // defines a variable of a given type without invoking its constructor - just a placeholder
  220. // large enough for the class. Have in mind that it is allocated on the stack
  221. #define NO_CONSTRUCTOR_TYPE(structName, var) \
  222. unsigned char buf##structName[sizeof(structName)]; \
  223. structName *var = (structName *)buf##structName;
  224. #endif