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
/*--------------------------------------------------------------------*/
9
This file is part of Valgrind, a dynamic binary instrumentation
12
Copyright (C) 2000-2006 Julian Seward
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.
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.
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
30
The GNU General Public License is contained in the file COPYING.
33
Stabs reader greatly improved by Nick Nethercote, Apr 02.
34
This module was also extensively hacked on by Jeremy Fitzhardinge
38
#ifndef __PRIV_STORAGE_H
39
#define __PRIV_STORAGE_H
41
/* --------------------- SYMBOLS --------------------- */
43
/* A structure to hold an ELF/XCOFF symbol (very crudely). */
46
Addr addr; /* lowest address of entity */
47
Addr tocptr; /* ppc64-linux only: value that R2 should have */
48
UInt size; /* size in bytes */
49
UChar *name; /* name */
53
/* --------------------- SRCLOCS --------------------- */
55
/* Line count at which overflow happens, due to line numbers being
56
stored as shorts in `struct nlist' in a.out.h. */
57
#define LINENO_OVERFLOW (1 << (sizeof(short) * 8))
59
#define LINENO_BITS 20
60
#define LOC_SIZE_BITS (32 - LINENO_BITS)
61
#define MAX_LINENO ((1 << LINENO_BITS) - 1)
63
/* Unlikely to have any lines with instruction ranges > 4096 bytes */
64
#define MAX_LOC_SIZE ((1 << LOC_SIZE_BITS) - 1)
66
/* Number used to detect line number overflows; if one line is
67
60000-odd smaller than the previous, is was probably an overflow.
69
#define OVERFLOW_DIFFERENCE (LINENO_OVERFLOW - 5000)
71
/* A structure to hold addr-to-source info for a single line. There
72
can be a lot of these, hence the dense packing. */
76
Addr addr; /* lowest address for this line */
78
UShort size:LOC_SIZE_BITS; /* # bytes; we catch overflows of this */
79
UInt lineno:LINENO_BITS; /* source line number, or zero */
81
UChar* filename; /* source filename */
83
UChar* dirname; /* source directory name */
87
/* --------------------- CF INFO --------------------- */
89
/* A structure to summarise DWARF2/3 CFA info for the code address
90
range [base .. base+len-1]. In short, if you know (sp,fp,ip) at
91
some point and ip is in the range [base .. base+len-1], it tells
92
you how to calculate (sp,fp) for the caller of the current frame
93
and also ra, the return address of the current frame.
95
First off, calculate CFA, the Canonical Frame Address, thusly:
97
cfa = if cfa_sprel then sp+cfa_off else fp+cfa_off
99
Once that is done, the previous frame's sp/fp values and this
100
frame's ra value can be calculated like this:
103
= case sp/fp/ra_how of
104
CFIR_UNKNOWN -> we don't know, sorry
105
CFIR_SAME -> same as it was before (sp/fp only)
106
CFIR_CFAREL -> cfa + sp/fp/ra_off
107
CFIR_MEMCFAREL -> *( cfa + sp/fp/ra_off )
110
#define CFIR_UNKNOWN ((UChar)0)
111
#define CFIR_SAME ((UChar)1)
112
#define CFIR_CFAREL ((UChar)2)
113
#define CFIR_MEMCFAREL ((UChar)3)
120
UChar ra_how; /* a CFIR_ value */
121
UChar sp_how; /* a CFIR_ value */
122
UChar fp_how; /* a CFIR_ value */
130
/* --------------------- SEGINFO --------------------- */
132
/* This is the top-level data type. It's a structure which contains
133
information pertaining to one mapped text segment. This type is
134
exported only abstractly - in pub_tool_debuginfo.h. */
136
#define SEGINFO_STRCHUNKSIZE (64*1024)
139
struct _SegInfo* next; /* list of SegInfos */
141
/* Description of the mapped segment. */
144
UChar* filename; /* in mallocville */
148
/* An expandable array of symbols. */
152
/* An expandable array of locations. */
156
/* An expandable array of CFI summary info records. Also includes
157
summary address bounds, showing the min and max address covered
158
by any of the records, as an aid to fast searching. */
165
/* Expandable arrays of characters -- the string table. Pointers
166
into this are stable (the arrays are not reallocated). */
169
struct strchunk *next;
170
UChar strtab[SEGINFO_STRCHUNKSIZE];
173
/* 'offset' is what needs to be added to an address in the address
174
space of the library as stored on disk (which is not 0-based for
175
executables or prelinked libraries) to get an address in memory
176
for the object loaded at 'start' */
179
/* Bounds of data, BSS, PLT, GOT and OPD (for ppc64-linux) so that
180
tools can see what section an address is in. In the running
194
/* --------------------- functions --------------------- */
196
/* ------ Adding ------ */
198
/* Add a symbol to si's symbol table. */
199
extern void ML_(addSym) ( struct _SegInfo* si, DiSym* sym );
201
/* Add a line-number record to a SegInfo. */
203
void ML_(addLineInfo) ( struct _SegInfo* si,
205
UChar* dirname, /* NULL is allowable */
206
Addr this, Addr next, Int lineno, Int entry);
208
/* Add a CFI summary record. The supplied DiCfSI is copied. */
209
extern void ML_(addDiCfSI) ( struct _SegInfo* si, DiCfSI* cfsi );
211
/* Add a string to the string table of a SegInfo. If len==-1,
212
ML_(addStr) will itself measure the length of the string. */
213
extern UChar* ML_(addStr) ( struct _SegInfo* si, UChar* str, Int len );
215
/* Canonicalise the tables held by 'si', in preparation for use. Call
216
this after finishing adding entries to these tables. */
217
extern void ML_(canonicaliseTables) ( struct _SegInfo* si );
219
/* ------ Searching ------ */
221
/* Find a symbol-table index containing the specified pointer, or -1
222
if not found. Binary search. */
223
extern Int ML_(search_one_symtab) ( struct _SegInfo* si, Addr ptr,
224
Bool match_anywhere_in_fun );
226
/* Find a location-table index containing the specified pointer, or -1
227
if not found. Binary search. */
228
extern Int ML_(search_one_loctab) ( struct _SegInfo* si, Addr ptr );
230
/* Find a CFI-table index containing the specified pointer, or -1 if
231
not found. Binary search. */
232
extern Int ML_(search_one_cfitab) ( struct _SegInfo* si, Addr ptr );
234
/* ------ Misc ------ */
236
/* Show a non-fatal debug info reading error. Use vg_panic if
238
extern void ML_(symerr) ( HChar* msg );
240
/* Print a symbol. */
241
extern void ML_(ppSym) ( Int idx, DiSym* sym );
243
/* Print a call-frame-info summary. */
244
extern void ML_(ppDiCfSI) ( DiCfSI* si );
247
#define TRACE_SYMTAB(format, args...) \
248
if (VG_(clo_trace_symtab)) { VG_(printf)(format, ## args); }
251
#endif /* ndef __PRIV_STORAGE_H */
253
/*--------------------------------------------------------------------*/
255
/*--------------------------------------------------------------------*/