From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ed1-x544.google.com (mail-ed1-x544.google.com [IPv6:2a00:1450:4864:20::544]) by sourceware.org (Postfix) with ESMTPS id D5146393BC14 for ; Mon, 7 Dec 2020 16:37:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org D5146393BC14 Received: by mail-ed1-x544.google.com with SMTP id dk8so11522002edb.1 for ; Mon, 07 Dec 2020 08:37:48 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=kd3BKgmLg0/NR366bsevQ+WI3563SVsPuGGOn0fDfOs=; b=O7U50s7hZjXqSSvhRtQ1UN7VXZA/ox3E2hTMC9pGPTZZqTFFktGN8/WmnoLIApQwqD bVADwGjPepmacv9326l4k2kwjM+gQYRNkYBuv2fEGLmcxaBbnuVcqxbQUrZXZmGg7SXj HTcOzvAzREnudNR9XoQVGjKePrF92Rw+EOR+cTmrRXok3wRQDxpG4woIGkZpZNq1FlWF EzSxfq98MPZe6xfd2yYj9YL8b6yQOf0bHLzeo8sp7UH+4HoIRTQx3U1oX2OCxYhQcEAF AsRWKpxB4jCi5DqBPF28vGr3loT0Fm1LGxi4ywa85JsNOCD1O+qXiMZXZTyzmFvjC+t7 zomA== X-Gm-Message-State: AOAM533c757r7WejdRbBtfyZioRaz8DTLOwumlsJCOUslzQl2ugFNAnG fdq23wRIq7TUokaTM/JuTLNF1+vTPq+i1MewYYE= X-Google-Smtp-Source: ABdhPJziOwygNalxg43UhKPBITlTlppVyRg4xHtOg1h3FdGFi+irhmpnCg19XLOAawBpTa8+lrPRjQ== X-Received: by 2002:a05:6402:1597:: with SMTP id c23mr11141190edv.212.1607359067578; Mon, 07 Dec 2020 08:37:47 -0800 (PST) Received: from atlantis.home ([2a03:1b20:3:f011::6d]) by smtp.gmail.com with ESMTPSA id a10sm12052682ejk.92.2020.12.07.08.37.46 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 07 Dec 2020 08:37:46 -0800 (PST) From: Shahab Vahedi To: gdb-patches@sourceware.org Cc: Shahab Vahedi , Shahab Vahedi , Tom Tromey , Francois Bedard Subject: [PATCH v2 1/2] arc: Take into account the REGNUM in supply/collect gdb hooks Date: Mon, 7 Dec 2020 17:37:39 +0100 Message-Id: <20201207163740.9128-2-shahab.vahedi@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201207163740.9128-1-shahab.vahedi@gmail.com> References: <20201112134811.9074-1-shahab.vahedi@gmail.com> <20201207163740.9128-1-shahab.vahedi@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-11.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 07 Dec 2020 16:37:50 -0000 From: Shahab Vahedi All the arc_linux_supply_*() target operations and the arc_linux_collect_v2_regset() in arc-linux-tdep.c were supplying/collecting all the registers in regcache as if the REGNUM was set to -1. The more efficient behavior is to examine the REGNUM and act accordingly. That is what this patch does. gdb/ChangeLog: * arc-linux-tdep.c (supply_register): New. (arc_linux_supply_gregset, arc_linux_supply_v2_regset, arc_linux_collect_v2_regset): Consider REGNUM. --- gdb/arc-linux-tdep.c | 41 ++++++++++++++++++++++++++++++++--------- 1 file changed, 32 insertions(+), 9 deletions(-) diff --git a/gdb/arc-linux-tdep.c b/gdb/arc-linux-tdep.c index ad68f494b3c..eca8d626084 100644 --- a/gdb/arc-linux-tdep.c +++ b/gdb/arc-linux-tdep.c @@ -460,6 +460,18 @@ arc_linux_skip_solib_resolver (struct gdbarch *gdbarch, CORE_ADDR pc) } } +/* Populate REGCACHE with register REGNUM from BUF. */ + +static void +supply_register (struct regcache *regcache, int regnum, const gdb_byte *buf) +{ + /* Skip non-existing registers. */ + if ((arc_linux_core_reg_offsets[regnum] == ARC_OFFSET_NO_REGISTER)) + return; + + regcache->raw_supply (regnum, buf + arc_linux_core_reg_offsets[regnum]); +} + void arc_linux_supply_gregset (const struct regset *regset, struct regcache *regcache, @@ -470,9 +482,14 @@ arc_linux_supply_gregset (const struct regset *regset, const bfd_byte *buf = (const bfd_byte *) gregs; - for (int reg = 0; reg <= ARC_LAST_REGNUM; reg++) - if (arc_linux_core_reg_offsets[reg] != ARC_OFFSET_NO_REGISTER) - regcache->raw_supply (reg, buf + arc_linux_core_reg_offsets[reg]); + /* regnum == -1 means writing all the registers. */ + if (regnum == -1) + for (int reg = 0; reg <= ARC_LAST_REGNUM; reg++) + supply_register (regcache, reg, buf); + else if (regnum <= ARC_LAST_REGNUM) + supply_register (regcache, regnum, buf); + else + gdb_assert_not_reached ("Invalid regnum in arc_linux_supply_gregset."); } void @@ -483,9 +500,12 @@ arc_linux_supply_v2_regset (const struct regset *regset, const bfd_byte *buf = (const bfd_byte *) v2_regs; /* user_regs_arcv2 is defined in linux arch/arc/include/uapi/asm/ptrace.h. */ - regcache->raw_supply (ARC_R30_REGNUM, buf); - regcache->raw_supply (ARC_R58_REGNUM, buf + REGOFF (1)); - regcache->raw_supply (ARC_R59_REGNUM, buf + REGOFF (2)); + if (regnum == -1 || regnum == ARC_R30_REGNUM) + regcache->raw_supply (ARC_R30_REGNUM, buf); + if (regnum == -1 || regnum == ARC_R58_REGNUM) + regcache->raw_supply (ARC_R58_REGNUM, buf + REGOFF (1)); + if (regnum == -1 || regnum == ARC_R59_REGNUM) + regcache->raw_supply (ARC_R59_REGNUM, buf + REGOFF (2)); } /* Populate BUF with register REGNUM from the REGCACHE. */ @@ -543,9 +563,12 @@ arc_linux_collect_v2_regset (const struct regset *regset, { bfd_byte *buf = (bfd_byte *) v2_regs; - regcache->raw_collect (ARC_R30_REGNUM, buf); - regcache->raw_collect (ARC_R58_REGNUM, buf + REGOFF (1)); - regcache->raw_collect (ARC_R59_REGNUM, buf + REGOFF (2)); + if (regnum == -1 || regnum == ARC_R30_REGNUM) + regcache->raw_collect (ARC_R30_REGNUM, buf); + if (regnum == -1 || regnum == ARC_R58_REGNUM) + regcache->raw_collect (ARC_R58_REGNUM, buf + REGOFF (1)); + if (regnum == -1 || regnum == ARC_R59_REGNUM) + regcache->raw_collect (ARC_R59_REGNUM, buf + REGOFF (2)); } /* Linux regset definitions. */ -- 2.29.2