1 /* Select target systems and architectures at runtime for GDB.
3 Copyright (C) 1990-2014 Free Software Foundation, Inc.
5 Contributed by Cygnus Support.
7 This file is part of GDB.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
26 #include "target-dcache.h"
36 #include "gdb_assert.h"
38 #include "exceptions.h"
39 #include "target-descriptions.h"
40 #include "gdbthread.h"
43 #include "inline-frame.h"
44 #include "tracepoint.h"
45 #include "gdb/fileio.h"
48 static void target_info (char *, int);
50 static void default_terminal_info (struct target_ops
*, const 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 (struct target_ops
*,
58 static void tcomplain (void) ATTRIBUTE_NORETURN
;
60 static int nomemory (CORE_ADDR
, char *, int, int, struct target_ops
*);
62 static int return_zero (void);
64 static int return_one (void);
66 static int return_minus_one (void);
68 static void *return_null (void);
70 void target_ignore (void);
72 static void target_command (char *, int);
74 static struct target_ops
*find_default_run_target (char *);
76 static target_xfer_partial_ftype default_xfer_partial
;
78 static struct gdbarch
*default_thread_architecture (struct target_ops
*ops
,
81 static int find_default_can_async_p (struct target_ops
*ignore
);
83 static int find_default_is_async_p (struct target_ops
*ignore
);
85 #include "target-delegates.c"
87 static void init_dummy_target (void);
89 static struct target_ops debug_target
;
91 static void debug_to_open (char *, int);
93 static void debug_to_prepare_to_store (struct target_ops
*self
,
96 static void debug_to_files_info (struct target_ops
*);
98 static int debug_to_insert_breakpoint (struct target_ops
*, struct gdbarch
*,
99 struct bp_target_info
*);
101 static int debug_to_remove_breakpoint (struct target_ops
*, struct gdbarch
*,
102 struct bp_target_info
*);
104 static int debug_to_can_use_hw_breakpoint (struct target_ops
*self
,
107 static int debug_to_insert_hw_breakpoint (struct target_ops
*self
,
109 struct bp_target_info
*);
111 static int debug_to_remove_hw_breakpoint (struct target_ops
*self
,
113 struct bp_target_info
*);
115 static int debug_to_insert_watchpoint (struct target_ops
*self
,
117 struct expression
*);
119 static int debug_to_remove_watchpoint (struct target_ops
*self
,
121 struct expression
*);
123 static int debug_to_stopped_data_address (struct target_ops
*, CORE_ADDR
*);
125 static int debug_to_watchpoint_addr_within_range (struct target_ops
*,
126 CORE_ADDR
, CORE_ADDR
, int);
128 static int debug_to_region_ok_for_hw_watchpoint (struct target_ops
*self
,
131 static int debug_to_can_accel_watchpoint_condition (struct target_ops
*self
,
133 struct expression
*);
135 static void debug_to_terminal_init (struct target_ops
*self
);
137 static void debug_to_terminal_inferior (struct target_ops
*self
);
139 static void debug_to_terminal_ours_for_output (struct target_ops
*self
);
141 static void debug_to_terminal_save_ours (struct target_ops
*self
);
143 static void debug_to_terminal_ours (struct target_ops
*self
);
145 static void debug_to_load (struct target_ops
*self
, char *, int);
147 static int debug_to_can_run (struct target_ops
*self
);
149 static void debug_to_stop (struct target_ops
*self
, ptid_t
);
151 /* Pointer to array of target architecture structures; the size of the
152 array; the current index into the array; the allocated size of the
154 struct target_ops
**target_structs
;
155 unsigned target_struct_size
;
156 unsigned target_struct_allocsize
;
157 #define DEFAULT_ALLOCSIZE 10
159 /* The initial current target, so that there is always a semi-valid
162 static struct target_ops dummy_target
;
164 /* Top of target stack. */
166 static struct target_ops
*target_stack
;
168 /* The target structure we are currently using to talk to a process
169 or file or whatever "inferior" we have. */
171 struct target_ops current_target
;
173 /* Command list for target. */
175 static struct cmd_list_element
*targetlist
= NULL
;
177 /* Nonzero if we should trust readonly sections from the
178 executable when reading memory. */
180 static int trust_readonly
= 0;
182 /* Nonzero if we should show true memory content including
183 memory breakpoint inserted by gdb. */
185 static int show_memory_breakpoints
= 0;
187 /* These globals control whether GDB attempts to perform these
188 operations; they are useful for targets that need to prevent
189 inadvertant disruption, such as in non-stop mode. */
191 int may_write_registers
= 1;
193 int may_write_memory
= 1;
195 int may_insert_breakpoints
= 1;
197 int may_insert_tracepoints
= 1;
199 int may_insert_fast_tracepoints
= 1;
203 /* Non-zero if we want to see trace of target level stuff. */
205 static unsigned int targetdebug
= 0;
207 show_targetdebug (struct ui_file
*file
, int from_tty
,
208 struct cmd_list_element
*c
, const char *value
)
210 fprintf_filtered (file
, _("Target debugging is %s.\n"), value
);
213 static void setup_target_debug (void);
215 /* The user just typed 'target' without the name of a target. */
218 target_command (char *arg
, int from_tty
)
220 fputs_filtered ("Argument required (target name). Try `help target'\n",
224 /* Default target_has_* methods for process_stratum targets. */
227 default_child_has_all_memory (struct target_ops
*ops
)
229 /* If no inferior selected, then we can't read memory here. */
230 if (ptid_equal (inferior_ptid
, null_ptid
))
237 default_child_has_memory (struct target_ops
*ops
)
239 /* If no inferior selected, then we can't read memory here. */
240 if (ptid_equal (inferior_ptid
, null_ptid
))
247 default_child_has_stack (struct target_ops
*ops
)
249 /* If no inferior selected, there's no stack. */
250 if (ptid_equal (inferior_ptid
, null_ptid
))
257 default_child_has_registers (struct target_ops
*ops
)
259 /* Can't read registers from no inferior. */
260 if (ptid_equal (inferior_ptid
, null_ptid
))
267 default_child_has_execution (struct target_ops
*ops
, ptid_t the_ptid
)
269 /* If there's no thread selected, then we can't make it run through
271 if (ptid_equal (the_ptid
, null_ptid
))
279 target_has_all_memory_1 (void)
281 struct target_ops
*t
;
283 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
284 if (t
->to_has_all_memory (t
))
291 target_has_memory_1 (void)
293 struct target_ops
*t
;
295 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
296 if (t
->to_has_memory (t
))
303 target_has_stack_1 (void)
305 struct target_ops
*t
;
307 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
308 if (t
->to_has_stack (t
))
315 target_has_registers_1 (void)
317 struct target_ops
*t
;
319 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
320 if (t
->to_has_registers (t
))
327 target_has_execution_1 (ptid_t the_ptid
)
329 struct target_ops
*t
;
331 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
332 if (t
->to_has_execution (t
, the_ptid
))
339 target_has_execution_current (void)
341 return target_has_execution_1 (inferior_ptid
);
344 /* Complete initialization of T. This ensures that various fields in
345 T are set, if needed by the target implementation. */
348 complete_target_initialization (struct target_ops
*t
)
350 /* Provide default values for all "must have" methods. */
351 if (t
->to_xfer_partial
== NULL
)
352 t
->to_xfer_partial
= default_xfer_partial
;
354 if (t
->to_has_all_memory
== NULL
)
355 t
->to_has_all_memory
= (int (*) (struct target_ops
*)) return_zero
;
357 if (t
->to_has_memory
== NULL
)
358 t
->to_has_memory
= (int (*) (struct target_ops
*)) return_zero
;
360 if (t
->to_has_stack
== NULL
)
361 t
->to_has_stack
= (int (*) (struct target_ops
*)) return_zero
;
363 if (t
->to_has_registers
== NULL
)
364 t
->to_has_registers
= (int (*) (struct target_ops
*)) return_zero
;
366 if (t
->to_has_execution
== NULL
)
367 t
->to_has_execution
= (int (*) (struct target_ops
*, ptid_t
)) return_zero
;
369 install_delegators (t
);
372 /* Add possible target architecture T to the list and add a new
373 command 'target T->to_shortname'. Set COMPLETER as the command's
374 completer if not NULL. */
377 add_target_with_completer (struct target_ops
*t
,
378 completer_ftype
*completer
)
380 struct cmd_list_element
*c
;
382 complete_target_initialization (t
);
386 target_struct_allocsize
= DEFAULT_ALLOCSIZE
;
387 target_structs
= (struct target_ops
**) xmalloc
388 (target_struct_allocsize
* sizeof (*target_structs
));
390 if (target_struct_size
>= target_struct_allocsize
)
392 target_struct_allocsize
*= 2;
393 target_structs
= (struct target_ops
**)
394 xrealloc ((char *) target_structs
,
395 target_struct_allocsize
* sizeof (*target_structs
));
397 target_structs
[target_struct_size
++] = t
;
399 if (targetlist
== NULL
)
400 add_prefix_cmd ("target", class_run
, target_command
, _("\
401 Connect to a target machine or process.\n\
402 The first argument is the type or protocol of the target machine.\n\
403 Remaining arguments are interpreted by the target protocol. For more\n\
404 information on the arguments for a particular protocol, type\n\
405 `help target ' followed by the protocol name."),
406 &targetlist
, "target ", 0, &cmdlist
);
407 c
= add_cmd (t
->to_shortname
, no_class
, t
->to_open
, t
->to_doc
,
409 if (completer
!= NULL
)
410 set_cmd_completer (c
, completer
);
413 /* Add a possible target architecture to the list. */
416 add_target (struct target_ops
*t
)
418 add_target_with_completer (t
, NULL
);
424 add_deprecated_target_alias (struct target_ops
*t
, char *alias
)
426 struct cmd_list_element
*c
;
429 /* If we use add_alias_cmd, here, we do not get the deprecated warning,
431 c
= add_cmd (alias
, no_class
, t
->to_open
, t
->to_doc
, &targetlist
);
432 alt
= xstrprintf ("target %s", t
->to_shortname
);
433 deprecate_cmd (c
, alt
);
446 struct target_ops
*t
;
448 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
449 if (t
->to_kill
!= NULL
)
452 fprintf_unfiltered (gdb_stdlog
, "target_kill ()\n");
462 target_load (char *arg
, int from_tty
)
464 target_dcache_invalidate ();
465 (*current_target
.to_load
) (¤t_target
, arg
, from_tty
);
469 target_create_inferior (char *exec_file
, char *args
,
470 char **env
, int from_tty
)
472 struct target_ops
*t
;
474 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
476 if (t
->to_create_inferior
!= NULL
)
478 t
->to_create_inferior (t
, exec_file
, args
, env
, from_tty
);
480 fprintf_unfiltered (gdb_stdlog
,
481 "target_create_inferior (%s, %s, xxx, %d)\n",
482 exec_file
, args
, from_tty
);
487 internal_error (__FILE__
, __LINE__
,
488 _("could not find a target to create inferior"));
492 target_terminal_inferior (void)
494 /* A background resume (``run&'') should leave GDB in control of the
495 terminal. Use target_can_async_p, not target_is_async_p, since at
496 this point the target is not async yet. However, if sync_execution
497 is not set, we know it will become async prior to resume. */
498 if (target_can_async_p () && !sync_execution
)
501 /* If GDB is resuming the inferior in the foreground, install
502 inferior's terminal modes. */
503 (*current_target
.to_terminal_inferior
) (¤t_target
);
507 nomemory (CORE_ADDR memaddr
, char *myaddr
, int len
, int write
,
508 struct target_ops
*t
)
510 errno
= EIO
; /* Can't read/write this location. */
511 return 0; /* No bytes handled. */
517 error (_("You can't do that when your target is `%s'"),
518 current_target
.to_shortname
);
524 error (_("You can't do that without a process to debug."));
528 default_terminal_info (struct target_ops
*self
, const char *args
, int from_tty
)
530 printf_unfiltered (_("No saved terminal information.\n"));
533 /* A default implementation for the to_get_ada_task_ptid target method.
535 This function builds the PTID by using both LWP and TID as part of
536 the PTID lwp and tid elements. The pid used is the pid of the
540 default_get_ada_task_ptid (struct target_ops
*self
, long lwp
, long tid
)
542 return ptid_build (ptid_get_pid (inferior_ptid
), lwp
, tid
);
545 static enum exec_direction_kind
546 default_execution_direction (struct target_ops
*self
)
548 if (!target_can_execute_reverse
)
550 else if (!target_can_async_p ())
553 gdb_assert_not_reached ("\
554 to_execution_direction must be implemented for reverse async");
557 /* Go through the target stack from top to bottom, copying over zero
558 entries in current_target, then filling in still empty entries. In
559 effect, we are doing class inheritance through the pushed target
562 NOTE: cagney/2003-10-17: The problem with this inheritance, as it
563 is currently implemented, is that it discards any knowledge of
564 which target an inherited method originally belonged to.
565 Consequently, new new target methods should instead explicitly and
566 locally search the target stack for the target that can handle the
570 update_current_target (void)
572 struct target_ops
*t
;
574 /* First, reset current's contents. */
575 memset (¤t_target
, 0, sizeof (current_target
));
577 /* Install the delegators. */
578 install_delegators (¤t_target
);
580 #define INHERIT(FIELD, TARGET) \
581 if (!current_target.FIELD) \
582 current_target.FIELD = (TARGET)->FIELD
584 for (t
= target_stack
; t
; t
= t
->beneath
)
586 INHERIT (to_shortname
, t
);
587 INHERIT (to_longname
, t
);
589 /* Do not inherit to_open. */
590 /* Do not inherit to_close. */
591 /* Do not inherit to_attach. */
592 INHERIT (to_post_attach
, t
);
593 INHERIT (to_attach_no_wait
, t
);
594 /* Do not inherit to_detach. */
595 /* Do not inherit to_disconnect. */
596 /* Do not inherit to_resume. */
597 /* Do not inherit to_wait. */
598 /* Do not inherit to_fetch_registers. */
599 /* Do not inherit to_store_registers. */
600 INHERIT (to_prepare_to_store
, t
);
601 INHERIT (deprecated_xfer_memory
, t
);
602 INHERIT (to_files_info
, t
);
603 /* Do not inherit to_insert_breakpoint. */
604 /* Do not inherit to_remove_breakpoint. */
605 INHERIT (to_can_use_hw_breakpoint
, t
);
606 INHERIT (to_insert_hw_breakpoint
, t
);
607 INHERIT (to_remove_hw_breakpoint
, t
);
608 /* Do not inherit to_ranged_break_num_registers. */
609 INHERIT (to_insert_watchpoint
, t
);
610 INHERIT (to_remove_watchpoint
, t
);
611 /* Do not inherit to_insert_mask_watchpoint. */
612 /* Do not inherit to_remove_mask_watchpoint. */
613 /* Do not inherit to_stopped_data_address. */
614 INHERIT (to_have_steppable_watchpoint
, t
);
615 INHERIT (to_have_continuable_watchpoint
, t
);
616 /* Do not inherit to_stopped_by_watchpoint. */
617 INHERIT (to_watchpoint_addr_within_range
, t
);
618 INHERIT (to_region_ok_for_hw_watchpoint
, t
);
619 INHERIT (to_can_accel_watchpoint_condition
, t
);
620 /* Do not inherit to_masked_watch_num_registers. */
621 INHERIT (to_terminal_init
, t
);
622 INHERIT (to_terminal_inferior
, t
);
623 INHERIT (to_terminal_ours_for_output
, t
);
624 INHERIT (to_terminal_ours
, t
);
625 INHERIT (to_terminal_save_ours
, t
);
626 INHERIT (to_terminal_info
, t
);
627 /* Do not inherit to_kill. */
628 INHERIT (to_load
, t
);
629 /* Do no inherit to_create_inferior. */
630 INHERIT (to_post_startup_inferior
, t
);
631 INHERIT (to_insert_fork_catchpoint
, t
);
632 INHERIT (to_remove_fork_catchpoint
, t
);
633 INHERIT (to_insert_vfork_catchpoint
, t
);
634 INHERIT (to_remove_vfork_catchpoint
, t
);
635 /* Do not inherit to_follow_fork. */
636 INHERIT (to_insert_exec_catchpoint
, t
);
637 INHERIT (to_remove_exec_catchpoint
, t
);
638 INHERIT (to_set_syscall_catchpoint
, t
);
639 INHERIT (to_has_exited
, t
);
640 /* Do not inherit to_mourn_inferior. */
641 INHERIT (to_can_run
, t
);
642 /* Do not inherit to_pass_signals. */
643 /* Do not inherit to_program_signals. */
644 /* Do not inherit to_thread_alive. */
645 /* Do not inherit to_find_new_threads. */
646 /* Do not inherit to_pid_to_str. */
647 INHERIT (to_extra_thread_info
, t
);
648 INHERIT (to_thread_name
, t
);
649 INHERIT (to_stop
, t
);
650 /* Do not inherit to_xfer_partial. */
651 INHERIT (to_rcmd
, t
);
652 INHERIT (to_pid_to_exec_file
, t
);
653 INHERIT (to_log_command
, t
);
654 INHERIT (to_stratum
, t
);
655 /* Do not inherit to_has_all_memory. */
656 /* Do not inherit to_has_memory. */
657 /* Do not inherit to_has_stack. */
658 /* Do not inherit to_has_registers. */
659 /* Do not inherit to_has_execution. */
660 INHERIT (to_has_thread_control
, t
);
661 /* Do not inherit to_can_async_p. */
662 /* Do not inherit to_is_async_p. */
663 /* Do not inherit to_async. */
664 INHERIT (to_find_memory_regions
, t
);
665 INHERIT (to_make_corefile_notes
, t
);
666 INHERIT (to_get_bookmark
, t
);
667 INHERIT (to_goto_bookmark
, t
);
668 /* Do not inherit to_get_thread_local_address. */
669 INHERIT (to_can_execute_reverse
, t
);
670 INHERIT (to_execution_direction
, t
);
671 INHERIT (to_thread_architecture
, t
);
672 /* Do not inherit to_read_description. */
673 INHERIT (to_get_ada_task_ptid
, t
);
674 /* Do not inherit to_search_memory. */
675 INHERIT (to_supports_multi_process
, t
);
676 INHERIT (to_supports_enable_disable_tracepoint
, t
);
677 INHERIT (to_supports_string_tracing
, t
);
678 INHERIT (to_trace_init
, t
);
679 INHERIT (to_download_tracepoint
, t
);
680 INHERIT (to_can_download_tracepoint
, t
);
681 INHERIT (to_download_trace_state_variable
, t
);
682 INHERIT (to_enable_tracepoint
, t
);
683 INHERIT (to_disable_tracepoint
, t
);
684 INHERIT (to_trace_set_readonly_regions
, t
);
685 INHERIT (to_trace_start
, t
);
686 INHERIT (to_get_trace_status
, t
);
687 INHERIT (to_get_tracepoint_status
, t
);
688 INHERIT (to_trace_stop
, t
);
689 INHERIT (to_trace_find
, t
);
690 INHERIT (to_get_trace_state_variable_value
, t
);
691 INHERIT (to_save_trace_data
, t
);
692 INHERIT (to_upload_tracepoints
, t
);
693 INHERIT (to_upload_trace_state_variables
, t
);
694 INHERIT (to_get_raw_trace_data
, t
);
695 INHERIT (to_get_min_fast_tracepoint_insn_len
, t
);
696 INHERIT (to_set_disconnected_tracing
, t
);
697 INHERIT (to_set_circular_trace_buffer
, t
);
698 INHERIT (to_set_trace_buffer_size
, t
);
699 INHERIT (to_set_trace_notes
, t
);
700 INHERIT (to_get_tib_address
, t
);
701 INHERIT (to_set_permissions
, t
);
702 INHERIT (to_static_tracepoint_marker_at
, t
);
703 INHERIT (to_static_tracepoint_markers_by_strid
, t
);
704 INHERIT (to_traceframe_info
, t
);
705 INHERIT (to_use_agent
, t
);
706 INHERIT (to_can_use_agent
, t
);
707 INHERIT (to_augmented_libraries_svr4_read
, t
);
708 INHERIT (to_magic
, t
);
709 INHERIT (to_supports_evaluation_of_breakpoint_conditions
, t
);
710 INHERIT (to_can_run_breakpoint_commands
, t
);
711 /* Do not inherit to_memory_map. */
712 /* Do not inherit to_flash_erase. */
713 /* Do not inherit to_flash_done. */
717 /* Clean up a target struct so it no longer has any zero pointers in
718 it. Some entries are defaulted to a method that print an error,
719 others are hard-wired to a standard recursive default. */
721 #define de_fault(field, value) \
722 if (!current_target.field) \
723 current_target.field = value
726 (void (*) (char *, int))
729 (void (*) (struct target_ops
*))
731 de_fault (to_post_attach
,
732 (void (*) (struct target_ops
*, int))
734 de_fault (to_prepare_to_store
,
735 (void (*) (struct target_ops
*, struct regcache
*))
737 de_fault (deprecated_xfer_memory
,
738 (int (*) (CORE_ADDR
, gdb_byte
*, int, int,
739 struct mem_attrib
*, struct target_ops
*))
741 de_fault (to_files_info
,
742 (void (*) (struct target_ops
*))
744 de_fault (to_can_use_hw_breakpoint
,
745 (int (*) (struct target_ops
*, int, int, int))
747 de_fault (to_insert_hw_breakpoint
,
748 (int (*) (struct target_ops
*, struct gdbarch
*,
749 struct bp_target_info
*))
751 de_fault (to_remove_hw_breakpoint
,
752 (int (*) (struct target_ops
*, struct gdbarch
*,
753 struct bp_target_info
*))
755 de_fault (to_insert_watchpoint
,
756 (int (*) (struct target_ops
*, CORE_ADDR
, int, int,
757 struct expression
*))
759 de_fault (to_remove_watchpoint
,
760 (int (*) (struct target_ops
*, CORE_ADDR
, int, int,
761 struct expression
*))
763 de_fault (to_watchpoint_addr_within_range
,
764 default_watchpoint_addr_within_range
);
765 de_fault (to_region_ok_for_hw_watchpoint
,
766 default_region_ok_for_hw_watchpoint
);
767 de_fault (to_can_accel_watchpoint_condition
,
768 (int (*) (struct target_ops
*, CORE_ADDR
, int, int,
769 struct expression
*))
771 de_fault (to_terminal_init
,
772 (void (*) (struct target_ops
*))
774 de_fault (to_terminal_inferior
,
775 (void (*) (struct target_ops
*))
777 de_fault (to_terminal_ours_for_output
,
778 (void (*) (struct target_ops
*))
780 de_fault (to_terminal_ours
,
781 (void (*) (struct target_ops
*))
783 de_fault (to_terminal_save_ours
,
784 (void (*) (struct target_ops
*))
786 de_fault (to_terminal_info
,
787 default_terminal_info
);
789 (void (*) (struct target_ops
*, char *, int))
791 de_fault (to_post_startup_inferior
,
792 (void (*) (struct target_ops
*, ptid_t
))
794 de_fault (to_insert_fork_catchpoint
,
795 (int (*) (struct target_ops
*, int))
797 de_fault (to_remove_fork_catchpoint
,
798 (int (*) (struct target_ops
*, int))
800 de_fault (to_insert_vfork_catchpoint
,
801 (int (*) (struct target_ops
*, int))
803 de_fault (to_remove_vfork_catchpoint
,
804 (int (*) (struct target_ops
*, int))
806 de_fault (to_insert_exec_catchpoint
,
807 (int (*) (struct target_ops
*, int))
809 de_fault (to_remove_exec_catchpoint
,
810 (int (*) (struct target_ops
*, int))
812 de_fault (to_set_syscall_catchpoint
,
813 (int (*) (struct target_ops
*, int, int, int, int, int *))
815 de_fault (to_has_exited
,
816 (int (*) (struct target_ops
*, int, int, int *))
818 de_fault (to_can_run
,
819 (int (*) (struct target_ops
*))
821 de_fault (to_extra_thread_info
,
822 (char *(*) (struct target_ops
*, struct thread_info
*))
824 de_fault (to_thread_name
,
825 (char *(*) (struct target_ops
*, struct thread_info
*))
828 (void (*) (struct target_ops
*, ptid_t
))
831 (void (*) (struct target_ops
*, char *, struct ui_file
*))
833 de_fault (to_pid_to_exec_file
,
834 (char *(*) (struct target_ops
*, int))
836 de_fault (to_thread_architecture
,
837 default_thread_architecture
);
838 current_target
.to_read_description
= NULL
;
839 de_fault (to_get_ada_task_ptid
,
840 (ptid_t (*) (struct target_ops
*, long, long))
841 default_get_ada_task_ptid
);
842 de_fault (to_supports_multi_process
,
843 (int (*) (struct target_ops
*))
845 de_fault (to_supports_enable_disable_tracepoint
,
846 (int (*) (struct target_ops
*))
848 de_fault (to_supports_string_tracing
,
849 (int (*) (struct target_ops
*))
851 de_fault (to_trace_init
,
852 (void (*) (struct target_ops
*))
854 de_fault (to_download_tracepoint
,
855 (void (*) (struct target_ops
*, struct bp_location
*))
857 de_fault (to_can_download_tracepoint
,
858 (int (*) (struct target_ops
*))
860 de_fault (to_download_trace_state_variable
,
861 (void (*) (struct target_ops
*, struct trace_state_variable
*))
863 de_fault (to_enable_tracepoint
,
864 (void (*) (struct target_ops
*, struct bp_location
*))
866 de_fault (to_disable_tracepoint
,
867 (void (*) (struct target_ops
*, struct bp_location
*))
869 de_fault (to_trace_set_readonly_regions
,
870 (void (*) (struct target_ops
*))
872 de_fault (to_trace_start
,
873 (void (*) (struct target_ops
*))
875 de_fault (to_get_trace_status
,
876 (int (*) (struct target_ops
*, struct trace_status
*))
878 de_fault (to_get_tracepoint_status
,
879 (void (*) (struct target_ops
*, struct breakpoint
*,
880 struct uploaded_tp
*))
882 de_fault (to_trace_stop
,
883 (void (*) (struct target_ops
*))
885 de_fault (to_trace_find
,
886 (int (*) (struct target_ops
*,
887 enum trace_find_type
, int, CORE_ADDR
, CORE_ADDR
, int *))
889 de_fault (to_get_trace_state_variable_value
,
890 (int (*) (struct target_ops
*, int, LONGEST
*))
892 de_fault (to_save_trace_data
,
893 (int (*) (struct target_ops
*, const char *))
895 de_fault (to_upload_tracepoints
,
896 (int (*) (struct target_ops
*, struct uploaded_tp
**))
898 de_fault (to_upload_trace_state_variables
,
899 (int (*) (struct target_ops
*, struct uploaded_tsv
**))
901 de_fault (to_get_raw_trace_data
,
902 (LONGEST (*) (struct target_ops
*, gdb_byte
*, ULONGEST
, LONGEST
))
904 de_fault (to_get_min_fast_tracepoint_insn_len
,
907 de_fault (to_set_disconnected_tracing
,
910 de_fault (to_set_circular_trace_buffer
,
913 de_fault (to_set_trace_buffer_size
,
916 de_fault (to_set_trace_notes
,
917 (int (*) (const char *, const char *, const char *))
919 de_fault (to_get_tib_address
,
920 (int (*) (ptid_t
, CORE_ADDR
*))
922 de_fault (to_set_permissions
,
925 de_fault (to_static_tracepoint_marker_at
,
926 (int (*) (CORE_ADDR
, struct static_tracepoint_marker
*))
928 de_fault (to_static_tracepoint_markers_by_strid
,
929 (VEC(static_tracepoint_marker_p
) * (*) (const char *))
931 de_fault (to_traceframe_info
,
932 (struct traceframe_info
* (*) (void))
934 de_fault (to_supports_evaluation_of_breakpoint_conditions
,
935 (int (*) (struct target_ops
*))
937 de_fault (to_can_run_breakpoint_commands
,
938 (int (*) (struct target_ops
*))
940 de_fault (to_use_agent
,
943 de_fault (to_can_use_agent
,
946 de_fault (to_augmented_libraries_svr4_read
,
949 de_fault (to_execution_direction
, default_execution_direction
);
953 /* Finally, position the target-stack beneath the squashed
954 "current_target". That way code looking for a non-inherited
955 target method can quickly and simply find it. */
956 current_target
.beneath
= target_stack
;
959 setup_target_debug ();
962 /* Push a new target type into the stack of the existing target accessors,
963 possibly superseding some of the existing accessors.
965 Rather than allow an empty stack, we always have the dummy target at
966 the bottom stratum, so we can call the function vectors without
970 push_target (struct target_ops
*t
)
972 struct target_ops
**cur
;
974 /* Check magic number. If wrong, it probably means someone changed
975 the struct definition, but not all the places that initialize one. */
976 if (t
->to_magic
!= OPS_MAGIC
)
978 fprintf_unfiltered (gdb_stderr
,
979 "Magic number of %s target struct wrong\n",
981 internal_error (__FILE__
, __LINE__
,
982 _("failed internal consistency check"));
985 /* Find the proper stratum to install this target in. */
986 for (cur
= &target_stack
; (*cur
) != NULL
; cur
= &(*cur
)->beneath
)
988 if ((int) (t
->to_stratum
) >= (int) (*cur
)->to_stratum
)
992 /* If there's already targets at this stratum, remove them. */
993 /* FIXME: cagney/2003-10-15: I think this should be popping all
994 targets to CUR, and not just those at this stratum level. */
995 while ((*cur
) != NULL
&& t
->to_stratum
== (*cur
)->to_stratum
)
997 /* There's already something at this stratum level. Close it,
998 and un-hook it from the stack. */
999 struct target_ops
*tmp
= (*cur
);
1001 (*cur
) = (*cur
)->beneath
;
1002 tmp
->beneath
= NULL
;
1006 /* We have removed all targets in our stratum, now add the new one. */
1007 t
->beneath
= (*cur
);
1010 update_current_target ();
1013 /* Remove a target_ops vector from the stack, wherever it may be.
1014 Return how many times it was removed (0 or 1). */
1017 unpush_target (struct target_ops
*t
)
1019 struct target_ops
**cur
;
1020 struct target_ops
*tmp
;
1022 if (t
->to_stratum
== dummy_stratum
)
1023 internal_error (__FILE__
, __LINE__
,
1024 _("Attempt to unpush the dummy target"));
1026 /* Look for the specified target. Note that we assume that a target
1027 can only occur once in the target stack. */
1029 for (cur
= &target_stack
; (*cur
) != NULL
; cur
= &(*cur
)->beneath
)
1035 /* If we don't find target_ops, quit. Only open targets should be
1040 /* Unchain the target. */
1042 (*cur
) = (*cur
)->beneath
;
1043 tmp
->beneath
= NULL
;
1045 update_current_target ();
1047 /* Finally close the target. Note we do this after unchaining, so
1048 any target method calls from within the target_close
1049 implementation don't end up in T anymore. */
1056 pop_all_targets_above (enum strata above_stratum
)
1058 while ((int) (current_target
.to_stratum
) > (int) above_stratum
)
1060 if (!unpush_target (target_stack
))
1062 fprintf_unfiltered (gdb_stderr
,
1063 "pop_all_targets couldn't find target %s\n",
1064 target_stack
->to_shortname
);
1065 internal_error (__FILE__
, __LINE__
,
1066 _("failed internal consistency check"));
1073 pop_all_targets (void)
1075 pop_all_targets_above (dummy_stratum
);
1078 /* Return 1 if T is now pushed in the target stack. Return 0 otherwise. */
1081 target_is_pushed (struct target_ops
*t
)
1083 struct target_ops
**cur
;
1085 /* Check magic number. If wrong, it probably means someone changed
1086 the struct definition, but not all the places that initialize one. */
1087 if (t
->to_magic
!= OPS_MAGIC
)
1089 fprintf_unfiltered (gdb_stderr
,
1090 "Magic number of %s target struct wrong\n",
1092 internal_error (__FILE__
, __LINE__
,
1093 _("failed internal consistency check"));
1096 for (cur
= &target_stack
; (*cur
) != NULL
; cur
= &(*cur
)->beneath
)
1103 /* Using the objfile specified in OBJFILE, find the address for the
1104 current thread's thread-local storage with offset OFFSET. */
1106 target_translate_tls_address (struct objfile
*objfile
, CORE_ADDR offset
)
1108 volatile CORE_ADDR addr
= 0;
1109 struct target_ops
*target
;
1111 for (target
= current_target
.beneath
;
1113 target
= target
->beneath
)
1115 if (target
->to_get_thread_local_address
!= NULL
)
1120 && gdbarch_fetch_tls_load_module_address_p (target_gdbarch ()))
1122 ptid_t ptid
= inferior_ptid
;
1123 volatile struct gdb_exception ex
;
1125 TRY_CATCH (ex
, RETURN_MASK_ALL
)
1129 /* Fetch the load module address for this objfile. */
1130 lm_addr
= gdbarch_fetch_tls_load_module_address (target_gdbarch (),
1132 /* If it's 0, throw the appropriate exception. */
1134 throw_error (TLS_LOAD_MODULE_NOT_FOUND_ERROR
,
1135 _("TLS load module not found"));
1137 addr
= target
->to_get_thread_local_address (target
, ptid
,
1140 /* If an error occurred, print TLS related messages here. Otherwise,
1141 throw the error to some higher catcher. */
1144 int objfile_is_library
= (objfile
->flags
& OBJF_SHARED
);
1148 case TLS_NO_LIBRARY_SUPPORT_ERROR
:
1149 error (_("Cannot find thread-local variables "
1150 "in this thread library."));
1152 case TLS_LOAD_MODULE_NOT_FOUND_ERROR
:
1153 if (objfile_is_library
)
1154 error (_("Cannot find shared library `%s' in dynamic"
1155 " linker's load module list"), objfile_name (objfile
));
1157 error (_("Cannot find executable file `%s' in dynamic"
1158 " linker's load module list"), objfile_name (objfile
));
1160 case TLS_NOT_ALLOCATED_YET_ERROR
:
1161 if (objfile_is_library
)
1162 error (_("The inferior has not yet allocated storage for"
1163 " thread-local variables in\n"
1164 "the shared library `%s'\n"
1166 objfile_name (objfile
), target_pid_to_str (ptid
));
1168 error (_("The inferior has not yet allocated storage for"
1169 " thread-local variables in\n"
1170 "the executable `%s'\n"
1172 objfile_name (objfile
), target_pid_to_str (ptid
));
1174 case TLS_GENERIC_ERROR
:
1175 if (objfile_is_library
)
1176 error (_("Cannot find thread-local storage for %s, "
1177 "shared library %s:\n%s"),
1178 target_pid_to_str (ptid
),
1179 objfile_name (objfile
), ex
.message
);
1181 error (_("Cannot find thread-local storage for %s, "
1182 "executable file %s:\n%s"),
1183 target_pid_to_str (ptid
),
1184 objfile_name (objfile
), ex
.message
);
1187 throw_exception (ex
);
1192 /* It wouldn't be wrong here to try a gdbarch method, too; finding
1193 TLS is an ABI-specific thing. But we don't do that yet. */
1195 error (_("Cannot find thread-local variables on this target"));
1201 target_xfer_status_to_string (enum target_xfer_status err
)
1203 #define CASE(X) case X: return #X
1206 CASE(TARGET_XFER_E_IO
);
1207 CASE(TARGET_XFER_E_UNAVAILABLE
);
1216 #define MIN(A, B) (((A) <= (B)) ? (A) : (B))
1218 /* target_read_string -- read a null terminated string, up to LEN bytes,
1219 from MEMADDR in target. Set *ERRNOP to the errno code, or 0 if successful.
1220 Set *STRING to a pointer to malloc'd memory containing the data; the caller
1221 is responsible for freeing it. Return the number of bytes successfully
1225 target_read_string (CORE_ADDR memaddr
, char **string
, int len
, int *errnop
)
1227 int tlen
, offset
, i
;
1231 int buffer_allocated
;
1233 unsigned int nbytes_read
= 0;
1235 gdb_assert (string
);
1237 /* Small for testing. */
1238 buffer_allocated
= 4;
1239 buffer
= xmalloc (buffer_allocated
);
1244 tlen
= MIN (len
, 4 - (memaddr
& 3));
1245 offset
= memaddr
& 3;
1247 errcode
= target_read_memory (memaddr
& ~3, buf
, sizeof buf
);
1250 /* The transfer request might have crossed the boundary to an
1251 unallocated region of memory. Retry the transfer, requesting
1255 errcode
= target_read_memory (memaddr
, buf
, 1);
1260 if (bufptr
- buffer
+ tlen
> buffer_allocated
)
1264 bytes
= bufptr
- buffer
;
1265 buffer_allocated
*= 2;
1266 buffer
= xrealloc (buffer
, buffer_allocated
);
1267 bufptr
= buffer
+ bytes
;
1270 for (i
= 0; i
< tlen
; i
++)
1272 *bufptr
++ = buf
[i
+ offset
];
1273 if (buf
[i
+ offset
] == '\000')
1275 nbytes_read
+= i
+ 1;
1282 nbytes_read
+= tlen
;
1291 struct target_section_table
*
1292 target_get_section_table (struct target_ops
*target
)
1294 struct target_ops
*t
;
1297 fprintf_unfiltered (gdb_stdlog
, "target_get_section_table ()\n");
1299 for (t
= target
; t
!= NULL
; t
= t
->beneath
)
1300 if (t
->to_get_section_table
!= NULL
)
1301 return (*t
->to_get_section_table
) (t
);
1306 /* Find a section containing ADDR. */
1308 struct target_section
*
1309 target_section_by_addr (struct target_ops
*target
, CORE_ADDR addr
)
1311 struct target_section_table
*table
= target_get_section_table (target
);
1312 struct target_section
*secp
;
1317 for (secp
= table
->sections
; secp
< table
->sections_end
; secp
++)
1319 if (addr
>= secp
->addr
&& addr
< secp
->endaddr
)
1325 /* Read memory from the live target, even if currently inspecting a
1326 traceframe. The return is the same as that of target_read. */
1328 static enum target_xfer_status
1329 target_read_live_memory (enum target_object object
,
1330 ULONGEST memaddr
, gdb_byte
*myaddr
, ULONGEST len
,
1331 ULONGEST
*xfered_len
)
1333 enum target_xfer_status ret
;
1334 struct cleanup
*cleanup
;
1336 /* Switch momentarily out of tfind mode so to access live memory.
1337 Note that this must not clear global state, such as the frame
1338 cache, which must still remain valid for the previous traceframe.
1339 We may be _building_ the frame cache at this point. */
1340 cleanup
= make_cleanup_restore_traceframe_number ();
1341 set_traceframe_number (-1);
1343 ret
= target_xfer_partial (current_target
.beneath
, object
, NULL
,
1344 myaddr
, NULL
, memaddr
, len
, xfered_len
);
1346 do_cleanups (cleanup
);
1350 /* Using the set of read-only target sections of OPS, read live
1351 read-only memory. Note that the actual reads start from the
1352 top-most target again.
1354 For interface/parameters/return description see target.h,
1357 static enum target_xfer_status
1358 memory_xfer_live_readonly_partial (struct target_ops
*ops
,
1359 enum target_object object
,
1360 gdb_byte
*readbuf
, ULONGEST memaddr
,
1361 ULONGEST len
, ULONGEST
*xfered_len
)
1363 struct target_section
*secp
;
1364 struct target_section_table
*table
;
1366 secp
= target_section_by_addr (ops
, memaddr
);
1368 && (bfd_get_section_flags (secp
->the_bfd_section
->owner
,
1369 secp
->the_bfd_section
)
1372 struct target_section
*p
;
1373 ULONGEST memend
= memaddr
+ len
;
1375 table
= target_get_section_table (ops
);
1377 for (p
= table
->sections
; p
< table
->sections_end
; p
++)
1379 if (memaddr
>= p
->addr
)
1381 if (memend
<= p
->endaddr
)
1383 /* Entire transfer is within this section. */
1384 return target_read_live_memory (object
, memaddr
,
1385 readbuf
, len
, xfered_len
);
1387 else if (memaddr
>= p
->endaddr
)
1389 /* This section ends before the transfer starts. */
1394 /* This section overlaps the transfer. Just do half. */
1395 len
= p
->endaddr
- memaddr
;
1396 return target_read_live_memory (object
, memaddr
,
1397 readbuf
, len
, xfered_len
);
1403 return TARGET_XFER_EOF
;
1406 /* Read memory from more than one valid target. A core file, for
1407 instance, could have some of memory but delegate other bits to
1408 the target below it. So, we must manually try all targets. */
1410 static enum target_xfer_status
1411 raw_memory_xfer_partial (struct target_ops
*ops
, gdb_byte
*readbuf
,
1412 const gdb_byte
*writebuf
, ULONGEST memaddr
, LONGEST len
,
1413 ULONGEST
*xfered_len
)
1415 enum target_xfer_status res
;
1419 res
= ops
->to_xfer_partial (ops
, TARGET_OBJECT_MEMORY
, NULL
,
1420 readbuf
, writebuf
, memaddr
, len
,
1422 if (res
== TARGET_XFER_OK
)
1425 /* Stop if the target reports that the memory is not available. */
1426 if (res
== TARGET_XFER_E_UNAVAILABLE
)
1429 /* We want to continue past core files to executables, but not
1430 past a running target's memory. */
1431 if (ops
->to_has_all_memory (ops
))
1436 while (ops
!= NULL
);
1441 /* Perform a partial memory transfer.
1442 For docs see target.h, to_xfer_partial. */
1444 static enum target_xfer_status
1445 memory_xfer_partial_1 (struct target_ops
*ops
, enum target_object object
,
1446 gdb_byte
*readbuf
, const gdb_byte
*writebuf
, ULONGEST memaddr
,
1447 ULONGEST len
, ULONGEST
*xfered_len
)
1449 enum target_xfer_status res
;
1451 struct mem_region
*region
;
1452 struct inferior
*inf
;
1454 /* For accesses to unmapped overlay sections, read directly from
1455 files. Must do this first, as MEMADDR may need adjustment. */
1456 if (readbuf
!= NULL
&& overlay_debugging
)
1458 struct obj_section
*section
= find_pc_overlay (memaddr
);
1460 if (pc_in_unmapped_range (memaddr
, section
))
1462 struct target_section_table
*table
1463 = target_get_section_table (ops
);
1464 const char *section_name
= section
->the_bfd_section
->name
;
1466 memaddr
= overlay_mapped_address (memaddr
, section
);
1467 return section_table_xfer_memory_partial (readbuf
, writebuf
,
1468 memaddr
, len
, xfered_len
,
1470 table
->sections_end
,
1475 /* Try the executable files, if "trust-readonly-sections" is set. */
1476 if (readbuf
!= NULL
&& trust_readonly
)
1478 struct target_section
*secp
;
1479 struct target_section_table
*table
;
1481 secp
= target_section_by_addr (ops
, memaddr
);
1483 && (bfd_get_section_flags (secp
->the_bfd_section
->owner
,
1484 secp
->the_bfd_section
)
1487 table
= target_get_section_table (ops
);
1488 return section_table_xfer_memory_partial (readbuf
, writebuf
,
1489 memaddr
, len
, xfered_len
,
1491 table
->sections_end
,
1496 /* If reading unavailable memory in the context of traceframes, and
1497 this address falls within a read-only section, fallback to
1498 reading from live memory. */
1499 if (readbuf
!= NULL
&& get_traceframe_number () != -1)
1501 VEC(mem_range_s
) *available
;
1503 /* If we fail to get the set of available memory, then the
1504 target does not support querying traceframe info, and so we
1505 attempt reading from the traceframe anyway (assuming the
1506 target implements the old QTro packet then). */
1507 if (traceframe_available_memory (&available
, memaddr
, len
))
1509 struct cleanup
*old_chain
;
1511 old_chain
= make_cleanup (VEC_cleanup(mem_range_s
), &available
);
1513 if (VEC_empty (mem_range_s
, available
)
1514 || VEC_index (mem_range_s
, available
, 0)->start
!= memaddr
)
1516 /* Don't read into the traceframe's available
1518 if (!VEC_empty (mem_range_s
, available
))
1520 LONGEST oldlen
= len
;
1522 len
= VEC_index (mem_range_s
, available
, 0)->start
- memaddr
;
1523 gdb_assert (len
<= oldlen
);
1526 do_cleanups (old_chain
);
1528 /* This goes through the topmost target again. */
1529 res
= memory_xfer_live_readonly_partial (ops
, object
,
1532 if (res
== TARGET_XFER_OK
)
1533 return TARGET_XFER_OK
;
1536 /* No use trying further, we know some memory starting
1537 at MEMADDR isn't available. */
1539 return TARGET_XFER_E_UNAVAILABLE
;
1543 /* Don't try to read more than how much is available, in
1544 case the target implements the deprecated QTro packet to
1545 cater for older GDBs (the target's knowledge of read-only
1546 sections may be outdated by now). */
1547 len
= VEC_index (mem_range_s
, available
, 0)->length
;
1549 do_cleanups (old_chain
);
1553 /* Try GDB's internal data cache. */
1554 region
= lookup_mem_region (memaddr
);
1555 /* region->hi == 0 means there's no upper bound. */
1556 if (memaddr
+ len
< region
->hi
|| region
->hi
== 0)
1559 reg_len
= region
->hi
- memaddr
;
1561 switch (region
->attrib
.mode
)
1564 if (writebuf
!= NULL
)
1565 return TARGET_XFER_E_IO
;
1569 if (readbuf
!= NULL
)
1570 return TARGET_XFER_E_IO
;
1574 /* We only support writing to flash during "load" for now. */
1575 if (writebuf
!= NULL
)
1576 error (_("Writing to flash memory forbidden in this context"));
1580 return TARGET_XFER_E_IO
;
1583 if (!ptid_equal (inferior_ptid
, null_ptid
))
1584 inf
= find_inferior_pid (ptid_get_pid (inferior_ptid
));
1589 /* The dcache reads whole cache lines; that doesn't play well
1590 with reading from a trace buffer, because reading outside of
1591 the collected memory range fails. */
1592 && get_traceframe_number () == -1
1593 && (region
->attrib
.cache
1594 || (stack_cache_enabled_p () && object
== TARGET_OBJECT_STACK_MEMORY
)
1595 || (code_cache_enabled_p () && object
== TARGET_OBJECT_CODE_MEMORY
)))
1597 DCACHE
*dcache
= target_dcache_get_or_init ();
1600 if (readbuf
!= NULL
)
1601 l
= dcache_xfer_memory (ops
, dcache
, memaddr
, readbuf
, reg_len
, 0);
1603 /* FIXME drow/2006-08-09: If we're going to preserve const
1604 correctness dcache_xfer_memory should take readbuf and
1606 l
= dcache_xfer_memory (ops
, dcache
, memaddr
, (void *) writebuf
,
1609 return TARGET_XFER_E_IO
;
1612 *xfered_len
= (ULONGEST
) l
;
1613 return TARGET_XFER_OK
;
1617 /* If none of those methods found the memory we wanted, fall back
1618 to a target partial transfer. Normally a single call to
1619 to_xfer_partial is enough; if it doesn't recognize an object
1620 it will call the to_xfer_partial of the next target down.
1621 But for memory this won't do. Memory is the only target
1622 object which can be read from more than one valid target.
1623 A core file, for instance, could have some of memory but
1624 delegate other bits to the target below it. So, we must
1625 manually try all targets. */
1627 res
= raw_memory_xfer_partial (ops
, readbuf
, writebuf
, memaddr
, reg_len
,
1630 /* Make sure the cache gets updated no matter what - if we are writing
1631 to the stack. Even if this write is not tagged as such, we still need
1632 to update the cache. */
1634 if (res
== TARGET_XFER_OK
1637 && target_dcache_init_p ()
1638 && !region
->attrib
.cache
1639 && ((stack_cache_enabled_p () && object
!= TARGET_OBJECT_STACK_MEMORY
)
1640 || (code_cache_enabled_p () && object
!= TARGET_OBJECT_CODE_MEMORY
)))
1642 DCACHE
*dcache
= target_dcache_get ();
1644 dcache_update (dcache
, memaddr
, (void *) writebuf
, reg_len
);
1647 /* If we still haven't got anything, return the last error. We
1652 /* Perform a partial memory transfer. For docs see target.h,
1655 static enum target_xfer_status
1656 memory_xfer_partial (struct target_ops
*ops
, enum target_object object
,
1657 gdb_byte
*readbuf
, const gdb_byte
*writebuf
,
1658 ULONGEST memaddr
, ULONGEST len
, ULONGEST
*xfered_len
)
1660 enum target_xfer_status res
;
1662 /* Zero length requests are ok and require no work. */
1664 return TARGET_XFER_EOF
;
1666 /* Fill in READBUF with breakpoint shadows, or WRITEBUF with
1667 breakpoint insns, thus hiding out from higher layers whether
1668 there are software breakpoints inserted in the code stream. */
1669 if (readbuf
!= NULL
)
1671 res
= memory_xfer_partial_1 (ops
, object
, readbuf
, NULL
, memaddr
, len
,
1674 if (res
== TARGET_XFER_OK
&& !show_memory_breakpoints
)
1675 breakpoint_xfer_memory (readbuf
, NULL
, NULL
, memaddr
, res
);
1680 struct cleanup
*old_chain
;
1682 /* A large write request is likely to be partially satisfied
1683 by memory_xfer_partial_1. We will continually malloc
1684 and free a copy of the entire write request for breakpoint
1685 shadow handling even though we only end up writing a small
1686 subset of it. Cap writes to 4KB to mitigate this. */
1687 len
= min (4096, len
);
1689 buf
= xmalloc (len
);
1690 old_chain
= make_cleanup (xfree
, buf
);
1691 memcpy (buf
, writebuf
, len
);
1693 breakpoint_xfer_memory (NULL
, buf
, writebuf
, memaddr
, len
);
1694 res
= memory_xfer_partial_1 (ops
, object
, NULL
, buf
, memaddr
, len
,
1697 do_cleanups (old_chain
);
1704 restore_show_memory_breakpoints (void *arg
)
1706 show_memory_breakpoints
= (uintptr_t) arg
;
1710 make_show_memory_breakpoints_cleanup (int show
)
1712 int current
= show_memory_breakpoints
;
1714 show_memory_breakpoints
= show
;
1715 return make_cleanup (restore_show_memory_breakpoints
,
1716 (void *) (uintptr_t) current
);
1719 /* For docs see target.h, to_xfer_partial. */
1721 enum target_xfer_status
1722 target_xfer_partial (struct target_ops
*ops
,
1723 enum target_object object
, const char *annex
,
1724 gdb_byte
*readbuf
, const gdb_byte
*writebuf
,
1725 ULONGEST offset
, ULONGEST len
,
1726 ULONGEST
*xfered_len
)
1728 enum target_xfer_status retval
;
1730 gdb_assert (ops
->to_xfer_partial
!= NULL
);
1732 /* Transfer is done when LEN is zero. */
1734 return TARGET_XFER_EOF
;
1736 if (writebuf
&& !may_write_memory
)
1737 error (_("Writing to memory is not allowed (addr %s, len %s)"),
1738 core_addr_to_string_nz (offset
), plongest (len
));
1742 /* If this is a memory transfer, let the memory-specific code
1743 have a look at it instead. Memory transfers are more
1745 if (object
== TARGET_OBJECT_MEMORY
|| object
== TARGET_OBJECT_STACK_MEMORY
1746 || object
== TARGET_OBJECT_CODE_MEMORY
)
1747 retval
= memory_xfer_partial (ops
, object
, readbuf
,
1748 writebuf
, offset
, len
, xfered_len
);
1749 else if (object
== TARGET_OBJECT_RAW_MEMORY
)
1751 /* Request the normal memory object from other layers. */
1752 retval
= raw_memory_xfer_partial (ops
, readbuf
, writebuf
, offset
, len
,
1756 retval
= ops
->to_xfer_partial (ops
, object
, annex
, readbuf
,
1757 writebuf
, offset
, len
, xfered_len
);
1761 const unsigned char *myaddr
= NULL
;
1763 fprintf_unfiltered (gdb_stdlog
,
1764 "%s:target_xfer_partial "
1765 "(%d, %s, %s, %s, %s, %s) = %d, %s",
1768 (annex
? annex
: "(null)"),
1769 host_address_to_string (readbuf
),
1770 host_address_to_string (writebuf
),
1771 core_addr_to_string_nz (offset
),
1772 pulongest (len
), retval
,
1773 pulongest (*xfered_len
));
1779 if (retval
== TARGET_XFER_OK
&& myaddr
!= NULL
)
1783 fputs_unfiltered (", bytes =", gdb_stdlog
);
1784 for (i
= 0; i
< *xfered_len
; i
++)
1786 if ((((intptr_t) &(myaddr
[i
])) & 0xf) == 0)
1788 if (targetdebug
< 2 && i
> 0)
1790 fprintf_unfiltered (gdb_stdlog
, " ...");
1793 fprintf_unfiltered (gdb_stdlog
, "\n");
1796 fprintf_unfiltered (gdb_stdlog
, " %02x", myaddr
[i
] & 0xff);
1800 fputc_unfiltered ('\n', gdb_stdlog
);
1803 /* Check implementations of to_xfer_partial update *XFERED_LEN
1804 properly. Do assertion after printing debug messages, so that we
1805 can find more clues on assertion failure from debugging messages. */
1806 if (retval
== TARGET_XFER_OK
|| retval
== TARGET_XFER_E_UNAVAILABLE
)
1807 gdb_assert (*xfered_len
> 0);
1812 /* Read LEN bytes of target memory at address MEMADDR, placing the
1813 results in GDB's memory at MYADDR. Returns either 0 for success or
1814 TARGET_XFER_E_IO if any error occurs.
1816 If an error occurs, no guarantee is made about the contents of the data at
1817 MYADDR. In particular, the caller should not depend upon partial reads
1818 filling the buffer with good data. There is no way for the caller to know
1819 how much good data might have been transfered anyway. Callers that can
1820 deal with partial reads should call target_read (which will retry until
1821 it makes no progress, and then return how much was transferred). */
1824 target_read_memory (CORE_ADDR memaddr
, gdb_byte
*myaddr
, ssize_t len
)
1826 /* Dispatch to the topmost target, not the flattened current_target.
1827 Memory accesses check target->to_has_(all_)memory, and the
1828 flattened target doesn't inherit those. */
1829 if (target_read (current_target
.beneath
, TARGET_OBJECT_MEMORY
, NULL
,
1830 myaddr
, memaddr
, len
) == len
)
1833 return TARGET_XFER_E_IO
;
1836 /* Like target_read_memory, but specify explicitly that this is a read
1837 from the target's raw memory. That is, this read bypasses the
1838 dcache, breakpoint shadowing, etc. */
1841 target_read_raw_memory (CORE_ADDR memaddr
, gdb_byte
*myaddr
, ssize_t len
)
1843 /* See comment in target_read_memory about why the request starts at
1844 current_target.beneath. */
1845 if (target_read (current_target
.beneath
, TARGET_OBJECT_RAW_MEMORY
, NULL
,
1846 myaddr
, memaddr
, len
) == len
)
1849 return TARGET_XFER_E_IO
;
1852 /* Like target_read_memory, but specify explicitly that this is a read from
1853 the target's stack. This may trigger different cache behavior. */
1856 target_read_stack (CORE_ADDR memaddr
, gdb_byte
*myaddr
, ssize_t len
)
1858 /* See comment in target_read_memory about why the request starts at
1859 current_target.beneath. */
1860 if (target_read (current_target
.beneath
, TARGET_OBJECT_STACK_MEMORY
, NULL
,
1861 myaddr
, memaddr
, len
) == len
)
1864 return TARGET_XFER_E_IO
;
1867 /* Like target_read_memory, but specify explicitly that this is a read from
1868 the target's code. This may trigger different cache behavior. */
1871 target_read_code (CORE_ADDR memaddr
, gdb_byte
*myaddr
, ssize_t len
)
1873 /* See comment in target_read_memory about why the request starts at
1874 current_target.beneath. */
1875 if (target_read (current_target
.beneath
, TARGET_OBJECT_CODE_MEMORY
, NULL
,
1876 myaddr
, memaddr
, len
) == len
)
1879 return TARGET_XFER_E_IO
;
1882 /* Write LEN bytes from MYADDR to target memory at address MEMADDR.
1883 Returns either 0 for success or TARGET_XFER_E_IO if any
1884 error occurs. If an error occurs, no guarantee is made about how
1885 much data got written. Callers that can deal with partial writes
1886 should call target_write. */
1889 target_write_memory (CORE_ADDR memaddr
, const gdb_byte
*myaddr
, ssize_t len
)
1891 /* See comment in target_read_memory about why the request starts at
1892 current_target.beneath. */
1893 if (target_write (current_target
.beneath
, TARGET_OBJECT_MEMORY
, NULL
,
1894 myaddr
, memaddr
, len
) == len
)
1897 return TARGET_XFER_E_IO
;
1900 /* Write LEN bytes from MYADDR to target raw memory at address
1901 MEMADDR. Returns either 0 for success or TARGET_XFER_E_IO
1902 if any error occurs. If an error occurs, no guarantee is made
1903 about how much data got written. Callers that can deal with
1904 partial writes should call target_write. */
1907 target_write_raw_memory (CORE_ADDR memaddr
, const gdb_byte
*myaddr
, ssize_t len
)
1909 /* See comment in target_read_memory about why the request starts at
1910 current_target.beneath. */
1911 if (target_write (current_target
.beneath
, TARGET_OBJECT_RAW_MEMORY
, NULL
,
1912 myaddr
, memaddr
, len
) == len
)
1915 return TARGET_XFER_E_IO
;
1918 /* Fetch the target's memory map. */
1921 target_memory_map (void)
1923 VEC(mem_region_s
) *result
;
1924 struct mem_region
*last_one
, *this_one
;
1926 struct target_ops
*t
;
1929 fprintf_unfiltered (gdb_stdlog
, "target_memory_map ()\n");
1931 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
1932 if (t
->to_memory_map
!= NULL
)
1938 result
= t
->to_memory_map (t
);
1942 qsort (VEC_address (mem_region_s
, result
),
1943 VEC_length (mem_region_s
, result
),
1944 sizeof (struct mem_region
), mem_region_cmp
);
1946 /* Check that regions do not overlap. Simultaneously assign
1947 a numbering for the "mem" commands to use to refer to
1950 for (ix
= 0; VEC_iterate (mem_region_s
, result
, ix
, this_one
); ix
++)
1952 this_one
->number
= ix
;
1954 if (last_one
&& last_one
->hi
> this_one
->lo
)
1956 warning (_("Overlapping regions in memory map: ignoring"));
1957 VEC_free (mem_region_s
, result
);
1960 last_one
= this_one
;
1967 target_flash_erase (ULONGEST address
, LONGEST length
)
1969 struct target_ops
*t
;
1971 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
1972 if (t
->to_flash_erase
!= NULL
)
1975 fprintf_unfiltered (gdb_stdlog
, "target_flash_erase (%s, %s)\n",
1976 hex_string (address
), phex (length
, 0));
1977 t
->to_flash_erase (t
, address
, length
);
1985 target_flash_done (void)
1987 struct target_ops
*t
;
1989 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
1990 if (t
->to_flash_done
!= NULL
)
1993 fprintf_unfiltered (gdb_stdlog
, "target_flash_done\n");
1994 t
->to_flash_done (t
);
2002 show_trust_readonly (struct ui_file
*file
, int from_tty
,
2003 struct cmd_list_element
*c
, const char *value
)
2005 fprintf_filtered (file
,
2006 _("Mode for reading from readonly sections is %s.\n"),
2010 /* More generic transfers. */
2012 static enum target_xfer_status
2013 default_xfer_partial (struct target_ops
*ops
, enum target_object object
,
2014 const char *annex
, gdb_byte
*readbuf
,
2015 const gdb_byte
*writebuf
, ULONGEST offset
, ULONGEST len
,
2016 ULONGEST
*xfered_len
)
2018 if (object
== TARGET_OBJECT_MEMORY
2019 && ops
->deprecated_xfer_memory
!= NULL
)
2020 /* If available, fall back to the target's
2021 "deprecated_xfer_memory" method. */
2026 if (writebuf
!= NULL
)
2028 void *buffer
= xmalloc (len
);
2029 struct cleanup
*cleanup
= make_cleanup (xfree
, buffer
);
2031 memcpy (buffer
, writebuf
, len
);
2032 xfered
= ops
->deprecated_xfer_memory (offset
, buffer
, len
,
2033 1/*write*/, NULL
, ops
);
2034 do_cleanups (cleanup
);
2036 if (readbuf
!= NULL
)
2037 xfered
= ops
->deprecated_xfer_memory (offset
, readbuf
, len
,
2038 0/*read*/, NULL
, ops
);
2041 *xfered_len
= (ULONGEST
) xfered
;
2042 return TARGET_XFER_E_IO
;
2044 else if (xfered
== 0 && errno
== 0)
2045 /* "deprecated_xfer_memory" uses 0, cross checked against
2046 ERRNO as one indication of an error. */
2047 return TARGET_XFER_EOF
;
2049 return TARGET_XFER_E_IO
;
2053 gdb_assert (ops
->beneath
!= NULL
);
2054 return ops
->beneath
->to_xfer_partial (ops
->beneath
, object
, annex
,
2055 readbuf
, writebuf
, offset
, len
,
2060 /* Target vector read/write partial wrapper functions. */
2062 static enum target_xfer_status
2063 target_read_partial (struct target_ops
*ops
,
2064 enum target_object object
,
2065 const char *annex
, gdb_byte
*buf
,
2066 ULONGEST offset
, ULONGEST len
,
2067 ULONGEST
*xfered_len
)
2069 return target_xfer_partial (ops
, object
, annex
, buf
, NULL
, offset
, len
,
2073 static enum target_xfer_status
2074 target_write_partial (struct target_ops
*ops
,
2075 enum target_object object
,
2076 const char *annex
, const gdb_byte
*buf
,
2077 ULONGEST offset
, LONGEST len
, ULONGEST
*xfered_len
)
2079 return target_xfer_partial (ops
, object
, annex
, NULL
, buf
, offset
, len
,
2083 /* Wrappers to perform the full transfer. */
2085 /* For docs on target_read see target.h. */
2088 target_read (struct target_ops
*ops
,
2089 enum target_object object
,
2090 const char *annex
, gdb_byte
*buf
,
2091 ULONGEST offset
, LONGEST len
)
2095 while (xfered
< len
)
2097 ULONGEST xfered_len
;
2098 enum target_xfer_status status
;
2100 status
= target_read_partial (ops
, object
, annex
,
2101 (gdb_byte
*) buf
+ xfered
,
2102 offset
+ xfered
, len
- xfered
,
2105 /* Call an observer, notifying them of the xfer progress? */
2106 if (status
== TARGET_XFER_EOF
)
2108 else if (status
== TARGET_XFER_OK
)
2110 xfered
+= xfered_len
;
2120 /* Assuming that the entire [begin, end) range of memory cannot be
2121 read, try to read whatever subrange is possible to read.
2123 The function returns, in RESULT, either zero or one memory block.
2124 If there's a readable subrange at the beginning, it is completely
2125 read and returned. Any further readable subrange will not be read.
2126 Otherwise, if there's a readable subrange at the end, it will be
2127 completely read and returned. Any readable subranges before it
2128 (obviously, not starting at the beginning), will be ignored. In
2129 other cases -- either no readable subrange, or readable subrange(s)
2130 that is neither at the beginning, or end, nothing is returned.
2132 The purpose of this function is to handle a read across a boundary
2133 of accessible memory in a case when memory map is not available.
2134 The above restrictions are fine for this case, but will give
2135 incorrect results if the memory is 'patchy'. However, supporting
2136 'patchy' memory would require trying to read every single byte,
2137 and it seems unacceptable solution. Explicit memory map is
2138 recommended for this case -- and target_read_memory_robust will
2139 take care of reading multiple ranges then. */
2142 read_whatever_is_readable (struct target_ops
*ops
,
2143 ULONGEST begin
, ULONGEST end
,
2144 VEC(memory_read_result_s
) **result
)
2146 gdb_byte
*buf
= xmalloc (end
- begin
);
2147 ULONGEST current_begin
= begin
;
2148 ULONGEST current_end
= end
;
2150 memory_read_result_s r
;
2151 ULONGEST xfered_len
;
2153 /* If we previously failed to read 1 byte, nothing can be done here. */
2154 if (end
- begin
<= 1)
2160 /* Check that either first or the last byte is readable, and give up
2161 if not. This heuristic is meant to permit reading accessible memory
2162 at the boundary of accessible region. */
2163 if (target_read_partial (ops
, TARGET_OBJECT_MEMORY
, NULL
,
2164 buf
, begin
, 1, &xfered_len
) == TARGET_XFER_OK
)
2169 else if (target_read_partial (ops
, TARGET_OBJECT_MEMORY
, NULL
,
2170 buf
+ (end
-begin
) - 1, end
- 1, 1,
2171 &xfered_len
) == TARGET_XFER_OK
)
2182 /* Loop invariant is that the [current_begin, current_end) was previously
2183 found to be not readable as a whole.
2185 Note loop condition -- if the range has 1 byte, we can't divide the range
2186 so there's no point trying further. */
2187 while (current_end
- current_begin
> 1)
2189 ULONGEST first_half_begin
, first_half_end
;
2190 ULONGEST second_half_begin
, second_half_end
;
2192 ULONGEST middle
= current_begin
+ (current_end
- current_begin
)/2;
2196 first_half_begin
= current_begin
;
2197 first_half_end
= middle
;
2198 second_half_begin
= middle
;
2199 second_half_end
= current_end
;
2203 first_half_begin
= middle
;
2204 first_half_end
= current_end
;
2205 second_half_begin
= current_begin
;
2206 second_half_end
= middle
;
2209 xfer
= target_read (ops
, TARGET_OBJECT_MEMORY
, NULL
,
2210 buf
+ (first_half_begin
- begin
),
2212 first_half_end
- first_half_begin
);
2214 if (xfer
== first_half_end
- first_half_begin
)
2216 /* This half reads up fine. So, the error must be in the
2218 current_begin
= second_half_begin
;
2219 current_end
= second_half_end
;
2223 /* This half is not readable. Because we've tried one byte, we
2224 know some part of this half if actually redable. Go to the next
2225 iteration to divide again and try to read.
2227 We don't handle the other half, because this function only tries
2228 to read a single readable subrange. */
2229 current_begin
= first_half_begin
;
2230 current_end
= first_half_end
;
2236 /* The [begin, current_begin) range has been read. */
2238 r
.end
= current_begin
;
2243 /* The [current_end, end) range has been read. */
2244 LONGEST rlen
= end
- current_end
;
2246 r
.data
= xmalloc (rlen
);
2247 memcpy (r
.data
, buf
+ current_end
- begin
, rlen
);
2248 r
.begin
= current_end
;
2252 VEC_safe_push(memory_read_result_s
, (*result
), &r
);
2256 free_memory_read_result_vector (void *x
)
2258 VEC(memory_read_result_s
) *v
= x
;
2259 memory_read_result_s
*current
;
2262 for (ix
= 0; VEC_iterate (memory_read_result_s
, v
, ix
, current
); ++ix
)
2264 xfree (current
->data
);
2266 VEC_free (memory_read_result_s
, v
);
2269 VEC(memory_read_result_s
) *
2270 read_memory_robust (struct target_ops
*ops
, ULONGEST offset
, LONGEST len
)
2272 VEC(memory_read_result_s
) *result
= 0;
2275 while (xfered
< len
)
2277 struct mem_region
*region
= lookup_mem_region (offset
+ xfered
);
2280 /* If there is no explicit region, a fake one should be created. */
2281 gdb_assert (region
);
2283 if (region
->hi
== 0)
2284 rlen
= len
- xfered
;
2286 rlen
= region
->hi
- offset
;
2288 if (region
->attrib
.mode
== MEM_NONE
|| region
->attrib
.mode
== MEM_WO
)
2290 /* Cannot read this region. Note that we can end up here only
2291 if the region is explicitly marked inaccessible, or
2292 'inaccessible-by-default' is in effect. */
2297 LONGEST to_read
= min (len
- xfered
, rlen
);
2298 gdb_byte
*buffer
= (gdb_byte
*)xmalloc (to_read
);
2300 LONGEST xfer
= target_read (ops
, TARGET_OBJECT_MEMORY
, NULL
,
2301 (gdb_byte
*) buffer
,
2302 offset
+ xfered
, to_read
);
2303 /* Call an observer, notifying them of the xfer progress? */
2306 /* Got an error reading full chunk. See if maybe we can read
2309 read_whatever_is_readable (ops
, offset
+ xfered
,
2310 offset
+ xfered
+ to_read
, &result
);
2315 struct memory_read_result r
;
2317 r
.begin
= offset
+ xfered
;
2318 r
.end
= r
.begin
+ xfer
;
2319 VEC_safe_push (memory_read_result_s
, result
, &r
);
2329 /* An alternative to target_write with progress callbacks. */
2332 target_write_with_progress (struct target_ops
*ops
,
2333 enum target_object object
,
2334 const char *annex
, const gdb_byte
*buf
,
2335 ULONGEST offset
, LONGEST len
,
2336 void (*progress
) (ULONGEST
, void *), void *baton
)
2340 /* Give the progress callback a chance to set up. */
2342 (*progress
) (0, baton
);
2344 while (xfered
< len
)
2346 ULONGEST xfered_len
;
2347 enum target_xfer_status status
;
2349 status
= target_write_partial (ops
, object
, annex
,
2350 (gdb_byte
*) buf
+ xfered
,
2351 offset
+ xfered
, len
- xfered
,
2354 if (status
== TARGET_XFER_EOF
)
2356 if (TARGET_XFER_STATUS_ERROR_P (status
))
2359 gdb_assert (status
== TARGET_XFER_OK
);
2361 (*progress
) (xfered_len
, baton
);
2363 xfered
+= xfered_len
;
2369 /* For docs on target_write see target.h. */
2372 target_write (struct target_ops
*ops
,
2373 enum target_object object
,
2374 const char *annex
, const gdb_byte
*buf
,
2375 ULONGEST offset
, LONGEST len
)
2377 return target_write_with_progress (ops
, object
, annex
, buf
, offset
, len
,
2381 /* Read OBJECT/ANNEX using OPS. Store the result in *BUF_P and return
2382 the size of the transferred data. PADDING additional bytes are
2383 available in *BUF_P. This is a helper function for
2384 target_read_alloc; see the declaration of that function for more
2388 target_read_alloc_1 (struct target_ops
*ops
, enum target_object object
,
2389 const char *annex
, gdb_byte
**buf_p
, int padding
)
2391 size_t buf_alloc
, buf_pos
;
2394 /* This function does not have a length parameter; it reads the
2395 entire OBJECT). Also, it doesn't support objects fetched partly
2396 from one target and partly from another (in a different stratum,
2397 e.g. a core file and an executable). Both reasons make it
2398 unsuitable for reading memory. */
2399 gdb_assert (object
!= TARGET_OBJECT_MEMORY
);
2401 /* Start by reading up to 4K at a time. The target will throttle
2402 this number down if necessary. */
2404 buf
= xmalloc (buf_alloc
);
2408 ULONGEST xfered_len
;
2409 enum target_xfer_status status
;
2411 status
= target_read_partial (ops
, object
, annex
, &buf
[buf_pos
],
2412 buf_pos
, buf_alloc
- buf_pos
- padding
,
2415 if (status
== TARGET_XFER_EOF
)
2417 /* Read all there was. */
2424 else if (status
!= TARGET_XFER_OK
)
2426 /* An error occurred. */
2428 return TARGET_XFER_E_IO
;
2431 buf_pos
+= xfered_len
;
2433 /* If the buffer is filling up, expand it. */
2434 if (buf_alloc
< buf_pos
* 2)
2437 buf
= xrealloc (buf
, buf_alloc
);
2444 /* Read OBJECT/ANNEX using OPS. Store the result in *BUF_P and return
2445 the size of the transferred data. See the declaration in "target.h"
2446 function for more information about the return value. */
2449 target_read_alloc (struct target_ops
*ops
, enum target_object object
,
2450 const char *annex
, gdb_byte
**buf_p
)
2452 return target_read_alloc_1 (ops
, object
, annex
, buf_p
, 0);
2455 /* Read OBJECT/ANNEX using OPS. The result is NUL-terminated and
2456 returned as a string, allocated using xmalloc. If an error occurs
2457 or the transfer is unsupported, NULL is returned. Empty objects
2458 are returned as allocated but empty strings. A warning is issued
2459 if the result contains any embedded NUL bytes. */
2462 target_read_stralloc (struct target_ops
*ops
, enum target_object object
,
2467 LONGEST i
, transferred
;
2469 transferred
= target_read_alloc_1 (ops
, object
, annex
, &buffer
, 1);
2470 bufstr
= (char *) buffer
;
2472 if (transferred
< 0)
2475 if (transferred
== 0)
2476 return xstrdup ("");
2478 bufstr
[transferred
] = 0;
2480 /* Check for embedded NUL bytes; but allow trailing NULs. */
2481 for (i
= strlen (bufstr
); i
< transferred
; i
++)
2484 warning (_("target object %d, annex %s, "
2485 "contained unexpected null characters"),
2486 (int) object
, annex
? annex
: "(none)");
2493 /* Memory transfer methods. */
2496 get_target_memory (struct target_ops
*ops
, CORE_ADDR addr
, gdb_byte
*buf
,
2499 /* This method is used to read from an alternate, non-current
2500 target. This read must bypass the overlay support (as symbols
2501 don't match this target), and GDB's internal cache (wrong cache
2502 for this target). */
2503 if (target_read (ops
, TARGET_OBJECT_RAW_MEMORY
, NULL
, buf
, addr
, len
)
2505 memory_error (TARGET_XFER_E_IO
, addr
);
2509 get_target_memory_unsigned (struct target_ops
*ops
, CORE_ADDR addr
,
2510 int len
, enum bfd_endian byte_order
)
2512 gdb_byte buf
[sizeof (ULONGEST
)];
2514 gdb_assert (len
<= sizeof (buf
));
2515 get_target_memory (ops
, addr
, buf
, len
);
2516 return extract_unsigned_integer (buf
, len
, byte_order
);
2522 target_insert_breakpoint (struct gdbarch
*gdbarch
,
2523 struct bp_target_info
*bp_tgt
)
2525 if (!may_insert_breakpoints
)
2527 warning (_("May not insert breakpoints"));
2531 return current_target
.to_insert_breakpoint (¤t_target
,
2538 target_remove_breakpoint (struct gdbarch
*gdbarch
,
2539 struct bp_target_info
*bp_tgt
)
2541 /* This is kind of a weird case to handle, but the permission might
2542 have been changed after breakpoints were inserted - in which case
2543 we should just take the user literally and assume that any
2544 breakpoints should be left in place. */
2545 if (!may_insert_breakpoints
)
2547 warning (_("May not remove breakpoints"));
2551 return current_target
.to_remove_breakpoint (¤t_target
,
2556 target_info (char *args
, int from_tty
)
2558 struct target_ops
*t
;
2559 int has_all_mem
= 0;
2561 if (symfile_objfile
!= NULL
)
2562 printf_unfiltered (_("Symbols from \"%s\".\n"),
2563 objfile_name (symfile_objfile
));
2565 for (t
= target_stack
; t
!= NULL
; t
= t
->beneath
)
2567 if (!(*t
->to_has_memory
) (t
))
2570 if ((int) (t
->to_stratum
) <= (int) dummy_stratum
)
2573 printf_unfiltered (_("\tWhile running this, "
2574 "GDB does not access memory from...\n"));
2575 printf_unfiltered ("%s:\n", t
->to_longname
);
2576 (t
->to_files_info
) (t
);
2577 has_all_mem
= (*t
->to_has_all_memory
) (t
);
2581 /* This function is called before any new inferior is created, e.g.
2582 by running a program, attaching, or connecting to a target.
2583 It cleans up any state from previous invocations which might
2584 change between runs. This is a subset of what target_preopen
2585 resets (things which might change between targets). */
2588 target_pre_inferior (int from_tty
)
2590 /* Clear out solib state. Otherwise the solib state of the previous
2591 inferior might have survived and is entirely wrong for the new
2592 target. This has been observed on GNU/Linux using glibc 2.3. How
2604 Cannot access memory at address 0xdeadbeef
2607 /* In some OSs, the shared library list is the same/global/shared
2608 across inferiors. If code is shared between processes, so are
2609 memory regions and features. */
2610 if (!gdbarch_has_global_solist (target_gdbarch ()))
2612 no_shared_libraries (NULL
, from_tty
);
2614 invalidate_target_mem_regions ();
2616 target_clear_description ();
2619 agent_capability_invalidate ();
2622 /* Callback for iterate_over_inferiors. Gets rid of the given
2626 dispose_inferior (struct inferior
*inf
, void *args
)
2628 struct thread_info
*thread
;
2630 thread
= any_thread_of_process (inf
->pid
);
2633 switch_to_thread (thread
->ptid
);
2635 /* Core inferiors actually should be detached, not killed. */
2636 if (target_has_execution
)
2639 target_detach (NULL
, 0);
2645 /* This is to be called by the open routine before it does
2649 target_preopen (int from_tty
)
2653 if (have_inferiors ())
2656 || !have_live_inferiors ()
2657 || query (_("A program is being debugged already. Kill it? ")))
2658 iterate_over_inferiors (dispose_inferior
, NULL
);
2660 error (_("Program not killed."));
2663 /* Calling target_kill may remove the target from the stack. But if
2664 it doesn't (which seems like a win for UDI), remove it now. */
2665 /* Leave the exec target, though. The user may be switching from a
2666 live process to a core of the same program. */
2667 pop_all_targets_above (file_stratum
);
2669 target_pre_inferior (from_tty
);
2672 /* Detach a target after doing deferred register stores. */
2675 target_detach (const char *args
, int from_tty
)
2677 struct target_ops
* t
;
2679 if (gdbarch_has_global_breakpoints (target_gdbarch ()))
2680 /* Don't remove global breakpoints here. They're removed on
2681 disconnection from the target. */
2684 /* If we're in breakpoints-always-inserted mode, have to remove
2685 them before detaching. */
2686 remove_breakpoints_pid (ptid_get_pid (inferior_ptid
));
2688 prepare_for_detach ();
2690 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
2692 if (t
->to_detach
!= NULL
)
2694 t
->to_detach (t
, args
, from_tty
);
2696 fprintf_unfiltered (gdb_stdlog
, "target_detach (%s, %d)\n",
2702 internal_error (__FILE__
, __LINE__
, _("could not find a target to detach"));
2706 target_disconnect (char *args
, int from_tty
)
2708 struct target_ops
*t
;
2710 /* If we're in breakpoints-always-inserted mode or if breakpoints
2711 are global across processes, we have to remove them before
2713 remove_breakpoints ();
2715 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
2716 if (t
->to_disconnect
!= NULL
)
2719 fprintf_unfiltered (gdb_stdlog
, "target_disconnect (%s, %d)\n",
2721 t
->to_disconnect (t
, args
, from_tty
);
2729 target_wait (ptid_t ptid
, struct target_waitstatus
*status
, int options
)
2731 struct target_ops
*t
;
2732 ptid_t retval
= (current_target
.to_wait
) (¤t_target
, ptid
,
2737 char *status_string
;
2738 char *options_string
;
2740 status_string
= target_waitstatus_to_string (status
);
2741 options_string
= target_options_to_string (options
);
2742 fprintf_unfiltered (gdb_stdlog
,
2743 "target_wait (%d, status, options={%s})"
2745 ptid_get_pid (ptid
), options_string
,
2746 ptid_get_pid (retval
), status_string
);
2747 xfree (status_string
);
2748 xfree (options_string
);
2755 target_pid_to_str (ptid_t ptid
)
2757 struct target_ops
*t
;
2759 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
2761 if (t
->to_pid_to_str
!= NULL
)
2762 return (*t
->to_pid_to_str
) (t
, ptid
);
2765 return normal_pid_to_str (ptid
);
2769 target_thread_name (struct thread_info
*info
)
2771 struct target_ops
*t
;
2773 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
2775 if (t
->to_thread_name
!= NULL
)
2776 return (*t
->to_thread_name
) (t
, info
);
2783 target_resume (ptid_t ptid
, int step
, enum gdb_signal signal
)
2785 struct target_ops
*t
;
2787 target_dcache_invalidate ();
2789 current_target
.to_resume (¤t_target
, ptid
, step
, signal
);
2791 fprintf_unfiltered (gdb_stdlog
, "target_resume (%d, %s, %s)\n",
2792 ptid_get_pid (ptid
),
2793 step
? "step" : "continue",
2794 gdb_signal_to_name (signal
));
2796 registers_changed_ptid (ptid
);
2797 set_executing (ptid
, 1);
2798 set_running (ptid
, 1);
2799 clear_inline_frame_state (ptid
);
2803 target_pass_signals (int numsigs
, unsigned char *pass_signals
)
2805 struct target_ops
*t
;
2807 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
2809 if (t
->to_pass_signals
!= NULL
)
2815 fprintf_unfiltered (gdb_stdlog
, "target_pass_signals (%d, {",
2818 for (i
= 0; i
< numsigs
; i
++)
2819 if (pass_signals
[i
])
2820 fprintf_unfiltered (gdb_stdlog
, " %s",
2821 gdb_signal_to_name (i
));
2823 fprintf_unfiltered (gdb_stdlog
, " })\n");
2826 (*t
->to_pass_signals
) (t
, numsigs
, pass_signals
);
2833 target_program_signals (int numsigs
, unsigned char *program_signals
)
2835 struct target_ops
*t
;
2837 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
2839 if (t
->to_program_signals
!= NULL
)
2845 fprintf_unfiltered (gdb_stdlog
, "target_program_signals (%d, {",
2848 for (i
= 0; i
< numsigs
; i
++)
2849 if (program_signals
[i
])
2850 fprintf_unfiltered (gdb_stdlog
, " %s",
2851 gdb_signal_to_name (i
));
2853 fprintf_unfiltered (gdb_stdlog
, " })\n");
2856 (*t
->to_program_signals
) (t
, numsigs
, program_signals
);
2862 /* Look through the list of possible targets for a target that can
2866 target_follow_fork (int follow_child
, int detach_fork
)
2868 struct target_ops
*t
;
2870 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
2872 if (t
->to_follow_fork
!= NULL
)
2874 int retval
= t
->to_follow_fork (t
, follow_child
, detach_fork
);
2877 fprintf_unfiltered (gdb_stdlog
,
2878 "target_follow_fork (%d, %d) = %d\n",
2879 follow_child
, detach_fork
, retval
);
2884 /* Some target returned a fork event, but did not know how to follow it. */
2885 internal_error (__FILE__
, __LINE__
,
2886 _("could not find a target to follow fork"));
2890 target_mourn_inferior (void)
2892 struct target_ops
*t
;
2894 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
2896 if (t
->to_mourn_inferior
!= NULL
)
2898 t
->to_mourn_inferior (t
);
2900 fprintf_unfiltered (gdb_stdlog
, "target_mourn_inferior ()\n");
2902 /* We no longer need to keep handles on any of the object files.
2903 Make sure to release them to avoid unnecessarily locking any
2904 of them while we're not actually debugging. */
2905 bfd_cache_close_all ();
2911 internal_error (__FILE__
, __LINE__
,
2912 _("could not find a target to follow mourn inferior"));
2915 /* Look for a target which can describe architectural features, starting
2916 from TARGET. If we find one, return its description. */
2918 const struct target_desc
*
2919 target_read_description (struct target_ops
*target
)
2921 struct target_ops
*t
;
2923 for (t
= target
; t
!= NULL
; t
= t
->beneath
)
2924 if (t
->to_read_description
!= NULL
)
2926 const struct target_desc
*tdesc
;
2928 tdesc
= t
->to_read_description (t
);
2936 /* The default implementation of to_search_memory.
2937 This implements a basic search of memory, reading target memory and
2938 performing the search here (as opposed to performing the search in on the
2939 target side with, for example, gdbserver). */
2942 simple_search_memory (struct target_ops
*ops
,
2943 CORE_ADDR start_addr
, ULONGEST search_space_len
,
2944 const gdb_byte
*pattern
, ULONGEST pattern_len
,
2945 CORE_ADDR
*found_addrp
)
2947 /* NOTE: also defined in find.c testcase. */
2948 #define SEARCH_CHUNK_SIZE 16000
2949 const unsigned chunk_size
= SEARCH_CHUNK_SIZE
;
2950 /* Buffer to hold memory contents for searching. */
2951 gdb_byte
*search_buf
;
2952 unsigned search_buf_size
;
2953 struct cleanup
*old_cleanups
;
2955 search_buf_size
= chunk_size
+ pattern_len
- 1;
2957 /* No point in trying to allocate a buffer larger than the search space. */
2958 if (search_space_len
< search_buf_size
)
2959 search_buf_size
= search_space_len
;
2961 search_buf
= malloc (search_buf_size
);
2962 if (search_buf
== NULL
)
2963 error (_("Unable to allocate memory to perform the search."));
2964 old_cleanups
= make_cleanup (free_current_contents
, &search_buf
);
2966 /* Prime the search buffer. */
2968 if (target_read (ops
, TARGET_OBJECT_MEMORY
, NULL
,
2969 search_buf
, start_addr
, search_buf_size
) != search_buf_size
)
2971 warning (_("Unable to access %s bytes of target "
2972 "memory at %s, halting search."),
2973 pulongest (search_buf_size
), hex_string (start_addr
));
2974 do_cleanups (old_cleanups
);
2978 /* Perform the search.
2980 The loop is kept simple by allocating [N + pattern-length - 1] bytes.
2981 When we've scanned N bytes we copy the trailing bytes to the start and
2982 read in another N bytes. */
2984 while (search_space_len
>= pattern_len
)
2986 gdb_byte
*found_ptr
;
2987 unsigned nr_search_bytes
= min (search_space_len
, search_buf_size
);
2989 found_ptr
= memmem (search_buf
, nr_search_bytes
,
2990 pattern
, pattern_len
);
2992 if (found_ptr
!= NULL
)
2994 CORE_ADDR found_addr
= start_addr
+ (found_ptr
- search_buf
);
2996 *found_addrp
= found_addr
;
2997 do_cleanups (old_cleanups
);
3001 /* Not found in this chunk, skip to next chunk. */
3003 /* Don't let search_space_len wrap here, it's unsigned. */
3004 if (search_space_len
>= chunk_size
)
3005 search_space_len
-= chunk_size
;
3007 search_space_len
= 0;
3009 if (search_space_len
>= pattern_len
)
3011 unsigned keep_len
= search_buf_size
- chunk_size
;
3012 CORE_ADDR read_addr
= start_addr
+ chunk_size
+ keep_len
;
3015 /* Copy the trailing part of the previous iteration to the front
3016 of the buffer for the next iteration. */
3017 gdb_assert (keep_len
== pattern_len
- 1);
3018 memcpy (search_buf
, search_buf
+ chunk_size
, keep_len
);
3020 nr_to_read
= min (search_space_len
- keep_len
, chunk_size
);
3022 if (target_read (ops
, TARGET_OBJECT_MEMORY
, NULL
,
3023 search_buf
+ keep_len
, read_addr
,
3024 nr_to_read
) != nr_to_read
)
3026 warning (_("Unable to access %s bytes of target "
3027 "memory at %s, halting search."),
3028 plongest (nr_to_read
),
3029 hex_string (read_addr
));
3030 do_cleanups (old_cleanups
);
3034 start_addr
+= chunk_size
;
3040 do_cleanups (old_cleanups
);
3044 /* Search SEARCH_SPACE_LEN bytes beginning at START_ADDR for the
3045 sequence of bytes in PATTERN with length PATTERN_LEN.
3047 The result is 1 if found, 0 if not found, and -1 if there was an error
3048 requiring halting of the search (e.g. memory read error).
3049 If the pattern is found the address is recorded in FOUND_ADDRP. */
3052 target_search_memory (CORE_ADDR start_addr
, ULONGEST search_space_len
,
3053 const gdb_byte
*pattern
, ULONGEST pattern_len
,
3054 CORE_ADDR
*found_addrp
)
3056 struct target_ops
*t
;
3059 /* We don't use INHERIT to set current_target.to_search_memory,
3060 so we have to scan the target stack and handle targetdebug
3064 fprintf_unfiltered (gdb_stdlog
, "target_search_memory (%s, ...)\n",
3065 hex_string (start_addr
));
3067 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
3068 if (t
->to_search_memory
!= NULL
)
3073 found
= t
->to_search_memory (t
, start_addr
, search_space_len
,
3074 pattern
, pattern_len
, found_addrp
);
3078 /* If a special version of to_search_memory isn't available, use the
3080 found
= simple_search_memory (current_target
.beneath
,
3081 start_addr
, search_space_len
,
3082 pattern
, pattern_len
, found_addrp
);
3086 fprintf_unfiltered (gdb_stdlog
, " = %d\n", found
);
3091 /* Look through the currently pushed targets. If none of them will
3092 be able to restart the currently running process, issue an error
3096 target_require_runnable (void)
3098 struct target_ops
*t
;
3100 for (t
= target_stack
; t
!= NULL
; t
= t
->beneath
)
3102 /* If this target knows how to create a new program, then
3103 assume we will still be able to after killing the current
3104 one. Either killing and mourning will not pop T, or else
3105 find_default_run_target will find it again. */
3106 if (t
->to_create_inferior
!= NULL
)
3109 /* Do not worry about thread_stratum targets that can not
3110 create inferiors. Assume they will be pushed again if
3111 necessary, and continue to the process_stratum. */
3112 if (t
->to_stratum
== thread_stratum
3113 || t
->to_stratum
== arch_stratum
)
3116 error (_("The \"%s\" target does not support \"run\". "
3117 "Try \"help target\" or \"continue\"."),
3121 /* This function is only called if the target is running. In that
3122 case there should have been a process_stratum target and it
3123 should either know how to create inferiors, or not... */
3124 internal_error (__FILE__
, __LINE__
, _("No targets found"));
3127 /* Look through the list of possible targets for a target that can
3128 execute a run or attach command without any other data. This is
3129 used to locate the default process stratum.
3131 If DO_MESG is not NULL, the result is always valid (error() is
3132 called for errors); else, return NULL on error. */
3134 static struct target_ops
*
3135 find_default_run_target (char *do_mesg
)
3137 struct target_ops
**t
;
3138 struct target_ops
*runable
= NULL
;
3143 for (t
= target_structs
; t
< target_structs
+ target_struct_size
;
3146 if ((*t
)->to_can_run
&& target_can_run (*t
))
3156 error (_("Don't know how to %s. Try \"help target\"."), do_mesg
);
3165 find_default_attach (struct target_ops
*ops
, char *args
, int from_tty
)
3167 struct target_ops
*t
;
3169 t
= find_default_run_target ("attach");
3170 (t
->to_attach
) (t
, args
, from_tty
);
3175 find_default_create_inferior (struct target_ops
*ops
,
3176 char *exec_file
, char *allargs
, char **env
,
3179 struct target_ops
*t
;
3181 t
= find_default_run_target ("run");
3182 (t
->to_create_inferior
) (t
, exec_file
, allargs
, env
, from_tty
);
3187 find_default_can_async_p (struct target_ops
*ignore
)
3189 struct target_ops
*t
;
3191 /* This may be called before the target is pushed on the stack;
3192 look for the default process stratum. If there's none, gdb isn't
3193 configured with a native debugger, and target remote isn't
3195 t
= find_default_run_target (NULL
);
3196 if (t
&& t
->to_can_async_p
!= delegate_can_async_p
)
3197 return (t
->to_can_async_p
) (t
);
3202 find_default_is_async_p (struct target_ops
*ignore
)
3204 struct target_ops
*t
;
3206 /* This may be called before the target is pushed on the stack;
3207 look for the default process stratum. If there's none, gdb isn't
3208 configured with a native debugger, and target remote isn't
3210 t
= find_default_run_target (NULL
);
3211 if (t
&& t
->to_is_async_p
!= delegate_is_async_p
)
3212 return (t
->to_is_async_p
) (t
);
3217 find_default_supports_non_stop (struct target_ops
*self
)
3219 struct target_ops
*t
;
3221 t
= find_default_run_target (NULL
);
3222 if (t
&& t
->to_supports_non_stop
)
3223 return (t
->to_supports_non_stop
) (t
);
3228 target_supports_non_stop (void)
3230 struct target_ops
*t
;
3232 for (t
= ¤t_target
; t
!= NULL
; t
= t
->beneath
)
3233 if (t
->to_supports_non_stop
)
3234 return t
->to_supports_non_stop (t
);
3239 /* Implement the "info proc" command. */
3242 target_info_proc (char *args
, enum info_proc_what what
)
3244 struct target_ops
*t
;
3246 /* If we're already connected to something that can get us OS
3247 related data, use it. Otherwise, try using the native
3249 if (current_target
.to_stratum
>= process_stratum
)
3250 t
= current_target
.beneath
;
3252 t
= find_default_run_target (NULL
);
3254 for (; t
!= NULL
; t
= t
->beneath
)
3256 if (t
->to_info_proc
!= NULL
)
3258 t
->to_info_proc (t
, args
, what
);
3261 fprintf_unfiltered (gdb_stdlog
,
3262 "target_info_proc (\"%s\", %d)\n", args
, what
);
3272 find_default_supports_disable_randomization (struct target_ops
*self
)
3274 struct target_ops
*t
;
3276 t
= find_default_run_target (NULL
);
3277 if (t
&& t
->to_supports_disable_randomization
)
3278 return (t
->to_supports_disable_randomization
) (t
);
3283 target_supports_disable_randomization (void)
3285 struct target_ops
*t
;
3287 for (t
= ¤t_target
; t
!= NULL
; t
= t
->beneath
)
3288 if (t
->to_supports_disable_randomization
)
3289 return t
->to_supports_disable_randomization (t
);
3295 target_get_osdata (const char *type
)
3297 struct target_ops
*t
;
3299 /* If we're already connected to something that can get us OS
3300 related data, use it. Otherwise, try using the native
3302 if (current_target
.to_stratum
>= process_stratum
)
3303 t
= current_target
.beneath
;
3305 t
= find_default_run_target ("get OS data");
3310 return target_read_stralloc (t
, TARGET_OBJECT_OSDATA
, type
);
3313 /* Determine the current address space of thread PTID. */
3315 struct address_space
*
3316 target_thread_address_space (ptid_t ptid
)
3318 struct address_space
*aspace
;
3319 struct inferior
*inf
;
3320 struct target_ops
*t
;
3322 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
3324 if (t
->to_thread_address_space
!= NULL
)
3326 aspace
= t
->to_thread_address_space (t
, ptid
);
3327 gdb_assert (aspace
);
3330 fprintf_unfiltered (gdb_stdlog
,
3331 "target_thread_address_space (%s) = %d\n",
3332 target_pid_to_str (ptid
),
3333 address_space_num (aspace
));
3338 /* Fall-back to the "main" address space of the inferior. */
3339 inf
= find_inferior_pid (ptid_get_pid (ptid
));
3341 if (inf
== NULL
|| inf
->aspace
== NULL
)
3342 internal_error (__FILE__
, __LINE__
,
3343 _("Can't determine the current "
3344 "address space of thread %s\n"),
3345 target_pid_to_str (ptid
));
3351 /* Target file operations. */
3353 static struct target_ops
*
3354 default_fileio_target (void)
3356 /* If we're already connected to something that can perform
3357 file I/O, use it. Otherwise, try using the native target. */
3358 if (current_target
.to_stratum
>= process_stratum
)
3359 return current_target
.beneath
;
3361 return find_default_run_target ("file I/O");
3364 /* Open FILENAME on the target, using FLAGS and MODE. Return a
3365 target file descriptor, or -1 if an error occurs (and set
3368 target_fileio_open (const char *filename
, int flags
, int mode
,
3371 struct target_ops
*t
;
3373 for (t
= default_fileio_target (); t
!= NULL
; t
= t
->beneath
)
3375 if (t
->to_fileio_open
!= NULL
)
3377 int fd
= t
->to_fileio_open (t
, filename
, flags
, mode
, target_errno
);
3380 fprintf_unfiltered (gdb_stdlog
,
3381 "target_fileio_open (%s,0x%x,0%o) = %d (%d)\n",
3382 filename
, flags
, mode
,
3383 fd
, fd
!= -1 ? 0 : *target_errno
);
3388 *target_errno
= FILEIO_ENOSYS
;
3392 /* Write up to LEN bytes from WRITE_BUF to FD on the target.
3393 Return the number of bytes written, or -1 if an error occurs
3394 (and set *TARGET_ERRNO). */
3396 target_fileio_pwrite (int fd
, const gdb_byte
*write_buf
, int len
,
3397 ULONGEST offset
, int *target_errno
)
3399 struct target_ops
*t
;
3401 for (t
= default_fileio_target (); t
!= NULL
; t
= t
->beneath
)
3403 if (t
->to_fileio_pwrite
!= NULL
)
3405 int ret
= t
->to_fileio_pwrite (t
, fd
, write_buf
, len
, offset
,
3409 fprintf_unfiltered (gdb_stdlog
,
3410 "target_fileio_pwrite (%d,...,%d,%s) "
3412 fd
, len
, pulongest (offset
),
3413 ret
, ret
!= -1 ? 0 : *target_errno
);
3418 *target_errno
= FILEIO_ENOSYS
;
3422 /* Read up to LEN bytes FD on the target into READ_BUF.
3423 Return the number of bytes read, or -1 if an error occurs
3424 (and set *TARGET_ERRNO). */
3426 target_fileio_pread (int fd
, gdb_byte
*read_buf
, int len
,
3427 ULONGEST offset
, int *target_errno
)
3429 struct target_ops
*t
;
3431 for (t
= default_fileio_target (); t
!= NULL
; t
= t
->beneath
)
3433 if (t
->to_fileio_pread
!= NULL
)
3435 int ret
= t
->to_fileio_pread (t
, fd
, read_buf
, len
, offset
,
3439 fprintf_unfiltered (gdb_stdlog
,
3440 "target_fileio_pread (%d,...,%d,%s) "
3442 fd
, len
, pulongest (offset
),
3443 ret
, ret
!= -1 ? 0 : *target_errno
);
3448 *target_errno
= FILEIO_ENOSYS
;
3452 /* Close FD on the target. Return 0, or -1 if an error occurs
3453 (and set *TARGET_ERRNO). */
3455 target_fileio_close (int fd
, int *target_errno
)
3457 struct target_ops
*t
;
3459 for (t
= default_fileio_target (); t
!= NULL
; t
= t
->beneath
)
3461 if (t
->to_fileio_close
!= NULL
)
3463 int ret
= t
->to_fileio_close (t
, fd
, target_errno
);
3466 fprintf_unfiltered (gdb_stdlog
,
3467 "target_fileio_close (%d) = %d (%d)\n",
3468 fd
, ret
, ret
!= -1 ? 0 : *target_errno
);
3473 *target_errno
= FILEIO_ENOSYS
;
3477 /* Unlink FILENAME on the target. Return 0, or -1 if an error
3478 occurs (and set *TARGET_ERRNO). */
3480 target_fileio_unlink (const char *filename
, int *target_errno
)
3482 struct target_ops
*t
;
3484 for (t
= default_fileio_target (); t
!= NULL
; t
= t
->beneath
)
3486 if (t
->to_fileio_unlink
!= NULL
)
3488 int ret
= t
->to_fileio_unlink (t
, filename
, target_errno
);
3491 fprintf_unfiltered (gdb_stdlog
,
3492 "target_fileio_unlink (%s) = %d (%d)\n",
3493 filename
, ret
, ret
!= -1 ? 0 : *target_errno
);
3498 *target_errno
= FILEIO_ENOSYS
;
3502 /* Read value of symbolic link FILENAME on the target. Return a
3503 null-terminated string allocated via xmalloc, or NULL if an error
3504 occurs (and set *TARGET_ERRNO). */
3506 target_fileio_readlink (const char *filename
, int *target_errno
)
3508 struct target_ops
*t
;
3510 for (t
= default_fileio_target (); t
!= NULL
; t
= t
->beneath
)
3512 if (t
->to_fileio_readlink
!= NULL
)
3514 char *ret
= t
->to_fileio_readlink (t
, filename
, target_errno
);
3517 fprintf_unfiltered (gdb_stdlog
,
3518 "target_fileio_readlink (%s) = %s (%d)\n",
3519 filename
, ret
? ret
: "(nil)",
3520 ret
? 0 : *target_errno
);
3525 *target_errno
= FILEIO_ENOSYS
;
3530 target_fileio_close_cleanup (void *opaque
)
3532 int fd
= *(int *) opaque
;
3535 target_fileio_close (fd
, &target_errno
);
3538 /* Read target file FILENAME. Store the result in *BUF_P and
3539 return the size of the transferred data. PADDING additional bytes are
3540 available in *BUF_P. This is a helper function for
3541 target_fileio_read_alloc; see the declaration of that function for more
3545 target_fileio_read_alloc_1 (const char *filename
,
3546 gdb_byte
**buf_p
, int padding
)
3548 struct cleanup
*close_cleanup
;
3549 size_t buf_alloc
, buf_pos
;
3555 fd
= target_fileio_open (filename
, FILEIO_O_RDONLY
, 0700, &target_errno
);
3559 close_cleanup
= make_cleanup (target_fileio_close_cleanup
, &fd
);
3561 /* Start by reading up to 4K at a time. The target will throttle
3562 this number down if necessary. */
3564 buf
= xmalloc (buf_alloc
);
3568 n
= target_fileio_pread (fd
, &buf
[buf_pos
],
3569 buf_alloc
- buf_pos
- padding
, buf_pos
,
3573 /* An error occurred. */
3574 do_cleanups (close_cleanup
);
3580 /* Read all there was. */
3581 do_cleanups (close_cleanup
);
3591 /* If the buffer is filling up, expand it. */
3592 if (buf_alloc
< buf_pos
* 2)
3595 buf
= xrealloc (buf
, buf_alloc
);
3602 /* Read target file FILENAME. Store the result in *BUF_P and return
3603 the size of the transferred data. See the declaration in "target.h"
3604 function for more information about the return value. */
3607 target_fileio_read_alloc (const char *filename
, gdb_byte
**buf_p
)
3609 return target_fileio_read_alloc_1 (filename
, buf_p
, 0);
3612 /* Read target file FILENAME. The result is NUL-terminated and
3613 returned as a string, allocated using xmalloc. If an error occurs
3614 or the transfer is unsupported, NULL is returned. Empty objects
3615 are returned as allocated but empty strings. A warning is issued
3616 if the result contains any embedded NUL bytes. */
3619 target_fileio_read_stralloc (const char *filename
)
3623 LONGEST i
, transferred
;
3625 transferred
= target_fileio_read_alloc_1 (filename
, &buffer
, 1);
3626 bufstr
= (char *) buffer
;
3628 if (transferred
< 0)
3631 if (transferred
== 0)
3632 return xstrdup ("");
3634 bufstr
[transferred
] = 0;
3636 /* Check for embedded NUL bytes; but allow trailing NULs. */
3637 for (i
= strlen (bufstr
); i
< transferred
; i
++)
3640 warning (_("target file %s "
3641 "contained unexpected null characters"),
3651 default_region_ok_for_hw_watchpoint (struct target_ops
*self
,
3652 CORE_ADDR addr
, int len
)
3654 return (len
<= gdbarch_ptr_bit (target_gdbarch ()) / TARGET_CHAR_BIT
);
3658 default_watchpoint_addr_within_range (struct target_ops
*target
,
3660 CORE_ADDR start
, int length
)
3662 return addr
>= start
&& addr
< start
+ length
;
3665 static struct gdbarch
*
3666 default_thread_architecture (struct target_ops
*ops
, ptid_t ptid
)
3668 return target_gdbarch ();
3684 return_minus_one (void)
3696 * Find the next target down the stack from the specified target.
3700 find_target_beneath (struct target_ops
*t
)
3708 find_target_at (enum strata stratum
)
3710 struct target_ops
*t
;
3712 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
3713 if (t
->to_stratum
== stratum
)
3720 /* The inferior process has died. Long live the inferior! */
3723 generic_mourn_inferior (void)
3727 ptid
= inferior_ptid
;
3728 inferior_ptid
= null_ptid
;
3730 /* Mark breakpoints uninserted in case something tries to delete a
3731 breakpoint while we delete the inferior's threads (which would
3732 fail, since the inferior is long gone). */
3733 mark_breakpoints_out ();
3735 if (!ptid_equal (ptid
, null_ptid
))
3737 int pid
= ptid_get_pid (ptid
);
3738 exit_inferior (pid
);
3741 /* Note this wipes step-resume breakpoints, so needs to be done
3742 after exit_inferior, which ends up referencing the step-resume
3743 breakpoints through clear_thread_inferior_resources. */
3744 breakpoint_init_inferior (inf_exited
);
3746 registers_changed ();
3748 reopen_exec_file ();
3749 reinit_frame_cache ();
3751 if (deprecated_detach_hook
)
3752 deprecated_detach_hook ();
3755 /* Convert a normal process ID to a string. Returns the string in a
3759 normal_pid_to_str (ptid_t ptid
)
3761 static char buf
[32];
3763 xsnprintf (buf
, sizeof buf
, "process %d", ptid_get_pid (ptid
));
3768 dummy_pid_to_str (struct target_ops
*ops
, ptid_t ptid
)
3770 return normal_pid_to_str (ptid
);
3773 /* Error-catcher for target_find_memory_regions. */
3775 dummy_find_memory_regions (struct target_ops
*self
,
3776 find_memory_region_ftype ignore1
, void *ignore2
)
3778 error (_("Command not implemented for this target."));
3782 /* Error-catcher for target_make_corefile_notes. */
3784 dummy_make_corefile_notes (struct target_ops
*self
,
3785 bfd
*ignore1
, int *ignore2
)
3787 error (_("Command not implemented for this target."));
3791 /* Error-catcher for target_get_bookmark. */
3793 dummy_get_bookmark (struct target_ops
*self
, char *ignore1
, int ignore2
)
3799 /* Error-catcher for target_goto_bookmark. */
3801 dummy_goto_bookmark (struct target_ops
*self
, gdb_byte
*ignore
, int from_tty
)
3806 /* Set up the handful of non-empty slots needed by the dummy target
3810 init_dummy_target (void)
3812 dummy_target
.to_shortname
= "None";
3813 dummy_target
.to_longname
= "None";
3814 dummy_target
.to_doc
= "";
3815 dummy_target
.to_attach
= find_default_attach
;
3816 dummy_target
.to_detach
=
3817 (void (*)(struct target_ops
*, const char *, int))target_ignore
;
3818 dummy_target
.to_create_inferior
= find_default_create_inferior
;
3819 dummy_target
.to_supports_non_stop
= find_default_supports_non_stop
;
3820 dummy_target
.to_supports_disable_randomization
3821 = find_default_supports_disable_randomization
;
3822 dummy_target
.to_pid_to_str
= dummy_pid_to_str
;
3823 dummy_target
.to_stratum
= dummy_stratum
;
3824 dummy_target
.to_find_memory_regions
= dummy_find_memory_regions
;
3825 dummy_target
.to_make_corefile_notes
= dummy_make_corefile_notes
;
3826 dummy_target
.to_get_bookmark
= dummy_get_bookmark
;
3827 dummy_target
.to_goto_bookmark
= dummy_goto_bookmark
;
3828 dummy_target
.to_has_all_memory
= (int (*) (struct target_ops
*)) return_zero
;
3829 dummy_target
.to_has_memory
= (int (*) (struct target_ops
*)) return_zero
;
3830 dummy_target
.to_has_stack
= (int (*) (struct target_ops
*)) return_zero
;
3831 dummy_target
.to_has_registers
= (int (*) (struct target_ops
*)) return_zero
;
3832 dummy_target
.to_has_execution
3833 = (int (*) (struct target_ops
*, ptid_t
)) return_zero
;
3834 dummy_target
.to_magic
= OPS_MAGIC
;
3836 install_dummy_methods (&dummy_target
);
3840 debug_to_open (char *args
, int from_tty
)
3842 debug_target
.to_open (args
, from_tty
);
3844 fprintf_unfiltered (gdb_stdlog
, "target_open (%s, %d)\n", args
, from_tty
);
3848 target_close (struct target_ops
*targ
)
3850 gdb_assert (!target_is_pushed (targ
));
3852 if (targ
->to_xclose
!= NULL
)
3853 targ
->to_xclose (targ
);
3854 else if (targ
->to_close
!= NULL
)
3855 targ
->to_close (targ
);
3858 fprintf_unfiltered (gdb_stdlog
, "target_close ()\n");
3862 target_attach (char *args
, int from_tty
)
3864 struct target_ops
*t
;
3866 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
3868 if (t
->to_attach
!= NULL
)
3870 t
->to_attach (t
, args
, from_tty
);
3872 fprintf_unfiltered (gdb_stdlog
, "target_attach (%s, %d)\n",
3878 internal_error (__FILE__
, __LINE__
,
3879 _("could not find a target to attach"));
3883 target_thread_alive (ptid_t ptid
)
3885 struct target_ops
*t
;
3887 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
3889 if (t
->to_thread_alive
!= NULL
)
3893 retval
= t
->to_thread_alive (t
, ptid
);
3895 fprintf_unfiltered (gdb_stdlog
, "target_thread_alive (%d) = %d\n",
3896 ptid_get_pid (ptid
), retval
);
3906 target_find_new_threads (void)
3908 struct target_ops
*t
;
3910 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
3912 if (t
->to_find_new_threads
!= NULL
)
3914 t
->to_find_new_threads (t
);
3916 fprintf_unfiltered (gdb_stdlog
, "target_find_new_threads ()\n");
3924 target_stop (ptid_t ptid
)
3928 warning (_("May not interrupt or stop the target, ignoring attempt"));
3932 (*current_target
.to_stop
) (¤t_target
, ptid
);
3936 debug_to_post_attach (struct target_ops
*self
, int pid
)
3938 debug_target
.to_post_attach (&debug_target
, pid
);
3940 fprintf_unfiltered (gdb_stdlog
, "target_post_attach (%d)\n", pid
);
3943 /* Concatenate ELEM to LIST, a comma separate list, and return the
3944 result. The LIST incoming argument is released. */
3947 str_comma_list_concat_elem (char *list
, const char *elem
)
3950 return xstrdup (elem
);
3952 return reconcat (list
, list
, ", ", elem
, (char *) NULL
);
3955 /* Helper for target_options_to_string. If OPT is present in
3956 TARGET_OPTIONS, append the OPT_STR (string version of OPT) in RET.
3957 Returns the new resulting string. OPT is removed from
3961 do_option (int *target_options
, char *ret
,
3962 int opt
, char *opt_str
)
3964 if ((*target_options
& opt
) != 0)
3966 ret
= str_comma_list_concat_elem (ret
, opt_str
);
3967 *target_options
&= ~opt
;
3974 target_options_to_string (int target_options
)
3978 #define DO_TARG_OPTION(OPT) \
3979 ret = do_option (&target_options, ret, OPT, #OPT)
3981 DO_TARG_OPTION (TARGET_WNOHANG
);
3983 if (target_options
!= 0)
3984 ret
= str_comma_list_concat_elem (ret
, "unknown???");
3992 debug_print_register (const char * func
,
3993 struct regcache
*regcache
, int regno
)
3995 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
3997 fprintf_unfiltered (gdb_stdlog
, "%s ", func
);
3998 if (regno
>= 0 && regno
< gdbarch_num_regs (gdbarch
)
3999 && gdbarch_register_name (gdbarch
, regno
) != NULL
4000 && gdbarch_register_name (gdbarch
, regno
)[0] != '\0')
4001 fprintf_unfiltered (gdb_stdlog
, "(%s)",
4002 gdbarch_register_name (gdbarch
, regno
));
4004 fprintf_unfiltered (gdb_stdlog
, "(%d)", regno
);
4005 if (regno
>= 0 && regno
< gdbarch_num_regs (gdbarch
))
4007 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
4008 int i
, size
= register_size (gdbarch
, regno
);
4009 gdb_byte buf
[MAX_REGISTER_SIZE
];
4011 regcache_raw_collect (regcache
, regno
, buf
);
4012 fprintf_unfiltered (gdb_stdlog
, " = ");
4013 for (i
= 0; i
< size
; i
++)
4015 fprintf_unfiltered (gdb_stdlog
, "%02x", buf
[i
]);
4017 if (size
<= sizeof (LONGEST
))
4019 ULONGEST val
= extract_unsigned_integer (buf
, size
, byte_order
);
4021 fprintf_unfiltered (gdb_stdlog
, " %s %s",
4022 core_addr_to_string_nz (val
), plongest (val
));
4025 fprintf_unfiltered (gdb_stdlog
, "\n");
4029 target_fetch_registers (struct regcache
*regcache
, int regno
)
4031 struct target_ops
*t
;
4033 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
4035 if (t
->to_fetch_registers
!= NULL
)
4037 t
->to_fetch_registers (t
, regcache
, regno
);
4039 debug_print_register ("target_fetch_registers", regcache
, regno
);
4046 target_store_registers (struct regcache
*regcache
, int regno
)
4048 struct target_ops
*t
;
4050 if (!may_write_registers
)
4051 error (_("Writing to registers is not allowed (regno %d)"), regno
);
4053 current_target
.to_store_registers (¤t_target
, regcache
, regno
);
4056 debug_print_register ("target_store_registers", regcache
, regno
);
4061 target_core_of_thread (ptid_t ptid
)
4063 struct target_ops
*t
;
4065 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
4067 if (t
->to_core_of_thread
!= NULL
)
4069 int retval
= t
->to_core_of_thread (t
, ptid
);
4072 fprintf_unfiltered (gdb_stdlog
,
4073 "target_core_of_thread (%d) = %d\n",
4074 ptid_get_pid (ptid
), retval
);
4083 target_verify_memory (const gdb_byte
*data
, CORE_ADDR memaddr
, ULONGEST size
)
4085 struct target_ops
*t
;
4087 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
4089 if (t
->to_verify_memory
!= NULL
)
4091 int retval
= t
->to_verify_memory (t
, data
, memaddr
, size
);
4094 fprintf_unfiltered (gdb_stdlog
,
4095 "target_verify_memory (%s, %s) = %d\n",
4096 paddress (target_gdbarch (), memaddr
),
4106 /* The documentation for this function is in its prototype declaration in
4110 target_insert_mask_watchpoint (CORE_ADDR addr
, CORE_ADDR mask
, int rw
)
4112 struct target_ops
*t
;
4114 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
4115 if (t
->to_insert_mask_watchpoint
!= NULL
)
4119 ret
= t
->to_insert_mask_watchpoint (t
, addr
, mask
, rw
);
4122 fprintf_unfiltered (gdb_stdlog
, "\
4123 target_insert_mask_watchpoint (%s, %s, %d) = %d\n",
4124 core_addr_to_string (addr
),
4125 core_addr_to_string (mask
), rw
, ret
);
4133 /* The documentation for this function is in its prototype declaration in
4137 target_remove_mask_watchpoint (CORE_ADDR addr
, CORE_ADDR mask
, int rw
)
4139 struct target_ops
*t
;
4141 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
4142 if (t
->to_remove_mask_watchpoint
!= NULL
)
4146 ret
= t
->to_remove_mask_watchpoint (t
, addr
, mask
, rw
);
4149 fprintf_unfiltered (gdb_stdlog
, "\
4150 target_remove_mask_watchpoint (%s, %s, %d) = %d\n",
4151 core_addr_to_string (addr
),
4152 core_addr_to_string (mask
), rw
, ret
);
4160 /* The documentation for this function is in its prototype declaration
4164 target_masked_watch_num_registers (CORE_ADDR addr
, CORE_ADDR mask
)
4166 struct target_ops
*t
;
4168 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
4169 if (t
->to_masked_watch_num_registers
!= NULL
)
4170 return t
->to_masked_watch_num_registers (t
, addr
, mask
);
4175 /* The documentation for this function is in its prototype declaration
4179 target_ranged_break_num_registers (void)
4181 struct target_ops
*t
;
4183 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
4184 if (t
->to_ranged_break_num_registers
!= NULL
)
4185 return t
->to_ranged_break_num_registers (t
);
4192 struct btrace_target_info
*
4193 target_enable_btrace (ptid_t ptid
)
4195 struct target_ops
*t
;
4197 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
4198 if (t
->to_enable_btrace
!= NULL
)
4199 return t
->to_enable_btrace (ptid
);
4208 target_disable_btrace (struct btrace_target_info
*btinfo
)
4210 struct target_ops
*t
;
4212 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
4213 if (t
->to_disable_btrace
!= NULL
)
4215 t
->to_disable_btrace (btinfo
);
4225 target_teardown_btrace (struct btrace_target_info
*btinfo
)
4227 struct target_ops
*t
;
4229 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
4230 if (t
->to_teardown_btrace
!= NULL
)
4232 t
->to_teardown_btrace (btinfo
);
4242 target_read_btrace (VEC (btrace_block_s
) **btrace
,
4243 struct btrace_target_info
*btinfo
,
4244 enum btrace_read_type type
)
4246 struct target_ops
*t
;
4248 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
4249 if (t
->to_read_btrace
!= NULL
)
4250 return t
->to_read_btrace (btrace
, btinfo
, type
);
4253 return BTRACE_ERR_NOT_SUPPORTED
;
4259 target_stop_recording (void)
4261 struct target_ops
*t
;
4263 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
4264 if (t
->to_stop_recording
!= NULL
)
4266 t
->to_stop_recording ();
4270 /* This is optional. */
4276 target_info_record (void)
4278 struct target_ops
*t
;
4280 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
4281 if (t
->to_info_record
!= NULL
)
4283 t
->to_info_record ();
4293 target_save_record (const char *filename
)
4295 struct target_ops
*t
;
4297 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
4298 if (t
->to_save_record
!= NULL
)
4300 t
->to_save_record (filename
);
4310 target_supports_delete_record (void)
4312 struct target_ops
*t
;
4314 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
4315 if (t
->to_delete_record
!= NULL
)
4324 target_delete_record (void)
4326 struct target_ops
*t
;
4328 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
4329 if (t
->to_delete_record
!= NULL
)
4331 t
->to_delete_record ();
4341 target_record_is_replaying (void)
4343 struct target_ops
*t
;
4345 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
4346 if (t
->to_record_is_replaying
!= NULL
)
4347 return t
->to_record_is_replaying ();
4355 target_goto_record_begin (void)
4357 struct target_ops
*t
;
4359 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
4360 if (t
->to_goto_record_begin
!= NULL
)
4362 t
->to_goto_record_begin ();
4372 target_goto_record_end (void)
4374 struct target_ops
*t
;
4376 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
4377 if (t
->to_goto_record_end
!= NULL
)
4379 t
->to_goto_record_end ();
4389 target_goto_record (ULONGEST insn
)
4391 struct target_ops
*t
;
4393 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
4394 if (t
->to_goto_record
!= NULL
)
4396 t
->to_goto_record (insn
);
4406 target_insn_history (int size
, int flags
)
4408 struct target_ops
*t
;
4410 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
4411 if (t
->to_insn_history
!= NULL
)
4413 t
->to_insn_history (size
, flags
);
4423 target_insn_history_from (ULONGEST from
, int size
, int flags
)
4425 struct target_ops
*t
;
4427 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
4428 if (t
->to_insn_history_from
!= NULL
)
4430 t
->to_insn_history_from (from
, size
, flags
);
4440 target_insn_history_range (ULONGEST begin
, ULONGEST end
, int flags
)
4442 struct target_ops
*t
;
4444 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
4445 if (t
->to_insn_history_range
!= NULL
)
4447 t
->to_insn_history_range (begin
, end
, flags
);
4457 target_call_history (int size
, int flags
)
4459 struct target_ops
*t
;
4461 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
4462 if (t
->to_call_history
!= NULL
)
4464 t
->to_call_history (size
, flags
);
4474 target_call_history_from (ULONGEST begin
, int size
, int flags
)
4476 struct target_ops
*t
;
4478 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
4479 if (t
->to_call_history_from
!= NULL
)
4481 t
->to_call_history_from (begin
, size
, flags
);
4491 target_call_history_range (ULONGEST begin
, ULONGEST end
, int flags
)
4493 struct target_ops
*t
;
4495 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
4496 if (t
->to_call_history_range
!= NULL
)
4498 t
->to_call_history_range (begin
, end
, flags
);
4506 debug_to_prepare_to_store (struct target_ops
*self
, struct regcache
*regcache
)
4508 debug_target
.to_prepare_to_store (&debug_target
, regcache
);
4510 fprintf_unfiltered (gdb_stdlog
, "target_prepare_to_store ()\n");
4515 const struct frame_unwind
*
4516 target_get_unwinder (void)
4518 struct target_ops
*t
;
4520 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
4521 if (t
->to_get_unwinder
!= NULL
)
4522 return t
->to_get_unwinder
;
4529 const struct frame_unwind
*
4530 target_get_tailcall_unwinder (void)
4532 struct target_ops
*t
;
4534 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
4535 if (t
->to_get_tailcall_unwinder
!= NULL
)
4536 return t
->to_get_tailcall_unwinder
;
4544 forward_target_decr_pc_after_break (struct target_ops
*ops
,
4545 struct gdbarch
*gdbarch
)
4547 for (; ops
!= NULL
; ops
= ops
->beneath
)
4548 if (ops
->to_decr_pc_after_break
!= NULL
)
4549 return ops
->to_decr_pc_after_break (ops
, gdbarch
);
4551 return gdbarch_decr_pc_after_break (gdbarch
);
4557 target_decr_pc_after_break (struct gdbarch
*gdbarch
)
4559 return forward_target_decr_pc_after_break (current_target
.beneath
, gdbarch
);
4563 deprecated_debug_xfer_memory (CORE_ADDR memaddr
, bfd_byte
*myaddr
, int len
,
4564 int write
, struct mem_attrib
*attrib
,
4565 struct target_ops
*target
)
4569 retval
= debug_target
.deprecated_xfer_memory (memaddr
, myaddr
, len
, write
,
4572 fprintf_unfiltered (gdb_stdlog
,
4573 "target_xfer_memory (%s, xxx, %d, %s, xxx) = %d",
4574 paddress (target_gdbarch (), memaddr
), len
,
4575 write
? "write" : "read", retval
);
4581 fputs_unfiltered (", bytes =", gdb_stdlog
);
4582 for (i
= 0; i
< retval
; i
++)
4584 if ((((intptr_t) &(myaddr
[i
])) & 0xf) == 0)
4586 if (targetdebug
< 2 && i
> 0)
4588 fprintf_unfiltered (gdb_stdlog
, " ...");
4591 fprintf_unfiltered (gdb_stdlog
, "\n");
4594 fprintf_unfiltered (gdb_stdlog
, " %02x", myaddr
[i
] & 0xff);
4598 fputc_unfiltered ('\n', gdb_stdlog
);
4604 debug_to_files_info (struct target_ops
*target
)
4606 debug_target
.to_files_info (target
);
4608 fprintf_unfiltered (gdb_stdlog
, "target_files_info (xxx)\n");
4612 debug_to_insert_breakpoint (struct target_ops
*ops
, struct gdbarch
*gdbarch
,
4613 struct bp_target_info
*bp_tgt
)
4617 retval
= debug_target
.to_insert_breakpoint (&debug_target
, gdbarch
, bp_tgt
);
4619 fprintf_unfiltered (gdb_stdlog
,
4620 "target_insert_breakpoint (%s, xxx) = %ld\n",
4621 core_addr_to_string (bp_tgt
->placed_address
),
4622 (unsigned long) retval
);
4627 debug_to_remove_breakpoint (struct target_ops
*ops
, struct gdbarch
*gdbarch
,
4628 struct bp_target_info
*bp_tgt
)
4632 retval
= debug_target
.to_remove_breakpoint (&debug_target
, gdbarch
, bp_tgt
);
4634 fprintf_unfiltered (gdb_stdlog
,
4635 "target_remove_breakpoint (%s, xxx) = %ld\n",
4636 core_addr_to_string (bp_tgt
->placed_address
),
4637 (unsigned long) retval
);
4642 debug_to_can_use_hw_breakpoint (struct target_ops
*self
,
4643 int type
, int cnt
, int from_tty
)
4647 retval
= debug_target
.to_can_use_hw_breakpoint (&debug_target
,
4648 type
, cnt
, from_tty
);
4650 fprintf_unfiltered (gdb_stdlog
,
4651 "target_can_use_hw_breakpoint (%ld, %ld, %ld) = %ld\n",
4652 (unsigned long) type
,
4653 (unsigned long) cnt
,
4654 (unsigned long) from_tty
,
4655 (unsigned long) retval
);
4660 debug_to_region_ok_for_hw_watchpoint (struct target_ops
*self
,
4661 CORE_ADDR addr
, int len
)
4665 retval
= debug_target
.to_region_ok_for_hw_watchpoint (&debug_target
,
4668 fprintf_unfiltered (gdb_stdlog
,
4669 "target_region_ok_for_hw_watchpoint (%s, %ld) = %s\n",
4670 core_addr_to_string (addr
), (unsigned long) len
,
4671 core_addr_to_string (retval
));
4676 debug_to_can_accel_watchpoint_condition (struct target_ops
*self
,
4677 CORE_ADDR addr
, int len
, int rw
,
4678 struct expression
*cond
)
4682 retval
= debug_target
.to_can_accel_watchpoint_condition (&debug_target
,
4686 fprintf_unfiltered (gdb_stdlog
,
4687 "target_can_accel_watchpoint_condition "
4688 "(%s, %d, %d, %s) = %ld\n",
4689 core_addr_to_string (addr
), len
, rw
,
4690 host_address_to_string (cond
), (unsigned long) retval
);
4695 debug_to_stopped_by_watchpoint (struct target_ops
*ops
)
4699 retval
= debug_target
.to_stopped_by_watchpoint (&debug_target
);
4701 fprintf_unfiltered (gdb_stdlog
,
4702 "target_stopped_by_watchpoint () = %ld\n",
4703 (unsigned long) retval
);
4708 debug_to_stopped_data_address (struct target_ops
*target
, CORE_ADDR
*addr
)
4712 retval
= debug_target
.to_stopped_data_address (target
, addr
);
4714 fprintf_unfiltered (gdb_stdlog
,
4715 "target_stopped_data_address ([%s]) = %ld\n",
4716 core_addr_to_string (*addr
),
4717 (unsigned long)retval
);
4722 debug_to_watchpoint_addr_within_range (struct target_ops
*target
,
4724 CORE_ADDR start
, int length
)
4728 retval
= debug_target
.to_watchpoint_addr_within_range (target
, addr
,
4731 fprintf_filtered (gdb_stdlog
,
4732 "target_watchpoint_addr_within_range (%s, %s, %d) = %d\n",
4733 core_addr_to_string (addr
), core_addr_to_string (start
),
4739 debug_to_insert_hw_breakpoint (struct target_ops
*self
,
4740 struct gdbarch
*gdbarch
,
4741 struct bp_target_info
*bp_tgt
)
4745 retval
= debug_target
.to_insert_hw_breakpoint (&debug_target
,
4748 fprintf_unfiltered (gdb_stdlog
,
4749 "target_insert_hw_breakpoint (%s, xxx) = %ld\n",
4750 core_addr_to_string (bp_tgt
->placed_address
),
4751 (unsigned long) retval
);
4756 debug_to_remove_hw_breakpoint (struct target_ops
*self
,
4757 struct gdbarch
*gdbarch
,
4758 struct bp_target_info
*bp_tgt
)
4762 retval
= debug_target
.to_remove_hw_breakpoint (&debug_target
,
4765 fprintf_unfiltered (gdb_stdlog
,
4766 "target_remove_hw_breakpoint (%s, xxx) = %ld\n",
4767 core_addr_to_string (bp_tgt
->placed_address
),
4768 (unsigned long) retval
);
4773 debug_to_insert_watchpoint (struct target_ops
*self
,
4774 CORE_ADDR addr
, int len
, int type
,
4775 struct expression
*cond
)
4779 retval
= debug_target
.to_insert_watchpoint (&debug_target
,
4780 addr
, len
, type
, cond
);
4782 fprintf_unfiltered (gdb_stdlog
,
4783 "target_insert_watchpoint (%s, %d, %d, %s) = %ld\n",
4784 core_addr_to_string (addr
), len
, type
,
4785 host_address_to_string (cond
), (unsigned long) retval
);
4790 debug_to_remove_watchpoint (struct target_ops
*self
,
4791 CORE_ADDR addr
, int len
, int type
,
4792 struct expression
*cond
)
4796 retval
= debug_target
.to_remove_watchpoint (&debug_target
,
4797 addr
, len
, type
, cond
);
4799 fprintf_unfiltered (gdb_stdlog
,
4800 "target_remove_watchpoint (%s, %d, %d, %s) = %ld\n",
4801 core_addr_to_string (addr
), len
, type
,
4802 host_address_to_string (cond
), (unsigned long) retval
);
4807 debug_to_terminal_init (struct target_ops
*self
)
4809 debug_target
.to_terminal_init (&debug_target
);
4811 fprintf_unfiltered (gdb_stdlog
, "target_terminal_init ()\n");
4815 debug_to_terminal_inferior (struct target_ops
*self
)
4817 debug_target
.to_terminal_inferior (&debug_target
);
4819 fprintf_unfiltered (gdb_stdlog
, "target_terminal_inferior ()\n");
4823 debug_to_terminal_ours_for_output (struct target_ops
*self
)
4825 debug_target
.to_terminal_ours_for_output (&debug_target
);
4827 fprintf_unfiltered (gdb_stdlog
, "target_terminal_ours_for_output ()\n");
4831 debug_to_terminal_ours (struct target_ops
*self
)
4833 debug_target
.to_terminal_ours (&debug_target
);
4835 fprintf_unfiltered (gdb_stdlog
, "target_terminal_ours ()\n");
4839 debug_to_terminal_save_ours (struct target_ops
*self
)
4841 debug_target
.to_terminal_save_ours (&debug_target
);
4843 fprintf_unfiltered (gdb_stdlog
, "target_terminal_save_ours ()\n");
4847 debug_to_terminal_info (struct target_ops
*self
,
4848 const char *arg
, int from_tty
)
4850 debug_target
.to_terminal_info (&debug_target
, arg
, from_tty
);
4852 fprintf_unfiltered (gdb_stdlog
, "target_terminal_info (%s, %d)\n", arg
,
4857 debug_to_load (struct target_ops
*self
, char *args
, int from_tty
)
4859 debug_target
.to_load (&debug_target
, args
, from_tty
);
4861 fprintf_unfiltered (gdb_stdlog
, "target_load (%s, %d)\n", args
, from_tty
);
4865 debug_to_post_startup_inferior (struct target_ops
*self
, ptid_t ptid
)
4867 debug_target
.to_post_startup_inferior (&debug_target
, ptid
);
4869 fprintf_unfiltered (gdb_stdlog
, "target_post_startup_inferior (%d)\n",
4870 ptid_get_pid (ptid
));
4874 debug_to_insert_fork_catchpoint (struct target_ops
*self
, int pid
)
4878 retval
= debug_target
.to_insert_fork_catchpoint (&debug_target
, pid
);
4880 fprintf_unfiltered (gdb_stdlog
, "target_insert_fork_catchpoint (%d) = %d\n",
4887 debug_to_remove_fork_catchpoint (struct target_ops
*self
, int pid
)
4891 retval
= debug_target
.to_remove_fork_catchpoint (&debug_target
, pid
);
4893 fprintf_unfiltered (gdb_stdlog
, "target_remove_fork_catchpoint (%d) = %d\n",
4900 debug_to_insert_vfork_catchpoint (struct target_ops
*self
, int pid
)
4904 retval
= debug_target
.to_insert_vfork_catchpoint (&debug_target
, pid
);
4906 fprintf_unfiltered (gdb_stdlog
, "target_insert_vfork_catchpoint (%d) = %d\n",
4913 debug_to_remove_vfork_catchpoint (struct target_ops
*self
, int pid
)
4917 retval
= debug_target
.to_remove_vfork_catchpoint (&debug_target
, pid
);
4919 fprintf_unfiltered (gdb_stdlog
, "target_remove_vfork_catchpoint (%d) = %d\n",
4926 debug_to_insert_exec_catchpoint (struct target_ops
*self
, int pid
)
4930 retval
= debug_target
.to_insert_exec_catchpoint (&debug_target
, pid
);
4932 fprintf_unfiltered (gdb_stdlog
, "target_insert_exec_catchpoint (%d) = %d\n",
4939 debug_to_remove_exec_catchpoint (struct target_ops
*self
, int pid
)
4943 retval
= debug_target
.to_remove_exec_catchpoint (&debug_target
, pid
);
4945 fprintf_unfiltered (gdb_stdlog
, "target_remove_exec_catchpoint (%d) = %d\n",
4952 debug_to_has_exited (struct target_ops
*self
,
4953 int pid
, int wait_status
, int *exit_status
)
4957 has_exited
= debug_target
.to_has_exited (&debug_target
,
4958 pid
, wait_status
, exit_status
);
4960 fprintf_unfiltered (gdb_stdlog
, "target_has_exited (%d, %d, %d) = %d\n",
4961 pid
, wait_status
, *exit_status
, has_exited
);
4967 debug_to_can_run (struct target_ops
*self
)
4971 retval
= debug_target
.to_can_run (&debug_target
);
4973 fprintf_unfiltered (gdb_stdlog
, "target_can_run () = %d\n", retval
);
4978 static struct gdbarch
*
4979 debug_to_thread_architecture (struct target_ops
*ops
, ptid_t ptid
)
4981 struct gdbarch
*retval
;
4983 retval
= debug_target
.to_thread_architecture (ops
, ptid
);
4985 fprintf_unfiltered (gdb_stdlog
,
4986 "target_thread_architecture (%s) = %s [%s]\n",
4987 target_pid_to_str (ptid
),
4988 host_address_to_string (retval
),
4989 gdbarch_bfd_arch_info (retval
)->printable_name
);
4994 debug_to_stop (struct target_ops
*self
, ptid_t ptid
)
4996 debug_target
.to_stop (&debug_target
, ptid
);
4998 fprintf_unfiltered (gdb_stdlog
, "target_stop (%s)\n",
4999 target_pid_to_str (ptid
));
5003 debug_to_rcmd (struct target_ops
*self
, char *command
,
5004 struct ui_file
*outbuf
)
5006 debug_target
.to_rcmd (&debug_target
, command
, outbuf
);
5007 fprintf_unfiltered (gdb_stdlog
, "target_rcmd (%s, ...)\n", command
);
5011 debug_to_pid_to_exec_file (struct target_ops
*self
, int pid
)
5015 exec_file
= debug_target
.to_pid_to_exec_file (&debug_target
, pid
);
5017 fprintf_unfiltered (gdb_stdlog
, "target_pid_to_exec_file (%d) = %s\n",
5024 setup_target_debug (void)
5026 memcpy (&debug_target
, ¤t_target
, sizeof debug_target
);
5028 current_target
.to_open
= debug_to_open
;
5029 current_target
.to_post_attach
= debug_to_post_attach
;
5030 current_target
.to_prepare_to_store
= debug_to_prepare_to_store
;
5031 current_target
.deprecated_xfer_memory
= deprecated_debug_xfer_memory
;
5032 current_target
.to_files_info
= debug_to_files_info
;
5033 current_target
.to_insert_breakpoint
= debug_to_insert_breakpoint
;
5034 current_target
.to_remove_breakpoint
= debug_to_remove_breakpoint
;
5035 current_target
.to_can_use_hw_breakpoint
= debug_to_can_use_hw_breakpoint
;
5036 current_target
.to_insert_hw_breakpoint
= debug_to_insert_hw_breakpoint
;
5037 current_target
.to_remove_hw_breakpoint
= debug_to_remove_hw_breakpoint
;
5038 current_target
.to_insert_watchpoint
= debug_to_insert_watchpoint
;
5039 current_target
.to_remove_watchpoint
= debug_to_remove_watchpoint
;
5040 current_target
.to_stopped_by_watchpoint
= debug_to_stopped_by_watchpoint
;
5041 current_target
.to_stopped_data_address
= debug_to_stopped_data_address
;
5042 current_target
.to_watchpoint_addr_within_range
5043 = debug_to_watchpoint_addr_within_range
;
5044 current_target
.to_region_ok_for_hw_watchpoint
5045 = debug_to_region_ok_for_hw_watchpoint
;
5046 current_target
.to_can_accel_watchpoint_condition
5047 = debug_to_can_accel_watchpoint_condition
;
5048 current_target
.to_terminal_init
= debug_to_terminal_init
;
5049 current_target
.to_terminal_inferior
= debug_to_terminal_inferior
;
5050 current_target
.to_terminal_ours_for_output
5051 = debug_to_terminal_ours_for_output
;
5052 current_target
.to_terminal_ours
= debug_to_terminal_ours
;
5053 current_target
.to_terminal_save_ours
= debug_to_terminal_save_ours
;
5054 current_target
.to_terminal_info
= debug_to_terminal_info
;
5055 current_target
.to_load
= debug_to_load
;
5056 current_target
.to_post_startup_inferior
= debug_to_post_startup_inferior
;
5057 current_target
.to_insert_fork_catchpoint
= debug_to_insert_fork_catchpoint
;
5058 current_target
.to_remove_fork_catchpoint
= debug_to_remove_fork_catchpoint
;
5059 current_target
.to_insert_vfork_catchpoint
= debug_to_insert_vfork_catchpoint
;
5060 current_target
.to_remove_vfork_catchpoint
= debug_to_remove_vfork_catchpoint
;
5061 current_target
.to_insert_exec_catchpoint
= debug_to_insert_exec_catchpoint
;
5062 current_target
.to_remove_exec_catchpoint
= debug_to_remove_exec_catchpoint
;
5063 current_target
.to_has_exited
= debug_to_has_exited
;
5064 current_target
.to_can_run
= debug_to_can_run
;
5065 current_target
.to_stop
= debug_to_stop
;
5066 current_target
.to_rcmd
= debug_to_rcmd
;
5067 current_target
.to_pid_to_exec_file
= debug_to_pid_to_exec_file
;
5068 current_target
.to_thread_architecture
= debug_to_thread_architecture
;
5072 static char targ_desc
[] =
5073 "Names of targets and files being debugged.\nShows the entire \
5074 stack of targets currently in use (including the exec-file,\n\
5075 core-file, and process, if any), as well as the symbol file name.";
5078 do_monitor_command (char *cmd
,
5081 if ((current_target
.to_rcmd
5082 == (void (*) (struct target_ops
*, char *, struct ui_file
*)) tcomplain
)
5083 || (current_target
.to_rcmd
== debug_to_rcmd
5084 && (debug_target
.to_rcmd
5085 == (void (*) (struct target_ops
*,
5086 char *, struct ui_file
*)) tcomplain
)))
5087 error (_("\"monitor\" command not supported by this target."));
5088 target_rcmd (cmd
, gdb_stdtarg
);
5091 /* Print the name of each layers of our target stack. */
5094 maintenance_print_target_stack (char *cmd
, int from_tty
)
5096 struct target_ops
*t
;
5098 printf_filtered (_("The current target stack is:\n"));
5100 for (t
= target_stack
; t
!= NULL
; t
= t
->beneath
)
5102 printf_filtered (" - %s (%s)\n", t
->to_shortname
, t
->to_longname
);
5106 /* Controls if async mode is permitted. */
5107 int target_async_permitted
= 0;
5109 /* The set command writes to this variable. If the inferior is
5110 executing, target_async_permitted is *not* updated. */
5111 static int target_async_permitted_1
= 0;
5114 set_target_async_command (char *args
, int from_tty
,
5115 struct cmd_list_element
*c
)
5117 if (have_live_inferiors ())
5119 target_async_permitted_1
= target_async_permitted
;
5120 error (_("Cannot change this setting while the inferior is running."));
5123 target_async_permitted
= target_async_permitted_1
;
5127 show_target_async_command (struct ui_file
*file
, int from_tty
,
5128 struct cmd_list_element
*c
,
5131 fprintf_filtered (file
,
5132 _("Controlling the inferior in "
5133 "asynchronous mode is %s.\n"), value
);
5136 /* Temporary copies of permission settings. */
5138 static int may_write_registers_1
= 1;
5139 static int may_write_memory_1
= 1;
5140 static int may_insert_breakpoints_1
= 1;
5141 static int may_insert_tracepoints_1
= 1;
5142 static int may_insert_fast_tracepoints_1
= 1;
5143 static int may_stop_1
= 1;
5145 /* Make the user-set values match the real values again. */
5148 update_target_permissions (void)
5150 may_write_registers_1
= may_write_registers
;
5151 may_write_memory_1
= may_write_memory
;
5152 may_insert_breakpoints_1
= may_insert_breakpoints
;
5153 may_insert_tracepoints_1
= may_insert_tracepoints
;
5154 may_insert_fast_tracepoints_1
= may_insert_fast_tracepoints
;
5155 may_stop_1
= may_stop
;
5158 /* The one function handles (most of) the permission flags in the same
5162 set_target_permissions (char *args
, int from_tty
,
5163 struct cmd_list_element
*c
)
5165 if (target_has_execution
)
5167 update_target_permissions ();
5168 error (_("Cannot change this setting while the inferior is running."));
5171 /* Make the real values match the user-changed values. */
5172 may_write_registers
= may_write_registers_1
;
5173 may_insert_breakpoints
= may_insert_breakpoints_1
;
5174 may_insert_tracepoints
= may_insert_tracepoints_1
;
5175 may_insert_fast_tracepoints
= may_insert_fast_tracepoints_1
;
5176 may_stop
= may_stop_1
;
5177 update_observer_mode ();
5180 /* Set memory write permission independently of observer mode. */
5183 set_write_memory_permission (char *args
, int from_tty
,
5184 struct cmd_list_element
*c
)
5186 /* Make the real values match the user-changed values. */
5187 may_write_memory
= may_write_memory_1
;
5188 update_observer_mode ();
5193 initialize_targets (void)
5195 init_dummy_target ();
5196 push_target (&dummy_target
);
5198 add_info ("target", target_info
, targ_desc
);
5199 add_info ("files", target_info
, targ_desc
);
5201 add_setshow_zuinteger_cmd ("target", class_maintenance
, &targetdebug
, _("\
5202 Set target debugging."), _("\
5203 Show target debugging."), _("\
5204 When non-zero, target debugging is enabled. Higher numbers are more\n\
5205 verbose. Changes do not take effect until the next \"run\" or \"target\"\n\
5209 &setdebuglist
, &showdebuglist
);
5211 add_setshow_boolean_cmd ("trust-readonly-sections", class_support
,
5212 &trust_readonly
, _("\
5213 Set mode for reading from readonly sections."), _("\
5214 Show mode for reading from readonly sections."), _("\
5215 When this mode is on, memory reads from readonly sections (such as .text)\n\
5216 will be read from the object file instead of from the target. This will\n\
5217 result in significant performance improvement for remote targets."),
5219 show_trust_readonly
,
5220 &setlist
, &showlist
);
5222 add_com ("monitor", class_obscure
, do_monitor_command
,
5223 _("Send a command to the remote monitor (remote targets only)."));
5225 add_cmd ("target-stack", class_maintenance
, maintenance_print_target_stack
,
5226 _("Print the name of each layer of the internal target stack."),
5227 &maintenanceprintlist
);
5229 add_setshow_boolean_cmd ("target-async", no_class
,
5230 &target_async_permitted_1
, _("\
5231 Set whether gdb controls the inferior in asynchronous mode."), _("\
5232 Show whether gdb controls the inferior in asynchronous mode."), _("\
5233 Tells gdb whether to control the inferior in asynchronous mode."),
5234 set_target_async_command
,
5235 show_target_async_command
,
5239 add_setshow_boolean_cmd ("may-write-registers", class_support
,
5240 &may_write_registers_1
, _("\
5241 Set permission to write into registers."), _("\
5242 Show permission to write into registers."), _("\
5243 When this permission is on, GDB may write into the target's registers.\n\
5244 Otherwise, any sort of write attempt will result in an error."),
5245 set_target_permissions
, NULL
,
5246 &setlist
, &showlist
);
5248 add_setshow_boolean_cmd ("may-write-memory", class_support
,
5249 &may_write_memory_1
, _("\
5250 Set permission to write into target memory."), _("\
5251 Show permission to write into target memory."), _("\
5252 When this permission is on, GDB may write into the target's memory.\n\
5253 Otherwise, any sort of write attempt will result in an error."),
5254 set_write_memory_permission
, NULL
,
5255 &setlist
, &showlist
);
5257 add_setshow_boolean_cmd ("may-insert-breakpoints", class_support
,
5258 &may_insert_breakpoints_1
, _("\
5259 Set permission to insert breakpoints in the target."), _("\
5260 Show permission to insert breakpoints in the target."), _("\
5261 When this permission is on, GDB may insert breakpoints in the program.\n\
5262 Otherwise, any sort of insertion attempt will result in an error."),
5263 set_target_permissions
, NULL
,
5264 &setlist
, &showlist
);
5266 add_setshow_boolean_cmd ("may-insert-tracepoints", class_support
,
5267 &may_insert_tracepoints_1
, _("\
5268 Set permission to insert tracepoints in the target."), _("\
5269 Show permission to insert tracepoints in the target."), _("\
5270 When this permission is on, GDB may insert tracepoints in the program.\n\
5271 Otherwise, any sort of insertion attempt will result in an error."),
5272 set_target_permissions
, NULL
,
5273 &setlist
, &showlist
);
5275 add_setshow_boolean_cmd ("may-insert-fast-tracepoints", class_support
,
5276 &may_insert_fast_tracepoints_1
, _("\
5277 Set permission to insert fast tracepoints in the target."), _("\
5278 Show permission to insert fast tracepoints in the target."), _("\
5279 When this permission is on, GDB may insert fast tracepoints.\n\
5280 Otherwise, any sort of insertion attempt will result in an error."),
5281 set_target_permissions
, NULL
,
5282 &setlist
, &showlist
);
5284 add_setshow_boolean_cmd ("may-interrupt", class_support
,
5286 Set permission to interrupt or signal the target."), _("\
5287 Show permission to interrupt or signal the target."), _("\
5288 When this permission is on, GDB may interrupt/stop the target's execution.\n\
5289 Otherwise, any attempt to interrupt or stop will be ignored."),
5290 set_target_permissions
, NULL
,
5291 &setlist
, &showlist
);