[Linux] Disable fatalError() backtraces when the runtime backtracer is active.

There's no need for fatalError() to try to generate its own backtraces
when the runtime's backtracer is enabled.  Not only is the code it uses
more fragile but it also doesn't support async or inline frames and it
can't look-up symbols properly either.

rdar://117470489
This commit is contained in:
Alastair Houghton
2023-10-31 16:47:38 +00:00
parent 8a1eefae07
commit 93e05cd1bb
3 changed files with 15 additions and 2 deletions

View File

@@ -135,6 +135,10 @@ struct BacktraceSettings {
SWIFT_RUNTIME_STDLIB_INTERNAL BacktraceSettings _swift_backtraceSettings;
inline bool _swift_backtrace_isEnabled() {
return _swift_backtraceSettings.enabled == OnOffTty::On;
}
SWIFT_RUNTIME_STDLIB_SPI
bool _swift_backtrace_isThunkFunction(const char *mangledName);

View File

@@ -34,6 +34,7 @@
#include "ImageInspection.h"
#include "swift/Demangling/Demangle.h"
#include "swift/Runtime/Backtrace.h"
#include "swift/Runtime/Debug.h"
#include "swift/Runtime/Portability.h"
#include "swift/Runtime/Win32.h"
@@ -353,7 +354,13 @@ void swift::swift_reportError(uint32_t flags,
const char *message) {
#if defined(__APPLE__) && NDEBUG
flags &= ~FatalErrorFlags::ReportBacktrace;
#else
// Disable fatalError backtraces if the backtracer is enabled
if (runtime::backtrace::_swift_backtrace_isEnabled()) {
flags &= ~FatalErrorFlags::ReportBacktrace;
}
#endif
reportNow(flags, message);
reportOnCrash(flags, message);
}
@@ -388,9 +395,9 @@ swift::warningv(uint32_t flags, const char *format, va_list args)
#pragma GCC diagnostic ignored "-Wuninitialized"
swift_vasprintf(&log, format, args);
#pragma GCC diagnostic pop
reportNow(flags, log);
free(log);
}

View File

@@ -37,6 +37,8 @@ struct FatalError {
}
}
// CHECK-NOT: Current stack trace:
// CHECK: *** Program crashed: {{Illegal instruction|System trap}} at 0x{{[0-9a-f]+}} ***
// CHECK: Thread 0 {{(".*" )?}}crashed: