Fix: convey enum value signedness into metadata
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Sun, 20 Mar 2016 18:11:29 +0000 (14:11 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Mon, 21 Mar 2016 16:13:26 +0000 (12:13 -0400)
Currently, passing an enum range of:

  ctf_enum_range("blah", 0, UINT_MAX)

will print a range of 0 ... -1 in the generated CTF metadata, which does
not reflect signedness of the values.

Also, struct ustctl_enum_entry is missing a LTTNG_PACKED attribute,
which is against our protocol rules.

This change needs to be pushed in locked-step into lttng-tools and
lttng-ust, since it breaks the protocol between the two when UST uses
the new enumeration type (introduced in 2.8.0-rc1).

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
include/lttng/ust-ctl.h
include/lttng/ust-events.h
include/lttng/ust-tracepoint-event.h
liblttng-ust-comm/lttng-ust-comm.c
liblttng-ust/lttng-ust-dynamic-type.c

index 379ad41f5253f205d0e7d3917176abe4fa4f6358..06de95c25ee12160b8fefcd545ac5eff961341cb 100644 (file)
@@ -320,12 +320,19 @@ struct ustctl_float_type {
        char padding[USTCTL_UST_FLOAT_TYPE_PADDING];
 } LTTNG_PACKED;
 
+#define USTCTL_UST_ENUM_VALUE_PADDING  15
+struct ustctl_enum_value {
+       uint64_t value;
+       uint8_t signedness;
+       char padding[USTCTL_UST_ENUM_VALUE_PADDING];
+} LTTNG_PACKED;
+
 #define USTCTL_UST_ENUM_ENTRY_PADDING  32
 struct ustctl_enum_entry {
-       uint64_t start, end;            /* start and end are inclusive */
+       struct ustctl_enum_value start, end; /* start and end are inclusive */
        char string[LTTNG_UST_SYM_NAME_LEN];
        char padding[USTCTL_UST_ENUM_ENTRY_PADDING];
-};
+} LTTNG_PACKED;
 
 #define USTCTL_UST_BASIC_TYPE_PADDING  296
 union _ustctl_basic_type {
index 9eed21ef0b2867c40b19e21144641a19aafc73d8..1acba2ad6ff7669cf09f7b5435c22761255971c5 100644 (file)
@@ -101,9 +101,14 @@ enum lttng_string_encodings {
        NR_STRING_ENCODINGS,
 };
 
+struct lttng_enum_value {
+       unsigned long long value;
+       unsigned int signedness:1;
+};
+
 #define LTTNG_UST_ENUM_ENTRY_PADDING   16
 struct lttng_enum_entry {
-       unsigned long long start, end;  /* start and end are inclusive */
+       struct lttng_enum_value start, end; /* start and end are inclusive */
        const char *string;
        char padding[LTTNG_UST_ENUM_ENTRY_PADDING];
 };
index 26ca1d57c53220196ce3ecf1e74593a139a7a626..92edc455f3ddde03bd3817b82bf7d7d3ae177667 100644 (file)
@@ -129,12 +129,36 @@ static const char                                                 \
 /* Enumeration entry (single value) */
 #undef ctf_enum_value
 #define ctf_enum_value(_string, _value)                                        \
-       { _value, _value, _string },
+       {                                                               \
+               .start = {                                              \
+                       .signedness = lttng_is_signed_type(__typeof__(_value)), \
+                       .value = lttng_is_signed_type(__typeof__(_value)) ? \
+                               (long long) (_value) : (_value),        \
+               },                                                      \
+               .end = {                                                \
+                       .signedness = lttng_is_signed_type(__typeof__(_value)), \
+                       .value = lttng_is_signed_type(__typeof__(_value)) ? \
+                               (long long) (_value) : (_value),        \
+               },                                                      \
+               .string = (_string),                                    \
+       },
 
 /* Enumeration entry (range) */
 #undef ctf_enum_range
 #define ctf_enum_range(_string, _range_start, _range_end)              \
-       { _range_start, _range_end, _string },
+       {                                                               \
+               .start = {                                              \
+                       .signedness = lttng_is_signed_type(__typeof__(_range_start)), \
+                       .value = lttng_is_signed_type(__typeof__(_range_start)) ? \
+                               (long long) (_range_start) : (_range_start), \
+               },                                                      \
+               .end = {                                                \
+                       .signedness = lttng_is_signed_type(__typeof__(_range_end)), \
+                       .value = lttng_is_signed_type(__typeof__(_range_end)) ? \
+                               (long long) (_range_end) : (_range_end), \
+               },                                                      \
+               .string = (_string),                                    \
+       },
 
 #undef TP_ENUM_VALUES
 #define TP_ENUM_VALUES(...)                                            \
index 2c54a443566a7fca4bc7e919d5bec6608f1fd176..ecc23821fb6fa29624dcbc25564c5011eed4aafb 100644 (file)
@@ -1088,8 +1088,10 @@ int serialize_entries(struct ustctl_enum_entry **_entries,
                uentry = &entries[i];
                lentry = &lttng_entries[i];
 
-               uentry->start = lentry->start;
-               uentry->end = lentry->end;
+               uentry->start.value = lentry->start.value;
+               uentry->start.signedness = lentry->start.signedness;
+               uentry->end.value = lentry->end.value;
+               uentry->end.signedness = lentry->end.signedness;
                strncpy(uentry->string, lentry->string, LTTNG_UST_SYM_NAME_LEN);
                uentry->string[LTTNG_UST_SYM_NAME_LEN - 1] = '\0';
        }
index c654f019b715769749a8575b40dc4a0e8d927433..488cf8156cba55587a4b391137ef57c90ec4abc0 100644 (file)
 #include <helper.h>
 #include <lttng/ust-dynamic-type.h>
 
-static const struct lttng_enum_entry dt_enum[_NR_LTTNG_UST_DYNAMIC_TYPES] = {
-       [LTTNG_UST_DYNAMIC_TYPE_NONE] = {
-               .start = 0,
-               .end = 0,
-               .string = "_none",
-       },
-       [LTTNG_UST_DYNAMIC_TYPE_S8] = {
-               .start = 1,
-               .end = 1,
-               .string = "_int8",
-       },
-       [LTTNG_UST_DYNAMIC_TYPE_S16] = {
-               .start = 2,
-               .end = 2,
-               .string = "_int16",
-       },
-       [LTTNG_UST_DYNAMIC_TYPE_S32] = {
-               .start = 3,
-               .end = 3,
-               .string = "_int32",
-       },
-       [LTTNG_UST_DYNAMIC_TYPE_S64] = {
-               .start = 4,
-               .end = 4,
-               .string = "_int64",
-       },
-       [LTTNG_UST_DYNAMIC_TYPE_U8] = {
-               .start = 5,
-               .end = 5,
-               .string = "_uint8",
-       },
-       [LTTNG_UST_DYNAMIC_TYPE_U16] = {
-               .start = 6,
-               .end = 6,
-               .string = "_uint16",
-       },
-       [LTTNG_UST_DYNAMIC_TYPE_U32] = {
-               .start = 7,
-               .end = 7,
-               .string = "_uint32",
-       },
-       [LTTNG_UST_DYNAMIC_TYPE_U64] = {
-               .start = 8,
-               .end = 8,
-               .string = "_uint64",
-       },
-       [LTTNG_UST_DYNAMIC_TYPE_FLOAT] = {
-               .start = 9,
-               .end = 9,
-               .string = "_float",
-       },
-       [LTTNG_UST_DYNAMIC_TYPE_DOUBLE] = {
-               .start = 10,
-               .end = 10,
-               .string = "_double",
-       },
-       [LTTNG_UST_DYNAMIC_TYPE_STRING] = {
-               .start = 11,
-               .end = 11,
-               .string = "_string",
+#define ctf_enum_value(_string, _value)                                        \
+       {                                                               \
+               .start = {                                              \
+                       .signedness = lttng_is_signed_type(__typeof__(_value)), \
+                       .value = lttng_is_signed_type(__typeof__(_value)) ? \
+                               (long long) (_value) : (_value),        \
+               },                                                      \
+               .end = {                                                \
+                       .signedness = lttng_is_signed_type(__typeof__(_value)), \
+                       .value = lttng_is_signed_type(__typeof__(_value)) ? \
+                               (long long) (_value) : (_value),        \
+               },                                                      \
+               .string = (_string),                                    \
        },
+
+static const struct lttng_enum_entry dt_enum[_NR_LTTNG_UST_DYNAMIC_TYPES] = {
+       [LTTNG_UST_DYNAMIC_TYPE_NONE] = ctf_enum_value("_none", 0)
+       [LTTNG_UST_DYNAMIC_TYPE_S8] = ctf_enum_value("_int8", 1)
+       [LTTNG_UST_DYNAMIC_TYPE_S16] = ctf_enum_value("_int16", 2)
+       [LTTNG_UST_DYNAMIC_TYPE_S32] = ctf_enum_value("_int32", 3)
+       [LTTNG_UST_DYNAMIC_TYPE_S64] = ctf_enum_value("_int64", 4)
+       [LTTNG_UST_DYNAMIC_TYPE_U8] = ctf_enum_value("_uint8", 5)
+       [LTTNG_UST_DYNAMIC_TYPE_U16] = ctf_enum_value("_uint16", 6)
+       [LTTNG_UST_DYNAMIC_TYPE_U32] = ctf_enum_value("_uint32", 7)
+       [LTTNG_UST_DYNAMIC_TYPE_U64] = ctf_enum_value("_uint64", 8)
+       [LTTNG_UST_DYNAMIC_TYPE_FLOAT] = ctf_enum_value("_float", 9)
+       [LTTNG_UST_DYNAMIC_TYPE_DOUBLE] = ctf_enum_value("_double", 10)
+       [LTTNG_UST_DYNAMIC_TYPE_STRING] = ctf_enum_value("_string", 11)
 };
 
 static const struct lttng_enum_desc dt_enum_desc = {
This page took 0.031347 seconds and 4 git commands to generate.