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.

254 lines
7.4 KiB

  1. /*++
  2. Copyright (c) 1998-2000 Microsoft Corporation
  3. Module Name:
  4. precomp.hxx
  5. Abstract:
  6. Common header file for LKRDBG component source files.
  7. Author:
  8. George V. Reilly (GeorgeRe) 24-Mar-2000
  9. Revision History:
  10. --*/
  11. #ifndef __PRECOMP_HXX__
  12. #define __PRECOMP_HXX__
  13. #include <windows.h>
  14. #include <ntsdexts.h>
  15. // TODO: use wdbgexts.h instead of ntsdexts.h
  16. // #include <wdbgexts.h>
  17. #include <stdio.h>
  18. #include <stdlib.h>
  19. #include <string.h>
  20. #include <stdlib.h>
  21. //
  22. // To obtain the private & protected members of C++ class,
  23. // let me fake the "private" keyword
  24. //
  25. # define private public
  26. # define protected public
  27. #define IRTL_DLLEXP
  28. #define IRTL_EXPIMP
  29. #define DLL_IMPLEMENTATION
  30. #define IMPLEMENTATION_EXPORT
  31. #include <lkrhash.h>
  32. /************************************************************
  33. * Macro Definitions
  34. ************************************************************/
  35. #define DBGEXT "lkrdbg"
  36. // For use as arguments to '%c%c%c%c'
  37. #define DECODE_SIGNATURE(dw) \
  38. isprint(((dw) >> 0) & 0xFF) ? (((dw) >> 0) & 0xFF) : '?', \
  39. isprint(((dw) >> 8) & 0xFF) ? (((dw) >> 8) & 0xFF) : '?', \
  40. isprint(((dw) >> 16) & 0xFF) ? (((dw) >> 16) & 0xFF) : '?', \
  41. isprint(((dw) >> 24) & 0xFF) ? (((dw) >> 24) & 0xFF) : '?'
  42. #define move(dst, src)\
  43. __try {\
  44. ReadMemory((LPVOID) (src), &(dst), sizeof(dst), NULL);\
  45. } __except (EXCEPTION_EXECUTE_HANDLER) {\
  46. return;\
  47. }
  48. #define moveBlock(dst, src, size)\
  49. __try {\
  50. ReadMemory((LPVOID) (src), &(dst), (size), NULL);\
  51. } __except (EXCEPTION_EXECUTE_HANDLER) {\
  52. return;\
  53. }
  54. #define MoveWithRet(dst, src, retVal)\
  55. __try {\
  56. ReadMemory((LPVOID) (src), &(dst), sizeof(dst), NULL);\
  57. } __except (EXCEPTION_EXECUTE_HANDLER) {\
  58. return retVal;\
  59. }
  60. #define MoveBlockWithRet(dst, src, size, retVal)\
  61. __try {\
  62. ReadMemory((LPVOID) (src), &(dst), (size), NULL);\
  63. } __except (EXCEPTION_EXECUTE_HANDLER) {\
  64. return retVal;\
  65. }
  66. #ifdef __cplusplus
  67. #define CPPMOD extern "C"
  68. #else
  69. #define CPPMOD
  70. #endif
  71. #ifndef DECLARE_API
  72. # define DECLARE_API(s) \
  73. CPPMOD VOID \
  74. s( \
  75. HANDLE hCurrentProcess, \
  76. HANDLE hCurrentThread, \
  77. DWORD dwCurrentPc, \
  78. PNTSD_EXTENSION_APIS lpExtensionApis, \
  79. LPSTR lpArgumentString \
  80. )
  81. #endif
  82. #define INIT_API() { \
  83. ExtensionApis = *lpExtensionApis; \
  84. ExtensionCurrentProcess = hCurrentProcess; \
  85. }
  86. #define dprintf (ExtensionApis.lpOutputRoutine)
  87. #define GetExpression (ExtensionApis.lpGetExpressionRoutine)
  88. #define GetSymbol (ExtensionApis.lpGetSymbolRoutine)
  89. #define Disasm (ExtensionApis.lpDisasmRoutine)
  90. #define CheckControlC (ExtensionApis.lpCheckControlCRoutine)
  91. #define ReadMemory(a,b,c,d) ReadProcessMemory( ExtensionCurrentProcess, (LPCVOID)(a), (b), (c), (d) )
  92. #define WriteMemory(a,b,c,d) WriteProcessMemory( ExtensionCurrentProcess, (LPVOID)(a), (LPVOID)(b), (c), (d) )
  93. #ifndef malloc
  94. # define malloc( n ) HeapAlloc( GetProcessHeap(), 0, (n) )
  95. #endif
  96. #ifndef calloc
  97. # define calloc( n , s) HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, (n)*(s) )
  98. #endif
  99. #ifndef realloc
  100. # define realloc( p, n ) HeapReAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, (p), (n) )
  101. #endif
  102. #ifndef free
  103. # define free( p ) HeapFree( GetProcessHeap(), 0, (p) )
  104. #endif
  105. #define MAX_SYMBOL_LEN 1024
  106. #define BoolValue( b) ((b) ? " TRUE" : " FALSE")
  107. #define DumpDword( symbol ) \
  108. { \
  109. ULONG_PTR dw = GetExpression( "&" symbol ); \
  110. ULONG_PTR dwValue = 0; \
  111. \
  112. if ( dw ) \
  113. { \
  114. if ( ReadMemory( (LPVOID) dw, \
  115. &dwValue, \
  116. sizeof(dwValue), \
  117. NULL )) \
  118. { \
  119. dprintf( "\t" symbol " = %8d (0x%p)\n", \
  120. dwValue, \
  121. dwValue ); \
  122. } \
  123. } \
  124. }
  125. //
  126. // C++ Structures typically require the constructors and most times
  127. // we may not have default constructors
  128. // => trouble in defining a copy of these struct/class inside the
  129. // Debugger extension DLL for debugger process
  130. // So we will define them as CHARACTER arrays with appropriate sizes.
  131. // This is okay, since we are not really interested in structure as is,
  132. // however, we will copy over data block from the debuggee process to
  133. // these structure variables in the debugger process.
  134. //
  135. # define DEFINE_CPP_VAR( className, classVar) \
  136. CHAR classVar[sizeof(className)]
  137. # define GET_CPP_VAR_PTR( className, classVar) \
  138. (className * ) &classVar[0]
  139. /************************************************************
  140. * Prototype Definitions
  141. ************************************************************/
  142. extern NTSD_EXTENSION_APIS ExtensionApis;
  143. extern HANDLE ExtensionCurrentProcess;
  144. VOID dstring( CHAR * pszName, PVOID pvString, DWORD cbLen);
  145. VOID Print2Dwords( CHAR * pszN1, DWORD d1,
  146. CHAR * pszN2, DWORD d2
  147. );
  148. VOID PrintUsage( IN PSTR CommandName );
  149. //
  150. // Determine if a linked list is empty.
  151. //
  152. #define IS_LIST_EMPTY( localaddr, remoteaddr, type, fieldname ) \
  153. ( ((type *)(localaddr))->fieldname.Flink == \
  154. (PLIST_ENTRY)( (remoteaddr) + \
  155. FIELD_OFFSET( type, fieldname ) ) )
  156. //
  157. // Enumerator for NT's standard doubly linked list LIST_ENTRY
  158. //
  159. // PFN_LIST_ENUMERATOR
  160. // This is the callback function for printing the CLIENT_CONN object.
  161. //
  162. // Arguments:
  163. // pvDebuggee - pointer to object in the debuggee process
  164. // pvDebugger - pointer to object in the debugger process
  165. // verbosity - character indicating the verbosity level desired
  166. //
  167. typedef
  168. VOID
  169. (CALLBACK * PFN_LIST_ENUMERATOR)(
  170. IN PVOID pvDebugee,
  171. IN PVOID pvDebugger,
  172. IN CHAR chVerbosity, //verbosity value supplied for the enumerator
  173. IN DWORD iCount //index for the item being enumerated
  174. );
  175. BOOL
  176. EnumLinkedList(
  177. IN LIST_ENTRY * pListHead,
  178. IN PFN_LIST_ENUMERATOR pfnListEnumerator,
  179. IN CHAR chVerbosity,
  180. IN DWORD cbSizeOfStructure,
  181. IN DWORD cbListEntryOffset
  182. );
  183. // Functions from dbglocks.cxx
  184. const char*
  185. LockName(
  186. LOCK_LOCKTYPE lt);
  187. int
  188. LockSize(
  189. LOCK_LOCKTYPE lt);
  190. BOOL
  191. PrintLock(
  192. LOCK_LOCKTYPE lt,
  193. IN PVOID pvLock,
  194. IN INT nVerbose);
  195. #endif // __PRECOMP_HXX__