-/*
- * SPDX-License-Identifier: MIT
- *
- * Copyright (C) 2011-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
- */
+// SPDX-FileCopyrightText: 2011-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
+//
+// SPDX-License-Identifier: MIT
#include <stdint.h>
#include <stdio.h>
};
#include LTTNG_UST_TRACEPOINT_INCLUDE
+
+/*
+ * Stage 0.9.0
+ * Verifying sequence length types are of an unsigned type.
+ */
+
+/* Reset all macros within LTTNG_UST_TRACEPOINT_EVENT */
+#include <lttng/ust-tracepoint-event-reset.h>
+#include <lttng/ust-tracepoint-event-write.h>
+#include <lttng/ust-tracepoint-event-nowrite.h>
+
+/*
+ * Note that it is not possible to encode the length type as a C identifier,
+ * since it can be multiple tokens.
+ */
+#undef lttng_ust__field_sequence_encoded
+#define lttng_ust__field_sequence_encoded(_type, _item, _src, _byte_order, \
+ _length_type, _src_length, _encoding, _nowrite, \
+ _elem_type_base) \
+ lttng_ust_static_assert(!lttng_ust_is_signed_type(_length_type), \
+ "Length type " #_length_type " is not a unsigned integer type", \
+ Length_type_is_not_a_unsigned_integer_type);
+
+#undef LTTNG_UST_TP_FIELDS
+#define LTTNG_UST_TP_FIELDS(...) __VA_ARGS__ /* Only one used in this phase */
+
+#undef LTTNG_UST__TRACEPOINT_EVENT_CLASS
+#define LTTNG_UST__TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
+ _fields
+
+#include LTTNG_UST_TRACEPOINT_INCLUDE
+
+#if defined(__cplusplus)
+
/*
* Stage 0.9.1
- * Verifying array and sequence elements are of an integer type.
+ * Verifying array and sequence elements are of an integer or pointer
+ * type.
+ *
+ * This compile-time check is only enabled in C++, because the C
+ * implementation of lttng_ust_is_pointer_type does not support opaque
+ * pointer types.
*/
/* Reset all macros within LTTNG_UST_TRACEPOINT_EVENT */
#include LTTNG_UST_TRACEPOINT_INCLUDE
+#endif
+
/*
* Stage 0.9.2 of tracepoint event generation.
*
if (lttng_ust_string_encoding_##_encoding == lttng_ust_string_encoding_none) \
__chan->ops->event_write(&__ctx, _src, sizeof(_type) * (_length), lttng_ust_rb_alignof(_type)); \
else \
- __chan->ops->event_pstrcpy_pad(&__ctx, (const char *) (_src), _length); \
+ __chan->ops->event_pstrcpy_pad(&__ctx, (const char *) (_src), _length);
#undef lttng_ust__field_sequence_encoded
#define lttng_ust__field_sequence_encoded(_type, _item, _src, _byte_order, _length_type, \
void lttng_ust__event_probe__##_provider##___##_name(LTTNG_UST__TP_ARGS_DATA_PROTO(_args)) \
{ \
struct lttng_ust_event_common *__event = (struct lttng_ust_event_common *) __tp_data; \
+ struct lttng_ust_channel_common *__chan_common; \
size_t __dynamic_len_idx = 0; \
const size_t __num_fields = LTTNG_UST__TP_ARRAY_SIZE(lttng_ust__event_fields___##_provider##___##_name) - 1; \
struct lttng_ust_probe_ctx __probe_ctx; \
\
if (0) \
(void) __dynamic_len_idx; /* don't warn if unused */ \
- switch (__event->type) { \
- case LTTNG_UST_EVENT_TYPE_RECORDER: \
- { \
- struct lttng_ust_event_recorder *__event_recorder = (struct lttng_ust_event_recorder *) __event->child; \
- struct lttng_ust_channel_buffer *__chan = __event_recorder->chan; \
- struct lttng_ust_channel_common *__chan_common = __chan->parent; \
- \
+ if (caa_unlikely(!CMM_ACCESS_ONCE(__event->enabled))) \
+ return; \
+ if (caa_unlikely(!LTTNG_UST_TP_RCU_LINK_TEST())) \
+ return; \
+ __chan_common = lttng_ust_get_chan_common_from_event_common(__event); \
+ if (__chan_common) { \
if (!LTTNG_UST__TP_SESSION_CHECK(session, __chan_common->session)) \
return; \
if (caa_unlikely(!CMM_ACCESS_ONCE(__chan_common->session->active))) \
return; \
if (caa_unlikely(!CMM_ACCESS_ONCE(__chan_common->enabled))) \
return; \
- break; \
- } \
- case LTTNG_UST_EVENT_TYPE_NOTIFIER: \
- break; \
} \
- if (caa_unlikely(!CMM_ACCESS_ONCE(__event->enabled))) \
- return; \
- if (caa_unlikely(!LTTNG_UST_TP_RCU_LINK_TEST())) \
- return; \
__probe_ctx.struct_size = sizeof(struct lttng_ust_probe_ctx); \
__probe_ctx.ip = LTTNG_UST__TP_IP_PARAM(LTTNG_UST_TP_IP_PARAM); \
if (caa_unlikely(CMM_ACCESS_ONCE(__event->eval_filter))) { \
&__notif_ctx); \
break; \
} \
+ case LTTNG_UST_EVENT_TYPE_COUNTER: \
+ { \
+ struct lttng_ust_event_counter *__event_counter = (struct lttng_ust_event_counter *) __event->child; \
+ struct lttng_ust_event_counter_ctx __event_counter_ctx; \
+ \
+ __event_counter_ctx.struct_size = sizeof(struct lttng_ust_event_counter_ctx); \
+ __event_counter_ctx.args_available = CMM_ACCESS_ONCE(__event_counter->use_args); \
+ \
+ if (caa_unlikely(!__interpreter_stack_prepared && __event_counter_ctx.args_available)) \
+ lttng_ust__event_prepare_interpreter_stack__##_provider##___##_name(__stackvar.__interpreter_stack_data, \
+ LTTNG_UST__TP_ARGS_DATA_VAR(_args)); \
+ \
+ (void) __event_counter->chan->ops->counter_hit(__event_counter, \
+ __stackvar.__interpreter_stack_data, \
+ &__probe_ctx, \
+ &__event_counter_ctx); \
+ break; \
+ } \
} \
}
#define LTTNG_UST__TRACEPOINT_EVENT_INSTANCE(_template_provider, _template_name, _provider, _name, _args) \
<tng_ust__event_desc___##_provider##_##_name,
-static const struct lttng_ust_event_desc * const LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__event_desc___, LTTNG_UST_TRACEPOINT_PROVIDER)[] = {
+static const struct lttng_ust_event_desc * const LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__provider_event_desc___, LTTNG_UST_TRACEPOINT_PROVIDER)[] = {
#include LTTNG_UST_TRACEPOINT_INCLUDE
NULL, /* Dummy, C99 forbids 0-len array. */
};
const struct lttng_ust_probe_desc LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__probe_desc___, LTTNG_UST_TRACEPOINT_PROVIDER) = {
.struct_size = sizeof(struct lttng_ust_probe_desc),
.provider_name = lttng_ust__tp_stringify(LTTNG_UST_TRACEPOINT_PROVIDER),
- .event_desc = LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__event_desc___, LTTNG_UST_TRACEPOINT_PROVIDER),
- .nr_events = LTTNG_UST__TP_ARRAY_SIZE(LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__event_desc___, LTTNG_UST_TRACEPOINT_PROVIDER)) - 1,
+ .event_desc = LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__provider_event_desc___, LTTNG_UST_TRACEPOINT_PROVIDER),
+ .nr_events = LTTNG_UST__TP_ARRAY_SIZE(LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__provider_event_desc___, LTTNG_UST_TRACEPOINT_PROVIDER)) - 1,
.major = LTTNG_UST_PROVIDER_MAJOR,
.minor = LTTNG_UST_PROVIDER_MINOR,
};
* linking the probe statically.
*
* Register refcount is protected by libc dynamic loader mutex.
+ *
+ * Note that when building this code as C++, the definition of constructors
+ * and destructors invoking the registration and unregistration functions
+ * must be performed _after_ the initialization of the probes.
+ *
+ * This is because we rely on the order of initialization of static variables
+ * and anonymous namespaces (their order of declaration) to ensure probes are
+ * fully initialized, see
+ * https://en.cppreference.com/w/cpp/language/initialization. This is especially
+ * important when LTTNG_UST_ALLOCATE_COMPOUND_LITERAL_ON_HEAP is defined as
+ * compound literals are then dynamically initialized.
*/
/* Reset all macros within LTTNG_UST_TRACEPOINT_EVENT */
#include <lttng/ust-tracepoint-event-reset.h>
+
static void
-LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__events_init__, LTTNG_UST_TRACEPOINT_PROVIDER)(void)
- lttng_ust_notrace __attribute__((constructor));
+LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__events_init__, LTTNG_UST_TRACEPOINT_PROVIDER)(void) lttng_ust_notrace;
static void
LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__events_init__, LTTNG_UST_TRACEPOINT_PROVIDER)(void)
{
}
static void
-LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__events_exit__, LTTNG_UST_TRACEPOINT_PROVIDER)(void)
- lttng_ust_notrace __attribute__((destructor));
+LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__events_exit__, LTTNG_UST_TRACEPOINT_PROVIDER)(void) lttng_ust_notrace;
static void
LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__events_exit__, LTTNG_UST_TRACEPOINT_PROVIDER)(void)
{
LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__probe_register_cookie___, LTTNG_UST_TRACEPOINT_PROVIDER) = NULL;
}
+LTTNG_UST_DECLARE_CONSTRUCTOR_DESTRUCTOR(
+ LTTNG_UST_TRACEPOINT_PROVIDER,
+ LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__events_init__, LTTNG_UST_TRACEPOINT_PROVIDER),
+ LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__events_exit__, LTTNG_UST_TRACEPOINT_PROVIDER),
+ lttng_ust_notrace)
+
/*
* LTTNG_UST_TRACEPOINT_PROVIDER_HIDDEN_DEFINITION: Define this before
* including a tracepoint instrumentation header to hide symbols