osf-core.c revision 89857
150565Sphk/* BFD back-end for OSF/1 core files. 250565Sphk Copyright 1993, 1994, 1995, 1998, 1999, 2001, 2002 350565Sphk Free Software Foundation, Inc. 450565Sphk 550565SphkThis file is part of BFD, the Binary File Descriptor library. 650565Sphk 750565SphkThis program is free software; you can redistribute it and/or modify 850565Sphkit under the terms of the GNU General Public License as published by 950565Sphkthe Free Software Foundation; either version 2 of the License, or 1050565Sphk(at your option) any later version. 1150565Sphk 1250565SphkThis program is distributed in the hope that it will be useful, 1350565Sphkbut WITHOUT ANY WARRANTY; without even the implied warranty of 1450565SphkMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1550565SphkGNU General Public License for more details. 1651111Sjulian 1760041SphkYou should have received a copy of the GNU General Public License 1850565Sphkalong with this program; if not, write to the Free Software 1950565SphkFoundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ 2050565Sphk 2161953Snbm/* This file can only be compiled on systems which use OSF/1 style 2250728Sphk core files. */ 2350565Sphk 2450565Sphk#include "bfd.h" 2550565Sphk#include "sysdep.h" 2650565Sphk#include "libbfd.h" 2750565Sphk 2850565Sphk#include <sys/user.h> 2950565Sphk#include <sys/core.h> 3050565Sphk 3161717Sphk/* forward declarations */ 3261717Sphk 3350565Sphkstatic asection *make_bfd_asection 3462617Simp PARAMS ((bfd *, const char *, flagword, bfd_size_type, bfd_vma, file_ptr)); 3562617Simpstatic const bfd_target *osf_core_core_file_p PARAMS ((bfd *)); 3662617Simpstatic char *osf_core_core_file_failing_command PARAMS ((bfd *)); 3762617Simpstatic int osf_core_core_file_failing_signal PARAMS ((bfd *)); 3862617Simpstatic boolean osf_core_core_file_matches_executable_p PARAMS ((bfd *, bfd *)); 3962617Simpstatic void swap_abort PARAMS ((void)); 4062617Simp 4162617Simp/* These are stored in the bfd's tdata */ 4262617Simp 4362617Simpstruct osf_core_struct 4462617Simp{ 4550565Sphk int sig; 4651215Sphk char cmd[MAXCOMLEN + 1]; 4750565Sphk}; 4850565Sphk 4950565Sphk#define core_hdr(bfd) ((bfd)->tdata.osf_core_data) 5051198Sphk#define core_signal(bfd) (core_hdr(bfd)->sig) 5151198Sphk#define core_command(bfd) (core_hdr(bfd)->cmd) 5250565Sphk 5351198Sphkstatic asection * 5451215Sphkmake_bfd_asection (abfd, name, flags, _raw_size, vma, filepos) 5551215Sphk bfd *abfd; 5651215Sphk const char *name; 5751215Sphk flagword flags; 5851215Sphk bfd_size_type _raw_size; 5951215Sphk bfd_vma vma; 6051215Sphk file_ptr filepos; 6150565Sphk{ 6250565Sphk asection *asect; 6353437Sjkh 6453437Sjkh asect = bfd_make_section_anyway (abfd, name); 6551243Sphk if (!asect) 6661717Sphk return NULL; 6750565Sphk 6850565Sphk asect->flags = flags; 6950565Sphk asect->_raw_size = _raw_size; 7052917Sphk asect->vma = vma; 7151215Sphk asect->filepos = filepos; 7261717Sphk asect->alignment_power = 8; 7350565Sphk 7450565Sphk return asect; 7550565Sphk} 7650728Sphk 7750728Sphkstatic const bfd_target * 7850728Sphkosf_core_core_file_p (abfd) 7950728Sphk bfd *abfd; 8050728Sphk{ 8150728Sphk int val; 8250728Sphk int i; 8350728Sphk char *secname; 8450728Sphk struct core_filehdr core_header; 8550728Sphk bfd_size_type amt; 8650728Sphk 8750728Sphk amt = sizeof core_header; 8850728Sphk val = bfd_bread ((PTR) &core_header, amt, abfd); 8950728Sphk if (val != sizeof core_header) 9050728Sphk return NULL; 9150728Sphk 9250728Sphk if (strncmp (core_header.magic, "Core", 4) != 0) 9350728Sphk return NULL; 9450728Sphk 9550728Sphk core_hdr (abfd) = (struct osf_core_struct *) 9650728Sphk bfd_zalloc (abfd, (bfd_size_type) sizeof (struct osf_core_struct)); 9750728Sphk if (!core_hdr (abfd)) 9850728Sphk return NULL; 9950728Sphk 10050728Sphk strncpy (core_command (abfd), core_header.name, MAXCOMLEN + 1); 10150728Sphk core_signal (abfd) = core_header.signo; 10250728Sphk 10350728Sphk for (i = 0; i < core_header.nscns; i++) 10450728Sphk { 10550728Sphk struct core_scnhdr core_scnhdr; 10657325Ssos flagword flags; 10757325Ssos 10850728Sphk amt = sizeof core_scnhdr; 10950728Sphk val = bfd_bread ((PTR) &core_scnhdr, amt, abfd); 11050565Sphk if (val != sizeof core_scnhdr) 11156767Sphk break; 11250565Sphk 11361717Sphk /* Skip empty sections. */ 11461717Sphk if (core_scnhdr.size == 0 || core_scnhdr.scnptr == 0) 11557325Ssos continue; 11657325Ssos 11750565Sphk switch (core_scnhdr.scntype) 11850565Sphk { 11950565Sphk case SCNRGN: 12061717Sphk secname = ".data"; 12161717Sphk flags = SEC_ALLOC + SEC_LOAD + SEC_HAS_CONTENTS; 12261717Sphk break; 12361717Sphk case SCNSTACK: 12461717Sphk secname = ".stack"; 12561717Sphk flags = SEC_ALLOC + SEC_LOAD + SEC_HAS_CONTENTS; 12661717Sphk break; 12761717Sphk case SCNREGS: 12861717Sphk secname = ".reg"; 12961953Snbm flags = SEC_HAS_CONTENTS; 13062573Sphk break; 13161953Snbm default: 13261953Snbm (*_bfd_error_handler) (_("Unhandled OSF/1 core file section type %d\n"), 13361953Snbm core_scnhdr.scntype); 13461953Snbm continue; 13561953Snbm } 13661953Snbm 13761953Snbm if (!make_bfd_asection (abfd, secname, flags, 13861953Snbm (bfd_size_type) core_scnhdr.size, 13961953Snbm (bfd_vma) core_scnhdr.vaddr, 14061953Snbm (file_ptr) core_scnhdr.scnptr)) 14161953Snbm goto fail; 14261953Snbm } 14361953Snbm 14461953Snbm /* OK, we believe you. You're a core file (sure, sure). */ 14561953Snbm 14661953Snbm return abfd->xvec; 14761953Snbm 14861953Snbm fail: 14961953Snbm bfd_release (abfd, core_hdr (abfd)); 15061953Snbm core_hdr (abfd) = NULL; 15161953Snbm bfd_section_list_clear (abfd); 15261953Snbm return NULL; 15361953Snbm} 15461953Snbm 15561953Snbmstatic char * 15661953Snbmosf_core_core_file_failing_command (abfd) 15750728Sphk bfd *abfd; 15850728Sphk{ 15950728Sphk return core_command (abfd); 16050728Sphk} 16150565Sphk 16250565Sphk/* ARGSUSED */ 16350565Sphkstatic int 16450565Sphkosf_core_core_file_failing_signal (abfd) 16550565Sphk bfd *abfd; 16650565Sphk{ 16750565Sphk return core_signal (abfd); 16850728Sphk} 16950565Sphk 17050728Sphk/* ARGSUSED */ 17150565Sphkstatic boolean 17250565Sphkosf_core_core_file_matches_executable_p (core_bfd, exec_bfd) 17350565Sphk bfd *core_bfd ATTRIBUTE_UNUSED; 17450728Sphk bfd *exec_bfd ATTRIBUTE_UNUSED; 17552917Sphk{ 17652917Sphk return true; /* FIXME, We have no way of telling at this point */ 17754815Sphk} 17854815Sphk 17954815Sphk/* If somebody calls any byte-swapping routines, shoot them. */ 18052917Sphkstatic void 18152917Sphkswap_abort() 18252917Sphk{ 18351860Sphk abort(); /* This way doesn't require any declaration for ANSI to fuck up */ 18451878Ssos} 18551878Ssos#define NO_GET ((bfd_vma (*) PARAMS (( const bfd_byte *))) swap_abort ) 18651826Sphk#define NO_PUT ((void (*) PARAMS ((bfd_vma, bfd_byte *))) swap_abort ) 18751860Sphk#define NO_SIGNED_GET \ 18851826Sphk ((bfd_signed_vma (*) PARAMS ((const bfd_byte *))) swap_abort ) 18951826Sphk 19062617Simpconst bfd_target osf_core_vec = 19150728Sphk { 19250728Sphk "osf-core", 19352917Sphk bfd_target_unknown_flavour, 19450728Sphk BFD_ENDIAN_BIG, /* target byte order */ 19552917Sphk BFD_ENDIAN_BIG, /* target headers byte order */ 19650565Sphk (HAS_RELOC | EXEC_P | /* object flags */ 19750728Sphk HAS_LINENO | HAS_DEBUG | 19851924Sphk HAS_SYMS | HAS_LOCALS | WP_TEXT | D_PAGED), 19952917Sphk (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */ 20052917Sphk 0, /* symbol prefix */ 20152917Sphk ' ', /* ar_pad_char */ 20252917Sphk 16, /* ar_max_namelen */ 20352917Sphk NO_GET, NO_SIGNED_GET, NO_PUT, /* 64 bit data */ 20452917Sphk NO_GET, NO_SIGNED_GET, NO_PUT, /* 32 bit data */ 20550728Sphk NO_GET, NO_SIGNED_GET, NO_PUT, /* 16 bit data */ 20650565Sphk NO_GET, NO_SIGNED_GET, NO_PUT, /* 64 bit hdrs */ 20750565Sphk NO_GET, NO_SIGNED_GET, NO_PUT, /* 32 bit hdrs */ 20850565Sphk NO_GET, NO_SIGNED_GET, NO_PUT, /* 16 bit hdrs */ 20950565Sphk 21050565Sphk { /* bfd_check_format */ 21150565Sphk _bfd_dummy_target, /* unknown format */ 21250565Sphk _bfd_dummy_target, /* object file */ 21350565Sphk _bfd_dummy_target, /* archive */ 21462617Simp osf_core_core_file_p /* a core file */ 21550565Sphk }, 21650565Sphk { /* bfd_set_format */ 21762617Simp bfd_false, bfd_false, 21862617Simp bfd_false, bfd_false 21951822Sphk }, 22051826Sphk { /* bfd_write_contents */ 22151924Sphk bfd_false, bfd_false, 22251826Sphk bfd_false, bfd_false 22350565Sphk }, 22450565Sphk 22550565Sphk BFD_JUMP_TABLE_GENERIC (_bfd_generic), 22650565Sphk BFD_JUMP_TABLE_COPY (_bfd_generic), 22759249Sphk BFD_JUMP_TABLE_CORE (osf_core), 22850565Sphk BFD_JUMP_TABLE_ARCHIVE (_bfd_noarchive), 22950565Sphk BFD_JUMP_TABLE_SYMBOLS (_bfd_nosymbols), 23050565Sphk BFD_JUMP_TABLE_RELOCS (_bfd_norelocs), 23150565Sphk BFD_JUMP_TABLE_WRITE (_bfd_generic), 23262617Simp BFD_JUMP_TABLE_LINK (_bfd_nolink), 23362617Simp BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic), 23462617Simp 23562617Simp NULL, 23650565Sphk 23750565Sphk (PTR) 0 /* backend_data */ 23859249Sphk}; 23959249Sphk