Skip to content

Commit 898da7b

Browse files
committed
Merge branch 'PHP-8.1'
* PHP-8.1: zend gdb detection fix on FreeBSD.
2 parents 1a4d2dd + 3ee2422 commit 898da7b

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

Zend/zend_gdb.c

+17
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@
2525
#include <fcntl.h>
2626
#include <unistd.h>
2727

28+
#if defined(__FreeBSD__)
29+
# include <sys/user.h>
30+
# include <libutil.h>
31+
#endif
32+
2833
enum {
2934
ZEND_GDBJIT_NOACTION,
3035
ZEND_GDBJIT_REGISTER,
@@ -105,6 +110,7 @@ ZEND_API void zend_gdb_unregister_all(void)
105110
ZEND_API bool zend_gdb_present(void)
106111
{
107112
bool ret = 0;
113+
#if defined(__linux__) /* netbsd while having this procfs part, does not hold the tracer pid */
108114
int fd = open("/proc/self/status", O_RDONLY);
109115

110116
if (fd > 0) {
@@ -136,6 +142,17 @@ ZEND_API bool zend_gdb_present(void)
136142

137143
close(fd);
138144
}
145+
#elif defined(__FreeBSD__)
146+
struct kinfo_proc *proc = kinfo_getproc(getpid());
147+
148+
if (proc) {
149+
if ((proc->ki_flag & P_TRACED) != 0) {
150+
struct kinfo_proc *dbg = kinfo_getproc(proc->ki_tracer);
151+
152+
ret = (dbg && strstr(dbg->ki_comm, "gdb"));
153+
}
154+
}
155+
#endif
139156

140157
return ret;
141158
}

0 commit comments

Comments
 (0)