Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: ajrojas <ajrojas.lab@gmail.com>
To: gdb-patches@sourceware.org
Cc: bug-hurd@gnu.org, Samuel Thibault <samuel.thibault@gnu.org>,
	Flavio Cruz <flaviocruz@gmail.com>,
	ajrojas <ajrojas.lab@gmail.com>
Subject: [PATCH 1/2] gdb/hurd: fix the gregset offsets for x86_64 core files
Date: Thu, 26 Nov 2026 22:14:49 -0300	[thread overview]
Message-ID: <20261127011450.60158-2-ajrojas.lab@gmail.com> (raw)
In-Reply-To: <20261127011450.60158-1-ajrojas.lab@gmail.com>

amd64_gnu_gregset_reg_offset is used to read the .reg section of x86_64
GNU/Hurd core files.  Its comment says the offsets come from
<sys/ucontext.h>, but they are those of amd64_linux_gregset_reg_offset,
and sizeof_gregset is the size of Mach's struct i386_thread_state.  The
Hurd writes pr_reg as glibc's gregset_t, which on x86_64 has 23 entries:
r8 to r15, rdi, rsi, rbp, rsp, rbx, rdx, rcx, rax, rip, cs, rfl, err,
trapno, oldmask, cr2.

Only rip, cs and eflags were read from the right place.  GDB warned
about the size of .reg, read rsp as 0 and could not unwind past the
first frame.

Use the gregset_t offsets and size.

Tested on x86_64 GNU/Hurd with core files written by the crash server.
---
The core files need a fix in the Hurd's core writer as well; without it
the notes are misaligned and GDB fails earlier:
https://lists.gnu.org/archive/html/bug-hurd/2026-11/msg00266.html

Tested with GDB 17.2 on Guix System x86_64 GNU/Hurd in QEMU, with core
files from the crash server and from the Hurd's gcore, of static and
dynamic programs.  i386 is not touched.

For example, a static program that writes through NULL in die (), with
the Hurd fix in the crash server.  Before:

  warning: Unexpected size of section `.reg/492' in core file.
  #0  die (how=<optimized out>) at src/crash.c:23
  Backtrace stopped: Cannot access memory at address 0x18
  rsp            0x0                 0x0
  rbp            0x150dd68           0x150dd68

After (the program puts 0x1122334455667788 in rbp):

  #0  die (how=how@entry=0x1013 "segv") at src/crash.c:23
  #1  0x0000000000404199 in main (argc=<optimized out>, argv=<optimized out>) at src/crash.c:49
  rsp            0x150dcb0           0x150dcb0
  rbp            0x1122334455667788  0x1122334455667788

The warning that .reg2 is too small stays: the Hurd does not save the
FP state yet, which is a separate problem.

I have not run the testsuite: these tables are only used for x86_64
GNU/Hurd, and I have not set it up there.

 gdb/amd64-gnu-tdep.c | 35 ++++++++++++++++++-----------------
 1 file changed, 18 insertions(+), 17 deletions(-)

diff --git a/gdb/amd64-gnu-tdep.c b/gdb/amd64-gnu-tdep.c
index 8415ce7468..d4a0ac7df5 100644
--- a/gdb/amd64-gnu-tdep.c
+++ b/gdb/amd64-gnu-tdep.c
@@ -160,25 +160,26 @@ static int amd64_gnu_sc_reg_offset[] =
   17 * 8,			/* %cs */
 };
 
-/* From <sys/ucontext.h>.  */
+/* From <sys/ucontext.h>: the REG_* order of gregset_t, which is the
+   format of pr_reg in the Hurd's core files.  */
 static int amd64_gnu_gregset_reg_offset[] =
 {
-  10 * 8,			/* %rax */
-  5 * 8,			/* %rbx */
-  11 * 8,			/* %rcx */
-  12 * 8,			/* %rdx */
-  13 * 8,			/* %rsi */
-  14 * 8,			/* %rdi */
-  4 * 8,			/* %rbp */
-  19 * 8,			/* %rsp */
-  9 * 8,			/* %r8 ...  */
-  8 * 8,
-  7 * 8,
-  6 * 8,
-  3 * 8,
-  2 * 8,
+  15 * 8,			/* %rax */
+  12 * 8,			/* %rbx */
+  14 * 8,			/* %rcx */
+  13 * 8,			/* %rdx */
+  9 * 8,			/* %rsi */
+  8 * 8,			/* %rdi */
+  10 * 8,			/* %rbp */
+  11 * 8,			/* %rsp */
+  0 * 8,			/* %r8 ...  */
   1 * 8,
-  0 * 8,			/* ... %r15 */
+  2 * 8,
+  3 * 8,
+  4 * 8,
+  5 * 8,
+  6 * 8,
+  7 * 8,			/* ... %r15 */
   16 * 8,			/* %rip */
   18 * 8,			/* %eflags */
   17 * 8,			/* %cs */
@@ -209,7 +210,7 @@ amd64_gnu_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 
   tdep->gregset_reg_offset = amd64_gnu_gregset_reg_offset;
   tdep->gregset_num_regs = ARRAY_SIZE (amd64_gnu_gregset_reg_offset);
-  tdep->sizeof_gregset = 21 * 8; /* sizeof (struct i386_thread_state); */
+  tdep->sizeof_gregset = 23 * 8; /* sizeof (gregset_t).  */
 
   tdep->sigtramp_p = amd64_gnu_sigtramp_p;
   tdep->sigcontext_addr = amd64_gnu_sigcontext_addr;
-- 
2.56.0


  reply	other threads:[~2026-11-27  1:15 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-27  1:14 [PATCH 0/2] gdb/hurd: fix the x86_64 register tables ajrojas
2026-11-27  1:14 ` ajrojas [this message]
2026-11-27  1:23   ` [PATCH 1/2] gdb/hurd: fix the gregset offsets for x86_64 core files Samuel Thibault
2026-11-27  1:14 ` [PATCH 2/2] gdb/hurd: fix the sigcontext offsets for x86_64 ajrojas
2026-11-27  1:24   ` Samuel Thibault

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=20261127011450.60158-2-ajrojas.lab@gmail.com \
    --to=ajrojas.lab@gmail.com \
    --cc=bug-hurd@gnu.org \
    --cc=flaviocruz@gmail.com \
    --cc=gdb-patches@sourceware.org \
    --cc=samuel.thibault@gnu.org \
    /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