-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathDebug.hpp
43 lines (36 loc) · 1.21 KB
/
Debug.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#pragma once
#include <nstd/Base.hpp>
class String;
class Debug
{
public:
static int print(const char* str);
static int printf(const char* format, ...);
#ifndef NDEBUG
static bool getSourceLine(void* addr, String& file, int& line);
#endif
};
#ifdef _MSC_VER
void __cdecl __debugbreak(void);
#define TRAP() __debugbreak()
#else
#if defined(__GNUC__) && defined(_ARM)
__attribute__((gnu_inline, always_inline)) static void __inline__ TRAP(void) {__asm__ volatile("BKPT");}
#else
#define TRAP() __builtin_trap()
#endif
#endif
#if defined(NDEBUG) && !defined(DEBUG)
#undef TRAP
#define TRAP() ((void)0)
#define ASSERT(exp) ((void)1)
#define VERIFY(exp) ((void)(exp))
#else
#ifdef _MSC_VER
#define ASSERT(exp) ((void)(!(exp) && Debug::printf("%s(%u): assertion failed: %s\n", __FILE__, __LINE__, #exp) && (TRAP(), 1)))
#define VERIFY(exp) ((void)(!(exp) && Debug::printf("%s(%u): verification failed: %s\n", __FILE__, __LINE__, #exp) && (TRAP(), 1)))
#else
#define ASSERT(exp) ((void)(!(exp) && Debug::printf("%s:%u: assertion failed: %s\n", __FILE__, __LINE__, #exp) && (TRAP(), 1)))
#define VERIFY(exp) ((void)(!(exp) && Debug::printf("%s:%u: verification failed: %s\n", __FILE__, __LINE__, #exp) && (TRAP(), 1)))
#endif
#endif