This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH, MIPS] Extract PID from core dump file


On MIPS platforms, PID information was not correctly propagated from core dump file to internal GDB structures. This patch fixes that behavior.

The bug was found while trying to read TLS variable from core dump file on MIPS platforms, but it was not able because GDB needs correct PID information in order to do that.

This change is tested on MIPS64R2 board with o32, n32 and n64 executables. Test program is forced to crash in order to generate core file. Core file is loaded into GDB and bfd structure is checked if it has correct PID value, the same value executable had before crash.

Currently I don't have copyright assignment. Couple a weeks ago my company initiated process of getting copyright assignment but with no response so far.


From 06d1e46e23297bcbbd6e75dcce6c0c4cfbca7864 Mon Sep 17 00:00:00 2001
From: Djordje Todorovic <djordje.todorovic@rt-rk.com>
Date: Fri, 16 Jun 2017 14:02:28 +0200
Subject: [PATCH] BFD: Extract PID from MIPS core dump file

On MIPS platforms, PID information was not correctly propagated
from core dump file to internal GDB structures.
This patch fixes that behavior.

bfd/ChangeLog:

	* elf32-mips.c (elf32_mips_grok_psinfo): Extract core->pid.
	* elf64-mips.c (elf64_mips_grok_psinfo): Likewise.
	* elfn32-mips.c (elf32_mips_grok_psinfo): Likewise.
---
 bfd/elf32-mips.c  | 2 ++
 bfd/elf64-mips.c  | 2 ++
 bfd/elfn32-mips.c | 2 ++
 3 files changed, 6 insertions(+)

diff --git a/bfd/elf32-mips.c b/bfd/elf32-mips.c
index 8c1a68eb..9ec2818 100644
--- a/bfd/elf32-mips.c
+++ b/bfd/elf32-mips.c
@@ -2353,6 +2353,8 @@ elf32_mips_grok_psinfo (bfd *abfd, Elf_Internal_Note *note)
 	return FALSE;

       case 128:		/* Linux/MIPS elf_prpsinfo */
+	elf_tdata (abfd)->core->pid
+	 = bfd_get_32 (abfd, note->descdata + 24);
 	elf_tdata (abfd)->core->program
 	 = _bfd_elfcore_strndup (abfd, note->descdata + 32, 16);
 	elf_tdata (abfd)->core->command
diff --git a/bfd/elf64-mips.c b/bfd/elf64-mips.c
index 84f2a3f..e45e362 100644
--- a/bfd/elf64-mips.c
+++ b/bfd/elf64-mips.c
@@ -4228,6 +4228,8 @@ elf64_mips_grok_psinfo (bfd *abfd, Elf_Internal_Note *note)
 	return FALSE;

       case 136:		/* Linux/MIPS - N64 kernel elf_prpsinfo */
+	elf_tdata (abfd)->core->pid
+	 = bfd_get_32 (abfd, note->descdata + 24);
 	elf_tdata (abfd)->core->program
 	 = _bfd_elfcore_strndup (abfd, note->descdata + 40, 16);
 	elf_tdata (abfd)->core->command
diff --git a/bfd/elfn32-mips.c b/bfd/elfn32-mips.c
index dce7ba1..af4e8c3 100644
--- a/bfd/elfn32-mips.c
+++ b/bfd/elfn32-mips.c
@@ -3558,6 +3558,8 @@ elf32_mips_grok_psinfo (bfd *abfd, Elf_Internal_Note *note)
 	return FALSE;

       case 128:		/* Linux/MIPS elf_prpsinfo */
+	elf_tdata (abfd)->core->pid
+	 = bfd_get_32 (abfd, note->descdata + 24);
 	elf_tdata (abfd)->core->program
 	 = _bfd_elfcore_strndup (abfd, note->descdata + 32, 16);
 	elf_tdata (abfd)->core->command
--
1.9.1



On 16.06.2017. 01:37, Maciej W. Rozycki wrote:
On Mon, 5 Jun 2017, Djordje Todorovic wrote:

There is already a thread for this but it is not correct ([PATCH, MIPS]
Extract PID from core file by Michael Eager).  As author in this thread says
it was only tested on MIPS32 (N32) .

  Please note that n32 is a MIPS64 ABI (an ILP32 ABI requiring a 64-bit
processor).

This patch is tested on MIPS32 and MIPS64
executables and both points for setting pid in bfd/elf32-mips.c and
bfd/elf64-mips.c is hit respectively. It is also checked in Linux kernel and
the size of pid is the same as size of int.

It can be found in the source of Linux kernel:
include/uapi/asm-generic/posix_types.h
...
#ifndef __kernel_pid_t
typedef int        __kernel_pid_t;
#endif
...

  Please resend with a description clearly stating what problem you intend
to solve, such that it can be used as the commit message.  If sending a
GIT-formatted patch, then place any comments not to be committed after the
`---' separator (there is no requirement to send GIT-formatted patches for
this project though).

  Do not include an update to any ChangeLog files with the patch itself; it
will cause a conflict when the patch is applied.  Include the intended
ChangeLog entries at the end of the description instead, and the committer
will apply them as appropriate.

 From 79272bae0b10fa35b640d4006045f389e9a85849 Mon Sep 17 00:00:00 2001
From: Djordje Todorovic <djordje.todorovic@rt-rk.com>
Date: Fri, 2 Jun 2017 13:16:00 +0200
Subject: [PATCH] Extract PID from MIPS core dump file

bfd/ChangeLog:

     * elf32-mips.c (elf32_mips_grok_psinfo): Extract core->pid.
     * elf64-mips.c (elf64_mips_grok_psinfo): Likewise.

  Why only update elf32-mips.c and elf64-mips.c and not elfn32-mips.c?

  Also did you verify your change and if so, then how?  When submitting a
change please always say how it has been tested.

  Finally, I see this is your first patch posted, so please clarify if you
have a copyright assignment in place with FSF.  This is a very small
change, so it's likely that it can go in even without such an assignment,
however it would be preferable that you had it, and it will be a
requirement if you intend to submit more changes.

  Please let me know if you have any questions.

   Maciej



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]