Blame SOURCES/gdb-babeltrace-minsize.patch

f9426a
http://sourceware.org/ml/gdb-patches/2014-08/msg00376.html
f9426a
Subject: Re: --with-babeltrace generates many FAILs
f9426a
f9426a
On 08/19/2014 10:07 PM, Jan Kratochvil wrote:
f9426a
>  * '#if HAVE_LIBBABELTRACE1_1_0' could have a comment that >=1.1.1 rejects the
f9426a
>    faked packet (what you described in the mail but not in the patch).
f9426a
f9426a
Fixed.  To be precise, >= 1.1.2 rejects the faked packet, 1.1.1
f9426a
doesn't.  See the table I posted.
f9426a
f9426a
>  * It is always better to check for feature/defect than to check for version.
f9426a
>    For example because various distros backport various fixes (unfortunately
f9426a
>    including their possible regressions/defects) and so version checks may be
f9426a
>    misleading then.  At least in this case it seems to me as possible to check
f9426a
>    how libbacktrace behaves from configure; although maybe it is not easy
f9426a
>    enough, not sure.
f9426a
f9426a
In order to check libbabeltrace's behaviour in configure, we have to write
f9426a
a c program to generate CTF data and read the trace data via
f9426a
babeltrace or any program (using libbabeltrace) written by ourselves.
f9426a
It is not easy to do so.
f9426a
f9426a
The patch is updated.  OK to apply?
f9426a
f9426a
-- 
f9426a
Yao (齐尧)
f9426a
f9426a
Subject: [PATCH] Check babeltrace 1.1.0
f9426a
Subject: [PATCH] Check babeltrace 1.1.0
f9426a
f9426a
When GDB uses recent version of babeltrace, such as 1.2.x, we'll see
f9426a
such error emitted from babeltrace library,
f9426a
f9426a
 (gdb) target ctf .../gdb/testsuite/gdb.trace/actions.ctf
f9426a
 [error] Invalid CTF stream: content size is smaller than
f9426a
packet headers.
f9426a
 [error] Stream index creation error.
f9426a
 [error] Open file stream error.
f9426a
f9426a
The problem can be reproduce out of GDB too, using babeltrace,
f9426a
f9426a
 $ babeltrace ./fake-packet.ctf/
f9426a
 [error] Invalid CTF stream: content size is smaller than packet headers.
f9426a
 [error] Stream index creation error.
f9426a
 [error] Open file stream error.
f9426a
f9426a
Recent babeltrace library becomes more strict on CTF, and complains
f9426a
about one "faked packet" GDB adds, when saving trace data in ctf
f9426a
format from GDB.  babeltrace 1.1.0 has a bug that it can't read trace
f9426a
data smaller than a certain size (see https://bugs.lttng.org/issues/450).
f9426a
We workaround it in GDB to append some meaningless data in a faked
f9426a
packet to make sure trace file is large enough (see ctf.c:ctf_end).
f9426a
The babeltrace issue was fixed in 1.1.1 release.  However, babeltrace
f9426a
recent release (since 1.1.2) starts to complain about such faked
f9426a
packet.  Here is a table shows that whether faked packet or no faked
f9426a
packet is supported by various babeltrace releases,
f9426a
f9426a
        faked packet      no faked packet
f9426a
1.1.0      Yes                 No
f9426a
1.1.1      Yes                 Yes
f9426a
1.1.2      No                  Yes
f9426a
1.2.0      No                  Yes
f9426a
f9426a
We decide to include the code to workaround 1.1.0 issue only if 1.1.0
f9426a
is used.  We choose pkg-config to check babeltrace's version in
f9426a
configure.
f9426a
f9426a
gdb:
f9426a
f9426a
2014-08-20  Yao Qi  <yao@codesourcery.com>
f9426a
f9426a
	* configure.ac: Disable babeltrace support if pkg-config is
f9426a
	missing.  Use pkg-config to check whether libbabeltrace is
f9426a
	1.1.0.
f9426a
	* config.in: Regenerate.
f9426a
	* configure: Regenerate.
f9426a
	* ctf.c (CTF_FILE_MIN_SIZE): Remove.
f9426a
	(ctf_end): Wrap the code with
f9426a
	#if HAVE_LIBBABELTRACE1_1_0 #endif.
f9426a
	[HAVE_LIBBABELTRACE1_1_0] (CTF_FILE_MIN_SIZE): New macro.
f9426a
---
f9426a
 gdb/config.in    |  3 +++
f9426a
 gdb/configure    | 25 +++++++++++++++++++++++++
f9426a
 gdb/configure.ac | 22 ++++++++++++++++++++++
f9426a
 gdb/ctf.c        | 25 ++++++++++++++++---------
f9426a
 4 files changed, 66 insertions(+), 9 deletions(-)
f9426a
f9426a
diff --git a/gdb/config.in b/gdb/config.in
f9426a
index b853412..54152cd 100644
f9426a
--- a/gdb/config.in
f9426a
+++ b/gdb/config.in
f9426a
@@ -183,6 +183,9 @@
f9426a
 /* Define if you have the babeltrace library. */
f9426a
 #undef HAVE_LIBBABELTRACE
f9426a
 
f9426a
+/* Define to 1 if you have libbabeltrace 1.1.0 */
f9426a
+#undef HAVE_LIBBABELTRACE1_1_0
f9426a
+
f9426a
 /* Define to 1 if you have the `dl' library (-ldl). */
f9426a
 #undef HAVE_LIBDL
f9426a
 
f9426a
diff --git a/gdb/configure b/gdb/configure
f9426a
index 9253e28..d4e2c6e 100755
f9426a
--- a/gdb/configure
f9426a
+++ b/gdb/configure
f9426a
@@ -14817,6 +14817,11 @@ $as_echo "$with_babeltrace" >&6; }
f9426a
 if test "x$with_babeltrace" = "xno"; then
