node->fts_accpath, format_str,
packet_seek, NULL, NULL);
if (trace_id < 0) {
- fprintf(stderr, "[warning] [Context] opening trace \"%s\" from %s "
+ fprintf(stderr, "[warning] [Context] cannot open trace \"%s\" from %s "
"for reading.\n", node->fts_accpath, path);
/* Allow to skip erroneous traces. */
ret = 1; /* partial error */
int i, stream_id;
gpointer *event_id_ptr;
unsigned long event_id;
- struct trace_collection *tc = iter->parent.ctx->tc;
+ struct trace_collection *tc;
+ if (!iter || !callback)
+ return -EINVAL;
+
+ tc = iter->parent.ctx->tc;
for (i = 0; i < tc->array->len; i++) {
struct ctf_trace *tin;
struct trace_descriptor *td_read;
enum bt_cb_ret ret;
struct bt_ctf_event ctf_data;
+ assert(iter && stream);
+
ret = extract_ctf_stream_event(stream, &ctf_data);
/* process all events callback first */
enum bt_ctf_scope scope)
{
struct definition *tmp = NULL;
- struct ctf_event_definition *event = ctf_event->parent;
+ struct ctf_event_definition *event;
+ if (!ctf_event)
+ return NULL;
+
+ event = ctf_event->parent;
switch (scope) {
case BT_TRACE_PACKET_HEADER:
if (!event->stream)
struct definition *def;
char *field_underscore;
- if (scope) {
- def = lookup_definition(scope, field);
- /*
- * optionally a field can have an underscore prefix, try
- * to lookup the field with this prefix if it failed
- */
- if (!def) {
- field_underscore = g_new(char, strlen(field) + 2);
- field_underscore[0] = '_';
- strcpy(&field_underscore[1], field);
- def = lookup_definition(scope, field_underscore);
- g_free(field_underscore);
- }
- if (bt_ctf_field_type(def) == CTF_TYPE_VARIANT) {
- struct definition_variant *variant_definition;
- variant_definition = container_of(def,
- struct definition_variant, p);
- return variant_definition->current_field;
- }
- return def;
+ if (!ctf_event || !scope || !field)
+ return NULL;
+
+ def = lookup_definition(scope, field);
+ /*
+ * optionally a field can have an underscore prefix, try
+ * to lookup the field with this prefix if it failed
+ */
+ if (!def) {
+ field_underscore = g_new(char, strlen(field) + 2);
+ field_underscore[0] = '_';
+ strcpy(&field_underscore[1], field);
+ def = lookup_definition(scope, field_underscore);
+ g_free(field_underscore);
}
- return NULL;
+ if (bt_ctf_field_type(def) == CTF_TYPE_VARIANT) {
+ struct definition_variant *variant_definition;
+ variant_definition = container_of(def,
+ struct definition_variant, p);
+ return variant_definition->current_field;
+ }
+ return def;
}
const struct definition *bt_ctf_get_index(const struct bt_ctf_event *ctf_event,
{
struct definition *ret = NULL;
+ if (!ctf_event || !field)
+ return NULL;
+
if (bt_ctf_field_type(field) == CTF_TYPE_ARRAY) {
struct definition_array *array_definition;
array_definition = container_of(field,
{
struct ctf_event_declaration *event_class;
struct ctf_stream_declaration *stream_class;
- struct ctf_event_definition *event = ctf_event->parent;
+ struct ctf_event_definition *event;
- if (!event)
+ if (!ctf_event)
return NULL;
+
+ event = ctf_event->parent;
stream_class = event->stream->stream_class;
event_class = g_ptr_array_index(stream_class->events_by_id,
event->stream->event_id);
const char *bt_ctf_field_name(const struct definition *def)
{
- if (def)
- return rem_(g_quark_to_string(def->name));
- return NULL;
+ if (!def)
+ return NULL;
+
+ return rem_(g_quark_to_string(def->name));
}
enum ctf_type_id bt_ctf_field_type(const struct definition *def)
{
- if (def)
- return def->declaration->id;
- return CTF_TYPE_UNKNOWN;
+ if (!def)
+ return CTF_TYPE_UNKNOWN;
+
+ return def->declaration->id;
}
int bt_ctf_get_field_list(const struct bt_ctf_event *ctf_event,
struct definition const * const **list,
unsigned int *count)
{
+ if (!ctf_event || !scope || !list || !count)
+ return -EINVAL;
+
switch (bt_ctf_field_type(scope)) {
case CTF_TYPE_INTEGER:
case CTF_TYPE_FLOAT:
} else {
goto error;
}
+ break;
}
case CTF_TYPE_UNTAGGED_VARIANT:
goto error;
} else {
goto error;
}
+ break;
}
case CTF_TYPE_ARRAY:
{
} else {
goto error;
}
+ break;
}
case CTF_TYPE_SEQUENCE:
{
} else {
goto error;
}
+ break;
}
default:
break;
struct bt_context *ret = NULL;
struct ctf_file_stream *cfs;
struct ctf_trace *trace;
- struct ctf_event_definition *event = ctf_event->parent;
+ struct ctf_event_definition *event;
+ if (!ctf_event)
+ return NULL;
+
+ event = ctf_event->parent;
cfs = container_of(event->stream, struct ctf_file_stream,
parent);
trace = cfs->parent.stream_class->trace;
int ret = -1;
struct ctf_file_stream *cfs;
struct ctf_trace *trace;
- struct ctf_event_definition *event = ctf_event->parent;
+ struct ctf_event_definition *event;
+
+ if (!ctf_event)
+ return -EINVAL;
+ event = ctf_event->parent;
cfs = container_of(event->stream, struct ctf_file_stream,
parent);
trace = cfs->parent.stream_class->trace;
uint64_t bt_ctf_get_timestamp(const struct bt_ctf_event *ctf_event)
{
- struct ctf_event_definition *event = ctf_event->parent;
+ struct ctf_event_definition *event;
+
+ if (!ctf_event)
+ return -1ULL;
+
+ event = ctf_event->parent;
if (event && event->stream->has_timestamp)
return event->stream->real_timestamp;
else
uint64_t bt_ctf_get_cycles(const struct bt_ctf_event *ctf_event)
{
- struct ctf_event_definition *event = ctf_event->parent;
+ struct ctf_event_definition *event;
+
+ if (!ctf_event)
+ return -1ULL;
+
+ event = ctf_event->parent;
if (event && event->stream->has_timestamp)
return event->stream->cycles_timestamp;
else
if (field && bt_ctf_field_type(field) == CTF_TYPE_INTEGER) {
ret = get_int_signedness(field);
} else {
- ret = -1;
+ ret = -EINVAL;
bt_ctf_field_set_error(-EINVAL);
}
if (field && bt_ctf_field_type(field) == CTF_TYPE_INTEGER) {
ret = get_int_base(field);
} else {
- ret = -1;
+ ret = -EINVAL;
bt_ctf_field_set_error(-EINVAL);
}
if (field && bt_ctf_field_type(field) == CTF_TYPE_INTEGER) {
ret = get_int_byte_order(field);
} else {
- ret = -1;
+ ret = -EINVAL;
bt_ctf_field_set_error(-EINVAL);
}
if (field && bt_ctf_field_type(field) == CTF_TYPE_INTEGER) {
ret = (ssize_t) get_int_len(field);
} else {
- ret = -1;
+ ret = -EINVAL;
bt_ctf_field_set_error(-EINVAL);
}
enum ctf_string_encoding ret = 0;
if (!field)
- goto end;
+ goto error;
if (bt_ctf_field_type(field) == CTF_TYPE_INTEGER)
ret = get_int_encoding(field);
ret = get_string_encoding(field);
else
goto error;
-
-end:
return ret;
error:
struct trace_descriptor *td;
struct ctf_trace *tin;
- if (!ctx)
+ if (!ctx || !list || !count)
goto error;
handle = g_hash_table_lookup(ctx->trace_handles,
{
if (!event)
return NULL;
+
return g_quark_to_string(event->parent.name);
}
int ret = 0;
*count = 0;
+ if (!event_decl || !list || !count)
+ return -EINVAL;
+
switch (scope) {
case BT_EVENT_CONTEXT:
if (event_decl->context_decl) {
const char *bt_ctf_get_decl_field_name(const struct bt_ctf_field_decl *field)
{
- if (field)
- return rem_(g_quark_to_string(((struct declaration_field *) field)->name));
- return NULL;
+ if (!field)
+ return NULL;
+
+ return rem_(g_quark_to_string(((struct declaration_field *) field)->name));
}
struct bt_ctf_iter *iter;
int ret;
+ if (!ctx)
+ return NULL;
+
iter = g_new0(struct bt_ctf_iter, 1);
ret = bt_iter_init(&iter->parent, ctx, begin_pos, end_pos);
if (ret) {
struct bt_callback_chain *bt_chain;
int i, j;
+ assert(iter);
+
/* free all events callbacks */
if (iter->main_callbacks.callback)
g_array_free(iter->main_callbacks.callback, TRUE);
struct bt_iter *bt_ctf_get_iter(struct bt_ctf_iter *iter)
{
+ if (!iter)
+ return NULL;
+
return &iter->parent;
}
struct bt_ctf_event *bt_ctf_iter_read_event(struct bt_ctf_iter *iter)
{
struct ctf_file_stream *file_stream;
- struct bt_ctf_event *ret = &iter->current_ctf_event;
+ struct bt_ctf_event *ret;
struct ctf_stream_definition *stream;
+ /*
+ * We do not want to fail for any other reason than end of
+ * trace, hence the assert.
+ */
+ assert(iter);
+
+ ret = &iter->current_ctf_event;
file_stream = heap_maximum(iter->parent.stream_heap);
if (!file_stream) {
/* end of file for all streams */
*
* stream_list is a linked list of streams, it is used to open a trace where
* the trace data is located in memory mapped areas instead of trace files,
- * this argument should be set to NULL when path is not NULL.
+ * this argument should be set to NULL when path is NULL.
*
* The metadata parameter acts as a metadata override when not NULL, otherwise
* the format handles the metadata opening.
/*
* bt_context_remove_trace: Remove a trace from the context.
*
- * Effectively closing the trace.
+ * Effectively closing the trace. Return negative error value if trace
+ * is not in context.
*/
-void bt_context_remove_trace(struct bt_context *ctx, int trace_id);
+int bt_context_remove_trace(struct bt_context *ctx, int trace_id);
/*
* bt_context_get and bt_context_put : increments and decrement the
*
* @callback: function pointer to call
* @depends: struct bt_dependency detailing the required computation results.
- * Ends with 0.
+ * Ends with 0. NULL is accepted as empty dependency.
* @weak_depends: struct bt_dependency detailing the optional computation
* results that can be optionally consumed by this
- * callback.
+ * callback. NULL is accepted as empty dependency.
* @provides: struct bt_dependency detailing the computation results
* provided by this callback.
- * Ends with 0.
+ * Ends with 0. NULL is accepted as empty dependency.
*
* "depends", "weak_depends" and "provides" memory is handled by the
* babeltrace library after this call succeeds or fails. These objects
/*
* bt_ctf_iter_read_event: Read the iterator's current event data.
*
- * @iter: trace collection iterator (input)
+ * @iter: trace collection iterator (input). Should NOT be NULL.
*
* Return current event on success, NULL on end of trace.
*/
#include <stdlib.h>
#include <string.h>
#include <assert.h>
+#include <errno.h>
#include <fts.h>
#include <fcntl.h> /* For O_RDONLY */
struct bt_trace_handle *handle;
int ret;
+ if (!ctx || !format_name || (!path && !stream_list))
+ return -EINVAL;
+
fmt = bt_lookup_format(g_quark_from_string(format_name));
if (!fmt) {
fprintf(stderr, "[error] [Context] Format \"%s\" unknown.\n\n",
return ret;
}
-void bt_context_remove_trace(struct bt_context *ctx, int handle_id)
+int bt_context_remove_trace(struct bt_context *ctx, int handle_id)
{
struct bt_trace_handle *handle;
+ if (!ctx)
+ return -EINVAL;
+
handle = g_hash_table_lookup(ctx->trace_handles,
(gpointer) (unsigned long) handle_id);
- assert(handle != NULL);
+ if (!handle)
+ return -ENOENT;
/* Remove from containers */
trace_collection_remove(ctx->tc, handle->td);
/* Remove and free the handle */
g_hash_table_remove(ctx->trace_handles,
(gpointer) (unsigned long) handle_id);
-
+ return 0;
}
static
void bt_context_destroy(struct bt_context *ctx)
{
+ assert(ctx);
finalize_trace_collection(ctx->tc);
/* Remote all traces. The g_hash_table_destroy will call
void bt_context_get(struct bt_context *ctx)
{
+ assert(ctx);
ctx->refcount++;
}
void bt_context_put(struct bt_context *ctx)
{
+ assert(ctx);
ctx->refcount--;
if (ctx->refcount == 0)
bt_context_destroy(ctx);
struct trace_collection *tc;
int i, ret;
+ if (!iter || !iter_pos)
+ return -EINVAL;
+
switch (iter_pos->type) {
case BT_SEEK_RESTORE:
if (!iter_pos->u.restore)
struct bt_iter_pos *bt_iter_get_pos(struct bt_iter *iter)
{
struct bt_iter_pos *pos;
- struct trace_collection *tc = iter->ctx->tc;
+ struct trace_collection *tc;
struct ctf_file_stream *file_stream = NULL, *removed;
struct ptr_heap iter_heap_copy;
int ret;
+ if (!iter)
+ return NULL;
+
+ tc = iter->ctx->tc;
pos = g_new0(struct bt_iter_pos, 1);
pos->type = BT_SEEK_RESTORE;
pos->u.restore = g_new0(struct bt_saved_pos, 1);
{
struct bt_iter_pos *pos;
+ if (!iter)
+ return NULL;
+
pos = g_new0(struct bt_iter_pos, 1);
pos->type = BT_SEEK_TIME;
pos->u.seek_time = timestamp;
{
int ret = 0;
+ if (!file_stream || !begin_pos)
+ return -EINVAL;
+
switch (begin_pos->type) {
case BT_SEEK_CUR:
/*
int i, stream_id;
int ret = 0;
+ if (!iter || !ctx)
+ return -EINVAL;
+
if (ctx->current_iterator) {
ret = -1;
goto error_ctx;
struct bt_iter *iter;
int ret;
+ if (!ctx)
+ return NULL;
+
iter = g_new0(struct bt_iter, 1);
ret = bt_iter_init(iter, ctx, begin_pos, end_pos);
if (ret) {
void bt_iter_fini(struct bt_iter *iter)
{
+ assert(iter);
if (iter->stream_heap) {
heap_free(iter->stream_heap);
g_free(iter->stream_heap);
void bt_iter_destroy(struct bt_iter *iter)
{
+ assert(iter);
bt_iter_fini(iter);
g_free(iter);
}
struct ctf_file_stream *file_stream, *removed;
int ret;
+ if (!iter)
+ return -EINVAL;
+
file_stream = heap_maximum(iter->stream_heap);
if (!file_stream) {
/* end of file for all streams */
{
if (!init_done)
return NULL;
+
return g_hash_table_lookup(format_registry,
(gconstpointer) (unsigned long) name);
}
{
struct walk_data data;
+ assert(fp);
+
data.fp = fp;
data.iter = 0;
int bt_register_format(struct format *format)
{
+ if (!format)
+ return -EINVAL;
+
if (!init_done)
format_init();
int trace_collection_add(struct trace_collection *tc,
struct trace_descriptor *td)
{
- struct ctf_trace *trace = container_of(td, struct ctf_trace, parent);
+ struct ctf_trace *trace;
+ if (!tc || !td)
+ return -EINVAL;
+
+ trace = container_of(td, struct ctf_trace, parent);
g_ptr_array_add(tc->array, td);
trace->collection = tc;
int trace_collection_remove(struct trace_collection *tc,
struct trace_descriptor *td)
{
+ if (!tc || !td)
+ return -EINVAL;
+
if (g_ptr_array_remove(tc->array, td)) {
return 0;
} else {
void init_trace_collection(struct trace_collection *tc)
{
+ assert(tc);
tc->array = g_ptr_array_new();
tc->clocks = g_hash_table_new(g_direct_hash, g_direct_equal);
tc->single_clock_offset_avg = 0;
*/
void finalize_trace_collection(struct trace_collection *tc)
{
+ assert(tc);
g_ptr_array_free(tc->array, TRUE);
g_hash_table_destroy(tc->clocks);
}
{
struct bt_trace_handle *th;
+ if (!ctx)
+ return NULL;
+
th = g_new0(struct bt_trace_handle, 1);
th->id = ctx->last_trace_handle_id++;
return th;
int bt_trace_handle_get_id(struct bt_trace_handle *th)
{
+ if (!th)
+ return -1;
+
return th->id;
}
{
struct bt_trace_handle *handle;
+ if (!ctx)
+ return NULL;
+
handle = g_hash_table_lookup(ctx->trace_handles,
(gpointer) (unsigned long) handle_id);
if (!handle)
struct bt_trace_handle *handle;
uint64_t ret;
+ if (!ctx)
+ return -1ULL;
+
handle = g_hash_table_lookup(ctx->trace_handles,
(gpointer) (unsigned long) handle_id);
if (!handle) {
struct bt_trace_handle *handle;
uint64_t ret;
+ if (!ctx)
+ return -1ULL;
+
handle = g_hash_table_lookup(ctx->trace_handles,
(gpointer) (unsigned long) handle_id);
if (!handle) {