~bkerensa/ubuntu/raring/valgrind/merge-from-deb

« back to all changes in this revision

Viewing changes to coregrind/m_debuginfo/priv_storage.h

  • Committer: Bazaar Package Importer
  • Author(s): Sebastian Dröge
  • Date: 2006-06-26 00:17:17 UTC
  • mto: This revision was merged to the branch mainline in revision 11.
  • Revision ID: james.westby@ubuntu.com-20060626001717-qi51nzty57cb12q6
Tags: upstream-3.2.0
Import upstream version 3.2.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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-2006 Julian Seward 
 
13
      jseward@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
 
 
38
#ifndef __PRIV_STORAGE_H
 
39
#define __PRIV_STORAGE_H
 
40
 
 
41
/* --------------------- SYMBOLS --------------------- */
 
42
 
 
43
/* A structure to hold an ELF/XCOFF symbol (very crudely). */
 
44
typedef 
 
45
   struct { 
 
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 */
 
50
   }
 
51
   DiSym;
 
52
 
 
53
/* --------------------- SRCLOCS --------------------- */
 
54
 
 
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))
 
58
 
 
59
#define LINENO_BITS     20
 
60
#define LOC_SIZE_BITS  (32 - LINENO_BITS)
 
61
#define MAX_LINENO     ((1 << LINENO_BITS) - 1)
 
62
 
 
63
/* Unlikely to have any lines with instruction ranges > 4096 bytes */
 
64
#define MAX_LOC_SIZE   ((1 << LOC_SIZE_BITS) - 1)
 
65
 
 
66
/* Number used to detect line number overflows; if one line is
 
67
   60000-odd smaller than the previous, is was probably an overflow.
 
68
 */
 
69
#define OVERFLOW_DIFFERENCE     (LINENO_OVERFLOW - 5000)
 
70
 
 
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. */
 
73
typedef
 
74
   struct {
 
75
      /* Word 1 */
 
76
      Addr   addr;               /* lowest address for this line */
 
77
      /* Word 2 */
 
78
      UShort size:LOC_SIZE_BITS; /* # bytes; we catch overflows of this */
 
79
      UInt   lineno:LINENO_BITS; /* source line number, or zero */
 
80
      /* Word 3 */
 
81
      UChar*  filename;          /* source filename */
 
82
      /* Word 4 */
 
83
      UChar*  dirname;           /* source directory name */
 
84
   }
 
85
   DiLoc;
 
86
 
 
87
/* --------------------- CF INFO --------------------- */
 
88
 
 
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.
 
94
 
 
95
   First off, calculate CFA, the Canonical Frame Address, thusly:
 
96
 
 
97
     cfa = if cfa_sprel then sp+cfa_off else fp+cfa_off
 
98
 
 
99
   Once that is done, the previous frame's sp/fp values and this
 
100
   frame's ra value can be calculated like this:
 
101
 
 
102
      old_sp/fp/ra
 
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 )
 
108
*/
 
109
 
 
110
#define CFIR_UNKNOWN   ((UChar)0)
 
111
#define CFIR_SAME      ((UChar)1)
 
112
#define CFIR_CFAREL    ((UChar)2)
 
113
#define CFIR_MEMCFAREL ((UChar)3)
 
114
 
 
115
typedef
 
116
   struct {
 
117
      Addr  base;
 
118
      UInt  len;
 
119
      Bool  cfa_sprel;
 
120
      UChar ra_how; /* a CFIR_ value */
 
121
      UChar sp_how; /* a CFIR_ value */
 
122
      UChar fp_how; /* a CFIR_ value */
 
123
      Int   cfa_off;
 
124
      Int   ra_off;
 
125
      Int   sp_off;
 
126
      Int   fp_off;
 
127
   }
 
128
   DiCfSI;
 
129
 
 
130
/* --------------------- SEGINFO --------------------- */
 
131
 
 
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. */
 
135
 
 
136
#define SEGINFO_STRCHUNKSIZE (64*1024)
 