f9426a
   { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: babletrace support disabled; GDB is unable to read CTF data." >&5
f9426a
 $as_echo "$as_me: WARNING: babletrace support disabled; GDB is unable to read CTF data." >&2;}
f9426a
+elif test "${pkg_config_prog_path}" = "missing"; then
f9426a
+  # pkg-config is used to check the version of libbabeltrace.  If pkg-config
f9426a
+  # is missing, we have to disable babeltrace support.
f9426a
+  { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: pkg-config not found, babletrace support disabled" >&5
f9426a
+$as_echo "$as_me: WARNING: pkg-config not found, babletrace support disabled" >&2;}
f9426a
 else
f9426a
   # Append -Werror to CFLAGS so that configure can catch the warning
f9426a
   # "assignment from incompatible pointer type", which is related to
f9426a
@@ -15307,6 +15312,26 @@ $as_echo "$LIBBABELTRACE" >&6; }
f9426a
        { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: babeltrace is missing or unusable; GDB is unable to read CTF data." >&5
f9426a
 $as_echo "$as_me: WARNING: babeltrace is missing or unusable; GDB is unable to read CTF data." >&2;}
f9426a
      fi
f9426a
+  else
f9426a
+     # Need to know whether libbabeltrace is 1.1.0.
f9426a
+     pkg_config_path=
f9426a
+     for x in $LTLIBBABELTRACE; do
f9426a
+       case "$x" in
f9426a
+         -L*)
f9426a
+	   dir=`echo "X$x" | sed -e 's/^X-L//'`
f9426a
+	   if test -d "$dir/pkgconfig"; then
f9426a
+	     pkg_config_path="${pkg_config_path}${pkg_config_path:+:}$dir/pkgconfig"
f9426a
+	   fi
f9426a
+	   ;;
f9426a
+       esac
f9426a
+     done
f9426a
+
f9426a
+     `PKG_CONFIG_PATH=$PKG_CONFIG_PATH:$pkg_config_path ${pkg_config_prog_path} babeltrace = 1.1.0`
f9426a
+     if test "$?" -eq 0 ; then
f9426a
+
f9426a
+$as_echo "#define HAVE_LIBBABELTRACE1_1_0 1" >>confdefs.h
f9426a
+
f9426a
+     fi
f9426a
   fi
f9426a
 fi
f9426a
 
f9426a
diff --git a/gdb/configure.ac b/gdb/configure.ac
f9426a
index 61919b4..1d8d400 100644
f9426a
--- a/gdb/configure.ac
f9426a
+++ b/gdb/configure.ac
f9426a
@@ -2420,6 +2420,10 @@ AC_MSG_RESULT([$with_babeltrace])
f9426a
 
f9426a
 if test "x$with_babeltrace" = "xno"; then
f9426a
   AC_MSG_WARN([babletrace support disabled; GDB is unable to read CTF data.])
f9426a
+elif test "${pkg_config_prog_path}" = "missing"; then
f9426a
+  # pkg-config is used to check the version of libbabeltrace.  If pkg-config
f9426a
+  # is missing, we have to disable babeltrace support.
f9426a
+  AC_MSG_WARN([pkg-config not found, babletrace support disabled])
f9426a
 else
