Modularise printing functions in m_libcprint.


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@3840 a5019735-40e9-0310-863c-91ae7b9d1cf9
diff --git a/cachegrind/amd64/cg_arch.c b/cachegrind/amd64/cg_arch.c
index 9d6ba01..8d14da3 100644
--- a/cachegrind/amd64/cg_arch.c
+++ b/cachegrind/amd64/cg_arch.c
@@ -31,6 +31,7 @@
 #include "tool.h"
 #include "cg_arch.h"
 #include "pub_tool_libcbase.h"
+#include "pub_tool_libcprint.h"
 
 // All CPUID info taken from sandpile.org/a32/cpuid.htm */
 // Probably only works for Intel and AMD chips, and probably only for some of
diff --git a/cachegrind/arm/cg_arch.c b/cachegrind/arm/cg_arch.c
index f775224..9800069 100644
--- a/cachegrind/arm/cg_arch.c
+++ b/cachegrind/arm/cg_arch.c
@@ -30,7 +30,6 @@
 
 #include "tool.h"
 #include "cg_arch.h"
-#include "pub_tool_libcbase.h"
 
 void VGA_(configure_caches)(cache_t* I1c, cache_t* D1c, cache_t* L2c,
                             Bool all_caches_clo_defined)
diff --git a/cachegrind/cg_main.c b/cachegrind/cg_main.c
index c313b7a..1c13db3 100644
--- a/cachegrind/cg_main.c
+++ b/cachegrind/cg_main.c
@@ -33,6 +33,7 @@
 #include "pub_tool_debuginfo.h"
 #include "pub_tool_hashtable.h"
 #include "pub_tool_libcbase.h"
+#include "pub_tool_libcprint.h"
 #include "pub_tool_mallocfree.h"
 #include "pub_tool_options.h"
 #include "pub_tool_profile.h"
diff --git a/cachegrind/x86/cg_arch.c b/cachegrind/x86/cg_arch.c
index f737836..36ab3a6 100644
--- a/cachegrind/x86/cg_arch.c
+++ b/cachegrind/x86/cg_arch.c
@@ -30,6 +30,7 @@
 
 #include "tool.h"
 #include "pub_tool_libcbase.h"
+#include "pub_tool_libcprint.h"
 #include "cg_arch.h"
 
 // All CPUID info taken from sandpile.org/a32/cpuid.htm */
diff --git a/coregrind/Makefile.am b/coregrind/Makefile.am
index 723436c1..d5c2ef9 100644
--- a/coregrind/Makefile.am
+++ b/coregrind/Makefile.am
@@ -47,6 +47,7 @@
 	pub_core_execontext.h	\
 	pub_core_hashtable.h	\
 	pub_core_libcbase.h	\
+	pub_core_libcprint.h	\
 	pub_core_main.h		\
 	pub_core_mallocfree.h	\
 	pub_core_options.h	\
@@ -89,6 +90,7 @@
 	m_execontext.c \
 	m_hashtable.c \
 	m_libcbase.c \
+	m_libcprint.c \
 	m_main.c \
 	m_mallocfree.c \
 	m_options.c \
@@ -102,7 +104,6 @@
 	m_transtab.c \
 	\
 	ume.c \
-	vg_messages.c \
 	vg_mylibc.c \
 	vg_threadmodel.c \
 	vg_pthreadmodel.c
diff --git a/coregrind/core.h b/coregrind/core.h
index 58e08f7..25c8ee4 100644
--- a/coregrind/core.h
+++ b/coregrind/core.h
@@ -128,10 +128,6 @@
 extern void VG_(unimplemented) ( Char* msg )
             __attribute__((__noreturn__));
 
-/* Tell the logging mechanism whether we are logging to a file
-   descriptor or a socket descriptor. */
-extern Bool VG_(logging_to_socket);
-
 /* Tools use VG_(strdup)() which doesn't expose ArenaId */
 extern Char* VG_(arena_strdup) ( ArenaId aid, const Char* s);
 
diff --git a/coregrind/linux/core_os.c b/coregrind/linux/core_os.c
index 1c65a29..77ed861 100644
--- a/coregrind/linux/core_os.c
+++ b/coregrind/linux/core_os.c
@@ -30,6 +30,7 @@
 
 #include "core.h"
 #include "pub_core_debuglog.h"
+#include "pub_core_libcprint.h"
 #include "pub_core_options.h"
 #include "pub_core_signals.h"
 #include "pub_core_tooliface.h"
diff --git a/coregrind/m_aspacemgr/aspacemgr.c b/coregrind/m_aspacemgr/aspacemgr.c
index 5f4fce1..ded33e6 100644
--- a/coregrind/m_aspacemgr/aspacemgr.c
+++ b/coregrind/m_aspacemgr/aspacemgr.c
@@ -33,6 +33,7 @@
 #include "core.h"
 #include "pub_core_aspacemgr.h"
 #include "pub_core_libcbase.h"
