public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Xi Ruoyao <xry111@xry111.site>
To: Tiezhu Yang <yangtiezhu@loongson.cn>, gdb-patches@sourceware.org
Subject: [PATCH v2] gdb: LoongArch: add orig_a0 into register set
Date: Mon, 04 Jul 2022 14:20:00 +0800	[thread overview]
Message-ID: <95fc996abd9583348184a81cdd9bc5760fba17e1.camel@xry111.site> (raw)
In-Reply-To: <a7068939-c775-d5ea-e391-49a7cff208d2@loongson.cn>

Hi Tiezhu,

Thanks for the review.

On Mon, 2022-07-04 at 10:50 +0800, Tiezhu Yang wrote:

> The related code in gdb/loongarch-linux-nat.c also need to be
> modified.

Done in v2.

> Additionally, we know that the LoongArch upstream Linux kernel can not
> actually be used before efistub, irqchip and pci are merged [0].
> 
> [0] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=c6f2f3e2c80e
> 
> So I think we can modify the patch subject and the commit message like
> this:

Done in v2, with some modification.

Patch v2 follows here:

-- >8 --


The basic support for LoongArch has been merged into the upstream Linux
kernel since 5.19-rc1 on June 5, 2022.  This commit adds orig_a0 which
is added into struct user_pt_regs [1] to match the upstream kernel, and
then the upstream GDB will work with the upstream kernel.

Note that orig_a0 was added into struct user_pt_regs in the development
cycle for merging LoongArch port into the upstream Linux kernel, so
earlier kernels (notably, the product kernel with version 4.19 used in
distros like UOS and Loongnix) don't have it.  Inspect
arch/loongarch/include/uapi/asm/ptrace.h in the kernel tree to make sure.
To build upstream GDB for a kernel lacking orig_a0, it's necessary to
revert this commit locally.

[1]: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/arch/loongarch/include/uapi/asm/ptrace.h#n24

Signed-off-by: Xi Ruoyao <xry111@xry111.site>
---
 gdb/features/loongarch/base32.c   | 1 +
 gdb/features/loongarch/base32.xml | 1 +
 gdb/features/loongarch/base64.c   | 1 +
 gdb/features/loongarch/base64.xml | 1 +
 gdb/loongarch-linux-nat.c         | 2 ++
 gdb/loongarch-linux-tdep.c        | 8 ++++++++
 gdb/loongarch-tdep.c              | 1 +
 gdb/loongarch-tdep.h              | 7 ++++---
 8 files changed, 19 insertions(+), 3 deletions(-)

diff --git a/gdb/features/loongarch/base32.c b/gdb/features/loongarch/base32.c
index 7105c152aed..3fb35ef2d05 100644
--- a/gdb/features/loongarch/base32.c
+++ b/gdb/features/loongarch/base32.c
@@ -41,6 +41,7 @@ create_feature_loongarch_base32 (struct target_desc *result, long regnum)
   tdesc_create_reg (feature, "r29", regnum++, 1, "general", 32, "uint32");
   tdesc_create_reg (feature, "r30", regnum++, 1, "general", 32, "uint32");
   tdesc_create_reg (feature, "r31", regnum++, 1, "general", 32, "uint32");
+  tdesc_create_reg (feature, "orig_a0", regnum++, 1, "general", 32, "uint32");
   tdesc_create_reg (feature, "pc", regnum++, 1, "general", 32, "code_ptr");
   tdesc_create_reg (feature, "badv", regnum++, 1, "general", 32, "code_ptr");
   return regnum;
diff --git a/gdb/features/loongarch/base32.xml b/gdb/features/loongarch/base32.xml
index 5b00f8a8d37..af47bbd3da4 100644
--- a/gdb/features/loongarch/base32.xml
+++ b/gdb/features/loongarch/base32.xml
@@ -39,6 +39,7 @@
   <reg name="r29" bitsize="32" type="uint32" group="general"/>
   <reg name="r30" bitsize="32" type="uint32" group="general"/>
   <reg name="r31" bitsize="32" type="uint32" group="general"/>
