Dynamic Load Balance 3.6.1+32-59d1
debug.h
Go to the documentation of this file.
1/*********************************************************************************/
2/* Copyright 2009-2021 Barcelona Supercomputing Center */
3/* */
4/* This file is part of the DLB library. */
5/* */
6/* DLB is free software: you can redistribute it and/or modify */
7/* it under the terms of the GNU Lesser General Public License as published by */
8/* the Free Software Foundation, either version 3 of the License, or */
9/* (at your option) any later version. */
10/* */
11/* DLB is distributed in the hope that it will be useful, */
12/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
13/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
14/* GNU Lesser General Public License for more details. */
15/* */
16/* You should have received a copy of the GNU Lesser General Public License */
17/* along with DLB. If not, see <https://www.gnu.org/licenses/>. */
18/*********************************************************************************/
19
20#ifndef DEBUG_H
21#define DEBUG_H
22
23#include "support/dlb_common.h"
24#include "support/options.h"
25#include "support/types.h"
26
27#include <assert.h>
28#include <stdlib.h>
29#include <stdio.h>
30
31typedef struct print_buffer {
32 char *addr;
33 size_t size;
34 size_t len;
36
37void debug_init(const options_t *options);
38void fatal(const char *fmt, ...) __attribute__ ((format (printf, 1, 2),__noreturn__));
39void fatal0(const char *fmt, ...) __attribute__ ((format (printf, 1, 2),__noreturn__));
40void warning(const char *fmt, ...) __attribute__ ((format (printf, 1, 2)));
41void warning0(const char *fmt, ...) __attribute__ ((format (printf, 1, 2)));
42void info(const char *fmt, ...) __attribute__ ((format (printf, 1, 2)));
43void info0(const char *fmt, ...) __attribute__ ((format (printf, 1, 2)));
44void info0_force_print(const char *fmt, ...) __attribute__ ((format (printf, 1, 2)));
45void verbose(verbose_opts_t flag, const char *fmt, ...) __attribute__ ((format (printf, 2, 3)));
46void verbose0(verbose_opts_t flag, const char *fmt, ...) __attribute__ ((format (printf, 2, 3)));
47void print_backtrace(void);
48void dlb_clean(void);
49void warn_error(int error);
52void printbuffer_append(print_buffer_t *buffer, const char *line);
53void printbuffer_append_no_newline(print_buffer_t *buffer, const char *text);
54
56
57#define fatal_cond(cond, ...) \
58 do { \
59 if (unlikely(cond)) { fatal(__VA_ARGS__); } \
60 } while(0)
61
62#define fatal_cond0(cond, ...) \
63 do { \
64 if (unlikely(cond)) { fatal0(__VA_ARGS__); } \
65 } while(0)
66
67#define fatal_cond_strerror(cond) \
68 do { \
69 int _error = cond; \
70 if (unlikely(_error)) fatal(#cond ":%s", strerror(_error)); \
71 } while(0)
72
73#define verbose(flag, ...) \
74 do { \
75 if (unlikely(vb_opts != VB_CLEAR)) { verbose(flag, __VA_ARGS__); } \
76 } while(0)
77
78#define verbose0(flag, ...) \
79 do { \
80 if (unlikely(vb_opts != VB_CLEAR)) { verbose0(flag, __VA_ARGS__); } \
81 } while(0)
82
83
84#ifdef DEBUG_VERSION
85#define DLB_DEBUG(stmt) do { stmt; } while(0)
86#else
87#define DLB_DEBUG(stmt) do { (void)0; } while(0)
88#endif
89
90#ifdef DEBUG_VERSION
91#define debug_warning(fmt, ...) \
92 warning("%s:%d:%s(): " fmt, __FILE__, __LINE__, __func__, ##__VA_ARGS__)
93
94#define ensure(cond, ...) \
95 do { \
96 if (likely(cond)) ; else { fatal(__VA_ARGS__); } \
97 } while(0)
98
99
100#if __STDC_VERSION__ >= 202311L
101 #define static_ensure(cond, msg) static_assert(cond, msg)
102#elif __STDC_VERSION__ >= 201112L
103 #define static_ensure(cond, msg) _Static_assert(cond, msg)
104#else
105 #define static_ensure(cond, msg) \
106 do { \
107 enum { assert_static__ = 1 / (!!(cond)) }; \
108 } while (0)
109#endif
110
111#else
112#define debug_warning(...) do { (void)0; } while(0)
113#define ensure(cond, ...) do { (void)0; } while(0)
114#define static_ensure(cond, ...) do { (void)0; } while(0)
115#endif
116
117/* Colors */
118
119#define ANSI_COLOR_RED "\x1b[31m"
120#define ANSI_COLOR_GREEN "\x1b[32m"
121#define ANSI_COLOR_YELLOW "\x1b[33m"
122#define ANSI_COLOR_BLUE "\x1b[34m"
123#define ANSI_COLOR_MAGENTA "\x1b[35m"
124#define ANSI_COLOR_CYAN "\x1b[36m"
125#define ANSI_COLOR_RESET "\x1b[0m"
126
127#endif /* DEBUG_H */
__attribute__((constructor))
Definition: DLB_interface.c:47
void fatal(const char *fmt,...) __attribute__((format(printf
void printbuffer_destroy(print_buffer_t *buffer)
Definition: debug.c:419
void void warning0(const char *fmt,...) __attribute__((format(printf
void printbuffer_init(print_buffer_t *buffer)
Definition: debug.c:412
void void void info(const char *fmt,...) __attribute__((format(printf
void warn_error(int error)
Definition: debug.c:372
void void void void void info0_force_print(const char *fmt,...) __attribute__((format(printf
#define verbose(flag,...)
Definition: debug.h:73
#define verbose0(flag,...)
Definition: debug.h:78
void void void void void void void void print_backtrace(void)
Definition: debug.c:293
void debug_init(const options_t *options)
Definition: debug.c:66
verbose_opts_t vb_opts
Definition: debug.c:56
void fatal0(const char *fmt,...) __attribute__((format(printf
void dlb_clean(void)
Definition: debug.c:331
void printbuffer_append_no_newline(print_buffer_t *buffer, const char *text)
Definition: debug.c:462
void printbuffer_append(print_buffer_t *buffer, const char *line)
Definition: debug.c:458
void warning(const char *fmt,...) __attribute__((format(printf
void __noreturn__
Definition: debug.h:38
void void void void info0(const char *fmt,...) __attribute__((format(printf
Definition: options.h:30
Definition: debug.h:31
size_t len
Definition: debug.h:34
size_t size
Definition: debug.h:33
char * addr
Definition: debug.h:32
verbose_opts_t
Definition: types.h:41