1 /* Target-dependent code for GNU/Linux i386.
3 Copyright (C) 2000-2024 Free Software Foundation, Inc.
5 This file is part of GDB.
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
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
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.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
20 #include "extract-store-integer.h"
28 #include "reggroups.h"
29 #include "dwarf2/frame.h"
30 #include "i386-tdep.h"
31 #include "i386-linux-tdep.h"
32 #include "linux-tdep.h"
34 #include "glibc-tdep.h"
35 #include "solib-svr4.h"
37 #include "arch-utils.h"
38 #include "xml-syscall.h"
41 #include "i387-tdep.h"
42 #include "gdbsupport/x86-xstate.h"
43 #include "arch/i386-linux-tdesc.h"
44 #include "arch/x86-linux-tdesc.h"
46 /* The syscall's XML filename for i386. */
47 #define XML_SYSCALL_FILENAME_I386 "syscalls/i386-linux.xml"
49 #include "record-full.h"
50 #include "linux-record.h"
52 #include "arch/i386.h"
53 #include "target-descriptions.h"
55 /* Return non-zero, when the register is in the corresponding register
56 group. Put the LINUX_ORIG_EAX register in the system group. */
58 i386_linux_register_reggroup_p (struct gdbarch
*gdbarch
, int regnum
,
59 const struct reggroup
*group
)
61 if (regnum
== I386_LINUX_ORIG_EAX_REGNUM
)
62 return (group
== system_reggroup
63 || group
== save_reggroup
64 || group
== restore_reggroup
);
65 return i386_register_reggroup_p (gdbarch
, regnum
, group
);
69 /* Recognizing signal handler frames. */
71 /* GNU/Linux has two flavors of signals. Normal signal handlers, and
72 "realtime" (RT) signals. The RT signals can provide additional
73 information to the signal handler if the SA_SIGINFO flag is set
74 when establishing a signal handler using `sigaction'. It is not
75 unlikely that future versions of GNU/Linux will support SA_SIGINFO
76 for normal signals too. */
78 /* When the i386 Linux kernel calls a signal handler and the
79 SA_RESTORER flag isn't set, the return address points to a bit of
80 code on the stack. This function returns whether the PC appears to
81 be within this bit of code.
83 The instruction sequence for normal signals is
87 or 0x58 0xb8 0x77 0x00 0x00 0x00 0xcd 0x80.
89 Checking for the code sequence should be somewhat reliable, because
90 the effect is to call the system call sigreturn. This is unlikely
91 to occur anywhere other than in a signal trampoline.
93 It kind of sucks that we have to read memory from the process in
94 order to identify a signal trampoline, but there doesn't seem to be
95 any other way. Therefore we only do the memory reads if no
96 function name could be identified, which should be the case since
97 the code is on the stack.
99 Detection of signal trampolines for handlers that set the
100 SA_RESTORER flag is in general not possible. Unfortunately this is
101 what the GNU C Library has been doing for quite some time now.
102 However, as of version 2.1.2, the GNU C Library uses signal
103 trampolines (named __restore and __restore_rt) that are identical
104 to the ones used by the kernel. Therefore, these trampolines are
107 #define LINUX_SIGTRAMP_INSN0 0x58 /* pop %eax */
108 #define LINUX_SIGTRAMP_OFFSET0 0
109 #define LINUX_SIGTRAMP_INSN1 0xb8 /* mov $NNNN, %eax */
110 #define LINUX_SIGTRAMP_OFFSET1 1
111 #define LINUX_SIGTRAMP_INSN2 0xcd /* int */
112 #define LINUX_SIGTRAMP_OFFSET2 6
114 static const gdb_byte linux_sigtramp_code
[] =
116 LINUX_SIGTRAMP_INSN0
, /* pop %eax */
117 LINUX_SIGTRAMP_INSN1
, 0x77, 0x00, 0x00, 0x00, /* mov $0x77, %eax */
118 LINUX_SIGTRAMP_INSN2
, 0x80 /* int $0x80 */
121 #define LINUX_SIGTRAMP_LEN (sizeof linux_sigtramp_code)
123 /* If THIS_FRAME is a sigtramp routine, return the address of the
124 start of the routine. Otherwise, return 0. */
127 i386_linux_sigtramp_start (const frame_info_ptr
&this_frame
)
129 CORE_ADDR pc
= get_frame_pc (this_frame
);
130 gdb_byte buf
[LINUX_SIGTRAMP_LEN
];
132 /* We only recognize a signal trampoline if PC is at the start of
133 one of the three instructions. We optimize for finding the PC at
134 the start, as will be the case when the trampoline is not the
135 first frame on the stack. We assume that in the case where the
136 PC is not at the start of the instruction sequence, there will be
137 a few trailing readable bytes on the stack. */
139 if (!safe_frame_unwind_memory (this_frame
, pc
, buf
))
142 if (buf
[0] != LINUX_SIGTRAMP_INSN0
)
148 case LINUX_SIGTRAMP_INSN1
:
149 adjust
= LINUX_SIGTRAMP_OFFSET1
;
151 case LINUX_SIGTRAMP_INSN2
:
152 adjust
= LINUX_SIGTRAMP_OFFSET2
;
160 if (!safe_frame_unwind_memory (this_frame
, pc
, buf
))
164 if (memcmp (buf
, linux_sigtramp_code
, LINUX_SIGTRAMP_LEN
) != 0)
170 /* This function does the same for RT signals. Here the instruction
174 or 0xb8 0xad 0x00 0x00 0x00 0xcd 0x80.
176 The effect is to call the system call rt_sigreturn. */
178 #define LINUX_RT_SIGTRAMP_INSN0 0xb8 /* mov $NNNN, %eax */
179 #define LINUX_RT_SIGTRAMP_OFFSET0 0
180 #define LINUX_RT_SIGTRAMP_INSN1 0xcd /* int */
181 #define LINUX_RT_SIGTRAMP_OFFSET1 5
183 static const gdb_byte linux_rt_sigtramp_code
[] =
185 LINUX_RT_SIGTRAMP_INSN0
, 0xad, 0x00, 0x00, 0x00, /* mov $0xad, %eax */
186 LINUX_RT_SIGTRAMP_INSN1
, 0x80 /* int $0x80 */
189 #define LINUX_RT_SIGTRAMP_LEN (sizeof linux_rt_sigtramp_code)
191 /* If THIS_FRAME is an RT sigtramp routine, return the address of the
192 start of the routine. Otherwise, return 0. */
195 i386_linux_rt_sigtramp_start (const frame_info_ptr
&this_frame
)
197 CORE_ADDR pc
= get_frame_pc (this_frame
);
198 gdb_byte buf
[LINUX_RT_SIGTRAMP_LEN
];
200 /* We only recognize a signal trampoline if PC is at the start of
201 one of the two instructions. We optimize for finding the PC at
202 the start, as will be the case when the trampoline is not the
203 first frame on the stack. We assume that in the case where the
204 PC is not at the start of the instruction sequence, there will be
205 a few trailing readable bytes on the stack. */
207 if (!safe_frame_unwind_memory (this_frame
, pc
, buf
))
210 if (buf
[0] != LINUX_RT_SIGTRAMP_INSN0
)
212 if (buf
[0] != LINUX_RT_SIGTRAMP_INSN1
)
215 pc
-= LINUX_RT_SIGTRAMP_OFFSET1
;
217 if (!safe_frame_unwind_memory (this_frame
, pc
,
222 if (memcmp (buf
, linux_rt_sigtramp_code
, LINUX_RT_SIGTRAMP_LEN
) != 0)
228 /* Return whether THIS_FRAME corresponds to a GNU/Linux sigtramp
232 i386_linux_sigtramp_p (const frame_info_ptr
&this_frame
)
234 CORE_ADDR pc
= get_frame_pc (this_frame
);
237 find_pc_partial_function (pc
, &name
, NULL
, NULL
);
239 /* If we have NAME, we can optimize the search. The trampolines are
240 named __restore and __restore_rt. However, they aren't dynamically
241 exported from the shared C library, so the trampoline may appear to
242 be part of the preceding function. This should always be sigaction,
243 __sigaction, or __libc_sigaction (all aliases to the same function). */
244 if (name
== NULL
|| strstr (name
, "sigaction") != NULL
)
245 return (i386_linux_sigtramp_start (this_frame
) != 0
246 || i386_linux_rt_sigtramp_start (this_frame
) != 0);
248 return (strcmp ("__restore", name
) == 0
249 || strcmp ("__restore_rt", name
) == 0);
252 /* Return one if the PC of THIS_FRAME is in a signal trampoline which
253 may have DWARF-2 CFI. */
256 i386_linux_dwarf_signal_frame_p (struct gdbarch
*gdbarch
,
257 const frame_info_ptr
&this_frame
)
259 CORE_ADDR pc
= get_frame_pc (this_frame
);
262 find_pc_partial_function (pc
, &name
, NULL
, NULL
);
264 /* If a vsyscall DSO is in use, the signal trampolines may have these
266 if (name
&& (strcmp (name
, "__kernel_sigreturn") == 0
267 || strcmp (name
, "__kernel_rt_sigreturn") == 0))
273 /* Offset to struct sigcontext in ucontext, from <asm/ucontext.h>. */
274 #define I386_LINUX_UCONTEXT_SIGCONTEXT_OFFSET 20
276 /* Assuming THIS_FRAME is a GNU/Linux sigtramp routine, return the
277 address of the associated sigcontext structure. */
280 i386_linux_sigcontext_addr (const frame_info_ptr
&this_frame
)
282 struct gdbarch
*gdbarch
= get_frame_arch (this_frame
);
283 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
288 get_frame_register (this_frame
, I386_ESP_REGNUM
, buf
);
289 sp
= extract_unsigned_integer (buf
, 4, byte_order
);
291 pc
= i386_linux_sigtramp_start (this_frame
);
294 /* The sigcontext structure lives on the stack, right after
295 the signum argument. We determine the address of the
296 sigcontext structure by looking at the frame's stack
297 pointer. Keep in mind that the first instruction of the
298 sigtramp code is "pop %eax". If the PC is after this
299 instruction, adjust the returned value accordingly. */
300 if (pc
== get_frame_pc (this_frame
))
305 pc
= i386_linux_rt_sigtramp_start (this_frame
);
308 CORE_ADDR ucontext_addr
;
310 /* The sigcontext structure is part of the user context. A
311 pointer to the user context is passed as the third argument
312 to the signal handler. */
313 read_memory (sp
+ 8, buf
, 4);
314 ucontext_addr
= extract_unsigned_integer (buf
, 4, byte_order
);
315 return ucontext_addr
+ I386_LINUX_UCONTEXT_SIGCONTEXT_OFFSET
;
318 error (_("Couldn't recognize signal trampoline."));
322 /* Set the program counter for process PTID to PC. */
325 i386_linux_write_pc (struct regcache
*regcache
, CORE_ADDR pc
)
327 regcache_cooked_write_unsigned (regcache
, I386_EIP_REGNUM
, pc
);
329 /* We must be careful with modifying the program counter. If we
330 just interrupted a system call, the kernel might try to restart
331 it when we resume the inferior. On restarting the system call,
332 the kernel will try backing up the program counter even though it
333 no longer points at the system call. This typically results in a
334 SIGSEGV or SIGILL. We can prevent this by writing `-1' in the
335 "orig_eax" pseudo-register.
337 Note that "orig_eax" is saved when setting up a dummy call frame.
338 This means that it is properly restored when that frame is
339 popped, and that the interrupted system call will be restarted
340 when we resume the inferior on return from a function call from
341 within GDB. In all other cases the system call will not be
343 regcache_cooked_write_unsigned (regcache
, I386_LINUX_ORIG_EAX_REGNUM
, -1);
346 /* Record all registers but IP register for process-record. */
349 i386_all_but_ip_registers_record (struct regcache
*regcache
)
351 if (record_full_arch_list_add_reg (regcache
, I386_EAX_REGNUM
))
353 if (record_full_arch_list_add_reg (regcache
, I386_ECX_REGNUM
))
355 if (record_full_arch_list_add_reg (regcache
, I386_EDX_REGNUM
))
357 if (record_full_arch_list_add_reg (regcache
, I386_EBX_REGNUM
))
359 if (record_full_arch_list_add_reg (regcache
, I386_ESP_REGNUM
))
361 if (record_full_arch_list_add_reg (regcache
, I386_EBP_REGNUM
))
363 if (record_full_arch_list_add_reg (regcache
, I386_ESI_REGNUM
))
365 if (record_full_arch_list_add_reg (regcache
, I386_EDI_REGNUM
))
367 if (record_full_arch_list_add_reg (regcache
, I386_EFLAGS_REGNUM
))
373 /* i386_canonicalize_syscall maps from the native i386 Linux set
374 of syscall ids into a canonical set of syscall ids used by
375 process record (a mostly trivial mapping, since the canonical
376 set was originally taken from the i386 set). */
378 static enum gdb_syscall
379 i386_canonicalize_syscall (int syscall
)
381 enum { i386_syscall_max
= 499 };
383 if (syscall
<= i386_syscall_max
)
384 return (enum gdb_syscall
) syscall
;
386 return gdb_sys_no_syscall
;
389 /* Value of the sigcode in case of a boundary fault. */
391 #define SIG_CODE_BOUNDARY_FAULT 3
393 /* Parse the arguments of current system call instruction and record
394 the values of the registers and memory that will be changed into
395 "record_arch_list". This instruction is "int 0x80" (Linux
396 Kernel2.4) or "sysenter" (Linux Kernel 2.6).
398 Return -1 if something wrong. */
400 static struct linux_record_tdep i386_linux_record_tdep
;
403 i386_linux_intx80_sysenter_syscall_record (struct regcache
*regcache
)
406 LONGEST syscall_native
;
407 enum gdb_syscall syscall_gdb
;
409 regcache_raw_read_signed (regcache
, I386_EAX_REGNUM
, &syscall_native
);
411 syscall_gdb
= i386_canonicalize_syscall (syscall_native
);
415 gdb_printf (gdb_stderr
,
416 _("Process record and replay target doesn't "
417 "support syscall number %s\n"),
418 plongest (syscall_native
));
422 if (syscall_gdb
== gdb_sys_sigreturn
423 || syscall_gdb
== gdb_sys_rt_sigreturn
)
425 if (i386_all_but_ip_registers_record (regcache
))
430 ret
= record_linux_system_call (syscall_gdb
, regcache
,
431 &i386_linux_record_tdep
);
435 /* Record the return value of the system call. */
436 if (record_full_arch_list_add_reg (regcache
, I386_EAX_REGNUM
))
442 #define I386_LINUX_xstate 270
443 #define I386_LINUX_frame_size 732
446 i386_linux_record_signal (struct gdbarch
*gdbarch
,
447 struct regcache
*regcache
,
448 enum gdb_signal signal
)
452 if (i386_all_but_ip_registers_record (regcache
))
455 if (record_full_arch_list_add_reg (regcache
, I386_EIP_REGNUM
))
458 /* Record the change in the stack. */
459 regcache_raw_read_unsigned (regcache
, I386_ESP_REGNUM
, &esp
);
460 /* This is for xstate.
461 sp -= sizeof (struct _fpstate); */
462 esp
-= I386_LINUX_xstate
;
463 /* This is for frame_size.
464 sp -= sizeof (struct rt_sigframe); */
465 esp
-= I386_LINUX_frame_size
;
466 if (record_full_arch_list_add_mem (esp
,
467 I386_LINUX_xstate
+ I386_LINUX_frame_size
))
470 if (record_full_arch_list_add_end ())
477 /* Core of the implementation for gdbarch get_syscall_number. Get pending
478 syscall number from REGCACHE. If there is no pending syscall -1 will be
479 returned. Pending syscall means ptrace has stepped into the syscall but
480 another ptrace call will step out. PC is right after the int $0x80
481 / syscall / sysenter instruction in both cases, PC does not change during
482 the second ptrace step. */
485 i386_linux_get_syscall_number_from_regcache (struct regcache
*regcache
)
487 struct gdbarch
*gdbarch
= regcache
->arch ();
488 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
489 /* The content of a register. */
494 /* Getting the system call number from the register.
495 When dealing with x86 architecture, this information
496 is stored at %eax register. */
497 regcache
->cooked_read (I386_LINUX_ORIG_EAX_REGNUM
, buf
);
499 ret
= extract_signed_integer (buf
, byte_order
);
504 /* Wrapper for i386_linux_get_syscall_number_from_regcache to make it
505 compatible with gdbarch get_syscall_number method prototype. */
508 i386_linux_get_syscall_number (struct gdbarch
*gdbarch
,
511 struct regcache
*regcache
= get_thread_regcache (thread
);
513 return i386_linux_get_syscall_number_from_regcache (regcache
);
516 /* The register sets used in GNU/Linux ELF core-dumps are identical to
517 the register sets in `struct user' that are used for a.out
518 core-dumps. These are also used by ptrace(2). The corresponding
519 types are `elf_gregset_t' for the general-purpose registers (with
520 `elf_greg_t' the type of a single GP register) and `elf_fpregset_t'
521 for the floating-point registers.
523 Those types used to be available under the names `gregset_t' and
524 `fpregset_t' too, and GDB used those names in the past. But those
525 names are now used for the register sets used in the `mcontext_t'
526 type, which have a different size and layout. */
528 /* Mapping between the general-purpose registers in `struct user'
529 format and GDB's register cache layout. */
531 /* From <sys/reg.h>. */
532 int i386_linux_gregset_reg_offset
[] =
543 14 * 4, /* %eflags */
550 -1, -1, -1, -1, -1, -1, -1, -1,
551 -1, -1, -1, -1, -1, -1, -1, -1,
552 -1, -1, -1, -1, -1, -1, -1, -1,
554 -1, -1, -1, -1, -1, -1, -1, -1,
555 /* MPX is deprecated. Yet we keep this to not give the registers below
556 a new number. That could break older gdbservers. */
557 -1, -1, -1, -1, /* MPX registers BND0 ... BND3. */
558 -1, -1, /* MPX registers BNDCFGU, BNDSTATUS. */
559 -1, -1, -1, -1, -1, -1, -1, -1, /* k0 ... k7 (AVX512) */
560 -1, -1, -1, -1, -1, -1, -1, -1, /* zmm0 ... zmm7 (AVX512) */
561 -1, /* PKRU register */
562 11 * 4, /* "orig_eax" */
565 /* Mapping between the general-purpose registers in `struct
566 sigcontext' format and GDB's register cache layout. */
568 /* From <asm/sigcontext.h>. */
569 static int i386_linux_sc_reg_offset
[] =
580 16 * 4, /* %eflags */
589 /* See i386-linux-tdep.h. */
592 i386_linux_core_read_xsave_info (bfd
*abfd
, x86_xsave_layout
&layout
)
594 asection
*xstate
= bfd_get_section_by_name (abfd
, ".reg-xstate");
595 if (xstate
== nullptr)
598 /* Check extended state size. */
599 size_t size
= bfd_section_size (xstate
);
600 if (size
< X86_XSTATE_AVX_SIZE
)
604 if (! bfd_get_section_contents (abfd
, xstate
, contents
,
605 I386_LINUX_XSAVE_XCR0_OFFSET
, 8))
607 warning (_("Couldn't read `xcr0' bytes from "
608 "`.reg-xstate' section in core file."));
612 uint64_t xcr0
= bfd_get_64 (abfd
, contents
);
614 if (!i387_guess_xsave_layout (xcr0
, size
, layout
))
620 /* See i386-linux-tdep.h. */
623 i386_linux_core_read_x86_xsave_layout (struct gdbarch
*gdbarch
,
624 x86_xsave_layout
&layout
)
626 return i386_linux_core_read_xsave_info (current_program_space
->core_bfd (),
630 /* See arch/x86-linux-tdesc.h. */
633 x86_linux_post_init_tdesc (target_desc
*tdesc
, bool is_64bit
)
638 /* Get Linux/x86 target description from core dump. */
640 static const struct target_desc
*
641 i386_linux_core_read_description (struct gdbarch
*gdbarch
,
642 struct target_ops
*target
,
646 x86_xsave_layout layout
;
647 uint64_t xcr0
= i386_linux_core_read_xsave_info (abfd
, layout
);
651 if (bfd_get_section_by_name (abfd
, ".reg-xfp") != nullptr)
652 xcr0
= X86_XSTATE_SSE_MASK
;
654 xcr0
= X86_XSTATE_X87_MASK
;
657 return i386_linux_read_description (xcr0
);
660 /* Similar to i386_supply_fpregset, but use XSAVE extended state. */
663 i386_linux_supply_xstateregset (const struct regset
*regset
,
664 struct regcache
*regcache
, int regnum
,
665 const void *xstateregs
, size_t len
)
667 i387_supply_xsave (regcache
, regnum
, xstateregs
);
670 /* Similar to i386_collect_fpregset, but use XSAVE extended state. */
673 i386_linux_collect_xstateregset (const struct regset
*regset
,
674 const struct regcache
*regcache
,
675 int regnum
, void *xstateregs
, size_t len
)
677 i387_collect_xsave (regcache
, regnum
, xstateregs
, 1);
680 /* Register set definitions. */
682 static const struct regset i386_linux_xstateregset
=
685 i386_linux_supply_xstateregset
,
686 i386_linux_collect_xstateregset
689 /* Iterate over core file register note sections. */
692 i386_linux_iterate_over_regset_sections (struct gdbarch
*gdbarch
,
693 iterate_over_regset_sections_cb
*cb
,
695 const struct regcache
*regcache
)
697 i386_gdbarch_tdep
*tdep
= gdbarch_tdep
<i386_gdbarch_tdep
> (gdbarch
);
699 cb (".reg", 68, 68, &i386_gregset
, NULL
, cb_data
);
701 if (tdep
->xsave_layout
.sizeof_xsave
!= 0)
702 cb (".reg-xstate", tdep
->xsave_layout
.sizeof_xsave
,
703 tdep
->xsave_layout
.sizeof_xsave
, &i386_linux_xstateregset
,
704 "XSAVE extended state", cb_data
);
705 else if (tdep
->xcr0
& X86_XSTATE_SSE
)
706 cb (".reg-xfp", 512, 512, &i386_fpregset
, "extended floating-point",
709 cb (".reg2", 108, 108, &i386_fpregset
, NULL
, cb_data
);
712 /* Linux kernel shows PC value after the 'int $0x80' instruction even if
713 inferior is still inside the syscall. On next PTRACE_SINGLESTEP it will
714 finish the syscall but PC will not change.
716 Some vDSOs contain 'int $0x80; ret' and during stepping out of the syscall
717 i386_displaced_step_fixup would keep PC at the displaced pad location.
718 As PC is pointing to the 'ret' instruction before the step
719 i386_displaced_step_fixup would expect inferior has just executed that 'ret'
720 and PC should not be adjusted. In reality it finished syscall instead and
721 PC should get relocated back to its vDSO address. Hide the 'ret'
722 instruction by 'nop' so that i386_displaced_step_fixup is not confused.
724 It is not fully correct as the bytes in struct
725 displaced_step_copy_insn_closure will not match the inferior code. But we
726 would need some new flag in displaced_step_copy_insn_closure otherwise to
727 keep the state that syscall is finishing for the later
728 i386_displaced_step_fixup execution as the syscall execution is already no
729 longer detectable there. The new flag field would mean i386-linux-tdep.c
730 needs to wrap all the displacement methods of i386-tdep.c which does not seem
731 worth it. The same effect is achieved by patching that 'nop' instruction
734 static displaced_step_copy_insn_closure_up
735 i386_linux_displaced_step_copy_insn (struct gdbarch
*gdbarch
,
736 CORE_ADDR from
, CORE_ADDR to
,
737 struct regcache
*regs
)
739 displaced_step_copy_insn_closure_up closure_
740 = i386_displaced_step_copy_insn (gdbarch
, from
, to
, regs
);
742 if (i386_linux_get_syscall_number_from_regcache (regs
) != -1)
744 /* The closure returned by i386_displaced_step_copy_insn is simply a
745 buffer with a copy of the instruction. */
746 i386_displaced_step_copy_insn_closure
*closure
747 = (i386_displaced_step_copy_insn_closure
*) closure_
.get ();
750 closure
->buf
[0] = 0x90;
757 i386_linux_init_abi (struct gdbarch_info info
, struct gdbarch
*gdbarch
)
759 i386_gdbarch_tdep
*tdep
= gdbarch_tdep
<i386_gdbarch_tdep
> (gdbarch
);
760 const struct target_desc
*tdesc
= info
.target_desc
;
761 struct tdesc_arch_data
*tdesc_data
= info
.tdesc_data
;
762 const struct tdesc_feature
*feature
;
765 gdb_assert (tdesc_data
);
767 linux_init_abi (info
, gdbarch
, 1);
769 /* GNU/Linux uses ELF. */
770 i386_elf_init_abi (info
, gdbarch
);
772 /* Reserve a number for orig_eax. */
773 set_gdbarch_num_regs (gdbarch
, I386_LINUX_NUM_REGS
);
775 if (! tdesc_has_registers (tdesc
))
776 tdesc
= i386_linux_read_description (X86_XSTATE_SSE_MASK
);
779 feature
= tdesc_find_feature (tdesc
, "org.gnu.gdb.i386.linux");
783 valid_p
= tdesc_numbered_register (feature
, tdesc_data
,
784 I386_LINUX_ORIG_EAX_REGNUM
,
789 /* Add the %orig_eax register used for syscall restarting. */
790 set_gdbarch_write_pc (gdbarch
, i386_linux_write_pc
);
792 tdep
->register_reggroup_p
= i386_linux_register_reggroup_p
;
794 tdep
->gregset_reg_offset
= i386_linux_gregset_reg_offset
;
795 tdep
->gregset_num_regs
= ARRAY_SIZE (i386_linux_gregset_reg_offset
);
796 tdep
->sizeof_gregset
= 17 * 4;
798 tdep
->jb_pc_offset
= 20; /* From <bits/setjmp.h>. */
800 tdep
->sigtramp_p
= i386_linux_sigtramp_p
;
801 tdep
->sigcontext_addr
= i386_linux_sigcontext_addr
;
802 tdep
->sc_reg_offset
= i386_linux_sc_reg_offset
;
803 tdep
->sc_num_regs
= ARRAY_SIZE (i386_linux_sc_reg_offset
);
805 tdep
->xsave_xcr0_offset
= I386_LINUX_XSAVE_XCR0_OFFSET
;
806 set_gdbarch_core_read_x86_xsave_layout
807 (gdbarch
, i386_linux_core_read_x86_xsave_layout
);
809 set_gdbarch_process_record (gdbarch
, i386_process_record
);
810 set_gdbarch_process_record_signal (gdbarch
, i386_linux_record_signal
);
812 /* Initialize the i386_linux_record_tdep. */
813 /* These values are the size of the type that will be used in a system
814 call. They are obtained from Linux Kernel source. */
815 i386_linux_record_tdep
.size_pointer
816 = gdbarch_ptr_bit (gdbarch
) / TARGET_CHAR_BIT
;
817 i386_linux_record_tdep
.size__old_kernel_stat
= 32;
818 i386_linux_record_tdep
.size_tms
= 16;
819 i386_linux_record_tdep
.size_loff_t
= 8;
820 i386_linux_record_tdep
.size_flock
= 16;
821 i386_linux_record_tdep
.size_oldold_utsname
= 45;
822 i386_linux_record_tdep
.size_ustat
= 20;
823 i386_linux_record_tdep
.size_old_sigaction
= 16;
824 i386_linux_record_tdep
.size_old_sigset_t
= 4;
825 i386_linux_record_tdep
.size_rlimit
= 8;
826 i386_linux_record_tdep
.size_rusage
= 72;
827 i386_linux_record_tdep
.size_timeval
= 8;
828 i386_linux_record_tdep
.size_timezone
= 8;
829 i386_linux_record_tdep
.size_old_gid_t
= 2;
830 i386_linux_record_tdep
.size_old_uid_t
= 2;
831 i386_linux_record_tdep
.size_fd_set
= 128;
832 i386_linux_record_tdep
.size_old_dirent
= 268;
833 i386_linux_record_tdep
.size_statfs
= 64;
834 i386_linux_record_tdep
.size_statfs64
= 84;
835 i386_linux_record_tdep
.size_sockaddr
= 16;
836 i386_linux_record_tdep
.size_int
837 = gdbarch_int_bit (gdbarch
) / TARGET_CHAR_BIT
;
838 i386_linux_record_tdep
.size_long
839 = gdbarch_long_bit (gdbarch
) / TARGET_CHAR_BIT
;
840 i386_linux_record_tdep
.size_ulong
841 = gdbarch_long_bit (gdbarch
) / TARGET_CHAR_BIT
;
842 i386_linux_record_tdep
.size_msghdr
= 28;
843 i386_linux_record_tdep
.size_itimerval
= 16;
844 i386_linux_record_tdep
.size_stat
= 88;
845 i386_linux_record_tdep
.size_old_utsname
= 325;
846 i386_linux_record_tdep
.size_sysinfo
= 64;
847 i386_linux_record_tdep
.size_msqid_ds
= 88;
848 i386_linux_record_tdep
.size_shmid_ds
= 84;
849 i386_linux_record_tdep
.size_new_utsname
= 390;
850 i386_linux_record_tdep
.size_timex
= 128;
851 i386_linux_record_tdep
.size_mem_dqinfo
= 24;
852 i386_linux_record_tdep
.size_if_dqblk
= 68;
853 i386_linux_record_tdep
.size_fs_quota_stat
= 68;
854 i386_linux_record_tdep
.size_timespec
= 8;
855 i386_linux_record_tdep
.size_pollfd
= 8;
856 i386_linux_record_tdep
.size_NFS_FHSIZE
= 32;
857 i386_linux_record_tdep
.size_knfsd_fh
= 132;
858 i386_linux_record_tdep
.size_TASK_COMM_LEN
= 16;
859 i386_linux_record_tdep
.size_sigaction
= 20;
860 i386_linux_record_tdep
.size_sigset_t
= 8;
861 i386_linux_record_tdep
.size_siginfo_t
= 128;
862 i386_linux_record_tdep
.size_cap_user_data_t
= 12;
863 i386_linux_record_tdep
.size_stack_t
= 12;
864 i386_linux_record_tdep
.size_off_t
= i386_linux_record_tdep
.size_long
;
865 i386_linux_record_tdep
.size_stat64
= 96;
866 i386_linux_record_tdep
.size_gid_t
= 4;
867 i386_linux_record_tdep
.size_uid_t
= 4;
868 i386_linux_record_tdep
.size_PAGE_SIZE
= 4096;
869 i386_linux_record_tdep
.size_flock64
= 24;
870 i386_linux_record_tdep
.size_user_desc
= 16;
871 i386_linux_record_tdep
.size_io_event
= 32;
872 i386_linux_record_tdep
.size_iocb
= 64;
873 i386_linux_record_tdep
.size_epoll_event
= 12;
874 i386_linux_record_tdep
.size_itimerspec
875 = i386_linux_record_tdep
.size_timespec
* 2;
876 i386_linux_record_tdep
.size_mq_attr
= 32;
877 i386_linux_record_tdep
.size_termios
= 36;
878 i386_linux_record_tdep
.size_termios2
= 44;
879 i386_linux_record_tdep
.size_pid_t
= 4;
880 i386_linux_record_tdep
.size_winsize
= 8;
881 i386_linux_record_tdep
.size_serial_struct
= 60;
882 i386_linux_record_tdep
.size_serial_icounter_struct
= 80;
883 i386_linux_record_tdep
.size_hayes_esp_config
= 12;
884 i386_linux_record_tdep
.size_size_t
= 4;
885 i386_linux_record_tdep
.size_iovec
= 8;
886 i386_linux_record_tdep
.size_time_t
= 4;
888 /* These values are the second argument of system call "sys_ioctl".
889 They are obtained from Linux Kernel source. */
890 i386_linux_record_tdep
.ioctl_TCGETS
= 0x5401;
891 i386_linux_record_tdep
.ioctl_TCSETS
= 0x5402;
892 i386_linux_record_tdep
.ioctl_TCSETSW
= 0x5403;
893 i386_linux_record_tdep
.ioctl_TCSETSF
= 0x5404;
894 i386_linux_record_tdep
.ioctl_TCGETA
= 0x5405;
895 i386_linux_record_tdep
.ioctl_TCSETA
= 0x5406;
896 i386_linux_record_tdep
.ioctl_TCSETAW
= 0x5407;
897 i386_linux_record_tdep
.ioctl_TCSETAF
= 0x5408;
898 i386_linux_record_tdep
.ioctl_TCSBRK
= 0x5409;
899 i386_linux_record_tdep
.ioctl_TCXONC
= 0x540A;
900 i386_linux_record_tdep
.ioctl_TCFLSH
= 0x540B;
901 i386_linux_record_tdep
.ioctl_TIOCEXCL
= 0x540C;
902 i386_linux_record_tdep
.ioctl_TIOCNXCL
= 0x540D;
903 i386_linux_record_tdep
.ioctl_TIOCSCTTY
= 0x540E;
904 i386_linux_record_tdep
.ioctl_TIOCGPGRP
= 0x540F;
905 i386_linux_record_tdep
.ioctl_TIOCSPGRP
= 0x5410;
906 i386_linux_record_tdep
.ioctl_TIOCOUTQ
= 0x5411;
907 i386_linux_record_tdep
.ioctl_TIOCSTI
= 0x5412;
908 i386_linux_record_tdep
.ioctl_TIOCGWINSZ
= 0x5413;
909 i386_linux_record_tdep
.ioctl_TIOCSWINSZ
= 0x5414;
910 i386_linux_record_tdep
.ioctl_TIOCMGET
= 0x5415;
911 i386_linux_record_tdep
.ioctl_TIOCMBIS
= 0x5416;
912 i386_linux_record_tdep
.ioctl_TIOCMBIC
= 0x5417;
913 i386_linux_record_tdep
.ioctl_TIOCMSET
= 0x5418;
914 i386_linux_record_tdep
.ioctl_TIOCGSOFTCAR
= 0x5419;
915 i386_linux_record_tdep
.ioctl_TIOCSSOFTCAR
= 0x541A;
916 i386_linux_record_tdep
.ioctl_FIONREAD
= 0x541B;
917 i386_linux_record_tdep
.ioctl_TIOCINQ
= i386_linux_record_tdep
.ioctl_FIONREAD
;
918 i386_linux_record_tdep
.ioctl_TIOCLINUX
= 0x541C;
919 i386_linux_record_tdep
.ioctl_TIOCCONS
= 0x541D;
920 i386_linux_record_tdep
.ioctl_TIOCGSERIAL
= 0x541E;
921 i386_linux_record_tdep
.ioctl_TIOCSSERIAL
= 0x541F;
922 i386_linux_record_tdep
.ioctl_TIOCPKT
= 0x5420;
923 i386_linux_record_tdep
.ioctl_FIONBIO
= 0x5421;
924 i386_linux_record_tdep
.ioctl_TIOCNOTTY
= 0x5422;
925 i386_linux_record_tdep
.ioctl_TIOCSETD
= 0x5423;
926 i386_linux_record_tdep
.ioctl_TIOCGETD
= 0x5424;
927 i386_linux_record_tdep
.ioctl_TCSBRKP
= 0x5425;
928 i386_linux_record_tdep
.ioctl_TIOCTTYGSTRUCT
= 0x5426;
929 i386_linux_record_tdep
.ioctl_TIOCSBRK
= 0x5427;
930 i386_linux_record_tdep
.ioctl_TIOCCBRK
= 0x5428;
931 i386_linux_record_tdep
.ioctl_TIOCGSID
= 0x5429;
932 i386_linux_record_tdep
.ioctl_TCGETS2
= 0x802c542a;
933 i386_linux_record_tdep
.ioctl_TCSETS2
= 0x402c542b;
934 i386_linux_record_tdep
.ioctl_TCSETSW2
= 0x402c542c;
935 i386_linux_record_tdep
.ioctl_TCSETSF2
= 0x402c542d;
936 i386_linux_record_tdep
.ioctl_TIOCGPTN
= 0x80045430;
937 i386_linux_record_tdep
.ioctl_TIOCSPTLCK
= 0x40045431;
938 i386_linux_record_tdep
.ioctl_FIONCLEX
= 0x5450;
939 i386_linux_record_tdep
.ioctl_FIOCLEX
= 0x5451;
940 i386_linux_record_tdep
.ioctl_FIOASYNC
= 0x5452;
941 i386_linux_record_tdep
.ioctl_TIOCSERCONFIG
= 0x5453;
942 i386_linux_record_tdep
.ioctl_TIOCSERGWILD
= 0x5454;
943 i386_linux_record_tdep
.ioctl_TIOCSERSWILD
= 0x5455;
944 i386_linux_record_tdep
.ioctl_TIOCGLCKTRMIOS
= 0x5456;
945 i386_linux_record_tdep
.ioctl_TIOCSLCKTRMIOS
= 0x5457;
946 i386_linux_record_tdep
.ioctl_TIOCSERGSTRUCT
= 0x5458;
947 i386_linux_record_tdep
.ioctl_TIOCSERGETLSR
= 0x5459;
948 i386_linux_record_tdep
.ioctl_TIOCSERGETMULTI
= 0x545A;
949 i386_linux_record_tdep
.ioctl_TIOCSERSETMULTI
= 0x545B;
950 i386_linux_record_tdep
.ioctl_TIOCMIWAIT
= 0x545C;
951 i386_linux_record_tdep
.ioctl_TIOCGICOUNT
= 0x545D;
952 i386_linux_record_tdep
.ioctl_TIOCGHAYESESP
= 0x545E;
953 i386_linux_record_tdep
.ioctl_TIOCSHAYESESP
= 0x545F;
954 i386_linux_record_tdep
.ioctl_FIOQSIZE
= 0x5460;
956 /* These values are the second argument of system call "sys_fcntl"
957 and "sys_fcntl64". They are obtained from Linux Kernel source. */
958 i386_linux_record_tdep
.fcntl_F_GETLK
= 5;
959 i386_linux_record_tdep
.fcntl_F_GETLK64
= 12;
960 i386_linux_record_tdep
.fcntl_F_SETLK64
= 13;
961 i386_linux_record_tdep
.fcntl_F_SETLKW64
= 14;
963 i386_linux_record_tdep
.arg1
= I386_EBX_REGNUM
;
964 i386_linux_record_tdep
.arg2
= I386_ECX_REGNUM
;
965 i386_linux_record_tdep
.arg3
= I386_EDX_REGNUM
;
966 i386_linux_record_tdep
.arg4
= I386_ESI_REGNUM
;
967 i386_linux_record_tdep
.arg5
= I386_EDI_REGNUM
;
968 i386_linux_record_tdep
.arg6
= I386_EBP_REGNUM
;
970 tdep
->i386_intx80_record
= i386_linux_intx80_sysenter_syscall_record
;
971 tdep
->i386_sysenter_record
= i386_linux_intx80_sysenter_syscall_record
;
972 tdep
->i386_syscall_record
= i386_linux_intx80_sysenter_syscall_record
;
974 /* N_FUN symbols in shared libraries have 0 for their values and need
976 set_gdbarch_sofun_address_maybe_missing (gdbarch
, 1);
978 /* GNU/Linux uses SVR4-style shared libraries. */
979 set_gdbarch_skip_trampoline_code (gdbarch
, find_solib_trampoline_target
);
980 set_solib_svr4_fetch_link_map_offsets
981 (gdbarch
, linux_ilp32_fetch_link_map_offsets
);
983 /* GNU/Linux uses the dynamic linker included in the GNU C Library. */
984 set_gdbarch_skip_solib_resolver (gdbarch
, glibc_skip_solib_resolver
);
986 dwarf2_frame_set_signal_frame_p (gdbarch
, i386_linux_dwarf_signal_frame_p
);
988 /* Enable TLS support. */
989 set_gdbarch_fetch_tls_load_module_address (gdbarch
,
990 svr4_fetch_objfile_link_map
);
992 /* Core file support. */
993 set_gdbarch_iterate_over_regset_sections
994 (gdbarch
, i386_linux_iterate_over_regset_sections
);
995 set_gdbarch_core_read_description (gdbarch
,
996 i386_linux_core_read_description
);
998 /* Displaced stepping. */
999 set_gdbarch_displaced_step_copy_insn (gdbarch
,
1000 i386_linux_displaced_step_copy_insn
);
1001 set_gdbarch_displaced_step_fixup (gdbarch
, i386_displaced_step_fixup
);
1003 /* Functions for 'catch syscall'. */
1004 set_xml_syscall_file_name (gdbarch
, XML_SYSCALL_FILENAME_I386
);
1005 set_gdbarch_get_syscall_number (gdbarch
,
1006 i386_linux_get_syscall_number
);
1009 void _initialize_i386_linux_tdep ();
1011 _initialize_i386_linux_tdep ()
1013 gdbarch_register_osabi (bfd_arch_i386
, 0, GDB_OSABI_LINUX
,
1014 i386_linux_init_abi
);