Fix: __string() and tp_strcpy() should handle NULL pointers
[lttng-modules.git] / probes / lttng-events.h
index 7963096a93d020061dc25df3fe70a7c65a0af5e5..db445f1adea405038b55b8dea2e56e7769e0e6d9 100644 (file)
@@ -28,6 +28,8 @@
 #include "../lttng-events.h"
 #include "../lttng-tracer-core.h"
 
+#define __LTTNG_NULL_STRING    "(null)"
+
 /*
  * Macro declarations used for all stages.
  */
@@ -185,6 +187,40 @@ void trace_##_name(void);
 
 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
 
+/*
+ * Stage 1.1 of the trace events.
+ *
+ * Create dummy trace prototypes for each event class, and for each used
+ * template. This will allow checking whether the prototypes from the
+ * class and the instance using the class actually match.
+ */
+
+#include "lttng-events-reset.h"        /* Reset all macros within TRACE_EVENT */
+
+#undef TP_PROTO
+#define TP_PROTO(args...) args
+
+#undef TP_ARGS
+#define TP_ARGS(args...) args
+
+#undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP
+#define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(_template, _name, _map, _proto, _args) \
+void __event_template_proto___##_template(_proto);
+
+#undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS
+#define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(_template, _name, _map) \
+void __event_template_proto___##_template(void);
+
+#undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
+#define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code, _tstruct, _assign, _print) \
+void __event_template_proto___##_name(_proto);
+
+#undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
+#define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code, _tstruct, _assign, _print) \
+void __event_template_proto___##_name(void);
+
+#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
+
 /*
  * Stage 2 of the trace events.
  *
@@ -471,7 +507,8 @@ static __used struct lttng_probe_desc TP_ID(__probe_desc___, TRACE_SYSTEM) = {
 
 #undef __string
 #define __string(_item, _src)                                                 \
-       __event_len += __dynamic_len[__dynamic_len_idx++] = strlen(_src) + 1;
+       __event_len += __dynamic_len[__dynamic_len_idx++] =                    \
+               strlen((_src) ? (_src) : __LTTNG_NULL_STRING) + 1;
 
 /*
  * strlen_user includes \0. If returns 0, it faulted, so we set size to
@@ -780,8 +817,12 @@ __assign_##dest:                                                   \
 __assign_##dest:                                                       \
        if (0)                                                          \
                (void) __typemap.dest;                                  \
-       lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__typemap.dest)); \
-       __chan->ops->event_strcpy(&__ctx, src, __get_dynamic_array_len(dest)); \
+       {                                                               \
+               const char *__ctf_tmp_string =                          \
+                       ((src) ? (src) : __LTTNG_NULL_STRING);          \
+               lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__typemap.dest)); \
+               __chan->ops->event_strcpy(&__ctx, __ctf_tmp_string, __get_dynamic_array_len(dest)); \
+       }                                                               \
        goto __end_field_##dest;
 
 /* Named field types must be defined in lttng-types.h */
This page took 0.024625 seconds and 4 git commands to generate.