blob: d9b6c07342c53774bbb512bd1b89121a8efb7d43 [file] [log] [blame]
Imre Kis2ccd8e82021-10-08 11:21:14 +02001/* SPDX-License-Identifier: BSD-3-Clause */
2/*
3 * Copyright (c) 2021, Arm Limited and Contributors. All rights reserved.
4 */
5
6#ifndef TRACE_H_
7#define TRACE_H_
8
9#include "compiler.h"
10
11#define TRACE_LEVEL_NONE (0)
12#define TRACE_LEVEL_ERROR (1)
13#define TRACE_LEVEL_INFO (2)
14#define TRACE_LEVEL_DEBUG (3)
15
16#ifndef TRACE_LEVEL
17#define TRACE_LEVEL TRACE_LEVEL_ERROR
18#endif /* TRACE_LEVEL */
19
20/**
21 * no_trace_printf will be optimized out becase of the 'if (0)' but all the
22 * checks will still run against the format string and the parameters.
23 */
24#define no_trace_printf(func, line, level, fmt, ...) \
25 do { \
26 if (0) { \
27 trace_printf(func, line, level, fmt, ##__VA_ARGS__); \
28 } \
29 } while (0)
30
Gabor Ambrus7ccab792023-08-14 22:56:56 +020031extern void (*trace_puts_interface)(const char *str);
Imre Kis2ccd8e82021-10-08 11:21:14 +020032void trace_puts(const char *str);
33void trace_printf(const char *func, int line, int level, const char *fmt, ...) __printf(4, 5);
34
35#if TRACE_LEVEL >= TRACE_LEVEL_ERROR
36#define EMSG(...) trace_printf(__func__, __LINE__, TRACE_LEVEL_ERROR, __VA_ARGS__)
37#else
38#define EMSG(...) no_trace_printf(__func__, __LINE__, TRACE_LEVEL_ERROR, __VA_ARGS__)
39#endif /* TRACE_LEVEL >= TRACE_LEVEL_ERROR */
40
41#if TRACE_LEVEL >= TRACE_LEVEL_INFO
42#define IMSG(...) trace_printf(__func__, __LINE__, TRACE_LEVEL_INFO, __VA_ARGS__)
43#else
44#define IMSG(...) no_trace_printf(__func__, __LINE__, TRACE_LEVEL_INFO, __VA_ARGS__)
45#endif /* TRACE_LEVEL >= TRACE_LEVEL_INFO */
46
47#if TRACE_LEVEL >= TRACE_LEVEL_DEBUG
48#define DMSG(...) trace_printf(__func__, __LINE__, TRACE_LEVEL_DEBUG, __VA_ARGS__)
49#else
50#define DMSG(...) no_trace_printf(__func__, __LINE__, TRACE_LEVEL_DEBUG, __VA_ARGS__)
51#endif /* TRACE_LEVEL >= TRACE_LEVEL_DEBUG */
52
53#endif /* TRACE_H_ */