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]

ping: Code cleanup: [patch 1/3 ppc64] Make addrs->SECTINDEX always defined


Hi,

planning to check it in as a code cleanup, undefined variable values are a bit
fragile.  But this code is very fragile so more eyes is welcome.


Thanks,
Jan


On Mon, 04 Apr 2011 13:14:12 +0200, Jan Kratochvil wrote:

when you check relative_addr_info_to_section_offsets the `continue' there was
like a dead code - it avoided assigning value 0 to a pre-cleared (memset 0)
array.

As SECTINDEX is used in [patch 3/3] for real sections mapping and not just
sections relocation we need it valid in more cases now.

After addr_info_make_relative commonly ADDR is 0 which makes even previously
valid SECTINDEX invalid now which is no longer acceptable for the new use of
SECTINDices.


gdb/
2011-04-04  Jan Kratochvil  <jan.kratochvil@redhat.com>

	Make addrs->SECTINDEX always defined.
	* symfile.c (relative_addr_info_to_section_offsets): Check for
	SECTINDEX -1, not for zero ADDR.
	(addrs_section_compar): Remove checking for invalid SECTINDEX.
	(addr_info_make_relative): Set SECTINDEX to -1 for unmatched entries.
	* symfile.h (struct section_addr_info) <sectindex>: Update the comment
	on its validity.

--- a/gdb/symfile.c
+++ b/gdb/symfile.c
@@ -527,7 +527,7 @@ relative_addr_info_to_section_offsets (struct section_offsets *section_offsets,
       struct other_sections *osp;
 
       osp = &addrs->other[i];
-      if (osp->addr == 0)
+      if (osp->sectindex == -1)
   	continue;
 
       /* Record all sections in offsets.  */
@@ -568,10 +568,7 @@ addrs_section_compar (const void *ap, const void *bp)
   if (retval)
     return retval;
 
-  /* SECTINDEX is undefined iff ADDR is zero.  */
-  a_idx = a->addr == 0 ? 0 : a->sectindex;
-  b_idx = b->addr == 0 ? 0 : b->sectindex;
-  return a_idx - b_idx;
+  return a->sectindex - b->sectindex;
 }
 
 /* Provide sorted array of pointers to sections of ADDRS.  The array is
@@ -734,8 +731,7 @@ addr_info_make_relative (struct section_addr_info *addrs, bfd *abfd)
 		     bfd_get_filename (abfd));
 
 	  addrs->other[i].addr = 0;
-
-	  /* SECTINDEX is invalid if ADDR is zero.  */
+	  addrs->other[i].sectindex = -1;
 	}
     }
 
--- a/gdb/symfile.h
+++ b/gdb/symfile.h
@@ -86,7 +86,7 @@ struct section_addr_info
     CORE_ADDR addr;
     char *name;
 
-    /* SECTINDEX must be valid for associated BFD if ADDR is not zero.  */
+    /* SECTINDEX must be valid for associated BFD or set to -1.  */
     int sectindex;
   } other[1];
 };


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