Added Debugger() to the programmer error handler on macOS. This will also be used when I add a bug-in-libui function.

This commit is contained in:
Pietro Gagliardi 2019-05-13 00:59:13 -04:00
parent b3049b0a1e
commit 0d21bf8846
1 changed files with 30 additions and 1 deletions

View File

@ -99,12 +99,41 @@ void uiQueueMain(void (*f)(void *data), void *data)
dispatch_async_f(dispatch_get_main_queue(), data, f);
}
// Debugger() was deprecated in macOS 10.8 (as part of the larger CarbonCore deprecation), but they did not provide a replacement.
// Though some people say inline asm, I'd rather make this work automatically everywhere.
// Others say raise(SIGTRAP) and others still say __builtin_trap(), but I can't confirm these do what I want (some sources, including documentation, claim they either cause a core dump or send a SIGILL instead).
// I've also heard of some new clang intrinsics, __builtin_debugtrap(), but this is totally undocumented and the original patch for this suggested it would be identical to __builtin_trap(), so...
// Also I cannot figure out how to manually raise EXC_BREAKPOINT.
// So that leaves us with one option: just use Debugger(), turning off the deprecation warnings.
// Also, while we could turn off the deprecation warning temporarily in gcc >= 4.6 and any clang, I'm not sure what minimum version of gcc we need, and I'm not sure if "any clang" is even accurate.
// So instead of juggling version macros, just turn off deprecation warnings at the bottom of this file.
// References:
// - https://stackoverflow.com/questions/37299/xcode-equivalent-of-asm-int-3-debugbreak-halt
// - https://stackoverflow.com/questions/2622017/suppressing-deprecated-warnings-in-xcode
// - https://stackoverflow.com/questions/28166565/detect-gcc-as-opposed-to-msvc-clang-with-macro
// - https://stackoverflow.com/questions/16555585/why-pragma-gcc-diagnostic-push-pop-warning-in-gcc-c
// - possibly others, all on stackoverflow.com (and maybe once on Apple's own forums?); I forget now
static void debugBreak(void);
void uiprivSysProgrammerError(const char *msg)
{
NSLog(@"*** %s: %s. %s", uiprivProgrammerErrorPrefix, msg, uiprivProgrammerErrorAdvice);
// TODO either find an appropriate exception for each message or use a custom exception name
[NSException raise:NSInvalidArgumentException
format:@"%s: %s", uiprivProgrammerErrorPrefix, msg];
// TODO break into the debugger?
debugBreak();
abort(); // we shouldn't reach here
}
#ifdef __clang__
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
#else
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#endif
static void debugBreak(void)
{
Debugger();
}
// DO NOT ADD NEW CODE HERE. IT WILL NOT BE SUBJECT TO DEPRECATION WARNINGS.
// I am making an exception here with Debugger(); see the large comment above.