public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH 0/6] Use unrelocate_addr in more places
@ 2023-03-21 19:18 Tom Tromey
  2023-03-21 19:18 ` [PATCH 1/6] Use function_view in gdb_bfd_lookup_symbol Tom Tromey
                   ` (6 more replies)
  0 siblings, 7 replies; 16+ messages in thread
From: Tom Tromey @ 2023-03-21 19:18 UTC (permalink / raw)
  To: gdb-patches

Minimal symbols, partial symbols, and partial symtabs all use
unrelocated addresses right now.  This series converts these to use
the unrelocated_addr type, revealing (I believe) a few latent bugs.

Regression tested on x86-64 Fedora 36.

Tom

---
Tom Tromey (6):
      Use function_view in gdb_bfd_lookup_symbol
      Move definition of unrelocated_addr earlier
      Use unrelocated_addr in partial symbol tables
      Use unrelocated_addr in psymbols
      Use unrelocated_addr in minimal symbols
      Rename "raw" to "unrelocated"

 gdb/coff-pe-read.c |  13 +++---
 gdb/coffread.c     |  12 +++---
 gdb/ctfread.c      |  27 +++++++------
 gdb/dbxread.c      | 114 ++++++++++++++++++++++++++++++++---------------------
 gdb/elfread.c      |  22 ++++++-----
 gdb/findvar.c      |   4 +-
 gdb/machoread.c    |   4 +-
 gdb/mdebugread.c   | 104 +++++++++++++++++++++++++++++-------------------
 gdb/minsyms.c      |  68 ++++++++++++++++----------------
 gdb/minsyms.h      |   6 +--
 gdb/mips-tdep.c    |   6 ++-
 gdb/mipsread.c     |   2 +-
 gdb/parse.c        |   2 +-
 gdb/printcmd.c     |   2 +-
 gdb/psympriv.h     |  42 ++++++++++----------
 gdb/psymtab.c      |  11 +++---
 gdb/solib-dsbt.c   |  17 ++++----
 gdb/solib-frv.c    |  15 +++----
 gdb/solib-svr4.c   |  20 +++++-----
 gdb/solib.c        |  31 ++++++---------
 gdb/solib.h        |  14 +++----
 gdb/stabsread.h    |   2 +-
 gdb/symmisc.c      |   2 +-
 gdb/symtab.c       |   2 +-
 gdb/symtab.h       |  43 ++++++++++++++++----
 gdb/xcoffread.c    |  55 +++++++++++++++-----------
 26 files changed, 358 insertions(+), 282 deletions(-)
---
base-commit: 70ea5a46bd926149fb4a9c3da32c2fc14f6e83c3
change-id: 20230321-submit-unrelocated-type-c256e0e7da50

Best regards,
-- 
Tom Tromey <tom@tromey.com>


^ permalink raw reply	[flat|nested] 16+ messages in thread

* [PATCH 1/6] Use function_view in gdb_bfd_lookup_symbol
  2023-03-21 19:18 [PATCH 0/6] Use unrelocate_addr in more places Tom Tromey
@ 2023-03-21 19:18 ` Tom Tromey
  2023-03-28 13:23   ` Simon Marchi
  2023-03-21 19:18 ` [PATCH 2/6] Move definition of unrelocated_addr earlier Tom Tromey
                   ` (5 subsequent siblings)
  6 siblings, 1 reply; 16+ messages in thread
From: Tom Tromey @ 2023-03-21 19:18 UTC (permalink / raw)
  To: gdb-patches

This changes gdb_bfd_lookup_symbol to use a function_view.  This
simplifies the code a little bit.
---
 gdb/solib-dsbt.c | 17 +++++++----------
 gdb/solib-frv.c  | 15 ++++++---------
 gdb/solib-svr4.c | 20 +++++++++-----------
 gdb/solib.c      | 29 ++++++++++++-----------------
 gdb/solib.h      | 14 +++++---------
 5 files changed, 39 insertions(+), 56 deletions(-)

diff --git a/gdb/solib-dsbt.c b/gdb/solib-dsbt.c
index 557df74eb00..866087ef3a5 100644
--- a/gdb/solib-dsbt.c
+++ b/gdb/solib-dsbt.c
@@ -662,14 +662,6 @@ enable_break_failure_warning (void)
 	     "and track explicitly loaded dynamic code."));
 }
 
-/* Helper function for gdb_bfd_lookup_symbol.  */
-
-static int
-cmp_name (const asymbol *sym, const void *data)
-{
-  return (strcmp (sym->name, (const char *) data) == 0);
-}
-
 /* The dynamic linkers has, as part of its debugger interface, support
    for arranging for the inferior to hit a breakpoint after mapping in
    the shared libraries.  This function enables that breakpoint.
@@ -759,8 +751,13 @@ enable_break (void)
 	    = info->interp_plt_sect_low + bfd_section_size (interp_sect);
 	}
 
-      addr = gdb_bfd_lookup_symbol (tmp_bfd.get (), cmp_name,
-				    "_dl_debug_state");
+      addr = (gdb_bfd_lookup_symbol
+	      (tmp_bfd.get (),
+	       [] (const asymbol *sym)
+	       {
+		 return strcmp (sym->name, "_dl_debug_state") == 0;
+	       }));
+
       if (addr != 0)
 	{
 	  if (solib_dsbt_debug)
diff --git a/gdb/solib-frv.c b/gdb/solib-frv.c
index 38aed7a6ca4..240b4da5d9d 100644
--- a/gdb/solib-frv.c
+++ b/gdb/solib-frv.c
@@ -472,14 +472,6 @@ enable_break_failure_warning (void)
 	   "and track explicitly loaded dynamic code."));
 }
 
-/* Helper function for gdb_bfd_lookup_symbol.  */
-
-static int
-cmp_name (const asymbol *sym, const void *data)
-{
-  return (strcmp (sym->name, (const char *) data) == 0);
-}
-
 /* Arrange for dynamic linker to hit breakpoint.
 
    The dynamic linkers has, as part of its debugger interface, support
@@ -602,7 +594,12 @@ enable_break2 (void)
 	    interp_plt_sect_low + bfd_section_size (interp_sect);
 	}
 
-      addr = gdb_bfd_lookup_symbol (tmp_bfd.get (), cmp_name, "_dl_debug_addr");
+      addr = (gdb_bfd_lookup_symbol
+	      (tmp_bfd.get (),
+	       [] (const asymbol *sym)
+	       {
+		 return strcmp (sym->name, "_dl_debug_addr") == 0;
+	       }));
 
       if (addr == 0)
 	{
diff --git a/gdb/solib-svr4.c b/gdb/solib-svr4.c
index b3f6b6adaf2..5a728939111 100644
--- a/gdb/solib-svr4.c
+++ b/gdb/solib-svr4.c
@@ -2301,14 +2301,6 @@ svr4_create_solib_event_breakpoints (svr4_info *info, struct gdbarch *gdbarch,
     }
 }
 
-/* Helper function for gdb_bfd_lookup_symbol.  */
-
-static int
-cmp_name_and_sec_flags (const asymbol *sym, const void *data)
-{
-  return (strcmp (sym->name, (const char *) data) == 0
-	  && (sym->section->flags & (SEC_CODE | SEC_DATA)) != 0);
-}
 /* Arrange for dynamic linker to hit breakpoint.
 
    Both the SunOS and the SVR4 dynamic linkers have, as part of their
@@ -2553,9 +2545,15 @@ enable_break (struct svr4_info *info, int from_tty)
       /* Now try to set a breakpoint in the dynamic linker.  */
       for (bkpt_namep = solib_break_names; *bkpt_namep != NULL; bkpt_namep++)
 	{
-	  sym_addr = gdb_bfd_lookup_symbol (tmp_bfd.get (),
-					    cmp_name_and_sec_flags,
-					    *bkpt_namep);
+	  sym_addr
+	    = (gdb_bfd_lookup_symbol
+	       (tmp_bfd.get (),
+		[=] (const asymbol *sym)
+		{
+		  return (strcmp (sym->name, *bkpt_namep) == 0
+			  && ((sym->section->flags & (SEC_CODE | SEC_DATA))
+			      != 0));
+		}));
 	  if (sym_addr != 0)
 	    break;
 	}
