Include string.h in common-defs.h
[binutils-gdb.git] / gdb / core-regset.c
1 /* Machine independent GDB support for core files on systems using "regsets".
2
3 Copyright (C) 1993-2014 Free Software Foundation, Inc.
4
5 This file is part of GDB.
6
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
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
11
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.
16
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
19
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. */
28
29 #include "defs.h"
30 #include "command.h"
31 #include "gdbcore.h"
32 #include "inferior.h"
33 #include "target.h"
34 #include "regcache.h"
35
36 #include <fcntl.h>
37 #include <errno.h>
38 #include <time.h>
39 #ifdef HAVE_SYS_PROCFS_H
40 #include <sys/procfs.h>
41 #endif
42
43 /* Prototypes for supply_gregset etc. */
44 #include "gregset.h"
45
46 /* Provide registers to GDB from a core file.
47
48 CORE_REG_SECT points to an array of bytes, which are the contents
49 of a `note' from a core file which BFD thinks might contain
50 register contents. CORE_REG_SIZE is its size.
51
52 WHICH says which register set corelow suspects this is:
53 0 --- the general-purpose register set, in gregset_t format
54 2 --- the floating-point register set, in fpregset_t format
55
56 REG_ADDR is ignored. */
57
58 static void
59 fetch_core_registers (struct regcache *regcache,
60 char *core_reg_sect,
61 unsigned core_reg_size,
62 int which,
63 CORE_ADDR reg_addr)
64 {
65 gdb_gregset_t gregset;
66 gdb_fpregset_t fpregset;
67 gdb_gregset_t *gregset_p = &gregset;
68 gdb_fpregset_t *fpregset_p = &fpregset;
69
70 switch (which)
71 {
72 case 0:
73 if (core_reg_size != sizeof (gregset))
74 warning (_("Wrong size gregset in core file."));
75 else
76 {
77 memcpy (&gregset, core_reg_sect, sizeof (gregset));
78 supply_gregset (regcache, (const gdb_gregset_t *) gregset_p);
79 }
80 break;
81
82 case 2:
83 if (core_reg_size != sizeof (fpregset))
84 warning (_("Wrong size fpregset in core file."));
85 else
86 {
87 memcpy (&fpregset, core_reg_sect, sizeof (fpregset));
88 if (gdbarch_fp0_regnum (get_regcache_arch (regcache)) >= 0)
89 supply_fpregset (regcache,
90 (const gdb_fpregset_t *) fpregset_p);
91 }
92 break;
93
94 default:
95 /* We've covered all the kinds of registers we know about here,
96 so this must be something we wouldn't know what to do with
97 anyway. Just ignore it. */
98 break;
99 }
100 }
101 \f
102
103 /* Register that we are able to handle ELF core file formats using
104 standard procfs "regset" structures. */
105
106 static struct core_fns regset_core_fns =
107 {
108 bfd_target_elf_flavour, /* core_flavour */
109 default_check_format, /* check_format */
110 default_core_sniffer, /* core_sniffer */
111 fetch_core_registers, /* core_read_registers */
112 NULL /* next */
113 };
114
115 /* Provide a prototype to silence -Wmissing-prototypes. */
116 extern void _initialize_core_regset (void);
117
118 void
119 _initialize_core_regset (void)
120 {
121 deprecated_add_core_fns (&regset_core_fns);
122 }