]>
Commit | Line | Data |
---|---|---|
252b5132 | 1 | /* BFD backend for core files which use the ptrace_user structure |
3db64b00 AM |
2 | Copyright 1993, 1994, 1995, 1996, 1998, 1999, 2001, 2002, 2003, 2004, |
3 | 2006, 2007 Free Software Foundation, Inc. | |
252b5132 RH |
4 | The structure of this file is based on trad-core.c written by John Gilmore |
5 | of Cygnus Support. | |
6 | Modified to work with the ptrace_user structure by Kevin A. Buettner. | |
7 | (Longterm it may be better to merge this file with trad-core.c) | |
8 | ||
cd123cb7 NC |
9 | This file is part of BFD, the Binary File Descriptor library. |
10 | ||
11 | This program is free software; you can redistribute it and/or modify | |
12 | it under the terms of the GNU General Public License as published by | |
13 | the Free Software Foundation; either version 3 of the License, or | |
14 | (at your option) any later version. | |
15 | ||
16 | This program is distributed in the hope that it will be useful, | |
17 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 | GNU General Public License for more details. | |
20 | ||
21 | You should have received a copy of the GNU General Public License | |
22 | along with this program; if not, write to the Free Software | |
23 | Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, | |
24 | MA 02110-1301, USA. */ | |
252b5132 RH |
25 | |
26 | #ifdef PTRACE_CORE | |
27 | ||
252b5132 | 28 | #include "sysdep.h" |
3db64b00 | 29 | #include "bfd.h" |
252b5132 RH |
30 | #include "libbfd.h" |
31 | ||
32 | #include <sys/param.h> | |
33 | #include <sys/dir.h> | |
34 | #include <signal.h> | |
35 | #include <sys/ptrace.h> | |
36 | ||
252b5132 RH |
37 | struct trad_core_struct |
38 | { | |
39 | asection *data_section; | |
40 | asection *stack_section; | |
41 | asection *reg_section; | |
42 | struct ptrace_user u; | |
43 | }; | |
44 | ||
45 | #define core_upage(bfd) (&((bfd)->tdata.trad_core_data->u)) | |
46 | #define core_datasec(bfd) ((bfd)->tdata.trad_core_data->data_section) | |
47 | #define core_stacksec(bfd) ((bfd)->tdata.trad_core_data->stack_section) | |
48 | #define core_regsec(bfd) ((bfd)->tdata.trad_core_data->reg_section) | |
49 | ||
50 | /* forward declarations */ | |
51 | ||
52 | const bfd_target *ptrace_unix_core_file_p PARAMS ((bfd *abfd)); | |
b34976b6 AM |
53 | char * ptrace_unix_core_file_failing_command PARAMS ((bfd *abfd)); |
54 | int ptrace_unix_core_file_failing_signal PARAMS ((bfd *abfd)); | |
69d246d9 | 55 | #define ptrace_unix_core_file_matches_executable_p generic_core_file_matches_executable_p |
b34976b6 | 56 | static void swap_abort PARAMS ((void)); |
252b5132 | 57 | |
252b5132 RH |
58 | const bfd_target * |
59 | ptrace_unix_core_file_p (abfd) | |
60 | bfd *abfd; | |
61 | ||
62 | { | |
63 | int val; | |
64 | struct ptrace_user u; | |
65 | struct trad_core_struct *rawptr; | |
dc810e39 | 66 | bfd_size_type amt; |
117ed4f8 | 67 | flagword flags; |
252b5132 | 68 | |
dc810e39 | 69 | val = bfd_bread ((void *)&u, (bfd_size_type) sizeof u, abfd); |
892339ee | 70 | if (val != sizeof u || u.pt_magic != _BCS_PTRACE_MAGIC |
252b5132 RH |
71 | || u.pt_rev != _BCS_PTRACE_REV) |
72 | { | |
73 | /* Too small to be a core file */ | |
74 | bfd_set_error (bfd_error_wrong_format); | |
75 | return 0; | |
76 | } | |
77 | ||
78 | /* OK, we believe you. You're a core file (sure, sure). */ | |
79 | ||
80 | /* Allocate both the upage and the struct core_data at once, so | |
81 | a single free() will free them both. */ | |
dc810e39 AM |
82 | amt = sizeof (struct trad_core_struct); |
83 | rawptr = (struct trad_core_struct *) bfd_zalloc (abfd, amt); | |
252b5132 RH |
84 | |
85 | if (rawptr == NULL) | |
86 | return 0; | |
892339ee | 87 | |
252b5132 RH |
88 | abfd->tdata.trad_core_data = rawptr; |
89 | ||
90 | rawptr->u = u; /*Copy the uarea into the tdata part of the bfd */ | |
91 | ||
9e7b37b3 | 92 | /* Create the sections. */ |
252b5132 | 93 | |
117ed4f8 AM |
94 | flags = SEC_ALLOC + SEC_LOAD + SEC_HAS_CONTENTS; |
95 | core_stacksec (abfd) = bfd_make_section_anyway_with_flags (abfd, ".stack", | |
96 | flags); | |
252b5132 | 97 | if (core_stacksec (abfd) == NULL) |
9e7b37b3 | 98 | goto fail; |
117ed4f8 AM |
99 | core_datasec (abfd) = bfd_make_section_anyway_with_flags (abfd, ".data", |
100 | flags); | |
252b5132 | 101 | if (core_datasec (abfd) == NULL) |
9e7b37b3 | 102 | goto fail; |
117ed4f8 AM |
103 | core_regsec (abfd) = bfd_make_section_anyway_with_flags (abfd, ".reg", |
104 | SEC_HAS_CONTENTS); | |
252b5132 | 105 | if (core_regsec (abfd) == NULL) |
9e7b37b3 | 106 | goto fail; |
252b5132 RH |
107 | |
108 | /* FIXME: Need to worry about shared memory, library data, and library | |
109 | text. I don't think that any of these things are supported on the | |
892339ee | 110 | system on which I am developing this for though. */ |
252b5132 | 111 | |
eea6121a AM |
112 | core_datasec (abfd)->size = u.pt_dsize; |
113 | core_stacksec (abfd)->size = u.pt_ssize; | |
114 | core_regsec (abfd)->size = sizeof (u); | |
252b5132 RH |
115 | |
116 | core_datasec (abfd)->vma = u.pt_o_data_start; | |
117 | core_stacksec (abfd)->vma = USRSTACK - u.pt_ssize; | |
892339ee | 118 | core_regsec (abfd)->vma = 0 - sizeof (u); /* see trad-core.c */ |
252b5132 RH |
119 | |
120 | core_datasec (abfd)->filepos = (int) u.pt_dataptr; | |
121 | core_stacksec (abfd)->filepos = (int) (u.pt_dataptr + u.pt_dsize); | |
122 | core_regsec (abfd)->filepos = 0; /* Register segment is ptrace_user */ | |
123 | ||
124 | /* Align to word at least */ | |
125 | core_stacksec (abfd)->alignment_power = 2; | |
126 | core_datasec (abfd)->alignment_power = 2; | |
127 | core_regsec (abfd)->alignment_power = 2; | |
128 | ||
252b5132 | 129 | return abfd->xvec; |
9e7b37b3 AM |
130 | |
131 | fail: | |
132 | bfd_release (abfd, abfd->tdata.any); | |
133 | abfd->tdata.any = NULL; | |
134 | bfd_section_list_clear (abfd); | |
135 | return NULL; | |
252b5132 RH |
136 | } |
137 | ||
138 | char * | |
139 | ptrace_unix_core_file_failing_command (abfd) | |
140 | bfd *abfd; | |
141 | { | |
142 | char *com = abfd->tdata.trad_core_data->u.pt_comm; | |
143 | if (*com) | |
144 | return com; | |
145 | else | |
146 | return 0; | |
147 | } | |
148 | ||
252b5132 RH |
149 | int |
150 | ptrace_unix_core_file_failing_signal (abfd) | |
151 | bfd *abfd; | |
152 | { | |
153 | return abfd->tdata.trad_core_data->u.pt_sigframe.sig_num; | |
154 | } | |
252b5132 RH |
155 | \f |
156 | /* If somebody calls any byte-swapping routines, shoot them. */ | |
157 | static void | |
892339ee | 158 | swap_abort () |
252b5132 | 159 | { |
892339ee | 160 | abort (); /* This way doesn't require any declaration for ANSI to fuck up */ |
252b5132 | 161 | } |
8ce8c090 | 162 | |
edeb6e24 AM |
163 | #define NO_GET ((bfd_vma (*) (const void *)) swap_abort) |
164 | #define NO_PUT ((void (*) (bfd_vma, void *)) swap_abort) | |
165 | #define NO_GETS ((bfd_signed_vma (*) (const void *)) swap_abort) | |
8ce8c090 AM |
166 | #define NO_GET64 ((bfd_uint64_t (*) (const void *)) swap_abort) |
167 | #define NO_PUT64 ((void (*) (bfd_uint64_t, void *)) swap_abort) | |
168 | #define NO_GETS64 ((bfd_int64_t (*) (const void *)) swap_abort) | |
252b5132 RH |
169 | |
170 | const bfd_target ptrace_core_vec = | |
171 | { | |
172 | "trad-core", | |
173 | bfd_target_unknown_flavour, | |
174 | BFD_ENDIAN_UNKNOWN, /* target byte order */ | |
175 | BFD_ENDIAN_UNKNOWN, /* target headers byte order */ | |
176 | (HAS_RELOC | EXEC_P | /* object flags */ | |
177 | HAS_LINENO | HAS_DEBUG | | |
178 | HAS_SYMS | HAS_LOCALS | WP_TEXT | D_PAGED), | |
179 | (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */ | |
180 | 0, /* symbol prefix */ | |
181 | ' ', /* ar_pad_char */ | |
182 | 16, /* ar_max_namelen */ | |
8ce8c090 | 183 | NO_GET64, NO_GETS64, NO_PUT64, /* 64 bit data */ |
edeb6e24 AM |
184 | NO_GET, NO_GETS, NO_PUT, /* 32 bit data */ |
185 | NO_GET, NO_GETS, NO_PUT, /* 16 bit data */ | |
8ce8c090 | 186 | NO_GET64, NO_GETS64, NO_PUT64, /* 64 bit hdrs */ |
edeb6e24 AM |
187 | NO_GET, NO_GETS, NO_PUT, /* 32 bit hdrs */ |
188 | NO_GET, NO_GETS, NO_PUT, /* 16 bit hdrs */ | |
252b5132 RH |
189 | |
190 | { /* bfd_check_format */ | |
8ce8c090 AM |
191 | _bfd_dummy_target, /* unknown format */ |
192 | _bfd_dummy_target, /* object file */ | |
193 | _bfd_dummy_target, /* archive */ | |
194 | ptrace_unix_core_file_p /* a core file */ | |
252b5132 RH |
195 | }, |
196 | { /* bfd_set_format */ | |
8ce8c090 AM |
197 | bfd_false, bfd_false, |
198 | bfd_false, bfd_false | |
252b5132 RH |
199 | }, |
200 | { /* bfd_write_contents */ | |
8ce8c090 AM |
201 | bfd_false, bfd_false, |
202 | bfd_false, bfd_false | |
252b5132 | 203 | }, |
892339ee | 204 | |
8ce8c090 AM |
205 | BFD_JUMP_TABLE_GENERIC (_bfd_generic), |
206 | BFD_JUMP_TABLE_COPY (_bfd_generic), | |
207 | BFD_JUMP_TABLE_CORE (ptrace_unix), | |
208 | BFD_JUMP_TABLE_ARCHIVE (_bfd_noarchive), | |
209 | BFD_JUMP_TABLE_SYMBOLS (_bfd_nosymbols), | |
210 | BFD_JUMP_TABLE_RELOCS (_bfd_norelocs), | |
211 | BFD_JUMP_TABLE_WRITE (_bfd_generic), | |
212 | BFD_JUMP_TABLE_LINK (_bfd_nolink), | |
213 | BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic), | |
252b5132 | 214 | |
c3c89269 | 215 | NULL, |
892339ee | 216 | |
252b5132 | 217 | (PTR) 0 /* backend_data */ |
8ce8c090 | 218 | }; |
252b5132 RH |
219 | |
220 | #endif /* PTRACE_CORE */ |