Touches most files in bfd/, so likely will be blamed for everything..
[binutils.git] / bfd / osf-core.c
blobbafc72857bfe9cb6061af4cc03dd2703ff867a45
1 /* BFD back-end for OSF/1 core files.
2 Copyright 1993, 1994, 1995, 1998, 1999, 2001
3 Free Software Foundation, Inc.
5 This file is part of BFD, the Binary File Descriptor library.
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.
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.
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. */
21 /* This file can only be compiled on systems which use OSF/1 style
22 core files. */
24 #include "bfd.h"
25 #include "sysdep.h"
26 #include "libbfd.h"
28 #include <sys/user.h>
29 #include <sys/core.h>
31 /* forward declarations */
33 static asection *
34 make_bfd_asection PARAMS ((bfd *, const char *, flagword, bfd_size_type,
35 bfd_vma, file_ptr));
36 static asymbol *
37 osf_core_make_empty_symbol PARAMS ((bfd *));
38 static const bfd_target *
39 osf_core_core_file_p PARAMS ((bfd *));
40 static char *
41 osf_core_core_file_failing_command PARAMS ((bfd *));
42 static int
43 osf_core_core_file_failing_signal PARAMS ((bfd *));
44 static boolean
45 osf_core_core_file_matches_executable_p PARAMS ((bfd *, bfd *));
46 static void
47 swap_abort PARAMS ((void));
49 /* These are stored in the bfd's tdata */
51 struct osf_core_struct
53 int sig;
54 char cmd[MAXCOMLEN + 1];
57 #define core_hdr(bfd) ((bfd)->tdata.osf_core_data)
58 #define core_signal(bfd) (core_hdr(bfd)->sig)
59 #define core_command(bfd) (core_hdr(bfd)->cmd)
61 static asection *
62 make_bfd_asection (abfd, name, flags, _raw_size, vma, filepos)
63 bfd *abfd;
64 const char *name;
65 flagword flags;
66 bfd_size_type _raw_size;
67 bfd_vma vma;
68 file_ptr filepos;
70 asection *asect;
72 asect = bfd_make_section_anyway (abfd, name);
73 if (!asect)
74 return NULL;
76 asect->flags = flags;
77 asect->_raw_size = _raw_size;
78 asect->vma = vma;
79 asect->filepos = filepos;
80 asect->alignment_power = 8;
82 return asect;
85 static asymbol *
86 osf_core_make_empty_symbol (abfd)
87 bfd *abfd;
89 asymbol *new;
91 new = (asymbol *) bfd_zalloc (abfd, (bfd_size_type) sizeof (asymbol));
92 if (new)
93 new->the_bfd = abfd;
94 return new;
97 static const bfd_target *
98 osf_core_core_file_p (abfd)
99 bfd *abfd;
101 int val;
102 int i;
103 char *secname;
104 struct core_filehdr core_header;
105 bfd_size_type amt;
107 amt = sizeof core_header;
108 val = bfd_bread ((PTR) &core_header, amt, abfd);
109 if (val != sizeof core_header)
110 return NULL;
112 if (strncmp (core_header.magic, "Core", 4) != 0)
113 return NULL;
115 core_hdr (abfd) = (struct osf_core_struct *)
116 bfd_zalloc (abfd, (bfd_size_type) sizeof (struct osf_core_struct));
117 if (!core_hdr (abfd))
118 return NULL;
120 strncpy (core_command (abfd), core_header.name, MAXCOMLEN + 1);
121 core_signal (abfd) = core_header.signo;
123 for (i = 0; i < core_header.nscns; i++)
125 struct core_scnhdr core_scnhdr;
126 flagword flags;
128 amt = sizeof core_scnhdr;
129 val = bfd_bread ((PTR) &core_scnhdr, amt, abfd);
130 if (val != sizeof core_scnhdr)
131 break;
133 /* Skip empty sections. */
134 if (core_scnhdr.size == 0 || core_scnhdr.scnptr == 0)
135 continue;
137 switch (core_scnhdr.scntype)
139 case SCNRGN:
140 secname = ".data";
141 flags = SEC_ALLOC + SEC_LOAD + SEC_HAS_CONTENTS;
142 break;
143 case SCNSTACK:
144 secname = ".stack";
145 flags = SEC_ALLOC + SEC_LOAD + SEC_HAS_CONTENTS;
146 break;
147 case SCNREGS:
148 secname = ".reg";
149 flags = SEC_HAS_CONTENTS;
150 break;
151 default:
152 (*_bfd_error_handler) (_("Unhandled OSF/1 core file section type %d\n"),
153 core_scnhdr.scntype);
154 continue;
157 if (!make_bfd_asection (abfd, secname, flags,
158 (bfd_size_type) core_scnhdr.size,
159 (bfd_vma) core_scnhdr.vaddr,
160 (file_ptr) core_scnhdr.scnptr))
161 return NULL;
164 /* OK, we believe you. You're a core file (sure, sure). */
166 return abfd->xvec;
169 static char *
170 osf_core_core_file_failing_command (abfd)
171 bfd *abfd;
173 return core_command (abfd);
176 /* ARGSUSED */
177 static int
178 osf_core_core_file_failing_signal (abfd)
179 bfd *abfd;
181 return core_signal (abfd);
184 /* ARGSUSED */
185 static boolean
186 osf_core_core_file_matches_executable_p (core_bfd, exec_bfd)
187 bfd *core_bfd ATTRIBUTE_UNUSED;
188 bfd *exec_bfd ATTRIBUTE_UNUSED;
190 return true; /* FIXME, We have no way of telling at this point */
193 #define osf_core_get_symtab_upper_bound _bfd_nosymbols_get_symtab_upper_bound
194 #define osf_core_get_symtab _bfd_nosymbols_get_symtab
195 #define osf_core_print_symbol _bfd_nosymbols_print_symbol
196 #define osf_core_get_symbol_info _bfd_nosymbols_get_symbol_info
197 #define osf_core_bfd_is_local_label_name _bfd_nosymbols_bfd_is_local_label_name
198 #define osf_core_get_lineno _bfd_nosymbols_get_lineno
199 #define osf_core_find_nearest_line _bfd_nosymbols_find_nearest_line
200 #define osf_core_bfd_make_debug_symbol _bfd_nosymbols_bfd_make_debug_symbol
201 #define osf_core_read_minisymbols _bfd_nosymbols_read_minisymbols
202 #define osf_core_minisymbol_to_symbol _bfd_nosymbols_minisymbol_to_symbol
204 /* If somebody calls any byte-swapping routines, shoot them. */
205 static void
206 swap_abort()
208 abort(); /* This way doesn't require any declaration for ANSI to fuck up */
210 #define NO_GET ((bfd_vma (*) PARAMS (( const bfd_byte *))) swap_abort )
211 #define NO_PUT ((void (*) PARAMS ((bfd_vma, bfd_byte *))) swap_abort )
212 #define NO_SIGNED_GET \
213 ((bfd_signed_vma (*) PARAMS ((const bfd_byte *))) swap_abort )
215 const bfd_target osf_core_vec =
217 "osf-core",
218 bfd_target_unknown_flavour,
219 BFD_ENDIAN_BIG, /* target byte order */
220 BFD_ENDIAN_BIG, /* target headers byte order */
221 (HAS_RELOC | EXEC_P | /* object flags */
222 HAS_LINENO | HAS_DEBUG |
223 HAS_SYMS | HAS_LOCALS | WP_TEXT | D_PAGED),
224 (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
225 0, /* symbol prefix */
226 ' ', /* ar_pad_char */
227 16, /* ar_max_namelen */
228 NO_GET, NO_SIGNED_GET, NO_PUT, /* 64 bit data */
229 NO_GET, NO_SIGNED_GET, NO_PUT, /* 32 bit data */
230 NO_GET, NO_SIGNED_GET, NO_PUT, /* 16 bit data */
231 NO_GET, NO_SIGNED_GET, NO_PUT, /* 64 bit hdrs */
232 NO_GET, NO_SIGNED_GET, NO_PUT, /* 32 bit hdrs */
233 NO_GET, NO_SIGNED_GET, NO_PUT, /* 16 bit hdrs */
235 { /* bfd_check_format */
236 _bfd_dummy_target, /* unknown format */
237 _bfd_dummy_target, /* object file */
238 _bfd_dummy_target, /* archive */
239 osf_core_core_file_p /* a core file */
241 { /* bfd_set_format */
242 bfd_false, bfd_false,
243 bfd_false, bfd_false
245 { /* bfd_write_contents */
246 bfd_false, bfd_false,
247 bfd_false, bfd_false
250 BFD_JUMP_TABLE_GENERIC (_bfd_generic),
251 BFD_JUMP_TABLE_COPY (_bfd_generic),
252 BFD_JUMP_TABLE_CORE (osf_core),
253 BFD_JUMP_TABLE_ARCHIVE (_bfd_noarchive),
254 BFD_JUMP_TABLE_SYMBOLS (osf_core),
255 BFD_JUMP_TABLE_RELOCS (_bfd_norelocs),
256 BFD_JUMP_TABLE_WRITE (_bfd_generic),
257 BFD_JUMP_TABLE_LINK (_bfd_nolink),
258 BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),
260 NULL,
262 (PTR) 0 /* backend_data */