1 /* BFD back end for Lynx core files
2 Copyright (C) 1993-2024 Free Software Foundation, Inc.
3 Written by Stu Grossman of Cygnus Support.
5 This file is part of BFD, the Binary File Descriptor library.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
20 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
55 #define lynx_core_file_pid _bfd_nocore_core_file_pid
57 /* Handle Lynx core dump file. */
60 make_bfd_asection (bfd
*abfd
,
70 newname
= bfd_alloc (abfd
, (bfd_size_type
) strlen (name
) + 1);
74 strcpy (newname
, name
);
76 asect
= bfd_make_section_with_flags (abfd
, newname
, flags
);
82 asect
->filepos
= filepos
;
83 asect
->alignment_power
= 2;
89 lynx_core_file_p (bfd
*abfd
)
93 bfd_size_type tcontext_size
;
99 pagesize
= getpagesize (); /* Serious cross-target issue here... This
100 really needs to come from a system-specific
103 /* Get the pss entry from the core file */
105 if (bfd_seek (abfd
, 0, SEEK_SET
) != 0)
109 if (bfd_read (&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
);
117 amt
= sizeof (struct lynx_core_struct
);
118 core_hdr (abfd
) = (struct lynx_core_struct
*) bfd_zalloc (abfd
, amt
);
120 if (!core_hdr (abfd
))
123 strncpy (core_command (abfd
), pss
.pname
, PNMLEN
);
124 core_command (abfd
)[PNMLEN
] = 0;
126 /* Compute the size of the thread contexts */
128 tcontext_size
= pss
.threadcnt
* sizeof (core_st_t
);
130 /* Save thread contexts */
131 if (bfd_seek (abfd
, pagesize
, SEEK_SET
) != 0)
133 threadp
= (core_st_t
*) _bfd_alloc_and_read (abfd
, tcontext_size
,
138 core_signal (abfd
) = threadp
->currsig
;
140 newsect
= make_bfd_asection (abfd
, ".stack",
141 SEC_ALLOC
+ SEC_LOAD
+ SEC_HAS_CONTENTS
,
144 pagesize
+ tcontext_size
);
148 newsect
= make_bfd_asection (abfd
, ".data",
149 SEC_ALLOC
+ SEC_LOAD
+ SEC_HAS_CONTENTS
,
150 pss
.data_len
+ pss
.bss_len
,
152 pagesize
+ tcontext_size
+ pss
.ssize
153 #if defined (SPARC) || defined (__SPARC__)
154 /* SPARC Lynx seems to start dumping
155 the .data section at a page
156 boundary. It's OK to check a
157 #define like SPARC here because this
158 file can only be compiled on a Lynx
160 + pss
.data_start
% pagesize
166 /* And, now for the .reg/XXX pseudo sections. Each thread has it's own
167 .reg/XXX section, where XXX is the thread id (without leading zeros). The
168 currently running thread (at the time of the core dump) also has an alias
169 called `.reg' (just to keep GDB happy). Note that we use `.reg/XXX' as
170 opposed to `.regXXX' because GDB expects that .reg2 will be the floating-
173 newsect
= make_bfd_asection (abfd
, ".reg",
181 for (secnum
= 0; secnum
< pss
.threadcnt
; secnum
++)
185 sprintf (secname
, ".reg/%d", BUILDPID (0, threadp
[secnum
].tid
));
186 newsect
= make_bfd_asection (abfd
, secname
,
190 pagesize
+ secnum
* sizeof (core_st_t
));
195 return _bfd_no_cleanup
;
198 bfd_release (abfd
, core_hdr (abfd
));
199 core_hdr (abfd
) = NULL
;
200 bfd_section_list_clear (abfd
);
205 lynx_core_file_failing_command (bfd
*abfd
)
207 return core_command (abfd
);
211 lynx_core_file_failing_signal (bfd
*abfd
)
213 return core_signal (abfd
);
216 #endif /* LYNX_CORE */