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