public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PUSHED OBV] Fix loongarch_iterate_over_regset_sections for non-native targets.
@ 2022-05-23 18:15 John Baldwin
  2022-05-24  9:20 ` Tiezhu Yang
  0 siblings, 1 reply; 3+ messages in thread
From: John Baldwin @ 2022-05-23 18:15 UTC (permalink / raw)
  To: gdb-patches

Define a constant for the number of registers stored in a register set
and use this with register_size to compute the size of the
general-purpose register set in core dumps.

This also fixes the build on hosts such as FreeBSD that do not define
an elf_gregset_t type.
---
 gdb/loongarch-linux-tdep.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/gdb/loongarch-linux-tdep.c b/gdb/loongarch-linux-tdep.c
index f13756dd003..bbb43abe13f 100644
--- a/gdb/loongarch-linux-tdep.c
+++ b/gdb/loongarch-linux-tdep.c
@@ -29,6 +29,11 @@
 #include "trad-frame.h"
 #include "tramp-frame.h"
 
+/* The general-purpose regset consists of 32 R registers, plus PC,
+   and BADV registers.  */
+
+#define LOONGARCH_LINUX_NUM_GREGSET	(34)
+
 /* Unpack an elf_gregset_t into GDB's register cache.  */
 
 static void
@@ -172,8 +177,13 @@ loongarch_iterate_over_regset_sections (struct gdbarch *gdbarch,
 					void *cb_data,
 					const struct regcache *regcache)
 {
-  cb (".reg", sizeof (elf_gregset_t), sizeof (elf_gregset_t),
-      &loongarch_gregset, NULL, cb_data);
+  loongarch_gdbarch_tdep *tdep
+    = (loongarch_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  auto regs = tdep->regs;
+  int regsize = register_size (gdbarch, regs.r);
+
+  cb (".reg", LOONGARCH_LINUX_NUM_GREGSET * regsize,
+      LOONGARCH_LINUX_NUM_GREGSET * regsize, &loongarch_gregset, NULL, cb_data);
 }
 
 /* Initialize LoongArch Linux ABI info.  */
-- 
2.36.1


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

* Re: [PUSHED OBV] Fix loongarch_iterate_over_regset_sections for non-native targets.
  2022-05-23 18:15 [PUSHED OBV] Fix loongarch_iterate_over_regset_sections for non-native targets John Baldwin
@ 2022-05-24  9:20 ` Tiezhu Yang
  2022-05-24 16:47   ` John Baldwin
  0 siblings, 1 reply; 3+ messages in thread
From: Tiezhu Yang @ 2022-05-24  9:20 UTC (permalink / raw)
  To: John Baldwin, gdb-patches



On 05/24/2022 02:15 AM, John Baldwin wrote:
> Define a constant for the number of registers stored in a register set
> and use this with register_size to compute the size of the
> general-purpose register set in core dumps.
>
> This also fixes the build on hosts such as FreeBSD that do not define
> an elf_gregset_t type.

Hi John,

Sorry for the related issues on FreeBSD,
the original patch is only tested on LoongArch Linux,
thank you very much for your test and fix.

> ---
>  gdb/loongarch-linux-tdep.c | 14 ++++++++++++--
>  1 file changed, 12 insertions(+), 2 deletions(-)
>
> diff --git a/gdb/loongarch-linux-tdep.c b/gdb/loongarch-linux-tdep.c
> index f13756dd003..bbb43abe13f 100644
> --- a/gdb/loongarch-linux-tdep.c
> +++ b/gdb/loongarch-linux-tdep.c
> @@ -29,6 +29,11 @@
>  #include "trad-frame.h"
>  #include "tramp-frame.h"
>
> +/* The general-purpose regset consists of 32 R registers, plus PC,
> +   and BADV registers.  */
> +
> +#define LOONGARCH_LINUX_NUM_GREGSET	(34)

LOONGARCH_LINUX_NUM_GREGSET should be defined as 45 (32 + 1 + 1 + 11)
due to reserved 11 for extension in glibc, otherwise when execute:

   make check-gdb TESTS="gdb.base/corefile.exp"

there exists the following failed testcase:

   (gdb) core-file 
/home/loongson/build.git/gdb/testsuite/outputs/gdb.base/corefile/corefile.core
   [New LWP 7742]
   warning: Unexpected size of section `.reg/7742' in core file.
   Core was generated by 
