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