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, 2009
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 "gdbthread.h"
45 #include "inline-frame.h"
47 static void target_info (char *, int);
49 static void kill_or_be_killed (int);
51 static void default_terminal_info (char *, int);
53 static int default_watchpoint_addr_within_range (struct target_ops
*,
54 CORE_ADDR
, CORE_ADDR
, int);
56 static int default_region_ok_for_hw_watchpoint (CORE_ADDR
, int);
58 static int nosymbol (char *, CORE_ADDR
*);
60 static void tcomplain (void) ATTR_NORETURN
;
62 static int nomemory (CORE_ADDR
, char *, int, int, struct target_ops
*);
64 static int return_zero (void);
66 static int return_one (void);
68 static int return_minus_one (void);
70 void target_ignore (void);
72 static void target_command (char *, int);
74 static struct target_ops
*find_default_run_target (char *);
76 static void nosupport_runtime (void);
78 static LONGEST
default_xfer_partial (struct target_ops
*ops
,
79 enum target_object object
,
80 const char *annex
, gdb_byte
*readbuf
,
81 const gdb_byte
*writebuf
,
82 ULONGEST offset
, LONGEST len
);
84 static LONGEST
current_xfer_partial (struct target_ops
*ops
,
85 enum target_object object
,
86 const char *annex
, gdb_byte
*readbuf
,
87 const gdb_byte
*writebuf
,
88 ULONGEST offset
, LONGEST len
);
90 static LONGEST
target_xfer_partial (struct target_ops
*ops
,
91 enum target_object object
,
93 void *readbuf
, const void *writebuf
,
94 ULONGEST offset
, LONGEST len
);
96 static struct gdbarch
*default_thread_architecture (struct target_ops
*ops
,
99 static void init_dummy_target (void);
101 static struct target_ops debug_target
;
103 static void debug_to_open (char *, int);
105 static void debug_to_prepare_to_store (struct regcache
*);
107 static void debug_to_files_info (struct target_ops
*);
109 static int debug_to_insert_breakpoint (struct gdbarch
*,
110 struct bp_target_info
*);
112 static int debug_to_remove_breakpoint (struct gdbarch
*,
113 struct bp_target_info
*);
115 static int debug_to_can_use_hw_breakpoint (int, int, int);
117 static int debug_to_insert_hw_breakpoint (struct gdbarch
*,
118 struct bp_target_info
*);
120 static int debug_to_remove_hw_breakpoint (struct gdbarch
*,
121 struct bp_target_info
*);
123 static int debug_to_insert_watchpoint (CORE_ADDR
, int, int);
125 static int debug_to_remove_watchpoint (CORE_ADDR
, int, int);
127 static int debug_to_stopped_by_watchpoint (void);
129 static int debug_to_stopped_data_address (struct target_ops
*, CORE_ADDR
*);
131 static int debug_to_watchpoint_addr_within_range (struct target_ops
*,
132 CORE_ADDR
, CORE_ADDR
, int);
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_load (char *, int);
150 static int debug_to_lookup_symbol (char *, CORE_ADDR
*);
152 static int debug_to_can_run (void);
154 static void debug_to_notice_signals (ptid_t
);
156 static void debug_to_stop (ptid_t
);
158 /* NOTE: cagney/2004-09-29: Many targets reference this variable in
159 wierd and mysterious ways. Putting the variable here lets those
160 wierd and mysterious ways keep building while they are being
161 converted to the inferior inheritance structure. */
162 struct target_ops deprecated_child_ops
;
164 /* Pointer to array of target architecture structures; the size of the
165 array; the current index into the array; the allocated size of the
167 struct target_ops
**target_structs
;
168 unsigned target_struct_size
;
169 unsigned target_struct_index
;
170 unsigned target_struct_allocsize
;
171 #define DEFAULT_ALLOCSIZE 10
173 /* The initial current target, so that there is always a semi-valid
176 static struct target_ops dummy_target
;
178 /* Top of target stack. */
180 static struct target_ops
*target_stack
;
182 /* The target structure we are currently using to talk to a process
183 or file or whatever "inferior" we have. */
185 struct target_ops current_target
;
187 /* Command list for target. */
189 static struct cmd_list_element
*targetlist
= NULL
;
191 /* Nonzero if we should trust readonly sections from the
192 executable when reading memory. */
194 static int trust_readonly
= 0;
196 /* Nonzero if we should show true memory content including
197 memory breakpoint inserted by gdb. */
199 static int show_memory_breakpoints
= 0;
201 /* Non-zero if we want to see trace of target level stuff. */
203 static int targetdebug
= 0;
205 show_targetdebug (struct ui_file
*file
, int from_tty
,
206 struct cmd_list_element
*c
, const char *value
)
208 fprintf_filtered (file
, _("Target debugging is %s.\n"), value
);
211 static void setup_target_debug (void);
213 /* The option sets this. */
214 static int stack_cache_enabled_p_1
= 1;
215 /* And set_stack_cache_enabled_p updates this.
216 The reason for the separation is so that we don't flush the cache for
217 on->on transitions. */
218 static int stack_cache_enabled_p
= 1;
220 /* This is called *after* the stack-cache has been set.
221 Flush the cache for off->on and on->off transitions.
222 There's no real need to flush the cache for on->off transitions,
223 except cleanliness. */
226 set_stack_cache_enabled_p (char *args
, int from_tty
,
227 struct cmd_list_element
*c
)
229 if (stack_cache_enabled_p
!= stack_cache_enabled_p_1
)
230 target_dcache_invalidate ();
232 stack_cache_enabled_p
= stack_cache_enabled_p_1
;
236 show_stack_cache_enabled_p (struct ui_file
*file
, int from_tty
,
237 struct cmd_list_element
*c
, const char *value
)
239 fprintf_filtered (file
, _("Cache use for stack accesses is %s.\n"), value
);
242 /* Cache of memory operations, to speed up remote access. */
243 static DCACHE
*target_dcache
;
245 /* Invalidate the target dcache. */
248 target_dcache_invalidate (void)
250 dcache_invalidate (target_dcache
);
253 /* The user just typed 'target' without the name of a target. */
256 target_command (char *arg
, int from_tty
)
258 fputs_filtered ("Argument required (target name). Try `help target'\n",
262 /* Default target_has_* methods for process_stratum targets. */
265 default_child_has_all_memory (struct target_ops
*ops
)
267 /* If no inferior selected, then we can't read memory here. */
268 if (ptid_equal (inferior_ptid
, null_ptid
))
275 default_child_has_memory (struct target_ops
*ops
)
277 /* If no inferior selected, then we can't read memory here. */
278 if (ptid_equal (inferior_ptid
, null_ptid
))
285 default_child_has_stack (struct target_ops
*ops
)
287 /* If no inferior selected, there's no stack. */
288 if (ptid_equal (inferior_ptid
, null_ptid
))
295 default_child_has_registers (struct target_ops
*ops
)
297 /* Can't read registers from no inferior. */
298 if (ptid_equal (inferior_ptid
, null_ptid
))
305 default_child_has_execution (struct target_ops
*ops
)
307 /* If there's no thread selected, then we can't make it run through
309 if (ptid_equal (inferior_ptid
, null_ptid
))
317 target_has_all_memory_1 (void)
319 struct target_ops
*t
;
321 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
322 if (t
->to_has_all_memory (t
))
329 target_has_memory_1 (void)
331 struct target_ops
*t
;
333 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
334 if (t
->to_has_memory (t
))
341 target_has_stack_1 (void)
343 struct target_ops
*t
;
345 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
346 if (t
->to_has_stack (t
))
353 target_has_registers_1 (void)
355 struct target_ops
*t
;
357 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
358 if (t
->to_has_registers (t
))
365 target_has_execution_1 (void)
367 struct target_ops
*t
;
369 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
370 if (t
->to_has_execution (t
))
376 /* Add a possible target architecture to the list. */
379 add_target (struct target_ops
*t
)
381 /* Provide default values for all "must have" methods. */
382 if (t
->to_xfer_partial
== NULL
)
383 t
->to_xfer_partial
= default_xfer_partial
;
385 if (t
->to_has_all_memory
== NULL
)
386 t
->to_has_all_memory
= (int (*) (struct target_ops
*)) return_zero
;
388 if (t
->to_has_memory
== NULL
)
389 t
->to_has_memory
= (int (*) (struct target_ops
*)) return_zero
;
391 if (t
->to_has_stack
== NULL
)
392 t
->to_has_stack
= (int (*) (struct target_ops
*)) return_zero
;
394 if (t
->to_has_registers
== NULL
)
395 t
->to_has_registers
= (int (*) (struct target_ops
*)) return_zero
;
397 if (t
->to_has_execution
== NULL
)
398 t
->to_has_execution
= (int (*) (struct target_ops
*)) return_zero
;
402 target_struct_allocsize
= DEFAULT_ALLOCSIZE
;
403 target_structs
= (struct target_ops
**) xmalloc
404 (target_struct_allocsize
* sizeof (*target_structs
));
406 if (target_struct_size
>= target_struct_allocsize
)
408 target_struct_allocsize
*= 2;
409 target_structs
= (struct target_ops
**)
410 xrealloc ((char *) target_structs
,
411 target_struct_allocsize
* sizeof (*target_structs
));
413 target_structs
[target_struct_size
++] = t
;
415 if (targetlist
== NULL
)
416 add_prefix_cmd ("target", class_run
, target_command
, _("\
417 Connect to a target machine or process.\n\
418 The first argument is the type or protocol of the target machine.\n\
419 Remaining arguments are interpreted by the target protocol. For more\n\
420 information on the arguments for a particular protocol, type\n\
421 `help target ' followed by the protocol name."),
422 &targetlist
, "target ", 0, &cmdlist
);
423 add_cmd (t
->to_shortname
, no_class
, t
->to_open
, t
->to_doc
, &targetlist
);
436 struct target_ops
*t
;
438 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
439 if (t
->to_kill
!= NULL
)
442 fprintf_unfiltered (gdb_stdlog
, "target_kill ()\n");
452 target_load (char *arg
, int from_tty
)
454 target_dcache_invalidate ();
455 (*current_target
.to_load
) (arg
, from_tty
);
459 target_create_inferior (char *exec_file
, char *args
,
460 char **env
, int from_tty
)
462 struct target_ops
*t
;
463 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
465 if (t
->to_create_inferior
!= NULL
)
467 t
->to_create_inferior (t
, exec_file
, args
, env
, from_tty
);
469 fprintf_unfiltered (gdb_stdlog
,
470 "target_create_inferior (%s, %s, xxx, %d)\n",
471 exec_file
, args
, from_tty
);
476 internal_error (__FILE__
, __LINE__
,
477 "could not find a target to create inferior");
481 target_terminal_inferior (void)
483 /* A background resume (``run&'') should leave GDB in control of the
485 if (target_is_async_p () && !sync_execution
)
488 /* If GDB is resuming the inferior in the foreground, install
489 inferior's terminal modes. */
490 (*current_target
.to_terminal_inferior
) ();
494 nomemory (CORE_ADDR memaddr
, char *myaddr
, int len
, int write
,
495 struct target_ops
*t
)
497 errno
= EIO
; /* Can't read/write this location */
498 return 0; /* No bytes handled */
504 error (_("You can't do that when your target is `%s'"),
505 current_target
.to_shortname
);
511 error (_("You can't do that without a process to debug."));
515 nosymbol (char *name
, CORE_ADDR
*addrp
)
517 return 1; /* Symbol does not exist in target env */
521 nosupport_runtime (void)
523 if (ptid_equal (inferior_ptid
, null_ptid
))
526 error (_("No run-time support for this"));
531 default_terminal_info (char *args
, int from_tty
)
533 printf_unfiltered (_("No saved terminal information.\n"));
536 /* This is the default target_create_inferior and target_attach function.
537 If the current target is executing, it asks whether to kill it off.
538 If this function returns without calling error(), it has killed off
539 the target, and the operation should be attempted. */
542 kill_or_be_killed (int from_tty
)
544 if (target_has_execution
)
546 printf_unfiltered (_("You are already running a program:\n"));
547 target_files_info ();
548 if (query (_("Kill it? ")))
551 if (target_has_execution
)
552 error (_("Killing the program did not help."));
557 error (_("Program not killed."));
563 /* A default implementation for the to_get_ada_task_ptid target method.
565 This function builds the PTID by using both LWP and TID as part of
566 the PTID lwp and tid elements. The pid used is the pid of the
570 default_get_ada_task_ptid (long lwp
, long tid
)
572 return ptid_build (ptid_get_pid (inferior_ptid
), lwp
, tid
);
575 /* Go through the target stack from top to bottom, copying over zero
576 entries in current_target, then filling in still empty entries. In
577 effect, we are doing class inheritance through the pushed target
580 NOTE: cagney/2003-10-17: The problem with this inheritance, as it
581 is currently implemented, is that it discards any knowledge of
582 which target an inherited method originally belonged to.
583 Consequently, new new target methods should instead explicitly and
584 locally search the target stack for the target that can handle the
588 update_current_target (void)
590 struct target_ops
*t
;
592 /* First, reset current's contents. */
593 memset (¤t_target
, 0, sizeof (current_target
));
595 #define INHERIT(FIELD, TARGET) \
596 if (!current_target.FIELD) \
597 current_target.FIELD = (TARGET)->FIELD
599 for (t
= target_stack
; t
; t
= t
->beneath
)
601 INHERIT (to_shortname
, t
);
602 INHERIT (to_longname
, t
);
604 /* Do not inherit to_open. */
605 /* Do not inherit to_close. */
606 /* Do not inherit to_attach. */
607 INHERIT (to_post_attach
, t
);
608 INHERIT (to_attach_no_wait
, t
);
609 /* Do not inherit to_detach. */
610 /* Do not inherit to_disconnect. */
611 /* Do not inherit to_resume. */
612 /* Do not inherit to_wait. */
613 /* Do not inherit to_fetch_registers. */
614 /* Do not inherit to_store_registers. */
615 INHERIT (to_prepare_to_store
, t
);
616 INHERIT (deprecated_xfer_memory
, t
);
617 INHERIT (to_files_info
, t
);
618 INHERIT (to_insert_breakpoint
, t
);
619 INHERIT (to_remove_breakpoint
, t
);
620 INHERIT (to_can_use_hw_breakpoint
, t
);
621 INHERIT (to_insert_hw_breakpoint
, t
);
622 INHERIT (to_remove_hw_breakpoint
, t
);
623 INHERIT (to_insert_watchpoint
, t
);
624 INHERIT (to_remove_watchpoint
, t
);
625 INHERIT (to_stopped_data_address
, t
);
626 INHERIT (to_have_steppable_watchpoint
, t
);
627 INHERIT (to_have_continuable_watchpoint
, t
);
628 INHERIT (to_stopped_by_watchpoint
, t
);
629 INHERIT (to_watchpoint_addr_within_range
, t
);
630 INHERIT (to_region_ok_for_hw_watchpoint
, t
);
631 INHERIT (to_terminal_init
, t
);
632 INHERIT (to_terminal_inferior
, t
);
633 INHERIT (to_terminal_ours_for_output
, t
);
634 INHERIT (to_terminal_ours
, t
);
635 INHERIT (to_terminal_save_ours
, t
);
636 INHERIT (to_terminal_info
, t
);
637 /* Do not inherit to_kill. */
638 INHERIT (to_load
, t
);
639 INHERIT (to_lookup_symbol
, t
);
640 /* Do no inherit to_create_inferior. */
641 INHERIT (to_post_startup_inferior
, t
);
642 INHERIT (to_acknowledge_created_inferior
, t
);
643 INHERIT (to_insert_fork_catchpoint
, t
);
644 INHERIT (to_remove_fork_catchpoint
, t
);
645 INHERIT (to_insert_vfork_catchpoint
, t
);
646 INHERIT (to_remove_vfork_catchpoint
, t
);
647 /* Do not inherit to_follow_fork. */
648 INHERIT (to_insert_exec_catchpoint
, t
);
649 INHERIT (to_remove_exec_catchpoint
, t
);
650 INHERIT (to_set_syscall_catchpoint
, t
);
651 INHERIT (to_has_exited
, t
);
652 /* Do not inherit to_mourn_inferiour. */
653 INHERIT (to_can_run
, t
);
654 INHERIT (to_notice_signals
, t
);
655 /* Do not inherit to_thread_alive. */
656 /* Do not inherit to_find_new_threads. */
657 /* Do not inherit to_pid_to_str. */
658 INHERIT (to_extra_thread_info
, t
);
659 INHERIT (to_stop
, t
);
660 /* Do not inherit to_xfer_partial. */
661 INHERIT (to_rcmd
, t
);
662 INHERIT (to_pid_to_exec_file
, t
);
663 INHERIT (to_log_command
, t
);
664 INHERIT (to_stratum
, t
);
665 /* Do not inherit to_has_all_memory */
666 /* Do not inherit to_has_memory */
667 /* Do not inherit to_has_stack */
668 /* Do not inherit to_has_registers */
669 /* Do not inherit to_has_execution */
670 INHERIT (to_has_thread_control
, t
);
671 INHERIT (to_can_async_p
, t
);
672 INHERIT (to_is_async_p
, t
);
673 INHERIT (to_async
, t
);
674 INHERIT (to_async_mask
, t
);
675 INHERIT (to_find_memory_regions
, t
);
676 INHERIT (to_make_corefile_notes
, t
);
677 /* Do not inherit to_get_thread_local_address. */
678 INHERIT (to_can_execute_reverse
, t
);
679 INHERIT (to_thread_architecture
, t
);
680 /* Do not inherit to_read_description. */
681 INHERIT (to_get_ada_task_ptid
, t
);
682 /* Do not inherit to_search_memory. */
683 INHERIT (to_supports_multi_process
, t
);
684 INHERIT (to_magic
, t
);
685 /* Do not inherit to_memory_map. */
686 /* Do not inherit to_flash_erase. */
687 /* Do not inherit to_flash_done. */
691 /* Clean up a target struct so it no longer has any zero pointers in
692 it. Some entries are defaulted to a method that print an error,
693 others are hard-wired to a standard recursive default. */
695 #define de_fault(field, value) \
696 if (!current_target.field) \
697 current_target.field = value
700 (void (*) (char *, int))
705 de_fault (to_post_attach
,
708 de_fault (to_prepare_to_store
,
709 (void (*) (struct regcache
*))
711 de_fault (deprecated_xfer_memory
,
712 (int (*) (CORE_ADDR
, gdb_byte
*, int, int, struct mem_attrib
*, struct target_ops
*))
714 de_fault (to_files_info
,
715 (void (*) (struct target_ops
*))
717 de_fault (to_insert_breakpoint
,
718 memory_insert_breakpoint
);
719 de_fault (to_remove_breakpoint
,
720 memory_remove_breakpoint
);
721 de_fault (to_can_use_hw_breakpoint
,
722 (int (*) (int, int, int))
724 de_fault (to_insert_hw_breakpoint
,
725 (int (*) (struct gdbarch
*, struct bp_target_info
*))
727 de_fault (to_remove_hw_breakpoint
,
728 (int (*) (struct gdbarch
*, struct bp_target_info
*))
730 de_fault (to_insert_watchpoint
,
731 (int (*) (CORE_ADDR
, int, int))
733 de_fault (to_remove_watchpoint
,
734 (int (*) (CORE_ADDR
, int, int))
736 de_fault (to_stopped_by_watchpoint
,
739 de_fault (to_stopped_data_address
,
740 (int (*) (struct target_ops
*, CORE_ADDR
*))
742 de_fault (to_watchpoint_addr_within_range
,
743 default_watchpoint_addr_within_range
);
744 de_fault (to_region_ok_for_hw_watchpoint
,
745 default_region_ok_for_hw_watchpoint
);
746 de_fault (to_terminal_init
,
749 de_fault (to_terminal_inferior
,
752 de_fault (to_terminal_ours_for_output
,
755 de_fault (to_terminal_ours
,
758 de_fault (to_terminal_save_ours
,
761 de_fault (to_terminal_info
,
762 default_terminal_info
);
764 (void (*) (char *, int))
766 de_fault (to_lookup_symbol
,
767 (int (*) (char *, CORE_ADDR
*))
769 de_fault (to_post_startup_inferior
,
772 de_fault (to_acknowledge_created_inferior
,
775 de_fault (to_insert_fork_catchpoint
,
778 de_fault (to_remove_fork_catchpoint
,
781 de_fault (to_insert_vfork_catchpoint
,
784 de_fault (to_remove_vfork_catchpoint
,
787 de_fault (to_insert_exec_catchpoint
,
790 de_fault (to_remove_exec_catchpoint
,
793 de_fault (to_set_syscall_catchpoint
,
794 (int (*) (int, int, int, int, int *))
796 de_fault (to_has_exited
,
797 (int (*) (int, int, int *))
799 de_fault (to_can_run
,
801 de_fault (to_notice_signals
,
804 de_fault (to_extra_thread_info
,
805 (char *(*) (struct thread_info
*))
810 current_target
.to_xfer_partial
= current_xfer_partial
;
812 (void (*) (char *, struct ui_file
*))
814 de_fault (to_pid_to_exec_file
,
818 (void (*) (void (*) (enum inferior_event_type
, void*), void*))
820 de_fault (to_async_mask
,
823 de_fault (to_thread_architecture
,
824 default_thread_architecture
);
825 current_target
.to_read_description
= NULL
;
826 de_fault (to_get_ada_task_ptid
,
827 (ptid_t (*) (long, long))
828 default_get_ada_task_ptid
);
829 de_fault (to_supports_multi_process
,
834 /* Finally, position the target-stack beneath the squashed
835 "current_target". That way code looking for a non-inherited
836 target method can quickly and simply find it. */
837 current_target
.beneath
= target_stack
;
840 setup_target_debug ();
843 /* Push a new target type into the stack of the existing target accessors,
844 possibly superseding some of the existing accessors.
846 Result is zero if the pushed target ended up on top of the stack,
847 nonzero if at least one target is on top of it.
849 Rather than allow an empty stack, we always have the dummy target at
850 the bottom stratum, so we can call the function vectors without
854 push_target (struct target_ops
*t
)
856 struct target_ops
**cur
;
858 /* Check magic number. If wrong, it probably means someone changed
859 the struct definition, but not all the places that initialize one. */
860 if (t
->to_magic
!= OPS_MAGIC
)
862 fprintf_unfiltered (gdb_stderr
,
863 "Magic number of %s target struct wrong\n",
865 internal_error (__FILE__
, __LINE__
, _("failed internal consistency check"));
868 /* Find the proper stratum to install this target in. */
869 for (cur
= &target_stack
; (*cur
) != NULL
; cur
= &(*cur
)->beneath
)
871 if ((int) (t
->to_stratum
) >= (int) (*cur
)->to_stratum
)
875 /* If there's already targets at this stratum, remove them. */
876 /* FIXME: cagney/2003-10-15: I think this should be popping all
877 targets to CUR, and not just those at this stratum level. */
878 while ((*cur
) != NULL
&& t
->to_stratum
== (*cur
)->to_stratum
)
880 /* There's already something at this stratum level. Close it,
881 and un-hook it from the stack. */
882 struct target_ops
*tmp
= (*cur
);
883 (*cur
) = (*cur
)->beneath
;
885 target_close (tmp
, 0);
888 /* We have removed all targets in our stratum, now add the new one. */
892 update_current_target ();
895 return (t
!= target_stack
);
898 /* Remove a target_ops vector from the stack, wherever it may be.
899 Return how many times it was removed (0 or 1). */
902 unpush_target (struct target_ops
*t
)
904 struct target_ops
**cur
;
905 struct target_ops
*tmp
;
907 if (t
->to_stratum
== dummy_stratum
)
908 internal_error (__FILE__
, __LINE__
,
909 "Attempt to unpush the dummy target");
911 /* Look for the specified target. Note that we assume that a target
912 can only occur once in the target stack. */
914 for (cur
= &target_stack
; (*cur
) != NULL
; cur
= &(*cur
)->beneath
)
921 return 0; /* Didn't find target_ops, quit now */
923 /* NOTE: cagney/2003-12-06: In '94 the close call was made
924 unconditional by moving it to before the above check that the
925 target was in the target stack (something about "Change the way
926 pushing and popping of targets work to support target overlays
927 and inheritance"). This doesn't make much sense - only open
928 targets should be closed. */
931 /* Unchain the target */
933 (*cur
) = (*cur
)->beneath
;
936 update_current_target ();
944 target_close (target_stack
, 0); /* Let it clean up */
945 if (unpush_target (target_stack
) == 1)
948 fprintf_unfiltered (gdb_stderr
,
949 "pop_target couldn't find target %s\n",
950 current_target
.to_shortname
);
951 internal_error (__FILE__
, __LINE__
, _("failed internal consistency check"));
955 pop_all_targets_above (enum strata above_stratum
, int quitting
)
957 while ((int) (current_target
.to_stratum
) > (int) above_stratum
)
959 target_close (target_stack
, quitting
);
960 if (!unpush_target (target_stack
))
962 fprintf_unfiltered (gdb_stderr
,
963 "pop_all_targets couldn't find target %s\n",
964 target_stack
->to_shortname
);
965 internal_error (__FILE__
, __LINE__
,
966 _("failed internal consistency check"));
973 pop_all_targets (int quitting
)
975 pop_all_targets_above (dummy_stratum
, quitting
);
978 /* Using the objfile specified in OBJFILE, find the address for the
979 current thread's thread-local storage with offset OFFSET. */
981 target_translate_tls_address (struct objfile
*objfile
, CORE_ADDR offset
)
983 volatile CORE_ADDR addr
= 0;
984 struct target_ops
*target
;
986 for (target
= current_target
.beneath
;
988 target
= target
->beneath
)
990 if (target
->to_get_thread_local_address
!= NULL
)
995 && gdbarch_fetch_tls_load_module_address_p (target_gdbarch
))
997 ptid_t ptid
= inferior_ptid
;
998 volatile struct gdb_exception ex
;
1000 TRY_CATCH (ex
, RETURN_MASK_ALL
)
1004 /* Fetch the load module address for this objfile. */
1005 lm_addr
= gdbarch_fetch_tls_load_module_address (target_gdbarch
,
1007 /* If it's 0, throw the appropriate exception. */
1009 throw_error (TLS_LOAD_MODULE_NOT_FOUND_ERROR
,
1010 _("TLS load module not found"));
1012 addr
= target
->to_get_thread_local_address (target
, ptid
, lm_addr
, offset
);
1014 /* If an error occurred, print TLS related messages here. Otherwise,
1015 throw the error to some higher catcher. */
1018 int objfile_is_library
= (objfile
->flags
& OBJF_SHARED
);
1022 case TLS_NO_LIBRARY_SUPPORT_ERROR
:
1023 error (_("Cannot find thread-local variables in this thread library."));
1025 case TLS_LOAD_MODULE_NOT_FOUND_ERROR
:
1026 if (objfile_is_library
)
1027 error (_("Cannot find shared library `%s' in dynamic"
1028 " linker's load module list"), objfile
->name
);
1030 error (_("Cannot find executable file `%s' in dynamic"
1031 " linker's load module list"), objfile
->name
);
1033 case TLS_NOT_ALLOCATED_YET_ERROR
:
1034 if (objfile_is_library
)
1035 error (_("The inferior has not yet allocated storage for"
1036 " thread-local variables in\n"
1037 "the shared library `%s'\n"
1039 objfile
->name
, target_pid_to_str (ptid
));
1041 error (_("The inferior has not yet allocated storage for"
1042 " thread-local variables in\n"
1043 "the executable `%s'\n"
1045 objfile
->name
, target_pid_to_str (ptid
));
1047 case TLS_GENERIC_ERROR
:
1048 if (objfile_is_library
)
1049 error (_("Cannot find thread-local storage for %s, "
1050 "shared library %s:\n%s"),
1051 target_pid_to_str (ptid
),
1052 objfile
->name
, ex
.message
);
1054 error (_("Cannot find thread-local storage for %s, "
1055 "executable file %s:\n%s"),
1056 target_pid_to_str (ptid
),
1057 objfile
->name
, ex
.message
);
1060 throw_exception (ex
);
1065 /* It wouldn't be wrong here to try a gdbarch method, too; finding
1066 TLS is an ABI-specific thing. But we don't do that yet. */
1068 error (_("Cannot find thread-local variables on this target"));
1074 #define MIN(A, B) (((A) <= (B)) ? (A) : (B))
1076 /* target_read_string -- read a null terminated string, up to LEN bytes,
1077 from MEMADDR in target. Set *ERRNOP to the errno code, or 0 if successful.
1078 Set *STRING to a pointer to malloc'd memory containing the data; the caller
1079 is responsible for freeing it. Return the number of bytes successfully
1083 target_read_string (CORE_ADDR memaddr
, char **string
, int len
, int *errnop
)
1085 int tlen
, origlen
, offset
, i
;
1089 int buffer_allocated
;
1091 unsigned int nbytes_read
= 0;
1093 gdb_assert (string
);
1095 /* Small for testing. */
1096 buffer_allocated
= 4;
1097 buffer
= xmalloc (buffer_allocated
);
1104 tlen
= MIN (len
, 4 - (memaddr
& 3));
1105 offset
= memaddr
& 3;
1107 errcode
= target_read_memory (memaddr
& ~3, buf
, sizeof buf
);
1110 /* The transfer request might have crossed the boundary to an
1111 unallocated region of memory. Retry the transfer, requesting
1115 errcode
= target_read_memory (memaddr
, buf
, 1);
1120 if (bufptr
- buffer
+ tlen
> buffer_allocated
)
1123 bytes
= bufptr
- buffer
;
1124 buffer_allocated
*= 2;
1125 buffer
= xrealloc (buffer
, buffer_allocated
);
1126 bufptr
= buffer
+ bytes
;
1129 for (i
= 0; i
< tlen
; i
++)
1131 *bufptr
++ = buf
[i
+ offset
];
1132 if (buf
[i
+ offset
] == '\000')
1134 nbytes_read
+= i
+ 1;
1141 nbytes_read
+= tlen
;
1150 struct target_section_table
*
1151 target_get_section_table (struct target_ops
*target
)
1153 struct target_ops
*t
;
1156 fprintf_unfiltered (gdb_stdlog
, "target_get_section_table ()\n");
1158 for (t
= target
; t
!= NULL
; t
= t
->beneath
)
1159 if (t
->to_get_section_table
!= NULL
)
1160 return (*t
->to_get_section_table
) (t
);
1165 /* Find a section containing ADDR. */
1167 struct target_section
*
1168 target_section_by_addr (struct target_ops
*target
, CORE_ADDR addr
)
1170 struct target_section_table
*table
= target_get_section_table (target
);
1171 struct target_section
*secp
;
1176 for (secp
= table
->sections
; secp
< table
->sections_end
; secp
++)
1178 if (addr
>= secp
->addr
&& addr
< secp
->endaddr
)
1184 /* Perform a partial memory transfer. The arguments and return
1185 value are just as for target_xfer_partial. */
1188 memory_xfer_partial (struct target_ops
*ops
, enum target_object object
,
1189 void *readbuf
, const void *writebuf
, ULONGEST memaddr
,
1194 struct mem_region
*region
;
1195 struct inferior
*inf
;
1197 /* Zero length requests are ok and require no work. */
1201 /* For accesses to unmapped overlay sections, read directly from
1202 files. Must do this first, as MEMADDR may need adjustment. */
1203 if (readbuf
!= NULL
&& overlay_debugging
)
1205 struct obj_section
*section
= find_pc_overlay (memaddr
);
1206 if (pc_in_unmapped_range (memaddr
, section
))
1208 struct target_section_table
*table
1209 = target_get_section_table (ops
);
1210 const char *section_name
= section
->the_bfd_section
->name
;
1211 memaddr
= overlay_mapped_address (memaddr
, section
);
1212 return section_table_xfer_memory_partial (readbuf
, writebuf
,
1215 table
->sections_end
,
1220 /* Try the executable files, if "trust-readonly-sections" is set. */
1221 if (readbuf
!= NULL
&& trust_readonly
)
1223 struct target_section
*secp
;
1224 struct target_section_table
*table
;
1226 secp
= target_section_by_addr (ops
, memaddr
);
1228 && (bfd_get_section_flags (secp
->bfd
, secp
->the_bfd_section
)
1231 table
= target_get_section_table (ops
);
1232 return section_table_xfer_memory_partial (readbuf
, writebuf
,
1235 table
->sections_end
,
1240 /* Try GDB's internal data cache. */
1241 region
= lookup_mem_region (memaddr
);
1242 /* region->hi == 0 means there's no upper bound. */
1243 if (memaddr
+ len
< region
->hi
|| region
->hi
== 0)
1246 reg_len
= region
->hi
- memaddr
;
1248 switch (region
->attrib
.mode
)
1251 if (writebuf
!= NULL
)
1256 if (readbuf
!= NULL
)
1261 /* We only support writing to flash during "load" for now. */
1262 if (writebuf
!= NULL
)
1263 error (_("Writing to flash memory forbidden in this context"));
1270 if (!ptid_equal (inferior_ptid
, null_ptid
))
1271 inf
= find_inferior_pid (ptid_get_pid (inferior_ptid
));
1276 && (region
->attrib
.cache
1277 || (stack_cache_enabled_p
&& object
== TARGET_OBJECT_STACK_MEMORY
)))
1279 if (readbuf
!= NULL
)
1280 res
= dcache_xfer_memory (ops
, target_dcache
, memaddr
, readbuf
,
1283 /* FIXME drow/2006-08-09: If we're going to preserve const
1284 correctness dcache_xfer_memory should take readbuf and
1286 res
= dcache_xfer_memory (ops
, target_dcache
, memaddr
,
1293 if (readbuf
&& !show_memory_breakpoints
)
1294 breakpoint_restore_shadows (readbuf
, memaddr
, reg_len
);
1299 /* If none of those methods found the memory we wanted, fall back
1300 to a target partial transfer. Normally a single call to
1301 to_xfer_partial is enough; if it doesn't recognize an object
1302 it will call the to_xfer_partial of the next target down.
1303 But for memory this won't do. Memory is the only target
1304 object which can be read from more than one valid target.
1305 A core file, for instance, could have some of memory but
1306 delegate other bits to the target below it. So, we must
1307 manually try all targets. */
1311 res
= ops
->to_xfer_partial (ops
, TARGET_OBJECT_MEMORY
, NULL
,
1312 readbuf
, writebuf
, memaddr
, reg_len
);
1316 /* We want to continue past core files to executables, but not
1317 past a running target's memory. */
1318 if (ops
->to_has_all_memory (ops
))
1323 while (ops
!= NULL
);
1325 if (readbuf
&& !show_memory_breakpoints
)
1326 breakpoint_restore_shadows (readbuf
, memaddr
, reg_len
);
1328 /* Make sure the cache gets updated no matter what - if we are writing
1329 to the stack. Even if this write is not tagged as such, we still need
1330 to update the cache. */
1335 && !region
->attrib
.cache
1336 && stack_cache_enabled_p
1337 && object
!= TARGET_OBJECT_STACK_MEMORY
)
1339 dcache_update (target_dcache
, memaddr
, (void *) writebuf
, res
);
1342 /* If we still haven't got anything, return the last error. We
1348 restore_show_memory_breakpoints (void *arg
)
1350 show_memory_breakpoints
= (uintptr_t) arg
;
1354 make_show_memory_breakpoints_cleanup (int show
)
1356 int current
= show_memory_breakpoints
;
1357 show_memory_breakpoints
= show
;
1359 return make_cleanup (restore_show_memory_breakpoints
,
1360 (void *) (uintptr_t) current
);
1364 target_xfer_partial (struct target_ops
*ops
,
1365 enum target_object object
, const char *annex
,
1366 void *readbuf
, const void *writebuf
,
1367 ULONGEST offset
, LONGEST len
)
1371 gdb_assert (ops
->to_xfer_partial
!= NULL
);
1373 /* If this is a memory transfer, let the memory-specific code
1374 have a look at it instead. Memory transfers are more
1376 if (object
== TARGET_OBJECT_MEMORY
|| object
== TARGET_OBJECT_STACK_MEMORY
)
1377 retval
= memory_xfer_partial (ops
, object
, readbuf
,
1378 writebuf
, offset
, len
);
1381 enum target_object raw_object
= object
;
1383 /* If this is a raw memory transfer, request the normal
1384 memory object from other layers. */
1385 if (raw_object
== TARGET_OBJECT_RAW_MEMORY
)
1386 raw_object
= TARGET_OBJECT_MEMORY
;
1388 retval
= ops
->to_xfer_partial (ops
, raw_object
, annex
, readbuf
,
1389 writebuf
, offset
, len
);
1394 const unsigned char *myaddr
= NULL
;
1396 fprintf_unfiltered (gdb_stdlog
,
1397 "%s:target_xfer_partial (%d, %s, %s, %s, %s, %s) = %s",
1400 (annex
? annex
: "(null)"),
1401 host_address_to_string (readbuf
),
1402 host_address_to_string (writebuf
),
1403 core_addr_to_string_nz (offset
),
1404 plongest (len
), plongest (retval
));
1410 if (retval
> 0 && myaddr
!= NULL
)
1414 fputs_unfiltered (", bytes =", gdb_stdlog
);
1415 for (i
= 0; i
< retval
; i
++)
1417 if ((((intptr_t) &(myaddr
[i
])) & 0xf) == 0)
1419 if (targetdebug
< 2 && i
> 0)
1421 fprintf_unfiltered (gdb_stdlog
, " ...");
1424 fprintf_unfiltered (gdb_stdlog
, "\n");
1427 fprintf_unfiltered (gdb_stdlog
, " %02x", myaddr
[i
] & 0xff);
1431 fputc_unfiltered ('\n', gdb_stdlog
);
1436 /* Read LEN bytes of target memory at address MEMADDR, placing the results in
1437 GDB's memory at MYADDR. Returns either 0 for success or an errno value
1438 if any error occurs.
1440 If an error occurs, no guarantee is made about the contents of the data at
1441 MYADDR. In particular, the caller should not depend upon partial reads
1442 filling the buffer with good data. There is no way for the caller to know
1443 how much good data might have been transfered anyway. Callers that can
1444 deal with partial reads should call target_read (which will retry until
1445 it makes no progress, and then return how much was transferred). */
1448 target_read_memory (CORE_ADDR memaddr
, gdb_byte
*myaddr
, int len
)
1450 /* Dispatch to the topmost target, not the flattened current_target.
1451 Memory accesses check target->to_has_(all_)memory, and the
1452 flattened target doesn't inherit those. */
1453 if (target_read (current_target
.beneath
, TARGET_OBJECT_MEMORY
, NULL
,
1454 myaddr
, memaddr
, len
) == len
)
1460 /* Like target_read_memory, but specify explicitly that this is a read from
1461 the target's stack. This may trigger different cache behavior. */
1464 target_read_stack (CORE_ADDR memaddr
, gdb_byte
*myaddr
, int len
)
1466 /* Dispatch to the topmost target, not the flattened current_target.
1467 Memory accesses check target->to_has_(all_)memory, and the
1468 flattened target doesn't inherit those. */
1470 if (target_read (current_target
.beneath
, TARGET_OBJECT_STACK_MEMORY
, NULL
,
1471 myaddr
, memaddr
, len
) == len
)
1478 target_write_memory (CORE_ADDR memaddr
, const gdb_byte
*myaddr
, int len
)
1480 /* Dispatch to the topmost target, not the flattened current_target.
1481 Memory accesses check target->to_has_(all_)memory, and the
1482 flattened target doesn't inherit those. */
1483 if (target_write (current_target
.beneath
, TARGET_OBJECT_MEMORY
, NULL
,
1484 myaddr
, memaddr
, len
) == len
)
1490 /* Fetch the target's memory map. */
1493 target_memory_map (void)
1495 VEC(mem_region_s
) *result
;
1496 struct mem_region
*last_one
, *this_one
;
1498 struct target_ops
*t
;
1501 fprintf_unfiltered (gdb_stdlog
, "target_memory_map ()\n");
1503 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
1504 if (t
->to_memory_map
!= NULL
)
1510 result
= t
->to_memory_map (t
);
1514 qsort (VEC_address (mem_region_s
, result
),
1515 VEC_length (mem_region_s
, result
),
1516 sizeof (struct mem_region
), mem_region_cmp
);
1518 /* Check that regions do not overlap. Simultaneously assign
1519 a numbering for the "mem" commands to use to refer to
1522 for (ix
= 0; VEC_iterate (mem_region_s
, result
, ix
, this_one
); ix
++)
1524 this_one
->number
= ix
;
1526 if (last_one
&& last_one
->hi
> this_one
->lo
)
1528 warning (_("Overlapping regions in memory map: ignoring"));
1529 VEC_free (mem_region_s
, result
);
1532 last_one
= this_one
;
1539 target_flash_erase (ULONGEST address
, LONGEST length
)
1541 struct target_ops
*t
;
1543 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
1544 if (t
->to_flash_erase
!= NULL
)
1547 fprintf_unfiltered (gdb_stdlog
, "target_flash_erase (%s, %s)\n",
1548 hex_string (address
), phex (length
, 0));
1549 t
->to_flash_erase (t
, address
, length
);
1557 target_flash_done (void)
1559 struct target_ops
*t
;
1561 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
1562 if (t
->to_flash_done
!= NULL
)
1565 fprintf_unfiltered (gdb_stdlog
, "target_flash_done\n");
1566 t
->to_flash_done (t
);
1574 show_trust_readonly (struct ui_file
*file
, int from_tty
,
1575 struct cmd_list_element
*c
, const char *value
)
1577 fprintf_filtered (file
, _("\
1578 Mode for reading from readonly sections is %s.\n"),
1582 /* More generic transfers. */
1585 default_xfer_partial (struct target_ops
*ops
, enum target_object object
,
1586 const char *annex
, gdb_byte
*readbuf
,
1587 const gdb_byte
*writebuf
, ULONGEST offset
, LONGEST len
)
1589 if (object
== TARGET_OBJECT_MEMORY
1590 && ops
->deprecated_xfer_memory
!= NULL
)
1591 /* If available, fall back to the target's
1592 "deprecated_xfer_memory" method. */
1596 if (writebuf
!= NULL
)
1598 void *buffer
= xmalloc (len
);
1599 struct cleanup
*cleanup
= make_cleanup (xfree
, buffer
);
1600 memcpy (buffer
, writebuf
, len
);
1601 xfered
= ops
->deprecated_xfer_memory (offset
, buffer
, len
,
1602 1/*write*/, NULL
, ops
);
1603 do_cleanups (cleanup
);
1605 if (readbuf
!= NULL
)
1606 xfered
= ops
->deprecated_xfer_memory (offset
, readbuf
, len
,
1607 0/*read*/, NULL
, ops
);
1610 else if (xfered
== 0 && errno
== 0)
1611 /* "deprecated_xfer_memory" uses 0, cross checked against
1612 ERRNO as one indication of an error. */
1617 else if (ops
->beneath
!= NULL
)
1618 return ops
->beneath
->to_xfer_partial (ops
->beneath
, object
, annex
,
1619 readbuf
, writebuf
, offset
, len
);
1624 /* The xfer_partial handler for the topmost target. Unlike the default,
1625 it does not need to handle memory specially; it just passes all
1626 requests down the stack. */
1629 current_xfer_partial (struct target_ops
*ops
, enum target_object object
,
1630 const char *annex
, gdb_byte
*readbuf
,
1631 const gdb_byte
*writebuf
, ULONGEST offset
, LONGEST len
)
1633 if (ops
->beneath
!= NULL
)
1634 return ops
->beneath
->to_xfer_partial (ops
->beneath
, object
, annex
,
1635 readbuf
, writebuf
, offset
, len
);
1640 /* Target vector read/write partial wrapper functions.
1642 NOTE: cagney/2003-10-21: I wonder if having "to_xfer_partial
1643 (inbuf, outbuf)", instead of separate read/write methods, make life
1647 target_read_partial (struct target_ops
*ops
,
1648 enum target_object object
,
1649 const char *annex
, gdb_byte
*buf
,
1650 ULONGEST offset
, LONGEST len
)
1652 return target_xfer_partial (ops
, object
, annex
, buf
, NULL
, offset
, len
);
1656 target_write_partial (struct target_ops
*ops
,
1657 enum target_object object
,
1658 const char *annex
, const gdb_byte
*buf
,
1659 ULONGEST offset
, LONGEST len
)
1661 return target_xfer_partial (ops
, object
, annex
, NULL
, buf
, offset
, len
);
1664 /* Wrappers to perform the full transfer. */
1666 target_read (struct target_ops
*ops
,
1667 enum target_object object
,
1668 const char *annex
, gdb_byte
*buf
,
1669 ULONGEST offset
, LONGEST len
)
1672 while (xfered
< len
)
1674 LONGEST xfer
= target_read_partial (ops
, object
, annex
,
1675 (gdb_byte
*) buf
+ xfered
,
1676 offset
+ xfered
, len
- xfered
);
1677 /* Call an observer, notifying them of the xfer progress? */
1689 target_read_until_error (struct target_ops
*ops
,
1690 enum target_object object
,
1691 const char *annex
, gdb_byte
*buf
,
1692 ULONGEST offset
, LONGEST len
)
1695 while (xfered
< len
)
1697 LONGEST xfer
= target_read_partial (ops
, object
, annex
,
1698 (gdb_byte
*) buf
+ xfered
,
1699 offset
+ xfered
, len
- xfered
);
1700 /* Call an observer, notifying them of the xfer progress? */
1705 /* We've got an error. Try to read in smaller blocks. */
1706 ULONGEST start
= offset
+ xfered
;
1707 ULONGEST remaining
= len
- xfered
;
1710 /* If an attempt was made to read a random memory address,
1711 it's likely that the very first byte is not accessible.
1712 Try reading the first byte, to avoid doing log N tries
1714 xfer
= target_read_partial (ops
, object
, annex
,
1715 (gdb_byte
*) buf
+ xfered
, start
, 1);
1724 xfer
= target_read_partial (ops
, object
, annex
,
1725 (gdb_byte
*) buf
+ xfered
,
1735 /* We have successfully read the first half. So, the
1736 error must be in the second half. Adjust start and
1737 remaining to point at the second half. */
1754 /* An alternative to target_write with progress callbacks. */
1757 target_write_with_progress (struct target_ops
*ops
,
1758 enum target_object object
,
1759 const char *annex
, const gdb_byte
*buf
,
1760 ULONGEST offset
, LONGEST len
,
1761 void (*progress
) (ULONGEST
, void *), void *baton
)
1765 /* Give the progress callback a chance to set up. */
1767 (*progress
) (0, baton
);
1769 while (xfered
< len
)
1771 LONGEST xfer
= target_write_partial (ops
, object
, annex
,
1772 (gdb_byte
*) buf
+ xfered
,
1773 offset
+ xfered
, len
- xfered
);
1781 (*progress
) (xfer
, baton
);
1790 target_write (struct target_ops
*ops
,
1791 enum target_object object
,
1792 const char *annex
, const gdb_byte
*buf
,
1793 ULONGEST offset
, LONGEST len
)
1795 return target_write_with_progress (ops
, object
, annex
, buf
, offset
, len
,
1799 /* Read OBJECT/ANNEX using OPS. Store the result in *BUF_P and return
1800 the size of the transferred data. PADDING additional bytes are
1801 available in *BUF_P. This is a helper function for
1802 target_read_alloc; see the declaration of that function for more
1806 target_read_alloc_1 (struct target_ops
*ops
, enum target_object object
,
1807 const char *annex
, gdb_byte
**buf_p
, int padding
)
1809 size_t buf_alloc
, buf_pos
;
1813 /* This function does not have a length parameter; it reads the
1814 entire OBJECT). Also, it doesn't support objects fetched partly
1815 from one target and partly from another (in a different stratum,
1816 e.g. a core file and an executable). Both reasons make it
1817 unsuitable for reading memory. */
1818 gdb_assert (object
!= TARGET_OBJECT_MEMORY
);
1820 /* Start by reading up to 4K at a time. The target will throttle
1821 this number down if necessary. */
1823 buf
= xmalloc (buf_alloc
);
1827 n
= target_read_partial (ops
, object
, annex
, &buf
[buf_pos
],
1828 buf_pos
, buf_alloc
- buf_pos
- padding
);
1831 /* An error occurred. */
1837 /* Read all there was. */
1847 /* If the buffer is filling up, expand it. */
1848 if (buf_alloc
< buf_pos
* 2)
1851 buf
= xrealloc (buf
, buf_alloc
);
1858 /* Read OBJECT/ANNEX using OPS. Store the result in *BUF_P and return
1859 the size of the transferred data. See the declaration in "target.h"
1860 function for more information about the return value. */
1863 target_read_alloc (struct target_ops
*ops
, enum target_object object
,
1864 const char *annex
, gdb_byte
**buf_p
)
1866 return target_read_alloc_1 (ops
, object
, annex
, buf_p
, 0);
1869 /* Read OBJECT/ANNEX using OPS. The result is NUL-terminated and
1870 returned as a string, allocated using xmalloc. If an error occurs
1871 or the transfer is unsupported, NULL is returned. Empty objects
1872 are returned as allocated but empty strings. A warning is issued
1873 if the result contains any embedded NUL bytes. */
1876 target_read_stralloc (struct target_ops
*ops
, enum target_object object
,
1880 LONGEST transferred
;
1882 transferred
= target_read_alloc_1 (ops
, object
, annex
, &buffer
, 1);
1884 if (transferred
< 0)
1887 if (transferred
== 0)
1888 return xstrdup ("");
1890 buffer
[transferred
] = 0;
1891 if (strlen (buffer
) < transferred
)
1892 warning (_("target object %d, annex %s, "
1893 "contained unexpected null characters"),
1894 (int) object
, annex
? annex
: "(none)");
1896 return (char *) buffer
;
1899 /* Memory transfer methods. */
1902 get_target_memory (struct target_ops
*ops
, CORE_ADDR addr
, gdb_byte
*buf
,
1905 /* This method is used to read from an alternate, non-current
1906 target. This read must bypass the overlay support (as symbols
1907 don't match this target), and GDB's internal cache (wrong cache
1908 for this target). */
1909 if (target_read (ops
, TARGET_OBJECT_RAW_MEMORY
, NULL
, buf
, addr
, len
)
1911 memory_error (EIO
, addr
);
1915 get_target_memory_unsigned (struct target_ops
*ops
,
1916 CORE_ADDR addr
, int len
, enum bfd_endian byte_order
)
1918 gdb_byte buf
[sizeof (ULONGEST
)];
1920 gdb_assert (len
<= sizeof (buf
));
1921 get_target_memory (ops
, addr
, buf
, len
);
1922 return extract_unsigned_integer (buf
, len
, byte_order
);
1926 target_info (char *args
, int from_tty
)
1928 struct target_ops
*t
;
1929 int has_all_mem
= 0;
1931 if (symfile_objfile
!= NULL
)
1932 printf_unfiltered (_("Symbols from \"%s\".\n"), symfile_objfile
->name
);
1934 for (t
= target_stack
; t
!= NULL
; t
= t
->beneath
)
1936 if (!(*t
->to_has_memory
) (t
))
1939 if ((int) (t
->to_stratum
) <= (int) dummy_stratum
)
1942 printf_unfiltered (_("\tWhile running this, GDB does not access memory from...\n"));
1943 printf_unfiltered ("%s:\n", t
->to_longname
);
1944 (t
->to_files_info
) (t
);
1945 has_all_mem
= (*t
->to_has_all_memory
) (t
);
1949 /* This function is called before any new inferior is created, e.g.
1950 by running a program, attaching, or connecting to a target.
1951 It cleans up any state from previous invocations which might
1952 change between runs. This is a subset of what target_preopen
1953 resets (things which might change between targets). */
1956 target_pre_inferior (int from_tty
)
1958 /* Clear out solib state. Otherwise the solib state of the previous
1959 inferior might have survived and is entirely wrong for the new
1960 target. This has been observed on GNU/Linux using glibc 2.3. How
1972 Cannot access memory at address 0xdeadbeef
1975 /* In some OSs, the shared library list is the same/global/shared
1976 across inferiors. If code is shared between processes, so are
1977 memory regions and features. */
1978 if (!gdbarch_has_global_solist (target_gdbarch
))
1980 no_shared_libraries (NULL
, from_tty
);
1982 invalidate_target_mem_regions ();
1984 target_clear_description ();
1988 /* Callback for iterate_over_inferiors. Gets rid of the given
1992 dispose_inferior (struct inferior
*inf
, void *args
)
1994 struct thread_info
*thread
;
1996 thread
= any_thread_of_process (inf
->pid
);
1999 switch_to_thread (thread
->ptid
);
2001 /* Core inferiors actually should be detached, not killed. */
2002 if (target_has_execution
)
2005 target_detach (NULL
, 0);
2011 /* This is to be called by the open routine before it does
2015 target_preopen (int from_tty
)
2019 if (have_inferiors ())
2022 || !have_live_inferiors ()
2023 || query (_("A program is being debugged already. Kill it? ")))
2024 iterate_over_inferiors (dispose_inferior
, NULL
);
2026 error (_("Program not killed."));
2029 /* Calling target_kill may remove the target from the stack. But if
2030 it doesn't (which seems like a win for UDI), remove it now. */
2031 /* Leave the exec target, though. The user may be switching from a
2032 live process to a core of the same program. */
2033 pop_all_targets_above (file_stratum
, 0);
2035 target_pre_inferior (from_tty
);
2038 /* Detach a target after doing deferred register stores. */
2041 target_detach (char *args
, int from_tty
)
2043 struct target_ops
* t
;
2045 if (gdbarch_has_global_breakpoints (target_gdbarch
))
2046 /* Don't remove global breakpoints here. They're removed on
2047 disconnection from the target. */
2050 /* If we're in breakpoints-always-inserted mode, have to remove
2051 them before detaching. */
2052 remove_breakpoints_pid (PIDGET (inferior_ptid
));
2054 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
2056 if (t
->to_detach
!= NULL
)
2058 t
->to_detach (t
, args
, from_tty
);
2060 fprintf_unfiltered (gdb_stdlog
, "target_detach (%s, %d)\n",
2066 internal_error (__FILE__
, __LINE__
, "could not find a target to detach");
2070 target_disconnect (char *args
, int from_tty
)
2072 struct target_ops
*t
;
2074 /* If we're in breakpoints-always-inserted mode or if breakpoints
2075 are global across processes, we have to remove them before
2077 remove_breakpoints ();
2079 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
2080 if (t
->to_disconnect
!= NULL
)
2083 fprintf_unfiltered (gdb_stdlog
, "target_disconnect (%s, %d)\n",
2085 t
->to_disconnect (t
, args
, from_tty
);
2093 target_wait (ptid_t ptid
, struct target_waitstatus
*status
, int options
)
2095 struct target_ops
*t
;
2097 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
2099 if (t
->to_wait
!= NULL
)
2101 ptid_t retval
= (*t
->to_wait
) (t
, ptid
, status
, options
);
2105 char *status_string
;
2107 status_string
= target_waitstatus_to_string (status
);
2108 fprintf_unfiltered (gdb_stdlog
,
2109 "target_wait (%d, status) = %d, %s\n",
2110 PIDGET (ptid
), PIDGET (retval
),
2112 xfree (status_string
);
2123 target_pid_to_str (ptid_t ptid
)
2125 struct target_ops
*t
;
2127 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
2129 if (t
->to_pid_to_str
!= NULL
)
2130 return (*t
->to_pid_to_str
) (t
, ptid
);
2133 return normal_pid_to_str (ptid
);
2137 target_resume (ptid_t ptid
, int step
, enum target_signal signal
)
2139 struct target_ops
*t
;
2141 target_dcache_invalidate ();
2143 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
2145 if (t
->to_resume
!= NULL
)
2147 t
->to_resume (t
, ptid
, step
, signal
);
2149 fprintf_unfiltered (gdb_stdlog
, "target_resume (%d, %s, %s)\n",
2151 step
? "step" : "continue",
2152 target_signal_to_name (signal
));
2154 set_executing (ptid
, 1);
2155 set_running (ptid
, 1);
2156 clear_inline_frame_state (ptid
);
2163 /* Look through the list of possible targets for a target that can
2167 target_follow_fork (int follow_child
)
2169 struct target_ops
*t
;
2171 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
2173 if (t
->to_follow_fork
!= NULL
)
2175 int retval
= t
->to_follow_fork (t
, follow_child
);
2177 fprintf_unfiltered (gdb_stdlog
, "target_follow_fork (%d) = %d\n",
2178 follow_child
, retval
);
2183 /* Some target returned a fork event, but did not know how to follow it. */
2184 internal_error (__FILE__
, __LINE__
,
2185 "could not find a target to follow fork");
2189 target_mourn_inferior (void)
2191 struct target_ops
*t
;
2192 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
2194 if (t
->to_mourn_inferior
!= NULL
)
2196 t
->to_mourn_inferior (t
);
2198 fprintf_unfiltered (gdb_stdlog
, "target_mourn_inferior ()\n");
2200 /* We no longer need to keep handles on any of the object files.
2201 Make sure to release them to avoid unnecessarily locking any
2202 of them while we're not actually debugging. */
2203 bfd_cache_close_all ();
2209 internal_error (__FILE__
, __LINE__
,
2210 "could not find a target to follow mourn inferiour");
2213 /* Look for a target which can describe architectural features, starting
2214 from TARGET. If we find one, return its description. */
2216 const struct target_desc
*
2217 target_read_description (struct target_ops
*target
)
2219 struct target_ops
*t
;
2221 for (t
= target
; t
!= NULL
; t
= t
->beneath
)
2222 if (t
->to_read_description
!= NULL
)
2224 const struct target_desc
*tdesc
;
2226 tdesc
= t
->to_read_description (t
);
2234 /* The default implementation of to_search_memory.
2235 This implements a basic search of memory, reading target memory and
2236 performing the search here (as opposed to performing the search in on the
2237 target side with, for example, gdbserver). */
2240 simple_search_memory (struct target_ops
*ops
,
2241 CORE_ADDR start_addr
, ULONGEST search_space_len
,
2242 const gdb_byte
*pattern
, ULONGEST pattern_len
,
2243 CORE_ADDR
*found_addrp
)
2245 /* NOTE: also defined in find.c testcase. */
2246 #define SEARCH_CHUNK_SIZE 16000
2247 const unsigned chunk_size
= SEARCH_CHUNK_SIZE
;
2248 /* Buffer to hold memory contents for searching. */
2249 gdb_byte
*search_buf
;
2250 unsigned search_buf_size
;
2251 struct cleanup
*old_cleanups
;
2253 search_buf_size
= chunk_size
+ pattern_len
- 1;
2255 /* No point in trying to allocate a buffer larger than the search space. */
2256 if (search_space_len
< search_buf_size
)
2257 search_buf_size
= search_space_len
;
2259 search_buf
= malloc (search_buf_size
);
2260 if (search_buf
== NULL
)
2261 error (_("Unable to allocate memory to perform the search."));
2262 old_cleanups
= make_cleanup (free_current_contents
, &search_buf
);
2264 /* Prime the search buffer. */
2266 if (target_read (ops
, TARGET_OBJECT_MEMORY
, NULL
,
2267 search_buf
, start_addr
, search_buf_size
) != search_buf_size
)
2269 warning (_("Unable to access target memory at %s, halting search."),
2270 hex_string (start_addr
));
2271 do_cleanups (old_cleanups
);
2275 /* Perform the search.
2277 The loop is kept simple by allocating [N + pattern-length - 1] bytes.
2278 When we've scanned N bytes we copy the trailing bytes to the start and
2279 read in another N bytes. */
2281 while (search_space_len
>= pattern_len
)
2283 gdb_byte
*found_ptr
;
2284 unsigned nr_search_bytes
= min (search_space_len
, search_buf_size
);
2286 found_ptr
= memmem (search_buf
, nr_search_bytes
,
2287 pattern
, pattern_len
);
2289 if (found_ptr
!= NULL
)
2291 CORE_ADDR found_addr
= start_addr
+ (found_ptr
- search_buf
);
2292 *found_addrp
= found_addr
;
2293 do_cleanups (old_cleanups
);
2297 /* Not found in this chunk, skip to next chunk. */
2299 /* Don't let search_space_len wrap here, it's unsigned. */
2300 if (search_space_len
>= chunk_size
)
2301 search_space_len
-= chunk_size
;
2303 search_space_len
= 0;
2305 if (search_space_len
>= pattern_len
)
2307 unsigned keep_len
= search_buf_size
- chunk_size
;
2308 CORE_ADDR read_addr
= start_addr
+ keep_len
;
2311 /* Copy the trailing part of the previous iteration to the front
2312 of the buffer for the next iteration. */
2313 gdb_assert (keep_len
== pattern_len
- 1);
2314 memcpy (search_buf
, search_buf
+ chunk_size
, keep_len
);
2316 nr_to_read
= min (search_space_len
- keep_len
, chunk_size
);
2318 if (target_read (ops
, TARGET_OBJECT_MEMORY
, NULL
,
2319 search_buf
+ keep_len
, read_addr
,
2320 nr_to_read
) != nr_to_read
)
2322 warning (_("Unable to access target memory at %s, halting search."),
2323 hex_string (read_addr
));
2324 do_cleanups (old_cleanups
);
2328 start_addr
+= chunk_size
;
2334 do_cleanups (old_cleanups
);
2338 /* Search SEARCH_SPACE_LEN bytes beginning at START_ADDR for the
2339 sequence of bytes in PATTERN with length PATTERN_LEN.
2341 The result is 1 if found, 0 if not found, and -1 if there was an error
2342 requiring halting of the search (e.g. memory read error).
2343 If the pattern is found the address is recorded in FOUND_ADDRP. */
2346 target_search_memory (CORE_ADDR start_addr
, ULONGEST search_space_len
,
2347 const gdb_byte
*pattern
, ULONGEST pattern_len
,
2348 CORE_ADDR
*found_addrp
)
2350 struct target_ops
*t
;
2353 /* We don't use INHERIT to set current_target.to_search_memory,
2354 so we have to scan the target stack and handle targetdebug
2358 fprintf_unfiltered (gdb_stdlog
, "target_search_memory (%s, ...)\n",
2359 hex_string (start_addr
));
2361 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
2362 if (t
->to_search_memory
!= NULL
)
2367 found
= t
->to_search_memory (t
, start_addr
, search_space_len
,
2368 pattern
, pattern_len
, found_addrp
);
2372 /* If a special version of to_search_memory isn't available, use the
2374 found
= simple_search_memory (current_target
.beneath
,
2375 start_addr
, search_space_len
,
2376 pattern
, pattern_len
, found_addrp
);
2380 fprintf_unfiltered (gdb_stdlog
, " = %d\n", found
);
2385 /* Look through the currently pushed targets. If none of them will
2386 be able to restart the currently running process, issue an error
2390 target_require_runnable (void)
2392 struct target_ops
*t
;
2394 for (t
= target_stack
; t
!= NULL
; t
= t
->beneath
)
2396 /* If this target knows how to create a new program, then
2397 assume we will still be able to after killing the current
2398 one. Either killing and mourning will not pop T, or else
2399 find_default_run_target will find it again. */
2400 if (t
->to_create_inferior
!= NULL
)
2403 /* Do not worry about thread_stratum targets that can not
2404 create inferiors. Assume they will be pushed again if
2405 necessary, and continue to the process_stratum. */
2406 if (t
->to_stratum
== thread_stratum
2407 || t
->to_stratum
== arch_stratum
)
2411 The \"%s\" target does not support \"run\". Try \"help target\" or \"continue\"."),
2415 /* This function is only called if the target is running. In that
2416 case there should have been a process_stratum target and it
2417 should either know how to create inferiors, or not... */
2418 internal_error (__FILE__
, __LINE__
, "No targets found");
2421 /* Look through the list of possible targets for a target that can
2422 execute a run or attach command without any other data. This is
2423 used to locate the default process stratum.
2425 If DO_MESG is not NULL, the result is always valid (error() is
2426 called for errors); else, return NULL on error. */
2428 static struct target_ops
*
2429 find_default_run_target (char *do_mesg
)
2431 struct target_ops
**t
;
2432 struct target_ops
*runable
= NULL
;
2437 for (t
= target_structs
; t
< target_structs
+ target_struct_size
;
2440 if ((*t
)->to_can_run
&& target_can_run (*t
))
2450 error (_("Don't know how to %s. Try \"help target\"."), do_mesg
);
2459 find_default_attach (struct target_ops
*ops
, char *args
, int from_tty
)
2461 struct target_ops
*t
;
2463 t
= find_default_run_target ("attach");
2464 (t
->to_attach
) (t
, args
, from_tty
);
2469 find_default_create_inferior (struct target_ops
*ops
,
2470 char *exec_file
, char *allargs
, char **env
,
2473 struct target_ops
*t
;
2475 t
= find_default_run_target ("run");
2476 (t
->to_create_inferior
) (t
, exec_file
, allargs
, env
, from_tty
);
2481 find_default_can_async_p (void)
2483 struct target_ops
*t
;
2485 /* This may be called before the target is pushed on the stack;
2486 look for the default process stratum. If there's none, gdb isn't
2487 configured with a native debugger, and target remote isn't
2489 t
= find_default_run_target (NULL
);
2490 if (t
&& t
->to_can_async_p
)
2491 return (t
->to_can_async_p
) ();
2496 find_default_is_async_p (void)
2498 struct target_ops
*t
;
2500 /* This may be called before the target is pushed on the stack;
2501 look for the default process stratum. If there's none, gdb isn't
2502 configured with a native debugger, and target remote isn't
2504 t
= find_default_run_target (NULL
);
2505 if (t
&& t
->to_is_async_p
)
2506 return (t
->to_is_async_p
) ();
2511 find_default_supports_non_stop (void)
2513 struct target_ops
*t
;
2515 t
= find_default_run_target (NULL
);
2516 if (t
&& t
->to_supports_non_stop
)
2517 return (t
->to_supports_non_stop
) ();
2522 target_supports_non_stop (void)
2524 struct target_ops
*t
;
2525 for (t
= ¤t_target
; t
!= NULL
; t
= t
->beneath
)
2526 if (t
->to_supports_non_stop
)
2527 return t
->to_supports_non_stop ();
2534 target_get_osdata (const char *type
)
2537 struct target_ops
*t
;
2539 /* If we're already connected to something that can get us OS
2540 related data, use it. Otherwise, try using the native
2542 if (current_target
.to_stratum
>= process_stratum
)
2543 t
= current_target
.beneath
;
2545 t
= find_default_run_target ("get OS data");
2550 return target_read_stralloc (t
, TARGET_OBJECT_OSDATA
, type
);
2553 /* Determine the current address space of thread PTID. */
2555 struct address_space
*
2556 target_thread_address_space (ptid_t ptid
)
2558 struct address_space
*aspace
;
2559 struct inferior
*inf
;
2560 struct target_ops
*t
;
2562 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
2564 if (t
->to_thread_address_space
!= NULL
)
2566 aspace
= t
->to_thread_address_space (t
, ptid
);
2567 gdb_assert (aspace
);
2570 fprintf_unfiltered (gdb_stdlog
,
2571 "target_thread_address_space (%s) = %d\n",
2572 target_pid_to_str (ptid
),
2573 address_space_num (aspace
));
2578 /* Fall-back to the "main" address space of the inferior. */
2579 inf
= find_inferior_pid (ptid_get_pid (ptid
));
2581 if (inf
== NULL
|| inf
->aspace
== NULL
)
2582 internal_error (__FILE__
, __LINE__
, "\
2583 Can't determine the current address space of thread %s\n",
2584 target_pid_to_str (ptid
));
2590 default_region_ok_for_hw_watchpoint (CORE_ADDR addr
, int len
)
2592 return (len
<= gdbarch_ptr_bit (target_gdbarch
) / TARGET_CHAR_BIT
);
2596 default_watchpoint_addr_within_range (struct target_ops
*target
,
2598 CORE_ADDR start
, int length
)
2600 return addr
>= start
&& addr
< start
+ length
;
2603 static struct gdbarch
*
2604 default_thread_architecture (struct target_ops
*ops
, ptid_t ptid
)
2606 return target_gdbarch
;
2622 return_minus_one (void)
2627 /* Find a single runnable target in the stack and return it. If for
2628 some reason there is more than one, return NULL. */
2631 find_run_target (void)
2633 struct target_ops
**t
;
2634 struct target_ops
*runable
= NULL
;
2639 for (t
= target_structs
; t
< target_structs
+ target_struct_size
; ++t
)
2641 if ((*t
)->to_can_run
&& target_can_run (*t
))
2648 return (count
== 1 ? runable
: NULL
);
2651 /* Find a single core_stratum target in the list of targets and return it.
2652 If for some reason there is more than one, return NULL. */
2655 find_core_target (void)
2657 struct target_ops
**t
;
2658 struct target_ops
*runable
= NULL
;
2663 for (t
= target_structs
; t
< target_structs
+ target_struct_size
;
2666 if ((*t
)->to_stratum
== core_stratum
)
2673 return (count
== 1 ? runable
: NULL
);
2677 * Find the next target down the stack from the specified target.
2681 find_target_beneath (struct target_ops
*t
)
2687 /* The inferior process has died. Long live the inferior! */
2690 generic_mourn_inferior (void)
2694 ptid
= inferior_ptid
;
2695 inferior_ptid
= null_ptid
;
2697 if (!ptid_equal (ptid
, null_ptid
))
2699 int pid
= ptid_get_pid (ptid
);
2700 exit_inferior (pid
);
2703 breakpoint_init_inferior (inf_exited
);
2704 registers_changed ();
2706 reopen_exec_file ();
2707 reinit_frame_cache ();
2709 if (deprecated_detach_hook
)
2710 deprecated_detach_hook ();
2713 /* Helper function for child_wait and the derivatives of child_wait.
2714 HOSTSTATUS is the waitstatus from wait() or the equivalent; store our
2715 translation of that in OURSTATUS. */
2717 store_waitstatus (struct target_waitstatus
*ourstatus
, int hoststatus
)
2719 if (WIFEXITED (hoststatus
))
2721 ourstatus
->kind
= TARGET_WAITKIND_EXITED
;
2722 ourstatus
->value
.integer
= WEXITSTATUS (hoststatus
);
2724 else if (!WIFSTOPPED (hoststatus
))
2726 ourstatus
->kind
= TARGET_WAITKIND_SIGNALLED
;
2727 ourstatus
->value
.sig
= target_signal_from_host (WTERMSIG (hoststatus
));
2731 ourstatus
->kind
= TARGET_WAITKIND_STOPPED
;
2732 ourstatus
->value
.sig
= target_signal_from_host (WSTOPSIG (hoststatus
));
2736 /* Convert a normal process ID to a string. Returns the string in a
2740 normal_pid_to_str (ptid_t ptid
)
2742 static char buf
[32];
2744 xsnprintf (buf
, sizeof buf
, "process %d", ptid_get_pid (ptid
));
2749 dummy_pid_to_str (struct target_ops
*ops
, ptid_t ptid
)
2751 return normal_pid_to_str (ptid
);
2754 /* Error-catcher for target_find_memory_regions. */
2756 dummy_find_memory_regions (int (*ignore1
) (), void *ignore2
)
2758 error (_("Command not implemented for this target."));
2762 /* Error-catcher for target_make_corefile_notes. */
2764 dummy_make_corefile_notes (bfd
*ignore1
, int *ignore2
)
2766 error (_("Command not implemented for this target."));
2770 /* Set up the handful of non-empty slots needed by the dummy target
2774 init_dummy_target (void)
2776 dummy_target
.to_shortname
= "None";
2777 dummy_target
.to_longname
= "None";
2778 dummy_target
.to_doc
= "";
2779 dummy_target
.to_attach
= find_default_attach
;
2780 dummy_target
.to_detach
=
2781 (void (*)(struct target_ops
*, char *, int))target_ignore
;
2782 dummy_target
.to_create_inferior
= find_default_create_inferior
;
2783 dummy_target
.to_can_async_p
= find_default_can_async_p
;
2784 dummy_target
.to_is_async_p
= find_default_is_async_p
;
2785 dummy_target
.to_supports_non_stop
= find_default_supports_non_stop
;
2786 dummy_target
.to_pid_to_str
= dummy_pid_to_str
;
2787 dummy_target
.to_stratum
= dummy_stratum
;
2788 dummy_target
.to_find_memory_regions
= dummy_find_memory_regions
;
2789 dummy_target
.to_make_corefile_notes
= dummy_make_corefile_notes
;
2790 dummy_target
.to_xfer_partial
= default_xfer_partial
;
2791 dummy_target
.to_has_all_memory
= (int (*) (struct target_ops
*)) return_zero
;
2792 dummy_target
.to_has_memory
= (int (*) (struct target_ops
*)) return_zero
;
2793 dummy_target
.to_has_stack
= (int (*) (struct target_ops
*)) return_zero
;
2794 dummy_target
.to_has_registers
= (int (*) (struct target_ops
*)) return_zero
;
2795 dummy_target
.to_has_execution
= (int (*) (struct target_ops
*)) return_zero
;
2796 dummy_target
.to_magic
= OPS_MAGIC
;
2800 debug_to_open (char *args
, int from_tty
)
2802 debug_target
.to_open (args
, from_tty
);
2804 fprintf_unfiltered (gdb_stdlog
, "target_open (%s, %d)\n", args
, from_tty
);
2808 target_close (struct target_ops
*targ
, int quitting
)
2810 if (targ
->to_xclose
!= NULL
)
2811 targ
->to_xclose (targ
, quitting
);
2812 else if (targ
->to_close
!= NULL
)
2813 targ
->to_close (quitting
);
2816 fprintf_unfiltered (gdb_stdlog
, "target_close (%d)\n", quitting
);
2820 target_attach (char *args
, int from_tty
)
2822 struct target_ops
*t
;
2823 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
2825 if (t
->to_attach
!= NULL
)
2827 t
->to_attach (t
, args
, from_tty
);
2829 fprintf_unfiltered (gdb_stdlog
, "target_attach (%s, %d)\n",
2835 internal_error (__FILE__
, __LINE__
,
2836 "could not find a target to attach");
2840 target_thread_alive (ptid_t ptid
)
2842 struct target_ops
*t
;
2843 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
2845 if (t
->to_thread_alive
!= NULL
)
2849 retval
= t
->to_thread_alive (t
, ptid
);
2851 fprintf_unfiltered (gdb_stdlog
, "target_thread_alive (%d) = %d\n",
2852 PIDGET (ptid
), retval
);
2862 target_find_new_threads (void)
2864 struct target_ops
*t
;
2865 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
2867 if (t
->to_find_new_threads
!= NULL
)
2869 t
->to_find_new_threads (t
);
2871 fprintf_unfiltered (gdb_stdlog
, "target_find_new_threads ()\n");
2879 debug_to_post_attach (int pid
)
2881 debug_target
.to_post_attach (pid
);
2883 fprintf_unfiltered (gdb_stdlog
, "target_post_attach (%d)\n", pid
);
2886 /* Return a pretty printed form of target_waitstatus.
2887 Space for the result is malloc'd, caller must free. */
2890 target_waitstatus_to_string (const struct target_waitstatus
*ws
)
2892 const char *kind_str
= "status->kind = ";
2896 case TARGET_WAITKIND_EXITED
:
2897 return xstrprintf ("%sexited, status = %d",
2898 kind_str
, ws
->value
.integer
);
2899 case TARGET_WAITKIND_STOPPED
:
2900 return xstrprintf ("%sstopped, signal = %s",
2901 kind_str
, target_signal_to_name (ws
->value
.sig
));
2902 case TARGET_WAITKIND_SIGNALLED
:
2903 return xstrprintf ("%ssignalled, signal = %s",
2904 kind_str
, target_signal_to_name (ws
->value
.sig
));
2905 case TARGET_WAITKIND_LOADED
:
2906 return xstrprintf ("%sloaded", kind_str
);
2907 case TARGET_WAITKIND_FORKED
:
2908 return xstrprintf ("%sforked", kind_str
);
2909 case TARGET_WAITKIND_VFORKED
:
2910 return xstrprintf ("%svforked", kind_str
);
2911 case TARGET_WAITKIND_EXECD
:
2912 return xstrprintf ("%sexecd", kind_str
);
2913 case TARGET_WAITKIND_SYSCALL_ENTRY
:
2914 return xstrprintf ("%sentered syscall", kind_str
);
2915 case TARGET_WAITKIND_SYSCALL_RETURN
:
2916 return xstrprintf ("%sexited syscall", kind_str
);
2917 case TARGET_WAITKIND_SPURIOUS
:
2918 return xstrprintf ("%sspurious", kind_str
);
2919 case TARGET_WAITKIND_IGNORE
:
2920 return xstrprintf ("%signore", kind_str
);
2921 case TARGET_WAITKIND_NO_HISTORY
:
2922 return xstrprintf ("%sno-history", kind_str
);
2924 return xstrprintf ("%sunknown???", kind_str
);
2929 debug_print_register (const char * func
,
2930 struct regcache
*regcache
, int regno
)
2932 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
2933 fprintf_unfiltered (gdb_stdlog
, "%s ", func
);
2934 if (regno
>= 0 && regno
< gdbarch_num_regs (gdbarch
)
2935 && gdbarch_register_name (gdbarch
, regno
) != NULL
2936 && gdbarch_register_name (gdbarch
, regno
)[0] != '\0')
2937 fprintf_unfiltered (gdb_stdlog
, "(%s)",
2938 gdbarch_register_name (gdbarch
, regno
));
2940 fprintf_unfiltered (gdb_stdlog
, "(%d)", regno
);
2941 if (regno
>= 0 && regno
< gdbarch_num_regs (gdbarch
))
2943 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
2944 int i
, size
= register_size (gdbarch
, regno
);
2945 unsigned char buf
[MAX_REGISTER_SIZE
];
2946 regcache_raw_collect (regcache
, regno
, buf
);
2947 fprintf_unfiltered (gdb_stdlog
, " = ");
2948 for (i
= 0; i
< size
; i
++)
2950 fprintf_unfiltered (gdb_stdlog
, "%02x", buf
[i
]);
2952 if (size
<= sizeof (LONGEST
))
2954 ULONGEST val
= extract_unsigned_integer (buf
, size
, byte_order
);
2955 fprintf_unfiltered (gdb_stdlog
, " %s %s",
2956 core_addr_to_string_nz (val
), plongest (val
));
2959 fprintf_unfiltered (gdb_stdlog
, "\n");
2963 target_fetch_registers (struct regcache
*regcache
, int regno
)
2965 struct target_ops
*t
;
2966 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
2968 if (t
->to_fetch_registers
!= NULL
)
2970 t
->to_fetch_registers (t
, regcache
, regno
);
2972 debug_print_register ("target_fetch_registers", regcache
, regno
);
2979 target_store_registers (struct regcache
*regcache
, int regno
)
2982 struct target_ops
*t
;
2983 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
2985 if (t
->to_store_registers
!= NULL
)
2987 t
->to_store_registers (t
, regcache
, regno
);
2990 debug_print_register ("target_store_registers", regcache
, regno
);
3000 debug_to_prepare_to_store (struct regcache
*regcache
)
3002 debug_target
.to_prepare_to_store (regcache
);
3004 fprintf_unfiltered (gdb_stdlog
, "target_prepare_to_store ()\n");
3008 deprecated_debug_xfer_memory (CORE_ADDR memaddr
, bfd_byte
*myaddr
, int len
,
3009 int write
, struct mem_attrib
*attrib
,
3010 struct target_ops
*target
)
3014 retval
= debug_target
.deprecated_xfer_memory (memaddr
, myaddr
, len
, write
,
3017 fprintf_unfiltered (gdb_stdlog
,
3018 "target_xfer_memory (%s, xxx, %d, %s, xxx) = %d",
3019 paddress (target_gdbarch
, memaddr
), len
,
3020 write
? "write" : "read", retval
);
3026 fputs_unfiltered (", bytes =", gdb_stdlog
);
3027 for (i
= 0; i
< retval
; i
++)
3029 if ((((intptr_t) &(myaddr
[i
])) & 0xf) == 0)
3031 if (targetdebug
< 2 && i
> 0)
3033 fprintf_unfiltered (gdb_stdlog
, " ...");
3036 fprintf_unfiltered (gdb_stdlog
, "\n");
3039 fprintf_unfiltered (gdb_stdlog
, " %02x", myaddr
[i
] & 0xff);
3043 fputc_unfiltered ('\n', gdb_stdlog
);
3049 debug_to_files_info (struct target_ops
*target
)
3051 debug_target
.to_files_info (target
);
3053 fprintf_unfiltered (gdb_stdlog
, "target_files_info (xxx)\n");
3057 debug_to_insert_breakpoint (struct gdbarch
*gdbarch
,
3058 struct bp_target_info
*bp_tgt
)
3062 retval
= debug_target
.to_insert_breakpoint (gdbarch
, bp_tgt
);
3064 fprintf_unfiltered (gdb_stdlog
,
3065 "target_insert_breakpoint (0x%lx, xxx) = %ld\n",
3066 (unsigned long) bp_tgt
->placed_address
,
3067 (unsigned long) retval
);
3072 debug_to_remove_breakpoint (struct gdbarch
*gdbarch
,
3073 struct bp_target_info
*bp_tgt
)
3077 retval
= debug_target
.to_remove_breakpoint (gdbarch
, bp_tgt
);
3079 fprintf_unfiltered (gdb_stdlog
,
3080 "target_remove_breakpoint (0x%lx, xxx) = %ld\n",
3081 (unsigned long) bp_tgt
->placed_address
,
3082 (unsigned long) retval
);
3087 debug_to_can_use_hw_breakpoint (int type
, int cnt
, int from_tty
)
3091 retval
= debug_target
.to_can_use_hw_breakpoint (type
, cnt
, from_tty
);
3093 fprintf_unfiltered (gdb_stdlog
,
3094 "target_can_use_hw_breakpoint (%ld, %ld, %ld) = %ld\n",
3095 (unsigned long) type
,
3096 (unsigned long) cnt
,
3097 (unsigned long) from_tty
,
3098 (unsigned long) retval
);
3103 debug_to_region_ok_for_hw_watchpoint (CORE_ADDR addr
, int len
)
3107 retval
= debug_target
.to_region_ok_for_hw_watchpoint (addr
, len
);
3109 fprintf_unfiltered (gdb_stdlog
,
3110 "target_region_ok_for_hw_watchpoint (%ld, %ld) = 0x%lx\n",
3111 (unsigned long) addr
,
3112 (unsigned long) len
,
3113 (unsigned long) retval
);
3118 debug_to_stopped_by_watchpoint (void)
3122 retval
= debug_target
.to_stopped_by_watchpoint ();
3124 fprintf_unfiltered (gdb_stdlog
,
3125 "target_stopped_by_watchpoint () = %ld\n",
3126 (unsigned long) retval
);
3131 debug_to_stopped_data_address (struct target_ops
*target
, CORE_ADDR
*addr
)
3135 retval
= debug_target
.to_stopped_data_address (target
, addr
);
3137 fprintf_unfiltered (gdb_stdlog
,
3138 "target_stopped_data_address ([0x%lx]) = %ld\n",
3139 (unsigned long)*addr
,
3140 (unsigned long)retval
);
3145 debug_to_watchpoint_addr_within_range (struct target_ops
*target
,
3147 CORE_ADDR start
, int length
)
3151 retval
= debug_target
.to_watchpoint_addr_within_range (target
, addr
,
3154 fprintf_filtered (gdb_stdlog
,
3155 "target_watchpoint_addr_within_range (0x%lx, 0x%lx, %d) = %d\n",
3156 (unsigned long) addr
, (unsigned long) start
, length
,
3162 debug_to_insert_hw_breakpoint (struct gdbarch
*gdbarch
,
3163 struct bp_target_info
*bp_tgt
)
3167 retval
= debug_target
.to_insert_hw_breakpoint (gdbarch
, bp_tgt
);
3169 fprintf_unfiltered (gdb_stdlog
,
3170 "target_insert_hw_breakpoint (0x%lx, xxx) = %ld\n",
3171 (unsigned long) bp_tgt
->placed_address
,
3172 (unsigned long) retval
);
3177 debug_to_remove_hw_breakpoint (struct gdbarch
*gdbarch
,
3178 struct bp_target_info
*bp_tgt
)
3182 retval
= debug_target
.to_remove_hw_breakpoint (gdbarch
, bp_tgt
);
3184 fprintf_unfiltered (gdb_stdlog
,
3185 "target_remove_hw_breakpoint (0x%lx, xxx) = %ld\n",
3186 (unsigned long) bp_tgt
->placed_address
,
3187 (unsigned long) retval
);
3192 debug_to_insert_watchpoint (CORE_ADDR addr
, int len
, int type
)
3196 retval
= debug_target
.to_insert_watchpoint (addr
, len
, type
);
3198 fprintf_unfiltered (gdb_stdlog
,
3199 "target_insert_watchpoint (0x%lx, %d, %d) = %ld\n",
3200 (unsigned long) addr
, len
, type
, (unsigned long) retval
);
3205 debug_to_remove_watchpoint (CORE_ADDR addr
, int len
, int type
)
3209 retval
= debug_target
.to_remove_watchpoint (addr
, len
, type
);
3211 fprintf_unfiltered (gdb_stdlog
,
3212 "target_remove_watchpoint (0x%lx, %d, %d) = %ld\n",
3213 (unsigned long) addr
, len
, type
, (unsigned long) retval
);
3218 debug_to_terminal_init (void)
3220 debug_target
.to_terminal_init ();
3222 fprintf_unfiltered (gdb_stdlog
, "target_terminal_init ()\n");
3226 debug_to_terminal_inferior (void)
3228 debug_target
.to_terminal_inferior ();
3230 fprintf_unfiltered (gdb_stdlog
, "target_terminal_inferior ()\n");
3234 debug_to_terminal_ours_for_output (void)
3236 debug_target
.to_terminal_ours_for_output ();
3238 fprintf_unfiltered (gdb_stdlog
, "target_terminal_ours_for_output ()\n");
3242 debug_to_terminal_ours (void)
3244 debug_target
.to_terminal_ours ();
3246 fprintf_unfiltered (gdb_stdlog
, "target_terminal_ours ()\n");
3250 debug_to_terminal_save_ours (void)
3252 debug_target
.to_terminal_save_ours ();
3254 fprintf_unfiltered (gdb_stdlog
, "target_terminal_save_ours ()\n");
3258 debug_to_terminal_info (char *arg
, int from_tty
)
3260 debug_target
.to_terminal_info (arg
, from_tty
);
3262 fprintf_unfiltered (gdb_stdlog
, "target_terminal_info (%s, %d)\n", arg
,
3267 debug_to_load (char *args
, int from_tty
)
3269 debug_target
.to_load (args
, from_tty
);
3271 fprintf_unfiltered (gdb_stdlog
, "target_load (%s, %d)\n", args
, from_tty
);
3275 debug_to_lookup_symbol (char *name
, CORE_ADDR
*addrp
)
3279 retval
= debug_target
.to_lookup_symbol (name
, addrp
);
3281 fprintf_unfiltered (gdb_stdlog
, "target_lookup_symbol (%s, xxx)\n", name
);
3287 debug_to_post_startup_inferior (ptid_t ptid
)
3289 debug_target
.to_post_startup_inferior (ptid
);
3291 fprintf_unfiltered (gdb_stdlog
, "target_post_startup_inferior (%d)\n",
3296 debug_to_acknowledge_created_inferior (int pid
)
3298 debug_target
.to_acknowledge_created_inferior (pid
);
3300 fprintf_unfiltered (gdb_stdlog
, "target_acknowledge_created_inferior (%d)\n",
3305 debug_to_insert_fork_catchpoint (int pid
)
3307 debug_target
.to_insert_fork_catchpoint (pid
);
3309 fprintf_unfiltered (gdb_stdlog
, "target_insert_fork_catchpoint (%d)\n",
3314 debug_to_remove_fork_catchpoint (int pid
)
3318 retval
= debug_target
.to_remove_fork_catchpoint (pid
);
3320 fprintf_unfiltered (gdb_stdlog
, "target_remove_fork_catchpoint (%d) = %d\n",
3327 debug_to_insert_vfork_catchpoint (int pid
)
3329 debug_target
.to_insert_vfork_catchpoint (pid
);
3331 fprintf_unfiltered (gdb_stdlog
, "target_insert_vfork_catchpoint (%d)\n",
3336 debug_to_remove_vfork_catchpoint (int pid
)
3340 retval
= debug_target
.to_remove_vfork_catchpoint (pid
);
3342 fprintf_unfiltered (gdb_stdlog
, "target_remove_vfork_catchpoint (%d) = %d\n",
3349 debug_to_insert_exec_catchpoint (int pid
)
3351 debug_target
.to_insert_exec_catchpoint (pid
);
3353 fprintf_unfiltered (gdb_stdlog
, "target_insert_exec_catchpoint (%d)\n",
3358 debug_to_remove_exec_catchpoint (int pid
)
3362 retval
= debug_target
.to_remove_exec_catchpoint (pid
);
3364 fprintf_unfiltered (gdb_stdlog
, "target_remove_exec_catchpoint (%d) = %d\n",
3371 debug_to_has_exited (int pid
, int wait_status
, int *exit_status
)
3375 has_exited
= debug_target
.to_has_exited (pid
, wait_status
, exit_status
);
3377 fprintf_unfiltered (gdb_stdlog
, "target_has_exited (%d, %d, %d) = %d\n",
3378 pid
, wait_status
, *exit_status
, has_exited
);
3384 debug_to_can_run (void)
3388 retval
= debug_target
.to_can_run ();
3390 fprintf_unfiltered (gdb_stdlog
, "target_can_run () = %d\n", retval
);
3396 debug_to_notice_signals (ptid_t ptid
)
3398 debug_target
.to_notice_signals (ptid
);
3400 fprintf_unfiltered (gdb_stdlog
, "target_notice_signals (%d)\n",
3404 static struct gdbarch
*
3405 debug_to_thread_architecture (struct target_ops
*ops
, ptid_t ptid
)
3407 struct gdbarch
*retval
;
3409 retval
= debug_target
.to_thread_architecture (ops
, ptid
);
3411 fprintf_unfiltered (gdb_stdlog
, "target_thread_architecture (%s) = %s [%s]\n",
3412 target_pid_to_str (ptid
), host_address_to_string (retval
),
3413 gdbarch_bfd_arch_info (retval
)->printable_name
);
3418 debug_to_stop (ptid_t ptid
)
3420 debug_target
.to_stop (ptid
);
3422 fprintf_unfiltered (gdb_stdlog
, "target_stop (%s)\n",
3423 target_pid_to_str (ptid
));
3427 debug_to_rcmd (char *command
,
3428 struct ui_file
*outbuf
)
3430 debug_target
.to_rcmd (command
, outbuf
);
3431 fprintf_unfiltered (gdb_stdlog
, "target_rcmd (%s, ...)\n", command
);
3435 debug_to_pid_to_exec_file (int pid
)
3439 exec_file
= debug_target
.to_pid_to_exec_file (pid
);
3441 fprintf_unfiltered (gdb_stdlog
, "target_pid_to_exec_file (%d) = %s\n",
3448 setup_target_debug (void)
3450 memcpy (&debug_target
, ¤t_target
, sizeof debug_target
);
3452 current_target
.to_open
= debug_to_open
;
3453 current_target
.to_post_attach
= debug_to_post_attach
;
3454 current_target
.to_prepare_to_store
= debug_to_prepare_to_store
;
3455 current_target
.deprecated_xfer_memory
= deprecated_debug_xfer_memory
;
3456 current_target
.to_files_info
= debug_to_files_info
;
3457 current_target
.to_insert_breakpoint
= debug_to_insert_breakpoint
;
3458 current_target
.to_remove_breakpoint
= debug_to_remove_breakpoint
;
3459 current_target
.to_can_use_hw_breakpoint
= debug_to_can_use_hw_breakpoint
;
3460 current_target
.to_insert_hw_breakpoint
= debug_to_insert_hw_breakpoint
;
3461 current_target
.to_remove_hw_breakpoint
= debug_to_remove_hw_breakpoint
;
3462 current_target
.to_insert_watchpoint
= debug_to_insert_watchpoint
;
3463 current_target
.to_remove_watchpoint
= debug_to_remove_watchpoint
;
3464 current_target
.to_stopped_by_watchpoint
= debug_to_stopped_by_watchpoint
;
3465 current_target
.to_stopped_data_address
= debug_to_stopped_data_address
;
3466 current_target
.to_watchpoint_addr_within_range
= debug_to_watchpoint_addr_within_range
;
3467 current_target
.to_region_ok_for_hw_watchpoint
= debug_to_region_ok_for_hw_watchpoint
;
3468 current_target
.to_terminal_init
= debug_to_terminal_init
;
3469 current_target
.to_terminal_inferior
= debug_to_terminal_inferior
;
3470 current_target
.to_terminal_ours_for_output
= debug_to_terminal_ours_for_output
;
3471 current_target
.to_terminal_ours
= debug_to_terminal_ours
;
3472 current_target
.to_terminal_save_ours
= debug_to_terminal_save_ours
;
3473 current_target
.to_terminal_info
= debug_to_terminal_info
;
3474 current_target
.to_load
= debug_to_load
;
3475 current_target
.to_lookup_symbol
= debug_to_lookup_symbol
;
3476 current_target
.to_post_startup_inferior
= debug_to_post_startup_inferior
;
3477 current_target
.to_acknowledge_created_inferior
= debug_to_acknowledge_created_inferior
;
3478 current_target
.to_insert_fork_catchpoint
= debug_to_insert_fork_catchpoint
;
3479 current_target
.to_remove_fork_catchpoint
= debug_to_remove_fork_catchpoint
;
3480 current_target
.to_insert_vfork_catchpoint
= debug_to_insert_vfork_catchpoint
;
3481 current_target
.to_remove_vfork_catchpoint
= debug_to_remove_vfork_catchpoint
;
3482 current_target
.to_insert_exec_catchpoint
= debug_to_insert_exec_catchpoint
;
3483 current_target
.to_remove_exec_catchpoint
= debug_to_remove_exec_catchpoint
;
3484 current_target
.to_has_exited
= debug_to_has_exited
;
3485 current_target
.to_can_run
= debug_to_can_run
;
3486 current_target
.to_notice_signals
= debug_to_notice_signals
;
3487 current_target
.to_stop
= debug_to_stop
;
3488 current_target
.to_rcmd
= debug_to_rcmd
;
3489 current_target
.to_pid_to_exec_file
= debug_to_pid_to_exec_file
;
3490 current_target
.to_thread_architecture
= debug_to_thread_architecture
;
3494 static char targ_desc
[] =
3495 "Names of targets and files being debugged.\n\
3496 Shows the entire stack of targets currently in use (including the exec-file,\n\
3497 core-file, and process, if any), as well as the symbol file name.";
3500 do_monitor_command (char *cmd
,
3503 if ((current_target
.to_rcmd
3504 == (void (*) (char *, struct ui_file
*)) tcomplain
)
3505 || (current_target
.to_rcmd
== debug_to_rcmd
3506 && (debug_target
.to_rcmd
3507 == (void (*) (char *, struct ui_file
*)) tcomplain
)))
3508 error (_("\"monitor\" command not supported by this target."));
3509 target_rcmd (cmd
, gdb_stdtarg
);
3512 /* Print the name of each layers of our target stack. */
3515 maintenance_print_target_stack (char *cmd
, int from_tty
)
3517 struct target_ops
*t
;
3519 printf_filtered (_("The current target stack is:\n"));
3521 for (t
= target_stack
; t
!= NULL
; t
= t
->beneath
)
3523 printf_filtered (" - %s (%s)\n", t
->to_shortname
, t
->to_longname
);
3527 /* Controls if async mode is permitted. */
3528 int target_async_permitted
= 0;
3530 /* The set command writes to this variable. If the inferior is
3531 executing, linux_nat_async_permitted is *not* updated. */
3532 static int target_async_permitted_1
= 0;
3535 set_maintenance_target_async_permitted (char *args
, int from_tty
,
3536 struct cmd_list_element
*c
)
3538 if (have_live_inferiors ())
3540 target_async_permitted_1
= target_async_permitted
;
3541 error (_("Cannot change this setting while the inferior is running."));
3544 target_async_permitted
= target_async_permitted_1
;
3548 show_maintenance_target_async_permitted (struct ui_file
*file
, int from_tty
,
3549 struct cmd_list_element
*c
,
3552 fprintf_filtered (file
, _("\
3553 Controlling the inferior in asynchronous mode is %s.\n"), value
);
3557 initialize_targets (void)
3559 init_dummy_target ();
3560 push_target (&dummy_target
);
3562 add_info ("target", target_info
, targ_desc
);
3563 add_info ("files", target_info
, targ_desc
);
3565 add_setshow_zinteger_cmd ("target", class_maintenance
, &targetdebug
, _("\
3566 Set target debugging."), _("\
3567 Show target debugging."), _("\
3568 When non-zero, target debugging is enabled. Higher numbers are more\n\
3569 verbose. Changes do not take effect until the next \"run\" or \"target\"\n\
3573 &setdebuglist
, &showdebuglist
);
3575 add_setshow_boolean_cmd ("trust-readonly-sections", class_support
,
3576 &trust_readonly
, _("\
3577 Set mode for reading from readonly sections."), _("\
3578 Show mode for reading from readonly sections."), _("\
3579 When this mode is on, memory reads from readonly sections (such as .text)\n\
3580 will be read from the object file instead of from the target. This will\n\
3581 result in significant performance improvement for remote targets."),
3583 show_trust_readonly
,
3584 &setlist
, &showlist
);
3586 add_com ("monitor", class_obscure
, do_monitor_command
,
3587 _("Send a command to the remote monitor (remote targets only)."));
3589 add_cmd ("target-stack", class_maintenance
, maintenance_print_target_stack
,
3590 _("Print the name of each layer of the internal target stack."),
3591 &maintenanceprintlist
);
3593 add_setshow_boolean_cmd ("target-async", no_class
,
3594 &target_async_permitted_1
, _("\
3595 Set whether gdb controls the inferior in asynchronous mode."), _("\
3596 Show whether gdb controls the inferior in asynchronous mode."), _("\
3597 Tells gdb whether to control the inferior in asynchronous mode."),
3598 set_maintenance_target_async_permitted
,
3599 show_maintenance_target_async_permitted
,
3603 add_setshow_boolean_cmd ("stack-cache", class_support
,
3604 &stack_cache_enabled_p_1
, _("\
3605 Set cache use for stack access."), _("\
3606 Show cache use for stack access."), _("\
3607 When on, use the data cache for all stack access, regardless of any\n\
3608 configured memory regions. This improves remote performance significantly.\n\
3609 By default, caching for stack access is on."),
3610 set_stack_cache_enabled_p
,
3611 show_stack_cache_enabled_p
,
3612 &setlist
, &showlist
);
3614 target_dcache
= dcache_init ();