This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[PATCH] Partially available/unavailable data in requested range
- From: Yao Qi <yao at codesourcery dot com>
- To: <gdb-patches at sourceware dot org>
- Date: Sun, 20 Apr 2014 20:48:06 +0800
- Subject: [PATCH] Partially available/unavailable data in requested range
- Authentication-results: sourceware.org; auth=none
I am testing again my pending patches "Visit varobj available children only in MI"
and find a regression in mi-available-children-only.exp, in which we
collect part of the fields of struct simple,
struct simple
{
int a; /* Collected by both. */
int b; /* Collected by action 2. */
struct
{
struct
{
int g; /* Collected by action 1. */
int h; /* Collected by action 2. */
} s3;
int d; /* Collected by action 1. */
} s1;
struct
{
int e;
int f; /* Collected by action 1. */
} s2;
};
When GDB examine traceframe collected by action 1, some collected fields
are unavailable, which is wrong.
(gdb) p s
$1 = {a = 0, b = <unavailable>, s1 = {s3 = {g = <unavailable>, h = <unavailable>}, d = <unavailable>}, s2 = {e = <unavailable>, f = <unavailable>}}
1. When GDB reads struct 's', it will request to read memory at address S
of length 28. Since s.a is collected while s.b isn't, tfile_xfer_partial
will return TARGET_XFER_OK and *xfered_len is set to 4 (length of s.a).
2. Then, GDB request to read memory at address S + 4 of length 24. No block
includes the first part of the desired range, so tfile_xfer_partial returns
TARGET_XFER_UNAVAILABLE and GDB thinks the range [S + 4, S + 28) is unavailable.
In order to fix this problem, in the iteration to 'M' blocks, we record the
minimal 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 mi-available-children-only.exp are
fixed as a result.
(gdb) p s
$1 = {a = 0, b = <unavailable>, s1 = {s3 = {g = 0, h = <unavailable>}, d = 0}, s2 = {e = <unavailable>, f = 0}}
I don't add a test case for it because mi-available-children-only.exp
will cover it.
gdb:
2014-04-20 Yao Qi <yao@codesourcery.com>
* tracefile-tfile.c (tfile_xfer_partial): Record the minimal
address of blocks and return TARGET_XFER_UNAVAILABLE if it
is within the requested range.
* ctf.c (ctf_xfer_partial): Likewise.
---
gdb/ctf.c | 18 ++++++++++++++++++
gdb/tracefile-tfile.c | 18 ++++++++++++++++++
2 files changed, 36 insertions(+)
diff --git a/gdb/ctf.c b/gdb/ctf.c
index bac7c28..253548d 100644
--- a/gdb/ctf.c
+++ b/gdb/ctf.c
@@ -1328,6 +1328,7 @@ ctf_xfer_partial (struct target_ops *ops, enum target_object object,
struct bt_iter_pos *pos;
int i = 0;
enum target_xfer_status res;
+ ULONGEST min_addr_available = 0;
gdb_assert (ctf_iter != NULL);
/* Save the current position. */
@@ -1410,6 +1411,13 @@ ctf_xfer_partial (struct target_ops *ops, enum target_object object,
}
}
+ /* If the block is within the desired range, the desired
+ range isn't fully unavailable. Record the minimal address
+ of blocks. */
+ if (offset < maddr && maddr < (offset + len))
+ if (min_addr_available == 0 || min_addr_available > maddr)
+ min_addr_available = maddr;
+
if (bt_iter_next (bt_ctf_get_iter (ctf_iter)) < 0)
break;
}
@@ -1417,6 +1425,16 @@ ctf_xfer_partial (struct target_ops *ops, enum target_object object,
/* Restore the position. */
bt_iter_set_pos (bt_ctf_get_iter (ctf_iter), pos);
+ /* There should be at least one block within desired range, and
+ range [OFFSET, MIN_ADDR_AVAILABLE) is unavailable. Tell
+ caller about it and caller will request memory from
+ MIN_ADDR_AVAILABLE. */
+ if (offset < min_addr_available)
+ {
+ *xfered_len = min_addr_available - offset;
+ return TARGET_XFER_UNAVAILABLE;
+ }
+
/* Requested memory is unavailable in the context of traceframes,
and this address falls within a read-only section, fallback
to reading from executable. */
diff --git a/gdb/tracefile-tfile.c b/gdb/tracefile-tfile.c
index efa69b2..472f387 100644
--- a/gdb/tracefile-tfile.c
+++ b/gdb/tracefile-tfile.c
@@ -853,6 +853,7 @@ tfile_xfer_partial (struct target_ops *ops, enum target_object object,
{
int pos = 0;
enum target_xfer_status res;
+ ULONGEST min_addr_available = 0;
/* Iterate through the traceframe's blocks, looking for
memory. */
@@ -886,10 +887,27 @@ tfile_xfer_partial (struct target_ops *ops, enum target_object object,
return TARGET_XFER_OK;
}
+ /* If the block is within the desired range, the desired
+ range isn't fully unavailable. Record the minimal address
+ of blocks. */
+ if (offset < maddr && maddr < (offset + len))
+ if (min_addr_available == 0 || min_addr_available > maddr)
+ min_addr_available = maddr;
+
/* Skip over this block. */
pos += (8 + 2 + mlen);
}
+ /* There should be at least one block within desired range, and
+ range [OFFSET, MIN_ADDR_AVAILABLE) is unavailable. Tell
+ caller about it and caller will request memory from
+ MIN_ADDR_AVAILABLE. */
+ if (offset < min_addr_available)
+ {
+ *xfered_len = min_addr_available - offset;
+ return TARGET_XFER_UNAVAILABLE;
+ }
+
/* Requested memory is unavailable in the context of traceframes,
and this address falls within a read-only section, fallback
to reading from executable. */
--
1.9.0