|
From: Bart V. A. <bar...@gm...> - 2008-04-13 17:31:28
|
Most messages in Valgrind are printed by calling VG_(message)().
Unfortunately, when this function is called from more than one thread,
the lines printed can get mixed up. The patch below makes sure that
all text printed by a single call to VG_(message) is printed on a
single line and that it is not mixed up with output from VG_(message)
calls from other threads. Additionally the following is changed:
- Number of buffered characters in printf_buf is increased from 100 to 128.
- Removed "paranoia".
Please review the patch below.
Bart.
Index: coregrind/m_libcprint.c
===================================================================
--- coregrind/m_libcprint.c (revision 7864)
+++ coregrind/m_libcprint.c (working copy)
@@ -76,18 +76,22 @@
typedef
struct {
- HChar buf[100];
+ HChar buf[128];
Int n;
}
printf_buf;
+static UInt VG_(vprintf_w_buf) ( printf_buf *printf_buf,
+ const HChar *format, va_list vargs );
+static UInt VG_(printf_w_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) - 1 ) {
send_bytes_to_logging_sink( myprintf_buf->buf, myprintf_buf->n );
myprintf_buf->n = 0;
}
@@ -100,14 +104,22 @@
UInt ret = 0;
printf_buf myprintf_buf = {"",0};
+ ret = VG_(vprintf_w_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_w_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 +136,18 @@
return ret;
}
+static UInt VG_(printf_w_buf) ( printf_buf* prbuf, const HChar *format, ... )
+{
+ UInt ret;
+ va_list vargs;
+
+ va_start(vargs, format);
+ ret = VG_(vprintf_w_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 +325,7 @@
UInt count = 0;
Char c;
Int i, depth;
+ printf_buf myprintf_buf = {"",0};
switch (kind) {
case Vg_UserMsg: c = '='; break;
@@ -314,23 +339,28 @@
// being performed.
depth = RUNNING_ON_VALGRIND;
for (i = 0; i < depth; i++) {
- count += VG_(printf) (">");
+ count += VG_(printf_w_buf) (&myprintf_buf, ">");
}
if (!VG_(clo_xml))
- count += VG_(printf) ("%c%c", c,c);
+ count += VG_(printf_w_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_w_buf)(&myprintf_buf, "%s ", buf);
}
if (!VG_(clo_xml))
- count += VG_(printf) ("%d%c%c ", VG_(getpid)(), c,c);
+ count += VG_(printf_w_buf) (&myprintf_buf, "%d%c%c ",
VG_(getpid)(), c,c);
- count += VG_(vprintf)(format, vargs);
- count += VG_(printf) ("\n");
+ count += VG_(vprintf_w_buf)(&myprintf_buf, format, vargs);
+ count += VG_(printf_w_buf) (&myprintf_buf, "\n");
+
+ if (myprintf_buf.n > 0) {
+ send_bytes_to_logging_sink( myprintf_buf.buf, myprintf_buf.n );
+ }
+
return count;
}
|