1 2 /*--------------------------------------------------------------------*/ 3 /*--- Address Description. ---*/ 4 /*--- hg_addrdescr.c ---*/ 5 /*--------------------------------------------------------------------*/ 6 7 /* 8 This file is part of Helgrind, a Valgrind tool for detecting errors 9 in threaded programs. 10 11 Copyright (C) 2007-2012 OpenWorks Ltd 12 info (at) open-works.co.uk 13 14 This program is free software; you can redistribute it and/or 15 modify it under the terms of the GNU General Public License as 16 published by the Free Software Foundation; either version 2 of the 17 License, or (at your option) any later version. 18 19 This program is distributed in the hope that it will be useful, but 20 WITHOUT ANY WARRANTY; without even the implied warranty of 21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 22 General Public License for more details. 23 24 You should have received a copy of the GNU General Public License 25 along with this program; if not, write to the Free Software 26 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 27 02111-1307, USA. 28 29 The GNU General Public License is contained in the file COPYING. 30 */ 31 #include "pub_tool_basics.h" 32 #include "pub_tool_libcbase.h" 33 #include "pub_tool_libcprint.h" 34 #include "pub_tool_libcassert.h" 35 #include "pub_tool_xarray.h" 36 #include "pub_tool_execontext.h" 37 #include "pub_tool_debuginfo.h" 38 #include "pub_tool_threadstate.h" 39 #include "pub_tool_addrinfo.h" 40 41 #include "hg_basics.h" 42 #include "hg_addrdescr.h" /* self */ 43 44 void HG_(describe_addr) ( Addr a, /*OUT*/AddrInfo* ai ) 45 { 46 tl_assert(ai->tag == Addr_Undescribed); 47 48 /* hctxt/haddr/hszB describe the addr if it is a heap block. */ 49 ExeContext* hctxt; 50 Addr haddr; 51 SizeT hszB; 52 53 /* First, see if it's in any heap block. Unfortunately this 54 means a linear search through all allocated heap blocks. The 55 assertion says that if it's detected as a heap block, then we 56 must have an allocation context for it, since all heap blocks 57 should have an allocation context. */ 58 Bool is_heapblock 59 = HG_(mm_find_containing_block)( 60 &hctxt, 61 &haddr, 62 &hszB, 63 a 64 ); 65 if (is_heapblock) { 66 tl_assert(is_heapblock == (hctxt != NULL)); 67 ai->tag = Addr_Block; 68 ai->Addr.Block.block_kind = Block_Mallocd; 69 ai->Addr.Block.block_desc = "block"; 70 ai->Addr.Block.block_szB = hszB; 71 ai->Addr.Block.rwoffset = (Word)(a) - (Word)(haddr); 72 ai->Addr.Block.allocated_at = hctxt; 73 ai->Addr.Block.freed_at = VG_(null_ExeContext)();; 74 } else { 75 /* No block found. Search a non-heap block description. */ 76 VG_(describe_addr) (a, ai); 77 } 78 } 79 80 Bool HG_(get_and_pp_addrdescr) (Addr addr) 81 { 82 83 Bool ret; 84 AddrInfo glai; 85 86 glai.tag = Addr_Undescribed; 87 HG_(describe_addr) (addr, &glai); 88 VG_(pp_addrinfo) (addr, &glai); 89 ret = glai.tag != Addr_Unknown; 90 91 VG_(clear_addrinfo) (&glai); 92 93 return ret; 94 } 95 96 /*--------------------------------------------------------------------*/ 97 /*--- end hg_addrdescr.c ---*/ 98 /*--------------------------------------------------------------------*/ 99