* breakpoint.c, breakpoint.h (breakpoint_init_inferior): New function
[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"
dd3b648e 33
dd3b648e
RP
34extern char registers[];
35
36/* Hook for `exec_file_command' command to call. */
37
7ed0f002 38void (*exec_file_display_hook) PARAMS ((char *)) = NULL;
dd3b648e 39
dd3b648e
RP
40/* Binary file diddling handle for the core file. */
41
42bfd *core_bfd = NULL;
43
dd3b648e 44\f
dd3b648e
RP
45/* Backward compatability with old way of specifying core files. */
46
47void
48core_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
70void
71specify_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
81void
82close_exec_file ()
83{
84#ifdef FIXME
85 if (exec_bfd)
86 bfd_tempclose (exec_bfd);
87#endif
88}
89
90void
91reopen_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
102void
103validate_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
118char *
119get_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\
126Use 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
133void
134memory_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. */
5573d7d4
JK
143 error ("Cannot access memory at address %s.",
144 local_hex_string((unsigned long) memaddr));
dd3b648e
RP
145 }
146 else
147 {
4ace50a5 148 error ("Error accessing memory address %s: %s.",
5573d7d4
JK
149 local_hex_string ((unsigned long) memaddr),
150 safe_strerror (status));
dd3b648e
RP
151 }
152}
153
154/* Same as target_read_memory, but report an error if can't read. */
155void
156read_memory (memaddr, myaddr, len)
157 CORE_ADDR memaddr;
158 char *myaddr;
159 int len;
160{
161 int status;
162 status = target_read_memory (memaddr, myaddr, len);
163 if (status != 0)
164 memory_error (status, memaddr);
165}
166
720b3aed 167/* Like target_read_memory, but slightly different parameters. */
bf097a0b 168
5d0734a7 169int
a6cead71 170dis_asm_read_memory (memaddr, myaddr, len, info)
5d0734a7
JK
171 bfd_vma memaddr;
172 bfd_byte *myaddr;
173 int len;
a6cead71 174 disassemble_info *info;
5d0734a7 175{
34b70237 176 return target_read_memory (memaddr, (char *) myaddr, len);
5d0734a7
JK
177}
178
179/* Like memory_error with slightly different parameters. */
180void
181dis_asm_memory_error (status, memaddr, info)
182 int status;
183 bfd_vma memaddr;
184 disassemble_info *info;
185{
186 memory_error (status, memaddr);
187}
188
720b3aed
JK
189/* Like print_address with slightly different parameters. */
190void
191dis_asm_print_address (addr, info)
192 bfd_vma addr;
193 struct disassemble_info *info;
194{
195 print_address (addr, info->stream);
196}
197
dd3b648e
RP
198/* Same as target_write_memory, but report an error if can't write. */
199void
200write_memory (memaddr, myaddr, len)
201 CORE_ADDR memaddr;
202 char *myaddr;
203 int len;
204{
205 int status;
206
207 status = target_write_memory (memaddr, myaddr, len);
208 if (status != 0)
209 memory_error (status, memaddr);
210}
211
212/* Read an integer from debugged memory, given address and number of bytes. */
213
34df79fc 214LONGEST
dd3b648e
RP
215read_memory_integer (memaddr, len)
216 CORE_ADDR memaddr;
217 int len;
218{
58e49e21 219 char buf[sizeof (LONGEST)];
dd3b648e 220
34df79fc
JK
221 read_memory (memaddr, buf, len);
222 return extract_signed_integer (buf, len);
dd3b648e 223}
86a5593e 224
34df79fc 225unsigned LONGEST
86a5593e
SC
226read_memory_unsigned_integer (memaddr, len)
227 CORE_ADDR memaddr;
228 int len;
229{
58e49e21 230 char buf[sizeof (unsigned LONGEST)];
86a5593e 231
34df79fc
JK
232 read_memory (memaddr, buf, len);
233 return extract_unsigned_integer (buf, len);
86a5593e 234}
dd3b648e 235\f
0685d95f
JK
236/* The current default bfd target. Points to storage allocated for
237 gnutarget_string. */
238char *gnutarget;
239
240/* Same thing, except it is "auto" not NULL for the default case. */
241static char *gnutarget_string;
242
243static void set_gnutarget_command
244 PARAMS ((char *, int, struct cmd_list_element *));
245
246static void
247set_gnutarget_command (ignore, from_tty, c)
248 char *ignore;
249 int from_tty;
250 struct cmd_list_element *c;
251{
252 if (STREQ (gnutarget_string, "auto"))
253 gnutarget = NULL;
254 else
255 gnutarget = gnutarget_string;
256}
257
258/* Set the gnutarget. */
259void
260set_gnutarget (newtarget)
261 char *newtarget;
262{
263 if (gnutarget_string != NULL)
264 free (gnutarget_string);
265 gnutarget_string = savestring (newtarget, strlen (newtarget));
266 set_gnutarget_command (NULL, 0, NULL);
267}
268
dd3b648e
RP
269void
270_initialize_core()
271{
df0f0dcc
JK
272 struct cmd_list_element *c;
273 c = add_cmd ("core-file", class_files, core_file_command,
274 "Use FILE as core dump for examining memory and registers.\n\
dd3b648e 275No arg means have no core file. This command has been superseded by the\n\
df0f0dcc
JK
276`target core' and `detach' commands.", &cmdlist);
277 c->completer = filename_completer;
0685d95f
JK
278
279 c = add_set_cmd ("gnutarget", class_files, var_string_noescape,
280 (char *) &gnutarget_string,
281 "Set the current BFD target.\n\
282Use `set gnutarget auto' to specify automatic detection.",
283 &setlist);
284 c->function.sfunc = set_gnutarget_command;
285 add_show_from_set (c, &showlist);
286
287 if (getenv ("GNUTARGET"))
288 set_gnutarget (getenv ("GNUTARGET"));
289 else
290 set_gnutarget ("auto");
dd3b648e 291}
This page took 0.120759 seconds and 4 git commands to generate.