This is the mail archive of the mailing list for the GDB project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Make explicitly treat .{sum,log} files as text

This weekend I was running GDB's testsuite with many options enabled,
and I noticed that, for some specific configurations (specifically
when testing gdbserver), I was getting the following error: sum files are for multiple tools, specify a tool

I remembered seeing this a lot before, so I spent some time
investigating the cause...

First, I found the line on that printed this
error message.  The code does:

  CNT=`grep '=== .* tests ===' $SUM_FILES --text | $AWK '{ print $3 }' | sort -u | wc -l`
  if [ $CNT -eq 1 ]; then
    TOOL=`grep '=== .* tests ===' $FIRST_SUM --text | $AWK '{ print $2 }'`
    msg "${PROGNAME}: sum files are for multiple tools, specify a tool"
    msg ""
    exit 1

So, the first thing to do was to identify why $CNT was not 1.  When I
ran the command that generated the result for CNT, I found:

  $ grep '=== .* tests ===' `find outputs -name gdb.log -print` \
     | awk '{ print $3 }' | sort -u | wc -l

Hm, strange.  So, removing the wc command, the output was:


And, when I used only the grep command, without the awk and the sort,
I saw that the majority of the lines were like this:

  outputs/gdb.trace/tfind/gdb.log:                === gdb tests ===

Which would generated the first line in the output above, "gdb".  But,
for the other 6 files above, I saw:

  Binary file outputs/gdb.base/gdb-sigterm/gdb.log matches

Right, the problem is that grep is assuming those 6 files are binary,
not text.  This happens because of this code, in grep:


  static enum textbin
  buffer_textbin (char *buf, size_t size)
    if (eolbyte && memchr (buf, '\0', size))
      return TEXTBIN_BINARY;

If one looks at those 6 files, one will find that they contain the NUL
byte there.  They are all printed by the same message, by gdbserver's

  input_interrupt, count = 0 c = 0 ('^@')

(The ^@ above is the NUL byte.)

Maybe the right fix would be to improve input_interrupt in
gdbserver/remote-utils.c (see PR server/16359), but I decided to go
the easier route and adjust the to be more
robust when dealing with the sum and log files.  To do that, I am
suggest passing the '--text' option to grep, which overrides grep's
machinery to identify if the file is binary and forces it to treat
every file as text.  For me, it makes sense to do that because sum and
log files will always be text, no matter what happens.

OK to apply?

2014-12-14  Sergio Durigan Junior  <>

	* Pass '--text' option to grep when
	filtering .{sum,log} files, which may contain binary data.
 gdb/testsuite/ | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/gdb/testsuite/ b/gdb/testsuite/
index 42190ae..5fe935a 100755
--- a/gdb/testsuite/
+++ b/gdb/testsuite/
@@ -120,9 +120,9 @@ if [ -z "$TOOL" ]; then
   # If no tool was specified, all specified summary files must be for
   # the same tool.
-  CNT=`grep '=== .* tests ===' $SUM_FILES | $AWK '{ print $3 }' | sort -u | wc -l`
+  CNT=`grep '=== .* tests ===' $SUM_FILES --text | $AWK '{ print $3 }' | sort -u | wc -l`
   if [ $CNT -eq 1 ]; then
-    TOOL=`grep '=== .* tests ===' $FIRST_SUM | $AWK '{ print $2 }'`
+    TOOL=`grep '=== .* tests ===' $FIRST_SUM --text | $AWK '{ print $2 }'`
     msg "${PROGNAME}: sum files are for multiple tools, specify a tool"
     msg ""
@@ -133,7 +133,7 @@ else
   # Ignore the specified summary files that are not for this tool.  This
   # should keep the relevant files in the same order.
-  SUM_FILES=`grep -l "=== $TOOL" $SUM_FILES`
+  SUM_FILES=`grep -l "=== $TOOL" $SUM_FILES --text`
   if test -z "$SUM_FILES" ; then
     msg "${PROGNAME}: none of the specified files are results for $TOOL"
     exit 1
@@ -222,7 +222,7 @@ else
   for VAR in $VARS
-    grep "Running target $VAR" $SUM_FILES > /dev/null && VARIANTS="$VARIANTS $VAR"
+    grep "Running target $VAR" $SUM_FILES --text > /dev/null && VARIANTS="$VARIANTS $VAR"

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]