+#include "pub_core_libcprint.h"
 #include "pub_core_options.h"
 #include "pub_core_syscalls.h"
 #include "pub_core_tooliface.h"
diff --git a/coregrind/m_aspacemgr/read_procselfmaps.c b/coregrind/m_aspacemgr/read_procselfmaps.c
index f1699c1..7e20cc1 100644
--- a/coregrind/m_aspacemgr/read_procselfmaps.c
+++ b/coregrind/m_aspacemgr/read_procselfmaps.c
@@ -33,6 +33,7 @@
 #include "core.h"
 #include "pub_core_aspacemgr.h"
 #include "pub_core_libcbase.h"
+#include "pub_core_libcprint.h"
 
 /* Size of a smallish table used to read /proc/self/map entries. */
 #define M_PROCMAP_BUF 50000
diff --git a/coregrind/m_debuginfo/dwarf.c b/coregrind/m_debuginfo/dwarf.c
index a4c7004..2cde637 100644
--- a/coregrind/m_debuginfo/dwarf.c
+++ b/coregrind/m_debuginfo/dwarf.c
@@ -30,6 +30,7 @@
 
 #include "core.h"
 #include "pub_core_libcbase.h"
+#include "pub_core_libcprint.h"
 #include "pub_core_options.h"
 #include "priv_symtab.h"
 
diff --git a/coregrind/m_debuginfo/stabs.c b/coregrind/m_debuginfo/stabs.c
index 1ba467f..aa117a3 100644
--- a/coregrind/m_debuginfo/stabs.c
+++ b/coregrind/m_debuginfo/stabs.c
@@ -30,6 +30,7 @@
 
 #include "core.h"
 #include "pub_core_libcbase.h"
+#include "pub_core_libcprint.h"
 #include "priv_symtab.h"
 
 #include <a.out.h>        /* stabs defns                    */
diff --git a/coregrind/m_debuginfo/symtab.c b/coregrind/m_debuginfo/symtab.c
index a259560..94d2b32 100644
--- a/coregrind/m_debuginfo/symtab.c
+++ b/coregrind/m_debuginfo/symtab.c
@@ -33,6 +33,7 @@
 #include "pub_core_aspacemgr.h"
 #include "pub_core_demangle.h"
 #include "pub_core_libcbase.h"
+#include "pub_core_libcprint.h"
 #include "pub_core_options.h"
 #include "pub_core_profile.h"
 #include "pub_core_redir.h"
diff --git a/coregrind/m_debuginfo/symtypes.c b/coregrind/m_debuginfo/symtypes.c
index 8c32d9e..4eae1ed 100644
--- a/coregrind/m_debuginfo/symtypes.c
+++ b/coregrind/m_debuginfo/symtypes.c
@@ -32,6 +32,7 @@
 #include "pub_core_debuginfo.h"
 #include "pub_core_debuglog.h"    /* VG_(debugLog_vprintf) */
 #include "pub_core_libcbase.h"
+#include "pub_core_libcprint.h"
 #include "pub_core_tooliface.h"
 #include "priv_symtypes.h"
 
diff --git a/coregrind/m_demangle/cplus-dem.c b/coregrind/m_demangle/cplus-dem.c
index fe059c7..e854c04 100644
--- a/coregrind/m_demangle/cplus-dem.c
+++ b/coregrind/m_demangle/cplus-dem.c
@@ -39,6 +39,7 @@
 #include "safe-ctype.h"
 #include "core.h"
 #include "pub_core_libcbase.h"
+#include "pub_tool_libcprint.h"
 
 /*#include <sys/types.h>
 #include <string.h>
diff --git a/coregrind/m_errormgr.c b/coregrind/m_errormgr.c
index 34a3219..fe36d22 100644
--- a/coregrind/m_errormgr.c
+++ b/coregrind/m_errormgr.c
@@ -33,6 +33,7 @@
 #include "pub_core_errormgr.h"
 #include "pub_core_execontext.h"
 #include "pub_core_libcbase.h"
+#include "pub_core_libcprint.h"
 #include "pub_core_main.h"          // for VG_(start_debugger)()
 #include "pub_core_options.h"
 #include "pub_core_stacktrace.h"
diff --git a/coregrind/m_execontext.c b/coregrind/m_execontext.c
index d8a47af..f53f151 100644
--- a/coregrind/m_execontext.c
+++ b/coregrind/m_execontext.c
@@ -30,6 +30,7 @@
 
 #include "core.h"
 #include "pub_core_execontext.h"
+#include "pub_core_libcprint.h"
 #include "pub_core_options.h"
 #include "pub_core_profile.h"
 
diff --git a/coregrind/m_libcbase.c b/coregrind/m_libcbase.c
index 33608ef..1ab10d3 100644
--- a/coregrind/m_libcbase.c
+++ b/coregrind/m_libcbase.c
@@ -28,7 +28,7 @@
    The GNU General Public License is contained in the file COPYING.
 */
 
-#include "tool.h"       // XXX: temporary, for NULL, VG_(), Char, etc
+#include "core.h"       // XXX: temporary, for NULL, VG_(), Char, etc
 #include "pub_core_libcbase.h"
 
 /* ---------------------------------------------------------------------
diff --git a/coregrind/m_main.c b/coregrind/m_main.c
index 713667c..d64272b 100644
--- a/coregrind/m_main.c
+++ b/coregrind/m_main.c
@@ -37,6 +37,7 @@
 #include "pub_core_errormgr.h"
 #include "pub_core_execontext.h"
 #include "pub_core_libcbase.h"
+#include "pub_core_libcprint.h"
 #include "pub_core_main.h"
 #include "pub_core_options.h"
 #include "pub_core_profile.h"
diff --git a/coregrind/m_mallocfree.c b/coregrind/m_mallocfree.c
index b6b58a7..3c09ef9 100644
--- a/coregrind/m_mallocfree.c
+++ b/coregrind/m_mallocfree.c
@@ -33,6 +33,7 @@
 #include "core.h"
 #include "pub_core_aspacemgr.h"
 #include "pub_core_libcbase.h"
+#include "pub_core_libcprint.h"
 #include "pub_core_options.h"
 #include "pub_core_profile.h"
 #include "valgrind.h"
diff --git a/coregrind/m_profile.c b/coregrind/m_profile.c
index 630fa9d..2f72aa3 100644
--- a/coregrind/m_profile.c
+++ b/coregrind/m_profile.c
@@ -29,6 +29,7 @@
 */
 
 #include "core.h"
+#include "pub_core_libcprint.h"
 #include "pub_core_profile.h"
 
 /* get rid of these, if possible */
diff --git a/coregrind/m_redir.c b/coregrind/m_redir.c
index b00645b..81afc96 100644
--- a/coregrind/m_redir.c
+++ b/coregrind/m_redir.c
@@ -33,6 +33,7 @@
 
 #include "pub_core_aspacemgr.h"
 #include "pub_core_libcbase.h"
+#include "pub_core_libcprint.h"
 #include "pub_core_skiplist.h"
 #include "pub_core_options.h"
 #include "pub_core_redir.h"
diff --git a/coregrind/m_replacemalloc/replacemalloc_core.c b/coregrind/m_replacemalloc/replacemalloc_core.c
index 8b99757..25ef0cf 100644
--- a/coregrind/m_replacemalloc/replacemalloc_core.c
+++ b/coregrind/m_replacemalloc/replacemalloc_core.c
@@ -30,6 +30,7 @@
 
 #include "core.h"
 #include "pub_core_libcbase.h"
+#include "pub_core_libcprint.h"
 #include "pub_core_options.h"
 #include "pub_core_replacemalloc.h"
 
diff --git a/coregrind/m_scheduler/scheduler.c b/coregrind/m_scheduler/scheduler.c
index 11c402c..5455ce7 100644
--- a/coregrind/m_scheduler/scheduler.c
+++ b/coregrind/m_scheduler/scheduler.c
@@ -64,6 +64,7 @@
 #include "pub_core_dispatch.h"
 #include "pub_core_errormgr.h"
 #include "pub_core_libcbase.h"
+#include "pub_core_libcprint.h"
 #include "pub_core_main.h"
 #include "pub_core_options.h"
 #include "pub_core_profile.h"
diff --git a/coregrind/m_sigframe/sigframe-amd64-linux.c b/coregrind/m_sigframe/sigframe-amd64-linux.c
index b9e2d6a..33593bc 100644
--- a/coregrind/m_sigframe/sigframe-amd64-linux.c
+++ b/coregrind/m_sigframe/sigframe-amd64-linux.c
@@ -32,6 +32,7 @@
 #include "core.h"
 #include "pub_core_aspacemgr.h"
 #include "pub_core_libcbase.h"
+#include "pub_core_libcprint.h"
 #include "pub_core_options.h"
 #include "pub_core_sigframe.h"
 #include "pub_core_signals.h"
diff --git a/coregrind/m_sigframe/sigframe-x86-linux.c b/coregrind/m_sigframe/sigframe-x86-linux.c
index 36aa5f1..f760586 100644
--- a/coregrind/m_sigframe/sigframe-x86-linux.c
+++ b/coregrind/m_sigframe/sigframe-x86-linux.c
@@ -32,6 +32,7 @@
 #include "core.h"
 #include "pub_core_aspacemgr.h" /* find_segment */
 #include "pub_core_libcbase.h"
