PR c++/15176:
[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,
2c3fc389 3 2007, 2010, 2011, 2012 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
69d246d9 37#define osf_core_core_file_matches_executable_p generic_core_file_matches_executable_p
261b8d08 38#define osf_core_core_file_pid _bfd_nocore_core_file_pid
252b5132
RH
39
40/* These are stored in the bfd's tdata */
41
dc810e39 42struct osf_core_struct
252b5132
RH
43{
44 int sig;
45 char cmd[MAXCOMLEN + 1];
46};
47
48#define core_hdr(bfd) ((bfd)->tdata.osf_core_data)
2c3fc389 49#define core_signal(bfd) (core_hdr(bfd)->sig)
252b5132
RH
50#define core_command(bfd) (core_hdr(bfd)->cmd)
51
52static asection *
2c3fc389
NC
53make_bfd_asection (bfd *abfd,
54 const char *name,
55 flagword flags,
56 bfd_size_type size,
57 bfd_vma vma,
58 file_ptr filepos)
252b5132
RH
59{
60 asection *asect;
61
117ed4f8 62 asect = bfd_make_section_anyway_with_flags (abfd, name, flags);
252b5132
RH
63 if (!asect)
64 return NULL;
65
eea6121a 66 asect->size = size;
252b5132
RH
67 asect->vma = vma;
68 asect->filepos = filepos;
69 asect->alignment_power = 8;
70
71 return asect;
72}
73
252b5132 74static const bfd_target *
2c3fc389 75osf_core_core_file_p (bfd *abfd)
252b5132
RH
76{
77 int val;
78 int i;
79 char *secname;
80 struct core_filehdr core_header;
dc810e39 81 bfd_size_type amt;
252b5132 82
dc810e39 83 amt = sizeof core_header;
2c3fc389 84 val = bfd_bread (& core_header, amt, abfd);
252b5132
RH
85 if (val != sizeof core_header)
86 return NULL;
87
0112cd26 88 if (! CONST_STRNEQ (core_header.magic, "Core"))
252b5132
RH
89 return NULL;
90
91 core_hdr (abfd) = (struct osf_core_struct *)
dc810e39 92 bfd_zalloc (abfd, (bfd_size_type) sizeof (struct osf_core_struct));
252b5132
RH
93 if (!core_hdr (abfd))
94 return NULL;
95
96 strncpy (core_command (abfd), core_header.name, MAXCOMLEN + 1);
97 core_signal (abfd) = core_header.signo;
98
99 for (i = 0; i < core_header.nscns; i++)
100 {
101 struct core_scnhdr core_scnhdr;
102 flagword flags;
103
dc810e39 104 amt = sizeof core_scnhdr;
2c3fc389 105 val = bfd_bread (& core_scnhdr, amt, abfd);
252b5132
RH
106 if (val != sizeof core_scnhdr)
107 break;
108
109 /* Skip empty sections. */
110 if (core_scnhdr.size == 0 || core_scnhdr.scnptr == 0)
111 continue;
112
113 switch (core_scnhdr.scntype)
114 {
115 case SCNRGN:
116 secname = ".data";
117 flags = SEC_ALLOC + SEC_LOAD + SEC_HAS_CONTENTS;
118 break;
119 case SCNSTACK:
120 secname = ".stack";
121 flags = SEC_ALLOC + SEC_LOAD + SEC_HAS_CONTENTS;
122 break;
123 case SCNREGS:
124 secname = ".reg";
125 flags = SEC_HAS_CONTENTS;
126 break;
127 default:
128 (*_bfd_error_handler) (_("Unhandled OSF/1 core file section type %d\n"),
129 core_scnhdr.scntype);
130 continue;
131 }
132
133 if (!make_bfd_asection (abfd, secname, flags,
134 (bfd_size_type) core_scnhdr.size,
135 (bfd_vma) core_scnhdr.vaddr,
136 (file_ptr) core_scnhdr.scnptr))
9e7b37b3 137 goto fail;
252b5132
RH
138 }
139
140 /* OK, we believe you. You're a core file (sure, sure). */
141
142 return abfd->xvec;
9e7b37b3
AM
143
144 fail:
145 bfd_release (abfd, core_hdr (abfd));
146 core_hdr (abfd) = NULL;
147 bfd_section_list_clear (abfd);
148 return NULL;
252b5132
RH
149}
150
151static char *
2c3fc389 152osf_core_core_file_failing_command (bfd *abfd)
252b5132
RH
153{
154 return core_command (abfd);
155}
156
252b5132 157static int
2c3fc389 158osf_core_core_file_failing_signal (bfd *abfd)
252b5132
RH
159{
160 return core_signal (abfd);
161}
252b5132 162\f
252b5132
RH
163/* If somebody calls any byte-swapping routines, shoot them. */
164static void
2c3fc389 165swap_abort (void)
252b5132 166{
2c3fc389 167 abort (); /* This way doesn't require any declaration for ANSI to fuck up */
252b5132 168}
8ce8c090 169
edeb6e24
AM
170#define NO_GET ((bfd_vma (*) (const void *)) swap_abort)
171#define NO_PUT ((void (*) (bfd_vma, void *)) swap_abort)
172#define NO_GETS ((bfd_signed_vma (*) (const void *)) swap_abort)
8ce8c090
AM
173#define NO_GET64 ((bfd_uint64_t (*) (const void *)) swap_abort)
174#define NO_PUT64 ((void (*) (bfd_uint64_t, void *)) swap_abort)
175#define NO_GETS64 ((bfd_int64_t (*) (const void *)) swap_abort)
252b5132
RH
176
177const bfd_target osf_core_vec =
178 {
179 "osf-core",
180 bfd_target_unknown_flavour,
a68d41fb
AM
181 BFD_ENDIAN_LITTLE, /* target byte order */
182 BFD_ENDIAN_LITTLE, /* target headers byte order */
252b5132
RH
183 (HAS_RELOC | EXEC_P | /* object flags */
184 HAS_LINENO | HAS_DEBUG |
185 HAS_SYMS | HAS_LOCALS | WP_TEXT | D_PAGED),
186 (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
d3aeb6ee
AM
187 0, /* symbol prefix */
188 ' ', /* ar_pad_char */
189 16, /* ar_max_namelen */
190 0, /* match priority. */
8ce8c090 191 NO_GET64, NO_GETS64, NO_PUT64, /* 64 bit data */
edeb6e24
AM
192 NO_GET, NO_GETS, NO_PUT, /* 32 bit data */
193 NO_GET, NO_GETS, NO_PUT, /* 16 bit data */
8ce8c090 194 NO_GET64, NO_GETS64, NO_PUT64, /* 64 bit hdrs */
edeb6e24
AM
195 NO_GET, NO_GETS, NO_PUT, /* 32 bit hdrs */
196 NO_GET, NO_GETS, NO_PUT, /* 16 bit hdrs */
252b5132
RH
197
198 { /* bfd_check_format */
8ce8c090
AM
199 _bfd_dummy_target, /* unknown format */
200 _bfd_dummy_target, /* object file */
201 _bfd_dummy_target, /* archive */
202 osf_core_core_file_p /* a core file */
252b5132
RH
203 },
204 { /* bfd_set_format */
8ce8c090
AM
205 bfd_false, bfd_false,
206 bfd_false, bfd_false
252b5132
RH
207 },
208 { /* bfd_write_contents */
8ce8c090
AM
209 bfd_false, bfd_false,
210 bfd_false, bfd_false
252b5132 211 },
dc810e39 212
3f3c5c34
AM
213 BFD_JUMP_TABLE_GENERIC (_bfd_generic),
214 BFD_JUMP_TABLE_COPY (_bfd_generic),
215 BFD_JUMP_TABLE_CORE (osf_core),
216 BFD_JUMP_TABLE_ARCHIVE (_bfd_noarchive),
217 BFD_JUMP_TABLE_SYMBOLS (_bfd_nosymbols),
218 BFD_JUMP_TABLE_RELOCS (_bfd_norelocs),
219 BFD_JUMP_TABLE_WRITE (_bfd_generic),
220 BFD_JUMP_TABLE_LINK (_bfd_nolink),
221 BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),
252b5132 222
c3c89269 223 NULL,
dc810e39 224
2c3fc389 225 NULL /* backend_data */
8ce8c090 226 };
This page took 0.700053 seconds and 4 git commands to generate.