* Rename remote-es1800.c to remote-es.c
[deliverable/binutils-gdb.git] / gdb / buildsym.c
index 208d207760725dac13525c7e3bdd450f4b87b5ed..6c8c807062f447513dd65026282061179cb1dc1a 100644 (file)
@@ -31,6 +31,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
 #include "symtab.h"
 #include "symfile.h"           /* Needed for "struct complaint" */
 #include "objfiles.h"
+#include "complaints.h"
 #include <string.h>
 
 /* Ask buildsym.h to define the vars it normally declares `extern'.  */
@@ -256,11 +257,12 @@ finish_block (symbol, listhead, old_blocks, start, end, objfile)
            {
              if (symbol)
                {
-                 complain (&innerblock_complaint, SYMBOL_NAME (symbol));
+                 complain (&innerblock_complaint,
+                           SYMBOL_SOURCE_NAME (symbol));
                }
              else
                {
-                 complain (&innerblock_anon_complaint, 0);
+                 complain (&innerblock_anon_complaint);
                }
              BLOCK_START (pblock->block) = BLOCK_START (block);
              BLOCK_END   (pblock->block) = BLOCK_END   (block);
@@ -345,7 +347,7 @@ make_blockvector (objfile)
              > BLOCK_START(BLOCKVECTOR_BLOCK (blockvector, i)))
            {
              complain (&blockvector_complaint, 
-                       (char *) BLOCK_START(BLOCKVECTOR_BLOCK (blockvector, i)));
+                       BLOCK_START(BLOCKVECTOR_BLOCK (blockvector, i)));
            }
        }
     }
@@ -370,7 +372,7 @@ start_subfile (name, dirname)
 
   for (subfile = subfiles; subfile; subfile = subfile->next)
     {
-      if (!strcmp (subfile->name, name))
+      if (STREQ (subfile->name, name))
        {
          current_subfile = subfile;
          return;
@@ -387,18 +389,72 @@ start_subfile (name, dirname)
   current_subfile = subfile;
 
   /* Save its name and compilation directory name */
-  subfile->name = strdup (name);
-  if (dirname == NULL)
-    {
-      subfile->dirname = NULL;
-    }
-  else
-    {
-      subfile->dirname = strdup (dirname);
-    }
+  subfile->name = (name == NULL)? NULL : strdup (name);
+  subfile->dirname = (dirname == NULL) ? NULL : strdup (dirname);
   
   /* Initialize line-number recording for this subfile.  */
   subfile->line_vector = NULL;
+
+  /* Default the source language to whatever can be deduced from
+     the filename.  If nothing can be deduced (such as for a C/C++
+     include file with a ".h" extension), then inherit whatever
+     language the previous subfile had.  This kludgery is necessary
+     because there is no standard way in some object formats to
+     record the source language.  Also, when symtabs are allocated
+     we try to deduce a language then as well, but it is too late
+     for us to use that information while reading symbols, since
+     symtabs aren't allocated until after all the symbols have
+     been processed for a given source file. */
+
+  subfile->language = deduce_language_from_filename (subfile->name);
+  if (subfile->language == language_unknown &&
+      subfile->next != NULL)
+    {
+      subfile->language = subfile->next->language;
+    }
+}
+
+/* For stabs readers, the first N_SO symbol is assumed to be the source
+   file name, and the subfile struct is initialized using that assumption.
+   If another N_SO symbol is later seen, immediately following the first
+   one, then the first one is assumed to be the directory name and the
+   second one is really the source file name.
+
+   So we have to patch up the subfile struct by moving the old name value to
+   dirname and remembering the new name.  Some sanity checking is performed
+   to ensure that the state of the subfile struct is reasonable and that the
+   old name we are assuming to be a directory name actually is (by checking
+   for a trailing '/'). */
+
+void
+patch_subfile_names (subfile, name)
+     struct subfile *subfile;
+     char *name;
+{
+  if (subfile != NULL && subfile->dirname == NULL && subfile->name != NULL
+      && subfile->name[strlen(subfile->name)-1] == '/')
+    {
+      subfile->dirname = subfile->name;
+      subfile->name = strdup (name);
+
+      /* Default the source language to whatever can be deduced from
+        the filename.  If nothing can be deduced (such as for a C/C++
+        include file with a ".h" extension), then inherit whatever
+        language the previous subfile had.  This kludgery is necessary
+        because there is no standard way in some object formats to
+        record the source language.  Also, when symtabs are allocated
+        we try to deduce a language then as well, but it is too late
+        for us to use that information while reading symbols, since
+        symtabs aren't allocated until after all the symbols have
+        been processed for a given source file. */
+
+      subfile->language = deduce_language_from_filename (subfile->name);
+      if (subfile->language == language_unknown &&
+         subfile->next != NULL)
+       {
+         subfile->language = subfile->next->language;
+       }
+    }
 }
 
 \f
@@ -531,14 +587,24 @@ start_symtab (name, dirname, start_addr)
    (creating struct block's for them), then make the struct symtab
    for that file and put it in the list of all such.
 
-   END_ADDR is the address of the end of the file's text.  */
+   END_ADDR is the address of the end of the file's text.
+   SECTION is the section number (in objfile->section_offsets) of
+   the blockvector and linetable.
+
+   Note that it is possible for end_symtab() to return NULL.  In particular,
+   for the DWARF case at least, it will return NULL when it finds a
+   compilation unit that has exactly one DIE, a TAG_compile_unit DIE.  This
+   can happen when we link in an object file that was compiled from an empty
+   source file.  Returning NULL is probably not the correct thing to do,
+   because then gdb will never know about this empty file (FIXME). */
 
 struct symtab *
-end_symtab (end_addr, sort_pending, sort_linevec, objfile)
+end_symtab (end_addr, sort_pending, sort_linevec, objfile, section)
      CORE_ADDR end_addr;
      int sort_pending;
      int sort_linevec;
      struct objfile *objfile;
+     int section;
 {
   register struct symtab *symtab;
   register struct blockvector *blockvector;
@@ -565,7 +631,7 @@ end_symtab (end_addr, sort_pending, sort_linevec, objfile)
        }
     }
 
-  /* It is unfortunate that in aixcoff, pending blocks might not be ordered
+  /* It is unfortunate that in xcoff, pending blocks might not be ordered
      in this stage. Especially, blocks for static functions will show up at
      the end.  We need to sort them, so tools like `find_pc_function' and
      `find_pc_block' can work reliably. */
@@ -624,7 +690,7 @@ end_symtab (end_addr, sort_pending, sort_linevec, objfile)
     }
 
 #ifdef PROCESS_LINENUMBER_HOOK
