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]

[RFC 2/7] change how psymtab section offsets are handled


Currently, a partial symbol table includes a section_offsets field.
This either comes verbatim from the objfile, or, in one case, is
computed separately.

This approach will not work if partial symtabs are to be independent
of the program space.

So, this patch changes the semantics of this field so that the partial
symtab holds offsets to be applied in addition to the objfile's
offsets.  It also arranges for the "normal" case to be that the
psymtab's section_offsets field is NULL.

2014-02-20  Tom Tromey  <tromey@redhat.com>

	* dbxread.c (start_psymtab): Update.
	(read_ofile_symtab): Remove comment.
	(cp_set_block_scope): Update comment.
	(process_one_symbol): Use PST_OFFSET.
	* dwarf2read.c (create_partial_symtab): Update.
	* elfread.c (elfstab_offset_sections): Compute new offset relative
	to the objfile's offset.
	* mdebugread.c (parse_symbol): Use PST_OFFSET.
	(parse_partial_symbols): Update.  Use PST_OFFSET.
	(new_psymtab): Don't initialize section_offsets field.
	* psympriv.h (struct partial_symtab) <section_offsets>: Update
	comment.
	(PST_OFFSET): New macro.
	(start_psymtab_common): Remove section_offsets argument.
	* psymtab.c (dump_psymtab): Use PST_OFFSET.
	(start_psymtab_common): Remove section_offsets argument.
	* xcoffread.c (xcoff_start_psymtab): Update.
---
 gdb/ChangeLog    | 20 ++++++++++++++++++++
 gdb/dbxread.c    | 37 +++++++++++++++++--------------------
 gdb/dwarf2read.c |  3 +--
 gdb/elfread.c    |  3 ++-
 gdb/mdebugread.c | 20 +++++++++++---------
 gdb/psympriv.h   | 16 ++++++++++++----
 gdb/psymtab.c    |  6 +++---
 gdb/xcoffread.c  |  2 +-
 8 files changed, 67 insertions(+), 40 deletions(-)

