Share code on to_xfer_partial for tfile and ctf target
authorYao Qi <yao@codesourcery.com>
Mon, 10 Feb 2014 09:17:32 +0000 (17:17 +0800)
committerYao Qi <yao@codesourcery.com>
Sun, 23 Feb 2014 03:44:27 +0000 (11:44 +0800)
In the to_xfer_partial implementations of ctf and tfile, the code on
reading from read-only sections is duplicated.  This patch moves it to
a separate function exec_read_partial_read_only.

gdb:

2014-02-23  Yao Qi  <yao@codesourcery.com>

* ctf.c (ctf_xfer_partial): Move code to ...
* exec.c (exec_read_partial_read_only): ... it.  New function.
* tracefile-tfile.c (tfile_xfer_partial): Likewise.
* tracefile.c: Include "exec.h".
* exec.h (exec_read_partial_read_only): Declare.

gdb/ChangeLog
gdb/ctf.c
gdb/exec.c
gdb/exec.h
gdb/tracefile-tfile.c
gdb/tracefile.c

index d7c3310..11b70b8 100644 (file)
@@ -1,5 +1,13 @@
 2014-02-23  Yao Qi  <yao@codesourcery.com>
 
+       * ctf.c (ctf_xfer_partial): Move code to ...
+       * exec.c (exec_read_partial_read_only): ... it.  New function.
+       * tracefile-tfile.c (tfile_xfer_partial): Likewise.
+       * tracefile.c: Include "exec.h".
+       * exec.h (exec_read_partial_read_only): Declare.
+
+2014-02-23  Yao Qi  <yao@codesourcery.com>
+
        * tracefile-tfile.c (tfile_has_all_memory): Remove.
        (tfile_has_memory): Remove.
        (init_tfile_ops): Don't set fields to_has_all_memory and
index 6924fb0..9c8f4d7 100644 (file)
--- a/gdb/ctf.c
+++ b/gdb/ctf.c
@@ -1467,47 +1467,7 @@ ctf_xfer_partial (struct target_ops *ops, enum target_object object,
       bt_iter_set_pos (bt_ctf_get_iter (ctf_iter), pos);
     }
 
-  /* It's unduly pedantic to refuse to look at the executable for
-     read-only pieces; so do the equivalent of readonly regions aka
-     QTro packet.  */
-  if (exec_bfd != NULL)
-    {
-      asection *s;
-      bfd_size_type size;
-      bfd_vma vma;
-
-      for (s = exec_bfd->sections; s; s = s->next)
-       {
-         if ((s->flags & SEC_LOAD) == 0
-             || (s->flags & SEC_READONLY) == 0)
-           continue;
-
-         vma = s->vma;
-         size = bfd_get_section_size (s);
-         if (vma <= offset && offset < (vma + size))
-           {
-             ULONGEST amt;
-
-             amt = (vma + size) - offset;
-             if (amt > len)
-               amt = len;
-
-             amt = bfd_get_section_contents (exec_bfd, s,
-                                             readbuf, offset - vma, amt);
-
-             if (amt == 0)
-               return TARGET_XFER_EOF;
-             else
-               {
-                 *xfered_len = amt;
-                 return TARGET_XFER_OK;
-               }
-           }
-       }
-    }
-
-  /* Indicate failure to find the requested memory block.  */
-  return TARGET_XFER_E_IO;
+  return exec_read_partial_read_only (readbuf, offset, len, xfered_len);
 }
 
 /* This is the implementation of target_ops method
index 7f53a50..74c61eb 100644 (file)
@@ -530,6 +530,53 @@ remove_target_sections (void *owner)
 
 \f
 
+enum target_xfer_status
+exec_read_partial_read_only (gdb_byte *readbuf, ULONGEST offset,
+                            ULONGEST len, ULONGEST *xfered_len)
+{
+  /* It's unduly pedantic to refuse to look at the executable for
+     read-only pieces; so do the equivalent of readonly regions aka
+     QTro packet.  */
+  if (exec_bfd != NULL)
+    {
+      asection *s;
+      bfd_size_type size;
+      bfd_vma vma;
+
+      for (s = exec_bfd->sections; s; s = s->next)
+       {
+         if ((s->flags & SEC_LOAD) == 0
+             || (s->flags & SEC_READONLY) == 0)
+           continue;
+
+         vma = s->vma;
+         size = bfd_get_section_size (s);
+         if (vma <= offset && offset < (vma + size))
+           {
+             ULONGEST amt;
+
+             amt = (vma + size) - offset;
+             if (amt > len)
+               amt = len;
+
+             amt = bfd_get_section_contents (exec_bfd, s,
+                                             readbuf, offset - vma, amt);
+
+             if (amt == 0)
+               return TARGET_XFER_EOF;
+             else
+               {
+                 *xfered_len = amt;
+                 return TARGET_XFER_OK;
+               }
+           }
+       }
+    }
+
+  /* Indicate failure to find the requested memory block.  */
+  return TARGET_XFER_E_IO;
+}
+
 VEC(mem_range_s) *
 section_table_available_memory (VEC(mem_range_s) *memory,
                                CORE_ADDR memaddr, ULONGEST len,
index 4725f1b..960c585 100644 (file)
@@ -46,6 +46,15 @@ extern int build_section_table (struct bfd *, struct target_section **,
 
 extern int resize_section_table (struct target_section_table *, int);
 
+/* Read from mappable read-only sections of BFD executable files.
+   Return TARGET_XFER_OK, if read is successful.  Return
+   TARGET_XFER_EOF if read is done.  Return TARGET_XFER_E_IO
+   otherwise.  */
+
+extern enum target_xfer_status
+  exec_read_partial_read_only (gdb_byte *readbuf, ULONGEST offset,
+                              ULONGEST len, ULONGEST *xfered_len);
+
 /* Appends all read-only memory ranges found in the target section
    table defined by SECTIONS and SECTIONS_END, starting at (and
    intersected with) MEMADDR for LEN bytes.  Returns the augmented
index 3ef109e..02122eb 100644 (file)
@@ -938,41 +938,7 @@ tfile_xfer_partial (struct target_ops *ops, enum target_object object,
        }
     }
 
-  /* It's unduly pedantic to refuse to look at the executable for
-     read-only pieces; so do the equivalent of readonly regions aka
-     QTro packet.  */
-  /* FIXME account for relocation at some point.  */
-  if (exec_bfd)
-    {
-      asection *s;
-      bfd_size_type size;
-      bfd_vma vma;
-
-      for (s = exec_bfd->sections; s; s = s->next)
-       {
-         if ((s->flags & SEC_LOAD) == 0
-             || (s->flags & SEC_READONLY) == 0)
-           continue;
-
-         vma = s->vma;
-         size = bfd_get_section_size (s);
-         if (vma <= offset && offset < (vma + size))
-           {
-             ULONGEST amt;
-
-             amt = (vma + size) - offset;
-             if (amt > len)
-               amt = len;
-
-             *xfered_len = bfd_get_section_contents (exec_bfd, s,
-                                                     readbuf, offset - vma, amt);
-             return TARGET_XFER_OK;
-           }
-       }
-    }
-
-  /* Indicate failure to find the requested memory block.  */
-  return TARGET_XFER_E_IO;
+  return exec_read_partial_read_only (readbuf, offset, len, xfered_len);
 }
 
 /* Iterate through the blocks of a trace frame, looking for a 'V'
index 508f898..a7c3cf7 100644 (file)
@@ -20,6 +20,7 @@
 #include "defs.h"
 #include "tracefile.h"
 #include "ctf.h"
+#include "exec.h"
 
 /* Helper macros.  */