From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 16960 invoked by alias); 8 Sep 2013 12:04:59 -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 16835 invoked by uid 89); 8 Sep 2013 12:04:58 -0000 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, 08 Sep 2013 12:04:58 +0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.6 required=5.0 tests=AWL,BAYES_00,KHOP_THREADED,RDNS_NONE,SPF_HELO_FAIL autolearn=no version=3.3.2 X-HELO: relay1.mentorg.com Received: from svr-orw-fem-01.mgc.mentorg.com ([147.34.98.93]) by relay1.mentorg.com with esmtp id 1VIdjZ-0005Rq-Jk from Yao_Qi@mentor.com for gdb-patches@sourceware.org; Sun, 08 Sep 2013 05:04:53 -0700 Received: from SVR-ORW-FEM-02.mgc.mentorg.com ([147.34.96.206]) by svr-orw-fem-01.mgc.mentorg.com over TLS secured channel with Microsoft SMTPSVC(6.0.3790.4675); Sun, 8 Sep 2013 05:04:52 -0700 Received: from qiyao.dyndns.org.dyndns.org (147.34.91.1) by svr-orw-fem-02.mgc.mentorg.com (147.34.96.168) with Microsoft SMTP Server id 14.2.247.3; Sun, 8 Sep 2013 05:04:52 -0700 From: Yao Qi To: Subject: [PATCH 1/7] Emit a warning when writing to a readonly section and trust_readonly is true Date: Sun, 08 Sep 2013 12:04:00 -0000 Message-ID: <1378641807-24256-2-git-send-email-yao@codesourcery.com> In-Reply-To: <1378641807-24256-1-git-send-email-yao@codesourcery.com> References: <1378432920-7731-1-git-send-email-yao@codesourcery.com> <1378641807-24256-1-git-send-email-yao@codesourcery.com> MIME-Version: 1.0 Content-Type: text/plain X-IsSubscribed: yes X-SW-Source: 2013-09/txt/msg00259.txt.bz2 If users write a readonly section, such as .text, the contents of the inferior and of the executable become out of sync. It is better to emit a warning to ask users to "set trust-readonly-sections off". (gdb) set trust-readonly-sections on (gdb) p /x* (char *) 0x080484c1 = 0xcc warning: Writing to a readonly section so that the contents in the inferior and in the executable are out of sync. Please 'set trust-readonly-sections off'. $1 = 0xcc gdb: 2013-09-08 Yao Qi * target.c (memory_xfer_partial_1): Emit a warning if GDB writes to a readonly section and 'trust_readonly' is true. --- gdb/target.c | 31 ++++++++++++++++++++++--------- 1 files changed, 22 insertions(+), 9 deletions(-) diff --git a/gdb/target.c b/gdb/target.c index d55712d..f6a58ff 100644 --- a/gdb/target.c +++ b/gdb/target.c @@ -1471,11 +1471,13 @@ memory_xfer_partial_1 (struct target_ops *ops, enum target_object object, } } - /* Try the executable files, if "trust-readonly-sections" is set. */ - if (readbuf != NULL && trust_readonly) + /* If "trust-readonly-sections" is set, read from the executable + files. When GDB writes to a readonly section of the inferior, + emit a warning that option 'trust-readonly-sections' should be + turned off. */ + if (trust_readonly) { struct target_section *secp; - struct target_section_table *table; secp = target_section_by_addr (ops, memaddr); if (secp != NULL @@ -1483,12 +1485,23 @@ memory_xfer_partial_1 (struct target_ops *ops, enum target_object object, secp->the_bfd_section) & SEC_READONLY)) { - table = target_get_section_table (ops); - return section_table_xfer_memory_partial (readbuf, writebuf, - memaddr, len, - table->sections, - table->sections_end, - NULL); + + if (readbuf != NULL) + { + struct target_section_table *table; + + table = target_get_section_table (ops); + return section_table_xfer_memory_partial (readbuf, writebuf, + memaddr, len, + table->sections, + table->sections_end, + NULL); + } + + if (writebuf != NULL) + warning (_("Writing to a readonly section so that the contents" + " in the inferior and in the executable are out of" + " sync. Please 'set trust-readonly-sections off'.")); } } -- 1.7.7.6