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
