From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 30792 invoked by alias); 27 Nov 2013 12:22:25 -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 30780 invoked by uid 89); 27 Nov 2013 12:22:24 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.7 required=5.0 tests=AWL,BAYES_05,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; Wed, 27 Nov 2013 12:22:22 +0000 Received: from svr-orw-fem-01.mgc.mentorg.com ([147.34.98.93]) by relay1.mentorg.com with esmtp id 1Vle86-0002DD-GQ from Yao_Qi@mentor.com for gdb-patches@sourceware.org; Wed, 27 Nov 2013 04:22:06 -0800 Received: from SVR-ORW-FEM-05.mgc.mentorg.com ([147.34.97.43]) by svr-orw-fem-01.mgc.mentorg.com over TLS secured channel with Microsoft SMTPSVC(6.0.3790.4675); Wed, 27 Nov 2013 04:22:06 -0800 Received: from qiyao.dyndns.org.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; Wed, 27 Nov 2013 04:21:22 -0800 From: Yao Qi To: Subject: [PATCH] Delegate to target_ops->beneath to read cache lines Date: Wed, 27 Nov 2013 12:41:00 -0000 Message-ID: <1385554824-7159-1-git-send-email-yao@codesourcery.com> MIME-Version: 1.0 Content-Type: text/plain X-IsSubscribed: yes X-SW-Source: 2013-11/txt/msg00839.txt.bz2 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 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 doesn't have such mechanism, and that is the cause for the error. This patch adds something similar in dcache_read_line to go through target_ops from top to bottom, and call to_xfer_partial. The original code uses TARGET_OBJECT_RAW_MEMORY, which is replaced by TARGET_OBJECT_MEMORY in target_xfer_partial, 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; so we can use TARGET_OBJECT_MEMORY here. Regression tested on x86_64-linux. gdb: 2013-11-27 Yao Qi * dcache.c (dcache_read_line): Don't call target_read. Use beneath->to_xfer_partial in a loop. --- gdb/dcache.c | 23 +++++++++++++++++++---- 1 files changed, 19 insertions(+), 4 deletions(-) diff --git a/gdb/dcache.c b/gdb/dcache.c index ea2b732..f52fc17 100644 --- a/gdb/dcache.c +++ b/gdb/dcache.c @@ -313,6 +313,7 @@ dcache_read_line (DCACHE *dcache, struct dcache_block *db) int res; int reg_len; struct mem_region *region; + struct target_ops *ops = current_target.beneath; len = dcache->line_size; memaddr = db->addr; @@ -336,10 +337,24 @@ dcache_read_line (DCACHE *dcache, struct dcache_block *db) len -= reg_len; continue; } - - res = target_read (¤t_target, TARGET_OBJECT_RAW_MEMORY, - NULL, myaddr, memaddr, reg_len); - if (res < reg_len) + + do + { + res = ops->to_xfer_partial (ops, TARGET_OBJECT_MEMORY, NULL, + myaddr, NULL, 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); + + if (res <= 0) return 0; memaddr += res; -- 1.7.7.6