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]

[9/10] RFC: remove general_symbol_info::obj_section


This, finally, removes general_symbol_info::obj_section.

It adds a new 'objfile' parameter to SYMBOL_OBJ_SECTION and updates all
the callers to pass it.  It also changes symbol and psymbol
initializations to init the 'symbol' field to -1, so that fixup_section
will continue to work.

A couple odd things to note:

* stabsread.c was setting the symbol's section.  However, this caused
  some test failures on HPPA.  It seemed better to me not to set the
  section and to let fixup_section do its work.

* fixup_section now has some "fallback" code to try to set the section
  if it is not found via minsyms.

  I think this function is fundamentally confused.

  The comment explains how this is only ever called for un-relocated
  symbols.  And, the code in this function works on that assumption.

  However, most of the rest of gdb doesn't work that way.  For instance,
  I think all the partial symbol readers make relocated symbols and do
  not set the section.

  Anyway, the changes I have made shouldn't really affect anything here
  (well, except perhaps some truly weird situations where a symbol
  doesn't seem to be in any section, but ... those are already doing
  something weird.)

  I'm not really sure what to do here.  I could further change all the
  symbol readers not to do relocation at read time.  However, I think
  that is pretty hard.  Anybody have a better idea?

Tom

	PR symtab/8424:
	* blockframe.c (find_pc_partial_function_gnu_ifunc): Check
	SYMBOL_SECTION, not SYMBOL_OBJ_SECTION.
	* breakpoint.c (resolve_sal_pc): Update.
	* elfread.c (elf_gnu_ifunc_record_cache): Update.
	* findvar.c (struct minsym_lookup_data) <objfile>: New field.
	(minsym_lookup_iterator_cb): Use it.
	(default_read_var_value): Update.
	* hppa-hpux-tdep.c (hppa64_hpux_in_solib_call_trampoline):
	Update.
	* infcmd.c (jump_command): Update.
	* linespec.c (minsym_found): Update.
	* maint.c (maintenance_translate_address): Update.
	* minsyms.c (lookup_minimal_symbol_by_pc_section_1): Update.
	(prim_record_minimal_symbol_full): Don't set SYMBOL_OBJ_SECTION.
	* parse.c (write_exp_msymbol): Update.
	* printcmd.c (address_info): Update.
	* psymtab.c (find_pc_sect_psymbol): Update.
	(fixup_psymbol_section): Check SYMBOL_SECTION, not
	SYMBOL_OBJ_SECTION.
	(add_psymbol_to_bcache): Correctly initialize SYMBOL_SECTION.
	Don't initialize SYMBOL_OBJ_SECTION.
	* spu-tdep.c (spu_catch_start): Update.
	* stabsread.c (define_symbol): Don't set SYMBOL_SECTION.
	* symmisc.c (dump_msymbols, print_symbol): Update.
	* symtab.c (fixup_section): Don't set 'obj_section'.  Change
	how fallback section is computed.
	(fixup_symbol_section): Update.
	(find_pc_sect_symtab, find_function_start_sal, skip_prologue_sal):
	Update.
	(allocate_symbol, initialize_symbol, allocate_template_symbol):
	Initialize SYMBOL_SECTION.
	* symtab.h (struct general_symbol_info) <section>: Update comment.
	<obj_section>: Remove.
	(SYMBOL_OBJ_SECTION): Add 'objfile' argument.  Rewrite.
	(SYMBOL_OBJFILE): New macro.
