Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [PATCH] gdb/sparc: implement PRSTATUS elf32-sparc handler
@ 2026-04-20 11:46 Michal Lach
  2026-04-20 18:42 ` Simon Marchi
  0 siblings, 1 reply; 2+ messages in thread
From: Michal Lach @ 2026-04-20 11:46 UTC (permalink / raw)
  To: gdb-patches; +Cc: jakub.klimek, michal.lach, daniel.sawka

From: Jakub Klimek <jakub.klimek@phoenix-rtos.com>

Some SPARC ELF32 coredumps emit a PRSTATUS note which is left unparsed
without a handler in GDB, leading to incorrectly viewed coredumps.
---
 bfd/elf32-sparc.c | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)

diff --git a/bfd/elf32-sparc.c b/bfd/elf32-sparc.c
index a5f5d058196..837b2e16fff 100644
--- a/bfd/elf32-sparc.c
+++ b/bfd/elf32-sparc.c
@@ -31,6 +31,34 @@

 /* Support for core dump NOTE sections.  */

+static bool
+elf32_sparc_grok_prstatus (bfd *abfd, Elf_Internal_Note *note)
+{
+  int offset;
+  size_t size;
+
+  switch (note->descsz)
+    {
+    default:
+      return false;
+    case 228:
+      /* pr_cursig */
+      elf_tdata (abfd)->core->signal = bfd_get_16 (abfd, note->descdata + 12);
+
+      /* pr_pid */
+      elf_tdata (abfd)->core->lwpid = bfd_get_32 (abfd, note->descdata + 24);
+
+      /* pr_reg */
+      offset = 72;
+      size = 152;
+
+      break;
+    }
+
+  /* Make a ".reg/999" section.  */
+  return _bfd_elfcore_make_pseudosection (abfd, ".reg", size, note->descpos + offset);
+}
+
 static bool
 elf32_sparc_grok_psinfo (bfd *abfd, Elf_Internal_Note *note)
 {
@@ -230,6 +258,7 @@ elf32_sparc_reloc_type_class (const struct bfd_link_info *info,
 					elf32_sparc_merge_private_bfd_data
 #define elf_backend_final_write_processing \
 					elf32_sparc_final_write_processing
+#define elf_backend_grok_prstatus	elf32_sparc_grok_prstatus
 #define elf_backend_grok_psinfo		elf32_sparc_grok_psinfo
 #define elf_backend_reloc_type_class	elf32_sparc_reloc_type_class

--
2.53.0


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

* Re: [PATCH] gdb/sparc: implement PRSTATUS elf32-sparc handler
  2026-04-20 11:46 [PATCH] gdb/sparc: implement PRSTATUS elf32-sparc handler Michal Lach
@ 2026-04-20 18:42 ` Simon Marchi
  0 siblings, 0 replies; 2+ messages in thread
From: Simon Marchi @ 2026-04-20 18:42 UTC (permalink / raw)
  To: Michal Lach, gdb-patches, Binutils; +Cc: jakub.klimek, daniel.sawka

Adding binutils@sourceware.org, since this targets code in "bfd".

Can someone from binutils review this?

Thanks,

Simon

On 4/20/26 7:46 AM, Michal Lach wrote:
> From: Jakub Klimek <jakub.klimek@phoenix-rtos.com>
> 
> Some SPARC ELF32 coredumps emit a PRSTATUS note which is left unparsed
> without a handler in GDB, leading to incorrectly viewed coredumps.
> ---
>  bfd/elf32-sparc.c | 29 +++++++++++++++++++++++++++++
>  1 file changed, 29 insertions(+)
> 
> diff --git a/bfd/elf32-sparc.c b/bfd/elf32-sparc.c
> index a5f5d058196..837b2e16fff 100644
> --- a/bfd/elf32-sparc.c
> +++ b/bfd/elf32-sparc.c
> @@ -31,6 +31,34 @@
> 
>  /* Support for core dump NOTE sections.  */
> 
> +static bool
> +elf32_sparc_grok_prstatus (bfd *abfd, Elf_Internal_Note *note)
> +{
> +  int offset;
> +  size_t size;
> +
> +  switch (note->descsz)
> +    {
> +    default:
> +      return false;
> +    case 228:
> +      /* pr_cursig */
> +      elf_tdata (abfd)->core->signal = bfd_get_16 (abfd, note->descdata + 12);
> +
> +      /* pr_pid */
> +      elf_tdata (abfd)->core->lwpid = bfd_get_32 (abfd, note->descdata + 24);
> +
> +      /* pr_reg */
> +      offset = 72;
> +      size = 152;
> +
> +      break;
> +    }
> +
> +  /* Make a ".reg/999" section.  */
> +  return _bfd_elfcore_make_pseudosection (abfd, ".reg", size, note->descpos + offset);
> +}
> +
>  static bool
>  elf32_sparc_grok_psinfo (bfd *abfd, Elf_Internal_Note *note)
>  {
> @@ -230,6 +258,7 @@ elf32_sparc_reloc_type_class (const struct bfd_link_info *info,
>  					elf32_sparc_merge_private_bfd_data
>  #define elf_backend_final_write_processing \
>  					elf32_sparc_final_write_processing
> +#define elf_backend_grok_prstatus	elf32_sparc_grok_prstatus
>  #define elf_backend_grok_psinfo		elf32_sparc_grok_psinfo
>  #define elf_backend_reloc_type_class	elf32_sparc_reloc_type_class
> 
> --
> 2.53.0
> 

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

end of thread, other threads:[~2026-04-20 18:44 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-04-20 11:46 [PATCH] gdb/sparc: implement PRSTATUS elf32-sparc handler Michal Lach
2026-04-20 18:42 ` Simon Marchi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox