From 5152f6df156d6ccb234965d1b3d26b167bd6b94e Mon Sep 17 00:00:00 2001 From: Michael Jeanson Date: Wed, 31 Mar 2021 17:52:30 -0400 Subject: [PATCH] Add 'ctf_unused' tracepoint field type Some tracepoint definitions have one or more arguments that don't have a corresponding field to allow passing a value to a probe without recording it in the trace buffer nor using it in the filter. This results in tracepoint macros generating inline functions with unused arguments which prevents us from turning on -Wunuse-parameter. Add a new tracepoint field type name 'ctf_unused' to adress this and properly handle unused values in the tracepoint macros. [ Mathieu: ctf_unused() takes only the _src parameter, no "type", because an unused "field" does not have any representation in the ring buffer nor the filter. If this ends up limiting us in the future, I accept all the blame. ] Change-Id: I56d8024926340e9c965ca01fa24a0fff7b7c5baa Signed-off-by: Michael Jeanson Signed-off-by: Mathieu Desnoyers --- include/lttng/tp/lttng-ust-tracef.h | 1 + include/lttng/tp/lttng-ust-tracelog.h | 1 + include/lttng/ust-tracepoint-event-nowrite.h | 4 ++ include/lttng/ust-tracepoint-event-reset.h | 9 +++ include/lttng/ust-tracepoint-event-write.h | 4 ++ include/lttng/ust-tracepoint-event.h | 56 +++++++++++++++++-- .../lttng-ust-cyg-profile-fast.h | 4 +- liblttng-ust-dl/ust_dl.h | 5 ++ liblttng-ust-libc-wrapper/ust_libc.h | 6 ++ liblttng-ust-libc-wrapper/ust_pthread.h | 4 ++ liblttng-ust/lttng-ust-statedump-provider.h | 12 +++- liblttng-ust/ust_lib.h | 4 ++ 12 files changed, 103 insertions(+), 7 deletions(-) diff --git a/include/lttng/tp/lttng-ust-tracef.h b/include/lttng/tp/lttng-ust-tracef.h index 785f2132..4feeb694 100644 --- a/include/lttng/tp/lttng-ust-tracef.h +++ b/include/lttng/tp/lttng-ust-tracef.h @@ -11,6 +11,7 @@ TRACEPOINT_EVENT(lttng_ust_tracef, event, TP_ARGS(const char *, msg, unsigned int, len, void *, ip), TP_FIELDS( ctf_sequence_text(char, msg, msg, unsigned int, len) + ctf_unused(ip) ) ) TRACEPOINT_LOGLEVEL(lttng_ust_tracef, event, TRACE_DEBUG) diff --git a/include/lttng/tp/lttng-ust-tracelog.h b/include/lttng/tp/lttng-ust-tracelog.h index abc66a0c..95564707 100644 --- a/include/lttng/tp/lttng-ust-tracelog.h +++ b/include/lttng/tp/lttng-ust-tracelog.h @@ -15,6 +15,7 @@ TRACEPOINT_EVENT_CLASS(lttng_ust_tracelog, tlclass, ctf_string(file, file) ctf_string(func, func) ctf_sequence_text(char, msg, msg, unsigned int, len) + ctf_unused(ip) ) ) diff --git a/include/lttng/ust-tracepoint-event-nowrite.h b/include/lttng/ust-tracepoint-event-nowrite.h index 57a970d1..3193d702 100644 --- a/include/lttng/ust-tracepoint-event-nowrite.h +++ b/include/lttng/ust-tracepoint-event-nowrite.h @@ -63,6 +63,10 @@ #define ctf_string_nowrite(_item, _src) \ _ctf_string(_item, _src, 1) +#undef ctf_unused_nowrite +#define ctf_unused_nowrite(_src) \ + _ctf_unused(_src) + #undef ctf_enum_nowrite #define ctf_enum_nowrite(_provider, _name, _type, _item, _src) \ _ctf_enum(_provider, _name, _type, _item, _src, 1) diff --git a/include/lttng/ust-tracepoint-event-reset.h b/include/lttng/ust-tracepoint-event-reset.h index acc1207b..d42213d1 100644 --- a/include/lttng/ust-tracepoint-event-reset.h +++ b/include/lttng/ust-tracepoint-event-reset.h @@ -48,6 +48,9 @@ #undef _ctf_string #define _ctf_string(_item, _src, _nowrite) +#undef _ctf_unused +#define _ctf_unused(_src) + #undef _ctf_enum #define _ctf_enum(_provider, _name, _type, _item, _src, _nowrite) @@ -100,6 +103,9 @@ #undef ctf_string #define ctf_string(_item, _src) +#undef ctf_unused +#define ctf_unused(_src) + #undef ctf_enum #define ctf_enum(_provider, _name, _type, _item, _src) @@ -143,5 +149,8 @@ #undef ctf_string_nowrite #define ctf_string_nowrite(_item, _src) +#undef ctf_unused_nowrite +#define ctf_unused_nowrite(_src) + #undef ctf_enum_nowrite #define ctf_enum_nowrite(_provider, _name, _type, _item, _src) diff --git a/include/lttng/ust-tracepoint-event-write.h b/include/lttng/ust-tracepoint-event-write.h index 17afbc8c..87f621cd 100644 --- a/include/lttng/ust-tracepoint-event-write.h +++ b/include/lttng/ust-tracepoint-event-write.h @@ -78,6 +78,10 @@ #define ctf_string(_item, _src) \ _ctf_string(_item, _src, 0) +#undef ctf_unused +#define ctf_unused(_src) \ + _ctf_unused(_src) + #undef ctf_enum #define ctf_enum(_provider, _name, _type, _item, _src) \ _ctf_enum(_provider, _name, _type, _item, _src, 0) diff --git a/include/lttng/ust-tracepoint-event.h b/include/lttng/ust-tracepoint-event.h index c4ec05eb..fe96bf24 100644 --- a/include/lttng/ust-tracepoint-event.h +++ b/include/lttng/ust-tracepoint-event.h @@ -340,6 +340,9 @@ void __event_template_proto___##_provider##___##_name(_TP_ARGS_DATA_PROTO(_args) .nofilter = 0, \ }), +#undef _ctf_unused +#define _ctf_unused(_src) + #undef _ctf_enum #define _ctf_enum(_provider, _name, _type, _item, _src, _nowrite) \ __LTTNG_COMPOUND_LITERAL(struct lttng_ust_event_field, { \ @@ -408,23 +411,31 @@ static void __event_probe__##_provider##___##_name(_TP_ARGS_DATA_PROTO(_args)); #undef _ctf_integer_ext #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \ + if (0) \ + (void) (_src); /* Unused */ \ __event_len += lttng_ust_lib_ring_buffer_align(__event_len, lttng_ust_rb_alignof(_type)); \ __event_len += sizeof(_type); #undef _ctf_float #define _ctf_float(_type, _item, _src, _nowrite) \ + if (0) \ + (void) (_src); /* Unused */ \ __event_len += lttng_ust_lib_ring_buffer_align(__event_len, lttng_ust_rb_alignof(_type)); \ __event_len += sizeof(_type); #undef _ctf_array_encoded #define _ctf_array_encoded(_type, _item, _src, _byte_order, _length, _encoding, \ _nowrite, _elem_type_base) \ + if (0) \ + (void) (_src); /* Unused */ \ __event_len += lttng_ust_lib_ring_buffer_align(__event_len, lttng_ust_rb_alignof(_type)); \ __event_len += sizeof(_type) * (_length); #undef _ctf_sequence_encoded #define _ctf_sequence_encoded(_type, _item, _src, _byte_order, _length_type, \ _src_length, _encoding, _nowrite, _elem_type_base) \ + if (0) \ + (void) (_src); /* Unused */ \ __event_len += lttng_ust_lib_ring_buffer_align(__event_len, lttng_ust_rb_alignof(_length_type)); \ __event_len += sizeof(_length_type); \ __event_len += lttng_ust_lib_ring_buffer_align(__event_len, lttng_ust_rb_alignof(_type)); \ @@ -437,6 +448,11 @@ static void __event_probe__##_provider##___##_name(_TP_ARGS_DATA_PROTO(_args)); __event_len += __dynamic_len[__dynamic_len_idx++] = \ strlen((_src) ? (_src) : __LTTNG_UST_NULL_STRING) + 1; +#undef _ctf_unused +#define _ctf_unused(_src) \ + if (0) \ + (void) (_src); /* Unused */ + #undef _ctf_enum #define _ctf_enum(_provider, _name, _type, _item, _src, _nowrite) \ _ctf_integer_ext(_type, _item, _src, BYTE_ORDER, 10, _nowrite) @@ -453,13 +469,16 @@ static inline \ size_t __event_get_size__##_provider##___##_name(size_t *__dynamic_len, _TP_ARGS_DATA_PROTO(_args)) \ lttng_ust_notrace; \ static inline \ -size_t __event_get_size__##_provider##___##_name(size_t *__dynamic_len, _TP_ARGS_DATA_PROTO(_args)) \ +size_t __event_get_size__##_provider##___##_name( \ + size_t *__dynamic_len __attribute__((__unused__)), \ + _TP_ARGS_DATA_PROTO(_args)) \ { \ size_t __event_len = 0; \ - unsigned int __dynamic_len_idx = 0; \ + unsigned int __dynamic_len_idx __attribute__((__unused__)) = 0; \ \ if (0) \ - (void) __dynamic_len_idx; /* don't warn if unused */ \ + (void) __tp_data; /* don't warn if unused */ \ + \ _fields \ return __event_len; \ } @@ -598,6 +617,11 @@ size_t __event_get_size__##_provider##___##_name(size_t *__dynamic_len, _TP_ARGS __stack_data += sizeof(void *); \ } +#undef _ctf_unused +#define _ctf_unused(_src) \ + if (0) \ + (void) (_src); + #undef _ctf_enum #define _ctf_enum(_provider, _name, _type, _item, _src, _nowrite) \ _ctf_integer_ext(_type, _item, _src, BYTE_ORDER, 10, _nowrite) @@ -614,6 +638,11 @@ static inline \ void __event_prepare_interpreter_stack__##_provider##___##_name(char *__stack_data,\ _TP_ARGS_DATA_PROTO(_args)) \ { \ + if (0) { \ + (void) __tp_data; /* don't warn if unused */ \ + (void) __stack_data; /* don't warn if unused */ \ + } \ + \ _fields \ } @@ -631,25 +660,42 @@ void __event_prepare_interpreter_stack__##_provider##___##_name(char *__stack_da #undef _ctf_integer_ext #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \ + if (0) \ + (void) (_src); /* Unused */ \ __event_align = _tp_max_t(size_t, __event_align, lttng_ust_rb_alignof(_type)); #undef _ctf_float #define _ctf_float(_type, _item, _src, _nowrite) \ + if (0) \ + (void) (_src); /* Unused */ \ __event_align = _tp_max_t(size_t, __event_align, lttng_ust_rb_alignof(_type)); #undef _ctf_array_encoded #define _ctf_array_encoded(_type, _item, _src, _byte_order, _length, \ _encoding, _nowrite, _elem_type_base) \ + if (0) \ + (void) (_src); /* Unused */ \ __event_align = _tp_max_t(size_t, __event_align, lttng_ust_rb_alignof(_type)); #undef _ctf_sequence_encoded #define _ctf_sequence_encoded(_type, _item, _src, _byte_order, _length_type, \ _src_length, _encoding, _nowrite, _elem_type_base) \ + if (0) \ + (void) (_src); /* Unused */ \ + if (0) \ + (void) (_src_length); /* Unused */ \ __event_align = _tp_max_t(size_t, __event_align, lttng_ust_rb_alignof(_length_type)); \ __event_align = _tp_max_t(size_t, __event_align, lttng_ust_rb_alignof(_type)); #undef _ctf_string -#define _ctf_string(_item, _src, _nowrite) +#define _ctf_string(_item, _src, _nowrite) \ + if (0) \ + (void) (_src); /* Unused */ + +#undef _ctf_unused +#define _ctf_unused(_src) \ + if (0) \ + (void) (_src); /* Unused */ #undef _ctf_enum #define _ctf_enum(_provider, _name, _type, _item, _src, _nowrite) \ @@ -732,6 +778,8 @@ size_t __event_get_align__##_provider##___##_name(_TP_ARGS_PROTO(_args)) \ __get_dynamic_len(dest)); \ } +#undef _ctf_unused +#define _ctf_unused(_src) #undef _ctf_enum #define _ctf_enum(_provider, _name, _type, _item, _src, _nowrite) \ diff --git a/liblttng-ust-cyg-profile/lttng-ust-cyg-profile-fast.h b/liblttng-ust-cyg-profile/lttng-ust-cyg-profile-fast.h index 9dbe9da2..f2cdaabe 100644 --- a/liblttng-ust-cyg-profile/lttng-ust-cyg-profile-fast.h +++ b/liblttng-ust-cyg-profile/lttng-ust-cyg-profile-fast.h @@ -29,7 +29,9 @@ TRACEPOINT_LOGLEVEL(lttng_ust_cyg_profile_fast, func_entry, TRACEPOINT_EVENT(lttng_ust_cyg_profile_fast, func_exit, TP_ARGS(void *, func_addr), - TP_FIELDS() + TP_FIELDS( + ctf_unused(func_addr) + ) ) TRACEPOINT_LOGLEVEL(lttng_ust_cyg_profile_fast, func_exit, diff --git a/liblttng-ust-dl/ust_dl.h b/liblttng-ust-dl/ust_dl.h index 94fc87ef..7f618da7 100644 --- a/liblttng-ust-dl/ust_dl.h +++ b/liblttng-ust-dl/ust_dl.h @@ -27,6 +27,7 @@ TRACEPOINT_EVENT(lttng_ust_dl, dlopen, int, flags, uint64_t, memsz, uint8_t, has_build_id, uint8_t, has_debug_link), TP_FIELDS( + ctf_unused(ip) ctf_integer_hex(void *, baddr, baddr) ctf_integer(uint64_t, memsz, memsz) ctf_integer_hex(int, flags, flags) @@ -43,6 +44,7 @@ TRACEPOINT_EVENT(lttng_ust_dl, dlmopen, uint64_t, memsz, uint8_t, has_build_id, uint8_t, has_debug_link), TP_FIELDS( + ctf_unused(ip) ctf_integer_hex(void *, baddr, baddr) ctf_integer(uint64_t, memsz, memsz) ctf_integer(Lmid_t, nsid, nsid) @@ -62,6 +64,7 @@ TRACEPOINT_EVENT(lttng_ust_dl, build_id, size_t, build_id_len ), TP_FIELDS( + ctf_unused(ip) ctf_integer_hex(void *, baddr, baddr) ctf_sequence_hex(uint8_t, build_id, build_id, size_t, build_id_len) @@ -76,6 +79,7 @@ TRACEPOINT_EVENT(lttng_ust_dl, debug_link, uint32_t, crc ), TP_FIELDS( + ctf_unused(ip) ctf_integer_hex(void *, baddr, baddr) ctf_integer(uint32_t, crc, crc) ctf_string(filename, filename) @@ -85,6 +89,7 @@ TRACEPOINT_EVENT(lttng_ust_dl, debug_link, TRACEPOINT_EVENT(lttng_ust_dl, dlclose, TP_ARGS(void *, ip, void *, baddr), TP_FIELDS( + ctf_unused(ip) ctf_integer_hex(void *, baddr, baddr) ) ) diff --git a/liblttng-ust-libc-wrapper/ust_libc.h b/liblttng-ust-libc-wrapper/ust_libc.h index 77056691..6aaef22b 100644 --- a/liblttng-ust-libc-wrapper/ust_libc.h +++ b/liblttng-ust-libc-wrapper/ust_libc.h @@ -21,6 +21,7 @@ TRACEPOINT_EVENT(lttng_ust_libc, malloc, TP_FIELDS( ctf_integer(size_t, size, size) ctf_integer_hex(void *, ptr, ptr) + ctf_unused(ip) ) ) @@ -28,6 +29,7 @@ TRACEPOINT_EVENT(lttng_ust_libc, free, TP_ARGS(void *, ptr, void *, ip), TP_FIELDS( ctf_integer_hex(void *, ptr, ptr) + ctf_unused(ip) ) ) @@ -37,6 +39,7 @@ TRACEPOINT_EVENT(lttng_ust_libc, calloc, ctf_integer(size_t, nmemb, nmemb) ctf_integer(size_t, size, size) ctf_integer_hex(void *, ptr, ptr) + ctf_unused(ip) ) ) @@ -46,6 +49,7 @@ TRACEPOINT_EVENT(lttng_ust_libc, realloc, ctf_integer_hex(void *, in_ptr, in_ptr) ctf_integer(size_t, size, size) ctf_integer_hex(void *, ptr, ptr) + ctf_unused(ip) ) ) @@ -55,6 +59,7 @@ TRACEPOINT_EVENT(lttng_ust_libc, memalign, ctf_integer(size_t, alignment, alignment) ctf_integer(size_t, size, size) ctf_integer_hex(void *, ptr, ptr) + ctf_unused(ip) ) ) @@ -65,6 +70,7 @@ TRACEPOINT_EVENT(lttng_ust_libc, posix_memalign, ctf_integer(size_t, alignment, alignment) ctf_integer(size_t, size, size) ctf_integer(int, result, result) + ctf_unused(ip) ) ) diff --git a/liblttng-ust-libc-wrapper/ust_pthread.h b/liblttng-ust-libc-wrapper/ust_pthread.h index 7296bf4c..4fdc11aa 100644 --- a/liblttng-ust-libc-wrapper/ust_pthread.h +++ b/liblttng-ust-libc-wrapper/ust_pthread.h @@ -20,6 +20,7 @@ TRACEPOINT_EVENT(lttng_ust_pthread, pthread_mutex_lock_req, TP_ARGS(pthread_mutex_t *, mutex, void *, ip), TP_FIELDS( ctf_integer_hex(void *, mutex, mutex) + ctf_unused(ip) ) ) @@ -28,6 +29,7 @@ TRACEPOINT_EVENT(lttng_ust_pthread, pthread_mutex_lock_acq, TP_FIELDS( ctf_integer_hex(void *, mutex, mutex) ctf_integer(int, status, status) + ctf_unused(ip) ) ) @@ -36,6 +38,7 @@ TRACEPOINT_EVENT(lttng_ust_pthread, pthread_mutex_trylock, TP_FIELDS( ctf_integer_hex(void *, mutex, mutex) ctf_integer(int, status, status) + ctf_unused(ip) ) ) @@ -44,6 +47,7 @@ TRACEPOINT_EVENT(lttng_ust_pthread, pthread_mutex_unlock, TP_FIELDS( ctf_integer_hex(void *, mutex, mutex) ctf_integer(int, status, status) + ctf_unused(ip) ) ) diff --git a/liblttng-ust/lttng-ust-statedump-provider.h b/liblttng-ust/lttng-ust-statedump-provider.h index 4529369d..cab628aa 100644 --- a/liblttng-ust/lttng-ust-statedump-provider.h +++ b/liblttng-ust/lttng-ust-statedump-provider.h @@ -26,7 +26,9 @@ extern "C" { TRACEPOINT_EVENT(lttng_ust_statedump, start, TP_ARGS(struct lttng_ust_session *, session), - TP_FIELDS() + TP_FIELDS( + ctf_unused(session) + ) ) TRACEPOINT_EVENT(lttng_ust_statedump, bin_info, @@ -40,6 +42,7 @@ TRACEPOINT_EVENT(lttng_ust_statedump, bin_info, uint8_t, has_debug_link ), TP_FIELDS( + ctf_unused(session) ctf_integer_hex(void *, baddr, baddr) ctf_integer(uint64_t, memsz, memsz) ctf_string(path, path) @@ -57,6 +60,7 @@ TRACEPOINT_EVENT(lttng_ust_statedump, build_id, size_t, build_id_len ), TP_FIELDS( + ctf_unused(session) ctf_integer_hex(void *, baddr, baddr) ctf_sequence_hex(uint8_t, build_id, build_id, size_t, build_id_len) @@ -71,6 +75,7 @@ TRACEPOINT_EVENT(lttng_ust_statedump, debug_link, uint32_t, crc ), TP_FIELDS( + ctf_unused(session) ctf_integer_hex(void *, baddr, baddr) ctf_integer(uint32_t, crc, crc) ctf_string(filename, filename) @@ -83,13 +88,16 @@ TRACEPOINT_EVENT(lttng_ust_statedump, procname, char *, name ), TP_FIELDS( + ctf_unused(session) ctf_array_text(char, procname, name, LTTNG_UST_ABI_PROCNAME_LEN) ) ) TRACEPOINT_EVENT(lttng_ust_statedump, end, TP_ARGS(struct lttng_ust_session *, session), - TP_FIELDS() + TP_FIELDS( + ctf_unused(session) + ) ) #endif /* _TRACEPOINT_LTTNG_UST_STATEDUMP_H */ diff --git a/liblttng-ust/ust_lib.h b/liblttng-ust/ust_lib.h index ca525d40..f704efb6 100644 --- a/liblttng-ust/ust_lib.h +++ b/liblttng-ust/ust_lib.h @@ -28,6 +28,7 @@ TRACEPOINT_EVENT(lttng_ust_lib, load, uint64_t, memsz, uint8_t, has_build_id, uint8_t, has_debug_link), TP_FIELDS( + ctf_unused(ip) ctf_integer_hex(void *, baddr, baddr) ctf_integer(uint64_t, memsz, memsz) ctf_string(path, path) @@ -44,6 +45,7 @@ TRACEPOINT_EVENT(lttng_ust_lib, build_id, size_t, build_id_len ), TP_FIELDS( + ctf_unused(ip) ctf_integer_hex(void *, baddr, baddr) ctf_sequence_hex(uint8_t, build_id, build_id, size_t, build_id_len) @@ -58,6 +60,7 @@ TRACEPOINT_EVENT(lttng_ust_lib, debug_link, uint32_t, crc ), TP_FIELDS( + ctf_unused(ip) ctf_integer_hex(void *, baddr, baddr) ctf_integer(uint32_t, crc, crc) ctf_string(filename, filename) @@ -67,6 +70,7 @@ TRACEPOINT_EVENT(lttng_ust_lib, debug_link, TRACEPOINT_EVENT(lttng_ust_lib, unload, TP_ARGS(void *, ip, void *, baddr), TP_FIELDS( + ctf_unused(ip) ctf_integer_hex(void *, baddr, baddr) ) ) -- 2.34.1