1 /* Core dump and executable file functions above target vector, for GDB.
2 Copyright 1986, 1987, 1989, 1991, 1992 Free Software Foundation, Inc.
4 This file is part of GDB.
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.
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.
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. */
24 #include "frame.h" /* required by inferior.h */
32 extern char registers
[];
34 /* Hook for `exec_file_command' command to call. */
36 void (*exec_file_display_hook
) PARAMS ((char *)) = NULL
;
38 /* Binary file diddling handle for the core file. */
43 /* Backward compatability with old way of specifying core files. */
46 core_file_command (filename
, from_tty
)
51 dont_repeat (); /* Either way, seems bogus. */
53 t
= find_core_target ();
56 (t
->to_detach
) (filename
, from_tty
);
58 (t
->to_open
) (filename
, from_tty
);
60 error ("unimplemented: core files");
64 /* Call this to specify the hook for exec_file_command to call back.
65 This is called from the x-window display code. */
68 specify_exec_file_hook (hook
)
69 void (*hook
) PARAMS ((char *));
71 exec_file_display_hook
= hook
;
74 /* The exec file must be closed before running an inferior.
75 If it is needed again after the inferior dies, it must
83 bfd_tempclose (exec_bfd
);
92 bfd_reopen (exec_bfd
);
96 /* If we have both a core file and an exec file,
97 print a warning if they don't go together. */
102 if (exec_bfd
&& core_bfd
)
104 if (!core_file_matches_executable_p (core_bfd
, exec_bfd
))
105 warning ("core file may not match specified executable file.");
106 else if (bfd_get_mtime(exec_bfd
) > bfd_get_mtime(core_bfd
))
107 warning ("exec file is newer than core file.");
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. */
119 if (exec_bfd
) return bfd_get_filename(exec_bfd
);
120 if (!err
) return NULL
;
122 error ("No executable file specified.\n\
123 Use the \"file\" or \"exec-file\" command.");
128 /* Report a memory error with error(). */
131 memory_error (status
, memaddr
)
138 /* Actually, address between memaddr and memaddr + len
139 was out of bounds. */
140 error ("Cannot access memory at address %s.", local_hex_string(memaddr
));
144 error ("Error accessing memory address %s: %s.",
145 local_hex_string (memaddr
), safe_strerror (status
));
149 /* Same as target_read_memory, but report an error if can't read. */
151 read_memory (memaddr
, myaddr
, len
)
157 status
= target_read_memory (memaddr
, myaddr
, len
);
159 memory_error (status
, memaddr
);
162 /* Same as target_write_memory, but report an error if can't write. */
164 write_memory (memaddr
, myaddr
, len
)
171 status
= target_write_memory (memaddr
, myaddr
, len
);
173 memory_error (status
, memaddr
);
176 /* Read an integer from debugged memory, given address and number of bytes. */
179 read_memory_integer (memaddr
, len
)
188 if (len
== sizeof (char))
190 read_memory (memaddr
, &cbuf
, len
);
193 if (len
== sizeof (short))
195 read_memory (memaddr
, (char *)&sbuf
, len
);
196 SWAP_TARGET_AND_HOST (&sbuf
, sizeof (short));
199 if (len
== sizeof (int))
201 read_memory (memaddr
, (char *)&ibuf
, len
);
202 SWAP_TARGET_AND_HOST (&ibuf
, sizeof (int));
205 if (len
== sizeof (lbuf
))
207 read_memory (memaddr
, (char *)&lbuf
, len
);
208 SWAP_TARGET_AND_HOST (&lbuf
, sizeof (lbuf
));
211 error ("Cannot handle integers of %d bytes.", len
);
212 return -1; /* for lint */
219 add_com ("core-file", class_files
, core_file_command
,
220 "Use FILE as core dump for examining memory and registers.\n\
221 No arg means have no core file. This command has been superseded by the\n\
222 `target core' and `detach' commands.");