home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / gnu / gdb-4.9 / gdb / symfile.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-05-12  |  38.0 KB  |  1,387 lines

  1. /* Generic symbol file reading for the GNU debugger, GDB.
  2.    Copyright 1990, 1991, 1992, 1993 Free Software Foundation, Inc.
  3.    Contributed by Cygnus Support, using pieces from other GDB modules.
  4.  
  5. This file is part of GDB.
  6.  
  7. This program is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation; either version 2 of the License, or
  10. (at your option) any later version.
  11.  
  12. This program is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. GNU General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with this program; if not, write to the Free Software
  19. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  20.  
  21. #include "defs.h"
  22. #include "symtab.h"
  23. #include "gdbtypes.h"
  24. #include "gdbcore.h"
  25. #include "frame.h"
  26. #include "target.h"
  27. #include "value.h"
  28. #include "symfile.h"
  29. #include "objfiles.h"
  30. #include "gdbcmd.h"
  31. #include "breakpoint.h"
  32. #include "language.h"
  33. #include "complaints.h"
  34. #include "demangle.h"
  35.  
  36. #include <obstack.h>
  37. #include <assert.h>
  38.  
  39. #include <sys/types.h>
  40. #include <fcntl.h>
  41. #include <string.h>
  42. #include <sys/stat.h>
  43. #include <ctype.h>
  44.  
  45. #ifndef O_BINARY
  46. #define O_BINARY 0
  47. #endif
  48.  
  49. /* Global variables owned by this file */
  50.  
  51. int readnow_symbol_files;        /* Read full symbols immediately */
  52.  
  53. struct complaint oldsyms_complaint = {
  54.   "Replacing old symbols for `%s'", 0, 0
  55. };
  56.  
  57. struct complaint empty_symtab_complaint = {
  58.   "Empty symbol table found for `%s'", 0, 0
  59. };
  60.  
  61. /* External variables and functions referenced. */
  62.  
  63. extern int info_verbose;
  64.  
  65. /* Functions this file defines */
  66.  
  67. static void
  68. set_initial_language PARAMS ((void));
  69.  
  70. static void
  71. load_command PARAMS ((char *, int));
  72.  
  73. static void
  74. add_symbol_file_command PARAMS ((char *, int));
  75.  
  76. static void
  77. cashier_psymtab PARAMS ((struct partial_symtab *));
  78.  
  79. static int
  80. compare_psymbols PARAMS ((const void *, const void *));
  81.  
  82. static int
  83. compare_symbols PARAMS ((const void *, const void *));
  84.  
  85. static bfd *
  86. symfile_bfd_open PARAMS ((char *));
  87.  
  88. static void
  89. find_sym_fns PARAMS ((struct objfile *));
  90.  
  91. void
  92. clear_symtab_users_once PARAMS ((void));
  93.  
  94. /* List of all available sym_fns.  On gdb startup, each object file reader
  95.    calls add_symtab_fns() to register information on each format it is
  96.    prepared to read. */
  97.  
  98. static struct sym_fns *symtab_fns = NULL;
  99.  
  100. /* Structures with which to manage partial symbol allocation.  */
  101.  
  102. struct psymbol_allocation_list global_psymbols = {0}, static_psymbols = {0};
  103.  
  104. /* Flag for whether user will be reloading symbols multiple times.
  105.    Defaults to ON for VxWorks, otherwise OFF.  */
  106.  
  107. #ifdef SYMBOL_RELOADING_DEFAULT
  108. int symbol_reloading = SYMBOL_RELOADING_DEFAULT;
  109. #else
  110. int symbol_reloading = 0;
  111. #endif
  112.  
  113.  
  114. /* In the following sort, we always make sure that
  115.    register debug symbol declarations always come before regular
  116.    debug symbol declarations (as might happen when parameters are
  117.    then put into registers by the compiler).
  118.  
  119.    Since this function is called from within qsort, in an ANSI environment
  120.    it must conform to the prototype for qsort, which specifies that the
  121.    comparison function takes two "void *" pointers. */
  122.  
  123. static int
  124. compare_symbols (s1p, s2p)
  125.      const PTR s1p;
  126.      const PTR s2p;
  127. {
  128.   register struct symbol **s1, **s2;
  129.   register int namediff;
  130.  
  131.   s1 = (struct symbol **) s1p;
  132.   s2 = (struct symbol **) s2p;
  133.  
  134.   namediff = STRCMP (SYMBOL_NAME (*s1), SYMBOL_NAME (*s2));
  135.   if (namediff != 0) return namediff;
  136.  
  137.   /* For symbols of the same name, registers should come first.  */
  138.   return ((SYMBOL_CLASS (*s2) == LOC_REGISTER)
  139.       - (SYMBOL_CLASS (*s1) == LOC_REGISTER));
  140. }
  141.  
  142. /*
  143.  
  144. LOCAL FUNCTION
  145.  
  146.     compare_psymbols -- compare two partial symbols by name
  147.  
  148. DESCRIPTION
  149.  
  150.     Given pointer to two partial symbol table entries, compare
  151.     them by name and return -N, 0, or +N (ala strcmp).  Typically
  152.     used by sorting routines like qsort().
  153.  
  154. NOTES
  155.  
  156.     Does direct compare of first two characters before punting
  157.     and passing to strcmp for longer compares.  Note that the
  158.     original version had a bug whereby two null strings or two
  159.     identically named one character strings would return the
  160.     comparison of memory following the null byte.
  161.  
  162.  */
  163.  
  164. static int
  165. compare_psymbols (s1p, s2p)
  166.      const PTR s1p;
  167.      const PTR s2p;
  168. {
  169.   register char *st1 = SYMBOL_NAME ((struct partial_symbol *) s1p);
  170.   register char *st2 = SYMBOL_NAME ((struct partial_symbol *) s2p);
  171.  
  172.   if ((st1[0] - st2[0]) || !st1[0])
  173.     {
  174.       return (st1[0] - st2[0]);
  175.     }
  176.   else if ((st1[1] - st2[1]) || !st1[1])
  177.     {
  178.       return (st1[1] - st2[1]);
  179.     }
  180.   else
  181.     {
  182.       return (STRCMP (st1 + 2, st2 + 2));
  183.     }
  184. }
  185.  
  186. void
  187. sort_pst_symbols (pst)
  188.      struct partial_symtab *pst;
  189. {
  190.   /* Sort the global list; don't sort the static list */
  191.  
  192.   qsort (pst -> objfile -> global_psymbols.list + pst -> globals_offset,
  193.      pst -> n_global_syms, sizeof (struct partial_symbol),
  194.      compare_psymbols);
  195. }
  196.  
  197. /* Call sort_block_syms to sort alphabetically the symbols of one block.  */
  198.  
  199. void
  200. sort_block_syms (b)
  201.      register struct block *b;
  202. {
  203.   qsort (&BLOCK_SYM (b, 0), BLOCK_NSYMS (b),
  204.      sizeof (struct symbol *), compare_symbols);
  205. }
  206.  
  207. /* Call sort_symtab_syms to sort alphabetically
  208.    the symbols of each block of one symtab.  */
  209.  
  210. void
  211. sort_symtab_syms (s)
  212.      register struct symtab *s;
  213. {
  214.   register struct blockvector *bv;
  215.   int nbl;
  216.   int i;
  217.   register struct block *b;
  218.  
  219.   if (s == 0)
  220.     return;
  221.   bv = BLOCKVECTOR (s);
  222.   nbl = BLOCKVECTOR_NBLOCKS (bv);
  223.   for (i = 0; i < nbl; i++)
  224.     {
  225.       b = BLOCKVECTOR_BLOCK (bv, i);
  226.       if (BLOCK_SHOULD_SORT (b))
  227.     sort_block_syms (b);
  228.     }
  229. }
  230.  
  231. void
  232. sort_all_symtab_syms ()
  233. {
  234.   register struct symtab *s;
  235.   register struct objfile *objfile;
  236.  
  237.   for (objfile = object_files; objfile != NULL; objfile = objfile -> next)
  238.     {
  239.       for (s = objfile -> symtabs; s != NULL; s = s -> next)
  240.     {
  241.       sort_symtab_syms (s);
  242.     }
  243.     }
  244. }
  245.  
  246. /* Make a copy of the string at PTR with SIZE characters in the symbol obstack
  247.    (and add a null character at the end in the copy).
  248.    Returns the address of the copy.  */
  249.  
  250. char *
  251. obsavestring (ptr, size, obstackp)
  252.      char *ptr;
  253.      int size;
  254.      struct obstack *obstackp;
  255. {
  256.   register char *p = (char *) obstack_alloc (obstackp, size + 1);
  257.   /* Open-coded bcopy--saves function call time.
  258.      These strings are usually short.  */
  259.   {
  260.     register char *p1 = ptr;
  261.     register char *p2 = p;
  262.     char *end = ptr + size;
  263.     while (p1 != end)
  264.       *p2++ = *p1++;
  265.   }
  266.   p[size] = 0;
  267.   return p;
  268. }
  269.  
  270. /* Concatenate strings S1, S2 and S3; return the new string.
  271.    Space is found in the symbol_obstack.  */
  272.  
  273. char *
  274. obconcat (obstackp, s1, s2, s3)
  275.      struct obstack *obstackp;
  276.      const char *s1, *s2, *s3;
  277. {
  278.   register int len = strlen (s1) + strlen (s2) + strlen (s3) + 1;
  279.   register char *val = (char *) obstack_alloc (obstackp, len);
  280.   strcpy (val, s1);
  281.   strcat (val, s2);
  282.   strcat (val, s3);
  283.   return val;
  284. }
  285.  
  286. /* Get the symbol table that corresponds to a partial_symtab.
  287.    This is fast after the first time you do it.  In fact, there
  288.    is an even faster macro PSYMTAB_TO_SYMTAB that does the fast
  289.    case inline.  */
  290.  
  291. struct symtab *
  292. psymtab_to_symtab (pst)
  293.      register struct partial_symtab *pst;
  294. {
  295.   /* If it's been looked up before, return it. */
  296.   if (pst->symtab)
  297.     return pst->symtab;
  298.  
  299.   /* If it has not yet been read in, read it.  */
  300.   if (!pst->readin)
  301.     { 
  302.       (*pst->read_symtab) (pst);
  303.     }
  304.  
  305.   return pst->symtab;
  306. }
  307.  
  308. /* Initialize entry point information for this objfile. */
  309.  
  310. void
  311. init_entry_point_info (objfile)
  312.      struct objfile *objfile;
  313. {
  314.   /* Save startup file's range of PC addresses to help blockframe.c
  315.      decide where the bottom of the stack is.  */
  316.  
  317.   if (bfd_get_file_flags (objfile -> obfd) & EXEC_P)
  318.     {
  319.       /* Executable file -- record its entry point so we'll recognize
  320.      the startup file because it contains the entry point.  */
  321.       objfile -> ei.entry_point = bfd_get_start_address (objfile -> obfd);
  322.     }
  323.   else
  324.     {
  325.       /* Examination of non-executable.o files.  Short-circuit this stuff.  */
  326.       /* ~0 will not be in any file, we hope.  */
  327.       objfile -> ei.entry_point = ~0;
  328.       /* set the startup file to be an empty range.  */
  329.       objfile -> ei.entry_file_lowpc = 0;
  330.       objfile -> ei.entry_file_highpc = 0;
  331.     }
  332. }
  333.  
  334. /* Remember the lowest-addressed loadable section we've seen.  
  335.    This function is called via bfd_map_over_sections.  */
  336.  
  337. #if 0     /* Not used yet */
  338. static void
  339. find_lowest_section (abfd, sect, obj)
  340.      bfd *abfd;
  341.      asection *sect;
  342.      PTR obj;
  343. {
  344.   asection **lowest = (asection **)obj;
  345.  
  346.   if (0 == (bfd_get_section_flags (abfd, sect) & SEC_LOAD))
  347.     return;
  348.   if (!*lowest)
  349.     *lowest = sect;        /* First loadable section */
  350.   else if (bfd_section_vma (abfd, *lowest) >= bfd_section_vma (abfd, sect))
  351.     *lowest = sect;        /* A lower loadable section */
  352. }
  353. #endif 
  354.  
  355. /* Process a symbol file, as either the main file or as a dynamically
  356.    loaded file.
  357.  
  358.    NAME is the file name (which will be tilde-expanded and made
  359.    absolute herein) (but we don't free or modify NAME itself).
  360.    FROM_TTY says how verbose to be.  MAINLINE specifies whether this
  361.    is the main symbol file, or whether it's an extra symbol file such
  362.    as dynamically loaded code.  If !mainline, ADDR is the address
  363.    where the text segment was loaded.  If VERBO, the caller has printed
  364.    a verbose message about the symbol reading (and complaints can be
  365.    more terse about it).  */
  366.  
  367. void
  368. syms_from_objfile (objfile, addr, mainline, verbo)
  369.      struct objfile *objfile;
  370.      CORE_ADDR addr;
  371.      int mainline;
  372.      int verbo;
  373. {
  374.   struct section_offsets *section_offsets;
  375.   asection *lowest_sect;
  376.  
  377.   init_entry_point_info (objfile);
  378.   find_sym_fns (objfile);
  379.  
  380.   if (mainline) 
  381.     {
  382.       /* Since no error yet, throw away the old symbol table.  */
  383.  
  384.       if (symfile_objfile != NULL)
  385.     {
  386.       free_objfile (symfile_objfile);
  387.       symfile_objfile = NULL;
  388.     }
  389.  
  390.       (*objfile -> sf -> sym_new_init) (objfile);
  391.     }
  392.  
  393.   /* Convert addr into an offset rather than an absolute address.
  394.      We find the lowest address of a loaded segment in the objfile,
  395.      and assume that <addr> is where that got loaded.  Due to historical
  396.      precedent, we warn if that doesn't happen to be the ".text"
  397.      segment.  */
  398.  
  399.   if (mainline)
  400.     {
  401.       addr = 0;        /* No offset from objfile addresses.  */
  402.     }
  403.   else
  404.     {
  405.       lowest_sect = bfd_get_section_by_name (objfile->obfd, ".text");
  406. #if 0
  407.       lowest_sect = 0;
  408.       bfd_map_over_sections (objfile->obfd, find_lowest_section,
  409.                  (PTR) &lowest_sect);
  410. #endif
  411.  
  412.       if (lowest_sect == 0)
  413.     warning ("no loadable sections found in added symbol-file %s",
  414.          objfile->name);
  415.       else if (0 == bfd_get_section_name (objfile->obfd, lowest_sect)
  416.            || !STREQ (".text",
  417.                   bfd_get_section_name (objfile->obfd, lowest_sect)))
  418.     warning ("Lowest section in %s is %s at 0x%x",
  419.          objfile->name,
  420.          bfd_section_name (objfile->obfd, lowest_sect),
  421.          bfd_section_vma (objfile->obfd, lowest_sect));
  422.  
  423.       if (lowest_sect)
  424.     addr -= bfd_section_vma (objfile->obfd, lowest_sect);
  425.     }
  426.  
  427.   /* Initialize symbol reading routines for this objfile, allow complaints to
  428.      appear for this new file, and record how verbose to be, then do the
  429.      initial symbol reading for this file. */
  430.  
  431.   (*objfile -> sf -> sym_init) (objfile);
  432.   clear_complaints (1, verbo);
  433.  
  434.   /* If objfile->sf->sym_offsets doesn't set this, we don't care
  435.      (currently).  */
  436.   objfile->num_sections = 0;  /* krp-FIXME: why zero? */
  437.   section_offsets = (*objfile -> sf -> sym_offsets) (objfile, addr);
  438.   objfile->section_offsets = section_offsets;
  439.  
  440. #ifndef IBM6000_TARGET
  441.   /* This is a SVR4/SunOS specific hack, I think.  In any event, it
  442.      screws RS/6000.  sym_offsets should be doing this sort of thing,
  443.      because it knows the mapping between bfd sections and
  444.      section_offsets.  */
  445.   /* This is a hack.  As far as I can tell, section offsets are not
  446.      target dependent.  They are all set to addr with a couple of
  447.      exceptions.  The exceptions are sysvr4 shared libraries, whose
  448.      offsets are kept in solib structures anyway and rs6000 xcoff
  449.      which handles shared libraries in a completely unique way.
  450.  
  451.      Section offsets are built similarly, except that they are built
  452.      by adding addr in all cases because there is no clear mapping
  453.      from section_offsets into actual sections.  Note that solib.c
  454.      has a different algorythm for finding section offsets.
  455.  
  456.      These should probably all be collapsed into some target
  457.      independent form of shared library support.  FIXME.  */
  458.  
  459.   if (addr)
  460.     {
  461.       struct obj_section *s;
  462.  
  463.       for (s = objfile->sections; s < objfile->sections_end; ++s)
  464.     {
  465.       s->addr -= s->offset;
  466.       s->addr += addr;
  467.       s->endaddr -= s->offset;
  468.       s->endaddr += addr;
  469.       s->offset += addr;
  470.     }
  471.     }
  472. #endif /* not IBM6000_TARGET */
  473.  
  474.   (*objfile -> sf -> sym_read) (objfile, section_offsets, mainline);
  475.  
  476.   /* Don't allow char * to have a typename (else would get caddr_t.)  */
  477.   /* Ditto void *.  FIXME should do this for all the builtin types.  */
  478.  
  479.   TYPE_NAME (lookup_pointer_type (builtin_type_char)) = 0;
  480.   TYPE_NAME (lookup_pointer_type (builtin_type_void)) = 0;
  481.  
  482.   /* Mark the objfile has having had initial symbol read attempted.  Note
  483.      that this does not mean we found any symbols... */
  484.  
  485.   objfile -> flags |= OBJF_SYMS;
  486. }
  487.  
  488. /* Perform required actions immediately after either reading in the initial
  489.    symbols for a new objfile, or mapping in the symbols from a reusable
  490.    objfile. */
  491.    
  492. void
  493. new_symfile_objfile (objfile, mainline, verbo)
  494.      struct objfile *objfile;
  495.      int mainline;
  496.      int verbo;
  497. {
  498.   if (mainline)
  499.     {
  500.       /* OK, make it the "real" symbol file.  */
  501.       symfile_objfile = objfile;
  502.     }
  503.  
  504.   /* If we have wiped out any old symbol tables, clean up.  */
  505.   clear_symtab_users_once ();
  506.  
  507.   /* We're done reading the symbol file; finish off complaints.  */
  508.   clear_complaints (0, verbo);
  509.  
  510.   /* Fixup all the breakpoints that may have been redefined by this
  511.      symbol file. */
  512.  
  513.   breakpoint_re_set ();
  514. }
  515.  
  516. /* Process a symbol file, as either the main file or as a dynamically
  517.    loaded file.
  518.  
  519.    NAME is the file name (which will be tilde-expanded and made
  520.    absolute herein) (but we don't free or modify NAME itself).
  521.    FROM_TTY says how verbose to be.  MAINLINE specifies whether this
  522.    is the main symbol file, or whether it's an extra symbol file such
  523.    as dynamically loaded code.  If !mainline, ADDR is the address
  524.    where the text segment was loaded.
  525.  
  526.    Upon success, returns a pointer to the objfile that was added.
  527.    Upon failure, jumps back to command level (never returns). */
  528.  
  529. struct objfile *
  530. symbol_file_add (name, from_tty, addr, mainline, mapped, readnow)
  531.      char *name;
  532.      int from_tty;
  533.      CORE_ADDR addr;
  534.      int mainline;
  535.      int mapped;
  536.      int readnow;
  537. {
  538.   struct objfile *objfile;
  539.   struct partial_symtab *psymtab;
  540.   bfd *abfd;
  541.  
  542.   /* Open a bfd for the file, and give user a chance to burp if we'd be
  543.      interactively wiping out any existing symbols.  */
  544.  
  545.   abfd = symfile_bfd_open (name);
  546.  
  547.   if ((have_full_symbols () || have_partial_symbols ())
  548.       && mainline
  549.       && from_tty
  550.       && !query ("Load new symbol table from \"%s\"? ", name))
  551.       error ("Not confirmed.");
  552.       
  553.   /* Getting new symbols may change our opinion about what is
  554.      frameless.  */
  555.  
  556.   reinit_frame_cache ();
  557.  
  558.   objfile = allocate_objfile (abfd, mapped);
  559.  
  560.   /* If the objfile uses a mapped symbol file, and we have a psymtab for
  561.      it, then skip reading any symbols at this time. */
  562.  
  563.   if ((objfile -> flags & OBJF_MAPPED) && (objfile -> flags & OBJF_SYMS))
  564.     {
  565.       /* We mapped in an existing symbol table file that already has had
  566.      initial symbol reading performed, so we can skip that part.  Notify
  567.      the user that instead of reading the symbols, they have been mapped.
  568.      */
  569.       if (from_tty || info_verbose)
  570.     {
  571.       printf_filtered ("Mapped symbols for %s...", name);
  572.       wrap_here ("");
  573.       fflush (stdout);
  574.     }
  575.       init_entry_point_info (objfile);
  576.       find_sym_fns (objfile);
  577.     }
  578.   else
  579.     {
  580.       /* We either created a new mapped symbol table, mapped an existing
  581.      symbol table file which has not had initial symbol reading
  582.      performed, or need to read an unmapped symbol table. */
  583.       if (from_tty || info_verbose)
  584.     {
  585.       printf_filtered ("Reading symbols from %s...", name);
  586.       wrap_here ("");
  587.       fflush (stdout);
  588.     }
  589.       syms_from_objfile (objfile, addr, mainline, from_tty);
  590.     }      
  591.  
  592.   new_symfile_objfile (objfile, mainline, from_tty);
  593.  
  594.   /* We now have at least a partial symbol table.  Check to see if the
  595.      user requested that all symbols be read on initial access via either
  596.      the gdb startup command line or on a per symbol file basis.  Expand
  597.      all partial symbol tables for this objfile if so. */
  598.  
  599.   if (readnow || readnow_symbol_files)
  600.     {
  601.       if (from_tty || info_verbose)
  602.     {
  603.       printf_filtered ("expanding to full symbols...");
  604.       wrap_here ("");
  605.       fflush (stdout);
  606.     }
  607.  
  608.       for (psymtab = objfile -> psymtabs;
  609.        psymtab != NULL;
  610.        psymtab = psymtab -> next)
  611.     {
  612.       psymtab_to_symtab (psymtab);
  613.     }
  614.     }
  615.  
  616.   if (from_tty || info_verbose)
  617.     {
  618.       printf_filtered ("done.\n");
  619.       fflush (stdout);
  620.     }
  621.  
  622.   return (objfile);
  623. }
  624.  
  625. /* This is the symbol-file command.  Read the file, analyze its symbols,
  626.    and add a struct symtab to a symtab list.  */
  627.  
  628. void
  629. symbol_file_command (args, from_tty)
  630.      char *args;
  631.      int from_tty;
  632. {
  633.   char **argv;
  634.   char *name = NULL;
  635.   struct cleanup *cleanups;
  636.   int mapped = 0;
  637.   int readnow = 0;
  638.  
  639.   dont_repeat ();
  640.  
  641.   if (args == NULL)
  642.     {
  643.       if ((have_full_symbols () || have_partial_symbols ())
  644.       && from_tty
  645.       && !query ("Discard symbol table from `%s'? ",
  646.              symfile_objfile -> name))
  647.     error ("Not confirmed.");
  648.       free_all_objfiles ();
  649.       symfile_objfile = NULL;
  650.       current_source_symtab = NULL;
  651.       current_source_line = 0;
  652.       if (from_tty)
  653.     {
  654.       printf ("No symbol file now.\n");
  655.     }
  656.     }
  657.   else
  658.     {
  659.       if ((argv = buildargv (args)) == NULL)
  660.     {
  661.       nomem (0);
  662.     }
  663.       cleanups = make_cleanup (freeargv, (char *) argv);
  664.       while (*argv != NULL)
  665.     {
  666.       if (STREQ (*argv, "-mapped"))
  667.         {
  668.           mapped = 1;
  669.         }
  670.       else if (STREQ (*argv, "-readnow"))
  671.         {
  672.           readnow = 1;
  673.         }
  674.       else if (**argv == '-')
  675.         {
  676.           error ("unknown option `%s'", *argv);
  677.         }
  678.       else
  679.         {
  680.           name = *argv;
  681.         }
  682.       argv++;
  683.     }
  684.  
  685.       if (name == NULL)
  686.     {
  687.       error ("no symbol file name was specified");
  688.     }
  689.       else
  690.     {
  691.       symbol_file_add (name, from_tty, (CORE_ADDR)0, 1, mapped, readnow);
  692.       set_initial_language ();
  693.     }
  694.       do_cleanups (cleanups);
  695.     }
  696. }
  697.  
  698. /* Set the initial language.
  699.  
  700.    A better solution would be to record the language in the psymtab when reading
  701.    partial symbols, and then use it (if known) to set the language.  This would
  702.    be a win for formats that encode the language in an easily discoverable place,
  703.    such as DWARF.  For stabs, we can jump through hoops looking for specially
  704.    named symbols or try to intuit the language from the specific type of stabs
  705.    we find, but we can't do that until later when we read in full symbols.
  706.    FIXME.  */
  707.  
  708. static void
  709. set_initial_language ()
  710. {
  711.   struct partial_symtab *pst;
  712.   enum language lang = language_unknown;      
  713.  
  714.   pst = find_main_psymtab ();
  715.   if (pst != NULL)
  716.     {
  717.       if (pst -> filename != NULL)
  718.     {
  719.       lang = deduce_language_from_filename (pst -> filename);
  720.         }
  721.       if (lang == language_unknown)
  722.     {
  723.         /* Make C the default language */
  724.         lang = language_c;
  725.     }
  726.       set_language (lang);
  727.       expected_language = current_language;    /* Don't warn the user */
  728.     }
  729. }
  730.  
  731. /* Open file specified by NAME and hand it off to BFD for preliminary
  732.    analysis.  Result is a newly initialized bfd *, which includes a newly
  733.    malloc'd` copy of NAME (tilde-expanded and made absolute).
  734.    In case of trouble, error() is called.  */
  735.  
  736. static bfd *
  737. symfile_bfd_open (name)
  738.      char *name;
  739. {
  740.   bfd *sym_bfd;
  741.   int desc;
  742.   char *absolute_name;
  743.  
  744.   name = tilde_expand (name);    /* Returns 1st new malloc'd copy */
  745.  
  746.   /* Look down path for it, allocate 2nd new malloc'd copy.  */
  747.   desc = openp (getenv ("PATH"), 1, name, O_RDONLY | O_BINARY, 0, &absolute_name);
  748.   if (desc < 0)
  749.     {
  750.       make_cleanup (free, name);
  751.       perror_with_name (name);
  752.     }
  753.   free (name);            /* Free 1st new malloc'd copy */
  754.   name = absolute_name;        /* Keep 2nd malloc'd copy in bfd */
  755.                 /* It'll be freed in free_objfile(). */
  756.  
  757.   sym_bfd = bfd_fdopenr (name, NULL, desc);
  758.   if (!sym_bfd)
  759.     {
  760.       close (desc);
  761.       make_cleanup (free, name);
  762.       error ("\"%s\": can't open to read symbols: %s.", name,
  763.          bfd_errmsg (bfd_error));
  764.     }
  765.   sym_bfd->cacheable = true;
  766.  
  767.   if (!bfd_check_format (sym_bfd, bfd_object))
  768.     {
  769.       bfd_close (sym_bfd);    /* This also closes desc */
  770.       make_cleanup (free, name);
  771.       error ("\"%s\": can't read symbols: %s.", name,
  772.          bfd_errmsg (bfd_error));
  773.     }
  774.  
  775.   return (sym_bfd);
  776. }
  777.  
  778. /* Link a new symtab_fns into the global symtab_fns list.  Called on gdb
  779.    startup by the _initialize routine in each object file format reader,
  780.    to register information about each format the the reader is prepared
  781.    to handle. */
  782.  
  783. void
  784. add_symtab_fns (sf)
  785.      struct sym_fns *sf;
  786. {
  787.   sf->next = symtab_fns;
  788.   symtab_fns = sf;
  789. }
  790.  
  791.  
  792. /* Initialize to read symbols from the symbol file sym_bfd.  It either
  793.    returns or calls error().  The result is an initialized struct sym_fns
  794.    in the objfile structure, that contains cached information about the
  795.    symbol file.  */
  796.  
  797. static void
  798. find_sym_fns (objfile)
  799.      struct objfile *objfile;
  800. {
  801.   struct sym_fns *sf;
  802.  
  803.   for (sf = symtab_fns; sf != NULL; sf = sf -> next)
  804.     {
  805.       if (strncmp (bfd_get_target (objfile -> obfd),
  806.             sf -> sym_name, sf -> sym_namelen) == 0)
  807.     {
  808.       objfile -> sf = sf;
  809.       return;
  810.     }
  811.     }
  812.   error ("I'm sorry, Dave, I can't do that.  Symbol format `%s' unknown.",
  813.      bfd_get_target (objfile -> obfd));
  814. }
  815.  
  816. /* This function runs the load command of our current target.  */
  817.  
  818. static void
  819. load_command (arg, from_tty)
  820.      char *arg;
  821.      int from_tty;
  822. {
  823.   target_load (arg, from_tty);
  824. }
  825.  
  826. /* This function allows the addition of incrementally linked object files.
  827.    It does not modify any state in the target, only in the debugger.  */
  828.  
  829. /* ARGSUSED */
  830. static void
  831. add_symbol_file_command (args, from_tty)
  832.      char *args;
  833.      int from_tty;
  834. {
  835.   char *name = NULL;
  836.   CORE_ADDR text_addr;
  837.   char *arg;
  838.   int readnow = 0;
  839.   int mapped = 0;
  840.   
  841.   dont_repeat ();
  842.  
  843.   if (args == NULL)
  844.     {
  845.       error ("add-symbol-file takes a file name and an address");
  846.     }
  847.  
  848.   /* Make a copy of the string that we can safely write into. */
  849.  
  850.   args = strdup (args);
  851.   make_cleanup (free, args);
  852.  
  853.   /* Pick off any -option args and the file name. */
  854.  
  855.   while ((*args != '\000') && (name == NULL))
  856.     {
  857.       while (isspace (*args)) {args++;}
  858.       arg = args;
  859.       while ((*args != '\000') && !isspace (*args)) {args++;}
  860.       if (*args != '\000')
  861.     {
  862.       *args++ = '\000';
  863.     }
  864.       if (*arg != '-')
  865.     {
  866.       name = arg;
  867.     }
  868.       else if (STREQ (arg, "-mapped"))
  869.     {
  870.       mapped = 1;
  871.     }
  872.       else if (STREQ (arg, "-readnow"))
  873.     {
  874.       readnow = 1;
  875.     }
  876.       else
  877.     {
  878.       error ("unknown option `%s'", arg);
  879.     }
  880.     }
  881.  
  882.   /* After picking off any options and the file name, args should be
  883.      left pointing at the remainder of the command line, which should
  884.      be the address expression to evaluate. */
  885.  
  886.   if ((name == NULL) || (*args == '\000') )
  887.     {
  888.       error ("add-symbol-file takes a file name and an address");
  889.     }
  890.   name = tilde_expand (name);
  891.   make_cleanup (free, name);
  892.  
  893.   text_addr = parse_and_eval_address (args);
  894.  
  895.   if (!query ("add symbol table from file \"%s\" at text_addr = %s?\n",
  896.           name, local_hex_string (text_addr)))
  897.     error ("Not confirmed.");
  898.  
  899.   symbol_file_add (name, 0, text_addr, 0, mapped, readnow);
  900. }
  901.  
  902. /* Re-read symbols if a symbol-file has changed.  */
  903. void
  904. reread_symbols ()
  905. {
  906.   struct objfile *objfile;
  907.   long new_modtime;
  908.   int reread_one = 0;
  909.   struct stat new_statbuf;
  910.   int res;
  911.  
  912.   /* With the addition of shared libraries, this should be modified,
  913.      the load time should be saved in the partial symbol tables, since
  914.      different tables may come from different source files.  FIXME.
  915.      This routine should then walk down each partial symbol table
  916.      and see if the symbol table that it originates from has been changed */
  917.  
  918. the_big_top:
  919.   for (objfile = object_files; objfile; objfile = objfile->next) {
  920.     if (objfile->obfd) {
  921. #ifdef IBM6000_TARGET
  922.      /* If this object is from a shared library, then you should
  923.         stat on the library name, not member name. */
  924.  
  925.      if (objfile->obfd->my_archive)
  926.        res = stat (objfile->obfd->my_archive->filename, &new_statbuf);
  927.      else
  928. #endif
  929.       res = stat (objfile->name, &new_statbuf);
  930.       if (res != 0) {
  931.     /* FIXME, should use print_sys_errmsg but it's not filtered. */
  932.     printf_filtered ("`%s' has disappeared; keeping its symbols.\n",
  933.              objfile->name);
  934.     continue;
  935.       }
  936.       new_modtime = new_statbuf.st_mtime;
  937.       if (new_modtime != objfile->mtime) {
  938.     printf_filtered ("`%s' has changed; re-reading symbols.\n",
  939.              objfile->name);
  940.     /* FIXME, this should use a different command...that would only
  941.         affect this objfile's symbols, and would reset objfile->mtime.
  942.                 (objfile->mtime = new_modtime;)
  943.         HOWEVER, that command isn't written yet -- so call symbol_file_
  944.        command, and restart the scan from the top, because it munges
  945.        the object_files list.  */
  946.     symbol_file_command (objfile->name, 0);
  947.     reread_one = 1;
  948.     goto the_big_top;    /* Start over.  */
  949.       }
  950.     }
  951.   }
  952.  
  953.   if (reread_one)
  954.     breakpoint_re_set ();
  955. }
  956.  
  957.  
  958. enum language
  959. deduce_language_from_filename (filename)
  960.      char *filename;
  961. {
  962.   char *c;
  963.   
  964.   if (0 == filename) 
  965.     ; /* Get default */
  966.   else if (0 == (c = strrchr (filename, '.')))
  967.     ; /* Get default. */
  968.   else if(STREQ(c,".mod"))
  969.     return language_m2;
  970.   else if(STREQ(c,".c"))
  971.     return language_c;
  972.   else if(STREQ(c,".cc") || STREQ(c,".C"))
  973.     return language_cplus;
  974.   else if(STREQ(c,".ch") || STREQ(c,".c186") || STREQ(c,".c286"))
  975.     return language_chill;
  976.  
  977.   return language_unknown;        /* default */
  978. }
  979.  
  980. /* allocate_symtab:
  981.  
  982.    Allocate and partly initialize a new symbol table.  Return a pointer
  983.    to it.  error() if no space.
  984.  
  985.    Caller must set these fields:
  986.     LINETABLE(symtab)
  987.     symtab->blockvector
  988.     symtab->dirname
  989.     symtab->free_code
  990.     symtab->free_ptr
  991.     initialize any EXTRA_SYMTAB_INFO
  992.     possibly free_named_symtabs (symtab->filename);
  993.  */
  994.  
  995. struct symtab *
  996. allocate_symtab (filename, objfile)
  997.      char *filename;
  998.      struct objfile *objfile;
  999. {
  1000.   register struct symtab *symtab;
  1001.  
  1002.   symtab = (struct symtab *)
  1003.     obstack_alloc (&objfile -> symbol_obstack, sizeof (struct symtab));
  1004.   memset (symtab, 0, sizeof (*symtab));
  1005.   symtab -> filename = obsavestring (filename, strlen (filename),
  1006.                      &objfile -> symbol_obstack);
  1007.   symtab -> fullname = NULL;
  1008.   symtab -> language = deduce_language_from_filename (filename);
  1009.  
  1010.   /* Hook it to the objfile it comes from */
  1011.  
  1012.   symtab -> objfile = objfile;
  1013.   symtab -> next = objfile -> symtabs;
  1014.   objfile -> symtabs = symtab;
  1015.  
  1016. #ifdef INIT_EXTRA_SYMTAB_INFO
  1017.   INIT_EXTRA_SYMTAB_INFO (symtab);
  1018. #endif
  1019.  
  1020.   return (symtab);
  1021. }
  1022.  
  1023. struct partial_symtab *
  1024. allocate_psymtab (filename, objfile)
  1025.      char *filename;
  1026.      struct objfile *objfile;
  1027. {
  1028.   struct partial_symtab *psymtab;
  1029.  
  1030.   if (objfile -> free_psymtabs)
  1031.     {
  1032.       psymtab = objfile -> free_psymtabs;
  1033.       objfile -> free_psymtabs = psymtab -> next;
  1034.     }
  1035.   else
  1036.     psymtab = (struct partial_symtab *)
  1037.       obstack_alloc (&objfile -> psymbol_obstack,
  1038.              sizeof (struct partial_symtab));
  1039.  
  1040.   memset (psymtab, 0, sizeof (struct partial_symtab));
  1041.   psymtab -> filename = obsavestring (filename, strlen (filename),
  1042.                       &objfile -> psymbol_obstack);
  1043.   psymtab -> symtab = NULL;
  1044.  
  1045.   /* Hook it to the objfile it comes from */
  1046.  
  1047.   psymtab -> objfile = objfile;
  1048.   psymtab -> next = objfile -> psymtabs;
  1049.   objfile -> psymtabs = psymtab;
  1050.   
  1051.   return (psymtab);
  1052. }
  1053.  
  1054.  
  1055. /* clear_symtab_users_once:
  1056.  
  1057.    This function is run after symbol reading, or from a cleanup.
  1058.    If an old symbol table was obsoleted, the old symbol table
  1059.    has been blown away, but the other GDB data structures that may 
  1060.    reference it have not yet been cleared or re-directed.  (The old
  1061.    symtab was zapped, and the cleanup queued, in free_named_symtab()
  1062.    below.)
  1063.  
  1064.    This function can be queued N times as a cleanup, or called
  1065.    directly; it will do all the work the first time, and then will be a
  1066.    no-op until the next time it is queued.  This works by bumping a
  1067.    counter at queueing time.  Much later when the cleanup is run, or at
  1068.    the end of symbol processing (in case the cleanup is discarded), if
  1069.    the queued count is greater than the "done-count", we do the work
  1070.    and set the done-count to the queued count.  If the queued count is
  1071.    less than or equal to the done-count, we just ignore the call.  This
  1072.    is needed because reading a single .o file will often replace many
  1073.    symtabs (one per .h file, for example), and we don't want to reset
  1074.    the breakpoints N times in the user's face.
  1075.  
  1076.    The reason we both queue a cleanup, and call it directly after symbol
  1077.    reading, is because the cleanup protects us in case of errors, but is
  1078.    discarded if symbol reading is successful.  */
  1079.  
  1080. static int clear_symtab_users_queued;
  1081. static int clear_symtab_users_done;
  1082.  
  1083. void
  1084. clear_symtab_users_once ()
  1085. {
  1086.   /* Enforce once-per-`do_cleanups'-semantics */
  1087.   if (clear_symtab_users_queued <= clear_symtab_users_done)
  1088.     return;
  1089.   clear_symtab_users_done = clear_symtab_users_queued;
  1090.  
  1091.   printf ("Resetting debugger state after updating old symbol tables\n");
  1092.  
  1093.   /* Someday, we should do better than this, by only blowing away
  1094.      the things that really need to be blown.  */
  1095.   clear_value_history ();
  1096.   clear_displays ();
  1097.   clear_internalvars ();
  1098.   breakpoint_re_set ();
  1099.   set_default_breakpoint (0, 0, 0, 0);
  1100.   current_source_symtab = 0;
  1101. }
  1102.  
  1103. /* Delete the specified psymtab, and any others that reference it.  */
  1104.  
  1105. static void
  1106. cashier_psymtab (pst)
  1107.      struct partial_symtab *pst;
  1108. {
  1109.   struct partial_symtab *ps, *pprev;
  1110.   int i;
  1111.  
  1112.   /* Find its previous psymtab in the chain */
  1113.   for (ps = pst->objfile->psymtabs; ps; ps = ps->next) {
  1114.     if (ps == pst)
  1115.       break;
  1116.     pprev = ps;
  1117.   }
  1118.  
  1119.   if (ps) {
  1120.     /* Unhook it from the chain.  */
  1121.     if (ps == pst->objfile->psymtabs)
  1122.       pst->objfile->psymtabs = ps->next;
  1123.     else
  1124.       pprev->next = ps->next;
  1125.  
  1126.     /* FIXME, we can't conveniently deallocate the entries in the
  1127.        partial_symbol lists (global_psymbols/static_psymbols) that
  1128.        this psymtab points to.  These just take up space until all
  1129.        the psymtabs are reclaimed.  Ditto the dependencies list and
  1130.        filename, which are all in the psymbol_obstack.  */
  1131.  
  1132.     /* We need to cashier any psymtab that has this one as a dependency... */
  1133. again:
  1134.     for (ps = pst->objfile->psymtabs; ps; ps = ps->next) {
  1135.       for (i = 0; i < ps->number_of_dependencies; i++) {
  1136.     if (ps->dependencies[i] == pst) {
  1137.       cashier_psymtab (ps);
  1138.       goto again;        /* Must restart, chain has been munged. */
  1139.     }
  1140.       }
  1141.     }
  1142.   }
  1143. }
  1144.  
  1145. /* If a symtab or psymtab for filename NAME is found, free it along
  1146.    with any dependent breakpoints, displays, etc.
  1147.    Used when loading new versions of object modules with the "add-file"
  1148.    command.  This is only called on the top-level symtab or psymtab's name;
  1149.    it is not called for subsidiary files such as .h files.
  1150.  
  1151.    Return value is 1 if we blew away the environment, 0 if not.
  1152.    FIXME.  The return valu appears to never be used.
  1153.  
  1154.    FIXME.  I think this is not the best way to do this.  We should
  1155.    work on being gentler to the environment while still cleaning up
  1156.    all stray pointers into the freed symtab.  */
  1157.  
  1158. int
  1159. free_named_symtabs (name)
  1160.      char *name;
  1161. {
  1162. #if 0
  1163.   /* FIXME:  With the new method of each objfile having it's own
  1164.      psymtab list, this function needs serious rethinking.  In particular,
  1165.      why was it ever necessary to toss psymtabs with specific compilation
  1166.      unit filenames, as opposed to all psymtabs from a particular symbol
  1167.      file?  -- fnf
  1168.      Well, the answer is that some systems permit reloading of particular
  1169.      compilation units.  We want to blow away any old info about these
  1170.      compilation units, regardless of which objfiles they arrived in. --gnu.  */
  1171.  
  1172.   register struct symtab *s;
  1173.   register struct symtab *prev;
  1174.   register struct partial_symtab *ps;
  1175.   struct blockvector *bv;
  1176.   int blewit = 0;
  1177.  
  1178.   /* We only wack things if the symbol-reload switch is set.  */
  1179.   if (!symbol_reloading)
  1180.     return 0;
  1181.  
  1182.   /* Some symbol formats have trouble providing file names... */
  1183.   if (name == 0 || *name == '\0')
  1184.     return 0;
  1185.  
  1186.   /* Look for a psymtab with the specified name.  */
  1187.  
  1188. again2:
  1189.   for (ps = partial_symtab_list; ps; ps = ps->next) {
  1190.     if (STREQ (name, ps->filename)) {
  1191.       cashier_psymtab (ps);    /* Blow it away...and its little dog, too.  */
  1192.       goto again2;        /* Must restart, chain has been munged */
  1193.     }
  1194.   }
  1195.  
  1196.   /* Look for a symtab with the specified name.  */
  1197.  
  1198.   for (s = symtab_list; s; s = s->next)
  1199.     {
  1200.       if (STREQ (name, s->filename))
  1201.     break;
  1202.       prev = s;
  1203.     }
  1204.  
  1205.   if (s)
  1206.     {
  1207.       if (s == symtab_list)
  1208.     symtab_list = s->next;
  1209.       else
  1210.     prev->next = s->next;
  1211.  
  1212.       /* For now, queue a delete for all breakpoints, displays, etc., whether
  1213.      or not they depend on the symtab being freed.  This should be
  1214.      changed so that only those data structures affected are deleted.  */
  1215.  
  1216.       /* But don't delete anything if the symtab is empty.
  1217.      This test is necessary due to a bug in "dbxread.c" that
  1218.      causes empty symtabs to be created for N_SO symbols that
  1219.      contain the pathname of the object file.  (This problem
  1220.      has been fixed in GDB 3.9x).  */
  1221.  
  1222.       bv = BLOCKVECTOR (s);
  1223.       if (BLOCKVECTOR_NBLOCKS (bv) > 2
  1224.       || BLOCK_NSYMS (BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK))
  1225.       || BLOCK_NSYMS (BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK)))
  1226.     {
  1227.       complain (&oldsyms_complaint, name);
  1228.  
  1229.       clear_symtab_users_queued++;
  1230.       make_cleanup (clear_symtab_users_once, 0);
  1231.       blewit = 1;
  1232.     } else {
  1233.       complain (&empty_symtab_complaint, name);
  1234.     }
  1235.  
  1236.       free_symtab (s);
  1237.     }
  1238.   else
  1239.     {
  1240.       /* It is still possible that some breakpoints will be affected
  1241.      even though no symtab was found, since the file might have
  1242.      been compiled without debugging, and hence not be associated
  1243.      with a symtab.  In order to handle this correctly, we would need
  1244.      to keep a list of text address ranges for undebuggable files.
  1245.      For now, we do nothing, since this is a fairly obscure case.  */
  1246.       ;
  1247.     }
  1248.  
  1249.   /* FIXME, what about the minimal symbol table? */
  1250.   return blewit;
  1251. #else
  1252.   return (0);
  1253. #endif
  1254. }
  1255.  
  1256. /* Allocate and partially fill a partial symtab.  It will be
  1257.    completely filled at the end of the symbol list.
  1258.  
  1259.    SYMFILE_NAME is the name of the symbol-file we are reading from, and ADDR
  1260.    is the address relative to which its symbols are (incremental) or 0
  1261.    (normal). */
  1262.  
  1263.  
  1264. struct partial_symtab *
  1265. start_psymtab_common (objfile, section_offsets,
  1266.               filename, textlow, global_syms, static_syms)
  1267.      struct objfile *objfile;
  1268.      struct section_offsets *section_offsets;
  1269.      char *filename;
  1270.      CORE_ADDR textlow;
  1271.      struct partial_symbol *global_syms;
  1272.      struct partial_symbol *static_syms;
  1273. {
  1274.   struct partial_symtab *psymtab;
  1275.  
  1276.   psymtab = allocate_psymtab (filename, objfile);
  1277.   psymtab -> section_offsets = section_offsets;
  1278.   psymtab -> textlow = textlow;
  1279.   psymtab -> texthigh = psymtab -> textlow;  /* default */
  1280.   psymtab -> globals_offset = global_syms - objfile -> global_psymbols.list;
  1281.   psymtab -> statics_offset = static_syms - objfile -> static_psymbols.list;
  1282.   return (psymtab);
  1283. }
  1284.  
  1285. /* Debugging versions of functions that are usually inline macros
  1286.    (see symfile.h).  */
  1287.  
  1288. #if !INLINE_ADD_PSYMBOL
  1289.  
  1290. /* Add a symbol with a long value to a psymtab.
  1291.    Since one arg is a struct, we pass in a ptr and deref it (sigh).  */
  1292.  
  1293. void
  1294. add_psymbol_to_list (name, namelength, namespace, class, list, val, language,
  1295.              objfile)
  1296.      char *name;
  1297.      int namelength;
  1298.      enum namespace namespace;
  1299.      enum address_class class;
  1300.      struct psymbol_allocation_list *list;
  1301.      long val;
  1302.      enum language language;
  1303.      struct objfile *objfile;
  1304. {
  1305.   register struct partial_symbol *psym;
  1306.   register char *demangled_name;
  1307.  
  1308.   if (list->next >= list->list + list->size)
  1309.     {
  1310.       extend_psymbol_list (list,objfile);
  1311.     }
  1312.   psym = list->next++;
  1313.   
  1314.   SYMBOL_NAME (psym) =
  1315.     (char *) obstack_alloc (&objfile->psymbol_obstack, namelength + 1);
  1316.   memcpy (SYMBOL_NAME (psym), name, namelength);
  1317.   SYMBOL_NAME (psym)[namelength] = '\0';
  1318.   SYMBOL_VALUE (psym) = val;
  1319.   SYMBOL_LANGUAGE (psym) = language;
  1320.   PSYMBOL_NAMESPACE (psym) = namespace;
  1321.   PSYMBOL_CLASS (psym) = class;
  1322.   SYMBOL_INIT_DEMANGLED_NAME (psym, &objfile->psymbol_obstack);
  1323. }
  1324.  
  1325. /* Add a symbol with a CORE_ADDR value to a psymtab. */
  1326.  
  1327. void
  1328. add_psymbol_addr_to_list (name, namelength, namespace, class, list, val,
  1329.               language, objfile)
  1330.      char *name;
  1331.      int namelength;
  1332.      enum namespace namespace;
  1333.      enum address_class class;
  1334.      struct psymbol_allocation_list *list;
  1335.      CORE_ADDR val;
  1336.      enum language language;
  1337.      struct objfile *objfile;
  1338. {
  1339.   register struct partial_symbol *psym;
  1340.   register char *demangled_name;
  1341.  
  1342.   if (list->next >= list->list + list->size)
  1343.     {
  1344.       extend_psymbol_list (list,objfile);
  1345.     }
  1346.   psym = list->next++;
  1347.   
  1348.   SYMBOL_NAME (psym) =
  1349.     (char *) obstack_alloc (&objfile->psymbol_obstack, namelength + 1);
  1350.   memcpy (SYMBOL_NAME (psym), name, namelength);
  1351.   SYMBOL_NAME (psym)[namelength] = '\0';
  1352.   SYMBOL_VALUE_ADDRESS (psym) = val;
  1353.   SYMBOL_LANGUAGE (psym) = language;
  1354.   PSYMBOL_NAMESPACE (psym) = namespace;
  1355.   PSYMBOL_CLASS (psym) = class;
  1356.   SYMBOL_INIT_DEMANGLED_NAME (psym, &objfile->psymbol_obstack);
  1357. }
  1358.  
  1359. #endif /* !INLINE_ADD_PSYMBOL */
  1360.  
  1361.  
  1362. void
  1363. _initialize_symfile ()
  1364. {
  1365.  
  1366.   add_com ("symbol-file", class_files, symbol_file_command,
  1367.    "Load symbol table from executable file FILE.\n\
  1368. The `file' command can also load symbol tables, as well as setting the file\n\
  1369. to execute.");
  1370.  
  1371.   add_com ("add-symbol-file", class_files, add_symbol_file_command,
  1372.    "Load the symbols from FILE, assuming FILE has been dynamically loaded.\n\
  1373. The second argument provides the starting address of the file's text.");
  1374.  
  1375.   add_com ("load", class_files, load_command,
  1376.    "Dynamically load FILE into the running program, and record its symbols\n\
  1377. for access from GDB.");
  1378.  
  1379.   add_show_from_set
  1380.     (add_set_cmd ("symbol-reloading", class_support, var_boolean,
  1381.           (char *)&symbol_reloading,
  1382.       "Set dynamic symbol table reloading multiple times in one run.",
  1383.           &setlist),
  1384.      &showlist);
  1385.  
  1386. }
  1387.