gdb: implement PRSTATUS elf32-sparc handler

Message ID 20260330160802.40218-1-michal.lach@phoenix-rtos.com
State New
Headers
Series gdb: implement PRSTATUS elf32-sparc handler |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_binutils_build--master-arm success Build passed
linaro-tcwg-bot/tcwg_binutils_build--master-aarch64 success Build passed
linaro-tcwg-bot/tcwg_binutils_check--master-arm success Test passed
linaro-tcwg-bot/tcwg_binutils_check--master-aarch64 success Test passed

Commit Message

Michal Lach March 30, 2026, 4:07 p.m. UTC
  From: Jakub Klimek <jakub.klimek@phoenix-rtos.com>

Solaris ELF32 coredumps emit a PRSTATUS note which is left unparsed,
without a handler in GDB, leading to incorrectly viewed coredumps.

Signed-off-by: Michal Lach <michal.lach@phoenix-rtos.com>
---
 bfd/elf32-sparc.c | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)

--
2.53.0
  

Comments

Michal Lach March 31, 2026, 3:12 p.m. UTC | #1
CC'ing SPARC maintainers.

Michal Lach <michal.lach@phoenix-rtos.com> writes:
> From: Jakub Klimek <jakub.klimek@phoenix-rtos.com>
>
> Solaris ELF32 coredumps emit a PRSTATUS note which is left unparsed,
> without a handler in GDB, leading to incorrectly viewed coredumps.
>
> Signed-off-by: Michal Lach <michal.lach@phoenix-rtos.com>
> ---
>  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

--
 - Michal Lach
  

Patch

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