This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[12/17] change minsyms to use indices


This patch changes minimal symbols to use the new index, rather than
obj_section.

It adds an objfile parameter to MSYMBOL_OBJ_SECTION and updates all
users.  Sometimes it can be a pain to find this, but usually not.  It
adds a new API for looking up minimal symbols that will also return the
objfile; that made things simpler.

Some places can just use the index directly; this is cheaper.

Tom

>From 26254337e254085ed0ab1da7d08a54740cf8d61e Mon Sep 17 00:00:00 2001
From: Tom Tromey <tromey@redhat.com>
Date: Wed, 7 Dec 2011 12:10:47 -0700
Subject: [PATCH 12/18] change minsyms to use indices, not obj_sections

	* blockframe.c (find_pc_partial_function_gnu_ifunc): Use
	MSYMBOL_SECTION_INDEX.
	* breakpoint.c (resolve_sal_pc): Use
	lookup_minimal_symbol_and_objfile_by_pc.  Update.
	* elfread.c (elf_gnu_ifunc_record_cache): Use
	lookup_minimal_symbol_and_objfile_by_pc.  Update.
	* findvar.c (read_var_value): Use lookup_minimal_symbol_full.
	Update.
	* hppa-hpux-tdep.c (hppa64_hpux_in_solib_call_trampoline): Use
	lookup_minimal_symbol_and_objfile_by_pc.  Update.
	* linespec.c (minsym_found): Update.
	* maint.c (maintenance_translate_address): Update.
	* minsyms.c (lookup_minimal_symbol_full): New function, based on
	old lookup_minimal_symbol.
	(lookup_minimal_symbol): Rewrite to use
	lookup_minimal_symbol_full.
	(lookup_minimal_symbol_by_pc_section_1): Update.
	(lookup_minimal_symbol_and_objfile_by_pc): New function.
	(prim_record_minimal_symbol_full): Use MSYMBOL_SECTION_INDEX.
	* minsyms.h (lookup_minimal_symbol_full): Declare.
	* parse.c (write_exp_msymbol): Update.
	* printcmd.c (address_info): Update.
	* spu-tdep.c (spu_catch_start): Update.
	* symmisc.c (dump_msymbols): Update.
	* symtab.c (fixup_section): Update.
	(skip_prologue_sal): Update.
	* symtab.h (MSYMBOL_OBJ_SECTION): Add objfile parameter.
	(MSYMBOL_SECTION_INDEX): New macro.
---
 gdb/blockframe.c     |    4 +-
 gdb/breakpoint.c     |    6 +++-
 gdb/elfread.c        |    5 +--
 gdb/findvar.c        |    8 +++--
 gdb/hppa-hpux-tdep.c |    5 ++-
 gdb/linespec.c       |    2 +-
 gdb/maint.c          |    9 ++++--
 gdb/minsyms.c        |   69 ++++++++++++++++++++++++++++++++++++++++---------
 gdb/minsyms.h        |   10 ++++++-
 gdb/parse.c          |    2 +-
 gdb/printcmd.c       |   10 +++++--
 gdb/spu-tdep.c       |    2 +-
 gdb/symmisc.c        |    2 +-
 gdb/symtab.c         |    6 ++--
 gdb/symtab.h         |    5 +++-
 15 files changed, 105 insertions(+), 40 deletions(-)

diff --git a/gdb/blockframe.c b/gdb/blockframe.c
index df78112..704c871 100644
--- a/gdb/blockframe.c
+++ b/gdb/blockframe.c
@@ -294,8 +294,8 @@ find_pc_partial_function_gnu_ifunc (CORE_ADDR pc, char **name,
 	{
 	  if (MSYMBOL_VALUE_ADDRESS (msymbol + i)
 	      != MSYMBOL_VALUE_ADDRESS (msymbol)
-	      && MSYMBOL_OBJ_SECTION (msymbol + i)
-	      == MSYMBOL_OBJ_SECTION (msymbol))
+	      && MSYMBOL_SECTION_INDEX (msymbol + i)
+	      == MSYMBOL_SECTION_INDEX (msymbol))
 	    break;
 	}
 
diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index 91b74f4..6bfb1ec 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -8028,13 +8028,15 @@ resolve_sal_pc (struct symtab_and_line *sal)
 	         happen in assembly source).  */
 
 	      struct minimal_symbol *msym;
+	      struct objfile *objfile;
 	      struct cleanup *old_chain = save_current_space_and_thread ();
 
 	      switch_to_program_space_and_thread (sal->pspace);
 
-	      msym = lookup_minimal_symbol_by_pc (sal->pc);
+	      msym = lookup_minimal_symbol_and_objfile_by_pc (sal->pc,
+							      &objfile);
 	      if (msym)
-		sal->section = MSYMBOL_OBJ_SECTION (msym);
+		sal->section = MSYMBOL_OBJ_SECTION (objfile, msym);
 
 	      do_cleanups (old_chain);
 	    }
diff --git a/gdb/elfread.c b/gdb/elfread.c
index e8f1310..8f0bde0 100644
--- a/gdb/elfread.c
+++ b/gdb/elfread.c
@@ -727,14 +727,13 @@ elf_gnu_ifunc_record_cache (const char *name, CORE_ADDR addr)
   struct elf_gnu_ifunc_cache entry_local, *entry_p;
   void **slot;
 
-  msym = lookup_minimal_symbol_by_pc (addr);
+  msym = lookup_minimal_symbol_and_objfile_by_pc (addr, &objfile);
   if (msym == NULL)
     return 0;
   if (MSYMBOL_VALUE_ADDRESS (msym) != addr)
     return 0;
   /* minimal symbols have always SYMBOL_OBJ_SECTION non-NULL.  */
-  sect = MSYMBOL_OBJ_SECTION (msym)->the_bfd_section;
-  objfile = MSYMBOL_OBJ_SECTION (msym)->objfile;
+  sect = MSYMBOL_OBJ_SECTION (objfile, msym)->the_bfd_section;
 
   /* If .plt jumps back to .plt the symbol is still deferred for later
      resolution and it has no use for GDB.  Besides ".text" this symbol can
diff --git a/gdb/findvar.c b/gdb/findvar.c
index aca8552..5991eaf 100644
--- a/gdb/findvar.c
+++ b/gdb/findvar.c
@@ -562,18 +562,20 @@ read_var_value (struct symbol *var, struct frame_info *frame)
     case LOC_UNRESOLVED:
       {
 	struct minimal_symbol *msym;
+	struct objfile *objf;
 	struct obj_section *obj_section;
 
-	msym = lookup_minimal_symbol (SYMBOL_LINKAGE_NAME (var), NULL, NULL);
+	msym = lookup_minimal_symbol_full (SYMBOL_LINKAGE_NAME (var),
+					   NULL, NULL, &objf);
 	if (msym == NULL)
 	  error (_("No global symbol \"%s\"."), SYMBOL_LINKAGE_NAME (var));
 	if (overlay_debugging)
 	  addr = symbol_overlayed_address (MSYMBOL_VALUE_ADDRESS (msym),
-					   MSYMBOL_OBJ_SECTION (msym));
+					   MSYMBOL_OBJ_SECTION (objf, msym));
 	else
 	  addr = MSYMBOL_VALUE_ADDRESS (msym);
 
-	obj_section = MSYMBOL_OBJ_SECTION (msym);
+	obj_section = MSYMBOL_OBJ_SECTION (objf, msym);
 	if (obj_section
 	    && (obj_section->the_bfd_section->flags & SEC_THREAD_LOCAL) != 0)
 	  addr = target_translate_tls_address (obj_section->objfile, addr);
diff --git a/gdb/hppa-hpux-tdep.c b/gdb/hppa-hpux-tdep.c
index 3771487..e750874 100644
--- a/gdb/hppa-hpux-tdep.c
+++ b/gdb/hppa-hpux-tdep.c
@@ -179,12 +179,13 @@ hppa64_hpux_in_solib_call_trampoline (struct gdbarch *gdbarch,
   asection *sec;
   CORE_ADDR addr;
   int insn, i;
+  struct objfile *objf;
 
-  minsym = lookup_minimal_symbol_by_pc (pc);
+  minsym = lookup_minimal_symbol_and_objfile_by_pc (pc, &objf);
   if (! minsym)
     return 0;
 
-  sec = MSYMBOL_OBJ_SECTION (minsym)->the_bfd_section;
+  sec = MSYMBOL_OBJ_SECTION (objf, minsym)->the_bfd_section;
 
   if (bfd_get_section_vma (sec->owner, sec) <= pc
       && pc < (bfd_get_section_vma (sec->owner, sec)
diff --git a/gdb/linespec.c b/gdb/linespec.c
index ad72cb5..769c569 100644
--- a/gdb/linespec.c
+++ b/gdb/linespec.c
@@ -2695,7 +2695,7 @@ minsym_found (struct linespec_state *self, struct objfile *objfile,
 
   sal = find_pc_sect_line (MSYMBOL_VALUE_ADDRESS (msymbol),
 			   (struct obj_section *) 0, 0);
-  sal.section = MSYMBOL_OBJ_SECTION (msymbol);
+  sal.section = MSYMBOL_OBJ_SECTION (objfile, msymbol);
 
   /* The minimal symbol might point to a function descriptor;
      resolve it to the actual code address instead.  */
