Use correct email address for Randolph Chung
[deliverable/binutils-gdb.git] / bfd / osf-core.c
CommitLineData
252b5132 1/* BFD back-end for OSF/1 core files.
edeb6e24 2 Copyright 1993, 1994, 1995, 1998, 1999, 2001, 2002, 2003, 2004
dc810e39 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
3e110533 19Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */
252b5132
RH
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>
9b818146 29#ifdef OSF_CORE
252b5132 30#include <sys/core.h>
9b818146 31#endif
252b5132
RH
32
33/* forward declarations */
34
3f3c5c34
AM
35static asection *make_bfd_asection
36 PARAMS ((bfd *, const char *, flagword, bfd_size_type, bfd_vma, file_ptr));
b34976b6
AM
37static const bfd_target *osf_core_core_file_p
38 PARAMS ((bfd *));
39static char *osf_core_core_file_failing_command
40 PARAMS ((bfd *));
41static int osf_core_core_file_failing_signal
42 PARAMS ((bfd *));
43static bfd_boolean osf_core_core_file_matches_executable_p
44 PARAMS ((bfd *, bfd *));
45static void swap_abort
46 PARAMS ((void));
252b5132
RH
47
48/* These are stored in the bfd's tdata */
49
dc810e39 50struct osf_core_struct
252b5132
RH
51{
52 int sig;
53 char cmd[MAXCOMLEN + 1];
54};
55
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)
59
60static asection *
eea6121a 61make_bfd_asection (abfd, name, flags, size, vma, filepos)
252b5132 62 bfd *abfd;
dc810e39 63 const char *name;
252b5132 64 flagword flags;
eea6121a 65 bfd_size_type size;
252b5132
RH
66 bfd_vma vma;
67 file_ptr filepos;
68{
69 asection *asect;
70
71 asect = bfd_make_section_anyway (abfd, name);
72 if (!asect)
73 return NULL;
74
75 asect->flags = flags;
eea6121a 76 asect->size = size;
252b5132
RH
77 asect->vma = vma;
78 asect->filepos = filepos;
79 asect->alignment_power = 8;
80
81 return asect;
82}
83
252b5132
RH
84static const bfd_target *
85osf_core_core_file_p (abfd)
86 bfd *abfd;
87{
88 int val;
89 int i;
90 char *secname;
91 struct core_filehdr core_header;
dc810e39 92 bfd_size_type amt;
252b5132 93
dc810e39
AM
94 amt = sizeof core_header;
95 val = bfd_bread ((PTR) &core_header, amt, abfd);
252b5132
RH
96 if (val != sizeof core_header)
97 return NULL;
98
99 if (strncmp (core_header.magic, "Core", 4) != 0)
100 return NULL;
101
102 core_hdr (abfd) = (struct osf_core_struct *)
dc810e39 103 bfd_zalloc (abfd, (bfd_size_type) sizeof (struct osf_core_struct));
252b5132
RH
104 if (!core_hdr (abfd))
105 return NULL;
106
107 strncpy (core_command (abfd), core_header.name, MAXCOMLEN + 1);
108 core_signal (abfd) = core_header.signo;
109
110 for (i = 0; i < core_header.nscns; i++)
111 {
112 struct core_scnhdr core_scnhdr;
113 flagword flags;
114
dc810e39
AM
115 amt = sizeof core_scnhdr;
116 val = bfd_bread ((PTR) &core_scnhdr, amt, abfd);
252b5132
RH
117 if (val != sizeof core_scnhdr)
118 break;
119
120 /* Skip empty sections. */
121 if (core_scnhdr.size == 0 || core_scnhdr.scnptr == 0)
122 continue;
123
124 switch (core_scnhdr.scntype)
125 {
126 case SCNRGN:
127 secname = ".data";
128 flags = SEC_ALLOC + SEC_LOAD + SEC_HAS_CONTENTS;
129 break;
130 case SCNSTACK:
131 secname = ".stack";
132 flags = SEC_ALLOC + SEC_LOAD + SEC_HAS_CONTENTS;
133 break;
134 case SCNREGS:
135 secname = ".reg";
136 flags = SEC_HAS_CONTENTS;
137 break;
138 default:
139 (*_bfd_error_handler) (_("Unhandled OSF/1 core file section type %d\n"),
140 core_scnhdr.scntype);
141 continue;
142 }
143
144 if (!make_bfd_asection (abfd, secname, flags,
145 (bfd_size_type) core_scnhdr.size,
146 (bfd_vma) core_scnhdr.vaddr,
147 (file_ptr) core_scnhdr.scnptr))
9e7b37b3 148 goto fail;
252b5132
RH
149 }
150
151 /* OK, we believe you. You're a core file (sure, sure). */
152
153 return abfd->xvec;
9e7b37b3
AM
154
155 fail:
156 bfd_release (abfd, core_hdr (abfd));
157 core_hdr (abfd) = NULL;
158 bfd_section_list_clear (abfd);
159 return NULL;
252b5132
RH
160}
161
162static char *
163osf_core_core_file_failing_command (abfd)
164 bfd *abfd;
165{
166 return core_command (abfd);
167}
168
252b5132
RH
169static int
170osf_core_core_file_failing_signal (abfd)
171 bfd *abfd;
172{
173 return core_signal (abfd);
174}
175
b34976b6 176static bfd_boolean
252b5132 177osf_core_core_file_matches_executable_p (core_bfd, exec_bfd)
dc810e39
AM
178 bfd *core_bfd ATTRIBUTE_UNUSED;
179 bfd *exec_bfd ATTRIBUTE_UNUSED;
252b5132 180{
b34976b6 181 return TRUE; /* FIXME, We have no way of telling at this point */
252b5132
RH
182}
183\f
252b5132
RH
184/* If somebody calls any byte-swapping routines, shoot them. */
185static void
186swap_abort()
187{
188 abort(); /* This way doesn't require any declaration for ANSI to fuck up */
189}
8ce8c090 190
edeb6e24
AM
191#define NO_GET ((bfd_vma (*) (const void *)) swap_abort)
192#define NO_PUT ((void (*) (bfd_vma, void *)) swap_abort)
193#define NO_GETS ((bfd_signed_vma (*) (const void *)) swap_abort)
8ce8c090
AM
194#define NO_GET64 ((bfd_uint64_t (*) (const void *)) swap_abort)
195#define NO_PUT64 ((void (*) (bfd_uint64_t, void *)) swap_abort)
196#define NO_GETS64 ((bfd_int64_t (*) (const void *)) swap_abort)
252b5132
RH
197
198const bfd_target osf_core_vec =
199 {
200 "osf-core",
201 bfd_target_unknown_flavour,
a68d41fb
AM
202 BFD_ENDIAN_LITTLE, /* target byte order */
203 BFD_ENDIAN_LITTLE, /* target headers byte order */
252b5132
RH
204 (HAS_RELOC | EXEC_P | /* object flags */
205 HAS_LINENO | HAS_DEBUG |
206 HAS_SYMS | HAS_LOCALS | WP_TEXT | D_PAGED),
207 (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
208 0, /* symbol prefix */
209 ' ', /* ar_pad_char */
210 16, /* ar_max_namelen */
8ce8c090 211 NO_GET64, NO_GETS64, NO_PUT64, /* 64 bit data */
edeb6e24
AM
212 NO_GET, NO_GETS, NO_PUT, /* 32 bit data */
213 NO_GET, NO_GETS, NO_PUT, /* 16 bit data */
8ce8c090 214 NO_GET64, NO_GETS64, NO_PUT64, /* 64 bit hdrs */
edeb6e24
AM
215 NO_GET, NO_GETS, NO_PUT, /* 32 bit hdrs */
216 NO_GET, NO_GETS, NO_PUT, /* 16 bit hdrs */
252b5132
RH
217
218 { /* bfd_check_format */
8ce8c090
AM
219 _bfd_dummy_target, /* unknown format */
220 _bfd_dummy_target, /* object file */
221 _bfd_dummy_target, /* archive */
222 osf_core_core_file_p /* a core file */
252b5132
RH
223 },
224 { /* bfd_set_format */
8ce8c090
AM
225 bfd_false, bfd_false,
226 bfd_false, bfd_false
252b5132
RH
227 },
228 { /* bfd_write_contents */
8ce8c090
AM
229 bfd_false, bfd_false,
230 bfd_false, bfd_false
252b5132 231 },
dc810e39 232
3f3c5c34
AM
233 BFD_JUMP_TABLE_GENERIC (_bfd_generic),
234 BFD_JUMP_TABLE_COPY (_bfd_generic),
235 BFD_JUMP_TABLE_CORE (osf_core),
236 BFD_JUMP_TABLE_ARCHIVE (_bfd_noarchive),
237 BFD_JUMP_TABLE_SYMBOLS (_bfd_nosymbols),
238 BFD_JUMP_TABLE_RELOCS (_bfd_norelocs),
239 BFD_JUMP_TABLE_WRITE (_bfd_generic),
240 BFD_JUMP_TABLE_LINK (_bfd_nolink),
241 BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),
252b5132 242
c3c89269 243 NULL,
dc810e39 244
252b5132 245 (PTR) 0 /* backend_data */
8ce8c090 246 };
This page took 0.346018 seconds and 4 git commands to generate.