From 8558ac9112b0a1b2c84f0ef022740b64e2c6ca0e Mon Sep 17 00:00:00 2001 From: Antony Polukhin Date: Thu, 26 Oct 2017 22:14:45 +0300 Subject: [PATCH 01/10] Added missing include. Fixes #32 --- include/boost/stacktrace/detail/safe_dump_posix.ipp | 1 + 1 file changed, 1 insertion(+) diff --git a/include/boost/stacktrace/detail/safe_dump_posix.ipp b/include/boost/stacktrace/detail/safe_dump_posix.ipp index 37eef5a..97792c9 100644 --- a/include/boost/stacktrace/detail/safe_dump_posix.ipp +++ b/include/boost/stacktrace/detail/safe_dump_posix.ipp @@ -16,6 +16,7 @@ #include // ::write #include // ::open +#include // S_IWUSR and friends namespace boost { namespace stacktrace { namespace detail { From c2ac4b28baa6a0fe864feb862253f6db8ca99344 Mon Sep 17 00:00:00 2001 From: Antony Polukhin Date: Tue, 31 Oct 2017 08:44:26 +0300 Subject: [PATCH 02/10] Updated docs to describe stacktrace usage with MinGW (refs #14) --- doc/stacktrace.qbk | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/doc/stacktrace.qbk b/doc/stacktrace.qbk index df843d8..784683f 100644 --- a/doc/stacktrace.qbk +++ b/doc/stacktrace.qbk @@ -309,6 +309,27 @@ In header only mode library could be tuned by macro. If one of the link macro fr * if you wish to disable backtracing and you use the library in header only mode, you just need to define *BOOST_STACKTRACE_USE_NOOP* for the whole project * if you wish to disable backtracing and *BOOST_STACKTRACE_LINK* is defined, you just need link with *-lboost_stacktrace_noop* +[section MinGW specific notes] + +MinGW-w64 users may use the *BOOST_STACKTRACE_USE_WINDBG* and *BOOST_STACKTRACE_USE_WINDBG_CACHED* for getting the best results. + +MinGW (without -w64) users have to install libbacktrace for getting better stacktraces. Follow the instruction: + +Let's assume that you've installed MinGw into C:\MinGW and downloaded [@https://github.com/ianlancetaylor/libbacktrace libbacktrace sources] into C:\libbacktrace-master + +* Configure & build libbacktrace from console: + * C:\MinGW\msys\1.0\bin\sh.exe + * cd /c/libbacktrace-master + * ./configure CC=/c/MinGW/bin/gcc.exe CXX=/c/MinGW/bin/g++.exe + * make + * ./libtool --mode=install /usr/bin/install -c libbacktrace.la '/c/libbacktrace-master' +* Add info to the project-config.jam in the Boost folder: + * using gcc : 6 : "C:\\MinGW\\bin\\g++.exe" : -I"C:\\libbacktrace-master\\" -L"C:\\libbacktrace-master\\" ; +* Now you can use a header only version by defining *BOOST_STACKTRACE_USE_BACKTRACE* for your project or build the stacktrace library from Boost folder: + * b2.exe toolset=gcc-6 --with-stacktrace + +[endsect] + [endsect] [section Acknowledgements] From cdfac8033ea0fde8b2aa9a1d88db9eaf112c7d74 Mon Sep 17 00:00:00 2001 From: Antony Polukhin Date: Tue, 31 Oct 2017 08:50:19 +0300 Subject: [PATCH 03/10] Disable invalid test (refs #33) --- example/terminate_handler.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/example/terminate_handler.cpp b/example/terminate_handler.cpp index 8b51935..ac46ac5 100644 --- a/example/terminate_handler.cpp +++ b/example/terminate_handler.cpp @@ -296,8 +296,12 @@ int main(int argc, const char* argv[]) { // We are copying files to make sure that stacktrace printing works independently from executable name copy_and_run(argv[0], '1', true); copy_and_run(argv[0], '2', false); + +#ifndef BOOST_WINDOWS + // There are some issues with async-safety of shared mmory writes on Windows. copy_and_run(argv[0], '3', true); copy_and_run(argv[0], '4', false); +#endif return test_inplace(); } From 8ab572d823fe3a42483a824adcb45137b9a7e1ff Mon Sep 17 00:00:00 2001 From: Antony Polukhin Date: Sun, 5 Nov 2017 20:13:05 +0300 Subject: [PATCH 04/10] Docs improved. Fixes #35 --- doc/stacktrace.qbk | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/doc/stacktrace.qbk b/doc/stacktrace.qbk index 784683f..69c2e69 100644 --- a/doc/stacktrace.qbk +++ b/doc/stacktrace.qbk @@ -293,13 +293,13 @@ By default Boost.Stacktrace is a header-only library, but you may change that an In header only mode library could be tuned by macro. If one of the link macro from above is defined, you have to manually link with one of the libraries: [table:libconfig Config [[Macro name or default] [Library] [Effect] [Platforms] [Uses debug information [footnote This will provide more readable backtraces with *source code locations* if the binary is built with debug information.]] [Uses dynamic exports information [footnote This will provide readable function names in backtrace for functions that are exported by the binary. Compiling with `-rdynamic` flag, without `-fisibility=hidden` or marking functions as exported produce a better stacktraces.]] ] - [[['default for MSVC] / *BOOST_STACKTRACE_USE_WINDBG*] [*boost_stacktrace_windbg*] [ Uses COM to show debug info. ] [Windows] [yes] [no]] - [[['default other platforms]] [*boost_stacktrace_basic*] [Uses compiler intrinsics to collect stacktrace and if possible `::dladdr` to show information about the symbol. Requires linking with *libdl* library on POSIX platforms.] [Not MSVC compiler on POSIX or Windows] [no] [yes]] - [[*BOOST_STACKTRACE_USE_WINDBG_CACHED*] [*boost_stacktrace_windbg_cached*] [ Uses COM to show debug info and caches COM instances in TLS for better performance. Useful only for cases when traces are gathered very often. [footnote This may affect other components of your program that use COM, because this mode calls the `CoInitializeEx(0, COINIT_MULTITHREADED)` on first use and does not call `::CoUninitialize();` until the current thread is destroyed. ] ] [Windows] [yes] [no]] + [[['default for MSVC, Intel on Windows, MinGW-w64] / *BOOST_STACKTRACE_USE_WINDBG*] [*boost_stacktrace_windbg*] [ Uses COM to show debug info. May require linking with *ole32* and *dbgeng*. ] [MSVC, MinGW-w64, Intel on Windows] [yes] [no]] + [[['default for other platforms]] [*boost_stacktrace_basic*] [Uses compiler intrinsics to collect stacktrace and if possible `::dladdr` to show information about the symbol. Requires linking with *libdl* library on POSIX platforms.] [Any compiler on POSIX or MinGW] [no] [yes]] + [[*BOOST_STACKTRACE_USE_WINDBG_CACHED*] [*boost_stacktrace_windbg_cached*] [ Uses COM to show debug info and caches COM instances in TLS for better performance. Useful only for cases when traces are gathered very often. [footnote This may affect other components of your program that use COM, because this mode calls the `CoInitializeEx(0, COINIT_MULTITHREADED)` on first use and does not call `::CoUninitialize();` until the current thread is destroyed. ] May require linking with *ole32* and *dbgeng*. ] [MSVC, MinGW-w64, Intel on Windows] [yes] [no]] [[*BOOST_STACKTRACE_USE_BACKTRACE*] [*boost_stacktrace_backtrace*] [Requires linking with *libdl* on POSIX and *libbacktrace* libraries. *libbacktrace* is probably already installed in your system, or built into your compiler. - Otherwise (if you are a *MinGW* user for example) it can be downloaded [@https://github.com/ianlancetaylor/libbacktrace from here] or [@https://github.com/gcc-mirror/gcc/tree/master/libbacktrace from here]. ] [GCC/MinGW/Clang... on POSIX or Windows] [yes] [yes]] - [[*BOOST_STACKTRACE_USE_ADDR2LINE*] [*boost_stacktrace_addr2line*] [Use *addr2line* program to retrieve stacktrace. Requires linking with *libdl* library and `::fork` system call. Macro *BOOST_STACKTRACE_ADDR2LINE_LOCATION* must be defined to the absolute path to the addr2line executable if it is not located in /usr/bin/addr2line. ] [GCC/MinGW/Clang... on POSIX] [yes] [yes]] + Otherwise (if you are a *MinGW* user for example) it can be downloaded [@https://github.com/ianlancetaylor/libbacktrace from here] or [@https://github.com/gcc-mirror/gcc/tree/master/libbacktrace from here]. ] [Any compiler on POSIX or MinGW] [yes] [yes]] + [[*BOOST_STACKTRACE_USE_ADDR2LINE*] [*boost_stacktrace_addr2line*] [Use *addr2line* program to retrieve stacktrace. Requires linking with *libdl* library and `::fork` system call. Macro *BOOST_STACKTRACE_ADDR2LINE_LOCATION* must be defined to the absolute path to the addr2line executable if it is not located in /usr/bin/addr2line. ] [Any compiler on POSIX] [yes] [yes]] [[*BOOST_STACKTRACE_USE_NOOP*] [*boost_stacktrace_noop*] [Use this if you wish to disable backtracing. `stacktrace::size()` with that macro always returns 0. ] [All] [no] [no]] ] From 75f79a117759e547393494e105ff1bce510cbca1 Mon Sep 17 00:00:00 2001 From: Antony Polukhin Date: Sun, 12 Nov 2017 22:31:35 +0300 Subject: [PATCH 05/10] Updated the docs to better reflect the MinGW situation. Refs #14, #34, #36 --- doc/stacktrace.qbk | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/doc/stacktrace.qbk b/doc/stacktrace.qbk index 69c2e69..e6e419f 100644 --- a/doc/stacktrace.qbk +++ b/doc/stacktrace.qbk @@ -295,10 +295,10 @@ In header only mode library could be tuned by macro. If one of the link macro fr [[Macro name or default] [Library] [Effect] [Platforms] [Uses debug information [footnote This will provide more readable backtraces with *source code locations* if the binary is built with debug information.]] [Uses dynamic exports information [footnote This will provide readable function names in backtrace for functions that are exported by the binary. Compiling with `-rdynamic` flag, without `-fisibility=hidden` or marking functions as exported produce a better stacktraces.]] ] [[['default for MSVC, Intel on Windows, MinGW-w64] / *BOOST_STACKTRACE_USE_WINDBG*] [*boost_stacktrace_windbg*] [ Uses COM to show debug info. May require linking with *ole32* and *dbgeng*. ] [MSVC, MinGW-w64, Intel on Windows] [yes] [no]] [[['default for other platforms]] [*boost_stacktrace_basic*] [Uses compiler intrinsics to collect stacktrace and if possible `::dladdr` to show information about the symbol. Requires linking with *libdl* library on POSIX platforms.] [Any compiler on POSIX or MinGW] [no] [yes]] - [[*BOOST_STACKTRACE_USE_WINDBG_CACHED*] [*boost_stacktrace_windbg_cached*] [ Uses COM to show debug info and caches COM instances in TLS for better performance. Useful only for cases when traces are gathered very often. [footnote This may affect other components of your program that use COM, because this mode calls the `CoInitializeEx(0, COINIT_MULTITHREADED)` on first use and does not call `::CoUninitialize();` until the current thread is destroyed. ] May require linking with *ole32* and *dbgeng*. ] [MSVC, MinGW-w64, Intel on Windows] [yes] [no]] + [[*BOOST_STACKTRACE_USE_WINDBG_CACHED*] [*boost_stacktrace_windbg_cached*] [ Uses COM to show debug info and caches COM instances in TLS for better performance. Useful only for cases when traces are gathered very often. [footnote This may affect other components of your program that use COM, because this mode calls the `CoInitializeEx(0, COINIT_MULTITHREADED)` on first use and does not call `::CoUninitialize();` until the current thread is destroyed. ] May require linking with *ole32* and *dbgeng*. ] [MSVC, Intel on Windows] [yes] [no]] [[*BOOST_STACKTRACE_USE_BACKTRACE*] [*boost_stacktrace_backtrace*] [Requires linking with *libdl* on POSIX and *libbacktrace* libraries. *libbacktrace* is probably already installed in your system, or built into your compiler. - Otherwise (if you are a *MinGW* user for example) it can be downloaded [@https://github.com/ianlancetaylor/libbacktrace from here] or [@https://github.com/gcc-mirror/gcc/tree/master/libbacktrace from here]. ] [Any compiler on POSIX or MinGW] [yes] [yes]] + Otherwise (if you are a *MinGW*/*MinGW-w64* user for example) it can be downloaded [@https://github.com/ianlancetaylor/libbacktrace from here] or [@https://github.com/gcc-mirror/gcc/tree/master/libbacktrace from here]. ] [Any compiler on POSIX, or MinGW, or MinGW-w64] [yes] [yes]] [[*BOOST_STACKTRACE_USE_ADDR2LINE*] [*boost_stacktrace_addr2line*] [Use *addr2line* program to retrieve stacktrace. Requires linking with *libdl* library and `::fork` system call. Macro *BOOST_STACKTRACE_ADDR2LINE_LOCATION* must be defined to the absolute path to the addr2line executable if it is not located in /usr/bin/addr2line. ] [Any compiler on POSIX] [yes] [yes]] [[*BOOST_STACKTRACE_USE_NOOP*] [*boost_stacktrace_noop*] [Use this if you wish to disable backtracing. `stacktrace::size()` with that macro always returns 0. ] [All] [no] [no]] ] @@ -309,13 +309,11 @@ In header only mode library could be tuned by macro. If one of the link macro fr * if you wish to disable backtracing and you use the library in header only mode, you just need to define *BOOST_STACKTRACE_USE_NOOP* for the whole project * if you wish to disable backtracing and *BOOST_STACKTRACE_LINK* is defined, you just need link with *-lboost_stacktrace_noop* -[section MinGW specific notes] +[section MinGW and MinGW-w64 specific notes] -MinGW-w64 users may use the *BOOST_STACKTRACE_USE_WINDBG* and *BOOST_STACKTRACE_USE_WINDBG_CACHED* for getting the best results. +MinGW-w64 and MinGW (without -w64) users have to install libbacktrace for getting better stacktraces. Follow the instruction: -MinGW (without -w64) users have to install libbacktrace for getting better stacktraces. Follow the instruction: - -Let's assume that you've installed MinGw into C:\MinGW and downloaded [@https://github.com/ianlancetaylor/libbacktrace libbacktrace sources] into C:\libbacktrace-master +Let's assume that you've installed MinGW into C:\MinGW and downloaded [@https://github.com/ianlancetaylor/libbacktrace libbacktrace sources] into C:\libbacktrace-master * Configure & build libbacktrace from console: * C:\MinGW\msys\1.0\bin\sh.exe From 8f0735d9bd6e782c84bee7da48205dcb23a468a5 Mon Sep 17 00:00:00 2001 From: Benjamin Buch Date: Mon, 20 Nov 2017 10:44:06 +0100 Subject: [PATCH 06/10] Include winapi only on windows --- include/boost/stacktrace/safe_dump_to.hpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/boost/stacktrace/safe_dump_to.hpp b/include/boost/stacktrace/safe_dump_to.hpp index bfd6072..748548b 100644 --- a/include/boost/stacktrace/safe_dump_to.hpp +++ b/include/boost/stacktrace/safe_dump_to.hpp @@ -12,7 +12,9 @@ # pragma once #endif +#if defined(BOOST_WINDOWS) #include +#endif #include #ifdef BOOST_INTEL From 9523e26aadc7810c76b371da741f9d41685a3545 Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Sat, 16 Dec 2017 21:31:13 +0200 Subject: [PATCH 07/10] Only use boost-install once --- build/Jamfile.v2 | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/build/Jamfile.v2 b/build/Jamfile.v2 index d9c2418..cc07af8 100644 --- a/build/Jamfile.v2 +++ b/build/Jamfile.v2 @@ -51,6 +51,8 @@ explicit WinDbg ; mp-run-simple has_windbg_cached.cpp : : : Dbgeng ole32 : WinDbgCached ; explicit WinDbgCached ; +local libraries ; + lib boost_stacktrace_noop : # sources ../src/noop.cpp @@ -62,7 +64,7 @@ lib boost_stacktrace_noop #shared:BOOST_STACKTRACE_DYN_LINK=1 ; -boost-install boost_stacktrace_noop ; +libraries += boost_stacktrace_noop ; lib boost_stacktrace_backtrace : # sources @@ -78,7 +80,7 @@ lib boost_stacktrace_backtrace #shared:BOOST_STACKTRACE_DYN_LINK=1 ; -boost-install boost_stacktrace_backtrace ; +libraries += boost_stacktrace_backtrace ; lib boost_stacktrace_addr2line : # sources @@ -93,7 +95,7 @@ lib boost_stacktrace_addr2line #shared:BOOST_STACKTRACE_DYN_LINK=1 ; -boost-install boost_stacktrace_addr2line ; +libraries += boost_stacktrace_addr2line ; lib boost_stacktrace_basic : # sources @@ -108,7 +110,7 @@ lib boost_stacktrace_basic #shared:BOOST_STACKTRACE_DYN_LINK=1 ; -boost-install boost_stacktrace_basic ; +libraries += boost_stacktrace_basic ; lib boost_stacktrace_windbg : # sources @@ -123,7 +125,7 @@ lib boost_stacktrace_windbg #shared:BOOST_STACKTRACE_DYN_LINK=1 ; -boost-install boost_stacktrace_windbg ; +libraries += boost_stacktrace_windbg ; lib boost_stacktrace_windbg_cached : # sources @@ -138,5 +140,6 @@ lib boost_stacktrace_windbg_cached #shared:BOOST_STACKTRACE_DYN_LINK=1 ; -boost-install boost_stacktrace_windbg_cached ; +libraries += boost_stacktrace_windbg_cached ; +boost-install $(libraries) ; From 168d9a75440b60418a28a85386c77550338f0f40 Mon Sep 17 00:00:00 2001 From: Daniela Engert Date: Wed, 27 Dec 2017 18:55:33 +0100 Subject: [PATCH 08/10] Most members of std::allocate are deprecated in C++17 Replace them by their cousins from std::allocator_traits. Signed-off-by: Daniela Engert --- include/boost/stacktrace/stacktrace.hpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/include/boost/stacktrace/stacktrace.hpp b/include/boost/stacktrace/stacktrace.hpp index 3c72488..200dd9f 100644 --- a/include/boost/stacktrace/stacktrace.hpp +++ b/include/boost/stacktrace/stacktrace.hpp @@ -87,7 +87,11 @@ class basic_stacktrace { } // Failed to fit in `buffer_size`. Allocating memory: +#ifdef BOOST_NO_CXX11_ALLOCATOR typedef typename Allocator::template rebind::other allocator_void_t; +#else + typedef typename std::allocator_traits::template rebind_alloc allocator_void_t; +#endif std::vector buf(buffer_size * 2, 0, impl_.get_allocator()); do { const std::size_t frames_count = boost::stacktrace::detail::this_thread_frames::collect(&buf[0], buf.size(), frames_to_skip + 1); From 57699543e836f7a01b8ab0b0b4932cdfca4b6a88 Mon Sep 17 00:00:00 2001 From: Antony Polukhin Date: Thu, 11 Jan 2018 11:08:07 +0300 Subject: [PATCH 09/10] Comment out some C calls that seem to be signal unsafe on Windows --- example/terminate_handler.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/example/terminate_handler.cpp b/example/terminate_handler.cpp index ac46ac5..09a5fc2 100644 --- a/example/terminate_handler.cpp +++ b/example/terminate_handler.cpp @@ -29,9 +29,9 @@ BOOST_NOINLINE void foo(int i) { #include void my_signal_handler(int signum) { - ::signal(signum, SIG_DFL); + //::signal(signum, SIG_DFL); boost::stacktrace::safe_dump_to("./backtrace.dump"); - ::raise(SIGABRT); + //::raise(SIGABRT); } //] From 998334c3b5019c8a16ac58a412172b5c43ced62c Mon Sep 17 00:00:00 2001 From: Antony Polukhin Date: Thu, 11 Jan 2018 21:38:04 +0300 Subject: [PATCH 10/10] Checking that safe_dump was causing hangs on Windows --- example/terminate_handler.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/example/terminate_handler.cpp b/example/terminate_handler.cpp index 09a5fc2..7b5bd78 100644 --- a/example/terminate_handler.cpp +++ b/example/terminate_handler.cpp @@ -29,9 +29,11 @@ BOOST_NOINLINE void foo(int i) { #include void my_signal_handler(int signum) { - //::signal(signum, SIG_DFL); + ::signal(signum, SIG_DFL); + #ifndef BOOST_WINDOWS boost::stacktrace::safe_dump_to("./backtrace.dump"); - //::raise(SIGABRT); + #endif + ::raise(SIGABRT); } //]