diff --git a/gdb/solib.c b/gdb/solib.c
index ce10fc5aaf2..e6bccc85ca7 100644
--- a/gdb/solib.c
+++ b/gdb/solib.c
@@ -1475,13 +1475,11 @@ show_auto_solib_add (struct ui_file *file, int from_tty,
 /* Lookup the value for a specific symbol from dynamic symbol table.  Look
    up symbol from ABFD.  MATCH_SYM is a callback function to determine
    whether to pick up a symbol.  DATA is the input of this callback
-   function.  Return NULL if symbol is not found.  */
+   function.  Return 0 if symbol is not found.  */
 
 CORE_ADDR
-gdb_bfd_lookup_symbol_from_symtab (bfd *abfd,
-				   int (*match_sym) (const asymbol *,
-						     const void *),
-				   const void *data)
+gdb_bfd_lookup_symbol_from_symtab
+     (bfd *abfd, gdb::function_view<bool (const asymbol *)> match_sym)
 {
   long storage_needed = bfd_get_symtab_upper_bound (abfd);
   CORE_ADDR symaddr = 0;
@@ -1499,7 +1497,7 @@ gdb_bfd_lookup_symbol_from_symtab (bfd *abfd,
 	{
 	  asymbol *sym  = *symbol_table++;
 
-	  if (match_sym (sym, data))
+	  if (match_sym (sym))
 	    {
 	      struct gdbarch *gdbarch = target_gdbarch ();
 	      symaddr = sym->value;
@@ -1675,10 +1673,8 @@ gdb_bfd_read_elf_soname (const char *filename)
    if symbol is not found.  */
 
 static CORE_ADDR
-bfd_lookup_symbol_from_dyn_symtab (bfd *abfd,
-				   int (*match_sym) (const asymbol *,
-						     const void *),
-				   const void *data)
+bfd_lookup_symbol_from_dyn_symtab
+     (bfd *abfd, gdb::function_view<bool (const asymbol *)> match_sym)
 {
   long storage_needed = bfd_get_dynamic_symtab_upper_bound (abfd);
   CORE_ADDR symaddr = 0;
@@ -1695,7 +1691,7 @@ bfd_lookup_symbol_from_dyn_symtab (bfd *abfd,
 	{
 	  asymbol *sym = *symbol_table++;
 
-	  if (match_sym (sym, data))
+	  if (match_sym (sym))
 	    {
 	      /* BFD symbols are section relative.  */
 	      symaddr = sym->value + sym->section->vma;
@@ -1709,20 +1705,19 @@ bfd_lookup_symbol_from_dyn_symtab (bfd *abfd,
 /* Lookup the value for a specific symbol from symbol table and dynamic
    symbol table.  Look up symbol from ABFD.  MATCH_SYM is a callback
    function to determine whether to pick up a symbol.  DATA is the
-   input of this callback function.  Return NULL if symbol is not
+   input of this callback function.  Return 0 if symbol is not
    found.  */
 
 CORE_ADDR
-gdb_bfd_lookup_symbol (bfd *abfd,
-		       int (*match_sym) (const asymbol *, const void *),
-		       const void *data)
+gdb_bfd_lookup_symbol
+     (bfd *abfd, gdb::function_view<bool (const asymbol *)> match_sym)
 {
-  CORE_ADDR symaddr = gdb_bfd_lookup_symbol_from_symtab (abfd, match_sym, data);
+  CORE_ADDR symaddr = gdb_bfd_lookup_symbol_from_symtab (abfd, match_sym);
 
   /* On FreeBSD, the dynamic linker is stripped by default.  So we'll
      have to check the dynamic string table too.  */
   if (symaddr == 0)
-    symaddr = bfd_lookup_symbol_from_dyn_symtab (abfd, match_sym, data);
+    symaddr = bfd_lookup_symbol_from_dyn_symtab (abfd, match_sym);
 
   return symaddr;
 }
diff --git a/gdb/solib.h b/gdb/solib.h
index 24c365a0ae0..77e023002ed 100644
--- a/gdb/solib.h
+++ b/gdb/solib.h
@@ -28,6 +28,7 @@ struct program_space;
 
 #include "gdb_bfd.h"
 #include "symfile-add-flags.h"
+#include "gdbsupport/function-view.h"
 
 /* Value of the 'set debug solib' configuration variable.  */
 
@@ -107,18 +108,13 @@ extern bool libpthread_name_p (const char *name);
 
 /* Look up symbol from both symbol table and dynamic string table.  */
 
-extern CORE_ADDR gdb_bfd_lookup_symbol (bfd *abfd,
-					int (*match_sym) (const asymbol *,
-							  const void *),
-					const void *data);
+extern CORE_ADDR gdb_bfd_lookup_symbol
+     (bfd *abfd, gdb::function_view<bool (const asymbol *)> match_sym);
 
 /* Look up symbol from symbol table.  */
 
-extern CORE_ADDR gdb_bfd_lookup_symbol_from_symtab (bfd *abfd,
-						    int (*match_sym)
-						      (const asymbol *,
-						       const void *),
-						    const void *data);
+extern CORE_ADDR gdb_bfd_lookup_symbol_from_symtab
+     (bfd *abfd, gdb::function_view<bool (const asymbol *)> match_sym);
 
 /* Scan for DESIRED_DYNTAG in .dynamic section of ABFD.  If DESIRED_DYNTAG is
    found, 1 is returned and the corresponding PTR and PTR_ADDR are set.  */

-- 
2.39.1


^ permalink raw reply	[flat|nested] 16+ messages in thread

* [PATCH 2/6] Move definition of unrelocated_addr earlier
  2023-03-21 19:18 [PATCH 0/6] Use unrelocate_addr in more places Tom Tromey
  2023-03-21 19:18 ` [PATCH 1/6] Use function_view in gdb_bfd_lookup_symbol Tom Tromey
@ 2023-03-21 19:18 ` Tom Tromey
  2023-03-21 19:18 ` [PATCH 3/6] Use unrelocated_addr in partial symbol tables Tom Tromey
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 16+ messages in thread
From: Tom Tromey @ 2023-03-21 19:18 UTC (permalink / raw)
  To: gdb-patches

This moves the definition of unrelocated_addr a bit earlier in
symtab.h, so that it can be used elsewhere in the file.
---
 gdb/symtab.h | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/gdb/symtab.h b/gdb/symtab.h
index 2fd56ce21bd..347f2d1fd1e 100644
--- a/gdb/symtab.h
+++ b/gdb/symtab.h
@@ -58,6 +58,12 @@ class probe;
 struct lookup_name_info;
 struct code_breakpoint;
 
+/* Like a CORE_ADDR, but not directly convertible.  This is used to
+   represent an unrelocated CORE_ADDR.  DEFINE_OFFSET_TYPE is not used
+   here because there's no need to add or subtract values of this
+   type.  */
+enum class unrelocated_addr : CORE_ADDR { };
+
 /* How to match a lookup name against a symbol search name.  */
 enum class symbol_name_match_type
 {
@@ -1540,12 +1546,6 @@ struct rust_vtable_symbol : public symbol
 };
 
 \f
-/* Like a CORE_ADDR, but not directly convertible.  This is used to
-   represent an unrelocated CORE_ADDR.  DEFINE_OFFSET_TYPE is not used
-   here because there's no need to add or subtract values of this
-   type.  */
-enum class unrelocated_addr : CORE_ADDR { };
-
 /* Each item represents a line-->pc (or the reverse) mapping.  This is
    somewhat more wasteful of space than one might wish, but since only
    the files which are actually debugged are read in to core, we don't

-- 
2.39.1


^ permalink raw reply	[flat|nested] 16+ messages in thread

* [PATCH 3/6] Use unrelocated_addr in partial symbol tables
  2023-03-21 19:18 [PATCH 0/6] Use unrelocate_addr in more places Tom Tromey
  2023-03-21 19:18 ` [PATCH 1/6] Use function_view in gdb_bfd_lookup_symbol Tom Tromey
  2023-03-21 19:18 ` [PATCH 2/6] Move definition of unrelocated_addr earlier Tom Tromey
@ 2023-03-21 19:18 ` Tom Tromey
  2023-03-21 19:18 ` [PATCH 4/6] Use unrelocated_addr in psymbols Tom Tromey
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 16+ messages in thread
From: Tom Tromey @ 2023-03-21 19:18 UTC (permalink / raw)
  To: gdb-patches

This changes partial symbol tables to use unrelocated_addr for the
text_high and text_low members.  This revealed some latent bugs in
ctfread.c, which are fixed here.
---
 gdb/ctfread.c    | 15 +++++++-------
 gdb/dbxread.c    | 60 ++++++++++++++++++++++++++++++++------------------------
 gdb/mdebugread.c | 32 ++++++++++++++++++------------
 gdb/psympriv.h   | 30 +++++++++++++++-------------
 gdb/psymtab.c    |  4 ++--
 gdb/stabsread.h  |  2 +-
 gdb/xcoffread.c  | 15 ++++++++------
 7 files changed, 89 insertions(+), 69 deletions(-)

diff --git a/gdb/ctfread.c b/gdb/ctfread.c
index 42f2da7a88f..41411abef2b 100644
--- a/gdb/ctfread.c
+++ b/gdb/ctfread.c
@@ -127,7 +127,7 @@ struct ctf_psymtab : public standard_psymtab
   ctf_psymtab (const char *filename,
 	       psymtab_storage *partial_symtabs,
 	       objfile_per_bfd_storage *objfile_per_bfd,
-	       CORE_ADDR addr)
+	       unrelocated_addr addr)
     : standard_psymtab (filename, partial_symtabs, objfile_per_bfd, addr)
   {
   }
@@ -1232,10 +1232,10 @@ add_stt_func (struct ctf_context *ccp)
   add_stt_entries (ccp, 1);
 }
 
-/* Get text segment base for OBJFILE, TSIZE contains the segment size.  */
+/* Get text section base for OBJFILE, TSIZE contains the size.  */
 
 static CORE_ADDR
-get_objfile_text_range (struct objfile *of, int *tsize)
+get_objfile_text_range (struct objfile *of, size_t *tsize)
 {
   bfd *abfd = of->obfd.get ();
   const asection *codes;
@@ -1405,14 +1405,14 @@ ctf_psymtab::read_symtab (struct objfile *objfile)
 
       /* Start a symtab.  */
       CORE_ADDR offset;        /* Start of text segment.  */
-      int tsize;
+      size_t tsize;
 
       offset = get_objfile_text_range (objfile, &tsize);
       ctf_start_compunit_symtab (this, objfile, offset);
       expand_psymtab (objfile);
 
-      set_text_low (offset);
-      set_text_high (offset + tsize);
+      set_text_low (unrelocated_addr (0));
+      set_text_high (unrelocated_addr (tsize));
       compunit_symtab = ctf_end_compunit_symtab (this, offset + tsize);
 
       /* Finish up the debug error message.  */
@@ -1442,7 +1442,8 @@ create_partial_symtab (const char *name,
 {
   ctf_psymtab *pst;
 
-  pst = new ctf_psymtab (name, partial_symtabs, objfile->per_bfd, 0);
+  pst = new ctf_psymtab (name, partial_symtabs, objfile->per_bfd,
+			 unrelocated_addr (0));
 
   pst->context.arc = arc;
   pst->context.fp = cfp;
diff --git a/gdb/dbxread.c b/gdb/dbxread.c
index e5366ccd0d0..1ae527e9bf3 100644
--- a/gdb/dbxread.c
+++ b/gdb/dbxread.c
@@ -296,7 +296,7 @@ static void add_old_header_file (const char *, int);
 static void add_this_object_header_file (int);
 
 static legacy_psymtab *start_psymtab (psymtab_storage *, struct objfile *,
-				      const char *, CORE_ADDR, int);
+				      const char *, unrelocated_addr, int);
 
 /* Free up old header file tables.  */
 
@@ -1125,16 +1125,18 @@ read_dbx_symtab (minimal_symbol_reader &reader,
 	      || (namestring[(nsl = strlen (namestring)) - 1] == 'o'
 		  && namestring[nsl - 2] == '.'))
 	    {
+	      unrelocated_addr unrel_val = unrelocated_addr (nlist.n_value);
+
 	      if (past_first_source_file && pst
 		  /* The gould NP1 uses low values for .o and -l symbols
 		     which are not the address.  */
-		  && nlist.n_value >= pst->raw_text_low ())
+		  && unrel_val >= pst->raw_text_low ())
 		{
 		  dbx_end_psymtab (objfile, partial_symtabs,
 				   pst, psymtab_include_list,
 				   includes_used, symnum * symbol_size,
-				   nlist.n_value > pst->raw_text_high ()
-				   ? nlist.n_value : pst->raw_text_high (),
+				   unrel_val > pst->raw_text_high ()
+				   ? unrel_val : pst->raw_text_high (),
 				   dependency_list, dependencies_used,
 				   textlow_not_set);
 		  pst = (legacy_psymtab *) 0;
@@ -1246,11 +1248,12 @@ read_dbx_symtab (minimal_symbol_reader &reader,
 
 		if (pst)
 		  {
+		    unrelocated_addr unrel_value = unrelocated_addr (valu);
 		    dbx_end_psymtab (objfile, partial_symtabs,
 				     pst, psymtab_include_list,
 				     includes_used, symnum * symbol_size,
-				     (valu > pst->raw_text_high ()
-				      ? valu : pst->raw_text_high ()),
+				     (unrel_value > pst->raw_text_high ()
+				      ? unrel_value : pst->raw_text_high ()),
 				     dependency_list, dependencies_used,
 				     prev_textlow_not_set);
 		    pst = (legacy_psymtab *) 0;
@@ -1291,7 +1294,8 @@ read_dbx_symtab (minimal_symbol_reader &reader,
 	    if (!pst)
 	      {
 		pst = start_psymtab (partial_symtabs, objfile,
-				     namestring, valu,
+				     namestring,
+				     unrelocated_addr (valu),
 				     first_so_symnum * symbol_size);
 		pst->dirname = dirname_nso;
 		dirname_nso = NULL;
@@ -1416,13 +1420,14 @@ read_dbx_symtab (minimal_symbol_reader &reader,
 	  /* See if this is an end of function stab.  */
 	  if (pst && nlist.n_type == N_FUN && *namestring == '\000')
 	    {
-	      CORE_ADDR valu;
+	      unrelocated_addr valu;
 
 	      /* It's value is the size (in bytes) of the function for
 		 function relative stabs, or the address of the function's
 		 end for old style stabs.  */
-	      valu = nlist.n_value + last_function_start;
-	      if (pst->raw_text_high () == 0 || valu > pst->raw_text_high ())
+	      valu = unrelocated_addr (nlist.n_value + last_function_start);
+	      if (pst->raw_text_high () == unrelocated_addr (0)
+		  || valu > pst->raw_text_high ())
 		pst->set_text_high (valu);
 	      break;
 	    }
@@ -1673,7 +1678,7 @@ read_dbx_symtab (minimal_symbol_reader &reader,
 	      if (pst && textlow_not_set
 		  && gdbarch_sofun_address_maybe_missing (gdbarch))
 		{
-		  pst->set_text_low (nlist.n_value);
+		  pst->set_text_low (unrelocated_addr (nlist.n_value));
 		  textlow_not_set = 0;
 		}
 	      /* End kludge.  */
@@ -1688,10 +1693,11 @@ read_dbx_symtab (minimal_symbol_reader &reader,
 		 the partial symbol table.  */
 	      if (pst
 		  && (textlow_not_set
-		      || (nlist.n_value < pst->raw_text_low ()
+		      || (unrelocated_addr (nlist.n_value)
+			  < pst->raw_text_low ()
 			  && (nlist.n_value != 0))))
 		{
-		  pst->set_text_low (nlist.n_value);
+		  pst->set_text_low (unrelocated_addr (nlist.n_value));
 		  textlow_not_set = 0;
 		}
 	      if (pst != nullptr)
@@ -1729,7 +1735,7 @@ read_dbx_symtab (minimal_symbol_reader &reader,
 	      if (pst && textlow_not_set
 		  && gdbarch_sofun_address_maybe_missing (gdbarch))
 		{
-		  pst->set_text_low (nlist.n_value);
+		  pst->set_text_low (unrelocated_addr (nlist.n_value));
 		  textlow_not_set = 0;
 		}
 	      /* End kludge.  */
@@ -1744,10 +1750,11 @@ read_dbx_symtab (minimal_symbol_reader &reader,
 		 the partial symbol table.  */
 	      if (pst
 		  && (textlow_not_set
-		      || (nlist.n_value < pst->raw_text_low ()
+		      || (unrelocated_addr (nlist.n_value)
+			  < pst->raw_text_low ()
 			  && (nlist.n_value != 0))))
 		{
-		  pst->set_text_low (nlist.n_value);
+		  pst->set_text_low (unrelocated_addr (nlist.n_value));
 		  textlow_not_set = 0;
 		}
 	      if (pst != nullptr)
@@ -1871,7 +1878,7 @@ read_dbx_symtab (minimal_symbol_reader &reader,
 	      dbx_end_psymtab (objfile, partial_symtabs, pst,
 			       psymtab_include_list, includes_used,
 			       symnum * symbol_size,
-			       (CORE_ADDR) 0, dependency_list,
+			       (unrelocated_addr) 0, dependency_list,
 			       dependencies_used, textlow_not_set);
 	      pst = (legacy_psymtab *) 0;
 	      includes_used = 0;
@@ -1928,11 +1935,11 @@ read_dbx_symtab (minimal_symbol_reader &reader,
     {
       /* Don't set high text address of PST lower than it already
 	 is.  */
-      CORE_ADDR text_end =
-	(lowest_text_address == (CORE_ADDR) -1
-	 ? text_addr
-	 : lowest_text_address)
-	+ text_size;
+      unrelocated_addr text_end
+	= unrelocated_addr ((lowest_text_address == (CORE_ADDR) -1
+			     ? text_addr
+			     : lowest_text_address)
+			    + text_size);
 
       dbx_end_psymtab (objfile, partial_symtabs,
 		       pst, psymtab_include_list, includes_used,
@@ -1952,7 +1959,7 @@ read_dbx_symtab (minimal_symbol_reader &reader,
 
 static legacy_psymtab *
 start_psymtab (psymtab_storage *partial_symtabs, struct objfile *objfile,
-	       const char *filename, CORE_ADDR textlow, int ldsymoff)
+	       const char *filename, unrelocated_addr textlow, int ldsymoff)
 {
   legacy_psymtab *result = new legacy_psymtab (filename, partial_symtabs,
 					       objfile->per_bfd, textlow);
@@ -1983,7 +1990,7 @@ legacy_psymtab *
 dbx_end_psymtab (struct objfile *objfile, psymtab_storage *partial_symtabs,
 		 legacy_psymtab *pst,
 		 const char **include_list, int num_includes,
-		 int capping_symbol_offset, CORE_ADDR capping_text,
+		 int capping_symbol_offset, unrelocated_addr capping_text,
 		 legacy_psymtab **dependency_list,
 		 int number_dependencies,
 		 int textlow_not_set)
@@ -2037,8 +2044,9 @@ dbx_end_psymtab (struct objfile *objfile, psymtab_storage *partial_symtabs,
 	}
 
       if (minsym.minsym)
-	pst->set_text_high (minsym.minsym->value_raw_address ()
-			    + minsym.minsym->size ());
+	pst->set_text_high
+	  (unrelocated_addr (minsym.minsym->value_raw_address ()
+			     + minsym.minsym->size ()));
 
       last_function_name = NULL;
     }
diff --git a/gdb/mdebugread.c b/gdb/mdebugread.c
index 43542eae673..4bcda4b9d74 100644
--- a/gdb/mdebugread.c
+++ b/gdb/mdebugread.c
@@ -2601,7 +2601,7 @@ parse_partial_symbols (minimal_symbol_reader &reader,
     {
       legacy_psymtab *save_pst;
       EXTR *ext_ptr;
-      CORE_ADDR textlow;
+      unrelocated_addr textlow;
 
       cur_fdr = fh = debug_info->fdr + f_idx;
 
@@ -2614,9 +2614,9 @@ parse_partial_symbols (minimal_symbol_reader &reader,
       /* Determine the start address for this object file from the
 	 file header and relocate it, except for Irix 5.2 zero fh->adr.  */
       if (fh->cpd)
-	textlow = fh->adr;
+	textlow = unrelocated_addr (fh->adr);
       else
-	textlow = 0;
+	textlow = unrelocated_addr (0);
       pst = new legacy_psymtab (fdr_name (fh), partial_symtabs,
 				objfile->per_bfd, textlow);
       pst->read_symtab_private = XOBNEW (&objfile->objfile_obstack, md_symloc);
@@ -2695,7 +2695,7 @@ parse_partial_symbols (minimal_symbol_reader &reader,
 		{
 		  if (sh.st == stProc || sh.st == stStaticProc)
 		    {
-		      CORE_ADDR procaddr;
+		      unrelocated_addr procaddr;
 		      long isym;
 
 		      if (sh.st == stStaticProc)
@@ -2705,7 +2705,7 @@ parse_partial_symbols (minimal_symbol_reader &reader,
 						 mst_file_text, sh.sc,
 						 objfile);
 			}
-		      procaddr = sh.value;
+		      procaddr = unrelocated_addr (sh.value);
 
 		      isym = AUX_GET_ISYM (fh->fBigendian,
 					   (debug_info->external_aux
@@ -2718,7 +2718,9 @@ parse_partial_symbols (minimal_symbol_reader &reader,
 				      &sh);
 		      if (sh.st == stEnd)
 			{
-			  CORE_ADDR high = procaddr + sh.value;
+			  unrelocated_addr high
+			    = unrelocated_addr (CORE_ADDR (procaddr)
+						+ sh.value);
 
 			  /* Kludge for Irix 5.2 zero fh->adr.  */
 			  if (!relocatable
@@ -3304,8 +3306,12 @@ parse_partial_symbols (minimal_symbol_reader &reader,
 		    continue;
 
 		  case N_RBRAC:
-		    if (sh.value > save_pst->raw_text_high ())
-		      save_pst->set_text_high (sh.value);
+		    {
+		      unrelocated_addr unrel_value
+			= unrelocated_addr (sh.value);
+		      if (unrel_value > save_pst->raw_text_high ())
+			save_pst->set_text_high (unrel_value);
+		    }
 		    continue;
 		  case N_EINCL:
 		  case N_DSLINE:
@@ -3409,8 +3415,8 @@ parse_partial_symbols (minimal_symbol_reader &reader,
 
 	      switch (sh.st)
 		{
-		  CORE_ADDR high;
-		  CORE_ADDR procaddr;
+		  unrelocated_addr high;
+		  unrelocated_addr procaddr;
 		  int new_sdx;
 
 		case stStaticProc:
@@ -3479,7 +3485,7 @@ parse_partial_symbols (minimal_symbol_reader &reader,
 				      sh.value, psymtab_language,
 				      partial_symtabs, objfile);
 
-		  procaddr = sh.value;
+		  procaddr = unrelocated_addr (sh.value);
 
 		  cur_sdx = new_sdx;
 		  (*swap_sym_in) (cur_bfd,
@@ -3496,7 +3502,7 @@ parse_partial_symbols (minimal_symbol_reader &reader,
 			  || procaddr < pst->raw_text_low ()))
 		    pst->set_text_low (procaddr);
 
-		  high = procaddr + sh.value;
+		  high = unrelocated_addr (CORE_ADDR (procaddr) + sh.value);
 		  if (high > pst->raw_text_high ())
 		    pst->set_text_high (high);
 		  continue;
@@ -4005,7 +4011,7 @@ mdebug_expand_psymtab (legacy_psymtab *pst, struct objfile *objfile)
 
       if (! last_symtab_ended)
 	{
-	  cust = end_compunit_symtab (pst->raw_text_high ());
+	  cust = end_compunit_symtab (pst->text_high (objfile));
 	  end_stabs ();
 	}
 
diff --git a/gdb/psympriv.h b/gdb/psympriv.h
index 332d6a62686..8fb595e2e0b 100644
--- a/gdb/psympriv.h
+++ b/gdb/psympriv.h
@@ -130,7 +130,7 @@ struct partial_symtab
   partial_symtab (const char *filename,
 		  psymtab_storage *partial_symtabs,
 		  objfile_per_bfd_storage *objfile_per_bfd,
-		  CORE_ADDR addr)
+		  unrelocated_addr addr)
     ATTRIBUTE_NONNULL (2) ATTRIBUTE_NONNULL (3);
 
   virtual ~partial_symtab ()
@@ -171,14 +171,16 @@ struct partial_symtab
   virtual struct compunit_symtab *get_compunit_symtab
     (struct objfile *) const = 0;
 
-  /* Return the raw low text address of this partial_symtab.  */
-  CORE_ADDR raw_text_low () const
+  /* Return the unrelocated low text address of this
+     partial_symtab.  */
+  unrelocated_addr raw_text_low () const
   {
     return m_text_low;
   }
 
-  /* Return the raw high text address of this partial_symtab.  */
-  CORE_ADDR raw_text_high () const
+  /* Return the unrelocated_addr high text address of this
+     partial_symtab.  */
+  unrelocated_addr raw_text_high () const
   {
     return m_text_high;
   }
@@ -186,24 +188,24 @@ struct partial_symtab
   /* Return the relocated low text address of this partial_symtab.  */
   CORE_ADDR text_low (struct objfile *objfile) const
   {
-    return m_text_low + objfile->text_section_offset ();
+    return CORE_ADDR (m_text_low) + objfile->text_section_offset ();
   }
 
   /* Return the relocated high text address of this partial_symtab.  */
   CORE_ADDR text_high (struct objfile *objfile) const
   {
-    return m_text_high + objfile->text_section_offset ();
+    return CORE_ADDR (m_text_high) + objfile->text_section_offset ();
   }
 
   /* Set the low text address of this partial_symtab.  */
-  void set_text_low (CORE_ADDR addr)
+  void set_text_low (unrelocated_addr addr)
   {
     m_text_low = addr;
     text_low_valid = 1;
   }
 
-  /* Set the hight text address of this partial_symtab.  */
-  void set_text_high (CORE_ADDR addr)
+  /* Set the high text address of this partial_symtab.  */
+  void set_text_high (unrelocated_addr addr)
   {
     m_text_high = addr;
     text_high_valid = 1;
@@ -283,8 +285,8 @@ struct partial_symtab
      fields; these are located later in this structure for better
      packing.  */
 
-  CORE_ADDR m_text_low = 0;
-  CORE_ADDR m_text_high = 0;
+  unrelocated_addr m_text_low {};
+  unrelocated_addr m_text_high {};
 
   /* If NULL, this is an ordinary partial symbol table.
 
@@ -372,7 +374,7 @@ struct standard_psymtab : public partial_symtab
   standard_psymtab (const char *filename,
 		    psymtab_storage *partial_symtabs,
 		    objfile_per_bfd_storage *objfile_per_bfd,
-		    CORE_ADDR addr)
+		    unrelocated_addr addr)
     : partial_symtab (filename, partial_symtabs, objfile_per_bfd, addr)
   {
   }
@@ -414,7 +416,7 @@ struct legacy_psymtab : public standard_psymtab
   legacy_psymtab (const char *filename,
 		  psymtab_storage *partial_symtabs,
 		  objfile_per_bfd_storage *objfile_per_bfd,
-		  CORE_ADDR addr)
+		  unrelocated_addr addr)
     : standard_psymtab (filename, partial_symtabs, objfile_per_bfd, addr)
   {
   }
diff --git a/gdb/psymtab.c b/gdb/psymtab.c
index 95a53b90edd..484199b4be2 100644
--- a/gdb/psymtab.c
+++ b/gdb/psymtab.c
@@ -1110,7 +1110,7 @@ psymbol_functions::has_unexpanded_symtabs (struct objfile *objfile)
 partial_symtab::partial_symtab (const char *filename,
 				psymtab_storage *partial_symtabs,
 				objfile_per_bfd_storage *objfile_per_bfd,
-				CORE_ADDR textlow)
+				unrelocated_addr textlow)
   : partial_symtab (filename, partial_symtabs, objfile_per_bfd)
 {
   set_text_low (textlow);
@@ -1653,7 +1653,7 @@ maintenance_check_psymtabs (const char *ignore, int from_tty)
 		      gdb_printf (" psymtab\n");
 		    }
 		}
-	      if (ps->raw_text_high () != 0
+	      if (ps->raw_text_high () != unrelocated_addr (0)
 		  && (ps->text_low (objfile) < b->start ()
 		      || ps->text_high (objfile) > b->end ()))
 		{
diff --git a/gdb/stabsread.h b/gdb/stabsread.h
index 9df79bc7dfa..27ba176f63f 100644
--- a/gdb/stabsread.h
+++ b/gdb/stabsread.h
@@ -175,7 +175,7 @@ extern legacy_psymtab *dbx_end_psymtab
   (struct objfile *objfile, psymtab_storage *partial_symtabs,
    legacy_psymtab *pst,
    const char **include_list, int num_includes,
-   int capping_symbol_offset, CORE_ADDR capping_text,
+   int capping_symbol_offset, unrelocated_addr capping_text,
    legacy_psymtab **dependency_list, int number_dependencies,
    int textlow_not_set);
 
diff --git a/gdb/xcoffread.c b/gdb/xcoffread.c
index a07f40b5702..c829fb2aea0 100644
--- a/gdb/xcoffread.c
+++ b/gdb/xcoffread.c
@@ -1875,7 +1875,8 @@ xcoff_start_psymtab (psymtab_storage *partial_symtabs,
 {
   /* We fill in textlow later.  */
   legacy_psymtab *result = new legacy_psymtab (filename, partial_symtabs,
-					       objfile->per_bfd, 0);
+					       objfile->per_bfd,
+					       unrelocated_addr (0));
 
   result->read_symtab_private =
     XOBNEW (&objfile->objfile_obstack, struct xcoff_symloc);
@@ -2172,14 +2173,16 @@ scan_xcoff_symtab (minimal_symbol_reader &reader,
 		      }
 		    if (pst != NULL)
 		      {
-			CORE_ADDR highval =
-			  symbol.n_value + csect_aux.x_csect.x_scnlen.l;
+			unrelocated_addr highval
+			  = unrelocated_addr (symbol.n_value
+					      + csect_aux.x_csect.x_scnlen.l);
 
 			if (highval > pst->raw_text_high ())
 			  pst->set_text_high (highval);
-			if (!pst->text_low_valid
-			    || symbol.n_value < pst->raw_text_low ())
-			  pst->set_text_low (symbol.n_value);
+			unrelocated_addr loval
+			  = unrelocated_addr (symbol.n_value);
+			if (!pst->text_low_valid || loval < pst->raw_text_low ())
+			  pst->set_text_low (loval);
 		      }
 		    misc_func_recorded = 0;
 		    break;

-- 
2.39.1


^ permalink raw reply	[flat|nested] 16+ messages in thread

* [PATCH 4/6] Use unrelocated_addr in psymbols
  2023-03-21 19:18 [PATCH 0/6] Use unrelocate_addr in more places Tom Tromey
                   ` (2 preceding siblings ...)
  2023-03-21 19:18 ` [PATCH 3/6] Use unrelocated_addr in partial symbol tables Tom Tromey
@ 2023-03-21 19:18 ` Tom Tromey
  2023-03-21 19:18 ` [PATCH 5/6] Use unrelocated_addr in minimal symbols Tom Tromey
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 16+ messages in thread
From: Tom Tromey @ 2023-03-21 19:18 UTC (permalink / raw)
  To: gdb-patches

This changes psymbols themselves to use unrelocated_addr.  This
transform is largely mechanical.  I don't think it finds any bugs.
---
 gdb/ctfread.c    | 12 ++++++++----
 gdb/dbxread.c    | 27 ++++++++++++++++++---------
 gdb/mdebugread.c | 43 ++++++++++++++++++++++++++++---------------
 gdb/psympriv.h   | 12 ++++++------
 gdb/psymtab.c    |  5 +++--
 gdb/symtab.h     | 16 ++++++++++++++++
 gdb/xcoffread.c  | 23 ++++++++++++++---------
 7 files changed, 93 insertions(+), 45 deletions(-)

diff --git a/gdb/ctfread.c b/gdb/ctfread.c
index 41411abef2b..005862c1097 100644
--- a/gdb/ctfread.c
+++ b/gdb/ctfread.c
@@ -1291,7 +1291,8 @@ ctf_psymtab_add_enums (struct ctf_context *ccp, ctf_id_t tid)
       ccp->pst->add_psymbol (ename, true,
 			     VAR_DOMAIN, LOC_CONST, -1,
 			     psymbol_placement::GLOBAL,
-			     0, language_c, ccp->partial_symtabs, ccp->of);
+			     unrelocated_addr (0),
+			     language_c, ccp->partial_symtabs, ccp->of);
     }
   if (ctf_errno (ccp->fp) != ECTF_NEXT_END)
     complaint (_("ctf_enum_next ctf_psymtab_add_enums failed - %s"),
@@ -1336,7 +1337,8 @@ ctf_psymtab_add_stt_entries (ctf_dict_t *cfp, ctf_psymtab *pst,
       pst->add_psymbol (tname, true,
 			tdomain, aclass, -1,
 			psymbol_placement::GLOBAL,
-			0, language_c, pst->context.partial_symtabs, of);
+			unrelocated_addr (0),
+			language_c, pst->context.partial_symtabs, of);
     }
 }
 
@@ -1513,7 +1515,8 @@ ctf_psymtab_type_cb (ctf_id_t tid, void *arg)
   ccp->pst->add_psymbol (name, false,
 			 domain, aclass, section,
 			 psymbol_placement::STATIC,
-			 0, language_c, ccp->partial_symtabs, ccp->of);
+			 unrelocated_addr (0),
+			 language_c, ccp->partial_symtabs, ccp->of);
 
   return 0;
 }
@@ -1528,7 +1531,8 @@ ctf_psymtab_var_cb (const char *name, ctf_id_t id, void *arg)
   ccp->pst->add_psymbol (name, true,
 			 VAR_DOMAIN, LOC_STATIC, -1,
 			 psymbol_placement::GLOBAL,
-			 0, language_c, ccp->partial_symtabs, ccp->of);
+			 unrelocated_addr (0),
+			 language_c, ccp->partial_symtabs, ccp->of);
   return 0;
 }
 
diff --git a/gdb/dbxread.c b/gdb/dbxread.c
index 1ae527e9bf3..677e91d7725 100644
--- a/gdb/dbxread.c
+++ b/gdb/dbxread.c
@@ -1484,7 +1484,8 @@ read_dbx_symtab (minimal_symbol_reader &reader,
 				  VAR_DOMAIN, LOC_STATIC,
 				  data_sect_index,
 				  psymbol_placement::STATIC,
-				  nlist.n_value, psymtab_language,
+				  unrelocated_addr (nlist.n_value),
+				  psymtab_language,
 				  partial_symtabs, objfile);
 	      else
 		complaint (_("static `%*s' appears to be defined "
@@ -1500,7 +1501,8 @@ read_dbx_symtab (minimal_symbol_reader &reader,
 				  VAR_DOMAIN, LOC_STATIC,
 				  data_sect_index,
 				  psymbol_placement::GLOBAL,
-				  nlist.n_value, psymtab_language,
+				  unrelocated_addr (nlist.n_value),
+				  psymtab_language,
 				  partial_symtabs, objfile);
 	      else
 		complaint (_("global `%*s' appears to be defined "
@@ -1523,7 +1525,8 @@ read_dbx_symtab (minimal_symbol_reader &reader,
 		    pst->add_psymbol (gdb::string_view (sym_name, sym_len),
 				      true, STRUCT_DOMAIN, LOC_TYPEDEF, -1,
 				      psymbol_placement::STATIC,
-				      0, psymtab_language,
+				      unrelocated_addr (0),
+				      psymtab_language,
 				      partial_symtabs, objfile);
 		  else
 		    complaint (_("enum, struct, or union `%*s' appears "
@@ -1537,7 +1540,8 @@ read_dbx_symtab (minimal_symbol_reader &reader,
 			pst->add_psymbol (gdb::string_view (sym_name, sym_len),
 					  true, VAR_DOMAIN, LOC_TYPEDEF, -1,
 					  psymbol_placement::STATIC,
-					  0, psymtab_language,
+					  unrelocated_addr (0),
+					  psymtab_language,
 					  partial_symtabs, objfile);
 		      else
 			complaint (_("typedef `%*s' appears to be defined "
@@ -1555,7 +1559,8 @@ read_dbx_symtab (minimal_symbol_reader &reader,
 		    pst->add_psymbol (gdb::string_view (sym_name, sym_len),
 				      true, VAR_DOMAIN, LOC_TYPEDEF, -1,
 				      psymbol_placement::STATIC,
-				      0, psymtab_language,
+				      unrelocated_addr (0),
+				      psymtab_language,
 				      partial_symtabs, objfile);
 		  else
 		    complaint (_("typename `%*s' appears to be defined "
@@ -1621,7 +1626,8 @@ read_dbx_symtab (minimal_symbol_reader &reader,
 		      if (pst != nullptr)
 			pst->add_psymbol (gdb::string_view (p, q - p), true,
 					  VAR_DOMAIN, LOC_CONST, -1,
-					  psymbol_placement::STATIC, 0,
+					  psymbol_placement::STATIC,
+					  unrelocated_addr (0),
 					  psymtab_language,
 					  partial_symtabs, objfile);
 		      else
@@ -1645,7 +1651,8 @@ read_dbx_symtab (minimal_symbol_reader &reader,
 	      if (pst != nullptr)
 		pst->add_psymbol (gdb::string_view (sym_name, sym_len), true,
 				  VAR_DOMAIN, LOC_CONST, -1,
-				  psymbol_placement::STATIC, 0,
+				  psymbol_placement::STATIC,
+				  unrelocated_addr (0),
 				  psymtab_language,
 				  partial_symtabs, objfile);
 	      else
@@ -1705,7 +1712,8 @@ read_dbx_symtab (minimal_symbol_reader &reader,
 				  VAR_DOMAIN, LOC_BLOCK,
 				  SECT_OFF_TEXT (objfile),
 				  psymbol_placement::STATIC,
-				  nlist.n_value, psymtab_language,
+				  unrelocated_addr (nlist.n_value),
+				  psymtab_language,
 				  partial_symtabs, objfile);
 	      continue;
 
@@ -1762,7 +1770,8 @@ read_dbx_symtab (minimal_symbol_reader &reader,
 				  VAR_DOMAIN, LOC_BLOCK,
 				  SECT_OFF_TEXT (objfile),
 				  psymbol_placement::GLOBAL,
-				  nlist.n_value, psymtab_language,
+				  unrelocated_addr (nlist.n_value),
+				  psymtab_language,
 				  partial_symtabs, objfile);
 	      continue;
 
diff --git a/gdb/mdebugread.c b/gdb/mdebugread.c
index 4bcda4b9d74..e0415587646 100644
--- a/gdb/mdebugread.c
+++ b/gdb/mdebugread.c
@@ -3056,7 +3056,7 @@ parse_partial_symbols (minimal_symbol_reader &reader,
 					  true, VAR_DOMAIN, LOC_STATIC,
 					  SECT_OFF_DATA (objfile),
 					  psymbol_placement::STATIC,
-					  sh.value,
+					  unrelocated_addr (sh.value),
 					  psymtab_language,
 					  partial_symtabs, objfile);
 			continue;
@@ -3069,7 +3069,7 @@ parse_partial_symbols (minimal_symbol_reader &reader,
 					  true, VAR_DOMAIN, LOC_STATIC,
 					  SECT_OFF_DATA (objfile),
 					  psymbol_placement::GLOBAL,
-					  sh.value,
+					  unrelocated_addr (sh.value),
 					  psymtab_language,
 					  partial_symtabs, objfile);
 			continue;
@@ -3088,7 +3088,9 @@ parse_partial_symbols (minimal_symbol_reader &reader,
 			    pst->add_psymbol
 			      (gdb::string_view (namestring, p - namestring),
 			       true, STRUCT_DOMAIN, LOC_TYPEDEF, -1,
-			       psymbol_placement::STATIC, 0, psymtab_language,
+			       psymbol_placement::STATIC,
+			       unrelocated_addr (0),
+			       psymtab_language,
 			       partial_symtabs, objfile);
 			    if (p[2] == 't')
 			      {
@@ -3097,7 +3099,8 @@ parse_partial_symbols (minimal_symbol_reader &reader,
 				  (gdb::string_view (namestring,
 						     p - namestring),
 				   true, VAR_DOMAIN, LOC_TYPEDEF, -1,
-				   psymbol_placement::STATIC, 0,
+				   psymbol_placement::STATIC,
+				   unrelocated_addr (0),
 				   psymtab_language,
 				   partial_symtabs, objfile);
 				p += 1;
@@ -3112,7 +3115,9 @@ parse_partial_symbols (minimal_symbol_reader &reader,
 			      (gdb::string_view (namestring,
 						 p - namestring),
 			       true, VAR_DOMAIN, LOC_TYPEDEF, -1,
-			       psymbol_placement::STATIC, 0, psymtab_language,
+			       psymbol_placement::STATIC,
+			       unrelocated_addr (0),
+			       psymtab_language,
 			       partial_symtabs, objfile);
 			  }
 		      check_enum:
@@ -3179,7 +3184,8 @@ parse_partial_symbols (minimal_symbol_reader &reader,
 						  true, VAR_DOMAIN,
 						  LOC_CONST, -1,
 						  psymbol_placement::STATIC,
-						  0, psymtab_language,
+						  unrelocated_addr (0),
+						  psymtab_language,
 						  partial_symtabs, objfile);
 				/* Point past the name.  */
 				p = q;
@@ -3198,7 +3204,8 @@ parse_partial_symbols (minimal_symbol_reader &reader,
 							    p - namestring),
 					  true, VAR_DOMAIN, LOC_CONST, -1,
 					  psymbol_placement::STATIC,
-					  0, psymtab_language,
+					  unrelocated_addr (0),
+					  psymtab_language,
 					  partial_symtabs, objfile);
 			continue;
 
@@ -3214,7 +3221,7 @@ parse_partial_symbols (minimal_symbol_reader &reader,
 					  true, VAR_DOMAIN, LOC_BLOCK,
 					  SECT_OFF_TEXT (objfile),
 					  psymbol_placement::STATIC,
-					  sh.value,
+					  unrelocated_addr (sh.value),
 					  psymtab_language,
 					  partial_symtabs, objfile);
 			continue;
@@ -3235,7 +3242,7 @@ parse_partial_symbols (minimal_symbol_reader &reader,
 					  true, VAR_DOMAIN, LOC_BLOCK,
 					  SECT_OFF_TEXT (objfile),
 					  psymbol_placement::GLOBAL,
-					  sh.value,
+					  unrelocated_addr (sh.value),
 					  psymtab_language,
 					  partial_symtabs, objfile);
 			continue;
@@ -3475,14 +3482,16 @@ parse_partial_symbols (minimal_symbol_reader &reader,
 				      VAR_DOMAIN, LOC_BLOCK,
 				      section,
 				      psymbol_placement::GLOBAL,
-				      sh.value, psymtab_language,
+				      unrelocated_addr (sh.value),
+				      psymtab_language,
 				      partial_symtabs, objfile);
 		  else
 		    pst->add_psymbol (sym_name, true,
 				      VAR_DOMAIN, LOC_BLOCK,
 				      section,
 				      psymbol_placement::STATIC,
-				      sh.value, psymtab_language,
+				      unrelocated_addr (sh.value),
+				      psymtab_language,
 				      partial_symtabs, objfile);
 
 		  procaddr = unrelocated_addr (sh.value);
@@ -3549,7 +3558,8 @@ parse_partial_symbols (minimal_symbol_reader &reader,
 		      pst->add_psymbol (sym_name, true,
 					STRUCT_DOMAIN, LOC_TYPEDEF, -1,
 					psymbol_placement::STATIC,
-					0, psymtab_language,
+					unrelocated_addr (0),
+					psymtab_language,
 					partial_symtabs, objfile);
 		    }
 		  handle_psymbol_enumerators (objfile, partial_symtabs,
@@ -3591,7 +3601,8 @@ parse_partial_symbols (minimal_symbol_reader &reader,
 	      pst->add_psymbol (sym_name, true,
 				VAR_DOMAIN, theclass, section,
 				psymbol_placement::STATIC,
-				sh.value, psymtab_language,
+				unrelocated_addr (sh.value),
+				psymtab_language,
 				partial_symtabs, objfile);
 	    skip:
 	      cur_sdx++;	/* Go to next file symbol.  */
@@ -3671,7 +3682,8 @@ parse_partial_symbols (minimal_symbol_reader &reader,
 				VAR_DOMAIN, theclass,
 				section,
 				psymbol_placement::GLOBAL,
-				svalue, psymtab_language,
+				unrelocated_addr (svalue),
+				psymtab_language,
 				partial_symtabs, objfile);
 	    }
 	}
@@ -3805,7 +3817,8 @@ handle_psymbol_enumerators (struct objfile *objfile,
 	 in psymtabs, just in symtabs.  */
       pst->add_psymbol (name, true,
 			VAR_DOMAIN, LOC_CONST, -1,
-			psymbol_placement::STATIC, 0,
+			psymbol_placement::STATIC,
+			unrelocated_addr (0),
 			psymtab_language, partial_symtabs, objfile);
       ext_sym += external_sym_size;
     }
diff --git a/gdb/psympriv.h b/gdb/psympriv.h
index 8fb595e2e0b..8f059dc5975 100644
--- a/gdb/psympriv.h
+++ b/gdb/psympriv.h
@@ -44,24 +44,24 @@ struct partial_symbol
   }
 
   /* Return the unrelocated address of this partial symbol.  */
-  CORE_ADDR unrelocated_address () const
+  unrelocated_addr unrelocated_address () const
   {
-    return ginfo.value_address ();
+    return ginfo.unrelocated_address ();
   }
 
   /* Return the address of this partial symbol, relocated according to
      the offsets provided in OBJFILE.  */
   CORE_ADDR address (const struct objfile *objfile) const
   {
-    return (ginfo.value_address ()
+    return (CORE_ADDR (ginfo.unrelocated_address ())
 	    + objfile->section_offsets[ginfo.section_index ()]);
   }
 
   /* Set the address of this partial symbol.  The address must be
      unrelocated.  */
-  void set_unrelocated_address (CORE_ADDR addr)
+  void set_unrelocated_address (unrelocated_addr addr)
   {
-    ginfo.set_value_address (addr);
+    ginfo.set_unrelocated_address (addr);
   }
 
   /* Note that partial_symbol does not derive from general_symbol_info
@@ -241,7 +241,7 @@ struct partial_symtab
 		    enum address_class theclass,
 		    short section,
 		    psymbol_placement where,
-		    CORE_ADDR coreaddr,
+		    unrelocated_addr coreaddr,
 		    enum language language,
 		    psymtab_storage *partial_symtabs,
 		    struct objfile *objfile);
diff --git a/gdb/psymtab.c b/gdb/psymtab.c
index 484199b4be2..c74280761dd 100644
--- a/gdb/psymtab.c
+++ b/gdb/psymtab.c
@@ -675,7 +675,8 @@ print_partial_symbols (struct gdbarch *gdbarch, struct objfile *objfile,
 	  break;
 	}
       gdb_puts (", ", outfile);
-      gdb_puts (paddress (gdbarch, p->unrelocated_address ()), outfile);
+      gdb_puts (paddress (gdbarch, CORE_ADDR (p->unrelocated_address ())),
+		outfile);
       gdb_printf (outfile, "\n");
     }
 }
@@ -1212,7 +1213,7 @@ partial_symtab::add_psymbol (gdb::string_view name, bool copy_name,
 			     enum address_class theclass,
 			     short section,
 			     psymbol_placement where,
-			     CORE_ADDR coreaddr,
+			     unrelocated_addr coreaddr,
 			     enum language language,
 			     psymtab_storage *partial_symtabs,
 			     struct objfile *objfile)
diff --git a/gdb/symtab.h b/gdb/symtab.h
index 347f2d1fd1e..4d760863081 100644
--- a/gdb/symtab.h
+++ b/gdb/symtab.h
@@ -530,6 +530,18 @@ struct general_symbol_info
     m_value.address = address;
   }
 
+  /* Return the unrelocated address of this symbol.  */
+  unrelocated_addr unrelocated_address () const
+  {
+    return m_value.unrel_addr;
+  }
+
+  /* Set the unrelocated address of this symbol.  */
+  void set_unrelocated_address (unrelocated_addr addr)
+  {
+    m_value.unrel_addr = addr;
+  }
+
   /* Name of the symbol.  This is a required field.  Storage for the
      name is allocated on the objfile_obstack for the associated
      objfile.  For languages like C++ that make a distinction between
@@ -554,6 +566,10 @@ struct general_symbol_info
 
     CORE_ADDR address;
 
+    /* The address, if unrelocated.  An unrelocated symbol does not
+       have the runtime section offset applied.  */
+    unrelocated_addr unrel_addr;
+
     /* A common block.  Used with LOC_COMMON_BLOCK.  */
 
     const struct common_block *common_block;
diff --git a/gdb/xcoffread.c b/gdb/xcoffread.c
index c829fb2aea0..5c20468e9e4 100644
--- a/gdb/xcoffread.c
+++ b/gdb/xcoffread.c
@@ -2499,7 +2499,7 @@ scan_xcoff_symtab (minimal_symbol_reader &reader,
 				  true, VAR_DOMAIN, LOC_STATIC,
 				  SECT_OFF_DATA (objfile),
 				  psymbol_placement::STATIC,
-				  symbol.n_value,
+				  unrelocated_addr (symbol.n_value),
 				  psymtab_language,
 				  partial_symtabs, objfile);
 		continue;
@@ -2512,7 +2512,7 @@ scan_xcoff_symtab (minimal_symbol_reader &reader,
 				  true, VAR_DOMAIN, LOC_STATIC,
 				  SECT_OFF_DATA (objfile),
 				  psymbol_placement::GLOBAL,
-				  symbol.n_value,
+				  unrelocated_addr (symbol.n_value),
 				  psymtab_language,
 				  partial_symtabs, objfile);
 		continue;
@@ -2532,7 +2532,8 @@ scan_xcoff_symtab (minimal_symbol_reader &reader,
 							p - namestring),
 				      true, STRUCT_DOMAIN, LOC_TYPEDEF, -1,
 				      psymbol_placement::STATIC,
-				      0, psymtab_language,
+				      unrelocated_addr (0),
+				      psymtab_language,
 				      partial_symtabs, objfile);
 		    if (p[2] == 't')
 		      {
@@ -2541,7 +2542,8 @@ scan_xcoff_symtab (minimal_symbol_reader &reader,
 							    p - namestring),
 					  true, VAR_DOMAIN, LOC_TYPEDEF, -1,
 					  psymbol_placement::STATIC,
-					  0, psymtab_language,
+					  unrelocated_addr (0),
+					  psymtab_language,
 					  partial_symtabs, objfile);
 			p += 1;
 		      }
@@ -2555,7 +2557,8 @@ scan_xcoff_symtab (minimal_symbol_reader &reader,
 							p - namestring),
 				      true, VAR_DOMAIN, LOC_TYPEDEF, -1,
 				      psymbol_placement::STATIC,
-				      0, psymtab_language,
+				      unrelocated_addr (0),
+				      psymtab_language,
 				      partial_symtabs, objfile);
 		  }
 	      check_enum:
@@ -2618,7 +2621,8 @@ scan_xcoff_symtab (minimal_symbol_reader &reader,
 			pst->add_psymbol (gdb::string_view (p, q - p), true,
 					  VAR_DOMAIN, LOC_CONST, -1,
 					  psymbol_placement::STATIC,
-					  0, psymtab_language,
+					  unrelocated_addr (0),
+					  psymtab_language,
 					  partial_symtabs, objfile);
 			/* Point past the name.  */
 			p = q;
@@ -2638,7 +2642,8 @@ scan_xcoff_symtab (minimal_symbol_reader &reader,
 						    p - namestring),
 				  true, VAR_DOMAIN, LOC_CONST, -1,
 				  psymbol_placement::STATIC,
-				  0, psymtab_language,
+				  unrelocated_addr (0),
+				  psymtab_language,
 				  partial_symtabs, objfile);
 		continue;
 
@@ -2653,7 +2658,7 @@ scan_xcoff_symtab (minimal_symbol_reader &reader,
 				  true, VAR_DOMAIN, LOC_BLOCK,
 				  SECT_OFF_TEXT (objfile),
 				  psymbol_placement::STATIC,
-				  symbol.n_value,
+				  unrelocated_addr (symbol.n_value),
 				  psymtab_language,
 				  partial_symtabs, objfile);
 		continue;
@@ -2680,7 +2685,7 @@ scan_xcoff_symtab (minimal_symbol_reader &reader,
 				  true, VAR_DOMAIN, LOC_BLOCK,
 				  SECT_OFF_TEXT (objfile),
 				  psymbol_placement::GLOBAL,
-				  symbol.n_value,
+				  unrelocated_addr (symbol.n_value),
 				  psymtab_language,
 				  partial_symtabs, objfile);
 		continue;

-- 
2.39.1


^ permalink raw reply	[flat|nested] 16+ messages in thread

* [PATCH 5/6] Use unrelocated_addr in minimal symbols
  2023-03-21 19:18 [PATCH 0/6] Use unrelocate_addr in more places Tom Tromey
                   ` (3 preceding siblings ...)
  2023-03-21 19:18 ` [PATCH 4/6] Use unrelocated_addr in psymbols Tom Tromey
@ 2023-03-21 19:18 ` Tom Tromey
  2023-03-28 13:46   ` Simon Marchi
  2023-03-30  3:52   ` Thiago Jung Bauermann
  2023-03-21 19:18 ` [PATCH 6/6] Rename "raw" to "unrelocated" Tom Tromey
  2023-03-28 12:36 ` [PATCH 0/6] Use unrelocate_addr in more places Alexandra Petlanova Hajkova
  6 siblings, 2 replies; 16+ messages in thread
From: Tom Tromey @ 2023-03-21 19:18 UTC (permalink / raw)
  To: gdb-patches

This changes minimal symbols to use unrelocated_addr.  I believe this
detected a latent bug in add_pe_forwarded_sym.
---
 gdb/coff-pe-read.c | 13 +++++--------
 gdb/coffread.c     | 12 +++++++-----
 gdb/dbxread.c      | 28 ++++++++++++++++------------
 gdb/elfread.c      | 22 +++++++++++++---------
 gdb/findvar.c      |  4 ++--
 gdb/machoread.c    |  4 ++--
 gdb/mdebugread.c   | 17 ++++++++++-------
 gdb/minsyms.c      | 40 ++++++++++++++++++++--------------------
 gdb/minsyms.h      |  6 +++---
 gdb/mips-tdep.c    |  6 ++++--
 gdb/mipsread.c     |  2 +-
 gdb/parse.c        |  2 +-
 gdb/printcmd.c     |  2 +-
 gdb/solib.c        |  2 +-
 gdb/symmisc.c      |  2 +-
 gdb/symtab.c       |  2 +-
 gdb/symtab.h       | 15 +++++++++++++--
 gdb/xcoffread.c    | 16 ++++++++--------
 18 files changed, 109 insertions(+), 86 deletions(-)

diff --git a/gdb/coff-pe-read.c b/gdb/coff-pe-read.c
index 2b89e8a3542..07cd216b4b2 100644
--- a/gdb/coff-pe-read.c
+++ b/gdb/coff-pe-read.c
@@ -127,7 +127,8 @@ add_pe_exported_sym (minimal_symbol_reader &reader,
 		     const char *dll_name, struct objfile *objfile)
 {
   /* Add the stored offset to get the loaded address of the symbol.  */
-  CORE_ADDR vma = func_rva + section_data->vma_offset;
+  unrelocated_addr vma = unrelocated_addr (func_rva
+					   + section_data->vma_offset);
 
   /* Generate a (hopefully unique) qualified name using the first part
      of the dll name, e.g. KERNEL32!AddAtomA.  This matches the style
@@ -174,7 +175,6 @@ add_pe_forwarded_sym (minimal_symbol_reader &reader,
 		      const char *forward_func_name, int ordinal,
 		      const char *dll_name, struct objfile *objfile)
 {
-  CORE_ADDR vma, baseaddr;
   struct bound_minimal_symbol msymbol;
   enum minimal_symbol_type msymtype;
   int forward_dll_name_len = strlen (forward_dll_name);
@@ -210,7 +210,7 @@ add_pe_forwarded_sym (minimal_symbol_reader &reader,
 			      " \"%s\" in dll \"%s\", pointing to \"%s\"\n"),
 		sym_name, dll_name, forward_qualified_name.c_str ());
 
-  vma = msymbol.value_address ();
+  unrelocated_addr vma = msymbol.minsym->value_raw_address ();
   msymtype = msymbol.minsym->type ();
   section = msymbol.minsym->section_index ();
 
@@ -232,14 +232,11 @@ add_pe_forwarded_sym (minimal_symbol_reader &reader,
      really be relocated properly, but nevertheless we make a stab at
      it, choosing an approach consistent with the history of this
      code.  */
-  baseaddr = objfile->text_section_offset ();
 
-  reader.record_with_info (qualified_name.c_str (), vma - baseaddr, msymtype,
-			   section);
+  reader.record_with_info (qualified_name.c_str (), vma, msymtype, section);
 
   /* Enter the plain name as well, which might not be unique.  */
-  reader.record_with_info (bare_name.c_str(), vma - baseaddr, msymtype,
-			   section);
+  reader.record_with_info (bare_name.c_str(), vma, msymtype, section);
 
   return 1;
 }
diff --git a/gdb/coffread.c b/gdb/coffread.c
index e993b17db09..837455a1d71 100644
--- a/gdb/coffread.c
+++ b/gdb/coffread.c
@@ -445,7 +445,7 @@ is_import_fixup_symbol (struct coff_symbol *cs,
 
 static struct minimal_symbol *
 record_minimal_symbol (minimal_symbol_reader &reader,
-		       struct coff_symbol *cs, CORE_ADDR address,
+		       struct coff_symbol *cs, unrelocated_addr address,
 		       enum minimal_symbol_type type, int section, 
 		       struct objfile *objfile)
 {
@@ -880,8 +880,9 @@ coff_symtab_read (minimal_symbol_reader &reader,
 	  tmpaddr = cs->c_value;
 	  /* Don't record unresolved symbols.  */
 	  if (!(cs->c_secnum <= 0 && cs->c_value == 0))
-	    record_minimal_symbol (reader, cs, tmpaddr, mst_text,
-				   section, objfile);
+	    record_minimal_symbol (reader, cs,
+				   unrelocated_addr (tmpaddr),
+				   mst_text, section, objfile);
 
 	  fcn_line_ptr = main_aux.x_sym.x_fcnary.x_fcn.x_lnnoptr;
 	  fcn_start_addr = tmpaddr;
@@ -1041,8 +1042,9 @@ coff_symtab_read (minimal_symbol_reader &reader,
 		  ms_type = mst_unknown;
 	      }
 
-	    msym = record_minimal_symbol (reader, cs, tmpaddr, ms_type,
-					  sec, objfile);
+	    msym = record_minimal_symbol (reader, cs,
+					  unrelocated_addr (tmpaddr),
+					  ms_type, sec, objfile);
 	    if (msym)
 	      gdbarch_coff_make_msymbol_special (gdbarch,
 						 cs->c_sclass, msym);
diff --git a/gdb/dbxread.c b/gdb/dbxread.c
index 677e91d7725..9df9320bc7b 100644
--- a/gdb/dbxread.c
+++ b/gdb/dbxread.c
@@ -157,7 +157,7 @@ static unsigned char processing_acc_compilation;
    need to make guesses based on the symbols (which *are* relocated to
    reflect the address it will be loaded at).  */
 
-static CORE_ADDR lowest_text_address;
+static unrelocated_addr lowest_text_address;
 
 /* Non-zero if there is any line number info in the objfile.  Prevents
    dbx_end_psymtab from discarding an otherwise empty psymtab.  */
@@ -286,7 +286,7 @@ static void dbx_symfile_read (struct objfile *, symfile_add_flags);
 static void dbx_symfile_finish (struct objfile *);
 
 static void record_minimal_symbol (minimal_symbol_reader &,
-				   const char *, CORE_ADDR, int,
+				   const char *, unrelocated_addr, int,
 				   struct objfile *);
 
 static void add_new_header_file (const char *, int);
@@ -428,7 +428,7 @@ explicit_lookup_type (int real_filenum, int index)
 \f
 static void
 record_minimal_symbol (minimal_symbol_reader &reader,
-		       const char *name, CORE_ADDR address, int type,
+		       const char *name, unrelocated_addr address, int type,
 		       struct objfile *objfile)
 {
   enum minimal_symbol_type ms_type;
@@ -1009,7 +1009,7 @@ read_dbx_symtab (minimal_symbol_reader &reader,
 
   set_last_source_file (NULL);
 
-  lowest_text_address = (CORE_ADDR) -1;
+  lowest_text_address = (unrelocated_addr) -1;
 
   symfile_bfd = objfile->obfd.get ();	/* For next_text_symbol.  */
   abfd = objfile->obfd.get ();
@@ -1103,7 +1103,8 @@ read_dbx_symtab (minimal_symbol_reader &reader,
 	  record_it:
 	  namestring = set_namestring (objfile, &nlist);
 
-	  record_minimal_symbol (reader, namestring, nlist.n_value,
+	  record_minimal_symbol (reader, namestring,
+				 unrelocated_addr (nlist.n_value),
 				 nlist.n_type, objfile);	/* Always */
 	  continue;
 
@@ -1680,7 +1681,8 @@ read_dbx_symtab (minimal_symbol_reader &reader,
 					  pst ? pst->filename : NULL,
 					  objfile);
 		  if (minsym.minsym != NULL)
-		    nlist.n_value = minsym.minsym->value_raw_address ();
+		    nlist.n_value
+		      = CORE_ADDR (minsym.minsym->value_raw_address ());
 		}
 	      if (pst && textlow_not_set
 		  && gdbarch_sofun_address_maybe_missing (gdbarch))
@@ -1738,7 +1740,8 @@ read_dbx_symtab (minimal_symbol_reader &reader,
 					  pst ? pst->filename : NULL,
 					  objfile);
 		  if (minsym.minsym != NULL)
-		    nlist.n_value = minsym.minsym->value_raw_address ();
+		    nlist.n_value
+		      = CORE_ADDR (minsym.minsym->value_raw_address ());
 		}
 	      if (pst && textlow_not_set
 		  && gdbarch_sofun_address_maybe_missing (gdbarch))
@@ -1945,10 +1948,11 @@ read_dbx_symtab (minimal_symbol_reader &reader,
       /* Don't set high text address of PST lower than it already
 	 is.  */
       unrelocated_addr text_end
-	= unrelocated_addr ((lowest_text_address == (CORE_ADDR) -1
-			     ? text_addr
-			     : lowest_text_address)
-			    + text_size);
+	= (unrelocated_addr
+	   (lowest_text_address == (unrelocated_addr) -1
+	    ? text_addr
+	    : CORE_ADDR (lowest_text_address)
+	    + text_size));
 
       dbx_end_psymtab (objfile, partial_symtabs,
 		       pst, psymtab_include_list, includes_used,
@@ -2054,7 +2058,7 @@ dbx_end_psymtab (struct objfile *objfile, psymtab_storage *partial_symtabs,
 
       if (minsym.minsym)
 	pst->set_text_high
-	  (unrelocated_addr (minsym.minsym->value_raw_address ()
+	  (unrelocated_addr (CORE_ADDR (minsym.minsym->value_raw_address ())
 			     + minsym.minsym->size ()));
 
       last_function_name = NULL;
diff --git a/gdb/elfread.c b/gdb/elfread.c
index b414da9ed21..55771492044 100644
--- a/gdb/elfread.c
+++ b/gdb/elfread.c
@@ -199,7 +199,7 @@ elf_locate_sections (asection *sectp, struct elfinfo *ei)
 static struct minimal_symbol *
 record_minimal_symbol (minimal_symbol_reader &reader,
 		       gdb::string_view name, bool copy_name,
-		       CORE_ADDR address,
+		       unrelocated_addr address,
 		       enum minimal_symbol_type ms_type,
 		       asection *bfd_section, struct objfile *objfile)
 {
@@ -207,7 +207,9 @@ record_minimal_symbol (minimal_symbol_reader &reader,
 
   if (ms_type == mst_text || ms_type == mst_file_text
       || ms_type == mst_text_gnu_ifunc)
-    address = gdbarch_addr_bits_remove (gdbarch, address);
+    address
+      = unrelocated_addr (gdbarch_addr_bits_remove (gdbarch,
+						    CORE_ADDR (address)));
 
   /* We only setup section information for allocatable sections.  Usually
      we'd only expect to find msymbols for allocatable sections, but if the
@@ -338,7 +340,8 @@ elf_symtab_read (minimal_symbol_reader &reader,
 
 	  msym = record_minimal_symbol
 	    (reader, sym->name, copy_names,
-	     symaddr, mst_solib_trampoline, sect, objfile);
+	     unrelocated_addr (symaddr),
+	     mst_solib_trampoline, sect, objfile);
 	  if (msym != NULL)
 	    {
 	      msym->filename = filesymname;
@@ -477,7 +480,7 @@ elf_symtab_read (minimal_symbol_reader &reader,
 	      continue;	/* Skip this symbol.  */
 	    }
 	  msym = record_minimal_symbol
-	    (reader, sym->name, copy_names, symaddr,
+	    (reader, sym->name, copy_names, unrelocated_addr (symaddr),
 	     ms_type, sym->section, objfile);
 
 	  if (msym)
@@ -509,8 +512,8 @@ elf_symtab_read (minimal_symbol_reader &reader,
 		  && (elf_sym->version & VERSYM_HIDDEN) == 0)
 		record_minimal_symbol (reader,
 				       gdb::string_view (sym->name, len),
-				       true, symaddr, ms_type, sym->section,
-				       objfile);
+				       true, unrelocated_addr (symaddr),
+				       ms_type, sym->section, objfile);
 	      else if (is_plt)
 		{
 		  /* For @plt symbols, also record a trampoline to the
@@ -523,7 +526,8 @@ elf_symtab_read (minimal_symbol_reader &reader,
 
 		      mtramp = record_minimal_symbol
 			(reader, gdb::string_view (sym->name, len), true,
-			 symaddr, mst_solib_trampoline, sym->section, objfile);
+			 unrelocated_addr (symaddr),
+			 mst_solib_trampoline, sym->section, objfile);
 		      if (mtramp)
 			{
 			  mtramp->set_size (msym->size());
@@ -641,8 +645,8 @@ elf_rel_plt_read (minimal_symbol_reader &reader,
       string_buffer.append (got_suffix, got_suffix + got_suffix_len);
 
       msym = record_minimal_symbol (reader, string_buffer,
-				    true, address, mst_slot_got_plt,
-				    msym_section, objfile);
+				    true, unrelocated_addr (address),
+				    mst_slot_got_plt, msym_section, objfile);
       if (msym)
 	msym->set_size (ptr_size);
     }
diff --git a/gdb/findvar.c b/gdb/findvar.c
index 60b5ca3faf3..97cc9ba7660 100644
--- a/gdb/findvar.c
+++ b/gdb/findvar.c
@@ -754,9 +754,9 @@ language_defn::read_var_value (struct symbol *var,
 	   a TLS variable. */
 	if (obj_section == NULL
 	    || (obj_section->the_bfd_section->flags & SEC_THREAD_LOCAL) != 0)
-	   addr = bmsym.minsym->value_raw_address ();
+	  addr = CORE_ADDR (bmsym.minsym->value_raw_address ());
 	else
-	   addr = bmsym.value_address ();
+	  addr = bmsym.value_address ();
 	if (overlay_debugging)
 	  addr = symbol_overlayed_address (addr, obj_section);
 	/* Determine address of TLS variable. */
diff --git a/gdb/machoread.c b/gdb/machoread.c
index e8cae810788..9735de80d57 100644
--- a/gdb/machoread.c
+++ b/gdb/machoread.c
@@ -98,11 +98,11 @@ macho_symtab_add_minsym (minimal_symbol_reader &reader,
 
   if (sym->flags & (BSF_GLOBAL | BSF_LOCAL | BSF_WEAK))
     {
-      CORE_ADDR symaddr;
+      unrelocated_addr symaddr;
       enum minimal_symbol_type ms_type;
 
       /* Bfd symbols are section relative.  */
-      symaddr = sym->value + sym->section->vma;
+      symaddr = unrelocated_addr (sym->value + sym->section->vma);
 
       if (sym->section == bfd_abs_section_ptr)
 	ms_type = mst_abs;
diff --git a/gdb/mdebugread.c b/gdb/mdebugread.c
index e0415587646..8faf482b09c 100644
--- a/gdb/mdebugread.c
+++ b/gdb/mdebugread.c
@@ -2235,7 +2235,7 @@ function_outside_compilation_unit_complaint (const char *arg1)
 
 static void
 record_minimal_symbol (minimal_symbol_reader &reader,
-		       const char *name, const CORE_ADDR address,
+		       const char *name, const unrelocated_addr address,
 		       enum minimal_symbol_type ms_type, int storage_class,
 		       struct objfile *objfile)
 {
@@ -2461,7 +2461,7 @@ parse_partial_symbols (minimal_symbol_reader &reader,
   for (; ext_in < ext_in_end; ext_in++)
     {
       enum minimal_symbol_type ms_type = mst_text;
-      CORE_ADDR svalue = ext_in->asym.value;
+      unrelocated_addr svalue = unrelocated_addr (ext_in->asym.value);
 
       /* The Irix 5 native tools seem to sometimes generate bogus
 	 external symbols.  */
@@ -2701,7 +2701,8 @@ parse_partial_symbols (minimal_symbol_reader &reader,
 		      if (sh.st == stStaticProc)
 			{
 			  namestring = debug_info->ss + fh->issBase + sh.iss;
-			  record_minimal_symbol (reader, namestring, sh.value,
+			  record_minimal_symbol (reader, namestring,
+						 unrelocated_addr (sh.value),
 						 mst_file_text, sh.sc,
 						 objfile);
 			}
@@ -2747,7 +2748,8 @@ parse_partial_symbols (minimal_symbol_reader &reader,
 			case scPData:
 			case scXData:
 			  namestring = debug_info->ss + fh->issBase + sh.iss;
-			  record_minimal_symbol (reader, namestring, sh.value,
+			  record_minimal_symbol (reader, namestring,
+						 unrelocated_addr (sh.value),
 						 mst_file_data, sh.sc,
 						 objfile);
 			  break;
@@ -2756,7 +2758,8 @@ parse_partial_symbols (minimal_symbol_reader &reader,
 			  /* FIXME!  Shouldn't this use cases for bss, 
 			     then have the default be abs?  */
 			  namestring = debug_info->ss + fh->issBase + sh.iss;
-			  record_minimal_symbol (reader, namestring, sh.value,
+			  record_minimal_symbol (reader, namestring,
+						 unrelocated_addr (sh.value),
 						 mst_file_bss, sh.sc,
 						 objfile);
 			  break;
@@ -3369,7 +3372,7 @@ parse_partial_symbols (minimal_symbol_reader &reader,
 	    {
 	      char *sym_name;
 	      enum address_class theclass;
-	      CORE_ADDR minsym_value;
+	      unrelocated_addr minsym_value;
 	      short section = -1;
 
 	      (*swap_sym_in) (cur_bfd,
@@ -3396,7 +3399,7 @@ parse_partial_symbols (minimal_symbol_reader &reader,
 
 	      sym_name = debug_info->ss + fh->issBase + sh.iss;
 
-	      minsym_value = sh.value;
+	      minsym_value = unrelocated_addr (sh.value);
 
 	      switch (sh.sc)
 		{
diff --git a/gdb/minsyms.c b/gdb/minsyms.c
index 02e36cc6dd2..67bd4903a3e 100644
--- a/gdb/minsyms.c
+++ b/gdb/minsyms.c
@@ -672,19 +672,20 @@ lookup_minimal_symbol_by_pc_name (CORE_ADDR pc, const char *name,
 
 /* A helper function that makes *PC section-relative.  This searches
    the sections of OBJFILE and if *PC is in a section, it subtracts
-   the section offset and returns true.  Otherwise it returns
-   false.  */
+   the section offset, stores the result into UNREL_ADDR, and returns
+   true.  Otherwise it returns false.  */
 
 static int
-frob_address (struct objfile *objfile, CORE_ADDR *pc)
+frob_address (struct objfile *objfile, CORE_ADDR pc,
+	      unrelocated_addr *unrel_addr)
 {
   struct obj_section *iter;
 
   ALL_OBJFILE_OSECTIONS (objfile, iter)
     {
-      if (*pc >= iter->addr () && *pc < iter->endaddr ())
+      if (pc >= iter->addr () && pc < iter->endaddr ())
 	{
-	  *pc -= iter->offset ();
+	  *unrel_addr = unrelocated_addr (pc - iter->offset ());
 	  return 1;
 	}
     }
@@ -793,15 +794,16 @@ lookup_minimal_symbol_by_pc_section (CORE_ADDR pc_in, struct obj_section *sectio
 
 	     Warning: this code is trickier than it would appear at first.  */
 
-	  if (frob_address (objfile, &pc)
-	      && pc >= msymbol[lo].value_raw_address ())
+	  unrelocated_addr unrel_pc;
+	  if (frob_address (objfile, pc, &unrel_pc)
+	      && unrel_pc >= msymbol[lo].value_raw_address ())
 	    {
-	      while (msymbol[hi].value_raw_address () > pc)
+	      while (msymbol[hi].value_raw_address () > unrel_pc)
 		{
 		  /* pc is still strictly less than highest address.  */
 		  /* Note "new" will always be >= lo.  */
 		  newobj = (lo + hi) / 2;
-		  if ((msymbol[newobj].value_raw_address () >= pc)
+		  if ((msymbol[newobj].value_raw_address () >= unrel_pc)
 		      || (lo == newobj))
 		    {
 		      hi = newobj;
@@ -894,10 +896,8 @@ lookup_minimal_symbol_by_pc_section (CORE_ADDR pc_in, struct obj_section *sectio
 		     the cancellable variants, but both have sizes.  */
 		  if (hi > 0
 		      && msymbol[hi].size () != 0
-		      && pc >= (msymbol[hi].value_raw_address ()
-				+ msymbol[hi].size ())
-		      && pc < (msymbol[hi - 1].value_raw_address ()
-			       + msymbol[hi - 1].size ()))
+		      && unrel_pc >= msymbol[hi].value_raw_end_address ()
+		      && unrel_pc < msymbol[hi - 1].value_raw_end_address ())
 		    {
 		      hi--;
 		      continue;
@@ -926,8 +926,7 @@ lookup_minimal_symbol_by_pc_section (CORE_ADDR pc_in, struct obj_section *sectio
 
 	      if (hi >= 0
 		  && msymbol[hi].size () != 0
-		  && pc >= (msymbol[hi].value_raw_address ()
-			    + msymbol[hi].size ()))
+		  && unrel_pc >= msymbol[hi].value_raw_end_address ())
 		{
 		  if (best_zero_sized != -1)
 		    hi = best_zero_sized;
@@ -1092,7 +1091,7 @@ minimal_symbol_reader::~minimal_symbol_reader ()
 /* See minsyms.h.  */
 
 void
-minimal_symbol_reader::record (const char *name, CORE_ADDR address,
+minimal_symbol_reader::record (const char *name, unrelocated_addr address,
 			       enum minimal_symbol_type ms_type)
 {
   int section;
@@ -1152,7 +1151,7 @@ mst_str (minimal_symbol_type t)
 
 struct minimal_symbol *
 minimal_symbol_reader::record_full (gdb::string_view name,
-				    bool copy_name, CORE_ADDR address,
+				    bool copy_name, unrelocated_addr address,
 				    enum minimal_symbol_type ms_type,
 				    int section)
 {
@@ -1178,8 +1177,9 @@ minimal_symbol_reader::record_full (gdb::string_view name,
     return (NULL);
 
   symtab_create_debug_printf_v ("recording minsym:  %-21s  %18s  %4d  %.*s",
-				mst_str (ms_type), hex_string (address), section,
-				(int) name.size (), name.data ());
+				mst_str (ms_type),
+				hex_string (LONGEST (address)),
+				section, (int) name.size (), name.data ());
 
   if (m_msym_bunch_index == BUNCH_SIZE)
     {
@@ -1198,7 +1198,7 @@ minimal_symbol_reader::record_full (gdb::string_view name,
   else
     msymbol->m_name = name.data ();
 
-  msymbol->set_value_address (address);
+  msymbol->set_unrelocated_address (address);
   msymbol->set_section_index (section);
 
   msymbol->set_type (ms_type);
diff --git a/gdb/minsyms.h b/gdb/minsyms.h
index e9081495eb1..59c276f01f3 100644
--- a/gdb/minsyms.h
+++ b/gdb/minsyms.h
@@ -120,7 +120,7 @@ class minimal_symbol_reader
 
   struct minimal_symbol *record_full (gdb::string_view name,
 				      bool copy_name,
-				      CORE_ADDR address,
+				      unrelocated_addr address,
 				      enum minimal_symbol_type ms_type,
 				      int section);
 
@@ -131,7 +131,7 @@ class minimal_symbol_reader
 
      This variant does not return the new symbol.  */
 
-  void record (const char *name, CORE_ADDR address,
+  void record (const char *name, unrelocated_addr address,
 	       enum minimal_symbol_type ms_type);
 
   /* Like record_full, but:
@@ -140,7 +140,7 @@ class minimal_symbol_reader
 
      This variant does not return the new symbol.  */
 
-  void record_with_info (const char *name, CORE_ADDR address,
+  void record_with_info (const char *name, unrelocated_addr address,
 			 enum minimal_symbol_type ms_type,
 			 int section)
   {
diff --git a/gdb/mips-tdep.c b/gdb/mips-tdep.c
index 52799b926d3..b86bf61f4d1 100644
--- a/gdb/mips-tdep.c
+++ b/gdb/mips-tdep.c
@@ -436,12 +436,14 @@ mips_elf_make_msymbol_special (asymbol * sym, struct minimal_symbol *msym)
   if (ELF_ST_IS_MICROMIPS (st_other))
     {
       SET_MSYMBOL_TARGET_FLAG_MICROMIPS (msym);
-      msym->set_value_address (msym->value_raw_address () | 1);
+      CORE_ADDR fixed = CORE_ADDR (msym->value_raw_address ()) | 1;
+      msym->set_unrelocated_address (unrelocated_addr (fixed));
     }
   else if (ELF_ST_IS_MIPS16 (st_other))
     {
       SET_MSYMBOL_TARGET_FLAG_MIPS16 (msym);
-      msym->set_value_address (msym->value_raw_address () | 1);
+      CORE_ADDR fixed = CORE_ADDR (msym->value_raw_address ()) | 1;
+      msym->set_unrelocated_address (unrelocated_addr (fixed));
     }
 }
 
diff --git a/gdb/mipsread.c b/gdb/mipsread.c
index 5c2c88e81c2..efff2841974 100644
--- a/gdb/mipsread.c
+++ b/gdb/mipsread.c
@@ -358,7 +358,7 @@ read_alphacoff_dynamic_symtab (minimal_symbol_reader &reader,
 	    }
 	}
 
-      reader.record (name, sym_value, ms_type);
+      reader.record (name, unrelocated_addr (sym_value), ms_type);
     }
 }
 
diff --git a/gdb/parse.c b/gdb/parse.c
index 24db3ca57d9..4bce63c58f7 100644
--- a/gdb/parse.c
+++ b/gdb/parse.c
@@ -115,7 +115,7 @@ find_minsym_type_and_address (minimal_symbol *msymbol,
     {
       /* Addresses of TLS symbols are really offsets into a
 	 per-objfile/per-thread storage block.  */
-      addr = bound_msym.minsym->value_raw_address ();
+      addr = CORE_ADDR (bound_msym.minsym->value_raw_address ());
     }
   else if (msymbol_is_function (objfile, msymbol, &addr))
     {
diff --git a/gdb/printcmd.c b/gdb/printcmd.c
index ae59a14aeb1..d4b3cce696f 100644
--- a/gdb/printcmd.c
+++ b/gdb/printcmd.c
@@ -1824,7 +1824,7 @@ info_address_command (const char *exp, int from_tty)
 	    if (section
 		&& (section->the_bfd_section->flags & SEC_THREAD_LOCAL) != 0)
 	      {
-		load_addr = msym.minsym->value_raw_address ();
+		load_addr = CORE_ADDR (msym.minsym->value_raw_address ());
 		gdb_printf (_("a thread-local variable at offset %s "
 			      "in the thread-local storage for `%s'"),
 			    paddress (gdbarch, load_addr),
diff --git a/gdb/solib.c b/gdb/solib.c
index e6bccc85ca7..e839b634e04 100644
--- a/gdb/solib.c
+++ b/gdb/solib.c
@@ -1515,7 +1515,7 @@ gdb_bfd_lookup_symbol_from_symtab
 
 		  msym.set_value_address (symaddr);
 		  gdbarch_elf_make_msymbol_special (gdbarch, sym, &msym);
-		  symaddr = msym.value_raw_address ();
+		  symaddr = CORE_ADDR (msym.value_raw_address ());
 		}
 
 	      /* BFD symbols are section relative.  */
diff --git a/gdb/symmisc.c b/gdb/symmisc.c
index 54dc570d282..df2bdb0d7c3 100644
--- a/gdb/symmisc.c
+++ b/gdb/symmisc.c
@@ -201,7 +201,7 @@ dump_msymbols (struct objfile *objfile, struct ui_file *outfile)
 
       /* Use the relocated address as shown in the symbol here -- do
 	 not try to respect copy relocations.  */
-      CORE_ADDR addr = (msymbol->value_raw_address ()
+      CORE_ADDR addr = (CORE_ADDR (msymbol->value_raw_address ())
 			+ objfile->section_offsets[msymbol->section_index ()]);
       gdb_puts (paddress (gdbarch, addr), outfile);
       gdb_printf (outfile, " %s", msymbol->linkage_name ());
diff --git a/gdb/symtab.c b/gdb/symtab.c
index 8ab1f58affe..ac6535fe983 100644
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -424,7 +424,7 @@ minimal_symbol::value_address (objfile *objfile) const
   if (this->maybe_copied)
     return get_msymbol_address (objfile, this);
   else
-    return (this->value_raw_address ()
+    return (CORE_ADDR (this->value_raw_address ())
 	    + objfile->section_offsets[this->section_index ()]);
 }
 
diff --git a/gdb/symtab.h b/gdb/symtab.h
index 4d760863081..1f3e0b87b19 100644
--- a/gdb/symtab.h
+++ b/gdb/symtab.h
@@ -754,10 +754,21 @@ struct minimal_symbol : public general_symbol_info
      offsets from OBJFILE.  */
   CORE_ADDR value_address (objfile *objfile) const;
 
+  /* It does not make sense to call this for minimal symbols, as they
+     are stored unrelocated.  */
+  CORE_ADDR value_address () const = delete;
+
   /* The unrelocated address of the minimal symbol.  */
-  CORE_ADDR value_raw_address () const
+  unrelocated_addr value_raw_address () const
   {
-    return m_value.address;
+    return m_value.unrel_addr;
+  }
+
+  /* The unrelocated address just after the end of the the minimal
+     symbol.  */
+  unrelocated_addr value_raw_end_address () const
+  {
+    return unrelocated_addr (CORE_ADDR (value_raw_address ()) + size ());
   }
 
   /* Return this minimal symbol's type.  */
diff --git a/gdb/xcoffread.c b/gdb/xcoffread.c
index 5c20468e9e4..52ed13062f2 100644
--- a/gdb/xcoffread.c
+++ b/gdb/xcoffread.c
@@ -840,7 +840,7 @@ enter_line_range (struct subfile *subfile, unsigned beginoffset,
 
 static void
 record_minimal_symbol (minimal_symbol_reader &reader,
-		       const char *name, CORE_ADDR address,
+		       const char *name, unrelocated_addr address,
 		       enum minimal_symbol_type ms_type,
 		       int n_scnum,
 		       struct objfile *objfile)
@@ -2055,7 +2055,7 @@ scan_xcoff_symtab (minimal_symbol_reader &reader,
   unsigned int ssymnum;
 
   const char *last_csect_name = NULL; /* Last seen csect's name and value.  */
-  CORE_ADDR last_csect_val = 0;
+  unrelocated_addr last_csect_val = unrelocated_addr (0);
   int last_csect_sec = 0;
   int misc_func_recorded = 0;	/* true if any misc. function.  */
   int textlow_not_set = 1;
@@ -2168,7 +2168,7 @@ scan_xcoff_symtab (minimal_symbol_reader &reader,
 				       || namestring[0] == '@'))
 		      {
 			last_csect_name = namestring;
-			last_csect_val = symbol.n_value;
+			last_csect_val = unrelocated_addr (symbol.n_value);
 			last_csect_sec = symbol.n_scnum;
 		      }
 		    if (pst != NULL)
@@ -2193,7 +2193,7 @@ scan_xcoff_symtab (minimal_symbol_reader &reader,
 		       table, except for section symbols.  */
 		    if (*namestring != '.')
 		      record_minimal_symbol
-			(reader, namestring, symbol.n_value,
+			(reader, namestring, unrelocated_addr (symbol.n_value),
 			 sclass == C_HIDEXT ? mst_file_data : mst_data,
 			 symbol.n_scnum, objfile);
 		    break;
@@ -2231,7 +2231,7 @@ scan_xcoff_symtab (minimal_symbol_reader &reader,
 			main_aux[0].x_sym.x_fcnary.x_fcn.x_lnnoptr;
 
 		    record_minimal_symbol
-		      (reader, namestring, symbol.n_value,
+		      (reader, namestring, unrelocated_addr (symbol.n_value),
 		       sclass == C_HIDEXT ? mst_file_text : mst_text,
 		       symbol.n_scnum, objfile);
 		    misc_func_recorded = 1;
@@ -2246,7 +2246,7 @@ scan_xcoff_symtab (minimal_symbol_reader &reader,
 		       symbols, we will choose mst_text over
 		       mst_solib_trampoline.  */
 		    record_minimal_symbol
-		      (reader, namestring, symbol.n_value,
+		      (reader, namestring, unrelocated_addr (symbol.n_value),
 		       mst_solib_trampoline, symbol.n_scnum, objfile);
 		    misc_func_recorded = 1;
 		    break;
@@ -2268,7 +2268,7 @@ scan_xcoff_symtab (minimal_symbol_reader &reader,
 		       XMC_BS might be possible too.  */
 		    if (*namestring != '.')
 		      record_minimal_symbol
-			(reader, namestring, symbol.n_value,
+			(reader, namestring, unrelocated_addr (symbol.n_value),
 			 sclass == C_HIDEXT ? mst_file_data : mst_data,
 			 symbol.n_scnum, objfile);
 		    break;
@@ -2284,7 +2284,7 @@ scan_xcoff_symtab (minimal_symbol_reader &reader,
 		       table, except for section symbols.  */
 		    if (*namestring != '.')
 		      record_minimal_symbol
-			(reader, namestring, symbol.n_value,
+			(reader, namestring, unrelocated_addr (symbol.n_value),
 			 sclass == C_HIDEXT ? mst_file_bss : mst_bss,
 			 symbol.n_scnum, objfile);
 		    break;

-- 
2.39.1


^ permalink raw reply	[flat|nested] 16+ messages in thread

* [PATCH 6/6] Rename "raw" to "unrelocated"
  2023-03-21 19:18 [PATCH 0/6] Use unrelocate_addr in more places Tom Tromey
                   ` (4 preceding siblings ...)
  2023-03-21 19:18 ` [PATCH 5/6] Use unrelocated_addr in minimal symbols Tom Tromey
@ 2023-03-21 19:18 ` Tom Tromey
  2023-03-28 12:36 ` [PATCH 0/6] Use unrelocate_addr in more places Alexandra Petlanova Hajkova
  6 siblings, 0 replies; 16+ messages in thread
From: Tom Tromey @ 2023-03-21 19:18 UTC (permalink / raw)
  To: gdb-patches

Per an earlier discussion, this patch renames the existing "raw" APIs
to use the word "unrelocated" instead.
---
 gdb/coff-pe-read.c |  2 +-
 gdb/dbxread.c      | 33 +++++++++++++++++----------------
 gdb/findvar.c      |  2 +-
 gdb/mdebugread.c   | 14 +++++++-------
 gdb/minsyms.c      | 40 ++++++++++++++++++++--------------------
 gdb/mips-tdep.c    |  4 ++--
 gdb/parse.c        |  2 +-
 gdb/printcmd.c     |  2 +-
 gdb/psympriv.h     |  4 ++--
 gdb/psymtab.c      |  4 ++--
 gdb/solib.c        |  2 +-
 gdb/symmisc.c      |  2 +-
 gdb/symtab.c       |  2 +-
 gdb/symtab.h       |  6 +++---
 gdb/xcoffread.c    |  5 +++--
 15 files changed, 63 insertions(+), 61 deletions(-)

diff --git a/gdb/coff-pe-read.c b/gdb/coff-pe-read.c
index 07cd216b4b2..fdd062f1b2e 100644
--- a/gdb/coff-pe-read.c
+++ b/gdb/coff-pe-read.c
@@ -210,7 +210,7 @@ add_pe_forwarded_sym (minimal_symbol_reader &reader,
 			      " \"%s\" in dll \"%s\", pointing to \"%s\"\n"),
 		sym_name, dll_name, forward_qualified_name.c_str ());
 
-  unrelocated_addr vma = msymbol.minsym->value_raw_address ();
+  unrelocated_addr vma = msymbol.minsym->unrelocated_address ();
   msymtype = msymbol.minsym->type ();
   section = msymbol.minsym->section_index ();
 
diff --git a/gdb/dbxread.c b/gdb/dbxread.c
index 9df9320bc7b..f7c44c14ae2 100644
--- a/gdb/dbxread.c
+++ b/gdb/dbxread.c
@@ -1131,13 +1131,13 @@ read_dbx_symtab (minimal_symbol_reader &reader,
 	      if (past_first_source_file && pst
 		  /* The gould NP1 uses low values for .o and -l symbols
 		     which are not the address.  */
-		  && unrel_val >= pst->raw_text_low ())
+		  && unrel_val >= pst->unrelocated_text_low ())
 		{
 		  dbx_end_psymtab (objfile, partial_symtabs,
 				   pst, psymtab_include_list,
 				   includes_used, symnum * symbol_size,
-				   unrel_val > pst->raw_text_high ()
-				   ? unrel_val : pst->raw_text_high (),
+				   unrel_val > pst->unrelocated_text_high ()
+				   ? unrel_val : pst->unrelocated_text_high (),
 				   dependency_list, dependencies_used,
 				   textlow_not_set);
 		  pst = (legacy_psymtab *) 0;
@@ -1253,8 +1253,9 @@ read_dbx_symtab (minimal_symbol_reader &reader,
 		    dbx_end_psymtab (objfile, partial_symtabs,
 				     pst, psymtab_include_list,
 				     includes_used, symnum * symbol_size,
-				     (unrel_value > pst->raw_text_high ()
-				      ? unrel_value : pst->raw_text_high ()),
+				     unrel_value > pst->unrelocated_text_high ()
+				     ? unrel_value
+				     : pst->unrelocated_text_high (),
 				     dependency_list, dependencies_used,
 				     prev_textlow_not_set);
 		    pst = (legacy_psymtab *) 0;
@@ -1427,8 +1428,8 @@ read_dbx_symtab (minimal_symbol_reader &reader,
 		 function relative stabs, or the address of the function's
 		 end for old style stabs.  */
 	      valu = unrelocated_addr (nlist.n_value + last_function_start);
-	      if (pst->raw_text_high () == unrelocated_addr (0)
-		  || valu > pst->raw_text_high ())
+	      if (pst->unrelocated_text_high () == unrelocated_addr (0)
+		  || valu > pst->unrelocated_text_high ())
 		pst->set_text_high (valu);
 	      break;
 	    }
@@ -1682,7 +1683,7 @@ read_dbx_symtab (minimal_symbol_reader &reader,
 					  objfile);
 		  if (minsym.minsym != NULL)
 		    nlist.n_value
-		      = CORE_ADDR (minsym.minsym->value_raw_address ());
+		      = CORE_ADDR (minsym.minsym->unrelocated_address ());
 		}
 	      if (pst && textlow_not_set
 		  && gdbarch_sofun_address_maybe_missing (gdbarch))
@@ -1703,7 +1704,7 @@ read_dbx_symtab (minimal_symbol_reader &reader,
 	      if (pst
 		  && (textlow_not_set
 		      || (unrelocated_addr (nlist.n_value)
-			  < pst->raw_text_low ()
+			  < pst->unrelocated_text_low ()
 			  && (nlist.n_value != 0))))
 		{
 		  pst->set_text_low (unrelocated_addr (nlist.n_value));
@@ -1741,7 +1742,7 @@ read_dbx_symtab (minimal_symbol_reader &reader,
 					  objfile);
 		  if (minsym.minsym != NULL)
 		    nlist.n_value
-		      = CORE_ADDR (minsym.minsym->value_raw_address ());
+		      = CORE_ADDR (minsym.minsym->unrelocated_address ());
 		}
 	      if (pst && textlow_not_set
 		  && gdbarch_sofun_address_maybe_missing (gdbarch))
@@ -1762,7 +1763,7 @@ read_dbx_symtab (minimal_symbol_reader &reader,
 	      if (pst
 		  && (textlow_not_set
 		      || (unrelocated_addr (nlist.n_value)
-			  < pst->raw_text_low ()
+			  < pst->unrelocated_text_low ()
 			  && (nlist.n_value != 0))))
 		{
 		  pst->set_text_low (unrelocated_addr (nlist.n_value));
@@ -1957,8 +1958,8 @@ read_dbx_symtab (minimal_symbol_reader &reader,
       dbx_end_psymtab (objfile, partial_symtabs,
 		       pst, psymtab_include_list, includes_used,
 		       symnum * symbol_size,
-		       (text_end > pst->raw_text_high ()
-			? text_end : pst->raw_text_high ()),
+		       (text_end > pst->unrelocated_text_high ()
+			? text_end : pst->unrelocated_text_high ()),
 		       dependency_list, dependencies_used, textlow_not_set);
     }
 }
@@ -2058,7 +2059,7 @@ dbx_end_psymtab (struct objfile *objfile, psymtab_storage *partial_symtabs,
 
       if (minsym.minsym)
 	pst->set_text_high
-	  (unrelocated_addr (CORE_ADDR (minsym.minsym->value_raw_address ())
+	  (unrelocated_addr (CORE_ADDR (minsym.minsym->unrelocated_address ())
 			     + minsym.minsym->size ()));
 
       last_function_name = NULL;
@@ -2068,7 +2069,7 @@ dbx_end_psymtab (struct objfile *objfile, psymtab_storage *partial_symtabs,
     ;
   /* This test will be true if the last .o file is only data.  */
   else if (textlow_not_set)
-    pst->set_text_low (pst->raw_text_high ());
+    pst->set_text_low (pst->unrelocated_text_high ());
   else
     {
       /* If we know our own starting text address, then walk through all other
@@ -2078,7 +2079,7 @@ dbx_end_psymtab (struct objfile *objfile, psymtab_storage *partial_symtabs,
 
       for (partial_symtab *p1 : partial_symtabs->range ())
 	if (!p1->text_high_valid && p1->text_low_valid && p1 != pst)
-	  p1->set_text_high (pst->raw_text_low ());
+	  p1->set_text_high (pst->unrelocated_text_low ());
     }
 
   /* End of kludge for patching Solaris textlow and texthigh.  */
diff --git a/gdb/findvar.c b/gdb/findvar.c
index 97cc9ba7660..1b7aa22888c 100644
--- a/gdb/findvar.c
+++ b/gdb/findvar.c
@@ -754,7 +754,7 @@ language_defn::read_var_value (struct symbol *var,
 	   a TLS variable. */
 	if (obj_section == NULL
 	    || (obj_section->the_bfd_section->flags & SEC_THREAD_LOCAL) != 0)
-	  addr = CORE_ADDR (bmsym.minsym->value_raw_address ());
+	  addr = CORE_ADDR (bmsym.minsym->unrelocated_address ());
 	else
 	  addr = bmsym.value_address ();
 	if (overlay_debugging)
diff --git a/gdb/mdebugread.c b/gdb/mdebugread.c
index 8faf482b09c..697ce0b5b1a 100644
--- a/gdb/mdebugread.c
+++ b/gdb/mdebugread.c
@@ -2659,7 +2659,7 @@ parse_partial_symbols (minimal_symbol_reader &reader,
 	psymtab_language = prev_language;
       PST_PRIVATE (pst)->pst_language = psymtab_language;
 
-      pst->set_text_high (pst->raw_text_low ());
+      pst->set_text_high (pst->unrelocated_text_low ());
 
       /* For stabs-in-ecoff files, the second symbol must be @stab.
 	 This symbol is emitted by mips-tfile to signal that the
@@ -2726,9 +2726,9 @@ parse_partial_symbols (minimal_symbol_reader &reader,
 			  /* Kludge for Irix 5.2 zero fh->adr.  */
 			  if (!relocatable
 			      && (!pst->text_low_valid
-				  || procaddr < pst->raw_text_low ()))
+				  || procaddr < pst->unrelocated_text_low ()))
 			    pst->set_text_low (procaddr);
-			  if (high > pst->raw_text_high ())
+			  if (high > pst->unrelocated_text_high ())
 			    pst->set_text_high (high);
 			}
 		    }
@@ -3319,7 +3319,7 @@ parse_partial_symbols (minimal_symbol_reader &reader,
 		    {
 		      unrelocated_addr unrel_value
 			= unrelocated_addr (sh.value);
-		      if (unrel_value > save_pst->raw_text_high ())
+		      if (unrel_value > save_pst->unrelocated_text_high ())
 			save_pst->set_text_high (unrel_value);
 		    }
 		    continue;
@@ -3511,11 +3511,11 @@ parse_partial_symbols (minimal_symbol_reader &reader,
 		  /* Kludge for Irix 5.2 zero fh->adr.  */
 		  if (!relocatable
 		      && (!pst->text_low_valid
-			  || procaddr < pst->raw_text_low ()))
+			  || procaddr < pst->unrelocated_text_low ()))
 		    pst->set_text_low (procaddr);
 
 		  high = unrelocated_addr (CORE_ADDR (procaddr) + sh.value);
-		  if (high > pst->raw_text_high ())
+		  if (high > pst->unrelocated_text_high ())
 		    pst->set_text_high (high);
 		  continue;
 
@@ -3696,7 +3696,7 @@ parse_partial_symbols (minimal_symbol_reader &reader,
       fdr_to_pst[f_idx].pst
 	= dbx_end_psymtab (objfile, partial_symtabs, save_pst,
 			   psymtab_include_list, includes_used,
-			   -1, save_pst->raw_text_high (),
+			   -1, save_pst->unrelocated_text_high (),
 			   dependency_list, dependencies_used,
 			   textlow_not_set);
       includes_used = 0;
diff --git a/gdb/minsyms.c b/gdb/minsyms.c
index 67bd4903a3e..3fa07f47b9f 100644
--- a/gdb/minsyms.c
+++ b/gdb/minsyms.c
@@ -796,14 +796,14 @@ lookup_minimal_symbol_by_pc_section (CORE_ADDR pc_in, struct obj_section *sectio
 
 	  unrelocated_addr unrel_pc;
 	  if (frob_address (objfile, pc, &unrel_pc)
-	      && unrel_pc >= msymbol[lo].value_raw_address ())
+	      && unrel_pc >= msymbol[lo].unrelocated_address ())
 	    {
-	      while (msymbol[hi].value_raw_address () > unrel_pc)
+	      while (msymbol[hi].unrelocated_address () > unrel_pc)
 		{
 		  /* pc is still strictly less than highest address.  */
 		  /* Note "new" will always be >= lo.  */
 		  newobj = (lo + hi) / 2;
-		  if ((msymbol[newobj].value_raw_address () >= unrel_pc)
+		  if ((msymbol[newobj].unrelocated_address () >= unrel_pc)
 		      || (lo == newobj))
 		    {
 		      hi = newobj;
@@ -818,8 +818,8 @@ lookup_minimal_symbol_by_pc_section (CORE_ADDR pc_in, struct obj_section *sectio
 		 hi to point to the last one.  That way we can find the
 		 right symbol if it has an index greater than hi.  */
 	      while (hi < objfile->per_bfd->minimal_symbol_count - 1
-		     && (msymbol[hi].value_raw_address ()
-			 == msymbol[hi + 1].value_raw_address ()))
+		     && (msymbol[hi].unrelocated_address ()
+			 == msymbol[hi + 1].unrelocated_address ()))
 		hi++;
 
 	      /* Skip various undesirable symbols.  */
@@ -866,8 +866,8 @@ lookup_minimal_symbol_by_pc_section (CORE_ADDR pc_in, struct obj_section *sectio
 		      && msymbol[hi].type () != want_type
 		      && msymbol[hi - 1].type () == want_type
 		      && (msymbol[hi].size () == msymbol[hi - 1].size ())
-		      && (msymbol[hi].value_raw_address ()
-			  == msymbol[hi - 1].value_raw_address ())
+		      && (msymbol[hi].unrelocated_address ()
+			  == msymbol[hi - 1].unrelocated_address ())
 		      && (msymbol[hi].obj_section (objfile)
 			  == msymbol[hi - 1].obj_section (objfile)))
 		    {
@@ -896,8 +896,8 @@ lookup_minimal_symbol_by_pc_section (CORE_ADDR pc_in, struct obj_section *sectio
 		     the cancellable variants, but both have sizes.  */
 		  if (hi > 0
 		      && msymbol[hi].size () != 0
-		      && unrel_pc >= msymbol[hi].value_raw_end_address ()
-		      && unrel_pc < msymbol[hi - 1].value_raw_end_address ())
+		      && unrel_pc >= msymbol[hi].unrelocated_end_address ()
+		      && unrel_pc < msymbol[hi - 1].unrelocated_end_address ())
 		    {
 		      hi--;
 		      continue;
@@ -926,7 +926,7 @@ lookup_minimal_symbol_by_pc_section (CORE_ADDR pc_in, struct obj_section *sectio
 
 	      if (hi >= 0
 		  && msymbol[hi].size () != 0
-		  && unrel_pc >= msymbol[hi].value_raw_end_address ())
+		  && unrel_pc >= msymbol[hi].unrelocated_end_address ())
 		{
 		  if (best_zero_sized != -1)
 		    hi = best_zero_sized;
@@ -937,8 +937,8 @@ lookup_minimal_symbol_by_pc_section (CORE_ADDR pc_in, struct obj_section *sectio
 		      if (previous != nullptr)
 			{
 			  if (previous->minsym == nullptr
-			      || (msymbol[hi].value_raw_address ()
-				  > previous->minsym->value_raw_address ()))
+			      || (msymbol[hi].unrelocated_address ()
+				  > previous->minsym->unrelocated_address ()))
 			    {
 			      previous->minsym = &msymbol[hi];
 			      previous->objfile = objfile;
@@ -955,8 +955,8 @@ lookup_minimal_symbol_by_pc_section (CORE_ADDR pc_in, struct obj_section *sectio
 
 	      if (hi >= 0
 		  && ((best_symbol == NULL) ||
-		      (best_symbol->value_raw_address () <
-		       msymbol[hi].value_raw_address ())))
+		      (best_symbol->unrelocated_address () <
+		       msymbol[hi].unrelocated_address ())))
 		{
 		  best_symbol = &msymbol[hi];
 		  best_objfile = objfile;
@@ -1222,11 +1222,11 @@ static inline bool
 minimal_symbol_is_less_than (const minimal_symbol &fn1,
 			     const minimal_symbol &fn2)
 {
-  if ((&fn1)->value_raw_address () < (&fn2)->value_raw_address ())
+  if ((&fn1)->unrelocated_address () < (&fn2)->unrelocated_address ())
     {
       return true;		/* addr 1 is less than addr 2.  */
     }
-  else if ((&fn1)->value_raw_address () > (&fn2)->value_raw_address ())
+  else if ((&fn1)->unrelocated_address () > (&fn2)->unrelocated_address ())
     {
       return false;		/* addr 1 is greater than addr 2.  */
     }
@@ -1286,8 +1286,8 @@ compact_minimal_symbols (struct minimal_symbol *msymbol, int mcount,
       copyfrom = copyto = msymbol;
       while (copyfrom < msymbol + mcount - 1)
 	{
-	  if (copyfrom->value_raw_address ()
-	      == (copyfrom + 1)->value_raw_address ()
+	  if (copyfrom->unrelocated_address ()
+	      == (copyfrom + 1)->unrelocated_address ()
 	      && (copyfrom->section_index ()
 		  == (copyfrom + 1)->section_index ())
 	      && strcmp (copyfrom->linkage_name (),
@@ -1593,8 +1593,8 @@ minimal_symbol_upper_bound (struct bound_minimal_symbol minsym)
   section = msymbol->section_index ();
   for (iter = msymbol + 1; iter != past_the_end; ++iter)
     {
-      if ((iter->value_raw_address ()
-	   != msymbol->value_raw_address ())
+      if ((iter->unrelocated_address ()
+	   != msymbol->unrelocated_address ())
 	  && iter->section_index () == section)
 	break;
     }
diff --git a/gdb/mips-tdep.c b/gdb/mips-tdep.c
index b86bf61f4d1..7092b266db3 100644
--- a/gdb/mips-tdep.c
+++ b/gdb/mips-tdep.c
@@ -436,13 +436,13 @@ mips_elf_make_msymbol_special (asymbol * sym, struct minimal_symbol *msym)
   if (ELF_ST_IS_MICROMIPS (st_other))
     {
       SET_MSYMBOL_TARGET_FLAG_MICROMIPS (msym);
-      CORE_ADDR fixed = CORE_ADDR (msym->value_raw_address ()) | 1;
+      CORE_ADDR fixed = CORE_ADDR (msym->unrelocated_address ()) | 1;
       msym->set_unrelocated_address (unrelocated_addr (fixed));
     }
   else if (ELF_ST_IS_MIPS16 (st_other))
     {
       SET_MSYMBOL_TARGET_FLAG_MIPS16 (msym);
-      CORE_ADDR fixed = CORE_ADDR (msym->value_raw_address ()) | 1;
+      CORE_ADDR fixed = CORE_ADDR (msym->unrelocated_address ()) | 1;
       msym->set_unrelocated_address (unrelocated_addr (fixed));
     }
 }
diff --git a/gdb/parse.c b/gdb/parse.c
index 4bce63c58f7..c0c9fa0a448 100644
--- a/gdb/parse.c
+++ b/gdb/parse.c
@@ -115,7 +115,7 @@ find_minsym_type_and_address (minimal_symbol *msymbol,
     {
       /* Addresses of TLS symbols are really offsets into a
 	 per-objfile/per-thread storage block.  */
-      addr = CORE_ADDR (bound_msym.minsym->value_raw_address ());
+      addr = CORE_ADDR (bound_msym.minsym->unrelocated_address ());
     }
   else if (msymbol_is_function (objfile, msymbol, &addr))
     {
diff --git a/gdb/printcmd.c b/gdb/printcmd.c
index d4b3cce696f..dd92e31d31b 100644
--- a/gdb/printcmd.c
+++ b/gdb/printcmd.c
@@ -1824,7 +1824,7 @@ info_address_command (const char *exp, int from_tty)
 	    if (section
 		&& (section->the_bfd_section->flags & SEC_THREAD_LOCAL) != 0)
 	      {
-		load_addr = CORE_ADDR (msym.minsym->value_raw_address ());
+		load_addr = CORE_ADDR (msym.minsym->unrelocated_address ());
 		gdb_printf (_("a thread-local variable at offset %s "
 			      "in the thread-local storage for `%s'"),
 			    paddress (gdbarch, load_addr),
diff --git a/gdb/psympriv.h b/gdb/psympriv.h
index 8f059dc5975..17c45e9220a 100644
--- a/gdb/psympriv.h
+++ b/gdb/psympriv.h
@@ -173,14 +173,14 @@ struct partial_symtab
 
   /* Return the unrelocated low text address of this
      partial_symtab.  */
-  unrelocated_addr raw_text_low () const
+  unrelocated_addr unrelocated_text_low () const
   {
     return m_text_low;
   }
 
   /* Return the unrelocated_addr high text address of this
      partial_symtab.  */
-  unrelocated_addr raw_text_high () const
+  unrelocated_addr unrelocated_text_high () const
   {
     return m_text_high;
   }
diff --git a/gdb/psymtab.c b/gdb/psymtab.c
index c74280761dd..64b67078641 100644
--- a/gdb/psymtab.c
+++ b/gdb/psymtab.c
@@ -1115,7 +1115,7 @@ partial_symtab::partial_symtab (const char *filename,
   : partial_symtab (filename, partial_symtabs, objfile_per_bfd)
 {
   set_text_low (textlow);
-  set_text_high (raw_text_low ()); /* default */
+  set_text_high (unrelocated_text_low ()); /* default */
 }
 
 /* Perform "finishing up" operations of a partial symtab.  */
@@ -1654,7 +1654,7 @@ maintenance_check_psymtabs (const char *ignore, int from_tty)
 		      gdb_printf (" psymtab\n");
 		    }
 		}
-	      if (ps->raw_text_high () != unrelocated_addr (0)
+	      if (ps->unrelocated_text_high () != unrelocated_addr (0)
 		  && (ps->text_low (objfile) < b->start ()
 		      || ps->text_high (objfile) > b->end ()))
 		{
diff --git a/gdb/solib.c b/gdb/solib.c
index e839b634e04..761cace2306 100644
--- a/gdb/solib.c
+++ b/gdb/solib.c
@@ -1515,7 +1515,7 @@ gdb_bfd_lookup_symbol_from_symtab
 
 		  msym.set_value_address (symaddr);
 		  gdbarch_elf_make_msymbol_special (gdbarch, sym, &msym);
-		  symaddr = CORE_ADDR (msym.value_raw_address ());
+		  symaddr = CORE_ADDR (msym.unrelocated_address ());
 		}
 
 	      /* BFD symbols are section relative.  */
diff --git a/gdb/symmisc.c b/gdb/symmisc.c
index df2bdb0d7c3..65564712282 100644
--- a/gdb/symmisc.c
+++ b/gdb/symmisc.c
@@ -201,7 +201,7 @@ dump_msymbols (struct objfile *objfile, struct ui_file *outfile)
 
       /* Use the relocated address as shown in the symbol here -- do
 	 not try to respect copy relocations.  */
-      CORE_ADDR addr = (CORE_ADDR (msymbol->value_raw_address ())
+      CORE_ADDR addr = (CORE_ADDR (msymbol->unrelocated_address ())
 			+ objfile->section_offsets[msymbol->section_index ()]);
       gdb_puts (paddress (gdbarch, addr), outfile);
       gdb_printf (outfile, " %s", msymbol->linkage_name ());
diff --git a/gdb/symtab.c b/gdb/symtab.c
index ac6535fe983..42e7f5cd908 100644
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -424,7 +424,7 @@ minimal_symbol::value_address (objfile *objfile) const
   if (this->maybe_copied)
     return get_msymbol_address (objfile, this);
   else
-    return (CORE_ADDR (this->value_raw_address ())
+    return (CORE_ADDR (this->unrelocated_address ())
 	    + objfile->section_offsets[this->section_index ()]);
 }
 
diff --git a/gdb/symtab.h b/gdb/symtab.h
index 1f3e0b87b19..e55a613bd84 100644
--- a/gdb/symtab.h
+++ b/gdb/symtab.h
@@ -759,16 +759,16 @@ struct minimal_symbol : public general_symbol_info
   CORE_ADDR value_address () const = delete;
 
   /* The unrelocated address of the minimal symbol.  */
-  unrelocated_addr value_raw_address () const
+  unrelocated_addr unrelocated_address () const
   {
     return m_value.unrel_addr;
   }
 
   /* The unrelocated address just after the end of the the minimal
      symbol.  */
-  unrelocated_addr value_raw_end_address () const
+  unrelocated_addr unrelocated_end_address () const
   {
-    return unrelocated_addr (CORE_ADDR (value_raw_address ()) + size ());
+    return unrelocated_addr (CORE_ADDR (unrelocated_address ()) + size ());
   }
 
   /* Return this minimal symbol's type.  */
diff --git a/gdb/xcoffread.c b/gdb/xcoffread.c
index 52ed13062f2..131a4e398be 100644
--- a/gdb/xcoffread.c
+++ b/gdb/xcoffread.c
@@ -2177,11 +2177,12 @@ scan_xcoff_symtab (minimal_symbol_reader &reader,
 			  = unrelocated_addr (symbol.n_value
 					      + csect_aux.x_csect.x_scnlen.l);
 
-			if (highval > pst->raw_text_high ())
+			if (highval > pst->unrelocated_text_high ())
 			  pst->set_text_high (highval);
 			unrelocated_addr loval
 			  = unrelocated_addr (symbol.n_value);
-			if (!pst->text_low_valid || loval < pst->raw_text_low ())
+			if (!pst->text_low_valid
+			    || loval < pst->unrelocated_text_low ())
 			  pst->set_text_low (loval);
 		      }
 		    misc_func_recorded = 0;

-- 
2.39.1


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH 0/6] Use unrelocate_addr in more places
  2023-03-21 19:18 [PATCH 0/6] Use unrelocate_addr in more places Tom Tromey
                   ` (5 preceding siblings ...)
  2023-03-21 19:18 ` [PATCH 6/6] Rename "raw" to "unrelocated" Tom Tromey
@ 2023-03-28 12:36 ` Alexandra Petlanova Hajkova
  2023-03-28 21:23   ` Tom Tromey
  6 siblings, 1 reply; 16+ messages in thread
From: Alexandra Petlanova Hajkova @ 2023-03-28 12:36 UTC (permalink / raw)
  To: Tom Tromey; +Cc: gdb-patches

[-- Attachment #1: Type: text/plain, Size: 737 bytes --]

On Tue, Mar 21, 2023 at 8:18 PM Tom Tromey <tom@tromey.com> wrote:

> Minimal symbols, partial symbols, and partial symtabs all use
> unrelocated addresses right now.  This series converts these to use
> the unrelocated_addr type, revealing (I believe) a few latent bugs.
>
> Regression tested on x86-64 Fedora 36.
>
> Tom
>
> ---
> Tom Tromey (6):
>       Use function_view in gdb_bfd_lookup_symbol
>       Move definition of unrelocated_addr earlier
>       Use unrelocated_addr in partial symbol tables
>       Use unrelocated_addr in psymbols
>       Use unrelocated_addr in minimal symbols
>       Rename "raw" to "unrelocated"
>
> I can confirm the series show no regressions on Fedora 38, x86_64 machine.
>

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH 1/6] Use function_view in gdb_bfd_lookup_symbol
  2023-03-21 19:18 ` [PATCH 1/6] Use function_view in gdb_bfd_lookup_symbol Tom Tromey
@ 2023-03-28 13:23   ` Simon Marchi
  2023-03-28 21:17     ` Tom Tromey
  0 siblings, 1 reply; 16+ messages in thread
From: Simon Marchi @ 2023-03-28 13:23 UTC (permalink / raw)
  To: Tom Tromey, gdb-patches

> @@ -1675,10 +1673,8 @@ gdb_bfd_read_elf_soname (const char *filename)
>     if symbol is not found.  */
>  
>  static CORE_ADDR
> -bfd_lookup_symbol_from_dyn_symtab (bfd *abfd,
> -				   int (*match_sym) (const asymbol *,
> -						     const void *),
> -				   const void *data)
> +bfd_lookup_symbol_from_dyn_symtab
> +     (bfd *abfd, gdb::function_view<bool (const asymbol *)> match_sym)
You fixed "Return NULL" to "Return 0" in the doc for the other function.
You could do it for the documentation of
bfd_lookup_symbol_from_dyn_symtab as well.

Otherwise, LGTM.

Simon


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH 5/6] Use unrelocated_addr in minimal symbols
  2023-03-21 19:18 ` [PATCH 5/6] Use unrelocated_addr in minimal symbols Tom Tromey
@ 2023-03-28 13:46   ` Simon Marchi
  2023-03-28 21:23     ` Tom Tromey
  2023-03-30  3:52   ` Thiago Jung Bauermann
  1 sibling, 1 reply; 16+ messages in thread
From: Simon Marchi @ 2023-03-28 13:46 UTC (permalink / raw)
  To: Tom Tromey, gdb-patches

On 3/21/23 15:18, Tom Tromey wrote:
> This changes minimal symbols to use unrelocated_addr.  I believe this
> detected a latent bug in add_pe_forwarded_sym.

Given the time I have right now, I just looked at a subset of the
changes, it looks fine to me.

On thought I had is that the frob_address function (from minsyms.c)
would be a good candidate to become a general-purpose
objfile::unrelocate method (for those callers that don't know the
section index).

Simon

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH 1/6] Use function_view in gdb_bfd_lookup_symbol
  2023-03-28 13:23   ` Simon Marchi
@ 2023-03-28 21:17     ` Tom Tromey
  0 siblings, 0 replies; 16+ messages in thread
From: Tom Tromey @ 2023-03-28 21:17 UTC (permalink / raw)
  To: Simon Marchi; +Cc: Tom Tromey, gdb-patches

>>>>> "Simon" == Simon Marchi <simark@simark.ca> writes:

>> @@ -1675,10 +1673,8 @@ gdb_bfd_read_elf_soname (const char *filename)
>> if symbol is not found.  */
>> 
>> static CORE_ADDR
>> -bfd_lookup_symbol_from_dyn_symtab (bfd *abfd,
>> -				   int (*match_sym) (const asymbol *,
>> -						     const void *),
>> -				   const void *data)
>> +bfd_lookup_symbol_from_dyn_symtab
>> +     (bfd *abfd, gdb::function_view<bool (const asymbol *)> match_sym)

Simon> You fixed "Return NULL" to "Return 0" in the doc for the other function.
Simon> You could do it for the documentation of
Simon> bfd_lookup_symbol_from_dyn_symtab as well.

Thanks, I made this change.

Tom

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH 5/6] Use unrelocated_addr in minimal symbols
  2023-03-28 13:46   ` Simon Marchi
@ 2023-03-28 21:23     ` Tom Tromey
  0 siblings, 0 replies; 16+ messages in thread
From: Tom Tromey @ 2023-03-28 21:23 UTC (permalink / raw)
  To: Simon Marchi; +Cc: Tom Tromey, gdb-patches

>>>>> "Simon" == Simon Marchi <simark@simark.ca> writes:

Simon> On 3/21/23 15:18, Tom Tromey wrote:
>> This changes minimal symbols to use unrelocated_addr.  I believe this
>> detected a latent bug in add_pe_forwarded_sym.

Simon> Given the time I have right now, I just looked at a subset of the
Simon> changes, it looks fine to me.

Thanks.  I'm going to check it in.

Simon> On thought I had is that the frob_address function (from minsyms.c)
Simon> would be a good candidate to become a general-purpose
Simon> objfile::unrelocate method (for those callers that don't know the
Simon> section index).

I didn't do this yet but I suppose I could.

Tom

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH 0/6] Use unrelocate_addr in more places
  2023-03-28 12:36 ` [PATCH 0/6] Use unrelocate_addr in more places Alexandra Petlanova Hajkova
@ 2023-03-28 21:23   ` Tom Tromey
  0 siblings, 0 replies; 16+ messages in thread
From: Tom Tromey @ 2023-03-28 21:23 UTC (permalink / raw)
  To: Alexandra Petlanova Hajkova; +Cc: Tom Tromey, gdb-patches

>>>>> Alexandra Petlanova Hajkova <ahajkova@redhat.com> writes:

>  I can confirm the series show no regressions on Fedora 38, x86_64 machine.

Thank you.

Tom

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH 5/6] Use unrelocated_addr in minimal symbols
  2023-03-21 19:18 ` [PATCH 5/6] Use unrelocated_addr in minimal symbols Tom Tromey
  2023-03-28 13:46   ` Simon Marchi
@ 2023-03-30  3:52   ` Thiago Jung Bauermann
  2023-04-03 15:04     ` Tom Tromey
  1 sibling, 1 reply; 16+ messages in thread
From: Thiago Jung Bauermann @ 2023-03-30  3:52 UTC (permalink / raw)
  To: Tom Tromey; +Cc: gdb-patches


Hello,

Tom Tromey <tom@tromey.com> writes:

> This changes minimal symbols to use unrelocated_addr.  I believe this
> detected a latent bug in add_pe_forwarded_sym.

This caused a regression on aarch64-linux. Previously
gdb.asm/asm-source.exp passed all tests, but now:

Running /home/thiago.bauermann/src/binutils-gdb/gdb/testsuite/gdb.asm/asm-source.exp ...
PASS: gdb.asm/asm-source.exp: f at main
PASS: gdb.asm/asm-source.exp: n at main
PASS: gdb.asm/asm-source.exp: next over macro
FAIL: gdb.asm/asm-source.exp: step into foo2
PASS: gdb.asm/asm-source.exp: info target
PASS: gdb.asm/asm-source.exp: info symbol
PASS: gdb.asm/asm-source.exp: list
PASS: gdb.asm/asm-source.exp: search
FAIL: gdb.asm/asm-source.exp: f in foo2
FAIL: gdb.asm/asm-source.exp: n in foo2 (the program exited)
FAIL: gdb.asm/asm-source.exp: bt ALL in foo2
FAIL: gdb.asm/asm-source.exp: bt 2 in foo2
PASS: gdb.asm/asm-source.exp: s 2
PASS: gdb.asm/asm-source.exp: n 2
FAIL: gdb.asm/asm-source.exp: bt 3 in foo3
PASS: gdb.asm/asm-source.exp: info source asmsrc1.s
FAIL: gdb.asm/asm-source.exp: finish from foo3 (the program is no longer running)
FAIL: gdb.asm/asm-source.exp: info source asmsrc2.s
PASS: gdb.asm/asm-source.exp: info sources
FAIL: gdb.asm/asm-source.exp: info line
FAIL: gdb.asm/asm-source.exp: next over foo3 (the program is no longer running)
FAIL: gdb.asm/asm-source.exp: return from foo2
PASS: gdb.asm/asm-source.exp: look at global variable
PASS: gdb.asm/asm-source.exp: x/i &globalvar
PASS: gdb.asm/asm-source.exp: disassem &globalvar, (int *) &globalvar+1
PASS: gdb.asm/asm-source.exp: look at static variable
PASS: gdb.asm/asm-source.exp: x/i &staticvar
PASS: gdb.asm/asm-source.exp: disassem &staticvar, (int *) &staticvar+1
PASS: gdb.asm/asm-source.exp: look at static function

The failures happen because GDB isn't able to step into foo2 anymore,
and steps over it instead:

(gdb) PASS: gdb.asm/asm-source.exp: next over macro
s^M
53		gdbasm_exit0^M
(gdb) FAIL: gdb.asm/asm-source.exp: step into foo2

I'm currently investigating.

-- 
Thiago

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH 5/6] Use unrelocated_addr in minimal symbols
  2023-03-30  3:52   ` Thiago Jung Bauermann
@ 2023-04-03 15:04     ` Tom Tromey
  2023-04-04 18:05       ` Thiago Jung Bauermann
  0 siblings, 1 reply; 16+ messages in thread
From: Tom Tromey @ 2023-04-03 15:04 UTC (permalink / raw)
  To: Thiago Jung Bauermann via Gdb-patches; +Cc: Tom Tromey, Thiago Jung Bauermann

>>>>> Thiago Jung Bauermann via Gdb-patches <gdb-patches@sourceware.org> writes:

>> This changes minimal symbols to use unrelocated_addr.  I believe this
>> detected a latent bug in add_pe_forwarded_sym.

> This caused a regression on aarch64-linux. Previously
> gdb.asm/asm-source.exp passed all tests, but now:
...
> The failures happen because GDB isn't able to step into foo2 anymore,
> and steps over it instead:

> I'm currently investigating.

Let me know if there's anything I can do to help.

Tom

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH 5/6] Use unrelocated_addr in minimal symbols
  2023-04-03 15:04     ` Tom Tromey
@ 2023-04-04 18:05       ` Thiago Jung Bauermann
  0 siblings, 0 replies; 16+ messages in thread
From: Thiago Jung Bauermann @ 2023-04-04 18:05 UTC (permalink / raw)
  To: Tom Tromey; +Cc: gdb-patches


Tom Tromey <tom@tromey.com> writes:

>>>>>> Thiago Jung Bauermann via Gdb-patches <gdb-patches@sourceware.org> writes:
>
>>> This changes minimal symbols to use unrelocated_addr.  I believe this
>>> detected a latent bug in add_pe_forwarded_sym.
>
>> This caused a regression on aarch64-linux. Previously
>> gdb.asm/asm-source.exp passed all tests, but now:
> ...
>> The failures happen because GDB isn't able to step into foo2 anymore,
>> and steps over it instead:
>
>> I'm currently investigating.
>
> Let me know if there's anything I can do to help.

Thanks! It turned out to be a simple problem. I posted the fix here:

https://inbox.sourceware.org/gdb-patches/20230404175915.288558-1-thiago.bauermann@linaro.org/

-- 
Thiago

^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2023-04-04 18:05 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-21 19:18 [PATCH 0/6] Use unrelocate_addr in more places Tom Tromey
2023-03-21 19:18 ` [PATCH 1/6] Use function_view in gdb_bfd_lookup_symbol Tom Tromey
2023-03-28 13:23   ` Simon Marchi
2023-03-28 21:17     ` Tom Tromey
2023-03-21 19:18 ` [PATCH 2/6] Move definition of unrelocated_addr earlier Tom Tromey
2023-03-21 19:18 ` [PATCH 3/6] Use unrelocated_addr in partial symbol tables Tom Tromey
2023-03-21 19:18 ` [PATCH 4/6] Use unrelocated_addr in psymbols Tom Tromey
2023-03-21 19:18 ` [PATCH 5/6] Use unrelocated_addr in minimal symbols Tom Tromey
2023-03-28 13:46   ` Simon Marchi
2023-03-28 21:23     ` Tom Tromey
2023-03-30  3:52   ` Thiago Jung Bauermann
2023-04-03 15:04     ` Tom Tromey
2023-04-04 18:05       ` Thiago Jung Bauermann
2023-03-21 19:18 ` [PATCH 6/6] Rename "raw" to "unrelocated" Tom Tromey
2023-03-28 12:36 ` [PATCH 0/6] Use unrelocate_addr in more places Alexandra Petlanova Hajkova
2023-03-28 21:23   ` Tom Tromey

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).