From patchwork Tue Apr 9 18:09:45 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 32227 Received: (qmail 59154 invoked by alias); 9 Apr 2019 18:09:53 -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 58960 invoked by uid 89); 9 Apr 2019 18:09:52 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-18.8 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.1 spammy=Master, wrapping, brother, sk:build_s X-HELO: gateway21.websitewelcome.com Received: from gateway21.websitewelcome.com (HELO gateway21.websitewelcome.com) (192.185.46.109) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 09 Apr 2019 18:09:49 +0000 Received: from cm12.websitewelcome.com (cm12.websitewelcome.com [100.42.49.8]) by gateway21.websitewelcome.com (Postfix) with ESMTP id 31FF9400D95A5 for ; Tue, 9 Apr 2019 13:09:48 -0500 (CDT) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id DvBshrP1yiQerDvBshbEIn; Tue, 09 Apr 2019 13:09:48 -0500 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=zmphHdctFGDWPhqJjd9wgzPGPAOKJP55ZsbfJXfx618=; b=fo89j3BggOtySa/QUOHZzOeYAk uKz1K+CxaqDevvXlMw7vwUYDLCC4zW0MNyTJg77fAVFngcU2KvHOjeYgfK8l2cAdzVmrMJVHtoyvT 7TIwqsLLt+bAXFidBc6ogDBqy; Received: from 174-29-37-56.hlrn.qwest.net ([174.29.37.56]:33050 helo=bapiya.Home) by box5379.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.91) (envelope-from ) id 1hDvBr-003Khd-Sn; Tue, 09 Apr 2019 13:09:48 -0500 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH 3/3] Introduce a separate debug objfile iterator Date: Tue, 9 Apr 2019 12:09:45 -0600 Message-Id: <20190409180945.21621-4-tom@tromey.com> In-Reply-To: <20190409180945.21621-1-tom@tromey.com> References: <20190409180945.21621-1-tom@tromey.com> This introduces a new iterator and range adapter for iteration over the separate debug files of a given objfile. As in the current approach, the requested objfile is returned first, followed by the separate debug objfiles. gdb/ChangeLog 2019-04-09 Tom Tromey * symtab.c (lookup_global_symbol_from_objfile) (lookup_symbol_in_objfile_from_linkage_name): Use the iterator. * objfiles.h (class separate_debug_iterator): New. (class separate_debug_range): New. (struct objfile) : New method. (objfile_separate_debug_iterate): Don't declare. * objfiles.c (separate_debug_iterator::operator++): Rename from objfile_separate_debug_iterate. (objfile_relocate, objfile_rebase, objfile_has_symbols): Use the iterator. * minsyms.c (lookup_minimal_symbol_by_pc_section): Use the iterator. --- gdb/ChangeLog | 15 +++++++++++ gdb/minsyms.c | 5 +--- gdb/objfiles.c | 67 ++++++++++++++++++++++++------------------------- gdb/objfiles.h | 68 +++++++++++++++++++++++++++++++++++++++++++++++--- gdb/symtab.c | 12 +++------ 5 files changed, 117 insertions(+), 50 deletions(-) diff --git a/gdb/minsyms.c b/gdb/minsyms.c index 34198d122dc..8037329a862 100644 --- a/gdb/minsyms.c +++ b/gdb/minsyms.c @@ -696,7 +696,6 @@ lookup_minimal_symbol_by_pc_section (CORE_ADDR pc_in, struct obj_section *sectio int lo; int hi; int newobj; - struct objfile *objfile; struct minimal_symbol *msymbol; struct minimal_symbol *best_symbol = NULL; struct objfile *best_objfile = NULL; @@ -722,9 +721,7 @@ lookup_minimal_symbol_by_pc_section (CORE_ADDR pc_in, struct obj_section *sectio gdb_assert (section != NULL); - for (objfile = section->objfile; - objfile != NULL; - objfile = objfile_separate_debug_iterate (section->objfile, objfile)) + for (struct objfile *objfile : section->objfile->separate_debug_objfiles ()) { CORE_ADDR pc = pc_in; diff --git a/gdb/objfiles.c b/gdb/objfiles.c index ada5edc42fa..71518ea5b24 100644 --- a/gdb/objfiles.c +++ b/gdb/objfiles.c @@ -446,44 +446,50 @@ entry_point_address (void) return retval; } -/* Iterator on PARENT and every separate debug objfile of PARENT. - The usage pattern is: - for (objfile = parent; - objfile; - objfile = objfile_separate_debug_iterate (parent, objfile)) - ... -*/ - -struct objfile * -objfile_separate_debug_iterate (const struct objfile *parent, - const struct objfile *objfile) +separate_debug_iterator & +separate_debug_iterator::operator++ () { + gdb_assert (m_objfile != nullptr); + struct objfile *res; /* If any, return the first child. */ - res = objfile->separate_debug_objfile; + res = m_objfile->separate_debug_objfile; if (res) - return res; + { + m_objfile = res; + return *this; + } /* Common case where there is no separate debug objfile. */ - if (objfile == parent) - return NULL; + if (m_objfile == m_parent) + { + m_objfile = nullptr; + return *this; + } /* Return the brother if any. Note that we don't iterate on brothers of the parents. */ - res = objfile->separate_debug_objfile_link; + res = m_objfile->separate_debug_objfile_link; if (res) - return res; + { + m_objfile = res; + return *this; + } - for (res = objfile->separate_debug_objfile_backlink; - res != parent; + for (res = m_objfile->separate_debug_objfile_backlink; + res != m_parent; res = res->separate_debug_objfile_backlink) { gdb_assert (res != NULL); if (res->separate_debug_objfile_link) - return res->separate_debug_objfile_link; + { + m_objfile = res->separate_debug_objfile_link; + return *this; + } } - return NULL; + m_objfile = nullptr; + return *this; } /* Put one object file before a specified on in the global list. @@ -860,15 +866,15 @@ void objfile_relocate (struct objfile *objfile, const struct section_offsets *new_offsets) { - struct objfile *debug_objfile; int changed = 0; changed |= objfile_relocate1 (objfile, new_offsets); - for (debug_objfile = objfile->separate_debug_objfile; - debug_objfile; - debug_objfile = objfile_separate_debug_iterate (objfile, debug_objfile)) + for (struct objfile *debug_objfile : objfile->separate_debug_objfiles ()) { + if (debug_objfile == objfile) + continue; + section_addr_info objfile_addrs = build_section_addr_info_from_objfile (objfile); @@ -917,14 +923,9 @@ objfile_rebase1 (struct objfile *objfile, CORE_ADDR slide) void objfile_rebase (struct objfile *objfile, CORE_ADDR slide) { - struct objfile *debug_objfile; int changed = 0; - changed |= objfile_rebase1 (objfile, slide); - - for (debug_objfile = objfile->separate_debug_objfile; - debug_objfile; - debug_objfile = objfile_separate_debug_iterate (objfile, debug_objfile)) + for (struct objfile *debug_objfile : objfile->separate_debug_objfiles ()) changed |= objfile_rebase1 (debug_objfile, slide); /* Relocate breakpoints as necessary, after things are relocated. */ @@ -965,9 +966,7 @@ objfile_has_full_symbols (struct objfile *objfile) int objfile_has_symbols (struct objfile *objfile) { - struct objfile *o; - - for (o = objfile; o; o = objfile_separate_debug_iterate (objfile, o)) + for (struct objfile *o : objfile->separate_debug_objfiles ()) if (objfile_has_partial_symbols (o) || objfile_has_full_symbols (o)) return 1; return 0; diff --git a/gdb/objfiles.h b/gdb/objfiles.h index 368d9f3abe2..168f7fc275b 100644 --- a/gdb/objfiles.h +++ b/gdb/objfiles.h @@ -318,6 +318,63 @@ struct objfile_per_bfd_storage std::bitset demangled_hash_languages; }; +/* An iterator that first returns a parent objfile, and then each + separate debug objfile. */ + +class separate_debug_iterator +{ +public: + + explicit separate_debug_iterator (struct objfile *objfile) + : m_objfile (objfile), + m_parent (objfile) + { + } + + bool operator!= (const separate_debug_iterator &other) + { + return m_objfile != other.m_objfile; + } + + separate_debug_iterator &operator++ (); + + struct objfile *operator* () + { + return m_objfile; + } + +private: + + struct objfile *m_objfile; + struct objfile *m_parent; +}; + +/* A range adapter wrapping separate_debug_iterator. */ + +class separate_debug_range +{ +public: + + explicit separate_debug_range (struct objfile *objfile) + : m_objfile (objfile) + { + } + + separate_debug_iterator begin () + { + return separate_debug_iterator (m_objfile); + } + + separate_debug_iterator end () + { + return separate_debug_iterator (nullptr); + } + +private: + + struct objfile *m_objfile; +}; + /* Master structure for keeping track of each file from which gdb reads symbols. There are several ways these get allocated: 1. The main symbol file, symfile_objfile, set by the symbol-file command, @@ -396,6 +453,14 @@ struct objfile return msymbols_range (this); } + /* Return a range adapter for iterating over all the separate debug + objfiles of this objfile. */ + + separate_debug_range separate_debug_objfiles () + { + return separate_debug_range (this); + } + /* All struct objfile's are chained together by their next pointers. The program space field "objfiles" (frequently referenced via @@ -563,9 +628,6 @@ extern CORE_ADDR entry_point_address (void); extern void build_objfile_section_table (struct objfile *); -extern struct objfile *objfile_separate_debug_iterate (const struct objfile *, - const struct objfile *); - extern void put_objfile_before (struct objfile *, struct objfile *); extern void add_separate_debug_objfile (struct objfile *, struct objfile *); diff --git a/gdb/symtab.c b/gdb/symtab.c index d25f560f084..16e641a830b 100644 --- a/gdb/symtab.c +++ b/gdb/symtab.c @@ -2246,11 +2246,7 @@ lookup_global_symbol_from_objfile (struct objfile *main_objfile, const char *name, const domain_enum domain) { - struct objfile *objfile; - - for (objfile = main_objfile; - objfile; - objfile = objfile_separate_debug_iterate (main_objfile, objfile)) + for (struct objfile *objfile : main_objfile->separate_debug_objfiles ()) { struct block_symbol result = lookup_symbol_in_objfile (objfile, GLOBAL_BLOCK, name, domain); @@ -2327,7 +2323,7 @@ lookup_symbol_in_objfile_from_linkage_name (struct objfile *objfile, domain_enum domain) { enum language lang = current_language->la_language; - struct objfile *main_objfile, *cur_objfile; + struct objfile *main_objfile; demangle_result_storage storage; const char *modified_name = demangle_for_lookup (linkage_name, lang, storage); @@ -2337,9 +2333,7 @@ lookup_symbol_in_objfile_from_linkage_name (struct objfile *objfile, else main_objfile = objfile; - for (cur_objfile = main_objfile; - cur_objfile; - cur_objfile = objfile_separate_debug_iterate (main_objfile, cur_objfile)) + for (struct objfile *cur_objfile : main_objfile->separate_debug_objfiles ()) { struct block_symbol result;