i386-linux-tdep.c 36 KB

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