---
 gdb/blockframe.c     |    4 ++--
 gdb/breakpoint.c     |    4 ++--
 gdb/elfread.c        |    4 ++--
 gdb/findvar.c        |   18 +++++++++++++-----
 gdb/hppa-hpux-tdep.c |    2 +-
 gdb/infcmd.c         |    4 ++--
 gdb/linespec.c       |    2 +-
 gdb/maint.c          |    2 +-
 gdb/minsyms.c        |   10 +++++-----
 gdb/parse.c          |    2 +-
 gdb/printcmd.c       |   18 ++++++++++--------
 gdb/psymtab.c        |   14 +++++++++-----
 gdb/spu-tdep.c       |    2 +-
 gdb/stabsread.c      |   13 -------------
 gdb/symmisc.c        |    5 +++--
 gdb/symtab.c         |   40 ++++++++++++++++++++++++++--------------
 gdb/symtab.h         |   16 +++++++---------
 17 files changed, 86 insertions(+), 74 deletions(-)

diff --git a/gdb/blockframe.c b/gdb/blockframe.c
index aedad3e..40e6c27 100644
--- a/gdb/blockframe.c
+++ b/gdb/blockframe.c
@@ -292,8 +292,8 @@ find_pc_partial_function_gnu_ifunc (CORE_ADDR pc, const char **name,
 	{
 	  if (SYMBOL_VALUE_ADDRESS (msymbol + i)
 	      != SYMBOL_VALUE_ADDRESS (msymbol)
-	      && SYMBOL_OBJ_SECTION (msymbol + i)
-	      == SYMBOL_OBJ_SECTION (msymbol))
+	      && SYMBOL_SECTION (msymbol + i)
+	      == SYMBOL_SECTION (msymbol))
 	    break;
 	}
 
diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index 8f8a30d..3d1cf0d 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -9796,7 +9796,7 @@ resolve_sal_pc (struct symtab_and_line *sal)
 	  if (sym != NULL)
 	    {
 	      fixup_symbol_section (sym, sal->symtab->objfile);
-	      sal->section = SYMBOL_OBJ_SECTION (sym);
+	      sal->section = SYMBOL_OBJ_SECTION (sal->symtab->objfile, sym);
 	    }
 	  else
 	    {
@@ -9812,7 +9812,7 @@ resolve_sal_pc (struct symtab_and_line *sal)
 
 	      msym = lookup_minimal_symbol_by_pc (sal->pc);
 	      if (msym.minsym)
-		sal->section = SYMBOL_OBJ_SECTION (msym.minsym);
+		sal->section = SYMBOL_OBJ_SECTION (msym.objfile, msym.minsym);
 
 	      do_cleanups (old_chain);
 	    }
diff --git a/gdb/elfread.c b/gdb/elfread.c
index c47b849..053c0ba 100644
--- a/gdb/elfread.c
+++ b/gdb/elfread.c
@@ -758,8 +758,8 @@ elf_gnu_ifunc_record_cache (const char *name, CORE_ADDR addr)
   if (SYMBOL_VALUE_ADDRESS (msym.minsym) != addr)
     return 0;
   /* minimal symbols have always SYMBOL_OBJ_SECTION non-NULL.  */
-  sect = SYMBOL_OBJ_SECTION (msym.minsym)->the_bfd_section;
-  objfile = SYMBOL_OBJ_SECTION (msym.minsym)->objfile;
+  sect = SYMBOL_OBJ_SECTION (msym.objfile, msym.minsym)->the_bfd_section;
+  objfile = msym.objfile;
 
   /* 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 fb66e0f..f93b52c 100644
--- a/gdb/findvar.c
+++ b/gdb/findvar.c
@@ -416,6 +416,9 @@ struct minsym_lookup_data
      if found.  It should be initialized to NULL before the search
      is started.  */
   struct minimal_symbol *result;
+
+  /* The objfile in which the symbol was found.  */
+  struct objfile *objfile;
 };
 
 /* A callback function for gdbarch_iterate_over_objfiles_in_search_order.
@@ -431,6 +434,7 @@ minsym_lookup_iterator_cb (struct objfile *objfile, void *cb_data)
   gdb_assert (data->result == NULL);
 
   data->result = lookup_minimal_symbol (data->name, NULL, objfile);
+  data->objfile = objfile;
 
   /* The iterator should stop iff a match was found.  */
   return (data->result != NULL);
