Lugdunum  0.1.0
Debug.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include <lug/Config.hpp>
4 #include <lug/System/Utils.hpp>
5 #include <iostream>
6 
7 
8 #if defined(LUG_DEBUG)
9 
10  #if defined(LUG_COMPILER_GCC) || defined(LUG_COMPILER_CLANG)
11 
12  #if defined(LUG_SYSTEM_ANDROID)
13  // see https://github.com/scottt/debugbreak/blob/master/debugbreak.h#L90
14  #define LUG_DEBUG_BREAK() __asm__ volatile(".inst 0xe7f001f0");
15  #else
16  #define LUG_DEBUG_BREAK() __asm__("int $3")
17  #endif
18 
19  #elif defined(LUG_COMPILER_MSVC)
20 
21  #define LUG_DEBUG_BREAK() __debugbreak()
22 
23  #endif
24 
25 
26  #define LUG_ASSERT(assertion, message)\
27  do {\
28  if (LUG_UNLIKELY(!(assertion))) {\
29  std::cerr << "Assertion failed: " << (message) << std::endl <<\
30  "In " << __FILE__ << std::endl <<\
31  " at `" << LUG_SYSTEM_FUNCTION_NAME << "` line " << __LINE__ << std::endl;\
32  LUG_DEBUG_BREAK();\
33  }\
34  } while (0)
35 
36 #else
37 
38  #define LUG_ASSERT(assertion, message)
39  #define LUG_DEBUG_BREAK()
40 
41 #endif