16
16
#include "../utils/string.h"
17
17
#include "../utils/threads.h"
18
18
#define BSG_HANDLED_SIGNAL_COUNT 6
19
-
19
+ #define BSG_SIGNAL_CODE_COUNT 15
20
20
/**
21
21
* Function to capture signals and write reports to disk
22
22
* @param signum The captured signal number
@@ -48,6 +48,17 @@ struct sigaction *bsg_global_sigaction;
48
48
/* the previous signal handler array */
49
49
struct sigaction * bsg_global_sigaction_previous ;
50
50
51
+ #define MSG_SIGILL "Illegal instruction"
52
+ #define MSG_SIGTRAP "Trace/breakpoint trap"
53
+ #define MSG_SIGABRT "Abort program"
54
+ #define MSG_SIGBUS "Bus error (bad memory access)"
55
+ #define MSG_SIGFPE "Floating-point exception"
56
+ #define MSG_SIGSEGV "Segmentation violation (invalid memory reference)"
57
+
58
+ #define xstr (s ) str(s)
59
+ #define str (s ) #s
60
+ #define SIG_CODE_MESSAGE (msg , code ) (msg ", code " xstr(code) " (" #code ")")
61
+
51
62
/**
52
63
* Native signals which will be captured by the Bugsnag signal handler™
53
64
*/
@@ -56,12 +67,88 @@ static const int bsg_native_signals[BSG_HANDLED_SIGNAL_COUNT + 1] = {
56
67
static const char bsg_native_signal_names [BSG_HANDLED_SIGNAL_COUNT + 1 ][8 ] = {
57
68
"SIGILL" , "SIGTRAP" , "SIGABRT" , "SIGBUS" , "SIGFPE" , "SIGSEGV" };
58
69
static const char bsg_native_signal_msgs [BSG_HANDLED_SIGNAL_COUNT + 1 ][60 ] = {
59
- "Illegal instruction" ,
60
- "Trace/breakpoint trap" ,
61
- "Abort program" ,
62
- "Bus error (bad memory access)" ,
63
- "Floating-point exception" ,
64
- "Segmentation violation (invalid memory reference)" };
70
+ MSG_SIGILL , MSG_SIGTRAP , MSG_SIGABRT , MSG_SIGBUS , MSG_SIGFPE , MSG_SIGSEGV };
71
+
72
+ static const char
73
+ bsg_native_signal_code_names [BSG_HANDLED_SIGNAL_COUNT +
74
+ 1 ][BSG_SIGNAL_CODE_COUNT + 1 ][72 ] = {
75
+ {SIG_CODE_MESSAGE (MSG_SIGILL , ILL_ILLOPC ),
76
+ SIG_CODE_MESSAGE (MSG_SIGILL , ILL_ILLOPN ),
77
+ SIG_CODE_MESSAGE (MSG_SIGILL , ILL_ILLADR ),
78
+ SIG_CODE_MESSAGE (MSG_SIGILL , ILL_ILLTRP ),
79
+ SIG_CODE_MESSAGE (MSG_SIGILL , ILL_PRVOPC ),
80
+ SIG_CODE_MESSAGE (MSG_SIGILL , ILL_PRVREG ),
81
+ SIG_CODE_MESSAGE (MSG_SIGILL , ILL_COPROC ),
82
+ SIG_CODE_MESSAGE (MSG_SIGILL , ILL_BADSTK ),
83
+ SIG_CODE_MESSAGE (MSG_SIGILL , ILL_BADIADDR ),
84
+ SIG_CODE_MESSAGE (MSG_SIGILL , __ILL_BREAK ),
85
+ SIG_CODE_MESSAGE (MSG_SIGILL , __ILL_BNDMOD )},
86
+ {SIG_CODE_MESSAGE (MSG_SIGTRAP , TRAP_BRKPT ),
87
+ SIG_CODE_MESSAGE (MSG_SIGTRAP , TRAP_TRACE ),
88
+ SIG_CODE_MESSAGE (MSG_SIGTRAP , TRAP_BRANCH ),
89
+ SIG_CODE_MESSAGE (MSG_SIGTRAP , TRAP_HWBKPT ),
90
+ SIG_CODE_MESSAGE (MSG_SIGTRAP , TRAP_UNK ),
91
+ SIG_CODE_MESSAGE (MSG_SIGTRAP , TRAP_PERF )},
92
+ {0 },
93
+ {SIG_CODE_MESSAGE (MSG_SIGBUS , BUS_ADRALN ),
94
+ SIG_CODE_MESSAGE (MSG_SIGBUS , BUS_ADRERR ),
95
+ SIG_CODE_MESSAGE (MSG_SIGBUS , BUS_OBJERR ),
96
+ SIG_CODE_MESSAGE (MSG_SIGBUS , BUS_MCEERR_AR ),
97
+ SIG_CODE_MESSAGE (MSG_SIGBUS , BUS_MCEERR_AO )},
98
+ {SIG_CODE_MESSAGE (MSG_SIGFPE , FPE_INTDIV ),
99
+ SIG_CODE_MESSAGE (MSG_SIGFPE , FPE_INTOVF ),
100
+ SIG_CODE_MESSAGE (MSG_SIGFPE , FPE_FLTDIV ),
101
+ SIG_CODE_MESSAGE (MSG_SIGFPE , FPE_FLTOVF ),
102
+ SIG_CODE_MESSAGE (MSG_SIGFPE , FPE_FLTUND ),
103
+ SIG_CODE_MESSAGE (MSG_SIGFPE , FPE_FLTRES ),
104
+ SIG_CODE_MESSAGE (MSG_SIGFPE , FPE_FLTINV ),
105
+ SIG_CODE_MESSAGE (MSG_SIGFPE , FPE_FLTSUB ),
106
+ SIG_CODE_MESSAGE (MSG_SIGFPE , __FPE_DECOVF ),
107
+ SIG_CODE_MESSAGE (MSG_SIGFPE , __FPE_DECDIV ),
108
+ SIG_CODE_MESSAGE (MSG_SIGFPE , __FPE_DECERR ),
109
+ SIG_CODE_MESSAGE (MSG_SIGFPE , __FPE_INVASC ),
110
+ SIG_CODE_MESSAGE (MSG_SIGFPE , __FPE_INVDEC ),
111
+ SIG_CODE_MESSAGE (MSG_SIGFPE , FPE_FLTUNK ),
112
+ SIG_CODE_MESSAGE (MSG_SIGFPE , FPE_CONDTRAP )},
113
+ {SIG_CODE_MESSAGE (MSG_SIGSEGV , SEGV_MAPERR ),
114
+ SIG_CODE_MESSAGE (MSG_SIGSEGV , SEGV_ACCERR ),
115
+ SIG_CODE_MESSAGE (MSG_SIGSEGV , SEGV_BNDERR ),
116
+ SIG_CODE_MESSAGE (MSG_SIGSEGV , SEGV_PKUERR ),
117
+ SIG_CODE_MESSAGE (MSG_SIGSEGV , SEGV_ACCADI ),
118
+ SIG_CODE_MESSAGE (MSG_SIGSEGV , SEGV_ADIDERR ),
119
+ SIG_CODE_MESSAGE (MSG_SIGSEGV , SEGV_ADIPERR ),
120
+ SIG_CODE_MESSAGE (MSG_SIGSEGV , SEGV_MTEAERR ),
121
+ SIG_CODE_MESSAGE (MSG_SIGSEGV , SEGV_MTESERR )}};
122
+
123
+ static const int bsg_native_signal_codes [BSG_HANDLED_SIGNAL_COUNT +
124
+ 1 ][BSG_SIGNAL_CODE_COUNT + 1 ] = {
125
+ {ILL_ILLOPC , ILL_ILLOPN , ILL_ILLADR , ILL_ILLTRP , ILL_PRVOPC , ILL_PRVREG ,
126
+ ILL_COPROC , ILL_BADSTK , ILL_BADIADDR , __ILL_BREAK , __ILL_BNDMOD },
127
+ {TRAP_BRKPT , TRAP_TRACE , TRAP_BRANCH , TRAP_HWBKPT , TRAP_UNK , TRAP_PERF },
128
+ {BUS_ADRALN , BUS_ADRERR , BUS_OBJERR , BUS_MCEERR_AR , BUS_MCEERR_AO },
129
+ {FPE_INTDIV , FPE_INTOVF , FPE_FLTDIV , FPE_FLTOVF , FPE_FLTUND , FPE_FLTRES ,
130
+ FPE_FLTINV , FPE_FLTSUB , __FPE_DECOVF , __FPE_DECDIV , __FPE_DECERR ,
131
+ __FPE_INVASC , __FPE_INVDEC , FPE_FLTUNK , FPE_CONDTRAP },
132
+ {SEGV_MAPERR , SEGV_ACCERR , SEGV_BNDERR , SEGV_PKUERR , SEGV_ACCADI ,
133
+ SEGV_ADIDERR , SEGV_ADIPERR , SEGV_MTEAERR , SEGV_MTESERR }};
134
+
135
+ static const char *
136
+ bsg_get_signal_code_description (const int signal ,
137
+ const int signal_code ) __asyncsafe {
138
+ for (int i = 0 ; i < BSG_HANDLED_SIGNAL_COUNT ; i ++ ) {
139
+ if (bsg_native_signals [i ] == signal ) {
140
+ for (int j = 0 ; j < BSG_SIGNAL_CODE_COUNT ; j ++ ) {
141
+ if (bsg_native_signal_codes [i ][j ] == signal_code ) {
142
+ return bsg_native_signal_code_names [i ][j ];
143
+ } else if (* bsg_native_signal_code_names [i ][j ] == 0 ) {
144
+ // NULL in the signal_code_name array indicates no more known codes
145
+ break ;
146
+ }
147
+ }
148
+ }
149
+ }
150
+ return NULL ;
151
+ }
65
152
66
153
bool bsg_handler_install_signal (bsg_environment * env ) {
67
154
if (bsg_global_env != NULL ) {
@@ -195,12 +282,17 @@ void bsg_handle_signal(int signum, siginfo_t *info,
195
282
196
283
for (int i = 0 ; i < BSG_HANDLED_SIGNAL_COUNT ; i ++ ) {
197
284
const int signal = bsg_native_signals [i ];
285
+ const int signal_code = info -> si_code ;
198
286
if (signal == signum ) {
199
287
bsg_strncpy (bsg_global_env -> next_event .error .errorClass ,
200
288
(char * )bsg_native_signal_names [i ],
201
289
sizeof (bsg_global_env -> next_event .error .errorClass ));
202
- bsg_strncpy (bsg_global_env -> next_event .error .errorMessage ,
203
- (char * )bsg_native_signal_msgs [i ],
290
+ const char * error_message =
291
+ bsg_get_signal_code_description (signal , signal_code );
292
+ if (error_message == NULL || * error_message == 0 ) {
293
+ error_message = (char * )bsg_native_signal_msgs [i ];
294
+ }
295
+ bsg_strncpy (bsg_global_env -> next_event .error .errorMessage , error_message ,
204
296
sizeof (bsg_global_env -> next_event .error .errorMessage ));
205
297
break ;
206
298
}
0 commit comments