file itbl-parse.h was initially added on branch binutils-2_10-branch.
[binutils.git] / bfd / osf-core.c
blob4f4fc12dc727a23ffee6526175512f52004f05d0
1 /* BFD back-end for OSF/1 core files.
2 Copyright 1993, 94, 95, 97, 1998 Free Software Foundation, Inc.
4 This file is part of BFD, the Binary File Descriptor library.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
20 /* This file can only be compiled on systems which use OSF/1 style
21 core files. */
23 #include "bfd.h"
24 #include "sysdep.h"
25 #include "libbfd.h"
27 #include <sys/user.h>
28 #include <sys/core.h>
30 /* forward declarations */
32 static asection *
33 make_bfd_asection PARAMS ((bfd *, CONST char *, flagword, bfd_size_type,
34 bfd_vma, file_ptr));
35 static asymbol *
36 osf_core_make_empty_symbol PARAMS ((bfd *));
37 static const bfd_target *
38 osf_core_core_file_p PARAMS ((bfd *));
39 static char *
40 osf_core_core_file_failing_command PARAMS ((bfd *));
41 static int
42 osf_core_core_file_failing_signal PARAMS ((bfd *));
43 static boolean
44 osf_core_core_file_matches_executable_p PARAMS ((bfd *, bfd *));
45 static void
46 swap_abort PARAMS ((void));
48 /* These are stored in the bfd's tdata */
50 struct osf_core_struct
52 int sig;
53 char cmd[MAXCOMLEN + 1];
56 #define core_hdr(bfd) ((bfd)->tdata.osf_core_data)
57 #define core_signal(bfd) (core_hdr(bfd)->sig)
58 #define core_command(bfd) (core_hdr(bfd)->cmd)
60 static asection *
61 make_bfd_asection (abfd, name, flags, _raw_size, vma, filepos)
62 bfd *abfd;
63 CONST char *name;
64 flagword flags;
65 bfd_size_type _raw_size;
66 bfd_vma vma;
67 file_ptr filepos;
69 asection *asect;
71 asect = bfd_make_section_anyway (abfd, name);
72 if (!asect)
73 return NULL;
75 asect->flags = flags;
76 asect->_raw_size = _raw_size;
77 asect->vma = vma;
78 asect->filepos = filepos;
79 asect->alignment_power = 8;
81 return asect;
84 static asymbol *
85 osf_core_make_empty_symbol (abfd)
86 bfd *abfd;
88 asymbol *new = (asymbol *) bfd_zalloc (abfd, sizeof (asymbol));
89 if (new)
90 new->the_bfd = abfd;
91 return new;
94 static const bfd_target *
95 osf_core_core_file_p (abfd)
96 bfd *abfd;
98 int val;
99 int i;
100 char *secname;
101 struct core_filehdr core_header;
103 val = bfd_read ((PTR)&core_header, 1, sizeof core_header, abfd);
104 if (val != sizeof core_header)
105 return NULL;
107 if (strncmp (core_header.magic, "Core", 4) != 0)
108 return NULL;
110 core_hdr (abfd) = (struct osf_core_struct *)
111 bfd_zalloc (abfd, sizeof (struct osf_core_struct));
112 if (!core_hdr (abfd))
113 return NULL;
115 strncpy (core_command (abfd), core_header.name, MAXCOMLEN + 1);
116 core_signal (abfd) = core_header.signo;
118 for (i = 0; i < core_header.nscns; i++)
120 struct core_scnhdr core_scnhdr;
121 flagword flags;
123 val = bfd_read ((PTR)&core_scnhdr, 1, sizeof core_scnhdr, abfd);
124 if (val != sizeof core_scnhdr)
125 break;
127 /* Skip empty sections. */
128 if (core_scnhdr.size == 0 || core_scnhdr.scnptr == 0)
129 continue;
131 switch (core_scnhdr.scntype)
133 case SCNRGN:
134 secname = ".data";
135 flags = SEC_ALLOC + SEC_LOAD + SEC_HAS_CONTENTS;
136 break;
137 case SCNSTACK:
138 secname = ".stack";
139 flags = SEC_ALLOC + SEC_LOAD + SEC_HAS_CONTENTS;
140 break;
141 case SCNREGS:
142 secname = ".reg";
143 flags = SEC_HAS_CONTENTS;
144 break;
145 default:
146 (*_bfd_error_handler) (_("Unhandled OSF/1 core file section type %d\n"),
147 core_scnhdr.scntype);
148 continue;
151 if (!make_bfd_asection (abfd, secname, flags,
152 (bfd_size_type) core_scnhdr.size,
153 (bfd_vma) core_scnhdr.vaddr,
154 (file_ptr) core_scnhdr.scnptr))
155 return NULL;
158 /* OK, we believe you. You're a core file (sure, sure). */
160 return abfd->xvec;
163 static char *
164 osf_core_core_file_failing_command (abfd)
165 bfd *abfd;
167 return core_command (abfd);
170 /* ARGSUSED */
171 static int
172 osf_core_core_file_failing_signal (abfd)
173 bfd *abfd;
175 return core_signal (abfd);
178 /* ARGSUSED */
179 static boolean
180 osf_core_core_file_matches_executable_p (core_bfd, exec_bfd)
181 bfd *core_bfd, *exec_bfd;
183 return true; /* FIXME, We have no way of telling at this point */
186 #define osf_core_get_symtab_upper_bound _bfd_nosymbols_get_symtab_upper_bound
187 #define osf_core_get_symtab _bfd_nosymbols_get_symtab
188 #define osf_core_print_symbol _bfd_nosymbols_print_symbol
189 #define osf_core_get_symbol_info _bfd_nosymbols_get_symbol_info
190 #define osf_core_bfd_is_local_label_name _bfd_nosymbols_bfd_is_local_label_name
191 #define osf_core_get_lineno _bfd_nosymbols_get_lineno
192 #define osf_core_find_nearest_line _bfd_nosymbols_find_nearest_line
193 #define osf_core_bfd_make_debug_symbol _bfd_nosymbols_bfd_make_debug_symbol
194 #define osf_core_read_minisymbols _bfd_nosymbols_read_minisymbols
195 #define osf_core_minisymbol_to_symbol _bfd_nosymbols_minisymbol_to_symbol
197 /* If somebody calls any byte-swapping routines, shoot them. */
198 static void
199 swap_abort()
201 abort(); /* This way doesn't require any declaration for ANSI to fuck up */
203 #define NO_GET ((bfd_vma (*) PARAMS (( const bfd_byte *))) swap_abort )
204 #define NO_PUT ((void (*) PARAMS ((bfd_vma, bfd_byte *))) swap_abort )
205 #define NO_SIGNED_GET \
206 ((bfd_signed_vma (*) PARAMS ((const bfd_byte *))) swap_abort )
208 const bfd_target osf_core_vec =
210 "osf-core",
211 bfd_target_unknown_flavour,
212 BFD_ENDIAN_BIG, /* target byte order */
213 BFD_ENDIAN_BIG, /* target headers byte order */
214 (HAS_RELOC | EXEC_P | /* object flags */
215 HAS_LINENO | HAS_DEBUG |
216 HAS_SYMS | HAS_LOCALS | WP_TEXT | D_PAGED),
217 (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
218 0, /* symbol prefix */
219 ' ', /* ar_pad_char */
220 16, /* ar_max_namelen */
221 NO_GET, NO_SIGNED_GET, NO_PUT, /* 64 bit data */
222 NO_GET, NO_SIGNED_GET, NO_PUT, /* 32 bit data */
223 NO_GET, NO_SIGNED_GET, NO_PUT, /* 16 bit data */
224 NO_GET, NO_SIGNED_GET, NO_PUT, /* 64 bit hdrs */
225 NO_GET, NO_SIGNED_GET, NO_PUT, /* 32 bit hdrs */
226 NO_GET, NO_SIGNED_GET, NO_PUT, /* 16 bit hdrs */
228 { /* bfd_check_format */
229 _bfd_dummy_target, /* unknown format */
230 _bfd_dummy_target, /* object file */
231 _bfd_dummy_target, /* archive */
232 osf_core_core_file_p /* a core file */
234 { /* bfd_set_format */
235 bfd_false, bfd_false,
236 bfd_false, bfd_false
238 { /* bfd_write_contents */
239 bfd_false, bfd_false,
240 bfd_false, bfd_false
243 BFD_JUMP_TABLE_GENERIC (_bfd_generic),
244 BFD_JUMP_TABLE_COPY (_bfd_generic),
245 BFD_JUMP_TABLE_CORE (osf_core),
246 BFD_JUMP_TABLE_ARCHIVE (_bfd_noarchive),
247 BFD_JUMP_TABLE_SYMBOLS (osf_core),
248 BFD_JUMP_TABLE_RELOCS (_bfd_norelocs),
249 BFD_JUMP_TABLE_WRITE (_bfd_generic),
250 BFD_JUMP_TABLE_LINK (_bfd_nolink),
251 BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),
253 NULL,
255 (PTR) 0 /* backend_data */