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. */
29 #include <sys/kernel.h>
30 /* sys/kernel.h should define this, but doesn't always, sigh. */
35 #include <sys/signal.h>
37 #include <sys/resource.h>
38 #include <sys/itimer.h>
42 /* These are stored in the bfd's tdata */
44 struct lynx_core_struct
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 #define lynx_core_file_matches_executable_p generic_core_file_matches_executable_p
56 /* Handle Lynx core dump file. */
59 make_bfd_asection (abfd
, name
, flags
, size
, vma
, filepos
)
70 newname
= bfd_alloc (abfd
, (bfd_size_type
) strlen (name
) + 1);
74 strcpy (newname
, name
);
76 asect
= bfd_make_section (abfd
, newname
);
83 asect
->filepos
= filepos
;
84 asect
->alignment_power
= 2;
90 lynx_core_file_p (abfd
)
95 bfd_size_type tcontext_size
;
101 pagesize
= getpagesize (); /* Serious cross-target issue here... This
102 really needs to come from a system-specific
105 /* Get the pss entry from the core file */
107 if (bfd_seek (abfd
, (file_ptr
) 0, SEEK_SET
) != 0)
111 if (bfd_bread ((void *) &pss
, amt
, abfd
) != amt
)
113 /* Too small to be a core file */
114 if (bfd_get_error () != bfd_error_system_call
)
115 bfd_set_error (bfd_error_wrong_format
);
119 amt
= sizeof (struct lynx_core_struct
);
120 core_hdr (abfd
) = (struct lynx_core_struct
*) bfd_zalloc (abfd
, amt
);
122 if (!core_hdr (abfd
))
125 strncpy (core_command (abfd
), pss
.pname
, PNMLEN
+ 1);
127 /* Compute the size of the thread contexts */
129 tcontext_size
= pss
.threadcnt
* sizeof (core_st_t
);
131 /* Allocate space for the thread contexts */
133 threadp
= (core_st_t
*) bfd_alloc (abfd
, tcontext_size
);
137 /* Save thread contexts */
139 if (bfd_seek (abfd
, (file_ptr
) pagesize
, SEEK_SET
) != 0)
142 if (bfd_bread ((void *) threadp
, tcontext_size
, abfd
) != tcontext_size
)
144 /* Probably too small to be a core file */
145 if (bfd_get_error () != bfd_error_system_call
)
146 bfd_set_error (bfd_error_wrong_format
);
150 core_signal (abfd
) = threadp
->currsig
;
152 newsect
= make_bfd_asection (abfd
, ".stack",
153 SEC_ALLOC
+ SEC_LOAD
+ SEC_HAS_CONTENTS
,
156 pagesize
+ tcontext_size
);
160 newsect
= make_bfd_asection (abfd
, ".data",
161 SEC_ALLOC
+ SEC_LOAD
+ SEC_HAS_CONTENTS
,
162 pss
.data_len
+ pss
.bss_len
,
164 pagesize
+ tcontext_size
+ pss
.ssize
165 #if defined (SPARC) || defined (__SPARC__)
166 /* SPARC Lynx seems to start dumping
167 the .data section at a page
168 boundary. It's OK to check a
169 #define like SPARC here because this
170 file can only be compiled on a Lynx
172 + pss
.data_start
% pagesize
178 /* And, now for the .reg/XXX pseudo sections. Each thread has it's own
179 .reg/XXX section, where XXX is the thread id (without leading zeros). The
180 currently running thread (at the time of the core dump) also has an alias
181 called `.reg' (just to keep GDB happy). Note that we use `.reg/XXX' as
182 opposed to `.regXXX' because GDB expects that .reg2 will be the floating-
185 newsect
= make_bfd_asection (abfd
, ".reg",
193 for (secnum
= 0; secnum
< pss
.threadcnt
; secnum
++)
197 sprintf (secname
, ".reg/%d", BUILDPID (0, threadp
[secnum
].tid
));
198 newsect
= make_bfd_asection (abfd
, secname
,
202 pagesize
+ secnum
* sizeof (core_st_t
));
210 bfd_release (abfd
, core_hdr (abfd
));
211 core_hdr (abfd
) = NULL
;
212 bfd_section_list_clear (abfd
);
217 lynx_core_file_failing_command (abfd
)
220 return core_command (abfd
);
224 lynx_core_file_failing_signal (abfd
)
227 return core_signal (abfd
);
230 #endif /* LYNX_CORE */