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"
47 static void target_info (char *, int);
49 static void default_terminal_info (char *, int);
51 static int default_watchpoint_addr_within_range (struct target_ops
*,
52 CORE_ADDR
, CORE_ADDR
, int);
54 static int default_region_ok_for_hw_watchpoint (CORE_ADDR
, int);
56 static int nosymbol (char *, CORE_ADDR
*);
58 static void tcomplain (void) ATTR_NORETURN
;
60 static int nomemory (CORE_ADDR
, char *, int, int, struct target_ops
*);
62 static int return_zero (void);
64 static int return_one (void);
66 static int return_minus_one (void);
68 void target_ignore (void);
70 static void target_command (char *, int);
72 static struct target_ops
*find_default_run_target (char *);
74 static LONGEST
default_xfer_partial (struct target_ops
*ops
,
75 enum target_object object
,
76 const char *annex
, gdb_byte
*readbuf
,
77 const gdb_byte
*writebuf
,
78 ULONGEST offset
, LONGEST len
);
80 static LONGEST
current_xfer_partial (struct target_ops
*ops
,
81 enum target_object object
,
82 const char *annex
, gdb_byte
*readbuf
,
83 const gdb_byte
*writebuf
,
84 ULONGEST offset
, LONGEST len
);
86 static LONGEST
target_xfer_partial (struct target_ops
*ops
,
87 enum target_object object
,
89 void *readbuf
, const void *writebuf
,
90 ULONGEST offset
, LONGEST len
);
92 static struct gdbarch
*default_thread_architecture (struct target_ops
*ops
,
95 static void init_dummy_target (void);
97 static struct target_ops debug_target
;
99 static void debug_to_open (char *, int);
101 static void debug_to_prepare_to_store (struct regcache
*);
103 static void debug_to_files_info (struct target_ops
*);
105 static int debug_to_insert_breakpoint (struct gdbarch
*,
106 struct bp_target_info
*);
108 static int debug_to_remove_breakpoint (struct gdbarch
*,
109 struct bp_target_info
*);
111 static int debug_to_can_use_hw_breakpoint (int, int, int);
113 static int debug_to_insert_hw_breakpoint (struct gdbarch
*,
114 struct bp_target_info
*);
116 static int debug_to_remove_hw_breakpoint (struct gdbarch
*,
117 struct bp_target_info
*);
119 static int debug_to_insert_watchpoint (CORE_ADDR
, int, int);
121 static int debug_to_remove_watchpoint (CORE_ADDR
, int, int);
123 static int debug_to_stopped_by_watchpoint (void);
125 static int debug_to_stopped_data_address (struct target_ops
*, CORE_ADDR
*);
127 static int debug_to_watchpoint_addr_within_range (struct target_ops
*,
128 CORE_ADDR
, CORE_ADDR
, int);
130 static int debug_to_region_ok_for_hw_watchpoint (CORE_ADDR
, int);
132 static void debug_to_terminal_init (void);
134 static void debug_to_terminal_inferior (void);
136 static void debug_to_terminal_ours_for_output (void);
138 static void debug_to_terminal_save_ours (void);
140 static void debug_to_terminal_ours (void);
142 static void debug_to_terminal_info (char *, int);
144 static void debug_to_load (char *, int);
146 static int debug_to_lookup_symbol (char *, CORE_ADDR
*);
148 static int debug_to_can_run (void);
150 static void debug_to_notice_signals (ptid_t
);
152 static void debug_to_stop (ptid_t
);
154 /* NOTE: cagney/2004-09-29: Many targets reference this variable in
155 wierd and mysterious ways. Putting the variable here lets those
156 wierd and mysterious ways keep building while they are being
157 converted to the inferior inheritance structure. */
158 struct target_ops deprecated_child_ops
;
160 /* Pointer to array of target architecture structures; the size of the
161 array; the current index into the array; the allocated size of the
163 struct target_ops
**target_structs
;
164 unsigned target_struct_size
;
165 unsigned target_struct_index
;
166 unsigned target_struct_allocsize
;
167 #define DEFAULT_ALLOCSIZE 10
169 /* The initial current target, so that there is always a semi-valid
172 static struct target_ops dummy_target
;
174 /* Top of target stack. */
176 static struct target_ops
*target_stack
;
178 /* The target structure we are currently using to talk to a process
179 or file or whatever "inferior" we have. */
181 struct target_ops current_target
;
183 /* Command list for target. */
185 static struct cmd_list_element
*targetlist
= NULL
;
187 /* Nonzero if we should trust readonly sections from the
188 executable when reading memory. */
190 static int trust_readonly
= 0;
192 /* Nonzero if we should show true memory content including
193 memory breakpoint inserted by gdb. */
195 static int show_memory_breakpoints
= 0;
197 /* Non-zero if we want to see trace of target level stuff. */
199 static int targetdebug
= 0;
201 show_targetdebug (struct ui_file
*file
, int from_tty
,
202 struct cmd_list_element
*c
, const char *value
)
204 fprintf_filtered (file
, _("Target debugging is %s.\n"), value
);
207 static void setup_target_debug (void);
209 /* The option sets this. */
210 static int stack_cache_enabled_p_1
= 1;
211 /* And set_stack_cache_enabled_p updates this.
212 The reason for the separation is so that we don't flush the cache for
213 on->on transitions. */
214 static int stack_cache_enabled_p
= 1;
216 /* This is called *after* the stack-cache has been set.
217 Flush the cache for off->on and on->off transitions.
218 There's no real need to flush the cache for on->off transitions,
219 except cleanliness. */
222 set_stack_cache_enabled_p (char *args
, int from_tty
,
223 struct cmd_list_element
*c
)
225 if (stack_cache_enabled_p
!= stack_cache_enabled_p_1
)
226 target_dcache_invalidate ();
228 stack_cache_enabled_p
= stack_cache_enabled_p_1
;
232 show_stack_cache_enabled_p (struct ui_file
*file
, int from_tty
,
233 struct cmd_list_element
*c
, const char *value
)
235 fprintf_filtered (file
, _("Cache use for stack accesses is %s.\n"), value
);
238 /* Cache of memory operations, to speed up remote access. */
239 static DCACHE
*target_dcache
;
241 /* Invalidate the target dcache. */
244 target_dcache_invalidate (void)
246 dcache_invalidate (target_dcache
);
249 /* The user just typed 'target' without the name of a target. */
252 target_command (char *arg
, int from_tty
)
254 fputs_filtered ("Argument required (target name). Try `help target'\n",
258 /* Default target_has_* methods for process_stratum targets. */
261 default_child_has_all_memory (struct target_ops
*ops
)
263 /* If no inferior selected, then we can't read memory here. */
264 if (ptid_equal (inferior_ptid
, null_ptid
))
271 default_child_has_memory (struct target_ops
*ops
)
273 /* If no inferior selected, then we can't read memory here. */
274 if (ptid_equal (inferior_ptid
, null_ptid
))
281 default_child_has_stack (struct target_ops
*ops
)
283 /* If no inferior selected, there's no stack. */
284 if (ptid_equal (inferior_ptid
, null_ptid
))
291 default_child_has_registers (struct target_ops
*ops
)
293 /* Can't read registers from no inferior. */
294 if (ptid_equal (inferior_ptid
, null_ptid
))
301 default_child_has_execution (struct target_ops
*ops
)
303 /* If there's no thread selected, then we can't make it run through
305 if (ptid_equal (inferior_ptid
, null_ptid
))
313 target_has_all_memory_1 (void)
315 struct target_ops
*t
;
317 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
318 if (t
->to_has_all_memory (t
))
325 target_has_memory_1 (void)
327 struct target_ops
*t
;
329 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
330 if (t
->to_has_memory (t
))
337 target_has_stack_1 (void)
339 struct target_ops
*t
;
341 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
342 if (t
->to_has_stack (t
))
349 target_has_registers_1 (void)
351 struct target_ops
*t
;
353 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
354 if (t
->to_has_registers (t
))
361 target_has_execution_1 (void)
363 struct target_ops
*t
;
365 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
366 if (t
->to_has_execution (t
))
372 /* Add a possible target architecture to the list. */
375 add_target (struct target_ops
*t
)
377 /* Provide default values for all "must have" methods. */
378 if (t
->to_xfer_partial
== NULL
)
379 t
->to_xfer_partial
= default_xfer_partial
;
381 if (t
->to_has_all_memory
== NULL
)
382 t
->to_has_all_memory
= (int (*) (struct target_ops
*)) return_zero
;
384 if (t
->to_has_memory
== NULL
)
385 t
->to_has_memory
= (int (*) (struct target_ops
*)) return_zero
;
387 if (t
->to_has_stack
== NULL
)
388 t
->to_has_stack
= (int (*) (struct target_ops
*)) return_zero
;
390 if (t
->to_has_registers
== NULL
)
391 t
->to_has_registers
= (int (*) (struct target_ops
*)) return_zero
;
393 if (t
->to_has_execution
== NULL
)
394 t
->to_has_execution
= (int (*) (struct target_ops
*)) return_zero
;
398 target_struct_allocsize
= DEFAULT_ALLOCSIZE
;
399 target_structs
= (struct target_ops
**) xmalloc
400 (target_struct_allocsize
* sizeof (*target_structs
));
402 if (target_struct_size
>= target_struct_allocsize
)
404 target_struct_allocsize
*= 2;
405 target_structs
= (struct target_ops
**)
406 xrealloc ((char *) target_structs
,
407 target_struct_allocsize
* sizeof (*target_structs
));
409 target_structs
[target_struct_size
++] = t
;
411 if (targetlist
== NULL
)
412 add_prefix_cmd ("target", class_run
, target_command
, _("\
413 Connect to a target machine or process.\n\
414 The first argument is the type or protocol of the target machine.\n\
415 Remaining arguments are interpreted by the target protocol. For more\n\
416 information on the arguments for a particular protocol, type\n\
417 `help target ' followed by the protocol name."),
418 &targetlist
, "target ", 0, &cmdlist
);
419 add_cmd (t
->to_shortname
, no_class
, t
->to_open
, t
->to_doc
, &targetlist
);
432 struct target_ops
*t
;
434 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
435 if (t
->to_kill
!= NULL
)
438 fprintf_unfiltered (gdb_stdlog
, "target_kill ()\n");
448 target_load (char *arg
, int from_tty
)
450 target_dcache_invalidate ();
451 (*current_target
.to_load
) (arg
, from_tty
);
455 target_create_inferior (char *exec_file
, char *args
,
456 char **env
, int from_tty
)
458 struct target_ops
*t
;
459 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
461 if (t
->to_create_inferior
!= NULL
)
463 t
->to_create_inferior (t
, exec_file
, args
, env
, from_tty
);
465 fprintf_unfiltered (gdb_stdlog
,
466 "target_create_inferior (%s, %s, xxx, %d)\n",
467 exec_file
, args
, from_tty
);
472 internal_error (__FILE__
, __LINE__
,
473 "could not find a target to create inferior");
477 target_terminal_inferior (void)
479 /* A background resume (``run&'') should leave GDB in control of the
480 terminal. Use target_can_async_p, not target_is_async_p, since at
481 this point the target is not async yet. However, if sync_execution
482 is not set, we know it will become async prior to resume. */
483 if (target_can_async_p () && !sync_execution
)
486 /* If GDB is resuming the inferior in the foreground, install
487 inferior's terminal modes. */
488 (*current_target
.to_terminal_inferior
) ();
492 nomemory (CORE_ADDR memaddr
, char *myaddr
, int len
, int write
,
493 struct target_ops
*t
)
495 errno
= EIO
; /* Can't read/write this location */
496 return 0; /* No bytes handled */
502 error (_("You can't do that when your target is `%s'"),
503 current_target
.to_shortname
);
509 error (_("You can't do that without a process to debug."));
513 nosymbol (char *name
, CORE_ADDR
*addrp
)
515 return 1; /* Symbol does not exist in target env */
519 default_terminal_info (char *args
, int from_tty
)
521 printf_unfiltered (_("No saved terminal information.\n"));
524 /* A default implementation for the to_get_ada_task_ptid target method.
526 This function builds the PTID by using both LWP and TID as part of
527 the PTID lwp and tid elements. The pid used is the pid of the
531 default_get_ada_task_ptid (long lwp
, long tid
)
533 return ptid_build (ptid_get_pid (inferior_ptid
), lwp
, tid
);
536 /* Go through the target stack from top to bottom, copying over zero
537 entries in current_target, then filling in still empty entries. In
538 effect, we are doing class inheritance through the pushed target
541 NOTE: cagney/2003-10-17: The problem with this inheritance, as it
542 is currently implemented, is that it discards any knowledge of
543 which target an inherited method originally belonged to.
544 Consequently, new new target methods should instead explicitly and
545 locally search the target stack for the target that can handle the
549 update_current_target (void)
551 struct target_ops
*t
;
553 /* First, reset current's contents. */
554 memset (¤t_target
, 0, sizeof (current_target
));
556 #define INHERIT(FIELD, TARGET) \
557 if (!current_target.FIELD) \
558 current_target.FIELD = (TARGET)->FIELD
560 for (t
= target_stack
; t
; t
= t
->beneath
)
562 INHERIT (to_shortname
, t
);
563 INHERIT (to_longname
, t
);
565 /* Do not inherit to_open. */
566 /* Do not inherit to_close. */
567 /* Do not inherit to_attach. */
568 INHERIT (to_post_attach
, t
);
569 INHERIT (to_attach_no_wait
, t
);
570 /* Do not inherit to_detach. */
571 /* Do not inherit to_disconnect. */
572 /* Do not inherit to_resume. */
573 /* Do not inherit to_wait. */
574 /* Do not inherit to_fetch_registers. */
575 /* Do not inherit to_store_registers. */
576 INHERIT (to_prepare_to_store
, t
);
577 INHERIT (deprecated_xfer_memory
, t
);
578 INHERIT (to_files_info
, t
);
579 INHERIT (to_insert_breakpoint
, t
);
580 INHERIT (to_remove_breakpoint
, t
);
581 INHERIT (to_can_use_hw_breakpoint
, t
);
582 INHERIT (to_insert_hw_breakpoint
, t
);
583 INHERIT (to_remove_hw_breakpoint
, t
);
584 INHERIT (to_insert_watchpoint
, t
);
585 INHERIT (to_remove_watchpoint
, t
);
586 INHERIT (to_stopped_data_address
, t
);
587 INHERIT (to_have_steppable_watchpoint
, t
);
588 INHERIT (to_have_continuable_watchpoint
, t
);
589 INHERIT (to_stopped_by_watchpoint
, t
);
590 INHERIT (to_watchpoint_addr_within_range
, t
);
591 INHERIT (to_region_ok_for_hw_watchpoint
, t
);
592 INHERIT (to_terminal_init
, t
);
593 INHERIT (to_terminal_inferior
, t
);
594 INHERIT (to_terminal_ours_for_output
, t
);
595 INHERIT (to_terminal_ours
, t
);
596 INHERIT (to_terminal_save_ours
, t
);
597 INHERIT (to_terminal_info
, t
);
598 /* Do not inherit to_kill. */
599 INHERIT (to_load
, t
);
600 INHERIT (to_lookup_symbol
, t
);
601 /* Do no inherit to_create_inferior. */
602 INHERIT (to_post_startup_inferior
, t
);
603 INHERIT (to_acknowledge_created_inferior
, t
);
604 INHERIT (to_insert_fork_catchpoint
, t
);
605 INHERIT (to_remove_fork_catchpoint
, t
);
606 INHERIT (to_insert_vfork_catchpoint
, t
);
607 INHERIT (to_remove_vfork_catchpoint
, t
);
608 /* Do not inherit to_follow_fork. */
609 INHERIT (to_insert_exec_catchpoint
, t
);
610 INHERIT (to_remove_exec_catchpoint
, t
);
611 INHERIT (to_set_syscall_catchpoint
, t
);
612 INHERIT (to_has_exited
, t
);
613 /* Do not inherit to_mourn_inferiour. */
614 INHERIT (to_can_run
, t
);
615 INHERIT (to_notice_signals
, t
);
616 /* Do not inherit to_thread_alive. */
617 /* Do not inherit to_find_new_threads. */
618 /* Do not inherit to_pid_to_str. */
619 INHERIT (to_extra_thread_info
, t
);
620 INHERIT (to_stop
, t
);
621 /* Do not inherit to_xfer_partial. */
622 INHERIT (to_rcmd
, t
);
623 INHERIT (to_pid_to_exec_file
, t
);
624 INHERIT (to_log_command
, t
);
625 INHERIT (to_stratum
, t
);
626 /* Do not inherit to_has_all_memory */
627 /* Do not inherit to_has_memory */
628 /* Do not inherit to_has_stack */
629 /* Do not inherit to_has_registers */
630 /* Do not inherit to_has_execution */
631 INHERIT (to_has_thread_control
, t
);
632 INHERIT (to_can_async_p
, t
);
633 INHERIT (to_is_async_p
, t
);
634 INHERIT (to_async
, t
);
635 INHERIT (to_async_mask
, t
);
636 INHERIT (to_find_memory_regions
, t
);
637 INHERIT (to_make_corefile_notes
, t
);
638 INHERIT (to_get_bookmark
, t
);
639 INHERIT (to_goto_bookmark
, t
);
640 /* Do not inherit to_get_thread_local_address. */
641 INHERIT (to_can_execute_reverse
, t
);
642 INHERIT (to_thread_architecture
, t
);
643 /* Do not inherit to_read_description. */
644 INHERIT (to_get_ada_task_ptid
, t
);
645 /* Do not inherit to_search_memory. */
646 INHERIT (to_supports_multi_process
, t
);
647 INHERIT (to_trace_init
, t
);
648 INHERIT (to_download_tracepoint
, t
);
649 INHERIT (to_download_trace_state_variable
, t
);
650 INHERIT (to_trace_set_readonly_regions
, t
);
651 INHERIT (to_trace_start
, t
);
652 INHERIT (to_get_trace_status
, t
);
653 INHERIT (to_trace_stop
, t
);
654 INHERIT (to_trace_find
, t
);
655 INHERIT (to_get_trace_state_variable_value
, t
);
656 INHERIT (to_save_trace_data
, t
);
657 INHERIT (to_upload_tracepoints
, t
);
658 INHERIT (to_upload_trace_state_variables
, t
);
659 INHERIT (to_get_raw_trace_data
, t
);
660 INHERIT (to_set_disconnected_tracing
, t
);
661 INHERIT (to_magic
, t
);
662 /* Do not inherit to_memory_map. */
663 /* Do not inherit to_flash_erase. */
664 /* Do not inherit to_flash_done. */
668 /* Clean up a target struct so it no longer has any zero pointers in
669 it. Some entries are defaulted to a method that print an error,
670 others are hard-wired to a standard recursive default. */
672 #define de_fault(field, value) \
673 if (!current_target.field) \
674 current_target.field = value
677 (void (*) (char *, int))
682 de_fault (to_post_attach
,
685 de_fault (to_prepare_to_store
,
686 (void (*) (struct regcache
*))
688 de_fault (deprecated_xfer_memory
,
689 (int (*) (CORE_ADDR
, gdb_byte
*, int, int, struct mem_attrib
*, struct target_ops
*))
691 de_fault (to_files_info
,
692 (void (*) (struct target_ops
*))
694 de_fault (to_insert_breakpoint
,
695 memory_insert_breakpoint
);
696 de_fault (to_remove_breakpoint
,
697 memory_remove_breakpoint
);
698 de_fault (to_can_use_hw_breakpoint
,
699 (int (*) (int, int, int))
701 de_fault (to_insert_hw_breakpoint
,
702 (int (*) (struct gdbarch
*, struct bp_target_info
*))
704 de_fault (to_remove_hw_breakpoint
,
705 (int (*) (struct gdbarch
*, struct bp_target_info
*))
707 de_fault (to_insert_watchpoint
,
708 (int (*) (CORE_ADDR
, int, int))
710 de_fault (to_remove_watchpoint
,
711 (int (*) (CORE_ADDR
, int, int))
713 de_fault (to_stopped_by_watchpoint
,
716 de_fault (to_stopped_data_address
,
717 (int (*) (struct target_ops
*, CORE_ADDR
*))
719 de_fault (to_watchpoint_addr_within_range
,
720 default_watchpoint_addr_within_range
);
721 de_fault (to_region_ok_for_hw_watchpoint
,
722 default_region_ok_for_hw_watchpoint
);
723 de_fault (to_terminal_init
,
726 de_fault (to_terminal_inferior
,
729 de_fault (to_terminal_ours_for_output
,
732 de_fault (to_terminal_ours
,
735 de_fault (to_terminal_save_ours
,
738 de_fault (to_terminal_info
,
739 default_terminal_info
);
741 (void (*) (char *, int))
743 de_fault (to_lookup_symbol
,
744 (int (*) (char *, CORE_ADDR
*))
746 de_fault (to_post_startup_inferior
,
749 de_fault (to_acknowledge_created_inferior
,
752 de_fault (to_insert_fork_catchpoint
,
755 de_fault (to_remove_fork_catchpoint
,
758 de_fault (to_insert_vfork_catchpoint
,
761 de_fault (to_remove_vfork_catchpoint
,
764 de_fault (to_insert_exec_catchpoint
,
767 de_fault (to_remove_exec_catchpoint
,
770 de_fault (to_set_syscall_catchpoint
,
771 (int (*) (int, int, int, int, int *))
773 de_fault (to_has_exited
,
774 (int (*) (int, int, int *))
776 de_fault (to_can_run
,
778 de_fault (to_notice_signals
,
781 de_fault (to_extra_thread_info
,
782 (char *(*) (struct thread_info
*))
787 current_target
.to_xfer_partial
= current_xfer_partial
;
789 (void (*) (char *, struct ui_file
*))
791 de_fault (to_pid_to_exec_file
,
795 (void (*) (void (*) (enum inferior_event_type
, void*), void*))
797 de_fault (to_async_mask
,
800 de_fault (to_thread_architecture
,
801 default_thread_architecture
);
802 current_target
.to_read_description
= NULL
;
803 de_fault (to_get_ada_task_ptid
,
804 (ptid_t (*) (long, long))
805 default_get_ada_task_ptid
);
806 de_fault (to_supports_multi_process
,
809 de_fault (to_trace_init
,
812 de_fault (to_download_tracepoint
,
813 (void (*) (struct breakpoint
*))
815 de_fault (to_download_trace_state_variable
,
816 (void (*) (struct trace_state_variable
*))
818 de_fault (to_trace_set_readonly_regions
,
821 de_fault (to_trace_start
,
824 de_fault (to_get_trace_status
,
825 (int (*) (struct trace_status
*))
827 de_fault (to_trace_stop
,
830 de_fault (to_trace_find
,
831 (int (*) (enum trace_find_type
, int, ULONGEST
, ULONGEST
, int *))
833 de_fault (to_get_trace_state_variable_value
,
834 (int (*) (int, LONGEST
*))
836 de_fault (to_save_trace_data
,
839 de_fault (to_upload_tracepoints
,
840 (int (*) (struct uploaded_tp
**))
842 de_fault (to_upload_trace_state_variables
,
843 (int (*) (struct uploaded_tsv
**))
845 de_fault (to_get_raw_trace_data
,
846 (LONGEST (*) (gdb_byte
*, ULONGEST
, LONGEST
))
848 de_fault (to_set_disconnected_tracing
,
853 /* Finally, position the target-stack beneath the squashed
854 "current_target". That way code looking for a non-inherited
855 target method can quickly and simply find it. */
856 current_target
.beneath
= target_stack
;
859 setup_target_debug ();
862 /* Push a new target type into the stack of the existing target accessors,
863 possibly superseding some of the existing accessors.
865 Result is zero if the pushed target ended up on top of the stack,
866 nonzero if at least one target is on top of it.
868 Rather than allow an empty stack, we always have the dummy target at
869 the bottom stratum, so we can call the function vectors without
873 push_target (struct target_ops
*t
)
875 struct target_ops
**cur
;
877 /* Check magic number. If wrong, it probably means someone changed
878 the struct definition, but not all the places that initialize one. */
879 if (t
->to_magic
!= OPS_MAGIC
)
881 fprintf_unfiltered (gdb_stderr
,
882 "Magic number of %s target struct wrong\n",
884 internal_error (__FILE__
, __LINE__
, _("failed internal consistency check"));
887 /* Find the proper stratum to install this target in. */
888 for (cur
= &target_stack
; (*cur
) != NULL
; cur
= &(*cur
)->beneath
)
890 if ((int) (t
->to_stratum
) >= (int) (*cur
)->to_stratum
)
894 /* If there's already targets at this stratum, remove them. */
895 /* FIXME: cagney/2003-10-15: I think this should be popping all
896 targets to CUR, and not just those at this stratum level. */
897 while ((*cur
) != NULL
&& t
->to_stratum
== (*cur
)->to_stratum
)
899 /* There's already something at this stratum level. Close it,
900 and un-hook it from the stack. */
901 struct target_ops
*tmp
= (*cur
);
902 (*cur
) = (*cur
)->beneath
;
904 target_close (tmp
, 0);
907 /* We have removed all targets in our stratum, now add the new one. */
911 update_current_target ();
914 return (t
!= target_stack
);
917 /* Remove a target_ops vector from the stack, wherever it may be.
918 Return how many times it was removed (0 or 1). */
921 unpush_target (struct target_ops
*t
)
923 struct target_ops
**cur
;
924 struct target_ops
*tmp
;
926 if (t
->to_stratum
== dummy_stratum
)
927 internal_error (__FILE__
, __LINE__
,
928 "Attempt to unpush the dummy target");
930 /* Look for the specified target. Note that we assume that a target
931 can only occur once in the target stack. */
933 for (cur
= &target_stack
; (*cur
) != NULL
; cur
= &(*cur
)->beneath
)
940 return 0; /* Didn't find target_ops, quit now */
942 /* NOTE: cagney/2003-12-06: In '94 the close call was made
943 unconditional by moving it to before the above check that the
944 target was in the target stack (something about "Change the way
945 pushing and popping of targets work to support target overlays
946 and inheritance"). This doesn't make much sense - only open
947 targets should be closed. */
950 /* Unchain the target */
952 (*cur
) = (*cur
)->beneath
;
955 update_current_target ();
963 target_close (target_stack
, 0); /* Let it clean up */
964 if (unpush_target (target_stack
) == 1)
967 fprintf_unfiltered (gdb_stderr
,
968 "pop_target couldn't find target %s\n",
969 current_target
.to_shortname
);
970 internal_error (__FILE__
, __LINE__
, _("failed internal consistency check"));
974 pop_all_targets_above (enum strata above_stratum
, int quitting
)
976 while ((int) (current_target
.to_stratum
) > (int) above_stratum
)
978 target_close (target_stack
, quitting
);
979 if (!unpush_target (target_stack
))
981 fprintf_unfiltered (gdb_stderr
,
982 "pop_all_targets couldn't find target %s\n",
983 target_stack
->to_shortname
);
984 internal_error (__FILE__
, __LINE__
,
985 _("failed internal consistency check"));
992 pop_all_targets (int quitting
)
994 pop_all_targets_above (dummy_stratum
, quitting
);
997 /* Using the objfile specified in OBJFILE, find the address for the
998 current thread's thread-local storage with offset OFFSET. */
1000 target_translate_tls_address (struct objfile
*objfile
, CORE_ADDR offset
)
1002 volatile CORE_ADDR addr
= 0;
1003 struct target_ops
*target
;
1005 for (target
= current_target
.beneath
;
1007 target
= target
->beneath
)
1009 if (target
->to_get_thread_local_address
!= NULL
)
1014 && gdbarch_fetch_tls_load_module_address_p (target_gdbarch
))
1016 ptid_t ptid
= inferior_ptid
;
1017 volatile struct gdb_exception ex
;
1019 TRY_CATCH (ex
, RETURN_MASK_ALL
)
1023 /* Fetch the load module address for this objfile. */
1024 lm_addr
= gdbarch_fetch_tls_load_module_address (target_gdbarch
,
1026 /* If it's 0, throw the appropriate exception. */
1028 throw_error (TLS_LOAD_MODULE_NOT_FOUND_ERROR
,
1029 _("TLS load module not found"));
1031 addr
= target
->to_get_thread_local_address (target
, ptid
, lm_addr
, offset
);
1033 /* If an error occurred, print TLS related messages here. Otherwise,
1034 throw the error to some higher catcher. */
1037 int objfile_is_library
= (objfile
->flags
& OBJF_SHARED
);
1041 case TLS_NO_LIBRARY_SUPPORT_ERROR
:
1042 error (_("Cannot find thread-local variables in this thread library."));
1044 case TLS_LOAD_MODULE_NOT_FOUND_ERROR
:
1045 if (objfile_is_library
)
1046 error (_("Cannot find shared library `%s' in dynamic"
1047 " linker's load module list"), objfile
->name
);
1049 error (_("Cannot find executable file `%s' in dynamic"
1050 " linker's load module list"), objfile
->name
);
1052 case TLS_NOT_ALLOCATED_YET_ERROR
:
1053 if (objfile_is_library
)
1054 error (_("The inferior has not yet allocated storage for"
1055 " thread-local variables in\n"
1056 "the shared library `%s'\n"
1058 objfile
->name
, target_pid_to_str (ptid
));
1060 error (_("The inferior has not yet allocated storage for"
1061 " thread-local variables in\n"
1062 "the executable `%s'\n"
1064 objfile
->name
, target_pid_to_str (ptid
));
1066 case TLS_GENERIC_ERROR
:
1067 if (objfile_is_library
)
1068 error (_("Cannot find thread-local storage for %s, "
1069 "shared library %s:\n%s"),
1070 target_pid_to_str (ptid
),
1071 objfile
->name
, ex
.message
);
1073 error (_("Cannot find thread-local storage for %s, "
1074 "executable file %s:\n%s"),
1075 target_pid_to_str (ptid
),
1076 objfile
->name
, ex
.message
);
1079 throw_exception (ex
);
1084 /* It wouldn't be wrong here to try a gdbarch method, too; finding
1085 TLS is an ABI-specific thing. But we don't do that yet. */
1087 error (_("Cannot find thread-local variables on this target"));
1093 #define MIN(A, B) (((A) <= (B)) ? (A) : (B))
1095 /* target_read_string -- read a null terminated string, up to LEN bytes,
1096 from MEMADDR in target. Set *ERRNOP to the errno code, or 0 if successful.
1097 Set *STRING to a pointer to malloc'd memory containing the data; the caller
1098 is responsible for freeing it. Return the number of bytes successfully
1102 target_read_string (CORE_ADDR memaddr
, char **string
, int len
, int *errnop
)
1104 int tlen
, origlen
, offset
, i
;
1108 int buffer_allocated
;
1110 unsigned int nbytes_read
= 0;
1112 gdb_assert (string
);
1114 /* Small for testing. */
1115 buffer_allocated
= 4;
1116 buffer
= xmalloc (buffer_allocated
);
1123 tlen
= MIN (len
, 4 - (memaddr
& 3));
1124 offset
= memaddr
& 3;
1126 errcode
= target_read_memory (memaddr
& ~3, buf
, sizeof buf
);
1129 /* The transfer request might have crossed the boundary to an
1130 unallocated region of memory. Retry the transfer, requesting
1134 errcode
= target_read_memory (memaddr
, buf
, 1);
1139 if (bufptr
- buffer
+ tlen
> buffer_allocated
)
1142 bytes
= bufptr
- buffer
;
1143 buffer_allocated
*= 2;
1144 buffer
= xrealloc (buffer
, buffer_allocated
);
1145 bufptr
= buffer
+ bytes
;
1148 for (i
= 0; i
< tlen
; i
++)
1150 *bufptr
++ = buf
[i
+ offset
];
1151 if (buf
[i
+ offset
] == '\000')
1153 nbytes_read
+= i
+ 1;
1160 nbytes_read
+= tlen
;
1169 struct target_section_table
*
1170 target_get_section_table (struct target_ops
*target
)
1172 struct target_ops
*t
;
1175 fprintf_unfiltered (gdb_stdlog
, "target_get_section_table ()\n");
1177 for (t
= target
; t
!= NULL
; t
= t
->beneath
)
1178 if (t
->to_get_section_table
!= NULL
)
1179 return (*t
->to_get_section_table
) (t
);
1184 /* Find a section containing ADDR. */
1186 struct target_section
*
1187 target_section_by_addr (struct target_ops
*target
, CORE_ADDR addr
)
1189 struct target_section_table
*table
= target_get_section_table (target
);
1190 struct target_section
*secp
;
1195 for (secp
= table
->sections
; secp
< table
->sections_end
; secp
++)
1197 if (addr
>= secp
->addr
&& addr
< secp
->endaddr
)
1203 /* Perform a partial memory transfer.
1204 For docs see target.h, to_xfer_partial. */
1207 memory_xfer_partial (struct target_ops
*ops
, enum target_object object
,
1208 void *readbuf
, const void *writebuf
, ULONGEST memaddr
,
1213 struct mem_region
*region
;
1214 struct inferior
*inf
;
1216 /* Zero length requests are ok and require no work. */
1220 /* For accesses to unmapped overlay sections, read directly from
1221 files. Must do this first, as MEMADDR may need adjustment. */
1222 if (readbuf
!= NULL
&& overlay_debugging
)
1224 struct obj_section
*section
= find_pc_overlay (memaddr
);
1225 if (pc_in_unmapped_range (memaddr
, section
))
1227 struct target_section_table
*table
1228 = target_get_section_table (ops
);
1229 const char *section_name
= section
->the_bfd_section
->name
;
1230 memaddr
= overlay_mapped_address (memaddr
, section
);
1231 return section_table_xfer_memory_partial (readbuf
, writebuf
,
1234 table
->sections_end
,
1239 /* Try the executable files, if "trust-readonly-sections" is set. */
1240 if (readbuf
!= NULL
&& trust_readonly
)
1242 struct target_section
*secp
;
1243 struct target_section_table
*table
;
1245 secp
= target_section_by_addr (ops
, memaddr
);
1247 && (bfd_get_section_flags (secp
->bfd
, secp
->the_bfd_section
)
1250 table
= target_get_section_table (ops
);
1251 return section_table_xfer_memory_partial (readbuf
, writebuf
,
1254 table
->sections_end
,
1259 /* Try GDB's internal data cache. */
1260 region
= lookup_mem_region (memaddr
);
1261 /* region->hi == 0 means there's no upper bound. */
1262 if (memaddr
+ len
< region
->hi
|| region
->hi
== 0)
1265 reg_len
= region
->hi
- memaddr
;
1267 switch (region
->attrib
.mode
)
1270 if (writebuf
!= NULL
)
1275 if (readbuf
!= NULL
)
1280 /* We only support writing to flash during "load" for now. */
1281 if (writebuf
!= NULL
)
1282 error (_("Writing to flash memory forbidden in this context"));
1289 if (!ptid_equal (inferior_ptid
, null_ptid
))
1290 inf
= find_inferior_pid (ptid_get_pid (inferior_ptid
));
1295 && (region
->attrib
.cache
1296 || (stack_cache_enabled_p
&& object
== TARGET_OBJECT_STACK_MEMORY
)))
1298 if (readbuf
!= NULL
)
1299 res
= dcache_xfer_memory (ops
, target_dcache
, memaddr
, readbuf
,
1302 /* FIXME drow/2006-08-09: If we're going to preserve const
1303 correctness dcache_xfer_memory should take readbuf and
1305 res
= dcache_xfer_memory (ops
, target_dcache
, memaddr
,
1312 if (readbuf
&& !show_memory_breakpoints
)
1313 breakpoint_restore_shadows (readbuf
, memaddr
, reg_len
);
1318 /* If none of those methods found the memory we wanted, fall back
1319 to a target partial transfer. Normally a single call to
1320 to_xfer_partial is enough; if it doesn't recognize an object
1321 it will call the to_xfer_partial of the next target down.
1322 But for memory this won't do. Memory is the only target
1323 object which can be read from more than one valid target.
1324 A core file, for instance, could have some of memory but
1325 delegate other bits to the target below it. So, we must
1326 manually try all targets. */
1330 res
= ops
->to_xfer_partial (ops
, TARGET_OBJECT_MEMORY
, NULL
,
1331 readbuf
, writebuf
, memaddr
, reg_len
);
1335 /* We want to continue past core files to executables, but not
1336 past a running target's memory. */
1337 if (ops
->to_has_all_memory (ops
))
1342 while (ops
!= NULL
);
1344 if (readbuf
&& !show_memory_breakpoints
)
1345 breakpoint_restore_shadows (readbuf
, memaddr
, reg_len
);
1347 /* Make sure the cache gets updated no matter what - if we are writing
1348 to the stack. Even if this write is not tagged as such, we still need
1349 to update the cache. */
1354 && !region
->attrib
.cache
1355 && stack_cache_enabled_p
1356 && object
!= TARGET_OBJECT_STACK_MEMORY
)
1358 dcache_update (target_dcache
, memaddr
, (void *) writebuf
, res
);
1361 /* If we still haven't got anything, return the last error. We
1367 restore_show_memory_breakpoints (void *arg
)
1369 show_memory_breakpoints
= (uintptr_t) arg
;
1373 make_show_memory_breakpoints_cleanup (int show
)
1375 int current
= show_memory_breakpoints
;
1376 show_memory_breakpoints
= show
;
1378 return make_cleanup (restore_show_memory_breakpoints
,
1379 (void *) (uintptr_t) current
);
1382 /* For docs see target.h, to_xfer_partial. */
1385 target_xfer_partial (struct target_ops
*ops
,
1386 enum target_object object
, const char *annex
,
1387 void *readbuf
, const void *writebuf
,
1388 ULONGEST offset
, LONGEST len
)
1392 gdb_assert (ops
->to_xfer_partial
!= NULL
);
1394 /* If this is a memory transfer, let the memory-specific code
1395 have a look at it instead. Memory transfers are more
1397 if (object
== TARGET_OBJECT_MEMORY
|| object
== TARGET_OBJECT_STACK_MEMORY
)
1398 retval
= memory_xfer_partial (ops
, object
, readbuf
,
1399 writebuf
, offset
, len
);
1402 enum target_object raw_object
= object
;
1404 /* If this is a raw memory transfer, request the normal
1405 memory object from other layers. */
1406 if (raw_object
== TARGET_OBJECT_RAW_MEMORY
)
1407 raw_object
= TARGET_OBJECT_MEMORY
;
1409 retval
= ops
->to_xfer_partial (ops
, raw_object
, annex
, readbuf
,
1410 writebuf
, offset
, len
);
1415 const unsigned char *myaddr
= NULL
;
1417 fprintf_unfiltered (gdb_stdlog
,
1418 "%s:target_xfer_partial (%d, %s, %s, %s, %s, %s) = %s",
1421 (annex
? annex
: "(null)"),
1422 host_address_to_string (readbuf
),
1423 host_address_to_string (writebuf
),
1424 core_addr_to_string_nz (offset
),
1425 plongest (len
), plongest (retval
));
1431 if (retval
> 0 && myaddr
!= NULL
)
1435 fputs_unfiltered (", bytes =", gdb_stdlog
);
1436 for (i
= 0; i
< retval
; i
++)
1438 if ((((intptr_t) &(myaddr
[i
])) & 0xf) == 0)
1440 if (targetdebug
< 2 && i
> 0)
1442 fprintf_unfiltered (gdb_stdlog
, " ...");
1445 fprintf_unfiltered (gdb_stdlog
, "\n");
1448 fprintf_unfiltered (gdb_stdlog
, " %02x", myaddr
[i
] & 0xff);
1452 fputc_unfiltered ('\n', gdb_stdlog
);
1457 /* Read LEN bytes of target memory at address MEMADDR, placing the results in
1458 GDB's memory at MYADDR. Returns either 0 for success or an errno value
1459 if any error occurs.
1461 If an error occurs, no guarantee is made about the contents of the data at
1462 MYADDR. In particular, the caller should not depend upon partial reads
1463 filling the buffer with good data. There is no way for the caller to know
1464 how much good data might have been transfered anyway. Callers that can
1465 deal with partial reads should call target_read (which will retry until
1466 it makes no progress, and then return how much was transferred). */
1469 target_read_memory (CORE_ADDR memaddr
, gdb_byte
*myaddr
, int len
)
1471 /* Dispatch to the topmost target, not the flattened current_target.
1472 Memory accesses check target->to_has_(all_)memory, and the
1473 flattened target doesn't inherit those. */
1474 if (target_read (current_target
.beneath
, TARGET_OBJECT_MEMORY
, NULL
,
1475 myaddr
, memaddr
, len
) == len
)
1481 /* Like target_read_memory, but specify explicitly that this is a read from
1482 the target's stack. This may trigger different cache behavior. */
1485 target_read_stack (CORE_ADDR memaddr
, gdb_byte
*myaddr
, int len
)
1487 /* Dispatch to the topmost target, not the flattened current_target.
1488 Memory accesses check target->to_has_(all_)memory, and the
1489 flattened target doesn't inherit those. */
1491 if (target_read (current_target
.beneath
, TARGET_OBJECT_STACK_MEMORY
, NULL
,
1492 myaddr
, memaddr
, len
) == len
)
1498 /* Write LEN bytes from MYADDR to target memory at address MEMADDR.
1499 Returns either 0 for success or an errno value if any error occurs.
1500 If an error occurs, no guarantee is made about how much data got written.
1501 Callers that can deal with partial writes should call target_write. */
1504 target_write_memory (CORE_ADDR memaddr
, const gdb_byte
*myaddr
, int len
)
1506 /* Dispatch to the topmost target, not the flattened current_target.
1507 Memory accesses check target->to_has_(all_)memory, and the
1508 flattened target doesn't inherit those. */
1509 if (target_write (current_target
.beneath
, TARGET_OBJECT_MEMORY
, NULL
,
1510 myaddr
, memaddr
, len
) == len
)
1516 /* Fetch the target's memory map. */
1519 target_memory_map (void)
1521 VEC(mem_region_s
) *result
;
1522 struct mem_region
*last_one
, *this_one
;
1524 struct target_ops
*t
;
1527 fprintf_unfiltered (gdb_stdlog
, "target_memory_map ()\n");
1529 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
1530 if (t
->to_memory_map
!= NULL
)
1536 result
= t
->to_memory_map (t
);
1540 qsort (VEC_address (mem_region_s
, result
),
1541 VEC_length (mem_region_s
, result
),
1542 sizeof (struct mem_region
), mem_region_cmp
);
1544 /* Check that regions do not overlap. Simultaneously assign
1545 a numbering for the "mem" commands to use to refer to
1548 for (ix
= 0; VEC_iterate (mem_region_s
, result
, ix
, this_one
); ix
++)
1550 this_one
->number
= ix
;
1552 if (last_one
&& last_one
->hi
> this_one
->lo
)
1554 warning (_("Overlapping regions in memory map: ignoring"));
1555 VEC_free (mem_region_s
, result
);
1558 last_one
= this_one
;
1565 target_flash_erase (ULONGEST address
, LONGEST length
)
1567 struct target_ops
*t
;
1569 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
1570 if (t
->to_flash_erase
!= NULL
)
1573 fprintf_unfiltered (gdb_stdlog
, "target_flash_erase (%s, %s)\n",
1574 hex_string (address
), phex (length
, 0));
1575 t
->to_flash_erase (t
, address
, length
);
1583 target_flash_done (void)
1585 struct target_ops
*t
;
1587 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
1588 if (t
->to_flash_done
!= NULL
)
1591 fprintf_unfiltered (gdb_stdlog
, "target_flash_done\n");
1592 t
->to_flash_done (t
);
1600 show_trust_readonly (struct ui_file
*file
, int from_tty
,
1601 struct cmd_list_element
*c
, const char *value
)
1603 fprintf_filtered (file
, _("\
1604 Mode for reading from readonly sections is %s.\n"),
1608 /* More generic transfers. */
1611 default_xfer_partial (struct target_ops
*ops
, enum target_object object
,
1612 const char *annex
, gdb_byte
*readbuf
,
1613 const gdb_byte
*writebuf
, ULONGEST offset
, LONGEST len
)
1615 if (object
== TARGET_OBJECT_MEMORY
1616 && ops
->deprecated_xfer_memory
!= NULL
)
1617 /* If available, fall back to the target's
1618 "deprecated_xfer_memory" method. */
1622 if (writebuf
!= NULL
)
1624 void *buffer
= xmalloc (len
);
1625 struct cleanup
*cleanup
= make_cleanup (xfree
, buffer
);
1626 memcpy (buffer
, writebuf
, len
);
1627 xfered
= ops
->deprecated_xfer_memory (offset
, buffer
, len
,
1628 1/*write*/, NULL
, ops
);
1629 do_cleanups (cleanup
);
1631 if (readbuf
!= NULL
)
1632 xfered
= ops
->deprecated_xfer_memory (offset
, readbuf
, len
,
1633 0/*read*/, NULL
, ops
);
1636 else if (xfered
== 0 && errno
== 0)
1637 /* "deprecated_xfer_memory" uses 0, cross checked against
1638 ERRNO as one indication of an error. */
1643 else if (ops
->beneath
!= NULL
)
1644 return ops
->beneath
->to_xfer_partial (ops
->beneath
, object
, annex
,
1645 readbuf
, writebuf
, offset
, len
);
1650 /* The xfer_partial handler for the topmost target. Unlike the default,
1651 it does not need to handle memory specially; it just passes all
1652 requests down the stack. */
1655 current_xfer_partial (struct target_ops
*ops
, enum target_object object
,
1656 const char *annex
, gdb_byte
*readbuf
,
1657 const gdb_byte
*writebuf
, ULONGEST offset
, LONGEST len
)
1659 if (ops
->beneath
!= NULL
)
1660 return ops
->beneath
->to_xfer_partial (ops
->beneath
, object
, annex
,
1661 readbuf
, writebuf
, offset
, len
);
1666 /* Target vector read/write partial wrapper functions. */
1669 target_read_partial (struct target_ops
*ops
,
1670 enum target_object object
,
1671 const char *annex
, gdb_byte
*buf
,
1672 ULONGEST offset
, LONGEST len
)
1674 return target_xfer_partial (ops
, object
, annex
, buf
, NULL
, offset
, len
);
1678 target_write_partial (struct target_ops
*ops
,
1679 enum target_object object
,
1680 const char *annex
, const gdb_byte
*buf
,
1681 ULONGEST offset
, LONGEST len
)
1683 return target_xfer_partial (ops
, object
, annex
, NULL
, buf
, offset
, len
);
1686 /* Wrappers to perform the full transfer. */
1688 /* For docs on target_read see target.h. */
1691 target_read (struct target_ops
*ops
,
1692 enum target_object object
,
1693 const char *annex
, gdb_byte
*buf
,
1694 ULONGEST offset
, LONGEST len
)
1697 while (xfered
< len
)
1699 LONGEST xfer
= target_read_partial (ops
, object
, annex
,
1700 (gdb_byte
*) buf
+ xfered
,
1701 offset
+ xfered
, len
- xfered
);
1702 /* Call an observer, notifying them of the xfer progress? */
1714 target_read_until_error (struct target_ops
*ops
,
1715 enum target_object object
,
1716 const char *annex
, gdb_byte
*buf
,
1717 ULONGEST offset
, LONGEST len
)
1720 while (xfered
< len
)
1722 LONGEST xfer
= target_read_partial (ops
, object
, annex
,
1723 (gdb_byte
*) buf
+ xfered
,
1724 offset
+ xfered
, len
- xfered
);
1725 /* Call an observer, notifying them of the xfer progress? */
1730 /* We've got an error. Try to read in smaller blocks. */
1731 ULONGEST start
= offset
+ xfered
;
1732 ULONGEST remaining
= len
- xfered
;
1735 /* If an attempt was made to read a random memory address,
1736 it's likely that the very first byte is not accessible.
1737 Try reading the first byte, to avoid doing log N tries
1739 xfer
= target_read_partial (ops
, object
, annex
,
1740 (gdb_byte
*) buf
+ xfered
, start
, 1);
1749 xfer
= target_read_partial (ops
, object
, annex
,
1750 (gdb_byte
*) buf
+ xfered
,
1760 /* We have successfully read the first half. So, the
1761 error must be in the second half. Adjust start and
1762 remaining to point at the second half. */
1778 /* An alternative to target_write with progress callbacks. */
1781 target_write_with_progress (struct target_ops
*ops
,
1782 enum target_object object
,
1783 const char *annex
, const gdb_byte
*buf
,
1784 ULONGEST offset
, LONGEST len
,
1785 void (*progress
) (ULONGEST
, void *), void *baton
)
1789 /* Give the progress callback a chance to set up. */
1791 (*progress
) (0, baton
);
1793 while (xfered
< len
)
1795 LONGEST xfer
= target_write_partial (ops
, object
, annex
,
1796 (gdb_byte
*) buf
+ xfered
,
1797 offset
+ xfered
, len
- xfered
);
1805 (*progress
) (xfer
, baton
);
1813 /* For docs on target_write see target.h. */
1816 target_write (struct target_ops
*ops
,
1817 enum target_object object
,
1818 const char *annex
, const gdb_byte
*buf
,
1819 ULONGEST offset
, LONGEST len
)
1821 return target_write_with_progress (ops
, object
, annex
, buf
, offset
, len
,
1825 /* Read OBJECT/ANNEX using OPS. Store the result in *BUF_P and return
1826 the size of the transferred data. PADDING additional bytes are
1827 available in *BUF_P. This is a helper function for
1828 target_read_alloc; see the declaration of that function for more
1832 target_read_alloc_1 (struct target_ops
*ops
, enum target_object object
,
1833 const char *annex
, gdb_byte
**buf_p
, int padding
)
1835 size_t buf_alloc
, buf_pos
;
1839 /* This function does not have a length parameter; it reads the
1840 entire OBJECT). Also, it doesn't support objects fetched partly
1841 from one target and partly from another (in a different stratum,
1842 e.g. a core file and an executable). Both reasons make it
1843 unsuitable for reading memory. */
1844 gdb_assert (object
!= TARGET_OBJECT_MEMORY
);
1846 /* Start by reading up to 4K at a time. The target will throttle
1847 this number down if necessary. */
1849 buf
= xmalloc (buf_alloc
);
1853 n
= target_read_partial (ops
, object
, annex
, &buf
[buf_pos
],
1854 buf_pos
, buf_alloc
- buf_pos
- padding
);
1857 /* An error occurred. */
1863 /* Read all there was. */
1873 /* If the buffer is filling up, expand it. */
1874 if (buf_alloc
< buf_pos
* 2)
1877 buf
= xrealloc (buf
, buf_alloc
);
1884 /* Read OBJECT/ANNEX using OPS. Store the result in *BUF_P and return
1885 the size of the transferred data. See the declaration in "target.h"
1886 function for more information about the return value. */
1889 target_read_alloc (struct target_ops
*ops
, enum target_object object
,
1890 const char *annex
, gdb_byte
**buf_p
)
1892 return target_read_alloc_1 (ops
, object
, annex
, buf_p
, 0);
1895 /* Read OBJECT/ANNEX using OPS. The result is NUL-terminated and
1896 returned as a string, allocated using xmalloc. If an error occurs
1897 or the transfer is unsupported, NULL is returned. Empty objects
1898 are returned as allocated but empty strings. A warning is issued
1899 if the result contains any embedded NUL bytes. */
1902 target_read_stralloc (struct target_ops
*ops
, enum target_object object
,
1906 LONGEST transferred
;
1908 transferred
= target_read_alloc_1 (ops
, object
, annex
, &buffer
, 1);
1910 if (transferred
< 0)
1913 if (transferred
== 0)
1914 return xstrdup ("");
1916 buffer
[transferred
] = 0;
1917 if (strlen (buffer
) < transferred
)
1918 warning (_("target object %d, annex %s, "
1919 "contained unexpected null characters"),
1920 (int) object
, annex
? annex
: "(none)");
1922 return (char *) buffer
;
1925 /* Memory transfer methods. */
1928 get_target_memory (struct target_ops
*ops
, CORE_ADDR addr
, gdb_byte
*buf
,
1931 /* This method is used to read from an alternate, non-current
1932 target. This read must bypass the overlay support (as symbols
1933 don't match this target), and GDB's internal cache (wrong cache
1934 for this target). */
1935 if (target_read (ops
, TARGET_OBJECT_RAW_MEMORY
, NULL
, buf
, addr
, len
)
1937 memory_error (EIO
, addr
);
1941 get_target_memory_unsigned (struct target_ops
*ops
,
1942 CORE_ADDR addr
, int len
, enum bfd_endian byte_order
)
1944 gdb_byte buf
[sizeof (ULONGEST
)];
1946 gdb_assert (len
<= sizeof (buf
));
1947 get_target_memory (ops
, addr
, buf
, len
);
1948 return extract_unsigned_integer (buf
, len
, byte_order
);
1952 target_info (char *args
, int from_tty
)
1954 struct target_ops
*t
;
1955 int has_all_mem
= 0;
1957 if (symfile_objfile
!= NULL
)
1958 printf_unfiltered (_("Symbols from \"%s\".\n"), symfile_objfile
->name
);
1960 for (t
= target_stack
; t
!= NULL
; t
= t
->beneath
)
1962 if (!(*t
->to_has_memory
) (t
))
1965 if ((int) (t
->to_stratum
) <= (int) dummy_stratum
)
1968 printf_unfiltered (_("\tWhile running this, GDB does not access memory from...\n"));
1969 printf_unfiltered ("%s:\n", t
->to_longname
);
1970 (t
->to_files_info
) (t
);
1971 has_all_mem
= (*t
->to_has_all_memory
) (t
);
1975 /* This function is called before any new inferior is created, e.g.
1976 by running a program, attaching, or connecting to a target.
1977 It cleans up any state from previous invocations which might
1978 change between runs. This is a subset of what target_preopen
1979 resets (things which might change between targets). */
1982 target_pre_inferior (int from_tty
)
1984 /* Clear out solib state. Otherwise the solib state of the previous
1985 inferior might have survived and is entirely wrong for the new
1986 target. This has been observed on GNU/Linux using glibc 2.3. How
1998 Cannot access memory at address 0xdeadbeef
2001 /* In some OSs, the shared library list is the same/global/shared
2002 across inferiors. If code is shared between processes, so are
2003 memory regions and features. */
2004 if (!gdbarch_has_global_solist (target_gdbarch
))
2006 no_shared_libraries (NULL
, from_tty
);
2008 invalidate_target_mem_regions ();
2010 target_clear_description ();
2014 /* Callback for iterate_over_inferiors. Gets rid of the given
2018 dispose_inferior (struct inferior
*inf
, void *args
)
2020 struct thread_info
*thread
;
2022 thread
= any_thread_of_process (inf
->pid
);
2025 switch_to_thread (thread
->ptid
);
2027 /* Core inferiors actually should be detached, not killed. */
2028 if (target_has_execution
)
2031 target_detach (NULL
, 0);
2037 /* This is to be called by the open routine before it does
2041 target_preopen (int from_tty
)
2045 if (have_inferiors ())
2048 || !have_live_inferiors ()
2049 || query (_("A program is being debugged already. Kill it? ")))
2050 iterate_over_inferiors (dispose_inferior
, NULL
);
2052 error (_("Program not killed."));
2055 /* Calling target_kill may remove the target from the stack. But if
2056 it doesn't (which seems like a win for UDI), remove it now. */
2057 /* Leave the exec target, though. The user may be switching from a
2058 live process to a core of the same program. */
2059 pop_all_targets_above (file_stratum
, 0);
2061 target_pre_inferior (from_tty
);
2064 /* Detach a target after doing deferred register stores. */
2067 target_detach (char *args
, int from_tty
)
2069 struct target_ops
* t
;
2071 if (gdbarch_has_global_breakpoints (target_gdbarch
))
2072 /* Don't remove global breakpoints here. They're removed on
2073 disconnection from the target. */
2076 /* If we're in breakpoints-always-inserted mode, have to remove
2077 them before detaching. */
2078 remove_breakpoints_pid (PIDGET (inferior_ptid
));
2080 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
2082 if (t
->to_detach
!= NULL
)
2084 t
->to_detach (t
, args
, from_tty
);
2086 fprintf_unfiltered (gdb_stdlog
, "target_detach (%s, %d)\n",
2092 internal_error (__FILE__
, __LINE__
, "could not find a target to detach");
2096 target_disconnect (char *args
, int from_tty
)
2098 struct target_ops
*t
;
2100 /* If we're in breakpoints-always-inserted mode or if breakpoints
2101 are global across processes, we have to remove them before
2103 remove_breakpoints ();
2105 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
2106 if (t
->to_disconnect
!= NULL
)
2109 fprintf_unfiltered (gdb_stdlog
, "target_disconnect (%s, %d)\n",
2111 t
->to_disconnect (t
, args
, from_tty
);
2119 target_wait (ptid_t ptid
, struct target_waitstatus
*status
, int options
)
2121 struct target_ops
*t
;
2123 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
2125 if (t
->to_wait
!= NULL
)
2127 ptid_t retval
= (*t
->to_wait
) (t
, ptid
, status
, options
);
2131 char *status_string
;
2133 status_string
= target_waitstatus_to_string (status
);
2134 fprintf_unfiltered (gdb_stdlog
,
2135 "target_wait (%d, status) = %d, %s\n",
2136 PIDGET (ptid
), PIDGET (retval
),
2138 xfree (status_string
);
2149 target_pid_to_str (ptid_t ptid
)
2151 struct target_ops
*t
;
2153 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
2155 if (t
->to_pid_to_str
!= NULL
)
2156 return (*t
->to_pid_to_str
) (t
, ptid
);
2159 return normal_pid_to_str (ptid
);
2163 target_resume (ptid_t ptid
, int step
, enum target_signal signal
)
2165 struct target_ops
*t
;
2167 target_dcache_invalidate ();
2169 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
2171 if (t
->to_resume
!= NULL
)
2173 t
->to_resume (t
, ptid
, step
, signal
);
2175 fprintf_unfiltered (gdb_stdlog
, "target_resume (%d, %s, %s)\n",
2177 step
? "step" : "continue",
2178 target_signal_to_name (signal
));
2180 set_executing (ptid
, 1);
2181 set_running (ptid
, 1);
2182 clear_inline_frame_state (ptid
);
2189 /* Look through the list of possible targets for a target that can
2193 target_follow_fork (int follow_child
)
2195 struct target_ops
*t
;
2197 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
2199 if (t
->to_follow_fork
!= NULL
)
2201 int retval
= t
->to_follow_fork (t
, follow_child
);
2203 fprintf_unfiltered (gdb_stdlog
, "target_follow_fork (%d) = %d\n",
2204 follow_child
, retval
);
2209 /* Some target returned a fork event, but did not know how to follow it. */
2210 internal_error (__FILE__
, __LINE__
,
2211 "could not find a target to follow fork");
2215 target_mourn_inferior (void)
2217 struct target_ops
*t
;
2218 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
2220 if (t
->to_mourn_inferior
!= NULL
)
2222 t
->to_mourn_inferior (t
);
2224 fprintf_unfiltered (gdb_stdlog
, "target_mourn_inferior ()\n");
2226 /* We no longer need to keep handles on any of the object files.
2227 Make sure to release them to avoid unnecessarily locking any
2228 of them while we're not actually debugging. */
2229 bfd_cache_close_all ();
2235 internal_error (__FILE__
, __LINE__
,
2236 "could not find a target to follow mourn inferiour");
2239 /* Look for a target which can describe architectural features, starting
2240 from TARGET. If we find one, return its description. */
2242 const struct target_desc
*
2243 target_read_description (struct target_ops
*target
)
2245 struct target_ops
*t
;
2247 for (t
= target
; t
!= NULL
; t
= t
->beneath
)
2248 if (t
->to_read_description
!= NULL
)
2250 const struct target_desc
*tdesc
;
2252 tdesc
= t
->to_read_description (t
);
2260 /* The default implementation of to_search_memory.
2261 This implements a basic search of memory, reading target memory and
2262 performing the search here (as opposed to performing the search in on the
2263 target side with, for example, gdbserver). */
2266 simple_search_memory (struct target_ops
*ops
,
2267 CORE_ADDR start_addr
, ULONGEST search_space_len
,
2268 const gdb_byte
*pattern
, ULONGEST pattern_len
,
2269 CORE_ADDR
*found_addrp
)
2271 /* NOTE: also defined in find.c testcase. */
2272 #define SEARCH_CHUNK_SIZE 16000
2273 const unsigned chunk_size
= SEARCH_CHUNK_SIZE
;
2274 /* Buffer to hold memory contents for searching. */
2275 gdb_byte
*search_buf
;
2276 unsigned search_buf_size
;
2277 struct cleanup
*old_cleanups
;
2279 search_buf_size
= chunk_size
+ pattern_len
- 1;
2281 /* No point in trying to allocate a buffer larger than the search space. */
2282 if (search_space_len
< search_buf_size
)
2283 search_buf_size
= search_space_len
;
2285 search_buf
= malloc (search_buf_size
);
2286 if (search_buf
== NULL
)
2287 error (_("Unable to allocate memory to perform the search."));
2288 old_cleanups
= make_cleanup (free_current_contents
, &search_buf
);
2290 /* Prime the search buffer. */
2292 if (target_read (ops
, TARGET_OBJECT_MEMORY
, NULL
,
2293 search_buf
, start_addr
, search_buf_size
) != search_buf_size
)
2295 warning (_("Unable to access target memory at %s, halting search."),
2296 hex_string (start_addr
));
2297 do_cleanups (old_cleanups
);
2301 /* Perform the search.
2303 The loop is kept simple by allocating [N + pattern-length - 1] bytes.
2304 When we've scanned N bytes we copy the trailing bytes to the start and
2305 read in another N bytes. */
2307 while (search_space_len
>= pattern_len
)
2309 gdb_byte
*found_ptr
;
2310 unsigned nr_search_bytes
= min (search_space_len
, search_buf_size
);
2312 found_ptr
= memmem (search_buf
, nr_search_bytes
,
2313 pattern
, pattern_len
);
2315 if (found_ptr
!= NULL
)
2317 CORE_ADDR found_addr
= start_addr
+ (found_ptr
- search_buf
);
2318 *found_addrp
= found_addr
;
2319 do_cleanups (old_cleanups
);
2323 /* Not found in this chunk, skip to next chunk. */
2325 /* Don't let search_space_len wrap here, it's unsigned. */
2326 if (search_space_len
>= chunk_size
)
2327 search_space_len
-= chunk_size
;
2329 search_space_len
= 0;
2331 if (search_space_len
>= pattern_len
)
2333 unsigned keep_len
= search_buf_size
- chunk_size
;
2334 CORE_ADDR read_addr
= start_addr
+ chunk_size
+ keep_len
;
2337 /* Copy the trailing part of the previous iteration to the front
2338 of the buffer for the next iteration. */
2339 gdb_assert (keep_len
== pattern_len
- 1);
2340 memcpy (search_buf
, search_buf
+ chunk_size
, keep_len
);
2342 nr_to_read
= min (search_space_len
- keep_len
, chunk_size
);
2344 if (target_read (ops
, TARGET_OBJECT_MEMORY
, NULL
,
2345 search_buf
+ keep_len
, read_addr
,
2346 nr_to_read
) != nr_to_read
)
2348 warning (_("Unable to access target memory at %s, halting search."),
2349 hex_string (read_addr
));
2350 do_cleanups (old_cleanups
);
2354 start_addr
+= chunk_size
;
2360 do_cleanups (old_cleanups
);
2364 /* Search SEARCH_SPACE_LEN bytes beginning at START_ADDR for the
2365 sequence of bytes in PATTERN with length PATTERN_LEN.
2367 The result is 1 if found, 0 if not found, and -1 if there was an error
2368 requiring halting of the search (e.g. memory read error).
2369 If the pattern is found the address is recorded in FOUND_ADDRP. */
2372 target_search_memory (CORE_ADDR start_addr
, ULONGEST search_space_len
,
2373 const gdb_byte
*pattern
, ULONGEST pattern_len
,
2374 CORE_ADDR
*found_addrp
)
2376 struct target_ops
*t
;
2379 /* We don't use INHERIT to set current_target.to_search_memory,
2380 so we have to scan the target stack and handle targetdebug
2384 fprintf_unfiltered (gdb_stdlog
, "target_search_memory (%s, ...)\n",
2385 hex_string (start_addr
));
2387 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
2388 if (t
->to_search_memory
!= NULL
)
2393 found
= t
->to_search_memory (t
, start_addr
, search_space_len
,
2394 pattern
, pattern_len
, found_addrp
);
2398 /* If a special version of to_search_memory isn't available, use the
2400 found
= simple_search_memory (current_target
.beneath
,
2401 start_addr
, search_space_len
,
2402 pattern
, pattern_len
, found_addrp
);
2406 fprintf_unfiltered (gdb_stdlog
, " = %d\n", found
);
2411 /* Look through the currently pushed targets. If none of them will
2412 be able to restart the currently running process, issue an error
2416 target_require_runnable (void)
2418 struct target_ops
*t
;
2420 for (t
= target_stack
; t
!= NULL
; t
= t
->beneath
)
2422 /* If this target knows how to create a new program, then
2423 assume we will still be able to after killing the current
2424 one. Either killing and mourning will not pop T, or else
2425 find_default_run_target will find it again. */
2426 if (t
->to_create_inferior
!= NULL
)
2429 /* Do not worry about thread_stratum targets that can not
2430 create inferiors. Assume they will be pushed again if
2431 necessary, and continue to the process_stratum. */
2432 if (t
->to_stratum
== thread_stratum
2433 || t
->to_stratum
== arch_stratum
)
2437 The \"%s\" target does not support \"run\". Try \"help target\" or \"continue\"."),
2441 /* This function is only called if the target is running. In that
2442 case there should have been a process_stratum target and it
2443 should either know how to create inferiors, or not... */
2444 internal_error (__FILE__
, __LINE__
, "No targets found");
2447 /* Look through the list of possible targets for a target that can
2448 execute a run or attach command without any other data. This is
2449 used to locate the default process stratum.
2451 If DO_MESG is not NULL, the result is always valid (error() is
2452 called for errors); else, return NULL on error. */
2454 static struct target_ops
*
2455 find_default_run_target (char *do_mesg
)
2457 struct target_ops
**t
;
2458 struct target_ops
*runable
= NULL
;
2463 for (t
= target_structs
; t
< target_structs
+ target_struct_size
;
2466 if ((*t
)->to_can_run
&& target_can_run (*t
))
2476 error (_("Don't know how to %s. Try \"help target\"."), do_mesg
);
2485 find_default_attach (struct target_ops
*ops
, char *args
, int from_tty
)
2487 struct target_ops
*t
;
2489 t
= find_default_run_target ("attach");
2490 (t
->to_attach
) (t
, args
, from_tty
);
2495 find_default_create_inferior (struct target_ops
*ops
,
2496 char *exec_file
, char *allargs
, char **env
,
2499 struct target_ops
*t
;
2501 t
= find_default_run_target ("run");
2502 (t
->to_create_inferior
) (t
, exec_file
, allargs
, env
, from_tty
);
2507 find_default_can_async_p (void)
2509 struct target_ops
*t
;
2511 /* This may be called before the target is pushed on the stack;
2512 look for the default process stratum. If there's none, gdb isn't
2513 configured with a native debugger, and target remote isn't
2515 t
= find_default_run_target (NULL
);
2516 if (t
&& t
->to_can_async_p
)
2517 return (t
->to_can_async_p
) ();
2522 find_default_is_async_p (void)
2524 struct target_ops
*t
;
2526 /* This may be called before the target is pushed on the stack;
2527 look for the default process stratum. If there's none, gdb isn't
2528 configured with a native debugger, and target remote isn't
2530 t
= find_default_run_target (NULL
);
2531 if (t
&& t
->to_is_async_p
)
2532 return (t
->to_is_async_p
) ();
2537 find_default_supports_non_stop (void)
2539 struct target_ops
*t
;
2541 t
= find_default_run_target (NULL
);
2542 if (t
&& t
->to_supports_non_stop
)
2543 return (t
->to_supports_non_stop
) ();
2548 target_supports_non_stop (void)
2550 struct target_ops
*t
;
2551 for (t
= ¤t_target
; t
!= NULL
; t
= t
->beneath
)
2552 if (t
->to_supports_non_stop
)
2553 return t
->to_supports_non_stop ();
2560 target_get_osdata (const char *type
)
2563 struct target_ops
*t
;
2565 /* If we're already connected to something that can get us OS
2566 related data, use it. Otherwise, try using the native
2568 if (current_target
.to_stratum
>= process_stratum
)
2569 t
= current_target
.beneath
;
2571 t
= find_default_run_target ("get OS data");
2576 return target_read_stralloc (t
, TARGET_OBJECT_OSDATA
, type
);
2579 /* Determine the current address space of thread PTID. */
2581 struct address_space
*
2582 target_thread_address_space (ptid_t ptid
)
2584 struct address_space
*aspace
;
2585 struct inferior
*inf
;
2586 struct target_ops
*t
;
2588 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
2590 if (t
->to_thread_address_space
!= NULL
)
2592 aspace
= t
->to_thread_address_space (t
, ptid
);
2593 gdb_assert (aspace
);
2596 fprintf_unfiltered (gdb_stdlog
,
2597 "target_thread_address_space (%s) = %d\n",
2598 target_pid_to_str (ptid
),
2599 address_space_num (aspace
));
2604 /* Fall-back to the "main" address space of the inferior. */
2605 inf
= find_inferior_pid (ptid_get_pid (ptid
));
2607 if (inf
== NULL
|| inf
->aspace
== NULL
)
2608 internal_error (__FILE__
, __LINE__
, "\
2609 Can't determine the current address space of thread %s\n",
2610 target_pid_to_str (ptid
));
2616 default_region_ok_for_hw_watchpoint (CORE_ADDR addr
, int len
)
2618 return (len
<= gdbarch_ptr_bit (target_gdbarch
) / TARGET_CHAR_BIT
);
2622 default_watchpoint_addr_within_range (struct target_ops
*target
,
2624 CORE_ADDR start
, int length
)
2626 return addr
>= start
&& addr
< start
+ length
;
2629 static struct gdbarch
*
2630 default_thread_architecture (struct target_ops
*ops
, ptid_t ptid
)
2632 return target_gdbarch
;
2648 return_minus_one (void)
2653 /* Find a single runnable target in the stack and return it. If for
2654 some reason there is more than one, return NULL. */
2657 find_run_target (void)
2659 struct target_ops
**t
;
2660 struct target_ops
*runable
= NULL
;
2665 for (t
= target_structs
; t
< target_structs
+ target_struct_size
; ++t
)
2667 if ((*t
)->to_can_run
&& target_can_run (*t
))
2674 return (count
== 1 ? runable
: NULL
);
2677 /* Find a single core_stratum target in the list of targets and return it.
2678 If for some reason there is more than one, return NULL. */
2681 find_core_target (void)
2683 struct target_ops
**t
;
2684 struct target_ops
*runable
= NULL
;
2689 for (t
= target_structs
; t
< target_structs
+ target_struct_size
;
2692 if ((*t
)->to_stratum
== core_stratum
)
2699 return (count
== 1 ? runable
: NULL
);
2703 * Find the next target down the stack from the specified target.
2707 find_target_beneath (struct target_ops
*t
)
2713 /* The inferior process has died. Long live the inferior! */
2716 generic_mourn_inferior (void)
2720 ptid
= inferior_ptid
;
2721 inferior_ptid
= null_ptid
;
2723 if (!ptid_equal (ptid
, null_ptid
))
2725 int pid
= ptid_get_pid (ptid
);
2726 exit_inferior (pid
);
2729 breakpoint_init_inferior (inf_exited
);
2730 registers_changed ();
2732 reopen_exec_file ();
2733 reinit_frame_cache ();
2735 if (deprecated_detach_hook
)
2736 deprecated_detach_hook ();
2739 /* Helper function for child_wait and the derivatives of child_wait.
2740 HOSTSTATUS is the waitstatus from wait() or the equivalent; store our
2741 translation of that in OURSTATUS. */
2743 store_waitstatus (struct target_waitstatus
*ourstatus
, int hoststatus
)
2745 if (WIFEXITED (hoststatus
))
2747 ourstatus
->kind
= TARGET_WAITKIND_EXITED
;
2748 ourstatus
->value
.integer
= WEXITSTATUS (hoststatus
);
2750 else if (!WIFSTOPPED (hoststatus
))
2752 ourstatus
->kind
= TARGET_WAITKIND_SIGNALLED
;
2753 ourstatus
->value
.sig
= target_signal_from_host (WTERMSIG (hoststatus
));
2757 ourstatus
->kind
= TARGET_WAITKIND_STOPPED
;
2758 ourstatus
->value
.sig
= target_signal_from_host (WSTOPSIG (hoststatus
));
2762 /* Convert a normal process ID to a string. Returns the string in a
2766 normal_pid_to_str (ptid_t ptid
)
2768 static char buf
[32];
2770 xsnprintf (buf
, sizeof buf
, "process %d", ptid_get_pid (ptid
));
2775 dummy_pid_to_str (struct target_ops
*ops
, ptid_t ptid
)
2777 return normal_pid_to_str (ptid
);
2780 /* Error-catcher for target_find_memory_regions. */
2782 dummy_find_memory_regions (int (*ignore1
) (), void *ignore2
)
2784 error (_("Command not implemented for this target."));
2788 /* Error-catcher for target_make_corefile_notes. */
2790 dummy_make_corefile_notes (bfd
*ignore1
, int *ignore2
)
2792 error (_("Command not implemented for this target."));
2796 /* Error-catcher for target_get_bookmark. */
2798 dummy_get_bookmark (char *ignore1
, int ignore2
)
2804 /* Error-catcher for target_goto_bookmark. */
2806 dummy_goto_bookmark (gdb_byte
*ignore
, int from_tty
)
2811 /* Set up the handful of non-empty slots needed by the dummy target
2815 init_dummy_target (void)
2817 dummy_target
.to_shortname
= "None";
2818 dummy_target
.to_longname
= "None";
2819 dummy_target
.to_doc
= "";
2820 dummy_target
.to_attach
= find_default_attach
;
2821 dummy_target
.to_detach
=
2822 (void (*)(struct target_ops
*, char *, int))target_ignore
;
2823 dummy_target
.to_create_inferior
= find_default_create_inferior
;
2824 dummy_target
.to_can_async_p
= find_default_can_async_p
;
2825 dummy_target
.to_is_async_p
= find_default_is_async_p
;
2826 dummy_target
.to_supports_non_stop
= find_default_supports_non_stop
;
2827 dummy_target
.to_pid_to_str
= dummy_pid_to_str
;
2828 dummy_target
.to_stratum
= dummy_stratum
;
2829 dummy_target
.to_find_memory_regions
= dummy_find_memory_regions
;
2830 dummy_target
.to_make_corefile_notes
= dummy_make_corefile_notes
;
2831 dummy_target
.to_get_bookmark
= dummy_get_bookmark
;
2832 dummy_target
.to_goto_bookmark
= dummy_goto_bookmark
;
2833 dummy_target
.to_xfer_partial
= default_xfer_partial
;
2834 dummy_target
.to_has_all_memory
= (int (*) (struct target_ops
*)) return_zero
;
2835 dummy_target
.to_has_memory
= (int (*) (struct target_ops
*)) return_zero
;
2836 dummy_target
.to_has_stack
= (int (*) (struct target_ops
*)) return_zero
;
2837 dummy_target
.to_has_registers
= (int (*) (struct target_ops
*)) return_zero
;
2838 dummy_target
.to_has_execution
= (int (*) (struct target_ops
*)) return_zero
;
2839 dummy_target
.to_magic
= OPS_MAGIC
;
2843 debug_to_open (char *args
, int from_tty
)
2845 debug_target
.to_open (args
, from_tty
);
2847 fprintf_unfiltered (gdb_stdlog
, "target_open (%s, %d)\n", args
, from_tty
);
2851 target_close (struct target_ops
*targ
, int quitting
)
2853 if (targ
->to_xclose
!= NULL
)
2854 targ
->to_xclose (targ
, quitting
);
2855 else if (targ
->to_close
!= NULL
)
2856 targ
->to_close (quitting
);
2859 fprintf_unfiltered (gdb_stdlog
, "target_close (%d)\n", quitting
);
2863 target_attach (char *args
, int from_tty
)
2865 struct target_ops
*t
;
2866 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
2868 if (t
->to_attach
!= NULL
)
2870 t
->to_attach (t
, args
, from_tty
);
2872 fprintf_unfiltered (gdb_stdlog
, "target_attach (%s, %d)\n",
2878 internal_error (__FILE__
, __LINE__
,
2879 "could not find a target to attach");
2883 target_thread_alive (ptid_t ptid
)
2885 struct target_ops
*t
;
2886 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
2888 if (t
->to_thread_alive
!= NULL
)
2892 retval
= t
->to_thread_alive (t
, ptid
);
2894 fprintf_unfiltered (gdb_stdlog
, "target_thread_alive (%d) = %d\n",
2895 PIDGET (ptid
), retval
);
2905 target_find_new_threads (void)
2907 struct target_ops
*t
;
2908 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
2910 if (t
->to_find_new_threads
!= NULL
)
2912 t
->to_find_new_threads (t
);
2914 fprintf_unfiltered (gdb_stdlog
, "target_find_new_threads ()\n");
2922 debug_to_post_attach (int pid
)
2924 debug_target
.to_post_attach (pid
);
2926 fprintf_unfiltered (gdb_stdlog
, "target_post_attach (%d)\n", pid
);
2929 /* Return a pretty printed form of target_waitstatus.
2930 Space for the result is malloc'd, caller must free. */
2933 target_waitstatus_to_string (const struct target_waitstatus
*ws
)
2935 const char *kind_str
= "status->kind = ";
2939 case TARGET_WAITKIND_EXITED
:
2940 return xstrprintf ("%sexited, status = %d",
2941 kind_str
, ws
->value
.integer
);
2942 case TARGET_WAITKIND_STOPPED
:
2943 return xstrprintf ("%sstopped, signal = %s",
2944 kind_str
, target_signal_to_name (ws
->value
.sig
));
2945 case TARGET_WAITKIND_SIGNALLED
:
2946 return xstrprintf ("%ssignalled, signal = %s",
2947 kind_str
, target_signal_to_name (ws
->value
.sig
));
2948 case TARGET_WAITKIND_LOADED
:
2949 return xstrprintf ("%sloaded", kind_str
);
2950 case TARGET_WAITKIND_FORKED
:
2951 return xstrprintf ("%sforked", kind_str
);
2952 case TARGET_WAITKIND_VFORKED
:
2953 return xstrprintf ("%svforked", kind_str
);
2954 case TARGET_WAITKIND_EXECD
:
2955 return xstrprintf ("%sexecd", kind_str
);
2956 case TARGET_WAITKIND_SYSCALL_ENTRY
:
2957 return xstrprintf ("%sentered syscall", kind_str
);
2958 case TARGET_WAITKIND_SYSCALL_RETURN
:
2959 return xstrprintf ("%sexited syscall", kind_str
);
2960 case TARGET_WAITKIND_SPURIOUS
:
2961 return xstrprintf ("%sspurious", kind_str
);
2962 case TARGET_WAITKIND_IGNORE
:
2963 return xstrprintf ("%signore", kind_str
);
2964 case TARGET_WAITKIND_NO_HISTORY
:
2965 return xstrprintf ("%sno-history", kind_str
);
2967 return xstrprintf ("%sunknown???", kind_str
);
2972 debug_print_register (const char * func
,
2973 struct regcache
*regcache
, int regno
)
2975 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
2976 fprintf_unfiltered (gdb_stdlog
, "%s ", func
);
2977 if (regno
>= 0 && regno
< gdbarch_num_regs (gdbarch
)
2978 && gdbarch_register_name (gdbarch
, regno
) != NULL
2979 && gdbarch_register_name (gdbarch
, regno
)[0] != '\0')
2980 fprintf_unfiltered (gdb_stdlog
, "(%s)",
2981 gdbarch_register_name (gdbarch
, regno
));
2983 fprintf_unfiltered (gdb_stdlog
, "(%d)", regno
);
2984 if (regno
>= 0 && regno
< gdbarch_num_regs (gdbarch
))
2986 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
2987 int i
, size
= register_size (gdbarch
, regno
);
2988 unsigned char buf
[MAX_REGISTER_SIZE
];
2989 regcache_raw_collect (regcache
, regno
, buf
);
2990 fprintf_unfiltered (gdb_stdlog
, " = ");
2991 for (i
= 0; i
< size
; i
++)
2993 fprintf_unfiltered (gdb_stdlog
, "%02x", buf
[i
]);
2995 if (size
<= sizeof (LONGEST
))
2997 ULONGEST val
= extract_unsigned_integer (buf
, size
, byte_order
);
2998 fprintf_unfiltered (gdb_stdlog
, " %s %s",
2999 core_addr_to_string_nz (val
), plongest (val
));
3002 fprintf_unfiltered (gdb_stdlog
, "\n");
3006 target_fetch_registers (struct regcache
*regcache
, int regno
)
3008 struct target_ops
*t
;
3009 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
3011 if (t
->to_fetch_registers
!= NULL
)
3013 t
->to_fetch_registers (t
, regcache
, regno
);
3015 debug_print_register ("target_fetch_registers", regcache
, regno
);
3022 target_store_registers (struct regcache
*regcache
, int regno
)
3025 struct target_ops
*t
;
3026 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
3028 if (t
->to_store_registers
!= NULL
)
3030 t
->to_store_registers (t
, regcache
, regno
);
3033 debug_print_register ("target_store_registers", regcache
, regno
);
3043 target_core_of_thread (ptid_t ptid
)
3045 struct target_ops
*t
;
3047 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
3049 if (t
->to_core_of_thread
!= NULL
)
3051 int retval
= t
->to_core_of_thread (t
, ptid
);
3053 fprintf_unfiltered (gdb_stdlog
, "target_core_of_thread (%d) = %d\n",
3054 PIDGET (ptid
), retval
);
3063 debug_to_prepare_to_store (struct regcache
*regcache
)
3065 debug_target
.to_prepare_to_store (regcache
);
3067 fprintf_unfiltered (gdb_stdlog
, "target_prepare_to_store ()\n");
3071 deprecated_debug_xfer_memory (CORE_ADDR memaddr
, bfd_byte
*myaddr
, int len
,
3072 int write
, struct mem_attrib
*attrib
,
3073 struct target_ops
*target
)
3077 retval
= debug_target
.deprecated_xfer_memory (memaddr
, myaddr
, len
, write
,
3080 fprintf_unfiltered (gdb_stdlog
,
3081 "target_xfer_memory (%s, xxx, %d, %s, xxx) = %d",
3082 paddress (target_gdbarch
, memaddr
), len
,
3083 write
? "write" : "read", retval
);
3089 fputs_unfiltered (", bytes =", gdb_stdlog
);
3090 for (i
= 0; i
< retval
; i
++)
3092 if ((((intptr_t) &(myaddr
[i
])) & 0xf) == 0)
3094 if (targetdebug
< 2 && i
> 0)
3096 fprintf_unfiltered (gdb_stdlog
, " ...");
3099 fprintf_unfiltered (gdb_stdlog
, "\n");
3102 fprintf_unfiltered (gdb_stdlog
, " %02x", myaddr
[i
] & 0xff);
3106 fputc_unfiltered ('\n', gdb_stdlog
);
3112 debug_to_files_info (struct target_ops
*target
)
3114 debug_target
.to_files_info (target
);
3116 fprintf_unfiltered (gdb_stdlog
, "target_files_info (xxx)\n");
3120 debug_to_insert_breakpoint (struct gdbarch
*gdbarch
,
3121 struct bp_target_info
*bp_tgt
)
3125 retval
= debug_target
.to_insert_breakpoint (gdbarch
, bp_tgt
);
3127 fprintf_unfiltered (gdb_stdlog
,
3128 "target_insert_breakpoint (0x%lx, xxx) = %ld\n",
3129 (unsigned long) bp_tgt
->placed_address
,
3130 (unsigned long) retval
);
3135 debug_to_remove_breakpoint (struct gdbarch
*gdbarch
,
3136 struct bp_target_info
*bp_tgt
)
3140 retval
= debug_target
.to_remove_breakpoint (gdbarch
, bp_tgt
);
3142 fprintf_unfiltered (gdb_stdlog
,
3143 "target_remove_breakpoint (0x%lx, xxx) = %ld\n",
3144 (unsigned long) bp_tgt
->placed_address
,
3145 (unsigned long) retval
);
3150 debug_to_can_use_hw_breakpoint (int type
, int cnt
, int from_tty
)
3154 retval
= debug_target
.to_can_use_hw_breakpoint (type
, cnt
, from_tty
);
3156 fprintf_unfiltered (gdb_stdlog
,
3157 "target_can_use_hw_breakpoint (%ld, %ld, %ld) = %ld\n",
3158 (unsigned long) type
,
3159 (unsigned long) cnt
,
3160 (unsigned long) from_tty
,
3161 (unsigned long) retval
);
3166 debug_to_region_ok_for_hw_watchpoint (CORE_ADDR addr
, int len
)
3170 retval
= debug_target
.to_region_ok_for_hw_watchpoint (addr
, len
);
3172 fprintf_unfiltered (gdb_stdlog
,
3173 "target_region_ok_for_hw_watchpoint (%ld, %ld) = 0x%lx\n",
3174 (unsigned long) addr
,
3175 (unsigned long) len
,
3176 (unsigned long) retval
);
3181 debug_to_stopped_by_watchpoint (void)
3185 retval
= debug_target
.to_stopped_by_watchpoint ();
3187 fprintf_unfiltered (gdb_stdlog
,
3188 "target_stopped_by_watchpoint () = %ld\n",
3189 (unsigned long) retval
);
3194 debug_to_stopped_data_address (struct target_ops
*target
, CORE_ADDR
*addr
)
3198 retval
= debug_target
.to_stopped_data_address (target
, addr
);
3200 fprintf_unfiltered (gdb_stdlog
,
3201 "target_stopped_data_address ([0x%lx]) = %ld\n",
3202 (unsigned long)*addr
,
3203 (unsigned long)retval
);
3208 debug_to_watchpoint_addr_within_range (struct target_ops
*target
,
3210 CORE_ADDR start
, int length
)
3214 retval
= debug_target
.to_watchpoint_addr_within_range (target
, addr
,
3217 fprintf_filtered (gdb_stdlog
,
3218 "target_watchpoint_addr_within_range (0x%lx, 0x%lx, %d) = %d\n",
3219 (unsigned long) addr
, (unsigned long) start
, length
,
3225 debug_to_insert_hw_breakpoint (struct gdbarch
*gdbarch
,
3226 struct bp_target_info
*bp_tgt
)
3230 retval
= debug_target
.to_insert_hw_breakpoint (gdbarch
, bp_tgt
);
3232 fprintf_unfiltered (gdb_stdlog
,
3233 "target_insert_hw_breakpoint (0x%lx, xxx) = %ld\n",
3234 (unsigned long) bp_tgt
->placed_address
,
3235 (unsigned long) retval
);
3240 debug_to_remove_hw_breakpoint (struct gdbarch
*gdbarch
,
3241 struct bp_target_info
*bp_tgt
)
3245 retval
= debug_target
.to_remove_hw_breakpoint (gdbarch
, bp_tgt
);
3247 fprintf_unfiltered (gdb_stdlog
,
3248 "target_remove_hw_breakpoint (0x%lx, xxx) = %ld\n",
3249 (unsigned long) bp_tgt
->placed_address
,
3250 (unsigned long) retval
);
3255 debug_to_insert_watchpoint (CORE_ADDR addr
, int len
, int type
)
3259 retval
= debug_target
.to_insert_watchpoint (addr
, len
, type
);
3261 fprintf_unfiltered (gdb_stdlog
,
3262 "target_insert_watchpoint (0x%lx, %d, %d) = %ld\n",
3263 (unsigned long) addr
, len
, type
, (unsigned long) retval
);
3268 debug_to_remove_watchpoint (CORE_ADDR addr
, int len
, int type
)
3272 retval
= debug_target
.to_remove_watchpoint (addr
, len
, type
);
3274 fprintf_unfiltered (gdb_stdlog
,
3275 "target_remove_watchpoint (0x%lx, %d, %d) = %ld\n",
3276 (unsigned long) addr
, len
, type
, (unsigned long) retval
);
3281 debug_to_terminal_init (void)
3283 debug_target
.to_terminal_init ();
3285 fprintf_unfiltered (gdb_stdlog
, "target_terminal_init ()\n");
3289 debug_to_terminal_inferior (void)
3291 debug_target
.to_terminal_inferior ();
3293 fprintf_unfiltered (gdb_stdlog
, "target_terminal_inferior ()\n");
3297 debug_to_terminal_ours_for_output (void)
3299 debug_target
.to_terminal_ours_for_output ();
3301 fprintf_unfiltered (gdb_stdlog
, "target_terminal_ours_for_output ()\n");
3305 debug_to_terminal_ours (void)
3307 debug_target
.to_terminal_ours ();
3309 fprintf_unfiltered (gdb_stdlog
, "target_terminal_ours ()\n");
3313 debug_to_terminal_save_ours (void)
3315 debug_target
.to_terminal_save_ours ();
3317 fprintf_unfiltered (gdb_stdlog
, "target_terminal_save_ours ()\n");
3321 debug_to_terminal_info (char *arg
, int from_tty
)
3323 debug_target
.to_terminal_info (arg
, from_tty
);
3325 fprintf_unfiltered (gdb_stdlog
, "target_terminal_info (%s, %d)\n", arg
,
3330 debug_to_load (char *args
, int from_tty
)
3332 debug_target
.to_load (args
, from_tty
);
3334 fprintf_unfiltered (gdb_stdlog
, "target_load (%s, %d)\n", args
, from_tty
);
3338 debug_to_lookup_symbol (char *name
, CORE_ADDR
*addrp
)
3342 retval
= debug_target
.to_lookup_symbol (name
, addrp
);
3344 fprintf_unfiltered (gdb_stdlog
, "target_lookup_symbol (%s, xxx)\n", name
);
3350 debug_to_post_startup_inferior (ptid_t ptid
)
3352 debug_target
.to_post_startup_inferior (ptid
);
3354 fprintf_unfiltered (gdb_stdlog
, "target_post_startup_inferior (%d)\n",
3359 debug_to_acknowledge_created_inferior (int pid
)
3361 debug_target
.to_acknowledge_created_inferior (pid
);
3363 fprintf_unfiltered (gdb_stdlog
, "target_acknowledge_created_inferior (%d)\n",
3368 debug_to_insert_fork_catchpoint (int pid
)
3370 debug_target
.to_insert_fork_catchpoint (pid
);
3372 fprintf_unfiltered (gdb_stdlog
, "target_insert_fork_catchpoint (%d)\n",
3377 debug_to_remove_fork_catchpoint (int pid
)
3381 retval
= debug_target
.to_remove_fork_catchpoint (pid
);
3383 fprintf_unfiltered (gdb_stdlog
, "target_remove_fork_catchpoint (%d) = %d\n",
3390 debug_to_insert_vfork_catchpoint (int pid
)
3392 debug_target
.to_insert_vfork_catchpoint (pid
);
3394 fprintf_unfiltered (gdb_stdlog
, "target_insert_vfork_catchpoint (%d)\n",
3399 debug_to_remove_vfork_catchpoint (int pid
)
3403 retval
= debug_target
.to_remove_vfork_catchpoint (pid
);
3405 fprintf_unfiltered (gdb_stdlog
, "target_remove_vfork_catchpoint (%d) = %d\n",
3412 debug_to_insert_exec_catchpoint (int pid
)
3414 debug_target
.to_insert_exec_catchpoint (pid
);
3416 fprintf_unfiltered (gdb_stdlog
, "target_insert_exec_catchpoint (%d)\n",
3421 debug_to_remove_exec_catchpoint (int pid
)
3425 retval
= debug_target
.to_remove_exec_catchpoint (pid
);
3427 fprintf_unfiltered (gdb_stdlog
, "target_remove_exec_catchpoint (%d) = %d\n",
3434 debug_to_has_exited (int pid
, int wait_status
, int *exit_status
)
3438 has_exited
= debug_target
.to_has_exited (pid
, wait_status
, exit_status
);
3440 fprintf_unfiltered (gdb_stdlog
, "target_has_exited (%d, %d, %d) = %d\n",
3441 pid
, wait_status
, *exit_status
, has_exited
);
3447 debug_to_can_run (void)
3451 retval
= debug_target
.to_can_run ();
3453 fprintf_unfiltered (gdb_stdlog
, "target_can_run () = %d\n", retval
);
3459 debug_to_notice_signals (ptid_t ptid
)
3461 debug_target
.to_notice_signals (ptid
);
3463 fprintf_unfiltered (gdb_stdlog
, "target_notice_signals (%d)\n",
3467 static struct gdbarch
*
3468 debug_to_thread_architecture (struct target_ops
*ops
, ptid_t ptid
)
3470 struct gdbarch
*retval
;
3472 retval
= debug_target
.to_thread_architecture (ops
, ptid
);
3474 fprintf_unfiltered (gdb_stdlog
, "target_thread_architecture (%s) = %s [%s]\n",
3475 target_pid_to_str (ptid
), host_address_to_string (retval
),
3476 gdbarch_bfd_arch_info (retval
)->printable_name
);
3481 debug_to_stop (ptid_t ptid
)
3483 debug_target
.to_stop (ptid
);
3485 fprintf_unfiltered (gdb_stdlog
, "target_stop (%s)\n",
3486 target_pid_to_str (ptid
));
3490 debug_to_rcmd (char *command
,
3491 struct ui_file
*outbuf
)
3493 debug_target
.to_rcmd (command
, outbuf
);
3494 fprintf_unfiltered (gdb_stdlog
, "target_rcmd (%s, ...)\n", command
);
3498 debug_to_pid_to_exec_file (int pid
)
3502 exec_file
= debug_target
.to_pid_to_exec_file (pid
);
3504 fprintf_unfiltered (gdb_stdlog
, "target_pid_to_exec_file (%d) = %s\n",
3511 setup_target_debug (void)
3513 memcpy (&debug_target
, ¤t_target
, sizeof debug_target
);
3515 current_target
.to_open
= debug_to_open
;
3516 current_target
.to_post_attach
= debug_to_post_attach
;
3517 current_target
.to_prepare_to_store
= debug_to_prepare_to_store
;
3518 current_target
.deprecated_xfer_memory
= deprecated_debug_xfer_memory
;
3519 current_target
.to_files_info
= debug_to_files_info
;
3520 current_target
.to_insert_breakpoint
= debug_to_insert_breakpoint
;
3521 current_target
.to_remove_breakpoint
= debug_to_remove_breakpoint
;
3522 current_target
.to_can_use_hw_breakpoint
= debug_to_can_use_hw_breakpoint
;
3523 current_target
.to_insert_hw_breakpoint
= debug_to_insert_hw_breakpoint
;
3524 current_target
.to_remove_hw_breakpoint
= debug_to_remove_hw_breakpoint
;
3525 current_target
.to_insert_watchpoint
= debug_to_insert_watchpoint
;
3526 current_target
.to_remove_watchpoint
= debug_to_remove_watchpoint
;
3527 current_target
.to_stopped_by_watchpoint
= debug_to_stopped_by_watchpoint
;
3528 current_target
.to_stopped_data_address
= debug_to_stopped_data_address
;
3529 current_target
.to_watchpoint_addr_within_range
= debug_to_watchpoint_addr_within_range
;
3530 current_target
.to_region_ok_for_hw_watchpoint
= debug_to_region_ok_for_hw_watchpoint
;
3531 current_target
.to_terminal_init
= debug_to_terminal_init
;
3532 current_target
.to_terminal_inferior
= debug_to_terminal_inferior
;
3533 current_target
.to_terminal_ours_for_output
= debug_to_terminal_ours_for_output
;
3534 current_target
.to_terminal_ours
= debug_to_terminal_ours
;
3535 current_target
.to_terminal_save_ours
= debug_to_terminal_save_ours
;
3536 current_target
.to_terminal_info
= debug_to_terminal_info
;
3537 current_target
.to_load
= debug_to_load
;
3538 current_target
.to_lookup_symbol
= debug_to_lookup_symbol
;
3539 current_target
.to_post_startup_inferior
= debug_to_post_startup_inferior
;
3540 current_target
.to_acknowledge_created_inferior
= debug_to_acknowledge_created_inferior
;
3541 current_target
.to_insert_fork_catchpoint
= debug_to_insert_fork_catchpoint
;
3542 current_target
.to_remove_fork_catchpoint
= debug_to_remove_fork_catchpoint
;
3543 current_target
.to_insert_vfork_catchpoint
= debug_to_insert_vfork_catchpoint
;
3544 current_target
.to_remove_vfork_catchpoint
= debug_to_remove_vfork_catchpoint
;
3545 current_target
.to_insert_exec_catchpoint
= debug_to_insert_exec_catchpoint
;
3546 current_target
.to_remove_exec_catchpoint
= debug_to_remove_exec_catchpoint
;
3547 current_target
.to_has_exited
= debug_to_has_exited
;
3548 current_target
.to_can_run
= debug_to_can_run
;
3549 current_target
.to_notice_signals
= debug_to_notice_signals
;
3550 current_target
.to_stop
= debug_to_stop
;
3551 current_target
.to_rcmd
= debug_to_rcmd
;
3552 current_target
.to_pid_to_exec_file
= debug_to_pid_to_exec_file
;
3553 current_target
.to_thread_architecture
= debug_to_thread_architecture
;
3557 static char targ_desc
[] =
3558 "Names of targets and files being debugged.\n\
3559 Shows the entire stack of targets currently in use (including the exec-file,\n\
3560 core-file, and process, if any), as well as the symbol file name.";
3563 do_monitor_command (char *cmd
,
3566 if ((current_target
.to_rcmd
3567 == (void (*) (char *, struct ui_file
*)) tcomplain
)
3568 || (current_target
.to_rcmd
== debug_to_rcmd
3569 && (debug_target
.to_rcmd
3570 == (void (*) (char *, struct ui_file
*)) tcomplain
)))
3571 error (_("\"monitor\" command not supported by this target."));
3572 target_rcmd (cmd
, gdb_stdtarg
);
3575 /* Print the name of each layers of our target stack. */
3578 maintenance_print_target_stack (char *cmd
, int from_tty
)
3580 struct target_ops
*t
;
3582 printf_filtered (_("The current target stack is:\n"));
3584 for (t
= target_stack
; t
!= NULL
; t
= t
->beneath
)
3586 printf_filtered (" - %s (%s)\n", t
->to_shortname
, t
->to_longname
);
3590 /* Controls if async mode is permitted. */
3591 int target_async_permitted
= 0;
3593 /* The set command writes to this variable. If the inferior is
3594 executing, linux_nat_async_permitted is *not* updated. */
3595 static int target_async_permitted_1
= 0;
3598 set_maintenance_target_async_permitted (char *args
, int from_tty
,
3599 struct cmd_list_element
*c
)
3601 if (have_live_inferiors ())
3603 target_async_permitted_1
= target_async_permitted
;
3604 error (_("Cannot change this setting while the inferior is running."));
3607 target_async_permitted
= target_async_permitted_1
;
3611 show_maintenance_target_async_permitted (struct ui_file
*file
, int from_tty
,
3612 struct cmd_list_element
*c
,
3615 fprintf_filtered (file
, _("\
3616 Controlling the inferior in asynchronous mode is %s.\n"), value
);
3620 initialize_targets (void)
3622 init_dummy_target ();
3623 push_target (&dummy_target
);
3625 add_info ("target", target_info
, targ_desc
);
3626 add_info ("files", target_info
, targ_desc
);
3628 add_setshow_zinteger_cmd ("target", class_maintenance
, &targetdebug
, _("\
3629 Set target debugging."), _("\
3630 Show target debugging."), _("\
3631 When non-zero, target debugging is enabled. Higher numbers are more\n\
3632 verbose. Changes do not take effect until the next \"run\" or \"target\"\n\
3636 &setdebuglist
, &showdebuglist
);
3638 add_setshow_boolean_cmd ("trust-readonly-sections", class_support
,
3639 &trust_readonly
, _("\
3640 Set mode for reading from readonly sections."), _("\
3641 Show mode for reading from readonly sections."), _("\
3642 When this mode is on, memory reads from readonly sections (such as .text)\n\
3643 will be read from the object file instead of from the target. This will\n\
3644 result in significant performance improvement for remote targets."),
3646 show_trust_readonly
,
3647 &setlist
, &showlist
);
3649 add_com ("monitor", class_obscure
, do_monitor_command
,
3650 _("Send a command to the remote monitor (remote targets only)."));
3652 add_cmd ("target-stack", class_maintenance
, maintenance_print_target_stack
,
3653 _("Print the name of each layer of the internal target stack."),
3654 &maintenanceprintlist
);
3656 add_setshow_boolean_cmd ("target-async", no_class
,
3657 &target_async_permitted_1
, _("\
3658 Set whether gdb controls the inferior in asynchronous mode."), _("\
3659 Show whether gdb controls the inferior in asynchronous mode."), _("\
3660 Tells gdb whether to control the inferior in asynchronous mode."),
3661 set_maintenance_target_async_permitted
,
3662 show_maintenance_target_async_permitted
,
3666 add_setshow_boolean_cmd ("stack-cache", class_support
,
3667 &stack_cache_enabled_p_1
, _("\
3668 Set cache use for stack access."), _("\
3669 Show cache use for stack access."), _("\
3670 When on, use the data cache for all stack access, regardless of any\n\
3671 configured memory regions. This improves remote performance significantly.\n\
3672 By default, caching for stack access is on."),
3673 set_stack_cache_enabled_p
,
3674 show_stack_cache_enabled_p
,
3675 &setlist
, &showlist
);
3677 target_dcache
= dcache_init ();