| 1 | /* BFD back-end for OSF/1 core files.
|
|---|
| 2 | Copyright 1993, 1994, 1995, 1998, 1999 Free Software Foundation, Inc.
|
|---|
| 3 |
|
|---|
| 4 | This file is part of BFD, the Binary File Descriptor library.
|
|---|
| 5 |
|
|---|
| 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 2 of the License, or
|
|---|
| 9 | (at your option) any later version.
|
|---|
| 10 |
|
|---|
| 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.
|
|---|
| 15 |
|
|---|
| 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
|
|---|
| 19 |
|
|---|
| 20 | /* This file can only be compiled on systems which use OSF/1 style
|
|---|
| 21 | core files. */
|
|---|
| 22 |
|
|---|
| 23 | #include "bfd.h"
|
|---|
| 24 | #include "sysdep.h"
|
|---|
| 25 | #include "libbfd.h"
|
|---|
| 26 |
|
|---|
| 27 | #include <sys/user.h>
|
|---|
| 28 | #include <sys/core.h>
|
|---|
| 29 |
|
|---|
| 30 | /* forward declarations */
|
|---|
| 31 |
|
|---|
| 32 | static asection *
|
|---|
| 33 | make_bfd_asection PARAMS ((bfd *, CONST char *, flagword, bfd_size_type,
|
|---|
| 34 | bfd_vma, file_ptr));
|
|---|
| 35 | static asymbol *
|
|---|
| 36 | osf_core_make_empty_symbol PARAMS ((bfd *));
|
|---|
| 37 | static const bfd_target *
|
|---|
| 38 | osf_core_core_file_p PARAMS ((bfd *));
|
|---|
| 39 | static char *
|
|---|
| 40 | osf_core_core_file_failing_command PARAMS ((bfd *));
|
|---|
| 41 | static int
|
|---|
| 42 | osf_core_core_file_failing_signal PARAMS ((bfd *));
|
|---|
| 43 | static boolean
|
|---|
| 44 | osf_core_core_file_matches_executable_p PARAMS ((bfd *, bfd *));
|
|---|
| 45 | static void
|
|---|
| 46 | swap_abort PARAMS ((void));
|
|---|
| 47 |
|
|---|
| 48 | /* These are stored in the bfd's tdata */
|
|---|
| 49 |
|
|---|
| 50 | struct osf_core_struct
|
|---|
| 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 |
|
|---|
| 60 | static asection *
|
|---|
| 61 | make_bfd_asection (abfd, name, flags, _raw_size, vma, filepos)
|
|---|
| 62 | bfd *abfd;
|
|---|
| 63 | CONST char *name;
|
|---|
| 64 | flagword flags;
|
|---|
| 65 | bfd_size_type _raw_size;
|
|---|
| 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;
|
|---|
| 76 | asect->_raw_size = _raw_size;
|
|---|
| 77 | asect->vma = vma;
|
|---|
| 78 | asect->filepos = filepos;
|
|---|
| 79 | asect->alignment_power = 8;
|
|---|
| 80 |
|
|---|
| 81 | return asect;
|
|---|
| 82 | }
|
|---|
| 83 |
|
|---|
| 84 | static asymbol *
|
|---|
| 85 | osf_core_make_empty_symbol (abfd)
|
|---|
| 86 | bfd *abfd;
|
|---|
| 87 | {
|
|---|
| 88 | asymbol *new = (asymbol *) bfd_zalloc (abfd, sizeof (asymbol));
|
|---|
| 89 | if (new)
|
|---|
| 90 | new->the_bfd = abfd;
|
|---|
| 91 | return new;
|
|---|
| 92 | }
|
|---|
| 93 |
|
|---|
| 94 | static const bfd_target *
|
|---|
| 95 | osf_core_core_file_p (abfd)
|
|---|
| 96 | bfd *abfd;
|
|---|
| 97 | {
|
|---|
| 98 | int val;
|
|---|
| 99 | int i;
|
|---|
| 100 | char *secname;
|
|---|
| 101 | struct core_filehdr core_header;
|
|---|
| 102 |
|
|---|
| 103 | val = bfd_read ((PTR)&core_header, 1, sizeof core_header, abfd);
|
|---|
| 104 | if (val != sizeof core_header)
|
|---|
| 105 | return NULL;
|
|---|
| 106 |
|
|---|
| 107 | if (strncmp (core_header.magic, "Core", 4) != 0)
|
|---|
| 108 | return NULL;
|
|---|
| 109 |
|
|---|
| 110 | core_hdr (abfd) = (struct osf_core_struct *)
|
|---|
| 111 | bfd_zalloc (abfd, sizeof (struct osf_core_struct));
|
|---|
| 112 | if (!core_hdr (abfd))
|
|---|
| 113 | return NULL;
|
|---|
| 114 |
|
|---|
| 115 | strncpy (core_command (abfd), core_header.name, MAXCOMLEN + 1);
|
|---|
| 116 | core_signal (abfd) = core_header.signo;
|
|---|
| 117 |
|
|---|
| 118 | for (i = 0; i < core_header.nscns; i++)
|
|---|
| 119 | {
|
|---|
| 120 | struct core_scnhdr core_scnhdr;
|
|---|
| 121 | flagword flags;
|
|---|
| 122 |
|
|---|
| 123 | val = bfd_read ((PTR)&core_scnhdr, 1, sizeof core_scnhdr, abfd);
|
|---|
| 124 | if (val != sizeof core_scnhdr)
|
|---|
| 125 | break;
|
|---|
| 126 |
|
|---|
| 127 | /* Skip empty sections. */
|
|---|
| 128 | if (core_scnhdr.size == 0 || core_scnhdr.scnptr == 0)
|
|---|
| 129 | continue;
|
|---|
| 130 |
|
|---|
| 131 | switch (core_scnhdr.scntype)
|
|---|
| 132 | {
|
|---|
| 133 | case SCNRGN:
|
|---|
| 134 | secname = ".data";
|
|---|
| 135 | flags = SEC_ALLOC + SEC_LOAD + SEC_HAS_CONTENTS;
|
|---|
| 136 | break;
|
|---|
| 137 | case SCNSTACK:
|
|---|
| 138 | secname = ".stack";
|
|---|
| 139 | flags = SEC_ALLOC + SEC_LOAD + SEC_HAS_CONTENTS;
|
|---|
| 140 | break;
|
|---|
| 141 | case SCNREGS:
|
|---|
| 142 | secname = ".reg";
|
|---|
| 143 | flags = SEC_HAS_CONTENTS;
|
|---|
| 144 | break;
|
|---|
| 145 | default:
|
|---|
| 146 | (*_bfd_error_handler) (_("Unhandled OSF/1 core file section type %d\n"),
|
|---|
| 147 | core_scnhdr.scntype);
|
|---|
| 148 | continue;
|
|---|
| 149 | }
|
|---|
| 150 |
|
|---|
| 151 | if (!make_bfd_asection (abfd, secname, flags,
|
|---|
| 152 | (bfd_size_type) core_scnhdr.size,
|
|---|
| 153 | (bfd_vma) core_scnhdr.vaddr,
|
|---|
| 154 | (file_ptr) core_scnhdr.scnptr))
|
|---|
| 155 | return NULL;
|
|---|
| 156 | }
|
|---|
| 157 |
|
|---|
| 158 | /* OK, we believe you. You're a core file (sure, sure). */
|
|---|
| 159 |
|
|---|
| 160 | return abfd->xvec;
|
|---|
| 161 | }
|
|---|
| 162 |
|
|---|
| 163 | static char *
|
|---|
| 164 | osf_core_core_file_failing_command (abfd)
|
|---|
| 165 | bfd *abfd;
|
|---|
| 166 | {
|
|---|
| 167 | return core_command (abfd);
|
|---|
| 168 | }
|
|---|
| 169 |
|
|---|
| 170 | /* ARGSUSED */
|
|---|
| 171 | static int
|
|---|
| 172 | osf_core_core_file_failing_signal (abfd)
|
|---|
| 173 | bfd *abfd;
|
|---|
| 174 | {
|
|---|
| 175 | return core_signal (abfd);
|
|---|
| 176 | }
|
|---|
| 177 |
|
|---|
| 178 | /* ARGSUSED */
|
|---|
| 179 | static boolean
|
|---|
| 180 | osf_core_core_file_matches_executable_p (core_bfd, exec_bfd)
|
|---|
| 181 | bfd *core_bfd, *exec_bfd;
|
|---|
| 182 | {
|
|---|
| 183 | return true; /* FIXME, We have no way of telling at this point */
|
|---|
| 184 | }
|
|---|
| 185 | |
|---|
| 186 |
|
|---|
| 187 | #define osf_core_get_symtab_upper_bound _bfd_nosymbols_get_symtab_upper_bound
|
|---|
| 188 | #define osf_core_get_symtab _bfd_nosymbols_get_symtab
|
|---|
| 189 | #define osf_core_print_symbol _bfd_nosymbols_print_symbol
|
|---|
| 190 | #define osf_core_get_symbol_info _bfd_nosymbols_get_symbol_info
|
|---|
| 191 | #define osf_core_bfd_is_local_label_name _bfd_nosymbols_bfd_is_local_label_name
|
|---|
| 192 | #define osf_core_get_lineno _bfd_nosymbols_get_lineno
|
|---|
| 193 | #define osf_core_find_nearest_line _bfd_nosymbols_find_nearest_line
|
|---|
| 194 | #define osf_core_bfd_make_debug_symbol _bfd_nosymbols_bfd_make_debug_symbol
|
|---|
| 195 | #define osf_core_read_minisymbols _bfd_nosymbols_read_minisymbols
|
|---|
| 196 | #define osf_core_minisymbol_to_symbol _bfd_nosymbols_minisymbol_to_symbol
|
|---|
| 197 |
|
|---|
| 198 | /* If somebody calls any byte-swapping routines, shoot them. */
|
|---|
| 199 | static void
|
|---|
| 200 | swap_abort()
|
|---|
| 201 | {
|
|---|
| 202 | abort(); /* This way doesn't require any declaration for ANSI to fuck up */
|
|---|
| 203 | }
|
|---|
| 204 | #define NO_GET ((bfd_vma (*) PARAMS (( const bfd_byte *))) swap_abort )
|
|---|
| 205 | #define NO_PUT ((void (*) PARAMS ((bfd_vma, bfd_byte *))) swap_abort )
|
|---|
| 206 | #define NO_SIGNED_GET \
|
|---|
| 207 | ((bfd_signed_vma (*) PARAMS ((const bfd_byte *))) swap_abort )
|
|---|
| 208 |
|
|---|
| 209 | const bfd_target osf_core_vec =
|
|---|
| 210 | {
|
|---|
| 211 | "osf-core",
|
|---|
| 212 | bfd_target_unknown_flavour,
|
|---|
| 213 | BFD_ENDIAN_BIG, /* target byte order */
|
|---|
| 214 | BFD_ENDIAN_BIG, /* target headers byte order */
|
|---|
| 215 | (HAS_RELOC | EXEC_P | /* object flags */
|
|---|
| 216 | HAS_LINENO | HAS_DEBUG |
|
|---|
| 217 | HAS_SYMS | HAS_LOCALS | WP_TEXT | D_PAGED),
|
|---|
| 218 | (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
|
|---|
| 219 | 0, /* symbol prefix */
|
|---|
| 220 | ' ', /* ar_pad_char */
|
|---|
| 221 | 16, /* ar_max_namelen */
|
|---|
| 222 | NO_GET, NO_SIGNED_GET, NO_PUT, /* 64 bit data */
|
|---|
| 223 | NO_GET, NO_SIGNED_GET, NO_PUT, /* 32 bit data */
|
|---|
| 224 | NO_GET, NO_SIGNED_GET, NO_PUT, /* 16 bit data */
|
|---|
| 225 | NO_GET, NO_SIGNED_GET, NO_PUT, /* 64 bit hdrs */
|
|---|
| 226 | NO_GET, NO_SIGNED_GET, NO_PUT, /* 32 bit hdrs */
|
|---|
| 227 | NO_GET, NO_SIGNED_GET, NO_PUT, /* 16 bit hdrs */
|
|---|
| 228 |
|
|---|
| 229 | { /* bfd_check_format */
|
|---|
| 230 | _bfd_dummy_target, /* unknown format */
|
|---|
| 231 | _bfd_dummy_target, /* object file */
|
|---|
| 232 | _bfd_dummy_target, /* archive */
|
|---|
| 233 | osf_core_core_file_p /* a core file */
|
|---|
| 234 | },
|
|---|
| 235 | { /* bfd_set_format */
|
|---|
| 236 | bfd_false, bfd_false,
|
|---|
| 237 | bfd_false, bfd_false
|
|---|
| 238 | },
|
|---|
| 239 | { /* bfd_write_contents */
|
|---|
| 240 | bfd_false, bfd_false,
|
|---|
| 241 | bfd_false, bfd_false
|
|---|
| 242 | },
|
|---|
| 243 |
|
|---|
| 244 | BFD_JUMP_TABLE_GENERIC (_bfd_generic),
|
|---|
| 245 | BFD_JUMP_TABLE_COPY (_bfd_generic),
|
|---|
| 246 | BFD_JUMP_TABLE_CORE (osf_core),
|
|---|
| 247 | BFD_JUMP_TABLE_ARCHIVE (_bfd_noarchive),
|
|---|
| 248 | BFD_JUMP_TABLE_SYMBOLS (osf_core),
|
|---|
| 249 | BFD_JUMP_TABLE_RELOCS (_bfd_norelocs),
|
|---|
| 250 | BFD_JUMP_TABLE_WRITE (_bfd_generic),
|
|---|
| 251 | BFD_JUMP_TABLE_LINK (_bfd_nolink),
|
|---|
| 252 | BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),
|
|---|
| 253 |
|
|---|
| 254 | NULL,
|
|---|
| 255 |
|
|---|
| 256 | (PTR) 0 /* backend_data */
|
|---|
| 257 | };
|
|---|