00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #include "bfd.h"
00029 #include "sysdep.h"
00030 #include "libbfd.h"
00031
00032 #include <sys/user.h>
00033 #include <sys/core.h>
00034
00035
00036
00037 static asection *make_bfd_asection
00038 PARAMS ((bfd *, const char *, flagword, bfd_size_type, bfd_vma, file_ptr));
00039 static const bfd_target *osf_core_core_file_p
00040 PARAMS ((bfd *));
00041 static char *osf_core_core_file_failing_command
00042 PARAMS ((bfd *));
00043 static int osf_core_core_file_failing_signal
00044 PARAMS ((bfd *));
00045 static bfd_boolean osf_core_core_file_matches_executable_p
00046 PARAMS ((bfd *, bfd *));
00047 static void swap_abort
00048 PARAMS ((void));
00049
00050
00051
00052 struct osf_core_struct
00053 {
00054 int sig;
00055 char cmd[MAXCOMLEN + 1];
00056 };
00057
00058 #define core_hdr(bfd) ((bfd)->tdata.osf_core_data)
00059 #define core_signal(bfd) (core_hdr(bfd)->sig)
00060 #define core_command(bfd) (core_hdr(bfd)->cmd)
00061
00062 static asection *
00063 make_bfd_asection (abfd, name, flags, size, vma, filepos)
00064 bfd *abfd;
00065 const char *name;
00066 flagword flags;
00067 bfd_size_type size;
00068 bfd_vma vma;
00069 file_ptr filepos;
00070 {
00071 asection *asect;
00072
00073 asect = bfd_make_section_anyway (abfd, name);
00074 if (!asect)
00075 return NULL;
00076
00077 asect->flags = flags;
00078 asect->size = size;
00079 asect->vma = vma;
00080 asect->filepos = filepos;
00081 asect->alignment_power = 8;
00082
00083 return asect;
00084 }
00085
00086 static const bfd_target *
00087 osf_core_core_file_p (abfd)
00088 bfd *abfd;
00089 {
00090 int val;
00091 int i;
00092 char *secname;
00093 struct core_filehdr core_header;
00094 bfd_size_type amt;
00095
00096 amt = sizeof core_header;
00097 val = bfd_bread ((PTR) &core_header, amt, abfd);
00098 if (val != sizeof core_header)
00099 return NULL;
00100
00101 if (strncmp (core_header.magic, "Core", 4) != 0)
00102 return NULL;
00103
00104 core_hdr (abfd) = (struct osf_core_struct *)
00105 bfd_zalloc (abfd, (bfd_size_type) sizeof (struct osf_core_struct));
00106 if (!core_hdr (abfd))
00107 return NULL;
00108
00109 strncpy (core_command (abfd), core_header.name, MAXCOMLEN + 1);
00110 core_signal (abfd) = core_header.signo;
00111
00112 for (i = 0; i < core_header.nscns; i++)
00113 {
00114 struct core_scnhdr core_scnhdr;
00115 flagword flags;
00116
00117 amt = sizeof core_scnhdr;
00118 val = bfd_bread ((PTR) &core_scnhdr, amt, abfd);
00119 if (val != sizeof core_scnhdr)
00120 break;
00121
00122
00123 if (core_scnhdr.size == 0 || core_scnhdr.scnptr == 0)
00124 continue;
00125
00126 switch (core_scnhdr.scntype)
00127 {
00128 case SCNRGN:
00129 secname = ".data";
00130 flags = SEC_ALLOC + SEC_LOAD + SEC_HAS_CONTENTS;
00131 break;
00132 case SCNSTACK:
00133 secname = ".stack";
00134 flags = SEC_ALLOC + SEC_LOAD + SEC_HAS_CONTENTS;
00135 break;
00136 case SCNREGS:
00137 secname = ".reg";
00138 flags = SEC_HAS_CONTENTS;
00139 break;
00140 default:
00141 (*_bfd_error_handler) (_("Unhandled OSF/1 core file section type %d\n"),
00142 core_scnhdr.scntype);
00143 continue;
00144 }
00145
00146 if (!make_bfd_asection (abfd, secname, flags,
00147 (bfd_size_type) core_scnhdr.size,
00148 (bfd_vma) core_scnhdr.vaddr,
00149 (file_ptr) core_scnhdr.scnptr))
00150 goto fail;
00151 }
00152
00153
00154
00155 return abfd->xvec;
00156
00157 fail:
00158 bfd_release (abfd, core_hdr (abfd));
00159 core_hdr (abfd) = NULL;
00160 bfd_section_list_clear (abfd);
00161 return NULL;
00162 }
00163
00164 static char *
00165 osf_core_core_file_failing_command (abfd)
00166 bfd *abfd;
00167 {
00168 return core_command (abfd);
00169 }
00170
00171 static int
00172 osf_core_core_file_failing_signal (abfd)
00173 bfd *abfd;
00174 {
00175 return core_signal (abfd);
00176 }
00177
00178 static bfd_boolean
00179 osf_core_core_file_matches_executable_p (core_bfd, exec_bfd)
00180 bfd *core_bfd ATTRIBUTE_UNUSED;
00181 bfd *exec_bfd ATTRIBUTE_UNUSED;
00182 {
00183 return TRUE;
00184 }
00185
00186
00187 static void
00188 swap_abort()
00189 {
00190 abort();
00191 }
00192
00193 #define NO_GET ((bfd_vma (*) (const void *)) swap_abort)
00194 #define NO_PUT ((void (*) (bfd_vma, void *)) swap_abort)
00195 #define NO_GETS ((bfd_signed_vma (*) (const void *)) swap_abort)
00196 #define NO_GET64 ((bfd_uint64_t (*) (const void *)) swap_abort)
00197 #define NO_PUT64 ((void (*) (bfd_uint64_t, void *)) swap_abort)
00198 #define NO_GETS64 ((bfd_int64_t (*) (const void *)) swap_abort)
00199
00200 const bfd_target osf_core_vec =
00201 {
00202 "osf-core",
00203 bfd_target_unknown_flavour,
00204 BFD_ENDIAN_LITTLE,
00205 BFD_ENDIAN_LITTLE,
00206 (HAS_RELOC | EXEC_P |
00207 HAS_LINENO | HAS_DEBUG |
00208 HAS_SYMS | HAS_LOCALS | WP_TEXT | D_PAGED),
00209 (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC),
00210 0,
00211 ' ',
00212 16,
00213 NO_GET64, NO_GETS64, NO_PUT64,
00214 NO_GET, NO_GETS, NO_PUT,
00215 NO_GET, NO_GETS, NO_PUT,
00216 NO_GET64, NO_GETS64, NO_PUT64,
00217 NO_GET, NO_GETS, NO_PUT,
00218 NO_GET, NO_GETS, NO_PUT,
00219
00220 {
00221 _bfd_dummy_target,
00222 _bfd_dummy_target,
00223 _bfd_dummy_target,
00224 osf_core_core_file_p
00225 },
00226 {
00227 bfd_false, bfd_false,
00228 bfd_false, bfd_false
00229 },
00230 {
00231 bfd_false, bfd_false,
00232 bfd_false, bfd_false
00233 },
00234
00235 BFD_JUMP_TABLE_GENERIC (_bfd_generic),
00236 BFD_JUMP_TABLE_COPY (_bfd_generic),
00237 BFD_JUMP_TABLE_CORE (osf_core),
00238 BFD_JUMP_TABLE_ARCHIVE (_bfd_noarchive),
00239 BFD_JUMP_TABLE_SYMBOLS (_bfd_nosymbols),
00240 BFD_JUMP_TABLE_RELOCS (_bfd_norelocs),
00241 BFD_JUMP_TABLE_WRITE (_bfd_generic),
00242 BFD_JUMP_TABLE_LINK (_bfd_nolink),
00243 BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),
00244
00245 NULL,
00246
00247 (PTR) 0
00248 };