xref: /dflybsd-src/contrib/gdb-7/gdb/objfiles.h (revision de8e141f24382815c10a4012d209bbbf7abf1112)
15796c8dcSSimon Schubert /* Definitions for symbol file management in GDB.
25796c8dcSSimon Schubert 
3*ef5ccd6cSJohn Marino    Copyright (C) 1992-2013 Free Software Foundation, Inc.
45796c8dcSSimon Schubert 
55796c8dcSSimon Schubert    This file is part of GDB.
65796c8dcSSimon Schubert 
75796c8dcSSimon Schubert    This program is free software; you can redistribute it and/or modify
85796c8dcSSimon Schubert    it under the terms of the GNU General Public License as published by
95796c8dcSSimon Schubert    the Free Software Foundation; either version 3 of the License, or
105796c8dcSSimon Schubert    (at your option) any later version.
115796c8dcSSimon Schubert 
125796c8dcSSimon Schubert    This program is distributed in the hope that it will be useful,
135796c8dcSSimon Schubert    but WITHOUT ANY WARRANTY; without even the implied warranty of
145796c8dcSSimon Schubert    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
155796c8dcSSimon Schubert    GNU General Public License for more details.
165796c8dcSSimon Schubert 
175796c8dcSSimon Schubert    You should have received a copy of the GNU General Public License
185796c8dcSSimon Schubert    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
195796c8dcSSimon Schubert 
205796c8dcSSimon Schubert #if !defined (OBJFILES_H)
215796c8dcSSimon Schubert #define OBJFILES_H
225796c8dcSSimon Schubert 
235796c8dcSSimon Schubert #include "gdb_obstack.h"	/* For obstack internals.  */
24c50c785cSJohn Marino #include "symfile.h"		/* For struct psymbol_allocation_list.  */
25cf7f2e2dSJohn Marino #include "progspace.h"
26*ef5ccd6cSJohn Marino #include "registry.h"
275796c8dcSSimon Schubert 
285796c8dcSSimon Schubert struct bcache;
295796c8dcSSimon Schubert struct htab;
305796c8dcSSimon Schubert struct symtab;
315796c8dcSSimon Schubert struct objfile_data;
325796c8dcSSimon Schubert 
335796c8dcSSimon Schubert /* This structure maintains information on a per-objfile basis about the
345796c8dcSSimon Schubert    "entry point" of the objfile, and the scope within which the entry point
355796c8dcSSimon Schubert    exists.  It is possible that gdb will see more than one objfile that is
365796c8dcSSimon Schubert    executable, each with its own entry point.
375796c8dcSSimon Schubert 
385796c8dcSSimon Schubert    For example, for dynamically linked executables in SVR4, the dynamic linker
395796c8dcSSimon Schubert    code is contained within the shared C library, which is actually executable
405796c8dcSSimon Schubert    and is run by the kernel first when an exec is done of a user executable
415796c8dcSSimon Schubert    that is dynamically linked.  The dynamic linker within the shared C library
425796c8dcSSimon Schubert    then maps in the various program segments in the user executable and jumps
435796c8dcSSimon Schubert    to the user executable's recorded entry point, as if the call had been made
445796c8dcSSimon Schubert    directly by the kernel.
455796c8dcSSimon Schubert 
465796c8dcSSimon Schubert    The traditional gdb method of using this info was to use the
475796c8dcSSimon Schubert    recorded entry point to set the entry-file's lowpc and highpc from
485796c8dcSSimon Schubert    the debugging information, where these values are the starting
495796c8dcSSimon Schubert    address (inclusive) and ending address (exclusive) of the
505796c8dcSSimon Schubert    instruction space in the executable which correspond to the
51c50c785cSJohn Marino    "startup file", i.e. crt0.o in most cases.  This file is assumed to
525796c8dcSSimon Schubert    be a startup file and frames with pc's inside it are treated as
535796c8dcSSimon Schubert    nonexistent.  Setting these variables is necessary so that
545796c8dcSSimon Schubert    backtraces do not fly off the bottom of the stack.
555796c8dcSSimon Schubert 
565796c8dcSSimon Schubert    NOTE: cagney/2003-09-09: It turns out that this "traditional"
575796c8dcSSimon Schubert    method doesn't work.  Corinna writes: ``It turns out that the call
585796c8dcSSimon Schubert    to test for "inside entry file" destroys a meaningful backtrace
595796c8dcSSimon Schubert    under some conditions.  E.g. the backtrace tests in the asm-source
605796c8dcSSimon Schubert    testcase are broken for some targets.  In this test the functions
615796c8dcSSimon Schubert    are all implemented as part of one file and the testcase is not
625796c8dcSSimon Schubert    necessarily linked with a start file (depending on the target).
635796c8dcSSimon Schubert    What happens is, that the first frame is printed normaly and
645796c8dcSSimon Schubert    following frames are treated as being inside the enttry file then.
655796c8dcSSimon Schubert    This way, only the #0 frame is printed in the backtrace output.''
665796c8dcSSimon Schubert    Ref "frame.c" "NOTE: vinschen/2003-04-01".
675796c8dcSSimon Schubert 
685796c8dcSSimon Schubert    Gdb also supports an alternate method to avoid running off the bottom
695796c8dcSSimon Schubert    of the stack.
705796c8dcSSimon Schubert 
715796c8dcSSimon Schubert    There are two frames that are "special", the frame for the function
725796c8dcSSimon Schubert    containing the process entry point, since it has no predecessor frame,
735796c8dcSSimon Schubert    and the frame for the function containing the user code entry point
745796c8dcSSimon Schubert    (the main() function), since all the predecessor frames are for the
755796c8dcSSimon Schubert    process startup code.  Since we have no guarantee that the linked
765796c8dcSSimon Schubert    in startup modules have any debugging information that gdb can use,
775796c8dcSSimon Schubert    we need to avoid following frame pointers back into frames that might
785796c8dcSSimon Schubert    have been built in the startup code, as we might get hopelessly
795796c8dcSSimon Schubert    confused.  However, we almost always have debugging information
805796c8dcSSimon Schubert    available for main().
815796c8dcSSimon Schubert 
825796c8dcSSimon Schubert    These variables are used to save the range of PC values which are
835796c8dcSSimon Schubert    valid within the main() function and within the function containing
845796c8dcSSimon Schubert    the process entry point.  If we always consider the frame for
855796c8dcSSimon Schubert    main() as the outermost frame when debugging user code, and the
865796c8dcSSimon Schubert    frame for the process entry point function as the outermost frame
875796c8dcSSimon Schubert    when debugging startup code, then all we have to do is have
885796c8dcSSimon Schubert    DEPRECATED_FRAME_CHAIN_VALID return false whenever a frame's
895796c8dcSSimon Schubert    current PC is within the range specified by these variables.  In
905796c8dcSSimon Schubert    essence, we set "ceilings" in the frame chain beyond which we will
915796c8dcSSimon Schubert    not proceed when following the frame chain back up the stack.
925796c8dcSSimon Schubert 
935796c8dcSSimon Schubert    A nice side effect is that we can still debug startup code without
945796c8dcSSimon Schubert    running off the end of the frame chain, assuming that we have usable
955796c8dcSSimon Schubert    debugging information in the startup modules, and if we choose to not
965796c8dcSSimon Schubert    use the block at main, or can't find it for some reason, everything
975796c8dcSSimon Schubert    still works as before.  And if we have no startup code debugging
985796c8dcSSimon Schubert    information but we do have usable information for main(), backtraces
995796c8dcSSimon Schubert    from user code don't go wandering off into the startup code.  */
1005796c8dcSSimon Schubert 
1015796c8dcSSimon Schubert struct entry_info
1025796c8dcSSimon Schubert   {
103cf7f2e2dSJohn Marino     /* The relocated value we should use for this objfile entry point.  */
1045796c8dcSSimon Schubert     CORE_ADDR entry_point;
1055796c8dcSSimon Schubert 
106cf7f2e2dSJohn Marino     /* Set to 1 iff ENTRY_POINT contains a valid value.  */
107cf7f2e2dSJohn Marino     unsigned entry_point_p : 1;
1085796c8dcSSimon Schubert   };
1095796c8dcSSimon Schubert 
1105796c8dcSSimon Schubert /* Sections in an objfile.  The section offsets are stored in the
1115796c8dcSSimon Schubert    OBJFILE.  */
1125796c8dcSSimon Schubert 
1135796c8dcSSimon Schubert struct obj_section
1145796c8dcSSimon Schubert   {
1155796c8dcSSimon Schubert     struct bfd_section *the_bfd_section;	/* BFD section pointer */
1165796c8dcSSimon Schubert 
1175796c8dcSSimon Schubert     /* Objfile this section is part of.  */
1185796c8dcSSimon Schubert     struct objfile *objfile;
1195796c8dcSSimon Schubert 
1205796c8dcSSimon Schubert     /* True if this "overlay section" is mapped into an "overlay region".  */
1215796c8dcSSimon Schubert     int ovly_mapped;
1225796c8dcSSimon Schubert   };
1235796c8dcSSimon Schubert 
1245796c8dcSSimon Schubert /* Relocation offset applied to S.  */
1255796c8dcSSimon Schubert #define obj_section_offset(s)						\
1265796c8dcSSimon Schubert   (((s)->objfile->section_offsets)->offsets[(s)->the_bfd_section->index])
1275796c8dcSSimon Schubert 
1285796c8dcSSimon Schubert /* The memory address of section S (vma + offset).  */
1295796c8dcSSimon Schubert #define obj_section_addr(s)				      		\
130a45ae5f8SJohn Marino   (bfd_get_section_vma ((s)->objfile->obfd, s->the_bfd_section)		\
1315796c8dcSSimon Schubert    + obj_section_offset (s))
1325796c8dcSSimon Schubert 
1335796c8dcSSimon Schubert /* The one-passed-the-end memory address of section S
1345796c8dcSSimon Schubert    (vma + size + offset).  */
1355796c8dcSSimon Schubert #define obj_section_endaddr(s)						\
136a45ae5f8SJohn Marino   (bfd_get_section_vma ((s)->objfile->obfd, s->the_bfd_section)		\
1375796c8dcSSimon Schubert    + bfd_get_section_size ((s)->the_bfd_section)			\
1385796c8dcSSimon Schubert    + obj_section_offset (s))
1395796c8dcSSimon Schubert 
1405796c8dcSSimon Schubert /* The "objstats" structure provides a place for gdb to record some
1415796c8dcSSimon Schubert    interesting information about its internal state at runtime, on a
1425796c8dcSSimon Schubert    per objfile basis, such as information about the number of symbols
1435796c8dcSSimon Schubert    read, size of string table (if any), etc.  */
1445796c8dcSSimon Schubert 
1455796c8dcSSimon Schubert struct objstats
1465796c8dcSSimon Schubert   {
1475796c8dcSSimon Schubert     int n_minsyms;		/* Number of minimal symbols read */
1485796c8dcSSimon Schubert     int n_psyms;		/* Number of partial symbols read */
1495796c8dcSSimon Schubert     int n_syms;			/* Number of full symbols read */
1505796c8dcSSimon Schubert     int n_stabs;		/* Number of ".stabs" read (if applicable) */
1515796c8dcSSimon Schubert     int n_types;		/* Number of types */
1525796c8dcSSimon Schubert     int sz_strtab;		/* Size of stringtable, (if applicable) */
1535796c8dcSSimon Schubert   };
1545796c8dcSSimon Schubert 
1555796c8dcSSimon Schubert #define OBJSTAT(objfile, expr) (objfile -> stats.expr)
1565796c8dcSSimon Schubert #define OBJSTATS struct objstats stats
1575796c8dcSSimon Schubert extern void print_objfile_statistics (void);
1585796c8dcSSimon Schubert extern void print_symbol_bcache_statistics (void);
1595796c8dcSSimon Schubert 
1605796c8dcSSimon Schubert /* Number of entries in the minimal symbol hash table.  */
1615796c8dcSSimon Schubert #define MINIMAL_SYMBOL_HASH_SIZE 2039
1625796c8dcSSimon Schubert 
163*ef5ccd6cSJohn Marino /* Some objfile data is hung off the BFD.  This enables sharing of the
164*ef5ccd6cSJohn Marino    data across all objfiles using the BFD.  The data is stored in an
165*ef5ccd6cSJohn Marino    instance of this structure, and associated with the BFD using the
166*ef5ccd6cSJohn Marino    registry system.  */
167*ef5ccd6cSJohn Marino 
168*ef5ccd6cSJohn Marino struct objfile_per_bfd_storage
169*ef5ccd6cSJohn Marino {
170*ef5ccd6cSJohn Marino   /* The storage has an obstack of its own.  */
171*ef5ccd6cSJohn Marino 
172*ef5ccd6cSJohn Marino   struct obstack storage_obstack;
173*ef5ccd6cSJohn Marino 
174*ef5ccd6cSJohn Marino   /* Byte cache for file names.  */
175*ef5ccd6cSJohn Marino 
176*ef5ccd6cSJohn Marino   struct bcache *filename_cache;
177*ef5ccd6cSJohn Marino 
178*ef5ccd6cSJohn Marino   /* Byte cache for macros.  */
179*ef5ccd6cSJohn Marino   struct bcache *macro_cache;
180*ef5ccd6cSJohn Marino };
181*ef5ccd6cSJohn Marino 
1825796c8dcSSimon Schubert /* Master structure for keeping track of each file from which
1835796c8dcSSimon Schubert    gdb reads symbols.  There are several ways these get allocated: 1.
1845796c8dcSSimon Schubert    The main symbol file, symfile_objfile, set by the symbol-file command,
1855796c8dcSSimon Schubert    2.  Additional symbol files added by the add-symbol-file command,
1865796c8dcSSimon Schubert    3.  Shared library objfiles, added by ADD_SOLIB,  4.  symbol files
1875796c8dcSSimon Schubert    for modules that were loaded when GDB attached to a remote system
1885796c8dcSSimon Schubert    (see remote-vx.c).  */
1895796c8dcSSimon Schubert 
1905796c8dcSSimon Schubert struct objfile
1915796c8dcSSimon Schubert   {
1925796c8dcSSimon Schubert 
1935796c8dcSSimon Schubert     /* All struct objfile's are chained together by their next pointers.
194a45ae5f8SJohn Marino        The program space field "objfiles"  (frequently referenced via
195a45ae5f8SJohn Marino        the macro "object_files") points to the first link in this
196a45ae5f8SJohn Marino        chain.  */
1975796c8dcSSimon Schubert 
1985796c8dcSSimon Schubert     struct objfile *next;
1995796c8dcSSimon Schubert 
200*ef5ccd6cSJohn Marino     /* The object file's name, tilde-expanded and absolute.  This
201*ef5ccd6cSJohn Marino        pointer is never NULL.  This does not have to be freed; it is
202*ef5ccd6cSJohn Marino        guaranteed to have a lifetime at least as long as the objfile.  */
2035796c8dcSSimon Schubert 
2045796c8dcSSimon Schubert     char *name;
2055796c8dcSSimon Schubert 
206c50c785cSJohn Marino     CORE_ADDR addr_low;
207c50c785cSJohn Marino 
208a45ae5f8SJohn Marino     /* Some flag bits for this objfile.
209a45ae5f8SJohn Marino        The values are defined by OBJF_*.  */
2105796c8dcSSimon Schubert 
2115796c8dcSSimon Schubert     unsigned short flags;
2125796c8dcSSimon Schubert 
213cf7f2e2dSJohn Marino     /* The program space associated with this objfile.  */
214cf7f2e2dSJohn Marino 
215cf7f2e2dSJohn Marino     struct program_space *pspace;
216cf7f2e2dSJohn Marino 
2175796c8dcSSimon Schubert     /* Each objfile points to a linked list of symtabs derived from this file,
2185796c8dcSSimon Schubert        one symtab structure for each compilation unit (source file).  Each link
2195796c8dcSSimon Schubert        in the symtab list contains a backpointer to this objfile.  */
2205796c8dcSSimon Schubert 
2215796c8dcSSimon Schubert     struct symtab *symtabs;
2225796c8dcSSimon Schubert 
2235796c8dcSSimon Schubert     /* Each objfile points to a linked list of partial symtabs derived from
2245796c8dcSSimon Schubert        this file, one partial symtab structure for each compilation unit
2255796c8dcSSimon Schubert        (source file).  */
2265796c8dcSSimon Schubert 
2275796c8dcSSimon Schubert     struct partial_symtab *psymtabs;
2285796c8dcSSimon Schubert 
2295796c8dcSSimon Schubert     /* Map addresses to the entries of PSYMTABS.  It would be more efficient to
2305796c8dcSSimon Schubert        have a map per the whole process but ADDRMAP cannot selectively remove
2315796c8dcSSimon Schubert        its items during FREE_OBJFILE.  This mapping is already present even for
2325796c8dcSSimon Schubert        PARTIAL_SYMTABs which still have no corresponding full SYMTABs read.  */
2335796c8dcSSimon Schubert 
2345796c8dcSSimon Schubert     struct addrmap *psymtabs_addrmap;
2355796c8dcSSimon Schubert 
236c50c785cSJohn Marino     /* List of freed partial symtabs, available for re-use.  */
2375796c8dcSSimon Schubert 
2385796c8dcSSimon Schubert     struct partial_symtab *free_psymtabs;
2395796c8dcSSimon Schubert 
2405796c8dcSSimon Schubert     /* The object file's BFD.  Can be null if the objfile contains only
2415796c8dcSSimon Schubert        minimal symbols, e.g. the run time common symbols for SunOS4.  */
2425796c8dcSSimon Schubert 
2435796c8dcSSimon Schubert     bfd *obfd;
2445796c8dcSSimon Schubert 
245*ef5ccd6cSJohn Marino     /* The per-BFD data.  Note that this is treated specially if OBFD
246*ef5ccd6cSJohn Marino        is NULL.  */
247*ef5ccd6cSJohn Marino 
248*ef5ccd6cSJohn Marino     struct objfile_per_bfd_storage *per_bfd;
249*ef5ccd6cSJohn Marino 
2505796c8dcSSimon Schubert     /* The gdbarch associated with the BFD.  Note that this gdbarch is
2515796c8dcSSimon Schubert        determined solely from BFD information, without looking at target
2525796c8dcSSimon Schubert        information.  The gdbarch determined from a running target may
2535796c8dcSSimon Schubert        differ from this e.g. with respect to register types and names.  */
2545796c8dcSSimon Schubert 
2555796c8dcSSimon Schubert     struct gdbarch *gdbarch;
2565796c8dcSSimon Schubert 
2575796c8dcSSimon Schubert     /* The modification timestamp of the object file, as of the last time
2585796c8dcSSimon Schubert        we read its symbols.  */
2595796c8dcSSimon Schubert 
2605796c8dcSSimon Schubert     long mtime;
2615796c8dcSSimon Schubert 
262a45ae5f8SJohn Marino     /* Cached 32-bit CRC as computed by gnu_debuglink_crc32.  CRC32 is valid
263a45ae5f8SJohn Marino        iff CRC32_P.  */
264a45ae5f8SJohn Marino     unsigned long crc32;
265a45ae5f8SJohn Marino     int crc32_p;
266a45ae5f8SJohn Marino 
2675796c8dcSSimon Schubert     /* Obstack to hold objects that should be freed when we load a new symbol
2685796c8dcSSimon Schubert        table from this object file.  */
2695796c8dcSSimon Schubert 
2705796c8dcSSimon Schubert     struct obstack objfile_obstack;
2715796c8dcSSimon Schubert 
2725796c8dcSSimon Schubert     /* A byte cache where we can stash arbitrary "chunks" of bytes that
2735796c8dcSSimon Schubert        will not change.  */
2745796c8dcSSimon Schubert 
275c50c785cSJohn Marino     struct psymbol_bcache *psymbol_cache; /* Byte cache for partial syms.  */
2765796c8dcSSimon Schubert 
2775796c8dcSSimon Schubert     /* Hash table for mapping symbol names to demangled names.  Each
2785796c8dcSSimon Schubert        entry in the hash table is actually two consecutive strings,
2795796c8dcSSimon Schubert        both null-terminated; the first one is a mangled or linkage
2805796c8dcSSimon Schubert        name, and the second is the demangled name or just a zero byte
2815796c8dcSSimon Schubert        if the name doesn't demangle.  */
2825796c8dcSSimon Schubert     struct htab *demangled_names_hash;
2835796c8dcSSimon Schubert 
2845796c8dcSSimon Schubert     /* Vectors of all partial symbols read in from file.  The actual data
2855796c8dcSSimon Schubert        is stored in the objfile_obstack.  */
2865796c8dcSSimon Schubert 
2875796c8dcSSimon Schubert     struct psymbol_allocation_list global_psymbols;
2885796c8dcSSimon Schubert     struct psymbol_allocation_list static_psymbols;
2895796c8dcSSimon Schubert 
2905796c8dcSSimon Schubert     /* Each file contains a pointer to an array of minimal symbols for all
291c50c785cSJohn Marino        global symbols that are defined within the file.  The array is
292c50c785cSJohn Marino        terminated by a "null symbol", one that has a NULL pointer for the
293c50c785cSJohn Marino        name and a zero value for the address.  This makes it easy to walk
294c50c785cSJohn Marino        through the array when passed a pointer to somewhere in the middle
295c50c785cSJohn Marino        of it.  There is also a count of the number of symbols, which does
296c50c785cSJohn Marino        not include the terminating null symbol.  The array itself, as well
297c50c785cSJohn Marino        as all the data that it points to, should be allocated on the
298c50c785cSJohn Marino        objfile_obstack for this file.  */
2995796c8dcSSimon Schubert 
3005796c8dcSSimon Schubert     struct minimal_symbol *msymbols;
3015796c8dcSSimon Schubert     int minimal_symbol_count;
3025796c8dcSSimon Schubert 
3035796c8dcSSimon Schubert     /* This is a hash table used to index the minimal symbols by name.  */
3045796c8dcSSimon Schubert 
3055796c8dcSSimon Schubert     struct minimal_symbol *msymbol_hash[MINIMAL_SYMBOL_HASH_SIZE];
3065796c8dcSSimon Schubert 
3075796c8dcSSimon Schubert     /* This hash table is used to index the minimal symbols by their
3085796c8dcSSimon Schubert        demangled names.  */
3095796c8dcSSimon Schubert 
3105796c8dcSSimon Schubert     struct minimal_symbol *msymbol_demangled_hash[MINIMAL_SYMBOL_HASH_SIZE];
3115796c8dcSSimon Schubert 
3125796c8dcSSimon Schubert     /* Structure which keeps track of functions that manipulate objfile's
313c50c785cSJohn Marino        of the same type as this objfile.  I.e. the function to read partial
3145796c8dcSSimon Schubert        symbols for example.  Note that this structure is in statically
3155796c8dcSSimon Schubert        allocated memory, and is shared by all objfiles that use the
3165796c8dcSSimon Schubert        object module reader of this type.  */
3175796c8dcSSimon Schubert 
318c50c785cSJohn Marino     const struct sym_fns *sf;
3195796c8dcSSimon Schubert 
3205796c8dcSSimon Schubert     /* The per-objfile information about the entry point, the scope (file/func)
3215796c8dcSSimon Schubert        containing the entry point, and the scope of the user's main() func.  */
3225796c8dcSSimon Schubert 
3235796c8dcSSimon Schubert     struct entry_info ei;
3245796c8dcSSimon Schubert 
3255796c8dcSSimon Schubert     /* Per objfile data-pointers required by other GDB modules.  */
3265796c8dcSSimon Schubert 
327*ef5ccd6cSJohn Marino     REGISTRY_FIELDS;
3285796c8dcSSimon Schubert 
3295796c8dcSSimon Schubert     /* Set of relocation offsets to apply to each section.
330*ef5ccd6cSJohn Marino        The table is indexed by the_bfd_section->index, thus it is generally
331*ef5ccd6cSJohn Marino        as large as the number of sections in the binary.
332*ef5ccd6cSJohn Marino        The table is stored on the objfile_obstack.
3335796c8dcSSimon Schubert 
3345796c8dcSSimon Schubert        These offsets indicate that all symbols (including partial and
3355796c8dcSSimon Schubert        minimal symbols) which have been read have been relocated by this
336*ef5ccd6cSJohn Marino        much.  Symbols which are yet to be read need to be relocated by it.  */
3375796c8dcSSimon Schubert 
3385796c8dcSSimon Schubert     struct section_offsets *section_offsets;
3395796c8dcSSimon Schubert     int num_sections;
3405796c8dcSSimon Schubert 
3415796c8dcSSimon Schubert     /* Indexes in the section_offsets array.  These are initialized by the
3425796c8dcSSimon Schubert        *_symfile_offsets() family of functions (som_symfile_offsets,
3435796c8dcSSimon Schubert        xcoff_symfile_offsets, default_symfile_offsets).  In theory they
3445796c8dcSSimon Schubert        should correspond to the section indexes used by bfd for the
3455796c8dcSSimon Schubert        current objfile.  The exception to this for the time being is the
3465796c8dcSSimon Schubert        SOM version.  */
3475796c8dcSSimon Schubert 
3485796c8dcSSimon Schubert     int sect_index_text;
3495796c8dcSSimon Schubert     int sect_index_data;
3505796c8dcSSimon Schubert     int sect_index_bss;
3515796c8dcSSimon Schubert     int sect_index_rodata;
3525796c8dcSSimon Schubert 
3535796c8dcSSimon Schubert     /* These pointers are used to locate the section table, which
3545796c8dcSSimon Schubert        among other things, is used to map pc addresses into sections.
3555796c8dcSSimon Schubert        SECTIONS points to the first entry in the table, and
3565796c8dcSSimon Schubert        SECTIONS_END points to the first location past the last entry
357*ef5ccd6cSJohn Marino        in the table.  The table is stored on the objfile_obstack.
358*ef5ccd6cSJohn Marino        There is no particular order to the sections in this table, and it
359*ef5ccd6cSJohn Marino        only contains sections we care about (e.g. non-empty, SEC_ALLOC).  */
3605796c8dcSSimon Schubert 
361*ef5ccd6cSJohn Marino     struct obj_section *sections, *sections_end;
3625796c8dcSSimon Schubert 
363cf7f2e2dSJohn Marino     /* GDB allows to have debug symbols in separate object files.  This is
364cf7f2e2dSJohn Marino        used by .gnu_debuglink, ELF build id note and Mach-O OSO.
365cf7f2e2dSJohn Marino        Although this is a tree structure, GDB only support one level
366cf7f2e2dSJohn Marino        (ie a separate debug for a separate debug is not supported).  Note that
367cf7f2e2dSJohn Marino        separate debug object are in the main chain and therefore will be
368cf7f2e2dSJohn Marino        visited by ALL_OBJFILES & co iterators.  Separate debug objfile always
369cf7f2e2dSJohn Marino        has a non-nul separate_debug_objfile_backlink.  */
370cf7f2e2dSJohn Marino 
371cf7f2e2dSJohn Marino     /* Link to the first separate debug object, if any.  */
3725796c8dcSSimon Schubert     struct objfile *separate_debug_objfile;
3735796c8dcSSimon Schubert 
3745796c8dcSSimon Schubert     /* If this is a separate debug object, this is used as a link to the
3755796c8dcSSimon Schubert        actual executable objfile.  */
3765796c8dcSSimon Schubert     struct objfile *separate_debug_objfile_backlink;
3775796c8dcSSimon Schubert 
378cf7f2e2dSJohn Marino     /* If this is a separate debug object, this is a link to the next one
379cf7f2e2dSJohn Marino        for the same executable objfile.  */
380cf7f2e2dSJohn Marino     struct objfile *separate_debug_objfile_link;
381cf7f2e2dSJohn Marino 
382c50c785cSJohn Marino     /* Place to stash various statistics about this objfile.  */
3835796c8dcSSimon Schubert     OBJSTATS;
3845796c8dcSSimon Schubert 
385c50c785cSJohn Marino     /* A linked list of symbols created when reading template types or
386c50c785cSJohn Marino        function templates.  These symbols are not stored in any symbol
387c50c785cSJohn Marino        table, so we have to keep them here to relocate them
388c50c785cSJohn Marino        properly.  */
389c50c785cSJohn Marino     struct symbol *template_symbols;
3905796c8dcSSimon Schubert   };
3915796c8dcSSimon Schubert 
3925796c8dcSSimon Schubert /* Defines for the objfile flag word.  */
3935796c8dcSSimon Schubert 
3945796c8dcSSimon Schubert /* When an object file has its functions reordered (currently Irix-5.2
3955796c8dcSSimon Schubert    shared libraries exhibit this behaviour), we will need an expensive
3965796c8dcSSimon Schubert    algorithm to locate a partial symtab or symtab via an address.
3975796c8dcSSimon Schubert    To avoid this penalty for normal object files, we use this flag,
3985796c8dcSSimon Schubert    whose setting is determined upon symbol table read in.  */
3995796c8dcSSimon Schubert 
4005796c8dcSSimon Schubert #define OBJF_REORDERED	(1 << 0)	/* Functions are reordered */
4015796c8dcSSimon Schubert 
4025796c8dcSSimon Schubert /* Distinguish between an objfile for a shared library and a "vanilla"
4035796c8dcSSimon Schubert    objfile.  (If not set, the objfile may still actually be a solib.
4045796c8dcSSimon Schubert    This can happen if the user created the objfile by using the
4055796c8dcSSimon Schubert    add-symbol-file command.  GDB doesn't in that situation actually
4065796c8dcSSimon Schubert    check whether the file is a solib.  Rather, the target's
4075796c8dcSSimon Schubert    implementation of the solib interface is responsible for setting
4085796c8dcSSimon Schubert    this flag when noticing solibs used by an inferior.)  */
4095796c8dcSSimon Schubert 
4105796c8dcSSimon Schubert #define OBJF_SHARED     (1 << 1)	/* From a shared library */
4115796c8dcSSimon Schubert 
4125796c8dcSSimon Schubert /* User requested that this objfile be read in it's entirety.  */
4135796c8dcSSimon Schubert 
4145796c8dcSSimon Schubert #define OBJF_READNOW	(1 << 2)	/* Immediate full read */
4155796c8dcSSimon Schubert 
4165796c8dcSSimon Schubert /* This objfile was created because the user explicitly caused it
4175796c8dcSSimon Schubert    (e.g., used the add-symbol-file command).  This bit offers a way
4185796c8dcSSimon Schubert    for run_command to remove old objfile entries which are no longer
4195796c8dcSSimon Schubert    valid (i.e., are associated with an old inferior), but to preserve
4205796c8dcSSimon Schubert    ones that the user explicitly loaded via the add-symbol-file
4215796c8dcSSimon Schubert    command.  */
4225796c8dcSSimon Schubert 
4235796c8dcSSimon Schubert #define OBJF_USERLOADED	(1 << 3)	/* User loaded */
4245796c8dcSSimon Schubert 
425c50c785cSJohn Marino /* Set if we have tried to read partial symtabs for this objfile.
426c50c785cSJohn Marino    This is used to allow lazy reading of partial symtabs.  */
427c50c785cSJohn Marino 
428c50c785cSJohn Marino #define OBJF_PSYMTABS_READ (1 << 4)
429c50c785cSJohn Marino 
430a45ae5f8SJohn Marino /* Set if this is the main symbol file
431a45ae5f8SJohn Marino    (as opposed to symbol file for dynamically loaded code).  */
432a45ae5f8SJohn Marino 
433a45ae5f8SJohn Marino #define OBJF_MAINLINE (1 << 5)
434a45ae5f8SJohn Marino 
4355796c8dcSSimon Schubert /* The object file that contains the runtime common minimal symbols
4365796c8dcSSimon Schubert    for SunOS4.  Note that this objfile has no associated BFD.  */
4375796c8dcSSimon Schubert 
4385796c8dcSSimon Schubert extern struct objfile *rt_common_objfile;
4395796c8dcSSimon Schubert 
4405796c8dcSSimon Schubert /* Declarations for functions defined in objfiles.c */
4415796c8dcSSimon Schubert 
4425796c8dcSSimon Schubert extern struct objfile *allocate_objfile (bfd *, int);
4435796c8dcSSimon Schubert 
4445796c8dcSSimon Schubert extern struct gdbarch *get_objfile_arch (struct objfile *);
4455796c8dcSSimon Schubert 
446cf7f2e2dSJohn Marino extern int entry_point_address_query (CORE_ADDR *entry_p);
447cf7f2e2dSJohn Marino 
4485796c8dcSSimon Schubert extern CORE_ADDR entry_point_address (void);
4495796c8dcSSimon Schubert 
450*ef5ccd6cSJohn Marino extern void build_objfile_section_table (struct objfile *);
4515796c8dcSSimon Schubert 
4525796c8dcSSimon Schubert extern void terminate_minimal_symbol_table (struct objfile *objfile);
4535796c8dcSSimon Schubert 
454cf7f2e2dSJohn Marino extern struct objfile *objfile_separate_debug_iterate (const struct objfile *,
455cf7f2e2dSJohn Marino                                                        const struct objfile *);
456cf7f2e2dSJohn Marino 
4575796c8dcSSimon Schubert extern void put_objfile_before (struct objfile *, struct objfile *);
4585796c8dcSSimon Schubert 
4595796c8dcSSimon Schubert extern void objfile_to_front (struct objfile *);
4605796c8dcSSimon Schubert 
461cf7f2e2dSJohn Marino extern void add_separate_debug_objfile (struct objfile *, struct objfile *);
462cf7f2e2dSJohn Marino 
4635796c8dcSSimon Schubert extern void unlink_objfile (struct objfile *);
4645796c8dcSSimon Schubert 
4655796c8dcSSimon Schubert extern void free_objfile (struct objfile *);
4665796c8dcSSimon Schubert 
467cf7f2e2dSJohn Marino extern void free_objfile_separate_debug (struct objfile *);
468cf7f2e2dSJohn Marino 
4695796c8dcSSimon Schubert extern struct cleanup *make_cleanup_free_objfile (struct objfile *);
4705796c8dcSSimon Schubert 
4715796c8dcSSimon Schubert extern void free_all_objfiles (void);
4725796c8dcSSimon Schubert 
4735796c8dcSSimon Schubert extern void objfile_relocate (struct objfile *, struct section_offsets *);
474*ef5ccd6cSJohn Marino extern void objfile_rebase (struct objfile *, CORE_ADDR);
4755796c8dcSSimon Schubert 
4765796c8dcSSimon Schubert extern int objfile_has_partial_symbols (struct objfile *objfile);
4775796c8dcSSimon Schubert 
4785796c8dcSSimon Schubert extern int objfile_has_full_symbols (struct objfile *objfile);
4795796c8dcSSimon Schubert 
480cf7f2e2dSJohn Marino extern int objfile_has_symbols (struct objfile *objfile);
481cf7f2e2dSJohn Marino 
4825796c8dcSSimon Schubert extern int have_partial_symbols (void);
4835796c8dcSSimon Schubert 
4845796c8dcSSimon Schubert extern int have_full_symbols (void);
4855796c8dcSSimon Schubert 
4865796c8dcSSimon Schubert extern void objfiles_changed (void);
4875796c8dcSSimon Schubert 
4885796c8dcSSimon Schubert /* This operation deletes all objfile entries that represent solibs that
4895796c8dcSSimon Schubert    weren't explicitly loaded by the user, via e.g., the add-symbol-file
490c50c785cSJohn Marino    command.  */
491c50c785cSJohn Marino 
4925796c8dcSSimon Schubert extern void objfile_purge_solibs (void);
4935796c8dcSSimon Schubert 
4945796c8dcSSimon Schubert /* Functions for dealing with the minimal symbol table, really a misc
4955796c8dcSSimon Schubert    address<->symbol mapping for things we don't have debug symbols for.  */
4965796c8dcSSimon Schubert 
4975796c8dcSSimon Schubert extern int have_minimal_symbols (void);
4985796c8dcSSimon Schubert 
4995796c8dcSSimon Schubert extern struct obj_section *find_pc_section (CORE_ADDR pc);
5005796c8dcSSimon Schubert 
5015796c8dcSSimon Schubert extern int in_plt_section (CORE_ADDR, char *);
5025796c8dcSSimon Schubert 
5035796c8dcSSimon Schubert /* Keep a registry of per-objfile data-pointers required by other GDB
5045796c8dcSSimon Schubert    modules.  */
505*ef5ccd6cSJohn Marino DECLARE_REGISTRY(objfile);
5065796c8dcSSimon Schubert 
507*ef5ccd6cSJohn Marino extern void default_iterate_over_objfiles_in_search_order
508*ef5ccd6cSJohn Marino   (struct gdbarch *gdbarch,
509*ef5ccd6cSJohn Marino    iterate_over_objfiles_in_search_order_cb_ftype *cb,
510*ef5ccd6cSJohn Marino    void *cb_data, struct objfile *current_objfile);
5115796c8dcSSimon Schubert 
5125796c8dcSSimon Schubert 
513cf7f2e2dSJohn Marino /* Traverse all object files in the current program space.
514cf7f2e2dSJohn Marino    ALL_OBJFILES_SAFE works even if you delete the objfile during the
515cf7f2e2dSJohn Marino    traversal.  */
516cf7f2e2dSJohn Marino 
517cf7f2e2dSJohn Marino /* Traverse all object files in program space SS.  */
518cf7f2e2dSJohn Marino 
519cf7f2e2dSJohn Marino #define ALL_PSPACE_OBJFILES(ss, obj)					\
520*ef5ccd6cSJohn Marino   for ((obj) = ss->objfiles; (obj) != NULL; (obj) = (obj)->next)
521cf7f2e2dSJohn Marino 
522cf7f2e2dSJohn Marino #define ALL_PSPACE_OBJFILES_SAFE(ss, obj, nxt)		\
523cf7f2e2dSJohn Marino   for ((obj) = ss->objfiles;			\
524cf7f2e2dSJohn Marino        (obj) != NULL? ((nxt)=(obj)->next,1) :0;	\
525cf7f2e2dSJohn Marino        (obj) = (nxt))
5265796c8dcSSimon Schubert 
5275796c8dcSSimon Schubert #define ALL_OBJFILES(obj)			    \
528cf7f2e2dSJohn Marino   for ((obj) = current_program_space->objfiles; \
529cf7f2e2dSJohn Marino        (obj) != NULL;				    \
530cf7f2e2dSJohn Marino        (obj) = (obj)->next)
5315796c8dcSSimon Schubert 
5325796c8dcSSimon Schubert #define ALL_OBJFILES_SAFE(obj,nxt)			\
533cf7f2e2dSJohn Marino   for ((obj) = current_program_space->objfiles;	\
5345796c8dcSSimon Schubert        (obj) != NULL? ((nxt)=(obj)->next,1) :0;	\
5355796c8dcSSimon Schubert        (obj) = (nxt))
5365796c8dcSSimon Schubert 
5375796c8dcSSimon Schubert /* Traverse all symtabs in one objfile.  */
5385796c8dcSSimon Schubert 
5395796c8dcSSimon Schubert #define	ALL_OBJFILE_SYMTABS(objfile, s) \
5405796c8dcSSimon Schubert     for ((s) = (objfile) -> symtabs; (s) != NULL; (s) = (s) -> next)
5415796c8dcSSimon Schubert 
542*ef5ccd6cSJohn Marino /* Traverse all primary symtabs in one objfile.  */
543*ef5ccd6cSJohn Marino 
544*ef5ccd6cSJohn Marino #define ALL_OBJFILE_PRIMARY_SYMTABS(objfile, s) \
545*ef5ccd6cSJohn Marino   ALL_OBJFILE_SYMTABS ((objfile), (s)) \
546*ef5ccd6cSJohn Marino     if ((s)->primary)
547*ef5ccd6cSJohn Marino 
5485796c8dcSSimon Schubert /* Traverse all minimal symbols in one objfile.  */
5495796c8dcSSimon Schubert 
5505796c8dcSSimon Schubert #define	ALL_OBJFILE_MSYMBOLS(objfile, m) \
5515796c8dcSSimon Schubert     for ((m) = (objfile) -> msymbols; SYMBOL_LINKAGE_NAME(m) != NULL; (m)++)
5525796c8dcSSimon Schubert 
553cf7f2e2dSJohn Marino /* Traverse all symtabs in all objfiles in the current symbol
554cf7f2e2dSJohn Marino    space.  */
5555796c8dcSSimon Schubert 
5565796c8dcSSimon Schubert #define	ALL_SYMTABS(objfile, s) \
5575796c8dcSSimon Schubert   ALL_OBJFILES (objfile)	 \
5585796c8dcSSimon Schubert     ALL_OBJFILE_SYMTABS (objfile, s)
5595796c8dcSSimon Schubert 
560cf7f2e2dSJohn Marino #define ALL_PSPACE_SYMTABS(ss, objfile, s)		\
561cf7f2e2dSJohn Marino   ALL_PSPACE_OBJFILES (ss, objfile)			\
562cf7f2e2dSJohn Marino     ALL_OBJFILE_SYMTABS (objfile, s)
563cf7f2e2dSJohn Marino 
564cf7f2e2dSJohn Marino /* Traverse all symtabs in all objfiles in the current program space,
565cf7f2e2dSJohn Marino    skipping included files (which share a blockvector with their
566cf7f2e2dSJohn Marino    primary symtab).  */
5675796c8dcSSimon Schubert 
5685796c8dcSSimon Schubert #define ALL_PRIMARY_SYMTABS(objfile, s) \
5695796c8dcSSimon Schubert   ALL_OBJFILES (objfile)		\
570*ef5ccd6cSJohn Marino     ALL_OBJFILE_PRIMARY_SYMTABS (objfile, s)
5715796c8dcSSimon Schubert 
572cf7f2e2dSJohn Marino #define ALL_PSPACE_PRIMARY_SYMTABS(pspace, objfile, s)	\
573cf7f2e2dSJohn Marino   ALL_PSPACE_OBJFILES (ss, objfile)			\
574*ef5ccd6cSJohn Marino     ALL_OBJFILE_PRIMARY_SYMTABS (objfile, s)
5755796c8dcSSimon Schubert 
576cf7f2e2dSJohn Marino /* Traverse all minimal symbols in all objfiles in the current symbol
577cf7f2e2dSJohn Marino    space.  */
5785796c8dcSSimon Schubert 
5795796c8dcSSimon Schubert #define	ALL_MSYMBOLS(objfile, m) \
5805796c8dcSSimon Schubert   ALL_OBJFILES (objfile)	 \
5815796c8dcSSimon Schubert     ALL_OBJFILE_MSYMBOLS (objfile, m)
5825796c8dcSSimon Schubert 
5835796c8dcSSimon Schubert #define ALL_OBJFILE_OSECTIONS(objfile, osect)	\
5845796c8dcSSimon Schubert   for (osect = objfile->sections; osect < objfile->sections_end; osect++)
5855796c8dcSSimon Schubert 
586c50c785cSJohn Marino /* Traverse all obj_sections in all objfiles in the current program
587c50c785cSJohn Marino    space.
588c50c785cSJohn Marino 
589c50c785cSJohn Marino    Note that this detects a "break" in the inner loop, and exits
590c50c785cSJohn Marino    immediately from the outer loop as well, thus, client code doesn't
591c50c785cSJohn Marino    need to know that this is implemented with a double for.  The extra
592c50c785cSJohn Marino    hair is to make sure that a "break;" stops the outer loop iterating
593c50c785cSJohn Marino    as well, and both OBJFILE and OSECT are left unmodified:
594c50c785cSJohn Marino 
595c50c785cSJohn Marino     - The outer loop learns about the inner loop's end condition, and
596c50c785cSJohn Marino       stops iterating if it detects the inner loop didn't reach its
597c50c785cSJohn Marino       end.  In other words, the outer loop keeps going only if the
598c50c785cSJohn Marino       inner loop reached its end cleanly [(osect) ==
599c50c785cSJohn Marino       (objfile)->sections_end].
600c50c785cSJohn Marino 
601c50c785cSJohn Marino     - OSECT is initialized in the outer loop initialization
602c50c785cSJohn Marino       expressions, such as if the inner loop has reached its end, so
603c50c785cSJohn Marino       the check mentioned above succeeds the first time.
604c50c785cSJohn Marino 
605c50c785cSJohn Marino     - The trick to not clearing OBJFILE on a "break;" is, in the outer
606c50c785cSJohn Marino       loop's loop expression, advance OBJFILE, but iff the inner loop
607c50c785cSJohn Marino       reached its end.  If not, there was a "break;", so leave OBJFILE
608c50c785cSJohn Marino       as is; the outer loop's conditional will break immediately as
609c50c785cSJohn Marino       well (as OSECT will be different from OBJFILE->sections_end).  */
610c50c785cSJohn Marino 
6115796c8dcSSimon Schubert #define ALL_OBJSECTIONS(objfile, osect)					\
612c50c785cSJohn Marino   for ((objfile) = current_program_space->objfiles,			\
613c50c785cSJohn Marino 	 (objfile) != NULL ? ((osect) = (objfile)->sections_end) : 0;	\
614c50c785cSJohn Marino        (objfile) != NULL						\
615c50c785cSJohn Marino 	 && (osect) == (objfile)->sections_end;				\
616c50c785cSJohn Marino        ((osect) == (objfile)->sections_end				\
617c50c785cSJohn Marino 	? ((objfile) = (objfile)->next,					\
618c50c785cSJohn Marino 	   (objfile) != NULL ? (osect) = (objfile)->sections_end : 0)	\
619c50c785cSJohn Marino 	: 0))								\
620c50c785cSJohn Marino     for ((osect) = (objfile)->sections;					\
621c50c785cSJohn Marino 	 (osect) < (objfile)->sections_end;				\
622c50c785cSJohn Marino 	 (osect)++)
6235796c8dcSSimon Schubert 
6245796c8dcSSimon Schubert #define SECT_OFF_DATA(objfile) \
6255796c8dcSSimon Schubert      ((objfile->sect_index_data == -1) \
626c50c785cSJohn Marino       ? (internal_error (__FILE__, __LINE__, \
627c50c785cSJohn Marino 			 _("sect_index_data not initialized")), -1)	\
6285796c8dcSSimon Schubert       : objfile->sect_index_data)
6295796c8dcSSimon Schubert 
6305796c8dcSSimon Schubert #define SECT_OFF_RODATA(objfile) \
6315796c8dcSSimon Schubert      ((objfile->sect_index_rodata == -1) \
632c50c785cSJohn Marino       ? (internal_error (__FILE__, __LINE__, \
633c50c785cSJohn Marino 			 _("sect_index_rodata not initialized")), -1)	\
6345796c8dcSSimon Schubert       : objfile->sect_index_rodata)
6355796c8dcSSimon Schubert 
6365796c8dcSSimon Schubert #define SECT_OFF_TEXT(objfile) \
6375796c8dcSSimon Schubert      ((objfile->sect_index_text == -1) \
638c50c785cSJohn Marino       ? (internal_error (__FILE__, __LINE__, \
639c50c785cSJohn Marino 			 _("sect_index_text not initialized")), -1)	\
6405796c8dcSSimon Schubert       : objfile->sect_index_text)
6415796c8dcSSimon Schubert 
6425796c8dcSSimon Schubert /* Sometimes the .bss section is missing from the objfile, so we don't
6435796c8dcSSimon Schubert    want to die here.  Let the users of SECT_OFF_BSS deal with an
6445796c8dcSSimon Schubert    uninitialized section index.  */
6455796c8dcSSimon Schubert #define SECT_OFF_BSS(objfile) (objfile)->sect_index_bss
6465796c8dcSSimon Schubert 
6475796c8dcSSimon Schubert /* Answer whether there is more than one object file loaded.  */
6485796c8dcSSimon Schubert 
6495796c8dcSSimon Schubert #define MULTI_OBJFILE_P() (object_files && object_files->next)
6505796c8dcSSimon Schubert 
651*ef5ccd6cSJohn Marino /* Reset the per-BFD storage area on OBJ.  */
652*ef5ccd6cSJohn Marino 
653*ef5ccd6cSJohn Marino void set_objfile_per_bfd (struct objfile *obj);
654*ef5ccd6cSJohn Marino 
6555796c8dcSSimon Schubert #endif /* !defined (OBJFILES_H) */
656