public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH 0/2] gdb: LoongArch: Modify the info reg command
@ 2023-02-16 11:20 Hui Li
  2023-02-16 11:20 ` [PATCH 1/2] gdb: LoongArch: Modify the result of " Hui Li
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Hui Li @ 2023-02-16 11:20 UTC (permalink / raw)
  To: gdb-patches; +Cc: Hui Li


Hui Li (2):
  gdb: LoongArch: Modify the result of the info reg command
  gdb: LoongArch: Support reg aliases in info reg command

 gdb/loongarch-tdep.c | 60 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 60 insertions(+)

-- 
2.38.0


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 1/2] gdb: LoongArch: Modify the result of the info reg command
  2023-02-16 11:20 [PATCH 0/2] gdb: LoongArch: Modify the info reg command Hui Li
@ 2023-02-16 11:20 ` Hui Li
  2023-02-16 11:20 ` [PATCH 2/2] gdb: LoongArch: Support reg aliases in " Hui Li
  2023-02-23 12:38 ` [PATCH 0/2] gdb: LoongArch: Modify the " Tiezhu Yang
  2 siblings, 0 replies; 4+ messages in thread
From: Hui Li @ 2023-02-16 11:20 UTC (permalink / raw)
  To: gdb-patches; +Cc: Hui Li

The "info register" command should only display general registers,
but it shows the information of all registers in the current code,
add loongarch_register_reggroup_p() so that we can get the expected
result.

Signed-off-by: Hui Li <lihui@loongson.cn>
---
 gdb/loongarch-tdep.c | 39 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 39 insertions(+)

diff --git a/gdb/loongarch-tdep.c b/gdb/loongarch-tdep.c
index 5f7a8a00ce7..67ea5494d90 100644
--- a/gdb/loongarch-tdep.c
+++ b/gdb/loongarch-tdep.c
@@ -24,6 +24,7 @@
 #include "frame-unwind.h"
 #include "gdbcore.h"
 #include "loongarch-tdep.h"
+#include "reggroups.h"
 #include "target.h"
 #include "target-descriptions.h"
 #include "trad-frame.h"
@@ -1433,6 +1434,43 @@ loongarch_find_default_target_description (const struct gdbarch_info info)
   return loongarch_lookup_target_description (features);
 }
 
+static int
+loongarch_register_reggroup_p (struct gdbarch *gdbarch, int regnum,
+			       const struct reggroup *group)
+{
+  if (gdbarch_register_name (gdbarch, regnum) == NULL
+      || *gdbarch_register_name (gdbarch, regnum) == '\0')
+    return 0;
+
+  int raw_p = regnum < gdbarch_num_regs (gdbarch);
+
+  if (group == save_reggroup || group == restore_reggroup)
+    return raw_p;
+
+  if (group == all_reggroup)
+    return 1;
+
+  if (0 <= regnum && regnum <= LOONGARCH_BADV_REGNUM)
+    return group == general_reggroup;
+
+  /* Only ORIG_A0, PC, BADV in general_reggroup */
+  if (group == general_reggroup)
+    return 0;
+
+  if (LOONGARCH_FIRST_FP_REGNUM <= regnum && regnum <= LOONGARCH_FCSR_REGNUM)
+    return group == float_reggroup;
+
+  /* Only $fx / $fccx / $fcsr in float_reggroup */
+  if (group == float_reggroup)
+    return 0;
+
+  int ret = tdesc_register_in_reggroup_p (gdbarch, regnum, group);
+  if (ret != -1)
+    return ret;
+
+  return default_register_reggroup_p (gdbarch, regnum, group);
+}
+
 /* Initialize the current architecture based on INFO  */
 
 static struct gdbarch *
@@ -1586,6 +1624,7 @@ loongarch_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
 
   /* Hook in OS ABI-specific overrides, if they have been registered.  */
   gdbarch_init_osabi (info, gdbarch);
+  set_gdbarch_register_reggroup_p (gdbarch, loongarch_register_reggroup_p);
 
   return gdbarch;
 }
-- 
2.38.0


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 2/2] gdb: LoongArch: Support reg aliases in info reg command
  2023-02-16 11:20 [PATCH 0/2] gdb: LoongArch: Modify the info reg command 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
  2023-02-23 12:38 ` [PATCH 0/2] gdb: LoongArch: Modify the " Tiezhu Yang
  2 siblings, 0 replies; 4+ messages in thread
From: Hui Li @ 2023-02-16 11:20 UTC (permalink / raw)
  To: gdb-patches; +Cc: Hui Li

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


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 0/2] gdb: LoongArch: Modify the info reg command
  2023-02-16 11:20 [PATCH 0/2] gdb: LoongArch: Modify the info reg command Hui Li
  2023-02-16 11:20 ` [PATCH 1/2] gdb: LoongArch: Modify the result of " Hui Li
  2023-02-16 11:20 ` [PATCH 2/2] gdb: LoongArch: Support reg aliases in " Hui Li
@ 2023-02-23 12:38 ` Tiezhu Yang
  2 siblings, 0 replies; 4+ messages in thread
From: Tiezhu Yang @ 2023-02-23 12:38 UTC (permalink / raw)
  To: Hui Li, gdb-patches



On 02/16/2023 07:20 PM, Hui Li wrote:
>
> Hui Li (2):
>   gdb: LoongArch: Modify the result of the info reg command
>   gdb: LoongArch: Support reg aliases in info reg command
>
>  gdb/loongarch-tdep.c | 60 ++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 60 insertions(+)
>

Looks good to me, tested on LoongArch, pushed.

Thanks,
Tiezhu


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-02-23 12:38 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-16 11:20 [PATCH 0/2] gdb: LoongArch: Modify the info reg command Hui Li
2023-02-16 11:20 ` [PATCH 1/2] gdb: LoongArch: Modify the result of " Hui Li
2023-02-16 11:20 ` [PATCH 2/2] gdb: LoongArch: Support reg aliases in " Hui Li
2023-02-23 12:38 ` [PATCH 0/2] gdb: LoongArch: Modify the " Tiezhu Yang

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).