Skip to content

Commit 93e05cd

Browse files
committed
[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
1 parent 8a1eefa commit 93e05cd

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

include/swift/Runtime/Backtrace.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,10 @@ struct BacktraceSettings {
135135

136136
SWIFT_RUNTIME_STDLIB_INTERNAL BacktraceSettings _swift_backtraceSettings;
137137

138+
inline bool _swift_backtrace_isEnabled() {
139+
return _swift_backtraceSettings.enabled == OnOffTty::On;
140+
}
141+
138142
SWIFT_RUNTIME_STDLIB_SPI
139143
bool _swift_backtrace_isThunkFunction(const char *mangledName);
140144

stdlib/public/runtime/Errors.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434

3535
#include "ImageInspection.h"
3636
#include "swift/Demangling/Demangle.h"
37+
#include "swift/Runtime/Backtrace.h"
3738
#include "swift/Runtime/Debug.h"
3839
#include "swift/Runtime/Portability.h"
3940
#include "swift/Runtime/Win32.h"
@@ -353,7 +354,13 @@ void swift::swift_reportError(uint32_t flags,
353354
const char *message) {
354355
#if defined(__APPLE__) && NDEBUG
355356
flags &= ~FatalErrorFlags::ReportBacktrace;
357+
#else
358+
// Disable fatalError backtraces if the backtracer is enabled
359+
if (runtime::backtrace::_swift_backtrace_isEnabled()) {
360+
flags &= ~FatalErrorFlags::ReportBacktrace;
361+
}
356362
#endif
363+
357364
reportNow(flags, message);
358365
reportOnCrash(flags, message);
359366
}
@@ -388,9 +395,9 @@ swift::warningv(uint32_t flags, const char *format, va_list args)
388395
#pragma GCC diagnostic ignored "-Wuninitialized"
389396
swift_vasprintf(&log, format, args);
390397
#pragma GCC diagnostic pop
391-
398+
392399
reportNow(flags, log);
393-
400+
394401
free(log);
395402
}
396403

test/Backtracing/FatalError.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ struct FatalError {
3737
}
3838
}
3939

40+
// CHECK-NOT: Current stack trace:
41+
4042
// CHECK: *** Program crashed: {{Illegal instruction|System trap}} at 0x{{[0-9a-f]+}} ***
4143

4244
// CHECK: Thread 0 {{(".*" )?}}crashed:

0 commit comments

Comments
 (0)