]>
Commit | Line | Data |
---|---|---|
8afd6ca5 | 1 | /* Core dump and executable file functions above target vector, for GDB. |
ba47c66a PS |
2 | Copyright 1986, 1987, 1989, 1991, 1992, 1993, 1994 |
3 | Free Software Foundation, Inc. | |
dd3b648e RP |
4 | |
5 | This file is part of GDB. | |
6 | ||
99a7de40 | 7 | This program is free software; you can redistribute it and/or modify |
dd3b648e | 8 | it under the terms of the GNU General Public License as published by |
99a7de40 JG |
9 | the Free Software Foundation; either version 2 of the License, or |
10 | (at your option) any later version. | |
dd3b648e | 11 | |
99a7de40 | 12 | This program is distributed in the hope that it will be useful, |
dd3b648e RP |
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. | |
16 | ||
17 | You should have received a copy of the GNU General Public License | |
99a7de40 JG |
18 | along with this program; if not, write to the Free Software |
19 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ | |
dd3b648e | 20 | |
d747e0af | 21 | #include "defs.h" |
ba47c66a | 22 | #include <string.h> |
dd3b648e RP |
23 | #include <errno.h> |
24 | #include <signal.h> | |
bdbd5f50 | 25 | #include <fcntl.h> |
dd3b648e RP |
26 | #include "frame.h" /* required by inferior.h */ |
27 | #include "inferior.h" | |
28 | #include "symtab.h" | |
29 | #include "command.h" | |
df0f0dcc | 30 | #include "gdbcmd.h" |
dd3b648e RP |
31 | #include "bfd.h" |
32 | #include "target.h" | |
33 | #include "gdbcore.h" | |
5d0734a7 | 34 | #include "dis-asm.h" |
100f92e2 | 35 | #include "language.h" |
dd3b648e | 36 | |
dd3b648e RP |
37 | extern char registers[]; |
38 | ||
39 | /* Hook for `exec_file_command' command to call. */ | |
40 | ||
7ed0f002 | 41 | void (*exec_file_display_hook) PARAMS ((char *)) = NULL; |
dd3b648e | 42 | |
dd3b648e RP |
43 | /* Binary file diddling handle for the core file. */ |
44 | ||
45 | bfd *core_bfd = NULL; | |
46 | ||
dd3b648e | 47 | \f |
dd3b648e RP |
48 | /* Backward compatability with old way of specifying core files. */ |
49 | ||
50 | void | |
51 | core_file_command (filename, from_tty) | |
52 | char *filename; | |
53 | int from_tty; | |
54 | { | |
df9b3bfc | 55 | struct target_ops *t; |
327f7197 | 56 | |
3f2e006b | 57 | dont_repeat (); /* Either way, seems bogus. */ |
8afd6ca5 | 58 | |
df9b3bfc RP |
59 | t = find_core_target (); |
60 | if (t != NULL) | |
61 | if (!filename) | |
62 | (t->to_detach) (filename, from_tty); | |
63 | else | |
64 | (t->to_open) (filename, from_tty); | |
dd3b648e | 65 | else |
327f7197 | 66 | error ("GDB can't read core files on this machine."); |
dd3b648e RP |
67 | } |
68 | ||
69 | \f | |
70 | /* Call this to specify the hook for exec_file_command to call back. | |
71 | This is called from the x-window display code. */ | |
72 | ||
73 | void | |
74 | specify_exec_file_hook (hook) | |
7ed0f002 | 75 | void (*hook) PARAMS ((char *)); |
dd3b648e RP |
76 | { |
77 | exec_file_display_hook = hook; | |
78 | } | |
79 | ||
80 | /* The exec file must be closed before running an inferior. | |
81 | If it is needed again after the inferior dies, it must | |
82 | be reopened. */ | |
83 | ||
84 | void | |
85 | close_exec_file () | |
86 | { | |
87 | #ifdef FIXME | |
88 | if (exec_bfd) | |
89 | bfd_tempclose (exec_bfd); | |
90 | #endif | |
91 | } | |
92 | ||
93 | void | |
94 | reopen_exec_file () | |
95 | { | |
96 | #ifdef FIXME | |
97 | if (exec_bfd) | |
98 | bfd_reopen (exec_bfd); | |
99 | #endif | |
100 | } | |
101 | \f | |
102 | /* If we have both a core file and an exec file, | |
c561ca5d | 103 | print a warning if they don't go together. */ |
dd3b648e RP |
104 | |
105 | void | |
106 | validate_files () | |
107 | { | |
108 | if (exec_bfd && core_bfd) | |
109 | { | |
bdbd5f50 | 110 | if (!core_file_matches_executable_p (core_bfd, exec_bfd)) |
c8094777 | 111 | warning ("core file may not match specified executable file."); |
dd3b648e | 112 | else if (bfd_get_mtime(exec_bfd) > bfd_get_mtime(core_bfd)) |
c8094777 | 113 | warning ("exec file is newer than core file."); |
dd3b648e RP |
114 | } |
115 | } | |
116 | ||
117 | /* Return the name of the executable file as a string. | |
118 | ERR nonzero means get error if there is none specified; | |
119 | otherwise return 0 in that case. */ | |
120 | ||
121 | char * | |
122 | get_exec_file (err) | |
123 | int err; | |
124 | { | |
125 | if (exec_bfd) return bfd_get_filename(exec_bfd); | |
126 | if (!err) return NULL; | |
127 | ||
128 | error ("No executable file specified.\n\ | |
129 | Use the \"file\" or \"exec-file\" command."); | |
130 | return NULL; | |
131 | } | |
132 | ||
dd3b648e | 133 | \f |
7ed0f002 JG |
134 | /* Report a memory error with error(). */ |
135 | ||
dd3b648e RP |
136 | void |
137 | memory_error (status, memaddr) | |
138 | int status; | |
139 | CORE_ADDR memaddr; | |
140 | { | |
833e0d94 | 141 | /* FIXME-32x64--casting CORE_ADDR to unsigned long */ |
dd3b648e RP |
142 | if (status == EIO) |
143 | { | |
144 | /* Actually, address between memaddr and memaddr + len | |
145 | was out of bounds. */ | |
5573d7d4 JK |
146 | error ("Cannot access memory at address %s.", |
147 | local_hex_string((unsigned long) memaddr)); | |
dd3b648e RP |
148 | } |
149 | else | |
150 | { | |
4ace50a5 | 151 | error ("Error accessing memory address %s: %s.", |
5573d7d4 JK |
152 | local_hex_string ((unsigned long) memaddr), |
153 | safe_strerror (status)); | |
dd3b648e RP |
154 | } |
155 | } | |
156 | ||
157 | /* Same as target_read_memory, but report an error if can't read. */ | |
158 | void | |
159 | read_memory (memaddr, myaddr, len) | |
160 | CORE_ADDR memaddr; | |
161 | char *myaddr; | |
162 | int len; | |
163 | { | |
164 | int status; | |
165 | status = target_read_memory (memaddr, myaddr, len); | |
166 | if (status != 0) | |
167 | memory_error (status, memaddr); | |
168 | } | |
169 | ||
720b3aed | 170 | /* Like target_read_memory, but slightly different parameters. */ |
bf097a0b | 171 | |
5d0734a7 | 172 | int |
a6cead71 | 173 | dis_asm_read_memory (memaddr, myaddr, len, info) |
5d0734a7 JK |
174 | bfd_vma memaddr; |
175 | bfd_byte *myaddr; | |
176 | int len; | |
a6cead71 | 177 | disassemble_info *info; |
5d0734a7 | 178 | { |
34b70237 | 179 | return target_read_memory (memaddr, (char *) myaddr, len); |
5d0734a7 JK |
180 | } |
181 | ||
182 | /* Like memory_error with slightly different parameters. */ | |
183 | void | |
184 | dis_asm_memory_error (status, memaddr, info) | |
185 | int status; | |
186 | bfd_vma memaddr; | |
187 | disassemble_info *info; | |
188 | { | |
189 | memory_error (status, memaddr); | |
190 | } | |
191 | ||
720b3aed JK |
192 | /* Like print_address with slightly different parameters. */ |
193 | void | |
194 | dis_asm_print_address (addr, info) | |
195 | bfd_vma addr; | |
196 | struct disassemble_info *info; | |
197 | { | |
198 | print_address (addr, info->stream); | |
199 | } | |
200 | ||
dd3b648e RP |
201 | /* Same as target_write_memory, but report an error if can't write. */ |
202 | void | |
203 | write_memory (memaddr, myaddr, len) | |
204 | CORE_ADDR memaddr; | |
205 | char *myaddr; | |
206 | int len; | |
207 | { | |
208 | int status; | |
209 | ||
210 | status = target_write_memory (memaddr, myaddr, len); | |
211 | if (status != 0) | |
212 | memory_error (status, memaddr); | |
213 | } | |
214 | ||
215 | /* Read an integer from debugged memory, given address and number of bytes. */ | |
216 | ||
34df79fc | 217 | LONGEST |
dd3b648e RP |
218 | read_memory_integer (memaddr, len) |
219 | CORE_ADDR memaddr; | |
220 | int len; | |
221 | { | |
58e49e21 | 222 | char buf[sizeof (LONGEST)]; |
dd3b648e | 223 | |
34df79fc JK |
224 | read_memory (memaddr, buf, len); |
225 | return extract_signed_integer (buf, len); | |
dd3b648e | 226 | } |
86a5593e | 227 | |
34df79fc | 228 | unsigned LONGEST |
86a5593e SC |
229 | read_memory_unsigned_integer (memaddr, len) |
230 | CORE_ADDR memaddr; | |
231 | int len; | |
232 | { | |
58e49e21 | 233 | char buf[sizeof (unsigned LONGEST)]; |
86a5593e | 234 | |
34df79fc JK |
235 | read_memory (memaddr, buf, len); |
236 | return extract_unsigned_integer (buf, len); | |
86a5593e | 237 | } |
dd3b648e | 238 | \f |
63dcc380 JK |
239 | #if 0 |
240 | /* Enable after 4.12. It is not tested. */ | |
241 | ||
242 | /* Search code. Targets can just make this their search function, or | |
243 | if the protocol has a less general search function, they can call this | |
244 | in the cases it can't handle. */ | |
245 | void | |
246 | generic_search (len, data, mask, startaddr, increment, lorange, hirange | |
247 | addr_found, data_found) | |
248 | int len; | |
249 | char *data; | |
250 | char *mask; | |
251 | CORE_ADDR startaddr; | |
252 | int increment; | |
253 | CORE_ADDR lorange; | |
254 | CORE_ADDR hirange; | |
255 | CORE_ADDR *addr_found; | |
256 | char *data_found; | |
257 | { | |
258 | int i; | |
259 | CORE_ADDR curaddr = startaddr; | |
260 | ||
261 | while (curaddr >= lorange && curaddr < hirange) | |
262 | { | |
263 | read_memory (curaddr, data_found, len); | |
264 | for (i = 0; i < len; ++i) | |
265 | if ((data_found[i] & mask[i]) != data[i]) | |
266 | goto try_again; | |
267 | /* It matches. */ | |
268 | *addr_found = curaddr; | |
269 | return; | |
270 | ||
271 | try_again: | |
272 | curaddr += increment; | |
273 | } | |
274 | *addr_found = (CORE_ADDR)0; | |
275 | return; | |
276 | } | |
277 | #endif /* 0 */ | |
278 | \f | |
0685d95f JK |
279 | /* The current default bfd target. Points to storage allocated for |
280 | gnutarget_string. */ | |
281 | char *gnutarget; | |
282 | ||
283 | /* Same thing, except it is "auto" not NULL for the default case. */ | |
284 | static char *gnutarget_string; | |
285 | ||
286 | static void set_gnutarget_command | |
287 | PARAMS ((char *, int, struct cmd_list_element *)); | |
288 | ||
289 | static void | |
290 | set_gnutarget_command (ignore, from_tty, c) | |
291 | char *ignore; | |
292 | int from_tty; | |
293 | struct cmd_list_element *c; | |
294 | { | |
295 | if (STREQ (gnutarget_string, "auto")) | |
296 | gnutarget = NULL; | |
297 | else | |
298 | gnutarget = gnutarget_string; | |
299 | } | |
300 | ||
301 | /* Set the gnutarget. */ | |
302 | void | |
303 | set_gnutarget (newtarget) | |
304 | char *newtarget; | |
305 | { | |
306 | if (gnutarget_string != NULL) | |
307 | free (gnutarget_string); | |
308 | gnutarget_string = savestring (newtarget, strlen (newtarget)); | |
309 | set_gnutarget_command (NULL, 0, NULL); | |
310 | } | |
311 | ||
dd3b648e RP |
312 | void |
313 | _initialize_core() | |
314 | { | |
df0f0dcc JK |
315 | struct cmd_list_element *c; |
316 | c = add_cmd ("core-file", class_files, core_file_command, | |
317 | "Use FILE as core dump for examining memory and registers.\n\ | |
dd3b648e | 318 | No arg means have no core file. This command has been superseded by the\n\ |
df0f0dcc JK |
319 | `target core' and `detach' commands.", &cmdlist); |
320 | c->completer = filename_completer; | |
0685d95f JK |
321 | |
322 | c = add_set_cmd ("gnutarget", class_files, var_string_noescape, | |
323 | (char *) &gnutarget_string, | |
324 | "Set the current BFD target.\n\ | |
325 | Use `set gnutarget auto' to specify automatic detection.", | |
326 | &setlist); | |
327 | c->function.sfunc = set_gnutarget_command; | |
328 | add_show_from_set (c, &showlist); | |
329 | ||
330 | if (getenv ("GNUTARGET")) | |
331 | set_gnutarget (getenv ("GNUTARGET")); | |
332 | else | |
333 | set_gnutarget ("auto"); | |
dd3b648e | 334 | } |