forked from clostra/newnode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlog.c
89 lines (75 loc) · 1.64 KB
/
log.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <assert.h>
#include <ctype.h>
#include <errno.h>
#ifndef ANDROID
#include <execinfo.h>
#endif
#include "log.h"
int o_debug = 0;
#ifdef ANDROID
void bugsnag_log(const char *fmt, ...)
{
char buf[4096];
va_list ap;
va_start(ap, fmt);
vsnprintf(buf, sizeof(buf), fmt, ap);
va_end(ap);
void bugsnag_leave_breadcrumb_log(const char *buf);
bugsnag_leave_breadcrumb_log(buf);
}
#endif
void die(const char *fmt, ...)
{
va_list ap;
fflush(stdout);
va_start(ap, fmt);
vfprintf(stderr, fmt, ap);
va_end(ap);
assert(0);
}
void pdie(const char *err)
{
debug("%s: (%d) %s\n", err, errno, strerror(errno));
assert(0);
}
void hexdump(const void *addr, size_t len)
{
unsigned char buff[33];
unsigned char *pc = (unsigned char*)addr;
if (!len) {
return;
}
size_t i = 0;
for (i = 0; i < len; i++) {
if ((i % 32) == 0) {
if (i != 0) {
fprintf(stderr, " %s\n", buff);
}
fprintf(stderr, " %04zx ", i);
}
fprintf(stderr, " %02x", pc[i]);
buff[i % 32] = isprint(pc[i]) ? pc[i] : '.';
buff[(i % 32) + 1] = '\0';
}
while ((i % 32) != 0) {
fprintf(stderr, " ");
i++;
}
fprintf(stderr, " %s\n", buff);
}
#ifndef ANDROID
void print_trace()
{
void *array[100];
int size = backtrace(array, sizeof(array) / sizeof(array[0]));
char **strings = backtrace_symbols(array, size);
for (int i = 0; i < size; i++) {
printf("%s\n", strings[i]);
}
free(strings);
}
#endif