[4/4] Partially available/unavailable data in requested range

Message ID 1398665538-16580-5-git-send-email-yao@codesourcery.com
State Committed
Headers

Commit Message

Yao Qi April 28, 2014, 6:12 a.m. UTC
  In gdb.trace/unavailable.exp, an action is defined to collect
struct_b.struct_a.array[2] and struct_b.struct_a.array[100],

struct StructB
{
  int d, ef;
  StructA struct_a;
  int s:1;
  static StructA static_struct_a;
  const char *string;
};

and the other fields are not collected.

When GDB examine traceframe collected by the action, "struct_b" is
unavailable completely, which is wrong.

(gdb) p struct_b
$1 = <unavailable>

When GDB reads 'struct_b', it will request to read memory at struct_b's address
of length LEN.  Since struct_b.d is not collected, no 'M' block
includes the first part of the desired range, so tfile_xfer_partial returns
TARGET_XFER_UNAVAILABLE and GDB thinks the whole requested range is unavailable.

In order to fix this problem, in the iteration to 'M' blocks, we record the
lowest address of blocks within the request range.  If it has, the requested
range isn't unavailable completely.  This applies to ctf too.  With this patch
applied, the result looks good and fails in unavailable.exp is fixed.

(gdb) p struct_b
$1 = {d = <unavailable>, ef = <unavailable>, struct_a = {a = <unavailable>, b = <unavailable>, array = {<unavailable>,
<unavailable>, -1431655766, <unavailable> <repeats 97 times>, -1431655766, <unavailable> <repeats 9899 times>}, ptr = <unavailable>, bitfield = <unavailable>}, s = <unavailable>,   static static_struct_a = {a = <unavailable>, b = <unavailable>, array = {<unavailable> <repeats 10000 times>}, ptr = <unavailable>,
bitfield = <unavailable>}, string = <unavailable>}

gdb:

2014-04-26  Yao Qi  <yao@codesourcery.com>
	    Pedro Alves  <palves@redhat.com>

	* tracefile-tfile.c (tfile_xfer_partial): Record the lowest
	address of blocks that intersects the requested range.  Trim
	LEN up to LOW_ADDR_AVAILABLE if read from executable read-only
	sections.
	* ctf.c (ctf_xfer_partial): Likewise.
---
 gdb/ctf.c             | 11 ++++++++++-
 gdb/tracefile-tfile.c | 11 ++++++++++-
 2 files changed, 20 insertions(+), 2 deletions(-)
  

Comments

Pedro Alves April 30, 2014, 4:28 p.m. UTC | #1
On 04/28/2014 07:12 AM, Yao Qi wrote:

> gdb:
> 
> 2014-04-26  Yao Qi  <yao@codesourcery.com>
> 	    Pedro Alves  <palves@redhat.com>
> 
> 	* tracefile-tfile.c (tfile_xfer_partial): Record the lowest
> 	address of blocks that intersects the requested range.  Trim
> 	LEN up to LOW_ADDR_AVAILABLE if read from executable read-only
> 	sections.
> 	* ctf.c (ctf_xfer_partial): Likewise.

OK.

Thanks!
  

Patch

diff --git a/gdb/ctf.c b/gdb/ctf.c
index bac7c28..84d0a48 100644
--- a/gdb/ctf.c
+++ b/gdb/ctf.c
@@ -1328,6 +1328,9 @@  ctf_xfer_partial (struct target_ops *ops, enum target_object object,
       struct bt_iter_pos *pos;
       int i = 0;
       enum target_xfer_status res;
+      /* Records the lowest available address of all blocks that
+	 intersects the requested range.  */
+      ULONGEST low_addr_available = 0;
 
       gdb_assert (ctf_iter != NULL);
       /* Save the current position.  */
@@ -1410,6 +1413,10 @@  ctf_xfer_partial (struct target_ops *ops, enum target_object object,
 		}
 	    }
 
+	  if (offset < maddr && maddr < (offset + len))
+	    if (low_addr_available == 0 || low_addr_available > maddr)
+	      low_addr_available = maddr;
+
 	  if (bt_iter_next (bt_ctf_get_iter (ctf_iter)) < 0)
 	    break;
 	}
@@ -1419,7 +1426,9 @@  ctf_xfer_partial (struct target_ops *ops, enum target_object object,
 
       /* Requested memory is unavailable in the context of traceframes,
 	 and this address falls within a read-only section, fallback
-	 to reading from executable.  */
+	 to reading from executable, up to LOW_ADDR_AVAILABLE  */
+      if (offset < low_addr_available)
+	len = min (len, low_addr_available - offset);
       res = exec_read_partial_read_only (readbuf, offset, len, xfered_len);
 
       if (res == TARGET_XFER_OK)
diff --git a/gdb/tracefile-tfile.c b/gdb/tracefile-tfile.c
index efa69b2..37dc691 100644
--- a/gdb/tracefile-tfile.c
+++ b/gdb/tracefile-tfile.c
@@ -853,6 +853,9 @@  tfile_xfer_partial (struct target_ops *ops, enum target_object object,
     {
       int pos = 0;
       enum target_xfer_status res;
+      /* Records the lowest available address of all blocks that
+	 intersects the requested range.  */
+      ULONGEST low_addr_available = 0;
 
       /* Iterate through the traceframe's blocks, looking for
 	 memory.  */
@@ -886,13 +889,19 @@  tfile_xfer_partial (struct target_ops *ops, enum target_object object,
 	      return TARGET_XFER_OK;
 	    }
 
+	  if (offset < maddr && maddr < (offset + len))
+	    if (low_addr_available == 0 || low_addr_available > maddr)
+	      low_addr_available = maddr;
+
 	  /* Skip over this block.  */
 	  pos += (8 + 2 + mlen);
 	}
 
       /* Requested memory is unavailable in the context of traceframes,
 	 and this address falls within a read-only section, fallback
-	 to reading from executable.  */
+	 to reading from executable, up to LOW_ADDR_AVAILABLE.  */
+      if (offset < low_addr_available)
+	len = min (len, low_addr_available - offset);
       res = exec_read_partial_read_only (readbuf, offset, len, xfered_len);
 
       if (res == TARGET_XFER_OK)