xref: /openbsd-src/gnu/llvm/lldb/packages/Python/lldbsuite/test/make/test_common.h (revision b99ef4df7fac99f3475b694d6cd4990521c99ae6)
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(_WIN32)
14 #define LLVM_PRETTY_FUNCTION __FUNCSIG__
15 #else
16 #define LLVM_PRETTY_FUNCTION LLVM_PRETTY_FUNCTION
17 #endif
18 
19 
20 // On some systems (e.g., some versions of linux) it is not possible to attach to a process
21 // without it giving us special permissions. This defines the lldb_enable_attach macro, which
22 // should perform any such actions, if needed by the platform. This is a macro instead of a
23 // function to avoid the need for complex linking of the test programs.
24 #if defined(__linux__)
25 #include <sys/prctl.h>
26 
27 // Android API <= 16 does not have these defined.
28 #ifndef PR_SET_PTRACER
29 #define PR_SET_PTRACER 0x59616d61
30 #endif
31 #ifndef PR_SET_PTRACER_ANY
32 #define PR_SET_PTRACER_ANY ((unsigned long)-1)
33 #endif
34 
35 // For now we execute on best effort basis.  If this fails for some reason, so be it.
36 #define lldb_enable_attach()                                                          \
37     do                                                                                \
38     {                                                                                 \
39         const int prctl_result = prctl(PR_SET_PTRACER, PR_SET_PTRACER_ANY, 0, 0, 0);  \
40         (void)prctl_result;                                                           \
41     } while (0)
42 
43 #else // not linux
44 
45 #define lldb_enable_attach()
46 
47 #endif
48