]>
Commit | Line | Data |
---|---|---|
9712c6e2 | 1 | /* BFD back end for traditional Unix core files (U-area and raw sections) |
0dc1bc8b | 2 | Copyright 1988, 1989, 1991, 1992, 1993 Free Software Foundation, Inc. |
9712c6e2 SG |
3 | Written by John Gilmore of Cygnus Support. |
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., 675 Mass Ave, Cambridge, MA 02139, USA. */ | |
ff37ea55 | 20 | |
6a469027 JG |
21 | /* To use this file on a particular host, configure the host with these |
22 | parameters in the config/h-HOST file: | |
23 | ||
637942e4 | 24 | HDEFINES=-DTRAD_CORE |
6a469027 JG |
25 | HDEPFILES=trad-core.o |
26 | ||
27 | */ | |
28 | ||
ff37ea55 | 29 | #include "bfd.h" |
637942e4 | 30 | #include "sysdep.h" |
ff37ea55 | 31 | #include "libbfd.h" |
359f1dee | 32 | #include "libaout.h" /* BFD a.out internal data structures */ |
ff37ea55 | 33 | |
637942e4 | 34 | #include <stdio.h> |
ff37ea55 JG |
35 | #include <sys/types.h> |
36 | #include <sys/param.h> | |
37 | #include <sys/dir.h> | |
38 | #include <signal.h> | |
ff37ea55 JG |
39 | |
40 | #include <sys/user.h> /* After a.out.h */ | |
4d09e8ac JK |
41 | #if 0 |
42 | /* file.h is included by std-host.h. So we better not try to include it | |
43 | twice; on some systems (dpx2) it is not protected against multiple | |
44 | inclusion. I have checked that all the hosts which use this file | |
45 | include sys/file.h in the hosts file. */ | |
ff37ea55 | 46 | #include <sys/file.h> |
4d09e8ac | 47 | #endif |
ff37ea55 JG |
48 | |
49 | #include <errno.h> | |
50 | ||
1f29e30b JG |
51 | struct trad_core_struct |
52 | { | |
53 | asection *data_section; | |
54 | asection *stack_section; | |
55 | asection *reg_section; | |
56 | struct user u; | |
57 | } *rawptr; | |
58 | ||
59 | #define core_upage(bfd) (&((bfd)->tdata.trad_core_data->u)) | |
60 | #define core_datasec(bfd) ((bfd)->tdata.trad_core_data->data_section) | |
61 | #define core_stacksec(bfd) ((bfd)->tdata.trad_core_data->stack_section) | |
62 | #define core_regsec(bfd) ((bfd)->tdata.trad_core_data->reg_section) | |
63 | ||
64 | /* forward declarations */ | |
ff37ea55 | 65 | |
1f29e30b JG |
66 | bfd_target * trad_unix_core_file_p PARAMS ((bfd *abfd)); |
67 | char * trad_unix_core_file_failing_command PARAMS ((bfd *abfd)); | |
68 | int trad_unix_core_file_failing_signal PARAMS ((bfd *abfd)); | |
69 | boolean trad_unix_core_file_matches_executable_p | |
70 | PARAMS ((bfd *core_bfd, bfd *exec_bfd)); | |
6a469027 | 71 | |
637942e4 JG |
72 | /* Handle 4.2-style (and perhaps also sysV-style) core dump file. */ |
73 | ||
7ed4093a | 74 | /* ARGSUSED */ |
ff37ea55 JG |
75 | bfd_target * |
76 | trad_unix_core_file_p (abfd) | |
77 | bfd *abfd; | |
1f29e30b | 78 | |
ff37ea55 | 79 | { |
ff37ea55 | 80 | int val; |
ff37ea55 | 81 | struct user u; |
ff37ea55 JG |
82 | |
83 | val = bfd_read ((void *)&u, 1, sizeof u, abfd); | |
84 | if (val != sizeof u) | |
31568a6f JK |
85 | { |
86 | /* Too small to be a core file */ | |
87 | bfd_error = wrong_format; | |
88 | return 0; | |
89 | } | |
ff37ea55 JG |
90 | |
91 | /* Sanity check perhaps??? */ | |
92 | if (u.u_dsize > 0x1000000) /* Remember, it's in pages... */ | |
31568a6f JK |
93 | { |
94 | bfd_error = wrong_format; | |
95 | return 0; | |
96 | } | |
ff37ea55 | 97 | if (u.u_ssize > 0x1000000) |
31568a6f JK |
98 | { |
99 | bfd_error = wrong_format; | |
100 | return 0; | |
101 | } | |
102 | ||
103 | /* Check that the size claimed is no greater than the file size. */ | |
104 | { | |
105 | FILE *stream = bfd_cache_lookup (abfd); | |
106 | struct stat statbuf; | |
107 | if (stream == NULL) | |
108 | return 0; | |
109 | if (fstat (fileno (stream), &statbuf) < 0) | |
110 | { | |
111 | bfd_error = system_call_error; | |
112 | return 0; | |
113 | } | |
114 | if (NBPG * (UPAGES + u.u_dsize + u.u_ssize) > statbuf.st_size) | |
115 | { | |
116 | bfd_error = file_truncated; | |
117 | return 0; | |
118 | } | |
4d09e8ac JK |
119 | if (NBPG * (UPAGES + u.u_dsize + u.u_ssize) |
120 | #ifdef TRAD_CORE_EXTRA_SIZE_ALLOWED | |
121 | /* Some systems write the file too big. */ | |
122 | + TRAD_CORE_EXTRA_SIZE_ALLOWED | |
123 | #endif | |
124 | < statbuf.st_size) | |
31568a6f JK |
125 | { |
126 | /* The file is too big. Maybe it's not a core file | |
127 | or we otherwise have bad values for u_dsize and u_ssize). */ | |
128 | bfd_error = wrong_format; | |
129 | return 0; | |
130 | } | |
131 | } | |
ff37ea55 JG |
132 | |
133 | /* OK, we believe you. You're a core file (sure, sure). */ | |
134 | ||
135 | /* Allocate both the upage and the struct core_data at once, so | |
136 | a single free() will free them both. */ | |
1f29e30b JG |
137 | rawptr = (struct trad_core_struct *) |
138 | bfd_zalloc (abfd, sizeof (struct trad_core_struct)); | |
ff37ea55 JG |
139 | if (rawptr == NULL) { |
140 | bfd_error = no_memory; | |
141 | return 0; | |
142 | } | |
143 | ||
1f29e30b JG |
144 | abfd->tdata.trad_core_data = rawptr; |
145 | ||
146 | rawptr->u = u; /*Copy the uarea into the tdata part of the bfd */ | |
ff37ea55 | 147 | |
637942e4 JG |
148 | /* Create the sections. This is raunchy, but bfd_close wants to free |
149 | them separately. */ | |
1f29e30b JG |
150 | |
151 | core_stacksec(abfd) = (asection *) zalloc (sizeof (asection)); | |
ff37ea55 | 152 | if (core_stacksec (abfd) == NULL) { |
1f29e30b | 153 | loser: |
ff37ea55 JG |
154 | bfd_error = no_memory; |
155 | free ((void *)rawptr); | |
156 | return 0; | |
157 | } | |
158 | core_datasec (abfd) = (asection *) zalloc (sizeof (asection)); | |
159 | if (core_datasec (abfd) == NULL) { | |
1f29e30b | 160 | loser1: |
ff37ea55 JG |
161 | free ((void *)core_stacksec (abfd)); |
162 | goto loser; | |
163 | } | |
164 | core_regsec (abfd) = (asection *) zalloc (sizeof (asection)); | |
165 | if (core_regsec (abfd) == NULL) { | |
ff37ea55 JG |
166 | free ((void *)core_datasec (abfd)); |
167 | goto loser1; | |
168 | } | |
169 | ||
170 | core_stacksec (abfd)->name = ".stack"; | |
171 | core_datasec (abfd)->name = ".data"; | |
172 | core_regsec (abfd)->name = ".reg"; | |
173 | ||
6a469027 JG |
174 | core_stacksec (abfd)->flags = SEC_ALLOC + SEC_LOAD + SEC_HAS_CONTENTS; |
175 | core_datasec (abfd)->flags = SEC_ALLOC + SEC_LOAD + SEC_HAS_CONTENTS; | |
176 | core_regsec (abfd)->flags = SEC_ALLOC + SEC_HAS_CONTENTS; | |
ff37ea55 | 177 | |
1f29e30b JG |
178 | core_datasec (abfd)->_raw_size = NBPG * u.u_dsize; |
179 | core_stacksec (abfd)->_raw_size = NBPG * u.u_ssize; | |
180 | core_regsec (abfd)->_raw_size = NBPG * UPAGES; /* Larger than sizeof struct u */ | |
ff37ea55 JG |
181 | |
182 | /* What a hack... we'd like to steal it from the exec file, | |
183 | since the upage does not seem to provide it. FIXME. */ | |
9712c6e2 SG |
184 | #ifdef HOST_DATA_START_ADDR |
185 | core_datasec (abfd)->vma = HOST_DATA_START_ADDR; | |
186 | #else | |
187 | core_datasec (abfd)->vma = HOST_TEXT_START_ADDR + (NBPG * u.u_tsize); | |
188 | #endif | |
189 | core_stacksec (abfd)->vma = HOST_STACK_END_ADDR - (NBPG * u.u_ssize); | |
637942e4 JG |
190 | /* This is tricky. As the "register section", we give them the entire |
191 | upage and stack. u.u_ar0 points to where "register 0" is stored. | |
192 | There are two tricks with this, though. One is that the rest of the | |
193 | registers might be at positive or negative (or both) displacements | |
194 | from *u_ar0. The other is that u_ar0 is sometimes an absolute address | |
195 | in kernel memory, and on other systems it is an offset from the beginning | |
196 | of the `struct user'. | |
1f29e30b | 197 | |
637942e4 JG |
198 | As a practical matter, we don't know where the registers actually are, |
199 | so we have to pass the whole area to GDB. We encode the value of u_ar0 | |
200 | by setting the .regs section up so that its virtual memory address | |
201 | 0 is at the place pointed to by u_ar0 (by setting the vma of the start | |
202 | of the section to -u_ar0). GDB uses this info to locate the regs, | |
203 | using minor trickery to get around the offset-or-absolute-addr problem. */ | |
204 | core_regsec (abfd)->vma = 0 - (int) u.u_ar0; | |
ff37ea55 JG |
205 | |
206 | core_datasec (abfd)->filepos = NBPG * UPAGES; | |
207 | core_stacksec (abfd)->filepos = (NBPG * UPAGES) + NBPG * u.u_dsize; | |
1f29e30b | 208 | core_regsec (abfd)->filepos = 0; /* Register segment is the upage */ |
ff37ea55 JG |
209 | |
210 | /* Align to word at least */ | |
211 | core_stacksec (abfd)->alignment_power = 2; | |
212 | core_datasec (abfd)->alignment_power = 2; | |
213 | core_regsec (abfd)->alignment_power = 2; | |
214 | ||
215 | abfd->sections = core_stacksec (abfd); | |
216 | core_stacksec (abfd)->next = core_datasec (abfd); | |
217 | core_datasec (abfd)->next = core_regsec (abfd); | |
218 | abfd->section_count = 3; | |
219 | ||
220 | return abfd->xvec; | |
ff37ea55 JG |
221 | } |
222 | ||
223 | char * | |
224 | trad_unix_core_file_failing_command (abfd) | |
225 | bfd *abfd; | |
226 | { | |
1f29e30b JG |
227 | #ifndef NO_CORE_COMMAND |
228 | char *com = abfd->tdata.trad_core_data->u.u_comm; | |
229 | if (*com) | |
230 | return com; | |
ff37ea55 | 231 | else |
1f29e30b | 232 | #endif |
ff37ea55 JG |
233 | return 0; |
234 | } | |
235 | ||
7ed4093a | 236 | /* ARGSUSED */ |
ff37ea55 | 237 | int |
7ed4093a SC |
238 | trad_unix_core_file_failing_signal (ignore_abfd) |
239 | bfd *ignore_abfd; | |
ff37ea55 | 240 | { |
31568a6f JK |
241 | #ifdef TRAD_UNIX_CORE_FILE_FAILING_SIGNAL |
242 | return TRAD_UNIX_CORE_FILE_FAILING_SIGNAL(ignore_abfd); | |
243 | #else | |
ff37ea55 | 244 | return -1; /* FIXME, where is it? */ |
31568a6f | 245 | #endif |
ff37ea55 JG |
246 | } |
247 | ||
7ed4093a | 248 | /* ARGSUSED */ |
ff37ea55 JG |
249 | boolean |
250 | trad_unix_core_file_matches_executable_p (core_bfd, exec_bfd) | |
251 | bfd *core_bfd, *exec_bfd; | |
252 | { | |
253 | return true; /* FIXME, We have no way of telling at this point */ | |
254 | } | |
6a469027 JG |
255 | \f |
256 | /* No archive file support via this BFD */ | |
257 | #define trad_unix_openr_next_archived_file bfd_generic_openr_next_archived_file | |
258 | #define trad_unix_generic_stat_arch_elt bfd_generic_stat_arch_elt | |
259 | #define trad_unix_slurp_armap bfd_false | |
260 | #define trad_unix_slurp_extended_name_table bfd_true | |
1f29e30b JG |
261 | #define trad_unix_write_armap (boolean (*) PARAMS \ |
262 | ((bfd *arch, unsigned int elength, struct orl *map, \ | |
263 | unsigned int orl_count, int stridx))) bfd_false | |
6a469027 JG |
264 | #define trad_unix_truncate_arname bfd_dont_truncate_arname |
265 | #define aout_32_openr_next_archived_file bfd_generic_openr_next_archived_file | |
266 | ||
267 | #define trad_unix_close_and_cleanup bfd_generic_close_and_cleanup | |
1f29e30b JG |
268 | #define trad_unix_set_section_contents (boolean (*) PARAMS \ |
269 | ((bfd *abfd, asection *section, PTR data, file_ptr offset, \ | |
270 | bfd_size_type count))) bfd_false | |
6a469027 | 271 | #define trad_unix_get_section_contents bfd_generic_get_section_contents |
1f29e30b JG |
272 | #define trad_unix_new_section_hook (boolean (*) PARAMS \ |
273 | ((bfd *, sec_ptr))) bfd_true | |
6a469027 | 274 | #define trad_unix_get_symtab_upper_bound bfd_0u |
1f29e30b JG |
275 | #define trad_unix_get_symtab (unsigned int (*) PARAMS \ |
276 | ((bfd *, struct symbol_cache_entry **))) bfd_0u | |
277 | #define trad_unix_get_reloc_upper_bound (unsigned int (*) PARAMS \ | |
278 | ((bfd *, sec_ptr))) bfd_0u | |
279 | #define trad_unix_canonicalize_reloc (unsigned int (*) PARAMS \ | |
280 | ((bfd *, sec_ptr, arelent **, struct symbol_cache_entry**))) bfd_0u | |
281 | #define trad_unix_make_empty_symbol (struct symbol_cache_entry * \ | |
31568a6f | 282 | (*) PARAMS ((bfd *))) bfd_false |
1f29e30b JG |
283 | #define trad_unix_print_symbol (void (*) PARAMS \ |
284 | ((bfd *, PTR, struct symbol_cache_entry *, \ | |
285 | bfd_print_symbol_type))) bfd_false | |
4d09e8ac JK |
286 | #define trad_unix_get_symbol_info (void (*) PARAMS \ |
287 | ((bfd *, struct symbol_cache_entry *, \ | |
288 | symbol_info *))) bfd_false | |
1f29e30b JG |
289 | #define trad_unix_get_lineno (alent * (*) PARAMS \ |
290 | ((bfd *, struct symbol_cache_entry *))) bfd_nullvoidptr | |
291 | #define trad_unix_set_arch_mach (boolean (*) PARAMS \ | |
0dc1bc8b | 292 | ((bfd *, enum bfd_architecture, unsigned long))) bfd_false |
1f29e30b | 293 | #define trad_unix_find_nearest_line (boolean (*) PARAMS \ |
0dc1bc8b | 294 | ((bfd *abfd, struct sec *section, \ |
6a469027 JG |
295 | struct symbol_cache_entry **symbols,bfd_vma offset, \ |
296 | CONST char **file, CONST char **func, unsigned int *line))) bfd_false | |
1f29e30b | 297 | #define trad_unix_sizeof_headers (int (*) PARAMS \ |
0dc1bc8b | 298 | ((bfd *, boolean))) bfd_0 |
6a469027 JG |
299 | |
300 | #define trad_unix_bfd_debug_info_start bfd_void | |
301 | #define trad_unix_bfd_debug_info_end bfd_void | |
1f29e30b | 302 | #define trad_unix_bfd_debug_info_accumulate (void (*) PARAMS \ |
0dc1bc8b | 303 | ((bfd *, struct sec *))) bfd_void |
1f29e30b JG |
304 | #define trad_unix_bfd_get_relocated_section_contents bfd_generic_get_relocated_section_contents |
305 | #define trad_unix_bfd_relax_section bfd_generic_relax_section | |
0dc1bc8b ILT |
306 | #define trad_unix_bfd_seclet_link \ |
307 | ((boolean (*) PARAMS ((bfd *, PTR, boolean))) bfd_false) | |
31568a6f JK |
308 | #define trad_unix_bfd_reloc_type_lookup \ |
309 | ((CONST struct reloc_howto_struct *(*) PARAMS ((bfd *, bfd_reloc_code_real_type))) bfd_nullvoidptr) | |
310 | #define trad_unix_bfd_make_debug_symbol \ | |
311 | ((asymbol *(*) PARAMS ((bfd *, void *, unsigned long))) bfd_nullvoidptr) | |
0dc1bc8b | 312 | |
637942e4 JG |
313 | /* If somebody calls any byte-swapping routines, shoot them. */ |
314 | void | |
315 | swap_abort() | |
316 | { | |
317 | abort(); /* This way doesn't require any declaration for ANSI to fuck up */ | |
318 | } | |
1f29e30b JG |
319 | #define NO_GET ((bfd_vma (*) PARAMS (( bfd_byte *))) swap_abort ) |
320 | #define NO_PUT ((void (*) PARAMS ((bfd_vma, bfd_byte *))) swap_abort ) | |
4d09e8ac | 321 | #define NO_SIGNED_GET ((bfd_signed_vma (*) PARAMS ((bfd_byte *))) swap_abort ) |
6a469027 | 322 | |
637942e4 | 323 | bfd_target trad_core_vec = |
6a469027 | 324 | { |
637942e4 | 325 | "trad-core", |
6a469027 JG |
326 | bfd_target_unknown_flavour, |
327 | true, /* target byte order */ | |
328 | true, /* target headers byte order */ | |
329 | (HAS_RELOC | EXEC_P | /* object flags */ | |
330 | HAS_LINENO | HAS_DEBUG | | |
331 | HAS_SYMS | HAS_LOCALS | DYNAMIC | WP_TEXT | D_PAGED), | |
332 | (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */ | |
0dc1bc8b | 333 | 0, /* symbol prefix */ |
6a469027 JG |
334 | ' ', /* ar_pad_char */ |
335 | 16, /* ar_max_namelen */ | |
336 | 3, /* minimum alignment power */ | |
4d09e8ac JK |
337 | NO_GET, NO_SIGNED_GET, NO_PUT, /* 64 bit data */ |
338 | NO_GET, NO_SIGNED_GET, NO_PUT, /* 32 bit data */ | |
339 | NO_GET, NO_SIGNED_GET, NO_PUT, /* 16 bit data */ | |
340 | NO_GET, NO_SIGNED_GET, NO_PUT, /* 64 bit hdrs */ | |
341 | NO_GET, NO_SIGNED_GET, NO_PUT, /* 32 bit hdrs */ | |
342 | NO_GET, NO_SIGNED_GET, NO_PUT, /* 16 bit hdrs */ | |
31568a6f JK |
343 | |
344 | { /* bfd_check_format */ | |
345 | _bfd_dummy_target, /* unknown format */ | |
346 | _bfd_dummy_target, /* object file */ | |
347 | _bfd_dummy_target, /* archive */ | |
348 | trad_unix_core_file_p /* a core file */ | |
349 | }, | |
350 | { /* bfd_set_format */ | |
351 | bfd_false, bfd_false, | |
352 | bfd_false, bfd_false | |
353 | }, | |
354 | { /* bfd_write_contents */ | |
355 | bfd_false, bfd_false, | |
356 | bfd_false, bfd_false | |
357 | }, | |
6a469027 | 358 | |
31568a6f JK |
359 | JUMP_TABLE(trad_unix), |
360 | (PTR) 0 /* backend_data */ | |
6a469027 | 361 | }; |