From: Philippe Proulx Date: Fri, 2 Jun 2017 18:11:49 +0000 (-0400) Subject: ir: do not try to create initial packet/event fields when opt. FT is NULL X-Git-Tag: v2.0.0-pre1~56 X-Git-Url: http://git.efficios.com/?p=babeltrace.git;a=commitdiff_plain;h=be514b0cc5125839619739b796190951ba45bb22 ir: do not try to create initial packet/event fields when opt. FT is NULL If a trace has not packet header field type, then when creating a packet, do not attempt to create the initial packet header field without checking that the field type is NULL because this is a violation of preconditions. The main side effect here is a WARN-level log message even if the situation is normal. Signed-off-by: Philippe Proulx Signed-off-by: Jérémie Galarneau --- diff --git a/lib/ctf-ir/event.c b/lib/ctf-ir/event.c index 1ab1be57..9a552e7b 100644 --- a/lib/ctf-ir/event.c +++ b/lib/ctf-ir/event.c @@ -174,14 +174,21 @@ struct bt_ctf_event *bt_ctf_event_create(struct bt_ctf_event_class *event_class) event->event_class = bt_get(event_class); event->clock_values = g_hash_table_new_full(g_direct_hash, g_direct_equal, bt_put, bt_put); - event_header = - bt_ctf_field_create(validation_output.event_header_type); - if (!event_header) { - BT_LOGE_STR("Cannot create initial event header field object."); - goto error; + + if (validation_output.event_header_type) { + BT_LOGD("Creating initial event header field: ft-addr=%p", + validation_output.event_header_type); + event_header = + bt_ctf_field_create(validation_output.event_header_type); + if (!event_header) { + BT_LOGE_STR("Cannot create initial event header field object."); + goto error; + } } if (validation_output.stream_event_ctx_type) { + BT_LOGD("Creating initial stream event context field: ft-addr=%p", + validation_output.stream_event_ctx_type); stream_event_context = bt_ctf_field_create( validation_output.stream_event_ctx_type); if (!stream_event_context) { @@ -191,6 +198,8 @@ struct bt_ctf_event *bt_ctf_event_create(struct bt_ctf_event_class *event_class) } if (validation_output.event_context_type) { + BT_LOGD("Creating initial event context field: ft-addr=%p", + validation_output.event_context_type); event_context = bt_ctf_field_create( validation_output.event_context_type); if (!event_context) { @@ -200,6 +209,8 @@ struct bt_ctf_event *bt_ctf_event_create(struct bt_ctf_event_class *event_class) } if (validation_output.event_payload_type) { + BT_LOGD("Creating initial event payload field: ft-addr=%p", + validation_output.event_payload_type); event_payload = bt_ctf_field_create( validation_output.event_payload_type); if (!event_payload) { diff --git a/lib/ctf-ir/packet.c b/lib/ctf-ir/packet.c index 75588149..9ec77dea 100644 --- a/lib/ctf-ir/packet.c +++ b/lib/ctf-ir/packet.c @@ -25,6 +25,7 @@ */ #define BT_LOG_TAG "PACKET" +#include #include #include @@ -35,9 +36,9 @@ #include #include #include -#include #include #include +#include struct bt_ctf_stream *bt_ctf_packet_get_stream(struct bt_ctf_packet *packet) { @@ -224,13 +225,19 @@ struct bt_ctf_packet *bt_ctf_packet_create( struct bt_ctf_stream_class *stream_class = NULL; struct bt_ctf_trace *trace = NULL; - BT_LOGD("Creating packet object: stream-addr=%p", stream); - if (!stream) { BT_LOGW_STR("Invalid parameter: stream is NULL."); goto end; } + BT_LOGD("Creating packet object: stream-addr=%p, " + "stream-name=\"%s\", stream-class-addr=%p, " + "stream-class-name=\"%s\", stream-class-id=%" PRId64, + stream, bt_ctf_stream_get_name(stream), + stream->stream_class, + bt_ctf_stream_class_get_name(stream->stream_class), + bt_ctf_stream_class_get_id(stream->stream_class)); + if (stream->pos.fd >= 0) { BT_LOGW_STR("Invalid parameter: stream is a CTF writer stream."); goto end; @@ -248,19 +255,28 @@ struct bt_ctf_packet *bt_ctf_packet_create( bt_object_init(packet, bt_ctf_packet_destroy); packet->stream = bt_get(stream); - packet->header = bt_ctf_field_create(trace->packet_header_type); - if (!packet->header && trace->packet_header_type) { - BT_LOGE_STR("Cannot create initial packet header field object."); - BT_PUT(packet); - goto end; + + if (trace->packet_header_type) { + BT_LOGD("Creating initial packet header field: ft-addr=%p", + trace->packet_header_type); + packet->header = bt_ctf_field_create(trace->packet_header_type); + if (!packet->header) { + BT_LOGE_STR("Cannot create initial packet header field object."); + BT_PUT(packet); + goto end; + } } - packet->context = bt_ctf_field_create( - stream->stream_class->packet_context_type); - if (!packet->context && stream->stream_class->packet_context_type) { - BT_LOGE_STR("Cannot create initial packet header field object."); - BT_PUT(packet); - goto end; + if (stream->stream_class->packet_context_type) { + BT_LOGD("Creating initial packet context field: ft-addr=%p", + stream->stream_class->packet_context_type); + packet->context = bt_ctf_field_create( + stream->stream_class->packet_context_type); + if (!packet->context) { + BT_LOGE_STR("Cannot create initial packet header field object."); + BT_PUT(packet); + goto end; + } } BT_LOGD("Created packet object: addr=%p", packet);