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 */
34 extern char registers[];
36 /* Hook for `exec_file_command' command to call. */
38 void (*exec_file_display_hook) PARAMS ((char *)) = NULL;
40 /* Binary file diddling handle for the core file. */
45 /* Backward compatability with old way of specifying core files. */
48 core_file_command (filename, from_tty)
54 dont_repeat (); /* Either way, seems bogus. */
56 t = find_core_target ();
59 (t->to_detach) (filename, from_tty);
61 (t->to_open) (filename, from_tty);
63 error ("GDB can't read core files on this machine.");
67 /* Call this to specify the hook for exec_file_command to call back.
68 This is called from the x-window display code. */
71 specify_exec_file_hook (hook)
72 void (*hook) PARAMS ((char *));
74 exec_file_display_hook = hook;
77 /* The exec file must be closed before running an inferior.
78 If it is needed again after the inferior dies, it must
86 bfd_tempclose (exec_bfd);
95 bfd_reopen (exec_bfd);
99 /* If we have both a core file and an exec file,
100 print a warning if they don't go together. */
105 if (exec_bfd && core_bfd)
107 if (!core_file_matches_executable_p (core_bfd, exec_bfd))
108 warning ("core file may not match specified executable file.");
109 else if (bfd_get_mtime(exec_bfd) > bfd_get_mtime(core_bfd))
110 warning ("exec file is newer than core file.");
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. */
122 if (exec_bfd) return bfd_get_filename(exec_bfd);
123 if (!err) return NULL;
125 error ("No executable file specified.\n\
126 Use the \"file\" or \"exec-file\" command.");
131 /* Report a memory error with error(). */
134 memory_error (status, memaddr)
141 /* Actually, address between memaddr and memaddr + len
142 was out of bounds. */
143 error ("Cannot access memory at address %s.", local_hex_string(memaddr));
147 error ("Error accessing memory address %s: %s.",
148 local_hex_string (memaddr), safe_strerror (status));
152 /* Same as target_read_memory, but report an error if can't read. */
154 read_memory (memaddr, myaddr, len)
160 status = target_read_memory (memaddr, myaddr, len);
162 memory_error (status, memaddr);
165 /* Like target_read_memory, but slightly different parameters. */
168 dis_asm_read_memory (memaddr, myaddr, len, info)
172 disassemble_info *info;
174 return target_read_memory (memaddr, (char *) myaddr, len);
177 /* Like memory_error with slightly different parameters. */
179 dis_asm_memory_error (status, memaddr, info)
182 disassemble_info *info;
184 memory_error (status, memaddr);
187 /* Like print_address with slightly different parameters. */
189 dis_asm_print_address (addr, info)
191 struct disassemble_info *info;
193 print_address (addr, info->stream);
196 /* Same as target_write_memory, but report an error if can't write. */
198 write_memory (memaddr, myaddr, len)
205 status = target_write_memory (memaddr, myaddr, len);
207 memory_error (status, memaddr);
210 /* Read an integer from debugged memory, given address and number of bytes. */
213 read_memory_integer (memaddr, len)
217 char buf[sizeof (LONGEST)];
219 read_memory (memaddr, buf, len);
220 return extract_signed_integer (buf, len);
224 read_memory_unsigned_integer (memaddr, len)
228 char buf[sizeof (unsigned LONGEST)];
230 read_memory (memaddr, buf, len);
231 return extract_unsigned_integer (buf, len);
234 /* The current default bfd target. Points to storage allocated for
238 /* Same thing, except it is "auto" not NULL for the default case. */
239 static char *gnutarget_string;
241 static void set_gnutarget_command
242 PARAMS ((char *, int, struct cmd_list_element *));
245 set_gnutarget_command (ignore, from_tty, c)
248 struct cmd_list_element *c;
250 if (STREQ (gnutarget_string, "auto"))
253 gnutarget = gnutarget_string;
256 /* Set the gnutarget. */
258 set_gnutarget (newtarget)
261 if (gnutarget_string != NULL)
262 free (gnutarget_string);
263 gnutarget_string = savestring (newtarget, strlen (newtarget));
264 set_gnutarget_command (NULL, 0, NULL);
270 struct cmd_list_element *c;
271 c = add_cmd ("core-file", class_files, core_file_command,
272 "Use FILE as core dump for examining memory and registers.\n\
273 No arg means have no core file. This command has been superseded by the\n\
274 `target core' and `detach' commands.", &cmdlist);
275 c->completer = filename_completer;
277 c = add_set_cmd ("gnutarget", class_files, var_string_noescape,
278 (char *) &gnutarget_string,
279 "Set the current BFD target.\n\
280 Use `set gnutarget auto' to specify automatic detection.",
282 c->function.sfunc = set_gnutarget_command;
283 add_show_from_set (c, &showlist);
285 if (getenv ("GNUTARGET"))
286 set_gnutarget (getenv ("GNUTARGET"));
288 set_gnutarget ("auto");