mirror of
https://gitlab.freedesktop.org/wayland/wayland.git
synced 2025-10-31 22:25:25 -04:00
test-runner: Implement is_debugger_attached() for FreeBSD
FreeBSD provides a PROC_TRACE_STATUS procctl(2) to detect this directly. Signed-off-by: Alex Richardson <Alexander.Richardson@cl.cam.ac.uk>
This commit is contained in:
parent
644efe9517
commit
bb92828807
2 changed files with 23 additions and 1 deletions
|
|
@ -26,7 +26,7 @@ add_project_arguments(
|
||||||
language: 'c'
|
language: 'c'
|
||||||
)
|
)
|
||||||
|
|
||||||
foreach h: [ 'sys/prctl.h', 'sys/ucred.h' ]
|
foreach h: [ 'sys/prctl.h', 'sys/procctl.h', 'sys/ucred.h' ]
|
||||||
config_h.set('HAVE_' + h.underscorify().to_upper(), cc.has_header(h))
|
config_h.set('HAVE_' + h.underscorify().to_upper(), cc.has_header(h))
|
||||||
endforeach
|
endforeach
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,7 @@
|
||||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
#include "../config.h"
|
||||||
|
|
||||||
#define _GNU_SOURCE
|
#define _GNU_SOURCE
|
||||||
|
|
||||||
|
|
@ -36,11 +37,16 @@
|
||||||
#include <dlfcn.h>
|
#include <dlfcn.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
|
#include <signal.h>
|
||||||
#include <sys/ptrace.h>
|
#include <sys/ptrace.h>
|
||||||
|
#ifdef HAVE_SYS_PROCCTL_H
|
||||||
|
#include <sys/procctl.h>
|
||||||
|
#elif defined(HAVE_SYS_PRCTL_H)
|
||||||
#include <sys/prctl.h>
|
#include <sys/prctl.h>
|
||||||
#ifndef PR_SET_PTRACER
|
#ifndef PR_SET_PTRACER
|
||||||
# define PR_SET_PTRACER 0x59616d61
|
# define PR_SET_PTRACER 0x59616d61
|
||||||
#endif
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "test-runner.h"
|
#include "test-runner.h"
|
||||||
|
|
||||||
|
|
@ -226,6 +232,21 @@ stderr_reset_color(void)
|
||||||
* Returns: 1 if a debugger is confirmed present; 0 if no debugger is
|
* Returns: 1 if a debugger is confirmed present; 0 if no debugger is
|
||||||
* present or if it can't be determined.
|
* present or if it can't be determined.
|
||||||
*/
|
*/
|
||||||
|
#if defined(HAVE_SYS_PROCCTL_H) && defined(PROC_TRACE_STATUS)
|
||||||
|
static int
|
||||||
|
is_debugger_attached(void)
|
||||||
|
{
|
||||||
|
int rc;
|
||||||
|
int status;
|
||||||
|
rc = procctl(P_PID, getpid(), PROC_TRACE_STATUS, &status);
|
||||||
|
if (rc == -1) {
|
||||||
|
perror("procctl");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
/* -1=tracing disabled, 0=no debugger attached, >0=pid of debugger. */
|
||||||
|
return status > 0;
|
||||||
|
}
|
||||||
|
#elif defined(HAVE_SYS_PRCTL_H)
|
||||||
static int
|
static int
|
||||||
is_debugger_attached(void)
|
is_debugger_attached(void)
|
||||||
{
|
{
|
||||||
|
|
@ -287,6 +308,7 @@ is_debugger_attached(void)
|
||||||
|
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue