extern bool finish_stab (void *, void *);
extern bool parse_stab
- (void *, void *, int, int, bfd_vma, const char *);
+ (void *, void *, int, int, bfd_vma, const char *, bool *);
extern bool write_stabs_in_sections_debugging_info
(bfd *, void *, bfd_byte **, bfd_size_type *, bfd_byte **, bfd_size_type *);
include files in a single compilation unit. */
bool
-debug_start_source (void *handle, const char *name)
+debug_start_source (void *handle, const char *name, bool *name_used)
{
struct debug_handle *info = (struct debug_handle *) handle;
struct debug_file *f, **pf;
memset (f, 0, sizeof *f);
f->filename = name;
+ *name_used = true;
for (pf = &info->current_file->next;
*pf != NULL;
/* Change source files to the given file name. This is used for
include files in a single compilation unit. */
-extern bool debug_start_source (void *, const char *);
+extern bool debug_start_source (void *, const char *, bool *);
/* Record a function definition. This implicitly starts a function
block. The debug_type argument is the type of the return value.
{
size_t len;
char *f, *s;
+ bool f_used;
if (stroff + strx >= strsize)
{
free (f);
f = s;
}
+ if (!f)
+ f = xstrdup (s);
save_stab (type, desc, value, s);
- if (! parse_stab (dhandle, shandle, type, desc, value, s))
+ if (! parse_stab (dhandle, shandle, type, desc, value,
+ f, &f_used))
{
stab_context ();
free_saved_stabs ();
return false;
}
- /* Don't free f, since I think the stabs code
- expects strings to hang around. This should be
- straightened out. FIXME. */
+ if (!f_used)
+ free (f);
}
}
free_saved_stabs ();
free (stabs);
-
- /* Don't free strings, since I think the stabs code expects
- the strings to hang around. This should be straightened
- out. FIXME. */
+ free (strings);
}
}
{
const char *s;
char *f;
+ bool f_used;
if (shandle == NULL)
{
f = n;
s = n;
}
+ if (!f)
+ f = xstrdup (s);
save_stab (i.stab_type, i.stab_desc, i.value, s);
if (! parse_stab (dhandle, shandle, i.stab_type, i.stab_desc,
- i.value, s))
+ i.value, f, &f_used))
{
stab_context ();
+ free (f);
free_saved_stabs ();
return false;
}
- /* Don't free f, since I think the stabs code expects
- strings to hang around. This should be straightened out.
- FIXME. */
+ if (!f_used)
+ free (f);
}
}
bool
parse_stab (void *dhandle, void *handle, int type, int desc, bfd_vma value,
- const char *string)
+ const char *string, bool *string_used)
{
const char * string_end;
struct stab_handle *info = (struct stab_handle *) handle;
+ *string_used = false;
/* gcc will emit two N_SO strings per compilation unit, one for the
directory name and one for the file name. We just collect N_SO
strings as we see them, and start the new compilation unit when
info->file_start_offset = info->so_value;
/* We need to reset the mapping from type numbers to types. We
- can't free the old mapping, because of the use of
- debug_make_indirect_type. */
+ can only free the file_types array, not the stab_types
+ list entries due to the use of debug_make_indirect_type. */
info->files = 1;
info->file_types = ((struct stab_types **)
- xmalloc (sizeof *info->file_types));
+ xrealloc (info->file_types, sizeof *info->file_types));
info->file_types[0] = NULL;
info->so_string = NULL;
case N_SOL:
/* Start an include file. */
- if (! debug_start_source (dhandle, string))
+ if (! debug_start_source (dhandle, string, string_used))
return false;
break;
case N_BINCL:
/* Start an include file which may be replaced. */
+ *string_used = true;
push_bincl (info, string, value);
- if (! debug_start_source (dhandle, string))
+ if (! debug_start_source (dhandle, string, string_used))
return false;
break;
case N_EINCL:
/* End an N_BINCL include. */
- if (! debug_start_source (dhandle, pop_bincl (info)))
- return false;
+ string = pop_bincl (info);
+ if (! debug_start_source (dhandle, string, string_used))
+ {
+ free ((char *) string);
+ return false;
+ }
+ if (!*string_used)
+ free ((char *) string);
+ *string_used = false;
break;
case N_EXCL: