blob: 7e2e5616be6163a504b95cfdbd0250aa6e3b4ca4 [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
Gabor Tothed8305b2024-09-24 12:47:26 +020011#ifdef EXPORT_PUBLIC_INTERFACE_TRACE
12#define TRACE_EXPORTED __attribute__((__visibility__("default")))
13#else
14#define TRACE_EXPORTED
15#endif
16
Imre Kis2ccd8e82021-10-08 11:21:14 +020017#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 Toth193f6dd2024-09-27 11:49:49 +020023#error "Trace level is not defined!"
Imre Kis2ccd8e82021-10-08 11:21:14 +020024#endif /* TRACE_LEVEL */
25
26/**
Gabor Toth121288a2024-10-03 18:02:15 +020027 * no_ts_trace_printf will be optimized out becase of the 'if (0)' but all the
Imre Kis2ccd8e82021-10-08 11:21:14 +020028 * checks will still run against the format string and the parameters.
29 */
Gabor Toth121288a2024-10-03 18:02:15 +020030#define no_ts_trace_printf(func, line, level, fmt, ...) \
Imre Kis2ccd8e82021-10-08 11:21:14 +020031 do { \
32 if (0) { \
Gabor Toth121288a2024-10-03 18:02:15 +020033 ts_trace_printf(func, line, level, fmt, ##__VA_ARGS__); \
Imre Kis2ccd8e82021-10-08 11:21:14 +020034 } \
35 } while (0)
36
Gabor Ambrus7ccab792023-08-14 22:56:56 +020037extern void (*trace_puts_interface)(const char *str);
Imre Kis2ccd8e82021-10-08 11:21:14 +020038void trace_puts(const char *str);
Gabor Tothed8305b2024-09-24 12:47:26 +020039TRACE_EXPORTED
Gabor Toth121288a2024-10-03 18:02:15 +020040void ts_trace_printf(const char *func, int line, int level, const char *fmt, ...) __printf(4, 5);
Imre Kis2ccd8e82021-10-08 11:21:14 +020041
42#if TRACE_LEVEL >= TRACE_LEVEL_ERROR
Gabor Toth121288a2024-10-03 18:02:15 +020043#define EMSG(...) ts_trace_printf(__func__, __LINE__, TRACE_LEVEL_ERROR, __VA_ARGS__)
Imre Kis2ccd8e82021-10-08 11:21:14 +020044#else
Gabor Toth121288a2024-10-03 18:02:15 +020045#define EMSG(...) no_ts_trace_printf(__func__, __LINE__, TRACE_LEVEL_ERROR, __VA_ARGS__)
Imre Kis2ccd8e82021-10-08 11:21:14 +020046#endif /* TRACE_LEVEL >= TRACE_LEVEL_ERROR */
47
48#if TRACE_LEVEL >= TRACE_LEVEL_INFO
Gabor Toth121288a2024-10-03 18:02:15 +020049#define IMSG(...) ts_trace_printf(__func__, __LINE__, TRACE_LEVEL_INFO, __VA_ARGS__)
Imre Kis2ccd8e82021-10-08 11:21:14 +020050#else
Gabor Toth121288a2024-10-03 18:02:15 +020051#define IMSG(...) no_ts_trace_printf(__func__, __LINE__, TRACE_LEVEL_INFO, __VA_ARGS__)
Imre Kis2ccd8e82021-10-08 11:21:14 +020052#endif /* TRACE_LEVEL >= TRACE_LEVEL_INFO */
53
54#if TRACE_LEVEL >= TRACE_LEVEL_DEBUG
Gabor Toth121288a2024-10-03 18:02:15 +020055#define DMSG(...) ts_trace_printf(__func__, __LINE__, TRACE_LEVEL_DEBUG, __VA_ARGS__)
Imre Kis2ccd8e82021-10-08 11:21:14 +020056#else
Gabor Toth121288a2024-10-03 18:02:15 +020057#define DMSG(...) no_ts_trace_printf(__func__, __LINE__, TRACE_LEVEL_DEBUG, __VA_ARGS__)
Imre Kis2ccd8e82021-10-08 11:21:14 +020058#endif /* TRACE_LEVEL >= TRACE_LEVEL_DEBUG */
59
60#endif /* TRACE_H_ */