summaryrefslogtreecommitdiffstats
path: root/include/debug.h
blob: 6cfb43ed88242f24ceda5765e4312655c2f5e44f (plain)
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
#ifndef _LIBDECT_DEBUG_H
#define _LIBDECT_DEBUG_H

#include <utils.h>
#include <dect/debug.h>

extern void __dect_debug(enum dect_debug_subsys subsys, const char *fmt, ...) __fmtstring(2, 3);
extern void __dect_hexdump(enum dect_debug_subsys subsys, const char *prefix,
			   const uint8_t *buf, size_t size);

#ifdef DEBUG
#define dect_debug(subsys, fmt, ...) \
	__dect_debug(subsys, fmt, ## __VA_ARGS__)
#define dect_hexdump(subsys, pfx, buf, size) \
	__dect_hexdump(subsys, pfx, buf, size)
#else
#define dect_debug(subsys, fmt, ...) \
	({ if (0) __dect_debug(subsys, fmt, ## __VA_ARGS__); })
#define dect_hexdump(subsys, pfx, buf, size) \
	({ if (0) __dect_hexdump(subsys, pfx, buf, size); })
#endif

extern void __dect_assert_fail(const char *assertion,
			       const char *file,
			       unsigned int line,
			       const char *function) __noreturn;

#define dect_assert(expr)						\
	((expr) ?							\
	 (void)0 :							\
	 __dect_assert_fail(__STRING(expr), __FILE__, __LINE__,		\
			    __ASSERT_FUNCTION))

struct dect_trans_tbl {
	uint64_t	val;
	const char	*str;
};

#define TRANS_TBL(_val, _str)	{ .val = (_val), .str = (_str) }

extern const char *__dect_flags2str(const struct dect_trans_tbl *tbl, unsigned int nelem,
				    char *buf, size_t size, uint64_t val);

#define dect_val2str(trans, buf, val) \
	__dect_val2str(trans, array_size(trans), buf, sizeof(buf), val)

extern const char *__dect_val2str(const struct dect_trans_tbl *tbl, unsigned int nelem,
				  char *buf, size_t len, uint64_t val);

#define dect_flags2str(trans, buf, val) \
	__dect_flags2str(trans, array_size(trans), buf, sizeof(buf), val)

#endif /* _LIBDECT_DEBUG_H */