From: Bart Van Assche Date: Mon, 14 Apr 2008 16:35:32 +0000 (+0000) Subject: Extended VG_(message)() buffer from 100 to 128 characters. Made sure that lines print... X-Git-Tag: svn/VALGRIND_3_4_0~732 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=366ad62a4669627db3a525858e7e15350748ec22;p=thirdparty%2Fvalgrind.git Extended VG_(message)() buffer from 100 to 128 characters. Made sure that lines printed by different threads are not mixed up in the output. git-svn-id: svn://svn.valgrind.org/valgrind/trunk@7875 --- diff --git a/coregrind/m_libcprint.c b/coregrind/m_libcprint.c index 340f6d49dc..bd331e4bd6 100644 --- a/coregrind/m_libcprint.c +++ b/coregrind/m_libcprint.c @@ -76,23 +76,28 @@ static void send_bytes_to_logging_sink ( Char* msg, Int nbytes ) typedef struct { - HChar buf[100]; + HChar buf[128]; Int n; } printf_buf; +static UInt VG_(vprintf_to_buf) ( printf_buf *printf_buf, + const HChar *format, va_list vargs ); +static UInt VG_(printf_to_buf) ( printf_buf* prbuf, const HChar *format, ... ); + // Adds a single char to the buffer. When the buffer gets sufficiently // full, we write its contents to the logging sink. static void add_to_myprintf_buf ( HChar c, void *p ) { printf_buf *myprintf_buf = (printf_buf *)p; - if (myprintf_buf->n >= 100-10 /*paranoia*/ ) { + if (myprintf_buf->n > sizeof(myprintf_buf->buf) - 2 ) { send_bytes_to_logging_sink( myprintf_buf->buf, myprintf_buf->n ); myprintf_buf->n = 0; } myprintf_buf->buf[myprintf_buf->n++] = c; myprintf_buf->buf[myprintf_buf->n] = 0; + tl_assert(myprintf_buf->n < sizeof(myprintf_buf->buf)); } UInt VG_(vprintf) ( const HChar *format, va_list vargs ) @@ -100,14 +105,22 @@ UInt VG_(vprintf) ( const HChar *format, va_list vargs ) UInt ret = 0; printf_buf myprintf_buf = {"",0}; + ret = VG_(vprintf_to_buf)(&myprintf_buf, format, vargs); + // Write out any chars left in the buffer. + if (myprintf_buf.n > 0) { + send_bytes_to_logging_sink( myprintf_buf.buf, myprintf_buf.n ); + } + return ret; +} + +static UInt VG_(vprintf_to_buf) ( printf_buf *prbuf, + const HChar *format, va_list vargs ) +{ + UInt ret = 0; + if (VG_(clo_log_fd) >= 0) { ret = VG_(debugLog_vprintf) - ( add_to_myprintf_buf, &myprintf_buf, format, vargs ); - - // Write out any chars left in the buffer. - if (myprintf_buf.n > 0) { - send_bytes_to_logging_sink( myprintf_buf.buf, myprintf_buf.n ); - } + ( add_to_myprintf_buf, prbuf, format, vargs ); } return ret; } @@ -124,6 +137,18 @@ UInt VG_(printf) ( const HChar *format, ... ) return ret; } +static UInt VG_(printf_to_buf) ( printf_buf* prbuf, const HChar *format, ... ) +{ + UInt ret; + va_list vargs; + + va_start(vargs, format); + ret = VG_(vprintf_to_buf)(prbuf, format, vargs); + va_end(vargs); + + return ret; +} + /* A general replacement for sprintf(). */ static void add_to_vg_sprintf_buf ( HChar c, void *p ) { @@ -301,6 +326,7 @@ UInt VG_(vmessage) ( VgMsgKind kind, const HChar* format, va_list vargs ) UInt count = 0; Char c; Int i, depth; + printf_buf myprintf_buf = {"",0}; switch (kind) { case Vg_UserMsg: c = '='; break; @@ -314,23 +340,28 @@ UInt VG_(vmessage) ( VgMsgKind kind, const HChar* format, va_list vargs ) // being performed. depth = RUNNING_ON_VALGRIND; for (i = 0; i < depth; i++) { - count += VG_(printf) (">"); + count += VG_(printf_to_buf) (&myprintf_buf, ">"); } if (!VG_(clo_xml)) - count += VG_(printf) ("%c%c", c,c); + count += VG_(printf_to_buf) (&myprintf_buf, "%c%c", c,c); if (VG_(clo_time_stamp)) { HChar buf[50]; VG_(elapsed_wallclock_time)(buf); - count += VG_(printf)( "%s ", buf); + count += VG_(printf_to_buf)(&myprintf_buf, "%s ", buf); } if (!VG_(clo_xml)) - count += VG_(printf) ("%d%c%c ", VG_(getpid)(), c,c); + count += VG_(printf_to_buf) (&myprintf_buf, "%d%c%c ", VG_(getpid)(), c,c); + + count += VG_(vprintf_to_buf)(&myprintf_buf, format, vargs); + count += VG_(printf_to_buf) (&myprintf_buf, "\n"); + + if (myprintf_buf.n > 0) { + send_bytes_to_logging_sink( myprintf_buf.buf, myprintf_buf.n ); + } - count += VG_(vprintf)(format, vargs); - count += VG_(printf) ("\n"); return count; }