gdb/i386-linux-nat.c - gdb

Global variables defined

Functions defined

Macros defined

Source code

  1. /* Native-dependent code for GNU/Linux i386.

  2.    Copyright (C) 1999-2015 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 "inferior.h"
  16. #include "gdbcore.h"
  17. #include "regcache.h"
  18. #include "elf/common.h"
  19. #include <sys/ptrace.h>
  20. #include <sys/uio.h>
  21. #include "gregset.h"
  22. #include "gdb_proc_service.h"

  23. #include "i386-linux-nat.h"
  24. #include "i387-tdep.h"
  25. #include "i386-tdep.h"
  26. #include "i386-linux-tdep.h"
  27. #include "x86-xstate.h"

  28. #include "x86-linux-nat.h"

  29. /* The register sets used in GNU/Linux ELF core-dumps are identical to
  30.    the register sets in `struct user' that is used for a.out
  31.    core-dumps, and is also used by `ptrace'.  The corresponding types
  32.    are `elf_gregset_t' for the general-purpose registers (with
  33.    `elf_greg_t' the type of a single GP register) and `elf_fpregset_t'
  34.    for the floating-point registers.

  35.    Those types used to be available under the names `gregset_t' and
  36.    `fpregset_t' too, and this file used those names in the past.  But
  37.    those names are now used for the register sets used in the
  38.    `mcontext_t' type, and have a different size and layout.  */

  39. /* Which ptrace request retrieves which registers?
  40.    These apply to the corresponding SET requests as well.  */

  41. #define GETREGS_SUPPLIES(regno) \
  42.   ((0 <= (regno) && (regno) <= 15) || (regno) == I386_LINUX_ORIG_EAX_REGNUM)

  43. #define GETFPXREGS_SUPPLIES(regno) \
  44.   (I386_ST0_REGNUM <= (regno) && (regno) < I386_SSE_NUM_REGS)

  45. #define GETXSTATEREGS_SUPPLIES(regno) \
  46.   (I386_ST0_REGNUM <= (regno) && (regno) < I386_AVX512_NUM_REGS)

  47. /* Does the current host support the GETREGS request?  */
  48. int have_ptrace_getregs =
  49. #ifdef HAVE_PTRACE_GETREGS
  50.   1
  51. #else
  52.   0
  53. #endif
  54. ;

  55. /* Does the current host support the GETFPXREGS request?  The header
  56.    file may or may not define it, and even if it is defined, the
  57.    kernel will return EIO if it's running on a pre-SSE processor.

  58.    My instinct is to attach this to some architecture- or
  59.    target-specific data structure, but really, a particular GDB
  60.    process can only run on top of one kernel at a time.  So it's okay
  61.    for this to be a simple variable.  */
  62. int have_ptrace_getfpxregs =
  63. #ifdef HAVE_PTRACE_GETFPXREGS
  64.   -1
  65. #else
  66.   0
  67. #endif
  68. ;


  69. /* Accessing registers through the U area, one at a time.  */

  70. /* Fetch one register.  */

  71. static void
  72. fetch_register (struct regcache *regcache, int regno)
  73. {
  74.   int tid;
  75.   int val;

  76.   gdb_assert (!have_ptrace_getregs);
  77.   if (i386_linux_gregset_reg_offset[regno] == -1)
  78.     {
  79.       regcache_raw_supply (regcache, regno, NULL);
  80.       return;
  81.     }

  82.   /* GNU/Linux LWP ID's are process ID's.  */
  83.   tid = ptid_get_lwp (inferior_ptid);
  84.   if (tid == 0)
  85.     tid = ptid_get_pid (inferior_ptid); /* Not a threaded program.  */

  86.   errno = 0;
  87.   val = ptrace (PTRACE_PEEKUSER, tid,
  88.                 i386_linux_gregset_reg_offset[regno], 0);
  89.   if (errno != 0)
  90.     error (_("Couldn't read register %s (#%d): %s."),
  91.            gdbarch_register_name (get_regcache_arch (regcache), regno),
  92.            regno, safe_strerror (errno));

  93.   regcache_raw_supply (regcache, regno, &val);
  94. }

  95. /* Store one register.  */

  96. static void
  97. store_register (const struct regcache *regcache, int regno)
  98. {
  99.   int tid;
  100.   int val;

  101.   gdb_assert (!have_ptrace_getregs);
  102.   if (i386_linux_gregset_reg_offset[regno] == -1)
  103.     return;

  104.   /* GNU/Linux LWP ID's are process ID's.  */
  105.   tid = ptid_get_lwp (inferior_ptid);
  106.   if (tid == 0)
  107.     tid = ptid_get_pid (inferior_ptid); /* Not a threaded program.  */

  108.   errno = 0;
  109.   regcache_raw_collect (regcache, regno, &val);
  110.   ptrace (PTRACE_POKEUSER, tid,
  111.           i386_linux_gregset_reg_offset[regno], val);
  112.   if (errno != 0)
  113.     error (_("Couldn't write register %s (#%d): %s."),
  114.            gdbarch_register_name (get_regcache_arch (regcache), regno),
  115.            regno, safe_strerror (errno));
  116. }


  117. /* Transfering the general-purpose registers between GDB, inferiors
  118.    and core files.  */

  119. /* Fill GDB's register array with the general-purpose register values
  120.    in *GREGSETP.  */

  121. void
  122. supply_gregset (struct regcache *regcache, const elf_gregset_t *gregsetp)
  123. {
  124.   const gdb_byte *regp = (const gdb_byte *) gregsetp;
  125.   int i;

  126.   for (i = 0; i < I386_NUM_GREGS; i++)
  127.     regcache_raw_supply (regcache, i,
  128.                          regp + i386_linux_gregset_reg_offset[i]);

  129.   if (I386_LINUX_ORIG_EAX_REGNUM
  130.         < gdbarch_num_regs (get_regcache_arch (regcache)))
  131.     regcache_raw_supply (regcache, I386_LINUX_ORIG_EAX_REGNUM, regp
  132.                          + i386_linux_gregset_reg_offset[I386_LINUX_ORIG_EAX_REGNUM]);
  133. }

  134. /* Fill register REGNO (if it is a general-purpose register) in
  135.    *GREGSETPS with the value in GDB's register array.  If REGNO is -1,
  136.    do this for all registers.  */

  137. void
  138. fill_gregset (const struct regcache *regcache,
  139.               elf_gregset_t *gregsetp, int regno)
  140. {
  141.   gdb_byte *regp = (gdb_byte *) gregsetp;
  142.   int i;

  143.   for (i = 0; i < I386_NUM_GREGS; i++)
  144.     if (regno == -1 || regno == i)
  145.       regcache_raw_collect (regcache, i,
  146.                             regp + i386_linux_gregset_reg_offset[i]);

  147.   if ((regno == -1 || regno == I386_LINUX_ORIG_EAX_REGNUM)
  148.       && I386_LINUX_ORIG_EAX_REGNUM
  149.            < gdbarch_num_regs (get_regcache_arch (regcache)))
  150.     regcache_raw_collect (regcache, I386_LINUX_ORIG_EAX_REGNUM, regp
  151.                           + i386_linux_gregset_reg_offset[I386_LINUX_ORIG_EAX_REGNUM]);
  152. }

  153. #ifdef HAVE_PTRACE_GETREGS

  154. /* Fetch all general-purpose registers from process/thread TID and
  155.    store their values in GDB's register array.  */

  156. static void
  157. fetch_regs (struct regcache *regcache, int tid)
  158. {
  159.   elf_gregset_t regs;
  160.   elf_gregset_t *regs_p = &regs;

  161.   if (ptrace (PTRACE_GETREGS, tid, 0, (int) &regs) < 0)
  162.     {
  163.       if (errno == EIO)
  164.         {
  165.           /* The kernel we're running on doesn't support the GETREGS
  166.              request.  Reset `have_ptrace_getregs'.  */
  167.           have_ptrace_getregs = 0;
  168.           return;
  169.         }

  170.       perror_with_name (_("Couldn't get registers"));
  171.     }

  172.   supply_gregset (regcache, (const elf_gregset_t *) regs_p);
  173. }

  174. /* Store all valid general-purpose registers in GDB's register array
  175.    into the process/thread specified by TID.  */

  176. static void
  177. store_regs (const struct regcache *regcache, int tid, int regno)
  178. {
  179.   elf_gregset_t regs;

  180.   if (ptrace (PTRACE_GETREGS, tid, 0, (int) &regs) < 0)
  181.     perror_with_name (_("Couldn't get registers"));

  182.   fill_gregset (regcache, &regs, regno);

  183.   if (ptrace (PTRACE_SETREGS, tid, 0, (int) &regs) < 0)
  184.     perror_with_name (_("Couldn't write registers"));
  185. }

  186. #else

  187. static void fetch_regs (struct regcache *regcache, int tid) {}
  188. static void store_regs (const struct regcache *regcache, int tid, int regno) {}

  189. #endif


  190. /* Transfering floating-point registers between GDB, inferiors and cores.  */

  191. /* Fill GDB's register array with the floating-point register values in
  192.    *FPREGSETP.  */

  193. void
  194. supply_fpregset (struct regcache *regcache, const elf_fpregset_t *fpregsetp)
  195. {
  196.   i387_supply_fsave (regcache, -1, fpregsetp);
  197. }

  198. /* Fill register REGNO (if it is a floating-point register) in
  199.    *FPREGSETP with the value in GDB's register array.  If REGNO is -1,
  200.    do this for all registers.  */

  201. void
  202. fill_fpregset (const struct regcache *regcache,
  203.                elf_fpregset_t *fpregsetp, int regno)
  204. {
  205.   i387_collect_fsave (regcache, regno, fpregsetp);
  206. }

  207. #ifdef HAVE_PTRACE_GETREGS

  208. /* Fetch all floating-point registers from process/thread TID and store
  209.    thier values in GDB's register array.  */

  210. static void
  211. fetch_fpregs (struct regcache *regcache, int tid)
  212. {
  213.   elf_fpregset_t fpregs;

  214.   if (ptrace (PTRACE_GETFPREGS, tid, 0, (int) &fpregs) < 0)
  215.     perror_with_name (_("Couldn't get floating point status"));

  216.   supply_fpregset (regcache, (const elf_fpregset_t *) &fpregs);
  217. }

  218. /* Store all valid floating-point registers in GDB's register array
  219.    into the process/thread specified by TID.  */

  220. static void
  221. store_fpregs (const struct regcache *regcache, int tid, int regno)
  222. {
  223.   elf_fpregset_t fpregs;

  224.   if (ptrace (PTRACE_GETFPREGS, tid, 0, (int) &fpregs) < 0)
  225.     perror_with_name (_("Couldn't get floating point status"));

  226.   fill_fpregset (regcache, &fpregs, regno);

  227.   if (ptrace (PTRACE_SETFPREGS, tid, 0, (int) &fpregs) < 0)
  228.     perror_with_name (_("Couldn't write floating point status"));
  229. }

  230. #else

  231. static void
  232. fetch_fpregs (struct regcache *regcache, int tid)
  233. {
  234. }

  235. static void
  236. store_fpregs (const struct regcache *regcache, int tid, int regno)
  237. {
  238. }

  239. #endif


  240. /* Transfering floating-point and SSE registers to and from GDB.  */

  241. /* Fetch all registers covered by the PTRACE_GETREGSET request from
  242.    process/thread TID and store their values in GDB's register array.
  243.    Return non-zero if successful, zero otherwise.  */

  244. static int
  245. fetch_xstateregs (struct regcache *regcache, int tid)
  246. {
  247.   char xstateregs[X86_XSTATE_MAX_SIZE];
  248.   struct iovec iov;

  249.   if (!have_ptrace_getregset)
  250.     return 0;

  251.   iov.iov_base = xstateregs;
  252.   iov.iov_len = sizeof(xstateregs);
  253.   if (ptrace (PTRACE_GETREGSET, tid, (unsigned int) NT_X86_XSTATE,
  254.               &iov) < 0)
  255.     perror_with_name (_("Couldn't read extended state status"));

  256.   i387_supply_xsave (regcache, -1, xstateregs);
  257.   return 1;
  258. }

  259. /* Store all valid registers in GDB's register array covered by the
  260.    PTRACE_SETREGSET request into the process/thread specified by TID.
  261.    Return non-zero if successful, zero otherwise.  */

  262. static int
  263. store_xstateregs (const struct regcache *regcache, int tid, int regno)
  264. {
  265.   char xstateregs[X86_XSTATE_MAX_SIZE];
  266.   struct iovec iov;

  267.   if (!have_ptrace_getregset)
  268.     return 0;

  269.   iov.iov_base = xstateregs;
  270.   iov.iov_len = sizeof(xstateregs);
  271.   if (ptrace (PTRACE_GETREGSET, tid, (unsigned int) NT_X86_XSTATE,
  272.               &iov) < 0)
  273.     perror_with_name (_("Couldn't read extended state status"));

  274.   i387_collect_xsave (regcache, regno, xstateregs, 0);

  275.   if (ptrace (PTRACE_SETREGSET, tid, (unsigned int) NT_X86_XSTATE,
  276.               (int) &iov) < 0)
  277.     perror_with_name (_("Couldn't write extended state status"));

  278.   return 1;
  279. }

  280. #ifdef HAVE_PTRACE_GETFPXREGS

  281. /* Fetch all registers covered by the PTRACE_GETFPXREGS request from
  282.    process/thread TID and store their values in GDB's register array.
  283.    Return non-zero if successful, zero otherwise.  */

  284. static int
  285. fetch_fpxregs (struct regcache *regcache, int tid)
  286. {
  287.   elf_fpxregset_t fpxregs;

  288.   if (! have_ptrace_getfpxregs)
  289.     return 0;

  290.   if (ptrace (PTRACE_GETFPXREGS, tid, 0, (int) &fpxregs) < 0)
  291.     {
  292.       if (errno == EIO)
  293.         {
  294.           have_ptrace_getfpxregs = 0;
  295.           return 0;
  296.         }

  297.       perror_with_name (_("Couldn't read floating-point and SSE registers"));
  298.     }

  299.   i387_supply_fxsave (regcache, -1, (const elf_fpxregset_t *) &fpxregs);
  300.   return 1;
  301. }

  302. /* Store all valid registers in GDB's register array covered by the
  303.    PTRACE_SETFPXREGS request into the process/thread specified by TID.
  304.    Return non-zero if successful, zero otherwise.  */

  305. static int
  306. store_fpxregs (const struct regcache *regcache, int tid, int regno)
  307. {
  308.   elf_fpxregset_t fpxregs;

  309.   if (! have_ptrace_getfpxregs)
  310.     return 0;

  311.   if (ptrace (PTRACE_GETFPXREGS, tid, 0, &fpxregs) == -1)
  312.     {
  313.       if (errno == EIO)
  314.         {
  315.           have_ptrace_getfpxregs = 0;
  316.           return 0;
  317.         }

  318.       perror_with_name (_("Couldn't read floating-point and SSE registers"));
  319.     }

  320.   i387_collect_fxsave (regcache, regno, &fpxregs);

  321.   if (ptrace (PTRACE_SETFPXREGS, tid, 0, &fpxregs) == -1)
  322.     perror_with_name (_("Couldn't write floating-point and SSE registers"));

  323.   return 1;
  324. }

  325. #else

  326. static int
  327. fetch_fpxregs (struct regcache *regcache, int tid)
  328. {
  329.   return 0;
  330. }

  331. static int
  332. store_fpxregs (const struct regcache *regcache, int tid, int regno)
  333. {
  334.   return 0;
  335. }

  336. #endif /* HAVE_PTRACE_GETFPXREGS */


  337. /* Transferring arbitrary registers between GDB and inferior.  */

  338. /* Fetch register REGNO from the child process.  If REGNO is -1, do
  339.    this for all registers (including the floating point and SSE
  340.    registers).  */

  341. static void
  342. i386_linux_fetch_inferior_registers (struct target_ops *ops,
  343.                                      struct regcache *regcache, int regno)
  344. {
  345.   int tid;

  346.   /* Use the old method of peeking around in `struct user' if the
  347.      GETREGS request isn't available.  */
  348.   if (!have_ptrace_getregs)
  349.     {
  350.       int i;

  351.       for (i = 0; i < gdbarch_num_regs (get_regcache_arch (regcache)); i++)
  352.         if (regno == -1 || regno == i)
  353.           fetch_register (regcache, i);

  354.       return;
  355.     }

  356.   /* GNU/Linux LWP ID's are process ID's.  */
  357.   tid = ptid_get_lwp (inferior_ptid);
  358.   if (tid == 0)
  359.     tid = ptid_get_pid (inferior_ptid); /* Not a threaded program.  */

  360.   /* Use the PTRACE_GETFPXREGS request whenever possible, since it
  361.      transfers more registers in one system call, and we'll cache the
  362.      results.  But remember that fetch_fpxregs can fail, and return
  363.      zero.  */
  364.   if (regno == -1)
  365.     {
  366.       fetch_regs (regcache, tid);

  367.       /* The call above might reset `have_ptrace_getregs'.  */
  368.       if (!have_ptrace_getregs)
  369.         {
  370.           i386_linux_fetch_inferior_registers (ops, regcache, regno);
  371.           return;
  372.         }

  373.       if (fetch_xstateregs (regcache, tid))
  374.         return;
  375.       if (fetch_fpxregs (regcache, tid))
  376.         return;
  377.       fetch_fpregs (regcache, tid);
  378.       return;
  379.     }

  380.   if (GETREGS_SUPPLIES (regno))
  381.     {
  382.       fetch_regs (regcache, tid);
  383.       return;
  384.     }

  385.   if (GETXSTATEREGS_SUPPLIES (regno))
  386.     {
  387.       if (fetch_xstateregs (regcache, tid))
  388.         return;
  389.     }

  390.   if (GETFPXREGS_SUPPLIES (regno))
  391.     {
  392.       if (fetch_fpxregs (regcache, tid))
  393.         return;

  394.       /* Either our processor or our kernel doesn't support the SSE
  395.          registers, so read the FP registers in the traditional way,
  396.          and fill the SSE registers with dummy values.  It would be
  397.          more graceful to handle differences in the register set using
  398.          gdbarch.  Until then, this will at least make things work
  399.          plausibly.  */
  400.       fetch_fpregs (regcache, tid);
  401.       return;
  402.     }

  403.   internal_error (__FILE__, __LINE__,
  404.                   _("Got request for bad register number %d."), regno);
  405. }

  406. /* Store register REGNO back into the child process.  If REGNO is -1,
  407.    do this for all registers (including the floating point and SSE
  408.    registers).  */
  409. static void
  410. i386_linux_store_inferior_registers (struct target_ops *ops,
  411.                                      struct regcache *regcache, int regno)
  412. {
  413.   int tid;

  414.   /* Use the old method of poking around in `struct user' if the
  415.      SETREGS request isn't available.  */
  416.   if (!have_ptrace_getregs)
  417.     {
  418.       int i;

  419.       for (i = 0; i < gdbarch_num_regs (get_regcache_arch (regcache)); i++)
  420.         if (regno == -1 || regno == i)
  421.           store_register (regcache, i);

  422.       return;
  423.     }

  424.   /* GNU/Linux LWP ID's are process ID's.  */
  425.   tid = ptid_get_lwp (inferior_ptid);
  426.   if (tid == 0)
  427.     tid = ptid_get_pid (inferior_ptid); /* Not a threaded program.  */

  428.   /* Use the PTRACE_SETFPXREGS requests whenever possible, since it
  429.      transfers more registers in one system call.  But remember that
  430.      store_fpxregs can fail, and return zero.  */
  431.   if (regno == -1)
  432.     {
  433.       store_regs (regcache, tid, regno);
  434.       if (store_xstateregs (regcache, tid, regno))
  435.         return;
  436.       if (store_fpxregs (regcache, tid, regno))
  437.         return;
  438.       store_fpregs (regcache, tid, regno);
  439.       return;
  440.     }

  441.   if (GETREGS_SUPPLIES (regno))
  442.     {
  443.       store_regs (regcache, tid, regno);
  444.       return;
  445.     }

  446.   if (GETXSTATEREGS_SUPPLIES (regno))
  447.     {
  448.       if (store_xstateregs (regcache, tid, regno))
  449.         return;
  450.     }

  451.   if (GETFPXREGS_SUPPLIES (regno))
  452.     {
  453.       if (store_fpxregs (regcache, tid, regno))
  454.         return;

  455.       /* Either our processor or our kernel doesn't support the SSE
  456.          registers, so just write the FP registers in the traditional
  457.          way.  */
  458.       store_fpregs (regcache, tid, regno);
  459.       return;
  460.     }

  461.   internal_error (__FILE__, __LINE__,
  462.                   _("Got request to store bad register number %d."), regno);
  463. }


  464. /* Called by libthread_db.  Returns a pointer to the thread local
  465.    storage (or its descriptor).  */

  466. ps_err_e
  467. ps_get_thread_area (const struct ps_prochandle *ph,
  468.                     lwpid_t lwpid, int idx, void **base)
  469. {
  470.   unsigned int base_addr;
  471.   ps_err_e result;

  472.   result = x86_linux_get_thread_area (lwpid, (void *) idx, &base_addr);

  473.   if (result == PS_OK)
  474.     *(int *) base = base_addr;

  475.   return result;
  476. }


  477. /* The instruction for a GNU/Linux system call is:
  478.        int $0x80
  479.    or 0xcd 0x80.  */

  480. static const unsigned char linux_syscall[] = { 0xcd, 0x80 };

  481. #define LINUX_SYSCALL_LEN (sizeof linux_syscall)

  482. /* The system call number is stored in the %eax register.  */
  483. #define LINUX_SYSCALL_REGNUM I386_EAX_REGNUM

  484. /* We are specifically interested in the sigreturn and rt_sigreturn
  485.    system calls.  */

  486. #ifndef SYS_sigreturn
  487. #define SYS_sigreturn                0x77
  488. #endif
  489. #ifndef SYS_rt_sigreturn
  490. #define SYS_rt_sigreturn        0xad
  491. #endif

  492. /* Offset to saved processor flags, from <asm/sigcontext.h>.  */
  493. #define LINUX_SIGCONTEXT_EFLAGS_OFFSET (64)

  494. /* Resume execution of the inferior process.
  495.    If STEP is nonzero, single-step it.
  496.    If SIGNAL is nonzero, give it that signal.  */

  497. static void
  498. i386_linux_resume (struct target_ops *ops,
  499.                    ptid_t ptid, int step, enum gdb_signal signal)
  500. {
  501.   int pid = ptid_get_pid (ptid);

  502.   int request;

  503.   if (catch_syscall_enabled () > 0)
  504.    request = PTRACE_SYSCALL;
  505.   else
  506.     request = PTRACE_CONT;

  507.   if (step)
  508.     {
  509.       struct regcache *regcache = get_thread_regcache (pid_to_ptid (pid));
  510.       struct gdbarch *gdbarch = get_regcache_arch (regcache);
  511.       enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
  512.       ULONGEST pc;
  513.       gdb_byte buf[LINUX_SYSCALL_LEN];

  514.       request = PTRACE_SINGLESTEP;

  515.       regcache_cooked_read_unsigned (regcache,
  516.                                      gdbarch_pc_regnum (gdbarch), &pc);

  517.       /* Returning from a signal trampoline is done by calling a
  518.          special system call (sigreturn or rt_sigreturn, see
  519.          i386-linux-tdep.c for more information).  This system call
  520.          restores the registers that were saved when the signal was
  521.          raised, including %eflags.  That means that single-stepping
  522.          won't work.  Instead, we'll have to modify the signal context
  523.          that's about to be restored, and set the trace flag there.  */

  524.       /* First check if PC is at a system call.  */
  525.       if (target_read_memory (pc, buf, LINUX_SYSCALL_LEN) == 0
  526.           && memcmp (buf, linux_syscall, LINUX_SYSCALL_LEN) == 0)
  527.         {
  528.           ULONGEST syscall;
  529.           regcache_cooked_read_unsigned (regcache,
  530.                                          LINUX_SYSCALL_REGNUM, &syscall);

  531.           /* Then check the system call number.  */
  532.           if (syscall == SYS_sigreturn || syscall == SYS_rt_sigreturn)
  533.             {
  534.               ULONGEST sp, addr;
  535.               unsigned long int eflags;

  536.               regcache_cooked_read_unsigned (regcache, I386_ESP_REGNUM, &sp);
  537.               if (syscall == SYS_rt_sigreturn)
  538.                 addr = read_memory_unsigned_integer (sp + 8, 4, byte_order)
  539.                   + 20;
  540.               else
  541.                 addr = sp;

  542.               /* Set the trace flag in the context that's about to be
  543.                  restored.  */
  544.               addr += LINUX_SIGCONTEXT_EFLAGS_OFFSET;
  545.               read_memory (addr, (gdb_byte *) &eflags, 4);
  546.               eflags |= 0x0100;
  547.               write_memory (addr, (gdb_byte *) &eflags, 4);
  548.             }
  549.         }
  550.     }

  551.   if (ptrace (request, pid, 0, gdb_signal_to_host (signal)) == -1)
  552.     perror_with_name (("ptrace"));
  553. }


  554. /* -Wmissing-prototypes */
  555. extern initialize_file_ftype _initialize_i386_linux_nat;

  556. void
  557. _initialize_i386_linux_nat (void)
  558. {
  559.   /* Create a generic x86 GNU/Linux target.  */
  560.   struct target_ops *t = x86_linux_create_target ();

  561.   /* Override the default ptrace resume method.  */
  562.   t->to_resume = i386_linux_resume;

  563.   /* Add our register access methods.  */
  564.   t->to_fetch_registers = i386_linux_fetch_inferior_registers;
  565.   t->to_store_registers = i386_linux_store_inferior_registers;

  566.   /* Add the target.  */
  567.   x86_linux_add_target (t);
  568. }