• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 
2 /*--------------------------------------------------------------------*/
3 /*--- Representation of source level types.         priv_tytypes.h ---*/
4 /*--------------------------------------------------------------------*/
5 
6 /*
7    This file is part of Valgrind, a dynamic binary instrumentation
8    framework.
9 
10    Copyright (C) 2008-2011 OpenWorks LLP
11       info@open-works.co.uk
12 
13    This program is free software; you can redistribute it and/or
14    modify it under the terms of the GNU General Public License as
15    published by the Free Software Foundation; either version 2 of the
16    License, or (at your option) any later version.
17 
18    This program is distributed in the hope that it will be useful, but
19    WITHOUT ANY WARRANTY; without even the implied warranty of
20    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
21    General Public License for more details.
22 
23    You should have received a copy of the GNU General Public License
24    along with this program; if not, write to the Free Software
25    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
26    02111-1307, USA.
27 
28    The GNU General Public License is contained in the file COPYING.
29 
30    Neither the names of the U.S. Department of Energy nor the
31    University of California nor the names of its contributors may be
32    used to endorse or promote products derived from this software
33    without prior written permission.
34 */
35 
36 #ifndef __PRIV_TYTYPES_H
37 #define __PRIV_TYTYPES_H
38 
39 typedef
40    enum {
41       Te_EMPTY=10, /* empty (contains no info) */
42       Te_INDIR,    /* indirection to some other TyEnt */
43       Te_UNKNOWN,  /* denotes a unknown type/field/whatever */
44       Te_Atom,     /* name & 64-bit const, iow, enumeration member */
45       Te_Field,    /* struct/class field defn */
46       Te_Bound,    /* array bounds indication, for one dimension */
47       Te_TyBase,   /* base type */
48       Te_TyPorR,   /* pointer or reference type */
49       Te_TyTyDef,  /* a renaming of some other type */
50       Te_TyStOrUn, /* structure or union type */
51       Te_TyEnum,   /* an enum type */
52       Te_TyArray,  /* an array type */
53       Te_TyFn,     /* function type */
54       Te_TyQual,   /* qualified type */
55       Te_TyVoid    /* void type */
56    }
57    TyEntTag;
58 
59 /* Fields ending in "R" are references to other TyEnts.  Fields ending
60    in "Rs" are XArray*s of references to other TyEnts. */
61 typedef
62    struct {
63       UWord    cuOff;
64       TyEntTag tag;
65       union {
66          struct {
67          } EMPTY;
68          struct {
69             UWord indR;
70          } INDIR;
71          struct {
72          } UNKNOWN;
73          struct {
74             UChar* name; /* in mallocville */
75             Bool   valueKnown; /* atoms w/ unknown value are possible */
76             Long   value;
77          } Atom;
78          struct {
79             UChar* name;  /* in mallocville */
80             UWord  typeR; /* should be Te_TyXXXX */
81             union {
82                UChar* loc;   /* location expr, in mallocville */
83                Word offset;  /* or offset from the beginning of containing
84                                 entity */
85             } pos;
86             Word  nLoc;  /* number of bytes in .pos.loc if >= 0, or -1
87                             if .pos.offset should be used instead */
88             Bool   isStruct;
89          } Field;
90          struct {
91             Bool knownL;
92             Bool knownU;
93             Long boundL;
94             Long boundU;
95          } Bound;
96          struct {
97             UChar* name; /* in mallocville */
98             Int    szB;
99             UChar  enc; /* S:signed U:unsigned F:floating C:complex float */
100          } TyBase;
101          struct {
102             Int   szB;
103             UWord typeR;
104             Bool  isPtr;
105          } TyPorR;
106          struct {
107             UChar* name;  /* in mallocville */
108             UWord  typeR; /* MAY BE D3_INVALID_CUOFF, denoting unknown */
109          } TyTyDef;
110          struct {
111             UChar*  name; /* in mallocville */
112             UWord   szB;
113             XArray* /* of UWord */ fieldRs;
114             Bool    complete;
115             Bool    isStruct;
116          } TyStOrUn;
117          struct {
118             UChar*  name; /* in mallocville */
119             Int     szB;
120             XArray* /* of UWord */ atomRs;
121          } TyEnum;
122          struct {
123             UWord   typeR;
124             XArray* /* of UWord */ boundRs;
125          } TyArray;
126          struct {
127          } TyFn;
128          struct {
129             UChar qual; /* C:const V:volatile */
130             UWord typeR;
131          } TyQual;
132          struct {
133             Bool isFake; /* True == introduced by the reader */
134          } TyVoid;
135       } Te;
136    }
137    TyEnt;
138 
139 /* Does this TyEnt denote a type, as opposed to some other kind of
140    thing? */
141 Bool ML_(TyEnt__is_type)( TyEnt* );
142 
143 /* Print a TyEnt, debug-style. */
144 void ML_(pp_TyEnt)( TyEnt* );
145 
146 /* Print a whole XArray of TyEnts, debug-style */
147 void ML_(pp_TyEnts)( XArray* tyents, HChar* who );
148 
149 /* Print a TyEnt, C style, chasing stuff as necessary. */
150 void ML_(pp_TyEnt_C_ishly)( XArray* /* of TyEnt */ tyents,
151                             UWord cuOff );
152 
153 /* Generates a total ordering on TyEnts based only on their .cuOff
154    fields. */
155 Word ML_(TyEnt__cmp_by_cuOff_only) ( TyEnt* te1, TyEnt* te2 );
156 
157 /* Generates a total ordering on TyEnts based on everything except
158    their .cuOff fields. */
159 Word ML_(TyEnt__cmp_by_all_except_cuOff) ( TyEnt* te1, TyEnt* te2 );
160 
161 /* Free up all directly or indirectly heap-allocated stuff attached to
162    this TyEnt, and set its tag to Te_EMPTY.  The .cuOff field is
163    unchanged. */
164 void ML_(TyEnt__make_EMPTY) ( TyEnt* te );
165 
166 /* How big is this type?  If .b in the returned struct is False, the
167    size is unknown. */
168 
169 MaybeULong ML_(sizeOfType)( XArray* /* of TyEnt */ tyents,
170                             UWord cuOff );
171 
172 /* Describe where in the type 'offset' falls.  Caller must
173    deallocate the resulting XArray. */
174 XArray* /*UChar*/ ML_(describe_type)( /*OUT*/PtrdiffT* residual_offset,
175                                       XArray* /* of TyEnt */ tyents,
176                                       UWord ty_cuOff,
177                                       PtrdiffT offset );
178 
179 
180 /* A fast-lookup cache for ML_(TyEnts__index_by_cuOff).  Nothing
181    particularly surprising here; it's 2 way set associative, with some
182    number of ways, doesn't particularly have to be a power of 2.  In
183    order to have a way to indicate an invalid entry, we set the second
184    value of the pair to NULL, and keep checking for it, since
185    unfortunately there's no obvious cuOff number that we could put in
186    the first word of the pair that could indicate an invalid entry.
187 
188    4096 arrived at as the best value for an E6600 loading Qt-4.4.1
189    Designer and all associated libraries, compiled by gcc-4.3.1,
190    -g -O, 64-bit, which is at least a moderately good stress test,
191    with the largest library being about 150MB.*/
192 
193 #define N_TYENT_INDEX_CACHE 4096
194 
195 typedef
196    struct {
197       struct { UWord cuOff0; TyEnt* ent0;
198                UWord cuOff1; TyEnt* ent1; }
199          ce[N_TYENT_INDEX_CACHE];
200    }
201    TyEntIndexCache;
202 
203 void ML_(TyEntIndexCache__invalidate) ( TyEntIndexCache* cache );
204 
205 /* 'ents' is an XArray of TyEnts, sorted by their .cuOff fields.  Find
206    the entry which has .cuOff field as specified.  Returns NULL if not
207    found.  Asserts if more than one entry has the specified .cuOff
208    value. */
209 TyEnt* ML_(TyEnts__index_by_cuOff) ( XArray* /* of TyEnt */ ents,
210                                      TyEntIndexCache* cache,
211                                      UWord cuOff_to_find );
212 
213 #endif /* ndef __PRIV_TYTYPES_H */
214 
215 /*--------------------------------------------------------------------*/
216 /*--- end                                           priv_tytypes.h ---*/
217 /*--------------------------------------------------------------------*/
218