[4/4] BFD: Extract PID from MIPS core dump file

Message ID f25f8ddf-28a8-034a-c36d-ae9b35cba46c@rt-rk.com
State Superseded
Headers

Commit Message

Djordje Todorovic Oct. 6, 2017, 11:03 a.m. UTC
  The patch which adds reading PID from Linux core PRPSINFO.

Please notice that I have corrected the offset for MIPS o32 and MIPS n32 from the first iteration.

MIPS o32 and n32 uses exactly the same struct elf_prpsinfo as you have mentioned.

The kernel struct elf_prpsinfo on MIPS o32 looks as following:

(top-gdb-mipso32) ptype struct elf_prpsinfo
type = struct elf_prpsinfo {
     char pr_state;
     char pr_sname;
     char pr_zomb;
     char pr_nice;
     unsigned long pr_flag;
     long pr_uid;
     long pr_gid;
     int pr_pid;
     int pr_ppid;
     int pr_pgrp;
     int pr_sid;
     char pr_fname[16];
     char pr_psargs[80];
}

and, as you also mentioned, the offset of PID is:

(top-gdb-mipso32) print /d &((struct elf_prpsinfo *)0)->pr_pid
$1 = 16

 From 6ef7b5c46efe881dc3421b2ea990131211dfc518 Mon Sep 17 00:00:00 2001
From: Djordje Todorovic <djordje.todorovic@rt-rk.com>
Date: Wed, 4 Oct 2017 15:07:28 +0200
Subject: [PATCH 4/4] BFD: Extract PID from MIPS core dump file

On MIPS o32, n32 and n64 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(+)
  

Comments

Maciej W. Rozycki Oct. 12, 2017, 10:38 p.m. UTC | #1
On Fri, 6 Oct 2017, Djordje Todorovic wrote:

> Please notice that I have corrected the offset for MIPS o32 and MIPS n32 from
> the first iteration.

 Yes, thanks.

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

 Two spaces after a full stop please.  It would be good to mention in the 
commit description what the consequence (symptom) of the bug was.

  Maciej
  

Patch

diff --git a/bfd/elf32-mips.c b/bfd/elf32-mips.c
index 48a2083..6b64527 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 + 16);
  	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 354e4cb..10d6880 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 07793b6..5621621 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 + 16);
  	elf_tdata (abfd)->core->program
  	 = _bfd_elfcore_strndup (abfd, note->descdata + 32, 16);
  	elf_tdata (abfd)->core->command