Remove dejagnu/ entry.
[binutils.git] / bfd / lynx-core.c
blob470cb506467c13045a014003f84dfc8e2905f466
1 /* BFD back end for Lynx core files
2 Copyright 1993, 1994, 1995, 2001, 2002, 2004
3 Free Software Foundation, Inc.
4 Written by Stu Grossman of Cygnus Support.
6 This file is part of BFD, the Binary File Descriptor library.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */
22 #include "bfd.h"
23 #include "sysdep.h"
24 #include "libbfd.h"
26 #ifdef LYNX_CORE
28 #include <sys/conf.h>
29 #include <sys/kernel.h>
30 /* sys/kernel.h should define this, but doesn't always, sigh. */
31 #ifndef __LYNXOS
32 #define __LYNXOS
33 #endif
34 #include <sys/mem.h>
35 #include <sys/signal.h>
36 #include <sys/time.h>
37 #include <sys/resource.h>
38 #include <sys/itimer.h>
39 #include <sys/file.h>
40 #include <sys/proc.h>
42 /* These are stored in the bfd's tdata */
44 struct lynx_core_struct
46 int sig;
47 char cmd[PNMLEN + 1];
50 #define core_hdr(bfd) ((bfd)->tdata.lynx_core_data)
51 #define core_signal(bfd) (core_hdr(bfd)->sig)
52 #define core_command(bfd) (core_hdr(bfd)->cmd)
54 /* Handle Lynx core dump file. */
56 static asection *
57 make_bfd_asection (abfd, name, flags, size, vma, filepos)
58 bfd *abfd;
59 const char *name;
60 flagword flags;
61 bfd_size_type size;
62 bfd_vma vma;
63 file_ptr filepos;
65 asection *asect;
66 char *newname;
68 newname = bfd_alloc (abfd, (bfd_size_type) strlen (name) + 1);
69 if (!newname)
70 return NULL;
72 strcpy (newname, name);
74 asect = bfd_make_section (abfd, newname);
75 if (!asect)
76 return NULL;
78 asect->flags = flags;
79 asect->size = size;
80 asect->vma = vma;
81 asect->filepos = filepos;
82 asect->alignment_power = 2;
84 return asect;
87 const bfd_target *
88 lynx_core_file_p (abfd)
89 bfd *abfd;
91 int secnum;
92 struct pssentry pss;
93 bfd_size_type tcontext_size;
94 core_st_t *threadp;
95 int pagesize;
96 asection *newsect;
97 bfd_size_type amt;
99 pagesize = getpagesize (); /* Serious cross-target issue here... This
100 really needs to come from a system-specific
101 header file. */
103 /* Get the pss entry from the core file */
105 if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0)
106 return NULL;
108 amt = sizeof pss;
109 if (bfd_bread ((void *) &pss, amt, abfd) != amt)
111 /* Too small to be a core file */
112 if (bfd_get_error () != bfd_error_system_call)
113 bfd_set_error (bfd_error_wrong_format);
114 return NULL;
117 amt = sizeof (struct lynx_core_struct);
118 core_hdr (abfd) = (struct lynx_core_struct *) bfd_zalloc (abfd, amt);
120 if (!core_hdr (abfd))
121 return NULL;
123 strncpy (core_command (abfd), pss.pname, PNMLEN + 1);
125 /* Compute the size of the thread contexts */
127 tcontext_size = pss.threadcnt * sizeof (core_st_t);
129 /* Allocate space for the thread contexts */
131 threadp = (core_st_t *) bfd_alloc (abfd, tcontext_size);
132 if (!threadp)
133 goto fail;
135 /* Save thread contexts */
137 if (bfd_seek (abfd, (file_ptr) pagesize, SEEK_SET) != 0)
138 goto fail;
140 if (bfd_bread ((void *) threadp, tcontext_size, abfd) != tcontext_size)
142 /* Probably too small to be a core file */
143 if (bfd_get_error () != bfd_error_system_call)
144 bfd_set_error (bfd_error_wrong_format);
145 goto fail;
148 core_signal (abfd) = threadp->currsig;
150 newsect = make_bfd_asection (abfd, ".stack",
151 SEC_ALLOC + SEC_LOAD + SEC_HAS_CONTENTS,
152 pss.ssize,
153 pss.slimit,
154 pagesize + tcontext_size);
155 if (!newsect)
156 goto fail;
158 newsect = make_bfd_asection (abfd, ".data",
159 SEC_ALLOC + SEC_LOAD + SEC_HAS_CONTENTS,
160 pss.data_len + pss.bss_len,
161 pss.data_start,
162 pagesize + tcontext_size + pss.ssize
163 #if defined (SPARC) || defined (__SPARC__)
164 /* SPARC Lynx seems to start dumping
165 the .data section at a page
166 boundary. It's OK to check a
167 #define like SPARC here because this
168 file can only be compiled on a Lynx
169 host. */
170 + pss.data_start % pagesize
171 #endif
173 if (!newsect)
174 goto fail;
176 /* And, now for the .reg/XXX pseudo sections. Each thread has it's own
177 .reg/XXX section, where XXX is the thread id (without leading zeros). The
178 currently running thread (at the time of the core dump) also has an alias
179 called `.reg' (just to keep GDB happy). Note that we use `.reg/XXX' as
180 opposed to `.regXXX' because GDB expects that .reg2 will be the floating-
181 point registers. */
183 newsect = make_bfd_asection (abfd, ".reg",
184 SEC_HAS_CONTENTS,
185 sizeof (core_st_t),
187 pagesize);
188 if (!newsect)
189 goto fail;
191 for (secnum = 0; secnum < pss.threadcnt; secnum++)
193 char secname[100];
195 sprintf (secname, ".reg/%d", BUILDPID (0, threadp[secnum].tid));
196 newsect = make_bfd_asection (abfd, secname,
197 SEC_HAS_CONTENTS,
198 sizeof (core_st_t),
200 pagesize + secnum * sizeof (core_st_t));
201 if (!newsect)
202 goto fail;
205 return abfd->xvec;
207 fail:
208 bfd_release (abfd, core_hdr (abfd));
209 core_hdr (abfd) = NULL;
210 bfd_section_list_clear (abfd);
211 return NULL;
214 char *
215 lynx_core_file_failing_command (abfd)
216 bfd *abfd;
218 return core_command (abfd);
222 lynx_core_file_failing_signal (abfd)
223 bfd *abfd;
225 return core_signal (abfd);
228 bfd_boolean
229 lynx_core_file_matches_executable_p (core_bfd, exec_bfd)
230 bfd *core_bfd, *exec_bfd;
232 return TRUE; /* FIXME, We have no way of telling at this point */
235 #endif /* LYNX_CORE */