[Libreoffice-commits] core.git: comphelper/source
LuboÅ¡ LuÅák (via logerrit)
logerrit at kemper.freedesktop.org
Sun Aug 22 08:57:53 UTC 2021
comphelper/source/misc/debuggerinfo.cxx | 33 ++++++++++++++++++++++++++++++++
1 file changed, 33 insertions(+)
New commits:
commit 096e28acff82948eef6c5425593f0929c9367a6f
Author: Luboš Luňák <l.lunak at collabora.com>
AuthorDate: Fri Aug 20 16:11:04 2021 +0200
Commit: Luboš Luňák <l.lunak at collabora.com>
CommitDate: Sun Aug 22 10:57:20 2021 +0200
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 at collabora.com>
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);
More information about the Libreoffice-commits
mailing list