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.


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@10694
This commit is contained in:
Nicholas Nethercote 2009-08-03 01:38:56 +00:00
parent 1bce42d94e
commit 5dfe01a847
11 changed files with 64 additions and 36 deletions

10
NEWS
View File

@ -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

View 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; \
}

View 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>

View 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)

View 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; \

View 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 \

View 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;
}

View 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

View File

@ -1 +0,0 @@
...

View File

@ -1,2 +1 @@
prog: vgprintf
stdout_filter: ../../tests/filter_numbers

View File

@ -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)/" |