@@ -145,9 +145,11 @@ ZEND_API int zend_gdb_present(void)
145
145
#if defined(__APPLE__ )
146
146
#define KINFO_PROC_FLAG (cproc->kp_proc.p_flag)
147
147
#define KINFO_PROC_PPID (cproc->kp_proc.p_oppid)
148
+ #define KINFO_PROC_COMM (pcproc->kp_proc.p_comm)
148
149
#else
149
150
#define KINFO_PROC_FLAG (cproc->ki_flag)
150
151
#define KINFO_PROC_PPID (cproc->ki_ppid)
152
+ #define KINFO_PROC_COMM (pcproc->ki_comm)
151
153
#endif
152
154
struct kinfo_proc * cproc ;
153
155
size_t cproclen = 0 ;
@@ -159,24 +161,15 @@ ZEND_API int zend_gdb_present(void)
159
161
if (sysctl (mib , 4 , cproc , & cproclen , NULL , 0 ) == 0 ) {
160
162
if ((KINFO_PROC_FLAG & P_TRACED ) != 0 ) {
161
163
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" )) {
168
169
ret = 1 ;
169
170
}
170
171
}
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 );
180
173
}
181
174
}
182
175
free (cproc );
0 commit comments