@@ -474,7 +478,8 @@ default_read_var_value (struct symbol *var, struct frame_info *frame)
 	{
 	  CORE_ADDR addr
 	    = symbol_overlayed_address (SYMBOL_VALUE_ADDRESS (var),
-					SYMBOL_OBJ_SECTION (var));
+					SYMBOL_OBJ_SECTION (SYMBOL_OBJFILE (var),
+							    var));
 
 	  store_typed_address (value_contents_raw (v), type, addr);
 	}
@@ -495,7 +500,8 @@ default_read_var_value (struct symbol *var, struct frame_info *frame)
       v = allocate_value_lazy (type);
       if (overlay_debugging)
 	addr = symbol_overlayed_address (SYMBOL_VALUE_ADDRESS (var),
-					 SYMBOL_OBJ_SECTION (var));
+					 SYMBOL_OBJ_SECTION (SYMBOL_OBJFILE (var),
+							     var));
       else
 	addr = SYMBOL_VALUE_ADDRESS (var);
       break;
@@ -540,7 +546,8 @@ default_read_var_value (struct symbol *var, struct frame_info *frame)
       v = allocate_value_lazy (type);
       if (overlay_debugging)
 	addr = symbol_overlayed_address
-	  (BLOCK_START (SYMBOL_BLOCK_VALUE (var)), SYMBOL_OBJ_SECTION (var));
+	  (BLOCK_START (SYMBOL_BLOCK_VALUE (var)), SYMBOL_OBJ_SECTION (SYMBOL_OBJFILE (var),
+								       var));
       else
 	addr = BLOCK_START (SYMBOL_BLOCK_VALUE (var));
       break;
@@ -604,11 +611,12 @@ default_read_var_value (struct symbol *var, struct frame_info *frame)
 	  error (_("No global symbol \"%s\"."), SYMBOL_LINKAGE_NAME (var));
 	if (overlay_debugging)
 	  addr = symbol_overlayed_address (SYMBOL_VALUE_ADDRESS (msym),
-					   SYMBOL_OBJ_SECTION (msym));
+					   SYMBOL_OBJ_SECTION (lookup_data.objfile,
+							       msym));
 	else
 	  addr = SYMBOL_VALUE_ADDRESS (msym);
 
