Home | History | Annotate | Download | only in Unwind
      1 //===----------------------------- config.h -------------------------------===//
      2 //
      3 //                     The LLVM Compiler Infrastructure
      4 //
      5 // This file is dual licensed under the MIT and the University of Illinois Open
      6 // Source Licenses. See LICENSE.TXT for details.
      7 //
      8 //
      9 //  Defines macros used within libuwind project.
     10 //
     11 //===----------------------------------------------------------------------===//
     12 
     13 
     14 #ifndef LIBUNWIND_CONFIG_H
     15 #define LIBUNWIND_CONFIG_H
     16 
     17 #include <assert.h>
     18 #include <stdio.h>
     19 
     20 // Define static_assert() unless already defined by compiler.
     21 #ifndef __has_feature
     22   #define __has_feature(__x) 0
     23 #endif
     24 #if !(__has_feature(cxx_static_assert)) && !defined(static_assert)
     25   #define static_assert(__b, __m) \
     26       extern int compile_time_assert_failed[ ( __b ) ? 1 : -1 ]  \
     27                                                   __attribute__( ( unused ) );
     28 #endif
     29 
     30 // Platform specific configuration defines.
     31 #if __APPLE__
     32   #include <Availability.h>
     33   #ifdef __cplusplus
     34     extern "C" {
     35   #endif
     36     void __assert_rtn(const char *, const char *, int, const char *)
     37                                                       __attribute__((noreturn));
     38   #ifdef __cplusplus
     39     }
     40   #endif
     41 
     42   #define _LIBUNWIND_BUILD_ZERO_COST_APIS (__i386__ || __x86_64__ || __arm64__)
     43   #define _LIBUNWIND_BUILD_SJLJ_APIS      (__arm__)
     44   #define _LIBUNWIND_SUPPORT_FRAME_APIS   (__i386__ || __x86_64__)
     45   #define _LIBUNWIND_EXPORT               __attribute__((visibility("default")))
     46   #define _LIBUNWIND_HIDDEN               __attribute__((visibility("hidden")))
     47   #define _LIBUNWIND_LOG(msg, ...) fprintf(stderr, "libunwind: " msg, __VA_ARGS__)
     48   #define _LIBUNWIND_ABORT(msg) __assert_rtn(__func__, __FILE__, __LINE__, msg)
     49 
     50   #if FOR_DYLD
     51     #define _LIBUNWIND_SUPPORT_COMPACT_UNWIND 1
     52     #define _LIBUNWIND_SUPPORT_DWARF_UNWIND   0
     53     #define _LIBUNWIND_SUPPORT_DWARF_INDEX    0
     54   #else
     55     #define _LIBUNWIND_SUPPORT_COMPACT_UNWIND 1
     56     #define _LIBUNWIND_SUPPORT_DWARF_UNWIND   1
     57     #define _LIBUNWIND_SUPPORT_DWARF_INDEX    0
     58   #endif
     59 
     60 #else
     61   #include <stdlib.h>
     62 
     63   static inline void assert_rtn(const char* func, const char* file, int line, const char* msg)  __attribute__ ((noreturn));
     64   static inline void assert_rtn(const char* func, const char* file, int line, const char* msg) {
     65     fprintf(stderr, "libunwind: %s %s:%d - %s\n",  func, file, line, msg);
     66     assert(false);
     67     abort();
     68   }
     69 
     70   #define _LIBUNWIND_BUILD_ZERO_COST_APIS (__i386__ || __x86_64__ || __arm64__ || __arm__)
     71   #define _LIBUNWIND_BUILD_SJLJ_APIS      0
     72   #define _LIBUNWIND_SUPPORT_FRAME_APIS   (__i386__ || __x86_64__)
     73   #define _LIBUNWIND_EXPORT               __attribute__((visibility("default")))
     74   #define _LIBUNWIND_HIDDEN               __attribute__((visibility("hidden")))
     75   #define _LIBUNWIND_LOG(msg, ...) fprintf(stderr, "libuwind: " msg, __VA_ARGS__)
     76   #define _LIBUNWIND_ABORT(msg) assert_rtn(__func__, __FILE__, __LINE__, msg)
     77 
     78   #define _LIBUNWIND_SUPPORT_COMPACT_UNWIND 0
     79   #define _LIBUNWIND_SUPPORT_DWARF_UNWIND   0
     80   #define _LIBUNWIND_SUPPORT_DWARF_INDEX    0
     81 #endif
     82 
     83 
     84 // Macros that define away in non-Debug builds
     85 #ifdef NDEBUG
     86   #define _LIBUNWIND_DEBUG_LOG(msg, ...)
     87   #define _LIBUNWIND_TRACE_API(msg, ...)
     88   #define _LIBUNWIND_TRACING_UNWINDING 0
     89   #define _LIBUNWIND_TRACE_UNWINDING(msg, ...)
     90   #define _LIBUNWIND_LOG_NON_ZERO(x) x
     91 #else
     92   #ifdef __cplusplus
     93     extern "C" {
     94   #endif
     95     extern  bool logAPIs();
     96     extern  bool logUnwinding();
     97   #ifdef __cplusplus
     98     }
     99   #endif
    100   #define _LIBUNWIND_DEBUG_LOG(msg, ...)  _LIBUNWIND_LOG(msg, __VA_ARGS__)
    101   #define _LIBUNWIND_LOG_NON_ZERO(x) \
    102             do { \
    103               int _err = x; \
    104               if ( _err != 0 ) \
    105                 _LIBUNWIND_LOG("" #x "=%d in %s", _err, __FUNCTION__); \
    106              } while (0)
    107   #define _LIBUNWIND_TRACE_API(msg, ...) \
    108             do { \
    109               if ( logAPIs() ) _LIBUNWIND_LOG(msg, __VA_ARGS__); \
    110             } while(0)
    111   #define _LIBUNWIND_TRACE_UNWINDING(msg, ...) \
    112             do { \
    113               if ( logUnwinding() ) _LIBUNWIND_LOG(msg, __VA_ARGS__); \
    114             } while(0)
    115   #define _LIBUNWIND_TRACING_UNWINDING logUnwinding()
    116 #endif
    117 
    118 
    119 #endif // LIBUNWIND_CONFIG_H
    120