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.

106 lines
2.5 KiB

  1. // debug.h : This file contains the
  2. // Created: Dec '97
  3. // Author : a-rakeba
  4. // History:
  5. // Copyright (C) 1997 Microsoft Corporation
  6. // All rights reserved.
  7. // Microsoft Confidential
  8. #if !defined( _DEBUG_H_ )
  9. #define _DEBUG_H_
  10. #include <stdio.h>
  11. #include "DbgLogr.h"
  12. #include "DbgLvl.h"
  13. namespace _Utils {
  14. #if _DEBUG || DBG
  15. #define _TRACE CDebugLogger::OutMessage
  16. #define _TRACE_POINT(x) CDebugLogger::OutMessage( x, __LINE__, __FILE__ )
  17. #else
  18. #define _TRACE ;
  19. #define _TRACE_POINT(x) ((void)0)
  20. #endif // _DEBUG
  21. #define _chFAIL( szMSG ) { \
  22. _TRACE( CDebugLevel::TRACE_DEBUGGING, szMSG ); \
  23. DebugBreak(); \
  24. }
  25. #define _chASSERTFAIL(file, line, expr) { \
  26. CHAR sz[256]; \
  27. sprintf(sz, "File %hs, line %d : %hs", file, line, expr); \
  28. _chFAIL(sz); \
  29. }
  30. #if _DEBUG || DBG
  31. #define _chASSERT(a) {if (!(a))\
  32. _chASSERTFAIL(__FILE__, __LINE__, #a);}
  33. #else
  34. #define _chASSERT(a)
  35. #endif // _DEBUG
  36. // Assert in debug builds, but don't remove the code in retail builds
  37. #if _DEBUG || DBG
  38. #define _chVERIFY1(a) _chASSERT(a)
  39. #else
  40. #define _chVERIFY1(x) (x)
  41. #endif // _DEBUG
  42. // Assert in debug builds, but don't remove the code in retail builds
  43. // This is similar to chVERIFY1 but this is to be used in Win32 calls
  44. // requiring a call to GetLastError()
  45. #define _chVERIFYFAIL( x, y, z ) { \
  46. CDebugLogger::OutMessage( x, y, z, GetLastError() ); \
  47. }
  48. #if _DEBUG || DBG
  49. #define _chVERIFY2(a) {if( !( a ) ) \
  50. _chVERIFYFAIL( #a, __FILE__, __LINE__ );}
  51. #else
  52. #define _chVERIFY2(x) (x)
  53. #endif // _DEBUG
  54. }
  55. #endif // _DEBUG_H_
  56. // Intended uses for:
  57. // _TRACE_POINT --> for exact location
  58. // _TRACE* ---> for tracing, etc
  59. // _chVERFIY1 ---> assert in debug build, code not removed in retail build
  60. // _chVERFIY2 ---> win32 calls requiring GetLastError()
  61. // _chASSERT ---> invariants, pre & post conditions, validity checks
  62. // Notes:
  63. // C++ exception handling avoided for various reasons
  64. // possibly might use WIN32 SEH if necessary
  65. // Hungarian notation as far as posssible but not when deemed overkill
  66. // Win32 SDK data types instead of diresct C++ data types
  67. // e.g. CHAR vs char , DWORD vs unsigned int
  68. // UNICODE only when absolutely necessary