From: Samuel Thibault <samuel.thibault@gnu.org>
To: ajrojas <ajrojas.lab@gmail.com>
Cc: gdb-patches@sourceware.org, bug-hurd@gnu.org,
Flavio Cruz <flaviocruz@gmail.com>
Subject: Re: [PATCH 2/2] gdb/hurd: fix the sigcontext offsets for x86_64
Date: Fri, 27 Nov 2026 02:24:47 +0100 [thread overview]
Message-ID: <awjb3xPQs-e737XS@end> (raw)
In-Reply-To: <20261127011450.60158-3-ajrojas.lab@gmail.com>
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.)
prev parent reply other threads:[~2026-11-27 1:25 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 ` [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 message]
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=awjb3xPQs-e737XS@end \
--to=samuel.thibault@gnu.org \
--cc=ajrojas.lab@gmail.com \
--cc=bug-hurd@gnu.org \
--cc=flaviocruz@gmail.com \
--cc=gdb-patches@sourceware.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