+#include "pub_core_libcprint.h"
 #include "pub_core_options.h"
 #include "pub_core_sigframe.h"
 #include "pub_core_signals.h"
diff --git a/coregrind/m_signals.c b/coregrind/m_signals.c
index d7dcc7f..36d5736 100644
--- a/coregrind/m_signals.c
+++ b/coregrind/m_signals.c
@@ -84,6 +84,7 @@
 #include "pub_core_aspacemgr.h"
 #include "pub_core_errormgr.h"
 #include "pub_core_libcbase.h"
+#include "pub_core_libcprint.h"
 #include "pub_core_main.h"
 #include "pub_core_options.h"
 #include "pub_core_signals.h"
diff --git a/coregrind/m_skiplist.c b/coregrind/m_skiplist.c
index 1de8d2d..17ee897 100644
--- a/coregrind/m_skiplist.c
+++ b/coregrind/m_skiplist.c
@@ -88,6 +88,7 @@
 
 #include "core.h"
 #include "pub_core_libcbase.h"
+#include "pub_core_libcprint.h"
 #include "pub_core_skiplist.h"
 
 #include <stdlib.h>
diff --git a/coregrind/m_stacktrace.c b/coregrind/m_stacktrace.c
index 2b87d76..d9845cd 100644
--- a/coregrind/m_stacktrace.c
+++ b/coregrind/m_stacktrace.c
@@ -31,6 +31,7 @@
 #include "core.h"
 #include "pub_core_aspacemgr.h"
 #include "pub_core_libcbase.h"
+#include "pub_core_libcprint.h"
 #include "pub_core_options.h"
 #include "pub_core_profile.h"
 #include "pub_core_stacktrace.h"
diff --git a/coregrind/m_syscalls/syscalls-amd64-linux.c b/coregrind/m_syscalls/syscalls-amd64-linux.c
index fdece82..e96bb2e 100644
--- a/coregrind/m_syscalls/syscalls-amd64-linux.c
+++ b/coregrind/m_syscalls/syscalls-amd64-linux.c
@@ -32,6 +32,7 @@
 #include "ume.h"                /* for jmp_with_stack */
 #include "pub_core_debuglog.h"
 #include "pub_core_aspacemgr.h"
+#include "pub_core_libcprint.h"
 #include "pub_core_sigframe.h"
 #include "pub_core_syscalls.h"
 #include "pub_core_tooliface.h"
diff --git a/coregrind/m_syscalls/syscalls-linux.c b/coregrind/m_syscalls/syscalls-linux.c
index 6895c43..165a97f 100644
--- a/coregrind/m_syscalls/syscalls-linux.c
+++ b/coregrind/m_syscalls/syscalls-linux.c
@@ -30,6 +30,7 @@
 
 #include "core.h"
 #include "pub_core_aspacemgr.h"
+#include "pub_core_libcprint.h"
 #include "pub_core_tooliface.h"
 #include "priv_syscalls.h"
 
diff --git a/coregrind/m_syscalls/syscalls-x86-linux.c b/coregrind/m_syscalls/syscalls-x86-linux.c
index d7cdd57..e4cd267 100644
--- a/coregrind/m_syscalls/syscalls-x86-linux.c
+++ b/coregrind/m_syscalls/syscalls-x86-linux.c
@@ -37,6 +37,7 @@
 #include "ume.h"                /* for jmp_with_stack */
 #include "pub_core_debuglog.h"
 #include "pub_core_aspacemgr.h"
+#include "pub_core_libcprint.h"
 #include "pub_core_sigframe.h"
 #include "pub_core_syscalls.h"
 #include "pub_core_tooliface.h"
diff --git a/coregrind/m_syscalls/syscalls.c b/coregrind/m_syscalls/syscalls.c
index 05805e4..dfc9ff6 100644
--- a/coregrind/m_syscalls/syscalls.c
+++ b/coregrind/m_syscalls/syscalls.c
@@ -32,6 +32,7 @@
 #include "pub_core_debuglog.h"
 #include "pub_core_aspacemgr.h"
 #include "pub_core_libcbase.h"
+#include "pub_core_libcprint.h"
 #include "pub_core_main.h"
 #include "pub_core_profile.h"
 #include "pub_core_stacktrace.h"
diff --git a/coregrind/m_tooliface.c b/coregrind/m_tooliface.c
index 9c343fd..b9916af 100644
--- a/coregrind/m_tooliface.c
+++ b/coregrind/m_tooliface.c
@@ -31,6 +31,7 @@
 
 #include "core.h"
 #include "pub_core_tooliface.h"
