There's a problem now where you need to explicitly set the native byte
order of a trace you create with bt_ctf_trace_create() with
bt_ctf_trace_set_native_byte_order() before the trace object is frozen,
otherwise the function which would cause the freezing fails.
Some trace formats have no byte order concept. Other properties like
alignment and binary field sizes may have no meaning either. Source
component classes which implement the decoding of those formats should
do a best effort to represent their trace's metadata using CTF IR. That
said, choosing an arbitrary trace's native byte order imposes this byte
order when a ctf.fs sink writes the trace. Here, BT_CTF_BYTE_ORDER_NONE
means that we don't care about the byte order, that it was not
meaningful when decoding the original trace, therefore you can choose
any output byte order you want.
With this patch, the initial trace's native byte order is
BT_CTF_BYTE_ORDER_NONE, and this is a valid byte order when the trace
needs to be frozen. A non-CTF writer trace cannot be used by a CTF
writer object anyway; a CTF writer always creates its own trace object.
The initial native byte order of a CTF writer trace is the machine's
byte order. You cannot set a CTF writer trace's native byte order to
BT_CTF_BYTE_ORDER_NONE. Also, you cannot set any field type's byte order
to BT_CTF_BYTE_ORDER_NONE: it's only valid for a non-CTF writer trace.
libctfcopytrace is modified to only explicitly set the CTF writer
trace's native byte order if the original trace's native byte order is
not BT_CTF_BYTE_ORDER_NONE.
Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
switch (bo) {
case BT_CTF_BYTE_ORDER_UNKNOWN:
return "BT_CTF_BYTE_ORDER_UNKNOWN";
switch (bo) {
case BT_CTF_BYTE_ORDER_UNKNOWN:
return "BT_CTF_BYTE_ORDER_UNKNOWN";
+ case BT_CTF_BYTE_ORDER_NONE:
+ return "BT_CTF_BYTE_ORDER_NONE";
case BT_CTF_BYTE_ORDER_NATIVE:
return "BT_CTF_BYTE_ORDER_NATIVE";
case BT_CTF_BYTE_ORDER_LITTLE_ENDIAN:
case BT_CTF_BYTE_ORDER_NATIVE:
return "BT_CTF_BYTE_ORDER_NATIVE";
case BT_CTF_BYTE_ORDER_LITTLE_ENDIAN:
/// Native (default) byte order.
BT_CTF_BYTE_ORDER_NATIVE = 0,
/// Native (default) byte order.
BT_CTF_BYTE_ORDER_NATIVE = 0,
+ /**
+ No byte order; the initial native byte order of a
+ \link ctfirtraceclass CTF IR trace class\endlink.
+ */
+ BT_CTF_BYTE_ORDER_NONE,
+
/// Little-endian.
BT_CTF_BYTE_ORDER_LITTLE_ENDIAN,
/// Little-endian.
BT_CTF_BYTE_ORDER_LITTLE_ENDIAN,
with bt_ctf_trace_set_name().
- <strong>UUID</strong>: none. You can set a UUID with
bt_ctf_trace_set_uuid().
with bt_ctf_trace_set_name().
- <strong>UUID</strong>: none. You can set a UUID with
bt_ctf_trace_set_uuid().
-- <strong>Native byte order</strong>: #BT_CTF_BYTE_ORDER_NATIVE. You
+- <strong>Native byte order</strong>: #BT_CTF_BYTE_ORDER_NONE. You
can set a native byte order with bt_ctf_trace_set_native_byte_order().
can set a native byte order with bt_ctf_trace_set_native_byte_order().
-
- Note that you \em must set the native byte order if any field type
- contained in the created trace class, in its stream classes, or in
- its event classes, has a byte order set to #BT_CTF_BYTE_ORDER_NATIVE.
- <strong>Environment</strong>: empty. You can add environment entries
with bt_ctf_trace_set_environment_field(),
bt_ctf_trace_set_environment_field_integer(), and
- <strong>Environment</strong>: empty. You can add environment entries
with bt_ctf_trace_set_environment_field(),
bt_ctf_trace_set_environment_field_integer(), and
- #BT_CTF_BYTE_ORDER_LITTLE_ENDIAN
- #BT_CTF_BYTE_ORDER_BIG_ENDIAN
- #BT_CTF_BYTE_ORDER_NETWORK
- #BT_CTF_BYTE_ORDER_LITTLE_ENDIAN
- #BT_CTF_BYTE_ORDER_BIG_ENDIAN
- #BT_CTF_BYTE_ORDER_NETWORK
+- <strong>If the trace is not in CTF writer mode<strong>,
+ #BT_CTF_BYTE_ORDER_NONE.
@param[in] trace_class Trace class of which to set the native byte
order.
@param[in] trace_class Trace class of which to set the native byte
order.
@prenotnull{trace_class}
@prehot{trace_class}
@prenotnull{trace_class}
@prehot{trace_class}
-@pre \p native_byte_order is either #BT_CTF_BYTE_ORDER_LITTLE_ENDIAN,
- #BT_CTF_BYTE_ORDER_BIG_ENDIAN, or
+@pre \p native_byte_order is either #BT_CTF_BYTE_ORDER_NONE (if the
+ trace is not in CTF writer mode),
+ #BT_CTF_BYTE_ORDER_LITTLE_ENDIAN, #BT_CTF_BYTE_ORDER_BIG_ENDIAN, or
#BT_CTF_BYTE_ORDER_NETWORK.
@postrefcountsame{trace_class}
#BT_CTF_BYTE_ORDER_NETWORK.
@postrefcountsame{trace_class}
byte_order != BT_CTF_BYTE_ORDER_LITTLE_ENDIAN &&
byte_order != BT_CTF_BYTE_ORDER_BIG_ENDIAN &&
byte_order != BT_CTF_BYTE_ORDER_NETWORK) {
byte_order != BT_CTF_BYTE_ORDER_LITTLE_ENDIAN &&
byte_order != BT_CTF_BYTE_ORDER_BIG_ENDIAN &&
byte_order != BT_CTF_BYTE_ORDER_NETWORK) {
- BT_LOGW("Invalid parameter: unknown byte order: "
+ BT_LOGW("Invalid parameter: invalid byte order: "
"addr=%p, bo=%s", type,
bt_ctf_byte_order_string(byte_order));
ret = -1;
"addr=%p, bo=%s", type,
bt_ctf_byte_order_string(byte_order));
ret = -1;
}
BT_LOGD_STR("Creating trace object.");
}
BT_LOGD_STR("Creating trace object.");
- trace->native_byte_order = BT_CTF_BYTE_ORDER_NATIVE;
+ trace->native_byte_order = BT_CTF_BYTE_ORDER_NONE;
bt_object_init(trace, bt_ctf_trace_destroy);
trace->clocks = g_ptr_array_new_with_free_func(
(GDestroyNotify) bt_put);
bt_object_init(trace, bt_ctf_trace_destroy);
trace->clocks = g_ptr_array_new_with_free_func(
(GDestroyNotify) bt_put);
stream_class, bt_ctf_stream_class_get_name(stream_class),
bt_ctf_stream_class_get_id(stream_class));
stream_class, bt_ctf_stream_class_get_name(stream_class),
bt_ctf_stream_class_get_id(stream_class));
- /*
- * At the end of this function we freeze the trace, so its
- * native byte order must NOT be BT_CTF_BYTE_ORDER_NATIVE.
- */
- if (trace->native_byte_order == BT_CTF_BYTE_ORDER_NATIVE) {
- BT_LOGW_STR("Invalid parameter: trace's byte order cannot be BT_CTF_BYTE_ORDER_NATIVE at this point; "
- "set it with bt_ctf_trace_set_native_byte_order().");
- ret = -1;
- goto end;
- }
-
current_parent_trace = bt_ctf_stream_class_get_trace(stream_class);
if (current_parent_trace) {
/* Stream class is already associated to a trace, abort. */
current_parent_trace = bt_ctf_stream_class_get_trace(stream_class);
if (current_parent_trace) {
/* Stream class is already associated to a trace, abort. */
unsigned char *uuid = trace->uuid;
int ret = 0;
unsigned char *uuid = trace->uuid;
int ret = 0;
- if (trace->native_byte_order == BT_CTF_BYTE_ORDER_NATIVE) {
- BT_LOGW("Invalid parameter: trace's byte order cannot be BT_CTF_BYTE_ORDER_NATIVE at this point; "
+ if (trace->native_byte_order == BT_CTF_BYTE_ORDER_NATIVE ||
+ trace->native_byte_order == BT_CTF_BYTE_ORDER_NONE) {
+ BT_LOGW("Invalid parameter: trace's byte order cannot be BT_CTF_BYTE_ORDER_NATIVE or BT_CTF_BYTE_ORDER_NONE at this point; "
"set it with bt_ctf_trace_set_native_byte_order(): "
"addr=%p, name=\"%s\"",
trace, bt_ctf_trace_get_name(trace));
"set it with bt_ctf_trace_set_native_byte_order(): "
"addr=%p, name=\"%s\"",
trace, bt_ctf_trace_get_name(trace));
+ if (trace->is_created_by_writer &&
+ byte_order == BT_CTF_BYTE_ORDER_NONE) {
+ BT_LOGW("Invalid parameter: BT_CTF_BYTE_ORDER_NONE byte order is not allowed for a CTF writer trace: "
+ "addr=%p, name=\"%s\"",
+ trace, bt_ctf_trace_get_name(trace));
+ ret = -1;
+ goto end;
+ }
+
if (byte_order != BT_CTF_BYTE_ORDER_LITTLE_ENDIAN &&
byte_order != BT_CTF_BYTE_ORDER_BIG_ENDIAN &&
byte_order != BT_CTF_BYTE_ORDER_NETWORK) {
if (byte_order != BT_CTF_BYTE_ORDER_LITTLE_ENDIAN &&
byte_order != BT_CTF_BYTE_ORDER_BIG_ENDIAN &&
byte_order != BT_CTF_BYTE_ORDER_NETWORK) {
- ret = bt_ctf_trace_set_native_byte_order(writer_trace, order);
- if (ret) {
- fprintf(err, "[error] %s in %s:%d\n", __func__, __FILE__, __LINE__);
- ret = BT_COMPONENT_STATUS_ERROR;
- goto end;
+ /*
+ * Only explicitly set the writer trace's native byte order if
+ * the original trace has a specific one. Otherwise leave what
+ * the CTF writer object chooses, which is the machine's native
+ * byte order.
+ */
+ if (order != BT_CTF_BYTE_ORDER_NONE) {
+ ret = bt_ctf_trace_set_native_byte_order(writer_trace, order);
+ if (ret) {
+ fprintf(err, "[error] %s in %s:%d\n", __func__, __FILE__, __LINE__);
+ ret = BT_COMPONENT_STATUS_ERROR;
+ goto end;
+ }
}
header_type = bt_ctf_trace_get_packet_header_type(writer_trace);
}
header_type = bt_ctf_trace_get_packet_header_type(writer_trace);