+  <reg name="orig_a0" bitsize="32" type="uint32" group="general"/>
   <reg name="pc" bitsize="32" type="code_ptr" group="general"/>
   <reg name="badv" bitsize="32" type="code_ptr" group="general"/>
 </feature>
diff --git a/gdb/features/loongarch/base64.c b/gdb/features/loongarch/base64.c
index 63eee024554..d84d4256294 100644
--- a/gdb/features/loongarch/base64.c
+++ b/gdb/features/loongarch/base64.c
@@ -41,6 +41,7 @@ create_feature_loongarch_base64 (struct target_desc *result, long regnum)
   tdesc_create_reg (feature, "r29", regnum++, 1, "general", 64, "uint64");
   tdesc_create_reg (feature, "r30", regnum++, 1, "general", 64, "uint64");
   tdesc_create_reg (feature, "r31", regnum++, 1, "general", 64, "uint64");
+  tdesc_create_reg (feature, "orig_a0", regnum++, 1, "general", 64, "uint64");
   tdesc_create_reg (feature, "pc", regnum++, 1, "general", 64, "code_ptr");
   tdesc_create_reg (feature, "badv", regnum++, 1, "general", 64, "code_ptr");
   return regnum;
diff --git a/gdb/features/loongarch/base64.xml b/gdb/features/loongarch/base64.xml
index bef91e50dd7..2d8a1f6b734 100644
--- a/gdb/features/loongarch/base64.xml
+++ b/gdb/features/loongarch/base64.xml
@@ -39,6 +39,7 @@
   <reg name="r29" bitsize="64" type="uint64" group="general"/>
   <reg name="r30" bitsize="64" type="uint64" group="general"/>
   <reg name="r31" bitsize="64" type="uint64" group="general"/>
+  <reg name="orig_a0" bitsize="64" type="uint64" group="general"/>
   <reg name="pc" bitsize="64" type="code_ptr" group="general"/>
   <reg name="badv" bitsize="64" type="code_ptr" group="general"/>
 </feature>
