From patchwork Mon Oct 7 21:54:35 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 34860 Received: (qmail 62877 invoked by alias); 7 Oct 2019 21:54:44 -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 62869 invoked by uid 89); 7 Oct 2019 21:54:43 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.1 spammy=pod, xfree, POD, cust X-HELO: mail-wr1-f44.google.com Received: from mail-wr1-f44.google.com (HELO mail-wr1-f44.google.com) (209.85.221.44) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 07 Oct 2019 21:54:41 +0000 Received: by mail-wr1-f44.google.com with SMTP id j11so11234148wrp.1 for ; Mon, 07 Oct 2019 14:54:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; h=from:to:cc:subject:date:message-id; bh=Wv2rAMzy34FTrCOyOQ4XPhKSTUZEZKzJH3nsPmcUi4c=; b=Fxt9BG9AVIUzIuY4VhNJ97gYdgmb6i+hQGu2aRfNAaLFWKRoqyG92ucoV50HuZMBpR cfUl2KEz0+eixCz4FqHjV5qopY6VyklSBgNTToZ3Vbe11tASzNUE5Xv5mqeJVtupY+h4 sYnE6dPs3aJSivpEonMHFnaeIfAp3FkIls1YLahJ8hNCPFAGYBZAzvNBlsuyfJbm20JC mCczaUErPkAXsQXF5xL6etabAlVaN/sXoid3XarSU+hzSG16ftv8A87wrEoGP68OWi6m lc70jH961PTCbrYbtEsKClYBWd96utwMl3XZUTrk2q5A0kh+XqO6PoHpnpFDOpp88SFb cwew== Return-Path: Received: from localhost ([2a00:23c5:3e8d:6c00:9cd0:87cb:29bd:5b8f]) by smtp.gmail.com with ESMTPSA id b186sm1474437wmd.16.2019.10.07.14.54.38 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 07 Oct 2019 14:54:38 -0700 (PDT) From: Andrew Burgess To: gdb-patches Cc: Andrew Burgess Subject: [PATCH] gdb: Remove use of VEC from dwarf2read.c Date: Mon, 7 Oct 2019 22:54:35 +0100 Message-Id: <20191007215435.3328-1-andrew.burgess@embecosm.com> X-IsSubscribed: yes This removes a use of VEC from GDB, from dwarf2read.c. This removal is not very clean, and would probably benefit from additional refactoring in the future. The problem here is that the VEC is contained within struct dwarf2_per_cu_data, which is treated as POD in dwarf2read.c. As such it is actually a VEC pointer. When converting this to a std::vector in an ideal world we would not use a std::vector pointer, and use the std::vector directly. Sadly, to do that would require some rewriting in dwarf2read.c - my concern would be introducing bugs during this rewrite. If we move to a std::vector pointer then we need to take care to handle the case where the pointer is null. The old VEC library would handle null for us, making the VEC interface very clean. With std::vector we need to handle the null pointer case ourselves. The achieve this then I've added a small number of function that wrap up access to the std::vector, hopefully hiding the null pointer management. The final ugliness with this conversion is that, ideally, when wrapping a data member behind an interface I would make the data member private, however, treating the structure as POD once again prevents this, so we are left with the data member being public, but access (ideally) being through the published interface functions. There should be no user visible changes after this commit. gdb/ChangeLog: * gdb/dwarf2read.c (dwarf2_per_objfile::~dwarf2_per_objfile): Update for new std::vector based implementation. (process_psymtab_comp_unit_reader): Likewise. (scan_partial_symbols): Likewise. (recursively_compute_inclusions): Likewise. (compute_compunit_symtab_includes): Likewise. (process_imported_unit_die): Likewise. (queue_and_load_dwo_tu): Likewise. (follow_die_sig_1): Likewise. * gdb/dwarf2read.h: Remove DEF_VEC_P. (typedef dwarf2_per_cu_ptr): Remove. (struct dwarf2_per_cu_data) : New function. (struct dwarf2_per_cu_data) : New function. (struct dwarf2_per_cu_data) : New function. (struct dwarf2_per_cu_data) : New function. (struct dwarf2_per_cu_data) : Change to std::vector. --- gdb/ChangeLog | 21 +++++++++++++++++++ gdb/dwarf2read.c | 61 ++++++++++++++++++++++---------------------------------- gdb/dwarf2read.h | 44 +++++++++++++++++++++++++++++++++++----- 3 files changed, 84 insertions(+), 42 deletions(-) diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c index ee9df34ed27..3639a1f133c 100644 --- a/gdb/dwarf2read.c +++ b/gdb/dwarf2read.c @@ -2164,10 +2164,10 @@ dwarf2_per_objfile::~dwarf2_per_objfile () htab_delete (line_header_hash); for (dwarf2_per_cu_data *per_cu : all_comp_units) - VEC_free (dwarf2_per_cu_ptr, per_cu->imported_symtabs); + per_cu->imported_symtabs_free (); for (signatured_type *sig_type : all_type_units) - VEC_free (dwarf2_per_cu_ptr, sig_type->per_cu.imported_symtabs); + sig_type->per_cu.imported_symtabs_free (); /* Everything else should be on the objfile obstack. */ } @@ -8092,24 +8092,23 @@ process_psymtab_comp_unit_reader (const struct die_reader_specs *reader, end_psymtab_common (objfile, pst); - if (!VEC_empty (dwarf2_per_cu_ptr, cu->per_cu->imported_symtabs)) + if (!cu->per_cu->imported_symtabs_empty ()) { int i; - int len = VEC_length (dwarf2_per_cu_ptr, cu->per_cu->imported_symtabs); - struct dwarf2_per_cu_data *iter; + int len = cu->per_cu->imported_symtabs_size (); /* Fill in 'dependencies' here; we fill in 'users' in a post-pass. */ pst->number_of_dependencies = len; pst->dependencies = objfile->partial_symtabs->allocate_dependencies (len); - for (i = 0; - VEC_iterate (dwarf2_per_cu_ptr, cu->per_cu->imported_symtabs, - i, iter); - ++i) - pst->dependencies[i] = iter->v.psymtab; + for (i = 0; i < len; ++i) + { + pst->dependencies[i] + = cu->per_cu->imported_symtabs->at (i)->v.psymtab; + } - VEC_free (dwarf2_per_cu_ptr, cu->per_cu->imported_symtabs); + cu->per_cu->imported_symtabs_free (); } /* Get the list of files included in the current compilation unit, @@ -8739,8 +8738,7 @@ scan_partial_symbols (struct partial_die_info *first_die, CORE_ADDR *lowpc, if (per_cu->v.psymtab == NULL) process_psymtab_comp_unit (per_cu, 1, cu->language); - VEC_safe_push (dwarf2_per_cu_ptr, - cu->per_cu->imported_symtabs, per_cu); + cu->per_cu->imported_symtabs_push (per_cu); } break; case DW_TAG_imported_declaration: @@ -10256,9 +10254,7 @@ recursively_compute_inclusions (std::vector *result, struct compunit_symtab *immediate_parent) { void **slot; - int ix; struct compunit_symtab *cust; - struct dwarf2_per_cu_data *iter; slot = htab_find_slot (all_children, per_cu, INSERT); if (*slot != NULL) @@ -10293,13 +10289,12 @@ recursively_compute_inclusions (std::vector *result, } } - for (ix = 0; - VEC_iterate (dwarf2_per_cu_ptr, per_cu->imported_symtabs, ix, iter); - ++ix) - { - recursively_compute_inclusions (result, all_children, - all_type_symtabs, iter, cust); - } + if (!per_cu->imported_symtabs_empty ()) + for (dwarf2_per_cu_data *ptr : *per_cu->imported_symtabs) + { + recursively_compute_inclusions (result, all_children, + all_type_symtabs, ptr, cust); + } } /* Compute the compunit_symtab 'includes' fields for the compunit_symtab of @@ -10310,10 +10305,9 @@ compute_compunit_symtab_includes (struct dwarf2_per_cu_data *per_cu) { gdb_assert (! per_cu->is_debug_types); - if (!VEC_empty (dwarf2_per_cu_ptr, per_cu->imported_symtabs)) + if (!per_cu->imported_symtabs_empty ()) { - int ix, len; - struct dwarf2_per_cu_data *per_cu_iter; + int len; std::vector result_symtabs; htab_t all_children, all_type_symtabs; struct compunit_symtab *cust = get_compunit_symtab (per_cu); @@ -10327,14 +10321,10 @@ compute_compunit_symtab_includes (struct dwarf2_per_cu_data *per_cu) all_type_symtabs = htab_create_alloc (1, htab_hash_pointer, htab_eq_pointer, NULL, xcalloc, xfree); - for (ix = 0; - VEC_iterate (dwarf2_per_cu_ptr, per_cu->imported_symtabs, - ix, per_cu_iter); - ++ix) + for (dwarf2_per_cu_data *ptr : *per_cu->imported_symtabs) { recursively_compute_inclusions (&result_symtabs, all_children, - all_type_symtabs, per_cu_iter, - cust); + all_type_symtabs, ptr, cust); } /* Now we have a transitive closure of all the included symtabs. */ @@ -10578,8 +10568,7 @@ process_imported_unit_die (struct die_info *die, struct dwarf2_cu *cu) if (maybe_queue_comp_unit (cu, per_cu, cu->language)) load_full_comp_unit (per_cu, false, cu->language); - VEC_safe_push (dwarf2_per_cu_ptr, cu->per_cu->imported_symtabs, - per_cu); + cu->per_cu->imported_symtabs_push (per_cu); } } @@ -13511,7 +13500,7 @@ queue_and_load_dwo_tu (void **slot, void *info) while processing PER_CU. */ if (maybe_queue_comp_unit (NULL, sig_cu, per_cu->cu->language)) load_full_type_unit (sig_cu); - VEC_safe_push (dwarf2_per_cu_ptr, per_cu->imported_symtabs, sig_cu); + per_cu->imported_symtabs_push (sig_cu); } return 1; @@ -23678,9 +23667,7 @@ follow_die_sig_1 (struct die_info *src_die, struct signatured_type *sig_type, if (dwarf2_per_objfile->index_table != NULL && dwarf2_per_objfile->index_table->version <= 7) { - VEC_safe_push (dwarf2_per_cu_ptr, - (*ref_cu)->per_cu->imported_symtabs, - sig_cu->per_cu); + (*ref_cu)->per_cu->imported_symtabs_push (sig_cu->per_cu); } *ref_cu = sig_cu; diff --git a/gdb/dwarf2read.h b/gdb/dwarf2read.h index a737168b629..53fc7f4d9be 100644 --- a/gdb/dwarf2read.h +++ b/gdb/dwarf2read.h @@ -30,9 +30,6 @@ extern struct cmd_list_element *set_dwarf_cmdlist; extern struct cmd_list_element *show_dwarf_cmdlist; -typedef struct dwarf2_per_cu_data *dwarf2_per_cu_ptr; -DEF_VEC_P (dwarf2_per_cu_ptr); - extern bool dwarf_always_disassemble; /* A descriptor for dwarf sections. @@ -347,6 +344,37 @@ struct dwarf2_per_cu_data struct dwarf2_per_cu_quick_data *quick; } v; + /* Return true of IMPORTED_SYMTABS is empty or not yet allocated. */ + bool imported_symtabs_empty () const + { + return (imported_symtabs == nullptr || imported_symtabs->empty ()); + } + + /* Push P to the back of IMPORTED_SYMTABS, allocated IMPORTED_SYMTABS + first if required. */ + void imported_symtabs_push (dwarf2_per_cu_data *p) + { + if (imported_symtabs == nullptr) + imported_symtabs = new std::vector ; + imported_symtabs->push_back (p); + } + + /* Return the size of IMPORTED_SYMTABS if it is allocated, otherwise + return 0. */ + size_t imported_symtabs_size () const + { + if (imported_symtabs == nullptr) + return 0; + return imported_symtabs->size (); + } + + /* Delete IMPORTED_SYMTABS and set the pointer back to nullptr. */ + void imported_symtabs_free () + { + delete imported_symtabs; + imported_symtabs = nullptr; + } + /* The CUs we import using DW_TAG_imported_unit. This is filled in while reading psymtabs, used to compute the psymtab dependencies, and then cleared. Then it is filled in again while reading full @@ -364,8 +392,14 @@ struct dwarf2_per_cu_data .gdb_index version <=7 this also records the TUs that the CU referred to. Concurrently with this change gdb was modified to emit version 8 indices so we only pay a price for gold generated indices. - http://sourceware.org/bugzilla/show_bug.cgi?id=15021. */ - VEC (dwarf2_per_cu_ptr) *imported_symtabs; + http://sourceware.org/bugzilla/show_bug.cgi?id=15021. + + This currently needs to be a public member due to how + dwarf2_per_cu_data is allocated and used. Ideally in future things + could be refactored to make this private. Until then please try to + avoid direct access to this member, and instead use the helper + functions above. */ + std::vector *imported_symtabs; }; /* Entry in the signatured_types hash table. */