From: Nicholas Nethercote Date: Mon, 3 Aug 2009 01:38:56 +0000 (+0000) Subject: With the recent VG_(message) change, X-Git-Tag: svn/VALGRIND_3_5_0~156 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=5dfe01a847e33bf1cfdb55c17ce8450a6320a276;p=thirdparty%2Fvalgrind.git 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 --- diff --git a/NEWS b/NEWS index 71aed4e9b1..4fcc62e70f 100644 --- 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 diff --git a/coregrind/m_replacemalloc/vg_replace_malloc.c b/coregrind/m_replacemalloc/vg_replace_malloc.c index 579ee50e20..89a38db0a3 100644 --- a/coregrind/m_replacemalloc/vg_replace_malloc.c +++ b/coregrind/m_replacemalloc/vg_replace_malloc.c @@ -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; \ } diff --git a/docs/xml/manual-core-adv.xml b/docs/xml/manual-core-adv.xml index 0210196890..017304fd95 100644 --- a/docs/xml/manual-core-adv.xml +++ b/docs/xml/manual-core-adv.xml @@ -215,18 +215,21 @@ tool-specific macros). VALGRIND_PRINTF(format, ...): 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. + Valgrind, prefixed with the PID between a pair of + ** 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. VALGRIND_PRINTF_BACKTRACE(format, ...): - 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. + Like VALGRIND_PRINTF, but prints + a stack backtrace immediately afterwards. diff --git a/include/valgrind.h b/include/valgrind.h index bdb037c2de..7c034c0463 100644 --- a/include/valgrind.h +++ b/include/valgrind.h @@ -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 "**** " part at the + start and the backtrace (if present). */ #if defined(NVALGRIND) diff --git a/memcheck/mc_replace_strmem.c b/memcheck/mc_replace_strmem.c index 6c5e31bc87..c15717adbc 100644 --- a/memcheck/mc_replace_strmem.c +++ b/memcheck/mc_replace_strmem.c @@ -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; \ diff --git a/none/tests/Makefile.am b/none/tests/Makefile.am index 92b1caaf19..f7c989fd21 100644 --- a/none/tests/Makefile.am +++ b/none/tests/Makefile.am @@ -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 \ diff --git a/none/tests/vgprintf.c b/none/tests/vgprintf.c index 10ebcb426b..aee3116451 100644 --- a/none/tests/vgprintf.c +++ b/none/tests/vgprintf.c @@ -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; } diff --git a/none/tests/vgprintf.stderr.exp b/none/tests/vgprintf.stderr.exp index f79bb06a4a..a6dc8ff540 100644 --- a/none/tests/vgprintf.stderr.exp +++ b/none/tests/vgprintf.stderr.exp @@ -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 index eb1ae458f8..0000000000 --- a/none/tests/vgprintf.stdout.exp +++ /dev/null @@ -1 +0,0 @@ -... diff --git a/none/tests/vgprintf.vgtest b/none/tests/vgprintf.vgtest index a8bb288f2a..4a6d5e1d94 100644 --- a/none/tests/vgprintf.vgtest +++ b/none/tests/vgprintf.vgtest @@ -1,2 +1 @@ prog: vgprintf -stdout_filter: ../../tests/filter_numbers diff --git a/tests/filter_stderr_basic b/tests/filter_stderr_basic index 3958bc812d..7586958713 100755 --- a/tests/filter_stderr_basic +++ b/tests/filter_stderr_basic @@ -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)/" |