Touches most files in bfd/, so likely will be blamed for everything..
[deliverable/binutils-gdb.git] / bfd / osf-core.c
CommitLineData
252b5132 1/* BFD back-end for OSF/1 core files.
dc810e39
AM
2 Copyright 1993, 1994, 1995, 1998, 1999, 2001
3 Free Software Foundation, Inc.
252b5132
RH
4
5This file is part of BFD, the Binary File Descriptor library.
6
7This program is free software; you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
9the Free Software Foundation; either version 2 of the License, or
10(at your option) any later version.
11
12This program is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with this program; if not, write to the Free Software
19Foundation, 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
33static asection *
dc810e39 34make_bfd_asection PARAMS ((bfd *, const char *, flagword, bfd_size_type,
252b5132
RH
35 bfd_vma, file_ptr));
36static asymbol *
37osf_core_make_empty_symbol PARAMS ((bfd *));
38static const bfd_target *
39osf_core_core_file_p PARAMS ((bfd *));
40static char *
41osf_core_core_file_failing_command PARAMS ((bfd *));
42static int
43osf_core_core_file_failing_signal PARAMS ((bfd *));
44static boolean
45osf_core_core_file_matches_executable_p PARAMS ((bfd *, bfd *));
46static void
47swap_abort PARAMS ((void));
48
49/* These are stored in the bfd's tdata */
50
dc810e39 51struct osf_core_struct
252b5132
RH
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
61static asection *
62make_bfd_asection (abfd, name, flags, _raw_size, vma, filepos)
63 bfd *abfd;
dc810e39 64 const char *name;
252b5132
RH
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
85static asymbol *
86osf_core_make_empty_symbol (abfd)
87 bfd *abfd;
88{
dc810e39
AM
89 asymbol *new;
90
91 new = (asymbol *) bfd_zalloc (abfd, (bfd_size_type) sizeof (asymbol));
252b5132
RH
92 if (new)
93 new->the_bfd = abfd;
94 return new;
95}
96
97static const bfd_target *
98osf_core_core_file_p (abfd)
99 bfd *abfd;
100{
101 int val;
102 int i;
103 char *secname;
104 struct core_filehdr core_header;
dc810e39 105 bfd_size_type amt;
252b5132 106
dc810e39
AM
107 amt = sizeof core_header;
108 val = bfd_bread ((PTR) &core_header, amt, abfd);
252b5132
RH
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 *)
dc810e39 116 bfd_zalloc (abfd, (bfd_size_type) sizeof (struct osf_core_struct));
252b5132
RH
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
dc810e39
AM
128 amt = sizeof core_scnhdr;
129 val = bfd_bread ((PTR) &core_scnhdr, amt, abfd);
252b5132
RH
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 return NULL;
162 }
163
164 /* OK, we believe you. You're a core file (sure, sure). */
165
166 return abfd->xvec;
167}
168
169static char *
170osf_core_core_file_failing_command (abfd)
171 bfd *abfd;
172{
173 return core_command (abfd);
174}
175
176/* ARGSUSED */
177static int
178osf_core_core_file_failing_signal (abfd)
179 bfd *abfd;
180{
181 return core_signal (abfd);
182}
183
184/* ARGSUSED */
185static boolean
186osf_core_core_file_matches_executable_p (core_bfd, exec_bfd)
dc810e39
AM
187 bfd *core_bfd ATTRIBUTE_UNUSED;
188 bfd *exec_bfd ATTRIBUTE_UNUSED;
252b5132
RH
189{
190 return true; /* FIXME, We have no way of telling at this point */
191}
192\f
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
203
204/* If somebody calls any byte-swapping routines, shoot them. */
205static void
206swap_abort()
207{
208 abort(); /* This way doesn't require any declaration for ANSI to fuck up */
209}
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 )
214
215const bfd_target osf_core_vec =
216 {
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 */
234
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 */
240 },
241 { /* bfd_set_format */
242 bfd_false, bfd_false,
243 bfd_false, bfd_false
244 },
245 { /* bfd_write_contents */
246 bfd_false, bfd_false,
247 bfd_false, bfd_false
248 },
dc810e39 249
252b5132
RH
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),
259
c3c89269 260 NULL,
dc810e39 261
252b5132
RH
262 (PTR) 0 /* backend_data */
263};
This page took 0.18637 seconds and 4 git commands to generate.