]>
Commit | Line | Data |
---|---|---|
c906108c | 1 | /* Machine independent support for Solaris 2 core files for GDB. |
23e04971 | 2 | Copyright 1994, 2000 Free Software Foundation, Inc. |
c906108c | 3 | |
c5aa993b | 4 | This file is part of GDB. |
c906108c | 5 | |
c5aa993b JM |
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. | |
c906108c | 10 | |
c5aa993b JM |
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. | |
c906108c | 15 | |
c5aa993b JM |
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. */ | |
c906108c SS |
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 | ||
23e04971 MS |
29 | /* for Sparc64 cross Sparc32 */ |
30 | #define _SYSCALL32 | |
c906108c | 31 | #include "defs.h" |
23e04971 MS |
32 | |
33 | #if defined (__sparcv9) | |
34 | /* Fails to get included by the Solaris system header files. */ | |
35 | # include <v9/sys/privregs.h> | |
36 | #endif | |
37 | ||
c906108c SS |
38 | #include <time.h> |
39 | #include <sys/types.h> | |
40 | #include <sys/regset.h> | |
41 | #include <sys/procfs.h> | |
42 | #include <fcntl.h> | |
43 | #include <errno.h> | |
44 | #include "gdb_string.h" | |
45 | ||
46 | #include "inferior.h" | |
47 | #include "target.h" | |
48 | #include "command.h" | |
49 | #include "gdbcore.h" | |
50 | ||
c60c0f5f MS |
51 | /* Prototypes for supply_gregset etc. */ |
52 | #include "gregset.h" | |
53 | ||
a14ed312 | 54 | static void fetch_core_registers (char *, unsigned, int, CORE_ADDR); |
c906108c | 55 | |
dbb41be1 KB |
56 | /* Fetch registers from core file data pointed to by CORE_REG_SECT. When |
57 | WHICH is 0, the the general register set is fetched; when WHICH is | |
58 | 2, the floating point registers are fetched. CORE_REG_SIZE is used | |
59 | to validate the size of the data pointed to by CORE_REG_SECT. REG_ADDR | |
60 | is unused. */ | |
61 | ||
c906108c | 62 | static void |
dbb41be1 KB |
63 | fetch_core_registers (char *core_reg_sect, unsigned core_reg_size, int which, |
64 | CORE_ADDR reg_addr) | |
c906108c | 65 | { |
23e04971 | 66 | int i; |
c906108c SS |
67 | |
68 | if (which == 0) | |
69 | { | |
23e04971 MS |
70 | prgregset_t prgregset; |
71 | ||
72 | if (core_reg_size == sizeof (prgregset_t)) | |
c906108c SS |
73 | { |
74 | memcpy ((char *) &prgregset, core_reg_sect, sizeof (prgregset)); | |
75 | supply_gregset (&prgregset); | |
76 | } | |
23e04971 MS |
77 | #if defined (HAVE_PRGREGSET32_T) |
78 | /* 32-bit corefile, 64-bit debugger. */ | |
79 | else if (core_reg_size == sizeof (prgregset32_t)) | |
80 | { | |
81 | prgreg32_t *core_gregs; | |
82 | ||
83 | /* Can't use memcpy here, because the core file contains | |
84 | 32-bit regs; supply_register expects 64-bit regs. */ | |
85 | core_gregs = (prgreg32_t *) core_reg_sect; | |
86 | for (i = 0; i < NPRGREG; i++) | |
87 | prgregset[i] = core_gregs[i]; | |
88 | ||
89 | supply_gregset (&prgregset); | |
90 | } | |
91 | #endif /* HAVE_PRGREGSET32_T */ | |
c906108c SS |
92 | else if (core_reg_size == sizeof (struct regs)) |
93 | { | |
23e04971 MS |
94 | struct regs *gregs = (struct regs *) core_reg_sect; |
95 | ||
c906108c | 96 | /* G0 *always* holds 0. */ |
c5aa993b | 97 | *(int *) ®isters[REGISTER_BYTE (0)] = 0; |
c906108c SS |
98 | |
99 | /* The globals and output registers. */ | |
c5aa993b | 100 | memcpy (®isters[REGISTER_BYTE (G1_REGNUM)], &gregs->r_g1, |
c906108c | 101 | 15 * REGISTER_RAW_SIZE (G1_REGNUM)); |
c5aa993b JM |
102 | *(int *) ®isters[REGISTER_BYTE (PS_REGNUM)] = gregs->r_ps; |
103 | *(int *) ®isters[REGISTER_BYTE (PC_REGNUM)] = gregs->r_pc; | |
104 | *(int *) ®isters[REGISTER_BYTE (NPC_REGNUM)] = gregs->r_npc; | |
105 | *(int *) ®isters[REGISTER_BYTE (Y_REGNUM)] = gregs->r_y; | |
c906108c SS |
106 | |
107 | /* My best guess at where to get the locals and input | |
108 | registers is exactly where they usually are, right above | |
109 | the stack pointer. If the core dump was caused by a bus error | |
110 | from blowing away the stack pointer (as is possible) then this | |
111 | won't work, but it's worth the try. */ | |
112 | { | |
113 | int sp; | |
114 | ||
c5aa993b | 115 | sp = *(int *) ®isters[REGISTER_BYTE (SP_REGNUM)]; |
c906108c | 116 | if (0 != target_read_memory (sp, |
c5aa993b | 117 | ®isters[REGISTER_BYTE (L0_REGNUM)], |
c906108c SS |
118 | 16 * REGISTER_RAW_SIZE (L0_REGNUM))) |
119 | { | |
120 | warning ("couldn't read input and local registers from core file\n"); | |
121 | } | |
122 | } | |
123 | } | |
124 | else | |
125 | { | |
126 | warning ("wrong size gregset struct in core file"); | |
127 | } | |
128 | } | |
129 | else if (which == 2) | |
130 | { | |
23e04971 MS |
131 | prfpregset_t prfpregset; |
132 | ||
133 | if (core_reg_size == sizeof (prfpregset_t)) | |
c906108c SS |
134 | { |
135 | memcpy ((char *) &prfpregset, core_reg_sect, sizeof (prfpregset)); | |
136 | supply_fpregset (&prfpregset); | |
137 | } | |
23e04971 MS |
138 | #if defined (HAVE_PRFPREGSET32_T) |
139 | /* 32-bit corefile, 64-bit debugger. */ | |
140 | else if (core_reg_size == sizeof (prfpregset32_t)) | |
141 | { | |
142 | prfpregset32_t *core_fpregset; | |
143 | ||
144 | /* Can't use memcpy here, because the core file contains | |
145 | 32-bit regs; supply_fpregset expects 64-bit regs. */ | |
146 | ||
147 | core_fpregset = (prfpregset32_t *) core_reg_sect; | |
148 | for (i = 0; i < 16; i++) | |
149 | prfpregset.pr_fr.pr_dregs[i] = core_fpregset->pr_fr.pr_dregs[i]; | |
150 | while (i < 32) | |
151 | prfpregset.pr_fr.pr_dregs[i++] = 0; | |
152 | ||
153 | prfpregset.pr_fsr = core_fpregset->pr_fsr; | |
154 | prfpregset.pr_qcnt = core_fpregset->pr_qcnt; | |
155 | prfpregset.pr_q_entrysize = core_fpregset->pr_q_entrysize; | |
156 | prfpregset.pr_en = core_fpregset->pr_en; | |
157 | /* We will not use the pr_q array. */ | |
158 | ||
159 | supply_fpregset (&prfpregset); | |
160 | } | |
161 | #endif /* HAVE_PRFPREGSET32_T */ | |
c906108c SS |
162 | else if (core_reg_size >= sizeof (struct fpu)) |
163 | { | |
23e04971 MS |
164 | struct fpu *fpuregs = (struct fpu *) core_reg_sect; |
165 | ||
c906108c SS |
166 | memcpy (®isters[REGISTER_BYTE (FP0_REGNUM)], &fpuregs->fpu_fr, |
167 | sizeof (fpuregs->fpu_fr)); | |
168 | memcpy (®isters[REGISTER_BYTE (FPS_REGNUM)], &fpuregs->fpu_fsr, | |
169 | sizeof (FPU_FSR_TYPE)); | |
170 | } | |
171 | else | |
172 | { | |
173 | warning ("wrong size fpregset struct in core file"); | |
174 | } | |
175 | } | |
176 | } | |
c906108c | 177 | \f |
c5aa993b | 178 | |
c906108c SS |
179 | /* Register that we are able to handle solaris core file formats. */ |
180 | ||
181 | static struct core_fns solaris_core_fns = | |
182 | { | |
2acceee2 JM |
183 | bfd_target_elf_flavour, /* core_flavour */ |
184 | default_check_format, /* check_format */ | |
185 | default_core_sniffer, /* core_sniffer */ | |
186 | fetch_core_registers, /* core_read_registers */ | |
187 | NULL /* next */ | |
c906108c SS |
188 | }; |
189 | ||
190 | void | |
fba45db2 | 191 | _initialize_core_solaris (void) |
c906108c SS |
192 | { |
193 | add_core_fns (&solaris_core_fns); | |
194 | } |