blob: f641eec9f80311436ed01e7f1d8f941d8119a3fd [file] [log] [blame]
njn4bbdc972003-10-16 10:10:55 +00001/*--------------------------------------------------------------------*/
2/*--- Header for symbol table stuff. vg_symtab2.h ---*/
3/*--------------------------------------------------------------------*/
4
5/*
njnb9c427c2004-12-01 14:14:42 +00006 This file is part of Valgrind, a dynamic binary instrumentation
7 framework.
njn4bbdc972003-10-16 10:10:55 +00008
njn53612422005-03-12 16:22:54 +00009 Copyright (C) 2000-2005 Julian Seward
njn4bbdc972003-10-16 10:10:55 +000010 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*/
jsgfcb1d1c02003-10-14 21:55:10 +000029
30#ifndef _VG_SYMTYPE_H
31#define _VG_SYMTYPE_H
32
jsgfcb1d1c02003-10-14 21:55:10 +000033#include "vg_symtypes.h"
34
35/* A structure to hold an ELF symbol (very crudely). */
36typedef
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. */
62typedef
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 */
76typedef struct _Scope Scope; /* a set of symbols in one scope */
77typedef struct _Sym Sym; /* a single symbol */
78typedef struct _ScopeRange ScopeRange; /* a range of code addreses a scope covers */
79
80typedef 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
90struct _Sym {
91 SymType *type; /* type */
92 Char *name; /* name */
93 SyKind kind; /* kind of symbol */
94
95 /* a value, depending on kind */
96 union {
njnc6168192004-11-29 13:54:10 +000097 OffT offset; /* offset on stack (-ve -> ebp; +ve -> esp) */
jsgfcb1d1c02003-10-14 21:55:10 +000098 Int regno; /* register number */
99 Addr addr; /* static or global address */
mueller5ed88f22004-01-06 16:02:29 +0000100 } u;
jsgfcb1d1c02003-10-14 21:55:10 +0000101};
102
103struct _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) */
112struct _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
sewardj5c638c22005-04-30 07:55:58 +0000120
sewardj35165532005-04-30 18:47:48 +0000121/* 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
sewardj5c638c22005-04-30 07:55:58 +0000147typedef
148 struct {
sewardj35165532005-04-30 18:47:48 +0000149 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;
sewardj5c638c22005-04-30 07:55:58 +0000159 }
160 CfiSI;
161
sewardj35165532005-04-30 18:47:48 +0000162extern void VG_(ppCfiSI) ( CfiSI* );
163
sewardj5c638c22005-04-30 07:55:58 +0000164
jsgfcb1d1c02003-10-14 21:55:10 +0000165/* A structure which contains information pertaining to one mapped
nethercote46063202004-09-02 08:51:43 +0000166 text segment. (typedef in tool.h) */
jsgfcb1d1c02003-10-14 21:55:10 +0000167struct _SegInfo {
fitzhardinge98abfc72003-12-16 02:05:15 +0000168 struct _SegInfo* next; /* list of SegInfos */
169
170 Segment *seg; /* first segment we're mapped out of */
171 Int ref;
172
jsgfcb1d1c02003-10-14 21:55:10 +0000173 /* Description of the mapped segment. */
174 Addr start;
175 UInt size;
176 Char* filename; /* in mallocville */
njnc6168192004-11-29 13:54:10 +0000177 OffT foffset;
fitzhardinge98abfc72003-12-16 02:05:15 +0000178 Char* soname;
179
jsgfcb1d1c02003-10-14 21:55:10 +0000180 /* 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;
sewardjbf603752005-05-02 00:36:27 +0000192 /* 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. */
sewardj5c638c22005-04-30 07:55:58 +0000195 CfiSI* cfisi;
196 UInt cfisi_used;
197 UInt cfisi_size;
sewardjbf603752005-05-02 00:36:27 +0000198 Addr cfisi_minaddr;
199 Addr cfisi_maxaddr;
jsgfcb1d1c02003-10-14 21:55:10 +0000200
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 */
njnc6168192004-11-29 13:54:10 +0000213 OffT offset;
jsgfcb1d1c02003-10-14 21:55:10 +0000214
nethercote996901a2004-08-03 13:29:09 +0000215 /* Bounds of data, BSS, PLT and GOT, so that tools can see what
jsgfcb1d1c02003-10-14 21:55:10 +0000216 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
230Char *VG_(addStr) ( SegInfo* si, Char* str, Int len );
231void VG_(addScopeInfo) ( SegInfo* si, Addr this, Addr next, Scope *scope);
232void VG_(addLineInfo) ( SegInfo* si, Char* filename, Addr this, Addr next, Int lineno, Int entry);
sewardj35165532005-04-30 18:47:48 +0000233void VG_(addCfiSI) ( SegInfo* si, CfiSI* cfisi );
jsgfcb1d1c02003-10-14 21:55:10 +0000234
235/* Non-fatal -- use vg_panic if terminal. */
236void VG_(symerr) ( Char* msg );
237
238/* --------------------
239 Stabs reader
240 -------------------- */
jsgfcb1d1c02003-10-14 21:55:10 +0000241void VG_(read_debuginfo_stabs) ( SegInfo* si,
242 UChar* stabC, Int stab_sz,
243 UChar* stabstr, Int stabstr_sz );
244
jsgfcb1d1c02003-10-14 21:55:10 +0000245/* --------------------
246 DWARF2 reader
247 -------------------- */
jseward8b3131a2003-12-13 23:16:26 +0000248void VG_(read_debuginfo_dwarf2) ( SegInfo* si,
249 UChar* dwarf2, Int dwarf2_sz );
250
251/* --------------------
252 DWARF1 reader
253 -------------------- */
254void VG_(read_debuginfo_dwarf1) ( SegInfo* si,
255 UChar* dwarf1d, Int dwarf1d_sz,
256 UChar* dwarf1l, Int dwarf1l_sz );
257
sewardj5c638c22005-04-30 07:55:58 +0000258/* --------------------
259 CFI reader
260 -------------------- */
261void VG_(read_callframe_info_dwarf2)
tom2fd38902005-05-01 15:14:01 +0000262 ( /*OUT*/SegInfo* si, UChar* ehframe, Int ehframe_sz, Addr ehframe_addr );
sewardj5c638c22005-04-30 07:55:58 +0000263
jsgfcb1d1c02003-10-14 21:55:10 +0000264
265#endif /* _VG_SYMTYPE_H */
njn4bbdc972003-10-16 10:10:55 +0000266
267/*--------------------------------------------------------------------*/
268/*--- end vg_symtab2.h ---*/
269/*--------------------------------------------------------------------*/