Skip to content

Commit 32c483d

Browse files
committed
Added debug code to print backtrace under OpenBSD.
1 parent f979cc7 commit 32c483d

4 files changed

Lines changed: 253 additions & 1 deletion

File tree

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -800,7 +800,7 @@ jobs:
800800
copyback: false
801801
envs: "LANG LIBRARY DEFAULT_BUILD_VARIANT BUILD_JOBS GCC_TOOLCHAIN_ROOT"
802802
prepare: |
803-
pkg_add bash
803+
pkg_add bash gdb
804804
run: |
805805
uname -mrs
806806
sysctl hw.model

test/threads/thread/constr/FArgs_pass.cpp

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,90 @@
2525
#include <boost/core/lightweight_test.hpp>
2626
#include <boost/config.hpp>
2727

28+
#if defined(__OpenBSD__)
29+
30+
#include <signal.h>
31+
#include <unistd.h>
32+
#include <spawn.h>
33+
34+
class signal_handler
35+
{
36+
public:
37+
signal_handler()
38+
{
39+
struct sigaction act = {};
40+
act.sa_flags = SA_SIGINFO | SA_RESTART;
41+
sigemptyset(&act.sa_mask);
42+
sigaddset(&act.sa_mask, SIGSEGV);
43+
sigaddset(&act.sa_mask, SIGFPE);
44+
sigaddset(&act.sa_mask, SIGILL);
45+
46+
act.sa_sigaction = &signal_handler::on_signal;
47+
48+
sigaction(SIGSEGV, &act, nullptr);
49+
sigaction(SIGFPE, &act, nullptr);
50+
sigaction(SIGILL, &act, nullptr);
51+
}
52+
53+
private:
54+
static void on_signal(int sig, siginfo_t* sig_info, void* context)
55+
{
56+
char attach_command_arg[128] = "--eval-command=attach ";
57+
const char* cmdline[] =
58+
{
59+
"/usr/bin/gdb",
60+
"--batch",
61+
"--eval-command=set pagination off",
62+
attach_command_arg,
63+
"--eval-command=info thread",
64+
"--eval-command=thread apply all bt",
65+
"--eval-command=kill",
66+
nullptr
67+
};
68+
69+
pid_t self_pid = getpid();
70+
print_pid(attach_command_arg + 22, self_pid);
71+
72+
int res = posix_spawn(nullptr, cmdline[0], nullptr, nullptr, const_cast< char* const* >(cmdline), nullptr);
73+
if (res == 0)
74+
{
75+
kill(self_pid, SIGSTOP);
76+
}
77+
78+
std::abort();
79+
}
80+
81+
static char* print_pid(char* p, unsigned int pid)
82+
{
83+
char* b = p;
84+
do
85+
{
86+
*p = '0' + pid % 10u;
87+
pid /= 10u;
88+
++p;
89+
}
90+
while (pid > 0);
91+
92+
char* const res = p;
93+
*p-- = '\0';
94+
95+
while (p > b)
96+
{
97+
char c = *b;
98+
*b = *p;
99+
*p = c;
100+
++b;
101+
--p;
102+
}
103+
104+
return res;
105+
}
106+
};
107+
108+
static signal_handler g_sig_handler;
109+
110+
#endif // defined(__OpenBSD__)
111+
28112
thread_local unsigned throw_one = 0xFFFF;
29113
thread_local unsigned operator_new_recursion_level = 0u;
30114

test/threads/thread/constr/F_pass.cpp

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,90 @@
2525
#include <boost/core/lightweight_test.hpp>
2626
#include <boost/config.hpp>
2727

