aboutsummaryrefslogtreecommitdiff
path: root/platform/linux-generic/include/odp/api/plat/debug_inlines.h
blob: 41af3dca4498890dc18b99022d9d17e6fddf2edc (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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/* Copyright (c) 2014-2018, Linaro Limited
 * Copyright (c) 2020-2022, Nokia
 * All rights reserved.
 *
 * SPDX-License-Identifier:     BSD-3-Clause
 */

/**
 * @file
 *
 * ODP Debug inlines
 *
 * @warning These definitions are not part of ODP API, they are for
 * implementation internal use only.
 */

#ifndef ODP_DEBUG_INLINES_H_
#define ODP_DEBUG_INLINES_H_

#include <odp/autoheader_external.h>

#include <odp/api/hints.h>
#include <odp/api/init.h>

#include <odp/api/plat/thread_inline_types.h>

/** @cond _ODP_HIDE_FROM_DOXYGEN_ */

#ifdef __cplusplus
extern "C" {
#endif

#pragma GCC diagnostic push

#ifdef __clang__
#pragma GCC diagnostic ignored "-Wgnu-zero-variadic-macro-arguments"
#endif

extern odp_log_func_t ODP_PRINTF_FORMAT(2, 3) _odp_log_fn;
extern odp_abort_func_t _odp_abort_fn;

#define _ODP_LOG_FN(level, ...) \
	do { \
		if (_odp_this_thread && _odp_this_thread->log_fn) \
			_odp_this_thread->log_fn(level, ##__VA_ARGS__); \
		else \
			_odp_log_fn(level, ##__VA_ARGS__); \
	} while (0)

/**
 * ODP LOG macro.
 */
#define _ODP_LOG(level, fmt, ...) \
		 _ODP_LOG_FN(level, "%s:%d:%s(): " fmt, __FILE__, \
		 __LINE__, __func__, ##__VA_ARGS__)

/**
 * Runtime assertion-macro - aborts if 'cond' is false.
 */
#define _ODP_ASSERT(cond) \
	do { if ((ODP_DEBUG == 1) && (!(cond))) { \
		_ODP_ERR("%s\n", #cond); \
		_odp_abort_fn(); } \
	} while (0)

/*
 * Print debug message to log, if ODP_DEBUG_PRINT flag is set (ignores CONFIG_DEBUG_LEVEL).
 */
#define _ODP_DBG(...) \
	do { \
		if (ODP_DEBUG_PRINT == 1) \
			__extension__ ({ \
				_ODP_LOG(ODP_LOG_DBG, ##__VA_ARGS__); \
			}); \
	} while (0)

/**
 * Log error message.
 */
#define _ODP_ERR(...) \
	do { \
		__extension__ ({ \
			_ODP_LOG(ODP_LOG_ERR, ##__VA_ARGS__); \
		}); \
	} while (0)

/**
 * Log abort message and then stop execution (by default call abort()).
 * This function should not return.
 */
#define _ODP_ABORT(...) \
	do { \
		__extension__ ({ \
			_ODP_LOG(ODP_LOG_ABORT, ##__VA_ARGS__); \
		}); \
		_odp_abort_fn(); \
	} while (0)

/**
 * Log print message when the application calls one of the ODP APIs
 * specifically for dumping internal data.
 */
#define _ODP_PRINT(...) \
	_ODP_LOG_FN(ODP_LOG_PRINT, ##__VA_ARGS__)

#pragma GCC diagnostic pop

#ifdef __cplusplus
}
#endif

/** @endcond */

#endif