GDB (xrefs)
Loading...
Searching...
No Matches
i386-gnu-tdep.c
Go to the documentation of this file.
1/* Target-dependent code for the GNU Hurd.
2 Copyright (C) 2002-2023 Free Software Foundation, Inc.
3
4 This file is part of GDB.
5
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.
10
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.
15
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/>. */
18
19#include "defs.h"
20#include "gdbcore.h"
21#include "osabi.h"
22#include "solib-svr4.h"
23
24#include "i386-tdep.h"
25
26/* Recognizing signal handler frames. */
27
28/* When the GNU/Hurd libc calls a signal handler, the return address points
29 inside the trampoline assembly snippet.
30
31 If the trampoline function name can not be identified, we resort to reading
32 memory from the process in order to identify it. */
33
34static const gdb_byte gnu_sigtramp_code[] =
35{
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 */
41
42/* trampoline: */
43 0xff, 0xd2, /* call *%edx */
44/* RA HERE */
45 0x83, 0xc4, 0x0c, /* addl $12, %esp */
46 0xc3, /* ret */
47
48/* firewall: */
49 0xf4, /* hlt */
50};
51
52#define GNU_SIGTRAMP_LEN (sizeof gnu_sigtramp_code)
53#define GNU_SIGTRAMP_TAIL 5 /* length of tail after RA */
54
55/* If THIS_FRAME is a sigtramp routine, return the address of the
56 start of the routine. Otherwise, return 0. */
57
58static CORE_ADDR
60{
61 CORE_ADDR pc = get_frame_pc (this_frame);
62 gdb_byte buf[GNU_SIGTRAMP_LEN];
63
64 if (!safe_frame_unwind_memory (this_frame,
66 buf))
67 return 0;
68
69 if (memcmp (buf, gnu_sigtramp_code, GNU_SIGTRAMP_LEN) != 0)
70 return 0;
71
72 return pc;
73}
74
75/* Return whether THIS_FRAME corresponds to a GNU/Linux sigtramp
76 routine. */
77
78static int
80{
81 CORE_ADDR pc = get_frame_pc (this_frame);
82 const char *name;
83
84 find_pc_partial_function (pc, &name, NULL, NULL);
85
86 /* If we have a NAME, we can check for the trampoline function */
87 if (name != NULL && strcmp (name, "trampoline") == 0)
88 return 1;
89
90 return i386_gnu_sigtramp_start (this_frame) != 0;
91}
92
93/* Offset to sc_i386_thread_state in sigcontext, from <bits/sigcontext.h>. */
94#define I386_GNU_SIGCONTEXT_THREAD_STATE_OFFSET 20
95
96/* Assuming THIS_FRAME is a GNU/Linux sigtramp routine, return the
97 address of the associated sigcontext structure. */
98
99static CORE_ADDR
101{
102 struct gdbarch *gdbarch = get_frame_arch (this_frame);
103 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
104 CORE_ADDR pc;
105 CORE_ADDR sp;
106 gdb_byte buf[4];
107
108 get_frame_register (this_frame, I386_ESP_REGNUM, buf);
109 sp = extract_unsigned_integer (buf, 4, byte_order);
110
111 pc = i386_gnu_sigtramp_start (this_frame);
112 if (pc)
113 {
114 CORE_ADDR sigcontext_addr;
115
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;
121 }
122
123 error (_("Couldn't recognize signal trampoline."));
124 return 0;
125}
126
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. */
130
131/* From <bits/sigcontext.h>. */
133{
134 11 * 4, /* %eax */
135 10 * 4, /* %ecx */
136 9 * 4, /* %edx */
137 8 * 4, /* %ebx */
138 7 * 4, /* %esp */
139 6 * 4, /* %ebp */
140 5 * 4, /* %esi */
141 4 * 4, /* %edi */
142 12 * 4, /* %eip */
143 14 * 4, /* %eflags */
144 13 * 4, /* %cs */
145 16 * 4, /* %ss */
146 3 * 4, /* %ds */
147 2 * 4, /* %es */
148 1 * 4, /* %fs */
149 0 * 4 /* %gs */
150};
151
152/* From <sys/ucontext.h>. */
154{
155 11 * 4, /* %eax */
156 10 * 4, /* %ecx */
157 9 * 4, /* %edx */
158 8 * 4, /* %ebx */
159 17 * 4, /* %uesp */
160 6 * 4, /* %ebp */
161 5 * 4, /* %esi */
162 4 * 4, /* %edi */
163 14 * 4, /* %eip */
164 16 * 4, /* %efl */
165 15 * 4, /* %cs */
166 18 * 4, /* %ss */
167 3 * 4, /* %ds */
168 2 * 4, /* %es */
169 1 * 4, /* %fs */
170 0 * 4, /* %gs */
171};
172
173static void
175{
176 i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
177
178 /* GNU uses ELF. */
180
183
185 tdep->gregset_num_regs = ARRAY_SIZE (i386gnu_gregset_reg_offset);
186 tdep->sizeof_gregset = 19 * 4;
187
188 tdep->jb_pc_offset = 20; /* From <bits/setjmp.h>. */
189
193 tdep->sc_num_regs = ARRAY_SIZE (i386_gnu_sc_reg_offset);
194}
195
197void
const char *const name
bool find_pc_partial_function(CORE_ADDR pc, const char **name, CORE_ADDR *address, CORE_ADDR *endaddr, const struct block **block)
Definition blockframe.c:373
void read_memory(CORE_ADDR memaddr, gdb_byte *myaddr, ssize_t len)
Definition corefile.c:238
static ULONGEST extract_unsigned_integer(gdb::array_view< const gdb_byte > buf, enum bfd_endian byte_order)
Definition defs.h:480
CORE_ADDR get_frame_pc(frame_info_ptr frame)
Definition frame.c:2712
void get_frame_register(frame_info_ptr frame, int regnum, gdb_byte *buf)
Definition frame.c:1263
struct gdbarch * get_frame_arch(frame_info_ptr this_frame)
Definition frame.c:3027
bool safe_frame_unwind_memory(frame_info_ptr this_frame, CORE_ADDR addr, gdb::array_view< gdb_byte > buffer)
Definition frame.c:3017
enum bfd_endian gdbarch_byte_order(struct gdbarch *gdbarch)
Definition gdbarch.c:1396
static int i386_gnu_sigtramp_p(frame_info_ptr this_frame)
#define GNU_SIGTRAMP_TAIL
void _initialize_i386gnu_tdep()
#define I386_GNU_SIGCONTEXT_THREAD_STATE_OFFSET
#define GNU_SIGTRAMP_LEN
static const gdb_byte gnu_sigtramp_code[]
static CORE_ADDR i386_gnu_sigcontext_addr(frame_info_ptr this_frame)
static int i386gnu_gregset_reg_offset[]
static int i386_gnu_sc_reg_offset[]
static CORE_ADDR i386_gnu_sigtramp_start(frame_info_ptr this_frame)
static void i386gnu_init_abi(struct gdbarch_info info, struct gdbarch *gdbarch)
void i386_elf_init_abi(struct gdbarch_info info, struct gdbarch *gdbarch)
Definition i386-tdep.c:4530
@ I386_ESP_REGNUM
Definition i386-tdep.h:285
info(Component c)
Definition gdbarch.py:41
void gdbarch_register_osabi(enum bfd_architecture arch, unsigned long machine, enum gdb_osabi osabi, void(*init_osabi)(struct gdbarch_info, struct gdbarch *))
Definition osabi.c:146
@ GDB_OSABI_HURD
Definition osabi.h:30
void set_solib_svr4_fetch_link_map_offsets(struct gdbarch *gdbarch, struct link_map_offsets *(*flmo)(void))
struct link_map_offsets * svr4_ilp32_fetch_link_map_offsets(void)
int * gregset_reg_offset
Definition i386-tdep.h:64
int(* sigtramp_p)(frame_info_ptr)
Definition i386-tdep.h:230
CORE_ADDR(* sigcontext_addr)(frame_info_ptr)
Definition i386-tdep.h:233
size_t sizeof_gregset
Definition i386-tdep.h:66