From: Tom Tromey Date: Wed, 16 May 2018 20:33:15 +0000 (-0600) Subject: Allocate dwz_file with new X-Git-Url: http://drtracing.org/?a=commitdiff_plain;h=7ff8cb8c51adec9cd1b461f9b670223d01223fef;p=deliverable%2Fbinutils-gdb.git Allocate dwz_file with new This adds a constructor to struct dwz_file and arranges for it to be allocated with "new" and wrapped in a unique_ptr. This cuts down on the amount of manual memory management that must be done. Regression tested by the buildbot. gdb/ChangeLog 2018-05-18 Tom Tromey * dwarf2read.c (struct dwz_file): Add constructor, initializers. : Now a gdb_bfd_ref_ptr. (~dwarf2_per_objfile): Update (dwarf2_get_dwz_file): Use new. * dwarf2read.h (struct dwarf2_per_objfile) : Now a unique_ptr. --- diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 5401089950..3c829df12d 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,12 @@ +2018-05-18 Tom Tromey + + * dwarf2read.c (struct dwz_file): Add constructor, initializers. + : Now a gdb_bfd_ref_ptr. + (~dwarf2_per_objfile): Update + (dwarf2_get_dwz_file): Use new. + * dwarf2read.h (struct dwarf2_per_objfile) : Now a + unique_ptr. + 2018-05-18 Tom Tromey * dwarf2read.h (struct dwarf2_per_objfile) : Now a diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c index dc149012ef..0690785c5e 100644 --- a/gdb/dwarf2read.c +++ b/gdb/dwarf2read.c @@ -845,17 +845,22 @@ struct dwp_file struct dwz_file { + dwz_file (gdb_bfd_ref_ptr &&bfd) + : dwz_bfd (std::move (bfd)) + { + } + /* A dwz file can only contain a few sections. */ - struct dwarf2_section_info abbrev; - struct dwarf2_section_info info; - struct dwarf2_section_info str; - struct dwarf2_section_info line; - struct dwarf2_section_info macro; - struct dwarf2_section_info gdb_index; - struct dwarf2_section_info debug_names; + struct dwarf2_section_info abbrev {}; + struct dwarf2_section_info info {}; + struct dwarf2_section_info str {}; + struct dwarf2_section_info line {}; + struct dwarf2_section_info macro {}; + struct dwarf2_section_info gdb_index {}; + struct dwarf2_section_info debug_names {}; /* The dwz's BFD. */ - bfd *dwz_bfd; + gdb_bfd_ref_ptr dwz_bfd; }; /* Struct used to pass misc. parameters to read_die_and_children, et @@ -2151,9 +2156,6 @@ dwarf2_per_objfile::~dwarf2_per_objfile () if (dwo_files != NULL) free_dwo_files (dwo_files, objfile); - if (dwz_file != NULL && dwz_file->dwz_bfd) - gdb_bfd_unref (dwz_file->dwz_bfd); - /* Everything else should be on the objfile obstack. */ } @@ -2639,13 +2641,12 @@ static struct dwz_file * dwarf2_get_dwz_file (struct dwarf2_per_objfile *dwarf2_per_objfile) { const char *filename; - struct dwz_file *result; bfd_size_type buildid_len_arg; size_t buildid_len; bfd_byte *buildid; if (dwarf2_per_objfile->dwz_file != NULL) - return dwarf2_per_objfile->dwz_file; + return dwarf2_per_objfile->dwz_file.get (); bfd_set_error (bfd_error_no_error); gdb::unique_xmalloc_ptr data @@ -2691,15 +2692,16 @@ dwarf2_get_dwz_file (struct dwarf2_per_objfile *dwarf2_per_objfile) error (_("could not find '.gnu_debugaltlink' file for %s"), objfile_name (dwarf2_per_objfile->objfile)); - result = OBSTACK_ZALLOC (&dwarf2_per_objfile->objfile->objfile_obstack, - struct dwz_file); - result->dwz_bfd = dwz_bfd.release (); + std::unique_ptr result + (new struct dwz_file (std::move (dwz_bfd))); - bfd_map_over_sections (result->dwz_bfd, locate_dwz_sections, result); + bfd_map_over_sections (result->dwz_bfd.get (), locate_dwz_sections, + result.get ()); - gdb_bfd_record_inclusion (dwarf2_per_objfile->objfile->obfd, result->dwz_bfd); - dwarf2_per_objfile->dwz_file = result; - return result; + gdb_bfd_record_inclusion (dwarf2_per_objfile->objfile->obfd, + result->dwz_bfd.get ()); + dwarf2_per_objfile->dwz_file = std::move (result); + return dwarf2_per_objfile->dwz_file.get (); } /* DWARF quick_symbols_functions support. */ diff --git a/gdb/dwarf2read.h b/gdb/dwarf2read.h index 1e0663be16..fbac7171de 100644 --- a/gdb/dwarf2read.h +++ b/gdb/dwarf2read.h @@ -198,7 +198,7 @@ public: /* The shared '.dwz' file, if one exists. This is used when the original data was compressed using 'dwz -m'. */ - struct dwz_file *dwz_file = NULL; + std::unique_ptr dwz_file; /* A flag indicating whether this objfile has a section loaded at a VMA of 0. */