]>
Commit | Line | Data |
---|---|---|
871fbe6a | 1 | /* Target-dependent code for GNU/Linux i386. |
ca557f44 | 2 | |
1d506c26 | 3 | Copyright (C) 2000-2024 Free Software Foundation, Inc. |
e7ee86a9 JB |
4 | |
5 | This file is part of GDB. | |
6 | ||
7 | This program is free software; you can redistribute it and/or modify | |
8 | it under the terms of the GNU General Public License as published by | |
a9762ec7 | 9 | the Free Software Foundation; either version 3 of the License, or |
e7ee86a9 JB |
10 | (at your option) any later version. |
11 | ||
12 | This program is distributed in the hope that it will be useful, | |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
16 | ||
17 | You should have received a copy of the GNU General Public License | |
a9762ec7 | 18 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
e7ee86a9 | 19 | |
ec452525 | 20 | #include "extract-store-integer.h" |
e7ee86a9 JB |
21 | #include "gdbcore.h" |
22 | #include "frame.h" | |
23 | #include "value.h" | |
4e052eda | 24 | #include "regcache.h" |
c131fcee | 25 | #include "regset.h" |
6441c4a0 | 26 | #include "inferior.h" |
0670c0aa | 27 | #include "osabi.h" |
38c968cf | 28 | #include "reggroups.h" |
82ca8957 | 29 | #include "dwarf2/frame.h" |
8201327c MK |
30 | #include "i386-tdep.h" |
31 | #include "i386-linux-tdep.h" | |
4aa995e1 | 32 | #include "linux-tdep.h" |
012b3a21 | 33 | #include "utils.h" |
0670c0aa | 34 | #include "glibc-tdep.h" |
871fbe6a | 35 | #include "solib-svr4.h" |
982e9687 | 36 | #include "symtab.h" |
237fc4c9 | 37 | #include "arch-utils.h" |
a96d9b2e | 38 | #include "xml-syscall.h" |
fdb61c6c | 39 | #include "infrun.h" |
a96d9b2e | 40 | |
c131fcee | 41 | #include "i387-tdep.h" |
268a13a5 | 42 | #include "gdbsupport/x86-xstate.h" |
c131fcee | 43 | |
a96d9b2e SDJ |
44 | /* The syscall's XML filename for i386. */ |
45 | #define XML_SYSCALL_FILENAME_I386 "syscalls/i386-linux.xml" | |
17ea7499 | 46 | |
d02ed0bb | 47 | #include "record-full.h" |
77fcef51 | 48 | #include "linux-record.h" |
ea03d0d3 | 49 | |
5f035c07 | 50 | #include "arch/i386.h" |
f49ff000 | 51 | #include "target-descriptions.h" |
90884b2b | 52 | |
38c968cf AC |
53 | /* Return non-zero, when the register is in the corresponding register |
54 | group. Put the LINUX_ORIG_EAX register in the system group. */ | |
55 | static int | |
56 | i386_linux_register_reggroup_p (struct gdbarch *gdbarch, int regnum, | |
dbf5d61b | 57 | const struct reggroup *group) |
38c968cf AC |
58 | { |
59 | if (regnum == I386_LINUX_ORIG_EAX_REGNUM) | |
60 | return (group == system_reggroup | |
61 | || group == save_reggroup | |
62 | || group == restore_reggroup); | |
63 | return i386_register_reggroup_p (gdbarch, regnum, group); | |
64 | } | |
65 | ||
e7ee86a9 JB |
66 | \f |
67 | /* Recognizing signal handler frames. */ | |
68 | ||
ca557f44 | 69 | /* GNU/Linux has two flavors of signals. Normal signal handlers, and |
e7ee86a9 JB |
70 | "realtime" (RT) signals. The RT signals can provide additional |
71 | information to the signal handler if the SA_SIGINFO flag is set | |
72 | when establishing a signal handler using `sigaction'. It is not | |
ca557f44 AC |
73 | unlikely that future versions of GNU/Linux will support SA_SIGINFO |
74 | for normal signals too. */ | |
e7ee86a9 JB |
75 | |
76 | /* When the i386 Linux kernel calls a signal handler and the | |
77 | SA_RESTORER flag isn't set, the return address points to a bit of | |
78 | code on the stack. This function returns whether the PC appears to | |
79 | be within this bit of code. | |
80 | ||
81 | The instruction sequence for normal signals is | |
82 | pop %eax | |
acd5c798 | 83 | mov $0x77, %eax |
e7ee86a9 JB |
84 | int $0x80 |
85 | or 0x58 0xb8 0x77 0x00 0x00 0x00 0xcd 0x80. | |
86 | ||
87 | Checking for the code sequence should be somewhat reliable, because | |
88 | the effect is to call the system call sigreturn. This is unlikely | |
911bc6ee | 89 | to occur anywhere other than in a signal trampoline. |
e7ee86a9 JB |
90 | |
91 | It kind of sucks that we have to read memory from the process in | |
92 | order to identify a signal trampoline, but there doesn't seem to be | |
911bc6ee MK |
93 | any other way. Therefore we only do the memory reads if no |
94 | function name could be identified, which should be the case since | |
95 | the code is on the stack. | |
e7ee86a9 JB |
96 | |
97 | Detection of signal trampolines for handlers that set the | |
98 | SA_RESTORER flag is in general not possible. Unfortunately this is | |
99 | what the GNU C Library has been doing for quite some time now. | |
100 | However, as of version 2.1.2, the GNU C Library uses signal | |
101 | trampolines (named __restore and __restore_rt) that are identical | |
102 | to the ones used by the kernel. Therefore, these trampolines are | |
103 | supported too. */ | |
104 | ||
acd5c798 MK |
105 | #define LINUX_SIGTRAMP_INSN0 0x58 /* pop %eax */ |
106 | #define LINUX_SIGTRAMP_OFFSET0 0 | |
107 | #define LINUX_SIGTRAMP_INSN1 0xb8 /* mov $NNNN, %eax */ | |
108 | #define LINUX_SIGTRAMP_OFFSET1 1 | |
109 | #define LINUX_SIGTRAMP_INSN2 0xcd /* int */ | |
110 | #define LINUX_SIGTRAMP_OFFSET2 6 | |
e7ee86a9 | 111 | |
4252dc94 | 112 | static const gdb_byte linux_sigtramp_code[] = |
e7ee86a9 JB |
113 | { |
114 | LINUX_SIGTRAMP_INSN0, /* pop %eax */ | |
acd5c798 | 115 | LINUX_SIGTRAMP_INSN1, 0x77, 0x00, 0x00, 0x00, /* mov $0x77, %eax */ |
e7ee86a9 JB |
116 | LINUX_SIGTRAMP_INSN2, 0x80 /* int $0x80 */ |
117 | }; | |
118 | ||
119 | #define LINUX_SIGTRAMP_LEN (sizeof linux_sigtramp_code) | |
120 | ||
10458914 DJ |
121 | /* If THIS_FRAME is a sigtramp routine, return the address of the |
122 | start of the routine. Otherwise, return 0. */ | |
e7ee86a9 JB |
123 | |
124 | static CORE_ADDR | |
8480a37e | 125 | i386_linux_sigtramp_start (const frame_info_ptr &this_frame) |
e7ee86a9 | 126 | { |
10458914 | 127 | CORE_ADDR pc = get_frame_pc (this_frame); |
4252dc94 | 128 | gdb_byte buf[LINUX_SIGTRAMP_LEN]; |
e7ee86a9 JB |
129 | |
130 | /* We only recognize a signal trampoline if PC is at the start of | |
131 | one of the three instructions. We optimize for finding the PC at | |
132 | the start, as will be the case when the trampoline is not the | |
133 | first frame on the stack. We assume that in the case where the | |
134 | PC is not at the start of the instruction sequence, there will be | |
135 | a few trailing readable bytes on the stack. */ | |
136 | ||
bdec2917 | 137 | if (!safe_frame_unwind_memory (this_frame, pc, buf)) |
e7ee86a9 JB |
138 | return 0; |
139 | ||
140 | if (buf[0] != LINUX_SIGTRAMP_INSN0) | |
141 | { | |
142 | int adjust; | |
143 | ||
144 | switch (buf[0]) | |
145 | { | |
146 | case LINUX_SIGTRAMP_INSN1: | |
147 | adjust = LINUX_SIGTRAMP_OFFSET1; | |
148 | break; | |
149 | case LINUX_SIGTRAMP_INSN2: | |
150 | adjust = LINUX_SIGTRAMP_OFFSET2; | |
151 | break; | |
152 | default: | |
153 | return 0; | |
154 | } | |
155 | ||
156 | pc -= adjust; | |
157 | ||
bdec2917 | 158 | if (!safe_frame_unwind_memory (this_frame, pc, buf)) |
e7ee86a9 JB |
159 | return 0; |
160 | } | |
161 | ||
162 | if (memcmp (buf, linux_sigtramp_code, LINUX_SIGTRAMP_LEN) != 0) | |
163 | return 0; | |
164 | ||
165 | return pc; | |
166 | } | |
167 | ||
168 | /* This function does the same for RT signals. Here the instruction | |
169 | sequence is | |
acd5c798 | 170 | mov $0xad, %eax |
e7ee86a9 JB |
171 | int $0x80 |
172 | or 0xb8 0xad 0x00 0x00 0x00 0xcd 0x80. | |
173 | ||
174 | The effect is to call the system call rt_sigreturn. */ | |
175 | ||
acd5c798 MK |
176 | #define LINUX_RT_SIGTRAMP_INSN0 0xb8 /* mov $NNNN, %eax */ |
177 | #define LINUX_RT_SIGTRAMP_OFFSET0 0 | |
178 | #define LINUX_RT_SIGTRAMP_INSN1 0xcd /* int */ | |
179 | #define LINUX_RT_SIGTRAMP_OFFSET1 5 | |
e7ee86a9 | 180 | |
4252dc94 | 181 | static const gdb_byte linux_rt_sigtramp_code[] = |
e7ee86a9 | 182 | { |
acd5c798 | 183 | LINUX_RT_SIGTRAMP_INSN0, 0xad, 0x00, 0x00, 0x00, /* mov $0xad, %eax */ |
e7ee86a9 JB |
184 | LINUX_RT_SIGTRAMP_INSN1, 0x80 /* int $0x80 */ |
185 | }; | |
186 | ||
187 | #define LINUX_RT_SIGTRAMP_LEN (sizeof linux_rt_sigtramp_code) | |
188 | ||
10458914 DJ |
189 | /* If THIS_FRAME is an RT sigtramp routine, return the address of the |
190 | start of the routine. Otherwise, return 0. */ | |
e7ee86a9 JB |
191 | |
192 | static CORE_ADDR | |
8480a37e | 193 | i386_linux_rt_sigtramp_start (const frame_info_ptr &this_frame) |
e7ee86a9 | 194 | { |
10458914 | 195 | CORE_ADDR pc = get_frame_pc (this_frame); |
4252dc94 | 196 | gdb_byte buf[LINUX_RT_SIGTRAMP_LEN]; |
e7ee86a9 JB |
197 | |
198 | /* We only recognize a signal trampoline if PC is at the start of | |
199 | one of the two instructions. We optimize for finding the PC at | |
200 | the start, as will be the case when the trampoline is not the | |
201 | first frame on the stack. We assume that in the case where the | |
202 | PC is not at the start of the instruction sequence, there will be | |
203 | a few trailing readable bytes on the stack. */ | |
204 | ||
bdec2917 | 205 | if (!safe_frame_unwind_memory (this_frame, pc, buf)) |
e7ee86a9 JB |
206 | return 0; |
207 | ||
208 | if (buf[0] != LINUX_RT_SIGTRAMP_INSN0) | |
209 | { | |
210 | if (buf[0] != LINUX_RT_SIGTRAMP_INSN1) | |
211 | return 0; | |
212 | ||
213 | pc -= LINUX_RT_SIGTRAMP_OFFSET1; | |
214 | ||
bdec2917 LM |
215 | if (!safe_frame_unwind_memory (this_frame, pc, |
216 | buf)) | |
e7ee86a9 JB |
217 | return 0; |
218 | } | |
219 | ||
220 | if (memcmp (buf, linux_rt_sigtramp_code, LINUX_RT_SIGTRAMP_LEN) != 0) | |
221 | return 0; | |
222 | ||
223 | return pc; | |
224 | } | |
225 | ||
10458914 DJ |
226 | /* Return whether THIS_FRAME corresponds to a GNU/Linux sigtramp |
227 | routine. */ | |
e7ee86a9 | 228 | |
8201327c | 229 | static int |
8480a37e | 230 | i386_linux_sigtramp_p (const frame_info_ptr &this_frame) |
e7ee86a9 | 231 | { |
10458914 | 232 | CORE_ADDR pc = get_frame_pc (this_frame); |
2c02bd72 | 233 | const char *name; |
911bc6ee MK |
234 | |
235 | find_pc_partial_function (pc, &name, NULL, NULL); | |
236 | ||
ef17e74b DJ |
237 | /* If we have NAME, we can optimize the search. The trampolines are |
238 | named __restore and __restore_rt. However, they aren't dynamically | |
239 | exported from the shared C library, so the trampoline may appear to | |
240 | be part of the preceding function. This should always be sigaction, | |
241 | __sigaction, or __libc_sigaction (all aliases to the same function). */ | |
242 | if (name == NULL || strstr (name, "sigaction") != NULL) | |
10458914 DJ |
243 | return (i386_linux_sigtramp_start (this_frame) != 0 |
244 | || i386_linux_rt_sigtramp_start (this_frame) != 0); | |
ef17e74b DJ |
245 | |
246 | return (strcmp ("__restore", name) == 0 | |
247 | || strcmp ("__restore_rt", name) == 0); | |
e7ee86a9 JB |
248 | } |
249 | ||
4a4e5149 DJ |
250 | /* Return one if the PC of THIS_FRAME is in a signal trampoline which |
251 | may have DWARF-2 CFI. */ | |
12b8a2cb DJ |
252 | |
253 | static int | |
254 | i386_linux_dwarf_signal_frame_p (struct gdbarch *gdbarch, | |
8480a37e | 255 | const frame_info_ptr &this_frame) |
12b8a2cb | 256 | { |
4a4e5149 | 257 | CORE_ADDR pc = get_frame_pc (this_frame); |
2c02bd72 | 258 | const char *name; |
12b8a2cb DJ |
259 | |
260 | find_pc_partial_function (pc, &name, NULL, NULL); | |
261 | ||
262 | /* If a vsyscall DSO is in use, the signal trampolines may have these | |
263 | names. */ | |
264 | if (name && (strcmp (name, "__kernel_sigreturn") == 0 | |
265 | || strcmp (name, "__kernel_rt_sigreturn") == 0)) | |
266 | return 1; | |
267 | ||
268 | return 0; | |
269 | } | |
270 | ||
acd5c798 MK |
271 | /* Offset to struct sigcontext in ucontext, from <asm/ucontext.h>. */ |
272 | #define I386_LINUX_UCONTEXT_SIGCONTEXT_OFFSET 20 | |
273 | ||
10458914 DJ |
274 | /* Assuming THIS_FRAME is a GNU/Linux sigtramp routine, return the |
275 | address of the associated sigcontext structure. */ | |
e7ee86a9 | 276 | |
b7d15bf7 | 277 | static CORE_ADDR |
8480a37e | 278 | i386_linux_sigcontext_addr (const frame_info_ptr &this_frame) |
e7ee86a9 | 279 | { |
e17a4113 UW |
280 | struct gdbarch *gdbarch = get_frame_arch (this_frame); |
281 | enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); | |
e7ee86a9 | 282 | CORE_ADDR pc; |
acd5c798 | 283 | CORE_ADDR sp; |
4252dc94 | 284 | gdb_byte buf[4]; |
acd5c798 | 285 | |
10458914 | 286 | get_frame_register (this_frame, I386_ESP_REGNUM, buf); |
e17a4113 | 287 | sp = extract_unsigned_integer (buf, 4, byte_order); |
e7ee86a9 | 288 | |
10458914 | 289 | pc = i386_linux_sigtramp_start (this_frame); |
e7ee86a9 JB |
290 | if (pc) |
291 | { | |
acd5c798 MK |
292 | /* The sigcontext structure lives on the stack, right after |
293 | the signum argument. We determine the address of the | |
294 | sigcontext structure by looking at the frame's stack | |
295 | pointer. Keep in mind that the first instruction of the | |
296 | sigtramp code is "pop %eax". If the PC is after this | |
297 | instruction, adjust the returned value accordingly. */ | |
10458914 | 298 | if (pc == get_frame_pc (this_frame)) |
e7ee86a9 JB |
299 | return sp + 4; |
300 | return sp; | |
301 | } | |
302 | ||
10458914 | 303 | pc = i386_linux_rt_sigtramp_start (this_frame); |
e7ee86a9 JB |
304 | if (pc) |
305 | { | |
acd5c798 MK |
306 | CORE_ADDR ucontext_addr; |
307 | ||
308 | /* The sigcontext structure is part of the user context. A | |
309 | pointer to the user context is passed as the third argument | |
310 | to the signal handler. */ | |
311 | read_memory (sp + 8, buf, 4); | |
e17a4113 | 312 | ucontext_addr = extract_unsigned_integer (buf, 4, byte_order); |
acd5c798 | 313 | return ucontext_addr + I386_LINUX_UCONTEXT_SIGCONTEXT_OFFSET; |
e7ee86a9 JB |
314 | } |
315 | ||
8a3fe4f8 | 316 | error (_("Couldn't recognize signal trampoline.")); |
e7ee86a9 JB |
317 | return 0; |
318 | } | |
319 | ||
6441c4a0 MK |
320 | /* Set the program counter for process PTID to PC. */ |
321 | ||
8201327c | 322 | static void |
61a1198a | 323 | i386_linux_write_pc (struct regcache *regcache, CORE_ADDR pc) |
6441c4a0 | 324 | { |
61a1198a | 325 | regcache_cooked_write_unsigned (regcache, I386_EIP_REGNUM, pc); |
6441c4a0 MK |
326 | |
327 | /* We must be careful with modifying the program counter. If we | |
328 | just interrupted a system call, the kernel might try to restart | |
329 | it when we resume the inferior. On restarting the system call, | |
330 | the kernel will try backing up the program counter even though it | |
331 | no longer points at the system call. This typically results in a | |
332 | SIGSEGV or SIGILL. We can prevent this by writing `-1' in the | |
333 | "orig_eax" pseudo-register. | |
334 | ||
335 | Note that "orig_eax" is saved when setting up a dummy call frame. | |
336 | This means that it is properly restored when that frame is | |
337 | popped, and that the interrupted system call will be restarted | |
338 | when we resume the inferior on return from a function call from | |
339 | within GDB. In all other cases the system call will not be | |
340 | restarted. */ | |
61a1198a | 341 | regcache_cooked_write_unsigned (regcache, I386_LINUX_ORIG_EAX_REGNUM, -1); |
6441c4a0 | 342 | } |
77fcef51 | 343 | |
8a2e0e28 HZ |
344 | /* Record all registers but IP register for process-record. */ |
345 | ||
346 | static int | |
347 | i386_all_but_ip_registers_record (struct regcache *regcache) | |
348 | { | |
25ea693b | 349 | if (record_full_arch_list_add_reg (regcache, I386_EAX_REGNUM)) |
8a2e0e28 | 350 | return -1; |
25ea693b | 351 | if (record_full_arch_list_add_reg (regcache, I386_ECX_REGNUM)) |
8a2e0e28 | 352 | return -1; |
25ea693b | 353 | if (record_full_arch_list_add_reg (regcache, I386_EDX_REGNUM)) |
8a2e0e28 | 354 | return -1; |
25ea693b | 355 | if (record_full_arch_list_add_reg (regcache, I386_EBX_REGNUM)) |
8a2e0e28 | 356 | return -1; |
25ea693b | 357 | if (record_full_arch_list_add_reg (regcache, I386_ESP_REGNUM)) |
8a2e0e28 | 358 | return -1; |
25ea693b | 359 | if (record_full_arch_list_add_reg (regcache, I386_EBP_REGNUM)) |
8a2e0e28 | 360 | return -1; |
25ea693b | 361 | if (record_full_arch_list_add_reg (regcache, I386_ESI_REGNUM)) |
8a2e0e28 | 362 | return -1; |
25ea693b | 363 | if (record_full_arch_list_add_reg (regcache, I386_EDI_REGNUM)) |
8a2e0e28 | 364 | return -1; |
25ea693b | 365 | if (record_full_arch_list_add_reg (regcache, I386_EFLAGS_REGNUM)) |
8a2e0e28 HZ |
366 | return -1; |
367 | ||
368 | return 0; | |
369 | } | |
13b6d1d4 MS |
370 | |
371 | /* i386_canonicalize_syscall maps from the native i386 Linux set | |
372 | of syscall ids into a canonical set of syscall ids used by | |
373 | process record (a mostly trivial mapping, since the canonical | |
374 | set was originally taken from the i386 set). */ | |
375 | ||
376 | static enum gdb_syscall | |
377 | i386_canonicalize_syscall (int syscall) | |
378 | { | |
379 | enum { i386_syscall_max = 499 }; | |
380 | ||
381 | if (syscall <= i386_syscall_max) | |
aead7601 | 382 | return (enum gdb_syscall) syscall; |
13b6d1d4 | 383 | else |
f486487f | 384 | return gdb_sys_no_syscall; |
13b6d1d4 MS |
385 | } |
386 | ||
012b3a21 WT |
387 | /* Value of the sigcode in case of a boundary fault. */ |
388 | ||
3bfdcabb | 389 | #define SIG_CODE_BOUNDARY_FAULT 3 |
012b3a21 | 390 | |
77bdfeb2 | 391 | /* i386 GNU/Linux implementation of the report_signal_info |
012b3a21 WT |
392 | gdbarch hook. Displays information related to MPX bound |
393 | violations. */ | |
394 | void | |
77bdfeb2 JB |
395 | i386_linux_report_signal_info (struct gdbarch *gdbarch, struct ui_out *uiout, |
396 | enum gdb_signal siggnal) | |
012b3a21 | 397 | { |
166616ce SM |
398 | /* -Wmaybe-uninitialized */ |
399 | CORE_ADDR lower_bound = 0, upper_bound = 0, access = 0; | |
012b3a21 WT |
400 | int is_upper; |
401 | long sig_code = 0; | |
402 | ||
77bdfeb2 | 403 | if (!i386_mpx_enabled () || siggnal != GDB_SIGNAL_SEGV) |
012b3a21 WT |
404 | return; |
405 | ||
a70b8144 | 406 | try |
012b3a21 WT |
407 | { |
408 | /* Sigcode evaluates if the actual segfault is a boundary violation. */ | |
409 | sig_code = parse_and_eval_long ("$_siginfo.si_code\n"); | |
410 | ||
411 | lower_bound | |
dda83cd7 | 412 | = parse_and_eval_long ("$_siginfo._sifields._sigfault._addr_bnd._lower"); |
012b3a21 | 413 | upper_bound |
dda83cd7 | 414 | = parse_and_eval_long ("$_siginfo._sifields._sigfault._addr_bnd._upper"); |
012b3a21 | 415 | access |
dda83cd7 | 416 | = parse_and_eval_long ("$_siginfo._sifields._sigfault.si_addr"); |
012b3a21 | 417 | } |
b1ffd112 | 418 | catch (const gdb_exception_error &exception) |
012b3a21 WT |
419 | { |
420 | return; | |
421 | } | |
012b3a21 WT |
422 | |
423 | /* If this is not a boundary violation just return. */ | |
3bfdcabb | 424 | if (sig_code != SIG_CODE_BOUNDARY_FAULT) |
012b3a21 WT |
425 | return; |
426 | ||
427 | is_upper = (access > upper_bound ? 1 : 0); | |
428 | ||
112e8700 | 429 | uiout->text ("\n"); |
012b3a21 | 430 | if (is_upper) |
112e8700 | 431 | uiout->field_string ("sigcode-meaning", _("Upper bound violation")); |
012b3a21 | 432 | else |
112e8700 | 433 | uiout->field_string ("sigcode-meaning", _("Lower bound violation")); |
012b3a21 | 434 | |
112e8700 | 435 | uiout->text (_(" while accessing address ")); |
ca8d69be | 436 | uiout->field_core_addr ("bound-access", gdbarch, access); |
012b3a21 | 437 | |
112e8700 | 438 | uiout->text (_("\nBounds: [lower = ")); |
ca8d69be | 439 | uiout->field_core_addr ("lower-bound", gdbarch, lower_bound); |
012b3a21 | 440 | |
112e8700 | 441 | uiout->text (_(", upper = ")); |
ca8d69be | 442 | uiout->field_core_addr ("upper-bound", gdbarch, upper_bound); |
012b3a21 | 443 | |
112e8700 | 444 | uiout->text (_("]")); |
012b3a21 WT |
445 | } |
446 | ||
77fcef51 HZ |
447 | /* Parse the arguments of current system call instruction and record |
448 | the values of the registers and memory that will be changed into | |
449 | "record_arch_list". This instruction is "int 0x80" (Linux | |
450 | Kernel2.4) or "sysenter" (Linux Kernel 2.6). | |
451 | ||
452 | Return -1 if something wrong. */ | |
453 | ||
8a2e0e28 HZ |
454 | static struct linux_record_tdep i386_linux_record_tdep; |
455 | ||
77fcef51 | 456 | static int |
ffdf6de5 | 457 | i386_linux_intx80_sysenter_syscall_record (struct regcache *regcache) |
77fcef51 HZ |
458 | { |
459 | int ret; | |
13b6d1d4 MS |
460 | LONGEST syscall_native; |
461 | enum gdb_syscall syscall_gdb; | |
462 | ||
463 | regcache_raw_read_signed (regcache, I386_EAX_REGNUM, &syscall_native); | |
77fcef51 | 464 | |
13b6d1d4 | 465 | syscall_gdb = i386_canonicalize_syscall (syscall_native); |
2c543fc4 | 466 | |
13b6d1d4 | 467 | if (syscall_gdb < 0) |
2c543fc4 | 468 | { |
6cb06a8c TT |
469 | gdb_printf (gdb_stderr, |
470 | _("Process record and replay target doesn't " | |
471 | "support syscall number %s\n"), | |
472 | plongest (syscall_native)); | |
2c543fc4 HZ |
473 | return -1; |
474 | } | |
77fcef51 | 475 | |
8a2e0e28 HZ |
476 | if (syscall_gdb == gdb_sys_sigreturn |
477 | || syscall_gdb == gdb_sys_rt_sigreturn) | |
478 | { | |
479 | if (i386_all_but_ip_registers_record (regcache)) | |
480 | return -1; | |
481 | return 0; | |
482 | } | |
483 | ||
13b6d1d4 | 484 | ret = record_linux_system_call (syscall_gdb, regcache, |
77fcef51 HZ |
485 | &i386_linux_record_tdep); |
486 | if (ret) | |
487 | return ret; | |
488 | ||
489 | /* Record the return value of the system call. */ | |
25ea693b | 490 | if (record_full_arch_list_add_reg (regcache, I386_EAX_REGNUM)) |
77fcef51 HZ |
491 | return -1; |
492 | ||
493 | return 0; | |
494 | } | |
8a2e0e28 HZ |
495 | |
496 | #define I386_LINUX_xstate 270 | |
497 | #define I386_LINUX_frame_size 732 | |
498 | ||
70221824 | 499 | static int |
8a2e0e28 | 500 | i386_linux_record_signal (struct gdbarch *gdbarch, |
dda83cd7 SM |
501 | struct regcache *regcache, |
502 | enum gdb_signal signal) | |
8a2e0e28 HZ |
503 | { |
504 | ULONGEST esp; | |
505 | ||
506 | if (i386_all_but_ip_registers_record (regcache)) | |
507 | return -1; | |
508 | ||
25ea693b | 509 | if (record_full_arch_list_add_reg (regcache, I386_EIP_REGNUM)) |
8a2e0e28 HZ |
510 | return -1; |
511 | ||
512 | /* Record the change in the stack. */ | |
513 | regcache_raw_read_unsigned (regcache, I386_ESP_REGNUM, &esp); | |
514 | /* This is for xstate. | |
515 | sp -= sizeof (struct _fpstate); */ | |
516 | esp -= I386_LINUX_xstate; | |
517 | /* This is for frame_size. | |
518 | sp -= sizeof (struct rt_sigframe); */ | |
519 | esp -= I386_LINUX_frame_size; | |
25ea693b MM |
520 | if (record_full_arch_list_add_mem (esp, |
521 | I386_LINUX_xstate + I386_LINUX_frame_size)) | |
8a2e0e28 HZ |
522 | return -1; |
523 | ||
25ea693b | 524 | if (record_full_arch_list_add_end ()) |
8a2e0e28 HZ |
525 | return -1; |
526 | ||
527 | return 0; | |
528 | } | |
6441c4a0 | 529 | \f |
8201327c | 530 | |
9a7f938f JK |
531 | /* Core of the implementation for gdbarch get_syscall_number. Get pending |
532 | syscall number from REGCACHE. If there is no pending syscall -1 will be | |
533 | returned. Pending syscall means ptrace has stepped into the syscall but | |
534 | another ptrace call will step out. PC is right after the int $0x80 | |
535 | / syscall / sysenter instruction in both cases, PC does not change during | |
536 | the second ptrace step. */ | |
537 | ||
a96d9b2e | 538 | static LONGEST |
9a7f938f | 539 | i386_linux_get_syscall_number_from_regcache (struct regcache *regcache) |
a96d9b2e | 540 | { |
ac7936df | 541 | struct gdbarch *gdbarch = regcache->arch (); |
a96d9b2e SDJ |
542 | enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); |
543 | /* The content of a register. */ | |
544 | gdb_byte buf[4]; | |
545 | /* The result. */ | |
546 | LONGEST ret; | |
547 | ||
548 | /* Getting the system call number from the register. | |
549 | When dealing with x86 architecture, this information | |
550 | is stored at %eax register. */ | |
dca08e1f | 551 | regcache->cooked_read (I386_LINUX_ORIG_EAX_REGNUM, buf); |
a96d9b2e | 552 | |
2a50938a | 553 | ret = extract_signed_integer (buf, byte_order); |
a96d9b2e SDJ |
554 | |
555 | return ret; | |
556 | } | |
557 | ||
9a7f938f JK |
558 | /* Wrapper for i386_linux_get_syscall_number_from_regcache to make it |
559 | compatible with gdbarch get_syscall_number method prototype. */ | |
560 | ||
561 | static LONGEST | |
562 | i386_linux_get_syscall_number (struct gdbarch *gdbarch, | |
00431a78 | 563 | thread_info *thread) |
9a7f938f | 564 | { |
00431a78 | 565 | struct regcache *regcache = get_thread_regcache (thread); |
9a7f938f JK |
566 | |
567 | return i386_linux_get_syscall_number_from_regcache (regcache); | |
568 | } | |
569 | ||
e9f1aad5 MK |
570 | /* The register sets used in GNU/Linux ELF core-dumps are identical to |
571 | the register sets in `struct user' that are used for a.out | |
572 | core-dumps. These are also used by ptrace(2). The corresponding | |
573 | types are `elf_gregset_t' for the general-purpose registers (with | |
574 | `elf_greg_t' the type of a single GP register) and `elf_fpregset_t' | |
575 | for the floating-point registers. | |
576 | ||
577 | Those types used to be available under the names `gregset_t' and | |
578 | `fpregset_t' too, and GDB used those names in the past. But those | |
579 | names are now used for the register sets used in the `mcontext_t' | |
580 | type, which have a different size and layout. */ | |
581 | ||
582 | /* Mapping between the general-purpose registers in `struct user' | |
583 | format and GDB's register cache layout. */ | |
584 | ||
585 | /* From <sys/reg.h>. */ | |
be0d2954 | 586 | int i386_linux_gregset_reg_offset[] = |
e9f1aad5 MK |
587 | { |
588 | 6 * 4, /* %eax */ | |
589 | 1 * 4, /* %ecx */ | |
590 | 2 * 4, /* %edx */ | |
591 | 0 * 4, /* %ebx */ | |
592 | 15 * 4, /* %esp */ | |
593 | 5 * 4, /* %ebp */ | |
594 | 3 * 4, /* %esi */ | |
595 | 4 * 4, /* %edi */ | |
596 | 12 * 4, /* %eip */ | |
597 | 14 * 4, /* %eflags */ | |
598 | 13 * 4, /* %cs */ | |
599 | 16 * 4, /* %ss */ | |
600 | 7 * 4, /* %ds */ | |
601 | 8 * 4, /* %es */ | |
602 | 9 * 4, /* %fs */ | |
603 | 10 * 4, /* %gs */ | |
604 | -1, -1, -1, -1, -1, -1, -1, -1, | |
605 | -1, -1, -1, -1, -1, -1, -1, -1, | |
606 | -1, -1, -1, -1, -1, -1, -1, -1, | |
607 | -1, | |
c131fcee | 608 | -1, -1, -1, -1, -1, -1, -1, -1, |
01f9f808 MS |
609 | -1, -1, -1, -1, /* MPX registers BND0 ... BND3. */ |
610 | -1, -1, /* MPX registers BNDCFGU, BNDSTATUS. */ | |
611 | -1, -1, -1, -1, -1, -1, -1, -1, /* k0 ... k7 (AVX512) */ | |
612 | -1, -1, -1, -1, -1, -1, -1, -1, /* zmm0 ... zmm7 (AVX512) */ | |
51547df6 | 613 | -1, /* PKRU register */ |
01f9f808 | 614 | 11 * 4, /* "orig_eax" */ |
e9f1aad5 MK |
615 | }; |
616 | ||
617 | /* Mapping between the general-purpose registers in `struct | |
618 | sigcontext' format and GDB's register cache layout. */ | |
619 | ||
a3386186 | 620 | /* From <asm/sigcontext.h>. */ |
bb489b3c | 621 | static int i386_linux_sc_reg_offset[] = |
a3386186 MK |
622 | { |
623 | 11 * 4, /* %eax */ | |
624 | 10 * 4, /* %ecx */ | |
625 | 9 * 4, /* %edx */ | |
626 | 8 * 4, /* %ebx */ | |
627 | 7 * 4, /* %esp */ | |
628 | 6 * 4, /* %ebp */ | |
629 | 5 * 4, /* %esi */ | |
630 | 4 * 4, /* %edi */ | |
631 | 14 * 4, /* %eip */ | |
632 | 16 * 4, /* %eflags */ | |
633 | 15 * 4, /* %cs */ | |
634 | 18 * 4, /* %ss */ | |
635 | 3 * 4, /* %ds */ | |
636 | 2 * 4, /* %es */ | |
637 | 1 * 4, /* %fs */ | |
638 | 0 * 4 /* %gs */ | |
639 | }; | |
640 | ||
b42405a1 | 641 | /* See i386-linux-tdep.h. */ |
c131fcee L |
642 | |
643 | uint64_t | |
b42405a1 | 644 | i386_linux_core_read_xsave_info (bfd *abfd, x86_xsave_layout &layout) |
c131fcee L |
645 | { |
646 | asection *xstate = bfd_get_section_by_name (abfd, ".reg-xstate"); | |
b42405a1 JB |
647 | if (xstate == nullptr) |
648 | return 0; | |
c131fcee | 649 | |
b42405a1 JB |
650 | /* Check extended state size. */ |
651 | size_t size = bfd_section_size (xstate); | |
652 | if (size < X86_XSTATE_AVX_SIZE) | |
653 | return 0; | |
c131fcee | 654 | |
b42405a1 JB |
655 | char contents[8]; |
656 | if (! bfd_get_section_contents (abfd, xstate, contents, | |
657 | I386_LINUX_XSAVE_XCR0_OFFSET, 8)) | |
658 | { | |
659 | warning (_("Couldn't read `xcr0' bytes from " | |
660 | "`.reg-xstate' section in core file.")); | |
661 | return 0; | |
c131fcee | 662 | } |
b42405a1 JB |
663 | |
664 | uint64_t xcr0 = bfd_get_64 (abfd, contents); | |
665 | ||
666 | if (!i387_guess_xsave_layout (xcr0, size, layout)) | |
667 | return 0; | |
c131fcee L |
668 | |
669 | return xcr0; | |
670 | } | |
671 | ||
35b4818d | 672 | /* See i386-linux-tdep.h. */ |
90884b2b | 673 | |
b42405a1 JB |
674 | bool |
675 | i386_linux_core_read_x86_xsave_layout (struct gdbarch *gdbarch, | |
676 | x86_xsave_layout &layout) | |
677 | { | |
6fdf95ae SM |
678 | return i386_linux_core_read_xsave_info (current_program_space->core_bfd (), |
679 | layout) != 0; | |
b42405a1 JB |
680 | } |
681 | ||
69324a74 | 682 | /* See i386-linux-tdep.h. */ |
b42405a1 | 683 | |
69324a74 AB |
684 | const struct target_desc * |
685 | i386_linux_read_description (uint64_t xcr0) | |
90884b2b | 686 | { |
69324a74 AB |
687 | if (xcr0 == 0) |
688 | return NULL; | |
689 | ||
690 | static struct target_desc *i386_linux_tdescs \ | |
691 | [2/*X87*/][2/*SSE*/][2/*AVX*/][2/*MPX*/][2/*AVX512*/][2/*PKRU*/] = {}; | |
692 | struct target_desc **tdesc; | |
693 | ||
694 | tdesc = &i386_linux_tdescs[(xcr0 & X86_XSTATE_X87) ? 1 : 0] | |
695 | [(xcr0 & X86_XSTATE_SSE) ? 1 : 0] | |
696 | [(xcr0 & X86_XSTATE_AVX) ? 1 : 0] | |
697 | [(xcr0 & X86_XSTATE_MPX) ? 1 : 0] | |
698 | [(xcr0 & X86_XSTATE_AVX512) ? 1 : 0] | |
699 | [(xcr0 & X86_XSTATE_PKRU) ? 1 : 0]; | |
700 | ||
701 | if (*tdesc == NULL) | |
702 | *tdesc = i386_create_target_description (xcr0, true, false); | |
703 | ||
704 | return *tdesc; | |
35b4818d YQ |
705 | } |
706 | ||
707 | /* Get Linux/x86 target description from core dump. */ | |
708 | ||
709 | static const struct target_desc * | |
710 | i386_linux_core_read_description (struct gdbarch *gdbarch, | |
711 | struct target_ops *target, | |
712 | bfd *abfd) | |
713 | { | |
714 | /* Linux/i386. */ | |
b42405a1 JB |
715 | x86_xsave_layout layout; |
716 | uint64_t xcr0 = i386_linux_core_read_xsave_info (abfd, layout); | |
69324a74 | 717 | const struct target_desc *tdesc = i386_linux_read_description (xcr0); |
35b4818d | 718 | |
c1738907 AB |
719 | if (tdesc != NULL) |
720 | return tdesc; | |
721 | ||
722 | if (bfd_get_section_by_name (abfd, ".reg-xfp") != NULL) | |
723 | return i386_linux_read_description (X86_XSTATE_SSE_MASK); | |
724 | else | |
725 | return i386_linux_read_description (X86_XSTATE_X87_MASK); | |
90884b2b L |
726 | } |
727 | ||
8f0435f7 AA |
728 | /* Similar to i386_supply_fpregset, but use XSAVE extended state. */ |
729 | ||
730 | static void | |
731 | i386_linux_supply_xstateregset (const struct regset *regset, | |
732 | struct regcache *regcache, int regnum, | |
733 | const void *xstateregs, size_t len) | |
734 | { | |
735 | i387_supply_xsave (regcache, regnum, xstateregs); | |
736 | } | |
737 | ||
190b495d WT |
738 | struct type * |
739 | x86_linux_get_siginfo_type (struct gdbarch *gdbarch) | |
740 | { | |
741 | return linux_get_siginfo_type_with_fields (gdbarch, LINUX_SIGINFO_FIELD_ADDR_BND); | |
742 | } | |
743 | ||
8f0435f7 AA |
744 | /* Similar to i386_collect_fpregset, but use XSAVE extended state. */ |
745 | ||
746 | static void | |
747 | i386_linux_collect_xstateregset (const struct regset *regset, | |
748 | const struct regcache *regcache, | |
749 | int regnum, void *xstateregs, size_t len) | |
750 | { | |
751 | i387_collect_xsave (regcache, regnum, xstateregs, 1); | |
752 | } | |
753 | ||
754 | /* Register set definitions. */ | |
755 | ||
756 | static const struct regset i386_linux_xstateregset = | |
757 | { | |
758 | NULL, | |
759 | i386_linux_supply_xstateregset, | |
760 | i386_linux_collect_xstateregset | |
761 | }; | |
762 | ||
5aa82d05 AA |
763 | /* Iterate over core file register note sections. */ |
764 | ||
765 | static void | |
766 | i386_linux_iterate_over_regset_sections (struct gdbarch *gdbarch, | |
767 | iterate_over_regset_sections_cb *cb, | |
768 | void *cb_data, | |
769 | const struct regcache *regcache) | |
770 | { | |
08106042 | 771 | i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch); |
5aa82d05 | 772 | |
a616bb94 | 773 | cb (".reg", 68, 68, &i386_gregset, NULL, cb_data); |
5aa82d05 | 774 | |
b42405a1 JB |
775 | if (tdep->xsave_layout.sizeof_xsave != 0) |
776 | cb (".reg-xstate", tdep->xsave_layout.sizeof_xsave, | |
777 | tdep->xsave_layout.sizeof_xsave, &i386_linux_xstateregset, | |
a616bb94 | 778 | "XSAVE extended state", cb_data); |
5aa82d05 | 779 | else if (tdep->xcr0 & X86_XSTATE_SSE) |
a616bb94 | 780 | cb (".reg-xfp", 512, 512, &i386_fpregset, "extended floating-point", |
8f0435f7 | 781 | cb_data); |
5aa82d05 | 782 | else |
a616bb94 | 783 | cb (".reg2", 108, 108, &i386_fpregset, NULL, cb_data); |
5aa82d05 AA |
784 | } |
785 | ||
9a7f938f JK |
786 | /* Linux kernel shows PC value after the 'int $0x80' instruction even if |
787 | inferior is still inside the syscall. On next PTRACE_SINGLESTEP it will | |
788 | finish the syscall but PC will not change. | |
789 | ||
790 | Some vDSOs contain 'int $0x80; ret' and during stepping out of the syscall | |
791 | i386_displaced_step_fixup would keep PC at the displaced pad location. | |
792 | As PC is pointing to the 'ret' instruction before the step | |
793 | i386_displaced_step_fixup would expect inferior has just executed that 'ret' | |
794 | and PC should not be adjusted. In reality it finished syscall instead and | |
795 | PC should get relocated back to its vDSO address. Hide the 'ret' | |
796 | instruction by 'nop' so that i386_displaced_step_fixup is not confused. | |
797 | ||
1152d984 SM |
798 | It is not fully correct as the bytes in struct |
799 | displaced_step_copy_insn_closure will not match the inferior code. But we | |
800 | would need some new flag in displaced_step_copy_insn_closure otherwise to | |
801 | keep the state that syscall is finishing for the later | |
802 | i386_displaced_step_fixup execution as the syscall execution is already no | |
803 | longer detectable there. The new flag field would mean i386-linux-tdep.c | |
804 | needs to wrap all the displacement methods of i386-tdep.c which does not seem | |
805 | worth it. The same effect is achieved by patching that 'nop' instruction | |
806 | there instead. */ | |
807 | ||
808 | static displaced_step_copy_insn_closure_up | |
9a7f938f JK |
809 | i386_linux_displaced_step_copy_insn (struct gdbarch *gdbarch, |
810 | CORE_ADDR from, CORE_ADDR to, | |
811 | struct regcache *regs) | |
812 | { | |
1152d984 | 813 | displaced_step_copy_insn_closure_up closure_ |
cfba9872 | 814 | = i386_displaced_step_copy_insn (gdbarch, from, to, regs); |
9a7f938f JK |
815 | |
816 | if (i386_linux_get_syscall_number_from_regcache (regs) != -1) | |
817 | { | |
c2508e90 | 818 | /* The closure returned by i386_displaced_step_copy_insn is simply a |
cfba9872 | 819 | buffer with a copy of the instruction. */ |
1152d984 SM |
820 | i386_displaced_step_copy_insn_closure *closure |
821 | = (i386_displaced_step_copy_insn_closure *) closure_.get (); | |
9a7f938f JK |
822 | |
823 | /* Fake nop. */ | |
cfba9872 | 824 | closure->buf[0] = 0x90; |
9a7f938f JK |
825 | } |
826 | ||
cfba9872 | 827 | return closure_; |
9a7f938f JK |
828 | } |
829 | ||
8201327c MK |
830 | static void |
831 | i386_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch) | |
832 | { | |
08106042 | 833 | i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch); |
90884b2b | 834 | const struct target_desc *tdesc = info.target_desc; |
0dba2a6c | 835 | struct tdesc_arch_data *tdesc_data = info.tdesc_data; |
90884b2b L |
836 | const struct tdesc_feature *feature; |
837 | int valid_p; | |
838 | ||
839 | gdb_assert (tdesc_data); | |
8201327c | 840 | |
480af54c | 841 | linux_init_abi (info, gdbarch, 1); |
a5ee0f0c | 842 | |
8201327c MK |
843 | /* GNU/Linux uses ELF. */ |
844 | i386_elf_init_abi (info, gdbarch); | |
845 | ||
90884b2b L |
846 | /* Reserve a number for orig_eax. */ |
847 | set_gdbarch_num_regs (gdbarch, I386_LINUX_NUM_REGS); | |
848 | ||
849 | if (! tdesc_has_registers (tdesc)) | |
35b4818d | 850 | tdesc = i386_linux_read_description (X86_XSTATE_SSE_MASK); |
90884b2b L |
851 | tdep->tdesc = tdesc; |
852 | ||
853 | feature = tdesc_find_feature (tdesc, "org.gnu.gdb.i386.linux"); | |
854 | if (feature == NULL) | |
855 | return; | |
8201327c | 856 | |
90884b2b L |
857 | valid_p = tdesc_numbered_register (feature, tdesc_data, |
858 | I386_LINUX_ORIG_EAX_REGNUM, | |
859 | "orig_eax"); | |
860 | if (!valid_p) | |
861 | return; | |
862 | ||
863 | /* Add the %orig_eax register used for syscall restarting. */ | |
8201327c | 864 | set_gdbarch_write_pc (gdbarch, i386_linux_write_pc); |
90884b2b L |
865 | |
866 | tdep->register_reggroup_p = i386_linux_register_reggroup_p; | |
8201327c | 867 | |
e9f1aad5 MK |
868 | tdep->gregset_reg_offset = i386_linux_gregset_reg_offset; |
869 | tdep->gregset_num_regs = ARRAY_SIZE (i386_linux_gregset_reg_offset); | |
870 | tdep->sizeof_gregset = 17 * 4; | |
871 | ||
8201327c MK |
872 | tdep->jb_pc_offset = 20; /* From <bits/setjmp.h>. */ |
873 | ||
911bc6ee | 874 | tdep->sigtramp_p = i386_linux_sigtramp_p; |
b7d15bf7 | 875 | tdep->sigcontext_addr = i386_linux_sigcontext_addr; |
a3386186 | 876 | tdep->sc_reg_offset = i386_linux_sc_reg_offset; |
bb489b3c | 877 | tdep->sc_num_regs = ARRAY_SIZE (i386_linux_sc_reg_offset); |
8201327c | 878 | |
c131fcee | 879 | tdep->xsave_xcr0_offset = I386_LINUX_XSAVE_XCR0_OFFSET; |
b42405a1 JB |
880 | set_gdbarch_core_read_x86_xsave_layout |
881 | (gdbarch, i386_linux_core_read_x86_xsave_layout); | |
c131fcee | 882 | |
a6b808b4 | 883 | set_gdbarch_process_record (gdbarch, i386_process_record); |
8a2e0e28 | 884 | set_gdbarch_process_record_signal (gdbarch, i386_linux_record_signal); |
a6b808b4 | 885 | |
77fcef51 | 886 | /* Initialize the i386_linux_record_tdep. */ |
5e31abdf HZ |
887 | /* These values are the size of the type that will be used in a system |
888 | call. They are obtained from Linux Kernel source. */ | |
2c543fc4 HZ |
889 | i386_linux_record_tdep.size_pointer |
890 | = gdbarch_ptr_bit (gdbarch) / TARGET_CHAR_BIT; | |
5e31abdf HZ |
891 | i386_linux_record_tdep.size__old_kernel_stat = 32; |
892 | i386_linux_record_tdep.size_tms = 16; | |
893 | i386_linux_record_tdep.size_loff_t = 8; | |
894 | i386_linux_record_tdep.size_flock = 16; | |
895 | i386_linux_record_tdep.size_oldold_utsname = 45; | |
896 | i386_linux_record_tdep.size_ustat = 20; | |
7571f7f2 MK |
897 | i386_linux_record_tdep.size_old_sigaction = 16; |
898 | i386_linux_record_tdep.size_old_sigset_t = 4; | |
5e31abdf HZ |
899 | i386_linux_record_tdep.size_rlimit = 8; |
900 | i386_linux_record_tdep.size_rusage = 72; | |
901 | i386_linux_record_tdep.size_timeval = 8; | |
902 | i386_linux_record_tdep.size_timezone = 8; | |
903 | i386_linux_record_tdep.size_old_gid_t = 2; | |
904 | i386_linux_record_tdep.size_old_uid_t = 2; | |
905 | i386_linux_record_tdep.size_fd_set = 128; | |
72aded86 | 906 | i386_linux_record_tdep.size_old_dirent = 268; |
5e31abdf HZ |
907 | i386_linux_record_tdep.size_statfs = 64; |
908 | i386_linux_record_tdep.size_statfs64 = 84; | |
909 | i386_linux_record_tdep.size_sockaddr = 16; | |
2c543fc4 HZ |
910 | i386_linux_record_tdep.size_int |
911 | = gdbarch_int_bit (gdbarch) / TARGET_CHAR_BIT; | |
912 | i386_linux_record_tdep.size_long | |
913 | = gdbarch_long_bit (gdbarch) / TARGET_CHAR_BIT; | |
914 | i386_linux_record_tdep.size_ulong | |
915 | = gdbarch_long_bit (gdbarch) / TARGET_CHAR_BIT; | |
5e31abdf HZ |
916 | i386_linux_record_tdep.size_msghdr = 28; |
917 | i386_linux_record_tdep.size_itimerval = 16; | |
918 | i386_linux_record_tdep.size_stat = 88; | |
919 | i386_linux_record_tdep.size_old_utsname = 325; | |
920 | i386_linux_record_tdep.size_sysinfo = 64; | |
921 | i386_linux_record_tdep.size_msqid_ds = 88; | |
922 | i386_linux_record_tdep.size_shmid_ds = 84; | |
923 | i386_linux_record_tdep.size_new_utsname = 390; | |
924 | i386_linux_record_tdep.size_timex = 128; | |
925 | i386_linux_record_tdep.size_mem_dqinfo = 24; | |
926 | i386_linux_record_tdep.size_if_dqblk = 68; | |
927 | i386_linux_record_tdep.size_fs_quota_stat = 68; | |
928 | i386_linux_record_tdep.size_timespec = 8; | |
929 | i386_linux_record_tdep.size_pollfd = 8; | |
930 | i386_linux_record_tdep.size_NFS_FHSIZE = 32; | |
931 | i386_linux_record_tdep.size_knfsd_fh = 132; | |
932 | i386_linux_record_tdep.size_TASK_COMM_LEN = 16; | |
7571f7f2 | 933 | i386_linux_record_tdep.size_sigaction = 20; |
5e31abdf HZ |
934 | i386_linux_record_tdep.size_sigset_t = 8; |
935 | i386_linux_record_tdep.size_siginfo_t = 128; | |
936 | i386_linux_record_tdep.size_cap_user_data_t = 12; | |
937 | i386_linux_record_tdep.size_stack_t = 12; | |
938 | i386_linux_record_tdep.size_off_t = i386_linux_record_tdep.size_long; | |
939 | i386_linux_record_tdep.size_stat64 = 96; | |
d625f9a9 MK |
940 | i386_linux_record_tdep.size_gid_t = 4; |
941 | i386_linux_record_tdep.size_uid_t = 4; | |
5e31abdf HZ |
942 | i386_linux_record_tdep.size_PAGE_SIZE = 4096; |
943 | i386_linux_record_tdep.size_flock64 = 24; | |
944 | i386_linux_record_tdep.size_user_desc = 16; | |
945 | i386_linux_record_tdep.size_io_event = 32; | |
946 | i386_linux_record_tdep.size_iocb = 64; | |
947 | i386_linux_record_tdep.size_epoll_event = 12; | |
2c543fc4 HZ |
948 | i386_linux_record_tdep.size_itimerspec |
949 | = i386_linux_record_tdep.size_timespec * 2; | |
5e31abdf | 950 | i386_linux_record_tdep.size_mq_attr = 32; |
5e31abdf HZ |
951 | i386_linux_record_tdep.size_termios = 36; |
952 | i386_linux_record_tdep.size_termios2 = 44; | |
953 | i386_linux_record_tdep.size_pid_t = 4; | |
954 | i386_linux_record_tdep.size_winsize = 8; | |
955 | i386_linux_record_tdep.size_serial_struct = 60; | |
956 | i386_linux_record_tdep.size_serial_icounter_struct = 80; | |
957 | i386_linux_record_tdep.size_hayes_esp_config = 12; | |
2c543fc4 HZ |
958 | i386_linux_record_tdep.size_size_t = 4; |
959 | i386_linux_record_tdep.size_iovec = 8; | |
b80d067f | 960 | i386_linux_record_tdep.size_time_t = 4; |
5e31abdf HZ |
961 | |
962 | /* These values are the second argument of system call "sys_ioctl". | |
963 | They are obtained from Linux Kernel source. */ | |
964 | i386_linux_record_tdep.ioctl_TCGETS = 0x5401; | |
965 | i386_linux_record_tdep.ioctl_TCSETS = 0x5402; | |
966 | i386_linux_record_tdep.ioctl_TCSETSW = 0x5403; | |
967 | i386_linux_record_tdep.ioctl_TCSETSF = 0x5404; | |
968 | i386_linux_record_tdep.ioctl_TCGETA = 0x5405; | |
969 | i386_linux_record_tdep.ioctl_TCSETA = 0x5406; | |
970 | i386_linux_record_tdep.ioctl_TCSETAW = 0x5407; | |
971 | i386_linux_record_tdep.ioctl_TCSETAF = 0x5408; | |
972 | i386_linux_record_tdep.ioctl_TCSBRK = 0x5409; | |
973 | i386_linux_record_tdep.ioctl_TCXONC = 0x540A; | |
974 | i386_linux_record_tdep.ioctl_TCFLSH = 0x540B; | |
975 | i386_linux_record_tdep.ioctl_TIOCEXCL = 0x540C; | |
976 | i386_linux_record_tdep.ioctl_TIOCNXCL = 0x540D; | |
977 | i386_linux_record_tdep.ioctl_TIOCSCTTY = 0x540E; | |
978 | i386_linux_record_tdep.ioctl_TIOCGPGRP = 0x540F; | |
979 | i386_linux_record_tdep.ioctl_TIOCSPGRP = 0x5410; | |
980 | i386_linux_record_tdep.ioctl_TIOCOUTQ = 0x5411; | |
981 | i386_linux_record_tdep.ioctl_TIOCSTI = 0x5412; | |
982 | i386_linux_record_tdep.ioctl_TIOCGWINSZ = 0x5413; | |
983 | i386_linux_record_tdep.ioctl_TIOCSWINSZ = 0x5414; | |
984 | i386_linux_record_tdep.ioctl_TIOCMGET = 0x5415; | |
985 | i386_linux_record_tdep.ioctl_TIOCMBIS = 0x5416; | |
986 | i386_linux_record_tdep.ioctl_TIOCMBIC = 0x5417; | |
987 | i386_linux_record_tdep.ioctl_TIOCMSET = 0x5418; | |
988 | i386_linux_record_tdep.ioctl_TIOCGSOFTCAR = 0x5419; | |
989 | i386_linux_record_tdep.ioctl_TIOCSSOFTCAR = 0x541A; | |
990 | i386_linux_record_tdep.ioctl_FIONREAD = 0x541B; | |
991 | i386_linux_record_tdep.ioctl_TIOCINQ = i386_linux_record_tdep.ioctl_FIONREAD; | |
992 | i386_linux_record_tdep.ioctl_TIOCLINUX = 0x541C; | |
993 | i386_linux_record_tdep.ioctl_TIOCCONS = 0x541D; | |
994 | i386_linux_record_tdep.ioctl_TIOCGSERIAL = 0x541E; | |
995 | i386_linux_record_tdep.ioctl_TIOCSSERIAL = 0x541F; | |
996 | i386_linux_record_tdep.ioctl_TIOCPKT = 0x5420; | |
997 | i386_linux_record_tdep.ioctl_FIONBIO = 0x5421; | |
998 | i386_linux_record_tdep.ioctl_TIOCNOTTY = 0x5422; | |
999 | i386_linux_record_tdep.ioctl_TIOCSETD = 0x5423; | |
1000 | i386_linux_record_tdep.ioctl_TIOCGETD = 0x5424; | |
1001 | i386_linux_record_tdep.ioctl_TCSBRKP = 0x5425; | |
1002 | i386_linux_record_tdep.ioctl_TIOCTTYGSTRUCT = 0x5426; | |
1003 | i386_linux_record_tdep.ioctl_TIOCSBRK = 0x5427; | |
1004 | i386_linux_record_tdep.ioctl_TIOCCBRK = 0x5428; | |
1005 | i386_linux_record_tdep.ioctl_TIOCGSID = 0x5429; | |
1006 | i386_linux_record_tdep.ioctl_TCGETS2 = 0x802c542a; | |
1007 | i386_linux_record_tdep.ioctl_TCSETS2 = 0x402c542b; | |
1008 | i386_linux_record_tdep.ioctl_TCSETSW2 = 0x402c542c; | |
1009 | i386_linux_record_tdep.ioctl_TCSETSF2 = 0x402c542d; | |
1010 | i386_linux_record_tdep.ioctl_TIOCGPTN = 0x80045430; | |
1011 | i386_linux_record_tdep.ioctl_TIOCSPTLCK = 0x40045431; | |
1012 | i386_linux_record_tdep.ioctl_FIONCLEX = 0x5450; | |
1013 | i386_linux_record_tdep.ioctl_FIOCLEX = 0x5451; | |
1014 | i386_linux_record_tdep.ioctl_FIOASYNC = 0x5452; | |
1015 | i386_linux_record_tdep.ioctl_TIOCSERCONFIG = 0x5453; | |
1016 | i386_linux_record_tdep.ioctl_TIOCSERGWILD = 0x5454; | |
1017 | i386_linux_record_tdep.ioctl_TIOCSERSWILD = 0x5455; | |
1018 | i386_linux_record_tdep.ioctl_TIOCGLCKTRMIOS = 0x5456; | |
1019 | i386_linux_record_tdep.ioctl_TIOCSLCKTRMIOS = 0x5457; | |
1020 | i386_linux_record_tdep.ioctl_TIOCSERGSTRUCT = 0x5458; | |
1021 | i386_linux_record_tdep.ioctl_TIOCSERGETLSR = 0x5459; | |
1022 | i386_linux_record_tdep.ioctl_TIOCSERGETMULTI = 0x545A; | |
1023 | i386_linux_record_tdep.ioctl_TIOCSERSETMULTI = 0x545B; | |
1024 | i386_linux_record_tdep.ioctl_TIOCMIWAIT = 0x545C; | |
1025 | i386_linux_record_tdep.ioctl_TIOCGICOUNT = 0x545D; | |
1026 | i386_linux_record_tdep.ioctl_TIOCGHAYESESP = 0x545E; | |
1027 | i386_linux_record_tdep.ioctl_TIOCSHAYESESP = 0x545F; | |
1028 | i386_linux_record_tdep.ioctl_FIOQSIZE = 0x5460; | |
1029 | ||
1030 | /* These values are the second argument of system call "sys_fcntl" | |
1031 | and "sys_fcntl64". They are obtained from Linux Kernel source. */ | |
1032 | i386_linux_record_tdep.fcntl_F_GETLK = 5; | |
1033 | i386_linux_record_tdep.fcntl_F_GETLK64 = 12; | |
1034 | i386_linux_record_tdep.fcntl_F_SETLK64 = 13; | |
1035 | i386_linux_record_tdep.fcntl_F_SETLKW64 = 14; | |
50ef67b3 | 1036 | |
77fcef51 HZ |
1037 | i386_linux_record_tdep.arg1 = I386_EBX_REGNUM; |
1038 | i386_linux_record_tdep.arg2 = I386_ECX_REGNUM; | |
1039 | i386_linux_record_tdep.arg3 = I386_EDX_REGNUM; | |
1040 | i386_linux_record_tdep.arg4 = I386_ESI_REGNUM; | |
1041 | i386_linux_record_tdep.arg5 = I386_EDI_REGNUM; | |
2c543fc4 | 1042 | i386_linux_record_tdep.arg6 = I386_EBP_REGNUM; |
77fcef51 | 1043 | |
ffdf6de5 JK |
1044 | tdep->i386_intx80_record = i386_linux_intx80_sysenter_syscall_record; |
1045 | tdep->i386_sysenter_record = i386_linux_intx80_sysenter_syscall_record; | |
1046 | tdep->i386_syscall_record = i386_linux_intx80_sysenter_syscall_record; | |
77fcef51 | 1047 | |
85102364 | 1048 | /* N_FUN symbols in shared libraries have 0 for their values and need |
1777feb0 | 1049 | to be relocated. */ |
203c3895 UW |
1050 | set_gdbarch_sofun_address_maybe_missing (gdbarch, 1); |
1051 | ||
871fbe6a | 1052 | /* GNU/Linux uses SVR4-style shared libraries. */ |
982e9687 | 1053 | set_gdbarch_skip_trampoline_code (gdbarch, find_solib_trampoline_target); |
871fbe6a | 1054 | set_solib_svr4_fetch_link_map_offsets |
c0154a4a | 1055 | (gdbarch, linux_ilp32_fetch_link_map_offsets); |
871fbe6a MK |
1056 | |
1057 | /* GNU/Linux uses the dynamic linker included in the GNU C Library. */ | |
bb41a796 | 1058 | set_gdbarch_skip_solib_resolver (gdbarch, glibc_skip_solib_resolver); |
12b8a2cb DJ |
1059 | |
1060 | dwarf2_frame_set_signal_frame_p (gdbarch, i386_linux_dwarf_signal_frame_p); | |
b2756930 KB |
1061 | |
1062 | /* Enable TLS support. */ | |
1063 | set_gdbarch_fetch_tls_load_module_address (gdbarch, | |
dda83cd7 | 1064 | svr4_fetch_objfile_link_map); |
237fc4c9 | 1065 | |
5aa82d05 AA |
1066 | /* Core file support. */ |
1067 | set_gdbarch_iterate_over_regset_sections | |
1068 | (gdbarch, i386_linux_iterate_over_regset_sections); | |
90884b2b L |
1069 | set_gdbarch_core_read_description (gdbarch, |
1070 | i386_linux_core_read_description); | |
1071 | ||
237fc4c9 PA |
1072 | /* Displaced stepping. */ |
1073 | set_gdbarch_displaced_step_copy_insn (gdbarch, | |
dda83cd7 | 1074 | i386_linux_displaced_step_copy_insn); |
237fc4c9 | 1075 | set_gdbarch_displaced_step_fixup (gdbarch, i386_displaced_step_fixup); |
4aa995e1 | 1076 | |
a96d9b2e | 1077 | /* Functions for 'catch syscall'. */ |
458c8db8 | 1078 | set_xml_syscall_file_name (gdbarch, XML_SYSCALL_FILENAME_I386); |
a96d9b2e | 1079 | set_gdbarch_get_syscall_number (gdbarch, |
dda83cd7 | 1080 | i386_linux_get_syscall_number); |
190b495d WT |
1081 | |
1082 | set_gdbarch_get_siginfo_type (gdbarch, x86_linux_get_siginfo_type); | |
77bdfeb2 | 1083 | set_gdbarch_report_signal_info (gdbarch, i386_linux_report_signal_info); |
8201327c MK |
1084 | } |
1085 | ||
6c265988 | 1086 | void _initialize_i386_linux_tdep (); |
8201327c | 1087 | void |
6c265988 | 1088 | _initialize_i386_linux_tdep () |
8201327c | 1089 | { |
05816f70 | 1090 | gdbarch_register_osabi (bfd_arch_i386, 0, GDB_OSABI_LINUX, |
8201327c MK |
1091 | i386_linux_init_abi); |
1092 | } |