blob: 65774798629f4694758d9d2b8ce58a76c852e664 [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
120/* A structure which contains information pertaining to one mapped
nethercote46063202004-09-02 08:51:43 +0000121 text segment. (typedef in tool.h) */
jsgfcb1d1c02003-10-14 21:55:10 +0000122struct _SegInfo {
fitzhardinge98abfc72003-12-16 02:05:15 +0000123 struct _SegInfo* next; /* list of SegInfos */
124
125 Segment *seg; /* first segment we're mapped out of */
126 Int ref;
127
jsgfcb1d1c02003-10-14 21:55:10 +0000128 /* Description of the mapped segment. */
129 Addr start;
130 UInt size;
131 Char* filename; /* in mallocville */
njnc6168192004-11-29 13:54:10 +0000132 OffT foffset;
fitzhardinge98abfc72003-12-16 02:05:15 +0000133 Char* soname;
134
jsgfcb1d1c02003-10-14 21:55:10 +0000135 /* An expandable array of symbols. */
136 RiSym* symtab;
137 UInt symtab_used;
138 UInt symtab_size;
139 /* An expandable array of locations. */
140 RiLoc* loctab;
141 UInt loctab_used;
142 UInt loctab_size;
143 /* An expandable array of scope ranges. */
144 ScopeRange *scopetab;
145 UInt scopetab_used;
146 UInt scopetab_size;
147
148 /* Expandable arrays of characters -- the string table.
149 Pointers into this are stable (the arrays are not reallocated)
150 */
151 struct strchunk {
152 UInt strtab_used;
153 struct strchunk *next;
154 Char strtab[STRCHUNKSIZE];
155 } *strchunks;
156
157 /* offset is what we need to add to symbol table entries
158 to get the real location of that symbol in memory.
159 */
njnc6168192004-11-29 13:54:10 +0000160 OffT offset;
jsgfcb1d1c02003-10-14 21:55:10 +0000161
nethercote996901a2004-08-03 13:29:09 +0000162 /* Bounds of data, BSS, PLT and GOT, so that tools can see what
jsgfcb1d1c02003-10-14 21:55:10 +0000163 section an address is in */
164 Addr plt_start;
165 UInt plt_size;
166 Addr got_start;
167 UInt got_size;
168 Addr data_start;
169 UInt data_size;
170 Addr bss_start;
171 UInt bss_size;
172
173 /* data used by stabs parser */
174 struct _StabTypeTab *stab_typetab;
175};
176
177Char *VG_(addStr) ( SegInfo* si, Char* str, Int len );
178void VG_(addScopeInfo) ( SegInfo* si, Addr this, Addr next, Scope *scope);
179void VG_(addLineInfo) ( SegInfo* si, Char* filename, Addr this, Addr next, Int lineno, Int entry);
180
181/* Non-fatal -- use vg_panic if terminal. */
182void VG_(symerr) ( Char* msg );
183
184/* --------------------
185 Stabs reader
186 -------------------- */
jsgfcb1d1c02003-10-14 21:55:10 +0000187void VG_(read_debuginfo_stabs) ( SegInfo* si,
188 UChar* stabC, Int stab_sz,
189 UChar* stabstr, Int stabstr_sz );
190
jsgfcb1d1c02003-10-14 21:55:10 +0000191/* --------------------
192 DWARF2 reader
193 -------------------- */
jseward8b3131a2003-12-13 23:16:26 +0000194void VG_(read_debuginfo_dwarf2) ( SegInfo* si,
195 UChar* dwarf2, Int dwarf2_sz );
196
197/* --------------------
198 DWARF1 reader
199 -------------------- */
200void VG_(read_debuginfo_dwarf1) ( SegInfo* si,
201 UChar* dwarf1d, Int dwarf1d_sz,
202 UChar* dwarf1l, Int dwarf1l_sz );
203
jsgfcb1d1c02003-10-14 21:55:10 +0000204
205#endif /* _VG_SYMTYPE_H */
njn4bbdc972003-10-16 10:10:55 +0000206
207/*--------------------------------------------------------------------*/
208/*--- end vg_symtab2.h ---*/
209/*--------------------------------------------------------------------*/