Flavio Cruz, le dim. 04 févr. 2024 01:43:48 -0500, a ecrit:
> +/* Recognizing signal handler frames. */
> +
> +/* When the GNU/Hurd libc calls a signal handler, the return address points
> + inside the trampoline assembly snippet.
> +
> + If the trampoline function name can not be identified, we resort to reading
> + memory from the process in order to identify it. */
> +
> +static const gdb_byte gnu_sigtramp_code[] =
> +{
> +/* rpc_wait_trampoline: */
> + 0x48, 0xc7, 0xc0, 0xe7, 0xff, 0xff, 0xff, /* mov $-25,%rax */
> + 0x0f, 0x05, /* syscall */
> + 0x49, 0x89, 0x04, 0x24, /* mov %rax,(%r12) */
0x48, 0x89, 0xdc /* mov %rbx,%rsp */
is missing here?
Thanks for catching! Seems like it got clobbered when I copied over the output from objdump.
> + CORE_ADDR sigcontext_addr;
> +
> + /* The sigcontext structure address is passed as the third argument to
> + the signal handler. */
> + read_memory (sp + 8, buf, 8);
on x86_64 it would rather be through registers
We could get it from RDX but I believe RDX can get clobbered when there's a function call in the signal handler.
I think we can just get the sigcontext by looking at position 16 from the frame's RSP since we leave the sigcontext
to be used for __sigreturn in that position, according to the comment sysdeps/mach/hurd/x86/trampoline.c:
/* The word at the top of stack is &__sigreturn; following are a dummy
word to fill the slot for the address for __sigreturn to return to,
and a copy of SCP for __sigreturn's argument. Load the SCP as for a
call, and "return" to calling __sigreturn (SCP); this call never
returns. */
So I think this part should be changed to just read_memory (sp + 16, buf, 8);
I did a few more tests and GDB seems to recognize the signal handler frame correctly when backtracking
and listing the frames during a signal.
Let me know if there's other ways to confirm this is working as intended.
> + sigcontext_addr = extract_unsigned_integer (buf, 8, byte_order);
> + return sigcontext_addr + AMD64_GNU_SIGCONTEXT_THREAD_STATE_OFFSET;
> + }
> +
> + error (_("Couldn't recognize signal trampoline."));
> + return 0;
> +}
> +/* From <bits/sigcontext.h>. */
> +static int amd64_gnu_sc_reg_offset[] =
I didn't check these :o)
The rest looks sane indeed.
Thanks for taking a look.
Flavio
Samuel