} SIDE_PACKED u;
};
+struct side_type_raw_string {
+ const void *p; /* pointer to string */
+ uint8_t unit_size; /* 1, 2, or 4 bytes */
+ uint8_t byte_order; /* enum side_type_label_byte_order */
+} SIDE_PACKED;
+
/* User attributes. */
struct side_attr {
- const char *key;
+ const struct side_type_raw_string key;
const struct side_attr_value value;
} SIDE_PACKED;
#define side_attr(_key, _value) \
{ \
- .key = _key, \
+ .key = { \
+ .p = (_key), \
+ .unit_size = sizeof(uint8_t), \
+ .byte_order = SIDE_TYPE_BYTE_ORDER_HOST, \
+ }, \
.value = SIDE_PARAM(_value), \
}
void tracer_print_type(const struct side_type *type_desc, const struct side_arg *item);
static
-void tracer_print_string(const void *p, uint8_t unit_size, enum side_type_label_byte_order byte_order,
- size_t *strlen_with_null)
+void tracer_convert_string_to_utf8(const void *p, uint8_t unit_size, enum side_type_label_byte_order byte_order,
+ size_t *strlen_with_null,
+ char **output_str)
{
size_t ret, inbytesleft = 0, outbytesleft, bufsize;
const char *str = p, *fromcode;
switch (unit_size) {
case 1:
- printf("\"%s\"", str);
if (strlen_with_null)
*strlen_with_null = strlen(str) + 1;
+ *output_str = (char *) str;
return;
case 2:
{
abort();
}
(*outbuf++) = '\0';
- if (strlen_with_null)
- *strlen_with_null = outbuf - buf;
- printf("\"%s\"", buf);
- free(buf);
if (iconv_close(cd) == -1) {
perror("iconv_close");
abort();
}
+ if (strlen_with_null)
+ *strlen_with_null = outbuf - buf;
+ *output_str = buf;
+}
+
+static
+void tracer_print_string(const void *p, uint8_t unit_size, enum side_type_label_byte_order byte_order,
+ size_t *strlen_with_null)
+{
+ char *output_str = NULL;
+
+ tracer_convert_string_to_utf8(p, unit_size, byte_order, strlen_with_null, &output_str);
+ printf("\"%s\"", output_str);
+ if (output_str != p)
+ free(output_str);
}
static
for (i = 0; i < nr_attr; i++) {
const struct side_attr *attr = &_attr[i];
-
- if (!strcmp(attr->key, "std.integer.base")) {
+ char *utf8_str = NULL;
+ bool cmp;
+
+ tracer_convert_string_to_utf8(attr->key.p, attr->key.unit_size,
+ attr->key.byte_order, NULL, &utf8_str);
+ cmp = strcmp(utf8_str, "std.integer.base");
+ if (utf8_str != attr->key.p)
+ free(utf8_str);
+ if (!cmp) {
int64_t val = get_attr_integer_value(attr);
switch (val) {
static
void tracer_print_attr_type(const char *separator, const struct side_attr *attr)
{
- printf("{ key%s \"%s\", value%s ", separator, attr->key, separator);
+ char *utf8_str = NULL;
+
+ tracer_convert_string_to_utf8(attr->key.p, attr->key.unit_size,
+ attr->key.byte_order, NULL, &utf8_str);
+ printf("{ key%s \"%s\", value%s ", separator, utf8_str, separator);
+ if (utf8_str != attr->key.p)
+ free(utf8_str);
switch (attr->value.type) {
case SIDE_ATTR_TYPE_BOOL:
printf("%s", attr->value.u.bool_value ? "true" : "false");