Skip to content

Commit 12e07fc

Browse files
authored
CI fixes (#153)
* Update thread_safety_checking.cpp to use Standard Library types * Remove MinGW runs due to boostorg/system#116 * Delete the shared memory example sources
1 parent 95caaea commit 12e07fc

6 files changed

Lines changed: 28 additions & 155 deletions

File tree

.github/workflows/ci.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ jobs:
2727
- toolset: gcc-9
2828
cxxstd: "03,11,14,17,2a"
2929
os: ubuntu-22.04
30-
- toolset: clang
31-
compiler: clang++-14
30+
- toolset: clang-15
3231
cxxstd: "03,11,14,17,2a"
3332
os: ubuntu-22.04
3433
# TODO: fix and uncomment

doc/stacktrace.qbk

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -295,43 +295,6 @@ Terminate called:
295295

296296
[endsect]
297297

298-
[/
299-
[section Store stacktraces into shared memory]
300-
301-
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.
302-
303-
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:
304-
305-
[getting_started_terminate_handlers_shmem]
306-
307-
After registering signal handlers and catching a signal, we may print stacktrace dumps on program restart:
308-
309-
[getting_started_on_program_restart_shmem]
310-
311-
The program output will be the following:
312-
313-
```
314-
Previous run crashed and left trace in shared memory:
315-
0# 0x00007FD51C7218EF
316-
1# my_signal_handler2(int) at ../example/terminate_handler.cpp:68
317-
2# 0x00007FD51B833CB0
318-
3# 0x00007FD51B833C37
319-
4# 0x00007FD51B837028
320-
5# 0x00007FD51BE44BBD
321-
6# 0x00007FD51BE42B96
322-
7# 0x00007FD51BE42BE1
323-
8# bar(int) at ../example/terminate_handler.cpp:18
324-
9# foo(int) at ../example/terminate_handler.cpp:22
325-
10# bar(int) at ../example/terminate_handler.cpp:14
326-
11# foo(int) at ../example/terminate_handler.cpp:22
327-
12# run_3(char const**) at ../example/terminate_handler.cpp:152
328-
13# main at ../example/terminate_handler.cpp:207
329-
14# 0x00007FD51B81EF45
330-
15# 0x0000000000402999
331-
```
332-
333-
[endsect]
334-
]
335298

336299
[endsect]
337300

example/terminate_handler.cpp

Lines changed: 2 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -63,33 +63,12 @@ void my_terminate_handler() {
6363

6464
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
6565

66-
BOOST_CONSTEXPR_OR_CONST std::size_t shared_memory_size = 4096 * 8;
67-
68-
//[getting_started_terminate_handlers_shmem
69-
#include <boost/stacktrace.hpp>
70-
#include <boost/interprocess/shared_memory_object.hpp>
71-
#include <boost/interprocess/mapped_region.hpp>
72-
73-
boost::interprocess::shared_memory_object g_shm; // inited at program start
74-
boost::interprocess::mapped_region g_region; // inited at program start
75-
76-
77-
void my_signal_handler2(int signum) {
78-
::signal(signum, SIG_DFL);
79-
void** f = static_cast<void**>(g_region.get_address());
80-
*f = reinterpret_cast<void*>(1); // Setting flag that shared memory now contains stacktrace.
81-
boost::stacktrace::safe_dump_to(f + 1, g_region.get_size() - sizeof(void*));
82-
83-
::raise(SIGABRT);
84-
}
85-
//]
86-
8766
#include <iostream> // std::cerr
8867
#include <fstream> // std::ifstream
8968
#include <boost/filesystem/path.hpp>
9069
#include <boost/filesystem/operations.hpp>
9170

92-
71+
#ifndef BOOST_WINDOWS
9372
inline void copy_and_run(const char* exec_name, char param, bool not_null) {
9473
std::cout << "Running with param " << param << std::endl;
9574
boost::filesystem::path command = exec_name;
@@ -110,6 +89,7 @@ inline void copy_and_run(const char* exec_name, char param, bool not_null) {
11089
std::exit(ret);
11190
}
11291
}
92+
#endif
11393

11494
int run_0(const char* /*argv*/[]) {
11595
//[getting_started_setup_terminate_handlers
@@ -160,67 +140,6 @@ int run_2(const char* argv[]) {
160140
return 0;
161141
}
162142

163-
164-
int run_3(const char* /*argv*/[]) {
165-
using namespace boost::interprocess;
166-
{
167-
shared_memory_object shm_obj(open_or_create, "shared_memory", read_write);
168-
shm_obj.swap(g_shm);
169-
}
170-
g_shm.truncate(shared_memory_size);
171-
172-
{
173-
mapped_region m(g_shm, read_write, 0, shared_memory_size);
174-
m.swap(g_region);
175-
}
176-
void** f = static_cast<void**>(g_region.get_address());
177-
*f = 0;
178-
179-
::signal(SIGSEGV, &my_signal_handler2);
180-
::signal(SIGABRT, &my_signal_handler2);
181-
foo(5);
182-
return 31;
183-
}
184-
185-
int run_4(const char* argv[]) {
186-
using namespace boost::interprocess;
187-
{
188-
shared_memory_object shm_obj(open_only, "shared_memory", read_write);
189-
shm_obj.swap(g_shm);
190-
}
191-
192-
{
193-
mapped_region m(g_shm, read_write, 0, shared_memory_size);
194-
m.swap(g_region);
195-
}
196-
197-
//[getting_started_on_program_restart_shmem
198-
void** f = static_cast<void**>(g_region.get_address());
199-
if (*f) { // Checking if memory contains stacktrace.
200-
boost::stacktrace::stacktrace st
201-
= boost::stacktrace::stacktrace::from_dump(f + 1, g_region.get_size() - sizeof(bool));
202-
203-
std::cout << "Previous run crashed and left trace in shared memory:\n" << st << std::endl;
204-
*f = 0; /*<-*/
205-
shared_memory_object::remove("shared_memory");
206-
if (std::string(argv[0]).find("noop") == std::string::npos) {
207-
if (!st) {
208-
return 43;
209-
}
210-
} else {
211-
if (st) {
212-
return 44;
213-
}
214-
}
215-
} else {
216-
return 42; /*->*/
217-
}
218-
//]
219-
220-
221-
return 0;
222-
}
223-
224143
#include <sstream>
225144

226145
int test_inplace() {
@@ -335,10 +254,6 @@ int main(int argc, const char* argv[]) {
335254
// We are copying files to make sure that stacktrace printing works independently from executable name
336255
copy_and_run(argv[0], '1', true);
337256
copy_and_run(argv[0], '2', false);
338-
339-
// There are some issues with async-safety of shared memory writes on Windows.
340-
copy_and_run(argv[0], '3', true);
341-
copy_and_run(argv[0], '4', false);
342257
#endif
343258

344259
return test_inplace();
@@ -347,9 +262,6 @@ int main(int argc, const char* argv[]) {
347262
switch (argv[1][0]) {
348263
case '0': return run_0(argv);
349264
case '1': return run_1(argv);
350-
case '2': return run_2(argv);
351-
case '3': return run_3(argv);
352-
case '4': return run_4(argv);
353265
}
354266

355267
return 404;

test/Jamfile.v2

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -117,20 +117,20 @@ test-suite stacktrace_tests
117117

118118
# Thread safety with debug symbols
119119
[ run thread_safety_checking.cpp
120-
: : : <debug-symbols>on <library>/boost/thread//boost_thread <library>/boost/timer//boost_timer <library>.//test_impl_lib_backtrace $(LINKSHARED_BT)
120+
: : : <debug-symbols>on <library>.//test_impl_lib_backtrace $(LINKSHARED_BT)
121121
: backtrace_lib_threaded ]
122122
[ run thread_safety_checking.cpp
123-
: : : <debug-symbols>on <library>/boost/thread//boost_thread <library>/boost/timer//boost_timer <library>.//test_impl_lib_backtrace $(LINKSHARED_BT)
123+
: : : <debug-symbols>on <library>.//test_impl_lib_backtrace $(LINKSHARED_BT)
124124
<define>BOOST_STACKTRACE_BACKTRACE_FORCE_STATIC
125125
: backtrace_lib_threaded_static ]
126126
[ run thread_safety_checking.cpp
127-
: : : <debug-symbols>on <library>/boost/thread//boost_thread <library>/boost/timer//boost_timer <library>.//test_impl_lib_windbg $(LINKSHARED_WIND)
127+
: : : <debug-symbols>on <library>.//test_impl_lib_windbg $(LINKSHARED_WIND)
128128
: windbg_lib_threaded ]
129129
[ run thread_safety_checking.cpp
130-
: : : <debug-symbols>on <library>/boost/thread//boost_thread <library>/boost/timer//boost_timer <library>.//test_impl_lib_windbg_cached $(LINKSHARED_WIND_CACHED)
130+
: : : <debug-symbols>on <library>.//test_impl_lib_windbg_cached $(LINKSHARED_WIND_CACHED)
131131
: windbg_cached_lib_threaded ]
132132
[ run thread_safety_checking.cpp
133-
: : : <debug-symbols>on <library>/boost/thread//boost_thread <library>/boost/timer//boost_timer <library>.//test_impl_lib_basic $(LINKSHARED_BASIC)
133+
: : : <debug-symbols>on <library>.//test_impl_lib_basic $(LINKSHARED_BASIC)
134134
: basic_lib_threaded ]
135135

136136
##### Tests with disabled debug symbols #####
@@ -157,29 +157,21 @@ test-suite stacktrace_tests
157157
# Thread safety without debug symbols
158158
[ run thread_safety_checking.cpp
159159
: : : <debug-symbols>off
160-
<library>/boost/thread//boost_thread
161-
<library>/boost/timer//boost_timer
162160
<library>.//test_impl_lib_backtrace_no_dbg
163161
$(LINKSHARED_BT)
164162
: backtrace_lib_no_dbg_threaded ]
165163
[ run thread_safety_checking.cpp
166164
: : : <debug-symbols>off
167-
<library>/boost/thread//boost_thread
168-
<library>/boost/timer//boost_timer
169165
<library>.//test_impl_lib_windbg_no_dbg
170166
$(LINKSHARED_WIND)
171167
: windbg_lib_no_dbg_threaded ]
172168
[ run thread_safety_checking.cpp
173169
: : : <debug-symbols>off
174-
<library>/boost/thread//boost_thread
175-
<library>/boost/timer//boost_timer
176170
<library>.//test_impl_lib_windbg_cached_no_dbg
177171
$(LINKSHARED_WIND_CACHED)
178172
: windbg_cached_lib_no_dbg_threaded ]
179173
[ run thread_safety_checking.cpp
180174
: : : <debug-symbols>off
181-
<library>/boost/thread//boost_thread
182-
<library>/boost/timer//boost_timer
183175
<library>.//test_impl_lib_basic_no_dbg
184176
$(LINKSHARED_BASIC)
185177
: basic_lib_no_dbg_threaded ]

test/appveyor.yml

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ skip_tags: true
3333
environment:
3434
matrix:
3535
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
36-
TOOLSET: msvc-14.1 # ,clang-win
36+
TOOLSET: msvc-14.1 #,clang-win
3737
CXXSTD: 14,17
3838
ADDRMD: 64
3939
#- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
@@ -44,10 +44,11 @@ environment:
4444
# ADDPATH: C:\cygwin64\bin;
4545
# TOOLSET: gcc
4646
# CXXSTD: 03,11,14,1z
47-
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
48-
ADDPATH: C:\mingw\bin;
49-
TOOLSET: gcc
50-
CXXSTD: 03,11,14,1z
47+
# Waiting for https://github.com/boostorg/system/issues/116
48+
#- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
49+
# ADDPATH: C:\mingw\bin;
50+
# TOOLSET: gcc
51+
# CXXSTD: 03,11,14,1z
5152
#- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
5253
# ADDPATH: C:\mingw-w64\x86_64-7.2.0-posix-seh-rt_v5-rev1\mingw64\bin;
5354
# TOOLSET: gcc
@@ -61,7 +62,10 @@ before_build:
6162
- set BOOST=C:/boost-local
6263
- git clone -b %BOOST_BRANCH% --depth 10 https://github.com/boostorg/boost.git %BOOST%
6364
- cd %BOOST%
64-
- git submodule update --init --depth 10 tools/build tools/boostdep libs/filesystem libs/interprocess
65+
- git submodule update --init --depth 10 tools/build tools/boostdep
66+
libs/filesystem libs/atomic libs/system libs/interprocess libs/array
67+
libs/iterator libs/detail libs/exception libs/smart_ptr libs/mpl
68+
libs/align libs/container libs/tuple libs/intrusive libs/scope
6569

6670
- rm -rf %BOOST%/libs/%BOOST_LIBS_FOLDER%
6771
- mv -f %APPVEYOR_BUILD_FOLDER% %BOOST%/libs/%BOOST_LIBS_FOLDER%

test/thread_safety_checking.cpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,14 @@
77
#include "test_impl.hpp"
88
#include <boost/stacktrace/stacktrace_fwd.hpp>
99

10+
#include <chrono>
1011
#include <sstream>
12+
#include <thread>
1113

1214
#include <boost/stacktrace.hpp>
13-
#include <boost/thread.hpp>
1415
#include <boost/optional.hpp>
1516
#include <boost/core/lightweight_test.hpp>
1617

17-
#include <boost/timer/timer.hpp>
18-
1918
using boost::stacktrace::stacktrace;
2019

2120

@@ -42,16 +41,20 @@ void main_test_loop() {
4241
}
4342

4443
int main() {
45-
boost::timer::auto_cpu_timer t;
44+
const auto t = std::chrono::steady_clock::now();
4645

47-
boost::thread t1(main_test_loop);
48-
boost::thread t2(main_test_loop);
49-
boost::thread t3(main_test_loop);
46+
std::thread t1(main_test_loop);
47+
std::thread t2(main_test_loop);
48+
std::thread t3(main_test_loop);
5049
main_test_loop();
5150

5251
t1.join();
5352
t2.join();
5453
t3.join();
5554

55+
const auto elapsed = t - std::chrono::steady_clock::now();
56+
std::cout << "Elapsed: " << std::chrono::duration_cast<std::chrono::milliseconds>(
57+
elapsed
58+
). count() << "ms";
5659
return boost::report_errors();
5760
}

0 commit comments

Comments
 (0)