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