Commit | Line | Data |
---|---|---|
c906108c | 1 | /* Machine independent GDB support for core files on systems using "regsets". |
94ba74a9 | 2 | |
aff410f1 MS |
3 | Copyright (C) 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2003, 2007, |
4 | 2008, 2009, 2010 Free Software Foundation, Inc. | |
c906108c | 5 | |
c5aa993b | 6 | This file is part of GDB. |
c906108c | 7 | |
c5aa993b JM |
8 | This program is free software; you can redistribute it and/or modify |
9 | it under the terms of the GNU General Public License as published by | |
a9762ec7 | 10 | the Free Software Foundation; either version 3 of the License, or |
c5aa993b | 11 | (at your option) any later version. |
c906108c | 12 | |
c5aa993b JM |
13 | This program is distributed in the hope that it will be useful, |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | GNU General Public License for more details. | |
c906108c | 17 | |
c5aa993b | 18 | You should have received a copy of the GNU General Public License |
a9762ec7 | 19 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
c906108c | 20 | |
94ba74a9 MK |
21 | /* This file is used by most systems that use ELF for their core |
22 | dumps. This includes most systems that have SVR4-ish variant of | |
23 | /proc. For these systems, the registers are laid out the same way | |
24 | in core files as in the gregset_t and fpregset_t structures that | |
25 | are used in the interaction with /proc (Irix 4 is an exception and | |
26 | therefore doesn't use this file). Quite a few systems without a | |
27 | SVR4-ish /proc define these structures too, and can make use of | |
28 | this code too. */ | |
c906108c SS |
29 | |
30 | #include "defs.h" | |
94ba74a9 MK |
31 | #include "command.h" |
32 | #include "gdbcore.h" | |
33 | #include "inferior.h" | |
34 | #include "target.h" | |
7f7fe91e | 35 | #include "regcache.h" |
c906108c | 36 | |
94ba74a9 MK |
37 | #include <fcntl.h> |
38 | #include <errno.h> | |
39 | #include "gdb_string.h" | |
c906108c SS |
40 | #include <time.h> |
41 | #ifdef HAVE_SYS_PROCFS_H | |
42 | #include <sys/procfs.h> | |
43 | #endif | |
c906108c | 44 | |
94ba74a9 | 45 | /* Prototypes for supply_gregset etc. */ |
c60c0f5f MS |
46 | #include "gregset.h" |
47 | ||
94ba74a9 | 48 | /* Provide registers to GDB from a core file. |
c906108c | 49 | |
94ba74a9 MK |
50 | CORE_REG_SECT points to an array of bytes, which are the contents |
51 | of a `note' from a core file which BFD thinks might contain | |
52 | register contents. CORE_REG_SIZE is its size. | |
c906108c | 53 | |
94ba74a9 MK |
54 | WHICH says which register set corelow suspects this is: |
55 | 0 --- the general-purpose register set, in gregset_t format | |
56 | 2 --- the floating-point register set, in fpregset_t format | |
c906108c | 57 | |
94ba74a9 | 58 | REG_ADDR is ignored. */ |
c906108c SS |
59 | |
60 | static void | |
9eefc95f | 61 | fetch_core_registers (struct regcache *regcache, |
aff410f1 MS |
62 | char *core_reg_sect, |
63 | unsigned core_reg_size, | |
64 | int which, | |
89727b6f | 65 | CORE_ADDR reg_addr) |
c906108c | 66 | { |
455ecc72 DJ |
67 | gdb_gregset_t gregset; |
68 | gdb_fpregset_t fpregset; | |
b48516f9 L |
69 | gdb_gregset_t *gregset_p = &gregset; |
70 | gdb_fpregset_t *fpregset_p = &fpregset; | |
c906108c | 71 | |
94ba74a9 | 72 | switch (which) |
c906108c | 73 | { |
94ba74a9 | 74 | case 0: |
c906108c | 75 | if (core_reg_size != sizeof (gregset)) |
8a3fe4f8 | 76 | warning (_("Wrong size gregset in core file.")); |
c906108c SS |
77 | else |
78 | { | |
94ba74a9 | 79 | memcpy (&gregset, core_reg_sect, sizeof (gregset)); |
b48516f9 | 80 | supply_gregset (regcache, (const gdb_gregset_t *) gregset_p); |
c906108c | 81 | } |
94ba74a9 MK |
82 | break; |
83 | ||
84 | case 2: | |
c906108c | 85 | if (core_reg_size != sizeof (fpregset)) |
8a3fe4f8 | 86 | warning (_("Wrong size fpregset in core file.")); |
c906108c SS |
87 | else |
88 | { | |
94ba74a9 | 89 | memcpy (&fpregset, core_reg_sect, sizeof (fpregset)); |
8f4f3fbe | 90 | if (gdbarch_fp0_regnum (get_regcache_arch (regcache)) >= 0) |
aff410f1 MS |
91 | supply_fpregset (regcache, |
92 | (const gdb_fpregset_t *) fpregset_p); | |
c906108c | 93 | } |
94ba74a9 MK |
94 | break; |
95 | ||
96 | default: | |
97 | /* We've covered all the kinds of registers we know about here, | |
98 | so this must be something we wouldn't know what to do with | |
99 | anyway. Just ignore it. */ | |
100 | break; | |
c906108c | 101 | } |
c906108c | 102 | } |
c906108c | 103 | \f |
c5aa993b | 104 | |
94ba74a9 MK |
105 | /* Register that we are able to handle ELF core file formats using |
106 | standard procfs "regset" structures. */ | |
c906108c SS |
107 | |
108 | static struct core_fns regset_core_fns = | |
109 | { | |
2acceee2 JM |
110 | bfd_target_elf_flavour, /* core_flavour */ |
111 | default_check_format, /* check_format */ | |
112 | default_core_sniffer, /* core_sniffer */ | |
113 | fetch_core_registers, /* core_read_registers */ | |
114 | NULL /* next */ | |
c906108c SS |
115 | }; |
116 | ||
94ba74a9 MK |
117 | /* Provide a prototype to silence -Wmissing-prototypes. */ |
118 | extern void _initialize_core_regset (void); | |
119 | ||
c906108c | 120 | void |
fba45db2 | 121 | _initialize_core_regset (void) |
c906108c | 122 | { |
00e32a35 | 123 | deprecated_add_core_fns (®set_core_fns); |
c906108c | 124 | } |