+#include "pub_core_libcprint.h"
 
 // The core/tool dictionary of functions (initially zeroed, as we want it)
 VgToolInterface VG_(tdict);
diff --git a/coregrind/m_translate.c b/coregrind/m_translate.c
index eb4d940..9da8aae 100644
--- a/coregrind/m_translate.c
+++ b/coregrind/m_translate.c
@@ -32,6 +32,7 @@
 #include "core.h"
 #include "pub_core_aspacemgr.h"
 #include "pub_core_libcbase.h"
+#include "pub_core_libcprint.h"
 #include "pub_core_main.h"       // for VG_(bbs_done)
 #include "pub_core_options.h"
 #include "pub_core_profile.h"
diff --git a/coregrind/m_transtab.c b/coregrind/m_transtab.c
index 50182e3..8cc1699 100644
--- a/coregrind/m_transtab.c
+++ b/coregrind/m_transtab.c
@@ -32,6 +32,7 @@
 #include "core.h"
 #include "pub_core_debuginfo.h"
 #include "pub_core_libcbase.h"
+#include "pub_core_libcprint.h"
 #include "pub_core_options.h"
 #include "pub_core_tooliface.h"
 // XXX: this module should not depend on m_translate!
diff --git a/coregrind/pub_core_libcprint.h b/coregrind/pub_core_libcprint.h
new file mode 100644
index 0000000..303a430
--- /dev/null
+++ b/coregrind/pub_core_libcprint.h
@@ -0,0 +1,49 @@
+
+/*--------------------------------------------------------------------*/
+/*--- Printing libc stuff.                    pub_core_libcprint.h ---*/
+/*--------------------------------------------------------------------*/
+
+/*
+   This file is part of Valgrind, a dynamic binary instrumentation
+   framework.
+
+   Copyright (C) 2000-2005 Julian Seward
+      jseward@acm.org
+
+   This program is free software; you can redistribute it and/or
+   modify it under the terms of the GNU General Public License as
+   published by the Free Software Foundation; either version 2 of the
+   License, or (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful, but
+   WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307, USA.
+
+   The GNU General Public License is contained in the file COPYING.
+*/
+
+#ifndef __PUB_CORE_LIBCPRINT_H
+#define __PUB_CORE_LIBCPRINT_H
+
+//--------------------------------------------------------------------
+// PURPOSE: This module contains all the libc code that is related to
+// higher-level (ie. higher than DebugLog) printing, eg. VG_(printf)().
+//--------------------------------------------------------------------
+
+#include "pub_tool_libcprint.h"
+
+/* Tell the logging mechanism whether we are logging to a file
+   descriptor or a socket descriptor. */
+extern Bool VG_(logging_to_socket);
+
+#endif   // __PUB_CORE_LIBCPRINT_H
+
+/*--------------------------------------------------------------------*/
+/*--- end                                                          ---*/
+/*--------------------------------------------------------------------*/
diff --git a/coregrind/vg_messages.c b/coregrind/vg_messages.c
deleted file mode 100644
index fe4004c..0000000
--- a/coregrind/vg_messages.c
+++ /dev/null
@@ -1,101 +0,0 @@
-
-/*--------------------------------------------------------------------*/
-/*--- For sending error/informative messages.                      ---*/
-/*---                                                vg_messages.c ---*/
-/*--------------------------------------------------------------------*/
-
-/*
-   This file is part of Valgrind, a dynamic binary instrumentation
-   framework.
-
-   Copyright (C) 2000-2005 Julian Seward 
-      jseward@acm.org
-
-   This program is free software; you can redistribute it and/or
-   modify it under the terms of the GNU General Public License as
-   published by the Free Software Foundation; either version 2 of the
-   License, or (at your option) any later version.
-
-   This program is distributed in the hope that it will be useful, but
-   WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   General Public License for more details.
-
-   You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software
-   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
-   02111-1307, USA.
-
-   The GNU General Public License is contained in the file COPYING.
-*/
-
-#include "core.h"
-#include "valgrind.h"
-
-#include "pub_core_options.h"
-
-#include <time.h>
-#include <sys/time.h>
-
-UInt VG_(vmessage) ( VgMsgKind kind, const HChar* format, va_list vargs )
-{
-   UInt  count = 0;
-   Char  c;
-   const Char* pfx_s;
-   static const Char pfx[] = ">>>>>>>>>>>>>>>>";
-
-   switch (kind) {
-      case Vg_UserMsg:       c = '='; break;
-      case Vg_DebugMsg:      c = '-'; break;
-      case Vg_DebugExtraMsg: c = '+'; break;
-      case Vg_ClientMsg:     c = '*'; break;
-      default:               c = '?'; break;
-   }
-
-   // The pfx trick prints one or more '>' characters in front of the
-   // messages when running Valgrind under Valgrind, one per level of
-   // self-hosting.
-   pfx_s = &pfx[sizeof(pfx)-1-RUNNING_ON_VALGRIND],
-
-   // Print the message
-   count = 0;
-
-   if (!VG_(clo_xml))
-      count += VG_(printf) ("%s%c%c", pfx_s, c,c);
-
-   if (VG_(clo_time_stamp)) {
-      struct timeval tv;
-      struct tm tm;
-     
-      if ( gettimeofday( &tv, NULL ) == 0 &&
-           localtime_r( &tv.tv_sec, &tm ) == &tm )
-      {
-         count +=
-            VG_(printf)( "%04d-%02d-%02d %02d:%02d:%02d.%03d ",
-                         tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
-                         tm.tm_hour, tm.tm_min, tm.tm_sec, tv.tv_usec / 1000 );
-      }
-   }
-
-   if (!VG_(clo_xml))
-      count += VG_(printf) ("%d%c%c ", VG_(getpid)(), c,c);
-
-   count += VG_(vprintf)(format, vargs);
-   count += VG_(printf) ("\n");
-   return count;
-}
-
-/* Send a simple single-part message. */
-UInt VG_(message) ( VgMsgKind kind, const HChar* format, ... )
-{
-   UInt count;
-   va_list vargs;
-   va_start(vargs,format);
-   count = VG_(vmessage) ( kind, format, vargs );
-   va_end(vargs);
-   return count;
-}
-
-/*--------------------------------------------------------------------*/
-/*--- end                                                          ---*/
-/*--------------------------------------------------------------------*/
diff --git a/coregrind/vg_mylibc.c b/coregrind/vg_mylibc.c
index 989bcd3..9486dac 100644
--- a/coregrind/vg_mylibc.c
+++ b/coregrind/vg_mylibc.c
@@ -34,6 +34,7 @@
 #include "pub_core_aspacemgr.h"
 #include "pub_core_debuglog.h"    /* VG_(debugLog_vprintf) */
 #include "pub_core_libcbase.h"
