|
From: <sv...@va...> - 2009-08-03 01:45:27
|
Author: njn
Date: 2009-08-03 02:38:56 +0100 (Mon, 03 Aug 2009)
New Revision: 10694
Log:
With the recent VG_(message) change,
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.
Removed:
trunk/none/tests/vgprintf.stdout.exp
Modified:
trunk/NEWS
trunk/coregrind/m_replacemalloc/vg_replace_malloc.c
trunk/docs/xml/manual-core-adv.xml
trunk/include/valgrind.h
trunk/memcheck/mc_replace_strmem.c
trunk/none/tests/Makefile.am
trunk/none/tests/vgprintf.c
trunk/none/tests/vgprintf.stderr.exp
trunk/none/tests/vgprintf.vgtest
trunk/tests/filter_stderr_basic
Modified: trunk/NEWS
===================================================================
--- trunk/NEWS 2009-08-03 01:05:18 UTC (rev 10693)
+++ trunk/NEWS 2009-08-03 01:38:56 UTC (rev 10694)
@@ -46,6 +46,16 @@
[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
Modified: trunk/coregrind/m_replacemalloc/vg_replace_malloc.c
===================================================================
--- trunk/coregrind/m_replacemalloc/vg_replace_malloc.c 2009-08-03 01:05:18 UTC (rev 10693)
+++ trunk/coregrind/m_replacemalloc/vg_replace_malloc.c 2009-08-03 01:38:56 UTC (rev 10694)
@@ -141,7 +141,7 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
/* 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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
{ \
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; \
}
Modified: trunk/docs/xml/manual-core-adv.xml
===================================================================
--- trunk/docs/xml/manual-core-adv.xml 2009-08-03 01:05:18 UTC (rev 10693)
+++ trunk/docs/xml/manual-core-adv.xml 2009-08-03 01:38:56 UTC (rev 10694)
@@ -215,18 +215,21 @@
<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>
Modified: trunk/include/valgrind.h
===================================================================
--- trunk/include/valgrind.h 2009-08-03 01:05:18 UTC (rev 10693)
+++ trunk/include/valgrind.h 2009-08-03 01:38:56 UTC (rev 10694)
@@ -3681,7 +3681,9 @@
/* 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)
Modified: trunk/memcheck/mc_replace_strmem.c
===================================================================
--- trunk/memcheck/mc_replace_strmem.c 2009-08-03 01:05:18 UTC (rev 10693)
+++ trunk/memcheck/mc_replace_strmem.c 2009-08-03 01:38:56 UTC (rev 10694)
@@ -669,7 +669,7 @@
badness: \
VALGRIND_PRINTF_BACKTRACE( \
"*** memmove_chk: buffer overflow detected ***: " \
- "program terminated"); \
+ "program terminated\n"); \
_exit(127); \
/*NOTREACHED*/ \
return NULL; \
@@ -730,7 +730,7 @@
badness: \
VALGRIND_PRINTF_BACKTRACE( \
"*** strcpy_chk: buffer overflow detected ***: " \
- "program terminated"); \
+ "program terminated\n"); \
_exit(127); \
/*NOTREACHED*/ \
return NULL; \
@@ -757,7 +757,7 @@
badness: \
VALGRIND_PRINTF_BACKTRACE( \
"*** stpcpy_chk: buffer overflow detected ***: " \
- "program terminated"); \
+ "program terminated\n"); \
_exit(127); \
/*NOTREACHED*/ \
return NULL; \
@@ -840,7 +840,7 @@
badness: \
VALGRIND_PRINTF_BACKTRACE( \
"*** memcpy_chk: buffer overflow detected ***: " \
- "program terminated"); \
+ "program terminated\n"); \
_exit(127); \
/*NOTREACHED*/ \
return NULL; \
Modified: trunk/none/tests/Makefile.am
===================================================================
--- trunk/none/tests/Makefile.am 2009-08-03 01:05:18 UTC (rev 10693)
+++ trunk/none/tests/Makefile.am 2009-08-03 01:38:56 UTC (rev 10694)
@@ -140,7 +140,7 @@
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 \
Modified: trunk/none/tests/vgprintf.c
===================================================================
--- trunk/none/tests/vgprintf.c 2009-08-03 01:05:18 UTC (rev 10693)
+++ trunk/none/tests/vgprintf.c 2009-08-03 01:38:56 UTC (rev 10694)
@@ -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;
}
Modified: trunk/none/tests/vgprintf.stderr.exp
===================================================================
--- trunk/none/tests/vgprintf.stderr.exp 2009-08-03 01:05:18 UTC (rev 10693)
+++ trunk/none/tests/vgprintf.stderr.exp 2009-08-03 01:38:56 UTC (rev 10694)
@@ -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
Deleted: trunk/none/tests/vgprintf.stdout.exp
===================================================================
--- trunk/none/tests/vgprintf.stdout.exp 2009-08-03 01:05:18 UTC (rev 10693)
+++ trunk/none/tests/vgprintf.stdout.exp 2009-08-03 01:38:56 UTC (rev 10694)
@@ -1 +0,0 @@
-...
Modified: trunk/none/tests/vgprintf.vgtest
===================================================================
--- trunk/none/tests/vgprintf.vgtest 2009-08-03 01:05:18 UTC (rev 10693)
+++ trunk/none/tests/vgprintf.vgtest 2009-08-03 01:38:56 UTC (rev 10694)
@@ -1,2 +1 @@
prog: vgprintf
-stdout_filter: ../../tests/filter_numbers
Modified: trunk/tests/filter_stderr_basic
===================================================================
--- trunk/tests/filter_stderr_basic 2009-08-03 01:05:18 UTC (rev 10693)
+++ trunk/tests/filter_stderr_basic 2009-08-03 01:38:56 UTC (rev 10694)
@@ -27,8 +27,11 @@
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)/" |
|