Commit | Line | Data |
---|---|---|
4c3721d5 ILT |
1 | /* BFD back-end for HP/UX core files. |
2 | Copyright 1993 Free Software Foundation, Inc. | |
3 | Written by Stu Grossman, Cygnus Support. | |
4 | Converted to back-end form by Ian Lance Taylor, Cygnus SUpport | |
5 | ||
6 | This file is part of BFD, the Binary File Descriptor library. | |
7 | ||
8 | This program is free software; you can redistribute it and/or modify | |
9 | it under the terms of the GNU General Public License as published by | |
10 | the Free Software Foundation; either version 2 of the License, or | |
11 | (at your option) any later version. | |
12 | ||
13 | This program is distributed in the hope that it will be useful, | |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | GNU General Public License for more details. | |
17 | ||
18 | You should have received a copy of the GNU General Public License | |
19 | along with this program; if not, write to the Free Software | |
20 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ | |
21 | ||
22 | /* This file can only be compiled on systems which use HP/UX style | |
23 | core files. In the config/XXXXXX.mh file for such a system add | |
24 | HDEFINES=-DHPUX_CORE | |
25 | HDEPFILES=hpux-core.o | |
26 | */ | |
27 | ||
28 | #include "bfd.h" | |
29 | #include "sysdep.h" | |
30 | #include "libbfd.h" | |
31 | ||
32 | #if defined (HOST_HPPAHPUX) || defined (HOST_HP300HPUX) | |
33 | ||
34 | /* FIXME: sys/core.h doesn't exist for HPUX version 7. HPUX version | |
35 | 5, 6, and 7 core files seem to be standard trad-core.c type core | |
36 | files; can we just use trad-core.c in addition to this file? */ | |
37 | ||
38 | #include <sys/core.h> | |
39 | #include <sys/utsname.h> | |
40 | ||
41 | #endif /* HOST_HPPAHPUX */ | |
42 | ||
43 | #ifdef HOST_HPPABSD | |
44 | ||
45 | /* Not a very swift place to put it, but that's where the BSD port | |
46 | puts them. */ | |
47 | #include "/hpux/usr/include/sys/core.h" | |
48 | ||
49 | #endif /* HOST_HPPABSD */ | |
50 | ||
51 | #include <stdio.h> | |
52 | #include <sys/types.h> | |
53 | #include <sys/param.h> | |
54 | #include <sys/dir.h> | |
55 | #include <signal.h> | |
56 | #include <machine/reg.h> | |
57 | #include <sys/user.h> /* After a.out.h */ | |
58 | #include <sys/file.h> | |
59 | #include <errno.h> | |
60 | ||
61 | /* These are stored in the bfd's tdata */ | |
62 | ||
63 | struct hpux_core_struct | |
64 | { | |
65 | int sig; | |
66 | char cmd[MAXCOMLEN + 1]; | |
67 | asection *data_section; | |
68 | asection *stack_section; | |
69 | asection *reg_section; | |
70 | }; | |
71 | ||
72 | #define core_hdr(bfd) ((bfd)->tdata.hpux_core_data) | |
73 | #define core_signal(bfd) (core_hdr(bfd)->sig) | |
74 | #define core_command(bfd) (core_hdr(bfd)->cmd) | |
75 | #define core_datasec(bfd) (core_hdr(bfd)->data_section) | |
76 | #define core_stacksec(bfd) (core_hdr(bfd)->stack_section) | |
77 | #define core_regsec(bfd) (core_hdr(bfd)->reg_section) | |
78 | ||
79 | static asection * | |
80 | make_bfd_asection (abfd, name, flags, _raw_size, vma, alignment_power) | |
81 | bfd *abfd; | |
82 | CONST char *name; | |
83 | flagword flags; | |
84 | bfd_size_type _raw_size; | |
85 | bfd_vma vma; | |
86 | unsigned int alignment_power; | |
87 | { | |
88 | asection *asect; | |
89 | ||
90 | asect = bfd_make_section (abfd, name); | |
91 | if (!asect) | |
92 | return NULL; | |
93 | ||
94 | asect->flags = flags; | |
95 | asect->_raw_size = _raw_size; | |
96 | asect->vma = vma; | |
97 | asect->filepos = bfd_tell (abfd); | |
98 | asect->alignment_power = alignment_power; | |
99 | ||
100 | return asect; | |
101 | } | |
102 | ||
103 | static asymbol * | |
104 | hpux_core_make_empty_symbol (abfd) | |
105 | bfd *abfd; | |
106 | { | |
107 | asymbol *new = (asymbol *) bfd_zalloc (abfd, sizeof (asymbol)); | |
108 | new->the_bfd = abfd; | |
109 | return new; | |
110 | } | |
111 | ||
112 | static bfd_target * | |
113 | hpux_core_core_file_p (abfd) | |
114 | bfd *abfd; | |
115 | { | |
116 | core_hdr (abfd) = (struct hpux_core_struct *) | |
117 | bfd_zalloc (abfd, sizeof (struct hpux_core_struct)); | |
118 | if (!core_hdr (abfd)) | |
119 | return NULL; | |
120 | ||
121 | while (1) | |
122 | { | |
123 | int val; | |
124 | struct corehead core_header; | |
125 | ||
126 | val = bfd_read ((void *) &core_header, 1, sizeof core_header, abfd); | |
127 | if (val <= 0) | |
128 | break; | |
129 | switch (core_header.type) | |
130 | { | |
131 | case CORE_KERNEL: | |
132 | case CORE_FORMAT: | |
133 | bfd_seek (abfd, core_header.len, SEEK_CUR); /* Just skip this */ | |
134 | break; | |
135 | case CORE_EXEC: | |
136 | { | |
137 | struct proc_exec proc_exec; | |
138 | bfd_read ((void *) &proc_exec, 1, core_header.len, abfd); | |
139 | strncpy (core_command (abfd), proc_exec.cmd, MAXCOMLEN + 1); | |
140 | } | |
141 | break; | |
142 | case CORE_PROC: | |
143 | { | |
144 | struct proc_info proc_info; | |
145 | core_regsec (abfd) = make_bfd_asection (abfd, ".reg", | |
146 | SEC_ALLOC + SEC_HAS_CONTENTS, | |
147 | core_header.len, | |
148 | (int) &proc_info - (int) &proc_info.hw_regs, | |
149 | 2); | |
150 | bfd_read (&proc_info, 1, core_header.len, abfd); | |
151 | core_signal (abfd) = proc_info.sig; | |
152 | } | |
153 | if (!core_regsec (abfd)) | |
154 | return NULL; | |
155 | break; | |
156 | case CORE_DATA: | |
157 | core_datasec (abfd) = make_bfd_asection (abfd, ".data", | |
158 | SEC_ALLOC + SEC_LOAD + SEC_HAS_CONTENTS, | |
159 | core_header.len, | |
160 | core_header.addr, | |
161 | 2); | |
162 | if (!core_datasec (abfd)) | |
163 | return NULL; | |
164 | bfd_seek (abfd, core_header.len, SEEK_CUR); | |
165 | break; | |
166 | case CORE_STACK: | |
167 | core_stacksec (abfd) = make_bfd_asection (abfd, ".stack", | |
168 | SEC_ALLOC + SEC_LOAD + SEC_HAS_CONTENTS, | |
169 | core_header.len, | |
170 | core_header.addr, | |
171 | 2); | |
172 | if (!core_stacksec (abfd)) | |
173 | return NULL; | |
174 | bfd_seek (abfd, core_header.len, SEEK_CUR); | |
175 | break; | |
176 | default: | |
177 | /* Falling into here is an error and should prevent this | |
178 | target from matching. That way systems which use hpux | |
179 | cores along with other formats can still work. */ | |
180 | return 0; | |
181 | } | |
182 | } | |
183 | ||
184 | /* OK, we believe you. You're a core file (sure, sure). */ | |
185 | ||
186 | return abfd->xvec; | |
187 | } | |
188 | ||
189 | static char * | |
190 | hpux_core_core_file_failing_command (abfd) | |
191 | bfd *abfd; | |
192 | { | |
193 | return core_command (abfd); | |
194 | } | |
195 | ||
196 | /* ARGSUSED */ | |
197 | static int | |
198 | hpux_core_core_file_failing_signal (abfd) | |
199 | bfd *abfd; | |
200 | { | |
201 | return core_signal (abfd); | |
202 | } | |
203 | ||
204 | /* ARGSUSED */ | |
205 | static boolean | |
206 | hpux_core_core_file_matches_executable_p (core_bfd, exec_bfd) | |
207 | bfd *core_bfd, *exec_bfd; | |
208 | { | |
209 | return true; /* FIXME, We have no way of telling at this point */ | |
210 | } | |
211 | \f | |
212 | /* No archive file support via this BFD */ | |
213 | #define hpux_core_openr_next_archived_file bfd_generic_openr_next_archived_file | |
214 | #define hpux_core_generic_stat_arch_elt bfd_generic_stat_arch_elt | |
215 | #define hpux_core_slurp_armap bfd_false | |
216 | #define hpux_core_slurp_extended_name_table bfd_true | |
217 | #define hpux_core_write_armap (boolean (*) PARAMS \ | |
218 | ((bfd *arch, unsigned int elength, struct orl *map, \ | |
219 | unsigned int orl_count, int stridx))) bfd_false | |
220 | #define hpux_core_truncate_arname bfd_dont_truncate_arname | |
221 | ||
222 | #define hpux_core_close_and_cleanup bfd_generic_close_and_cleanup | |
223 | #define hpux_core_set_section_contents (boolean (*) PARAMS \ | |
224 | ((bfd *abfd, asection *section, PTR data, file_ptr offset, \ | |
225 | bfd_size_type count))) bfd_false | |
226 | #define hpux_core_get_section_contents bfd_generic_get_section_contents | |
227 | #define hpux_core_new_section_hook (boolean (*) PARAMS \ | |
228 | ((bfd *, sec_ptr))) bfd_true | |
229 | #define hpux_core_get_symtab_upper_bound bfd_0u | |
230 | #define hpux_core_get_symtab (unsigned int (*) PARAMS \ | |
231 | ((bfd *, struct symbol_cache_entry **))) bfd_0u | |
232 | #define hpux_core_get_reloc_upper_bound (unsigned int (*) PARAMS \ | |
233 | ((bfd *, sec_ptr))) bfd_0u | |
234 | #define hpux_core_canonicalize_reloc (unsigned int (*) PARAMS \ | |
235 | ((bfd *, sec_ptr, arelent **, struct symbol_cache_entry**))) bfd_0u | |
236 | #define hpux_core_print_symbol (void (*) PARAMS \ | |
237 | ((bfd *, PTR, struct symbol_cache_entry *, \ | |
238 | bfd_print_symbol_type))) bfd_false | |
239 | #define hpux_core_get_symbol_info (void (*) PARAMS \ | |
240 | ((bfd *, struct symbol_cache_entry *, \ | |
241 | symbol_info *))) bfd_false | |
242 | #define hpux_core_get_lineno (alent * (*) PARAMS \ | |
243 | ((bfd *, struct symbol_cache_entry *))) bfd_nullvoidptr | |
244 | #define hpux_core_set_arch_mach (boolean (*) PARAMS \ | |
245 | ((bfd *, enum bfd_architecture, unsigned long))) bfd_false | |
246 | #define hpux_core_find_nearest_line (boolean (*) PARAMS \ | |
247 | ((bfd *abfd, struct sec *section, \ | |
248 | struct symbol_cache_entry **symbols,bfd_vma offset, \ | |
249 | CONST char **file, CONST char **func, unsigned int *line))) bfd_false | |
250 | #define hpux_core_sizeof_headers (int (*) PARAMS \ | |
251 | ((bfd *, boolean))) bfd_0 | |
252 | ||
253 | #define hpux_core_bfd_debug_info_start bfd_void | |
254 | #define hpux_core_bfd_debug_info_end bfd_void | |
255 | #define hpux_core_bfd_debug_info_accumulate (void (*) PARAMS \ | |
256 | ((bfd *, struct sec *))) bfd_void | |
257 | #define hpux_core_bfd_get_relocated_section_contents bfd_generic_get_relocated_section_contents | |
258 | #define hpux_core_bfd_relax_section bfd_generic_relax_section | |
259 | #define hpux_core_bfd_reloc_type_lookup \ | |
260 | ((CONST struct reloc_howto_struct *(*) PARAMS ((bfd *, bfd_reloc_code_real_type))) bfd_nullvoidptr) | |
261 | #define hpux_core_bfd_make_debug_symbol \ | |
262 | ((asymbol *(*) PARAMS ((bfd *, void *, unsigned long))) bfd_nullvoidptr) | |
263 | #define hpux_core_bfd_link_hash_table_create \ | |
264 | ((struct bfd_link_hash_table *(*) PARAMS ((bfd *))) bfd_nullvoidptr) | |
265 | #define hpux_core_bfd_link_add_symbols \ | |
266 | ((boolean (*) PARAMS ((bfd *, struct bfd_link_info *))) bfd_false) | |
267 | #define hpux_core_bfd_final_link \ | |
268 | ((boolean (*) PARAMS ((bfd *, struct bfd_link_info *))) bfd_false) | |
269 | ||
270 | /* If somebody calls any byte-swapping routines, shoot them. */ | |
271 | void | |
272 | swap_abort() | |
273 | { | |
274 | abort(); /* This way doesn't require any declaration for ANSI to fuck up */ | |
275 | } | |
276 | #define NO_GET ((bfd_vma (*) PARAMS (( bfd_byte *))) swap_abort ) | |
277 | #define NO_PUT ((void (*) PARAMS ((bfd_vma, bfd_byte *))) swap_abort ) | |
278 | #define NO_SIGNED_GET ((bfd_signed_vma (*) PARAMS ((bfd_byte *))) swap_abort ) | |
279 | ||
280 | bfd_target hpux_core_vec = | |
281 | { | |
282 | "hpux-core", | |
283 | bfd_target_unknown_flavour, | |
284 | true, /* target byte order */ | |
285 | true, /* target headers byte order */ | |
286 | (HAS_RELOC | EXEC_P | /* object flags */ | |
287 | HAS_LINENO | HAS_DEBUG | | |
288 | HAS_SYMS | HAS_LOCALS | WP_TEXT | D_PAGED), | |
289 | (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */ | |
290 | 0, /* symbol prefix */ | |
291 | ' ', /* ar_pad_char */ | |
292 | 16, /* ar_max_namelen */ | |
293 | 3, /* minimum alignment power */ | |
294 | NO_GET, NO_SIGNED_GET, NO_PUT, /* 64 bit data */ | |
295 | NO_GET, NO_SIGNED_GET, NO_PUT, /* 32 bit data */ | |
296 | NO_GET, NO_SIGNED_GET, NO_PUT, /* 16 bit data */ | |
297 | NO_GET, NO_SIGNED_GET, NO_PUT, /* 64 bit hdrs */ | |
298 | NO_GET, NO_SIGNED_GET, NO_PUT, /* 32 bit hdrs */ | |
299 | NO_GET, NO_SIGNED_GET, NO_PUT, /* 16 bit hdrs */ | |
300 | ||
301 | { /* bfd_check_format */ | |
302 | _bfd_dummy_target, /* unknown format */ | |
303 | _bfd_dummy_target, /* object file */ | |
304 | _bfd_dummy_target, /* archive */ | |
305 | hpux_core_core_file_p /* a core file */ | |
306 | }, | |
307 | { /* bfd_set_format */ | |
308 | bfd_false, bfd_false, | |
309 | bfd_false, bfd_false | |
310 | }, | |
311 | { /* bfd_write_contents */ | |
312 | bfd_false, bfd_false, | |
313 | bfd_false, bfd_false | |
314 | }, | |
315 | ||
316 | JUMP_TABLE(hpux_core), | |
317 | (PTR) 0 /* backend_data */ | |
318 | }; |