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