28+
#if defined(__OpenBSD__)
29+
30+
#include <signal.h>
31+
#include <unistd.h>
32+
#include <spawn.h>
33+
34+
class signal_handler
35+
{
36+
public:
37+
signal_handler()
38+
{
39+
struct sigaction act = {};
40+
act.sa_flags = SA_SIGINFO | SA_RESTART;
41+
sigemptyset(&act.sa_mask);
42+
sigaddset(&act.sa_mask, SIGSEGV);
43+
sigaddset(&act.sa_mask, SIGFPE);
44+
sigaddset(&act.sa_mask, SIGILL);
45+
46+
act.sa_sigaction = &signal_handler::on_signal;
47+
48+
sigaction(SIGSEGV, &act, nullptr);
49+
sigaction(SIGFPE, &act, nullptr);
50+
sigaction(SIGILL, &act, nullptr);
51+
}
52+
53+
private:
54+
static void on_signal(int sig, siginfo_t* sig_info, void* context)
55+
{
56+
char attach_command_arg[128] = "--eval-command=attach ";
57+
const char* cmdline[] =
58+
{
59+
"/usr/bin/gdb",
60+
"--batch",
61+
"--eval-command=set pagination off",
62+
attach_command_arg,
63+
"--eval-command=info thread",
64+
"--eval-command=thread apply all bt",
65+
"--eval-command=kill",
66+
nullptr
67+
};
68+
69+
pid_t self_pid = getpid();
70+
print_pid(attach_command_arg + 22, self_pid);
71+
72+
int res = posix_spawn(nullptr, cmdline[0], nullptr, nullptr, const_cast< char* const* >(cmdline), nullptr);
73+
if (res == 0)
74+
{
75+
kill(self_pid, SIGSTOP);
76+
}
77+
78+
std::abort();
79+
}
80+
81+
static char* print_pid(char* p, unsigned int pid)
82+
{
83+
char* b = p;
84+
do
85+
{
86+
*p = '0' + pid % 10u;
87+
pid /= 10u;
88+
++p;
89+
}
90+
while (pid > 0);
91+
92+
char* const res = p;
93+
*p-- = '\0';
94+
95+
while (p > b)
96+
{
97+
char c = *b;
98+
*b = *p;
99+
*p = c;
100+
++b;
101+
--p;
102+
}
103+
104+
return res;
105+
}
106+
};
107+
108+
static signal_handler g_sig_handler;
109+
110+
#endif // defined(__OpenBSD__)
111+
28112
thread_local unsigned throw_one = 0xFFFF;
29113
thread_local unsigned operator_new_recursion_level = 0u;
30114

test/threads/thread/constr/lambda_pass.cpp

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,90 @@
2727

2828
#if ! defined BOOST_NO_CXX11_LAMBDAS
2929

30+
#if defined(__OpenBSD__)
31+
32+
#include <signal.h>
33+
#include <unistd.h>
34+
#include <spawn.h>
35+
36+
class signal_handler
37+
{
38+
public:
39+
signal_handler()
40+
{
41+
struct sigaction act = {};
42+
act.sa_flags = SA_SIGINFO | SA_RESTART;
43+
sigemptyset(&act.sa_mask);
44+
sigaddset(&act.sa_mask, SIGSEGV);
45+
sigaddset(&act.sa_mask, SIGFPE);
46+
sigaddset(&act.sa_mask, SIGILL);
47+
48+
act.sa_sigaction = &signal_handler::on_signal;
49+
50+
sigaction(SIGSEGV, &act, nullptr);
51+
sigaction(SIGFPE, &act, nullptr);
52+
sigaction(SIGILL, &act, nullptr);
53+
}
54+
55+
private:
56+
static void on_signal(int sig, siginfo_t* sig_info, void* context)
57+
{
58+
char attach_command_arg[128] = "--eval-command=attach ";
59+
const char* cmdline[] =
60+
{
61+
"/usr/bin/gdb",
62+
"--batch",
63+
"--eval-command=set pagination off",
64+
attach_command_arg,
65+
"--eval-command=info thread",
66+
"--eval-command=thread apply all bt",
67+
"--eval-command=kill",
68+
nullptr
69+
};
70+
71+
pid_t self_pid = getpid();
72+
print_pid(attach_command_arg + 22, self_pid);
73+
74+
int res = posix_spawn(nullptr, cmdline[0], nullptr, nullptr, const_cast< char* const* >(cmdline), nullptr);
75+
if (res == 0)
76+
{
77+
kill(self_pid, SIGSTOP);
78+
}
79+
80+
std::abort();
81+
}
82+
83+
static char* print_pid(char* p, unsigned int pid)
84+
{
85+
char* b = p;
86+
do
87+
{
88+
*p = '0' + pid % 10u;
89+
pid /= 10u;
90+
++p;
91+
}
92+
while (pid > 0);
93+
94+
char* const res = p;
95+
*p-- = '\0';
96+
97+
while (p > b)
98+
{
99+
char c = *b;
100+
*b = *p;
101+
*p = c;
102+
++b;
103+
--p;
104+
}
105+
106+
return res;
107+
}
108+
};
109+
110+
static signal_handler g_sig_handler;
111+
112+
#endif // defined(__OpenBSD__)
113+
30114
thread_local unsigned throw_one = 0xFFFF;
31115
thread_local unsigned operator_new_recursion_level = 0u;
32116

0 commit comments

Comments
 (0)