From: Nicholas Nethercote Date: Fri, 3 Jun 2005 03:08:39 +0000 (+0000) Subject: Modularise printing functions in m_libcprint. X-Git-Tag: svn/VALGRIND_3_0_0~478 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=dbc8c6d99ced09706914bcec9fee7449e5f94ed0;p=thirdparty%2Fvalgrind.git Modularise printing functions in m_libcprint. git-svn-id: svn://svn.valgrind.org/valgrind/trunk@3840 --- diff --git a/cachegrind/amd64/cg_arch.c b/cachegrind/amd64/cg_arch.c index 9d6ba0169c..8d14da37c5 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 f775224006..9800069aa3 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 c313b7aaec..1c13db3b1b 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 f737836c03..36ab3a68dc 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 723436c106..d5c2ef9010 100644 --- a/coregrind/Makefile.am +++ b/coregrind/Makefile.am @@ -47,6 +47,7 @@ noinst_HEADERS = \ 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 @@ stage2_SOURCES = \ 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 @@ stage2_SOURCES = \ 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 58e08f7cea..25c8ee41af 100644 --- a/coregrind/core.h +++ b/coregrind/core.h @@ -128,10 +128,6 @@ extern void VG_(core_panic_at) ( Char* str, Addr ip, Addr sp, Addr fp ); 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 1c65a29602..77ed8618e8 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 5f4fce11e9..ded33e6e0d 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 f1699c1e8f..7e20cc1624 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 a4c7004eba..2cde63765a 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 1ba467fdd8..aa117a359e 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 /* stabs defns */ diff --git a/coregrind/m_debuginfo/symtab.c b/coregrind/m_debuginfo/symtab.c index a259560148..94d2b323bf 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 8c32d9e209..4eae1ed5eb 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 fe059c75e7..e854c04c8f 100644 --- a/coregrind/m_demangle/cplus-dem.c +++ b/coregrind/m_demangle/cplus-dem.c @@ -39,6 +39,7 @@ Boston, MA 02111-1307, USA. */ #include "safe-ctype.h" #include "core.h" #include "pub_core_libcbase.h" +#include "pub_tool_libcprint.h" /*#include #include diff --git a/coregrind/m_errormgr.c b/coregrind/m_errormgr.c index 34a3219bb3..fe36d2291e 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 d8a47af418..f53f151d7e 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 33608efdca..1ab10d37d8 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 713667ccda..d64272bc0d 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 b6b58a7a89..3c09ef92e8 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 630fa9d29d..2f72aa308d 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 b00645b691..81afc96c61 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 8b99757f3f..25ef0cf65b 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 11c402c09d..5455ce7e7b 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 b9e2d6a682..33593bc96f 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 36aa5f1ae7..f760586935 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 d7dcc7f818..36d57361f6 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 1de8d2df55..17ee897c9c 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 diff --git a/coregrind/m_stacktrace.c b/coregrind/m_stacktrace.c index 2b87d765ba..d9845cd2bf 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 fdece82ac7..e96bb2ea50 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 6895c43f9a..165a97f5aa 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 d7cdd576d0..e4cd2675c8 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 05805e49db..dfc9ff6010 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 9c343fd51d..b9916af471 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 eb4d9409b8..9da8aaeb21 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 50182e3e55..8cc16997d6 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 0000000000..303a4305c3 --- /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 fe4004c2eb..0000000000 --- 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 -#include - -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 989bcd386f..9486dac0e0 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 @@ Int VG_(poll)( struct vki_pollfd *ufds, UInt nfds, Int timeout) } -/* 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 91d9be0bd1..d23fe7a574 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 62426871c4..aac22923e1 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -9,6 +9,7 @@ incinc_HEADERS = \ 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 0000000000..8e44d23a1b --- /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 "???? "; '?' 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 063b7c1426..a781459d59 100644 --- a/include/tool.h +++ b/include/tool.h @@ -77,26 +77,6 @@ extern Char** VG_(client_argv); extern Char** VG_(client_envp); -/*====================================================================*/ -/*=== Printing messages for the user ===*/ -/*====================================================================*/ - -/* Print a message prefixed by "???? "; '?' 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 @@ extern Addr VG_(get_IP) ( ThreadId tid ); #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 80a987b63a..f63551aa25 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 ec8ebeb704..c25147352e 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 e7ed39339d..5341c0d143 100644 --- a/memcheck/mac_leakcheck.c +++ b/memcheck/mac_leakcheck.c @@ -33,6 +33,7 @@ #include #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 a35a6e77a9..a888536ec7 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 2f9effd127..83a8084a8f 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 a4df82f01e..a2e24db51c 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 f61570b8f8..d4a1327c78 100644 --- a/memcheck/mc_translate.c +++ b/memcheck/mc_translate.c @@ -30,6 +30,7 @@ */ #include "mc_include.h" +#include "pub_tool_libcprint.h" /*------------------------------------------------------------*/