* i386-linux-nat.c (i386_linux_saved_pc_after_call): Lost in the
[deliverable/binutils-gdb.git] / gdb / i386-linux-nat.c
CommitLineData
d4f3574e
SS
1/* Native-dependent code for Linux running on i386's, for GDB.
2
04cd15b6 3 This file is part of GDB.
d4f3574e 4
04cd15b6
MK
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
d4f3574e 9
04cd15b6
MK
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
d4f3574e 14
04cd15b6
MK
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. */
d4f3574e
SS
19
20#include "defs.h"
21#include "inferior.h"
22#include "gdbcore.h"
23
04cd15b6 24/* For i386_linux_skip_solib_resolver. */
d4f3574e
SS
25#include "symtab.h"
26#include "frame.h"
27#include "symfile.h"
28#include "objfiles.h"
29
30#include <sys/ptrace.h>
31#include <sys/user.h>
32#include <sys/procfs.h>
33
34#ifdef HAVE_SYS_REG_H
35#include <sys/reg.h>
36#endif
37
04cd15b6
MK
38/* On Linux, threads are implemented as pseudo-processes, in which
39 case we may be tracing more than one process at a time. In that
40 case, inferior_pid will contain the main process ID and the
41 individual thread (process) ID mashed together. These macros are
42 used to separate them out. These definitions should be overridden
43 if thread support is included. */
ed9a39eb
JM
44
45#if !defined (PIDGET) /* Default definition for PIDGET/TIDGET. */
46#define PIDGET(PID) PID
47#define TIDGET(PID) 0
48#endif
49
d4f3574e 50
04cd15b6
MK
51/* The register sets used in Linux ELF core-dumps are identical to the
52 register sets in `struct user' that is used for a.out core-dumps,
53 and is also used by `ptrace'. The corresponding types are
54 `elf_gregset_t' for the general-purpose registers (with
55 `elf_greg_t' the type of a single GP register) and `elf_fpregset_t'
56 for the floating-point registers.
57
58 Those types used to be available under the names `gregset_t' and
59 `fpregset_t' too, and this file used those names in the past. But
60 those names are now used for the register sets used in the
61 `mcontext_t' type, and have a different size and layout. */
62
63/* Mapping between the general-purpose registers in `struct user'
64 format and GDB's register array layout. */
d4f3574e
SS
65static int regmap[] =
66{
67 EAX, ECX, EDX, EBX,
68 UESP, EBP, ESI, EDI,
69 EIP, EFL, CS, SS,
04cd15b6 70 DS, ES, FS, GS
d4f3574e
SS
71};
72
5c44784c
JM
73/* Which ptrace request retrieves which registers?
74 These apply to the corresponding SET requests as well. */
75#define GETREGS_SUPPLIES(regno) \
76 (0 <= (regno) && (regno) <= 15)
77#define GETFPREGS_SUPPLIES(regno) \
78 (FP0_REGNUM <= (regno) && (regno) <= LAST_FPU_CTRL_REGNUM)
79#define GETXFPREGS_SUPPLIES(regno) \
80 (FP0_REGNUM <= (regno) && (regno) <= MXCSR_REGNUM)
81
f60300e7
MK
82/* Does the current host support the GETREGS request? */
83int have_ptrace_getregs =
84#ifdef HAVE_PTRACE_GETREGS
85 1
86#else
87 0
88#endif
89;
90
5c44784c
JM
91/* Does the current host support the GETXFPREGS request? The header
92 file may or may not define it, and even if it is defined, the
93 kernel will return EIO if it's running on a pre-SSE processor.
94
c2d11a7d
JM
95 PTRACE_GETXFPREGS is a Cygnus invention, since we wrote our own
96 Linux kernel patch for SSE support. That patch may or may not
97 actually make it into the official distribution. If you find that
98 years have gone by since this stuff was added, and Linux isn't
99 using PTRACE_GETXFPREGS, that means that our patch didn't make it,
100 and you can delete this, and the related code.
101
5c44784c
JM
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. */
106int have_ptrace_getxfpregs =
107#ifdef HAVE_PTRACE_GETXFPREGS
108 1
109#else
110 0
111#endif
112;
113
f60300e7 114\f
97780f5f
JB
115/* Fetching registers directly from the U area, one at a time. */
116
f60300e7
MK
117/* FIXME: kettenis/2000-03-05: This duplicates code from `inptrace.c'.
118 The problem is that we define FETCH_INFERIOR_REGISTERS since we
119 want to use our own versions of {fetch,store}_inferior_registers
120 that use the GETREGS request. This means that the code in
121 `infptrace.c' is #ifdef'd out. But we need to fall back on that
122 code when GDB is running on top of a kernel that doesn't support
123 the GETREGS request. I want to avoid changing `infptrace.c' right
124 now. */
125
126/* Default the type of the ptrace transfer to int. */
127#ifndef PTRACE_XFER_TYPE
128#define PTRACE_XFER_TYPE int
129#endif
130
131/* Registers we shouldn't try to fetch. */
132#if !defined (CANNOT_FETCH_REGISTER)
133#define CANNOT_FETCH_REGISTER(regno) 0
134#endif
135
136/* Fetch one register. */
137
138static void
139fetch_register (regno)
140 int regno;
141{
142 /* This isn't really an address. But ptrace thinks of it as one. */
143 CORE_ADDR regaddr;
144 char mess[128]; /* For messages */
145 register int i;
146 unsigned int offset; /* Offset of registers within the u area. */
147 char buf[MAX_REGISTER_RAW_SIZE];
148 int tid;
149
150 if (CANNOT_FETCH_REGISTER (regno))
151 {
152 memset (buf, '\0', REGISTER_RAW_SIZE (regno)); /* Supply zeroes */
153 supply_register (regno, buf);
154 return;
155 }
156
157 /* Overload thread id onto process id */
158 if ((tid = TIDGET (inferior_pid)) == 0)
159 tid = inferior_pid; /* no thread id, just use process id */
160
161 offset = U_REGS_OFFSET;
162
163 regaddr = register_addr (regno, offset);
164 for (i = 0; i < REGISTER_RAW_SIZE (regno); i += sizeof (PTRACE_XFER_TYPE))
165 {
166 errno = 0;
167 *(PTRACE_XFER_TYPE *) & buf[i] = ptrace (PT_READ_U, tid,
168 (PTRACE_ARG3_TYPE) regaddr, 0);
169 regaddr += sizeof (PTRACE_XFER_TYPE);
170 if (errno != 0)
171 {
172 sprintf (mess, "reading register %s (#%d)",
173 REGISTER_NAME (regno), regno);
174 perror_with_name (mess);
175 }
176 }
177 supply_register (regno, buf);
178}
179
180/* Fetch register values from the inferior.
181 If REGNO is negative, do this for all registers.
182 Otherwise, REGNO specifies which register (so we can save time). */
183
184void
185old_fetch_inferior_registers (regno)
186 int regno;
187{
188 if (regno >= 0)
189 {
190 fetch_register (regno);
191 }
192 else
193 {
194 for (regno = 0; regno < ARCH_NUM_REGS; regno++)
195 {
196 fetch_register (regno);
197 }
198 }
199}
200
201/* Registers we shouldn't try to store. */
202#if !defined (CANNOT_STORE_REGISTER)
203#define CANNOT_STORE_REGISTER(regno) 0
204#endif
205
206/* Store one register. */
207
208static void
209store_register (regno)
210 int regno;
211{
212 /* This isn't really an address. But ptrace thinks of it as one. */
213 CORE_ADDR regaddr;
214 char mess[128]; /* For messages */
215 register int i;
216 unsigned int offset; /* Offset of registers within the u area. */
217 int tid;
218
219 if (CANNOT_STORE_REGISTER (regno))
220 {
221 return;
222 }
223
224 /* Overload thread id onto process id */
225 if ((tid = TIDGET (inferior_pid)) == 0)
226 tid = inferior_pid; /* no thread id, just use process id */
227
228 offset = U_REGS_OFFSET;
229
230 regaddr = register_addr (regno, offset);
231 for (i = 0; i < REGISTER_RAW_SIZE (regno); i += sizeof (PTRACE_XFER_TYPE))
232 {
233 errno = 0;
234 ptrace (PT_WRITE_U, tid, (PTRACE_ARG3_TYPE) regaddr,
235 *(PTRACE_XFER_TYPE *) & registers[REGISTER_BYTE (regno) + i]);
236 regaddr += sizeof (PTRACE_XFER_TYPE);
237 if (errno != 0)
238 {
239 sprintf (mess, "writing register %s (#%d)",
240 REGISTER_NAME (regno), regno);
241 perror_with_name (mess);
242 }
243 }
244}
245
246/* Store our register values back into the inferior.
247 If REGNO is negative, do this for all registers.
248 Otherwise, REGNO specifies which register (so we can save time). */
249
250void
251old_store_inferior_registers (regno)
252 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
5c44784c 267\f
04cd15b6
MK
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. */
5c44784c 273
d4f3574e 274void
04cd15b6 275supply_gregset (elf_gregset_t *gregsetp)
d4f3574e 276{
04cd15b6
MK
277 elf_greg_t *regp = (elf_greg_t *) gregsetp;
278 int regi;
d4f3574e 279
917317f4 280 for (regi = 0; regi < NUM_GREGS; regi++)
04cd15b6 281 supply_register (regi, (char *) (regp + regmap[regi]));
d4f3574e
SS
282}
283
04cd15b6
MK
284/* Convert the valid general-purpose register values in GDB's register
285 array to `struct user' format and store them in *GREGSETP. The
286 array VALID indicates which register values are valid. If VALID is
287 NULL, all registers are assumed to be valid. */
5c44784c 288
04cd15b6
MK
289static void
290convert_to_gregset (elf_gregset_t *gregsetp, signed char *valid)
d4f3574e 291{
04cd15b6 292 elf_greg_t *regp = (elf_greg_t *) gregsetp;
d4f3574e 293 int regi;
d4f3574e 294
917317f4
JM
295 for (regi = 0; regi < NUM_GREGS; regi++)
296 if (! valid || valid[regi])
297 *(regp + regmap[regi]) = * (int *) &registers[REGISTER_BYTE (regi)];
298}
299
04cd15b6
MK
300/* Fill register REGNO (if it is a general-purpose register) in
301 *GREGSETPS with the value in GDB's register array. If REGNO is -1,
302 do this for all registers. */
917317f4 303void
04cd15b6 304fill_gregset (elf_gregset_t *gregsetp, int regno)
917317f4
JM
305{
306 if (regno == -1)
04cd15b6
MK
307 {
308 convert_to_gregset (gregsetp, NULL);
309 return;
310 }
311
312 if (GETREGS_SUPPLIES (regno))
d4f3574e 313 {
917317f4 314 signed char valid[NUM_GREGS];
04cd15b6 315
917317f4
JM
316 memset (valid, 0, sizeof (valid));
317 valid[regno] = 1;
04cd15b6
MK
318
319 convert_to_gregset (gregsetp, valid);
d4f3574e
SS
320 }
321}
322
f60300e7
MK
323#ifdef HAVE_PTRACE_GETREGS
324
04cd15b6
MK
325/* Fetch all general-purpose registers from process/thread TID and
326 store their values in GDB's register array. */
d4f3574e 327
5c44784c 328static void
ed9a39eb 329fetch_regs (int tid)
5c44784c 330{
04cd15b6
MK
331 elf_gregset_t regs;
332 int ret;
5c44784c 333
04cd15b6 334 ret = ptrace (PTRACE_GETREGS, tid, 0, (int) &regs);
5c44784c
JM
335 if (ret < 0)
336 {
f60300e7
MK
337 if (errno == EIO)
338 {
339 /* The kernel we're running on doesn't support the GETREGS
340 request. Reset `have_ptrace_getregs'. */
341 have_ptrace_getregs = 0;
342 return;
343 }
344
04cd15b6 345 warning ("Couldn't get registers.");
5c44784c
JM
346 return;
347 }
348
04cd15b6 349 supply_gregset (&regs);
5c44784c
JM
350}
351
04cd15b6
MK
352/* Store all valid general-purpose registers in GDB's register array
353 into the process/thread specified by TID. */
5c44784c 354
5c44784c 355static void
ed9a39eb 356store_regs (int tid)
5c44784c 357{
04cd15b6
MK
358 elf_gregset_t regs;
359 int ret;
5c44784c 360
04cd15b6 361 ret = ptrace (PTRACE_GETREGS, tid, 0, (int) &regs);
5c44784c
JM
362 if (ret < 0)
363 {
04cd15b6 364 warning ("Couldn't get registers.");
5c44784c
JM
365 return;
366 }
367
04cd15b6 368 convert_to_gregset (&regs, register_valid);
5c44784c 369
04cd15b6 370 ret = ptrace (PTRACE_SETREGS, tid, 0, (int) &regs);
5c44784c
JM
371 if (ret < 0)
372 {
04cd15b6 373 warning ("Couldn't write registers.");
5c44784c
JM
374 return;
375 }
376}
377
f60300e7
MK
378#else
379
380static void fetch_regs (int tid) {}
381static void store_regs (int tid) {}
382
383#endif
384
5c44784c
JM
385\f
386/* Transfering floating-point registers between GDB, inferiors and cores. */
387
04cd15b6
MK
388/* What is the address of st(N) within the floating-point register set F? */
389#define FPREG_ADDR(f, n) ((char *) &(f)->st_space + (n) * 10)
d4f3574e 390
04cd15b6 391/* Fill GDB's register array with the floating-point register values in
917317f4 392 *FPREGSETP. */
04cd15b6 393
d4f3574e 394void
04cd15b6 395supply_fpregset (elf_fpregset_t *fpregsetp)
d4f3574e 396{
04cd15b6 397 int reg;
b948cda9 398 long l;
917317f4
JM
399
400 /* Supply the floating-point registers. */
04cd15b6
MK
401 for (reg = 0; reg < 8; reg++)
402 supply_register (FP0_REGNUM + reg, FPREG_ADDR (fpregsetp, reg));
917317f4 403
b948cda9
MK
404 /* We have to mask off the reserved bits in *FPREGSETP before
405 storing the values in GDB's register file. */
406#define supply(REGNO, MEMBER) \
407 l = fpregsetp->MEMBER & 0xffff; \
408 supply_register (REGNO, (char *) &l)
409
410 supply (FCTRL_REGNUM, cwd);
411 supply (FSTAT_REGNUM, swd);
412 supply (FTAG_REGNUM, twd);
917317f4 413 supply_register (FCOFF_REGNUM, (char *) &fpregsetp->fip);
b948cda9 414 supply (FDS_REGNUM, fos);
917317f4 415 supply_register (FDOFF_REGNUM, (char *) &fpregsetp->foo);
917317f4 416
b948cda9
MK
417#undef supply
418
419 /* Extract the code segment and opcode from the "fcs" member. */
420 l = fpregsetp->fcs & 0xffff;
421 supply_register (FCS_REGNUM, (char *) &l);
917317f4 422
b948cda9
MK
423 l = (fpregsetp->fcs >> 16) & ((1 << 11) - 1);
424 supply_register (FOP_REGNUM, (char *) &l);
d4f3574e
SS
425}
426
04cd15b6
MK
427/* Convert the valid floating-point register values in GDB's register
428 array to `struct user' format and store them in *FPREGSETP. The
429 array VALID indicates which register values are valid. If VALID is
430 NULL, all registers are assumed to be valid. */
d4f3574e 431
04cd15b6
MK
432static void
433convert_to_fpregset (elf_fpregset_t *fpregsetp, signed char *valid)
d4f3574e 434{
04cd15b6 435 int reg;
917317f4
JM
436
437 /* Fill in the floating-point registers. */
04cd15b6
MK
438 for (reg = 0; reg < 8; reg++)
439 if (!valid || valid[reg])
440 memcpy (FPREG_ADDR (fpregsetp, reg),
441 &registers[REGISTER_BYTE (FP0_REGNUM + reg)],
442 REGISTER_RAW_SIZE(FP0_REGNUM + reg));
917317f4 443
b948cda9
MK
444 /* We're not supposed to touch the reserved bits in *FPREGSETP. */
445
917317f4
JM
446#define fill(MEMBER, REGNO) \
447 if (! valid || valid[(REGNO)]) \
b948cda9
MK
448 fpregsetp->MEMBER \
449 = ((fpregsetp->MEMBER & ~0xffff) \
450 | (* (int *) &registers[REGISTER_BYTE (REGNO)] & 0xffff))
451
452#define fill_register(MEMBER, REGNO) \
453 if (! valid || valid[(REGNO)]) \
454 memcpy (&fpregsetp->MEMBER, &registers[REGISTER_BYTE (REGNO)], \
455 sizeof (fpregsetp->MEMBER))
917317f4
JM
456
457 fill (cwd, FCTRL_REGNUM);
458 fill (swd, FSTAT_REGNUM);
459 fill (twd, FTAG_REGNUM);
b948cda9 460 fill_register (fip, FCOFF_REGNUM);
917317f4 461 fill (foo, FDOFF_REGNUM);
b948cda9 462 fill_register (fos, FDS_REGNUM);
917317f4
JM
463
464#undef fill
b948cda9 465#undef fill_register
917317f4
JM
466
467 if (! valid || valid[FCS_REGNUM])
468 fpregsetp->fcs
469 = ((fpregsetp->fcs & ~0xffff)
470 | (* (int *) &registers[REGISTER_BYTE (FCS_REGNUM)] & 0xffff));
471
472 if (! valid || valid[FOP_REGNUM])
473 fpregsetp->fcs
474 = ((fpregsetp->fcs & 0xffff)
475 | ((*(int *) &registers[REGISTER_BYTE (FOP_REGNUM)] & ((1 << 11) - 1))
476 << 16));
477}
d4f3574e 478
04cd15b6
MK
479/* Fill register REGNO (if it is a floating-point register) in
480 *FPREGSETP with the value in GDB's register array. If REGNO is -1,
481 do this for all registers. */
917317f4
JM
482
483void
04cd15b6 484fill_fpregset (elf_fpregset_t *fpregsetp, int regno)
917317f4 485{
04cd15b6
MK
486 if (regno == -1)
487 {
488 convert_to_fpregset (fpregsetp, NULL);
489 return;
490 }
491
492 if (GETFPREGS_SUPPLIES(regno))
493 {
494 signed char valid[MAX_NUM_REGS];
495
496 memset (valid, 0, sizeof (valid));
497 valid[regno] = 1;
498
499 convert_to_fpregset (fpregsetp, valid);
500 }
d4f3574e
SS
501}
502
f60300e7
MK
503#ifdef HAVE_PTRACE_GETREGS
504
04cd15b6
MK
505/* Fetch all floating-point registers from process/thread TID and store
506 thier values in GDB's register array. */
917317f4 507
d4f3574e 508static void
ed9a39eb 509fetch_fpregs (int tid)
d4f3574e 510{
04cd15b6
MK
511 elf_fpregset_t fpregs;
512 int ret;
d4f3574e 513
04cd15b6 514 ret = ptrace (PTRACE_GETFPREGS, tid, 0, (int) &fpregs);
917317f4 515 if (ret < 0)
d4f3574e 516 {
04cd15b6 517 warning ("Couldn't get floating point status.");
d4f3574e
SS
518 return;
519 }
520
04cd15b6 521 supply_fpregset (&fpregs);
d4f3574e
SS
522}
523
04cd15b6
MK
524/* Store all valid floating-point registers in GDB's register array
525 into the process/thread specified by TID. */
d4f3574e 526
d4f3574e 527static void
ed9a39eb 528store_fpregs (int tid)
d4f3574e 529{
04cd15b6 530 elf_fpregset_t fpregs;
917317f4 531 int ret;
d4f3574e 532
04cd15b6 533 ret = ptrace (PTRACE_GETFPREGS, tid, 0, (int) &fpregs);
917317f4 534 if (ret < 0)
d4f3574e 535 {
04cd15b6 536 warning ("Couldn't get floating point status.");
d4f3574e
SS
537 return;
538 }
539
04cd15b6 540 convert_to_fpregset (&fpregs, register_valid);
d4f3574e 541
04cd15b6 542 ret = ptrace (PTRACE_SETFPREGS, tid, 0, (int) &fpregs);
917317f4 543 if (ret < 0)
d4f3574e 544 {
04cd15b6 545 warning ("Couldn't write floating point status.");
d4f3574e
SS
546 return;
547 }
d4f3574e
SS
548}
549
f60300e7
MK
550#else
551
552static void fetch_fpregs (int tid) {}
553static void store_fpregs (int tid) {}
554
555#endif
556
5c44784c
JM
557\f
558/* Transfering floating-point and SSE registers to and from GDB. */
d4f3574e 559
11cf8741
JM
560/* PTRACE_GETXFPREGS is a Cygnus invention, since we wrote our own
561 Linux kernel patch for SSE support. That patch may or may not
562 actually make it into the official distribution. If you find that
563 years have gone by since this code was added, and Linux isn't using
564 PTRACE_GETXFPREGS, that means that our patch didn't make it, and
565 you can delete this code. */
566
5c44784c 567#ifdef HAVE_PTRACE_GETXFPREGS
04cd15b6
MK
568
569/* Fill GDB's register array with the floating-point and SSE register
570 values in *XFPREGS. */
571
d4f3574e 572static void
5c44784c 573supply_xfpregset (struct user_xfpregs_struct *xfpregs)
d4f3574e 574{
5c44784c 575 int reg;
d4f3574e 576
5c44784c
JM
577 /* Supply the floating-point registers. */
578 for (reg = 0; reg < 8; reg++)
579 supply_register (FP0_REGNUM + reg, (char *) &xfpregs->st_space[reg]);
580
581 {
582 supply_register (FCTRL_REGNUM, (char *) &xfpregs->cwd);
583 supply_register (FSTAT_REGNUM, (char *) &xfpregs->swd);
584 supply_register (FTAG_REGNUM, (char *) &xfpregs->twd);
585 supply_register (FCOFF_REGNUM, (char *) &xfpregs->fip);
586 supply_register (FDS_REGNUM, (char *) &xfpregs->fos);
587 supply_register (FDOFF_REGNUM, (char *) &xfpregs->foo);
588
589 /* Extract the code segment and opcode from the "fcs" member. */
d4f3574e 590 {
5c44784c
JM
591 long l;
592
593 l = xfpregs->fcs & 0xffff;
594 supply_register (FCS_REGNUM, (char *) &l);
595
596 l = (xfpregs->fcs >> 16) & ((1 << 11) - 1);
597 supply_register (FOP_REGNUM, (char *) &l);
d4f3574e 598 }
5c44784c 599 }
d4f3574e 600
5c44784c
JM
601 /* Supply the SSE registers. */
602 for (reg = 0; reg < 8; reg++)
603 supply_register (XMM0_REGNUM + reg, (char *) &xfpregs->xmm_space[reg]);
604 supply_register (MXCSR_REGNUM, (char *) &xfpregs->mxcsr);
d4f3574e
SS
605}
606
04cd15b6
MK
607/* Convert the valid floating-point and SSE registers in GDB's
608 register array to `struct user' format and store them in *XFPREGS.
609 The array VALID indicates which registers are valid. If VALID is
610 NULL, all registers are assumed to be valid. */
d4f3574e 611
d4f3574e 612static void
5c44784c 613convert_to_xfpregset (struct user_xfpregs_struct *xfpregs,
5c44784c 614 signed char *valid)
d4f3574e 615{
5c44784c 616 int reg;
d4f3574e 617
5c44784c
JM
618 /* Fill in the floating-point registers. */
619 for (reg = 0; reg < 8; reg++)
620 if (!valid || valid[reg])
621 memcpy (&xfpregs->st_space[reg],
622 &registers[REGISTER_BYTE (FP0_REGNUM + reg)],
623 REGISTER_RAW_SIZE(FP0_REGNUM + reg));
624
625#define fill(MEMBER, REGNO) \
626 if (! valid || valid[(REGNO)]) \
627 memcpy (&xfpregs->MEMBER, &registers[REGISTER_BYTE (REGNO)], \
628 sizeof (xfpregs->MEMBER))
629
630 fill (cwd, FCTRL_REGNUM);
631 fill (swd, FSTAT_REGNUM);
632 fill (twd, FTAG_REGNUM);
633 fill (fip, FCOFF_REGNUM);
634 fill (foo, FDOFF_REGNUM);
635 fill (fos, FDS_REGNUM);
636
637#undef fill
638
639 if (! valid || valid[FCS_REGNUM])
640 xfpregs->fcs
641 = ((xfpregs->fcs & ~0xffff)
642 | (* (int *) &registers[REGISTER_BYTE (FCS_REGNUM)] & 0xffff));
643
644 if (! valid || valid[FOP_REGNUM])
645 xfpregs->fcs
646 = ((xfpregs->fcs & 0xffff)
647 | ((*(int *) &registers[REGISTER_BYTE (FOP_REGNUM)] & ((1 << 11) - 1))
648 << 16));
649
650 /* Fill in the XMM registers. */
651 for (reg = 0; reg < 8; reg++)
652 if (! valid || valid[reg])
653 memcpy (&xfpregs->xmm_space[reg],
654 &registers[REGISTER_BYTE (XMM0_REGNUM + reg)],
655 REGISTER_RAW_SIZE (XMM0_REGNUM + reg));
656}
657
04cd15b6
MK
658/* Fetch all registers covered by the PTRACE_SETXFPREGS request from
659 process/thread TID and store their values in GDB's register array.
660 Return non-zero if successful, zero otherwise. */
5c44784c 661
5c44784c 662static int
ed9a39eb 663fetch_xfpregs (int tid)
5c44784c 664{
5c44784c 665 struct user_xfpregs_struct xfpregs;
04cd15b6 666 int ret;
5c44784c
JM
667
668 if (! have_ptrace_getxfpregs)
669 return 0;
670
ed9a39eb 671 ret = ptrace (PTRACE_GETXFPREGS, tid, 0, &xfpregs);
5c44784c 672 if (ret == -1)
d4f3574e 673 {
5c44784c
JM
674 if (errno == EIO)
675 {
676 have_ptrace_getxfpregs = 0;
677 return 0;
678 }
679
04cd15b6 680 warning ("Couldn't read floating-point and SSE registers.");
5c44784c 681 return 0;
d4f3574e
SS
682 }
683
5c44784c
JM
684 supply_xfpregset (&xfpregs);
685 return 1;
686}
d4f3574e 687
04cd15b6
MK
688/* Store all valid registers in GDB's register array covered by the
689 PTRACE_SETXFPREGS request into the process/thread specified by TID.
690 Return non-zero if successful, zero otherwise. */
5c44784c 691
5c44784c 692static int
ed9a39eb 693store_xfpregs (int tid)
5c44784c 694{
5c44784c 695 struct user_xfpregs_struct xfpregs;
04cd15b6 696 int ret;
5c44784c
JM
697
698 if (! have_ptrace_getxfpregs)
699 return 0;
700
ed9a39eb 701 ret = ptrace (PTRACE_GETXFPREGS, tid, 0, &xfpregs);
5c44784c 702 if (ret == -1)
d4f3574e 703 {
5c44784c
JM
704 if (errno == EIO)
705 {
706 have_ptrace_getxfpregs = 0;
707 return 0;
708 }
709
04cd15b6 710 warning ("Couldn't read floating-point and SSE registers.");
5c44784c
JM
711 return 0;
712 }
713
04cd15b6 714 convert_to_xfpregset (&xfpregs, register_valid);
5c44784c 715
ed9a39eb 716 if (ptrace (PTRACE_SETXFPREGS, tid, 0, &xfpregs) < 0)
5c44784c
JM
717 {
718 warning ("Couldn't write floating-point and SSE registers.");
719 return 0;
d4f3574e 720 }
5c44784c
JM
721
722 return 1;
723}
724
04cd15b6 725/* Fill the XMM registers in the register array with dummy values. For
5c44784c
JM
726 cases where we don't have access to the XMM registers. I think
727 this is cleaner than printing a warning. For a cleaner solution,
728 we should gdbarchify the i386 family. */
04cd15b6 729
5c44784c 730static void
04cd15b6 731dummy_sse_values (void)
5c44784c
JM
732{
733 /* C doesn't have a syntax for NaN's, so write it out as an array of
734 longs. */
735 static long dummy[4] = { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff };
736 static long mxcsr = 0x1f80;
737 int reg;
738
739 for (reg = 0; reg < 8; reg++)
740 supply_register (XMM0_REGNUM + reg, (char *) dummy);
741 supply_register (MXCSR_REGNUM, (char *) &mxcsr);
d4f3574e
SS
742}
743
5c44784c
JM
744#else
745
746/* Stub versions of the above routines, for systems that don't have
747 PTRACE_GETXFPREGS. */
ed9a39eb
JM
748static int store_xfpregs (int tid) { return 0; }
749static int fetch_xfpregs (int tid) { return 0; }
04cd15b6 750static void dummy_sse_values (void) {}
5c44784c
JM
751
752#endif
753
754\f
755/* Transferring arbitrary registers between GDB and inferior. */
d4f3574e 756
04cd15b6
MK
757/* Fetch register REGNO from the child process. If REGNO is -1, do
758 this for all registers (including the floating point and SSE
759 registers). */
d4f3574e
SS
760
761void
917317f4 762fetch_inferior_registers (int regno)
d4f3574e 763{
ed9a39eb
JM
764 int tid;
765
f60300e7
MK
766 /* Use the old method of peeking around in `struct user' if the
767 GETREGS request isn't available. */
768 if (! have_ptrace_getregs)
769 {
770 old_fetch_inferior_registers (regno);
771 return;
772 }
773
04cd15b6 774 /* Linux LWP ID's are process ID's. */
ed9a39eb 775 if ((tid = TIDGET (inferior_pid)) == 0)
04cd15b6 776 tid = inferior_pid; /* Not a threaded program. */
ed9a39eb 777
04cd15b6
MK
778 /* Use the PTRACE_GETXFPREGS request whenever possible, since it
779 transfers more registers in one system call, and we'll cache the
780 results. But remember that fetch_xfpregs can fail, and return
781 zero. */
5c44784c
JM
782 if (regno == -1)
783 {
ed9a39eb 784 fetch_regs (tid);
f60300e7
MK
785
786 /* The call above might reset `have_ptrace_getregs'. */
787 if (! have_ptrace_getregs)
788 {
789 old_fetch_inferior_registers (-1);
790 return;
791 }
792
ed9a39eb 793 if (fetch_xfpregs (tid))
5c44784c 794 return;
ed9a39eb 795 fetch_fpregs (tid);
5c44784c
JM
796 return;
797 }
d4f3574e 798
5c44784c
JM
799 if (GETREGS_SUPPLIES (regno))
800 {
ed9a39eb 801 fetch_regs (tid);
5c44784c
JM
802 return;
803 }
804
805 if (GETXFPREGS_SUPPLIES (regno))
806 {
ed9a39eb 807 if (fetch_xfpregs (tid))
5c44784c
JM
808 return;
809
810 /* Either our processor or our kernel doesn't support the SSE
811 registers, so read the FP registers in the traditional way,
812 and fill the SSE registers with dummy values. It would be
813 more graceful to handle differences in the register set using
814 gdbarch. Until then, this will at least make things work
815 plausibly. */
ed9a39eb 816 fetch_fpregs (tid);
5c44784c
JM
817 dummy_sse_values ();
818 return;
819 }
820
821 internal_error ("i386-linux-nat.c (fetch_inferior_registers): "
822 "got request for bad register number %d", regno);
d4f3574e
SS
823}
824
04cd15b6
MK
825/* Store register REGNO back into the child process. If REGNO is -1,
826 do this for all registers (including the floating point and SSE
827 registers). */
d4f3574e 828void
04cd15b6 829store_inferior_registers (int regno)
d4f3574e 830{
ed9a39eb
JM
831 int tid;
832
f60300e7
MK
833 /* Use the old method of poking around in `struct user' if the
834 SETREGS request isn't available. */
835 if (! have_ptrace_getregs)
836 {
837 old_store_inferior_registers (regno);
838 return;
839 }
840
04cd15b6 841 /* Linux LWP ID's are process ID's. */
ed9a39eb 842 if ((tid = TIDGET (inferior_pid)) == 0)
04cd15b6 843 tid = inferior_pid; /* Not a threaded program. */
ed9a39eb 844
04cd15b6
MK
845 /* Use the PTRACE_SETXFPREGS requests whenever possibl, since it
846 transfers more registers in one system call. But remember that
ed9a39eb 847 store_xfpregs can fail, and return zero. */
5c44784c
JM
848 if (regno == -1)
849 {
ed9a39eb
JM
850 store_regs (tid);
851 if (store_xfpregs (tid))
5c44784c 852 return;
ed9a39eb 853 store_fpregs (tid);
5c44784c
JM
854 return;
855 }
d4f3574e 856
5c44784c
JM
857 if (GETREGS_SUPPLIES (regno))
858 {
ed9a39eb 859 store_regs (tid);
5c44784c
JM
860 return;
861 }
862
863 if (GETXFPREGS_SUPPLIES (regno))
864 {
ed9a39eb 865 if (store_xfpregs (tid))
5c44784c
JM
866 return;
867
868 /* Either our processor or our kernel doesn't support the SSE
04cd15b6
MK
869 registers, so just write the FP registers in the traditional
870 way. */
ed9a39eb 871 store_fpregs (tid);
5c44784c
JM
872 return;
873 }
874
04cd15b6 875 internal_error ("Got request to store bad register number %d.", regno);
d4f3574e
SS
876}
877
de57eccd
JM
878\f
879/* Interpreting register set info found in core files. */
880
881/* Provide registers to GDB from a core file.
882
883 (We can't use the generic version of this function in
884 core-regset.c, because Linux has *three* different kinds of
885 register set notes. core-regset.c would have to call
886 supply_xfpregset, which most platforms don't have.)
887
888 CORE_REG_SECT points to an array of bytes, which are the contents
889 of a `note' from a core file which BFD thinks might contain
890 register contents. CORE_REG_SIZE is its size.
891
892 WHICH says which register set corelow suspects this is:
04cd15b6
MK
893 0 --- the general-purpose register set, in elf_gregset_t format
894 2 --- the floating-point register set, in elf_fpregset_t format
895 3 --- the extended floating-point register set, in struct
896 user_xfpregs_struct format
897
898 REG_ADDR isn't used on Linux. */
de57eccd 899
de57eccd 900static void
04cd15b6
MK
901fetch_core_registers (char *core_reg_sect, unsigned core_reg_size,
902 int which, CORE_ADDR reg_addr)
de57eccd 903{
04cd15b6
MK
904 elf_gregset_t gregset;
905 elf_fpregset_t fpregset;
de57eccd
JM
906
907 switch (which)
908 {
909 case 0:
910 if (core_reg_size != sizeof (gregset))
04cd15b6 911 warning ("Wrong size gregset in core file.");
de57eccd
JM
912 else
913 {
914 memcpy (&gregset, core_reg_sect, sizeof (gregset));
915 supply_gregset (&gregset);
916 }
917 break;
918
919 case 2:
920 if (core_reg_size != sizeof (fpregset))
04cd15b6 921 warning ("Wrong size fpregset in core file.");
de57eccd
JM
922 else
923 {
924 memcpy (&fpregset, core_reg_sect, sizeof (fpregset));
925 supply_fpregset (&fpregset);
926 }
927 break;
928
929#ifdef HAVE_PTRACE_GETXFPREGS
930 {
931 struct user_xfpregs_struct xfpregset;
04cd15b6 932
de57eccd 933 case 3:
04cd15b6
MK
934 if (core_reg_size != sizeof (xfpregset))
935 warning ("Wrong size user_xfpregs_struct in core file.");
de57eccd
JM
936 else
937 {
938 memcpy (&xfpregset, core_reg_sect, sizeof (xfpregset));
939 supply_xfpregset (&xfpregset);
940 }
941 break;
942 }
943#endif
944
945 default:
946 /* We've covered all the kinds of registers we know about here,
947 so this must be something we wouldn't know what to do with
948 anyway. Just ignore it. */
949 break;
950 }
951}
952
5c44784c
JM
953\f
954/* Calling functions in shared libraries. */
04cd15b6
MK
955/* FIXME: kettenis/2000-03-05: Doesn't this belong in a
956 target-dependent file? The function
957 `i386_linux_skip_solib_resolver' is mentioned in
958 `config/i386/tm-linux.h'. */
5c44784c 959
d4f3574e
SS
960/* Find the minimal symbol named NAME, and return both the minsym
961 struct and its objfile. This probably ought to be in minsym.c, but
962 everything there is trying to deal with things like C++ and
963 SOFUN_ADDRESS_MAYBE_TURQUOISE, ... Since this is so simple, it may
964 be considered too special-purpose for general consumption. */
965
966static struct minimal_symbol *
967find_minsym_and_objfile (char *name, struct objfile **objfile_p)
968{
969 struct objfile *objfile;
970
971 ALL_OBJFILES (objfile)
972 {
973 struct minimal_symbol *msym;
974
975 ALL_OBJFILE_MSYMBOLS (objfile, msym)
976 {
977 if (SYMBOL_NAME (msym)
978 && STREQ (SYMBOL_NAME (msym), name))
979 {
980 *objfile_p = objfile;
981 return msym;
982 }
983 }
984 }
985
986 return 0;
987}
988
989
990static CORE_ADDR
991skip_hurd_resolver (CORE_ADDR pc)
992{
993 /* The HURD dynamic linker is part of the GNU C library, so many
994 GNU/Linux distributions use it. (All ELF versions, as far as I
995 know.) An unresolved PLT entry points to "_dl_runtime_resolve",
996 which calls "fixup" to patch the PLT, and then passes control to
997 the function.
998
999 We look for the symbol `_dl_runtime_resolve', and find `fixup' in
1000 the same objfile. If we are at the entry point of `fixup', then
1001 we set a breakpoint at the return address (at the top of the
1002 stack), and continue.
1003
1004 It's kind of gross to do all these checks every time we're
1005 called, since they don't change once the executable has gotten
1006 started. But this is only a temporary hack --- upcoming versions
1007 of Linux will provide a portable, efficient interface for
1008 debugging programs that use shared libraries. */
1009
1010 struct objfile *objfile;
1011 struct minimal_symbol *resolver
1012 = find_minsym_and_objfile ("_dl_runtime_resolve", &objfile);
1013
1014 if (resolver)
1015 {
1016 struct minimal_symbol *fixup
1017 = lookup_minimal_symbol ("fixup", 0, objfile);
1018
1019 if (fixup && SYMBOL_VALUE_ADDRESS (fixup) == pc)
1020 return (SAVED_PC_AFTER_CALL (get_current_frame ()));
1021 }
1022
1023 return 0;
1024}
1025
d4f3574e
SS
1026/* See the comments for SKIP_SOLIB_RESOLVER at the top of infrun.c.
1027 This function:
1028 1) decides whether a PLT has sent us into the linker to resolve
1029 a function reference, and
1030 2) if so, tells us where to set a temporary breakpoint that will
1031 trigger when the dynamic linker is done. */
1032
1033CORE_ADDR
1034i386_linux_skip_solib_resolver (CORE_ADDR pc)
1035{
1036 CORE_ADDR result;
1037
1038 /* Plug in functions for other kinds of resolvers here. */
1039 result = skip_hurd_resolver (pc);
1040 if (result)
1041 return result;
1042
1043 return 0;
1044}
de57eccd 1045
11708b95
JB
1046\f
1047/* Recognizing signal handler frames. */
1048
1049/* Linux has two flavors of signals. Normal signal handlers, and
1050 "realtime" (RT) signals. The RT signals can provide additional
1051 information to the signal handler if the SA_SIGINFO flag is set
1052 when establishing a signal handler using `sigaction'. It is not
1053 unlikely that future versions of Linux will support SA_SIGINFO for
1054 normal signals too. */
1055
1056/* When the i386 Linux kernel calls a signal handler and the
1057 SA_RESTORER flag isn't set, the return address points to a bit of
1058 code on the stack. This function returns whether the PC appears to
1059 be within this bit of code.
1060
1061 The instruction sequence for normal signals is
1062 pop %eax
1063 mov $0x77,%eax
1064 int $0x80
1065 or 0x58 0xb8 0x77 0x00 0x00 0x00 0xcd 0x80.
1066
1067 Checking for the code sequence should be somewhat reliable, because
1068 the effect is to call the system call sigreturn. This is unlikely
1069 to occur anywhere other than a signal trampoline.
1070
1071 It kind of sucks that we have to read memory from the process in
1072 order to identify a signal trampoline, but there doesn't seem to be
1073 any other way. The IN_SIGTRAMP macro in tm-linux.h arranges to
1074 only call us if no function name could be identified, which should
1075 be the case since the code is on the stack.
1076
1077 Detection of signal trampolines for handlers that set the
1078 SA_RESTORER flag is in general not possible. Unfortunately this is
1079 what the GNU C Library has been doing for quite some time now.
1080 However, as of version 2.1.2, the GNU C Library uses signal
1081 trampolines (named __restore and __restore_rt) that are identical
1082 to the ones used by the kernel. Therefore, these trampolines are
1083 supported too. */
1084
1085#define LINUX_SIGTRAMP_INSN0 (0x58) /* pop %eax */
1086#define LINUX_SIGTRAMP_OFFSET0 (0)
1087#define LINUX_SIGTRAMP_INSN1 (0xb8) /* mov $NNNN,%eax */
1088#define LINUX_SIGTRAMP_OFFSET1 (1)
1089#define LINUX_SIGTRAMP_INSN2 (0xcd) /* int */
1090#define LINUX_SIGTRAMP_OFFSET2 (6)
1091
1092static const unsigned char linux_sigtramp_code[] =
1093{
1094 LINUX_SIGTRAMP_INSN0, /* pop %eax */
1095 LINUX_SIGTRAMP_INSN1, 0x77, 0x00, 0x00, 0x00, /* mov $0x77,%eax */
1096 LINUX_SIGTRAMP_INSN2, 0x80 /* int $0x80 */
1097};
1098
1099#define LINUX_SIGTRAMP_LEN (sizeof linux_sigtramp_code)
1100
1101/* If PC is in a sigtramp routine, return the address of the start of
1102 the routine. Otherwise, return 0. */
1103
1104static CORE_ADDR
1105i386_linux_sigtramp_start (CORE_ADDR pc)
1106{
1107 unsigned char buf[LINUX_SIGTRAMP_LEN];
1108
1109 /* We only recognize a signal trampoline if PC is at the start of
1110 one of the three instructions. We optimize for finding the PC at
1111 the start, as will be the case when the trampoline is not the
1112 first frame on the stack. We assume that in the case where the
1113 PC is not at the start of the instruction sequence, there will be
1114 a few trailing readable bytes on the stack. */
1115
1116 if (read_memory_nobpt (pc, (char *) buf, LINUX_SIGTRAMP_LEN) != 0)
1117 return 0;
1118
1119 if (buf[0] != LINUX_SIGTRAMP_INSN0)
1120 {
1121 int adjust;
1122
1123 switch (buf[0])
1124 {
1125 case LINUX_SIGTRAMP_INSN1:
1126 adjust = LINUX_SIGTRAMP_OFFSET1;
1127 break;
1128 case LINUX_SIGTRAMP_INSN2:
1129 adjust = LINUX_SIGTRAMP_OFFSET2;
1130 break;
1131 default:
1132 return 0;
1133 }
1134
1135 pc -= adjust;
1136
1137 if (read_memory_nobpt (pc, (char *) buf, LINUX_SIGTRAMP_LEN) != 0)
1138 return 0;
1139 }
1140
1141 if (memcmp (buf, linux_sigtramp_code, LINUX_SIGTRAMP_LEN) != 0)
1142 return 0;
1143
1144 return pc;
1145}
1146
1147/* This function does the same for RT signals. Here the instruction
1148 sequence is
1149 mov $0xad,%eax
1150 int $0x80
1151 or 0xb8 0xad 0x00 0x00 0x00 0xcd 0x80.
1152
1153 The effect is to call the system call rt_sigreturn. */
1154
1155#define LINUX_RT_SIGTRAMP_INSN0 (0xb8) /* mov $NNNN,%eax */
1156#define LINUX_RT_SIGTRAMP_OFFSET0 (0)
1157#define LINUX_RT_SIGTRAMP_INSN1 (0xcd) /* int */
1158#define LINUX_RT_SIGTRAMP_OFFSET1 (5)
1159
1160static const unsigned char linux_rt_sigtramp_code[] =
1161{
1162 LINUX_RT_SIGTRAMP_INSN0, 0xad, 0x00, 0x00, 0x00, /* mov $0xad,%eax */
1163 LINUX_RT_SIGTRAMP_INSN1, 0x80 /* int $0x80 */
1164};
1165
1166#define LINUX_RT_SIGTRAMP_LEN (sizeof linux_rt_sigtramp_code)
1167
1168/* If PC is in a RT sigtramp routine, return the address of the start
1169 of the routine. Otherwise, return 0. */
1170
1171static CORE_ADDR
1172i386_linux_rt_sigtramp_start (CORE_ADDR pc)
1173{
1174 unsigned char buf[LINUX_RT_SIGTRAMP_LEN];
1175
1176 /* We only recognize a signal trampoline if PC is at the start of
1177 one of the two instructions. We optimize for finding the PC at
1178 the start, as will be the case when the trampoline is not the
1179 first frame on the stack. We assume that in the case where the
1180 PC is not at the start of the instruction sequence, there will be
1181 a few trailing readable bytes on the stack. */
1182
1183 if (read_memory_nobpt (pc, (char *) buf, LINUX_RT_SIGTRAMP_LEN) != 0)
1184 return 0;
1185
1186 if (buf[0] != LINUX_RT_SIGTRAMP_INSN0)
1187 {
1188 if (buf[0] != LINUX_RT_SIGTRAMP_INSN1)
1189 return 0;
1190
1191 pc -= LINUX_RT_SIGTRAMP_OFFSET1;
1192
1193 if (read_memory_nobpt (pc, (char *) buf, LINUX_RT_SIGTRAMP_LEN) != 0)
1194 return 0;
1195 }
1196
1197 if (memcmp (buf, linux_rt_sigtramp_code, LINUX_RT_SIGTRAMP_LEN) != 0)
1198 return 0;
1199
1200 return pc;
1201}
1202
1203/* Return whether PC is in a Linux sigtramp routine. */
1204
1205int
1206i386_linux_in_sigtramp (CORE_ADDR pc, char *name)
1207{
1208 if (name)
1209 return STREQ ("__restore", name) || STREQ ("__restore_rt", name);
1210
1211 return (i386_linux_sigtramp_start (pc) != 0
1212 || i386_linux_rt_sigtramp_start (pc) != 0);
1213}
1214
1215/* Assuming FRAME is for a Linux sigtramp routine, return the address
1216 of the associated sigcontext structure. */
1217
1218CORE_ADDR
1219i386_linux_sigcontext_addr (struct frame_info *frame)
1220{
1221 CORE_ADDR pc;
1222
1223 pc = i386_linux_sigtramp_start (frame->pc);
1224 if (pc)
1225 {
1226 CORE_ADDR sp;
1227
1228 if (frame->next)
1229 /* If this isn't the top frame, the next frame must be for the
1230 signal handler itself. The sigcontext structure lives on
1231 the stack, right after the signum argument. */
1232 return frame->next->frame + 12;
1233
1234 /* This is the top frame. We'll have to find the address of the
1235 sigcontext structure by looking at the stack pointer. Keep
1236 in mind that the first instruction of the sigtramp code is
1237 "pop %eax". If the PC is at this instruction, adjust the
1238 returned value accordingly. */
1239 sp = read_register (SP_REGNUM);
1240 if (pc == frame->pc)
1241 return sp + 4;
1242 return sp;
1243 }
1244
1245 pc = i386_linux_rt_sigtramp_start (frame->pc);
1246 if (pc)
1247 {
1248 if (frame->next)
1249 /* If this isn't the top frame, the next frame must be for the
1250 signal handler itself. The sigcontext structure is part of
1251 the user context. A pointer to the user context is passed
1252 as the third argument to the signal handler. */
1253 return read_memory_integer (frame->next->frame + 16, 4) + 20;
1254
1255 /* This is the top frame. Again, use the stack pointer to find
1256 the address of the sigcontext structure. */
1257 return read_memory_integer (read_register (SP_REGNUM) + 8, 4) + 20;
1258 }
1259
1260 error ("Couldn't recognize signal trampoline.");
1261 return 0;
1262}
1263
1264/* Offset to saved PC in sigcontext, from <asm/sigcontext.h>. */
1265#define LINUX_SIGCONTEXT_PC_OFFSET (56)
1266
1267/* Assuming FRAME is for a Linux sigtramp routine, return the saved
1268 program counter. */
1269
1270CORE_ADDR
1271i386_linux_sigtramp_saved_pc (struct frame_info *frame)
1272{
1273 CORE_ADDR addr;
1274 addr = i386_linux_sigcontext_addr (frame);
1275 return read_memory_integer (addr + LINUX_SIGCONTEXT_PC_OFFSET, 4);
1276}
1277
1278/* Offset to saved SP in sigcontext, from <asm/sigcontext.h>. */
1279#define LINUX_SIGCONTEXT_SP_OFFSET (28)
1280
1281/* Assuming FRAME is for a Linux sigtramp routine, return the saved
1282 stack pointer. */
1283
1284CORE_ADDR
1285i386_linux_sigtramp_saved_sp (struct frame_info *frame)
1286{
1287 CORE_ADDR addr;
1288 addr = i386_linux_sigcontext_addr (frame);
1289 return read_memory_integer (addr + LINUX_SIGCONTEXT_SP_OFFSET, 4);
1290}
1291
17f9defb
JB
1292/* Immediately after a function call, return the saved pc. */
1293
1294CORE_ADDR
1295i386_linux_saved_pc_after_call (struct frame_info *frame)
1296{
1297 if (frame->signal_handler_caller)
1298 return i386_linux_sigtramp_saved_pc (frame);
1299
1300 return read_memory_integer (read_register (SP_REGNUM), 4);
1301}
1302
de57eccd 1303\f
04cd15b6
MK
1304/* Register that we are able to handle Linux ELF core file formats. */
1305
1306static struct core_fns linux_elf_core_fns =
1307{
1308 bfd_target_elf_flavour, /* core_flavour */
1309 default_check_format, /* check_format */
1310 default_core_sniffer, /* core_sniffer */
1311 fetch_core_registers, /* core_read_registers */
1312 NULL /* next */
1313};
de57eccd
JM
1314
1315void
1316_initialize_i386_linux_nat ()
1317{
04cd15b6 1318 add_core_fns (&linux_elf_core_fns);
de57eccd 1319}
This page took 0.089079 seconds and 4 git commands to generate.