2007-07-01 H.J. Lu <hongjiu.lu@intel.com>
[deliverable/binutils-gdb.git] / gdb / core-regset.c
... / ...
CommitLineData
1/* Machine independent GDB support for core files on systems using "regsets".
2
3 Copyright (C) 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2003, 2007
4 Free Software Foundation, Inc.
5
6 This file is part of GDB.
7
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
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
12
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.
17
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 Boston, MA 02110-1301, USA. */
22
23/* This file is used by most systems that use ELF for their core
24 dumps. This includes most systems that have SVR4-ish variant of
25 /proc. For these systems, the registers are laid out the same way
26 in core files as in the gregset_t and fpregset_t structures that
27 are used in the interaction with /proc (Irix 4 is an exception and
28 therefore doesn't use this file). Quite a few systems without a
29 SVR4-ish /proc define these structures too, and can make use of
30 this code too. */
31
32#include "defs.h"
33#include "command.h"
34#include "gdbcore.h"
35#include "inferior.h"
36#include "target.h"
37#include "regcache.h"
38
39#include <fcntl.h>
40#include <errno.h>
41#include "gdb_string.h"
42#include <time.h>
43#ifdef HAVE_SYS_PROCFS_H
44#include <sys/procfs.h>
45#endif
46
47/* Prototypes for supply_gregset etc. */
48#include "gregset.h"
49
50/* Provide registers to GDB from a core file.
51
52 CORE_REG_SECT points to an array of bytes, which are the contents
53 of a `note' from a core file which BFD thinks might contain
54 register contents. CORE_REG_SIZE is its size.
55
56 WHICH says which register set corelow suspects this is:
57 0 --- the general-purpose register set, in gregset_t format
58 2 --- the floating-point register set, in fpregset_t format
59
60 REG_ADDR is ignored. */
61
62static void
63fetch_core_registers (struct regcache *regcache,
64 char *core_reg_sect, unsigned core_reg_size, int which,
65 CORE_ADDR reg_addr)
66{
67 gdb_gregset_t gregset;
68 gdb_fpregset_t fpregset;
69 gdb_gregset_t *gregset_p = &gregset;
70 gdb_fpregset_t *fpregset_p = &fpregset;
71
72 switch (which)
73 {
74 case 0:
75 if (core_reg_size != sizeof (gregset))
76 warning (_("Wrong size gregset in core file."));
77 else
78 {
79 memcpy (&gregset, core_reg_sect, sizeof (gregset));
80 supply_gregset (regcache, (const gdb_gregset_t *) gregset_p);
81 }
82 break;
83
84 case 2:
85 if (core_reg_size != sizeof (fpregset))
86 warning (_("Wrong size fpregset in core file."));
87 else
88 {
89 memcpy (&fpregset, core_reg_sect, sizeof (fpregset));
90 if (gdbarch_fp0_regnum (current_gdbarch) >= 0)
91 supply_fpregset (regcache, (const gdb_fpregset_t *) fpregset_p);
92 }
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;
100 }
101}
102\f
103
104/* Register that we are able to handle ELF core file formats using
105 standard procfs "regset" structures. */
106
107static struct core_fns regset_core_fns =
108{
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 */
114};
115
116/* Provide a prototype to silence -Wmissing-prototypes. */
117extern void _initialize_core_regset (void);
118
119void
120_initialize_core_regset (void)
121{
122 deprecated_add_core_fns (&regset_core_fns);
123}
This page took 0.022895 seconds and 4 git commands to generate.