aboutsummaryrefslogtreecommitdiff
path: root/binutils/stabs.c
diff options
context:
space:
mode:
authorAlan Modra <amodra@gmail.com>2023-03-31 13:36:16 +1030
committerAlan Modra <amodra@gmail.com>2023-04-03 07:29:35 +0930
commita6336913332303c45608d77b731bee5c3a3095e0 (patch)
tree242a75f53aeb5eafb0122f70107574ad3c178929 /binutils/stabs.c
parent31991eaaeee55fbf077e5c7ed1bc5deece050933 (diff)
downloadgdb-a6336913332303c45608d77b731bee5c3a3095e0.zip
gdb-a6336913332303c45608d77b731bee5c3a3095e0.tar.gz
gdb-a6336913332303c45608d77b731bee5c3a3095e0.tar.bz2
rddbg.c stabs FIXMEs
This should sort out some very old FIXMEs in code handling stabs debug info. Necessary if we are to fuss over freeing up memory before objdump and objcopy exit. It is of course better from a user viewpoint to *not* free memory, which takes some time, and leave that to process exit. The only reason to do so is that having many memory leaks in binutils/ code tends to hide leaks in bfd/ or opcodes/, which we should care about. * budbg.h (parse_stab): Update prototype. * debug.h (debug_start_source): Update prototype. * debug.c (debug_start_source): Add name_used. Set if stashed. * rddbg.c (read_symbol_stabs_debugging_info): Always malloc stab string passed to parse_stab. Free stab string when unreferenced. (read_section_stabs_debugging_info): Likewise, and strings section contents. * stabs.c (parse_stab): Add string_used param. Set if string stashed. Pass to debug_start_source. Realloc file_types array rather that using malloc. Clarify comment about debug_make_indirect_type.
Diffstat (limited to 'binutils/stabs.c')
-rw-r--r--binutils/stabs.c25
1 files changed, 17 insertions, 8 deletions
diff --git a/binutils/stabs.c b/binutils/stabs.c
index 85eebeb..f5a76dd 100644
--- a/binutils/stabs.c
+++ b/binutils/stabs.c
@@ -422,11 +422,12 @@ finish_stab (void *dhandle, void *handle)
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
@@ -447,11 +448,11 @@ parse_stab (void *dhandle, void *handle, int type, int desc, bfd_vma value,
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;
@@ -566,21 +567,29 @@ parse_stab (void *dhandle, void *handle, int type, int desc, bfd_vma value,
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: