]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
With the recent VG_(message) change,
authorNicholas Nethercote <njn@valgrind.org>
Mon, 3 Aug 2009 01:38:56 +0000 (01:38 +0000)
committerNicholas Nethercote <njn@valgrind.org>
Mon, 3 Aug 2009 01:38:56 +0000 (01:38 +0000)
VALGRIND_{PRINTF,PRINTF_BACKTRACE,INTERNAL_PRINTF} were no longer appending
newlines.  This meant that --trace-malloc=yes spewed everything onto a
single line, among other things.

Rather than adding the newline back in, I chose to offically change their
behaviour to not add the newlines, as this is more flexible (and the reason
for the underlying VG_(message) change).  I updated all the relevant places
I could find.

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

NEWS
coregrind/m_replacemalloc/vg_replace_malloc.c
docs/xml/manual-core-adv.xml
include/valgrind.h
memcheck/mc_replace_strmem.c
none/tests/Makefile.am
none/tests/vgprintf.c
none/tests/vgprintf.stderr.exp
none/tests/vgprintf.stdout.exp [deleted file]
none/tests/vgprintf.vgtest
tests/filter_stderr_basic

diff --git a/NEWS b/NEWS
index 71aed4e9b1f9526b39238300b5eee946a7815c1c..4fcc62e70fca40fe410efc22ac61b764d69353eb 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -46,6 +46,16 @@ Release 3.5.0 (???)
   [XXX: consider adding VALGRIND_COUNT_LEAK_BYTES as a synonym and
   deprecating VALGRIND_COUNT_LEAKS, which wasn't a good name to begin with]
 
+* The Valgrind client requests VALGRIND_PRINTF and VALGRIND_PRINTF_BACKTRACE
+  have been changed slightly.  Previously, the string was always printed
+  immediately on its own line.  Now, the string will be added to a buffer
+  but not printed until a newline is encountered, or other Valgrind output
+  is printed (note that for VALGRIND_PRINTF_BACKTRACE, the back-trace itself
+  is considered "other Valgrind output").  This allows you to use multiple
+  VALGRIND_PRINTF calls to build up a single output line, and also to print
+  multiple output lines with a single request (by embedding multiple
+  newlines in the string).
+
 * Memcheck's leak checker has been improved.  
   - The results for --leak-check=summary now match the summary results for
     --leak-check=full.  Previously they could differ because
index 579ee50e2046e94b6e8cfe0e20dc31001c0ba1f0..89a38db0a307a13564d1300297a97eebf7ac2e15 100644 (file)
@@ -141,7 +141,7 @@ static void init(void);
       MALLOC_TRACE(#fnname "(%llu)", (ULong)n ); \
       \
       v = (void*)VALGRIND_NON_SIMD_CALL1( info.tl_##vg_replacement, n ); \
-      MALLOC_TRACE(" = %p", v ); \
+      MALLOC_TRACE(" = %p\n", v ); \
       return v; \
    }
 
@@ -156,7 +156,7 @@ static void init(void);
       MALLOC_TRACE(#fnname "(%p, %llu)", zone, (ULong)n ); \
       \
       v = (void*)VALGRIND_NON_SIMD_CALL1( info.tl_##vg_replacement, n ); \
-      MALLOC_TRACE(" = %p", v ); \
+      MALLOC_TRACE(" = %p\n", v ); \
       return v; \
    }
 
@@ -176,11 +176,12 @@ static void init(void);
       MALLOC_TRACE(#fnname "(%llu)", (ULong)n );        \
       \
       v = (void*)VALGRIND_NON_SIMD_CALL1( info.tl_##vg_replacement, n ); \
-      MALLOC_TRACE(" = %p", v ); \
+      MALLOC_TRACE(" = %p\n", v ); \
       if (NULL == v) { \
          VALGRIND_PRINTF_BACKTRACE( \
-            "new/new[] failed and should throw an exception, but Valgrind\n" \
-            "   cannot throw exceptions and so is aborting instead.  Sorry."); \
+            "new/new[] failed and should throw an exception, but Valgrind\n"); \
+         VALGRIND_PRINTF_BACKTRACE( \
+            "   cannot throw exceptions and so is aborting instead.  Sorry.\n"); \
             _exit(1); \
       } \
       return v; \
@@ -301,7 +302,7 @@ ALLOC_or_BOMB(VG_Z_LIBC_SONAME,       __builtin_vec_new, __builtin_vec_new );
    void VG_REPLACE_FUNCTION_ZU(soname,fnname) (void *zone, void *p)  \
    { \
       if (!init_done) init(); \
-      MALLOC_TRACE(#vg_replacement "(%p, %p)", zone, p ); \
+      MALLOC_TRACE(#vg_replacement "(%p, %p)\n", zone, p ); \
       if (p == NULL)  \
          return; \
       (void)VALGRIND_NON_SIMD_CALL1( info.tl_##vg_replacement, p ); \
@@ -313,7 +314,7 @@ ALLOC_or_BOMB(VG_Z_LIBC_SONAME,       __builtin_vec_new, __builtin_vec_new );
    void VG_REPLACE_FUNCTION_ZU(soname,fnname) (void *p)  \
    { \
       if (!init_done) init(); \
-      MALLOC_TRACE(#vg_replacement "(%p)", p ); \
+      MALLOC_TRACE(#vg_replacement "(%p)\n", p ); \
       if (p == NULL)  \
          return; \
       (void)VALGRIND_NON_SIMD_CALL1( info.tl_##vg_replacement, p ); \
@@ -393,7 +394,7 @@ FREE(VG_Z_LIBC_SONAME,       _ZdaPvRKSt9nothrow_t, __builtin_vec_delete );
       MALLOC_TRACE("calloc(%p, %llu,%llu)", zone, (ULong)nmemb, (ULong)size ); \
       \
       v = (void*)VALGRIND_NON_SIMD_CALL2( info.tl_calloc, nmemb, size ); \
-      MALLOC_TRACE(" = %p", v ); \
+      MALLOC_TRACE(" = %p\n", v ); \
       return v; \
    }
 
@@ -410,7 +411,7 @@ FREE(VG_Z_LIBC_SONAME,       _ZdaPvRKSt9nothrow_t, __builtin_vec_delete );
       /* Protect against overflow.  See bug 24078. */ \
       if (size && nmemb > (SizeT)-1 / size) return NULL; \
       v = (void*)VALGRIND_NON_SIMD_CALL2( info.tl_calloc, nmemb, size ); \
-      MALLOC_TRACE(" = %p", v ); \
+      MALLOC_TRACE(" = %p\n", v ); \
       return v; \
    }
 
@@ -440,11 +441,11 @@ ZONECALLOC(VG_Z_LIBC_SONAME, malloc_zone_calloc);
          return VG_REPLACE_FUNCTION_ZU(VG_Z_LIBC_SONAME,malloc) (new_size); \
       if (new_size <= 0) { \
          VG_REPLACE_FUNCTION_ZU(VG_Z_LIBC_SONAME,free)(ptrV); \
-         MALLOC_TRACE(" = 0"); \
+         MALLOC_TRACE(" = 0\n"); \
          return NULL; \
       } \
       v = (void*)VALGRIND_NON_SIMD_CALL2( info.tl_realloc, ptrV, new_size ); \
-      MALLOC_TRACE(" = %p", v ); \
+      MALLOC_TRACE(" = %p\n", v ); \
       return v; \
    }
 
@@ -464,11 +465,11 @@ ZONECALLOC(VG_Z_LIBC_SONAME, malloc_zone_calloc);
          return VG_REPLACE_FUNCTION_ZU(VG_Z_LIBC_SONAME,malloc) (new_size); \
       if (new_size <= 0) { \
          VG_REPLACE_FUNCTION_ZU(VG_Z_LIBC_SONAME,free)(ptrV); \
-         MALLOC_TRACE(" = 0"); \
+         MALLOC_TRACE(" = 0\n"); \
          return NULL; \
       } \
       v = (void*)VALGRIND_NON_SIMD_CALL2( info.tl_realloc, ptrV, new_size ); \
-      MALLOC_TRACE(" = %p", v ); \
+      MALLOC_TRACE(" = %p\n", v ); \
       return v; \
    }
 
@@ -501,7 +502,7 @@ ZONEREALLOC(VG_Z_LIBC_SONAME, malloc_zone_realloc);
       while (0 != (alignment & (alignment - 1))) alignment++; \
       \
       v = (void*)VALGRIND_NON_SIMD_CALL2( info.tl_memalign, alignment, n ); \
-      MALLOC_TRACE(" = %p", v ); \
+      MALLOC_TRACE(" = %p\n", v ); \
       return v; \
    }
 
@@ -524,7 +525,7 @@ ZONEREALLOC(VG_Z_LIBC_SONAME, malloc_zone_realloc);
       while (0 != (alignment & (alignment - 1))) alignment++; \
       \
       v = (void*)VALGRIND_NON_SIMD_CALL2( info.tl_memalign, alignment, n ); \
-      MALLOC_TRACE(" = %p", v ); \
+      MALLOC_TRACE(" = %p\n", v ); \
       return v; \
    }
 
@@ -680,7 +681,7 @@ POSIX_MEMALIGN(VG_Z_LIBC_SONAME, memalign_common);
          return 0; \
       \
       pszB = (SizeT)VALGRIND_NON_SIMD_CALL1( info.tl_malloc_usable_size, p ); \
-      MALLOC_TRACE(" = %llu", (ULong)pszB ); \
+      MALLOC_TRACE(" = %llu\n", (ULong)pszB ); \
       \
       return pszB; \
    }
@@ -695,7 +696,7 @@ MALLOC_USABLE_SIZE(VG_Z_LIBC_SONAME, malloc_size);
 
 static void panic(const char *str)
 {
-   VALGRIND_PRINTF_BACKTRACE("Program aborting because of call to %s", str);
+   VALGRIND_PRINTF_BACKTRACE("Program aborting because of call to %s\n", str);
    _exit(99);
    *(int *)0 = 'x';
 }
@@ -735,7 +736,7 @@ MALLOC_STATS(VG_Z_LIBC_SONAME, malloc_stats);
    { \
       static struct vg_mallinfo mi; \
       if (!init_done) init(); \
-      MALLOC_TRACE("mallinfo()"); \
+      MALLOC_TRACE("mallinfo()\n"); \
       (void)VALGRIND_NON_SIMD_CALL1( info.mallinfo, &mi ); \
       return mi; \
    }
index 0210196890816d3f4883c8b0d3ffd0f9acf0068b..017304fd95071bd4cc79eeb60bae57b56537a204 100644 (file)
@@ -215,18 +215,21 @@ tool-specific macros).</para>
    <term><command><computeroutput>VALGRIND_PRINTF(format, ...)</computeroutput>:</command></term>
    <listitem>
     <para>printf a message to the log file when running under
-    Valgrind.  Nothing is output if not running under Valgrind.
-    Returns the number of characters output.</para>
+    Valgrind, prefixed with the PID between a pair of
+    <computeroutput>**</computeroutput> markers.  Nothing is output if not
+    running under Valgrind.  Output is not produced until a newline is
+    encountered, or subequent Valgrind output is printed;  this allows you
+    to build up a single line of output over multiple calls.
+    Returns the number of characters output, excluding the PID at the
+    start.</para>
    </listitem>
   </varlistentry>
 
   <varlistentry>
    <term><command><computeroutput>VALGRIND_PRINTF_BACKTRACE(format, ...)</computeroutput>:</command></term>
    <listitem>
-    <para>printf a message to the log file along with a stack
-    backtrace when running under Valgrind.  Nothing is output if
-    not running under Valgrind.  Returns the number of characters
-    output.</para>
+    <para>Like <computeroutput>VALGRIND_PRINTF<computeroutput>, but prints
+    a stack backtrace immediately afterwards.</para>
    </listitem>
   </varlistentry>
 
index bdb037c2de064ae21230e1cc6eab587b3a4430c9..7c034c0463e80bb81ec419d204a9891b9d923071 100644 (file)
@@ -3681,7 +3681,9 @@ typedef
 
 
 /* These requests are for getting Valgrind itself to print something.
-   Possibly with a backtrace.  This is a really ugly hack. */
+   Possibly with a backtrace.  This is a really ugly hack.  The return value
+   is the number of characters printed, excluding the "**<pid>** " part at the
+   start and the backtrace (if present). */
 
 #if defined(NVALGRIND)
 
index 6c5e31bc87f6ae4bbe2aaae4f9a09f9380a091e4..c15717adbceb2cb0282a6db0dc8c2edf6ac6d3d5 100644 (file)
@@ -669,7 +669,7 @@ BCOPY(VG_Z_DYLD,        bcopy)
      badness: \
       VALGRIND_PRINTF_BACKTRACE( \
          "*** memmove_chk: buffer overflow detected ***: " \
-         "program terminated"); \
+         "program terminated\n"); \
      _exit(127); \
      /*NOTREACHED*/ \
      return NULL; \
@@ -730,7 +730,7 @@ GLIBC232_RAWMEMCHR(VG_Z_LIBC_SONAME, rawmemchr)
      badness: \
       VALGRIND_PRINTF_BACKTRACE( \
          "*** strcpy_chk: buffer overflow detected ***: " \
-         "program terminated"); \
+         "program terminated\n"); \
      _exit(127); \
      /*NOTREACHED*/ \
      return NULL; \
@@ -757,7 +757,7 @@ GLIBC25___STRCPY_CHK(VG_Z_LIBC_SONAME, __strcpy_chk)
      badness: \
       VALGRIND_PRINTF_BACKTRACE( \
          "*** stpcpy_chk: buffer overflow detected ***: " \
-         "program terminated"); \
+         "program terminated\n"); \
      _exit(127); \
      /*NOTREACHED*/ \
      return NULL; \
@@ -840,7 +840,7 @@ GLIBC25_MEMPCPY(VG_Z_LD_SO_1,     mempcpy) /* ld.so.1 */
      badness: \
       VALGRIND_PRINTF_BACKTRACE( \
          "*** memcpy_chk: buffer overflow detected ***: " \
-         "program terminated"); \
+         "program terminated\n"); \
      _exit(127); \
      /*NOTREACHED*/ \
      return NULL; \
