1 /* BFD back end for Lynx core files
2 Copyright 1993, 1994, 1995, 2001, 2002, 2004, 2005, 2006, 2007
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 3 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,
21 MA 02110-1301, USA. */
30 #include <sys/kernel.h>
31 /* sys/kernel.h should define this, but doesn't always, sigh. */
36 #include <sys/signal.h>
38 #include <sys/resource.h>
39 #include <sys/itimer.h>
43 /* These are stored in the bfd's tdata */
45 struct lynx_core_struct
51 #define core_hdr(bfd) ((bfd)->tdata.lynx_core_data)
52 #define core_signal(bfd) (core_hdr(bfd)->sig)
53 #define core_command(bfd) (core_hdr(bfd)->cmd)
55 #define lynx_core_file_matches_executable_p generic_core_file_matches_executable_p
56 #define lynx_core_file_pid _bfd_nocore_core_file_pid
58 /* Handle Lynx core dump file. */
61 make_bfd_asection (abfd, name, flags, size, vma, filepos)
72 newname = bfd_alloc (abfd, (bfd_size_type) strlen (name) + 1);
76 strcpy (newname, name);
78 asect = bfd_make_section_with_flags (abfd, newname, flags);
84 asect->filepos = filepos;
85 asect->alignment_power = 2;
91 lynx_core_file_p (abfd)
96 bfd_size_type tcontext_size;
102 pagesize = getpagesize (); /* Serious cross-target issue here... This
103 really needs to come from a system-specific
106 /* Get the pss entry from the core file */
108 if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0)
112 if (bfd_bread ((void *) &pss, amt, abfd) != amt)
114 /* Too small to be a core file */
115 if (bfd_get_error () != bfd_error_system_call)
116 bfd_set_error (bfd_error_wrong_format);
120 amt = sizeof (struct lynx_core_struct);
121 core_hdr (abfd) = (struct lynx_core_struct *) bfd_zalloc (abfd, amt);
123 if (!core_hdr (abfd))
126 strncpy (core_command (abfd), pss.pname, PNMLEN + 1);
128 /* Compute the size of the thread contexts */
130 tcontext_size = pss.threadcnt * sizeof (core_st_t);
132 /* Allocate space for the thread contexts */
134 threadp = (core_st_t *) bfd_alloc (abfd, tcontext_size);
138 /* Save thread contexts */
140 if (bfd_seek (abfd, (file_ptr) pagesize, SEEK_SET) != 0)
143 if (bfd_bread ((void *) threadp, tcontext_size, abfd) != tcontext_size)
145 /* Probably too small to be a core file */
146 if (bfd_get_error () != bfd_error_system_call)
147 bfd_set_error (bfd_error_wrong_format);
151 core_signal (abfd) = threadp->currsig;
153 newsect = make_bfd_asection (abfd, ".stack",
154 SEC_ALLOC + SEC_LOAD + SEC_HAS_CONTENTS,
157 pagesize + tcontext_size);
161 newsect = make_bfd_asection (abfd, ".data",
162 SEC_ALLOC + SEC_LOAD + SEC_HAS_CONTENTS,
163 pss.data_len + pss.bss_len,
165 pagesize + tcontext_size + pss.ssize
166 #if defined (SPARC) || defined (__SPARC__)
167 /* SPARC Lynx seems to start dumping
168 the .data section at a page
169 boundary. It's OK to check a
170 #define like SPARC here because this
171 file can only be compiled on a Lynx
173 + pss.data_start % pagesize
179 /* And, now for the .reg/XXX pseudo sections. Each thread has it's own
180 .reg/XXX section, where XXX is the thread id (without leading zeros). The
181 currently running thread (at the time of the core dump) also has an alias
182 called `.reg' (just to keep GDB happy). Note that we use `.reg/XXX' as
183 opposed to `.regXXX' because GDB expects that .reg2 will be the floating-
186 newsect = make_bfd_asection (abfd, ".reg",
194 for (secnum = 0; secnum < pss.threadcnt; secnum++)
198 sprintf (secname, ".reg/%d", BUILDPID (0, threadp[secnum].tid));
199 newsect = make_bfd_asection (abfd, secname,
203 pagesize + secnum * sizeof (core_st_t));
211 bfd_release (abfd, core_hdr (abfd));
212 core_hdr (abfd) = NULL;
213 bfd_section_list_clear (abfd);
218 lynx_core_file_failing_command (abfd)
221 return core_command (abfd);
225 lynx_core_file_failing_signal (abfd)
228 return core_signal (abfd);
231 #endif /* LYNX_CORE */