public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Tom Tromey <tromey@adacore.com>
To: gdb-patches@sourceware.org
Subject: [PATCH 1/5] Introduce lookup_minimal_symbol_linkage
Date: Tue, 14 Mar 2023 14:04:45 -0600	[thread overview]
Message-ID: <20230314-submit-pragma-import-export-v1-1-a235709f7e96@adacore.com> (raw)
In-Reply-To: <20230314-submit-pragma-import-export-v1-0-a235709f7e96@adacore.com>

This introduces a new function, lookup_minimal_symbol_linkage, and
refactors a couple other existing functions to call it.  This function
will be used in a subsequent patch.
---
 gdb/minsyms.c | 22 ++++++++++++++++++++++
 gdb/minsyms.h |  8 ++++++++
 gdb/symtab.c  | 31 ++++++++-----------------------
 3 files changed, 38 insertions(+), 23 deletions(-)

diff --git a/gdb/minsyms.c b/gdb/minsyms.c
index 02e36cc6dd2..aed37978bb9 100644
--- a/gdb/minsyms.c
+++ b/gdb/minsyms.c
@@ -592,6 +592,28 @@ lookup_minimal_symbol_linkage (const char *name, struct objfile *objf)
 
 /* See minsyms.h.  */
 
+struct bound_minimal_symbol
+lookup_minimal_symbol_linkage (const char *name, bool only_main)
+{
+  for (objfile *objfile : current_program_space->objfiles ())
+    {
+      if (objfile->separate_debug_objfile_backlink != nullptr)
+	continue;
+
+      if (only_main && (objfile->flags & OBJF_MAINLINE) == 0)
+	continue;
+
+      bound_minimal_symbol minsym = lookup_minimal_symbol_linkage (name,
+								   objfile);
+      if (minsym.minsym != nullptr)
+	return minsym;
+    }
+
+  return {};
+}
+
+/* See minsyms.h.  */
+
 struct bound_minimal_symbol
 lookup_minimal_symbol_text (const char *name, struct objfile *objf)
 {
diff --git a/gdb/minsyms.h b/gdb/minsyms.h
index e9081495eb1..40513b148ff 100644
--- a/gdb/minsyms.h
+++ b/gdb/minsyms.h
@@ -236,6 +236,14 @@ extern struct bound_minimal_symbol lookup_minimal_symbol_linkage
   (const char *name, struct objfile *objf)
   ATTRIBUTE_NONNULL (1) ATTRIBUTE_NONNULL (2);
 
+/* A variant of lookup_minimal_symbol_linkage that iterates over all
+   objfiles.  If ONLY_MAIN is true, then only an objfile with
+   OBJF_MAINLINE will be considered.  */
+
+extern struct bound_minimal_symbol lookup_minimal_symbol_linkage
+  (const char *name, bool only_main)
+  ATTRIBUTE_NONNULL (1);
+
 /* Look through all the current minimal symbol tables and find the
    first minimal symbol that matches NAME and PC.  If OBJF is non-NULL,
    limit the search to that objfile.  Returns a pointer to the minimal
diff --git a/gdb/symtab.c b/gdb/symtab.c
index e11f9262a22..80395f99f24 100644
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -6475,17 +6475,10 @@ get_symbol_address (const struct symbol *sym)
   gdb_assert (sym->aclass () == LOC_STATIC);
 
   const char *linkage_name = sym->linkage_name ();
-
-  for (objfile *objfile : current_program_space->objfiles ())
-    {
-      if (objfile->separate_debug_objfile_backlink != nullptr)
-	continue;
-
-      bound_minimal_symbol minsym
-	= lookup_minimal_symbol_linkage (linkage_name, objfile);
-      if (minsym.minsym != nullptr)
-	return minsym.value_address ();
-    }
+  bound_minimal_symbol minsym = lookup_minimal_symbol_linkage (linkage_name,
+							       false);
+  if (minsym.minsym != nullptr)
+    return minsym.value_address ();
   return sym->m_value.address;
 }
 
@@ -6498,18 +6491,10 @@ get_msymbol_address (struct objfile *objf, const struct minimal_symbol *minsym)
   gdb_assert ((objf->flags & OBJF_MAINLINE) == 0);
 
   const char *linkage_name = minsym->linkage_name ();
-
-  for (objfile *objfile : current_program_space->objfiles ())
-    {
-      if (objfile->separate_debug_objfile_backlink == nullptr
-	  && (objfile->flags & OBJF_MAINLINE) != 0)
-	{
-	  bound_minimal_symbol found
-	    = lookup_minimal_symbol_linkage (linkage_name, objfile);
-	  if (found.minsym != nullptr)
-	    return found.value_address ();
-	}
-    }
+  bound_minimal_symbol found = lookup_minimal_symbol_linkage (linkage_name,
+							      true);
+  if (found.minsym != nullptr)
+    return found.value_address ();
   return (minsym->m_value.address
 	  + objf->section_offsets[minsym->section_index ()]);
 }

-- 
2.39.1


  reply	other threads:[~2023-03-14 20:04 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-14 20:04 [PATCH 0/5] Implement Ada Pragma Import and Pragma Export Tom Tromey
2023-03-14 20:04 ` Tom Tromey [this message]
2023-03-14 20:04 ` [PATCH 2/5] Bump MAX_SYMBOL_IMPLS Tom Tromey
2023-03-14 20:04 ` [PATCH 3/5] Define symbol::value_block separately Tom Tromey
2023-03-14 20:04 ` [PATCH 4/5] Introduce symbol_block_ops::get_block_value Tom Tromey
2023-03-14 20:04 ` [PATCH 5/5] Handle Ada Pragma Import and Pragma Export Tom Tromey
2023-03-29 16:10 ` [PATCH 0/5] Implement " Tom Tromey

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230314-submit-pragma-import-export-v1-1-a235709f7e96@adacore.com \
    --to=tromey@adacore.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).