xref: /openbsd-src/gnu/usr.bin/binutils/bfd/osf-core.c (revision c88b1d6c2990dec69cf89c9efe884ddff6a0bbe5)
1 /* BFD back-end for OSF/1 core files.
2    Copyright 1993, 1994 Free Software Foundation, Inc.
3 
4 This file is part of BFD, the Binary File Descriptor library.
5 
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10 
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 GNU General Public License for more details.
15 
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
19 
20 /* This file can only be compiled on systems which use OSF/1 style
21    core files.  */
22 
23 #include "bfd.h"
24 #include "sysdep.h"
25 #include "libbfd.h"
26 
27 #include <stdio.h>
28 #include <string.h>
29 #include <sys/user.h>
30 #include <sys/core.h>
31 
32 /* forward declarations */
33 
34 static asection *
35 make_bfd_asection PARAMS ((bfd *, CONST char *, flagword, bfd_size_type,
36 			   bfd_vma, file_ptr));
37 static asymbol *
38 osf_core_make_empty_symbol PARAMS ((bfd *));
39 static const bfd_target *
40 osf_core_core_file_p PARAMS ((bfd *));
41 static char *
42 osf_core_core_file_failing_command PARAMS ((bfd *));
43 static int
44 osf_core_core_file_failing_signal PARAMS ((bfd *));
45 static boolean
46 osf_core_core_file_matches_executable_p PARAMS ((bfd *, bfd *));
47 static void
48 swap_abort PARAMS ((void));
49 
50 /* These are stored in the bfd's tdata */
51 
52 struct osf_core_struct
53 {
54   int sig;
55   char cmd[MAXCOMLEN + 1];
56 };
57 
58 #define core_hdr(bfd) ((bfd)->tdata.osf_core_data)
59 #define core_signal(bfd) (core_hdr(bfd)->sig)
60 #define core_command(bfd) (core_hdr(bfd)->cmd)
61 
62 static asection *
63 make_bfd_asection (abfd, name, flags, _raw_size, vma, filepos)
64      bfd *abfd;
65      CONST char *name;
66      flagword flags;
67      bfd_size_type _raw_size;
68      bfd_vma vma;
69      file_ptr filepos;
70 {
71   asection *asect;
72 
73   asect = bfd_make_section_anyway (abfd, name);
74   if (!asect)
75     return NULL;
76 
77   asect->flags = flags;
78   asect->_raw_size = _raw_size;
79   asect->vma = vma;
80   asect->filepos = filepos;
81   asect->alignment_power = 8;
82 
83   return asect;
84 }
85 
86 static asymbol *
87 osf_core_make_empty_symbol (abfd)
88      bfd *abfd;
89 {
90   asymbol *new = (asymbol *) bfd_zalloc (abfd, sizeof (asymbol));
91   if (new)
92     new->the_bfd = abfd;
93   return new;
94 }
95 
96 static const bfd_target *
97 osf_core_core_file_p (abfd)
98      bfd *abfd;
99 {
100   int val;
101   int i;
102   char *secname;
103   struct core_filehdr core_header;
104 
105   val = bfd_read ((PTR)&core_header, 1, sizeof core_header, abfd);
106   if (val != sizeof core_header)
107     return NULL;
108 
109   if (strncmp (core_header.magic, "Core", 4) != 0)
110     return NULL;
111 
112   core_hdr (abfd) = (struct osf_core_struct *)
113     bfd_zalloc (abfd, sizeof (struct osf_core_struct));
114   if (!core_hdr (abfd))
115     return NULL;
116 
117   strncpy (core_command (abfd), core_header.name, MAXCOMLEN + 1);
118   core_signal (abfd) = core_header.signo;
119 
120   for (i = 0; i < core_header.nscns; i++)
121     {
122       struct core_scnhdr core_scnhdr;
123       flagword flags;
124 
125       val = bfd_read ((PTR)&core_scnhdr, 1, sizeof core_scnhdr, abfd);
126       if (val != sizeof core_scnhdr)
127 	break;
128 
129       /* Skip empty sections.  */
130       if (core_scnhdr.size == 0 || core_scnhdr.scnptr == 0)
131 	continue;
132 
133       switch (core_scnhdr.scntype)
134 	{
135 	case SCNRGN:
136 	  secname = ".data";
137 	  flags = SEC_ALLOC + SEC_LOAD + SEC_HAS_CONTENTS;
138 	  break;
139 	case SCNSTACK:
140 	  secname = ".stack";
141 	  flags = SEC_ALLOC + SEC_LOAD + SEC_HAS_CONTENTS;
142 	  break;
143 	case SCNREGS:
144 	  secname = ".reg";
145 	  flags = SEC_HAS_CONTENTS;
146 	  break;
147 	default:
148 	  (*_bfd_error_handler) ("Unhandled OSF/1 core file section type %d\n",
149 				 core_scnhdr.scntype);
150 	  continue;
151 	}
152 
153       if (!make_bfd_asection (abfd, secname, flags,
154 			      (bfd_size_type) core_scnhdr.size,
155 			      (bfd_vma) core_scnhdr.vaddr,
156 			      (file_ptr) core_scnhdr.scnptr))
157 	return NULL;
158     }
159 
160   /* OK, we believe you.  You're a core file (sure, sure).  */
161 
162   return abfd->xvec;
163 }
164 
165 static char *
166 osf_core_core_file_failing_command (abfd)
167      bfd *abfd;
168 {
169   return core_command (abfd);
170 }
171 
172 /* ARGSUSED */
173 static int
174 osf_core_core_file_failing_signal (abfd)
175      bfd *abfd;
176 {
177   return core_signal (abfd);
178 }
179 
180 /* ARGSUSED */
181 static boolean
182 osf_core_core_file_matches_executable_p (core_bfd, exec_bfd)
183      bfd *core_bfd, *exec_bfd;
184 {
185   return true;		/* FIXME, We have no way of telling at this point */
186 }
187 
188 #define osf_core_get_symtab_upper_bound _bfd_nosymbols_get_symtab_upper_bound
189 #define osf_core_get_symtab _bfd_nosymbols_get_symtab
190 #define osf_core_print_symbol _bfd_nosymbols_print_symbol
191 #define osf_core_get_symbol_info _bfd_nosymbols_get_symbol_info
192 #define osf_core_bfd_is_local_label _bfd_nosymbols_bfd_is_local_label
193 #define osf_core_get_lineno _bfd_nosymbols_get_lineno
194 #define osf_core_find_nearest_line _bfd_nosymbols_find_nearest_line
195 #define osf_core_bfd_make_debug_symbol _bfd_nosymbols_bfd_make_debug_symbol
196 #define osf_core_read_minisymbols _bfd_nosymbols_read_minisymbols
197 #define osf_core_minisymbol_to_symbol _bfd_nosymbols_minisymbol_to_symbol
198 
199 /* If somebody calls any byte-swapping routines, shoot them.  */
200 static void
201 swap_abort()
202 {
203   abort(); /* This way doesn't require any declaration for ANSI to fuck up */
204 }
205 #define	NO_GET	((bfd_vma (*) PARAMS ((   const bfd_byte *))) swap_abort )
206 #define	NO_PUT	((void    (*) PARAMS ((bfd_vma, bfd_byte *))) swap_abort )
207 #define	NO_SIGNED_GET \
208   ((bfd_signed_vma (*) PARAMS ((const bfd_byte *))) swap_abort )
209 
210 const bfd_target osf_core_vec =
211   {
212     "osf-core",
213     bfd_target_unknown_flavour,
214     BFD_ENDIAN_BIG,		/* target byte order */
215     BFD_ENDIAN_BIG,		/* target headers byte order */
216     (HAS_RELOC | EXEC_P |	/* object flags */
217      HAS_LINENO | HAS_DEBUG |
218      HAS_SYMS | HAS_LOCALS | WP_TEXT | D_PAGED),
219     (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
220     0,			                                   /* symbol prefix */
221     ' ',						   /* ar_pad_char */
222     16,							   /* ar_max_namelen */
223     NO_GET, NO_SIGNED_GET, NO_PUT,	/* 64 bit data */
224     NO_GET, NO_SIGNED_GET, NO_PUT,	/* 32 bit data */
225     NO_GET, NO_SIGNED_GET, NO_PUT,	/* 16 bit data */
226     NO_GET, NO_SIGNED_GET, NO_PUT,	/* 64 bit hdrs */
227     NO_GET, NO_SIGNED_GET, NO_PUT,	/* 32 bit hdrs */
228     NO_GET, NO_SIGNED_GET, NO_PUT,	/* 16 bit hdrs */
229 
230     {				/* bfd_check_format */
231      _bfd_dummy_target,		/* unknown format */
232      _bfd_dummy_target,		/* object file */
233      _bfd_dummy_target,		/* archive */
234      osf_core_core_file_p	/* a core file */
235     },
236     {				/* bfd_set_format */
237      bfd_false, bfd_false,
238      bfd_false, bfd_false
239     },
240     {				/* bfd_write_contents */
241      bfd_false, bfd_false,
242      bfd_false, bfd_false
243     },
244 
245        BFD_JUMP_TABLE_GENERIC (_bfd_generic),
246        BFD_JUMP_TABLE_COPY (_bfd_generic),
247        BFD_JUMP_TABLE_CORE (osf_core),
248        BFD_JUMP_TABLE_ARCHIVE (_bfd_noarchive),
249        BFD_JUMP_TABLE_SYMBOLS (osf_core),
250        BFD_JUMP_TABLE_RELOCS (_bfd_norelocs),
251        BFD_JUMP_TABLE_WRITE (_bfd_generic),
252        BFD_JUMP_TABLE_LINK (_bfd_nolink),
253        BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),
254 
255     (PTR) 0			/* backend_data */
256 };
257