pub_tool_addrinfo.h revision 07c08527f05caeb0062b42ca9a58ee774ec5fba1
107c08527f05caeb0062b42ca9a58ee774ec5fba1philippe 207c08527f05caeb0062b42ca9a58ee774ec5fba1philippe/*--------------------------------------------------------------------*/ 307c08527f05caeb0062b42ca9a58ee774ec5fba1philippe/*--- Obtaining information about an address. pub_tool_addrinfo.h ---*/ 407c08527f05caeb0062b42ca9a58ee774ec5fba1philippe/*--------------------------------------------------------------------*/ 507c08527f05caeb0062b42ca9a58ee774ec5fba1philippe 607c08527f05caeb0062b42ca9a58ee774ec5fba1philippe/* 707c08527f05caeb0062b42ca9a58ee774ec5fba1philippe This file is part of Valgrind, a dynamic binary instrumentation 807c08527f05caeb0062b42ca9a58ee774ec5fba1philippe framework. 907c08527f05caeb0062b42ca9a58ee774ec5fba1philippe 1007c08527f05caeb0062b42ca9a58ee774ec5fba1philippe Copyright (C) 2000-2013 Julian Seward 1107c08527f05caeb0062b42ca9a58ee774ec5fba1philippe jseward@acm.org 1207c08527f05caeb0062b42ca9a58ee774ec5fba1philippe 1307c08527f05caeb0062b42ca9a58ee774ec5fba1philippe This program is free software; you can redistribute it and/or 1407c08527f05caeb0062b42ca9a58ee774ec5fba1philippe modify it under the terms of the GNU General Public License as 1507c08527f05caeb0062b42ca9a58ee774ec5fba1philippe published by the Free Software Foundation; either version 2 of the 1607c08527f05caeb0062b42ca9a58ee774ec5fba1philippe License, or (at your option) any later version. 1707c08527f05caeb0062b42ca9a58ee774ec5fba1philippe 1807c08527f05caeb0062b42ca9a58ee774ec5fba1philippe This program is distributed in the hope that it will be useful, but 1907c08527f05caeb0062b42ca9a58ee774ec5fba1philippe WITHOUT ANY WARRANTY; without even the implied warranty of 2007c08527f05caeb0062b42ca9a58ee774ec5fba1philippe MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 2107c08527f05caeb0062b42ca9a58ee774ec5fba1philippe General Public License for more details. 2207c08527f05caeb0062b42ca9a58ee774ec5fba1philippe 2307c08527f05caeb0062b42ca9a58ee774ec5fba1philippe You should have received a copy of the GNU General Public License 2407c08527f05caeb0062b42ca9a58ee774ec5fba1philippe along with this program; if not, write to the Free Software 2507c08527f05caeb0062b42ca9a58ee774ec5fba1philippe Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 2607c08527f05caeb0062b42ca9a58ee774ec5fba1philippe 02111-1307, USA. 2707c08527f05caeb0062b42ca9a58ee774ec5fba1philippe 2807c08527f05caeb0062b42ca9a58ee774ec5fba1philippe The GNU General Public License is contained in the file COPYING. 2907c08527f05caeb0062b42ca9a58ee774ec5fba1philippe*/ 3007c08527f05caeb0062b42ca9a58ee774ec5fba1philippe 3107c08527f05caeb0062b42ca9a58ee774ec5fba1philippe#ifndef __PUB_TOOL_ADDRINFO_H 3207c08527f05caeb0062b42ca9a58ee774ec5fba1philippe#define __PUB_TOOL_ADDRINFO_H 3307c08527f05caeb0062b42ca9a58ee774ec5fba1philippe 3407c08527f05caeb0062b42ca9a58ee774ec5fba1philippe#include "pub_tool_basics.h" // VG_ macro 3507c08527f05caeb0062b42ca9a58ee774ec5fba1philippe 3607c08527f05caeb0062b42ca9a58ee774ec5fba1philippe/*====================================================================*/ 3707c08527f05caeb0062b42ca9a58ee774ec5fba1philippe/*=== Obtaining information about an address ===*/ 3807c08527f05caeb0062b42ca9a58ee774ec5fba1philippe/*====================================================================*/ 3907c08527f05caeb0062b42ca9a58ee774ec5fba1philippe 4007c08527f05caeb0062b42ca9a58ee774ec5fba1philippe// Different kinds of blocks. 4107c08527f05caeb0062b42ca9a58ee774ec5fba1philippe// Block_Mallocd is used by tools that maintain detailed information about 4207c08527f05caeb0062b42ca9a58ee774ec5fba1philippe// Client allocated heap blocks. 4307c08527f05caeb0062b42ca9a58ee774ec5fba1philippe// Block_Freed is used by tools such as memcheck that maintain a 'quarantine' 4407c08527f05caeb0062b42ca9a58ee774ec5fba1philippe// list of blocks freed by the Client but not yet physically freed. 4507c08527f05caeb0062b42ca9a58ee774ec5fba1philippe// Block_MempoolChunk and Block_UserG are used for mempool or user defined heap 4607c08527f05caeb0062b42ca9a58ee774ec5fba1philippe// blocks. 4707c08527f05caeb0062b42ca9a58ee774ec5fba1philippe// Block_ClientArenaMallocd and Block_ClientArenaFree are used when the tool 4807c08527f05caeb0062b42ca9a58ee774ec5fba1philippe// replaces the malloc/free/... functions but does not maintain detailed 4907c08527f05caeb0062b42ca9a58ee774ec5fba1philippe// information about Client allocated heap blocks. 5007c08527f05caeb0062b42ca9a58ee774ec5fba1philippe// Block_ValgrindArenaMallocd and Block_ValgrindArenaFree are used for heap blocks 5107c08527f05caeb0062b42ca9a58ee774ec5fba1philippe// of Valgrind internal heap. 5207c08527f05caeb0062b42ca9a58ee774ec5fba1philippetypedef enum { 5307c08527f05caeb0062b42ca9a58ee774ec5fba1philippe Block_Mallocd = 111, 5407c08527f05caeb0062b42ca9a58ee774ec5fba1philippe Block_Freed, 5507c08527f05caeb0062b42ca9a58ee774ec5fba1philippe Block_MempoolChunk, 5607c08527f05caeb0062b42ca9a58ee774ec5fba1philippe Block_UserG, 5707c08527f05caeb0062b42ca9a58ee774ec5fba1philippe Block_ClientArenaMallocd, 5807c08527f05caeb0062b42ca9a58ee774ec5fba1philippe Block_ClientArenaFree, 5907c08527f05caeb0062b42ca9a58ee774ec5fba1philippe Block_ValgrindArenaMallocd, 6007c08527f05caeb0062b42ca9a58ee774ec5fba1philippe Block_ValgrindArenaFree, 6107c08527f05caeb0062b42ca9a58ee774ec5fba1philippe} BlockKind; 6207c08527f05caeb0062b42ca9a58ee774ec5fba1philippe 6307c08527f05caeb0062b42ca9a58ee774ec5fba1philippe/* ------------------ Addresses -------------------- */ 6407c08527f05caeb0062b42ca9a58ee774ec5fba1philippe 6507c08527f05caeb0062b42ca9a58ee774ec5fba1philippe/* The classification of a faulting address. */ 6607c08527f05caeb0062b42ca9a58ee774ec5fba1philippetypedef 6707c08527f05caeb0062b42ca9a58ee774ec5fba1philippe enum { 6807c08527f05caeb0062b42ca9a58ee774ec5fba1philippe Addr_Undescribed, // as-yet unclassified 6907c08527f05caeb0062b42ca9a58ee774ec5fba1philippe Addr_Unknown, // classification yielded nothing useful 7007c08527f05caeb0062b42ca9a58ee774ec5fba1philippe Addr_Block, // in malloc'd/free'd block 7107c08527f05caeb0062b42ca9a58ee774ec5fba1philippe Addr_Stack, // on a thread's stack 7207c08527f05caeb0062b42ca9a58ee774ec5fba1philippe Addr_DataSym, // in a global data sym 7307c08527f05caeb0062b42ca9a58ee774ec5fba1philippe Addr_Variable, // variable described by the debug info 7407c08527f05caeb0062b42ca9a58ee774ec5fba1philippe Addr_SectKind // last-ditch classification attempt 7507c08527f05caeb0062b42ca9a58ee774ec5fba1philippe } 7607c08527f05caeb0062b42ca9a58ee774ec5fba1philippe AddrTag; 7707c08527f05caeb0062b42ca9a58ee774ec5fba1philippe 7807c08527f05caeb0062b42ca9a58ee774ec5fba1philippetypedef 7907c08527f05caeb0062b42ca9a58ee774ec5fba1philippe struct _AddrInfo 8007c08527f05caeb0062b42ca9a58ee774ec5fba1philippe AddrInfo; 8107c08527f05caeb0062b42ca9a58ee774ec5fba1philippe 8207c08527f05caeb0062b42ca9a58ee774ec5fba1philippestruct _AddrInfo { 8307c08527f05caeb0062b42ca9a58ee774ec5fba1philippe AddrTag tag; 8407c08527f05caeb0062b42ca9a58ee774ec5fba1philippe union { 8507c08527f05caeb0062b42ca9a58ee774ec5fba1philippe // As-yet unclassified. 8607c08527f05caeb0062b42ca9a58ee774ec5fba1philippe struct { } Undescribed; 8707c08527f05caeb0062b42ca9a58ee774ec5fba1philippe 8807c08527f05caeb0062b42ca9a58ee774ec5fba1philippe // On a stack. 8907c08527f05caeb0062b42ca9a58ee774ec5fba1philippe struct { 9007c08527f05caeb0062b42ca9a58ee774ec5fba1philippe ThreadId tid; // Which thread's stack? 9107c08527f05caeb0062b42ca9a58ee774ec5fba1philippe } Stack; 9207c08527f05caeb0062b42ca9a58ee774ec5fba1philippe 9307c08527f05caeb0062b42ca9a58ee774ec5fba1philippe // This covers heap blocks (normal and from mempools), user-defined blocks, 9407c08527f05caeb0062b42ca9a58ee774ec5fba1philippe // and Arena blocks. 9507c08527f05caeb0062b42ca9a58ee774ec5fba1philippe struct { 9607c08527f05caeb0062b42ca9a58ee774ec5fba1philippe BlockKind block_kind; 9707c08527f05caeb0062b42ca9a58ee774ec5fba1philippe const HChar* block_desc; // "block", "mempool" or user-defined or arena 9807c08527f05caeb0062b42ca9a58ee774ec5fba1philippe SizeT block_szB; 9907c08527f05caeb0062b42ca9a58ee774ec5fba1philippe PtrdiffT rwoffset; 10007c08527f05caeb0062b42ca9a58ee774ec5fba1philippe ExeContext* allocated_at; // might be null_ExeContext. 10107c08527f05caeb0062b42ca9a58ee774ec5fba1philippe ExeContext* freed_at; // might be null_ExeContext. 10207c08527f05caeb0062b42ca9a58ee774ec5fba1philippe } Block; 10307c08527f05caeb0062b42ca9a58ee774ec5fba1philippe 10407c08527f05caeb0062b42ca9a58ee774ec5fba1philippe // In a global .data symbol. This holds the first 127 chars of 10507c08527f05caeb0062b42ca9a58ee774ec5fba1philippe // the variable's name (zero terminated), plus a (memory) offset. 10607c08527f05caeb0062b42ca9a58ee774ec5fba1philippe struct { 10707c08527f05caeb0062b42ca9a58ee774ec5fba1philippe HChar name[128]; 10807c08527f05caeb0062b42ca9a58ee774ec5fba1philippe PtrdiffT offset; 10907c08527f05caeb0062b42ca9a58ee774ec5fba1philippe } DataSym; 11007c08527f05caeb0062b42ca9a58ee774ec5fba1philippe 11107c08527f05caeb0062b42ca9a58ee774ec5fba1philippe // Is described by Dwarf debug info. XArray*s of HChar. 11207c08527f05caeb0062b42ca9a58ee774ec5fba1philippe struct { 11307c08527f05caeb0062b42ca9a58ee774ec5fba1philippe XArray* /* of HChar */ descr1; 11407c08527f05caeb0062b42ca9a58ee774ec5fba1philippe XArray* /* of HChar */ descr2; 11507c08527f05caeb0062b42ca9a58ee774ec5fba1philippe } Variable; 11607c08527f05caeb0062b42ca9a58ee774ec5fba1philippe 11707c08527f05caeb0062b42ca9a58ee774ec5fba1philippe // Could only narrow it down to be the PLT/GOT/etc of a given 11807c08527f05caeb0062b42ca9a58ee774ec5fba1philippe // object. Better than nothing, perhaps. 11907c08527f05caeb0062b42ca9a58ee774ec5fba1philippe struct { 12007c08527f05caeb0062b42ca9a58ee774ec5fba1philippe HChar objname[128]; 12107c08527f05caeb0062b42ca9a58ee774ec5fba1philippe VgSectKind kind; 12207c08527f05caeb0062b42ca9a58ee774ec5fba1philippe } SectKind; 12307c08527f05caeb0062b42ca9a58ee774ec5fba1philippe 12407c08527f05caeb0062b42ca9a58ee774ec5fba1philippe // Classification yielded nothing useful. 12507c08527f05caeb0062b42ca9a58ee774ec5fba1philippe struct { } Unknown; 12607c08527f05caeb0062b42ca9a58ee774ec5fba1philippe 12707c08527f05caeb0062b42ca9a58ee774ec5fba1philippe } Addr; 12807c08527f05caeb0062b42ca9a58ee774ec5fba1philippe}; 12907c08527f05caeb0062b42ca9a58ee774ec5fba1philippe 13007c08527f05caeb0062b42ca9a58ee774ec5fba1philippe 13107c08527f05caeb0062b42ca9a58ee774ec5fba1philippe/* Describe an address as best you can, putting the result in ai. 13207c08527f05caeb0062b42ca9a58ee774ec5fba1philippe On entry, ai->tag must be equal to Addr_Undescribed. 13307c08527f05caeb0062b42ca9a58ee774ec5fba1philippe This might allocate some memory, that can be cleared with 13407c08527f05caeb0062b42ca9a58ee774ec5fba1philippe VG_(clear_addrinfo). */ 13507c08527f05caeb0062b42ca9a58ee774ec5fba1philippeextern void VG_(describe_addr) ( Addr a, /*OUT*/AddrInfo* ai ); 13607c08527f05caeb0062b42ca9a58ee774ec5fba1philippe 13707c08527f05caeb0062b42ca9a58ee774ec5fba1philippeextern void VG_(clear_addrinfo) ( AddrInfo* ai); 13807c08527f05caeb0062b42ca9a58ee774ec5fba1philippe 13907c08527f05caeb0062b42ca9a58ee774ec5fba1philippe/* Prints the AddrInfo ai describing a. */ 14007c08527f05caeb0062b42ca9a58ee774ec5fba1philippeextern void VG_(pp_addrinfo) ( Addr a, AddrInfo* ai ); 14107c08527f05caeb0062b42ca9a58ee774ec5fba1philippe 14207c08527f05caeb0062b42ca9a58ee774ec5fba1philippe/* Same as VG_(pp_addrinfo) but provides some memcheck specific behaviour: 14307c08527f05caeb0062b42ca9a58ee774ec5fba1philippe * maybe_gcc indicates Addr a was just below the stack ptr when the error 14407c08527f05caeb0062b42ca9a58ee774ec5fba1philippe with a was encountered. 14507c08527f05caeb0062b42ca9a58ee774ec5fba1philippe * the message for Unknown tag is slightly different, as memcheck 14607c08527f05caeb0062b42ca9a58ee774ec5fba1philippe has a recently freed list. */ 14707c08527f05caeb0062b42ca9a58ee774ec5fba1philippeextern void VG_(pp_addrinfo_mc) ( Addr a, AddrInfo* ai, Bool maybe_gcc ); 14807c08527f05caeb0062b42ca9a58ee774ec5fba1philippe 14907c08527f05caeb0062b42ca9a58ee774ec5fba1philippe#endif // __PUB_TOOL_ADDRINFO_H 15007c08527f05caeb0062b42ca9a58ee774ec5fba1philippe 15107c08527f05caeb0062b42ca9a58ee774ec5fba1philippe/*--------------------------------------------------------------------*/ 15207c08527f05caeb0062b42ca9a58ee774ec5fba1philippe/*--- end ---*/ 15307c08527f05caeb0062b42ca9a58ee774ec5fba1philippe/*--------------------------------------------------------------------*/ 154