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 a5019735-40e9-0310-863c-91ae7b9d1cf9
diff --git a/coregrind/m_libcprint.c b/coregrind/m_libcprint.c
index 340f6d4..bd331e4 100644
--- a/coregrind/m_libcprint.c
+++ b/coregrind/m_libcprint.c
@@ -76,23 +76,28 @@
 
 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 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 @@
    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 count = 0;
    Char c;
    Int  i, depth;
+   printf_buf myprintf_buf = {"",0};
 
    switch (kind) {
       case Vg_UserMsg:       c = '='; break;
@@ -314,23 +340,28 @@
    // 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)(format, vargs);
-   count += VG_(printf) ("\n");
+   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 );
+   }
+
    return count;
 }