15796c8dcSSimon Schubert /* Definitions for symbol file management in GDB. 25796c8dcSSimon Schubert 3*a45ae5f8SJohn Marino Copyright (C) 1992-2004, 2007-2012 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" 265796c8dcSSimon Schubert 275796c8dcSSimon Schubert struct bcache; 285796c8dcSSimon Schubert struct htab; 295796c8dcSSimon Schubert struct symtab; 305796c8dcSSimon Schubert struct objfile_data; 315796c8dcSSimon Schubert 325796c8dcSSimon Schubert /* This structure maintains information on a per-objfile basis about the 335796c8dcSSimon Schubert "entry point" of the objfile, and the scope within which the entry point 345796c8dcSSimon Schubert exists. It is possible that gdb will see more than one objfile that is 355796c8dcSSimon Schubert executable, each with its own entry point. 365796c8dcSSimon Schubert 375796c8dcSSimon Schubert For example, for dynamically linked executables in SVR4, the dynamic linker 385796c8dcSSimon Schubert code is contained within the shared C library, which is actually executable 395796c8dcSSimon Schubert and is run by the kernel first when an exec is done of a user executable 405796c8dcSSimon Schubert that is dynamically linked. The dynamic linker within the shared C library 415796c8dcSSimon Schubert then maps in the various program segments in the user executable and jumps 425796c8dcSSimon Schubert to the user executable's recorded entry point, as if the call had been made 435796c8dcSSimon Schubert directly by the kernel. 445796c8dcSSimon Schubert 455796c8dcSSimon Schubert The traditional gdb method of using this info was to use the 465796c8dcSSimon Schubert recorded entry point to set the entry-file's lowpc and highpc from 475796c8dcSSimon Schubert the debugging information, where these values are the starting 485796c8dcSSimon Schubert address (inclusive) and ending address (exclusive) of the 495796c8dcSSimon Schubert instruction space in the executable which correspond to the 50c50c785cSJohn Marino "startup file", i.e. crt0.o in most cases. This file is assumed to 515796c8dcSSimon Schubert be a startup file and frames with pc's inside it are treated as 525796c8dcSSimon Schubert nonexistent. Setting these variables is necessary so that 535796c8dcSSimon Schubert backtraces do not fly off the bottom of the stack. 545796c8dcSSimon Schubert 555796c8dcSSimon Schubert NOTE: cagney/2003-09-09: It turns out that this "traditional" 565796c8dcSSimon Schubert method doesn't work. Corinna writes: ``It turns out that the call 575796c8dcSSimon Schubert to test for "inside entry file" destroys a meaningful backtrace 585796c8dcSSimon Schubert under some conditions. E.g. the backtrace tests in the asm-source 595796c8dcSSimon Schubert testcase are broken for some targets. In this test the functions 605796c8dcSSimon Schubert are all implemented as part of one file and the testcase is not 615796c8dcSSimon Schubert necessarily linked with a start file (depending on the target). 625796c8dcSSimon Schubert What happens is, that the first frame is printed normaly and 635796c8dcSSimon Schubert following frames are treated as being inside the enttry file then. 645796c8dcSSimon Schubert This way, only the #0 frame is printed in the backtrace output.'' 655796c8dcSSimon Schubert Ref "frame.c" "NOTE: vinschen/2003-04-01". 665796c8dcSSimon Schubert 675796c8dcSSimon Schubert Gdb also supports an alternate method to avoid running off the bottom 685796c8dcSSimon Schubert of the stack. 695796c8dcSSimon Schubert 705796c8dcSSimon Schubert There are two frames that are "special", the frame for the function 715796c8dcSSimon Schubert containing the process entry point, since it has no predecessor frame, 725796c8dcSSimon Schubert and the frame for the function containing the user code entry point 735796c8dcSSimon Schubert (the main() function), since all the predecessor frames are for the 745796c8dcSSimon Schubert process startup code. Since we have no guarantee that the linked 755796c8dcSSimon Schubert in startup modules have any debugging information that gdb can use, 765796c8dcSSimon Schubert we need to avoid following frame pointers back into frames that might 775796c8dcSSimon Schubert have been built in the startup code, as we might get hopelessly 785796c8dcSSimon Schubert confused. However, we almost always have debugging information 795796c8dcSSimon Schubert available for main(). 805796c8dcSSimon Schubert 815796c8dcSSimon Schubert These variables are used to save the range of PC values which are 825796c8dcSSimon Schubert valid within the main() function and within the function containing 835796c8dcSSimon Schubert the process entry point. If we always consider the frame for 845796c8dcSSimon Schubert main() as the outermost frame when debugging user code, and the 855796c8dcSSimon Schubert frame for the process entry point function as the outermost frame 865796c8dcSSimon Schubert when debugging startup code, then all we have to do is have 875796c8dcSSimon Schubert DEPRECATED_FRAME_CHAIN_VALID return false whenever a frame's 885796c8dcSSimon Schubert current PC is within the range specified by these variables. In 895796c8dcSSimon Schubert essence, we set "ceilings" in the frame chain beyond which we will 905796c8dcSSimon Schubert not proceed when following the frame chain back up the stack. 915796c8dcSSimon Schubert 925796c8dcSSimon Schubert A nice side effect is that we can still debug startup code without 935796c8dcSSimon Schubert running off the end of the frame chain, assuming that we have usable 945796c8dcSSimon Schubert debugging information in the startup modules, and if we choose to not 955796c8dcSSimon Schubert use the block at main, or can't find it for some reason, everything 965796c8dcSSimon Schubert still works as before. And if we have no startup code debugging 975796c8dcSSimon Schubert information but we do have usable information for main(), backtraces 985796c8dcSSimon Schubert from user code don't go wandering off into the startup code. */ 995796c8dcSSimon Schubert 1005796c8dcSSimon Schubert struct entry_info 1015796c8dcSSimon Schubert { 102cf7f2e2dSJohn Marino /* The relocated value we should use for this objfile entry point. */ 1035796c8dcSSimon Schubert CORE_ADDR entry_point; 1045796c8dcSSimon Schubert 105cf7f2e2dSJohn Marino /* Set to 1 iff ENTRY_POINT contains a valid value. */ 106cf7f2e2dSJohn Marino unsigned entry_point_p : 1; 1075796c8dcSSimon Schubert }; 1085796c8dcSSimon Schubert 1095796c8dcSSimon Schubert /* Sections in an objfile. The section offsets are stored in the 1105796c8dcSSimon Schubert OBJFILE. */ 1115796c8dcSSimon Schubert 1125796c8dcSSimon Schubert struct obj_section 1135796c8dcSSimon Schubert { 1145796c8dcSSimon Schubert struct bfd_section *the_bfd_section; /* BFD section pointer */ 1155796c8dcSSimon Schubert 1165796c8dcSSimon Schubert /* Objfile this section is part of. */ 1175796c8dcSSimon Schubert struct objfile *objfile; 1185796c8dcSSimon Schubert 1195796c8dcSSimon Schubert /* True if this "overlay section" is mapped into an "overlay region". */ 1205796c8dcSSimon Schubert int ovly_mapped; 1215796c8dcSSimon Schubert }; 1225796c8dcSSimon Schubert 1235796c8dcSSimon Schubert /* Relocation offset applied to S. */ 1245796c8dcSSimon Schubert #define obj_section_offset(s) \ 1255796c8dcSSimon Schubert (((s)->objfile->section_offsets)->offsets[(s)->the_bfd_section->index]) 1265796c8dcSSimon Schubert 1275796c8dcSSimon Schubert /* The memory address of section S (vma + offset). */ 1285796c8dcSSimon Schubert #define obj_section_addr(s) \ 129*a45ae5f8SJohn Marino (bfd_get_section_vma ((s)->objfile->obfd, s->the_bfd_section) \ 1305796c8dcSSimon Schubert + obj_section_offset (s)) 1315796c8dcSSimon Schubert 1325796c8dcSSimon Schubert /* The one-passed-the-end memory address of section S 1335796c8dcSSimon Schubert (vma + size + offset). */ 1345796c8dcSSimon Schubert #define obj_section_endaddr(s) \ 135*a45ae5f8SJohn Marino (bfd_get_section_vma ((s)->objfile->obfd, s->the_bfd_section) \ 1365796c8dcSSimon Schubert + bfd_get_section_size ((s)->the_bfd_section) \ 1375796c8dcSSimon Schubert + obj_section_offset (s)) 1385796c8dcSSimon Schubert 1395796c8dcSSimon Schubert /* The "objstats" structure provides a place for gdb to record some 1405796c8dcSSimon Schubert interesting information about its internal state at runtime, on a 1415796c8dcSSimon Schubert per objfile basis, such as information about the number of symbols 1425796c8dcSSimon Schubert read, size of string table (if any), etc. */ 1435796c8dcSSimon Schubert 1445796c8dcSSimon Schubert struct objstats 1455796c8dcSSimon Schubert { 1465796c8dcSSimon Schubert int n_minsyms; /* Number of minimal symbols read */ 1475796c8dcSSimon Schubert int n_psyms; /* Number of partial symbols read */ 1485796c8dcSSimon Schubert int n_syms; /* Number of full symbols read */ 1495796c8dcSSimon Schubert int n_stabs; /* Number of ".stabs" read (if applicable) */ 1505796c8dcSSimon Schubert int n_types; /* Number of types */ 1515796c8dcSSimon Schubert int sz_strtab; /* Size of stringtable, (if applicable) */ 1525796c8dcSSimon Schubert }; 1535796c8dcSSimon Schubert 1545796c8dcSSimon Schubert #define OBJSTAT(objfile, expr) (objfile -> stats.expr) 1555796c8dcSSimon Schubert #define OBJSTATS struct objstats stats 1565796c8dcSSimon Schubert extern void print_objfile_statistics (void); 1575796c8dcSSimon Schubert extern void print_symbol_bcache_statistics (void); 1585796c8dcSSimon Schubert 1595796c8dcSSimon Schubert /* Number of entries in the minimal symbol hash table. */ 1605796c8dcSSimon Schubert #define MINIMAL_SYMBOL_HASH_SIZE 2039 1615796c8dcSSimon Schubert 1625796c8dcSSimon Schubert /* Master structure for keeping track of each file from which 1635796c8dcSSimon Schubert gdb reads symbols. There are several ways these get allocated: 1. 1645796c8dcSSimon Schubert The main symbol file, symfile_objfile, set by the symbol-file command, 1655796c8dcSSimon Schubert 2. Additional symbol files added by the add-symbol-file command, 1665796c8dcSSimon Schubert 3. Shared library objfiles, added by ADD_SOLIB, 4. symbol files 1675796c8dcSSimon Schubert for modules that were loaded when GDB attached to a remote system 1685796c8dcSSimon Schubert (see remote-vx.c). */ 1695796c8dcSSimon Schubert 1705796c8dcSSimon Schubert struct objfile 1715796c8dcSSimon Schubert { 1725796c8dcSSimon Schubert 1735796c8dcSSimon Schubert /* All struct objfile's are chained together by their next pointers. 174*a45ae5f8SJohn Marino The program space field "objfiles" (frequently referenced via 175*a45ae5f8SJohn Marino the macro "object_files") points to the first link in this 176*a45ae5f8SJohn Marino chain. */ 1775796c8dcSSimon Schubert 1785796c8dcSSimon Schubert struct objfile *next; 1795796c8dcSSimon Schubert 180c50c785cSJohn Marino /* The object file's name, tilde-expanded and absolute. Malloc'd; free it 181c50c785cSJohn Marino if you free this struct. This pointer is never NULL. */ 1825796c8dcSSimon Schubert 1835796c8dcSSimon Schubert char *name; 1845796c8dcSSimon Schubert 185c50c785cSJohn Marino CORE_ADDR addr_low; 186c50c785cSJohn Marino 187*a45ae5f8SJohn Marino /* Some flag bits for this objfile. 188*a45ae5f8SJohn Marino The values are defined by OBJF_*. */ 1895796c8dcSSimon Schubert 1905796c8dcSSimon Schubert unsigned short flags; 1915796c8dcSSimon Schubert 192cf7f2e2dSJohn Marino /* The program space associated with this objfile. */ 193cf7f2e2dSJohn Marino 194cf7f2e2dSJohn Marino struct program_space *pspace; 195cf7f2e2dSJohn Marino 1965796c8dcSSimon Schubert /* Each objfile points to a linked list of symtabs derived from this file, 1975796c8dcSSimon Schubert one symtab structure for each compilation unit (source file). Each link 1985796c8dcSSimon Schubert in the symtab list contains a backpointer to this objfile. */ 1995796c8dcSSimon Schubert 2005796c8dcSSimon Schubert struct symtab *symtabs; 2015796c8dcSSimon Schubert 2025796c8dcSSimon Schubert /* Each objfile points to a linked list of partial symtabs derived from 2035796c8dcSSimon Schubert this file, one partial symtab structure for each compilation unit 2045796c8dcSSimon Schubert (source file). */ 2055796c8dcSSimon Schubert 2065796c8dcSSimon Schubert struct partial_symtab *psymtabs; 2075796c8dcSSimon Schubert 2085796c8dcSSimon Schubert /* Map addresses to the entries of PSYMTABS. It would be more efficient to 2095796c8dcSSimon Schubert have a map per the whole process but ADDRMAP cannot selectively remove 2105796c8dcSSimon Schubert its items during FREE_OBJFILE. This mapping is already present even for 2115796c8dcSSimon Schubert PARTIAL_SYMTABs which still have no corresponding full SYMTABs read. */ 2125796c8dcSSimon Schubert 2135796c8dcSSimon Schubert struct addrmap *psymtabs_addrmap; 2145796c8dcSSimon Schubert 215c50c785cSJohn Marino /* List of freed partial symtabs, available for re-use. */ 2165796c8dcSSimon Schubert 2175796c8dcSSimon Schubert struct partial_symtab *free_psymtabs; 2185796c8dcSSimon Schubert 2195796c8dcSSimon Schubert /* The object file's BFD. Can be null if the objfile contains only 2205796c8dcSSimon Schubert minimal symbols, e.g. the run time common symbols for SunOS4. */ 2215796c8dcSSimon Schubert 2225796c8dcSSimon Schubert bfd *obfd; 2235796c8dcSSimon Schubert 2245796c8dcSSimon Schubert /* The gdbarch associated with the BFD. Note that this gdbarch is 2255796c8dcSSimon Schubert determined solely from BFD information, without looking at target 2265796c8dcSSimon Schubert information. The gdbarch determined from a running target may 2275796c8dcSSimon Schubert differ from this e.g. with respect to register types and names. */ 2285796c8dcSSimon Schubert 2295796c8dcSSimon Schubert struct gdbarch *gdbarch; 2305796c8dcSSimon Schubert 2315796c8dcSSimon Schubert /* The modification timestamp of the object file, as of the last time 2325796c8dcSSimon Schubert we read its symbols. */ 2335796c8dcSSimon Schubert 2345796c8dcSSimon Schubert long mtime; 2355796c8dcSSimon Schubert 236*a45ae5f8SJohn Marino /* Cached 32-bit CRC as computed by gnu_debuglink_crc32. CRC32 is valid 237*a45ae5f8SJohn Marino iff CRC32_P. */ 238*a45ae5f8SJohn Marino unsigned long crc32; 239*a45ae5f8SJohn Marino int crc32_p; 240*a45ae5f8SJohn Marino 2415796c8dcSSimon Schubert /* Obstack to hold objects that should be freed when we load a new symbol 2425796c8dcSSimon Schubert table from this object file. */ 2435796c8dcSSimon Schubert 2445796c8dcSSimon Schubert struct obstack objfile_obstack; 2455796c8dcSSimon Schubert 2465796c8dcSSimon Schubert /* A byte cache where we can stash arbitrary "chunks" of bytes that 2475796c8dcSSimon Schubert will not change. */ 2485796c8dcSSimon Schubert 249c50c785cSJohn Marino struct psymbol_bcache *psymbol_cache; /* Byte cache for partial syms. */ 250c50c785cSJohn Marino struct bcache *macro_cache; /* Byte cache for macros. */ 251cf7f2e2dSJohn Marino struct bcache *filename_cache; /* Byte cache for file names. */ 2525796c8dcSSimon Schubert 2535796c8dcSSimon Schubert /* Hash table for mapping symbol names to demangled names. Each 2545796c8dcSSimon Schubert entry in the hash table is actually two consecutive strings, 2555796c8dcSSimon Schubert both null-terminated; the first one is a mangled or linkage 2565796c8dcSSimon Schubert name, and the second is the demangled name or just a zero byte 2575796c8dcSSimon Schubert if the name doesn't demangle. */ 2585796c8dcSSimon Schubert struct htab *demangled_names_hash; 2595796c8dcSSimon Schubert 2605796c8dcSSimon Schubert /* Vectors of all partial symbols read in from file. The actual data 2615796c8dcSSimon Schubert is stored in the objfile_obstack. */ 2625796c8dcSSimon Schubert 2635796c8dcSSimon Schubert struct psymbol_allocation_list global_psymbols; 2645796c8dcSSimon Schubert struct psymbol_allocation_list static_psymbols; 2655796c8dcSSimon Schubert 2665796c8dcSSimon Schubert /* Each file contains a pointer to an array of minimal symbols for all 267c50c785cSJohn Marino global symbols that are defined within the file. The array is 268c50c785cSJohn Marino terminated by a "null symbol", one that has a NULL pointer for the 269c50c785cSJohn Marino name and a zero value for the address. This makes it easy to walk 270c50c785cSJohn Marino through the array when passed a pointer to somewhere in the middle 271c50c785cSJohn Marino of it. There is also a count of the number of symbols, which does 272c50c785cSJohn Marino not include the terminating null symbol. The array itself, as well 273c50c785cSJohn Marino as all the data that it points to, should be allocated on the 274c50c785cSJohn Marino objfile_obstack for this file. */ 2755796c8dcSSimon Schubert 2765796c8dcSSimon Schubert struct minimal_symbol *msymbols; 2775796c8dcSSimon Schubert int minimal_symbol_count; 2785796c8dcSSimon Schubert 2795796c8dcSSimon Schubert /* This is a hash table used to index the minimal symbols by name. */ 2805796c8dcSSimon Schubert 2815796c8dcSSimon Schubert struct minimal_symbol *msymbol_hash[MINIMAL_SYMBOL_HASH_SIZE]; 2825796c8dcSSimon Schubert 2835796c8dcSSimon Schubert /* This hash table is used to index the minimal symbols by their 2845796c8dcSSimon Schubert demangled names. */ 2855796c8dcSSimon Schubert 2865796c8dcSSimon Schubert struct minimal_symbol *msymbol_demangled_hash[MINIMAL_SYMBOL_HASH_SIZE]; 2875796c8dcSSimon Schubert 2885796c8dcSSimon Schubert /* Structure which keeps track of functions that manipulate objfile's 289c50c785cSJohn Marino of the same type as this objfile. I.e. the function to read partial 2905796c8dcSSimon Schubert symbols for example. Note that this structure is in statically 2915796c8dcSSimon Schubert allocated memory, and is shared by all objfiles that use the 2925796c8dcSSimon Schubert object module reader of this type. */ 2935796c8dcSSimon Schubert 294c50c785cSJohn Marino const struct sym_fns *sf; 2955796c8dcSSimon Schubert 2965796c8dcSSimon Schubert /* The per-objfile information about the entry point, the scope (file/func) 2975796c8dcSSimon Schubert containing the entry point, and the scope of the user's main() func. */ 2985796c8dcSSimon Schubert 2995796c8dcSSimon Schubert struct entry_info ei; 3005796c8dcSSimon Schubert 3015796c8dcSSimon Schubert /* Information about stabs. Will be filled in with a dbx_symfile_info 3025796c8dcSSimon Schubert struct by those readers that need it. */ 3035796c8dcSSimon Schubert /* NOTE: cagney/2004-10-23: This has been replaced by per-objfile 3045796c8dcSSimon Schubert data points implemented using "data" and "num_data" below. For 3055796c8dcSSimon Schubert an example of how to use this replacement, see "objfile_data" 3065796c8dcSSimon Schubert in "mips-tdep.c". */ 3075796c8dcSSimon Schubert 3085796c8dcSSimon Schubert struct dbx_symfile_info *deprecated_sym_stab_info; 3095796c8dcSSimon Schubert 3105796c8dcSSimon Schubert /* Hook for information for use by the symbol reader (currently used 3115796c8dcSSimon Schubert for information shared by sym_init and sym_read). It is 3125796c8dcSSimon Schubert typically a pointer to malloc'd memory. The symbol reader's finish 3135796c8dcSSimon Schubert function is responsible for freeing the memory thusly allocated. */ 3145796c8dcSSimon Schubert /* NOTE: cagney/2004-10-23: This has been replaced by per-objfile 3155796c8dcSSimon Schubert data points implemented using "data" and "num_data" below. For 3165796c8dcSSimon Schubert an example of how to use this replacement, see "objfile_data" 3175796c8dcSSimon Schubert in "mips-tdep.c". */ 3185796c8dcSSimon Schubert 3195796c8dcSSimon Schubert void *deprecated_sym_private; 3205796c8dcSSimon Schubert 3215796c8dcSSimon Schubert /* Per objfile data-pointers required by other GDB modules. */ 3225796c8dcSSimon Schubert /* FIXME: kettenis/20030711: This mechanism could replace 3235796c8dcSSimon Schubert deprecated_sym_stab_info and deprecated_sym_private 3245796c8dcSSimon Schubert entirely. */ 3255796c8dcSSimon Schubert 3265796c8dcSSimon Schubert void **data; 3275796c8dcSSimon Schubert unsigned num_data; 3285796c8dcSSimon Schubert 3295796c8dcSSimon Schubert /* Set of relocation offsets to apply to each section. 3305796c8dcSSimon Schubert Currently on the objfile_obstack (which makes no sense, but I'm 3315796c8dcSSimon Schubert not sure it's harming anything). 3325796c8dcSSimon Schubert 3335796c8dcSSimon Schubert These offsets indicate that all symbols (including partial and 3345796c8dcSSimon Schubert minimal symbols) which have been read have been relocated by this 3355796c8dcSSimon Schubert much. Symbols which are yet to be read need to be relocated by 3365796c8dcSSimon Schubert 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 3575796c8dcSSimon Schubert in the table. Currently the table is stored on the 3585796c8dcSSimon Schubert objfile_obstack (which makes no sense, but I'm not sure it's 3595796c8dcSSimon Schubert harming anything). */ 3605796c8dcSSimon Schubert 3615796c8dcSSimon Schubert struct obj_section 3625796c8dcSSimon Schubert *sections, *sections_end; 3635796c8dcSSimon Schubert 364cf7f2e2dSJohn Marino /* GDB allows to have debug symbols in separate object files. This is 365cf7f2e2dSJohn Marino used by .gnu_debuglink, ELF build id note and Mach-O OSO. 366cf7f2e2dSJohn Marino Although this is a tree structure, GDB only support one level 367cf7f2e2dSJohn Marino (ie a separate debug for a separate debug is not supported). Note that 368cf7f2e2dSJohn Marino separate debug object are in the main chain and therefore will be 369cf7f2e2dSJohn Marino visited by ALL_OBJFILES & co iterators. Separate debug objfile always 370cf7f2e2dSJohn Marino has a non-nul separate_debug_objfile_backlink. */ 371cf7f2e2dSJohn Marino 372cf7f2e2dSJohn Marino /* Link to the first separate debug object, if any. */ 3735796c8dcSSimon Schubert struct objfile *separate_debug_objfile; 3745796c8dcSSimon Schubert 3755796c8dcSSimon Schubert /* If this is a separate debug object, this is used as a link to the 3765796c8dcSSimon Schubert actual executable objfile. */ 3775796c8dcSSimon Schubert struct objfile *separate_debug_objfile_backlink; 3785796c8dcSSimon Schubert 379cf7f2e2dSJohn Marino /* If this is a separate debug object, this is a link to the next one 380cf7f2e2dSJohn Marino for the same executable objfile. */ 381cf7f2e2dSJohn Marino struct objfile *separate_debug_objfile_link; 382cf7f2e2dSJohn Marino 383c50c785cSJohn Marino /* Place to stash various statistics about this objfile. */ 3845796c8dcSSimon Schubert OBJSTATS; 3855796c8dcSSimon Schubert 386c50c785cSJohn Marino /* A linked list of symbols created when reading template types or 387c50c785cSJohn Marino function templates. These symbols are not stored in any symbol 388c50c785cSJohn Marino table, so we have to keep them here to relocate them 389c50c785cSJohn Marino properly. */ 390c50c785cSJohn Marino struct symbol *template_symbols; 3915796c8dcSSimon Schubert }; 3925796c8dcSSimon Schubert 3935796c8dcSSimon Schubert /* Defines for the objfile flag word. */ 3945796c8dcSSimon Schubert 3955796c8dcSSimon Schubert /* When an object file has its functions reordered (currently Irix-5.2 3965796c8dcSSimon Schubert shared libraries exhibit this behaviour), we will need an expensive 3975796c8dcSSimon Schubert algorithm to locate a partial symtab or symtab via an address. 3985796c8dcSSimon Schubert To avoid this penalty for normal object files, we use this flag, 3995796c8dcSSimon Schubert whose setting is determined upon symbol table read in. */ 4005796c8dcSSimon Schubert 4015796c8dcSSimon Schubert #define OBJF_REORDERED (1 << 0) /* Functions are reordered */ 4025796c8dcSSimon Schubert 4035796c8dcSSimon Schubert /* Distinguish between an objfile for a shared library and a "vanilla" 4045796c8dcSSimon Schubert objfile. (If not set, the objfile may still actually be a solib. 4055796c8dcSSimon Schubert This can happen if the user created the objfile by using the 4065796c8dcSSimon Schubert add-symbol-file command. GDB doesn't in that situation actually 4075796c8dcSSimon Schubert check whether the file is a solib. Rather, the target's 4085796c8dcSSimon Schubert implementation of the solib interface is responsible for setting 4095796c8dcSSimon Schubert this flag when noticing solibs used by an inferior.) */ 4105796c8dcSSimon Schubert 4115796c8dcSSimon Schubert #define OBJF_SHARED (1 << 1) /* From a shared library */ 4125796c8dcSSimon Schubert 4135796c8dcSSimon Schubert /* User requested that this objfile be read in it's entirety. */ 4145796c8dcSSimon Schubert 4155796c8dcSSimon Schubert #define OBJF_READNOW (1 << 2) /* Immediate full read */ 4165796c8dcSSimon Schubert 4175796c8dcSSimon Schubert /* This objfile was created because the user explicitly caused it 4185796c8dcSSimon Schubert (e.g., used the add-symbol-file command). This bit offers a way 4195796c8dcSSimon Schubert for run_command to remove old objfile entries which are no longer 4205796c8dcSSimon Schubert valid (i.e., are associated with an old inferior), but to preserve 4215796c8dcSSimon Schubert ones that the user explicitly loaded via the add-symbol-file 4225796c8dcSSimon Schubert command. */ 4235796c8dcSSimon Schubert 4245796c8dcSSimon Schubert #define OBJF_USERLOADED (1 << 3) /* User loaded */ 4255796c8dcSSimon Schubert 426c50c785cSJohn Marino /* Set if we have tried to read partial symtabs for this objfile. 427c50c785cSJohn Marino This is used to allow lazy reading of partial symtabs. */ 428c50c785cSJohn Marino 429c50c785cSJohn Marino #define OBJF_PSYMTABS_READ (1 << 4) 430c50c785cSJohn Marino 431*a45ae5f8SJohn Marino /* Set if this is the main symbol file 432*a45ae5f8SJohn Marino (as opposed to symbol file for dynamically loaded code). */ 433*a45ae5f8SJohn Marino 434*a45ae5f8SJohn Marino #define OBJF_MAINLINE (1 << 5) 435*a45ae5f8SJohn Marino 4365796c8dcSSimon Schubert /* The object file that contains the runtime common minimal symbols 4375796c8dcSSimon Schubert for SunOS4. Note that this objfile has no associated BFD. */ 4385796c8dcSSimon Schubert 4395796c8dcSSimon Schubert extern struct objfile *rt_common_objfile; 4405796c8dcSSimon Schubert 4415796c8dcSSimon Schubert /* Declarations for functions defined in objfiles.c */ 4425796c8dcSSimon Schubert 4435796c8dcSSimon Schubert extern struct objfile *allocate_objfile (bfd *, int); 4445796c8dcSSimon Schubert 4455796c8dcSSimon Schubert extern struct gdbarch *get_objfile_arch (struct objfile *); 4465796c8dcSSimon Schubert 4475796c8dcSSimon Schubert extern void init_entry_point_info (struct objfile *); 4485796c8dcSSimon Schubert 449cf7f2e2dSJohn Marino extern int entry_point_address_query (CORE_ADDR *entry_p); 450cf7f2e2dSJohn Marino 4515796c8dcSSimon Schubert extern CORE_ADDR entry_point_address (void); 4525796c8dcSSimon Schubert 4535796c8dcSSimon Schubert extern int build_objfile_section_table (struct objfile *); 4545796c8dcSSimon Schubert 4555796c8dcSSimon Schubert extern void terminate_minimal_symbol_table (struct objfile *objfile); 4565796c8dcSSimon Schubert 457cf7f2e2dSJohn Marino extern struct objfile *objfile_separate_debug_iterate (const struct objfile *, 458cf7f2e2dSJohn Marino const struct objfile *); 459cf7f2e2dSJohn Marino 4605796c8dcSSimon Schubert extern void put_objfile_before (struct objfile *, struct objfile *); 4615796c8dcSSimon Schubert 4625796c8dcSSimon Schubert extern void objfile_to_front (struct objfile *); 4635796c8dcSSimon Schubert 464cf7f2e2dSJohn Marino extern void add_separate_debug_objfile (struct objfile *, struct objfile *); 465cf7f2e2dSJohn Marino 4665796c8dcSSimon Schubert extern void unlink_objfile (struct objfile *); 4675796c8dcSSimon Schubert 4685796c8dcSSimon Schubert extern void free_objfile (struct objfile *); 4695796c8dcSSimon Schubert 470cf7f2e2dSJohn Marino extern void free_objfile_separate_debug (struct objfile *); 471cf7f2e2dSJohn Marino 4725796c8dcSSimon Schubert extern struct cleanup *make_cleanup_free_objfile (struct objfile *); 4735796c8dcSSimon Schubert 4745796c8dcSSimon Schubert extern void free_all_objfiles (void); 4755796c8dcSSimon Schubert 4765796c8dcSSimon Schubert extern void objfile_relocate (struct objfile *, struct section_offsets *); 4775796c8dcSSimon Schubert 4785796c8dcSSimon Schubert extern int objfile_has_partial_symbols (struct objfile *objfile); 4795796c8dcSSimon Schubert 4805796c8dcSSimon Schubert extern int objfile_has_full_symbols (struct objfile *objfile); 4815796c8dcSSimon Schubert 482cf7f2e2dSJohn Marino extern int objfile_has_symbols (struct objfile *objfile); 483cf7f2e2dSJohn Marino 4845796c8dcSSimon Schubert extern int have_partial_symbols (void); 4855796c8dcSSimon Schubert 4865796c8dcSSimon Schubert extern int have_full_symbols (void); 4875796c8dcSSimon Schubert 4885796c8dcSSimon Schubert extern void objfiles_changed (void); 4895796c8dcSSimon Schubert 4905796c8dcSSimon Schubert /* This operation deletes all objfile entries that represent solibs that 4915796c8dcSSimon Schubert weren't explicitly loaded by the user, via e.g., the add-symbol-file 492c50c785cSJohn Marino command. */ 493c50c785cSJohn Marino 4945796c8dcSSimon Schubert extern void objfile_purge_solibs (void); 4955796c8dcSSimon Schubert 4965796c8dcSSimon Schubert /* Functions for dealing with the minimal symbol table, really a misc 4975796c8dcSSimon Schubert address<->symbol mapping for things we don't have debug symbols for. */ 4985796c8dcSSimon Schubert 4995796c8dcSSimon Schubert extern int have_minimal_symbols (void); 5005796c8dcSSimon Schubert 5015796c8dcSSimon Schubert extern struct obj_section *find_pc_section (CORE_ADDR pc); 5025796c8dcSSimon Schubert 5035796c8dcSSimon Schubert extern int in_plt_section (CORE_ADDR, char *); 5045796c8dcSSimon Schubert 5055796c8dcSSimon Schubert /* Keep a registry of per-objfile data-pointers required by other GDB 5065796c8dcSSimon Schubert modules. */ 5075796c8dcSSimon Schubert 5085796c8dcSSimon Schubert /* Allocate an entry in the per-objfile registry. */ 5095796c8dcSSimon Schubert extern const struct objfile_data *register_objfile_data (void); 5105796c8dcSSimon Schubert 5115796c8dcSSimon Schubert /* Allocate an entry in the per-objfile registry. 5125796c8dcSSimon Schubert SAVE and FREE are called when clearing objfile data. 5135796c8dcSSimon Schubert First all registered SAVE functions are called. 5145796c8dcSSimon Schubert Then all registered FREE functions are called. 5155796c8dcSSimon Schubert Either or both of SAVE, FREE may be NULL. */ 5165796c8dcSSimon Schubert extern const struct objfile_data *register_objfile_data_with_cleanup 5175796c8dcSSimon Schubert (void (*save) (struct objfile *, void *), 5185796c8dcSSimon Schubert void (*free) (struct objfile *, void *)); 5195796c8dcSSimon Schubert 5205796c8dcSSimon Schubert extern void clear_objfile_data (struct objfile *objfile); 5215796c8dcSSimon Schubert extern void set_objfile_data (struct objfile *objfile, 5225796c8dcSSimon Schubert const struct objfile_data *data, void *value); 5235796c8dcSSimon Schubert extern void *objfile_data (struct objfile *objfile, 5245796c8dcSSimon Schubert const struct objfile_data *data); 5255796c8dcSSimon Schubert 5265796c8dcSSimon Schubert extern struct bfd *gdb_bfd_ref (struct bfd *abfd); 5275796c8dcSSimon Schubert extern void gdb_bfd_unref (struct bfd *abfd); 528cf7f2e2dSJohn Marino extern int gdb_bfd_close_or_warn (struct bfd *abfd); 5295796c8dcSSimon Schubert 5305796c8dcSSimon Schubert 531cf7f2e2dSJohn Marino /* Traverse all object files in the current program space. 532cf7f2e2dSJohn Marino ALL_OBJFILES_SAFE works even if you delete the objfile during the 533cf7f2e2dSJohn Marino traversal. */ 534cf7f2e2dSJohn Marino 535cf7f2e2dSJohn Marino /* Traverse all object files in program space SS. */ 536cf7f2e2dSJohn Marino 537cf7f2e2dSJohn Marino #define ALL_PSPACE_OBJFILES(ss, obj) \ 538cf7f2e2dSJohn Marino for ((obj) = ss->objfiles; (obj) != NULL; (obj) = (obj)->next) \ 539cf7f2e2dSJohn Marino 540cf7f2e2dSJohn Marino #define ALL_PSPACE_OBJFILES_SAFE(ss, obj, nxt) \ 541cf7f2e2dSJohn Marino for ((obj) = ss->objfiles; \ 542cf7f2e2dSJohn Marino (obj) != NULL? ((nxt)=(obj)->next,1) :0; \ 543cf7f2e2dSJohn Marino (obj) = (nxt)) 5445796c8dcSSimon Schubert 5455796c8dcSSimon Schubert #define ALL_OBJFILES(obj) \ 546cf7f2e2dSJohn Marino for ((obj) = current_program_space->objfiles; \ 547cf7f2e2dSJohn Marino (obj) != NULL; \ 548cf7f2e2dSJohn Marino (obj) = (obj)->next) 5495796c8dcSSimon Schubert 5505796c8dcSSimon Schubert #define ALL_OBJFILES_SAFE(obj,nxt) \ 551cf7f2e2dSJohn Marino for ((obj) = current_program_space->objfiles; \ 5525796c8dcSSimon Schubert (obj) != NULL? ((nxt)=(obj)->next,1) :0; \ 5535796c8dcSSimon Schubert (obj) = (nxt)) 5545796c8dcSSimon Schubert 5555796c8dcSSimon Schubert /* Traverse all symtabs in one objfile. */ 5565796c8dcSSimon Schubert 5575796c8dcSSimon Schubert #define ALL_OBJFILE_SYMTABS(objfile, s) \ 5585796c8dcSSimon Schubert for ((s) = (objfile) -> symtabs; (s) != NULL; (s) = (s) -> next) 5595796c8dcSSimon Schubert 5605796c8dcSSimon Schubert /* Traverse all minimal symbols in one objfile. */ 5615796c8dcSSimon Schubert 5625796c8dcSSimon Schubert #define ALL_OBJFILE_MSYMBOLS(objfile, m) \ 5635796c8dcSSimon Schubert for ((m) = (objfile) -> msymbols; SYMBOL_LINKAGE_NAME(m) != NULL; (m)++) 5645796c8dcSSimon Schubert 565cf7f2e2dSJohn Marino /* Traverse all symtabs in all objfiles in the current symbol 566cf7f2e2dSJohn Marino space. */ 5675796c8dcSSimon Schubert 5685796c8dcSSimon Schubert #define ALL_SYMTABS(objfile, s) \ 5695796c8dcSSimon Schubert ALL_OBJFILES (objfile) \ 5705796c8dcSSimon Schubert ALL_OBJFILE_SYMTABS (objfile, s) 5715796c8dcSSimon Schubert 572cf7f2e2dSJohn Marino #define ALL_PSPACE_SYMTABS(ss, objfile, s) \ 573cf7f2e2dSJohn Marino ALL_PSPACE_OBJFILES (ss, objfile) \ 574cf7f2e2dSJohn Marino ALL_OBJFILE_SYMTABS (objfile, s) 575cf7f2e2dSJohn Marino 576cf7f2e2dSJohn Marino /* Traverse all symtabs in all objfiles in the current program space, 577cf7f2e2dSJohn Marino skipping included files (which share a blockvector with their 578cf7f2e2dSJohn Marino primary symtab). */ 5795796c8dcSSimon Schubert 5805796c8dcSSimon Schubert #define ALL_PRIMARY_SYMTABS(objfile, s) \ 5815796c8dcSSimon Schubert ALL_OBJFILES (objfile) \ 5825796c8dcSSimon Schubert ALL_OBJFILE_SYMTABS (objfile, s) \ 5835796c8dcSSimon Schubert if ((s)->primary) 5845796c8dcSSimon Schubert 585cf7f2e2dSJohn Marino #define ALL_PSPACE_PRIMARY_SYMTABS(pspace, objfile, s) \ 586cf7f2e2dSJohn Marino ALL_PSPACE_OBJFILES (ss, objfile) \ 587cf7f2e2dSJohn Marino ALL_OBJFILE_SYMTABS (objfile, s) \ 588cf7f2e2dSJohn Marino if ((s)->primary) 5895796c8dcSSimon Schubert 590cf7f2e2dSJohn Marino /* Traverse all minimal symbols in all objfiles in the current symbol 591cf7f2e2dSJohn Marino space. */ 5925796c8dcSSimon Schubert 5935796c8dcSSimon Schubert #define ALL_MSYMBOLS(objfile, m) \ 5945796c8dcSSimon Schubert ALL_OBJFILES (objfile) \ 5955796c8dcSSimon Schubert ALL_OBJFILE_MSYMBOLS (objfile, m) 5965796c8dcSSimon Schubert 5975796c8dcSSimon Schubert #define ALL_OBJFILE_OSECTIONS(objfile, osect) \ 5985796c8dcSSimon Schubert for (osect = objfile->sections; osect < objfile->sections_end; osect++) 5995796c8dcSSimon Schubert 600c50c785cSJohn Marino /* Traverse all obj_sections in all objfiles in the current program 601c50c785cSJohn Marino space. 602c50c785cSJohn Marino 603c50c785cSJohn Marino Note that this detects a "break" in the inner loop, and exits 604c50c785cSJohn Marino immediately from the outer loop as well, thus, client code doesn't 605c50c785cSJohn Marino need to know that this is implemented with a double for. The extra 606c50c785cSJohn Marino hair is to make sure that a "break;" stops the outer loop iterating 607c50c785cSJohn Marino as well, and both OBJFILE and OSECT are left unmodified: 608c50c785cSJohn Marino 609c50c785cSJohn Marino - The outer loop learns about the inner loop's end condition, and 610c50c785cSJohn Marino stops iterating if it detects the inner loop didn't reach its 611c50c785cSJohn Marino end. In other words, the outer loop keeps going only if the 612c50c785cSJohn Marino inner loop reached its end cleanly [(osect) == 613c50c785cSJohn Marino (objfile)->sections_end]. 614c50c785cSJohn Marino 615c50c785cSJohn Marino - OSECT is initialized in the outer loop initialization 616c50c785cSJohn Marino expressions, such as if the inner loop has reached its end, so 617c50c785cSJohn Marino the check mentioned above succeeds the first time. 618c50c785cSJohn Marino 619c50c785cSJohn Marino - The trick to not clearing OBJFILE on a "break;" is, in the outer 620c50c785cSJohn Marino loop's loop expression, advance OBJFILE, but iff the inner loop 621c50c785cSJohn Marino reached its end. If not, there was a "break;", so leave OBJFILE 622c50c785cSJohn Marino as is; the outer loop's conditional will break immediately as 623c50c785cSJohn Marino well (as OSECT will be different from OBJFILE->sections_end). */ 624c50c785cSJohn Marino 6255796c8dcSSimon Schubert #define ALL_OBJSECTIONS(objfile, osect) \ 626c50c785cSJohn Marino for ((objfile) = current_program_space->objfiles, \ 627c50c785cSJohn Marino (objfile) != NULL ? ((osect) = (objfile)->sections_end) : 0; \ 628c50c785cSJohn Marino (objfile) != NULL \ 629c50c785cSJohn Marino && (osect) == (objfile)->sections_end; \ 630c50c785cSJohn Marino ((osect) == (objfile)->sections_end \ 631c50c785cSJohn Marino ? ((objfile) = (objfile)->next, \ 632c50c785cSJohn Marino (objfile) != NULL ? (osect) = (objfile)->sections_end : 0) \ 633c50c785cSJohn Marino : 0)) \ 634c50c785cSJohn Marino for ((osect) = (objfile)->sections; \ 635c50c785cSJohn Marino (osect) < (objfile)->sections_end; \ 636c50c785cSJohn Marino (osect)++) 6375796c8dcSSimon Schubert 6385796c8dcSSimon Schubert #define SECT_OFF_DATA(objfile) \ 6395796c8dcSSimon Schubert ((objfile->sect_index_data == -1) \ 640c50c785cSJohn Marino ? (internal_error (__FILE__, __LINE__, \ 641c50c785cSJohn Marino _("sect_index_data not initialized")), -1) \ 6425796c8dcSSimon Schubert : objfile->sect_index_data) 6435796c8dcSSimon Schubert 6445796c8dcSSimon Schubert #define SECT_OFF_RODATA(objfile) \ 6455796c8dcSSimon Schubert ((objfile->sect_index_rodata == -1) \ 646c50c785cSJohn Marino ? (internal_error (__FILE__, __LINE__, \ 647c50c785cSJohn Marino _("sect_index_rodata not initialized")), -1) \ 6485796c8dcSSimon Schubert : objfile->sect_index_rodata) 6495796c8dcSSimon Schubert 6505796c8dcSSimon Schubert #define SECT_OFF_TEXT(objfile) \ 6515796c8dcSSimon Schubert ((objfile->sect_index_text == -1) \ 652c50c785cSJohn Marino ? (internal_error (__FILE__, __LINE__, \ 653c50c785cSJohn Marino _("sect_index_text not initialized")), -1) \ 6545796c8dcSSimon Schubert : objfile->sect_index_text) 6555796c8dcSSimon Schubert 6565796c8dcSSimon Schubert /* Sometimes the .bss section is missing from the objfile, so we don't 6575796c8dcSSimon Schubert want to die here. Let the users of SECT_OFF_BSS deal with an 6585796c8dcSSimon Schubert uninitialized section index. */ 6595796c8dcSSimon Schubert #define SECT_OFF_BSS(objfile) (objfile)->sect_index_bss 6605796c8dcSSimon Schubert 6615796c8dcSSimon Schubert /* Answer whether there is more than one object file loaded. */ 6625796c8dcSSimon Schubert 6635796c8dcSSimon Schubert #define MULTI_OBJFILE_P() (object_files && object_files->next) 6645796c8dcSSimon Schubert 6655796c8dcSSimon Schubert #endif /* !defined (OBJFILES_H) */ 666