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