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