public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Tom Tromey <tromey@adacore.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tromey@adacore.com>
Subject: [PATCH] Use unrelocated_addr in dwarf2_base_index_functions::find_per_cu
Date: Thu, 14 Dec 2023 13:15:23 -0700	[thread overview]
Message-ID: <20231214201523.3370294-1-tromey@adacore.com> (raw)

dwarf2_base_index_functions::find_per_cu is documented as using an
unrelocated address.  This patch changes the interface to use the
unrelocated_addr type, just to be a bit more type-safe.

Regression tested on x86-64 Fedora 38.
---
 gdb/dwarf2/cooked-index.c |  2 +-
 gdb/dwarf2/cooked-index.h |  7 ++++---
 gdb/dwarf2/read.c         | 15 ++++++++-------
 gdb/dwarf2/read.h         |  2 +-
 4 files changed, 14 insertions(+), 12 deletions(-)

diff --git a/gdb/dwarf2/cooked-index.c b/gdb/dwarf2/cooked-index.c
index ba77f9cb373..785f1684988 100644
--- a/gdb/dwarf2/cooked-index.c
+++ b/gdb/dwarf2/cooked-index.c
@@ -501,7 +501,7 @@ cooked_index::~cooked_index ()
 /* See cooked-index.h.  */
 
 dwarf2_per_cu_data *
-cooked_index::lookup (CORE_ADDR addr)
+cooked_index::lookup (unrelocated_addr addr)
 {
   for (const auto &index : m_vector)
     {
diff --git a/gdb/dwarf2/cooked-index.h b/gdb/dwarf2/cooked-index.h
index 5675ea68bb8..fdf7d25673d 100644
--- a/gdb/dwarf2/cooked-index.h
+++ b/gdb/dwarf2/cooked-index.h
@@ -307,9 +307,10 @@ class cooked_index_shard
   /* Look up ADDR in the address map, and return either the
      corresponding CU, or nullptr if the address could not be
      found.  */
-  dwarf2_per_cu_data *lookup (CORE_ADDR addr)
+  dwarf2_per_cu_data *lookup (unrelocated_addr addr)
   {
-    return static_cast<dwarf2_per_cu_data *> (m_addrmap->find (addr));
+    return (static_cast<dwarf2_per_cu_data *>
+	    (m_addrmap->find ((CORE_ADDR) addr)));
   }
 
   /* Create a new cooked_index_entry and register it with this object.
@@ -400,7 +401,7 @@ class cooked_index : public dwarf_scanner_base
   /* Look up ADDR in the address map, and return either the
      corresponding CU, or nullptr if the address could not be
      found.  */
-  dwarf2_per_cu_data *lookup (CORE_ADDR addr);
+  dwarf2_per_cu_data *lookup (unrelocated_addr addr);
 
   /* Return a new vector of all the addrmaps used by all the indexes
      held by this object.  */
diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 37cabe52ecc..009cb72daf1 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -2988,12 +2988,12 @@ recursively_find_pc_sect_compunit_symtab (struct compunit_symtab *cust,
 
 dwarf2_per_cu_data *
 dwarf2_base_index_functions::find_per_cu (dwarf2_per_bfd *per_bfd,
-					  CORE_ADDR adjusted_pc)
+					  unrelocated_addr adjusted_pc)
 {
   if (per_bfd->index_addrmap == nullptr)
     return nullptr;
 
-  void *obj = per_bfd->index_addrmap->find (adjusted_pc);
+  void *obj = per_bfd->index_addrmap->find ((CORE_ADDR) adjusted_pc);
   return static_cast<dwarf2_per_cu_data *> (obj);
 }
 
@@ -3010,8 +3010,8 @@ dwarf2_base_index_functions::find_pc_sect_compunit_symtab
   dwarf2_per_objfile *per_objfile = get_dwarf2_per_objfile (objfile);
 
   CORE_ADDR baseaddr = objfile->text_section_offset ();
-  struct dwarf2_per_cu_data *data = find_per_cu (per_objfile->per_bfd,
-						 pc - baseaddr);
+  struct dwarf2_per_cu_data *data
+    = find_per_cu (per_objfile->per_bfd, (unrelocated_addr) (pc - baseaddr));
   if (data == nullptr)
     return nullptr;
 
@@ -16486,7 +16486,7 @@ cooked_indexer::make_index (cutu_reader *reader)
 struct cooked_index_functions : public dwarf2_base_index_functions
 {
   dwarf2_per_cu_data *find_per_cu (dwarf2_per_bfd *per_bfd,
-				   CORE_ADDR adjusted_pc) override;
+				   unrelocated_addr adjusted_pc) override;
 
   struct compunit_symtab *find_compunit_symtab_by_address
     (struct objfile *objfile, CORE_ADDR address) override;
@@ -16569,7 +16569,7 @@ struct cooked_index_functions : public dwarf2_base_index_functions
 
 dwarf2_per_cu_data *
 cooked_index_functions::find_per_cu (dwarf2_per_bfd *per_bfd,
-				     CORE_ADDR adjusted_pc)
+				     unrelocated_addr adjusted_pc)
 {
   cooked_index *table
     = (gdb::checked_static_cast<cooked_index *>
@@ -16594,7 +16594,8 @@ cooked_index_functions::find_compunit_symtab_by_address
     return nullptr;
 
   CORE_ADDR baseaddr = objfile->data_section_offset ();
-  dwarf2_per_cu_data *per_cu = table->lookup (address - baseaddr);
+  dwarf2_per_cu_data *per_cu
+    = table->lookup ((unrelocated_addr) (address - baseaddr));
   if (per_cu == nullptr)
     return nullptr;
 
diff --git a/gdb/dwarf2/read.h b/gdb/dwarf2/read.h
index 6f97f641c8e..f28433ed91b 100644
--- a/gdb/dwarf2/read.h
+++ b/gdb/dwarf2/read.h
@@ -893,7 +893,7 @@ struct dwarf2_base_index_functions : public quick_symbol_functions
   /* A helper function that finds the per-cu object from an "adjusted"
      PC -- a PC with the base text offset removed.  */
   virtual dwarf2_per_cu_data *find_per_cu (dwarf2_per_bfd *per_bfd,
-					   CORE_ADDR adjusted_pc);
+					   unrelocated_addr adjusted_pc);
 
   struct compunit_symtab *find_pc_sect_compunit_symtab
     (struct objfile *objfile, struct bound_minimal_symbol msymbol,
-- 
2.43.0


             reply	other threads:[~2023-12-14 20:15 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-14 20:15 Tom Tromey [this message]
2024-01-09 14:06 ` 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=20231214201523.3370294-1-tromey@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).