Implement gather byte
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Mon, 7 Nov 2022 21:00:48 +0000 (16:00 -0500)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Mon, 7 Nov 2022 21:00:48 +0000 (16:00 -0500)
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
include/side/trace.h
src/test.c
src/tracer.c

index b47bb96cd307a1df492f91ab6b1b8d45906903aa..57280423166c006b6d47d23f4a375d7e24f26a1e 100644 (file)
@@ -93,6 +93,7 @@ enum side_type_label {
        /* Gather types */
        SIDE_TYPE_GATHER_UNSIGNED_INT,
        SIDE_TYPE_GATHER_SIGNED_INT,
+       SIDE_TYPE_GATHER_BYTE,
        SIDE_TYPE_GATHER_FLOAT,
        SIDE_TYPE_GATHER_STRUCT,
        SIDE_TYPE_GATHER_ARRAY,
@@ -336,6 +337,12 @@ struct side_type_enum_bitmap {
        const struct side_type *elem_type;
 } SIDE_PACKED;
 
+struct side_type_gather_byte {
+       uint64_t offset;        /* bytes */
+       uint8_t access_mode;    /* enum side_type_gather_access_mode */
+       struct side_type_byte type;
+} SIDE_PACKED;
+
 struct side_type_gather_integer {
        uint64_t offset;        /* bytes */
        uint8_t access_mode;    /* enum side_type_gather_access_mode */
@@ -377,6 +384,7 @@ enum side_type_gather_access_mode {
 
 struct side_type_gather {
        union {
+               struct side_type_gather_byte side_byte;
                struct side_type_gather_integer side_integer;
                struct side_type_gather_float side_float;
                struct side_type_gather_array side_array;
@@ -454,6 +462,7 @@ struct side_arg_static {
        } SIDE_PACKED side_vla_fixint;
 
        /* Gather types */
+       void *side_byte_gather_ptr;
        void *side_integer_gather_ptr;
        void *side_float_gather_ptr;
        void *side_array_gather_ptr;
@@ -890,6 +899,27 @@ struct side_event_description {
 
 /* Gather fields */
 
+#define side_type_gather_byte(_offset, _access_mode, _attr) \
+       { \
+               .type = SIDE_TYPE_GATHER_BYTE, \
+               .u = { \
+                       .side_gather = { \
+                               .u = { \
+                                       .side_byte = { \
+                                               .offset = _offset, \
+                                               .access_mode = _access_mode, \
+                                               .type = { \
+                                                       .attr = _attr, \
+                                                       .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
+                                               }, \
+                                       }, \
+                               }, \
+                       }, \
+               }, \
+       }
+#define side_field_gather_byte(_name, _offset, _access_mode, _attr) \
+       _side_field(_name, side_type_gather_byte(_offset, _access_mode, SIDE_PARAM(_attr)))
+
 #define _side_type_gather_integer(_type, _signedness, _byte_order, _offset, \
                _integer_size_bits, _offset_bits, _len_bits, _access_mode, _attr) \
        { \
@@ -1115,6 +1145,7 @@ struct side_event_description {
 #define side_arg_vla_pointer(_ptr, _length) { .type = SIDE_TYPE_VLA_POINTER_HOST, .u = { .side_static = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } } }
 
 /* Gather field arguments */
+#define side_arg_gather_byte(_ptr)             { .type = SIDE_TYPE_GATHER_BYTE, .u = { .side_static = { .side_byte_gather_ptr = (_ptr) } } }
 #define side_arg_gather_unsigned_integer(_ptr) { .type = SIDE_TYPE_GATHER_UNSIGNED_INT, .u = { .side_static = { .side_integer_gather_ptr = (_ptr) } } }
 #define side_arg_gather_signed_integer(_ptr)   { .type = SIDE_TYPE_GATHER_SIGNED_INT, .u = { .side_static = { .side_integer_gather_ptr = (_ptr) } } }
 #define side_arg_gather_float(_ptr)            { .type = SIDE_TYPE_GATHER_FLOAT, .u = { .side_static = { .side_float_gather_ptr = (_ptr) } } }
index 5a8ff89d630e02e3a34d189ec102559fe3a3ef25..13419ad44f0c8f0f1e05f5c7cfcc0613464a6155 100644 (file)
@@ -1973,6 +1973,34 @@ void test_gather_vla_flex(void)
        }
 }
 
+side_static_event(my_provider_event_gatherbyte,
+       "myprovider", "myeventgatherbyte", SIDE_LOGLEVEL_DEBUG,
+       side_field_list(
+               side_field_gather_byte("byte", 0, SIDE_TYPE_GATHER_ACCESS_POINTER, side_attr_list()),
+               side_field_gather_array("array",
+                       side_elem(side_type_gather_byte(0, SIDE_TYPE_GATHER_ACCESS_ADDRESS, side_attr_list())),
+                       3, 0, SIDE_TYPE_GATHER_ACCESS_POINTER, side_attr_list()
+               ),
+       ),
+       side_attr_list()
+);
+
+static
+void test_gather_byte(void)
+{
+       side_event_cond(my_provider_event_structgatherarray) {
+               uint8_t v = 0x44;
+               uint8_t array[3] = { 0x1, 0x2, 0x3 };
+
+               side_event_call(my_provider_event_gatherbyte,
+                       side_arg_list(
+                               side_arg_gather_byte(&v),
+                               side_arg_gather_array(array),
+                       )
+               );
+       }
+}
+
 int main()
 {
        test_fields();
@@ -2020,5 +2048,6 @@ int main()
        test_gather_structnest();
        test_gather_vla();
        test_gather_vla_flex();
+       test_gather_byte();
        return 0;
 }
index 2e32e709a4c083a54ba3ea834dc54870bb2882de..45ef5945e8313b4f9068083685f282aa222ff3f1 100644 (file)
@@ -36,12 +36,14 @@ void tracer_print_vla_fixint(const struct side_type *type_desc, const struct sid
 static
 void tracer_print_dynamic(const struct side_arg *dynamic_item);
 static
-uint32_t tracer_print_gather_struct(const struct side_type_gather *type_gather, const void *_ptr);
+uint32_t tracer_print_gather_byte_type(const struct side_type_gather *type_gather, const void *_ptr);
 static
 uint32_t tracer_print_gather_integer_type(const struct side_type_gather *type_gather, const void *_ptr);
 static
 uint32_t tracer_print_gather_float_type(const struct side_type_gather *type_gather, const void *_ptr);
 static
+uint32_t tracer_print_gather_struct(const struct side_type_gather *type_gather, const void *_ptr);
+static
 uint32_t tracer_print_gather_array(const struct side_type_gather *type_gather, const void *_ptr);
 static
 uint32_t tracer_print_gather_vla(const struct side_type_gather *type_gather, const void *_ptr);
@@ -911,6 +913,9 @@ void tracer_print_type(const struct side_type *type_desc, const struct side_arg
        case SIDE_TYPE_GATHER_ARRAY:
                (void) tracer_print_gather_array(&type_desc->u.side_gather, &item->u.side_static.side_array_gather_ptr);
                break;
+       case SIDE_TYPE_GATHER_BYTE:
+               (void) tracer_print_gather_byte_type(&type_desc->u.side_gather, &item->u.side_static.side_byte_gather_ptr);
+               break;
        case SIDE_TYPE_GATHER_UNSIGNED_INT:
        case SIDE_TYPE_GATHER_SIGNED_INT:
                (void) tracer_print_gather_integer_type(&type_desc->u.side_gather, item->u.side_static.side_integer_gather_ptr);
@@ -1106,6 +1111,21 @@ uint64_t tracer_load_gather_integer_type(const struct side_type_gather *type_gat
        }
 }
 
+static
+uint32_t tracer_print_gather_byte_type(const struct side_type_gather *type_gather, const void *_ptr)
+{
+       enum side_type_gather_access_mode access_mode = type_gather->u.side_byte.access_mode;
+       const char *ptr = (const char *) _ptr;
+       uint8_t value;
+
+       ptr = tracer_gather_access(access_mode, ptr + type_gather->u.side_byte.offset);
+       memcpy(&value, ptr, 1);
+       tracer_print_type_header(":", type_gather->u.side_byte.type.attr,
+                       type_gather->u.side_byte.type.nr_attr);
+       printf("0x%" PRIx8, value);
+       return tracer_gather_size(access_mode, 1);
+}
+
 static
 uint32_t tracer_print_gather_integer_type(const struct side_type_gather *type_gather, const void *_ptr)
 {
@@ -1160,6 +1180,9 @@ uint32_t tracer_print_gather_type(const struct side_type *type_desc, const void
 
        printf("{ ");
        switch (type_desc->type) {
+       case SIDE_TYPE_GATHER_BYTE:
+               len = tracer_print_gather_byte_type(&type_desc->u.side_gather, ptr);
+               break;
        case SIDE_TYPE_GATHER_UNSIGNED_INT:
        case SIDE_TYPE_GATHER_SIGNED_INT:
                len = tracer_print_gather_integer_type(&type_desc->u.side_gather, ptr);
This page took 0.02779 seconds and 4 git commands to generate.