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