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