Loading...
Searching...
No Matches
Debug.hpp
1#pragma once
2
3#if defined(SCORE_DEBUG)
4#include <QDebug>
5
6#ifdef _WIN32
7#if defined(_MSC_VER)
8#include <windows.h>
9#endif
10#include <debugapi.h>
11#define DEBUG_BREAK DebugBreak()
12#else
13#include <csignal>
14#define DEBUG_BREAK std::raise(SIGTRAP)
15#endif
16#else
17#include <stdexcept>
18#endif
19
20#if defined(SCORE_DEBUG)
21#define SCORE_TODO \
22 do \
23 { \
24 static bool score_todo_b = false; \
25 if(!score_todo_b) \
26 { \
27 qDebug() << "TODO"; \
28 score_todo_b = true; \
29 } \
30 } while(0)
31
32#define SCORE_TODO_(Str) \
33 do \
34 { \
35 static bool score_todo_b = false; \
36 if(!score_todo_b) \
37 { \
38 qDebug() << "TODO: " << (Str); \
39 score_todo_b = true; \
40 } \
41 } while(0)
42
43#define SCORE_BREAKPOINT \
44 do \
45 { \
46 DEBUG_BREAK; \
47 } while(0)
48
49#else
50#define SCORE_TODO \
51 do \
52 { \
53 } while(0)
54#define SCORE_TODO_(Str) \
55 do \
56 { \
57 } while(0)
58#define SCORE_BREAKPOINT \
59 do \
60 { \
61 } while(0)
62#endif
63
64#ifdef SCORE_DEBUG
65#define SCORE_ASSERT(arg) \
66 do \
67 { \
68 if(bool score_assert_b = !!(arg); !score_assert_b) \
69 { \
70 DEBUG_BREAK; \
71 Q_ASSERT(!(#arg)); \
72 } \
73 } while(false)
74#else
75#define SCORE_ASSERT(arg) \
76 do \
77 { \
78 if(bool score_assert_b = !!(arg); !score_assert_b) \
79 { \
80 throw std::runtime_error("Assertion failure: " #arg); \
81 } \
82 } while(false)
83#endif
84
85#define SCORE_SOFT_ASSERT(arg) \
86 do \
87 { \
88 if(bool score_assert_b = !!(arg); !score_assert_b) \
89 { \
90 SCORE_BREAKPOINT; \
91 qDebug() << "Assertion failure: " #arg; \
92 } \
93 } while(false)
94
95#define SCORE_ABORT \
96 do \
97 { \
98 std::abort(); \
99 } while(0)
100
101#define SCORE_XSTR(s) SCORE_STR(s)
102#define SCORE_STR(s) #s
103
104// TODO reconsider this
105#if defined(Q_CC_MSVC)
106#define INLINE_EXPORT
107#else
108#if defined(SCORE_STATIC_PLUGINS)
109#define INLINE_EXPORT
110#else
111#define INLINE_EXPORT __attribute__((visibility("default")))
112#endif
113#endif