public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Shahab Vahedi <shahab.vahedi@gmail.com>
To: gdb-patches@sourceware.org
Cc: Shahab Vahedi <shahab.vahedi@gmail.com>,
	Shahab Vahedi <shahab@synopsys.com>,
	Anton Kolesov <anton.kolesov@synopsys.com>,
	Francois Bedard <fbedard@synopsys.com>
Subject: [PATCH 1/2] arc: Take into account the REGNUM in supply/collect gdb hooks
Date: Thu, 12 Nov 2020 14:48:10 +0100	[thread overview]
Message-ID: <20201112134811.9074-2-shahab.vahedi@gmail.com> (raw)
In-Reply-To: <20201112134811.9074-1-shahab.vahedi@gmail.com>

From: Shahab Vahedi <shahab@synopsys.com>

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 b8ea2194934..e8e5461bc34 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.  */
@@ -539,9 +559,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


  reply	other threads:[~2020-11-12 13:48 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-12 13:48 [PATCH 0/2] Add native GNU/Linux support for ARC in GDB Shahab Vahedi
2020-11-12 13:48 ` Shahab Vahedi [this message]
2020-11-12 17:33   ` [PATCH 1/2] arc: Take into account the REGNUM in supply/collect gdb hooks Tom Tromey
2020-11-12 17:36     ` Tom Tromey
2020-11-12 13:48 ` [PATCH 2/2] gdb: Add native support for ARC in GNU/Linux Shahab Vahedi
2020-11-12 18:03   ` Tom Tromey
2020-12-07 16:37 ` [PATCH v2 0/2] Add native GNU/Linux support for ARC in GDB Shahab Vahedi
2020-12-07 16:37   ` [PATCH v2 1/2] arc: Take into account the REGNUM in supply/collect gdb hooks Shahab Vahedi
2020-12-10 19:11     ` Tom Tromey
2020-12-07 16:37   ` [PATCH v2 2/2] gdb: Add native support for ARC in GNU/Linux Shahab Vahedi
2020-12-10 19:13     ` Tom Tromey
2020-12-10 19:33       ` Shahab Vahedi
2020-12-22 11:21 ` [PUSHED v2 1/2] arc: Take into account the REGNUM in supply/collect gdb hooks Shahab Vahedi
2020-12-22 11:21   ` [PUSHED v2 2/2] gdb: Add native support for ARC in GNU/Linux Shahab Vahedi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201112134811.9074-2-shahab.vahedi@gmail.com \
    --to=shahab.vahedi@gmail.com \
    --cc=anton.kolesov@synopsys.com \
    --cc=fbedard@synopsys.com \
    --cc=gdb-patches@sourceware.org \
    --cc=shahab@synopsys.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).