[sgen] Support binary protocol cross platform grep-ing across platforms with unequal...
authorVlad Brezae <brezaevlad@gmail.com>
Fri, 6 May 2016 01:03:31 +0000 (04:03 +0300)
committerVlad Brezae <brezaevlad@gmail.com>
Mon, 9 May 2016 23:32:54 +0000 (02:32 +0300)
tools/sgen/Makefile.am
tools/sgen/sgen-grep-binprot-main.c
tools/sgen/sgen-grep-binprot.c
tools/sgen/sgen-grep-binprot.h

index 8f9473eb55413704455aee1dfb702008ca9cdb75..ac155b0cedfb5eb43720b5bc17a86d3250d12f46 100644 (file)
@@ -2,16 +2,17 @@ bin_PROGRAMS = sgen-grep-binprot
 
 AM_CPPFLAGS =  $(GLIB_CFLAGS) -I$(top_srcdir)
 
-noinst_LIBRARIES = libsgen-grep-binprot.a libsgen-grep-binprotp.a
+noinst_LIBRARIES = libsgen-grep-binprot.a libsgen-grep-binprot32p.a libsgen-grep-binprot64p.a
 libsgen_grep_binprot_a_SOURCES = sgen-grep-binprot.c
 libsgen_grep_binprot_a_CPPFLAGS = $(GLIB_CFLAGS) -I$(top_srcdir)
-libsgen_grep_binprotp_a_SOURCES = sgen-grep-binprot.c
-libsgen_grep_binprotp_a_CPPFLAGS = $(GLIB_CFLAGS) -I$(top_srcdir) -DBINPROT_HAS_HEADER
+libsgen_grep_binprot32p_a_SOURCES = sgen-grep-binprot.c
+libsgen_grep_binprot32p_a_CPPFLAGS = $(GLIB_CFLAGS) -I$(top_srcdir) -DBINPROT_SIZEOF_VOID_P=4 -DBINPROT_HAS_HEADER
+libsgen_grep_binprot64p_a_SOURCES = sgen-grep-binprot.c
+libsgen_grep_binprot64p_a_CPPFLAGS = $(GLIB_CFLAGS) -I$(top_srcdir) -DBINPROT_SIZEOF_VOID_P=8 -DBINPROT_HAS_HEADER
 
 sgen_grep_binprot_SOURCES = \
        sgen-grep-binprot-main.c        \
-       sgen-grep-binprot.c             \
        sgen-entry-stream.c
 
 sgen_grep_binprot_LDADD = \
-       $(GLIB_LIBS) $(LIBICONV) libsgen-grep-binprot.a libsgen-grep-binprotp.a
+       $(GLIB_LIBS) $(LIBICONV) libsgen-grep-binprot.a libsgen-grep-binprot32p.a libsgen-grep-binprot64p.a
index 2b74ceda11315275b0adcc8e01a1a993386e925b..bcfbb54f54ae7223a82468a77f75675ac39c0051 100644 (file)
 #include "sgen-entry-stream.h"
 #include "sgen-grep-binprot.h"
 
+/* FIXME Add grepers for specific endianness */
 GrepEntriesFunction grepers [] = {
-       sgen_binary_protocol_grep_entriesp,
-       sgen_binary_protocol_grep_entries
+       sgen_binary_protocol_grep_entries32p, /* We have header, structures are packed, 32 bit word */
+       sgen_binary_protocol_grep_entries64p, /* We have header, structures are packed, 64 bit word */
+       sgen_binary_protocol_grep_entries /* No header, uses default word size and structure layout */
 };
 
 int
index 7b46827fcfb330d6e7ada5d13a3e3a350474de6d..4ca309f38eb6d3d8ef67ea96e4a2290bb0395b24 100644 (file)
 #define PACKED_SUFFIX
 #endif
 
-#if SIZEOF_VOID_P == 4
+#ifndef BINPROT_SIZEOF_VOID_P
+#define BINPROT_SIZEOF_VOID_P SIZEOF_VOID_P
+#define ARCH_SUFFIX
+#endif
+
+#if BINPROT_SIZEOF_VOID_P == 4
 typedef int32_t mword;
 #define MWORD_FORMAT_SPEC_D PRId32
 #define MWORD_FORMAT_SPEC_P PRIx32
+#ifndef ARCH_SUFFIX
+#define ARCH_SUFFIX    32
+#endif
 #else
 typedef int64_t mword;
 #define MWORD_FORMAT_SPEC_D PRId64
 #define MWORD_FORMAT_SPEC_P PRIx64
+#ifndef ARCH_SUFFIX
+#define ARCH_SUFFIX    64
+#endif
 #endif
 #define TYPE_SIZE      mword
 #define TYPE_POINTER   mword
@@ -560,7 +571,7 @@ sgen_binary_protocol_read_header (EntryStream *stream)
                return FALSE;
        if (type == PROTOCOL_ID (binary_protocol_header)) {
                PROTOCOL_STRUCT (binary_protocol_header) * str = (PROTOCOL_STRUCT (binary_protocol_header) *) data;
-               if (str->check == PROTOCOL_HEADER_CHECK)
+               if (str->check == PROTOCOL_HEADER_CHECK && str->ptr_size == BINPROT_SIZEOF_VOID_P)
                        return TRUE;
        }
        return FALSE;
@@ -577,7 +588,7 @@ sgen_binary_protocol_read_header (EntryStream *stream)
 
 #define CONC(A, B) CONC_(A, B)
 #define CONC_(A, B) A##B
-#define GREP_ENTRIES_FUNCTION_NAME CONC(sgen_binary_protocol_grep_entries, PACKED_SUFFIX)
+#define GREP_ENTRIES_FUNCTION_NAME CONC(sgen_binary_protocol_grep_entries, CONC(ARCH_SUFFIX,PACKED_SUFFIX))
 
 gboolean
 GREP_ENTRIES_FUNCTION_NAME (EntryStream *stream, int num_nums, long nums [], int num_vtables, long vtables [],
index 360e7d435e360970f06edda4c2aa269f5fe720f9..9025c9aa4dfed65f1d4c76160a99a96b10021af5 100644 (file)
@@ -5,5 +5,8 @@ gboolean
 sgen_binary_protocol_grep_entries (EntryStream *stream, int num_nums, long nums [], int num_vtables, long vtables [],
                         gboolean dump_all, gboolean pause_times, gboolean color_output, unsigned long long first_entry_to_consider);
 gboolean
-sgen_binary_protocol_grep_entriesp (EntryStream *stream, int num_nums, long nums [], int num_vtables, long vtables [],
+sgen_binary_protocol_grep_entries32p (EntryStream *stream, int num_nums, long nums [], int num_vtables, long vtables [],
+                        gboolean dump_all, gboolean pause_times, gboolean color_output, unsigned long long first_entry_to_consider);
+gboolean
+sgen_binary_protocol_grep_entries64p (EntryStream *stream, int num_nums, long nums [], int num_vtables, long vtables [],
                         gboolean dump_all, gboolean pause_times, gboolean color_output, unsigned long long first_entry_to_consider);