xref: /4.0.0/forestdb/utils/debug.cc (revision eda2b6e5)
1#include "debug.h"
2#include <stdio.h>
3#include <stdlib.h>
4#include <stdint.h>
5#include "time_utils.h"
6
7#define N_DBG_SWITCH (256)
8
9static uint8_t _global_dbg_switch[N_DBG_SWITCH];
10static void* _global_dbg_addr[N_DBG_SWITCH];
11static uint64_t _global_dbg_uint64_t[N_DBG_SWITCH];
12
13// LCOV_EXCL_START
14void _dbg_sw_set(int n)
15{
16    _global_dbg_switch[n] = 1;
17}
18
19void _dbg_sw_clear(int n)
20{
21    _global_dbg_switch[n] = 0;
22}
23
24void _dbg_set_addr(int n, void *addr)
25{
26    _global_dbg_addr[n] = addr;
27}
28
29void * _dbg_get_addr(int n)
30{
31    return _global_dbg_addr[n];
32}
33
34void _dbg_set_uint64_t(int n, uint64_t val)
35{
36    _global_dbg_uint64_t[n] = val;
37}
38
39uint64_t _dbg_get_uint64_t(int n)
40{
41    return _global_dbg_uint64_t[n];
42}
43
44int _dbg_is_sw_set(int n)
45{
46    return _global_dbg_switch[n];
47}
48
49void _dbg_assert(int line, const char *file, uint64_t val, uint64_t expected) {
50    char *hang_process;
51     fprintf(stderr, "Assertion in %p != %p in %s:%d\n",
52            (void *)val, (void *)expected, file, line);
53     hang_process = getenv("HANG_ON_ASSERTION");
54     if (hang_process) {
55         fprintf(stderr, "Hanging process...");
56         fprintf(stderr, "\n");
57         while (1) {
58             usleep(1000);
59         }
60     }
61}
62// LCOV_EXCL_STOP
63
64