osf-core.c revision 60484
133965Sjdp/* BFD back-end for OSF/1 core files.
260484Sobrien   Copyright 1993, 94, 95, 97, 1998 Free Software Foundation, Inc.
333965Sjdp
433965SjdpThis file is part of BFD, the Binary File Descriptor library.
533965Sjdp
633965SjdpThis program is free software; you can redistribute it and/or modify
733965Sjdpit under the terms of the GNU General Public License as published by
833965Sjdpthe Free Software Foundation; either version 2 of the License, or
933965Sjdp(at your option) any later version.
1033965Sjdp
1133965SjdpThis program is distributed in the hope that it will be useful,
1233965Sjdpbut WITHOUT ANY WARRANTY; without even the implied warranty of
1333965SjdpMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1433965SjdpGNU General Public License for more details.
1533965Sjdp
1633965SjdpYou should have received a copy of the GNU General Public License
1733965Sjdpalong with this program; if not, write to the Free Software
1833965SjdpFoundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
1933965Sjdp
2033965Sjdp/* This file can only be compiled on systems which use OSF/1 style
2133965Sjdp   core files.  */
2233965Sjdp
2333965Sjdp#include "bfd.h"
2433965Sjdp#include "sysdep.h"
2533965Sjdp#include "libbfd.h"
2633965Sjdp
2733965Sjdp#include <sys/user.h>
2833965Sjdp#include <sys/core.h>
2933965Sjdp
3033965Sjdp/* forward declarations */
3133965Sjdp
3233965Sjdpstatic asection *
3333965Sjdpmake_bfd_asection PARAMS ((bfd *, CONST char *, flagword, bfd_size_type,
3433965Sjdp			   bfd_vma, file_ptr));
3533965Sjdpstatic asymbol *
3633965Sjdposf_core_make_empty_symbol PARAMS ((bfd *));
3733965Sjdpstatic const bfd_target *
3833965Sjdposf_core_core_file_p PARAMS ((bfd *));
3933965Sjdpstatic char *
4033965Sjdposf_core_core_file_failing_command PARAMS ((bfd *));
4133965Sjdpstatic int
4233965Sjdposf_core_core_file_failing_signal PARAMS ((bfd *));
4333965Sjdpstatic boolean
4433965Sjdposf_core_core_file_matches_executable_p PARAMS ((bfd *, bfd *));
4533965Sjdpstatic void
4633965Sjdpswap_abort PARAMS ((void));
4733965Sjdp
4833965Sjdp/* These are stored in the bfd's tdata */
4933965Sjdp
5033965Sjdpstruct osf_core_struct
5133965Sjdp{
5233965Sjdp  int sig;
5333965Sjdp  char cmd[MAXCOMLEN + 1];
5433965Sjdp};
5533965Sjdp
5633965Sjdp#define core_hdr(bfd) ((bfd)->tdata.osf_core_data)
5733965Sjdp#define core_signal(bfd) (core_hdr(bfd)->sig)
5833965Sjdp#define core_command(bfd) (core_hdr(bfd)->cmd)
5933965Sjdp
6033965Sjdpstatic asection *
6133965Sjdpmake_bfd_asection (abfd, name, flags, _raw_size, vma, filepos)
6233965Sjdp     bfd *abfd;
6333965Sjdp     CONST char *name;
6433965Sjdp     flagword flags;
6533965Sjdp     bfd_size_type _raw_size;
6633965Sjdp     bfd_vma vma;
6733965Sjdp     file_ptr filepos;
6833965Sjdp{
6933965Sjdp  asection *asect;
7033965Sjdp
7133965Sjdp  asect = bfd_make_section_anyway (abfd, name);
7233965Sjdp  if (!asect)
7333965Sjdp    return NULL;
7433965Sjdp
7533965Sjdp  asect->flags = flags;
7633965Sjdp  asect->_raw_size = _raw_size;
7733965Sjdp  asect->vma = vma;
7833965Sjdp  asect->filepos = filepos;
7933965Sjdp  asect->alignment_power = 8;
8033965Sjdp
8133965Sjdp  return asect;
8233965Sjdp}
8333965Sjdp
8433965Sjdpstatic asymbol *
8533965Sjdposf_core_make_empty_symbol (abfd)
8633965Sjdp     bfd *abfd;
8733965Sjdp{
8833965Sjdp  asymbol *new = (asymbol *) bfd_zalloc (abfd, sizeof (asymbol));
8933965Sjdp  if (new)
9033965Sjdp    new->the_bfd = abfd;
9133965Sjdp  return new;
9233965Sjdp}
9333965Sjdp
9433965Sjdpstatic const bfd_target *
9533965Sjdposf_core_core_file_p (abfd)
9633965Sjdp     bfd *abfd;
9733965Sjdp{
9833965Sjdp  int val;
9933965Sjdp  int i;
10033965Sjdp  char *secname;
10133965Sjdp  struct core_filehdr core_header;
10233965Sjdp
10333965Sjdp  val = bfd_read ((PTR)&core_header, 1, sizeof core_header, abfd);
10433965Sjdp  if (val != sizeof core_header)
10533965Sjdp    return NULL;
10633965Sjdp
10733965Sjdp  if (strncmp (core_header.magic, "Core", 4) != 0)
10833965Sjdp    return NULL;
10933965Sjdp
11033965Sjdp  core_hdr (abfd) = (struct osf_core_struct *)
11133965Sjdp    bfd_zalloc (abfd, sizeof (struct osf_core_struct));
11233965Sjdp  if (!core_hdr (abfd))
11333965Sjdp    return NULL;
11433965Sjdp
11533965Sjdp  strncpy (core_command (abfd), core_header.name, MAXCOMLEN + 1);
11633965Sjdp  core_signal (abfd) = core_header.signo;
11733965Sjdp
11833965Sjdp  for (i = 0; i < core_header.nscns; i++)
11933965Sjdp    {
12033965Sjdp      struct core_scnhdr core_scnhdr;
12133965Sjdp      flagword flags;
12233965Sjdp
12333965Sjdp      val = bfd_read ((PTR)&core_scnhdr, 1, sizeof core_scnhdr, abfd);
12433965Sjdp      if (val != sizeof core_scnhdr)
12533965Sjdp	break;
12633965Sjdp
12733965Sjdp      /* Skip empty sections.  */
12833965Sjdp      if (core_scnhdr.size == 0 || core_scnhdr.scnptr == 0)
12933965Sjdp	continue;
13033965Sjdp
13133965Sjdp      switch (core_scnhdr.scntype)
13233965Sjdp	{
13333965Sjdp	case SCNRGN:
13433965Sjdp	  secname = ".data";
13533965Sjdp	  flags = SEC_ALLOC + SEC_LOAD + SEC_HAS_CONTENTS;
13633965Sjdp	  break;
13733965Sjdp	case SCNSTACK:
13833965Sjdp	  secname = ".stack";
13933965Sjdp	  flags = SEC_ALLOC + SEC_LOAD + SEC_HAS_CONTENTS;
14033965Sjdp	  break;
14133965Sjdp	case SCNREGS:
14233965Sjdp	  secname = ".reg";
14333965Sjdp	  flags = SEC_HAS_CONTENTS;
14433965Sjdp	  break;
14533965Sjdp	default:
14660484Sobrien	  (*_bfd_error_handler) (_("Unhandled OSF/1 core file section type %d\n"),
14733965Sjdp				 core_scnhdr.scntype);
14833965Sjdp	  continue;
14933965Sjdp	}
15033965Sjdp
15133965Sjdp      if (!make_bfd_asection (abfd, secname, flags,
15233965Sjdp			      (bfd_size_type) core_scnhdr.size,
15333965Sjdp			      (bfd_vma) core_scnhdr.vaddr,
15433965Sjdp			      (file_ptr) core_scnhdr.scnptr))
15533965Sjdp	return NULL;
15633965Sjdp    }
15733965Sjdp
15833965Sjdp  /* OK, we believe you.  You're a core file (sure, sure).  */
15933965Sjdp
16033965Sjdp  return abfd->xvec;
16133965Sjdp}
16233965Sjdp
16333965Sjdpstatic char *
16433965Sjdposf_core_core_file_failing_command (abfd)
16533965Sjdp     bfd *abfd;
16633965Sjdp{
16733965Sjdp  return core_command (abfd);
16833965Sjdp}
16933965Sjdp
17033965Sjdp/* ARGSUSED */
17133965Sjdpstatic int
17233965Sjdposf_core_core_file_failing_signal (abfd)
17333965Sjdp     bfd *abfd;
17433965Sjdp{
17533965Sjdp  return core_signal (abfd);
17633965Sjdp}
17733965Sjdp
17833965Sjdp/* ARGSUSED */
17933965Sjdpstatic boolean
18033965Sjdposf_core_core_file_matches_executable_p (core_bfd, exec_bfd)
18133965Sjdp     bfd *core_bfd, *exec_bfd;
18233965Sjdp{
18333965Sjdp  return true;		/* FIXME, We have no way of telling at this point */
18433965Sjdp}
18533965Sjdp
18633965Sjdp#define osf_core_get_symtab_upper_bound _bfd_nosymbols_get_symtab_upper_bound
18733965Sjdp#define osf_core_get_symtab _bfd_nosymbols_get_symtab
18833965Sjdp#define osf_core_print_symbol _bfd_nosymbols_print_symbol
18933965Sjdp#define osf_core_get_symbol_info _bfd_nosymbols_get_symbol_info
19033965Sjdp#define osf_core_bfd_is_local_label_name _bfd_nosymbols_bfd_is_local_label_name
19133965Sjdp#define osf_core_get_lineno _bfd_nosymbols_get_lineno
19233965Sjdp#define osf_core_find_nearest_line _bfd_nosymbols_find_nearest_line
19333965Sjdp#define osf_core_bfd_make_debug_symbol _bfd_nosymbols_bfd_make_debug_symbol
19433965Sjdp#define osf_core_read_minisymbols _bfd_nosymbols_read_minisymbols
19533965Sjdp#define osf_core_minisymbol_to_symbol _bfd_nosymbols_minisymbol_to_symbol
19633965Sjdp
19733965Sjdp/* If somebody calls any byte-swapping routines, shoot them.  */
19833965Sjdpstatic void
19933965Sjdpswap_abort()
20033965Sjdp{
20133965Sjdp  abort(); /* This way doesn't require any declaration for ANSI to fuck up */
20233965Sjdp}
20333965Sjdp#define	NO_GET	((bfd_vma (*) PARAMS ((   const bfd_byte *))) swap_abort )
20433965Sjdp#define	NO_PUT	((void    (*) PARAMS ((bfd_vma, bfd_byte *))) swap_abort )
20533965Sjdp#define	NO_SIGNED_GET \
20633965Sjdp  ((bfd_signed_vma (*) PARAMS ((const bfd_byte *))) swap_abort )
20733965Sjdp
20833965Sjdpconst bfd_target osf_core_vec =
20933965Sjdp  {
21033965Sjdp    "osf-core",
21133965Sjdp    bfd_target_unknown_flavour,
21233965Sjdp    BFD_ENDIAN_BIG,		/* target byte order */
21333965Sjdp    BFD_ENDIAN_BIG,		/* target headers byte order */
21433965Sjdp    (HAS_RELOC | EXEC_P |	/* object flags */
21533965Sjdp     HAS_LINENO | HAS_DEBUG |
21633965Sjdp     HAS_SYMS | HAS_LOCALS | WP_TEXT | D_PAGED),
21733965Sjdp    (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
21833965Sjdp    0,			                                   /* symbol prefix */
21933965Sjdp    ' ',						   /* ar_pad_char */
22033965Sjdp    16,							   /* ar_max_namelen */
22133965Sjdp    NO_GET, NO_SIGNED_GET, NO_PUT,	/* 64 bit data */
22233965Sjdp    NO_GET, NO_SIGNED_GET, NO_PUT,	/* 32 bit data */
22333965Sjdp    NO_GET, NO_SIGNED_GET, NO_PUT,	/* 16 bit data */
22433965Sjdp    NO_GET, NO_SIGNED_GET, NO_PUT,	/* 64 bit hdrs */
22533965Sjdp    NO_GET, NO_SIGNED_GET, NO_PUT,	/* 32 bit hdrs */
22633965Sjdp    NO_GET, NO_SIGNED_GET, NO_PUT,	/* 16 bit hdrs */
22733965Sjdp
22833965Sjdp    {				/* bfd_check_format */
22933965Sjdp     _bfd_dummy_target,		/* unknown format */
23033965Sjdp     _bfd_dummy_target,		/* object file */
23133965Sjdp     _bfd_dummy_target,		/* archive */
23233965Sjdp     osf_core_core_file_p	/* a core file */
23333965Sjdp    },
23433965Sjdp    {				/* bfd_set_format */
23533965Sjdp     bfd_false, bfd_false,
23633965Sjdp     bfd_false, bfd_false
23733965Sjdp    },
23833965Sjdp    {				/* bfd_write_contents */
23933965Sjdp     bfd_false, bfd_false,
24033965Sjdp     bfd_false, bfd_false
24133965Sjdp    },
24233965Sjdp
24333965Sjdp       BFD_JUMP_TABLE_GENERIC (_bfd_generic),
24433965Sjdp       BFD_JUMP_TABLE_COPY (_bfd_generic),
24533965Sjdp       BFD_JUMP_TABLE_CORE (osf_core),
24633965Sjdp       BFD_JUMP_TABLE_ARCHIVE (_bfd_noarchive),
24733965Sjdp       BFD_JUMP_TABLE_SYMBOLS (osf_core),
24833965Sjdp       BFD_JUMP_TABLE_RELOCS (_bfd_norelocs),
24933965Sjdp       BFD_JUMP_TABLE_WRITE (_bfd_generic),
25033965Sjdp       BFD_JUMP_TABLE_LINK (_bfd_nolink),
25133965Sjdp       BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),
25233965Sjdp
25360484Sobrien    NULL,
25460484Sobrien
25533965Sjdp    (PTR) 0			/* backend_data */
25633965Sjdp};
257