Commit | Line | Data |
---|---|---|
c906108c | 1 | /* Select target systems and architectures at runtime for GDB. |
7998dfc3 | 2 | |
197e01b6 | 3 | Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, |
f6519ebc MK |
4 | 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006 |
5 | Free Software Foundation, Inc. | |
7998dfc3 | 6 | |
c906108c SS |
7 | Contributed by Cygnus Support. |
8 | ||
c5aa993b | 9 | This file is part of GDB. |
c906108c | 10 | |
c5aa993b JM |
11 | This program is free software; you can redistribute it and/or modify |
12 | it under the terms of the GNU General Public License as published by | |
13 | the Free Software Foundation; either version 2 of the License, or | |
14 | (at your option) any later version. | |
c906108c | 15 | |
c5aa993b JM |
16 | This program is distributed in the hope that it will be useful, |
17 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 | GNU General Public License for more details. | |
c906108c | 20 | |
c5aa993b JM |
21 | You should have received a copy of the GNU General Public License |
22 | along with this program; if not, write to the Free Software | |
197e01b6 EZ |
23 | Foundation, Inc., 51 Franklin Street, Fifth Floor, |
24 | Boston, MA 02110-1301, USA. */ | |
c906108c SS |
25 | |
26 | #include "defs.h" | |
27 | #include <errno.h> | |
c906108c SS |
28 | #include "gdb_string.h" |
29 | #include "target.h" | |
30 | #include "gdbcmd.h" | |
31 | #include "symtab.h" | |
32 | #include "inferior.h" | |
33 | #include "bfd.h" | |
34 | #include "symfile.h" | |
35 | #include "objfiles.h" | |
03f2053f | 36 | #include "gdb_wait.h" |
4930751a | 37 | #include "dcache.h" |
c906108c | 38 | #include <signal.h> |
4e052eda | 39 | #include "regcache.h" |
0088c768 | 40 | #include "gdb_assert.h" |
b6591e8b | 41 | #include "gdbcore.h" |
9e35dae4 | 42 | #include "exceptions.h" |
c906108c | 43 | |
a14ed312 | 44 | static void target_info (char *, int); |
c906108c | 45 | |
a14ed312 | 46 | static void maybe_kill_then_attach (char *, int); |
c906108c | 47 | |
a14ed312 | 48 | static void kill_or_be_killed (int); |
c906108c | 49 | |
a14ed312 | 50 | static void default_terminal_info (char *, int); |
c906108c | 51 | |
e0d24f8d WZ |
52 | static int default_region_ok_for_hw_watchpoint (CORE_ADDR, int); |
53 | ||
a14ed312 | 54 | static int nosymbol (char *, CORE_ADDR *); |
c906108c | 55 | |
4ecb6f27 | 56 | static void tcomplain (void) ATTR_NORETURN; |
c906108c | 57 | |
a14ed312 | 58 | static int nomemory (CORE_ADDR, char *, int, int, struct target_ops *); |
c906108c | 59 | |
a14ed312 | 60 | static int return_zero (void); |
c906108c | 61 | |
a14ed312 | 62 | static int return_one (void); |
c906108c | 63 | |
ccaa32c7 GS |
64 | static int return_minus_one (void); |
65 | ||
a14ed312 | 66 | void target_ignore (void); |
c906108c | 67 | |
a14ed312 | 68 | static void target_command (char *, int); |
c906108c | 69 | |
a14ed312 | 70 | static struct target_ops *find_default_run_target (char *); |
c906108c | 71 | |
a14ed312 | 72 | static void nosupport_runtime (void); |
392a587b | 73 | |
4b8a223f | 74 | static LONGEST default_xfer_partial (struct target_ops *ops, |
0088c768 | 75 | enum target_object object, |
1b0ba102 AC |
76 | const char *annex, gdb_byte *readbuf, |
77 | const gdb_byte *writebuf, | |
8aa91c1e | 78 | ULONGEST offset, LONGEST len); |
0088c768 | 79 | |
cf7a04e8 DJ |
80 | static LONGEST current_xfer_partial (struct target_ops *ops, |
81 | enum target_object object, | |
82 | const char *annex, gdb_byte *readbuf, | |
83 | const gdb_byte *writebuf, | |
84 | ULONGEST offset, LONGEST len); | |
c906108c | 85 | |
cf7a04e8 DJ |
86 | static LONGEST target_xfer_partial (struct target_ops *ops, |
87 | enum target_object object, | |
88 | const char *annex, | |
89 | void *readbuf, const void *writebuf, | |
90 | ULONGEST offset, LONGEST len); | |
c906108c | 91 | |
a14ed312 | 92 | static void init_dummy_target (void); |
c906108c | 93 | |
aa869812 AC |
94 | static struct target_ops debug_target; |
95 | ||
a14ed312 | 96 | static void debug_to_open (char *, int); |
c906108c | 97 | |
a14ed312 | 98 | static void debug_to_close (int); |
c906108c | 99 | |
a14ed312 | 100 | static void debug_to_attach (char *, int); |
c906108c | 101 | |
a14ed312 | 102 | static void debug_to_detach (char *, int); |
c906108c | 103 | |
39f77062 | 104 | static void debug_to_resume (ptid_t, int, enum target_signal); |
c906108c | 105 | |
39f77062 | 106 | static ptid_t debug_to_wait (ptid_t, struct target_waitstatus *); |
c906108c | 107 | |
a14ed312 | 108 | static void debug_to_fetch_registers (int); |
c906108c | 109 | |
a14ed312 | 110 | static void debug_to_store_registers (int); |
c906108c | 111 | |
a14ed312 | 112 | static void debug_to_prepare_to_store (void); |
c906108c | 113 | |
a14ed312 | 114 | static void debug_to_files_info (struct target_ops *); |
c906108c | 115 | |
8181d85f | 116 | static int debug_to_insert_breakpoint (struct bp_target_info *); |
c906108c | 117 | |
8181d85f | 118 | static int debug_to_remove_breakpoint (struct bp_target_info *); |
c906108c | 119 | |
ccaa32c7 GS |
120 | static int debug_to_can_use_hw_breakpoint (int, int, int); |
121 | ||
8181d85f | 122 | static int debug_to_insert_hw_breakpoint (struct bp_target_info *); |
ccaa32c7 | 123 | |
8181d85f | 124 | static int debug_to_remove_hw_breakpoint (struct bp_target_info *); |
ccaa32c7 GS |
125 | |
126 | static int debug_to_insert_watchpoint (CORE_ADDR, int, int); | |
127 | ||
128 | static int debug_to_remove_watchpoint (CORE_ADDR, int, int); | |
129 | ||
130 | static int debug_to_stopped_by_watchpoint (void); | |
131 | ||
4aa7a7f5 | 132 | static int debug_to_stopped_data_address (struct target_ops *, CORE_ADDR *); |
ccaa32c7 | 133 | |
e0d24f8d WZ |
134 | static int debug_to_region_ok_for_hw_watchpoint (CORE_ADDR, int); |
135 | ||
a14ed312 | 136 | static void debug_to_terminal_init (void); |
c906108c | 137 | |
a14ed312 | 138 | static void debug_to_terminal_inferior (void); |
c906108c | 139 | |
a14ed312 | 140 | static void debug_to_terminal_ours_for_output (void); |
c906108c | 141 | |
a790ad35 SC |
142 | static void debug_to_terminal_save_ours (void); |
143 | ||
a14ed312 | 144 | static void debug_to_terminal_ours (void); |
c906108c | 145 | |
a14ed312 | 146 | static void debug_to_terminal_info (char *, int); |
c906108c | 147 | |
a14ed312 | 148 | static void debug_to_kill (void); |
c906108c | 149 | |
a14ed312 | 150 | static void debug_to_load (char *, int); |
c906108c | 151 | |
a14ed312 | 152 | static int debug_to_lookup_symbol (char *, CORE_ADDR *); |
c906108c | 153 | |
a14ed312 | 154 | static void debug_to_mourn_inferior (void); |
c906108c | 155 | |
a14ed312 | 156 | static int debug_to_can_run (void); |
c906108c | 157 | |
39f77062 | 158 | static void debug_to_notice_signals (ptid_t); |
c906108c | 159 | |
39f77062 | 160 | static int debug_to_thread_alive (ptid_t); |
c906108c | 161 | |
a14ed312 | 162 | static void debug_to_stop (void); |
c906108c | 163 | |
5ac10fd1 AC |
164 | /* NOTE: cagney/2004-09-29: Many targets reference this variable in |
165 | wierd and mysterious ways. Putting the variable here lets those | |
166 | wierd and mysterious ways keep building while they are being | |
167 | converted to the inferior inheritance structure. */ | |
1df84f13 | 168 | struct target_ops deprecated_child_ops; |
5ac10fd1 | 169 | |
c906108c | 170 | /* Pointer to array of target architecture structures; the size of the |
2bc416ba | 171 | array; the current index into the array; the allocated size of the |
c906108c SS |
172 | array. */ |
173 | struct target_ops **target_structs; | |
174 | unsigned target_struct_size; | |
175 | unsigned target_struct_index; | |
176 | unsigned target_struct_allocsize; | |
177 | #define DEFAULT_ALLOCSIZE 10 | |
178 | ||
179 | /* The initial current target, so that there is always a semi-valid | |
180 | current target. */ | |
181 | ||
182 | static struct target_ops dummy_target; | |
183 | ||
184 | /* Top of target stack. */ | |
185 | ||
258b763a | 186 | static struct target_ops *target_stack; |
c906108c SS |
187 | |
188 | /* The target structure we are currently using to talk to a process | |
189 | or file or whatever "inferior" we have. */ | |
190 | ||
191 | struct target_ops current_target; | |
192 | ||
193 | /* Command list for target. */ | |
194 | ||
195 | static struct cmd_list_element *targetlist = NULL; | |
196 | ||
197 | /* Nonzero if we are debugging an attached outside process | |
198 | rather than an inferior. */ | |
199 | ||
200 | int attach_flag; | |
201 | ||
cf7a04e8 DJ |
202 | /* Nonzero if we should trust readonly sections from the |
203 | executable when reading memory. */ | |
204 | ||
205 | static int trust_readonly = 0; | |
206 | ||
c906108c SS |
207 | /* Non-zero if we want to see trace of target level stuff. */ |
208 | ||
209 | static int targetdebug = 0; | |
920d2a44 AC |
210 | static void |
211 | show_targetdebug (struct ui_file *file, int from_tty, | |
212 | struct cmd_list_element *c, const char *value) | |
213 | { | |
214 | fprintf_filtered (file, _("Target debugging is %s.\n"), value); | |
215 | } | |
c906108c | 216 | |
a14ed312 | 217 | static void setup_target_debug (void); |
c906108c | 218 | |
4930751a C |
219 | DCACHE *target_dcache; |
220 | ||
c906108c SS |
221 | /* The user just typed 'target' without the name of a target. */ |
222 | ||
c906108c | 223 | static void |
fba45db2 | 224 | target_command (char *arg, int from_tty) |
c906108c SS |
225 | { |
226 | fputs_filtered ("Argument required (target name). Try `help target'\n", | |
227 | gdb_stdout); | |
228 | } | |
229 | ||
230 | /* Add a possible target architecture to the list. */ | |
231 | ||
232 | void | |
fba45db2 | 233 | add_target (struct target_ops *t) |
c906108c | 234 | { |
0088c768 | 235 | /* Provide default values for all "must have" methods. */ |
0b603eba AC |
236 | if (t->to_xfer_partial == NULL) |
237 | t->to_xfer_partial = default_xfer_partial; | |
0088c768 | 238 | |
c906108c SS |
239 | if (!target_structs) |
240 | { | |
241 | target_struct_allocsize = DEFAULT_ALLOCSIZE; | |
242 | target_structs = (struct target_ops **) xmalloc | |
243 | (target_struct_allocsize * sizeof (*target_structs)); | |
244 | } | |
245 | if (target_struct_size >= target_struct_allocsize) | |
246 | { | |
247 | target_struct_allocsize *= 2; | |
248 | target_structs = (struct target_ops **) | |
c5aa993b JM |
249 | xrealloc ((char *) target_structs, |
250 | target_struct_allocsize * sizeof (*target_structs)); | |
c906108c SS |
251 | } |
252 | target_structs[target_struct_size++] = t; | |
c906108c SS |
253 | |
254 | if (targetlist == NULL) | |
1bedd215 AC |
255 | add_prefix_cmd ("target", class_run, target_command, _("\ |
256 | Connect to a target machine or process.\n\ | |
c906108c SS |
257 | The first argument is the type or protocol of the target machine.\n\ |
258 | Remaining arguments are interpreted by the target protocol. For more\n\ | |
259 | information on the arguments for a particular protocol, type\n\ | |
1bedd215 | 260 | `help target ' followed by the protocol name."), |
c906108c SS |
261 | &targetlist, "target ", 0, &cmdlist); |
262 | add_cmd (t->to_shortname, no_class, t->to_open, t->to_doc, &targetlist); | |
263 | } | |
264 | ||
265 | /* Stub functions */ | |
266 | ||
267 | void | |
fba45db2 | 268 | target_ignore (void) |
c906108c SS |
269 | { |
270 | } | |
271 | ||
11cf8741 JM |
272 | void |
273 | target_load (char *arg, int from_tty) | |
274 | { | |
4930751a | 275 | dcache_invalidate (target_dcache); |
11cf8741 JM |
276 | (*current_target.to_load) (arg, from_tty); |
277 | } | |
278 | ||
c906108c | 279 | static int |
fba45db2 KB |
280 | nomemory (CORE_ADDR memaddr, char *myaddr, int len, int write, |
281 | struct target_ops *t) | |
c906108c | 282 | { |
c5aa993b JM |
283 | errno = EIO; /* Can't read/write this location */ |
284 | return 0; /* No bytes handled */ | |
c906108c SS |
285 | } |
286 | ||
287 | static void | |
fba45db2 | 288 | tcomplain (void) |
c906108c | 289 | { |
8a3fe4f8 | 290 | error (_("You can't do that when your target is `%s'"), |
c906108c SS |
291 | current_target.to_shortname); |
292 | } | |
293 | ||
294 | void | |
fba45db2 | 295 | noprocess (void) |
c906108c | 296 | { |
8a3fe4f8 | 297 | error (_("You can't do that without a process to debug.")); |
c906108c SS |
298 | } |
299 | ||
c906108c | 300 | static int |
fba45db2 | 301 | nosymbol (char *name, CORE_ADDR *addrp) |
c906108c | 302 | { |
c5aa993b | 303 | return 1; /* Symbol does not exist in target env */ |
c906108c SS |
304 | } |
305 | ||
392a587b | 306 | static void |
fba45db2 | 307 | nosupport_runtime (void) |
c906108c | 308 | { |
39f77062 | 309 | if (ptid_equal (inferior_ptid, null_ptid)) |
c906108c SS |
310 | noprocess (); |
311 | else | |
8a3fe4f8 | 312 | error (_("No run-time support for this")); |
c906108c SS |
313 | } |
314 | ||
315 | ||
c906108c | 316 | static void |
fba45db2 | 317 | default_terminal_info (char *args, int from_tty) |
c906108c | 318 | { |
a3f17187 | 319 | printf_unfiltered (_("No saved terminal information.\n")); |
c906108c SS |
320 | } |
321 | ||
322 | /* This is the default target_create_inferior and target_attach function. | |
323 | If the current target is executing, it asks whether to kill it off. | |
324 | If this function returns without calling error(), it has killed off | |
325 | the target, and the operation should be attempted. */ | |
326 | ||
327 | static void | |
fba45db2 | 328 | kill_or_be_killed (int from_tty) |
c906108c SS |
329 | { |
330 | if (target_has_execution) | |
331 | { | |
a3f17187 | 332 | printf_unfiltered (_("You are already running a program:\n")); |
c906108c | 333 | target_files_info (); |
c5aa993b JM |
334 | if (query ("Kill it? ")) |
335 | { | |
336 | target_kill (); | |
337 | if (target_has_execution) | |
8a3fe4f8 | 338 | error (_("Killing the program did not help.")); |
c5aa993b JM |
339 | return; |
340 | } | |
341 | else | |
342 | { | |
8a3fe4f8 | 343 | error (_("Program not killed.")); |
c5aa993b | 344 | } |
c906108c | 345 | } |
c5aa993b | 346 | tcomplain (); |
c906108c SS |
347 | } |
348 | ||
349 | static void | |
fba45db2 | 350 | maybe_kill_then_attach (char *args, int from_tty) |
c906108c SS |
351 | { |
352 | kill_or_be_killed (from_tty); | |
353 | target_attach (args, from_tty); | |
354 | } | |
355 | ||
356 | static void | |
c27cda74 AC |
357 | maybe_kill_then_create_inferior (char *exec, char *args, char **env, |
358 | int from_tty) | |
c906108c SS |
359 | { |
360 | kill_or_be_killed (0); | |
c27cda74 | 361 | target_create_inferior (exec, args, env, from_tty); |
c906108c SS |
362 | } |
363 | ||
7998dfc3 AC |
364 | /* Go through the target stack from top to bottom, copying over zero |
365 | entries in current_target, then filling in still empty entries. In | |
366 | effect, we are doing class inheritance through the pushed target | |
367 | vectors. | |
368 | ||
369 | NOTE: cagney/2003-10-17: The problem with this inheritance, as it | |
370 | is currently implemented, is that it discards any knowledge of | |
371 | which target an inherited method originally belonged to. | |
372 | Consequently, new new target methods should instead explicitly and | |
373 | locally search the target stack for the target that can handle the | |
374 | request. */ | |
c906108c SS |
375 | |
376 | static void | |
7998dfc3 | 377 | update_current_target (void) |
c906108c | 378 | { |
7998dfc3 AC |
379 | struct target_ops *t; |
380 | ||
381 | /* First, reset curren'ts contents. */ | |
382 | memset (¤t_target, 0, sizeof (current_target)); | |
383 | ||
384 | #define INHERIT(FIELD, TARGET) \ | |
385 | if (!current_target.FIELD) \ | |
386 | current_target.FIELD = (TARGET)->FIELD | |
387 | ||
388 | for (t = target_stack; t; t = t->beneath) | |
389 | { | |
390 | INHERIT (to_shortname, t); | |
391 | INHERIT (to_longname, t); | |
392 | INHERIT (to_doc, t); | |
393 | INHERIT (to_open, t); | |
394 | INHERIT (to_close, t); | |
395 | INHERIT (to_attach, t); | |
396 | INHERIT (to_post_attach, t); | |
397 | INHERIT (to_detach, t); | |
597320e7 | 398 | /* Do not inherit to_disconnect. */ |
7998dfc3 AC |
399 | INHERIT (to_resume, t); |
400 | INHERIT (to_wait, t); | |
7998dfc3 AC |
401 | INHERIT (to_fetch_registers, t); |
402 | INHERIT (to_store_registers, t); | |
403 | INHERIT (to_prepare_to_store, t); | |
c8e73a31 | 404 | INHERIT (deprecated_xfer_memory, t); |
7998dfc3 AC |
405 | INHERIT (to_files_info, t); |
406 | INHERIT (to_insert_breakpoint, t); | |
407 | INHERIT (to_remove_breakpoint, t); | |
408 | INHERIT (to_can_use_hw_breakpoint, t); | |
409 | INHERIT (to_insert_hw_breakpoint, t); | |
410 | INHERIT (to_remove_hw_breakpoint, t); | |
411 | INHERIT (to_insert_watchpoint, t); | |
412 | INHERIT (to_remove_watchpoint, t); | |
413 | INHERIT (to_stopped_data_address, t); | |
414 | INHERIT (to_stopped_by_watchpoint, t); | |
415 | INHERIT (to_have_continuable_watchpoint, t); | |
e0d24f8d | 416 | INHERIT (to_region_ok_for_hw_watchpoint, t); |
7998dfc3 AC |
417 | INHERIT (to_terminal_init, t); |
418 | INHERIT (to_terminal_inferior, t); | |
419 | INHERIT (to_terminal_ours_for_output, t); | |
420 | INHERIT (to_terminal_ours, t); | |
421 | INHERIT (to_terminal_save_ours, t); | |
422 | INHERIT (to_terminal_info, t); | |
423 | INHERIT (to_kill, t); | |
424 | INHERIT (to_load, t); | |
425 | INHERIT (to_lookup_symbol, t); | |
426 | INHERIT (to_create_inferior, t); | |
427 | INHERIT (to_post_startup_inferior, t); | |
428 | INHERIT (to_acknowledge_created_inferior, t); | |
429 | INHERIT (to_insert_fork_catchpoint, t); | |
430 | INHERIT (to_remove_fork_catchpoint, t); | |
431 | INHERIT (to_insert_vfork_catchpoint, t); | |
432 | INHERIT (to_remove_vfork_catchpoint, t); | |
ee057212 | 433 | /* Do not inherit to_follow_fork. */ |
7998dfc3 AC |
434 | INHERIT (to_insert_exec_catchpoint, t); |
435 | INHERIT (to_remove_exec_catchpoint, t); | |
436 | INHERIT (to_reported_exec_events_per_exec_call, t); | |
437 | INHERIT (to_has_exited, t); | |
438 | INHERIT (to_mourn_inferior, t); | |
439 | INHERIT (to_can_run, t); | |
440 | INHERIT (to_notice_signals, t); | |
441 | INHERIT (to_thread_alive, t); | |
442 | INHERIT (to_find_new_threads, t); | |
443 | INHERIT (to_pid_to_str, t); | |
444 | INHERIT (to_extra_thread_info, t); | |
445 | INHERIT (to_stop, t); | |
4b8a223f | 446 | /* Do not inherit to_xfer_partial. */ |
7998dfc3 AC |
447 | INHERIT (to_rcmd, t); |
448 | INHERIT (to_enable_exception_callback, t); | |
449 | INHERIT (to_get_current_exception_event, t); | |
450 | INHERIT (to_pid_to_exec_file, t); | |
451 | INHERIT (to_stratum, t); | |
452 | INHERIT (to_has_all_memory, t); | |
453 | INHERIT (to_has_memory, t); | |
454 | INHERIT (to_has_stack, t); | |
455 | INHERIT (to_has_registers, t); | |
456 | INHERIT (to_has_execution, t); | |
457 | INHERIT (to_has_thread_control, t); | |
458 | INHERIT (to_sections, t); | |
459 | INHERIT (to_sections_end, t); | |
460 | INHERIT (to_can_async_p, t); | |
461 | INHERIT (to_is_async_p, t); | |
462 | INHERIT (to_async, t); | |
463 | INHERIT (to_async_mask_value, t); | |
464 | INHERIT (to_find_memory_regions, t); | |
465 | INHERIT (to_make_corefile_notes, t); | |
466 | INHERIT (to_get_thread_local_address, t); | |
467 | INHERIT (to_magic, t); | |
fd79ecee | 468 | /* Do not inherit to_memory_map. */ |
a76d924d DJ |
469 | /* Do not inherit to_flash_erase. */ |
470 | /* Do not inherit to_flash_done. */ | |
7998dfc3 AC |
471 | } |
472 | #undef INHERIT | |
473 | ||
474 | /* Clean up a target struct so it no longer has any zero pointers in | |
0088c768 AC |
475 | it. Some entries are defaulted to a method that print an error, |
476 | others are hard-wired to a standard recursive default. */ | |
c906108c SS |
477 | |
478 | #define de_fault(field, value) \ | |
7998dfc3 AC |
479 | if (!current_target.field) \ |
480 | current_target.field = value | |
0d06e24b | 481 | |
2bc416ba DJ |
482 | de_fault (to_open, |
483 | (void (*) (char *, int)) | |
0d06e24b | 484 | tcomplain); |
2bc416ba DJ |
485 | de_fault (to_close, |
486 | (void (*) (int)) | |
0d06e24b | 487 | target_ignore); |
2bc416ba | 488 | de_fault (to_attach, |
0d06e24b | 489 | maybe_kill_then_attach); |
2bc416ba DJ |
490 | de_fault (to_post_attach, |
491 | (void (*) (int)) | |
0d06e24b | 492 | target_ignore); |
2bc416ba DJ |
493 | de_fault (to_detach, |
494 | (void (*) (char *, int)) | |
0d06e24b | 495 | target_ignore); |
2bc416ba DJ |
496 | de_fault (to_resume, |
497 | (void (*) (ptid_t, int, enum target_signal)) | |
0d06e24b | 498 | noprocess); |
2bc416ba DJ |
499 | de_fault (to_wait, |
500 | (ptid_t (*) (ptid_t, struct target_waitstatus *)) | |
0d06e24b | 501 | noprocess); |
2bc416ba DJ |
502 | de_fault (to_fetch_registers, |
503 | (void (*) (int)) | |
0d06e24b | 504 | target_ignore); |
2bc416ba DJ |
505 | de_fault (to_store_registers, |
506 | (void (*) (int)) | |
0d06e24b | 507 | noprocess); |
2bc416ba DJ |
508 | de_fault (to_prepare_to_store, |
509 | (void (*) (void)) | |
0d06e24b | 510 | noprocess); |
2bc416ba DJ |
511 | de_fault (deprecated_xfer_memory, |
512 | (int (*) (CORE_ADDR, gdb_byte *, int, int, struct mem_attrib *, struct target_ops *)) | |
0d06e24b | 513 | nomemory); |
2bc416ba DJ |
514 | de_fault (to_files_info, |
515 | (void (*) (struct target_ops *)) | |
0d06e24b | 516 | target_ignore); |
2bc416ba | 517 | de_fault (to_insert_breakpoint, |
0d06e24b | 518 | memory_insert_breakpoint); |
2bc416ba | 519 | de_fault (to_remove_breakpoint, |
0d06e24b | 520 | memory_remove_breakpoint); |
ccaa32c7 GS |
521 | de_fault (to_can_use_hw_breakpoint, |
522 | (int (*) (int, int, int)) | |
523 | return_zero); | |
524 | de_fault (to_insert_hw_breakpoint, | |
8181d85f | 525 | (int (*) (struct bp_target_info *)) |
ccaa32c7 GS |
526 | return_minus_one); |
527 | de_fault (to_remove_hw_breakpoint, | |
8181d85f | 528 | (int (*) (struct bp_target_info *)) |
ccaa32c7 GS |
529 | return_minus_one); |
530 | de_fault (to_insert_watchpoint, | |
531 | (int (*) (CORE_ADDR, int, int)) | |
532 | return_minus_one); | |
533 | de_fault (to_remove_watchpoint, | |
534 | (int (*) (CORE_ADDR, int, int)) | |
535 | return_minus_one); | |
536 | de_fault (to_stopped_by_watchpoint, | |
537 | (int (*) (void)) | |
538 | return_zero); | |
539 | de_fault (to_stopped_data_address, | |
4aa7a7f5 | 540 | (int (*) (struct target_ops *, CORE_ADDR *)) |
ccaa32c7 | 541 | return_zero); |
e0d24f8d WZ |
542 | de_fault (to_region_ok_for_hw_watchpoint, |
543 | default_region_ok_for_hw_watchpoint); | |
2bc416ba DJ |
544 | de_fault (to_terminal_init, |
545 | (void (*) (void)) | |
0d06e24b | 546 | target_ignore); |
2bc416ba DJ |
547 | de_fault (to_terminal_inferior, |
548 | (void (*) (void)) | |
0d06e24b | 549 | target_ignore); |
2bc416ba DJ |
550 | de_fault (to_terminal_ours_for_output, |
551 | (void (*) (void)) | |
0d06e24b | 552 | target_ignore); |
2bc416ba DJ |
553 | de_fault (to_terminal_ours, |
554 | (void (*) (void)) | |
0d06e24b | 555 | target_ignore); |
2bc416ba DJ |
556 | de_fault (to_terminal_save_ours, |
557 | (void (*) (void)) | |
a790ad35 | 558 | target_ignore); |
2bc416ba | 559 | de_fault (to_terminal_info, |
0d06e24b | 560 | default_terminal_info); |
2bc416ba DJ |
561 | de_fault (to_kill, |
562 | (void (*) (void)) | |
0d06e24b | 563 | noprocess); |
2bc416ba DJ |
564 | de_fault (to_load, |
565 | (void (*) (char *, int)) | |
0d06e24b | 566 | tcomplain); |
2bc416ba DJ |
567 | de_fault (to_lookup_symbol, |
568 | (int (*) (char *, CORE_ADDR *)) | |
0d06e24b | 569 | nosymbol); |
2bc416ba | 570 | de_fault (to_create_inferior, |
0d06e24b | 571 | maybe_kill_then_create_inferior); |
2bc416ba DJ |
572 | de_fault (to_post_startup_inferior, |
573 | (void (*) (ptid_t)) | |
0d06e24b | 574 | target_ignore); |
2bc416ba DJ |
575 | de_fault (to_acknowledge_created_inferior, |
576 | (void (*) (int)) | |
0d06e24b | 577 | target_ignore); |
2bc416ba DJ |
578 | de_fault (to_insert_fork_catchpoint, |
579 | (void (*) (int)) | |
0d06e24b | 580 | tcomplain); |
2bc416ba DJ |
581 | de_fault (to_remove_fork_catchpoint, |
582 | (int (*) (int)) | |
0d06e24b | 583 | tcomplain); |
2bc416ba DJ |
584 | de_fault (to_insert_vfork_catchpoint, |
585 | (void (*) (int)) | |
0d06e24b | 586 | tcomplain); |
2bc416ba DJ |
587 | de_fault (to_remove_vfork_catchpoint, |
588 | (int (*) (int)) | |
0d06e24b | 589 | tcomplain); |
2bc416ba DJ |
590 | de_fault (to_insert_exec_catchpoint, |
591 | (void (*) (int)) | |
0d06e24b | 592 | tcomplain); |
2bc416ba DJ |
593 | de_fault (to_remove_exec_catchpoint, |
594 | (int (*) (int)) | |
0d06e24b | 595 | tcomplain); |
2bc416ba DJ |
596 | de_fault (to_reported_exec_events_per_exec_call, |
597 | (int (*) (void)) | |
0d06e24b | 598 | return_one); |
2bc416ba DJ |
599 | de_fault (to_has_exited, |
600 | (int (*) (int, int, int *)) | |
0d06e24b | 601 | return_zero); |
2bc416ba DJ |
602 | de_fault (to_mourn_inferior, |
603 | (void (*) (void)) | |
0d06e24b | 604 | noprocess); |
2bc416ba | 605 | de_fault (to_can_run, |
0d06e24b | 606 | return_zero); |
2bc416ba DJ |
607 | de_fault (to_notice_signals, |
608 | (void (*) (ptid_t)) | |
0d06e24b | 609 | target_ignore); |
2bc416ba DJ |
610 | de_fault (to_thread_alive, |
611 | (int (*) (ptid_t)) | |
0d06e24b | 612 | return_zero); |
2bc416ba DJ |
613 | de_fault (to_find_new_threads, |
614 | (void (*) (void)) | |
0d06e24b | 615 | target_ignore); |
2bc416ba DJ |
616 | de_fault (to_extra_thread_info, |
617 | (char *(*) (struct thread_info *)) | |
0d06e24b | 618 | return_zero); |
2bc416ba DJ |
619 | de_fault (to_stop, |
620 | (void (*) (void)) | |
0d06e24b | 621 | target_ignore); |
cf7a04e8 | 622 | current_target.to_xfer_partial = current_xfer_partial; |
2bc416ba DJ |
623 | de_fault (to_rcmd, |
624 | (void (*) (char *, struct ui_file *)) | |
0d06e24b | 625 | tcomplain); |
2bc416ba DJ |
626 | de_fault (to_enable_exception_callback, |
627 | (struct symtab_and_line * (*) (enum exception_event_kind, int)) | |
0d06e24b | 628 | nosupport_runtime); |
2bc416ba DJ |
629 | de_fault (to_get_current_exception_event, |
630 | (struct exception_event_record * (*) (void)) | |
0d06e24b | 631 | nosupport_runtime); |
2bc416ba DJ |
632 | de_fault (to_pid_to_exec_file, |
633 | (char *(*) (int)) | |
0d06e24b | 634 | return_zero); |
2bc416ba DJ |
635 | de_fault (to_can_async_p, |
636 | (int (*) (void)) | |
0d06e24b | 637 | return_zero); |
2bc416ba DJ |
638 | de_fault (to_is_async_p, |
639 | (int (*) (void)) | |
0d06e24b | 640 | return_zero); |
2bc416ba DJ |
641 | de_fault (to_async, |
642 | (void (*) (void (*) (enum inferior_event_type, void*), void*)) | |
0d06e24b | 643 | tcomplain); |
c906108c | 644 | #undef de_fault |
c906108c | 645 | |
7998dfc3 AC |
646 | /* Finally, position the target-stack beneath the squashed |
647 | "current_target". That way code looking for a non-inherited | |
648 | target method can quickly and simply find it. */ | |
649 | current_target.beneath = target_stack; | |
c906108c SS |
650 | } |
651 | ||
52bb452f DJ |
652 | /* Mark OPS as a running target. This reverses the effect |
653 | of target_mark_exited. */ | |
654 | ||
655 | void | |
656 | target_mark_running (struct target_ops *ops) | |
657 | { | |
658 | struct target_ops *t; | |
659 | ||
660 | for (t = target_stack; t != NULL; t = t->beneath) | |
661 | if (t == ops) | |
662 | break; | |
663 | if (t == NULL) | |
664 | internal_error (__FILE__, __LINE__, | |
665 | "Attempted to mark unpushed target \"%s\" as running", | |
666 | ops->to_shortname); | |
667 | ||
668 | ops->to_has_execution = 1; | |
669 | ops->to_has_all_memory = 1; | |
670 | ops->to_has_memory = 1; | |
671 | ops->to_has_stack = 1; | |
672 | ops->to_has_registers = 1; | |
673 | ||
674 | update_current_target (); | |
675 | } | |
676 | ||
677 | /* Mark OPS as a non-running target. This reverses the effect | |
678 | of target_mark_running. */ | |
679 | ||
680 | void | |
681 | target_mark_exited (struct target_ops *ops) | |
682 | { | |
683 | struct target_ops *t; | |
684 | ||
685 | for (t = target_stack; t != NULL; t = t->beneath) | |
686 | if (t == ops) | |
687 | break; | |
688 | if (t == NULL) | |
689 | internal_error (__FILE__, __LINE__, | |
690 | "Attempted to mark unpushed target \"%s\" as running", | |
691 | ops->to_shortname); | |
692 | ||
693 | ops->to_has_execution = 0; | |
694 | ops->to_has_all_memory = 0; | |
695 | ops->to_has_memory = 0; | |
696 | ops->to_has_stack = 0; | |
697 | ops->to_has_registers = 0; | |
698 | ||
699 | update_current_target (); | |
700 | } | |
701 | ||
c906108c SS |
702 | /* Push a new target type into the stack of the existing target accessors, |
703 | possibly superseding some of the existing accessors. | |
704 | ||
705 | Result is zero if the pushed target ended up on top of the stack, | |
706 | nonzero if at least one target is on top of it. | |
707 | ||
708 | Rather than allow an empty stack, we always have the dummy target at | |
709 | the bottom stratum, so we can call the function vectors without | |
710 | checking them. */ | |
711 | ||
712 | int | |
fba45db2 | 713 | push_target (struct target_ops *t) |
c906108c | 714 | { |
258b763a | 715 | struct target_ops **cur; |
c906108c SS |
716 | |
717 | /* Check magic number. If wrong, it probably means someone changed | |
718 | the struct definition, but not all the places that initialize one. */ | |
719 | if (t->to_magic != OPS_MAGIC) | |
720 | { | |
c5aa993b JM |
721 | fprintf_unfiltered (gdb_stderr, |
722 | "Magic number of %s target struct wrong\n", | |
723 | t->to_shortname); | |
e2e0b3e5 | 724 | internal_error (__FILE__, __LINE__, _("failed internal consistency check")); |
c906108c SS |
725 | } |
726 | ||
258b763a AC |
727 | /* Find the proper stratum to install this target in. */ |
728 | for (cur = &target_stack; (*cur) != NULL; cur = &(*cur)->beneath) | |
c906108c | 729 | { |
258b763a | 730 | if ((int) (t->to_stratum) >= (int) (*cur)->to_stratum) |
c906108c SS |
731 | break; |
732 | } | |
733 | ||
258b763a | 734 | /* If there's already targets at this stratum, remove them. */ |
88c231eb | 735 | /* FIXME: cagney/2003-10-15: I think this should be popping all |
258b763a AC |
736 | targets to CUR, and not just those at this stratum level. */ |
737 | while ((*cur) != NULL && t->to_stratum == (*cur)->to_stratum) | |
738 | { | |
739 | /* There's already something at this stratum level. Close it, | |
740 | and un-hook it from the stack. */ | |
741 | struct target_ops *tmp = (*cur); | |
742 | (*cur) = (*cur)->beneath; | |
743 | tmp->beneath = NULL; | |
f1c07ab0 | 744 | target_close (tmp, 0); |
258b763a | 745 | } |
c906108c SS |
746 | |
747 | /* We have removed all targets in our stratum, now add the new one. */ | |
258b763a AC |
748 | t->beneath = (*cur); |
749 | (*cur) = t; | |
c906108c SS |
750 | |
751 | update_current_target (); | |
752 | ||
c906108c SS |
753 | if (targetdebug) |
754 | setup_target_debug (); | |
c906108c | 755 | |
258b763a AC |
756 | /* Not on top? */ |
757 | return (t != target_stack); | |
c906108c SS |
758 | } |
759 | ||
2bc416ba | 760 | /* Remove a target_ops vector from the stack, wherever it may be. |
c906108c SS |
761 | Return how many times it was removed (0 or 1). */ |
762 | ||
763 | int | |
fba45db2 | 764 | unpush_target (struct target_ops *t) |
c906108c | 765 | { |
258b763a AC |
766 | struct target_ops **cur; |
767 | struct target_ops *tmp; | |
c906108c | 768 | |
c906108c SS |
769 | /* Look for the specified target. Note that we assume that a target |
770 | can only occur once in the target stack. */ | |
771 | ||
258b763a AC |
772 | for (cur = &target_stack; (*cur) != NULL; cur = &(*cur)->beneath) |
773 | { | |
774 | if ((*cur) == t) | |
775 | break; | |
776 | } | |
c906108c | 777 | |
258b763a | 778 | if ((*cur) == NULL) |
c906108c SS |
779 | return 0; /* Didn't find target_ops, quit now */ |
780 | ||
5269965e AC |
781 | /* NOTE: cagney/2003-12-06: In '94 the close call was made |
782 | unconditional by moving it to before the above check that the | |
783 | target was in the target stack (something about "Change the way | |
784 | pushing and popping of targets work to support target overlays | |
785 | and inheritance"). This doesn't make much sense - only open | |
786 | targets should be closed. */ | |
787 | target_close (t, 0); | |
788 | ||
c906108c | 789 | /* Unchain the target */ |
258b763a AC |
790 | tmp = (*cur); |
791 | (*cur) = (*cur)->beneath; | |
792 | tmp->beneath = NULL; | |
c906108c SS |
793 | |
794 | update_current_target (); | |
c906108c SS |
795 | |
796 | return 1; | |
797 | } | |
798 | ||
799 | void | |
fba45db2 | 800 | pop_target (void) |
c906108c | 801 | { |
f1c07ab0 | 802 | target_close (¤t_target, 0); /* Let it clean up */ |
258b763a | 803 | if (unpush_target (target_stack) == 1) |
c906108c SS |
804 | return; |
805 | ||
c5aa993b JM |
806 | fprintf_unfiltered (gdb_stderr, |
807 | "pop_target couldn't find target %s\n", | |
808 | current_target.to_shortname); | |
e2e0b3e5 | 809 | internal_error (__FILE__, __LINE__, _("failed internal consistency check")); |
c906108c SS |
810 | } |
811 | ||
9e35dae4 DJ |
812 | /* Using the objfile specified in BATON, find the address for the |
813 | current thread's thread-local storage with offset OFFSET. */ | |
814 | CORE_ADDR | |
815 | target_translate_tls_address (struct objfile *objfile, CORE_ADDR offset) | |
816 | { | |
817 | volatile CORE_ADDR addr = 0; | |
818 | ||
819 | if (target_get_thread_local_address_p () | |
820 | && gdbarch_fetch_tls_load_module_address_p (current_gdbarch)) | |
821 | { | |
822 | ptid_t ptid = inferior_ptid; | |
823 | volatile struct gdb_exception ex; | |
824 | ||
825 | TRY_CATCH (ex, RETURN_MASK_ALL) | |
826 | { | |
827 | CORE_ADDR lm_addr; | |
828 | ||
829 | /* Fetch the load module address for this objfile. */ | |
830 | lm_addr = gdbarch_fetch_tls_load_module_address (current_gdbarch, | |
831 | objfile); | |
832 | /* If it's 0, throw the appropriate exception. */ | |
833 | if (lm_addr == 0) | |
834 | throw_error (TLS_LOAD_MODULE_NOT_FOUND_ERROR, | |
835 | _("TLS load module not found")); | |
836 | ||
837 | addr = target_get_thread_local_address (ptid, lm_addr, offset); | |
838 | } | |
839 | /* If an error occurred, print TLS related messages here. Otherwise, | |
840 | throw the error to some higher catcher. */ | |
841 | if (ex.reason < 0) | |
842 | { | |
843 | int objfile_is_library = (objfile->flags & OBJF_SHARED); | |
844 | ||
845 | switch (ex.error) | |
846 | { | |
847 | case TLS_NO_LIBRARY_SUPPORT_ERROR: | |
848 | error (_("Cannot find thread-local variables in this thread library.")); | |
849 | break; | |
850 | case TLS_LOAD_MODULE_NOT_FOUND_ERROR: | |
851 | if (objfile_is_library) | |
852 | error (_("Cannot find shared library `%s' in dynamic" | |
853 | " linker's load module list"), objfile->name); | |
854 | else | |
855 | error (_("Cannot find executable file `%s' in dynamic" | |
856 | " linker's load module list"), objfile->name); | |
857 | break; | |
858 | case TLS_NOT_ALLOCATED_YET_ERROR: | |
859 | if (objfile_is_library) | |
860 | error (_("The inferior has not yet allocated storage for" | |
861 | " thread-local variables in\n" | |
862 | "the shared library `%s'\n" | |
863 | "for %s"), | |
864 | objfile->name, target_pid_to_str (ptid)); | |
865 | else | |
866 | error (_("The inferior has not yet allocated storage for" | |
867 | " thread-local variables in\n" | |
868 | "the executable `%s'\n" | |
869 | "for %s"), | |
870 | objfile->name, target_pid_to_str (ptid)); | |
871 | break; | |
872 | case TLS_GENERIC_ERROR: | |
873 | if (objfile_is_library) | |
874 | error (_("Cannot find thread-local storage for %s, " | |
875 | "shared library %s:\n%s"), | |
876 | target_pid_to_str (ptid), | |
877 | objfile->name, ex.message); | |
878 | else | |
879 | error (_("Cannot find thread-local storage for %s, " | |
880 | "executable file %s:\n%s"), | |
881 | target_pid_to_str (ptid), | |
882 | objfile->name, ex.message); | |
883 | break; | |
884 | default: | |
885 | throw_exception (ex); | |
886 | break; | |
887 | } | |
888 | } | |
889 | } | |
890 | /* It wouldn't be wrong here to try a gdbarch method, too; finding | |
891 | TLS is an ABI-specific thing. But we don't do that yet. */ | |
892 | else | |
893 | error (_("Cannot find thread-local variables on this target")); | |
894 | ||
895 | return addr; | |
896 | } | |
897 | ||
c906108c SS |
898 | #undef MIN |
899 | #define MIN(A, B) (((A) <= (B)) ? (A) : (B)) | |
900 | ||
901 | /* target_read_string -- read a null terminated string, up to LEN bytes, | |
902 | from MEMADDR in target. Set *ERRNOP to the errno code, or 0 if successful. | |
903 | Set *STRING to a pointer to malloc'd memory containing the data; the caller | |
904 | is responsible for freeing it. Return the number of bytes successfully | |
905 | read. */ | |
906 | ||
907 | int | |
fba45db2 | 908 | target_read_string (CORE_ADDR memaddr, char **string, int len, int *errnop) |
c906108c SS |
909 | { |
910 | int tlen, origlen, offset, i; | |
1b0ba102 | 911 | gdb_byte buf[4]; |
c906108c SS |
912 | int errcode = 0; |
913 | char *buffer; | |
914 | int buffer_allocated; | |
915 | char *bufptr; | |
916 | unsigned int nbytes_read = 0; | |
917 | ||
918 | /* Small for testing. */ | |
919 | buffer_allocated = 4; | |
920 | buffer = xmalloc (buffer_allocated); | |
921 | bufptr = buffer; | |
922 | ||
923 | origlen = len; | |
924 | ||
925 | while (len > 0) | |
926 | { | |
927 | tlen = MIN (len, 4 - (memaddr & 3)); | |
928 | offset = memaddr & 3; | |
929 | ||
1b0ba102 | 930 | errcode = target_read_memory (memaddr & ~3, buf, sizeof buf); |
c906108c SS |
931 | if (errcode != 0) |
932 | { | |
933 | /* The transfer request might have crossed the boundary to an | |
934 | unallocated region of memory. Retry the transfer, requesting | |
935 | a single byte. */ | |
936 | tlen = 1; | |
937 | offset = 0; | |
b8eb5af0 | 938 | errcode = target_read_memory (memaddr, buf, 1); |
c906108c SS |
939 | if (errcode != 0) |
940 | goto done; | |
941 | } | |
942 | ||
943 | if (bufptr - buffer + tlen > buffer_allocated) | |
944 | { | |
945 | unsigned int bytes; | |
946 | bytes = bufptr - buffer; | |
947 | buffer_allocated *= 2; | |
948 | buffer = xrealloc (buffer, buffer_allocated); | |
949 | bufptr = buffer + bytes; | |
950 | } | |
951 | ||
952 | for (i = 0; i < tlen; i++) | |
953 | { | |
954 | *bufptr++ = buf[i + offset]; | |
955 | if (buf[i + offset] == '\000') | |
956 | { | |
957 | nbytes_read += i + 1; | |
958 | goto done; | |
959 | } | |
960 | } | |
961 | ||
962 | memaddr += tlen; | |
963 | len -= tlen; | |
964 | nbytes_read += tlen; | |
965 | } | |
c5aa993b | 966 | done: |
c906108c SS |
967 | if (errnop != NULL) |
968 | *errnop = errcode; | |
969 | if (string != NULL) | |
970 | *string = buffer; | |
971 | return nbytes_read; | |
972 | } | |
973 | ||
8db32d44 AC |
974 | /* Find a section containing ADDR. */ |
975 | struct section_table * | |
976 | target_section_by_addr (struct target_ops *target, CORE_ADDR addr) | |
977 | { | |
978 | struct section_table *secp; | |
979 | for (secp = target->to_sections; | |
980 | secp < target->to_sections_end; | |
981 | secp++) | |
982 | { | |
983 | if (addr >= secp->addr && addr < secp->endaddr) | |
984 | return secp; | |
985 | } | |
986 | return NULL; | |
987 | } | |
988 | ||
cf7a04e8 DJ |
989 | /* Perform a partial memory transfer. The arguments and return |
990 | value are just as for target_xfer_partial. */ | |
991 | ||
992 | static LONGEST | |
993 | memory_xfer_partial (struct target_ops *ops, void *readbuf, const void *writebuf, | |
994 | ULONGEST memaddr, LONGEST len) | |
0779438d | 995 | { |
cf7a04e8 DJ |
996 | LONGEST res; |
997 | int reg_len; | |
998 | struct mem_region *region; | |
999 | ||
1000 | /* Zero length requests are ok and require no work. */ | |
1001 | if (len == 0) | |
1002 | return 0; | |
1003 | ||
1004 | /* Try the executable file, if "trust-readonly-sections" is set. */ | |
1005 | if (readbuf != NULL && trust_readonly) | |
1006 | { | |
1007 | struct section_table *secp; | |
1008 | ||
1009 | secp = target_section_by_addr (ops, memaddr); | |
1010 | if (secp != NULL | |
1011 | && (bfd_get_section_flags (secp->bfd, secp->the_bfd_section) | |
1012 | & SEC_READONLY)) | |
1013 | return xfer_memory (memaddr, readbuf, len, 0, NULL, ops); | |
1014 | } | |
1015 | ||
1016 | /* Try GDB's internal data cache. */ | |
1017 | region = lookup_mem_region (memaddr); | |
4b5752d0 VP |
1018 | /* region->hi == 0 means there's no upper bound. */ |
1019 | if (memaddr + len < region->hi || region->hi == 0) | |
cf7a04e8 DJ |
1020 | reg_len = len; |
1021 | else | |
1022 | reg_len = region->hi - memaddr; | |
1023 | ||
1024 | switch (region->attrib.mode) | |
1025 | { | |
1026 | case MEM_RO: | |
1027 | if (writebuf != NULL) | |
1028 | return -1; | |
1029 | break; | |
1030 | ||
1031 | case MEM_WO: | |
1032 | if (readbuf != NULL) | |
1033 | return -1; | |
1034 | break; | |
a76d924d DJ |
1035 | |
1036 | case MEM_FLASH: | |
1037 | /* We only support writing to flash during "load" for now. */ | |
1038 | if (writebuf != NULL) | |
1039 | error (_("Writing to flash memory forbidden in this context")); | |
1040 | break; | |
4b5752d0 VP |
1041 | |
1042 | case MEM_NONE: | |
1043 | return -1; | |
cf7a04e8 DJ |
1044 | } |
1045 | ||
1046 | if (region->attrib.cache) | |
1047 | { | |
1048 | /* FIXME drow/2006-08-09: This call discards OPS, so the raw | |
1049 | memory request will start back at current_target. */ | |
1050 | if (readbuf != NULL) | |
1051 | res = dcache_xfer_memory (target_dcache, memaddr, readbuf, | |
1052 | reg_len, 0); | |
1053 | else | |
1054 | /* FIXME drow/2006-08-09: If we're going to preserve const | |
1055 | correctness dcache_xfer_memory should take readbuf and | |
1056 | writebuf. */ | |
1057 | res = dcache_xfer_memory (target_dcache, memaddr, | |
1058 | (void *) writebuf, | |
1059 | reg_len, 1); | |
1060 | if (res <= 0) | |
1061 | return -1; | |
1062 | else | |
1063 | return res; | |
1064 | } | |
1065 | ||
1066 | /* If none of those methods found the memory we wanted, fall back | |
1067 | to a target partial transfer. Normally a single call to | |
1068 | to_xfer_partial is enough; if it doesn't recognize an object | |
1069 | it will call the to_xfer_partial of the next target down. | |
1070 | But for memory this won't do. Memory is the only target | |
1071 | object which can be read from more than one valid target. | |
1072 | A core file, for instance, could have some of memory but | |
1073 | delegate other bits to the target below it. So, we must | |
1074 | manually try all targets. */ | |
1075 | ||
1076 | do | |
1077 | { | |
1078 | res = ops->to_xfer_partial (ops, TARGET_OBJECT_MEMORY, NULL, | |
4b5752d0 | 1079 | readbuf, writebuf, memaddr, reg_len); |
cf7a04e8 DJ |
1080 | if (res > 0) |
1081 | return res; | |
1082 | ||
1083 | ops = ops->beneath; | |
1084 | } | |
1085 | while (ops != NULL); | |
1086 | ||
1087 | /* If we still haven't got anything, return the last error. We | |
1088 | give up. */ | |
1089 | return res; | |
0779438d AC |
1090 | } |
1091 | ||
27394598 AC |
1092 | static LONGEST |
1093 | target_xfer_partial (struct target_ops *ops, | |
1094 | enum target_object object, const char *annex, | |
1095 | void *readbuf, const void *writebuf, | |
1096 | ULONGEST offset, LONGEST len) | |
1097 | { | |
1098 | LONGEST retval; | |
1099 | ||
1100 | gdb_assert (ops->to_xfer_partial != NULL); | |
cf7a04e8 DJ |
1101 | |
1102 | /* If this is a memory transfer, let the memory-specific code | |
1103 | have a look at it instead. Memory transfers are more | |
1104 | complicated. */ | |
1105 | if (object == TARGET_OBJECT_MEMORY) | |
1106 | retval = memory_xfer_partial (ops, readbuf, writebuf, offset, len); | |
1107 | else | |
1108 | { | |
1109 | enum target_object raw_object = object; | |
1110 | ||
1111 | /* If this is a raw memory transfer, request the normal | |
1112 | memory object from other layers. */ | |
1113 | if (raw_object == TARGET_OBJECT_RAW_MEMORY) | |
1114 | raw_object = TARGET_OBJECT_MEMORY; | |
1115 | ||
1116 | retval = ops->to_xfer_partial (ops, raw_object, annex, readbuf, | |
1117 | writebuf, offset, len); | |
1118 | } | |
1119 | ||
27394598 AC |
1120 | if (targetdebug) |
1121 | { | |
1122 | const unsigned char *myaddr = NULL; | |
1123 | ||
1124 | fprintf_unfiltered (gdb_stdlog, | |
1125 | "%s:target_xfer_partial (%d, %s, 0x%lx, 0x%lx, 0x%s, %s) = %s", | |
1126 | ops->to_shortname, | |
1127 | (int) object, | |
1128 | (annex ? annex : "(null)"), | |
1129 | (long) readbuf, (long) writebuf, | |
1130 | paddr_nz (offset), paddr_d (len), paddr_d (retval)); | |
1131 | ||
1132 | if (readbuf) | |
1133 | myaddr = readbuf; | |
1134 | if (writebuf) | |
1135 | myaddr = writebuf; | |
1136 | if (retval > 0 && myaddr != NULL) | |
1137 | { | |
1138 | int i; | |
2bc416ba | 1139 | |
27394598 AC |
1140 | fputs_unfiltered (", bytes =", gdb_stdlog); |
1141 | for (i = 0; i < retval; i++) | |
1142 | { | |
1143 | if ((((long) &(myaddr[i])) & 0xf) == 0) | |
1144 | { | |
1145 | if (targetdebug < 2 && i > 0) | |
1146 | { | |
1147 | fprintf_unfiltered (gdb_stdlog, " ..."); | |
1148 | break; | |
1149 | } | |
1150 | fprintf_unfiltered (gdb_stdlog, "\n"); | |
1151 | } | |
2bc416ba | 1152 | |
27394598 AC |
1153 | fprintf_unfiltered (gdb_stdlog, " %02x", myaddr[i] & 0xff); |
1154 | } | |
1155 | } | |
2bc416ba | 1156 | |
27394598 AC |
1157 | fputc_unfiltered ('\n', gdb_stdlog); |
1158 | } | |
1159 | return retval; | |
1160 | } | |
1161 | ||
c906108c SS |
1162 | /* Read LEN bytes of target memory at address MEMADDR, placing the results in |
1163 | GDB's memory at MYADDR. Returns either 0 for success or an errno value | |
1164 | if any error occurs. | |
1165 | ||
1166 | If an error occurs, no guarantee is made about the contents of the data at | |
1167 | MYADDR. In particular, the caller should not depend upon partial reads | |
1168 | filling the buffer with good data. There is no way for the caller to know | |
1169 | how much good data might have been transfered anyway. Callers that can | |
cf7a04e8 DJ |
1170 | deal with partial reads should call target_read (which will retry until |
1171 | it makes no progress, and then return how much was transferred). */ | |
c906108c SS |
1172 | |
1173 | int | |
fc1a4b47 | 1174 | target_read_memory (CORE_ADDR memaddr, gdb_byte *myaddr, int len) |
c906108c | 1175 | { |
cf7a04e8 DJ |
1176 | if (target_read (¤t_target, TARGET_OBJECT_MEMORY, NULL, |
1177 | myaddr, memaddr, len) == len) | |
1178 | return 0; | |
0779438d | 1179 | else |
cf7a04e8 | 1180 | return EIO; |
c906108c SS |
1181 | } |
1182 | ||
c906108c | 1183 | int |
fc1a4b47 | 1184 | target_write_memory (CORE_ADDR memaddr, const gdb_byte *myaddr, int len) |
c906108c | 1185 | { |
cf7a04e8 DJ |
1186 | if (target_write (¤t_target, TARGET_OBJECT_MEMORY, NULL, |
1187 | myaddr, memaddr, len) == len) | |
1188 | return 0; | |
0779438d | 1189 | else |
cf7a04e8 | 1190 | return EIO; |
c906108c | 1191 | } |
c5aa993b | 1192 | |
fd79ecee DJ |
1193 | /* Fetch the target's memory map. */ |
1194 | ||
1195 | VEC(mem_region_s) * | |
1196 | target_memory_map (void) | |
1197 | { | |
1198 | VEC(mem_region_s) *result; | |
1199 | struct mem_region *last_one, *this_one; | |
1200 | int ix; | |
1201 | struct target_ops *t; | |
1202 | ||
1203 | if (targetdebug) | |
1204 | fprintf_unfiltered (gdb_stdlog, "target_memory_map ()\n"); | |
1205 | ||
1206 | for (t = current_target.beneath; t != NULL; t = t->beneath) | |
1207 | if (t->to_memory_map != NULL) | |
1208 | break; | |
1209 | ||
1210 | if (t == NULL) | |
1211 | return NULL; | |
1212 | ||
1213 | result = t->to_memory_map (t); | |
1214 | if (result == NULL) | |
1215 | return NULL; | |
1216 | ||
1217 | qsort (VEC_address (mem_region_s, result), | |
1218 | VEC_length (mem_region_s, result), | |
1219 | sizeof (struct mem_region), mem_region_cmp); | |
1220 | ||
1221 | /* Check that regions do not overlap. Simultaneously assign | |
1222 | a numbering for the "mem" commands to use to refer to | |
1223 | each region. */ | |
1224 | last_one = NULL; | |
1225 | for (ix = 0; VEC_iterate (mem_region_s, result, ix, this_one); ix++) | |
1226 | { | |
1227 | this_one->number = ix; | |
1228 | ||
1229 | if (last_one && last_one->hi > this_one->lo) | |
1230 | { | |
1231 | warning (_("Overlapping regions in memory map: ignoring")); | |
1232 | VEC_free (mem_region_s, result); | |
1233 | return NULL; | |
1234 | } | |
1235 | last_one = this_one; | |
1236 | } | |
1237 | ||
1238 | return result; | |
1239 | } | |
1240 | ||
a76d924d DJ |
1241 | void |
1242 | target_flash_erase (ULONGEST address, LONGEST length) | |
1243 | { | |
1244 | struct target_ops *t; | |
1245 | ||
1246 | for (t = current_target.beneath; t != NULL; t = t->beneath) | |
1247 | if (t->to_flash_erase != NULL) | |
1248 | { | |
1249 | if (targetdebug) | |
1250 | fprintf_unfiltered (gdb_stdlog, "target_flash_erase (%s, %s)\n", | |
1251 | paddr (address), phex (length, 0)); | |
1252 | return t->to_flash_erase (t, address, length); | |
1253 | } | |
1254 | ||
1255 | tcomplain (); | |
1256 | } | |
1257 | ||
1258 | void | |
1259 | target_flash_done (void) | |
1260 | { | |
1261 | struct target_ops *t; | |
1262 | ||
1263 | for (t = current_target.beneath; t != NULL; t = t->beneath) | |
1264 | if (t->to_flash_done != NULL) | |
1265 | { | |
1266 | if (targetdebug) | |
1267 | fprintf_unfiltered (gdb_stdlog, "target_flash_done\n"); | |
1268 | return t->to_flash_done (t); | |
1269 | } | |
1270 | ||
1271 | tcomplain (); | |
1272 | } | |
1273 | ||
4aa7a7f5 JJ |
1274 | #ifndef target_stopped_data_address_p |
1275 | int | |
1276 | target_stopped_data_address_p (struct target_ops *target) | |
1277 | { | |
aa869812 AC |
1278 | if (target->to_stopped_data_address |
1279 | == (int (*) (struct target_ops *, CORE_ADDR *)) return_zero) | |
4aa7a7f5 | 1280 | return 0; |
aa869812 AC |
1281 | if (target->to_stopped_data_address == debug_to_stopped_data_address |
1282 | && (debug_target.to_stopped_data_address | |
1283 | == (int (*) (struct target_ops *, CORE_ADDR *)) return_zero)) | |
1284 | return 0; | |
1285 | return 1; | |
4aa7a7f5 JJ |
1286 | } |
1287 | #endif | |
1288 | ||
920d2a44 AC |
1289 | static void |
1290 | show_trust_readonly (struct ui_file *file, int from_tty, | |
1291 | struct cmd_list_element *c, const char *value) | |
1292 | { | |
1293 | fprintf_filtered (file, _("\ | |
1294 | Mode for reading from readonly sections is %s.\n"), | |
1295 | value); | |
1296 | } | |
3a11626d | 1297 | |
1e3ff5ad AC |
1298 | /* More generic transfers. */ |
1299 | ||
0088c768 | 1300 | static LONGEST |
8aa91c1e | 1301 | default_xfer_partial (struct target_ops *ops, enum target_object object, |
2bc416ba | 1302 | const char *annex, gdb_byte *readbuf, |
1b0ba102 | 1303 | const gdb_byte *writebuf, ULONGEST offset, LONGEST len) |
0088c768 AC |
1304 | { |
1305 | if (object == TARGET_OBJECT_MEMORY | |
c8e73a31 AC |
1306 | && ops->deprecated_xfer_memory != NULL) |
1307 | /* If available, fall back to the target's | |
1308 | "deprecated_xfer_memory" method. */ | |
0088c768 | 1309 | { |
4b8a223f | 1310 | int xfered = -1; |
0088c768 | 1311 | errno = 0; |
4b8a223f AC |
1312 | if (writebuf != NULL) |
1313 | { | |
1314 | void *buffer = xmalloc (len); | |
1315 | struct cleanup *cleanup = make_cleanup (xfree, buffer); | |
1316 | memcpy (buffer, writebuf, len); | |
c8e73a31 AC |
1317 | xfered = ops->deprecated_xfer_memory (offset, buffer, len, |
1318 | 1/*write*/, NULL, ops); | |
4b8a223f AC |
1319 | do_cleanups (cleanup); |
1320 | } | |
1321 | if (readbuf != NULL) | |
c8e73a31 AC |
1322 | xfered = ops->deprecated_xfer_memory (offset, readbuf, len, 0/*read*/, |
1323 | NULL, ops); | |
0088c768 AC |
1324 | if (xfered > 0) |
1325 | return xfered; | |
1326 | else if (xfered == 0 && errno == 0) | |
c8e73a31 AC |
1327 | /* "deprecated_xfer_memory" uses 0, cross checked against |
1328 | ERRNO as one indication of an error. */ | |
0088c768 AC |
1329 | return 0; |
1330 | else | |
1331 | return -1; | |
1332 | } | |
1333 | else if (ops->beneath != NULL) | |
cf7a04e8 DJ |
1334 | return ops->beneath->to_xfer_partial (ops->beneath, object, annex, |
1335 | readbuf, writebuf, offset, len); | |
1336 | else | |
1337 | return -1; | |
1338 | } | |
1339 | ||
1340 | /* The xfer_partial handler for the topmost target. Unlike the default, | |
1341 | it does not need to handle memory specially; it just passes all | |
1342 | requests down the stack. */ | |
1343 | ||
1344 | static LONGEST | |
1345 | current_xfer_partial (struct target_ops *ops, enum target_object object, | |
1346 | const char *annex, gdb_byte *readbuf, | |
1347 | const gdb_byte *writebuf, ULONGEST offset, LONGEST len) | |
1348 | { | |
1349 | if (ops->beneath != NULL) | |
1350 | return ops->beneath->to_xfer_partial (ops->beneath, object, annex, | |
1351 | readbuf, writebuf, offset, len); | |
0088c768 AC |
1352 | else |
1353 | return -1; | |
1354 | } | |
1355 | ||
1356 | /* Target vector read/write partial wrapper functions. | |
1357 | ||
1358 | NOTE: cagney/2003-10-21: I wonder if having "to_xfer_partial | |
1359 | (inbuf, outbuf)", instead of separate read/write methods, make life | |
1360 | easier. */ | |
1361 | ||
13547ab6 | 1362 | static LONGEST |
1e3ff5ad AC |
1363 | target_read_partial (struct target_ops *ops, |
1364 | enum target_object object, | |
1b0ba102 | 1365 | const char *annex, gdb_byte *buf, |
1e3ff5ad AC |
1366 | ULONGEST offset, LONGEST len) |
1367 | { | |
27394598 | 1368 | return target_xfer_partial (ops, object, annex, buf, NULL, offset, len); |
1e3ff5ad AC |
1369 | } |
1370 | ||
13547ab6 | 1371 | static LONGEST |
1e3ff5ad AC |
1372 | target_write_partial (struct target_ops *ops, |
1373 | enum target_object object, | |
1b0ba102 | 1374 | const char *annex, const gdb_byte *buf, |
1e3ff5ad AC |
1375 | ULONGEST offset, LONGEST len) |
1376 | { | |
27394598 | 1377 | return target_xfer_partial (ops, object, annex, NULL, buf, offset, len); |
1e3ff5ad AC |
1378 | } |
1379 | ||
1380 | /* Wrappers to perform the full transfer. */ | |
1381 | LONGEST | |
1382 | target_read (struct target_ops *ops, | |
1383 | enum target_object object, | |
1b0ba102 | 1384 | const char *annex, gdb_byte *buf, |
1e3ff5ad AC |
1385 | ULONGEST offset, LONGEST len) |
1386 | { | |
1387 | LONGEST xfered = 0; | |
1388 | while (xfered < len) | |
1389 | { | |
0088c768 | 1390 | LONGEST xfer = target_read_partial (ops, object, annex, |
fc1a4b47 | 1391 | (gdb_byte *) buf + xfered, |
0088c768 | 1392 | offset + xfered, len - xfered); |
1e3ff5ad | 1393 | /* Call an observer, notifying them of the xfer progress? */ |
13547ab6 DJ |
1394 | if (xfer == 0) |
1395 | return xfered; | |
1396 | if (xfer < 0) | |
0088c768 | 1397 | return -1; |
1e3ff5ad AC |
1398 | xfered += xfer; |
1399 | QUIT; | |
1400 | } | |
1401 | return len; | |
1402 | } | |
1403 | ||
cf7a04e8 DJ |
1404 | /* An alternative to target_write with progress callbacks. */ |
1405 | ||
1e3ff5ad | 1406 | LONGEST |
cf7a04e8 DJ |
1407 | target_write_with_progress (struct target_ops *ops, |
1408 | enum target_object object, | |
1409 | const char *annex, const gdb_byte *buf, | |
1410 | ULONGEST offset, LONGEST len, | |
1411 | void (*progress) (ULONGEST, void *), void *baton) | |
1e3ff5ad AC |
1412 | { |
1413 | LONGEST xfered = 0; | |
a76d924d DJ |
1414 | |
1415 | /* Give the progress callback a chance to set up. */ | |
1416 | if (progress) | |
1417 | (*progress) (0, baton); | |
1418 | ||
1e3ff5ad AC |
1419 | while (xfered < len) |
1420 | { | |
1421 | LONGEST xfer = target_write_partial (ops, object, annex, | |
fc1a4b47 | 1422 | (gdb_byte *) buf + xfered, |
1e3ff5ad | 1423 | offset + xfered, len - xfered); |
cf7a04e8 | 1424 | |
13547ab6 DJ |
1425 | if (xfer == 0) |
1426 | return xfered; | |
1427 | if (xfer < 0) | |
0088c768 | 1428 | return -1; |
cf7a04e8 DJ |
1429 | |
1430 | if (progress) | |
1431 | (*progress) (xfer, baton); | |
1432 | ||
1e3ff5ad AC |
1433 | xfered += xfer; |
1434 | QUIT; | |
1435 | } | |
1436 | return len; | |
1437 | } | |
1438 | ||
cf7a04e8 DJ |
1439 | LONGEST |
1440 | target_write (struct target_ops *ops, | |
1441 | enum target_object object, | |
1442 | const char *annex, const gdb_byte *buf, | |
1443 | ULONGEST offset, LONGEST len) | |
1444 | { | |
1445 | return target_write_with_progress (ops, object, annex, buf, offset, len, | |
1446 | NULL, NULL); | |
1447 | } | |
1448 | ||
159f81f3 DJ |
1449 | /* Read OBJECT/ANNEX using OPS. Store the result in *BUF_P and return |
1450 | the size of the transferred data. PADDING additional bytes are | |
1451 | available in *BUF_P. This is a helper function for | |
1452 | target_read_alloc; see the declaration of that function for more | |
1453 | information. */ | |
13547ab6 | 1454 | |
159f81f3 DJ |
1455 | static LONGEST |
1456 | target_read_alloc_1 (struct target_ops *ops, enum target_object object, | |
1457 | const char *annex, gdb_byte **buf_p, int padding) | |
13547ab6 DJ |
1458 | { |
1459 | size_t buf_alloc, buf_pos; | |
1460 | gdb_byte *buf; | |
1461 | LONGEST n; | |
1462 | ||
1463 | /* This function does not have a length parameter; it reads the | |
1464 | entire OBJECT). Also, it doesn't support objects fetched partly | |
1465 | from one target and partly from another (in a different stratum, | |
1466 | e.g. a core file and an executable). Both reasons make it | |
1467 | unsuitable for reading memory. */ | |
1468 | gdb_assert (object != TARGET_OBJECT_MEMORY); | |
1469 | ||
1470 | /* Start by reading up to 4K at a time. The target will throttle | |
1471 | this number down if necessary. */ | |
1472 | buf_alloc = 4096; | |
1473 | buf = xmalloc (buf_alloc); | |
1474 | buf_pos = 0; | |
1475 | while (1) | |
1476 | { | |
1477 | n = target_read_partial (ops, object, annex, &buf[buf_pos], | |
159f81f3 | 1478 | buf_pos, buf_alloc - buf_pos - padding); |
13547ab6 DJ |
1479 | if (n < 0) |
1480 | { | |
1481 | /* An error occurred. */ | |
1482 | xfree (buf); | |
1483 | return -1; | |
1484 | } | |
1485 | else if (n == 0) | |
1486 | { | |
1487 | /* Read all there was. */ | |
1488 | if (buf_pos == 0) | |
1489 | xfree (buf); | |
1490 | else | |
1491 | *buf_p = buf; | |
1492 | return buf_pos; | |
1493 | } | |
1494 | ||
1495 | buf_pos += n; | |
1496 | ||
1497 | /* If the buffer is filling up, expand it. */ | |
1498 | if (buf_alloc < buf_pos * 2) | |
1499 | { | |
1500 | buf_alloc *= 2; | |
1501 | buf = xrealloc (buf, buf_alloc); | |
1502 | } | |
1503 | ||
1504 | QUIT; | |
1505 | } | |
1506 | } | |
1507 | ||
159f81f3 DJ |
1508 | /* Read OBJECT/ANNEX using OPS. Store the result in *BUF_P and return |
1509 | the size of the transferred data. See the declaration in "target.h" | |
1510 | function for more information about the return value. */ | |
1511 | ||
1512 | LONGEST | |
1513 | target_read_alloc (struct target_ops *ops, enum target_object object, | |
1514 | const char *annex, gdb_byte **buf_p) | |
1515 | { | |
1516 | return target_read_alloc_1 (ops, object, annex, buf_p, 0); | |
1517 | } | |
1518 | ||
1519 | /* Read OBJECT/ANNEX using OPS. The result is NUL-terminated and | |
1520 | returned as a string, allocated using xmalloc. If an error occurs | |
1521 | or the transfer is unsupported, NULL is returned. Empty objects | |
1522 | are returned as allocated but empty strings. A warning is issued | |
1523 | if the result contains any embedded NUL bytes. */ | |
1524 | ||
1525 | char * | |
1526 | target_read_stralloc (struct target_ops *ops, enum target_object object, | |
1527 | const char *annex) | |
1528 | { | |
1529 | gdb_byte *buffer; | |
1530 | LONGEST transferred; | |
1531 | ||
1532 | transferred = target_read_alloc_1 (ops, object, annex, &buffer, 1); | |
1533 | ||
1534 | if (transferred < 0) | |
1535 | return NULL; | |
1536 | ||
1537 | if (transferred == 0) | |
1538 | return xstrdup (""); | |
1539 | ||
1540 | buffer[transferred] = 0; | |
1541 | if (strlen (buffer) < transferred) | |
1542 | warning (_("target object %d, annex %s, " | |
1543 | "contained unexpected null characters"), | |
1544 | (int) object, annex ? annex : "(none)"); | |
1545 | ||
1546 | return (char *) buffer; | |
1547 | } | |
1548 | ||
b6591e8b AC |
1549 | /* Memory transfer methods. */ |
1550 | ||
1551 | void | |
1b0ba102 | 1552 | get_target_memory (struct target_ops *ops, CORE_ADDR addr, gdb_byte *buf, |
b6591e8b AC |
1553 | LONGEST len) |
1554 | { | |
1555 | if (target_read (ops, TARGET_OBJECT_MEMORY, NULL, buf, addr, len) | |
1556 | != len) | |
1557 | memory_error (EIO, addr); | |
1558 | } | |
1559 | ||
1560 | ULONGEST | |
1561 | get_target_memory_unsigned (struct target_ops *ops, | |
1562 | CORE_ADDR addr, int len) | |
1563 | { | |
f6519ebc | 1564 | gdb_byte buf[sizeof (ULONGEST)]; |
b6591e8b AC |
1565 | |
1566 | gdb_assert (len <= sizeof (buf)); | |
1567 | get_target_memory (ops, addr, buf, len); | |
1568 | return extract_unsigned_integer (buf, len); | |
1569 | } | |
1570 | ||
c906108c | 1571 | static void |
fba45db2 | 1572 | target_info (char *args, int from_tty) |
c906108c SS |
1573 | { |
1574 | struct target_ops *t; | |
c906108c | 1575 | int has_all_mem = 0; |
c5aa993b | 1576 | |
c906108c | 1577 | if (symfile_objfile != NULL) |
a3f17187 | 1578 | printf_unfiltered (_("Symbols from \"%s\".\n"), symfile_objfile->name); |
c906108c | 1579 | |
258b763a | 1580 | for (t = target_stack; t != NULL; t = t->beneath) |
c906108c | 1581 | { |
c906108c SS |
1582 | if (!t->to_has_memory) |
1583 | continue; | |
1584 | ||
c5aa993b | 1585 | if ((int) (t->to_stratum) <= (int) dummy_stratum) |
c906108c SS |
1586 | continue; |
1587 | if (has_all_mem) | |
a3f17187 | 1588 | printf_unfiltered (_("\tWhile running this, GDB does not access memory from...\n")); |
c5aa993b JM |
1589 | printf_unfiltered ("%s:\n", t->to_longname); |
1590 | (t->to_files_info) (t); | |
c906108c SS |
1591 | has_all_mem = t->to_has_all_memory; |
1592 | } | |
1593 | } | |
1594 | ||
fd79ecee DJ |
1595 | /* This function is called before any new inferior is created, e.g. |
1596 | by running a program, attaching, or connecting to a target. | |
1597 | It cleans up any state from previous invocations which might | |
1598 | change between runs. This is a subset of what target_preopen | |
1599 | resets (things which might change between targets). */ | |
1600 | ||
1601 | void | |
1602 | target_pre_inferior (int from_tty) | |
1603 | { | |
1604 | invalidate_target_mem_regions (); | |
1605 | } | |
1606 | ||
c906108c SS |
1607 | /* This is to be called by the open routine before it does |
1608 | anything. */ | |
1609 | ||
1610 | void | |
fba45db2 | 1611 | target_preopen (int from_tty) |
c906108c | 1612 | { |
c5aa993b | 1613 | dont_repeat (); |
c906108c SS |
1614 | |
1615 | if (target_has_execution) | |
c5aa993b | 1616 | { |
adf40b2e | 1617 | if (!from_tty |
e2e0b3e5 | 1618 | || query (_("A program is being debugged already. Kill it? "))) |
c5aa993b | 1619 | target_kill (); |
c906108c | 1620 | else |
8a3fe4f8 | 1621 | error (_("Program not killed.")); |
c906108c SS |
1622 | } |
1623 | ||
1624 | /* Calling target_kill may remove the target from the stack. But if | |
1625 | it doesn't (which seems like a win for UDI), remove it now. */ | |
1626 | ||
1627 | if (target_has_execution) | |
1628 | pop_target (); | |
fd79ecee DJ |
1629 | |
1630 | target_pre_inferior (from_tty); | |
c906108c SS |
1631 | } |
1632 | ||
1633 | /* Detach a target after doing deferred register stores. */ | |
1634 | ||
1635 | void | |
fba45db2 | 1636 | target_detach (char *args, int from_tty) |
c906108c | 1637 | { |
c906108c SS |
1638 | (current_target.to_detach) (args, from_tty); |
1639 | } | |
1640 | ||
6ad8ae5c DJ |
1641 | void |
1642 | target_disconnect (char *args, int from_tty) | |
1643 | { | |
597320e7 DJ |
1644 | struct target_ops *t; |
1645 | ||
1646 | for (t = current_target.beneath; t != NULL; t = t->beneath) | |
1647 | if (t->to_disconnect != NULL) | |
1648 | { | |
1649 | if (targetdebug) | |
1650 | fprintf_unfiltered (gdb_stdlog, "target_disconnect (%s, %d)\n", | |
1651 | args, from_tty); | |
1652 | t->to_disconnect (t, args, from_tty); | |
1653 | return; | |
1654 | } | |
1655 | ||
1656 | tcomplain (); | |
6ad8ae5c DJ |
1657 | } |
1658 | ||
ed9a39eb JM |
1659 | int |
1660 | target_async_mask (int mask) | |
1661 | { | |
1662 | int saved_async_masked_status = target_async_mask_value; | |
1663 | target_async_mask_value = mask; | |
1664 | return saved_async_masked_status; | |
1665 | } | |
1666 | ||
ee057212 DJ |
1667 | /* Look through the list of possible targets for a target that can |
1668 | follow forks. */ | |
1669 | ||
1670 | int | |
1671 | target_follow_fork (int follow_child) | |
1672 | { | |
1673 | struct target_ops *t; | |
1674 | ||
1675 | for (t = current_target.beneath; t != NULL; t = t->beneath) | |
1676 | { | |
1677 | if (t->to_follow_fork != NULL) | |
1678 | { | |
1679 | int retval = t->to_follow_fork (t, follow_child); | |
1680 | if (targetdebug) | |
1681 | fprintf_unfiltered (gdb_stdlog, "target_follow_fork (%d) = %d\n", | |
1682 | follow_child, retval); | |
1683 | return retval; | |
1684 | } | |
1685 | } | |
1686 | ||
1687 | /* Some target returned a fork event, but did not know how to follow it. */ | |
1688 | internal_error (__FILE__, __LINE__, | |
1689 | "could not find a target to follow fork"); | |
1690 | } | |
1691 | ||
c906108c SS |
1692 | /* Look through the list of possible targets for a target that can |
1693 | execute a run or attach command without any other data. This is | |
1694 | used to locate the default process stratum. | |
1695 | ||
1696 | Result is always valid (error() is called for errors). */ | |
1697 | ||
1698 | static struct target_ops * | |
fba45db2 | 1699 | find_default_run_target (char *do_mesg) |
c906108c SS |
1700 | { |
1701 | struct target_ops **t; | |
1702 | struct target_ops *runable = NULL; | |
1703 | int count; | |
1704 | ||
1705 | count = 0; | |
1706 | ||
1707 | for (t = target_structs; t < target_structs + target_struct_size; | |
1708 | ++t) | |
1709 | { | |
c5aa993b | 1710 | if ((*t)->to_can_run && target_can_run (*t)) |
c906108c SS |
1711 | { |
1712 | runable = *t; | |
1713 | ++count; | |
1714 | } | |
1715 | } | |
1716 | ||
1717 | if (count != 1) | |
8a3fe4f8 | 1718 | error (_("Don't know how to %s. Try \"help target\"."), do_mesg); |
c906108c SS |
1719 | |
1720 | return runable; | |
1721 | } | |
1722 | ||
1723 | void | |
fba45db2 | 1724 | find_default_attach (char *args, int from_tty) |
c906108c SS |
1725 | { |
1726 | struct target_ops *t; | |
1727 | ||
c5aa993b | 1728 | t = find_default_run_target ("attach"); |
c906108c SS |
1729 | (t->to_attach) (args, from_tty); |
1730 | return; | |
1731 | } | |
1732 | ||
c906108c | 1733 | void |
c27cda74 AC |
1734 | find_default_create_inferior (char *exec_file, char *allargs, char **env, |
1735 | int from_tty) | |
c906108c SS |
1736 | { |
1737 | struct target_ops *t; | |
1738 | ||
c5aa993b | 1739 | t = find_default_run_target ("run"); |
c27cda74 | 1740 | (t->to_create_inferior) (exec_file, allargs, env, from_tty); |
c906108c SS |
1741 | return; |
1742 | } | |
1743 | ||
e0d24f8d WZ |
1744 | static int |
1745 | default_region_ok_for_hw_watchpoint (CORE_ADDR addr, int len) | |
1746 | { | |
2a3cdf79 | 1747 | return (len <= TYPE_LENGTH (builtin_type_void_data_ptr)); |
ccaa32c7 GS |
1748 | } |
1749 | ||
c906108c | 1750 | static int |
fba45db2 | 1751 | return_zero (void) |
c906108c SS |
1752 | { |
1753 | return 0; | |
1754 | } | |
1755 | ||
1756 | static int | |
fba45db2 | 1757 | return_one (void) |
c906108c SS |
1758 | { |
1759 | return 1; | |
1760 | } | |
1761 | ||
ccaa32c7 GS |
1762 | static int |
1763 | return_minus_one (void) | |
1764 | { | |
1765 | return -1; | |
1766 | } | |
1767 | ||
6426a772 JM |
1768 | /* |
1769 | * Resize the to_sections pointer. Also make sure that anyone that | |
1770 | * was holding on to an old value of it gets updated. | |
1771 | * Returns the old size. | |
1772 | */ | |
1773 | ||
1774 | int | |
1775 | target_resize_to_sections (struct target_ops *target, int num_added) | |
1776 | { | |
1777 | struct target_ops **t; | |
1778 | struct section_table *old_value; | |
1779 | int old_count; | |
1780 | ||
1781 | old_value = target->to_sections; | |
1782 | ||
1783 | if (target->to_sections) | |
1784 | { | |
1785 | old_count = target->to_sections_end - target->to_sections; | |
1786 | target->to_sections = (struct section_table *) | |
1787 | xrealloc ((char *) target->to_sections, | |
1788 | (sizeof (struct section_table)) * (num_added + old_count)); | |
1789 | } | |
1790 | else | |
1791 | { | |
1792 | old_count = 0; | |
1793 | target->to_sections = (struct section_table *) | |
1794 | xmalloc ((sizeof (struct section_table)) * num_added); | |
1795 | } | |
1796 | target->to_sections_end = target->to_sections + (num_added + old_count); | |
1797 | ||
1798 | /* Check to see if anyone else was pointing to this structure. | |
1799 | If old_value was null, then no one was. */ | |
2bc416ba | 1800 | |
6426a772 JM |
1801 | if (old_value) |
1802 | { | |
1803 | for (t = target_structs; t < target_structs + target_struct_size; | |
1804 | ++t) | |
1805 | { | |
1806 | if ((*t)->to_sections == old_value) | |
1807 | { | |
1808 | (*t)->to_sections = target->to_sections; | |
1809 | (*t)->to_sections_end = target->to_sections_end; | |
1810 | } | |
1811 | } | |
e354df01 NW |
1812 | /* There is a flattened view of the target stack in current_target, |
1813 | so its to_sections pointer might also need updating. */ | |
1814 | if (current_target.to_sections == old_value) | |
1815 | { | |
1816 | current_target.to_sections = target->to_sections; | |
1817 | current_target.to_sections_end = target->to_sections_end; | |
1818 | } | |
6426a772 | 1819 | } |
2bc416ba | 1820 | |
6426a772 JM |
1821 | return old_count; |
1822 | ||
1823 | } | |
1824 | ||
07cd4b97 JB |
1825 | /* Remove all target sections taken from ABFD. |
1826 | ||
1827 | Scan the current target stack for targets whose section tables | |
1828 | refer to sections from BFD, and remove those sections. We use this | |
1829 | when we notice that the inferior has unloaded a shared object, for | |
1830 | example. */ | |
1831 | void | |
1832 | remove_target_sections (bfd *abfd) | |
1833 | { | |
1834 | struct target_ops **t; | |
1835 | ||
1836 | for (t = target_structs; t < target_structs + target_struct_size; t++) | |
1837 | { | |
1838 | struct section_table *src, *dest; | |
1839 | ||
1840 | dest = (*t)->to_sections; | |
1841 | for (src = (*t)->to_sections; src < (*t)->to_sections_end; src++) | |
1842 | if (src->bfd != abfd) | |
1843 | { | |
1844 | /* Keep this section. */ | |
1845 | if (dest < src) *dest = *src; | |
1846 | dest++; | |
1847 | } | |
1848 | ||
1849 | /* If we've dropped any sections, resize the section table. */ | |
1850 | if (dest < src) | |
1851 | target_resize_to_sections (*t, dest - src); | |
1852 | } | |
1853 | } | |
1854 | ||
1855 | ||
1856 | ||
1857 | ||
7a292a7a SS |
1858 | /* Find a single runnable target in the stack and return it. If for |
1859 | some reason there is more than one, return NULL. */ | |
1860 | ||
1861 | struct target_ops * | |
fba45db2 | 1862 | find_run_target (void) |
7a292a7a SS |
1863 | { |
1864 | struct target_ops **t; | |
1865 | struct target_ops *runable = NULL; | |
1866 | int count; | |
c5aa993b | 1867 | |
7a292a7a | 1868 | count = 0; |
c5aa993b | 1869 | |
7a292a7a SS |
1870 | for (t = target_structs; t < target_structs + target_struct_size; ++t) |
1871 | { | |
c5aa993b | 1872 | if ((*t)->to_can_run && target_can_run (*t)) |
7a292a7a SS |
1873 | { |
1874 | runable = *t; | |
1875 | ++count; | |
1876 | } | |
1877 | } | |
c5aa993b | 1878 | |
7a292a7a SS |
1879 | return (count == 1 ? runable : NULL); |
1880 | } | |
1881 | ||
ed9a39eb JM |
1882 | /* Find a single core_stratum target in the list of targets and return it. |
1883 | If for some reason there is more than one, return NULL. */ | |
1884 | ||
c906108c | 1885 | struct target_ops * |
fba45db2 | 1886 | find_core_target (void) |
c906108c SS |
1887 | { |
1888 | struct target_ops **t; | |
1889 | struct target_ops *runable = NULL; | |
1890 | int count; | |
c5aa993b | 1891 | |
c906108c | 1892 | count = 0; |
c5aa993b | 1893 | |
c906108c SS |
1894 | for (t = target_structs; t < target_structs + target_struct_size; |
1895 | ++t) | |
1896 | { | |
1897 | if ((*t)->to_stratum == core_stratum) | |
1898 | { | |
1899 | runable = *t; | |
1900 | ++count; | |
1901 | } | |
1902 | } | |
c5aa993b JM |
1903 | |
1904 | return (count == 1 ? runable : NULL); | |
c906108c | 1905 | } |
ed9a39eb JM |
1906 | |
1907 | /* | |
1908 | * Find the next target down the stack from the specified target. | |
1909 | */ | |
1910 | ||
1911 | struct target_ops * | |
fba45db2 | 1912 | find_target_beneath (struct target_ops *t) |
ed9a39eb | 1913 | { |
258b763a | 1914 | return t->beneath; |
ed9a39eb JM |
1915 | } |
1916 | ||
c906108c SS |
1917 | \f |
1918 | /* The inferior process has died. Long live the inferior! */ | |
1919 | ||
1920 | void | |
fba45db2 | 1921 | generic_mourn_inferior (void) |
c906108c SS |
1922 | { |
1923 | extern int show_breakpoint_hit_counts; | |
1924 | ||
39f77062 | 1925 | inferior_ptid = null_ptid; |
c906108c SS |
1926 | attach_flag = 0; |
1927 | breakpoint_init_inferior (inf_exited); | |
1928 | registers_changed (); | |
1929 | ||
c906108c SS |
1930 | reopen_exec_file (); |
1931 | reinit_frame_cache (); | |
1932 | ||
1933 | /* It is confusing to the user for ignore counts to stick around | |
1934 | from previous runs of the inferior. So clear them. */ | |
1935 | /* However, it is more confusing for the ignore counts to disappear when | |
1936 | using hit counts. So don't clear them if we're counting hits. */ | |
1937 | if (!show_breakpoint_hit_counts) | |
1938 | breakpoint_clear_ignore_counts (); | |
c5b739b5 | 1939 | |
9a4105ab AC |
1940 | if (deprecated_detach_hook) |
1941 | deprecated_detach_hook (); | |
c906108c SS |
1942 | } |
1943 | \f | |
c906108c SS |
1944 | /* Helper function for child_wait and the Lynx derivatives of child_wait. |
1945 | HOSTSTATUS is the waitstatus from wait() or the equivalent; store our | |
1946 | translation of that in OURSTATUS. */ | |
1947 | void | |
fba45db2 | 1948 | store_waitstatus (struct target_waitstatus *ourstatus, int hoststatus) |
c906108c SS |
1949 | { |
1950 | #ifdef CHILD_SPECIAL_WAITSTATUS | |
1951 | /* CHILD_SPECIAL_WAITSTATUS should return nonzero and set *OURSTATUS | |
1952 | if it wants to deal with hoststatus. */ | |
1953 | if (CHILD_SPECIAL_WAITSTATUS (ourstatus, hoststatus)) | |
1954 | return; | |
1955 | #endif | |
1956 | ||
1957 | if (WIFEXITED (hoststatus)) | |
1958 | { | |
1959 | ourstatus->kind = TARGET_WAITKIND_EXITED; | |
1960 | ourstatus->value.integer = WEXITSTATUS (hoststatus); | |
1961 | } | |
1962 | else if (!WIFSTOPPED (hoststatus)) | |
1963 | { | |
1964 | ourstatus->kind = TARGET_WAITKIND_SIGNALLED; | |
1965 | ourstatus->value.sig = target_signal_from_host (WTERMSIG (hoststatus)); | |
1966 | } | |
1967 | else | |
1968 | { | |
1969 | ourstatus->kind = TARGET_WAITKIND_STOPPED; | |
1970 | ourstatus->value.sig = target_signal_from_host (WSTOPSIG (hoststatus)); | |
1971 | } | |
1972 | } | |
1973 | \f | |
c906108c | 1974 | /* Returns zero to leave the inferior alone, one to interrupt it. */ |
507f3c78 | 1975 | int (*target_activity_function) (void); |
c906108c SS |
1976 | int target_activity_fd; |
1977 | \f | |
fd0a2a6f MK |
1978 | /* Convert a normal process ID to a string. Returns the string in a |
1979 | static buffer. */ | |
c906108c SS |
1980 | |
1981 | char * | |
39f77062 | 1982 | normal_pid_to_str (ptid_t ptid) |
c906108c | 1983 | { |
fd0a2a6f | 1984 | static char buf[32]; |
c906108c | 1985 | |
5fff8fc0 | 1986 | xsnprintf (buf, sizeof buf, "process %d", ptid_get_pid (ptid)); |
c906108c SS |
1987 | return buf; |
1988 | } | |
1989 | ||
be4d1333 | 1990 | /* Error-catcher for target_find_memory_regions */ |
be4d1333 MS |
1991 | static int dummy_find_memory_regions (int (*ignore1) (), void *ignore2) |
1992 | { | |
8a3fe4f8 | 1993 | error (_("No target.")); |
be4d1333 MS |
1994 | return 0; |
1995 | } | |
1996 | ||
1997 | /* Error-catcher for target_make_corefile_notes */ | |
be4d1333 MS |
1998 | static char * dummy_make_corefile_notes (bfd *ignore1, int *ignore2) |
1999 | { | |
8a3fe4f8 | 2000 | error (_("No target.")); |
be4d1333 MS |
2001 | return NULL; |
2002 | } | |
2003 | ||
c906108c SS |
2004 | /* Set up the handful of non-empty slots needed by the dummy target |
2005 | vector. */ | |
2006 | ||
2007 | static void | |
fba45db2 | 2008 | init_dummy_target (void) |
c906108c SS |
2009 | { |
2010 | dummy_target.to_shortname = "None"; | |
2011 | dummy_target.to_longname = "None"; | |
2012 | dummy_target.to_doc = ""; | |
2013 | dummy_target.to_attach = find_default_attach; | |
c906108c | 2014 | dummy_target.to_create_inferior = find_default_create_inferior; |
ed9a39eb | 2015 | dummy_target.to_pid_to_str = normal_pid_to_str; |
c906108c | 2016 | dummy_target.to_stratum = dummy_stratum; |
be4d1333 MS |
2017 | dummy_target.to_find_memory_regions = dummy_find_memory_regions; |
2018 | dummy_target.to_make_corefile_notes = dummy_make_corefile_notes; | |
0b603eba | 2019 | dummy_target.to_xfer_partial = default_xfer_partial; |
c906108c SS |
2020 | dummy_target.to_magic = OPS_MAGIC; |
2021 | } | |
c906108c | 2022 | \f |
c906108c | 2023 | static void |
fba45db2 | 2024 | debug_to_open (char *args, int from_tty) |
c906108c SS |
2025 | { |
2026 | debug_target.to_open (args, from_tty); | |
2027 | ||
96baa820 | 2028 | fprintf_unfiltered (gdb_stdlog, "target_open (%s, %d)\n", args, from_tty); |
c906108c SS |
2029 | } |
2030 | ||
2031 | static void | |
fba45db2 | 2032 | debug_to_close (int quitting) |
c906108c | 2033 | { |
f1c07ab0 | 2034 | target_close (&debug_target, quitting); |
96baa820 | 2035 | fprintf_unfiltered (gdb_stdlog, "target_close (%d)\n", quitting); |
c906108c SS |
2036 | } |
2037 | ||
f1c07ab0 AC |
2038 | void |
2039 | target_close (struct target_ops *targ, int quitting) | |
2040 | { | |
2041 | if (targ->to_xclose != NULL) | |
2042 | targ->to_xclose (targ, quitting); | |
2043 | else if (targ->to_close != NULL) | |
2044 | targ->to_close (quitting); | |
2045 | } | |
2046 | ||
c906108c | 2047 | static void |
fba45db2 | 2048 | debug_to_attach (char *args, int from_tty) |
c906108c SS |
2049 | { |
2050 | debug_target.to_attach (args, from_tty); | |
2051 | ||
96baa820 | 2052 | fprintf_unfiltered (gdb_stdlog, "target_attach (%s, %d)\n", args, from_tty); |
c906108c SS |
2053 | } |
2054 | ||
2055 | ||
2056 | static void | |
fba45db2 | 2057 | debug_to_post_attach (int pid) |
c906108c SS |
2058 | { |
2059 | debug_target.to_post_attach (pid); | |
2060 | ||
96baa820 | 2061 | fprintf_unfiltered (gdb_stdlog, "target_post_attach (%d)\n", pid); |
c906108c SS |
2062 | } |
2063 | ||
c906108c | 2064 | static void |
fba45db2 | 2065 | debug_to_detach (char *args, int from_tty) |
c906108c SS |
2066 | { |
2067 | debug_target.to_detach (args, from_tty); | |
2068 | ||
96baa820 | 2069 | fprintf_unfiltered (gdb_stdlog, "target_detach (%s, %d)\n", args, from_tty); |
c906108c SS |
2070 | } |
2071 | ||
c906108c | 2072 | static void |
39f77062 | 2073 | debug_to_resume (ptid_t ptid, int step, enum target_signal siggnal) |
c906108c | 2074 | { |
39f77062 | 2075 | debug_target.to_resume (ptid, step, siggnal); |
c906108c | 2076 | |
39f77062 | 2077 | fprintf_unfiltered (gdb_stdlog, "target_resume (%d, %s, %s)\n", PIDGET (ptid), |
c906108c SS |
2078 | step ? "step" : "continue", |
2079 | target_signal_to_name (siggnal)); | |
2080 | } | |
2081 | ||
39f77062 KB |
2082 | static ptid_t |
2083 | debug_to_wait (ptid_t ptid, struct target_waitstatus *status) | |
c906108c | 2084 | { |
39f77062 | 2085 | ptid_t retval; |
c906108c | 2086 | |
39f77062 | 2087 | retval = debug_target.to_wait (ptid, status); |
c906108c | 2088 | |
96baa820 | 2089 | fprintf_unfiltered (gdb_stdlog, |
39f77062 KB |
2090 | "target_wait (%d, status) = %d, ", PIDGET (ptid), |
2091 | PIDGET (retval)); | |
96baa820 | 2092 | fprintf_unfiltered (gdb_stdlog, "status->kind = "); |
c906108c SS |
2093 | switch (status->kind) |
2094 | { | |
2095 | case TARGET_WAITKIND_EXITED: | |
96baa820 | 2096 | fprintf_unfiltered (gdb_stdlog, "exited, status = %d\n", |
c906108c SS |
2097 | status->value.integer); |
2098 | break; | |
2099 | case TARGET_WAITKIND_STOPPED: | |
96baa820 | 2100 | fprintf_unfiltered (gdb_stdlog, "stopped, signal = %s\n", |
c906108c SS |
2101 | target_signal_to_name (status->value.sig)); |
2102 | break; | |
2103 | case TARGET_WAITKIND_SIGNALLED: | |
96baa820 | 2104 | fprintf_unfiltered (gdb_stdlog, "signalled, signal = %s\n", |
c906108c SS |
2105 | target_signal_to_name (status->value.sig)); |
2106 | break; | |
2107 | case TARGET_WAITKIND_LOADED: | |
96baa820 | 2108 | fprintf_unfiltered (gdb_stdlog, "loaded\n"); |
c906108c SS |
2109 | break; |
2110 | case TARGET_WAITKIND_FORKED: | |
96baa820 | 2111 | fprintf_unfiltered (gdb_stdlog, "forked\n"); |
c906108c SS |
2112 | break; |
2113 | case TARGET_WAITKIND_VFORKED: | |
96baa820 | 2114 | fprintf_unfiltered (gdb_stdlog, "vforked\n"); |
c906108c SS |
2115 | break; |
2116 | case TARGET_WAITKIND_EXECD: | |
96baa820 | 2117 | fprintf_unfiltered (gdb_stdlog, "execd\n"); |
c906108c SS |
2118 | break; |
2119 | case TARGET_WAITKIND_SPURIOUS: | |
96baa820 | 2120 | fprintf_unfiltered (gdb_stdlog, "spurious\n"); |
c906108c SS |
2121 | break; |
2122 | default: | |
96baa820 | 2123 | fprintf_unfiltered (gdb_stdlog, "unknown???\n"); |
c906108c SS |
2124 | break; |
2125 | } | |
2126 | ||
2127 | return retval; | |
2128 | } | |
2129 | ||
bf0c5130 AC |
2130 | static void |
2131 | debug_print_register (const char * func, int regno) | |
2132 | { | |
2133 | fprintf_unfiltered (gdb_stdlog, "%s ", func); | |
2134 | if (regno >= 0 && regno < NUM_REGS + NUM_PSEUDO_REGS | |
2135 | && REGISTER_NAME (regno) != NULL && REGISTER_NAME (regno)[0] != '\0') | |
2136 | fprintf_unfiltered (gdb_stdlog, "(%s)", REGISTER_NAME (regno)); | |
2137 | else | |
2138 | fprintf_unfiltered (gdb_stdlog, "(%d)", regno); | |
2139 | if (regno >= 0) | |
2140 | { | |
2141 | int i; | |
d9d9c31f | 2142 | unsigned char buf[MAX_REGISTER_SIZE]; |
4caf0990 | 2143 | deprecated_read_register_gen (regno, buf); |
bf0c5130 | 2144 | fprintf_unfiltered (gdb_stdlog, " = "); |
3acba339 | 2145 | for (i = 0; i < register_size (current_gdbarch, regno); i++) |
bf0c5130 AC |
2146 | { |
2147 | fprintf_unfiltered (gdb_stdlog, "%02x", buf[i]); | |
2148 | } | |
3acba339 | 2149 | if (register_size (current_gdbarch, regno) <= sizeof (LONGEST)) |
bf0c5130 AC |
2150 | { |
2151 | fprintf_unfiltered (gdb_stdlog, " 0x%s %s", | |
2152 | paddr_nz (read_register (regno)), | |
2153 | paddr_d (read_register (regno))); | |
2154 | } | |
2155 | } | |
2156 | fprintf_unfiltered (gdb_stdlog, "\n"); | |
2157 | } | |
2158 | ||
c906108c | 2159 | static void |
fba45db2 | 2160 | debug_to_fetch_registers (int regno) |
c906108c SS |
2161 | { |
2162 | debug_target.to_fetch_registers (regno); | |
bf0c5130 | 2163 | debug_print_register ("target_fetch_registers", regno); |
c906108c SS |
2164 | } |
2165 | ||
2166 | static void | |
fba45db2 | 2167 | debug_to_store_registers (int regno) |
c906108c SS |
2168 | { |
2169 | debug_target.to_store_registers (regno); | |
bf0c5130 AC |
2170 | debug_print_register ("target_store_registers", regno); |
2171 | fprintf_unfiltered (gdb_stdlog, "\n"); | |
c906108c SS |
2172 | } |
2173 | ||
2174 | static void | |
fba45db2 | 2175 | debug_to_prepare_to_store (void) |
c906108c SS |
2176 | { |
2177 | debug_target.to_prepare_to_store (); | |
2178 | ||
96baa820 | 2179 | fprintf_unfiltered (gdb_stdlog, "target_prepare_to_store ()\n"); |
c906108c SS |
2180 | } |
2181 | ||
2182 | static int | |
961cb7b5 | 2183 | deprecated_debug_xfer_memory (CORE_ADDR memaddr, bfd_byte *myaddr, int len, |
c8e73a31 AC |
2184 | int write, struct mem_attrib *attrib, |
2185 | struct target_ops *target) | |
c906108c SS |
2186 | { |
2187 | int retval; | |
2188 | ||
c8e73a31 AC |
2189 | retval = debug_target.deprecated_xfer_memory (memaddr, myaddr, len, write, |
2190 | attrib, target); | |
c906108c | 2191 | |
96baa820 | 2192 | fprintf_unfiltered (gdb_stdlog, |
c906108c | 2193 | "target_xfer_memory (0x%x, xxx, %d, %s, xxx) = %d", |
c5aa993b | 2194 | (unsigned int) memaddr, /* possable truncate long long */ |
c906108c SS |
2195 | len, write ? "write" : "read", retval); |
2196 | ||
c906108c SS |
2197 | if (retval > 0) |
2198 | { | |
2199 | int i; | |
2200 | ||
96baa820 | 2201 | fputs_unfiltered (", bytes =", gdb_stdlog); |
c906108c SS |
2202 | for (i = 0; i < retval; i++) |
2203 | { | |
2204 | if ((((long) &(myaddr[i])) & 0xf) == 0) | |
333dabeb DJ |
2205 | { |
2206 | if (targetdebug < 2 && i > 0) | |
2207 | { | |
2208 | fprintf_unfiltered (gdb_stdlog, " ..."); | |
2209 | break; | |
2210 | } | |
2211 | fprintf_unfiltered (gdb_stdlog, "\n"); | |
2212 | } | |
2bc416ba | 2213 | |
96baa820 | 2214 | fprintf_unfiltered (gdb_stdlog, " %02x", myaddr[i] & 0xff); |
c906108c SS |
2215 | } |
2216 | } | |
2217 | ||
96baa820 | 2218 | fputc_unfiltered ('\n', gdb_stdlog); |
c906108c SS |
2219 | |
2220 | return retval; | |
2221 | } | |
2222 | ||
2223 | static void | |
fba45db2 | 2224 | debug_to_files_info (struct target_ops *target) |
c906108c SS |
2225 | { |
2226 | debug_target.to_files_info (target); | |
2227 | ||
96baa820 | 2228 | fprintf_unfiltered (gdb_stdlog, "target_files_info (xxx)\n"); |
c906108c SS |
2229 | } |
2230 | ||
2231 | static int | |
8181d85f | 2232 | debug_to_insert_breakpoint (struct bp_target_info *bp_tgt) |
c906108c SS |
2233 | { |
2234 | int retval; | |
2235 | ||
8181d85f | 2236 | retval = debug_target.to_insert_breakpoint (bp_tgt); |
c906108c | 2237 | |
96baa820 | 2238 | fprintf_unfiltered (gdb_stdlog, |
104c1213 | 2239 | "target_insert_breakpoint (0x%lx, xxx) = %ld\n", |
8181d85f | 2240 | (unsigned long) bp_tgt->placed_address, |
104c1213 | 2241 | (unsigned long) retval); |
c906108c SS |
2242 | return retval; |
2243 | } | |
2244 | ||
2245 | static int | |
8181d85f | 2246 | debug_to_remove_breakpoint (struct bp_target_info *bp_tgt) |
c906108c SS |
2247 | { |
2248 | int retval; | |
2249 | ||
8181d85f | 2250 | retval = debug_target.to_remove_breakpoint (bp_tgt); |
c906108c | 2251 | |
96baa820 | 2252 | fprintf_unfiltered (gdb_stdlog, |
104c1213 | 2253 | "target_remove_breakpoint (0x%lx, xxx) = %ld\n", |
8181d85f | 2254 | (unsigned long) bp_tgt->placed_address, |
104c1213 | 2255 | (unsigned long) retval); |
c906108c SS |
2256 | return retval; |
2257 | } | |
2258 | ||
ccaa32c7 GS |
2259 | static int |
2260 | debug_to_can_use_hw_breakpoint (int type, int cnt, int from_tty) | |
2261 | { | |
2262 | int retval; | |
2263 | ||
2264 | retval = debug_target.to_can_use_hw_breakpoint (type, cnt, from_tty); | |
2265 | ||
2266 | fprintf_unfiltered (gdb_stdlog, | |
2267 | "target_can_use_hw_breakpoint (%ld, %ld, %ld) = %ld\n", | |
2268 | (unsigned long) type, | |
2269 | (unsigned long) cnt, | |
2270 | (unsigned long) from_tty, | |
2271 | (unsigned long) retval); | |
2272 | return retval; | |
2273 | } | |
2274 | ||
e0d24f8d WZ |
2275 | static int |
2276 | debug_to_region_ok_for_hw_watchpoint (CORE_ADDR addr, int len) | |
2277 | { | |
2278 | CORE_ADDR retval; | |
2279 | ||
2280 | retval = debug_target.to_region_ok_for_hw_watchpoint (addr, len); | |
2281 | ||
2282 | fprintf_unfiltered (gdb_stdlog, | |
2283 | "TARGET_REGION_OK_FOR_HW_WATCHPOINT (%ld, %ld) = 0x%lx\n", | |
2284 | (unsigned long) addr, | |
2285 | (unsigned long) len, | |
2286 | (unsigned long) retval); | |
2287 | return retval; | |
2288 | } | |
2289 | ||
ccaa32c7 GS |
2290 | static int |
2291 | debug_to_stopped_by_watchpoint (void) | |
2292 | { | |
2293 | int retval; | |
2294 | ||
2295 | retval = debug_target.to_stopped_by_watchpoint (); | |
2296 | ||
2297 | fprintf_unfiltered (gdb_stdlog, | |
2298 | "STOPPED_BY_WATCHPOINT () = %ld\n", | |
2299 | (unsigned long) retval); | |
2300 | return retval; | |
2301 | } | |
2302 | ||
4aa7a7f5 JJ |
2303 | static int |
2304 | debug_to_stopped_data_address (struct target_ops *target, CORE_ADDR *addr) | |
ccaa32c7 | 2305 | { |
4aa7a7f5 | 2306 | int retval; |
ccaa32c7 | 2307 | |
4aa7a7f5 | 2308 | retval = debug_target.to_stopped_data_address (target, addr); |
ccaa32c7 GS |
2309 | |
2310 | fprintf_unfiltered (gdb_stdlog, | |
4aa7a7f5 JJ |
2311 | "target_stopped_data_address ([0x%lx]) = %ld\n", |
2312 | (unsigned long)*addr, | |
2313 | (unsigned long)retval); | |
ccaa32c7 GS |
2314 | return retval; |
2315 | } | |
2316 | ||
2317 | static int | |
8181d85f | 2318 | debug_to_insert_hw_breakpoint (struct bp_target_info *bp_tgt) |
ccaa32c7 GS |
2319 | { |
2320 | int retval; | |
2321 | ||
8181d85f | 2322 | retval = debug_target.to_insert_hw_breakpoint (bp_tgt); |
ccaa32c7 GS |
2323 | |
2324 | fprintf_unfiltered (gdb_stdlog, | |
2325 | "target_insert_hw_breakpoint (0x%lx, xxx) = %ld\n", | |
8181d85f | 2326 | (unsigned long) bp_tgt->placed_address, |
ccaa32c7 GS |
2327 | (unsigned long) retval); |
2328 | return retval; | |
2329 | } | |
2330 | ||
2331 | static int | |
8181d85f | 2332 | debug_to_remove_hw_breakpoint (struct bp_target_info *bp_tgt) |
ccaa32c7 GS |
2333 | { |
2334 | int retval; | |
2335 | ||
8181d85f | 2336 | retval = debug_target.to_remove_hw_breakpoint (bp_tgt); |
ccaa32c7 GS |
2337 | |
2338 | fprintf_unfiltered (gdb_stdlog, | |
2339 | "target_remove_hw_breakpoint (0x%lx, xxx) = %ld\n", | |
8181d85f | 2340 | (unsigned long) bp_tgt->placed_address, |
ccaa32c7 GS |
2341 | (unsigned long) retval); |
2342 | return retval; | |
2343 | } | |
2344 | ||
2345 | static int | |
2346 | debug_to_insert_watchpoint (CORE_ADDR addr, int len, int type) | |
2347 | { | |
2348 | int retval; | |
2349 | ||
2350 | retval = debug_target.to_insert_watchpoint (addr, len, type); | |
2351 | ||
2352 | fprintf_unfiltered (gdb_stdlog, | |
2353 | "target_insert_watchpoint (0x%lx, %d, %d) = %ld\n", | |
2354 | (unsigned long) addr, len, type, (unsigned long) retval); | |
2355 | return retval; | |
2356 | } | |
2357 | ||
2358 | static int | |
2359 | debug_to_remove_watchpoint (CORE_ADDR addr, int len, int type) | |
2360 | { | |
2361 | int retval; | |
2362 | ||
2363 | retval = debug_target.to_insert_watchpoint (addr, len, type); | |
2364 | ||
2365 | fprintf_unfiltered (gdb_stdlog, | |
2366 | "target_insert_watchpoint (0x%lx, %d, %d) = %ld\n", | |
2367 | (unsigned long) addr, len, type, (unsigned long) retval); | |
2368 | return retval; | |
2369 | } | |
2370 | ||
c906108c | 2371 | static void |
fba45db2 | 2372 | debug_to_terminal_init (void) |
c906108c SS |
2373 | { |
2374 | debug_target.to_terminal_init (); | |
2375 | ||
96baa820 | 2376 | fprintf_unfiltered (gdb_stdlog, "target_terminal_init ()\n"); |
c906108c SS |
2377 | } |
2378 | ||
2379 | static void | |
fba45db2 | 2380 | debug_to_terminal_inferior (void) |
c906108c SS |
2381 | { |
2382 | debug_target.to_terminal_inferior (); | |
2383 | ||
96baa820 | 2384 | fprintf_unfiltered (gdb_stdlog, "target_terminal_inferior ()\n"); |
c906108c SS |
2385 | } |
2386 | ||
2387 | static void | |
fba45db2 | 2388 | debug_to_terminal_ours_for_output (void) |
c906108c SS |
2389 | { |
2390 | debug_target.to_terminal_ours_for_output (); | |
2391 | ||
96baa820 | 2392 | fprintf_unfiltered (gdb_stdlog, "target_terminal_ours_for_output ()\n"); |
c906108c SS |
2393 | } |
2394 | ||
2395 | static void | |
fba45db2 | 2396 | debug_to_terminal_ours (void) |
c906108c SS |
2397 | { |
2398 | debug_target.to_terminal_ours (); | |
2399 | ||
96baa820 | 2400 | fprintf_unfiltered (gdb_stdlog, "target_terminal_ours ()\n"); |
c906108c SS |
2401 | } |
2402 | ||
a790ad35 SC |
2403 | static void |
2404 | debug_to_terminal_save_ours (void) | |
2405 | { | |
2406 | debug_target.to_terminal_save_ours (); | |
2407 | ||
2408 | fprintf_unfiltered (gdb_stdlog, "target_terminal_save_ours ()\n"); | |
2409 | } | |
2410 | ||
c906108c | 2411 | static void |
fba45db2 | 2412 | debug_to_terminal_info (char *arg, int from_tty) |
c906108c SS |
2413 | { |
2414 | debug_target.to_terminal_info (arg, from_tty); | |
2415 | ||
96baa820 | 2416 | fprintf_unfiltered (gdb_stdlog, "target_terminal_info (%s, %d)\n", arg, |
c906108c SS |
2417 | from_tty); |
2418 | } | |
2419 | ||
2420 | static void | |
fba45db2 | 2421 | debug_to_kill (void) |
c906108c SS |
2422 | { |
2423 | debug_target.to_kill (); | |
2424 | ||
96baa820 | 2425 | fprintf_unfiltered (gdb_stdlog, "target_kill ()\n"); |
c906108c SS |
2426 | } |
2427 | ||
2428 | static void | |
fba45db2 | 2429 | debug_to_load (char *args, int from_tty) |
c906108c SS |
2430 | { |
2431 | debug_target.to_load (args, from_tty); | |
2432 | ||
96baa820 | 2433 | fprintf_unfiltered (gdb_stdlog, "target_load (%s, %d)\n", args, from_tty); |
c906108c SS |
2434 | } |
2435 | ||
2436 | static int | |
fba45db2 | 2437 | debug_to_lookup_symbol (char *name, CORE_ADDR *addrp) |
c906108c SS |
2438 | { |
2439 | int retval; | |
2440 | ||
2441 | retval = debug_target.to_lookup_symbol (name, addrp); | |
2442 | ||
96baa820 | 2443 | fprintf_unfiltered (gdb_stdlog, "target_lookup_symbol (%s, xxx)\n", name); |
c906108c SS |
2444 | |
2445 | return retval; | |
2446 | } | |
2447 | ||
2448 | static void | |
c27cda74 AC |
2449 | debug_to_create_inferior (char *exec_file, char *args, char **env, |
2450 | int from_tty) | |
c906108c | 2451 | { |
c27cda74 | 2452 | debug_target.to_create_inferior (exec_file, args, env, from_tty); |
c906108c | 2453 | |
c27cda74 AC |
2454 | fprintf_unfiltered (gdb_stdlog, "target_create_inferior (%s, %s, xxx, %d)\n", |
2455 | exec_file, args, from_tty); | |
c906108c SS |
2456 | } |
2457 | ||
2458 | static void | |
39f77062 | 2459 | debug_to_post_startup_inferior (ptid_t ptid) |
c906108c | 2460 | { |
39f77062 | 2461 | debug_target.to_post_startup_inferior (ptid); |
c906108c | 2462 | |
96baa820 | 2463 | fprintf_unfiltered (gdb_stdlog, "target_post_startup_inferior (%d)\n", |
39f77062 | 2464 | PIDGET (ptid)); |
c906108c SS |
2465 | } |
2466 | ||
2467 | static void | |
fba45db2 | 2468 | debug_to_acknowledge_created_inferior (int pid) |
c906108c SS |
2469 | { |
2470 | debug_target.to_acknowledge_created_inferior (pid); | |
2471 | ||
96baa820 | 2472 | fprintf_unfiltered (gdb_stdlog, "target_acknowledge_created_inferior (%d)\n", |
c906108c SS |
2473 | pid); |
2474 | } | |
2475 | ||
fa113d1a | 2476 | static void |
fba45db2 | 2477 | debug_to_insert_fork_catchpoint (int pid) |
c906108c | 2478 | { |
fa113d1a | 2479 | debug_target.to_insert_fork_catchpoint (pid); |
c906108c | 2480 | |
fa113d1a AC |
2481 | fprintf_unfiltered (gdb_stdlog, "target_insert_fork_catchpoint (%d)\n", |
2482 | pid); | |
c906108c SS |
2483 | } |
2484 | ||
2485 | static int | |
fba45db2 | 2486 | debug_to_remove_fork_catchpoint (int pid) |
c906108c | 2487 | { |
c5aa993b | 2488 | int retval; |
c906108c SS |
2489 | |
2490 | retval = debug_target.to_remove_fork_catchpoint (pid); | |
2491 | ||
96baa820 | 2492 | fprintf_unfiltered (gdb_stdlog, "target_remove_fork_catchpoint (%d) = %d\n", |
c5aa993b | 2493 | pid, retval); |
c906108c SS |
2494 | |
2495 | return retval; | |
2496 | } | |
2497 | ||
fa113d1a | 2498 | static void |
fba45db2 | 2499 | debug_to_insert_vfork_catchpoint (int pid) |
c906108c | 2500 | { |
fa113d1a | 2501 | debug_target.to_insert_vfork_catchpoint (pid); |
c906108c | 2502 | |
fa113d1a AC |
2503 | fprintf_unfiltered (gdb_stdlog, "target_insert_vfork_catchpoint (%d)\n", |
2504 | pid); | |
c906108c SS |
2505 | } |
2506 | ||
2507 | static int | |
fba45db2 | 2508 | debug_to_remove_vfork_catchpoint (int pid) |
c906108c | 2509 | { |
c5aa993b | 2510 | int retval; |
c906108c SS |
2511 | |
2512 | retval = debug_target.to_remove_vfork_catchpoint (pid); | |
2513 | ||
96baa820 | 2514 | fprintf_unfiltered (gdb_stdlog, "target_remove_vfork_catchpoint (%d) = %d\n", |
c5aa993b | 2515 | pid, retval); |
c906108c SS |
2516 | |
2517 | return retval; | |
2518 | } | |
2519 | ||
fa113d1a | 2520 | static void |
fba45db2 | 2521 | debug_to_insert_exec_catchpoint (int pid) |
c906108c | 2522 | { |
fa113d1a | 2523 | debug_target.to_insert_exec_catchpoint (pid); |
c906108c | 2524 | |
fa113d1a AC |
2525 | fprintf_unfiltered (gdb_stdlog, "target_insert_exec_catchpoint (%d)\n", |
2526 | pid); | |
c906108c SS |
2527 | } |
2528 | ||
2529 | static int | |
fba45db2 | 2530 | debug_to_remove_exec_catchpoint (int pid) |
c906108c | 2531 | { |
c5aa993b | 2532 | int retval; |
c906108c SS |
2533 | |
2534 | retval = debug_target.to_remove_exec_catchpoint (pid); | |
2535 | ||
96baa820 | 2536 | fprintf_unfiltered (gdb_stdlog, "target_remove_exec_catchpoint (%d) = %d\n", |
c5aa993b | 2537 | pid, retval); |
c906108c SS |
2538 | |
2539 | return retval; | |
2540 | } | |
2541 | ||
c906108c | 2542 | static int |
fba45db2 | 2543 | debug_to_reported_exec_events_per_exec_call (void) |
c906108c | 2544 | { |
c5aa993b | 2545 | int reported_exec_events; |
c906108c SS |
2546 | |
2547 | reported_exec_events = debug_target.to_reported_exec_events_per_exec_call (); | |
2548 | ||
96baa820 | 2549 | fprintf_unfiltered (gdb_stdlog, |
c906108c | 2550 | "target_reported_exec_events_per_exec_call () = %d\n", |
c5aa993b | 2551 | reported_exec_events); |
c906108c SS |
2552 | |
2553 | return reported_exec_events; | |
2554 | } | |
2555 | ||
c906108c | 2556 | static int |
fba45db2 | 2557 | debug_to_has_exited (int pid, int wait_status, int *exit_status) |
c906108c | 2558 | { |
c5aa993b | 2559 | int has_exited; |
c906108c SS |
2560 | |
2561 | has_exited = debug_target.to_has_exited (pid, wait_status, exit_status); | |
2562 | ||
96baa820 | 2563 | fprintf_unfiltered (gdb_stdlog, "target_has_exited (%d, %d, %d) = %d\n", |
c5aa993b | 2564 | pid, wait_status, *exit_status, has_exited); |
c906108c SS |
2565 | |
2566 | return has_exited; | |
2567 | } | |
2568 | ||
2569 | static void | |
fba45db2 | 2570 | debug_to_mourn_inferior (void) |
c906108c SS |
2571 | { |
2572 | debug_target.to_mourn_inferior (); | |
2573 | ||
96baa820 | 2574 | fprintf_unfiltered (gdb_stdlog, "target_mourn_inferior ()\n"); |
c906108c SS |
2575 | } |
2576 | ||
2577 | static int | |
fba45db2 | 2578 | debug_to_can_run (void) |
c906108c SS |
2579 | { |
2580 | int retval; | |
2581 | ||
2582 | retval = debug_target.to_can_run (); | |
2583 | ||
96baa820 | 2584 | fprintf_unfiltered (gdb_stdlog, "target_can_run () = %d\n", retval); |
c906108c SS |
2585 | |
2586 | return retval; | |
2587 | } | |
2588 | ||
2589 | static void | |
39f77062 | 2590 | debug_to_notice_signals (ptid_t ptid) |
c906108c | 2591 | { |
39f77062 | 2592 | debug_target.to_notice_signals (ptid); |
c906108c | 2593 | |
39f77062 KB |
2594 | fprintf_unfiltered (gdb_stdlog, "target_notice_signals (%d)\n", |
2595 | PIDGET (ptid)); | |
c906108c SS |
2596 | } |
2597 | ||
2598 | static int | |
39f77062 | 2599 | debug_to_thread_alive (ptid_t ptid) |
c906108c SS |
2600 | { |
2601 | int retval; | |
2602 | ||
39f77062 | 2603 | retval = debug_target.to_thread_alive (ptid); |
c906108c | 2604 | |
96baa820 | 2605 | fprintf_unfiltered (gdb_stdlog, "target_thread_alive (%d) = %d\n", |
39f77062 | 2606 | PIDGET (ptid), retval); |
c906108c SS |
2607 | |
2608 | return retval; | |
2609 | } | |
2610 | ||
0d06e24b | 2611 | static void |
fba45db2 | 2612 | debug_to_find_new_threads (void) |
0d06e24b JM |
2613 | { |
2614 | debug_target.to_find_new_threads (); | |
2615 | ||
2616 | fputs_unfiltered ("target_find_new_threads ()\n", gdb_stdlog); | |
2617 | } | |
2618 | ||
c906108c | 2619 | static void |
fba45db2 | 2620 | debug_to_stop (void) |
c906108c SS |
2621 | { |
2622 | debug_target.to_stop (); | |
2623 | ||
96baa820 | 2624 | fprintf_unfiltered (gdb_stdlog, "target_stop ()\n"); |
c906108c SS |
2625 | } |
2626 | ||
96baa820 JM |
2627 | static void |
2628 | debug_to_rcmd (char *command, | |
d9fcf2fb | 2629 | struct ui_file *outbuf) |
96baa820 JM |
2630 | { |
2631 | debug_target.to_rcmd (command, outbuf); | |
2632 | fprintf_unfiltered (gdb_stdlog, "target_rcmd (%s, ...)\n", command); | |
2633 | } | |
2634 | ||
c906108c | 2635 | static struct symtab_and_line * |
fba45db2 | 2636 | debug_to_enable_exception_callback (enum exception_event_kind kind, int enable) |
c906108c | 2637 | { |
7a292a7a SS |
2638 | struct symtab_and_line *result; |
2639 | result = debug_target.to_enable_exception_callback (kind, enable); | |
96baa820 | 2640 | fprintf_unfiltered (gdb_stdlog, |
c906108c SS |
2641 | "target get_exception_callback_sal (%d, %d)\n", |
2642 | kind, enable); | |
7a292a7a | 2643 | return result; |
c906108c SS |
2644 | } |
2645 | ||
2646 | static struct exception_event_record * | |
fba45db2 | 2647 | debug_to_get_current_exception_event (void) |
c906108c | 2648 | { |
7a292a7a | 2649 | struct exception_event_record *result; |
c5aa993b | 2650 | result = debug_target.to_get_current_exception_event (); |
96baa820 | 2651 | fprintf_unfiltered (gdb_stdlog, "target get_current_exception_event ()\n"); |
7a292a7a | 2652 | return result; |
c906108c SS |
2653 | } |
2654 | ||
2655 | static char * | |
fba45db2 | 2656 | debug_to_pid_to_exec_file (int pid) |
c906108c | 2657 | { |
c5aa993b | 2658 | char *exec_file; |
c906108c SS |
2659 | |
2660 | exec_file = debug_target.to_pid_to_exec_file (pid); | |
2661 | ||
96baa820 | 2662 | fprintf_unfiltered (gdb_stdlog, "target_pid_to_exec_file (%d) = %s\n", |
c5aa993b | 2663 | pid, exec_file); |
c906108c SS |
2664 | |
2665 | return exec_file; | |
2666 | } | |
2667 | ||
c906108c | 2668 | static void |
fba45db2 | 2669 | setup_target_debug (void) |
c906108c SS |
2670 | { |
2671 | memcpy (&debug_target, ¤t_target, sizeof debug_target); | |
2672 | ||
2673 | current_target.to_open = debug_to_open; | |
2674 | current_target.to_close = debug_to_close; | |
2675 | current_target.to_attach = debug_to_attach; | |
2676 | current_target.to_post_attach = debug_to_post_attach; | |
c906108c | 2677 | current_target.to_detach = debug_to_detach; |
c906108c SS |
2678 | current_target.to_resume = debug_to_resume; |
2679 | current_target.to_wait = debug_to_wait; | |
c906108c SS |
2680 | current_target.to_fetch_registers = debug_to_fetch_registers; |
2681 | current_target.to_store_registers = debug_to_store_registers; | |
2682 | current_target.to_prepare_to_store = debug_to_prepare_to_store; | |
c8e73a31 | 2683 | current_target.deprecated_xfer_memory = deprecated_debug_xfer_memory; |
c906108c SS |
2684 | current_target.to_files_info = debug_to_files_info; |
2685 | current_target.to_insert_breakpoint = debug_to_insert_breakpoint; | |
2686 | current_target.to_remove_breakpoint = debug_to_remove_breakpoint; | |
ccaa32c7 GS |
2687 | current_target.to_can_use_hw_breakpoint = debug_to_can_use_hw_breakpoint; |
2688 | current_target.to_insert_hw_breakpoint = debug_to_insert_hw_breakpoint; | |
2689 | current_target.to_remove_hw_breakpoint = debug_to_remove_hw_breakpoint; | |
2690 | current_target.to_insert_watchpoint = debug_to_insert_watchpoint; | |
2691 | current_target.to_remove_watchpoint = debug_to_remove_watchpoint; | |
2692 | current_target.to_stopped_by_watchpoint = debug_to_stopped_by_watchpoint; | |
2693 | current_target.to_stopped_data_address = debug_to_stopped_data_address; | |
e0d24f8d | 2694 | current_target.to_region_ok_for_hw_watchpoint = debug_to_region_ok_for_hw_watchpoint; |
c906108c SS |
2695 | current_target.to_terminal_init = debug_to_terminal_init; |
2696 | current_target.to_terminal_inferior = debug_to_terminal_inferior; | |
2697 | current_target.to_terminal_ours_for_output = debug_to_terminal_ours_for_output; | |
2698 | current_target.to_terminal_ours = debug_to_terminal_ours; | |
a790ad35 | 2699 | current_target.to_terminal_save_ours = debug_to_terminal_save_ours; |
c906108c SS |
2700 | current_target.to_terminal_info = debug_to_terminal_info; |
2701 | current_target.to_kill = debug_to_kill; | |
2702 | current_target.to_load = debug_to_load; | |
2703 | current_target.to_lookup_symbol = debug_to_lookup_symbol; | |
2704 | current_target.to_create_inferior = debug_to_create_inferior; | |
2705 | current_target.to_post_startup_inferior = debug_to_post_startup_inferior; | |
2706 | current_target.to_acknowledge_created_inferior = debug_to_acknowledge_created_inferior; | |
c906108c SS |
2707 | current_target.to_insert_fork_catchpoint = debug_to_insert_fork_catchpoint; |
2708 | current_target.to_remove_fork_catchpoint = debug_to_remove_fork_catchpoint; | |
2709 | current_target.to_insert_vfork_catchpoint = debug_to_insert_vfork_catchpoint; | |
2710 | current_target.to_remove_vfork_catchpoint = debug_to_remove_vfork_catchpoint; | |
c906108c SS |
2711 | current_target.to_insert_exec_catchpoint = debug_to_insert_exec_catchpoint; |
2712 | current_target.to_remove_exec_catchpoint = debug_to_remove_exec_catchpoint; | |
c906108c | 2713 | current_target.to_reported_exec_events_per_exec_call = debug_to_reported_exec_events_per_exec_call; |
c906108c SS |
2714 | current_target.to_has_exited = debug_to_has_exited; |
2715 | current_target.to_mourn_inferior = debug_to_mourn_inferior; | |
2716 | current_target.to_can_run = debug_to_can_run; | |
2717 | current_target.to_notice_signals = debug_to_notice_signals; | |
2718 | current_target.to_thread_alive = debug_to_thread_alive; | |
0d06e24b | 2719 | current_target.to_find_new_threads = debug_to_find_new_threads; |
c906108c | 2720 | current_target.to_stop = debug_to_stop; |
96baa820 | 2721 | current_target.to_rcmd = debug_to_rcmd; |
c906108c SS |
2722 | current_target.to_enable_exception_callback = debug_to_enable_exception_callback; |
2723 | current_target.to_get_current_exception_event = debug_to_get_current_exception_event; | |
2724 | current_target.to_pid_to_exec_file = debug_to_pid_to_exec_file; | |
c906108c | 2725 | } |
c906108c | 2726 | \f |
c5aa993b JM |
2727 | |
2728 | static char targ_desc[] = | |
2729 | "Names of targets and files being debugged.\n\ | |
c906108c SS |
2730 | Shows the entire stack of targets currently in use (including the exec-file,\n\ |
2731 | core-file, and process, if any), as well as the symbol file name."; | |
2732 | ||
96baa820 JM |
2733 | static void |
2734 | do_monitor_command (char *cmd, | |
2735 | int from_tty) | |
2736 | { | |
2b5fe715 AC |
2737 | if ((current_target.to_rcmd |
2738 | == (void (*) (char *, struct ui_file *)) tcomplain) | |
96baa820 | 2739 | || (current_target.to_rcmd == debug_to_rcmd |
2b5fe715 AC |
2740 | && (debug_target.to_rcmd |
2741 | == (void (*) (char *, struct ui_file *)) tcomplain))) | |
8a3fe4f8 | 2742 | error (_("\"monitor\" command not supported by this target.")); |
96baa820 JM |
2743 | target_rcmd (cmd, gdb_stdtarg); |
2744 | } | |
2745 | ||
c906108c | 2746 | void |
fba45db2 | 2747 | initialize_targets (void) |
c906108c SS |
2748 | { |
2749 | init_dummy_target (); | |
2750 | push_target (&dummy_target); | |
2751 | ||
2752 | add_info ("target", target_info, targ_desc); | |
2753 | add_info ("files", target_info, targ_desc); | |
2754 | ||
85c07804 AC |
2755 | add_setshow_zinteger_cmd ("target", class_maintenance, &targetdebug, _("\ |
2756 | Set target debugging."), _("\ | |
2757 | Show target debugging."), _("\ | |
333dabeb DJ |
2758 | When non-zero, target debugging is enabled. Higher numbers are more\n\ |
2759 | verbose. Changes do not take effect until the next \"run\" or \"target\"\n\ | |
85c07804 AC |
2760 | command."), |
2761 | NULL, | |
920d2a44 | 2762 | show_targetdebug, |
85c07804 | 2763 | &setdebuglist, &showdebuglist); |
3a11626d | 2764 | |
2bc416ba | 2765 | add_setshow_boolean_cmd ("trust-readonly-sections", class_support, |
7915a72c AC |
2766 | &trust_readonly, _("\ |
2767 | Set mode for reading from readonly sections."), _("\ | |
2768 | Show mode for reading from readonly sections."), _("\ | |
3a11626d MS |
2769 | When this mode is on, memory reads from readonly sections (such as .text)\n\ |
2770 | will be read from the object file instead of from the target. This will\n\ | |
7915a72c | 2771 | result in significant performance improvement for remote targets."), |
2c5b56ce | 2772 | NULL, |
920d2a44 | 2773 | show_trust_readonly, |
e707bbc2 | 2774 | &setlist, &showlist); |
96baa820 JM |
2775 | |
2776 | add_com ("monitor", class_obscure, do_monitor_command, | |
1bedd215 | 2777 | _("Send a command to the remote monitor (remote targets only).")); |
96baa820 | 2778 | |
8add0441 | 2779 | target_dcache = dcache_init (); |
c906108c | 2780 | } |