From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 22103 invoked by alias); 29 Nov 2013 02:54:45 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 22090 invoked by uid 89); 29 Nov 2013 02:54:44 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=3.2 required=5.0 tests=AWL,BAYES_50,GARBLED_BODY,RDNS_NONE,URIBL_BLOCKED autolearn=no version=3.3.2 X-HELO: relay1.mentorg.com Received: from Unknown (HELO relay1.mentorg.com) (192.94.38.131) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 29 Nov 2013 02:54:42 +0000 Received: from svr-orw-exc-10.mgc.mentorg.com ([147.34.98.58]) by relay1.mentorg.com with esmtp id 1VmEDq-0001dR-H5 from Yao_Qi@mentor.com ; Thu, 28 Nov 2013 18:54:26 -0800 Received: from SVR-ORW-FEM-05.mgc.mentorg.com ([147.34.97.43]) by SVR-ORW-EXC-10.mgc.mentorg.com with Microsoft SMTPSVC(6.0.3790.4675); Thu, 28 Nov 2013 18:54:26 -0800 Received: from qiyao.dyndns.org (147.34.91.1) by svr-orw-fem-05.mgc.mentorg.com (147.34.97.43) with Microsoft SMTP Server id 14.2.247.3; Thu, 28 Nov 2013 18:53:34 -0800 Message-ID: <52980180.1050000@codesourcery.com> Date: Fri, 29 Nov 2013 11:12:00 -0000 From: Yao Qi User-Agent: Mozilla/5.0 (X11; Linux i686; rv:17.0) Gecko/20130110 Thunderbird/17.0.2 MIME-Version: 1.0 To: Pedro Alves CC: Subject: Re: [PATCH] Delegate to target_ops->beneath to read cache lines References: <1385554824-7159-1-git-send-email-yao@codesourcery.com> <5295F877.3060004@redhat.com> In-Reply-To: <5295F877.3060004@redhat.com> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8bit X-IsSubscribed: yes X-SW-Source: 2013-11/txt/msg00898.txt.bz2 On 11/27/2013 09:49 PM, Pedro Alves wrote: > The dcache is the sole user of TARGET_OBJECT_RAW_MEMORY. This shows > that if we want to code from lower targets too, then this sole user also > wants to do the top to bottom delegation that memory_xfer_partial_1 does. > > So this can all be done within target.c. Factor out the > memory_xfer_partial_1 top to bottom memory read code to a separate > raw_memory_xfer_partial function (despite the name, it'd request > TARGET_OBJECT_MEMORY from the targets), and make target_xfer_partial > call that for TARGET_OBJECT_RAW_MEMORY: Yeah, that looks cleaner than my patch. How about this one? -- Yao (齐尧) Subject: [PATCH] Delegate to target_ops->beneath for TARGET_OBJECT_RAW_MEMORY GDB on x86_64-linux is unable to disassemble on core-file target. $ ./gdb ./testsuite/gdb.base/corefile (gdb) core-file ./testsuite/gdb.base/corefile.core (gdb) disassemble main Dump of assembler code for function main: 0x0000000000400976 <+0>: Cannot access memory at address 0x400976 However, it works if we turn code-cache off. (gdb) set code-cache off (gdb) disassemble main,+4 Dump of assembler code from 0x400976 to 0x40097a: 0x0000000000400976 : push %rbp 0x0000000000400977 : mov %rsp,%rbp End of assembler dump. When code-cache is off, GDB will iterate target_ops from top to bottom and call to_xfer_partial. When current_target is "core", it will call to_xfer_partial of target "exec", which reads the contents for disassemble. However, dcache uses TARGET_OBJECT_RAW_MEMORY to read, but target_xfer_partial doesn't delegate requests to beneath for TARGET_OBJECT_RAW_MEMORY. This patch factors out the iteration from top to bottom to a new function, raw_memory_xfer_partial, and use it for TARGET_OBJECT_RAW_MEMORY. Note that using ¤t_target in dcache_read_line will cause an endless recursion, so I change it to current_target.beneath. IMO, other ¤t_target usages should be changed to current_target.beneath too. Regression tested on x86_64-linux. gdb: 2013-11-29 Yao Qi Pedro Alves * dcache.c (dcache_read_line): Use current_target.beneath instead of ¤t_target. * target.c (memory_xfer_partial_1): Factor code out to ... (raw_memory_xfer_partial): ... it. New function. (target_xfer_partial): Call raw_memory_xfer_partial if OBJECT is TARGET_OBJECT_RAW_MEMORY. --- gdb/dcache.c | 4 +- gdb/target.c | 67 ++++++++++++++++++++++++++++++++-------------------------- 2 files changed, 39 insertions(+), 32 deletions(-) diff --git a/gdb/dcache.c b/gdb/dcache.c index ea2b732..12d1a4b 100644 --- a/gdb/dcache.c +++ b/gdb/dcache.c @@ -336,8 +336,8 @@ dcache_read_line (DCACHE *dcache, struct dcache_block *db) len -= reg_len; continue; } - - res = target_read (¤t_target, TARGET_OBJECT_RAW_MEMORY, + + res = target_read (current_target.beneath, TARGET_OBJECT_RAW_MEMORY, NULL, myaddr, memaddr, reg_len); if (res < reg_len) return 0; diff --git a/gdb/target.c b/gdb/target.c index cc6194b..6c72e70 100644 --- a/gdb/target.c +++ b/gdb/target.c @@ -1398,6 +1398,35 @@ memory_xfer_live_readonly_partial (struct target_ops *ops, return 0; } +/* Read memory from more than one valid target. A core file, for + instance, could have some of memory but delegate other bits to + the target below it. So, we must manually try all targets. */ + +static LONGEST +raw_memory_xfer_partial (struct target_ops *ops, void *readbuf, + const void *writebuf, ULONGEST memaddr, LONGEST len) +{ + LONGEST res; + + do + { + res = ops->to_xfer_partial (ops, TARGET_OBJECT_MEMORY, NULL, + readbuf, writebuf, memaddr, len); + if (res > 0) + break; + + /* We want to continue past core files to executables, but not + past a running target's memory. */ + if (ops->to_has_all_memory (ops)) + break; + + ops = ops->beneath; + } + while (ops != NULL); + + return res; +} + /* Perform a partial memory transfer. For docs see target.h, to_xfer_partial. */ @@ -1571,26 +1600,8 @@ memory_xfer_partial_1 (struct target_ops *ops, enum target_object object, to_xfer_partial is enough; if it doesn't recognize an object it will call the to_xfer_partial of the next target down. But for memory this won't do. Memory is the only target - object which can be read from more than one valid target. - A core file, for instance, could have some of memory but - delegate other bits to the target below it. So, we must - manually try all targets. */ - - do - { - res = ops->to_xfer_partial (ops, TARGET_OBJECT_MEMORY, NULL, - readbuf, writebuf, memaddr, reg_len); - if (res > 0) - break; - - /* We want to continue past core files to executables, but not - past a running target's memory. */ - if (ops->to_has_all_memory (ops)) - break; - - ops = ops->beneath; - } - while (ops != NULL); + object which can be read from more than one valid target. */ + res = raw_memory_xfer_partial (ops, readbuf, writebuf, memaddr, reg_len); /* Make sure the cache gets updated no matter what - if we are writing to the stack. Even if this write is not tagged as such, we still need @@ -1702,18 +1713,14 @@ target_xfer_partial (struct target_ops *ops, || object == TARGET_OBJECT_CODE_MEMORY) retval = memory_xfer_partial (ops, object, readbuf, writebuf, offset, len); - else + else if (object == TARGET_OBJECT_RAW_MEMORY) { - enum target_object raw_object = object; - - /* If this is a raw memory transfer, request the normal - memory object from other layers. */ - if (raw_object == TARGET_OBJECT_RAW_MEMORY) - raw_object = TARGET_OBJECT_MEMORY; - - retval = ops->to_xfer_partial (ops, raw_object, annex, readbuf, - writebuf, offset, len); + /* Request the normal memory object from other layers. */ + retval = raw_memory_xfer_partial (ops, readbuf, writebuf, offset, len); } + else + retval = ops->to_xfer_partial (ops, object, annex, readbuf, + writebuf, offset, len); if (targetdebug) { -- 1.7.7.6