From patchwork Sat Jan 6 00:26:19 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 25240 Received: (qmail 5300 invoked by alias); 6 Jan 2018 00:26:29 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 5135 invoked by uid 89); 6 Jan 2018 00:26:28 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.7 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=sk:scoped_, 7247 X-HELO: gateway36.websitewelcome.com Received: from gateway36.websitewelcome.com (HELO gateway36.websitewelcome.com) (192.185.185.36) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sat, 06 Jan 2018 00:26:26 +0000 Received: from cm17.websitewelcome.com (cm17.websitewelcome.com [100.42.49.20]) by gateway36.websitewelcome.com (Postfix) with ESMTP id 0E793403D8656 for ; Fri, 5 Jan 2018 18:26:25 -0600 (CST) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id XcJdeeiZwuMnyXcJdeQv5u; Fri, 05 Jan 2018 18:26:25 -0600 Received: from 71-218-90-63.hlrn.qwest.net ([71.218.90.63]:39986 helo=pokyo.Home) by box5379.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.89) (envelope-from ) id 1eXcJc-0035k1-RZ; Fri, 05 Jan 2018 18:26:24 -0600 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [RFA 4/6] Change dwarf2_cu::method_info to be a std::vector Date: Fri, 5 Jan 2018 17:26:19 -0700 Message-Id: <20180106002621.21099-5-tom@tromey.com> In-Reply-To: <20180106002621.21099-1-tom@tromey.com> References: <20180106002621.21099-1-tom@tromey.com> X-BWhitelist: no X-Source-L: No X-Exim-ID: 1eXcJc-0035k1-RZ X-Source-Sender: 71-218-90-63.hlrn.qwest.net (pokyo.Home) [71.218.90.63]:39986 X-Source-Auth: tom+tromey.com X-Email-Count: 5 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes This changes the type of dwarf2_cu::method_info and fixes up the uses. In order to remove cleanups from process_full_comp_unit and process_full_type_unit, psymtab_include_file_name also had to be changed to avoid leaving dangling cleanups. 2018-01-05 Tom Tromey * dwarf2read.c (delayed_method_info): Remove typedef. (dwarf2_cu::method_info): Now a std::vector. (add_to_method_list): Update. (free_delayed_list): Remove. (compute_delayed_physnames): Update. (process_full_comp_unit, process_full_type_unit): Clear the method list. Remove cleanups. (psymtab_include_file_name): Add name_holder parameter. Use unique_xmalloc_ptr. (dwarf_decode_lines): Update. --- gdb/ChangeLog | 13 ++++++++ gdb/dwarf2read.c | 93 ++++++++++++++++++++++---------------------------------- 2 files changed, 49 insertions(+), 57 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 04000eacae..0c878d9aba 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,18 @@ 2018-01-05 Tom Tromey + * dwarf2read.c (delayed_method_info): Remove typedef. + (dwarf2_cu::method_info): Now a std::vector. + (add_to_method_list): Update. + (free_delayed_list): Remove. + (compute_delayed_physnames): Update. + (process_full_comp_unit, process_full_type_unit): Clear the method + list. Remove cleanups. + (psymtab_include_file_name): Add name_holder parameter. Use + unique_xmalloc_ptr. + (dwarf_decode_lines): Update. + +2018-01-05 Tom Tromey + * dwarf2read.c (struct dwarf2_cu): Add constructor, destructor. : Declare method. (~auto_free_abbrev_table): Update. diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c index 400080b208..998c8479ea 100644 --- a/gdb/dwarf2read.c +++ b/gdb/dwarf2read.c @@ -633,9 +633,6 @@ struct delayed_method_info struct die_info *die; }; -typedef struct delayed_method_info delayed_method_info; -DEF_VEC_O (delayed_method_info); - /* Internal state when decoding a particular compilation unit. */ struct dwarf2_cu { @@ -724,7 +721,7 @@ struct dwarf2_cu /* A list of methods which need to have physnames computed after all type information has been read. */ - VEC (delayed_method_info) *method_list = nullptr; + std::vector method_list; /* To be copied to symtab->call_site_htab. */ htab_t call_site_htab = nullptr; @@ -10051,20 +10048,7 @@ add_to_method_list (struct type *type, int fnfield_index, int index, mi.index = index; mi.name = name; mi.die = die; - VEC_safe_push (delayed_method_info, cu->method_list, &mi); -} - -/* A cleanup for freeing the delayed method list. */ - -static void -free_delayed_list (void *ptr) -{ - struct dwarf2_cu *cu = (struct dwarf2_cu *) ptr; - if (cu->method_list != NULL) - { - VEC_free (delayed_method_info, cu->method_list); - cu->method_list = NULL; - } + cu->method_list.push_back (mi); } /* Check whether [PHYSNAME, PHYSNAME+LEN) ends with a modifier like @@ -10093,21 +10077,18 @@ check_modifier (const char *physname, size_t &len, const char (&mod)[N]) static void compute_delayed_physnames (struct dwarf2_cu *cu) { - int i; - struct delayed_method_info *mi; - /* Only C++ delays computing physnames. */ - if (VEC_empty (delayed_method_info, cu->method_list)) + if (cu->method_list.empty ()) return; gdb_assert (cu->language == language_cplus); - for (i = 0; VEC_iterate (delayed_method_info, cu->method_list, i, mi) ; ++i) + for (struct delayed_method_info &mi : cu->method_list) { const char *physname; struct fn_fieldlist *fn_flp - = &TYPE_FN_FIELDLIST (mi->type, mi->fnfield_index); - physname = dwarf2_physname (mi->name, mi->die, cu); - TYPE_FN_FIELD_PHYSNAME (fn_flp->fn_fields, mi->index) + = &TYPE_FN_FIELDLIST (mi.type, mi.fnfield_index); + physname = dwarf2_physname (mi.name, mi.die, cu); + TYPE_FN_FIELD_PHYSNAME (fn_flp->fn_fields, mi.index) = physname ? physname : ""; /* Since there's no tag to indicate whether a method is a @@ -10122,14 +10103,17 @@ compute_delayed_physnames (struct dwarf2_cu *cu) if (physname[len] == ')') /* shortcut */ break; else if (check_modifier (physname, len, " const")) - TYPE_FN_FIELD_CONST (fn_flp->fn_fields, mi->index) = 1; + TYPE_FN_FIELD_CONST (fn_flp->fn_fields, mi.index) = 1; else if (check_modifier (physname, len, " volatile")) - TYPE_FN_FIELD_VOLATILE (fn_flp->fn_fields, mi->index) = 1; + TYPE_FN_FIELD_VOLATILE (fn_flp->fn_fields, mi.index) = 1; else break; } } } + + /* The list is no longer needed. */ + cu->method_list.clear (); } /* Go objects should be embedded in a DW_TAG_module DIE, @@ -10364,7 +10348,6 @@ process_full_comp_unit (struct dwarf2_per_cu_data *per_cu, struct gdbarch *gdbarch = get_objfile_arch (objfile); CORE_ADDR lowpc, highpc; struct compunit_symtab *cust; - struct cleanup *delayed_list_cleanup; CORE_ADDR baseaddr; struct block *static_block; CORE_ADDR addr; @@ -10373,7 +10356,9 @@ process_full_comp_unit (struct dwarf2_per_cu_data *per_cu, buildsym_init (); scoped_free_pendings free_pending; - delayed_list_cleanup = make_cleanup (free_delayed_list, cu); + + /* Clear the list here in case something was left over. */ + cu->method_list.clear (); cu->list_in_scope = &file_symbols; @@ -10391,7 +10376,6 @@ process_full_comp_unit (struct dwarf2_per_cu_data *per_cu, should be complete, and it should now be safe to compute all of the physnames. */ compute_delayed_physnames (cu); - do_cleanups (delayed_list_cleanup); /* Some compilers don't define a DW_AT_high_pc attribute for the compilation unit. If the DW_AT_high_pc is missing, synthesize @@ -10466,7 +10450,6 @@ process_full_type_unit (struct dwarf2_per_cu_data *per_cu, struct dwarf2_cu *cu = per_cu->cu; struct objfile *objfile = per_cu->objfile; struct compunit_symtab *cust; - struct cleanup *delayed_list_cleanup; struct signatured_type *sig_type; gdb_assert (per_cu->is_debug_types); @@ -10474,7 +10457,9 @@ process_full_type_unit (struct dwarf2_per_cu_data *per_cu, buildsym_init (); scoped_free_pendings free_pending; - delayed_list_cleanup = make_cleanup (free_delayed_list, cu); + + /* Clear the list here in case something was left over. */ + cu->method_list.clear (); cu->list_in_scope = &file_symbols; @@ -10492,7 +10477,6 @@ process_full_type_unit (struct dwarf2_per_cu_data *per_cu, should be complete, and it should now be safe to compute all of the physnames. */ compute_delayed_physnames (cu); - do_cleanups (delayed_list_cleanup); /* TUs share symbol tables. If this is the first TU to use this symtab, complete the construction @@ -20219,25 +20203,24 @@ dwarf_decode_line_header (sect_offset sect_off, struct dwarf2_cu *cu) Return the file name of the psymtab for included file FILE_INDEX in line header LH of PST. COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown. - If space for the result is malloc'd, it will be freed by a cleanup. - Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. - - The function creates dangling cleanup registration. */ + If space for the result is malloc'd, *NAME_HOLDER will be set. + Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */ static const char * psymtab_include_file_name (const struct line_header *lh, int file_index, const struct partial_symtab *pst, - const char *comp_dir) + const char *comp_dir, + gdb::unique_xmalloc_ptr *name_holder) { const file_entry &fe = lh->file_names[file_index]; const char *include_name = fe.name; const char *include_name_to_compare = include_name; const char *pst_filename; - char *copied_name = NULL; int file_is_pst; const char *dir_name = fe.include_dir (lh); + gdb::unique_xmalloc_ptr hold_compare; if (!IS_ABSOLUTE_PATH (include_name) && (dir_name != NULL || comp_dir != NULL)) { @@ -20264,36 +20247,30 @@ psymtab_include_file_name (const struct line_header *lh, int file_index, if (dir_name != NULL) { - char *tem = concat (dir_name, SLASH_STRING, - include_name, (char *)NULL); - - make_cleanup (xfree, tem); - include_name = tem; + name_holder->reset (concat (dir_name, SLASH_STRING, + include_name, (char *) NULL)); + include_name = name_holder->get (); include_name_to_compare = include_name; } if (!IS_ABSOLUTE_PATH (include_name) && comp_dir != NULL) { - char *tem = concat (comp_dir, SLASH_STRING, - include_name, (char *)NULL); - - make_cleanup (xfree, tem); - include_name_to_compare = tem; + hold_compare.reset (concat (comp_dir, SLASH_STRING, + include_name, (char *) NULL)); + include_name_to_compare = hold_compare.get (); } } pst_filename = pst->filename; + gdb::unique_xmalloc_ptr copied_name; if (!IS_ABSOLUTE_PATH (pst_filename) && pst->dirname != NULL) { - copied_name = concat (pst->dirname, SLASH_STRING, - pst_filename, (char *)NULL); - pst_filename = copied_name; + copied_name.reset (concat (pst->dirname, SLASH_STRING, + pst_filename, (char *) NULL)); + pst_filename = copied_name.get (); } file_is_pst = FILENAME_CMP (include_name_to_compare, pst_filename) == 0; - if (copied_name != NULL) - xfree (copied_name); - if (file_is_pst) return NULL; return include_name; @@ -20951,8 +20928,10 @@ dwarf_decode_lines (struct line_header *lh, const char *comp_dir, for (file_index = 0; file_index < lh->file_names.size (); file_index++) if (lh->file_names[file_index].included_p == 1) { + gdb::unique_xmalloc_ptr name_holder; const char *include_name = - psymtab_include_file_name (lh, file_index, pst, comp_dir); + psymtab_include_file_name (lh, file_index, pst, comp_dir, + &name_holder); if (include_name != NULL) dwarf2_create_include_psymtab (include_name, pst, objfile); }