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