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