]>
Commit | Line | Data |
---|---|---|
252b5132 | 1 | /* BFD back-end for OSF/1 core files. |
117ed4f8 | 2 | Copyright 1993, 1994, 1995, 1998, 1999, 2001, 2002, 2003, 2004, 2006 |
dc810e39 | 3 | Free Software Foundation, Inc. |
252b5132 RH |
4 | |
5 | This file is part of BFD, the Binary File Descriptor library. | |
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 2 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, write to the Free Software | |
3e110533 | 19 | Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ |
252b5132 RH |
20 | |
21 | /* This file can only be compiled on systems which use OSF/1 style | |
22 | core files. */ | |
23 | ||
24 | #include "bfd.h" | |
25 | #include "sysdep.h" | |
26 | #include "libbfd.h" | |
27 | ||
28 | #include <sys/user.h> | |
9b818146 | 29 | #ifdef OSF_CORE |
252b5132 | 30 | #include <sys/core.h> |
9b818146 | 31 | #endif |
252b5132 RH |
32 | |
33 | /* forward declarations */ | |
34 | ||
3f3c5c34 AM |
35 | static asection *make_bfd_asection |
36 | PARAMS ((bfd *, const char *, flagword, bfd_size_type, bfd_vma, file_ptr)); | |
b34976b6 AM |
37 | static const bfd_target *osf_core_core_file_p |
38 | PARAMS ((bfd *)); | |
39 | static char *osf_core_core_file_failing_command | |
40 | PARAMS ((bfd *)); | |
41 | static int osf_core_core_file_failing_signal | |
42 | PARAMS ((bfd *)); | |
69d246d9 | 43 | #define osf_core_core_file_matches_executable_p generic_core_file_matches_executable_p |
b34976b6 AM |
44 | static void swap_abort |
45 | PARAMS ((void)); | |
252b5132 RH |
46 | |
47 | /* These are stored in the bfd's tdata */ | |
48 | ||
dc810e39 | 49 | struct osf_core_struct |
252b5132 RH |
50 | { |
51 | int sig; | |
52 | char cmd[MAXCOMLEN + 1]; | |
53 | }; | |
54 | ||
55 | #define core_hdr(bfd) ((bfd)->tdata.osf_core_data) | |
56 | #define core_signal(bfd) (core_hdr(bfd)->sig) | |
57 | #define core_command(bfd) (core_hdr(bfd)->cmd) | |
58 | ||
59 | static asection * | |
eea6121a | 60 | make_bfd_asection (abfd, name, flags, size, vma, filepos) |
252b5132 | 61 | bfd *abfd; |
dc810e39 | 62 | const char *name; |
252b5132 | 63 | flagword flags; |
eea6121a | 64 | bfd_size_type size; |
252b5132 RH |
65 | bfd_vma vma; |
66 | file_ptr filepos; | |
67 | { | |
68 | asection *asect; | |
69 | ||
117ed4f8 | 70 | asect = bfd_make_section_anyway_with_flags (abfd, name, flags); |
252b5132 RH |
71 | if (!asect) |
72 | return NULL; | |
73 | ||
eea6121a | 74 | asect->size = size; |
252b5132 RH |
75 | asect->vma = vma; |
76 | asect->filepos = filepos; | |
77 | asect->alignment_power = 8; | |
78 | ||
79 | return asect; | |
80 | } | |
81 | ||
252b5132 RH |
82 | static const bfd_target * |
83 | osf_core_core_file_p (abfd) | |
84 | bfd *abfd; | |
85 | { | |
86 | int val; | |
87 | int i; | |
88 | char *secname; | |
89 | struct core_filehdr core_header; | |
dc810e39 | 90 | bfd_size_type amt; |
252b5132 | 91 | |
dc810e39 AM |
92 | amt = sizeof core_header; |
93 | val = bfd_bread ((PTR) &core_header, amt, abfd); | |
252b5132 RH |
94 | if (val != sizeof core_header) |
95 | return NULL; | |
96 | ||
0112cd26 | 97 | if (! CONST_STRNEQ (core_header.magic, "Core")) |
252b5132 RH |
98 | return NULL; |
99 | ||
100 | core_hdr (abfd) = (struct osf_core_struct *) | |
dc810e39 | 101 | bfd_zalloc (abfd, (bfd_size_type) sizeof (struct osf_core_struct)); |
252b5132 RH |
102 | if (!core_hdr (abfd)) |
103 | return NULL; | |
104 | ||
105 | strncpy (core_command (abfd), core_header.name, MAXCOMLEN + 1); | |
106 | core_signal (abfd) = core_header.signo; | |
107 | ||
108 | for (i = 0; i < core_header.nscns; i++) | |
109 | { | |
110 | struct core_scnhdr core_scnhdr; | |
111 | flagword flags; | |
112 | ||
dc810e39 AM |
113 | amt = sizeof core_scnhdr; |
114 | val = bfd_bread ((PTR) &core_scnhdr, amt, abfd); | |
252b5132 RH |
115 | if (val != sizeof core_scnhdr) |
116 | break; | |
117 | ||
118 | /* Skip empty sections. */ | |
119 | if (core_scnhdr.size == 0 || core_scnhdr.scnptr == 0) | |
120 | continue; | |
121 | ||
122 | switch (core_scnhdr.scntype) | |
123 | { | |
124 | case SCNRGN: | |
125 | secname = ".data"; | |
126 | flags = SEC_ALLOC + SEC_LOAD + SEC_HAS_CONTENTS; | |
127 | break; | |
128 | case SCNSTACK: | |
129 | secname = ".stack"; | |
130 | flags = SEC_ALLOC + SEC_LOAD + SEC_HAS_CONTENTS; | |
131 | break; | |
132 | case SCNREGS: | |
133 | secname = ".reg"; | |
134 | flags = SEC_HAS_CONTENTS; | |
135 | break; | |
136 | default: | |
137 | (*_bfd_error_handler) (_("Unhandled OSF/1 core file section type %d\n"), | |
138 | core_scnhdr.scntype); | |
139 | continue; | |
140 | } | |
141 | ||
142 | if (!make_bfd_asection (abfd, secname, flags, | |
143 | (bfd_size_type) core_scnhdr.size, | |
144 | (bfd_vma) core_scnhdr.vaddr, | |
145 | (file_ptr) core_scnhdr.scnptr)) | |
9e7b37b3 | 146 | goto fail; |
252b5132 RH |
147 | } |
148 | ||
149 | /* OK, we believe you. You're a core file (sure, sure). */ | |
150 | ||
151 | return abfd->xvec; | |
9e7b37b3 AM |
152 | |
153 | fail: | |
154 | bfd_release (abfd, core_hdr (abfd)); | |
155 | core_hdr (abfd) = NULL; | |
156 | bfd_section_list_clear (abfd); | |
157 | return NULL; | |
252b5132 RH |
158 | } |
159 | ||
160 | static char * | |
161 | osf_core_core_file_failing_command (abfd) | |
162 | bfd *abfd; | |
163 | { | |
164 | return core_command (abfd); | |
165 | } | |
166 | ||
252b5132 RH |
167 | static int |
168 | osf_core_core_file_failing_signal (abfd) | |
169 | bfd *abfd; | |
170 | { | |
171 | return core_signal (abfd); | |
172 | } | |
252b5132 | 173 | \f |
252b5132 RH |
174 | /* If somebody calls any byte-swapping routines, shoot them. */ |
175 | static void | |
176 | swap_abort() | |
177 | { | |
178 | abort(); /* This way doesn't require any declaration for ANSI to fuck up */ | |
179 | } | |
8ce8c090 | 180 | |
edeb6e24 AM |
181 | #define NO_GET ((bfd_vma (*) (const void *)) swap_abort) |
182 | #define NO_PUT ((void (*) (bfd_vma, void *)) swap_abort) | |
183 | #define NO_GETS ((bfd_signed_vma (*) (const void *)) swap_abort) | |
8ce8c090 AM |
184 | #define NO_GET64 ((bfd_uint64_t (*) (const void *)) swap_abort) |
185 | #define NO_PUT64 ((void (*) (bfd_uint64_t, void *)) swap_abort) | |
186 | #define NO_GETS64 ((bfd_int64_t (*) (const void *)) swap_abort) | |
252b5132 RH |
187 | |
188 | const bfd_target osf_core_vec = | |
189 | { | |
190 | "osf-core", | |
191 | bfd_target_unknown_flavour, | |
a68d41fb AM |
192 | BFD_ENDIAN_LITTLE, /* target byte order */ |
193 | BFD_ENDIAN_LITTLE, /* target headers byte order */ | |
252b5132 RH |
194 | (HAS_RELOC | EXEC_P | /* object flags */ |
195 | HAS_LINENO | HAS_DEBUG | | |
196 | HAS_SYMS | HAS_LOCALS | WP_TEXT | D_PAGED), | |
197 | (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */ | |
198 | 0, /* symbol prefix */ | |
199 | ' ', /* ar_pad_char */ | |
200 | 16, /* ar_max_namelen */ | |
8ce8c090 | 201 | NO_GET64, NO_GETS64, NO_PUT64, /* 64 bit data */ |
edeb6e24 AM |
202 | NO_GET, NO_GETS, NO_PUT, /* 32 bit data */ |
203 | NO_GET, NO_GETS, NO_PUT, /* 16 bit data */ | |
8ce8c090 | 204 | NO_GET64, NO_GETS64, NO_PUT64, /* 64 bit hdrs */ |
edeb6e24 AM |
205 | NO_GET, NO_GETS, NO_PUT, /* 32 bit hdrs */ |
206 | NO_GET, NO_GETS, NO_PUT, /* 16 bit hdrs */ | |
252b5132 RH |
207 | |
208 | { /* bfd_check_format */ | |
8ce8c090 AM |
209 | _bfd_dummy_target, /* unknown format */ |
210 | _bfd_dummy_target, /* object file */ | |
211 | _bfd_dummy_target, /* archive */ | |
212 | osf_core_core_file_p /* a core file */ | |
252b5132 RH |
213 | }, |
214 | { /* bfd_set_format */ | |
8ce8c090 AM |
215 | bfd_false, bfd_false, |
216 | bfd_false, bfd_false | |
252b5132 RH |
217 | }, |
218 | { /* bfd_write_contents */ | |
8ce8c090 AM |
219 | bfd_false, bfd_false, |
220 | bfd_false, bfd_false | |
252b5132 | 221 | }, |
dc810e39 | 222 | |
3f3c5c34 AM |
223 | BFD_JUMP_TABLE_GENERIC (_bfd_generic), |
224 | BFD_JUMP_TABLE_COPY (_bfd_generic), | |
225 | BFD_JUMP_TABLE_CORE (osf_core), | |
226 | BFD_JUMP_TABLE_ARCHIVE (_bfd_noarchive), | |
227 | BFD_JUMP_TABLE_SYMBOLS (_bfd_nosymbols), | |
228 | BFD_JUMP_TABLE_RELOCS (_bfd_norelocs), | |
229 | BFD_JUMP_TABLE_WRITE (_bfd_generic), | |
230 | BFD_JUMP_TABLE_LINK (_bfd_nolink), | |
231 | BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic), | |
252b5132 | 232 | |
c3c89269 | 233 | NULL, |
dc810e39 | 234 | |
252b5132 | 235 | (PTR) 0 /* backend_data */ |
8ce8c090 | 236 | }; |