xref: /dflybsd-src/contrib/gdb-7/gdb/objfiles.h (revision cf7f2e2d389e8012d562650bd94d7e433f449d6e)
15796c8dcSSimon Schubert /* Definitions for symbol file management in GDB.
25796c8dcSSimon Schubert 
35796c8dcSSimon Schubert    Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001,
4*cf7f2e2dSJohn Marino    2002, 2003, 2004, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
55796c8dcSSimon Schubert 
65796c8dcSSimon Schubert    This file is part of GDB.
75796c8dcSSimon Schubert 
85796c8dcSSimon Schubert    This program is free software; you can redistribute it and/or modify
95796c8dcSSimon Schubert    it under the terms of the GNU General Public License as published by
105796c8dcSSimon Schubert    the Free Software Foundation; either version 3 of the License, or
115796c8dcSSimon Schubert    (at your option) any later version.
125796c8dcSSimon Schubert 
135796c8dcSSimon Schubert    This program is distributed in the hope that it will be useful,
145796c8dcSSimon Schubert    but WITHOUT ANY WARRANTY; without even the implied warranty of
155796c8dcSSimon Schubert    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
165796c8dcSSimon Schubert    GNU General Public License for more details.
175796c8dcSSimon Schubert 
185796c8dcSSimon Schubert    You should have received a copy of the GNU General Public License
195796c8dcSSimon Schubert    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
205796c8dcSSimon Schubert 
215796c8dcSSimon Schubert #if !defined (OBJFILES_H)
225796c8dcSSimon Schubert #define OBJFILES_H
235796c8dcSSimon Schubert 
245796c8dcSSimon Schubert #include "gdb_obstack.h"	/* For obstack internals.  */
255796c8dcSSimon Schubert #include "symfile.h"		/* For struct psymbol_allocation_list */
26*cf7f2e2dSJohn Marino #include "progspace.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
515796c8dcSSimon Schubert    "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   {
103*cf7f2e2dSJohn Marino     /* The relocated value we should use for this objfile entry point.  */
1045796c8dcSSimon Schubert     CORE_ADDR entry_point;
1055796c8dcSSimon Schubert 
106*cf7f2e2dSJohn Marino     /* Set to 1 iff ENTRY_POINT contains a valid value.  */
107*cf7f2e2dSJohn 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)				      		\
1305796c8dcSSimon Schubert   (bfd_get_section_vma ((s)->objfile->abfd, 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)						\
1365796c8dcSSimon Schubert   (bfd_get_section_vma ((s)->objfile->abfd, 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 
1635796c8dcSSimon Schubert /* Master structure for keeping track of each file from which
1645796c8dcSSimon Schubert    gdb reads symbols.  There are several ways these get allocated: 1.
1655796c8dcSSimon Schubert    The main symbol file, symfile_objfile, set by the symbol-file command,
1665796c8dcSSimon Schubert    2.  Additional symbol files added by the add-symbol-file command,
1675796c8dcSSimon Schubert    3.  Shared library objfiles, added by ADD_SOLIB,  4.  symbol files
1685796c8dcSSimon Schubert    for modules that were loaded when GDB attached to a remote system
1695796c8dcSSimon Schubert    (see remote-vx.c).  */
1705796c8dcSSimon Schubert 
1715796c8dcSSimon Schubert struct objfile
1725796c8dcSSimon Schubert   {
1735796c8dcSSimon Schubert 
1745796c8dcSSimon Schubert     /* All struct objfile's are chained together by their next pointers.
1755796c8dcSSimon Schubert        The global variable "object_files" points to the first link in this
1765796c8dcSSimon Schubert        chain.
1775796c8dcSSimon Schubert 
1785796c8dcSSimon Schubert        FIXME:  There is a problem here if the objfile is reusable, and if
1795796c8dcSSimon Schubert        multiple users are to be supported.  The problem is that the objfile
1805796c8dcSSimon Schubert        list is linked through a member of the objfile struct itself, which
1815796c8dcSSimon Schubert        is only valid for one gdb process.  The list implementation needs to
1825796c8dcSSimon Schubert        be changed to something like:
1835796c8dcSSimon Schubert 
1845796c8dcSSimon Schubert        struct list {struct list *next; struct objfile *objfile};
1855796c8dcSSimon Schubert 
1865796c8dcSSimon Schubert        where the list structure is completely maintained separately within
1875796c8dcSSimon Schubert        each gdb process. */
1885796c8dcSSimon Schubert 
1895796c8dcSSimon Schubert     struct objfile *next;
1905796c8dcSSimon Schubert 
1915796c8dcSSimon Schubert     /* The object file's name, tilde-expanded and absolute.
1925796c8dcSSimon Schubert        Malloc'd; free it if you free this struct.  */
1935796c8dcSSimon Schubert 
1945796c8dcSSimon Schubert     char *name;
1955796c8dcSSimon Schubert 
1965796c8dcSSimon Schubert     /* Some flag bits for this objfile. */
1975796c8dcSSimon Schubert 
1985796c8dcSSimon Schubert     unsigned short flags;
1995796c8dcSSimon Schubert 
200*cf7f2e2dSJohn Marino     /* The program space associated with this objfile.  */
201*cf7f2e2dSJohn Marino 
202*cf7f2e2dSJohn Marino     struct program_space *pspace;
203*cf7f2e2dSJohn Marino 
2045796c8dcSSimon Schubert     /* Each objfile points to a linked list of symtabs derived from this file,
2055796c8dcSSimon Schubert        one symtab structure for each compilation unit (source file).  Each link
2065796c8dcSSimon Schubert        in the symtab list contains a backpointer to this objfile. */
2075796c8dcSSimon Schubert 
2085796c8dcSSimon Schubert     struct symtab *symtabs;
2095796c8dcSSimon Schubert 
2105796c8dcSSimon Schubert     /* Each objfile points to a linked list of partial symtabs derived from
2115796c8dcSSimon Schubert        this file, one partial symtab structure for each compilation unit
2125796c8dcSSimon Schubert        (source file). */
2135796c8dcSSimon Schubert 
2145796c8dcSSimon Schubert     struct partial_symtab *psymtabs;
2155796c8dcSSimon Schubert 
2165796c8dcSSimon Schubert     /* Map addresses to the entries of PSYMTABS.  It would be more efficient to
2175796c8dcSSimon Schubert        have a map per the whole process but ADDRMAP cannot selectively remove
2185796c8dcSSimon Schubert        its items during FREE_OBJFILE.  This mapping is already present even for
2195796c8dcSSimon Schubert        PARTIAL_SYMTABs which still have no corresponding full SYMTABs read.  */
2205796c8dcSSimon Schubert 
2215796c8dcSSimon Schubert     struct addrmap *psymtabs_addrmap;
2225796c8dcSSimon Schubert 
2235796c8dcSSimon Schubert     /* List of freed partial symtabs, available for re-use */
2245796c8dcSSimon Schubert 
2255796c8dcSSimon Schubert     struct partial_symtab *free_psymtabs;
2265796c8dcSSimon Schubert 
2275796c8dcSSimon Schubert     /* The object file's BFD.  Can be null if the objfile contains only
2285796c8dcSSimon Schubert        minimal symbols, e.g. the run time common symbols for SunOS4.  */
2295796c8dcSSimon Schubert 
2305796c8dcSSimon Schubert     bfd *obfd;
2315796c8dcSSimon Schubert 
2325796c8dcSSimon Schubert     /* The gdbarch associated with the BFD.  Note that this gdbarch is
2335796c8dcSSimon Schubert        determined solely from BFD information, without looking at target
2345796c8dcSSimon Schubert        information.  The gdbarch determined from a running target may
2355796c8dcSSimon Schubert        differ from this e.g. with respect to register types and names.  */
2365796c8dcSSimon Schubert 
2375796c8dcSSimon Schubert     struct gdbarch *gdbarch;
2385796c8dcSSimon Schubert 
2395796c8dcSSimon Schubert     /* The modification timestamp of the object file, as of the last time
2405796c8dcSSimon Schubert        we read its symbols.  */
2415796c8dcSSimon Schubert 
2425796c8dcSSimon Schubert     long mtime;
2435796c8dcSSimon Schubert 
2445796c8dcSSimon Schubert     /* Obstack to hold objects that should be freed when we load a new symbol
2455796c8dcSSimon Schubert        table from this object file. */
2465796c8dcSSimon Schubert 
2475796c8dcSSimon Schubert     struct obstack objfile_obstack;
2485796c8dcSSimon Schubert 
2495796c8dcSSimon Schubert     /* A byte cache where we can stash arbitrary "chunks" of bytes that
2505796c8dcSSimon Schubert        will not change. */
2515796c8dcSSimon Schubert 
2525796c8dcSSimon Schubert     struct bcache *psymbol_cache;	/* Byte cache for partial syms */
2535796c8dcSSimon Schubert     struct bcache *macro_cache;          /* Byte cache for macros */
254*cf7f2e2dSJohn Marino     struct bcache *filename_cache;	 /* Byte cache for file names.  */
2555796c8dcSSimon Schubert 
2565796c8dcSSimon Schubert     /* Hash table for mapping symbol names to demangled names.  Each
2575796c8dcSSimon Schubert        entry in the hash table is actually two consecutive strings,
2585796c8dcSSimon Schubert        both null-terminated; the first one is a mangled or linkage
2595796c8dcSSimon Schubert        name, and the second is the demangled name or just a zero byte
2605796c8dcSSimon Schubert        if the name doesn't demangle.  */
2615796c8dcSSimon Schubert     struct htab *demangled_names_hash;
2625796c8dcSSimon Schubert 
2635796c8dcSSimon Schubert     /* Vectors of all partial symbols read in from file.  The actual data
2645796c8dcSSimon Schubert        is stored in the objfile_obstack. */
2655796c8dcSSimon Schubert 
2665796c8dcSSimon Schubert     struct psymbol_allocation_list global_psymbols;
2675796c8dcSSimon Schubert     struct psymbol_allocation_list static_psymbols;
2685796c8dcSSimon Schubert 
2695796c8dcSSimon Schubert     /* Each file contains a pointer to an array of minimal symbols for all
2705796c8dcSSimon Schubert        global symbols that are defined within the file.  The array is terminated
2715796c8dcSSimon Schubert        by a "null symbol", one that has a NULL pointer for the name and a zero
2725796c8dcSSimon Schubert        value for the address.  This makes it easy to walk through the array
2735796c8dcSSimon Schubert        when passed a pointer to somewhere in the middle of it.  There is also
2745796c8dcSSimon Schubert        a count of the number of symbols, which does not include the terminating
2755796c8dcSSimon Schubert        null symbol.  The array itself, as well as all the data that it points
2765796c8dcSSimon Schubert        to, should be allocated on the objfile_obstack for this file. */
2775796c8dcSSimon Schubert 
2785796c8dcSSimon Schubert     struct minimal_symbol *msymbols;
2795796c8dcSSimon Schubert     int minimal_symbol_count;
2805796c8dcSSimon Schubert 
2815796c8dcSSimon Schubert     /* This is a hash table used to index the minimal symbols by name.  */
2825796c8dcSSimon Schubert 
2835796c8dcSSimon Schubert     struct minimal_symbol *msymbol_hash[MINIMAL_SYMBOL_HASH_SIZE];
2845796c8dcSSimon Schubert 
2855796c8dcSSimon Schubert     /* This hash table is used to index the minimal symbols by their
2865796c8dcSSimon Schubert        demangled names.  */
2875796c8dcSSimon Schubert 
2885796c8dcSSimon Schubert     struct minimal_symbol *msymbol_demangled_hash[MINIMAL_SYMBOL_HASH_SIZE];
2895796c8dcSSimon Schubert 
2905796c8dcSSimon Schubert     /* Structure which keeps track of functions that manipulate objfile's
2915796c8dcSSimon Schubert        of the same type as this objfile.  I.E. the function to read partial
2925796c8dcSSimon Schubert        symbols for example.  Note that this structure is in statically
2935796c8dcSSimon Schubert        allocated memory, and is shared by all objfiles that use the
2945796c8dcSSimon Schubert        object module reader of this type. */
2955796c8dcSSimon Schubert 
2965796c8dcSSimon Schubert     struct sym_fns *sf;
2975796c8dcSSimon Schubert 
2985796c8dcSSimon Schubert     /* The per-objfile information about the entry point, the scope (file/func)
2995796c8dcSSimon Schubert        containing the entry point, and the scope of the user's main() func. */
3005796c8dcSSimon Schubert 
3015796c8dcSSimon Schubert     struct entry_info ei;
3025796c8dcSSimon Schubert 
3035796c8dcSSimon Schubert     /* Information about stabs.  Will be filled in with a dbx_symfile_info
3045796c8dcSSimon Schubert        struct by those readers that need it. */
3055796c8dcSSimon Schubert     /* NOTE: cagney/2004-10-23: This has been replaced by per-objfile
3065796c8dcSSimon Schubert        data points implemented using "data" and "num_data" below.  For
3075796c8dcSSimon Schubert        an example of how to use this replacement, see "objfile_data"
3085796c8dcSSimon Schubert        in "mips-tdep.c".  */
3095796c8dcSSimon Schubert 
3105796c8dcSSimon Schubert     struct dbx_symfile_info *deprecated_sym_stab_info;
3115796c8dcSSimon Schubert 
3125796c8dcSSimon Schubert     /* Hook for information for use by the symbol reader (currently used
3135796c8dcSSimon Schubert        for information shared by sym_init and sym_read).  It is
3145796c8dcSSimon Schubert        typically a pointer to malloc'd memory.  The symbol reader's finish
3155796c8dcSSimon Schubert        function is responsible for freeing the memory thusly allocated.  */
3165796c8dcSSimon Schubert     /* NOTE: cagney/2004-10-23: This has been replaced by per-objfile
3175796c8dcSSimon Schubert        data points implemented using "data" and "num_data" below.  For
3185796c8dcSSimon Schubert        an example of how to use this replacement, see "objfile_data"
3195796c8dcSSimon Schubert        in "mips-tdep.c".  */
3205796c8dcSSimon Schubert 
3215796c8dcSSimon Schubert     void *deprecated_sym_private;
3225796c8dcSSimon Schubert 
3235796c8dcSSimon Schubert     /* Per objfile data-pointers required by other GDB modules.  */
3245796c8dcSSimon Schubert     /* FIXME: kettenis/20030711: This mechanism could replace
3255796c8dcSSimon Schubert        deprecated_sym_stab_info and deprecated_sym_private
3265796c8dcSSimon Schubert        entirely.  */
3275796c8dcSSimon Schubert 
3285796c8dcSSimon Schubert     void **data;
3295796c8dcSSimon Schubert     unsigned num_data;
3305796c8dcSSimon Schubert 
3315796c8dcSSimon Schubert     /* Set of relocation offsets to apply to each section.
3325796c8dcSSimon Schubert        Currently on the objfile_obstack (which makes no sense, but I'm
3335796c8dcSSimon Schubert        not sure it's harming anything).
3345796c8dcSSimon Schubert 
3355796c8dcSSimon Schubert        These offsets indicate that all symbols (including partial and
3365796c8dcSSimon Schubert        minimal symbols) which have been read have been relocated by this
3375796c8dcSSimon Schubert        much.  Symbols which are yet to be read need to be relocated by
3385796c8dcSSimon Schubert        it.  */
3395796c8dcSSimon Schubert 
3405796c8dcSSimon Schubert     struct section_offsets *section_offsets;
3415796c8dcSSimon Schubert     int num_sections;
3425796c8dcSSimon Schubert 
3435796c8dcSSimon Schubert     /* Indexes in the section_offsets array. These are initialized by the
3445796c8dcSSimon Schubert        *_symfile_offsets() family of functions (som_symfile_offsets,
3455796c8dcSSimon Schubert        xcoff_symfile_offsets, default_symfile_offsets). In theory they
3465796c8dcSSimon Schubert        should correspond to the section indexes used by bfd for the
3475796c8dcSSimon Schubert        current objfile. The exception to this for the time being is the
3485796c8dcSSimon Schubert        SOM version. */
3495796c8dcSSimon Schubert 
3505796c8dcSSimon Schubert     int sect_index_text;
3515796c8dcSSimon Schubert     int sect_index_data;
3525796c8dcSSimon Schubert     int sect_index_bss;
3535796c8dcSSimon Schubert     int sect_index_rodata;
3545796c8dcSSimon Schubert 
3555796c8dcSSimon Schubert     /* These pointers are used to locate the section table, which
3565796c8dcSSimon Schubert        among other things, is used to map pc addresses into sections.
3575796c8dcSSimon Schubert        SECTIONS points to the first entry in the table, and
3585796c8dcSSimon Schubert        SECTIONS_END points to the first location past the last entry
3595796c8dcSSimon Schubert        in the table.  Currently the table is stored on the
3605796c8dcSSimon Schubert        objfile_obstack (which makes no sense, but I'm not sure it's
3615796c8dcSSimon Schubert        harming anything).  */
3625796c8dcSSimon Schubert 
3635796c8dcSSimon Schubert     struct obj_section
3645796c8dcSSimon Schubert      *sections, *sections_end;
3655796c8dcSSimon Schubert 
366*cf7f2e2dSJohn Marino     /* GDB allows to have debug symbols in separate object files.  This is
367*cf7f2e2dSJohn Marino        used by .gnu_debuglink, ELF build id note and Mach-O OSO.
368*cf7f2e2dSJohn Marino        Although this is a tree structure, GDB only support one level
369*cf7f2e2dSJohn Marino        (ie a separate debug for a separate debug is not supported).  Note that
370*cf7f2e2dSJohn Marino        separate debug object are in the main chain and therefore will be
371*cf7f2e2dSJohn Marino        visited by ALL_OBJFILES & co iterators.  Separate debug objfile always
372*cf7f2e2dSJohn Marino        has a non-nul separate_debug_objfile_backlink.  */
373*cf7f2e2dSJohn Marino 
374*cf7f2e2dSJohn Marino     /* Link to the first separate debug object, if any.  */
3755796c8dcSSimon Schubert     struct objfile *separate_debug_objfile;
3765796c8dcSSimon Schubert 
3775796c8dcSSimon Schubert     /* If this is a separate debug object, this is used as a link to the
3785796c8dcSSimon Schubert        actual executable objfile. */
3795796c8dcSSimon Schubert     struct objfile *separate_debug_objfile_backlink;
3805796c8dcSSimon Schubert 
381*cf7f2e2dSJohn Marino     /* If this is a separate debug object, this is a link to the next one
382*cf7f2e2dSJohn Marino        for the same executable objfile.  */
383*cf7f2e2dSJohn Marino     struct objfile *separate_debug_objfile_link;
384*cf7f2e2dSJohn Marino 
3855796c8dcSSimon Schubert     /* Place to stash various statistics about this objfile */
3865796c8dcSSimon Schubert       OBJSTATS;
3875796c8dcSSimon Schubert 
3885796c8dcSSimon Schubert     /* A symtab that the C++ code uses to stash special symbols
3895796c8dcSSimon Schubert        associated to namespaces.  */
3905796c8dcSSimon Schubert 
3915796c8dcSSimon Schubert     /* FIXME/carlton-2003-06-27: Delete this in a few years once
3925796c8dcSSimon Schubert        "possible namespace symbols" go away.  */
3935796c8dcSSimon Schubert     struct symtab *cp_namespace_symtab;
3945796c8dcSSimon Schubert   };
3955796c8dcSSimon Schubert 
3965796c8dcSSimon Schubert /* Defines for the objfile flag word. */
3975796c8dcSSimon Schubert 
3985796c8dcSSimon Schubert /* When an object file has its functions reordered (currently Irix-5.2
3995796c8dcSSimon Schubert    shared libraries exhibit this behaviour), we will need an expensive
4005796c8dcSSimon Schubert    algorithm to locate a partial symtab or symtab via an address.
4015796c8dcSSimon Schubert    To avoid this penalty for normal object files, we use this flag,
4025796c8dcSSimon Schubert    whose setting is determined upon symbol table read in.  */
4035796c8dcSSimon Schubert 
4045796c8dcSSimon Schubert #define OBJF_REORDERED	(1 << 0)	/* Functions are reordered */
4055796c8dcSSimon Schubert 
4065796c8dcSSimon Schubert /* Distinguish between an objfile for a shared library and a "vanilla"
4075796c8dcSSimon Schubert    objfile. (If not set, the objfile may still actually be a solib.
4085796c8dcSSimon Schubert    This can happen if the user created the objfile by using the
4095796c8dcSSimon Schubert    add-symbol-file command.  GDB doesn't in that situation actually
4105796c8dcSSimon Schubert    check whether the file is a solib.  Rather, the target's
4115796c8dcSSimon Schubert    implementation of the solib interface is responsible for setting
4125796c8dcSSimon Schubert    this flag when noticing solibs used by an inferior.)  */
4135796c8dcSSimon Schubert 
4145796c8dcSSimon Schubert #define OBJF_SHARED     (1 << 1)	/* From a shared library */
4155796c8dcSSimon Schubert 
4165796c8dcSSimon Schubert /* User requested that this objfile be read in it's entirety. */
4175796c8dcSSimon Schubert 
4185796c8dcSSimon Schubert #define OBJF_READNOW	(1 << 2)	/* Immediate full read */
4195796c8dcSSimon Schubert 
4205796c8dcSSimon Schubert /* This objfile was created because the user explicitly caused it
4215796c8dcSSimon Schubert    (e.g., used the add-symbol-file command).  This bit offers a way
4225796c8dcSSimon Schubert    for run_command to remove old objfile entries which are no longer
4235796c8dcSSimon Schubert    valid (i.e., are associated with an old inferior), but to preserve
4245796c8dcSSimon Schubert    ones that the user explicitly loaded via the add-symbol-file
4255796c8dcSSimon Schubert    command. */
4265796c8dcSSimon Schubert 
4275796c8dcSSimon Schubert #define OBJF_USERLOADED	(1 << 3)	/* User loaded */
4285796c8dcSSimon Schubert 
4295796c8dcSSimon Schubert /* The object file that contains the runtime common minimal symbols
4305796c8dcSSimon Schubert    for SunOS4. Note that this objfile has no associated BFD.  */
4315796c8dcSSimon Schubert 
4325796c8dcSSimon Schubert extern struct objfile *rt_common_objfile;
4335796c8dcSSimon Schubert 
4345796c8dcSSimon Schubert /* When we need to allocate a new type, we need to know which objfile_obstack
4355796c8dcSSimon Schubert    to allocate the type on, since there is one for each objfile.  The places
4365796c8dcSSimon Schubert    where types are allocated are deeply buried in function call hierarchies
4375796c8dcSSimon Schubert    which know nothing about objfiles, so rather than trying to pass a
4385796c8dcSSimon Schubert    particular objfile down to them, we just do an end run around them and
4395796c8dcSSimon Schubert    set current_objfile to be whatever objfile we expect to be using at the
4405796c8dcSSimon Schubert    time types are being allocated.  For instance, when we start reading
4415796c8dcSSimon Schubert    symbols for a particular objfile, we set current_objfile to point to that
4425796c8dcSSimon Schubert    objfile, and when we are done, we set it back to NULL, to ensure that we
4435796c8dcSSimon Schubert    never put a type someplace other than where we are expecting to put it.
4445796c8dcSSimon Schubert    FIXME:  Maybe we should review the entire type handling system and
4455796c8dcSSimon Schubert    see if there is a better way to avoid this problem. */
4465796c8dcSSimon Schubert 
4475796c8dcSSimon Schubert extern struct objfile *current_objfile;
4485796c8dcSSimon Schubert 
4495796c8dcSSimon Schubert /* Declarations for functions defined in objfiles.c */
4505796c8dcSSimon Schubert 
4515796c8dcSSimon Schubert extern struct objfile *allocate_objfile (bfd *, int);
4525796c8dcSSimon Schubert 
4535796c8dcSSimon Schubert extern struct gdbarch *get_objfile_arch (struct objfile *);
4545796c8dcSSimon Schubert 
4555796c8dcSSimon Schubert extern void init_entry_point_info (struct objfile *);
4565796c8dcSSimon Schubert 
457*cf7f2e2dSJohn Marino extern int entry_point_address_query (CORE_ADDR *entry_p);
458*cf7f2e2dSJohn Marino 
4595796c8dcSSimon Schubert extern CORE_ADDR entry_point_address (void);
4605796c8dcSSimon Schubert 
4615796c8dcSSimon Schubert extern int build_objfile_section_table (struct objfile *);
4625796c8dcSSimon Schubert 
4635796c8dcSSimon Schubert extern void terminate_minimal_symbol_table (struct objfile *objfile);
4645796c8dcSSimon Schubert 
465*cf7f2e2dSJohn Marino extern struct objfile *objfile_separate_debug_iterate (const struct objfile *,
466*cf7f2e2dSJohn Marino                                                        const struct objfile *);
467*cf7f2e2dSJohn Marino 
4685796c8dcSSimon Schubert extern void put_objfile_before (struct objfile *, struct objfile *);
4695796c8dcSSimon Schubert 
4705796c8dcSSimon Schubert extern void objfile_to_front (struct objfile *);
4715796c8dcSSimon Schubert 
472*cf7f2e2dSJohn Marino extern void add_separate_debug_objfile (struct objfile *, struct objfile *);
473*cf7f2e2dSJohn Marino 
4745796c8dcSSimon Schubert extern void unlink_objfile (struct objfile *);
4755796c8dcSSimon Schubert 
4765796c8dcSSimon Schubert extern void free_objfile (struct objfile *);
4775796c8dcSSimon Schubert 
478*cf7f2e2dSJohn Marino extern void free_objfile_separate_debug (struct objfile *);
479*cf7f2e2dSJohn Marino 
4805796c8dcSSimon Schubert extern struct cleanup *make_cleanup_free_objfile (struct objfile *);
4815796c8dcSSimon Schubert 
4825796c8dcSSimon Schubert extern void free_all_objfiles (void);
4835796c8dcSSimon Schubert 
4845796c8dcSSimon Schubert extern void objfile_relocate (struct objfile *, struct section_offsets *);
4855796c8dcSSimon Schubert 
4865796c8dcSSimon Schubert extern int objfile_has_partial_symbols (struct objfile *objfile);
4875796c8dcSSimon Schubert 
4885796c8dcSSimon Schubert extern int objfile_has_full_symbols (struct objfile *objfile);
4895796c8dcSSimon Schubert 
490*cf7f2e2dSJohn Marino extern int objfile_has_symbols (struct objfile *objfile);
491*cf7f2e2dSJohn Marino 
4925796c8dcSSimon Schubert extern int have_partial_symbols (void);
4935796c8dcSSimon Schubert 
4945796c8dcSSimon Schubert extern int have_full_symbols (void);
4955796c8dcSSimon Schubert 
4965796c8dcSSimon Schubert extern void objfiles_changed (void);
4975796c8dcSSimon Schubert 
4985796c8dcSSimon Schubert /* This operation deletes all objfile entries that represent solibs that
4995796c8dcSSimon Schubert    weren't explicitly loaded by the user, via e.g., the add-symbol-file
5005796c8dcSSimon Schubert    command.
5015796c8dcSSimon Schubert  */
5025796c8dcSSimon Schubert extern void objfile_purge_solibs (void);
5035796c8dcSSimon Schubert 
5045796c8dcSSimon Schubert /* Functions for dealing with the minimal symbol table, really a misc
5055796c8dcSSimon Schubert    address<->symbol mapping for things we don't have debug symbols for.  */
5065796c8dcSSimon Schubert 
5075796c8dcSSimon Schubert extern int have_minimal_symbols (void);
5085796c8dcSSimon Schubert 
5095796c8dcSSimon Schubert extern struct obj_section *find_pc_section (CORE_ADDR pc);
5105796c8dcSSimon Schubert 
5115796c8dcSSimon Schubert extern int in_plt_section (CORE_ADDR, char *);
5125796c8dcSSimon Schubert 
5135796c8dcSSimon Schubert /* Keep a registry of per-objfile data-pointers required by other GDB
5145796c8dcSSimon Schubert    modules.  */
5155796c8dcSSimon Schubert 
5165796c8dcSSimon Schubert /* Allocate an entry in the per-objfile registry.  */
5175796c8dcSSimon Schubert extern const struct objfile_data *register_objfile_data (void);
5185796c8dcSSimon Schubert 
5195796c8dcSSimon Schubert /* Allocate an entry in the per-objfile registry.
5205796c8dcSSimon Schubert    SAVE and FREE are called when clearing objfile data.
5215796c8dcSSimon Schubert    First all registered SAVE functions are called.
5225796c8dcSSimon Schubert    Then all registered FREE functions are called.
5235796c8dcSSimon Schubert    Either or both of SAVE, FREE may be NULL.  */
5245796c8dcSSimon Schubert extern const struct objfile_data *register_objfile_data_with_cleanup
5255796c8dcSSimon Schubert   (void (*save) (struct objfile *, void *),
5265796c8dcSSimon Schubert    void (*free) (struct objfile *, void *));
5275796c8dcSSimon Schubert 
5285796c8dcSSimon Schubert extern void clear_objfile_data (struct objfile *objfile);
5295796c8dcSSimon Schubert extern void set_objfile_data (struct objfile *objfile,
5305796c8dcSSimon Schubert 			      const struct objfile_data *data, void *value);
5315796c8dcSSimon Schubert extern void *objfile_data (struct objfile *objfile,
5325796c8dcSSimon Schubert 			   const struct objfile_data *data);
5335796c8dcSSimon Schubert 
5345796c8dcSSimon Schubert extern struct bfd *gdb_bfd_ref (struct bfd *abfd);
5355796c8dcSSimon Schubert extern void gdb_bfd_unref (struct bfd *abfd);
536*cf7f2e2dSJohn Marino extern int gdb_bfd_close_or_warn (struct bfd *abfd);
5375796c8dcSSimon Schubert 
5385796c8dcSSimon Schubert 
539*cf7f2e2dSJohn Marino /* Traverse all object files in the current program space.
540*cf7f2e2dSJohn Marino    ALL_OBJFILES_SAFE works even if you delete the objfile during the
541*cf7f2e2dSJohn Marino    traversal.  */
542*cf7f2e2dSJohn Marino 
543*cf7f2e2dSJohn Marino /* Traverse all object files in program space SS.  */
544*cf7f2e2dSJohn Marino 
545*cf7f2e2dSJohn Marino #define ALL_PSPACE_OBJFILES(ss, obj)					\
546*cf7f2e2dSJohn Marino   for ((obj) = ss->objfiles; (obj) != NULL; (obj) = (obj)->next)	\
547*cf7f2e2dSJohn Marino 
548*cf7f2e2dSJohn Marino #define ALL_PSPACE_OBJFILES_SAFE(ss, obj, nxt)		\
549*cf7f2e2dSJohn Marino   for ((obj) = ss->objfiles;			\
550*cf7f2e2dSJohn Marino        (obj) != NULL? ((nxt)=(obj)->next,1) :0;	\
551*cf7f2e2dSJohn Marino        (obj) = (nxt))
5525796c8dcSSimon Schubert 
5535796c8dcSSimon Schubert #define ALL_OBJFILES(obj)			    \
554*cf7f2e2dSJohn Marino   for ((obj) = current_program_space->objfiles; \
555*cf7f2e2dSJohn Marino        (obj) != NULL;				    \
556*cf7f2e2dSJohn Marino        (obj) = (obj)->next)
5575796c8dcSSimon Schubert 
5585796c8dcSSimon Schubert #define ALL_OBJFILES_SAFE(obj,nxt)			\
559*cf7f2e2dSJohn Marino   for ((obj) = current_program_space->objfiles;	\
5605796c8dcSSimon Schubert        (obj) != NULL? ((nxt)=(obj)->next,1) :0;	\
5615796c8dcSSimon Schubert        (obj) = (nxt))
5625796c8dcSSimon Schubert 
5635796c8dcSSimon Schubert /* Traverse all symtabs in one objfile.  */
5645796c8dcSSimon Schubert 
5655796c8dcSSimon Schubert #define	ALL_OBJFILE_SYMTABS(objfile, s) \
5665796c8dcSSimon Schubert     for ((s) = (objfile) -> symtabs; (s) != NULL; (s) = (s) -> next)
5675796c8dcSSimon Schubert 
5685796c8dcSSimon Schubert /* Traverse all minimal symbols in one objfile.  */
5695796c8dcSSimon Schubert 
5705796c8dcSSimon Schubert #define	ALL_OBJFILE_MSYMBOLS(objfile, m) \
5715796c8dcSSimon Schubert     for ((m) = (objfile) -> msymbols; SYMBOL_LINKAGE_NAME(m) != NULL; (m)++)
5725796c8dcSSimon Schubert 
573*cf7f2e2dSJohn Marino /* Traverse all symtabs in all objfiles in the current symbol
574*cf7f2e2dSJohn Marino    space.  */
5755796c8dcSSimon Schubert 
5765796c8dcSSimon Schubert #define	ALL_SYMTABS(objfile, s) \
5775796c8dcSSimon Schubert   ALL_OBJFILES (objfile)	 \
5785796c8dcSSimon Schubert     ALL_OBJFILE_SYMTABS (objfile, s)
5795796c8dcSSimon Schubert 
580*cf7f2e2dSJohn Marino #define ALL_PSPACE_SYMTABS(ss, objfile, s)		\
581*cf7f2e2dSJohn Marino   ALL_PSPACE_OBJFILES (ss, objfile)			\
582*cf7f2e2dSJohn Marino     ALL_OBJFILE_SYMTABS (objfile, s)
583*cf7f2e2dSJohn Marino 
584*cf7f2e2dSJohn Marino /* Traverse all symtabs in all objfiles in the current program space,
585*cf7f2e2dSJohn Marino    skipping included files (which share a blockvector with their
586*cf7f2e2dSJohn Marino    primary symtab).  */
5875796c8dcSSimon Schubert 
5885796c8dcSSimon Schubert #define ALL_PRIMARY_SYMTABS(objfile, s) \
5895796c8dcSSimon Schubert   ALL_OBJFILES (objfile)		\
5905796c8dcSSimon Schubert     ALL_OBJFILE_SYMTABS (objfile, s)	\
5915796c8dcSSimon Schubert       if ((s)->primary)
5925796c8dcSSimon Schubert 
593*cf7f2e2dSJohn Marino #define ALL_PSPACE_PRIMARY_SYMTABS(pspace, objfile, s)	\
594*cf7f2e2dSJohn Marino   ALL_PSPACE_OBJFILES (ss, objfile)			\
595*cf7f2e2dSJohn Marino     ALL_OBJFILE_SYMTABS (objfile, s)			\
596*cf7f2e2dSJohn Marino       if ((s)->primary)
5975796c8dcSSimon Schubert 
598*cf7f2e2dSJohn Marino /* Traverse all minimal symbols in all objfiles in the current symbol
599*cf7f2e2dSJohn Marino    space.  */
6005796c8dcSSimon Schubert 
6015796c8dcSSimon Schubert #define	ALL_MSYMBOLS(objfile, m) \
6025796c8dcSSimon Schubert   ALL_OBJFILES (objfile)	 \
6035796c8dcSSimon Schubert     ALL_OBJFILE_MSYMBOLS (objfile, m)
6045796c8dcSSimon Schubert 
6055796c8dcSSimon Schubert #define ALL_OBJFILE_OSECTIONS(objfile, osect)	\
6065796c8dcSSimon Schubert   for (osect = objfile->sections; osect < objfile->sections_end; osect++)
6075796c8dcSSimon Schubert 
6085796c8dcSSimon Schubert #define ALL_OBJSECTIONS(objfile, osect)		\
6095796c8dcSSimon Schubert   ALL_OBJFILES (objfile)			\
6105796c8dcSSimon Schubert     ALL_OBJFILE_OSECTIONS (objfile, osect)
6115796c8dcSSimon Schubert 
6125796c8dcSSimon Schubert #define SECT_OFF_DATA(objfile) \
6135796c8dcSSimon Schubert      ((objfile->sect_index_data == -1) \
6145796c8dcSSimon Schubert       ? (internal_error (__FILE__, __LINE__, _("sect_index_data not initialized")), -1) \
6155796c8dcSSimon Schubert       : objfile->sect_index_data)
6165796c8dcSSimon Schubert 
6175796c8dcSSimon Schubert #define SECT_OFF_RODATA(objfile) \
6185796c8dcSSimon Schubert      ((objfile->sect_index_rodata == -1) \
6195796c8dcSSimon Schubert       ? (internal_error (__FILE__, __LINE__, _("sect_index_rodata not initialized")), -1) \
6205796c8dcSSimon Schubert       : objfile->sect_index_rodata)
6215796c8dcSSimon Schubert 
6225796c8dcSSimon Schubert #define SECT_OFF_TEXT(objfile) \
6235796c8dcSSimon Schubert      ((objfile->sect_index_text == -1) \
6245796c8dcSSimon Schubert       ? (internal_error (__FILE__, __LINE__, _("sect_index_text not initialized")), -1) \
6255796c8dcSSimon Schubert       : objfile->sect_index_text)
6265796c8dcSSimon Schubert 
6275796c8dcSSimon Schubert /* Sometimes the .bss section is missing from the objfile, so we don't
6285796c8dcSSimon Schubert    want to die here. Let the users of SECT_OFF_BSS deal with an
6295796c8dcSSimon Schubert    uninitialized section index. */
6305796c8dcSSimon Schubert #define SECT_OFF_BSS(objfile) (objfile)->sect_index_bss
6315796c8dcSSimon Schubert 
6325796c8dcSSimon Schubert /* Answer whether there is more than one object file loaded.  */
6335796c8dcSSimon Schubert 
6345796c8dcSSimon Schubert #define MULTI_OBJFILE_P() (object_files && object_files->next)
6355796c8dcSSimon Schubert 
6365796c8dcSSimon Schubert #endif /* !defined (OBJFILES_H) */
637