* buildsym.c (start_subfile): Compact dirname initialization.

* buildsym.c (patch_subfile_names):  New function.
	* buildsym.c (end_symtab):  Make copy of dirname on symbol obstack.
	* buildsym.c (end_symtab):  Free all malloc'd subfile fields.
	* buildsym.h (patch_subfile_names):  Add prototype.
	* dbxread.c (process_one_symbol):  Call patch_subfile_names.
This commit is contained in:
Fred Fish
1992-08-06 19:59:46 +00:00
parent 7fd3560a6a
commit 3416d90bd6
4 changed files with 96 additions and 31 deletions

View 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);
}
}
/* Handle the N_BINCL and N_EINCL symbol types
that act like N_SOL for switching source files
@@ -692,9 +710,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->line_vector);
free ((PTR) subfile->name);
}
if (subfile->dirname != NULL)
{
free ((PTR) subfile->dirname);
}
if (subfile->line_vector != NULL)
{
free ((PTR) subfile->line_vector);
}
nextsub = subfile->next;