diff --git a/gdb/loongarch-linux-nat.c b/gdb/loongarch-linux-nat.c
index c341e7199e3..1fd1af6c99f 100644
--- a/gdb/loongarch-linux-nat.c
+++ b/gdb/loongarch-linux-nat.c
@@ -53,6 +53,7 @@ fetch_gregs_from_thread (struct regcache *regcache, int regnum, pid_t tid)
   elf_gregset_t regset;
 
   if (regnum == -1 || (regnum >= 0 && regnum < 32)
+      || regnum == LOONGARCH_ORIG_A0_REGNUM
       || regnum == LOONGARCH_PC_REGNUM
       || regnum == LOONGARCH_BADV_REGNUM)
   {
@@ -78,6 +79,7 @@ store_gregs_to_thread (struct regcache *regcache, int regnum, pid_t tid)
   elf_gregset_t regset;
 
   if (regnum == -1 || (regnum >= 0 && regnum < 32)
+      || regnum == LOONGARCH_ORIG_A0_REGNUM
       || regnum == LOONGARCH_PC_REGNUM
       || regnum == LOONGARCH_BADV_REGNUM)
   {
diff --git a/gdb/loongarch-linux-tdep.c b/gdb/loongarch-linux-tdep.c
index 21fc67f9323..1076e935997 100644
--- a/gdb/loongarch-linux-tdep.c
+++ b/gdb/loongarch-linux-tdep.c
@@ -48,6 +48,9 @@ loongarch_supply_gregset (const struct regset *regset,
 	  regcache->raw_supply (i, (const void *) buf);
 	}
 
+      buf = (const gdb_byte*) gprs + regsize * LOONGARCH_ORIG_A0_REGNUM;
+      regcache->raw_supply (LOONGARCH_ORIG_A0_REGNUM, (const void *) buf);
+
       buf = (const gdb_byte*) gprs + regsize * LOONGARCH_PC_REGNUM;
       regcache->raw_supply (LOONGARCH_PC_REGNUM, (const void *) buf);
 
@@ -57,6 +60,7 @@ loongarch_supply_gregset (const struct regset *regset,
   else if (regnum == 0)
     regcache->raw_supply_zeroed (0);
   else if ((regnum > 0 && regnum < 32)
+	   || regnum == LOONGARCH_ORIG_A0_REGNUM
 	   || regnum == LOONGARCH_PC_REGNUM
 	   || regnum == LOONGARCH_BADV_REGNUM)
     {
@@ -83,6 +87,9 @@ loongarch_fill_gregset (const struct regset *regset,
 	  regcache->raw_collect (i, (void *) buf);
 	}
 
+      buf = (gdb_byte *) gprs + regsize * LOONGARCH_ORIG_A0_REGNUM;
+      regcache->raw_collect (LOONGARCH_ORIG_A0_REGNUM, (void *) buf);
+
       buf = (gdb_byte *) gprs + regsize * LOONGARCH_PC_REGNUM;
       regcache->raw_collect (LOONGARCH_PC_REGNUM, (void *) buf);
 
@@ -90,6 +97,7 @@ loongarch_fill_gregset (const struct regset *regset,
       regcache->raw_collect (LOONGARCH_BADV_REGNUM, (void *) buf);
     }
   else if ((regnum >= 0 && regnum < 32)
+	   || regnum == LOONGARCH_ORIG_A0_REGNUM
 	   || regnum == LOONGARCH_PC_REGNUM
 	   || regnum == LOONGARCH_BADV_REGNUM)
     {
diff --git a/gdb/loongarch-tdep.c b/gdb/loongarch-tdep.c
index f2f4e3be909..76480ce6c94 100644
--- a/gdb/loongarch-tdep.c
+++ b/gdb/loongarch-tdep.c
@@ -576,6 +576,7 @@ loongarch_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
   for (int i = 0; i < 32; i++)
     valid_p &= tdesc_numbered_register (feature_cpu, tdesc_data.get (), regnum++,
 					loongarch_r_normal_name[i] + 1);
+  valid_p &= tdesc_numbered_register (feature_cpu, tdesc_data.get (), regnum++, "orig_a0");
   valid_p &= tdesc_numbered_register (feature_cpu, tdesc_data.get (), regnum++, "pc");
   valid_p &= tdesc_numbered_register (feature_cpu, tdesc_data.get (), regnum++, "badv");
   if (!valid_p)
diff --git a/gdb/loongarch-tdep.h b/gdb/loongarch-tdep.h
index 54b34af1d66..acf0191fd65 100644
--- a/gdb/loongarch-tdep.h
+++ b/gdb/loongarch-tdep.h
@@ -35,9 +35,10 @@ enum
   LOONGARCH_A0_REGNUM = 4,		/* First Argument/Return Value.  */
   LOONGARCH_A7_REGNUM = 11,		/* Seventh Argument/Syscall Number.  */
   LOONGARCH_FP_REGNUM = 22,		/* Frame Pointer.  */
-  LOONGARCH_PC_REGNUM = 32,		/* Program Counter.  */
-  LOONGARCH_BADV_REGNUM = 33,		/* Bad Vaddr for Addressing Exception.  */
-  LOONGARCH_LINUX_NUM_GREGSET = 45,	/* 32 GPR, PC, BADV, RESERVED 11.  */
+  LOONGARCH_ORIG_A0_REGNUM = 32,	/* Syscall's original arg0.  */
+  LOONGARCH_PC_REGNUM = 33,		/* Program Counter.  */
+  LOONGARCH_BADV_REGNUM = 34,		/* Bad Vaddr for Addressing Exception.  */
+  LOONGARCH_LINUX_NUM_GREGSET = 45,	/* 32 GPR, ORIG_A0, PC, BADV, RESERVED 10.  */
 };
 
 /* Register set definitions.  */
-- 
2.37.0



  reply	other threads:[~2022-07-04  6:20 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-03  3:58 [PATCH] " Xi Ruoyao
2022-07-04  2:50 ` Tiezhu Yang
2022-07-04  6:20   ` Xi Ruoyao [this message]
2022-07-05 14:38     ` [PATCH v2] " Tiezhu Yang

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=95fc996abd9583348184a81cdd9bc5760fba17e1.camel@xry111.site \
    --to=xry111@xry111.site \
    --cc=gdb-patches@sourceware.org \
    --cc=yangtiezhu@loongson.cn \
    /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).