137
 
 
138
struct _SegInfo {
 
139
   struct _SegInfo* next;       /* list of SegInfos */
 
140
 
 
141
   /* Description of the mapped segment. */
 
142
   Addr   start;
 
143
   UInt   size;
 
144
   UChar* filename; /* in mallocville */
 
145
   OffT   foffset;
 
146
   UChar* soname;
 
147
 
 
148
   /* An expandable array of symbols. */
 
149
   DiSym*  symtab;
 
150
   UInt    symtab_used;
 
151
   UInt    symtab_size;
 
152
   /* An expandable array of locations. */
 
153
   DiLoc*  loctab;
 
154
   UInt    loctab_used;
 
155
   UInt    loctab_size;
 
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. */
 
159
   DiCfSI* cfsi;
 
160
   UInt    cfsi_used;
 
161
   UInt    cfsi_size;
 
162
   Addr    cfsi_minaddr;
 
163
   Addr    cfsi_maxaddr;
 
164
 
 
165
   /* Expandable arrays of characters -- the string table.  Pointers
 
166
      into this are stable (the arrays are not reallocated). */
 
167
   struct strchunk {
 
168
      UInt   strtab_used;
 
169
      struct strchunk *next;
 
170
      UChar  strtab[SEGINFO_STRCHUNKSIZE];
 
171
   } *strchunks;
 
172
 
 
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' */
 
177
   OffT   offset;
 
178
 
 
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
 
181
      image! */
 
182
   Addr   plt_start_vma;
 
183
   UInt   plt_size;
 
184
   Addr   got_start_vma;
 
185
   UInt   got_size;
 
186
   Addr   opd_start_vma;
 
187
   UInt   opd_size;
 
188
   Addr   data_start_vma;
 
189
   UInt   data_size;
 
190
   Addr   bss_start_vma;
 
191
   UInt   bss_size;
 
192
};
 
193
 
 
194
/* --------------------- functions --------------------- */
 
195
 
 
196
/* ------ Adding ------ */
 
197
 
 
198
/* Add a symbol to si's symbol table. */
 
199
extern void ML_(addSym) ( struct _SegInfo* si, DiSym* sym );
 
200
 
 
201
/* Add a line-number record to a SegInfo. */
 
202
extern
 
203
void ML_(addLineInfo) ( struct _SegInfo* si, 
 
204
                        UChar*   filename, 
 
205
                        UChar*   dirname,  /* NULL is allowable */
 
206
                        Addr this, Addr next, Int lineno, Int entry);
 
207
 
 
208
/* Add a CFI summary record.  The supplied DiCfSI is copied. */
 
209
extern void ML_(addDiCfSI) ( struct _SegInfo* si, DiCfSI* cfsi );
 
210
 
 
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 );
 
214
 
 
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 );
 
218
 
 
219
/* ------ Searching ------ */
 
220
 
 
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 );
 
225
 
 
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 );
 
229
 
 
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 );
 
233
 
 
234
/* ------ Misc ------ */
 
235
 
 
236
/* Show a non-fatal debug info reading error.  Use vg_panic if
 
237
   terminal. */
 
238
extern void ML_(symerr) ( HChar* msg );
 
239
 
 
240
/* Print a symbol. */
 
241
extern void ML_(ppSym) ( Int idx, DiSym* sym );
 
242
 
 
243
/* Print a call-frame-info summary. */
 
244
extern void ML_(ppDiCfSI) ( DiCfSI* si );
 
245
 
 
246
 
 
247
#define TRACE_SYMTAB(format, args...) \
 
248
   if (VG_(clo_trace_symtab)) { VG_(printf)(format, ## args); }
 
249
 
 
250
 
 
251
#endif /* ndef __PRIV_STORAGE_H */
 
252
 
 
253
/*--------------------------------------------------------------------*/
 
254
/*--- end                                                          ---*/
 
255
/*--------------------------------------------------------------------*/