1 /* Target-dependent code for the GNU Hurd.
2 Copyright (C) 2002-2022 Free Software Foundation, Inc.
4 This file is part of GDB.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>. */
22 #include "solib-svr4.h"
24 #include "i386-tdep.h"
26 /* Recognizing signal handler frames. */
28 /* When the GNU/Hurd libc calls a signal handler, the return address points
29 inside the trampoline assembly snippet.
31 If the trampoline function name can not be identified, we resort to reading
32 memory from the process in order to identify it. */
34 static const gdb_byte gnu_sigtramp_code
[] =
36 /* rpc_wait_trampoline: */
37 0xb8, 0xe7, 0xff, 0xff, 0xff, /* mov $-25,%eax */
38 0x9a, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, /* lcall $7,$0 */
39 0x89, 0x01, /* movl %eax, (%ecx) */
40 0x89, 0xdc, /* movl %ebx, %esp */
43 0xff, 0xd2, /* call *%edx */
45 0x83, 0xc4, 0x0c, /* addl $12, %esp */
52 #define GNU_SIGTRAMP_LEN (sizeof gnu_sigtramp_code)
53 #define GNU_SIGTRAMP_TAIL 5 /* length of tail after RA */
55 /* If THIS_FRAME is a sigtramp routine, return the address of the
56 start of the routine. Otherwise, return 0. */
59 i386_gnu_sigtramp_start (struct frame_info
*this_frame
)
61 CORE_ADDR pc
= get_frame_pc (this_frame
);
62 gdb_byte buf
[GNU_SIGTRAMP_LEN
];
64 if (!safe_frame_unwind_memory (this_frame
,
65 pc
+ GNU_SIGTRAMP_TAIL
- GNU_SIGTRAMP_LEN
,
69 if (memcmp (buf
, gnu_sigtramp_code
, GNU_SIGTRAMP_LEN
) != 0)
75 /* Return whether THIS_FRAME corresponds to a GNU/Linux sigtramp
79 i386_gnu_sigtramp_p (struct frame_info
*this_frame
)
81 CORE_ADDR pc
= get_frame_pc (this_frame
);
84 find_pc_partial_function (pc
, &name
, NULL
, NULL
);
86 /* If we have a NAME, we can check for the trampoline function */
87 if (name
!= NULL
&& strcmp (name
, "trampoline") == 0)
90 return i386_gnu_sigtramp_start (this_frame
) != 0;
93 /* Offset to sc_i386_thread_state in sigcontext, from <bits/sigcontext.h>. */
94 #define I386_GNU_SIGCONTEXT_THREAD_STATE_OFFSET 20
96 /* Assuming THIS_FRAME is a GNU/Linux sigtramp routine, return the
97 address of the associated sigcontext structure. */
100 i386_gnu_sigcontext_addr (struct frame_info
*this_frame
)
102 struct gdbarch
*gdbarch
= get_frame_arch (this_frame
);
103 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
108 get_frame_register (this_frame
, I386_ESP_REGNUM
, buf
);
109 sp
= extract_unsigned_integer (buf
, 4, byte_order
);
111 pc
= i386_gnu_sigtramp_start (this_frame
);
114 CORE_ADDR sigcontext_addr
;
116 /* The sigcontext structure address is passed as the third argument to
117 the signal handler. */
118 read_memory (sp
+ 8, buf
, 4);
119 sigcontext_addr
= extract_unsigned_integer (buf
, 4, byte_order
);
120 return sigcontext_addr
+ I386_GNU_SIGCONTEXT_THREAD_STATE_OFFSET
;
123 error (_("Couldn't recognize signal trampoline."));
127 /* Mapping between the general-purpose registers in `struct
128 sigcontext' format (starting at sc_i386_thread_state)
129 and GDB's register cache layout. */
131 /* From <bits/sigcontext.h>. */
132 static int i386_gnu_sc_reg_offset
[] =
143 14 * 4, /* %eflags */
152 /* From <sys/ucontext.h>. */
153 static int i386gnu_gregset_reg_offset
[] =
174 i386gnu_init_abi (struct gdbarch_info info
, struct gdbarch
*gdbarch
)
176 i386_gdbarch_tdep
*tdep
= (i386_gdbarch_tdep
*) gdbarch_tdep (gdbarch
);
179 i386_elf_init_abi (info
, gdbarch
);
181 set_solib_svr4_fetch_link_map_offsets
182 (gdbarch
, svr4_ilp32_fetch_link_map_offsets
);
184 tdep
->gregset_reg_offset
= i386gnu_gregset_reg_offset
;
185 tdep
->gregset_num_regs
= ARRAY_SIZE (i386gnu_gregset_reg_offset
);
186 tdep
->sizeof_gregset
= 19 * 4;
188 tdep
->jb_pc_offset
= 20; /* From <bits/setjmp.h>. */
190 tdep
->sigtramp_p
= i386_gnu_sigtramp_p
;
191 tdep
->sigcontext_addr
= i386_gnu_sigcontext_addr
;
192 tdep
->sc_reg_offset
= i386_gnu_sc_reg_offset
;
193 tdep
->sc_num_regs
= ARRAY_SIZE (i386_gnu_sc_reg_offset
);
196 void _initialize_i386gnu_tdep ();
198 _initialize_i386gnu_tdep ()
200 gdbarch_register_osabi (bfd_arch_i386
, 0, GDB_OSABI_HURD
, i386gnu_init_abi
);