fprintf(pos->fp, "%s = ",
g_quark_to_string(definition->name));
- if (!compare_definition_path(definition, g_quark_from_static_string("stream.event.header.timestamp"))) {
- fprintf(pos->fp, "%" PRIu64,
- integer_definition->value._unsigned);
- return 0;
- }
+ switch (integer_declaration->base) {
+ case 2:
+ {
+ int bitnr;
+ uint64_t v = integer_definition->value._unsigned;
- if (!integer_declaration->signedness) {
- fprintf(pos->fp, "%" PRIu64" (0x%" PRIX64 ")",
- integer_definition->value._unsigned,
+ fprintf(pos->fp, "b");
+ for (bitnr = 0; bitnr < integer_declaration->len; bitnr++)
+ v <<= 1;
+ for (; bitnr < sizeof(v) * CHAR_BIT; bitnr++) {
+ fprintf(pos->fp, "%u", ((v & 1ULL) << 63) ? 1 : 0);
+ v <<= 1;
+ }
+ break;
+ }
+ case 8:
+ fprintf(pos->fp, "0%" PRIo64,
+ integer_definition->value._unsigned);
+ break;
+ case 10:
+ if (!integer_declaration->signedness) {
+ fprintf(pos->fp, "%" PRIu64,
+ integer_definition->value._unsigned);
+ } else {
+ fprintf(pos->fp, "%" PRId64,
+ integer_definition->value._signed);
+ }
+ break;
+ case 16:
+ fprintf(pos->fp, "0x%" PRIX64,
integer_definition->value._unsigned);
- } else {
- fprintf(pos->fp, "%" PRId64" (0x%" PRIX64 ")",
- integer_definition->value._signed,
- integer_definition->value._signed);
+ break;
+ default:
+ return -EINVAL;
}
+
return 0;
}
int byte_order = trace->byte_order;
int signedness = 0;
int has_alignment = 0, has_size = 0;
+ int base = 10;
struct declaration_integer *integer_declaration;
cds_list_for_each_entry(expression, expressions, siblings) {
return NULL;
}
has_alignment = 1;
+ } else if (!strcmp(left->u.unary_expression.u.string, "base")) {
+ switch (right->u.unary_expression.type) {
+ case UNARY_UNSIGNED_CONSTANT:
+ switch (right->u.unary_expression.u.unsigned_constant) {
+ case 2:
+ case 8:
+ case 10:
+ case 16:
+ base = right->u.unary_expression.u.unsigned_constant;
+ break;
+ default:
+ fprintf(fd, "[error] %s: base not supported (%" PRIu64 ")\n",
+ __func__, right->u.unary_expression.u.unsigned_constant);
+ return NULL;
+ }
+ break;
+ case UNARY_STRING:
+ {
+ char *s_right = concatenate_unary_strings(&expression->u.ctf_expression.right);
+ if (!s_right) {
+ fprintf(fd, "[error] %s: unexpected unary expression for integer base\n", __func__);
+ g_free(s_right);
+ return NULL;
+ }
+ if (!strcmp(s_right, "decimal") || !strcmp(s_right, "dec") || !strcmp(s_right, "d")
+ || !strcmp(s_right, "i") || !strcmp(s_right, "u")) {
+ base = 10;
+ } else if (!strcmp(s_right, "hexadecimal") || !strcmp(s_right, "hex")
+ || !strcmp(s_right, "x") || !strcmp(s_right, "X")
+ || !strcmp(s_right, "p")) {
+ base = 16;
+ } else if (!strcmp(s_right, "octal") || !strcmp(s_right, "oct")
+ || !strcmp(s_right, "o")) {
+ base = 8;
+ } else if (!strcmp(s_right, "binary") || !strcmp(s_right, "b")) {
+ base = 2;
+ } else {
+ fprintf(fd, "[error] %s: unexpected expression for integer base (%s)\n", __func__, s_right);
+ g_free(s_right);
+ return NULL;
+ }
+
+ g_free(s_right);
+ break;
+ }
+ default:
+ fprintf(fd, "[error] %s: base: expecting unsigned constant or unary string\n",
+ __func__);
+ return NULL;
+ }
} else {
fprintf(fd, "[error] %s: unknown attribute name %s\n",
__func__, left->u.unary_expression.u.string);
}
}
integer_declaration = integer_declaration_new(size,
- byte_order, signedness, alignment);
+ byte_order, signedness, alignment, base);
return &integer_declaration->p;
}
size_t len; /* length, in bits. */
int byte_order; /* byte order */
int signedness;
+ int base; /* Base for pretty-printing: 2, 8, 10, 16 */
};
struct definition_integer {
void definition_unref(struct definition *definition);
struct declaration_integer *integer_declaration_new(size_t len, int byte_order,
- int signedness, size_t alignment);
+ int signedness, size_t alignment,
+ int base);
/*
* mantissa_len is the length of the number of bytes represented by the mantissa
typealias integer { size = 8; align = 8; signed = false; } := uint8_t;
typealias integer { size = 63; align = 1; signed = false; } := timestamp_t;
-typealias integer { size = 32; align = 32; signed = false; } := uint32_t;
-typealias integer { size = 32; align = 32; signed = false; } := void *;
+typealias integer { size = 32; align = 32; signed = false; base = 10; } := uint32_t;
+typealias integer { size = 32; align = 32; signed = false; base = hex; } := void *;
trace {
-typealias integer { size = 8; align = 8; signed = false; } := uint8_t;
-typealias integer { size = 32; align = 32; signed = false; } := uint32_t;
+typealias integer { size = 8; align = 8; signed = false; base = 10; } := uint8_t;
+typealias integer { size = 32; align = 32; signed = false; base = hex; } := uint32_t;
trace {
major = 0;
float_declaration->byte_order = byte_order;
float_declaration->sign = integer_declaration_new(1,
- byte_order, false, 1);
+ byte_order, false, 1, 2);
float_declaration->mantissa = integer_declaration_new(mantissa_len - 1,
- byte_order, false, 1);
+ byte_order, false, 1, 10);
float_declaration->exp = integer_declaration_new(exp_len,
- byte_order, true, 1);
+ byte_order, true, 1, 10);
return float_declaration;
}
struct declaration_integer *
integer_declaration_new(size_t len, int byte_order,
- int signedness, size_t alignment)
+ int signedness, size_t alignment, int base)
{
struct declaration_integer *integer_declaration;
integer_declaration->len = len;
integer_declaration->byte_order = byte_order;
integer_declaration->signedness = signedness;
+ integer_declaration->base = base;
return integer_declaration;
}