]>
Commit | Line | Data |
---|---|---|
4c3721d5 ILT |
1 | /* BFD backend for core files which use the ptrace_user structure |
2 | Copyright 1993 Free Software Foundation, Inc. | |
3 | The structure of this file is based on trad-core.c written by John Gilmore | |
4 | of Cygnus Support. | |
5 | Modified to work with the ptrace_user structure by Kevin A. Buettner. | |
6 | (Longterm it may be better to merge this file with trad-core.c) | |
7 | ||
8 | This file is part of BFD, the Binary File Descriptor library. | |
9 | ||
10 | This program is free software; you can redistribute it and/or modify | |
11 | it under the terms of the GNU General Public License as published by | |
12 | the Free Software Foundation; either version 2 of the License, or | |
13 | (at your option) any later version. | |
14 | ||
15 | This program is distributed in the hope that it will be useful, | |
16 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 | GNU General Public License for more details. | |
19 | ||
20 | You should have received a copy of the GNU General Public License | |
21 | along with this program; if not, write to the Free Software | |
22 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | |
23 | ||
24 | To use this file on a particular host, configure the host with these | |
25 | parameters in the config/h-HOST file: | |
26 | ||
27 | HDEFINES=-DPTRACE_CORE | |
28 | HDEPFILES=ptrace-core.o | |
29 | ||
30 | */ | |
31 | ||
32 | #ifdef PTRACE_CORE | |
33 | ||
34 | #include "bfd.h" | |
35 | #include "sysdep.h" | |
36 | #include "libbfd.h" | |
37 | ||
38 | #include <stdio.h> | |
39 | #include <sys/types.h> | |
40 | #include <sys/param.h> | |
41 | #include <sys/dir.h> | |
42 | #include <signal.h> | |
43 | #include <errno.h> | |
44 | #include <unistd.h> | |
45 | #include <sys/ptrace.h> | |
46 | ||
47 | ||
48 | struct trad_core_struct | |
49 | { | |
50 | asection *data_section; | |
51 | asection *stack_section; | |
52 | asection *reg_section; | |
53 | struct ptrace_user u; | |
54 | } *rawptr; | |
55 | ||
56 | #define core_upage(bfd) (&((bfd)->tdata.trad_core_data->u)) | |
57 | #define core_datasec(bfd) ((bfd)->tdata.trad_core_data->data_section) | |
58 | #define core_stacksec(bfd) ((bfd)->tdata.trad_core_data->stack_section) | |
59 | #define core_regsec(bfd) ((bfd)->tdata.trad_core_data->reg_section) | |
60 | ||
61 | /* forward declarations */ | |
62 | ||
63 | bfd_target * ptrace_unix_core_file_p PARAMS ((bfd *abfd)); | |
64 | char * ptrace_unix_core_file_failing_command PARAMS ((bfd *abfd)); | |
65 | int ptrace_unix_core_file_failing_signal PARAMS ((bfd *abfd)); | |
66 | boolean ptrace_unix_core_file_matches_executable_p | |
67 | PARAMS ((bfd *core_bfd, bfd *exec_bfd)); | |
68 | ||
69 | /* ARGSUSED */ | |
70 | bfd_target * | |
71 | ptrace_unix_core_file_p (abfd) | |
72 | bfd *abfd; | |
73 | ||
74 | { | |
75 | int val; | |
76 | struct ptrace_user u; | |
77 | ||
78 | val = bfd_read ((void *)&u, 1, sizeof u, abfd); | |
79 | if (val != sizeof u || u.pt_magic != _BCS_PTRACE_MAGIC | |
80 | || u.pt_rev != _BCS_PTRACE_REV) | |
81 | { | |
82 | /* Too small to be a core file */ | |
83 | bfd_error = wrong_format; | |
84 | return 0; | |
85 | } | |
86 | ||
87 | /* OK, we believe you. You're a core file (sure, sure). */ | |
88 | ||
89 | /* Allocate both the upage and the struct core_data at once, so | |
90 | a single free() will free them both. */ | |
91 | rawptr = (struct trad_core_struct *) | |
92 | bfd_zalloc (abfd, sizeof (struct trad_core_struct)); | |
93 | ||
94 | if (rawptr == NULL) { | |
95 | bfd_error = no_memory; | |
96 | return 0; | |
97 | } | |
98 | ||
99 | abfd->tdata.trad_core_data = rawptr; | |
100 | ||
101 | rawptr->u = u; /*Copy the uarea into the tdata part of the bfd */ | |
102 | ||
103 | /* Create the sections. This is raunchy, but bfd_close wants to free | |
104 | them separately. */ | |
105 | ||
106 | core_stacksec(abfd) = (asection *) zalloc (sizeof (asection)); | |
107 | if (core_stacksec (abfd) == NULL) { | |
108 | loser: | |
109 | bfd_error = no_memory; | |
110 | free ((void *)rawptr); | |
111 | return 0; | |
112 | } | |
113 | core_datasec (abfd) = (asection *) zalloc (sizeof (asection)); | |
114 | if (core_datasec (abfd) == NULL) { | |
115 | loser1: | |
116 | free ((void *)core_stacksec (abfd)); | |
117 | goto loser; | |
118 | } | |
119 | core_regsec (abfd) = (asection *) zalloc (sizeof (asection)); | |
120 | if (core_regsec (abfd) == NULL) { | |
121 | free ((void *)core_datasec (abfd)); | |
122 | goto loser1; | |
123 | } | |
124 | ||
125 | core_stacksec (abfd)->name = ".stack"; | |
126 | core_datasec (abfd)->name = ".data"; | |
127 | core_regsec (abfd)->name = ".reg"; | |
128 | ||
129 | /* FIXME: Need to worry about shared memory, library data, and library | |
130 | text. I don't think that any of these things are supported on the | |
131 | system on which I am developing this for though. */ | |
132 | ||
133 | ||
134 | core_stacksec (abfd)->flags = SEC_ALLOC + SEC_LOAD + SEC_HAS_CONTENTS; | |
135 | core_datasec (abfd)->flags = SEC_ALLOC + SEC_LOAD + SEC_HAS_CONTENTS; | |
136 | core_regsec (abfd)->flags = SEC_ALLOC + SEC_HAS_CONTENTS; | |
137 | ||
138 | core_datasec (abfd)->_raw_size = u.pt_dsize; | |
139 | core_stacksec (abfd)->_raw_size = u.pt_ssize; | |
140 | core_regsec (abfd)->_raw_size = sizeof(u); | |
141 | ||
142 | core_datasec (abfd)->vma = u.pt_o_data_start; | |
143 | core_stacksec (abfd)->vma = USRSTACK - u.pt_ssize; | |
144 | core_regsec (abfd)->vma = 0 - sizeof(u); /* see trad-core.c */ | |
145 | ||
146 | core_datasec (abfd)->filepos = (int) u.pt_dataptr; | |
147 | core_stacksec (abfd)->filepos = (int) (u.pt_dataptr + u.pt_dsize); | |
148 | core_regsec (abfd)->filepos = 0; /* Register segment is ptrace_user */ | |
149 | ||
150 | /* Align to word at least */ | |
151 | core_stacksec (abfd)->alignment_power = 2; | |
152 | core_datasec (abfd)->alignment_power = 2; | |
153 | core_regsec (abfd)->alignment_power = 2; | |
154 | ||
155 | abfd->sections = core_stacksec (abfd); | |
156 | core_stacksec (abfd)->next = core_datasec (abfd); | |
157 | core_datasec (abfd)->next = core_regsec (abfd); | |
158 | abfd->section_count = 3; | |
159 | ||
160 | return abfd->xvec; | |
161 | } | |
162 | ||
163 | char * | |
164 | ptrace_unix_core_file_failing_command (abfd) | |
165 | bfd *abfd; | |
166 | { | |
167 | char *com = abfd->tdata.trad_core_data->u.pt_comm; | |
168 | if (*com) | |
169 | return com; | |
170 | else | |
171 | return 0; | |
172 | } | |
173 | ||
174 | /* ARGSUSED */ | |
175 | int | |
176 | ptrace_unix_core_file_failing_signal (abfd) | |
177 | bfd *abfd; | |
178 | { | |
179 | return abfd->tdata.trad_core_data->u.pt_sigframe.sig_num; | |
180 | } | |
181 | ||
182 | /* ARGSUSED */ | |
183 | boolean | |
184 | ptrace_unix_core_file_matches_executable_p (core_bfd, exec_bfd) | |
185 | bfd *core_bfd, *exec_bfd; | |
186 | { | |
187 | /* FIXME: Use pt_timdat field of the ptrace_user structure to match | |
188 | the date of the executable */ | |
189 | return true; | |
190 | } | |
191 | \f | |
192 | /* No archive file support via this BFD */ | |
193 | #define ptrace_unix_openr_next_archived_file bfd_generic_openr_next_archived_file | |
194 | #define ptrace_unix_generic_stat_arch_elt bfd_generic_stat_arch_elt | |
195 | #define ptrace_unix_slurp_armap bfd_false | |
196 | #define ptrace_unix_slurp_extended_name_table bfd_true | |
197 | #define ptrace_unix_write_armap (boolean (*) PARAMS \ | |
198 | ((bfd *arch, unsigned int elength, struct orl *map, \ | |
199 | unsigned int orl_count, int stridx))) bfd_false | |
200 | #define ptrace_unix_truncate_arname bfd_dont_truncate_arname | |
201 | #define aout_32_openr_next_archived_file bfd_generic_openr_next_archived_file | |
202 | ||
203 | #define ptrace_unix_close_and_cleanup bfd_generic_close_and_cleanup | |
204 | #define ptrace_unix_set_section_contents (boolean (*) PARAMS \ | |
205 | ((bfd *abfd, asection *section, PTR data, file_ptr offset, \ | |
206 | bfd_size_type count))) bfd_false | |
207 | #define ptrace_unix_get_section_contents bfd_generic_get_section_contents | |
208 | #define ptrace_unix_new_section_hook (boolean (*) PARAMS \ | |
209 | ((bfd *, sec_ptr))) bfd_true | |
210 | #define ptrace_unix_get_symtab_upper_bound bfd_0u | |
211 | #define ptrace_unix_get_symtab (unsigned int (*) PARAMS \ | |
212 | ((bfd *, struct symbol_cache_entry **))) bfd_0u | |
213 | #define ptrace_unix_get_reloc_upper_bound (unsigned int (*) PARAMS \ | |
214 | ((bfd *, sec_ptr))) bfd_0u | |
215 | #define ptrace_unix_canonicalize_reloc (unsigned int (*) PARAMS \ | |
216 | ((bfd *, sec_ptr, arelent **, struct symbol_cache_entry**))) bfd_0u | |
217 | #define ptrace_unix_make_empty_symbol (struct symbol_cache_entry * \ | |
218 | (*) PARAMS ((bfd *))) bfd_false | |
219 | #define ptrace_unix_print_symbol (void (*) PARAMS \ | |
220 | ((bfd *, PTR, struct symbol_cache_entry *, \ | |
221 | bfd_print_symbol_type))) bfd_false | |
222 | #define ptrace_unix_get_symbol_info (void (*) PARAMS \ | |
223 | ((bfd *, struct symbol_cache_entry *, \ | |
224 | symbol_info *))) bfd_false | |
225 | #define ptrace_unix_get_lineno (alent * (*) PARAMS \ | |
226 | ((bfd *, struct symbol_cache_entry *))) bfd_nullvoidptr | |
227 | #define ptrace_unix_set_arch_mach (boolean (*) PARAMS \ | |
228 | ((bfd *, enum bfd_architecture, unsigned long))) bfd_false | |
229 | #define ptrace_unix_find_nearest_line (boolean (*) PARAMS \ | |
230 | ((bfd *abfd, struct sec *section, \ | |
231 | struct symbol_cache_entry **symbols,bfd_vma offset, \ | |
232 | CONST char **file, CONST char **func, unsigned int *line))) bfd_false | |
233 | #define ptrace_unix_sizeof_headers (int (*) PARAMS \ | |
234 | ((bfd *, boolean))) bfd_0 | |
235 | ||
236 | #define ptrace_unix_bfd_debug_info_start bfd_void | |
237 | #define ptrace_unix_bfd_debug_info_end bfd_void | |
238 | #define ptrace_unix_bfd_debug_info_accumulate (void (*) PARAMS \ | |
239 | ((bfd *, struct sec *))) bfd_void | |
240 | #define ptrace_unix_bfd_get_relocated_section_contents bfd_generic_get_relocated_section_contents | |
241 | #define ptrace_unix_bfd_relax_section bfd_generic_relax_section | |
242 | #define ptrace_unix_bfd_reloc_type_lookup \ | |
243 | ((CONST struct reloc_howto_struct *(*) PARAMS ((bfd *, bfd_reloc_code_real_type))) bfd_nullvoidptr) | |
244 | #define ptrace_unix_bfd_make_debug_symbol \ | |
245 | ((asymbol *(*) PARAMS ((bfd *, void *, unsigned long))) bfd_nullvoidptr) | |
246 | #define ptrace_unix_bfd_link_hash_table_create \ | |
247 | ((struct bfd_link_hash_table *(*) PARAMS ((bfd *))) bfd_nullvoidptr) | |
248 | #define ptrace_unix_bfd_link_add_symbols \ | |
249 | ((boolean (*) PARAMS ((bfd *, struct bfd_link_info *))) bfd_false) | |
250 | #define ptrace_unix_bfd_final_link \ | |
251 | ((boolean (*) PARAMS ((bfd *, struct bfd_link_info *))) bfd_false) | |
252 | ||
253 | /* If somebody calls any byte-swapping routines, shoot them. */ | |
254 | void | |
255 | swap_abort() | |
256 | { | |
257 | abort(); /* This way doesn't require any declaration for ANSI to fuck up */ | |
258 | } | |
259 | #define NO_GET ((bfd_vma (*) PARAMS (( bfd_byte *))) swap_abort ) | |
260 | #define NO_PUT ((void (*) PARAMS ((bfd_vma, bfd_byte *))) swap_abort ) | |
261 | #define NO_SIGNED_GET ((bfd_signed_vma (*) PARAMS ((bfd_byte *))) swap_abort ) | |
262 | ||
263 | bfd_target ptrace_core_vec = | |
264 | { | |
265 | "trad-core", | |
266 | bfd_target_unknown_flavour, | |
267 | true, /* target byte order */ | |
268 | true, /* target headers byte order */ | |
269 | (HAS_RELOC | EXEC_P | /* object flags */ | |
270 | HAS_LINENO | HAS_DEBUG | | |
271 | HAS_SYMS | HAS_LOCALS | WP_TEXT | D_PAGED), | |
272 | (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */ | |
273 | 0, /* symbol prefix */ | |
274 | ' ', /* ar_pad_char */ | |
275 | 16, /* ar_max_namelen */ | |
276 | 3, /* minimum alignment power */ | |
277 | NO_GET, NO_SIGNED_GET, NO_PUT, /* 64 bit data */ | |
278 | NO_GET, NO_SIGNED_GET, NO_PUT, /* 32 bit data */ | |
279 | NO_GET, NO_SIGNED_GET, NO_PUT, /* 16 bit data */ | |
280 | NO_GET, NO_SIGNED_GET, NO_PUT, /* 64 bit hdrs */ | |
281 | NO_GET, NO_SIGNED_GET, NO_PUT, /* 32 bit hdrs */ | |
282 | NO_GET, NO_SIGNED_GET, NO_PUT, /* 16 bit hdrs */ | |
283 | ||
284 | { /* bfd_check_format */ | |
285 | _bfd_dummy_target, /* unknown format */ | |
286 | _bfd_dummy_target, /* object file */ | |
287 | _bfd_dummy_target, /* archive */ | |
288 | ptrace_unix_core_file_p /* a core file */ | |
289 | }, | |
290 | { /* bfd_set_format */ | |
291 | bfd_false, bfd_false, | |
292 | bfd_false, bfd_false | |
293 | }, | |
294 | { /* bfd_write_contents */ | |
295 | bfd_false, bfd_false, | |
296 | bfd_false, bfd_false | |
297 | }, | |
298 | ||
299 | JUMP_TABLE(ptrace_unix), | |
300 | (PTR) 0 /* backend_data */ | |
301 | }; | |
302 | ||
303 | #endif /* PTRACE_CORE */ |