Back to index

cell-binutils  2.17cvs20070401
osf-core.c
Go to the documentation of this file.
00001 /* BFD back-end for OSF/1 core files.
00002    Copyright 1993, 1994, 1995, 1998, 1999, 2001, 2002, 2003, 2004, 2006
00003    Free Software Foundation, Inc.
00004 
00005 This file is part of BFD, the Binary File Descriptor library.
00006 
00007 This program is free software; you can redistribute it and/or modify
00008 it under the terms of the GNU General Public License as published by
00009 the Free Software Foundation; either version 2 of the License, or
00010 (at your option) any later version.
00011 
00012 This program is distributed in the hope that it will be useful,
00013 but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015 GNU General Public License for more details.
00016 
00017 You should have received a copy of the GNU General Public License
00018 along with this program; if not, write to the Free Software
00019 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.  */
00020 
00021 /* This file can only be compiled on systems which use OSF/1 style
00022    core files.  */
00023 
00024 #include "bfd.h"
00025 #include "sysdep.h"
00026 #include "libbfd.h"
00027 
00028 #include <sys/user.h>
00029 #ifdef OSF_CORE
00030 #include <sys/core.h>
00031 #endif
00032 
00033 /* forward declarations */
00034 
00035 static asection *make_bfd_asection
00036   PARAMS ((bfd *, const char *, flagword, bfd_size_type, bfd_vma, file_ptr));
00037 static const bfd_target *osf_core_core_file_p
00038   PARAMS ((bfd *));
00039 static char *osf_core_core_file_failing_command
00040   PARAMS ((bfd *));
00041 static int osf_core_core_file_failing_signal
00042   PARAMS ((bfd *));
00043 #define osf_core_core_file_matches_executable_p generic_core_file_matches_executable_p
00044 static void swap_abort
00045   PARAMS ((void));
00046 
00047 /* These are stored in the bfd's tdata */
00048 
00049 struct osf_core_struct
00050 {
00051   int sig;
00052   char cmd[MAXCOMLEN + 1];
00053 };
00054 
00055 #define core_hdr(bfd) ((bfd)->tdata.osf_core_data)
00056 #define core_signal(bfd) (core_hdr(bfd)->sig)
00057 #define core_command(bfd) (core_hdr(bfd)->cmd)
00058 
00059 static asection *
00060 make_bfd_asection (abfd, name, flags, size, vma, filepos)
00061      bfd *abfd;
00062      const char *name;
00063      flagword flags;
00064      bfd_size_type size;
00065      bfd_vma vma;
00066      file_ptr filepos;
00067 {
00068   asection *asect;
00069 
00070   asect = bfd_make_section_anyway_with_flags (abfd, name, flags);
00071   if (!asect)
00072     return NULL;
00073 
00074   asect->size = size;
00075   asect->vma = vma;
00076   asect->filepos = filepos;
00077   asect->alignment_power = 8;
00078 
00079   return asect;
00080 }
00081 
00082 static const bfd_target *
00083 osf_core_core_file_p (abfd)
00084      bfd *abfd;
00085 {
00086   int val;
00087   int i;
00088   char *secname;
00089   struct core_filehdr core_header;
00090   bfd_size_type amt;
00091 
00092   amt = sizeof core_header;
00093   val = bfd_bread ((PTR) &core_header, amt, abfd);
00094   if (val != sizeof core_header)
00095     return NULL;
00096 
00097   if (! CONST_STRNEQ (core_header.magic, "Core"))
00098     return NULL;
00099 
00100   core_hdr (abfd) = (struct osf_core_struct *)
00101     bfd_zalloc (abfd, (bfd_size_type) sizeof (struct osf_core_struct));
00102   if (!core_hdr (abfd))
00103     return NULL;
00104 
00105   strncpy (core_command (abfd), core_header.name, MAXCOMLEN + 1);
00106   core_signal (abfd) = core_header.signo;
00107 
00108   for (i = 0; i < core_header.nscns; i++)
00109     {
00110       struct core_scnhdr core_scnhdr;
00111       flagword flags;
00112 
00113       amt = sizeof core_scnhdr;
00114       val = bfd_bread ((PTR) &core_scnhdr, amt, abfd);
00115       if (val != sizeof core_scnhdr)
00116        break;
00117 
00118       /* Skip empty sections.  */
00119       if (core_scnhdr.size == 0 || core_scnhdr.scnptr == 0)
00120        continue;
00121 
00122       switch (core_scnhdr.scntype)
00123        {
00124        case SCNRGN:
00125          secname = ".data";
00126          flags = SEC_ALLOC + SEC_LOAD + SEC_HAS_CONTENTS;
00127          break;
00128        case SCNSTACK:
00129          secname = ".stack";
00130          flags = SEC_ALLOC + SEC_LOAD + SEC_HAS_CONTENTS;
00131          break;
00132        case SCNREGS:
00133          secname = ".reg";
00134          flags = SEC_HAS_CONTENTS;
00135          break;
00136        default:
00137          (*_bfd_error_handler) (_("Unhandled OSF/1 core file section type %d\n"),
00138                              core_scnhdr.scntype);
00139          continue;
00140        }
00141 
00142       if (!make_bfd_asection (abfd, secname, flags,
00143                            (bfd_size_type) core_scnhdr.size,
00144                            (bfd_vma) core_scnhdr.vaddr,
00145                            (file_ptr) core_scnhdr.scnptr))
00146        goto fail;
00147     }
00148 
00149   /* OK, we believe you.  You're a core file (sure, sure).  */
00150 
00151   return abfd->xvec;
00152 
00153  fail:
00154   bfd_release (abfd, core_hdr (abfd));
00155   core_hdr (abfd) = NULL;
00156   bfd_section_list_clear (abfd);
00157   return NULL;
00158 }
00159 
00160 static char *
00161 osf_core_core_file_failing_command (abfd)
00162      bfd *abfd;
00163 {
00164   return core_command (abfd);
00165 }
00166 
00167 static int
00168 osf_core_core_file_failing_signal (abfd)
00169      bfd *abfd;
00170 {
00171   return core_signal (abfd);
00172 }
00173 
00174 /* If somebody calls any byte-swapping routines, shoot them.  */
00175 static void
00176 swap_abort()
00177 {
00178   abort(); /* This way doesn't require any declaration for ANSI to fuck up */
00179 }
00180 
00181 #define       NO_GET ((bfd_vma (*) (const void *)) swap_abort)
00182 #define       NO_PUT ((void (*) (bfd_vma, void *)) swap_abort)
00183 #define       NO_GETS ((bfd_signed_vma (*) (const void *)) swap_abort)
00184 #define       NO_GET64 ((bfd_uint64_t (*) (const void *)) swap_abort)
00185 #define       NO_PUT64 ((void (*) (bfd_uint64_t, void *)) swap_abort)
00186 #define       NO_GETS64 ((bfd_int64_t (*) (const void *)) swap_abort)
00187 
00188 const bfd_target osf_core_vec =
00189   {
00190     "osf-core",
00191     bfd_target_unknown_flavour,
00192     BFD_ENDIAN_LITTLE,             /* target byte order */
00193     BFD_ENDIAN_LITTLE,             /* target headers byte order */
00194     (HAS_RELOC | EXEC_P |   /* object flags */
00195      HAS_LINENO | HAS_DEBUG |
00196      HAS_SYMS | HAS_LOCALS | WP_TEXT | D_PAGED),
00197     (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
00198     0,                                                  /* symbol prefix */
00199     ' ',                                            /* ar_pad_char */
00200     16,                                                    /* ar_max_namelen */
00201     NO_GET64, NO_GETS64, NO_PUT64, /* 64 bit data */
00202     NO_GET, NO_GETS, NO_PUT,              /* 32 bit data */
00203     NO_GET, NO_GETS, NO_PUT,              /* 16 bit data */
00204     NO_GET64, NO_GETS64, NO_PUT64, /* 64 bit hdrs */
00205     NO_GET, NO_GETS, NO_PUT,              /* 32 bit hdrs */
00206     NO_GET, NO_GETS, NO_PUT,              /* 16 bit hdrs */
00207 
00208     {                       /* bfd_check_format */
00209       _bfd_dummy_target,           /* unknown format */
00210       _bfd_dummy_target,           /* object file */
00211       _bfd_dummy_target,           /* archive */
00212       osf_core_core_file_p         /* a core file */
00213     },
00214     {                       /* bfd_set_format */
00215       bfd_false, bfd_false,
00216       bfd_false, bfd_false
00217     },
00218     {                       /* bfd_write_contents */
00219       bfd_false, bfd_false,
00220       bfd_false, bfd_false
00221     },
00222 
00223     BFD_JUMP_TABLE_GENERIC (_bfd_generic),
00224     BFD_JUMP_TABLE_COPY (_bfd_generic),
00225     BFD_JUMP_TABLE_CORE (osf_core),
00226     BFD_JUMP_TABLE_ARCHIVE (_bfd_noarchive),
00227     BFD_JUMP_TABLE_SYMBOLS (_bfd_nosymbols),
00228     BFD_JUMP_TABLE_RELOCS (_bfd_norelocs),
00229     BFD_JUMP_TABLE_WRITE (_bfd_generic),
00230     BFD_JUMP_TABLE_LINK (_bfd_nolink),
00231     BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),
00232 
00233     NULL,
00234 
00235     (PTR) 0                 /* backend_data */
00236   };