osf-core.c revision 33965
133965Sjdp/* BFD back-end for OSF/1 core files.
233965Sjdp   Copyright 1993, 94, 95, 1997 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 <stdio.h>
2833965Sjdp#include <string.h>
2933965Sjdp#include <sys/user.h>
3033965Sjdp#include <sys/core.h>
3133965Sjdp
3233965Sjdp/* forward declarations */
3333965Sjdp
3433965Sjdpstatic asection *
3533965Sjdpmake_bfd_asection PARAMS ((bfd *, CONST char *, flagword, bfd_size_type,
3633965Sjdp			   bfd_vma, file_ptr));
3733965Sjdpstatic asymbol *
3833965Sjdposf_core_make_empty_symbol PARAMS ((bfd *));
3933965Sjdpstatic const bfd_target *
4033965Sjdposf_core_core_file_p PARAMS ((bfd *));
4133965Sjdpstatic char *
4233965Sjdposf_core_core_file_failing_command PARAMS ((bfd *));
4333965Sjdpstatic int
4433965Sjdposf_core_core_file_failing_signal PARAMS ((bfd *));
4533965Sjdpstatic boolean
4633965Sjdposf_core_core_file_matches_executable_p PARAMS ((bfd *, bfd *));
4733965Sjdpstatic void
4833965Sjdpswap_abort PARAMS ((void));
4933965Sjdp
5033965Sjdp/* These are stored in the bfd's tdata */
5133965Sjdp
5233965Sjdpstruct osf_core_struct
5333965Sjdp{
5433965Sjdp  int sig;
5533965Sjdp  char cmd[MAXCOMLEN + 1];
5633965Sjdp};
5733965Sjdp
5833965Sjdp#define core_hdr(bfd) ((bfd)->tdata.osf_core_data)
5933965Sjdp#define core_signal(bfd) (core_hdr(bfd)->sig)
6033965Sjdp#define core_command(bfd) (core_hdr(bfd)->cmd)
6133965Sjdp
6233965Sjdpstatic asection *
6333965Sjdpmake_bfd_asection (abfd, name, flags, _raw_size, vma, filepos)
6433965Sjdp     bfd *abfd;
6533965Sjdp     CONST char *name;
6633965Sjdp     flagword flags;
6733965Sjdp     bfd_size_type _raw_size;
6833965Sjdp     bfd_vma vma;
6933965Sjdp     file_ptr filepos;
7033965Sjdp{
7133965Sjdp  asection *asect;
7233965Sjdp
7333965Sjdp  asect = bfd_make_section_anyway (abfd, name);
7433965Sjdp  if (!asect)
7533965Sjdp    return NULL;
7633965Sjdp
7733965Sjdp  asect->flags = flags;
7833965Sjdp  asect->_raw_size = _raw_size;
7933965Sjdp  asect->vma = vma;
8033965Sjdp  asect->filepos = filepos;
8133965Sjdp  asect->alignment_power = 8;
8233965Sjdp
8333965Sjdp  return asect;
8433965Sjdp}
8533965Sjdp
8633965Sjdpstatic asymbol *
8733965Sjdposf_core_make_empty_symbol (abfd)
8833965Sjdp     bfd *abfd;
8933965Sjdp{
9033965Sjdp  asymbol *new = (asymbol *) bfd_zalloc (abfd, sizeof (asymbol));
9133965Sjdp  if (new)
9233965Sjdp    new->the_bfd = abfd;
9333965Sjdp  return new;
9433965Sjdp}
9533965Sjdp
9633965Sjdpstatic const bfd_target *
9733965Sjdposf_core_core_file_p (abfd)
9833965Sjdp     bfd *abfd;
9933965Sjdp{
10033965Sjdp  int val;
10133965Sjdp  int i;
10233965Sjdp  char *secname;
10333965Sjdp  struct core_filehdr core_header;
10433965Sjdp
10533965Sjdp  val = bfd_read ((PTR)&core_header, 1, sizeof core_header, abfd);
10633965Sjdp  if (val != sizeof core_header)
10733965Sjdp    return NULL;
10833965Sjdp
10933965Sjdp  if (strncmp (core_header.magic, "Core", 4) != 0)
11033965Sjdp    return NULL;
11133965Sjdp
11233965Sjdp  core_hdr (abfd) = (struct osf_core_struct *)
11333965Sjdp    bfd_zalloc (abfd, sizeof (struct osf_core_struct));
11433965Sjdp  if (!core_hdr (abfd))
11533965Sjdp    return NULL;
11633965Sjdp
11733965Sjdp  strncpy (core_command (abfd), core_header.name, MAXCOMLEN + 1);
11833965Sjdp  core_signal (abfd) = core_header.signo;
11933965Sjdp
12033965Sjdp  for (i = 0; i < core_header.nscns; i++)
12133965Sjdp    {
12233965Sjdp      struct core_scnhdr core_scnhdr;
12333965Sjdp      flagword flags;
12433965Sjdp
12533965Sjdp      val = bfd_read ((PTR)&core_scnhdr, 1, sizeof core_scnhdr, abfd);
12633965Sjdp      if (val != sizeof core_scnhdr)
12733965Sjdp	break;
12833965Sjdp
12933965Sjdp      /* Skip empty sections.  */
13033965Sjdp      if (core_scnhdr.size == 0 || core_scnhdr.scnptr == 0)
13133965Sjdp	continue;
13233965Sjdp
13333965Sjdp      switch (core_scnhdr.scntype)
13433965Sjdp	{
13533965Sjdp	case SCNRGN:
13633965Sjdp	  secname = ".data";
13733965Sjdp	  flags = SEC_ALLOC + SEC_LOAD + SEC_HAS_CONTENTS;
13833965Sjdp	  break;
13933965Sjdp	case SCNSTACK:
14033965Sjdp	  secname = ".stack";
14133965Sjdp	  flags = SEC_ALLOC + SEC_LOAD + SEC_HAS_CONTENTS;
14233965Sjdp	  break;
14333965Sjdp	case SCNREGS:
14433965Sjdp	  secname = ".reg";
14533965Sjdp	  flags = SEC_HAS_CONTENTS;
14633965Sjdp	  break;
14733965Sjdp	default:
14833965Sjdp	  (*_bfd_error_handler) ("Unhandled OSF/1 core file section type %d\n",
14933965Sjdp				 core_scnhdr.scntype);
15033965Sjdp	  continue;
15133965Sjdp	}
15233965Sjdp
15333965Sjdp      if (!make_bfd_asection (abfd, secname, flags,
15433965Sjdp			      (bfd_size_type) core_scnhdr.size,
15533965Sjdp			      (bfd_vma) core_scnhdr.vaddr,
15633965Sjdp			      (file_ptr) core_scnhdr.scnptr))
15733965Sjdp	return NULL;
15833965Sjdp    }
15933965Sjdp
16033965Sjdp  /* OK, we believe you.  You're a core file (sure, sure).  */
16133965Sjdp
16233965Sjdp  return abfd->xvec;
16333965Sjdp}
16433965Sjdp
16533965Sjdpstatic char *
16633965Sjdposf_core_core_file_failing_command (abfd)
16733965Sjdp     bfd *abfd;
16833965Sjdp{
16933965Sjdp  return core_command (abfd);
17033965Sjdp}
17133965Sjdp
17233965Sjdp/* ARGSUSED */
17333965Sjdpstatic int
17433965Sjdposf_core_core_file_failing_signal (abfd)
17533965Sjdp     bfd *abfd;
17633965Sjdp{
17733965Sjdp  return core_signal (abfd);
17833965Sjdp}
17933965Sjdp
18033965Sjdp/* ARGSUSED */
18133965Sjdpstatic boolean
18233965Sjdposf_core_core_file_matches_executable_p (core_bfd, exec_bfd)
18333965Sjdp     bfd *core_bfd, *exec_bfd;
18433965Sjdp{
18533965Sjdp  return true;		/* FIXME, We have no way of telling at this point */
18633965Sjdp}
18733965Sjdp
18833965Sjdp#define osf_core_get_symtab_upper_bound _bfd_nosymbols_get_symtab_upper_bound
18933965Sjdp#define osf_core_get_symtab _bfd_nosymbols_get_symtab
19033965Sjdp#define osf_core_print_symbol _bfd_nosymbols_print_symbol
19133965Sjdp#define osf_core_get_symbol_info _bfd_nosymbols_get_symbol_info
19233965Sjdp#define osf_core_bfd_is_local_label_name _bfd_nosymbols_bfd_is_local_label_name
19333965Sjdp#define osf_core_get_lineno _bfd_nosymbols_get_lineno
19433965Sjdp#define osf_core_find_nearest_line _bfd_nosymbols_find_nearest_line
19533965Sjdp#define osf_core_bfd_make_debug_symbol _bfd_nosymbols_bfd_make_debug_symbol
19633965Sjdp#define osf_core_read_minisymbols _bfd_nosymbols_read_minisymbols
19733965Sjdp#define osf_core_minisymbol_to_symbol _bfd_nosymbols_minisymbol_to_symbol
19833965Sjdp
19933965Sjdp/* If somebody calls any byte-swapping routines, shoot them.  */
20033965Sjdpstatic void
20133965Sjdpswap_abort()
20233965Sjdp{
20333965Sjdp  abort(); /* This way doesn't require any declaration for ANSI to fuck up */
20433965Sjdp}
20533965Sjdp#define	NO_GET	((bfd_vma (*) PARAMS ((   const bfd_byte *))) swap_abort )
20633965Sjdp#define	NO_PUT	((void    (*) PARAMS ((bfd_vma, bfd_byte *))) swap_abort )
20733965Sjdp#define	NO_SIGNED_GET \
20833965Sjdp  ((bfd_signed_vma (*) PARAMS ((const bfd_byte *))) swap_abort )
20933965Sjdp
21033965Sjdpconst bfd_target osf_core_vec =
21133965Sjdp  {
21233965Sjdp    "osf-core",
21333965Sjdp    bfd_target_unknown_flavour,
21433965Sjdp    BFD_ENDIAN_BIG,		/* target byte order */
21533965Sjdp    BFD_ENDIAN_BIG,		/* target headers byte order */
21633965Sjdp    (HAS_RELOC | EXEC_P |	/* object flags */
21733965Sjdp     HAS_LINENO | HAS_DEBUG |
21833965Sjdp     HAS_SYMS | HAS_LOCALS | WP_TEXT | D_PAGED),
21933965Sjdp    (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
22033965Sjdp    0,			                                   /* symbol prefix */
22133965Sjdp    ' ',						   /* ar_pad_char */
22233965Sjdp    16,							   /* ar_max_namelen */
22333965Sjdp    NO_GET, NO_SIGNED_GET, NO_PUT,	/* 64 bit data */
22433965Sjdp    NO_GET, NO_SIGNED_GET, NO_PUT,	/* 32 bit data */
22533965Sjdp    NO_GET, NO_SIGNED_GET, NO_PUT,	/* 16 bit data */
22633965Sjdp    NO_GET, NO_SIGNED_GET, NO_PUT,	/* 64 bit hdrs */
22733965Sjdp    NO_GET, NO_SIGNED_GET, NO_PUT,	/* 32 bit hdrs */
22833965Sjdp    NO_GET, NO_SIGNED_GET, NO_PUT,	/* 16 bit hdrs */
22933965Sjdp
23033965Sjdp    {				/* bfd_check_format */
23133965Sjdp     _bfd_dummy_target,		/* unknown format */
23233965Sjdp     _bfd_dummy_target,		/* object file */
23333965Sjdp     _bfd_dummy_target,		/* archive */
23433965Sjdp     osf_core_core_file_p	/* a core file */
23533965Sjdp    },
23633965Sjdp    {				/* bfd_set_format */
23733965Sjdp     bfd_false, bfd_false,
23833965Sjdp     bfd_false, bfd_false
23933965Sjdp    },
24033965Sjdp    {				/* bfd_write_contents */
24133965Sjdp     bfd_false, bfd_false,
24233965Sjdp     bfd_false, bfd_false
24333965Sjdp    },
24433965Sjdp
24533965Sjdp       BFD_JUMP_TABLE_GENERIC (_bfd_generic),
24633965Sjdp       BFD_JUMP_TABLE_COPY (_bfd_generic),
24733965Sjdp       BFD_JUMP_TABLE_CORE (osf_core),
24833965Sjdp       BFD_JUMP_TABLE_ARCHIVE (_bfd_noarchive),
24933965Sjdp       BFD_JUMP_TABLE_SYMBOLS (osf_core),
25033965Sjdp       BFD_JUMP_TABLE_RELOCS (_bfd_norelocs),
25133965Sjdp       BFD_JUMP_TABLE_WRITE (_bfd_generic),
25233965Sjdp       BFD_JUMP_TABLE_LINK (_bfd_nolink),
25333965Sjdp       BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),
25433965Sjdp
25533965Sjdp    (PTR) 0			/* backend_data */
25633965Sjdp};
257