This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[PATCH 5/8] Share code on to_xfer_partial for tfile and ctf target
- From: Yao Qi <yao at codesourcery dot com>
- To: <gdb-patches at sourceware dot org>
- Date: Wed, 12 Feb 2014 14:05:49 +0800
- Subject: [PATCH 5/8] Share code on to_xfer_partial for tfile and ctf target
- Authentication-results: sourceware.org; auth=none
- References: <1392185152-21220-1-git-send-email-yao at codesourcery dot com>
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_only_xfer_partial.
gdb:
2014-02-12 Yao Qi <yao@codesourcery.com>
* ctf.c (ctf_xfer_partial): Move code to ...
* exec.c (exec_read_only_xfer_partial): ... it. New function.
* tracefile-tfile.c (tfile_xfer_partial): Likewise.
* tracefile.c: Include "exec.h".
* exec.h (exec_read_only_xfer_partial): Declare.
---
gdb/ctf.c | 42 +-----------------------------------------
gdb/exec.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++
gdb/exec.h | 9 +++++++++
gdb/tracefile-tfile.c | 36 +-----------------------------------
gdb/tracefile.c | 1 +
5 files changed, 59 insertions(+), 76 deletions(-)
diff --git a/gdb/ctf.c b/gdb/ctf.c
index 8c60545..96ea966 100644
--- 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_only_xfer_partial (readbuf, offset, len, xfered_len);
}
/* This is the implementation of target_ops method
diff --git a/gdb/exec.c b/gdb/exec.c
index 23d6187..bf422a7 100644
--- a/gdb/exec.c
+++ b/gdb/exec.c
@@ -529,6 +529,53 @@ remove_target_sections (void *owner)
+enum target_xfer_status
+exec_read_only_xfer_partial (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,
diff --git a/gdb/exec.h b/gdb/exec.h
index 4725f1b..a0c59c2 100644
--- a/gdb/exec.h
+++ b/gdb/exec.h
@@ -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_only_xfer_partial (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
diff --git a/gdb/tracefile-tfile.c b/gdb/tracefile-tfile.c
index 80df960..dcd46e4 100644
--- a/gdb/tracefile-tfile.c
+++ b/gdb/tracefile-tfile.c
@@ -933,41 +933,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_only_xfer_partial (readbuf, offset, len, xfered_len);
}
/* Iterate through the blocks of a trace frame, looking for a 'V'
diff --git a/gdb/tracefile.c b/gdb/tracefile.c
index a2dc9fd..5e263c5 100644
--- a/gdb/tracefile.c
+++ b/gdb/tracefile.c
@@ -20,6 +20,7 @@
#include "defs.h"
#include "tracefile.h"
#include "ctf.h"
+#include "exec.h"
/* Helper macros. */
--
1.7.7.6