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 */
35 extern char registers
[];
37 /* Hook for `exec_file_command' command to call. */
39 void (*exec_file_display_hook
) PARAMS ((char *)) = NULL
;
41 /* Binary file diddling handle for the core file. */
46 /* Backward compatability with old way of specifying core files. */
49 core_file_command (filename
, from_tty
)
55 dont_repeat (); /* Either way, seems bogus. */
57 t
= find_core_target ();
60 (t
->to_detach
) (filename
, from_tty
);
62 (t
->to_open
) (filename
, from_tty
);
64 error ("GDB can't read core files on this machine.");
68 /* Call this to specify the hook for exec_file_command to call back.
69 This is called from the x-window display code. */
72 specify_exec_file_hook (hook
)
73 void (*hook
) PARAMS ((char *));
75 exec_file_display_hook
= hook
;
78 /* The exec file must be closed before running an inferior.
79 If it is needed again after the inferior dies, it must
87 bfd_tempclose (exec_bfd
);
96 bfd_reopen (exec_bfd
);
100 /* If we have both a core file and an exec file,
101 print a warning if they don't go together. */
106 if (exec_bfd
&& core_bfd
)
108 if (!core_file_matches_executable_p (core_bfd
, exec_bfd
))
109 warning ("core file may not match specified executable file.");
110 else if (bfd_get_mtime(exec_bfd
) > bfd_get_mtime(core_bfd
))
111 warning ("exec file is newer than core file.");
115 /* Return the name of the executable file as a string.
116 ERR nonzero means get error if there is none specified;
117 otherwise return 0 in that case. */
123 if (exec_bfd
) return bfd_get_filename(exec_bfd
);
124 if (!err
) return NULL
;
126 error ("No executable file specified.\n\
127 Use the \"file\" or \"exec-file\" command.");
132 /* Report a memory error with error(). */
135 memory_error (status
, memaddr
)
139 /* FIXME-32x64--casting CORE_ADDR to unsigned long */
142 /* Actually, address between memaddr and memaddr + len
143 was out of bounds. */
144 error ("Cannot access memory at address %s.",
145 local_hex_string((unsigned long) memaddr
));
149 error ("Error accessing memory address %s: %s.",
150 local_hex_string ((unsigned long) memaddr
),
151 safe_strerror (status
));
155 /* Same as target_read_memory, but report an error if can't read. */
157 read_memory (memaddr
, myaddr
, len
)
163 status
= target_read_memory (memaddr
, myaddr
, len
);
165 memory_error (status
, memaddr
);
168 /* Like target_read_memory, but slightly different parameters. */
171 dis_asm_read_memory (memaddr
, myaddr
, len
, info
)
175 disassemble_info
*info
;
177 return target_read_memory (memaddr
, (char *) myaddr
, len
);
180 /* Like memory_error with slightly different parameters. */
182 dis_asm_memory_error (status
, memaddr
, info
)
185 disassemble_info
*info
;
187 memory_error (status
, memaddr
);
190 /* Like print_address with slightly different parameters. */
192 dis_asm_print_address (addr
, info
)
194 struct disassemble_info
*info
;
196 print_address (addr
, info
->stream
);
199 /* Same as target_write_memory, but report an error if can't write. */
201 write_memory (memaddr
, myaddr
, len
)
208 status
= target_write_memory (memaddr
, myaddr
, len
);
210 memory_error (status
, memaddr
);
213 /* Read an integer from debugged memory, given address and number of bytes. */
216 read_memory_integer (memaddr
, len
)
220 char buf
[sizeof (LONGEST
)];
222 read_memory (memaddr
, buf
, len
);
223 return extract_signed_integer (buf
, len
);
227 read_memory_unsigned_integer (memaddr
, len
)
231 char buf
[sizeof (unsigned LONGEST
)];
233 read_memory (memaddr
, buf
, len
);
234 return extract_unsigned_integer (buf
, len
);
238 /* Enable after 4.12. It is not tested. */
240 /* Search code. Targets can just make this their search function, or
241 if the protocol has a less general search function, they can call this
242 in the cases it can't handle. */
244 generic_search (len
, data
, mask
, startaddr
, increment
, lorange
, hirange
245 addr_found
, data_found
)
253 CORE_ADDR
*addr_found
;
257 CORE_ADDR curaddr
= startaddr
;
259 while (curaddr
>= lorange
&& curaddr
< hirange
)
261 read_memory (curaddr
, data_found
, len
);
262 for (i
= 0; i
< len
; ++i
)
263 if ((data_found
[i
] & mask
[i
]) != data
[i
])
266 *addr_found
= curaddr
;
270 curaddr
+= increment
;
272 *addr_found
= (CORE_ADDR
)0;
277 /* The current default bfd target. Points to storage allocated for
281 /* Same thing, except it is "auto" not NULL for the default case. */
282 static char *gnutarget_string
;
284 static void set_gnutarget_command
285 PARAMS ((char *, int, struct cmd_list_element
*));
288 set_gnutarget_command (ignore
, from_tty
, c
)
291 struct cmd_list_element
*c
;
293 if (STREQ (gnutarget_string
, "auto"))
296 gnutarget
= gnutarget_string
;
299 /* Set the gnutarget. */
301 set_gnutarget (newtarget
)
304 if (gnutarget_string
!= NULL
)
305 free (gnutarget_string
);
306 gnutarget_string
= savestring (newtarget
, strlen (newtarget
));
307 set_gnutarget_command (NULL
, 0, NULL
);
313 struct cmd_list_element
*c
;
314 c
= add_cmd ("core-file", class_files
, core_file_command
,
315 "Use FILE as core dump for examining memory and registers.\n\
316 No arg means have no core file. This command has been superseded by the\n\
317 `target core' and `detach' commands.", &cmdlist
);
318 c
->completer
= filename_completer
;
320 c
= add_set_cmd ("gnutarget", class_files
, var_string_noescape
,
321 (char *) &gnutarget_string
,
322 "Set the current BFD target.\n\
323 Use `set gnutarget auto' to specify automatic detection.",
325 c
->function
.sfunc
= set_gnutarget_command
;
326 add_show_from_set (c
, &showlist
);
328 if (getenv ("GNUTARGET"))
329 set_gnutarget (getenv ("GNUTARGET"));
331 set_gnutarget ("auto");
This page took 0.035714 seconds and 4 git commands to generate.