index 92b1caaf199eddeea3cbe68cd72e597b11866010..f7c989fd21bd4d9dea24628cf71b04224c71be08 100644 (file)
@@ -140,7 +140,7 @@ EXTRA_DIST = \
        threadederrno.vgtest \
        timestamp.stderr.exp timestamp.vgtest \
        tls.vgtest tls.stderr.exp tls.stdout.exp  \
-       vgprintf.stderr.exp vgprintf.stdout.exp vgprintf.vgtest
+       vgprintf.stderr.exp vgprintf.vgtest
 
 check_PROGRAMS = \
        ansi args \
index 10ebcb426b614b2b5b76cf9318d118b8617f9681..aee3116451a50c55c12c85e28f0007e802dedcd9 100644 (file)
@@ -4,7 +4,12 @@
 int
 main (int argc, char **argv)
 {
-   int x = VALGRIND_PRINTF("Yo\n");
-   printf ("%d\n", x);
+   int x = 0;
+   x += VALGRIND_PRINTF("Yo ");
+   x += VALGRIND_PRINTF("Yo ");
+   x += VALGRIND_PRINTF("Ma\n");
+   fprintf(stderr, "%d\n", x);
+   x  = VALGRIND_PRINTF_BACKTRACE("Backtrace line one\nLine two:\n");
+   fprintf(stderr, "%d\n", x);
    return 0;
 }
