Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions include/swift/Runtime/Backtrace.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
11 changes: 9 additions & 2 deletions stdlib/public/runtime/Errors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}

Expand Down
2 changes: 2 additions & 0 deletions test/Backtracing/FatalError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion test/Runtime/backtrace.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// RUN: %empty-directory(%t)
// RUN: %target-build-swift %s -o %t/a.out
// RUN: %{python} %S/../Inputs/not.py "%target-run %t/a.out" 2>&1 | %{python} %utils/backtrace-check
// RUN: env SWIFT_BACKTRACE=enable=no %{python} %S/../Inputs/not.py "%target-run %t/a.out" 2>&1 | %{python} %utils/backtrace-check

// NOTE: not.py is used above instead of "not --crash" because %target-run
// doesn't pass through the crash, and `not` may not be available when running
Expand Down