+#include "pub_core_libcprint.h"
 #include "pub_core_main.h"
 #include "pub_core_options.h"
 #include "pub_core_stacktrace.h"
@@ -408,107 +409,6 @@
 }
 
 
-/* Tell the logging mechanism whether we are logging to a file
-   descriptor or a socket descriptor. */
-Bool VG_(logging_to_socket) = False;
-
-/* Do the low-level send of a message to the logging sink. */
-static void send_bytes_to_logging_sink ( Char* msg, Int nbytes )
-{
-   if (!VG_(logging_to_socket)) {
-      VG_(write)( VG_(clo_log_fd), msg, nbytes );
-   } else {
-      Int rc = VG_(write_socket)( VG_(clo_log_fd), msg, nbytes );
-      if (rc == -1) {
-         // For example, the listener process died.  Switch back to stderr.
-         VG_(logging_to_socket) = False;
-         VG_(clo_log_fd) = 2;
-         VG_(write)( VG_(clo_log_fd), msg, nbytes );
-      }
-   }
-}
-
-typedef struct {
-   char buf[100];
-   int n;
-} printf_buf;
-
-// 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*/ ) {
-      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;
-}
-
-UInt VG_(vprintf) ( const HChar *format, va_list vargs )
-{
-   UInt ret = 0;
-   printf_buf myprintf_buf = {"",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 );
-      }
-   }
-   return ret;
-}
-
-UInt VG_(printf) ( const HChar *format, ... )
-{
-   UInt ret;
-   va_list vargs;
-
-   va_start(vargs, format);
-   ret = VG_(vprintf)(format, vargs);
-   va_end(vargs);
-
-   return ret;
-}
-
-/* A general replacement for sprintf(). */
-static void add_to_vg_sprintf_buf ( HChar c, void *p )
-{
-   char **vg_sprintf_ptr = p;
-   *(*vg_sprintf_ptr)++ = c;
-}
-
-UInt VG_(vsprintf) ( Char* buf, const HChar *format, va_list vargs )
-{
-   Int ret;
-   Char *vg_sprintf_ptr = buf;
-
-   ret = VG_(debugLog_vprintf) 
-            ( add_to_vg_sprintf_buf, &vg_sprintf_ptr, format, vargs );
-   add_to_vg_sprintf_buf('\0', &vg_sprintf_ptr);
-
-   vg_assert(VG_(strlen)(buf) == ret);
-
-   return ret;
-}
-
-UInt VG_(sprintf) ( Char* buf, const HChar *format, ... )
-{
-   UInt ret;
-   va_list vargs;
-
-   va_start(vargs,format);
-   ret = VG_(vsprintf)(buf, format, vargs);
-   va_end(vargs);
-
-   return ret;
-}
-
 /* ---------------------------------------------------------------------
    strdup()
    ------------------------------------------------------------------ */
