2 * SPDX-License-Identifier: MIT
4 * Copyright (C) 2013-2014 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
5 * Copyright (C) 2021 Norbert Lange <nolange79@gmail.com>
7 * Shared helper macro for tracelog and tracef.
10 #define LTTNG_UST_TRACELOG_VARARG(fmt, callback, ...) \
12 char local_buf[LTTNG_TRACE_PRINTF_BUFSIZE]; \
13 char *alloc_buff = NULL, *msg = local_buf; \
17 if (caa_unlikely(fmt[0] == '%' && fmt[1] == 's' && fmt[2] == '\0')) { \
19 msg = va_arg(ap, char *); \
23 size_t buflen = sizeof(local_buf); \
26 /* On-stack buffer attempt */ \
28 ret = vsnprintf(msg, buflen, fmt, ap); \
30 if (caa_unlikely(ret < 0)) \
34 if (caa_unlikely(len >= sizeof(local_buf))) { \
36 alloc_buff = (char *)malloc(buflen); \
41 ret = vsnprintf(msg, buflen, fmt, ap); \
43 lttng_ust_runtime_bug_on(ret < 0 || (size_t)ret != buflen - 1); \
48 callback(__VA_ARGS__); \
50 /* Don't call a potentially instrumented forbidden free needlessly. */ \
51 if (caa_unlikely(alloc_buff)) \
55 #define LTTNG_UST_TRACELOG_VALIST(fmt, ap, callback, ...) \
57 char local_buf[LTTNG_TRACE_PRINTF_BUFSIZE]; \
58 char *alloc_buff = NULL, *msg = local_buf; \
61 if (caa_unlikely(fmt[0] == '%' && fmt[1] == 's' && fmt[2] == '\0')) { \
62 msg = va_arg(ap, char *); \
65 size_t buflen = sizeof(local_buf); \
70 ret = vsnprintf(msg, buflen, fmt, ap2); \
72 if (caa_unlikely(ret < 0)) \
76 if (caa_unlikely(len >= sizeof(local_buf))) { \
78 alloc_buff = (char *)malloc(buflen); \
82 ret = vsnprintf(msg, buflen, fmt, ap); \
83 lttng_ust_runtime_bug_on(ret < 0 || (size_t)ret != buflen - 1); \
88 callback(__VA_ARGS__); \
90 /* Don't call a potentially instrumented forbidden free needlessly. */ \
91 if (caa_unlikely(alloc_buff)) \
This page took 0.032454 seconds and 5 git commands to generate.