index f79bb06a4a3c73b1bf7e80f3d66c5feeae99fa88..a6dc8ff540384b81fc420a636791c416fb544868 100644 (file)
@@ -1,3 +1,9 @@
 
-Yo
+Yo Yo Ma
+9
+Backtrace line one
+Line two:
+   at 0x........: VALGRIND_PRINTF_BACKTRACE (valgrind.h:...)
+   by 0x........: main (vgprintf.c:12)
+29
 
diff --git a/none/tests/vgprintf.stdout.exp b/none/tests/vgprintf.stdout.exp
deleted file mode 100644 (file)
index eb1ae45..0000000
+++ /dev/null
@@ -1 +0,0 @@
-...
index a8bb288f2ac69690b603d164dc3d6e2a885769fb..4a6d5e1d94405417361e560c572a0a7daf1a6b46 100644 (file)
@@ -1,2 +1 @@
 prog: vgprintf
-stdout_filter: ../../tests/filter_numbers
index 3958bc812d5270528de94385ba2206cc7ccfa412..758695871328ad397bdad73021b3cc21d09b42fe 100755 (executable)
@@ -27,7 +27,10 @@ sed "/^WARNING: assuming toc 0x*/d" |
 sed "/^Using Valgrind-.* and LibVEX; rerun with -h for copyright info/ d" |
 
 # Anonymise line numbers in vg_replace_malloc.c, remove dirname if present
-perl -p -e "s/(m_replacemalloc\/)?vg_replace_malloc.c:[0-9]*/vg_replace_malloc.c:.../" |
+perl -p -e "s/(m_replacemalloc\/)?vg_replace_malloc.c:\d+\)/vg_replace_malloc.c:...\)/" |
+
+# Likewise for valgrind.h
+perl -p -e "s/valgrind\.h:\d+\)/valgrind\.h:...\)/" |
 
 # Hide suppressed error counts
 sed "s/^\(ERROR SUMMARY[^(]*(suppressed: \)[0-9]*\( from \)[0-9]*)$/\10\20)/" |