#include <inttypes.h>
#include <endian.h>
#include <errno.h>
+#include <babeltrace/babeltrace.h>
#include <babeltrace/list.h>
#include <babeltrace/types.h>
#include <babeltrace/ctf/metadata.h>
}
static
-struct ctf_stream *trace_stream_lookup(struct ctf_trace *trace, uint64_t stream_id)
+struct ctf_stream_class *trace_stream_lookup(struct ctf_trace *trace, uint64_t stream_id)
{
if (trace->streams->len <= stream_id)
return NULL;
static
struct declaration *ctf_declaration_struct_visit(FILE *fd,
int depth, const char *name, struct cds_list_head *declaration_list,
- int has_body, struct declaration_scope *declaration_scope,
+ int has_body, struct cds_list_head *min_align,
+ struct declaration_scope *declaration_scope,
struct ctf_trace *trace)
{
struct declaration_struct *struct_declaration;
declaration_scope);
return &struct_declaration->p;
} else {
+ uint64_t min_align_value = 0;
+
/* For unnamed struct, create type */
/* For named struct (with body), create type and add to declaration scope */
if (name) {
return NULL;
}
}
- struct_declaration = struct_declaration_new(declaration_scope);
+ if (!cds_list_empty(min_align)) {
+ ret = get_unary_unsigned(min_align, &min_align_value);
+ if (ret) {
+ fprintf(fd, "[error] %s: unexpected unary expression for structure \"align\" attribute\n", __func__);
+ ret = -EINVAL;
+ goto error;
+ }
+ }
+ struct_declaration = struct_declaration_new(declaration_scope,
+ min_align_value);
cds_list_for_each_entry(iter, declaration_list, siblings) {
ret = ctf_struct_declaration_list_visit(fd, depth + 1, iter,
struct_declaration, trace);
return NULL;
}
alignment = right->u.unary_expression.u.unsigned_constant;
+ /* Make sure alignment is a power of two */
+ if (alignment == 0 || (alignment & (alignment - 1)) != 0) {
+ fprintf(fd, "[error] %s: align: expecting power of two\n",
+ __func__);
+ return NULL;
+ }
has_alignment = 1;
} else {
fprintf(fd, "[error] %s: unknown attribute name %s\n",
return NULL;
}
alignment = right->u.unary_expression.u.unsigned_constant;
+ /* Make sure alignment is a power of two */
+ if (alignment == 0 || (alignment & (alignment - 1)) != 0) {
+ fprintf(fd, "[error] %s: align: expecting power of two\n",
+ __func__);
+ return NULL;
+ }
has_alignment = 1;
} else {
fprintf(fd, "[error] %s: unknown attribute name %s\n",
node->u._struct.name,
&node->u._struct.declaration_list,
node->u._struct.has_body,
+ &node->u._struct.min_align,
declaration_scope,
trace);
case TYPESPEC_VARIANT:
static
-int ctf_stream_declaration_visit(FILE *fd, int depth, struct ctf_node *node, struct ctf_stream *stream, struct ctf_trace *trace)
+int ctf_stream_declaration_visit(FILE *fd, int depth, struct ctf_node *node, struct ctf_stream_class *stream, struct ctf_trace *trace)
{
int ret = 0;
{
int ret = 0;
struct ctf_node *iter;
- struct ctf_stream *stream;
+ struct ctf_stream_class *stream;
struct definition_scope *parent_def_scope;
- stream = g_new0(struct ctf_stream, 1);
+ stream = g_new0(struct ctf_stream_class, 1);
stream->declaration_scope = new_declaration_scope(parent_declaration_scope);
stream->events_by_id = g_ptr_array_new();
stream->event_quark_to_id = g_hash_table_new(g_direct_hash, g_direct_equal);
int ret = 0;
struct ctf_node *iter;
- fprintf(fd, "CTF visitor: metadata construction... ");
+ printf_verbose("CTF visitor: metadata construction... ");
trace->root_declaration_scope = new_declaration_scope(NULL);
+ trace->streams = g_ptr_array_new();
trace->byte_order = byte_order;
switch (node->type) {
(int) node->type);
return -EINVAL;
}
- fprintf(fd, "done.\n");
+ printf_verbose("done.\n");
return ret;
}