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.

249 lines
5.8 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Copyright (C) Microsoft Corporation, 1997.
  4. //
  5. // debug.c
  6. //
  7. // Debug build support routines.
  8. //
  9. // History:
  10. // Mon Jun 02 17:07:23 1997 -by- Drew Bliss [drewb]
  11. // Created
  12. //
  13. //----------------------------------------------------------------------------
  14. #include "precomp.h"
  15. #pragma hdrstop
  16. #include <imports.h>
  17. #include <devlock.h>
  18. #if DBG
  19. static void printNormalFloat( float fval )
  20. {
  21. int logi, logval_i, logval_f;
  22. float logval, logf;
  23. int negative=0;
  24. if( fval < (float) 0.0 )
  25. negative = 1;
  26. fval = __GL_ABSF(fval);
  27. logval = (float) (log( fval ) / log( 10 ));
  28. logi = (int) logval;
  29. logf = logval - logi;
  30. if( (logval <= (float) 0) && (logf != (float) 0.0) ) {
  31. logi -= 1;
  32. logf += (float) 1.0;
  33. }
  34. logval = (float) pow(10,logf);
  35. if( negative )
  36. DbgPrint( "-" );
  37. #if 0
  38. DbgPrint( "%fE%d", logval, logi );
  39. #else
  40. logval_i = (int) logval;
  41. logval_f = (int) ((logval - (float) logval_i) * (float) 10000.0 + (float) 0.5);
  42. DbgPrint( "%d.%dE%d", logval_i, logval_f, logi );
  43. #endif
  44. }
  45. void printFloat( char *comment, void *mval, int printHex )
  46. {
  47. // IEEE single format: sign bits : 1
  48. // exponent : 7
  49. // fraction : 24
  50. // Representation: low word : Fraction low
  51. // high word : 0-6: Fraction high
  52. // 7-14: Exponent
  53. // 15: Sign
  54. char *ploww, *phighw;
  55. short loww, highw;
  56. long lval = 0, fraction;
  57. int sign, exponent;
  58. float fval;
  59. ploww = (char *) mval;
  60. phighw = (char *) ((char *) mval) + 2;
  61. memcpy( &loww, ploww, 2 );
  62. memcpy( &highw, phighw, 2 );
  63. memcpy( &lval, mval, 4 );
  64. sign = (highw & 0x8000) >> 15;
  65. fraction = lval & 0x007fffff;
  66. exponent = (highw & 0x7f80) >> 7;
  67. DbgPrint( "%s", comment );
  68. if( printHex )
  69. DbgPrint( "0x%x, ", lval );
  70. if( exponent == 255 ) {
  71. if( fraction == 0 ) {
  72. if( sign )
  73. DbgPrint( "-" );
  74. DbgPrint( "infinity" );
  75. }
  76. else
  77. DbgPrint( "NaN" );
  78. }
  79. else if( exponent == 0 ) {
  80. if( fraction == 0 )
  81. DbgPrint( "0.0" );
  82. else {
  83. memcpy( &fval, mval, 4 );
  84. printNormalFloat( fval );
  85. }
  86. }
  87. else {
  88. memcpy( &fval, mval, 4 );
  89. printNormalFloat( fval );
  90. }
  91. }
  92. /*****************************************************************************\
  93. * DbgPrintFloat
  94. *
  95. * Prints floating point numbers from within server, in exponent notation with
  96. * 4 significant digits (e.g 1.7392E-23). Also prints string preceeding number.
  97. * Checks for deviant cases, such as NaN's or infinity.
  98. *
  99. \*****************************************************************************/
  100. void DbgPrintFloat( char *comment, float fval )
  101. {
  102. printFloat( comment, &fval, 0 );
  103. }
  104. /*****************************************************************************\
  105. * DbgPrintFloatP
  106. *
  107. * Same as DbgPrintFloat, but takes a pointer to the float to print. Also
  108. * prints out the hex representation of the float.
  109. * Used in cases where the float may not be a valid float.
  110. *
  111. \*****************************************************************************/
  112. void DbgPrintFloatP( char *comment, void *mval )
  113. {
  114. printFloat( comment, mval, 1 );
  115. }
  116. #if defined(VERBOSE_DDSLOCK)
  117. //
  118. // Define DDGLOCK if you know the location of the DDraw global lock
  119. // (DDRAW!CheapMutexCrossProcess) and want to see its counts.
  120. //
  121. typedef struct _DDRAW_GLOBAL_LOCK
  122. {
  123. LONG LockCount;
  124. LONG RecursionCount;
  125. DWORD Tid;
  126. DWORD Pid;
  127. } DDRAW_GLOBAL_LOCK;
  128. // #define DDGLOCK ((DDRAW_GLOBAL_LOCK *)0x76959048)
  129. /******************************Public*Routine******************************\
  130. *
  131. * DDSLOCK
  132. *
  133. * Tracks DirectDraw surface locks
  134. *
  135. * History:
  136. * Wed May 28 13:42:23 1997 -by- Drew Bliss [drewb]
  137. * Created
  138. *
  139. \**************************************************************************/
  140. HRESULT dbgDdsLock(LPDIRECTDRAWSURFACE pdds, DDSURFACEDESC *pddsd,
  141. DWORD flags, char *file, int line)
  142. {
  143. HRESULT hr;
  144. #ifdef DDGLOCK
  145. volatile DDRAW_GLOBAL_LOCK *glock = DDGLOCK;
  146. #endif
  147. DbgPrint("%2X:Lock %08lX %4d:%s\n",
  148. GetCurrentThreadId(), pdds, line, file);
  149. #ifdef DDGLOCK
  150. DbgPrint(" %2d %2d %2X\n", glock->LockCount, glock->RecursionCount,
  151. glock->Tid);
  152. #endif
  153. hr = pdds->lpVtbl->Lock(pdds, NULL, pddsd, flags, NULL);
  154. #ifdef DDGLOCK
  155. DbgPrint(" %2d %2d %2X\n", glock->LockCount, glock->RecursionCount,
  156. glock->Tid);
  157. #endif
  158. return hr;
  159. }
  160. /******************************Public*Routine******************************\
  161. *
  162. * DDSUNLOCK
  163. *
  164. * Tracks DirectDrawSurface unlocks
  165. *
  166. * History:
  167. * Wed May 28 13:42:39 1997 -by- Drew Bliss [drewb]
  168. * Created
  169. *
  170. \**************************************************************************/
  171. HRESULT dbgDdsUnlock(LPDIRECTDRAWSURFACE pdds, void *ptr,
  172. char *file, int line)
  173. {
  174. HRESULT hr;
  175. #ifdef DDGLOCK
  176. volatile DDRAW_GLOBAL_LOCK *glock = DDGLOCK;
  177. LONG preLock;
  178. #endif
  179. DbgPrint("%2X:Unlk %08lX %4d:%s\n",
  180. GetCurrentThreadId(), pdds, line, file);
  181. #ifdef DDGLOCK
  182. DbgPrint(" %2d %2d %2X\n", glock->LockCount, glock->RecursionCount,
  183. glock->Tid);
  184. preLock = glock->LockCount;
  185. #endif
  186. hr = pdds->lpVtbl->Unlock(pdds, ptr);
  187. #ifdef DDGLOCK
  188. DbgPrint(" %2d %2d %2X\n", glock->LockCount, glock->RecursionCount,
  189. glock->Tid);
  190. if (preLock <= glock->LockCount)
  191. {
  192. DebugBreak();
  193. }
  194. #endif
  195. return hr;
  196. }
  197. #endif // VERBOSE_DDSLOCK
  198. #endif // DBG
  199. #ifdef _WIN95_
  200. // Provide a DbgPrint implementation on Win95 since the system's doesn't
  201. // do anything.
  202. ULONG DbgPrint(PCH Format, ...)
  203. {
  204. char achMsg[256];
  205. va_list vlArgs;
  206. va_start(vlArgs, Format);
  207. _vsnprintf(achMsg, sizeof(achMsg), Format, vlArgs);
  208. va_end(vlArgs);
  209. OutputDebugString(achMsg);
  210. return TRUE;
  211. }
  212. #endif // _WIN95_