Imre Kis | 2ccd8e8 | 2021-10-08 11:21:14 +0200 | [diff] [blame] | 1 | /* 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 | |
Gabor Toth | ed8305b | 2024-09-24 12:47:26 +0200 | [diff] [blame] | 11 | #ifdef EXPORT_PUBLIC_INTERFACE_TRACE |
| 12 | #define TRACE_EXPORTED __attribute__((__visibility__("default"))) |
| 13 | #else |
| 14 | #define TRACE_EXPORTED |
| 15 | #endif |
| 16 | |
Imre Kis | 2ccd8e8 | 2021-10-08 11:21:14 +0200 | [diff] [blame] | 17 | #define TRACE_LEVEL_NONE (0) |
| 18 | #define TRACE_LEVEL_ERROR (1) |
| 19 | #define TRACE_LEVEL_INFO (2) |
| 20 | #define TRACE_LEVEL_DEBUG (3) |
| 21 | |
| 22 | #ifndef TRACE_LEVEL |
Gabor Toth | 193f6dd | 2024-09-27 11:49:49 +0200 | [diff] [blame] | 23 | #error "Trace level is not defined!" |
Imre Kis | 2ccd8e8 | 2021-10-08 11:21:14 +0200 | [diff] [blame] | 24 | #endif /* TRACE_LEVEL */ |
| 25 | |
| 26 | /** |
Gabor Toth | 121288a | 2024-10-03 18:02:15 +0200 | [diff] [blame] | 27 | * no_ts_trace_printf will be optimized out becase of the 'if (0)' but all the |
Imre Kis | 2ccd8e8 | 2021-10-08 11:21:14 +0200 | [diff] [blame] | 28 | * checks will still run against the format string and the parameters. |
| 29 | */ |
Gabor Toth | 121288a | 2024-10-03 18:02:15 +0200 | [diff] [blame] | 30 | #define no_ts_trace_printf(func, line, level, fmt, ...) \ |
Imre Kis | 2ccd8e8 | 2021-10-08 11:21:14 +0200 | [diff] [blame] | 31 | do { \ |
| 32 | if (0) { \ |
Gabor Toth | 121288a | 2024-10-03 18:02:15 +0200 | [diff] [blame] | 33 | ts_trace_printf(func, line, level, fmt, ##__VA_ARGS__); \ |
Imre Kis | 2ccd8e8 | 2021-10-08 11:21:14 +0200 | [diff] [blame] | 34 | } \ |
| 35 | } while (0) |
| 36 | |
Gabor Ambrus | 7ccab79 | 2023-08-14 22:56:56 +0200 | [diff] [blame] | 37 | extern void (*trace_puts_interface)(const char *str); |
Imre Kis | 2ccd8e8 | 2021-10-08 11:21:14 +0200 | [diff] [blame] | 38 | void trace_puts(const char *str); |
Gabor Toth | ed8305b | 2024-09-24 12:47:26 +0200 | [diff] [blame] | 39 | TRACE_EXPORTED |
Gabor Toth | 121288a | 2024-10-03 18:02:15 +0200 | [diff] [blame] | 40 | void ts_trace_printf(const char *func, int line, int level, const char *fmt, ...) __printf(4, 5); |
Imre Kis | 2ccd8e8 | 2021-10-08 11:21:14 +0200 | [diff] [blame] | 41 | |
| 42 | #if TRACE_LEVEL >= TRACE_LEVEL_ERROR |
Gabor Toth | 121288a | 2024-10-03 18:02:15 +0200 | [diff] [blame] | 43 | #define EMSG(...) ts_trace_printf(__func__, __LINE__, TRACE_LEVEL_ERROR, __VA_ARGS__) |
Imre Kis | 2ccd8e8 | 2021-10-08 11:21:14 +0200 | [diff] [blame] | 44 | #else |
Gabor Toth | 121288a | 2024-10-03 18:02:15 +0200 | [diff] [blame] | 45 | #define EMSG(...) no_ts_trace_printf(__func__, __LINE__, TRACE_LEVEL_ERROR, __VA_ARGS__) |
Imre Kis | 2ccd8e8 | 2021-10-08 11:21:14 +0200 | [diff] [blame] | 46 | #endif /* TRACE_LEVEL >= TRACE_LEVEL_ERROR */ |
| 47 | |
| 48 | #if TRACE_LEVEL >= TRACE_LEVEL_INFO |
Gabor Toth | 121288a | 2024-10-03 18:02:15 +0200 | [diff] [blame] | 49 | #define IMSG(...) ts_trace_printf(__func__, __LINE__, TRACE_LEVEL_INFO, __VA_ARGS__) |
Imre Kis | 2ccd8e8 | 2021-10-08 11:21:14 +0200 | [diff] [blame] | 50 | #else |
Gabor Toth | 121288a | 2024-10-03 18:02:15 +0200 | [diff] [blame] | 51 | #define IMSG(...) no_ts_trace_printf(__func__, __LINE__, TRACE_LEVEL_INFO, __VA_ARGS__) |
Imre Kis | 2ccd8e8 | 2021-10-08 11:21:14 +0200 | [diff] [blame] | 52 | #endif /* TRACE_LEVEL >= TRACE_LEVEL_INFO */ |
| 53 | |
| 54 | #if TRACE_LEVEL >= TRACE_LEVEL_DEBUG |
Gabor Toth | 121288a | 2024-10-03 18:02:15 +0200 | [diff] [blame] | 55 | #define DMSG(...) ts_trace_printf(__func__, __LINE__, TRACE_LEVEL_DEBUG, __VA_ARGS__) |
Imre Kis | 2ccd8e8 | 2021-10-08 11:21:14 +0200 | [diff] [blame] | 56 | #else |
Gabor Toth | 121288a | 2024-10-03 18:02:15 +0200 | [diff] [blame] | 57 | #define DMSG(...) no_ts_trace_printf(__func__, __LINE__, TRACE_LEVEL_DEBUG, __VA_ARGS__) |
Imre Kis | 2ccd8e8 | 2021-10-08 11:21:14 +0200 | [diff] [blame] | 58 | #endif /* TRACE_LEVEL >= TRACE_LEVEL_DEBUG */ |
| 59 | |
| 60 | #endif /* TRACE_H_ */ |