Home | History | Annotate | Download | only in m_debuginfo
      1 
      2 /*--------------------------------------------------------------------*/
      3 /*--- Format-neutral storage of and querying of info acquired from ---*/
      4 /*--- ELF/XCOFF stabs/dwarf1/dwarf2 debug info.                    ---*/
      5 /*---                                               priv_storage.h ---*/
      6 /*--------------------------------------------------------------------*/
      7 
      8 /*
      9    This file is part of Valgrind, a dynamic binary instrumentation
     10    framework.
     11 
     12    Copyright (C) 2000-2010 Julian Seward
     13       jseward (at) acm.org
     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    Stabs reader greatly improved by Nick Nethercote, Apr 02.
     34    This module was also extensively hacked on by Jeremy Fitzhardinge
     35    and Tom Hughes.
     36 */
     37 /* See comment at top of debuginfo.c for explanation of
     38    the _svma / _avma / _image / _bias naming scheme.
     39 */
     40 /* Note this is not freestanding; needs pub_core_xarray.h and
     41    priv_tytypes.h to be included before it. */
     42 
     43 #ifndef __PRIV_STORAGE_H
     44 #define __PRIV_STORAGE_H
     45 
     46 /* --------------------- SYMBOLS --------------------- */
     47 
     48 /* A structure to hold an ELF/XCOFF symbol (very crudely). */
     49 typedef
     50    struct {
     51       Addr  addr;    /* lowest address of entity */
     52       Addr  tocptr;  /* ppc64-linux only: value that R2 should have */
     53       UChar *name;   /* name */
     54       // XXX: this could be shrunk (on 32-bit platforms) by using 31 bits for
     55       // the size and 1 bit for the isText.  If you do this, make sure that
     56       // all assignments to isText use 0 or 1 (or True or False), and that a
     57       // positive number larger than 1 is never used to represent True.
     58       UInt  size;    /* size in bytes */
     59       Bool  isText;
     60       Bool  isIFunc; /* symbol is an indirect function? */
     61    }
     62    DiSym;
     63 
     64 /* --------------------- SRCLOCS --------------------- */
     65 
     66 /* Line count at which overflow happens, due to line numbers being
     67    stored as shorts in `struct nlist' in a.out.h. */
     68 #define LINENO_OVERFLOW (1 << (sizeof(short) * 8))
     69 
     70 #define LINENO_BITS     20
     71 #define LOC_SIZE_BITS  (32 - LINENO_BITS)
     72 #define MAX_LINENO     ((1 << LINENO_BITS) - 1)
     73 
     74 /* Unlikely to have any lines with instruction ranges > 4096 bytes */
     75 #define MAX_LOC_SIZE   ((1 << LOC_SIZE_BITS) - 1)
     76 
     77 /* Number used to detect line number overflows; if one line is
     78    60000-odd smaller than the previous, it was probably an overflow.
     79  */
     80 #define OVERFLOW_DIFFERENCE     (LINENO_OVERFLOW - 5000)
     81 
     82 /* A structure to hold addr-to-source info for a single line.  There
     83   can be a lot of these, hence the dense packing. */
     84 typedef
     85    struct {
     86       /* Word 1 */
     87       Addr   addr;               /* lowest address for this line */
     88       /* Word 2 */
     89       UShort size:LOC_SIZE_BITS; /* # bytes; we catch overflows of this */
     90       UInt   lineno:LINENO_BITS; /* source line number, or zero */
     91       /* Word 3 */
     92       UChar*  filename;          /* source filename */
     93       /* Word 4 */
     94       UChar*  dirname;           /* source directory name */
     95    }
     96    DiLoc;
     97 
     98 /* --------------------- CF INFO --------------------- */
     99 
    100 /* DiCfSI: a structure to summarise DWARF2/3 CFA info for the code
    101    address range [base .. base+len-1].
    102 
    103    On x86 and amd64 ("IA"), if you know ({e,r}sp, {e,r}bp, {e,r}ip) at
    104    some point and {e,r}ip is in the range [base .. base+len-1], it
    105    tells you how to calculate ({e,r}sp, {e,r}bp) for the caller of the
    106    current frame and also ra, the return address of the current frame.
    107 
    108    First off, calculate CFA, the Canonical Frame Address, thusly:
    109 
    110      cfa = case cfa_how of
    111               CFIC_IA_SPREL -> {e,r}sp + cfa_off
    112               CFIC_IA_BPREL -> {e,r}bp + cfa_off
    113               CFIR_IA_EXPR  -> expr whose index is in cfa_off
    114 
    115    Once that is done, the previous frame's {e,r}sp/{e,r}bp values and
    116    this frame's {e,r}ra value can be calculated like this:
    117 
    118      old_{e,r}sp/{e,r}bp/ra
    119          = case {e,r}sp/{e,r}bp/ra_how of
    120               CFIR_UNKNOWN   -> we don't know, sorry
    121               CFIR_SAME      -> same as it was before (sp/fp only)
    122               CFIR_CFAREL    -> cfa + sp/bp/ra_off
    123               CFIR_MEMCFAREL -> *( cfa + sp/bp/ra_off )
    124               CFIR_EXPR      -> expr whose index is in sp/bp/ra_off
    125 
    126    On ARM it's pretty much the same, except we have more registers to
    127    keep track of:
    128 
    129      cfa = case cfa_how of
    130               CFIC_R13REL -> r13 + cfa_off
    131               CFIC_R12REL -> r12 + cfa_off
    132               CFIC_R11REL -> r11 + cfa_off
    133               CFIC_R7REL  -> r7  + cfa_off
    134               CFIR_EXPR   -> expr whose index is in cfa_off
    135 
    136      old_r14/r13/r12/r11/r7/ra
    137          = case r14/r13/r12/r11/r7/ra_how of
    138               CFIR_UNKNOWN   -> we don't know, sorry
    139               CFIR_SAME      -> same as it was before (r14/r13/r12/r11/r7 only)
    140               CFIR_CFAREL    -> cfa + r14/r13/r12/r11/r7/ra_off
    141               CFIR_MEMCFAREL -> *( cfa + r14/r13/r12/r11/r7/ra_off )
    142               CFIR_EXPR      -> expr whose index is in r14/r13/r12/r11/r7/ra_off
    143 */
    144 
    145 #define CFIC_IA_SPREL     ((UChar)1)
    146 #define CFIC_IA_BPREL     ((UChar)2)
    147 #define CFIC_IA_EXPR      ((UChar)3)
    148 #define CFIC_ARM_R13REL   ((UChar)4)
    149 #define CFIC_ARM_R12REL   ((UChar)5)
    150 #define CFIC_ARM_R11REL   ((UChar)6)
    151 #define CFIC_ARM_R7REL    ((UChar)7)
    152 #define CFIC_EXPR         ((UChar)8)  /* all targets */
    153 
    154 #define CFIR_UNKNOWN      ((UChar)64)
    155 #define CFIR_SAME         ((UChar)65)
    156 #define CFIR_CFAREL       ((UChar)66)
    157 #define CFIR_MEMCFAREL    ((UChar)67)
    158 #define CFIR_EXPR         ((UChar)68)
    159 
    160 #if defined(VGA_x86) || defined(VGA_amd64)
    161 typedef
    162    struct {
    163       Addr  base;
    164       UInt  len;
    165       UChar cfa_how; /* a CFIC_IA value */
    166       UChar ra_how;  /* a CFIR_ value */
    167       UChar sp_how;  /* a CFIR_ value */
    168       UChar bp_how;  /* a CFIR_ value */
    169       Int   cfa_off;
    170       Int   ra_off;
    171       Int   sp_off;
    172       Int   bp_off;
    173    }
    174    DiCfSI;
    175 #elif defined(VGA_arm)
    176 typedef
    177    struct {
    178       Addr  base;
    179       UInt  len;
    180       UChar cfa_how; /* a CFIC_ value */
    181       UChar ra_how;  /* a CFIR_ value */
    182       UChar r14_how; /* a CFIR_ value */
    183       UChar r13_how; /* a CFIR_ value */
    184       UChar r12_how; /* a CFIR_ value */
    185       UChar r11_how; /* a CFIR_ value */
    186       UChar r7_how;  /* a CFIR_ value */
    187       Int   cfa_off;
    188       Int   ra_off;
    189       Int   r14_off;
    190       Int   r13_off;
    191       Int   r12_off;
    192       Int   r11_off;
    193       Int   r7_off;
    194    }
    195    DiCfSI;
    196 #elif defined(VGA_ppc32) || defined(VGA_ppc64)
    197 /* Just have a struct with the common fields in, so that code that
    198    processes the common fields doesn't have to be ifdef'd against
    199    VGP_/VGA_ symbols.  These are not used in any way on ppc32/64-linux
    200    at the moment. */
    201 typedef
    202    struct {
    203       Addr  base;
    204       UInt  len;
    205       UChar cfa_how; /* a CFIC_ value */
    206       UChar ra_how;  /* a CFIR_ value */
    207       Int   cfa_off;
    208       Int   ra_off;
    209    }
    210    DiCfSI;
    211 #else
    212 #  error "Unknown arch"
    213 #endif
    214 
    215 
    216 typedef
    217    enum {
    218       Cop_Add=0x321,
    219       Cop_Sub,
    220       Cop_And,
    221       Cop_Mul
    222    }
    223    CfiOp;
    224 
    225 typedef
    226    enum {
    227       Creg_IA_SP=0x213,
    228       Creg_IA_BP,
    229       Creg_IA_IP,
    230       Creg_ARM_R13,
    231       Creg_ARM_R12,
    232       Creg_ARM_R15,
    233       Creg_ARM_R14
    234    }
    235    CfiReg;
    236 
    237 typedef
    238    enum {
    239       Cex_Undef=0x123,
    240       Cex_Deref,
    241       Cex_Const,
    242       Cex_Binop,
    243       Cex_CfiReg,
    244       Cex_DwReg
    245    }
    246    CfiExprTag;
    247 
    248 typedef
    249    struct {
    250       CfiExprTag tag;
    251       union {
    252          struct {
    253          } Undef;
    254          struct {
    255             Int ixAddr;
    256          } Deref;
    257          struct {
    258             UWord con;
    259          } Const;
    260          struct {
    261             CfiOp op;
    262             Int ixL;
    263             Int ixR;
    264          } Binop;
    265          struct {
    266             CfiReg reg;
    267          } CfiReg;
    268          struct {
    269             Int reg;
    270          } DwReg;
    271       }
    272       Cex;
    273    }
    274    CfiExpr;
    275 
    276 extern Int ML_(CfiExpr_Undef) ( XArray* dst );
    277 extern Int ML_(CfiExpr_Deref) ( XArray* dst, Int ixAddr );
    278 extern Int ML_(CfiExpr_Const) ( XArray* dst, UWord con );
    279 extern Int ML_(CfiExpr_Binop) ( XArray* dst, CfiOp op, Int ixL, Int ixR );
    280 extern Int ML_(CfiExpr_CfiReg)( XArray* dst, CfiReg reg );
    281 extern Int ML_(CfiExpr_DwReg) ( XArray* dst, Int reg );
    282 
    283 extern void ML_(ppCfiExpr)( XArray* src, Int ix );
    284 
    285 /* ---------------- FPO INFO (Windows PE) -------------- */
    286 
    287 /* for apps using Wine: MSVC++ PDB FramePointerOmitted: somewhat like
    288    a primitive CFI */
    289 typedef
    290    struct _FPO_DATA {  /* 16 bytes */
    291       UInt   ulOffStart; /* offset of 1st byte of function code */
    292       UInt   cbProcSize; /* # bytes in function */
    293       UInt   cdwLocals;  /* # bytes/4 in locals */
    294       UShort cdwParams;  /* # bytes/4 in params */
    295       UChar  cbProlog;   /* # bytes in prolog */
    296       UChar  cbRegs :3;  /* # regs saved */
    297       UChar  fHasSEH:1;  /* Structured Exception Handling */
    298       UChar  fUseBP :1;  /* EBP has been used */
    299       UChar  reserved:1;
    300       UChar  cbFrame:2;  /* frame type */
    301    }
    302    FPO_DATA;
    303 
    304 #define PDB_FRAME_FPO  0
    305 #define PDB_FRAME_TRAP 1
    306 #define PDB_FRAME_TSS  2
    307 
    308 /* --------------------- VARIABLES --------------------- */
    309 
    310 typedef
    311    struct {
    312       Addr    aMin;
    313       Addr    aMax;
    314       XArray* /* of DiVariable */ vars;
    315    }
    316    DiAddrRange;
    317 
    318 typedef
    319    struct {
    320       UChar* name;  /* in DebugInfo.strchunks */
    321       UWord  typeR; /* a cuOff */
    322       GExpr* gexpr; /* on DebugInfo.gexprs list */
    323       GExpr* fbGX;  /* SHARED. */
    324       UChar* fileName; /* where declared; may be NULL. in
    325                           DebugInfo.strchunks */
    326       Int    lineNo;   /* where declared; may be zero. */
    327    }
    328    DiVariable;
    329 
    330 Word
    331 ML_(cmp_for_DiAddrRange_range) ( const void* keyV, const void* elemV );
    332 
    333 /* --------------------- DEBUGINFO --------------------- */
    334 
    335 /* This is the top-level data type.  It's a structure which contains
    336    information pertaining to one mapped ELF object.  This type is
    337    exported only abstractly - in pub_tool_debuginfo.h. */
    338 
    339 #define SEGINFO_STRCHUNKSIZE (64*1024)
    340 
    341 struct _DebugInfo {
    342 
    343    /* Admin stuff */
    344 
    345    struct _DebugInfo* next;   /* list of DebugInfos */
    346    Bool               mark;   /* marked for deletion? */
    347 
    348    /* An abstract handle, which can be used by entities outside of
    349       m_debuginfo to (in an abstract datatype sense) refer to this
    350       struct _DebugInfo.  A .handle of zero is invalid; valid handles
    351       are 1 and above.  The same handle is never issued twice (in any
    352       given run of Valgrind), so a handle becomes invalid when the
    353       associated struct _DebugInfo is discarded, and remains invalid
    354       forever thereafter.  The .handle field is set as soon as this
    355       structure is allocated. */
    356    ULong handle;
    357 
    358    /* Used for debugging only - indicate what stuff to dump whilst
    359       reading stuff into the seginfo.  Are computed as early in the
    360       lifetime of the DebugInfo as possible -- at the point when it is
    361       created.  Use these when deciding what to spew out; do not use
    362       the global VG_(clo_blah) flags. */
    363 
    364    Bool trace_symtab; /* symbols, our style */
    365    Bool trace_cfi;    /* dwarf frame unwind, our style */
    366    Bool ddump_syms;   /* mimic /usr/bin/readelf --syms */
    367    Bool ddump_line;   /* mimic /usr/bin/readelf --debug-dump=line */
    368    Bool ddump_frames; /* mimic /usr/bin/readelf --debug-dump=frames */
    369 
    370    /* Fields that must be filled in before we can start reading
    371       anything from the ELF file.  These fields are filled in by
    372       VG_(di_notify_mmap) and its immediate helpers. */
    373 
    374    UChar* filename; /* in mallocville (VG_AR_DINFO) */
    375    UChar* memname;  /* also in VG_AR_DINFO.  AIX5 only: .a member name */
    376 
    377    Bool  have_rx_map; /* did we see a r?x mapping yet for the file? */
    378    Bool  have_rw_map; /* did we see a rw? mapping yet for the file? */
    379 
    380    Addr  rx_map_avma; /* these fields record the file offset, length */
    381    SizeT rx_map_size; /* and map address of the r?x mapping we believe */
    382    OffT  rx_map_foff; /* is the .text segment mapping */
    383 
    384    Addr  rw_map_avma; /* ditto, for the rw? mapping we believe is the */
    385    SizeT rw_map_size; /* .data segment mapping */
    386    OffT  rw_map_foff;
    387 
    388    /* Once both a rw? and r?x mapping for .filename have been
    389       observed, we can go on to read the symbol tables and debug info.
    390       .have_dinfo flags when that has happened. */
    391    /* If have_dinfo is False, then all fields except "*rx_map*" and
    392       "*rw_map*" are invalid and should not be consulted. */
    393    Bool  have_dinfo; /* initially False */
    394 
    395    /* All the rest of the fields in this structure are filled in once
    396       we have committed to reading the symbols and debug info (that
    397       is, at the point where .have_dinfo is set to True). */
    398 
    399    /* The file's soname.  FIXME: ensure this is always allocated in
    400       VG_AR_DINFO. */
    401    UChar* soname;
    402 
    403    /* Description of some important mapped segments.  The presence or
    404       absence of the mapping is denoted by the _present field, since
    405       in some obscure circumstances (to do with data/sdata/bss) it is
    406       possible for the mapping to be present but have zero size.
    407       Certainly text_ is mandatory on all platforms; not sure about
    408       the rest though.
    409 
    410       --------------------------------------------------------
    411 
    412       Comment_on_IMPORTANT_CFSI_REPRESENTATIONAL_INVARIANTS: we require that
    413 
    414       either (rx_map_size == 0 && cfsi == NULL) (the degenerate case)
    415 
    416       or the normal case, which is the AND of the following:
    417       (0) rx_map_size > 0
    418       (1) no two DebugInfos with rx_map_size > 0
    419           have overlapping [rx_map_avma,+rx_map_size)
    420       (2) [cfsi_minavma,cfsi_maxavma] does not extend
    421           beyond [rx_map_avma,+rx_map_size); that is, the former is a
    422           subrange or equal to the latter.
    423       (3) all DiCfSI in the cfsi array all have ranges that fall within
    424           [rx_map_avma,+rx_map_size).
    425       (4) all DiCfSI in the cfsi array are non-overlapping
    426 
    427       The cumulative effect of these restrictions is to ensure that
    428       all the DiCfSI records in the entire system are non overlapping.
    429       Hence any address falls into either exactly one DiCfSI record,
    430       or none.  Hence it is safe to cache the results of searches for
    431       DiCfSI records.  This is the whole point of these restrictions.
    432       The caching of DiCfSI searches is done in VG_(use_CF_info).  The
    433       cache is flushed after any change to debugInfo_list.  DiCfSI
    434       searches are cached because they are central to stack unwinding
    435       on amd64-linux.
    436 
    437       Where are these invariants imposed and checked?
    438 
    439       They are checked after a successful read of debuginfo into
    440       a DebugInfo*, in check_CFSI_related_invariants.
    441 
    442       (1) is not really imposed anywhere.  We simply assume that the
    443       kernel will not map the text segments from two different objects
    444       into the same space.  Sounds reasonable.
    445 
    446       (2) follows from (4) and (3).  It is ensured by canonicaliseCFI.
    447       (3) is ensured by ML_(addDiCfSI).
    448       (4) is ensured by canonicaliseCFI.
    449 
    450       --------------------------------------------------------
    451 
    452       Comment_on_DEBUG_SVMA_and_DEBUG_BIAS_fields:
    453 
    454       The _debug_{svma,bias} fields were added as part of a fix to
    455       #185816.  The problem encompassed in that bug report was that it
    456       wasn't correct to use apply the bias values deduced for a
    457       primary object to its associated debuginfo object, because the
    458       debuginfo object (or the primary) could have been prelinked to a
    459       different SVMA.  Hence debuginfo and primary objects need to
    460       have their own biases.
    461 
    462       ------ JRS: (referring to r9329): ------
    463       Let me see if I understand the workings correctly.  Initially
    464       the _debug_ values are set to the same values as the "normal"
    465       ones, as there's a bunch of bits of code like this (in
    466       readelf.c)
    467 
    468          di->text_svma = svma;
    469          ...
    470          di->text_bias = rx_bias;
    471          di->text_debug_svma = svma;
    472          di->text_debug_bias = rx_bias;
    473 
    474       If a debuginfo object subsequently shows up then the
    475       _debug_svma/bias are set for the debuginfo object.  Result is
    476       that if there's no debuginfo object then the values are the same
    477       as the primary-object values, and if there is a debuginfo object
    478       then they will (or at least may) be different.
    479 
    480       Then when we need to actually bias something, we'll have to
    481       decide whether to use the primary bias or the debuginfo bias.
    482       And the strategy is to use the primary bias for ELF symbols but
    483       the debuginfo bias for anything pulled out of Dwarf.
    484 
    485       ------ THH: ------
    486       Correct - the debug_svma and bias values apply to any address
    487       read from the debug data regardless of where that debug data is
    488       stored and the other values are used for addresses from other
    489       places (primarily the symbol table).
    490 
    491       ------ JRS: ------
    492       Ok; so this was my only area of concern.  Are there any
    493       corner-case scenarios where this wouldn't be right?  It sounds
    494       like we're assuming the ELF symbols come from the primary object
    495       and, if there is a debug object, then all the Dwarf comes from
    496       there.  But what if (eg) both symbols and Dwarf come from the
    497       debug object?  Is that even possible or allowable?
    498 
    499       ------ THH: ------
    500       You may have a point...
    501 
    502       The current logic is to try and take any one set of data from
    503       either the base object or the debug object. There are four sets
    504       of data we consider:
    505 
    506          - Symbol Table
    507          - Stabs
    508          - DWARF1
    509          - DWARF2
    510 
    511       If we see the primary section for a given set in the base object
    512       then we ignore all sections relating to that set in the debug
    513       object.
    514 
    515       Now in principle if we saw a secondary section (like debug_line
    516       say) in the base object, but not the main section (debug_info in
    517       this case) then we would take debug_info from the debug object
    518       but would use the debug_line from the base object unless we saw
    519       a replacement copy in the debug object. That's probably unlikely
    520       however.
    521 
    522       A bigger issue might be, as you say, the symbol table as we will
    523       pick that up from the debug object if it isn't in the base. The
    524       dynamic symbol table will always have to be in the base object
    525       though so we will have to be careful when processing symbols to
    526       know which table we are reading in that case.
    527 
    528       What we probably need to do is tell read_elf_symtab which object
    529       the symbols it is being asked to read came from.
    530 
    531       (A followup patch to deal with this was committed in r9469).
    532    */
    533    /* .text */
    534    Bool     text_present;
    535    Addr     text_avma;
    536    Addr     text_svma;
    537    SizeT    text_size;
    538    PtrdiffT text_bias;
    539    Addr     text_debug_svma;
    540    PtrdiffT text_debug_bias;
    541    /* .data */
    542    Bool     data_present;
    543    Addr     data_svma;
    544    Addr     data_avma;
    545    SizeT    data_size;
    546    PtrdiffT data_bias;
    547    Addr     data_debug_svma;
    548    PtrdiffT data_debug_bias;
    549    /* .sdata */
    550    Bool     sdata_present;
    551    Addr     sdata_svma;
    552    Addr     sdata_avma;
    553    SizeT    sdata_size;
    554    PtrdiffT sdata_bias;
    555    Addr     sdata_debug_svma;
    556    PtrdiffT sdata_debug_bias;
    557    /* .rodata */
    558    Bool     rodata_present;
    559    Addr     rodata_svma;
    560    Addr     rodata_avma;
    561    SizeT    rodata_size;
    562    PtrdiffT rodata_bias;
    563    Addr     rodata_debug_svma;
    564    PtrdiffT rodata_debug_bias;
    565    /* .bss */
    566    Bool     bss_present;
    567    Addr     bss_svma;
    568    Addr     bss_avma;
    569    SizeT    bss_size;
    570    PtrdiffT bss_bias;
    571    Addr     bss_debug_svma;
    572    PtrdiffT bss_debug_bias;
    573    /* .sbss */
    574    Bool     sbss_present;
    575    Addr     sbss_svma;
    576    Addr     sbss_avma;
    577    SizeT    sbss_size;
    578    PtrdiffT sbss_bias;
    579    Addr     sbss_debug_svma;
    580    PtrdiffT sbss_debug_bias;
    581    /* .plt */
    582    Bool   plt_present;
    583    Addr	  plt_avma;
    584    SizeT  plt_size;
    585    /* .got */
    586    Bool   got_present;
    587    Addr   got_avma;
    588    SizeT  got_size;
    589    /* .got.plt */
    590    Bool   gotplt_present;
    591    Addr   gotplt_avma;
    592    SizeT  gotplt_size;
    593    /* .opd -- needed on ppc64-linux for finding symbols */
    594    Bool   opd_present;
    595    Addr   opd_avma;
    596    SizeT  opd_size;
    597    /* .ehframe -- needed on amd64-linux for stack unwinding */
    598    Bool   ehframe_present;
    599    Addr   ehframe_avma;
    600    SizeT  ehframe_size;
    601 
    602    /* Sorted tables of stuff we snarfed from the file.  This is the
    603       eventual product of reading the debug info.  All this stuff
    604       lives in VG_AR_DINFO. */
    605 
    606    /* An expandable array of symbols. */
    607    DiSym*  symtab;
    608    UWord   symtab_used;
    609    UWord   symtab_size;
    610    /* An expandable array of locations. */
    611    DiLoc*  loctab;
    612    UWord   loctab_used;
    613    UWord   loctab_size;
    614    /* An expandable array of CFI summary info records.  Also includes
    615       summary address bounds, showing the min and max address covered
    616       by any of the records, as an aid to fast searching.  And, if the
    617       records require any expression nodes, they are stored in
    618       cfsi_exprs. */
    619    DiCfSI* cfsi;
    620    UWord   cfsi_used;
    621    UWord   cfsi_size;
    622    Addr    cfsi_minavma;
    623    Addr    cfsi_maxavma;
    624    XArray* cfsi_exprs; /* XArray of CfiExpr */
    625 
    626    /* Optimized code under Wine x86: MSVC++ PDB FramePointerOmitted
    627       data.  Non-expandable array, hence .size == .used. */
    628    FPO_DATA* fpo;
    629    UWord     fpo_size;
    630    Addr      fpo_minavma;
    631    Addr      fpo_maxavma;
    632 
    633    /* Expandable arrays of characters -- the string table.  Pointers
    634       into this are stable (the arrays are not reallocated). */
    635    struct strchunk {
    636       UInt   strtab_used;
    637       struct strchunk* next;
    638       UChar  strtab[SEGINFO_STRCHUNKSIZE];
    639    } *strchunks;
    640 
    641    /* Variable scope information, as harvested from Dwarf3 files.
    642 
    643       In short it's an
    644 
    645          array of (array of PC address ranges and variables)
    646 
    647       The outer array indexes over scopes, with Entry 0 containing
    648       information on variables which exist for any value of the program
    649       counter (PC) -- that is, the outermost scope.  Entries 1, 2, 3,
    650       etc contain information on increasinly deeply nested variables.
    651 
    652       Each inner array is an array of (an address range, and a set
    653       of variables that are in scope over that address range).
    654 
    655       The address ranges may not overlap.
    656 
    657       Since Entry 0 in the outer array holds information on variables
    658       that exist for any value of the PC (that is, global vars), it
    659       follows that Entry 0's inner array can only have one address
    660       range pair, one that covers the entire address space.
    661    */
    662    XArray* /* of OSet of DiAddrRange */varinfo;
    663 
    664    /* These are arrays of the relevant typed objects, held here
    665       partially for the purposes of visiting each object exactly once
    666       when we need to delete them. */
    667 
    668    /* An array of TyEnts.  These are needed to make sense of any types
    669       in the .varinfo.  Also, when deleting this DebugInfo, we must
    670       first traverse this array and throw away malloc'd stuff hanging
    671       off it -- by calling ML_(TyEnt__make_EMPTY) on each entry. */
    672    XArray* /* of TyEnt */ admin_tyents;
    673 
    674    /* An array of guarded DWARF3 expressions. */
    675    XArray* admin_gexprs;
    676 };
    677 
    678 /* --------------------- functions --------------------- */
    679 
    680 /* ------ Adding ------ */
    681 
    682 /* Add a symbol to si's symbol table. */
    683 extern void ML_(addSym) ( struct _DebugInfo* di, DiSym* sym );
    684 
    685 /* Add a line-number record to a DebugInfo. */
    686 extern
    687 void ML_(addLineInfo) ( struct _DebugInfo* di,
    688                         UChar*   filename,
    689                         UChar*   dirname,  /* NULL is allowable */
    690                         Addr this, Addr next, Int lineno, Int entry);
    691 
    692 /* Shrink completed tables to save memory. */
    693 extern
    694 void ML_(shrinkSym) ( struct _DebugInfo *di );
    695 extern
    696 void ML_(shrinkLineInfo) ( struct _DebugInfo *di );
    697 
    698 /* Add a CFI summary record.  The supplied DiCfSI is copied. */
    699 extern void ML_(addDiCfSI) ( struct _DebugInfo* di, DiCfSI* cfsi );
    700 
    701 /* Add a string to the string table of a DebugInfo.  If len==-1,
    702    ML_(addStr) will itself measure the length of the string. */
    703 extern UChar* ML_(addStr) ( struct _DebugInfo* di, UChar* str, Int len );
    704 
    705 extern void ML_(addVar)( struct _DebugInfo* di,
    706                          Int    level,
    707                          Addr   aMin,
    708                          Addr   aMax,
    709                          UChar* name,
    710                          UWord  typeR, /* a cuOff */
    711                          GExpr* gexpr,
    712                          GExpr* fbGX, /* SHARED. */
    713                          UChar* fileName, /* where decl'd - may be NULL */
    714                          Int    lineNo, /* where decl'd - may be zero */
    715                          Bool   show );
    716 
    717 /* Canonicalise the tables held by 'di', in preparation for use.  Call
    718    this after finishing adding entries to these tables. */
    719 extern void ML_(canonicaliseTables) ( struct _DebugInfo* di );
    720 
    721 /* Canonicalise the call-frame-info table held by 'di', in preparation
    722    for use. This is called by ML_(canonicaliseTables) but can also be
    723    called on it's own to sort just this table. */
    724 extern void ML_(canonicaliseCFI) ( struct _DebugInfo* di );
    725 
    726 /* ------ Searching ------ */
    727 
    728 /* Find a symbol-table index containing the specified pointer, or -1
    729    if not found.  Binary search.  */
    730 extern Word ML_(search_one_symtab) ( struct _DebugInfo* di, Addr ptr,
    731                                      Bool match_anywhere_in_sym,
    732                                      Bool findText );
    733 
    734 /* Find a location-table index containing the specified pointer, or -1
    735    if not found.  Binary search.  */
    736 extern Word ML_(search_one_loctab) ( struct _DebugInfo* di, Addr ptr );
    737 
    738 /* Find a CFI-table index containing the specified pointer, or -1 if
    739    not found.  Binary search.  */
    740 extern Word ML_(search_one_cfitab) ( struct _DebugInfo* di, Addr ptr );
    741 
    742 /* Find a FPO-table index containing the specified pointer, or -1
    743    if not found.  Binary search.  */
    744 extern Word ML_(search_one_fpotab) ( struct _DebugInfo* di, Addr ptr );
    745 
    746 /* ------ Misc ------ */
    747 
    748 /* Show a non-fatal debug info reading error.  Use vg_panic if
    749    terminal.  'serious' errors are always shown, not 'serious' ones
    750    are shown only at verbosity level 2 and above. */
    751 extern
    752 void ML_(symerr) ( struct _DebugInfo* di, Bool serious, HChar* msg );
    753 
    754 /* Print a symbol. */
    755 extern void ML_(ppSym) ( Int idx, DiSym* sym );
    756 
    757 /* Print a call-frame-info summary. */
    758 extern void ML_(ppDiCfSI) ( XArray* /* of CfiExpr */ exprs, DiCfSI* si );
    759 
    760 
    761 #define TRACE_SYMTAB(format, args...) \
    762    if (di->trace_symtab) { VG_(printf)(format, ## args); }
    763 
    764 
    765 #endif /* ndef __PRIV_STORAGE_H */
    766 
    767 /*--------------------------------------------------------------------*/
    768 /*--- end                                                          ---*/
    769 /*--------------------------------------------------------------------*/
    770