From patchwork Thu May 22 14:23:38 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pierre Langlois X-Patchwork-Id: 1075 Return-Path: X-Original-To: siddhesh@wilcox.dreamhost.com Delivered-To: siddhesh@wilcox.dreamhost.com Received: from homiemail-mx23.g.dreamhost.com (mx2.sub5.homie.mail.dreamhost.com [208.113.200.128]) by wilcox.dreamhost.com (Postfix) with ESMTP id A582D360076 for ; Thu, 22 May 2014 07:23:51 -0700 (PDT) Received: by homiemail-mx23.g.dreamhost.com (Postfix, from userid 14314964) id 57605640872E6; Thu, 22 May 2014 07:23:51 -0700 (PDT) X-Original-To: gdb@patchwork.siddhesh.in Delivered-To: x14314964@homiemail-mx23.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-mx23.g.dreamhost.com (Postfix) with ESMTPS id 34B62640872DB for ; Thu, 22 May 2014 07:23:51 -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:message-id:date:from:mime-version:to:subject :content-type:content-transfer-encoding; q=dns; s=default; b=FyD T7AvdFE4AOlSEdrKTpkd7EZDfcD9zqqSUmRSboGuZ2enufpKMLaau1PiTS/3lCc9 jIz2LySxF4AN4uDC7itJYYLYHwMXRfm2dEMzwljYPv0GzODhS7Ds7BkT3Mdt/rjF fHAJjtbEH5iVb63O5G5JtiLKdH2bs/rUAJBRDaTw= 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:message-id:date:from:mime-version:to:subject :content-type:content-transfer-encoding; s=default; bh=UJh9UJMKM mj+I6KrNBC03oYUNyo=; b=CUzG56jEzgFUG9ug8gMgmql+B5ubyYoXnsGCKcO8H KWdQUnAln2KqjFxNKkzWOMTN85q8qOujshD0fR1QoF8DUa+iJPOFpxFgQQo5wBNU r4MuBLNtYNFKOzJTZ8P8CBHCFB/hXwpZPVHqkpow0PEOCbcBUaRsm50Fc55rqegS mI= Received: (qmail 24762 invoked by alias); 22 May 2014 14:23:49 -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 24727 invoked by uid 89); 22 May 2014 14:23:45 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.3 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.2 X-HELO: mail-wg0-f49.google.com Received: from mail-wg0-f49.google.com (HELO mail-wg0-f49.google.com) (74.125.82.49) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Thu, 22 May 2014 14:23:43 +0000 Received: by mail-wg0-f49.google.com with SMTP id m15so3509568wgh.32 for ; Thu, 22 May 2014 07:23:40 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:message-id:date:from:user-agent:mime-version:to :subject:content-type:content-transfer-encoding; bh=Hcc+Bycg826deat2ZtcnGfYeIaRdAHZursmzl7vWhFI=; b=MnKZeBf/C5ThH74gBrcSGZ0P21LFUq/RvL4eyPQNcWTr4vAWn6DmndILdHTOllJGZo p62iijmehuzFTd3L9AyPp+XSYInrcwTsrF5xud9FObgfwqjOC26QUOU/BRZ0Tnq2nQWp b22UyTNuJzfxhMvbdX2pxqnbO0QKfSShD6fbXD7Vj/zJAMGCy7INfJ414+iQEIGCDt3o iosSpxDoZoL/DS1gMPbWwckOChRcW2jaMlPnyeiqUl57Ypa/bbGEjUs7us1VVER9sSbr lK6i9sK3JNhnajRPqGl2jK7PFqeVjbK42glHx4Tp8FPFQy3WS3ShyRdFi9XYzg0qz0yL J1GA== X-Gm-Message-State: ALoCoQmMf9UiSCkOiQOV7v1vRLWoBF/n1vqePkAoI5hiP7dpf5QelxujiKwEkSI/Os3Cqzx5BjTh X-Received: by 10.194.82.9 with SMTP id e9mr50221347wjy.45.1400768620420; Thu, 22 May 2014 07:23:40 -0700 (PDT) Received: from [192.168.0.8] (cust64-dsl91-135-5.idnet.net. [91.135.5.64]) by mx.google.com with ESMTPSA id o9sm26948779wjo.1.2014.05.22.07.23.39 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 22 May 2014 07:23:39 -0700 (PDT) Message-ID: <537E086A.9030803@embecosm.com> Date: Thu, 22 May 2014 15:23:38 +0100 From: Pierre Langlois User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.5.0 MIME-Version: 1.0 To: gdb-patches@sourceware.org, palves@redhat.com Subject: [RFC][PATCH v2][PR remote/16896] Invalidate a register in cache when a remote target failed to write it. X-IsSubscribed: yes X-DH-Original-To: gdb@patchwork.siddhesh.in Hello all, This patch addresses the issue in patch [1] generically as pointed out by a comment [2]. As opposed to invalidating a register in cache in the remote target before throwing an error, we can do this using a cleanup in regcache_raw_write. This patch adds routines to add a regcache_invalidate cleanup to the current chain. We can use this before target_store_registers and discard it after if an error was not thrown. [1] https://sourceware.org/ml/gdb-patches/2014-05/msg00083.html [2] https://sourceware.org/ml/gdb-patches/2014-05/msg00357.html 2014-05-20 Pierre Langlois PR remote/16896 * regcache.c (register_to_invalidate): New structure. Combines a pointer to a struct regcache and a register number. (do_register_invalidate): New function. Call regcache_invalidate. (make_cleanup_regcache_invalidate): New function. Construct a cleanup for invalidating a register. (regcache_raw_write): Call make_cleanup_regcache_invalidate * regcache.h (make_cleanup_regcache_invalidate): New prototype. --- gdb/regcache.c | 41 ++++++++++++++++++++++++++++++++++++++--- gdb/regcache.h | 2 ++ 2 files changed, 40 insertions(+), 3 deletions(-) diff --git a/gdb/regcache.c b/gdb/regcache.c index 8b588c6..87a6b02 100644 --- a/gdb/regcache.c +++ b/gdb/regcache.c @@ -267,6 +267,30 @@ make_cleanup_regcache_xfree (struct regcache *regcache) return make_cleanup (do_regcache_xfree, regcache); } +/* Cleanup routines for invalidating a register. */ + +struct register_to_invalidate +{ + struct regcache *regcache; + int regnum; +}; + +static void +do_regcache_invalidate (void *data) +{ + struct register_to_invalidate *reg = data; + regcache_invalidate (reg->regcache, reg->regnum); +} + +struct cleanup * +make_cleanup_regcache_invalidate (struct regcache *regcache, int regnum) +{ + struct register_to_invalidate* reg = XNEW (struct register_to_invalidate); + reg->regcache = regcache; + reg->regnum = regnum; + return make_cleanup_dtor (do_regcache_invalidate, (void *) reg, xfree); +} + /* Return REGCACHE's architecture. */ struct gdbarch * @@ -846,7 +870,8 @@ void regcache_raw_write (struct regcache *regcache, int regnum, const gdb_byte *buf) { - struct cleanup *old_chain; + struct cleanup *chain_before_save_inferior; + struct cleanup *chain_before_invalidate_register; gdb_assert (regcache != NULL && buf != NULL); gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_raw_registers); @@ -864,16 +889,26 @@ regcache_raw_write (struct regcache *regcache, int regnum, regcache->descr->sizeof_register[regnum]) == 0)) return; - old_chain = save_inferior_ptid (); + chain_before_save_inferior = save_inferior_ptid (); inferior_ptid = regcache->ptid; target_prepare_to_store (regcache); memcpy (register_buffer (regcache, regnum), buf, regcache->descr->sizeof_register[regnum]); regcache->register_status[regnum] = REG_VALID; + + /* Register a cleanup function for invalidating the register after it is + written, in case of a failure. */ + chain_before_invalidate_register = + make_cleanup_regcache_invalidate (regcache, regnum); + target_store_registers (regcache, regnum); - do_cleanups (old_chain); + /* The target did not throw an error so we can discard invalidating the + register and restore the cleanup chain to what it was. */ + discard_cleanups (chain_before_invalidate_register); + + do_cleanups (chain_before_save_inferior); } void diff --git a/gdb/regcache.h b/gdb/regcache.h index 8423f57..bb40b65 100644 --- a/gdb/regcache.h +++ b/gdb/regcache.h @@ -33,6 +33,8 @@ extern struct regcache *get_thread_arch_aspace_regcache (ptid_t, void regcache_xfree (struct regcache *regcache); struct cleanup *make_cleanup_regcache_xfree (struct regcache *regcache); +struct cleanup *make_cleanup_regcache_invalidate (struct regcache *regcache, + int regnum); struct regcache *regcache_xmalloc (struct gdbarch *gdbarch, struct address_space *aspace);