Patchwork [RFA,v3,5/6] Add validity bits for psymtab high and low fields

login
register
mail settings
Submitter Tom Tromey
Date June 7, 2018, 4:19 p.m.
Message ID <20180607161955.9800-6-tom@tromey.com>
Download mbox | patch
Permalink /patch/27693/
State New
Headers show

Comments

Tom Tromey - June 7, 2018, 4:19 p.m.
Right now some psymtab code checks whether a psymtab's textlow or
texthigh fields are valid by comparing against 0.

I imagine this is mildly wrong in the current environment, but once
psymtabs are relocated dynamically, it will no longer be correct,
because it will be much more normal to see a psymtab with a textlow of
zero -- this will just mean it appears at the start of the text
section.

This patch introduces validity bits to handle this situation more
nicely, and changes users of the code to follow.

gdb/ChangeLog
2018-06-07  Tom Tromey  <tromey@redhat.com>

	* dbxread.c (end_psymtab): Use texthigh_valid and textlow_valid.
	* mdebugread.c (parse_partial_symbols): Use textlow_valid.
	(psymtab_to_symtab_1): Use texthigh_valid and textlow_valid.
	* psympriv.h (struct partial_symtab) <m_textlow, m_texthigh>: Update
	comment.
	<textlow_valid, texthigh_valid>: New fields.
	<set_text_low, set_text_high>: Update.
	* xcoffread.c (scan_xcoff_symtab): Use textlow_valid.
---
 gdb/ChangeLog    | 11 +++++++++++
 gdb/dbxread.c    |  6 ++----
 gdb/mdebugread.c |  8 ++++----
 gdb/psympriv.h   | 11 ++++++++++-
 gdb/xcoffread.c  |  2 +-
 5 files changed, 28 insertions(+), 10 deletions(-)

Patch

diff --git a/gdb/dbxread.c b/gdb/dbxread.c
index e011b5cf417..204937a9db8 100644
--- a/gdb/dbxread.c
+++ b/gdb/dbxread.c
@@ -2040,13 +2040,11 @@  dbx_end_psymtab (struct objfile *objfile, struct partial_symtab *pst,
       /* If we know our own starting text address, then walk through all other
          psymtabs for this objfile, and if any didn't know their ending text
          address, set it to our starting address.  Take care to not set our
-         own ending address to our starting address, nor to set addresses on
-         `dependency' files that have both textlow and texthigh zero.  */
+         own ending address to our starting address.  */
 
       ALL_OBJFILE_PSYMTABS (objfile, p1)
       {
-	if (p1->text_high () == 0 && p1->text_low () != 0
-	    && p1 != pst)
+	if (!p1->texthigh_valid && p1->textlow_valid && p1 != pst)
 	  p1->set_text_high (pst->text_low ());
       }
     }
diff --git a/gdb/mdebugread.c b/gdb/mdebugread.c
index 2699cb99b19..3deb8cf2a43 100644
--- a/gdb/mdebugread.c
+++ b/gdb/mdebugread.c
@@ -2737,7 +2737,7 @@  parse_partial_symbols (minimal_symbol_reader &reader,
 
 			  /* Kludge for Irix 5.2 zero fh->adr.  */
 			  if (!relocatable
-			      && (pst->text_low () == 0
+			      && (!pst->textlow_valid
 				  || procaddr < pst->text_low ()))
 			    pst->set_text_low (procaddr);
 			  if (high > pst->text_high ())
@@ -3513,7 +3513,7 @@  parse_partial_symbols (minimal_symbol_reader &reader,
 
 		  /* Kludge for Irix 5.2 zero fh->adr.  */
 		  if (!relocatable
-		      && (pst->text_low () == 0
+		      && (!pst->textlow_valid
 			  || procaddr < pst->text_low ()))
 		    pst->set_text_low (procaddr);
 
@@ -3712,7 +3712,7 @@  parse_partial_symbols (minimal_symbol_reader &reader,
          other cases.  */
       save_pst = fdr_to_pst[f_idx].pst;
       if (save_pst != NULL
-	  && save_pst->text_low () != 0
+	  && save_pst->textlow_valid
 	  && !(objfile->flags & OBJF_REORDERED))
 	{
 	  ALL_OBJFILE_PSYMTABS (objfile, pst)
@@ -3923,7 +3923,7 @@  psymtab_to_symtab_1 (struct objfile *objfile,
   /* Do nothing if this is a dummy psymtab.  */
 
   if (pst->n_global_syms == 0 && pst->n_static_syms == 0
-      && pst->text_low () == 0 && pst->text_high () == 0)
+      && !pst->textlow_valid && !pst->texthigh_valid)
     return;
 
   /* Now read the symbols for this symtab.  */
diff --git a/gdb/psympriv.h b/gdb/psympriv.h
index c1f1defd58c..30e81dbe5bc 100644
--- a/gdb/psympriv.h
+++ b/gdb/psympriv.h
@@ -114,12 +114,14 @@  struct partial_symtab
   void set_text_low (CORE_ADDR addr)
   {
     m_textlow = addr;
+    textlow_valid = 1;
   }
 
   /* Set the hight text address of this partial_symtab.  */
   void set_text_high (CORE_ADDR addr)
   {
     m_texthigh = addr;
+    texthigh_valid = 1;
   }
 
 
@@ -144,7 +146,9 @@  struct partial_symtab
   /* Range of text addresses covered by this file; texthigh is the
      beginning of the next section.  Do not use if PSYMTABS_ADDRMAP_SUPPORTED
      is set.  Do not refer directly to these fields.  Instead, use the
-     accessors.  */
+     accessors.  The validity of these fields is determined by the
+     textlow_valid and texthigh_valid fields; these are located later
+     in this structure for better packing.  */
 
   CORE_ADDR m_textlow;
   CORE_ADDR m_texthigh;
@@ -230,6 +234,11 @@  struct partial_symtab
 
   ENUM_BITFIELD (psymtab_search_status) searched_flag : 2;
 
+  /* Validity of the textlow_ and texthigh_ fields.  */
+
+  unsigned int textlow_valid : 1;
+  unsigned int texthigh_valid : 1;
+
   /* Pointer to compunit eventually allocated for this source file, 0 if
      !readin or if we haven't looked for the symtab after it was readin.  */
 
diff --git a/gdb/xcoffread.c b/gdb/xcoffread.c
index 5e621e608d7..cf402fabe30 100644
--- a/gdb/xcoffread.c
+++ b/gdb/xcoffread.c
@@ -2346,7 +2346,7 @@  scan_xcoff_symtab (minimal_symbol_reader &reader,
 
 			if (highval > pst->text_high ())
 			  pst->set_text_high (highval);
-			if (pst->text_low () == 0
+			if (!pst->textlow_valid
 			    || symbol.n_value < pst->text_low ())
 			  pst->set_text_low (symbol.n_value);
 		      }