daily update
[binutils.git] / bfd / osf-core.c
blob95292a3e4bc0b85f35515f8ccdd77ba8340ac7ad
1 /* BFD back-end for OSF/1 core files.
2 Copyright 1993, 1994, 1995, 1998, 1999, 2001, 2002
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 *make_bfd_asection
34 PARAMS ((bfd *, const char *, flagword, bfd_size_type, bfd_vma, file_ptr));
35 static const bfd_target *osf_core_core_file_p
36 PARAMS ((bfd *));
37 static char *osf_core_core_file_failing_command
38 PARAMS ((bfd *));
39 static int osf_core_core_file_failing_signal
40 PARAMS ((bfd *));
41 static bfd_boolean osf_core_core_file_matches_executable_p
42 PARAMS ((bfd *, bfd *));
43 static void swap_abort
44 PARAMS ((void));
46 /* These are stored in the bfd's tdata */
48 struct osf_core_struct
50 int sig;
51 char cmd[MAXCOMLEN + 1];
54 #define core_hdr(bfd) ((bfd)->tdata.osf_core_data)
55 #define core_signal(bfd) (core_hdr(bfd)->sig)
56 #define core_command(bfd) (core_hdr(bfd)->cmd)
58 static asection *
59 make_bfd_asection (abfd, name, flags, _raw_size, vma, filepos)
60 bfd *abfd;
61 const char *name;
62 flagword flags;
63 bfd_size_type _raw_size;
64 bfd_vma vma;
65 file_ptr filepos;
67 asection *asect;
69 asect = bfd_make_section_anyway (abfd, name);
70 if (!asect)
71 return NULL;
73 asect->flags = flags;
74 asect->_raw_size = _raw_size;
75 asect->vma = vma;
76 asect->filepos = filepos;
77 asect->alignment_power = 8;
79 return asect;
82 static const bfd_target *
83 osf_core_core_file_p (abfd)
84 bfd *abfd;
86 int val;
87 int i;
88 char *secname;
89 struct core_filehdr core_header;
90 bfd_size_type amt;
92 amt = sizeof core_header;
93 val = bfd_bread ((PTR) &core_header, amt, abfd);
94 if (val != sizeof core_header)
95 return NULL;
97 if (strncmp (core_header.magic, "Core", 4) != 0)
98 return NULL;
100 core_hdr (abfd) = (struct osf_core_struct *)
101 bfd_zalloc (abfd, (bfd_size_type) sizeof (struct osf_core_struct));
102 if (!core_hdr (abfd))
103 return NULL;
105 strncpy (core_command (abfd), core_header.name, MAXCOMLEN + 1);
106 core_signal (abfd) = core_header.signo;
108 for (i = 0; i < core_header.nscns; i++)
110 struct core_scnhdr core_scnhdr;
111 flagword flags;
113 amt = sizeof core_scnhdr;
114 val = bfd_bread ((PTR) &core_scnhdr, amt, abfd);
115 if (val != sizeof core_scnhdr)
116 break;
118 /* Skip empty sections. */
119 if (core_scnhdr.size == 0 || core_scnhdr.scnptr == 0)
120 continue;
122 switch (core_scnhdr.scntype)
124 case SCNRGN:
125 secname = ".data";
126 flags = SEC_ALLOC + SEC_LOAD + SEC_HAS_CONTENTS;
127 break;
128 case SCNSTACK:
129 secname = ".stack";
130 flags = SEC_ALLOC + SEC_LOAD + SEC_HAS_CONTENTS;
131 break;
132 case SCNREGS:
133 secname = ".reg";
134 flags = SEC_HAS_CONTENTS;
135 break;
136 default:
137 (*_bfd_error_handler) (_("Unhandled OSF/1 core file section type %d\n"),
138 core_scnhdr.scntype);
139 continue;
142 if (!make_bfd_asection (abfd, secname, flags,
143 (bfd_size_type) core_scnhdr.size,
144 (bfd_vma) core_scnhdr.vaddr,
145 (file_ptr) core_scnhdr.scnptr))
146 goto fail;
149 /* OK, we believe you. You're a core file (sure, sure). */
151 return abfd->xvec;
153 fail:
154 bfd_release (abfd, core_hdr (abfd));
155 core_hdr (abfd) = NULL;
156 bfd_section_list_clear (abfd);
157 return NULL;
160 static char *
161 osf_core_core_file_failing_command (abfd)
162 bfd *abfd;
164 return core_command (abfd);
167 /* ARGSUSED */
168 static int
169 osf_core_core_file_failing_signal (abfd)
170 bfd *abfd;
172 return core_signal (abfd);
175 /* ARGSUSED */
176 static bfd_boolean
177 osf_core_core_file_matches_executable_p (core_bfd, exec_bfd)
178 bfd *core_bfd ATTRIBUTE_UNUSED;
179 bfd *exec_bfd ATTRIBUTE_UNUSED;
181 return TRUE; /* FIXME, We have no way of telling at this point */
184 /* If somebody calls any byte-swapping routines, shoot them. */
185 static void
186 swap_abort()
188 abort(); /* This way doesn't require any declaration for ANSI to fuck up */
190 #define NO_GET ((bfd_vma (*) PARAMS (( const bfd_byte *))) swap_abort )
191 #define NO_PUT ((void (*) PARAMS ((bfd_vma, bfd_byte *))) swap_abort )
192 #define NO_SIGNED_GET \
193 ((bfd_signed_vma (*) PARAMS ((const bfd_byte *))) swap_abort )
195 const bfd_target osf_core_vec =
197 "osf-core",
198 bfd_target_unknown_flavour,
199 BFD_ENDIAN_LITTLE, /* target byte order */
200 BFD_ENDIAN_LITTLE, /* target headers byte order */
201 (HAS_RELOC | EXEC_P | /* object flags */
202 HAS_LINENO | HAS_DEBUG |
203 HAS_SYMS | HAS_LOCALS | WP_TEXT | D_PAGED),
204 (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
205 0, /* symbol prefix */
206 ' ', /* ar_pad_char */
207 16, /* ar_max_namelen */
208 NO_GET, NO_SIGNED_GET, NO_PUT, /* 64 bit data */
209 NO_GET, NO_SIGNED_GET, NO_PUT, /* 32 bit data */
210 NO_GET, NO_SIGNED_GET, NO_PUT, /* 16 bit data */
211 NO_GET, NO_SIGNED_GET, NO_PUT, /* 64 bit hdrs */
212 NO_GET, NO_SIGNED_GET, NO_PUT, /* 32 bit hdrs */
213 NO_GET, NO_SIGNED_GET, NO_PUT, /* 16 bit hdrs */
215 { /* bfd_check_format */
216 _bfd_dummy_target, /* unknown format */
217 _bfd_dummy_target, /* object file */
218 _bfd_dummy_target, /* archive */
219 osf_core_core_file_p /* a core file */
221 { /* bfd_set_format */
222 bfd_false, bfd_false,
223 bfd_false, bfd_false
225 { /* bfd_write_contents */
226 bfd_false, bfd_false,
227 bfd_false, bfd_false
230 BFD_JUMP_TABLE_GENERIC (_bfd_generic),
231 BFD_JUMP_TABLE_COPY (_bfd_generic),
232 BFD_JUMP_TABLE_CORE (osf_core),
233 BFD_JUMP_TABLE_ARCHIVE (_bfd_noarchive),
234 BFD_JUMP_TABLE_SYMBOLS (_bfd_nosymbols),
235 BFD_JUMP_TABLE_RELOCS (_bfd_norelocs),
236 BFD_JUMP_TABLE_WRITE (_bfd_generic),
237 BFD_JUMP_TABLE_LINK (_bfd_nolink),
238 BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),
240 NULL,
242 (PTR) 0 /* backend_data */