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