diff options
author | Luboš Luňák <l.lunak@collabora.com> | 2021-08-20 16:11:04 +0200 |
---|---|---|
committer | Luboš Luňák <l.lunak@collabora.com> | 2021-08-22 10:57:20 +0200 |
commit | 096e28acff82948eef6c5425593f0929c9367a6f (patch) | |
tree | cc3565091073b8f30e5d308293570105b078e1ff | |
parent | feb59fca82df3762c4eb3b9ac2c96e9fa387bed1 (diff) |
make isDebuggerAttached() work on Mac
Change-Id: I1c7c2b58686e7cbb0f8f11327df7ae951226586f
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/120803
Tested-by: Jenkins
Reviewed-by: Luboš Luňák <l.lunak@collabora.com>
-rw-r--r-- | comphelper/source/misc/debuggerinfo.cxx | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/comphelper/source/misc/debuggerinfo.cxx b/comphelper/source/misc/debuggerinfo.cxx index 07b2f0132fff..eaa05d37c88c 100644 --- a/comphelper/source/misc/debuggerinfo.cxx +++ b/comphelper/source/misc/debuggerinfo.cxx @@ -16,6 +16,10 @@ #if defined(_WIN32) #define WIN32_LEAN_AND_MEAN #include <windows.h> +#elif defined MACOSX +#include <unistd.h> +#include <sys/types.h> +#include <sys/sysctl.h> #elif defined UNX #include <unistd.h> #include <fcntl.h> @@ -28,6 +32,35 @@ bool isDebuggerAttached() { #if defined(_WIN32) return IsDebuggerPresent(); +#elif defined MACOSX + // https://developer.apple.com/library/archive/qa/qa1361/_index.html + int junk; + int mib[4]; + struct kinfo_proc info; + size_t size; + + // Initialize the flags so that, if sysctl fails for some bizarre + // reason, we get a predictable result. + + info.kp_proc.p_flag = 0; + + // Initialize mib, which tells sysctl the info we want, in this case + // we're looking for information about a specific process ID. + + mib[0] = CTL_KERN; + mib[1] = KERN_PROC; + mib[2] = KERN_PROC_PID; + mib[3] = getpid(); + + // Call sysctl. + + size = sizeof(info); + junk = sysctl(mib, sizeof(mib) / sizeof(*mib), &info, &size, NULL, 0); + assert(junk == 0); + + // We're being debugged if the P_TRACED flag is set. + + return ((info.kp_proc.p_flag & P_TRACED) != 0); #elif defined LINUX char buf[4096]; int fd = open("/proc/self/status", O_RDONLY); |