diff --git a/gdb/maint.c b/gdb/maint.c
index cae675e..dedc750 100644
--- a/gdb/maint.c
+++ b/gdb/maint.c
@@ -477,9 +477,12 @@ maintenance_translate_address (char *arg, int from_tty)
   address = parse_and_eval_address (p);
 
   if (sect)
-    sym = lookup_minimal_symbol_by_pc_section (address, sect);
+    {
+      sym = lookup_minimal_symbol_by_pc_section (address, sect);
+      objfile = sect->objfile;
+    }
   else
-    sym = lookup_minimal_symbol_by_pc (address);
+    sym = lookup_minimal_symbol_and_objfile_by_pc (address, &objfile);
 
   if (sym)
     {
@@ -487,7 +490,7 @@ maintenance_translate_address (char *arg, int from_tty)
       const char *symbol_offset
 	= pulongest (address - MSYMBOL_VALUE_ADDRESS (sym));
 
-      sect = MSYMBOL_OBJ_SECTION(sym);
+      sect = MSYMBOL_OBJ_SECTION (objfile, sym);
       if (sect != NULL)
 	{
 	  const char *section_name;
diff --git a/gdb/minsyms.c b/gdb/minsyms.c
index c75c5f1..e5d0b69 100644
--- a/gdb/minsyms.c
+++ b/gdb/minsyms.c
@@ -183,14 +183,18 @@ msymbol_objfile (struct minimal_symbol *sym)
    but the demangled names are all the same: S::S or S::~S.  */
 
 struct minimal_symbol *
-lookup_minimal_symbol (const char *name, const char *sfile,
-		       struct objfile *objf)
+lookup_minimal_symbol_full (const char *name, const char *sfile,
+			    struct objfile *objf,
+			    struct objfile **out_objfile)
 {
   struct objfile *objfile;
   struct minimal_symbol *msymbol;
   struct minimal_symbol *found_symbol = NULL;
+  struct objfile *found_objfile = NULL;
   struct minimal_symbol *found_file_symbol = NULL;
+  struct objfile *found_file_objfile = NULL;
   struct minimal_symbol *trampoline_symbol = NULL;
+  struct objfile *found_trampoline_objfile = NULL;
 
   unsigned int hash = msymbol_hash (name) % MINIMAL_SYMBOL_HASH_SIZE;
   unsigned int dem_hash = msymbol_hash_iw (name) % MINIMAL_SYMBOL_HASH_SIZE;
@@ -262,7 +266,10 @@ lookup_minimal_symbol (const char *name, const char *sfile,
                       case mst_file_bss:
                         if (sfile == NULL
 			    || filename_cmp (msymbol->filename, sfile) == 0)
-                          found_file_symbol = msymbol;
+			  {
+			    found_file_symbol = msymbol;
+			    found_file_objfile = objfile;
+			  }
                         break;
 
                       case mst_solib_trampoline:
@@ -272,12 +279,16 @@ lookup_minimal_symbol (const char *name, const char *sfile,
                            actual symbol is not found, then we'll use the
                            trampoline entry.  */
                         if (trampoline_symbol == NULL)
-                          trampoline_symbol = msymbol;
+			  {
+			    trampoline_symbol = msymbol;
+			    found_trampoline_objfile = objfile;
+			  }
                         break;
 
                       case mst_unknown:
                       default:
                         found_symbol = msymbol;
+			found_objfile = objfile;
                         break;
                       }
 		    }
@@ -297,19 +308,38 @@ lookup_minimal_symbol (const char *name, const char *sfile,
 
   /* External symbols are best.  */
   if (found_symbol)
-    return found_symbol;
+    {
+      if (out_objfile)
+	*out_objfile = found_objfile;
+      return found_symbol;
+    }
 
   /* File-local symbols are next best.  */
   if (found_file_symbol)
-    return found_file_symbol;
+    {
+      if (out_objfile)
+	*out_objfile = found_file_objfile;
+      return found_file_symbol;
+    }
 
   /* Symbols for shared library trampolines are next best.  */
   if (trampoline_symbol)
-    return trampoline_symbol;
+    {
+      if (out_objfile)
+	*out_objfile = found_trampoline_objfile;
+      return trampoline_symbol;
+    }
 
   return NULL;
 }
 
+struct minimal_symbol *
+lookup_minimal_symbol (const char *name, const char *sfile,
+		       struct objfile *objf)
+{
+  return lookup_minimal_symbol_full (name, sfile, objf, NULL);
+}
+
 /* Iterate over all the minimal symbols in the objfile OBJF which
    match NAME.  Both the ordinary and demangled names of each symbol
    are considered.  The caller is responsible for canonicalizing NAME,
@@ -613,9 +643,9 @@ lookup_minimal_symbol_by_pc_section_1 (CORE_ADDR pc,
 		      /* Some types of debug info, such as COFF,
 			 don't fill the bfd_section member, so don't
 			 throw away symbols on those platforms.  */
-		      && MSYMBOL_OBJ_SECTION (&msymbol[hi]) != NULL
+		      && MSYMBOL_OBJ_SECTION (objfile, &msymbol[hi]) != NULL
 		      && (!matching_obj_sections
-			  (MSYMBOL_OBJ_SECTION (&msymbol[hi]), section)))
+			  (MSYMBOL_OBJ_SECTION (objfile, &msymbol[hi]), section)))
 		    {
 		      hi--;
 		      continue;
@@ -632,8 +662,8 @@ lookup_minimal_symbol_by_pc_section_1 (CORE_ADDR pc,
 			  == MSYMBOL_SIZE (&msymbol[hi - 1]))
 		      && (MSYMBOL_VALUE_ADDRESS (&msymbol[hi])
 			  == MSYMBOL_VALUE_ADDRESS (&msymbol[hi - 1]))
-		      && (MSYMBOL_OBJ_SECTION (&msymbol[hi])
-			  == MSYMBOL_OBJ_SECTION (&msymbol[hi - 1])))
+		      && (MSYMBOL_SECTION_INDEX (&msymbol[hi])
+			  == MSYMBOL_SECTION_INDEX (&msymbol[hi - 1])))
 		    {
 		      hi--;
 		      continue;
@@ -743,6 +773,19 @@ lookup_minimal_symbol_by_pc (CORE_ADDR pc)
   return lookup_minimal_symbol_by_pc_section (pc, NULL);
 }
 
