]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - bfd/osf-core.c
* section.c (bfd_section_init): Remove unnecessary initialisations.
[thirdparty/binutils-gdb.git] / bfd / osf-core.c
1 /* BFD back-end for OSF/1 core files.
2 Copyright 1993, 1994, 1995, 1998, 1999, 2001, 2002
3 Free Software Foundation, Inc.
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
20
21 /* This file can only be compiled on systems which use OSF/1 style
22 core files. */
23
24 #include "bfd.h"
25 #include "sysdep.h"
26 #include "libbfd.h"
27
28 #include <sys/user.h>
29 #include <sys/core.h>
30
31 /* forward declarations */
32
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));
48
49 /* These are stored in the bfd's tdata */
50
51 struct osf_core_struct
52 {
53 int sig;
54 char cmd[MAXCOMLEN + 1];
55 };
56
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)
60
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;
69 {
70 asection *asect;
71
72 asect = bfd_make_section_anyway (abfd, name);
73 if (!asect)
74 return NULL;
75
76 asect->flags = flags;
77 asect->_raw_size = _raw_size;
78 asect->vma = vma;
79 asect->filepos = filepos;
80 asect->alignment_power = 8;
81
82 return asect;
83 }
84
85 static asymbol *
86 osf_core_make_empty_symbol (abfd)
87 bfd *abfd;
88 {
89 asymbol *new;
90
91 new = (asymbol *) bfd_zalloc (abfd, (bfd_size_type) sizeof (asymbol));
92 if (new)
93 new->the_bfd = abfd;
94 return new;
95 }
96
97 static const bfd_target *
98 osf_core_core_file_p (abfd)
99 bfd *abfd;
100 {
101 int val;
102 int i;
103 char *secname;
104 struct core_filehdr core_header;
105 bfd_size_type amt;
106
107 amt = sizeof core_header;
108 val = bfd_bread ((PTR) &core_header, amt, abfd);
109 if (val != sizeof core_header)
110 return NULL;
111
112 if (strncmp (core_header.magic, "Core", 4) != 0)
113 return NULL;
114
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;
119
120 strncpy (core_command (abfd), core_header.name, MAXCOMLEN + 1);
121 core_signal (abfd) = core_header.signo;
122
123 for (i = 0; i < core_header.nscns; i++)
124 {
125 struct core_scnhdr core_scnhdr;
126 flagword flags;
127
128 amt = sizeof core_scnhdr;
129 val = bfd_bread ((PTR) &core_scnhdr, amt, abfd);
130 if (val != sizeof core_scnhdr)
131 break;
132
133 /* Skip empty sections. */
134 if (core_scnhdr.size == 0 || core_scnhdr.scnptr == 0)
135 continue;
136
137 switch (core_scnhdr.scntype)
138 {
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;
155 }
156
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 goto fail;
162 }
163
164 /* OK, we believe you. You're a core file (sure, sure). */
165
166 return abfd->xvec;
167
168 fail:
169 bfd_release (abfd, core_hdr (abfd));
170 core_hdr (abfd) = NULL;
171 bfd_section_list_clear (abfd);
172 return NULL;
173 }
174
175 static char *
176 osf_core_core_file_failing_command (abfd)
177 bfd *abfd;
178 {
179 return core_command (abfd);
180 }
181
182 /* ARGSUSED */
183 static int
184 osf_core_core_file_failing_signal (abfd)
185 bfd *abfd;
186 {
187 return core_signal (abfd);
188 }
189
190 /* ARGSUSED */
191 static boolean
192 osf_core_core_file_matches_executable_p (core_bfd, exec_bfd)
193 bfd *core_bfd ATTRIBUTE_UNUSED;
194 bfd *exec_bfd ATTRIBUTE_UNUSED;
195 {
196 return true; /* FIXME, We have no way of telling at this point */
197 }
198 \f
199 #define osf_core_get_symtab_upper_bound _bfd_nosymbols_get_symtab_upper_bound
200 #define osf_core_get_symtab _bfd_nosymbols_get_symtab
201 #define osf_core_print_symbol _bfd_nosymbols_print_symbol
202 #define osf_core_get_symbol_info _bfd_nosymbols_get_symbol_info
203 #define osf_core_bfd_is_local_label_name _bfd_nosymbols_bfd_is_local_label_name
204 #define osf_core_get_lineno _bfd_nosymbols_get_lineno
205 #define osf_core_find_nearest_line _bfd_nosymbols_find_nearest_line
206 #define osf_core_bfd_make_debug_symbol _bfd_nosymbols_bfd_make_debug_symbol
207 #define osf_core_read_minisymbols _bfd_nosymbols_read_minisymbols
208 #define osf_core_minisymbol_to_symbol _bfd_nosymbols_minisymbol_to_symbol
209
210 /* If somebody calls any byte-swapping routines, shoot them. */
211 static void
212 swap_abort()
213 {
214 abort(); /* This way doesn't require any declaration for ANSI to fuck up */
215 }
216 #define NO_GET ((bfd_vma (*) PARAMS (( const bfd_byte *))) swap_abort )
217 #define NO_PUT ((void (*) PARAMS ((bfd_vma, bfd_byte *))) swap_abort )
218 #define NO_SIGNED_GET \
219 ((bfd_signed_vma (*) PARAMS ((const bfd_byte *))) swap_abort )
220
221 const bfd_target osf_core_vec =
222 {
223 "osf-core",
224 bfd_target_unknown_flavour,
225 BFD_ENDIAN_BIG, /* target byte order */
226 BFD_ENDIAN_BIG, /* target headers byte order */
227 (HAS_RELOC | EXEC_P | /* object flags */
228 HAS_LINENO | HAS_DEBUG |
229 HAS_SYMS | HAS_LOCALS | WP_TEXT | D_PAGED),
230 (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
231 0, /* symbol prefix */
232 ' ', /* ar_pad_char */
233 16, /* ar_max_namelen */
234 NO_GET, NO_SIGNED_GET, NO_PUT, /* 64 bit data */
235 NO_GET, NO_SIGNED_GET, NO_PUT, /* 32 bit data */
236 NO_GET, NO_SIGNED_GET, NO_PUT, /* 16 bit data */
237 NO_GET, NO_SIGNED_GET, NO_PUT, /* 64 bit hdrs */
238 NO_GET, NO_SIGNED_GET, NO_PUT, /* 32 bit hdrs */
239 NO_GET, NO_SIGNED_GET, NO_PUT, /* 16 bit hdrs */
240
241 { /* bfd_check_format */
242 _bfd_dummy_target, /* unknown format */
243 _bfd_dummy_target, /* object file */
244 _bfd_dummy_target, /* archive */
245 osf_core_core_file_p /* a core file */
246 },
247 { /* bfd_set_format */
248 bfd_false, bfd_false,
249 bfd_false, bfd_false
250 },
251 { /* bfd_write_contents */
252 bfd_false, bfd_false,
253 bfd_false, bfd_false
254 },
255
256 BFD_JUMP_TABLE_GENERIC (_bfd_generic),
257 BFD_JUMP_TABLE_COPY (_bfd_generic),
258 BFD_JUMP_TABLE_CORE (osf_core),
259 BFD_JUMP_TABLE_ARCHIVE (_bfd_noarchive),
260 BFD_JUMP_TABLE_SYMBOLS (osf_core),
261 BFD_JUMP_TABLE_RELOCS (_bfd_norelocs),
262 BFD_JUMP_TABLE_WRITE (_bfd_generic),
263 BFD_JUMP_TABLE_LINK (_bfd_nolink),
264 BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),
265
266 NULL,
267
268 (PTR) 0 /* backend_data */
269 };