blob: 319ea8e950e3df2678bb825dd2fa712659807c5d [file] [log] [blame]
philippef5774342014-05-03 11:12:50 +00001
2/*---------------------------------------------------------------------*/
3/*--- Address Description, used e.g. to describe addresses involved ---*/
4/*--- in race conditions, locks. ---*/
5/*--- hg_addrdescr.h ---*/
6/*---------------------------------------------------------------------*/
7
8/*
9 This file is part of Helgrind, a Valgrind tool for detecting errors
10 in threaded programs.
11
12 Copyright (C) 2007-2012 OpenWorks Ltd
13 info@open-works.co.uk
14
15 This program is free software; you can redistribute it and/or
16 modify it under the terms of the GNU General Public License as
17 published by the Free Software Foundation; either version 2 of the
18 License, or (at your option) any later version.
19
20 This program is distributed in the hope that it will be useful, but
21 WITHOUT ANY WARRANTY; without even the implied warranty of
22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23 General Public License for more details.
24
25 You should have received a copy of the GNU General Public License
26 along with this program; if not, write to the Free Software
27 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
28 02111-1307, USA.
29
30 The GNU General Public License is contained in the file COPYING.
31*/
32
33#ifndef __HG_ADDRDESCR_H
34#define __HG_ADDRDESCR_H
35
36/*----------------------------------------------------------------*/
37/*--- Address Description ---*/
38/*--- Used e.g. to describe an address in a Race cond. error ---*/
39/*--- or a lock. ---*/
40/*----------------------------------------------------------------*/
41typedef
42 struct {
43 /* descr1/2 provide a description of stack/global locs */
44 XArray* descr1; /* XArray* of HChar */
45 XArray* descr2; /* XArray* of HChar */
46 /* hctxt/haddr/hszB describe the addr if it is a heap block. */
47 ExeContext* hctxt;
48 Addr haddr;
49 SizeT hszB;
50 }
51 AddrDescr;
52
53/* Initialises an empty AddrDescr. */
54void HG_(init_AddrDescr) ( AddrDescr* ad );
55
56/* Describe an address as best you can, for error messages or
57 lock description, putting the result in ad.
58 This allocates some memory in ad, to be cleared with VG_(clear_addrdesc). */
59extern void HG_(describe_addr) ( Addr a, /*OUT*/AddrDescr* ad );
60
61/* Prints (using *print) the readable description of addr given in ad.
62 "what" identifies the type pointed to by addr (e.g. a lock). */
63extern void HG_(pp_addrdescr) (Bool xml, const HChar* what, Addr addr,
64 AddrDescr* ad,
65 void(*print)(const HChar *format, ...));
66
67/* Get a readable description of addr, then print it using HG_(pp_addrdescr)
68 using xml False and VG_(printf) to emit the characters.
69 Returns True if a description was found/printed, False otherwise. */
70extern Bool HG_(get_and_pp_addrdescr) (const HChar* what, Addr a);
71
72/* Free all memory allocated by HG_(describe_addr)
73 Sets all elements of ad to 0/NULL. */
74extern void HG_(clear_addrdesc) ( AddrDescr* ad);
75
76/* For error creation/address description:
77 map 'data_addr' to a malloc'd chunk, if any.
78 Slow linear search accelerated in some special cases normal hash
79 search of the mallocmeta table. This is an abuse of the normal file
80 structure since this is exported by hg_main.c, not hg_addrdesc.c. Oh
81 Well. Returns True if found, False if not. Zero-sized blocks are
82 considered to contain the searched-for address if they equal that
83 address. */
84Bool HG_(mm_find_containing_block)( /*OUT*/ExeContext** where,
85 /*OUT*/Addr* payload,
86 /*OUT*/SizeT* szB,
87 Addr data_addr );
88
89
90#endif /* ! __HG_ADDRDESCR_H */
91
92/*--------------------------------------------------------------------*/
93/*--- end hg_addrdescr.h ---*/
94/*--------------------------------------------------------------------*/