dune-fem  2.8-git
debugbreak.hh
Go to the documentation of this file.
1 /* Debugging assertions and traps
2  * Portable Snippets - https://github.com/nemequ/portable-snippets
3  * Created by Evan Nemerson <evan@nemerson.com>
4  *
5  * To the extent possible under law, the authors have waived all
6  * copyright and related or neighboring rights to this code. For
7  * details, see the Creative Commons Zero 1.0 Universal license at
8  * https://creativecommons.org/publicdomain/zero/1.0/
9  */
10 
11 #if !defined(PSNIP_DEBUG_TRAP_H)
12 #define PSNIP_DEBUG_TRAP_H
13 
14 #if !defined(PSNIP_NDEBUG) && defined(NDEBUG) && !defined(PSNIP_DEBUG)
15 # define PSNIP_NDEBUG 1
16 #endif
17 
18 #if defined(__has_builtin) && !defined(__ibmxl__)
19 # if __has_builtin(__builtin_debugtrap)
20 # define psnip_trap() __builtin_debugtrap()
21 # elif __has_builtin(__debugbreak)
22 # define psnip_trap() __debugbreak()
23 # endif
24 #endif
25 #if !defined(psnip_trap)
26 # if defined(_MSC_VER) || defined(__INTEL_COMPILER)
27 # define psnip_trap() __debugbreak()
28 # elif defined(__ARMCC_VERSION)
29 # define psnip_trap() __breakpoint(42)
30 # elif defined(__ibmxl__) || defined(__xlC__)
31 # include <builtins.h>
32 # define psnip_trap() __trap(42)
33 # elif defined(__DMC__) && defined(_M_IX86)
34  static inline void psnip_trap(void) { __asm int 3h; }
35 # elif defined(__i386__) || defined(__x86_64__)
36  static inline void psnip_trap(void) { __asm__ __volatile__("int3"); }
37 # elif defined(__thumb__)
38  static inline void psnip_trap(void) { __asm__ __volatile__(".inst 0xde01"); }
39 # elif defined(__aarch64__)
40  static inline void psnip_trap(void) { __asm__ __volatile__(".inst 0xd4200000"); }
41 # elif defined(__arm__)
42  static inline void psnip_trap(void) { __asm__ __volatile__(".inst 0xe7f001f0"); }
43 # elif defined (__alpha__) && !defined(__osf__)
44  static inline void psnip_trap(void) { __asm__ __volatile__("bpt"); }
45 # elif defined(_54_)
46  static inline void psnip_trap(void) { __asm__ __volatile__("ESTOP"); }
47 # elif defined(_55_)
48  static inline void psnip_trap(void) { __asm__ __volatile__(";\n .if (.MNEMONIC)\n ESTOP_1\n .else\n ESTOP_1()\n .endif\n NOP"); }
49 # elif defined(_64P_)
50  static inline void psnip_trap(void) { __asm__ __volatile__("SWBP 0"); }
51 # elif defined(_6x_)
52  static inline void psnip_trap(void) { __asm__ __volatile__("NOP\n .word 0x10000000"); }
53 # elif defined(__STDC_HOSTED__) && (__STDC_HOSTED__ == 0) && defined(__GNUC__)
54 # define psnip_trap() __builtin_trap()
55 # else
56 # include <signal.h>
57 # if defined(SIGTRAP)
58 # define psnip_trap() raise(SIGTRAP)
59 # else
60 # define psnip_trap() raise(SIGABRT)
61 # endif
62 # endif
63 #endif
64 
65 #if defined(HEDLEY_LIKELY)
66 # define PSNIP_DBG_LIKELY(expr) HEDLEY_LIKELY(expr)
67 #elif defined(__GNUC__) && (__GNUC__ >= 3)
68 # define PSNIP_DBG_LIKELY(expr) __builtin_expect(!!(expr), 1)
69 #else
70 # define PSNIP_DBG_LIKELY(expr) (!!(expr))
71 #endif
72 
73 #if !defined(PSNIP_NDEBUG) || (PSNIP_NDEBUG == 0)
74 # define gdb_assert(expr) do { \
75  if (!PSNIP_DBG_LIKELY(expr)) { \
76  psnip_trap(); \
77  } \
78  } while (0)
79 #else
80 # define gdb_assert(expr)
81 #endif
82 
83 #define debugbreak gdb_assert(0)
84 
85 #endif /* !defined(PSNIP_DEBUG_TRAP_H) */
#define psnip_trap()
Definition: debugbreak.hh:60