forked from atheme/atheme-contrib-modules
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbacktrace.c
45 lines (37 loc) · 1 KB
/
backtrace.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include "atheme-compat.h"
#if defined( __linux__) || defined(__Linux__)
#include <execinfo.h>
DECLARE_MODULE_V1
(
"contrib/backtrace", false, _modinit, _moddeinit,
PACKAGE_STRING,
"Xtheme Development Group <http://www.xtheme.org>"
);
static void __segv_hdl(int whocares)
{
void *array[256];
char **strings;
size_t sz, i;
sz = backtrace(array, 256);
strings = backtrace_symbols(array, sz);
slog(LG_INFO, "---------------- [ CRASH ] -----------------");
slog(LG_INFO, "%zu stack frames, flags %s", sz, get_conf_opts());
for (i = 0; i < sz; i++)
slog(LG_INFO, "#%zu --> %p (%s)", i, array[i], strings[i]);
slog(LG_INFO, "Report to https://github.com/XthemeOrg/Xtheme/issues/");
slog(LG_INFO, "--------------------------------------------");
}
void _modinit(module_t *m)
{
signal(SIGSEGV, __segv_hdl);
}
void _moddeinit(module_unload_intent_t intent)
{
signal(SIGSEGV, NULL);
}
#endif
/* vim:cinoptions=>s,e0,n0,f0,{0,}0,^0,=s,ps,t0,c3,+s,(2s,us,)20,*30,gs,hs
* vim:ts=8
* vim:sw=8
* vim:noexpandtab
*/