From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 16865 invoked by alias); 18 Feb 2020 11:58:22 -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 16852 invoked by uid 89); 18 Feb 2020 11:58:21 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-23.7 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,KAM_STOCKGEN,RCVD_IN_DNSWL_NONE,SPF_PASS autolearn=ham version=3.3.1 spammy= X-HELO: mail-qt1-f196.google.com Received: from mail-qt1-f196.google.com (HELO mail-qt1-f196.google.com) (209.85.160.196) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 18 Feb 2020 11:58:18 +0000 Received: by mail-qt1-f196.google.com with SMTP id v25so14258308qto.7 for ; Tue, 18 Feb 2020 03:58:18 -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=UIRkPrAayJZ30OUwqC91us/2n/BpEnbF4q1V2pXsYJ0=; b=Mank5tjr+KVK3uTdBKQ3OfwypAjXAq9Aa4QR4fooGR3sITTf52Bna3IR/Z7BBzmzX5 dTOaB7/sf5iJ2Uk38ArbX2tPcIa0frt82pqseM7/4Pz046OChW4T8Xfpf4XdOL1oOCdj bz/bhJjFh2aIcqtwGWonHYGQONCOFftLjHbJMSVc+6XTal/OdlH2IvYDfoCXgey3CY/u ZbHtRoaAPmDp3lqvXfdjmanqR8Oi8oCbgWwJ6IYSqWjHKj2Mz5RXduSsBNgbI8HAKizx RX56qgGF/TKVHRjCPztOcwkkMVG6e1YvSXzClROQxon0T/nAt8HVOuqFmq+22l+oDBgO sh9w== Return-Path: Received: from [192.168.0.185] ([179.177.236.155]) by smtp.gmail.com with ESMTPSA id w134sm1729008qka.127.2020.02.18.03.58.13 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 18 Feb 2020 03:58:14 -0800 (PST) Subject: Re: [PATCH 10/14] Introduce dwarf2_enter_objfile and use it To: Tom Tromey , gdb-patches@sourceware.org References: <20200215165444.32653-1-tom@tromey.com> <20200215165444.32653-11-tom@tromey.com> From: Luis Machado Message-ID: <11f40f4c-6926-e077-bf41-7af6d45edde9@linaro.org> Date: Tue, 18 Feb 2020 11:58: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-11-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/msg00711.txt.bz2 On 2/15/20 1:54 PM, Tom Tromey wrote: > dwarf2_per_objfile has a backlink to objfile. Once the series is > complete, the objfile will only be set temporarily: that is, it will > be set when calling in to some DWARF module, and then cleared when > leaving. > > This patch introduces a new RAII class, dwarf2_enter_objfile, which > will be used for this purpose. Then, it changes all the callbacks to > call this. > > 2020-02-15 Tom Tromey > > * dwarf2/read.h (class dwarf2_enter_objfile): New. > * dwarf2/read.c (dw2_find_last_source_symtab) > (dw2_map_symtabs_matching_filename, dw2_lookup_symbol) > (dw2_print_stats, dw2_expand_symtabs_for_function) > (dw2_expand_all_symtabs, dw2_expand_symtabs_with_fullname) > (dw2_expand_symtabs_matching, dw2_find_pc_sect_compunit_symtab) > (dw2_map_symbol_filenames, dw2_debug_names_lookup_symbol) > (dw2_debug_names_expand_symtabs_for_function) > (dw2_debug_names_map_matching_symbols) > (dw2_debug_names_expand_symtabs_matching) > (dwarf2_initialize_objfile, dwarf2_build_psymtabs) > (dwarf2_psymtab::read_symtab, dwarf2_psymtab::expand_psymtab) > (dwarf2_psymtab::get_compunit_symtab): Use dwarf2_enter_objfile. > * dwarf2/loc.c (dwarf2_find_location_expression) > (rw_pieced_value, indirect_pieced_value, coerce_pieced_ref) > (dwarf2_locexpr_baton_eval, dwarf2_evaluate_property) > (locexpr_read_variable, locexpr_read_variable_at_entry) > (locexpr_get_symbol_read_needs, locexpr_describe_location) > (locexpr_tracepoint_var_ref, locexpr_generate_c_location) > (loclist_read_variable, loclist_read_variable_at_entry) > (loclist_describe_location, loclist_tracepoint_var_ref) > (loclist_generate_c_location): Use dwarf2_enter_objfile. > * dwarf2/index-write.c (save_gdb_index_command): Use > dwarf2_enter_objfile. > --- > gdb/ChangeLog | 27 +++++++++++++++++++++++++++ > gdb/dwarf2/index-write.c | 1 + > gdb/dwarf2/loc.c | 34 ++++++++++++++++++++++++++++++---- > gdb/dwarf2/read.c | 21 +++++++++++++++++++++ > gdb/dwarf2/read.h | 24 ++++++++++++++++++++++++ > 5 files changed, 103 insertions(+), 4 deletions(-) > > diff --git a/gdb/dwarf2/index-write.c b/gdb/dwarf2/index-write.c > index 2cbf2ebd202..24255f5f76f 100644 > --- a/gdb/dwarf2/index-write.c > +++ b/gdb/dwarf2/index-write.c > @@ -1755,6 +1755,7 @@ save_gdb_index_command (const char *arg, int from_tty) > > struct dwarf2_per_objfile *dwarf2_per_objfile > = get_dwarf2_per_objfile (objfile); > + dwarf2_enter_objfile enterer (objfile); > > if (dwarf2_per_objfile != NULL) > { > diff --git a/gdb/dwarf2/loc.c b/gdb/dwarf2/loc.c > index 4a148c26722..b0f650cada8 100644 > --- a/gdb/dwarf2/loc.c > +++ b/gdb/dwarf2/loc.c > @@ -312,7 +312,7 @@ const gdb_byte * > dwarf2_find_location_expression (struct dwarf2_loclist_baton *baton, > size_t *locexpr_length, CORE_ADDR pc) > { > - struct objfile *objfile = baton->per_cu->objfile (); > + struct objfile *objfile = baton->objfile; I noticed the above change in a few hunks. Are these spurious changes from a different patch in the series? It doesn't seem to be related to the dwarf2_enter_objfile change. Am i missing something? > struct gdbarch *gdbarch = get_objfile_arch (objfile); > enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); > unsigned int addr_size = baton->per_cu->addr_size (); > @@ -1612,6 +1612,8 @@ rw_pieced_value (struct value *v, struct value *from) > gdb::byte_vector buffer; > bool bits_big_endian = type_byte_order (value_type (v)) == BFD_ENDIAN_BIG; > > + dwarf2_enter_objfile enterer (c->objfile); > + > if (from != NULL) > { > from_contents = value_contents (from); > @@ -2015,6 +2017,8 @@ indirect_pieced_value (struct value *value) > { > struct piece_closure *c > = (struct piece_closure *) value_computed_closure (value); > + dwarf2_enter_objfile enterer (c->objfile); > + > struct type *type; > struct frame_info *frame; > int i, bit_length; > @@ -2105,6 +2109,7 @@ coerce_pieced_ref (const struct value *value) > gdb_assert (closure != NULL); > gdb_assert (closure->pieces.size () == 1); > > + dwarf2_enter_objfile enterer (closure->objfile); > return indirect_synthetic_pointer > (closure->pieces[0].v.ptr.die_sect_off, > closure->pieces[0].v.ptr.offset, > @@ -2404,7 +2409,7 @@ dwarf2_locexpr_baton_eval (const struct dwarf2_locexpr_baton *dlbaton, > ctx.per_cu = dlbaton->per_cu; > ctx.obj_address = addr; > > - objfile = dlbaton->per_cu->objfile (); > + objfile = dlbaton->objfile; > > ctx.gdbarch = get_objfile_arch (objfile); > ctx.addr_size = dlbaton->per_cu->addr_size (); > @@ -2474,6 +2479,7 @@ dwarf2_evaluate_property (const struct dynamic_prop *prop, > const struct dwarf2_property_baton *baton > = (const struct dwarf2_property_baton *) prop->data.baton; > gdb_assert (baton->property_type != NULL); > + dwarf2_enter_objfile enterer (baton->locexpr.objfile); > > if (dwarf2_locexpr_baton_eval (&baton->locexpr, frame, > addr_stack ? addr_stack->addr : 0, > @@ -3552,6 +3558,8 @@ locexpr_read_variable (struct symbol *symbol, struct frame_info *frame) > { > struct dwarf2_locexpr_baton *dlbaton > = (struct dwarf2_locexpr_baton *) SYMBOL_LOCATION_BATON (symbol); > + dwarf2_enter_objfile enterer (dlbaton->objfile); > + > struct value *val; > > val = dwarf2_evaluate_loc_desc (SYMBOL_TYPE (symbol), frame, dlbaton->data, > @@ -3569,6 +3577,7 @@ locexpr_read_variable_at_entry (struct symbol *symbol, struct frame_info *frame) > { > struct dwarf2_locexpr_baton *dlbaton > = (struct dwarf2_locexpr_baton *) SYMBOL_LOCATION_BATON (symbol); > + dwarf2_enter_objfile enterer (dlbaton->objfile); > > return value_of_dwarf_block_entry (SYMBOL_TYPE (symbol), frame, dlbaton->data, > dlbaton->size); > @@ -3582,6 +3591,7 @@ locexpr_get_symbol_read_needs (struct symbol *symbol) > { > struct dwarf2_locexpr_baton *dlbaton > = (struct dwarf2_locexpr_baton *) SYMBOL_LOCATION_BATON (symbol); > + dwarf2_enter_objfile enterer (dlbaton->objfile); > > return dwarf2_loc_desc_get_symbol_read_needs (dlbaton->data, dlbaton->size, > dlbaton->per_cu); > @@ -4285,7 +4295,9 @@ locexpr_describe_location (struct symbol *symbol, CORE_ADDR addr, > { > struct dwarf2_locexpr_baton *dlbaton > = (struct dwarf2_locexpr_baton *) SYMBOL_LOCATION_BATON (symbol); > - struct objfile *objfile = dlbaton->per_cu->objfile (); > + dwarf2_enter_objfile enterer (dlbaton->objfile); > + > + struct objfile *objfile = dlbaton->objfile; > unsigned int addr_size = dlbaton->per_cu->addr_size (); > int offset_size = dlbaton->per_cu->offset_size (); > > @@ -4304,6 +4316,8 @@ locexpr_tracepoint_var_ref (struct symbol *symbol, struct agent_expr *ax, > { > struct dwarf2_locexpr_baton *dlbaton > = (struct dwarf2_locexpr_baton *) SYMBOL_LOCATION_BATON (symbol); > + dwarf2_enter_objfile enterer (dlbaton->objfile); > + > unsigned int addr_size = dlbaton->per_cu->addr_size (); > > if (dlbaton->size == 0) > @@ -4323,6 +4337,8 @@ locexpr_generate_c_location (struct symbol *sym, string_file *stream, > { > struct dwarf2_locexpr_baton *dlbaton > = (struct dwarf2_locexpr_baton *) SYMBOL_LOCATION_BATON (sym); > + dwarf2_enter_objfile enterer (dlbaton->objfile); > + > unsigned int addr_size = dlbaton->per_cu->addr_size (); > > if (dlbaton->size == 0) > @@ -4357,6 +4373,8 @@ loclist_read_variable (struct symbol *symbol, struct frame_info *frame) > { > struct dwarf2_loclist_baton *dlbaton > = (struct dwarf2_loclist_baton *) SYMBOL_LOCATION_BATON (symbol); > + dwarf2_enter_objfile enterer (dlbaton->objfile); > + > struct value *val; > const gdb_byte *data; > size_t size; > @@ -4382,6 +4400,8 @@ loclist_read_variable_at_entry (struct symbol *symbol, struct frame_info *frame) > { > struct dwarf2_loclist_baton *dlbaton > = (struct dwarf2_loclist_baton *) SYMBOL_LOCATION_BATON (symbol); > + dwarf2_enter_objfile enterer (dlbaton->objfile); > + > const gdb_byte *data; > size_t size; > CORE_ADDR pc; > @@ -4421,8 +4441,10 @@ loclist_describe_location (struct symbol *symbol, CORE_ADDR addr, > { > struct dwarf2_loclist_baton *dlbaton > = (struct dwarf2_loclist_baton *) SYMBOL_LOCATION_BATON (symbol); > + dwarf2_enter_objfile enterer (dlbaton->objfile); > + > const gdb_byte *loc_ptr, *buf_end; > - struct objfile *objfile = dlbaton->per_cu->objfile (); > + struct objfile *objfile = dlbaton->objfile; > struct gdbarch *gdbarch = get_objfile_arch (objfile); > enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); > unsigned int addr_size = dlbaton->per_cu->addr_size (); > @@ -4511,6 +4533,8 @@ loclist_tracepoint_var_ref (struct symbol *symbol, struct agent_expr *ax, > { > struct dwarf2_loclist_baton *dlbaton > = (struct dwarf2_loclist_baton *) SYMBOL_LOCATION_BATON (symbol); > + dwarf2_enter_objfile enterer (dlbaton->objfile); > + > const gdb_byte *data; > size_t size; > unsigned int addr_size = dlbaton->per_cu->addr_size (); > @@ -4533,6 +4557,8 @@ loclist_generate_c_location (struct symbol *sym, string_file *stream, > { > struct dwarf2_loclist_baton *dlbaton > = (struct dwarf2_loclist_baton *) SYMBOL_LOCATION_BATON (sym); > + dwarf2_enter_objfile enterer (dlbaton->objfile); > + > unsigned int addr_size = dlbaton->per_cu->addr_size (); > const gdb_byte *data; > size_t size; > diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c > index 7b493f5a227..f86034f2273 100644 > --- a/gdb/dwarf2/read.c > +++ b/gdb/dwarf2/read.c > @@ -3234,6 +3234,7 @@ dw2_get_real_path (struct objfile *objfile, > static struct symtab * > dw2_find_last_source_symtab (struct objfile *objfile) > { > + dwarf2_enter_objfile enterer (objfile); > struct dwarf2_per_objfile *dwarf2_per_objfile > = get_dwarf2_per_objfile (objfile); > dwarf2_per_cu_data *dwarf_cu = dwarf2_per_objfile->all_comp_units.back (); > @@ -3310,6 +3311,7 @@ dw2_map_symtabs_matching_filename > (struct objfile *objfile, const char *name, const char *real_path, > gdb::function_view callback) > { > + dwarf2_enter_objfile enterer (objfile); > const char *name_basename = lbasename (name); > struct dwarf2_per_objfile *dwarf2_per_objfile > = get_dwarf2_per_objfile (objfile); > @@ -3528,6 +3530,7 @@ static struct compunit_symtab * > dw2_lookup_symbol (struct objfile *objfile, block_enum block_index, > const char *name, domain_enum domain) > { > + dwarf2_enter_objfile enterer (objfile); > struct compunit_symtab *stab_best = NULL; > struct dwarf2_per_objfile *dwarf2_per_objfile > = get_dwarf2_per_objfile (objfile); > @@ -3570,6 +3573,7 @@ dw2_lookup_symbol (struct objfile *objfile, block_enum block_index, > static void > dw2_print_stats (struct objfile *objfile) > { > + dwarf2_enter_objfile enterer (objfile); > struct dwarf2_per_objfile *dwarf2_per_objfile > = get_dwarf2_per_objfile (objfile); > int total = (dwarf2_per_objfile->all_comp_units.size () > @@ -3616,6 +3620,7 @@ static void > dw2_expand_symtabs_for_function (struct objfile *objfile, > const char *func_name) > { > + dwarf2_enter_objfile enterer (objfile); > struct dwarf2_per_objfile *dwarf2_per_objfile > = get_dwarf2_per_objfile (objfile); > > @@ -3632,6 +3637,7 @@ dw2_expand_symtabs_for_function (struct objfile *objfile, > static void > dw2_expand_all_symtabs (struct objfile *objfile) > { > + dwarf2_enter_objfile enterer (objfile); > struct dwarf2_per_objfile *dwarf2_per_objfile > = get_dwarf2_per_objfile (objfile); > int total_units = (dwarf2_per_objfile->all_comp_units.size () > @@ -3654,6 +3660,7 @@ static void > dw2_expand_symtabs_with_fullname (struct objfile *objfile, > const char *fullname) > { > + dwarf2_enter_objfile enterer (objfile); > struct dwarf2_per_objfile *dwarf2_per_objfile > = get_dwarf2_per_objfile (objfile); > > @@ -4657,6 +4664,7 @@ dw2_expand_symtabs_matching > gdb::function_view expansion_notify, > enum search_domain kind) > { > + dwarf2_enter_objfile enterer (objfile); > struct dwarf2_per_objfile *dwarf2_per_objfile > = get_dwarf2_per_objfile (objfile); > > @@ -4725,6 +4733,7 @@ dw2_find_pc_sect_compunit_symtab (struct objfile *objfile, > if (!data) > return NULL; > > + dwarf2_enter_objfile enterer (objfile); > struct dwarf2_per_objfile *dwarf2_per_objfile > = get_dwarf2_per_objfile (objfile); > gdb::optional &symtab > @@ -4745,6 +4754,7 @@ static void > dw2_map_symbol_filenames (struct objfile *objfile, symbol_filename_ftype *fun, > void *data, int need_fullname) > { > + dwarf2_enter_objfile enterer (objfile); > struct dwarf2_per_objfile *dwarf2_per_objfile > = get_dwarf2_per_objfile (objfile); > > @@ -5527,6 +5537,7 @@ static struct compunit_symtab * > dw2_debug_names_lookup_symbol (struct objfile *objfile, block_enum block_index, > const char *name, domain_enum domain) > { > + dwarf2_enter_objfile enterer (objfile); > struct dwarf2_per_objfile *dwarf2_per_objfile > = get_dwarf2_per_objfile (objfile); > > @@ -5593,6 +5604,7 @@ static void > dw2_debug_names_expand_symtabs_for_function (struct objfile *objfile, > const char *func_name) > { > + dwarf2_enter_objfile enterer (objfile); > struct dwarf2_per_objfile *dwarf2_per_objfile > = get_dwarf2_per_objfile (objfile); > > @@ -5617,6 +5629,7 @@ dw2_debug_names_map_matching_symbols > gdb::function_view callback, > symbol_compare_ftype *ordered_compare) > { > + dwarf2_enter_objfile enterer (objfile); > struct dwarf2_per_objfile *dwarf2_per_objfile > = get_dwarf2_per_objfile (objfile); > > @@ -5676,6 +5689,7 @@ dw2_debug_names_expand_symtabs_matching > gdb::function_view expansion_notify, > enum search_domain kind) > { > + dwarf2_enter_objfile enterer (objfile); > struct dwarf2_per_objfile *dwarf2_per_objfile > = get_dwarf2_per_objfile (objfile); > > @@ -5792,6 +5806,7 @@ dwarf2_initialize_objfile (struct objfile *objfile, dw_index_kind *index_kind) > { > struct dwarf2_per_objfile *dwarf2_per_objfile > = get_dwarf2_per_objfile (objfile); > + dwarf2_enter_objfile enterer (objfile); > > /* If we're about to read full symbols, don't bother with the > indices. In this case we also don't care if some other debug > @@ -5861,6 +5876,8 @@ dwarf2_initialize_objfile (struct objfile *objfile, dw_index_kind *index_kind) > void > dwarf2_build_psymtabs (struct objfile *objfile) > { > + dwarf2_enter_objfile enterer (objfile); > + > struct dwarf2_per_objfile *dwarf2_per_objfile > = get_dwarf2_per_objfile (objfile); > > @@ -8740,6 +8757,7 @@ locate_pdi_sibling (const struct die_reader_specs *reader, > void > dwarf2_psymtab::read_symtab (struct objfile *objfile) > { > + dwarf2_enter_objfile enterer (objfile); > struct dwarf2_per_objfile *dwarf2_per_objfile > = get_dwarf2_per_objfile (objfile); > > @@ -8899,6 +8917,7 @@ process_queue (struct dwarf2_per_objfile *dwarf2_per_objfile) > void > dwarf2_psymtab::expand_psymtab (struct objfile *objfile) > { > + dwarf2_enter_objfile enterer (objfile); > struct dwarf2_per_objfile *dwarf2_per_objfile > = get_dwarf2_per_objfile (objfile); > > @@ -8928,6 +8947,7 @@ dwarf2_psymtab::readin_p (struct objfile *objfile) const > if (per_cu_data == nullptr) > return true; > > + dwarf2_enter_objfile enterer (objfile); > dwarf2_per_objfile *dwarf2_per_objfile > = get_dwarf2_per_objfile (objfile); > gdb::optional &symtab > @@ -8943,6 +8963,7 @@ dwarf2_psymtab::get_compunit_symtab (struct objfile *objfile) const > if (per_cu_data == nullptr) > return nullptr; > > + dwarf2_enter_objfile enterer (objfile); > dwarf2_per_objfile *dwarf2_per_objfile > = get_dwarf2_per_objfile (objfile); > gdb::optional &symtab > diff --git a/gdb/dwarf2/read.h b/gdb/dwarf2/read.h > index 98d58fb6880..bef37e969d3 100644 > --- a/gdb/dwarf2/read.h > +++ b/gdb/dwarf2/read.h > @@ -284,6 +284,30 @@ public: > > dwarf2_per_objfile *get_dwarf2_per_objfile (struct objfile *objfile); > > +/* The "objfile" member of a dwarf2_per_objfile is normally nullptr, > + and temporarily set when calling into the DWARF code. This class > + is used "enter" a particular objfile. */ "is used to "enter" a ..." ? > + > +class dwarf2_enter_objfile > +{ > +public: > + > + dwarf2_enter_objfile (struct objfile *objfile) > + : m_per_objfile (get_dwarf2_per_objfile (objfile)), > + m_restore_objfile (&m_per_objfile->objfile, objfile) > + { > + } > + > + ~dwarf2_enter_objfile () = default; > + > + DISABLE_COPY_AND_ASSIGN (dwarf2_enter_objfile); > + > +private: > + > + dwarf2_per_objfile *m_per_objfile; > + scoped_restore_tmpl m_restore_objfile; > +}; > + > /* A partial symtab specialized for DWARF. */ > struct dwarf2_psymtab : public partial_symtab > { >