Rename gdbarch_update() to gdbarch_update_p()
[deliverable/binutils-gdb.git] / gdb / core-sol2.c
1 /* Machine independent support for Solaris 2 core files for GDB.
2 Copyright 1994 Free Software Foundation, Inc.
3
4 This file is part of GDB.
5
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.
10
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.
15
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. */
20
21
22 /* Solaris comes with two flavours of core files, cores generated by
23 an ELF executable and cores generated by programs that were
24 run under BCP (the part of Solaris which allows it to run SunOS4
25 a.out files).
26 This file combines the core register fetching from core-regset.c
27 and sparc-nat.c to be able to read both flavours. */
28
29 #include "defs.h"
30 #include <time.h>
31 #include <sys/types.h>
32 #include <sys/regset.h>
33 #include <sys/procfs.h>
34 #include <fcntl.h>
35 #include <errno.h>
36 #include "gdb_string.h"
37
38 #include "inferior.h"
39 #include "target.h"
40 #include "command.h"
41 #include "gdbcore.h"
42
43 /* Prototypes for supply_gregset etc. */
44 #include "gregset.h"
45
46 static void fetch_core_registers (char *, unsigned, int, CORE_ADDR);
47
48 /* Fetch registers from core file data pointed to by CORE_REG_SECT. When
49 WHICH is 0, the the general register set is fetched; when WHICH is
50 2, the floating point registers are fetched. CORE_REG_SIZE is used
51 to validate the size of the data pointed to by CORE_REG_SECT. REG_ADDR
52 is unused. */
53
54 static void
55 fetch_core_registers (char *core_reg_sect, unsigned core_reg_size, int which,
56 CORE_ADDR reg_addr)
57 {
58 prgregset_t prgregset;
59 prfpregset_t prfpregset;
60
61 if (which == 0)
62 {
63 if (core_reg_size == sizeof (prgregset))
64 {
65 memcpy ((char *) &prgregset, core_reg_sect, sizeof (prgregset));
66 supply_gregset (&prgregset);
67 }
68 else if (core_reg_size == sizeof (struct regs))
69 {
70 #define gregs ((struct regs *)core_reg_sect)
71 /* G0 *always* holds 0. */
72 *(int *) &registers[REGISTER_BYTE (0)] = 0;
73
74 /* The globals and output registers. */
75 memcpy (&registers[REGISTER_BYTE (G1_REGNUM)], &gregs->r_g1,
76 15 * REGISTER_RAW_SIZE (G1_REGNUM));
77 *(int *) &registers[REGISTER_BYTE (PS_REGNUM)] = gregs->r_ps;
78 *(int *) &registers[REGISTER_BYTE (PC_REGNUM)] = gregs->r_pc;
79 *(int *) &registers[REGISTER_BYTE (NPC_REGNUM)] = gregs->r_npc;
80 *(int *) &registers[REGISTER_BYTE (Y_REGNUM)] = gregs->r_y;
81
82 /* My best guess at where to get the locals and input
83 registers is exactly where they usually are, right above
84 the stack pointer. If the core dump was caused by a bus error
85 from blowing away the stack pointer (as is possible) then this
86 won't work, but it's worth the try. */
87 {
88 int sp;
89
90 sp = *(int *) &registers[REGISTER_BYTE (SP_REGNUM)];
91 if (0 != target_read_memory (sp,
92 &registers[REGISTER_BYTE (L0_REGNUM)],
93 16 * REGISTER_RAW_SIZE (L0_REGNUM)))
94 {
95 warning ("couldn't read input and local registers from core file\n");
96 }
97 }
98 }
99 else
100 {
101 warning ("wrong size gregset struct in core file");
102 }
103 }
104 else if (which == 2)
105 {
106 if (core_reg_size == sizeof (prfpregset))
107 {
108 memcpy ((char *) &prfpregset, core_reg_sect, sizeof (prfpregset));
109 supply_fpregset (&prfpregset);
110 }
111 else if (core_reg_size >= sizeof (struct fpu))
112 {
113 #define fpuregs ((struct fpu *) core_reg_sect)
114 memcpy (&registers[REGISTER_BYTE (FP0_REGNUM)], &fpuregs->fpu_fr,
115 sizeof (fpuregs->fpu_fr));
116 memcpy (&registers[REGISTER_BYTE (FPS_REGNUM)], &fpuregs->fpu_fsr,
117 sizeof (FPU_FSR_TYPE));
118 }
119 else
120 {
121 warning ("wrong size fpregset struct in core file");
122 }
123 }
124 }
125 \f
126
127 /* Register that we are able to handle solaris core file formats. */
128
129 static struct core_fns solaris_core_fns =
130 {
131 bfd_target_elf_flavour, /* core_flavour */
132 default_check_format, /* check_format */
133 default_core_sniffer, /* core_sniffer */
134 fetch_core_registers, /* core_read_registers */
135 NULL /* next */
136 };
137
138 void
139 _initialize_core_solaris (void)
140 {
141 add_core_fns (&solaris_core_fns);
142 }
This page took 0.032176 seconds and 4 git commands to generate.