njn | 4bbdc97 | 2003-10-16 10:10:55 +0000 | [diff] [blame] | 1 | /*--------------------------------------------------------------------*/ |
| 2 | /*--- Header for symbol table stuff. vg_symtab2.h ---*/ |
| 3 | /*--------------------------------------------------------------------*/ |
| 4 | |
| 5 | /* |
njn | b9c427c | 2004-12-01 14:14:42 +0000 | [diff] [blame] | 6 | This file is part of Valgrind, a dynamic binary instrumentation |
| 7 | framework. |
njn | 4bbdc97 | 2003-10-16 10:10:55 +0000 | [diff] [blame] | 8 | |
njn | 5361242 | 2005-03-12 16:22:54 +0000 | [diff] [blame] | 9 | Copyright (C) 2000-2005 Julian Seward |
njn | 4bbdc97 | 2003-10-16 10:10:55 +0000 | [diff] [blame] | 10 | jseward@acm.org |
| 11 | |
| 12 | This program is free software; you can redistribute it and/or |
| 13 | modify it under the terms of the GNU General Public License as |
| 14 | published by the Free Software Foundation; either version 2 of the |
| 15 | License, or (at your option) any later version. |
| 16 | |
| 17 | This program is distributed in the hope that it will be useful, but |
| 18 | WITHOUT ANY WARRANTY; without even the implied warranty of |
| 19 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 20 | General Public License for more details. |
| 21 | |
| 22 | You should have received a copy of the GNU General Public License |
| 23 | along with this program; if not, write to the Free Software |
| 24 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA |
| 25 | 02111-1307, USA. |
| 26 | |
| 27 | The GNU General Public License is contained in the file COPYING. |
| 28 | */ |
jsgf | cb1d1c0 | 2003-10-14 21:55:10 +0000 | [diff] [blame] | 29 | |
| 30 | #ifndef _VG_SYMTYPE_H |
| 31 | #define _VG_SYMTYPE_H |
| 32 | |
jsgf | cb1d1c0 | 2003-10-14 21:55:10 +0000 | [diff] [blame] | 33 | #include "vg_symtypes.h" |
| 34 | |
| 35 | /* A structure to hold an ELF symbol (very crudely). */ |
| 36 | typedef |
| 37 | struct { |
| 38 | Addr addr; /* lowest address of entity */ |
| 39 | UInt size; /* size in bytes */ |
| 40 | Char *name; /* name */ |
| 41 | } |
| 42 | RiSym; |
| 43 | |
| 44 | /* Line count at which overflow happens, due to line numbers being stored as |
| 45 | * shorts in `struct nlist' in a.out.h. */ |
| 46 | #define LINENO_OVERFLOW (1 << (sizeof(short) * 8)) |
| 47 | |
| 48 | #define LINENO_BITS 20 |
| 49 | #define LOC_SIZE_BITS (32 - LINENO_BITS) |
| 50 | #define MAX_LINENO ((1 << LINENO_BITS) - 1) |
| 51 | |
| 52 | /* Unlikely to have any lines with instruction ranges > 4096 bytes */ |
| 53 | #define MAX_LOC_SIZE ((1 << LOC_SIZE_BITS) - 1) |
| 54 | |
| 55 | /* Number used to detect line number overflows; if one line is 60000-odd |
| 56 | * smaller than the previous, is was probably an overflow. |
| 57 | */ |
| 58 | #define OVERFLOW_DIFFERENCE (LINENO_OVERFLOW - 5000) |
| 59 | |
| 60 | /* A structure to hold addr-to-source info for a single line. There can be a |
| 61 | * lot of these, hence the dense packing. */ |
| 62 | typedef |
| 63 | struct { |
| 64 | /* Word 1 */ |
| 65 | Addr addr; /* lowest address for this line */ |
| 66 | /* Word 2 */ |
| 67 | UShort size:LOC_SIZE_BITS; /* byte size; we catch overflows of this */ |
| 68 | UInt lineno:LINENO_BITS; /* source line number, or zero */ |
| 69 | /* Word 3 */ |
| 70 | Char* filename; /* source filename */ |
| 71 | } |
| 72 | RiLoc; |
| 73 | |
| 74 | |
| 75 | /* A structure to hold a set of variables in a particular scope */ |
| 76 | typedef struct _Scope Scope; /* a set of symbols in one scope */ |
| 77 | typedef struct _Sym Sym; /* a single symbol */ |
| 78 | typedef struct _ScopeRange ScopeRange; /* a range of code addreses a scope covers */ |
| 79 | |
| 80 | typedef enum { |
| 81 | SyESPrel, /* on the stack (relative to ESP) */ |
| 82 | SyEBPrel, /* on the stack (relative to EBP) */ |
| 83 | SyReg, /* in a register */ |
| 84 | SyType, /* a type definition */ |
| 85 | SyStatic, /* a static variable */ |
| 86 | SyGlobal, /* a global variable (XXX any different to static |
| 87 | in an outer scope?) */ |
| 88 | } SyKind; |
| 89 | |
| 90 | struct _Sym { |
| 91 | SymType *type; /* type */ |
| 92 | Char *name; /* name */ |
| 93 | SyKind kind; /* kind of symbol */ |
| 94 | |
| 95 | /* a value, depending on kind */ |
| 96 | union { |
njn | c616819 | 2004-11-29 13:54:10 +0000 | [diff] [blame] | 97 | OffT offset; /* offset on stack (-ve -> ebp; +ve -> esp) */ |
jsgf | cb1d1c0 | 2003-10-14 21:55:10 +0000 | [diff] [blame] | 98 | Int regno; /* register number */ |
| 99 | Addr addr; /* static or global address */ |
mueller | 5ed88f2 | 2004-01-06 16:02:29 +0000 | [diff] [blame] | 100 | } u; |
jsgf | cb1d1c0 | 2003-10-14 21:55:10 +0000 | [diff] [blame] | 101 | }; |
| 102 | |
| 103 | struct _Scope { |
| 104 | Scope *outer; /* outer (containing) scope */ |
| 105 | UInt nsyms; /* number of symbols in this scope */ |
| 106 | UInt depth; /* depth of scope */ |
| 107 | Sym *syms; /* the symbols */ |
| 108 | }; |
| 109 | |
| 110 | /* A structure to map a scope to a range of code addresses; scopes may |
| 111 | be broken into multiple ranges (before and after a nested scope) */ |
| 112 | struct _ScopeRange { |
| 113 | Addr addr; /* start address of this scope */ |
| 114 | Int size; /* length of scope */ |
| 115 | Scope *scope; /* symbols in scope */ |
| 116 | }; |
| 117 | |
| 118 | #define STRCHUNKSIZE (64*1024) |
| 119 | |
sewardj | 5c638c2 | 2005-04-30 07:55:58 +0000 | [diff] [blame] | 120 | |
sewardj | 3516553 | 2005-04-30 18:47:48 +0000 | [diff] [blame] | 121 | /* A structure to summarise CFI summary info for the code address |
| 122 | range [base .. base+len-1]. In short, if you know (sp,fp,ip) at |
| 123 | some point and ip is in the range [base .. base+len-1], it tells |
| 124 | you how to calculate (sp,fp) for the caller of the current |
| 125 | frame and also ra, the return address of the current frame. |
| 126 | |
| 127 | First off, calculate CFA, the Canonical Frame Address, thusly: |
| 128 | |
| 129 | cfa = if cfa_sprel then sp+cfa_off else fp+cfa_off |
| 130 | |
| 131 | Once that is done, the previous frame's sp/fp values and this |
| 132 | frame's ra value can be calculated like this: |
| 133 | |
| 134 | old_sp/fp/ra |
| 135 | = case sp/fp/ra_how of |
| 136 | CFIR_UNKNOWN -> we don't know, sorry |
| 137 | CFIR_SAME -> same as it was before (sp/fp only) |
| 138 | CFIR_CFAREL -> cfa + sp/fp/ra_off |
| 139 | CFIR_MEMCFAREL -> *( cfa + sp/fp/ra_off ) |
| 140 | */ |
| 141 | |
| 142 | #define CFIR_UNKNOWN ((UChar)0) |
| 143 | #define CFIR_SAME ((UChar)1) |
| 144 | #define CFIR_CFAREL ((UChar)2) |
| 145 | #define CFIR_MEMCFAREL ((UChar)3) |
| 146 | |
sewardj | 5c638c2 | 2005-04-30 07:55:58 +0000 | [diff] [blame] | 147 | typedef |
| 148 | struct { |
sewardj | 3516553 | 2005-04-30 18:47:48 +0000 | [diff] [blame] | 149 | Addr base; |
| 150 | UInt len; |
| 151 | Bool cfa_sprel; |
| 152 | UChar ra_how; /* a CFIR_ value */ |
| 153 | UChar sp_how; /* a CFIR_ value */ |
| 154 | UChar fp_how; /* a CFIR_ value */ |
| 155 | Int cfa_off; |
| 156 | Int ra_off; |
| 157 | Int sp_off; |
| 158 | Int fp_off; |
sewardj | 5c638c2 | 2005-04-30 07:55:58 +0000 | [diff] [blame] | 159 | } |
| 160 | CfiSI; |
| 161 | |
sewardj | 3516553 | 2005-04-30 18:47:48 +0000 | [diff] [blame] | 162 | extern void VG_(ppCfiSI) ( CfiSI* ); |
| 163 | |
sewardj | 5c638c2 | 2005-04-30 07:55:58 +0000 | [diff] [blame] | 164 | |
jsgf | cb1d1c0 | 2003-10-14 21:55:10 +0000 | [diff] [blame] | 165 | /* A structure which contains information pertaining to one mapped |
nethercote | 4606320 | 2004-09-02 08:51:43 +0000 | [diff] [blame] | 166 | text segment. (typedef in tool.h) */ |
jsgf | cb1d1c0 | 2003-10-14 21:55:10 +0000 | [diff] [blame] | 167 | struct _SegInfo { |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 168 | struct _SegInfo* next; /* list of SegInfos */ |
| 169 | |
| 170 | Segment *seg; /* first segment we're mapped out of */ |
| 171 | Int ref; |
| 172 | |
jsgf | cb1d1c0 | 2003-10-14 21:55:10 +0000 | [diff] [blame] | 173 | /* Description of the mapped segment. */ |
| 174 | Addr start; |
| 175 | UInt size; |
| 176 | Char* filename; /* in mallocville */ |
njn | c616819 | 2004-11-29 13:54:10 +0000 | [diff] [blame] | 177 | OffT foffset; |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 178 | Char* soname; |
| 179 | |
jsgf | cb1d1c0 | 2003-10-14 21:55:10 +0000 | [diff] [blame] | 180 | /* An expandable array of symbols. */ |
| 181 | RiSym* symtab; |
| 182 | UInt symtab_used; |
| 183 | UInt symtab_size; |
| 184 | /* An expandable array of locations. */ |
| 185 | RiLoc* loctab; |
| 186 | UInt loctab_used; |
| 187 | UInt loctab_size; |
| 188 | /* An expandable array of scope ranges. */ |
| 189 | ScopeRange *scopetab; |
| 190 | UInt scopetab_used; |
| 191 | UInt scopetab_size; |
sewardj | bf60375 | 2005-05-02 00:36:27 +0000 | [diff] [blame] | 192 | /* An expandable array of CFI summary info records. Also includes |
| 193 | summary address bounds, showing the min and max address covered |
| 194 | by any of the records, as an aid to fast searching. */ |
sewardj | 5c638c2 | 2005-04-30 07:55:58 +0000 | [diff] [blame] | 195 | CfiSI* cfisi; |
| 196 | UInt cfisi_used; |
| 197 | UInt cfisi_size; |
sewardj | bf60375 | 2005-05-02 00:36:27 +0000 | [diff] [blame] | 198 | Addr cfisi_minaddr; |
| 199 | Addr cfisi_maxaddr; |
jsgf | cb1d1c0 | 2003-10-14 21:55:10 +0000 | [diff] [blame] | 200 | |
| 201 | /* Expandable arrays of characters -- the string table. |
| 202 | Pointers into this are stable (the arrays are not reallocated) |
| 203 | */ |
| 204 | struct strchunk { |
| 205 | UInt strtab_used; |
| 206 | struct strchunk *next; |
| 207 | Char strtab[STRCHUNKSIZE]; |
| 208 | } *strchunks; |
| 209 | |
| 210 | /* offset is what we need to add to symbol table entries |
| 211 | to get the real location of that symbol in memory. |
| 212 | */ |
njn | c616819 | 2004-11-29 13:54:10 +0000 | [diff] [blame] | 213 | OffT offset; |
jsgf | cb1d1c0 | 2003-10-14 21:55:10 +0000 | [diff] [blame] | 214 | |
nethercote | 996901a | 2004-08-03 13:29:09 +0000 | [diff] [blame] | 215 | /* Bounds of data, BSS, PLT and GOT, so that tools can see what |
jsgf | cb1d1c0 | 2003-10-14 21:55:10 +0000 | [diff] [blame] | 216 | section an address is in */ |
| 217 | Addr plt_start; |
| 218 | UInt plt_size; |
| 219 | Addr got_start; |
| 220 | UInt got_size; |
| 221 | Addr data_start; |
| 222 | UInt data_size; |
| 223 | Addr bss_start; |
| 224 | UInt bss_size; |
| 225 | |
| 226 | /* data used by stabs parser */ |
| 227 | struct _StabTypeTab *stab_typetab; |
| 228 | }; |
| 229 | |
| 230 | Char *VG_(addStr) ( SegInfo* si, Char* str, Int len ); |
| 231 | void VG_(addScopeInfo) ( SegInfo* si, Addr this, Addr next, Scope *scope); |
| 232 | void VG_(addLineInfo) ( SegInfo* si, Char* filename, Addr this, Addr next, Int lineno, Int entry); |
sewardj | 3516553 | 2005-04-30 18:47:48 +0000 | [diff] [blame] | 233 | void VG_(addCfiSI) ( SegInfo* si, CfiSI* cfisi ); |
jsgf | cb1d1c0 | 2003-10-14 21:55:10 +0000 | [diff] [blame] | 234 | |
| 235 | /* Non-fatal -- use vg_panic if terminal. */ |
| 236 | void VG_(symerr) ( Char* msg ); |
| 237 | |
| 238 | /* -------------------- |
| 239 | Stabs reader |
| 240 | -------------------- */ |
jsgf | cb1d1c0 | 2003-10-14 21:55:10 +0000 | [diff] [blame] | 241 | void VG_(read_debuginfo_stabs) ( SegInfo* si, |
| 242 | UChar* stabC, Int stab_sz, |
| 243 | UChar* stabstr, Int stabstr_sz ); |
| 244 | |
jsgf | cb1d1c0 | 2003-10-14 21:55:10 +0000 | [diff] [blame] | 245 | /* -------------------- |
| 246 | DWARF2 reader |
| 247 | -------------------- */ |
jseward | 8b3131a | 2003-12-13 23:16:26 +0000 | [diff] [blame] | 248 | void VG_(read_debuginfo_dwarf2) ( SegInfo* si, |
| 249 | UChar* dwarf2, Int dwarf2_sz ); |
| 250 | |
| 251 | /* -------------------- |
| 252 | DWARF1 reader |
| 253 | -------------------- */ |
| 254 | void VG_(read_debuginfo_dwarf1) ( SegInfo* si, |
| 255 | UChar* dwarf1d, Int dwarf1d_sz, |
| 256 | UChar* dwarf1l, Int dwarf1l_sz ); |
| 257 | |
sewardj | 5c638c2 | 2005-04-30 07:55:58 +0000 | [diff] [blame] | 258 | /* -------------------- |
| 259 | CFI reader |
| 260 | -------------------- */ |
| 261 | void VG_(read_callframe_info_dwarf2) |
tom | 2fd3890 | 2005-05-01 15:14:01 +0000 | [diff] [blame] | 262 | ( /*OUT*/SegInfo* si, UChar* ehframe, Int ehframe_sz, Addr ehframe_addr ); |
sewardj | 5c638c2 | 2005-04-30 07:55:58 +0000 | [diff] [blame] | 263 | |
jsgf | cb1d1c0 | 2003-10-14 21:55:10 +0000 | [diff] [blame] | 264 | |
| 265 | #endif /* _VG_SYMTYPE_H */ |
njn | 4bbdc97 | 2003-10-16 10:10:55 +0000 | [diff] [blame] | 266 | |
| 267 | /*--------------------------------------------------------------------*/ |
| 268 | /*--- end vg_symtab2.h ---*/ |
| 269 | /*--------------------------------------------------------------------*/ |