]>
Commit | Line | Data |
---|---|---|
c906108c SS |
1 | /* Machine independent support for Solaris 2 core files for GDB. |
2 | Copyright 1994 Free Software Foundation, Inc. | |
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 | ||
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 | ||
c60c0f5f MS |
43 | /* Prototypes for supply_gregset etc. */ |
44 | #include "gregset.h" | |
45 | ||
a14ed312 | 46 | static void fetch_core_registers (char *, unsigned, int, CORE_ADDR); |
c906108c SS |
47 | |
48 | static void | |
49 | fetch_core_registers (core_reg_sect, core_reg_size, which, reg_addr) | |
50 | char *core_reg_sect; | |
51 | unsigned core_reg_size; | |
52 | int which; | |
53 | CORE_ADDR reg_addr; /* Unused in this version */ | |
54 | { | |
55 | prgregset_t prgregset; | |
56 | prfpregset_t prfpregset; | |
57 | ||
58 | if (which == 0) | |
59 | { | |
60 | if (core_reg_size == sizeof (prgregset)) | |
61 | { | |
62 | memcpy ((char *) &prgregset, core_reg_sect, sizeof (prgregset)); | |
63 | supply_gregset (&prgregset); | |
64 | } | |
65 | else if (core_reg_size == sizeof (struct regs)) | |
66 | { | |
67 | #define gregs ((struct regs *)core_reg_sect) | |
68 | /* G0 *always* holds 0. */ | |
c5aa993b | 69 | *(int *) ®isters[REGISTER_BYTE (0)] = 0; |
c906108c SS |
70 | |
71 | /* The globals and output registers. */ | |
c5aa993b | 72 | memcpy (®isters[REGISTER_BYTE (G1_REGNUM)], &gregs->r_g1, |
c906108c | 73 | 15 * REGISTER_RAW_SIZE (G1_REGNUM)); |
c5aa993b JM |
74 | *(int *) ®isters[REGISTER_BYTE (PS_REGNUM)] = gregs->r_ps; |
75 | *(int *) ®isters[REGISTER_BYTE (PC_REGNUM)] = gregs->r_pc; | |
76 | *(int *) ®isters[REGISTER_BYTE (NPC_REGNUM)] = gregs->r_npc; | |
77 | *(int *) ®isters[REGISTER_BYTE (Y_REGNUM)] = gregs->r_y; | |
c906108c SS |
78 | |
79 | /* My best guess at where to get the locals and input | |
80 | registers is exactly where they usually are, right above | |
81 | the stack pointer. If the core dump was caused by a bus error | |
82 | from blowing away the stack pointer (as is possible) then this | |
83 | won't work, but it's worth the try. */ | |
84 | { | |
85 | int sp; | |
86 | ||
c5aa993b | 87 | sp = *(int *) ®isters[REGISTER_BYTE (SP_REGNUM)]; |
c906108c | 88 | if (0 != target_read_memory (sp, |
c5aa993b | 89 | ®isters[REGISTER_BYTE (L0_REGNUM)], |
c906108c SS |
90 | 16 * REGISTER_RAW_SIZE (L0_REGNUM))) |
91 | { | |
92 | warning ("couldn't read input and local registers from core file\n"); | |
93 | } | |
94 | } | |
95 | } | |
96 | else | |
97 | { | |
98 | warning ("wrong size gregset struct in core file"); | |
99 | } | |
100 | } | |
101 | else if (which == 2) | |
102 | { | |
103 | if (core_reg_size == sizeof (prfpregset)) | |
104 | { | |
105 | memcpy ((char *) &prfpregset, core_reg_sect, sizeof (prfpregset)); | |
106 | supply_fpregset (&prfpregset); | |
107 | } | |
108 | else if (core_reg_size >= sizeof (struct fpu)) | |
109 | { | |
110 | #define fpuregs ((struct fpu *) core_reg_sect) | |
111 | memcpy (®isters[REGISTER_BYTE (FP0_REGNUM)], &fpuregs->fpu_fr, | |
112 | sizeof (fpuregs->fpu_fr)); | |
113 | memcpy (®isters[REGISTER_BYTE (FPS_REGNUM)], &fpuregs->fpu_fsr, | |
114 | sizeof (FPU_FSR_TYPE)); | |
115 | } | |
116 | else | |
117 | { | |
118 | warning ("wrong size fpregset struct in core file"); | |
119 | } | |
120 | } | |
121 | } | |
c906108c | 122 | \f |
c5aa993b | 123 | |
c906108c SS |
124 | /* Register that we are able to handle solaris core file formats. */ |
125 | ||
126 | static struct core_fns solaris_core_fns = | |
127 | { | |
2acceee2 JM |
128 | bfd_target_elf_flavour, /* core_flavour */ |
129 | default_check_format, /* check_format */ | |
130 | default_core_sniffer, /* core_sniffer */ | |
131 | fetch_core_registers, /* core_read_registers */ | |
132 | NULL /* next */ | |
c906108c SS |
133 | }; |
134 | ||
135 | void | |
136 | _initialize_core_solaris () | |
137 | { | |
138 | add_core_fns (&solaris_core_fns); | |
139 | } |