[PATCH 1/4] Remove some explicit memory management from dwarf2read.c
Simon Marchi
simark@simark.ca
Wed Jan 8 03:44:00 GMT 2020
On 2020-01-07 5:07 p.m., Tom Tromey wrote:
> I noticed a few spots in dwarf2read.c that could be improved by moving
> to unique_xmalloc_ptr or, in one case, std::vector.
>
> gdb/ChangeLog
> 2020-01-07 Tom Tromey <tromey@adacore.com>
>
> * dwarf2read.c (add_partial_symbol): Use unique_xmalloc_ptr.
> (dwarf2_compute_name, open_dwo_file): Likewise.
> (process_enumeration_scope): Use std::vector.
> (guess_partial_die_structure_name): Use unique_xmalloc_ptr.
> (partial_die_info::fixup, dwarf2_start_subfile)
> (guess_full_die_structure_name, dwarf2_name): Likewise.
> (determine_prefix): Update.
> (guess_full_die_structure_name): Make return type const.
>
> Change-Id: I1cb278c608041ef36ef1f77c7e7565c921038d08
Thanks, this LGTM. I noted some suggestions below.
> diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
> index 63d533a4459..9fd2b7715b1 100644
> --- a/gdb/dwarf2read.c
> +++ b/gdb/dwarf2read.c
> @@ -8954,13 +8954,13 @@ add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu)
> CORE_ADDR addr = 0;
> const char *actual_name = NULL;
> CORE_ADDR baseaddr;
> - char *built_actual_name;
>
> baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
>
> - built_actual_name = partial_die_full_name (pdi, cu);
> + gdb::unique_xmalloc_ptr<char> built_actual_name
> + (partial_die_full_name (pdi, cu));
You could make partial_die_full_name return a gdb::unique_xmalloc_ptr while at
it, since this is the sole user. This can then stay an assignment:
gdb::unique_xmalloc_ptr<char> built_actual_name
= partial_die_full_name (pdi, cu);
> @@ -16566,34 +16555,26 @@ process_enumeration_scope (struct die_info *die, struct dwarf2_cu *cu)
> {
> sym = new_symbol (child_die, this_type, cu);
>
> - if ((num_fields % DW_FIELD_ALLOC_CHUNK) == 0)
> - {
> - fields = (struct field *)
> - xrealloc (fields,
> - (num_fields + DW_FIELD_ALLOC_CHUNK)
> - * sizeof (struct field));
> - }
You can actually delete DW_FIELD_ALLOC_CHUNK, defined higher in dwarf2read.c.
Simon
More information about the Gdb-patches
mailing list