-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbacktrace.c
executable file
·56 lines (46 loc) · 1.06 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
46
47
48
49
50
51
52
53
54
55
56
/*****************************************************************
*
*
*****************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <unistd.h>
#include <signal.h>
#include <asm/types.h>
#include <dlfcn.h>
#ifndef __ANDROID__
#include <execinfo.h>
#endif
#define _BACKTRACE_IMPL_
#include "backtrace.h"
#include "libaglog.h"
#undef LOG_TAG
#define LOG_TAG "GVBackTrace"
void dump(int signo)
{
void *buffer[100] = {0};
size_t size;
char **strings = NULL;
size_t i = 0;
size = backtrace(buffer, 100);
fprintf(stdout, "Obtained %zd stack frames.nm\n", size);
strings = backtrace_symbols(buffer, size);
if (strings == NULL) {
perror("backtrace_symbols.");
exit(0);
}
for (i = 0; i < size; i++) {
fprintf(stdout, "%s\n", strings[i]);
}
free(strings);
strings = NULL;
exit(0);
}
void backtrace_init(void)
{
LOGD("backtrace inited.");
if(signal(SIGSEGV, dump) == SIG_ERR) {
perror("can't catch SIGSEGV");
}
}