Audio plugin host https://kx.studio/carla
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.

241 lines
8.6KB

  1. //------------------------------------------------------------------------
  2. // Project : SDK Base
  3. // Version : 1.0
  4. //
  5. // Category : Helpers
  6. // Filename : base/source/fdebug.h
  7. // Created by : Steinberg, 1995
  8. // Description : There are 2 levels of debugging messages:
  9. // DEVELOPMENT During development
  10. // RELEASE Program is shipping.
  11. //
  12. //-----------------------------------------------------------------------------
  13. // LICENSE
  14. // (c) 2019, Steinberg Media Technologies GmbH, All Rights Reserved
  15. //-----------------------------------------------------------------------------
  16. // Redistribution and use in source and binary forms, with or without modification,
  17. // are permitted provided that the following conditions are met:
  18. //
  19. // * Redistributions of source code must retain the above copyright notice,
  20. // this list of conditions and the following disclaimer.
  21. // * Redistributions in binary form must reproduce the above copyright notice,
  22. // this list of conditions and the following disclaimer in the documentation
  23. // and/or other materials provided with the distribution.
  24. // * Neither the name of the Steinberg Media Technologies nor the names of its
  25. // contributors may be used to endorse or promote products derived from this
  26. // software without specific prior written permission.
  27. //
  28. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  29. // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  30. // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  31. // IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
  32. // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  33. // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  34. // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  35. // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
  36. // OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
  37. // OF THE POSSIBILITY OF SUCH DAMAGE.
  38. //-----------------------------------------------------------------------------
  39. //-----------------------------------------------------------------------------
  40. /** @file base/source/fdebug.h
  41. Debugging tools.
  42. There are 2 levels of debugging messages:
  43. - DEVELOPMENT
  44. - During development
  45. - RELEASE
  46. - Program is shipping.
  47. */
  48. //-----------------------------------------------------------------------------
  49. #pragma once
  50. #include "pluginterfaces/base/ftypes.h"
  51. #include <string.h>
  52. #if SMTG_OS_MACOS
  53. #include <new>
  54. #endif
  55. //-----------------------------------------------------------------------------
  56. // development / release
  57. //-----------------------------------------------------------------------------
  58. #if !defined (DEVELOPMENT) && !defined (RELEASE)
  59. #ifdef _DEBUG
  60. #define DEVELOPMENT 1
  61. #elif defined (NDEBUG)
  62. #define RELEASE 1
  63. #else
  64. #error DEVELOPMENT, RELEASE, _DEBUG, or NDEBUG must be defined!
  65. #endif
  66. #endif
  67. //-----------------------------------------------------------------------------
  68. #if SMTG_OS_WINDOWS
  69. /** Disable compiler warning:
  70. * C4291: "No matching operator delete found; memory will not be freed if initialization throws an
  71. * exception. A placement new is used for which there is no placement delete." */
  72. #if DEVELOPMENT && defined(_MSC_VER)
  73. #pragma warning(disable : 4291)
  74. #pragma warning(disable : 4985)
  75. #endif
  76. #endif // SMTG_OS_WINDOWS
  77. #if DEVELOPMENT
  78. //-----------------------------------------------------------------------------
  79. /** If "f" is not true and a debugger is present, send an error string to the debugger for display
  80. and cause a breakpoint exception to occur in the current process. SMTG_ASSERT is removed
  81. completely in RELEASE configuration. So do not pass methods calls to this macro that are expected
  82. to exist in the RELEASE build (for method calls that need to be present in a RELEASE build, use
  83. the VERIFY macros instead)*/
  84. #define SMTG_ASSERT(f) \
  85. if (!(f)) \
  86. FDebugBreak ("%s(%d) : Assert failed: %s\n", __FILE__, __LINE__, #f);
  87. /** Send "comment" string to the debugger for display. */
  88. #define SMTG_WARNING(comment) FDebugPrint ("%s(%d) : %s\n", __FILE__, __LINE__, comment);
  89. /** Send the last error string to the debugger for display. */
  90. #define SMTG_PRINTSYSERROR FPrintLastError (__FILE__, __LINE__);
  91. /** If a debugger is present, send string "s" to the debugger for display and
  92. cause a breakpoint exception to occur in the current process. */
  93. #define SMTG_DEBUGSTR(s) FDebugBreak (s);
  94. /** Use VERIFY for calling methods "f" having a bool result (expecting them to return 'true')
  95. The call of "f" is not removed in RELEASE builds, only the result verification. eg: SMTG_VERIFY
  96. (isValid ()) */
  97. #define SMTG_VERIFY(f) SMTG_ASSERT (f)
  98. /** Use VERIFY_IS for calling methods "f" and expect a certain result "r".
  99. The call of "f" is not removed in RELEASE builds, only the result verification. eg:
  100. SMTG_VERIFY_IS (callMethod (), kResultOK) */
  101. #define SMTG_VERIFY_IS(f, r) \
  102. if ((f) != (r)) \
  103. FDebugBreak ("%s(%d) : Assert failed: %s\n", __FILE__, __LINE__, #f);
  104. /** Use VERIFY_NOT for calling methods "f" and expect the result to be anything else but "r".
  105. The call of "f" is not removed in RELEASE builds, only the result verification. eg:
  106. SMTG_VERIFY_NOT (callMethod (), kResultError) */
  107. #define SMTG_VERIFY_NOT(f, r) \
  108. if ((f) == (r)) \
  109. FDebugBreak ("%s(%d) : Assert failed: %s\n", __FILE__, __LINE__, #f);
  110. /** @name Shortcut macros for sending strings to the debugger for display.
  111. First parameter is always the format string (printf like).
  112. */
  113. ///@{
  114. #define SMTG_DBPRT0(a) FDebugPrint (a);
  115. #define SMTG_DBPRT1(a, b) FDebugPrint (a, b);
  116. #define SMTG_DBPRT2(a, b, c) FDebugPrint (a, b, c);
  117. #define SMTG_DBPRT3(a, b, c, d) FDebugPrint (a, b, c, d);
  118. #define SMTG_DBPRT4(a, b, c, d, e) FDebugPrint (a, b, c, d, e);
  119. #define SMTG_DBPRT5(a, b, c, d, e, f) FDebugPrint (a, b, c, d, e, f);
  120. ///@}
  121. /** @name Helper functions for the above defined macros.
  122. You shouldn't use them directly (if you do so, don't forget "#if DEVELOPMENT")!
  123. It is recommended to use the macros instead.
  124. */
  125. ///@{
  126. void FDebugPrint (const char* format, ...);
  127. void FDebugBreak (const char* format, ...);
  128. void FPrintLastError (const char* file, int line);
  129. ///@}
  130. /** @name Provide a custom assertion handler and debug print handler, eg
  131. so that we can provide an assert with a custom dialog, or redirect
  132. the debug output to a file or stream.
  133. */
  134. ///@{
  135. typedef bool (*AssertionHandler) (const char* message);
  136. extern AssertionHandler gAssertionHandler;
  137. extern AssertionHandler gPreAssertionHook;
  138. typedef void (*DebugPrintLogger) (const char* message);
  139. extern DebugPrintLogger gDebugPrintLogger;
  140. ///@}
  141. /** Definition of memory allocation macros:
  142. Use "NEW" to allocate storage for individual objects.
  143. Use "NEWVEC" to allocate storage for an array of objects. */
  144. #if SMTG_OS_MACOS
  145. void* operator new (size_t, int, const char*, int);
  146. void* operator new[] (size_t, int, const char*, int);
  147. void operator delete (void* p, int, const char* file, int line);
  148. void operator delete[] (void* p, int, const char* file, int line);
  149. #ifndef NEW
  150. #define NEW new (1, __FILE__, __LINE__)
  151. #define NEWVEC new (1, __FILE__, __LINE__)
  152. #endif
  153. #define DEBUG_NEW DEBUG_NEW_LEAKS
  154. #elif SMTG_OS_WINDOWS && defined(_MSC_VER)
  155. #ifndef NEW
  156. void* operator new (size_t, int, const char*, int);
  157. #define NEW new (1, __FILE__, __LINE__)
  158. #define NEWVEC new (1, __FILE__, __LINE__)
  159. #endif
  160. #else
  161. #ifndef NEW
  162. #define NEW new
  163. #define NEWVEC new
  164. #endif
  165. #endif
  166. #else
  167. /** if DEVELOPMENT is not set, these macros will do nothing. */
  168. #define SMTG_ASSERT(f)
  169. #define SMTG_WARNING(s)
  170. #define SMTG_PRINTSYSERROR
  171. #define SMTG_DEBUGSTR(s)
  172. #define SMTG_VERIFY(f) f;
  173. #define SMTG_VERIFY_IS(f, r) f;
  174. #define SMTG_VERIFY_NOT(f, r) f;
  175. #define SMTG_DBPRT0(a)
  176. #define SMTG_DBPRT1(a, b)
  177. #define SMTG_DBPRT2(a, b, c)
  178. #define SMTG_DBPRT3(a, b, c, d)
  179. #define SMTG_DBPRT4(a, b, c, d, e)
  180. #define SMTG_DBPRT5(a, b, c, d, e, f)
  181. #ifndef NEW
  182. #define NEW new
  183. #define NEWVEC new
  184. #endif
  185. #endif
  186. #if SMTG_CPPUNIT_TESTING
  187. #define SMTG_IS_TEST true
  188. #else
  189. #define SMTG_IS_TEST false
  190. #endif
  191. #if !SMTG_RENAME_ASSERT
  192. #if SMTG_OS_WINDOWS
  193. #undef ASSERT
  194. #endif
  195. #define ASSERT SMTG_ASSERT
  196. #define WARNING SMTG_WARNING
  197. #define DEBUGSTR SMTG_DEBUGSTR
  198. #define VERIFY SMTG_VERIFY
  199. #define VERIFY_IS SMTG_VERIFY_IS
  200. #define VERIFY_NOT SMTG_VERIFY_NOT
  201. #define PRINTSYSERROR SMTG_PRINTSYSERROR
  202. #define DBPRT0 SMTG_DBPRT0
  203. #define DBPRT1 SMTG_DBPRT1
  204. #define DBPRT2 SMTG_DBPRT2
  205. #define DBPRT3 SMTG_DBPRT3
  206. #define DBPRT4 SMTG_DBPRT4
  207. #define DBPRT5 SMTG_DBPRT5
  208. #endif