Output hex with local_hex_string for Modula-2 support.
[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
JG
20
21/* This file does not define a particular back-end, but it defines routines
22 that can be used by other back-ends. */
7ed4093a 23#include <sysdep.h>
ff37ea55
JG
24#include "bfd.h"
25#include <stdio.h>
26#include "libbfd.h"
27
359f1dee 28#include "libaout.h" /* BFD a.out internal data structures */
ff37ea55
JG
29
30#include <sys/types.h>
31#include <sys/param.h>
32#include <sys/dir.h>
33#include <signal.h>
34#include <machine/reg.h>
35
36#include <sys/user.h> /* After a.out.h */
37#include <sys/file.h>
ff37ea55
JG
38
39#include <errno.h>
40
41/* need this cast b/c ptr is really void * */
42#define core_hdr(bfd) (((struct core_data *) (bfd->tdata))->hdr)
43#define core_datasec(bfd) (((struct core_data *) ((bfd)->tdata))->data_section)
44#define core_stacksec(bfd) (((struct core_data*)((bfd)->tdata))->stack_section)
45#define core_regsec(bfd) (((struct core_data *) ((bfd)->tdata))->reg_section)
46#define core_upage(bfd) (((struct core_data *) ((bfd)->tdata))->upage)
47
48/* These are stored in the bfd's tdata */
49struct core_data {
50 struct user *upage; /* core file header */
51 asection *data_section;
52 asection *stack_section;
53 asection *reg_section;
54};
55
7ed4093a 56/* ARGSUSED */
ff37ea55
JG
57bfd_target *
58trad_unix_core_file_p (abfd)
59 bfd *abfd;
60{
9712c6e2 61#if HOST_SYS == SUN4_SYS
ff37ea55
JG
62 return 0;
63#else
64 int val;
65 char *rawptr;
66 struct user u;
67 unsigned int reg_offset, fp_reg_offset;
68
69 /* 4.2-style (and perhaps also sysV-style) core dump file. */
70
71 val = bfd_read ((void *)&u, 1, sizeof u, abfd);
72 if (val != sizeof u)
73 return 0; /* Too small to be a core file */
74
75 /* Sanity check perhaps??? */
76 if (u.u_dsize > 0x1000000) /* Remember, it's in pages... */
77 return 0;
78 if (u.u_ssize > 0x1000000)
79 return 0;
80 /* Check that the size claimed is no greater than the file size. FIXME. */
81
82 /* OK, we believe you. You're a core file (sure, sure). */
83
84 /* Allocate both the upage and the struct core_data at once, so
85 a single free() will free them both. */
86 rawptr = (char *)zalloc (sizeof (u) + sizeof (struct core_data));
87 if (rawptr == NULL) {
88 bfd_error = no_memory;
89 return 0;
90 }
91
92 set_tdata (abfd, (struct core_data *)rawptr);
93 core_upage (abfd) = (struct user *)(rawptr + sizeof (struct core_data));
94 *core_upage (abfd) = u; /* Save that upage! */
95
96 /* create the sections. This is raunchy, but bfd_close wants to reclaim
97 them */
98 core_stacksec (abfd) = (asection *) zalloc (sizeof (asection));
99 if (core_stacksec (abfd) == NULL) {
100loser:
101 bfd_error = no_memory;
102 free ((void *)rawptr);
103 return 0;
104 }
105 core_datasec (abfd) = (asection *) zalloc (sizeof (asection));
106 if (core_datasec (abfd) == NULL) {
107loser1:
108 free ((void *)core_stacksec (abfd));
109 goto loser;
110 }
111 core_regsec (abfd) = (asection *) zalloc (sizeof (asection));
112 if (core_regsec (abfd) == NULL) {
113loser2:
114 free ((void *)core_datasec (abfd));
115 goto loser1;
116 }
117
118 core_stacksec (abfd)->name = ".stack";
119 core_datasec (abfd)->name = ".data";
120 core_regsec (abfd)->name = ".reg";
121
122 core_stacksec (abfd)->flags = SEC_ALLOC + SEC_LOAD;
123 core_datasec (abfd)->flags = SEC_ALLOC + SEC_LOAD;
124 core_regsec (abfd)->flags = SEC_ALLOC;
125
126 core_datasec (abfd)->size = NBPG * u.u_dsize;
127 core_stacksec (abfd)->size = NBPG * u.u_ssize;
128 core_regsec (abfd)->size = NBPG * UPAGES; /* Larger than sizeof struct u */
129
130 /* What a hack... we'd like to steal it from the exec file,
131 since the upage does not seem to provide it. FIXME. */
9712c6e2
SG
132#ifdef HOST_DATA_START_ADDR
133 core_datasec (abfd)->vma = HOST_DATA_START_ADDR;
134#else
135 core_datasec (abfd)->vma = HOST_TEXT_START_ADDR + (NBPG * u.u_tsize);
136#endif
137 core_stacksec (abfd)->vma = HOST_STACK_END_ADDR - (NBPG * u.u_ssize);
ff37ea55
JG
138 core_regsec (abfd)->vma = -1;
139
140 core_datasec (abfd)->filepos = NBPG * UPAGES;
141 core_stacksec (abfd)->filepos = (NBPG * UPAGES) + NBPG * u.u_dsize;
142 core_regsec (abfd)->filepos = 0; /* Register segment is the upage */
143
144 /* Align to word at least */
145 core_stacksec (abfd)->alignment_power = 2;
146 core_datasec (abfd)->alignment_power = 2;
147 core_regsec (abfd)->alignment_power = 2;
148
149 abfd->sections = core_stacksec (abfd);
150 core_stacksec (abfd)->next = core_datasec (abfd);
151 core_datasec (abfd)->next = core_regsec (abfd);
152 abfd->section_count = 3;
153
154 return abfd->xvec;
155#endif
156}
157
158char *
159trad_unix_core_file_failing_command (abfd)
160 bfd *abfd;
161{
162 if (*core_upage (abfd)->u_comm)
163 return core_upage (abfd)->u_comm;
164 else
165 return 0;
166}
167
7ed4093a 168/* ARGSUSED */
ff37ea55 169int
7ed4093a
SC
170trad_unix_core_file_failing_signal (ignore_abfd)
171 bfd *ignore_abfd;
ff37ea55
JG
172{
173 return -1; /* FIXME, where is it? */
174}
175
7ed4093a 176/* ARGSUSED */
ff37ea55
JG
177boolean
178trad_unix_core_file_matches_executable_p (core_bfd, exec_bfd)
179 bfd *core_bfd, *exec_bfd;
180{
181 return true; /* FIXME, We have no way of telling at this point */
182}
This page took 0.037011 seconds and 4 git commands to generate.