1 /* Select target systems and architectures at runtime for GDB.
3 Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
4 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
5 Free Software Foundation, Inc.
7 Contributed by Cygnus Support.
9 This file is part of GDB.
11 This program is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 3 of the License, or
14 (at your option) any later version.
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with this program. If not, see <http://www.gnu.org/licenses/>. */
26 #include "gdb_string.h"
38 #include "gdb_assert.h"
40 #include "exceptions.h"
41 #include "target-descriptions.h"
42 #include "gdbthread.h"
45 #include "inline-frame.h"
46 #include "tracepoint.h"
48 static void target_info (char *, int);
50 static void default_terminal_info (char *, int);
52 static int default_watchpoint_addr_within_range (struct target_ops
*,
53 CORE_ADDR
, CORE_ADDR
, int);
55 static int default_region_ok_for_hw_watchpoint (CORE_ADDR
, int);
57 static int nosymbol (char *, CORE_ADDR
*);
59 static void tcomplain (void) ATTRIBUTE_NORETURN
;
61 static int nomemory (CORE_ADDR
, char *, int, int, struct target_ops
*);
63 static int return_zero (void);
65 static int return_one (void);
67 static int return_minus_one (void);
69 void target_ignore (void);
71 static void target_command (char *, int);
73 static struct target_ops
*find_default_run_target (char *);
75 static LONGEST
default_xfer_partial (struct target_ops
*ops
,
76 enum target_object object
,
77 const char *annex
, gdb_byte
*readbuf
,
78 const gdb_byte
*writebuf
,
79 ULONGEST offset
, LONGEST len
);
81 static LONGEST
current_xfer_partial (struct target_ops
*ops
,
82 enum target_object object
,
83 const char *annex
, gdb_byte
*readbuf
,
84 const gdb_byte
*writebuf
,
85 ULONGEST offset
, LONGEST len
);
87 static LONGEST
target_xfer_partial (struct target_ops
*ops
,
88 enum target_object object
,
90 void *readbuf
, const void *writebuf
,
91 ULONGEST offset
, LONGEST len
);
93 static struct gdbarch
*default_thread_architecture (struct target_ops
*ops
,
96 static void init_dummy_target (void);
98 static struct target_ops debug_target
;
100 static void debug_to_open (char *, int);
102 static void debug_to_prepare_to_store (struct regcache
*);
104 static void debug_to_files_info (struct target_ops
*);
106 static int debug_to_insert_breakpoint (struct gdbarch
*,
107 struct bp_target_info
*);
109 static int debug_to_remove_breakpoint (struct gdbarch
*,
110 struct bp_target_info
*);
112 static int debug_to_can_use_hw_breakpoint (int, int, int);
114 static int debug_to_insert_hw_breakpoint (struct gdbarch
*,
115 struct bp_target_info
*);
117 static int debug_to_remove_hw_breakpoint (struct gdbarch
*,
118 struct bp_target_info
*);
120 static int debug_to_insert_watchpoint (CORE_ADDR
, int, int);
122 static int debug_to_remove_watchpoint (CORE_ADDR
, int, int);
124 static int debug_to_stopped_by_watchpoint (void);
126 static int debug_to_stopped_data_address (struct target_ops
*, CORE_ADDR
*);
128 static int debug_to_watchpoint_addr_within_range (struct target_ops
*,
129 CORE_ADDR
, CORE_ADDR
, int);
131 static int debug_to_region_ok_for_hw_watchpoint (CORE_ADDR
, int);
133 static void debug_to_terminal_init (void);
135 static void debug_to_terminal_inferior (void);
137 static void debug_to_terminal_ours_for_output (void);
139 static void debug_to_terminal_save_ours (void);
141 static void debug_to_terminal_ours (void);
143 static void debug_to_terminal_info (char *, int);
145 static void debug_to_load (char *, int);
147 static int debug_to_lookup_symbol (char *, CORE_ADDR
*);
149 static int debug_to_can_run (void);
151 static void debug_to_notice_signals (ptid_t
);
153 static void debug_to_stop (ptid_t
);
155 /* NOTE: cagney/2004-09-29: Many targets reference this variable in
156 wierd and mysterious ways. Putting the variable here lets those
157 wierd and mysterious ways keep building while they are being
158 converted to the inferior inheritance structure. */
159 struct target_ops deprecated_child_ops
;
161 /* Pointer to array of target architecture structures; the size of the
162 array; the current index into the array; the allocated size of the
164 struct target_ops
**target_structs
;
165 unsigned target_struct_size
;
166 unsigned target_struct_index
;
167 unsigned target_struct_allocsize
;
168 #define DEFAULT_ALLOCSIZE 10
170 /* The initial current target, so that there is always a semi-valid
173 static struct target_ops dummy_target
;
175 /* Top of target stack. */
177 static struct target_ops
*target_stack
;
179 /* The target structure we are currently using to talk to a process
180 or file or whatever "inferior" we have. */
182 struct target_ops current_target
;
184 /* Command list for target. */
186 static struct cmd_list_element
*targetlist
= NULL
;
188 /* Nonzero if we should trust readonly sections from the
189 executable when reading memory. */
191 static int trust_readonly
= 0;
193 /* Nonzero if we should show true memory content including
194 memory breakpoint inserted by gdb. */
196 static int show_memory_breakpoints
= 0;
198 /* These globals control whether GDB attempts to perform these
199 operations; they are useful for targets that need to prevent
200 inadvertant disruption, such as in non-stop mode. */
202 int may_write_registers
= 1;
204 int may_write_memory
= 1;
206 int may_insert_breakpoints
= 1;
208 int may_insert_tracepoints
= 1;
210 int may_insert_fast_tracepoints
= 1;
214 /* Non-zero if we want to see trace of target level stuff. */
216 static int targetdebug
= 0;
218 show_targetdebug (struct ui_file
*file
, int from_tty
,
219 struct cmd_list_element
*c
, const char *value
)
221 fprintf_filtered (file
, _("Target debugging is %s.\n"), value
);
224 static void setup_target_debug (void);
226 /* The option sets this. */
227 static int stack_cache_enabled_p_1
= 1;
228 /* And set_stack_cache_enabled_p updates this.
229 The reason for the separation is so that we don't flush the cache for
230 on->on transitions. */
231 static int stack_cache_enabled_p
= 1;
233 /* This is called *after* the stack-cache has been set.
234 Flush the cache for off->on and on->off transitions.
235 There's no real need to flush the cache for on->off transitions,
236 except cleanliness. */
239 set_stack_cache_enabled_p (char *args
, int from_tty
,
240 struct cmd_list_element
*c
)
242 if (stack_cache_enabled_p
!= stack_cache_enabled_p_1
)
243 target_dcache_invalidate ();
245 stack_cache_enabled_p
= stack_cache_enabled_p_1
;
249 show_stack_cache_enabled_p (struct ui_file
*file
, int from_tty
,
250 struct cmd_list_element
*c
, const char *value
)
252 fprintf_filtered (file
, _("Cache use for stack accesses is %s.\n"), value
);
255 /* Cache of memory operations, to speed up remote access. */
256 static DCACHE
*target_dcache
;
258 /* Invalidate the target dcache. */
261 target_dcache_invalidate (void)
263 dcache_invalidate (target_dcache
);
266 /* The user just typed 'target' without the name of a target. */
269 target_command (char *arg
, int from_tty
)
271 fputs_filtered ("Argument required (target name). Try `help target'\n",
275 /* Default target_has_* methods for process_stratum targets. */
278 default_child_has_all_memory (struct target_ops
*ops
)
280 /* If no inferior selected, then we can't read memory here. */
281 if (ptid_equal (inferior_ptid
, null_ptid
))
288 default_child_has_memory (struct target_ops
*ops
)
290 /* If no inferior selected, then we can't read memory here. */
291 if (ptid_equal (inferior_ptid
, null_ptid
))
298 default_child_has_stack (struct target_ops
*ops
)
300 /* If no inferior selected, there's no stack. */
301 if (ptid_equal (inferior_ptid
, null_ptid
))
308 default_child_has_registers (struct target_ops
*ops
)
310 /* Can't read registers from no inferior. */
311 if (ptid_equal (inferior_ptid
, null_ptid
))
318 default_child_has_execution (struct target_ops
*ops
)
320 /* If there's no thread selected, then we can't make it run through
322 if (ptid_equal (inferior_ptid
, null_ptid
))
330 target_has_all_memory_1 (void)
332 struct target_ops
*t
;
334 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
335 if (t
->to_has_all_memory (t
))
342 target_has_memory_1 (void)
344 struct target_ops
*t
;
346 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
347 if (t
->to_has_memory (t
))
354 target_has_stack_1 (void)
356 struct target_ops
*t
;
358 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
359 if (t
->to_has_stack (t
))
366 target_has_registers_1 (void)
368 struct target_ops
*t
;
370 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
371 if (t
->to_has_registers (t
))
378 target_has_execution_1 (void)
380 struct target_ops
*t
;
382 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
383 if (t
->to_has_execution (t
))
389 /* Add a possible target architecture to the list. */
392 add_target (struct target_ops
*t
)
394 /* Provide default values for all "must have" methods. */
395 if (t
->to_xfer_partial
== NULL
)
396 t
->to_xfer_partial
= default_xfer_partial
;
398 if (t
->to_has_all_memory
== NULL
)
399 t
->to_has_all_memory
= (int (*) (struct target_ops
*)) return_zero
;
401 if (t
->to_has_memory
== NULL
)
402 t
->to_has_memory
= (int (*) (struct target_ops
*)) return_zero
;
404 if (t
->to_has_stack
== NULL
)
405 t
->to_has_stack
= (int (*) (struct target_ops
*)) return_zero
;
407 if (t
->to_has_registers
== NULL
)
408 t
->to_has_registers
= (int (*) (struct target_ops
*)) return_zero
;
410 if (t
->to_has_execution
== NULL
)
411 t
->to_has_execution
= (int (*) (struct target_ops
*)) return_zero
;
415 target_struct_allocsize
= DEFAULT_ALLOCSIZE
;
416 target_structs
= (struct target_ops
**) xmalloc
417 (target_struct_allocsize
* sizeof (*target_structs
));
419 if (target_struct_size
>= target_struct_allocsize
)
421 target_struct_allocsize
*= 2;
422 target_structs
= (struct target_ops
**)
423 xrealloc ((char *) target_structs
,
424 target_struct_allocsize
* sizeof (*target_structs
));
426 target_structs
[target_struct_size
++] = t
;
428 if (targetlist
== NULL
)
429 add_prefix_cmd ("target", class_run
, target_command
, _("\
430 Connect to a target machine or process.\n\
431 The first argument is the type or protocol of the target machine.\n\
432 Remaining arguments are interpreted by the target protocol. For more\n\
433 information on the arguments for a particular protocol, type\n\
434 `help target ' followed by the protocol name."),
435 &targetlist
, "target ", 0, &cmdlist
);
436 add_cmd (t
->to_shortname
, no_class
, t
->to_open
, t
->to_doc
, &targetlist
);
449 struct target_ops
*t
;
451 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
452 if (t
->to_kill
!= NULL
)
455 fprintf_unfiltered (gdb_stdlog
, "target_kill ()\n");
465 target_load (char *arg
, int from_tty
)
467 target_dcache_invalidate ();
468 (*current_target
.to_load
) (arg
, from_tty
);
472 target_create_inferior (char *exec_file
, char *args
,
473 char **env
, int from_tty
)
475 struct target_ops
*t
;
477 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
479 if (t
->to_create_inferior
!= NULL
)
481 t
->to_create_inferior (t
, exec_file
, args
, env
, from_tty
);
483 fprintf_unfiltered (gdb_stdlog
,
484 "target_create_inferior (%s, %s, xxx, %d)\n",
485 exec_file
, args
, from_tty
);
490 internal_error (__FILE__
, __LINE__
,
491 "could not find a target to create inferior");
495 target_terminal_inferior (void)
497 /* A background resume (``run&'') should leave GDB in control of the
498 terminal. Use target_can_async_p, not target_is_async_p, since at
499 this point the target is not async yet. However, if sync_execution
500 is not set, we know it will become async prior to resume. */
501 if (target_can_async_p () && !sync_execution
)
504 /* If GDB is resuming the inferior in the foreground, install
505 inferior's terminal modes. */
506 (*current_target
.to_terminal_inferior
) ();
510 nomemory (CORE_ADDR memaddr
, char *myaddr
, int len
, int write
,
511 struct target_ops
*t
)
513 errno
= EIO
; /* Can't read/write this location */
514 return 0; /* No bytes handled */
520 error (_("You can't do that when your target is `%s'"),
521 current_target
.to_shortname
);
527 error (_("You can't do that without a process to debug."));
531 nosymbol (char *name
, CORE_ADDR
*addrp
)
533 return 1; /* Symbol does not exist in target env */
537 default_terminal_info (char *args
, int from_tty
)
539 printf_unfiltered (_("No saved terminal information.\n"));
542 /* A default implementation for the to_get_ada_task_ptid target method.
544 This function builds the PTID by using both LWP and TID as part of
545 the PTID lwp and tid elements. The pid used is the pid of the
549 default_get_ada_task_ptid (long lwp
, long tid
)
551 return ptid_build (ptid_get_pid (inferior_ptid
), lwp
, tid
);
554 /* Go through the target stack from top to bottom, copying over zero
555 entries in current_target, then filling in still empty entries. In
556 effect, we are doing class inheritance through the pushed target
559 NOTE: cagney/2003-10-17: The problem with this inheritance, as it
560 is currently implemented, is that it discards any knowledge of
561 which target an inherited method originally belonged to.
562 Consequently, new new target methods should instead explicitly and
563 locally search the target stack for the target that can handle the
567 update_current_target (void)
569 struct target_ops
*t
;
571 /* First, reset current's contents. */
572 memset (¤t_target
, 0, sizeof (current_target
));
574 #define INHERIT(FIELD, TARGET) \
575 if (!current_target.FIELD) \
576 current_target.FIELD = (TARGET)->FIELD
578 for (t
= target_stack
; t
; t
= t
->beneath
)
580 INHERIT (to_shortname
, t
);
581 INHERIT (to_longname
, t
);
583 /* Do not inherit to_open. */
584 /* Do not inherit to_close. */
585 /* Do not inherit to_attach. */
586 INHERIT (to_post_attach
, t
);
587 INHERIT (to_attach_no_wait
, t
);
588 /* Do not inherit to_detach. */
589 /* Do not inherit to_disconnect. */
590 /* Do not inherit to_resume. */
591 /* Do not inherit to_wait. */
592 /* Do not inherit to_fetch_registers. */
593 /* Do not inherit to_store_registers. */
594 INHERIT (to_prepare_to_store
, t
);
595 INHERIT (deprecated_xfer_memory
, t
);
596 INHERIT (to_files_info
, t
);
597 INHERIT (to_insert_breakpoint
, t
);
598 INHERIT (to_remove_breakpoint
, t
);
599 INHERIT (to_can_use_hw_breakpoint
, t
);
600 INHERIT (to_insert_hw_breakpoint
, t
);
601 INHERIT (to_remove_hw_breakpoint
, t
);
602 INHERIT (to_insert_watchpoint
, t
);
603 INHERIT (to_remove_watchpoint
, t
);
604 INHERIT (to_stopped_data_address
, t
);
605 INHERIT (to_have_steppable_watchpoint
, t
);
606 INHERIT (to_have_continuable_watchpoint
, t
);
607 INHERIT (to_stopped_by_watchpoint
, t
);
608 INHERIT (to_watchpoint_addr_within_range
, t
);
609 INHERIT (to_region_ok_for_hw_watchpoint
, t
);
610 INHERIT (to_terminal_init
, t
);
611 INHERIT (to_terminal_inferior
, t
);
612 INHERIT (to_terminal_ours_for_output
, t
);
613 INHERIT (to_terminal_ours
, t
);
614 INHERIT (to_terminal_save_ours
, t
);
615 INHERIT (to_terminal_info
, t
);
616 /* Do not inherit to_kill. */
617 INHERIT (to_load
, t
);
618 INHERIT (to_lookup_symbol
, t
);
619 /* Do no inherit to_create_inferior. */
620 INHERIT (to_post_startup_inferior
, t
);
621 INHERIT (to_acknowledge_created_inferior
, t
);
622 INHERIT (to_insert_fork_catchpoint
, t
);
623 INHERIT (to_remove_fork_catchpoint
, t
);
624 INHERIT (to_insert_vfork_catchpoint
, t
);
625 INHERIT (to_remove_vfork_catchpoint
, t
);
626 /* Do not inherit to_follow_fork. */
627 INHERIT (to_insert_exec_catchpoint
, t
);
628 INHERIT (to_remove_exec_catchpoint
, t
);
629 INHERIT (to_set_syscall_catchpoint
, t
);
630 INHERIT (to_has_exited
, t
);
631 /* Do not inherit to_mourn_inferior. */
632 INHERIT (to_can_run
, t
);
633 INHERIT (to_notice_signals
, t
);
634 /* Do not inherit to_thread_alive. */
635 /* Do not inherit to_find_new_threads. */
636 /* Do not inherit to_pid_to_str. */
637 INHERIT (to_extra_thread_info
, t
);
638 INHERIT (to_stop
, t
);
639 /* Do not inherit to_xfer_partial. */
640 INHERIT (to_rcmd
, t
);
641 INHERIT (to_pid_to_exec_file
, t
);
642 INHERIT (to_log_command
, t
);
643 INHERIT (to_stratum
, t
);
644 /* Do not inherit to_has_all_memory */
645 /* Do not inherit to_has_memory */
646 /* Do not inherit to_has_stack */
647 /* Do not inherit to_has_registers */
648 /* Do not inherit to_has_execution */
649 INHERIT (to_has_thread_control
, t
);
650 INHERIT (to_can_async_p
, t
);
651 INHERIT (to_is_async_p
, t
);
652 INHERIT (to_async
, t
);
653 INHERIT (to_async_mask
, t
);
654 INHERIT (to_find_memory_regions
, t
);
655 INHERIT (to_make_corefile_notes
, t
);
656 INHERIT (to_get_bookmark
, t
);
657 INHERIT (to_goto_bookmark
, t
);
658 /* Do not inherit to_get_thread_local_address. */
659 INHERIT (to_can_execute_reverse
, t
);
660 INHERIT (to_thread_architecture
, t
);
661 /* Do not inherit to_read_description. */
662 INHERIT (to_get_ada_task_ptid
, t
);
663 /* Do not inherit to_search_memory. */
664 INHERIT (to_supports_multi_process
, t
);
665 INHERIT (to_trace_init
, t
);
666 INHERIT (to_download_tracepoint
, t
);
667 INHERIT (to_download_trace_state_variable
, t
);
668 INHERIT (to_trace_set_readonly_regions
, t
);
669 INHERIT (to_trace_start
, t
);
670 INHERIT (to_get_trace_status
, t
);
671 INHERIT (to_trace_stop
, t
);
672 INHERIT (to_trace_find
, t
);
673 INHERIT (to_get_trace_state_variable_value
, t
);
674 INHERIT (to_save_trace_data
, t
);
675 INHERIT (to_upload_tracepoints
, t
);
676 INHERIT (to_upload_trace_state_variables
, t
);
677 INHERIT (to_get_raw_trace_data
, t
);
678 INHERIT (to_set_disconnected_tracing
, t
);
679 INHERIT (to_set_circular_trace_buffer
, t
);
680 INHERIT (to_get_tib_address
, t
);
681 INHERIT (to_set_permissions
, t
);
682 INHERIT (to_static_tracepoint_marker_at
, t
);
683 INHERIT (to_static_tracepoint_markers_by_strid
, t
);
684 INHERIT (to_magic
, t
);
685 /* Do not inherit to_memory_map. */
686 /* Do not inherit to_flash_erase. */
687 /* Do not inherit to_flash_done. */
691 /* Clean up a target struct so it no longer has any zero pointers in
692 it. Some entries are defaulted to a method that print an error,
693 others are hard-wired to a standard recursive default. */
695 #define de_fault(field, value) \
696 if (!current_target.field) \
697 current_target.field = value
700 (void (*) (char *, int))
705 de_fault (to_post_attach
,
708 de_fault (to_prepare_to_store
,
709 (void (*) (struct regcache
*))
711 de_fault (deprecated_xfer_memory
,
712 (int (*) (CORE_ADDR
, gdb_byte
*, int, int, struct mem_attrib
*, struct target_ops
*))
714 de_fault (to_files_info
,
715 (void (*) (struct target_ops
*))
717 de_fault (to_insert_breakpoint
,
718 memory_insert_breakpoint
);
719 de_fault (to_remove_breakpoint
,
720 memory_remove_breakpoint
);
721 de_fault (to_can_use_hw_breakpoint
,
722 (int (*) (int, int, int))
724 de_fault (to_insert_hw_breakpoint
,
725 (int (*) (struct gdbarch
*, struct bp_target_info
*))
727 de_fault (to_remove_hw_breakpoint
,
728 (int (*) (struct gdbarch
*, struct bp_target_info
*))
730 de_fault (to_insert_watchpoint
,
731 (int (*) (CORE_ADDR
, int, int))
733 de_fault (to_remove_watchpoint
,
734 (int (*) (CORE_ADDR
, int, int))
736 de_fault (to_stopped_by_watchpoint
,
739 de_fault (to_stopped_data_address
,
740 (int (*) (struct target_ops
*, CORE_ADDR
*))
742 de_fault (to_watchpoint_addr_within_range
,
743 default_watchpoint_addr_within_range
);
744 de_fault (to_region_ok_for_hw_watchpoint
,
745 default_region_ok_for_hw_watchpoint
);
746 de_fault (to_terminal_init
,
749 de_fault (to_terminal_inferior
,
752 de_fault (to_terminal_ours_for_output
,
755 de_fault (to_terminal_ours
,
758 de_fault (to_terminal_save_ours
,
761 de_fault (to_terminal_info
,
762 default_terminal_info
);
764 (void (*) (char *, int))
766 de_fault (to_lookup_symbol
,
767 (int (*) (char *, CORE_ADDR
*))
769 de_fault (to_post_startup_inferior
,
772 de_fault (to_acknowledge_created_inferior
,
775 de_fault (to_insert_fork_catchpoint
,
778 de_fault (to_remove_fork_catchpoint
,
781 de_fault (to_insert_vfork_catchpoint
,
784 de_fault (to_remove_vfork_catchpoint
,
787 de_fault (to_insert_exec_catchpoint
,
790 de_fault (to_remove_exec_catchpoint
,
793 de_fault (to_set_syscall_catchpoint
,
794 (int (*) (int, int, int, int, int *))
796 de_fault (to_has_exited
,
797 (int (*) (int, int, int *))
799 de_fault (to_can_run
,
801 de_fault (to_notice_signals
,
804 de_fault (to_extra_thread_info
,
805 (char *(*) (struct thread_info
*))
810 current_target
.to_xfer_partial
= current_xfer_partial
;
812 (void (*) (char *, struct ui_file
*))
814 de_fault (to_pid_to_exec_file
,
818 (void (*) (void (*) (enum inferior_event_type
, void*), void*))
820 de_fault (to_async_mask
,
823 de_fault (to_thread_architecture
,
824 default_thread_architecture
);
825 current_target
.to_read_description
= NULL
;
826 de_fault (to_get_ada_task_ptid
,
827 (ptid_t (*) (long, long))
828 default_get_ada_task_ptid
);
829 de_fault (to_supports_multi_process
,
832 de_fault (to_trace_init
,
835 de_fault (to_download_tracepoint
,
836 (void (*) (struct breakpoint
*))
838 de_fault (to_download_trace_state_variable
,
839 (void (*) (struct trace_state_variable
*))
841 de_fault (to_trace_set_readonly_regions
,
844 de_fault (to_trace_start
,
847 de_fault (to_get_trace_status
,
848 (int (*) (struct trace_status
*))
850 de_fault (to_trace_stop
,
853 de_fault (to_trace_find
,
854 (int (*) (enum trace_find_type
, int, ULONGEST
, ULONGEST
, int *))
856 de_fault (to_get_trace_state_variable_value
,
857 (int (*) (int, LONGEST
*))
859 de_fault (to_save_trace_data
,
860 (int (*) (const char *))
862 de_fault (to_upload_tracepoints
,
863 (int (*) (struct uploaded_tp
**))
865 de_fault (to_upload_trace_state_variables
,
866 (int (*) (struct uploaded_tsv
**))
868 de_fault (to_get_raw_trace_data
,
869 (LONGEST (*) (gdb_byte
*, ULONGEST
, LONGEST
))
871 de_fault (to_set_disconnected_tracing
,
874 de_fault (to_set_circular_trace_buffer
,
877 de_fault (to_get_tib_address
,
878 (int (*) (ptid_t
, CORE_ADDR
*))
880 de_fault (to_set_permissions
,
883 de_fault (to_static_tracepoint_marker_at
,
884 (int (*) (CORE_ADDR
, struct static_tracepoint_marker
*))
886 de_fault (to_static_tracepoint_markers_by_strid
,
887 (VEC(static_tracepoint_marker_p
) * (*) (const char *))
891 /* Finally, position the target-stack beneath the squashed
892 "current_target". That way code looking for a non-inherited
893 target method can quickly and simply find it. */
894 current_target
.beneath
= target_stack
;
897 setup_target_debug ();
900 /* Push a new target type into the stack of the existing target accessors,
901 possibly superseding some of the existing accessors.
903 Rather than allow an empty stack, we always have the dummy target at
904 the bottom stratum, so we can call the function vectors without
908 push_target (struct target_ops
*t
)
910 struct target_ops
**cur
;
912 /* Check magic number. If wrong, it probably means someone changed
913 the struct definition, but not all the places that initialize one. */
914 if (t
->to_magic
!= OPS_MAGIC
)
916 fprintf_unfiltered (gdb_stderr
,
917 "Magic number of %s target struct wrong\n",
919 internal_error (__FILE__
, __LINE__
, _("failed internal consistency check"));
922 /* Find the proper stratum to install this target in. */
923 for (cur
= &target_stack
; (*cur
) != NULL
; cur
= &(*cur
)->beneath
)
925 if ((int) (t
->to_stratum
) >= (int) (*cur
)->to_stratum
)
929 /* If there's already targets at this stratum, remove them. */
930 /* FIXME: cagney/2003-10-15: I think this should be popping all
931 targets to CUR, and not just those at this stratum level. */
932 while ((*cur
) != NULL
&& t
->to_stratum
== (*cur
)->to_stratum
)
934 /* There's already something at this stratum level. Close it,
935 and un-hook it from the stack. */
936 struct target_ops
*tmp
= (*cur
);
938 (*cur
) = (*cur
)->beneath
;
940 target_close (tmp
, 0);
943 /* We have removed all targets in our stratum, now add the new one. */
947 update_current_target ();
950 /* Remove a target_ops vector from the stack, wherever it may be.
951 Return how many times it was removed (0 or 1). */
954 unpush_target (struct target_ops
*t
)
956 struct target_ops
**cur
;
957 struct target_ops
*tmp
;
959 if (t
->to_stratum
== dummy_stratum
)
960 internal_error (__FILE__
, __LINE__
,
961 "Attempt to unpush the dummy target");
963 /* Look for the specified target. Note that we assume that a target
964 can only occur once in the target stack. */
966 for (cur
= &target_stack
; (*cur
) != NULL
; cur
= &(*cur
)->beneath
)
973 return 0; /* Didn't find target_ops, quit now */
975 /* NOTE: cagney/2003-12-06: In '94 the close call was made
976 unconditional by moving it to before the above check that the
977 target was in the target stack (something about "Change the way
978 pushing and popping of targets work to support target overlays
979 and inheritance"). This doesn't make much sense - only open
980 targets should be closed. */
983 /* Unchain the target */
985 (*cur
) = (*cur
)->beneath
;
988 update_current_target ();
996 target_close (target_stack
, 0); /* Let it clean up */
997 if (unpush_target (target_stack
) == 1)
1000 fprintf_unfiltered (gdb_stderr
,
1001 "pop_target couldn't find target %s\n",
1002 current_target
.to_shortname
);
1003 internal_error (__FILE__
, __LINE__
,
1004 _("failed internal consistency check"));
1008 pop_all_targets_above (enum strata above_stratum
, int quitting
)
1010 while ((int) (current_target
.to_stratum
) > (int) above_stratum
)
1012 target_close (target_stack
, quitting
);
1013 if (!unpush_target (target_stack
))
1015 fprintf_unfiltered (gdb_stderr
,
1016 "pop_all_targets couldn't find target %s\n",
1017 target_stack
->to_shortname
);
1018 internal_error (__FILE__
, __LINE__
,
1019 _("failed internal consistency check"));
1026 pop_all_targets (int quitting
)
1028 pop_all_targets_above (dummy_stratum
, quitting
);
1031 /* Using the objfile specified in OBJFILE, find the address for the
1032 current thread's thread-local storage with offset OFFSET. */
1034 target_translate_tls_address (struct objfile
*objfile
, CORE_ADDR offset
)
1036 volatile CORE_ADDR addr
= 0;
1037 struct target_ops
*target
;
1039 for (target
= current_target
.beneath
;
1041 target
= target
->beneath
)
1043 if (target
->to_get_thread_local_address
!= NULL
)
1048 && gdbarch_fetch_tls_load_module_address_p (target_gdbarch
))
1050 ptid_t ptid
= inferior_ptid
;
1051 volatile struct gdb_exception ex
;
1053 TRY_CATCH (ex
, RETURN_MASK_ALL
)
1057 /* Fetch the load module address for this objfile. */
1058 lm_addr
= gdbarch_fetch_tls_load_module_address (target_gdbarch
,
1060 /* If it's 0, throw the appropriate exception. */
1062 throw_error (TLS_LOAD_MODULE_NOT_FOUND_ERROR
,
1063 _("TLS load module not found"));
1065 addr
= target
->to_get_thread_local_address (target
, ptid
, lm_addr
, offset
);
1067 /* If an error occurred, print TLS related messages here. Otherwise,
1068 throw the error to some higher catcher. */
1071 int objfile_is_library
= (objfile
->flags
& OBJF_SHARED
);
1075 case TLS_NO_LIBRARY_SUPPORT_ERROR
:
1076 error (_("Cannot find thread-local variables in this thread library."));
1078 case TLS_LOAD_MODULE_NOT_FOUND_ERROR
:
1079 if (objfile_is_library
)
1080 error (_("Cannot find shared library `%s' in dynamic"
1081 " linker's load module list"), objfile
->name
);
1083 error (_("Cannot find executable file `%s' in dynamic"
1084 " linker's load module list"), objfile
->name
);
1086 case TLS_NOT_ALLOCATED_YET_ERROR
:
1087 if (objfile_is_library
)
1088 error (_("The inferior has not yet allocated storage for"
1089 " thread-local variables in\n"
1090 "the shared library `%s'\n"
1092 objfile
->name
, target_pid_to_str (ptid
));
1094 error (_("The inferior has not yet allocated storage for"
1095 " thread-local variables in\n"
1096 "the executable `%s'\n"
1098 objfile
->name
, target_pid_to_str (ptid
));
1100 case TLS_GENERIC_ERROR
:
1101 if (objfile_is_library
)
1102 error (_("Cannot find thread-local storage for %s, "
1103 "shared library %s:\n%s"),
1104 target_pid_to_str (ptid
),
1105 objfile
->name
, ex
.message
);
1107 error (_("Cannot find thread-local storage for %s, "
1108 "executable file %s:\n%s"),
1109 target_pid_to_str (ptid
),
1110 objfile
->name
, ex
.message
);
1113 throw_exception (ex
);
1118 /* It wouldn't be wrong here to try a gdbarch method, too; finding
1119 TLS is an ABI-specific thing. But we don't do that yet. */
1121 error (_("Cannot find thread-local variables on this target"));
1127 #define MIN(A, B) (((A) <= (B)) ? (A) : (B))
1129 /* target_read_string -- read a null terminated string, up to LEN bytes,
1130 from MEMADDR in target. Set *ERRNOP to the errno code, or 0 if successful.
1131 Set *STRING to a pointer to malloc'd memory containing the data; the caller
1132 is responsible for freeing it. Return the number of bytes successfully
1136 target_read_string (CORE_ADDR memaddr
, char **string
, int len
, int *errnop
)
1138 int tlen
, origlen
, offset
, i
;
1142 int buffer_allocated
;
1144 unsigned int nbytes_read
= 0;
1146 gdb_assert (string
);
1148 /* Small for testing. */
1149 buffer_allocated
= 4;
1150 buffer
= xmalloc (buffer_allocated
);
1157 tlen
= MIN (len
, 4 - (memaddr
& 3));
1158 offset
= memaddr
& 3;
1160 errcode
= target_read_memory (memaddr
& ~3, buf
, sizeof buf
);
1163 /* The transfer request might have crossed the boundary to an
1164 unallocated region of memory. Retry the transfer, requesting
1168 errcode
= target_read_memory (memaddr
, buf
, 1);
1173 if (bufptr
- buffer
+ tlen
> buffer_allocated
)
1177 bytes
= bufptr
- buffer
;
1178 buffer_allocated
*= 2;
1179 buffer
= xrealloc (buffer
, buffer_allocated
);
1180 bufptr
= buffer
+ bytes
;
1183 for (i
= 0; i
< tlen
; i
++)
1185 *bufptr
++ = buf
[i
+ offset
];
1186 if (buf
[i
+ offset
] == '\000')
1188 nbytes_read
+= i
+ 1;
1195 nbytes_read
+= tlen
;
1204 struct target_section_table
*
1205 target_get_section_table (struct target_ops
*target
)
1207 struct target_ops
*t
;
1210 fprintf_unfiltered (gdb_stdlog
, "target_get_section_table ()\n");
1212 for (t
= target
; t
!= NULL
; t
= t
->beneath
)
1213 if (t
->to_get_section_table
!= NULL
)
1214 return (*t
->to_get_section_table
) (t
);
1219 /* Find a section containing ADDR. */
1221 struct target_section
*
1222 target_section_by_addr (struct target_ops
*target
, CORE_ADDR addr
)
1224 struct target_section_table
*table
= target_get_section_table (target
);
1225 struct target_section
*secp
;
1230 for (secp
= table
->sections
; secp
< table
->sections_end
; secp
++)
1232 if (addr
>= secp
->addr
&& addr
< secp
->endaddr
)
1238 /* Perform a partial memory transfer.
1239 For docs see target.h, to_xfer_partial. */
1242 memory_xfer_partial (struct target_ops
*ops
, enum target_object object
,
1243 void *readbuf
, const void *writebuf
, ULONGEST memaddr
,
1248 struct mem_region
*region
;
1249 struct inferior
*inf
;
1251 /* Zero length requests are ok and require no work. */
1255 /* For accesses to unmapped overlay sections, read directly from
1256 files. Must do this first, as MEMADDR may need adjustment. */
1257 if (readbuf
!= NULL
&& overlay_debugging
)
1259 struct obj_section
*section
= find_pc_overlay (memaddr
);
1261 if (pc_in_unmapped_range (memaddr
, section
))
1263 struct target_section_table
*table
1264 = target_get_section_table (ops
);
1265 const char *section_name
= section
->the_bfd_section
->name
;
1267 memaddr
= overlay_mapped_address (memaddr
, section
);
1268 return section_table_xfer_memory_partial (readbuf
, writebuf
,
1271 table
->sections_end
,
1276 /* Try the executable files, if "trust-readonly-sections" is set. */
1277 if (readbuf
!= NULL
&& trust_readonly
)
1279 struct target_section
*secp
;
1280 struct target_section_table
*table
;
1282 secp
= target_section_by_addr (ops
, memaddr
);
1284 && (bfd_get_section_flags (secp
->bfd
, secp
->the_bfd_section
)
1287 table
= target_get_section_table (ops
);
1288 return section_table_xfer_memory_partial (readbuf
, writebuf
,
1291 table
->sections_end
,
1296 /* Try GDB's internal data cache. */
1297 region
= lookup_mem_region (memaddr
);
1298 /* region->hi == 0 means there's no upper bound. */
1299 if (memaddr
+ len
< region
->hi
|| region
->hi
== 0)
1302 reg_len
= region
->hi
- memaddr
;
1304 switch (region
->attrib
.mode
)
1307 if (writebuf
!= NULL
)
1312 if (readbuf
!= NULL
)
1317 /* We only support writing to flash during "load" for now. */
1318 if (writebuf
!= NULL
)
1319 error (_("Writing to flash memory forbidden in this context"));
1326 if (!ptid_equal (inferior_ptid
, null_ptid
))
1327 inf
= find_inferior_pid (ptid_get_pid (inferior_ptid
));
1332 /* The dcache reads whole cache lines; that doesn't play well
1333 with reading from a trace buffer, because reading outside of
1334 the collected memory range fails. */
1335 && get_traceframe_number () == -1
1336 && (region
->attrib
.cache
1337 || (stack_cache_enabled_p
&& object
== TARGET_OBJECT_STACK_MEMORY
)))
1339 if (readbuf
!= NULL
)
1340 res
= dcache_xfer_memory (ops
, target_dcache
, memaddr
, readbuf
,
1343 /* FIXME drow/2006-08-09: If we're going to preserve const
1344 correctness dcache_xfer_memory should take readbuf and
1346 res
= dcache_xfer_memory (ops
, target_dcache
, memaddr
,
1353 if (readbuf
&& !show_memory_breakpoints
)
1354 breakpoint_restore_shadows (readbuf
, memaddr
, reg_len
);
1359 /* If none of those methods found the memory we wanted, fall back
1360 to a target partial transfer. Normally a single call to
1361 to_xfer_partial is enough; if it doesn't recognize an object
1362 it will call the to_xfer_partial of the next target down.
1363 But for memory this won't do. Memory is the only target
1364 object which can be read from more than one valid target.
1365 A core file, for instance, could have some of memory but
1366 delegate other bits to the target below it. So, we must
1367 manually try all targets. */
1371 res
= ops
->to_xfer_partial (ops
, TARGET_OBJECT_MEMORY
, NULL
,
1372 readbuf
, writebuf
, memaddr
, reg_len
);
1376 /* We want to continue past core files to executables, but not
1377 past a running target's memory. */
1378 if (ops
->to_has_all_memory (ops
))
1383 while (ops
!= NULL
);
1385 if (readbuf
&& !show_memory_breakpoints
)
1386 breakpoint_restore_shadows (readbuf
, memaddr
, reg_len
);
1388 /* Make sure the cache gets updated no matter what - if we are writing
1389 to the stack. Even if this write is not tagged as such, we still need
1390 to update the cache. */
1395 && !region
->attrib
.cache
1396 && stack_cache_enabled_p
1397 && object
!= TARGET_OBJECT_STACK_MEMORY
)
1399 dcache_update (target_dcache
, memaddr
, (void *) writebuf
, res
);
1402 /* If we still haven't got anything, return the last error. We
1408 restore_show_memory_breakpoints (void *arg
)
1410 show_memory_breakpoints
= (uintptr_t) arg
;
1414 make_show_memory_breakpoints_cleanup (int show
)
1416 int current
= show_memory_breakpoints
;
1418 show_memory_breakpoints
= show
;
1419 return make_cleanup (restore_show_memory_breakpoints
,
1420 (void *) (uintptr_t) current
);
1423 /* For docs see target.h, to_xfer_partial. */
1426 target_xfer_partial (struct target_ops
*ops
,
1427 enum target_object object
, const char *annex
,
1428 void *readbuf
, const void *writebuf
,
1429 ULONGEST offset
, LONGEST len
)
1433 gdb_assert (ops
->to_xfer_partial
!= NULL
);
1435 if (writebuf
&& !may_write_memory
)
1436 error (_("Writing to memory is not allowed (addr %s, len %s)"),
1437 core_addr_to_string_nz (offset
), plongest (len
));
1439 /* If this is a memory transfer, let the memory-specific code
1440 have a look at it instead. Memory transfers are more
1442 if (object
== TARGET_OBJECT_MEMORY
|| object
== TARGET_OBJECT_STACK_MEMORY
)
1443 retval
= memory_xfer_partial (ops
, object
, readbuf
,
1444 writebuf
, offset
, len
);
1447 enum target_object raw_object
= object
;
1449 /* If this is a raw memory transfer, request the normal
1450 memory object from other layers. */
1451 if (raw_object
== TARGET_OBJECT_RAW_MEMORY
)
1452 raw_object
= TARGET_OBJECT_MEMORY
;
1454 retval
= ops
->to_xfer_partial (ops
, raw_object
, annex
, readbuf
,
1455 writebuf
, offset
, len
);
1460 const unsigned char *myaddr
= NULL
;
1462 fprintf_unfiltered (gdb_stdlog
,
1463 "%s:target_xfer_partial (%d, %s, %s, %s, %s, %s) = %s",
1466 (annex
? annex
: "(null)"),
1467 host_address_to_string (readbuf
),
1468 host_address_to_string (writebuf
),
1469 core_addr_to_string_nz (offset
),
1470 plongest (len
), plongest (retval
));
1476 if (retval
> 0 && myaddr
!= NULL
)
1480 fputs_unfiltered (", bytes =", gdb_stdlog
);
1481 for (i
= 0; i
< retval
; i
++)
1483 if ((((intptr_t) &(myaddr
[i
])) & 0xf) == 0)
1485 if (targetdebug
< 2 && i
> 0)
1487 fprintf_unfiltered (gdb_stdlog
, " ...");
1490 fprintf_unfiltered (gdb_stdlog
, "\n");
1493 fprintf_unfiltered (gdb_stdlog
, " %02x", myaddr
[i
] & 0xff);
1497 fputc_unfiltered ('\n', gdb_stdlog
);
1502 /* Read LEN bytes of target memory at address MEMADDR, placing the results in
1503 GDB's memory at MYADDR. Returns either 0 for success or an errno value
1504 if any error occurs.
1506 If an error occurs, no guarantee is made about the contents of the data at
1507 MYADDR. In particular, the caller should not depend upon partial reads
1508 filling the buffer with good data. There is no way for the caller to know
1509 how much good data might have been transfered anyway. Callers that can
1510 deal with partial reads should call target_read (which will retry until
1511 it makes no progress, and then return how much was transferred). */
1514 target_read_memory (CORE_ADDR memaddr
, gdb_byte
*myaddr
, int len
)
1516 /* Dispatch to the topmost target, not the flattened current_target.
1517 Memory accesses check target->to_has_(all_)memory, and the
1518 flattened target doesn't inherit those. */
1519 if (target_read (current_target
.beneath
, TARGET_OBJECT_MEMORY
, NULL
,
1520 myaddr
, memaddr
, len
) == len
)
1526 /* Like target_read_memory, but specify explicitly that this is a read from
1527 the target's stack. This may trigger different cache behavior. */
1530 target_read_stack (CORE_ADDR memaddr
, gdb_byte
*myaddr
, int len
)
1532 /* Dispatch to the topmost target, not the flattened current_target.
1533 Memory accesses check target->to_has_(all_)memory, and the
1534 flattened target doesn't inherit those. */
1536 if (target_read (current_target
.beneath
, TARGET_OBJECT_STACK_MEMORY
, NULL
,
1537 myaddr
, memaddr
, len
) == len
)
1543 /* Write LEN bytes from MYADDR to target memory at address MEMADDR.
1544 Returns either 0 for success or an errno value if any error occurs.
1545 If an error occurs, no guarantee is made about how much data got written.
1546 Callers that can deal with partial writes should call target_write. */
1549 target_write_memory (CORE_ADDR memaddr
, const gdb_byte
*myaddr
, int len
)
1551 /* Dispatch to the topmost target, not the flattened current_target.
1552 Memory accesses check target->to_has_(all_)memory, and the
1553 flattened target doesn't inherit those. */
1554 if (target_write (current_target
.beneath
, TARGET_OBJECT_MEMORY
, NULL
,
1555 myaddr
, memaddr
, len
) == len
)
1561 /* Fetch the target's memory map. */
1564 target_memory_map (void)
1566 VEC(mem_region_s
) *result
;
1567 struct mem_region
*last_one
, *this_one
;
1569 struct target_ops
*t
;
1572 fprintf_unfiltered (gdb_stdlog
, "target_memory_map ()\n");
1574 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
1575 if (t
->to_memory_map
!= NULL
)
1581 result
= t
->to_memory_map (t
);
1585 qsort (VEC_address (mem_region_s
, result
),
1586 VEC_length (mem_region_s
, result
),
1587 sizeof (struct mem_region
), mem_region_cmp
);
1589 /* Check that regions do not overlap. Simultaneously assign
1590 a numbering for the "mem" commands to use to refer to
1593 for (ix
= 0; VEC_iterate (mem_region_s
, result
, ix
, this_one
); ix
++)
1595 this_one
->number
= ix
;
1597 if (last_one
&& last_one
->hi
> this_one
->lo
)
1599 warning (_("Overlapping regions in memory map: ignoring"));
1600 VEC_free (mem_region_s
, result
);
1603 last_one
= this_one
;
1610 target_flash_erase (ULONGEST address
, LONGEST length
)
1612 struct target_ops
*t
;
1614 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
1615 if (t
->to_flash_erase
!= NULL
)
1618 fprintf_unfiltered (gdb_stdlog
, "target_flash_erase (%s, %s)\n",
1619 hex_string (address
), phex (length
, 0));
1620 t
->to_flash_erase (t
, address
, length
);
1628 target_flash_done (void)
1630 struct target_ops
*t
;
1632 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
1633 if (t
->to_flash_done
!= NULL
)
1636 fprintf_unfiltered (gdb_stdlog
, "target_flash_done\n");
1637 t
->to_flash_done (t
);
1645 show_trust_readonly (struct ui_file
*file
, int from_tty
,
1646 struct cmd_list_element
*c
, const char *value
)
1648 fprintf_filtered (file
, _("\
1649 Mode for reading from readonly sections is %s.\n"),
1653 /* More generic transfers. */
1656 default_xfer_partial (struct target_ops
*ops
, enum target_object object
,
1657 const char *annex
, gdb_byte
*readbuf
,
1658 const gdb_byte
*writebuf
, ULONGEST offset
, LONGEST len
)
1660 if (object
== TARGET_OBJECT_MEMORY
1661 && ops
->deprecated_xfer_memory
!= NULL
)
1662 /* If available, fall back to the target's
1663 "deprecated_xfer_memory" method. */
1668 if (writebuf
!= NULL
)
1670 void *buffer
= xmalloc (len
);
1671 struct cleanup
*cleanup
= make_cleanup (xfree
, buffer
);
1673 memcpy (buffer
, writebuf
, len
);
1674 xfered
= ops
->deprecated_xfer_memory (offset
, buffer
, len
,
1675 1/*write*/, NULL
, ops
);
1676 do_cleanups (cleanup
);
1678 if (readbuf
!= NULL
)
1679 xfered
= ops
->deprecated_xfer_memory (offset
, readbuf
, len
,
1680 0/*read*/, NULL
, ops
);
1683 else if (xfered
== 0 && errno
== 0)
1684 /* "deprecated_xfer_memory" uses 0, cross checked against
1685 ERRNO as one indication of an error. */
1690 else if (ops
->beneath
!= NULL
)
1691 return ops
->beneath
->to_xfer_partial (ops
->beneath
, object
, annex
,
1692 readbuf
, writebuf
, offset
, len
);
1697 /* The xfer_partial handler for the topmost target. Unlike the default,
1698 it does not need to handle memory specially; it just passes all
1699 requests down the stack. */
1702 current_xfer_partial (struct target_ops
*ops
, enum target_object object
,
1703 const char *annex
, gdb_byte
*readbuf
,
1704 const gdb_byte
*writebuf
, ULONGEST offset
, LONGEST len
)
1706 if (ops
->beneath
!= NULL
)
1707 return ops
->beneath
->to_xfer_partial (ops
->beneath
, object
, annex
,
1708 readbuf
, writebuf
, offset
, len
);
1713 /* Target vector read/write partial wrapper functions. */
1716 target_read_partial (struct target_ops
*ops
,
1717 enum target_object object
,
1718 const char *annex
, gdb_byte
*buf
,
1719 ULONGEST offset
, LONGEST len
)
1721 return target_xfer_partial (ops
, object
, annex
, buf
, NULL
, offset
, len
);
1725 target_write_partial (struct target_ops
*ops
,
1726 enum target_object object
,
1727 const char *annex
, const gdb_byte
*buf
,
1728 ULONGEST offset
, LONGEST len
)
1730 return target_xfer_partial (ops
, object
, annex
, NULL
, buf
, offset
, len
);
1733 /* Wrappers to perform the full transfer. */
1735 /* For docs on target_read see target.h. */
1738 target_read (struct target_ops
*ops
,
1739 enum target_object object
,
1740 const char *annex
, gdb_byte
*buf
,
1741 ULONGEST offset
, LONGEST len
)
1745 while (xfered
< len
)
1747 LONGEST xfer
= target_read_partial (ops
, object
, annex
,
1748 (gdb_byte
*) buf
+ xfered
,
1749 offset
+ xfered
, len
- xfered
);
1751 /* Call an observer, notifying them of the xfer progress? */
1763 target_read_until_error (struct target_ops
*ops
,
1764 enum target_object object
,
1765 const char *annex
, gdb_byte
*buf
,
1766 ULONGEST offset
, LONGEST len
)
1770 while (xfered
< len
)
1772 LONGEST xfer
= target_read_partial (ops
, object
, annex
,
1773 (gdb_byte
*) buf
+ xfered
,
1774 offset
+ xfered
, len
- xfered
);
1776 /* Call an observer, notifying them of the xfer progress? */
1781 /* We've got an error. Try to read in smaller blocks. */
1782 ULONGEST start
= offset
+ xfered
;
1783 ULONGEST remaining
= len
- xfered
;
1786 /* If an attempt was made to read a random memory address,
1787 it's likely that the very first byte is not accessible.
1788 Try reading the first byte, to avoid doing log N tries
1790 xfer
= target_read_partial (ops
, object
, annex
,
1791 (gdb_byte
*) buf
+ xfered
, start
, 1);
1800 xfer
= target_read_partial (ops
, object
, annex
,
1801 (gdb_byte
*) buf
+ xfered
,
1811 /* We have successfully read the first half. So, the
1812 error must be in the second half. Adjust start and
1813 remaining to point at the second half. */
1829 /* An alternative to target_write with progress callbacks. */
1832 target_write_with_progress (struct target_ops
*ops
,
1833 enum target_object object
,
1834 const char *annex
, const gdb_byte
*buf
,
1835 ULONGEST offset
, LONGEST len
,
1836 void (*progress
) (ULONGEST
, void *), void *baton
)
1840 /* Give the progress callback a chance to set up. */
1842 (*progress
) (0, baton
);
1844 while (xfered
< len
)
1846 LONGEST xfer
= target_write_partial (ops
, object
, annex
,
1847 (gdb_byte
*) buf
+ xfered
,
1848 offset
+ xfered
, len
- xfered
);
1856 (*progress
) (xfer
, baton
);
1864 /* For docs on target_write see target.h. */
1867 target_write (struct target_ops
*ops
,
1868 enum target_object object
,
1869 const char *annex
, const gdb_byte
*buf
,
1870 ULONGEST offset
, LONGEST len
)
1872 return target_write_with_progress (ops
, object
, annex
, buf
, offset
, len
,
1876 /* Read OBJECT/ANNEX using OPS. Store the result in *BUF_P and return
1877 the size of the transferred data. PADDING additional bytes are
1878 available in *BUF_P. This is a helper function for
1879 target_read_alloc; see the declaration of that function for more
1883 target_read_alloc_1 (struct target_ops
*ops
, enum target_object object
,
1884 const char *annex
, gdb_byte
**buf_p
, int padding
)
1886 size_t buf_alloc
, buf_pos
;
1890 /* This function does not have a length parameter; it reads the
1891 entire OBJECT). Also, it doesn't support objects fetched partly
1892 from one target and partly from another (in a different stratum,
1893 e.g. a core file and an executable). Both reasons make it
1894 unsuitable for reading memory. */
1895 gdb_assert (object
!= TARGET_OBJECT_MEMORY
);
1897 /* Start by reading up to 4K at a time. The target will throttle
1898 this number down if necessary. */
1900 buf
= xmalloc (buf_alloc
);
1904 n
= target_read_partial (ops
, object
, annex
, &buf
[buf_pos
],
1905 buf_pos
, buf_alloc
- buf_pos
- padding
);
1908 /* An error occurred. */
1914 /* Read all there was. */
1924 /* If the buffer is filling up, expand it. */
1925 if (buf_alloc
< buf_pos
* 2)
1928 buf
= xrealloc (buf
, buf_alloc
);
1935 /* Read OBJECT/ANNEX using OPS. Store the result in *BUF_P and return
1936 the size of the transferred data. See the declaration in "target.h"
1937 function for more information about the return value. */
1940 target_read_alloc (struct target_ops
*ops
, enum target_object object
,
1941 const char *annex
, gdb_byte
**buf_p
)
1943 return target_read_alloc_1 (ops
, object
, annex
, buf_p
, 0);
1946 /* Read OBJECT/ANNEX using OPS. The result is NUL-terminated and
1947 returned as a string, allocated using xmalloc. If an error occurs
1948 or the transfer is unsupported, NULL is returned. Empty objects
1949 are returned as allocated but empty strings. A warning is issued
1950 if the result contains any embedded NUL bytes. */
1953 target_read_stralloc (struct target_ops
*ops
, enum target_object object
,
1957 LONGEST transferred
;
1959 transferred
= target_read_alloc_1 (ops
, object
, annex
, &buffer
, 1);
1961 if (transferred
< 0)
1964 if (transferred
== 0)
1965 return xstrdup ("");
1967 buffer
[transferred
] = 0;
1968 if (strlen (buffer
) < transferred
)
1969 warning (_("target object %d, annex %s, "
1970 "contained unexpected null characters"),
1971 (int) object
, annex
? annex
: "(none)");
1973 return (char *) buffer
;
1976 /* Memory transfer methods. */
1979 get_target_memory (struct target_ops
*ops
, CORE_ADDR addr
, gdb_byte
*buf
,
1982 /* This method is used to read from an alternate, non-current
1983 target. This read must bypass the overlay support (as symbols
1984 don't match this target), and GDB's internal cache (wrong cache
1985 for this target). */
1986 if (target_read (ops
, TARGET_OBJECT_RAW_MEMORY
, NULL
, buf
, addr
, len
)
1988 memory_error (EIO
, addr
);
1992 get_target_memory_unsigned (struct target_ops
*ops
, CORE_ADDR addr
,
1993 int len
, enum bfd_endian byte_order
)
1995 gdb_byte buf
[sizeof (ULONGEST
)];
1997 gdb_assert (len
<= sizeof (buf
));
1998 get_target_memory (ops
, addr
, buf
, len
);
1999 return extract_unsigned_integer (buf
, len
, byte_order
);
2003 target_insert_breakpoint (struct gdbarch
*gdbarch
,
2004 struct bp_target_info
*bp_tgt
)
2006 if (!may_insert_breakpoints
)
2008 warning (_("May not insert breakpoints"));
2012 return (*current_target
.to_insert_breakpoint
) (gdbarch
, bp_tgt
);
2016 target_remove_breakpoint (struct gdbarch
*gdbarch
,
2017 struct bp_target_info
*bp_tgt
)
2019 /* This is kind of a weird case to handle, but the permission might
2020 have been changed after breakpoints were inserted - in which case
2021 we should just take the user literally and assume that any
2022 breakpoints should be left in place. */
2023 if (!may_insert_breakpoints
)
2025 warning (_("May not remove breakpoints"));
2029 return (*current_target
.to_remove_breakpoint
) (gdbarch
, bp_tgt
);
2033 target_info (char *args
, int from_tty
)
2035 struct target_ops
*t
;
2036 int has_all_mem
= 0;
2038 if (symfile_objfile
!= NULL
)
2039 printf_unfiltered (_("Symbols from \"%s\".\n"), symfile_objfile
->name
);
2041 for (t
= target_stack
; t
!= NULL
; t
= t
->beneath
)
2043 if (!(*t
->to_has_memory
) (t
))
2046 if ((int) (t
->to_stratum
) <= (int) dummy_stratum
)
2049 printf_unfiltered (_("\tWhile running this, GDB does not access memory from...\n"));
2050 printf_unfiltered ("%s:\n", t
->to_longname
);
2051 (t
->to_files_info
) (t
);
2052 has_all_mem
= (*t
->to_has_all_memory
) (t
);
2056 /* This function is called before any new inferior is created, e.g.
2057 by running a program, attaching, or connecting to a target.
2058 It cleans up any state from previous invocations which might
2059 change between runs. This is a subset of what target_preopen
2060 resets (things which might change between targets). */
2063 target_pre_inferior (int from_tty
)
2065 /* Clear out solib state. Otherwise the solib state of the previous
2066 inferior might have survived and is entirely wrong for the new
2067 target. This has been observed on GNU/Linux using glibc 2.3. How
2079 Cannot access memory at address 0xdeadbeef
2082 /* In some OSs, the shared library list is the same/global/shared
2083 across inferiors. If code is shared between processes, so are
2084 memory regions and features. */
2085 if (!gdbarch_has_global_solist (target_gdbarch
))
2087 no_shared_libraries (NULL
, from_tty
);
2089 invalidate_target_mem_regions ();
2091 target_clear_description ();
2095 /* Callback for iterate_over_inferiors. Gets rid of the given
2099 dispose_inferior (struct inferior
*inf
, void *args
)
2101 struct thread_info
*thread
;
2103 thread
= any_thread_of_process (inf
->pid
);
2106 switch_to_thread (thread
->ptid
);
2108 /* Core inferiors actually should be detached, not killed. */
2109 if (target_has_execution
)
2112 target_detach (NULL
, 0);
2118 /* This is to be called by the open routine before it does
2122 target_preopen (int from_tty
)
2126 if (have_inferiors ())
2129 || !have_live_inferiors ()
2130 || query (_("A program is being debugged already. Kill it? ")))
2131 iterate_over_inferiors (dispose_inferior
, NULL
);
2133 error (_("Program not killed."));
2136 /* Calling target_kill may remove the target from the stack. But if
2137 it doesn't (which seems like a win for UDI), remove it now. */
2138 /* Leave the exec target, though. The user may be switching from a
2139 live process to a core of the same program. */
2140 pop_all_targets_above (file_stratum
, 0);
2142 target_pre_inferior (from_tty
);
2145 /* Detach a target after doing deferred register stores. */
2148 target_detach (char *args
, int from_tty
)
2150 struct target_ops
* t
;
2152 if (gdbarch_has_global_breakpoints (target_gdbarch
))
2153 /* Don't remove global breakpoints here. They're removed on
2154 disconnection from the target. */
2157 /* If we're in breakpoints-always-inserted mode, have to remove
2158 them before detaching. */
2159 remove_breakpoints_pid (PIDGET (inferior_ptid
));
2161 prepare_for_detach ();
2163 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
2165 if (t
->to_detach
!= NULL
)
2167 t
->to_detach (t
, args
, from_tty
);
2169 fprintf_unfiltered (gdb_stdlog
, "target_detach (%s, %d)\n",
2175 internal_error (__FILE__
, __LINE__
, "could not find a target to detach");
2179 target_disconnect (char *args
, int from_tty
)
2181 struct target_ops
*t
;
2183 /* If we're in breakpoints-always-inserted mode or if breakpoints
2184 are global across processes, we have to remove them before
2186 remove_breakpoints ();
2188 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
2189 if (t
->to_disconnect
!= NULL
)
2192 fprintf_unfiltered (gdb_stdlog
, "target_disconnect (%s, %d)\n",
2194 t
->to_disconnect (t
, args
, from_tty
);
2202 target_wait (ptid_t ptid
, struct target_waitstatus
*status
, int options
)
2204 struct target_ops
*t
;
2206 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
2208 if (t
->to_wait
!= NULL
)
2210 ptid_t retval
= (*t
->to_wait
) (t
, ptid
, status
, options
);
2214 char *status_string
;
2216 status_string
= target_waitstatus_to_string (status
);
2217 fprintf_unfiltered (gdb_stdlog
,
2218 "target_wait (%d, status) = %d, %s\n",
2219 PIDGET (ptid
), PIDGET (retval
),
2221 xfree (status_string
);
2232 target_pid_to_str (ptid_t ptid
)
2234 struct target_ops
*t
;
2236 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
2238 if (t
->to_pid_to_str
!= NULL
)
2239 return (*t
->to_pid_to_str
) (t
, ptid
);
2242 return normal_pid_to_str (ptid
);
2246 target_resume (ptid_t ptid
, int step
, enum target_signal signal
)
2248 struct target_ops
*t
;
2250 target_dcache_invalidate ();
2252 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
2254 if (t
->to_resume
!= NULL
)
2256 t
->to_resume (t
, ptid
, step
, signal
);
2258 fprintf_unfiltered (gdb_stdlog
, "target_resume (%d, %s, %s)\n",
2260 step
? "step" : "continue",
2261 target_signal_to_name (signal
));
2263 registers_changed_ptid (ptid
);
2264 set_executing (ptid
, 1);
2265 set_running (ptid
, 1);
2266 clear_inline_frame_state (ptid
);
2273 /* Look through the list of possible targets for a target that can
2277 target_follow_fork (int follow_child
)
2279 struct target_ops
*t
;
2281 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
2283 if (t
->to_follow_fork
!= NULL
)
2285 int retval
= t
->to_follow_fork (t
, follow_child
);
2288 fprintf_unfiltered (gdb_stdlog
, "target_follow_fork (%d) = %d\n",
2289 follow_child
, retval
);
2294 /* Some target returned a fork event, but did not know how to follow it. */
2295 internal_error (__FILE__
, __LINE__
,
2296 "could not find a target to follow fork");
2300 target_mourn_inferior (void)
2302 struct target_ops
*t
;
2304 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
2306 if (t
->to_mourn_inferior
!= NULL
)
2308 t
->to_mourn_inferior (t
);
2310 fprintf_unfiltered (gdb_stdlog
, "target_mourn_inferior ()\n");
2312 /* We no longer need to keep handles on any of the object files.
2313 Make sure to release them to avoid unnecessarily locking any
2314 of them while we're not actually debugging. */
2315 bfd_cache_close_all ();
2321 internal_error (__FILE__
, __LINE__
,
2322 "could not find a target to follow mourn inferior");
2325 /* Look for a target which can describe architectural features, starting
2326 from TARGET. If we find one, return its description. */
2328 const struct target_desc
*
2329 target_read_description (struct target_ops
*target
)
2331 struct target_ops
*t
;
2333 for (t
= target
; t
!= NULL
; t
= t
->beneath
)
2334 if (t
->to_read_description
!= NULL
)
2336 const struct target_desc
*tdesc
;
2338 tdesc
= t
->to_read_description (t
);
2346 /* The default implementation of to_search_memory.
2347 This implements a basic search of memory, reading target memory and
2348 performing the search here (as opposed to performing the search in on the
2349 target side with, for example, gdbserver). */
2352 simple_search_memory (struct target_ops
*ops
,
2353 CORE_ADDR start_addr
, ULONGEST search_space_len
,
2354 const gdb_byte
*pattern
, ULONGEST pattern_len
,
2355 CORE_ADDR
*found_addrp
)
2357 /* NOTE: also defined in find.c testcase. */
2358 #define SEARCH_CHUNK_SIZE 16000
2359 const unsigned chunk_size
= SEARCH_CHUNK_SIZE
;
2360 /* Buffer to hold memory contents for searching. */
2361 gdb_byte
*search_buf
;
2362 unsigned search_buf_size
;
2363 struct cleanup
*old_cleanups
;
2365 search_buf_size
= chunk_size
+ pattern_len
- 1;
2367 /* No point in trying to allocate a buffer larger than the search space. */
2368 if (search_space_len
< search_buf_size
)
2369 search_buf_size
= search_space_len
;
2371 search_buf
= malloc (search_buf_size
);
2372 if (search_buf
== NULL
)
2373 error (_("Unable to allocate memory to perform the search."));
2374 old_cleanups
= make_cleanup (free_current_contents
, &search_buf
);
2376 /* Prime the search buffer. */
2378 if (target_read (ops
, TARGET_OBJECT_MEMORY
, NULL
,
2379 search_buf
, start_addr
, search_buf_size
) != search_buf_size
)
2381 warning (_("Unable to access target memory at %s, halting search."),
2382 hex_string (start_addr
));
2383 do_cleanups (old_cleanups
);
2387 /* Perform the search.
2389 The loop is kept simple by allocating [N + pattern-length - 1] bytes.
2390 When we've scanned N bytes we copy the trailing bytes to the start and
2391 read in another N bytes. */
2393 while (search_space_len
>= pattern_len
)
2395 gdb_byte
*found_ptr
;
2396 unsigned nr_search_bytes
= min (search_space_len
, search_buf_size
);
2398 found_ptr
= memmem (search_buf
, nr_search_bytes
,
2399 pattern
, pattern_len
);
2401 if (found_ptr
!= NULL
)
2403 CORE_ADDR found_addr
= start_addr
+ (found_ptr
- search_buf
);
2405 *found_addrp
= found_addr
;
2406 do_cleanups (old_cleanups
);
2410 /* Not found in this chunk, skip to next chunk. */
2412 /* Don't let search_space_len wrap here, it's unsigned. */
2413 if (search_space_len
>= chunk_size
)
2414 search_space_len
-= chunk_size
;
2416 search_space_len
= 0;
2418 if (search_space_len
>= pattern_len
)
2420 unsigned keep_len
= search_buf_size
- chunk_size
;
2421 CORE_ADDR read_addr
= start_addr
+ chunk_size
+ keep_len
;
2424 /* Copy the trailing part of the previous iteration to the front
2425 of the buffer for the next iteration. */
2426 gdb_assert (keep_len
== pattern_len
- 1);
2427 memcpy (search_buf
, search_buf
+ chunk_size
, keep_len
);
2429 nr_to_read
= min (search_space_len
- keep_len
, chunk_size
);
2431 if (target_read (ops
, TARGET_OBJECT_MEMORY
, NULL
,
2432 search_buf
+ keep_len
, read_addr
,
2433 nr_to_read
) != nr_to_read
)
2435 warning (_("Unable to access target memory at %s, halting search."),
2436 hex_string (read_addr
));
2437 do_cleanups (old_cleanups
);
2441 start_addr
+= chunk_size
;
2447 do_cleanups (old_cleanups
);
2451 /* Search SEARCH_SPACE_LEN bytes beginning at START_ADDR for the
2452 sequence of bytes in PATTERN with length PATTERN_LEN.
2454 The result is 1 if found, 0 if not found, and -1 if there was an error
2455 requiring halting of the search (e.g. memory read error).
2456 If the pattern is found the address is recorded in FOUND_ADDRP. */
2459 target_search_memory (CORE_ADDR start_addr
, ULONGEST search_space_len
,
2460 const gdb_byte
*pattern
, ULONGEST pattern_len
,
2461 CORE_ADDR
*found_addrp
)
2463 struct target_ops
*t
;
2466 /* We don't use INHERIT to set current_target.to_search_memory,
2467 so we have to scan the target stack and handle targetdebug
2471 fprintf_unfiltered (gdb_stdlog
, "target_search_memory (%s, ...)\n",
2472 hex_string (start_addr
));
2474 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
2475 if (t
->to_search_memory
!= NULL
)
2480 found
= t
->to_search_memory (t
, start_addr
, search_space_len
,
2481 pattern
, pattern_len
, found_addrp
);
2485 /* If a special version of to_search_memory isn't available, use the
2487 found
= simple_search_memory (current_target
.beneath
,
2488 start_addr
, search_space_len
,
2489 pattern
, pattern_len
, found_addrp
);
2493 fprintf_unfiltered (gdb_stdlog
, " = %d\n", found
);
2498 /* Look through the currently pushed targets. If none of them will
2499 be able to restart the currently running process, issue an error
2503 target_require_runnable (void)
2505 struct target_ops
*t
;
2507 for (t
= target_stack
; t
!= NULL
; t
= t
->beneath
)
2509 /* If this target knows how to create a new program, then
2510 assume we will still be able to after killing the current
2511 one. Either killing and mourning will not pop T, or else
2512 find_default_run_target will find it again. */
2513 if (t
->to_create_inferior
!= NULL
)
2516 /* Do not worry about thread_stratum targets that can not
2517 create inferiors. Assume they will be pushed again if
2518 necessary, and continue to the process_stratum. */
2519 if (t
->to_stratum
== thread_stratum
2520 || t
->to_stratum
== arch_stratum
)
2524 The \"%s\" target does not support \"run\". Try \"help target\" or \"continue\"."),
2528 /* This function is only called if the target is running. In that
2529 case there should have been a process_stratum target and it
2530 should either know how to create inferiors, or not... */
2531 internal_error (__FILE__
, __LINE__
, "No targets found");
2534 /* Look through the list of possible targets for a target that can
2535 execute a run or attach command without any other data. This is
2536 used to locate the default process stratum.
2538 If DO_MESG is not NULL, the result is always valid (error() is
2539 called for errors); else, return NULL on error. */
2541 static struct target_ops
*
2542 find_default_run_target (char *do_mesg
)
2544 struct target_ops
**t
;
2545 struct target_ops
*runable
= NULL
;
2550 for (t
= target_structs
; t
< target_structs
+ target_struct_size
;
2553 if ((*t
)->to_can_run
&& target_can_run (*t
))
2563 error (_("Don't know how to %s. Try \"help target\"."), do_mesg
);
2572 find_default_attach (struct target_ops
*ops
, char *args
, int from_tty
)
2574 struct target_ops
*t
;
2576 t
= find_default_run_target ("attach");
2577 (t
->to_attach
) (t
, args
, from_tty
);
2582 find_default_create_inferior (struct target_ops
*ops
,
2583 char *exec_file
, char *allargs
, char **env
,
2586 struct target_ops
*t
;
2588 t
= find_default_run_target ("run");
2589 (t
->to_create_inferior
) (t
, exec_file
, allargs
, env
, from_tty
);
2594 find_default_can_async_p (void)
2596 struct target_ops
*t
;
2598 /* This may be called before the target is pushed on the stack;
2599 look for the default process stratum. If there's none, gdb isn't
2600 configured with a native debugger, and target remote isn't
2602 t
= find_default_run_target (NULL
);
2603 if (t
&& t
->to_can_async_p
)
2604 return (t
->to_can_async_p
) ();
2609 find_default_is_async_p (void)
2611 struct target_ops
*t
;
2613 /* This may be called before the target is pushed on the stack;
2614 look for the default process stratum. If there's none, gdb isn't
2615 configured with a native debugger, and target remote isn't
2617 t
= find_default_run_target (NULL
);
2618 if (t
&& t
->to_is_async_p
)
2619 return (t
->to_is_async_p
) ();
2624 find_default_supports_non_stop (void)
2626 struct target_ops
*t
;
2628 t
= find_default_run_target (NULL
);
2629 if (t
&& t
->to_supports_non_stop
)
2630 return (t
->to_supports_non_stop
) ();
2635 target_supports_non_stop (void)
2637 struct target_ops
*t
;
2639 for (t
= ¤t_target
; t
!= NULL
; t
= t
->beneath
)
2640 if (t
->to_supports_non_stop
)
2641 return t
->to_supports_non_stop ();
2648 target_get_osdata (const char *type
)
2650 struct target_ops
*t
;
2652 /* If we're already connected to something that can get us OS
2653 related data, use it. Otherwise, try using the native
2655 if (current_target
.to_stratum
>= process_stratum
)
2656 t
= current_target
.beneath
;
2658 t
= find_default_run_target ("get OS data");
2663 return target_read_stralloc (t
, TARGET_OBJECT_OSDATA
, type
);
2666 /* Determine the current address space of thread PTID. */
2668 struct address_space
*
2669 target_thread_address_space (ptid_t ptid
)
2671 struct address_space
*aspace
;
2672 struct inferior
*inf
;
2673 struct target_ops
*t
;
2675 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
2677 if (t
->to_thread_address_space
!= NULL
)
2679 aspace
= t
->to_thread_address_space (t
, ptid
);
2680 gdb_assert (aspace
);
2683 fprintf_unfiltered (gdb_stdlog
,
2684 "target_thread_address_space (%s) = %d\n",
2685 target_pid_to_str (ptid
),
2686 address_space_num (aspace
));
2691 /* Fall-back to the "main" address space of the inferior. */
2692 inf
= find_inferior_pid (ptid_get_pid (ptid
));
2694 if (inf
== NULL
|| inf
->aspace
== NULL
)
2695 internal_error (__FILE__
, __LINE__
, "\
2696 Can't determine the current address space of thread %s\n",
2697 target_pid_to_str (ptid
));
2703 default_region_ok_for_hw_watchpoint (CORE_ADDR addr
, int len
)
2705 return (len
<= gdbarch_ptr_bit (target_gdbarch
) / TARGET_CHAR_BIT
);
2709 default_watchpoint_addr_within_range (struct target_ops
*target
,
2711 CORE_ADDR start
, int length
)
2713 return addr
>= start
&& addr
< start
+ length
;
2716 static struct gdbarch
*
2717 default_thread_architecture (struct target_ops
*ops
, ptid_t ptid
)
2719 return target_gdbarch
;
2735 return_minus_one (void)
2740 /* Find a single runnable target in the stack and return it. If for
2741 some reason there is more than one, return NULL. */
2744 find_run_target (void)
2746 struct target_ops
**t
;
2747 struct target_ops
*runable
= NULL
;
2752 for (t
= target_structs
; t
< target_structs
+ target_struct_size
; ++t
)
2754 if ((*t
)->to_can_run
&& target_can_run (*t
))
2761 return (count
== 1 ? runable
: NULL
);
2764 /* Find a single core_stratum target in the list of targets and return it.
2765 If for some reason there is more than one, return NULL. */
2768 find_core_target (void)
2770 struct target_ops
**t
;
2771 struct target_ops
*runable
= NULL
;
2776 for (t
= target_structs
; t
< target_structs
+ target_struct_size
;
2779 if ((*t
)->to_stratum
== core_stratum
)
2786 return (count
== 1 ? runable
: NULL
);
2790 * Find the next target down the stack from the specified target.
2794 find_target_beneath (struct target_ops
*t
)
2800 /* The inferior process has died. Long live the inferior! */
2803 generic_mourn_inferior (void)
2807 ptid
= inferior_ptid
;
2808 inferior_ptid
= null_ptid
;
2810 if (!ptid_equal (ptid
, null_ptid
))
2812 int pid
= ptid_get_pid (ptid
);
2813 exit_inferior (pid
);
2816 breakpoint_init_inferior (inf_exited
);
2817 registers_changed ();
2819 reopen_exec_file ();
2820 reinit_frame_cache ();
2822 if (deprecated_detach_hook
)
2823 deprecated_detach_hook ();
2826 /* Helper function for child_wait and the derivatives of child_wait.
2827 HOSTSTATUS is the waitstatus from wait() or the equivalent; store our
2828 translation of that in OURSTATUS. */
2830 store_waitstatus (struct target_waitstatus
*ourstatus
, int hoststatus
)
2832 if (WIFEXITED (hoststatus
))
2834 ourstatus
->kind
= TARGET_WAITKIND_EXITED
;
2835 ourstatus
->value
.integer
= WEXITSTATUS (hoststatus
);
2837 else if (!WIFSTOPPED (hoststatus
))
2839 ourstatus
->kind
= TARGET_WAITKIND_SIGNALLED
;
2840 ourstatus
->value
.sig
= target_signal_from_host (WTERMSIG (hoststatus
));
2844 ourstatus
->kind
= TARGET_WAITKIND_STOPPED
;
2845 ourstatus
->value
.sig
= target_signal_from_host (WSTOPSIG (hoststatus
));
2849 /* Convert a normal process ID to a string. Returns the string in a
2853 normal_pid_to_str (ptid_t ptid
)
2855 static char buf
[32];
2857 xsnprintf (buf
, sizeof buf
, "process %d", ptid_get_pid (ptid
));
2862 dummy_pid_to_str (struct target_ops
*ops
, ptid_t ptid
)
2864 return normal_pid_to_str (ptid
);
2867 /* Error-catcher for target_find_memory_regions. */
2869 dummy_find_memory_regions (int (*ignore1
) (), void *ignore2
)
2871 error (_("Command not implemented for this target."));
2875 /* Error-catcher for target_make_corefile_notes. */
2877 dummy_make_corefile_notes (bfd
*ignore1
, int *ignore2
)
2879 error (_("Command not implemented for this target."));
2883 /* Error-catcher for target_get_bookmark. */
2885 dummy_get_bookmark (char *ignore1
, int ignore2
)
2891 /* Error-catcher for target_goto_bookmark. */
2893 dummy_goto_bookmark (gdb_byte
*ignore
, int from_tty
)
2898 /* Set up the handful of non-empty slots needed by the dummy target
2902 init_dummy_target (void)
2904 dummy_target
.to_shortname
= "None";
2905 dummy_target
.to_longname
= "None";
2906 dummy_target
.to_doc
= "";
2907 dummy_target
.to_attach
= find_default_attach
;
2908 dummy_target
.to_detach
=
2909 (void (*)(struct target_ops
*, char *, int))target_ignore
;
2910 dummy_target
.to_create_inferior
= find_default_create_inferior
;
2911 dummy_target
.to_can_async_p
= find_default_can_async_p
;
2912 dummy_target
.to_is_async_p
= find_default_is_async_p
;
2913 dummy_target
.to_supports_non_stop
= find_default_supports_non_stop
;
2914 dummy_target
.to_pid_to_str
= dummy_pid_to_str
;
2915 dummy_target
.to_stratum
= dummy_stratum
;
2916 dummy_target
.to_find_memory_regions
= dummy_find_memory_regions
;
2917 dummy_target
.to_make_corefile_notes
= dummy_make_corefile_notes
;
2918 dummy_target
.to_get_bookmark
= dummy_get_bookmark
;
2919 dummy_target
.to_goto_bookmark
= dummy_goto_bookmark
;
2920 dummy_target
.to_xfer_partial
= default_xfer_partial
;
2921 dummy_target
.to_has_all_memory
= (int (*) (struct target_ops
*)) return_zero
;
2922 dummy_target
.to_has_memory
= (int (*) (struct target_ops
*)) return_zero
;
2923 dummy_target
.to_has_stack
= (int (*) (struct target_ops
*)) return_zero
;
2924 dummy_target
.to_has_registers
= (int (*) (struct target_ops
*)) return_zero
;
2925 dummy_target
.to_has_execution
= (int (*) (struct target_ops
*)) return_zero
;
2926 dummy_target
.to_stopped_by_watchpoint
= return_zero
;
2927 dummy_target
.to_stopped_data_address
=
2928 (int (*) (struct target_ops
*, CORE_ADDR
*)) return_zero
;
2929 dummy_target
.to_magic
= OPS_MAGIC
;
2933 debug_to_open (char *args
, int from_tty
)
2935 debug_target
.to_open (args
, from_tty
);
2937 fprintf_unfiltered (gdb_stdlog
, "target_open (%s, %d)\n", args
, from_tty
);
2941 target_close (struct target_ops
*targ
, int quitting
)
2943 if (targ
->to_xclose
!= NULL
)
2944 targ
->to_xclose (targ
, quitting
);
2945 else if (targ
->to_close
!= NULL
)
2946 targ
->to_close (quitting
);
2949 fprintf_unfiltered (gdb_stdlog
, "target_close (%d)\n", quitting
);
2953 target_attach (char *args
, int from_tty
)
2955 struct target_ops
*t
;
2957 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
2959 if (t
->to_attach
!= NULL
)
2961 t
->to_attach (t
, args
, from_tty
);
2963 fprintf_unfiltered (gdb_stdlog
, "target_attach (%s, %d)\n",
2969 internal_error (__FILE__
, __LINE__
,
2970 "could not find a target to attach");
2974 target_thread_alive (ptid_t ptid
)
2976 struct target_ops
*t
;
2978 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
2980 if (t
->to_thread_alive
!= NULL
)
2984 retval
= t
->to_thread_alive (t
, ptid
);
2986 fprintf_unfiltered (gdb_stdlog
, "target_thread_alive (%d) = %d\n",
2987 PIDGET (ptid
), retval
);
2997 target_find_new_threads (void)
2999 struct target_ops
*t
;
3001 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
3003 if (t
->to_find_new_threads
!= NULL
)
3005 t
->to_find_new_threads (t
);
3007 fprintf_unfiltered (gdb_stdlog
, "target_find_new_threads ()\n");
3015 target_stop (ptid_t ptid
)
3019 warning (_("May not interrupt or stop the target, ignoring attempt"));
3023 (*current_target
.to_stop
) (ptid
);
3027 debug_to_post_attach (int pid
)
3029 debug_target
.to_post_attach (pid
);
3031 fprintf_unfiltered (gdb_stdlog
, "target_post_attach (%d)\n", pid
);
3034 /* Return a pretty printed form of target_waitstatus.
3035 Space for the result is malloc'd, caller must free. */
3038 target_waitstatus_to_string (const struct target_waitstatus
*ws
)
3040 const char *kind_str
= "status->kind = ";
3044 case TARGET_WAITKIND_EXITED
:
3045 return xstrprintf ("%sexited, status = %d",
3046 kind_str
, ws
->value
.integer
);
3047 case TARGET_WAITKIND_STOPPED
:
3048 return xstrprintf ("%sstopped, signal = %s",
3049 kind_str
, target_signal_to_name (ws
->value
.sig
));
3050 case TARGET_WAITKIND_SIGNALLED
:
3051 return xstrprintf ("%ssignalled, signal = %s",
3052 kind_str
, target_signal_to_name (ws
->value
.sig
));
3053 case TARGET_WAITKIND_LOADED
:
3054 return xstrprintf ("%sloaded", kind_str
);
3055 case TARGET_WAITKIND_FORKED
:
3056 return xstrprintf ("%sforked", kind_str
);
3057 case TARGET_WAITKIND_VFORKED
:
3058 return xstrprintf ("%svforked", kind_str
);
3059 case TARGET_WAITKIND_EXECD
:
3060 return xstrprintf ("%sexecd", kind_str
);
3061 case TARGET_WAITKIND_SYSCALL_ENTRY
:
3062 return xstrprintf ("%sentered syscall", kind_str
);
3063 case TARGET_WAITKIND_SYSCALL_RETURN
:
3064 return xstrprintf ("%sexited syscall", kind_str
);
3065 case TARGET_WAITKIND_SPURIOUS
:
3066 return xstrprintf ("%sspurious", kind_str
);
3067 case TARGET_WAITKIND_IGNORE
:
3068 return xstrprintf ("%signore", kind_str
);
3069 case TARGET_WAITKIND_NO_HISTORY
:
3070 return xstrprintf ("%sno-history", kind_str
);
3072 return xstrprintf ("%sunknown???", kind_str
);
3077 debug_print_register (const char * func
,
3078 struct regcache
*regcache
, int regno
)
3080 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
3082 fprintf_unfiltered (gdb_stdlog
, "%s ", func
);
3083 if (regno
>= 0 && regno
< gdbarch_num_regs (gdbarch
)
3084 && gdbarch_register_name (gdbarch
, regno
) != NULL
3085 && gdbarch_register_name (gdbarch
, regno
)[0] != '\0')
3086 fprintf_unfiltered (gdb_stdlog
, "(%s)",
3087 gdbarch_register_name (gdbarch
, regno
));
3089 fprintf_unfiltered (gdb_stdlog
, "(%d)", regno
);
3090 if (regno
>= 0 && regno
< gdbarch_num_regs (gdbarch
))
3092 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
3093 int i
, size
= register_size (gdbarch
, regno
);
3094 unsigned char buf
[MAX_REGISTER_SIZE
];
3096 regcache_raw_collect (regcache
, regno
, buf
);
3097 fprintf_unfiltered (gdb_stdlog
, " = ");
3098 for (i
= 0; i
< size
; i
++)
3100 fprintf_unfiltered (gdb_stdlog
, "%02x", buf
[i
]);
3102 if (size
<= sizeof (LONGEST
))
3104 ULONGEST val
= extract_unsigned_integer (buf
, size
, byte_order
);
3106 fprintf_unfiltered (gdb_stdlog
, " %s %s",
3107 core_addr_to_string_nz (val
), plongest (val
));
3110 fprintf_unfiltered (gdb_stdlog
, "\n");
3114 target_fetch_registers (struct regcache
*regcache
, int regno
)
3116 struct target_ops
*t
;
3118 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
3120 if (t
->to_fetch_registers
!= NULL
)
3122 t
->to_fetch_registers (t
, regcache
, regno
);
3124 debug_print_register ("target_fetch_registers", regcache
, regno
);
3131 target_store_registers (struct regcache
*regcache
, int regno
)
3133 struct target_ops
*t
;
3135 if (!may_write_registers
)
3136 error (_("Writing to registers is not allowed (regno %d)"), regno
);
3138 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
3140 if (t
->to_store_registers
!= NULL
)
3142 t
->to_store_registers (t
, regcache
, regno
);
3145 debug_print_register ("target_store_registers", regcache
, regno
);
3155 target_core_of_thread (ptid_t ptid
)
3157 struct target_ops
*t
;
3159 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
3161 if (t
->to_core_of_thread
!= NULL
)
3163 int retval
= t
->to_core_of_thread (t
, ptid
);
3166 fprintf_unfiltered (gdb_stdlog
, "target_core_of_thread (%d) = %d\n",
3167 PIDGET (ptid
), retval
);
3176 target_verify_memory (const gdb_byte
*data
, CORE_ADDR memaddr
, ULONGEST size
)
3178 struct target_ops
*t
;
3180 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
3182 if (t
->to_verify_memory
!= NULL
)
3184 int retval
= t
->to_verify_memory (t
, data
, memaddr
, size
);
3187 fprintf_unfiltered (gdb_stdlog
, "target_verify_memory (%s, %s) = %d\n",
3188 paddress (target_gdbarch
, memaddr
),
3199 debug_to_prepare_to_store (struct regcache
*regcache
)
3201 debug_target
.to_prepare_to_store (regcache
);
3203 fprintf_unfiltered (gdb_stdlog
, "target_prepare_to_store ()\n");
3207 deprecated_debug_xfer_memory (CORE_ADDR memaddr
, bfd_byte
*myaddr
, int len
,
3208 int write
, struct mem_attrib
*attrib
,
3209 struct target_ops
*target
)
3213 retval
= debug_target
.deprecated_xfer_memory (memaddr
, myaddr
, len
, write
,
3216 fprintf_unfiltered (gdb_stdlog
,
3217 "target_xfer_memory (%s, xxx, %d, %s, xxx) = %d",
3218 paddress (target_gdbarch
, memaddr
), len
,
3219 write
? "write" : "read", retval
);
3225 fputs_unfiltered (", bytes =", gdb_stdlog
);
3226 for (i
= 0; i
< retval
; i
++)
3228 if ((((intptr_t) &(myaddr
[i
])) & 0xf) == 0)
3230 if (targetdebug
< 2 && i
> 0)
3232 fprintf_unfiltered (gdb_stdlog
, " ...");
3235 fprintf_unfiltered (gdb_stdlog
, "\n");
3238 fprintf_unfiltered (gdb_stdlog
, " %02x", myaddr
[i
] & 0xff);
3242 fputc_unfiltered ('\n', gdb_stdlog
);
3248 debug_to_files_info (struct target_ops
*target
)
3250 debug_target
.to_files_info (target
);
3252 fprintf_unfiltered (gdb_stdlog
, "target_files_info (xxx)\n");
3256 debug_to_insert_breakpoint (struct gdbarch
*gdbarch
,
3257 struct bp_target_info
*bp_tgt
)
3261 retval
= debug_target
.to_insert_breakpoint (gdbarch
, bp_tgt
);
3263 fprintf_unfiltered (gdb_stdlog
,
3264 "target_insert_breakpoint (0x%lx, xxx) = %ld\n",
3265 (unsigned long) bp_tgt
->placed_address
,
3266 (unsigned long) retval
);
3271 debug_to_remove_breakpoint (struct gdbarch
*gdbarch
,
3272 struct bp_target_info
*bp_tgt
)
3276 retval
= debug_target
.to_remove_breakpoint (gdbarch
, bp_tgt
);
3278 fprintf_unfiltered (gdb_stdlog
,
3279 "target_remove_breakpoint (0x%lx, xxx) = %ld\n",
3280 (unsigned long) bp_tgt
->placed_address
,
3281 (unsigned long) retval
);
3286 debug_to_can_use_hw_breakpoint (int type
, int cnt
, int from_tty
)
3290 retval
= debug_target
.to_can_use_hw_breakpoint (type
, cnt
, from_tty
);
3292 fprintf_unfiltered (gdb_stdlog
,
3293 "target_can_use_hw_breakpoint (%ld, %ld, %ld) = %ld\n",
3294 (unsigned long) type
,
3295 (unsigned long) cnt
,
3296 (unsigned long) from_tty
,
3297 (unsigned long) retval
);
3302 debug_to_region_ok_for_hw_watchpoint (CORE_ADDR addr
, int len
)
3306 retval
= debug_target
.to_region_ok_for_hw_watchpoint (addr
, len
);
3308 fprintf_unfiltered (gdb_stdlog
,
3309 "target_region_ok_for_hw_watchpoint (%ld, %ld) = 0x%lx\n",
3310 (unsigned long) addr
,
3311 (unsigned long) len
,
3312 (unsigned long) retval
);
3317 debug_to_stopped_by_watchpoint (void)
3321 retval
= debug_target
.to_stopped_by_watchpoint ();
3323 fprintf_unfiltered (gdb_stdlog
,
3324 "target_stopped_by_watchpoint () = %ld\n",
3325 (unsigned long) retval
);
3330 debug_to_stopped_data_address (struct target_ops
*target
, CORE_ADDR
*addr
)
3334 retval
= debug_target
.to_stopped_data_address (target
, addr
);
3336 fprintf_unfiltered (gdb_stdlog
,
3337 "target_stopped_data_address ([0x%lx]) = %ld\n",
3338 (unsigned long)*addr
,
3339 (unsigned long)retval
);
3344 debug_to_watchpoint_addr_within_range (struct target_ops
*target
,
3346 CORE_ADDR start
, int length
)
3350 retval
= debug_target
.to_watchpoint_addr_within_range (target
, addr
,
3353 fprintf_filtered (gdb_stdlog
,
3354 "target_watchpoint_addr_within_range (0x%lx, 0x%lx, %d) = %d\n",
3355 (unsigned long) addr
, (unsigned long) start
, length
,
3361 debug_to_insert_hw_breakpoint (struct gdbarch
*gdbarch
,
3362 struct bp_target_info
*bp_tgt
)
3366 retval
= debug_target
.to_insert_hw_breakpoint (gdbarch
, bp_tgt
);
3368 fprintf_unfiltered (gdb_stdlog
,
3369 "target_insert_hw_breakpoint (0x%lx, xxx) = %ld\n",
3370 (unsigned long) bp_tgt
->placed_address
,
3371 (unsigned long) retval
);
3376 debug_to_remove_hw_breakpoint (struct gdbarch
*gdbarch
,
3377 struct bp_target_info
*bp_tgt
)
3381 retval
= debug_target
.to_remove_hw_breakpoint (gdbarch
, bp_tgt
);
3383 fprintf_unfiltered (gdb_stdlog
,
3384 "target_remove_hw_breakpoint (0x%lx, xxx) = %ld\n",
3385 (unsigned long) bp_tgt
->placed_address
,
3386 (unsigned long) retval
);
3391 debug_to_insert_watchpoint (CORE_ADDR addr
, int len
, int type
)
3395 retval
= debug_target
.to_insert_watchpoint (addr
, len
, type
);
3397 fprintf_unfiltered (gdb_stdlog
,
3398 "target_insert_watchpoint (0x%lx, %d, %d) = %ld\n",
3399 (unsigned long) addr
, len
, type
, (unsigned long) retval
);
3404 debug_to_remove_watchpoint (CORE_ADDR addr
, int len
, int type
)
3408 retval
= debug_target
.to_remove_watchpoint (addr
, len
, type
);
3410 fprintf_unfiltered (gdb_stdlog
,
3411 "target_remove_watchpoint (0x%lx, %d, %d) = %ld\n",
3412 (unsigned long) addr
, len
, type
, (unsigned long) retval
);
3417 debug_to_terminal_init (void)
3419 debug_target
.to_terminal_init ();
3421 fprintf_unfiltered (gdb_stdlog
, "target_terminal_init ()\n");
3425 debug_to_terminal_inferior (void)
3427 debug_target
.to_terminal_inferior ();
3429 fprintf_unfiltered (gdb_stdlog
, "target_terminal_inferior ()\n");
3433 debug_to_terminal_ours_for_output (void)
3435 debug_target
.to_terminal_ours_for_output ();
3437 fprintf_unfiltered (gdb_stdlog
, "target_terminal_ours_for_output ()\n");
3441 debug_to_terminal_ours (void)
3443 debug_target
.to_terminal_ours ();
3445 fprintf_unfiltered (gdb_stdlog
, "target_terminal_ours ()\n");
3449 debug_to_terminal_save_ours (void)
3451 debug_target
.to_terminal_save_ours ();
3453 fprintf_unfiltered (gdb_stdlog
, "target_terminal_save_ours ()\n");
3457 debug_to_terminal_info (char *arg
, int from_tty
)
3459 debug_target
.to_terminal_info (arg
, from_tty
);
3461 fprintf_unfiltered (gdb_stdlog
, "target_terminal_info (%s, %d)\n", arg
,
3466 debug_to_load (char *args
, int from_tty
)
3468 debug_target
.to_load (args
, from_tty
);
3470 fprintf_unfiltered (gdb_stdlog
, "target_load (%s, %d)\n", args
, from_tty
);
3474 debug_to_lookup_symbol (char *name
, CORE_ADDR
*addrp
)
3478 retval
= debug_target
.to_lookup_symbol (name
, addrp
);
3480 fprintf_unfiltered (gdb_stdlog
, "target_lookup_symbol (%s, xxx)\n", name
);
3486 debug_to_post_startup_inferior (ptid_t ptid
)
3488 debug_target
.to_post_startup_inferior (ptid
);
3490 fprintf_unfiltered (gdb_stdlog
, "target_post_startup_inferior (%d)\n",
3495 debug_to_acknowledge_created_inferior (int pid
)
3497 debug_target
.to_acknowledge_created_inferior (pid
);
3499 fprintf_unfiltered (gdb_stdlog
, "target_acknowledge_created_inferior (%d)\n",
3504 debug_to_insert_fork_catchpoint (int pid
)
3506 debug_target
.to_insert_fork_catchpoint (pid
);
3508 fprintf_unfiltered (gdb_stdlog
, "target_insert_fork_catchpoint (%d)\n",
3513 debug_to_remove_fork_catchpoint (int pid
)
3517 retval
= debug_target
.to_remove_fork_catchpoint (pid
);
3519 fprintf_unfiltered (gdb_stdlog
, "target_remove_fork_catchpoint (%d) = %d\n",
3526 debug_to_insert_vfork_catchpoint (int pid
)
3528 debug_target
.to_insert_vfork_catchpoint (pid
);
3530 fprintf_unfiltered (gdb_stdlog
, "target_insert_vfork_catchpoint (%d)\n",
3535 debug_to_remove_vfork_catchpoint (int pid
)
3539 retval
= debug_target
.to_remove_vfork_catchpoint (pid
);
3541 fprintf_unfiltered (gdb_stdlog
, "target_remove_vfork_catchpoint (%d) = %d\n",
3548 debug_to_insert_exec_catchpoint (int pid
)
3550 debug_target
.to_insert_exec_catchpoint (pid
);
3552 fprintf_unfiltered (gdb_stdlog
, "target_insert_exec_catchpoint (%d)\n",
3557 debug_to_remove_exec_catchpoint (int pid
)
3561 retval
= debug_target
.to_remove_exec_catchpoint (pid
);
3563 fprintf_unfiltered (gdb_stdlog
, "target_remove_exec_catchpoint (%d) = %d\n",
3570 debug_to_has_exited (int pid
, int wait_status
, int *exit_status
)
3574 has_exited
= debug_target
.to_has_exited (pid
, wait_status
, exit_status
);
3576 fprintf_unfiltered (gdb_stdlog
, "target_has_exited (%d, %d, %d) = %d\n",
3577 pid
, wait_status
, *exit_status
, has_exited
);
3583 debug_to_can_run (void)
3587 retval
= debug_target
.to_can_run ();
3589 fprintf_unfiltered (gdb_stdlog
, "target_can_run () = %d\n", retval
);
3595 debug_to_notice_signals (ptid_t ptid
)
3597 debug_target
.to_notice_signals (ptid
);
3599 fprintf_unfiltered (gdb_stdlog
, "target_notice_signals (%d)\n",
3603 static struct gdbarch
*
3604 debug_to_thread_architecture (struct target_ops
*ops
, ptid_t ptid
)
3606 struct gdbarch
*retval
;
3608 retval
= debug_target
.to_thread_architecture (ops
, ptid
);
3610 fprintf_unfiltered (gdb_stdlog
, "target_thread_architecture (%s) = %s [%s]\n",
3611 target_pid_to_str (ptid
), host_address_to_string (retval
),
3612 gdbarch_bfd_arch_info (retval
)->printable_name
);
3617 debug_to_stop (ptid_t ptid
)
3619 debug_target
.to_stop (ptid
);
3621 fprintf_unfiltered (gdb_stdlog
, "target_stop (%s)\n",
3622 target_pid_to_str (ptid
));
3626 debug_to_rcmd (char *command
,
3627 struct ui_file
*outbuf
)
3629 debug_target
.to_rcmd (command
, outbuf
);
3630 fprintf_unfiltered (gdb_stdlog
, "target_rcmd (%s, ...)\n", command
);
3634 debug_to_pid_to_exec_file (int pid
)
3638 exec_file
= debug_target
.to_pid_to_exec_file (pid
);
3640 fprintf_unfiltered (gdb_stdlog
, "target_pid_to_exec_file (%d) = %s\n",
3647 setup_target_debug (void)
3649 memcpy (&debug_target
, ¤t_target
, sizeof debug_target
);
3651 current_target
.to_open
= debug_to_open
;
3652 current_target
.to_post_attach
= debug_to_post_attach
;
3653 current_target
.to_prepare_to_store
= debug_to_prepare_to_store
;
3654 current_target
.deprecated_xfer_memory
= deprecated_debug_xfer_memory
;
3655 current_target
.to_files_info
= debug_to_files_info
;
3656 current_target
.to_insert_breakpoint
= debug_to_insert_breakpoint
;
3657 current_target
.to_remove_breakpoint
= debug_to_remove_breakpoint
;
3658 current_target
.to_can_use_hw_breakpoint
= debug_to_can_use_hw_breakpoint
;
3659 current_target
.to_insert_hw_breakpoint
= debug_to_insert_hw_breakpoint
;
3660 current_target
.to_remove_hw_breakpoint
= debug_to_remove_hw_breakpoint
;
3661 current_target
.to_insert_watchpoint
= debug_to_insert_watchpoint
;
3662 current_target
.to_remove_watchpoint
= debug_to_remove_watchpoint
;
3663 current_target
.to_stopped_by_watchpoint
= debug_to_stopped_by_watchpoint
;
3664 current_target
.to_stopped_data_address
= debug_to_stopped_data_address
;
3665 current_target
.to_watchpoint_addr_within_range
= debug_to_watchpoint_addr_within_range
;
3666 current_target
.to_region_ok_for_hw_watchpoint
= debug_to_region_ok_for_hw_watchpoint
;
3667 current_target
.to_terminal_init
= debug_to_terminal_init
;
3668 current_target
.to_terminal_inferior
= debug_to_terminal_inferior
;
3669 current_target
.to_terminal_ours_for_output
= debug_to_terminal_ours_for_output
;
3670 current_target
.to_terminal_ours
= debug_to_terminal_ours
;
3671 current_target
.to_terminal_save_ours
= debug_to_terminal_save_ours
;
3672 current_target
.to_terminal_info
= debug_to_terminal_info
;
3673 current_target
.to_load
= debug_to_load
;
3674 current_target
.to_lookup_symbol
= debug_to_lookup_symbol
;
3675 current_target
.to_post_startup_inferior
= debug_to_post_startup_inferior
;
3676 current_target
.to_acknowledge_created_inferior
= debug_to_acknowledge_created_inferior
;
3677 current_target
.to_insert_fork_catchpoint
= debug_to_insert_fork_catchpoint
;
3678 current_target
.to_remove_fork_catchpoint
= debug_to_remove_fork_catchpoint
;
3679 current_target
.to_insert_vfork_catchpoint
= debug_to_insert_vfork_catchpoint
;
3680 current_target
.to_remove_vfork_catchpoint
= debug_to_remove_vfork_catchpoint
;
3681 current_target
.to_insert_exec_catchpoint
= debug_to_insert_exec_catchpoint
;
3682 current_target
.to_remove_exec_catchpoint
= debug_to_remove_exec_catchpoint
;
3683 current_target
.to_has_exited
= debug_to_has_exited
;
3684 current_target
.to_can_run
= debug_to_can_run
;
3685 current_target
.to_notice_signals
= debug_to_notice_signals
;
3686 current_target
.to_stop
= debug_to_stop
;
3687 current_target
.to_rcmd
= debug_to_rcmd
;
3688 current_target
.to_pid_to_exec_file
= debug_to_pid_to_exec_file
;
3689 current_target
.to_thread_architecture
= debug_to_thread_architecture
;
3693 static char targ_desc
[] =
3694 "Names of targets and files being debugged.\n\
3695 Shows the entire stack of targets currently in use (including the exec-file,\n\
3696 core-file, and process, if any), as well as the symbol file name.";
3699 do_monitor_command (char *cmd
,
3702 if ((current_target
.to_rcmd
3703 == (void (*) (char *, struct ui_file
*)) tcomplain
)
3704 || (current_target
.to_rcmd
== debug_to_rcmd
3705 && (debug_target
.to_rcmd
3706 == (void (*) (char *, struct ui_file
*)) tcomplain
)))
3707 error (_("\"monitor\" command not supported by this target."));
3708 target_rcmd (cmd
, gdb_stdtarg
);
3711 /* Print the name of each layers of our target stack. */
3714 maintenance_print_target_stack (char *cmd
, int from_tty
)
3716 struct target_ops
*t
;
3718 printf_filtered (_("The current target stack is:\n"));
3720 for (t
= target_stack
; t
!= NULL
; t
= t
->beneath
)
3722 printf_filtered (" - %s (%s)\n", t
->to_shortname
, t
->to_longname
);
3726 /* Controls if async mode is permitted. */
3727 int target_async_permitted
= 0;
3729 /* The set command writes to this variable. If the inferior is
3730 executing, linux_nat_async_permitted is *not* updated. */
3731 static int target_async_permitted_1
= 0;
3734 set_maintenance_target_async_permitted (char *args
, int from_tty
,
3735 struct cmd_list_element
*c
)
3737 if (have_live_inferiors ())
3739 target_async_permitted_1
= target_async_permitted
;
3740 error (_("Cannot change this setting while the inferior is running."));
3743 target_async_permitted
= target_async_permitted_1
;
3747 show_maintenance_target_async_permitted (struct ui_file
*file
, int from_tty
,
3748 struct cmd_list_element
*c
,
3751 fprintf_filtered (file
, _("\
3752 Controlling the inferior in asynchronous mode is %s.\n"), value
);
3755 /* Temporary copies of permission settings. */
3757 static int may_write_registers_1
= 1;
3758 static int may_write_memory_1
= 1;
3759 static int may_insert_breakpoints_1
= 1;
3760 static int may_insert_tracepoints_1
= 1;
3761 static int may_insert_fast_tracepoints_1
= 1;
3762 static int may_stop_1
= 1;
3764 /* Make the user-set values match the real values again. */
3767 update_target_permissions (void)
3769 may_write_registers_1
= may_write_registers
;
3770 may_write_memory_1
= may_write_memory
;
3771 may_insert_breakpoints_1
= may_insert_breakpoints
;
3772 may_insert_tracepoints_1
= may_insert_tracepoints
;
3773 may_insert_fast_tracepoints_1
= may_insert_fast_tracepoints
;
3774 may_stop_1
= may_stop
;
3777 /* The one function handles (most of) the permission flags in the same
3781 set_target_permissions (char *args
, int from_tty
,
3782 struct cmd_list_element
*c
)
3784 if (target_has_execution
)
3786 update_target_permissions ();
3787 error (_("Cannot change this setting while the inferior is running."));
3790 /* Make the real values match the user-changed values. */
3791 may_write_registers
= may_write_registers_1
;
3792 may_insert_breakpoints
= may_insert_breakpoints_1
;
3793 may_insert_tracepoints
= may_insert_tracepoints_1
;
3794 may_insert_fast_tracepoints
= may_insert_fast_tracepoints_1
;
3795 may_stop
= may_stop_1
;
3796 update_observer_mode ();
3799 /* Set memory write permission independently of observer mode. */
3802 set_write_memory_permission (char *args
, int from_tty
,
3803 struct cmd_list_element
*c
)
3805 /* Make the real values match the user-changed values. */
3806 may_write_memory
= may_write_memory_1
;
3807 update_observer_mode ();
3812 initialize_targets (void)
3814 init_dummy_target ();
3815 push_target (&dummy_target
);
3817 add_info ("target", target_info
, targ_desc
);
3818 add_info ("files", target_info
, targ_desc
);
3820 add_setshow_zinteger_cmd ("target", class_maintenance
, &targetdebug
, _("\
3821 Set target debugging."), _("\
3822 Show target debugging."), _("\
3823 When non-zero, target debugging is enabled. Higher numbers are more\n\
3824 verbose. Changes do not take effect until the next \"run\" or \"target\"\n\
3828 &setdebuglist
, &showdebuglist
);
3830 add_setshow_boolean_cmd ("trust-readonly-sections", class_support
,
3831 &trust_readonly
, _("\
3832 Set mode for reading from readonly sections."), _("\
3833 Show mode for reading from readonly sections."), _("\
3834 When this mode is on, memory reads from readonly sections (such as .text)\n\
3835 will be read from the object file instead of from the target. This will\n\
3836 result in significant performance improvement for remote targets."),
3838 show_trust_readonly
,
3839 &setlist
, &showlist
);
3841 add_com ("monitor", class_obscure
, do_monitor_command
,
3842 _("Send a command to the remote monitor (remote targets only)."));
3844 add_cmd ("target-stack", class_maintenance
, maintenance_print_target_stack
,
3845 _("Print the name of each layer of the internal target stack."),
3846 &maintenanceprintlist
);
3848 add_setshow_boolean_cmd ("target-async", no_class
,
3849 &target_async_permitted_1
, _("\
3850 Set whether gdb controls the inferior in asynchronous mode."), _("\
3851 Show whether gdb controls the inferior in asynchronous mode."), _("\
3852 Tells gdb whether to control the inferior in asynchronous mode."),
3853 set_maintenance_target_async_permitted
,
3854 show_maintenance_target_async_permitted
,
3858 add_setshow_boolean_cmd ("stack-cache", class_support
,
3859 &stack_cache_enabled_p_1
, _("\
3860 Set cache use for stack access."), _("\
3861 Show cache use for stack access."), _("\
3862 When on, use the data cache for all stack access, regardless of any\n\
3863 configured memory regions. This improves remote performance significantly.\n\
3864 By default, caching for stack access is on."),
3865 set_stack_cache_enabled_p
,
3866 show_stack_cache_enabled_p
,
3867 &setlist
, &showlist
);
3869 add_setshow_boolean_cmd ("may-write-registers", class_support
,
3870 &may_write_registers_1
, _("\
3871 Set permission to write into registers."), _("\
3872 Show permission to write into registers."), _("\
3873 When this permission is on, GDB may write into the target's registers.\n\
3874 Otherwise, any sort of write attempt will result in an error."),
3875 set_target_permissions
, NULL
,
3876 &setlist
, &showlist
);
3878 add_setshow_boolean_cmd ("may-write-memory", class_support
,
3879 &may_write_memory_1
, _("\
3880 Set permission to write into target memory."), _("\
3881 Show permission to write into target memory."), _("\
3882 When this permission is on, GDB may write into the target's memory.\n\
3883 Otherwise, any sort of write attempt will result in an error."),
3884 set_write_memory_permission
, NULL
,
3885 &setlist
, &showlist
);
3887 add_setshow_boolean_cmd ("may-insert-breakpoints", class_support
,
3888 &may_insert_breakpoints_1
, _("\
3889 Set permission to insert breakpoints in the target."), _("\
3890 Show permission to insert breakpoints in the target."), _("\
3891 When this permission is on, GDB may insert breakpoints in the program.\n\
3892 Otherwise, any sort of insertion attempt will result in an error."),
3893 set_target_permissions
, NULL
,
3894 &setlist
, &showlist
);
3896 add_setshow_boolean_cmd ("may-insert-tracepoints", class_support
,
3897 &may_insert_tracepoints_1
, _("\
3898 Set permission to insert tracepoints in the target."), _("\
3899 Show permission to insert tracepoints in the target."), _("\
3900 When this permission is on, GDB may insert tracepoints in the program.\n\
3901 Otherwise, any sort of insertion attempt will result in an error."),
3902 set_target_permissions
, NULL
,
3903 &setlist
, &showlist
);
3905 add_setshow_boolean_cmd ("may-insert-fast-tracepoints", class_support
,
3906 &may_insert_fast_tracepoints_1
, _("\
3907 Set permission to insert fast tracepoints in the target."), _("\
3908 Show permission to insert fast tracepoints in the target."), _("\
3909 When this permission is on, GDB may insert fast tracepoints.\n\
3910 Otherwise, any sort of insertion attempt will result in an error."),
3911 set_target_permissions
, NULL
,
3912 &setlist
, &showlist
);
3914 add_setshow_boolean_cmd ("may-interrupt", class_support
,
3916 Set permission to interrupt or signal the target."), _("\
3917 Show permission to interrupt or signal the target."), _("\
3918 When this permission is on, GDB may interrupt/stop the target's execution.\n\
3919 Otherwise, any attempt to interrupt or stop will be ignored."),
3920 set_target_permissions
, NULL
,
3921 &setlist
, &showlist
);
3924 target_dcache
= dcache_init ();