xref: /dflybsd-src/contrib/gdb-7/gdb/objfiles.h (revision 5796c8dc12c637f18a1740c26afd8d40ffa9b719)
1*5796c8dcSSimon Schubert /* Definitions for symbol file management in GDB.
2*5796c8dcSSimon Schubert 
3*5796c8dcSSimon Schubert    Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001,
4*5796c8dcSSimon Schubert    2002, 2003, 2004, 2007, 2008, 2009 Free Software Foundation, Inc.
5*5796c8dcSSimon Schubert 
6*5796c8dcSSimon Schubert    This file is part of GDB.
7*5796c8dcSSimon Schubert 
8*5796c8dcSSimon Schubert    This program is free software; you can redistribute it and/or modify
9*5796c8dcSSimon Schubert    it under the terms of the GNU General Public License as published by
10*5796c8dcSSimon Schubert    the Free Software Foundation; either version 3 of the License, or
11*5796c8dcSSimon Schubert    (at your option) any later version.
12*5796c8dcSSimon Schubert 
13*5796c8dcSSimon Schubert    This program is distributed in the hope that it will be useful,
14*5796c8dcSSimon Schubert    but WITHOUT ANY WARRANTY; without even the implied warranty of
15*5796c8dcSSimon Schubert    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16*5796c8dcSSimon Schubert    GNU General Public License for more details.
17*5796c8dcSSimon Schubert 
18*5796c8dcSSimon Schubert    You should have received a copy of the GNU General Public License
19*5796c8dcSSimon Schubert    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
20*5796c8dcSSimon Schubert 
21*5796c8dcSSimon Schubert #if !defined (OBJFILES_H)
22*5796c8dcSSimon Schubert #define OBJFILES_H
23*5796c8dcSSimon Schubert 
24*5796c8dcSSimon Schubert #include "gdb_obstack.h"	/* For obstack internals.  */
25*5796c8dcSSimon Schubert #include "symfile.h"		/* For struct psymbol_allocation_list */
26*5796c8dcSSimon Schubert 
27*5796c8dcSSimon Schubert struct bcache;
28*5796c8dcSSimon Schubert struct htab;
29*5796c8dcSSimon Schubert struct symtab;
30*5796c8dcSSimon Schubert struct objfile_data;
31*5796c8dcSSimon Schubert 
32*5796c8dcSSimon Schubert /* This structure maintains information on a per-objfile basis about the
33*5796c8dcSSimon Schubert    "entry point" of the objfile, and the scope within which the entry point
34*5796c8dcSSimon Schubert    exists.  It is possible that gdb will see more than one objfile that is
35*5796c8dcSSimon Schubert    executable, each with its own entry point.
36*5796c8dcSSimon Schubert 
37*5796c8dcSSimon Schubert    For example, for dynamically linked executables in SVR4, the dynamic linker
38*5796c8dcSSimon Schubert    code is contained within the shared C library, which is actually executable
39*5796c8dcSSimon Schubert    and is run by the kernel first when an exec is done of a user executable
40*5796c8dcSSimon Schubert    that is dynamically linked.  The dynamic linker within the shared C library
41*5796c8dcSSimon Schubert    then maps in the various program segments in the user executable and jumps
42*5796c8dcSSimon Schubert    to the user executable's recorded entry point, as if the call had been made
43*5796c8dcSSimon Schubert    directly by the kernel.
44*5796c8dcSSimon Schubert 
45*5796c8dcSSimon Schubert    The traditional gdb method of using this info was to use the
46*5796c8dcSSimon Schubert    recorded entry point to set the entry-file's lowpc and highpc from
47*5796c8dcSSimon Schubert    the debugging information, where these values are the starting
48*5796c8dcSSimon Schubert    address (inclusive) and ending address (exclusive) of the
49*5796c8dcSSimon Schubert    instruction space in the executable which correspond to the
50*5796c8dcSSimon Schubert    "startup file", I.E. crt0.o in most cases.  This file is assumed to
51*5796c8dcSSimon Schubert    be a startup file and frames with pc's inside it are treated as
52*5796c8dcSSimon Schubert    nonexistent.  Setting these variables is necessary so that
53*5796c8dcSSimon Schubert    backtraces do not fly off the bottom of the stack.
54*5796c8dcSSimon Schubert 
55*5796c8dcSSimon Schubert    NOTE: cagney/2003-09-09: It turns out that this "traditional"
56*5796c8dcSSimon Schubert    method doesn't work.  Corinna writes: ``It turns out that the call
57*5796c8dcSSimon Schubert    to test for "inside entry file" destroys a meaningful backtrace
58*5796c8dcSSimon Schubert    under some conditions.  E. g. the backtrace tests in the asm-source
59*5796c8dcSSimon Schubert    testcase are broken for some targets.  In this test the functions
60*5796c8dcSSimon Schubert    are all implemented as part of one file and the testcase is not
61*5796c8dcSSimon Schubert    necessarily linked with a start file (depending on the target).
62*5796c8dcSSimon Schubert    What happens is, that the first frame is printed normaly and
63*5796c8dcSSimon Schubert    following frames are treated as being inside the enttry file then.
64*5796c8dcSSimon Schubert    This way, only the #0 frame is printed in the backtrace output.''
65*5796c8dcSSimon Schubert    Ref "frame.c" "NOTE: vinschen/2003-04-01".
66*5796c8dcSSimon Schubert 
67*5796c8dcSSimon Schubert    Gdb also supports an alternate method to avoid running off the bottom
68*5796c8dcSSimon Schubert    of the stack.
69*5796c8dcSSimon Schubert 
70*5796c8dcSSimon Schubert    There are two frames that are "special", the frame for the function
71*5796c8dcSSimon Schubert    containing the process entry point, since it has no predecessor frame,
72*5796c8dcSSimon Schubert    and the frame for the function containing the user code entry point
73*5796c8dcSSimon Schubert    (the main() function), since all the predecessor frames are for the
74*5796c8dcSSimon Schubert    process startup code.  Since we have no guarantee that the linked
75*5796c8dcSSimon Schubert    in startup modules have any debugging information that gdb can use,
76*5796c8dcSSimon Schubert    we need to avoid following frame pointers back into frames that might
77*5796c8dcSSimon Schubert    have been built in the startup code, as we might get hopelessly
78*5796c8dcSSimon Schubert    confused.  However, we almost always have debugging information
79*5796c8dcSSimon Schubert    available for main().
80*5796c8dcSSimon Schubert 
81*5796c8dcSSimon Schubert    These variables are used to save the range of PC values which are
82*5796c8dcSSimon Schubert    valid within the main() function and within the function containing
83*5796c8dcSSimon Schubert    the process entry point.  If we always consider the frame for
84*5796c8dcSSimon Schubert    main() as the outermost frame when debugging user code, and the
85*5796c8dcSSimon Schubert    frame for the process entry point function as the outermost frame
86*5796c8dcSSimon Schubert    when debugging startup code, then all we have to do is have
87*5796c8dcSSimon Schubert    DEPRECATED_FRAME_CHAIN_VALID return false whenever a frame's
88*5796c8dcSSimon Schubert    current PC is within the range specified by these variables.  In
89*5796c8dcSSimon Schubert    essence, we set "ceilings" in the frame chain beyond which we will
90*5796c8dcSSimon Schubert    not proceed when following the frame chain back up the stack.
91*5796c8dcSSimon Schubert 
92*5796c8dcSSimon Schubert    A nice side effect is that we can still debug startup code without
93*5796c8dcSSimon Schubert    running off the end of the frame chain, assuming that we have usable
94*5796c8dcSSimon Schubert    debugging information in the startup modules, and if we choose to not
95*5796c8dcSSimon Schubert    use the block at main, or can't find it for some reason, everything
96*5796c8dcSSimon Schubert    still works as before.  And if we have no startup code debugging
97*5796c8dcSSimon Schubert    information but we do have usable information for main(), backtraces
98*5796c8dcSSimon Schubert    from user code don't go wandering off into the startup code.  */
99*5796c8dcSSimon Schubert 
100*5796c8dcSSimon Schubert struct entry_info
101*5796c8dcSSimon Schubert   {
102*5796c8dcSSimon Schubert 
103*5796c8dcSSimon Schubert     /* The value we should use for this objects entry point.
104*5796c8dcSSimon Schubert        The illegal/unknown value needs to be something other than 0, ~0
105*5796c8dcSSimon Schubert        for instance, which is much less likely than 0. */
106*5796c8dcSSimon Schubert 
107*5796c8dcSSimon Schubert     CORE_ADDR entry_point;
108*5796c8dcSSimon Schubert 
109*5796c8dcSSimon Schubert #define INVALID_ENTRY_POINT (~0)	/* ~0 will not be in any file, we hope.  */
110*5796c8dcSSimon Schubert 
111*5796c8dcSSimon Schubert   };
112*5796c8dcSSimon Schubert 
113*5796c8dcSSimon Schubert /* Sections in an objfile.  The section offsets are stored in the
114*5796c8dcSSimon Schubert    OBJFILE.  */
115*5796c8dcSSimon Schubert 
116*5796c8dcSSimon Schubert struct obj_section
117*5796c8dcSSimon Schubert   {
118*5796c8dcSSimon Schubert     struct bfd_section *the_bfd_section;	/* BFD section pointer */
119*5796c8dcSSimon Schubert 
120*5796c8dcSSimon Schubert     /* Objfile this section is part of.  */
121*5796c8dcSSimon Schubert     struct objfile *objfile;
122*5796c8dcSSimon Schubert 
123*5796c8dcSSimon Schubert     /* True if this "overlay section" is mapped into an "overlay region". */
124*5796c8dcSSimon Schubert     int ovly_mapped;
125*5796c8dcSSimon Schubert   };
126*5796c8dcSSimon Schubert 
127*5796c8dcSSimon Schubert /* Relocation offset applied to S.  */
128*5796c8dcSSimon Schubert #define obj_section_offset(s)						\
129*5796c8dcSSimon Schubert   (((s)->objfile->section_offsets)->offsets[(s)->the_bfd_section->index])
130*5796c8dcSSimon Schubert 
131*5796c8dcSSimon Schubert /* The memory address of section S (vma + offset).  */
132*5796c8dcSSimon Schubert #define obj_section_addr(s)				      		\
133*5796c8dcSSimon Schubert   (bfd_get_section_vma ((s)->objfile->abfd, s->the_bfd_section)		\
134*5796c8dcSSimon Schubert    + obj_section_offset (s))
135*5796c8dcSSimon Schubert 
136*5796c8dcSSimon Schubert /* The one-passed-the-end memory address of section S
137*5796c8dcSSimon Schubert    (vma + size + offset).  */
138*5796c8dcSSimon Schubert #define obj_section_endaddr(s)						\
139*5796c8dcSSimon Schubert   (bfd_get_section_vma ((s)->objfile->abfd, s->the_bfd_section)		\
140*5796c8dcSSimon Schubert    + bfd_get_section_size ((s)->the_bfd_section)			\
141*5796c8dcSSimon Schubert    + obj_section_offset (s))
142*5796c8dcSSimon Schubert 
143*5796c8dcSSimon Schubert /* The "objstats" structure provides a place for gdb to record some
144*5796c8dcSSimon Schubert    interesting information about its internal state at runtime, on a
145*5796c8dcSSimon Schubert    per objfile basis, such as information about the number of symbols
146*5796c8dcSSimon Schubert    read, size of string table (if any), etc. */
147*5796c8dcSSimon Schubert 
148*5796c8dcSSimon Schubert struct objstats
149*5796c8dcSSimon Schubert   {
150*5796c8dcSSimon Schubert     int n_minsyms;		/* Number of minimal symbols read */
151*5796c8dcSSimon Schubert     int n_psyms;		/* Number of partial symbols read */
152*5796c8dcSSimon Schubert     int n_syms;			/* Number of full symbols read */
153*5796c8dcSSimon Schubert     int n_stabs;		/* Number of ".stabs" read (if applicable) */
154*5796c8dcSSimon Schubert     int n_types;		/* Number of types */
155*5796c8dcSSimon Schubert     int sz_strtab;		/* Size of stringtable, (if applicable) */
156*5796c8dcSSimon Schubert   };
157*5796c8dcSSimon Schubert 
158*5796c8dcSSimon Schubert #define OBJSTAT(objfile, expr) (objfile -> stats.expr)
159*5796c8dcSSimon Schubert #define OBJSTATS struct objstats stats
160*5796c8dcSSimon Schubert extern void print_objfile_statistics (void);
161*5796c8dcSSimon Schubert extern void print_symbol_bcache_statistics (void);
162*5796c8dcSSimon Schubert 
163*5796c8dcSSimon Schubert /* Number of entries in the minimal symbol hash table.  */
164*5796c8dcSSimon Schubert #define MINIMAL_SYMBOL_HASH_SIZE 2039
165*5796c8dcSSimon Schubert 
166*5796c8dcSSimon Schubert /* Master structure for keeping track of each file from which
167*5796c8dcSSimon Schubert    gdb reads symbols.  There are several ways these get allocated: 1.
168*5796c8dcSSimon Schubert    The main symbol file, symfile_objfile, set by the symbol-file command,
169*5796c8dcSSimon Schubert    2.  Additional symbol files added by the add-symbol-file command,
170*5796c8dcSSimon Schubert    3.  Shared library objfiles, added by ADD_SOLIB,  4.  symbol files
171*5796c8dcSSimon Schubert    for modules that were loaded when GDB attached to a remote system
172*5796c8dcSSimon Schubert    (see remote-vx.c).  */
173*5796c8dcSSimon Schubert 
174*5796c8dcSSimon Schubert struct objfile
175*5796c8dcSSimon Schubert   {
176*5796c8dcSSimon Schubert 
177*5796c8dcSSimon Schubert     /* All struct objfile's are chained together by their next pointers.
178*5796c8dcSSimon Schubert        The global variable "object_files" points to the first link in this
179*5796c8dcSSimon Schubert        chain.
180*5796c8dcSSimon Schubert 
181*5796c8dcSSimon Schubert        FIXME:  There is a problem here if the objfile is reusable, and if
182*5796c8dcSSimon Schubert        multiple users are to be supported.  The problem is that the objfile
183*5796c8dcSSimon Schubert        list is linked through a member of the objfile struct itself, which
184*5796c8dcSSimon Schubert        is only valid for one gdb process.  The list implementation needs to
185*5796c8dcSSimon Schubert        be changed to something like:
186*5796c8dcSSimon Schubert 
187*5796c8dcSSimon Schubert        struct list {struct list *next; struct objfile *objfile};
188*5796c8dcSSimon Schubert 
189*5796c8dcSSimon Schubert        where the list structure is completely maintained separately within
190*5796c8dcSSimon Schubert        each gdb process. */
191*5796c8dcSSimon Schubert 
192*5796c8dcSSimon Schubert     struct objfile *next;
193*5796c8dcSSimon Schubert 
194*5796c8dcSSimon Schubert     /* The object file's name, tilde-expanded and absolute.
195*5796c8dcSSimon Schubert        Malloc'd; free it if you free this struct.  */
196*5796c8dcSSimon Schubert 
197*5796c8dcSSimon Schubert     char *name;
198*5796c8dcSSimon Schubert 
199*5796c8dcSSimon Schubert     /* Some flag bits for this objfile. */
200*5796c8dcSSimon Schubert 
201*5796c8dcSSimon Schubert     unsigned short flags;
202*5796c8dcSSimon Schubert 
203*5796c8dcSSimon Schubert     /* Each objfile points to a linked list of symtabs derived from this file,
204*5796c8dcSSimon Schubert        one symtab structure for each compilation unit (source file).  Each link
205*5796c8dcSSimon Schubert        in the symtab list contains a backpointer to this objfile. */
206*5796c8dcSSimon Schubert 
207*5796c8dcSSimon Schubert     struct symtab *symtabs;
208*5796c8dcSSimon Schubert 
209*5796c8dcSSimon Schubert     /* Each objfile points to a linked list of partial symtabs derived from
210*5796c8dcSSimon Schubert        this file, one partial symtab structure for each compilation unit
211*5796c8dcSSimon Schubert        (source file). */
212*5796c8dcSSimon Schubert 
213*5796c8dcSSimon Schubert     struct partial_symtab *psymtabs;
214*5796c8dcSSimon Schubert 
215*5796c8dcSSimon Schubert     /* Map addresses to the entries of PSYMTABS.  It would be more efficient to
216*5796c8dcSSimon Schubert        have a map per the whole process but ADDRMAP cannot selectively remove
217*5796c8dcSSimon Schubert        its items during FREE_OBJFILE.  This mapping is already present even for
218*5796c8dcSSimon Schubert        PARTIAL_SYMTABs which still have no corresponding full SYMTABs read.  */
219*5796c8dcSSimon Schubert 
220*5796c8dcSSimon Schubert     struct addrmap *psymtabs_addrmap;
221*5796c8dcSSimon Schubert 
222*5796c8dcSSimon Schubert     /* List of freed partial symtabs, available for re-use */
223*5796c8dcSSimon Schubert 
224*5796c8dcSSimon Schubert     struct partial_symtab *free_psymtabs;
225*5796c8dcSSimon Schubert 
226*5796c8dcSSimon Schubert     /* The object file's BFD.  Can be null if the objfile contains only
227*5796c8dcSSimon Schubert        minimal symbols, e.g. the run time common symbols for SunOS4.  */
228*5796c8dcSSimon Schubert 
229*5796c8dcSSimon Schubert     bfd *obfd;
230*5796c8dcSSimon Schubert 
231*5796c8dcSSimon Schubert     /* The gdbarch associated with the BFD.  Note that this gdbarch is
232*5796c8dcSSimon Schubert        determined solely from BFD information, without looking at target
233*5796c8dcSSimon Schubert        information.  The gdbarch determined from a running target may
234*5796c8dcSSimon Schubert        differ from this e.g. with respect to register types and names.  */
235*5796c8dcSSimon Schubert 
236*5796c8dcSSimon Schubert     struct gdbarch *gdbarch;
237*5796c8dcSSimon Schubert 
238*5796c8dcSSimon Schubert     /* The modification timestamp of the object file, as of the last time
239*5796c8dcSSimon Schubert        we read its symbols.  */
240*5796c8dcSSimon Schubert 
241*5796c8dcSSimon Schubert     long mtime;
242*5796c8dcSSimon Schubert 
243*5796c8dcSSimon Schubert     /* Obstack to hold objects that should be freed when we load a new symbol
244*5796c8dcSSimon Schubert        table from this object file. */
245*5796c8dcSSimon Schubert 
246*5796c8dcSSimon Schubert     struct obstack objfile_obstack;
247*5796c8dcSSimon Schubert 
248*5796c8dcSSimon Schubert     /* A byte cache where we can stash arbitrary "chunks" of bytes that
249*5796c8dcSSimon Schubert        will not change. */
250*5796c8dcSSimon Schubert 
251*5796c8dcSSimon Schubert     struct bcache *psymbol_cache;	/* Byte cache for partial syms */
252*5796c8dcSSimon Schubert     struct bcache *macro_cache;          /* Byte cache for macros */
253*5796c8dcSSimon Schubert 
254*5796c8dcSSimon Schubert     /* Hash table for mapping symbol names to demangled names.  Each
255*5796c8dcSSimon Schubert        entry in the hash table is actually two consecutive strings,
256*5796c8dcSSimon Schubert        both null-terminated; the first one is a mangled or linkage
257*5796c8dcSSimon Schubert        name, and the second is the demangled name or just a zero byte
258*5796c8dcSSimon Schubert        if the name doesn't demangle.  */
259*5796c8dcSSimon Schubert     struct htab *demangled_names_hash;
260*5796c8dcSSimon Schubert 
261*5796c8dcSSimon Schubert     /* Vectors of all partial symbols read in from file.  The actual data
262*5796c8dcSSimon Schubert        is stored in the objfile_obstack. */
263*5796c8dcSSimon Schubert 
264*5796c8dcSSimon Schubert     struct psymbol_allocation_list global_psymbols;
265*5796c8dcSSimon Schubert     struct psymbol_allocation_list static_psymbols;
266*5796c8dcSSimon Schubert 
267*5796c8dcSSimon Schubert     /* Each file contains a pointer to an array of minimal symbols for all
268*5796c8dcSSimon Schubert        global symbols that are defined within the file.  The array is terminated
269*5796c8dcSSimon Schubert        by a "null symbol", one that has a NULL pointer for the name and a zero
270*5796c8dcSSimon Schubert        value for the address.  This makes it easy to walk through the array
271*5796c8dcSSimon Schubert        when passed a pointer to somewhere in the middle of it.  There is also
272*5796c8dcSSimon Schubert        a count of the number of symbols, which does not include the terminating
273*5796c8dcSSimon Schubert        null symbol.  The array itself, as well as all the data that it points
274*5796c8dcSSimon Schubert        to, should be allocated on the objfile_obstack for this file. */
275*5796c8dcSSimon Schubert 
276*5796c8dcSSimon Schubert     struct minimal_symbol *msymbols;
277*5796c8dcSSimon Schubert     int minimal_symbol_count;
278*5796c8dcSSimon Schubert 
279*5796c8dcSSimon Schubert     /* This is a hash table used to index the minimal symbols by name.  */
280*5796c8dcSSimon Schubert 
281*5796c8dcSSimon Schubert     struct minimal_symbol *msymbol_hash[MINIMAL_SYMBOL_HASH_SIZE];
282*5796c8dcSSimon Schubert 
283*5796c8dcSSimon Schubert     /* This hash table is used to index the minimal symbols by their
284*5796c8dcSSimon Schubert        demangled names.  */
285*5796c8dcSSimon Schubert 
286*5796c8dcSSimon Schubert     struct minimal_symbol *msymbol_demangled_hash[MINIMAL_SYMBOL_HASH_SIZE];
287*5796c8dcSSimon Schubert 
288*5796c8dcSSimon Schubert     /* Structure which keeps track of functions that manipulate objfile's
289*5796c8dcSSimon Schubert        of the same type as this objfile.  I.E. the function to read partial
290*5796c8dcSSimon Schubert        symbols for example.  Note that this structure is in statically
291*5796c8dcSSimon Schubert        allocated memory, and is shared by all objfiles that use the
292*5796c8dcSSimon Schubert        object module reader of this type. */
293*5796c8dcSSimon Schubert 
294*5796c8dcSSimon Schubert     struct sym_fns *sf;
295*5796c8dcSSimon Schubert 
296*5796c8dcSSimon Schubert     /* The per-objfile information about the entry point, the scope (file/func)
297*5796c8dcSSimon Schubert        containing the entry point, and the scope of the user's main() func. */
298*5796c8dcSSimon Schubert 
299*5796c8dcSSimon Schubert     struct entry_info ei;
300*5796c8dcSSimon Schubert 
301*5796c8dcSSimon Schubert     /* Information about stabs.  Will be filled in with a dbx_symfile_info
302*5796c8dcSSimon Schubert        struct by those readers that need it. */
303*5796c8dcSSimon Schubert     /* NOTE: cagney/2004-10-23: This has been replaced by per-objfile
304*5796c8dcSSimon Schubert        data points implemented using "data" and "num_data" below.  For
305*5796c8dcSSimon Schubert        an example of how to use this replacement, see "objfile_data"
306*5796c8dcSSimon Schubert        in "mips-tdep.c".  */
307*5796c8dcSSimon Schubert 
308*5796c8dcSSimon Schubert     struct dbx_symfile_info *deprecated_sym_stab_info;
309*5796c8dcSSimon Schubert 
310*5796c8dcSSimon Schubert     /* Hook for information for use by the symbol reader (currently used
311*5796c8dcSSimon Schubert        for information shared by sym_init and sym_read).  It is
312*5796c8dcSSimon Schubert        typically a pointer to malloc'd memory.  The symbol reader's finish
313*5796c8dcSSimon Schubert        function is responsible for freeing the memory thusly allocated.  */
314*5796c8dcSSimon Schubert     /* NOTE: cagney/2004-10-23: This has been replaced by per-objfile
315*5796c8dcSSimon Schubert        data points implemented using "data" and "num_data" below.  For
316*5796c8dcSSimon Schubert        an example of how to use this replacement, see "objfile_data"
317*5796c8dcSSimon Schubert        in "mips-tdep.c".  */
318*5796c8dcSSimon Schubert 
319*5796c8dcSSimon Schubert     void *deprecated_sym_private;
320*5796c8dcSSimon Schubert 
321*5796c8dcSSimon Schubert     /* Per objfile data-pointers required by other GDB modules.  */
322*5796c8dcSSimon Schubert     /* FIXME: kettenis/20030711: This mechanism could replace
323*5796c8dcSSimon Schubert        deprecated_sym_stab_info and deprecated_sym_private
324*5796c8dcSSimon Schubert        entirely.  */
325*5796c8dcSSimon Schubert 
326*5796c8dcSSimon Schubert     void **data;
327*5796c8dcSSimon Schubert     unsigned num_data;
328*5796c8dcSSimon Schubert 
329*5796c8dcSSimon Schubert     /* Set of relocation offsets to apply to each section.
330*5796c8dcSSimon Schubert        Currently on the objfile_obstack (which makes no sense, but I'm
331*5796c8dcSSimon Schubert        not sure it's harming anything).
332*5796c8dcSSimon Schubert 
333*5796c8dcSSimon Schubert        These offsets indicate that all symbols (including partial and
334*5796c8dcSSimon Schubert        minimal symbols) which have been read have been relocated by this
335*5796c8dcSSimon Schubert        much.  Symbols which are yet to be read need to be relocated by
336*5796c8dcSSimon Schubert        it.  */
337*5796c8dcSSimon Schubert 
338*5796c8dcSSimon Schubert     struct section_offsets *section_offsets;
339*5796c8dcSSimon Schubert     int num_sections;
340*5796c8dcSSimon Schubert 
341*5796c8dcSSimon Schubert     /* Indexes in the section_offsets array. These are initialized by the
342*5796c8dcSSimon Schubert        *_symfile_offsets() family of functions (som_symfile_offsets,
343*5796c8dcSSimon Schubert        xcoff_symfile_offsets, default_symfile_offsets). In theory they
344*5796c8dcSSimon Schubert        should correspond to the section indexes used by bfd for the
345*5796c8dcSSimon Schubert        current objfile. The exception to this for the time being is the
346*5796c8dcSSimon Schubert        SOM version. */
347*5796c8dcSSimon Schubert 
348*5796c8dcSSimon Schubert     int sect_index_text;
349*5796c8dcSSimon Schubert     int sect_index_data;
350*5796c8dcSSimon Schubert     int sect_index_bss;
351*5796c8dcSSimon Schubert     int sect_index_rodata;
352*5796c8dcSSimon Schubert 
353*5796c8dcSSimon Schubert     /* These pointers are used to locate the section table, which
354*5796c8dcSSimon Schubert        among other things, is used to map pc addresses into sections.
355*5796c8dcSSimon Schubert        SECTIONS points to the first entry in the table, and
356*5796c8dcSSimon Schubert        SECTIONS_END points to the first location past the last entry
357*5796c8dcSSimon Schubert        in the table.  Currently the table is stored on the
358*5796c8dcSSimon Schubert        objfile_obstack (which makes no sense, but I'm not sure it's
359*5796c8dcSSimon Schubert        harming anything).  */
360*5796c8dcSSimon Schubert 
361*5796c8dcSSimon Schubert     struct obj_section
362*5796c8dcSSimon Schubert      *sections, *sections_end;
363*5796c8dcSSimon Schubert 
364*5796c8dcSSimon Schubert     /* Link to objfile that contains the debug symbols for this one.
365*5796c8dcSSimon Schubert        One is loaded if this file has an debug link to an existing
366*5796c8dcSSimon Schubert        debug file with the right checksum */
367*5796c8dcSSimon Schubert     struct objfile *separate_debug_objfile;
368*5796c8dcSSimon Schubert 
369*5796c8dcSSimon Schubert     /* If this is a separate debug object, this is used as a link to the
370*5796c8dcSSimon Schubert        actual executable objfile. */
371*5796c8dcSSimon Schubert     struct objfile *separate_debug_objfile_backlink;
372*5796c8dcSSimon Schubert 
373*5796c8dcSSimon Schubert     /* Place to stash various statistics about this objfile */
374*5796c8dcSSimon Schubert       OBJSTATS;
375*5796c8dcSSimon Schubert 
376*5796c8dcSSimon Schubert     /* A symtab that the C++ code uses to stash special symbols
377*5796c8dcSSimon Schubert        associated to namespaces.  */
378*5796c8dcSSimon Schubert 
379*5796c8dcSSimon Schubert     /* FIXME/carlton-2003-06-27: Delete this in a few years once
380*5796c8dcSSimon Schubert        "possible namespace symbols" go away.  */
381*5796c8dcSSimon Schubert     struct symtab *cp_namespace_symtab;
382*5796c8dcSSimon Schubert   };
383*5796c8dcSSimon Schubert 
384*5796c8dcSSimon Schubert /* Defines for the objfile flag word. */
385*5796c8dcSSimon Schubert 
386*5796c8dcSSimon Schubert /* When an object file has its functions reordered (currently Irix-5.2
387*5796c8dcSSimon Schubert    shared libraries exhibit this behaviour), we will need an expensive
388*5796c8dcSSimon Schubert    algorithm to locate a partial symtab or symtab via an address.
389*5796c8dcSSimon Schubert    To avoid this penalty for normal object files, we use this flag,
390*5796c8dcSSimon Schubert    whose setting is determined upon symbol table read in.  */
391*5796c8dcSSimon Schubert 
392*5796c8dcSSimon Schubert #define OBJF_REORDERED	(1 << 0)	/* Functions are reordered */
393*5796c8dcSSimon Schubert 
394*5796c8dcSSimon Schubert /* Distinguish between an objfile for a shared library and a "vanilla"
395*5796c8dcSSimon Schubert    objfile. (If not set, the objfile may still actually be a solib.
396*5796c8dcSSimon Schubert    This can happen if the user created the objfile by using the
397*5796c8dcSSimon Schubert    add-symbol-file command.  GDB doesn't in that situation actually
398*5796c8dcSSimon Schubert    check whether the file is a solib.  Rather, the target's
399*5796c8dcSSimon Schubert    implementation of the solib interface is responsible for setting
400*5796c8dcSSimon Schubert    this flag when noticing solibs used by an inferior.)  */
401*5796c8dcSSimon Schubert 
402*5796c8dcSSimon Schubert #define OBJF_SHARED     (1 << 1)	/* From a shared library */
403*5796c8dcSSimon Schubert 
404*5796c8dcSSimon Schubert /* User requested that this objfile be read in it's entirety. */
405*5796c8dcSSimon Schubert 
406*5796c8dcSSimon Schubert #define OBJF_READNOW	(1 << 2)	/* Immediate full read */
407*5796c8dcSSimon Schubert 
408*5796c8dcSSimon Schubert /* This objfile was created because the user explicitly caused it
409*5796c8dcSSimon Schubert    (e.g., used the add-symbol-file command).  This bit offers a way
410*5796c8dcSSimon Schubert    for run_command to remove old objfile entries which are no longer
411*5796c8dcSSimon Schubert    valid (i.e., are associated with an old inferior), but to preserve
412*5796c8dcSSimon Schubert    ones that the user explicitly loaded via the add-symbol-file
413*5796c8dcSSimon Schubert    command. */
414*5796c8dcSSimon Schubert 
415*5796c8dcSSimon Schubert #define OBJF_USERLOADED	(1 << 3)	/* User loaded */
416*5796c8dcSSimon Schubert 
417*5796c8dcSSimon Schubert /* The object file that the main symbol table was loaded from (e.g. the
418*5796c8dcSSimon Schubert    argument to the "symbol-file" or "file" command).  */
419*5796c8dcSSimon Schubert 
420*5796c8dcSSimon Schubert extern struct objfile *symfile_objfile;
421*5796c8dcSSimon Schubert 
422*5796c8dcSSimon Schubert /* The object file that contains the runtime common minimal symbols
423*5796c8dcSSimon Schubert    for SunOS4. Note that this objfile has no associated BFD.  */
424*5796c8dcSSimon Schubert 
425*5796c8dcSSimon Schubert extern struct objfile *rt_common_objfile;
426*5796c8dcSSimon Schubert 
427*5796c8dcSSimon Schubert /* When we need to allocate a new type, we need to know which objfile_obstack
428*5796c8dcSSimon Schubert    to allocate the type on, since there is one for each objfile.  The places
429*5796c8dcSSimon Schubert    where types are allocated are deeply buried in function call hierarchies
430*5796c8dcSSimon Schubert    which know nothing about objfiles, so rather than trying to pass a
431*5796c8dcSSimon Schubert    particular objfile down to them, we just do an end run around them and
432*5796c8dcSSimon Schubert    set current_objfile to be whatever objfile we expect to be using at the
433*5796c8dcSSimon Schubert    time types are being allocated.  For instance, when we start reading
434*5796c8dcSSimon Schubert    symbols for a particular objfile, we set current_objfile to point to that
435*5796c8dcSSimon Schubert    objfile, and when we are done, we set it back to NULL, to ensure that we
436*5796c8dcSSimon Schubert    never put a type someplace other than where we are expecting to put it.
437*5796c8dcSSimon Schubert    FIXME:  Maybe we should review the entire type handling system and
438*5796c8dcSSimon Schubert    see if there is a better way to avoid this problem. */
439*5796c8dcSSimon Schubert 
440*5796c8dcSSimon Schubert extern struct objfile *current_objfile;
441*5796c8dcSSimon Schubert 
442*5796c8dcSSimon Schubert /* All known objfiles are kept in a linked list.  This points to the
443*5796c8dcSSimon Schubert    root of this list. */
444*5796c8dcSSimon Schubert 
445*5796c8dcSSimon Schubert extern struct objfile *object_files;
446*5796c8dcSSimon Schubert 
447*5796c8dcSSimon Schubert /* Declarations for functions defined in objfiles.c */
448*5796c8dcSSimon Schubert 
449*5796c8dcSSimon Schubert extern struct objfile *allocate_objfile (bfd *, int);
450*5796c8dcSSimon Schubert 
451*5796c8dcSSimon Schubert extern struct gdbarch *get_objfile_arch (struct objfile *);
452*5796c8dcSSimon Schubert 
453*5796c8dcSSimon Schubert extern void init_entry_point_info (struct objfile *);
454*5796c8dcSSimon Schubert 
455*5796c8dcSSimon Schubert extern CORE_ADDR entry_point_address (void);
456*5796c8dcSSimon Schubert 
457*5796c8dcSSimon Schubert extern int build_objfile_section_table (struct objfile *);
458*5796c8dcSSimon Schubert 
459*5796c8dcSSimon Schubert extern void terminate_minimal_symbol_table (struct objfile *objfile);
460*5796c8dcSSimon Schubert 
461*5796c8dcSSimon Schubert extern void put_objfile_before (struct objfile *, struct objfile *);
462*5796c8dcSSimon Schubert 
463*5796c8dcSSimon Schubert extern void objfile_to_front (struct objfile *);
464*5796c8dcSSimon Schubert 
465*5796c8dcSSimon Schubert extern void unlink_objfile (struct objfile *);
466*5796c8dcSSimon Schubert 
467*5796c8dcSSimon Schubert extern void free_objfile (struct objfile *);
468*5796c8dcSSimon Schubert 
469*5796c8dcSSimon Schubert extern struct cleanup *make_cleanup_free_objfile (struct objfile *);
470*5796c8dcSSimon Schubert 
471*5796c8dcSSimon Schubert extern void free_all_objfiles (void);
472*5796c8dcSSimon Schubert 
473*5796c8dcSSimon Schubert extern void objfile_relocate (struct objfile *, struct section_offsets *);
474*5796c8dcSSimon Schubert 
475*5796c8dcSSimon Schubert extern int objfile_has_partial_symbols (struct objfile *objfile);
476*5796c8dcSSimon Schubert 
477*5796c8dcSSimon Schubert extern int objfile_has_full_symbols (struct objfile *objfile);
478*5796c8dcSSimon Schubert 
479*5796c8dcSSimon Schubert extern int have_partial_symbols (void);
480*5796c8dcSSimon Schubert 
481*5796c8dcSSimon Schubert extern int have_full_symbols (void);
482*5796c8dcSSimon Schubert 
483*5796c8dcSSimon Schubert extern void objfiles_changed (void);
484*5796c8dcSSimon Schubert 
485*5796c8dcSSimon Schubert /* This operation deletes all objfile entries that represent solibs that
486*5796c8dcSSimon Schubert    weren't explicitly loaded by the user, via e.g., the add-symbol-file
487*5796c8dcSSimon Schubert    command.
488*5796c8dcSSimon Schubert  */
489*5796c8dcSSimon Schubert extern void objfile_purge_solibs (void);
490*5796c8dcSSimon Schubert 
491*5796c8dcSSimon Schubert /* Functions for dealing with the minimal symbol table, really a misc
492*5796c8dcSSimon Schubert    address<->symbol mapping for things we don't have debug symbols for.  */
493*5796c8dcSSimon Schubert 
494*5796c8dcSSimon Schubert extern int have_minimal_symbols (void);
495*5796c8dcSSimon Schubert 
496*5796c8dcSSimon Schubert extern struct obj_section *find_pc_section (CORE_ADDR pc);
497*5796c8dcSSimon Schubert 
498*5796c8dcSSimon Schubert extern int in_plt_section (CORE_ADDR, char *);
499*5796c8dcSSimon Schubert 
500*5796c8dcSSimon Schubert /* Keep a registry of per-objfile data-pointers required by other GDB
501*5796c8dcSSimon Schubert    modules.  */
502*5796c8dcSSimon Schubert 
503*5796c8dcSSimon Schubert /* Allocate an entry in the per-objfile registry.  */
504*5796c8dcSSimon Schubert extern const struct objfile_data *register_objfile_data (void);
505*5796c8dcSSimon Schubert 
506*5796c8dcSSimon Schubert /* Allocate an entry in the per-objfile registry.
507*5796c8dcSSimon Schubert    SAVE and FREE are called when clearing objfile data.
508*5796c8dcSSimon Schubert    First all registered SAVE functions are called.
509*5796c8dcSSimon Schubert    Then all registered FREE functions are called.
510*5796c8dcSSimon Schubert    Either or both of SAVE, FREE may be NULL.  */
511*5796c8dcSSimon Schubert extern const struct objfile_data *register_objfile_data_with_cleanup
512*5796c8dcSSimon Schubert   (void (*save) (struct objfile *, void *),
513*5796c8dcSSimon Schubert    void (*free) (struct objfile *, void *));
514*5796c8dcSSimon Schubert 
515*5796c8dcSSimon Schubert extern void clear_objfile_data (struct objfile *objfile);
516*5796c8dcSSimon Schubert extern void set_objfile_data (struct objfile *objfile,
517*5796c8dcSSimon Schubert 			      const struct objfile_data *data, void *value);
518*5796c8dcSSimon Schubert extern void *objfile_data (struct objfile *objfile,
519*5796c8dcSSimon Schubert 			   const struct objfile_data *data);
520*5796c8dcSSimon Schubert 
521*5796c8dcSSimon Schubert extern struct bfd *gdb_bfd_ref (struct bfd *abfd);
522*5796c8dcSSimon Schubert extern void gdb_bfd_unref (struct bfd *abfd);
523*5796c8dcSSimon Schubert 
524*5796c8dcSSimon Schubert 
525*5796c8dcSSimon Schubert /* Traverse all object files.  ALL_OBJFILES_SAFE works even if you delete
526*5796c8dcSSimon Schubert    the objfile during the traversal.  */
527*5796c8dcSSimon Schubert 
528*5796c8dcSSimon Schubert #define	ALL_OBJFILES(obj) \
529*5796c8dcSSimon Schubert   for ((obj) = object_files; (obj) != NULL; (obj) = (obj)->next)
530*5796c8dcSSimon Schubert 
531*5796c8dcSSimon Schubert #define	ALL_OBJFILES_SAFE(obj,nxt) \
532*5796c8dcSSimon Schubert   for ((obj) = object_files; 	   \
533*5796c8dcSSimon Schubert        (obj) != NULL? ((nxt)=(obj)->next,1) :0;	\
534*5796c8dcSSimon Schubert        (obj) = (nxt))
535*5796c8dcSSimon Schubert 
536*5796c8dcSSimon Schubert /* Traverse all symtabs in one objfile.  */
537*5796c8dcSSimon Schubert 
538*5796c8dcSSimon Schubert #define	ALL_OBJFILE_SYMTABS(objfile, s) \
539*5796c8dcSSimon Schubert     for ((s) = (objfile) -> symtabs; (s) != NULL; (s) = (s) -> next)
540*5796c8dcSSimon Schubert 
541*5796c8dcSSimon Schubert /* Traverse all psymtabs in one objfile.  */
542*5796c8dcSSimon Schubert 
543*5796c8dcSSimon Schubert #define	ALL_OBJFILE_PSYMTABS(objfile, p) \
544*5796c8dcSSimon Schubert     for ((p) = (objfile) -> psymtabs; (p) != NULL; (p) = (p) -> next)
545*5796c8dcSSimon Schubert 
546*5796c8dcSSimon Schubert /* Traverse all minimal symbols in one objfile.  */
547*5796c8dcSSimon Schubert 
548*5796c8dcSSimon Schubert #define	ALL_OBJFILE_MSYMBOLS(objfile, m) \
549*5796c8dcSSimon Schubert     for ((m) = (objfile) -> msymbols; SYMBOL_LINKAGE_NAME(m) != NULL; (m)++)
550*5796c8dcSSimon Schubert 
551*5796c8dcSSimon Schubert /* Traverse all symtabs in all objfiles.  */
552*5796c8dcSSimon Schubert 
553*5796c8dcSSimon Schubert #define	ALL_SYMTABS(objfile, s) \
554*5796c8dcSSimon Schubert   ALL_OBJFILES (objfile)	 \
555*5796c8dcSSimon Schubert     ALL_OBJFILE_SYMTABS (objfile, s)
556*5796c8dcSSimon Schubert 
557*5796c8dcSSimon Schubert /* Traverse all symtabs in all objfiles, skipping included files
558*5796c8dcSSimon Schubert    (which share a blockvector with their primary symtab).  */
559*5796c8dcSSimon Schubert 
560*5796c8dcSSimon Schubert #define ALL_PRIMARY_SYMTABS(objfile, s) \
561*5796c8dcSSimon Schubert   ALL_OBJFILES (objfile)		\
562*5796c8dcSSimon Schubert     ALL_OBJFILE_SYMTABS (objfile, s)	\
563*5796c8dcSSimon Schubert       if ((s)->primary)
564*5796c8dcSSimon Schubert 
565*5796c8dcSSimon Schubert /* Traverse all psymtabs in all objfiles.  */
566*5796c8dcSSimon Schubert 
567*5796c8dcSSimon Schubert #define	ALL_PSYMTABS(objfile, p) \
568*5796c8dcSSimon Schubert   ALL_OBJFILES (objfile)	 \
569*5796c8dcSSimon Schubert     ALL_OBJFILE_PSYMTABS (objfile, p)
570*5796c8dcSSimon Schubert 
571*5796c8dcSSimon Schubert /* Traverse all minimal symbols in all objfiles.  */
572*5796c8dcSSimon Schubert 
573*5796c8dcSSimon Schubert #define	ALL_MSYMBOLS(objfile, m) \
574*5796c8dcSSimon Schubert   ALL_OBJFILES (objfile)	 \
575*5796c8dcSSimon Schubert     ALL_OBJFILE_MSYMBOLS (objfile, m)
576*5796c8dcSSimon Schubert 
577*5796c8dcSSimon Schubert #define ALL_OBJFILE_OSECTIONS(objfile, osect)	\
578*5796c8dcSSimon Schubert   for (osect = objfile->sections; osect < objfile->sections_end; osect++)
579*5796c8dcSSimon Schubert 
580*5796c8dcSSimon Schubert #define ALL_OBJSECTIONS(objfile, osect)		\
581*5796c8dcSSimon Schubert   ALL_OBJFILES (objfile)			\
582*5796c8dcSSimon Schubert     ALL_OBJFILE_OSECTIONS (objfile, osect)
583*5796c8dcSSimon Schubert 
584*5796c8dcSSimon Schubert #define SECT_OFF_DATA(objfile) \
585*5796c8dcSSimon Schubert      ((objfile->sect_index_data == -1) \
586*5796c8dcSSimon Schubert       ? (internal_error (__FILE__, __LINE__, _("sect_index_data not initialized")), -1) \
587*5796c8dcSSimon Schubert       : objfile->sect_index_data)
588*5796c8dcSSimon Schubert 
589*5796c8dcSSimon Schubert #define SECT_OFF_RODATA(objfile) \
590*5796c8dcSSimon Schubert      ((objfile->sect_index_rodata == -1) \
591*5796c8dcSSimon Schubert       ? (internal_error (__FILE__, __LINE__, _("sect_index_rodata not initialized")), -1) \
592*5796c8dcSSimon Schubert       : objfile->sect_index_rodata)
593*5796c8dcSSimon Schubert 
594*5796c8dcSSimon Schubert #define SECT_OFF_TEXT(objfile) \
595*5796c8dcSSimon Schubert      ((objfile->sect_index_text == -1) \
596*5796c8dcSSimon Schubert       ? (internal_error (__FILE__, __LINE__, _("sect_index_text not initialized")), -1) \
597*5796c8dcSSimon Schubert       : objfile->sect_index_text)
598*5796c8dcSSimon Schubert 
599*5796c8dcSSimon Schubert /* Sometimes the .bss section is missing from the objfile, so we don't
600*5796c8dcSSimon Schubert    want to die here. Let the users of SECT_OFF_BSS deal with an
601*5796c8dcSSimon Schubert    uninitialized section index. */
602*5796c8dcSSimon Schubert #define SECT_OFF_BSS(objfile) (objfile)->sect_index_bss
603*5796c8dcSSimon Schubert 
604*5796c8dcSSimon Schubert /* Answer whether there is more than one object file loaded.  */
605*5796c8dcSSimon Schubert 
606*5796c8dcSSimon Schubert #define MULTI_OBJFILE_P() (object_files && object_files->next)
607*5796c8dcSSimon Schubert 
608*5796c8dcSSimon Schubert #endif /* !defined (OBJFILES_H) */
609