* [PATCH 0/2] gdb/hurd: fix the x86_64 register tables
@ 2026-11-27 1:14 ajrojas
2026-11-27 1:14 ` [PATCH 1/2] gdb/hurd: fix the gregset offsets for x86_64 core files ajrojas
2026-11-27 1:14 ` [PATCH 2/2] gdb/hurd: fix the sigcontext offsets for x86_64 ajrojas
0 siblings, 2 replies; 5+ messages in thread
From: ajrojas @ 2026-11-27 1:14 UTC (permalink / raw)
To: gdb-patches; +Cc: bug-hurd, Samuel Thibault, Flavio Cruz, ajrojas
Two tables in amd64-gnu-tdep.c do not match glibc's headers. 1/2 fixes
the one used to read core files, 2/2 the one used for signal frames.
The two are independent.
Both were tested with GDB 17.2, where the file has the same tables as
on master.
I have asked the FSF for a copyright assignment for past and future
changes to GDB; it is in progress.
ajrojas (2):
gdb/hurd: fix the gregset offsets for x86_64 core files
gdb/hurd: fix the sigcontext offsets for x86_64
gdb/amd64-gnu-tdep.c | 51 ++++++++++++++++++++++----------------------
1 file changed, 26 insertions(+), 25 deletions(-)
--
2.56.0
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 1/2] gdb/hurd: fix the gregset offsets for x86_64 core files
2026-11-27 1:14 [PATCH 0/2] gdb/hurd: fix the x86_64 register tables ajrojas
@ 2026-11-27 1:14 ` ajrojas
2026-11-27 1:23 ` Samuel Thibault
2026-11-27 1:14 ` [PATCH 2/2] gdb/hurd: fix the sigcontext offsets for x86_64 ajrojas
1 sibling, 1 reply; 5+ messages in thread
From: ajrojas @ 2026-11-27 1:14 UTC (permalink / raw)
To: gdb-patches; +Cc: bug-hurd, Samuel Thibault, Flavio Cruz, ajrojas
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
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 2/2] gdb/hurd: fix the sigcontext offsets for x86_64
2026-11-27 1:14 [PATCH 0/2] gdb/hurd: fix the x86_64 register tables ajrojas
2026-11-27 1:14 ` [PATCH 1/2] gdb/hurd: fix the gregset offsets for x86_64 core files ajrojas
@ 2026-11-27 1:14 ` ajrojas
2026-11-27 1:24 ` Samuel Thibault
1 sibling, 1 reply; 5+ messages in thread
From: ajrojas @ 2026-11-27 1:14 UTC (permalink / raw)
To: gdb-patches; +Cc: bug-hurd, Samuel Thibault, Flavio Cruz, ajrojas
amd64_gnu_sc_reg_offset gives the place of each register in struct
sigcontext, from sc_r8 on, and is used to unwind through the signal
trampoline. Some entries do not match <bits/sigcontext.h>: rsi and rdi
are one slot off, and r9 to r15 are in the wrong slots (r9 is read from
sc_rdi, r15 from sc_r8). rip, rsp and rbp were right, so the backtrace
was complete, but in the frame that got the signal GDB showed wrong
values for these registers, and for arguments kept in them in optimized
code.
Use the order of <bits/sigcontext.h>: r8 to r15, rdi, rsi, rbp, rsp,
rbx, rdx, rcx, rax, rip, cs, rfl. rsp stays at sc_rsp, as on i386 with
sc_esp: the header says it is not used, but _hurd_setup_sighandler
saves the interrupted stack pointer there.
Tested on x86_64 GNU/Hurd, with core files and with a live process.
---
Tested with GDB 17.2 on Guix System x86_64 GNU/Hurd in QEMU. A static
program puts known values in rbx, rcx, rdx, rsi, rdi and r8 to r15,
writes through NULL, and aborts or waits in its SIGSEGV handler; I
looked at its core file from the crash server and attached to the
waiting process. A second one, built with -O2, calls
crash2 (NULL, 12345), which reads through its first argument; core
file only.
Before and after, the backtrace goes through "<signal handler called>"
to main. Before, the faulting frame showed rsi, rdi and r9 to r15 with
the values of other registers, and the second program showed
"crash2 (p=0x3039, p@entry=0x0, v=v@entry=1)". After, every value is
in its register and it shows "crash2 (p=p@entry=0x0, v=v@entry=12345)".
I have not run the testsuite: this table is only used for x86_64
GNU/Hurd, and I have not set it up there.
The glibc here has 0d99714680 ("hurd: Clear FP exceptions before
calling signal handler", in 2.42), where the return address is in
_trampoline, so the name check in amd64_gnu_sigtramp_p does not match
and the frame is found by its code.
gdb/amd64-gnu-tdep.c | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)
diff --git a/gdb/amd64-gnu-tdep.c b/gdb/amd64-gnu-tdep.c
index d4a0ac7df5..d021a18974 100644
--- a/gdb/amd64-gnu-tdep.c
+++ b/gdb/amd64-gnu-tdep.c
@@ -143,18 +143,18 @@ static int amd64_gnu_sc_reg_offset[] =
12 * 8, /* %rbx */
14 * 8, /* %rcx */
13 * 8, /* %rdx */
- 10 * 8, /* %rsi */
- 9 * 8, /* %rdi */
+ 9 * 8, /* %rsi */
+ 8 * 8, /* %rdi */
10 * 8, /* %rbp */
11 * 8, /* %rsp */
0 * 8, /* %r8 ... */
- 8 * 8,
- 7 * 8,
- 6 * 8,
- 3 * 8,
- 2 * 8,
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 */
--
2.56.0
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 1/2] gdb/hurd: fix the gregset offsets for x86_64 core files
2026-11-27 1:14 ` [PATCH 1/2] gdb/hurd: fix the gregset offsets for x86_64 core files ajrojas
@ 2026-11-27 1:23 ` Samuel Thibault
0 siblings, 0 replies; 5+ messages in thread
From: Samuel Thibault @ 2026-11-27 1:23 UTC (permalink / raw)
To: ajrojas; +Cc: gdb-patches, bug-hurd, Flavio Cruz
ajrojas, le jeu. 26 nov. 2026 22:14:49 -0300, a ecrit:
> 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.
Reviewed-by: Samuel Thibault <samuel.thibault@gnu.org>
Thanks!
> ---
> 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
>
--
Samuel
Actually, typing random strings in the Finder does the equivalent of
filename completion.
(Discussion in comp.os.linux.misc on the intuitiveness of commands: file
completion vs. the Mac Finder.)
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 2/2] gdb/hurd: fix the sigcontext offsets for x86_64
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
0 siblings, 0 replies; 5+ messages in thread
From: Samuel Thibault @ 2026-11-27 1:24 UTC (permalink / raw)
To: ajrojas; +Cc: gdb-patches, bug-hurd, Flavio Cruz
ajrojas, le jeu. 26 nov. 2026 22:14:50 -0300, a ecrit:
> amd64_gnu_sc_reg_offset gives the place of each register in struct
> sigcontext, from sc_r8 on, and is used to unwind through the signal
> trampoline. Some entries do not match <bits/sigcontext.h>: rsi and rdi
> are one slot off, and r9 to r15 are in the wrong slots (r9 is read from
> sc_rdi, r15 from sc_r8). rip, rsp and rbp were right, so the backtrace
> was complete, but in the frame that got the signal GDB showed wrong
> values for these registers, and for arguments kept in them in optimized
> code.
>
> Use the order of <bits/sigcontext.h>: r8 to r15, rdi, rsi, rbp, rsp,
> rbx, rdx, rcx, rax, rip, cs, rfl. rsp stays at sc_rsp, as on i386 with
> sc_esp: the header says it is not used, but _hurd_setup_sighandler
> saves the interrupted stack pointer there.
>
> Tested on x86_64 GNU/Hurd, with core files and with a live process.
Reviewed-by: Samuel Thibault <samuel.thibault@gnu.org>
Thanks!
> ---
> Tested with GDB 17.2 on Guix System x86_64 GNU/Hurd in QEMU. A static
> program puts known values in rbx, rcx, rdx, rsi, rdi and r8 to r15,
> writes through NULL, and aborts or waits in its SIGSEGV handler; I
> looked at its core file from the crash server and attached to the
> waiting process. A second one, built with -O2, calls
> crash2 (NULL, 12345), which reads through its first argument; core
> file only.
>
> Before and after, the backtrace goes through "<signal handler called>"
> to main. Before, the faulting frame showed rsi, rdi and r9 to r15 with
> the values of other registers, and the second program showed
> "crash2 (p=0x3039, p@entry=0x0, v=v@entry=1)". After, every value is
> in its register and it shows "crash2 (p=p@entry=0x0, v=v@entry=12345)".
>
> I have not run the testsuite: this table is only used for x86_64
> GNU/Hurd, and I have not set it up there.
>
> The glibc here has 0d99714680 ("hurd: Clear FP exceptions before
> calling signal handler", in 2.42), where the return address is in
> _trampoline, so the name check in amd64_gnu_sigtramp_p does not match
> and the frame is found by its code.
>
> gdb/amd64-gnu-tdep.c | 16 ++++++++--------
> 1 file changed, 8 insertions(+), 8 deletions(-)
>
> diff --git a/gdb/amd64-gnu-tdep.c b/gdb/amd64-gnu-tdep.c
> index d4a0ac7df5..d021a18974 100644
> --- a/gdb/amd64-gnu-tdep.c
> +++ b/gdb/amd64-gnu-tdep.c
> @@ -143,18 +143,18 @@ static int amd64_gnu_sc_reg_offset[] =
> 12 * 8, /* %rbx */
> 14 * 8, /* %rcx */
> 13 * 8, /* %rdx */
> - 10 * 8, /* %rsi */
> - 9 * 8, /* %rdi */
> + 9 * 8, /* %rsi */
> + 8 * 8, /* %rdi */
> 10 * 8, /* %rbp */
> 11 * 8, /* %rsp */
> 0 * 8, /* %r8 ... */
> - 8 * 8,
> - 7 * 8,
> - 6 * 8,
> - 3 * 8,
> - 2 * 8,
> 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 */
> --
> 2.56.0
>
--
Samuel
Actually, typing random strings in the Finder does the equivalent of
filename completion.
(Discussion in comp.os.linux.misc on the intuitiveness of commands: file
completion vs. the Mac Finder.)
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-11-27 1:25 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-27 1:14 [PATCH 0/2] gdb/hurd: fix the x86_64 register tables ajrojas
2026-11-27 1:14 ` [PATCH 1/2] gdb/hurd: fix the gregset offsets for x86_64 core files ajrojas
2026-11-27 1:23 ` 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
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox