From 49faeca7301c4081d16ef360636bc79077c9943f Mon Sep 17 00:00:00 2001 From: Mathieu Desnoyers Date: Wed, 16 Dec 2020 16:23:53 -0500 Subject: [PATCH] Fix: incorrect parameters passed to vtracelog The vtracelog APIs should be called from the vtracelog instrumentation rather than the "tracelog" APIs, because it passes a va_list rather than a variable argument list (...). This can be verified by tracing the demo program doc/examples/demo-tracelog/demo-vtracelog: Issue (corrupted trace output): 16:17:26.686073539] (+0.000000530) thinkos lttng_ust_tracelog:TRACE_ERR: { cpu_id = 2 }, { line = 31, file = "demo-vtracelog.c", func = "print_err", _msg_length = 49, msg = "This is a \"\b\" formatted 638975520 error event d68" } Fixed: [16:23:33.538189343] (+0.000000600) thinkos lttng_ust_tracelog:TRACE_ERR: { cpu_id = 3 }, { line = 31, file = "demo-vtracelog.c", func = "print_err", _msg_length = 52, msg = "This is a \"mystring test\" formatted 4 error event 42" } Signed-off-by: Mathieu Desnoyers Change-Id: I330e339a3bf68fb8d9779bbc71b08c3bc033ac4e --- include/lttng/tracelog.h | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/include/lttng/tracelog.h b/include/lttng/tracelog.h index 7aa86809..d4406a43 100644 --- a/include/lttng/tracelog.h +++ b/include/lttng/tracelog.h @@ -29,9 +29,11 @@ extern "C" { #endif -#define TP_TRACELOG_CB_TEMPLATE(level) \ - extern void _lttng_ust_tracelog_##level(const char *file, \ - int line, const char *func, const char *fmt, ...) +#define TP_TRACELOG_CB_TEMPLATE(level) \ + extern void _lttng_ust_tracelog_##level(const char *file, \ + int line, const char *func, const char *fmt, ...); \ + extern void _lttng_ust_vtracelog_##level(const char *file, \ + int line, const char *func, const char *fmt, va_list ap); TP_TRACELOG_CB_TEMPLATE(TRACE_EMERG); TP_TRACELOG_CB_TEMPLATE(TRACE_ALERT); @@ -56,14 +58,14 @@ TP_TRACELOG_CB_TEMPLATE(TRACE_DEBUG); LTTNG_STAP_PROBEV(tracepoint_lttng_ust_tracelog, level, ## __VA_ARGS__); \ if (caa_unlikely(__tracepoint_lttng_ust_tracelog___##level.state)) \ _lttng_ust_tracelog_##level(__FILE__, __LINE__, __func__, \ - fmt, ## __VA_ARGS__); \ + fmt, ## __VA_ARGS__); \ } while (0) #define vtracelog(level, fmt, ap) \ do { \ if (caa_unlikely(__tracepoint_lttng_ust_tracelog___##level.state)) \ - _lttng_ust_tracelog_##level(__FILE__, __LINE__, __func__, \ - fmt, ap); \ + _lttng_ust_vtracelog_##level(__FILE__, __LINE__, __func__, \ + fmt, ap); \ } while (0) #ifdef __cplusplus -- 2.34.1