]>
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" | |
28 | #include "bfd.h" | |
29 | #include "target.h" | |
30 | #include "gdbcore.h" | |
5d0734a7 | 31 | #include "dis-asm.h" |
dd3b648e | 32 | |
dd3b648e RP |
33 | extern char registers[]; |
34 | ||
35 | /* Hook for `exec_file_command' command to call. */ | |
36 | ||
7ed0f002 | 37 | void (*exec_file_display_hook) PARAMS ((char *)) = NULL; |
dd3b648e | 38 | |
dd3b648e RP |
39 | /* Binary file diddling handle for the core file. */ |
40 | ||
41 | bfd *core_bfd = NULL; | |
42 | ||
dd3b648e | 43 | \f |
dd3b648e RP |
44 | /* Backward compatability with old way of specifying core files. */ |
45 | ||
46 | void | |
47 | core_file_command (filename, from_tty) | |
48 | char *filename; | |
49 | int from_tty; | |
50 | { | |
df9b3bfc | 51 | struct target_ops *t; |
327f7197 | 52 | |
3f2e006b | 53 | dont_repeat (); /* Either way, seems bogus. */ |
8afd6ca5 | 54 | |
df9b3bfc RP |
55 | t = find_core_target (); |
56 | if (t != NULL) | |
57 | if (!filename) | |
58 | (t->to_detach) (filename, from_tty); | |
59 | else | |
60 | (t->to_open) (filename, from_tty); | |
dd3b648e | 61 | else |
327f7197 | 62 | error ("GDB can't read core files on this machine."); |
dd3b648e RP |
63 | } |
64 | ||
65 | \f | |
66 | /* Call this to specify the hook for exec_file_command to call back. | |
67 | This is called from the x-window display code. */ | |
68 | ||
69 | void | |
70 | specify_exec_file_hook (hook) | |
7ed0f002 | 71 | void (*hook) PARAMS ((char *)); |
dd3b648e RP |
72 | { |
73 | exec_file_display_hook = hook; | |
74 | } | |
75 | ||
76 | /* The exec file must be closed before running an inferior. | |
77 | If it is needed again after the inferior dies, it must | |
78 | be reopened. */ | |
79 | ||
80 | void | |
81 | close_exec_file () | |
82 | { | |
83 | #ifdef FIXME | |
84 | if (exec_bfd) | |
85 | bfd_tempclose (exec_bfd); | |
86 | #endif | |
87 | } | |
88 | ||
89 | void | |
90 | reopen_exec_file () | |
91 | { | |
92 | #ifdef FIXME | |
93 | if (exec_bfd) | |
94 | bfd_reopen (exec_bfd); | |
95 | #endif | |
96 | } | |
97 | \f | |
98 | /* If we have both a core file and an exec file, | |
c561ca5d | 99 | print a warning if they don't go together. */ |
dd3b648e RP |
100 | |
101 | void | |
102 | validate_files () | |
103 | { | |
104 | if (exec_bfd && core_bfd) | |
105 | { | |
bdbd5f50 | 106 | if (!core_file_matches_executable_p (core_bfd, exec_bfd)) |
c8094777 | 107 | warning ("core file may not match specified executable file."); |
dd3b648e | 108 | else if (bfd_get_mtime(exec_bfd) > bfd_get_mtime(core_bfd)) |
c8094777 | 109 | warning ("exec file is newer than core file."); |
dd3b648e RP |
110 | } |
111 | } | |
112 | ||
113 | /* Return the name of the executable file as a string. | |
114 | ERR nonzero means get error if there is none specified; | |
115 | otherwise return 0 in that case. */ | |
116 | ||
117 | char * | |
118 | get_exec_file (err) | |
119 | int err; | |
120 | { | |
121 | if (exec_bfd) return bfd_get_filename(exec_bfd); | |
122 | if (!err) return NULL; | |
123 | ||
124 | error ("No executable file specified.\n\ | |
125 | Use the \"file\" or \"exec-file\" command."); | |
126 | return NULL; | |
127 | } | |
128 | ||
dd3b648e | 129 | \f |
7ed0f002 JG |
130 | /* Report a memory error with error(). */ |
131 | ||
dd3b648e RP |
132 | void |
133 | memory_error (status, memaddr) | |
134 | int status; | |
135 | CORE_ADDR memaddr; | |
136 | { | |
137 | ||
138 | if (status == EIO) | |
139 | { | |
140 | /* Actually, address between memaddr and memaddr + len | |
141 | was out of bounds. */ | |
ec99961f | 142 | error ("Cannot access memory at address %s.", local_hex_string(memaddr)); |
dd3b648e RP |
143 | } |
144 | else | |
145 | { | |
4ace50a5 FF |
146 | error ("Error accessing memory address %s: %s.", |
147 | local_hex_string (memaddr), safe_strerror (status)); | |
dd3b648e RP |
148 | } |
149 | } | |
150 | ||
151 | /* Same as target_read_memory, but report an error if can't read. */ | |
152 | void | |
153 | read_memory (memaddr, myaddr, len) | |
154 | CORE_ADDR memaddr; | |
155 | char *myaddr; | |
156 | int len; | |
157 | { | |
158 | int status; | |
159 | status = target_read_memory (memaddr, myaddr, len); | |
160 | if (status != 0) | |
161 | memory_error (status, memaddr); | |
162 | } | |
163 | ||
720b3aed | 164 | /* Like target_read_memory, but slightly different parameters. */ |
bf097a0b | 165 | |
5d0734a7 | 166 | int |
a6cead71 | 167 | dis_asm_read_memory (memaddr, myaddr, len, info) |
5d0734a7 JK |
168 | bfd_vma memaddr; |
169 | bfd_byte *myaddr; | |
170 | int len; | |
a6cead71 | 171 | disassemble_info *info; |
5d0734a7 JK |
172 | { |
173 | return target_read_memory (memaddr, myaddr, len); | |
174 | } | |
175 | ||
176 | /* Like memory_error with slightly different parameters. */ | |
177 | void | |
178 | dis_asm_memory_error (status, memaddr, info) | |
179 | int status; | |
180 | bfd_vma memaddr; | |
181 | disassemble_info *info; | |
182 | { | |
183 | memory_error (status, memaddr); | |
184 | } | |
185 | ||
720b3aed JK |
186 | /* Like print_address with slightly different parameters. */ |
187 | void | |
188 | dis_asm_print_address (addr, info) | |
189 | bfd_vma addr; | |
190 | struct disassemble_info *info; | |
191 | { | |
192 | print_address (addr, info->stream); | |
193 | } | |
194 | ||
dd3b648e RP |
195 | /* Same as target_write_memory, but report an error if can't write. */ |
196 | void | |
197 | write_memory (memaddr, myaddr, len) | |
198 | CORE_ADDR memaddr; | |
199 | char *myaddr; | |
200 | int len; | |
201 | { | |
202 | int status; | |
203 | ||
204 | status = target_write_memory (memaddr, myaddr, len); | |
205 | if (status != 0) | |
206 | memory_error (status, memaddr); | |
207 | } | |
208 | ||
209 | /* Read an integer from debugged memory, given address and number of bytes. */ | |
210 | ||
211 | long | |
212 | read_memory_integer (memaddr, len) | |
213 | CORE_ADDR memaddr; | |
214 | int len; | |
215 | { | |
216 | char cbuf; | |
217 | short sbuf; | |
218 | int ibuf; | |
219 | long lbuf; | |
220 | ||
221 | if (len == sizeof (char)) | |
222 | { | |
223 | read_memory (memaddr, &cbuf, len); | |
224 | return cbuf; | |
225 | } | |
226 | if (len == sizeof (short)) | |
227 | { | |
228 | read_memory (memaddr, (char *)&sbuf, len); | |
229 | SWAP_TARGET_AND_HOST (&sbuf, sizeof (short)); | |
230 | return sbuf; | |
231 | } | |
232 | if (len == sizeof (int)) | |
233 | { | |
234 | read_memory (memaddr, (char *)&ibuf, len); | |
235 | SWAP_TARGET_AND_HOST (&ibuf, sizeof (int)); | |
236 | return ibuf; | |
237 | } | |
238 | if (len == sizeof (lbuf)) | |
239 | { | |
240 | read_memory (memaddr, (char *)&lbuf, len); | |
241 | SWAP_TARGET_AND_HOST (&lbuf, sizeof (lbuf)); | |
242 | return lbuf; | |
243 | } | |
244 | error ("Cannot handle integers of %d bytes.", len); | |
245 | return -1; /* for lint */ | |
246 | } | |
247 | \f | |
dd3b648e RP |
248 | void |
249 | _initialize_core() | |
250 | { | |
251 | ||
252 | add_com ("core-file", class_files, core_file_command, | |
253 | "Use FILE as core dump for examining memory and registers.\n\ | |
254 | No arg means have no core file. This command has been superseded by the\n\ | |
255 | `target core' and `detach' commands."); | |
8afd6ca5 | 256 | |
dd3b648e | 257 | } |