Skip to content

Commit 6875ed6

Browse files
committed
Find more common grounds accross BSDs.
Checking the proc title might be enough.
1 parent 32962f4 commit 6875ed6

File tree

1 file changed

+8
-15
lines changed

1 file changed

+8
-15
lines changed

Zend/zend_gdb.c

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,11 @@ ZEND_API int zend_gdb_present(void)
145145
#if defined(__APPLE__)
146146
#define KINFO_PROC_FLAG (cproc->kp_proc.p_flag)
147147
#define KINFO_PROC_PPID (cproc->kp_proc.p_oppid)
148+
#define KINFO_PROC_COMM (pcproc->kp_proc.p_comm)
148149
#else
149150
#define KINFO_PROC_FLAG (cproc->ki_flag)
150151
#define KINFO_PROC_PPID (cproc->ki_ppid)
152+
#define KINFO_PROC_COMM (pcproc->ki_comm)
151153
#endif
152154
struct kinfo_proc *cproc;
153155
size_t cproclen = 0;
@@ -159,24 +161,15 @@ ZEND_API int zend_gdb_present(void)
159161
if (sysctl(mib, 4, cproc, &cproclen, NULL, 0) == 0) {
160162
if ((KINFO_PROC_FLAG & P_TRACED) != 0) {
161163
pid_t ppid = KINFO_PROC_PPID;
162-
#if defined(__FreeBSD__)
163-
char path[PATH_MAX];
164-
size_t pathlen = sizeof(path);
165-
int smib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, ppid};
166-
if (sysctl(smib, 4, path, &pathlen, NULL, 0) == 0) {
167-
if (strstr(path, "gdb")) {
164+
int smib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_PID, ppid};
165+
struct kinfo_proc *pcproc = malloc(cproclen);
166+
if (sysctl(smib, 4, pcproc, &cproclen, NULL, 0) == 0) {
167+
// Could be prefixed with package systems e.g. egdb
168+
if (strstr(KINFO_PROC_COMM, "gdb")) {
168169
ret = 1;
169170
}
170171
}
171-
#else
172-
// Does not seem there is a way to get a full path
173-
// but only from the current process ...
174-
// unless there is "off the book" technique to get it ;
175-
// here considered "gdb-ish"
176-
// open to debate if we throw away the mac support altogether...
177-
(void)ppid;
178-
ret = 1;
179-
#endif
172+
free(pcproc);
180173
}
181174
}
182175
free(cproc);

0 commit comments

Comments
 (0)