Home | History | Annotate | Download | only in m_debuginfo
      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-2012 OpenWorks LLP
     11       info (at) 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_TyPtr,    /* pointer type */
     49       Te_TyRef,    /* reference type */
     50       Te_TyPtrMbr, /* pointer to member type */
     51       Te_TyRvalRef,/* rvalue reference type */
     52       Te_TyTyDef,  /* a renaming of some other type */
     53       Te_TyStOrUn, /* structure or union type */
     54       Te_TyEnum,   /* an enum type */
     55       Te_TyArray,  /* an array type */
     56       Te_TyFn,     /* function type */
     57       Te_TyQual,   /* qualified type */
     58       Te_TyVoid    /* void type */
     59    }
     60    TyEntTag;
     61 
     62 /* Fields ending in "R" are references to other TyEnts.  Fields ending
     63    in "Rs" are XArray*s of references to other TyEnts. */
     64 typedef
     65    struct {
     66       UWord    cuOff;
     67       TyEntTag tag;
     68       union {
     69          struct {
     70          } EMPTY;
     71          struct {
     72             UWord indR;
     73          } INDIR;
     74          struct {
     75          } UNKNOWN;
     76          struct {
     77             UChar* name; /* in mallocville */
     78             Bool   valueKnown; /* atoms w/ unknown value are possible */
     79             Long   value;
     80          } Atom;
     81          struct {
     82             UChar* name;  /* in mallocville */
     83             UWord  typeR; /* should be Te_TyXXXX */
     84             union {
     85                UChar* loc;   /* location expr, in mallocville */
     86                Word offset;  /* or offset from the beginning of containing
     87                                 entity */
     88             } pos;
     89             Word  nLoc;  /* number of bytes in .pos.loc if >= 0, or -1
     90                             if .pos.offset should be used instead */
     91             Bool   isStruct;
     92          } Field;
     93          struct {
     94             Bool knownL;
     95             Bool knownU;
     96             Long boundL;
     97             Long boundU;
     98          } Bound;
     99          struct {
    100             UChar* name; /* in mallocville */
    101             Int    szB;
    102             UChar  enc; /* S:signed U:unsigned F:floating C:complex float */
    103          } TyBase;
    104          struct {
    105             Int   szB;
    106             UWord typeR;
    107          } TyPorR;
    108          struct {
    109             UChar* name;  /* in mallocville */
    110             UWord  typeR; /* MAY BE D3_INVALID_CUOFF, denoting unknown */
    111          } TyTyDef;
    112          struct {
    113             UChar*  name; /* in mallocville */
    114             UWord   szB;
    115             XArray* /* of UWord */ fieldRs;
    116             Bool    complete;
    117             Bool    isStruct;
    118          } TyStOrUn;
    119          struct {
    120             UChar*  name; /* in mallocville */
    121             Int     szB;
    122             XArray* /* of UWord */ atomRs;
    123          } TyEnum;
    124          struct {
    125             UWord   typeR;
    126             XArray* /* of UWord */ boundRs;
    127          } TyArray;
    128          struct {
    129          } TyFn;
    130          struct {
    131             UChar qual; /* C:const V:volatile */
    132             UWord typeR;
    133          } TyQual;
    134          struct {
    135             Bool isFake; /* True == introduced by the reader */
    136          } TyVoid;
    137       } Te;
    138    }
    139    TyEnt;
    140 
    141 /* Does this TyEnt denote a type, as opposed to some other kind of
    142    thing? */
    143 Bool ML_(TyEnt__is_type)( TyEnt* );
    144 
    145 /* Print a TyEnt, debug-style. */
    146 void ML_(pp_TyEnt)( TyEnt* );
    147 
    148 /* Print a whole XArray of TyEnts, debug-style */
    149 void ML_(pp_TyEnts)( XArray* tyents, HChar* who );
    150 
    151 /* Print a TyEnt, C style, chasing stuff as necessary. */
    152 void ML_(pp_TyEnt_C_ishly)( XArray* /* of TyEnt */ tyents,
    153                             UWord cuOff );
    154 
    155 /* Generates a total ordering on TyEnts based only on their .cuOff
    156    fields. */
    157 Word ML_(TyEnt__cmp_by_cuOff_only) ( TyEnt* te1, TyEnt* te2 );
    158 
    159 /* Generates a total ordering on TyEnts based on everything except
    160    their .cuOff fields. */
    161 Word ML_(TyEnt__cmp_by_all_except_cuOff) ( TyEnt* te1, TyEnt* te2 );
    162 
    163 /* Free up all directly or indirectly heap-allocated stuff attached to
    164    this TyEnt, and set its tag to Te_EMPTY.  The .cuOff field is
    165    unchanged. */
    166 void ML_(TyEnt__make_EMPTY) ( TyEnt* te );
    167 
    168 /* How big is this type?  If .b in the returned struct is False, the
    169    size is unknown. */
    170 
    171 MaybeULong ML_(sizeOfType)( XArray* /* of TyEnt */ tyents,
    172                             UWord cuOff );
    173 
    174 /* Describe where in the type 'offset' falls.  Caller must
    175    deallocate the resulting XArray. */
    176 XArray* /*UChar*/ ML_(describe_type)( /*OUT*/PtrdiffT* residual_offset,
    177                                       XArray* /* of TyEnt */ tyents,
    178                                       UWord ty_cuOff,
    179                                       PtrdiffT offset );
    180 
    181 
    182 /* A fast-lookup cache for ML_(TyEnts__index_by_cuOff).  Nothing
    183    particularly surprising here; it's 2 way set associative, with some
    184    number of ways, doesn't particularly have to be a power of 2.  In
    185    order to have a way to indicate an invalid entry, we set the second
    186    value of the pair to NULL, and keep checking for it, since
    187    unfortunately there's no obvious cuOff number that we could put in
    188    the first word of the pair that could indicate an invalid entry.
    189 
    190    4096 arrived at as the best value for an E6600 loading Qt-4.4.1
    191    Designer and all associated libraries, compiled by gcc-4.3.1,
    192    -g -O, 64-bit, which is at least a moderately good stress test,
    193    with the largest library being about 150MB.*/
    194 
    195 #define N_TYENT_INDEX_CACHE 4096
    196 
    197 typedef
    198    struct {
    199       struct { UWord cuOff0; TyEnt* ent0;
    200                UWord cuOff1; TyEnt* ent1; }
    201          ce[N_TYENT_INDEX_CACHE];
    202    }
    203    TyEntIndexCache;
    204 
    205 void ML_(TyEntIndexCache__invalidate) ( TyEntIndexCache* cache );
    206 
    207 /* 'ents' is an XArray of TyEnts, sorted by their .cuOff fields.  Find
    208    the entry which has .cuOff field as specified.  Returns NULL if not
    209    found.  Asserts if more than one entry has the specified .cuOff
    210    value. */
    211 TyEnt* ML_(TyEnts__index_by_cuOff) ( XArray* /* of TyEnt */ ents,
    212                                      TyEntIndexCache* cache,
    213                                      UWord cuOff_to_find );
    214 
    215 #endif /* ndef __PRIV_TYTYPES_H */
    216 
    217 /*--------------------------------------------------------------------*/
    218 /*--- end                                           priv_tytypes.h ---*/
    219 /*--------------------------------------------------------------------*/
    220