GDB (xrefs)
Loading...
Searching...
No Matches
i386-linux-tdep.c
Go to the documentation of this file.
1/* Target-dependent code for GNU/Linux i386.
2
3 Copyright (C) 2000-2023 Free Software Foundation, Inc.
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
9 the Free Software Foundation; either version 3 of the License, or
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
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
19
20#include "defs.h"
21#include "gdbcore.h"
22#include "frame.h"
23#include "value.h"
24#include "regcache.h"
25#include "regset.h"
26#include "inferior.h"
27#include "osabi.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"
33#include "utils.h"
34#include "glibc-tdep.h"
35#include "solib-svr4.h"
36#include "symtab.h"
37#include "arch-utils.h"
38#include "xml-syscall.h"
39#include "infrun.h"
40
41#include "i387-tdep.h"
42#include "gdbsupport/x86-xstate.h"
43
44/* The syscall's XML filename for i386. */
45#define XML_SYSCALL_FILENAME_I386 "syscalls/i386-linux.xml"
46
47#include "record-full.h"
48#include "linux-record.h"
49
50#include "arch/i386.h"
51#include "target-descriptions.h"
52
53/* Return non-zero, when the register is in the corresponding register
54 group. Put the LINUX_ORIG_EAX register in the system group. */
55static int
57 const struct reggroup *group)
58{
60 return (group == system_reggroup
61 || group == save_reggroup
62 || group == restore_reggroup);
64}
65
66
67/* Recognizing signal handler frames. */
68
69/* GNU/Linux has two flavors of signals. Normal signal handlers, and
70 "realtime" (RT) signals. The RT signals can provide additional
71 information to the signal handler if the SA_SIGINFO flag is set
72 when establishing a signal handler using `sigaction'. It is not
73 unlikely that future versions of GNU/Linux will support SA_SIGINFO
74 for normal signals too. */
75
76/* When the i386 Linux kernel calls a signal handler and the
77 SA_RESTORER flag isn't set, the return address points to a bit of
78 code on the stack. This function returns whether the PC appears to
79 be within this bit of code.
80
81 The instruction sequence for normal signals is
82 pop %eax
83 mov $0x77, %eax
84 int $0x80
85 or 0x58 0xb8 0x77 0x00 0x00 0x00 0xcd 0x80.
86
87 Checking for the code sequence should be somewhat reliable, because
88 the effect is to call the system call sigreturn. This is unlikely
89 to occur anywhere other than in a signal trampoline.
90
91 It kind of sucks that we have to read memory from the process in
92 order to identify a signal trampoline, but there doesn't seem to be
93 any other way. Therefore we only do the memory reads if no
94 function name could be identified, which should be the case since
95 the code is on the stack.
96
97 Detection of signal trampolines for handlers that set the
98 SA_RESTORER flag is in general not possible. Unfortunately this is
99 what the GNU C Library has been doing for quite some time now.
100 However, as of version 2.1.2, the GNU C Library uses signal
101 trampolines (named __restore and __restore_rt) that are identical
102 to the ones used by the kernel. Therefore, these trampolines are
103 supported too. */
104
105#define LINUX_SIGTRAMP_INSN0 0x58 /* pop %eax */
106#define LINUX_SIGTRAMP_OFFSET0 0
107#define LINUX_SIGTRAMP_INSN1 0xb8 /* mov $NNNN, %eax */
108#define LINUX_SIGTRAMP_OFFSET1 1
109#define LINUX_SIGTRAMP_INSN2 0xcd /* int */
110#define LINUX_SIGTRAMP_OFFSET2 6
111
112static const gdb_byte linux_sigtramp_code[] =
113{
114 LINUX_SIGTRAMP_INSN0, /* pop %eax */
115 LINUX_SIGTRAMP_INSN1, 0x77, 0x00, 0x00, 0x00, /* mov $0x77, %eax */
116 LINUX_SIGTRAMP_INSN2, 0x80 /* int $0x80 */
117};
118
119#define LINUX_SIGTRAMP_LEN (sizeof linux_sigtramp_code)
120
121/* If THIS_FRAME is a sigtramp routine, return the address of the
122 start of the routine. Otherwise, return 0. */
123
124static CORE_ADDR
126{
127 CORE_ADDR pc = get_frame_pc (this_frame);
128 gdb_byte buf[LINUX_SIGTRAMP_LEN];
129
130 /* We only recognize a signal trampoline if PC is at the start of
131 one of the three instructions. We optimize for finding the PC at
132 the start, as will be the case when the trampoline is not the
133 first frame on the stack. We assume that in the case where the
134 PC is not at the start of the instruction sequence, there will be
135 a few trailing readable bytes on the stack. */
136
137 if (!safe_frame_unwind_memory (this_frame, pc, buf))
138 return 0;
139
140 if (buf[0] != LINUX_SIGTRAMP_INSN0)
141 {
142 int adjust;
143
144 switch (buf[0])
145 {
147 adjust = LINUX_SIGTRAMP_OFFSET1;
148 break;
150 adjust = LINUX_SIGTRAMP_OFFSET2;
151 break;
152 default:
153 return 0;
154 }
155
156 pc -= adjust;
157
158 if (!safe_frame_unwind_memory (this_frame, pc, buf))
159 return 0;
160 }
161
162 if (memcmp (buf, linux_sigtramp_code, LINUX_SIGTRAMP_LEN) != 0)
163 return 0;
164
165 return pc;
166}
167
168/* This function does the same for RT signals. Here the instruction
169 sequence is
170 mov $0xad, %eax
171 int $0x80
172 or 0xb8 0xad 0x00 0x00 0x00 0xcd 0x80.
173
174 The effect is to call the system call rt_sigreturn. */
175
176#define LINUX_RT_SIGTRAMP_INSN0 0xb8 /* mov $NNNN, %eax */
177#define LINUX_RT_SIGTRAMP_OFFSET0 0
178#define LINUX_RT_SIGTRAMP_INSN1 0xcd /* int */
179#define LINUX_RT_SIGTRAMP_OFFSET1 5
180
181static const gdb_byte linux_rt_sigtramp_code[] =
182{
183 LINUX_RT_SIGTRAMP_INSN0, 0xad, 0x00, 0x00, 0x00, /* mov $0xad, %eax */
184 LINUX_RT_SIGTRAMP_INSN1, 0x80 /* int $0x80 */
185};
186
187#define LINUX_RT_SIGTRAMP_LEN (sizeof linux_rt_sigtramp_code)
188
189/* If THIS_FRAME is an RT sigtramp routine, return the address of the
190 start of the routine. Otherwise, return 0. */
191
192static CORE_ADDR
194{
195 CORE_ADDR pc = get_frame_pc (this_frame);
196 gdb_byte buf[LINUX_RT_SIGTRAMP_LEN];
197
198 /* We only recognize a signal trampoline if PC is at the start of
199 one of the two instructions. We optimize for finding the PC at
200 the start, as will be the case when the trampoline is not the
201 first frame on the stack. We assume that in the case where the
202 PC is not at the start of the instruction sequence, there will be
203 a few trailing readable bytes on the stack. */
204
205 if (!safe_frame_unwind_memory (this_frame, pc, buf))
206 return 0;
207
208 if (buf[0] != LINUX_RT_SIGTRAMP_INSN0)
209 {
210 if (buf[0] != LINUX_RT_SIGTRAMP_INSN1)
211 return 0;
212
214
215 if (!safe_frame_unwind_memory (this_frame, pc,
216 buf))
217 return 0;
218 }
219
220 if (memcmp (buf, linux_rt_sigtramp_code, LINUX_RT_SIGTRAMP_LEN) != 0)
221 return 0;
222
223 return pc;
224}
225
226/* Return whether THIS_FRAME corresponds to a GNU/Linux sigtramp
227 routine. */
228
229static int
231{
232 CORE_ADDR pc = get_frame_pc (this_frame);
233 const char *name;
234
235 find_pc_partial_function (pc, &name, NULL, NULL);
236
237 /* If we have NAME, we can optimize the search. The trampolines are
238 named __restore and __restore_rt. However, they aren't dynamically
239 exported from the shared C library, so the trampoline may appear to
240 be part of the preceding function. This should always be sigaction,
241 __sigaction, or __libc_sigaction (all aliases to the same function). */
242 if (name == NULL || strstr (name, "sigaction") != NULL)
243 return (i386_linux_sigtramp_start (this_frame) != 0
244 || i386_linux_rt_sigtramp_start (this_frame) != 0);
245
246 return (strcmp ("__restore", name) == 0
247 || strcmp ("__restore_rt", name) == 0);
248}
249
250/* Return one if the PC of THIS_FRAME is in a signal trampoline which
251 may have DWARF-2 CFI. */
252
253static int
255 frame_info_ptr this_frame)
256{
257 CORE_ADDR pc = get_frame_pc (this_frame);
258 const char *name;
259
260 find_pc_partial_function (pc, &name, NULL, NULL);
261
262 /* If a vsyscall DSO is in use, the signal trampolines may have these
263 names. */
264 if (name && (strcmp (name, "__kernel_sigreturn") == 0
265 || strcmp (name, "__kernel_rt_sigreturn") == 0))
266 return 1;
267
268 return 0;
269}
270
271/* Offset to struct sigcontext in ucontext, from <asm/ucontext.h>. */
272#define I386_LINUX_UCONTEXT_SIGCONTEXT_OFFSET 20
273
274/* Assuming THIS_FRAME is a GNU/Linux sigtramp routine, return the
275 address of the associated sigcontext structure. */
276
277static CORE_ADDR
279{
280 struct gdbarch *gdbarch = get_frame_arch (this_frame);
281 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
282 CORE_ADDR pc;
283 CORE_ADDR sp;
284 gdb_byte buf[4];
285
286 get_frame_register (this_frame, I386_ESP_REGNUM, buf);
287 sp = extract_unsigned_integer (buf, 4, byte_order);
288
289 pc = i386_linux_sigtramp_start (this_frame);
290 if (pc)
291 {
292 /* The sigcontext structure lives on the stack, right after
293 the signum argument. We determine the address of the
294 sigcontext structure by looking at the frame's stack
295 pointer. Keep in mind that the first instruction of the
296 sigtramp code is "pop %eax". If the PC is after this
297 instruction, adjust the returned value accordingly. */
298 if (pc == get_frame_pc (this_frame))
299 return sp + 4;
300 return sp;
301 }
302
303 pc = i386_linux_rt_sigtramp_start (this_frame);
304 if (pc)
305 {
306 CORE_ADDR ucontext_addr;
307
308 /* The sigcontext structure is part of the user context. A
309 pointer to the user context is passed as the third argument
310 to the signal handler. */
311 read_memory (sp + 8, buf, 4);
312 ucontext_addr = extract_unsigned_integer (buf, 4, byte_order);
313 return ucontext_addr + I386_LINUX_UCONTEXT_SIGCONTEXT_OFFSET;
314 }
315
316 error (_("Couldn't recognize signal trampoline."));
317 return 0;
318}
319
320/* Set the program counter for process PTID to PC. */
321
322static void
323i386_linux_write_pc (struct regcache *regcache, CORE_ADDR pc)
324{
326
327 /* We must be careful with modifying the program counter. If we
328 just interrupted a system call, the kernel might try to restart
329 it when we resume the inferior. On restarting the system call,
330 the kernel will try backing up the program counter even though it
331 no longer points at the system call. This typically results in a
332 SIGSEGV or SIGILL. We can prevent this by writing `-1' in the
333 "orig_eax" pseudo-register.
334
335 Note that "orig_eax" is saved when setting up a dummy call frame.
336 This means that it is properly restored when that frame is
337 popped, and that the interrupted system call will be restarted
338 when we resume the inferior on return from a function call from
339 within GDB. In all other cases the system call will not be
340 restarted. */
342}
343
344/* Record all registers but IP register for process-record. */
345
346static int
370
371/* i386_canonicalize_syscall maps from the native i386 Linux set
372 of syscall ids into a canonical set of syscall ids used by
373 process record (a mostly trivial mapping, since the canonical
374 set was originally taken from the i386 set). */
375
376static enum gdb_syscall
378{
379 enum { i386_syscall_max = 499 };
380
381 if (syscall <= i386_syscall_max)
382 return (enum gdb_syscall) syscall;
383 else
384 return gdb_sys_no_syscall;
385}
386
387/* Value of the sigcode in case of a boundary fault. */
388
389#define SIG_CODE_BOUNDARY_FAULT 3
390
391/* i386 GNU/Linux implementation of the report_signal_info
392 gdbarch hook. Displays information related to MPX bound
393 violations. */
394void
396 enum gdb_signal siggnal)
397{
398 /* -Wmaybe-uninitialized */
399 CORE_ADDR lower_bound = 0, upper_bound = 0, access = 0;
400 int is_upper;
401 long sig_code = 0;
402
403 if (!i386_mpx_enabled () || siggnal != GDB_SIGNAL_SEGV)
404 return;
405
406 try
407 {
408 /* Sigcode evaluates if the actual segfault is a boundary violation. */
409 sig_code = parse_and_eval_long ("$_siginfo.si_code\n");
410
411 lower_bound
412 = parse_and_eval_long ("$_siginfo._sifields._sigfault._addr_bnd._lower");
413 upper_bound
414 = parse_and_eval_long ("$_siginfo._sifields._sigfault._addr_bnd._upper");
415 access
416 = parse_and_eval_long ("$_siginfo._sifields._sigfault.si_addr");
417 }
418 catch (const gdb_exception_error &exception)
419 {
420 return;
421 }
422
423 /* If this is not a boundary violation just return. */
424 if (sig_code != SIG_CODE_BOUNDARY_FAULT)
425 return;
426
427 is_upper = (access > upper_bound ? 1 : 0);
428
429 uiout->text ("\n");
430 if (is_upper)
431 uiout->field_string ("sigcode-meaning", _("Upper bound violation"));
432 else
433 uiout->field_string ("sigcode-meaning", _("Lower bound violation"));
434
435 uiout->text (_(" while accessing address "));
436 uiout->field_core_addr ("bound-access", gdbarch, access);
437
438 uiout->text (_("\nBounds: [lower = "));
439 uiout->field_core_addr ("lower-bound", gdbarch, lower_bound);
440
441 uiout->text (_(", upper = "));
442 uiout->field_core_addr ("upper-bound", gdbarch, upper_bound);
443
444 uiout->text (_("]"));
445}
446
447/* Parse the arguments of current system call instruction and record
448 the values of the registers and memory that will be changed into
449 "record_arch_list". This instruction is "int 0x80" (Linux
450 Kernel2.4) or "sysenter" (Linux Kernel 2.6).
451
452 Return -1 if something wrong. */
453
455
456static int
458{
459 int ret;
460 LONGEST syscall_native;
461 enum gdb_syscall syscall_gdb;
462
464
465 syscall_gdb = i386_canonicalize_syscall (syscall_native);
466
467 if (syscall_gdb < 0)
468 {
470 _("Process record and replay target doesn't "
471 "support syscall number %s\n"),
472 plongest (syscall_native));
473 return -1;
474 }
475
476 if (syscall_gdb == gdb_sys_sigreturn
477 || syscall_gdb == gdb_sys_rt_sigreturn)
478 {
480 return -1;
481 return 0;
482 }
483
484 ret = record_linux_system_call (syscall_gdb, regcache,
486 if (ret)
487 return ret;
488
489 /* Record the return value of the system call. */
491 return -1;
492
493 return 0;
494}
495
496#define I386_LINUX_xstate 270
497#define I386_LINUX_frame_size 732
498
499static int
501 struct regcache *regcache,
502 enum gdb_signal signal)
503{
504 ULONGEST esp;
505
507 return -1;
508
510 return -1;
511
512 /* Record the change in the stack. */
514 /* This is for xstate.
515 sp -= sizeof (struct _fpstate); */
516 esp -= I386_LINUX_xstate;
517 /* This is for frame_size.
518 sp -= sizeof (struct rt_sigframe); */
522 return -1;
523
525 return -1;
526
527 return 0;
528}
529
530
531/* Core of the implementation for gdbarch get_syscall_number. Get pending
532 syscall number from REGCACHE. If there is no pending syscall -1 will be
533 returned. Pending syscall means ptrace has stepped into the syscall but
534 another ptrace call will step out. PC is right after the int $0x80
535 / syscall / sysenter instruction in both cases, PC does not change during
536 the second ptrace step. */
537
538static LONGEST
540{
541 struct gdbarch *gdbarch = regcache->arch ();
542 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
543 /* The content of a register. */
544 gdb_byte buf[4];
545 /* The result. */
546 LONGEST ret;
547
548 /* Getting the system call number from the register.
549 When dealing with x86 architecture, this information
550 is stored at %eax register. */
552
553 ret = extract_signed_integer (buf, byte_order);
554
555 return ret;
556}
557
558/* Wrapper for i386_linux_get_syscall_number_from_regcache to make it
559 compatible with gdbarch get_syscall_number method prototype. */
560
561static LONGEST
569
570/* The register sets used in GNU/Linux ELF core-dumps are identical to
571 the register sets in `struct user' that are used for a.out
572 core-dumps. These are also used by ptrace(2). The corresponding
573 types are `elf_gregset_t' for the general-purpose registers (with
574 `elf_greg_t' the type of a single GP register) and `elf_fpregset_t'
575 for the floating-point registers.
576
577 Those types used to be available under the names `gregset_t' and
578 `fpregset_t' too, and GDB used those names in the past. But those
579 names are now used for the register sets used in the `mcontext_t'
580 type, which have a different size and layout. */
581
582/* Mapping between the general-purpose registers in `struct user'
583 format and GDB's register cache layout. */
584
585/* From <sys/reg.h>. */
587{
588 6 * 4, /* %eax */
589 1 * 4, /* %ecx */
590 2 * 4, /* %edx */
591 0 * 4, /* %ebx */
592 15 * 4, /* %esp */
593 5 * 4, /* %ebp */
594 3 * 4, /* %esi */
595 4 * 4, /* %edi */
596 12 * 4, /* %eip */
597 14 * 4, /* %eflags */
598 13 * 4, /* %cs */
599 16 * 4, /* %ss */
600 7 * 4, /* %ds */
601 8 * 4, /* %es */
602 9 * 4, /* %fs */
603 10 * 4, /* %gs */
604 -1, -1, -1, -1, -1, -1, -1, -1,
605 -1, -1, -1, -1, -1, -1, -1, -1,
606 -1, -1, -1, -1, -1, -1, -1, -1,
607 -1,
608 -1, -1, -1, -1, -1, -1, -1, -1,
609 -1, -1, -1, -1, /* MPX registers BND0 ... BND3. */
610 -1, -1, /* MPX registers BNDCFGU, BNDSTATUS. */
611 -1, -1, -1, -1, -1, -1, -1, -1, /* k0 ... k7 (AVX512) */
612 -1, -1, -1, -1, -1, -1, -1, -1, /* zmm0 ... zmm7 (AVX512) */
613 -1, /* PKRU register */
614 11 * 4, /* "orig_eax" */
615};
616
617/* Mapping between the general-purpose registers in `struct
618 sigcontext' format and GDB's register cache layout. */
619
620/* From <asm/sigcontext.h>. */
622{
623 11 * 4, /* %eax */
624 10 * 4, /* %ecx */
625 9 * 4, /* %edx */
626 8 * 4, /* %ebx */
627 7 * 4, /* %esp */
628 6 * 4, /* %ebp */
629 5 * 4, /* %esi */
630 4 * 4, /* %edi */
631 14 * 4, /* %eip */
632 16 * 4, /* %eflags */
633 15 * 4, /* %cs */
634 18 * 4, /* %ss */
635 3 * 4, /* %ds */
636 2 * 4, /* %es */
637 1 * 4, /* %fs */
638 0 * 4 /* %gs */
639};
640
641/* See i386-linux-tdep.h. */
642
643uint64_t
644i386_linux_core_read_xsave_info (bfd *abfd, x86_xsave_layout &layout)
645{
646 asection *xstate = bfd_get_section_by_name (abfd, ".reg-xstate");
647 if (xstate == nullptr)
648 return 0;
649
650 /* Check extended state size. */
651 size_t size = bfd_section_size (xstate);
652 if (size < X86_XSTATE_AVX_SIZE)
653 return 0;
654
655 char contents[8];
656 if (! bfd_get_section_contents (abfd, xstate, contents,
658 {
659 warning (_("Couldn't read `xcr0' bytes from "
660 "`.reg-xstate' section in core file."));
661 return 0;
662 }
663
664 uint64_t xcr0 = bfd_get_64 (abfd, contents);
665
666 if (!i387_guess_xsave_layout (xcr0, size, layout))
667 return 0;
668
669 return xcr0;
670}
671
672/* See i386-linux-tdep.h. */
673
674bool
676 x86_xsave_layout &layout)
677{
678 return i386_linux_core_read_xsave_info (core_bfd, layout) != 0;
679}
680
681/* See i386-linux-tdep.h. */
682
683const struct target_desc *
685{
686 if (xcr0 == 0)
687 return NULL;
688
689 static struct target_desc *i386_linux_tdescs \
690 [2/*X87*/][2/*SSE*/][2/*AVX*/][2/*MPX*/][2/*AVX512*/][2/*PKRU*/] = {};
691 struct target_desc **tdesc;
692
693 tdesc = &i386_linux_tdescs[(xcr0 & X86_XSTATE_X87) ? 1 : 0]
694 [(xcr0 & X86_XSTATE_SSE) ? 1 : 0]
695 [(xcr0 & X86_XSTATE_AVX) ? 1 : 0]
696 [(xcr0 & X86_XSTATE_MPX) ? 1 : 0]
697 [(xcr0 & X86_XSTATE_AVX512) ? 1 : 0]
698 [(xcr0 & X86_XSTATE_PKRU) ? 1 : 0];
699
700 if (*tdesc == NULL)
701 *tdesc = i386_create_target_description (xcr0, true, false);
702
703 return *tdesc;
704}
705
706/* Get Linux/x86 target description from core dump. */
707
708static const struct target_desc *
710 struct target_ops *target,
711 bfd *abfd)
712{
713 /* Linux/i386. */
714 x86_xsave_layout layout;
715 uint64_t xcr0 = i386_linux_core_read_xsave_info (abfd, layout);
716 const struct target_desc *tdesc = i386_linux_read_description (xcr0);
717
718 if (tdesc != NULL)
719 return tdesc;
720
721 if (bfd_get_section_by_name (abfd, ".reg-xfp") != NULL)
722 return i386_linux_read_description (X86_XSTATE_SSE_MASK);
723 else
724 return i386_linux_read_description (X86_XSTATE_X87_MASK);
725}
726
727/* Similar to i386_supply_fpregset, but use XSAVE extended state. */
728
729static void
731 struct regcache *regcache, int regnum,
732 const void *xstateregs, size_t len)
733{
734 i387_supply_xsave (regcache, regnum, xstateregs);
735}
736
737struct type *
742
743/* Similar to i386_collect_fpregset, but use XSAVE extended state. */
744
745static void
747 const struct regcache *regcache,
748 int regnum, void *xstateregs, size_t len)
749{
750 i387_collect_xsave (regcache, regnum, xstateregs, 1);
751}
752
753/* Register set definitions. */
754
761
762/* Iterate over core file register note sections. */
763
764static void
767 void *cb_data,
768 const struct regcache *regcache)
769{
770 i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
771
772 cb (".reg", 68, 68, &i386_gregset, NULL, cb_data);
773
774 if (tdep->xsave_layout.sizeof_xsave != 0)
775 cb (".reg-xstate", tdep->xsave_layout.sizeof_xsave,
776 tdep->xsave_layout.sizeof_xsave, &i386_linux_xstateregset,
777 "XSAVE extended state", cb_data);
778 else if (tdep->xcr0 & X86_XSTATE_SSE)
779 cb (".reg-xfp", 512, 512, &i386_fpregset, "extended floating-point",
780 cb_data);
781 else
782 cb (".reg2", 108, 108, &i386_fpregset, NULL, cb_data);
783}
784
785/* Linux kernel shows PC value after the 'int $0x80' instruction even if
786 inferior is still inside the syscall. On next PTRACE_SINGLESTEP it will
787 finish the syscall but PC will not change.
788
789 Some vDSOs contain 'int $0x80; ret' and during stepping out of the syscall
790 i386_displaced_step_fixup would keep PC at the displaced pad location.
791 As PC is pointing to the 'ret' instruction before the step
792 i386_displaced_step_fixup would expect inferior has just executed that 'ret'
793 and PC should not be adjusted. In reality it finished syscall instead and
794 PC should get relocated back to its vDSO address. Hide the 'ret'
795 instruction by 'nop' so that i386_displaced_step_fixup is not confused.
796
797 It is not fully correct as the bytes in struct
798 displaced_step_copy_insn_closure will not match the inferior code. But we
799 would need some new flag in displaced_step_copy_insn_closure otherwise to
800 keep the state that syscall is finishing for the later
801 i386_displaced_step_fixup execution as the syscall execution is already no
802 longer detectable there. The new flag field would mean i386-linux-tdep.c
803 needs to wrap all the displacement methods of i386-tdep.c which does not seem
804 worth it. The same effect is achieved by patching that 'nop' instruction
805 there instead. */
806
809 CORE_ADDR from, CORE_ADDR to,
810 struct regcache *regs)
811{
813 = i386_displaced_step_copy_insn (gdbarch, from, to, regs);
814
816 {
817 /* The closure returned by i386_displaced_step_copy_insn is simply a
818 buffer with a copy of the instruction. */
820 = (i386_displaced_step_copy_insn_closure *) closure_.get ();
821
822 /* Fake nop. */
823 closure->buf[0] = 0x90;
824 }
825
826 return closure_;
827}
828
829static void
831{
832 i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
833 const struct target_desc *tdesc = info.target_desc;
834 struct tdesc_arch_data *tdesc_data = info.tdesc_data;
835 const struct tdesc_feature *feature;
836 int valid_p;
837
838 gdb_assert (tdesc_data);
839
840 linux_init_abi (info, gdbarch, 1);
841
842 /* GNU/Linux uses ELF. */
844
845 /* Reserve a number for orig_eax. */
847
848 if (! tdesc_has_registers (tdesc))
849 tdesc = i386_linux_read_description (X86_XSTATE_SSE_MASK);
850 tdep->tdesc = tdesc;
851
852 feature = tdesc_find_feature (tdesc, "org.gnu.gdb.i386.linux");
853 if (feature == NULL)
854 return;
855
856 valid_p = tdesc_numbered_register (feature, tdesc_data,
858 "orig_eax");
859 if (!valid_p)
860 return;
861
862 /* Add the %orig_eax register used for syscall restarting. */
864
866
869 tdep->sizeof_gregset = 17 * 4;
870
871 tdep->jb_pc_offset = 20; /* From <bits/setjmp.h>. */
872
876 tdep->sc_num_regs = ARRAY_SIZE (i386_linux_sc_reg_offset);
877
881
884
885 /* Initialize the i386_linux_record_tdep. */
886 /* These values are the size of the type that will be used in a system
887 call. They are obtained from Linux Kernel source. */
889 = gdbarch_ptr_bit (gdbarch) / TARGET_CHAR_BIT;
910 = gdbarch_int_bit (gdbarch) / TARGET_CHAR_BIT;
912 = gdbarch_long_bit (gdbarch) / TARGET_CHAR_BIT;
914 = gdbarch_long_bit (gdbarch) / TARGET_CHAR_BIT;
960
961 /* These values are the second argument of system call "sys_ioctl".
962 They are obtained from Linux Kernel source. */
1028
1029 /* These values are the second argument of system call "sys_fcntl"
1030 and "sys_fcntl64". They are obtained from Linux Kernel source. */
1035
1042
1046
1047 /* N_FUN symbols in shared libraries have 0 for their values and need
1048 to be relocated. */
1050
1051 /* GNU/Linux uses SVR4-style shared libraries. */
1055
1056 /* GNU/Linux uses the dynamic linker included in the GNU C Library. */
1058
1060
1061 /* Enable TLS support. */
1064
1065 /* Core file support. */
1070
1071 /* Displaced stepping. */
1075
1076 /* Functions for 'catch syscall'. */
1080
1083}
1084
1086void
int regnum
const char *const name
bool find_pc_partial_function(CORE_ADDR pc, const char **name, CORE_ADDR *address, CORE_ADDR *endaddr, const struct block **block)
Definition blockframe.c:373
enum register_status cooked_read(int regnum, gdb_byte *buf)
Definition regcache.c:698
gdbarch * arch() const
Definition regcache.c:231
void field_core_addr(const char *fldname, struct gdbarch *gdbarch, CORE_ADDR address)
Definition ui-out.c:478
void field_string(const char *fldname, const char *string, const ui_file_style &style=ui_file_style())
Definition ui-out.c:511
void text(const char *string)
Definition ui-out.c:566
void read_memory(CORE_ADDR memaddr, gdb_byte *myaddr, ssize_t len)
Definition corefile.c:238
static LONGEST extract_signed_integer(gdb::array_view< const gdb_byte > buf, enum bfd_endian byte_order)
Definition defs.h:465
static ULONGEST extract_unsigned_integer(gdb::array_view< const gdb_byte > buf, enum bfd_endian byte_order)
Definition defs.h:480
std::unique_ptr< displaced_step_copy_insn_closure > displaced_step_copy_insn_closure_up
void dwarf2_frame_set_signal_frame_p(struct gdbarch *gdbarch, int(*signal_frame_p)(struct gdbarch *, frame_info_ptr))
Definition frame.c:692
LONGEST parse_and_eval_long(const char *exp)
Definition eval.c:62
CORE_ADDR get_frame_pc(frame_info_ptr frame)
Definition frame.c:2712
void get_frame_register(frame_info_ptr frame, int regnum, gdb_byte *buf)
Definition frame.c:1263
struct gdbarch * get_frame_arch(frame_info_ptr this_frame)
Definition frame.c:3027
bool safe_frame_unwind_memory(frame_info_ptr this_frame, CORE_ADDR addr, gdb::array_view< gdb_byte > buffer)
Definition frame.c:3017
void set_gdbarch_process_record(struct gdbarch *gdbarch, gdbarch_process_record_ftype *process_record)
enum bfd_endian gdbarch_byte_order(struct gdbarch *gdbarch)
Definition gdbarch.c:1396
void set_gdbarch_sofun_address_maybe_missing(struct gdbarch *gdbarch, int sofun_address_maybe_missing)
Definition gdbarch.c:4341
void set_gdbarch_core_read_description(struct gdbarch *gdbarch, gdbarch_core_read_description_ftype *core_read_description)
void set_gdbarch_write_pc(struct gdbarch *gdbarch, gdbarch_write_pc_ftype *write_pc)
void set_gdbarch_skip_trampoline_code(struct gdbarch *gdbarch, gdbarch_skip_trampoline_code_ftype *skip_trampoline_code)
void set_gdbarch_get_syscall_number(struct gdbarch *gdbarch, gdbarch_get_syscall_number_ftype *get_syscall_number)
void set_gdbarch_get_siginfo_type(struct gdbarch *gdbarch, gdbarch_get_siginfo_type_ftype *get_siginfo_type)
int gdbarch_int_bit(struct gdbarch *gdbarch)
Definition gdbarch.c:1449
void set_gdbarch_displaced_step_copy_insn(struct gdbarch *gdbarch, gdbarch_displaced_step_copy_insn_ftype *displaced_step_copy_insn)
void set_gdbarch_core_read_x86_xsave_layout(struct gdbarch *gdbarch, gdbarch_core_read_x86_xsave_layout_ftype *core_read_x86_xsave_layout)
void set_gdbarch_displaced_step_fixup(struct gdbarch *gdbarch, gdbarch_displaced_step_fixup_ftype *displaced_step_fixup)
void set_gdbarch_report_signal_info(struct gdbarch *gdbarch, gdbarch_report_signal_info_ftype *report_signal_info)
void set_gdbarch_process_record_signal(struct gdbarch *gdbarch, gdbarch_process_record_signal_ftype *process_record_signal)
void set_gdbarch_fetch_tls_load_module_address(struct gdbarch *gdbarch, gdbarch_fetch_tls_load_module_address_ftype *fetch_tls_load_module_address)
void set_gdbarch_num_regs(struct gdbarch *gdbarch, int num_regs)
Definition gdbarch.c:1941
int gdbarch_long_bit(struct gdbarch *gdbarch)
Definition gdbarch.c:1466
int gdbarch_ptr_bit(struct gdbarch *gdbarch)
Definition gdbarch.c:1722
void set_gdbarch_skip_solib_resolver(struct gdbarch *gdbarch, gdbarch_skip_solib_resolver_ftype *skip_solib_resolver)
void set_gdbarch_iterate_over_regset_sections(struct gdbarch *gdbarch, gdbarch_iterate_over_regset_sections_ftype *iterate_over_regset_sections)
void iterate_over_regset_sections_cb(const char *sect_name, int supply_size, int collect_size, const struct regset *regset, const char *human_name, void *cb_data)
Definition gdbarch.h:104
#define core_bfd
Definition gdbcore.h:130
CORE_ADDR glibc_skip_solib_resolver(struct gdbarch *gdbarch, CORE_ADDR pc)
Definition glibc-tdep.c:38
size_t size
Definition go32-nat.c:239
static int i386_linux_record_signal(struct gdbarch *gdbarch, struct regcache *regcache, enum gdb_signal signal)
#define LINUX_SIGTRAMP_INSN1
struct type * x86_linux_get_siginfo_type(struct gdbarch *gdbarch)
#define LINUX_SIGTRAMP_LEN
static LONGEST i386_linux_get_syscall_number(struct gdbarch *gdbarch, thread_info *thread)
int i386_linux_gregset_reg_offset[]
static int i386_linux_sc_reg_offset[]
static int i386_linux_register_reggroup_p(struct gdbarch *gdbarch, int regnum, const struct reggroup *group)
#define I386_LINUX_UCONTEXT_SIGCONTEXT_OFFSET
static enum gdb_syscall i386_canonicalize_syscall(int syscall)
static void i386_linux_collect_xstateregset(const struct regset *regset, const struct regcache *regcache, int regnum, void *xstateregs, size_t len)
static const gdb_byte linux_sigtramp_code[]
static const gdb_byte linux_rt_sigtramp_code[]
void _initialize_i386_linux_tdep()
#define LINUX_SIGTRAMP_INSN0
#define XML_SYSCALL_FILENAME_I386
bool i386_linux_core_read_x86_xsave_layout(struct gdbarch *gdbarch, x86_xsave_layout &layout)
static LONGEST i386_linux_get_syscall_number_from_regcache(struct regcache *regcache)
static const struct target_desc * i386_linux_core_read_description(struct gdbarch *gdbarch, struct target_ops *target, bfd *abfd)
static void i386_linux_supply_xstateregset(const struct regset *regset, struct regcache *regcache, int regnum, const void *xstateregs, size_t len)
static void i386_linux_init_abi(struct gdbarch_info info, struct gdbarch *gdbarch)
static int i386_linux_dwarf_signal_frame_p(struct gdbarch *gdbarch, frame_info_ptr this_frame)
#define I386_LINUX_frame_size
static CORE_ADDR i386_linux_sigtramp_start(frame_info_ptr this_frame)
static displaced_step_copy_insn_closure_up i386_linux_displaced_step_copy_insn(struct gdbarch *gdbarch, CORE_ADDR from, CORE_ADDR to, struct regcache *regs)
uint64_t i386_linux_core_read_xsave_info(bfd *abfd, x86_xsave_layout &layout)
static CORE_ADDR i386_linux_rt_sigtramp_start(frame_info_ptr this_frame)
static struct linux_record_tdep i386_linux_record_tdep
static int i386_all_but_ip_registers_record(struct regcache *regcache)
const struct target_desc * i386_linux_read_description(uint64_t xcr0)
#define LINUX_RT_SIGTRAMP_OFFSET1
#define I386_LINUX_xstate
#define LINUX_RT_SIGTRAMP_INSN0
#define LINUX_RT_SIGTRAMP_INSN1
#define LINUX_RT_SIGTRAMP_LEN
static int i386_linux_sigtramp_p(frame_info_ptr this_frame)
#define LINUX_SIGTRAMP_INSN2
static void i386_linux_write_pc(struct regcache *regcache, CORE_ADDR pc)
#define LINUX_SIGTRAMP_OFFSET1
static const struct regset i386_linux_xstateregset
#define SIG_CODE_BOUNDARY_FAULT
static void i386_linux_iterate_over_regset_sections(struct gdbarch *gdbarch, iterate_over_regset_sections_cb *cb, void *cb_data, const struct regcache *regcache)
static int i386_linux_intx80_sysenter_syscall_record(struct regcache *regcache)
void i386_linux_report_signal_info(struct gdbarch *gdbarch, struct ui_out *uiout, enum gdb_signal siggnal)
static CORE_ADDR i386_linux_sigcontext_addr(frame_info_ptr this_frame)
#define LINUX_SIGTRAMP_OFFSET2
#define I386_LINUX_NUM_REGS
#define I386_LINUX_XSAVE_XCR0_OFFSET
#define I386_LINUX_ORIG_EAX_REGNUM
int i386_register_reggroup_p(struct gdbarch *gdbarch, int regnum, const struct reggroup *group)
Definition i386-tdep.c:4604
const struct regset i386_fpregset
Definition i386-tdep.c:4047
int i386_process_record(struct gdbarch *gdbarch, struct regcache *regcache, CORE_ADDR input_addr)
Definition i386-tdep.c:5112
const struct regset i386_gregset
Definition i386-tdep.c:4042
displaced_step_copy_insn_closure_up i386_displaced_step_copy_insn(struct gdbarch *gdbarch, CORE_ADDR from, CORE_ADDR to, struct regcache *regs)
Definition i386-tdep.c:806
void i386_displaced_step_fixup(struct gdbarch *gdbarch, struct displaced_step_copy_insn_closure *closure_, CORE_ADDR from, CORE_ADDR to, struct regcache *regs, bool completed_p)
Definition i386-tdep.c:843
void i386_elf_init_abi(struct gdbarch_info info, struct gdbarch *gdbarch)
Definition i386-tdep.c:4530
int i386_mpx_enabled(void)
Definition i386-tdep.c:9000
@ I386_EFLAGS_REGNUM
Definition i386-tdep.h:290
@ I386_ESI_REGNUM
Definition i386-tdep.h:287
@ I386_ECX_REGNUM
Definition i386-tdep.h:282
@ I386_EIP_REGNUM
Definition i386-tdep.h:289
@ I386_EBP_REGNUM
Definition i386-tdep.h:286
@ I386_EAX_REGNUM
Definition i386-tdep.h:281
@ I386_EDX_REGNUM
Definition i386-tdep.h:283
@ I386_ESP_REGNUM
Definition i386-tdep.h:285
@ I386_EBX_REGNUM
Definition i386-tdep.h:284
@ I386_EDI_REGNUM
Definition i386-tdep.h:288
target_desc * i386_create_target_description(uint64_t xcr0, bool is_linux, bool segments)
Definition i386.c:36
void i387_supply_xsave(struct regcache *regcache, int regnum, const void *xsave)
Definition i387-tdep.c:1061
bool i387_guess_xsave_layout(uint64_t xcr0, size_t xsave_size, x86_xsave_layout &layout)
Definition i387-tdep.c:938
void i387_collect_xsave(const struct regcache *regcache, int regnum, void *xsave, int gcore)
Definition i387-tdep.c:1508
int record_linux_system_call(enum gdb_syscall syscall, struct regcache *regcache, struct linux_record_tdep *tdep)
gdb_syscall
@ gdb_sys_sigreturn
@ gdb_sys_no_syscall
@ gdb_sys_rt_sigreturn
link_map_offsets * linux_ilp32_fetch_link_map_offsets()
void linux_init_abi(struct gdbarch_info info, struct gdbarch *gdbarch, int num_disp_step_buffers)
struct type * linux_get_siginfo_type_with_fields(struct gdbarch *gdbarch, linux_siginfo_extra_fields extra_fields)
Definition linux-tdep.c:272
@ LINUX_SIGINFO_FIELD_ADDR_BND
Definition linux-tdep.h:34
CORE_ADDR find_solib_trampoline_target(frame_info_ptr frame, CORE_ADDR pc)
Definition minsyms.c:1554
void gdbarch_register_osabi(enum bfd_architecture arch, unsigned long machine, enum gdb_osabi osabi, void(*init_osabi)(struct gdbarch_info, struct gdbarch *))
Definition osabi.c:146
@ GDB_OSABI_LINUX
Definition osabi.h:32
int record_full_arch_list_add_reg(struct regcache *regcache, int regnum)
int record_full_arch_list_add_mem(CORE_ADDR addr, int len)
int record_full_arch_list_add_end(void)
enum register_status regcache_raw_read_signed(struct regcache *regcache, int regnum, LONGEST *val)
Definition regcache.c:626
enum register_status regcache_raw_read_unsigned(struct regcache *regcache, int regnum, ULONGEST *val)
Definition regcache.c:649
struct regcache * get_thread_regcache(process_stratum_target *target, ptid_t ptid)
Definition regcache.c:400
void regcache_cooked_write_unsigned(struct regcache *regcache, int regnum, ULONGEST val)
Definition regcache.c:825
const reggroup *const system_reggroup
Definition reggroups.c:253
const reggroup *const save_reggroup
Definition reggroups.c:256
const reggroup *const restore_reggroup
Definition reggroups.c:257
void set_solib_svr4_fetch_link_map_offsets(struct gdbarch *gdbarch, struct link_map_offsets *(*flmo)(void))
CORE_ADDR svr4_fetch_objfile_link_map(struct objfile *objfile)
int * gregset_reg_offset
Definition i386-tdep.h:64
int(* i386_syscall_record)(struct regcache *regcache)
Definition i386-tdep.h:260
int(* i386_intx80_record)(struct regcache *regcache)
Definition i386-tdep.h:256
int(* sigtramp_p)(frame_info_ptr)
Definition i386-tdep.h:230
x86_xsave_layout xsave_layout
Definition i386-tdep.h:150
gdbarch_register_reggroup_p_ftype * register_reggroup_p
Definition i386-tdep.h:217
CORE_ADDR(* sigcontext_addr)(frame_info_ptr)
Definition i386-tdep.h:233
size_t sizeof_gregset
Definition i386-tdep.h:66
const struct target_desc * tdesc
Definition i386-tdep.h:214
int(* i386_sysenter_record)(struct regcache *regcache)
Definition i386-tdep.h:258
ULONGEST ioctl_TIOCGLCKTRMIOS
ULONGEST ioctl_TIOCMIWAIT
ULONGEST ioctl_TCGETA
ULONGEST ioctl_TIOCGICOUNT
ULONGEST ioctl_TIOCMBIC
ULONGEST ioctl_TIOCMBIS
ULONGEST ioctl_TCSETSW2
ULONGEST ioctl_TIOCSERGSTRUCT
ULONGEST ioctl_TIOCGPTN
ULONGEST ioctl_TIOCSERGETMULTI
ULONGEST ioctl_TIOCGSID
ULONGEST ioctl_FIOQSIZE
ULONGEST ioctl_TIOCSERCONFIG
ULONGEST ioctl_FIONCLEX
ULONGEST ioctl_TIOCSSOFTCAR
ULONGEST ioctl_TIOCSWINSZ
ULONGEST ioctl_TCSETSF
ULONGEST ioctl_TIOCLINUX
ULONGEST ioctl_TIOCTTYGSTRUCT
ULONGEST ioctl_TIOCSBRK
ULONGEST ioctl_TIOCGPGRP
ULONGEST ioctl_TIOCSERSETMULTI
ULONGEST ioctl_TCSETS
ULONGEST ioctl_TIOCSSERIAL
int size_serial_icounter_struct
ULONGEST ioctl_TIOCSPTLCK
ULONGEST ioctl_TIOCGETD
ULONGEST ioctl_FIONREAD
ULONGEST ioctl_TIOCCBRK
ULONGEST ioctl_TCGETS
ULONGEST ioctl_TIOCGSOFTCAR
ULONGEST ioctl_TIOCNOTTY
ULONGEST ioctl_TIOCSPGRP
ULONGEST ioctl_TIOCGSERIAL
ULONGEST ioctl_FIOASYNC
ULONGEST ioctl_TIOCSERGETLSR
ULONGEST ioctl_TIOCOUTQ
ULONGEST ioctl_TIOCMGET
ULONGEST ioctl_TIOCGWINSZ
ULONGEST ioctl_TIOCSERGWILD
ULONGEST ioctl_TIOCCONS
ULONGEST ioctl_TCSETSF2
ULONGEST ioctl_TIOCSCTTY
ULONGEST ioctl_TIOCSETD
ULONGEST ioctl_TIOCSLCKTRMIOS
ULONGEST ioctl_TIOCSHAYESESP
ULONGEST ioctl_TIOCGHAYESESP
ULONGEST ioctl_TIOCEXCL
ULONGEST ioctl_TIOCNXCL
ULONGEST ioctl_TCSETSW
ULONGEST ioctl_TIOCMSET
ULONGEST ioctl_TIOCSERSWILD
const struct tdesc_feature * tdesc_find_feature(const struct target_desc *target_desc, const char *name)
int tdesc_numbered_register(const struct tdesc_feature *feature, struct tdesc_arch_data *data, int regno, const char *name)
static const registry< gdbarch >::key< tdesc_arch_data > tdesc_data
int tdesc_has_registers(const struct target_desc *target_desc)
void gdb_printf(struct ui_file *stream, const char *format,...)
Definition utils.c:1886
#define gdb_stderr
Definition utils.h:187
void set_xml_syscall_file_name(struct gdbarch *gdbarch, const char *name)
Definition xml-syscall.c:50