-
Notifications
You must be signed in to change notification settings - Fork 9
/
error.c
49 lines (37 loc) · 916 Bytes
/
error.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
#include "error.h"
#include <stdlib.h>
#include <stdarg.h>
int note_error_(struct errors *errs_, const char *fmt, ...)
{
static char buf[512];
struct error err;
struct cursor *errs;
va_list ap;
errs = &errs_->cur;
if (errs_->enabled == 0)
return 0;
va_start(ap, fmt);
vsprintf(buf, fmt, ap);
va_end(ap);
err.msg = buf;
if (!cursor_push_error(errs, &err)) {
fprintf(stderr, "arena OOM when recording error, ");
fprintf(stderr, "errs->p at %ld, remaining %ld, strlen %ld\n",
errs->p - errs->start, errs->end - errs->p, strlen(buf));
}
return 0;
}
void print_error_backtrace(struct errors *errors)
{
struct cursor errs;
struct error err;
copy_cursor(&errors->cur, &errs);
errs.p = errs.start;
while (errs.p < errors->cur.p) {
if (!cursor_pull_error(&errs, &err)) {
fprintf(stderr, "backtrace: couldn't pull error\n");
return;
}
fprintf(stderr, "%s\n", err.msg);
}
}