1 /* Native-dependent code for Linux running on i386's, for GDB.
2 Copyright (C) 1999, 2000 Free Software Foundation, Inc.
4 This file is part of GDB.
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.
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.
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. */
25 /* For i386_linux_skip_solib_resolver. */
30 #include <sys/ptrace.h>
32 #include <sys/procfs.h>
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. */
45 #if !defined (PIDGET) /* Default definition for PIDGET/TIDGET. */
46 #define PIDGET(PID) PID
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.
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. */
63 /* Mapping between the general-purpose registers in `struct user'
64 format and GDB's register array layout. */
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)
82 /* Does the current host support the GETREGS request? */
83 int have_ptrace_getregs
=
84 #ifdef HAVE_PTRACE_GETREGS
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.
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.
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_getxfpregs
=
107 #ifdef HAVE_PTRACE_GETXFPREGS
115 /* Fetching registers directly from the U area, one at a time. */
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
126 /* Default the type of the ptrace transfer to int. */
127 #ifndef PTRACE_XFER_TYPE
128 #define PTRACE_XFER_TYPE int
131 /* Registers we shouldn't try to fetch. */
132 #if !defined (CANNOT_FETCH_REGISTER)
133 #define CANNOT_FETCH_REGISTER(regno) 0
136 /* Fetch one register. */
139 fetch_register (regno
)
142 /* This isn't really an address. But ptrace thinks of it as one. */
144 char mess
[128]; /* For messages */
146 unsigned int offset
; /* Offset of registers within the u area. */
147 char buf
[MAX_REGISTER_RAW_SIZE
];
150 if (CANNOT_FETCH_REGISTER (regno
))
152 memset (buf
, '\0', REGISTER_RAW_SIZE (regno
)); /* Supply zeroes */
153 supply_register (regno
, buf
);
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 */
161 offset
= U_REGS_OFFSET
;
163 regaddr
= register_addr (regno
, offset
);
164 for (i
= 0; i
< REGISTER_RAW_SIZE (regno
); i
+= sizeof (PTRACE_XFER_TYPE
))
167 *(PTRACE_XFER_TYPE
*) & buf
[i
] = ptrace (PT_READ_U
, tid
,
168 (PTRACE_ARG3_TYPE
) regaddr
, 0);
169 regaddr
+= sizeof (PTRACE_XFER_TYPE
);
172 sprintf (mess
, "reading register %s (#%d)",
173 REGISTER_NAME (regno
), regno
);
174 perror_with_name (mess
);
177 supply_register (regno
, buf
);
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). */
185 old_fetch_inferior_registers (regno
)
190 fetch_register (regno
);
194 for (regno
= 0; regno
< ARCH_NUM_REGS
; regno
++)
196 fetch_register (regno
);
201 /* Registers we shouldn't try to store. */
202 #if !defined (CANNOT_STORE_REGISTER)
203 #define CANNOT_STORE_REGISTER(regno) 0
206 /* Store one register. */
209 store_register (regno
)
212 /* This isn't really an address. But ptrace thinks of it as one. */
214 char mess
[128]; /* For messages */
216 unsigned int offset
; /* Offset of registers within the u area. */
219 if (CANNOT_STORE_REGISTER (regno
))
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 */
228 offset
= U_REGS_OFFSET
;
230 regaddr
= register_addr (regno
, offset
);
231 for (i
= 0; i
< REGISTER_RAW_SIZE (regno
); i
+= sizeof (PTRACE_XFER_TYPE
))
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
);
239 sprintf (mess
, "writing register %s (#%d)",
240 REGISTER_NAME (regno
), regno
);
241 perror_with_name (mess
);
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). */
251 old_store_inferior_registers (regno
)
256 store_register (regno
);
260 for (regno
= 0; regno
< ARCH_NUM_REGS
; regno
++)
262 store_register (regno
);
268 /* Transfering the general-purpose registers between GDB, inferiors
271 /* Fill GDB's register array with the genereal-purpose register values
275 supply_gregset (elf_gregset_t
*gregsetp
)
277 elf_greg_t
*regp
= (elf_greg_t
*) gregsetp
;
280 for (regi
= 0; regi
< NUM_GREGS
; regi
++)
281 supply_register (regi
, (char *) (regp
+ regmap
[regi
]));
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. */
290 convert_to_gregset (elf_gregset_t
*gregsetp
, signed char *valid
)
292 elf_greg_t
*regp
= (elf_greg_t
*) gregsetp
;
295 for (regi
= 0; regi
< NUM_GREGS
; regi
++)
296 if (! valid
|| valid
[regi
])
297 *(regp
+ regmap
[regi
]) = * (int *) ®isters
[REGISTER_BYTE (regi
)];
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. */
304 fill_gregset (elf_gregset_t
*gregsetp
, int regno
)
308 convert_to_gregset (gregsetp
, NULL
);
312 if (GETREGS_SUPPLIES (regno
))
314 signed char valid
[NUM_GREGS
];
316 memset (valid
, 0, sizeof (valid
));
319 convert_to_gregset (gregsetp
, valid
);
323 #ifdef HAVE_PTRACE_GETREGS
325 /* Fetch all general-purpose registers from process/thread TID and
326 store their values in GDB's register array. */
334 ret
= ptrace (PTRACE_GETREGS
, tid
, 0, (int) ®s
);
339 /* The kernel we're running on doesn't support the GETREGS
340 request. Reset `have_ptrace_getregs'. */
341 have_ptrace_getregs
= 0;
345 warning ("Couldn't get registers.");
349 supply_gregset (®s
);
352 /* Store all valid general-purpose registers in GDB's register array
353 into the process/thread specified by TID. */
361 ret
= ptrace (PTRACE_GETREGS
, tid
, 0, (int) ®s
);
364 warning ("Couldn't get registers.");
368 convert_to_gregset (®s
, register_valid
);
370 ret
= ptrace (PTRACE_SETREGS
, tid
, 0, (int) ®s
);
373 warning ("Couldn't write registers.");
380 static void fetch_regs (int tid
) {}
381 static void store_regs (int tid
) {}
386 /* Transfering floating-point registers between GDB, inferiors and cores. */
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)
391 /* Fill GDB's register array with the floating-point register values in
395 supply_fpregset (elf_fpregset_t
*fpregsetp
)
400 /* Supply the floating-point registers. */
401 for (reg
= 0; reg
< 8; reg
++)
402 supply_register (FP0_REGNUM
+ reg
, FPREG_ADDR (fpregsetp
, reg
));
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)
410 supply (FCTRL_REGNUM
, cwd
);
411 supply (FSTAT_REGNUM
, swd
);
412 supply (FTAG_REGNUM
, twd
);
413 supply_register (FCOFF_REGNUM
, (char *) &fpregsetp
->fip
);
414 supply (FDS_REGNUM
, fos
);
415 supply_register (FDOFF_REGNUM
, (char *) &fpregsetp
->foo
);
419 /* Extract the code segment and opcode from the "fcs" member. */
420 l
= fpregsetp
->fcs
& 0xffff;
421 supply_register (FCS_REGNUM
, (char *) &l
);
423 l
= (fpregsetp
->fcs
>> 16) & ((1 << 11) - 1);
424 supply_register (FOP_REGNUM
, (char *) &l
);
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. */
433 convert_to_fpregset (elf_fpregset_t
*fpregsetp
, signed char *valid
)
437 /* Fill in the floating-point registers. */
438 for (reg
= 0; reg
< 8; reg
++)
439 if (!valid
|| valid
[reg
])
440 memcpy (FPREG_ADDR (fpregsetp
, reg
),
441 ®isters
[REGISTER_BYTE (FP0_REGNUM
+ reg
)],
442 REGISTER_RAW_SIZE(FP0_REGNUM
+ reg
));
444 /* We're not supposed to touch the reserved bits in *FPREGSETP. */
446 #define fill(MEMBER, REGNO) \
447 if (! valid || valid[(REGNO)]) \
449 = ((fpregsetp->MEMBER & ~0xffff) \
450 | (* (int *) ®isters[REGISTER_BYTE (REGNO)] & 0xffff))
452 #define fill_register(MEMBER, REGNO) \
453 if (! valid || valid[(REGNO)]) \
454 memcpy (&fpregsetp->MEMBER, ®isters[REGISTER_BYTE (REGNO)], \
455 sizeof (fpregsetp->MEMBER))
457 fill (cwd
, FCTRL_REGNUM
);
458 fill (swd
, FSTAT_REGNUM
);
459 fill (twd
, FTAG_REGNUM
);
460 fill_register (fip
, FCOFF_REGNUM
);
461 fill (foo
, FDOFF_REGNUM
);
462 fill_register (fos
, FDS_REGNUM
);
467 if (! valid
|| valid
[FCS_REGNUM
])
469 = ((fpregsetp
->fcs
& ~0xffff)
470 | (* (int *) ®isters
[REGISTER_BYTE (FCS_REGNUM
)] & 0xffff));
472 if (! valid
|| valid
[FOP_REGNUM
])
474 = ((fpregsetp
->fcs
& 0xffff)
475 | ((*(int *) ®isters
[REGISTER_BYTE (FOP_REGNUM
)] & ((1 << 11) - 1))
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. */
484 fill_fpregset (elf_fpregset_t
*fpregsetp
, int regno
)
488 convert_to_fpregset (fpregsetp
, NULL
);
492 if (GETFPREGS_SUPPLIES(regno
))
494 signed char valid
[MAX_NUM_REGS
];
496 memset (valid
, 0, sizeof (valid
));
499 convert_to_fpregset (fpregsetp
, valid
);
503 #ifdef HAVE_PTRACE_GETREGS
505 /* Fetch all floating-point registers from process/thread TID and store
506 thier values in GDB's register array. */
509 fetch_fpregs (int tid
)
511 elf_fpregset_t fpregs
;
514 ret
= ptrace (PTRACE_GETFPREGS
, tid
, 0, (int) &fpregs
);
517 warning ("Couldn't get floating point status.");
521 supply_fpregset (&fpregs
);
524 /* Store all valid floating-point registers in GDB's register array
525 into the process/thread specified by TID. */
528 store_fpregs (int tid
)
530 elf_fpregset_t fpregs
;
533 ret
= ptrace (PTRACE_GETFPREGS
, tid
, 0, (int) &fpregs
);
536 warning ("Couldn't get floating point status.");
540 convert_to_fpregset (&fpregs
, register_valid
);
542 ret
= ptrace (PTRACE_SETFPREGS
, tid
, 0, (int) &fpregs
);
545 warning ("Couldn't write floating point status.");
552 static void fetch_fpregs (int tid
) {}
553 static void store_fpregs (int tid
) {}
558 /* Transfering floating-point and SSE registers to and from GDB. */
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. */
567 #ifdef HAVE_PTRACE_GETXFPREGS
569 /* Fill GDB's register array with the floating-point and SSE register
570 values in *XFPREGS. */
573 supply_xfpregset (struct user_xfpregs_struct
*xfpregs
)
577 /* Supply the floating-point registers. */
578 for (reg
= 0; reg
< 8; reg
++)
579 supply_register (FP0_REGNUM
+ reg
, (char *) &xfpregs
->st_space
[reg
]);
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
);
589 /* Extract the code segment and opcode from the "fcs" member. */
593 l
= xfpregs
->fcs
& 0xffff;
594 supply_register (FCS_REGNUM
, (char *) &l
);
596 l
= (xfpregs
->fcs
>> 16) & ((1 << 11) - 1);
597 supply_register (FOP_REGNUM
, (char *) &l
);
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
);
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. */
613 convert_to_xfpregset (struct user_xfpregs_struct
*xfpregs
,
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 ®isters
[REGISTER_BYTE (FP0_REGNUM
+ reg
)],
623 REGISTER_RAW_SIZE(FP0_REGNUM
+ reg
));
625 #define fill(MEMBER, REGNO) \
626 if (! valid || valid[(REGNO)]) \
627 memcpy (&xfpregs->MEMBER, ®isters[REGISTER_BYTE (REGNO)], \
628 sizeof (xfpregs->MEMBER))
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
);
639 if (! valid
|| valid
[FCS_REGNUM
])
641 = ((xfpregs
->fcs
& ~0xffff)
642 | (* (int *) ®isters
[REGISTER_BYTE (FCS_REGNUM
)] & 0xffff));
644 if (! valid
|| valid
[FOP_REGNUM
])
646 = ((xfpregs
->fcs
& 0xffff)
647 | ((*(int *) ®isters
[REGISTER_BYTE (FOP_REGNUM
)] & ((1 << 11) - 1))
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 ®isters
[REGISTER_BYTE (XMM0_REGNUM
+ reg
)],
655 REGISTER_RAW_SIZE (XMM0_REGNUM
+ reg
));
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. */
663 fetch_xfpregs (int tid
)
665 struct user_xfpregs_struct xfpregs
;
668 if (! have_ptrace_getxfpregs
)
671 ret
= ptrace (PTRACE_GETXFPREGS
, tid
, 0, &xfpregs
);
676 have_ptrace_getxfpregs
= 0;
680 warning ("Couldn't read floating-point and SSE registers.");
684 supply_xfpregset (&xfpregs
);
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. */
693 store_xfpregs (int tid
)
695 struct user_xfpregs_struct xfpregs
;
698 if (! have_ptrace_getxfpregs
)
701 ret
= ptrace (PTRACE_GETXFPREGS
, tid
, 0, &xfpregs
);
706 have_ptrace_getxfpregs
= 0;
710 warning ("Couldn't read floating-point and SSE registers.");
714 convert_to_xfpregset (&xfpregs
, register_valid
);
716 if (ptrace (PTRACE_SETXFPREGS
, tid
, 0, &xfpregs
) < 0)
718 warning ("Couldn't write floating-point and SSE registers.");
725 /* Fill the XMM registers in the register array with dummy values. For
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. */
731 dummy_sse_values (void)
733 /* C doesn't have a syntax for NaN's, so write it out as an array of
735 static long dummy
[4] = { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff };
736 static long mxcsr
= 0x1f80;
739 for (reg
= 0; reg
< 8; reg
++)
740 supply_register (XMM0_REGNUM
+ reg
, (char *) dummy
);
741 supply_register (MXCSR_REGNUM
, (char *) &mxcsr
);
746 /* Stub versions of the above routines, for systems that don't have
747 PTRACE_GETXFPREGS. */
748 static int store_xfpregs (int tid
) { return 0; }
749 static int fetch_xfpregs (int tid
) { return 0; }
750 static void dummy_sse_values (void) {}
755 /* Transferring arbitrary registers between GDB and inferior. */
757 /* Fetch register REGNO from the child process. If REGNO is -1, do
758 this for all registers (including the floating point and SSE
762 fetch_inferior_registers (int regno
)
766 /* Use the old method of peeking around in `struct user' if the
767 GETREGS request isn't available. */
768 if (! have_ptrace_getregs
)
770 old_fetch_inferior_registers (regno
);
774 /* Linux LWP ID's are process ID's. */
775 if ((tid
= TIDGET (inferior_pid
)) == 0)
776 tid
= inferior_pid
; /* Not a threaded program. */
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
786 /* The call above might reset `have_ptrace_getregs'. */
787 if (! have_ptrace_getregs
)
789 old_fetch_inferior_registers (-1);
793 if (fetch_xfpregs (tid
))
799 if (GETREGS_SUPPLIES (regno
))
805 if (GETXFPREGS_SUPPLIES (regno
))
807 if (fetch_xfpregs (tid
))
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
821 internal_error ("i386-linux-nat.c (fetch_inferior_registers): "
822 "got request for bad register number %d", regno
);
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
829 store_inferior_registers (int regno
)
833 /* Use the old method of poking around in `struct user' if the
834 SETREGS request isn't available. */
835 if (! have_ptrace_getregs
)
837 old_store_inferior_registers (regno
);
841 /* Linux LWP ID's are process ID's. */
842 if ((tid
= TIDGET (inferior_pid
)) == 0)
843 tid
= inferior_pid
; /* Not a threaded program. */
845 /* Use the PTRACE_SETXFPREGS requests whenever possibl, since it
846 transfers more registers in one system call. But remember that
847 store_xfpregs can fail, and return zero. */
851 if (store_xfpregs (tid
))
857 if (GETREGS_SUPPLIES (regno
))
863 if (GETXFPREGS_SUPPLIES (regno
))
865 if (store_xfpregs (tid
))
868 /* Either our processor or our kernel doesn't support the SSE
869 registers, so just write the FP registers in the traditional
875 internal_error ("Got request to store bad register number %d.", regno
);
879 /* Interpreting register set info found in core files. */
881 /* Provide registers to GDB from a core file.
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.)
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.
892 WHICH says which register set corelow suspects this is:
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
898 REG_ADDR isn't used on Linux. */
901 fetch_core_registers (char *core_reg_sect
, unsigned core_reg_size
,
902 int which
, CORE_ADDR reg_addr
)
904 elf_gregset_t gregset
;
905 elf_fpregset_t fpregset
;
910 if (core_reg_size
!= sizeof (gregset
))
911 warning ("Wrong size gregset in core file.");
914 memcpy (&gregset
, core_reg_sect
, sizeof (gregset
));
915 supply_gregset (&gregset
);
920 if (core_reg_size
!= sizeof (fpregset
))
921 warning ("Wrong size fpregset in core file.");
924 memcpy (&fpregset
, core_reg_sect
, sizeof (fpregset
));
925 supply_fpregset (&fpregset
);
929 #ifdef HAVE_PTRACE_GETXFPREGS
931 struct user_xfpregs_struct xfpregset
;
934 if (core_reg_size
!= sizeof (xfpregset
))
935 warning ("Wrong size user_xfpregs_struct in core file.");
938 memcpy (&xfpregset
, core_reg_sect
, sizeof (xfpregset
));
939 supply_xfpregset (&xfpregset
);
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. */
954 /* Calling functions in shared libraries. */
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'. */
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. */
966 static struct minimal_symbol
*
967 find_minsym_and_objfile (char *name
, struct objfile
**objfile_p
)
969 struct objfile
*objfile
;
971 ALL_OBJFILES (objfile
)
973 struct minimal_symbol
*msym
;
975 ALL_OBJFILE_MSYMBOLS (objfile
, msym
)
977 if (SYMBOL_NAME (msym
)
978 && STREQ (SYMBOL_NAME (msym
), name
))
980 *objfile_p
= objfile
;
991 skip_hurd_resolver (CORE_ADDR pc
)
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
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.
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. */
1010 struct objfile
*objfile
;
1011 struct minimal_symbol
*resolver
1012 = find_minsym_and_objfile ("_dl_runtime_resolve", &objfile
);
1016 struct minimal_symbol
*fixup
1017 = lookup_minimal_symbol ("fixup", 0, objfile
);
1019 if (fixup
&& SYMBOL_VALUE_ADDRESS (fixup
) == pc
)
1020 return (SAVED_PC_AFTER_CALL (get_current_frame ()));
1026 /* See the comments for SKIP_SOLIB_RESOLVER at the top of infrun.c.
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. */
1034 i386_linux_skip_solib_resolver (CORE_ADDR pc
)
1038 /* Plug in functions for other kinds of resolvers here. */
1039 result
= skip_hurd_resolver (pc
);
1047 /* Register that we are able to handle Linux ELF core file formats. */
1049 static struct core_fns linux_elf_core_fns
=
1051 bfd_target_elf_flavour
, /* core_flavour */
1052 default_check_format
, /* check_format */
1053 default_core_sniffer
, /* core_sniffer */
1054 fetch_core_registers
, /* core_read_registers */
1059 _initialize_i386_linux_nat ()
1061 add_core_fns (&linux_elf_core_fns
);