From: Nicholas Nethercote Date: Sat, 18 Jun 2005 02:18:04 +0000 (+0000) Subject: Created coregrind.h, a counterpart to valgrind.h containing the internal X-Git-Tag: svn/VALGRIND_3_0_0~391 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=c5a38c663b6033ebfa7fbf1ed078422f27cade03;p=thirdparty%2Fvalgrind.git Created coregrind.h, a counterpart to valgrind.h containing the internal client requests. git-svn-id: svn://svn.valgrind.org/valgrind/trunk@3927 --- diff --git a/coregrind/Makefile.am b/coregrind/Makefile.am index 76b9e16266..3ba22e22d3 100644 --- a/coregrind/Makefile.am +++ b/coregrind/Makefile.am @@ -37,6 +37,7 @@ val_PROGRAMS = \ noinst_HEADERS = \ core.h \ core_asm.h \ + coregrind.h \ pub_core_aspacemgr.h \ pub_core_debuginfo.h \ pub_core_debuglog.h \ diff --git a/coregrind/core.h b/coregrind/core.h index 26b7c46390..93d96c51e4 100644 --- a/coregrind/core.h +++ b/coregrind/core.h @@ -49,20 +49,6 @@ #include "pub_core_scheduler.h" // for types 'ThreadArchState' -/* These are the internal client request codes. The publically-visible - request codes are also defined in valgrind.h, and similar headers for - some tools. */ - -/* Get the tool's malloc-wrapping functions */ -#define VG_USERREQ__GET_MALLOCFUNCS 0x3030 - -/* Internal equivalent of VALGRIND_PRINTF . */ -#define VG_USERREQ__INTERNAL_PRINTF 0x3103 - -/* Denote the finish of __libc_freeres_wrapper(). - A synonym for exit. */ -#define VG_USERREQ__LIBC_FREERES_DONE 0x3029 - /* --------------------------------------------------------------------- Exports of vg_helpers.S ------------------------------------------------------------------ */ diff --git a/coregrind/coregrind.h b/coregrind/coregrind.h new file mode 100644 index 0000000000..8f3b9847be --- /dev/null +++ b/coregrind/coregrind.h @@ -0,0 +1,80 @@ + +/*--------------------------------------------------------------------*/ +/*--- Internal client requests. coregrind.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 __COREGRIND_H +#define __COREGRIND_H + +//-------------------------------------------------------------------- +// PURPOSE: This file is the counterpart to valgrind.h. It contains +// the client requests that are internal to Valgrind, and not to be seen +// by client programs. +//-------------------------------------------------------------------- + +#include + +// The strange choice of values here is due to historical reasons -- there +// used to be many more internal client requests. +typedef + enum { + /* Denote the finish of __libc_freeres_wrapper(). Also causes exit. */ + VG_USERREQ__LIBC_FREERES_DONE = 0x3029, + + /* Get the tool's malloc-wrapping functions */ + VG_USERREQ__GET_MALLOCFUNCS = 0x3030, + + /* Internal equivalent of VALGRIND_PRINTF . */ + VG_USERREQ__INTERNAL_PRINTF = 0x3103, + + } Vg_InternalClientRequest; + +// Function for printing from code within Valgrind, but which runs on the +// sim'd CPU. Must be a function rather than macros so that va_list can +// be used. + +int VALGRIND_INTERNAL_PRINTF(char *format, ...); +__attribute__((format(__printf__, 1, 2))) +__attribute__((weak)) +int VALGRIND_INTERNAL_PRINTF(char *format, ...) +{ + unsigned long _qzz_res = 0; + va_list vargs; + va_start(vargs, format); + VALGRIND_MAGIC_SEQUENCE(_qzz_res, 0, VG_USERREQ__INTERNAL_PRINTF, + (unsigned long)format, (unsigned long)vargs, 0, 0); + va_end(vargs); + return _qzz_res; +} + + +#endif // __COREGRIND_H + +/*--------------------------------------------------------------------*/ +/*--- end ---*/ +/*--------------------------------------------------------------------*/ diff --git a/coregrind/m_replacemalloc/vg_replace_malloc.c b/coregrind/m_replacemalloc/vg_replace_malloc.c index 723bcfde01..be1a26f72a 100644 --- a/coregrind/m_replacemalloc/vg_replace_malloc.c +++ b/coregrind/m_replacemalloc/vg_replace_malloc.c @@ -45,6 +45,8 @@ ------------------------------------------------------------------ */ #include "valgrind.h" // for VALGRIND_NON_SIMD_CALL[12] +#include "coregrind.h" // for VALGRIND_INTERNAL_PRINTF + #include "core.h" #include "pub_core_debuginfo.h" // needed for pub_core_redir.h :( #include "pub_core_mallocfree.h" // for VG_MIN_MALLOC_SZB, VG_AR_CLIENT @@ -81,29 +83,9 @@ static int init_done; /* Startup hook - called as init section */ static void init(void) __attribute__((constructor)); -// Functions for printing from code within Valgrind, but which runs on the -// sim'd CPU. They must be functions rather than macros so that va_list can -// be used. -// Nb: at one point, these were used by multiple files that run on the sim'd -// CPU, and so were *defined* in core.h with the 'weak' attribute. That was -// pretty ugly. It's much better if this is the only file that needs them. - -__attribute__((format(__printf__, 1, 2))) -static int -internal_printf(char *format, ...) -{ - UWord _qzz_res = 0; - va_list vargs; - va_start(vargs, format); - VALGRIND_MAGIC_SEQUENCE(_qzz_res, 0, VG_USERREQ__INTERNAL_PRINTF, - (UWord)format, (UWord)vargs, 0, 0); - va_end(vargs); - return _qzz_res; -} - #define MALLOC_TRACE(format, args...) \ if (info.clo_trace_malloc) \ - internal_printf(format, ## args ) + VALGRIND_INTERNAL_PRINTF(format, ## args ) /* Below are new versions of malloc, __builtin_new, free, __builtin_delete, calloc, realloc, memalign, and friends. @@ -312,8 +294,7 @@ CALLOC(m_libc_dot_so_dot_6, calloc); return VG_REPLACE_FUNCTION(libcZdsoZd6,malloc) (new_size); \ if (new_size <= 0) { \ VG_REPLACE_FUNCTION(libcZdsoZd6,free)(ptrV); \ - if (info.clo_trace_malloc) \ - internal_printf(" = 0" ); \ + MALLOC_TRACE(" = 0"); \ return NULL; \ } \ if (!init_done) init(); \ diff --git a/coregrind/m_scheduler/scheduler.c b/coregrind/m_scheduler/scheduler.c index c7b6e91162..1d149e579e 100644 --- a/coregrind/m_scheduler/scheduler.c +++ b/coregrind/m_scheduler/scheduler.c @@ -53,13 +53,14 @@ This file is almost entirely OS-independent. The details of how the OS handles threading and signalling are abstracted away and - implemented elsewhere. + implemented elsewhere. [Some of the functions have worked their + way back for the moment, until we do an OS port in earnest...] */ -#include "valgrind.h" /* for VG_USERREQ__RUNNING_ON_VALGRIND and - VG_USERREQ__DISCARD_TRANSLATIONS, and others */ -#include "core.h" +#include "valgrind.h" // for VG_USERREQ__* +#include "coregrind.h" // for VG_USERREQ__* +#include "core.h" #include "pub_core_aspacemgr.h" #include "pub_core_dispatch.h" #include "pub_core_errormgr.h" diff --git a/coregrind/vg_preloaded.c b/coregrind/vg_preloaded.c index e3dc68b7ba..11c1507021 100644 --- a/coregrind/vg_preloaded.c +++ b/coregrind/vg_preloaded.c @@ -43,6 +43,8 @@ ------------------------------------------------------------------ */ #include "valgrind.h" +#include "coregrind.h" + #include "core.h" #include "pub_core_debuginfo.h" // needed for pub_core_redir.h :( #include "pub_core_redir.h"