Thu May 21 18:00:09 1992 Michael Tiemann (tiemann@rtl.cygnus.com)
[deliverable/binutils-gdb.git] / bfd / trad-core.c
CommitLineData
9712c6e2
SG
1/* BFD back end for traditional Unix core files (U-area and raw sections)
2 Copyright (C) 1988, 1989, 1991 Free Software Foundation, Inc.
3 Written by John Gilmore of Cygnus Support.
4
5This file is part of BFD, the Binary File Descriptor library.
6
7This program is free software; you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
9the Free Software Foundation; either version 2 of the License, or
10(at your option) any later version.
11
12This program is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with this program; if not, write to the Free Software
19Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
ff37ea55 20
6a469027
JG
21/* To use this file on a particular host, configure the host with these
22 parameters in the config/h-HOST file:
23
637942e4 24 HDEFINES=-DTRAD_CORE
6a469027
JG
25 HDEPFILES=trad-core.o
26
27 */
28
ff37ea55 29#include "bfd.h"
637942e4 30#include "sysdep.h"
ff37ea55 31#include "libbfd.h"
359f1dee 32#include "libaout.h" /* BFD a.out internal data structures */
ff37ea55 33
637942e4 34#include <stdio.h>
ff37ea55
JG
35#include <sys/types.h>
36#include <sys/param.h>
37#include <sys/dir.h>
38#include <signal.h>
39#include <machine/reg.h>
40
41#include <sys/user.h> /* After a.out.h */
42#include <sys/file.h>
ff37ea55
JG
43
44#include <errno.h>
45
ff37ea55
JG
46/* These are stored in the bfd's tdata */
47struct core_data {
48 struct user *upage; /* core file header */
49 asection *data_section;
50 asection *stack_section;
51 asection *reg_section;
52};
53
6a469027
JG
54#define core_hdr(bfd) (((struct core_data *) (bfd->tdata))->hdr)
55#define core_upage(bfd) (((struct core_data *) ((bfd)->tdata))->upage)
56#define core_datasec(bfd) (((struct core_data *) ((bfd)->tdata))->data_section)
57#define core_stacksec(bfd) (((struct core_data*)((bfd)->tdata))->stack_section)
58#define core_regsec(bfd) (((struct core_data *) ((bfd)->tdata))->reg_section)
59
637942e4
JG
60/* Handle 4.2-style (and perhaps also sysV-style) core dump file. */
61
7ed4093a 62/* ARGSUSED */
ff37ea55
JG
63bfd_target *
64trad_unix_core_file_p (abfd)
65 bfd *abfd;
66{
ff37ea55 67 int val;
ff37ea55
JG
68 struct user u;
69 unsigned int reg_offset, fp_reg_offset;
637942e4
JG
70 /* This struct is just for allocating two things with one zalloc, so
71 they will be freed together, without violating alignment constraints. */
72 struct core_user {
73 struct core_data coredata;
74 struct user u;
75 } *rawptr;
ff37ea55
JG
76
77 val = bfd_read ((void *)&u, 1, sizeof u, abfd);
78 if (val != sizeof u)
79 return 0; /* Too small to be a core file */
80
81 /* Sanity check perhaps??? */
82 if (u.u_dsize > 0x1000000) /* Remember, it's in pages... */
83 return 0;
84 if (u.u_ssize > 0x1000000)
85 return 0;
86 /* Check that the size claimed is no greater than the file size. FIXME. */
87
88 /* OK, we believe you. You're a core file (sure, sure). */
89
90 /* Allocate both the upage and the struct core_data at once, so
91 a single free() will free them both. */
637942e4 92 rawptr = (struct core_user *)bfd_zalloc (abfd, sizeof (struct core_user));
ff37ea55
JG
93 if (rawptr == NULL) {
94 bfd_error = no_memory;
95 return 0;
96 }
97
637942e4
JG
98 set_tdata (abfd, &rawptr->coredata);
99 core_upage (abfd) = &rawptr->u;
ff37ea55
JG
100 *core_upage (abfd) = u; /* Save that upage! */
101
637942e4
JG
102 /* Create the sections. This is raunchy, but bfd_close wants to free
103 them separately. */
ff37ea55
JG
104 core_stacksec (abfd) = (asection *) zalloc (sizeof (asection));
105 if (core_stacksec (abfd) == NULL) {
106loser:
107 bfd_error = no_memory;
108 free ((void *)rawptr);
109 return 0;
110 }
111 core_datasec (abfd) = (asection *) zalloc (sizeof (asection));
112 if (core_datasec (abfd) == NULL) {
113loser1:
114 free ((void *)core_stacksec (abfd));
115 goto loser;
116 }
117 core_regsec (abfd) = (asection *) zalloc (sizeof (asection));
118 if (core_regsec (abfd) == NULL) {
119loser2:
120 free ((void *)core_datasec (abfd));
121 goto loser1;
122 }
123
124 core_stacksec (abfd)->name = ".stack";
125 core_datasec (abfd)->name = ".data";
126 core_regsec (abfd)->name = ".reg";
127
6a469027
JG
128 core_stacksec (abfd)->flags = SEC_ALLOC + SEC_LOAD + SEC_HAS_CONTENTS;
129 core_datasec (abfd)->flags = SEC_ALLOC + SEC_LOAD + SEC_HAS_CONTENTS;
130 core_regsec (abfd)->flags = SEC_ALLOC + SEC_HAS_CONTENTS;
ff37ea55
JG
131
132 core_datasec (abfd)->size = NBPG * u.u_dsize;
133 core_stacksec (abfd)->size = NBPG * u.u_ssize;
134 core_regsec (abfd)->size = NBPG * UPAGES; /* Larger than sizeof struct u */
135
136 /* What a hack... we'd like to steal it from the exec file,
137 since the upage does not seem to provide it. FIXME. */
9712c6e2
SG
138#ifdef HOST_DATA_START_ADDR
139 core_datasec (abfd)->vma = HOST_DATA_START_ADDR;
140#else
141 core_datasec (abfd)->vma = HOST_TEXT_START_ADDR + (NBPG * u.u_tsize);
142#endif
143 core_stacksec (abfd)->vma = HOST_STACK_END_ADDR - (NBPG * u.u_ssize);
637942e4
JG
144 /* This is tricky. As the "register section", we give them the entire
145 upage and stack. u.u_ar0 points to where "register 0" is stored.
146 There are two tricks with this, though. One is that the rest of the
147 registers might be at positive or negative (or both) displacements
148 from *u_ar0. The other is that u_ar0 is sometimes an absolute address
149 in kernel memory, and on other systems it is an offset from the beginning
150 of the `struct user'.
151
152 As a practical matter, we don't know where the registers actually are,
153 so we have to pass the whole area to GDB. We encode the value of u_ar0
154 by setting the .regs section up so that its virtual memory address
155 0 is at the place pointed to by u_ar0 (by setting the vma of the start
156 of the section to -u_ar0). GDB uses this info to locate the regs,
157 using minor trickery to get around the offset-or-absolute-addr problem. */
158 core_regsec (abfd)->vma = 0 - (int) u.u_ar0;
ff37ea55
JG
159
160 core_datasec (abfd)->filepos = NBPG * UPAGES;
161 core_stacksec (abfd)->filepos = (NBPG * UPAGES) + NBPG * u.u_dsize;
162 core_regsec (abfd)->filepos = 0; /* Register segment is the upage */
163
164 /* Align to word at least */
165 core_stacksec (abfd)->alignment_power = 2;
166 core_datasec (abfd)->alignment_power = 2;
167 core_regsec (abfd)->alignment_power = 2;
168
169 abfd->sections = core_stacksec (abfd);
170 core_stacksec (abfd)->next = core_datasec (abfd);
171 core_datasec (abfd)->next = core_regsec (abfd);
172 abfd->section_count = 3;
173
174 return abfd->xvec;
ff37ea55
JG
175}
176
177char *
178trad_unix_core_file_failing_command (abfd)
179 bfd *abfd;
180{
181 if (*core_upage (abfd)->u_comm)
182 return core_upage (abfd)->u_comm;
183 else
184 return 0;
185}
186
7ed4093a 187/* ARGSUSED */
ff37ea55 188int
7ed4093a
SC
189trad_unix_core_file_failing_signal (ignore_abfd)
190 bfd *ignore_abfd;
ff37ea55
JG
191{
192 return -1; /* FIXME, where is it? */
193}
194
7ed4093a 195/* ARGSUSED */
ff37ea55
JG
196boolean
197trad_unix_core_file_matches_executable_p (core_bfd, exec_bfd)
198 bfd *core_bfd, *exec_bfd;
199{
200 return true; /* FIXME, We have no way of telling at this point */
201}
6a469027
JG
202\f
203/* No archive file support via this BFD */
204#define trad_unix_openr_next_archived_file bfd_generic_openr_next_archived_file
205#define trad_unix_generic_stat_arch_elt bfd_generic_stat_arch_elt
206#define trad_unix_slurp_armap bfd_false
207#define trad_unix_slurp_extended_name_table bfd_true
208#define trad_unix_write_armap (PROTO (boolean, (*), \
209 (bfd *arch, unsigned int elength, struct orl *map, int orl_count, \
210 int stridx))) bfd_false
211#define trad_unix_truncate_arname bfd_dont_truncate_arname
212#define aout_32_openr_next_archived_file bfd_generic_openr_next_archived_file
213
214#define trad_unix_close_and_cleanup bfd_generic_close_and_cleanup
215#define trad_unix_set_section_contents (PROTO(boolean, (*), \
216 (bfd *abfd, asection *section, PTR data, file_ptr offset, \
217 bfd_size_type count))) bfd_false
218#define trad_unix_get_section_contents bfd_generic_get_section_contents
219#define trad_unix_new_section_hook (PROTO (boolean, (*), \
220 (bfd *, sec_ptr))) bfd_true
221#define trad_unix_get_symtab_upper_bound bfd_0u
222#define trad_unix_get_symtab (PROTO (unsigned int, (*), \
223 (bfd *, struct symbol_cache_entry **))) bfd_0u
224#define trad_unix_get_reloc_upper_bound (PROTO (unsigned int, (*), \
225 (bfd *, sec_ptr))) bfd_0u
226#define trad_unix_canonicalize_reloc (PROTO (unsigned int, (*), \
227 (bfd *, sec_ptr, arelent **, struct symbol_cache_entry**))) bfd_0u
228#define trad_unix_make_empty_symbol (PROTO ( \
229 struct symbol_cache_entry *, (*), (bfd *))) bfd_false
230#define trad_unix_print_symbol (PROTO (void, (*), \
231 (bfd *, PTR, struct symbol_cache_entry *, \
232 bfd_print_symbol_type))) bfd_false
233#define trad_unix_get_lineno (PROTO (alent *, (*), \
234 (bfd *, struct symbol_cache_entry *))) bfd_nullvoidptr
235#define trad_unix_set_arch_mach (PROTO (boolean, (*), \
236 (bfd *, enum bfd_architecture, unsigned long))) bfd_false
237#define trad_unix_find_nearest_line (PROTO (boolean, (*), \
238 (bfd *abfd, struct sec *section, \
239 struct symbol_cache_entry **symbols,bfd_vma offset, \
240 CONST char **file, CONST char **func, unsigned int *line))) bfd_false
241#define trad_unix_sizeof_headers (PROTO (int, (*), \
242 (bfd *, boolean))) bfd_0
243
244#define trad_unix_bfd_debug_info_start bfd_void
245#define trad_unix_bfd_debug_info_end bfd_void
246#define trad_unix_bfd_debug_info_accumulate (PROTO (void, (*), \
247 (bfd *, struct sec *))) bfd_void
248
637942e4
JG
249/* If somebody calls any byte-swapping routines, shoot them. */
250void
251swap_abort()
252{
253 abort(); /* This way doesn't require any declaration for ANSI to fuck up */
254}
255#define NO_GET ((PROTO(bfd_vma, (*), ( bfd_byte *))) swap_abort )
256#define NO_PUT ((PROTO(void, (*), (bfd_vma, bfd_byte *))) swap_abort )
6a469027 257
637942e4 258bfd_target trad_core_vec =
6a469027 259 {
637942e4 260 "trad-core",
6a469027
JG
261 bfd_target_unknown_flavour,
262 true, /* target byte order */
263 true, /* target headers byte order */
264 (HAS_RELOC | EXEC_P | /* object flags */
265 HAS_LINENO | HAS_DEBUG |
266 HAS_SYMS | HAS_LOCALS | DYNAMIC | WP_TEXT | D_PAGED),
267 (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
268 ' ', /* ar_pad_char */
269 16, /* ar_max_namelen */
270 3, /* minimum alignment power */
637942e4
JG
271 NO_GET, NO_PUT, NO_GET, NO_PUT, NO_GET, NO_PUT, /* data */
272 NO_GET, NO_PUT, NO_GET, NO_PUT, NO_GET, NO_PUT, /* hdrs */
273
274 {_bfd_dummy_target, _bfd_dummy_target,
275 _bfd_dummy_target, trad_unix_core_file_p},
276 {bfd_false, bfd_false, /* bfd_create_object */
277 bfd_false, bfd_false},
278 {bfd_false, bfd_false, /* bfd_write_contents */
279 bfd_false, bfd_false},
6a469027
JG
280
281 JUMP_TABLE(trad_unix)
282};
This page took 0.055271 seconds and 4 git commands to generate.