From patchwork Fri Oct 27 09:31:37 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yao Qi X-Patchwork-Id: 23902 Received: (qmail 51834 invoked by alias); 27 Oct 2017 09:31:54 -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 51804 invoked by uid 89); 27 Oct 2017 09:31:54 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.4 required=5.0 tests=BAYES_00, FREEMAIL_FROM, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM, SPF_PASS autolearn=ham version=3.3.2 spammy=H*RU:209.85.128.194, Hx-spam-relays-external:209.85.128.194, Hx-languages-length:5166, H*r:sk:static. X-HELO: mail-wr0-f194.google.com Received: from mail-wr0-f194.google.com (HELO mail-wr0-f194.google.com) (209.85.128.194) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 27 Oct 2017 09:31:52 +0000 Received: by mail-wr0-f194.google.com with SMTP id r79so5581868wrb.13 for ; Fri, 27 Oct 2017 02:31:52 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=9ICAahrqkUcbmf3cvP6MyLw+YHzJnsNKzfXRa1OnPCQ=; b=Y8vWuSRJMWd2Y1Kl7gx74kck0Qt6XaUJWZdAXRQFbmlj5/TtWO/29zTB7DxzD/4gvt vEwm89CkuEd6xcsJZ1V49Hg2J8EJmDnHUfu61n4AdqidBMoP6uua5TzUork+vYf9NKBo 4P75ASoWeJf1nGI/h5luWnuFqsfzsXyq84jgn7PpQVjKGuZc7Nlp+TMxqfNyRLAcTT1Y 2P2iVsYucw0614Png9IkQEwEN6up2w4pxVNSj45vuQQy0bKHIC8SuRKRKDSPJx2K7swa uHtlYVmtIMQ6LApaUicz7EuBd5d8rRSvt03nGchq12ta5UNEOH65sIPbMZsGY5jMcGss hFKA== X-Gm-Message-State: AMCzsaVUnfRPB4ZQVZDUdho7StAE7D88FeAqpsrSw1nYd1n+7a2PnyES TYav2F6wyHSPzixyV08UbYYeEw== X-Google-Smtp-Source: ABhQp+RFshG6RdJtxHk2PEpiHXSglgFwBDsgwhziaEPI7yMlEg7ZMxcbGHdDy1kuI0BFDb3A+dMIbw== X-Received: by 10.223.186.20 with SMTP id o20mr8710878wrg.3.1509096710349; Fri, 27 Oct 2017 02:31:50 -0700 (PDT) Received: from E107787-LIN.cambridge.arm.com (static.42.136.251.148.clients.your-server.de. [148.251.136.42]) by smtp.gmail.com with ESMTPSA id r29sm10349378wra.71.2017.10.27.02.31.49 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 27 Oct 2017 02:31:49 -0700 (PDT) From: Yao Qi X-Google-Original-From: Yao Qi To: gdb-patches@sourceware.org Subject: [PATCH 3/8] New method regcache::assert_regnum Date: Fri, 27 Oct 2017 10:31:37 +0100 Message-Id: <1509096702-12202-4-git-send-email-yao.qi@linaro.org> In-Reply-To: <1509096702-12202-1-git-send-email-yao.qi@linaro.org> References: <1509096702-12202-1-git-send-email-yao.qi@linaro.org> X-IsSubscribed: yes class regcache has some methods checking the range of register number, this patch is to move it in a new method assert_regnum. gdb: 2017-10-19 Yao Qi * regcache.c (regcache::assert_regnum): New method. (regcache::invalidate): Call assert_regnum. (regcache::raw_update): Likewise. (regcache::raw_write): Likewise. (regcache::raw_read_part): Likewise. (regcache::raw_write_part): Likewise. (regcache::raw_supply): Likewise. (regcache::raw_supply_integer): Likewise. (regcache::raw_supply_zeroed): Likewise. (regcache::raw_collect): Likewise. (regcache::raw_collect_integer): Likewise. * regcache.h (regcache::assert_regnum): Declare. --- gdb/regcache.c | 31 ++++++++++++++++++------------- gdb/regcache.h | 3 +++ 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/gdb/regcache.c b/gdb/regcache.c index 0d3fe3d..0aee934 100644 --- a/gdb/regcache.c +++ b/gdb/regcache.c @@ -393,12 +393,17 @@ regcache_invalidate (struct regcache *regcache, int regnum) void regcache::invalidate (int regnum) { - gdb_assert (regnum >= 0); gdb_assert (!m_readonly_p); - gdb_assert (regnum < m_descr->nr_raw_registers); + assert_regnum (regnum); m_register_status[regnum] = REG_UNKNOWN; } +void +regcache::assert_regnum (int regnum) const +{ + gdb_assert (regnum >= 0 && regnum < m_descr->nr_raw_registers); +} + /* Global structure containing the current regcache. */ /* NOTE: this is a write-through cache. There is no "dirty" bit for @@ -546,7 +551,7 @@ regcache_raw_update (struct regcache *regcache, int regnum) void regcache::raw_update (int regnum) { - gdb_assert (regnum >= 0 && regnum < m_descr->nr_raw_registers); + assert_regnum (regnum); /* Make certain that the register cache is up-to-date with respect to the current thread. This switching shouldn't be necessary @@ -600,7 +605,7 @@ regcache::raw_read (int regnum, T *val) gdb_byte *buf; enum register_status status; - gdb_assert (regnum >= 0 && regnum < m_descr->nr_raw_registers); + assert_regnum (regnum); buf = (gdb_byte *) alloca (m_descr->sizeof_register[regnum]); status = raw_read (regnum, buf); if (status == REG_VALID) @@ -633,7 +638,7 @@ regcache::raw_write (int regnum, T val) { gdb_byte *buf; - gdb_assert (regnum >=0 && regnum < m_descr->nr_raw_registers); + assert_regnum (regnum); buf = (gdb_byte *) alloca (m_descr->sizeof_register[regnum]); store_integer (buf, m_descr->sizeof_register[regnum], gdbarch_byte_order (m_descr->gdbarch), val); @@ -844,7 +849,7 @@ regcache::raw_write (int regnum, const gdb_byte *buf) { gdb_assert (buf != NULL); - gdb_assert (regnum >= 0 && regnum < m_descr->nr_raw_registers); + assert_regnum (regnum); gdb_assert (!m_readonly_p); /* On the sparc, writing %g0 is a no-op, so we don't even want to @@ -953,7 +958,7 @@ regcache_raw_read_part (struct regcache *regcache, int regnum, enum register_status regcache::raw_read_part (int regnum, int offset, int len, gdb_byte *buf) { - gdb_assert (regnum >= 0 && regnum < m_descr->nr_raw_registers); + assert_regnum (regnum); return xfer_part (regnum, offset, len, buf, NULL, true); } @@ -968,7 +973,7 @@ void regcache::raw_write_part (int regnum, int offset, int len, const gdb_byte *buf) { - gdb_assert (regnum >= 0 && regnum < m_descr->nr_raw_registers); + assert_regnum (regnum); xfer_part (regnum, offset, len, NULL, buf, true); } @@ -1017,7 +1022,7 @@ regcache::raw_supply (int regnum, const void *buf) void *regbuf; size_t size; - gdb_assert (regnum >= 0 && regnum < m_descr->nr_raw_registers); + assert_regnum (regnum); gdb_assert (!m_readonly_p); regbuf = register_buffer (regnum); @@ -1052,7 +1057,7 @@ regcache::raw_supply_integer (int regnum, const gdb_byte *addr, int addr_len, gdb_byte *regbuf; size_t regsize; - gdb_assert (regnum >= 0 && regnum < m_descr->nr_raw_registers); + assert_regnum (regnum); gdb_assert (!m_readonly_p); regbuf = register_buffer (regnum); @@ -1073,7 +1078,7 @@ regcache::raw_supply_zeroed (int regnum) void *regbuf; size_t size; - gdb_assert (regnum >= 0 && regnum < m_descr->nr_raw_registers); + assert_regnum (regnum); gdb_assert (!m_readonly_p); regbuf = register_buffer (regnum); @@ -1099,7 +1104,7 @@ regcache::raw_collect (int regnum, void *buf) const size_t size; gdb_assert (buf != NULL); - gdb_assert (regnum >= 0 && regnum < m_descr->nr_raw_registers); + assert_regnum (regnum); regbuf = register_buffer (regnum); size = m_descr->sizeof_register[regnum]; @@ -1124,7 +1129,7 @@ regcache::raw_collect_integer (int regnum, gdb_byte *addr, int addr_len, const gdb_byte *regbuf; size_t regsize; - gdb_assert (regnum >= 0 && regnum < m_descr->nr_raw_registers); + assert_regnum (regnum); regbuf = register_buffer (regnum); regsize = m_descr->sizeof_register[regnum]; diff --git a/gdb/regcache.h b/gdb/regcache.h index 0eea042..6fb790d 100644 --- a/gdb/regcache.h +++ b/gdb/regcache.h @@ -358,6 +358,9 @@ private: int regnum, const void *in_buf, void *out_buf, size_t size) const; + /* Assert on the range of REGNUM. */ + void assert_regnum (int regnum) const; + struct regcache_descr *m_descr; /* The address space of this register cache (for registers where it