diff --git a/gdb/dbxread.c b/gdb/dbxread.c
index ceb593a..216c86c 100644
--- a/gdb/dbxread.c
+++ b/gdb/dbxread.c
@@ -2178,8 +2178,7 @@ start_psymtab (struct objfile *objfile, char *filename, CORE_ADDR textlow,
 	       struct partial_symbol **static_syms)
 {
   struct partial_symtab *result =
-    start_psymtab_common (objfile, objfile->section_offsets,
-			  filename, textlow, global_syms, static_syms);
+    start_psymtab_common (objfile, filename, textlow, global_syms, static_syms);
 
   result->read_symtab_private = obstack_alloc (&objfile->objfile_obstack,
 					       sizeof (struct symloc));
@@ -2501,10 +2500,6 @@ read_ofile_symtab (struct objfile *objfile, struct partial_symtab *pst)
   sym_size = LDSYMLEN (pst);
   text_offset = pst->textlow;
   text_size = pst->texthigh - pst->textlow;
-  /* This cannot be simply objfile->section_offsets because of
-     elfstab_offset_sections() which initializes the psymtab section
-     offsets information in a special way, and that is different from
-     objfile->section_offsets.  */ 
   section_offsets = pst->section_offsets;
 
   dbxread_objfile = objfile;
@@ -2689,8 +2684,9 @@ cp_set_block_scope (const struct symbol *symbol,
    SECTION_OFFSETS is a set of amounts by which the sections of this
    object file were relocated when it was loaded into memory.  Note
    that these section_offsets are not the objfile->section_offsets but
-   the pst->section_offsets.  All symbols that refer to memory
-   locations need to be offset by these amounts.
+   the pst->section_offsets, used in addition to the objfile's
+   offsets.  All symbols that refer to memory locations need to be
+   offset by these amounts.
    OBJFILE is the object file from which we are reading symbols.  It
    is used in end_symtab.  */
 
@@ -2732,7 +2728,7 @@ process_one_symbol (int type, int desc, CORE_ADDR valu, char *name,
       /* N_LBRAC, N_RBRAC and N_SLINE entries are not relative to the
 	 function start address, so just use the text offset.  */
       function_start_offset =
-	ANOFFSET (section_offsets, SECT_OFF_TEXT (objfile));
+	PST_OFFSET (objfile, section_offsets, SECT_OFF_TEXT (objfile));
     }
 
   /* Something is wrong if we see real data before seeing a source
@@ -2799,7 +2795,7 @@ process_one_symbol (int type, int desc, CORE_ADDR valu, char *name,
       sline_found_in_function = 0;
 
       /* Relocate for dynamic loading.  */
-      valu += ANOFFSET (section_offsets, SECT_OFF_TEXT (objfile));
+      valu += PST_OFFSET (objfile, section_offsets, SECT_OFF_TEXT (objfile));
       valu = gdbarch_addr_bits_remove (gdbarch, valu);
       last_function_start = valu;
 
@@ -2901,7 +2897,7 @@ process_one_symbol (int type, int desc, CORE_ADDR valu, char *name,
     case N_FN_SEQ:
       /* This kind of symbol indicates the start of an object file.
          Relocate for dynamic loading.  */
-      valu += ANOFFSET (section_offsets, SECT_OFF_TEXT (objfile));
+      valu += PST_OFFSET (objfile, section_offsets, SECT_OFF_TEXT (objfile));
       break;
 
     case N_SO:
@@ -2909,7 +2905,7 @@ process_one_symbol (int type, int desc, CORE_ADDR valu, char *name,
          source file.  Finish the symbol table of the previous source
          file (if any) and start accumulating a new symbol table.
          Relocate for dynamic loading.  */
-      valu += ANOFFSET (section_offsets, SECT_OFF_TEXT (objfile));
+      valu += PST_OFFSET (objfile, section_offsets, SECT_OFF_TEXT (objfile));
 
       n_opt_found = 0;
 
@@ -2946,7 +2942,7 @@ process_one_symbol (int type, int desc, CORE_ADDR valu, char *name,
          sub-source-file, one whose contents were copied or included
          in the compilation of the main source file (whose name was
          given in the N_SO symbol).  Relocate for dynamic loading.  */
-      valu += ANOFFSET (section_offsets, SECT_OFF_TEXT (objfile));
+      valu += PST_OFFSET (objfile, section_offsets, SECT_OFF_TEXT (objfile));
       start_subfile (name, current_subfile->dirname);
       break;
 
@@ -3051,7 +3047,8 @@ process_one_symbol (int type, int desc, CORE_ADDR valu, char *name,
 		   elfstab_offset_sections ever starts dealing with
 		   the text offset, and we still need to do this, we
 		   need to invent a SECT_OFF_ADDR_KLUDGE or something.  */
-		valu += ANOFFSET (section_offsets, SECT_OFF_TEXT (objfile));
+		valu += PST_OFFSET (objfile, section_offsets,
+				     SECT_OFF_TEXT (objfile));
 		goto define_a_symbol;
 	      }
 	  }
@@ -3073,22 +3070,22 @@ process_one_symbol (int type, int desc, CORE_ADDR valu, char *name,
 
     case_N_STSYM:		/* Static symbol in data segment.  */
     case N_DSLINE:		/* Source line number, data segment.  */
-      valu += ANOFFSET (section_offsets, SECT_OFF_DATA (objfile));
+      valu += PST_OFFSET (objfile, section_offsets, SECT_OFF_DATA (objfile));
       goto define_a_symbol;
 
     case_N_LCSYM:		/* Static symbol in BSS segment.  */
     case N_BSLINE:		/* Source line number, BSS segment.  */
       /* N_BROWS: overlaps with N_BSLINE.  */
-      valu += ANOFFSET (section_offsets, SECT_OFF_BSS (objfile));
+      valu += PST_OFFSET (objfile, section_offsets, SECT_OFF_BSS (objfile));
       goto define_a_symbol;
 
     case_N_ROSYM:		/* Static symbol in read-only data segment.  */
-      valu += ANOFFSET (section_offsets, SECT_OFF_RODATA (objfile));
+      valu += PST_OFFSET (objfile, section_offsets, SECT_OFF_RODATA (objfile));
       goto define_a_symbol;
 
     case N_ENTRY:		/* Alternate entry point.  */
       /* Relocate for dynamic loading.  */
-      valu += ANOFFSET (section_offsets, SECT_OFF_TEXT (objfile));
+      valu += PST_OFFSET (objfile, section_offsets, SECT_OFF_TEXT (objfile));
       goto define_a_symbol;
 
       /* The following symbol types we don't know how to process.
@@ -3141,8 +3138,8 @@ process_one_symbol (int type, int desc, CORE_ADDR valu, char *name,
 	      /* Deal with the SunPRO 3.0 compiler which omits the
 	         address from N_FUN symbols.  */
 	      if (type == N_FUN
-		  && valu == ANOFFSET (section_offsets,
-				       SECT_OFF_TEXT (objfile))
+		  && valu == PST_OFFSET (objfile, section_offsets,
+					  SECT_OFF_TEXT (objfile))
 		  && gdbarch_sofun_address_maybe_missing (gdbarch))
 		{
 		  CORE_ADDR minsym_valu = 
diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
index 87c6ba2..72662a5 100644
--- a/gdb/dwarf2read.c
+++ b/gdb/dwarf2read.c
@@ -5925,8 +5925,7 @@ create_partial_symtab (struct dwarf2_per_cu_data *per_cu, const char *name)
   struct objfile *objfile = per_cu->objfile;
   struct partial_symtab *pst;
 
-  pst = start_psymtab_common (objfile, objfile->section_offsets,
-			      name, 0,
+  pst = start_psymtab_common (objfile, name, 0,
 			      objfile->global_psymbols.next,
 			      objfile->static_psymbols.next);
 
diff --git a/gdb/elfread.c b/gdb/elfread.c
index 88fb018..d25b09a 100644
--- a/gdb/elfread.c
+++ b/gdb/elfread.c
@@ -1481,7 +1481,8 @@ elfstab_offset_sections (struct objfile *objfile, struct partial_symtab *pst)
 	obstack_alloc (&objfile->objfile_obstack,
 		       SIZEOF_N_SECTION_OFFSETS (objfile->num_sections));
       for (i = 0; i < maybe->num_sections; i++)
-	(pst->section_offsets)->offsets[i] = maybe->sections[i];
+	(pst->section_offsets)->offsets[i]
+	  = maybe->sections[i] - ANOFFSET (objfile->section_offsets, i);
       return;
     }
 
diff --git a/gdb/mdebugread.c b/gdb/mdebugread.c
index 94af07b..ce180c4 100644
--- a/gdb/mdebugread.c
+++ b/gdb/mdebugread.c
@@ -581,18 +581,21 @@ parse_symbol (SYMR *sh, union aux_ext *ax, char *ext_sh, int bigend,
          The value of a stBlock symbol is the displacement from the
          procedure address.  */
       if (sh->st != stEnd && sh->st != stBlock)
-	sh->value += ANOFFSET (section_offsets, SECT_OFF_TEXT (objfile));
+	sh->value += PST_OFFSET (objfile, section_offsets,
+				   SECT_OFF_TEXT (objfile));
       break;
     case scData:
     case scSData:
     case scRData:
     case scPData:
     case scXData:
-      sh->value += ANOFFSET (section_offsets, SECT_OFF_DATA (objfile));
+      sh->value += PST_OFFSET (objfile, section_offsets,
+			       SECT_OFF_DATA (objfile));
       break;
     case scBss:
     case scSBss:
-      sh->value += ANOFFSET (section_offsets, SECT_OFF_BSS (objfile));
+      sh->value += PST_OFFSET (objfile, section_offsets,
+			       SECT_OFF_BSS (objfile));
       break;
     }
 
@@ -2647,7 +2650,7 @@ parse_partial_symbols (struct objfile *objfile)
 	}
       else
 	textlow = 0;
-      pst = start_psymtab_common (objfile, objfile->section_offsets,
+      pst = start_psymtab_common (objfile,
 				  fdr_name (fh),
 				  textlow,
 				  objfile->global_psymbols.next,
@@ -4052,8 +4055,8 @@ psymtab_to_symtab_1 (struct objfile *objfile,
 		      && previous_stab_code != (unsigned char) N_SO
 		      && *name == '\000')
 		    {
-		      valu += ANOFFSET (pst->section_offsets,
-					SECT_OFF_TEXT (objfile));
+		      valu += PST_OFFSET (objfile, pst->section_offsets,
+					  SECT_OFF_TEXT (objfile));
 		      previous_stab_code = N_SO;
 		      st = end_symtab (valu, objfile,
 				       SECT_OFF_TEXT (objfile));
@@ -4103,8 +4106,8 @@ psymtab_to_symtab_1 (struct objfile *objfile,
 	      else
 		{
 		  /* Handle encoded stab line number.  */
-		  valu += ANOFFSET (pst->section_offsets,
-				    SECT_OFF_TEXT (objfile));
+		  valu += PST_OFFSET (objfile, pst->section_offsets,
+				      SECT_OFF_TEXT (objfile));
 		  record_line (current_subfile, sh.index,
 			       gdbarch_addr_bits_remove (gdbarch, valu));
 		}
@@ -4753,7 +4756,6 @@ new_psymtab (char *name, struct objfile *objfile)
   struct partial_symtab *psymtab;
 
   psymtab = allocate_psymtab (name, objfile);
-  psymtab->section_offsets = objfile->section_offsets;
 
   /* Keep a backpointer to the file's symbols.  */
 
diff --git a/gdb/psympriv.h b/gdb/psympriv.h
index 006e134..57442c2 100644
--- a/gdb/psympriv.h
+++ b/gdb/psympriv.h
@@ -98,9 +98,11 @@ struct partial_symtab
 
   const char *dirname;
 
-  /* Set of relocation offsets to apply to each section.
-     This is typically objfile->section_offsets, but in some cases
-     it's different.  See, e.g., elfstab_offset_sections.  */
+  /* Set of relocation offsets to apply to each section.  Offsets here
+     are applied when expanding this psymtab to a full symtab.  This
+     is typically NULL, which means no additional offsets need to be
+     applied, but in some cases it's different.  See, e.g.,
+     elfstab_offset_sections.  */
 
   struct section_offsets *section_offsets;
 
@@ -210,6 +212,13 @@ struct partial_symtab
   void *read_symtab_private;
 };
 
+/* Compute a section offset given an objfile, a section_offsets field
+   from a partial symtab, and an index.  */
+
+#define PST_OFFSET(OBJF, OFFS, INDEX)				\
+  (ANOFFSET ((OBJF)->section_offsets, (INDEX))			\
+   + ((((OFFS) == NULL)) ? 0 : ANOFFSET ((OFFS), (INDEX))))
+
 extern void sort_pst_symbols (struct objfile *, struct partial_symtab *);
 
 /* Add any kind of symbol to a psymbol_allocation_list.  */
@@ -224,7 +233,6 @@ extern void add_psymbol_to_list (const char *, int,
 extern void init_psymbol_list (struct objfile *, int);
 
 extern struct partial_symtab *start_psymtab_common (struct objfile *,
-						    struct section_offsets *,
 						    const char *, CORE_ADDR,
 						    struct partial_symbol **,
 						    struct partial_symbol **);
diff --git a/gdb/psymtab.c b/gdb/psymtab.c
index 2787f4c..24faef9 100644
--- a/gdb/psymtab.c
+++ b/gdb/psymtab.c
@@ -995,7 +995,9 @@ dump_psymtab (struct objfile *objfile, struct partial_symtab *psymtab,
 	fprintf_filtered (outfile, ", ");
       wrap_here ("    ");
       fputs_filtered (paddress (gdbarch,
-				ANOFFSET (psymtab->section_offsets, i)),
+				PST_OFFSET (objfile,
+					    psymtab->section_offsets,
+					    i)),
 		      outfile);
     }
   fprintf_filtered (outfile, "\n");
@@ -1468,7 +1470,6 @@ sort_pst_symbols (struct objfile *objfile, struct partial_symtab *pst)
 
 struct partial_symtab *
 start_psymtab_common (struct objfile *objfile,
-		      struct section_offsets *section_offsets,
 		      const char *filename,
 		      CORE_ADDR textlow, struct partial_symbol **global_syms,
 		      struct partial_symbol **static_syms)
@@ -1476,7 +1477,6 @@ start_psymtab_common (struct objfile *objfile,
   struct partial_symtab *psymtab;
 
   psymtab = allocate_psymtab (filename, objfile);
-  psymtab->section_offsets = section_offsets;
   psymtab->textlow = textlow;
   psymtab->texthigh = psymtab->textlow;		/* default */
   psymtab->globals_offset = global_syms - objfile->global_psymbols.list;
diff --git a/gdb/xcoffread.c b/gdb/xcoffread.c
index b986dbd..261fc7b 100644
--- a/gdb/xcoffread.c
+++ b/gdb/xcoffread.c
@@ -2028,7 +2028,7 @@ xcoff_start_psymtab (struct objfile *objfile,
 		     struct partial_symbol **static_syms)
 {
   struct partial_symtab *result =
-    start_psymtab_common (objfile, objfile->section_offsets,
+    start_psymtab_common (objfile,
 			  filename,
 			  /* We fill in textlow later.  */
 			  0,
-- 
1.8.1.4


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