This is the mail archive of the gdb-patches@sources.redhat.com 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]

[commit] Add target_section_by_addr(), use


Hello,

This moves the lookup section by addr code, found in do_xfer_memory, to a separate function.

Committed,
Andrew

PS: Perhaphs "struct section_table" should be renamed to the more specific "struct target_section"?
2003-10-17  Andrew Cagney  <cagney@redhat.com>

	* target.c (target_section_by_addr): New function.
	(do_xfer_memory): Use "target_section_by_addr".
	* target.h (target_section_by_addr): Declare.

Index: target.c
===================================================================
RCS file: /cvs/src/src/gdb/target.c,v
retrieving revision 1.57
diff -u -r1.57 target.c
--- target.c	17 Oct 2003 16:09:20 -0000	1.57
+++ target.c	17 Oct 2003 20:00:33 -0000
@@ -815,6 +815,21 @@
   return nbytes_read;
 }
 
+/* Find a section containing ADDR.  */
+struct section_table *
+target_section_by_addr (struct target_ops *target, CORE_ADDR addr)
+{
+  struct section_table *secp;
+  for (secp = target->to_sections;
+       secp < target->to_sections_end;
+       secp++)
+    {
+      if (addr >= secp->addr && addr < secp->endaddr)
+	return secp;
+    }
+  return NULL;
+}
+
 /* Read LEN bytes of target memory at address MEMADDR, placing the results in
    GDB's memory at MYADDR.  Returns either 0 for success or an errno value
    if any error occurs.
@@ -862,22 +877,15 @@
 
   if (!write && trust_readonly)
     {
+      struct section_table *secp;
       /* User-settable option, "trust-readonly-sections".  If true,
          then memory from any SEC_READONLY bfd section may be read
-         directly from the bfd file. */
-
-      struct section_table *secp;
-
-      for (secp = current_target.to_sections;
-	   secp < current_target.to_sections_end;
-	   secp++)
-	{
-	  if (bfd_get_section_flags (secp->bfd, secp->the_bfd_section) 
-	      & SEC_READONLY)
-	    if (memaddr >= secp->addr && memaddr < secp->endaddr)
-	      return xfer_memory (memaddr, myaddr, len, 0, 
-				  attrib, &current_target);
-	}
+         directly from the bfd file.  */
+      secp = target_section_by_addr (&current_target, memaddr);
+      if (secp != NULL
+	  && (bfd_get_section_flags (secp->bfd, secp->the_bfd_section)
+	      & SEC_READONLY))
+	return xfer_memory (memaddr, myaddr, len, 0, attrib, &current_target);
     }
 
   /* The quick case is that the top target can handle the transfer.  */
Index: target.h
===================================================================
RCS file: /cvs/src/src/gdb/target.h,v
retrieving revision 1.43
diff -u -r1.43 target.h
--- target.h	17 Oct 2003 13:59:27 -0000	1.43
+++ target.h	17 Oct 2003 20:00:50 -0000
@@ -1076,6 +1076,11 @@
     bfd *bfd;			/* BFD file pointer */
   };
 
+/* Return the "section" containing the specified address.  */
+struct section_table *target_section_by_addr (struct target_ops *target,
+					      CORE_ADDR addr);
+
+
 /* Builds a section table, given args BFD, SECTABLE_PTR, SECEND_PTR.
    Returns 0 if OK, 1 on error.  */
 

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