1 /* Native-dependent code for Linux running on i386's, for GDB.
3 This file is part of GDB.
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.
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.
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. */
24 /* For i386_linux_skip_solib_resolver. */
29 #include <sys/ptrace.h>
31 #include <sys/procfs.h>
37 /* On Linux, threads are implemented as pseudo-processes, in which
38 case we may be tracing more than one process at a time. In that
39 case, inferior_pid will contain the main process ID and the
40 individual thread (process) ID mashed together. These macros are
41 used to separate them out. These definitions should be overridden
42 if thread support is included. */
44 #if !defined (PIDGET) /* Default definition for PIDGET/TIDGET. */
45 #define PIDGET(PID) PID
50 /* The register sets used in Linux ELF core-dumps are identical to the
51 register sets in `struct user' that is used for a.out core-dumps,
52 and is also used by `ptrace'. The corresponding types are
53 `elf_gregset_t' for the general-purpose registers (with
54 `elf_greg_t' the type of a single GP register) and `elf_fpregset_t'
55 for the floating-point registers.
57 Those types used to be available under the names `gregset_t' and
58 `fpregset_t' too, and this file used those names in the past. But
59 those names are now used for the register sets used in the
60 `mcontext_t' type, and have a different size and layout. */
62 /* Mapping between the general-purpose registers in `struct user'
63 format and GDB's register array layout. */
72 /* Which ptrace request retrieves which registers?
73 These apply to the corresponding SET requests as well. */
74 #define GETREGS_SUPPLIES(regno) \
75 (0 <= (regno) && (regno) <= 15)
76 #define GETFPREGS_SUPPLIES(regno) \
77 (FP0_REGNUM <= (regno) && (regno) <= LAST_FPU_CTRL_REGNUM)
78 #define GETXFPREGS_SUPPLIES(regno) \
79 (FP0_REGNUM <= (regno) && (regno) <= MXCSR_REGNUM)
81 /* Does the current host support the GETREGS request? */
82 int have_ptrace_getregs
=
83 #ifdef HAVE_PTRACE_GETREGS
90 /* Does the current host support the GETXFPREGS request? The header
91 file may or may not define it, and even if it is defined, the
92 kernel will return EIO if it's running on a pre-SSE processor.
94 PTRACE_GETXFPREGS is a Cygnus invention, since we wrote our own
95 Linux kernel patch for SSE support. That patch may or may not
96 actually make it into the official distribution. If you find that
97 years have gone by since this stuff was added, and Linux isn't
98 using PTRACE_GETXFPREGS, that means that our patch didn't make it,
99 and you can delete this, and the related code.
101 My instinct is to attach this to some architecture- or
102 target-specific data structure, but really, a particular GDB
103 process can only run on top of one kernel at a time. So it's okay
104 for this to be a simple variable. */
105 int have_ptrace_getxfpregs
=
106 #ifdef HAVE_PTRACE_GETXFPREGS
114 /* Fetching registers directly from the U area, one at a time. */
116 /* FIXME: kettenis/2000-03-05: This duplicates code from `inptrace.c'.
117 The problem is that we define FETCH_INFERIOR_REGISTERS since we
118 want to use our own versions of {fetch,store}_inferior_registers
119 that use the GETREGS request. This means that the code in
120 `infptrace.c' is #ifdef'd out. But we need to fall back on that
121 code when GDB is running on top of a kernel that doesn't support
122 the GETREGS request. I want to avoid changing `infptrace.c' right
125 /* Default the type of the ptrace transfer to int. */
126 #ifndef PTRACE_XFER_TYPE
127 #define PTRACE_XFER_TYPE int
130 /* Registers we shouldn't try to fetch. */
131 #if !defined (CANNOT_FETCH_REGISTER)
132 #define CANNOT_FETCH_REGISTER(regno) 0
135 /* Fetch one register. */
138 fetch_register (regno
)
141 /* This isn't really an address. But ptrace thinks of it as one. */
143 char mess
[128]; /* For messages */
145 unsigned int offset
; /* Offset of registers within the u area. */
146 char buf
[MAX_REGISTER_RAW_SIZE
];
149 if (CANNOT_FETCH_REGISTER (regno
))
151 memset (buf
, '\0', REGISTER_RAW_SIZE (regno
)); /* Supply zeroes */
152 supply_register (regno
, buf
);
156 /* Overload thread id onto process id */
157 if ((tid
= TIDGET (inferior_pid
)) == 0)
158 tid
= inferior_pid
; /* no thread id, just use process id */
160 offset
= U_REGS_OFFSET
;
162 regaddr
= register_addr (regno
, offset
);
163 for (i
= 0; i
< REGISTER_RAW_SIZE (regno
); i
+= sizeof (PTRACE_XFER_TYPE
))
166 *(PTRACE_XFER_TYPE
*) & buf
[i
] = ptrace (PT_READ_U
, tid
,
167 (PTRACE_ARG3_TYPE
) regaddr
, 0);
168 regaddr
+= sizeof (PTRACE_XFER_TYPE
);
171 sprintf (mess
, "reading register %s (#%d)",
172 REGISTER_NAME (regno
), regno
);
173 perror_with_name (mess
);
176 supply_register (regno
, buf
);
179 /* Fetch register values from the inferior.
180 If REGNO is negative, do this for all registers.
181 Otherwise, REGNO specifies which register (so we can save time). */
184 old_fetch_inferior_registers (regno
)
189 fetch_register (regno
);
193 for (regno
= 0; regno
< ARCH_NUM_REGS
; regno
++)
195 fetch_register (regno
);
200 /* Registers we shouldn't try to store. */
201 #if !defined (CANNOT_STORE_REGISTER)
202 #define CANNOT_STORE_REGISTER(regno) 0
205 /* Store one register. */
208 store_register (regno
)
211 /* This isn't really an address. But ptrace thinks of it as one. */
213 char mess
[128]; /* For messages */
215 unsigned int offset
; /* Offset of registers within the u area. */
218 if (CANNOT_STORE_REGISTER (regno
))
223 /* Overload thread id onto process id */
224 if ((tid
= TIDGET (inferior_pid
)) == 0)
225 tid
= inferior_pid
; /* no thread id, just use process id */
227 offset
= U_REGS_OFFSET
;
229 regaddr
= register_addr (regno
, offset
);
230 for (i
= 0; i
< REGISTER_RAW_SIZE (regno
); i
+= sizeof (PTRACE_XFER_TYPE
))
233 ptrace (PT_WRITE_U
, tid
, (PTRACE_ARG3_TYPE
) regaddr
,
234 *(PTRACE_XFER_TYPE
*) & registers
[REGISTER_BYTE (regno
) + i
]);
235 regaddr
+= sizeof (PTRACE_XFER_TYPE
);
238 sprintf (mess
, "writing register %s (#%d)",
239 REGISTER_NAME (regno
), regno
);
240 perror_with_name (mess
);
245 /* Store our register values back into the inferior.
246 If REGNO is negative, do this for all registers.
247 Otherwise, REGNO specifies which register (so we can save time). */
250 old_store_inferior_registers (regno
)
255 store_register (regno
);
259 for (regno
= 0; regno
< ARCH_NUM_REGS
; regno
++)
261 store_register (regno
);
267 /* Transfering the general-purpose registers between GDB, inferiors
270 /* Fill GDB's register array with the genereal-purpose register values
274 supply_gregset (elf_gregset_t
*gregsetp
)
276 elf_greg_t
*regp
= (elf_greg_t
*) gregsetp
;
279 for (regi
= 0; regi
< NUM_GREGS
; regi
++)
280 supply_register (regi
, (char *) (regp
+ regmap
[regi
]));
283 /* Convert the valid general-purpose register values in GDB's register
284 array to `struct user' format and store them in *GREGSETP. The
285 array VALID indicates which register values are valid. If VALID is
286 NULL, all registers are assumed to be valid. */
289 convert_to_gregset (elf_gregset_t
*gregsetp
, signed char *valid
)
291 elf_greg_t
*regp
= (elf_greg_t
*) gregsetp
;
294 for (regi
= 0; regi
< NUM_GREGS
; regi
++)
295 if (! valid
|| valid
[regi
])
296 *(regp
+ regmap
[regi
]) = * (int *) ®isters
[REGISTER_BYTE (regi
)];
299 /* Fill register REGNO (if it is a general-purpose register) in
300 *GREGSETPS with the value in GDB's register array. If REGNO is -1,
301 do this for all registers. */
303 fill_gregset (elf_gregset_t
*gregsetp
, int regno
)
307 convert_to_gregset (gregsetp
, NULL
);
311 if (GETREGS_SUPPLIES (regno
))
313 signed char valid
[NUM_GREGS
];
315 memset (valid
, 0, sizeof (valid
));
318 convert_to_gregset (gregsetp
, valid
);
322 #ifdef HAVE_PTRACE_GETREGS
324 /* Fetch all general-purpose registers from process/thread TID and
325 store their values in GDB's register array. */
333 ret
= ptrace (PTRACE_GETREGS
, tid
, 0, (int) ®s
);
338 /* The kernel we're running on doesn't support the GETREGS
339 request. Reset `have_ptrace_getregs'. */
340 have_ptrace_getregs
= 0;
344 warning ("Couldn't get registers.");
348 supply_gregset (®s
);
351 /* Store all valid general-purpose registers in GDB's register array
352 into the process/thread specified by TID. */
360 ret
= ptrace (PTRACE_GETREGS
, tid
, 0, (int) ®s
);
363 warning ("Couldn't get registers.");
367 convert_to_gregset (®s
, register_valid
);
369 ret
= ptrace (PTRACE_SETREGS
, tid
, 0, (int) ®s
);
372 warning ("Couldn't write registers.");
379 static void fetch_regs (int tid
) {}
380 static void store_regs (int tid
) {}
385 /* Transfering floating-point registers between GDB, inferiors and cores. */
387 /* What is the address of st(N) within the floating-point register set F? */
388 #define FPREG_ADDR(f, n) ((char *) &(f)->st_space + (n) * 10)
390 /* Fill GDB's register array with the floating-point register values in
394 supply_fpregset (elf_fpregset_t
*fpregsetp
)
399 /* Supply the floating-point registers. */
400 for (reg
= 0; reg
< 8; reg
++)
401 supply_register (FP0_REGNUM
+ reg
, FPREG_ADDR (fpregsetp
, reg
));
403 /* We have to mask off the reserved bits in *FPREGSETP before
404 storing the values in GDB's register file. */
405 #define supply(REGNO, MEMBER) \
406 l = fpregsetp->MEMBER & 0xffff; \
407 supply_register (REGNO, (char *) &l)
409 supply (FCTRL_REGNUM
, cwd
);
410 supply (FSTAT_REGNUM
, swd
);
411 supply (FTAG_REGNUM
, twd
);
412 supply_register (FCOFF_REGNUM
, (char *) &fpregsetp
->fip
);
413 supply (FDS_REGNUM
, fos
);
414 supply_register (FDOFF_REGNUM
, (char *) &fpregsetp
->foo
);
418 /* Extract the code segment and opcode from the "fcs" member. */
419 l
= fpregsetp
->fcs
& 0xffff;
420 supply_register (FCS_REGNUM
, (char *) &l
);
422 l
= (fpregsetp
->fcs
>> 16) & ((1 << 11) - 1);
423 supply_register (FOP_REGNUM
, (char *) &l
);
426 /* Convert the valid floating-point register values in GDB's register
427 array to `struct user' format and store them in *FPREGSETP. The
428 array VALID indicates which register values are valid. If VALID is
429 NULL, all registers are assumed to be valid. */
432 convert_to_fpregset (elf_fpregset_t
*fpregsetp
, signed char *valid
)
436 /* Fill in the floating-point registers. */
437 for (reg
= 0; reg
< 8; reg
++)
438 if (!valid
|| valid
[reg
])
439 memcpy (FPREG_ADDR (fpregsetp
, reg
),
440 ®isters
[REGISTER_BYTE (FP0_REGNUM
+ reg
)],
441 REGISTER_RAW_SIZE(FP0_REGNUM
+ reg
));
443 /* We're not supposed to touch the reserved bits in *FPREGSETP. */
445 #define fill(MEMBER, REGNO) \
446 if (! valid || valid[(REGNO)]) \
448 = ((fpregsetp->MEMBER & ~0xffff) \
449 | (* (int *) ®isters[REGISTER_BYTE (REGNO)] & 0xffff))
451 #define fill_register(MEMBER, REGNO) \
452 if (! valid || valid[(REGNO)]) \
453 memcpy (&fpregsetp->MEMBER, ®isters[REGISTER_BYTE (REGNO)], \
454 sizeof (fpregsetp->MEMBER))
456 fill (cwd
, FCTRL_REGNUM
);
457 fill (swd
, FSTAT_REGNUM
);
458 fill (twd
, FTAG_REGNUM
);
459 fill_register (fip
, FCOFF_REGNUM
);
460 fill (foo
, FDOFF_REGNUM
);
461 fill_register (fos
, FDS_REGNUM
);
466 if (! valid
|| valid
[FCS_REGNUM
])
468 = ((fpregsetp
->fcs
& ~0xffff)
469 | (* (int *) ®isters
[REGISTER_BYTE (FCS_REGNUM
)] & 0xffff));
471 if (! valid
|| valid
[FOP_REGNUM
])
473 = ((fpregsetp
->fcs
& 0xffff)
474 | ((*(int *) ®isters
[REGISTER_BYTE (FOP_REGNUM
)] & ((1 << 11) - 1))
478 /* Fill register REGNO (if it is a floating-point register) in
479 *FPREGSETP with the value in GDB's register array. If REGNO is -1,
480 do this for all registers. */
483 fill_fpregset (elf_fpregset_t
*fpregsetp
, int regno
)
487 convert_to_fpregset (fpregsetp
, NULL
);
491 if (GETFPREGS_SUPPLIES(regno
))
493 signed char valid
[MAX_NUM_REGS
];
495 memset (valid
, 0, sizeof (valid
));
498 convert_to_fpregset (fpregsetp
, valid
);
502 #ifdef HAVE_PTRACE_GETREGS
504 /* Fetch all floating-point registers from process/thread TID and store
505 thier values in GDB's register array. */
508 fetch_fpregs (int tid
)
510 elf_fpregset_t fpregs
;
513 ret
= ptrace (PTRACE_GETFPREGS
, tid
, 0, (int) &fpregs
);
516 warning ("Couldn't get floating point status.");
520 supply_fpregset (&fpregs
);
523 /* Store all valid floating-point registers in GDB's register array
524 into the process/thread specified by TID. */
527 store_fpregs (int tid
)
529 elf_fpregset_t fpregs
;
532 ret
= ptrace (PTRACE_GETFPREGS
, tid
, 0, (int) &fpregs
);
535 warning ("Couldn't get floating point status.");
539 convert_to_fpregset (&fpregs
, register_valid
);
541 ret
= ptrace (PTRACE_SETFPREGS
, tid
, 0, (int) &fpregs
);
544 warning ("Couldn't write floating point status.");
551 static void fetch_fpregs (int tid
) {}
552 static void store_fpregs (int tid
) {}
557 /* Transfering floating-point and SSE registers to and from GDB. */
559 /* PTRACE_GETXFPREGS is a Cygnus invention, since we wrote our own
560 Linux kernel patch for SSE support. That patch may or may not
561 actually make it into the official distribution. If you find that
562 years have gone by since this code was added, and Linux isn't using
563 PTRACE_GETXFPREGS, that means that our patch didn't make it, and
564 you can delete this code. */
566 #ifdef HAVE_PTRACE_GETXFPREGS
568 /* Fill GDB's register array with the floating-point and SSE register
569 values in *XFPREGS. */
572 supply_xfpregset (struct user_xfpregs_struct
*xfpregs
)
576 /* Supply the floating-point registers. */
577 for (reg
= 0; reg
< 8; reg
++)
578 supply_register (FP0_REGNUM
+ reg
, (char *) &xfpregs
->st_space
[reg
]);
581 supply_register (FCTRL_REGNUM
, (char *) &xfpregs
->cwd
);
582 supply_register (FSTAT_REGNUM
, (char *) &xfpregs
->swd
);
583 supply_register (FTAG_REGNUM
, (char *) &xfpregs
->twd
);
584 supply_register (FCOFF_REGNUM
, (char *) &xfpregs
->fip
);
585 supply_register (FDS_REGNUM
, (char *) &xfpregs
->fos
);
586 supply_register (FDOFF_REGNUM
, (char *) &xfpregs
->foo
);
588 /* Extract the code segment and opcode from the "fcs" member. */
592 l
= xfpregs
->fcs
& 0xffff;
593 supply_register (FCS_REGNUM
, (char *) &l
);
595 l
= (xfpregs
->fcs
>> 16) & ((1 << 11) - 1);
596 supply_register (FOP_REGNUM
, (char *) &l
);
600 /* Supply the SSE registers. */
601 for (reg
= 0; reg
< 8; reg
++)
602 supply_register (XMM0_REGNUM
+ reg
, (char *) &xfpregs
->xmm_space
[reg
]);
603 supply_register (MXCSR_REGNUM
, (char *) &xfpregs
->mxcsr
);
606 /* Convert the valid floating-point and SSE registers in GDB's
607 register array to `struct user' format and store them in *XFPREGS.
608 The array VALID indicates which registers are valid. If VALID is
609 NULL, all registers are assumed to be valid. */
612 convert_to_xfpregset (struct user_xfpregs_struct
*xfpregs
,
617 /* Fill in the floating-point registers. */
618 for (reg
= 0; reg
< 8; reg
++)
619 if (!valid
|| valid
[reg
])
620 memcpy (&xfpregs
->st_space
[reg
],
621 ®isters
[REGISTER_BYTE (FP0_REGNUM
+ reg
)],
622 REGISTER_RAW_SIZE(FP0_REGNUM
+ reg
));
624 #define fill(MEMBER, REGNO) \
625 if (! valid || valid[(REGNO)]) \
626 memcpy (&xfpregs->MEMBER, ®isters[REGISTER_BYTE (REGNO)], \
627 sizeof (xfpregs->MEMBER))
629 fill (cwd
, FCTRL_REGNUM
);
630 fill (swd
, FSTAT_REGNUM
);
631 fill (twd
, FTAG_REGNUM
);
632 fill (fip
, FCOFF_REGNUM
);
633 fill (foo
, FDOFF_REGNUM
);
634 fill (fos
, FDS_REGNUM
);
638 if (! valid
|| valid
[FCS_REGNUM
])
640 = ((xfpregs
->fcs
& ~0xffff)
641 | (* (int *) ®isters
[REGISTER_BYTE (FCS_REGNUM
)] & 0xffff));
643 if (! valid
|| valid
[FOP_REGNUM
])
645 = ((xfpregs
->fcs
& 0xffff)
646 | ((*(int *) ®isters
[REGISTER_BYTE (FOP_REGNUM
)] & ((1 << 11) - 1))
649 /* Fill in the XMM registers. */
650 for (reg
= 0; reg
< 8; reg
++)
651 if (! valid
|| valid
[reg
])
652 memcpy (&xfpregs
->xmm_space
[reg
],
653 ®isters
[REGISTER_BYTE (XMM0_REGNUM
+ reg
)],
654 REGISTER_RAW_SIZE (XMM0_REGNUM
+ reg
));
657 /* Fetch all registers covered by the PTRACE_SETXFPREGS request from
658 process/thread TID and store their values in GDB's register array.
659 Return non-zero if successful, zero otherwise. */
662 fetch_xfpregs (int tid
)
664 struct user_xfpregs_struct xfpregs
;
667 if (! have_ptrace_getxfpregs
)
670 ret
= ptrace (PTRACE_GETXFPREGS
, tid
, 0, &xfpregs
);
675 have_ptrace_getxfpregs
= 0;
679 warning ("Couldn't read floating-point and SSE registers.");
683 supply_xfpregset (&xfpregs
);
687 /* Store all valid registers in GDB's register array covered by the
688 PTRACE_SETXFPREGS request into the process/thread specified by TID.
689 Return non-zero if successful, zero otherwise. */
692 store_xfpregs (int tid
)
694 struct user_xfpregs_struct xfpregs
;
697 if (! have_ptrace_getxfpregs
)
700 ret
= ptrace (PTRACE_GETXFPREGS
, tid
, 0, &xfpregs
);
705 have_ptrace_getxfpregs
= 0;
709 warning ("Couldn't read floating-point and SSE registers.");
713 convert_to_xfpregset (&xfpregs
, register_valid
);
715 if (ptrace (PTRACE_SETXFPREGS
, tid
, 0, &xfpregs
) < 0)
717 warning ("Couldn't write floating-point and SSE registers.");
724 /* Fill the XMM registers in the register array with dummy values. For
725 cases where we don't have access to the XMM registers. I think
726 this is cleaner than printing a warning. For a cleaner solution,
727 we should gdbarchify the i386 family. */
730 dummy_sse_values (void)
732 /* C doesn't have a syntax for NaN's, so write it out as an array of
734 static long dummy
[4] = { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff };
735 static long mxcsr
= 0x1f80;
738 for (reg
= 0; reg
< 8; reg
++)
739 supply_register (XMM0_REGNUM
+ reg
, (char *) dummy
);
740 supply_register (MXCSR_REGNUM
, (char *) &mxcsr
);
745 /* Stub versions of the above routines, for systems that don't have
746 PTRACE_GETXFPREGS. */
747 static int store_xfpregs (int tid
) { return 0; }
748 static int fetch_xfpregs (int tid
) { return 0; }
749 static void dummy_sse_values (void) {}
754 /* Transferring arbitrary registers between GDB and inferior. */
756 /* Fetch register REGNO from the child process. If REGNO is -1, do
757 this for all registers (including the floating point and SSE
761 fetch_inferior_registers (int regno
)
765 /* Use the old method of peeking around in `struct user' if the
766 GETREGS request isn't available. */
767 if (! have_ptrace_getregs
)
769 old_fetch_inferior_registers (regno
);
773 /* Linux LWP ID's are process ID's. */
774 if ((tid
= TIDGET (inferior_pid
)) == 0)
775 tid
= inferior_pid
; /* Not a threaded program. */
777 /* Use the PTRACE_GETXFPREGS request whenever possible, since it
778 transfers more registers in one system call, and we'll cache the
779 results. But remember that fetch_xfpregs can fail, and return
785 /* The call above might reset `have_ptrace_getregs'. */
786 if (! have_ptrace_getregs
)
788 old_fetch_inferior_registers (-1);
792 if (fetch_xfpregs (tid
))
798 if (GETREGS_SUPPLIES (regno
))
804 if (GETXFPREGS_SUPPLIES (regno
))
806 if (fetch_xfpregs (tid
))
809 /* Either our processor or our kernel doesn't support the SSE
810 registers, so read the FP registers in the traditional way,
811 and fill the SSE registers with dummy values. It would be
812 more graceful to handle differences in the register set using
813 gdbarch. Until then, this will at least make things work
820 internal_error ("i386-linux-nat.c (fetch_inferior_registers): "
821 "got request for bad register number %d", regno
);
824 /* Store register REGNO back into the child process. If REGNO is -1,
825 do this for all registers (including the floating point and SSE
828 store_inferior_registers (int regno
)
832 /* Use the old method of poking around in `struct user' if the
833 SETREGS request isn't available. */
834 if (! have_ptrace_getregs
)
836 old_store_inferior_registers (regno
);
840 /* Linux LWP ID's are process ID's. */
841 if ((tid
= TIDGET (inferior_pid
)) == 0)
842 tid
= inferior_pid
; /* Not a threaded program. */
844 /* Use the PTRACE_SETXFPREGS requests whenever possibl, since it
845 transfers more registers in one system call. But remember that
846 store_xfpregs can fail, and return zero. */
850 if (store_xfpregs (tid
))
856 if (GETREGS_SUPPLIES (regno
))
862 if (GETXFPREGS_SUPPLIES (regno
))
864 if (store_xfpregs (tid
))
867 /* Either our processor or our kernel doesn't support the SSE
868 registers, so just write the FP registers in the traditional
874 internal_error ("Got request to store bad register number %d.", regno
);
878 /* Interpreting register set info found in core files. */
880 /* Provide registers to GDB from a core file.
882 (We can't use the generic version of this function in
883 core-regset.c, because Linux has *three* different kinds of
884 register set notes. core-regset.c would have to call
885 supply_xfpregset, which most platforms don't have.)
887 CORE_REG_SECT points to an array of bytes, which are the contents
888 of a `note' from a core file which BFD thinks might contain
889 register contents. CORE_REG_SIZE is its size.
891 WHICH says which register set corelow suspects this is:
892 0 --- the general-purpose register set, in elf_gregset_t format
893 2 --- the floating-point register set, in elf_fpregset_t format
894 3 --- the extended floating-point register set, in struct
895 user_xfpregs_struct format
897 REG_ADDR isn't used on Linux. */
900 fetch_core_registers (char *core_reg_sect
, unsigned core_reg_size
,
901 int which
, CORE_ADDR reg_addr
)
903 elf_gregset_t gregset
;
904 elf_fpregset_t fpregset
;
909 if (core_reg_size
!= sizeof (gregset
))
910 warning ("Wrong size gregset in core file.");
913 memcpy (&gregset
, core_reg_sect
, sizeof (gregset
));
914 supply_gregset (&gregset
);
919 if (core_reg_size
!= sizeof (fpregset
))
920 warning ("Wrong size fpregset in core file.");
923 memcpy (&fpregset
, core_reg_sect
, sizeof (fpregset
));
924 supply_fpregset (&fpregset
);
928 #ifdef HAVE_PTRACE_GETXFPREGS
930 struct user_xfpregs_struct xfpregset
;
933 if (core_reg_size
!= sizeof (xfpregset
))
934 warning ("Wrong size user_xfpregs_struct in core file.");
937 memcpy (&xfpregset
, core_reg_sect
, sizeof (xfpregset
));
938 supply_xfpregset (&xfpregset
);
945 /* We've covered all the kinds of registers we know about here,
946 so this must be something we wouldn't know what to do with
947 anyway. Just ignore it. */
953 /* Calling functions in shared libraries. */
954 /* FIXME: kettenis/2000-03-05: Doesn't this belong in a
955 target-dependent file? The function
956 `i386_linux_skip_solib_resolver' is mentioned in
957 `config/i386/tm-linux.h'. */
959 /* Find the minimal symbol named NAME, and return both the minsym
960 struct and its objfile. This probably ought to be in minsym.c, but
961 everything there is trying to deal with things like C++ and
962 SOFUN_ADDRESS_MAYBE_TURQUOISE, ... Since this is so simple, it may
963 be considered too special-purpose for general consumption. */
965 static struct minimal_symbol
*
966 find_minsym_and_objfile (char *name
, struct objfile
**objfile_p
)
968 struct objfile
*objfile
;
970 ALL_OBJFILES (objfile
)
972 struct minimal_symbol
*msym
;
974 ALL_OBJFILE_MSYMBOLS (objfile
, msym
)
976 if (SYMBOL_NAME (msym
)
977 && STREQ (SYMBOL_NAME (msym
), name
))
979 *objfile_p
= objfile
;
990 skip_hurd_resolver (CORE_ADDR pc
)
992 /* The HURD dynamic linker is part of the GNU C library, so many
993 GNU/Linux distributions use it. (All ELF versions, as far as I
994 know.) An unresolved PLT entry points to "_dl_runtime_resolve",
995 which calls "fixup" to patch the PLT, and then passes control to
998 We look for the symbol `_dl_runtime_resolve', and find `fixup' in
999 the same objfile. If we are at the entry point of `fixup', then
1000 we set a breakpoint at the return address (at the top of the
1001 stack), and continue.
1003 It's kind of gross to do all these checks every time we're
1004 called, since they don't change once the executable has gotten
1005 started. But this is only a temporary hack --- upcoming versions
1006 of Linux will provide a portable, efficient interface for
1007 debugging programs that use shared libraries. */
1009 struct objfile
*objfile
;
1010 struct minimal_symbol
*resolver
1011 = find_minsym_and_objfile ("_dl_runtime_resolve", &objfile
);
1015 struct minimal_symbol
*fixup
1016 = lookup_minimal_symbol ("fixup", 0, objfile
);
1018 if (fixup
&& SYMBOL_VALUE_ADDRESS (fixup
) == pc
)
1019 return (SAVED_PC_AFTER_CALL (get_current_frame ()));
1025 /* See the comments for SKIP_SOLIB_RESOLVER at the top of infrun.c.
1027 1) decides whether a PLT has sent us into the linker to resolve
1028 a function reference, and
1029 2) if so, tells us where to set a temporary breakpoint that will
1030 trigger when the dynamic linker is done. */
1033 i386_linux_skip_solib_resolver (CORE_ADDR pc
)
1037 /* Plug in functions for other kinds of resolvers here. */
1038 result
= skip_hurd_resolver (pc
);
1046 /* Register that we are able to handle Linux ELF core file formats. */
1048 static struct core_fns linux_elf_core_fns
=
1050 bfd_target_elf_flavour
, /* core_flavour */
1051 default_check_format
, /* check_format */
1052 default_core_sniffer
, /* core_sniffer */
1053 fetch_core_registers
, /* core_read_registers */
1058 _initialize_i386_linux_nat ()
1060 add_core_fns (&linux_elf_core_fns
);