diff --git a/helgrind/hg_main.c b/helgrind/hg_main.c
index 91d9be0..d23fe7a 100644
--- a/helgrind/hg_main.c
+++ b/helgrind/hg_main.c
@@ -33,6 +33,7 @@
 #include "pub_tool_debuginfo.h"
 #include "pub_tool_hashtable.h"
 #include "pub_tool_libcbase.h"
+#include "pub_tool_libcprint.h"
 #include "pub_tool_mallocfree.h"
 #include "pub_tool_options.h"
 #include "pub_tool_profile.h"
diff --git a/include/Makefile.am b/include/Makefile.am
index 6242687..aac2292 100644
--- a/include/Makefile.am
+++ b/include/Makefile.am
@@ -9,6 +9,7 @@
 	pub_tool_execontext.h 		\
 	pub_tool_hashtable.h 		\
 	pub_tool_libcbase.h 		\
+	pub_tool_libcprint.h 		\
 	pub_tool_mallocfree.h 		\
 	pub_tool_options.h 		\
 	pub_tool_profile.h		\
diff --git a/include/pub_tool_libcprint.h b/include/pub_tool_libcprint.h
new file mode 100644
index 0000000..8e44d23
--- /dev/null
+++ b/include/pub_tool_libcprint.h
@@ -0,0 +1,71 @@
+
+/*--------------------------------------------------------------------*/
+/*--- Printing libc stuff.                    pub_tool_libcprint.h ---*/
+/*--------------------------------------------------------------------*/
+
+/*
+   This file is part of Valgrind, a dynamic binary instrumentation
+   framework.
+
+   Copyright (C) 2000-2005 Julian Seward
+      jseward@acm.org
+
+   This program is free software; you can redistribute it and/or
+   modify it under the terms of the GNU General Public License as
+   published by the Free Software Foundation; either version 2 of the
+   License, or (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful, but
+   WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307, USA.
+
+   The GNU General Public License is contained in the file COPYING.
+*/
+
+#ifndef __PUB_TOOL_LIBCPRINT_H
+#define __PUB_TOOL_LIBCPRINT_H
+
+/* ---------------------------------------------------------------------
+   Basic printing
+   ------------------------------------------------------------------ */
+
+/* Note that they all output to the file descriptor given by the
+ * --log-fd/--log-file/--log-socket argument, which defaults to 2 (stderr).
+ * Hence no need for VG_(fprintf)().
+ */
+extern UInt VG_(printf)  ( const HChar *format, ... );
+extern UInt VG_(vprintf) ( const HChar *format, va_list vargs );
+/* too noisy ...  __attribute__ ((format (printf, 1, 2))) ; */
+extern UInt VG_(sprintf) ( Char* buf, const HChar* format, ... );
+extern UInt VG_(vsprintf)( Char* buf, const HChar* format, va_list vargs );
+
+/* ---------------------------------------------------------------------
+   Messages for the user
+   ------------------------------------------------------------------ */
+
+/* Print a message prefixed by "??<pid>?? "; '?' depends on the VgMsgKind.
+   Should be used for all user output. */
+
+typedef
+   enum { Vg_UserMsg,         /* '?' == '=' */
+          Vg_DebugMsg,        /* '?' == '-' */
+          Vg_DebugExtraMsg,   /* '?' == '+' */
+          Vg_ClientMsg        /* '?' == '*' */
+   }
+   VgMsgKind;
+
+/* Send a single-part message.  Appends a newline. */
+extern UInt VG_(message)    ( VgMsgKind kind, const HChar* format, ... );
+extern UInt VG_(vmessage)   ( VgMsgKind kind, const HChar* format, va_list vargs );
+
+#endif   // __PUB_TOOL_LIBCPRINT_H
+
+/*--------------------------------------------------------------------*/
+/*--- end                                                          ---*/
+/*--------------------------------------------------------------------*/
diff --git a/include/tool.h b/include/tool.h
index 063b7c1..a781459 100644
--- a/include/tool.h
+++ b/include/tool.h
@@ -78,26 +78,6 @@
 
 
 /*====================================================================*/
-/*=== Printing messages for the user                               ===*/
-/*====================================================================*/
-
-/* Print a message prefixed by "??<pid>?? "; '?' depends on the VgMsgKind.
-   Should be used for all user output. */
-
-typedef
-   enum { Vg_UserMsg,         /* '?' == '=' */
-          Vg_DebugMsg,        /* '?' == '-' */
-          Vg_DebugExtraMsg,   /* '?' == '+' */
-          Vg_ClientMsg        /* '?' == '*' */
-   }
-   VgMsgKind;
-
-/* Send a single-part message.  Appends a newline. */
-extern UInt VG_(message)    ( VgMsgKind kind, const HChar* format, ... );
-extern UInt VG_(vmessage)   ( VgMsgKind kind, const HChar* format, va_list vargs );
-
-
-/*====================================================================*/
 /*=== Useful stuff to call from generated code                     ===*/
 /*====================================================================*/
 
