Compare commits

..

116 Commits

Author SHA1 Message Date
Antony Polukhin
d6499f26d4 Fix stacktrace_from_exception builds with MinGW (#206)
Fixes https://github.com/boostorg/stacktrace/issues/196
2025-02-18 13:41:40 +03:00
Antony Polukhin
d408cf4468 Document build options and use windbg_cached in Boost::stacktrace in CMake (#205) 2025-01-28 21:34:31 +03:00
Antony Polukhin
9d314b2b47 Force features to override library detections and make separate rules for each feature check with diagnostic messages (#203) 2025-01-23 21:56:26 +03:00
Uilian Ries
54934a386a Expose stacktrace libraries as build features (#202)
As I commented in the issue #195, this PR exposes all stacktrace libraries as boost features, mirroring what's available in the CMakeLists.txt in this project. So users will be able to build or not specific libraries present in this project. Here are some keypoints to evaluate these new changes:

- Added `build-stacktrace-feature` as generic rule validate on/off entry from users for each feature
- For `addr2line` I added a rule to disable in case using Windows and not Cygwin. It reflects the rule present in CMakeLists.txt: https://github.com/boostorg/stacktrace/blob/develop/CMakeLists.txt#L67

close #195

Signed-off-by: Uilian Ries <uilianries@gmail.com>
2025-01-18 13:26:21 +03:00
Antony Polukhin
ea282324b8 Fix some warnings on MSVC (#201) 2025-01-11 12:36:57 +03:00
Antony Polukhin
9e7a98a61a Update copyright years 2025-01-08 19:54:11 +03:00
Maciej Czarnecki
b170b28479 Use Relative Virtual Addresses to allow their decoding without knowing the base address (#200)
Instead of printing absolute addresses use relative ones so they can be used later to decode the stack trace.

## Motivation

It’s quite common to release apps without debug symbols while keeping them internally. Currently the lib prints absolute addresses which require the base address to decode them using symbols. With this change, the base address won’t be needed as values are relative to the beginning of the loaded module/binary.

The implementation for unix is **straightforward** as the existing code is used. For Windows, I’ve implemented similar logic using Windows API.

## Manual testing of Windows implementation

Here are 2 runs of `trivial_windbg_lib.exe` with .pdb and without .pdb file:

```jsx
>./trivial_windbg_lib.exe
 0# boost::stacktrace::basic_stacktrace<std::allocator<boost::stacktrace::frame> >::init at C:\Users\czarneckim\repositories\boost\boost\stacktrace\stacktrace.hpp:110
 1# main at C:\Users\czarneckim\repositories\boost\libs\stacktrace\test\test_trivial.cpp:14
 2# __scrt_common_main_seh at D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:288
 3# BaseThreadInitThunk in C:\WINDOWS\System32\KERNEL32.DLL
 4# RtlUserThreadStart in C:\WINDOWS\SYSTEM32\ntdll.dll

> mv ./trivial_windbg_lib.pdb{,_} 
> ./trivial_windbg_lib.exe
 0# 0x0000000000001DE3 in C:\Users\czarneckim\repositories\boost\bin.v2\libs\stacktrace\test\trivial_windbg_lib.test\msvc-14.3\release\x86_64\asynch-exceptions-on\cxxstd-latest-iso\debug-symbols-on\threading-multi\trivial_windbg_lib.exe
 1# 0x0000000000001FEE in C:\Users\czarneckim\repositories\boost\bin.v2\libs\stacktrace\test\trivial_windbg_lib.test\msvc-14.3\release\x86_64\asynch-exceptions-on\cxxstd-latest-iso\debug-symbols-on\threading-multi\trivial_windbg_lib.exe
 2# 0x000000000000246C in C:\Users\czarneckim\repositories\boost\bin.v2\libs\stacktrace\test\trivial_windbg_lib.test\msvc-14.3\release\x86_64\asynch-exceptions-on\cxxstd-latest-iso\debug-symbols-on\threading-multi\trivial_windbg_lib.exe
 3# BaseThreadInitThunk in C:\WINDOWS\System32\KERNEL32.DLL
 4# RtlUserThreadStart in C:\WINDOWS\SYSTEM32\ntdll.dll

> mv ./trivial_windbg_lib.pdb{_,}
> winaddr2line.exe -f -e trivial_windbg_lib.pdb 0x0000000000001DE3
boost::stacktrace::basic_stacktrace<std::allocator<boost::stacktrace::frame> >::init
C:\Users\czarneckim\repositories\boost\boost\stacktrace\stacktrace.hpp:110
```

I’ve also decoded the returned address using x64dbg running `trivial_windbg_lib.exe+0x0000000000001DE3`:

![image](https://github.com/user-attachments/assets/a36d3306-488d-4610-9f04-7888b98c2b75)

## Control

As it was suggested in #180, the new logic is enabled by default, but can be disabled with `BOOST_STACKTRACE_DISABLE_OFFSET_ADDR_BASE` (With non header-only mode, it requires rebuilding the lib)
2025-01-07 23:59:16 +03:00
Antony Polukhin
5ec45912da Autodetect stacktrace dependencies in Appveyor CI runs (#199) 2024-12-22 18:47:19 +03:00
Antony Polukhin
679bd845aa Add libs/function_types dependency for Appveyor tests 2024-12-22 16:40:11 +03:00
Antony Polukhin
0bcc382ab5 Add libs/concept_check dependency for Appveyor tests 2024-12-22 16:25:09 +03:00
Antony Polukhin
a64b8b7985 Do not test on macos-12 as the images are not available any more (take 2) 2024-12-22 16:22:14 +03:00
Antony Polukhin
92b1c794b3 Do not test on macos-12 as the images are not available any more 2024-12-22 14:06:12 +03:00
Daniel Krügler
8c4e50324c Use GetModuleNames to determine the full module path for msvc implementation 2024-12-22 01:24:02 +03:00
Dmitry Arkhipov
22982db3f6 fix setting custom b2 feature from CLI (#194) 2024-11-19 11:00:46 +03:00
Antony Polukhin
088bf8ed7f Fix stacktrace_from_exception CMake builds (#191) 2024-10-17 11:57:19 +03:00
Antony Polukhin
344f6bae19 Always link boost_stacktrace/Boost::stacktrace with Boost::stacktrace_from_exception if it is awailable in CMake 2024-10-16 15:13:44 +03:00
int mian
6504ed9ea4 Add CMake target boost_stacktrace_from_exception (#189)
Fixes #188
2024-10-16 15:11:09 +03:00
Antony Polukhin
a778e3d223 cleanup 2024-09-15 19:03:09 +03:00
huangqinjin
464e224c2f Don't export boost_stacktrace_impl_return_nullptr for static build (#186)
Now `boost_stacktrace.lib` provides the symbol `boost_stacktrace_impl_return_nullptr` for static and shared build.

For header only library, to make the symbol available **automatically**, the only way AFAIK is to export it. We may also consider provide a configuration macro to opt-out the exported symbol, and user need to manually define the non-exported symbol somewhere in their binaries.

Closes #177 .
2024-09-13 20:42:31 +03:00
Antony Polukhin
3f79aee92f Revert fix attempt for #177 2024-09-12 22:27:45 +03:00
Antony Polukhin
da94896d2d Fix attempt for #177 2024-09-12 22:00:21 +03:00
Antony Polukhin
0a1f8ac9a0 Fix Appveyor CI runs (#183) 2024-09-12 18:26:16 +03:00
Antony Polukhin
7c79d84614 fix attempt for Appveyor 2024-09-12 11:31:04 +03:00
Antony Polukhin
e95c2723d8 Add auto linking when using clang compiler under Visual Studio (fixes #100) 2024-09-12 11:15:03 +03:00
Antony Polukhin
9028c8a413 Attempt to fix weird build issues with CYGWIN and MacOS (fixes #88) 2024-09-12 11:14:26 +03:00
Antony Polukhin
b37fc77b5d Attempt to fix weird build issues with CYGWIN and MacOS (fixes #88) 2024-09-12 11:04:52 +03:00
Mats Taraldsvik
aa97b1a34c Fix missing namespace in stacktrace.qbk (#181) 2024-09-12 10:36:53 +03:00
Julien Schueller
23e1213f54 Fix missing include for std::exception (#178)
Fixes build on mingw: 
from_exception.cpp:333:23: error: 'current_exception' is not a member of 'std'
2024-09-03 10:27:59 +03:00
René Ferdinand Rivera Morell
ad121dbed0 Add support for modular build structure. (#172)
This is part of the effort to make the Boost libraries "modular" for build and consumption. See https://lists.boost.org/Archives/boost/2024/01/255704.php and https://github.com/grafikrobot/boost-b2-modular/blob/b2-modular/README.adoc for more information.
2024-09-01 17:23:26 +03:00
Jaroslaw Pelczar
981e37c218 Fix type conversions errors reported by GCC (#175)
This commit fixes errors when compiling with:
 -Wall -Werror -Wextra -Wconversion -Wsign-conversion

Signed-off-by: Jarosław Pelczar <jarek@jpelczar.com>
2024-09-01 17:22:07 +03:00
Antony Polukhin
cbf0df774d Fix addr2line work when the process is looked up via PATH.
Fixes #72
2024-07-07 20:30:51 +03:00
Peter Dimov
34e56c4e90 Do not define BOOST_STACKTRACE_DYN_LINK when BOOST_STACKTRACE_STATIC_LINK is defined 2024-06-23 20:36:49 +03:00
Peter Dimov
f32bd5a543 Define BOOST_STACKTRACE_LINK when BOOST_STACKTRACE_STATIC_LINK is defined. Refs #169. 2024-06-21 23:01:57 +03:00
Peter Dimov
79fc075655 Revert "Disable static linking in GHA because of https://github.com/boostorg/stacktrace/issues/169"
This reverts commit 274aeaa351.
2024-06-21 22:58:47 +03:00
Peter Dimov
6624a0aaeb Remove RelWithDebInfo from posix-cmake-test, because it fails under macos-14 2024-06-21 21:59:41 +03:00
Peter Dimov
ca76415503 Set CMAKE_BUILD_TYPE in posix-cmake-test 2024-06-21 21:53:32 +03:00
Peter Dimov
4352901d19 Move tests to their own function to ensure two stack frames 2024-06-21 21:42:05 +03:00
Peter Dimov
2820ed36b5 Change Windows jobs from Release to RelWithDebInfo 2024-06-21 20:09:21 +03:00
Peter Dimov
1a389747a3 Change test/CMakeLists.txt to use Boost::stacktrace 2024-06-21 20:01:34 +03:00
Peter Dimov
1db160d566 Change cmake_subdir_test and cmake_install_test to use Boost::stacktrace 2024-06-21 19:59:27 +03:00
Peter Dimov
1b16c5d6ae Add the boost_stacktrace library to CMakeLists.txt (an alias to the default backend) 2024-06-21 19:58:30 +03:00
Peter Dimov
274aeaa351 Disable static linking in GHA because of https://github.com/boostorg/stacktrace/issues/169 2024-06-21 18:33:09 +03:00
Peter Dimov
a615135de0 Update test/CMakeLists.txt 2024-06-21 18:12:51 +03:00
Peter Dimov
32749a7041 Update ci.yml 2024-06-21 18:07:37 +03:00
Peter Dimov
08d4f46333 Update test/CMakeLists.txt 2024-06-21 18:04:40 +03:00
Peter Dimov
97bc049bcb Link to ${CMAKE_DL_LIBS} where appropriate 2024-06-21 17:29:27 +03:00
Peter Dimov
98ed11d235 Update test/CMakeLists.txt 2024-06-21 17:25:11 +03:00
Peter Dimov
f1c5cd8963 Update test/CMakeLists.txt 2024-06-21 17:19:56 +03:00
Peter Dimov
94f11c52eb Add test/CMakeLists.txt 2024-06-21 17:13:06 +03:00
Peter Dimov
f6f3623594 Update cmake_install_test/CMakeLists.txt 2024-06-21 17:09:47 +03:00
Peter Dimov
aad95c2667 Add cmake_install_test, cmake_subdir_test 2024-06-21 17:05:04 +03:00
Peter Dimov
a95e7e5860 Add CMake jobs to GHA 2024-06-21 16:59:21 +03:00
Peter Dimov
8b79199a2a Merge pull request #168 from leha-bot/hotfix-for-cmake
hotfix for boost superproject CI
2024-06-21 16:56:41 +03:00
leha-bot
6e39a41abf hotfix for boost superproject CI 2024-06-21 14:59:41 +03:00
Alex
5747f85c0b CMake: add Boost::stacktrace ALIAS target for platform defaults (#167) 2024-06-20 11:26:28 +03:00
Antony Polukhin
c093aef138 Require support for noexcept and template aliases in tests 2024-06-20 10:42:31 +03:00
Antony Polukhin
66c0f7a54f avoid memory leaks and make the code more C++ish 2024-06-12 18:13:01 +03:00
Clément Chigot
aacfc2e557 Add dladdr minimal support for AIX
AIX doesn't provide dladdr syscall. This patch implements a minimal
version in order to be able to compile stacktrace.
2024-06-12 18:13:01 +03:00
Antony Polukhin
80af3a44c3 Fix shadowing (fixes #141) 2024-06-11 12:19:03 +03:00
Antony Polukhin
69260779d1 fix a typo in assert (fixes #164) 2024-06-10 22:24:16 +03:00
Peter Dimov
2c83563695 Add a conditional rule for enabling boost_stacktrace_from_exception. Fixes #165. (#166) 2024-05-27 11:38:17 +03:00
Marat Abrarov
39afcefb64 Avoid inclusion of rarely used Windows SDK headers which can cause conflict with other code using Windows SDK. (#157)
Signed-off-by: Marat Abrarov <abrarov@gmail.com>
2024-04-16 11:47:28 +03:00
huangqinjin
d1b7a61353 Implement stacktrace from current exception for MSVC (#159)
std::current_exception() makes a copy of current exception object
into returned std::exception_ptr. So the tracking of the original
exception object and its stacktrace are lost.
2024-04-16 11:39:07 +03:00
Antony Polukhin
351b03d522 Fix typo in documentation (fixes #158) 2024-04-01 12:17:55 +03:00
Antony Polukhin
a33e198cf6 More clarifications for async-signal-safety (refs #131) (#156) 2024-03-04 11:45:49 +03:00
Antony Polukhin
824f0c0ea7 Clarify the async-signal-safety guarantees in docs (refs #131) (#154) 2024-02-29 20:47:13 +03:00
Antony Polukhin
f783534b0f Fix frame_msvc.ipp compilation 2024-02-23 14:04:26 +03:00
Antony Polukhin
27093f24cb Update frame_msvc.ipp 2024-02-23 13:50:11 +03:00
Antony Polukhin
12e07fcca1 CI fixes (#153)
* Update thread_safety_checking.cpp to use Standard Library types
* Remove MinGW runs due to https://github.com/boostorg/system/issues/116
* Delete the shared memory example sources
2024-02-22 09:12:00 +03:00
Antony Polukhin
95caaeaf99 Option to disable boost_stacktrace_from_exception library build 2024-02-17 10:26:49 +03:00
Antony Polukhin
906bb0b551 Add unignorable info on memory leaks for affected platforms (#150) 2024-02-16 08:49:57 +03:00
Antony Polukhin
87ef7f6950 Fix build (failure was noted in #147) (#151) 2024-02-15 09:19:27 +03:00
Antony Polukhin
f6d4e117cd Add missing include 2024-02-12 22:21:35 +03:00
Antony Polukhin
0d8aed6bc9 Library for getting stacktraces from arbitrary exceptions (#147) 2024-02-07 11:27:45 +03:00
Antony Polukhin
3de5aea554 Merge pull request #149 from Lastique/feature/update_filesystem_usage
Update Boost.Filesystem usage
2024-01-27 11:54:24 +03:00
Andrey Semashev
e9e0b6c3d4 Updated Boost.Filesystem usage.
Removed usage of Boost.Filesystem APIs that were deprecated and
then removed.
2024-01-27 01:28:50 +03:00
Antony Polukhin
1fd3665a71 Allow building stacktrace libraries with global visibility (fixes #146) 2024-01-20 11:03:31 +03:00
Antony Polukhin
0ec802df84 Update copyright years 2024-01-07 13:03:02 +03:00
Antony Polukhin
4f2da0e653 Merge pull request #143 from francesco-ballarin/develop
Add missing cstdint include to detail/addr_base.hpp
2023-10-20 19:02:54 +03:00
Francesco Ballarin
8b1699c9d3 Add missing cstdint include to detail/addr_base.hpp 2023-10-01 10:14:34 +02:00
yhsb2k
dc5cd9d1f3 Fix build with MinGW-w64 12+. (#140)
For more details see: https://github.com/boostorg/stacktrace/issues/133

Accommodate mingw-llvm to this fix as well

macros defined by mingw-llvm 16 (https://github.com/mstorsjo/llvm-mingw):
#define __GNUC_MINOR__ 2
#define __GNUC_PATCHLEVEL__ 1
#define __GNUC__ 4

#define __clang_major__ 16
#define __clang_minor__ 0
#define __clang_patchlevel__ 0
2023-09-02 16:36:27 +03:00
ja2142
fbcd543b51 fix addr2line for pie binaries (#138) 2023-08-27 21:34:56 +03:00
Antony Polukhin
d849b145a6 disable some of the CI tests (2) 2023-08-27 18:27:41 +03:00
Antony Polukhin
760203fde5 disable some of the CI tests 2023-08-27 15:38:09 +03:00
Antony Polukhin
6a7510bd5e Do not produce and explicit hard error if compiler may not support some of the C++11 features 2023-08-27 15:26:56 +03:00
Antony Polukhin
959b65f303 CI fix attempt (3) 2023-08-26 21:18:46 +03:00
Antony Polukhin
d6320cc5a7 CI fix attempt (2) 2023-08-26 17:10:23 +03:00
Antony Polukhin
22a2c3920b CI fix attempt 2023-08-26 10:42:57 +03:00
Antony Polukhin
fc21c82b27 do not run tests on old MSVC in appveyor 2023-08-25 14:14:40 +03:00
Antony Polukhin
ae87ac9bcf update appveyor CI setup 2023-08-25 12:36:33 +03:00
Antony Polukhin
15b12e6e95 run tests on more compilers 2023-08-25 12:09:31 +03:00
Mohammad Nejati
34441a64c8 Use relative URL for redirect in index.html (#137) 2023-08-12 11:27:01 +03:00
Alex
abba18524f Modernize to cpp11 (#139)
Drop support for C++03

Boost.Stacktrace 1.84 now requires C++11.
2023-08-11 21:32:41 +03:00
Antony Polukhin
c6e7712868 update CI (1) 2023-05-21 12:42:28 +03:00
Antony Polukhin
c836328054 update CI setup 2023-05-21 10:45:29 +03:00
Antony Polukhin
71da3cfd56 add C++03 deprecation warnings 2023-05-14 20:06:38 +03:00
Antony Polukhin
95065ca638 Merge pull request #132 from Chocobo1/typo
Fix typos
2023-02-21 14:27:08 +03:00
Chocobo1
b9a0a12f1c Fix typo 2023-02-08 17:45:10 +08:00
Antony Polukhin
4cf47389c1 Update copyright years 2023-01-19 10:21:22 +03:00
Antony Polukhin
d904d26f4f Fix multithreading flag detection for backtrace_create_state if BOOST_STACKTRACE_BACKTRACE_FORCE_STATIC is defined 2023-01-18 17:16:51 +03:00
Antony Polukhin
cd4c5fe554 fix a type that was noted in https://github.com/boostorg/stacktrace/issues/118#issuecomment-1315142952 2023-01-18 17:14:49 +03:00
Antony Polukhin
12e3743e58 Simplify Jamfile a little-bit
Relates: https://github.com/boostorg/stacktrace/issues/119
2022-09-12 16:29:05 +03:00
Antony Polukhin
6db6fd0c01 Use BOOST_STACKTRACE_BACKTRACE_INCLUDE_FILE while detecting the libbacktrace availability in b2
Fixes: https://github.com/boostorg/stacktrace/issues/115
2022-09-12 15:46:46 +03:00
Antony Polukhin
57db1f511e Update CI 2022-09-02 17:40:44 +03:00
Antony Polukhin
308b7f6b08 allow forcing the static backtrace_state
References: https://github.com/boostorg/stacktrace/issues/118
2022-09-02 12:20:30 +03:00
Antony Polukhin
b856a99f9f fix and make sure that boost/stacktrace/stacktrace.hpp header has no unresolved references
Fixes: https://github.com/boostorg/stacktrace/issues/116
2022-09-02 10:38:17 +03:00
Antony Polukhin
6bf1a98d97 Merge pull request #127 from boostorg/antoshkka/no-more-strlen
avoid strlen() calls by using the size-1 from GetNameByOffset
2022-09-01 19:45:36 +03:00
Antony Polukhin
cc4d16e2ad avoid strlen() calls by using the size-1 from GetNameByOffset
Refs: https://github.com/boostorg/stacktrace/issues/122
2022-09-01 19:02:46 +03:00
Antony Polukhin
7c6778e9f4 Merge pull request #126 from boostorg/antoshkka/no-more-com-init
remove COM-initialization related tests and notes in docs
2022-09-01 18:51:16 +03:00
Antony Polukhin
e5940e7103 remove COM-initialization related tests and notes in docs 2022-09-01 17:51:22 +03:00
Antony Polukhin
bac3611ad8 Merge pull request #123 from AlexGuteniev/windows-dbgeng-tweak
Don't initialize COM, as it is not required
2022-09-01 17:42:13 +03:00
Alex Guteniev
9e8510076d BOOST_STACKTRACE_USE_WINDBG_CACHED support 2022-02-18 20:08:31 +02:00
Alex Guteniev
a60ee55b36 Don't initialize COM
Resolve #121
2022-02-18 19:45:26 +02:00
Antony Polukhin
75b7986f97 update copyright years 2022-01-30 14:47:24 +03:00
Antony Polukhin
3f3f9020fb do not use depth 1 for checkouts in CI 2021-09-20 21:55:43 +03:00
Antony Polukhin
898fedac41 modernize CI setup 2021-09-11 18:15:38 +03:00
67 changed files with 2608 additions and 749 deletions

View File

@@ -17,35 +17,19 @@ jobs:
fail-fast: false
matrix:
include:
- toolset: gcc-7
cxxstd: "03,11,14,17"
os: ubuntu-18.04
- toolset: gcc-9
- toolset: gcc-12
cxxstd: "03,11,14,17,2a"
os: ubuntu-18.04
- toolset: gcc-10
cxxstd: "03,11,14,17,2a"
os: ubuntu-18.04
os: ubuntu-22.04
cxxflags: "cxxflags=--coverage -fsanitize=address,leak,undefined -fno-sanitize-recover=undefined"
linkflags: "linkflags=--coverage -lasan -lubsan"
launcher: "testing.launcher=LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libasan.so.6"
gcov_tool: "gcov-10"
- toolset: clang
compiler: clang++-3.7
cxxstd: "03,11,14"
os: ubuntu-16.04
install: clang-3.7
- toolset: clang
compiler: clang++-9
gcov_tool: "gcov-12"
launcher: "testing.launcher=LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libasan.so.8"
- toolset: gcc-9
cxxstd: "03,11,14,17,2a"
os: ubuntu-20.04
cxxflags: "cxxflags=--coverage"
linkflags: "linkflags=--coverage"
gcov_tool: "llvm-cov-9 gcov"
- toolset: clang
compiler: clang++-10
os: ubuntu-22.04
- toolset: clang-15
cxxstd: "03,11,14,17,2a"
os: ubuntu-20.04
os: ubuntu-22.04
# TODO: fix and uncomment
#- toolset: clang
# cxxstd: "03,11,14,17,2a"
@@ -56,7 +40,7 @@ jobs:
runs-on: ${{matrix.os}}
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Install packages
if: matrix.install
@@ -87,11 +71,6 @@ jobs:
./b2 -d0 headers
./b2 -j4 variant=debug tools/inspect/build
- name: Create user-config.jam
if: matrix.compiler
run: |
echo "using ${{matrix.toolset}} : : ${{matrix.compiler}} ;" > ~/user-config.jam
- name: Run tests
run: |
cd ../boost-root
@@ -105,9 +84,9 @@ jobs:
echo -e "#!/bin/bash\nexec ${{matrix.gcov_tool}} \"\$@\"" > $GITHUB_WORKSPACE/coveralls/gcov_wrapper.sh
chmod +x $GITHUB_WORKSPACE/coveralls/gcov_wrapper.sh
wget https://github.com/linux-test-project/lcov/archive/v1.15.zip
unzip v1.15.zip
LCOV="`pwd`/lcov-1.15/bin/lcov --gcov-tool $GITHUB_WORKSPACE/coveralls/gcov_wrapper.sh"
wget https://github.com/linux-test-project/lcov/archive/v1.16.zip
unzip v1.16.zip
LCOV="`pwd`/lcov-1.16/bin/lcov --gcov-tool $GITHUB_WORKSPACE/coveralls/gcov_wrapper.sh"
echo "$LCOV --directory ../boost-root/bin.v2/libs/$LIBRARY/ --base-directory `pwd`/libs/$LIBRARY/test --capture --output-file $GITHUB_WORKSPACE/coveralls/coverage.info"
$LCOV --directory ../boost-root/bin.v2/libs/$LIBRARY/ --base-directory ../boost-root/ --capture --output-file $GITHUB_WORKSPACE/coveralls/coverage.info
@@ -131,10 +110,10 @@ jobs:
fail-fast: false
matrix:
include:
- toolset: msvc-14.1
- toolset: msvc
cxxstd: "14,17,latest"
addrmd: 64
os: windows-2016
os: windows-2022
- toolset: msvc-14.2
cxxstd: "14,17,latest"
addrmd: 64
@@ -147,7 +126,7 @@ jobs:
runs-on: ${{matrix.os}}
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Setup Boost
shell: cmd
@@ -163,7 +142,7 @@ jobs:
for /f %%i in ("%GITHUB_BASE_REF%") do if "%%~nxi" == "master" set BOOST_BRANCH=master
echo BOOST_BRANCH: %BOOST_BRANCH%
cd ..
git clone -b %BOOST_BRANCH% --depth 1 https://github.com/boostorg/boost.git boost-root
git clone -b %BOOST_BRANCH% --depth 10 https://github.com/boostorg/boost.git boost-root
cd boost-root
xcopy /s /e /q %GITHUB_WORKSPACE% libs\%LIBRARY%\
git submodule update --init tools/boostdep
@@ -186,3 +165,338 @@ jobs:
with:
github-token: ${{ secrets.github_token }}
parallel-finished: true
posix-cmake-subdir:
strategy:
fail-fast: false
matrix:
os: [ ubuntu-20.04, ubuntu-22.04, macos-13, macos-14 ]
shared: [ OFF, ON ]
runs-on: ${{matrix.os}}
steps:
- uses: actions/checkout@v4
- name: Install packages
if: matrix.install
run: sudo apt-get -y install ${{matrix.install}}
- name: Setup Boost
run: |
echo GITHUB_REPOSITORY: $GITHUB_REPOSITORY
LIBRARY=${GITHUB_REPOSITORY#*/}
echo LIBRARY: $LIBRARY
echo "LIBRARY=$LIBRARY" >> $GITHUB_ENV
echo GITHUB_BASE_REF: $GITHUB_BASE_REF
echo GITHUB_REF: $GITHUB_REF
REF=${GITHUB_BASE_REF:-$GITHUB_REF}
REF=${REF#refs/heads/}
echo REF: $REF
BOOST_BRANCH=develop && [ "$REF" == "master" ] && BOOST_BRANCH=master || true
echo BOOST_BRANCH: $BOOST_BRANCH
cd ..
git clone -b $BOOST_BRANCH --depth 1 https://github.com/boostorg/boost.git boost-root
cd boost-root
cp -r $GITHUB_WORKSPACE/* libs/$LIBRARY
git submodule update --init tools/boostdep
python tools/boostdep/depinst/depinst.py --git_args "--jobs 3" $LIBRARY
- name: Use library with add_subdirectory
run: |
cd ../boost-root/libs/$LIBRARY/test/cmake_subdir_test
mkdir __build__ && cd __build__
cmake -DBUILD_SHARED_LIBS=${{matrix.shared}} ..
cmake --build .
ctest --output-on-failure --no-tests=error
posix-cmake-install:
strategy:
fail-fast: false
matrix:
os: [ ubuntu-20.04, ubuntu-22.04, macos-13, macos-14 ]
shared: [ OFF, ON ]
runs-on: ${{matrix.os}}
steps:
- uses: actions/checkout@v4
- name: Install packages
if: matrix.install
run: sudo apt-get -y install ${{matrix.install}}
- name: Setup Boost
run: |
echo GITHUB_REPOSITORY: $GITHUB_REPOSITORY
LIBRARY=${GITHUB_REPOSITORY#*/}
echo LIBRARY: $LIBRARY
echo "LIBRARY=$LIBRARY" >> $GITHUB_ENV
echo GITHUB_BASE_REF: $GITHUB_BASE_REF
echo GITHUB_REF: $GITHUB_REF
REF=${GITHUB_BASE_REF:-$GITHUB_REF}
REF=${REF#refs/heads/}
echo REF: $REF
BOOST_BRANCH=develop && [ "$REF" == "master" ] && BOOST_BRANCH=master || true
echo BOOST_BRANCH: $BOOST_BRANCH
cd ..
git clone -b $BOOST_BRANCH --depth 1 https://github.com/boostorg/boost.git boost-root
cd boost-root
cp -r $GITHUB_WORKSPACE/* libs/$LIBRARY
git submodule update --init tools/boostdep
python tools/boostdep/depinst/depinst.py --git_args "--jobs 3" $LIBRARY
- name: Configure
run: |
cd ../boost-root
mkdir __build__ && cd __build__
cmake -DBOOST_INCLUDE_LIBRARIES=$LIBRARY -DCMAKE_INSTALL_PREFIX=~/.local -DBUILD_SHARED_LIBS=${{matrix.shared}} ..
- name: Build
run: |
cd ../boost-root/__build__
cmake --build .
- name: Install
run: |
cd ../boost-root/__build__
cmake --build . --target install
- name: Use the installed library
run: |
cd ../boost-root/libs/$LIBRARY/test/cmake_install_test && mkdir __build__ && cd __build__
cmake -DCMAKE_INSTALL_PREFIX=~/.local ..
cmake --build .
export LD_LIBRARY_PATH=$HOME/.local/lib:$LD_LIBRARY_PATH
ctest --output-on-failure --no-tests=error
posix-cmake-test:
strategy:
fail-fast: false
matrix:
os: [ ubuntu-20.04, ubuntu-22.04, macos-13, macos-14 ]
shared: [ OFF, ON ]
runs-on: ${{matrix.os}}
steps:
- uses: actions/checkout@v4
- name: Install packages
if: matrix.install
run: sudo apt-get -y install ${{matrix.install}}
- name: Setup Boost
run: |
echo GITHUB_REPOSITORY: $GITHUB_REPOSITORY
LIBRARY=${GITHUB_REPOSITORY#*/}
echo LIBRARY: $LIBRARY
echo "LIBRARY=$LIBRARY" >> $GITHUB_ENV
echo GITHUB_BASE_REF: $GITHUB_BASE_REF
echo GITHUB_REF: $GITHUB_REF
REF=${GITHUB_BASE_REF:-$GITHUB_REF}
REF=${REF#refs/heads/}
echo REF: $REF
BOOST_BRANCH=develop && [ "$REF" == "master" ] && BOOST_BRANCH=master || true
echo BOOST_BRANCH: $BOOST_BRANCH
cd ..
git clone -b $BOOST_BRANCH --depth 1 https://github.com/boostorg/boost.git boost-root
cd boost-root
cp -r $GITHUB_WORKSPACE/* libs/$LIBRARY
git submodule update --init tools/boostdep
python tools/boostdep/depinst/depinst.py --git_args "--jobs 3" $LIBRARY
- name: Configure (Debug)
run: |
cd ../boost-root
mkdir __build_debug__ && cd __build_debug__
cmake -DBOOST_INCLUDE_LIBRARIES=$LIBRARY -DBUILD_TESTING=ON -DBUILD_SHARED_LIBS=${{matrix.shared}} -DCMAKE_BUILD_TYPE=Debug ..
- name: Build tests (Debug)
run: |
cd ../boost-root/__build_debug__
cmake --build . --target tests
- name: Run tests (Debug)
run: |
cd ../boost-root/__build_debug__
ctest --output-on-failure --no-tests=error
windows-cmake-subdir:
strategy:
fail-fast: false
matrix:
os: [ windows-2019, windows-2022 ]
shared: [ OFF, ON ]
runs-on: ${{matrix.os}}
steps:
- uses: actions/checkout@v4
- name: Setup Boost
shell: cmd
run: |
echo GITHUB_REPOSITORY: %GITHUB_REPOSITORY%
for /f %%i in ("%GITHUB_REPOSITORY%") do set LIBRARY=%%~nxi
echo LIBRARY: %LIBRARY%
echo LIBRARY=%LIBRARY%>>%GITHUB_ENV%
echo GITHUB_BASE_REF: %GITHUB_BASE_REF%
echo GITHUB_REF: %GITHUB_REF%
if "%GITHUB_BASE_REF%" == "" set GITHUB_BASE_REF=%GITHUB_REF%
set BOOST_BRANCH=develop
for /f %%i in ("%GITHUB_BASE_REF%") do if "%%~nxi" == "master" set BOOST_BRANCH=master
echo BOOST_BRANCH: %BOOST_BRANCH%
cd ..
git clone -b %BOOST_BRANCH% --depth 1 https://github.com/boostorg/boost.git boost-root
cd boost-root
xcopy /s /e /q %GITHUB_WORKSPACE% libs\%LIBRARY%\
git submodule update --init tools/boostdep
python tools/boostdep/depinst/depinst.py --git_args "--jobs 3" %LIBRARY%
- name: Use library with add_subdirectory (Debug)
shell: cmd
run: |
cd ../boost-root/libs/%LIBRARY%/test/cmake_subdir_test
mkdir __build__ && cd __build__
cmake -DBUILD_SHARED_LIBS=${{matrix.shared}} ..
cmake --build . --config Debug
ctest --output-on-failure --no-tests=error -C Debug
- name: Use library with add_subdirectory (RelWithDebInfo)
shell: cmd
run: |
cd ../boost-root/libs/%LIBRARY%/test/cmake_subdir_test/__build__
cmake --build . --config RelWithDebInfo
ctest --output-on-failure --no-tests=error -C RelWithDebInfo
windows-cmake-install:
strategy:
fail-fast: false
matrix:
os: [ windows-2019, windows-2022 ]
shared: [ OFF, ON ]
runs-on: ${{matrix.os}}
steps:
- uses: actions/checkout@v4
- name: Setup Boost
shell: cmd
run: |
echo GITHUB_REPOSITORY: %GITHUB_REPOSITORY%
for /f %%i in ("%GITHUB_REPOSITORY%") do set LIBRARY=%%~nxi
echo LIBRARY: %LIBRARY%
echo LIBRARY=%LIBRARY%>>%GITHUB_ENV%
echo GITHUB_BASE_REF: %GITHUB_BASE_REF%
echo GITHUB_REF: %GITHUB_REF%
if "%GITHUB_BASE_REF%" == "" set GITHUB_BASE_REF=%GITHUB_REF%
set BOOST_BRANCH=develop
for /f %%i in ("%GITHUB_BASE_REF%") do if "%%~nxi" == "master" set BOOST_BRANCH=master
echo BOOST_BRANCH: %BOOST_BRANCH%
cd ..
git clone -b %BOOST_BRANCH% --depth 1 https://github.com/boostorg/boost.git boost-root
cd boost-root
xcopy /s /e /q %GITHUB_WORKSPACE% libs\%LIBRARY%\
git submodule update --init tools/boostdep
python tools/boostdep/depinst/depinst.py --git_args "--jobs 3" %LIBRARY%
- name: Configure
shell: cmd
run: |
cd ../boost-root
mkdir __build__ && cd __build__
cmake -DBOOST_INCLUDE_LIBRARIES=%LIBRARY% -DCMAKE_INSTALL_PREFIX=C:/cmake-prefix -DBUILD_SHARED_LIBS=${{matrix.shared}} ..
- name: Install (Debug)
shell: cmd
run: |
cd ../boost-root/__build__
cmake --build . --target install --config Debug
- name: Install (RelWithDebInfo)
shell: cmd
run: |
cd ../boost-root/__build__
cmake --build . --target install --config RelWithDebInfo
- name: Use the installed library (Debug)
shell: cmd
run: |
cd ../boost-root/libs/%LIBRARY%/test/cmake_install_test && mkdir __build__ && cd __build__
cmake -DCMAKE_INSTALL_PREFIX=C:/cmake-prefix ..
cmake --build . --config Debug
PATH C:\cmake-prefix\bin;%PATH%
ctest --output-on-failure --no-tests=error -C Debug
- name: Use the installed library (RelWithDebInfo)
shell: cmd
run: |
cd ../boost-root/libs/%LIBRARY%/test/cmake_install_test/__build__
cmake --build . --config RelWithDebInfo
PATH C:\cmake-prefix\bin;%PATH%
ctest --output-on-failure --no-tests=error -C RelWithDebInfo
windows-cmake-test:
strategy:
fail-fast: false
matrix:
os: [ windows-2019, windows-2022 ]
shared: [ OFF, ON ]
runs-on: ${{matrix.os}}
steps:
- uses: actions/checkout@v4
- name: Setup Boost
shell: cmd
run: |
echo GITHUB_REPOSITORY: %GITHUB_REPOSITORY%
for /f %%i in ("%GITHUB_REPOSITORY%") do set LIBRARY=%%~nxi
echo LIBRARY: %LIBRARY%
echo LIBRARY=%LIBRARY%>>%GITHUB_ENV%
echo GITHUB_BASE_REF: %GITHUB_BASE_REF%
echo GITHUB_REF: %GITHUB_REF%
if "%GITHUB_BASE_REF%" == "" set GITHUB_BASE_REF=%GITHUB_REF%
set BOOST_BRANCH=develop
for /f %%i in ("%GITHUB_BASE_REF%") do if "%%~nxi" == "master" set BOOST_BRANCH=master
echo BOOST_BRANCH: %BOOST_BRANCH%
cd ..
git clone -b %BOOST_BRANCH% --depth 1 https://github.com/boostorg/boost.git boost-root
cd boost-root
xcopy /s /e /q %GITHUB_WORKSPACE% libs\%LIBRARY%\
git submodule update --init tools/boostdep
python tools/boostdep/depinst/depinst.py --git_args "--jobs 3" %LIBRARY%
- name: Configure
shell: cmd
run: |
cd ../boost-root
mkdir __build__ && cd __build__
cmake -DBOOST_INCLUDE_LIBRARIES=%LIBRARY% -DBUILD_TESTING=ON -DBUILD_SHARED_LIBS=${{matrix.shared}} ..
- name: Build tests (Debug)
shell: cmd
run: |
cd ../boost-root/__build__
cmake --build . --target tests --config Debug
- name: Run tests (Debug)
shell: cmd
run: |
cd ../boost-root/__build__
ctest --output-on-failure --no-tests=error -C Debug
- name: Build tests (RelWithDebInfo)
shell: cmd
run: |
cd ../boost-root/__build__
cmake --build . --target tests --config RelWithDebInfo
- name: Run tests (RelWithDebInfo)
shell: cmd
run: |
cd ../boost-root/__build__
ctest --output-on-failure --no-tests=error -C RelWithDebInfo

View File

@@ -1,161 +0,0 @@
# Use, modification, and distribution are
# subject to the Boost Software License, Version 1.0. (See accompanying
# file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#
# Copyright Antony Polukhin 2014-2021.
#
# See https://svn.boost.org/trac/boost/wiki/TravisCoverals for description of this file
# and how it can be used with Boost libraries.
#
# File revision #10
language: cpp
os: linux
# `--coverage` flags required to generate coverage info for Coveralls
matrix:
include:
- env: B2_ARGS='cxxstd=98,03,11,14,1y toolset=gcc-6 cxxflags="--coverage -fsanitize=address,leak,undefined -fno-sanitize-recover=undefined -DBOOST_TRAVISCI_BUILD -fno-rtti" linkflags="--coverage -lasan -lubsan" "testing.launcher=LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libasan.so.3"' GCOVTOOL='gcov-6'
name: "GCC-6, no RTTI"
addons:
apt:
sources: ubuntu-toolchain-r-test
packages: g++-6
- env: B2_ARGS='cxxstd=98,03,11,14,1z toolset=gcc-8 cxxflags="--coverage -fsanitize=address,leak,undefined -fno-sanitize-recover=undefined -DBOOST_TRAVISCI_BUILD" linkflags="--coverage -lasan -lubsan" "testing.launcher=LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libasan.so.5"' GCOVTOOL='gcov-8'
name: "GCC-8"
sudo: required # Required by leak sanitizer
addons:
apt:
sources: ubuntu-toolchain-r-test
packages: g++-8
- env: B2_ARGS='cxxstd=98,0x toolset=gcc-4.6 cxxflags="--coverage -DBOOST_TRAVISCI_BUILD" linkflags="--coverage"' GCOVTOOL='gcov-4.6'
name: "GCC-4.6"
addons:
apt:
sources: ubuntu-toolchain-r-test
packages: g++-4.6
# - env: B2_ARGS='cxxstd=98,03,11,14,1y toolset=gcc-8 cxxflags="--coverage -fsanitize=address,leak,undefined -fno-sanitize-recover=undefined -DBOOST_TRAVISCI_BUILD -fno-exceptions" linkflags="--coverage -lasan -lubsan"'
# name: "GCC-8, no exceptions"
# sudo: required # Required by leak sanitizer
# addons:
# apt:
# sources: ubuntu-toolchain-r-test
# packages: g++-8
# Not running UBSan because it gives an error for some tests:
# test_impl.cpp:14:16: runtime error: call to function (unknown) through pointer to incorrect function type 'std::pair<stacktrace, stacktrace> (*)(int)'
- env: B2_ARGS='cxxstd=98,03,11,14,1z toolset=clang-8 cxxflags="--coverage -fsanitize=address,leak -DBOOST_TRAVISCI_BUILD" linkflags="--coverage -fsanitize=address,leak"' GCOVTOOL='gcov_for_clang.sh'
name: "Clang-8"
sudo: required # Required by leak sanitizer
addons:
apt:
sources: llvm-toolchain-trusty-8
packages: clang-8
# Sanitizers disabled for this toolset as they started causing link troubles:
# hidden symbol `_ZNSt3__112basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEE11__recommendEm' isn't defined
- env: B2_ARGS='cxxstd=03,11,14 toolset=clang-libc++ cxxflags="--coverage -DBOOST_TRAVISCI_BUILD" linkflags="--coverage"' GCOVTOOL='gcov_for_clang.sh'
name: "Clang-3.8, libc++"
addons:
apt:
packages: libc++-dev
###############################################################################################################
# From this point and below code is same for all the Boost libs
###############################################################################################################
# Installing additional tools
addons:
apt:
sources: git-core
packages:
- git
- python-yaml
- binutils # for addr2line tests of Boost.Stacktrace
before_install:
# Autodetect Boost branch by using the following code: - BOOST_BRANCH=$TRAVIS_BRANCH
# or just directly specify it
- BOOST_BRANCH=develop && [ "$TRAVIS_BRANCH" == "master" ] && BOOST_BRANCH=master || true
# Files, which coverage results must be ignored (files from other projects).
# Example: - IGNORE_COVERAGE='*/boost/progress.hpp */filesystem/src/*'
- IGNORE_COVERAGE='*/filesystem/src/* */thread/src/pthread/* */thread/src/future.cpp */timer/src/* operators.hpp'
# boost-local/libs/ folder to put this library into. This may be useful, if you're for example running Travis
# from `Boost.DLL` repo while Boost already has `dll` and with to replace `dll` with content of`Boost.DLL`.
#
# Otherwise just leave the default value - BOOST_LIBS_FOLDER=$(basename $TRAVIS_BUILD_DIR)
- BOOST_LIBS_FOLDER=$(basename $TRAVIS_BUILD_DIR)
# Global options for sanitizers
- UBSAN_OPTIONS=print_stacktrace=1
- LSAN_OPTIONS=verbosity=1:log_threads=1
# Cloning minimal set of Boost libraries
- BOOST=$HOME/boost-local
- git clone -b $BOOST_BRANCH --depth 10 https://github.com/boostorg/boost.git $BOOST
- cd $BOOST
- git submodule update --init --depth 10 --jobs 2 tools/build tools/boostdep tools/inspect libs/filesystem libs/interprocess # Boost.Interprocess is required for examples
- python tools/boostdep/depinst/depinst.py --git_args "--depth 10 --jobs 2" $BOOST/libs/filesystem
# Replacing Boost module with this project and installing Boost dependencies
- echo "Testing $BOOST/libs/$BOOST_LIBS_FOLDER moved from $TRAVIS_BUILD_DIR, branch $BOOST_BRANCH"
- rm -rf $BOOST/libs/$BOOST_LIBS_FOLDER || true
- mv $TRAVIS_BUILD_DIR $BOOST/libs/$BOOST_LIBS_FOLDER
- python tools/boostdep/depinst/depinst.py --git_args "--depth 10 --jobs 2" $BOOST_LIBS_FOLDER
- git status
# Adding missing toolsets and preparing Boost headers
- ./bootstrap.sh
- ./b2 headers
- ./b2 -j4 variant=debug tools/inspect/build
- |-
echo "using gcc ;" >> ~/user-config.jam
echo "using clang ;" >> ~/user-config.jam
echo "using clang : 3.8 : clang++-3.8 ;" >> ~/user-config.jam
echo "using clang : 4 : clang++-4.0 ;" >> ~/user-config.jam
echo "using clang : 5 : clang++-5.0 ;" >> ~/user-config.jam
echo "using clang : 6 : clang++-6.0 ;" >> ~/user-config.jam
echo "using clang : 7 : clang++-7.0 ;" >> ~/user-config.jam
echo "using clang : 8 : clang++-8 ;" >> ~/user-config.jam
echo "using clang : libc++ : clang++-libc++ ;" >> ~/user-config.jam
- cd $BOOST/libs/$BOOST_LIBS_FOLDER/test/
script:
- sh -c "../../../b2 -j2 $B2_ARGS"
- ../../../dist/bin/inspect ..
after_success:
- exit 0 # We run coverage repoprts from GithubActions
# Copying Coveralls data to a separate folder
- mkdir -p $TRAVIS_BUILD_DIR/coverals
- wget https://github.com/linux-test-project/lcov/archive/v1.15.zip
- unzip v1.15.zip
- LCOV="`pwd`/lcov-1.15/bin/lcov --gcov-tool $GCOVTOOL"
- mkdir -p ~/.local/bin
- echo -e '#!/bin/bash\nexec llvm-cov gcov "$@"' > ~/.local/bin/gcov_for_clang.sh
- chmod 755 ~/.local/bin/gcov_for_clang.sh
# Preparing Coveralls data by changind data format to a readable one
- echo "$LCOV --directory $BOOST/bin.v2/libs/$BOOST_LIBS_FOLDER --base-directory `pwd` --capture --output-file $TRAVIS_BUILD_DIR/coverals/coverage.info"
- $LCOV --directory $BOOST/bin.v2/libs/$BOOST_LIBS_FOLDER --base-directory `pwd` --capture --output-file $TRAVIS_BUILD_DIR/coverals/coverage.info
# ... erasing /test/ /example/ folder data
- cd $BOOST
- $LCOV --remove $TRAVIS_BUILD_DIR/coverals/coverage.info "/usr*" "*/$BOOST_LIBS_FOLDER/test/*" $IGNORE_COVERAGE "*/$BOOST_LIBS_FOLDER/tests/*" "*/$BOOST_LIBS_FOLDER/examples/*" "*/$BOOST_LIBS_FOLDER/example/*" -o $TRAVIS_BUILD_DIR/coverals/coverage.info
# ... erasing data that is not related to this project directly
- OTHER_LIBS=`grep "submodule .*" .gitmodules | sed 's/\[submodule\ "\(.*\)"\]/"\*\/boost\/\1\.hpp" "\*\/boost\/\1\/\*" "\*\/libs\/\1\/src\/\*"/g'| sed "/\"\*\/boost\/$BOOST_LIBS_FOLDER\/\*\"/d" | sed ':a;N;$!ba;s/\n/ /g'`
- echo $OTHER_LIBS
- eval "$LCOV --remove $TRAVIS_BUILD_DIR/coverals/coverage.info $OTHER_LIBS -o $TRAVIS_BUILD_DIR/coverals/coverage.info"
# Sending data to Coveralls
- cd $TRAVIS_BUILD_DIR
- gem install coveralls-lcov
- coveralls-lcov coverals/coverage.info

View File

@@ -22,13 +22,10 @@ function(stacktrace_add_library suffix opt libs defs)
target_link_libraries(boost_stacktrace_${suffix}
PUBLIC
Boost::array
Boost::config
Boost::container_hash
Boost::core
Boost::predef
Boost::static_assert
Boost::type_traits
Boost::winapi
PRIVATE
${libs}
@@ -74,14 +71,21 @@ endif()
stacktrace_check(BOOST_STACKTRACE_HAS_WINDBG has_windbg.cpp "" "dbgeng;ole32" "")
stacktrace_check(BOOST_STACKTRACE_HAS_WINDBG_CACHED has_windbg_cached.cpp "${CMAKE_CURRENT_SOURCE_DIR}/../config/include" "dbgeng;ole32" "")
set(_default_from_exception ON)
if (NOT CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64|AMD64|amd64|i386|i686|x86")
set(_default_from_exception OFF)
endif()
option(BOOST_STACKTRACE_ENABLE_NOOP "Boost.Stacktrace: build boost_stacktrace_noop" ON)
option(BOOST_STACKTRACE_ENABLE_BACKTRACE "Boost.Stacktrace: build boost_stacktrace_backtrace" ${BOOST_STACKTRACE_HAS_BACKTRACE})
option(BOOST_STACKTRACE_ENABLE_ADDR2LINE "Boost.Stacktrace: build boost_stacktrace_addr2line" ${_default_addr2line})
option(BOOST_STACKTRACE_ENABLE_BASIC "Boost.Stacktrace: build boost_stacktrace_basic" ON)
option(BOOST_STACKTRACE_ENABLE_WINDBG "Boost.Stacktrace: build boost_stacktrace_windbg" ${BOOST_STACKTRACE_HAS_WINDBG})
option(BOOST_STACKTRACE_ENABLE_WINDBG_CACHED "Boost.Stacktrace: build boost_stacktrace_windbg_cached" ${BOOST_STACKTRACE_HAS_WINDBG_CACHED})
option(BOOST_STACKTRACE_ENABLE_FROM_EXCEPTION "Boost.Stacktrace: build boost_stacktrace_from_exception" ${_default_from_exception})
unset(_default_addr2line)
unset(_default_from_exception)
message(STATUS "Boost.Stacktrace: "
"noop ${BOOST_STACKTRACE_ENABLE_NOOP}, "
@@ -89,16 +93,55 @@ message(STATUS "Boost.Stacktrace: "
"addr2line ${BOOST_STACKTRACE_ENABLE_ADDR2LINE}, "
"basic ${BOOST_STACKTRACE_ENABLE_BASIC}, "
"windbg ${BOOST_STACKTRACE_ENABLE_WINDBG}, "
"windbg_cached ${BOOST_STACKTRACE_ENABLE_WINDBG_CACHED}"
"windbg_cached ${BOOST_STACKTRACE_ENABLE_WINDBG_CACHED}, "
"from_exception ${BOOST_STACKTRACE_ENABLE_FROM_EXCEPTION}"
)
stacktrace_add_library(noop ${BOOST_STACKTRACE_ENABLE_NOOP} "" "")
stacktrace_add_library(backtrace ${BOOST_STACKTRACE_ENABLE_BACKTRACE} "backtrace" "")
stacktrace_add_library(addr2line ${BOOST_STACKTRACE_ENABLE_ADDR2LINE} "" "")
stacktrace_add_library(basic ${BOOST_STACKTRACE_ENABLE_BASIC} "" "")
stacktrace_add_library(backtrace ${BOOST_STACKTRACE_ENABLE_BACKTRACE} "backtrace;${CMAKE_DL_LIBS}" "")
stacktrace_add_library(addr2line ${BOOST_STACKTRACE_ENABLE_ADDR2LINE} "${CMAKE_DL_LIBS}" "")
stacktrace_add_library(basic ${BOOST_STACKTRACE_ENABLE_BASIC} "${CMAKE_DL_LIBS}" "")
stacktrace_add_library(windbg ${BOOST_STACKTRACE_ENABLE_WINDBG} "dbgeng;ole32" "_GNU_SOURCE=1")
stacktrace_add_library(windbg_cached ${BOOST_STACKTRACE_ENABLE_WINDBG_CACHED} "dbgeng;ole32" "_GNU_SOURCE=1")
# boost_stacktrace, default library
add_library(boost_stacktrace INTERFACE)
add_library(Boost::stacktrace ALIAS boost_stacktrace)
target_include_directories(boost_stacktrace INTERFACE include)
if(BOOST_STACKTRACE_ENABLE_WINDBG)
target_link_libraries(boost_stacktrace INTERFACE Boost::stacktrace_windbg)
elseif(BOOST_STACKTRACE_ENABLE_WINDBG_CACHED)
target_link_libraries(boost_stacktrace INTERFACE Boost::stacktrace_windbg)
elseif(BOOST_STACKTRACE_ENABLE_BACKTRACE)
target_link_libraries(boost_stacktrace INTERFACE Boost::stacktrace_backtrace)
elseif(BOOST_STACKTRACE_ENABLE_ADDR2LINE)
target_link_libraries(boost_stacktrace INTERFACE Boost::stacktrace_addr2line)
elseif(BOOST_STACKTRACE_ENABLE_BASIC)
target_link_libraries(boost_stacktrace INTERFACE Boost::stacktrace_basic)
elseif(BOOST_STACKTRACE_ENABLE_NOOP)
target_link_libraries(boost_stacktrace INTERFACE Boost::stacktrace_noop)
endif()
# Boost::stacktrace_from_exception is never the default
stacktrace_add_library(from_exception ${BOOST_STACKTRACE_ENABLE_FROM_EXCEPTION} "${CMAKE_DL_LIBS};boost_stacktrace" "")
#
if(BUILD_TESTING AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/test/CMakeLists.txt")
add_subdirectory(test)

View File

@@ -8,8 +8,8 @@ Boost.Stacktrace is a part of the [Boost C++ Libraries](https://github.com/boost
### Test results
@ | Build | Tests coverage | More info
----------------|-------------- | -------------- |-----------
Develop branch: | [![CI](https://github.com/boostorg/stacktrace/actions/workflows/ci.yml/badge.svg?branch=develop)](https://github.com/boostorg/stacktrace/actions/workflows/ci.yml) [![Build Status](https://travis-ci.org/boostorg/stacktrace.svg?branch=develop)](https://travis-ci.org/boostorg/stacktrace) [![Build status](https://ci.appveyor.com/api/projects/status/l3aak4j8k39rx08t/branch/develop?svg=true)](https://ci.appveyor.com/project/apolukhin/stacktrace/branch/develop) | [![Coverage Status](https://coveralls.io/repos/github/boostorg/stacktrace/badge.svg?branch=develop)](https://coveralls.io/github/boostorg/stacktrace?branch=develop) | [details...](https://www.boost.org/development/tests/develop/developer/stacktrace.html)
Master branch: | [![CI](https://github.com/boostorg/stacktrace/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/boostorg/stacktrace/actions/workflows/ci.yml) [![Build Status](https://travis-ci.org/boostorg/stacktrace.svg?branch=master)](https://travis-ci.org/boostorg/stacktrace) [![Build status](https://ci.appveyor.com/api/projects/status/l3aak4j8k39rx08t/branch/master?svg=true)](https://ci.appveyor.com/project/apolukhin/stacktrace/branch/master) | [![Coverage Status](https://coveralls.io/repos/github/boostorg/stacktrace/badge.svg?branch=master)](https://coveralls.io/github/boostorg/stacktrace?branch=master) | [details...](https://www.boost.org/development/tests/master/developer/stacktrace.html)
Develop branch: | [![CI](https://github.com/boostorg/stacktrace/actions/workflows/ci.yml/badge.svg?branch=develop)](https://github.com/boostorg/stacktrace/actions/workflows/ci.yml) [![Build status](https://ci.appveyor.com/api/projects/status/l3aak4j8k39rx08t/branch/develop?svg=true)](https://ci.appveyor.com/project/apolukhin/stacktrace/branch/develop) | [![Coverage Status](https://coveralls.io/repos/github/boostorg/stacktrace/badge.svg?branch=develop)](https://coveralls.io/github/boostorg/stacktrace?branch=develop) | [details...](https://www.boost.org/development/tests/develop/developer/stacktrace.html)
Master branch: | [![CI](https://github.com/boostorg/stacktrace/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/boostorg/stacktrace/actions/workflows/ci.yml) [![Build status](https://ci.appveyor.com/api/projects/status/l3aak4j8k39rx08t/branch/master?svg=true)](https://ci.appveyor.com/project/apolukhin/stacktrace/branch/master) | [![Coverage Status](https://coveralls.io/repos/github/boostorg/stacktrace/badge.svg?branch=master)](https://coveralls.io/github/boostorg/stacktrace?branch=master) | [details...](https://www.boost.org/development/tests/master/developer/stacktrace.html)
[Latest developer documentation](https://www.boost.org/doc/libs/develop/doc/html/stacktrace.html)

View File

@@ -0,0 +1,15 @@
# Copyright (C) 2016-2024, Antony Polukhin.
#
# Use, modification and distribution is subject to the Boost Software License,
# Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
# http://www.boost.org/LICENSE_1_0.txt)
#
import feature ;
feature.feature boost.stacktrace.noop : on off : optional propagated ;
feature.feature boost.stacktrace.backtrace : on off : optional propagated ;
feature.feature boost.stacktrace.addr2line : on off : optional propagated ;
feature.feature boost.stacktrace.basic : on off : optional propagated ;
feature.feature boost.stacktrace.windbg : on off : optional propagated ;
feature.feature boost.stacktrace.windbg_cached : on off : optional propagated ;
feature.feature boost.stacktrace.from_exception : on off : optional propagated ;

52
build.jam Normal file
View File

@@ -0,0 +1,52 @@
# Copyright René Ferdinand Rivera Morell 2023-2024
# Distributed under the Boost Software License, Version 1.0.
# (See accompanying file LICENSE_1_0.txt or copy at
# http://www.boost.org/LICENSE_1_0.txt)
require-b2 5.2 ;
import boost-stacktrace-features ;
constant boost_dependencies :
<library>/boost/config//boost_config
<library>/boost/container_hash//boost_container_hash
<library>/boost/core//boost_core
<library>/boost/predef//boost_predef
<target-os>windows:<library>/boost/winapi//boost_winapi ;
project /boost/stacktrace
: common-requirements
<include>include
;
explicit
[ alias boost_stacktrace_addr2line : build//boost_stacktrace_addr2line ]
[ alias boost_stacktrace_backtrace : build//boost_stacktrace_backtrace ]
[ alias boost_stacktrace_basic : build//boost_stacktrace_basic ]
[ alias boost_stacktrace_from_exception : build//boost_stacktrace_from_exception ]
[ alias boost_stacktrace_noop : build//boost_stacktrace_noop ]
[ alias boost_stacktrace_windbg : build//boost_stacktrace_windbg ]
[ alias boost_stacktrace_windbg_cached : build//boost_stacktrace_windbg_cached ]
[ alias boost_stacktrace : boost_stacktrace_noop ]
[ alias all :
boost_stacktrace_addr2line
boost_stacktrace_backtrace
boost_stacktrace_basic
boost_stacktrace_from_exception
boost_stacktrace_noop
boost_stacktrace_windbg
boost_stacktrace_windbg_cached
test
]
;
call-if : boost-library stacktrace
: install
boost_stacktrace_addr2line
boost_stacktrace_backtrace
boost_stacktrace_basic
boost_stacktrace_from_exception
boost_stacktrace_noop
boost_stacktrace_windbg
boost_stacktrace_windbg_cached
;

View File

@@ -1,13 +1,27 @@
# Copyright (C) 2016-2019, Antony Polukhin.
# Copyright (C) 2016-2024, Antony Polukhin.
#
# Use, modification and distribution is subject to the Boost Software License,
# Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
# http://www.boost.org/LICENSE_1_0.txt)
#
require-b2 5.0.1 ;
import-search /boost/config/checks ;
import boost-stacktrace-features ;
import config : requires ;
import configure ;
import property ;
constant boost_dependencies_private :
<library>/boost/assert//boost_assert
;
project
: source-location .
: common-requirements $(boost_dependencies)
: requirements
[ requires cxx11_rvalue_references ]
$(boost_dependencies_private)
: default-build
<visibility>hidden
;
@@ -16,13 +30,12 @@ lib gcc_s ;
lib Dbgeng ;
lib ole32 ;
local LIBBACKTRACE_PATH = [ modules.peek : LIBBACKTRACE_PATH ] ;
lib backtrace
:
:
: <search>$(LIBBACKTRACE_PATH)/lib <link>static
:
: <include>$(LIBBACKTRACE_PATH)/include
: <include>$(LIBBACKTRACE_PATH)/include
;
actions mp_simple_run_action
@@ -51,7 +64,15 @@ explicit WinDbg ;
mp-run-simple has_windbg_cached.cpp : : : <library>Dbgeng <library>ole32 : WinDbgCached ;
explicit WinDbgCached ;
local libraries ;
rule build-stacktrace-noop ( props * )
{
local enabled = [ property.select <boost.stacktrace.noop> : $(props) ] ;
switch $(enabled:G=)
{
case "on" : return ;
case "off" : return <build>no ;
}
}
lib boost_stacktrace_noop
: # sources
@@ -59,12 +80,27 @@ lib boost_stacktrace_noop
: # requirements
<warnings>all
<link>shared:<define>BOOST_STACKTRACE_DYN_LINK=1
<conditional>@build-stacktrace-noop
: # default build
: # usage-requirements
#<link>shared:<define>BOOST_STACKTRACE_DYN_LINK=1
<define>BOOST_STACKTRACE_NO_LIB=1
;
libraries += boost_stacktrace_noop ;
rule build-stacktrace-backtrace ( props * )
{
local enabled = [ property.select <boost.stacktrace.backtrace> : $(props) ] ;
switch $(enabled:G=)
{
case "on" : return ;
case "off" : return <build>no ;
}
if ! [ configure.builds libbacktrace : $(props) : "boost.stacktrace.backtrace" ]
{
return <build>no ;
}
}
lib boost_stacktrace_backtrace
: # sources
@@ -74,13 +110,34 @@ lib boost_stacktrace_backtrace
<target-os>linux:<library>dl
<library>backtrace
<link>shared:<define>BOOST_STACKTRACE_DYN_LINK=1
[ check-target-builds ../build//libbacktrace : : <build>no ]
<conditional>@build-stacktrace-backtrace
: # default build
: # usage-requirements
#<link>shared:<define>BOOST_STACKTRACE_DYN_LINK=1
<define>BOOST_STACKTRACE_NO_LIB=1
;
libraries += boost_stacktrace_backtrace ;
rule build-stacktrace-addr2line ( props * )
{
local enabled = [ property.select <boost.stacktrace.addr2line> : $(props) ] ;
switch $(enabled:G=)
{
case "on" : return ;
case "off" : return <build>no ;
}
# Disable by default on Windows when not using Cygwin
if <target-os>windows in $(props) && ! ( <target-os>cygwin in $(props) )
{
configure.log-library-search-result "boost.stacktrace.addr2line" : "no" ;
return <build>no ;
}
if ! [ configure.builds addr2line : $(props) : "boost.stacktrace.addr2line" ]
{
return <build>no ;
}
}
lib boost_stacktrace_addr2line
: # sources
@@ -89,13 +146,27 @@ lib boost_stacktrace_addr2line
<warnings>all
<target-os>linux:<library>dl
<link>shared:<define>BOOST_STACKTRACE_DYN_LINK=1
[ check-target-builds ../build//addr2line : : <build>no ]
<conditional>@build-stacktrace-addr2line
: # default build
: # usage-requirements
#<link>shared:<define>BOOST_STACKTRACE_DYN_LINK=1
<define>BOOST_STACKTRACE_NO_LIB=1
;
libraries += boost_stacktrace_addr2line ;
rule build-stacktrace-basic ( props * )
{
local enabled = [ property.select <boost.stacktrace.basic> : $(props) ] ;
switch $(enabled:G=)
{
case "on" : return ;
case "off" : return <build>no ;
}
if [ configure.builds WinDbg : $(props) : "boost.stacktrace.basic" ]
{
return <build>no ;
}
}
lib boost_stacktrace_basic
: # sources
@@ -104,13 +175,27 @@ lib boost_stacktrace_basic
<warnings>all
<target-os>linux:<library>dl
<link>shared:<define>BOOST_STACKTRACE_DYN_LINK=1
[ check-target-builds ../build//WinDbg : <build>no ]
<conditional>@build-stacktrace-basic
: # default build
: # usage-requirements
#<link>shared:<define>BOOST_STACKTRACE_DYN_LINK=1
<define>BOOST_STACKTRACE_NO_LIB=1
;
libraries += boost_stacktrace_basic ;
rule build-stacktrace-windbg ( props * )
{
local enabled = [ property.select <boost.stacktrace.windbg> : $(props) ] ;
switch $(enabled:G=)
{
case "on" : return ;
case "off" : return <build>no ;
}
if ! [ configure.builds WinDbg : $(props) : "boost.stacktrace.windbg" ]
{
return <build>no ;
}
}
lib boost_stacktrace_windbg
: # sources
@@ -119,13 +204,27 @@ lib boost_stacktrace_windbg
<warnings>all
<library>Dbgeng <library>ole32
<link>shared:<define>BOOST_STACKTRACE_DYN_LINK=1
[ check-target-builds ../build//WinDbg : : <build>no ]
<conditional>@build-stacktrace-windbg
: # default build
: # usage-requirements
#<link>shared:<define>BOOST_STACKTRACE_DYN_LINK=1
<define>BOOST_STACKTRACE_NO_LIB=1
;
libraries += boost_stacktrace_windbg ;
rule build-stacktrace-windbg-cached ( props * )
{
local enabled = [ property.select <boost.stacktrace.windbg_cached> : $(props) ] ;
switch $(enabled:G=)
{
case "on" : return ;
case "off" : return <build>no ;
}
if ! [ configure.builds WinDbgCached : $(props) : "boost.stacktrace.windbg_cached" ]
{
return <build>no ;
}
}
lib boost_stacktrace_windbg_cached
: # sources
@@ -134,12 +233,42 @@ lib boost_stacktrace_windbg_cached
<warnings>all
<library>Dbgeng <library>ole32
<link>shared:<define>BOOST_STACKTRACE_DYN_LINK=1
[ check-target-builds ../build//WinDbgCached : : <build>no ]
<conditional>@build-stacktrace-windbg-cached
: # default build
: # usage-requirements
#<link>shared:<define>BOOST_STACKTRACE_DYN_LINK=1
<define>BOOST_STACKTRACE_NO_LIB=1
;
libraries += boost_stacktrace_windbg_cached ;
rule build-stacktrace-from-exception ( props * )
{
local enabled = [ property.select <boost.stacktrace.from_exception> : $(props) ] ;
switch $(enabled:G=)
{
case "on" : return ;
case "off" : return <build>no ;
}
boost-install $(libraries) ;
local arch = [ property.select <architecture> : $(props) ] ;
if $(arch) && ( $(arch:G=) != x86 )
{
configure.log-library-search-result "boost.stacktrace.from_exception" : "no" ;
return <build>no ;
}
configure.log-library-search-result "boost.stacktrace.from_exception" : "yes" ;
}
lib boost_stacktrace_from_exception
: # sources
../src/from_exception.cpp
: # requirements
<warnings>all
<target-os>linux:<library>dl
# Enable build when explicitly requested, or by default, when on x86
<conditional>@build-stacktrace-from-exception
: # default build
: # usage-requirements
#<link>shared:<define>BOOST_STACKTRACE_DYN_LINK=1
<define>BOOST_STACKTRACE_NO_LIB=1
;

View File

@@ -1,10 +1,15 @@
// Copyright Antony Polukhin, 2016-2020.
// Copyright Antony Polukhin, 2016-2025.
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#include <backtrace.h>
#ifdef BOOST_STACKTRACE_BACKTRACE_INCLUDE_FILE
# include BOOST_STACKTRACE_BACKTRACE_INCLUDE_FILE
#else
# include <backtrace.h>
#endif
#include <unwind.h>
int main() {

View File

@@ -1,4 +1,4 @@
# Copyright Antony Polukhin 2016-2021.
# Copyright Antony Polukhin, 2016-2025.
# Use, modification, and distribution are
# subject to the Boost Software License, Version 1.0. (See accompanying
# file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
@@ -9,9 +9,9 @@ import doxygen ;
doxygen autodoc
:
[ glob ../../../boost/stacktrace.hpp ]
[ glob ../../../boost/stacktrace/*.hpp ]
[ glob ../../../boost/stacktrace/detail/frame_decl.hpp ]
[ glob ../include/boost/stacktrace.hpp ]
[ glob ../include/boost/stacktrace/*.hpp ]
[ glob ../include/boost/stacktrace/detail/frame_decl.hpp ]
:
<doxygen:param>EXTRACT_ALL=NO
<doxygen:param>HIDE_UNDOC_MEMBERS=YES
@@ -22,6 +22,9 @@ doxygen autodoc
<doxygen:param>SEARCH_INCLUDES=YES
<doxygen:param>SHORT_NAMES=NO
<doxygen:param>INCLUDE_PATH=../../../
<doxygen:param>"ALIASES= \\
\"asyncsafe=\\xmlonly<link linkend='stacktrace.theoretical_async_signal_safety'>\\endxmlonly Theoretically async signal safe \\xmlonly</link>\\endxmlonly\" \\
"
<doxygen:param>"PREDEFINED=\"stl_type_info=std::type_info\" \\
\"BOOST_EXPLICIT_OPERATOR_BOOL_NOEXCEPT()=explicit operator bool() const noexcept;\" \\
\"BOOST_CONSTEXPR_EXPLICIT_OPERATOR_BOOL()=explicit constexpr operator bool() const noexcept;\" \\
@@ -39,9 +42,9 @@ boostbook standalone
:
stacktrace
:
<xsl:param>boost.root=http://www.boost.org/doc/libs/1_63_0
<xsl:param>boost.root=http\://www.boost.org/doc/libs/1_84_0
# <xsl:param>boost.root=../../../..
<format>pdf:<xsl:param>boost.url.prefix=http://www.boost.org/doc/libs/release/doc/html
<format>pdf:<xsl:param>boost.url.prefix=http\://www.boost.org/doc/libs/release/doc/html
;
###############################################################################

View File

@@ -2,7 +2,7 @@
[quickbook 1.6]
[version 1.0]
[id stacktrace]
[copyright 2016-2021 Antony Polukhin]
[copyright 2016-2025 Antony Polukhin]
[category Language Features Emulation]
[license
Distributed under the Boost Software License, Version 1.0.
@@ -68,7 +68,7 @@ Pretty often assertions provide not enough information to locate the problem. Fo
Aborted (core dumped)
```
That's not enough to locate the problem without debugger. There may be thousand code lines in real world examples and hundred places where that assertion could happen. Let's try to improve the assertions, and make them more informative:
That's not enough to locate the problem without debugger. There may be thousand code lines in real world examples and hundred places where that assertion can happen. Let's try to improve the assertions, and make them more informative:
[getting_started_assert_handlers]
@@ -120,14 +120,80 @@ Previous run crashed:
9# 0x0000000000402209
```
[warning There's a temptation to write a signal handler that prints the stacktrace on `SIGSEGV` or abort. Unfortunately, there's no cross platform way to do that without a risk of deadlocking. Not all the platforms provide means for even getting stacktrace in async signal safe way.
[warning There's a temptation to write a signal handler that prints the stacktrace on `SIGSEGV` or abort. Unfortunately,
there's no cross platform way to do that without a risk of deadlocking.
Not all the platforms provide means for even getting stacktrace in async signal safe way.
Signal handler is often invoked on a separate stack and trash is returned on attempt to get a trace!
Generic recommendation is to *avoid signal handlers! Use* platform specific ways to store and decode *core files*.
See [link stacktrace.theoretical_async_signal_safety "Theoretical async signal safety"] for more info.
]
[endsect]
[section Stacktrace from arbitrary exception]
[warning At the moment the functionality is only available for some of the
popular C++ runtimes for POSIX systems with *libbacktrace* and for Windows.
Make sure that your platform is supported by running some tests.
]
The library provides a way to get stacktrace from an exception as if the
stacktrace was captured at the point the exception was thrown. Works even if
the exception was thrown from a third party binary library.
Link with
`boost_stacktrace_from_exception` library (or just `LD_PRELOAD` it!) and call
boost::stacktrace::stacktrace::from_current_exception() to get the trace:
```
#include <iostream>
#include <stdexcept>
#include <string_view>
#include <boost/stacktrace.hpp>
void foo(std::string_view key);
void bar(std::string_view key);
int main() {
try {
foo("test1");
bar("test2");
} catch (const std::exception& exc) {
boost::stacktrace::stacktrace trace = boost::stacktrace::stacktrace::from_current_exception(); // <---
std::cerr << "Caught exception: " << exc.what() << ", trace:\n" << trace;
}
}
```
The output of the above sample may be the following:
```
Caught exception: std::map::at, trace:
0# get_data_from_config(std::string_view) at /home/axolm/basic.cpp:600
1# bar(std::string_view) at /home/axolm/basic.cpp:6
2# main at /home/axolm/basic.cpp:17
```
With the above technique a developer can locate the source file and the function
that has thrown the exception without a debugger help. it is especially useful
for testing in containers (github CI, other CIs), where the developer has no
direct access to the testing environment and reproducing the issue is
complicated.
Note that linking with `boost_stacktrace_from_exception` may increase memory
consumption of the application, as the exceptions now additionally store traces.
At runtime switch boost::stacktrace::this_thread::set_capture_stacktraces_at_throw()
allows to disable/enable capturing and storing traces in exceptions.
To disable the `boost_stacktrace_from_exception` library builds the
`boost.stacktrace.from_exception=off` option, for example
`./b2 boost.stacktrace.from_exception=off`.
[endsect]
@@ -170,7 +236,7 @@ Code from above will output:
[section Enabling and disabling stacktraces]
At some point arises a requirement to easily enable/disable stacktraces for a whole project. That could be easily achieved.
At some point arises a requirement to easily enable/disable stacktraces for a whole project. That can be easily achieved.
Just define *BOOST_STACKTRACE_LINK* for a whole project. Now you can enable/disable stacktraces by just linking with different libraries:
@@ -185,7 +251,7 @@ See [link stacktrace.configuration_and_build section "Configuration and Build"]
[section Saving stacktraces by specified format]
[classref boost::stacktrace::stacktrace] provides access to individual [classref boost::stacktrace::frame frames] of the stacktrace,
so that you could save stacktrace information in your own format. Consider the example, that saves only function addresses of each frame:
so that you can save stacktrace information in your own format. Consider the example, that saves only function addresses of each frame:
[getting_started_trace_addresses]
@@ -233,49 +299,68 @@ Terminate called:
[endsect]
[/
[section Store stacktraces into shared memory]
There's a way to serialize stacktrace in async safe manner and share that serialized representation with another process. Here's another example with signal handlers.
This example is very close to the [link stacktrace.getting_started.handle_terminates_aborts_and_seg "Handle terminates, aborts and Segmentation Faults"], but this time we are dumping stacktrace into shared memory:
[getting_started_terminate_handlers_shmem]
After registering signal handlers and catching a signal, we may print stacktrace dumps on program restart:
[getting_started_on_program_restart_shmem]
The program output will be the following:
```
Previous run crashed and left trace in shared memory:
0# 0x00007FD51C7218EF
1# my_signal_handler2(int) at ../example/terminate_handler.cpp:68
2# 0x00007FD51B833CB0
3# 0x00007FD51B833C37
4# 0x00007FD51B837028
5# 0x00007FD51BE44BBD
6# 0x00007FD51BE42B96
7# 0x00007FD51BE42BE1
8# bar(int) at ../example/terminate_handler.cpp:18
9# foo(int) at ../example/terminate_handler.cpp:22
10# bar(int) at ../example/terminate_handler.cpp:14
11# foo(int) at ../example/terminate_handler.cpp:22
12# run_3(char const**) at ../example/terminate_handler.cpp:152
13# main at ../example/terminate_handler.cpp:207
14# 0x00007FD51B81EF45
15# 0x0000000000402999
```
[endsect]
]
[endsect]
[section Configuration and Build]
By default Boost.Stacktrace is a header-only library, but you may change that and use the following macros to improve build times or to be able to tune library without recompiling your project:
[section Usage from CMake]
CMake library `Boost::stacktrace` provides the best available implementation:
```
target_link_libraries(${PROJECT}
PUBLIC
Boost::stacktrace
)
```
There are also CMake libraries for fine grained selection of implementation:
* `Boost::stacktrace_windbg`
* `Boost::stacktrace_windbg_cached`
* `Boost::stacktrace_backtrace`
* `Boost::stacktrace_addr2line`
* `Boost::stacktrace_basic`
* `Boost::stacktrace_noop`
Note that `Boost::stacktrace_from_exception` is not used by default, so add it explicitly if its functionality is required:
```
target_link_libraries(${PROJECT} # your project
PUBLIC
Boost::stacktrace
Boost::stacktrace_from_exception
)
```
[endsect]
[section CMake build notes]
When building the Boost.Stacktrace libraries using `CMake` the `BOOST_STACKTRACE_ENABLE_*` options control the build. For example:
* `cmake -DBOOST_STACKTRACE_ENABLE_NOOP=0 -DBOOST_STACKTRACE_ENABLE_BACKTRACE=1 -DBOOST_STACKTRACE_ENABLE_FROM_EXCEPTION=1` - do not build the `noop` implementation and force the builds of `backtrace` and `from_exception`.
* `cmake -DBOOST_STACKTRACE_ENABLE_NOOP=1 -DBOOST_STACKTRACE_ENABLE_WINDBG=1 -DBOOST_STACKTRACE_ENABLE_WINDBG_CACHED=0` - build the `noop` and `windbg` implementations and disable the build of `windbg_cached`.
If options are not provided they are auto-detected and the result of detection is printed and implicitly used during build.
[endsect]
[section B2 build notes]
When building the Boost.Stacktrace libraries using `b2` the `boost.stacktrace.*` options can be used to control the build. For example:
* `b2 boost.stacktrace.noop=off boost.stacktrace.backtrace=on boost.stacktrace.from_exception=on` - do not build the `noop` implementation and force the builds of `backtrace` and `from_exception`.
* `b2 boost.stacktrace.noop=on boost.stacktrace.windbg=on boost.stacktrace.windbg_cached=off` - build the `noop` and `windbg` implementations and disable the build of `windbg_cached`.
If options are not provided they are auto-detected and the result of detection is printed and implicitly used during build.
[endsect]
[section Header only options]
If CMake is not used then the Boost.Stacktrace is a header-only library by default. To change that (to improve build times or to be able to tune library without recompiling your project) use the following macros:
[table:linkmacro Link macros
[[Macro name] [Effect]]
[[*BOOST_STACKTRACE_LINK*] [Disable header-only build and require linking with shared or static library that contains the tracing implementation. If *BOOST_ALL_DYN_LINK* is defined, then link with shared library.]]
@@ -283,13 +368,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:
In header only mode library can 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, 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]]
[[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 `-fvisibility=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 `dbgeng.h` to show debug info, stores the implementation internals in a static variable protected with mutex. 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, 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[footnote If you are using Clang with libstdc++ you could get into troubles of including `<backtrace.h>`, because on some platforms Clang does not search for headers in the GCC's include paths and any attempt to add GCC's include path leads to linker errors. To explicitly specify a path to the `<backtrace.h>` header you could define the *BOOST_STACKTRACE_BACKTRACE_INCLUDE_FILE* to a full path to the header. For example on Ubuntu Xenial use the command line option *-DBOOST_STACKTRACE_BACKTRACE_INCLUDE_FILE=</usr/lib/gcc/x86_64-linux-gnu/5/include/backtrace.h>* while building with Clang. ], or built into your compiler.
[[*BOOST_STACKTRACE_USE_WINDBG_CACHED*] [*boost_stacktrace_windbg_cached*] [ Uses `dbgeng.h` to show debug info and caches implementation internals in TLS for better performance. Useful only for cases when traces are gathered very often. 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[footnote Some *libbacktrace* packages SEGFAULT if there's a concurrent work with the same `backtrace_state` instance. To avoid that issue the Boost.Stacktrace library uses `thread_local` states, unfortunately this may consume a lot of memory if you often create and destroy execution threads in your application. Define *BOOST_STACKTRACE_BACKTRACE_FORCE_STATIC* to force single instance, but make sure that [@https://github.com/boostorg/stacktrace/blob/develop/test/thread_safety_checking.cpp thread_safety_checking.cpp] works well in your setup. ]. *libbacktrace* is probably already installed in your system[footnote If you are using Clang with libstdc++ you can get into troubles of including `<backtrace.h>`, because on some platforms Clang does not search for headers in the GCC's include paths and any attempt to add GCC's include path leads to linker errors. To explicitly specify a path to the `<backtrace.h>` header you can define the *BOOST_STACKTRACE_BACKTRACE_INCLUDE_FILE* to a full path to the header. For example on Ubuntu Xenial use the command line option *-DBOOST_STACKTRACE_BACKTRACE_INCLUDE_FILE=</usr/lib/gcc/x86_64-linux-gnu/5/include/backtrace.h>* while building with Clang. ], or built into your compiler.
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]]
@@ -302,6 +387,8 @@ In header only mode library could be tuned by macro. If one of the link macro fr
* if you wish to disable backtracing and *BOOST_STACKTRACE_LINK* is defined, you just need link with *-lboost_stacktrace_noop*
* 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 and recompile it
[endsect]
[section MinGW and MinGW-w64 specific notes]
MinGW-w64 and MinGW (without -w64) users have to install libbacktrace for getting better stacktraces. Follow the instruction:
@@ -334,7 +421,33 @@ There are multiple ways to deal with that issue if you distribute PDB files alon
[endsect]
[section Acknowledgements]
[section Theoretical async signal safety]
In theory, walking the stack without decoding and demangling should be async signal safe.
In practice, it is not:
* Looks like a page fault while dumping the trace on a containerized/virtualized
Windows system has a chance to deadlock. Page fault can happen easily
as we have to write the dump either to memory or to a file.
* On POSIX systems a deadlock can happen if a signal is received when throwing
an exception [@https://github.com/boostorg/stacktrace/issues/131 #131].
Theoretically this can be worked around by bypassing the mutex locking
in C++-runtime at exception throw
([@https://github.com/userver-framework/userver/blob/4246909c99506d3ab34bd130a5154b4acc8e87de/core/src/engine/task/exception_hacks.cpp#L241-L244 sample implementation]
in the 🐙 userver framework), or by using a very modern runtime
(glibc-2.35+ with [@https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71744#c32 modern]
libgcc or [@https://reviews.llvm.org/D130668 modern] LLVM's libunwind).
* `-fomit-frame-pointer` like flags add additional complexity to the stack
walking implementation, which may also negatively affect the signal safety.
As a rule of thumb: do *not* capture stack traces in signal handlers unless you
are absolutely sure in your environment and inspected all of its source codes.
[endsect]
[section Acknowledgments]
In order of helping and advising:
@@ -342,6 +455,8 @@ In order of helping and advising:
* Great thanks to Nat Goodspeed for requesting [classref boost::stacktrace::frame] like class.
* Great thanks to Niall Douglas for making an initial review, helping with some platforms and giving great hints on library design.
* Great thanks to all the library reviewers.
* Great thanks to Andrei Nekrashevich for prototyping the idea of stacktraces
from arbitrary exception in `libsfe`.
[endsect]

View File

@@ -1,4 +1,4 @@
// Copyright Antony Polukhin, 2016-2021.
// Copyright Antony Polukhin, 2016-2025.
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at

View File

@@ -1,4 +1,4 @@
// Copyright Antony Polukhin, 2016-2021.
// Copyright Antony Polukhin, 2016-2025.
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at

View File

@@ -1,4 +1,4 @@
// Copyright Antony Polukhin, 2016-2021.
// Copyright Antony Polukhin, 2016-2025.
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
@@ -63,38 +63,17 @@ void my_terminate_handler() {
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
BOOST_CONSTEXPR_OR_CONST std::size_t shared_memory_size = 4096 * 8;
//[getting_started_terminate_handlers_shmem
#include <boost/stacktrace.hpp>
#include <boost/interprocess/shared_memory_object.hpp>
#include <boost/interprocess/mapped_region.hpp>
boost::interprocess::shared_memory_object g_shm; // inited at program start
boost::interprocess::mapped_region g_region; // inited at program start
void my_signal_handler2(int signum) {
::signal(signum, SIG_DFL);
void** f = static_cast<void**>(g_region.get_address());
*f = reinterpret_cast<void*>(1); // Setting flag that shared memory now constains stacktrace.
boost::stacktrace::safe_dump_to(f + 1, g_region.get_size() - sizeof(void*));
::raise(SIGABRT);
}
//]
#include <iostream> // std::cerr
#include <fstream> // std::ifstream
#include <boost/filesystem/path.hpp>
#include <boost/filesystem/operations.hpp>
#ifndef BOOST_WINDOWS
inline void copy_and_run(const char* exec_name, char param, bool not_null) {
std::cout << "Running with param " << param << std::endl;
boost::filesystem::path command = exec_name;
command = command.parent_path() / (command.stem().string() + param + command.extension().string());
boost::filesystem::copy_file(exec_name, command, boost::filesystem::copy_option::overwrite_if_exists);
boost::filesystem::copy_file(exec_name, command, boost::filesystem::copy_options::overwrite_existing);
boost::filesystem::path command_args = command;
command_args += ' ';
@@ -110,6 +89,7 @@ inline void copy_and_run(const char* exec_name, char param, bool not_null) {
std::exit(ret);
}
}
#endif
int run_0(const char* /*argv*/[]) {
//[getting_started_setup_terminate_handlers
@@ -160,67 +140,6 @@ int run_2(const char* argv[]) {
return 0;
}
int run_3(const char* /*argv*/[]) {
using namespace boost::interprocess;
{
shared_memory_object shm_obj(open_or_create, "shared_memory", read_write);
shm_obj.swap(g_shm);
}
g_shm.truncate(shared_memory_size);
{
mapped_region m(g_shm, read_write, 0, shared_memory_size);
m.swap(g_region);
}
void** f = static_cast<void**>(g_region.get_address());
*f = 0;
::signal(SIGSEGV, &my_signal_handler2);
::signal(SIGABRT, &my_signal_handler2);
foo(5);
return 31;
}
int run_4(const char* argv[]) {
using namespace boost::interprocess;
{
shared_memory_object shm_obj(open_only, "shared_memory", read_write);
shm_obj.swap(g_shm);
}
{
mapped_region m(g_shm, read_write, 0, shared_memory_size);
m.swap(g_region);
}
//[getting_started_on_program_restart_shmem
void** f = static_cast<void**>(g_region.get_address());
if (*f) { // Checking if memory constains stacktrace.
boost::stacktrace::stacktrace st
= boost::stacktrace::stacktrace::from_dump(f + 1, g_region.get_size() - sizeof(bool));
std::cout << "Previous run crashed and left trace in shared memory:\n" << st << std::endl;
*f = 0; /*<-*/
shared_memory_object::remove("shared_memory");
if (std::string(argv[0]).find("noop") == std::string::npos) {
if (!st) {
return 43;
}
} else {
if (st) {
return 44;
}
}
} else {
return 42; /*->*/
}
//]
return 0;
}
#include <sstream>
int test_inplace() {
@@ -335,10 +254,6 @@ 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);
// There are some issues with async-safety of shared memory writes on Windows.
copy_and_run(argv[0], '3', true);
copy_and_run(argv[0], '4', false);
#endif
return test_inplace();
@@ -347,9 +262,6 @@ int main(int argc, const char* argv[]) {
switch (argv[1][0]) {
case '0': return run_0(argv);
case '1': return run_1(argv);
case '2': return run_2(argv);
case '3': return run_3(argv);
case '4': return run_4(argv);
}
return 404;

View File

@@ -1,4 +1,4 @@
// Copyright Antony Polukhin, 2016-2021.
// Copyright Antony Polukhin, 2016-2025.
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at

View File

@@ -1,4 +1,4 @@
// Copyright Antony Polukhin, 2016-2021.
// Copyright Antony Polukhin, 2016-2025.
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at

View File

@@ -1,10 +1,10 @@
// Copyright Antony Polukhin, 2016-2021.
// Copyright Antony Polukhin, 2016-2025.
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#define BOOST_USER_CONFIG <libs/stacktrace/example/user_config.hpp>
#define BOOST_USER_CONFIG <example/user_config.hpp>
#include <boost/array.hpp>
#include <exception> // std::set_terminate, std::abort

View File

@@ -1,4 +1,4 @@
// Copyright Antony Polukhin, 2016-2021.
// Copyright Antony Polukhin, 2016-2025.
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at

View File

@@ -1,4 +1,4 @@
// Copyright Antony Polukhin, 2016-2021.
// Copyright Antony Polukhin, 2016-2025.
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
@@ -15,5 +15,6 @@
#include <boost/stacktrace/frame.hpp>
#include <boost/stacktrace/stacktrace.hpp>
#include <boost/stacktrace/safe_dump_to.hpp>
#include <boost/stacktrace/this_thread.hpp>
#endif // BOOST_STACKTRACE_HPP

View File

@@ -1,4 +1,4 @@
// Copyright Antony Polukhin, 2016-2021.
// Copyright Antony Polukhin, 2016-2025.
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
@@ -12,11 +12,13 @@
# pragma once
#endif
#include <boost/stacktrace/detail/addr_base.hpp>
#include <boost/stacktrace/detail/to_hex_array.hpp>
#include <boost/stacktrace/detail/to_dec_array.hpp>
#include <boost/stacktrace/detail/try_dec_convert.hpp>
#include <boost/core/demangle.hpp>
#include <cstdio>
#include <cstring>
#include <sys/types.h>
#include <sys/wait.h>
@@ -28,7 +30,7 @@ namespace boost { namespace stacktrace { namespace detail {
#if defined(BOOST_STACKTRACE_ADDR2LINE_LOCATION) && !defined(BOOST_NO_CXX11_CONSTEXPR)
constexpr bool is_abs_path(const char* path) BOOST_NOEXCEPT {
constexpr bool is_abs_path(const char* path) noexcept {
return *path != '\0' && (
*path == ':' || *path == '/' || is_abs_path(path + 1)
);
@@ -41,7 +43,7 @@ class addr2line_pipe {
::pid_t pid;
public:
explicit addr2line_pipe(const char *flag, const char* exec_path, const char* addr) BOOST_NOEXCEPT
explicit addr2line_pipe(const char *flag, const char* exec_path, const char* addr) noexcept
: p(0)
, pid(0)
{
@@ -97,11 +99,11 @@ public:
::close(pdes[1]);
}
operator ::FILE*() const BOOST_NOEXCEPT {
operator ::FILE*() const noexcept {
return p;
}
~addr2line_pipe() BOOST_NOEXCEPT {
~addr2line_pipe() noexcept {
if (p) {
::fclose(p);
int pstat = 0;
@@ -115,12 +117,14 @@ inline std::string addr2line(const char* flag, const void* addr) {
std::string res;
boost::stacktrace::detail::location_from_symbol loc(addr);
if (!loc.empty()) {
// For programs started through $PATH loc.name() is not absolute and
// addr2line will fail.
if (!loc.empty() && std::strchr(loc.name(), '/') != nullptr) {
res = loc.name();
} else {
res.resize(16);
int rlin_size = ::readlink("/proc/self/exe", &res[0], res.size() - 1);
while (rlin_size == static_cast<int>(res.size() - 1)) {
ssize_t rlin_size = ::readlink("/proc/self/exe", &res[0], res.size() - 1);
while (rlin_size == static_cast<ssize_t>(res.size() - 1)) {
res.resize(res.size() * 4);
rlin_size = ::readlink("/proc/self/exe", &res[0], res.size() - 1);
}
@@ -128,7 +132,7 @@ inline std::string addr2line(const char* flag, const void* addr) {
res.clear();
return res;
}
res.resize(rlin_size);
res.resize(static_cast<std::size_t>(rlin_size));
}
addr2line_pipe p(flag, res.c_str(), to_hex_array(addr).data());
@@ -155,6 +159,19 @@ inline std::string addr2line(const char* flag, const void* addr) {
return res;
}
inline std::string source_location(const void* addr, bool position_independent) {
uintptr_t addr_base = 0;
if (position_independent) {
addr_base = boost::stacktrace::detail::get_own_proc_addr_base(addr);
}
const void* offset = reinterpret_cast<void*>(reinterpret_cast<uintptr_t>(addr) - addr_base);
std::string source_line = boost::stacktrace::detail::addr2line("-Cpe", reinterpret_cast<const void*>(offset));
if (source_line.empty() || source_line[0] == '?') {
return "";
}
return source_line;
}
struct to_string_using_addr2line {
std::string res;
@@ -163,9 +180,20 @@ struct to_string_using_addr2line {
}
bool prepare_source_location(const void* addr) {
//return addr2line("-Cfipe", addr); // Does not seem to work in all cases
std::string source_line = boost::stacktrace::detail::addr2line("-Cpe", addr);
if (!source_line.empty() && source_line[0] != '?') {
// general idea in all addr2line uses:
// in each case:
// - try to resolve whole address as if it was a non-pie binary
// - if that didn't work, try to resolve just an offset from binary base address
// this is needed because:
// - in pie binaries just passing an address to addr2line won't work (it needs an offset in this case)
// - in non-pie binaries whole address is needed (offset won't work)
// - there is no easy way to test if binary is position independent (that I know of)
std::string source_line = boost::stacktrace::detail::source_location(addr, false);
if(source_line.empty()) {
source_line = boost::stacktrace::detail::source_location(addr, true);
}
if (!source_line.empty()) {
res += " at ";
res += source_line;
return true;
@@ -178,8 +206,13 @@ struct to_string_using_addr2line {
template <class Base> class to_string_impl_base;
typedef to_string_impl_base<to_string_using_addr2line> to_string_impl;
inline std::string name_impl(const void* addr) {
std::string res = boost::stacktrace::detail::addr2line("-fe", addr);
inline std::string name(const void* addr, bool position_independent) {
uintptr_t addr_base = 0;
if(position_independent){
addr_base = boost::stacktrace::detail::get_own_proc_addr_base(addr);
}
const void* offset = reinterpret_cast<void*>(reinterpret_cast<uintptr_t>(addr) - addr_base);
std::string res = boost::stacktrace::detail::addr2line("-fe", offset);
res = res.substr(0, res.find_last_of('\n'));
res = boost::core::demangle(res.c_str());
@@ -190,11 +223,23 @@ inline std::string name_impl(const void* addr) {
return res;
}
} // namespace detail
inline std::string name_impl(const void* addr) {
std::string res = boost::stacktrace::detail::name(addr, false);
if (res.empty()) {
res = boost::stacktrace::detail::name(addr, true);
}
std::string frame::source_file() const {
return res;
}
inline std::string source_file(const void* addr, bool position_independent) {
std::string res;
res = boost::stacktrace::detail::addr2line("-e", addr_);
uintptr_t addr_base = 0;
if(position_independent){
addr_base = boost::stacktrace::detail::get_own_proc_addr_base(addr);
}
const void* offset = reinterpret_cast<void*>(reinterpret_cast<uintptr_t>(addr) - addr_base);
res = boost::stacktrace::detail::addr2line("-e", offset);
res = res.substr(0, res.find_last_of(':'));
if (res == "??") {
res.clear();
@@ -203,10 +248,14 @@ std::string frame::source_file() const {
return res;
}
std::size_t frame::source_line() const {
inline std::size_t source_line(const void* addr, bool position_independent) {
std::size_t line_num = 0;
std::string res = boost::stacktrace::detail::addr2line("-e", addr_);
uintptr_t addr_base = 0;
if(position_independent){
addr_base = boost::stacktrace::detail::get_own_proc_addr_base(addr);
}
const void* offset = reinterpret_cast<void*>(reinterpret_cast<uintptr_t>(addr) - addr_base);
std::string res = boost::stacktrace::detail::addr2line("-e", offset);
const std::size_t last = res.find_last_of(':');
if (last == std::string::npos) {
return 0;
@@ -220,6 +269,27 @@ std::size_t frame::source_line() const {
return line_num;
}
} // namespace detail
std::string frame::source_file() const {
std::string res = boost::stacktrace::detail::source_file(addr_, false);
if (res.empty()) {
res = boost::stacktrace::detail::source_file(addr_, true);
}
return res;
}
std::size_t frame::source_line() const {
std::size_t line_num = boost::stacktrace::detail::source_line(addr_, false);
if (line_num == 0) {
line_num = boost::stacktrace::detail::source_line(addr_, true);
}
return line_num;
}
}} // namespace boost::stacktrace

View File

@@ -0,0 +1,89 @@
// Copyright Antony Polukhin, 2016-2025.
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#ifndef BOOST_STACKTRACE_DETAIL_ADDR_BASE_HPP
#define BOOST_STACKTRACE_DETAIL_ADDR_BASE_HPP
#include <boost/config.hpp>
#ifdef BOOST_HAS_PRAGMA_ONCE
# pragma once
#endif
#include <fstream>
#include <sstream>
#include <cstdint>
#include <cstdlib>
namespace boost { namespace stacktrace { namespace detail {
struct mapping_entry_t {
uintptr_t start = 0;
uintptr_t end = 0;
uintptr_t offset_from_base = 0;
inline bool contains_addr(const void* addr) const {
uintptr_t addr_uint = reinterpret_cast<uintptr_t>(addr);
return addr_uint >= start && addr_uint < end;
}
};
inline uintptr_t hex_str_to_int(const std::string& str) {
uintptr_t out;
std::stringstream ss;
ss << std::hex << str;
ss >> out;
if(ss.eof() && !ss.fail()) { // whole stream read, with no errors
return out;
} else {
throw std::invalid_argument(std::string("can't convert '") + str + "' to hex");
}
}
// parse line from /proc/<id>/maps
// format:
// 7fb60d1ea000-7fb60d20c000 r--p 00000000 103:02 120327460 /usr/lib/libc.so.6
// only parts 0 and 2 are interesting, these are:
// 0. mapping address range
// 2. mapping offset from base
inline mapping_entry_t parse_proc_maps_line(const std::string& line) {
std::string mapping_range_str, permissions_str, offset_from_base_str;
std::istringstream line_stream(line);
if(!std::getline(line_stream, mapping_range_str, ' ') ||
!std::getline(line_stream, permissions_str, ' ') ||
!std::getline(line_stream, offset_from_base_str, ' ')) {
return mapping_entry_t{};
}
std::string mapping_start_str, mapping_end_str;
std::istringstream mapping_range_stream(mapping_range_str);
if(!std::getline(mapping_range_stream, mapping_start_str, '-') ||
!std::getline(mapping_range_stream, mapping_end_str)) {
return mapping_entry_t{};
}
mapping_entry_t mapping{};
try {
mapping.start = hex_str_to_int(mapping_start_str);
mapping.end = hex_str_to_int(mapping_end_str);
mapping.offset_from_base = hex_str_to_int(offset_from_base_str);
return mapping;
} catch(std::invalid_argument& e) {
return mapping_entry_t{};
}
}
inline uintptr_t get_own_proc_addr_base(const void* addr) {
std::ifstream maps_file("/proc/self/maps");
for (std::string line; std::getline(maps_file, line); ) {
const mapping_entry_t mapping = parse_proc_maps_line(line);
if (mapping.contains_addr(addr)) {
return mapping.start - mapping.offset_from_base;
}
}
return 0;
}
}}} // namespace boost::stacktrace::detail
#endif // BOOST_STACKTRACE_DETAIL_ADDR_BASE_HPP

View File

@@ -0,0 +1,72 @@
// Copyright Antony Polukhin, 2016-2025.
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#ifndef BOOST_STACKTRACE_DETAIL_ADDR_BASE_MSVC_HPP
#define BOOST_STACKTRACE_DETAIL_ADDR_BASE_MSVC_HPP
#include <boost/config.hpp>
#ifdef BOOST_HAS_PRAGMA_ONCE
# pragma once
#endif
#include <cstdio>
#include <memory>
#ifdef WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <psapi.h>
#else
// Prevent inclusion of extra Windows SDK headers which can cause conflict
// with other code using Windows SDK
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <psapi.h>
#undef WIN32_LEAN_AND_MEAN
#endif
namespace boost { namespace stacktrace { namespace detail {
inline std::uintptr_t get_own_proc_addr_base(const void* addr) {
// Try to avoid allocating memory for the modules array if possible.
// The stack buffer should be large enough for most processes.
HMODULE modules_stack[1024];
std::unique_ptr<HMODULE[]> modules_allocated;
HMODULE* modules = modules_stack;
DWORD needed_bytes = 0;
std::uintptr_t addr_base = 0;
HANDLE process_handle = GetCurrentProcess();
auto enum_process_is_ok = EnumProcessModules(process_handle, modules, sizeof(modules), &needed_bytes);
// Check if the error is because the buffer is too small.
if (!enum_process_is_ok && GetLastError() == ERROR_INSUFFICIENT_BUFFER) {
modules_allocated.reset(new HMODULE[needed_bytes / sizeof(HMODULE)]);
modules = modules_allocated.get();
enum_process_is_ok = EnumProcessModules(process_handle, modules, needed_bytes, &needed_bytes);
}
if (enum_process_is_ok) {
for (std::size_t i = 0; i < (needed_bytes / sizeof(HMODULE)); ++i) {
MODULEINFO module_info;
// Get the module name
if (GetModuleInformation(process_handle, modules[i], &module_info, sizeof(module_info))
&& module_info.lpBaseOfDll <= addr && addr < LPBYTE(module_info.lpBaseOfDll) + module_info.SizeOfImage) {
// Module contains the address
addr_base = reinterpret_cast<std::uintptr_t>(module_info.lpBaseOfDll);
break;
}
}
}
CloseHandle(process_handle);
return addr_base;
}
}}} // namespace boost::stacktrace::detail
#endif // BOOST_STACKTRACE_DETAIL_ADDR_BASE_MSVC_HPP

View File

@@ -1,4 +1,4 @@
// Copyright Antony Polukhin, 2016-2021.
// Copyright Antony Polukhin, 2016-2025.
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
@@ -18,7 +18,7 @@
namespace boost { namespace stacktrace { namespace detail {
std::size_t this_thread_frames::collect(native_frame_ptr_t* out_frames, std::size_t max_frames_count, std::size_t skip) BOOST_NOEXCEPT {
std::size_t this_thread_frames::collect(native_frame_ptr_t* out_frames, std::size_t max_frames_count, std::size_t skip) noexcept {
return boost::winapi::RtlCaptureStackBackTrace(
static_cast<boost::winapi::ULONG_>(skip),
static_cast<boost::winapi::ULONG_>(max_frames_count),

View File

@@ -1,4 +1,4 @@
// Copyright Antony Polukhin, 2016-2021.
// Copyright Antony Polukhin, 2016-2025.
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
@@ -16,7 +16,7 @@
namespace boost { namespace stacktrace { namespace detail {
std::size_t this_thread_frames::collect(native_frame_ptr_t* /*out_frames*/, std::size_t /*max_frames_count*/, std::size_t /*skip*/) BOOST_NOEXCEPT {
std::size_t this_thread_frames::collect(native_frame_ptr_t* /*out_frames*/, std::size_t /*max_frames_count*/, std::size_t /*skip*/) noexcept {
return 0;
}

View File

@@ -1,4 +1,4 @@
// Copyright Antony Polukhin, 2016-2021.
// Copyright Antony Polukhin, 2016-2025.
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
@@ -63,7 +63,7 @@ inline _Unwind_Reason_Code unwind_callback(::_Unwind_Context* context, void* arg
}
#endif //!defined(BOOST_STACKTRACE_USE_LIBC_BACKTRACE_FUNCTION)
std::size_t this_thread_frames::collect(native_frame_ptr_t* out_frames, std::size_t max_frames_count, std::size_t skip) BOOST_NOEXCEPT {
std::size_t this_thread_frames::collect(native_frame_ptr_t* out_frames, std::size_t max_frames_count, std::size_t skip) noexcept {
std::size_t frames_count = 0;
if (!max_frames_count) {
return frames_count;
@@ -88,7 +88,7 @@ std::size_t this_thread_frames::collect(native_frame_ptr_t* out_frames, std::siz
#else
boost::stacktrace::detail::unwind_state state = { skip, out_frames, out_frames + max_frames_count };
::_Unwind_Backtrace(&boost::stacktrace::detail::unwind_callback, &state);
frames_count = state.current - out_frames;
frames_count = static_cast<std::size_t>(state.current - out_frames);
#endif //defined(BOOST_STACKTRACE_USE_LIBC_BACKTRACE_FUNCTION)
if (frames_count && out_frames[frames_count - 1] == 0) {

View File

@@ -1,4 +1,4 @@
// Copyright Antony Polukhin, 2016-2021.
// Copyright Antony Polukhin, 2016-2025.
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
@@ -15,8 +15,6 @@
#include <iosfwd>
#include <string>
#include <boost/core/explicit_operator_bool.hpp>
#include <boost/stacktrace/safe_dump_to.hpp> // boost::stacktrace::detail::native_frame_ptr_t
#include <boost/stacktrace/detail/void_ptr_cast.hpp>
@@ -47,7 +45,7 @@ public:
///
/// @b Async-Handler-Safety: Safe.
/// @throws Nothing.
BOOST_CONSTEXPR frame() BOOST_NOEXCEPT
constexpr frame() noexcept
: addr_(0)
{}
@@ -75,7 +73,7 @@ public:
///
/// @b Async-Handler-Safety: Safe.
/// @throws Nothing.
BOOST_CONSTEXPR explicit frame(native_frame_ptr_t addr) BOOST_NOEXCEPT
constexpr explicit frame(native_frame_ptr_t addr) noexcept
: addr_(addr)
{}
@@ -86,7 +84,7 @@ public:
/// @b Async-Handler-Safety: Safe.
/// @throws Nothing.
template <class T>
explicit frame(T* function_addr) BOOST_NOEXCEPT
explicit frame(T* function_addr) noexcept
: addr_(boost::stacktrace::detail::void_ptr_cast<native_frame_ptr_t>(function_addr))
{}
@@ -104,7 +102,7 @@ public:
///
/// @b Async-Handler-Safety: Safe.
/// @throws Nothing.
BOOST_CONSTEXPR native_frame_ptr_t address() const BOOST_NOEXCEPT {
constexpr native_frame_ptr_t address() const noexcept {
return addr_;
}
@@ -131,7 +129,7 @@ public:
/// @b Complexity: O(1)
///
/// @b Async-Handler-Safety: Safe.
BOOST_EXPLICIT_OPERATOR_BOOL()
constexpr explicit operator bool () const noexcept { return !empty(); }
/// @brief Checks that frame references NULL address.
/// @returns `true` if `this->address() == 0`
@@ -139,11 +137,7 @@ public:
/// @b Complexity: O(1)
///
/// @b Async-Handler-Safety: Safe.
BOOST_CONSTEXPR bool empty() const BOOST_NOEXCEPT { return !address(); }
/// @cond
BOOST_CONSTEXPR bool operator!() const BOOST_NOEXCEPT { return !address(); }
/// @endcond
constexpr bool empty() const noexcept { return !address(); }
};

View File

@@ -1,4 +1,4 @@
// Copyright Antony Polukhin, 2016-2021.
// Copyright Antony Polukhin, 2016-2025.
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
@@ -18,19 +18,39 @@
#include <boost/core/noncopyable.hpp>
#include <boost/stacktrace/detail/to_dec_array.hpp>
#include <boost/stacktrace/detail/to_hex_array.hpp>
#ifndef BOOST_STACKTRACE_DISABLE_OFFSET_ADDR_BASE
#include <boost/stacktrace/detail/addr_base_msvc.hpp>
#endif
#ifdef WIN32_LEAN_AND_MEAN
#include <windows.h>
#else
// Prevent inclusion of extra Windows SDK headers which can cause conflict
// with other code using Windows SDK
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#undef WIN32_LEAN_AND_MEAN
#endif
#include "dbgeng.h"
#ifdef BOOST_MSVC
#include <mutex>
#if defined(__clang__) || defined(BOOST_MSVC)
# pragma comment(lib, "ole32.lib")
# pragma comment(lib, "Dbgeng.lib")
#endif
#ifdef __CRT_UUID_DECL // for __MINGW32__
#if !defined(__MINGW32__) || \
(!defined(__clang__) && __GNUC__ < 12) || \
(defined(__clang__) && __clang_major__ < 16)
__CRT_UUID_DECL(IDebugClient,0x27fe5639,0x8407,0x4f47,0x83,0x64,0xee,0x11,0x8f,0xb0,0x8a,0xc8)
__CRT_UUID_DECL(IDebugControl,0x5182e668,0x105e,0x416e,0xad,0x92,0x24,0xef,0x80,0x04,0x24,0xba)
__CRT_UUID_DECL(IDebugSymbols,0x8c31e98c,0x983a,0x48a5,0x90,0x16,0x6f,0xe5,0xd6,0x67,0xa9,0x50)
#endif
#elif defined(DEFINE_GUID) && !defined(BOOST_MSVC)
DEFINE_GUID(IID_IDebugClient,0x27fe5639,0x8407,0x4f47,0x83,0x64,0xee,0x11,0x8f,0xb0,0x8a,0xc8);
DEFINE_GUID(IID_IDebugControl,0x5182e668,0x105e,0x416e,0xad,0x92,0x24,0xef,0x80,0x04,0x24,0xba);
@@ -44,53 +64,28 @@
namespace boost { namespace stacktrace { namespace detail {
class com_global_initer: boost::noncopyable {
bool ok_;
public:
com_global_initer() BOOST_NOEXCEPT
: ok_(false)
{
// COINIT_MULTITHREADED means that we must serialize access to the objects manually.
// This is the fastest way to work. If user calls CoInitializeEx before us - we
// can end up with other mode (which is OK for us).
//
// If we call CoInitializeEx befire user - user may end up with different mode, which is a problem.
// So we need to call that initialization function as late as possible.
const DWORD res = ::CoInitializeEx(0, COINIT_MULTITHREADED);
ok_ = (res == S_OK || res == S_FALSE);
}
~com_global_initer() BOOST_NOEXCEPT {
if (ok_) {
::CoUninitialize();
}
}
};
template <class T>
class com_holder: boost::noncopyable {
T* holder_;
public:
com_holder(const com_global_initer&) BOOST_NOEXCEPT
com_holder() noexcept
: holder_(0)
{}
T* operator->() const BOOST_NOEXCEPT {
T* operator->() const noexcept {
return holder_;
}
void** to_void_ptr_ptr() BOOST_NOEXCEPT {
void** to_void_ptr_ptr() noexcept {
return reinterpret_cast<void**>(&holder_);
}
bool is_inited() const BOOST_NOEXCEPT {
bool is_inited() const noexcept {
return !!holder_;
}
~com_holder() BOOST_NOEXCEPT {
~com_holder() noexcept {
if (holder_) {
holder_->Release();
}
@@ -126,13 +121,13 @@ inline void trim_right_zeroes(std::string& s) {
}
class debugging_symbols: boost::noncopyable {
static void try_init_com(com_holder< ::IDebugSymbols>& idebug, const com_global_initer& com) BOOST_NOEXCEPT {
com_holder< ::IDebugClient> iclient(com);
static void try_init_com(com_holder< ::IDebugSymbols>& idebug) noexcept {
com_holder< ::IDebugClient> iclient;
if (S_OK != ::DebugCreate(__uuidof(IDebugClient), iclient.to_void_ptr_ptr())) {
return;
}
com_holder< ::IDebugControl> icontrol(com);
com_holder< ::IDebugControl> icontrol;
const bool res0 = (S_OK == iclient->QueryInterface(
__uuidof(IDebugControl),
icontrol.to_void_ptr_ptr()
@@ -154,36 +149,48 @@ class debugging_symbols: boost::noncopyable {
return;
}
// No cheking: QueryInterface sets the output parameter to NULL in case of error.
// No checking: QueryInterface sets the output parameter to NULL in case of error.
iclient->QueryInterface(__uuidof(IDebugSymbols), idebug.to_void_ptr_ptr());
}
#ifndef BOOST_STACKTRACE_USE_WINDBG_CACHED
boost::stacktrace::detail::com_global_initer com_;
com_holder< ::IDebugSymbols> idebug_;
public:
debugging_symbols() BOOST_NOEXCEPT
: com_()
, idebug_(com_)
{
try_init_com(idebug_, com_);
static std::mutex& get_mutex_inst() noexcept {
static std::mutex m;
return m;
}
static com_holder< ::IDebugSymbols>& get_static_debug_inst() noexcept {
// [class.mfct]: A static local variable or local type in a member function always refers to the same entity, whether
// or not the member function is inline.
static com_holder< ::IDebugSymbols> idebug;
if (!idebug.is_inited()) {
try_init_com(idebug);
}
return idebug;
}
std::lock_guard<std::mutex> guard_;
com_holder< ::IDebugSymbols>& idebug_;
public:
debugging_symbols() noexcept
: guard_( get_mutex_inst() )
, idebug_( get_static_debug_inst() )
{}
#else
#ifdef BOOST_NO_CXX11_THREAD_LOCAL
# error Your compiler does not support C++11 thread_local storage. It`s impossible to build with BOOST_STACKTRACE_USE_WINDBG_CACHED.
#endif
static com_holder< ::IDebugSymbols>& get_thread_local_debug_inst() BOOST_NOEXCEPT {
static com_holder< ::IDebugSymbols>& get_thread_local_debug_inst() noexcept {
// [class.mfct]: A static local variable or local type in a member function always refers to the same entity, whether
// or not the member function is inline.
static thread_local boost::stacktrace::detail::com_global_initer com;
static thread_local com_holder< ::IDebugSymbols> idebug(com);
static thread_local com_holder< ::IDebugSymbols> idebug;
if (!idebug.is_inited()) {
try_init_com(idebug, com);
try_init_com(idebug);
}
return idebug;
@@ -191,13 +198,13 @@ public:
com_holder< ::IDebugSymbols>& idebug_;
public:
debugging_symbols() BOOST_NOEXCEPT
debugging_symbols() noexcept
: idebug_( get_thread_local_debug_inst() )
{}
#endif // #ifndef BOOST_STACKTRACE_USE_WINDBG_CACHED
bool is_inited() const BOOST_NOEXCEPT {
bool is_inited() const noexcept {
return idebug_.is_inited();
}
@@ -228,9 +235,12 @@ public:
&size,
0
));
trim_right_zeroes(result);
// According to https://docs.microsoft.com/en-us/windows-hardware/drivers/ddi/dbgeng/nf-dbgeng-idebugsymbols-getnamebyoffset
// "This size includes the space for the '\0' terminating character."
result.resize(size - 1);
} else if (res) {
result = name;
result.assign(name, size - 1);
}
if (!res) {
@@ -241,6 +251,57 @@ public:
const std::size_t delimiter = result.find_first_of('!');
if (module_name) {
*module_name = result.substr(0, delimiter);
if (!module_name->empty()) {
ULONG64 base = 0;
res = (S_OK == idebug_->GetModuleByOffset(
offset,
0,
nullptr,
&base
));
if (res) {
name[0] = '\0';
size = 0;
res = (S_OK == idebug_->GetModuleNames(
DEBUG_ANY_ID,
base,
name,
sizeof(name),
&size,
nullptr,
0,
nullptr,
nullptr,
0,
nullptr
));
}
if (!res && size != 0)
{
std::string module_path(size, char());
res = (S_OK == idebug_->GetModuleNames(
DEBUG_ANY_ID,
base,
&module_path[0],
static_cast<ULONG>(module_path.size()),
&size,
nullptr,
0,
nullptr,
nullptr,
0,
nullptr
));
if (res && size > 1) {
module_name->assign(module_path, size - 1);
}
}
else if (res && size > 1) {
module_name->assign(name, size - 1);
}
}
}
if (delimiter == std::string::npos) {
@@ -256,7 +317,7 @@ public:
return result;
}
std::size_t get_line_impl(const void* addr) const BOOST_NOEXCEPT {
std::size_t get_line_impl(const void* addr) const noexcept {
ULONG result = 0;
if (!is_inited()) {
return result;
@@ -334,7 +395,13 @@ public:
if (!name.empty()) {
res += name;
} else {
#ifdef BOOST_STACKTRACE_DISABLE_OFFSET_ADDR_BASE
res += to_hex_array(addr).data();
#else
// Get own base address
const uintptr_t base_addr = get_own_proc_addr_base(addr);
res += to_hex_array(reinterpret_cast<uintptr_t>(addr) - base_addr).data();
#endif
}
std::pair<std::string, std::size_t> source_line = this->get_source_file_line_impl(addr);

View File

@@ -1,4 +1,4 @@
// Copyright Antony Polukhin, 2016-2021.
// Copyright Antony Polukhin, 2016-2025.
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at

View File

@@ -1,4 +1,4 @@
// Copyright Antony Polukhin, 2016-2021.
// Copyright Antony Polukhin, 2016-2025.
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
@@ -17,6 +17,7 @@
#include <boost/stacktrace/detail/to_hex_array.hpp>
#include <boost/stacktrace/detail/location_from_symbol.hpp>
#include <boost/stacktrace/detail/to_dec_array.hpp>
#include <boost/stacktrace/detail/addr_base.hpp>
#include <boost/core/demangle.hpp>
#include <cstdio>
@@ -40,7 +41,12 @@ public:
if (!Base::res.empty()) {
Base::res = boost::core::demangle(Base::res.c_str());
} else {
#ifdef BOOST_STACKTRACE_DISABLE_OFFSET_ADDR_BASE
Base::res = to_hex_array(addr).data();
#else
const auto addr_base = boost::stacktrace::detail::get_own_proc_addr_base(addr);
Base::res = to_hex_array(reinterpret_cast<uintptr_t>(addr) - addr_base).data();
#endif
}
if (Base::prepare_source_location(addr)) {
@@ -90,8 +96,8 @@ std::string frame::name() const {
}
#if !defined(BOOST_WINDOWS) && !defined(__CYGWIN__)
::Dl_info dli;
const bool dl_ok = !!::dladdr(const_cast<void*>(addr_), &dli); // `dladdr` on Solaris accepts nonconst addresses
boost::stacktrace::detail::Dl_info dli;
const bool dl_ok = !!boost::stacktrace::detail::dladdr(addr_, dli);
if (dl_ok && dli.dli_sname) {
return boost::core::demangle(dli.dli_sname);
}

View File

@@ -1,4 +1,4 @@
// Copyright Antony Polukhin, 2016-2021.
// Copyright Antony Polukhin, 2016-2025.
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
@@ -52,11 +52,11 @@ inline int libbacktrace_full_callback(void *data, uintptr_t /*pc*/, const char *
if (d.function && function) {
*d.function = function;
}
d.line = lineno;
d.line = static_cast<std::size_t>(lineno);
return 0;
}
inline void libbacktrace_error_callback(void* /*data*/, const char* /*msg*/, int /*errnum*/) BOOST_NOEXCEPT {
inline void libbacktrace_error_callback(void* /*data*/, const char* /*msg*/, int /*errnum*/) noexcept {
// Do nothing, just return.
}
@@ -68,7 +68,7 @@ inline void libbacktrace_error_callback(void* /*data*/, const char* /*msg*/, int
//
// Currently `backtrace_create_state` can not detect file name on Windows https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82543
// That's why we provide a `prog_location` here.
BOOST_SYMBOL_VISIBLE inline ::backtrace_state* construct_state(const program_location& prog_location) BOOST_NOEXCEPT {
BOOST_SYMBOL_VISIBLE inline ::backtrace_state* construct_state(const program_location& prog_location) noexcept {
// [dcl.inline]: A static local variable in an inline function with external linkage always refers to the same object.
// TODO: The most obvious solution:
@@ -82,31 +82,35 @@ BOOST_SYMBOL_VISIBLE inline ::backtrace_state* construct_state(const program_loc
//
//
// Unfortunately, that solution segfaults when `construct_state()` function is in .so file
// and multiple threads concurrently work with state.
// and multiple threads concurrently work with state. I failed to localize the root cause:
// https://gcc.gnu.org/bugzilla//show_bug.cgi?id=87653
#define BOOST_STACKTRACE_DETAIL_IS_MT 1
#ifndef BOOST_HAS_THREADS
static
#if !defined(BOOST_HAS_THREADS)
# define BOOST_STACKTRACE_DETAIL_STORAGE static
# undef BOOST_STACKTRACE_DETAIL_IS_MT
# define BOOST_STACKTRACE_DETAIL_IS_MT 0
#elif defined(BOOST_STACKTRACE_BACKTRACE_FORCE_STATIC)
# define BOOST_STACKTRACE_DETAIL_STORAGE static
#elif !defined(BOOST_NO_CXX11_THREAD_LOCAL)
# define BOOST_STACKTRACE_DETAIL_STORAGE thread_local
#elif defined(__GNUC__) && !defined(__clang__)
# define BOOST_STACKTRACE_DETAIL_STORAGE static __thread
#else
// Result of `construct_state()` invocation is not stored by the callers, so `thread_local`
// gives a single `state` per thread and that state is not shared between threads in any way.
# ifndef BOOST_NO_CXX11_THREAD_LOCAL
thread_local
# elif defined(__GNUC__) && !defined(__clang__)
static __thread
# else
/* just a local variable */
# endif
# define BOOST_STACKTRACE_DETAIL_STORAGE /* just a local variable */
#endif
::backtrace_state* state = ::backtrace_create_state(
BOOST_STACKTRACE_DETAIL_STORAGE ::backtrace_state* state = ::backtrace_create_state(
prog_location.name(),
0,
BOOST_STACKTRACE_DETAIL_IS_MT,
boost::stacktrace::detail::libbacktrace_error_callback,
0
);
#undef BOOST_STACKTRACE_DETAIL_IS_MT
#undef BOOST_STACKTRACE_DETAIL_STORAGE
return state;
}
@@ -151,7 +155,7 @@ struct to_string_using_backtrace {
return true;
}
to_string_using_backtrace() BOOST_NOEXCEPT {
to_string_using_backtrace() noexcept {
state = boost::stacktrace::detail::construct_state(prog_location);
}
};

View File

@@ -1,4 +1,4 @@
// Copyright Antony Polukhin, 2016-2021.
// Copyright Antony Polukhin, 2016-2025.
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
@@ -18,33 +18,126 @@
# include <boost/winapi/dll.hpp>
#endif
#ifdef _AIX
/* AIX doesn't provide dladdr syscall.
This provides a minimal implementation of dladdr which retrieves
only files information.
TODO: Implement the symbol name. */
#include <sys/ldr.h>
#include <sys/debug.h>
#include <cstring>
#include <string>
#include <vector>
namespace boost { namespace stacktrace { namespace detail {
struct Dl_info {
std::string fname_storage{};
const char *dli_fname = nullptr;
const char *dli_sname = nullptr;
};
int dladdr(const void* address_raw, Dl_info* info) noexcept {
static constexpr std::size_t dl_buff_size = 0x1000;
try {
std::vector<struct ld_info> pld_info_storage;
pld_info_storage.resize(
(dl_buff_size + sizeof(struct ld_info) - 1) / sizeof(struct ld_info)
);
if (loadquery(L_GETINFO, pld_info_storage.data(), dl_buff_size) == -1) {
return 0;
}
const auto* pld_info = pld_info_storage.data();
const char* const address = static_cast<const char*>(address_raw);
while (true) {
const auto* const dataorg = static_cast<char*>(pld_info->ldinfo_dataorg);
const auto* const textorg = static_cast<char*>(pld_info->ldinfo_textorg);
if ((address >= dataorg && address < dataorg + pld_info->ldinfo_datasize )
|| (address >= textorg && address < textorg + pld_info->ldinfo_textsize )) {
/* ldinfo_filename is the null-terminated path name followed
by null-terminated member name.
If the file is not an archive, then member name is null. */
const auto size_filename = std::strlen(pld_info->ldinfo_filename);
const auto size_member = std::strlen(pld_info->ldinfo_filename + size_filename + 1);
/* If member is not null, '(' and ')' must be added to create a
fname looking like "filename(membername)". */
info->fname_storage.reserve(size_filename + (size_member ? size_member + 3 : 1));
info->fname_storage = pld_info->ldinfo_filename;
if (size_member) {
info->fname_storage += "(";
info->fname_storage += pld_info->ldinfo_filename + size_filename + 1;
info->fname_storage += ")";
}
info->dli_fname = info->fname_storage.c_str();
return 1;
}
if (!pld_info->ldinfo_next) {
break;
}
pld_info = reinterpret_cast<const struct ld_info *>(
reinterpret_cast<const char*>(pld_info) + pld_info->ldinfo_next
);
};
} catch (...) {
// ignore
}
return 0;
}
}}} // namespace boost::stacktrace::detail
#elif !defined(BOOST_WINDOWS) && !defined(__CYGWIN__)
namespace boost { namespace stacktrace { namespace detail {
using Dl_info = ::Dl_info;
inline int dladdr(const void* addr, Dl_info& dli) noexcept {
// `dladdr` on Solaris accepts nonconst addresses
return ::dladdr(const_cast<void*>(addr), &dli);
}
}}} // namespace boost::stacktrace::detail
#endif
namespace boost { namespace stacktrace { namespace detail {
#if !defined(BOOST_WINDOWS) && !defined(__CYGWIN__)
class location_from_symbol {
::Dl_info dli_;
boost::stacktrace::detail::Dl_info dli_;
public:
explicit location_from_symbol(const void* addr) BOOST_NOEXCEPT
explicit location_from_symbol(const void* addr) noexcept
: dli_()
{
if (!::dladdr(const_cast<void*>(addr), &dli_)) { // `dladdr` on Solaris accepts nonconst addresses
if (!boost::stacktrace::detail::dladdr(addr, dli_)) {
dli_.dli_fname = 0;
}
}
bool empty() const BOOST_NOEXCEPT {
bool empty() const noexcept {
return !dli_.dli_fname;
}
const char* name() const BOOST_NOEXCEPT {
const char* name() const noexcept {
return dli_.dli_fname;
}
};
class program_location {
public:
const char* name() const BOOST_NOEXCEPT {
const char* name() const noexcept {
return 0;
}
};
@@ -56,7 +149,7 @@ class location_from_symbol {
char file_name_[DEFAULT_PATH_SIZE_];
public:
explicit location_from_symbol(const void* addr) BOOST_NOEXCEPT {
explicit location_from_symbol(const void* addr) noexcept {
file_name_[0] = '\0';
boost::winapi::MEMORY_BASIC_INFORMATION_ mbi;
@@ -71,11 +164,11 @@ public:
}
}
bool empty() const BOOST_NOEXCEPT {
bool empty() const noexcept {
return file_name_[0] == '\0';
}
const char* name() const BOOST_NOEXCEPT {
const char* name() const noexcept {
return file_name_;
}
};
@@ -85,7 +178,7 @@ class program_location {
char file_name_[DEFAULT_PATH_SIZE_];
public:
program_location() BOOST_NOEXCEPT {
program_location() noexcept {
file_name_[0] = '\0';
const boost::winapi::HMODULE_ handle = 0;
@@ -94,7 +187,7 @@ public:
}
}
const char* name() const BOOST_NOEXCEPT {
const char* name() const noexcept {
return file_name_[0] ? file_name_ : 0;
}
};

View File

@@ -1,4 +1,4 @@
// Copyright Antony Polukhin, 2016-2021.
// Copyright Antony Polukhin, 2016-2025.
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at

View File

@@ -1,4 +1,4 @@
// Copyright Antony Polukhin, 2016-2021.
// Copyright Antony Polukhin, 2016-2025.
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
@@ -11,7 +11,11 @@
# define BOOST_STACKTRACE_LINK
#endif
#if defined(BOOST_STACKTRACE_LINK) && !defined(BOOST_STACKTRACE_DYN_LINK) && defined(BOOST_ALL_DYN_LINK)
#if !defined(BOOST_STACKTRACE_LINK) && defined(BOOST_STACKTRACE_STATIC_LINK)
# define BOOST_STACKTRACE_LINK
#endif
#if defined(BOOST_STACKTRACE_LINK) && !defined(BOOST_STACKTRACE_DYN_LINK) && !defined(BOOST_STACKTRACE_STATIC_LINK) && defined(BOOST_ALL_DYN_LINK)
# define BOOST_STACKTRACE_DYN_LINK
#endif

View File

@@ -1,4 +1,4 @@
// Copyright Antony Polukhin, 2016-2021.
// Copyright Antony Polukhin, 2016-2025.
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
@@ -18,17 +18,17 @@ namespace boost { namespace stacktrace { namespace detail {
#if defined(BOOST_WINDOWS)
std::size_t dump(void* /*fd*/, const native_frame_ptr_t* /*frames*/, std::size_t /*frames_count*/) BOOST_NOEXCEPT {
std::size_t dump(void* /*fd*/, const native_frame_ptr_t* /*frames*/, std::size_t /*frames_count*/) noexcept {
return 0;
}
#else
std::size_t dump(int /*fd*/, const native_frame_ptr_t* /*frames*/, std::size_t /*frames_count*/) BOOST_NOEXCEPT {
std::size_t dump(int /*fd*/, const native_frame_ptr_t* /*frames*/, std::size_t /*frames_count*/) noexcept {
return 0;
}
#endif
std::size_t dump(const char* /*file*/, const native_frame_ptr_t* /*frames*/, std::size_t /*frames_count*/) BOOST_NOEXCEPT {
std::size_t dump(const char* /*file*/, const native_frame_ptr_t* /*frames*/, std::size_t /*frames_count*/) noexcept {
return 0;
}

View File

@@ -1,4 +1,4 @@
// Copyright Antony Polukhin, 2016-2021.
// Copyright Antony Polukhin, 2016-2025.
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
@@ -21,7 +21,7 @@
namespace boost { namespace stacktrace { namespace detail {
std::size_t dump(int fd, const native_frame_ptr_t* frames, std::size_t frames_count) BOOST_NOEXCEPT {
std::size_t dump(int fd, const native_frame_ptr_t* frames, std::size_t frames_count) noexcept {
// We do not retry, because this function must be typically called from signal handler so it's:
// * to scary to continue in case of EINTR
// * EAGAIN or EWOULDBLOCK may occur only in case of O_NONBLOCK is set for fd,
@@ -33,7 +33,7 @@ std::size_t dump(int fd, const native_frame_ptr_t* frames, std::size_t frames_co
return frames_count;
}
std::size_t dump(const char* file, const native_frame_ptr_t* frames, std::size_t frames_count) BOOST_NOEXCEPT {
std::size_t dump(const char* file, const native_frame_ptr_t* frames, std::size_t frames_count) noexcept {
const int fd = ::open(
file,
O_CREAT | O_WRONLY | O_TRUNC,

View File

@@ -1,4 +1,4 @@
// Copyright Antony Polukhin, 2016-2021.
// Copyright Antony Polukhin, 2016-2025.
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
@@ -23,7 +23,7 @@
namespace boost { namespace stacktrace { namespace detail {
std::size_t dump(void* /*fd*/, const native_frame_ptr_t* /*frames*/, std::size_t /*frames_count*/) BOOST_NOEXCEPT {
std::size_t dump(void* /*fd*/, const native_frame_ptr_t* /*frames*/, std::size_t /*frames_count*/) noexcept {
#if 0 // This code potentially could cause deadlocks (according to the MSDN). Disabled
boost::winapi::DWORD_ written;
const boost::winapi::DWORD_ bytes_to_write = static_cast<boost::winapi::DWORD_>(
@@ -38,7 +38,7 @@ std::size_t dump(void* /*fd*/, const native_frame_ptr_t* /*frames*/, std::size_t
return 0;
}
std::size_t dump(const char* /*file*/, const native_frame_ptr_t* /*frames*/, std::size_t /*frames_count*/) BOOST_NOEXCEPT {
std::size_t dump(const char* /*file*/, const native_frame_ptr_t* /*frames*/, std::size_t /*frames_count*/) noexcept {
#if 0 // This code causing deadlocks on some platforms. Disabled
void* const fd = boost::winapi::CreateFileA(
file,

View File

@@ -1,4 +1,4 @@
// Copyright Antony Polukhin, 2016-2021.
// Copyright Antony Polukhin, 2016-2025.
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
@@ -12,13 +12,14 @@
# pragma once
#endif
#include <boost/array.hpp>
#include <array>
#include <cstddef> // std::size_t
namespace boost { namespace stacktrace { namespace detail {
// We do not use boost::lexical_cast in this function to reduce module dependencies
inline boost::array<char, 40> to_dec_array(std::size_t value) BOOST_NOEXCEPT {
boost::array<char, 40> ret;
inline std::array<char, 40> to_dec_array(std::size_t value) noexcept {
std::array<char, 40> ret;
if (!value) {
ret[0] = '0';
ret[1] = '\0';

View File

@@ -1,4 +1,4 @@
// Copyright Antony Polukhin, 2016-2021.
// Copyright Antony Polukhin, 2016-2025.
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
@@ -12,20 +12,18 @@
# pragma once
#endif
#include <boost/array.hpp>
#include <boost/static_assert.hpp>
#include <boost/type_traits/is_pointer.hpp>
#include <boost/type_traits/make_unsigned.hpp>
#include <array>
#include <type_traits>
namespace boost { namespace stacktrace { namespace detail {
BOOST_STATIC_CONSTEXPR char to_hex_array_bytes[] = "0123456789ABCDEF";
template <class T>
inline boost::array<char, 2 + sizeof(void*) * 2 + 1> to_hex_array(T addr) BOOST_NOEXCEPT {
boost::array<char, 2 + sizeof(void*) * 2 + 1> ret = {"0x"};
inline std::array<char, 2 + sizeof(void*) * 2 + 1> to_hex_array(T addr) noexcept {
std::array<char, 2 + sizeof(void*) * 2 + 1> ret = {"0x"};
ret.back() = '\0';
BOOST_STATIC_ASSERT_MSG(!boost::is_pointer<T>::value, "");
static_assert(!std::is_pointer<T>::value, "");
const std::size_t s = sizeof(T);
@@ -43,9 +41,9 @@ inline boost::array<char, 2 + sizeof(void*) * 2 + 1> to_hex_array(T addr) BOOST_
return ret;
}
inline boost::array<char, 2 + sizeof(void*) * 2 + 1> to_hex_array(const void* addr) BOOST_NOEXCEPT {
inline std::array<char, 2 + sizeof(void*) * 2 + 1> to_hex_array(const void* addr) noexcept {
return to_hex_array(
reinterpret_cast< boost::make_unsigned<std::ptrdiff_t>::type >(addr)
reinterpret_cast< std::make_unsigned<std::ptrdiff_t>::type >(addr)
);
}

View File

@@ -1,4 +1,4 @@
// Copyright Antony Polukhin, 2016-2021.
// Copyright Antony Polukhin, 2016-2025.
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
@@ -17,7 +17,7 @@
namespace boost { namespace stacktrace { namespace detail {
// We do not use boost::lexical_cast in this function to reduce module dependencies
inline bool try_dec_convert(const char* s, std::size_t& res) BOOST_NOEXCEPT {
inline bool try_dec_convert(const char* s, std::size_t& res) noexcept {
char* end_ptr = 0;
res = std::strtoul(s, &end_ptr, 10);
return *end_ptr == '\0';

View File

@@ -1,4 +1,4 @@
// Copyright Antony Polukhin, 2016-2021.
// Copyright Antony Polukhin, 2016-2025.
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
@@ -23,7 +23,7 @@ struct to_string_using_nothing {
res = boost::stacktrace::frame(addr).name();
}
bool prepare_source_location(const void* /*addr*/) const BOOST_NOEXCEPT {
bool prepare_source_location(const void* /*addr*/) const noexcept {
return false;
}
};

View File

@@ -1,5 +1,5 @@
// Copyright 2014 Renato Tegon Forti, Antony Polukhin.
// Copyright 2015-2021 Antony Polukhin.
// Copyright Antony Polukhin, 2015-2025.
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt
@@ -13,8 +13,7 @@
# pragma once
#endif
#include <boost/static_assert.hpp>
#include <boost/type_traits/is_pointer.hpp>
#include <type_traits>
#if defined(__GNUC__) && defined(__GNUC_MINOR__) && (__GNUC__ * 100 + __GNUC_MINOR__ > 301)
# pragma GCC system_header
@@ -25,13 +24,13 @@ namespace boost { namespace stacktrace { namespace detail {
// GCC warns when reinterpret_cast between function pointer and object pointer occur.
// This functionsuppress the warnings and ensures that such casts are safe.
template <class To, class From>
To void_ptr_cast(From* v) BOOST_NOEXCEPT {
BOOST_STATIC_ASSERT_MSG(
boost::is_pointer<To>::value,
To void_ptr_cast(From* v) noexcept {
static_assert(
std::is_pointer<To>::value,
"`void_ptr_cast` function must be used only for casting to or from void pointers."
);
BOOST_STATIC_ASSERT_MSG(
static_assert(
sizeof(From*) == sizeof(To),
"Pointer to function and pointer to object differ in size on your platform."
);

View File

@@ -1,4 +1,4 @@
// Copyright Antony Polukhin, 2016-2021.
// Copyright Antony Polukhin, 2016-2025.
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
@@ -15,25 +15,37 @@
#include <iosfwd>
#include <string>
#include <boost/core/explicit_operator_bool.hpp>
#include <boost/stacktrace/safe_dump_to.hpp> // boost::stacktrace::detail::native_frame_ptr_t
#include <boost/stacktrace/detail/frame_decl.hpp>
#include <boost/stacktrace/detail/push_options.h>
#if defined(BOOST_MSVC) && (defined(BOOST_STACKTRACE_INTERNAL_BUILD_LIBS) || !defined(BOOST_STACKTRACE_LINK))
extern "C" {
#if defined(BOOST_STACKTRACE_DYN_LINK)
BOOST_SYMBOL_EXPORT
#elif defined(BOOST_STACKTRACE_LINK)
#else
BOOST_SYMBOL_EXPORT inline
#endif
void* boost_stacktrace_impl_return_nullptr() { return nullptr; }
}
#endif
namespace boost { namespace stacktrace {
/// Comparison operators that provide platform dependant ordering and have O(1) complexity; are Async-Handler-Safe.
BOOST_CONSTEXPR inline bool operator< (const frame& lhs, const frame& rhs) BOOST_NOEXCEPT { return lhs.address() < rhs.address(); }
BOOST_CONSTEXPR inline bool operator> (const frame& lhs, const frame& rhs) BOOST_NOEXCEPT { return rhs < lhs; }
BOOST_CONSTEXPR inline bool operator<=(const frame& lhs, const frame& rhs) BOOST_NOEXCEPT { return !(lhs > rhs); }
BOOST_CONSTEXPR inline bool operator>=(const frame& lhs, const frame& rhs) BOOST_NOEXCEPT { return !(lhs < rhs); }
BOOST_CONSTEXPR inline bool operator==(const frame& lhs, const frame& rhs) BOOST_NOEXCEPT { return lhs.address() == rhs.address(); }
BOOST_CONSTEXPR inline bool operator!=(const frame& lhs, const frame& rhs) BOOST_NOEXCEPT { return !(lhs == rhs); }
constexpr inline bool operator< (const frame& lhs, const frame& rhs) noexcept { return lhs.address() < rhs.address(); }
constexpr inline bool operator> (const frame& lhs, const frame& rhs) noexcept { return rhs < lhs; }
constexpr inline bool operator<=(const frame& lhs, const frame& rhs) noexcept { return !(lhs > rhs); }
constexpr inline bool operator>=(const frame& lhs, const frame& rhs) noexcept { return !(lhs < rhs); }
constexpr inline bool operator==(const frame& lhs, const frame& rhs) noexcept { return lhs.address() == rhs.address(); }
constexpr inline bool operator!=(const frame& lhs, const frame& rhs) noexcept { return !(lhs == rhs); }
/// Fast hashing support, O(1) complexity; Async-Handler-Safe.
inline std::size_t hash_value(const frame& f) BOOST_NOEXCEPT {
inline std::size_t hash_value(const frame& f) noexcept {
return reinterpret_cast<std::size_t>(f.address());
}

View File

@@ -1,4 +1,4 @@
// Copyright Antony Polukhin, 2016-2021.
// Copyright Antony Polukhin, 2016-2025.
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
@@ -12,6 +12,8 @@
# pragma once
#endif
#include <cstddef>
#if defined(BOOST_WINDOWS)
#include <boost/winapi/config.hpp>
#endif
@@ -23,32 +25,34 @@
# pragma warning(disable:2196) // warning #2196: routine is both "inline" and "noinline"
#endif
/// @file safe_dump_to.hpp This header contains low-level async-signal-safe functions for dumping call stacks. Dumps are binary serialized arrays of `void*`,
/// so you could read them by using 'od -tx8 -An stacktrace_dump_failename' Linux command or using boost::stacktrace::stacktrace::from_dump functions.
/// @file safe_dump_to.hpp \asyncsafe low-level
/// functions for dumping call stacks. Dumps are binary serialized arrays of `void*`,
/// so you could read them by using 'od -tx8 -An stacktrace_dump_failename'
/// Linux command or using boost::stacktrace::stacktrace::from_dump functions.
namespace boost { namespace stacktrace {
/// @cond
namespace detail {
typedef const void* native_frame_ptr_t; // TODO: change to `typedef void(*native_frame_ptr_t)();`
using native_frame_ptr_t = const void*;
enum helper{ max_frames_dump = 128 };
BOOST_STACKTRACE_FUNCTION std::size_t from_dump(const char* filename, native_frame_ptr_t* out_frames);
BOOST_STACKTRACE_FUNCTION std::size_t dump(const char* file, const native_frame_ptr_t* frames, std::size_t frames_count) BOOST_NOEXCEPT;
BOOST_STACKTRACE_FUNCTION std::size_t dump(const char* file, const native_frame_ptr_t* frames, std::size_t frames_count) noexcept;
#if defined(BOOST_WINDOWS)
BOOST_STACKTRACE_FUNCTION std::size_t dump(void* fd, const native_frame_ptr_t* frames, std::size_t frames_count) BOOST_NOEXCEPT;
BOOST_STACKTRACE_FUNCTION std::size_t dump(void* fd, const native_frame_ptr_t* frames, std::size_t frames_count) noexcept;
#else
// POSIX
BOOST_STACKTRACE_FUNCTION std::size_t dump(int fd, const native_frame_ptr_t* frames, std::size_t frames_count) BOOST_NOEXCEPT;
BOOST_STACKTRACE_FUNCTION std::size_t dump(int fd, const native_frame_ptr_t* frames, std::size_t frames_count) noexcept;
#endif
struct this_thread_frames { // struct is required to avoid warning about usage of inline+BOOST_NOINLINE
BOOST_NOINLINE BOOST_STACKTRACE_FUNCTION static std::size_t collect(native_frame_ptr_t* out_frames, std::size_t max_frames_count, std::size_t skip) BOOST_NOEXCEPT;
BOOST_NOINLINE BOOST_STACKTRACE_FUNCTION static std::size_t collect(native_frame_ptr_t* out_frames, std::size_t max_frames_count, std::size_t skip) noexcept;
BOOST_NOINLINE static std::size_t safe_dump_to_impl(void* memory, std::size_t size, std::size_t skip) BOOST_NOEXCEPT {
typedef boost::stacktrace::detail::native_frame_ptr_t native_frame_ptr_t;
BOOST_NOINLINE static std::size_t safe_dump_to_impl(void* memory, std::size_t size, std::size_t skip) noexcept {
using boost::stacktrace::detail::native_frame_ptr_t;
if (size < sizeof(native_frame_ptr_t)) {
return 0;
@@ -61,8 +65,8 @@ struct this_thread_frames { // struct is required to avoid warning about usage o
}
template <class T>
BOOST_NOINLINE static std::size_t safe_dump_to_impl(T file, std::size_t skip, std::size_t max_depth) BOOST_NOEXCEPT {
typedef boost::stacktrace::detail::native_frame_ptr_t native_frame_ptr_t;
BOOST_NOINLINE static std::size_t safe_dump_to_impl(T file, std::size_t skip, std::size_t max_depth) noexcept {
using boost::stacktrace::detail::native_frame_ptr_t;
native_frame_ptr_t buffer[boost::stacktrace::detail::max_frames_dump + 1];
if (max_depth > boost::stacktrace::detail::max_frames_dump) {
@@ -82,14 +86,14 @@ struct this_thread_frames { // struct is required to avoid warning about usage o
///
/// @b Complexity: O(N) where N is call sequence length, O(1) if BOOST_STACKTRACE_USE_NOOP is defined.
///
/// @b Async-Handler-Safety: Safe.
/// @b Async-Handler-Safety: \asyncsafe.
///
/// @returns Stored call sequence depth including terminating zero frame. To get the actually consumed bytes multiply this value by the sizeof(boost::stacktrace::frame::native_frame_ptr_t)
///
/// @param memory Preallocated buffer to store current function call sequence into.
///
/// @param size Size of the preallocated buffer.
BOOST_FORCEINLINE std::size_t safe_dump_to(void* memory, std::size_t size) BOOST_NOEXCEPT {
BOOST_FORCEINLINE std::size_t safe_dump_to(void* memory, std::size_t size) noexcept {
return boost::stacktrace::detail::this_thread_frames::safe_dump_to_impl(memory, size, 0);
}
@@ -97,7 +101,7 @@ BOOST_FORCEINLINE std::size_t safe_dump_to(void* memory, std::size_t size) BOOST
///
/// @b Complexity: O(N) where N is call sequence length, O(1) if BOOST_STACKTRACE_USE_NOOP is defined.
///
/// @b Async-Handler-Safety: Safe.
/// @b Async-Handler-Safety: \asyncsafe.
///
/// @returns Stored call sequence depth including terminating zero frame. To get the actually consumed bytes multiply this value by the sizeof(boost::stacktrace::frame::native_frame_ptr_t)
///
@@ -106,7 +110,7 @@ BOOST_FORCEINLINE std::size_t safe_dump_to(void* memory, std::size_t size) BOOST
/// @param memory Preallocated buffer to store current function call sequence into.
///
/// @param size Size of the preallocated buffer.
BOOST_FORCEINLINE std::size_t safe_dump_to(std::size_t skip, void* memory, std::size_t size) BOOST_NOEXCEPT {
BOOST_FORCEINLINE std::size_t safe_dump_to(std::size_t skip, void* memory, std::size_t size) noexcept {
return boost::stacktrace::detail::this_thread_frames::safe_dump_to_impl(memory, size, skip);
}
@@ -115,12 +119,12 @@ BOOST_FORCEINLINE std::size_t safe_dump_to(std::size_t skip, void* memory, std::
///
/// @b Complexity: O(N) where N is call sequence length, O(1) if BOOST_STACKTRACE_USE_NOOP is defined.
///
/// @b Async-Handler-Safety: Safe.
/// @b Async-Handler-Safety: \asyncsafe.
///
/// @returns Stored call sequence depth including terminating zero frame.
///
/// @param file File to store current function call sequence.
BOOST_FORCEINLINE std::size_t safe_dump_to(const char* file) BOOST_NOEXCEPT {
BOOST_FORCEINLINE std::size_t safe_dump_to(const char* file) noexcept {
return boost::stacktrace::detail::this_thread_frames::safe_dump_to_impl(file, 0, boost::stacktrace::detail::max_frames_dump);
}
@@ -128,7 +132,7 @@ BOOST_FORCEINLINE std::size_t safe_dump_to(const char* file) BOOST_NOEXCEPT {
///
/// @b Complexity: O(N) where N is call sequence length, O(1) if BOOST_STACKTRACE_USE_NOOP is defined.
///
/// @b Async-Handler-Safety: Safe.
/// @b Async-Handler-Safety: \asyncsafe.
///
/// @returns Stored call sequence depth including terminating zero frame.
///
@@ -137,7 +141,7 @@ BOOST_FORCEINLINE std::size_t safe_dump_to(const char* file) BOOST_NOEXCEPT {
/// @param max_depth Max call sequence depth to collect.
///
/// @param file File to store current function call sequence.
BOOST_FORCEINLINE std::size_t safe_dump_to(std::size_t skip, std::size_t max_depth, const char* file) BOOST_NOEXCEPT {
BOOST_FORCEINLINE std::size_t safe_dump_to(std::size_t skip, std::size_t max_depth, const char* file) noexcept {
return boost::stacktrace::detail::this_thread_frames::safe_dump_to_impl(file, skip, max_depth);
}
@@ -147,18 +151,18 @@ BOOST_FORCEINLINE std::size_t safe_dump_to(std::size_t skip, std::size_t max_dep
///
/// @b Complexity: O(N) where N is call sequence length, O(1) if BOOST_STACKTRACE_USE_NOOP is defined.
///
/// @b Async-Handler-Safety: Safe.
/// @b Async-Handler-Safety: \asyncsafe.
///
/// @returns Stored call sequence depth including terminating zero frame.
///
/// @param file File to store current function call sequence.
BOOST_FORCEINLINE std::size_t safe_dump_to(platform_specific_descriptor fd) BOOST_NOEXCEPT;
BOOST_FORCEINLINE std::size_t safe_dump_to(platform_specific_descriptor fd) noexcept;
/// @brief Writes into the provided file descriptor the current function call sequence if such operation is async signal safe.
///
/// @b Complexity: O(N) where N is call sequence length, O(1) if BOOST_STACKTRACE_USE_NOOP is defined.
///
/// @b Async-Handler-Safety: Safe.
/// @b Async-Handler-Safety: \asyncsafe.
///
/// @returns Stored call sequence depth including terminating zero frame.
///
@@ -167,26 +171,26 @@ BOOST_FORCEINLINE std::size_t safe_dump_to(platform_specific_descriptor fd) BOOS
/// @param max_depth Max call sequence depth to collect.
///
/// @param file File to store current function call sequence.
BOOST_FORCEINLINE std::size_t safe_dump_to(std::size_t skip, std::size_t max_depth, platform_specific_descriptor fd) BOOST_NOEXCEPT;
BOOST_FORCEINLINE std::size_t safe_dump_to(std::size_t skip, std::size_t max_depth, platform_specific_descriptor fd) noexcept;
#elif defined(BOOST_WINDOWS)
BOOST_FORCEINLINE std::size_t safe_dump_to(void* fd) BOOST_NOEXCEPT {
BOOST_FORCEINLINE std::size_t safe_dump_to(void* fd) noexcept {
return boost::stacktrace::detail::this_thread_frames::safe_dump_to_impl(fd, 0, boost::stacktrace::detail::max_frames_dump);
}
BOOST_FORCEINLINE std::size_t safe_dump_to(std::size_t skip, std::size_t max_depth, void* fd) BOOST_NOEXCEPT {
BOOST_FORCEINLINE std::size_t safe_dump_to(std::size_t skip, std::size_t max_depth, void* fd) noexcept {
return boost::stacktrace::detail::this_thread_frames::safe_dump_to_impl(fd, skip, max_depth);
}
#else
// POSIX
BOOST_FORCEINLINE std::size_t safe_dump_to(int fd) BOOST_NOEXCEPT {
BOOST_FORCEINLINE std::size_t safe_dump_to(int fd) noexcept {
return boost::stacktrace::detail::this_thread_frames::safe_dump_to_impl(fd, 0, boost::stacktrace::detail::max_frames_dump);
}
BOOST_FORCEINLINE std::size_t safe_dump_to(std::size_t skip, std::size_t max_depth, int fd) BOOST_NOEXCEPT {
BOOST_FORCEINLINE std::size_t safe_dump_to(std::size_t skip, std::size_t max_depth, int fd) noexcept {
return boost::stacktrace::detail::this_thread_frames::safe_dump_to_impl(fd, skip, max_depth);
}

View File

@@ -1,4 +1,4 @@
// Copyright Antony Polukhin, 2016-2021.
// Copyright Antony Polukhin, 2016-2025.
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
@@ -12,7 +12,6 @@
# pragma once
#endif
#include <boost/core/explicit_operator_bool.hpp>
#include <boost/core/no_exceptions_support.hpp>
#include <boost/container_hash/hash_fwd.hpp>
@@ -27,14 +26,48 @@
#include <boost/stacktrace/stacktrace_fwd.hpp>
#include <boost/stacktrace/safe_dump_to.hpp>
#include <boost/stacktrace/detail/frame_decl.hpp>
#include <boost/stacktrace/frame.hpp>
#ifdef BOOST_INTEL
# pragma warning(push)
# pragma warning(disable:2196) // warning #2196: routine is both "inline" and "noinline"
#endif
#if defined(BOOST_MSVC)
extern "C" {
const char* boost_stacktrace_impl_current_exception_stacktrace();
bool* boost_stacktrace_impl_ref_capture_stacktraces_at_throw();
}
#ifdef _M_IX86
# pragma comment(linker, "/ALTERNATENAME:_boost_stacktrace_impl_current_exception_stacktrace=_boost_stacktrace_impl_return_nullptr")
# pragma comment(linker, "/ALTERNATENAME:_boost_stacktrace_impl_ref_capture_stacktraces_at_throw=_boost_stacktrace_impl_return_nullptr")
#else
# pragma comment(linker, "/ALTERNATENAME:boost_stacktrace_impl_current_exception_stacktrace=boost_stacktrace_impl_return_nullptr")
# pragma comment(linker, "/ALTERNATENAME:boost_stacktrace_impl_ref_capture_stacktraces_at_throw=boost_stacktrace_impl_return_nullptr")
#endif
#endif
namespace boost { namespace stacktrace {
namespace impl {
#if defined(__GNUC__) && defined(__ELF__)
BOOST_NOINLINE BOOST_SYMBOL_VISIBLE __attribute__((weak))
const char* current_exception_stacktrace() noexcept;
BOOST_NOINLINE BOOST_SYMBOL_VISIBLE __attribute__((weak))
bool& ref_capture_stacktraces_at_throw() noexcept;
#endif
} // namespace impl
/// Class that on construction copies minimal information about call stack into its internals and provides access to that information.
/// @tparam Allocator Allocator to use during stack capture.
template <class Allocator>
@@ -59,13 +92,13 @@ class basic_stacktrace {
}
}
static std::size_t frames_count_from_buffer_size(std::size_t buffer_size) BOOST_NOEXCEPT {
static std::size_t frames_count_from_buffer_size(std::size_t buffer_size) noexcept {
const std::size_t ret = (buffer_size > sizeof(native_frame_ptr_t) ? buffer_size / sizeof(native_frame_ptr_t) : 0);
return (ret > 1024 ? 1024 : ret); // Dealing with suspiciously big sizes
}
BOOST_NOINLINE void init(std::size_t frames_to_skip, std::size_t max_depth) {
BOOST_CONSTEXPR_OR_CONST std::size_t buffer_size = 128;
constexpr std::size_t buffer_size = 128;
if (!max_depth) {
return;
}
@@ -121,8 +154,8 @@ public:
///
/// @b Complexity: O(N) where N is call sequence length, O(1) if BOOST_STACKTRACE_USE_NOOP is defined.
///
/// @b Async-Handler-Safety: Safe if Allocator construction, copying, Allocator::allocate and Allocator::deallocate are async signal safe.
BOOST_FORCEINLINE basic_stacktrace() BOOST_NOEXCEPT
/// @b Async-Handler-Safety: \asyncsafe if Allocator construction, copying, Allocator::allocate and Allocator::deallocate are async signal safe.
BOOST_FORCEINLINE basic_stacktrace() noexcept
: impl_()
{
init(0 , static_cast<std::size_t>(-1));
@@ -132,10 +165,10 @@ public:
///
/// @b Complexity: O(N) where N is call sequence length, O(1) if BOOST_STACKTRACE_USE_NOOP is defined.
///
/// @b Async-Handler-Safety: Safe if Allocator construction, copying, Allocator::allocate and Allocator::deallocate are async signal safe.
/// @b Async-Handler-Safety: \asyncsafe if Allocator construction, copying, Allocator::allocate and Allocator::deallocate are async signal safe.
///
/// @param a Allocator that would be passed to underlying storeage.
BOOST_FORCEINLINE explicit basic_stacktrace(const allocator_type& a) BOOST_NOEXCEPT
/// @param a Allocator that would be passed to underlying storage.
BOOST_FORCEINLINE explicit basic_stacktrace(const allocator_type& a) noexcept
: impl_(a)
{
init(0 , static_cast<std::size_t>(-1));
@@ -145,17 +178,17 @@ public:
///
/// @b Complexity: O(N) where N is call sequence length, O(1) if BOOST_STACKTRACE_USE_NOOP is defined.
///
/// @b Async-Handler-Safety: Safe if Allocator construction, copying, Allocator::allocate and Allocator::deallocate are async signal safe.
/// @b Async-Handler-Safety: \asyncsafe if Allocator construction, copying, Allocator::allocate and Allocator::deallocate are async signal safe.
///
/// @param skip How many top calls to skip and do not store in *this.
///
/// @param max_depth Max call sequence depth to collect.
///
/// @param a Allocator that would be passed to underlying storeage.
/// @param a Allocator that would be passed to underlying storage.
///
/// @throws Nothing. Note that default construction of allocator may throw, however it is
/// performed outside the constructor and exception in `allocator_type()` would not result in calling `std::terminate`.
BOOST_FORCEINLINE basic_stacktrace(std::size_t skip, std::size_t max_depth, const allocator_type& a = allocator_type()) BOOST_NOEXCEPT
BOOST_FORCEINLINE basic_stacktrace(std::size_t skip, std::size_t max_depth, const allocator_type& a = allocator_type()) noexcept
: impl_(a)
{
init(skip , max_depth);
@@ -163,14 +196,14 @@ public:
/// @b Complexity: O(st.size())
///
/// @b Async-Handler-Safety: Safe if Allocator construction, copying, Allocator::allocate and Allocator::deallocate are async signal safe.
/// @b Async-Handler-Safety: \asyncsafe if Allocator construction, copying, Allocator::allocate and Allocator::deallocate are async signal safe.
basic_stacktrace(const basic_stacktrace& st)
: impl_(st.impl_)
{}
/// @b Complexity: O(st.size())
///
/// @b Async-Handler-Safety: Safe if Allocator construction, copying, Allocator::allocate and Allocator::deallocate are async signal safe.
/// @b Async-Handler-Safety: \asyncsafe if Allocator construction, copying, Allocator::allocate and Allocator::deallocate are async signal safe.
basic_stacktrace& operator=(const basic_stacktrace& st) {
impl_ = st.impl_;
return *this;
@@ -179,26 +212,26 @@ public:
#ifdef BOOST_STACKTRACE_DOXYGEN_INVOKED
/// @b Complexity: O(1)
///
/// @b Async-Handler-Safety: Safe if Allocator::deallocate is async signal safe.
~basic_stacktrace() BOOST_NOEXCEPT = default;
/// @b Async-Handler-Safety: \asyncsafe if Allocator::deallocate is async signal safe.
~basic_stacktrace() noexcept = default;
#endif
#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
/// @b Complexity: O(1)
///
/// @b Async-Handler-Safety: Safe if Allocator construction and copying are async signal safe.
basic_stacktrace(basic_stacktrace&& st) BOOST_NOEXCEPT
/// @b Async-Handler-Safety: \asyncsafe if Allocator construction and copying are async signal safe.
basic_stacktrace(basic_stacktrace&& st) noexcept
: impl_(std::move(st.impl_))
{}
/// @b Complexity: O(st.size())
///
/// @b Async-Handler-Safety: Safe if Allocator construction and copying are async signal safe.
/// @b Async-Handler-Safety: \asyncsafe if Allocator construction and copying are async signal safe.
basic_stacktrace& operator=(basic_stacktrace&& st)
#ifndef BOOST_NO_CXX11_HDR_TYPE_TRAITS
BOOST_NOEXCEPT_IF(( std::is_nothrow_move_assignable< std::vector<boost::stacktrace::frame, Allocator> >::value ))
noexcept(( std::is_nothrow_move_assignable< std::vector<boost::stacktrace::frame, Allocator> >::value ))
#else
BOOST_NOEXCEPT
noexcept
#endif
{
impl_ = std::move(st.impl_);
@@ -210,8 +243,8 @@ public:
///
/// @b Complexity: O(1)
///
/// @b Async-Handler-Safety: Safe.
size_type size() const BOOST_NOEXCEPT {
/// @b Async-Handler-Safety: \asyncsafe.
size_type size() const noexcept {
return impl_.size();
}
@@ -222,44 +255,44 @@ public:
///
/// @b Complexity: O(1).
///
/// @b Async-Handler-Safety: Safe.
const_reference operator[](std::size_t frame_no) const BOOST_NOEXCEPT {
/// @b Async-Handler-Safety: \asyncsafe.
const_reference operator[](std::size_t frame_no) const noexcept {
return impl_[frame_no];
}
/// @b Complexity: O(1)
///
/// @b Async-Handler-Safety: Safe.
const_iterator begin() const BOOST_NOEXCEPT { return impl_.begin(); }
/// @b Async-Handler-Safety: \asyncsafe.
const_iterator begin() const noexcept { return impl_.begin(); }
/// @b Complexity: O(1)
///
/// @b Async-Handler-Safety: Safe.
const_iterator cbegin() const BOOST_NOEXCEPT { return impl_.begin(); }
/// @b Async-Handler-Safety: \asyncsafe.
const_iterator cbegin() const noexcept { return impl_.begin(); }
/// @b Complexity: O(1)
///
/// @b Async-Handler-Safety: Safe.
const_iterator end() const BOOST_NOEXCEPT { return impl_.end(); }
/// @b Async-Handler-Safety: \asyncsafe.
const_iterator end() const noexcept { return impl_.end(); }
/// @b Complexity: O(1)
///
/// @b Async-Handler-Safety: Safe.
const_iterator cend() const BOOST_NOEXCEPT { return impl_.end(); }
/// @b Async-Handler-Safety: \asyncsafe.
const_iterator cend() const noexcept { return impl_.end(); }
/// @b Complexity: O(1)
///
/// @b Async-Handler-Safety: Safe.
const_reverse_iterator rbegin() const BOOST_NOEXCEPT { return impl_.rbegin(); }
/// @b Async-Handler-Safety: \asyncsafe.
const_reverse_iterator rbegin() const noexcept { return impl_.rbegin(); }
/// @b Complexity: O(1)
///
/// @b Async-Handler-Safety: Safe.
const_reverse_iterator crbegin() const BOOST_NOEXCEPT { return impl_.rbegin(); }
/// @b Async-Handler-Safety: \asyncsafe.
const_reverse_iterator crbegin() const noexcept { return impl_.rbegin(); }
/// @b Complexity: O(1)
///
/// @b Async-Handler-Safety: Safe.
const_reverse_iterator rend() const BOOST_NOEXCEPT { return impl_.rend(); }
/// @b Async-Handler-Safety: \asyncsafe.
const_reverse_iterator rend() const noexcept { return impl_.rend(); }
/// @b Complexity: O(1)
///
/// @b Async-Handler-Safety: Safe.
const_reverse_iterator crend() const BOOST_NOEXCEPT { return impl_.rend(); }
/// @b Async-Handler-Safety: \asyncsafe.
const_reverse_iterator crend() const noexcept { return impl_.rend(); }
/// @brief Allows to check that stack trace capturing was successful.
@@ -267,22 +300,18 @@ public:
///
/// @b Complexity: O(1)
///
/// @b Async-Handler-Safety: Safe.
BOOST_EXPLICIT_OPERATOR_BOOL_NOEXCEPT()
/// @b Async-Handler-Safety: \asyncsafe.
constexpr explicit operator bool () const noexcept { return !empty(); }
/// @brief Allows to check that stack trace failed.
/// @returns `true` if `this->size() == 0`
///
/// @b Complexity: O(1)
///
/// @b Async-Handler-Safety: Safe.
bool empty() const BOOST_NOEXCEPT { return !size(); }
/// @b Async-Handler-Safety: \asyncsafe.
bool empty() const noexcept { return !size(); }
/// @cond
bool operator!() const BOOST_NOEXCEPT { return !size(); }
/// @endcond
const std::vector<boost::stacktrace::frame, Allocator>& as_vector() const BOOST_NOEXCEPT {
const std::vector<boost::stacktrace::frame, Allocator>& as_vector() const noexcept {
return impl_;
}
@@ -319,7 +348,7 @@ public:
/// Constructs stacktrace from raw memory dump. Terminating zero frame is discarded.
///
/// @param begin Begining of the memory where the stacktrace was saved using the boost::stacktrace::safe_dump_to
/// @param begin Beginning of the memory where the stacktrace was saved using the boost::stacktrace::safe_dump_to
///
/// @param buffer_size_in_bytes Size of the memory. Usually the same value that was passed to the boost::stacktrace::safe_dump_to
///
@@ -344,15 +373,55 @@ public:
return ret;
}
/// Returns a basic_stacktrace object containing a stacktrace captured at
/// the point where the currently handled exception was thrown by its
/// initial throw-expression (i.e. not a rethrow), or an empty
/// basic_stacktrace object if:
///
/// - the `boost_stacktrace_from_exception` library is not linked to the
/// current binary, or
/// - the initialization of stacktrace failed, or
/// - stacktrace captures are not enabled for the throwing thread, or
/// - no exception is being handled, or
/// - due to implementation-defined reasons.
///
/// `alloc` is passed to the constructor of the stacktrace object.
/// Rethrowing an exception using a throw-expression with no operand does
/// not alter the captured stacktrace.
///
/// Implements https://wg21.link/p2370r1
static basic_stacktrace<Allocator> from_current_exception(const allocator_type& alloc = allocator_type()) noexcept {
// Matches the constant from implementation
constexpr std::size_t kStacktraceDumpSize = 4096;
const char* trace = nullptr;
#if defined(__GNUC__) && defined(__ELF__)
if (impl::current_exception_stacktrace) {
trace = impl::current_exception_stacktrace();
}
#elif defined(BOOST_MSVC)
trace = boost_stacktrace_impl_current_exception_stacktrace();
#endif
if (trace) {
try {
return basic_stacktrace<Allocator>::from_dump(trace, kStacktraceDumpSize, alloc);
} catch (const std::exception&) {
// ignore
}
}
return basic_stacktrace<Allocator>{0, 0, alloc};
}
};
/// @brief Compares stacktraces for less, order is platform dependent.
///
/// @b Complexity: Amortized O(1); worst case O(size())
///
/// @b Async-Handler-Safety: Safe.
/// @b Async-Handler-Safety: \asyncsafe.
template <class Allocator1, class Allocator2>
bool operator< (const basic_stacktrace<Allocator1>& lhs, const basic_stacktrace<Allocator2>& rhs) BOOST_NOEXCEPT {
bool operator< (const basic_stacktrace<Allocator1>& lhs, const basic_stacktrace<Allocator2>& rhs) noexcept {
return lhs.size() < rhs.size() || (lhs.size() == rhs.size() && lhs.as_vector() < rhs.as_vector());
}
@@ -360,37 +429,37 @@ bool operator< (const basic_stacktrace<Allocator1>& lhs, const basic_stacktrace<
///
/// @b Complexity: Amortized O(1); worst case O(size())
///
/// @b Async-Handler-Safety: Safe.
/// @b Async-Handler-Safety: \asyncsafe.
template <class Allocator1, class Allocator2>
bool operator==(const basic_stacktrace<Allocator1>& lhs, const basic_stacktrace<Allocator2>& rhs) BOOST_NOEXCEPT {
bool operator==(const basic_stacktrace<Allocator1>& lhs, const basic_stacktrace<Allocator2>& rhs) noexcept {
return lhs.as_vector() == rhs.as_vector();
}
/// Comparison operators that provide platform dependant ordering and have amortized O(1) complexity; O(size()) worst case complexity; are Async-Handler-Safe.
template <class Allocator1, class Allocator2>
bool operator> (const basic_stacktrace<Allocator1>& lhs, const basic_stacktrace<Allocator2>& rhs) BOOST_NOEXCEPT {
bool operator> (const basic_stacktrace<Allocator1>& lhs, const basic_stacktrace<Allocator2>& rhs) noexcept {
return rhs < lhs;
}
template <class Allocator1, class Allocator2>
bool operator<=(const basic_stacktrace<Allocator1>& lhs, const basic_stacktrace<Allocator2>& rhs) BOOST_NOEXCEPT {
bool operator<=(const basic_stacktrace<Allocator1>& lhs, const basic_stacktrace<Allocator2>& rhs) noexcept {
return !(lhs > rhs);
}
template <class Allocator1, class Allocator2>
bool operator>=(const basic_stacktrace<Allocator1>& lhs, const basic_stacktrace<Allocator2>& rhs) BOOST_NOEXCEPT {
bool operator>=(const basic_stacktrace<Allocator1>& lhs, const basic_stacktrace<Allocator2>& rhs) noexcept {
return !(lhs < rhs);
}
template <class Allocator1, class Allocator2>
bool operator!=(const basic_stacktrace<Allocator1>& lhs, const basic_stacktrace<Allocator2>& rhs) BOOST_NOEXCEPT {
bool operator!=(const basic_stacktrace<Allocator1>& lhs, const basic_stacktrace<Allocator2>& rhs) noexcept {
return !(lhs == rhs);
}
/// Fast hashing support, O(st.size()) complexity; Async-Handler-Safe.
template <class Allocator>
std::size_t hash_value(const basic_stacktrace<Allocator>& st) BOOST_NOEXCEPT {
std::size_t hash_value(const basic_stacktrace<Allocator>& st) noexcept {
return boost::hash_range(st.as_vector().begin(), st.as_vector().end());
}

View File

@@ -1,4 +1,4 @@
// Copyright Antony Polukhin, 2016-2021.
// Copyright Antony Polukhin, 2016-2025.
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at

View File

@@ -0,0 +1,62 @@
// Copyright Antony Polukhin, 2023-2025.
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#ifndef BOOST_STACKTRACE_THIS_THREAD_HPP
#define BOOST_STACKTRACE_THIS_THREAD_HPP
#include <boost/config.hpp>
#ifdef BOOST_HAS_PRAGMA_ONCE
# pragma once
#endif
#include <boost/stacktrace/stacktrace.hpp>
namespace boost { namespace stacktrace { namespace this_thread {
/// @brief Invoking the function with the enable parameter equal to `true`
/// enables capturing of stacktraces by the current thread of execution at
/// exception object construction if the `boost_stacktrace_from_exception`
/// library is linked to the current binary; disables otherwise.
///
/// Implements https://wg21.link/p2370r1
inline void set_capture_stacktraces_at_throw(bool enable = true) noexcept {
#if defined(__GNUC__) && defined(__ELF__)
if (impl::ref_capture_stacktraces_at_throw) {
impl::ref_capture_stacktraces_at_throw() = enable;
}
#elif defined(BOOST_MSVC)
if (bool* p = boost_stacktrace_impl_ref_capture_stacktraces_at_throw()) {
*p = enable;
}
#endif
(void)enable;
}
/// @return whether the capturing of stacktraces by the current thread of
/// execution is enabled and
/// boost::stacktrace::basic_stacktrace::from_current_exception may return a
/// non empty stacktrace.
///
/// Returns true if set_capture_stacktraces_at_throw(false) was not called
/// and the `boost_stacktrace_from_exception` is linked to the current binary.
///
/// Implements https://wg21.link/p2370r1
inline bool get_capture_stacktraces_at_throw() noexcept {
#if defined(__GNUC__) && defined(__ELF__)
if (impl::ref_capture_stacktraces_at_throw) {
return impl::ref_capture_stacktraces_at_throw();
}
#elif defined(BOOST_MSVC)
if (bool* p = boost_stacktrace_impl_ref_capture_stacktraces_at_throw()) {
return *p;
}
#endif
return false;
}
}}} // namespace boost::stacktrace::this_thread
#endif // BOOST_STACKTRACE_THIS_THREAD_HPP

View File

@@ -1,16 +1,18 @@
<!DOCTYPE html>
<!--
Copyright (c) 2014-2021 Antony Polukhin
Copyright (c) Antony Polukhin, 2014-2024
antoshkka at gmail dot com
Distributed under the Boost Software License,
Version 1.0. (See accompanying file LICENSE_1_0.txt
or copy at http://boost.org/LICENSE_1_0.txt)
boost-no-inspect
-->
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="refresh" content="0; url=https://www.boost.org/doc/libs/master/doc/html/stacktrace.html">
<meta http-equiv="refresh" content="0; url=../../doc/html/stacktrace.html">
<title>Boost.Stacktrace</title>
<style>
body {
@@ -26,10 +28,10 @@
<body>
<p>
Automatic redirection failed, please go to
<a href="https://www.boost.org/doc/libs/master/doc/html/stacktrace.html">https://www.boost.org/doc/libs/master/doc/html/stacktrace.html</a>
<a href="../../doc/html/stacktrace.html">../../doc/html/stacktrace.html</a>
</p>
<p>
&copy; 2014-2021 Antony Polukhin
&copy; Antony Polukhin, 2014-2024
</p>
</body>
</html>

View File

@@ -11,5 +11,6 @@
"std": [ "c++23" ],
"category": [
"System", "Correctness"
]
],
"cxxstd": "11"
}

54
src/exception_headers.h Normal file
View File

@@ -0,0 +1,54 @@
// Copyright Antony Polukhin, 2023-2025.
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#include <stddef.h>
#if defined(__x86_64__) || defined(_M_X64) || defined(__MINGW32__)
#define BOOST_STACKTRACE_ALWAYS_STORE_IN_PADDING 1
#else
#define BOOST_STACKTRACE_ALWAYS_STORE_IN_PADDING 0
#endif
extern "C" {
// Developer note: helper to experiment with layouts of different
// exception headers https://godbolt.org/z/rrcdPbh1P
// https://github.com/llvm/llvm-project/blob/b3dd14ce07f2750ae1068fe62abbf2f3bd2cade8/libcxxabi/src/cxa_exception.h
struct cxa_exception_begin_llvm {
const char* reserve;
size_t referenceCount;
};
static cxa_exception_begin_llvm* exception_begin_llvm_ptr(void* ptr) {
size_t kExceptionBeginOffset = (
sizeof(void*) == 8 ? 128 : 80
);
return (cxa_exception_begin_llvm*)((char*)ptr - kExceptionBeginOffset);
}
// https://github.com/gcc-mirror/gcc/blob/5d2a360f0a541646abb11efdbabc33c6a04de7ee/libstdc%2B%2B-v3/libsupc%2B%2B/unwind-cxx.h#L100
struct cxa_exception_begin_gcc {
size_t referenceCount;
const char* reserve;
};
static cxa_exception_begin_gcc* exception_begin_gcc_ptr(void* ptr) {
size_t kExceptionBeginOffset = (
sizeof(void*) == 8 ? 128 : 96
);
return (cxa_exception_begin_gcc*)((char*)ptr - kExceptionBeginOffset);
}
static void* get_current_exception_raw_ptr(void* exc_ptr) {
// https://github.com/gcc-mirror/gcc/blob/16e2427f50c208dfe07d07f18009969502c25dc8/libstdc%2B%2B-v3/libsupc%2B%2B/eh_ptr.cc#L147
return *static_cast<void**>(exc_ptr);
}
} // extern "C"

367
src/from_exception.cpp Normal file
View File

@@ -0,0 +1,367 @@
// Copyright Antony Polukhin, 2023-2025.
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#if defined(__MINGW32__) || defined(_MSC_VER)
#include <boost/stacktrace/safe_dump_to.hpp>
#include <windows.h>
extern "C" void** __cdecl __current_exception(); // exported from vcruntime.dll
#define _pCurrentException static_cast<PEXCEPTION_RECORD>(*__current_exception())
namespace {
constexpr std::size_t kStacktraceDumpSize = 4096;
struct thrown_info {
ULONG_PTR object;
char* dump;
};
struct exception_data {
bool capture_stacktraces_at_throw = true;
unsigned count = 0;
thrown_info* info = nullptr;
~exception_data() noexcept {
HANDLE hHeap = GetProcessHeap();
for (unsigned i = 0; i < count; ++i) {
HeapFree(hHeap, 0, info[i].dump);
}
HeapFree(hHeap, 0, info);
}
};
thread_local exception_data data;
inline bool PER_IS_MSVC_EH(PEXCEPTION_RECORD p) noexcept {
const DWORD EH_EXCEPTION_NUMBER = 0xE06D7363;
const ULONG_PTR EH_MAGIC_NUMBER1 = 0x19930520;
return p->ExceptionCode == EH_EXCEPTION_NUMBER &&
(p->NumberParameters == 3 || p->NumberParameters == 4) &&
p->ExceptionInformation[0] == EH_MAGIC_NUMBER1;
}
inline ULONG_PTR PER_PEXCEPTOBJ(PEXCEPTION_RECORD p) noexcept {
return p->ExceptionInformation[1];
}
unsigned current_cxx_exception_index() noexcept {
if (PEXCEPTION_RECORD current_cxx_exception = _pCurrentException) {
for (unsigned i = data.count; i > 0;) {
--i;
if (data.info[i].object == PER_PEXCEPTOBJ(current_cxx_exception)) {
return i;
}
}
}
return data.count;
}
bool is_processing_rethrow(PEXCEPTION_RECORD p) noexcept {
// Processing flow:
// 0. throw;
// 1. _CxxThrowException(pExceptionObject = nullptr)
// 2. VEH & SEH (may throw new c++ exceptions!)
// 3. __RethrowException(_pCurrentException)
// 4. VEH
if (PER_PEXCEPTOBJ(p) == 0) return true;
PEXCEPTION_RECORD current_cxx_exception = _pCurrentException;
if (current_cxx_exception == nullptr) return false;
return PER_PEXCEPTOBJ(p) == PER_PEXCEPTOBJ(current_cxx_exception);
}
LONG NTAPI veh(PEXCEPTION_POINTERS p) {
if (data.capture_stacktraces_at_throw &&
PER_IS_MSVC_EH(p->ExceptionRecord) &&
!is_processing_rethrow(p->ExceptionRecord)) {
HANDLE hHeap = GetProcessHeap();
unsigned index = current_cxx_exception_index();
unsigned new_count = 1 + (index < data.count ? index + 1 : 0);
for (unsigned i = new_count; i < data.count; ++i) {
HeapFree(hHeap, 0, data.info[i].dump);
data.info[i].dump = nullptr;
}
void* new_info;
if (data.info) {
new_info = HeapReAlloc(hHeap, HEAP_ZERO_MEMORY, data.info, sizeof(thrown_info) * new_count);
} else {
new_info = HeapAlloc(hHeap, HEAP_ZERO_MEMORY, sizeof(thrown_info) * new_count);
}
if (new_info) {
data.count = new_count;
data.info = static_cast<thrown_info*>(new_info);
data.info[data.count - 1].object = PER_PEXCEPTOBJ(p->ExceptionRecord);
char*& dump_ptr = data.info[data.count - 1].dump;
if (dump_ptr == nullptr) {
dump_ptr = static_cast<char*>(HeapAlloc(hHeap, 0, kStacktraceDumpSize));
}
if (dump_ptr != nullptr) {
const std::size_t kSkip = 4;
boost::stacktrace::safe_dump_to(kSkip, dump_ptr, kStacktraceDumpSize);
}
} else if (new_count <= data.count) {
data.count = new_count - 1;
HeapFree(hHeap, 0, data.info[data.count - 1].dump);
data.info[data.count - 1].dump = nullptr;
}
}
return EXCEPTION_CONTINUE_SEARCH;
}
struct veh_installer {
PVOID h;
veh_installer() noexcept : h(AddVectoredExceptionHandler(1, veh)) {}
~veh_installer() noexcept { RemoveVectoredExceptionHandler(h); }
} installer;
}
extern "C" {
BOOST_SYMBOL_EXPORT const char* boost_stacktrace_impl_current_exception_stacktrace() {
unsigned index = current_cxx_exception_index();
return index < data.count ? data.info[index].dump : nullptr;
}
BOOST_SYMBOL_EXPORT bool* boost_stacktrace_impl_ref_capture_stacktraces_at_throw() {
return &data.capture_stacktraces_at_throw;
}
}
namespace boost { namespace stacktrace { namespace impl {
BOOST_SYMBOL_EXPORT void assert_no_pending_traces() noexcept {
}
}}} // namespace boost::stacktrace::impl
#else
#include "exception_headers.h"
// At the moment the file is used only on POSIX. _Unwind_Backtrace may be
// available on some platforms only if _GNU_SOURCE is defined.
#ifndef _GNU_SOURCE
# define _GNU_SOURCE
#endif
#include <boost/assert.hpp>
#include <boost/stacktrace/safe_dump_to.hpp>
#include <cstddef>
#include <exception>
#include <dlfcn.h>
#if !BOOST_STACKTRACE_ALWAYS_STORE_IN_PADDING
#include <mutex>
#include <unordered_map>
#ifndef BOOST_STACKTRACE_LIBCXX_RUNTIME_MAY_CAUSE_MEMORY_LEAK
#ifdef BOOST_HAS_THREADS
#error On this platform memory leaks are possible if capturing stacktrace from \
exceptions is enabled and exceptions are thrown concurrently \
and libc++ runtime is used. \
\
Define `BOOST_STACKTRACE_LIBCXX_RUNTIME_MAY_CAUSE_MEMORY_LEAK` to \
suppress this error if the library would not be used with libc++ \
runtime (for example, it would be only used with GCC runtime). \
\
Otherwise, disable the boost_stacktrace_from_exception library build \
(for example by `./b2 boost.stacktrace.from_exception=off` option).
#endif
#endif
#endif
namespace {
constexpr std::size_t kStacktraceDumpSize = 4096;
struct decrement_on_destroy {
std::size_t& to_decrement;
~decrement_on_destroy() { --to_decrement; }
};
#if !BOOST_STACKTRACE_ALWAYS_STORE_IN_PADDING
// Inspired by the coursework by Andrei Nekrashevich in the `libsfe`
/*constinit*/ std::mutex g_mapping_mutex;
std::unordered_map<void*, const char*> g_exception_to_dump_mapping;
#endif
} // namespace
namespace boost { namespace stacktrace { namespace impl {
BOOST_SYMBOL_EXPORT bool& ref_capture_stacktraces_at_throw() noexcept {
/*constinit*/ thread_local bool g_capture_stacktraces_at_throw{true};
return g_capture_stacktraces_at_throw;
}
}}} // namespace boost::stacktrace::impl
namespace __cxxabiv1 {
#if defined(__GNUC__) && defined(__ELF__)
// libc++-runtime specific function
extern "C" BOOST_NOINLINE BOOST_SYMBOL_VISIBLE __attribute__((weak))
void __cxa_increment_exception_refcount(void *primary_exception) throw();
static bool is_libcpp_runtime() noexcept {
return __cxa_increment_exception_refcount;
}
#else
static bool is_libcpp_runtime() noexcept { return false; }
#endif
static const char*& reference_to_empty_padding(void* ptr) noexcept {
if (is_libcpp_runtime()) {
// libc++-runtime
BOOST_ASSERT_MSG(
sizeof(void*) != 4,
"32bit platforms are unsupported with libc++ runtime padding reusage. "
"Please report this issue to the library maintainters."
);
return exception_begin_llvm_ptr(ptr)->reserve;
}
return exception_begin_gcc_ptr(ptr)->reserve;
}
extern "C" BOOST_SYMBOL_EXPORT
void* __cxa_allocate_exception(size_t thrown_size) throw() {
static const auto orig_allocate_exception = []() {
void* const ptr = ::dlsym(RTLD_NEXT, "__cxa_allocate_exception");
BOOST_ASSERT_MSG(ptr, "Failed to find '__cxa_allocate_exception'");
return reinterpret_cast<void*(*)(size_t)>(ptr);
}();
if (!boost::stacktrace::impl::ref_capture_stacktraces_at_throw()) {
return orig_allocate_exception(thrown_size);
}
#ifndef NDEBUG
static thread_local std::size_t in_allocate_exception = 0;
BOOST_ASSERT_MSG(in_allocate_exception < 10, "Suspicious recursion");
++in_allocate_exception;
const decrement_on_destroy guard{in_allocate_exception};
#endif
static constexpr std::size_t kAlign = alignof(std::max_align_t);
thrown_size = (thrown_size + kAlign - 1) & (~(kAlign - 1));
void* const ptr = orig_allocate_exception(thrown_size + kStacktraceDumpSize);
char* const dump_ptr = static_cast<char*>(ptr) + thrown_size;
constexpr size_t kSkip = 1;
boost::stacktrace::safe_dump_to(kSkip, dump_ptr, kStacktraceDumpSize);
#if !BOOST_STACKTRACE_ALWAYS_STORE_IN_PADDING
if (is_libcpp_runtime()) {
const std::lock_guard<std::mutex> guard{g_mapping_mutex};
g_exception_to_dump_mapping[ptr] = dump_ptr;
} else
#endif
{
BOOST_ASSERT_MSG(
reference_to_empty_padding(ptr) == nullptr,
"Not zeroed out, unsupported implementation"
);
reference_to_empty_padding(ptr) = dump_ptr;
}
return ptr;
}
#if !BOOST_STACKTRACE_ALWAYS_STORE_IN_PADDING
// __cxa_free_exception is not called in libc++ as the
// __cxa_decrement_exception_refcount has an inlined call to
// __cxa_free_exception. Overriding libc++ specific function
extern "C" BOOST_SYMBOL_EXPORT
void __cxa_decrement_exception_refcount(void *thrown_object) throw() {
BOOST_ASSERT(is_libcpp_runtime());
if (!thrown_object) {
return;
}
static const auto orig_decrement_refcount = []() {
void* const ptr = ::dlsym(RTLD_NEXT, "__cxa_decrement_exception_refcount");
BOOST_ASSERT_MSG(ptr, "Failed to find '__cxa_decrement_exception_refcount'");
return reinterpret_cast<void(*)(void*)>(ptr);
}();
const auto* exception_header = exception_begin_llvm_ptr(thrown_object);
// The following line has a race and could give false positives and false
// negatives. In first case we remove the trace earlier, in the second case
// we get a memory leak.
if (exception_header->referenceCount == 1) {
const std::lock_guard<std::mutex> guard{g_mapping_mutex};
g_exception_to_dump_mapping.erase(thrown_object);
}
orig_decrement_refcount(thrown_object);
}
#endif
} // namespace __cxxabiv1
namespace boost { namespace stacktrace { namespace impl {
BOOST_SYMBOL_EXPORT const char* current_exception_stacktrace() noexcept {
if (!ref_capture_stacktraces_at_throw()) {
return nullptr;
}
auto exc_ptr = std::current_exception();
void* const exc_raw_ptr = get_current_exception_raw_ptr(&exc_ptr);
if (!exc_raw_ptr) {
return nullptr;
}
#if !BOOST_STACKTRACE_ALWAYS_STORE_IN_PADDING
if (__cxxabiv1::is_libcpp_runtime()) {
const std::lock_guard<std::mutex> guard{g_mapping_mutex};
const auto it = g_exception_to_dump_mapping.find(exc_raw_ptr);
if (it != g_exception_to_dump_mapping.end()) {
return it->second;
} else {
return nullptr;
}
} else
#endif
{
return __cxxabiv1::reference_to_empty_padding(exc_raw_ptr);
}
}
BOOST_SYMBOL_EXPORT void assert_no_pending_traces() noexcept {
#if !BOOST_STACKTRACE_ALWAYS_STORE_IN_PADDING
if (__cxxabiv1::is_libcpp_runtime()) {
const std::lock_guard<std::mutex> guard{g_mapping_mutex};
BOOST_ASSERT(g_exception_to_dump_mapping.empty());
}
#endif
}
}}} // namespace boost::stacktrace::impl
#endif

View File

@@ -4,6 +4,10 @@
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#ifndef _GNU_SOURCE
# define _GNU_SOURCE
#endif
#define BOOST_STACKTRACE_INTERNAL_BUILD_LIBS
#define BOOST_STACKTRACE_LINK
#include <boost/stacktrace/detail/frame_msvc.ipp>

View File

@@ -4,6 +4,10 @@
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#ifndef _GNU_SOURCE
# define _GNU_SOURCE
#endif
#define BOOST_STACKTRACE_INTERNAL_BUILD_LIBS
#define BOOST_STACKTRACE_LINK
#define BOOST_STACKTRACE_USE_WINDBG_CACHED

14
test/CMakeLists.txt Normal file
View File

@@ -0,0 +1,14 @@
# Copyright 2018-2020 Peter Dimov
# Distributed under the Boost Software License, Version 1.0.
# See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt
include(BoostTest OPTIONAL RESULT_VARIABLE HAVE_BOOST_TEST)
if(NOT HAVE_BOOST_TEST)
return()
endif()
boost_test(TYPE run SOURCES test.cpp test_impl.cpp LINK_LIBRARIES Boost::stacktrace Boost::core)
boost_test(TYPE run SOURCES test_noop.cpp test_impl.cpp LINK_LIBRARIES Boost::stacktrace_noop Boost::core)
boost_test(TYPE run SOURCES test_trivial.cpp LINK_LIBRARIES Boost::stacktrace Boost::core)

View File

@@ -1,11 +1,13 @@
# Copyright (C) 2016-2021, Antony Polukhin.
# Copyright (C) 2016-2024, Antony Polukhin.
#
# Use, modification and distribution is subject to the Boost Software License,
# Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
# http://www.boost.org/LICENSE_1_0.txt)
#
import ../../config/checks/config : requires ;
import-search /boost/config/checks ;
import config : requires ;
import testing ;
lib dl : : <link>shared ;
lib gcc_s ;
@@ -24,12 +26,15 @@ lib backtrace
project
: requirements
[ requires cxx11_rvalue_references cxx11_template_aliases cxx11_noexcept ]
<toolset>msvc:<asynch-exceptions>on
<toolset>intel:<cxxflags>-wd2196
<target-os>linux:<linkflags>-lpthread
<warnings>all
<test-info>always_show_run_output
<visibility>hidden
<include>..
<library>/boost/optional//boost_optional
;
local FORCE_SYMBOL_EXPORT = <target-os>freebsd:<linkflags>"-rdynamic" <target-os>solaris:<linkflags>"-Bdynamic" <target-os>aix:<linkflags>"-rdynamic"
@@ -81,6 +86,7 @@ test-suite stacktrace_tests
# Header only tests with debug symbols
[ run test.cpp test_impl.cpp : : : <debug-symbols>on <define>BOOST_STACKTRACE_USE_BACKTRACE $(BT_DEPS) : backtrace_ho ]
[ run test.cpp test_impl.cpp : : : <debug-symbols>on <define>BOOST_STACKTRACE_USE_BACKTRACE <define>BOOST_STACKTRACE_BACKTRACE_FORCE_STATIC $(BT_DEPS) : backtrace_ho_static ]
[ run test.cpp test_impl.cpp : : : <debug-symbols>on <define>BOOST_STACKTRACE_USE_ADDR2LINE $(AD2L_DEPS) : addr2line_ho ]
[ run test_noop.cpp test_impl.cpp : : : <debug-symbols>on <define>BOOST_STACKTRACE_USE_NOOP $(NOOP_DEPS) : noop_ho ]
[ run test.cpp test_impl.cpp : : : <debug-symbols>on $(WIND_DEPS) : windbg_ho ]
@@ -88,6 +94,15 @@ test-suite stacktrace_tests
[ run test.cpp test_impl.cpp : : : <debug-symbols>on $(FORCE_SYMBOL_EXPORT) $(BASIC_DEPS) : basic_ho ]
[ run test.cpp test_impl.cpp : : : <debug-symbols>on <define>BOOST_STACKTRACE_TEST_NO_DEBUG_AT_ALL $(BASIC_DEPS) : basic_ho_empty ]
# Header only trivial
[ run test_trivial.cpp : : : <debug-symbols>on <define>BOOST_STACKTRACE_USE_BACKTRACE $(BT_DEPS) : trivial_backtrace_ho ]
[ run test_trivial.cpp : : : <debug-symbols>on <define>BOOST_STACKTRACE_USE_ADDR2LINE $(AD2L_DEPS) : trivial_addr2line_ho ]
[ run test_trivial.cpp : : : <debug-symbols>on <define>BOOST_STACKTRACE_USE_NOOP $(NOOP_DEPS) : trivial_noop_ho ]
[ run test_trivial.cpp : : : <debug-symbols>on $(WIND_DEPS) : trivial_windbg_ho ]
[ run test_trivial.cpp : : : <debug-symbols>on <define>BOOST_STACKTRACE_USE_WINDBG_CACHED $(WICA_DEPS) : trivial_windbg_cached_ho ]
[ run test_trivial.cpp : : : <debug-symbols>on $(FORCE_SYMBOL_EXPORT) $(BASIC_DEPS) : trivial_basic_ho ]
[ run test_trivial.cpp : : : <debug-symbols>on <define>BOOST_STACKTRACE_TEST_NO_DEBUG_AT_ALL $(BASIC_DEPS) : trivial_basic_ho_empty ]
# Test with shared linked implementations with debug symbols
[ run test.cpp : : : <debug-symbols>on <library>.//test_impl_lib_backtrace $(LINKSHARED_BT) : backtrace_lib ]
[ run test.cpp : : : <debug-symbols>on <library>.//test_impl_lib_addr2line $(LINKSHARED_AD2L) : addr2line_lib ]
@@ -96,29 +111,36 @@ test-suite stacktrace_tests
[ run test_noop.cpp : : : <debug-symbols>on <library>.//test_impl_lib_noop $(LINKSHARED_NOOP) : noop_lib ]
[ run test.cpp : : : <debug-symbols>on <library>.//test_impl_lib_basic $(LINKSHARED_BASIC) : basic_lib ]
# Trivial test with shared linked implementations with debug symbols
[ run test_trivial.cpp : : : <debug-symbols>on <library>.//test_impl_lib_backtrace $(LINKSHARED_BT) : trivial_backtrace_lib ]
[ run test_trivial.cpp : : : <debug-symbols>on <library>.//test_impl_lib_addr2line $(LINKSHARED_AD2L) : trivial_addr2line_lib ]
[ run test_trivial.cpp : : : <debug-symbols>on <library>.//test_impl_lib_windbg $(LINKSHARED_WIND) : trivial_windbg_lib ]
[ run test_trivial.cpp : : : <debug-symbols>on <library>.//test_impl_lib_windbg_cached $(LINKSHARED_WIND_CACHED) : trivial_windbg_cached_lib ]
[ run test_trivial.cpp : : : <debug-symbols>on <library>.//test_impl_lib_noop $(LINKSHARED_NOOP) : trivial_noop_lib ]
[ run test_trivial.cpp : : : <debug-symbols>on <library>.//test_impl_lib_basic $(LINKSHARED_BASIC) : trivial_basic_lib ]
# Thread safety with debug symbols
[ run thread_safety_checking.cpp
: : : <debug-symbols>on <library>/boost/thread//boost_thread <library>/boost/timer//boost_timer <library>.//test_impl_lib_backtrace $(LINKSHARED_BT)
: : : <debug-symbols>on <library>.//test_impl_lib_backtrace $(LINKSHARED_BT)
: backtrace_lib_threaded ]
[ run thread_safety_checking.cpp
: : : <debug-symbols>on <library>/boost/thread//boost_thread <library>/boost/timer//boost_timer <library>.//test_impl_lib_windbg $(LINKSHARED_WIND)
: : : <debug-symbols>on <library>.//test_impl_lib_backtrace $(LINKSHARED_BT)
<define>BOOST_STACKTRACE_BACKTRACE_FORCE_STATIC
<library>/boost/optional//boost_optional
: backtrace_lib_threaded_static ]
[ run thread_safety_checking.cpp
: : : <debug-symbols>on <library>.//test_impl_lib_windbg $(LINKSHARED_WIND)
<library>/boost/optional//boost_optional
: windbg_lib_threaded ]
[ run thread_safety_checking.cpp
: : : <debug-symbols>on <library>/boost/thread//boost_thread <library>/boost/timer//boost_timer <library>.//test_impl_lib_windbg_cached $(LINKSHARED_WIND_CACHED)
: : : <debug-symbols>on <library>.//test_impl_lib_windbg_cached $(LINKSHARED_WIND_CACHED)
<library>/boost/optional//boost_optional
: windbg_cached_lib_threaded ]
[ run thread_safety_checking.cpp
: : : <debug-symbols>on <library>/boost/thread//boost_thread <library>/boost/timer//boost_timer <library>.//test_impl_lib_basic $(LINKSHARED_BASIC)
: : : <debug-symbols>on <library>.//test_impl_lib_basic $(LINKSHARED_BASIC)
<library>/boost/optional//boost_optional
: basic_lib_threaded ]
[ run thread_safety_checking.cpp
: : : <debug-symbols>on <library>/boost/thread//boost_thread <library>/boost/timer//boost_timer <library>.//test_impl_lib_windbg
$(LINKSHARED_WIND) <define>BOOST_STACKTRACE_TEST_COM_PREINIT_MT
: windbg_lib_threaded_com_mt ]
[ run thread_safety_checking.cpp
: : : <debug-symbols>on <library>/boost/thread//boost_thread <library>/boost/timer//boost_timer <library>.//test_impl_lib_windbg_cached
$(LINKSHARED_WIND_CACHED) <define>BOOST_STACKTRACE_TEST_COM_PREINIT_ST
: windbg_cached_lib_threaded_com_st ]
##### Tests with disabled debug symbols #####
# Header only tests without debug symbols
@@ -143,67 +165,75 @@ test-suite stacktrace_tests
# Thread safety without debug symbols
[ run thread_safety_checking.cpp
: : : <debug-symbols>off
<library>/boost/thread//boost_thread
<library>/boost/timer//boost_timer
<library>.//test_impl_lib_backtrace_no_dbg
<library>/boost/optional//boost_optional
$(LINKSHARED_BT)
: backtrace_lib_no_dbg_threaded ]
[ run thread_safety_checking.cpp
: : : <debug-symbols>off
<library>/boost/thread//boost_thread
<library>/boost/timer//boost_timer
<library>.//test_impl_lib_windbg_no_dbg
$(LINKSHARED_WIND)
: windbg_lib_no_dbg_threaded ]
[ run thread_safety_checking.cpp
: : : <debug-symbols>off
<library>/boost/thread//boost_thread
<library>/boost/timer//boost_timer
<library>.//test_impl_lib_windbg_cached_no_dbg
$(LINKSHARED_WIND_CACHED)
: windbg_cached_lib_no_dbg_threaded ]
[ run thread_safety_checking.cpp
: : : <debug-symbols>off
<library>/boost/thread//boost_thread
<library>/boost/timer//boost_timer
<library>.//test_impl_lib_basic_no_dbg
$(LINKSHARED_BASIC)
: basic_lib_no_dbg_threaded ]
[ run thread_safety_checking.cpp
: : : <debug-symbols>off
<library>/boost/thread//boost_thread
<library>/boost/timer//boost_timer
<library>.//test_impl_lib_windbg
$(LINKSHARED_WIND)
<define>BOOST_STACKTRACE_TEST_COM_PREINIT_MT
: windbg_lib_threaded_com_mt ]
[ run thread_safety_checking.cpp
: : : <debug-symbols>off
<library>/boost/thread//boost_thread
<library>/boost/timer//boost_timer
<library>.//test_impl_lib_windbg_cached
$(LINKSHARED_WIND_CACHED)
<define>BOOST_STACKTRACE_TEST_COM_PREINIT_ST
: windbg_cached_lib_threaded_com_st ]
[ run test_void_ptr_cast.cpp ]
[ run test_num_conv.cpp ]
[ run test_from_exception_none.cpp : : : $(LINKSHARED_NOOP) <debug-symbols>on : from_exception_none_noop ]
[ run test_from_exception_none.cpp : : : <define>BOOST_STACKTRACE_USE_NOOP $(NOOP_DEPS) <debug-symbols>on : from_exception_none_noop_ho ]
[ run test_from_exception_none.cpp : : : $(LINKSHARED_BASIC) <debug-symbols>on : from_exception_none_basic ]
[ run test_from_exception_none.cpp : : : $(FORCE_SYMBOL_EXPORT) $(BASIC_DEPS) <debug-symbols>on : from_exception_none_basic_ho ]
[ run test_from_exception_none.cpp : : : $(LINKSHARED_BT) <debug-symbols>on : from_exception_none_bt ]
[ run test_from_exception_none.cpp : : : <define>BOOST_STACKTRACE_USE_BACKTRACE $(BT_DEPS) <debug-symbols>on : from_exception_none_bt_ho ]
[ run test_from_exception_none.cpp : : : $(LINKSHARED_WIND) <debug-symbols>on : from_exception_none_windbg ]
[ run test_from_exception_none.cpp : : : <define>BOOST_STACKTRACE_USE_WINDBG $(WIND_DEPS) <debug-symbols>on : from_exception_none_windbg_ho ]
[ run test_from_exception_none.cpp : : : $(LINKSHARED_WIND_CACHED) <debug-symbols>on : from_exception_none_windbg_cached ]
[ run test_from_exception_none.cpp : : : <define>BOOST_STACKTRACE_USE_WINDBG_CACHED $(WICA_DEPS) <debug-symbols>on : from_exception_none_windbg_cached_ho ]
[ run test_from_exception_none.cpp : : : <library>/boost/stacktrace//boost_stacktrace_from_exception $(LINKSHARED_NOOP) <debug-symbols>on : from_exception_disabled_none ]
[ run test_from_exception_none.cpp : : : <library>/boost/stacktrace//boost_stacktrace_from_exception <define>BOOST_STACKTRACE_USE_NOOP $(NOOP_DEPS) : from_exception_disabled_none_ho ]
[ run test_from_exception_none.cpp : : : <library>/boost/stacktrace//boost_stacktrace_from_exception $(LINKSHARED_BASIC) <debug-symbols>on : from_exception_disabled_basic ]
[ run test_from_exception_none.cpp : : : <library>/boost/stacktrace//boost_stacktrace_from_exception $(FORCE_SYMBOL_EXPORT) $(BASIC_DEPS) <debug-symbols>on : from_exception_disabled_basic_ho ]
[ run test_from_exception_none.cpp : : : <library>/boost/stacktrace//boost_stacktrace_from_exception $(LINKSHARED_BT) <debug-symbols>on : from_exception_disabled_bt ]
[ run test_from_exception_none.cpp : : : <library>/boost/stacktrace//boost_stacktrace_from_exception <define>BOOST_STACKTRACE_USE_BACKTRACE $(BT_DEPS) : from_exception_disabled_bt_ho ]
[ run test_from_exception_none.cpp : : : <library>/boost/stacktrace//boost_stacktrace_from_exception $(LINKSHARED_WIND) <debug-symbols>on : from_exception_disabled_windbg ]
[ run test_from_exception_none.cpp : : : <library>/boost/stacktrace//boost_stacktrace_from_exception <define>BOOST_STACKTRACE_USE_WINDBG $(WIND_DEPS) <debug-symbols>on : from_exception_disabled_windbg_ho ]
[ run test_from_exception_none.cpp : : : <library>/boost/stacktrace//boost_stacktrace_from_exception $(LINKSHARED_WIND_CACHED) <debug-symbols>on : from_exception_disabled_windbg_cached ]
[ run test_from_exception_none.cpp : : : <library>/boost/stacktrace//boost_stacktrace_from_exception <define>BOOST_STACKTRACE_USE_WINDBG_CACHED $(WICA_DEPS) <debug-symbols>on : from_exception_disabled_windbg_cached_ho ]
[ link test_from_exception.cpp : <library>/boost/stacktrace//boost_stacktrace_from_exception $(LINKSHARED_BASIC) <debug-symbols>on : from_exception_basic ]
[ run test_from_exception.cpp : : : <library>/boost/stacktrace//boost_stacktrace_from_exception $(LINKSHARED_BT) <debug-symbols>on : from_exception_bt ]
[ run test_from_exception.cpp : : : <library>/boost/stacktrace//boost_stacktrace_from_exception $(LINKSHARED_WIND) <debug-symbols>on : from_exception_windbg ]
[ run test_from_exception.cpp : : : <library>/boost/stacktrace//boost_stacktrace_from_exception $(LINKSHARED_WIND_CACHED) <debug-symbols>on : from_exception_windbg_cached ]
[ link test_from_exception.cpp : <library>/boost/stacktrace//boost_stacktrace_from_exception $(FORCE_SYMBOL_EXPORT) $(BASIC_DEPS) <debug-symbols>on : from_exception_basic_ho ]
[ run test_from_exception.cpp : : : <library>/boost/stacktrace//boost_stacktrace_from_exception <define>BOOST_STACKTRACE_USE_BACKTRACE $(BT_DEPS) <debug-symbols>on : from_exception_bt_ho ]
[ run test_from_exception.cpp : : : <library>/boost/stacktrace//boost_stacktrace_from_exception <define>BOOST_STACKTRACE_USE_WINDBG $(WIND_DEPS) <debug-symbols>on : from_exception_windbg_ho ]
[ run test_from_exception.cpp : : : <library>/boost/stacktrace//boost_stacktrace_from_exception <define>BOOST_STACKTRACE_USE_WINDBG_CACHED $(WICA_DEPS) <debug-symbols>on : from_exception_windbg_cached_ho ]
;
# Assuring that examples compile and run. Adding sources from `examples` directory to the `type_index` test suite.
for local p in [ glob ../example/*.cpp ]
{
local target_name = $(p[1]:B) ;
local additional_dependency = ;
local additional_dependency = <library>/boost/array//boost_array ;
if $(target_name) = "terminate_handler"
{
additional_dependency = <library>/boost/filesystem//boost_filesystem <library>/boost/system//boost_system <target-os>linux:<library>rt ;
additional_dependency += <library>/boost/filesystem//boost_filesystem <library>/boost/system//boost_system <target-os>linux:<library>rt ;
}
if $(target_name) = "throwing_st"
{
additional_dependency = [ requires rtti ] ;
additional_dependency += [ requires rtti ] <library>/boost/exception//boost_exception ;
}
stacktrace_tests += [ run $(p) : : : <debug-symbols>on $(LINKSHARED_BT) $(additional_dependency) : backtrace_$(p2[1]:B) ] ;

View File

@@ -2,23 +2,26 @@
# subject to the Boost Software License, Version 1.0. (See accompanying
# file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#
# Copyright Antony Polukhin 2016-2021.
# Copyright Antony Polukhin, 2016-2025.
#
# See https://svn.boost.org/trac/boost/wiki/TravisCoverals for description of this file
# and how it can be used with Boost libraries.
#
# File revision #5
# File revision #6
init:
- set BRANCH_TO_TEST=%APPVEYOR_REPO_BRANCH% # Change to branch you wish to test. Use %APPVEYOR_REPO_BRANCH% for current branch.
- set BOOST_REMOVE=stacktrace # Remove this folder from lib from full clone of Boost. If you are testing `any` repo, write here `any`.
# boost-local/libs/ folder to put this library into. This may be useful, if you're for example running Travis
# from `Boost.DLL` repo while Boost already has `dll` and with to replace `dll` with content of`Boost.DLL`.
#
# Otherwise just leave the default value - set BOOST_LIBS_FOLDER=%APPVEYOR_PROJECT_NAME%
- set BOOST_LIBS_FOLDER=%APPVEYOR_PROJECT_NAME%
###############################################################################################################
# From this point and below code is same for all the Boost libs
###############################################################################################################
version: 1.64.{build}-{branch}
version: 1.88.{build}-{branch}
# branches to build
branches:
@@ -27,32 +30,57 @@ branches:
skip_tags: true
environment:
matrix:
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
TOOLSET: msvc-14.1 #,clang-win
CXXSTD: 14,17
ADDRMD: 64
#- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
# ADDPATH: C:\cygwin\bin;
# TOOLSET: gcc
# CXXSTD: 03,11,14,1z
#- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
# ADDPATH: C:\cygwin64\bin;
# TOOLSET: gcc
# CXXSTD: 03,11,14,1z
# Waiting for https://github.com/boostorg/system/issues/116
#- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
# ADDPATH: C:\mingw\bin;
# TOOLSET: gcc
# CXXSTD: 03,11,14,1z
#- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
# ADDPATH: C:\mingw-w64\x86_64-7.2.0-posix-seh-rt_v5-rev1\mingw64\bin;
# TOOLSET: gcc
# CXXSTD: 03,11,14,1z
before_build:
- set PATH=%PATH%;C:\\MinGW\\bin
- set BOOST_BRANCH=develop
- if "%APPVEYOR_REPO_BRANCH%" == "master" set BOOST_BRANCH=master
- echo "Testing %APPVEYOR_PROJECT_NAME%"
# Cloning Boost libraries (fast nondeep cloning)
- set BOOST=C:/boost-local
- git init %BOOST%
- git clone -b %BOOST_BRANCH% --depth 10 https://github.com/boostorg/boost.git %BOOST%
- cd %BOOST%
- git remote add --no-tags -t %BRANCH_TO_TEST% origin https://github.com/boostorg/boost.git
- git fetch --depth=1
- git checkout %BRANCH_TO_TEST%
- git submodule update --init --merge --jobs 16
- git remote set-branches --add origin %BRANCH_TO_TEST%
#- git pull --recurse-submodules # Updaes submodules to most recent version. Not required
- rm -rf %BOOST%/libs/%BOOST_REMOVE%
- mv %APPVEYOR_BUILD_FOLDER% %BOOST%/libs/%APPVEYOR_PROJECT_NAME%
- git submodule update --init --depth 10 tools/build tools/boostdep
- rm -rf %BOOST%/libs/%BOOST_LIBS_FOLDER%
- mv -f %APPVEYOR_BUILD_FOLDER% %BOOST%/libs/%BOOST_LIBS_FOLDER%
- python tools/boostdep/depinst/depinst.py --include example --git_args "--depth 10 --jobs 2" %BOOST_LIBS_FOLDER%
build_script:
- call "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" x64
- bootstrap.bat
- cmd /c bootstrap
- b2.exe headers
- cd %BOOST%/libs/%APPVEYOR_PROJECT_NAME%/test
- cd %BOOST%/libs/%BOOST_LIBS_FOLDER%/test
after_build:
before_test:
test_script:
- ..\..\..\b2.exe address-model=32 architecture=x86 toolset=msvc,gcc cxxflags="-DBOOST_TRAVISCI_BUILD" -sBOOST_BUILD_PATH=.
- PATH=%ADDPATH%%PATH%
- if not "%CXXSTD%" == "" set CXXSTD=cxxstd=%CXXSTD%
- if not "%ADDRMD%" == "" set ADDRMD=address-model=%ADDRMD%
- echo "Running command ..\..\..\b2 -j3 toolset=%TOOLSET% %CXXSTD% %ADDRMD% variant=debug,release"
- ..\..\..\b2.exe -j3 toolset=%TOOLSET% %CXXSTD% %ADDRMD% variant=debug,release cxxflags="-DBOOST_TRAVISCI_BUILD"
after_test:
on_success:

View File

@@ -0,0 +1,15 @@
# Copyright 2018-2021 Peter Dimov
# Distributed under the Boost Software License, Version 1.0.
# https://www.boost.org/LICENSE_1_0.txt
cmake_minimum_required(VERSION 3.5...3.20)
project(cmake_install_test LANGUAGES CXX)
find_package(boost_stacktrace REQUIRED)
add_executable(main main.cpp)
target_link_libraries(main Boost::stacktrace)
enable_testing()
add_test(main main)

View File

@@ -0,0 +1,12 @@
// Copyright 2019 Peter Dimov
// Copyright 2022-2025 Antony Polukhin
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt
#include <boost/stacktrace/stacktrace.hpp>
#include <iostream>
int main()
{
std::cout << boost::stacktrace::stacktrace() << std::endl;
}

View File

@@ -0,0 +1,46 @@
# Copyright 2018-2021 Peter Dimov
# Distributed under the Boost Software License, Version 1.0.
# See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt
cmake_minimum_required(VERSION 3.5...3.20)
project(cmake_subdir_test LANGUAGES CXX)
# Put boost_stacktrace_*.dll in the same directory as main.exe
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
add_subdirectory(../.. boostorg/stacktrace)
# boostdep --brief stacktrace
set(deps
# Primary dependencies
assert
config
container_hash
core
predef
winapi
# Secondary dependencies
describe
mp11
static_assert
throw_exception
)
foreach(dep IN LISTS deps)
add_subdirectory(../../../${dep} boostorg/${dep})
endforeach()
add_executable(main main.cpp)
target_link_libraries(main Boost::stacktrace)
enable_testing()
add_test(main main)

View File

@@ -0,0 +1,12 @@
// Copyright 2019 Peter Dimov
// Copyright 2022-2025 Antony Polukhin
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt
#include <boost/stacktrace/stacktrace.hpp>
#include <iostream>
int main()
{
std::cout << boost::stacktrace::stacktrace() << std::endl;
}

View File

@@ -1,4 +1,4 @@
// Copyright Antony Polukhin, 2016-2021.
// Copyright Antony Polukhin, 2016-2025.
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
@@ -8,6 +8,7 @@
#include <boost/stacktrace.hpp>
#include <stdexcept>
#include <fstream>
#include <iostream>
#include <sstream>
#include <cctype>
@@ -257,7 +258,57 @@ void test_empty_basic_stacktrace() {
BOOST_TEST(!(st > st_t(0, 0)));
}
int main() {
void test_stacktrace_limits()
{
BOOST_TEST_EQ(boost::stacktrace::stacktrace(0, 1).size(), 1);
BOOST_TEST_EQ(boost::stacktrace::stacktrace(1, 1).size(), 1);
}
std::size_t get_file_size(const char* file_name) {
std::ifstream file(file_name, std::ios::binary | std::ios::ate);
const auto file_size = file.tellg();
BOOST_TEST(file_size > 0);
return static_cast<std::size_t>(file_size);
}
uintptr_t get_address_from_frame(const std::string& frame) {
std::size_t address = 0;
std::string hex_address;
std::size_t pos = frame.find("0x");
if (pos != std::string::npos) {
// Extract the hex address substring
hex_address = frame.substr(pos + 2); // Skip "0x"
// Convert hex string to std::size_t
std::stringstream ss;
ss << std::hex << hex_address;
ss >> address;
}
return address;
}
void test_relative_virtual_address(const char* file_path)
{
const auto frame = to_string(boost::stacktrace::stacktrace(0, 1).as_vector().front());
// Skip the test if the frame does not contain an address
if (frame.find("0x") == std::string::npos) {
return;
}
const auto file_size = get_file_size(file_path);
BOOST_TEST(file_size > 0);
const auto address = get_address_from_frame(frame);
BOOST_TEST(address > 0);
// Verify that the address is within the binary
BOOST_TEST(address <= file_size);
}
int main(const int, const char* argv[]) {
test_deeply_nested_namespaces();
test_frames_string_data_validity();
test_nested<15>();
@@ -275,8 +326,9 @@ int main() {
test_comparisons_base(make_some_stacktrace1(), make_some_stacktrace2());
test_nested<260>(false);
BOOST_TEST(boost::stacktrace::stacktrace(0, 1).size() == 1);
BOOST_TEST(boost::stacktrace::stacktrace(1, 1).size() == 1);
test_stacktrace_limits();
test_relative_virtual_address(argv[0]);
return boost::report_errors();
}

View File

@@ -0,0 +1,209 @@
// Copyright Antony Polukhin, 2023-2025.
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#include <boost/stacktrace.hpp>
#include <iostream>
#include <thread>
#include <boost/core/lightweight_test.hpp>
namespace boost { namespace stacktrace { namespace impl {
void assert_no_pending_traces() noexcept;
}}}
using boost::stacktrace::stacktrace;
struct test_no_pending_on_finish {
~test_no_pending_on_finish() {
boost::stacktrace::impl::assert_no_pending_traces();
}
};
BOOST_NOINLINE BOOST_SYMBOL_VISIBLE void in_test_throw_1(const char* msg) {
std::string new_msg{msg};
throw std::runtime_error(new_msg);
}
BOOST_NOINLINE BOOST_SYMBOL_VISIBLE void in_test_throw_2(const char* msg) {
std::string new_msg{msg};
throw std::logic_error(new_msg);
}
BOOST_NOINLINE BOOST_SYMBOL_VISIBLE void in_test_rethrow_1(const char* msg) {
try {
in_test_throw_1(msg);
} catch (const std::exception&) {
throw;
}
}
BOOST_NOINLINE BOOST_SYMBOL_VISIBLE void in_test_rethrow_2(const char* msg) {
try {
in_test_throw_2(msg);
} catch (const std::exception&) {
try {
in_test_throw_1(msg);
} catch (const std::exception&) {}
throw;
}
}
BOOST_NOINLINE BOOST_SYMBOL_VISIBLE void test_no_exception() {
auto trace = stacktrace::from_current_exception();
BOOST_TEST(!trace);
}
BOOST_NOINLINE BOOST_SYMBOL_VISIBLE void test_trace_from_exception() {
// const test_no_pending_on_finish guard{}; // something strange
try {
in_test_throw_1("testing basic");
} catch (const std::exception&) {
auto trace = stacktrace::from_current_exception();
BOOST_TEST(trace);
std::cout << "Tarce in test_trace_from_exception(): " << trace << '\n';
BOOST_TEST(to_string(trace).find("in_test_throw_1") != std::string::npos);
}
}
BOOST_NOINLINE BOOST_SYMBOL_VISIBLE void test_after_other_exception() {
try {
in_test_throw_1("test_other_exception_active");
} catch (const std::exception&) {
try {
in_test_throw_2("test_other_exception_active 2");
} catch (const std::exception&) {}
auto trace = stacktrace::from_current_exception();
BOOST_TEST(trace);
std::cout << "Tarce in test_after_other_exception(): " << trace;
BOOST_TEST(to_string(trace).find("in_test_throw_1") != std::string::npos);
BOOST_TEST(to_string(trace).find("in_test_throw_2") == std::string::npos);
}
}
BOOST_NOINLINE BOOST_SYMBOL_VISIBLE void test_rethrow() {
try {
in_test_rethrow_1("test rethrow");
} catch (const std::exception&) {
auto trace = stacktrace::from_current_exception();
BOOST_TEST(trace);
std::cout << "Tarce in test_rethrow(): " << trace << '\n';
BOOST_TEST(to_string(trace).find("in_test_throw_1") != std::string::npos);
BOOST_TEST(to_string(trace).find("in_test_rethrow_1") != std::string::npos);
}
}
BOOST_NOINLINE BOOST_SYMBOL_VISIBLE void test_rethrow_after_other_exception() {
try {
in_test_rethrow_2("test_rethrow_after_other_exception");
} catch (const std::exception&) {
auto trace = stacktrace::from_current_exception();
BOOST_TEST(trace);
std::cout << "Tarce in test_rethrow_after_other_exception(): " << trace << '\n';
BOOST_TEST(to_string(trace).find("in_test_throw_1") == std::string::npos);
BOOST_TEST(to_string(trace).find("in_test_throw_2") != std::string::npos);
BOOST_TEST(to_string(trace).find("in_test_rethrow_2") != std::string::npos);
}
}
BOOST_NOINLINE BOOST_SYMBOL_VISIBLE void test_nested() {
try {
in_test_throw_1("test_other_exception_active");
} catch (const std::exception&) {
try {
in_test_throw_2("test_other_exception_active 2");
} catch (const std::exception&) {
auto trace = stacktrace::from_current_exception();
BOOST_TEST(trace);
std::cout << "Tarce in test_nested(): " << trace << '\n';
BOOST_TEST(to_string(trace).find("in_test_throw_1") == std::string::npos);
BOOST_TEST(to_string(trace).find("in_test_throw_2") != std::string::npos);
}
}
}
BOOST_NOINLINE BOOST_SYMBOL_VISIBLE void test_rethrow_nested() {
std::exception_ptr ptr;
try {
in_test_throw_1("test_other_exception_active");
} catch (const std::exception&) {
try {
in_test_throw_2("test_other_exception_active 2");
} catch (const std::exception&) {
ptr = std::current_exception();
}
}
try {
std::rethrow_exception(ptr);
} catch (...) {
auto trace = stacktrace::from_current_exception();
BOOST_TEST(trace);
std::cout << "Tarce in test_rethrow_nested(): " << trace << '\n';
BOOST_TEST(to_string(trace).find("in_test_throw_1") == std::string::npos);
#if defined(BOOST_MSVC)
BOOST_TEST(to_string(trace).find("in_test_throw_2") == std::string::npos);
#else
BOOST_TEST(to_string(trace).find("in_test_throw_2") != std::string::npos);
#endif
}
}
BOOST_NOINLINE BOOST_SYMBOL_VISIBLE void test_from_other_thread() {
// MinGW error: 'thread' is not a member of 'std'
#ifndef __MINGW32__
std::exception_ptr ptr;
std::thread t([&ptr]{
try {
in_test_throw_1("test_other_exception_active");
} catch (const std::exception&) {
try {
in_test_throw_2("test_other_exception_active 2");
} catch (const std::exception&) {
ptr = std::current_exception();
}
}
});
t.join();
try {
std::rethrow_exception(ptr);
} catch (...) {
auto trace = stacktrace::from_current_exception();
BOOST_TEST(trace);
std::cout << "Tarce in test_rethrow_nested(): " << trace << '\n';
BOOST_TEST(to_string(trace).find("in_test_throw_1") == std::string::npos);
#if defined(BOOST_MSVC)
BOOST_TEST(to_string(trace).find("in_test_throw_2") == std::string::npos);
#else
BOOST_TEST(to_string(trace).find("in_test_throw_2") != std::string::npos);
#endif
}
#endif
}
int main() {
const test_no_pending_on_finish guard{};
BOOST_TEST(boost::stacktrace::this_thread::get_capture_stacktraces_at_throw());
test_no_exception();
test_trace_from_exception();
test_after_other_exception();
test_rethrow();
test_rethrow_after_other_exception();
test_nested();
test_rethrow_nested();
test_from_other_thread();
return boost::report_errors();
}

View File

@@ -0,0 +1,34 @@
// Copyright Antony Polukhin, 2023-2025.
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#include <boost/stacktrace.hpp>
#include <boost/core/lightweight_test.hpp>
using boost::stacktrace::stacktrace;
BOOST_NOINLINE BOOST_SYMBOL_VISIBLE void in_test_throw_1(const char* msg) {
std::string new_msg{msg};
throw std::runtime_error(new_msg);
}
BOOST_NOINLINE BOOST_SYMBOL_VISIBLE void test_no_trace_from_exception() {
try {
in_test_throw_1("testing basic");
} catch (const std::exception&) {
auto trace = stacktrace::from_current_exception();
BOOST_TEST(!trace);
}
}
int main() {
boost::stacktrace::this_thread::set_capture_stacktraces_at_throw(false);
BOOST_TEST(!boost::stacktrace::this_thread::get_capture_stacktraces_at_throw());
test_no_trace_from_exception();
return boost::report_errors();
}

View File

@@ -1,4 +1,4 @@
// Copyright Antony Polukhin, 2016-2021.
// Copyright Antony Polukhin, 2016-2025.
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at

View File

@@ -1,4 +1,4 @@
// Copyright Antony Polukhin, 2016-2021.
// Copyright Antony Polukhin, 2016-2025.
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at

View File

@@ -1,4 +1,4 @@
// Copyright Antony Polukhin, 2016-2021.
// Copyright Antony Polukhin, 2016-2025.
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at

View File

@@ -1,4 +1,4 @@
// Copyright Antony Polukhin, 2016-2021.
// Copyright Antony Polukhin, 2016-2025.
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at

15
test/test_trivial.cpp Normal file
View File

@@ -0,0 +1,15 @@
// Copyright Antony Polukhin, 2022-2025.
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
// See https://github.com/boostorg/stacktrace/issues/116
#include <boost/stacktrace/stacktrace.hpp>
#include <iostream>
int main() {
std::cout << boost::stacktrace::stacktrace() << std::endl;
}

View File

@@ -1,4 +1,4 @@
// Copyright Antony Polukhin, 2016-2021.
// Copyright Antony Polukhin, 2016-2025.
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
@@ -7,15 +7,14 @@
#include "test_impl.hpp"
#include <boost/stacktrace/stacktrace_fwd.hpp>
#include <chrono>
#include <sstream>
#include <thread>
#include <boost/stacktrace.hpp>
#include <boost/thread.hpp>
#include <boost/optional.hpp>
#include <boost/core/lightweight_test.hpp>
#include <boost/timer/timer.hpp>
using boost::stacktrace::stacktrace;
@@ -41,32 +40,21 @@ void main_test_loop() {
}
}
#if defined(BOOST_STACKTRACE_TEST_COM_PREINIT_MT) || defined(BOOST_STACKTRACE_TEST_COM_PREINIT_ST)
# include <windows.h>
# include "dbgeng.h"
#endif
int main() {
#if defined(BOOST_STACKTRACE_TEST_COM_PREINIT_MT)
::CoInitializeEx(0, COINIT_MULTITHREADED);
#elif defined(BOOST_STACKTRACE_TEST_COM_PREINIT_ST)
::CoInitializeEx(0, COINIT_APARTMENTTHREADED);
#endif
const auto t = std::chrono::steady_clock::now();
boost::timer::auto_cpu_timer t;
boost::thread t1(main_test_loop);
boost::thread t2(main_test_loop);
boost::thread t3(main_test_loop);
std::thread t1(main_test_loop);
std::thread t2(main_test_loop);
std::thread t3(main_test_loop);
main_test_loop();
t1.join();
t2.join();
t3.join();
#if defined(BOOST_STACKTRACE_TEST_COM_PREINIT_MT) || defined(BOOST_STACKTRACE_TEST_COM_PREINIT_ST)
::CoUninitialize();
#endif
const auto elapsed = t - std::chrono::steady_clock::now();
std::cout << "Elapsed: " << std::chrono::duration_cast<std::chrono::milliseconds>(
elapsed
). count() << "ms";
return boost::report_errors();
}