]>
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 */ | |
41 | #include <sys/file.h> | |
ff37ea55 JG |
42 | |
43 | #include <errno.h> | |
44 | ||
1f29e30b JG |
45 | struct trad_core_struct |
46 | { | |
47 | asection *data_section; | |
48 | asection *stack_section; | |
49 | asection *reg_section; | |
50 | struct user u; | |
51 | } *rawptr; | |
52 | ||
53 | #define core_upage(bfd) (&((bfd)->tdata.trad_core_data->u)) | |
54 | #define core_datasec(bfd) ((bfd)->tdata.trad_core_data->data_section) | |
55 | #define core_stacksec(bfd) ((bfd)->tdata.trad_core_data->stack_section) | |
56 | #define core_regsec(bfd) ((bfd)->tdata.trad_core_data->reg_section) | |
57 | ||
58 | /* forward declarations */ | |
ff37ea55 | 59 | |
1f29e30b JG |
60 | bfd_target * trad_unix_core_file_p PARAMS ((bfd *abfd)); |
61 | char * trad_unix_core_file_failing_command PARAMS ((bfd *abfd)); | |
62 | int trad_unix_core_file_failing_signal PARAMS ((bfd *abfd)); | |
63 | boolean trad_unix_core_file_matches_executable_p | |
64 | PARAMS ((bfd *core_bfd, bfd *exec_bfd)); | |
6a469027 | 65 | |
637942e4 JG |
66 | /* Handle 4.2-style (and perhaps also sysV-style) core dump file. */ |
67 | ||
7ed4093a | 68 | /* ARGSUSED */ |
ff37ea55 JG |
69 | bfd_target * |
70 | trad_unix_core_file_p (abfd) | |
71 | bfd *abfd; | |
1f29e30b | 72 | |
ff37ea55 | 73 | { |
ff37ea55 | 74 | int val; |
ff37ea55 | 75 | struct user u; |
ff37ea55 JG |
76 | |
77 | val = bfd_read ((void *)&u, 1, sizeof u, abfd); | |
78 | if (val != sizeof u) | |
79 | return 0; /* Too small to be a core file */ | |
80 | ||
81 | /* Sanity check perhaps??? */ | |
82 | if (u.u_dsize > 0x1000000) /* Remember, it's in pages... */ | |
83 | return 0; | |
84 | if (u.u_ssize > 0x1000000) | |
85 | return 0; | |
86 | /* Check that the size claimed is no greater than the file size. FIXME. */ | |
87 | ||
88 | /* OK, we believe you. You're a core file (sure, sure). */ | |
89 | ||
90 | /* Allocate both the upage and the struct core_data at once, so | |
91 | a single free() will free them both. */ | |
1f29e30b JG |
92 | rawptr = (struct trad_core_struct *) |
93 | bfd_zalloc (abfd, sizeof (struct trad_core_struct)); | |
ff37ea55 JG |
94 | if (rawptr == NULL) { |
95 | bfd_error = no_memory; | |
96 | return 0; | |
97 | } | |
98 | ||
1f29e30b JG |
99 | abfd->tdata.trad_core_data = rawptr; |
100 | ||
101 | rawptr->u = u; /*Copy the uarea into the tdata part of the bfd */ | |
ff37ea55 | 102 | |
637942e4 JG |
103 | /* Create the sections. This is raunchy, but bfd_close wants to free |
104 | them separately. */ | |
1f29e30b JG |
105 | |
106 | core_stacksec(abfd) = (asection *) zalloc (sizeof (asection)); | |
ff37ea55 | 107 | if (core_stacksec (abfd) == NULL) { |
1f29e30b | 108 | loser: |
ff37ea55 JG |
109 | bfd_error = no_memory; |
110 | free ((void *)rawptr); | |
111 | return 0; | |
112 | } | |
113 | core_datasec (abfd) = (asection *) zalloc (sizeof (asection)); | |
114 | if (core_datasec (abfd) == NULL) { | |
1f29e30b | 115 | loser1: |
ff37ea55 JG |
116 | free ((void *)core_stacksec (abfd)); |
117 | goto loser; | |
118 | } | |
119 | core_regsec (abfd) = (asection *) zalloc (sizeof (asection)); | |
120 | if (core_regsec (abfd) == NULL) { | |
ff37ea55 JG |
121 | free ((void *)core_datasec (abfd)); |
122 | goto loser1; | |
123 | } | |
124 | ||
125 | core_stacksec (abfd)->name = ".stack"; | |
126 | core_datasec (abfd)->name = ".data"; | |
127 | core_regsec (abfd)->name = ".reg"; | |
128 | ||
6a469027 JG |
129 | core_stacksec (abfd)->flags = SEC_ALLOC + SEC_LOAD + SEC_HAS_CONTENTS; |
130 | core_datasec (abfd)->flags = SEC_ALLOC + SEC_LOAD + SEC_HAS_CONTENTS; | |
131 | core_regsec (abfd)->flags = SEC_ALLOC + SEC_HAS_CONTENTS; | |
ff37ea55 | 132 | |
1f29e30b JG |
133 | core_datasec (abfd)->_raw_size = NBPG * u.u_dsize; |
134 | core_stacksec (abfd)->_raw_size = NBPG * u.u_ssize; | |
135 | core_regsec (abfd)->_raw_size = NBPG * UPAGES; /* Larger than sizeof struct u */ | |
ff37ea55 JG |
136 | |
137 | /* What a hack... we'd like to steal it from the exec file, | |
138 | since the upage does not seem to provide it. FIXME. */ | |
9712c6e2 SG |
139 | #ifdef HOST_DATA_START_ADDR |
140 | core_datasec (abfd)->vma = HOST_DATA_START_ADDR; | |
141 | #else | |
142 | core_datasec (abfd)->vma = HOST_TEXT_START_ADDR + (NBPG * u.u_tsize); | |
143 | #endif | |
144 | core_stacksec (abfd)->vma = HOST_STACK_END_ADDR - (NBPG * u.u_ssize); | |
637942e4 JG |
145 | /* This is tricky. As the "register section", we give them the entire |
146 | upage and stack. u.u_ar0 points to where "register 0" is stored. | |
147 | There are two tricks with this, though. One is that the rest of the | |
148 | registers might be at positive or negative (or both) displacements | |
149 | from *u_ar0. The other is that u_ar0 is sometimes an absolute address | |
150 | in kernel memory, and on other systems it is an offset from the beginning | |
151 | of the `struct user'. | |
1f29e30b | 152 | |
637942e4 JG |
153 | As a practical matter, we don't know where the registers actually are, |
154 | so we have to pass the whole area to GDB. We encode the value of u_ar0 | |
155 | by setting the .regs section up so that its virtual memory address | |
156 | 0 is at the place pointed to by u_ar0 (by setting the vma of the start | |
157 | of the section to -u_ar0). GDB uses this info to locate the regs, | |
158 | using minor trickery to get around the offset-or-absolute-addr problem. */ | |
159 | core_regsec (abfd)->vma = 0 - (int) u.u_ar0; | |
ff37ea55 JG |
160 | |
161 | core_datasec (abfd)->filepos = NBPG * UPAGES; | |
162 | core_stacksec (abfd)->filepos = (NBPG * UPAGES) + NBPG * u.u_dsize; | |
1f29e30b | 163 | core_regsec (abfd)->filepos = 0; /* Register segment is the upage */ |
ff37ea55 JG |
164 | |
165 | /* Align to word at least */ | |
166 | core_stacksec (abfd)->alignment_power = 2; | |
167 | core_datasec (abfd)->alignment_power = 2; | |
168 | core_regsec (abfd)->alignment_power = 2; | |
169 | ||
170 | abfd->sections = core_stacksec (abfd); | |
171 | core_stacksec (abfd)->next = core_datasec (abfd); | |
172 | core_datasec (abfd)->next = core_regsec (abfd); | |
173 | abfd->section_count = 3; | |
174 | ||
175 | return abfd->xvec; | |
ff37ea55 JG |
176 | } |
177 | ||
178 | char * | |
179 | trad_unix_core_file_failing_command (abfd) | |
180 | bfd *abfd; | |
181 | { | |
1f29e30b JG |
182 | #ifndef NO_CORE_COMMAND |
183 | char *com = abfd->tdata.trad_core_data->u.u_comm; | |
184 | if (*com) | |
185 | return com; | |
ff37ea55 | 186 | else |
1f29e30b | 187 | #endif |
ff37ea55 JG |
188 | return 0; |
189 | } | |
190 | ||
7ed4093a | 191 | /* ARGSUSED */ |
ff37ea55 | 192 | int |
7ed4093a SC |
193 | trad_unix_core_file_failing_signal (ignore_abfd) |
194 | bfd *ignore_abfd; | |
ff37ea55 JG |
195 | { |
196 | return -1; /* FIXME, where is it? */ | |
197 | } | |
198 | ||
7ed4093a | 199 | /* ARGSUSED */ |
ff37ea55 JG |
200 | boolean |
201 | trad_unix_core_file_matches_executable_p (core_bfd, exec_bfd) | |
202 | bfd *core_bfd, *exec_bfd; | |
203 | { | |
204 | return true; /* FIXME, We have no way of telling at this point */ | |
205 | } | |
6a469027 JG |
206 | \f |
207 | /* No archive file support via this BFD */ | |
208 | #define trad_unix_openr_next_archived_file bfd_generic_openr_next_archived_file | |
209 | #define trad_unix_generic_stat_arch_elt bfd_generic_stat_arch_elt | |
210 | #define trad_unix_slurp_armap bfd_false | |
211 | #define trad_unix_slurp_extended_name_table bfd_true | |
1f29e30b JG |
212 | #define trad_unix_write_armap (boolean (*) PARAMS \ |
213 | ((bfd *arch, unsigned int elength, struct orl *map, \ | |
214 | unsigned int orl_count, int stridx))) bfd_false | |
6a469027 JG |
215 | #define trad_unix_truncate_arname bfd_dont_truncate_arname |
216 | #define aout_32_openr_next_archived_file bfd_generic_openr_next_archived_file | |
217 | ||
218 | #define trad_unix_close_and_cleanup bfd_generic_close_and_cleanup | |
1f29e30b JG |
219 | #define trad_unix_set_section_contents (boolean (*) PARAMS \ |
220 | ((bfd *abfd, asection *section, PTR data, file_ptr offset, \ | |
221 | bfd_size_type count))) bfd_false | |
6a469027 | 222 | #define trad_unix_get_section_contents bfd_generic_get_section_contents |
1f29e30b JG |
223 | #define trad_unix_new_section_hook (boolean (*) PARAMS \ |
224 | ((bfd *, sec_ptr))) bfd_true | |
6a469027 | 225 | #define trad_unix_get_symtab_upper_bound bfd_0u |
1f29e30b JG |
226 | #define trad_unix_get_symtab (unsigned int (*) PARAMS \ |
227 | ((bfd *, struct symbol_cache_entry **))) bfd_0u | |
228 | #define trad_unix_get_reloc_upper_bound (unsigned int (*) PARAMS \ | |
229 | ((bfd *, sec_ptr))) bfd_0u | |
230 | #define trad_unix_canonicalize_reloc (unsigned int (*) PARAMS \ | |
231 | ((bfd *, sec_ptr, arelent **, struct symbol_cache_entry**))) bfd_0u | |
232 | #define trad_unix_make_empty_symbol (struct symbol_cache_entry * \ | |
0dc1bc8b | 233 | (*) (bfd *)) bfd_false |
1f29e30b JG |
234 | #define trad_unix_print_symbol (void (*) PARAMS \ |
235 | ((bfd *, PTR, struct symbol_cache_entry *, \ | |
236 | bfd_print_symbol_type))) bfd_false | |
237 | #define trad_unix_get_lineno (alent * (*) PARAMS \ | |
238 | ((bfd *, struct symbol_cache_entry *))) bfd_nullvoidptr | |
239 | #define trad_unix_set_arch_mach (boolean (*) PARAMS \ | |
0dc1bc8b | 240 | ((bfd *, enum bfd_architecture, unsigned long))) bfd_false |
1f29e30b | 241 | #define trad_unix_find_nearest_line (boolean (*) PARAMS \ |
0dc1bc8b | 242 | ((bfd *abfd, struct sec *section, \ |
6a469027 JG |
243 | struct symbol_cache_entry **symbols,bfd_vma offset, \ |
244 | CONST char **file, CONST char **func, unsigned int *line))) bfd_false | |
1f29e30b | 245 | #define trad_unix_sizeof_headers (int (*) PARAMS \ |
0dc1bc8b | 246 | ((bfd *, boolean))) bfd_0 |
6a469027 JG |
247 | |
248 | #define trad_unix_bfd_debug_info_start bfd_void | |
249 | #define trad_unix_bfd_debug_info_end bfd_void | |
1f29e30b | 250 | #define trad_unix_bfd_debug_info_accumulate (void (*) PARAMS \ |
0dc1bc8b | 251 | ((bfd *, struct sec *))) bfd_void |
1f29e30b JG |
252 | #define trad_unix_bfd_get_relocated_section_contents bfd_generic_get_relocated_section_contents |
253 | #define trad_unix_bfd_relax_section bfd_generic_relax_section | |
0dc1bc8b ILT |
254 | #define trad_unix_bfd_seclet_link \ |
255 | ((boolean (*) PARAMS ((bfd *, PTR, boolean))) bfd_false) | |
256 | ||
637942e4 JG |
257 | /* If somebody calls any byte-swapping routines, shoot them. */ |
258 | void | |
259 | swap_abort() | |
260 | { | |
261 | abort(); /* This way doesn't require any declaration for ANSI to fuck up */ | |
262 | } | |
1f29e30b JG |
263 | #define NO_GET ((bfd_vma (*) PARAMS (( bfd_byte *))) swap_abort ) |
264 | #define NO_PUT ((void (*) PARAMS ((bfd_vma, bfd_byte *))) swap_abort ) | |
6a469027 | 265 | |
637942e4 | 266 | bfd_target trad_core_vec = |
6a469027 | 267 | { |
637942e4 | 268 | "trad-core", |
6a469027 JG |
269 | bfd_target_unknown_flavour, |
270 | true, /* target byte order */ | |
271 | true, /* target headers byte order */ | |
272 | (HAS_RELOC | EXEC_P | /* object flags */ | |
273 | HAS_LINENO | HAS_DEBUG | | |
274 | HAS_SYMS | HAS_LOCALS | DYNAMIC | WP_TEXT | D_PAGED), | |
275 | (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */ | |
0dc1bc8b | 276 | 0, /* symbol prefix */ |
6a469027 JG |
277 | ' ', /* ar_pad_char */ |
278 | 16, /* ar_max_namelen */ | |
279 | 3, /* minimum alignment power */ | |
637942e4 JG |
280 | NO_GET, NO_PUT, NO_GET, NO_PUT, NO_GET, NO_PUT, /* data */ |
281 | NO_GET, NO_PUT, NO_GET, NO_PUT, NO_GET, NO_PUT, /* hdrs */ | |
282 | ||
283 | {_bfd_dummy_target, _bfd_dummy_target, | |
284 | _bfd_dummy_target, trad_unix_core_file_p}, | |
285 | {bfd_false, bfd_false, /* bfd_create_object */ | |
286 | bfd_false, bfd_false}, | |
287 | {bfd_false, bfd_false, /* bfd_write_contents */ | |
288 | bfd_false, bfd_false}, | |
6a469027 JG |
289 | |
290 | JUMP_TABLE(trad_unix) | |
291 | }; |