@@ -132,17 +112,7 @@
 #endif
 
 /* ------------------------------------------------------------------ */
-/* stdio.h
- *
- * Note that they all output to the file descriptor given by the
- * --log-fd/--log-file/--log-socket argument, which defaults to 2 (stderr).
- * Hence no need for VG_(fprintf)().
- */
-extern UInt VG_(printf)  ( const HChar *format, ... );
-extern UInt VG_(vprintf) ( const HChar *format, va_list vargs );
-/* too noisy ...  __attribute__ ((format (printf, 1, 2))) ; */
-extern UInt VG_(sprintf) ( Char* buf, const HChar* format, ... );
-extern UInt VG_(vsprintf)( Char* buf, const HChar* format, va_list vargs );
+/* stdio.h */
 
 extern Int  VG_(rename) ( Char* old_name, Char* new_name );
 
diff --git a/lackey/lk_main.c b/lackey/lk_main.c
index 80a987b..f63551a 100644
--- a/lackey/lk_main.c
+++ b/lackey/lk_main.c
@@ -31,6 +31,7 @@
 
 #include "tool.h"
 #include "pub_tool_tooliface.h"
+#include "pub_tool_libcprint.h"
 
 /* Nb: use ULongs because the numbers can get very big */
 static ULong n_dlrr_calls   = 0;
diff --git a/massif/ms_main.c b/massif/ms_main.c
index ec8ebeb..c251473 100644
--- a/massif/ms_main.c
+++ b/massif/ms_main.c
@@ -38,6 +38,7 @@
 #include "pub_tool_debuginfo.h"
 #include "pub_tool_hashtable.h"
 #include "pub_tool_libcbase.h"
+#include "pub_tool_libcprint.h"
 #include "pub_tool_mallocfree.h"
 #include "pub_tool_options.h"
 #include "pub_tool_profile.h"
diff --git a/memcheck/mac_leakcheck.c b/memcheck/mac_leakcheck.c
index e7ed393..5341c0d 100644
--- a/memcheck/mac_leakcheck.c
+++ b/memcheck/mac_leakcheck.c
@@ -33,6 +33,7 @@
 #include <setjmp.h>
 #include "mac_shared.h"
 #include "pub_tool_libcbase.h"
+#include "pub_tool_libcprint.h"
 
 /* Define to debug the memory-leak-detector. */
 #define VG_DEBUG_LEAKCHECK 0
diff --git a/memcheck/mac_malloc_wrappers.c b/memcheck/mac_malloc_wrappers.c
index a35a6e7..a888536 100644
--- a/memcheck/mac_malloc_wrappers.c
+++ b/memcheck/mac_malloc_wrappers.c
@@ -32,6 +32,7 @@
 
 #include "mac_shared.h"
 #include "pub_tool_libcbase.h"
+#include "pub_tool_libcprint.h"
 
 /*------------------------------------------------------------*/
 /*--- Defns                                                ---*/
diff --git a/memcheck/mac_shared.c b/memcheck/mac_shared.c
index 2f9effd..83a8084 100644
--- a/memcheck/mac_shared.c
+++ b/memcheck/mac_shared.c
@@ -32,6 +32,7 @@
 
 #include "mac_shared.h"
 #include "pub_tool_libcbase.h"
+#include "pub_tool_libcprint.h"
 #include "memcheck.h"   /* for VG_USERREQ__* */
 
 /*------------------------------------------------------------*/
diff --git a/memcheck/mc_main.c b/memcheck/mc_main.c
index a4df82f..a2e24db 100644
--- a/memcheck/mc_main.c
+++ b/memcheck/mc_main.c
@@ -39,6 +39,7 @@
 #include "mc_include.h"
 #include "memcheck.h"   /* for client requests */
 #include "pub_tool_libcbase.h"
+#include "pub_tool_libcprint.h"
 
 
 #define EXPECTED_TAKEN(cond)     __builtin_expect((cond),1)
diff --git a/memcheck/mc_translate.c b/memcheck/mc_translate.c
index f61570b..d4a1327 100644
--- a/memcheck/mc_translate.c
+++ b/memcheck/mc_translate.c
@@ -30,6 +30,7 @@
 */
 
 #include "mc_include.h"
+#include "pub_tool_libcprint.h"
 
 
 /*------------------------------------------------------------*/