Home | History | Annotate | Download | only in include
      1 
      2 /*-----------------------------------------------------------------------*/
      3 /*--- Support functions for xtree memory reports. pub_tool_xtmemory.h ---*/
      4 /*-----------------------------------------------------------------------*/
      5 
      6 /*
      7    This file is part of Valgrind, a dynamic binary instrumentation
      8    framework.
      9 
     10    Copyright (C) 2016-2017 Philippe Waroquiers
     11 
     12    This program is free software; you can redistribute it and/or
     13    modify it under the terms of the GNU General Public License as
     14    published by the Free Software Foundation; either version 2 of the
     15    License, or (at your option) any later version.
     16 
     17    This program is distributed in the hope that it will be useful, but
     18    WITHOUT ANY WARRANTY; without even the implied warranty of
     19    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     20    General Public License for more details.
     21 
     22    You should have received a copy of the GNU General Public License
     23    along with this program; if not, write to the Free Software
     24    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
     25    02111-1307, USA.
     26 
     27    The GNU General Public License is contained in the file COPYING.
     28 */
     29 
     30 #ifndef __PUB_TOOL_XTMEMORY_H
     31 #define __PUB_TOOL_XTMEMORY_H
     32 
     33 /* Type to profile allocated size and nr of blocks, typically used for
     34    --xtree-memory=allocs. */
     35 typedef
     36    struct _XT_Allocs {
     37       SizeT nbytes;
     38       SizeT nblocks;
     39    } XT_Allocs;
     40 
     41 /* Support functions to produce a full xtree memory profiling. */
     42 /* tool must call VG_(XTMemory_Full_init) to ini full xtree memory profiling. */
     43 extern void VG_(XTMemory_Full_init) (XT_filter_IPs_t filter_IPs_Fn);
     44 /* Then each time a certain nr of blocks are allocated or freed, the below
     45    functions must be called. The arguments are:
     46       szB: nr of bytes for the allocated/freed block(s)
     47       ec_alloc : ExeContext of the allocation (original allocation for
     48                  free and resize_in_place).
     49       ec_free  : ExeContext of the free.
     50    The tool is responsible to properly provide the ExeContext for
     51    the allocation and free. For VG_(XTMemory_Full_free), ec_alloc
     52    must be the one that was used for the allocation of the just released
     53    block. */
     54 extern void VG_(XTMemory_Full_alloc)(SizeT szB,
     55                                      ExeContext* ec_alloc);
     56 extern void VG_(XTMemory_Full_free)(SizeT szB,
     57                                     ExeContext* ec_alloc,
     58                                     ExeContext* ec_free);
     59 extern void VG_(XTMemory_Full_resize_in_place)(SizeT oldSzB, SizeT newSzB,
     60                                                ExeContext* ec_alloc);
     61 
     62 /* Handle the production of a xtree memory report, either during run (fini False
     63    e.g. via a gdb monitor command), or at the end of execution (fini True).
     64 
     65    VG_(XTMemory_report) behaviour depends on the value of the command line
     66    options --xtree-memory=none|allocs|full and --xtree-memory-file=<filename> :
     67      If --xtree-memory=full, the report will be produced from the data
     68        provided via the calls to void VG_(XTMemory_Full_*).
     69      Otherwise, for --xtree-memory=allocs or for --xtree-memory=none (if fini
     70        is False), next_block is used to get the data for the report:
     71    next_block is called repetitively to get information about all allocated
     72    blocks, till xta->nblocks is 0.
     73    If filename is NULL, --xtree-memory-file is used to produce the name.
     74    filter_IPs_fn : used for --xtree-memory=allocs/none filtering (see
     75    VG_(XT_create) and XT_filter_IPs_t typdef for more information). */
     76 extern void VG_(XTMemory_report)
     77      (const HChar* filename, Bool fini,
     78       void (*next_block)(XT_Allocs* xta, ExeContext** ec_alloc),
     79       XT_filter_IPs_t filter_IPs_fn);
     80 
     81 #endif   // __PUB_TOOL_XTMEMORY_H
     82 
     83 
     84 /*-----------------------------------------------------------------------*/
     85 /*--- end                                         pub_tool_xtmemory.h ---*/
     86 /*-----------------------------------------------------------------------*/
     87