Move duplicated code into new files
[external/binutils.git] / gdb / i386-linux-nat.c
1 /* Native-dependent code for GNU/Linux i386.
2
3    Copyright (C) 1999-2014 Free Software Foundation, Inc.
4
5    This file is part of GDB.
6
7    This program is free software; you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation; either version 3 of the License, or
10    (at your option) any later version.
11
12    This program is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16
17    You should have received a copy of the GNU General Public License
18    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
19
20 #include "defs.h"
21 #include "i386-nat.h"
22 #include "inferior.h"
23 #include "gdbcore.h"
24 #include "regcache.h"
25 #include "regset.h"
26 #include "target.h"
27 #include "linux-nat.h"
28 #include "nat/linux-btrace.h"
29 #include "btrace.h"
30
31 #include "gdb_assert.h"
32 #include <string.h>
33 #include "elf/common.h"
34 #include <sys/uio.h>
35 #include <sys/ptrace.h>
36 #include <sys/user.h>
37 #include <sys/procfs.h>
38
39 #ifdef HAVE_SYS_REG_H
40 #include <sys/reg.h>
41 #endif
42
43 #ifndef ORIG_EAX
44 #define ORIG_EAX -1
45 #endif
46
47 #ifdef HAVE_SYS_DEBUGREG_H
48 #include <sys/debugreg.h>
49 #endif
50
51 /* Prototypes for supply_gregset etc.  */
52 #include "gregset.h"
53
54 #include "i387-tdep.h"
55 #include "i386-tdep.h"
56 #include "i386-linux-tdep.h"
57
58 /* Defines ps_err_e, struct ps_prochandle.  */
59 #include "gdb_proc_service.h"
60
61 #include "i386-xstate.h"
62
63 #include "x86-linux-nat.h"
64
65 /* The register sets used in GNU/Linux ELF core-dumps are identical to
66    the register sets in `struct user' that is used for a.out
67    core-dumps, and is also used by `ptrace'.  The corresponding types
68    are `elf_gregset_t' for the general-purpose registers (with
69    `elf_greg_t' the type of a single GP register) and `elf_fpregset_t'
70    for the floating-point registers.
71
72    Those types used to be available under the names `gregset_t' and
73    `fpregset_t' too, and this file used those names in the past.  But
74    those names are now used for the register sets used in the
75    `mcontext_t' type, and have a different size and layout.  */
76
77 /* Which ptrace request retrieves which registers?
78    These apply to the corresponding SET requests as well.  */
79
80 #define GETREGS_SUPPLIES(regno) \
81   ((0 <= (regno) && (regno) <= 15) || (regno) == I386_LINUX_ORIG_EAX_REGNUM)
82
83 #define GETFPXREGS_SUPPLIES(regno) \
84   (I386_ST0_REGNUM <= (regno) && (regno) < I386_SSE_NUM_REGS)
85
86 #define GETXSTATEREGS_SUPPLIES(regno) \
87   (I386_ST0_REGNUM <= (regno) && (regno) < I386_AVX512_NUM_REGS)
88
89 /* Does the current host support the GETREGS request?  */
90 int have_ptrace_getregs =
91 #ifdef HAVE_PTRACE_GETREGS
92   1
93 #else
94   0
95 #endif
96 ;
97
98 /* Does the current host support the GETFPXREGS request?  The header
99    file may or may not define it, and even if it is defined, the
100    kernel will return EIO if it's running on a pre-SSE processor.
101
102    My instinct is to attach this to some architecture- or
103    target-specific data structure, but really, a particular GDB
104    process can only run on top of one kernel at a time.  So it's okay
105    for this to be a simple variable.  */
106 int have_ptrace_getfpxregs =
107 #ifdef HAVE_PTRACE_GETFPXREGS
108   -1
109 #else
110   0
111 #endif
112 ;
113 \f
114
115 /* Accessing registers through the U area, one at a time.  */
116
117 /* Fetch one register.  */
118
119 static void
120 fetch_register (struct regcache *regcache, int regno)
121 {
122   int tid;
123   int val;
124
125   gdb_assert (!have_ptrace_getregs);
126   if (i386_linux_gregset_reg_offset[regno] == -1)
127     {
128       regcache_raw_supply (regcache, regno, NULL);
129       return;
130     }
131
132   /* GNU/Linux LWP ID's are process ID's.  */
133   tid = ptid_get_lwp (inferior_ptid);
134   if (tid == 0)
135     tid = ptid_get_pid (inferior_ptid); /* Not a threaded program.  */
136
137   errno = 0;
138   val = ptrace (PTRACE_PEEKUSER, tid,
139                 i386_linux_gregset_reg_offset[regno], 0);
140   if (errno != 0)
141     error (_("Couldn't read register %s (#%d): %s."), 
142            gdbarch_register_name (get_regcache_arch (regcache), regno),
143            regno, safe_strerror (errno));
144
145   regcache_raw_supply (regcache, regno, &val);
146 }
147
148 /* Store one register.  */
149
150 static void
151 store_register (const struct regcache *regcache, int regno)
152 {
153   int tid;
154   int val;
155
156   gdb_assert (!have_ptrace_getregs);
157   if (i386_linux_gregset_reg_offset[regno] == -1)
158     return;
159
160   /* GNU/Linux LWP ID's are process ID's.  */
161   tid = ptid_get_lwp (inferior_ptid);
162   if (tid == 0)
163     tid = ptid_get_pid (inferior_ptid); /* Not a threaded program.  */
164
165   errno = 0;
166   regcache_raw_collect (regcache, regno, &val);
167   ptrace (PTRACE_POKEUSER, tid,
168           i386_linux_gregset_reg_offset[regno], val);
169   if (errno != 0)
170     error (_("Couldn't write register %s (#%d): %s."),
171            gdbarch_register_name (get_regcache_arch (regcache), regno),
172            regno, safe_strerror (errno));
173 }
174 \f
175
176 /* Transfering the general-purpose registers between GDB, inferiors
177    and core files.  */
178
179 /* Fill GDB's register array with the general-purpose register values
180    in *GREGSETP.  */
181
182 void
183 supply_gregset (struct regcache *regcache, const elf_gregset_t *gregsetp)
184 {
185   const gdb_byte *regp = (const gdb_byte *) gregsetp;
186   int i;
187
188   for (i = 0; i < I386_NUM_GREGS; i++)
189     regcache_raw_supply (regcache, i,
190                          regp + i386_linux_gregset_reg_offset[i]);
191
192   if (I386_LINUX_ORIG_EAX_REGNUM
193         < gdbarch_num_regs (get_regcache_arch (regcache)))
194     regcache_raw_supply (regcache, I386_LINUX_ORIG_EAX_REGNUM, regp
195                          + i386_linux_gregset_reg_offset[I386_LINUX_ORIG_EAX_REGNUM]);
196 }
197
198 /* Fill register REGNO (if it is a general-purpose register) in
199    *GREGSETPS with the value in GDB's register array.  If REGNO is -1,
200    do this for all registers.  */
201
202 void
203 fill_gregset (const struct regcache *regcache,
204               elf_gregset_t *gregsetp, int regno)
205 {
206   gdb_byte *regp = (gdb_byte *) gregsetp;
207   int i;
208
209   for (i = 0; i < I386_NUM_GREGS; i++)
210     if (regno == -1 || regno == i)
211       regcache_raw_collect (regcache, i,
212                             regp + i386_linux_gregset_reg_offset[i]);
213
214   if ((regno == -1 || regno == I386_LINUX_ORIG_EAX_REGNUM)
215       && I386_LINUX_ORIG_EAX_REGNUM
216            < gdbarch_num_regs (get_regcache_arch (regcache)))
217     regcache_raw_collect (regcache, I386_LINUX_ORIG_EAX_REGNUM, regp
218                           + i386_linux_gregset_reg_offset[I386_LINUX_ORIG_EAX_REGNUM]);
219 }
220
221 #ifdef HAVE_PTRACE_GETREGS
222
223 /* Fetch all general-purpose registers from process/thread TID and
224    store their values in GDB's register array.  */
225
226 static void
227 fetch_regs (struct regcache *regcache, int tid)
228 {
229   elf_gregset_t regs;
230   elf_gregset_t *regs_p = &regs;
231
232   if (ptrace (PTRACE_GETREGS, tid, 0, (int) &regs) < 0)
233     {
234       if (errno == EIO)
235         {
236           /* The kernel we're running on doesn't support the GETREGS
237              request.  Reset `have_ptrace_getregs'.  */
238           have_ptrace_getregs = 0;
239           return;
240         }
241
242       perror_with_name (_("Couldn't get registers"));
243     }
244
245   supply_gregset (regcache, (const elf_gregset_t *) regs_p);
246 }
247
248 /* Store all valid general-purpose registers in GDB's register array
249    into the process/thread specified by TID.  */
250
251 static void
252 store_regs (const struct regcache *regcache, int tid, int regno)
253 {
254   elf_gregset_t regs;
255
256   if (ptrace (PTRACE_GETREGS, tid, 0, (int) &regs) < 0)
257     perror_with_name (_("Couldn't get registers"));
258
259   fill_gregset (regcache, &regs, regno);
260   
261   if (ptrace (PTRACE_SETREGS, tid, 0, (int) &regs) < 0)
262     perror_with_name (_("Couldn't write registers"));
263 }
264
265 #else
266
267 static void fetch_regs (struct regcache *regcache, int tid) {}
268 static void store_regs (const struct regcache *regcache, int tid, int regno) {}
269
270 #endif
271 \f
272
273 /* Transfering floating-point registers between GDB, inferiors and cores.  */
274
275 /* Fill GDB's register array with the floating-point register values in
276    *FPREGSETP.  */
277
278 void 
279 supply_fpregset (struct regcache *regcache, const elf_fpregset_t *fpregsetp)
280 {
281   i387_supply_fsave (regcache, -1, fpregsetp);
282 }
283
284 /* Fill register REGNO (if it is a floating-point register) in
285    *FPREGSETP with the value in GDB's register array.  If REGNO is -1,
286    do this for all registers.  */
287
288 void
289 fill_fpregset (const struct regcache *regcache,
290                elf_fpregset_t *fpregsetp, int regno)
291 {
292   i387_collect_fsave (regcache, regno, fpregsetp);
293 }
294
295 #ifdef HAVE_PTRACE_GETREGS
296
297 /* Fetch all floating-point registers from process/thread TID and store
298    thier values in GDB's register array.  */
299
300 static void
301 fetch_fpregs (struct regcache *regcache, int tid)
302 {
303   elf_fpregset_t fpregs;
304
305   if (ptrace (PTRACE_GETFPREGS, tid, 0, (int) &fpregs) < 0)
306     perror_with_name (_("Couldn't get floating point status"));
307
308   supply_fpregset (regcache, (const elf_fpregset_t *) &fpregs);
309 }
310
311 /* Store all valid floating-point registers in GDB's register array
312    into the process/thread specified by TID.  */
313
314 static void
315 store_fpregs (const struct regcache *regcache, int tid, int regno)
316 {
317   elf_fpregset_t fpregs;
318
319   if (ptrace (PTRACE_GETFPREGS, tid, 0, (int) &fpregs) < 0)
320     perror_with_name (_("Couldn't get floating point status"));
321
322   fill_fpregset (regcache, &fpregs, regno);
323
324   if (ptrace (PTRACE_SETFPREGS, tid, 0, (int) &fpregs) < 0)
325     perror_with_name (_("Couldn't write floating point status"));
326 }
327
328 #else
329
330 static void
331 fetch_fpregs (struct regcache *regcache, int tid)
332 {
333 }
334
335 static void
336 store_fpregs (const struct regcache *regcache, int tid, int regno)
337 {
338 }
339
340 #endif
341 \f
342
343 /* Transfering floating-point and SSE registers to and from GDB.  */
344
345 /* Fetch all registers covered by the PTRACE_GETREGSET request from
346    process/thread TID and store their values in GDB's register array.
347    Return non-zero if successful, zero otherwise.  */
348
349 static int
350 fetch_xstateregs (struct regcache *regcache, int tid)
351 {
352   char xstateregs[I386_XSTATE_MAX_SIZE];
353   struct iovec iov;
354
355   if (!have_ptrace_getregset)
356     return 0;
357
358   iov.iov_base = xstateregs;
359   iov.iov_len = sizeof(xstateregs);
360   if (ptrace (PTRACE_GETREGSET, tid, (unsigned int) NT_X86_XSTATE,
361               &iov) < 0)
362     perror_with_name (_("Couldn't read extended state status"));
363
364   i387_supply_xsave (regcache, -1, xstateregs);
365   return 1;
366 }
367
368 /* Store all valid registers in GDB's register array covered by the
369    PTRACE_SETREGSET request into the process/thread specified by TID.
370    Return non-zero if successful, zero otherwise.  */
371
372 static int
373 store_xstateregs (const struct regcache *regcache, int tid, int regno)
374 {
375   char xstateregs[I386_XSTATE_MAX_SIZE];
376   struct iovec iov;
377
378   if (!have_ptrace_getregset)
379     return 0;
380   
381   iov.iov_base = xstateregs;
382   iov.iov_len = sizeof(xstateregs);
383   if (ptrace (PTRACE_GETREGSET, tid, (unsigned int) NT_X86_XSTATE,
384               &iov) < 0)
385     perror_with_name (_("Couldn't read extended state status"));
386
387   i387_collect_xsave (regcache, regno, xstateregs, 0);
388
389   if (ptrace (PTRACE_SETREGSET, tid, (unsigned int) NT_X86_XSTATE,
390               (int) &iov) < 0)
391     perror_with_name (_("Couldn't write extended state status"));
392
393   return 1;
394 }
395
396 #ifdef HAVE_PTRACE_GETFPXREGS
397
398 /* Fetch all registers covered by the PTRACE_GETFPXREGS request from
399    process/thread TID and store their values in GDB's register array.
400    Return non-zero if successful, zero otherwise.  */
401
402 static int
403 fetch_fpxregs (struct regcache *regcache, int tid)
404 {
405   elf_fpxregset_t fpxregs;
406
407   if (! have_ptrace_getfpxregs)
408     return 0;
409
410   if (ptrace (PTRACE_GETFPXREGS, tid, 0, (int) &fpxregs) < 0)
411     {
412       if (errno == EIO)
413         {
414           have_ptrace_getfpxregs = 0;
415           return 0;
416         }
417
418       perror_with_name (_("Couldn't read floating-point and SSE registers"));
419     }
420
421   i387_supply_fxsave (regcache, -1, (const elf_fpxregset_t *) &fpxregs);
422   return 1;
423 }
424
425 /* Store all valid registers in GDB's register array covered by the
426    PTRACE_SETFPXREGS request into the process/thread specified by TID.
427    Return non-zero if successful, zero otherwise.  */
428
429 static int
430 store_fpxregs (const struct regcache *regcache, int tid, int regno)
431 {
432   elf_fpxregset_t fpxregs;
433
434   if (! have_ptrace_getfpxregs)
435     return 0;
436   
437   if (ptrace (PTRACE_GETFPXREGS, tid, 0, &fpxregs) == -1)
438     {
439       if (errno == EIO)
440         {
441           have_ptrace_getfpxregs = 0;
442           return 0;
443         }
444
445       perror_with_name (_("Couldn't read floating-point and SSE registers"));
446     }
447
448   i387_collect_fxsave (regcache, regno, &fpxregs);
449
450   if (ptrace (PTRACE_SETFPXREGS, tid, 0, &fpxregs) == -1)
451     perror_with_name (_("Couldn't write floating-point and SSE registers"));
452
453   return 1;
454 }
455
456 #else
457
458 static int
459 fetch_fpxregs (struct regcache *regcache, int tid)
460 {
461   return 0;
462 }
463
464 static int
465 store_fpxregs (const struct regcache *regcache, int tid, int regno)
466 {
467   return 0;
468 }
469
470 #endif /* HAVE_PTRACE_GETFPXREGS */
471 \f
472
473 /* Transferring arbitrary registers between GDB and inferior.  */
474
475 /* Fetch register REGNO from the child process.  If REGNO is -1, do
476    this for all registers (including the floating point and SSE
477    registers).  */
478
479 static void
480 i386_linux_fetch_inferior_registers (struct target_ops *ops,
481                                      struct regcache *regcache, int regno)
482 {
483   int tid;
484
485   /* Use the old method of peeking around in `struct user' if the
486      GETREGS request isn't available.  */
487   if (!have_ptrace_getregs)
488     {
489       int i;
490
491       for (i = 0; i < gdbarch_num_regs (get_regcache_arch (regcache)); i++)
492         if (regno == -1 || regno == i)
493           fetch_register (regcache, i);
494
495       return;
496     }
497
498   /* GNU/Linux LWP ID's are process ID's.  */
499   tid = ptid_get_lwp (inferior_ptid);
500   if (tid == 0)
501     tid = ptid_get_pid (inferior_ptid); /* Not a threaded program.  */
502
503   /* Use the PTRACE_GETFPXREGS request whenever possible, since it
504      transfers more registers in one system call, and we'll cache the
505      results.  But remember that fetch_fpxregs can fail, and return
506      zero.  */
507   if (regno == -1)
508     {
509       fetch_regs (regcache, tid);
510
511       /* The call above might reset `have_ptrace_getregs'.  */
512       if (!have_ptrace_getregs)
513         {
514           i386_linux_fetch_inferior_registers (ops, regcache, regno);
515           return;
516         }
517
518       if (fetch_xstateregs (regcache, tid))
519         return;
520       if (fetch_fpxregs (regcache, tid))
521         return;
522       fetch_fpregs (regcache, tid);
523       return;
524     }
525
526   if (GETREGS_SUPPLIES (regno))
527     {
528       fetch_regs (regcache, tid);
529       return;
530     }
531
532   if (GETXSTATEREGS_SUPPLIES (regno))
533     {
534       if (fetch_xstateregs (regcache, tid))
535         return;
536     }
537
538   if (GETFPXREGS_SUPPLIES (regno))
539     {
540       if (fetch_fpxregs (regcache, tid))
541         return;
542
543       /* Either our processor or our kernel doesn't support the SSE
544          registers, so read the FP registers in the traditional way,
545          and fill the SSE registers with dummy values.  It would be
546          more graceful to handle differences in the register set using
547          gdbarch.  Until then, this will at least make things work
548          plausibly.  */
549       fetch_fpregs (regcache, tid);
550       return;
551     }
552
553   internal_error (__FILE__, __LINE__,
554                   _("Got request for bad register number %d."), regno);
555 }
556
557 /* Store register REGNO back into the child process.  If REGNO is -1,
558    do this for all registers (including the floating point and SSE
559    registers).  */
560 static void
561 i386_linux_store_inferior_registers (struct target_ops *ops,
562                                      struct regcache *regcache, int regno)
563 {
564   int tid;
565
566   /* Use the old method of poking around in `struct user' if the
567      SETREGS request isn't available.  */
568   if (!have_ptrace_getregs)
569     {
570       int i;
571
572       for (i = 0; i < gdbarch_num_regs (get_regcache_arch (regcache)); i++)
573         if (regno == -1 || regno == i)
574           store_register (regcache, i);
575
576       return;
577     }
578
579   /* GNU/Linux LWP ID's are process ID's.  */
580   tid = ptid_get_lwp (inferior_ptid);
581   if (tid == 0)
582     tid = ptid_get_pid (inferior_ptid); /* Not a threaded program.  */
583
584   /* Use the PTRACE_SETFPXREGS requests whenever possible, since it
585      transfers more registers in one system call.  But remember that
586      store_fpxregs can fail, and return zero.  */
587   if (regno == -1)
588     {
589       store_regs (regcache, tid, regno);
590       if (store_xstateregs (regcache, tid, regno))
591         return;
592       if (store_fpxregs (regcache, tid, regno))
593         return;
594       store_fpregs (regcache, tid, regno);
595       return;
596     }
597
598   if (GETREGS_SUPPLIES (regno))
599     {
600       store_regs (regcache, tid, regno);
601       return;
602     }
603
604   if (GETXSTATEREGS_SUPPLIES (regno))
605     {
606       if (store_xstateregs (regcache, tid, regno))
607         return;
608     }
609
610   if (GETFPXREGS_SUPPLIES (regno))
611     {
612       if (store_fpxregs (regcache, tid, regno))
613         return;
614
615       /* Either our processor or our kernel doesn't support the SSE
616          registers, so just write the FP registers in the traditional
617          way.  */
618       store_fpregs (regcache, tid, regno);
619       return;
620     }
621
622   internal_error (__FILE__, __LINE__,
623                   _("Got request to store bad register number %d."), regno);
624 }
625 \f
626
627 /* Called by libthread_db.  Returns a pointer to the thread local
628    storage (or its descriptor).  */
629
630 ps_err_e
631 ps_get_thread_area (const struct ps_prochandle *ph,
632                     lwpid_t lwpid, int idx, void **base)
633 {
634   unsigned int base_addr;
635   ps_err_e result;
636
637   result = x86_linux_get_thread_area (lwpid, (void *) idx, &base_addr);
638
639   if (result == PS_OK)
640     *(int *) base = base_addr;
641
642   return result;
643 }
644 \f
645
646 /* The instruction for a GNU/Linux system call is:
647        int $0x80
648    or 0xcd 0x80.  */
649
650 static const unsigned char linux_syscall[] = { 0xcd, 0x80 };
651
652 #define LINUX_SYSCALL_LEN (sizeof linux_syscall)
653
654 /* The system call number is stored in the %eax register.  */
655 #define LINUX_SYSCALL_REGNUM I386_EAX_REGNUM
656
657 /* We are specifically interested in the sigreturn and rt_sigreturn
658    system calls.  */
659
660 #ifndef SYS_sigreturn
661 #define SYS_sigreturn           0x77
662 #endif
663 #ifndef SYS_rt_sigreturn
664 #define SYS_rt_sigreturn        0xad
665 #endif
666
667 /* Offset to saved processor flags, from <asm/sigcontext.h>.  */
668 #define LINUX_SIGCONTEXT_EFLAGS_OFFSET (64)
669
670 /* Resume execution of the inferior process.
671    If STEP is nonzero, single-step it.
672    If SIGNAL is nonzero, give it that signal.  */
673
674 static void
675 i386_linux_resume (struct target_ops *ops,
676                    ptid_t ptid, int step, enum gdb_signal signal)
677 {
678   int pid = ptid_get_pid (ptid);
679
680   int request;
681
682   if (catch_syscall_enabled () > 0)
683    request = PTRACE_SYSCALL;
684   else
685     request = PTRACE_CONT;
686
687   if (step)
688     {
689       struct regcache *regcache = get_thread_regcache (pid_to_ptid (pid));
690       struct gdbarch *gdbarch = get_regcache_arch (regcache);
691       enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
692       ULONGEST pc;
693       gdb_byte buf[LINUX_SYSCALL_LEN];
694
695       request = PTRACE_SINGLESTEP;
696
697       regcache_cooked_read_unsigned (regcache,
698                                      gdbarch_pc_regnum (gdbarch), &pc);
699
700       /* Returning from a signal trampoline is done by calling a
701          special system call (sigreturn or rt_sigreturn, see
702          i386-linux-tdep.c for more information).  This system call
703          restores the registers that were saved when the signal was
704          raised, including %eflags.  That means that single-stepping
705          won't work.  Instead, we'll have to modify the signal context
706          that's about to be restored, and set the trace flag there.  */
707
708       /* First check if PC is at a system call.  */
709       if (target_read_memory (pc, buf, LINUX_SYSCALL_LEN) == 0
710           && memcmp (buf, linux_syscall, LINUX_SYSCALL_LEN) == 0)
711         {
712           ULONGEST syscall;
713           regcache_cooked_read_unsigned (regcache,
714                                          LINUX_SYSCALL_REGNUM, &syscall);
715
716           /* Then check the system call number.  */
717           if (syscall == SYS_sigreturn || syscall == SYS_rt_sigreturn)
718             {
719               ULONGEST sp, addr;
720               unsigned long int eflags;
721
722               regcache_cooked_read_unsigned (regcache, I386_ESP_REGNUM, &sp);
723               if (syscall == SYS_rt_sigreturn)
724                 addr = read_memory_unsigned_integer (sp + 8, 4, byte_order)
725                   + 20;
726               else
727                 addr = sp;
728
729               /* Set the trace flag in the context that's about to be
730                  restored.  */
731               addr += LINUX_SIGCONTEXT_EFLAGS_OFFSET;
732               read_memory (addr, (gdb_byte *) &eflags, 4);
733               eflags |= 0x0100;
734               write_memory (addr, (gdb_byte *) &eflags, 4);
735             }
736         }
737     }
738
739   if (ptrace (request, pid, 0, gdb_signal_to_host (signal)) == -1)
740     perror_with_name (("ptrace"));
741 }
742 \f
743
744 /* -Wmissing-prototypes */
745 extern initialize_file_ftype _initialize_i386_linux_nat;
746
747 void
748 _initialize_i386_linux_nat (void)
749 {
750   /* Create a generic x86 GNU/Linux target.  */
751   struct target_ops *t = x86_linux_create_target ();
752
753   /* Override the default ptrace resume method.  */
754   t->to_resume = i386_linux_resume;
755
756   /* Add our register access methods.  */
757   t->to_fetch_registers = i386_linux_fetch_inferior_registers;
758   t->to_store_registers = i386_linux_store_inferior_registers;
759
760   /* Add the target.  */
761   x86_linux_add_target (t);
762 }