[1/4] Read tid from correct offset in win32pstatus NOTE_INFO_THREAD

Message ID 20200703140505.26682-2-jon.turney@dronecode.org.uk
State Superseded
Headers show
Series
  • bfd: Add support for Cygwin x86_64 core dumps
Related show

Commit Message

Jon Turney July 3, 2020, 2:05 p.m.
Fix the offset used to read the tid from a win32pstatus ELF note.

This probably meant that registers were only being correctly recovered
from the core dump for the current thread.

It looks like this has beeen incorrect since 4a6636fb.

Also fix offsets used in NOTE_INFO_PROCESS (which is not actually
generated by the Cygwin dumper tool).

Also improve comment.

bfd/ChangeLog:

2020-07-01  Jon Turney  <jon.turney@dronecode.org.uk>

	* elf.c (elfcore_grok_win32pstatus): Fix the offset used to read
	the tid from a win32pstatus NOTE_INFO_THREAD ELF note.  Fix
	offsets used to read NOTE_INFO_PROCESS.
---
 bfd/ChangeLog | 6 ++++++
 bfd/elf.c     | 9 +++++----
 2 files changed, 11 insertions(+), 4 deletions(-)

-- 
2.27.0

Patch

diff --git a/bfd/elf.c b/bfd/elf.c
index 9ca42e10d8e..0990be31f54 100644
--- a/bfd/elf.c
+++ b/bfd/elf.c
@@ -10151,15 +10151,16 @@  elfcore_grok_win32pstatus (bfd *abfd, Elf_Internal_Note *note)
     case 1 /* NOTE_INFO_PROCESS */:
       /* FIXME: need to add ->core->command.  */
       /* process_info.pid */
-      elf_tdata (abfd)->core->pid = bfd_get_32 (abfd, note->descdata + 8);
+      elf_tdata (abfd)->core->pid = bfd_get_32 (abfd, note->descdata + 4);
       /* process_info.signal */
-      elf_tdata (abfd)->core->signal = bfd_get_32 (abfd, note->descdata + 12);
+      elf_tdata (abfd)->core->signal = bfd_get_32 (abfd, note->descdata + 8);
       break;
 
     case 2 /* NOTE_INFO_THREAD */:
-      /* Make a ".reg/999" section.  */
+      /* Make a ".reg/<tid>" section containing the Win32 API thread CONTEXT
+         structure. */
       /* thread_info.tid */
-      sprintf (buf, ".reg/%ld", (long) bfd_get_32 (abfd, note->descdata + 8));
+      sprintf (buf, ".reg/%ld", (long) bfd_get_32 (abfd, note->descdata + 4));
 
       len = strlen (buf) + 1;
       name = (char *) bfd_alloc (abfd, len);