[PATCH 2/3] Write CTF in host byte order

Yao Qi yao@codesourcery.com
Wed Mar 20 03:48:00 GMT 2013


On 03/20/2013 05:05 AM, Joel Brobecker wrote:
>> >    ctf_save_write_metadata (handler, metadata_fmt,
>> >  			   CTF_SAVE_MAJOR, CTF_SAVE_MINOR,
>> >-			   BYTE_ORDER == LITTLE_ENDIAN ? "le" : "be");
>> >+			   HOST_ENDIANNESS);
>    +                        WORDS_BIGENDIAN ? "be" : "le");
> 
> Either way really works for me, especially if you think you might
> be using HOST_ENDIANNESS elsewhere again sometime.
> 

Joel, thanks for the review.  Your suggestion doesn't compile on little
endian machine, because WORDS_BIGENDIAN is not defined.  In the
autoconf manual:

"The default for action-if-true is to define ‘WORDS_BIGENDIAN’. The
default for action-if-false is to do nothing."

> You can commit with a comment or the change I suggested. If someone
> objects, it's easy to revert or adjust.

Patch below is what I committed.

-- 
Yao (齐尧)

gdb:

2013-03-20  Yao Qi  <yao@codesourcery.com>

	* ctf.c (ctf_save_metadata_header): Define macro HOST_ENDIANNESS
	and write it to CTF metadata.
---
 gdb/ctf.c |   10 +++++++++-
 1 files changed, 9 insertions(+), 1 deletions(-)

diff --git a/gdb/ctf.c b/gdb/ctf.c
index f77eb7d..455bfde 100644
--- a/gdb/ctf.c
+++ b/gdb/ctf.c
@@ -242,9 +242,17 @@ ctf_save_metadata_header (struct trace_write_handler *handler)
 			   " } := chars;\n");
   ctf_save_write_metadata (handler, "\n");
 
+  /* Get the byte order of the host and write CTF data in this byte
+     order.  */
+#if WORDS_BIGENDIAN
+#define HOST_ENDIANNESS "be"
+#else
+#define HOST_ENDIANNESS "le"
+#endif
+
   ctf_save_write_metadata (handler, metadata_fmt,
 			   CTF_SAVE_MAJOR, CTF_SAVE_MINOR,
-			   BYTE_ORDER == LITTLE_ENDIAN ? "le" : "be");
+			   HOST_ENDIANNESS);
   ctf_save_write_metadata (handler, "\n");
 }
 
-- 
1.7.7.6



More information about the Gdb-patches mailing list