f9426a
   # Append -Werror to CFLAGS so that configure can catch the warning
f9426a
   # "assignment from incompatible pointer type", which is related to
f9426a
@@ -2450,6 +2454,24 @@ else
f9426a
      else
f9426a
        AC_MSG_WARN([babeltrace is missing or unusable; GDB is unable to read CTF data.])
f9426a
      fi
f9426a
+  else
f9426a
+     # Need to know whether libbabeltrace is 1.1.0.
f9426a
+     pkg_config_path=
f9426a
+     for x in $LTLIBBABELTRACE; do
f9426a
+       case "$x" in
f9426a
+         -L*)
f9426a
+	   dir=`echo "X$x" | sed -e 's/^X-L//'`
f9426a
+	   if test -d "$dir/pkgconfig"; then
f9426a
+	     pkg_config_path="${pkg_config_path}${pkg_config_path:+:}$dir/pkgconfig"
f9426a
+	   fi
f9426a
+	   ;;
f9426a
+       esac
f9426a
+     done
f9426a
+
f9426a
+     `PKG_CONFIG_PATH=$PKG_CONFIG_PATH:$pkg_config_path ${pkg_config_prog_path} babeltrace = 1.1.0`
f9426a
+     if test "$?" -eq 0 ; then
f9426a
+       AC_DEFINE([HAVE_LIBBABELTRACE1_1_0], [1], [Define to 1 if you have libbabeltrace 1.1.0])
f9426a
+     fi
f9426a
   fi
f9426a
 fi
f9426a
 
f9426a
diff --git a/gdb/ctf.c b/gdb/ctf.c
f9426a
index df645c0..684da50 100644
f9426a
--- a/gdb/ctf.c
f9426a
+++ b/gdb/ctf.c
f9426a
@@ -623,11 +623,6 @@ ctf_write_definition_end (struct trace_file_writer *self)
f9426a
   self->ops->frame_ops->end (self);
f9426a
 }
f9426a
 
f9426a
-/* The minimal file size of data stream.  It is required by
f9426a
-   babeltrace.  */
f9426a
-
f9426a
-#define CTF_FILE_MIN_SIZE		4096
f9426a
-
f9426a
 /* This is the implementation of trace_file_write_ops method
f9426a
    end.  */
f9426a
 
f9426a
@@ -637,10 +632,21 @@ ctf_end (struct trace_file_writer *self)
f9426a
   struct ctf_trace_file_writer *writer = (struct ctf_trace_file_writer *) self;
f9426a
 
f9426a
   gdb_assert (writer->tcs.content_size == 0);
f9426a
-  /* The babeltrace requires or assumes that the size of datastream
f9426a
-     file is greater than 4096 bytes.  If we don't generate enough
f9426a
-     packets and events, create a fake packet which has zero event,
f9426a
-      to use up the space.  */
f9426a
+
f9426a
+#if HAVE_LIBBABELTRACE1_1_0
f9426a
+  /* The babeltrace-1.1.0 requires or assumes that the size of datastream
f9426a
+     file is greater than 4096 bytes.  This was fixed after 1.1.0 release.
f9426a
+     See https://bugs.lttng.org/issues/450
f9426a
+     If we don't generate enough packets and events, create a fake packet
f9426a
+     which has zero event, to use up the space.  However, babeltrace
f9426a
+     release (since 1.1.2) starts to complain about such faked packet,
f9426a
+     we include this workaround only for babeltrace 1.1.0.  */
f9426a
+
f9426a
+  /* The minimal file size of data stream.  It is required by
f9426a
+     babeltrace.  */
f9426a
+
f9426a
+#define CTF_FILE_MIN_SIZE		4096
f9426a
+
f9426a
   if (writer->tcs.packet_start < CTF_FILE_MIN_SIZE)
f9426a
     {
f9426a
       uint32_t u32;
f9426a
@@ -681,6 +687,7 @@ ctf_end (struct trace_file_writer *self)
f9426a
 	  ctf_save_write (&writer->tcs, &b, 1);
f9426a
 	}
f9426a
     }
f9426a
+#endif /* HAVE_LIBBABELTRACE1_1_0 */
f9426a
 }
f9426a
 
f9426a
 /* This is the implementation of trace_frame_write_ops method
f9426a
-- 
f9426a
1.9.3
f9426a