]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Print the command being run at startup. It wraps to avoid going over 80
authorNicholas Nethercote <njn@valgrind.org>
Wed, 29 Jul 2009 23:34:49 +0000 (23:34 +0000)
committerNicholas Nethercote <njn@valgrind.org>
Wed, 29 Jul 2009 23:34:49 +0000 (23:34 +0000)
chars wide whenever possible.  Finishes off bug 197933.

git-svn-id: svn://svn.valgrind.org/valgrind/trunk@10657

NEWS
coregrind/m_main.c
docs/xml/manual-writing-tools.xml
none/tests/Makefile.am
none/tests/filter_long_command [new file with mode: 0755]
none/tests/filter_timestamp
none/tests/long-command.stderr.exp [new file with mode: 0644]
none/tests/long-command.vgtest [new file with mode: 0644]
tests/filter_stderr_basic

diff --git a/NEWS b/NEWS
index 98e7e90ee20975d2d6ec5cab29470c233c8d2782..7e544021dc0139a83fac4b166792c0a60f5468e3 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -31,6 +31,16 @@ Release 3.5.0 (???)
 
 * XXX: exp-bbv has been added...
 
+* Valgrind's start-up message has changed.  It is shorter but also includes
+  the command being run, which makes it easier to use --trace-children=yes.
+  An example:
+
+==3050== Memcheck, a memory error detector.
+==3050== Copyright (C) 2002-2009, and GNU GPL'd, by Julian Seward et al.
+==3050== Using Valgrind-3.5.0.SVN and LibVEX; rerun with -h for copyright info
+==3050== Command: ls -l
+==3050== 
+
 * A new Memcheck client request VALGRIND_COUNT_LEAK_BLOCKS has been added.
   It is similar to VALGRIND_COUNT_LEAKS but counts blocks instead of bytes.
   [XXX: consider adding VALGRIND_COUNT_LEAK_BYTES as a synonym and
index b5c8f50ef575035b6660c7d1793e2023575b4919..a32d2f29b85635cc8995adee18d35db844854b98 100644 (file)
@@ -967,6 +967,7 @@ static void print_preamble ( Bool logging_to_fd,
                              const HChar* toolname )
 {
    Int    i;
+   SizeT  n;
    HChar* xpre  = VG_(clo_xml) ? "  <line>" : "";
    HChar* xpost = VG_(clo_xml) ? "</line>" : "";
    UInt (*umsg_or_xml)( const HChar*, ... )
@@ -1017,6 +1018,35 @@ static void print_preamble ( Bool logging_to_fd,
          xpre, VERSION, xpost
       );
 
+      /* Print the command line, wrapping near 80-chars wide.  An example of a
+         command line with many args, some of them very long:
+        
+==9717== Command: date 11 23 4a \
+==9717==          aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa \
+==9717==          aaa 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 \
+==9717==          22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 \
+==9717==          fffffffffffffffffffffffffffff 1 2 3 \
+==9717==          bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
+      */
+      VG_(umsg)("Command: ");
+      if (VG_(args_the_exename))
+         VG_(umsg)("%s", VG_(args_the_exename));
+      n = 0;
+      for (i = 0; i < VG_(sizeXA)( VG_(args_for_client) ); i++) {
+         HChar* s = *(HChar**)VG_(indexXA)( VG_(args_for_client), i );
+         SizeT slen = VG_(strlen)(s);
+         n += slen + 1;   // +1 for the space char between each argument
+         // With a PID of up to 5 digits, 58 puts the line-ending '\' in
+         // column 79 at the most, always leaving column 80 empty.
+         if (n > 58) {
+            VG_(umsg)(" \\");
+            VG_(umsg)("\n        ");
+            n = slen;
+         }
+         VG_(umsg)(" %s", s);
+      }
+      VG_(umsg)("\n");
+
       if (VG_(clo_xml))
          VG_(printf_xml)("</preamble>\n");
    }
@@ -1091,15 +1121,7 @@ static void print_preamble ( Bool logging_to_fd,
       VexArchInfo vex_archinfo;
       if (!logging_to_fd)
          VG_(message)(Vg_DebugMsg, "\n");
-      VG_(message)(Vg_DebugMsg, "Command line\n");
-      if (VG_(args_the_exename))
-         VG_(message)(Vg_DebugMsg, "   %s\n", VG_(args_the_exename));
-      for (i = 0; i < VG_(sizeXA)( VG_(args_for_client) ); i++)
-         VG_(message)(Vg_DebugMsg, 
-                     "   %s\n", 
-                     * (HChar**) VG_(indexXA)( VG_(args_for_client), i ));
-
-      VG_(message)(Vg_DebugMsg, "Startup, with flags:\n");
+      VG_(message)(Vg_DebugMsg, "Valgrind flags:\n");
       for (i = 0; i < VG_(sizeXA)( VG_(args_for_valgrind) ); i++) {
          VG_(message)(Vg_DebugMsg, 
                      "   %s\n", 
@@ -1113,10 +1135,10 @@ static void print_preamble ( Bool logging_to_fd,
       } else {
 #        define BUF_LEN    256
          Char version_buf[BUF_LEN];
-         Int n = VG_(read) ( sr_Res(fd), version_buf, BUF_LEN );
-         vg_assert(n <= BUF_LEN);
-         if (n > 0) {
-            version_buf[n-1] = '\0';
+         Int nn = VG_(read) ( sr_Res(fd), version_buf, BUF_LEN );
+         vg_assert(nn <= BUF_LEN);
+         if (nn > 0) {
+            version_buf[nn-1] = '\0';
             VG_(message)(Vg_DebugMsg, "  %s\n", version_buf);
          } else {
             VG_(message)(Vg_DebugMsg, "  (empty?)\n");
index 3dca7a064b1aa3d67a6aa6271e4a4865d8162ab8..002e77b75d3e97edc828df80f7c7764cc9ad29fc 100644 (file)
@@ -153,13 +153,10 @@ top-level directory <computeroutput>valgrind/</computeroutput>.</para>
    <computeroutput>date</computeroutput> is just an example).
    The output should be something like this:</para>
 <programlisting><![CDATA[
-  ==738== foobar-0.0.1, a foobarring tool for x86-linux.
-  ==738== Copyright (C) 2002-2007, and GNU GPL'd, by Julian Seward et al.
-  ==738== Using LibVEX rev 1791, a library for dynamic binary translation.
-  ==738== Copyright (C) 2004-2007, and GNU GPL'd, by OpenWorks LLP.
-  ==738== Using valgrind-3.3.0, a dynamic binary instrumentation framework.
-  ==738== Copyright (C) 2000-2007, and GNU GPL'd, by Julian Seward et al.
-  ==738== For more details, rerun with: -v
+  ==738== foobar-0.0.1, a foobarring tool.
+  ==738== Copyright (C) 2002-2009, and GNU GPL'd, by J. Programmer.
+  ==738== Using Valgrind-3.5.0.SVN and LibVEX; rerun with -h for copyright info
+  ==738== Command: date
   ==738==
   Tue Nov 27 12:40:49 EST 2007
   ==738==]]></programlisting>
index 8257d4dd820a02340873347fbd5c47a973bb6171..cb85e3c32a7b843d218947218e91e79d1b0fa6ae 100644 (file)
@@ -34,8 +34,9 @@ DIST_SUBDIRS = x86 amd64 ppc32 ppc64 linux darwin x86-linux .
 
 dist_noinst_SCRIPTS = \
        filter_cmdline0 \
-       filter_linenos \
        filter_fdleak \
+       filter_linenos \
+       filter_long_command \
        filter_none_discards \
        filter_stderr \
        filter_timestamp
@@ -79,6 +80,7 @@ EXTRA_DIST = \
        fork.stderr.exp fork.stdout.exp fork.vgtest \
        fucomip.stderr.exp fucomip.vgtest \
        gxx304.stderr.exp gxx304.vgtest \
+       long-command.stderr.exp long-command.vgtest \
        manythreads.stdout.exp manythreads.stderr.exp manythreads.vgtest \
        map_unaligned.stderr.exp map_unaligned.vgtest \
        map_unmap.stderr.exp map_unmap.stdout.exp map_unmap.vgtest \
diff --git a/none/tests/filter_long_command b/none/tests/filter_long_command
new file mode 100755 (executable)
index 0000000..3e96849
--- /dev/null
@@ -0,0 +1,9 @@
+#! /bin/sh
+
+dir=`dirname $0`
+
+# We change the "Command:" so it doesn't get stripped out by the standard
+# filters.
+sed "s/Command:/COMMAND:/" |
+
+./filter_stderr
index f8fe944fdb9ebe11cfb5907ac994061ef8239321..d524aef16387f26426590bf4f047a6f22b3f8876 100755 (executable)
@@ -11,6 +11,7 @@ perl -p -e "s/ [0-9]{1,7}==//" |
 sed "/ Nulgrind.*$/ d" |
 sed "/ Copyright.*$/ d" |
 sed "/ Using Valgrind.*$/ d" |
+sed "/ Command:.*$/ d" |
 
 $dir/filter_stderr |
 
diff --git a/none/tests/long-command.stderr.exp b/none/tests/long-command.stderr.exp
new file mode 100644 (file)
index 0000000..53c32e9
--- /dev/null
@@ -0,0 +1,10 @@
+COMMAND: ./../../tests/true 11 23 4a \
+         aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa \
+         aaa 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 \
+         22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 \
+         fffffffffffffffffffffffffffff 1 2 3 \
+         bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb 1 2 3 4 1 \
+         2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 \
+         xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
+
+
diff --git a/none/tests/long-command.vgtest b/none/tests/long-command.vgtest
new file mode 100644 (file)
index 0000000..acce130
--- /dev/null
@@ -0,0 +1,2 @@
+prog: ../../tests/true 11 23 4a aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaa 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 fffffffffffffffffffffffffffff 1 2 3 bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
+stderr_filter: filter_long_command
index dfa50ecd45c4370e502939754a5a504629292d7c..3958bc812d5270528de94385ba2206cc7ccfa412 100755 (executable)
@@ -15,6 +15,10 @@ perl -p -e 's/(==|--|\+\+|\*\*)[0-9]{1,7}\1 //' |
 # Remove any --pid:0: strings (debuglog level zero output)
 sed "/^--[0-9]\{1,7\}:0:*/d" |
 
+# Remove "Command: line".  (If wrapping occurs, it won't remove the
+# subsequent lines...)
+sed "/^Command: .*$/d" |
+
 # Remove "WARNING: assuming toc 0x.." strings
 sed "/^WARNING: assuming toc 0x*/d" |