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.

355 lines
11 KiB

  1. /*++
  2. Copyright (c) 1995 Microsoft Corporation
  3. All rights reserved.
  4. Module Name:
  5. debug.hxx
  6. Abstract:
  7. Standard debug header.
  8. Author:
  9. Albert Ting (AlbertT) 19-Feb-1995
  10. Revision History:
  11. --*/
  12. extern HANDLE hCurrentProcess;
  13. extern WINDBG_EXTENSION_APIS ExtensionApis;
  14. extern PWINDBG_OUTPUT_ROUTINE Print;
  15. extern PWINDBG_GET_EXPRESSION EvalExpression;
  16. extern PWINDBG_GET_SYMBOL GetSymbolRtn;
  17. extern PWINDBG_CHECK_CONTROL_C CheckControlCRtn;
  18. extern BOOL bWindbg;
  19. enum DEBUG_EXT_FLAG {
  20. DEBUG_GLOBAL= 1,
  21. };
  22. enum DEBUG_TRACE {
  23. DEBUG_TRACE_NONE = 0,
  24. DEBUG_TRACE_BT = 1, // Dump backtrace
  25. DEBUG_TRACE_DBGMSG = 2, // Format as DBGMSG
  26. DEBUG_TRACE_HEX = 4 // Hex output
  27. };
  28. #define DEBUG_EXT_CLASS_PROTOTYPE( dumpfunc ) \
  29. static BOOL \
  30. dumpfunc( \
  31. PVOID pObject, \
  32. ULONG_PTR dwAddr \
  33. )
  34. typedef struct DEBUG_FLAGS {
  35. LPSTR pszFlag;
  36. ULONG_PTR dwFlag;
  37. } *PDEBUG_FLAGS;
  38. typedef struct DEBUG_VALUES {
  39. LPSTR pszValue;
  40. ULONG_PTR dwValue;
  41. } *PDEBUG_VALUES;
  42. class TDebugExt {
  43. public:
  44. enum CONSTANTS {
  45. kMaxCallFrame = 0x4000,
  46. //
  47. // Flags for LC.
  48. //
  49. kLCFlagAll = 0x1,
  50. kLCVerbose = 0x2,
  51. //
  52. // Constant for FP.
  53. // Must be power of 2.
  54. //
  55. kFPGranularity = 0x1000,
  56. //
  57. // When strings are read, we try and read kStringDefaultMax.
  58. // If we can't get a string, then we may be at the end of a page,
  59. // so read up until the last kStringChunk.
  60. //
  61. // kStringChunk must be a power of 2.
  62. //
  63. kStringDefaultMax = MAX_PATH,
  64. kStringChunk = 0x100
  65. };
  66. //
  67. // Generic Debug routines (debug.cxx)
  68. //
  69. static VOID
  70. vDumpPDL(
  71. PDLINK pDLink
  72. );
  73. static VOID
  74. vDumpStr(
  75. LPCWSTR pszString
  76. );
  77. static VOID
  78. vDumpStrA(
  79. LPCSTR pszString
  80. );
  81. static VOID
  82. vDumpFlags(
  83. ULONG_PTR dwFlags,
  84. PDEBUG_FLAGS pDebugFlags
  85. );
  86. static VOID
  87. vDumpValue(
  88. ULONG_PTR dwValue,
  89. PDEBUG_VALUES pDebugValues
  90. );
  91. static VOID
  92. vDumpTime(
  93. const SYSTEMTIME& st
  94. );
  95. static VOID
  96. vDumpTrace(
  97. ULONG_PTR dwAddress
  98. );
  99. static ULONG_PTR
  100. dwEval(
  101. LPSTR& lpArgumentString,
  102. BOOL bParam = FALSE
  103. );
  104. static ULONG_PTR
  105. dwEvalParam(
  106. LPSTR& lpArgumentString
  107. )
  108. {
  109. return dwEval( lpArgumentString, TRUE );
  110. }
  111. //
  112. // Generic extensions.
  113. //
  114. static VOID
  115. vCreateRemoteThread(
  116. HANDLE hProcess,
  117. ULONG_PTR dwAddr,
  118. ULONG_PTR dwParm
  119. );
  120. static VOID
  121. vFindPointer(
  122. HANDLE hProcess,
  123. ULONG_PTR dwStartAddr,
  124. ULONG_PTR dwEndAddr,
  125. ULONG_PTR dwStartPtr,
  126. ULONG_PTR dwEndPtr
  127. );
  128. static VOID
  129. vLookCalls(
  130. HANDLE hProcess,
  131. HANDLE hThread,
  132. ULONG_PTR dwAddr,
  133. ULONG_PTR dwLength,
  134. ULONG_PTR dwFlags
  135. );
  136. //
  137. // SplLib debug routines.
  138. //
  139. DEBUG_EXT_CLASS_PROTOTYPE( bDumpCritSec );
  140. DEBUG_EXT_CLASS_PROTOTYPE( bDumpDbgPointers );
  141. static VOID
  142. vDumpMem(
  143. LPCSTR pszFile
  144. );
  145. static BOOL
  146. bDumpDebugTrace(
  147. ULONG_PTR dwLineAddr,
  148. COUNT Count,
  149. PDWORD pdwSkip,
  150. DWORD DebugTrace,
  151. DWORD DebugFlags,
  152. DWORD dwThreadId,
  153. ULONG_PTR dwMem
  154. );
  155. static BOOL
  156. bDumpBackTrace(
  157. ULONG_PTR dwAddr,
  158. COUNT Count,
  159. PDWORD pdwSkip,
  160. DWORD DebugTrace,
  161. DWORD DebugFlags,
  162. DWORD dwThreadId,
  163. ULONG_PTR dwMem
  164. );
  165. //
  166. // Localspl debug routines
  167. //
  168. DEBUG_EXT_CLASS_PROTOTYPE( bDumpIniSpooler );
  169. DEBUG_EXT_CLASS_PROTOTYPE( bDumpIniPrinter );
  170. DEBUG_EXT_CLASS_PROTOTYPE( bDumpIniPrintProc );
  171. DEBUG_EXT_CLASS_PROTOTYPE( bDumpIniDriver );
  172. DEBUG_EXT_CLASS_PROTOTYPE( bDumpIniVersion );
  173. DEBUG_EXT_CLASS_PROTOTYPE( bDumpIniEnvironment );
  174. DEBUG_EXT_CLASS_PROTOTYPE( bDumpIniMonitor );
  175. DEBUG_EXT_CLASS_PROTOTYPE( bDumpIniJob );
  176. DEBUG_EXT_CLASS_PROTOTYPE( bDumpIniPort );
  177. DEBUG_EXT_CLASS_PROTOTYPE( bDumpSpool );
  178. DEBUG_EXT_CLASS_PROTOTYPE( bDumpDevMode );
  179. DEBUG_EXT_CLASS_PROTOTYPE( bDumpDevModeA );
  180. //
  181. // PrintUI
  182. //
  183. DEBUG_EXT_CLASS_PROTOTYPE( bDumpUNotify );
  184. DEBUG_EXT_CLASS_PROTOTYPE( bDumpUPrinter );
  185. };
  186. #define DEBUG_EXT_FUNC(func) \
  187. VOID \
  188. func( \
  189. HANDLE hCurrentProcess, \
  190. HANDLE hCurrentThread, \
  191. ULONG_PTR dwCurrentPc, \
  192. PWINDBG_EXTENSION_APIS lpExtensionApis, \
  193. LPSTR lpArgumentString \
  194. )
  195. #define DEBUG_EXT_HEAD( func ) \
  196. extern "C" DEBUG_EXT_FUNC( func )
  197. VOID
  198. vDumpTraceWithFlags(
  199. LPSTR lpArgumentString,
  200. ULONG_PTR dwAddress
  201. );
  202. /********************************************************************
  203. Setup the global variables.
  204. ********************************************************************/
  205. #define DEBUG_EXT_SETUP_VARS() \
  206. if( !bWindbg && lpExtensionApis ){ \
  207. ::ExtensionApis = *lpExtensionApis; \
  208. } \
  209. ::Print = ExtensionApis.lpOutputRoutine; \
  210. ::EvalExpression = ExtensionApis.lpGetExpressionRoutine; \
  211. ::GetSymbolRtn = ExtensionApis.lpGetSymbolRoutine; \
  212. ::CheckControlCRtn = ExtensionApis.lpCheckControlCRoutine; \
  213. ::hCurrentProcess = hCurrentProcess
  214. /*++
  215. Routine Description:
  216. Handles default parsing of simple structures.
  217. Arguments:
  218. struct - Name of the structure do be dumped. Must not be of
  219. variable size.
  220. var - Variable name that receives a stack buffer of the struct type.
  221. expr - Input string, usually the arguement string.
  222. default - String for default parameter if no parameters given
  223. (or evaluates to zero). If the function needs to take a
  224. "special action" (such as dumping all printers on the local
  225. spooler), then use the string gszSpecialAction. The value
  226. -1 will be passed to the dump function.
  227. offset - Offset to actual structure (using for baes/derived classes).
  228. bAllowNull - Indicates whether a NULL address should be passed to
  229. the dump function.
  230. Return Value:
  231. --*/
  232. #define DEBUG_EXT_SETUP_SIMPLE( struct, \
  233. var, \
  234. expr, \
  235. default, \
  236. offset, \
  237. bAllowNull ) \
  238. \
  239. UNREFERENCED_PARAMETER( hCurrentThread ); \
  240. UNREFERENCED_PARAMETER( dwCurrentPc ); \
  241. \
  242. DEBUG_EXT_SETUP_VARS(); \
  243. \
  244. PBYTE var = NULL; \
  245. if( expr ){ \
  246. var = (PBYTE)EvalExpression( expr ); \
  247. } \
  248. \
  249. BYTE struct##Buf[sizeof( struct )]; \
  250. \
  251. if( !var ) { \
  252. if( default ){ \
  253. var = (PBYTE)EvalExpression( default ); \
  254. move2( &var, var, sizeof( PVOID )); \
  255. } \
  256. \
  257. if( !var ){ \
  258. if( !bAllowNull ){ \
  259. Print( "<Null address>\n" ); \
  260. return; \
  261. } \
  262. } else { \
  263. Print( "<Default: %hs>\n", default ); \
  264. } \
  265. } \
  266. \
  267. var -= offset; \
  268. \
  269. ULONG_PTR dwAddr = (ULONG_PTR)var; \
  270. \
  271. if( var ){ \
  272. Print( "%x (offset %x) ", var, offset ); \
  273. \
  274. move( struct##Buf, var ); \
  275. var = struct##Buf; \
  276. }
  277. #define DEBUG_EXT_ENTRY( func, struct, dumpfunc, default, bAllowNull ) \
  278. DEBUG_EXT_HEAD( func ) \
  279. { \
  280. DEBUG_EXT_SETUP_SIMPLE( struct, \
  281. p##struct, \
  282. lpArgumentString, \
  283. default, \
  284. 0, \
  285. bAllowNull ); \
  286. if( !TDebugExt::dumpfunc( p##struct, dwAddr )){ \
  287. Print( "Unknown signature.\n" ); \
  288. } \
  289. }