Skip to content

Commit 91ea494

Browse files
authored
[lldb] Move lldb_enable_attach from test_common to a separate header (#139550)
test_common is force-included into every compilation, which causes problems when we're compiling assembly code, as we were in #138805. This avoids that as we can include the header only when it's needed.
1 parent dcd5e47 commit 91ea494

File tree

17 files changed

+58
-44
lines changed

17 files changed

+58
-44
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#ifndef LLDB_TEST_ATTACH_H
2+
#define LLDB_TEST_ATTACH_H
3+
4+
// On some systems (e.g., some versions of linux) it is not possible to attach
5+
// to a process without it giving us special permissions. This defines the
6+
// lldb_enable_attach macro, which should perform any such actions, if needed by
7+
// the platform.
8+
#if defined(__linux__)
9+
#include <sys/prctl.h>
10+
11+
// Android API <= 16 does not have these defined.
12+
#ifndef PR_SET_PTRACER
13+
#define PR_SET_PTRACER 0x59616d61
14+
#endif
15+
#ifndef PR_SET_PTRACER_ANY
16+
#define PR_SET_PTRACER_ANY ((unsigned long)-1)
17+
#endif
18+
19+
// For now we execute on best effort basis. If this fails for some reason, so
20+
// be it.
21+
#define lldb_enable_attach() \
22+
do { \
23+
const int prctl_result = \
24+
prctl(PR_SET_PTRACER, PR_SET_PTRACER_ANY, 0, 0, 0); \
25+
(void)prctl_result; \
26+
} while (0)
27+
28+
#else // not linux
29+
30+
#define lldb_enable_attach()
31+
32+
#endif // defined(__linux__)
33+
34+
#endif // LLDB_TEST_ATTACH_H

lldb/packages/Python/lldbsuite/test/make/test_common.h

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -20,33 +20,3 @@
2020
#else
2121
#define LLVM_PRETTY_FUNCTION LLVM_PRETTY_FUNCTION
2222
#endif
23-
24-
25-
// On some systems (e.g., some versions of linux) it is not possible to attach to a process
26-
// without it giving us special permissions. This defines the lldb_enable_attach macro, which
27-
// should perform any such actions, if needed by the platform. This is a macro instead of a
28-
// function to avoid the need for complex linking of the test programs.
29-
#if defined(__linux__)
30-
#include <sys/prctl.h>
31-
32-
// Android API <= 16 does not have these defined.
33-
#ifndef PR_SET_PTRACER
34-
#define PR_SET_PTRACER 0x59616d61
35-
#endif
36-
#ifndef PR_SET_PTRACER_ANY
37-
#define PR_SET_PTRACER_ANY ((unsigned long)-1)
38-
#endif
39-
40-
// For now we execute on best effort basis. If this fails for some reason, so be it.
41-
#define lldb_enable_attach() \
42-
do \
43-
{ \
44-
const int prctl_result = prctl(PR_SET_PTRACER, PR_SET_PTRACER_ANY, 0, 0, 0); \
45-
(void)prctl_result; \
46-
} while (0)
47-
48-
#else // not linux
49-
50-
#define lldb_enable_attach()
51-
52-
#endif

lldb/test/API/commands/process/attach-resume/main.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
#include <stdio.h>
2-
#include <fcntl.h>
3-
1+
#include "attach.h"
42
#include <chrono>
3+
#include <cstdio>
4+
#include <fcntl.h>
55
#include <thread>
66

77
volatile bool debugger_flag = true; // The debugger will flip this to false

lldb/test/API/commands/process/attach/main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#include <stdio.h>
2-
1+
#include "attach.h"
32
#include <chrono>
3+
#include <cstdio>
44
#include <thread>
55

66
volatile int g_val = 12345;

lldb/test/API/commands/process/detach-resumes/main.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1+
#include "attach.h"
12
#include "pseudo_barrier.h"
23
#include <chrono>
4+
#include <cstdio>
35
#include <fcntl.h>
46
#include <fstream>
5-
#include <stdio.h>
67
#include <thread>
78
#include <vector>
89

lldb/test/API/commands/register/register/register_command/main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#include <stdio.h>
2-
1+
#include "attach.h"
32
#include <chrono>
3+
#include <cstdio>
44
#include <thread>
55

66
long double outermost_return_long_double (long double my_long_double);

lldb/test/API/driver/batch_mode/main.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#include "attach.h"
12
#include <stdio.h>
23
#include <string.h>
34
#include <unistd.h>

lldb/test/API/functionalities/deleted-executable/main.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#include "attach.h"
12
#include <chrono>
23
#include <fstream>
34
#include <thread>

lldb/test/API/functionalities/load_after_attach/main.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1+
#include "attach.h"
12
#include "dylib.h"
23
#include <cassert>
3-
#include <cstdio>
4-
#include <thread>
54
#include <chrono>
5+
#include <cstdio>
66
#include <fstream>
7+
#include <thread>
78

89
int main(int argc, char* argv[]) {
910
lldb_enable_attach();

lldb/test/API/functionalities/process_group/main.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
#include "attach.h"
12
#include <stdio.h>
2-
#include <unistd.h>
33
#include <sys/wait.h>
4+
#include <unistd.h>
45

56
volatile int release_child_flag = 0;
67

lldb/test/API/functionalities/thread/create_after_attach/main.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
#include <stdio.h>
1+
#include "attach.h"
22
#include <chrono>
3+
#include <cstdio>
34
#include <thread>
45

56
using std::chrono::microseconds;
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
int main(int argc, char **argv) {
2-
lldb_enable_attach();
32
int to_complete = 0;
43
return to_complete;
54
}

lldb/test/API/python_api/hello_world/main.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#include "attach.h"
12
#include <stdio.h>
23
#ifdef _MSC_VER
34
#include <windows.h>

lldb/test/API/tools/lldb-dap/attach/main.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#include "attach.h"
12
#include <stdio.h>
23
#ifdef _WIN32
34
#include <process.h>

lldb/test/API/tools/lldb-dap/disconnect/main.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#include "attach.h"
12
#include <chrono>
23
#include <cstdio>
34
#include <fstream>

lldb/test/API/tools/lldb-server/attach-wait/shim.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
#include <unistd.h>
1+
#include "attach.h"
22
#include <cstdio>
3+
#include <unistd.h>
34

45
int main(int argc, char *argv[]) {
56
lldb_enable_attach();

lldb/test/API/tools/lldb-server/main.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#include "attach.h"
12
#include <atomic>
23
#include <cassert>
34
#include <chrono>

0 commit comments

Comments
 (0)