Wrap calls to fmt::format to catch formatting exceptions
[lttng-tools.git] / src / common / testpoint / testpoint.hpp
1 /*
2 * Copyright (C) 2012 Christian Babeux <christian.babeux@efficios.com>
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 */
7
8 #ifdef NTESTPOINT
9
10 #define testpoint(name)
11 #define TESTPOINT_DECL(name)
12
13 #else /* NTESTPOINT */
14
15 #include <urcu.h> /* for caa_likely/unlikely */
16
17 extern int lttng_testpoint_activated;
18
19 void *lttng_testpoint_lookup(const char *name);
20
21 /*
22 * Testpoint is only active if the global lttng_testpoint_activated flag is
23 * set.
24 * Return a non-zero error code to indicate failure.
25 */
26 #define testpoint(name) \
27 ((caa_unlikely(lttng_testpoint_activated)) ? __testpoint_##name##_wrapper() : 0)
28
29 /*
30 * One wrapper per testpoint is generated. This is to keep track of the symbol
31 * lookup status and the corresponding function pointer, if any.
32 */
33 #define _TESTPOINT_DECL(_name) \
34 static inline int __testpoint_##_name##_wrapper(void) \
35 { \
36 int ret = 0; \
37 static int (*tp)(void); \
38 static int found; \
39 const char *tp_name = "__testpoint_" #_name; \
40 \
41 if (tp) { \
42 ret = tp(); \
43 } else { \
44 if (!found) { \
45 tp = (int (*)(void)) lttng_testpoint_lookup(tp_name); \
46 if (tp) { \
47 found = 1; \
48 ret = tp(); \
49 } else { \
50 found = -1; \
51 } \
52 } \
53 } \
54 return ret; \
55 }
56
57 /* Testpoint declaration */
58 #define TESTPOINT_DECL(name) _TESTPOINT_DECL(name)
59
60 #endif /* NTESTPOINT */
This page took 0.030073 seconds and 4 git commands to generate.