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.

350 lines
6.0 KiB

  1. /*++
  2. Copyright (c) 1990-1991 Microsoft Corporation
  3. Module Name:
  4. htdebug.c
  5. Abstract:
  6. This module contains the debug functions
  7. Author:
  8. 23-Apr-1992 Thu 20:01:55 updated -by- Daniel Chou (danielc)
  9. changed 'CHAR' type to 'BYTE' type, this will make sure if compiled
  10. under MIPS the default 'unsigned char' will not affect the signed
  11. operation on the single 8 bits
  12. 28-Mar-1992 Sat 20:53:29 updated -by- Daniel Chou (danielc)
  13. Modify sprintf for by not using va_start
  14. 20-Feb-1991 Wed 23:06:09 created -by- Daniel Chou (danielc)
  15. [Environment:]
  16. Printer Driver.
  17. [Notes:]
  18. Revision History:
  19. --*/
  20. #if DBG
  21. #include <htp.h>
  22. #include <string.h>
  23. #include <time.h>
  24. #include "htdebug.h"
  25. #include "stdio.h"
  26. UINT DbgTimerIdx = TIMER_LAST;
  27. DBGTIMER DbgTimer[TIMER_MAX_IDX + 1];
  28. LPBYTE
  29. HTENTRY
  30. HT_LOADDS
  31. FD6ToString(
  32. LONG Num,
  33. SHORT IntDigits,
  34. WORD FracDigits
  35. )
  36. {
  37. #define DBG_ONE_FD6_STR_SIZE 13
  38. #define DBG_FD6_STR_MAX 20
  39. #define DBG_FD6_STR_SIZE (DBG_ONE_FD6_STR_SIZE * DBG_FD6_STR_MAX)
  40. #define DBG_FD6_LAST_STR_IDX (DBG_ONE_FD6_STR_SIZE * (DBG_FD6_STR_MAX-1))
  41. static WORD Rounding[] = { 50000, 5000, 500, 50, 5 };
  42. static WORD DbgFD6StringIndex = 0;
  43. static BYTE DbgFD6Strings[DBG_FD6_STR_SIZE + 2];
  44. LPBYTE pFD6Str;
  45. LPBYTE pb;
  46. DWORD Number;
  47. INT Loop;
  48. BOOL Sign;
  49. #ifdef UMODE
  50. DWORD dw = GET_TICK;
  51. #endif
  52. //
  53. // Check before using it
  54. //
  55. if ((DbgFD6StringIndex += DBG_ONE_FD6_STR_SIZE) > DBG_FD6_LAST_STR_IDX) {
  56. DbgFD6StringIndex = 0; // Reset
  57. }
  58. pFD6Str = &DbgFD6Strings[DbgFD6StringIndex];
  59. if (Sign = (BOOL)(Num < 0)) {
  60. Number = (DWORD)-Num;
  61. } else {
  62. Number = (DWORD)Num;
  63. }
  64. if (FracDigits) {
  65. if (FracDigits < 6) {
  66. Num += (LONG)Rounding[FracDigits];
  67. } else {
  68. FracDigits = 6;
  69. }
  70. }
  71. sprintf(pFD6Str, "%5u.%06ld", (UINT)(Number / 1000000L), Number % 1000000L);
  72. if (!FracDigits) {
  73. pb = pFD6Str + 11;
  74. Loop = (INT)5;
  75. FracDigits = 6;
  76. while ((Loop--) && (*pb-- == (BYTE)'0')) {
  77. --FracDigits;
  78. }
  79. }
  80. *(pFD6Str + 6 + FracDigits) = (BYTE)0;
  81. pFD6Str += 4;
  82. if (IntDigits > 5) {
  83. IntDigits = 5;
  84. }
  85. while (*pFD6Str != (BYTE)' ') {
  86. --IntDigits;
  87. --pFD6Str;
  88. }
  89. if (Sign) {
  90. --IntDigits;
  91. *pFD6Str = '-';
  92. } else {
  93. ++pFD6Str;
  94. }
  95. #ifdef UMODE
  96. dw = GET_TICK - dw;
  97. DbgTimer[DbgTimerIdx].Last += dw;
  98. DbgTimer[TIMER_TOT].Last += dw;
  99. #endif
  100. return((LPBYTE)((IntDigits > 0) ? pFD6Str - IntDigits : pFD6Str));
  101. #undef DBG_ONE_FD6_STR_SIZE
  102. #undef DBG_FD6_STR_MAX
  103. #undef DBG_FD6_STR_SIZE
  104. #undef DBG_FD6_LAST_STR_IDX
  105. }
  106. VOID
  107. cdecl
  108. HTENTRY
  109. HT_LOADDS
  110. DbgPrintf(
  111. LPSTR pStr,
  112. ...
  113. )
  114. {
  115. va_list vaList;
  116. BYTE Buf[256];
  117. #ifdef UMODE
  118. DWORD dw = GET_TICK;
  119. #endif
  120. va_start(vaList, pStr);
  121. vsprintf(Buf, pStr, vaList);
  122. va_end(vaList);
  123. #ifdef DBG_INSERT_CR_TO_LF
  124. {
  125. LPBYTE pBufCurrent;
  126. LPBYTE pBufNext;
  127. pBufCurrent = (LPBYTE)Buf;
  128. while (pBufCurrent) {
  129. if (pBufNext = (LPBYTE)strchr(pBufCurrent, 0x0a)) {
  130. *pBufNext++ = 0x00;
  131. DEBUGOUTPUTFUNC(pBufCurrent);
  132. DEBUGOUTPUTFUNC("\r\n");
  133. } else {
  134. DEBUGOUTPUTFUNC(pBufCurrent);
  135. }
  136. pBufCurrent = pBufNext;
  137. }
  138. DEBUGOUTPUTFUNC("\r\n");
  139. }
  140. #else // DBG_INSERT_CR_TO_LF
  141. DEBUGOUTPUTFUNC(Buf);
  142. #endif // DBG_INSERT_CR_TO_LF
  143. #ifdef UMODE
  144. dw = GET_TICK - dw;
  145. DbgTimer[DbgTimerIdx].Last += dw;
  146. DbgTimer[TIMER_TOT].Last += dw;
  147. #endif
  148. }
  149. VOID
  150. HTENTRY
  151. HT_LOADDS
  152. _MyAssert(
  153. LPSTR pMsg,
  154. LPSTR pFalseExp,
  155. LPSTR pFilename,
  156. WORD LineNo
  157. )
  158. {
  159. #ifdef UMODE
  160. DWORD dw = GET_TICK;
  161. #endif
  162. DbgPrintf("\n* Assertion Failed: %s", pMsg);
  163. DbgPrintf("* False Expression: %s", pFalseExp);
  164. DbgPrintf("* Failed Filename: %s", pFilename);
  165. DbgPrintf("* Failed Line Number: %u\n\n", LineNo);
  166. DBGSTOP();
  167. #ifdef UMODE
  168. dw = GET_TICK - dw;
  169. DbgTimer[DbgTimerIdx].Last += dw;
  170. DbgTimer[TIMER_TOT].Last += dw;
  171. #endif
  172. }
  173. LPSTR
  174. HTENTRY
  175. HT_LOADDS
  176. DbgTimeString(
  177. UINT Idx
  178. )
  179. {
  180. #define DBG_ONE_TIME_STR_SIZE 12
  181. #define DBG_TIME_STR_MAX (TIMER_MAX_IDX + 1)
  182. #define DBG_TIME_STR_SIZE (DBG_ONE_TIME_STR_SIZE * DBG_TIME_STR_MAX)
  183. #define DBG_TIME_LAST_STR_IDX (DBG_ONE_TIME_STR_SIZE * (DBG_TIME_STR_MAX-1))
  184. static WORD DbgTimeStringIndex = 0;
  185. static BYTE DbgTimeStrings[DBG_TIME_STR_SIZE + 2];
  186. LPSTR pTimeStr;
  187. DWORD Time;
  188. UINT Second;
  189. if ((DbgTimeStringIndex += DBG_ONE_TIME_STR_SIZE) > DBG_TIME_LAST_STR_IDX) {
  190. DbgTimeStringIndex = 0; // Reset
  191. }
  192. pTimeStr = &DbgTimeStrings[DbgTimeStringIndex];
  193. if ((Time = DbgTimer[Idx].Tot) >= 1000L) {
  194. Second = (UINT)(Time / 1000L);
  195. Time %= 1000L;
  196. } else {
  197. Second = 0;
  198. }
  199. sprintf(pTimeStr, "%2u.%03u", Second, Time);
  200. return(pTimeStr);
  201. #undef DBG_ONE_TIME_STR_SIZE
  202. #undef DBG_TIME_STR_MAX
  203. #undef DBG_TIME_STR_SIZE
  204. #undef DBG_TIME_LAST_STR_IDX
  205. }
  206. #if defined(_OS2_) || defined(_OS_20_)
  207. VOID
  208. HTENTRY
  209. DebugBreak(
  210. VOID
  211. )
  212. {
  213. _asm
  214. {
  215. int 3h
  216. }
  217. }
  218. #endif // _OS2_
  219. #ifndef UMODE
  220. void DrvDbgPrint(
  221. char * pch,
  222. ...)
  223. {
  224. va_list ap;
  225. va_start(ap, pch);
  226. EngDebugPrint("",pch,ap);
  227. va_end(ap);
  228. }
  229. #endif
  230. #endif // DBG != 0