Support amd64 AVX.
[deliverable/binutils-gdb.git] / gdb / i386-linux-tdep.c
CommitLineData
871fbe6a 1/* Target-dependent code for GNU/Linux i386.
ca557f44 2
4c38e0a4 3 Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2007, 2008, 2009, 2010
4252dc94 4 Free Software Foundation, Inc.
e7ee86a9
JB
5
6 This file is part of GDB.
7
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
a9762ec7 10 the Free Software Foundation; either version 3 of the License, or
e7ee86a9
JB
11 (at your option) any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
a9762ec7 19 along with this program. If not, see <http://www.gnu.org/licenses/>. */
e7ee86a9
JB
20
21#include "defs.h"
22#include "gdbcore.h"
23#include "frame.h"
24#include "value.h"
4e052eda 25#include "regcache.h"
c131fcee 26#include "regset.h"
6441c4a0 27#include "inferior.h"
0670c0aa 28#include "osabi.h"
38c968cf 29#include "reggroups.h"
5cb2fe25 30#include "dwarf2-frame.h"
0670c0aa 31#include "gdb_string.h"
4be87837 32
8201327c
MK
33#include "i386-tdep.h"
34#include "i386-linux-tdep.h"
4aa995e1 35#include "linux-tdep.h"
0670c0aa 36#include "glibc-tdep.h"
871fbe6a 37#include "solib-svr4.h"
982e9687 38#include "symtab.h"
237fc4c9 39#include "arch-utils.h"
a96d9b2e
SDJ
40#include "xml-syscall.h"
41
c131fcee
L
42#include "i387-tdep.h"
43#include "i386-xstate.h"
44
a96d9b2e
SDJ
45/* The syscall's XML filename for i386. */
46#define XML_SYSCALL_FILENAME_I386 "syscalls/i386-linux.xml"
17ea7499 47
77fcef51
HZ
48#include "record.h"
49#include "linux-record.h"
50#include <stdint.h>
51
90884b2b 52#include "features/i386/i386-linux.c"
c131fcee 53#include "features/i386/i386-avx-linux.c"
90884b2b 54
17ea7499
CES
55/* Supported register note sections. */
56static struct core_regset_section i386_linux_regset_sections[] =
57{
1b1818e4
UW
58 { ".reg", 144, "general-purpose" },
59 { ".reg2", 108, "floating-point" },
60 { ".reg-xfp", 512, "extended floating-point" },
c131fcee 61 { ".reg-xstate", I386_XSTATE_MAX_SIZE, "XSAVE extended state" },
17ea7499
CES
62 { NULL, 0 }
63};
8201327c 64
38c968cf
AC
65/* Return non-zero, when the register is in the corresponding register
66 group. Put the LINUX_ORIG_EAX register in the system group. */
67static int
68i386_linux_register_reggroup_p (struct gdbarch *gdbarch, int regnum,
69 struct reggroup *group)
70{
71 if (regnum == I386_LINUX_ORIG_EAX_REGNUM)
72 return (group == system_reggroup
73 || group == save_reggroup
74 || group == restore_reggroup);
75 return i386_register_reggroup_p (gdbarch, regnum, group);
76}
77
e7ee86a9
JB
78\f
79/* Recognizing signal handler frames. */
80
ca557f44 81/* GNU/Linux has two flavors of signals. Normal signal handlers, and
e7ee86a9
JB
82 "realtime" (RT) signals. The RT signals can provide additional
83 information to the signal handler if the SA_SIGINFO flag is set
84 when establishing a signal handler using `sigaction'. It is not
ca557f44
AC
85 unlikely that future versions of GNU/Linux will support SA_SIGINFO
86 for normal signals too. */
e7ee86a9
JB
87
88/* When the i386 Linux kernel calls a signal handler and the
89 SA_RESTORER flag isn't set, the return address points to a bit of
90 code on the stack. This function returns whether the PC appears to
91 be within this bit of code.
92
93 The instruction sequence for normal signals is
94 pop %eax
acd5c798 95 mov $0x77, %eax
e7ee86a9
JB
96 int $0x80
97 or 0x58 0xb8 0x77 0x00 0x00 0x00 0xcd 0x80.
98
99 Checking for the code sequence should be somewhat reliable, because
100 the effect is to call the system call sigreturn. This is unlikely
911bc6ee 101 to occur anywhere other than in a signal trampoline.
e7ee86a9
JB
102
103 It kind of sucks that we have to read memory from the process in
104 order to identify a signal trampoline, but there doesn't seem to be
911bc6ee
MK
105 any other way. Therefore we only do the memory reads if no
106 function name could be identified, which should be the case since
107 the code is on the stack.
e7ee86a9
JB
108
109 Detection of signal trampolines for handlers that set the
110 SA_RESTORER flag is in general not possible. Unfortunately this is
111 what the GNU C Library has been doing for quite some time now.
112 However, as of version 2.1.2, the GNU C Library uses signal
113 trampolines (named __restore and __restore_rt) that are identical
114 to the ones used by the kernel. Therefore, these trampolines are
115 supported too. */
116
acd5c798
MK
117#define LINUX_SIGTRAMP_INSN0 0x58 /* pop %eax */
118#define LINUX_SIGTRAMP_OFFSET0 0
119#define LINUX_SIGTRAMP_INSN1 0xb8 /* mov $NNNN, %eax */
120#define LINUX_SIGTRAMP_OFFSET1 1
121#define LINUX_SIGTRAMP_INSN2 0xcd /* int */
122#define LINUX_SIGTRAMP_OFFSET2 6
e7ee86a9 123
4252dc94 124static const gdb_byte linux_sigtramp_code[] =
e7ee86a9
JB
125{
126 LINUX_SIGTRAMP_INSN0, /* pop %eax */
acd5c798 127 LINUX_SIGTRAMP_INSN1, 0x77, 0x00, 0x00, 0x00, /* mov $0x77, %eax */
e7ee86a9
JB
128 LINUX_SIGTRAMP_INSN2, 0x80 /* int $0x80 */
129};
130
131#define LINUX_SIGTRAMP_LEN (sizeof linux_sigtramp_code)
132
10458914
DJ
133/* If THIS_FRAME is a sigtramp routine, return the address of the
134 start of the routine. Otherwise, return 0. */
e7ee86a9
JB
135
136static CORE_ADDR
10458914 137i386_linux_sigtramp_start (struct frame_info *this_frame)
e7ee86a9 138{
10458914 139 CORE_ADDR pc = get_frame_pc (this_frame);
4252dc94 140 gdb_byte buf[LINUX_SIGTRAMP_LEN];
e7ee86a9
JB
141
142 /* We only recognize a signal trampoline if PC is at the start of
143 one of the three instructions. We optimize for finding the PC at
144 the start, as will be the case when the trampoline is not the
145 first frame on the stack. We assume that in the case where the
146 PC is not at the start of the instruction sequence, there will be
147 a few trailing readable bytes on the stack. */
148
10458914 149 if (!safe_frame_unwind_memory (this_frame, pc, buf, LINUX_SIGTRAMP_LEN))
e7ee86a9
JB
150 return 0;
151
152 if (buf[0] != LINUX_SIGTRAMP_INSN0)
153 {
154 int adjust;
155
156 switch (buf[0])
157 {
158 case LINUX_SIGTRAMP_INSN1:
159 adjust = LINUX_SIGTRAMP_OFFSET1;
160 break;
161 case LINUX_SIGTRAMP_INSN2:
162 adjust = LINUX_SIGTRAMP_OFFSET2;
163 break;
164 default:
165 return 0;
166 }
167
168 pc -= adjust;
169
10458914 170 if (!safe_frame_unwind_memory (this_frame, pc, buf, LINUX_SIGTRAMP_LEN))
e7ee86a9
JB
171 return 0;
172 }
173
174 if (memcmp (buf, linux_sigtramp_code, LINUX_SIGTRAMP_LEN) != 0)
175 return 0;
176
177 return pc;
178}
179
180/* This function does the same for RT signals. Here the instruction
181 sequence is
acd5c798 182 mov $0xad, %eax
e7ee86a9
JB
183 int $0x80
184 or 0xb8 0xad 0x00 0x00 0x00 0xcd 0x80.
185
186 The effect is to call the system call rt_sigreturn. */
187
acd5c798
MK
188#define LINUX_RT_SIGTRAMP_INSN0 0xb8 /* mov $NNNN, %eax */
189#define LINUX_RT_SIGTRAMP_OFFSET0 0
190#define LINUX_RT_SIGTRAMP_INSN1 0xcd /* int */
191#define LINUX_RT_SIGTRAMP_OFFSET1 5
e7ee86a9 192
4252dc94 193static const gdb_byte linux_rt_sigtramp_code[] =
e7ee86a9 194{
acd5c798 195 LINUX_RT_SIGTRAMP_INSN0, 0xad, 0x00, 0x00, 0x00, /* mov $0xad, %eax */
e7ee86a9
JB
196 LINUX_RT_SIGTRAMP_INSN1, 0x80 /* int $0x80 */
197};
198
199#define LINUX_RT_SIGTRAMP_LEN (sizeof linux_rt_sigtramp_code)
200
10458914
DJ
201/* If THIS_FRAME is an RT sigtramp routine, return the address of the
202 start of the routine. Otherwise, return 0. */
e7ee86a9
JB
203
204static CORE_ADDR
10458914 205i386_linux_rt_sigtramp_start (struct frame_info *this_frame)
e7ee86a9 206{
10458914 207 CORE_ADDR pc = get_frame_pc (this_frame);
4252dc94 208 gdb_byte buf[LINUX_RT_SIGTRAMP_LEN];
e7ee86a9
JB
209
210 /* We only recognize a signal trampoline if PC is at the start of
211 one of the two instructions. We optimize for finding the PC at
212 the start, as will be the case when the trampoline is not the
213 first frame on the stack. We assume that in the case where the
214 PC is not at the start of the instruction sequence, there will be
215 a few trailing readable bytes on the stack. */
216
10458914 217 if (!safe_frame_unwind_memory (this_frame, pc, buf, LINUX_RT_SIGTRAMP_LEN))
e7ee86a9
JB
218 return 0;
219
220 if (buf[0] != LINUX_RT_SIGTRAMP_INSN0)
221 {
222 if (buf[0] != LINUX_RT_SIGTRAMP_INSN1)
223 return 0;
224
225 pc -= LINUX_RT_SIGTRAMP_OFFSET1;
226
10458914 227 if (!safe_frame_unwind_memory (this_frame, pc, buf,
8e6bed05 228 LINUX_RT_SIGTRAMP_LEN))
e7ee86a9
JB
229 return 0;
230 }
231
232 if (memcmp (buf, linux_rt_sigtramp_code, LINUX_RT_SIGTRAMP_LEN) != 0)
233 return 0;
234
235 return pc;
236}
237
10458914
DJ
238/* Return whether THIS_FRAME corresponds to a GNU/Linux sigtramp
239 routine. */
e7ee86a9 240
8201327c 241static int
10458914 242i386_linux_sigtramp_p (struct frame_info *this_frame)
e7ee86a9 243{
10458914 244 CORE_ADDR pc = get_frame_pc (this_frame);
911bc6ee
MK
245 char *name;
246
247 find_pc_partial_function (pc, &name, NULL, NULL);
248
ef17e74b
DJ
249 /* If we have NAME, we can optimize the search. The trampolines are
250 named __restore and __restore_rt. However, they aren't dynamically
251 exported from the shared C library, so the trampoline may appear to
252 be part of the preceding function. This should always be sigaction,
253 __sigaction, or __libc_sigaction (all aliases to the same function). */
254 if (name == NULL || strstr (name, "sigaction") != NULL)
10458914
DJ
255 return (i386_linux_sigtramp_start (this_frame) != 0
256 || i386_linux_rt_sigtramp_start (this_frame) != 0);
ef17e74b
DJ
257
258 return (strcmp ("__restore", name) == 0
259 || strcmp ("__restore_rt", name) == 0);
e7ee86a9
JB
260}
261
4a4e5149
DJ
262/* Return one if the PC of THIS_FRAME is in a signal trampoline which
263 may have DWARF-2 CFI. */
12b8a2cb
DJ
264
265static int
266i386_linux_dwarf_signal_frame_p (struct gdbarch *gdbarch,
4a4e5149 267 struct frame_info *this_frame)
12b8a2cb 268{
4a4e5149 269 CORE_ADDR pc = get_frame_pc (this_frame);
12b8a2cb
DJ
270 char *name;
271
272 find_pc_partial_function (pc, &name, NULL, NULL);
273
274 /* If a vsyscall DSO is in use, the signal trampolines may have these
275 names. */
276 if (name && (strcmp (name, "__kernel_sigreturn") == 0
277 || strcmp (name, "__kernel_rt_sigreturn") == 0))
278 return 1;
279
280 return 0;
281}
282
acd5c798
MK
283/* Offset to struct sigcontext in ucontext, from <asm/ucontext.h>. */
284#define I386_LINUX_UCONTEXT_SIGCONTEXT_OFFSET 20
285
10458914
DJ
286/* Assuming THIS_FRAME is a GNU/Linux sigtramp routine, return the
287 address of the associated sigcontext structure. */
e7ee86a9 288
b7d15bf7 289static CORE_ADDR
10458914 290i386_linux_sigcontext_addr (struct frame_info *this_frame)
e7ee86a9 291{
e17a4113
UW
292 struct gdbarch *gdbarch = get_frame_arch (this_frame);
293 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
e7ee86a9 294 CORE_ADDR pc;
acd5c798 295 CORE_ADDR sp;
4252dc94 296 gdb_byte buf[4];
acd5c798 297
10458914 298 get_frame_register (this_frame, I386_ESP_REGNUM, buf);
e17a4113 299 sp = extract_unsigned_integer (buf, 4, byte_order);
e7ee86a9 300
10458914 301 pc = i386_linux_sigtramp_start (this_frame);
e7ee86a9
JB
302 if (pc)
303 {
acd5c798
MK
304 /* The sigcontext structure lives on the stack, right after
305 the signum argument. We determine the address of the
306 sigcontext structure by looking at the frame's stack
307 pointer. Keep in mind that the first instruction of the
308 sigtramp code is "pop %eax". If the PC is after this
309 instruction, adjust the returned value accordingly. */
10458914 310 if (pc == get_frame_pc (this_frame))
e7ee86a9
JB
311 return sp + 4;
312 return sp;
313 }
314
10458914 315 pc = i386_linux_rt_sigtramp_start (this_frame);
e7ee86a9
JB
316 if (pc)
317 {
acd5c798
MK
318 CORE_ADDR ucontext_addr;
319
320 /* The sigcontext structure is part of the user context. A
321 pointer to the user context is passed as the third argument
322 to the signal handler. */
323 read_memory (sp + 8, buf, 4);
e17a4113 324 ucontext_addr = extract_unsigned_integer (buf, 4, byte_order);
acd5c798 325 return ucontext_addr + I386_LINUX_UCONTEXT_SIGCONTEXT_OFFSET;
e7ee86a9
JB
326 }
327
8a3fe4f8 328 error (_("Couldn't recognize signal trampoline."));
e7ee86a9
JB
329 return 0;
330}
331
6441c4a0
MK
332/* Set the program counter for process PTID to PC. */
333
8201327c 334static void
61a1198a 335i386_linux_write_pc (struct regcache *regcache, CORE_ADDR pc)
6441c4a0 336{
61a1198a 337 regcache_cooked_write_unsigned (regcache, I386_EIP_REGNUM, pc);
6441c4a0
MK
338
339 /* We must be careful with modifying the program counter. If we
340 just interrupted a system call, the kernel might try to restart
341 it when we resume the inferior. On restarting the system call,
342 the kernel will try backing up the program counter even though it
343 no longer points at the system call. This typically results in a
344 SIGSEGV or SIGILL. We can prevent this by writing `-1' in the
345 "orig_eax" pseudo-register.
346
347 Note that "orig_eax" is saved when setting up a dummy call frame.
348 This means that it is properly restored when that frame is
349 popped, and that the interrupted system call will be restarted
350 when we resume the inferior on return from a function call from
351 within GDB. In all other cases the system call will not be
352 restarted. */
61a1198a 353 regcache_cooked_write_unsigned (regcache, I386_LINUX_ORIG_EAX_REGNUM, -1);
6441c4a0 354}
77fcef51 355
8a2e0e28
HZ
356/* Record all registers but IP register for process-record. */
357
358static int
359i386_all_but_ip_registers_record (struct regcache *regcache)
360{
361 if (record_arch_list_add_reg (regcache, I386_EAX_REGNUM))
362 return -1;
363 if (record_arch_list_add_reg (regcache, I386_ECX_REGNUM))
364 return -1;
365 if (record_arch_list_add_reg (regcache, I386_EDX_REGNUM))
366 return -1;
367 if (record_arch_list_add_reg (regcache, I386_EBX_REGNUM))
368 return -1;
369 if (record_arch_list_add_reg (regcache, I386_ESP_REGNUM))
370 return -1;
371 if (record_arch_list_add_reg (regcache, I386_EBP_REGNUM))
372 return -1;
373 if (record_arch_list_add_reg (regcache, I386_ESI_REGNUM))
374 return -1;
375 if (record_arch_list_add_reg (regcache, I386_EDI_REGNUM))
376 return -1;
377 if (record_arch_list_add_reg (regcache, I386_EFLAGS_REGNUM))
378 return -1;
379
380 return 0;
381}
13b6d1d4
MS
382
383/* i386_canonicalize_syscall maps from the native i386 Linux set
384 of syscall ids into a canonical set of syscall ids used by
385 process record (a mostly trivial mapping, since the canonical
386 set was originally taken from the i386 set). */
387
388static enum gdb_syscall
389i386_canonicalize_syscall (int syscall)
390{
391 enum { i386_syscall_max = 499 };
392
393 if (syscall <= i386_syscall_max)
394 return syscall;
395 else
396 return -1;
397}
398
77fcef51
HZ
399/* Parse the arguments of current system call instruction and record
400 the values of the registers and memory that will be changed into
401 "record_arch_list". This instruction is "int 0x80" (Linux
402 Kernel2.4) or "sysenter" (Linux Kernel 2.6).
403
404 Return -1 if something wrong. */
405
8a2e0e28
HZ
406static struct linux_record_tdep i386_linux_record_tdep;
407
77fcef51
HZ
408static int
409i386_linux_intx80_sysenter_record (struct regcache *regcache)
410{
411 int ret;
13b6d1d4
MS
412 LONGEST syscall_native;
413 enum gdb_syscall syscall_gdb;
414
415 regcache_raw_read_signed (regcache, I386_EAX_REGNUM, &syscall_native);
77fcef51 416
13b6d1d4 417 syscall_gdb = i386_canonicalize_syscall (syscall_native);
2c543fc4 418
13b6d1d4 419 if (syscall_gdb < 0)
2c543fc4
HZ
420 {
421 printf_unfiltered (_("Process record and replay target doesn't "
13b6d1d4
MS
422 "support syscall number %s\n"),
423 plongest (syscall_native));
2c543fc4
HZ
424 return -1;
425 }
77fcef51 426
8a2e0e28
HZ
427 if (syscall_gdb == gdb_sys_sigreturn
428 || syscall_gdb == gdb_sys_rt_sigreturn)
429 {
430 if (i386_all_but_ip_registers_record (regcache))
431 return -1;
432 return 0;
433 }
434
13b6d1d4 435 ret = record_linux_system_call (syscall_gdb, regcache,
77fcef51
HZ
436 &i386_linux_record_tdep);
437 if (ret)
438 return ret;
439
440 /* Record the return value of the system call. */
441 if (record_arch_list_add_reg (regcache, I386_EAX_REGNUM))
442 return -1;
443
444 return 0;
445}
8a2e0e28
HZ
446
447#define I386_LINUX_xstate 270
448#define I386_LINUX_frame_size 732
449
450int
451i386_linux_record_signal (struct gdbarch *gdbarch,
452 struct regcache *regcache,
453 enum target_signal signal)
454{
455 ULONGEST esp;
456
457 if (i386_all_but_ip_registers_record (regcache))
458 return -1;
459
460 if (record_arch_list_add_reg (regcache, I386_EIP_REGNUM))
461 return -1;
462
463 /* Record the change in the stack. */
464 regcache_raw_read_unsigned (regcache, I386_ESP_REGNUM, &esp);
465 /* This is for xstate.
466 sp -= sizeof (struct _fpstate); */
467 esp -= I386_LINUX_xstate;
468 /* This is for frame_size.
469 sp -= sizeof (struct rt_sigframe); */
470 esp -= I386_LINUX_frame_size;
471 if (record_arch_list_add_mem (esp,
472 I386_LINUX_xstate + I386_LINUX_frame_size))
473 return -1;
474
475 if (record_arch_list_add_end ())
476 return -1;
477
478 return 0;
479}
6441c4a0 480\f
8201327c 481
a96d9b2e
SDJ
482static LONGEST
483i386_linux_get_syscall_number (struct gdbarch *gdbarch,
484 ptid_t ptid)
485{
486 struct regcache *regcache = get_thread_regcache (ptid);
487 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
488 /* The content of a register. */
489 gdb_byte buf[4];
490 /* The result. */
491 LONGEST ret;
492
493 /* Getting the system call number from the register.
494 When dealing with x86 architecture, this information
495 is stored at %eax register. */
496 regcache_cooked_read (regcache, I386_LINUX_ORIG_EAX_REGNUM, buf);
497
498 ret = extract_signed_integer (buf, 4, byte_order);
499
500 return ret;
501}
502
e9f1aad5
MK
503/* The register sets used in GNU/Linux ELF core-dumps are identical to
504 the register sets in `struct user' that are used for a.out
505 core-dumps. These are also used by ptrace(2). The corresponding
506 types are `elf_gregset_t' for the general-purpose registers (with
507 `elf_greg_t' the type of a single GP register) and `elf_fpregset_t'
508 for the floating-point registers.
509
510 Those types used to be available under the names `gregset_t' and
511 `fpregset_t' too, and GDB used those names in the past. But those
512 names are now used for the register sets used in the `mcontext_t'
513 type, which have a different size and layout. */
514
515/* Mapping between the general-purpose registers in `struct user'
516 format and GDB's register cache layout. */
517
518/* From <sys/reg.h>. */
519static int i386_linux_gregset_reg_offset[] =
520{
521 6 * 4, /* %eax */
522 1 * 4, /* %ecx */
523 2 * 4, /* %edx */
524 0 * 4, /* %ebx */
525 15 * 4, /* %esp */
526 5 * 4, /* %ebp */
527 3 * 4, /* %esi */
528 4 * 4, /* %edi */
529 12 * 4, /* %eip */
530 14 * 4, /* %eflags */
531 13 * 4, /* %cs */
532 16 * 4, /* %ss */
533 7 * 4, /* %ds */
534 8 * 4, /* %es */
535 9 * 4, /* %fs */
536 10 * 4, /* %gs */
537 -1, -1, -1, -1, -1, -1, -1, -1,
538 -1, -1, -1, -1, -1, -1, -1, -1,
539 -1, -1, -1, -1, -1, -1, -1, -1,
540 -1,
c131fcee 541 -1, -1, -1, -1, -1, -1, -1, -1,
e9f1aad5
MK
542 11 * 4 /* "orig_eax" */
543};
544
545/* Mapping between the general-purpose registers in `struct
546 sigcontext' format and GDB's register cache layout. */
547
a3386186 548/* From <asm/sigcontext.h>. */
bb489b3c 549static int i386_linux_sc_reg_offset[] =
a3386186
MK
550{
551 11 * 4, /* %eax */
552 10 * 4, /* %ecx */
553 9 * 4, /* %edx */
554 8 * 4, /* %ebx */
555 7 * 4, /* %esp */
556 6 * 4, /* %ebp */
557 5 * 4, /* %esi */
558 4 * 4, /* %edi */
559 14 * 4, /* %eip */
560 16 * 4, /* %eflags */
561 15 * 4, /* %cs */
562 18 * 4, /* %ss */
563 3 * 4, /* %ds */
564 2 * 4, /* %es */
565 1 * 4, /* %fs */
566 0 * 4 /* %gs */
567};
568
c131fcee
L
569/* Get XSAVE extended state xcr0 from core dump. */
570
571uint64_t
572i386_linux_core_read_xcr0 (struct gdbarch *gdbarch,
573 struct target_ops *target, bfd *abfd)
574{
575 asection *xstate = bfd_get_section_by_name (abfd, ".reg-xstate");
576 uint64_t xcr0;
577
578 if (xstate)
579 {
580 size_t size = bfd_section_size (abfd, xstate);
581
582 /* Check extended state size. */
583 if (size < I386_XSTATE_AVX_SIZE)
584 xcr0 = I386_XSTATE_SSE_MASK;
585 else
586 {
587 char contents[8];
588
589 if (! bfd_get_section_contents (abfd, xstate, contents,
590 I386_LINUX_XSAVE_XCR0_OFFSET,
591 8))
592 {
593 warning (_("Couldn't read `xcr0' bytes from `.reg-xstate' section in core file."));
594 return 0;
595 }
596
597 xcr0 = bfd_get_64 (abfd, contents);
598 }
599 }
600 else
601 xcr0 = I386_XSTATE_SSE_MASK;
602
603 return xcr0;
604}
605
90884b2b
L
606/* Get Linux/x86 target description from core dump. */
607
608static const struct target_desc *
609i386_linux_core_read_description (struct gdbarch *gdbarch,
610 struct target_ops *target,
611 bfd *abfd)
612{
613 asection *section = bfd_get_section_by_name (abfd, ".reg2");
c131fcee 614 uint64_t xcr0;
90884b2b
L
615
616 if (section == NULL)
617 return NULL;
618
619 /* Linux/i386. */
c131fcee
L
620 xcr0 = i386_linux_core_read_xcr0 (gdbarch, target, abfd);
621 if ((xcr0 & I386_XSTATE_AVX_MASK) == I386_XSTATE_AVX_MASK)
622 return tdesc_i386_avx_linux;
623 else
624 return tdesc_i386_linux;
90884b2b
L
625}
626
8201327c
MK
627static void
628i386_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
629{
630 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
90884b2b
L
631 const struct target_desc *tdesc = info.target_desc;
632 struct tdesc_arch_data *tdesc_data = (void *) info.tdep_info;
633 const struct tdesc_feature *feature;
634 int valid_p;
635
636 gdb_assert (tdesc_data);
8201327c
MK
637
638 /* GNU/Linux uses ELF. */
639 i386_elf_init_abi (info, gdbarch);
640
90884b2b
L
641 /* Reserve a number for orig_eax. */
642 set_gdbarch_num_regs (gdbarch, I386_LINUX_NUM_REGS);
643
644 if (! tdesc_has_registers (tdesc))
645 tdesc = tdesc_i386_linux;
646 tdep->tdesc = tdesc;
647
648 feature = tdesc_find_feature (tdesc, "org.gnu.gdb.i386.linux");
649 if (feature == NULL)
650 return;
8201327c 651
90884b2b
L
652 valid_p = tdesc_numbered_register (feature, tdesc_data,
653 I386_LINUX_ORIG_EAX_REGNUM,
654 "orig_eax");
655 if (!valid_p)
656 return;
657
658 /* Add the %orig_eax register used for syscall restarting. */
8201327c 659 set_gdbarch_write_pc (gdbarch, i386_linux_write_pc);
90884b2b
L
660
661 tdep->register_reggroup_p = i386_linux_register_reggroup_p;
8201327c 662
e9f1aad5
MK
663 tdep->gregset_reg_offset = i386_linux_gregset_reg_offset;
664 tdep->gregset_num_regs = ARRAY_SIZE (i386_linux_gregset_reg_offset);
665 tdep->sizeof_gregset = 17 * 4;
666
8201327c
MK
667 tdep->jb_pc_offset = 20; /* From <bits/setjmp.h>. */
668
911bc6ee 669 tdep->sigtramp_p = i386_linux_sigtramp_p;
b7d15bf7 670 tdep->sigcontext_addr = i386_linux_sigcontext_addr;
a3386186 671 tdep->sc_reg_offset = i386_linux_sc_reg_offset;
bb489b3c 672 tdep->sc_num_regs = ARRAY_SIZE (i386_linux_sc_reg_offset);
8201327c 673
c131fcee
L
674 tdep->xsave_xcr0_offset = I386_LINUX_XSAVE_XCR0_OFFSET;
675
a6b808b4 676 set_gdbarch_process_record (gdbarch, i386_process_record);
8a2e0e28 677 set_gdbarch_process_record_signal (gdbarch, i386_linux_record_signal);
a6b808b4 678
77fcef51 679 /* Initialize the i386_linux_record_tdep. */
5e31abdf
HZ
680 /* These values are the size of the type that will be used in a system
681 call. They are obtained from Linux Kernel source. */
2c543fc4
HZ
682 i386_linux_record_tdep.size_pointer
683 = gdbarch_ptr_bit (gdbarch) / TARGET_CHAR_BIT;
5e31abdf
HZ
684 i386_linux_record_tdep.size__old_kernel_stat = 32;
685 i386_linux_record_tdep.size_tms = 16;
686 i386_linux_record_tdep.size_loff_t = 8;
687 i386_linux_record_tdep.size_flock = 16;
688 i386_linux_record_tdep.size_oldold_utsname = 45;
689 i386_linux_record_tdep.size_ustat = 20;
690 i386_linux_record_tdep.size_old_sigaction = 140;
691 i386_linux_record_tdep.size_old_sigset_t = 128;
692 i386_linux_record_tdep.size_rlimit = 8;
693 i386_linux_record_tdep.size_rusage = 72;
694 i386_linux_record_tdep.size_timeval = 8;
695 i386_linux_record_tdep.size_timezone = 8;
696 i386_linux_record_tdep.size_old_gid_t = 2;
697 i386_linux_record_tdep.size_old_uid_t = 2;
698 i386_linux_record_tdep.size_fd_set = 128;
699 i386_linux_record_tdep.size_dirent = 268;
700 i386_linux_record_tdep.size_dirent64 = 276;
701 i386_linux_record_tdep.size_statfs = 64;
702 i386_linux_record_tdep.size_statfs64 = 84;
703 i386_linux_record_tdep.size_sockaddr = 16;
2c543fc4
HZ
704 i386_linux_record_tdep.size_int
705 = gdbarch_int_bit (gdbarch) / TARGET_CHAR_BIT;
706 i386_linux_record_tdep.size_long
707 = gdbarch_long_bit (gdbarch) / TARGET_CHAR_BIT;
708 i386_linux_record_tdep.size_ulong
709 = gdbarch_long_bit (gdbarch) / TARGET_CHAR_BIT;
5e31abdf
HZ
710 i386_linux_record_tdep.size_msghdr = 28;
711 i386_linux_record_tdep.size_itimerval = 16;
712 i386_linux_record_tdep.size_stat = 88;
713 i386_linux_record_tdep.size_old_utsname = 325;
714 i386_linux_record_tdep.size_sysinfo = 64;
715 i386_linux_record_tdep.size_msqid_ds = 88;
716 i386_linux_record_tdep.size_shmid_ds = 84;
717 i386_linux_record_tdep.size_new_utsname = 390;
718 i386_linux_record_tdep.size_timex = 128;
719 i386_linux_record_tdep.size_mem_dqinfo = 24;
720 i386_linux_record_tdep.size_if_dqblk = 68;
721 i386_linux_record_tdep.size_fs_quota_stat = 68;
722 i386_linux_record_tdep.size_timespec = 8;
723 i386_linux_record_tdep.size_pollfd = 8;
724 i386_linux_record_tdep.size_NFS_FHSIZE = 32;
725 i386_linux_record_tdep.size_knfsd_fh = 132;
726 i386_linux_record_tdep.size_TASK_COMM_LEN = 16;
727 i386_linux_record_tdep.size_sigaction = 140;
728 i386_linux_record_tdep.size_sigset_t = 8;
729 i386_linux_record_tdep.size_siginfo_t = 128;
730 i386_linux_record_tdep.size_cap_user_data_t = 12;
731 i386_linux_record_tdep.size_stack_t = 12;
732 i386_linux_record_tdep.size_off_t = i386_linux_record_tdep.size_long;
733 i386_linux_record_tdep.size_stat64 = 96;
734 i386_linux_record_tdep.size_gid_t = 2;
735 i386_linux_record_tdep.size_uid_t = 2;
736 i386_linux_record_tdep.size_PAGE_SIZE = 4096;
737 i386_linux_record_tdep.size_flock64 = 24;
738 i386_linux_record_tdep.size_user_desc = 16;
739 i386_linux_record_tdep.size_io_event = 32;
740 i386_linux_record_tdep.size_iocb = 64;
741 i386_linux_record_tdep.size_epoll_event = 12;
2c543fc4
HZ
742 i386_linux_record_tdep.size_itimerspec
743 = i386_linux_record_tdep.size_timespec * 2;
5e31abdf
HZ
744 i386_linux_record_tdep.size_mq_attr = 32;
745 i386_linux_record_tdep.size_siginfo = 128;
746 i386_linux_record_tdep.size_termios = 36;
747 i386_linux_record_tdep.size_termios2 = 44;
748 i386_linux_record_tdep.size_pid_t = 4;
749 i386_linux_record_tdep.size_winsize = 8;
750 i386_linux_record_tdep.size_serial_struct = 60;
751 i386_linux_record_tdep.size_serial_icounter_struct = 80;
752 i386_linux_record_tdep.size_hayes_esp_config = 12;
2c543fc4
HZ
753 i386_linux_record_tdep.size_size_t = 4;
754 i386_linux_record_tdep.size_iovec = 8;
5e31abdf
HZ
755
756 /* These values are the second argument of system call "sys_ioctl".
757 They are obtained from Linux Kernel source. */
758 i386_linux_record_tdep.ioctl_TCGETS = 0x5401;
759 i386_linux_record_tdep.ioctl_TCSETS = 0x5402;
760 i386_linux_record_tdep.ioctl_TCSETSW = 0x5403;
761 i386_linux_record_tdep.ioctl_TCSETSF = 0x5404;
762 i386_linux_record_tdep.ioctl_TCGETA = 0x5405;
763 i386_linux_record_tdep.ioctl_TCSETA = 0x5406;
764 i386_linux_record_tdep.ioctl_TCSETAW = 0x5407;
765 i386_linux_record_tdep.ioctl_TCSETAF = 0x5408;
766 i386_linux_record_tdep.ioctl_TCSBRK = 0x5409;
767 i386_linux_record_tdep.ioctl_TCXONC = 0x540A;
768 i386_linux_record_tdep.ioctl_TCFLSH = 0x540B;
769 i386_linux_record_tdep.ioctl_TIOCEXCL = 0x540C;
770 i386_linux_record_tdep.ioctl_TIOCNXCL = 0x540D;
771 i386_linux_record_tdep.ioctl_TIOCSCTTY = 0x540E;
772 i386_linux_record_tdep.ioctl_TIOCGPGRP = 0x540F;
773 i386_linux_record_tdep.ioctl_TIOCSPGRP = 0x5410;
774 i386_linux_record_tdep.ioctl_TIOCOUTQ = 0x5411;
775 i386_linux_record_tdep.ioctl_TIOCSTI = 0x5412;
776 i386_linux_record_tdep.ioctl_TIOCGWINSZ = 0x5413;
777 i386_linux_record_tdep.ioctl_TIOCSWINSZ = 0x5414;
778 i386_linux_record_tdep.ioctl_TIOCMGET = 0x5415;
779 i386_linux_record_tdep.ioctl_TIOCMBIS = 0x5416;
780 i386_linux_record_tdep.ioctl_TIOCMBIC = 0x5417;
781 i386_linux_record_tdep.ioctl_TIOCMSET = 0x5418;
782 i386_linux_record_tdep.ioctl_TIOCGSOFTCAR = 0x5419;
783 i386_linux_record_tdep.ioctl_TIOCSSOFTCAR = 0x541A;
784 i386_linux_record_tdep.ioctl_FIONREAD = 0x541B;
785 i386_linux_record_tdep.ioctl_TIOCINQ = i386_linux_record_tdep.ioctl_FIONREAD;
786 i386_linux_record_tdep.ioctl_TIOCLINUX = 0x541C;
787 i386_linux_record_tdep.ioctl_TIOCCONS = 0x541D;
788 i386_linux_record_tdep.ioctl_TIOCGSERIAL = 0x541E;
789 i386_linux_record_tdep.ioctl_TIOCSSERIAL = 0x541F;
790 i386_linux_record_tdep.ioctl_TIOCPKT = 0x5420;
791 i386_linux_record_tdep.ioctl_FIONBIO = 0x5421;
792 i386_linux_record_tdep.ioctl_TIOCNOTTY = 0x5422;
793 i386_linux_record_tdep.ioctl_TIOCSETD = 0x5423;
794 i386_linux_record_tdep.ioctl_TIOCGETD = 0x5424;
795 i386_linux_record_tdep.ioctl_TCSBRKP = 0x5425;
796 i386_linux_record_tdep.ioctl_TIOCTTYGSTRUCT = 0x5426;
797 i386_linux_record_tdep.ioctl_TIOCSBRK = 0x5427;
798 i386_linux_record_tdep.ioctl_TIOCCBRK = 0x5428;
799 i386_linux_record_tdep.ioctl_TIOCGSID = 0x5429;
800 i386_linux_record_tdep.ioctl_TCGETS2 = 0x802c542a;
801 i386_linux_record_tdep.ioctl_TCSETS2 = 0x402c542b;
802 i386_linux_record_tdep.ioctl_TCSETSW2 = 0x402c542c;
803 i386_linux_record_tdep.ioctl_TCSETSF2 = 0x402c542d;
804 i386_linux_record_tdep.ioctl_TIOCGPTN = 0x80045430;
805 i386_linux_record_tdep.ioctl_TIOCSPTLCK = 0x40045431;
806 i386_linux_record_tdep.ioctl_FIONCLEX = 0x5450;
807 i386_linux_record_tdep.ioctl_FIOCLEX = 0x5451;
808 i386_linux_record_tdep.ioctl_FIOASYNC = 0x5452;
809 i386_linux_record_tdep.ioctl_TIOCSERCONFIG = 0x5453;
810 i386_linux_record_tdep.ioctl_TIOCSERGWILD = 0x5454;
811 i386_linux_record_tdep.ioctl_TIOCSERSWILD = 0x5455;
812 i386_linux_record_tdep.ioctl_TIOCGLCKTRMIOS = 0x5456;
813 i386_linux_record_tdep.ioctl_TIOCSLCKTRMIOS = 0x5457;
814 i386_linux_record_tdep.ioctl_TIOCSERGSTRUCT = 0x5458;
815 i386_linux_record_tdep.ioctl_TIOCSERGETLSR = 0x5459;
816 i386_linux_record_tdep.ioctl_TIOCSERGETMULTI = 0x545A;
817 i386_linux_record_tdep.ioctl_TIOCSERSETMULTI = 0x545B;
818 i386_linux_record_tdep.ioctl_TIOCMIWAIT = 0x545C;
819 i386_linux_record_tdep.ioctl_TIOCGICOUNT = 0x545D;
820 i386_linux_record_tdep.ioctl_TIOCGHAYESESP = 0x545E;
821 i386_linux_record_tdep.ioctl_TIOCSHAYESESP = 0x545F;
822 i386_linux_record_tdep.ioctl_FIOQSIZE = 0x5460;
823
824 /* These values are the second argument of system call "sys_fcntl"
825 and "sys_fcntl64". They are obtained from Linux Kernel source. */
826 i386_linux_record_tdep.fcntl_F_GETLK = 5;
827 i386_linux_record_tdep.fcntl_F_GETLK64 = 12;
828 i386_linux_record_tdep.fcntl_F_SETLK64 = 13;
829 i386_linux_record_tdep.fcntl_F_SETLKW64 = 14;
50ef67b3 830
77fcef51
HZ
831 i386_linux_record_tdep.arg1 = I386_EBX_REGNUM;
832 i386_linux_record_tdep.arg2 = I386_ECX_REGNUM;
833 i386_linux_record_tdep.arg3 = I386_EDX_REGNUM;
834 i386_linux_record_tdep.arg4 = I386_ESI_REGNUM;
835 i386_linux_record_tdep.arg5 = I386_EDI_REGNUM;
2c543fc4 836 i386_linux_record_tdep.arg6 = I386_EBP_REGNUM;
77fcef51
HZ
837
838 tdep->i386_intx80_record = i386_linux_intx80_sysenter_record;
839 tdep->i386_sysenter_record = i386_linux_intx80_sysenter_record;
840
203c3895
UW
841 /* N_FUN symbols in shared libaries have 0 for their values and need
842 to be relocated. */
843 set_gdbarch_sofun_address_maybe_missing (gdbarch, 1);
844
871fbe6a 845 /* GNU/Linux uses SVR4-style shared libraries. */
982e9687 846 set_gdbarch_skip_trampoline_code (gdbarch, find_solib_trampoline_target);
871fbe6a
MK
847 set_solib_svr4_fetch_link_map_offsets
848 (gdbarch, svr4_ilp32_fetch_link_map_offsets);
849
850 /* GNU/Linux uses the dynamic linker included in the GNU C Library. */
bb41a796 851 set_gdbarch_skip_solib_resolver (gdbarch, glibc_skip_solib_resolver);
12b8a2cb
DJ
852
853 dwarf2_frame_set_signal_frame_p (gdbarch, i386_linux_dwarf_signal_frame_p);
b2756930
KB
854
855 /* Enable TLS support. */
856 set_gdbarch_fetch_tls_load_module_address (gdbarch,
857 svr4_fetch_objfile_link_map);
237fc4c9 858
17ea7499
CES
859 /* Install supported register note sections. */
860 set_gdbarch_core_regset_sections (gdbarch, i386_linux_regset_sections);
861
90884b2b
L
862 set_gdbarch_core_read_description (gdbarch,
863 i386_linux_core_read_description);
864
237fc4c9
PA
865 /* Displaced stepping. */
866 set_gdbarch_displaced_step_copy_insn (gdbarch,
867 simple_displaced_step_copy_insn);
868 set_gdbarch_displaced_step_fixup (gdbarch, i386_displaced_step_fixup);
869 set_gdbarch_displaced_step_free_closure (gdbarch,
870 simple_displaced_step_free_closure);
871 set_gdbarch_displaced_step_location (gdbarch,
872 displaced_step_at_entry_point);
4aa995e1 873
a96d9b2e
SDJ
874 /* Functions for 'catch syscall'. */
875 set_xml_syscall_file_name (XML_SYSCALL_FILENAME_I386);
876 set_gdbarch_get_syscall_number (gdbarch,
877 i386_linux_get_syscall_number);
878
4aa995e1 879 set_gdbarch_get_siginfo_type (gdbarch, linux_get_siginfo_type);
8201327c
MK
880}
881
882/* Provide a prototype to silence -Wmissing-prototypes. */
883extern void _initialize_i386_linux_tdep (void);
884
885void
886_initialize_i386_linux_tdep (void)
887{
05816f70 888 gdbarch_register_osabi (bfd_arch_i386, 0, GDB_OSABI_LINUX,
8201327c 889 i386_linux_init_abi);
90884b2b
L
890
891 /* Initialize the Linux target description */
892 initialize_tdesc_i386_linux ();
c131fcee 893 initialize_tdesc_i386_avx_linux ();
8201327c 894}
This page took 0.764355 seconds and 4 git commands to generate.