|
6 | 6 | // |
7 | 7 | //===----------------------------------------------------------------------===// |
8 | 8 |
|
| 9 | +#ifdef ENABLE_STACK_TRACE |
| 10 | +#include "llvm/ADT/StringRef.h" |
| 11 | +#include "llvm/Support/Signals.h" |
| 12 | +#endif |
| 13 | + |
9 | 14 | #include <detail/config.hpp> |
10 | 15 | #include <detail/global_handler.hpp> |
11 | 16 | #include <detail/platform_impl.hpp> |
@@ -95,9 +100,25 @@ void GlobalHandler::attachScheduler(Scheduler *Scheduler) { |
95 | 100 | MScheduler.Inst.reset(Scheduler); |
96 | 101 | } |
97 | 102 |
|
| 103 | +static void enableOnCrashStackPrinting() { |
| 104 | +#ifdef ENABLE_STACK_TRACE |
| 105 | + static std::once_flag PrintStackFlag; |
| 106 | + std::call_once(PrintStackFlag, []() { |
| 107 | + llvm::sys::PrintStackTraceOnErrorSignal(llvm::StringRef()); |
| 108 | + }); |
| 109 | +#endif |
| 110 | +} |
| 111 | + |
98 | 112 | Scheduler &GlobalHandler::getScheduler() { |
99 | 113 | getOrCreate(MScheduler); |
100 | 114 | registerSchedulerUsage(); |
| 115 | + // On Windows the registration of the signal handler before main function |
| 116 | + // (e.g. from DLLMain or from constructors of program scope objects) doesn't |
| 117 | + // work. So, registering signal handler here because: |
| 118 | + // 1) getScheduler is likely to be called for any non-trivial application; |
| 119 | + // 2) first call to getScheduler is likely to be done after main starts. |
| 120 | + // The same is done in getPlugins. |
| 121 | + enableOnCrashStackPrinting(); |
101 | 122 | return *MScheduler.Inst; |
102 | 123 | } |
103 | 124 |
|
@@ -132,6 +153,7 @@ std::mutex &GlobalHandler::getFilterMutex() { |
132 | 153 | return getOrCreate(MFilterMutex); |
133 | 154 | } |
134 | 155 | std::vector<plugin> &GlobalHandler::getPlugins() { |
| 156 | + enableOnCrashStackPrinting(); |
135 | 157 | return getOrCreate(MPlugins); |
136 | 158 | } |
137 | 159 | device_filter_list & |
|
0 commit comments