-  PROCESS_LINENUMBER_HOOK ();                  /* Needed for aixcoff. */
+  PROCESS_LINENUMBER_HOOK ();                  /* Needed for xcoff. */
 #endif
 
   /* Now create the symtab objects proper, one for each subfile.  */
@@ -668,6 +734,7 @@ end_symtab (end_addr, sort_pending, sort_linevec, objfile)
            {
              symtab->linetable = NULL;
            }
+         symtab->block_line_section = section;
          if (subfile->dirname)
            {
              /* Reallocate the dirname on the symbol obstack */
@@ -683,32 +750,41 @@ end_symtab (end_addr, sort_pending, sort_linevec, objfile)
          symtab->free_code = free_linetable;
          symtab->free_ptr = NULL;
 
-#ifdef IBM6000_TARGET
-         /* In case we need to duplicate symbol tables (to represent include
-            files), and in case our system needs relocation, we want to
-            relocate the main symbol table node only (for the main file,
-            not for the include files). */
+         /* Use whatever language we have been using for this subfile,
+            not the one that was deduced in allocate_symtab from the
+            filename.  We already did our own deducing when we created
+            the subfile, and we may have altered our opinion of what
+            language it is from things we found in the symbols. */
+         symtab->language = subfile->language;
 
-         symtab->nonreloc = TRUE;
-#endif
+         /* All symtabs for the main file and the subfiles share a
+            blockvector, so we need to clear primary for everything but
+            the main file.  */
+
+         symtab->primary = 0;
+       }
+      if (subfile->name != NULL)
+       {
+         free ((PTR) subfile->name);
        }
-      if (subfile->line_vector)
+      if (subfile->dirname != NULL)
        {
-         free ((PTR)subfile->line_vector);
+         free ((PTR) subfile->dirname);
+       }
+      if (subfile->line_vector != NULL)
+       {
+         free ((PTR) subfile->line_vector);
        }
 
       nextsub = subfile->next;
       free ((PTR)subfile);
     }
 
-#ifdef IBM6000_TARGET
-  /* all include symbol tables are non-relocatable, except the main source
-     file's. */
+  /* Set this for the main source file.  */
   if (symtab)
     {
-      symtab->nonreloc = FALSE;
+      symtab->primary = 1;
     }
-#endif
 
   last_source_file = NULL;
   current_subfile = NULL;
This page took 0.025727 seconds and 4 git commands to generate.