Files
ftmemsim-valgrind/coregrind/m_replacemalloc/replacemalloc_core.c
Julian Seward e7dde85a24 Merge coregrind/ changes from branches/MESSAGING_TIDYUP r10464.
This commit tidies up and rationalises what could be called the
"messaging" system -- that part of V to do with presenting output to
the user.  In particular it brings significant improvements to XML
output.

Changes are:

* XML and normal text output now have separate file descriptors,
  which solves longstanding problems for XML consumers caused by
  the XML output getting polluted by unexpected non-XML output.

* This also means that we no longer have to hardwire all manner
  of output settings (verbosity, etc) when XML is requested.

* The XML output format has been revised, cleaned up, and made
  more suitable for use by error detecting tools in general
  (various Memcheck-specific features have been removed).  XML
  output is enabled for Ptrcheck and Helgrind, and Memcheck is
  updated to the new format.

* One side effect is that the behaviour of VG_(message) has been
  made to be consistent with printf: it no longer automatically
  adds a newline at the end of the output.  This means multiple
  calls to it can be used to build up a single line message; or a
  single call can write a multi-line message.  The ==pid==
  preamble is automatically inserted at each newline.

* VG_(message)(Vg_UserMsg, ..args..) now has the abbreviated form
  VG_(UMSG)(..args..); ditto VG_(DMSG) for Vg_DebugMsg and
  VG_(EMSG) for Vg_DebugExtraMsg.  A couple of other useful
  printf derivatives have been added to pub_tool_libcprint.h,
  most particularly VG_(vcbprintf).

* There's a small change in the core-tool interface to do with
  error handling: VG_(needs_tool_errors) has a new method
  void (*before_pp_Error)(Error* err)  which, if non-NULL, is
  called just before  void (*pp_Error)(Error* err).  This is to
  give tools the chance to look at errors before any part of them
  is printed, so they can print any XML preamble they like.

* coregrind/m_errormgr.c has been overhauled and cleaned up, and
  is a bit simpler and more commented.  In particular pp_Error
  and VG_(maybe_record_error) are significantly changed.

The diff is huge, but mostly very boring.  Most of the changes
are of the form

-   VG_(message)(Vg_UserMsg, "this is a message %d", n);
+   VG_(message)(Vg_UserMsg, "this is a message %d\n", n);

Unfortunately as a result of this, it touches a large number
of source files.



git-svn-id: svn://svn.valgrind.org/valgrind/trunk@10465
2009-07-15 14:48:32 +00:00

121 lines
4.2 KiB
C

/*--------------------------------------------------------------------*/
/*--- Malloc replacement. replacemalloc_core.c ---*/
/*--------------------------------------------------------------------*/
/*
This file is part of Valgrind, a dynamic binary instrumentation
framework.
Copyright (C) 2000-2009 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 "pub_core_basics.h"
#include "pub_core_libcbase.h"
#include "pub_core_libcprint.h"
#include "pub_core_mallocfree.h"
#include "pub_core_options.h"
#include "pub_core_replacemalloc.h"
/*------------------------------------------------------------*/
/*--- Command line options ---*/
/*------------------------------------------------------------*/
/* Nb: the allocator always rounds blocks up to a multiple of
VG_MIN_MALLOC_SZB.
*/
/* DEBUG: print malloc details? default: NO */
Bool VG_(clo_trace_malloc) = False;
/* Minimum alignment in functions that don't specify alignment explicitly.
default: 0, i.e. use VG_MIN_MALLOC_SZB. */
UInt VG_(clo_alignment) = VG_MIN_MALLOC_SZB;
Bool VG_(replacement_malloc_process_cmd_line_option)(Char* arg)
{
if VG_INT_CLO(arg, "--alignment", VG_(clo_alignment)) {
if (VG_(clo_alignment) < VG_MIN_MALLOC_SZB ||
VG_(clo_alignment) > 4096 ||
VG_(log2)( VG_(clo_alignment) ) == -1 /* not a power of 2 */)
{
VG_(message)(Vg_UserMsg,
"Invalid --alignment= setting. "
"Should be a power of 2, >= %d, <= 4096.\n",
VG_MIN_MALLOC_SZB
);
VG_(err_bad_option)("--alignment");
}
}
else if VG_BOOL_CLO(arg, "--trace-malloc", VG_(clo_trace_malloc)) {}
else
return False;
return True;
}
void VG_(replacement_malloc_print_usage)(void)
{
VG_(printf)(
" --alignment=<number> set minimum alignment of allocations [%d]\n",
VG_MIN_MALLOC_SZB
);
}
void VG_(replacement_malloc_print_debug_usage)(void)
{
VG_(printf)(
" --trace-malloc=no|yes show client malloc details? [no]\n"
);
}
/*------------------------------------------------------------*/
/*--- Useful functions ---*/
/*------------------------------------------------------------*/
void* VG_(cli_malloc) ( SizeT align, SizeT nbytes )
{
// 'align' should be valid (ie. big enough and a power of two) by now.
// VG_(arena_memalign)() will abort if it's not.
if (VG_MIN_MALLOC_SZB == align)
return VG_(arena_malloc) ( VG_AR_CLIENT, "replacemalloc.cm.1",
nbytes );
else
return VG_(arena_memalign) ( VG_AR_CLIENT, "replacemalloc.cm.2",
align, nbytes );
}
void VG_(cli_free) ( void* p )
{
VG_(arena_free) ( VG_AR_CLIENT, p );
}
Bool VG_(addr_is_in_block)( Addr a, Addr start, SizeT size, SizeT rz_szB )
{
return ( start - rz_szB <= a && a < start + size + rz_szB );
}
/*--------------------------------------------------------------------*/
/*--- end ---*/
/*--------------------------------------------------------------------*/