1 /* Select target systems and architectures at runtime for GDB.
3 Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
4 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008
5 Free Software Foundation, Inc.
7 Contributed by Cygnus Support.
9 This file is part of GDB.
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 3 of the License, or
14 (at your option) any later version.
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.
21 You should have received a copy of the GNU General Public License
22 along with this program. If not, see <http://www.gnu.org/licenses/>. */
26 #include "gdb_string.h"
38 #include "gdb_assert.h"
40 #include "exceptions.h"
41 #include "target-descriptions.h"
42 #include "gdb_stdint.h"
44 static void target_info (char *, int);
46 static void maybe_kill_then_attach (char *, int);
48 static void kill_or_be_killed (int);
50 static void default_terminal_info (char *, int);
52 static int default_region_ok_for_hw_watchpoint (CORE_ADDR, int);
54 static int nosymbol (char *, CORE_ADDR *);
56 static void tcomplain (void) ATTR_NORETURN;
58 static int nomemory (CORE_ADDR, char *, int, int, struct target_ops *);
60 static int return_zero (void);
62 static int return_one (void);
64 static int return_minus_one (void);
66 void target_ignore (void);
68 static void target_command (char *, int);
70 static struct target_ops *find_default_run_target (char *);
72 static void nosupport_runtime (void);
74 static LONGEST default_xfer_partial (struct target_ops *ops,
75 enum target_object object,
76 const char *annex, gdb_byte *readbuf,
77 const gdb_byte *writebuf,
78 ULONGEST offset, LONGEST len);
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);
86 static LONGEST target_xfer_partial (struct target_ops *ops,
87 enum target_object object,
89 void *readbuf, const void *writebuf,
90 ULONGEST offset, LONGEST len);
92 static void init_dummy_target (void);
94 static struct target_ops debug_target;
96 static void debug_to_open (char *, int);
98 static void debug_to_close (int);
100 static void debug_to_attach (char *, int);
102 static void debug_to_detach (char *, int);
104 static void debug_to_resume (ptid_t, int, enum target_signal);
106 static ptid_t debug_to_wait (ptid_t, struct target_waitstatus *);
108 static void debug_to_fetch_registers (struct regcache *, int);
110 static void debug_to_store_registers (struct regcache *, int);
112 static void debug_to_prepare_to_store (struct regcache *);
114 static void debug_to_files_info (struct target_ops *);
116 static int debug_to_insert_breakpoint (struct bp_target_info *);
118 static int debug_to_remove_breakpoint (struct bp_target_info *);
120 static int debug_to_can_use_hw_breakpoint (int, int, int);
122 static int debug_to_insert_hw_breakpoint (struct bp_target_info *);
124 static int debug_to_remove_hw_breakpoint (struct bp_target_info *);
126 static int debug_to_insert_watchpoint (CORE_ADDR, int, int);
128 static int debug_to_remove_watchpoint (CORE_ADDR, int, int);
130 static int debug_to_stopped_by_watchpoint (void);
132 static int debug_to_stopped_data_address (struct target_ops *, CORE_ADDR *);
134 static int debug_to_region_ok_for_hw_watchpoint (CORE_ADDR, int);
136 static void debug_to_terminal_init (void);
138 static void debug_to_terminal_inferior (void);
140 static void debug_to_terminal_ours_for_output (void);
142 static void debug_to_terminal_save_ours (void);
144 static void debug_to_terminal_ours (void);
146 static void debug_to_terminal_info (char *, int);
148 static void debug_to_kill (void);
150 static void debug_to_load (char *, int);
152 static int debug_to_lookup_symbol (char *, CORE_ADDR *);
154 static void debug_to_mourn_inferior (void);
156 static int debug_to_can_run (void);
158 static void debug_to_notice_signals (ptid_t);
160 static int debug_to_thread_alive (ptid_t);
162 static void debug_to_stop (void);
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. */
168 struct target_ops deprecated_child_ops;
170 /* Pointer to array of target architecture structures; the size of the
171 array; the current index into the array; the allocated size of the
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
179 /* The initial current target, so that there is always a semi-valid
182 static struct target_ops dummy_target;
184 /* Top of target stack. */
186 static struct target_ops *target_stack;
188 /* The target structure we are currently using to talk to a process
189 or file or whatever "inferior" we have. */
191 struct target_ops current_target;
193 /* Command list for target. */
195 static struct cmd_list_element *targetlist = NULL;
197 /* Nonzero if we are debugging an attached outside process
198 rather than an inferior. */
202 /* Nonzero if we should trust readonly sections from the
203 executable when reading memory. */
205 static int trust_readonly = 0;
207 /* Nonzero if we should show true memory content including
208 memory breakpoint inserted by gdb. */
210 static int show_memory_breakpoints = 0;
212 /* Non-zero if we want to see trace of target level stuff. */
214 static int targetdebug = 0;
216 show_targetdebug (struct ui_file *file, int from_tty,
217 struct cmd_list_element *c, const char *value)
219 fprintf_filtered (file, _("Target debugging is %s.\n"), value);
222 static void setup_target_debug (void);
224 DCACHE *target_dcache;
226 /* The user just typed 'target' without the name of a target. */
229 target_command (char *arg, int from_tty)
231 fputs_filtered ("Argument required (target name). Try `help target'\n",
235 /* Add a possible target architecture to the list. */
238 add_target (struct target_ops *t)
240 /* Provide default values for all "must have" methods. */
241 if (t->to_xfer_partial == NULL)
242 t->to_xfer_partial = default_xfer_partial;
246 target_struct_allocsize = DEFAULT_ALLOCSIZE;
247 target_structs = (struct target_ops **) xmalloc
248 (target_struct_allocsize * sizeof (*target_structs));
250 if (target_struct_size >= target_struct_allocsize)
252 target_struct_allocsize *= 2;
253 target_structs = (struct target_ops **)
254 xrealloc ((char *) target_structs,
255 target_struct_allocsize * sizeof (*target_structs));
257 target_structs[target_struct_size++] = t;
259 if (targetlist == NULL)
260 add_prefix_cmd ("target", class_run, target_command, _("\
261 Connect to a target machine or process.\n\
262 The first argument is the type or protocol of the target machine.\n\
263 Remaining arguments are interpreted by the target protocol. For more\n\
264 information on the arguments for a particular protocol, type\n\
265 `help target ' followed by the protocol name."),
266 &targetlist, "target ", 0, &cmdlist);
267 add_cmd (t->to_shortname, no_class, t->to_open, t->to_doc, &targetlist);
278 target_load (char *arg, int from_tty)
280 dcache_invalidate (target_dcache);
281 (*current_target.to_load) (arg, from_tty);
285 nomemory (CORE_ADDR memaddr, char *myaddr, int len, int write,
286 struct target_ops *t)
288 errno = EIO; /* Can't read/write this location */
289 return 0; /* No bytes handled */
295 error (_("You can't do that when your target is `%s'"),
296 current_target.to_shortname);
302 error (_("You can't do that without a process to debug."));
306 nosymbol (char *name, CORE_ADDR *addrp)
308 return 1; /* Symbol does not exist in target env */
312 nosupport_runtime (void)
314 if (ptid_equal (inferior_ptid, null_ptid))
317 error (_("No run-time support for this"));
322 default_terminal_info (char *args, int from_tty)
324 printf_unfiltered (_("No saved terminal information.\n"));
327 /* This is the default target_create_inferior and target_attach function.
328 If the current target is executing, it asks whether to kill it off.
329 If this function returns without calling error(), it has killed off
330 the target, and the operation should be attempted. */
333 kill_or_be_killed (int from_tty)
335 if (target_has_execution)
337 printf_unfiltered (_("You are already running a program:\n"));
338 target_files_info ();
339 if (query ("Kill it? "))
342 if (target_has_execution)
343 error (_("Killing the program did not help."));
348 error (_("Program not killed."));
355 maybe_kill_then_attach (char *args, int from_tty)
357 kill_or_be_killed (from_tty);
358 target_attach (args, from_tty);
362 maybe_kill_then_create_inferior (char *exec, char *args, char **env,
365 kill_or_be_killed (0);
366 target_create_inferior (exec, args, env, from_tty);
369 /* Go through the target stack from top to bottom, copying over zero
370 entries in current_target, then filling in still empty entries. In
371 effect, we are doing class inheritance through the pushed target
374 NOTE: cagney/2003-10-17: The problem with this inheritance, as it
375 is currently implemented, is that it discards any knowledge of
376 which target an inherited method originally belonged to.
377 Consequently, new new target methods should instead explicitly and
378 locally search the target stack for the target that can handle the
382 update_current_target (void)
384 struct target_ops *t;
386 /* First, reset current's contents. */
387 memset (¤t_target, 0, sizeof (current_target));
389 #define INHERIT(FIELD, TARGET) \
390 if (!current_target.FIELD) \
391 current_target.FIELD = (TARGET)->FIELD
393 for (t = target_stack; t; t = t->beneath)
395 INHERIT (to_shortname, t);
396 INHERIT (to_longname, t);
398 INHERIT (to_open, t);
399 INHERIT (to_close, t);
400 INHERIT (to_attach, t);
401 INHERIT (to_post_attach, t);
402 INHERIT (to_detach, t);
403 /* Do not inherit to_disconnect. */
404 INHERIT (to_resume, t);
405 INHERIT (to_wait, t);
406 INHERIT (to_fetch_registers, t);
407 INHERIT (to_store_registers, t);
408 INHERIT (to_prepare_to_store, t);
409 INHERIT (deprecated_xfer_memory, t);
410 INHERIT (to_files_info, t);
411 INHERIT (to_insert_breakpoint, t);
412 INHERIT (to_remove_breakpoint, t);
413 INHERIT (to_can_use_hw_breakpoint, t);
414 INHERIT (to_insert_hw_breakpoint, t);
415 INHERIT (to_remove_hw_breakpoint, t);
416 INHERIT (to_insert_watchpoint, t);
417 INHERIT (to_remove_watchpoint, t);
418 INHERIT (to_stopped_data_address, t);
419 INHERIT (to_stopped_by_watchpoint, t);
420 INHERIT (to_have_steppable_watchpoint, t);
421 INHERIT (to_have_continuable_watchpoint, t);
422 INHERIT (to_region_ok_for_hw_watchpoint, t);
423 INHERIT (to_terminal_init, t);
424 INHERIT (to_terminal_inferior, t);
425 INHERIT (to_terminal_ours_for_output, t);
426 INHERIT (to_terminal_ours, t);
427 INHERIT (to_terminal_save_ours, t);
428 INHERIT (to_terminal_info, t);
429 INHERIT (to_kill, t);
430 INHERIT (to_load, t);
431 INHERIT (to_lookup_symbol, t);
432 INHERIT (to_create_inferior, t);
433 INHERIT (to_post_startup_inferior, t);
434 INHERIT (to_acknowledge_created_inferior, t);
435 INHERIT (to_insert_fork_catchpoint, t);
436 INHERIT (to_remove_fork_catchpoint, t);
437 INHERIT (to_insert_vfork_catchpoint, t);
438 INHERIT (to_remove_vfork_catchpoint, t);
439 /* Do not inherit to_follow_fork. */
440 INHERIT (to_insert_exec_catchpoint, t);
441 INHERIT (to_remove_exec_catchpoint, t);
442 INHERIT (to_has_exited, t);
443 INHERIT (to_mourn_inferior, t);
444 INHERIT (to_can_run, t);
445 INHERIT (to_notice_signals, t);
446 INHERIT (to_thread_alive, t);
447 INHERIT (to_find_new_threads, t);
448 INHERIT (to_pid_to_str, t);
449 INHERIT (to_extra_thread_info, t);
450 INHERIT (to_stop, t);
451 /* Do not inherit to_xfer_partial. */
452 INHERIT (to_rcmd, t);
453 INHERIT (to_pid_to_exec_file, t);
454 INHERIT (to_log_command, t);
455 INHERIT (to_stratum, t);
456 INHERIT (to_has_all_memory, t);
457 INHERIT (to_has_memory, t);
458 INHERIT (to_has_stack, t);
459 INHERIT (to_has_registers, t);
460 INHERIT (to_has_execution, t);
461 INHERIT (to_has_thread_control, t);
462 INHERIT (to_sections, t);
463 INHERIT (to_sections_end, t);
464 INHERIT (to_can_async_p, t);
465 INHERIT (to_is_async_p, t);
466 INHERIT (to_async, t);
467 INHERIT (to_async_mask, t);
468 INHERIT (to_find_memory_regions, t);
469 INHERIT (to_make_corefile_notes, t);
470 INHERIT (to_get_thread_local_address, t);
471 /* Do not inherit to_read_description. */
472 INHERIT (to_magic, t);
473 /* Do not inherit to_memory_map. */
474 /* Do not inherit to_flash_erase. */
475 /* Do not inherit to_flash_done. */
479 /* Clean up a target struct so it no longer has any zero pointers in
480 it. Some entries are defaulted to a method that print an error,
481 others are hard-wired to a standard recursive default. */
483 #define de_fault(field, value) \
484 if (!current_target.field) \
485 current_target.field = value
488 (void (*) (char *, int))
494 maybe_kill_then_attach);
495 de_fault (to_post_attach,
499 (void (*) (char *, int))
502 (void (*) (ptid_t, int, enum target_signal))
505 (ptid_t (*) (ptid_t, struct target_waitstatus *))
507 de_fault (to_fetch_registers,
508 (void (*) (struct regcache *, int))
510 de_fault (to_store_registers,
511 (void (*) (struct regcache *, int))
513 de_fault (to_prepare_to_store,
514 (void (*) (struct regcache *))
516 de_fault (deprecated_xfer_memory,
517 (int (*) (CORE_ADDR, gdb_byte *, int, int, struct mem_attrib *, struct target_ops *))
519 de_fault (to_files_info,
520 (void (*) (struct target_ops *))
522 de_fault (to_insert_breakpoint,
523 memory_insert_breakpoint);
524 de_fault (to_remove_breakpoint,
525 memory_remove_breakpoint);
526 de_fault (to_can_use_hw_breakpoint,
527 (int (*) (int, int, int))
529 de_fault (to_insert_hw_breakpoint,
530 (int (*) (struct bp_target_info *))
532 de_fault (to_remove_hw_breakpoint,
533 (int (*) (struct bp_target_info *))
535 de_fault (to_insert_watchpoint,
536 (int (*) (CORE_ADDR, int, int))
538 de_fault (to_remove_watchpoint,
539 (int (*) (CORE_ADDR, int, int))
541 de_fault (to_stopped_by_watchpoint,
544 de_fault (to_stopped_data_address,
545 (int (*) (struct target_ops *, CORE_ADDR *))
547 de_fault (to_region_ok_for_hw_watchpoint,
548 default_region_ok_for_hw_watchpoint);
549 de_fault (to_terminal_init,
552 de_fault (to_terminal_inferior,
555 de_fault (to_terminal_ours_for_output,
558 de_fault (to_terminal_ours,
561 de_fault (to_terminal_save_ours,
564 de_fault (to_terminal_info,
565 default_terminal_info);
570 (void (*) (char *, int))
572 de_fault (to_lookup_symbol,
573 (int (*) (char *, CORE_ADDR *))
575 de_fault (to_create_inferior,
576 maybe_kill_then_create_inferior);
577 de_fault (to_post_startup_inferior,
580 de_fault (to_acknowledge_created_inferior,
583 de_fault (to_insert_fork_catchpoint,
586 de_fault (to_remove_fork_catchpoint,
589 de_fault (to_insert_vfork_catchpoint,
592 de_fault (to_remove_vfork_catchpoint,
595 de_fault (to_insert_exec_catchpoint,
598 de_fault (to_remove_exec_catchpoint,
601 de_fault (to_has_exited,
602 (int (*) (int, int, int *))
604 de_fault (to_mourn_inferior,
607 de_fault (to_can_run,
609 de_fault (to_notice_signals,
612 de_fault (to_thread_alive,
615 de_fault (to_find_new_threads,
618 de_fault (to_extra_thread_info,
619 (char *(*) (struct thread_info *))
624 current_target.to_xfer_partial = current_xfer_partial;
626 (void (*) (char *, struct ui_file *))
628 de_fault (to_pid_to_exec_file,
631 de_fault (to_can_async_p,
634 de_fault (to_is_async_p,
638 (void (*) (void (*) (enum inferior_event_type, void*), void*))
640 de_fault (to_async_mask,
643 current_target.to_read_description = NULL;
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;
652 setup_target_debug ();
655 /* Mark OPS as a running target. This reverses the effect
656 of target_mark_exited. */
659 target_mark_running (struct target_ops *ops)
661 struct target_ops *t;
663 for (t = target_stack; t != NULL; t = t->beneath)
667 internal_error (__FILE__, __LINE__,
668 "Attempted to mark unpushed target \"%s\" as running",
671 ops->to_has_execution = 1;
672 ops->to_has_all_memory = 1;
673 ops->to_has_memory = 1;
674 ops->to_has_stack = 1;
675 ops->to_has_registers = 1;
677 update_current_target ();
680 /* Mark OPS as a non-running target. This reverses the effect
681 of target_mark_running. */
684 target_mark_exited (struct target_ops *ops)
686 struct target_ops *t;
688 for (t = target_stack; t != NULL; t = t->beneath)
692 internal_error (__FILE__, __LINE__,
693 "Attempted to mark unpushed target \"%s\" as running",
696 ops->to_has_execution = 0;
697 ops->to_has_all_memory = 0;
698 ops->to_has_memory = 0;
699 ops->to_has_stack = 0;
700 ops->to_has_registers = 0;
702 update_current_target ();
705 /* Push a new target type into the stack of the existing target accessors,
706 possibly superseding some of the existing accessors.
708 Result is zero if the pushed target ended up on top of the stack,
709 nonzero if at least one target is on top of it.
711 Rather than allow an empty stack, we always have the dummy target at
712 the bottom stratum, so we can call the function vectors without
716 push_target (struct target_ops *t)
718 struct target_ops **cur;
720 /* Check magic number. If wrong, it probably means someone changed
721 the struct definition, but not all the places that initialize one. */
722 if (t->to_magic != OPS_MAGIC)
724 fprintf_unfiltered (gdb_stderr,
725 "Magic number of %s target struct wrong\n",
727 internal_error (__FILE__, __LINE__, _("failed internal consistency check"));
730 /* Find the proper stratum to install this target in. */
731 for (cur = &target_stack; (*cur) != NULL; cur = &(*cur)->beneath)
733 if ((int) (t->to_stratum) >= (int) (*cur)->to_stratum)
737 /* If there's already targets at this stratum, remove them. */
738 /* FIXME: cagney/2003-10-15: I think this should be popping all
739 targets to CUR, and not just those at this stratum level. */
740 while ((*cur) != NULL && t->to_stratum == (*cur)->to_stratum)
742 /* There's already something at this stratum level. Close it,
743 and un-hook it from the stack. */
744 struct target_ops *tmp = (*cur);
745 (*cur) = (*cur)->beneath;
747 target_close (tmp, 0);
750 /* We have removed all targets in our stratum, now add the new one. */
754 update_current_target ();
757 return (t != target_stack);
760 /* Remove a target_ops vector from the stack, wherever it may be.
761 Return how many times it was removed (0 or 1). */
764 unpush_target (struct target_ops *t)
766 struct target_ops **cur;
767 struct target_ops *tmp;
769 /* Look for the specified target. Note that we assume that a target
770 can only occur once in the target stack. */
772 for (cur = &target_stack; (*cur) != NULL; cur = &(*cur)->beneath)
779 return 0; /* Didn't find target_ops, quit now */
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. */
789 /* Unchain the target */
791 (*cur) = (*cur)->beneath;
794 update_current_target ();
802 target_close (¤t_target, 0); /* Let it clean up */
803 if (unpush_target (target_stack) == 1)
806 fprintf_unfiltered (gdb_stderr,
807 "pop_target couldn't find target %s\n",
808 current_target.to_shortname);
809 internal_error (__FILE__, __LINE__, _("failed internal consistency check"));
812 /* Using the objfile specified in OBJFILE, find the address for the
813 current thread's thread-local storage with offset OFFSET. */
815 target_translate_tls_address (struct objfile *objfile, CORE_ADDR offset)
817 volatile CORE_ADDR addr = 0;
819 if (target_get_thread_local_address_p ()
820 && gdbarch_fetch_tls_load_module_address_p (current_gdbarch))
822 ptid_t ptid = inferior_ptid;
823 volatile struct gdb_exception ex;
825 TRY_CATCH (ex, RETURN_MASK_ALL)
829 /* Fetch the load module address for this objfile. */
830 lm_addr = gdbarch_fetch_tls_load_module_address (current_gdbarch,
832 /* If it's 0, throw the appropriate exception. */
834 throw_error (TLS_LOAD_MODULE_NOT_FOUND_ERROR,
835 _("TLS load module not found"));
837 addr = target_get_thread_local_address (ptid, lm_addr, offset);
839 /* If an error occurred, print TLS related messages here. Otherwise,
840 throw the error to some higher catcher. */
843 int objfile_is_library = (objfile->flags & OBJF_SHARED);
847 case TLS_NO_LIBRARY_SUPPORT_ERROR:
848 error (_("Cannot find thread-local variables in this thread library."));
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);
855 error (_("Cannot find executable file `%s' in dynamic"
856 " linker's load module list"), objfile->name);
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"
864 objfile->name, target_pid_to_str (ptid));
866 error (_("The inferior has not yet allocated storage for"
867 " thread-local variables in\n"
868 "the executable `%s'\n"
870 objfile->name, target_pid_to_str (ptid));
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);
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);
885 throw_exception (ex);
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. */
893 error (_("Cannot find thread-local variables on this target"));
899 #define MIN(A, B) (((A) <= (B)) ? (A) : (B))
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
908 target_read_string (CORE_ADDR memaddr, char **string, int len, int *errnop)
910 int tlen, origlen, offset, i;
914 int buffer_allocated;
916 unsigned int nbytes_read = 0;
920 /* Small for testing. */
921 buffer_allocated = 4;
922 buffer = xmalloc (buffer_allocated);
929 tlen = MIN (len, 4 - (memaddr & 3));
930 offset = memaddr & 3;
932 errcode = target_read_memory (memaddr & ~3, buf, sizeof buf);
935 /* The transfer request might have crossed the boundary to an
936 unallocated region of memory. Retry the transfer, requesting
940 errcode = target_read_memory (memaddr, buf, 1);
945 if (bufptr - buffer + tlen > buffer_allocated)
948 bytes = bufptr - buffer;
949 buffer_allocated *= 2;
950 buffer = xrealloc (buffer, buffer_allocated);
951 bufptr = buffer + bytes;
954 for (i = 0; i < tlen; i++)
956 *bufptr++ = buf[i + offset];
957 if (buf[i + offset] == '\000')
959 nbytes_read += i + 1;
975 /* Find a section containing ADDR. */
976 struct section_table *
977 target_section_by_addr (struct target_ops *target, CORE_ADDR addr)
979 struct section_table *secp;
980 for (secp = target->to_sections;
981 secp < target->to_sections_end;
984 if (addr >= secp->addr && addr < secp->endaddr)
990 /* Perform a partial memory transfer. The arguments and return
991 value are just as for target_xfer_partial. */
994 memory_xfer_partial (struct target_ops *ops, void *readbuf, const void *writebuf,
995 ULONGEST memaddr, LONGEST len)
999 struct mem_region *region;
1001 /* Zero length requests are ok and require no work. */
1005 /* Try the executable file, if "trust-readonly-sections" is set. */
1006 if (readbuf != NULL && trust_readonly)
1008 struct section_table *secp;
1010 secp = target_section_by_addr (ops, memaddr);
1012 && (bfd_get_section_flags (secp->bfd, secp->the_bfd_section)
1014 return xfer_memory (memaddr, readbuf, len, 0, NULL, ops);
1017 /* Likewise for accesses to unmapped overlay sections. */
1018 if (readbuf != NULL && overlay_debugging)
1020 asection *section = find_pc_overlay (memaddr);
1021 if (pc_in_unmapped_range (memaddr, section))
1022 return xfer_memory (memaddr, readbuf, len, 0, NULL, ops);
1025 /* Try GDB's internal data cache. */
1026 region = lookup_mem_region (memaddr);
1027 /* region->hi == 0 means there's no upper bound. */
1028 if (memaddr + len < region->hi || region->hi == 0)
1031 reg_len = region->hi - memaddr;
1033 switch (region->attrib.mode)
1036 if (writebuf != NULL)
1041 if (readbuf != NULL)
1046 /* We only support writing to flash during "load" for now. */
1047 if (writebuf != NULL)
1048 error (_("Writing to flash memory forbidden in this context"));
1055 if (region->attrib.cache)
1057 /* FIXME drow/2006-08-09: This call discards OPS, so the raw
1058 memory request will start back at current_target. */
1059 if (readbuf != NULL)
1060 res = dcache_xfer_memory (target_dcache, memaddr, readbuf,
1063 /* FIXME drow/2006-08-09: If we're going to preserve const
1064 correctness dcache_xfer_memory should take readbuf and
1066 res = dcache_xfer_memory (target_dcache, memaddr,
1073 if (readbuf && !show_memory_breakpoints)
1074 breakpoint_restore_shadows (readbuf, memaddr, reg_len);
1079 /* If none of those methods found the memory we wanted, fall back
1080 to a target partial transfer. Normally a single call to
1081 to_xfer_partial is enough; if it doesn't recognize an object
1082 it will call the to_xfer_partial of the next target down.
1083 But for memory this won't do. Memory is the only target
1084 object which can be read from more than one valid target.
1085 A core file, for instance, could have some of memory but
1086 delegate other bits to the target below it. So, we must
1087 manually try all targets. */
1091 res = ops->to_xfer_partial (ops, TARGET_OBJECT_MEMORY, NULL,
1092 readbuf, writebuf, memaddr, reg_len);
1096 /* We want to continue past core files to executables, but not
1097 past a running target's memory. */
1098 if (ops->to_has_all_memory)
1103 while (ops != NULL);
1105 if (readbuf && !show_memory_breakpoints)
1106 breakpoint_restore_shadows (readbuf, memaddr, reg_len);
1108 /* If we still haven't got anything, return the last error. We
1114 restore_show_memory_breakpoints (void *arg)
1116 show_memory_breakpoints = (uintptr_t) arg;
1120 make_show_memory_breakpoints_cleanup (int show)
1122 int current = show_memory_breakpoints;
1123 show_memory_breakpoints = show;
1125 return make_cleanup (restore_show_memory_breakpoints,
1126 (void *) (uintptr_t) current);
1130 target_xfer_partial (struct target_ops *ops,
1131 enum target_object object, const char *annex,
1132 void *readbuf, const void *writebuf,
1133 ULONGEST offset, LONGEST len)
1137 gdb_assert (ops->to_xfer_partial != NULL);
1139 /* If this is a memory transfer, let the memory-specific code
1140 have a look at it instead. Memory transfers are more
1142 if (object == TARGET_OBJECT_MEMORY)
1143 retval = memory_xfer_partial (ops, readbuf, writebuf, offset, len);
1146 enum target_object raw_object = object;
1148 /* If this is a raw memory transfer, request the normal
1149 memory object from other layers. */
1150 if (raw_object == TARGET_OBJECT_RAW_MEMORY)
1151 raw_object = TARGET_OBJECT_MEMORY;
1153 retval = ops->to_xfer_partial (ops, raw_object, annex, readbuf,
1154 writebuf, offset, len);
1159 const unsigned char *myaddr = NULL;
1161 fprintf_unfiltered (gdb_stdlog,
1162 "%s:target_xfer_partial (%d, %s, 0x%lx, 0x%lx, 0x%s, %s) = %s",
1165 (annex ? annex : "(null)"),
1166 (long) readbuf, (long) writebuf,
1167 paddr_nz (offset), paddr_d (len), paddr_d (retval));
1173 if (retval > 0 && myaddr != NULL)
1177 fputs_unfiltered (", bytes =", gdb_stdlog);
1178 for (i = 0; i < retval; i++)
1180 if ((((long) &(myaddr[i])) & 0xf) == 0)
1182 if (targetdebug < 2 && i > 0)
1184 fprintf_unfiltered (gdb_stdlog, " ...");
1187 fprintf_unfiltered (gdb_stdlog, "\n");
1190 fprintf_unfiltered (gdb_stdlog, " %02x", myaddr[i] & 0xff);
1194 fputc_unfiltered ('\n', gdb_stdlog);
1199 /* Read LEN bytes of target memory at address MEMADDR, placing the results in
1200 GDB's memory at MYADDR. Returns either 0 for success or an errno value
1201 if any error occurs.
1203 If an error occurs, no guarantee is made about the contents of the data at
1204 MYADDR. In particular, the caller should not depend upon partial reads
1205 filling the buffer with good data. There is no way for the caller to know
1206 how much good data might have been transfered anyway. Callers that can
1207 deal with partial reads should call target_read (which will retry until
1208 it makes no progress, and then return how much was transferred). */
1211 target_read_memory (CORE_ADDR memaddr, gdb_byte *myaddr, int len)
1213 if (target_read (¤t_target, TARGET_OBJECT_MEMORY, NULL,
1214 myaddr, memaddr, len) == len)
1221 target_write_memory (CORE_ADDR memaddr, const gdb_byte *myaddr, int len)
1223 if (target_write (¤t_target, TARGET_OBJECT_MEMORY, NULL,
1224 myaddr, memaddr, len) == len)
1230 /* Fetch the target's memory map. */
1233 target_memory_map (void)
1235 VEC(mem_region_s) *result;
1236 struct mem_region *last_one, *this_one;
1238 struct target_ops *t;
1241 fprintf_unfiltered (gdb_stdlog, "target_memory_map ()\n");
1243 for (t = current_target.beneath; t != NULL; t = t->beneath)
1244 if (t->to_memory_map != NULL)
1250 result = t->to_memory_map (t);
1254 qsort (VEC_address (mem_region_s, result),
1255 VEC_length (mem_region_s, result),
1256 sizeof (struct mem_region), mem_region_cmp);
1258 /* Check that regions do not overlap. Simultaneously assign
1259 a numbering for the "mem" commands to use to refer to
1262 for (ix = 0; VEC_iterate (mem_region_s, result, ix, this_one); ix++)
1264 this_one->number = ix;
1266 if (last_one && last_one->hi > this_one->lo)
1268 warning (_("Overlapping regions in memory map: ignoring"));
1269 VEC_free (mem_region_s, result);
1272 last_one = this_one;
1279 target_flash_erase (ULONGEST address, LONGEST length)
1281 struct target_ops *t;
1283 for (t = current_target.beneath; t != NULL; t = t->beneath)
1284 if (t->to_flash_erase != NULL)
1287 fprintf_unfiltered (gdb_stdlog, "target_flash_erase (%s, %s)\n",
1288 paddr (address), phex (length, 0));
1289 t->to_flash_erase (t, address, length);
1297 target_flash_done (void)
1299 struct target_ops *t;
1301 for (t = current_target.beneath; t != NULL; t = t->beneath)
1302 if (t->to_flash_done != NULL)
1305 fprintf_unfiltered (gdb_stdlog, "target_flash_done\n");
1306 t->to_flash_done (t);
1313 #ifndef target_stopped_data_address_p
1315 target_stopped_data_address_p (struct target_ops *target)
1317 if (target->to_stopped_data_address
1318 == (int (*) (struct target_ops *, CORE_ADDR *)) return_zero)
1320 if (target->to_stopped_data_address == debug_to_stopped_data_address
1321 && (debug_target.to_stopped_data_address
1322 == (int (*) (struct target_ops *, CORE_ADDR *)) return_zero))
1329 show_trust_readonly (struct ui_file *file, int from_tty,
1330 struct cmd_list_element *c, const char *value)
1332 fprintf_filtered (file, _("\
1333 Mode for reading from readonly sections is %s.\n"),
1337 /* More generic transfers. */
1340 default_xfer_partial (struct target_ops *ops, enum target_object object,
1341 const char *annex, gdb_byte *readbuf,
1342 const gdb_byte *writebuf, ULONGEST offset, LONGEST len)
1344 if (object == TARGET_OBJECT_MEMORY
1345 && ops->deprecated_xfer_memory != NULL)
1346 /* If available, fall back to the target's
1347 "deprecated_xfer_memory" method. */
1351 if (writebuf != NULL)
1353 void *buffer = xmalloc (len);
1354 struct cleanup *cleanup = make_cleanup (xfree, buffer);
1355 memcpy (buffer, writebuf, len);
1356 xfered = ops->deprecated_xfer_memory (offset, buffer, len,
1357 1/*write*/, NULL, ops);
1358 do_cleanups (cleanup);
1360 if (readbuf != NULL)
1361 xfered = ops->deprecated_xfer_memory (offset, readbuf, len,
1362 0/*read*/, NULL, ops);
1365 else if (xfered == 0 && errno == 0)
1366 /* "deprecated_xfer_memory" uses 0, cross checked against
1367 ERRNO as one indication of an error. */
1372 else if (ops->beneath != NULL)
1373 return ops->beneath->to_xfer_partial (ops->beneath, object, annex,
1374 readbuf, writebuf, offset, len);
1379 /* The xfer_partial handler for the topmost target. Unlike the default,
1380 it does not need to handle memory specially; it just passes all
1381 requests down the stack. */
1384 current_xfer_partial (struct target_ops *ops, enum target_object object,
1385 const char *annex, gdb_byte *readbuf,
1386 const gdb_byte *writebuf, ULONGEST offset, LONGEST len)
1388 if (ops->beneath != NULL)
1389 return ops->beneath->to_xfer_partial (ops->beneath, object, annex,
1390 readbuf, writebuf, offset, len);
1395 /* Target vector read/write partial wrapper functions.
1397 NOTE: cagney/2003-10-21: I wonder if having "to_xfer_partial
1398 (inbuf, outbuf)", instead of separate read/write methods, make life
1402 target_read_partial (struct target_ops *ops,
1403 enum target_object object,
1404 const char *annex, gdb_byte *buf,
1405 ULONGEST offset, LONGEST len)
1407 return target_xfer_partial (ops, object, annex, buf, NULL, offset, len);
1411 target_write_partial (struct target_ops *ops,
1412 enum target_object object,
1413 const char *annex, const gdb_byte *buf,
1414 ULONGEST offset, LONGEST len)
1416 return target_xfer_partial (ops, object, annex, NULL, buf, offset, len);
1419 /* Wrappers to perform the full transfer. */
1421 target_read (struct target_ops *ops,
1422 enum target_object object,
1423 const char *annex, gdb_byte *buf,
1424 ULONGEST offset, LONGEST len)
1427 while (xfered < len)
1429 LONGEST xfer = target_read_partial (ops, object, annex,
1430 (gdb_byte *) buf + xfered,
1431 offset + xfered, len - xfered);
1432 /* Call an observer, notifying them of the xfer progress? */
1443 /* An alternative to target_write with progress callbacks. */
1446 target_write_with_progress (struct target_ops *ops,
1447 enum target_object object,
1448 const char *annex, const gdb_byte *buf,
1449 ULONGEST offset, LONGEST len,
1450 void (*progress) (ULONGEST, void *), void *baton)
1454 /* Give the progress callback a chance to set up. */
1456 (*progress) (0, baton);
1458 while (xfered < len)
1460 LONGEST xfer = target_write_partial (ops, object, annex,
1461 (gdb_byte *) buf + xfered,
1462 offset + xfered, len - xfered);
1470 (*progress) (xfer, baton);
1479 target_write (struct target_ops *ops,
1480 enum target_object object,
1481 const char *annex, const gdb_byte *buf,
1482 ULONGEST offset, LONGEST len)
1484 return target_write_with_progress (ops, object, annex, buf, offset, len,
1488 /* Read OBJECT/ANNEX using OPS. Store the result in *BUF_P and return
1489 the size of the transferred data. PADDING additional bytes are
1490 available in *BUF_P. This is a helper function for
1491 target_read_alloc; see the declaration of that function for more
1495 target_read_alloc_1 (struct target_ops *ops, enum target_object object,
1496 const char *annex, gdb_byte **buf_p, int padding)
1498 size_t buf_alloc, buf_pos;
1502 /* This function does not have a length parameter; it reads the
1503 entire OBJECT). Also, it doesn't support objects fetched partly
1504 from one target and partly from another (in a different stratum,
1505 e.g. a core file and an executable). Both reasons make it
1506 unsuitable for reading memory. */
1507 gdb_assert (object != TARGET_OBJECT_MEMORY);
1509 /* Start by reading up to 4K at a time. The target will throttle
1510 this number down if necessary. */
1512 buf = xmalloc (buf_alloc);
1516 n = target_read_partial (ops, object, annex, &buf[buf_pos],
1517 buf_pos, buf_alloc - buf_pos - padding);
1520 /* An error occurred. */
1526 /* Read all there was. */
1536 /* If the buffer is filling up, expand it. */
1537 if (buf_alloc < buf_pos * 2)
1540 buf = xrealloc (buf, buf_alloc);
1547 /* Read OBJECT/ANNEX using OPS. Store the result in *BUF_P and return
1548 the size of the transferred data. See the declaration in "target.h"
1549 function for more information about the return value. */
1552 target_read_alloc (struct target_ops *ops, enum target_object object,
1553 const char *annex, gdb_byte **buf_p)
1555 return target_read_alloc_1 (ops, object, annex, buf_p, 0);
1558 /* Read OBJECT/ANNEX using OPS. The result is NUL-terminated and
1559 returned as a string, allocated using xmalloc. If an error occurs
1560 or the transfer is unsupported, NULL is returned. Empty objects
1561 are returned as allocated but empty strings. A warning is issued
1562 if the result contains any embedded NUL bytes. */
1565 target_read_stralloc (struct target_ops *ops, enum target_object object,
1569 LONGEST transferred;
1571 transferred = target_read_alloc_1 (ops, object, annex, &buffer, 1);
1573 if (transferred < 0)
1576 if (transferred == 0)
1577 return xstrdup ("");
1579 buffer[transferred] = 0;
1580 if (strlen (buffer) < transferred)
1581 warning (_("target object %d, annex %s, "
1582 "contained unexpected null characters"),
1583 (int) object, annex ? annex : "(none)");
1585 return (char *) buffer;
1588 /* Memory transfer methods. */
1591 get_target_memory (struct target_ops *ops, CORE_ADDR addr, gdb_byte *buf,
1594 if (target_read (ops, TARGET_OBJECT_MEMORY, NULL, buf, addr, len)
1596 memory_error (EIO, addr);
1600 get_target_memory_unsigned (struct target_ops *ops,
1601 CORE_ADDR addr, int len)
1603 gdb_byte buf[sizeof (ULONGEST)];
1605 gdb_assert (len <= sizeof (buf));
1606 get_target_memory (ops, addr, buf, len);
1607 return extract_unsigned_integer (buf, len);
1611 target_info (char *args, int from_tty)
1613 struct target_ops *t;
1614 int has_all_mem = 0;
1616 if (symfile_objfile != NULL)
1617 printf_unfiltered (_("Symbols from \"%s\".\n"), symfile_objfile->name);
1619 for (t = target_stack; t != NULL; t = t->beneath)
1621 if (!t->to_has_memory)
1624 if ((int) (t->to_stratum) <= (int) dummy_stratum)
1627 printf_unfiltered (_("\tWhile running this, GDB does not access memory from...\n"));
1628 printf_unfiltered ("%s:\n", t->to_longname);
1629 (t->to_files_info) (t);
1630 has_all_mem = t->to_has_all_memory;
1634 /* This function is called before any new inferior is created, e.g.
1635 by running a program, attaching, or connecting to a target.
1636 It cleans up any state from previous invocations which might
1637 change between runs. This is a subset of what target_preopen
1638 resets (things which might change between targets). */
1641 target_pre_inferior (int from_tty)
1643 invalidate_target_mem_regions ();
1645 target_clear_description ();
1648 /* This is to be called by the open routine before it does
1652 target_preopen (int from_tty)
1656 if (target_has_execution)
1659 || query (_("A program is being debugged already. Kill it? ")))
1662 error (_("Program not killed."));
1665 /* Calling target_kill may remove the target from the stack. But if
1666 it doesn't (which seems like a win for UDI), remove it now. */
1668 if (target_has_execution)
1671 target_pre_inferior (from_tty);
1674 /* Detach a target after doing deferred register stores. */
1677 target_detach (char *args, int from_tty)
1679 (current_target.to_detach) (args, from_tty);
1683 target_disconnect (char *args, int from_tty)
1685 struct target_ops *t;
1687 for (t = current_target.beneath; t != NULL; t = t->beneath)
1688 if (t->to_disconnect != NULL)
1691 fprintf_unfiltered (gdb_stdlog, "target_disconnect (%s, %d)\n",
1693 t->to_disconnect (t, args, from_tty);
1700 /* Look through the list of possible targets for a target that can
1704 target_follow_fork (int follow_child)
1706 struct target_ops *t;
1708 for (t = current_target.beneath; t != NULL; t = t->beneath)
1710 if (t->to_follow_fork != NULL)
1712 int retval = t->to_follow_fork (t, follow_child);
1714 fprintf_unfiltered (gdb_stdlog, "target_follow_fork (%d) = %d\n",
1715 follow_child, retval);
1720 /* Some target returned a fork event, but did not know how to follow it. */
1721 internal_error (__FILE__, __LINE__,
1722 "could not find a target to follow fork");
1725 /* Look for a target which can describe architectural features, starting
1726 from TARGET. If we find one, return its description. */
1728 const struct target_desc *
1729 target_read_description (struct target_ops *target)
1731 struct target_ops *t;
1733 for (t = target; t != NULL; t = t->beneath)
1734 if (t->to_read_description != NULL)
1736 const struct target_desc *tdesc;
1738 tdesc = t->to_read_description (t);
1746 /* Look through the currently pushed targets. If none of them will
1747 be able to restart the currently running process, issue an error
1751 target_require_runnable (void)
1753 struct target_ops *t;
1755 for (t = target_stack; t != NULL; t = t->beneath)
1757 /* If this target knows how to create a new program, then
1758 assume we will still be able to after killing the current
1759 one. Either killing and mourning will not pop T, or else
1760 find_default_run_target will find it again. */
1761 if (t->to_create_inferior != NULL)
1764 /* Do not worry about thread_stratum targets that can not
1765 create inferiors. Assume they will be pushed again if
1766 necessary, and continue to the process_stratum. */
1767 if (t->to_stratum == thread_stratum)
1771 The \"%s\" target does not support \"run\". Try \"help target\" or \"continue\"."),
1775 /* This function is only called if the target is running. In that
1776 case there should have been a process_stratum target and it
1777 should either know how to create inferiors, or not... */
1778 internal_error (__FILE__, __LINE__, "No targets found");
1781 /* Look through the list of possible targets for a target that can
1782 execute a run or attach command without any other data. This is
1783 used to locate the default process stratum.
1785 If DO_MESG is not NULL, the result is always valid (error() is
1786 called for errors); else, return NULL on error. */
1788 static struct target_ops *
1789 find_default_run_target (char *do_mesg)
1791 struct target_ops **t;
1792 struct target_ops *runable = NULL;
1797 for (t = target_structs; t < target_structs + target_struct_size;
1800 if ((*t)->to_can_run && target_can_run (*t))
1810 error (_("Don't know how to %s. Try \"help target\"."), do_mesg);
1819 find_default_attach (char *args, int from_tty)
1821 struct target_ops *t;
1823 t = find_default_run_target ("attach");
1824 (t->to_attach) (args, from_tty);
1829 find_default_create_inferior (char *exec_file, char *allargs, char **env,
1832 struct target_ops *t;
1834 t = find_default_run_target ("run");
1835 (t->to_create_inferior) (exec_file, allargs, env, from_tty);
1840 find_default_can_async_p (void)
1842 struct target_ops *t;
1844 /* This may be called before the target is pushed on the stack;
1845 look for the default process stratum. If there's none, gdb isn't
1846 configured with a native debugger, and target remote isn't
1848 t = find_default_run_target (NULL);
1849 if (t && t->to_can_async_p)
1850 return (t->to_can_async_p) ();
1855 find_default_is_async_p (void)
1857 struct target_ops *t;
1859 /* This may be called before the target is pushed on the stack;
1860 look for the default process stratum. If there's none, gdb isn't
1861 configured with a native debugger, and target remote isn't
1863 t = find_default_run_target (NULL);
1864 if (t && t->to_is_async_p)
1865 return (t->to_is_async_p) ();
1870 default_region_ok_for_hw_watchpoint (CORE_ADDR addr, int len)
1872 return (len <= TYPE_LENGTH (builtin_type_void_data_ptr));
1888 return_minus_one (void)
1894 * Resize the to_sections pointer. Also make sure that anyone that
1895 * was holding on to an old value of it gets updated.
1896 * Returns the old size.
1900 target_resize_to_sections (struct target_ops *target, int num_added)
1902 struct target_ops **t;
1903 struct section_table *old_value;
1906 old_value = target->to_sections;
1908 if (target->to_sections)
1910 old_count = target->to_sections_end - target->to_sections;
1911 target->to_sections = (struct section_table *)
1912 xrealloc ((char *) target->to_sections,
1913 (sizeof (struct section_table)) * (num_added + old_count));
1918 target->to_sections = (struct section_table *)
1919 xmalloc ((sizeof (struct section_table)) * num_added);
1921 target->to_sections_end = target->to_sections + (num_added + old_count);
1923 /* Check to see if anyone else was pointing to this structure.
1924 If old_value was null, then no one was. */
1928 for (t = target_structs; t < target_structs + target_struct_size;
1931 if ((*t)->to_sections == old_value)
1933 (*t)->to_sections = target->to_sections;
1934 (*t)->to_sections_end = target->to_sections_end;
1937 /* There is a flattened view of the target stack in current_target,
1938 so its to_sections pointer might also need updating. */
1939 if (current_target.to_sections == old_value)
1941 current_target.to_sections = target->to_sections;
1942 current_target.to_sections_end = target->to_sections_end;
1950 /* Remove all target sections taken from ABFD.
1952 Scan the current target stack for targets whose section tables
1953 refer to sections from BFD, and remove those sections. We use this
1954 when we notice that the inferior has unloaded a shared object, for
1957 remove_target_sections (bfd *abfd)
1959 struct target_ops **t;
1961 for (t = target_structs; t < target_structs + target_struct_size; t++)
1963 struct section_table *src, *dest;
1965 dest = (*t)->to_sections;
1966 for (src = (*t)->to_sections; src < (*t)->to_sections_end; src++)
1967 if (src->bfd != abfd)
1969 /* Keep this section. */
1970 if (dest < src) *dest = *src;
1974 /* If we've dropped any sections, resize the section table. */
1976 target_resize_to_sections (*t, dest - src);
1983 /* Find a single runnable target in the stack and return it. If for
1984 some reason there is more than one, return NULL. */
1987 find_run_target (void)
1989 struct target_ops **t;
1990 struct target_ops *runable = NULL;
1995 for (t = target_structs; t < target_structs + target_struct_size; ++t)
1997 if ((*t)->to_can_run && target_can_run (*t))
2004 return (count == 1 ? runable : NULL);
2007 /* Find a single core_stratum target in the list of targets and return it.
2008 If for some reason there is more than one, return NULL. */
2011 find_core_target (void)
2013 struct target_ops **t;
2014 struct target_ops *runable = NULL;
2019 for (t = target_structs; t < target_structs + target_struct_size;
2022 if ((*t)->to_stratum == core_stratum)
2029 return (count == 1 ? runable : NULL);
2033 * Find the next target down the stack from the specified target.
2037 find_target_beneath (struct target_ops *t)
2043 /* The inferior process has died. Long live the inferior! */
2046 generic_mourn_inferior (void)
2048 extern int show_breakpoint_hit_counts;
2050 inferior_ptid = null_ptid;
2052 breakpoint_init_inferior (inf_exited);
2053 registers_changed ();
2055 reopen_exec_file ();
2056 reinit_frame_cache ();
2058 /* It is confusing to the user for ignore counts to stick around
2059 from previous runs of the inferior. So clear them. */
2060 /* However, it is more confusing for the ignore counts to disappear when
2061 using hit counts. So don't clear them if we're counting hits. */
2062 if (!show_breakpoint_hit_counts)
2063 breakpoint_clear_ignore_counts ();
2065 if (deprecated_detach_hook)
2066 deprecated_detach_hook ();
2069 /* Helper function for child_wait and the derivatives of child_wait.
2070 HOSTSTATUS is the waitstatus from wait() or the equivalent; store our
2071 translation of that in OURSTATUS. */
2073 store_waitstatus (struct target_waitstatus *ourstatus, int hoststatus)
2075 if (WIFEXITED (hoststatus))
2077 ourstatus->kind = TARGET_WAITKIND_EXITED;
2078 ourstatus->value.integer = WEXITSTATUS (hoststatus);
2080 else if (!WIFSTOPPED (hoststatus))
2082 ourstatus->kind = TARGET_WAITKIND_SIGNALLED;
2083 ourstatus->value.sig = target_signal_from_host (WTERMSIG (hoststatus));
2087 ourstatus->kind = TARGET_WAITKIND_STOPPED;
2088 ourstatus->value.sig = target_signal_from_host (WSTOPSIG (hoststatus));
2092 /* Returns zero to leave the inferior alone, one to interrupt it. */
2093 int (*target_activity_function) (void);
2094 int target_activity_fd;
2096 /* Convert a normal process ID to a string. Returns the string in a
2100 normal_pid_to_str (ptid_t ptid)
2102 static char buf[32];
2104 xsnprintf (buf, sizeof buf, "process %d", ptid_get_pid (ptid));
2108 /* Error-catcher for target_find_memory_regions */
2109 static int dummy_find_memory_regions (int (*ignore1) (), void *ignore2)
2111 error (_("No target."));
2115 /* Error-catcher for target_make_corefile_notes */
2116 static char * dummy_make_corefile_notes (bfd *ignore1, int *ignore2)
2118 error (_("No target."));
2122 /* Set up the handful of non-empty slots needed by the dummy target
2126 init_dummy_target (void)
2128 dummy_target.to_shortname = "None";
2129 dummy_target.to_longname = "None";
2130 dummy_target.to_doc = "";
2131 dummy_target.to_attach = find_default_attach;
2132 dummy_target.to_create_inferior = find_default_create_inferior;
2133 dummy_target.to_can_async_p = find_default_can_async_p;
2134 dummy_target.to_is_async_p = find_default_is_async_p;
2135 dummy_target.to_pid_to_str = normal_pid_to_str;
2136 dummy_target.to_stratum = dummy_stratum;
2137 dummy_target.to_find_memory_regions = dummy_find_memory_regions;
2138 dummy_target.to_make_corefile_notes = dummy_make_corefile_notes;
2139 dummy_target.to_xfer_partial = default_xfer_partial;
2140 dummy_target.to_magic = OPS_MAGIC;
2144 debug_to_open (char *args, int from_tty)
2146 debug_target.to_open (args, from_tty);
2148 fprintf_unfiltered (gdb_stdlog, "target_open (%s, %d)\n", args, from_tty);
2152 debug_to_close (int quitting)
2154 target_close (&debug_target, quitting);
2155 fprintf_unfiltered (gdb_stdlog, "target_close (%d)\n", quitting);
2159 target_close (struct target_ops *targ, int quitting)
2161 if (targ->to_xclose != NULL)
2162 targ->to_xclose (targ, quitting);
2163 else if (targ->to_close != NULL)
2164 targ->to_close (quitting);
2168 debug_to_attach (char *args, int from_tty)
2170 debug_target.to_attach (args, from_tty);
2172 fprintf_unfiltered (gdb_stdlog, "target_attach (%s, %d)\n", args, from_tty);
2177 debug_to_post_attach (int pid)
2179 debug_target.to_post_attach (pid);
2181 fprintf_unfiltered (gdb_stdlog, "target_post_attach (%d)\n", pid);
2185 debug_to_detach (char *args, int from_tty)
2187 debug_target.to_detach (args, from_tty);
2189 fprintf_unfiltered (gdb_stdlog, "target_detach (%s, %d)\n", args, from_tty);
2193 debug_to_resume (ptid_t ptid, int step, enum target_signal siggnal)
2195 debug_target.to_resume (ptid, step, siggnal);
2197 fprintf_unfiltered (gdb_stdlog, "target_resume (%d, %s, %s)\n", PIDGET (ptid),
2198 step ? "step" : "continue",
2199 target_signal_to_name (siggnal));
2203 debug_to_wait (ptid_t ptid, struct target_waitstatus *status)
2207 retval = debug_target.to_wait (ptid, status);
2209 fprintf_unfiltered (gdb_stdlog,
2210 "target_wait (%d, status) = %d, ", PIDGET (ptid),
2212 fprintf_unfiltered (gdb_stdlog, "status->kind = ");
2213 switch (status->kind)
2215 case TARGET_WAITKIND_EXITED:
2216 fprintf_unfiltered (gdb_stdlog, "exited, status = %d\n",
2217 status->value.integer);
2219 case TARGET_WAITKIND_STOPPED:
2220 fprintf_unfiltered (gdb_stdlog, "stopped, signal = %s\n",
2221 target_signal_to_name (status->value.sig));
2223 case TARGET_WAITKIND_SIGNALLED:
2224 fprintf_unfiltered (gdb_stdlog, "signalled, signal = %s\n",
2225 target_signal_to_name (status->value.sig));
2227 case TARGET_WAITKIND_LOADED:
2228 fprintf_unfiltered (gdb_stdlog, "loaded\n");
2230 case TARGET_WAITKIND_FORKED:
2231 fprintf_unfiltered (gdb_stdlog, "forked\n");
2233 case TARGET_WAITKIND_VFORKED:
2234 fprintf_unfiltered (gdb_stdlog, "vforked\n");
2236 case TARGET_WAITKIND_EXECD:
2237 fprintf_unfiltered (gdb_stdlog, "execd\n");
2239 case TARGET_WAITKIND_SPURIOUS:
2240 fprintf_unfiltered (gdb_stdlog, "spurious\n");
2243 fprintf_unfiltered (gdb_stdlog, "unknown???\n");
2251 debug_print_register (const char * func,
2252 struct regcache *regcache, int regno)
2254 struct gdbarch *gdbarch = get_regcache_arch (regcache);
2255 fprintf_unfiltered (gdb_stdlog, "%s ", func);
2256 if (regno >= 0 && regno < gdbarch_num_regs (gdbarch)
2257 + gdbarch_num_pseudo_regs (gdbarch)
2258 && gdbarch_register_name (gdbarch, regno) != NULL
2259 && gdbarch_register_name (gdbarch, regno)[0] != '\0')
2260 fprintf_unfiltered (gdb_stdlog, "(%s)",
2261 gdbarch_register_name (gdbarch, regno));
2263 fprintf_unfiltered (gdb_stdlog, "(%d)", regno);
2266 int i, size = register_size (gdbarch, regno);
2267 unsigned char buf[MAX_REGISTER_SIZE];
2268 regcache_cooked_read (regcache, regno, buf);
2269 fprintf_unfiltered (gdb_stdlog, " = ");
2270 for (i = 0; i < size; i++)
2272 fprintf_unfiltered (gdb_stdlog, "%02x", buf[i]);
2274 if (size <= sizeof (LONGEST))
2276 ULONGEST val = extract_unsigned_integer (buf, size);
2277 fprintf_unfiltered (gdb_stdlog, " 0x%s %s",
2278 paddr_nz (val), paddr_d (val));
2281 fprintf_unfiltered (gdb_stdlog, "\n");
2285 debug_to_fetch_registers (struct regcache *regcache, int regno)
2287 debug_target.to_fetch_registers (regcache, regno);
2288 debug_print_register ("target_fetch_registers", regcache, regno);
2292 debug_to_store_registers (struct regcache *regcache, int regno)
2294 debug_target.to_store_registers (regcache, regno);
2295 debug_print_register ("target_store_registers", regcache, regno);
2296 fprintf_unfiltered (gdb_stdlog, "\n");
2300 debug_to_prepare_to_store (struct regcache *regcache)
2302 debug_target.to_prepare_to_store (regcache);
2304 fprintf_unfiltered (gdb_stdlog, "target_prepare_to_store ()\n");
2308 deprecated_debug_xfer_memory (CORE_ADDR memaddr, bfd_byte *myaddr, int len,
2309 int write, struct mem_attrib *attrib,
2310 struct target_ops *target)
2314 retval = debug_target.deprecated_xfer_memory (memaddr, myaddr, len, write,
2317 fprintf_unfiltered (gdb_stdlog,
2318 "target_xfer_memory (0x%x, xxx, %d, %s, xxx) = %d",
2319 (unsigned int) memaddr, /* possable truncate long long */
2320 len, write ? "write" : "read", retval);
2326 fputs_unfiltered (", bytes =", gdb_stdlog);
2327 for (i = 0; i < retval; i++)
2329 if ((((long) &(myaddr[i])) & 0xf) == 0)
2331 if (targetdebug < 2 && i > 0)
2333 fprintf_unfiltered (gdb_stdlog, " ...");
2336 fprintf_unfiltered (gdb_stdlog, "\n");
2339 fprintf_unfiltered (gdb_stdlog, " %02x", myaddr[i] & 0xff);
2343 fputc_unfiltered ('\n', gdb_stdlog);
2349 debug_to_files_info (struct target_ops *target)
2351 debug_target.to_files_info (target);
2353 fprintf_unfiltered (gdb_stdlog, "target_files_info (xxx)\n");
2357 debug_to_insert_breakpoint (struct bp_target_info *bp_tgt)
2361 retval = debug_target.to_insert_breakpoint (bp_tgt);
2363 fprintf_unfiltered (gdb_stdlog,
2364 "target_insert_breakpoint (0x%lx, xxx) = %ld\n",
2365 (unsigned long) bp_tgt->placed_address,
2366 (unsigned long) retval);
2371 debug_to_remove_breakpoint (struct bp_target_info *bp_tgt)
2375 retval = debug_target.to_remove_breakpoint (bp_tgt);
2377 fprintf_unfiltered (gdb_stdlog,
2378 "target_remove_breakpoint (0x%lx, xxx) = %ld\n",
2379 (unsigned long) bp_tgt->placed_address,
2380 (unsigned long) retval);
2385 debug_to_can_use_hw_breakpoint (int type, int cnt, int from_tty)
2389 retval = debug_target.to_can_use_hw_breakpoint (type, cnt, from_tty);
2391 fprintf_unfiltered (gdb_stdlog,
2392 "target_can_use_hw_breakpoint (%ld, %ld, %ld) = %ld\n",
2393 (unsigned long) type,
2394 (unsigned long) cnt,
2395 (unsigned long) from_tty,
2396 (unsigned long) retval);
2401 debug_to_region_ok_for_hw_watchpoint (CORE_ADDR addr, int len)
2405 retval = debug_target.to_region_ok_for_hw_watchpoint (addr, len);
2407 fprintf_unfiltered (gdb_stdlog,
2408 "TARGET_REGION_OK_FOR_HW_WATCHPOINT (%ld, %ld) = 0x%lx\n",
2409 (unsigned long) addr,
2410 (unsigned long) len,
2411 (unsigned long) retval);
2416 debug_to_stopped_by_watchpoint (void)
2420 retval = debug_target.to_stopped_by_watchpoint ();
2422 fprintf_unfiltered (gdb_stdlog,
2423 "STOPPED_BY_WATCHPOINT () = %ld\n",
2424 (unsigned long) retval);
2429 debug_to_stopped_data_address (struct target_ops *target, CORE_ADDR *addr)
2433 retval = debug_target.to_stopped_data_address (target, addr);
2435 fprintf_unfiltered (gdb_stdlog,
2436 "target_stopped_data_address ([0x%lx]) = %ld\n",
2437 (unsigned long)*addr,
2438 (unsigned long)retval);
2443 debug_to_insert_hw_breakpoint (struct bp_target_info *bp_tgt)
2447 retval = debug_target.to_insert_hw_breakpoint (bp_tgt);
2449 fprintf_unfiltered (gdb_stdlog,
2450 "target_insert_hw_breakpoint (0x%lx, xxx) = %ld\n",
2451 (unsigned long) bp_tgt->placed_address,
2452 (unsigned long) retval);
2457 debug_to_remove_hw_breakpoint (struct bp_target_info *bp_tgt)
2461 retval = debug_target.to_remove_hw_breakpoint (bp_tgt);
2463 fprintf_unfiltered (gdb_stdlog,
2464 "target_remove_hw_breakpoint (0x%lx, xxx) = %ld\n",
2465 (unsigned long) bp_tgt->placed_address,
2466 (unsigned long) retval);
2471 debug_to_insert_watchpoint (CORE_ADDR addr, int len, int type)
2475 retval = debug_target.to_insert_watchpoint (addr, len, type);
2477 fprintf_unfiltered (gdb_stdlog,
2478 "target_insert_watchpoint (0x%lx, %d, %d) = %ld\n",
2479 (unsigned long) addr, len, type, (unsigned long) retval);
2484 debug_to_remove_watchpoint (CORE_ADDR addr, int len, int type)
2488 retval = debug_target.to_remove_watchpoint (addr, len, type);
2490 fprintf_unfiltered (gdb_stdlog,
2491 "target_remove_watchpoint (0x%lx, %d, %d) = %ld\n",
2492 (unsigned long) addr, len, type, (unsigned long) retval);
2497 debug_to_terminal_init (void)
2499 debug_target.to_terminal_init ();
2501 fprintf_unfiltered (gdb_stdlog, "target_terminal_init ()\n");
2505 debug_to_terminal_inferior (void)
2507 debug_target.to_terminal_inferior ();
2509 fprintf_unfiltered (gdb_stdlog, "target_terminal_inferior ()\n");
2513 debug_to_terminal_ours_for_output (void)
2515 debug_target.to_terminal_ours_for_output ();
2517 fprintf_unfiltered (gdb_stdlog, "target_terminal_ours_for_output ()\n");
2521 debug_to_terminal_ours (void)
2523 debug_target.to_terminal_ours ();
2525 fprintf_unfiltered (gdb_stdlog, "target_terminal_ours ()\n");
2529 debug_to_terminal_save_ours (void)
2531 debug_target.to_terminal_save_ours ();
2533 fprintf_unfiltered (gdb_stdlog, "target_terminal_save_ours ()\n");
2537 debug_to_terminal_info (char *arg, int from_tty)
2539 debug_target.to_terminal_info (arg, from_tty);
2541 fprintf_unfiltered (gdb_stdlog, "target_terminal_info (%s, %d)\n", arg,
2546 debug_to_kill (void)
2548 debug_target.to_kill ();
2550 fprintf_unfiltered (gdb_stdlog, "target_kill ()\n");
2554 debug_to_load (char *args, int from_tty)
2556 debug_target.to_load (args, from_tty);
2558 fprintf_unfiltered (gdb_stdlog, "target_load (%s, %d)\n", args, from_tty);
2562 debug_to_lookup_symbol (char *name, CORE_ADDR *addrp)
2566 retval = debug_target.to_lookup_symbol (name, addrp);
2568 fprintf_unfiltered (gdb_stdlog, "target_lookup_symbol (%s, xxx)\n", name);
2574 debug_to_create_inferior (char *exec_file, char *args, char **env,
2577 debug_target.to_create_inferior (exec_file, args, env, from_tty);
2579 fprintf_unfiltered (gdb_stdlog, "target_create_inferior (%s, %s, xxx, %d)\n",
2580 exec_file, args, from_tty);
2584 debug_to_post_startup_inferior (ptid_t ptid)
2586 debug_target.to_post_startup_inferior (ptid);
2588 fprintf_unfiltered (gdb_stdlog, "target_post_startup_inferior (%d)\n",
2593 debug_to_acknowledge_created_inferior (int pid)
2595 debug_target.to_acknowledge_created_inferior (pid);
2597 fprintf_unfiltered (gdb_stdlog, "target_acknowledge_created_inferior (%d)\n",
2602 debug_to_insert_fork_catchpoint (int pid)
2604 debug_target.to_insert_fork_catchpoint (pid);
2606 fprintf_unfiltered (gdb_stdlog, "target_insert_fork_catchpoint (%d)\n",
2611 debug_to_remove_fork_catchpoint (int pid)
2615 retval = debug_target.to_remove_fork_catchpoint (pid);
2617 fprintf_unfiltered (gdb_stdlog, "target_remove_fork_catchpoint (%d) = %d\n",
2624 debug_to_insert_vfork_catchpoint (int pid)
2626 debug_target.to_insert_vfork_catchpoint (pid);
2628 fprintf_unfiltered (gdb_stdlog, "target_insert_vfork_catchpoint (%d)\n",
2633 debug_to_remove_vfork_catchpoint (int pid)
2637 retval = debug_target.to_remove_vfork_catchpoint (pid);
2639 fprintf_unfiltered (gdb_stdlog, "target_remove_vfork_catchpoint (%d) = %d\n",
2646 debug_to_insert_exec_catchpoint (int pid)
2648 debug_target.to_insert_exec_catchpoint (pid);
2650 fprintf_unfiltered (gdb_stdlog, "target_insert_exec_catchpoint (%d)\n",
2655 debug_to_remove_exec_catchpoint (int pid)
2659 retval = debug_target.to_remove_exec_catchpoint (pid);
2661 fprintf_unfiltered (gdb_stdlog, "target_remove_exec_catchpoint (%d) = %d\n",
2668 debug_to_has_exited (int pid, int wait_status, int *exit_status)
2672 has_exited = debug_target.to_has_exited (pid, wait_status, exit_status);
2674 fprintf_unfiltered (gdb_stdlog, "target_has_exited (%d, %d, %d) = %d\n",
2675 pid, wait_status, *exit_status, has_exited);
2681 debug_to_mourn_inferior (void)
2683 debug_target.to_mourn_inferior ();
2685 fprintf_unfiltered (gdb_stdlog, "target_mourn_inferior ()\n");
2689 debug_to_can_run (void)
2693 retval = debug_target.to_can_run ();
2695 fprintf_unfiltered (gdb_stdlog, "target_can_run () = %d\n", retval);
2701 debug_to_notice_signals (ptid_t ptid)
2703 debug_target.to_notice_signals (ptid);
2705 fprintf_unfiltered (gdb_stdlog, "target_notice_signals (%d)\n",
2710 debug_to_thread_alive (ptid_t ptid)
2714 retval = debug_target.to_thread_alive (ptid);
2716 fprintf_unfiltered (gdb_stdlog, "target_thread_alive (%d) = %d\n",
2717 PIDGET (ptid), retval);
2723 debug_to_find_new_threads (void)
2725 debug_target.to_find_new_threads ();
2727 fputs_unfiltered ("target_find_new_threads ()\n", gdb_stdlog);
2731 debug_to_stop (void)
2733 debug_target.to_stop ();
2735 fprintf_unfiltered (gdb_stdlog, "target_stop ()\n");
2739 debug_to_rcmd (char *command,
2740 struct ui_file *outbuf)
2742 debug_target.to_rcmd (command, outbuf);
2743 fprintf_unfiltered (gdb_stdlog, "target_rcmd (%s, ...)\n", command);
2747 debug_to_pid_to_exec_file (int pid)
2751 exec_file = debug_target.to_pid_to_exec_file (pid);
2753 fprintf_unfiltered (gdb_stdlog, "target_pid_to_exec_file (%d) = %s\n",
2760 setup_target_debug (void)
2762 memcpy (&debug_target, ¤t_target, sizeof debug_target);
2764 current_target.to_open = debug_to_open;
2765 current_target.to_close = debug_to_close;
2766 current_target.to_attach = debug_to_attach;
2767 current_target.to_post_attach = debug_to_post_attach;
2768 current_target.to_detach = debug_to_detach;
2769 current_target.to_resume = debug_to_resume;
2770 current_target.to_wait = debug_to_wait;
2771 current_target.to_fetch_registers = debug_to_fetch_registers;
2772 current_target.to_store_registers = debug_to_store_registers;
2773 current_target.to_prepare_to_store = debug_to_prepare_to_store;
2774 current_target.deprecated_xfer_memory = deprecated_debug_xfer_memory;
2775 current_target.to_files_info = debug_to_files_info;
2776 current_target.to_insert_breakpoint = debug_to_insert_breakpoint;
2777 current_target.to_remove_breakpoint = debug_to_remove_breakpoint;
2778 current_target.to_can_use_hw_breakpoint = debug_to_can_use_hw_breakpoint;
2779 current_target.to_insert_hw_breakpoint = debug_to_insert_hw_breakpoint;
2780 current_target.to_remove_hw_breakpoint = debug_to_remove_hw_breakpoint;
2781 current_target.to_insert_watchpoint = debug_to_insert_watchpoint;
2782 current_target.to_remove_watchpoint = debug_to_remove_watchpoint;
2783 current_target.to_stopped_by_watchpoint = debug_to_stopped_by_watchpoint;
2784 current_target.to_stopped_data_address = debug_to_stopped_data_address;
2785 current_target.to_region_ok_for_hw_watchpoint = debug_to_region_ok_for_hw_watchpoint;
2786 current_target.to_terminal_init = debug_to_terminal_init;
2787 current_target.to_terminal_inferior = debug_to_terminal_inferior;
2788 current_target.to_terminal_ours_for_output = debug_to_terminal_ours_for_output;
2789 current_target.to_terminal_ours = debug_to_terminal_ours;
2790 current_target.to_terminal_save_ours = debug_to_terminal_save_ours;
2791 current_target.to_terminal_info = debug_to_terminal_info;
2792 current_target.to_kill = debug_to_kill;
2793 current_target.to_load = debug_to_load;
2794 current_target.to_lookup_symbol = debug_to_lookup_symbol;
2795 current_target.to_create_inferior = debug_to_create_inferior;
2796 current_target.to_post_startup_inferior = debug_to_post_startup_inferior;
2797 current_target.to_acknowledge_created_inferior = debug_to_acknowledge_created_inferior;
2798 current_target.to_insert_fork_catchpoint = debug_to_insert_fork_catchpoint;
2799 current_target.to_remove_fork_catchpoint = debug_to_remove_fork_catchpoint;
2800 current_target.to_insert_vfork_catchpoint = debug_to_insert_vfork_catchpoint;
2801 current_target.to_remove_vfork_catchpoint = debug_to_remove_vfork_catchpoint;
2802 current_target.to_insert_exec_catchpoint = debug_to_insert_exec_catchpoint;
2803 current_target.to_remove_exec_catchpoint = debug_to_remove_exec_catchpoint;
2804 current_target.to_has_exited = debug_to_has_exited;
2805 current_target.to_mourn_inferior = debug_to_mourn_inferior;
2806 current_target.to_can_run = debug_to_can_run;
2807 current_target.to_notice_signals = debug_to_notice_signals;
2808 current_target.to_thread_alive = debug_to_thread_alive;
2809 current_target.to_find_new_threads = debug_to_find_new_threads;
2810 current_target.to_stop = debug_to_stop;
2811 current_target.to_rcmd = debug_to_rcmd;
2812 current_target.to_pid_to_exec_file = debug_to_pid_to_exec_file;
2816 static char targ_desc[] =
2817 "Names of targets and files being debugged.\n\
2818 Shows the entire stack of targets currently in use (including the exec-file,\n\
2819 core-file, and process, if any), as well as the symbol file name.";
2822 do_monitor_command (char *cmd,
2825 if ((current_target.to_rcmd
2826 == (void (*) (char *, struct ui_file *)) tcomplain)
2827 || (current_target.to_rcmd == debug_to_rcmd
2828 && (debug_target.to_rcmd
2829 == (void (*) (char *, struct ui_file *)) tcomplain)))
2830 error (_("\"monitor\" command not supported by this target."));
2831 target_rcmd (cmd, gdb_stdtarg);
2834 /* Print the name of each layers of our target stack. */
2837 maintenance_print_target_stack (char *cmd, int from_tty)
2839 struct target_ops *t;
2841 printf_filtered (_("The current target stack is:\n"));
2843 for (t = target_stack; t != NULL; t = t->beneath)
2845 printf_filtered (" - %s (%s)\n", t->to_shortname, t->to_longname);
2850 initialize_targets (void)
2852 init_dummy_target ();
2853 push_target (&dummy_target);
2855 add_info ("target", target_info, targ_desc);
2856 add_info ("files", target_info, targ_desc);
2858 add_setshow_zinteger_cmd ("target", class_maintenance, &targetdebug, _("\
2859 Set target debugging."), _("\
2860 Show target debugging."), _("\
2861 When non-zero, target debugging is enabled. Higher numbers are more\n\
2862 verbose. Changes do not take effect until the next \"run\" or \"target\"\n\
2866 &setdebuglist, &showdebuglist);
2868 add_setshow_boolean_cmd ("trust-readonly-sections", class_support,
2869 &trust_readonly, _("\
2870 Set mode for reading from readonly sections."), _("\
2871 Show mode for reading from readonly sections."), _("\
2872 When this mode is on, memory reads from readonly sections (such as .text)\n\
2873 will be read from the object file instead of from the target. This will\n\
2874 result in significant performance improvement for remote targets."),
2876 show_trust_readonly,
2877 &setlist, &showlist);
2879 add_com ("monitor", class_obscure, do_monitor_command,
2880 _("Send a command to the remote monitor (remote targets only)."));
2882 add_cmd ("target-stack", class_maintenance, maintenance_print_target_stack,
2883 _("Print the name of each layer of the internal target stack."),
2884 &maintenanceprintlist);
2886 target_dcache = dcache_init ();