-	obj_section = SYMBOL_OBJ_SECTION (msym);
+	obj_section = SYMBOL_OBJ_SECTION (lookup_data.objfile, 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 cc178b8..0044dbf 100644
--- a/gdb/hppa-hpux-tdep.c
+++ b/gdb/hppa-hpux-tdep.c
@@ -184,7 +184,7 @@ hppa64_hpux_in_solib_call_trampoline (struct gdbarch *gdbarch,
   if (! minsym.minsym)
     return 0;
 
-  sec = SYMBOL_OBJ_SECTION (minsym.minsym)->the_bfd_section;
+  sec = SYMBOL_OBJ_SECTION (minsym.objfile, minsym.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/infcmd.c b/gdb/infcmd.c
index 9bc28dd..70897e5 100644
--- a/gdb/infcmd.c
+++ b/gdb/infcmd.c
@@ -1169,8 +1169,8 @@ jump_command (char *arg, int from_tty)
   if (sfn != NULL)
     {
       fixup_symbol_section (sfn, 0);
-      if (section_is_overlay (SYMBOL_OBJ_SECTION (sfn)) &&
-	  !section_is_mapped (SYMBOL_OBJ_SECTION (sfn)))
+      if (section_is_overlay (SYMBOL_OBJ_SECTION (SYMBOL_OBJFILE (sfn), sfn)) &&
+	  !section_is_mapped (SYMBOL_OBJ_SECTION (SYMBOL_OBJFILE (sfn), sfn)))
 	{
 	  if (!query (_("WARNING!!!  Destination is in "
 			"unmapped overlay!  Jump anyway? ")))
diff --git a/gdb/linespec.c b/gdb/linespec.c
index 2e98db7..7df1195 100644
--- a/gdb/linespec.c
+++ b/gdb/linespec.c
@@ -3273,7 +3273,7 @@ minsym_found (struct linespec_state *self, struct objfile *objfile,
 
   sal = find_pc_sect_line (SYMBOL_VALUE_ADDRESS (msymbol),
 			   (struct obj_section *) 0, 0);
-  sal.section = SYMBOL_OBJ_SECTION (msymbol);
+  sal.section = SYMBOL_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 da34a7d..bf8521d 100644
--- a/gdb/maint.c
+++ b/gdb/maint.c
@@ -486,7 +486,7 @@ maintenance_translate_address (char *arg, int from_tty)
       const char *symbol_offset
 	= pulongest (address - SYMBOL_VALUE_ADDRESS (sym.minsym));
 
-      sect = SYMBOL_OBJ_SECTION(sym.minsym);
+      sect = SYMBOL_OBJ_SECTION(sym.objfile, sym.minsym);
       if (sect != NULL)
 	{
 	  const char *section_name;
diff --git a/gdb/minsyms.c b/gdb/minsyms.c
index 3d16a97..5319d33 100644
--- a/gdb/minsyms.c
+++ b/gdb/minsyms.c
@@ -593,9 +593,10 @@ 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.  */
-		      && SYMBOL_OBJ_SECTION (&msymbol[hi]) != NULL
+		      && SYMBOL_OBJ_SECTION (objfile, &msymbol[hi]) != NULL
 		      && (!matching_obj_sections
-			  (SYMBOL_OBJ_SECTION (&msymbol[hi]), section)))
+			  (SYMBOL_OBJ_SECTION (objfile, &msymbol[hi]),
+			   section)))
 		    {
 		      hi--;
 		      continue;
@@ -612,8 +613,8 @@ lookup_minimal_symbol_by_pc_section_1 (CORE_ADDR pc,
 			  == MSYMBOL_SIZE (&msymbol[hi - 1]))
 		      && (SYMBOL_VALUE_ADDRESS (&msymbol[hi])
 			  == SYMBOL_VALUE_ADDRESS (&msymbol[hi - 1]))
-		      && (SYMBOL_OBJ_SECTION (&msymbol[hi])
-			  == SYMBOL_OBJ_SECTION (&msymbol[hi - 1])))
+		      && (SYMBOL_OBJ_SECTION (objfile, &msymbol[hi])
+			  == SYMBOL_OBJ_SECTION (objfile, &msymbol[hi - 1])))
 		    {
 		      hi--;
 		      continue;
@@ -942,7 +943,6 @@ prim_record_minimal_symbol_full (const char *name, int name_len, int copy_name,
 
   SYMBOL_VALUE_ADDRESS (msymbol) = address;
   SYMBOL_SECTION (msymbol) = section;
-  SYMBOL_OBJ_SECTION (msymbol) = NULL;
 
   MSYMBOL_TYPE (msymbol) = ms_type;
   MSYMBOL_TARGET_FLAG_1 (msymbol) = 0;
diff --git a/gdb/parse.c b/gdb/parse.c
index 42817ca..e2f68c6 100644
--- a/gdb/parse.c
+++ b/gdb/parse.c
@@ -499,7 +499,7 @@ write_exp_msymbol (struct minimal_symbol *msymbol)
   struct gdbarch *gdbarch = get_objfile_arch (objfile);
 
   CORE_ADDR addr = SYMBOL_VALUE_ADDRESS (msymbol);
-  struct obj_section *section = SYMBOL_OBJ_SECTION (msymbol);
+  struct obj_section *section = SYMBOL_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 a246153..0cdeba4 100644
--- a/gdb/printcmd.c
+++ b/gdb/printcmd.c
@@ -1209,7 +1209,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 = SYMBOL_VALUE_ADDRESS (msymbol);
 
 	  printf_filtered ("Symbol \"");
@@ -1218,7 +1220,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 = SYMBOL_OBJ_SECTION (msymbol);
+	  section = SYMBOL_OBJ_SECTION (objfile, msymbol);
 	  if (section_is_overlay (section))
 	    {
 	      load_addr = overlay_unmapped_address (load_addr, section);
@@ -1239,7 +1241,7 @@ address_info (char *exp, int from_tty)
 			   current_language->la_language, DMGL_ANSI);
   printf_filtered ("\" is ");
   val = SYMBOL_VALUE (sym);
-  section = SYMBOL_OBJ_SECTION (sym);
+  section = SYMBOL_OBJ_SECTION (SYMBOL_OBJFILE (sym), sym);
   gdbarch = get_objfile_arch (SYMBOL_SYMTAB (sym)->objfile);
 
   switch (SYMBOL_CLASS (sym))
@@ -1343,15 +1345,15 @@ address_info (char *exp, int from_tty)
 
     case LOC_UNRESOLVED:
       {
-	struct minimal_symbol *msym;
+	struct bound_minimal_symbol msym;
 
-	msym = lookup_minimal_symbol (SYMBOL_LINKAGE_NAME (sym), NULL, NULL);
-	if (msym == NULL)
+	msym = lookup_minimal_symbol_and_objfile (SYMBOL_LINKAGE_NAME (sym));
+	if (msym.minsym == NULL)
 	  printf_filtered ("unresolved");
 	else
 	  {
-	    section = SYMBOL_OBJ_SECTION (msym);
-	    load_addr = SYMBOL_VALUE_ADDRESS (msym);
+	    section = SYMBOL_OBJ_SECTION (msym.objfile, msym.minsym);
+	    load_addr = SYMBOL_VALUE_ADDRESS (msym.minsym);
 
 	    if (section
 		&& (section->the_bfd_section->flags & SEC_THREAD_LOCAL) != 0)
diff --git a/gdb/psymtab.c b/gdb/psymtab.c
index e727048..767a516 100644
--- a/gdb/psymtab.c
+++ b/gdb/psymtab.c
@@ -426,7 +426,8 @@ find_pc_sect_psymbol (struct objfile *objfile,
 	  if (section)		/* Match on a specific section.  */
 	    {
 	      fixup_psymbol_section (p, objfile);
-	      if (!matching_obj_sections (SYMBOL_OBJ_SECTION (p), section))
+	      if (!matching_obj_sections (SYMBOL_OBJ_SECTION (objfile, p),
+					  section))
 		continue;
 	    }
 	  best_pc = SYMBOL_VALUE_ADDRESS (p);
@@ -450,7 +451,8 @@ find_pc_sect_psymbol (struct objfile *objfile,
 	  if (section)		/* Match on a specific section.  */
 	    {
 	      fixup_psymbol_section (p, objfile);
-	      if (!matching_obj_sections (SYMBOL_OBJ_SECTION (p), section))
+	      if (!matching_obj_sections (SYMBOL_OBJ_SECTION (objfile, p),
+					  section))
 		continue;
 	    }
 	  best_pc = SYMBOL_VALUE_ADDRESS (p);
@@ -466,7 +468,10 @@ fixup_psymbol_section (struct partial_symbol *psym, struct objfile *objfile)
 {
   CORE_ADDR addr;
 
-  if (psym == NULL || SYMBOL_OBJ_SECTION (psym) != NULL)
+  if (!psym)
+    return;
+
+  if (SYMBOL_SECTION (psym) >= 0)
     return;
 
   gdb_assert (objfile);
@@ -1596,8 +1601,7 @@ add_psymbol_to_bcache (const char *name, int namelength, int copy_name,
     {
       SYMBOL_VALUE_ADDRESS (&psymbol) = coreaddr;
     }
-  SYMBOL_SECTION (&psymbol) = 0;
-  SYMBOL_OBJ_SECTION (&psymbol) = NULL;
+  SYMBOL_SECTION (&psymbol) = -1;
   SYMBOL_SET_LANGUAGE (&psymbol, language, &objfile->objfile_obstack);
   PSYMBOL_DOMAIN (&psymbol) = domain;
   PSYMBOL_CLASS (&psymbol) = class;
diff --git a/gdb/spu-tdep.c b/gdb/spu-tdep.c
index 0cf94e9..4365da1 100644
--- a/gdb/spu-tdep.c
+++ b/gdb/spu-tdep.c
@@ -1920,7 +1920,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 = SYMBOL_VALUE_ADDRESS (minsym);
-  symtab = find_pc_sect_symtab (pc, SYMBOL_OBJ_SECTION (minsym));
+  symtab = find_pc_sect_symtab (pc, SYMBOL_OBJ_SECTION (objfile, minsym));
   if (symtab != NULL)
     {
       struct blockvector *bv = BLOCKVECTOR (symtab);
diff --git a/gdb/stabsread.c b/gdb/stabsread.c
index 5f8f643..e6e16cd 100644
--- a/gdb/stabsread.c
+++ b/gdb/stabsread.c
@@ -645,19 +645,6 @@ define_symbol (CORE_ADDR valu, char *string, int desc, int type,
 
   current_symbol = sym = allocate_symbol (objfile);
 
-  switch (type & N_TYPE)
-    {
-    case N_TEXT:
-      SYMBOL_SECTION (sym) = SECT_OFF_TEXT (objfile);
-      break;
-    case N_DATA:
-      SYMBOL_SECTION (sym) = SECT_OFF_DATA (objfile);
-      break;
-    case N_BSS:
-      SYMBOL_SECTION (sym) = SECT_OFF_BSS (objfile);
-      break;
-    }
-
   if (processing_gcc_compilation)
     {
       /* GCC 2.x puts the line number in desc.  SunOS apparently puts in the
diff --git a/gdb/symmisc.c b/gdb/symmisc.c
index 5fa4e4e..4156fc6 100644
--- a/gdb/symmisc.c
+++ b/gdb/symmisc.c
@@ -218,7 +218,7 @@ dump_msymbols (struct objfile *objfile, struct ui_file *outfile)
   index = 0;
   ALL_OBJFILE_MSYMBOLS (objfile, msymbol)
     {
-      struct obj_section *section = SYMBOL_OBJ_SECTION (msymbol);
+      struct obj_section *section = SYMBOL_OBJ_SECTION (objfile, msymbol);
 
       switch (MSYMBOL_TYPE (msymbol))
 	{
@@ -464,7 +464,8 @@ print_symbol (void *args)
   struct symbol *symbol = ((struct print_symbol_args *) args)->symbol;
   int depth = ((struct print_symbol_args *) args)->depth;
   struct ui_file *outfile = ((struct print_symbol_args *) args)->outfile;
-  struct obj_section *section = SYMBOL_OBJ_SECTION (symbol);
+  struct obj_section *section = SYMBOL_OBJ_SECTION (SYMBOL_OBJFILE (symbol),
+						    symbol);
 
   print_spaces (depth, outfile);
   if (SYMBOL_DOMAIN (symbol) == LABEL_DOMAIN)
diff --git a/gdb/symtab.c b/gdb/symtab.c
index 0f1cd68..486e918 100644
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -1014,10 +1014,7 @@ fixup_section (struct general_symbol_info *ginfo,
      point to the actual function code.  */
   msym = lookup_minimal_symbol_by_pc_name (addr, ginfo->name, objfile);
   if (msym)
-    {
-      ginfo->obj_section = SYMBOL_OBJ_SECTION (msym);
-      ginfo->section = SYMBOL_SECTION (msym);
-    }
+    ginfo->section = SYMBOL_SECTION (msym);
   else
     {
       /* Static, function-local variables do appear in the linker
@@ -1057,20 +1054,31 @@ fixup_section (struct general_symbol_info *ginfo,
 	 a search of the section table.  */
 
       struct obj_section *s;
+      int fallback = -1;
 
       ALL_OBJFILE_OSECTIONS (objfile, s)
 	{
 	  int idx = s - objfile->sections;
 	  CORE_ADDR offset = ANOFFSET (objfile->section_offsets, idx);
 
+	  if (fallback == -1)
+	    fallback = idx;
+
 	  if (obj_section_addr (s) - offset <= addr
 	      && addr < obj_section_endaddr (s) - offset)
 	    {
-	      ginfo->obj_section = s;
 	      ginfo->section = idx;
 	      return;
 	    }
 	}
+
+      /* If we didn't find the section, assume it is in the first
+	 section.  If there is no allocated section, then it hardly
+	 matters what we pick, so just pick zero.  */
+      if (fallback == -1)
+	ginfo->section = 0;
+      else
+	ginfo->section = fallback;
     }
 }
 
@@ -1082,9 +1090,6 @@ fixup_symbol_section (struct symbol *sym, struct objfile *objfile)
   if (!sym)
     return NULL;
 
-  if (SYMBOL_OBJ_SECTION (sym))
-    return sym;
-
   /* We either have an OBJFILE, or we can get at it from the sym's
      symtab.  Anything else is a bug.  */
   gdb_assert (objfile || SYMBOL_SYMTAB (sym));
@@ -1092,6 +1097,9 @@ fixup_symbol_section (struct symbol *sym, struct objfile *objfile)
   if (objfile == NULL)
     objfile = SYMBOL_SYMTAB (sym)->objfile;
 
+  if (SYMBOL_OBJ_SECTION (objfile, sym))
+    return sym;
+
   /* We should have an objfile by now.  */
   gdb_assert (objfile);
 
@@ -2160,7 +2168,8 @@ find_pc_sect_symtab (CORE_ADDR pc, struct obj_section *section)
 	    ALL_BLOCK_SYMBOLS (b, iter, sym)
 	      {
 		fixup_symbol_section (sym, objfile);
-		if (matching_obj_sections (SYMBOL_OBJ_SECTION (sym), section))
+		if (matching_obj_sections (SYMBOL_OBJ_SECTION (objfile, sym),
+					   section))
 		  break;
 	      }
 	    if (sym == NULL)
@@ -2792,7 +2801,7 @@ find_function_start_sal (struct symbol *sym, int funfirstline)
 
   fixup_symbol_section (sym, NULL);
   sal = find_pc_sect_line (BLOCK_START (SYMBOL_BLOCK_VALUE (sym)),
-			   SYMBOL_OBJ_SECTION (sym), 0);
+			   SYMBOL_OBJ_SECTION (SYMBOL_OBJFILE (sym), sym), 0);
 
   /* We always should have a line for the function start address.
      If we don't, something is odd.  Create a plain SAL refering
@@ -2803,7 +2812,7 @@ find_function_start_sal (struct symbol *sym, int funfirstline)
       init_sal (&sal);
       sal.pspace = current_program_space;
       sal.pc = BLOCK_START (SYMBOL_BLOCK_VALUE (sym));
-      sal.section = SYMBOL_OBJ_SECTION (sym);
+      sal.section = SYMBOL_OBJ_SECTION (SYMBOL_OBJFILE (sym), sym);
     }
 
   if (funfirstline)
@@ -2844,7 +2853,7 @@ skip_prologue_sal (struct symtab_and_line *sal)
       fixup_symbol_section (sym, NULL);
 
       pc = BLOCK_START (SYMBOL_BLOCK_VALUE (sym));
-      section = SYMBOL_OBJ_SECTION (sym);
+      section = SYMBOL_OBJ_SECTION (SYMBOL_OBJFILE (sym), sym);
       name = SYMBOL_LINKAGE_NAME (sym);
       objfile = SYMBOL_SYMTAB (sym)->objfile;
     }
@@ -2859,10 +2868,10 @@ skip_prologue_sal (struct symtab_and_line *sal)
 	  return;
 	}
 
+      objfile = msymbol_objfile (msymbol);
       pc = SYMBOL_VALUE_ADDRESS (msymbol);
-      section = SYMBOL_OBJ_SECTION (msymbol);
+      section = SYMBOL_OBJ_SECTION (objfile, msymbol);
       name = SYMBOL_LINKAGE_NAME (msymbol);
-      objfile = msymbol_objfile (msymbol);
     }
 
   gdbarch = get_objfile_arch (objfile);
@@ -5068,6 +5077,7 @@ allocate_symbol (struct objfile *objfile)
   struct symbol *result;
 
   result = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct symbol);
+  SYMBOL_SECTION (result) = -1;
 
   return result;
 }
@@ -5078,6 +5088,7 @@ void
 initialize_symbol (struct symbol *sym)
 {
   memset (sym, 0, sizeof (*sym));
+  SYMBOL_SECTION (sym) = -1;
 }
 
 /* Allocate and initialize a new 'struct template_symbol' on OBJFILE's
@@ -5089,6 +5100,7 @@ allocate_template_symbol (struct objfile *objfile)
   struct template_symbol *result;
 
   result = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct template_symbol);
+  SYMBOL_SECTION (&result->base) = -1;
 
   return result;
 }
diff --git a/gdb/symtab.h b/gdb/symtab.h
index e941a1a..f4928f3 100644
--- a/gdb/symtab.h
+++ b/gdb/symtab.h
@@ -165,16 +165,9 @@ struct general_symbol_info
 
   /* Which section is this symbol in?  This is an index into
      section_offsets for this objfile.  Negative means that the symbol
-     does not get relocated relative to a section.
-     Disclaimer: currently this is just used for xcoff, so don't
-     expect all symbol-reading code to set it correctly (the ELF code
-     also tries to set it correctly).  */
+     does not get relocated relative to a section.  */
 
   short section;
-
-  /* The section associated with this symbol.  It can be NULL.  */
-
-  struct obj_section *obj_section;
 };
 
 extern void symbol_set_demangled_name (struct general_symbol_info *,
@@ -202,7 +195,10 @@ extern CORE_ADDR symbol_overlayed_address (CORE_ADDR, struct obj_section *);
 #define SYMBOL_VALUE_CHAIN(symbol)	(symbol)->ginfo.value.chain
 #define SYMBOL_LANGUAGE(symbol)		(symbol)->ginfo.language
 #define SYMBOL_SECTION(symbol)		(symbol)->ginfo.section
-#define SYMBOL_OBJ_SECTION(symbol)	(symbol)->ginfo.obj_section
+#define SYMBOL_OBJ_SECTION(objfile, symbol)			\
+  (((symbol)->ginfo.section >= 0)				\
+   ? (&(((objfile)->sections)[(symbol)->ginfo.section]))	\
+   : NULL)
 
 /* Initializes the language dependent portion of a symbol
    depending upon the language for the symbol.  */
@@ -700,6 +696,8 @@ struct symbol
 #define SYMBOL_REGISTER_OPS(symbol)     (symbol)->ops.ops_register
 #define SYMBOL_LOCATION_BATON(symbol)   (symbol)->aux_value
 
+#define SYMBOL_OBJFILE(symbol) 		(SYMBOL_SYMTAB (symbol)->objfile)
+
 /* An instance of this type is used to represent a C++ template
    function.  It includes a "struct symbol" as a kind of base class;
    users downcast to "struct template_symbol *" when needed.  A symbol
-- 
1.7.7.6


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