* lin-lwp.c (stop_wait_callback): Remove bogus assertions in the
[deliverable/binutils-gdb.git] / gdb / i386-linux-nat.c
1 /* Native-dependent code for Linux/x86.
2 Copyright 1999, 2000 Free Software Foundation, Inc.
3
4 This file is part of GDB.
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
20
21 #include "defs.h"
22 #include "inferior.h"
23 #include "gdbcore.h"
24
25 #include <sys/ptrace.h>
26 #include <sys/user.h>
27 #include <sys/procfs.h>
28
29 #ifdef HAVE_SYS_REG_H
30 #include <sys/reg.h>
31 #endif
32
33 /* Prototypes for supply_gregset etc. */
34 #include "gregset.h"
35
36 /* Prototypes for i387_supply_fsave etc. */
37 #include "i387-nat.h"
38
39 /* Prototypes for local functions. */
40 static void dummy_sse_values (void);
41
42 /* On Linux, threads are implemented as pseudo-processes, in which
43 case we may be tracing more than one process at a time. In that
44 case, inferior_pid will contain the main process ID and the
45 individual thread (process) ID mashed together. These macros are
46 used to separate them out. These definitions should be overridden
47 if thread support is included. */
48
49 #if !defined (PIDGET) /* Default definition for PIDGET/TIDGET. */
50 #define PIDGET(PID) PID
51 #define TIDGET(PID) 0
52 #endif
53 \f
54
55 /* The register sets used in Linux ELF core-dumps are identical to the
56 register sets in `struct user' that is used for a.out core-dumps,
57 and is also used by `ptrace'. The corresponding types are
58 `elf_gregset_t' for the general-purpose registers (with
59 `elf_greg_t' the type of a single GP register) and `elf_fpregset_t'
60 for the floating-point registers.
61
62 Those types used to be available under the names `gregset_t' and
63 `fpregset_t' too, and this file used those names in the past. But
64 those names are now used for the register sets used in the
65 `mcontext_t' type, and have a different size and layout. */
66
67 /* Mapping between the general-purpose registers in `struct user'
68 format and GDB's register array layout. */
69 static int regmap[] =
70 {
71 EAX, ECX, EDX, EBX,
72 UESP, EBP, ESI, EDI,
73 EIP, EFL, CS, SS,
74 DS, ES, FS, GS
75 };
76
77 /* Which ptrace request retrieves which registers?
78 These apply to the corresponding SET requests as well. */
79 #define GETREGS_SUPPLIES(regno) \
80 (0 <= (regno) && (regno) <= 15)
81 #define GETFPREGS_SUPPLIES(regno) \
82 (FP0_REGNUM <= (regno) && (regno) <= LAST_FPU_CTRL_REGNUM)
83 #define GETFPXREGS_SUPPLIES(regno) \
84 (FP0_REGNUM <= (regno) && (regno) <= MXCSR_REGNUM)
85
86 /* Does the current host support the GETREGS request? */
87 int have_ptrace_getregs =
88 #ifdef HAVE_PTRACE_GETREGS
89 1
90 #else
91 0
92 #endif
93 ;
94
95 /* Does the current host support the GETFPXREGS request? The header
96 file may or may not define it, and even if it is defined, the
97 kernel will return EIO if it's running on a pre-SSE processor.
98
99 My instinct is to attach this to some architecture- or
100 target-specific data structure, but really, a particular GDB
101 process can only run on top of one kernel at a time. So it's okay
102 for this to be a simple variable. */
103 int have_ptrace_getfpxregs =
104 #ifdef HAVE_PTRACE_GETFPXREGS
105 1
106 #else
107 0
108 #endif
109 ;
110 \f
111
112 /* Fetching registers directly from the U area, one at a time. */
113
114 /* FIXME: kettenis/2000-03-05: This duplicates code from `inptrace.c'.
115 The problem is that we define FETCH_INFERIOR_REGISTERS since we
116 want to use our own versions of {fetch,store}_inferior_registers
117 that use the GETREGS request. This means that the code in
118 `infptrace.c' is #ifdef'd out. But we need to fall back on that
119 code when GDB is running on top of a kernel that doesn't support
120 the GETREGS request. I want to avoid changing `infptrace.c' right
121 now. */
122
123 #ifndef PT_READ_U
124 #define PT_READ_U PTRACE_PEEKUSR
125 #endif
126 #ifndef PT_WRITE_U
127 #define PT_WRITE_U PTRACE_POKEUSR
128 #endif
129
130 /* Default the type of the ptrace transfer to int. */
131 #ifndef PTRACE_XFER_TYPE
132 #define PTRACE_XFER_TYPE int
133 #endif
134
135 /* Registers we shouldn't try to fetch. */
136 #if !defined (CANNOT_FETCH_REGISTER)
137 #define CANNOT_FETCH_REGISTER(regno) 0
138 #endif
139
140 /* Fetch one register. */
141
142 static void
143 fetch_register (int regno)
144 {
145 /* This isn't really an address. But ptrace thinks of it as one. */
146 CORE_ADDR regaddr;
147 char mess[128]; /* For messages */
148 register int i;
149 unsigned int offset; /* Offset of registers within the u area. */
150 char buf[MAX_REGISTER_RAW_SIZE];
151 int tid;
152
153 if (CANNOT_FETCH_REGISTER (regno))
154 {
155 memset (buf, '\0', REGISTER_RAW_SIZE (regno)); /* Supply zeroes */
156 supply_register (regno, buf);
157 return;
158 }
159
160 /* Overload thread id onto process id */
161 if ((tid = TIDGET (inferior_pid)) == 0)
162 tid = inferior_pid; /* no thread id, just use process id */
163
164 offset = U_REGS_OFFSET;
165
166 regaddr = register_addr (regno, offset);
167 for (i = 0; i < REGISTER_RAW_SIZE (regno); i += sizeof (PTRACE_XFER_TYPE))
168 {
169 errno = 0;
170 *(PTRACE_XFER_TYPE *) & buf[i] = ptrace (PT_READ_U, tid,
171 (PTRACE_ARG3_TYPE) regaddr, 0);
172 regaddr += sizeof (PTRACE_XFER_TYPE);
173 if (errno != 0)
174 {
175 sprintf (mess, "reading register %s (#%d)",
176 REGISTER_NAME (regno), regno);
177 perror_with_name (mess);
178 }
179 }
180 supply_register (regno, buf);
181 }
182
183 /* Fetch register values from the inferior.
184 If REGNO is negative, do this for all registers.
185 Otherwise, REGNO specifies which register (so we can save time). */
186
187 void
188 old_fetch_inferior_registers (int regno)
189 {
190 if (regno >= 0)
191 {
192 fetch_register (regno);
193 }
194 else
195 {
196 for (regno = 0; regno < ARCH_NUM_REGS; regno++)
197 {
198 fetch_register (regno);
199 }
200 }
201 }
202
203 /* Registers we shouldn't try to store. */
204 #if !defined (CANNOT_STORE_REGISTER)
205 #define CANNOT_STORE_REGISTER(regno) 0
206 #endif
207
208 /* Store one register. */
209
210 static void
211 store_register (int regno)
212 {
213 /* This isn't really an address. But ptrace thinks of it as one. */
214 CORE_ADDR regaddr;
215 char mess[128]; /* For messages */
216 register int i;
217 unsigned int offset; /* Offset of registers within the u area. */
218 int tid;
219
220 if (CANNOT_STORE_REGISTER (regno))
221 {
222 return;
223 }
224
225 /* Overload thread id onto process id */
226 if ((tid = TIDGET (inferior_pid)) == 0)
227 tid = inferior_pid; /* no thread id, just use process id */
228
229 offset = U_REGS_OFFSET;
230
231 regaddr = register_addr (regno, offset);
232 for (i = 0; i < REGISTER_RAW_SIZE (regno); i += sizeof (PTRACE_XFER_TYPE))
233 {
234 errno = 0;
235 ptrace (PT_WRITE_U, tid, (PTRACE_ARG3_TYPE) regaddr,
236 *(PTRACE_XFER_TYPE *) & registers[REGISTER_BYTE (regno) + i]);
237 regaddr += sizeof (PTRACE_XFER_TYPE);
238 if (errno != 0)
239 {
240 sprintf (mess, "writing register %s (#%d)",
241 REGISTER_NAME (regno), regno);
242 perror_with_name (mess);
243 }
244 }
245 }
246
247 /* Store our register values back into the inferior.
248 If REGNO is negative, do this for all registers.
249 Otherwise, REGNO specifies which register (so we can save time). */
250
251 void
252 old_store_inferior_registers (int regno)
253 {
254 if (regno >= 0)
255 {
256 store_register (regno);
257 }
258 else
259 {
260 for (regno = 0; regno < ARCH_NUM_REGS; regno++)
261 {
262 store_register (regno);
263 }
264 }
265 }
266 \f
267
268 /* Transfering the general-purpose registers between GDB, inferiors
269 and core files. */
270
271 /* Fill GDB's register array with the genereal-purpose register values
272 in *GREGSETP. */
273
274 void
275 supply_gregset (elf_gregset_t *gregsetp)
276 {
277 elf_greg_t *regp = (elf_greg_t *) gregsetp;
278 int i;
279
280 for (i = 0; i < NUM_GREGS; i++)
281 supply_register (i, (char *) (regp + regmap[i]));
282 }
283
284 /* Fill register REGNO (if it is a general-purpose register) in
285 *GREGSETPS with the value in GDB's register array. If REGNO is -1,
286 do this for all registers. */
287
288 void
289 fill_gregset (elf_gregset_t *gregsetp, int regno)
290 {
291 elf_greg_t *regp = (elf_greg_t *) gregsetp;
292 int i;
293
294 for (i = 0; i < NUM_GREGS; i++)
295 if ((regno == -1 || regno == i))
296 *(regp + regmap[i]) = *(elf_greg_t *) &registers[REGISTER_BYTE (i)];
297 }
298
299 #ifdef HAVE_PTRACE_GETREGS
300
301 /* Fetch all general-purpose registers from process/thread TID and
302 store their values in GDB's register array. */
303
304 static void
305 fetch_regs (int tid)
306 {
307 elf_gregset_t regs;
308
309 if (ptrace (PTRACE_GETREGS, tid, 0, (int) &regs) < 0)
310 {
311 if (errno == EIO)
312 {
313 /* The kernel we're running on doesn't support the GETREGS
314 request. Reset `have_ptrace_getregs'. */
315 have_ptrace_getregs = 0;
316 return;
317 }
318
319 perror_with_name ("Couldn't get registers");
320 }
321
322 supply_gregset (&regs);
323 }
324
325 /* Store all valid general-purpose registers in GDB's register array
326 into the process/thread specified by TID. */
327
328 static void
329 store_regs (int tid, int regno)
330 {
331 elf_gregset_t regs;
332
333 if (ptrace (PTRACE_GETREGS, tid, 0, (int) &regs) < 0)
334 perror_with_name ("Couldn't get registers");
335
336 fill_gregset (&regs, regno);
337
338 if (ptrace (PTRACE_SETREGS, tid, 0, (int) &regs) < 0)
339 perror_with_name ("Couldn't write registers");
340 }
341
342 #else
343
344 static void fetch_regs (int tid) {}
345 static void store_regs (int tid, int regno) {}
346
347 #endif
348 \f
349
350 /* Transfering floating-point registers between GDB, inferiors and cores. */
351
352 /* Fill GDB's register array with the floating-point register values in
353 *FPREGSETP. */
354
355 void
356 supply_fpregset (elf_fpregset_t *fpregsetp)
357 {
358 i387_supply_fsave ((char *) fpregsetp);
359 dummy_sse_values ();
360 }
361
362 /* Fill register REGNO (if it is a floating-point register) in
363 *FPREGSETP with the value in GDB's register array. If REGNO is -1,
364 do this for all registers. */
365
366 void
367 fill_fpregset (elf_fpregset_t *fpregsetp, int regno)
368 {
369 i387_fill_fsave ((char *) fpregsetp, regno);
370 }
371
372 #ifdef HAVE_PTRACE_GETREGS
373
374 /* Fetch all floating-point registers from process/thread TID and store
375 thier values in GDB's register array. */
376
377 static void
378 fetch_fpregs (int tid)
379 {
380 elf_fpregset_t fpregs;
381
382 if (ptrace (PTRACE_GETFPREGS, tid, 0, (int) &fpregs) < 0)
383 perror_with_name ("Couldn't get floating point status");
384
385 supply_fpregset (&fpregs);
386 }
387
388 /* Store all valid floating-point registers in GDB's register array
389 into the process/thread specified by TID. */
390
391 static void
392 store_fpregs (int tid, int regno)
393 {
394 elf_fpregset_t fpregs;
395
396 if (ptrace (PTRACE_GETFPREGS, tid, 0, (int) &fpregs) < 0)
397 perror_with_name ("Couldn't get floating point status");
398
399 fill_fpregset (&fpregs, regno);
400
401 if (ptrace (PTRACE_SETFPREGS, tid, 0, (int) &fpregs) < 0)
402 perror_with_name ("Couldn't write floating point status");
403 }
404
405 #else
406
407 static void fetch_fpregs (int tid) {}
408 static void store_fpregs (int tid, int regno) {}
409
410 #endif
411 \f
412
413 /* Transfering floating-point and SSE registers to and from GDB. */
414
415 #ifdef HAVE_PTRACE_GETFPXREGS
416
417 /* Fill GDB's register array with the floating-point and SSE register
418 values in *FPXREGSETP. */
419
420 static void
421 supply_fpxregset (elf_fpxregset_t *fpxregsetp)
422 {
423 i387_supply_fxsave ((char *) fpxregsetp);
424 }
425
426 /* Fill register REGNO (if it is a floating-point or SSE register) in
427 *FPXREGSETP with the value in GDB's register array. If REGNO is
428 -1, do this for all registers. */
429
430 static void
431 fill_fpxregset (elf_fpxregset_t *fpxregsetp, int regno)
432 {
433 i387_fill_fxsave ((char *) fpxregsetp, regno);
434 }
435
436 /* Fetch all registers covered by the PTRACE_GETFPXREGS request from
437 process/thread TID and store their values in GDB's register array.
438 Return non-zero if successful, zero otherwise. */
439
440 static int
441 fetch_fpxregs (int tid)
442 {
443 elf_fpxregset_t fpxregs;
444
445 if (! have_ptrace_getfpxregs)
446 return 0;
447
448 if (ptrace (PTRACE_GETFPXREGS, tid, 0, (int) &fpxregs) < 0)
449 {
450 if (errno == EIO)
451 {
452 have_ptrace_getfpxregs = 0;
453 return 0;
454 }
455
456 perror_with_name ("Couldn't read floating-point and SSE registers");
457 }
458
459 supply_fpxregset (&fpxregs);
460 return 1;
461 }
462
463 /* Store all valid registers in GDB's register array covered by the
464 PTRACE_SETFPXREGS request into the process/thread specified by TID.
465 Return non-zero if successful, zero otherwise. */
466
467 static int
468 store_fpxregs (int tid, int regno)
469 {
470 elf_fpxregset_t fpxregs;
471
472 if (! have_ptrace_getfpxregs)
473 return 0;
474
475 if (ptrace (PTRACE_GETFPXREGS, tid, 0, &fpxregs) == -1)
476 perror_with_name ("Couldn't read floating-point and SSE registers");
477
478 fill_fpxregset (&fpxregs, regno);
479
480 if (ptrace (PTRACE_SETFPXREGS, tid, 0, &fpxregs) == -1)
481 perror_with_name ("Couldn't write floating-point and SSE registers");
482
483 return 1;
484 }
485
486 /* Fill the XMM registers in the register array with dummy values. For
487 cases where we don't have access to the XMM registers. I think
488 this is cleaner than printing a warning. For a cleaner solution,
489 we should gdbarchify the i386 family. */
490
491 static void
492 dummy_sse_values (void)
493 {
494 /* C doesn't have a syntax for NaN's, so write it out as an array of
495 longs. */
496 static long dummy[4] = { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff };
497 static long mxcsr = 0x1f80;
498 int reg;
499
500 for (reg = 0; reg < 8; reg++)
501 supply_register (XMM0_REGNUM + reg, (char *) dummy);
502 supply_register (MXCSR_REGNUM, (char *) &mxcsr);
503 }
504
505 #else
506
507 static int fetch_fpxregs (int tid) { return 0; }
508 static int store_fpxregs (int tid, int regno) { return 0; }
509 static void dummy_sse_values (void) {}
510
511 #endif /* HAVE_PTRACE_GETFPXREGS */
512 \f
513
514 /* Transferring arbitrary registers between GDB and inferior. */
515
516 /* Fetch register REGNO from the child process. If REGNO is -1, do
517 this for all registers (including the floating point and SSE
518 registers). */
519
520 void
521 fetch_inferior_registers (int regno)
522 {
523 int tid;
524
525 /* Use the old method of peeking around in `struct user' if the
526 GETREGS request isn't available. */
527 if (! have_ptrace_getregs)
528 {
529 old_fetch_inferior_registers (regno);
530 return;
531 }
532
533 /* Linux LWP ID's are process ID's. */
534 if ((tid = TIDGET (inferior_pid)) == 0)
535 tid = inferior_pid; /* Not a threaded program. */
536
537 /* Use the PTRACE_GETFPXREGS request whenever possible, since it
538 transfers more registers in one system call, and we'll cache the
539 results. But remember that fetch_fpxregs can fail, and return
540 zero. */
541 if (regno == -1)
542 {
543 fetch_regs (tid);
544
545 /* The call above might reset `have_ptrace_getregs'. */
546 if (! have_ptrace_getregs)
547 {
548 old_fetch_inferior_registers (-1);
549 return;
550 }
551
552 if (fetch_fpxregs (tid))
553 return;
554 fetch_fpregs (tid);
555 return;
556 }
557
558 if (GETREGS_SUPPLIES (regno))
559 {
560 fetch_regs (tid);
561 return;
562 }
563
564 if (GETFPXREGS_SUPPLIES (regno))
565 {
566 if (fetch_fpxregs (tid))
567 return;
568
569 /* Either our processor or our kernel doesn't support the SSE
570 registers, so read the FP registers in the traditional way,
571 and fill the SSE registers with dummy values. It would be
572 more graceful to handle differences in the register set using
573 gdbarch. Until then, this will at least make things work
574 plausibly. */
575 fetch_fpregs (tid);
576 return;
577 }
578
579 internal_error ("Got request for bad register number %d.", regno);
580 }
581
582 /* Store register REGNO back into the child process. If REGNO is -1,
583 do this for all registers (including the floating point and SSE
584 registers). */
585 void
586 store_inferior_registers (int regno)
587 {
588 int tid;
589
590 /* Use the old method of poking around in `struct user' if the
591 SETREGS request isn't available. */
592 if (! have_ptrace_getregs)
593 {
594 old_store_inferior_registers (regno);
595 return;
596 }
597
598 /* Linux LWP ID's are process ID's. */
599 if ((tid = TIDGET (inferior_pid)) == 0)
600 tid = inferior_pid; /* Not a threaded program. */
601
602 /* Use the PTRACE_SETFPXREGS requests whenever possible, since it
603 transfers more registers in one system call. But remember that
604 store_fpxregs can fail, and return zero. */
605 if (regno == -1)
606 {
607 store_regs (tid, regno);
608 if (store_fpxregs (tid, regno))
609 return;
610 store_fpregs (tid, regno);
611 return;
612 }
613
614 if (GETREGS_SUPPLIES (regno))
615 {
616 store_regs (tid, regno);
617 return;
618 }
619
620 if (GETFPXREGS_SUPPLIES (regno))
621 {
622 if (store_fpxregs (tid, regno))
623 return;
624
625 /* Either our processor or our kernel doesn't support the SSE
626 registers, so just write the FP registers in the traditional
627 way. */
628 store_fpregs (tid, regno);
629 return;
630 }
631
632 internal_error ("Got request to store bad register number %d.", regno);
633 }
634 \f
635
636 /* Interpreting register set info found in core files. */
637
638 /* Provide registers to GDB from a core file.
639
640 (We can't use the generic version of this function in
641 core-regset.c, because Linux has *three* different kinds of
642 register set notes. core-regset.c would have to call
643 supply_fpxregset, which most platforms don't have.)
644
645 CORE_REG_SECT points to an array of bytes, which are the contents
646 of a `note' from a core file which BFD thinks might contain
647 register contents. CORE_REG_SIZE is its size.
648
649 WHICH says which register set corelow suspects this is:
650 0 --- the general-purpose register set, in elf_gregset_t format
651 2 --- the floating-point register set, in elf_fpregset_t format
652 3 --- the extended floating-point register set, in elf_fpxregset_t format
653
654 REG_ADDR isn't used on Linux. */
655
656 static void
657 fetch_core_registers (char *core_reg_sect, unsigned core_reg_size,
658 int which, CORE_ADDR reg_addr)
659 {
660 elf_gregset_t gregset;
661 elf_fpregset_t fpregset;
662
663 switch (which)
664 {
665 case 0:
666 if (core_reg_size != sizeof (gregset))
667 warning ("Wrong size gregset in core file.");
668 else
669 {
670 memcpy (&gregset, core_reg_sect, sizeof (gregset));
671 supply_gregset (&gregset);
672 }
673 break;
674
675 case 2:
676 if (core_reg_size != sizeof (fpregset))
677 warning ("Wrong size fpregset in core file.");
678 else
679 {
680 memcpy (&fpregset, core_reg_sect, sizeof (fpregset));
681 supply_fpregset (&fpregset);
682 }
683 break;
684
685 #ifdef HAVE_PTRACE_GETFPXREGS
686 {
687 elf_fpxregset_t fpxregset;
688
689 case 3:
690 if (core_reg_size != sizeof (fpxregset))
691 warning ("Wrong size fpxregset in core file.");
692 else
693 {
694 memcpy (&fpxregset, core_reg_sect, sizeof (fpxregset));
695 supply_fpxregset (&fpxregset);
696 }
697 break;
698 }
699 #endif
700
701 default:
702 /* We've covered all the kinds of registers we know about here,
703 so this must be something we wouldn't know what to do with
704 anyway. Just ignore it. */
705 break;
706 }
707 }
708 \f
709
710 /* The instruction for a Linux system call is:
711 int $0x80
712 or 0xcd 0x80. */
713
714 static const unsigned char linux_syscall[] = { 0xcd, 0x80 };
715
716 #define LINUX_SYSCALL_LEN (sizeof linux_syscall)
717
718 /* The system call number is stored in the %eax register. */
719 #define LINUX_SYSCALL_REGNUM 0 /* %eax */
720
721 /* We are specifically interested in the sigreturn and rt_sigreturn
722 system calls. */
723
724 #ifndef SYS_sigreturn
725 #define SYS_sigreturn 0x77
726 #endif
727 #ifndef SYS_rt_sigreturn
728 #define SYS_rt_sigreturn 0xad
729 #endif
730
731 /* Offset to saved processor flags, from <asm/sigcontext.h>. */
732 #define LINUX_SIGCONTEXT_EFLAGS_OFFSET (64)
733
734 /* Resume execution of the inferior process.
735 If STEP is nonzero, single-step it.
736 If SIGNAL is nonzero, give it that signal. */
737
738 void
739 child_resume (int pid, int step, enum target_signal signal)
740 {
741 int request = PTRACE_CONT;
742
743 if (pid == -1)
744 /* Resume all threads. */
745 /* I think this only gets used in the non-threaded case, where "resume
746 all threads" and "resume inferior_pid" are the same. */
747 pid = inferior_pid;
748
749 if (step)
750 {
751 CORE_ADDR pc = read_pc_pid (pid);
752 unsigned char buf[LINUX_SYSCALL_LEN];
753
754 request = PTRACE_SINGLESTEP;
755
756 /* Returning from a signal trampoline is done by calling a
757 special system call (sigreturn or rt_sigreturn, see
758 i386-linux-tdep.c for more information). This system call
759 restores the registers that were saved when the signal was
760 raised, including %eflags. That means that single-stepping
761 won't work. Instead, we'll have to modify the signal context
762 that's about to be restored, and set the trace flag there. */
763
764 /* First check if PC is at a system call. */
765 if (read_memory_nobpt (pc, (char *) buf, LINUX_SYSCALL_LEN) == 0
766 && memcmp (buf, linux_syscall, LINUX_SYSCALL_LEN) == 0)
767 {
768 int syscall = read_register_pid (LINUX_SYSCALL_REGNUM, pid);
769
770 /* Then check the system call number. */
771 if (syscall == SYS_sigreturn || syscall == SYS_rt_sigreturn)
772 {
773 CORE_ADDR sp = read_register (SP_REGNUM);
774 CORE_ADDR addr = sp;
775 unsigned long int eflags;
776
777 if (syscall == SYS_rt_sigreturn)
778 addr = read_memory_integer (sp + 8, 4) + 20;
779
780 /* Set the trace flag in the context that's about to be
781 restored. */
782 addr += LINUX_SIGCONTEXT_EFLAGS_OFFSET;
783 read_memory (addr, (char *) &eflags, 4);
784 eflags |= 0x0100;
785 write_memory (addr, (char *) &eflags, 4);
786 }
787 }
788 }
789
790 if (ptrace (request, pid, 0, target_signal_to_host (signal)) == -1)
791 perror_with_name ("ptrace");
792 }
793 \f
794
795 /* Register that we are able to handle Linux ELF core file formats. */
796
797 static struct core_fns linux_elf_core_fns =
798 {
799 bfd_target_elf_flavour, /* core_flavour */
800 default_check_format, /* check_format */
801 default_core_sniffer, /* core_sniffer */
802 fetch_core_registers, /* core_read_registers */
803 NULL /* next */
804 };
805
806 void
807 _initialize_i386_linux_nat (void)
808 {
809 add_core_fns (&linux_elf_core_fns);
810 }
This page took 0.049395 seconds and 4 git commands to generate.