diff --git a/backward.hpp b/backward.hpp index 19d5ba3..491f6bb 100644 --- a/backward.hpp +++ b/backward.hpp @@ -3918,7 +3918,6 @@ class cfile_streambuf : public std::streambuf { private: FILE *sink; - std::vector buffer; }; #ifdef BACKWARD_SYSTEM_LINUX @@ -4162,16 +4161,15 @@ class SignalHandling { sizeof posix_signals / sizeof posix_signals[0]); } - SignalHandling(const std::vector &posix_signals = make_default_signals()) - : _loaded(false) { + static bool installHandler(const std::vector &posix_signals, + void (*handler)(int, siginfo_t *, void *), + char *altstack, size_t altstack_size) { bool success = true; - const size_t stack_size = 1024 * 1024 * 8; - _stack_content.reset(static_cast(malloc(stack_size))); - if (_stack_content) { + if (altstack) { stack_t ss; - ss.ss_sp = _stack_content.get(); - ss.ss_size = stack_size; + ss.ss_sp = altstack; + ss.ss_size = altstack_size; ss.ss_flags = 0; if (sigaltstack(&ss, nullptr) < 0) { success = false; @@ -4191,7 +4189,7 @@ class SignalHandling { #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdisabled-macro-expansion" #endif - action.sa_sigaction = &sig_handler; + action.sa_sigaction = handler; #if defined(__clang__) #pragma clang diagnostic pop #endif @@ -4201,9 +4199,21 @@ class SignalHandling { success = false; } - _loaded = success; + return success; } + SignalHandling(const std::vector &posix_signals, + void (*handler)(int, siginfo_t *, void *)) + : _loaded(false) { + const size_t stack_size = 1024 * 1024 * 8; + _stack_content.reset(static_cast(malloc(stack_size))); + _loaded = installHandler(posix_signals, handler, _stack_content.get(), + stack_size); + } + + SignalHandling(const std::vector &posix_signals = make_default_signals()) + : SignalHandling(posix_signals, sig_handler) {} + bool loaded() const { return _loaded; } static void handleSignal(int, siginfo_t *info, void *_ctx) { @@ -4249,7 +4259,7 @@ class SignalHandling { Printer printer; printer.address = true; - printer.print(st, stderr); + fflush(printer.print(st, stderr)); #if (defined(_XOPEN_SOURCE) && _XOPEN_SOURCE >= 700) || \ (defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 200809L) @@ -4449,7 +4459,7 @@ class SignalHandling { st.skip_n_firsts(skip_frames); printer.address = true; - printer.print(st, std::cerr); + printer.print(st, std::cerr) << std::flush; } };