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.

429 lines
11 KiB

  1. // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
  2. // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
  3. // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
  4. // PARTICULAR PURPOSE.
  5. //
  6. // Copyright 1996 - 2003 Microsoft Corporation. All Rights Reserved.
  7. //
  8. // FILE: Debug.cpp
  9. //
  10. //
  11. // PURPOSE: Debug functions.
  12. //
  13. //
  14. // Functions:
  15. //
  16. //
  17. //
  18. // PLATFORMS: Windows 2000, Windows XP, Windows Server 2003
  19. //
  20. //
  21. #include "precomp.h"
  22. #include "oem.h"
  23. #include "debug.h"
  24. // StrSafe.h needs to be included last
  25. // to disallow bad string functions.
  26. #include <STRSAFE.H>
  27. ////////////////////////////////////////////////////////
  28. // INTERNAL DEFINES
  29. ////////////////////////////////////////////////////////
  30. #define DEBUG_BUFFER_SIZE 1024
  31. #define PATH_SEPARATOR '\\'
  32. #define MAX_LOOP 10
  33. // Determine what level of debugging messages to eject.
  34. #ifdef VERBOSE_MSG
  35. #define DEBUG_LEVEL DBG_VERBOSE
  36. #elif TERSE_MSG
  37. #define DEBUG_LEVEL DBG_TERSE
  38. #elif WARNING_MSG
  39. #define DEBUG_LEVEL DBG_WARNING
  40. #elif ERROR_MSG
  41. #define DEBUG_LEVEL DBG_ERROR
  42. #elif RIP_MSG
  43. #define DEBUG_LEVEL DBG_RIP
  44. #elif NO_DBG_MSG
  45. #define DEBUG_LEVEL DBG_NONE
  46. #else
  47. #define DEBUG_LEVEL DBG_WARNING
  48. #endif
  49. ////////////////////////////////////////////////////////
  50. // EXTERNAL GLOBALS
  51. ////////////////////////////////////////////////////////
  52. INT giDebugLevel = DEBUG_LEVEL;
  53. ////////////////////////////////////////////////////////
  54. // INTERNAL PROTOTYPES
  55. ////////////////////////////////////////////////////////
  56. static BOOL DebugMessageV(LPCSTR lpszMessage, va_list arglist);
  57. static BOOL DebugMessageV(DWORD dwSize, LPCWSTR lpszMessage, va_list arglist);
  58. //////////////////////////////////////////////////////////////////////////
  59. // Function: DebugMessageV
  60. //
  61. // Description: Outputs variable argument debug string.
  62. //
  63. //
  64. // Parameters:
  65. //
  66. // dwSize Size of temp buffer to hold formated string.
  67. //
  68. // lpszMessage Format string.
  69. //
  70. // arglist Variable argument list..
  71. //
  72. //
  73. // Returns:
  74. //
  75. //
  76. // Comments:
  77. //
  78. //
  79. // History:
  80. // 12/18/96 APresley Created.
  81. //
  82. //////////////////////////////////////////////////////////////////////////
  83. static BOOL DebugMessageV(LPCSTR lpszMessage, va_list arglist)
  84. {
  85. DWORD dwSize = DEBUG_BUFFER_SIZE;
  86. DWORD dwLoop = 0;
  87. LPSTR lpszMsgBuf = NULL;
  88. HRESULT hr;
  89. // Parameter checking.
  90. if( (NULL == lpszMessage)
  91. ||
  92. (0 == dwSize)
  93. )
  94. {
  95. return FALSE;
  96. }
  97. do
  98. {
  99. // Allocate memory for message buffer.
  100. if(NULL != lpszMsgBuf)
  101. {
  102. delete[] lpszMsgBuf;
  103. dwSize *= 2;
  104. }
  105. lpszMsgBuf = new CHAR[dwSize + 1];
  106. if(NULL == lpszMsgBuf)
  107. {
  108. return FALSE;
  109. }
  110. hr = StringCbVPrintfA(lpszMsgBuf, (dwSize + 1) * sizeof(CHAR), lpszMessage, arglist);
  111. // Pass the variable parameters to wvsprintf to be formated.
  112. } while (FAILED(hr) && (STRSAFE_E_INSUFFICIENT_BUFFER == hr) && (++dwLoop < MAX_LOOP) );
  113. // Dump string to Debug output.
  114. OutputDebugStringA(lpszMsgBuf);
  115. // Cleanup.
  116. delete[] lpszMsgBuf;
  117. return SUCCEEDED(hr);
  118. }
  119. //////////////////////////////////////////////////////////////////////////
  120. // Function: DebugMessageV
  121. //
  122. // Description: Outputs variable argument debug string.
  123. //
  124. //
  125. // Parameters:
  126. //
  127. // dwSize Size of temp buffer to hold formated string.
  128. //
  129. // lpszMessage Format string.
  130. //
  131. // arglist Variable argument list..
  132. //
  133. //
  134. // Returns:
  135. //
  136. //
  137. // Comments:
  138. //
  139. //
  140. // History:
  141. // 12/18/96 APresley Created.
  142. //
  143. //////////////////////////////////////////////////////////////////////////
  144. static BOOL DebugMessageV(DWORD dwSize, LPCWSTR lpszMessage, va_list arglist)
  145. {
  146. LPWSTR lpszMsgBuf;
  147. HRESULT hResult;
  148. // Parameter checking.
  149. if( (NULL == lpszMessage)
  150. ||
  151. (0 == dwSize)
  152. )
  153. {
  154. return FALSE;
  155. }
  156. // Allocate memory for message buffer.
  157. lpszMsgBuf = new WCHAR[dwSize + 1];
  158. if(NULL == lpszMsgBuf)
  159. return FALSE;
  160. // Pass the variable parameters to wvsprintf to be formated.
  161. hResult = StringCbVPrintfW(lpszMsgBuf, (dwSize + 1) * sizeof(WCHAR), lpszMessage, arglist);
  162. // Dump string to debug output.
  163. OutputDebugStringW(lpszMsgBuf);
  164. // Clean up.
  165. delete[] lpszMsgBuf;
  166. return SUCCEEDED(hResult);
  167. }
  168. //////////////////////////////////////////////////////////////////////////
  169. // Function: DebugMessage
  170. //
  171. // Description: Outputs variable argument debug string.
  172. //
  173. //
  174. // Parameters:
  175. //
  176. // lpszMessage Format string.
  177. //
  178. //
  179. // Returns:
  180. //
  181. //
  182. // Comments:
  183. //
  184. //
  185. // History:
  186. // 12/18/96 APresley Created.
  187. //
  188. //////////////////////////////////////////////////////////////////////////
  189. BOOL DebugMessage(LPCSTR lpszMessage, ...)
  190. {
  191. BOOL bResult;
  192. va_list VAList;
  193. // Pass the variable parameters to DebugMessageV for processing.
  194. va_start(VAList, lpszMessage);
  195. bResult = DebugMessageV(lpszMessage, VAList);
  196. va_end(VAList);
  197. return bResult;
  198. }
  199. //////////////////////////////////////////////////////////////////////////
  200. // Function: DebugMessage
  201. //
  202. // Description: Outputs variable argument debug string.
  203. //
  204. //
  205. // Parameters:
  206. //
  207. // lpszMessage Format string.
  208. //
  209. //
  210. // Returns:
  211. //
  212. //
  213. // Comments:
  214. //
  215. //
  216. // History:
  217. // 12/18/96 APresley Created.
  218. //
  219. //////////////////////////////////////////////////////////////////////////
  220. BOOL DebugMessage(LPCWSTR lpszMessage, ...)
  221. {
  222. BOOL bResult;
  223. va_list VAList;
  224. // Pass the variable parameters to DebugMessageV to be processed.
  225. va_start(VAList, lpszMessage);
  226. bResult = DebugMessageV(MAX_PATH, lpszMessage, VAList);
  227. va_end(VAList);
  228. return bResult;
  229. }
  230. void Dump(PPUBLISHERINFO pPublisherInfo)
  231. {
  232. VERBOSE(TEXT("pPublisherInfo:\r\n"));
  233. if(NULL == pPublisherInfo)
  234. {
  235. VERBOSE(TEXT("\tpPublisherInfo is NULL!\r\n"));
  236. return;
  237. }
  238. VERBOSE(TEXT("\tdwMode = %#x\r\n"), pPublisherInfo->dwMode);
  239. VERBOSE(TEXT("\twMinoutlinePPEM = %d\r\n"), pPublisherInfo->wMinoutlinePPEM);
  240. VERBOSE(TEXT("\twMaxbitmapPPEM = %d\r\n"), pPublisherInfo->wMaxbitmapPPEM);
  241. }
  242. void Dump(POEMDMPARAM pOemDMParam)
  243. {
  244. VERBOSE(TEXT("pOemDMParam:\r\n"));
  245. if(NULL == pOemDMParam)
  246. {
  247. VERBOSE(TEXT("\tpOemDMParam is NULL!\r\n"));
  248. return;
  249. }
  250. VERBOSE(TEXT("\tcbSize = %d\r\n"), pOemDMParam->cbSize);
  251. VERBOSE(TEXT("\tpdriverobj = %#x\r\n"), pOemDMParam->pdriverobj);
  252. VERBOSE(TEXT("\thPrinter = %#x\r\n"), pOemDMParam->hPrinter);
  253. VERBOSE(TEXT("\thModule = %#x\r\n"), pOemDMParam->hModule);
  254. VERBOSE(TEXT("\tpPublicDMIn = %#x\r\n"), pOemDMParam->pPublicDMIn);
  255. VERBOSE(TEXT("\tpPublicDMOut = %#x\r\n"), pOemDMParam->pPublicDMOut);
  256. VERBOSE(TEXT("\tpOEMDMIn = %#x\r\n"), pOemDMParam->pOEMDMIn);
  257. VERBOSE(TEXT("\tpOEMDMOut = %#x\r\n"), pOemDMParam->pOEMDMOut);
  258. VERBOSE(TEXT("\tcbBufSize = %d\r\n"), pOemDMParam->cbBufSize);
  259. }
  260. void Dump(PPROPSHEETUI_INFO pPSUIInfo)
  261. {
  262. VERBOSE(TEXT("pPSUIInfo:\r\n"));
  263. if(NULL == pPSUIInfo)
  264. {
  265. VERBOSE(TEXT("\tpPSUIInfo is NULL!\r\n"));
  266. return;
  267. }
  268. VERBOSE(TEXT("\tcbSize = %d\r\n"), pPSUIInfo->cbSize);
  269. VERBOSE(TEXT("\tVersion = %#x\r\n"), pPSUIInfo->Version);
  270. VERBOSE(TEXT("\tFlags = %#x\r\n"), pPSUIInfo->Flags);
  271. VERBOSE(TEXT("\tReason = %d\r\n"), pPSUIInfo->Reason);
  272. VERBOSE(TEXT("\thComPropSheet = %#x\r\n"), pPSUIInfo->hComPropSheet);
  273. VERBOSE(TEXT("\tpfnComPropSheet = %#x\r\n"), pPSUIInfo->pfnComPropSheet);
  274. VERBOSE(TEXT("\tlParamInit = %#x\r\n"), pPSUIInfo->lParamInit);
  275. VERBOSE(TEXT("\tUserData = %#x\r\n"), pPSUIInfo->UserData);
  276. VERBOSE(TEXT("\tResult = %#x\r\n"), pPSUIInfo->Result);
  277. }
  278. void Dump(POPTITEM pOptItem)
  279. {
  280. VERBOSE(TEXT("pOptItem:\r\n"));
  281. if(NULL == pOptItem)
  282. {
  283. VERBOSE(TEXT("\tpOptItem is NULL!\r\n"));
  284. return;
  285. }
  286. VERBOSE(TEXT("\tcbSize = %d\r\n"), pOptItem->cbSize);
  287. VERBOSE(TEXT("\tLevel = %d\r\n"), pOptItem->Level);
  288. VERBOSE(TEXT("\tDlgPageIdx = %d\r\n"), pOptItem->DlgPageIdx);
  289. VERBOSE(TEXT("\tFlags = 0x%x\r\n"), pOptItem->Flags);
  290. VERBOSE(TEXT("\tUserData = 0x%p\r\n"), pOptItem->UserData);
  291. VERBOSE(TEXT("\tpName = %s\r\n"), pOptItem->pName ? pOptItem->pName : TEXT("<NULL>"));
  292. VERBOSE(TEXT("\tpSel = 0x%p\r\n"), pOptItem->pSel);
  293. VERBOSE(TEXT("\tpExtChkBox = 0x%p\r\n"), pOptItem->pExtChkBox);
  294. VERBOSE(TEXT("\tpExtChkBox = 0x%p\r\n"), pOptItem->pExtChkBox);
  295. VERBOSE(TEXT("\tHelpIndex = 0x%x\r\n"), pOptItem->HelpIndex);
  296. VERBOSE(TEXT("\tDMPubID = 0x%x\r\n"), pOptItem->DMPubID);
  297. VERBOSE(TEXT("\tUserItemID = 0x%x\r\n"), pOptItem->UserItemID);
  298. VERBOSE(TEXT("\twReserved = 0x%x\r\n"), pOptItem->wReserved);
  299. VERBOSE(TEXT("\tpOIExt = 0x%p\r\n"), pOptItem->pOIExt);
  300. Dump(pOptItem->pOptType);
  301. }
  302. void Dump(POPTTYPE pOptType)
  303. {
  304. VERBOSE(TEXT("\tpOptType:\r\n"));
  305. if(NULL == pOptType)
  306. {
  307. VERBOSE(TEXT("\t\tpOptType is NULL!\r\n"));
  308. return;
  309. }
  310. VERBOSE(TEXT("\t\tcbSize = %d\r\n"), pOptType->cbSize);
  311. VERBOSE(TEXT("\t\tType = 0x%x\r\n"), pOptType->Type);
  312. VERBOSE(TEXT("\t\tFlags = 0x%x\r\n"), pOptType->Flags);
  313. VERBOSE(TEXT("\t\tCount = %d\r\n"), pOptType->Count);
  314. VERBOSE(TEXT("\t\tCount = 0x%x\r\n"), pOptType->BegCtrlID);
  315. VERBOSE(TEXT("\t\tStyle = 0x%x\r\n"), pOptType->Style);
  316. Dump(pOptType->pOptParam, pOptType->Count);
  317. }
  318. void Dump(POPTPARAM pOptParam, WORD wCount)
  319. {
  320. if(NULL == pOptParam)
  321. {
  322. VERBOSE(TEXT("\t\tpOptParam is NULL!\r\n"));
  323. return;
  324. }
  325. for(WORD wIndex = 0; wIndex < wCount; ++wIndex)
  326. {
  327. VERBOSE(TEXT("\t\tpOptParam[wIndex]:\r\n"));
  328. VERBOSE(TEXT("\t\t\tcbSize = %d\r\n"), pOptParam[wIndex].cbSize);
  329. VERBOSE(TEXT("\t\t\tFlags = 0x%x\r\n"), pOptParam[wIndex].Flags);
  330. VERBOSE(TEXT("\t\t\tStyle = 0x%x\r\n"), pOptParam[wIndex].Style);
  331. VERBOSE(TEXT("\t\t\tpData = 0x%p\r\n"), pOptParam[wIndex].pData);
  332. VERBOSE(TEXT("\t\t\tIconID = 0x%p\r\n"), pOptParam[wIndex].IconID);
  333. VERBOSE(TEXT("\t\t\tlParam = 0x%p\r\n"), pOptParam[wIndex].lParam);
  334. }
  335. }
  336. PCSTR
  337. StripDirPrefixA(
  338. IN PCSTR pstrFilename
  339. )
  340. /*++
  341. Routine Description:
  342. Strip the directory prefix off a filename (ANSI version)
  343. Arguments:
  344. pstrFilename - Pointer to filename string
  345. Return Value:
  346. Pointer to the last component of a filename (without directory prefix)
  347. --*/
  348. {
  349. PCSTR pstr;
  350. if (pstr = strrchr(pstrFilename, PATH_SEPARATOR))
  351. return pstr + 1;
  352. return pstrFilename;
  353. }