public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Djordje Todorovic <djordje.todorovic@rt-rk.com>
To: "Maciej W. Rozycki" <macro@imgtec.com>
Cc: binutils@sourceware.org, gdb-patches@sourceware.org,
	"nemanja.popov@rt-rk.com" <nemanja.popov@rt-rk.com>,
	Nikola Prica <nikola.prica@rt-rk.com>,
	petar.jovanovic@rt-rk.com,
	"Ananthakrishna Sowda (asowda)" <asowda@cisco.com>
Subject: [PATCH 3/4] BFD: Fix reading Linux core PRSTATUS note for MIPS n32
Date: Fri, 06 Oct 2017 11:03:00 -0000	[thread overview]
Message-ID: <b2a9a1ea-ef8c-4843-b631-67e4a673aab1@rt-rk.com> (raw)

The kernel struct elf_prstatus which GDB MIPS n32 uses is defined as following:

(top-gdb-mipsN32) ptype struct elf_prstatus
type = struct elf_prstatus {
     struct elf_siginfo pr_info;
     short pr_cursig;
     unsigned long long pr_sigpend;
     unsigned long long pr_sighold;
     __pid_t pr_pid;
     __pid_t pr_ppid;
     __pid_t pr_pgrp;
     __pid_t pr_sid;
     struct timeval pr_utime;
     struct timeval pr_stime;
     struct timeval pr_cutime;
     struct timeval pr_cstime;
     elf_gregset_t pr_reg;
     int pr_fpvalid;
}

and the size of the structure is not right in the current source code, because:

(top-gdb-mipsN32) p sizeof(struct elf_prstatus)
$1 = 448

Also, offset of the pr_pid and pr_reg have to be corrected:

(top-gdb-mipsN32) print /d &((struct elf_prstatus *)0)->pr_reg
$2 = 80
(top-gdb-mipsN32) print /d &((struct elf_prstatus *)0)->pr_pid
$3 = 32

Also, it is detected that on MIPS n32 platform, GDB has never called functions for reading Linux core PRPSINFO and PRSTATUS note defined in bfd/elfn32-mips.c, but GDB MIPS n32 
currently uses functions from bfd/elf32-mips.c. I am not sure if it is expected, but 'elf32_mips_grok_psinfo' from bfd/elfn32-mips.c is exactly the same as one from 
bfd/elf32-mips.c, because GDB MIPS n32 uses exactly the same struct elf_prpsinfo and there is no problem for end users. But, when GDB MIPS n32 comes into 'elf32_mips_grok_prstatus' 
from bfd/elf32-mips.c, it would never go into 'case 256' of the 'switch' because the size of struct elf_prstatus is different on MIPS n32.

So, I have also noticed when GDB MIPS n32 generates core file it calls proper functions for it (from bfd/elfn32-mips.c) because target vector points to the proper architecture:

(gdb) gcore
Breakpoint 1, elf32_mips_write_core_note (abfd=0x10b329e8, buf=0x10b32d88 "", bufsiz=0x7fff5fec,
     note_type=1) at ../../binutils-gdb/bfd/elfn32-mips.c:3590
3590      switch (note_type)
(top-gdb-mipsN32) p abfd->xvec
$4 = (const struct bfd_target *) 0x10869010 <mips_elf32_ntrad_be_vec>

but when reads the core file it looks as following:
...
(top-gdb-mipsN32) c
Continuing.
A program is being debugged already.  Kill it? (y or n) y

Breakpoint 2, elf32_mips_grok_prstatus (abfd=0x10ac9a58, note=0x7fff5d08)
     at ../../binutils-gdb/bfd/elf32-mips.c:2323
2323      switch (note->descsz)
(top-gdb-mipsN32) p abfd->xvec
$5 = (const struct bfd_target *) 0x1085a318 <mips_elf32_trad_be_vec>

Even GDB MIPS n32 does not use the function by current design, at least on my MIPS board, the patch looks as following:

 From 918226ecebb699916e7e3f3e0f5befa2602b8708 Mon Sep 17 00:00:00 2001
From: Djordje Todorovic <djordje.todorovic@rt-rk.com>
Date: Wed, 4 Oct 2017 15:01:00 +0200
Subject: [PATCH 3/4] BFD: Fix reading Linux core PRSTATUS note for MIPS n32

bfd/ChangeLog:

	* bfd/elfn32-mips (elf32_mips_grok_prstatus): Fix pr_pid and
	pr_reg offsets and size of struct elf_prstatus.
---
  bfd/elfn32-mips.c | 6 +++---
  1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/bfd/elfn32-mips.c b/bfd/elfn32-mips.c
index 5287da3..07793b6 100644
--- a/bfd/elfn32-mips.c
+++ b/bfd/elfn32-mips.c
@@ -3530,15 +3530,15 @@ elf32_mips_grok_prstatus (bfd *abfd, Elf_Internal_Note *note)
        default:
  	return FALSE;

-      case 440:		/* Linux/MIPS N32 */
+      case 448:		/* Linux/MIPS N32 */
  	/* 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);
+	elf_tdata (abfd)->core->lwpid = bfd_get_32 (abfd, note->descdata + 32);

  	/* pr_reg */
-	offset = 72;
+	offset = 80;
  	size = 360;

  	break;
-- 
2.7.4

             reply	other threads:[~2017-10-06 11:03 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-10-06 11:03 Djordje Todorovic [this message]
2017-10-12 22:35 ` Maciej W. Rozycki
2017-10-17 13:47   ` Djordje Todorovic

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=b2a9a1ea-ef8c-4843-b631-67e4a673aab1@rt-rk.com \
    --to=djordje.todorovic@rt-rk.com \
    --cc=asowda@cisco.com \
    --cc=binutils@sourceware.org \
    --cc=gdb-patches@sourceware.org \
    --cc=macro@imgtec.com \
    --cc=nemanja.popov@rt-rk.com \
    --cc=nikola.prica@rt-rk.com \
    --cc=petar.jovanovic@rt-rk.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).