LMMS
Loading...
Searching...
No Matches
fdebug.h
Go to the documentation of this file.
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) 2021, 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//-----------------------------------------------------------------------------
50//-----------------------------------------------------------------------------
51#pragma once
52
54#include <cstring>
55
56#if SMTG_OS_MACOS
57#include <new>
58#endif
59
62
63//-----------------------------------------------------------------------------
64// development / release
65//-----------------------------------------------------------------------------
66#if !defined (DEVELOPMENT) && !defined (RELEASE)
67 #ifdef _DEBUG
68 #define DEVELOPMENT 1
69 #elif defined (NDEBUG)
70 #define RELEASE 1
71 #else
72 #error DEVELOPMENT, RELEASE, _DEBUG, or NDEBUG must be defined!
73 #endif
74#endif
75
76//-----------------------------------------------------------------------------
77#if SMTG_OS_WINDOWS
78
82#if DEVELOPMENT && defined(_MSC_VER)
83#pragma warning(disable : 4291)
84#pragma warning(disable : 4985)
85#endif
86
87#endif // SMTG_OS_WINDOWS
88
89#if DEVELOPMENT
90//-----------------------------------------------------------------------------
96#define SMTG_ASSERT(f) \
97 if (!(f)) \
98 FDebugBreak ("%s(%d) : Assert failed: %s\n", __FILE__, __LINE__, #f);
99
101#define SMTG_WARNING(comment) FDebugPrint ("%s(%d) : %s\n", __FILE__, __LINE__, comment);
102
104#define SMTG_PRINTSYSERROR FPrintLastError (__FILE__, __LINE__);
105
108#define SMTG_DEBUGSTR(s) FDebugBreak (s);
109
113#define SMTG_VERIFY(f) SMTG_ASSERT (f)
114
118#define SMTG_VERIFY_IS(f, r) \
119 if ((f) != (r)) \
120 FDebugBreak ("%s(%d) : Assert failed: %s\n", __FILE__, __LINE__, #f);
121
125#define SMTG_VERIFY_NOT(f, r) \
126 if ((f) == (r)) \
127 FDebugBreak ("%s(%d) : Assert failed: %s\n", __FILE__, __LINE__, #f);
128
132
134#define SMTG_DBPRT0(a) FDebugPrint (a);
135#define SMTG_DBPRT1(a, b) FDebugPrint (a, b);
136#define SMTG_DBPRT2(a, b, c) FDebugPrint (a, b, c);
137#define SMTG_DBPRT3(a, b, c, d) FDebugPrint (a, b, c, d);
138#define SMTG_DBPRT4(a, b, c, d, e) FDebugPrint (a, b, c, d, e);
139#define SMTG_DBPRT5(a, b, c, d, e, f) FDebugPrint (a, b, c, d, e, f);
141
148void FDebugPrint (const char* format, ...);
149void FDebugBreak (const char* format, ...);
150void FPrintLastError (const char* file, int line);
152
158using AssertionHandler = bool (*) (const char* message);
159extern AssertionHandler gAssertionHandler;
160extern AssertionHandler gPreAssertionHook;
161using DebugPrintLogger = void (*) (const char* message);
162extern DebugPrintLogger gDebugPrintLogger;
164
168#if SMTG_OS_MACOS
169void* operator new (size_t, int, const char*, int);
170void* operator new[] (size_t, int, const char*, int);
171void operator delete (void* p, int, const char* file, int line);
172void operator delete[] (void* p, int, const char* file, int line);
173#ifndef NEW
174#define NEW new (1, __FILE__, __LINE__)
175#define NEWVEC new (1, __FILE__, __LINE__)
176#endif
177
178#define DEBUG_NEW DEBUG_NEW_LEAKS
179
180#elif SMTG_OS_WINDOWS && defined(_MSC_VER)
181#ifndef NEW
182void* operator new (size_t, int, const char*, int);
183#define NEW new (1, __FILE__, __LINE__)
184#define NEWVEC new (1, __FILE__, __LINE__)
185#endif
186
187#else
188#ifndef NEW
189#define NEW new
190#define NEWVEC new
191#endif
192#endif
193
194#else
196#define SMTG_ASSERT(f)
197#define SMTG_WARNING(s)
198#define SMTG_PRINTSYSERROR
199#define SMTG_DEBUGSTR(s)
200#define SMTG_VERIFY(f) f;
201#define SMTG_VERIFY_IS(f, r) f;
202#define SMTG_VERIFY_NOT(f, r) f;
203
204#define SMTG_DBPRT0(a)
205#define SMTG_DBPRT1(a, b)
206#define SMTG_DBPRT2(a, b, c)
207#define SMTG_DBPRT3(a, b, c, d)
208#define SMTG_DBPRT4(a, b, c, d, e)
209#define SMTG_DBPRT5(a, b, c, d, e, f)
210
211#ifndef NEW
212#define NEW new
213#define NEWVEC new
214
215#endif
216#endif
217
218// replace #if SMTG_CPPUNIT_TESTING
219bool isSmtgUnitTesting ();
220void setSmtgUnitTesting ();
221
222#if !SMTG_RENAME_ASSERT
223#if SMTG_OS_WINDOWS
224#undef ASSERT
225#endif
226
227#define ASSERT SMTG_ASSERT
228#define WARNING SMTG_WARNING
229#define DEBUGSTR SMTG_DEBUGSTR
230#define VERIFY SMTG_VERIFY
231#define VERIFY_IS SMTG_VERIFY_IS
232#define VERIFY_NOT SMTG_VERIFY_NOT
233#define PRINTSYSERROR SMTG_PRINTSYSERROR
234
235#define DBPRT0 SMTG_DBPRT0
236#define DBPRT1 SMTG_DBPRT1
237#define DBPRT2 SMTG_DBPRT2
238#define DBPRT3 SMTG_DBPRT3
239#define DBPRT4 SMTG_DBPRT4
240#define DBPRT5 SMTG_DBPRT5
241#endif
static void message(int level, const char *fmt,...)
Definition adplugdb.cpp:120
void setSmtgUnitTesting()
Definition fdebug.cpp:316
bool AmIBeingDebugged()
bool isSmtgUnitTesting()
Definition fdebug.cpp:310
uch * p
Definition crypt.c:594
typedef int(UZ_EXP MsgFn)()
#define void
Definition unzip.h:396
struct zdirent * file
Definition win32.c:1500
_WDL_CSTRING_PREFIX void INT_PTR const char * format
Definition wdlcstring.h:263