From: Hui Li <lihui@loongson.cn>
To: gdb-patches@sourceware.org
Cc: Hui Li <lihui@loongson.cn>
Subject: [PATCH 2/2] gdb: LoongArch: Support reg aliases in info reg command
Date: Thu, 16 Feb 2023 19:20:20 +0800 [thread overview]
Message-ID: <20230216112020.25610-3-lihui@loongson.cn> (raw)
In-Reply-To: <20230216112020.25610-1-lihui@loongson.cn>
According to LoongArch ELF ABI specification [1], support the register
aliases in "info register" command.
Without this patch:
```
(gdb) info reg a0
Invalid register `a0'
```
With this patch:
```
(gdb) info reg a0
a0 0x1 1
```
[1] https://loongson.github.io/LoongArch-Documentation/LoongArch-ELF-ABI-EN.html#_register_convention
Signed-off-by: Hui Li <lihui@loongson.cn>
---
gdb/loongarch-tdep.c | 21 +++++++++++++++++++++
1 file changed, 21 insertions(+)
diff --git a/gdb/loongarch-tdep.c b/gdb/loongarch-tdep.c
index 67ea5494d90..f5ddad0ba65 100644
--- a/gdb/loongarch-tdep.c
+++ b/gdb/loongarch-tdep.c
@@ -387,6 +387,14 @@ loongarch_software_single_step (struct regcache *regcache)
return {next_pc};
}
+/* Callback function for user_reg_add. */
+
+static struct value *
+value_of_loongarch_user_reg (frame_info_ptr frame, const void *baton)
+{
+ return value_of_register ((long long) baton, frame);
+}
+
/* Implement the frame_align gdbarch method. */
static CORE_ADDR
@@ -1589,6 +1597,19 @@ loongarch_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
info.target_desc = tdesc;
info.tdesc_data = tdesc_data.get ();
+ for (int i = 0; i < ARRAY_SIZE (loongarch_r_lp64_name); ++i)
+ if (loongarch_r_lp64_name[i][0] != '\0')
+ user_reg_add (gdbarch, loongarch_r_lp64_name[i] + 1,
+ value_of_loongarch_user_reg, (void *) (size_t) i);
+
+ for (int i = 0; i < ARRAY_SIZE (loongarch_f_lp64_name); ++i)
+ {
+ if (loongarch_f_lp64_name[i][0] != '\0')
+ user_reg_add (gdbarch, loongarch_f_lp64_name[i] + 1,
+ value_of_loongarch_user_reg,
+ (void *) (size_t) (LOONGARCH_FIRST_FP_REGNUM + i));
+ }
+
/* Information about registers. */
set_gdbarch_num_regs (gdbarch, regnum);
set_gdbarch_sp_regnum (gdbarch, LOONGARCH_SP_REGNUM);
--
2.38.0
next prev parent reply other threads:[~2023-02-16 11:20 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-16 11:20 [PATCH 0/2] gdb: LoongArch: Modify the " Hui Li
2023-02-16 11:20 ` [PATCH 1/2] gdb: LoongArch: Modify the result of " Hui Li
2023-02-16 11:20 ` Hui Li [this message]
2023-02-23 12:38 ` [PATCH 0/2] gdb: LoongArch: Modify " 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=20230216112020.25610-3-lihui@loongson.cn \
--to=lihui@loongson.cn \
--cc=gdb-patches@sourceware.org \
/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).