diff --git a/Source/Engine/Platform/Apple/ApplePlatform.cpp b/Source/Engine/Platform/Apple/ApplePlatform.cpp index bf79c95c2..523f3b561 100644 --- a/Source/Engine/Platform/Apple/ApplePlatform.cpp +++ b/Source/Engine/Platform/Apple/ApplePlatform.cpp @@ -245,13 +245,40 @@ void ApplePlatform::GetUTCTime(int32& year, int32& month, int32& dayOfWeek, int3 millisecond = time.tv_usec / 1000; } +#if !BUILD_RELEASE + void ApplePlatform::Log(const StringView& msg) { -#if !BUILD_RELEASE && !USE_EDITOR +#if !USE_EDITOR NSLog(@"%s", StringAsANSI<>(*msg, msg.Length()).Get()); #endif } +bool ApplePlatform::IsDebuggerPresent() +{ + // Reference: https://developer.apple.com/library/archive/qa/qa1361/_index.html + int mib[4]; + struct kinfo_proc info; + + // 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_t size = sizeof(info); + sysctl(mib, sizeof(mib) / sizeof(*mib), &info, &size, NULL, 0); + + // We're being debugged if the P_TRACED flag is set + return ((info.kp_proc.p_flag & P_TRACED) != 0); +} + +#endif + bool ApplePlatform::Init() { if (UnixPlatform::Init()) diff --git a/Source/Engine/Platform/Apple/ApplePlatform.h b/Source/Engine/Platform/Apple/ApplePlatform.h index f1148d0b6..94b6534d6 100644 --- a/Source/Engine/Platform/Apple/ApplePlatform.h +++ b/Source/Engine/Platform/Apple/ApplePlatform.h @@ -79,7 +79,10 @@ public: static uint64 GetClockFrequency(); static void GetSystemTime(int32& year, int32& month, int32& dayOfWeek, int32& day, int32& hour, int32& minute, int32& second, int32& millisecond); static void GetUTCTime(int32& year, int32& month, int32& dayOfWeek, int32& day, int32& hour, int32& minute, int32& second, int32& millisecond); +#if !BUILD_RELEASE static void Log(const StringView& msg); + static bool IsDebuggerPresent(); +#endif static bool Init(); static void Tick(); static void BeforeExit();