+struct minimal_symbol *
+lookup_minimal_symbol_and_objfile_by_pc (CORE_ADDR pc, struct objfile **objf)
+{
+  struct obj_section *section;
+
+  section = find_pc_section (pc);
+  if (section == NULL)
+    return NULL;
+  *objf = section->objfile;
+
+  return lookup_minimal_symbol_by_pc_section_1 (pc, section, 0);
+}
+
 /* Return non-zero iff PC is in an STT_GNU_IFUNC function resolver.  */
 
 int
@@ -945,7 +988,7 @@ prim_record_minimal_symbol_full (const char *name, int name_len, int copy_name,
 
   MSYMBOL_VALUE_ADDRESS (msymbol) = address;
   MSYMBOL_SECTION (msymbol) = section;
-  MSYMBOL_OBJ_SECTION (msymbol) = NULL;
+  MSYMBOL_SECTION_INDEX (msymbol) = 0;
 
   /* Find obj_section corresponding to bfd_section.  */
   if (bfd_section)
@@ -953,7 +996,7 @@ prim_record_minimal_symbol_full (const char *name, int name_len, int copy_name,
       {
 	if (obj_section->the_bfd_section == bfd_section)
 	  {
-	    MSYMBOL_OBJ_SECTION (msymbol) = obj_section;
+	    MSYMBOL_SECTION_INDEX (msymbol) = obj_section - objfile->sections;
 	    break;
 	  }
       }
diff --git a/gdb/minsyms.h b/gdb/minsyms.h
index a60bd81..f66b1e0 100644
--- a/gdb/minsyms.h
+++ b/gdb/minsyms.h
@@ -63,6 +63,11 @@ struct minimal_symbol *lookup_minimal_symbol (const char *,
 					      const char *,
 					      struct objfile *);
 
+struct minimal_symbol *lookup_minimal_symbol_full (const char *,
+						   const char *,
+						   struct objfile *,
+						   struct objfile **);
+
 struct minimal_symbol *lookup_minimal_symbol_text (const char *,
 						   struct objfile *);
 
@@ -71,10 +76,13 @@ struct minimal_symbol *lookup_minimal_symbol_solib_trampoline
      struct objfile *);
 
 struct minimal_symbol *lookup_minimal_symbol_by_pc_name
-(CORE_ADDR, const char *, struct objfile *);
+    (CORE_ADDR, const char *, struct objfile *);
 
 struct minimal_symbol *lookup_minimal_symbol_by_pc (CORE_ADDR);
 
+struct minimal_symbol *lookup_minimal_symbol_and_objfile_by_pc
+    (CORE_ADDR pc, struct objfile **objf);
+
 struct minimal_symbol *lookup_minimal_symbol_and_objfile (const char *,
 							  struct objfile **);
 
diff --git a/gdb/parse.c b/gdb/parse.c
index 7b510b5..d9785de 100644
--- a/gdb/parse.c
+++ b/gdb/parse.c
@@ -478,7 +478,7 @@ write_exp_msymbol (struct minimal_symbol *msymbol)
   struct gdbarch *gdbarch = get_objfile_arch (objfile);
 
   CORE_ADDR addr = MSYMBOL_VALUE_ADDRESS (msymbol);
-  struct obj_section *section = MSYMBOL_OBJ_SECTION (msymbol);
+  struct obj_section *section = MSYMBOL_OBJ_SECTION (objfile, msymbol);
   enum minimal_symbol_type type = MSYMBOL_TYPE (msymbol);
   CORE_ADDR pc;
 
diff --git a/gdb/printcmd.c b/gdb/printcmd.c
index 042ce5f..48d1d8c 100644
--- a/gdb/printcmd.c
+++ b/gdb/printcmd.c
@@ -1215,7 +1215,9 @@ address_info (char *exp, int from_tty)
 
       if (msymbol != NULL)
 	{
-	  gdbarch = get_objfile_arch (msymbol_objfile (msymbol));
+	  struct objfile *objfile = msymbol_objfile (msymbol);
+
+	  gdbarch = get_objfile_arch (objfile);
 	  load_addr = MSYMBOL_VALUE_ADDRESS (msymbol);
 
 	  printf_filtered ("Symbol \"");
@@ -1224,7 +1226,7 @@ address_info (char *exp, int from_tty)
 	  printf_filtered ("\" is at ");
 	  fputs_filtered (paddress (gdbarch, load_addr), gdb_stdout);
 	  printf_filtered (" in a file compiled without debugging");
-	  section = MSYMBOL_OBJ_SECTION (msymbol);
+	  section = MSYMBOL_OBJ_SECTION (objfile, msymbol);
 	  if (section_is_overlay (section))
 	    {
 	      load_addr = overlay_unmapped_address (load_addr, section);
@@ -1356,7 +1358,9 @@ address_info (char *exp, int from_tty)
 	  printf_filtered ("unresolved");
 	else
 	  {
-	    section = MSYMBOL_OBJ_SECTION (msym);
+	    struct objfile *objfile = msymbol_objfile (msym);
+
+	    section = MSYMBOL_OBJ_SECTION (objfile, msym);
 	    load_addr = MSYMBOL_VALUE_ADDRESS (msym);
 
 	    if (section
diff --git a/gdb/spu-tdep.c b/gdb/spu-tdep.c
index c8b0b81..5e696e3 100644
--- a/gdb/spu-tdep.c
+++ b/gdb/spu-tdep.c
@@ -1921,7 +1921,7 @@ spu_catch_start (struct objfile *objfile)
   /* If we have debugging information, try to use it -- this
      will allow us to properly skip the prologue.  */
   pc = MSYMBOL_VALUE_ADDRESS (minsym);
-  symtab = find_pc_sect_symtab (pc, MSYMBOL_OBJ_SECTION (minsym));
+  symtab = find_pc_sect_symtab (pc, MSYMBOL_OBJ_SECTION (objfile, minsym));
   if (symtab != NULL)
     {
       struct blockvector *bv = BLOCKVECTOR (symtab);
diff --git a/gdb/symmisc.c b/gdb/symmisc.c
index 8ce5ab5..dbe6d11 100644
--- a/gdb/symmisc.c
+++ b/gdb/symmisc.c
@@ -215,7 +215,7 @@ dump_msymbols (struct objfile *objfile, struct ui_file *outfile)
   index = 0;
   ALL_OBJFILE_MSYMBOLS (objfile, msymbol)
     {
-      struct obj_section *section = MSYMBOL_OBJ_SECTION (msymbol);
+      struct obj_section *section = MSYMBOL_OBJ_SECTION (objfile, msymbol);
 
       switch (MSYMBOL_TYPE (msymbol))
 	{
diff --git a/gdb/symtab.c b/gdb/symtab.c
index 071c203..23bc561 100644
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -951,7 +951,7 @@ fixup_section (struct general_symbol_info *ginfo,
   msym = lookup_minimal_symbol_by_pc_name (addr, ginfo->name, objfile);
   if (msym)
     {
-      ginfo->sinfo.obj_section = MSYMBOL_OBJ_SECTION (msym);
+      ginfo->sinfo.obj_section = MSYMBOL_OBJ_SECTION (objfile, msym);
       ginfo->section = MSYMBOL_SECTION (msym);
     }
   else
@@ -2670,9 +2670,9 @@ skip_prologue_sal (struct symtab_and_line *sal)
 	}
 
       pc = MSYMBOL_VALUE_ADDRESS (msymbol);
-      section = MSYMBOL_OBJ_SECTION (msymbol);
-      name = MSYMBOL_LINKAGE_NAME (msymbol);
       objfile = msymbol_objfile (msymbol);
+      section = MSYMBOL_OBJ_SECTION (objfile, msymbol);
+      name = MSYMBOL_LINKAGE_NAME (msymbol);
     }
 
   gdbarch = get_objfile_arch (objfile);
diff --git a/gdb/symtab.h b/gdb/symtab.h
index 864d8c8..f3926e8 100644
--- a/gdb/symtab.h
+++ b/gdb/symtab.h
@@ -387,7 +387,10 @@ struct minimal_symbol
 #define MSYMBOL_VALUE_CHAIN(symbol)	(symbol)->mginfo.value.chain
 #define MSYMBOL_LANGUAGE(symbol)	(symbol)->mginfo.language
 #define MSYMBOL_SECTION(symbol)		(symbol)->mginfo.section
-#define MSYMBOL_OBJ_SECTION(symbol)	(symbol)->mginfo.sinfo.obj_section
+#define MSYMBOL_OBJ_SECTION(objfile, symbol) \
+  (&((objfile)->sections[(symbol)->mginfo.sinfo.index]))
+#define MSYMBOL_SECTION_INDEX(symbol) \
+  (symbol)->mginfo.sinfo.index
 
 #define MSYMBOL_NATURAL_NAME(symbol) \
   (symbol_natural_name (&(symbol)->mginfo))
-- 
1.7.6.4


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]