1 /* Core dump and executable file functions above target vector, for GDB.
2 Copyright 1986, 1987, 1989, 1991, 1992, 1993, 1994
3 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
22 #include "gdb_string.h"
26 #include "frame.h" /* required by inferior.h */
37 extern char registers
[];
39 /* Hook for `exec_file_command' command to call. */
41 void (*exec_file_display_hook
) PARAMS ((char *)) = NULL
;
43 /* Binary file diddling handle for the core file. */
48 /* Backward compatability with old way of specifying core files. */
51 core_file_command (filename
, from_tty
)
57 dont_repeat (); /* Either way, seems bogus. */
59 t
= find_core_target ();
62 (t
->to_detach
) (filename
, from_tty
);
64 (t
->to_open
) (filename
, from_tty
);
66 error ("GDB can't read core files on this machine.");
70 /* Call this to specify the hook for exec_file_command to call back.
71 This is called from the x-window display code. */
74 specify_exec_file_hook (hook
)
75 void (*hook
) PARAMS ((char *));
77 exec_file_display_hook
= hook
;
80 /* The exec file must be closed before running an inferior.
81 If it is needed again after the inferior dies, it must
89 bfd_tempclose (exec_bfd
);
98 bfd_reopen (exec_bfd
);
102 /* If we have both a core file and an exec file,
103 print a warning if they don't go together. */
108 if (exec_bfd
&& core_bfd
)
110 if (!core_file_matches_executable_p (core_bfd
, exec_bfd
))
111 warning ("core file may not match specified executable file.");
112 else if (bfd_get_mtime(exec_bfd
) > bfd_get_mtime(core_bfd
))
113 warning ("exec file is newer than core file.");
117 /* Return the name of the executable file as a string.
118 ERR nonzero means get error if there is none specified;
119 otherwise return 0 in that case. */
125 if (exec_bfd
) return bfd_get_filename(exec_bfd
);
126 if (!err
) return NULL
;
128 error ("No executable file specified.\n\
129 Use the \"file\" or \"exec-file\" command.");
134 /* Report a memory error with error(). */
137 memory_error (status
, memaddr
)
143 /* Actually, address between memaddr and memaddr + len
144 was out of bounds. */
146 printf_filtered ("Cannot access memory at address ");
147 print_address_numeric (memaddr
, 1, gdb_stdout
);
148 printf_filtered (".\n");
149 return_to_top_level (RETURN_ERROR
);
154 printf_filtered ("Error accessing memory address ");
155 print_address_numeric (memaddr
, 1, gdb_stdout
);
156 printf_filtered (": %s.\n",
157 safe_strerror (status
));
158 return_to_top_level (RETURN_ERROR
);
162 /* Same as target_read_memory, but report an error if can't read. */
164 read_memory (memaddr
, myaddr
, len
)
170 status
= target_read_memory (memaddr
, myaddr
, len
);
172 memory_error (status
, memaddr
);
175 /* Like target_read_memory, but slightly different parameters. */
178 dis_asm_read_memory (memaddr
, myaddr
, len
, info
)
182 disassemble_info
*info
;
184 return target_read_memory (memaddr
, (char *) myaddr
, len
);
187 /* Like memory_error with slightly different parameters. */
189 dis_asm_memory_error (status
, memaddr
, info
)
192 disassemble_info
*info
;
194 memory_error (status
, memaddr
);
197 /* Like print_address with slightly different parameters. */
199 dis_asm_print_address (addr
, info
)
201 struct disassemble_info
*info
;
203 print_address (addr
, info
->stream
);
206 /* Same as target_write_memory, but report an error if can't write. */
208 write_memory (memaddr
, myaddr
, len
)
215 status
= target_write_memory (memaddr
, myaddr
, len
);
217 memory_error (status
, memaddr
);
220 /* Read an integer from debugged memory, given address and number of bytes. */
223 read_memory_integer (memaddr
, len
)
227 char buf
[sizeof (LONGEST
)];
229 read_memory (memaddr
, buf
, len
);
230 return extract_signed_integer (buf
, len
);
234 read_memory_unsigned_integer (memaddr
, len
)
238 char buf
[sizeof (unsigned LONGEST
)];
240 read_memory (memaddr
, buf
, len
);
241 return extract_unsigned_integer (buf
, len
);
245 /* Enable after 4.12. It is not tested. */
247 /* Search code. Targets can just make this their search function, or
248 if the protocol has a less general search function, they can call this
249 in the cases it can't handle. */
251 generic_search (len
, data
, mask
, startaddr
, increment
, lorange
, hirange
252 addr_found
, data_found
)
260 CORE_ADDR
*addr_found
;
264 CORE_ADDR curaddr
= startaddr
;
266 while (curaddr
>= lorange
&& curaddr
< hirange
)
268 read_memory (curaddr
, data_found
, len
);
269 for (i
= 0; i
< len
; ++i
)
270 if ((data_found
[i
] & mask
[i
]) != data
[i
])
273 *addr_found
= curaddr
;
277 curaddr
+= increment
;
279 *addr_found
= (CORE_ADDR
)0;
284 /* The current default bfd target. Points to storage allocated for
288 /* Same thing, except it is "auto" not NULL for the default case. */
289 static char *gnutarget_string
;
291 static void set_gnutarget_command
292 PARAMS ((char *, int, struct cmd_list_element
*));
295 set_gnutarget_command (ignore
, from_tty
, c
)
298 struct cmd_list_element
*c
;
300 if (STREQ (gnutarget_string
, "auto"))
303 gnutarget
= gnutarget_string
;
306 /* Set the gnutarget. */
308 set_gnutarget (newtarget
)
311 if (gnutarget_string
!= NULL
)
312 free (gnutarget_string
);
313 gnutarget_string
= savestring (newtarget
, strlen (newtarget
));
314 set_gnutarget_command (NULL
, 0, NULL
);
320 struct cmd_list_element
*c
;
321 c
= add_cmd ("core-file", class_files
, core_file_command
,
322 "Use FILE as core dump for examining memory and registers.\n\
323 No arg means have no core file. This command has been superseded by the\n\
324 `target core' and `detach' commands.", &cmdlist
);
325 c
->completer
= filename_completer
;
327 c
= add_set_cmd ("gnutarget", class_files
, var_string_noescape
,
328 (char *) &gnutarget_string
,
329 "Set the current BFD target.\n\
330 Use `set gnutarget auto' to specify automatic detection.",
332 c
->function
.sfunc
= set_gnutarget_command
;
333 add_show_from_set (c
, &showlist
);
335 if (getenv ("GNUTARGET"))
336 set_gnutarget (getenv ("GNUTARGET"));
338 set_gnutarget ("auto");
This page took 0.035454 seconds and 4 git commands to generate.