Add bug 467036 Add time cost statistics for Regtest to NEWS
[valgrind.git] / helgrind / hg_addrdescr.c
blobc13ad07e2da88289d11877647e070ecf9f9208b0
2 /*--------------------------------------------------------------------*/
3 /*--- Address Description. ---*/
4 /*--- hg_addrdescr.c ---*/
5 /*--------------------------------------------------------------------*/
7 /*
8 This file is part of Helgrind, a Valgrind tool for detecting errors
9 in threaded programs.
11 Copyright (C) 2007-2017 OpenWorks Ltd
12 info@open-works.co.uk
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.
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.
24 You should have received a copy of the GNU General Public License
25 along with this program; if not, see <http://www.gnu.org/licenses/>.
27 The GNU General Public License is contained in the file COPYING.
29 #include "pub_tool_basics.h"
30 #include "pub_tool_libcbase.h"
31 #include "pub_tool_libcprint.h"
32 #include "pub_tool_libcassert.h"
33 #include "pub_tool_wordfm.h"
34 #include "pub_tool_xarray.h"
35 #include "pub_tool_execontext.h"
36 #include "pub_tool_debuginfo.h"
37 #include "pub_tool_threadstate.h"
38 #include "pub_tool_aspacemgr.h"
39 #include "pub_tool_addrinfo.h"
41 #include "hg_basics.h"
42 #include "hg_wordset.h"
43 #include "hg_lock_n_thread.h"
44 #include "hg_addrdescr.h" /* self */
46 void HG_(describe_addr) ( DiEpoch ep, Addr a, /*OUT*/AddrInfo* ai )
48 tl_assert(ai->tag == Addr_Undescribed);
50 /* hctxt/tnr/haddr/hszB describe the addr if it is a heap block. */
51 ExeContext* hctxt;
52 UInt tnr;
53 Addr haddr;
54 SizeT hszB;
56 /* First, see if it's in any heap block. Unfortunately this
57 means a linear search through all allocated heap blocks. The
58 assertion says that if it's detected as a heap block, then we
59 must have an allocation context for it, since all heap blocks
60 should have an allocation context. */
61 Bool is_heapblock
62 = HG_(mm_find_containing_block)(
63 &hctxt,
64 &tnr,
65 &haddr,
66 &hszB,
69 if (is_heapblock) {
70 tl_assert(is_heapblock == (hctxt != NULL));
71 ai->tag = Addr_Block;
72 ai->Addr.Block.block_kind = Block_Mallocd;
73 ai->Addr.Block.block_desc = "block";
74 ai->Addr.Block.block_szB = hszB;
75 ai->Addr.Block.rwoffset = (Word)(a) - (Word)(haddr);
76 ai->Addr.Block.allocated_at = hctxt;
77 VG_(initThreadInfo) (&ai->Addr.Block.alloc_tinfo);
78 ai->Addr.Block.alloc_tinfo.tnr = tnr;
79 ai->Addr.Block.freed_at = VG_(null_ExeContext)();;
80 } else {
81 /* No block found. Search a non-heap block description. */
82 VG_(describe_addr) (ep, a, ai);
84 /* In case ai contains a tid, set tnr to the corresponding helgrind
85 thread number. */
86 if (ai->tag == Addr_Stack) {
87 Thread* thr = get_admin_threads();
89 tl_assert(ai->Addr.Stack.tinfo.tid);
90 while (thr) {
91 if (thr->coretid == ai->Addr.Stack.tinfo.tid) {
92 ai->Addr.Stack.tinfo.tnr = thr->errmsg_index;
93 break;
95 thr = thr->admin;
101 Bool HG_(get_and_pp_addrdescr) (DiEpoch ep, Addr addr)
104 Bool ret;
105 AddrInfo glai;
107 glai.tag = Addr_Undescribed;
108 HG_(describe_addr) (ep, addr, &glai);
109 VG_(pp_addrinfo) (addr, &glai);
110 ret = glai.tag != Addr_Unknown;
112 VG_(clear_addrinfo) (&glai);
114 return ret;
117 /*--------------------------------------------------------------------*/
118 /*--- end hg_addrdescr.c ---*/
119 /*--------------------------------------------------------------------*/