symfile.c revision 19370
119370Spst/* Generic symbol file reading for the GNU debugger, GDB. 219370Spst Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996 319370Spst Free Software Foundation, Inc. 419370Spst Contributed by Cygnus Support, using pieces from other GDB modules. 519370Spst 619370SpstThis file is part of GDB. 719370Spst 819370SpstThis program is free software; you can redistribute it and/or modify 919370Spstit under the terms of the GNU General Public License as published by 1019370Spstthe Free Software Foundation; either version 2 of the License, or 1119370Spst(at your option) any later version. 1219370Spst 1319370SpstThis program is distributed in the hope that it will be useful, 1419370Spstbut WITHOUT ANY WARRANTY; without even the implied warranty of 1519370SpstMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1619370SpstGNU General Public License for more details. 1719370Spst 1819370SpstYou should have received a copy of the GNU General Public License 1919370Spstalong with this program; if not, write to the Free Software 2019370SpstFoundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ 2119370Spst 2219370Spst#include "defs.h" 2319370Spst#include "symtab.h" 2419370Spst#include "gdbtypes.h" 2519370Spst#include "gdbcore.h" 2619370Spst#include "frame.h" 2719370Spst#include "target.h" 2819370Spst#include "value.h" 2919370Spst#include "symfile.h" 3019370Spst#include "objfiles.h" 3119370Spst#include "gdbcmd.h" 3219370Spst#include "breakpoint.h" 3319370Spst#include "language.h" 3419370Spst#include "complaints.h" 3519370Spst#include "demangle.h" 3619370Spst#include "inferior.h" /* for write_pc */ 3719370Spst 3819370Spst#include "obstack.h" 3919370Spst#include <assert.h> 4019370Spst 4119370Spst#include <sys/types.h> 4219370Spst#include <fcntl.h> 4319370Spst#include "gdb_string.h" 4419370Spst#include "gdb_stat.h" 4519370Spst#include <ctype.h> 4619370Spst#include <time.h> 4719370Spst#ifdef HAVE_UNISTD_H 4819370Spst#include <unistd.h> 4919370Spst#endif 5019370Spst 5119370Spst#ifndef O_BINARY 5219370Spst#define O_BINARY 0 5319370Spst#endif 5419370Spst 5519370Spst/* Global variables owned by this file */ 5619370Spstint readnow_symbol_files; /* Read full symbols immediately */ 5719370Spst 5819370Spststruct complaint oldsyms_complaint = { 5919370Spst "Replacing old symbols for `%s'", 0, 0 6019370Spst}; 6119370Spst 6219370Spststruct complaint empty_symtab_complaint = { 6319370Spst "Empty symbol table found for `%s'", 0, 0 6419370Spst}; 6519370Spst 6619370Spst/* External variables and functions referenced. */ 6719370Spst 6819370Spstextern int info_verbose; 6919370Spst 7019370Spst/* Functions this file defines */ 7119370Spst 7219370Spststatic void 7319370Spstset_initial_language PARAMS ((void)); 7419370Spst 7519370Spststatic void 7619370Spstload_command PARAMS ((char *, int)); 7719370Spst 7819370Spststatic void 7919370Spstadd_symbol_file_command PARAMS ((char *, int)); 8019370Spst 8119370Spststatic void 8219370Spstadd_shared_symbol_files_command PARAMS ((char *, int)); 8319370Spst 8419370Spststatic void 8519370Spstcashier_psymtab PARAMS ((struct partial_symtab *)); 8619370Spst 8719370Spststatic int 8819370Spstcompare_psymbols PARAMS ((const void *, const void *)); 8919370Spst 9019370Spststatic int 9119370Spstcompare_symbols PARAMS ((const void *, const void *)); 9219370Spst 9319370Spststatic bfd * 9419370Spstsymfile_bfd_open PARAMS ((char *)); 9519370Spst 9619370Spststatic void 9719370Spstfind_sym_fns PARAMS ((struct objfile *)); 9819370Spst 9919370Spst/* List of all available sym_fns. On gdb startup, each object file reader 10019370Spst calls add_symtab_fns() to register information on each format it is 10119370Spst prepared to read. */ 10219370Spst 10319370Spststatic struct sym_fns *symtab_fns = NULL; 10419370Spst 10519370Spst/* Flag for whether user will be reloading symbols multiple times. 10619370Spst Defaults to ON for VxWorks, otherwise OFF. */ 10719370Spst 10819370Spst#ifdef SYMBOL_RELOADING_DEFAULT 10919370Spstint symbol_reloading = SYMBOL_RELOADING_DEFAULT; 11019370Spst#else 11119370Spstint symbol_reloading = 0; 11219370Spst#endif 11319370Spst 11419370Spst/* If true, then shared library symbols will be added automatically 11519370Spst when the inferior is created, new libraries are loaded, or when 11619370Spst attaching to the inferior. This is almost always what users 11719370Spst will want to have happen; but for very large programs, the startup 11819370Spst time will be excessive, and so if this is a problem, the user can 11919370Spst clear this flag and then add the shared library symbols as needed. 12019370Spst Note that there is a potential for confusion, since if the shared 12119370Spst library symbols are not loaded, commands like "info fun" will *not* 12219370Spst report all the functions that are actually present. */ 12319370Spst 12419370Spstint auto_solib_add = 1; 12519370Spst 12619370Spst 12719370Spst/* Since this function is called from within qsort, in an ANSI environment 12819370Spst it must conform to the prototype for qsort, which specifies that the 12919370Spst comparison function takes two "void *" pointers. */ 13019370Spst 13119370Spststatic int 13219370Spstcompare_symbols (s1p, s2p) 13319370Spst const PTR s1p; 13419370Spst const PTR s2p; 13519370Spst{ 13619370Spst register struct symbol **s1, **s2; 13719370Spst 13819370Spst s1 = (struct symbol **) s1p; 13919370Spst s2 = (struct symbol **) s2p; 14019370Spst 14119370Spst return (STRCMP (SYMBOL_NAME (*s1), SYMBOL_NAME (*s2))); 14219370Spst} 14319370Spst 14419370Spst/* 14519370Spst 14619370SpstLOCAL FUNCTION 14719370Spst 14819370Spst compare_psymbols -- compare two partial symbols by name 14919370Spst 15019370SpstDESCRIPTION 15119370Spst 15219370Spst Given pointers to pointers to two partial symbol table entries, 15319370Spst compare them by name and return -N, 0, or +N (ala strcmp). 15419370Spst Typically used by sorting routines like qsort(). 15519370Spst 15619370SpstNOTES 15719370Spst 15819370Spst Does direct compare of first two characters before punting 15919370Spst and passing to strcmp for longer compares. Note that the 16019370Spst original version had a bug whereby two null strings or two 16119370Spst identically named one character strings would return the 16219370Spst comparison of memory following the null byte. 16319370Spst 16419370Spst */ 16519370Spst 16619370Spststatic int 16719370Spstcompare_psymbols (s1p, s2p) 16819370Spst const PTR s1p; 16919370Spst const PTR s2p; 17019370Spst{ 17119370Spst register char *st1 = SYMBOL_NAME (*(struct partial_symbol **) s1p); 17219370Spst register char *st2 = SYMBOL_NAME (*(struct partial_symbol **) s2p); 17319370Spst 17419370Spst if ((st1[0] - st2[0]) || !st1[0]) 17519370Spst { 17619370Spst return (st1[0] - st2[0]); 17719370Spst } 17819370Spst else if ((st1[1] - st2[1]) || !st1[1]) 17919370Spst { 18019370Spst return (st1[1] - st2[1]); 18119370Spst } 18219370Spst else 18319370Spst { 18419370Spst return (STRCMP (st1 + 2, st2 + 2)); 18519370Spst } 18619370Spst} 18719370Spst 18819370Spstvoid 18919370Spstsort_pst_symbols (pst) 19019370Spst struct partial_symtab *pst; 19119370Spst{ 19219370Spst /* Sort the global list; don't sort the static list */ 19319370Spst 19419370Spst qsort (pst -> objfile -> global_psymbols.list + pst -> globals_offset, 19519370Spst pst -> n_global_syms, sizeof (struct partial_symbol *), 19619370Spst compare_psymbols); 19719370Spst} 19819370Spst 19919370Spst/* Call sort_block_syms to sort alphabetically the symbols of one block. */ 20019370Spst 20119370Spstvoid 20219370Spstsort_block_syms (b) 20319370Spst register struct block *b; 20419370Spst{ 20519370Spst qsort (&BLOCK_SYM (b, 0), BLOCK_NSYMS (b), 20619370Spst sizeof (struct symbol *), compare_symbols); 20719370Spst} 20819370Spst 20919370Spst/* Call sort_symtab_syms to sort alphabetically 21019370Spst the symbols of each block of one symtab. */ 21119370Spst 21219370Spstvoid 21319370Spstsort_symtab_syms (s) 21419370Spst register struct symtab *s; 21519370Spst{ 21619370Spst register struct blockvector *bv; 21719370Spst int nbl; 21819370Spst int i; 21919370Spst register struct block *b; 22019370Spst 22119370Spst if (s == 0) 22219370Spst return; 22319370Spst bv = BLOCKVECTOR (s); 22419370Spst nbl = BLOCKVECTOR_NBLOCKS (bv); 22519370Spst for (i = 0; i < nbl; i++) 22619370Spst { 22719370Spst b = BLOCKVECTOR_BLOCK (bv, i); 22819370Spst if (BLOCK_SHOULD_SORT (b)) 22919370Spst sort_block_syms (b); 23019370Spst } 23119370Spst} 23219370Spst 23319370Spst/* Make a copy of the string at PTR with SIZE characters in the symbol obstack 23419370Spst (and add a null character at the end in the copy). 23519370Spst Returns the address of the copy. */ 23619370Spst 23719370Spstchar * 23819370Spstobsavestring (ptr, size, obstackp) 23919370Spst char *ptr; 24019370Spst int size; 24119370Spst struct obstack *obstackp; 24219370Spst{ 24319370Spst register char *p = (char *) obstack_alloc (obstackp, size + 1); 24419370Spst /* Open-coded memcpy--saves function call time. 24519370Spst These strings are usually short. */ 24619370Spst { 24719370Spst register char *p1 = ptr; 24819370Spst register char *p2 = p; 24919370Spst char *end = ptr + size; 25019370Spst while (p1 != end) 25119370Spst *p2++ = *p1++; 25219370Spst } 25319370Spst p[size] = 0; 25419370Spst return p; 25519370Spst} 25619370Spst 25719370Spst/* Concatenate strings S1, S2 and S3; return the new string. 25819370Spst Space is found in the symbol_obstack. */ 25919370Spst 26019370Spstchar * 26119370Spstobconcat (obstackp, s1, s2, s3) 26219370Spst struct obstack *obstackp; 26319370Spst const char *s1, *s2, *s3; 26419370Spst{ 26519370Spst register int len = strlen (s1) + strlen (s2) + strlen (s3) + 1; 26619370Spst register char *val = (char *) obstack_alloc (obstackp, len); 26719370Spst strcpy (val, s1); 26819370Spst strcat (val, s2); 26919370Spst strcat (val, s3); 27019370Spst return val; 27119370Spst} 27219370Spst 27319370Spst/* True if we are nested inside psymtab_to_symtab. */ 27419370Spst 27519370Spstint currently_reading_symtab = 0; 27619370Spst 27719370Spststatic void 27819370Spstdecrement_reading_symtab (dummy) 27919370Spst void *dummy; 28019370Spst{ 28119370Spst currently_reading_symtab--; 28219370Spst} 28319370Spst 28419370Spst/* Get the symbol table that corresponds to a partial_symtab. 28519370Spst This is fast after the first time you do it. In fact, there 28619370Spst is an even faster macro PSYMTAB_TO_SYMTAB that does the fast 28719370Spst case inline. */ 28819370Spst 28919370Spststruct symtab * 29019370Spstpsymtab_to_symtab (pst) 29119370Spst register struct partial_symtab *pst; 29219370Spst{ 29319370Spst /* If it's been looked up before, return it. */ 29419370Spst if (pst->symtab) 29519370Spst return pst->symtab; 29619370Spst 29719370Spst /* If it has not yet been read in, read it. */ 29819370Spst if (!pst->readin) 29919370Spst { 30019370Spst struct cleanup *back_to = make_cleanup (decrement_reading_symtab, NULL); 30119370Spst currently_reading_symtab++; 30219370Spst (*pst->read_symtab) (pst); 30319370Spst do_cleanups (back_to); 30419370Spst } 30519370Spst 30619370Spst return pst->symtab; 30719370Spst} 30819370Spst 30919370Spst/* Initialize entry point information for this objfile. */ 31019370Spst 31119370Spstvoid 31219370Spstinit_entry_point_info (objfile) 31319370Spst struct objfile *objfile; 31419370Spst{ 31519370Spst /* Save startup file's range of PC addresses to help blockframe.c 31619370Spst decide where the bottom of the stack is. */ 31719370Spst 31819370Spst if (bfd_get_file_flags (objfile -> obfd) & EXEC_P) 31919370Spst { 32019370Spst /* Executable file -- record its entry point so we'll recognize 32119370Spst the startup file because it contains the entry point. */ 32219370Spst objfile -> ei.entry_point = bfd_get_start_address (objfile -> obfd); 32319370Spst } 32419370Spst else 32519370Spst { 32619370Spst /* Examination of non-executable.o files. Short-circuit this stuff. */ 32719370Spst objfile -> ei.entry_point = INVALID_ENTRY_POINT; 32819370Spst } 32919370Spst objfile -> ei.entry_file_lowpc = INVALID_ENTRY_LOWPC; 33019370Spst objfile -> ei.entry_file_highpc = INVALID_ENTRY_HIGHPC; 33119370Spst objfile -> ei.entry_func_lowpc = INVALID_ENTRY_LOWPC; 33219370Spst objfile -> ei.entry_func_highpc = INVALID_ENTRY_HIGHPC; 33319370Spst objfile -> ei.main_func_lowpc = INVALID_ENTRY_LOWPC; 33419370Spst objfile -> ei.main_func_highpc = INVALID_ENTRY_HIGHPC; 33519370Spst} 33619370Spst 33719370Spst/* Get current entry point address. */ 33819370Spst 33919370SpstCORE_ADDR 34019370Spstentry_point_address() 34119370Spst{ 34219370Spst return symfile_objfile ? symfile_objfile->ei.entry_point : 0; 34319370Spst} 34419370Spst 34519370Spst/* Remember the lowest-addressed loadable section we've seen. 34619370Spst This function is called via bfd_map_over_sections. 34719370Spst 34819370Spst In case of equal vmas, the section with the largest size becomes the 34919370Spst lowest-addressed loadable section. 35019370Spst 35119370Spst If the vmas and sizes are equal, the last section is considered the 35219370Spst lowest-addressed loadable section. */ 35319370Spst 35419370Spstvoid 35519370Spstfind_lowest_section (abfd, sect, obj) 35619370Spst bfd *abfd; 35719370Spst asection *sect; 35819370Spst PTR obj; 35919370Spst{ 36019370Spst asection **lowest = (asection **)obj; 36119370Spst 36219370Spst if (0 == (bfd_get_section_flags (abfd, sect) & SEC_LOAD)) 36319370Spst return; 36419370Spst if (!*lowest) 36519370Spst *lowest = sect; /* First loadable section */ 36619370Spst else if (bfd_section_vma (abfd, *lowest) > bfd_section_vma (abfd, sect)) 36719370Spst *lowest = sect; /* A lower loadable section */ 36819370Spst else if (bfd_section_vma (abfd, *lowest) == bfd_section_vma (abfd, sect) 36919370Spst && (bfd_section_size (abfd, (*lowest)) 37019370Spst <= bfd_section_size (abfd, sect))) 37119370Spst *lowest = sect; 37219370Spst} 37319370Spst 37419370Spst/* Process a symbol file, as either the main file or as a dynamically 37519370Spst loaded file. 37619370Spst 37719370Spst NAME is the file name (which will be tilde-expanded and made 37819370Spst absolute herein) (but we don't free or modify NAME itself). 37919370Spst FROM_TTY says how verbose to be. MAINLINE specifies whether this 38019370Spst is the main symbol file, or whether it's an extra symbol file such 38119370Spst as dynamically loaded code. If !mainline, ADDR is the address 38219370Spst where the text segment was loaded. If VERBO, the caller has printed 38319370Spst a verbose message about the symbol reading (and complaints can be 38419370Spst more terse about it). */ 38519370Spst 38619370Spstvoid 38719370Spstsyms_from_objfile (objfile, addr, mainline, verbo) 38819370Spst struct objfile *objfile; 38919370Spst CORE_ADDR addr; 39019370Spst int mainline; 39119370Spst int verbo; 39219370Spst{ 39319370Spst struct section_offsets *section_offsets; 39419370Spst asection *lowest_sect; 39519370Spst struct cleanup *old_chain; 39619370Spst 39719370Spst init_entry_point_info (objfile); 39819370Spst find_sym_fns (objfile); 39919370Spst 40019370Spst /* Make sure that partially constructed symbol tables will be cleaned up 40119370Spst if an error occurs during symbol reading. */ 40219370Spst old_chain = make_cleanup (free_objfile, objfile); 40319370Spst 40419370Spst if (mainline) 40519370Spst { 40619370Spst /* We will modify the main symbol table, make sure that all its users 40719370Spst will be cleaned up if an error occurs during symbol reading. */ 40819370Spst make_cleanup (clear_symtab_users, 0); 40919370Spst 41019370Spst /* Since no error yet, throw away the old symbol table. */ 41119370Spst 41219370Spst if (symfile_objfile != NULL) 41319370Spst { 41419370Spst free_objfile (symfile_objfile); 41519370Spst symfile_objfile = NULL; 41619370Spst } 41719370Spst 41819370Spst /* Currently we keep symbols from the add-symbol-file command. 41919370Spst If the user wants to get rid of them, they should do "symbol-file" 42019370Spst without arguments first. Not sure this is the best behavior 42119370Spst (PR 2207). */ 42219370Spst 42319370Spst (*objfile -> sf -> sym_new_init) (objfile); 42419370Spst } 42519370Spst 42619370Spst /* Convert addr into an offset rather than an absolute address. 42719370Spst We find the lowest address of a loaded segment in the objfile, 42819370Spst and assume that <addr> is where that got loaded. Due to historical 42919370Spst precedent, we warn if that doesn't happen to be a text segment. */ 43019370Spst 43119370Spst if (mainline) 43219370Spst { 43319370Spst addr = 0; /* No offset from objfile addresses. */ 43419370Spst } 43519370Spst else 43619370Spst { 43719370Spst lowest_sect = bfd_get_section_by_name (objfile->obfd, ".text"); 43819370Spst if (lowest_sect == NULL) 43919370Spst bfd_map_over_sections (objfile->obfd, find_lowest_section, 44019370Spst (PTR) &lowest_sect); 44119370Spst 44219370Spst if (lowest_sect == NULL) 44319370Spst warning ("no loadable sections found in added symbol-file %s", 44419370Spst objfile->name); 44519370Spst else if ((bfd_get_section_flags (objfile->obfd, lowest_sect) & SEC_CODE) 44619370Spst == 0) 44719370Spst /* FIXME-32x64--assumes bfd_vma fits in long. */ 44819370Spst warning ("Lowest section in %s is %s at 0x%lx", 44919370Spst objfile->name, 45019370Spst bfd_section_name (objfile->obfd, lowest_sect), 45119370Spst (unsigned long) bfd_section_vma (objfile->obfd, lowest_sect)); 45219370Spst 45319370Spst if (lowest_sect) 45419370Spst addr -= bfd_section_vma (objfile->obfd, lowest_sect); 45519370Spst } 45619370Spst 45719370Spst /* Initialize symbol reading routines for this objfile, allow complaints to 45819370Spst appear for this new file, and record how verbose to be, then do the 45919370Spst initial symbol reading for this file. */ 46019370Spst 46119370Spst (*objfile -> sf -> sym_init) (objfile); 46219370Spst clear_complaints (1, verbo); 46319370Spst 46419370Spst section_offsets = (*objfile -> sf -> sym_offsets) (objfile, addr); 46519370Spst objfile->section_offsets = section_offsets; 46619370Spst 46719370Spst#ifndef IBM6000_TARGET 46819370Spst /* This is a SVR4/SunOS specific hack, I think. In any event, it 46919370Spst screws RS/6000. sym_offsets should be doing this sort of thing, 47019370Spst because it knows the mapping between bfd sections and 47119370Spst section_offsets. */ 47219370Spst /* This is a hack. As far as I can tell, section offsets are not 47319370Spst target dependent. They are all set to addr with a couple of 47419370Spst exceptions. The exceptions are sysvr4 shared libraries, whose 47519370Spst offsets are kept in solib structures anyway and rs6000 xcoff 47619370Spst which handles shared libraries in a completely unique way. 47719370Spst 47819370Spst Section offsets are built similarly, except that they are built 47919370Spst by adding addr in all cases because there is no clear mapping 48019370Spst from section_offsets into actual sections. Note that solib.c 48119370Spst has a different algorythm for finding section offsets. 48219370Spst 48319370Spst These should probably all be collapsed into some target 48419370Spst independent form of shared library support. FIXME. */ 48519370Spst 48619370Spst if (addr) 48719370Spst { 48819370Spst struct obj_section *s; 48919370Spst 49019370Spst for (s = objfile->sections; s < objfile->sections_end; ++s) 49119370Spst { 49219370Spst s->addr -= s->offset; 49319370Spst s->addr += addr; 49419370Spst s->endaddr -= s->offset; 49519370Spst s->endaddr += addr; 49619370Spst s->offset += addr; 49719370Spst } 49819370Spst } 49919370Spst#endif /* not IBM6000_TARGET */ 50019370Spst 50119370Spst (*objfile -> sf -> sym_read) (objfile, section_offsets, mainline); 50219370Spst 50319370Spst if (!have_partial_symbols () && !have_full_symbols ()) 50419370Spst { 50519370Spst wrap_here (""); 50619370Spst printf_filtered ("(no debugging symbols found)..."); 50719370Spst wrap_here (""); 50819370Spst } 50919370Spst 51019370Spst /* Don't allow char * to have a typename (else would get caddr_t). 51119370Spst Ditto void *. FIXME: Check whether this is now done by all the 51219370Spst symbol readers themselves (many of them now do), and if so remove 51319370Spst it from here. */ 51419370Spst 51519370Spst TYPE_NAME (lookup_pointer_type (builtin_type_char)) = 0; 51619370Spst TYPE_NAME (lookup_pointer_type (builtin_type_void)) = 0; 51719370Spst 51819370Spst /* Mark the objfile has having had initial symbol read attempted. Note 51919370Spst that this does not mean we found any symbols... */ 52019370Spst 52119370Spst objfile -> flags |= OBJF_SYMS; 52219370Spst 52319370Spst /* Discard cleanups as symbol reading was successful. */ 52419370Spst 52519370Spst discard_cleanups (old_chain); 52619370Spst 52719370Spst/* Call this after reading in a new symbol table to give target dependant code 52819370Spst a crack at the new symbols. For instance, this could be used to update the 52919370Spst values of target-specific symbols GDB needs to keep track of (such as 53019370Spst _sigtramp, or whatever). */ 53119370Spst 53219370Spst TARGET_SYMFILE_POSTREAD (objfile); 53319370Spst} 53419370Spst 53519370Spst/* Perform required actions after either reading in the initial 53619370Spst symbols for a new objfile, or mapping in the symbols from a reusable 53719370Spst objfile. */ 53819370Spst 53919370Spstvoid 54019370Spstnew_symfile_objfile (objfile, mainline, verbo) 54119370Spst struct objfile *objfile; 54219370Spst int mainline; 54319370Spst int verbo; 54419370Spst{ 54519370Spst 54619370Spst /* If this is the main symbol file we have to clean up all users of the 54719370Spst old main symbol file. Otherwise it is sufficient to fixup all the 54819370Spst breakpoints that may have been redefined by this symbol file. */ 54919370Spst if (mainline) 55019370Spst { 55119370Spst /* OK, make it the "real" symbol file. */ 55219370Spst symfile_objfile = objfile; 55319370Spst 55419370Spst clear_symtab_users (); 55519370Spst } 55619370Spst else 55719370Spst { 55819370Spst breakpoint_re_set (); 55919370Spst } 56019370Spst 56119370Spst /* We're done reading the symbol file; finish off complaints. */ 56219370Spst clear_complaints (0, verbo); 56319370Spst} 56419370Spst 56519370Spst/* Process a symbol file, as either the main file or as a dynamically 56619370Spst loaded file. 56719370Spst 56819370Spst NAME is the file name (which will be tilde-expanded and made 56919370Spst absolute herein) (but we don't free or modify NAME itself). 57019370Spst FROM_TTY says how verbose to be. MAINLINE specifies whether this 57119370Spst is the main symbol file, or whether it's an extra symbol file such 57219370Spst as dynamically loaded code. If !mainline, ADDR is the address 57319370Spst where the text segment was loaded. 57419370Spst 57519370Spst Upon success, returns a pointer to the objfile that was added. 57619370Spst Upon failure, jumps back to command level (never returns). */ 57719370Spst 57819370Spststruct objfile * 57919370Spstsymbol_file_add (name, from_tty, addr, mainline, mapped, readnow) 58019370Spst char *name; 58119370Spst int from_tty; 58219370Spst CORE_ADDR addr; 58319370Spst int mainline; 58419370Spst int mapped; 58519370Spst int readnow; 58619370Spst{ 58719370Spst struct objfile *objfile; 58819370Spst struct partial_symtab *psymtab; 58919370Spst bfd *abfd; 59019370Spst 59119370Spst /* Open a bfd for the file, and give user a chance to burp if we'd be 59219370Spst interactively wiping out any existing symbols. */ 59319370Spst 59419370Spst abfd = symfile_bfd_open (name); 59519370Spst 59619370Spst if ((have_full_symbols () || have_partial_symbols ()) 59719370Spst && mainline 59819370Spst && from_tty 59919370Spst && !query ("Load new symbol table from \"%s\"? ", name)) 60019370Spst error ("Not confirmed."); 60119370Spst 60219370Spst objfile = allocate_objfile (abfd, mapped); 60319370Spst 60419370Spst /* If the objfile uses a mapped symbol file, and we have a psymtab for 60519370Spst it, then skip reading any symbols at this time. */ 60619370Spst 60719370Spst if ((objfile -> flags & OBJF_MAPPED) && (objfile -> flags & OBJF_SYMS)) 60819370Spst { 60919370Spst /* We mapped in an existing symbol table file that already has had 61019370Spst initial symbol reading performed, so we can skip that part. Notify 61119370Spst the user that instead of reading the symbols, they have been mapped. 61219370Spst */ 61319370Spst if (from_tty || info_verbose) 61419370Spst { 61519370Spst printf_filtered ("Mapped symbols for %s...", name); 61619370Spst wrap_here (""); 61719370Spst gdb_flush (gdb_stdout); 61819370Spst } 61919370Spst init_entry_point_info (objfile); 62019370Spst find_sym_fns (objfile); 62119370Spst } 62219370Spst else 62319370Spst { 62419370Spst /* We either created a new mapped symbol table, mapped an existing 62519370Spst symbol table file which has not had initial symbol reading 62619370Spst performed, or need to read an unmapped symbol table. */ 62719370Spst if (from_tty || info_verbose) 62819370Spst { 62919370Spst printf_filtered ("Reading symbols from %s...", name); 63019370Spst wrap_here (""); 63119370Spst gdb_flush (gdb_stdout); 63219370Spst } 63319370Spst syms_from_objfile (objfile, addr, mainline, from_tty); 63419370Spst } 63519370Spst 63619370Spst /* We now have at least a partial symbol table. Check to see if the 63719370Spst user requested that all symbols be read on initial access via either 63819370Spst the gdb startup command line or on a per symbol file basis. Expand 63919370Spst all partial symbol tables for this objfile if so. */ 64019370Spst 64119370Spst if (readnow || readnow_symbol_files) 64219370Spst { 64319370Spst if (from_tty || info_verbose) 64419370Spst { 64519370Spst printf_filtered ("expanding to full symbols..."); 64619370Spst wrap_here (""); 64719370Spst gdb_flush (gdb_stdout); 64819370Spst } 64919370Spst 65019370Spst for (psymtab = objfile -> psymtabs; 65119370Spst psymtab != NULL; 65219370Spst psymtab = psymtab -> next) 65319370Spst { 65419370Spst psymtab_to_symtab (psymtab); 65519370Spst } 65619370Spst } 65719370Spst 65819370Spst if (from_tty || info_verbose) 65919370Spst { 66019370Spst printf_filtered ("done.\n"); 66119370Spst gdb_flush (gdb_stdout); 66219370Spst } 66319370Spst 66419370Spst new_symfile_objfile (objfile, mainline, from_tty); 66519370Spst 66619370Spst return (objfile); 66719370Spst} 66819370Spst 66919370Spst/* This is the symbol-file command. Read the file, analyze its 67019370Spst symbols, and add a struct symtab to a symtab list. The syntax of 67119370Spst the command is rather bizarre--(1) buildargv implements various 67219370Spst quoting conventions which are undocumented and have little or 67319370Spst nothing in common with the way things are quoted (or not quoted) 67419370Spst elsewhere in GDB, (2) options are used, which are not generally 67519370Spst used in GDB (perhaps "set mapped on", "set readnow on" would be 67619370Spst better), (3) the order of options matters, which is contrary to GNU 67719370Spst conventions (because it is confusing and inconvenient). */ 67819370Spst 67919370Spstvoid 68019370Spstsymbol_file_command (args, from_tty) 68119370Spst char *args; 68219370Spst int from_tty; 68319370Spst{ 68419370Spst char **argv; 68519370Spst char *name = NULL; 68619370Spst CORE_ADDR text_relocation = 0; /* text_relocation */ 68719370Spst struct cleanup *cleanups; 68819370Spst int mapped = 0; 68919370Spst int readnow = 0; 69019370Spst 69119370Spst dont_repeat (); 69219370Spst 69319370Spst if (args == NULL) 69419370Spst { 69519370Spst if ((have_full_symbols () || have_partial_symbols ()) 69619370Spst && from_tty 69719370Spst && !query ("Discard symbol table from `%s'? ", 69819370Spst symfile_objfile -> name)) 69919370Spst error ("Not confirmed."); 70019370Spst free_all_objfiles (); 70119370Spst symfile_objfile = NULL; 70219370Spst if (from_tty) 70319370Spst { 70419370Spst printf_unfiltered ("No symbol file now.\n"); 70519370Spst } 70619370Spst } 70719370Spst else 70819370Spst { 70919370Spst if ((argv = buildargv (args)) == NULL) 71019370Spst { 71119370Spst nomem (0); 71219370Spst } 71319370Spst cleanups = make_cleanup (freeargv, (char *) argv); 71419370Spst while (*argv != NULL) 71519370Spst { 71619370Spst if (STREQ (*argv, "-mapped")) 71719370Spst { 71819370Spst mapped = 1; 71919370Spst } 72019370Spst else if (STREQ (*argv, "-readnow")) 72119370Spst { 72219370Spst readnow = 1; 72319370Spst } 72419370Spst else if (**argv == '-') 72519370Spst { 72619370Spst error ("unknown option `%s'", *argv); 72719370Spst } 72819370Spst else 72919370Spst { 73019370Spst char *p; 73119370Spst 73219370Spst name = *argv; 73319370Spst 73419370Spst /* this is for rombug remote only, to get the text relocation by 73519370Spst using link command */ 73619370Spst p = strrchr(name, '/'); 73719370Spst if (p != NULL) p++; 73819370Spst else p = name; 73919370Spst 74019370Spst target_link(p, &text_relocation); 74119370Spst 74219370Spst if (text_relocation == (CORE_ADDR)0) 74319370Spst return; 74419370Spst else if (text_relocation == (CORE_ADDR)-1) 74519370Spst symbol_file_add (name, from_tty, (CORE_ADDR)0, 1, mapped, 74619370Spst readnow); 74719370Spst else 74819370Spst symbol_file_add (name, from_tty, (CORE_ADDR)text_relocation, 74919370Spst 0, mapped, readnow); 75019370Spst 75119370Spst /* Getting new symbols may change our opinion about what is 75219370Spst frameless. */ 75319370Spst reinit_frame_cache (); 75419370Spst 75519370Spst set_initial_language (); 75619370Spst } 75719370Spst argv++; 75819370Spst } 75919370Spst 76019370Spst if (name == NULL) 76119370Spst { 76219370Spst error ("no symbol file name was specified"); 76319370Spst } 76419370Spst do_cleanups (cleanups); 76519370Spst } 76619370Spst} 76719370Spst 76819370Spst/* Set the initial language. 76919370Spst 77019370Spst A better solution would be to record the language in the psymtab when reading 77119370Spst partial symbols, and then use it (if known) to set the language. This would 77219370Spst be a win for formats that encode the language in an easily discoverable place, 77319370Spst such as DWARF. For stabs, we can jump through hoops looking for specially 77419370Spst named symbols or try to intuit the language from the specific type of stabs 77519370Spst we find, but we can't do that until later when we read in full symbols. 77619370Spst FIXME. */ 77719370Spst 77819370Spststatic void 77919370Spstset_initial_language () 78019370Spst{ 78119370Spst struct partial_symtab *pst; 78219370Spst enum language lang = language_unknown; 78319370Spst 78419370Spst pst = find_main_psymtab (); 78519370Spst if (pst != NULL) 78619370Spst { 78719370Spst if (pst -> filename != NULL) 78819370Spst { 78919370Spst lang = deduce_language_from_filename (pst -> filename); 79019370Spst } 79119370Spst if (lang == language_unknown) 79219370Spst { 79319370Spst /* Make C the default language */ 79419370Spst lang = language_c; 79519370Spst } 79619370Spst set_language (lang); 79719370Spst expected_language = current_language; /* Don't warn the user */ 79819370Spst } 79919370Spst} 80019370Spst 80119370Spst/* Open file specified by NAME and hand it off to BFD for preliminary 80219370Spst analysis. Result is a newly initialized bfd *, which includes a newly 80319370Spst malloc'd` copy of NAME (tilde-expanded and made absolute). 80419370Spst In case of trouble, error() is called. */ 80519370Spst 80619370Spststatic bfd * 80719370Spstsymfile_bfd_open (name) 80819370Spst char *name; 80919370Spst{ 81019370Spst bfd *sym_bfd; 81119370Spst int desc; 81219370Spst char *absolute_name; 81319370Spst 81419370Spst name = tilde_expand (name); /* Returns 1st new malloc'd copy */ 81519370Spst 81619370Spst /* Look down path for it, allocate 2nd new malloc'd copy. */ 81719370Spst desc = openp (getenv ("PATH"), 1, name, O_RDONLY | O_BINARY, 0, &absolute_name); 81819370Spst if (desc < 0) 81919370Spst { 82019370Spst make_cleanup (free, name); 82119370Spst perror_with_name (name); 82219370Spst } 82319370Spst free (name); /* Free 1st new malloc'd copy */ 82419370Spst name = absolute_name; /* Keep 2nd malloc'd copy in bfd */ 82519370Spst /* It'll be freed in free_objfile(). */ 82619370Spst 82719370Spst sym_bfd = bfd_fdopenr (name, gnutarget, desc); 82819370Spst if (!sym_bfd) 82919370Spst { 83019370Spst close (desc); 83119370Spst make_cleanup (free, name); 83219370Spst error ("\"%s\": can't open to read symbols: %s.", name, 83319370Spst bfd_errmsg (bfd_get_error ())); 83419370Spst } 83519370Spst sym_bfd->cacheable = true; 83619370Spst 83719370Spst if (!bfd_check_format (sym_bfd, bfd_object)) 83819370Spst { 83919370Spst /* FIXME: should be checking for errors from bfd_close (for one thing, 84019370Spst on error it does not free all the storage associated with the 84119370Spst bfd). */ 84219370Spst bfd_close (sym_bfd); /* This also closes desc */ 84319370Spst make_cleanup (free, name); 84419370Spst error ("\"%s\": can't read symbols: %s.", name, 84519370Spst bfd_errmsg (bfd_get_error ())); 84619370Spst } 84719370Spst 84819370Spst return (sym_bfd); 84919370Spst} 85019370Spst 85119370Spst/* Link a new symtab_fns into the global symtab_fns list. Called on gdb 85219370Spst startup by the _initialize routine in each object file format reader, 85319370Spst to register information about each format the the reader is prepared 85419370Spst to handle. */ 85519370Spst 85619370Spstvoid 85719370Spstadd_symtab_fns (sf) 85819370Spst struct sym_fns *sf; 85919370Spst{ 86019370Spst sf->next = symtab_fns; 86119370Spst symtab_fns = sf; 86219370Spst} 86319370Spst 86419370Spst 86519370Spst/* Initialize to read symbols from the symbol file sym_bfd. It either 86619370Spst returns or calls error(). The result is an initialized struct sym_fns 86719370Spst in the objfile structure, that contains cached information about the 86819370Spst symbol file. */ 86919370Spst 87019370Spststatic void 87119370Spstfind_sym_fns (objfile) 87219370Spst struct objfile *objfile; 87319370Spst{ 87419370Spst struct sym_fns *sf; 87519370Spst enum bfd_flavour our_flavour = bfd_get_flavour (objfile -> obfd); 87619370Spst char *our_target = bfd_get_target (objfile -> obfd); 87719370Spst 87819370Spst /* Special kludge for RS/6000 and PowerMac. See xcoffread.c. */ 87919370Spst if (STREQ (our_target, "aixcoff-rs6000") || 88019370Spst STREQ (our_target, "xcoff-powermac")) 88119370Spst our_flavour = (enum bfd_flavour)-1; 88219370Spst 88319370Spst /* Special kludge for apollo. See dstread.c. */ 88419370Spst if (STREQN (our_target, "apollo", 6)) 88519370Spst our_flavour = (enum bfd_flavour)-2; 88619370Spst 88719370Spst for (sf = symtab_fns; sf != NULL; sf = sf -> next) 88819370Spst { 88919370Spst if (our_flavour == sf -> sym_flavour) 89019370Spst { 89119370Spst objfile -> sf = sf; 89219370Spst return; 89319370Spst } 89419370Spst } 89519370Spst error ("I'm sorry, Dave, I can't do that. Symbol format `%s' unknown.", 89619370Spst bfd_get_target (objfile -> obfd)); 89719370Spst} 89819370Spst 89919370Spst/* This function runs the load command of our current target. */ 90019370Spst 90119370Spststatic void 90219370Spstload_command (arg, from_tty) 90319370Spst char *arg; 90419370Spst int from_tty; 90519370Spst{ 90619370Spst if (arg == NULL) 90719370Spst arg = get_exec_file (1); 90819370Spst target_load (arg, from_tty); 90919370Spst} 91019370Spst 91119370Spst/* This version of "load" should be usable for any target. Currently 91219370Spst it is just used for remote targets, not inftarg.c or core files, 91319370Spst on the theory that only in that case is it useful. 91419370Spst 91519370Spst Avoiding xmodem and the like seems like a win (a) because we don't have 91619370Spst to worry about finding it, and (b) On VMS, fork() is very slow and so 91719370Spst we don't want to run a subprocess. On the other hand, I'm not sure how 91819370Spst performance compares. */ 91919370Spstvoid 92019370Spstgeneric_load (filename, from_tty) 92119370Spst char *filename; 92219370Spst int from_tty; 92319370Spst{ 92419370Spst struct cleanup *old_cleanups; 92519370Spst asection *s; 92619370Spst bfd *loadfile_bfd; 92719370Spst time_t start_time, end_time; /* Start and end times of download */ 92819370Spst unsigned long data_count; /* Number of bytes transferred to memory */ 92919370Spst 93019370Spst loadfile_bfd = bfd_openr (filename, gnutarget); 93119370Spst if (loadfile_bfd == NULL) 93219370Spst { 93319370Spst perror_with_name (filename); 93419370Spst return; 93519370Spst } 93619370Spst /* FIXME: should be checking for errors from bfd_close (for one thing, 93719370Spst on error it does not free all the storage associated with the 93819370Spst bfd). */ 93919370Spst old_cleanups = make_cleanup (bfd_close, loadfile_bfd); 94019370Spst 94119370Spst if (!bfd_check_format (loadfile_bfd, bfd_object)) 94219370Spst { 94319370Spst error ("\"%s\" is not an object file: %s", filename, 94419370Spst bfd_errmsg (bfd_get_error ())); 94519370Spst } 94619370Spst 94719370Spst start_time = time (NULL); 94819370Spst 94919370Spst for (s = loadfile_bfd->sections; s; s = s->next) 95019370Spst { 95119370Spst if (s->flags & SEC_LOAD) 95219370Spst { 95319370Spst bfd_size_type size; 95419370Spst 95519370Spst size = bfd_get_section_size_before_reloc (s); 95619370Spst if (size > 0) 95719370Spst { 95819370Spst char *buffer; 95919370Spst struct cleanup *old_chain; 96019370Spst bfd_vma vma; 96119370Spst 96219370Spst data_count += size; 96319370Spst 96419370Spst buffer = xmalloc (size); 96519370Spst old_chain = make_cleanup (free, buffer); 96619370Spst 96719370Spst vma = bfd_get_section_vma (loadfile_bfd, s); 96819370Spst 96919370Spst /* Is this really necessary? I guess it gives the user something 97019370Spst to look at during a long download. */ 97119370Spst printf_filtered ("Loading section %s, size 0x%lx vma ", 97219370Spst bfd_get_section_name (loadfile_bfd, s), 97319370Spst (unsigned long) size); 97419370Spst print_address_numeric (vma, 1, gdb_stdout); 97519370Spst printf_filtered ("\n"); 97619370Spst 97719370Spst bfd_get_section_contents (loadfile_bfd, s, buffer, 0, size); 97819370Spst 97919370Spst target_write_memory (vma, buffer, size); 98019370Spst 98119370Spst do_cleanups (old_chain); 98219370Spst } 98319370Spst } 98419370Spst } 98519370Spst 98619370Spst end_time = time (NULL); 98719370Spst 98819370Spst /* We were doing this in remote-mips.c, I suspect it is right 98919370Spst for other targets too. */ 99019370Spst write_pc (loadfile_bfd->start_address); 99119370Spst 99219370Spst /* FIXME: are we supposed to call symbol_file_add or not? According to 99319370Spst a comment from remote-mips.c (where a call to symbol_file_add was 99419370Spst commented out), making the call confuses GDB if more than one file is 99519370Spst loaded in. remote-nindy.c had no call to symbol_file_add, but remote-vx.c 99619370Spst does. */ 99719370Spst 99819370Spst if (end_time != start_time) 99919370Spst printf_filtered ("Transfer rate: %d bits/sec.\n", 100019370Spst (data_count * 8)/(end_time - start_time)); 100119370Spst 100219370Spst do_cleanups (old_cleanups); 100319370Spst} 100419370Spst 100519370Spst/* This function allows the addition of incrementally linked object files. 100619370Spst It does not modify any state in the target, only in the debugger. */ 100719370Spst 100819370Spst/* ARGSUSED */ 100919370Spststatic void 101019370Spstadd_symbol_file_command (args, from_tty) 101119370Spst char *args; 101219370Spst int from_tty; 101319370Spst{ 101419370Spst char *name = NULL; 101519370Spst CORE_ADDR text_addr; 101619370Spst char *arg; 101719370Spst int readnow = 0; 101819370Spst int mapped = 0; 101919370Spst 102019370Spst dont_repeat (); 102119370Spst 102219370Spst if (args == NULL) 102319370Spst { 102419370Spst error ("add-symbol-file takes a file name and an address"); 102519370Spst } 102619370Spst 102719370Spst /* Make a copy of the string that we can safely write into. */ 102819370Spst 102919370Spst args = strdup (args); 103019370Spst make_cleanup (free, args); 103119370Spst 103219370Spst /* Pick off any -option args and the file name. */ 103319370Spst 103419370Spst while ((*args != '\000') && (name == NULL)) 103519370Spst { 103619370Spst while (isspace (*args)) {args++;} 103719370Spst arg = args; 103819370Spst while ((*args != '\000') && !isspace (*args)) {args++;} 103919370Spst if (*args != '\000') 104019370Spst { 104119370Spst *args++ = '\000'; 104219370Spst } 104319370Spst if (*arg != '-') 104419370Spst { 104519370Spst name = arg; 104619370Spst } 104719370Spst else if (STREQ (arg, "-mapped")) 104819370Spst { 104919370Spst mapped = 1; 105019370Spst } 105119370Spst else if (STREQ (arg, "-readnow")) 105219370Spst { 105319370Spst readnow = 1; 105419370Spst } 105519370Spst else 105619370Spst { 105719370Spst error ("unknown option `%s'", arg); 105819370Spst } 105919370Spst } 106019370Spst 106119370Spst /* After picking off any options and the file name, args should be 106219370Spst left pointing at the remainder of the command line, which should 106319370Spst be the address expression to evaluate. */ 106419370Spst 106519370Spst if (name == NULL) 106619370Spst { 106719370Spst error ("add-symbol-file takes a file name"); 106819370Spst } 106919370Spst name = tilde_expand (name); 107019370Spst make_cleanup (free, name); 107119370Spst 107219370Spst if (*args != '\000') 107319370Spst { 107419370Spst text_addr = parse_and_eval_address (args); 107519370Spst } 107619370Spst else 107719370Spst { 107819370Spst target_link(name, &text_addr); 107919370Spst if (text_addr == (CORE_ADDR)-1) 108019370Spst error("Don't know how to get text start location for this file"); 108119370Spst } 108219370Spst 108319370Spst /* FIXME-32x64: Assumes text_addr fits in a long. */ 108419370Spst if (!query ("add symbol table from file \"%s\" at text_addr = %s?\n", 108519370Spst name, local_hex_string ((unsigned long)text_addr))) 108619370Spst error ("Not confirmed."); 108719370Spst 108819370Spst symbol_file_add (name, 0, text_addr, 0, mapped, readnow); 108919370Spst 109019370Spst /* Getting new symbols may change our opinion about what is 109119370Spst frameless. */ 109219370Spst reinit_frame_cache (); 109319370Spst} 109419370Spst 109519370Spststatic void 109619370Spstadd_shared_symbol_files_command (args, from_tty) 109719370Spst char *args; 109819370Spst int from_tty; 109919370Spst{ 110019370Spst#ifdef ADD_SHARED_SYMBOL_FILES 110119370Spst ADD_SHARED_SYMBOL_FILES (args, from_tty); 110219370Spst#else 110319370Spst error ("This command is not available in this configuration of GDB."); 110419370Spst#endif 110519370Spst} 110619370Spst 110719370Spst/* Re-read symbols if a symbol-file has changed. */ 110819370Spstvoid 110919370Spstreread_symbols () 111019370Spst{ 111119370Spst struct objfile *objfile; 111219370Spst long new_modtime; 111319370Spst int reread_one = 0; 111419370Spst struct stat new_statbuf; 111519370Spst int res; 111619370Spst 111719370Spst /* With the addition of shared libraries, this should be modified, 111819370Spst the load time should be saved in the partial symbol tables, since 111919370Spst different tables may come from different source files. FIXME. 112019370Spst This routine should then walk down each partial symbol table 112119370Spst and see if the symbol table that it originates from has been changed */ 112219370Spst 112319370Spst for (objfile = object_files; objfile; objfile = objfile->next) { 112419370Spst if (objfile->obfd) { 112519370Spst#ifdef IBM6000_TARGET 112619370Spst /* If this object is from a shared library, then you should 112719370Spst stat on the library name, not member name. */ 112819370Spst 112919370Spst if (objfile->obfd->my_archive) 113019370Spst res = stat (objfile->obfd->my_archive->filename, &new_statbuf); 113119370Spst else 113219370Spst#endif 113319370Spst res = stat (objfile->name, &new_statbuf); 113419370Spst if (res != 0) { 113519370Spst /* FIXME, should use print_sys_errmsg but it's not filtered. */ 113619370Spst printf_filtered ("`%s' has disappeared; keeping its symbols.\n", 113719370Spst objfile->name); 113819370Spst continue; 113919370Spst } 114019370Spst new_modtime = new_statbuf.st_mtime; 114119370Spst if (new_modtime != objfile->mtime) 114219370Spst { 114319370Spst struct cleanup *old_cleanups; 114419370Spst struct section_offsets *offsets; 114519370Spst int num_offsets; 114619370Spst int section_offsets_size; 114719370Spst char *obfd_filename; 114819370Spst 114919370Spst printf_filtered ("`%s' has changed; re-reading symbols.\n", 115019370Spst objfile->name); 115119370Spst 115219370Spst /* There are various functions like symbol_file_add, 115319370Spst symfile_bfd_open, syms_from_objfile, etc., which might 115419370Spst appear to do what we want. But they have various other 115519370Spst effects which we *don't* want. So we just do stuff 115619370Spst ourselves. We don't worry about mapped files (for one thing, 115719370Spst any mapped file will be out of date). */ 115819370Spst 115919370Spst /* If we get an error, blow away this objfile (not sure if 116019370Spst that is the correct response for things like shared 116119370Spst libraries). */ 116219370Spst old_cleanups = make_cleanup (free_objfile, objfile); 116319370Spst /* We need to do this whenever any symbols go away. */ 116419370Spst make_cleanup (clear_symtab_users, 0); 116519370Spst 116619370Spst /* Clean up any state BFD has sitting around. We don't need 116719370Spst to close the descriptor but BFD lacks a way of closing the 116819370Spst BFD without closing the descriptor. */ 116919370Spst obfd_filename = bfd_get_filename (objfile->obfd); 117019370Spst if (!bfd_close (objfile->obfd)) 117119370Spst error ("Can't close BFD for %s: %s", objfile->name, 117219370Spst bfd_errmsg (bfd_get_error ())); 117319370Spst objfile->obfd = bfd_openr (obfd_filename, gnutarget); 117419370Spst if (objfile->obfd == NULL) 117519370Spst error ("Can't open %s to read symbols.", objfile->name); 117619370Spst /* bfd_openr sets cacheable to true, which is what we want. */ 117719370Spst if (!bfd_check_format (objfile->obfd, bfd_object)) 117819370Spst error ("Can't read symbols from %s: %s.", objfile->name, 117919370Spst bfd_errmsg (bfd_get_error ())); 118019370Spst 118119370Spst /* Save the offsets, we will nuke them with the rest of the 118219370Spst psymbol_obstack. */ 118319370Spst num_offsets = objfile->num_sections; 118419370Spst section_offsets_size = 118519370Spst sizeof (struct section_offsets) 118619370Spst + sizeof (objfile->section_offsets->offsets) * num_offsets; 118719370Spst offsets = (struct section_offsets *) alloca (section_offsets_size); 118819370Spst memcpy (offsets, objfile->section_offsets, section_offsets_size); 118919370Spst 119019370Spst /* Nuke all the state that we will re-read. Much of the following 119119370Spst code which sets things to NULL really is necessary to tell 119219370Spst other parts of GDB that there is nothing currently there. */ 119319370Spst 119419370Spst /* FIXME: Do we have to free a whole linked list, or is this 119519370Spst enough? */ 119619370Spst if (objfile->global_psymbols.list) 119719370Spst mfree (objfile->md, objfile->global_psymbols.list); 119819370Spst memset (&objfile -> global_psymbols, 0, 119919370Spst sizeof (objfile -> global_psymbols)); 120019370Spst if (objfile->static_psymbols.list) 120119370Spst mfree (objfile->md, objfile->static_psymbols.list); 120219370Spst memset (&objfile -> static_psymbols, 0, 120319370Spst sizeof (objfile -> static_psymbols)); 120419370Spst 120519370Spst /* Free the obstacks for non-reusable objfiles */ 120619370Spst obstack_free (&objfile -> psymbol_cache.cache, 0); 120719370Spst memset (&objfile -> psymbol_cache, 0, 120819370Spst sizeof (objfile -> psymbol_cache)); 120919370Spst obstack_free (&objfile -> psymbol_obstack, 0); 121019370Spst obstack_free (&objfile -> symbol_obstack, 0); 121119370Spst obstack_free (&objfile -> type_obstack, 0); 121219370Spst objfile->sections = NULL; 121319370Spst objfile->symtabs = NULL; 121419370Spst objfile->psymtabs = NULL; 121519370Spst objfile->free_psymtabs = NULL; 121619370Spst objfile->msymbols = NULL; 121719370Spst objfile->minimal_symbol_count= 0; 121819370Spst objfile->fundamental_types = NULL; 121919370Spst if (objfile -> sf != NULL) 122019370Spst { 122119370Spst (*objfile -> sf -> sym_finish) (objfile); 122219370Spst } 122319370Spst 122419370Spst /* We never make this a mapped file. */ 122519370Spst objfile -> md = NULL; 122619370Spst /* obstack_specify_allocation also initializes the obstack so 122719370Spst it is empty. */ 122819370Spst obstack_specify_allocation (&objfile -> psymbol_cache.cache, 0, 0, 122919370Spst xmalloc, free); 123019370Spst obstack_specify_allocation (&objfile -> psymbol_obstack, 0, 0, 123119370Spst xmalloc, free); 123219370Spst obstack_specify_allocation (&objfile -> symbol_obstack, 0, 0, 123319370Spst xmalloc, free); 123419370Spst obstack_specify_allocation (&objfile -> type_obstack, 0, 0, 123519370Spst xmalloc, free); 123619370Spst if (build_objfile_section_table (objfile)) 123719370Spst { 123819370Spst error ("Can't find the file sections in `%s': %s", 123919370Spst objfile -> name, bfd_errmsg (bfd_get_error ())); 124019370Spst } 124119370Spst 124219370Spst /* We use the same section offsets as from last time. I'm not 124319370Spst sure whether that is always correct for shared libraries. */ 124419370Spst objfile->section_offsets = (struct section_offsets *) 124519370Spst obstack_alloc (&objfile -> psymbol_obstack, section_offsets_size); 124619370Spst memcpy (objfile->section_offsets, offsets, section_offsets_size); 124719370Spst objfile->num_sections = num_offsets; 124819370Spst 124919370Spst /* What the hell is sym_new_init for, anyway? The concept of 125019370Spst distinguishing between the main file and additional files 125119370Spst in this way seems rather dubious. */ 125219370Spst if (objfile == symfile_objfile) 125319370Spst (*objfile->sf->sym_new_init) (objfile); 125419370Spst 125519370Spst (*objfile->sf->sym_init) (objfile); 125619370Spst clear_complaints (1, 1); 125719370Spst /* The "mainline" parameter is a hideous hack; I think leaving it 125819370Spst zero is OK since dbxread.c also does what it needs to do if 125919370Spst objfile->global_psymbols.size is 0. */ 126019370Spst (*objfile->sf->sym_read) (objfile, objfile->section_offsets, 0); 126119370Spst if (!have_partial_symbols () && !have_full_symbols ()) 126219370Spst { 126319370Spst wrap_here (""); 126419370Spst printf_filtered ("(no debugging symbols found)\n"); 126519370Spst wrap_here (""); 126619370Spst } 126719370Spst objfile -> flags |= OBJF_SYMS; 126819370Spst 126919370Spst /* We're done reading the symbol file; finish off complaints. */ 127019370Spst clear_complaints (0, 1); 127119370Spst 127219370Spst /* Getting new symbols may change our opinion about what is 127319370Spst frameless. */ 127419370Spst 127519370Spst reinit_frame_cache (); 127619370Spst 127719370Spst /* Discard cleanups as symbol reading was successful. */ 127819370Spst discard_cleanups (old_cleanups); 127919370Spst 128019370Spst /* If the mtime has changed between the time we set new_modtime 128119370Spst and now, we *want* this to be out of date, so don't call stat 128219370Spst again now. */ 128319370Spst objfile->mtime = new_modtime; 128419370Spst reread_one = 1; 128519370Spst 128619370Spst /* Call this after reading in a new symbol table to give target 128719370Spst dependant code a crack at the new symbols. For instance, this 128819370Spst could be used to update the values of target-specific symbols GDB 128919370Spst needs to keep track of (such as _sigtramp, or whatever). */ 129019370Spst 129119370Spst TARGET_SYMFILE_POSTREAD (objfile); 129219370Spst } 129319370Spst } 129419370Spst } 129519370Spst 129619370Spst if (reread_one) 129719370Spst clear_symtab_users (); 129819370Spst} 129919370Spst 130019370Spst 130119370Spstenum language 130219370Spstdeduce_language_from_filename (filename) 130319370Spst char *filename; 130419370Spst{ 130519370Spst char *c; 130619370Spst 130719370Spst if (0 == filename) 130819370Spst ; /* Get default */ 130919370Spst else if (0 == (c = strrchr (filename, '.'))) 131019370Spst ; /* Get default. */ 131119370Spst else if (STREQ (c, ".c")) 131219370Spst return language_c; 131319370Spst else if (STREQ (c, ".cc") || STREQ (c, ".C") || STREQ (c, ".cxx") 131419370Spst || STREQ (c, ".cpp") || STREQ (c, ".cp") || STREQ (c, ".c++")) 131519370Spst return language_cplus; 131619370Spst else if (STREQ (c, ".ch") || STREQ (c, ".c186") || STREQ (c, ".c286")) 131719370Spst return language_chill; 131819370Spst else if (STREQ (c, ".f") || STREQ (c, ".F")) 131919370Spst return language_fortran; 132019370Spst else if (STREQ (c, ".mod")) 132119370Spst return language_m2; 132219370Spst else if (STREQ (c, ".s") || STREQ (c, ".S")) 132319370Spst return language_asm; 132419370Spst 132519370Spst return language_unknown; /* default */ 132619370Spst} 132719370Spst 132819370Spst/* allocate_symtab: 132919370Spst 133019370Spst Allocate and partly initialize a new symbol table. Return a pointer 133119370Spst to it. error() if no space. 133219370Spst 133319370Spst Caller must set these fields: 133419370Spst LINETABLE(symtab) 133519370Spst symtab->blockvector 133619370Spst symtab->dirname 133719370Spst symtab->free_code 133819370Spst symtab->free_ptr 133919370Spst initialize any EXTRA_SYMTAB_INFO 134019370Spst possibly free_named_symtabs (symtab->filename); 134119370Spst */ 134219370Spst 134319370Spststruct symtab * 134419370Spstallocate_symtab (filename, objfile) 134519370Spst char *filename; 134619370Spst struct objfile *objfile; 134719370Spst{ 134819370Spst register struct symtab *symtab; 134919370Spst 135019370Spst symtab = (struct symtab *) 135119370Spst obstack_alloc (&objfile -> symbol_obstack, sizeof (struct symtab)); 135219370Spst memset (symtab, 0, sizeof (*symtab)); 135319370Spst symtab -> filename = obsavestring (filename, strlen (filename), 135419370Spst &objfile -> symbol_obstack); 135519370Spst symtab -> fullname = NULL; 135619370Spst symtab -> language = deduce_language_from_filename (filename); 135719370Spst 135819370Spst /* Hook it to the objfile it comes from */ 135919370Spst 136019370Spst symtab -> objfile = objfile; 136119370Spst symtab -> next = objfile -> symtabs; 136219370Spst objfile -> symtabs = symtab; 136319370Spst 136419370Spst#ifdef INIT_EXTRA_SYMTAB_INFO 136519370Spst INIT_EXTRA_SYMTAB_INFO (symtab); 136619370Spst#endif 136719370Spst 136819370Spst return (symtab); 136919370Spst} 137019370Spst 137119370Spststruct partial_symtab * 137219370Spstallocate_psymtab (filename, objfile) 137319370Spst char *filename; 137419370Spst struct objfile *objfile; 137519370Spst{ 137619370Spst struct partial_symtab *psymtab; 137719370Spst 137819370Spst if (objfile -> free_psymtabs) 137919370Spst { 138019370Spst psymtab = objfile -> free_psymtabs; 138119370Spst objfile -> free_psymtabs = psymtab -> next; 138219370Spst } 138319370Spst else 138419370Spst psymtab = (struct partial_symtab *) 138519370Spst obstack_alloc (&objfile -> psymbol_obstack, 138619370Spst sizeof (struct partial_symtab)); 138719370Spst 138819370Spst memset (psymtab, 0, sizeof (struct partial_symtab)); 138919370Spst psymtab -> filename = obsavestring (filename, strlen (filename), 139019370Spst &objfile -> psymbol_obstack); 139119370Spst psymtab -> symtab = NULL; 139219370Spst 139319370Spst /* Hook it to the objfile it comes from */ 139419370Spst 139519370Spst psymtab -> objfile = objfile; 139619370Spst psymtab -> next = objfile -> psymtabs; 139719370Spst objfile -> psymtabs = psymtab; 139819370Spst 139919370Spst return (psymtab); 140019370Spst} 140119370Spst 140219370Spst 140319370Spst/* Reset all data structures in gdb which may contain references to symbol 140419370Spst table date. */ 140519370Spst 140619370Spstvoid 140719370Spstclear_symtab_users () 140819370Spst{ 140919370Spst /* Someday, we should do better than this, by only blowing away 141019370Spst the things that really need to be blown. */ 141119370Spst clear_value_history (); 141219370Spst clear_displays (); 141319370Spst clear_internalvars (); 141419370Spst breakpoint_re_set (); 141519370Spst set_default_breakpoint (0, 0, 0, 0); 141619370Spst current_source_symtab = 0; 141719370Spst current_source_line = 0; 141819370Spst clear_pc_function_cache (); 141919370Spst} 142019370Spst 142119370Spst/* clear_symtab_users_once: 142219370Spst 142319370Spst This function is run after symbol reading, or from a cleanup. 142419370Spst If an old symbol table was obsoleted, the old symbol table 142519370Spst has been blown away, but the other GDB data structures that may 142619370Spst reference it have not yet been cleared or re-directed. (The old 142719370Spst symtab was zapped, and the cleanup queued, in free_named_symtab() 142819370Spst below.) 142919370Spst 143019370Spst This function can be queued N times as a cleanup, or called 143119370Spst directly; it will do all the work the first time, and then will be a 143219370Spst no-op until the next time it is queued. This works by bumping a 143319370Spst counter at queueing time. Much later when the cleanup is run, or at 143419370Spst the end of symbol processing (in case the cleanup is discarded), if 143519370Spst the queued count is greater than the "done-count", we do the work 143619370Spst and set the done-count to the queued count. If the queued count is 143719370Spst less than or equal to the done-count, we just ignore the call. This 143819370Spst is needed because reading a single .o file will often replace many 143919370Spst symtabs (one per .h file, for example), and we don't want to reset 144019370Spst the breakpoints N times in the user's face. 144119370Spst 144219370Spst The reason we both queue a cleanup, and call it directly after symbol 144319370Spst reading, is because the cleanup protects us in case of errors, but is 144419370Spst discarded if symbol reading is successful. */ 144519370Spst 144619370Spst#if 0 144719370Spst/* FIXME: As free_named_symtabs is currently a big noop this function 144819370Spst is no longer needed. */ 144919370Spststatic void 145019370Spstclear_symtab_users_once PARAMS ((void)); 145119370Spst 145219370Spststatic int clear_symtab_users_queued; 145319370Spststatic int clear_symtab_users_done; 145419370Spst 145519370Spststatic void 145619370Spstclear_symtab_users_once () 145719370Spst{ 145819370Spst /* Enforce once-per-`do_cleanups'-semantics */ 145919370Spst if (clear_symtab_users_queued <= clear_symtab_users_done) 146019370Spst return; 146119370Spst clear_symtab_users_done = clear_symtab_users_queued; 146219370Spst 146319370Spst clear_symtab_users (); 146419370Spst} 146519370Spst#endif 146619370Spst 146719370Spst/* Delete the specified psymtab, and any others that reference it. */ 146819370Spst 146919370Spststatic void 147019370Spstcashier_psymtab (pst) 147119370Spst struct partial_symtab *pst; 147219370Spst{ 147319370Spst struct partial_symtab *ps, *pprev = NULL; 147419370Spst int i; 147519370Spst 147619370Spst /* Find its previous psymtab in the chain */ 147719370Spst for (ps = pst->objfile->psymtabs; ps; ps = ps->next) { 147819370Spst if (ps == pst) 147919370Spst break; 148019370Spst pprev = ps; 148119370Spst } 148219370Spst 148319370Spst if (ps) { 148419370Spst /* Unhook it from the chain. */ 148519370Spst if (ps == pst->objfile->psymtabs) 148619370Spst pst->objfile->psymtabs = ps->next; 148719370Spst else 148819370Spst pprev->next = ps->next; 148919370Spst 149019370Spst /* FIXME, we can't conveniently deallocate the entries in the 149119370Spst partial_symbol lists (global_psymbols/static_psymbols) that 149219370Spst this psymtab points to. These just take up space until all 149319370Spst the psymtabs are reclaimed. Ditto the dependencies list and 149419370Spst filename, which are all in the psymbol_obstack. */ 149519370Spst 149619370Spst /* We need to cashier any psymtab that has this one as a dependency... */ 149719370Spstagain: 149819370Spst for (ps = pst->objfile->psymtabs; ps; ps = ps->next) { 149919370Spst for (i = 0; i < ps->number_of_dependencies; i++) { 150019370Spst if (ps->dependencies[i] == pst) { 150119370Spst cashier_psymtab (ps); 150219370Spst goto again; /* Must restart, chain has been munged. */ 150319370Spst } 150419370Spst } 150519370Spst } 150619370Spst } 150719370Spst} 150819370Spst 150919370Spst/* If a symtab or psymtab for filename NAME is found, free it along 151019370Spst with any dependent breakpoints, displays, etc. 151119370Spst Used when loading new versions of object modules with the "add-file" 151219370Spst command. This is only called on the top-level symtab or psymtab's name; 151319370Spst it is not called for subsidiary files such as .h files. 151419370Spst 151519370Spst Return value is 1 if we blew away the environment, 0 if not. 151619370Spst FIXME. The return valu appears to never be used. 151719370Spst 151819370Spst FIXME. I think this is not the best way to do this. We should 151919370Spst work on being gentler to the environment while still cleaning up 152019370Spst all stray pointers into the freed symtab. */ 152119370Spst 152219370Spstint 152319370Spstfree_named_symtabs (name) 152419370Spst char *name; 152519370Spst{ 152619370Spst#if 0 152719370Spst /* FIXME: With the new method of each objfile having it's own 152819370Spst psymtab list, this function needs serious rethinking. In particular, 152919370Spst why was it ever necessary to toss psymtabs with specific compilation 153019370Spst unit filenames, as opposed to all psymtabs from a particular symbol 153119370Spst file? -- fnf 153219370Spst Well, the answer is that some systems permit reloading of particular 153319370Spst compilation units. We want to blow away any old info about these 153419370Spst compilation units, regardless of which objfiles they arrived in. --gnu. */ 153519370Spst 153619370Spst register struct symtab *s; 153719370Spst register struct symtab *prev; 153819370Spst register struct partial_symtab *ps; 153919370Spst struct blockvector *bv; 154019370Spst int blewit = 0; 154119370Spst 154219370Spst /* We only wack things if the symbol-reload switch is set. */ 154319370Spst if (!symbol_reloading) 154419370Spst return 0; 154519370Spst 154619370Spst /* Some symbol formats have trouble providing file names... */ 154719370Spst if (name == 0 || *name == '\0') 154819370Spst return 0; 154919370Spst 155019370Spst /* Look for a psymtab with the specified name. */ 155119370Spst 155219370Spstagain2: 155319370Spst for (ps = partial_symtab_list; ps; ps = ps->next) { 155419370Spst if (STREQ (name, ps->filename)) { 155519370Spst cashier_psymtab (ps); /* Blow it away...and its little dog, too. */ 155619370Spst goto again2; /* Must restart, chain has been munged */ 155719370Spst } 155819370Spst } 155919370Spst 156019370Spst /* Look for a symtab with the specified name. */ 156119370Spst 156219370Spst for (s = symtab_list; s; s = s->next) 156319370Spst { 156419370Spst if (STREQ (name, s->filename)) 156519370Spst break; 156619370Spst prev = s; 156719370Spst } 156819370Spst 156919370Spst if (s) 157019370Spst { 157119370Spst if (s == symtab_list) 157219370Spst symtab_list = s->next; 157319370Spst else 157419370Spst prev->next = s->next; 157519370Spst 157619370Spst /* For now, queue a delete for all breakpoints, displays, etc., whether 157719370Spst or not they depend on the symtab being freed. This should be 157819370Spst changed so that only those data structures affected are deleted. */ 157919370Spst 158019370Spst /* But don't delete anything if the symtab is empty. 158119370Spst This test is necessary due to a bug in "dbxread.c" that 158219370Spst causes empty symtabs to be created for N_SO symbols that 158319370Spst contain the pathname of the object file. (This problem 158419370Spst has been fixed in GDB 3.9x). */ 158519370Spst 158619370Spst bv = BLOCKVECTOR (s); 158719370Spst if (BLOCKVECTOR_NBLOCKS (bv) > 2 158819370Spst || BLOCK_NSYMS (BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK)) 158919370Spst || BLOCK_NSYMS (BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK))) 159019370Spst { 159119370Spst complain (&oldsyms_complaint, name); 159219370Spst 159319370Spst clear_symtab_users_queued++; 159419370Spst make_cleanup (clear_symtab_users_once, 0); 159519370Spst blewit = 1; 159619370Spst } else { 159719370Spst complain (&empty_symtab_complaint, name); 159819370Spst } 159919370Spst 160019370Spst free_symtab (s); 160119370Spst } 160219370Spst else 160319370Spst { 160419370Spst /* It is still possible that some breakpoints will be affected 160519370Spst even though no symtab was found, since the file might have 160619370Spst been compiled without debugging, and hence not be associated 160719370Spst with a symtab. In order to handle this correctly, we would need 160819370Spst to keep a list of text address ranges for undebuggable files. 160919370Spst For now, we do nothing, since this is a fairly obscure case. */ 161019370Spst ; 161119370Spst } 161219370Spst 161319370Spst /* FIXME, what about the minimal symbol table? */ 161419370Spst return blewit; 161519370Spst#else 161619370Spst return (0); 161719370Spst#endif 161819370Spst} 161919370Spst 162019370Spst/* Allocate and partially fill a partial symtab. It will be 162119370Spst completely filled at the end of the symbol list. 162219370Spst 162319370Spst SYMFILE_NAME is the name of the symbol-file we are reading from, and ADDR 162419370Spst is the address relative to which its symbols are (incremental) or 0 162519370Spst (normal). */ 162619370Spst 162719370Spst 162819370Spststruct partial_symtab * 162919370Spststart_psymtab_common (objfile, section_offsets, 163019370Spst filename, textlow, global_syms, static_syms) 163119370Spst struct objfile *objfile; 163219370Spst struct section_offsets *section_offsets; 163319370Spst char *filename; 163419370Spst CORE_ADDR textlow; 163519370Spst struct partial_symbol **global_syms; 163619370Spst struct partial_symbol **static_syms; 163719370Spst{ 163819370Spst struct partial_symtab *psymtab; 163919370Spst 164019370Spst psymtab = allocate_psymtab (filename, objfile); 164119370Spst psymtab -> section_offsets = section_offsets; 164219370Spst psymtab -> textlow = textlow; 164319370Spst psymtab -> texthigh = psymtab -> textlow; /* default */ 164419370Spst psymtab -> globals_offset = global_syms - objfile -> global_psymbols.list; 164519370Spst psymtab -> statics_offset = static_syms - objfile -> static_psymbols.list; 164619370Spst return (psymtab); 164719370Spst} 164819370Spst 164919370Spst/* Add a symbol with a long value to a psymtab. 165019370Spst Since one arg is a struct, we pass in a ptr and deref it (sigh). */ 165119370Spst 165219370Spstvoid 165319370Spstadd_psymbol_to_list (name, namelength, namespace, class, list, val, coreaddr, 165419370Spst language, objfile) 165519370Spst char *name; 165619370Spst int namelength; 165719370Spst namespace_enum namespace; 165819370Spst enum address_class class; 165919370Spst struct psymbol_allocation_list *list; 166019370Spst long val; /* Value as a long */ 166119370Spst CORE_ADDR coreaddr; /* Value as a CORE_ADDR */ 166219370Spst enum language language; 166319370Spst struct objfile *objfile; 166419370Spst{ 166519370Spst register struct partial_symbol *psym; 166619370Spst char *buf = alloca (namelength + 1); 166719370Spst /* psymbol is static so that there will be no uninitialized gaps in the 166819370Spst structure which might contain random data, causing cache misses in 166919370Spst bcache. */ 167019370Spst static struct partial_symbol psymbol; 167119370Spst 167219370Spst /* Create local copy of the partial symbol */ 167319370Spst memcpy (buf, name, namelength); 167419370Spst buf[namelength] = '\0'; 167519370Spst SYMBOL_NAME (&psymbol) = bcache (buf, namelength + 1, &objfile->psymbol_cache); 167619370Spst /* val and coreaddr are mutually exclusive, one of them *will* be zero */ 167719370Spst if (val != 0) 167819370Spst { 167919370Spst SYMBOL_VALUE (&psymbol) = val; 168019370Spst } 168119370Spst else 168219370Spst { 168319370Spst SYMBOL_VALUE_ADDRESS (&psymbol) = coreaddr; 168419370Spst } 168519370Spst SYMBOL_SECTION (&psymbol) = 0; 168619370Spst SYMBOL_LANGUAGE (&psymbol) = language; 168719370Spst PSYMBOL_NAMESPACE (&psymbol) = namespace; 168819370Spst PSYMBOL_CLASS (&psymbol) = class; 168919370Spst SYMBOL_INIT_LANGUAGE_SPECIFIC (&psymbol, language); 169019370Spst 169119370Spst /* Stash the partial symbol away in the cache */ 169219370Spst psym = bcache (&psymbol, sizeof (struct partial_symbol), &objfile->psymbol_cache); 169319370Spst 169419370Spst /* Save pointer to partial symbol in psymtab, growing symtab if needed. */ 169519370Spst if (list->next >= list->list + list->size) 169619370Spst { 169719370Spst extend_psymbol_list (list, objfile); 169819370Spst } 169919370Spst *list->next++ = psym; 170019370Spst OBJSTAT (objfile, n_psyms++); 170119370Spst} 170219370Spst 170319370Spst/* Initialize storage for partial symbols. */ 170419370Spst 170519370Spstvoid 170619370Spstinit_psymbol_list (objfile, total_symbols) 170719370Spst struct objfile *objfile; 170819370Spst int total_symbols; 170919370Spst{ 171019370Spst /* Free any previously allocated psymbol lists. */ 171119370Spst 171219370Spst if (objfile -> global_psymbols.list) 171319370Spst { 171419370Spst mfree (objfile -> md, (PTR)objfile -> global_psymbols.list); 171519370Spst } 171619370Spst if (objfile -> static_psymbols.list) 171719370Spst { 171819370Spst mfree (objfile -> md, (PTR)objfile -> static_psymbols.list); 171919370Spst } 172019370Spst 172119370Spst /* Current best guess is that approximately a twentieth 172219370Spst of the total symbols (in a debugging file) are global or static 172319370Spst oriented symbols */ 172419370Spst 172519370Spst objfile -> global_psymbols.size = total_symbols / 10; 172619370Spst objfile -> static_psymbols.size = total_symbols / 10; 172719370Spst objfile -> global_psymbols.next = 172819370Spst objfile -> global_psymbols.list = (struct partial_symbol **) 172919370Spst xmmalloc (objfile -> md, objfile -> global_psymbols.size 173019370Spst * sizeof (struct partial_symbol *)); 173119370Spst objfile -> static_psymbols.next = 173219370Spst objfile -> static_psymbols.list = (struct partial_symbol **) 173319370Spst xmmalloc (objfile -> md, objfile -> static_psymbols.size 173419370Spst * sizeof (struct partial_symbol *)); 173519370Spst} 173619370Spst 173719370Spstvoid 173819370Spst_initialize_symfile () 173919370Spst{ 174019370Spst struct cmd_list_element *c; 174119370Spst 174219370Spst c = add_cmd ("symbol-file", class_files, symbol_file_command, 174319370Spst "Load symbol table from executable file FILE.\n\ 174419370SpstThe `file' command can also load symbol tables, as well as setting the file\n\ 174519370Spstto execute.", &cmdlist); 174619370Spst c->completer = filename_completer; 174719370Spst 174819370Spst c = add_cmd ("add-symbol-file", class_files, add_symbol_file_command, 174919370Spst "Usage: add-symbol-file FILE ADDR\n\ 175019370SpstLoad the symbols from FILE, assuming FILE has been dynamically loaded.\n\ 175119370SpstADDR is the starting address of the file's text.", 175219370Spst &cmdlist); 175319370Spst c->completer = filename_completer; 175419370Spst 175519370Spst c = add_cmd ("add-shared-symbol-files", class_files, 175619370Spst add_shared_symbol_files_command, 175719370Spst "Load the symbols from shared objects in the dynamic linker's link map.", 175819370Spst &cmdlist); 175919370Spst c = add_alias_cmd ("assf", "add-shared-symbol-files", class_files, 1, 176019370Spst &cmdlist); 176119370Spst 176219370Spst c = add_cmd ("load", class_files, load_command, 176319370Spst "Dynamically load FILE into the running program, and record its symbols\n\ 176419370Spstfor access from GDB.", &cmdlist); 176519370Spst c->completer = filename_completer; 176619370Spst 176719370Spst add_show_from_set 176819370Spst (add_set_cmd ("symbol-reloading", class_support, var_boolean, 176919370Spst (char *)&symbol_reloading, 177019370Spst "Set dynamic symbol table reloading multiple times in one run.", 177119370Spst &setlist), 177219370Spst &showlist); 177319370Spst 177419370Spst} 1775