Coverage Report

Created: 2024-05-03 06:05

/builds/xfbs/passgen/src/assert.c
Line
Count
Source (jump to first uncovered line)
1
#include "passgen/assert.h"
2
3
#include <stdlib.h>
4
5
#ifdef PASSGEN_DEBUG
6
7
#ifdef PASSGEN_BACKTRACE
8
#include <execinfo.h>
9
#endif
10
11
#include <stdio.h>
12
13
#define CALLSTACK_MAX 128
14
15
void passgen_assert_fail(
16
    const char *cond,
17
    const char *file,
18
    const char *func,
19
0
    size_t line) {
20
0
    // print warning
21
0
    fprintf(
22
0
        stderr,
23
0
        "Assertion failed in file %s at %s:%zu\n  \033[31m%s\033[0m\n",
24
0
        file,
25
0
        func,
26
0
        line,
27
0
        cond);
28
0
29
0
#ifdef PASSGEN_BACKTRACE
30
0
    // print backtrace
31
0
    fprintf(stderr, "\nBacktrace:\n");
32
0
33
0
    void *callstack[CALLSTACK_MAX];
34
0
    int frames = backtrace(callstack, sizeof(callstack));
35
0
    char **strs = backtrace_symbols(callstack, frames);
36
0
37
0
    for(int i = 0; i < frames; ++i) {
38
0
        printf("%s\n", strs[i]);
39
0
    }
40
0
41
0
    free(strs);
42
0
#endif
43
0
44
0
    exit(EXIT_FAILURE);
45
0
}
46
#endif