From patchwork Sun Apr 20 12:48:06 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yao Qi X-Patchwork-Id: 627 Return-Path: X-Original-To: siddhesh@wilcox.dreamhost.com Delivered-To: siddhesh@wilcox.dreamhost.com Received: from homiemail-mx21.g.dreamhost.com (peon2454.g.dreamhost.com [208.113.200.127]) by wilcox.dreamhost.com (Postfix) with ESMTP id 70784360068 for ; Sun, 20 Apr 2014 05:50:50 -0700 (PDT) Received: by homiemail-mx21.g.dreamhost.com (Postfix, from userid 14314964) id 8BCAF1305C1F; Sun, 20 Apr 2014 05:50:45 -0700 (PDT) X-Original-To: gdb@patchwork.siddhesh.in Delivered-To: x14314964@homiemail-mx21.g.dreamhost.com Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by homiemail-mx21.g.dreamhost.com (Postfix) with ESMTPS id 6069612E4619 for ; Sun, 20 Apr 2014 05:50:45 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:subject:date:message-id:mime-version :content-type; q=dns; s=default; b=gul98vxU2zdrhHdWlsoAVuOGvfvsB rrK+Y9gz/1OykeCaDBFcJH+n5gbVVUsZbz/tqn+M9FuAWbwkeKEfwgdCd7JhqIYs XGVd0CYR1zFRHxI1CNmJu4wT3Y5hU5QK66JXKojv48RDQ+1J+57HKbOKzDx7B6qY 20LltVcO+YptFA= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:subject:date:message-id:mime-version :content-type; s=default; bh=+ECHulJfVBjsknmTGRlrCkk8bOI=; b=cYe aKJzkaiLs99r6b94/GS2kWY+YPccvpz0NMUdDmOMMymcbwS17U2NFmayTs3ZE+fk JMk9sEPauZFyhg+vzXkx0wsmIy8OqUnR6ZhN87GZ3wha9I1KDQxxjKuEGg8GzyHu 19DLO5wleVoS5ymKbg6elccCU3jL62whbG3OUUWo= Received: (qmail 16284 invoked by alias); 20 Apr 2014 12:50:43 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 16272 invoked by uid 89); 20 Apr 2014 12:50:43 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.6 required=5.0 tests=AWL, BAYES_00 autolearn=ham version=3.3.2 X-HELO: relay1.mentorg.com Received: from relay1.mentorg.com (HELO relay1.mentorg.com) (192.94.38.131) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sun, 20 Apr 2014 12:50:42 +0000 Received: from svr-orw-exc-10.mgc.mentorg.com ([147.34.98.58]) by relay1.mentorg.com with esmtp id 1WbrCh-0005Mt-91 from Yao_Qi@mentor.com for gdb-patches@sourceware.org; Sun, 20 Apr 2014 05:50:39 -0700 Received: from SVR-ORW-FEM-06.mgc.mentorg.com ([147.34.97.120]) by SVR-ORW-EXC-10.mgc.mentorg.com with Microsoft SMTPSVC(6.0.3790.4675); Sun, 20 Apr 2014 05:50:38 -0700 Received: from qiyao.dyndns.org.com (147.34.91.1) by SVR-ORW-FEM-06.mgc.mentorg.com (147.34.97.120) with Microsoft SMTP Server id 14.2.247.3; Sun, 20 Apr 2014 05:50:38 -0700 From: Yao Qi To: Subject: [PATCH] Partially available/unavailable data in requested range Date: Sun, 20 Apr 2014 20:48:06 +0800 Message-ID: <1397998086-750-1-git-send-email-yao@codesourcery.com> MIME-Version: 1.0 X-IsSubscribed: yes X-DH-Original-To: gdb@patchwork.siddhesh.in 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 = , s1 = {s3 = {g = , h = }, d = }, s2 = {e = , f = }} 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 = , s1 = {s3 = {g = 0, h = }, d = 0}, s2 = {e = , 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 * 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. */