From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 50689 invoked by alias); 18 Feb 2020 11:50:18 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 50677 invoked by uid 89); 18 Feb 2020 11:50:18 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-24.3 required=5.0 tests=AWL,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=Hold, sk:dw2_get X-HELO: mail-qk1-f195.google.com Received: from mail-qk1-f195.google.com (HELO mail-qk1-f195.google.com) (209.85.222.195) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 18 Feb 2020 11:50:14 +0000 Received: by mail-qk1-f195.google.com with SMTP id t83so2180916qke.3 for ; Tue, 18 Feb 2020 03:50:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-language:content-transfer-encoding; bh=gtgxu5PJCXA/y8SESUoJGMKW0Ea636UcDvW6UHjs+x4=; b=y6akPP7pSzXztHnbYMQTtB6MMjvj/6ny47L+kwS0tqTsQVglnIPyP/U0529b+GHJsX ys5euiSZIgFOI+J6P2+A2tYBvx+5SF6tNE8rlEsZLYLmkj6Z7XaUpt3SnOTwltPYDja1 35gCnHRlUEBhFdR0N13LSEnNtEMgJ5IsAPFl8+t9erFSU6jt4BXMtzjSsUXn/0D702mP eZe0LeBLdTkCotiVWlCjHnOlA8IP4SR8OjZsASo/anF22xvnfn08sdGDT0Q9WZPnzLZa YaKEoNFvATVx7xi/vK3Y0hM87A2AcQtvXSxD9VXzeairBlhLgU+kfZCXK7pQFYEUDvNl FRng== Return-Path: Received: from [192.168.0.185] ([179.177.236.155]) by smtp.gmail.com with ESMTPSA id c26sm1658207qtn.19.2020.02.18.03.50.09 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 18 Feb 2020 03:50:11 -0800 (PST) Subject: Re: [PATCH 08/14] Remove symtab links from dwarf2_psymtab and dwarf2_per_cu_quick_data To: Tom Tromey , gdb-patches@sourceware.org References: <20200215165444.32653-1-tom@tromey.com> <20200215165444.32653-9-tom@tromey.com> From: Luis Machado Message-ID: <6767060e-cc61-1180-de10-df5652d606bb@linaro.org> Date: Tue, 18 Feb 2020 11:50:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.4.1 MIME-Version: 1.0 In-Reply-To: <20200215165444.32653-9-tom@tromey.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-IsSubscribed: yes X-SW-Source: 2020-02/txt/msg00709.txt.bz2 A comment below... On 2/15/20 1:54 PM, Tom Tromey wrote: > This removes the links from dwarf2_psymtab and > dwarf2_per_cu_quick_data to the compunit_symtab. Now, the DWARF code > uses the index in these objects to find the corresponding symtab in > the "unshared" object. > > 2020-02-15 Tom Tromey > > * dwarf2/read.h (struct dwarf2_unshareable) : New > member. > (struct dwarf2_psymtab): Derive from partial_symtab. > : Declare methods. > * dwarf2/read.c (struct dwarf2_per_cu_quick_data) > : Remove. > (dw2_do_instantiate_symtab, dw2_instantiate_symtab) > (dw2_map_expand_apply, dw2_map_symtabs_matching_filename) > (dw2_symtab_iter_next, dw2_print_stats) > (dw2_expand_symtabs_with_fullname) > (dw2_expand_symtabs_matching_one) > (dw_expand_symtabs_matching_file_matcher) > (dw2_find_pc_sect_compunit_symtab, dw2_map_symbol_filenames) > (dw2_debug_names_iterator::next, does) > (fill_in_sig_entry_from_dwo_entry, dwarf2_psymtab::read_symtab) > (process_queue, dwarf2_psymtab::expand_psymtab): Update. > (dwarf2_psymtab::readin_p, dwarf2_psymtab::get_compunit_symtab): > New methods. > (get_compunit_symtab, process_full_comp_unit) > (process_full_type_unit): Update. > (dwarf2_build_psymtabs): Resize the symtabs vector. > (dwarf2_resize_unshareable): New function. > (dwarf2_initialize_objfile): Call dwarf2_resize_unshareable. > --- > gdb/ChangeLog | 26 +++++++ > gdb/dwarf2/read.c | 194 +++++++++++++++++++++++++++++++--------------- > gdb/dwarf2/read.h | 14 +++- > 3 files changed, 170 insertions(+), 64 deletions(-) > > diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c > index 281d39ad271..44fdb070e49 100644 > --- a/gdb/dwarf2/read.c > +++ b/gdb/dwarf2/read.c > @@ -2205,10 +2205,6 @@ struct dwarf2_per_cu_quick_data > NOTE: This points into dwarf2_per_objfile->quick_file_names_table. */ > struct quick_file_names *file_names; > > - /* The corresponding symbol table. This is NULL if symbols for this > - CU have not yet been read. */ > - struct compunit_symtab *compunit_symtab; > - > /* A temporary mark bit used when iterating over all CUs in > expand_symtabs_matching. */ > unsigned int mark : 1; > @@ -2332,9 +2328,9 @@ dw2_do_instantiate_symtab (struct dwarf2_per_cu_data *per_cu, bool skip_partial) > with the dwarf queue empty. */ > dwarf2_queue_guard q_guard (dwarf2_per_objfile); > > - if (dwarf2_per_objfile->using_index > - ? per_cu->v.quick->compunit_symtab == NULL > - : (per_cu->v.psymtab == NULL || !per_cu->v.psymtab->readin)) > + gdb::optional &symtab > + = dwarf2_per_objfile->unshareable->symtabs[per_cu->index]; > + if (!symtab.has_value ()) I noticed the above sequence gets repeated a lot throughout the code. Can we turn it into a function/method and reduce the duplication? There are other sequences that get repeated, but not as often. > { > queue_comp_unit (per_cu, language_minimal); > load_cu (per_cu, skip_partial); > @@ -2369,7 +2365,10 @@ dw2_instantiate_symtab (struct dwarf2_per_cu_data *per_cu, bool skip_partial) > struct dwarf2_per_objfile *dwarf2_per_objfile = per_cu->dwarf2_per_objfile; > > gdb_assert (dwarf2_per_objfile->using_index); > - if (!per_cu->v.quick->compunit_symtab) > + gdb::optional &symtab > + = dwarf2_per_objfile->unshareable->symtabs[per_cu->index]; > + > + if (!symtab.has_value ()) > { > free_cached_comp_units freer (dwarf2_per_objfile); > scoped_restore decrementer = increment_reading_symtab (); > @@ -2377,7 +2376,7 @@ dw2_instantiate_symtab (struct dwarf2_per_cu_data *per_cu, bool skip_partial) > process_cu_includes (dwarf2_per_objfile); > } > > - return per_cu->v.quick->compunit_symtab; > + return *symtab; > } > > /* See declaration. */ > @@ -3289,7 +3288,11 @@ dw2_map_expand_apply (struct objfile *objfile, > struct compunit_symtab *last_made = objfile->compunit_symtabs; > > /* Don't visit already-expanded CUs. */ > - if (per_cu->v.quick->compunit_symtab) > + struct dwarf2_per_objfile *dwarf2_per_objfile > + = get_dwarf2_per_objfile (objfile); > + gdb::optional &symtab > + = dwarf2_per_objfile->unshareable->symtabs[per_cu->index]; > + if (symtab.has_value ()) > return 0; > > /* This may expand more than one symtab, and we want to iterate over > @@ -3317,7 +3320,9 @@ dw2_map_symtabs_matching_filename > for (dwarf2_per_cu_data *per_cu : dwarf2_per_objfile->all_comp_units) > { > /* We only need to look at symtabs not already expanded. */ > - if (per_cu->v.quick->compunit_symtab) > + gdb::optional &symtab > + = dwarf2_per_objfile->unshareable->symtabs[per_cu->index]; > + if (symtab.has_value ()) > continue; > > quick_file_names *file_data = dw2_get_file_names (per_cu); > @@ -3458,7 +3463,9 @@ dw2_symtab_iter_next (struct dw2_symtab_iterator *iter) > dwarf2_per_cu_data *per_cu = dwarf2_per_objfile->get_cutu (cu_index); > > /* Skip if already read in. */ > - if (per_cu->v.quick->compunit_symtab) > + gdb::optional &symtab > + = dwarf2_per_objfile->unshareable->symtabs[per_cu->index]; > + if (symtab.has_value ()) > continue; > > /* Check static vs global. */ > @@ -3573,7 +3580,9 @@ dw2_print_stats (struct objfile *objfile) > { > dwarf2_per_cu_data *per_cu = dwarf2_per_objfile->get_cutu (i); > > - if (!per_cu->v.quick->compunit_symtab) > + gdb::optional &symtab > + = dwarf2_per_objfile->unshareable->symtabs[per_cu->index]; > + if (!symtab.has_value ()) > ++count; > } > printf_filtered (_(" Number of read CUs: %d\n"), total - count); > @@ -3656,7 +3665,9 @@ dw2_expand_symtabs_with_fullname (struct objfile *objfile, > for (dwarf2_per_cu_data *per_cu : dwarf2_per_objfile->all_comp_units) > { > /* We only need to look at symtabs not already expanded. */ > - if (per_cu->v.quick->compunit_symtab) > + gdb::optional &symtab > + = dwarf2_per_objfile->unshareable->symtabs[per_cu->index]; > + if (symtab.has_value ()) > continue; > > quick_file_names *file_data = dw2_get_file_names (per_cu); > @@ -4455,15 +4466,19 @@ dw2_expand_symtabs_matching_one > { > if (file_matcher == NULL || per_cu->v.quick->mark) > { > - bool symtab_was_null > - = (per_cu->v.quick->compunit_symtab == NULL); > + struct dwarf2_per_objfile *dwarf2_per_objfile > + = per_cu->dwarf2_per_objfile; > + gdb::optional &symtab > + = dwarf2_per_objfile->unshareable->symtabs[per_cu->index]; > + bool symtab_was_null = !symtab.has_value () || *symtab == nullptr; > > dw2_instantiate_symtab (per_cu, false); > > if (expansion_notify != NULL > && symtab_was_null > - && per_cu->v.quick->compunit_symtab != NULL) > - expansion_notify (per_cu->v.quick->compunit_symtab); > + && symtab.has_value () > + && *symtab != nullptr) > + expansion_notify (*symtab); > } > } > > @@ -4583,7 +4598,9 @@ dw_expand_symtabs_matching_file_matcher > per_cu->v.quick->mark = 0; > > /* We only need to look at symtabs not already expanded. */ > - if (per_cu->v.quick->compunit_symtab) > + gdb::optional &symtab > + = dwarf2_per_objfile->unshareable->symtabs[per_cu->index]; > + if (symtab.has_value ()) > continue; > > quick_file_names *file_data = dw2_get_file_names (per_cu); > @@ -4708,7 +4725,11 @@ dw2_find_pc_sect_compunit_symtab (struct objfile *objfile, > if (!data) > return NULL; > > - if (warn_if_readin && data->v.quick->compunit_symtab) > + struct dwarf2_per_objfile *dwarf2_per_objfile > + = get_dwarf2_per_objfile (objfile); > + gdb::optional &symtab > + = dwarf2_per_objfile->unshareable->symtabs[data->index]; > + if (warn_if_readin && symtab.has_value ()) > warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"), > paddress (get_objfile_arch (objfile), pc)); > > @@ -4741,7 +4762,9 @@ dw2_map_symbol_filenames (struct objfile *objfile, symbol_filename_ftype *fun, > > for (dwarf2_per_cu_data *per_cu : dwarf2_per_objfile->all_comp_units) > { > - if (per_cu->v.quick->compunit_symtab) > + gdb::optional &symtab > + = dwarf2_per_objfile->unshareable->symtabs[per_cu->index]; > + if (symtab.has_value ()) > { > void **slot = htab_find_slot (visited.get (), > per_cu->v.quick->file_names, > @@ -4754,7 +4777,9 @@ dw2_map_symbol_filenames (struct objfile *objfile, symbol_filename_ftype *fun, > for (dwarf2_per_cu_data *per_cu : dwarf2_per_objfile->all_comp_units) > { > /* We only need to look at symtabs not already expanded. */ > - if (per_cu->v.quick->compunit_symtab) > + gdb::optional &symtab > + = dwarf2_per_objfile->unshareable->symtabs[per_cu->index]; > + if (symtab.has_value ()) > continue; > > quick_file_names *file_data = dw2_get_file_names (per_cu); > @@ -5386,7 +5411,9 @@ dw2_debug_names_iterator::next () > } > > /* Skip if already read in. */ > - if (per_cu->v.quick->compunit_symtab) > + gdb::optional &symtab > + = dwarf2_per_objfile->unshareable->symtabs[per_cu->index]; > + if (symtab.has_value ()) > goto again; > > /* Check static vs global. */ > @@ -5627,11 +5654,12 @@ dw2_debug_names_map_matching_symbols > the psymtab code does. */ > for (dwarf2_per_cu_data *per_cu : dwarf2_per_objfile->all_comp_units) > { > - struct compunit_symtab *cust = per_cu->v.quick->compunit_symtab; > - if (cust != nullptr) > + gdb::optional &symtab > + = dwarf2_per_objfile->unshareable->symtabs[per_cu->index]; > + if (symtab.has_value () && *symtab != nullptr) > { > const struct block *block > - = BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (cust), block_kind); > + = BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (*symtab), block_kind); > if (!iterate_over_symbols_terminated (block, name, > domain, callback)) > break; > @@ -5748,6 +5776,15 @@ get_gdb_index_contents_from_cache_dwz (objfile *obj, dwz_file *dwz) > return global_index_cache.lookup_gdb_index (build_id, &dwz->index_cache_res); > } > > +/* Make sure we have space for the compunit_symtabs we may need. */ > + > +static void > +dwarf2_resize_unshareable (dwarf2_per_objfile *dwarf2_per_objfile) > +{ > + dwarf2_per_objfile->unshareable->symtabs.resize > + (dwarf2_per_objfile->num_psymtabs); > +} > + > /* See symfile.h. */ > > bool > @@ -5768,6 +5805,7 @@ dwarf2_initialize_objfile (struct objfile *objfile, dw_index_kind *index_kind) > dwarf2_per_objfile->quick_file_names_table > = create_quick_file_names_table > (dwarf2_per_objfile->all_comp_units.size ()); > + dwarf2_resize_unshareable (dwarf2_per_objfile); > > for (int i = 0; i < (dwarf2_per_objfile->all_comp_units.size () > + dwarf2_per_objfile->all_type_units.size ()); ++i) > @@ -5788,6 +5826,7 @@ dwarf2_initialize_objfile (struct objfile *objfile, dw_index_kind *index_kind) > if (dwarf2_read_debug_names (dwarf2_per_objfile)) > { > *index_kind = dw_index_kind::DEBUG_NAMES; > + dwarf2_resize_unshareable (dwarf2_per_objfile); > return true; > } > > @@ -5796,6 +5835,7 @@ dwarf2_initialize_objfile (struct objfile *objfile, dw_index_kind *index_kind) > get_gdb_index_contents_from_section)) > { > *index_kind = dw_index_kind::GDB_INDEX; > + dwarf2_resize_unshareable (dwarf2_per_objfile); > return true; > } > > @@ -5806,6 +5846,7 @@ dwarf2_initialize_objfile (struct objfile *objfile, dw_index_kind *index_kind) > { > global_index_cache.hit (); > *index_kind = dw_index_kind::GDB_INDEX; > + dwarf2_resize_unshareable (dwarf2_per_objfile); > return true; > } > > @@ -5834,6 +5875,8 @@ dwarf2_build_psymtabs (struct objfile *objfile) > dwarf2_build_psymtabs_hard (dwarf2_per_objfile); > psymtabs.keep (); > > + dwarf2_resize_unshareable (dwarf2_per_objfile); > + > /* (maybe) store an index in the cache. */ > global_index_cache.store (dwarf2_per_objfile); > } > @@ -6259,7 +6302,7 @@ fill_in_sig_entry_from_dwo_entry (struct dwarf2_per_objfile *dwarf2_per_objfile, > if (dwarf2_per_objfile->using_index) > { > gdb_assert (sig_entry->per_cu.v.quick != NULL); > - gdb_assert (sig_entry->per_cu.v.quick->compunit_symtab == NULL); > + gdb_assert (!dwarf2_per_objfile->unshareable->symtabs[sig_entry->per_cu.index].has_value ()); > } > else > gdb_assert (sig_entry->per_cu.v.psymtab == NULL); > @@ -8700,7 +8743,10 @@ dwarf2_psymtab::read_symtab (struct objfile *objfile) > struct dwarf2_per_objfile *dwarf2_per_objfile > = get_dwarf2_per_objfile (objfile); > > - gdb_assert (!readin); > + gdb::optional &symtab > + = dwarf2_per_objfile->unshareable->symtabs[per_cu_data->index]; > + gdb_assert (!symtab.has_value ()); > + > /* If this psymtab is constructed from a debug-only objfile, the > has_section_at_zero flag will not necessarily be correct. We > can get the correct value for this flag by looking at the data > @@ -8796,9 +8842,9 @@ process_queue (struct dwarf2_per_objfile *dwarf2_per_objfile) > { > dwarf2_queue_item &item = dwarf2_per_objfile->queue.front (); > > - if ((dwarf2_per_objfile->using_index > - ? !item.per_cu->v.quick->compunit_symtab > - : (item.per_cu->v.psymtab && !item.per_cu->v.psymtab->readin)) > + gdb::optional &symtab > + = dwarf2_per_objfile->unshareable->symtabs[item.per_cu->index]; > + if (!symtab.has_value () > /* Skip dummy CUs. */ > && item.per_cu->cu != NULL) > { > @@ -8853,24 +8899,57 @@ process_queue (struct dwarf2_per_objfile *dwarf2_per_objfile) > void > dwarf2_psymtab::expand_psymtab (struct objfile *objfile) > { > - struct dwarf2_per_cu_data *per_cu; > - > - if (readin) > - return; > - > - read_dependencies (objfile); > - > - per_cu = per_cu_data; > + struct dwarf2_per_objfile *dwarf2_per_objfile > + = get_dwarf2_per_objfile (objfile); > > - if (per_cu == NULL) > + if (per_cu_data == NULL) > { > /* It's an include file, no symbols to read for it. > Everything is in the parent symtab. */ > - readin = true; > return; > } > > - dw2_do_instantiate_symtab (per_cu, false); > + gdb::optional &symtab > + = dwarf2_per_objfile->unshareable->symtabs[per_cu_data->index]; > + > + if (symtab.has_value ()) > + return; > + > + read_dependencies (objfile); > + > + dw2_do_instantiate_symtab (per_cu_data, false); > +} > + > +/* See psympriv.h. */ > + > +bool > +dwarf2_psymtab::readin_p (struct objfile *objfile) const > +{ > + if (per_cu_data == nullptr) > + return true; > + > + dwarf2_per_objfile *dwarf2_per_objfile > + = get_dwarf2_per_objfile (objfile); > + gdb::optional &symtab > + = dwarf2_per_objfile->unshareable->symtabs[per_cu_data->index]; > + return symtab.has_value (); > +} > + > +/* See psympriv.h. */ > + > +compunit_symtab * > +dwarf2_psymtab::get_compunit_symtab (struct objfile *objfile) const > +{ > + if (per_cu_data == nullptr) > + return nullptr; > + > + dwarf2_per_objfile *dwarf2_per_objfile > + = get_dwarf2_per_objfile (objfile); > + gdb::optional &symtab > + = dwarf2_per_objfile->unshareable->symtabs[per_cu_data->index]; > + if (!symtab.has_value ()) > + return nullptr; > + return *symtab; > } > > /* Trivial hash function for die_info: the hash value of a DIE > @@ -9413,9 +9492,12 @@ rust_union_quirks (struct dwarf2_cu *cu) > static struct compunit_symtab * > get_compunit_symtab (struct dwarf2_per_cu_data *per_cu) > { > - return (per_cu->dwarf2_per_objfile->using_index > - ? per_cu->v.quick->compunit_symtab > - : per_cu->v.psymtab->compunit_symtab); > + struct dwarf2_per_objfile *dwarf2_per_objfile > + = per_cu->dwarf2_per_objfile; > + gdb::optional &symtab > + = dwarf2_per_objfile->unshareable->symtabs[per_cu->index]; > + gdb_assert (symtab.has_value ()); > + return *symtab; > } > > /* A helper function for computing the list of all symbol tables > @@ -9621,14 +9703,9 @@ process_full_comp_unit (struct dwarf2_per_cu_data *per_cu, > cust->call_site_htab = cu->call_site_htab; > } > > - if (dwarf2_per_objfile->using_index) > - per_cu->v.quick->compunit_symtab = cust; > - else > - { > - dwarf2_psymtab *pst = per_cu->v.psymtab; > - pst->compunit_symtab = cust; > - pst->readin = true; > - } > + gdb::optional &symtab > + = dwarf2_per_objfile->unshareable->symtabs[per_cu->index]; > + symtab = cust; > > /* Push it for inclusion processing later. */ > dwarf2_per_objfile->just_read_cus.push_back (per_cu); > @@ -9701,14 +9778,9 @@ process_full_type_unit (struct dwarf2_per_cu_data *per_cu, > cust = sig_type->type_unit_group->compunit_symtab; > } > > - if (dwarf2_per_objfile->using_index) > - per_cu->v.quick->compunit_symtab = cust; > - else > - { > - dwarf2_psymtab *pst = per_cu->v.psymtab; > - pst->compunit_symtab = cust; > - pst->readin = true; > - } > + gdb::optional &symtab > + = dwarf2_per_objfile->unshareable->symtabs[per_cu->index]; > + symtab = cust; > > /* Not needed any more. */ > cu->reset_builder (); > diff --git a/gdb/dwarf2/read.h b/gdb/dwarf2/read.h > index 5fc7f7f72e5..98d58fb6880 100644 > --- a/gdb/dwarf2/read.h > +++ b/gdb/dwarf2/read.h > @@ -82,6 +82,10 @@ struct dwarf2_unshareable > This is NULL if not allocated yet. > The mapping is done via (CU/TU + DIE offset) -> type. */ > htab_up die_type_hash; > + > + /* Hold the corresponding compunit_symtab for each CU or TU. This > + is indexed by dwarf2_per_cu_data::index. */ > + std::vector> symtabs; > }; > > /* Collection of data recorded per objfile. > @@ -281,22 +285,26 @@ public: > dwarf2_per_objfile *get_dwarf2_per_objfile (struct objfile *objfile); > > /* A partial symtab specialized for DWARF. */ > -struct dwarf2_psymtab : public standard_psymtab > +struct dwarf2_psymtab : public partial_symtab > { > dwarf2_psymtab (const char *filename, struct objfile *objfile) > - : standard_psymtab (filename, objfile) > + : partial_symtab (filename, objfile) > { > } > > dwarf2_psymtab (const char *filename, struct objfile *objfile, > CORE_ADDR addr) > - : standard_psymtab (filename, objfile, addr) > + : partial_symtab (filename, objfile, addr) > { > } > > void read_symtab (struct objfile *) override; > void expand_psymtab (struct objfile *) override; > > + bool readin_p (struct objfile *) const override; > + struct compunit_symtab *get_compunit_symtab (struct objfile *) const > + override; > + > struct dwarf2_per_cu_data *per_cu_data; > }; > >