]>
Commit | Line | Data |
---|---|---|
fe16107d C |
1 | /* BFD back end for NetBSD style core files |
2 | Copyright 1988, 1989, 1991, 1992, 1993 Free Software Foundation, Inc. | |
3 | Written by Paul Kranenburg, EUR | |
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 | |
19 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ | |
20 | ||
21 | #include "bfd.h" | |
22 | #include "sysdep.h" | |
23 | #include "libbfd.h" | |
24 | #include "libaout.h" /* BFD a.out internal data structures */ | |
25 | ||
26 | #include <stdio.h> | |
27 | #include <sys/types.h> | |
28 | #include <sys/param.h> | |
29 | #include <sys/dir.h> | |
30 | #include <signal.h> | |
31 | #include <sys/core.h> | |
32 | #include <errno.h> | |
33 | ||
34 | /* | |
35 | * FIXME: On NetBSD/sparc CORE_FPU_OFFSET should be (sizeof(struct trapframe)) | |
36 | */ | |
37 | ||
38 | struct netbsd_core_struct { | |
39 | struct core core; | |
40 | } *rawptr; | |
41 | ||
42 | /* forward declarations */ | |
43 | ||
44 | static const bfd_target * netbsd_core_core_file_p PARAMS ((bfd *abfd)); | |
45 | static char * netbsd_core_core_file_failing_command PARAMS ((bfd *abfd)); | |
46 | static int netbsd_core_core_file_failing_signal PARAMS ((bfd *abfd)); | |
47 | static boolean netbsd_core_core_file_matches_executable_p | |
48 | PARAMS ((bfd *core_bfd, bfd *exec_bfd)); | |
49 | ||
50 | /* Handle NetBSD-style core dump file. */ | |
51 | ||
52 | /* ARGSUSED */ | |
53 | static const bfd_target * | |
54 | netbsd_core_core_file_p (abfd) | |
55 | bfd *abfd; | |
56 | ||
57 | { | |
58 | int i, val, offset; | |
59 | asection *asect, *asect2; | |
60 | struct core core; | |
61 | struct coreseg coreseg; | |
62 | ||
63 | val = bfd_read ((void *)&core, 1, sizeof core, abfd); | |
64 | if (val != sizeof core) { | |
65 | /* Too small to be a core file */ | |
66 | bfd_set_error(bfd_error_wrong_format); | |
67 | return 0; | |
68 | } | |
69 | ||
70 | if (CORE_GETMAGIC(core) != COREMAGIC) { | |
71 | bfd_set_error(bfd_error_wrong_format); | |
72 | return 0; | |
73 | } | |
74 | ||
75 | rawptr = (struct netbsd_core_struct *) | |
76 | bfd_zalloc (abfd, sizeof (struct netbsd_core_struct)); | |
77 | if (rawptr == NULL) { | |
78 | bfd_set_error(bfd_error_no_memory); | |
79 | return 0; | |
80 | } | |
81 | ||
82 | rawptr->core = core; | |
83 | abfd->tdata.netbsd_core_data = rawptr; | |
84 | ||
85 | offset = core.c_hdrsize; | |
86 | for (i = 0; i < core.c_nseg; i++) { | |
87 | ||
88 | if (bfd_seek (abfd, offset, SEEK_SET) != 0) | |
89 | goto punt; | |
90 | ||
91 | val = bfd_read ((void *)&coreseg, 1, sizeof coreseg, abfd); | |
92 | if (val != sizeof coreseg) { | |
93 | bfd_set_error(bfd_error_file_truncated); | |
94 | goto punt; | |
95 | } | |
96 | if (CORE_GETMAGIC(coreseg) != CORESEGMAGIC) { | |
97 | bfd_set_error(bfd_error_wrong_format); | |
98 | goto punt; | |
99 | } | |
100 | ||
101 | offset += core.c_seghdrsize; | |
102 | ||
103 | asect = (asection *) bfd_zalloc (abfd, sizeof(asection)); | |
104 | if (asect == NULL) { | |
105 | bfd_set_error(bfd_error_no_memory); | |
106 | } | |
107 | ||
108 | asect->_raw_size = coreseg.c_size; | |
109 | asect->vma = coreseg.c_addr; | |
110 | asect->filepos = offset; | |
111 | asect->alignment_power = 2; | |
112 | asect->next = abfd->sections; | |
113 | abfd->sections = asect; | |
114 | abfd->section_count++; | |
115 | offset += coreseg.c_size; | |
116 | ||
117 | switch (CORE_GETFLAG(coreseg)) { | |
118 | case CORE_CPU: | |
119 | asect->name = ".reg"; | |
120 | asect->flags = SEC_ALLOC + SEC_HAS_CONTENTS; | |
121 | #ifdef CORE_FPU_OFFSET | |
122 | /* Hackish... */ | |
123 | asect->_raw_size = CORE_FPU_OFFSET; | |
124 | asect2 = (asection *)bfd_zalloc (abfd, | |
125 | sizeof (asection)); | |
126 | if (asect2 == NULL) { | |
127 | bfd_set_error(bfd_error_no_memory); | |
128 | goto punt; | |
129 | } | |
130 | asect2->_raw_size = coreseg.c_size - CORE_FPU_OFFSET; | |
131 | asect2->vma = 0; | |
132 | asect2->filepos = asect->filepos + CORE_FPU_OFFSET; | |
133 | asect2->alignment_power = 2; | |
134 | asect2->next = abfd->sections; | |
135 | asect2->name = ".reg2"; | |
136 | asect2->flags = SEC_ALLOC + SEC_HAS_CONTENTS; | |
137 | abfd->sections = asect2; | |
138 | abfd->section_count++; | |
139 | #endif | |
140 | ||
141 | break; | |
142 | case CORE_DATA: | |
143 | asect->name = ".data"; | |
144 | asect->flags = SEC_ALLOC+SEC_LOAD+SEC_HAS_CONTENTS; | |
145 | break; | |
146 | case CORE_STACK: | |
147 | asect->name = ".stack"; | |
148 | asect->flags = SEC_ALLOC+SEC_LOAD+SEC_HAS_CONTENTS; | |
149 | break; | |
150 | } | |
151 | } | |
152 | ||
153 | /* OK, we believe you. You're a core file (sure, sure). */ | |
154 | return abfd->xvec; | |
155 | ||
156 | punt: { | |
157 | asection *anext; | |
158 | for (asect = abfd->sections; asect; asect = anext) { | |
159 | anext = asect->next; | |
160 | free((void *)asect); | |
161 | } | |
162 | } | |
163 | free ((void *)rawptr); | |
164 | abfd->tdata.netbsd_core_data = NULL; | |
165 | abfd->sections = NULL; | |
166 | abfd->section_count = 0; | |
167 | return 0; | |
168 | } | |
169 | ||
170 | static char* | |
171 | netbsd_core_core_file_failing_command (abfd) | |
172 | bfd *abfd; | |
173 | { | |
174 | /*return core_command (abfd);*/ | |
175 | return abfd->tdata.netbsd_core_data->core.c_name; | |
176 | } | |
177 | ||
178 | /* ARGSUSED */ | |
179 | static int | |
180 | netbsd_core_core_file_failing_signal (abfd) | |
181 | bfd *abfd; | |
182 | { | |
183 | /*return core_signal (abfd);*/ | |
184 | return abfd->tdata.netbsd_core_data->core.c_signo; | |
185 | } | |
186 | ||
187 | /* ARGSUSED */ | |
188 | static boolean | |
189 | netbsd_core_core_file_matches_executable_p (core_bfd, exec_bfd) | |
190 | bfd *core_bfd, *exec_bfd; | |
191 | { | |
192 | return true; /* FIXME, We have no way of telling at this point */ | |
193 | } | |
194 | \f | |
195 | /* No archive file support via this BFD */ | |
196 | #define netbsd_openr_next_archived_file bfd_generic_openr_next_archived_file | |
197 | #define netbsd_generic_stat_arch_elt bfd_generic_stat_arch_elt | |
198 | #define netbsd_slurp_armap bfd_false | |
199 | #define netbsd_slurp_extended_name_table bfd_true | |
200 | #define netbsd_write_armap (boolean (*) PARAMS \ | |
201 | ((bfd *arch, unsigned int elength, struct orl *map, \ | |
202 | unsigned int orl_count, int stridx))) bfd_false | |
203 | #define netbsd_truncate_arname bfd_dont_truncate_arname | |
204 | #define aout_32_openr_next_archived_file bfd_generic_openr_next_archived_file | |
205 | ||
206 | #define netbsd_close_and_cleanup bfd_generic_close_and_cleanup | |
207 | #define netbsd_set_section_contents (boolean (*) PARAMS \ | |
208 | ((bfd *abfd, asection *section, PTR data, file_ptr offset, \ | |
209 | bfd_size_type count))) bfd_false | |
210 | #define netbsd_get_section_contents bfd_generic_get_section_contents | |
211 | #define netbsd_new_section_hook (boolean (*) PARAMS \ | |
212 | ((bfd *, sec_ptr))) bfd_true | |
213 | #define netbsd_get_symtab_upper_bound bfd_0u | |
214 | #define netbsd_get_symtab (unsigned int (*) PARAMS \ | |
215 | ((bfd *, struct symbol_cache_entry **))) bfd_0u | |
216 | #define netbsd_get_reloc_upper_bound (unsigned int (*) PARAMS \ | |
217 | ((bfd *, sec_ptr))) bfd_0u | |
218 | #define netbsd_canonicalize_reloc (unsigned int (*) PARAMS \ | |
219 | ((bfd *, sec_ptr, arelent **, struct symbol_cache_entry**))) bfd_0u | |
220 | #define netbsd_make_empty_symbol (struct symbol_cache_entry * \ | |
221 | (*) PARAMS ((bfd *))) bfd_false | |
222 | #define netbsd_print_symbol (void (*) PARAMS \ | |
223 | ((bfd *, PTR, struct symbol_cache_entry *, \ | |
224 | bfd_print_symbol_type))) bfd_false | |
225 | #define netbsd_get_symbol_info (void (*) PARAMS \ | |
226 | ((bfd *, struct symbol_cache_entry *, \ | |
227 | symbol_info *))) bfd_false | |
228 | #define netbsd_get_lineno (alent * (*) PARAMS \ | |
229 | ((bfd *, struct symbol_cache_entry *))) bfd_nullvoidptr | |
230 | #define netbsd_set_arch_mach (boolean (*) PARAMS \ | |
231 | ((bfd *, enum bfd_architecture, unsigned long))) bfd_false | |
232 | #define netbsd_find_nearest_line (boolean (*) PARAMS \ | |
233 | ((bfd *abfd, struct sec *section, \ | |
234 | struct symbol_cache_entry **symbols,bfd_vma offset, \ | |
235 | CONST char **file, CONST char **func, unsigned int *line))) bfd_false | |
236 | #define netbsd_sizeof_headers (int (*) PARAMS \ | |
237 | ((bfd *, boolean))) bfd_0 | |
238 | ||
239 | #define netbsd_bfd_debug_info_start bfd_void | |
240 | #define netbsd_bfd_debug_info_end bfd_void | |
241 | #define netbsd_bfd_debug_info_accumulate (void (*) PARAMS \ | |
242 | ((bfd *, struct sec *))) bfd_void | |
243 | #define netbsd_bfd_get_relocated_section_contents bfd_generic_get_relocated_section_contents | |
244 | #define netbsd_bfd_relax_section bfd_generic_relax_section | |
245 | #define netbsd_bfd_seclet_link \ | |
246 | ((boolean (*) PARAMS ((bfd *, PTR, boolean))) bfd_false) | |
247 | #define netbsd_bfd_reloc_type_lookup \ | |
248 | ((CONST struct reloc_howto_struct *(*) PARAMS ((bfd *, bfd_reloc_code_real_type))) bfd_nullvoidptr) | |
249 | #define netbsd_bfd_make_debug_symbol \ | |
250 | ((asymbol *(*) PARAMS ((bfd *, void *, unsigned long))) bfd_nullvoidptr) | |
251 | ||
252 | /* If somebody calls any byte-swapping routines, shoot them. */ | |
253 | static void | |
254 | swap_abort() | |
255 | { | |
256 | abort(); /* This way doesn't require any declaration for ANSI to fuck up */ | |
257 | } | |
258 | #define NO_GET ((bfd_vma (*) PARAMS (( const bfd_byte *))) swap_abort ) | |
259 | #define NO_PUT ((void (*) PARAMS ((bfd_vma, bfd_byte *))) swap_abort ) | |
260 | #define NO_SIGNED_GET \ | |
261 | ((bfd_signed_vma (*) PARAMS (( const bfd_byte *))) swap_abort ) | |
262 | ||
263 | const bfd_target netbsd_core_vec = | |
264 | { | |
265 | "netbsd-core", | |
266 | bfd_target_unknown_flavour, | |
267 | true, /* target byte order */ | |
268 | true, /* target headers byte order */ | |
269 | (HAS_RELOC | EXEC_P | /* object flags */ | |
270 | HAS_LINENO | HAS_DEBUG | | |
271 | HAS_SYMS | HAS_LOCALS | DYNAMIC | WP_TEXT | D_PAGED), | |
272 | (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */ | |
273 | 0, /* symbol prefix */ | |
274 | ' ', /* ar_pad_char */ | |
275 | 16, /* ar_max_namelen */ | |
276 | 3, /* minimum alignment power */ | |
277 | NO_GET, NO_SIGNED_GET, NO_PUT, /* 64 bit data */ | |
278 | NO_GET, NO_SIGNED_GET, NO_PUT, /* 32 bit data */ | |
279 | NO_GET, NO_SIGNED_GET, NO_PUT, /* 16 bit data */ | |
280 | NO_GET, NO_SIGNED_GET, NO_PUT, /* 64 bit hdrs */ | |
281 | NO_GET, NO_SIGNED_GET, NO_PUT, /* 32 bit hdrs */ | |
282 | NO_GET, NO_SIGNED_GET, NO_PUT, /* 16 bit hdrs */ | |
283 | ||
284 | { /* bfd_check_format */ | |
285 | _bfd_dummy_target, /* unknown format */ | |
286 | _bfd_dummy_target, /* object file */ | |
287 | _bfd_dummy_target, /* archive */ | |
288 | netbsd_core_core_file_p /* a core file */ | |
289 | }, | |
290 | { /* bfd_set_format */ | |
291 | bfd_false, bfd_false, | |
292 | bfd_false, bfd_false | |
293 | }, | |
294 | { /* bfd_write_contents */ | |
295 | bfd_false, bfd_false, | |
296 | bfd_false, bfd_false | |
297 | }, | |
298 | ||
299 | BFD_JUMP_TABLE_GENERIC (_bfd_generic), | |
300 | BFD_JUMP_TABLE_COPY (_bfd_generic), | |
301 | BFD_JUMP_TABLE_CORE (netbsd_core), | |
302 | BFD_JUMP_TABLE_ARCHIVE (_bfd_noarchive), | |
303 | BFD_JUMP_TABLE_SYMBOLS (_bfd_nosymbols), | |
304 | BFD_JUMP_TABLE_RELOCS (_bfd_norelocs), | |
305 | BFD_JUMP_TABLE_WRITE (_bfd_generic), | |
306 | BFD_JUMP_TABLE_LINK (_bfd_nolink), | |
307 | BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic), | |
308 | ||
309 | (PTR) 0 /* backend_data */ | |
310 | }; |