`/home/loongson/build.git/gdb/testsuite/outputs/gdb.base/corefile/corefile'.
   Program terminated with signal SIGABRT, Aborted.
   warning: Unexpected size of section `.reg/7742' in core file.
   #0  0x000000fff76f4e24 in raise () from 
/lib/loongarch64-linux-gnu/libc.so.6
   (gdb) FAIL: gdb.base/corefile.exp: core-file warning-free

I will send a patch to fix the above issue.

Thanks,
Tiezhu

> +
>  /* Unpack an elf_gregset_t into GDB's register cache.  */
>
>  static void
> @@ -172,8 +177,13 @@ loongarch_iterate_over_regset_sections (struct gdbarch *gdbarch,
>  					void *cb_data,
>  					const struct regcache *regcache)
>  {
> -  cb (".reg", sizeof (elf_gregset_t), sizeof (elf_gregset_t),
> -      &loongarch_gregset, NULL, cb_data);
> +  loongarch_gdbarch_tdep *tdep
> +    = (loongarch_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  auto regs = tdep->regs;
> +  int regsize = register_size (gdbarch, regs.r);
> +
> +  cb (".reg", LOONGARCH_LINUX_NUM_GREGSET * regsize,
> +      LOONGARCH_LINUX_NUM_GREGSET * regsize, &loongarch_gregset, NULL, cb_data);
>  }
>
>  /* Initialize LoongArch Linux ABI info.  */
>


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

* Re: [PUSHED OBV] Fix loongarch_iterate_over_regset_sections for non-native targets.
  2022-05-24  9:20 ` Tiezhu Yang
@ 2022-05-24 16:47   ` John Baldwin
  0 siblings, 0 replies; 3+ messages in thread
From: John Baldwin @ 2022-05-24 16:47 UTC (permalink / raw)
  To: Tiezhu Yang, gdb-patches

On 5/24/22 2:20 AM, Tiezhu Yang wrote:
> 
> 
> On 05/24/2022 02:15 AM, John Baldwin wrote:
>> Define a constant for the number of registers stored in a register set
>> and use this with register_size to compute the size of the
>> general-purpose register set in core dumps.
>>
>> This also fixes the build on hosts such as FreeBSD that do not define
>> an elf_gregset_t type.
> 
> Hi John,
> 
> Sorry for the related issues on FreeBSD,
> the original patch is only tested on LoongArch Linux,
> thank you very much for your test and fix.

Testing on x86-64 Linux or the like might also be good to help ensure
that you can cross-debug core dumps in the future.  Testing on that
would probably have also not worked due to elf_gregset_t being different
sizes for different architectures.

>> ---
>>   gdb/loongarch-linux-tdep.c | 14 ++++++++++++--
>>   1 file changed, 12 insertions(+), 2 deletions(-)
>>
>> diff --git a/gdb/loongarch-linux-tdep.c b/gdb/loongarch-linux-tdep.c
>> index f13756dd003..bbb43abe13f 100644
>> --- a/gdb/loongarch-linux-tdep.c
>> +++ b/gdb/loongarch-linux-tdep.c
>> @@ -29,6 +29,11 @@
>>   #include "trad-frame.h"
>>   #include "tramp-frame.h"
>>
>> +/* The general-purpose regset consists of 32 R registers, plus PC,
>> +   and BADV registers.  */
>> +
>> +#define LOONGARCH_LINUX_NUM_GREGSET	(34)
> 
> LOONGARCH_LINUX_NUM_GREGSET should be defined as 45 (32 + 1 + 1 + 11)
> due to reserved 11 for extension in glibc, otherwise when execute:

Thanks for fixing the constant.  I just guessed based on what the regset
functions supplied and collected.

-- 
John Baldwin

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

end of thread, other threads:[~2022-05-24 16:47 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-23 18:15 [PUSHED OBV] Fix loongarch_iterate_over_regset_sections for non-native targets John Baldwin
2022-05-24  9:20 ` Tiezhu Yang
2022-05-24 16:47   ` John Baldwin

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