From: Nicholas Nethercote Date: Wed, 29 Jul 2009 23:34:49 +0000 (+0000) Subject: Print the command being run at startup. It wraps to avoid going over 80 X-Git-Tag: svn/VALGRIND_3_5_0~193 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=a3fe17b34b7148269df398b0f31495f2f30847d1;p=thirdparty%2Fvalgrind.git Print the command being run at startup. It wraps to avoid going over 80 chars wide whenever possible. Finishes off bug 197933. git-svn-id: svn://svn.valgrind.org/valgrind/trunk@10657 --- diff --git a/NEWS b/NEWS index 98e7e90ee2..7e544021dc 100644 --- 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 diff --git a/coregrind/m_main.c b/coregrind/m_main.c index b5c8f50ef5..a32d2f29b8 100644 --- a/coregrind/m_main.c +++ b/coregrind/m_main.c @@ -967,6 +967,7 @@ static void print_preamble ( Bool logging_to_fd, const HChar* toolname ) { Int i; + SizeT n; HChar* xpre = VG_(clo_xml) ? " " : ""; HChar* xpost = VG_(clo_xml) ? "" : ""; 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)("\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"); diff --git a/docs/xml/manual-writing-tools.xml b/docs/xml/manual-writing-tools.xml index 3dca7a064b..002e77b75d 100644 --- a/docs/xml/manual-writing-tools.xml +++ b/docs/xml/manual-writing-tools.xml @@ -153,13 +153,10 @@ top-level directory valgrind/. date is just an example). The output should be something like this: diff --git a/none/tests/Makefile.am b/none/tests/Makefile.am index 8257d4dd82..cb85e3c32a 100644 --- a/none/tests/Makefile.am +++ b/none/tests/Makefile.am @@ -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 index 0000000000..3e9684904c --- /dev/null +++ b/none/tests/filter_long_command @@ -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 diff --git a/none/tests/filter_timestamp b/none/tests/filter_timestamp index f8fe944fdb..d524aef163 100755 --- a/none/tests/filter_timestamp +++ b/none/tests/filter_timestamp @@ -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 index 0000000000..53c32e98fd --- /dev/null +++ b/none/tests/long-command.stderr.exp @@ -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 index 0000000000..acce130c0a --- /dev/null +++ b/none/tests/long-command.vgtest @@ -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 diff --git a/tests/filter_stderr_basic b/tests/filter_stderr_basic index dfa50ecd45..3958bc812d 100755 --- a/tests/filter_stderr_basic +++ b/tests/filter_stderr_basic @@ -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" |