-
Notifications
You must be signed in to change notification settings - Fork 0
/
baselib.c
47 lines (34 loc) · 840 Bytes
/
baselib.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
46
/**
** Small lib for commonly used C functions.
**
** -- Kristofer Hallin [email protected]
**
*/
#include <stdlib.h>
#include <stdio.h>
#include <signal.h>
#include <sys/types.h>
#include <signal.h>
#include <execinfo.h>
#include "baselib.h"
void stacktrace_init(void)
{
struct sigaction sa;
sigemptyset(&(sa.sa_mask));
sa.sa_handler = &stacktrace_print;
sa.sa_flags = SA_RESETHAND;
sigaction(SIGSEGV, &sa, NULL);
}
static void stacktrace_print(const int sig)
{
void *stack_array[10];
ssize_t stack_size;
ssize_t stack_count;
char **strings;
stack_size = backtrace(stack_array, STACK_MAX_SIZE);
fprintf(stderr, "*** Obtained %d stack frames\n", stack_size);
for (stack_count = 0; stack_count < stack_size; stack_count++) {
fprintf(stderr, "*** %s\n", strings[stack_count]);
}
free(strings);
}