Fix: tracepoint: Remove trailing \ at the end of macro
[lttng-ust.git] / include / lttng / ust-tracepoint-event.h
index c6dfed7ddc36700f1ab8d43430d3f676ed8f53d9..951c0f4ec3c9c431709b7a1f2b566c276708d3de 100644 (file)
@@ -257,9 +257,16 @@ void lttng_ust__event_template_proto___##_provider##___##_name(LTTNG_UST__TP_ARG
        };
 #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 */
@@ -288,6 +295,8 @@ void lttng_ust__event_template_proto___##_provider##___##_name(LTTNG_UST__TP_ARG
 
 #include LTTNG_UST_TRACEPOINT_INCLUDE
 
+#endif
+
 /*
  * Stage 0.9.2 of tracepoint event generation.
  *
@@ -329,6 +338,19 @@ static void lttng_ust__event_probe__##_provider##___##_name(LTTNG_UST__TP_ARGS_D
 
 #include LTTNG_UST_TRACEPOINT_INCLUDE
 
+/*
+ * Stage 1.1 of tracepoint event generation.
+ *
+ * Declare toplevel descriptor for the whole probe.
+ * Unlike C, C++ does not allow tentative definitions. Therefore, we
+ * need to explicitly declare the variable with "extern", using hidden
+ * visibility to keep this symbol from being exported to the global
+ * symbol table.
+ */
+
+extern const struct lttng_ust_probe_desc LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__probe_desc___, LTTNG_UST_TRACEPOINT_PROVIDER)
+       __attribute__((visibility("hidden")));
+
 /*
  * Stage 2 of tracepoint event generation.
  *
@@ -461,6 +483,7 @@ static void lttng_ust__event_probe__##_provider##___##_name(LTTNG_UST__TP_ARGS_D
                .nr_fields = LTTNG_UST__TP_ARRAY_SIZE(lttng_ust__event_fields___##_provider##___##_name) - 1, \
                .probe_callback = (void (*)(void)) &lttng_ust__event_probe__##_provider##___##_name, \
                .signature = __tp_event_signature___##_provider##___##_name,                         \
+               .probe_desc = &lttng_ust__probe_desc___##_provider,                                  \
        };
 
 #undef LTTNG_UST_TRACEPOINT_ENUM
@@ -470,6 +493,7 @@ static void lttng_ust__event_probe__##_provider##___##_name(LTTNG_UST__TP_ARGS_D
                .name = #_provider "_" #_name,                                          \
                .entries = __enum_values__##_provider##_##_name,                        \
                .nr_entries = LTTNG_UST__TP_ARRAY_SIZE(__enum_values__##_provider##_##_name) - 1,       \
+               .probe_desc = &lttng_ust__probe_desc___##_provider,                     \
        };
 
 #include LTTNG_UST_TRACEPOINT_INCLUDE
@@ -829,7 +853,7 @@ size_t lttng_ust__event_get_align__##_provider##___##_name(LTTNG_UST__TP_ARGS_PR
        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, \
@@ -1075,19 +1099,6 @@ LTTNG_UST_TP_EXTERN_C const char * const _model_emf_uri___##__provider##___##__n
 /*
  * Stage 7.0 of tracepoint event generation.
  *
- * Declare toplevel descriptor for the whole probe.
- * Unlike C, C++ does not allow tentative definitions. Therefore, we
- * need to explicitly declare the variable with "extern", using hidden
- * visibility to keep this symbol from being exported to the global
- * symbol table.
- */
-
-extern const struct lttng_ust_probe_desc LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__probe_desc___, LTTNG_UST_TRACEPOINT_PROVIDER)
-       __attribute__((visibility("hidden")));
-
-/*
- * Stage 7.1 of tracepoint event generation.
- *
  * Create events description structures. We use a weakref because
  * loglevels are optional. If not declared, the event will point to
  * a loglevel that contains NULL.
@@ -1122,7 +1133,7 @@ static const struct lttng_ust_event_desc lttng_ust__event_desc___##_provider##_#
 #include LTTNG_UST_TRACEPOINT_INCLUDE
 
 /*
- * Stage 7.2 of tracepoint event generation.
+ * Stage 7.1 of tracepoint event generation.
  *
  * Create array of events.
  */
@@ -1134,7 +1145,7 @@ static const struct lttng_ust_event_desc lttng_ust__event_desc___##_provider##_#
 #define LTTNG_UST__TRACEPOINT_EVENT_INSTANCE(_template_provider, _template_name, _provider, _name, _args) \
        &lttng_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. */
 };
@@ -1149,8 +1160,8 @@ static const struct lttng_ust_event_desc * const LTTNG_UST__TP_COMBINE_TOKENS(lt
 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,
 };
@@ -1167,13 +1178,24 @@ static struct lttng_ust_registered_probe *LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust
  * 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)
 {
@@ -1202,8 +1224,7 @@ LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__events_init__, LTTNG_UST_TRACEPOINT_PROV
 }
 
 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)
 {
@@ -1215,6 +1236,12 @@ LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__events_exit__, LTTNG_UST_TRACEPOINT_PROV
        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
This page took 0.026221 seconds and 4 git commands to generate.