|
14 | 14 | //
|
15 | 15 | //===----------------------------------------------------------------------===//
|
16 | 16 |
|
17 |
| -#if defined(__CYGWIN__) || defined(__ANDROID__) || defined(_WIN32) || defined(__HAIKU__) |
18 |
| -# define SWIFT_SUPPORTS_BACKTRACE_REPORTING 0 |
| 17 | +#if defined(__CYGWIN__) || defined(__ANDROID__) || defined(__HAIKU__) |
| 18 | +#define SWIFT_SUPPORTS_BACKTRACE_REPORTING 0 |
19 | 19 | #else
|
20 |
| -# define SWIFT_SUPPORTS_BACKTRACE_REPORTING 1 |
| 20 | +#define SWIFT_SUPPORTS_BACKTRACE_REPORTING 1 |
21 | 21 | #endif
|
22 | 22 |
|
23 | 23 | #if defined(_WIN32)
|
24 | 24 | #include <mutex>
|
25 | 25 | #endif
|
26 | 26 |
|
| 27 | +#include <stdint.h> |
27 | 28 | #include <stdio.h>
|
28 | 29 | #include <stdlib.h>
|
29 | 30 | #include <string.h>
|
30 |
| -#include <stdint.h> |
31 | 31 | #if defined(_WIN32)
|
32 | 32 | #include <io.h>
|
33 | 33 | #else
|
|
48 | 48 | #include <cxxabi.h>
|
49 | 49 | #endif
|
50 | 50 |
|
51 |
| -#if SWIFT_SUPPORTS_BACKTRACE_REPORTING |
52 |
| -// execinfo.h is not available on Android. Checks in this file ensure that |
53 |
| -// fatalError behaves as expected, but without stack traces. |
| 51 | +#if __has_include(<execinfo.h>) |
54 | 52 | #include <execinfo.h>
|
55 | 53 | #endif
|
56 | 54 |
|
@@ -97,7 +95,7 @@ static bool getSymbolNameAddr(llvm::StringRef libraryName, SymbolInfo syminfo,
|
97 | 95 | DWORD dwResult;
|
98 | 96 |
|
99 | 97 | {
|
100 |
| - std::lock_guard<std::mutex> lock(m); |
| 98 | + std::lock_guard<std::mutex> lock(mutex); |
101 | 99 | dwResult = UnDecorateSymbolName(syminfo.symbolName, szUndName,
|
102 | 100 | sizeof(szUndName), dwFlags);
|
103 | 101 | }
|
@@ -193,8 +191,11 @@ void swift::printCurrentBacktrace(unsigned framesToSkip) {
|
193 | 191 | #if SWIFT_SUPPORTS_BACKTRACE_REPORTING
|
194 | 192 | constexpr unsigned maxSupportedStackDepth = 128;
|
195 | 193 | void *addrs[maxSupportedStackDepth];
|
196 |
| - |
| 194 | +#if defined(_WIN32) |
| 195 | + int symbolCount = CaptureStackBackTrace(0, maxSupportedStackDepth, addrs, NULL); |
| 196 | +#else |
197 | 197 | int symbolCount = backtrace(addrs, maxSupportedStackDepth);
|
| 198 | +#endif |
198 | 199 | for (int i = framesToSkip; i < symbolCount; ++i) {
|
199 | 200 | dumpStackTraceEntry(i - framesToSkip, addrs[i]);
|
200 | 201 | }
|
|
0 commit comments