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