From 3f5808e584c030d29db447ecffd42496d09b85fb Mon Sep 17 00:00:00 2001 From: Philippe Proulx Date: Mon, 3 Apr 2017 18:05:19 -0400 Subject: [PATCH] CTF writer: restore native byte order is the CPU's native byte order MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit To remain compatible with the first experiments of CTF writer, let's restore this legacy behaviour in which a native byte order means the native byte order of the CPU running the Babeltrace library. This only applies to bt_ctf_writer_set_byte_order() when you pass BT_CTF_BYTE_ORDER_NATIVE: bt_ctf_trace_set_native_byte_order() does not accept BT_CTF_BYTE_ORDER_NATIVE. Thus, when you create a CTF writer object with bt_ctf_writer_create(), it sets its trace's native byte order to the CPU's native byte order. perf is a CTF writer user known to not call bt_ctf_writer_set_byte_order() manually: in this case the CTF IR trace would be invalid because its native byte order would still be set to BT_CTF_BYTE_ORDER_NATIVE. Signed-off-by: Philippe Proulx Signed-off-by: Jérémie Galarneau --- include/babeltrace/endian.h | 6 ++++++ lib/ctf-writer/serialize.c | 9 +-------- lib/ctf-writer/writer.c | 11 +++++++++++ 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/include/babeltrace/endian.h b/include/babeltrace/endian.h index c5e5d705..55f8d1ec 100644 --- a/include/babeltrace/endian.h +++ b/include/babeltrace/endian.h @@ -222,4 +222,10 @@ #endif /* __FLOAT_WORD_ORDER */ #endif /* FLOAT_WORD_ORDER */ +#if (BYTE_ORDER == BIG_ENDIAN) +# define BT_CTF_MY_BYTE_ORDER BT_CTF_BYTE_ORDER_BIG_ENDIAN +#else +# define BT_CTF_MY_BYTE_ORDER BT_CTF_BYTE_ORDER_LITTLE_ENDIAN +#endif + #endif /* _BABELTRACE_ENDIAN_H */ diff --git a/lib/ctf-writer/serialize.c b/lib/ctf-writer/serialize.c index 6058dd35..0e04229f 100644 --- a/lib/ctf-writer/serialize.c +++ b/lib/ctf-writer/serialize.c @@ -43,13 +43,6 @@ #include #include -/* "Native" to CTF IR byte order */ -#if (BYTE_ORDER == LITTLE_ENDIAN) -# define MY_BT_CTF_BYTE_ORDER BT_CTF_BYTE_ORDER_LITTLE_ENDIAN -#else -# define MY_BT_CTF_BYTE_ORDER BT_CTF_BYTE_ORDER_BIG_ENDIAN -#endif - #if (FLT_RADIX != 2) # error "Unsupported floating point radix" #endif @@ -69,7 +62,7 @@ int aligned_integer_write(struct bt_ctf_stream_pos *pos, union intval value, unsigned int alignment, unsigned int size, bool is_signed, enum bt_ctf_byte_order byte_order) { - bool rbo = (byte_order != MY_BT_CTF_BYTE_ORDER); /* reverse byte order */ + bool rbo = (byte_order != BT_CTF_MY_BYTE_ORDER); /* reverse byte order */ if (!bt_ctf_stream_pos_align(pos, alignment)) return -EFAULT; diff --git a/lib/ctf-writer/writer.c b/lib/ctf-writer/writer.c index c822d63f..c0dbdbb0 100644 --- a/lib/ctf-writer/writer.c +++ b/lib/ctf-writer/writer.c @@ -35,6 +35,7 @@ #include #include #include +#include #include #include #include @@ -49,6 +50,7 @@ void bt_ctf_writer_destroy(struct bt_object *obj); struct bt_ctf_writer *bt_ctf_writer_create(const char *path) { + int ret; struct bt_ctf_writer *writer = NULL; if (!path) { @@ -74,6 +76,11 @@ struct bt_ctf_writer *bt_ctf_writer_create(const char *path) writer->trace->is_created_by_writer = 1; bt_object_set_parent(writer->trace, writer); bt_put(writer->trace); + + /* Default to little-endian */ + ret = bt_ctf_writer_set_byte_order(writer, BT_CTF_BYTE_ORDER_NATIVE); + assert(ret == 0); + /* Create trace directory if necessary and open a metadata file */ if (g_mkdir_with_parents(path, S_IRWXU | S_IRWXG)) { perror("g_mkdir_with_parents"); @@ -298,6 +305,10 @@ int bt_ctf_writer_set_byte_order(struct bt_ctf_writer *writer, goto end; } + if (byte_order == BT_CTF_BYTE_ORDER_NATIVE) { + byte_order = BT_CTF_MY_BYTE_ORDER; + } + ret = bt_ctf_trace_set_native_byte_order(writer->trace, byte_order); end: -- 2.34.1