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 )
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;
}
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 )
{
UInt count = 0;
Char c;
Int i, depth;
+ printf_buf myprintf_buf = {"",0};
switch (kind) {
case Vg_UserMsg: c = '='; break;
// 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;
}