gdb/testsuite: make gdb.reverse/i386-avx-reverse.exp require avx
[binutils-gdb.git] / bfd / osf-core.c
blob6869dfa23eadff8a745a073cd1263b0367e772f2
1 /* BFD back-end for OSF/1 core files.
2 Copyright (C) 1993-2024 Free Software Foundation, Inc.
4 This file is part of BFD, the Binary File Descriptor library.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
19 MA 02110-1301, USA. */
22 /* This file can only be compiled on systems which use OSF/1 style
23 core files. */
25 #include "sysdep.h"
26 #include "bfd.h"
27 #include "libbfd.h"
29 #include <sys/user.h>
30 #ifdef OSF_CORE
31 #include <sys/core.h>
32 #endif
34 /* forward declarations */
36 #define osf_core_core_file_matches_executable_p generic_core_file_matches_executable_p
37 #define osf_core_core_file_pid _bfd_nocore_core_file_pid
39 /* These are stored in the bfd's tdata */
41 struct osf_core_struct
43 int sig;
44 char cmd[MAXCOMLEN + 1];
47 #define core_hdr(bfd) ((bfd)->tdata.osf_core_data)
48 #define core_signal(bfd) (core_hdr(bfd)->sig)
49 #define core_command(bfd) (core_hdr(bfd)->cmd)
51 static asection *
52 make_bfd_asection (bfd *abfd,
53 const char *name,
54 flagword flags,
55 bfd_size_type size,
56 bfd_vma vma,
57 file_ptr filepos)
59 asection *asect;
61 asect = bfd_make_section_anyway_with_flags (abfd, name, flags);
62 if (!asect)
63 return NULL;
65 asect->size = size;
66 asect->vma = vma;
67 asect->filepos = filepos;
68 asect->alignment_power = 8;
70 return asect;
73 static bfd_cleanup
74 osf_core_core_file_p (bfd *abfd)
76 int val;
77 int i;
78 char *secname;
79 struct core_filehdr core_header;
80 size_t amt;
82 amt = sizeof core_header;
83 val = bfd_read (& core_header, amt, abfd);
84 if (val != sizeof core_header)
85 return NULL;
87 if (! startswith (core_header.magic, "Core"))
88 return NULL;
90 core_hdr (abfd) = (struct osf_core_struct *)
91 bfd_zalloc (abfd, (bfd_size_type) sizeof (struct osf_core_struct));
92 if (!core_hdr (abfd))
93 return NULL;
95 strncpy (core_command (abfd), core_header.name, MAXCOMLEN);
96 core_command (abfd)[MAXCOMLEN] = 0;
97 core_signal (abfd) = core_header.signo;
99 for (i = 0; i < core_header.nscns; i++)
101 struct core_scnhdr core_scnhdr;
102 flagword flags;
104 amt = sizeof core_scnhdr;
105 val = bfd_read (& core_scnhdr, amt, abfd);
106 if (val != sizeof core_scnhdr)
107 break;
109 /* Skip empty sections. */
110 if (core_scnhdr.size == 0 || core_scnhdr.scnptr == 0)
111 continue;
113 switch (core_scnhdr.scntype)
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"),
129 core_scnhdr.scntype);
130 continue;
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))
137 goto fail;
140 /* OK, we believe you. You're a core file (sure, sure). */
142 return _bfd_no_cleanup;
144 fail:
145 bfd_release (abfd, core_hdr (abfd));
146 core_hdr (abfd) = NULL;
147 bfd_section_list_clear (abfd);
148 return NULL;
151 static char *
152 osf_core_core_file_failing_command (bfd *abfd)
154 return core_command (abfd);
157 static int
158 osf_core_core_file_failing_signal (bfd *abfd)
160 return core_signal (abfd);
163 /* If somebody calls any byte-swapping routines, shoot them. */
164 static void
165 swap_abort (void)
167 abort (); /* This way doesn't require any declaration for ANSI to fuck up */
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)
173 #define NO_GET64 ((uint64_t (*) (const void *)) swap_abort)
174 #define NO_PUT64 ((void (*) (uint64_t, void *)) swap_abort)
175 #define NO_GETS64 ((int64_t (*) (const void *)) swap_abort)
177 const bfd_target core_osf_vec =
179 "osf-core",
180 bfd_target_unknown_flavour,
181 BFD_ENDIAN_LITTLE, /* target byte order */
182 BFD_ENDIAN_LITTLE, /* target headers byte order */
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 */
187 0, /* symbol prefix */
188 ' ', /* ar_pad_char */
189 16, /* ar_max_namelen */
190 0, /* match priority. */
191 TARGET_KEEP_UNUSED_SECTION_SYMBOLS, /* keep unused section symbols. */
192 NO_GET64, NO_GETS64, NO_PUT64, /* 64 bit data */
193 NO_GET, NO_GETS, NO_PUT, /* 32 bit data */
194 NO_GET, NO_GETS, NO_PUT, /* 16 bit data */
195 NO_GET64, NO_GETS64, NO_PUT64, /* 64 bit hdrs */
196 NO_GET, NO_GETS, NO_PUT, /* 32 bit hdrs */
197 NO_GET, NO_GETS, NO_PUT, /* 16 bit hdrs */
199 { /* bfd_check_format */
200 _bfd_dummy_target, /* unknown format */
201 _bfd_dummy_target, /* object file */
202 _bfd_dummy_target, /* archive */
203 osf_core_core_file_p /* a core file */
205 { /* bfd_set_format */
206 _bfd_bool_bfd_false_error,
207 _bfd_bool_bfd_false_error,
208 _bfd_bool_bfd_false_error,
209 _bfd_bool_bfd_false_error
211 { /* bfd_write_contents */
212 _bfd_bool_bfd_false_error,
213 _bfd_bool_bfd_false_error,
214 _bfd_bool_bfd_false_error,
215 _bfd_bool_bfd_false_error
218 BFD_JUMP_TABLE_GENERIC (_bfd_generic),
219 BFD_JUMP_TABLE_COPY (_bfd_generic),
220 BFD_JUMP_TABLE_CORE (osf_core),
221 BFD_JUMP_TABLE_ARCHIVE (_bfd_noarchive),
222 BFD_JUMP_TABLE_SYMBOLS (_bfd_nosymbols),
223 BFD_JUMP_TABLE_RELOCS (_bfd_norelocs),
224 BFD_JUMP_TABLE_WRITE (_bfd_generic),
225 BFD_JUMP_TABLE_LINK (_bfd_nolink),
226 BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),
228 NULL,
230 NULL /* backend_data */