* config/sun4os4.mh (XDEPFILES): fork-child.o removed.
[deliverable/binutils-gdb.git] / gdb / buildsym.c
index 90cbbe42f9de8b3eba5dd7f4c10da4826790f2e6..a25190a6168054fd9b1e698bb85e84cf23984ce5 100644 (file)
@@ -388,19 +388,37 @@ start_subfile (name, dirname)
 
   /* Save its name and compilation directory name */
   subfile->name = strdup (name);
-  if (dirname == NULL)
-    {
-      subfile->dirname = NULL;
-    }
-  else
-    {
-      subfile->dirname = strdup (dirname);
-    }
+  subfile->dirname = (dirname == NULL) ? NULL : strdup (dirname);
   
   /* Initialize line-number recording for this subfile.  */
   subfile->line_vector = NULL;
 }
 
+/* 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);
+    }
+}
+
 \f
 /* Handle the N_BINCL and N_EINCL symbol types
    that act like N_SOL for switching source files
@@ -531,7 +549,14 @@ 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.
+
+   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)
@@ -565,7 +590,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 +649,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,7 +693,18 @@ end_symtab (end_addr, sort_pending, sort_linevec, objfile)
            {
              symtab->linetable = NULL;
            }
-         symtab->dirname = subfile->dirname;
+         if (subfile->dirname)
+           {
+             /* Reallocate the dirname on the symbol obstack */
+             symtab->dirname = (char *)
+               obstack_alloc (&objfile -> symbol_obstack,
+                              strlen (subfile -> dirname) + 1);
+             strcpy (symtab->dirname, subfile->dirname);
+           }
+         else
+           {
+             symtab->dirname = NULL;
+           }
          symtab->free_code = free_linetable;
          symtab->free_ptr = NULL;
 
@@ -681,9 +717,17 @@ end_symtab (end_addr, sort_pending, sort_linevec, objfile)
          symtab->nonreloc = TRUE;
 #endif
        }
-      if (subfile->line_vector)
+      if (subfile->name != NULL)
+       {
+         free ((PTR) subfile->name);
+       }
+      if (subfile->dirname != NULL)
+       {
+         free ((PTR) subfile->dirname);
+       }
+      if (subfile->line_vector != NULL)
        {
-         free ((PTR)subfile->line_vector);
+         free ((PTR) subfile->line_vector);
        }
 
       nextsub = subfile->next;
This page took 0.026528 seconds and 4 git commands to generate.