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, 2010, 2011
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"
46 #include "tracepoint.h"
48 static void target_info (char *, int);
50 static void default_terminal_info (char *, int);
52 static int default_watchpoint_addr_within_range (struct target_ops
*,
53 CORE_ADDR
, CORE_ADDR
, int);
55 static int default_region_ok_for_hw_watchpoint (CORE_ADDR
, int);
57 static void tcomplain (void) ATTRIBUTE_NORETURN
;
59 static int nomemory (CORE_ADDR
, char *, int, int, struct target_ops
*);
61 static int return_zero (void);
63 static int return_one (void);
65 static int return_minus_one (void);
67 void target_ignore (void);
69 static void target_command (char *, int);
71 static struct target_ops
*find_default_run_target (char *);
73 static LONGEST
default_xfer_partial (struct target_ops
*ops
,
74 enum target_object object
,
75 const char *annex
, gdb_byte
*readbuf
,
76 const gdb_byte
*writebuf
,
77 ULONGEST offset
, LONGEST len
);
79 static LONGEST
current_xfer_partial (struct target_ops
*ops
,
80 enum target_object object
,
81 const char *annex
, gdb_byte
*readbuf
,
82 const gdb_byte
*writebuf
,
83 ULONGEST offset
, LONGEST len
);
85 static LONGEST
target_xfer_partial (struct target_ops
*ops
,
86 enum target_object object
,
88 void *readbuf
, const void *writebuf
,
89 ULONGEST offset
, LONGEST len
);
91 static struct gdbarch
*default_thread_architecture (struct target_ops
*ops
,
94 static void init_dummy_target (void);
96 static struct target_ops debug_target
;
98 static void debug_to_open (char *, int);
100 static void debug_to_prepare_to_store (struct regcache
*);
102 static void debug_to_files_info (struct target_ops
*);
104 static int debug_to_insert_breakpoint (struct gdbarch
*,
105 struct bp_target_info
*);
107 static int debug_to_remove_breakpoint (struct gdbarch
*,
108 struct bp_target_info
*);
110 static int debug_to_can_use_hw_breakpoint (int, int, int);
112 static int debug_to_insert_hw_breakpoint (struct gdbarch
*,
113 struct bp_target_info
*);
115 static int debug_to_remove_hw_breakpoint (struct gdbarch
*,
116 struct bp_target_info
*);
118 static int debug_to_insert_watchpoint (CORE_ADDR
, int, int,
119 struct expression
*);
121 static int debug_to_remove_watchpoint (CORE_ADDR
, int, int,
122 struct expression
*);
124 static int debug_to_stopped_by_watchpoint (void);
126 static int debug_to_stopped_data_address (struct target_ops
*, CORE_ADDR
*);
128 static int debug_to_watchpoint_addr_within_range (struct target_ops
*,
129 CORE_ADDR
, CORE_ADDR
, int);
131 static int debug_to_region_ok_for_hw_watchpoint (CORE_ADDR
, int);
133 static int debug_to_can_accel_watchpoint_condition (CORE_ADDR
, int, int,
134 struct expression
*);
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_can_run (void);
152 static void debug_to_stop (ptid_t
);
154 /* Pointer to array of target architecture structures; the size of the
155 array; the current index into the array; the allocated size of the
157 struct target_ops
**target_structs
;
158 unsigned target_struct_size
;
159 unsigned target_struct_index
;
160 unsigned target_struct_allocsize
;
161 #define DEFAULT_ALLOCSIZE 10
163 /* The initial current target, so that there is always a semi-valid
166 static struct target_ops dummy_target
;
168 /* Top of target stack. */
170 static struct target_ops
*target_stack
;
172 /* The target structure we are currently using to talk to a process
173 or file or whatever "inferior" we have. */
175 struct target_ops current_target
;
177 /* Command list for target. */
179 static struct cmd_list_element
*targetlist
= NULL
;
181 /* Nonzero if we should trust readonly sections from the
182 executable when reading memory. */
184 static int trust_readonly
= 0;
186 /* Nonzero if we should show true memory content including
187 memory breakpoint inserted by gdb. */
189 static int show_memory_breakpoints
= 0;
191 /* These globals control whether GDB attempts to perform these
192 operations; they are useful for targets that need to prevent
193 inadvertant disruption, such as in non-stop mode. */
195 int may_write_registers
= 1;
197 int may_write_memory
= 1;
199 int may_insert_breakpoints
= 1;
201 int may_insert_tracepoints
= 1;
203 int may_insert_fast_tracepoints
= 1;
207 /* Non-zero if we want to see trace of target level stuff. */
209 static int targetdebug
= 0;
211 show_targetdebug (struct ui_file
*file
, int from_tty
,
212 struct cmd_list_element
*c
, const char *value
)
214 fprintf_filtered (file
, _("Target debugging is %s.\n"), value
);
217 static void setup_target_debug (void);
219 /* The option sets this. */
220 static int stack_cache_enabled_p_1
= 1;
221 /* And set_stack_cache_enabled_p updates this.
222 The reason for the separation is so that we don't flush the cache for
223 on->on transitions. */
224 static int stack_cache_enabled_p
= 1;
226 /* This is called *after* the stack-cache has been set.
227 Flush the cache for off->on and on->off transitions.
228 There's no real need to flush the cache for on->off transitions,
229 except cleanliness. */
232 set_stack_cache_enabled_p (char *args
, int from_tty
,
233 struct cmd_list_element
*c
)
235 if (stack_cache_enabled_p
!= stack_cache_enabled_p_1
)
236 target_dcache_invalidate ();
238 stack_cache_enabled_p
= stack_cache_enabled_p_1
;
242 show_stack_cache_enabled_p (struct ui_file
*file
, int from_tty
,
243 struct cmd_list_element
*c
, const char *value
)
245 fprintf_filtered (file
, _("Cache use for stack accesses is %s.\n"), value
);
248 /* Cache of memory operations, to speed up remote access. */
249 static DCACHE
*target_dcache
;
251 /* Invalidate the target dcache. */
254 target_dcache_invalidate (void)
256 dcache_invalidate (target_dcache
);
259 /* The user just typed 'target' without the name of a target. */
262 target_command (char *arg
, int from_tty
)
264 fputs_filtered ("Argument required (target name). Try `help target'\n",
268 /* Default target_has_* methods for process_stratum targets. */
271 default_child_has_all_memory (struct target_ops
*ops
)
273 /* If no inferior selected, then we can't read memory here. */
274 if (ptid_equal (inferior_ptid
, null_ptid
))
281 default_child_has_memory (struct target_ops
*ops
)
283 /* If no inferior selected, then we can't read memory here. */
284 if (ptid_equal (inferior_ptid
, null_ptid
))
291 default_child_has_stack (struct target_ops
*ops
)
293 /* If no inferior selected, there's no stack. */
294 if (ptid_equal (inferior_ptid
, null_ptid
))
301 default_child_has_registers (struct target_ops
*ops
)
303 /* Can't read registers from no inferior. */
304 if (ptid_equal (inferior_ptid
, null_ptid
))
311 default_child_has_execution (struct target_ops
*ops
, ptid_t the_ptid
)
313 /* If there's no thread selected, then we can't make it run through
315 if (ptid_equal (the_ptid
, null_ptid
))
323 target_has_all_memory_1 (void)
325 struct target_ops
*t
;
327 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
328 if (t
->to_has_all_memory (t
))
335 target_has_memory_1 (void)
337 struct target_ops
*t
;
339 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
340 if (t
->to_has_memory (t
))
347 target_has_stack_1 (void)
349 struct target_ops
*t
;
351 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
352 if (t
->to_has_stack (t
))
359 target_has_registers_1 (void)
361 struct target_ops
*t
;
363 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
364 if (t
->to_has_registers (t
))
371 target_has_execution_1 (ptid_t the_ptid
)
373 struct target_ops
*t
;
375 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
376 if (t
->to_has_execution (t
, the_ptid
))
383 target_has_execution_current (void)
385 return target_has_execution_1 (inferior_ptid
);
388 /* Add a possible target architecture to the list. */
391 add_target (struct target_ops
*t
)
393 /* Provide default values for all "must have" methods. */
394 if (t
->to_xfer_partial
== NULL
)
395 t
->to_xfer_partial
= default_xfer_partial
;
397 if (t
->to_has_all_memory
== NULL
)
398 t
->to_has_all_memory
= (int (*) (struct target_ops
*)) return_zero
;
400 if (t
->to_has_memory
== NULL
)
401 t
->to_has_memory
= (int (*) (struct target_ops
*)) return_zero
;
403 if (t
->to_has_stack
== NULL
)
404 t
->to_has_stack
= (int (*) (struct target_ops
*)) return_zero
;
406 if (t
->to_has_registers
== NULL
)
407 t
->to_has_registers
= (int (*) (struct target_ops
*)) return_zero
;
409 if (t
->to_has_execution
== NULL
)
410 t
->to_has_execution
= (int (*) (struct target_ops
*, ptid_t
)) return_zero
;
414 target_struct_allocsize
= DEFAULT_ALLOCSIZE
;
415 target_structs
= (struct target_ops
**) xmalloc
416 (target_struct_allocsize
* sizeof (*target_structs
));
418 if (target_struct_size
>= target_struct_allocsize
)
420 target_struct_allocsize
*= 2;
421 target_structs
= (struct target_ops
**)
422 xrealloc ((char *) target_structs
,
423 target_struct_allocsize
* sizeof (*target_structs
));
425 target_structs
[target_struct_size
++] = t
;
427 if (targetlist
== NULL
)
428 add_prefix_cmd ("target", class_run
, target_command
, _("\
429 Connect to a target machine or process.\n\
430 The first argument is the type or protocol of the target machine.\n\
431 Remaining arguments are interpreted by the target protocol. For more\n\
432 information on the arguments for a particular protocol, type\n\
433 `help target ' followed by the protocol name."),
434 &targetlist
, "target ", 0, &cmdlist
);
435 add_cmd (t
->to_shortname
, no_class
, t
->to_open
, t
->to_doc
, &targetlist
);
448 struct target_ops
*t
;
450 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
451 if (t
->to_kill
!= NULL
)
454 fprintf_unfiltered (gdb_stdlog
, "target_kill ()\n");
464 target_load (char *arg
, int from_tty
)
466 target_dcache_invalidate ();
467 (*current_target
.to_load
) (arg
, from_tty
);
471 target_create_inferior (char *exec_file
, char *args
,
472 char **env
, int from_tty
)
474 struct target_ops
*t
;
476 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
478 if (t
->to_create_inferior
!= NULL
)
480 t
->to_create_inferior (t
, exec_file
, args
, env
, from_tty
);
482 fprintf_unfiltered (gdb_stdlog
,
483 "target_create_inferior (%s, %s, xxx, %d)\n",
484 exec_file
, args
, from_tty
);
489 internal_error (__FILE__
, __LINE__
,
490 _("could not find a target to create inferior"));
494 target_terminal_inferior (void)
496 /* A background resume (``run&'') should leave GDB in control of the
497 terminal. Use target_can_async_p, not target_is_async_p, since at
498 this point the target is not async yet. However, if sync_execution
499 is not set, we know it will become async prior to resume. */
500 if (target_can_async_p () && !sync_execution
)
503 /* If GDB is resuming the inferior in the foreground, install
504 inferior's terminal modes. */
505 (*current_target
.to_terminal_inferior
) ();
509 nomemory (CORE_ADDR memaddr
, char *myaddr
, int len
, int write
,
510 struct target_ops
*t
)
512 errno
= EIO
; /* Can't read/write this location. */
513 return 0; /* No bytes handled. */
519 error (_("You can't do that when your target is `%s'"),
520 current_target
.to_shortname
);
526 error (_("You can't do that without a process to debug."));
530 default_terminal_info (char *args
, int from_tty
)
532 printf_unfiltered (_("No saved terminal information.\n"));
535 /* A default implementation for the to_get_ada_task_ptid target method.
537 This function builds the PTID by using both LWP and TID as part of
538 the PTID lwp and tid elements. The pid used is the pid of the
542 default_get_ada_task_ptid (long lwp
, long tid
)
544 return ptid_build (ptid_get_pid (inferior_ptid
), lwp
, tid
);
547 static enum exec_direction_kind
548 default_execution_direction (void)
550 if (!target_can_execute_reverse
)
552 else if (!target_can_async_p ())
555 gdb_assert_not_reached ("\
556 to_execution_direction must be implemented for reverse async");
559 /* Go through the target stack from top to bottom, copying over zero
560 entries in current_target, then filling in still empty entries. In
561 effect, we are doing class inheritance through the pushed target
564 NOTE: cagney/2003-10-17: The problem with this inheritance, as it
565 is currently implemented, is that it discards any knowledge of
566 which target an inherited method originally belonged to.
567 Consequently, new new target methods should instead explicitly and
568 locally search the target stack for the target that can handle the
572 update_current_target (void)
574 struct target_ops
*t
;
576 /* First, reset current's contents. */
577 memset (¤t_target
, 0, sizeof (current_target
));
579 #define INHERIT(FIELD, TARGET) \
580 if (!current_target.FIELD) \
581 current_target.FIELD = (TARGET)->FIELD
583 for (t
= target_stack
; t
; t
= t
->beneath
)
585 INHERIT (to_shortname
, t
);
586 INHERIT (to_longname
, t
);
588 /* Do not inherit to_open. */
589 /* Do not inherit to_close. */
590 /* Do not inherit to_attach. */
591 INHERIT (to_post_attach
, t
);
592 INHERIT (to_attach_no_wait
, t
);
593 /* Do not inherit to_detach. */
594 /* Do not inherit to_disconnect. */
595 /* Do not inherit to_resume. */
596 /* Do not inherit to_wait. */
597 /* Do not inherit to_fetch_registers. */
598 /* Do not inherit to_store_registers. */
599 INHERIT (to_prepare_to_store
, t
);
600 INHERIT (deprecated_xfer_memory
, t
);
601 INHERIT (to_files_info
, t
);
602 INHERIT (to_insert_breakpoint
, t
);
603 INHERIT (to_remove_breakpoint
, t
);
604 INHERIT (to_can_use_hw_breakpoint
, t
);
605 INHERIT (to_insert_hw_breakpoint
, t
);
606 INHERIT (to_remove_hw_breakpoint
, t
);
607 /* Do not inherit to_ranged_break_num_registers. */
608 INHERIT (to_insert_watchpoint
, t
);
609 INHERIT (to_remove_watchpoint
, t
);
610 /* Do not inherit to_insert_mask_watchpoint. */
611 /* Do not inherit to_remove_mask_watchpoint. */
612 INHERIT (to_stopped_data_address
, t
);
613 INHERIT (to_have_steppable_watchpoint
, t
);
614 INHERIT (to_have_continuable_watchpoint
, t
);
615 INHERIT (to_stopped_by_watchpoint
, t
);
616 INHERIT (to_watchpoint_addr_within_range
, t
);
617 INHERIT (to_region_ok_for_hw_watchpoint
, t
);
618 INHERIT (to_can_accel_watchpoint_condition
, t
);
619 /* Do not inherit to_masked_watch_num_registers. */
620 INHERIT (to_terminal_init
, t
);
621 INHERIT (to_terminal_inferior
, t
);
622 INHERIT (to_terminal_ours_for_output
, t
);
623 INHERIT (to_terminal_ours
, t
);
624 INHERIT (to_terminal_save_ours
, t
);
625 INHERIT (to_terminal_info
, t
);
626 /* Do not inherit to_kill. */
627 INHERIT (to_load
, t
);
628 /* Do no inherit to_create_inferior. */
629 INHERIT (to_post_startup_inferior
, t
);
630 INHERIT (to_insert_fork_catchpoint
, t
);
631 INHERIT (to_remove_fork_catchpoint
, t
);
632 INHERIT (to_insert_vfork_catchpoint
, t
);
633 INHERIT (to_remove_vfork_catchpoint
, t
);
634 /* Do not inherit to_follow_fork. */
635 INHERIT (to_insert_exec_catchpoint
, t
);
636 INHERIT (to_remove_exec_catchpoint
, t
);
637 INHERIT (to_set_syscall_catchpoint
, t
);
638 INHERIT (to_has_exited
, t
);
639 /* Do not inherit to_mourn_inferior. */
640 INHERIT (to_can_run
, t
);
641 /* Do not inherit to_pass_signals. */
642 /* Do not inherit to_thread_alive. */
643 /* Do not inherit to_find_new_threads. */
644 /* Do not inherit to_pid_to_str. */
645 INHERIT (to_extra_thread_info
, t
);
646 INHERIT (to_thread_name
, t
);
647 INHERIT (to_stop
, t
);
648 /* Do not inherit to_xfer_partial. */
649 INHERIT (to_rcmd
, t
);
650 INHERIT (to_pid_to_exec_file
, t
);
651 INHERIT (to_log_command
, t
);
652 INHERIT (to_stratum
, t
);
653 /* Do not inherit to_has_all_memory. */
654 /* Do not inherit to_has_memory. */
655 /* Do not inherit to_has_stack. */
656 /* Do not inherit to_has_registers. */
657 /* Do not inherit to_has_execution. */
658 INHERIT (to_has_thread_control
, t
);
659 INHERIT (to_can_async_p
, t
);
660 INHERIT (to_is_async_p
, t
);
661 INHERIT (to_async
, t
);
662 INHERIT (to_find_memory_regions
, t
);
663 INHERIT (to_make_corefile_notes
, t
);
664 INHERIT (to_get_bookmark
, t
);
665 INHERIT (to_goto_bookmark
, t
);
666 /* Do not inherit to_get_thread_local_address. */
667 INHERIT (to_can_execute_reverse
, t
);
668 INHERIT (to_execution_direction
, t
);
669 INHERIT (to_thread_architecture
, t
);
670 /* Do not inherit to_read_description. */
671 INHERIT (to_get_ada_task_ptid
, t
);
672 /* Do not inherit to_search_memory. */
673 INHERIT (to_supports_multi_process
, t
);
674 INHERIT (to_supports_enable_disable_tracepoint
, t
);
675 INHERIT (to_supports_string_tracing
, t
);
676 INHERIT (to_trace_init
, t
);
677 INHERIT (to_download_tracepoint
, t
);
678 INHERIT (to_can_download_tracepoint
, t
);
679 INHERIT (to_download_trace_state_variable
, t
);
680 INHERIT (to_enable_tracepoint
, t
);
681 INHERIT (to_disable_tracepoint
, t
);
682 INHERIT (to_trace_set_readonly_regions
, t
);
683 INHERIT (to_trace_start
, t
);
684 INHERIT (to_get_trace_status
, t
);
685 INHERIT (to_trace_stop
, t
);
686 INHERIT (to_trace_find
, t
);
687 INHERIT (to_get_trace_state_variable_value
, t
);
688 INHERIT (to_save_trace_data
, t
);
689 INHERIT (to_upload_tracepoints
, t
);
690 INHERIT (to_upload_trace_state_variables
, t
);
691 INHERIT (to_get_raw_trace_data
, t
);
692 INHERIT (to_get_min_fast_tracepoint_insn_len
, t
);
693 INHERIT (to_set_disconnected_tracing
, t
);
694 INHERIT (to_set_circular_trace_buffer
, t
);
695 INHERIT (to_get_tib_address
, t
);
696 INHERIT (to_set_permissions
, t
);
697 INHERIT (to_static_tracepoint_marker_at
, t
);
698 INHERIT (to_static_tracepoint_markers_by_strid
, t
);
699 INHERIT (to_traceframe_info
, t
);
700 INHERIT (to_magic
, t
);
701 /* Do not inherit to_memory_map. */
702 /* Do not inherit to_flash_erase. */
703 /* Do not inherit to_flash_done. */
707 /* Clean up a target struct so it no longer has any zero pointers in
708 it. Some entries are defaulted to a method that print an error,
709 others are hard-wired to a standard recursive default. */
711 #define de_fault(field, value) \
712 if (!current_target.field) \
713 current_target.field = value
716 (void (*) (char *, int))
721 de_fault (to_post_attach
,
724 de_fault (to_prepare_to_store
,
725 (void (*) (struct regcache
*))
727 de_fault (deprecated_xfer_memory
,
728 (int (*) (CORE_ADDR
, gdb_byte
*, int, int,
729 struct mem_attrib
*, struct target_ops
*))
731 de_fault (to_files_info
,
732 (void (*) (struct target_ops
*))
734 de_fault (to_insert_breakpoint
,
735 memory_insert_breakpoint
);
736 de_fault (to_remove_breakpoint
,
737 memory_remove_breakpoint
);
738 de_fault (to_can_use_hw_breakpoint
,
739 (int (*) (int, int, int))
741 de_fault (to_insert_hw_breakpoint
,
742 (int (*) (struct gdbarch
*, struct bp_target_info
*))
744 de_fault (to_remove_hw_breakpoint
,
745 (int (*) (struct gdbarch
*, struct bp_target_info
*))
747 de_fault (to_insert_watchpoint
,
748 (int (*) (CORE_ADDR
, int, int, struct expression
*))
750 de_fault (to_remove_watchpoint
,
751 (int (*) (CORE_ADDR
, int, int, struct expression
*))
753 de_fault (to_stopped_by_watchpoint
,
756 de_fault (to_stopped_data_address
,
757 (int (*) (struct target_ops
*, CORE_ADDR
*))
759 de_fault (to_watchpoint_addr_within_range
,
760 default_watchpoint_addr_within_range
);
761 de_fault (to_region_ok_for_hw_watchpoint
,
762 default_region_ok_for_hw_watchpoint
);
763 de_fault (to_can_accel_watchpoint_condition
,
764 (int (*) (CORE_ADDR
, int, int, struct expression
*))
766 de_fault (to_terminal_init
,
769 de_fault (to_terminal_inferior
,
772 de_fault (to_terminal_ours_for_output
,
775 de_fault (to_terminal_ours
,
778 de_fault (to_terminal_save_ours
,
781 de_fault (to_terminal_info
,
782 default_terminal_info
);
784 (void (*) (char *, int))
786 de_fault (to_post_startup_inferior
,
789 de_fault (to_insert_fork_catchpoint
,
792 de_fault (to_remove_fork_catchpoint
,
795 de_fault (to_insert_vfork_catchpoint
,
798 de_fault (to_remove_vfork_catchpoint
,
801 de_fault (to_insert_exec_catchpoint
,
804 de_fault (to_remove_exec_catchpoint
,
807 de_fault (to_set_syscall_catchpoint
,
808 (int (*) (int, int, int, int, int *))
810 de_fault (to_has_exited
,
811 (int (*) (int, int, int *))
813 de_fault (to_can_run
,
815 de_fault (to_extra_thread_info
,
816 (char *(*) (struct thread_info
*))
818 de_fault (to_thread_name
,
819 (char *(*) (struct thread_info
*))
824 current_target
.to_xfer_partial
= current_xfer_partial
;
826 (void (*) (char *, struct ui_file
*))
828 de_fault (to_pid_to_exec_file
,
832 (void (*) (void (*) (enum inferior_event_type
, void*), void*))
834 de_fault (to_thread_architecture
,
835 default_thread_architecture
);
836 current_target
.to_read_description
= NULL
;
837 de_fault (to_get_ada_task_ptid
,
838 (ptid_t (*) (long, long))
839 default_get_ada_task_ptid
);
840 de_fault (to_supports_multi_process
,
843 de_fault (to_supports_enable_disable_tracepoint
,
846 de_fault (to_supports_string_tracing
,
849 de_fault (to_trace_init
,
852 de_fault (to_download_tracepoint
,
853 (void (*) (struct bp_location
*))
855 de_fault (to_can_download_tracepoint
,
858 de_fault (to_download_trace_state_variable
,
859 (void (*) (struct trace_state_variable
*))
861 de_fault (to_enable_tracepoint
,
862 (void (*) (struct bp_location
*))
864 de_fault (to_disable_tracepoint
,
865 (void (*) (struct bp_location
*))
867 de_fault (to_trace_set_readonly_regions
,
870 de_fault (to_trace_start
,
873 de_fault (to_get_trace_status
,
874 (int (*) (struct trace_status
*))
876 de_fault (to_trace_stop
,
879 de_fault (to_trace_find
,
880 (int (*) (enum trace_find_type
, int, ULONGEST
, ULONGEST
, int *))
882 de_fault (to_get_trace_state_variable_value
,
883 (int (*) (int, LONGEST
*))
885 de_fault (to_save_trace_data
,
886 (int (*) (const char *))
888 de_fault (to_upload_tracepoints
,
889 (int (*) (struct uploaded_tp
**))
891 de_fault (to_upload_trace_state_variables
,
892 (int (*) (struct uploaded_tsv
**))
894 de_fault (to_get_raw_trace_data
,
895 (LONGEST (*) (gdb_byte
*, ULONGEST
, LONGEST
))
897 de_fault (to_get_min_fast_tracepoint_insn_len
,
900 de_fault (to_set_disconnected_tracing
,
903 de_fault (to_set_circular_trace_buffer
,
906 de_fault (to_get_tib_address
,
907 (int (*) (ptid_t
, CORE_ADDR
*))
909 de_fault (to_set_permissions
,
912 de_fault (to_static_tracepoint_marker_at
,
913 (int (*) (CORE_ADDR
, struct static_tracepoint_marker
*))
915 de_fault (to_static_tracepoint_markers_by_strid
,
916 (VEC(static_tracepoint_marker_p
) * (*) (const char *))
918 de_fault (to_traceframe_info
,
919 (struct traceframe_info
* (*) (void))
921 de_fault (to_execution_direction
, default_execution_direction
);
925 /* Finally, position the target-stack beneath the squashed
926 "current_target". That way code looking for a non-inherited
927 target method can quickly and simply find it. */
928 current_target
.beneath
= target_stack
;
931 setup_target_debug ();
934 /* Push a new target type into the stack of the existing target accessors,
935 possibly superseding some of the existing accessors.
937 Rather than allow an empty stack, we always have the dummy target at
938 the bottom stratum, so we can call the function vectors without
942 push_target (struct target_ops
*t
)
944 struct target_ops
**cur
;
946 /* Check magic number. If wrong, it probably means someone changed
947 the struct definition, but not all the places that initialize one. */
948 if (t
->to_magic
!= OPS_MAGIC
)
950 fprintf_unfiltered (gdb_stderr
,
951 "Magic number of %s target struct wrong\n",
953 internal_error (__FILE__
, __LINE__
,
954 _("failed internal consistency check"));
957 /* Find the proper stratum to install this target in. */
958 for (cur
= &target_stack
; (*cur
) != NULL
; cur
= &(*cur
)->beneath
)
960 if ((int) (t
->to_stratum
) >= (int) (*cur
)->to_stratum
)
964 /* If there's already targets at this stratum, remove them. */
965 /* FIXME: cagney/2003-10-15: I think this should be popping all
966 targets to CUR, and not just those at this stratum level. */
967 while ((*cur
) != NULL
&& t
->to_stratum
== (*cur
)->to_stratum
)
969 /* There's already something at this stratum level. Close it,
970 and un-hook it from the stack. */
971 struct target_ops
*tmp
= (*cur
);
973 (*cur
) = (*cur
)->beneath
;
975 target_close (tmp
, 0);
978 /* We have removed all targets in our stratum, now add the new one. */
982 update_current_target ();
985 /* Remove a target_ops vector from the stack, wherever it may be.
986 Return how many times it was removed (0 or 1). */
989 unpush_target (struct target_ops
*t
)
991 struct target_ops
**cur
;
992 struct target_ops
*tmp
;
994 if (t
->to_stratum
== dummy_stratum
)
995 internal_error (__FILE__
, __LINE__
,
996 _("Attempt to unpush the dummy target"));
998 /* Look for the specified target. Note that we assume that a target
999 can only occur once in the target stack. */
1001 for (cur
= &target_stack
; (*cur
) != NULL
; cur
= &(*cur
)->beneath
)
1008 return 0; /* Didn't find target_ops, quit now. */
1010 /* NOTE: cagney/2003-12-06: In '94 the close call was made
1011 unconditional by moving it to before the above check that the
1012 target was in the target stack (something about "Change the way
1013 pushing and popping of targets work to support target overlays
1014 and inheritance"). This doesn't make much sense - only open
1015 targets should be closed. */
1016 target_close (t
, 0);
1018 /* Unchain the target. */
1020 (*cur
) = (*cur
)->beneath
;
1021 tmp
->beneath
= NULL
;
1023 update_current_target ();
1031 target_close (target_stack
, 0); /* Let it clean up. */
1032 if (unpush_target (target_stack
) == 1)
1035 fprintf_unfiltered (gdb_stderr
,
1036 "pop_target couldn't find target %s\n",
1037 current_target
.to_shortname
);
1038 internal_error (__FILE__
, __LINE__
,
1039 _("failed internal consistency check"));
1043 pop_all_targets_above (enum strata above_stratum
, int quitting
)
1045 while ((int) (current_target
.to_stratum
) > (int) above_stratum
)
1047 target_close (target_stack
, quitting
);
1048 if (!unpush_target (target_stack
))
1050 fprintf_unfiltered (gdb_stderr
,
1051 "pop_all_targets couldn't find target %s\n",
1052 target_stack
->to_shortname
);
1053 internal_error (__FILE__
, __LINE__
,
1054 _("failed internal consistency check"));
1061 pop_all_targets (int quitting
)
1063 pop_all_targets_above (dummy_stratum
, quitting
);
1066 /* Return 1 if T is now pushed in the target stack. Return 0 otherwise. */
1069 target_is_pushed (struct target_ops
*t
)
1071 struct target_ops
**cur
;
1073 /* Check magic number. If wrong, it probably means someone changed
1074 the struct definition, but not all the places that initialize one. */
1075 if (t
->to_magic
!= OPS_MAGIC
)
1077 fprintf_unfiltered (gdb_stderr
,
1078 "Magic number of %s target struct wrong\n",
1080 internal_error (__FILE__
, __LINE__
,
1081 _("failed internal consistency check"));
1084 for (cur
= &target_stack
; (*cur
) != NULL
; cur
= &(*cur
)->beneath
)
1091 /* Using the objfile specified in OBJFILE, find the address for the
1092 current thread's thread-local storage with offset OFFSET. */
1094 target_translate_tls_address (struct objfile
*objfile
, CORE_ADDR offset
)
1096 volatile CORE_ADDR addr
= 0;
1097 struct target_ops
*target
;
1099 for (target
= current_target
.beneath
;
1101 target
= target
->beneath
)
1103 if (target
->to_get_thread_local_address
!= NULL
)
1108 && gdbarch_fetch_tls_load_module_address_p (target_gdbarch
))
1110 ptid_t ptid
= inferior_ptid
;
1111 volatile struct gdb_exception ex
;
1113 TRY_CATCH (ex
, RETURN_MASK_ALL
)
1117 /* Fetch the load module address for this objfile. */
1118 lm_addr
= gdbarch_fetch_tls_load_module_address (target_gdbarch
,
1120 /* If it's 0, throw the appropriate exception. */
1122 throw_error (TLS_LOAD_MODULE_NOT_FOUND_ERROR
,
1123 _("TLS load module not found"));
1125 addr
= target
->to_get_thread_local_address (target
, ptid
,
1128 /* If an error occurred, print TLS related messages here. Otherwise,
1129 throw the error to some higher catcher. */
1132 int objfile_is_library
= (objfile
->flags
& OBJF_SHARED
);
1136 case TLS_NO_LIBRARY_SUPPORT_ERROR
:
1137 error (_("Cannot find thread-local variables "
1138 "in this thread library."));
1140 case TLS_LOAD_MODULE_NOT_FOUND_ERROR
:
1141 if (objfile_is_library
)
1142 error (_("Cannot find shared library `%s' in dynamic"
1143 " linker's load module list"), objfile
->name
);
1145 error (_("Cannot find executable file `%s' in dynamic"
1146 " linker's load module list"), objfile
->name
);
1148 case TLS_NOT_ALLOCATED_YET_ERROR
:
1149 if (objfile_is_library
)
1150 error (_("The inferior has not yet allocated storage for"
1151 " thread-local variables in\n"
1152 "the shared library `%s'\n"
1154 objfile
->name
, target_pid_to_str (ptid
));
1156 error (_("The inferior has not yet allocated storage for"
1157 " thread-local variables in\n"
1158 "the executable `%s'\n"
1160 objfile
->name
, target_pid_to_str (ptid
));
1162 case TLS_GENERIC_ERROR
:
1163 if (objfile_is_library
)
1164 error (_("Cannot find thread-local storage for %s, "
1165 "shared library %s:\n%s"),
1166 target_pid_to_str (ptid
),
1167 objfile
->name
, ex
.message
);
1169 error (_("Cannot find thread-local storage for %s, "
1170 "executable file %s:\n%s"),
1171 target_pid_to_str (ptid
),
1172 objfile
->name
, ex
.message
);
1175 throw_exception (ex
);
1180 /* It wouldn't be wrong here to try a gdbarch method, too; finding
1181 TLS is an ABI-specific thing. But we don't do that yet. */
1183 error (_("Cannot find thread-local variables on this target"));
1189 #define MIN(A, B) (((A) <= (B)) ? (A) : (B))
1191 /* target_read_string -- read a null terminated string, up to LEN bytes,
1192 from MEMADDR in target. Set *ERRNOP to the errno code, or 0 if successful.
1193 Set *STRING to a pointer to malloc'd memory containing the data; the caller
1194 is responsible for freeing it. Return the number of bytes successfully
1198 target_read_string (CORE_ADDR memaddr
, char **string
, int len
, int *errnop
)
1200 int tlen
, origlen
, offset
, i
;
1204 int buffer_allocated
;
1206 unsigned int nbytes_read
= 0;
1208 gdb_assert (string
);
1210 /* Small for testing. */
1211 buffer_allocated
= 4;
1212 buffer
= xmalloc (buffer_allocated
);
1219 tlen
= MIN (len
, 4 - (memaddr
& 3));
1220 offset
= memaddr
& 3;
1222 errcode
= target_read_memory (memaddr
& ~3, buf
, sizeof buf
);
1225 /* The transfer request might have crossed the boundary to an
1226 unallocated region of memory. Retry the transfer, requesting
1230 errcode
= target_read_memory (memaddr
, buf
, 1);
1235 if (bufptr
- buffer
+ tlen
> buffer_allocated
)
1239 bytes
= bufptr
- buffer
;
1240 buffer_allocated
*= 2;
1241 buffer
= xrealloc (buffer
, buffer_allocated
);
1242 bufptr
= buffer
+ bytes
;
1245 for (i
= 0; i
< tlen
; i
++)
1247 *bufptr
++ = buf
[i
+ offset
];
1248 if (buf
[i
+ offset
] == '\000')
1250 nbytes_read
+= i
+ 1;
1257 nbytes_read
+= tlen
;
1266 struct target_section_table
*
1267 target_get_section_table (struct target_ops
*target
)
1269 struct target_ops
*t
;
1272 fprintf_unfiltered (gdb_stdlog
, "target_get_section_table ()\n");
1274 for (t
= target
; t
!= NULL
; t
= t
->beneath
)
1275 if (t
->to_get_section_table
!= NULL
)
1276 return (*t
->to_get_section_table
) (t
);
1281 /* Find a section containing ADDR. */
1283 struct target_section
*
1284 target_section_by_addr (struct target_ops
*target
, CORE_ADDR addr
)
1286 struct target_section_table
*table
= target_get_section_table (target
);
1287 struct target_section
*secp
;
1292 for (secp
= table
->sections
; secp
< table
->sections_end
; secp
++)
1294 if (addr
>= secp
->addr
&& addr
< secp
->endaddr
)
1300 /* Read memory from the live target, even if currently inspecting a
1301 traceframe. The return is the same as that of target_read. */
1304 target_read_live_memory (enum target_object object
,
1305 ULONGEST memaddr
, gdb_byte
*myaddr
, LONGEST len
)
1308 struct cleanup
*cleanup
;
1310 /* Switch momentarily out of tfind mode so to access live memory.
1311 Note that this must not clear global state, such as the frame
1312 cache, which must still remain valid for the previous traceframe.
1313 We may be _building_ the frame cache at this point. */
1314 cleanup
= make_cleanup_restore_traceframe_number ();
1315 set_traceframe_number (-1);
1317 ret
= target_read (current_target
.beneath
, object
, NULL
,
1318 myaddr
, memaddr
, len
);
1320 do_cleanups (cleanup
);
1324 /* Using the set of read-only target sections of OPS, read live
1325 read-only memory. Note that the actual reads start from the
1326 top-most target again.
1328 For interface/parameters/return description see target.h,
1332 memory_xfer_live_readonly_partial (struct target_ops
*ops
,
1333 enum target_object object
,
1334 gdb_byte
*readbuf
, ULONGEST memaddr
,
1337 struct target_section
*secp
;
1338 struct target_section_table
*table
;
1340 secp
= target_section_by_addr (ops
, memaddr
);
1342 && (bfd_get_section_flags (secp
->bfd
, secp
->the_bfd_section
)
1345 struct target_section
*p
;
1346 ULONGEST memend
= memaddr
+ len
;
1348 table
= target_get_section_table (ops
);
1350 for (p
= table
->sections
; p
< table
->sections_end
; p
++)
1352 if (memaddr
>= p
->addr
)
1354 if (memend
<= p
->endaddr
)
1356 /* Entire transfer is within this section. */
1357 return target_read_live_memory (object
, memaddr
,
1360 else if (memaddr
>= p
->endaddr
)
1362 /* This section ends before the transfer starts. */
1367 /* This section overlaps the transfer. Just do half. */
1368 len
= p
->endaddr
- memaddr
;
1369 return target_read_live_memory (object
, memaddr
,
1379 /* Perform a partial memory transfer.
1380 For docs see target.h, to_xfer_partial. */
1383 memory_xfer_partial (struct target_ops
*ops
, enum target_object object
,
1384 void *readbuf
, const void *writebuf
, ULONGEST memaddr
,
1389 struct mem_region
*region
;
1390 struct inferior
*inf
;
1392 /* Zero length requests are ok and require no work. */
1396 /* For accesses to unmapped overlay sections, read directly from
1397 files. Must do this first, as MEMADDR may need adjustment. */
1398 if (readbuf
!= NULL
&& overlay_debugging
)
1400 struct obj_section
*section
= find_pc_overlay (memaddr
);
1402 if (pc_in_unmapped_range (memaddr
, section
))
1404 struct target_section_table
*table
1405 = target_get_section_table (ops
);
1406 const char *section_name
= section
->the_bfd_section
->name
;
1408 memaddr
= overlay_mapped_address (memaddr
, section
);
1409 return section_table_xfer_memory_partial (readbuf
, writebuf
,
1412 table
->sections_end
,
1417 /* Try the executable files, if "trust-readonly-sections" is set. */
1418 if (readbuf
!= NULL
&& trust_readonly
)
1420 struct target_section
*secp
;
1421 struct target_section_table
*table
;
1423 secp
= target_section_by_addr (ops
, memaddr
);
1425 && (bfd_get_section_flags (secp
->bfd
, secp
->the_bfd_section
)
1428 table
= target_get_section_table (ops
);
1429 return section_table_xfer_memory_partial (readbuf
, writebuf
,
1432 table
->sections_end
,
1437 /* If reading unavailable memory in the context of traceframes, and
1438 this address falls within a read-only section, fallback to
1439 reading from live memory. */
1440 if (readbuf
!= NULL
&& get_traceframe_number () != -1)
1442 VEC(mem_range_s
) *available
;
1444 /* If we fail to get the set of available memory, then the
1445 target does not support querying traceframe info, and so we
1446 attempt reading from the traceframe anyway (assuming the
1447 target implements the old QTro packet then). */
1448 if (traceframe_available_memory (&available
, memaddr
, len
))
1450 struct cleanup
*old_chain
;
1452 old_chain
= make_cleanup (VEC_cleanup(mem_range_s
), &available
);
1454 if (VEC_empty (mem_range_s
, available
)
1455 || VEC_index (mem_range_s
, available
, 0)->start
!= memaddr
)
1457 /* Don't read into the traceframe's available
1459 if (!VEC_empty (mem_range_s
, available
))
1461 LONGEST oldlen
= len
;
1463 len
= VEC_index (mem_range_s
, available
, 0)->start
- memaddr
;
1464 gdb_assert (len
<= oldlen
);
1467 do_cleanups (old_chain
);
1469 /* This goes through the topmost target again. */
1470 res
= memory_xfer_live_readonly_partial (ops
, object
,
1471 readbuf
, memaddr
, len
);
1475 /* No use trying further, we know some memory starting
1476 at MEMADDR isn't available. */
1480 /* Don't try to read more than how much is available, in
1481 case the target implements the deprecated QTro packet to
1482 cater for older GDBs (the target's knowledge of read-only
1483 sections may be outdated by now). */
1484 len
= VEC_index (mem_range_s
, available
, 0)->length
;
1486 do_cleanups (old_chain
);
1490 /* Try GDB's internal data cache. */
1491 region
= lookup_mem_region (memaddr
);
1492 /* region->hi == 0 means there's no upper bound. */
1493 if (memaddr
+ len
< region
->hi
|| region
->hi
== 0)
1496 reg_len
= region
->hi
- memaddr
;
1498 switch (region
->attrib
.mode
)
1501 if (writebuf
!= NULL
)
1506 if (readbuf
!= NULL
)
1511 /* We only support writing to flash during "load" for now. */
1512 if (writebuf
!= NULL
)
1513 error (_("Writing to flash memory forbidden in this context"));
1520 if (!ptid_equal (inferior_ptid
, null_ptid
))
1521 inf
= find_inferior_pid (ptid_get_pid (inferior_ptid
));
1526 /* The dcache reads whole cache lines; that doesn't play well
1527 with reading from a trace buffer, because reading outside of
1528 the collected memory range fails. */
1529 && get_traceframe_number () == -1
1530 && (region
->attrib
.cache
1531 || (stack_cache_enabled_p
&& object
== TARGET_OBJECT_STACK_MEMORY
)))
1533 if (readbuf
!= NULL
)
1534 res
= dcache_xfer_memory (ops
, target_dcache
, memaddr
, readbuf
,
1537 /* FIXME drow/2006-08-09: If we're going to preserve const
1538 correctness dcache_xfer_memory should take readbuf and
1540 res
= dcache_xfer_memory (ops
, target_dcache
, memaddr
,
1547 if (readbuf
&& !show_memory_breakpoints
)
1548 breakpoint_restore_shadows (readbuf
, memaddr
, reg_len
);
1553 /* If none of those methods found the memory we wanted, fall back
1554 to a target partial transfer. Normally a single call to
1555 to_xfer_partial is enough; if it doesn't recognize an object
1556 it will call the to_xfer_partial of the next target down.
1557 But for memory this won't do. Memory is the only target
1558 object which can be read from more than one valid target.
1559 A core file, for instance, could have some of memory but
1560 delegate other bits to the target below it. So, we must
1561 manually try all targets. */
1565 res
= ops
->to_xfer_partial (ops
, TARGET_OBJECT_MEMORY
, NULL
,
1566 readbuf
, writebuf
, memaddr
, reg_len
);
1570 /* We want to continue past core files to executables, but not
1571 past a running target's memory. */
1572 if (ops
->to_has_all_memory (ops
))
1577 while (ops
!= NULL
);
1579 if (res
> 0 && readbuf
!= NULL
&& !show_memory_breakpoints
)
1580 breakpoint_restore_shadows (readbuf
, memaddr
, reg_len
);
1582 /* Make sure the cache gets updated no matter what - if we are writing
1583 to the stack. Even if this write is not tagged as such, we still need
1584 to update the cache. */
1589 && !region
->attrib
.cache
1590 && stack_cache_enabled_p
1591 && object
!= TARGET_OBJECT_STACK_MEMORY
)
1593 dcache_update (target_dcache
, memaddr
, (void *) writebuf
, res
);
1596 /* If we still haven't got anything, return the last error. We
1602 restore_show_memory_breakpoints (void *arg
)
1604 show_memory_breakpoints
= (uintptr_t) arg
;
1608 make_show_memory_breakpoints_cleanup (int show
)
1610 int current
= show_memory_breakpoints
;
1612 show_memory_breakpoints
= show
;
1613 return make_cleanup (restore_show_memory_breakpoints
,
1614 (void *) (uintptr_t) current
);
1617 /* For docs see target.h, to_xfer_partial. */
1620 target_xfer_partial (struct target_ops
*ops
,
1621 enum target_object object
, const char *annex
,
1622 void *readbuf
, const void *writebuf
,
1623 ULONGEST offset
, LONGEST len
)
1627 gdb_assert (ops
->to_xfer_partial
!= NULL
);
1629 if (writebuf
&& !may_write_memory
)
1630 error (_("Writing to memory is not allowed (addr %s, len %s)"),
1631 core_addr_to_string_nz (offset
), plongest (len
));
1633 /* If this is a memory transfer, let the memory-specific code
1634 have a look at it instead. Memory transfers are more
1636 if (object
== TARGET_OBJECT_MEMORY
|| object
== TARGET_OBJECT_STACK_MEMORY
)
1637 retval
= memory_xfer_partial (ops
, object
, readbuf
,
1638 writebuf
, offset
, len
);
1641 enum target_object raw_object
= object
;
1643 /* If this is a raw memory transfer, request the normal
1644 memory object from other layers. */
1645 if (raw_object
== TARGET_OBJECT_RAW_MEMORY
)
1646 raw_object
= TARGET_OBJECT_MEMORY
;
1648 retval
= ops
->to_xfer_partial (ops
, raw_object
, annex
, readbuf
,
1649 writebuf
, offset
, len
);
1654 const unsigned char *myaddr
= NULL
;
1656 fprintf_unfiltered (gdb_stdlog
,
1657 "%s:target_xfer_partial "
1658 "(%d, %s, %s, %s, %s, %s) = %s",
1661 (annex
? annex
: "(null)"),
1662 host_address_to_string (readbuf
),
1663 host_address_to_string (writebuf
),
1664 core_addr_to_string_nz (offset
),
1665 plongest (len
), plongest (retval
));
1671 if (retval
> 0 && myaddr
!= NULL
)
1675 fputs_unfiltered (", bytes =", gdb_stdlog
);
1676 for (i
= 0; i
< retval
; i
++)
1678 if ((((intptr_t) &(myaddr
[i
])) & 0xf) == 0)
1680 if (targetdebug
< 2 && i
> 0)
1682 fprintf_unfiltered (gdb_stdlog
, " ...");
1685 fprintf_unfiltered (gdb_stdlog
, "\n");
1688 fprintf_unfiltered (gdb_stdlog
, " %02x", myaddr
[i
] & 0xff);
1692 fputc_unfiltered ('\n', gdb_stdlog
);
1697 /* Read LEN bytes of target memory at address MEMADDR, placing the results in
1698 GDB's memory at MYADDR. Returns either 0 for success or an errno value
1699 if any error occurs.
1701 If an error occurs, no guarantee is made about the contents of the data at
1702 MYADDR. In particular, the caller should not depend upon partial reads
1703 filling the buffer with good data. There is no way for the caller to know
1704 how much good data might have been transfered anyway. Callers that can
1705 deal with partial reads should call target_read (which will retry until
1706 it makes no progress, and then return how much was transferred). */
1709 target_read_memory (CORE_ADDR memaddr
, gdb_byte
*myaddr
, int len
)
1711 /* Dispatch to the topmost target, not the flattened current_target.
1712 Memory accesses check target->to_has_(all_)memory, and the
1713 flattened target doesn't inherit those. */
1714 if (target_read (current_target
.beneath
, TARGET_OBJECT_MEMORY
, NULL
,
1715 myaddr
, memaddr
, len
) == len
)
1721 /* Like target_read_memory, but specify explicitly that this is a read from
1722 the target's stack. This may trigger different cache behavior. */
1725 target_read_stack (CORE_ADDR memaddr
, gdb_byte
*myaddr
, int len
)
1727 /* Dispatch to the topmost target, not the flattened current_target.
1728 Memory accesses check target->to_has_(all_)memory, and the
1729 flattened target doesn't inherit those. */
1731 if (target_read (current_target
.beneath
, TARGET_OBJECT_STACK_MEMORY
, NULL
,
1732 myaddr
, memaddr
, len
) == len
)
1738 /* Write LEN bytes from MYADDR to target memory at address MEMADDR.
1739 Returns either 0 for success or an errno value if any error occurs.
1740 If an error occurs, no guarantee is made about how much data got written.
1741 Callers that can deal with partial writes should call target_write. */
1744 target_write_memory (CORE_ADDR memaddr
, const gdb_byte
*myaddr
, int len
)
1746 /* Dispatch to the topmost target, not the flattened current_target.
1747 Memory accesses check target->to_has_(all_)memory, and the
1748 flattened target doesn't inherit those. */
1749 if (target_write (current_target
.beneath
, TARGET_OBJECT_MEMORY
, NULL
,
1750 myaddr
, memaddr
, len
) == len
)
1756 /* Fetch the target's memory map. */
1759 target_memory_map (void)
1761 VEC(mem_region_s
) *result
;
1762 struct mem_region
*last_one
, *this_one
;
1764 struct target_ops
*t
;
1767 fprintf_unfiltered (gdb_stdlog
, "target_memory_map ()\n");
1769 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
1770 if (t
->to_memory_map
!= NULL
)
1776 result
= t
->to_memory_map (t
);
1780 qsort (VEC_address (mem_region_s
, result
),
1781 VEC_length (mem_region_s
, result
),
1782 sizeof (struct mem_region
), mem_region_cmp
);
1784 /* Check that regions do not overlap. Simultaneously assign
1785 a numbering for the "mem" commands to use to refer to
1788 for (ix
= 0; VEC_iterate (mem_region_s
, result
, ix
, this_one
); ix
++)
1790 this_one
->number
= ix
;
1792 if (last_one
&& last_one
->hi
> this_one
->lo
)
1794 warning (_("Overlapping regions in memory map: ignoring"));
1795 VEC_free (mem_region_s
, result
);
1798 last_one
= this_one
;
1805 target_flash_erase (ULONGEST address
, LONGEST length
)
1807 struct target_ops
*t
;
1809 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
1810 if (t
->to_flash_erase
!= NULL
)
1813 fprintf_unfiltered (gdb_stdlog
, "target_flash_erase (%s, %s)\n",
1814 hex_string (address
), phex (length
, 0));
1815 t
->to_flash_erase (t
, address
, length
);
1823 target_flash_done (void)
1825 struct target_ops
*t
;
1827 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
1828 if (t
->to_flash_done
!= NULL
)
1831 fprintf_unfiltered (gdb_stdlog
, "target_flash_done\n");
1832 t
->to_flash_done (t
);
1840 show_trust_readonly (struct ui_file
*file
, int from_tty
,
1841 struct cmd_list_element
*c
, const char *value
)
1843 fprintf_filtered (file
,
1844 _("Mode for reading from readonly sections is %s.\n"),
1848 /* More generic transfers. */
1851 default_xfer_partial (struct target_ops
*ops
, enum target_object object
,
1852 const char *annex
, gdb_byte
*readbuf
,
1853 const gdb_byte
*writebuf
, ULONGEST offset
, LONGEST len
)
1855 if (object
== TARGET_OBJECT_MEMORY
1856 && ops
->deprecated_xfer_memory
!= NULL
)
1857 /* If available, fall back to the target's
1858 "deprecated_xfer_memory" method. */
1863 if (writebuf
!= NULL
)
1865 void *buffer
= xmalloc (len
);
1866 struct cleanup
*cleanup
= make_cleanup (xfree
, buffer
);
1868 memcpy (buffer
, writebuf
, len
);
1869 xfered
= ops
->deprecated_xfer_memory (offset
, buffer
, len
,
1870 1/*write*/, NULL
, ops
);
1871 do_cleanups (cleanup
);
1873 if (readbuf
!= NULL
)
1874 xfered
= ops
->deprecated_xfer_memory (offset
, readbuf
, len
,
1875 0/*read*/, NULL
, ops
);
1878 else if (xfered
== 0 && errno
== 0)
1879 /* "deprecated_xfer_memory" uses 0, cross checked against
1880 ERRNO as one indication of an error. */
1885 else if (ops
->beneath
!= NULL
)
1886 return ops
->beneath
->to_xfer_partial (ops
->beneath
, object
, annex
,
1887 readbuf
, writebuf
, offset
, len
);
1892 /* The xfer_partial handler for the topmost target. Unlike the default,
1893 it does not need to handle memory specially; it just passes all
1894 requests down the stack. */
1897 current_xfer_partial (struct target_ops
*ops
, enum target_object object
,
1898 const char *annex
, gdb_byte
*readbuf
,
1899 const gdb_byte
*writebuf
, ULONGEST offset
, LONGEST len
)
1901 if (ops
->beneath
!= NULL
)
1902 return ops
->beneath
->to_xfer_partial (ops
->beneath
, object
, annex
,
1903 readbuf
, writebuf
, offset
, len
);
1908 /* Target vector read/write partial wrapper functions. */
1911 target_read_partial (struct target_ops
*ops
,
1912 enum target_object object
,
1913 const char *annex
, gdb_byte
*buf
,
1914 ULONGEST offset
, LONGEST len
)
1916 return target_xfer_partial (ops
, object
, annex
, buf
, NULL
, offset
, len
);
1920 target_write_partial (struct target_ops
*ops
,
1921 enum target_object object
,
1922 const char *annex
, const gdb_byte
*buf
,
1923 ULONGEST offset
, LONGEST len
)
1925 return target_xfer_partial (ops
, object
, annex
, NULL
, buf
, offset
, len
);
1928 /* Wrappers to perform the full transfer. */
1930 /* For docs on target_read see target.h. */
1933 target_read (struct target_ops
*ops
,
1934 enum target_object object
,
1935 const char *annex
, gdb_byte
*buf
,
1936 ULONGEST offset
, LONGEST len
)
1940 while (xfered
< len
)
1942 LONGEST xfer
= target_read_partial (ops
, object
, annex
,
1943 (gdb_byte
*) buf
+ xfered
,
1944 offset
+ xfered
, len
- xfered
);
1946 /* Call an observer, notifying them of the xfer progress? */
1957 /* Assuming that the entire [begin, end) range of memory cannot be
1958 read, try to read whatever subrange is possible to read.
1960 The function returns, in RESULT, either zero or one memory block.
1961 If there's a readable subrange at the beginning, it is completely
1962 read and returned. Any further readable subrange will not be read.
1963 Otherwise, if there's a readable subrange at the end, it will be
1964 completely read and returned. Any readable subranges before it
1965 (obviously, not starting at the beginning), will be ignored. In
1966 other cases -- either no readable subrange, or readable subrange(s)
1967 that is neither at the beginning, or end, nothing is returned.
1969 The purpose of this function is to handle a read across a boundary
1970 of accessible memory in a case when memory map is not available.
1971 The above restrictions are fine for this case, but will give
1972 incorrect results if the memory is 'patchy'. However, supporting
1973 'patchy' memory would require trying to read every single byte,
1974 and it seems unacceptable solution. Explicit memory map is
1975 recommended for this case -- and target_read_memory_robust will
1976 take care of reading multiple ranges then. */
1979 read_whatever_is_readable (struct target_ops
*ops
,
1980 ULONGEST begin
, ULONGEST end
,
1981 VEC(memory_read_result_s
) **result
)
1983 gdb_byte
*buf
= xmalloc (end
- begin
);
1984 ULONGEST current_begin
= begin
;
1985 ULONGEST current_end
= end
;
1987 memory_read_result_s r
;
1989 /* If we previously failed to read 1 byte, nothing can be done here. */
1990 if (end
- begin
<= 1)
1996 /* Check that either first or the last byte is readable, and give up
1997 if not. This heuristic is meant to permit reading accessible memory
1998 at the boundary of accessible region. */
1999 if (target_read_partial (ops
, TARGET_OBJECT_MEMORY
, NULL
,
2000 buf
, begin
, 1) == 1)
2005 else if (target_read_partial (ops
, TARGET_OBJECT_MEMORY
, NULL
,
2006 buf
+ (end
-begin
) - 1, end
- 1, 1) == 1)
2017 /* Loop invariant is that the [current_begin, current_end) was previously
2018 found to be not readable as a whole.
2020 Note loop condition -- if the range has 1 byte, we can't divide the range
2021 so there's no point trying further. */
2022 while (current_end
- current_begin
> 1)
2024 ULONGEST first_half_begin
, first_half_end
;
2025 ULONGEST second_half_begin
, second_half_end
;
2027 ULONGEST middle
= current_begin
+ (current_end
- current_begin
)/2;
2031 first_half_begin
= current_begin
;
2032 first_half_end
= middle
;
2033 second_half_begin
= middle
;
2034 second_half_end
= current_end
;
2038 first_half_begin
= middle
;
2039 first_half_end
= current_end
;
2040 second_half_begin
= current_begin
;
2041 second_half_end
= middle
;
2044 xfer
= target_read (ops
, TARGET_OBJECT_MEMORY
, NULL
,
2045 buf
+ (first_half_begin
- begin
),
2047 first_half_end
- first_half_begin
);
2049 if (xfer
== first_half_end
- first_half_begin
)
2051 /* This half reads up fine. So, the error must be in the
2053 current_begin
= second_half_begin
;
2054 current_end
= second_half_end
;
2058 /* This half is not readable. Because we've tried one byte, we
2059 know some part of this half if actually redable. Go to the next
2060 iteration to divide again and try to read.
2062 We don't handle the other half, because this function only tries
2063 to read a single readable subrange. */
2064 current_begin
= first_half_begin
;
2065 current_end
= first_half_end
;
2071 /* The [begin, current_begin) range has been read. */
2073 r
.end
= current_begin
;
2078 /* The [current_end, end) range has been read. */
2079 LONGEST rlen
= end
- current_end
;
2081 r
.data
= xmalloc (rlen
);
2082 memcpy (r
.data
, buf
+ current_end
- begin
, rlen
);
2083 r
.begin
= current_end
;
2087 VEC_safe_push(memory_read_result_s
, (*result
), &r
);
2091 free_memory_read_result_vector (void *x
)
2093 VEC(memory_read_result_s
) *v
= x
;
2094 memory_read_result_s
*current
;
2097 for (ix
= 0; VEC_iterate (memory_read_result_s
, v
, ix
, current
); ++ix
)
2099 xfree (current
->data
);
2101 VEC_free (memory_read_result_s
, v
);
2104 VEC(memory_read_result_s
) *
2105 read_memory_robust (struct target_ops
*ops
, ULONGEST offset
, LONGEST len
)
2107 VEC(memory_read_result_s
) *result
= 0;
2110 while (xfered
< len
)
2112 struct mem_region
*region
= lookup_mem_region (offset
+ xfered
);
2115 /* If there is no explicit region, a fake one should be created. */
2116 gdb_assert (region
);
2118 if (region
->hi
== 0)
2119 rlen
= len
- xfered
;
2121 rlen
= region
->hi
- offset
;
2123 if (region
->attrib
.mode
== MEM_NONE
|| region
->attrib
.mode
== MEM_WO
)
2125 /* Cannot read this region. Note that we can end up here only
2126 if the region is explicitly marked inaccessible, or
2127 'inaccessible-by-default' is in effect. */
2132 LONGEST to_read
= min (len
- xfered
, rlen
);
2133 gdb_byte
*buffer
= (gdb_byte
*)xmalloc (to_read
);
2135 LONGEST xfer
= target_read (ops
, TARGET_OBJECT_MEMORY
, NULL
,
2136 (gdb_byte
*) buffer
,
2137 offset
+ xfered
, to_read
);
2138 /* Call an observer, notifying them of the xfer progress? */
2141 /* Got an error reading full chunk. See if maybe we can read
2144 read_whatever_is_readable (ops
, offset
+ xfered
,
2145 offset
+ xfered
+ to_read
, &result
);
2150 struct memory_read_result r
;
2152 r
.begin
= offset
+ xfered
;
2153 r
.end
= r
.begin
+ xfer
;
2154 VEC_safe_push (memory_read_result_s
, result
, &r
);
2164 /* An alternative to target_write with progress callbacks. */
2167 target_write_with_progress (struct target_ops
*ops
,
2168 enum target_object object
,
2169 const char *annex
, const gdb_byte
*buf
,
2170 ULONGEST offset
, LONGEST len
,
2171 void (*progress
) (ULONGEST
, void *), void *baton
)
2175 /* Give the progress callback a chance to set up. */
2177 (*progress
) (0, baton
);
2179 while (xfered
< len
)
2181 LONGEST xfer
= target_write_partial (ops
, object
, annex
,
2182 (gdb_byte
*) buf
+ xfered
,
2183 offset
+ xfered
, len
- xfered
);
2191 (*progress
) (xfer
, baton
);
2199 /* For docs on target_write see target.h. */
2202 target_write (struct target_ops
*ops
,
2203 enum target_object object
,
2204 const char *annex
, const gdb_byte
*buf
,
2205 ULONGEST offset
, LONGEST len
)
2207 return target_write_with_progress (ops
, object
, annex
, buf
, offset
, len
,
2211 /* Read OBJECT/ANNEX using OPS. Store the result in *BUF_P and return
2212 the size of the transferred data. PADDING additional bytes are
2213 available in *BUF_P. This is a helper function for
2214 target_read_alloc; see the declaration of that function for more
2218 target_read_alloc_1 (struct target_ops
*ops
, enum target_object object
,
2219 const char *annex
, gdb_byte
**buf_p
, int padding
)
2221 size_t buf_alloc
, buf_pos
;
2225 /* This function does not have a length parameter; it reads the
2226 entire OBJECT). Also, it doesn't support objects fetched partly
2227 from one target and partly from another (in a different stratum,
2228 e.g. a core file and an executable). Both reasons make it
2229 unsuitable for reading memory. */
2230 gdb_assert (object
!= TARGET_OBJECT_MEMORY
);
2232 /* Start by reading up to 4K at a time. The target will throttle
2233 this number down if necessary. */
2235 buf
= xmalloc (buf_alloc
);
2239 n
= target_read_partial (ops
, object
, annex
, &buf
[buf_pos
],
2240 buf_pos
, buf_alloc
- buf_pos
- padding
);
2243 /* An error occurred. */
2249 /* Read all there was. */
2259 /* If the buffer is filling up, expand it. */
2260 if (buf_alloc
< buf_pos
* 2)
2263 buf
= xrealloc (buf
, buf_alloc
);
2270 /* Read OBJECT/ANNEX using OPS. Store the result in *BUF_P and return
2271 the size of the transferred data. See the declaration in "target.h"
2272 function for more information about the return value. */
2275 target_read_alloc (struct target_ops
*ops
, enum target_object object
,
2276 const char *annex
, gdb_byte
**buf_p
)
2278 return target_read_alloc_1 (ops
, object
, annex
, buf_p
, 0);
2281 /* Read OBJECT/ANNEX using OPS. The result is NUL-terminated and
2282 returned as a string, allocated using xmalloc. If an error occurs
2283 or the transfer is unsupported, NULL is returned. Empty objects
2284 are returned as allocated but empty strings. A warning is issued
2285 if the result contains any embedded NUL bytes. */
2288 target_read_stralloc (struct target_ops
*ops
, enum target_object object
,
2292 LONGEST transferred
;
2294 transferred
= target_read_alloc_1 (ops
, object
, annex
, &buffer
, 1);
2296 if (transferred
< 0)
2299 if (transferred
== 0)
2300 return xstrdup ("");
2302 buffer
[transferred
] = 0;
2303 if (strlen (buffer
) < transferred
)
2304 warning (_("target object %d, annex %s, "
2305 "contained unexpected null characters"),
2306 (int) object
, annex
? annex
: "(none)");
2308 return (char *) buffer
;
2311 /* Memory transfer methods. */
2314 get_target_memory (struct target_ops
*ops
, CORE_ADDR addr
, gdb_byte
*buf
,
2317 /* This method is used to read from an alternate, non-current
2318 target. This read must bypass the overlay support (as symbols
2319 don't match this target), and GDB's internal cache (wrong cache
2320 for this target). */
2321 if (target_read (ops
, TARGET_OBJECT_RAW_MEMORY
, NULL
, buf
, addr
, len
)
2323 memory_error (EIO
, addr
);
2327 get_target_memory_unsigned (struct target_ops
*ops
, CORE_ADDR addr
,
2328 int len
, enum bfd_endian byte_order
)
2330 gdb_byte buf
[sizeof (ULONGEST
)];
2332 gdb_assert (len
<= sizeof (buf
));
2333 get_target_memory (ops
, addr
, buf
, len
);
2334 return extract_unsigned_integer (buf
, len
, byte_order
);
2338 target_insert_breakpoint (struct gdbarch
*gdbarch
,
2339 struct bp_target_info
*bp_tgt
)
2341 if (!may_insert_breakpoints
)
2343 warning (_("May not insert breakpoints"));
2347 return (*current_target
.to_insert_breakpoint
) (gdbarch
, bp_tgt
);
2351 target_remove_breakpoint (struct gdbarch
*gdbarch
,
2352 struct bp_target_info
*bp_tgt
)
2354 /* This is kind of a weird case to handle, but the permission might
2355 have been changed after breakpoints were inserted - in which case
2356 we should just take the user literally and assume that any
2357 breakpoints should be left in place. */
2358 if (!may_insert_breakpoints
)
2360 warning (_("May not remove breakpoints"));
2364 return (*current_target
.to_remove_breakpoint
) (gdbarch
, bp_tgt
);
2368 target_info (char *args
, int from_tty
)
2370 struct target_ops
*t
;
2371 int has_all_mem
= 0;
2373 if (symfile_objfile
!= NULL
)
2374 printf_unfiltered (_("Symbols from \"%s\".\n"), symfile_objfile
->name
);
2376 for (t
= target_stack
; t
!= NULL
; t
= t
->beneath
)
2378 if (!(*t
->to_has_memory
) (t
))
2381 if ((int) (t
->to_stratum
) <= (int) dummy_stratum
)
2384 printf_unfiltered (_("\tWhile running this, "
2385 "GDB does not access memory from...\n"));
2386 printf_unfiltered ("%s:\n", t
->to_longname
);
2387 (t
->to_files_info
) (t
);
2388 has_all_mem
= (*t
->to_has_all_memory
) (t
);
2392 /* This function is called before any new inferior is created, e.g.
2393 by running a program, attaching, or connecting to a target.
2394 It cleans up any state from previous invocations which might
2395 change between runs. This is a subset of what target_preopen
2396 resets (things which might change between targets). */
2399 target_pre_inferior (int from_tty
)
2401 /* Clear out solib state. Otherwise the solib state of the previous
2402 inferior might have survived and is entirely wrong for the new
2403 target. This has been observed on GNU/Linux using glibc 2.3. How
2415 Cannot access memory at address 0xdeadbeef
2418 /* In some OSs, the shared library list is the same/global/shared
2419 across inferiors. If code is shared between processes, so are
2420 memory regions and features. */
2421 if (!gdbarch_has_global_solist (target_gdbarch
))
2423 no_shared_libraries (NULL
, from_tty
);
2425 invalidate_target_mem_regions ();
2427 target_clear_description ();
2431 /* Callback for iterate_over_inferiors. Gets rid of the given
2435 dispose_inferior (struct inferior
*inf
, void *args
)
2437 struct thread_info
*thread
;
2439 thread
= any_thread_of_process (inf
->pid
);
2442 switch_to_thread (thread
->ptid
);
2444 /* Core inferiors actually should be detached, not killed. */
2445 if (target_has_execution
)
2448 target_detach (NULL
, 0);
2454 /* This is to be called by the open routine before it does
2458 target_preopen (int from_tty
)
2462 if (have_inferiors ())
2465 || !have_live_inferiors ()
2466 || query (_("A program is being debugged already. Kill it? ")))
2467 iterate_over_inferiors (dispose_inferior
, NULL
);
2469 error (_("Program not killed."));
2472 /* Calling target_kill may remove the target from the stack. But if
2473 it doesn't (which seems like a win for UDI), remove it now. */
2474 /* Leave the exec target, though. The user may be switching from a
2475 live process to a core of the same program. */
2476 pop_all_targets_above (file_stratum
, 0);
2478 target_pre_inferior (from_tty
);
2481 /* Detach a target after doing deferred register stores. */
2484 target_detach (char *args
, int from_tty
)
2486 struct target_ops
* t
;
2488 if (gdbarch_has_global_breakpoints (target_gdbarch
))
2489 /* Don't remove global breakpoints here. They're removed on
2490 disconnection from the target. */
2493 /* If we're in breakpoints-always-inserted mode, have to remove
2494 them before detaching. */
2495 remove_breakpoints_pid (PIDGET (inferior_ptid
));
2497 prepare_for_detach ();
2499 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
2501 if (t
->to_detach
!= NULL
)
2503 t
->to_detach (t
, args
, from_tty
);
2505 fprintf_unfiltered (gdb_stdlog
, "target_detach (%s, %d)\n",
2511 internal_error (__FILE__
, __LINE__
, _("could not find a target to detach"));
2515 target_disconnect (char *args
, int from_tty
)
2517 struct target_ops
*t
;
2519 /* If we're in breakpoints-always-inserted mode or if breakpoints
2520 are global across processes, we have to remove them before
2522 remove_breakpoints ();
2524 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
2525 if (t
->to_disconnect
!= NULL
)
2528 fprintf_unfiltered (gdb_stdlog
, "target_disconnect (%s, %d)\n",
2530 t
->to_disconnect (t
, args
, from_tty
);
2538 target_wait (ptid_t ptid
, struct target_waitstatus
*status
, int options
)
2540 struct target_ops
*t
;
2542 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
2544 if (t
->to_wait
!= NULL
)
2546 ptid_t retval
= (*t
->to_wait
) (t
, ptid
, status
, options
);
2550 char *status_string
;
2552 status_string
= target_waitstatus_to_string (status
);
2553 fprintf_unfiltered (gdb_stdlog
,
2554 "target_wait (%d, status) = %d, %s\n",
2555 PIDGET (ptid
), PIDGET (retval
),
2557 xfree (status_string
);
2568 target_pid_to_str (ptid_t ptid
)
2570 struct target_ops
*t
;
2572 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
2574 if (t
->to_pid_to_str
!= NULL
)
2575 return (*t
->to_pid_to_str
) (t
, ptid
);
2578 return normal_pid_to_str (ptid
);
2582 target_thread_name (struct thread_info
*info
)
2584 struct target_ops
*t
;
2586 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
2588 if (t
->to_thread_name
!= NULL
)
2589 return (*t
->to_thread_name
) (info
);
2596 target_resume (ptid_t ptid
, int step
, enum target_signal signal
)
2598 struct target_ops
*t
;
2600 target_dcache_invalidate ();
2602 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
2604 if (t
->to_resume
!= NULL
)
2606 t
->to_resume (t
, ptid
, step
, signal
);
2608 fprintf_unfiltered (gdb_stdlog
, "target_resume (%d, %s, %s)\n",
2610 step
? "step" : "continue",
2611 target_signal_to_name (signal
));
2613 registers_changed_ptid (ptid
);
2614 set_executing (ptid
, 1);
2615 set_running (ptid
, 1);
2616 clear_inline_frame_state (ptid
);
2625 target_pass_signals (int numsigs
, unsigned char *pass_signals
)
2627 struct target_ops
*t
;
2629 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
2631 if (t
->to_pass_signals
!= NULL
)
2637 fprintf_unfiltered (gdb_stdlog
, "target_pass_signals (%d, {",
2640 for (i
= 0; i
< numsigs
; i
++)
2641 if (pass_signals
[i
])
2642 fprintf_unfiltered (gdb_stdlog
, " %s",
2643 target_signal_to_name (i
));
2645 fprintf_unfiltered (gdb_stdlog
, " })\n");
2648 (*t
->to_pass_signals
) (numsigs
, pass_signals
);
2654 /* Look through the list of possible targets for a target that can
2658 target_follow_fork (int follow_child
)
2660 struct target_ops
*t
;
2662 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
2664 if (t
->to_follow_fork
!= NULL
)
2666 int retval
= t
->to_follow_fork (t
, follow_child
);
2669 fprintf_unfiltered (gdb_stdlog
, "target_follow_fork (%d) = %d\n",
2670 follow_child
, retval
);
2675 /* Some target returned a fork event, but did not know how to follow it. */
2676 internal_error (__FILE__
, __LINE__
,
2677 _("could not find a target to follow fork"));
2681 target_mourn_inferior (void)
2683 struct target_ops
*t
;
2685 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
2687 if (t
->to_mourn_inferior
!= NULL
)
2689 t
->to_mourn_inferior (t
);
2691 fprintf_unfiltered (gdb_stdlog
, "target_mourn_inferior ()\n");
2693 /* We no longer need to keep handles on any of the object files.
2694 Make sure to release them to avoid unnecessarily locking any
2695 of them while we're not actually debugging. */
2696 bfd_cache_close_all ();
2702 internal_error (__FILE__
, __LINE__
,
2703 _("could not find a target to follow mourn inferior"));
2706 /* Look for a target which can describe architectural features, starting
2707 from TARGET. If we find one, return its description. */
2709 const struct target_desc
*
2710 target_read_description (struct target_ops
*target
)
2712 struct target_ops
*t
;
2714 for (t
= target
; t
!= NULL
; t
= t
->beneath
)
2715 if (t
->to_read_description
!= NULL
)
2717 const struct target_desc
*tdesc
;
2719 tdesc
= t
->to_read_description (t
);
2727 /* The default implementation of to_search_memory.
2728 This implements a basic search of memory, reading target memory and
2729 performing the search here (as opposed to performing the search in on the
2730 target side with, for example, gdbserver). */
2733 simple_search_memory (struct target_ops
*ops
,
2734 CORE_ADDR start_addr
, ULONGEST search_space_len
,
2735 const gdb_byte
*pattern
, ULONGEST pattern_len
,
2736 CORE_ADDR
*found_addrp
)
2738 /* NOTE: also defined in find.c testcase. */
2739 #define SEARCH_CHUNK_SIZE 16000
2740 const unsigned chunk_size
= SEARCH_CHUNK_SIZE
;
2741 /* Buffer to hold memory contents for searching. */
2742 gdb_byte
*search_buf
;
2743 unsigned search_buf_size
;
2744 struct cleanup
*old_cleanups
;
2746 search_buf_size
= chunk_size
+ pattern_len
- 1;
2748 /* No point in trying to allocate a buffer larger than the search space. */
2749 if (search_space_len
< search_buf_size
)
2750 search_buf_size
= search_space_len
;
2752 search_buf
= malloc (search_buf_size
);
2753 if (search_buf
== NULL
)
2754 error (_("Unable to allocate memory to perform the search."));
2755 old_cleanups
= make_cleanup (free_current_contents
, &search_buf
);
2757 /* Prime the search buffer. */
2759 if (target_read (ops
, TARGET_OBJECT_MEMORY
, NULL
,
2760 search_buf
, start_addr
, search_buf_size
) != search_buf_size
)
2762 warning (_("Unable to access target memory at %s, halting search."),
2763 hex_string (start_addr
));
2764 do_cleanups (old_cleanups
);
2768 /* Perform the search.
2770 The loop is kept simple by allocating [N + pattern-length - 1] bytes.
2771 When we've scanned N bytes we copy the trailing bytes to the start and
2772 read in another N bytes. */
2774 while (search_space_len
>= pattern_len
)
2776 gdb_byte
*found_ptr
;
2777 unsigned nr_search_bytes
= min (search_space_len
, search_buf_size
);
2779 found_ptr
= memmem (search_buf
, nr_search_bytes
,
2780 pattern
, pattern_len
);
2782 if (found_ptr
!= NULL
)
2784 CORE_ADDR found_addr
= start_addr
+ (found_ptr
- search_buf
);
2786 *found_addrp
= found_addr
;
2787 do_cleanups (old_cleanups
);
2791 /* Not found in this chunk, skip to next chunk. */
2793 /* Don't let search_space_len wrap here, it's unsigned. */
2794 if (search_space_len
>= chunk_size
)
2795 search_space_len
-= chunk_size
;
2797 search_space_len
= 0;
2799 if (search_space_len
>= pattern_len
)
2801 unsigned keep_len
= search_buf_size
- chunk_size
;
2802 CORE_ADDR read_addr
= start_addr
+ chunk_size
+ keep_len
;
2805 /* Copy the trailing part of the previous iteration to the front
2806 of the buffer for the next iteration. */
2807 gdb_assert (keep_len
== pattern_len
- 1);
2808 memcpy (search_buf
, search_buf
+ chunk_size
, keep_len
);
2810 nr_to_read
= min (search_space_len
- keep_len
, chunk_size
);
2812 if (target_read (ops
, TARGET_OBJECT_MEMORY
, NULL
,
2813 search_buf
+ keep_len
, read_addr
,
2814 nr_to_read
) != nr_to_read
)
2816 warning (_("Unable to access target "
2817 "memory at %s, halting search."),
2818 hex_string (read_addr
));
2819 do_cleanups (old_cleanups
);
2823 start_addr
+= chunk_size
;
2829 do_cleanups (old_cleanups
);
2833 /* Search SEARCH_SPACE_LEN bytes beginning at START_ADDR for the
2834 sequence of bytes in PATTERN with length PATTERN_LEN.
2836 The result is 1 if found, 0 if not found, and -1 if there was an error
2837 requiring halting of the search (e.g. memory read error).
2838 If the pattern is found the address is recorded in FOUND_ADDRP. */
2841 target_search_memory (CORE_ADDR start_addr
, ULONGEST search_space_len
,
2842 const gdb_byte
*pattern
, ULONGEST pattern_len
,
2843 CORE_ADDR
*found_addrp
)
2845 struct target_ops
*t
;
2848 /* We don't use INHERIT to set current_target.to_search_memory,
2849 so we have to scan the target stack and handle targetdebug
2853 fprintf_unfiltered (gdb_stdlog
, "target_search_memory (%s, ...)\n",
2854 hex_string (start_addr
));
2856 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
2857 if (t
->to_search_memory
!= NULL
)
2862 found
= t
->to_search_memory (t
, start_addr
, search_space_len
,
2863 pattern
, pattern_len
, found_addrp
);
2867 /* If a special version of to_search_memory isn't available, use the
2869 found
= simple_search_memory (current_target
.beneath
,
2870 start_addr
, search_space_len
,
2871 pattern
, pattern_len
, found_addrp
);
2875 fprintf_unfiltered (gdb_stdlog
, " = %d\n", found
);
2880 /* Look through the currently pushed targets. If none of them will
2881 be able to restart the currently running process, issue an error
2885 target_require_runnable (void)
2887 struct target_ops
*t
;
2889 for (t
= target_stack
; t
!= NULL
; t
= t
->beneath
)
2891 /* If this target knows how to create a new program, then
2892 assume we will still be able to after killing the current
2893 one. Either killing and mourning will not pop T, or else
2894 find_default_run_target will find it again. */
2895 if (t
->to_create_inferior
!= NULL
)
2898 /* Do not worry about thread_stratum targets that can not
2899 create inferiors. Assume they will be pushed again if
2900 necessary, and continue to the process_stratum. */
2901 if (t
->to_stratum
== thread_stratum
2902 || t
->to_stratum
== arch_stratum
)
2905 error (_("The \"%s\" target does not support \"run\". "
2906 "Try \"help target\" or \"continue\"."),
2910 /* This function is only called if the target is running. In that
2911 case there should have been a process_stratum target and it
2912 should either know how to create inferiors, or not... */
2913 internal_error (__FILE__
, __LINE__
, _("No targets found"));
2916 /* Look through the list of possible targets for a target that can
2917 execute a run or attach command without any other data. This is
2918 used to locate the default process stratum.
2920 If DO_MESG is not NULL, the result is always valid (error() is
2921 called for errors); else, return NULL on error. */
2923 static struct target_ops
*
2924 find_default_run_target (char *do_mesg
)
2926 struct target_ops
**t
;
2927 struct target_ops
*runable
= NULL
;
2932 for (t
= target_structs
; t
< target_structs
+ target_struct_size
;
2935 if ((*t
)->to_can_run
&& target_can_run (*t
))
2945 error (_("Don't know how to %s. Try \"help target\"."), do_mesg
);
2954 find_default_attach (struct target_ops
*ops
, char *args
, int from_tty
)
2956 struct target_ops
*t
;
2958 t
= find_default_run_target ("attach");
2959 (t
->to_attach
) (t
, args
, from_tty
);
2964 find_default_create_inferior (struct target_ops
*ops
,
2965 char *exec_file
, char *allargs
, char **env
,
2968 struct target_ops
*t
;
2970 t
= find_default_run_target ("run");
2971 (t
->to_create_inferior
) (t
, exec_file
, allargs
, env
, from_tty
);
2976 find_default_can_async_p (void)
2978 struct target_ops
*t
;
2980 /* This may be called before the target is pushed on the stack;
2981 look for the default process stratum. If there's none, gdb isn't
2982 configured with a native debugger, and target remote isn't
2984 t
= find_default_run_target (NULL
);
2985 if (t
&& t
->to_can_async_p
)
2986 return (t
->to_can_async_p
) ();
2991 find_default_is_async_p (void)
2993 struct target_ops
*t
;
2995 /* This may be called before the target is pushed on the stack;
2996 look for the default process stratum. If there's none, gdb isn't
2997 configured with a native debugger, and target remote isn't
2999 t
= find_default_run_target (NULL
);
3000 if (t
&& t
->to_is_async_p
)
3001 return (t
->to_is_async_p
) ();
3006 find_default_supports_non_stop (void)
3008 struct target_ops
*t
;
3010 t
= find_default_run_target (NULL
);
3011 if (t
&& t
->to_supports_non_stop
)
3012 return (t
->to_supports_non_stop
) ();
3017 target_supports_non_stop (void)
3019 struct target_ops
*t
;
3021 for (t
= ¤t_target
; t
!= NULL
; t
= t
->beneath
)
3022 if (t
->to_supports_non_stop
)
3023 return t
->to_supports_non_stop ();
3029 find_default_supports_disable_randomization (void)
3031 struct target_ops
*t
;
3033 t
= find_default_run_target (NULL
);
3034 if (t
&& t
->to_supports_disable_randomization
)
3035 return (t
->to_supports_disable_randomization
) ();
3040 target_supports_disable_randomization (void)
3042 struct target_ops
*t
;
3044 for (t
= ¤t_target
; t
!= NULL
; t
= t
->beneath
)
3045 if (t
->to_supports_disable_randomization
)
3046 return t
->to_supports_disable_randomization ();
3052 target_get_osdata (const char *type
)
3054 struct target_ops
*t
;
3056 /* If we're already connected to something that can get us OS
3057 related data, use it. Otherwise, try using the native
3059 if (current_target
.to_stratum
>= process_stratum
)
3060 t
= current_target
.beneath
;
3062 t
= find_default_run_target ("get OS data");
3067 return target_read_stralloc (t
, TARGET_OBJECT_OSDATA
, type
);
3070 /* Determine the current address space of thread PTID. */
3072 struct address_space
*
3073 target_thread_address_space (ptid_t ptid
)
3075 struct address_space
*aspace
;
3076 struct inferior
*inf
;
3077 struct target_ops
*t
;
3079 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
3081 if (t
->to_thread_address_space
!= NULL
)
3083 aspace
= t
->to_thread_address_space (t
, ptid
);
3084 gdb_assert (aspace
);
3087 fprintf_unfiltered (gdb_stdlog
,
3088 "target_thread_address_space (%s) = %d\n",
3089 target_pid_to_str (ptid
),
3090 address_space_num (aspace
));
3095 /* Fall-back to the "main" address space of the inferior. */
3096 inf
= find_inferior_pid (ptid_get_pid (ptid
));
3098 if (inf
== NULL
|| inf
->aspace
== NULL
)
3099 internal_error (__FILE__
, __LINE__
,
3100 _("Can't determine the current "
3101 "address space of thread %s\n"),
3102 target_pid_to_str (ptid
));
3108 default_region_ok_for_hw_watchpoint (CORE_ADDR addr
, int len
)
3110 return (len
<= gdbarch_ptr_bit (target_gdbarch
) / TARGET_CHAR_BIT
);
3114 default_watchpoint_addr_within_range (struct target_ops
*target
,
3116 CORE_ADDR start
, int length
)
3118 return addr
>= start
&& addr
< start
+ length
;
3121 static struct gdbarch
*
3122 default_thread_architecture (struct target_ops
*ops
, ptid_t ptid
)
3124 return target_gdbarch
;
3140 return_minus_one (void)
3145 /* Find a single runnable target in the stack and return it. If for
3146 some reason there is more than one, return NULL. */
3149 find_run_target (void)
3151 struct target_ops
**t
;
3152 struct target_ops
*runable
= NULL
;
3157 for (t
= target_structs
; t
< target_structs
+ target_struct_size
; ++t
)
3159 if ((*t
)->to_can_run
&& target_can_run (*t
))
3166 return (count
== 1 ? runable
: NULL
);
3170 * Find the next target down the stack from the specified target.
3174 find_target_beneath (struct target_ops
*t
)
3180 /* The inferior process has died. Long live the inferior! */
3183 generic_mourn_inferior (void)
3187 ptid
= inferior_ptid
;
3188 inferior_ptid
= null_ptid
;
3190 if (!ptid_equal (ptid
, null_ptid
))
3192 int pid
= ptid_get_pid (ptid
);
3193 exit_inferior (pid
);
3196 breakpoint_init_inferior (inf_exited
);
3197 registers_changed ();
3199 reopen_exec_file ();
3200 reinit_frame_cache ();
3202 if (deprecated_detach_hook
)
3203 deprecated_detach_hook ();
3206 /* Helper function for child_wait and the derivatives of child_wait.
3207 HOSTSTATUS is the waitstatus from wait() or the equivalent; store our
3208 translation of that in OURSTATUS. */
3210 store_waitstatus (struct target_waitstatus
*ourstatus
, int hoststatus
)
3212 if (WIFEXITED (hoststatus
))
3214 ourstatus
->kind
= TARGET_WAITKIND_EXITED
;
3215 ourstatus
->value
.integer
= WEXITSTATUS (hoststatus
);
3217 else if (!WIFSTOPPED (hoststatus
))
3219 ourstatus
->kind
= TARGET_WAITKIND_SIGNALLED
;
3220 ourstatus
->value
.sig
= target_signal_from_host (WTERMSIG (hoststatus
));
3224 ourstatus
->kind
= TARGET_WAITKIND_STOPPED
;
3225 ourstatus
->value
.sig
= target_signal_from_host (WSTOPSIG (hoststatus
));
3229 /* Convert a normal process ID to a string. Returns the string in a
3233 normal_pid_to_str (ptid_t ptid
)
3235 static char buf
[32];
3237 xsnprintf (buf
, sizeof buf
, "process %d", ptid_get_pid (ptid
));
3242 dummy_pid_to_str (struct target_ops
*ops
, ptid_t ptid
)
3244 return normal_pid_to_str (ptid
);
3247 /* Error-catcher for target_find_memory_regions. */
3249 dummy_find_memory_regions (find_memory_region_ftype ignore1
, void *ignore2
)
3251 error (_("Command not implemented for this target."));
3255 /* Error-catcher for target_make_corefile_notes. */
3257 dummy_make_corefile_notes (bfd
*ignore1
, int *ignore2
)
3259 error (_("Command not implemented for this target."));
3263 /* Error-catcher for target_get_bookmark. */
3265 dummy_get_bookmark (char *ignore1
, int ignore2
)
3271 /* Error-catcher for target_goto_bookmark. */
3273 dummy_goto_bookmark (gdb_byte
*ignore
, int from_tty
)
3278 /* Set up the handful of non-empty slots needed by the dummy target
3282 init_dummy_target (void)
3284 dummy_target
.to_shortname
= "None";
3285 dummy_target
.to_longname
= "None";
3286 dummy_target
.to_doc
= "";
3287 dummy_target
.to_attach
= find_default_attach
;
3288 dummy_target
.to_detach
=
3289 (void (*)(struct target_ops
*, char *, int))target_ignore
;
3290 dummy_target
.to_create_inferior
= find_default_create_inferior
;
3291 dummy_target
.to_can_async_p
= find_default_can_async_p
;
3292 dummy_target
.to_is_async_p
= find_default_is_async_p
;
3293 dummy_target
.to_supports_non_stop
= find_default_supports_non_stop
;
3294 dummy_target
.to_supports_disable_randomization
3295 = find_default_supports_disable_randomization
;
3296 dummy_target
.to_pid_to_str
= dummy_pid_to_str
;
3297 dummy_target
.to_stratum
= dummy_stratum
;
3298 dummy_target
.to_find_memory_regions
= dummy_find_memory_regions
;
3299 dummy_target
.to_make_corefile_notes
= dummy_make_corefile_notes
;
3300 dummy_target
.to_get_bookmark
= dummy_get_bookmark
;
3301 dummy_target
.to_goto_bookmark
= dummy_goto_bookmark
;
3302 dummy_target
.to_xfer_partial
= default_xfer_partial
;
3303 dummy_target
.to_has_all_memory
= (int (*) (struct target_ops
*)) return_zero
;
3304 dummy_target
.to_has_memory
= (int (*) (struct target_ops
*)) return_zero
;
3305 dummy_target
.to_has_stack
= (int (*) (struct target_ops
*)) return_zero
;
3306 dummy_target
.to_has_registers
= (int (*) (struct target_ops
*)) return_zero
;
3307 dummy_target
.to_has_execution
3308 = (int (*) (struct target_ops
*, ptid_t
)) return_zero
;
3309 dummy_target
.to_stopped_by_watchpoint
= return_zero
;
3310 dummy_target
.to_stopped_data_address
=
3311 (int (*) (struct target_ops
*, CORE_ADDR
*)) return_zero
;
3312 dummy_target
.to_magic
= OPS_MAGIC
;
3316 debug_to_open (char *args
, int from_tty
)
3318 debug_target
.to_open (args
, from_tty
);
3320 fprintf_unfiltered (gdb_stdlog
, "target_open (%s, %d)\n", args
, from_tty
);
3324 target_close (struct target_ops
*targ
, int quitting
)
3326 if (targ
->to_xclose
!= NULL
)
3327 targ
->to_xclose (targ
, quitting
);
3328 else if (targ
->to_close
!= NULL
)
3329 targ
->to_close (quitting
);
3332 fprintf_unfiltered (gdb_stdlog
, "target_close (%d)\n", quitting
);
3336 target_attach (char *args
, int from_tty
)
3338 struct target_ops
*t
;
3340 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
3342 if (t
->to_attach
!= NULL
)
3344 t
->to_attach (t
, args
, from_tty
);
3346 fprintf_unfiltered (gdb_stdlog
, "target_attach (%s, %d)\n",
3352 internal_error (__FILE__
, __LINE__
,
3353 _("could not find a target to attach"));
3357 target_thread_alive (ptid_t ptid
)
3359 struct target_ops
*t
;
3361 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
3363 if (t
->to_thread_alive
!= NULL
)
3367 retval
= t
->to_thread_alive (t
, ptid
);
3369 fprintf_unfiltered (gdb_stdlog
, "target_thread_alive (%d) = %d\n",
3370 PIDGET (ptid
), retval
);
3380 target_find_new_threads (void)
3382 struct target_ops
*t
;
3384 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
3386 if (t
->to_find_new_threads
!= NULL
)
3388 t
->to_find_new_threads (t
);
3390 fprintf_unfiltered (gdb_stdlog
, "target_find_new_threads ()\n");
3398 target_stop (ptid_t ptid
)
3402 warning (_("May not interrupt or stop the target, ignoring attempt"));
3406 (*current_target
.to_stop
) (ptid
);
3410 debug_to_post_attach (int pid
)
3412 debug_target
.to_post_attach (pid
);
3414 fprintf_unfiltered (gdb_stdlog
, "target_post_attach (%d)\n", pid
);
3417 /* Return a pretty printed form of target_waitstatus.
3418 Space for the result is malloc'd, caller must free. */
3421 target_waitstatus_to_string (const struct target_waitstatus
*ws
)
3423 const char *kind_str
= "status->kind = ";
3427 case TARGET_WAITKIND_EXITED
:
3428 return xstrprintf ("%sexited, status = %d",
3429 kind_str
, ws
->value
.integer
);
3430 case TARGET_WAITKIND_STOPPED
:
3431 return xstrprintf ("%sstopped, signal = %s",
3432 kind_str
, target_signal_to_name (ws
->value
.sig
));
3433 case TARGET_WAITKIND_SIGNALLED
:
3434 return xstrprintf ("%ssignalled, signal = %s",
3435 kind_str
, target_signal_to_name (ws
->value
.sig
));
3436 case TARGET_WAITKIND_LOADED
:
3437 return xstrprintf ("%sloaded", kind_str
);
3438 case TARGET_WAITKIND_FORKED
:
3439 return xstrprintf ("%sforked", kind_str
);
3440 case TARGET_WAITKIND_VFORKED
:
3441 return xstrprintf ("%svforked", kind_str
);
3442 case TARGET_WAITKIND_EXECD
:
3443 return xstrprintf ("%sexecd", kind_str
);
3444 case TARGET_WAITKIND_SYSCALL_ENTRY
:
3445 return xstrprintf ("%sentered syscall", kind_str
);
3446 case TARGET_WAITKIND_SYSCALL_RETURN
:
3447 return xstrprintf ("%sexited syscall", kind_str
);
3448 case TARGET_WAITKIND_SPURIOUS
:
3449 return xstrprintf ("%sspurious", kind_str
);
3450 case TARGET_WAITKIND_IGNORE
:
3451 return xstrprintf ("%signore", kind_str
);
3452 case TARGET_WAITKIND_NO_HISTORY
:
3453 return xstrprintf ("%sno-history", kind_str
);
3454 case TARGET_WAITKIND_NO_RESUMED
:
3455 return xstrprintf ("%sno-resumed", kind_str
);
3457 return xstrprintf ("%sunknown???", kind_str
);
3462 debug_print_register (const char * func
,
3463 struct regcache
*regcache
, int regno
)
3465 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
3467 fprintf_unfiltered (gdb_stdlog
, "%s ", func
);
3468 if (regno
>= 0 && regno
< gdbarch_num_regs (gdbarch
)
3469 && gdbarch_register_name (gdbarch
, regno
) != NULL
3470 && gdbarch_register_name (gdbarch
, regno
)[0] != '\0')
3471 fprintf_unfiltered (gdb_stdlog
, "(%s)",
3472 gdbarch_register_name (gdbarch
, regno
));
3474 fprintf_unfiltered (gdb_stdlog
, "(%d)", regno
);
3475 if (regno
>= 0 && regno
< gdbarch_num_regs (gdbarch
))
3477 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
3478 int i
, size
= register_size (gdbarch
, regno
);
3479 unsigned char buf
[MAX_REGISTER_SIZE
];
3481 regcache_raw_collect (regcache
, regno
, buf
);
3482 fprintf_unfiltered (gdb_stdlog
, " = ");
3483 for (i
= 0; i
< size
; i
++)
3485 fprintf_unfiltered (gdb_stdlog
, "%02x", buf
[i
]);
3487 if (size
<= sizeof (LONGEST
))
3489 ULONGEST val
= extract_unsigned_integer (buf
, size
, byte_order
);
3491 fprintf_unfiltered (gdb_stdlog
, " %s %s",
3492 core_addr_to_string_nz (val
), plongest (val
));
3495 fprintf_unfiltered (gdb_stdlog
, "\n");
3499 target_fetch_registers (struct regcache
*regcache
, int regno
)
3501 struct target_ops
*t
;
3503 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
3505 if (t
->to_fetch_registers
!= NULL
)
3507 t
->to_fetch_registers (t
, regcache
, regno
);
3509 debug_print_register ("target_fetch_registers", regcache
, regno
);
3516 target_store_registers (struct regcache
*regcache
, int regno
)
3518 struct target_ops
*t
;
3520 if (!may_write_registers
)
3521 error (_("Writing to registers is not allowed (regno %d)"), regno
);
3523 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
3525 if (t
->to_store_registers
!= NULL
)
3527 t
->to_store_registers (t
, regcache
, regno
);
3530 debug_print_register ("target_store_registers", regcache
, regno
);
3540 target_core_of_thread (ptid_t ptid
)
3542 struct target_ops
*t
;
3544 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
3546 if (t
->to_core_of_thread
!= NULL
)
3548 int retval
= t
->to_core_of_thread (t
, ptid
);
3551 fprintf_unfiltered (gdb_stdlog
,
3552 "target_core_of_thread (%d) = %d\n",
3553 PIDGET (ptid
), retval
);
3562 target_verify_memory (const gdb_byte
*data
, CORE_ADDR memaddr
, ULONGEST size
)
3564 struct target_ops
*t
;
3566 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
3568 if (t
->to_verify_memory
!= NULL
)
3570 int retval
= t
->to_verify_memory (t
, data
, memaddr
, size
);
3573 fprintf_unfiltered (gdb_stdlog
,
3574 "target_verify_memory (%s, %s) = %d\n",
3575 paddress (target_gdbarch
, memaddr
),
3585 /* The documentation for this function is in its prototype declaration in
3589 target_insert_mask_watchpoint (CORE_ADDR addr
, CORE_ADDR mask
, int rw
)
3591 struct target_ops
*t
;
3593 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
3594 if (t
->to_insert_mask_watchpoint
!= NULL
)
3598 ret
= t
->to_insert_mask_watchpoint (t
, addr
, mask
, rw
);
3601 fprintf_unfiltered (gdb_stdlog
, "\
3602 target_insert_mask_watchpoint (%s, %s, %d) = %d\n",
3603 core_addr_to_string (addr
),
3604 core_addr_to_string (mask
), rw
, ret
);
3612 /* The documentation for this function is in its prototype declaration in
3616 target_remove_mask_watchpoint (CORE_ADDR addr
, CORE_ADDR mask
, int rw
)
3618 struct target_ops
*t
;
3620 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
3621 if (t
->to_remove_mask_watchpoint
!= NULL
)
3625 ret
= t
->to_remove_mask_watchpoint (t
, addr
, mask
, rw
);
3628 fprintf_unfiltered (gdb_stdlog
, "\
3629 target_remove_mask_watchpoint (%s, %s, %d) = %d\n",
3630 core_addr_to_string (addr
),
3631 core_addr_to_string (mask
), rw
, ret
);
3639 /* The documentation for this function is in its prototype declaration
3643 target_masked_watch_num_registers (CORE_ADDR addr
, CORE_ADDR mask
)
3645 struct target_ops
*t
;
3647 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
3648 if (t
->to_masked_watch_num_registers
!= NULL
)
3649 return t
->to_masked_watch_num_registers (t
, addr
, mask
);
3654 /* The documentation for this function is in its prototype declaration
3658 target_ranged_break_num_registers (void)
3660 struct target_ops
*t
;
3662 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
3663 if (t
->to_ranged_break_num_registers
!= NULL
)
3664 return t
->to_ranged_break_num_registers (t
);
3670 debug_to_prepare_to_store (struct regcache
*regcache
)
3672 debug_target
.to_prepare_to_store (regcache
);
3674 fprintf_unfiltered (gdb_stdlog
, "target_prepare_to_store ()\n");
3678 deprecated_debug_xfer_memory (CORE_ADDR memaddr
, bfd_byte
*myaddr
, int len
,
3679 int write
, struct mem_attrib
*attrib
,
3680 struct target_ops
*target
)
3684 retval
= debug_target
.deprecated_xfer_memory (memaddr
, myaddr
, len
, write
,
3687 fprintf_unfiltered (gdb_stdlog
,
3688 "target_xfer_memory (%s, xxx, %d, %s, xxx) = %d",
3689 paddress (target_gdbarch
, memaddr
), len
,
3690 write
? "write" : "read", retval
);
3696 fputs_unfiltered (", bytes =", gdb_stdlog
);
3697 for (i
= 0; i
< retval
; i
++)
3699 if ((((intptr_t) &(myaddr
[i
])) & 0xf) == 0)
3701 if (targetdebug
< 2 && i
> 0)
3703 fprintf_unfiltered (gdb_stdlog
, " ...");
3706 fprintf_unfiltered (gdb_stdlog
, "\n");
3709 fprintf_unfiltered (gdb_stdlog
, " %02x", myaddr
[i
] & 0xff);
3713 fputc_unfiltered ('\n', gdb_stdlog
);
3719 debug_to_files_info (struct target_ops
*target
)
3721 debug_target
.to_files_info (target
);
3723 fprintf_unfiltered (gdb_stdlog
, "target_files_info (xxx)\n");
3727 debug_to_insert_breakpoint (struct gdbarch
*gdbarch
,
3728 struct bp_target_info
*bp_tgt
)
3732 retval
= debug_target
.to_insert_breakpoint (gdbarch
, bp_tgt
);
3734 fprintf_unfiltered (gdb_stdlog
,
3735 "target_insert_breakpoint (%s, xxx) = %ld\n",
3736 core_addr_to_string (bp_tgt
->placed_address
),
3737 (unsigned long) retval
);
3742 debug_to_remove_breakpoint (struct gdbarch
*gdbarch
,
3743 struct bp_target_info
*bp_tgt
)
3747 retval
= debug_target
.to_remove_breakpoint (gdbarch
, bp_tgt
);
3749 fprintf_unfiltered (gdb_stdlog
,
3750 "target_remove_breakpoint (%s, xxx) = %ld\n",
3751 core_addr_to_string (bp_tgt
->placed_address
),
3752 (unsigned long) retval
);
3757 debug_to_can_use_hw_breakpoint (int type
, int cnt
, int from_tty
)
3761 retval
= debug_target
.to_can_use_hw_breakpoint (type
, cnt
, from_tty
);
3763 fprintf_unfiltered (gdb_stdlog
,
3764 "target_can_use_hw_breakpoint (%ld, %ld, %ld) = %ld\n",
3765 (unsigned long) type
,
3766 (unsigned long) cnt
,
3767 (unsigned long) from_tty
,
3768 (unsigned long) retval
);
3773 debug_to_region_ok_for_hw_watchpoint (CORE_ADDR addr
, int len
)
3777 retval
= debug_target
.to_region_ok_for_hw_watchpoint (addr
, len
);
3779 fprintf_unfiltered (gdb_stdlog
,
3780 "target_region_ok_for_hw_watchpoint (%s, %ld) = %s\n",
3781 core_addr_to_string (addr
), (unsigned long) len
,
3782 core_addr_to_string (retval
));
3787 debug_to_can_accel_watchpoint_condition (CORE_ADDR addr
, int len
, int rw
,
3788 struct expression
*cond
)
3792 retval
= debug_target
.to_can_accel_watchpoint_condition (addr
, len
,
3795 fprintf_unfiltered (gdb_stdlog
,
3796 "target_can_accel_watchpoint_condition "
3797 "(%s, %d, %d, %s) = %ld\n",
3798 core_addr_to_string (addr
), len
, rw
,
3799 host_address_to_string (cond
), (unsigned long) retval
);
3804 debug_to_stopped_by_watchpoint (void)
3808 retval
= debug_target
.to_stopped_by_watchpoint ();
3810 fprintf_unfiltered (gdb_stdlog
,
3811 "target_stopped_by_watchpoint () = %ld\n",
3812 (unsigned long) retval
);
3817 debug_to_stopped_data_address (struct target_ops
*target
, CORE_ADDR
*addr
)
3821 retval
= debug_target
.to_stopped_data_address (target
, addr
);
3823 fprintf_unfiltered (gdb_stdlog
,
3824 "target_stopped_data_address ([%s]) = %ld\n",
3825 core_addr_to_string (*addr
),
3826 (unsigned long)retval
);
3831 debug_to_watchpoint_addr_within_range (struct target_ops
*target
,
3833 CORE_ADDR start
, int length
)
3837 retval
= debug_target
.to_watchpoint_addr_within_range (target
, addr
,
3840 fprintf_filtered (gdb_stdlog
,
3841 "target_watchpoint_addr_within_range (%s, %s, %d) = %d\n",
3842 core_addr_to_string (addr
), core_addr_to_string (start
),
3848 debug_to_insert_hw_breakpoint (struct gdbarch
*gdbarch
,
3849 struct bp_target_info
*bp_tgt
)
3853 retval
= debug_target
.to_insert_hw_breakpoint (gdbarch
, bp_tgt
);
3855 fprintf_unfiltered (gdb_stdlog
,
3856 "target_insert_hw_breakpoint (%s, xxx) = %ld\n",
3857 core_addr_to_string (bp_tgt
->placed_address
),
3858 (unsigned long) retval
);
3863 debug_to_remove_hw_breakpoint (struct gdbarch
*gdbarch
,
3864 struct bp_target_info
*bp_tgt
)
3868 retval
= debug_target
.to_remove_hw_breakpoint (gdbarch
, bp_tgt
);
3870 fprintf_unfiltered (gdb_stdlog
,
3871 "target_remove_hw_breakpoint (%s, xxx) = %ld\n",
3872 core_addr_to_string (bp_tgt
->placed_address
),
3873 (unsigned long) retval
);
3878 debug_to_insert_watchpoint (CORE_ADDR addr
, int len
, int type
,
3879 struct expression
*cond
)
3883 retval
= debug_target
.to_insert_watchpoint (addr
, len
, type
, cond
);
3885 fprintf_unfiltered (gdb_stdlog
,
3886 "target_insert_watchpoint (%s, %d, %d, %s) = %ld\n",
3887 core_addr_to_string (addr
), len
, type
,
3888 host_address_to_string (cond
), (unsigned long) retval
);
3893 debug_to_remove_watchpoint (CORE_ADDR addr
, int len
, int type
,
3894 struct expression
*cond
)
3898 retval
= debug_target
.to_remove_watchpoint (addr
, len
, type
, cond
);
3900 fprintf_unfiltered (gdb_stdlog
,
3901 "target_remove_watchpoint (%s, %d, %d, %s) = %ld\n",
3902 core_addr_to_string (addr
), len
, type
,
3903 host_address_to_string (cond
), (unsigned long) retval
);
3908 debug_to_terminal_init (void)
3910 debug_target
.to_terminal_init ();
3912 fprintf_unfiltered (gdb_stdlog
, "target_terminal_init ()\n");
3916 debug_to_terminal_inferior (void)
3918 debug_target
.to_terminal_inferior ();
3920 fprintf_unfiltered (gdb_stdlog
, "target_terminal_inferior ()\n");
3924 debug_to_terminal_ours_for_output (void)
3926 debug_target
.to_terminal_ours_for_output ();
3928 fprintf_unfiltered (gdb_stdlog
, "target_terminal_ours_for_output ()\n");
3932 debug_to_terminal_ours (void)
3934 debug_target
.to_terminal_ours ();
3936 fprintf_unfiltered (gdb_stdlog
, "target_terminal_ours ()\n");
3940 debug_to_terminal_save_ours (void)
3942 debug_target
.to_terminal_save_ours ();
3944 fprintf_unfiltered (gdb_stdlog
, "target_terminal_save_ours ()\n");
3948 debug_to_terminal_info (char *arg
, int from_tty
)
3950 debug_target
.to_terminal_info (arg
, from_tty
);
3952 fprintf_unfiltered (gdb_stdlog
, "target_terminal_info (%s, %d)\n", arg
,
3957 debug_to_load (char *args
, int from_tty
)
3959 debug_target
.to_load (args
, from_tty
);
3961 fprintf_unfiltered (gdb_stdlog
, "target_load (%s, %d)\n", args
, from_tty
);
3965 debug_to_post_startup_inferior (ptid_t ptid
)
3967 debug_target
.to_post_startup_inferior (ptid
);
3969 fprintf_unfiltered (gdb_stdlog
, "target_post_startup_inferior (%d)\n",
3974 debug_to_insert_fork_catchpoint (int pid
)
3978 retval
= debug_target
.to_insert_fork_catchpoint (pid
);
3980 fprintf_unfiltered (gdb_stdlog
, "target_insert_fork_catchpoint (%d) = %d\n",
3987 debug_to_remove_fork_catchpoint (int pid
)
3991 retval
= debug_target
.to_remove_fork_catchpoint (pid
);
3993 fprintf_unfiltered (gdb_stdlog
, "target_remove_fork_catchpoint (%d) = %d\n",
4000 debug_to_insert_vfork_catchpoint (int pid
)
4004 retval
= debug_target
.to_insert_vfork_catchpoint (pid
);
4006 fprintf_unfiltered (gdb_stdlog
, "target_insert_vfork_catchpoint (%d) = %d\n",
4013 debug_to_remove_vfork_catchpoint (int pid
)
4017 retval
= debug_target
.to_remove_vfork_catchpoint (pid
);
4019 fprintf_unfiltered (gdb_stdlog
, "target_remove_vfork_catchpoint (%d) = %d\n",
4026 debug_to_insert_exec_catchpoint (int pid
)
4030 retval
= debug_target
.to_insert_exec_catchpoint (pid
);
4032 fprintf_unfiltered (gdb_stdlog
, "target_insert_exec_catchpoint (%d) = %d\n",
4039 debug_to_remove_exec_catchpoint (int pid
)
4043 retval
= debug_target
.to_remove_exec_catchpoint (pid
);
4045 fprintf_unfiltered (gdb_stdlog
, "target_remove_exec_catchpoint (%d) = %d\n",
4052 debug_to_has_exited (int pid
, int wait_status
, int *exit_status
)
4056 has_exited
= debug_target
.to_has_exited (pid
, wait_status
, exit_status
);
4058 fprintf_unfiltered (gdb_stdlog
, "target_has_exited (%d, %d, %d) = %d\n",
4059 pid
, wait_status
, *exit_status
, has_exited
);
4065 debug_to_can_run (void)
4069 retval
= debug_target
.to_can_run ();
4071 fprintf_unfiltered (gdb_stdlog
, "target_can_run () = %d\n", retval
);
4076 static struct gdbarch
*
4077 debug_to_thread_architecture (struct target_ops
*ops
, ptid_t ptid
)
4079 struct gdbarch
*retval
;
4081 retval
= debug_target
.to_thread_architecture (ops
, ptid
);
4083 fprintf_unfiltered (gdb_stdlog
,
4084 "target_thread_architecture (%s) = %s [%s]\n",
4085 target_pid_to_str (ptid
),
4086 host_address_to_string (retval
),
4087 gdbarch_bfd_arch_info (retval
)->printable_name
);
4092 debug_to_stop (ptid_t ptid
)
4094 debug_target
.to_stop (ptid
);
4096 fprintf_unfiltered (gdb_stdlog
, "target_stop (%s)\n",
4097 target_pid_to_str (ptid
));
4101 debug_to_rcmd (char *command
,
4102 struct ui_file
*outbuf
)
4104 debug_target
.to_rcmd (command
, outbuf
);
4105 fprintf_unfiltered (gdb_stdlog
, "target_rcmd (%s, ...)\n", command
);
4109 debug_to_pid_to_exec_file (int pid
)
4113 exec_file
= debug_target
.to_pid_to_exec_file (pid
);
4115 fprintf_unfiltered (gdb_stdlog
, "target_pid_to_exec_file (%d) = %s\n",
4122 setup_target_debug (void)
4124 memcpy (&debug_target
, ¤t_target
, sizeof debug_target
);
4126 current_target
.to_open
= debug_to_open
;
4127 current_target
.to_post_attach
= debug_to_post_attach
;
4128 current_target
.to_prepare_to_store
= debug_to_prepare_to_store
;
4129 current_target
.deprecated_xfer_memory
= deprecated_debug_xfer_memory
;
4130 current_target
.to_files_info
= debug_to_files_info
;
4131 current_target
.to_insert_breakpoint
= debug_to_insert_breakpoint
;
4132 current_target
.to_remove_breakpoint
= debug_to_remove_breakpoint
;
4133 current_target
.to_can_use_hw_breakpoint
= debug_to_can_use_hw_breakpoint
;
4134 current_target
.to_insert_hw_breakpoint
= debug_to_insert_hw_breakpoint
;
4135 current_target
.to_remove_hw_breakpoint
= debug_to_remove_hw_breakpoint
;
4136 current_target
.to_insert_watchpoint
= debug_to_insert_watchpoint
;
4137 current_target
.to_remove_watchpoint
= debug_to_remove_watchpoint
;
4138 current_target
.to_stopped_by_watchpoint
= debug_to_stopped_by_watchpoint
;
4139 current_target
.to_stopped_data_address
= debug_to_stopped_data_address
;
4140 current_target
.to_watchpoint_addr_within_range
4141 = debug_to_watchpoint_addr_within_range
;
4142 current_target
.to_region_ok_for_hw_watchpoint
4143 = debug_to_region_ok_for_hw_watchpoint
;
4144 current_target
.to_can_accel_watchpoint_condition
4145 = debug_to_can_accel_watchpoint_condition
;
4146 current_target
.to_terminal_init
= debug_to_terminal_init
;
4147 current_target
.to_terminal_inferior
= debug_to_terminal_inferior
;
4148 current_target
.to_terminal_ours_for_output
4149 = debug_to_terminal_ours_for_output
;
4150 current_target
.to_terminal_ours
= debug_to_terminal_ours
;
4151 current_target
.to_terminal_save_ours
= debug_to_terminal_save_ours
;
4152 current_target
.to_terminal_info
= debug_to_terminal_info
;
4153 current_target
.to_load
= debug_to_load
;
4154 current_target
.to_post_startup_inferior
= debug_to_post_startup_inferior
;
4155 current_target
.to_insert_fork_catchpoint
= debug_to_insert_fork_catchpoint
;
4156 current_target
.to_remove_fork_catchpoint
= debug_to_remove_fork_catchpoint
;
4157 current_target
.to_insert_vfork_catchpoint
= debug_to_insert_vfork_catchpoint
;
4158 current_target
.to_remove_vfork_catchpoint
= debug_to_remove_vfork_catchpoint
;
4159 current_target
.to_insert_exec_catchpoint
= debug_to_insert_exec_catchpoint
;
4160 current_target
.to_remove_exec_catchpoint
= debug_to_remove_exec_catchpoint
;
4161 current_target
.to_has_exited
= debug_to_has_exited
;
4162 current_target
.to_can_run
= debug_to_can_run
;
4163 current_target
.to_stop
= debug_to_stop
;
4164 current_target
.to_rcmd
= debug_to_rcmd
;
4165 current_target
.to_pid_to_exec_file
= debug_to_pid_to_exec_file
;
4166 current_target
.to_thread_architecture
= debug_to_thread_architecture
;
4170 static char targ_desc
[] =
4171 "Names of targets and files being debugged.\nShows the entire \
4172 stack of targets currently in use (including the exec-file,\n\
4173 core-file, and process, if any), as well as the symbol file name.";
4176 do_monitor_command (char *cmd
,
4179 if ((current_target
.to_rcmd
4180 == (void (*) (char *, struct ui_file
*)) tcomplain
)
4181 || (current_target
.to_rcmd
== debug_to_rcmd
4182 && (debug_target
.to_rcmd
4183 == (void (*) (char *, struct ui_file
*)) tcomplain
)))
4184 error (_("\"monitor\" command not supported by this target."));
4185 target_rcmd (cmd
, gdb_stdtarg
);
4188 /* Print the name of each layers of our target stack. */
4191 maintenance_print_target_stack (char *cmd
, int from_tty
)
4193 struct target_ops
*t
;
4195 printf_filtered (_("The current target stack is:\n"));
4197 for (t
= target_stack
; t
!= NULL
; t
= t
->beneath
)
4199 printf_filtered (" - %s (%s)\n", t
->to_shortname
, t
->to_longname
);
4203 /* Controls if async mode is permitted. */
4204 int target_async_permitted
= 0;
4206 /* The set command writes to this variable. If the inferior is
4207 executing, linux_nat_async_permitted is *not* updated. */
4208 static int target_async_permitted_1
= 0;
4211 set_maintenance_target_async_permitted (char *args
, int from_tty
,
4212 struct cmd_list_element
*c
)
4214 if (have_live_inferiors ())
4216 target_async_permitted_1
= target_async_permitted
;
4217 error (_("Cannot change this setting while the inferior is running."));
4220 target_async_permitted
= target_async_permitted_1
;
4224 show_maintenance_target_async_permitted (struct ui_file
*file
, int from_tty
,
4225 struct cmd_list_element
*c
,
4228 fprintf_filtered (file
,
4229 _("Controlling the inferior in "
4230 "asynchronous mode is %s.\n"), value
);
4233 /* Temporary copies of permission settings. */
4235 static int may_write_registers_1
= 1;
4236 static int may_write_memory_1
= 1;
4237 static int may_insert_breakpoints_1
= 1;
4238 static int may_insert_tracepoints_1
= 1;
4239 static int may_insert_fast_tracepoints_1
= 1;
4240 static int may_stop_1
= 1;
4242 /* Make the user-set values match the real values again. */
4245 update_target_permissions (void)
4247 may_write_registers_1
= may_write_registers
;
4248 may_write_memory_1
= may_write_memory
;
4249 may_insert_breakpoints_1
= may_insert_breakpoints
;
4250 may_insert_tracepoints_1
= may_insert_tracepoints
;
4251 may_insert_fast_tracepoints_1
= may_insert_fast_tracepoints
;
4252 may_stop_1
= may_stop
;
4255 /* The one function handles (most of) the permission flags in the same
4259 set_target_permissions (char *args
, int from_tty
,
4260 struct cmd_list_element
*c
)
4262 if (target_has_execution
)
4264 update_target_permissions ();
4265 error (_("Cannot change this setting while the inferior is running."));
4268 /* Make the real values match the user-changed values. */
4269 may_write_registers
= may_write_registers_1
;
4270 may_insert_breakpoints
= may_insert_breakpoints_1
;
4271 may_insert_tracepoints
= may_insert_tracepoints_1
;
4272 may_insert_fast_tracepoints
= may_insert_fast_tracepoints_1
;
4273 may_stop
= may_stop_1
;
4274 update_observer_mode ();
4277 /* Set memory write permission independently of observer mode. */
4280 set_write_memory_permission (char *args
, int from_tty
,
4281 struct cmd_list_element
*c
)
4283 /* Make the real values match the user-changed values. */
4284 may_write_memory
= may_write_memory_1
;
4285 update_observer_mode ();
4290 initialize_targets (void)
4292 init_dummy_target ();
4293 push_target (&dummy_target
);
4295 add_info ("target", target_info
, targ_desc
);
4296 add_info ("files", target_info
, targ_desc
);
4298 add_setshow_zinteger_cmd ("target", class_maintenance
, &targetdebug
, _("\
4299 Set target debugging."), _("\
4300 Show target debugging."), _("\
4301 When non-zero, target debugging is enabled. Higher numbers are more\n\
4302 verbose. Changes do not take effect until the next \"run\" or \"target\"\n\
4306 &setdebuglist
, &showdebuglist
);
4308 add_setshow_boolean_cmd ("trust-readonly-sections", class_support
,
4309 &trust_readonly
, _("\
4310 Set mode for reading from readonly sections."), _("\
4311 Show mode for reading from readonly sections."), _("\
4312 When this mode is on, memory reads from readonly sections (such as .text)\n\
4313 will be read from the object file instead of from the target. This will\n\
4314 result in significant performance improvement for remote targets."),
4316 show_trust_readonly
,
4317 &setlist
, &showlist
);
4319 add_com ("monitor", class_obscure
, do_monitor_command
,
4320 _("Send a command to the remote monitor (remote targets only)."));
4322 add_cmd ("target-stack", class_maintenance
, maintenance_print_target_stack
,
4323 _("Print the name of each layer of the internal target stack."),
4324 &maintenanceprintlist
);
4326 add_setshow_boolean_cmd ("target-async", no_class
,
4327 &target_async_permitted_1
, _("\
4328 Set whether gdb controls the inferior in asynchronous mode."), _("\
4329 Show whether gdb controls the inferior in asynchronous mode."), _("\
4330 Tells gdb whether to control the inferior in asynchronous mode."),
4331 set_maintenance_target_async_permitted
,
4332 show_maintenance_target_async_permitted
,
4336 add_setshow_boolean_cmd ("stack-cache", class_support
,
4337 &stack_cache_enabled_p_1
, _("\
4338 Set cache use for stack access."), _("\
4339 Show cache use for stack access."), _("\
4340 When on, use the data cache for all stack access, regardless of any\n\
4341 configured memory regions. This improves remote performance significantly.\n\
4342 By default, caching for stack access is on."),
4343 set_stack_cache_enabled_p
,
4344 show_stack_cache_enabled_p
,
4345 &setlist
, &showlist
);
4347 add_setshow_boolean_cmd ("may-write-registers", class_support
,
4348 &may_write_registers_1
, _("\
4349 Set permission to write into registers."), _("\
4350 Show permission to write into registers."), _("\
4351 When this permission is on, GDB may write into the target's registers.\n\
4352 Otherwise, any sort of write attempt will result in an error."),
4353 set_target_permissions
, NULL
,
4354 &setlist
, &showlist
);
4356 add_setshow_boolean_cmd ("may-write-memory", class_support
,
4357 &may_write_memory_1
, _("\
4358 Set permission to write into target memory."), _("\
4359 Show permission to write into target memory."), _("\
4360 When this permission is on, GDB may write into the target's memory.\n\
4361 Otherwise, any sort of write attempt will result in an error."),
4362 set_write_memory_permission
, NULL
,
4363 &setlist
, &showlist
);
4365 add_setshow_boolean_cmd ("may-insert-breakpoints", class_support
,
4366 &may_insert_breakpoints_1
, _("\
4367 Set permission to insert breakpoints in the target."), _("\
4368 Show permission to insert breakpoints in the target."), _("\
4369 When this permission is on, GDB may insert breakpoints in the program.\n\
4370 Otherwise, any sort of insertion attempt will result in an error."),
4371 set_target_permissions
, NULL
,
4372 &setlist
, &showlist
);
4374 add_setshow_boolean_cmd ("may-insert-tracepoints", class_support
,
4375 &may_insert_tracepoints_1
, _("\
4376 Set permission to insert tracepoints in the target."), _("\
4377 Show permission to insert tracepoints in the target."), _("\
4378 When this permission is on, GDB may insert tracepoints in the program.\n\
4379 Otherwise, any sort of insertion attempt will result in an error."),
4380 set_target_permissions
, NULL
,
4381 &setlist
, &showlist
);
4383 add_setshow_boolean_cmd ("may-insert-fast-tracepoints", class_support
,
4384 &may_insert_fast_tracepoints_1
, _("\
4385 Set permission to insert fast tracepoints in the target."), _("\
4386 Show permission to insert fast tracepoints in the target."), _("\
4387 When this permission is on, GDB may insert fast tracepoints.\n\
4388 Otherwise, any sort of insertion attempt will result in an error."),
4389 set_target_permissions
, NULL
,
4390 &setlist
, &showlist
);
4392 add_setshow_boolean_cmd ("may-interrupt", class_support
,
4394 Set permission to interrupt or signal the target."), _("\
4395 Show permission to interrupt or signal the target."), _("\
4396 When this permission is on, GDB may interrupt/stop the target's execution.\n\
4397 Otherwise, any attempt to interrupt or stop will be ignored."),
4398 set_target_permissions
, NULL
,
4399 &setlist
, &showlist
);
4402 target_dcache
= dcache_init ();