testlib: Don't disable watchdog when the macOS crash reporter is enabled

The debuggerPresent() function was used both to decide whether we should
print our own stacktrace, and if we should start the watchdog timer, but
checking for the macOS crash reporter only applies to the former usecase.

The crash reporter check has now been split into a separate function, only
used to decide whether we should print our own stacktrace or not.

Change-Id: I282aa57a51c14b07d3cbd547b551b6bf81b61897
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
This commit is contained in:
Tor Arne Vestbø 2020-01-31 13:27:17 +01:00 committed by Tor Arne Vestbø
parent e6f479a830
commit ac0a266e75

View File

@ -154,10 +154,6 @@ static bool debuggerPresent()
#elif defined(Q_OS_WIN)
return IsDebuggerPresent();
#elif defined(Q_OS_MACOS)
auto equals = [](CFStringRef str1, CFStringRef str2) -> bool {
return CFStringCompare(str1, str2, kCFCompareCaseInsensitive) == kCFCompareEqualTo;
};
// Check if there is an exception handler for the process:
mach_msg_type_number_t portCount = 0;
exception_mask_t masks[EXC_TYPES_COUNT];
@ -174,21 +170,31 @@ static bool debuggerPresent()
}
}
}
return false;
#else
// TODO
return false;
#endif
}
// Ok, no debugger attached. So, let's see if CrashReporter will throw up a dialog. If so, we
// leave it to the OS to do the stack trace.
static bool hasSystemCrashReporter()
{
#if defined(Q_OS_MACOS)
CFStringRef crashReporterType = static_cast<CFStringRef>(
CFPreferencesCopyAppValue(CFSTR("DialogType"), CFSTR("com.apple.CrashReporter")));
if (crashReporterType == nullptr)
return true;
auto equals = [](CFStringRef str1, CFStringRef str2) -> bool {
return CFStringCompare(str1, str2, kCFCompareCaseInsensitive) == kCFCompareEqualTo;
};
const bool createsStackTrace =
!equals(crashReporterType, CFSTR("server")) &&
!equals(crashReporterType, CFSTR("none"));
CFRelease(crashReporterType);
return createsStackTrace;
#else
// TODO
return false;
#endif
}
@ -216,7 +222,7 @@ static void stackTrace()
if (ok && disableStackDump == 1)
return;
if (debuggerPresent())
if (debuggerPresent() || hasSystemCrashReporter())
return;
#if defined(Q_OS_LINUX) || defined(Q_OS_MACOS)