From patchwork Sat Feb 15 16:54:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 38105 Received: (qmail 86476 invoked by alias); 15 Feb 2020 16:55:00 -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 86111 invoked by uid 89); 15 Feb 2020 16:54:57 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-19.9 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_HELO_PASS autolearn=ham version=3.3.1 spammy=BFD_ENDIAN_BIG, baton, bfd_endian_big X-HELO: gateway33.websitewelcome.com Received: from gateway33.websitewelcome.com (HELO gateway33.websitewelcome.com) (192.185.146.21) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sat, 15 Feb 2020 16:54:50 +0000 Received: from cm16.websitewelcome.com (cm16.websitewelcome.com [100.42.49.19]) by gateway33.websitewelcome.com (Postfix) with ESMTP id 2FA6A10B4389 for ; Sat, 15 Feb 2020 10:54:49 -0600 (CST) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id 30iPj1bG98vkB30iPjyzzn; Sat, 15 Feb 2020 10:54:49 -0600 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Sender:Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=CujzeqeWXKwbegei3UBWlzeGOB8T4K6ZF32MYXTOxm8=; b=e4H5UBDPXIshEpSfi2Dt2pK6mL idpcQyqeNXrRub7uvczXPhhhh33I573TpyvDFSTUuYCagq6iBMUV9XhVBFxbW1nBvnGIYhE5FOxpc nzjOgUYWaH5UczuynbF1B3y6A; Received: from 75-166-123-50.hlrn.qwest.net ([75.166.123.50]:45240 helo=bapiya.Home) by box5379.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.92) (envelope-from ) id 1j30iO-000xcC-Qu; Sat, 15 Feb 2020 09:54:48 -0700 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH 10/14] Introduce dwarf2_enter_objfile and use it Date: Sat, 15 Feb 2020 09:54:40 -0700 Message-Id: <20200215165444.32653-11-tom@tromey.com> In-Reply-To: <20200215165444.32653-1-tom@tromey.com> References: <20200215165444.32653-1-tom@tromey.com> 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; 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. */ + +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 {