Source code of Windows XP (NT5)
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.

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