From: Mathieu Desnoyers Date: Fri, 21 Oct 2022 16:03:46 +0000 (-0400) Subject: Add binary blob static type X-Git-Url: http://drtracing.org/?a=commitdiff_plain;h=7aec0d09a0486654cc8e5be637ab6a64f3354bd4;p=libside.git Add binary blob static type Signed-off-by: Mathieu Desnoyers --- diff --git a/include/side/trace.h b/include/side/trace.h index 623a854..3b1283d 100644 --- a/include/side/trace.h +++ b/include/side/trace.h @@ -40,6 +40,7 @@ enum side_type { SIDE_TYPE_S16, SIDE_TYPE_S32, SIDE_TYPE_S64, + SIDE_TYPE_BLOB, SIDE_TYPE_ENUM_U8, SIDE_TYPE_ENUM_U16, @@ -75,6 +76,7 @@ enum side_type { SIDE_TYPE_ARRAY_S16, SIDE_TYPE_ARRAY_S32, SIDE_TYPE_ARRAY_S64, + SIDE_TYPE_ARRAY_BLOB, SIDE_TYPE_VLA_U8, SIDE_TYPE_VLA_U16, @@ -84,6 +86,7 @@ enum side_type { SIDE_TYPE_VLA_S16, SIDE_TYPE_VLA_S32, SIDE_TYPE_VLA_S64, + SIDE_TYPE_VLA_BLOB, SIDE_TYPE_DYNAMIC, }; @@ -342,6 +345,7 @@ struct side_arg_vec { int16_t side_s16; int32_t side_s32; int64_t side_s64; + uint8_t side_blob; #if __HAVE_FLOAT16 _Float16 side_float_binary16; @@ -424,6 +428,7 @@ struct side_tracer_dynamic_vla_visitor_ctx { #define side_type_s16(_attr) _side_type(SIDE_TYPE_S16, SIDE_PARAM(_attr)) #define side_type_s32(_attr) _side_type(SIDE_TYPE_S32, SIDE_PARAM(_attr)) #define side_type_s64(_attr) _side_type(SIDE_TYPE_S64, SIDE_PARAM(_attr)) +#define side_type_blob(_attr) _side_type(SIDE_TYPE_BLOB, SIDE_PARAM(_attr)) #define side_type_float_binary16(_attr) _side_type(SIDE_TYPE_FLOAT_BINARY16, SIDE_PARAM(_attr)) #define side_type_float_binary32(_attr) _side_type(SIDE_TYPE_FLOAT_BINARY32, SIDE_PARAM(_attr)) #define side_type_float_binary64(_attr) _side_type(SIDE_TYPE_FLOAT_BINARY64, SIDE_PARAM(_attr)) @@ -446,6 +451,7 @@ struct side_tracer_dynamic_vla_visitor_ctx { #define side_field_s16(_name, _attr) _side_field(_name, side_type_s16(SIDE_PARAM(_attr))) #define side_field_s32(_name, _attr) _side_field(_name, side_type_s32(SIDE_PARAM(_attr))) #define side_field_s64(_name, _attr) _side_field(_name, side_type_s64(SIDE_PARAM(_attr))) +#define side_field_blob(_name, _attr) _side_field(_name, side_type_blob(SIDE_PARAM(_attr))) #define side_field_float_binary16(_name, _attr) _side_field(_name, side_type_float_binary16(SIDE_PARAM(_attr))) #define side_field_float_binary32(_name, _attr) _side_field(_name, side_type_float_binary32(SIDE_PARAM(_attr))) #define side_field_float_binary64(_name, _attr) _side_field(_name, side_type_float_binary64(SIDE_PARAM(_attr))) @@ -577,6 +583,7 @@ struct side_tracer_dynamic_vla_visitor_ctx { #define side_arg_s16(val) { .type = SIDE_TYPE_S16, .u = { .side_s16 = (val) } } #define side_arg_s32(val) { .type = SIDE_TYPE_S32, .u = { .side_s32 = (val) } } #define side_arg_s64(val) { .type = SIDE_TYPE_S64, .u = { .side_s64 = (val) } } +#define side_arg_blob(val) { .type = SIDE_TYPE_BLOB, .u = { .side_blob = (val) } } #define side_arg_enum_u8(val) { .type = SIDE_TYPE_ENUM_U8, .u = { .side_u8 = (val) } } #define side_arg_enum_u16(val) { .type = SIDE_TYPE_ENUM_U16, .u = { .side_u16 = (val) } } #define side_arg_enum_u32(val) { .type = SIDE_TYPE_ENUM_U32, .u = { .side_u32 = (val) } } @@ -608,6 +615,7 @@ struct side_tracer_dynamic_vla_visitor_ctx { #define side_arg_array_s16(_ptr) { .type = SIDE_TYPE_ARRAY_S16, .u = { .side_array_fixint = (_ptr) } } #define side_arg_array_s32(_ptr) { .type = SIDE_TYPE_ARRAY_S32, .u = { .side_array_fixint = (_ptr) } } #define side_arg_array_s64(_ptr) { .type = SIDE_TYPE_ARRAY_S64, .u = { .side_array_fixint = (_ptr) } } +#define side_arg_array_blob(_ptr) { .type = SIDE_TYPE_ARRAY_BLOB, .u = { .side_array_fixint = (_ptr) } } #define side_arg_vla_u8(_ptr, _length) { .type = SIDE_TYPE_VLA_U8, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } #define side_arg_vla_u16(_ptr, _length) { .type = SIDE_TYPE_VLA_U16, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } } @@ -617,6 +625,7 @@ struct side_tracer_dynamic_vla_visitor_ctx { #define side_arg_vla_s16(_ptr, _length) { .type = SIDE_TYPE_VLA_S16, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } } #define side_arg_vla_s32(_ptr, _length) { .type = SIDE_TYPE_VLA_S32, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } } #define side_arg_vla_s64(_ptr, _length) { .type = SIDE_TYPE_VLA_S64, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } } +#define side_arg_vla_blob(_ptr, _length) { .type = SIDE_TYPE_VLA_BLOB, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } } #define side_arg_dynamic(dynamic_arg_type) \ { \ diff --git a/src/test.c b/src/test.c index 5c301c5..bfa30ee 100644 --- a/src/test.c +++ b/src/test.c @@ -1000,6 +1000,34 @@ void test_enum_bitmap(void) ); } +static uint8_t blob_fixint[] = { 0x55, 0x44, 0x33, 0x22, 0x11 }; + +static side_define_event(my_provider_event_blob, "myprovider", "myeventblob", SIDE_LOGLEVEL_DEBUG, + side_field_list( + side_field_blob("blobfield", side_attr_list()), + side_field_array("arrayblob", side_elem(side_type_blob(side_attr_list())), 3, side_attr_list()), + side_field_array("arrayblobfix", side_elem(side_type_blob(side_attr_list())), SIDE_ARRAY_SIZE(blob_fixint), side_attr_list()), + side_field_vla("vlablobfix", side_elem(side_type_blob(side_attr_list())), side_attr_list()), + ), + side_attr_list() +); + +static +void test_blob(void) +{ + my_provider_event_blob.enabled = 1; + side_event_cond(&my_provider_event_blob) { + side_arg_define_vec(myarray, side_arg_list(side_arg_blob(1), side_arg_blob(2), side_arg_blob(3))); + side_event_call(&my_provider_event_blob, + side_arg_list( + side_arg_blob(0x55), + side_arg_array(&myarray), + side_arg_array_blob(blob_fixint), + side_arg_vla_blob(blob_fixint, SIDE_ARRAY_SIZE(blob_fixint)), + ) + ); + } +} int main() { @@ -1034,5 +1062,6 @@ int main() test_variadic_float(); test_enum(); test_enum_bitmap(); + test_blob(); return 0; } diff --git a/src/tracer.c b/src/tracer.c index 62555d7..9a90de8 100644 --- a/src/tracer.c +++ b/src/tracer.c @@ -184,6 +184,7 @@ void tracer_print_type(const struct side_type_description *type_desc, const stru case SIDE_TYPE_ARRAY_S16: case SIDE_TYPE_ARRAY_S32: case SIDE_TYPE_ARRAY_S64: + case SIDE_TYPE_ARRAY_BLOB: if (type_desc->type != SIDE_TYPE_ARRAY) { printf("ERROR: type mismatch between description and arguments\n"); abort(); @@ -197,6 +198,7 @@ void tracer_print_type(const struct side_type_description *type_desc, const stru case SIDE_TYPE_VLA_S16: case SIDE_TYPE_VLA_S32: case SIDE_TYPE_VLA_S64: + case SIDE_TYPE_VLA_BLOB: if (type_desc->type != SIDE_TYPE_VLA) { printf("ERROR: type mismatch between description and arguments\n"); abort(); @@ -242,6 +244,9 @@ void tracer_print_type(const struct side_type_description *type_desc, const stru case SIDE_TYPE_S64: printf("%" PRId64, item->u.side_s64); break; + case SIDE_TYPE_BLOB: + printf("0x%" PRIx8, item->u.side_blob); + break; case SIDE_TYPE_ENUM_U8: print_enum(type_desc->u.side_enum_mappings, @@ -348,6 +353,7 @@ void tracer_print_type(const struct side_type_description *type_desc, const stru case SIDE_TYPE_ARRAY_S16: case SIDE_TYPE_ARRAY_S32: case SIDE_TYPE_ARRAY_S64: + case SIDE_TYPE_ARRAY_BLOB: tracer_print_array_fixint(type_desc, item); break; case SIDE_TYPE_VLA_U8: @@ -358,6 +364,7 @@ void tracer_print_type(const struct side_type_description *type_desc, const stru case SIDE_TYPE_VLA_S16: case SIDE_TYPE_VLA_S32: case SIDE_TYPE_VLA_S64: + case SIDE_TYPE_VLA_BLOB: tracer_print_vla_fixint(type_desc, item); break; case SIDE_TYPE_DYNAMIC: @@ -512,6 +519,10 @@ void tracer_print_array_fixint(const struct side_type_description *type_desc, co if (elem_type->type != SIDE_TYPE_S64) goto type_error; break; + case SIDE_TYPE_ARRAY_BLOB: + if (elem_type->type != SIDE_TYPE_BLOB) + goto type_error; + break; default: goto type_error; } @@ -548,6 +559,9 @@ void tracer_print_array_fixint(const struct side_type_description *type_desc, co case SIDE_TYPE_S64: sav_elem.u.side_s64 = ((const int64_t *) p)[i]; break; + case SIDE_TYPE_BLOB: + sav_elem.u.side_blob = ((const uint8_t *) p)[i]; + break; default: printf("ERROR: Unexpected type\n"); @@ -606,6 +620,10 @@ void tracer_print_vla_fixint(const struct side_type_description *type_desc, cons if (elem_type->type != SIDE_TYPE_S64) goto type_error; break; + case SIDE_TYPE_VLA_BLOB: + if (elem_type->type != SIDE_TYPE_BLOB) + goto type_error; + break; default: goto type_error; } @@ -642,6 +660,9 @@ void tracer_print_vla_fixint(const struct side_type_description *type_desc, cons case SIDE_TYPE_S64: sav_elem.u.side_s64 = ((const int64_t *) p)[i]; break; + case SIDE_TYPE_BLOB: + sav_elem.u.side_blob = ((const uint8_t *) p)[i]; + break; default: printf("ERROR: Unexpected type\n");