public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] [ARC] Parse NOTE section in core dump files
@ 2016-08-22 17:22 Anton Kolesov
  2016-08-23  8:52 ` Nick Clifton
  0 siblings, 1 reply; 3+ messages in thread
From: Anton Kolesov @ 2016-08-22 17:22 UTC (permalink / raw)
  To: binutils
  Cc: Anton Kolesov, Francois.Bedard, Claudiu.Zissulescu, Cupertino Miranda

This patch adds function elf32_arc_grok_parse to parse NOTE section of core
dump files. GDB requires this to work properly with core dumps.

GDB expects general purpose registers to be in the section .reg. However Linux
kernel doesn't create this section and instead writes registers to NOTE
section. It is up to BFD to create a pseudosection .reg from the
contents of NOTE. This patch adds this functionality to the ARC. Also BFD
will read from NOTE process id and signal number that caused failure. This
function relies on offsets inside elf_prstatus structure in Linux.

This solution is similar to what other architectures use, for example
elf32_arm_nabi_grok_prstatus or elf32_mips_grok_prstatus.

bfd/
	* elf32-arc.c (elf32_arc_grok_prstatus): New function.

---
 bfd/elf32-arc.c | 35 +++++++++++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)

diff --git a/bfd/elf32-arc.c b/bfd/elf32-arc.c
index 00828be..89a2b52 100644
--- a/bfd/elf32-arc.c
+++ b/bfd/elf32-arc.c
@@ -2439,6 +2439,39 @@ elf_arc_add_symbol_hook (bfd * abfd,
   return TRUE;
 }
 
+/* GDB expects general purpose registers to be in section .reg.  However Linux
+   kernel doesn't create this section and instead writes registers to NOTE
+   section.  It is up to the binutils to create a pseudo-section .reg from the
+   contents of NOTE.  Also BFD will read pid and signal number from NOTE.  This
+   function relies on offsets inside elf_prstatus structure in Linux to be
+   stable.  */
+
+static bfd_boolean
+elf32_arc_grok_prstatus (bfd *abfd, Elf_Internal_Note *note)
+{
+  int offset;
+  size_t size;
+
+  switch (note->descsz)
+    {
+    default:
+      return FALSE;
+
+    case 236: /* sizeof (struct elf_prstatus) on Linux/arc.  */
+      /* 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_regs */
+      offset = 72;
+      size = (40 * 4); /* There are 40 registers in user_regs_struct.  */
+      break;
+    }
+  /* Make a ".reg/999" section.  */
+  return _bfd_elfcore_make_pseudosection (abfd, ".reg", size,
+					  note->descpos + offset);
+}
+
 #define TARGET_LITTLE_SYM   arc_elf32_le_vec
 #define TARGET_LITTLE_NAME  "elf32-littlearc"
 #define TARGET_BIG_SYM	    arc_elf32_be_vec
@@ -2484,6 +2517,8 @@ elf_arc_add_symbol_hook (bfd * abfd,
 #define elf_backend_may_use_rela_p	1
 #define elf_backend_default_use_rela_p	1
 
+#define elf_backend_grok_prstatus elf32_arc_grok_prstatus
+
 #define elf_backend_default_execstack	0
 
 #include "elf32-target.h"
-- 
2.8.1

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

* Re: [PATCH] [ARC] Parse NOTE section in core dump files
  2016-08-22 17:22 [PATCH] [ARC] Parse NOTE section in core dump files Anton Kolesov
@ 2016-08-23  8:52 ` Nick Clifton
  2016-08-24 12:37   ` Claudiu Zissulescu
  0 siblings, 1 reply; 3+ messages in thread
From: Nick Clifton @ 2016-08-23  8:52 UTC (permalink / raw)
  To: Anton Kolesov, binutils
  Cc: Francois.Bedard, Claudiu.Zissulescu, Cupertino Miranda

Hi Anton,

> bfd/
> 	* elf32-arc.c (elf32_arc_grok_prstatus): New function.

Approved - please apply.

Cheers
  Nick

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

* RE: [PATCH] [ARC] Parse NOTE section in core dump files
  2016-08-23  8:52 ` Nick Clifton
@ 2016-08-24 12:37   ` Claudiu Zissulescu
  0 siblings, 0 replies; 3+ messages in thread
From: Claudiu Zissulescu @ 2016-08-24 12:37 UTC (permalink / raw)
  To: Nick Clifton, Anton Kolesov, binutils
  Cc: Francois.Bedard, Claudiu.Zissulescu, Cupertino Miranda

Committed.

Thank you for your review,
Claudiu

> -----Original Message-----
> From: Nick Clifton [mailto:nickc@redhat.com]
> Sent: Tuesday, August 23, 2016 10:53 AM
> To: Anton Kolesov <Anton.Kolesov@synopsys.com>;
> binutils@sourceware.org
> Cc: Francois.Bedard@synopsys.com; Claudiu.Zissulescu@synopsys.com;
> Cupertino Miranda <Cupertino.Miranda@synopsys.com>
> Subject: Re: [PATCH] [ARC] Parse NOTE section in core dump files
> 
> Hi Anton,
> 
> > bfd/
> > 	* elf32-arc.c (elf32_arc_grok_prstatus): New function.
> 
> Approved - please apply.
> 
> Cheers
>   Nick

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

end of thread, other threads:[~2016-08-24 12:37 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-08-22 17:22 [PATCH] [ARC] Parse NOTE section in core dump files Anton Kolesov
2016-08-23  8:52 ` Nick Clifton
2016-08-24 12:37   ` Claudiu Zissulescu

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