1 // This header is included in all the test programs (C and C++) and provides a 2 // hook for dealing with platform-specifics. 3 #if defined(_WIN32) || defined(_WIN64) 4 #ifdef COMPILING_LLDB_TEST_DLL 5 #define LLDB_TEST_API __declspec(dllexport) 6 #else 7 #define LLDB_TEST_API __declspec(dllimport) 8 #endif 9 #else 10 #define LLDB_TEST_API 11 #endif 12 13 #if defined(__cplusplus) && defined(_MSC_VER) && (_HAS_EXCEPTIONS == 0) 14 // Compiling MSVC libraries with _HAS_EXCEPTIONS=0, eliminates most but not all 15 // calls to __uncaught_exception. Unfortunately, it does seem to eliminate 16 // the delcaration of __uncaught_excpeiton. Including <eh.h> ensures that it is 17 // declared. This may not be necessary after MSVC 12. 18 #include <eh.h> 19 #endif 20 21 #if defined(_WIN32) 22 #define LLVM_PRETTY_FUNCTION __FUNCSIG__ 23 #else 24 #define LLVM_PRETTY_FUNCTION LLVM_PRETTY_FUNCTION 25 #endif 26 27 28 // On some systems (e.g., some versions of linux) it is not possible to attach to a process 29 // without it giving us special permissions. This defines the lldb_enable_attach macro, which 30 // should perform any such actions, if needed by the platform. This is a macro instead of a 31 // function to avoid the need for complex linking of the test programs. 32 #if defined(__linux__) 33 #include <sys/prctl.h> 34 35 // Android API <= 16 does not have these defined. 36 #ifndef PR_SET_PTRACER 37 #define PR_SET_PTRACER 0x59616d61 38 #endif 39 #ifndef PR_SET_PTRACER_ANY 40 #define PR_SET_PTRACER_ANY ((unsigned long)-1) 41 #endif 42 43 // For now we execute on best effort basis. If this fails for some reason, so be it. 44 #define lldb_enable_attach() \ 45 do \ 46 { \ 47 const int prctl_result = prctl(PR_SET_PTRACER, PR_SET_PTRACER_ANY, 0, 0, 0); \ 48 (void)prctl_result; \ 49 } while (0) 50 51 #else // not linux 52 53 #define lldb_enable_attach() 54 55 #endif 56 57 #if defined(__APPLE__) && defined(LLDB_USING_LIBSTDCPP) 58 59 // on Darwin, libstdc++ is missing <atomic>, so this would cause any test to fail building 60 // since this header file is being included in every C-family test case, we need to not include it 61 // on Darwin, most tests use libc++ by default, so this will only affect tests that explicitly require libstdc++ 62 63 #else 64 #ifdef __cplusplus 65 #include <atomic> 66 67 // Note that although hogging the CPU while waiting for a variable to change 68 // would be terrible in production code, it's great for testing since it 69 // avoids a lot of messy context switching to get multiple threads synchronized. 70 71 typedef std::atomic<int> pseudo_barrier_t; 72 #define pseudo_barrier_wait(barrier) \ 73 do \ 74 { \ 75 --(barrier); \ 76 while ((barrier).load() > 0) \ 77 ; \ 78 } while (0) 79 80 #define pseudo_barrier_init(barrier, count) \ 81 do \ 82 { \ 83 (barrier) = (count); \ 84 } while (0) 85 #endif // __cplusplus 86 #endif // defined(__APPLE__) && defined(LLDB_USING_LIBSTDCPP) 87