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.

115 lines
2.6 KiB

  1. //
  2. // Debug.CPP
  3. //
  4. // Copyright (c) 1997-1998 Microsoft Corporation
  5. //
  6. // @doc INTERNAL
  7. //
  8. // @module Debug | Debug services for DMusic.DLL
  9. //
  10. #include <windows.h>
  11. #include <stdio.h>
  12. #include <stdarg.h>
  13. #include "debug.h"
  14. #ifdef DBG
  15. #define MODULE "DMTOOL"
  16. // @globalv Section in WIN.INI for all debug settings
  17. const char szDebugSection[] = "debug";
  18. // @globalv Key in WIN.INI for our debug level. All messages with
  19. // a level of this number or lower will be displayed.
  20. const char szDebugKey[] = MODULE;
  21. // @globalv Key in WIN.INI [debug] section which determines if assert calls
  22. // DebugBreak or not
  23. //
  24. const char szAssertBreak[] = "AssertBreak";
  25. // @globalv Prefix for all debug outputs
  26. //
  27. const char szDebugPrefix[] = MODULE ": ";
  28. // @globalv The current debug level.
  29. static int giDebugLevel;
  30. // @globalv Do asserts break?
  31. static BOOL gfAssertBreak;
  32. // @func Sets the debug level from WIN.INI
  33. //
  34. void DebugInit(
  35. void)
  36. {
  37. giDebugLevel = GetProfileInt(szDebugSection, szDebugKey, 0);
  38. gfAssertBreak = GetProfileInt(szDebugSection, szAssertBreak, 0);
  39. // Nepotism at its finest
  40. DebugTrace(-1, "Debug level is %d\n", giDebugLevel);
  41. }
  42. // @func Send a debug trace out.
  43. //
  44. // @comm Any message with a level less than or equal to the current debug
  45. // level will be displayed using the OutputDebugString API. This means either
  46. // the IDE Debug window if the app is running in that context or WDEB if
  47. // it's running.
  48. //
  49. static BOOL fNeedPrefix = TRUE;
  50. void DebugTrace(
  51. int iDebugLevel, // @parm The debug level of this message
  52. LPSTR pstrFormat, // @parm A printf style format string
  53. ...) // @parm | ... | Variable paramters based on <p pstrFormat>
  54. {
  55. char sz[512];
  56. if (iDebugLevel != -1 && iDebugLevel > giDebugLevel)
  57. {
  58. return;
  59. }
  60. va_list va;
  61. va_start(va, pstrFormat);
  62. vsprintf(sz, pstrFormat, va);
  63. va_end(va);
  64. if (fNeedPrefix)
  65. {
  66. OutputDebugString(szDebugPrefix);
  67. }
  68. OutputDebugString(sz);
  69. // Let them construct multiple piece trace outs w/o
  70. // prefixing each one
  71. //
  72. fNeedPrefix = FALSE;
  73. for (;*pstrFormat && !fNeedPrefix; ++pstrFormat)
  74. {
  75. if (*pstrFormat == '\n')
  76. {
  77. fNeedPrefix = TRUE;
  78. }
  79. }
  80. }
  81. void DebugAssert(
  82. LPSTR szExp,
  83. LPSTR szFile,
  84. ULONG ulLine)
  85. {
  86. DebugTrace(0, "ASSERT: \"%s\" %s@%lu\n", szExp, szFile, ulLine);
  87. if (gfAssertBreak)
  88. {
  89. DebugBreak();
  90. }
  91. }
  92. #endif