1 /* Select target systems and architectures at runtime for GDB.
3 Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
4 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006
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 2 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, write to the Free Software
23 Foundation, Inc., 51 Franklin Street, Fifth Floor,
24 Boston, MA 02110-1301, USA. */
28 #include "gdb_string.h"
40 #include "gdb_assert.h"
42 #include "exceptions.h"
44 static void target_info (char *, int);
46 static void maybe_kill_then_attach (char *, int);
48 static void kill_or_be_killed (int);
50 static void default_terminal_info (char *, int);
52 static int default_region_ok_for_hw_watchpoint (CORE_ADDR
, int);
54 static int nosymbol (char *, CORE_ADDR
*);
56 static void tcomplain (void) ATTR_NORETURN
;
58 static int nomemory (CORE_ADDR
, char *, int, int, struct target_ops
*);
60 static int return_zero (void);
62 static int return_one (void);
64 static int return_minus_one (void);
66 void target_ignore (void);
68 static void target_command (char *, int);
70 static struct target_ops
*find_default_run_target (char *);
72 static void nosupport_runtime (void);
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 void init_dummy_target (void);
94 static struct target_ops debug_target
;
96 static void debug_to_open (char *, int);
98 static void debug_to_close (int);
100 static void debug_to_attach (char *, int);
102 static void debug_to_detach (char *, int);
104 static void debug_to_resume (ptid_t
, int, enum target_signal
);
106 static ptid_t
debug_to_wait (ptid_t
, struct target_waitstatus
*);
108 static void debug_to_fetch_registers (int);
110 static void debug_to_store_registers (int);
112 static void debug_to_prepare_to_store (void);
114 static void debug_to_files_info (struct target_ops
*);
116 static int debug_to_insert_breakpoint (struct bp_target_info
*);
118 static int debug_to_remove_breakpoint (struct bp_target_info
*);
120 static int debug_to_can_use_hw_breakpoint (int, int, int);
122 static int debug_to_insert_hw_breakpoint (struct bp_target_info
*);
124 static int debug_to_remove_hw_breakpoint (struct bp_target_info
*);
126 static int debug_to_insert_watchpoint (CORE_ADDR
, int, int);
128 static int debug_to_remove_watchpoint (CORE_ADDR
, int, int);
130 static int debug_to_stopped_by_watchpoint (void);
132 static int debug_to_stopped_data_address (struct target_ops
*, CORE_ADDR
*);
134 static int debug_to_region_ok_for_hw_watchpoint (CORE_ADDR
, int);
136 static void debug_to_terminal_init (void);
138 static void debug_to_terminal_inferior (void);
140 static void debug_to_terminal_ours_for_output (void);
142 static void debug_to_terminal_save_ours (void);
144 static void debug_to_terminal_ours (void);
146 static void debug_to_terminal_info (char *, int);
148 static void debug_to_kill (void);
150 static void debug_to_load (char *, int);
152 static int debug_to_lookup_symbol (char *, CORE_ADDR
*);
154 static void debug_to_mourn_inferior (void);
156 static int debug_to_can_run (void);
158 static void debug_to_notice_signals (ptid_t
);
160 static int debug_to_thread_alive (ptid_t
);
162 static void debug_to_stop (void);
164 /* NOTE: cagney/2004-09-29: Many targets reference this variable in
165 wierd and mysterious ways. Putting the variable here lets those
166 wierd and mysterious ways keep building while they are being
167 converted to the inferior inheritance structure. */
168 struct target_ops deprecated_child_ops
;
170 /* Pointer to array of target architecture structures; the size of the
171 array; the current index into the array; the allocated size of the
173 struct target_ops
**target_structs
;
174 unsigned target_struct_size
;
175 unsigned target_struct_index
;
176 unsigned target_struct_allocsize
;
177 #define DEFAULT_ALLOCSIZE 10
179 /* The initial current target, so that there is always a semi-valid
182 static struct target_ops dummy_target
;
184 /* Top of target stack. */
186 static struct target_ops
*target_stack
;
188 /* The target structure we are currently using to talk to a process
189 or file or whatever "inferior" we have. */
191 struct target_ops current_target
;
193 /* Command list for target. */
195 static struct cmd_list_element
*targetlist
= NULL
;
197 /* Nonzero if we are debugging an attached outside process
198 rather than an inferior. */
202 /* Nonzero if we should trust readonly sections from the
203 executable when reading memory. */
205 static int trust_readonly
= 0;
207 /* Non-zero if we want to see trace of target level stuff. */
209 static int targetdebug
= 0;
211 show_targetdebug (struct ui_file
*file
, int from_tty
,
212 struct cmd_list_element
*c
, const char *value
)
214 fprintf_filtered (file
, _("Target debugging is %s.\n"), value
);
217 static void setup_target_debug (void);
219 DCACHE
*target_dcache
;
221 /* The user just typed 'target' without the name of a target. */
224 target_command (char *arg
, int from_tty
)
226 fputs_filtered ("Argument required (target name). Try `help target'\n",
230 /* Add a possible target architecture to the list. */
233 add_target (struct target_ops
*t
)
235 /* Provide default values for all "must have" methods. */
236 if (t
->to_xfer_partial
== NULL
)
237 t
->to_xfer_partial
= default_xfer_partial
;
241 target_struct_allocsize
= DEFAULT_ALLOCSIZE
;
242 target_structs
= (struct target_ops
**) xmalloc
243 (target_struct_allocsize
* sizeof (*target_structs
));
245 if (target_struct_size
>= target_struct_allocsize
)
247 target_struct_allocsize
*= 2;
248 target_structs
= (struct target_ops
**)
249 xrealloc ((char *) target_structs
,
250 target_struct_allocsize
* sizeof (*target_structs
));
252 target_structs
[target_struct_size
++] = t
;
254 if (targetlist
== NULL
)
255 add_prefix_cmd ("target", class_run
, target_command
, _("\
256 Connect to a target machine or process.\n\
257 The first argument is the type or protocol of the target machine.\n\
258 Remaining arguments are interpreted by the target protocol. For more\n\
259 information on the arguments for a particular protocol, type\n\
260 `help target ' followed by the protocol name."),
261 &targetlist
, "target ", 0, &cmdlist
);
262 add_cmd (t
->to_shortname
, no_class
, t
->to_open
, t
->to_doc
, &targetlist
);
273 target_load (char *arg
, int from_tty
)
275 dcache_invalidate (target_dcache
);
276 (*current_target
.to_load
) (arg
, from_tty
);
280 nomemory (CORE_ADDR memaddr
, char *myaddr
, int len
, int write
,
281 struct target_ops
*t
)
283 errno
= EIO
; /* Can't read/write this location */
284 return 0; /* No bytes handled */
290 error (_("You can't do that when your target is `%s'"),
291 current_target
.to_shortname
);
297 error (_("You can't do that without a process to debug."));
301 nosymbol (char *name
, CORE_ADDR
*addrp
)
303 return 1; /* Symbol does not exist in target env */
307 nosupport_runtime (void)
309 if (ptid_equal (inferior_ptid
, null_ptid
))
312 error (_("No run-time support for this"));
317 default_terminal_info (char *args
, int from_tty
)
319 printf_unfiltered (_("No saved terminal information.\n"));
322 /* This is the default target_create_inferior and target_attach function.
323 If the current target is executing, it asks whether to kill it off.
324 If this function returns without calling error(), it has killed off
325 the target, and the operation should be attempted. */
328 kill_or_be_killed (int from_tty
)
330 if (target_has_execution
)
332 printf_unfiltered (_("You are already running a program:\n"));
333 target_files_info ();
334 if (query ("Kill it? "))
337 if (target_has_execution
)
338 error (_("Killing the program did not help."));
343 error (_("Program not killed."));
350 maybe_kill_then_attach (char *args
, int from_tty
)
352 kill_or_be_killed (from_tty
);
353 target_attach (args
, from_tty
);
357 maybe_kill_then_create_inferior (char *exec
, char *args
, char **env
,
360 kill_or_be_killed (0);
361 target_create_inferior (exec
, args
, env
, from_tty
);
364 /* Go through the target stack from top to bottom, copying over zero
365 entries in current_target, then filling in still empty entries. In
366 effect, we are doing class inheritance through the pushed target
369 NOTE: cagney/2003-10-17: The problem with this inheritance, as it
370 is currently implemented, is that it discards any knowledge of
371 which target an inherited method originally belonged to.
372 Consequently, new new target methods should instead explicitly and
373 locally search the target stack for the target that can handle the
377 update_current_target (void)
379 struct target_ops
*t
;
381 /* First, reset curren'ts contents. */
382 memset (¤t_target
, 0, sizeof (current_target
));
384 #define INHERIT(FIELD, TARGET) \
385 if (!current_target.FIELD) \
386 current_target.FIELD = (TARGET)->FIELD
388 for (t
= target_stack
; t
; t
= t
->beneath
)
390 INHERIT (to_shortname
, t
);
391 INHERIT (to_longname
, t
);
393 INHERIT (to_open
, t
);
394 INHERIT (to_close
, t
);
395 INHERIT (to_attach
, t
);
396 INHERIT (to_post_attach
, t
);
397 INHERIT (to_detach
, t
);
398 /* Do not inherit to_disconnect. */
399 INHERIT (to_resume
, t
);
400 INHERIT (to_wait
, t
);
401 INHERIT (to_fetch_registers
, t
);
402 INHERIT (to_store_registers
, t
);
403 INHERIT (to_prepare_to_store
, t
);
404 INHERIT (deprecated_xfer_memory
, t
);
405 INHERIT (to_files_info
, t
);
406 INHERIT (to_insert_breakpoint
, t
);
407 INHERIT (to_remove_breakpoint
, t
);
408 INHERIT (to_can_use_hw_breakpoint
, t
);
409 INHERIT (to_insert_hw_breakpoint
, t
);
410 INHERIT (to_remove_hw_breakpoint
, t
);
411 INHERIT (to_insert_watchpoint
, t
);
412 INHERIT (to_remove_watchpoint
, t
);
413 INHERIT (to_stopped_data_address
, t
);
414 INHERIT (to_stopped_by_watchpoint
, t
);
415 INHERIT (to_have_continuable_watchpoint
, t
);
416 INHERIT (to_region_ok_for_hw_watchpoint
, t
);
417 INHERIT (to_terminal_init
, t
);
418 INHERIT (to_terminal_inferior
, t
);
419 INHERIT (to_terminal_ours_for_output
, t
);
420 INHERIT (to_terminal_ours
, t
);
421 INHERIT (to_terminal_save_ours
, t
);
422 INHERIT (to_terminal_info
, t
);
423 INHERIT (to_kill
, t
);
424 INHERIT (to_load
, t
);
425 INHERIT (to_lookup_symbol
, t
);
426 INHERIT (to_create_inferior
, t
);
427 INHERIT (to_post_startup_inferior
, t
);
428 INHERIT (to_acknowledge_created_inferior
, t
);
429 INHERIT (to_insert_fork_catchpoint
, t
);
430 INHERIT (to_remove_fork_catchpoint
, t
);
431 INHERIT (to_insert_vfork_catchpoint
, t
);
432 INHERIT (to_remove_vfork_catchpoint
, t
);
433 /* Do not inherit to_follow_fork. */
434 INHERIT (to_insert_exec_catchpoint
, t
);
435 INHERIT (to_remove_exec_catchpoint
, t
);
436 INHERIT (to_reported_exec_events_per_exec_call
, t
);
437 INHERIT (to_has_exited
, t
);
438 INHERIT (to_mourn_inferior
, t
);
439 INHERIT (to_can_run
, t
);
440 INHERIT (to_notice_signals
, t
);
441 INHERIT (to_thread_alive
, t
);
442 INHERIT (to_find_new_threads
, t
);
443 INHERIT (to_pid_to_str
, t
);
444 INHERIT (to_extra_thread_info
, t
);
445 INHERIT (to_stop
, t
);
446 /* Do not inherit to_xfer_partial. */
447 INHERIT (to_rcmd
, t
);
448 INHERIT (to_enable_exception_callback
, t
);
449 INHERIT (to_get_current_exception_event
, t
);
450 INHERIT (to_pid_to_exec_file
, t
);
451 INHERIT (to_stratum
, t
);
452 INHERIT (to_has_all_memory
, t
);
453 INHERIT (to_has_memory
, t
);
454 INHERIT (to_has_stack
, t
);
455 INHERIT (to_has_registers
, t
);
456 INHERIT (to_has_execution
, t
);
457 INHERIT (to_has_thread_control
, t
);
458 INHERIT (to_sections
, t
);
459 INHERIT (to_sections_end
, t
);
460 INHERIT (to_can_async_p
, t
);
461 INHERIT (to_is_async_p
, t
);
462 INHERIT (to_async
, t
);
463 INHERIT (to_async_mask_value
, t
);
464 INHERIT (to_find_memory_regions
, t
);
465 INHERIT (to_make_corefile_notes
, t
);
466 INHERIT (to_get_thread_local_address
, t
);
467 INHERIT (to_magic
, t
);
468 /* Do not inherit to_memory_map. */
469 /* Do not inherit to_flash_erase. */
470 /* Do not inherit to_flash_done. */
474 /* Clean up a target struct so it no longer has any zero pointers in
475 it. Some entries are defaulted to a method that print an error,
476 others are hard-wired to a standard recursive default. */
478 #define de_fault(field, value) \
479 if (!current_target.field) \
480 current_target.field = value
483 (void (*) (char *, int))
489 maybe_kill_then_attach
);
490 de_fault (to_post_attach
,
494 (void (*) (char *, int))
497 (void (*) (ptid_t
, int, enum target_signal
))
500 (ptid_t (*) (ptid_t
, struct target_waitstatus
*))
502 de_fault (to_fetch_registers
,
505 de_fault (to_store_registers
,
508 de_fault (to_prepare_to_store
,
511 de_fault (deprecated_xfer_memory
,
512 (int (*) (CORE_ADDR
, gdb_byte
*, int, int, struct mem_attrib
*, struct target_ops
*))
514 de_fault (to_files_info
,
515 (void (*) (struct target_ops
*))
517 de_fault (to_insert_breakpoint
,
518 memory_insert_breakpoint
);
519 de_fault (to_remove_breakpoint
,
520 memory_remove_breakpoint
);
521 de_fault (to_can_use_hw_breakpoint
,
522 (int (*) (int, int, int))
524 de_fault (to_insert_hw_breakpoint
,
525 (int (*) (struct bp_target_info
*))
527 de_fault (to_remove_hw_breakpoint
,
528 (int (*) (struct bp_target_info
*))
530 de_fault (to_insert_watchpoint
,
531 (int (*) (CORE_ADDR
, int, int))
533 de_fault (to_remove_watchpoint
,
534 (int (*) (CORE_ADDR
, int, int))
536 de_fault (to_stopped_by_watchpoint
,
539 de_fault (to_stopped_data_address
,
540 (int (*) (struct target_ops
*, CORE_ADDR
*))
542 de_fault (to_region_ok_for_hw_watchpoint
,
543 default_region_ok_for_hw_watchpoint
);
544 de_fault (to_terminal_init
,
547 de_fault (to_terminal_inferior
,
550 de_fault (to_terminal_ours_for_output
,
553 de_fault (to_terminal_ours
,
556 de_fault (to_terminal_save_ours
,
559 de_fault (to_terminal_info
,
560 default_terminal_info
);
565 (void (*) (char *, int))
567 de_fault (to_lookup_symbol
,
568 (int (*) (char *, CORE_ADDR
*))
570 de_fault (to_create_inferior
,
571 maybe_kill_then_create_inferior
);
572 de_fault (to_post_startup_inferior
,
575 de_fault (to_acknowledge_created_inferior
,
578 de_fault (to_insert_fork_catchpoint
,
581 de_fault (to_remove_fork_catchpoint
,
584 de_fault (to_insert_vfork_catchpoint
,
587 de_fault (to_remove_vfork_catchpoint
,
590 de_fault (to_insert_exec_catchpoint
,
593 de_fault (to_remove_exec_catchpoint
,
596 de_fault (to_reported_exec_events_per_exec_call
,
599 de_fault (to_has_exited
,
600 (int (*) (int, int, int *))
602 de_fault (to_mourn_inferior
,
605 de_fault (to_can_run
,
607 de_fault (to_notice_signals
,
610 de_fault (to_thread_alive
,
613 de_fault (to_find_new_threads
,
616 de_fault (to_extra_thread_info
,
617 (char *(*) (struct thread_info
*))
622 current_target
.to_xfer_partial
= current_xfer_partial
;
624 (void (*) (char *, struct ui_file
*))
626 de_fault (to_enable_exception_callback
,
627 (struct symtab_and_line
* (*) (enum exception_event_kind
, int))
629 de_fault (to_get_current_exception_event
,
630 (struct exception_event_record
* (*) (void))
632 de_fault (to_pid_to_exec_file
,
635 de_fault (to_can_async_p
,
638 de_fault (to_is_async_p
,
642 (void (*) (void (*) (enum inferior_event_type
, void*), void*))
646 /* Finally, position the target-stack beneath the squashed
647 "current_target". That way code looking for a non-inherited
648 target method can quickly and simply find it. */
649 current_target
.beneath
= target_stack
;
652 /* Mark OPS as a running target. This reverses the effect
653 of target_mark_exited. */
656 target_mark_running (struct target_ops
*ops
)
658 struct target_ops
*t
;
660 for (t
= target_stack
; t
!= NULL
; t
= t
->beneath
)
664 internal_error (__FILE__
, __LINE__
,
665 "Attempted to mark unpushed target \"%s\" as running",
668 ops
->to_has_execution
= 1;
669 ops
->to_has_all_memory
= 1;
670 ops
->to_has_memory
= 1;
671 ops
->to_has_stack
= 1;
672 ops
->to_has_registers
= 1;
674 update_current_target ();
677 /* Mark OPS as a non-running target. This reverses the effect
678 of target_mark_running. */
681 target_mark_exited (struct target_ops
*ops
)
683 struct target_ops
*t
;
685 for (t
= target_stack
; t
!= NULL
; t
= t
->beneath
)
689 internal_error (__FILE__
, __LINE__
,
690 "Attempted to mark unpushed target \"%s\" as running",
693 ops
->to_has_execution
= 0;
694 ops
->to_has_all_memory
= 0;
695 ops
->to_has_memory
= 0;
696 ops
->to_has_stack
= 0;
697 ops
->to_has_registers
= 0;
699 update_current_target ();
702 /* Push a new target type into the stack of the existing target accessors,
703 possibly superseding some of the existing accessors.
705 Result is zero if the pushed target ended up on top of the stack,
706 nonzero if at least one target is on top of it.
708 Rather than allow an empty stack, we always have the dummy target at
709 the bottom stratum, so we can call the function vectors without
713 push_target (struct target_ops
*t
)
715 struct target_ops
**cur
;
717 /* Check magic number. If wrong, it probably means someone changed
718 the struct definition, but not all the places that initialize one. */
719 if (t
->to_magic
!= OPS_MAGIC
)
721 fprintf_unfiltered (gdb_stderr
,
722 "Magic number of %s target struct wrong\n",
724 internal_error (__FILE__
, __LINE__
, _("failed internal consistency check"));
727 /* Find the proper stratum to install this target in. */
728 for (cur
= &target_stack
; (*cur
) != NULL
; cur
= &(*cur
)->beneath
)
730 if ((int) (t
->to_stratum
) >= (int) (*cur
)->to_stratum
)
734 /* If there's already targets at this stratum, remove them. */
735 /* FIXME: cagney/2003-10-15: I think this should be popping all
736 targets to CUR, and not just those at this stratum level. */
737 while ((*cur
) != NULL
&& t
->to_stratum
== (*cur
)->to_stratum
)
739 /* There's already something at this stratum level. Close it,
740 and un-hook it from the stack. */
741 struct target_ops
*tmp
= (*cur
);
742 (*cur
) = (*cur
)->beneath
;
744 target_close (tmp
, 0);
747 /* We have removed all targets in our stratum, now add the new one. */
751 update_current_target ();
754 setup_target_debug ();
757 return (t
!= target_stack
);
760 /* Remove a target_ops vector from the stack, wherever it may be.
761 Return how many times it was removed (0 or 1). */
764 unpush_target (struct target_ops
*t
)
766 struct target_ops
**cur
;
767 struct target_ops
*tmp
;
769 /* Look for the specified target. Note that we assume that a target
770 can only occur once in the target stack. */
772 for (cur
= &target_stack
; (*cur
) != NULL
; cur
= &(*cur
)->beneath
)
779 return 0; /* Didn't find target_ops, quit now */
781 /* NOTE: cagney/2003-12-06: In '94 the close call was made
782 unconditional by moving it to before the above check that the
783 target was in the target stack (something about "Change the way
784 pushing and popping of targets work to support target overlays
785 and inheritance"). This doesn't make much sense - only open
786 targets should be closed. */
789 /* Unchain the target */
791 (*cur
) = (*cur
)->beneath
;
794 update_current_target ();
802 target_close (¤t_target
, 0); /* Let it clean up */
803 if (unpush_target (target_stack
) == 1)
806 fprintf_unfiltered (gdb_stderr
,
807 "pop_target couldn't find target %s\n",
808 current_target
.to_shortname
);
809 internal_error (__FILE__
, __LINE__
, _("failed internal consistency check"));
812 /* Using the objfile specified in BATON, find the address for the
813 current thread's thread-local storage with offset OFFSET. */
815 target_translate_tls_address (struct objfile
*objfile
, CORE_ADDR offset
)
817 volatile CORE_ADDR addr
= 0;
819 if (target_get_thread_local_address_p ()
820 && gdbarch_fetch_tls_load_module_address_p (current_gdbarch
))
822 ptid_t ptid
= inferior_ptid
;
823 volatile struct gdb_exception ex
;
825 TRY_CATCH (ex
, RETURN_MASK_ALL
)
829 /* Fetch the load module address for this objfile. */
830 lm_addr
= gdbarch_fetch_tls_load_module_address (current_gdbarch
,
832 /* If it's 0, throw the appropriate exception. */
834 throw_error (TLS_LOAD_MODULE_NOT_FOUND_ERROR
,
835 _("TLS load module not found"));
837 addr
= target_get_thread_local_address (ptid
, lm_addr
, offset
);
839 /* If an error occurred, print TLS related messages here. Otherwise,
840 throw the error to some higher catcher. */
843 int objfile_is_library
= (objfile
->flags
& OBJF_SHARED
);
847 case TLS_NO_LIBRARY_SUPPORT_ERROR
:
848 error (_("Cannot find thread-local variables in this thread library."));
850 case TLS_LOAD_MODULE_NOT_FOUND_ERROR
:
851 if (objfile_is_library
)
852 error (_("Cannot find shared library `%s' in dynamic"
853 " linker's load module list"), objfile
->name
);
855 error (_("Cannot find executable file `%s' in dynamic"
856 " linker's load module list"), objfile
->name
);
858 case TLS_NOT_ALLOCATED_YET_ERROR
:
859 if (objfile_is_library
)
860 error (_("The inferior has not yet allocated storage for"
861 " thread-local variables in\n"
862 "the shared library `%s'\n"
864 objfile
->name
, target_pid_to_str (ptid
));
866 error (_("The inferior has not yet allocated storage for"
867 " thread-local variables in\n"
868 "the executable `%s'\n"
870 objfile
->name
, target_pid_to_str (ptid
));
872 case TLS_GENERIC_ERROR
:
873 if (objfile_is_library
)
874 error (_("Cannot find thread-local storage for %s, "
875 "shared library %s:\n%s"),
876 target_pid_to_str (ptid
),
877 objfile
->name
, ex
.message
);
879 error (_("Cannot find thread-local storage for %s, "
880 "executable file %s:\n%s"),
881 target_pid_to_str (ptid
),
882 objfile
->name
, ex
.message
);
885 throw_exception (ex
);
890 /* It wouldn't be wrong here to try a gdbarch method, too; finding
891 TLS is an ABI-specific thing. But we don't do that yet. */
893 error (_("Cannot find thread-local variables on this target"));
899 #define MIN(A, B) (((A) <= (B)) ? (A) : (B))
901 /* target_read_string -- read a null terminated string, up to LEN bytes,
902 from MEMADDR in target. Set *ERRNOP to the errno code, or 0 if successful.
903 Set *STRING to a pointer to malloc'd memory containing the data; the caller
904 is responsible for freeing it. Return the number of bytes successfully
908 target_read_string (CORE_ADDR memaddr
, char **string
, int len
, int *errnop
)
910 int tlen
, origlen
, offset
, i
;
914 int buffer_allocated
;
916 unsigned int nbytes_read
= 0;
918 /* Small for testing. */
919 buffer_allocated
= 4;
920 buffer
= xmalloc (buffer_allocated
);
927 tlen
= MIN (len
, 4 - (memaddr
& 3));
928 offset
= memaddr
& 3;
930 errcode
= target_read_memory (memaddr
& ~3, buf
, sizeof buf
);
933 /* The transfer request might have crossed the boundary to an
934 unallocated region of memory. Retry the transfer, requesting
938 errcode
= target_read_memory (memaddr
, buf
, 1);
943 if (bufptr
- buffer
+ tlen
> buffer_allocated
)
946 bytes
= bufptr
- buffer
;
947 buffer_allocated
*= 2;
948 buffer
= xrealloc (buffer
, buffer_allocated
);
949 bufptr
= buffer
+ bytes
;
952 for (i
= 0; i
< tlen
; i
++)
954 *bufptr
++ = buf
[i
+ offset
];
955 if (buf
[i
+ offset
] == '\000')
957 nbytes_read
+= i
+ 1;
974 /* Find a section containing ADDR. */
975 struct section_table
*
976 target_section_by_addr (struct target_ops
*target
, CORE_ADDR addr
)
978 struct section_table
*secp
;
979 for (secp
= target
->to_sections
;
980 secp
< target
->to_sections_end
;
983 if (addr
>= secp
->addr
&& addr
< secp
->endaddr
)
989 /* Perform a partial memory transfer. The arguments and return
990 value are just as for target_xfer_partial. */
993 memory_xfer_partial (struct target_ops
*ops
, void *readbuf
, const void *writebuf
,
994 ULONGEST memaddr
, LONGEST len
)
998 struct mem_region
*region
;
1000 /* Zero length requests are ok and require no work. */
1004 /* Try the executable file, if "trust-readonly-sections" is set. */
1005 if (readbuf
!= NULL
&& trust_readonly
)
1007 struct section_table
*secp
;
1009 secp
= target_section_by_addr (ops
, memaddr
);
1011 && (bfd_get_section_flags (secp
->bfd
, secp
->the_bfd_section
)
1013 return xfer_memory (memaddr
, readbuf
, len
, 0, NULL
, ops
);
1016 /* Try GDB's internal data cache. */
1017 region
= lookup_mem_region (memaddr
);
1018 if (memaddr
+ len
< region
->hi
)
1021 reg_len
= region
->hi
- memaddr
;
1023 switch (region
->attrib
.mode
)
1026 if (writebuf
!= NULL
)
1031 if (readbuf
!= NULL
)
1036 /* We only support writing to flash during "load" for now. */
1037 if (writebuf
!= NULL
)
1038 error (_("Writing to flash memory forbidden in this context"));
1042 if (region
->attrib
.cache
)
1044 /* FIXME drow/2006-08-09: This call discards OPS, so the raw
1045 memory request will start back at current_target. */
1046 if (readbuf
!= NULL
)
1047 res
= dcache_xfer_memory (target_dcache
, memaddr
, readbuf
,
1050 /* FIXME drow/2006-08-09: If we're going to preserve const
1051 correctness dcache_xfer_memory should take readbuf and
1053 res
= dcache_xfer_memory (target_dcache
, memaddr
,
1062 /* If none of those methods found the memory we wanted, fall back
1063 to a target partial transfer. Normally a single call to
1064 to_xfer_partial is enough; if it doesn't recognize an object
1065 it will call the to_xfer_partial of the next target down.
1066 But for memory this won't do. Memory is the only target
1067 object which can be read from more than one valid target.
1068 A core file, for instance, could have some of memory but
1069 delegate other bits to the target below it. So, we must
1070 manually try all targets. */
1074 res
= ops
->to_xfer_partial (ops
, TARGET_OBJECT_MEMORY
, NULL
,
1075 readbuf
, writebuf
, memaddr
, len
);
1081 while (ops
!= NULL
);
1083 /* If we still haven't got anything, return the last error. We
1089 target_xfer_partial (struct target_ops
*ops
,
1090 enum target_object object
, const char *annex
,
1091 void *readbuf
, const void *writebuf
,
1092 ULONGEST offset
, LONGEST len
)
1096 gdb_assert (ops
->to_xfer_partial
!= NULL
);
1098 /* If this is a memory transfer, let the memory-specific code
1099 have a look at it instead. Memory transfers are more
1101 if (object
== TARGET_OBJECT_MEMORY
)
1102 retval
= memory_xfer_partial (ops
, readbuf
, writebuf
, offset
, len
);
1105 enum target_object raw_object
= object
;
1107 /* If this is a raw memory transfer, request the normal
1108 memory object from other layers. */
1109 if (raw_object
== TARGET_OBJECT_RAW_MEMORY
)
1110 raw_object
= TARGET_OBJECT_MEMORY
;
1112 retval
= ops
->to_xfer_partial (ops
, raw_object
, annex
, readbuf
,
1113 writebuf
, offset
, len
);
1118 const unsigned char *myaddr
= NULL
;
1120 fprintf_unfiltered (gdb_stdlog
,
1121 "%s:target_xfer_partial (%d, %s, 0x%lx, 0x%lx, 0x%s, %s) = %s",
1124 (annex
? annex
: "(null)"),
1125 (long) readbuf
, (long) writebuf
,
1126 paddr_nz (offset
), paddr_d (len
), paddr_d (retval
));
1132 if (retval
> 0 && myaddr
!= NULL
)
1136 fputs_unfiltered (", bytes =", gdb_stdlog
);
1137 for (i
= 0; i
< retval
; i
++)
1139 if ((((long) &(myaddr
[i
])) & 0xf) == 0)
1141 if (targetdebug
< 2 && i
> 0)
1143 fprintf_unfiltered (gdb_stdlog
, " ...");
1146 fprintf_unfiltered (gdb_stdlog
, "\n");
1149 fprintf_unfiltered (gdb_stdlog
, " %02x", myaddr
[i
] & 0xff);
1153 fputc_unfiltered ('\n', gdb_stdlog
);
1158 /* Read LEN bytes of target memory at address MEMADDR, placing the results in
1159 GDB's memory at MYADDR. Returns either 0 for success or an errno value
1160 if any error occurs.
1162 If an error occurs, no guarantee is made about the contents of the data at
1163 MYADDR. In particular, the caller should not depend upon partial reads
1164 filling the buffer with good data. There is no way for the caller to know
1165 how much good data might have been transfered anyway. Callers that can
1166 deal with partial reads should call target_read (which will retry until
1167 it makes no progress, and then return how much was transferred). */
1170 target_read_memory (CORE_ADDR memaddr
, gdb_byte
*myaddr
, int len
)
1172 if (target_read (¤t_target
, TARGET_OBJECT_MEMORY
, NULL
,
1173 myaddr
, memaddr
, len
) == len
)
1180 target_write_memory (CORE_ADDR memaddr
, const gdb_byte
*myaddr
, int len
)
1182 if (target_write (¤t_target
, TARGET_OBJECT_MEMORY
, NULL
,
1183 myaddr
, memaddr
, len
) == len
)
1189 /* Fetch the target's memory map. */
1192 target_memory_map (void)
1194 VEC(mem_region_s
) *result
;
1195 struct mem_region
*last_one
, *this_one
;
1197 struct target_ops
*t
;
1200 fprintf_unfiltered (gdb_stdlog
, "target_memory_map ()\n");
1202 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
1203 if (t
->to_memory_map
!= NULL
)
1209 result
= t
->to_memory_map (t
);
1213 qsort (VEC_address (mem_region_s
, result
),
1214 VEC_length (mem_region_s
, result
),
1215 sizeof (struct mem_region
), mem_region_cmp
);
1217 /* Check that regions do not overlap. Simultaneously assign
1218 a numbering for the "mem" commands to use to refer to
1221 for (ix
= 0; VEC_iterate (mem_region_s
, result
, ix
, this_one
); ix
++)
1223 this_one
->number
= ix
;
1225 if (last_one
&& last_one
->hi
> this_one
->lo
)
1227 warning (_("Overlapping regions in memory map: ignoring"));
1228 VEC_free (mem_region_s
, result
);
1231 last_one
= this_one
;
1238 target_flash_erase (ULONGEST address
, LONGEST length
)
1240 struct target_ops
*t
;
1242 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
1243 if (t
->to_flash_erase
!= NULL
)
1246 fprintf_unfiltered (gdb_stdlog
, "target_flash_erase (%s, %s)\n",
1247 paddr (address
), phex (length
, 0));
1248 return t
->to_flash_erase (t
, address
, length
);
1255 target_flash_done (void)
1257 struct target_ops
*t
;
1259 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
1260 if (t
->to_flash_done
!= NULL
)
1263 fprintf_unfiltered (gdb_stdlog
, "target_flash_done\n");
1264 return t
->to_flash_done (t
);
1270 #ifndef target_stopped_data_address_p
1272 target_stopped_data_address_p (struct target_ops
*target
)
1274 if (target
->to_stopped_data_address
1275 == (int (*) (struct target_ops
*, CORE_ADDR
*)) return_zero
)
1277 if (target
->to_stopped_data_address
== debug_to_stopped_data_address
1278 && (debug_target
.to_stopped_data_address
1279 == (int (*) (struct target_ops
*, CORE_ADDR
*)) return_zero
))
1286 show_trust_readonly (struct ui_file
*file
, int from_tty
,
1287 struct cmd_list_element
*c
, const char *value
)
1289 fprintf_filtered (file
, _("\
1290 Mode for reading from readonly sections is %s.\n"),
1294 /* More generic transfers. */
1297 default_xfer_partial (struct target_ops
*ops
, enum target_object object
,
1298 const char *annex
, gdb_byte
*readbuf
,
1299 const gdb_byte
*writebuf
, ULONGEST offset
, LONGEST len
)
1301 if (object
== TARGET_OBJECT_MEMORY
1302 && ops
->deprecated_xfer_memory
!= NULL
)
1303 /* If available, fall back to the target's
1304 "deprecated_xfer_memory" method. */
1308 if (writebuf
!= NULL
)
1310 void *buffer
= xmalloc (len
);
1311 struct cleanup
*cleanup
= make_cleanup (xfree
, buffer
);
1312 memcpy (buffer
, writebuf
, len
);
1313 xfered
= ops
->deprecated_xfer_memory (offset
, buffer
, len
,
1314 1/*write*/, NULL
, ops
);
1315 do_cleanups (cleanup
);
1317 if (readbuf
!= NULL
)
1318 xfered
= ops
->deprecated_xfer_memory (offset
, readbuf
, len
, 0/*read*/,
1322 else if (xfered
== 0 && errno
== 0)
1323 /* "deprecated_xfer_memory" uses 0, cross checked against
1324 ERRNO as one indication of an error. */
1329 else if (ops
->beneath
!= NULL
)
1330 return ops
->beneath
->to_xfer_partial (ops
->beneath
, object
, annex
,
1331 readbuf
, writebuf
, offset
, len
);
1336 /* The xfer_partial handler for the topmost target. Unlike the default,
1337 it does not need to handle memory specially; it just passes all
1338 requests down the stack. */
1341 current_xfer_partial (struct target_ops
*ops
, enum target_object object
,
1342 const char *annex
, gdb_byte
*readbuf
,
1343 const gdb_byte
*writebuf
, ULONGEST offset
, LONGEST len
)
1345 if (ops
->beneath
!= NULL
)
1346 return ops
->beneath
->to_xfer_partial (ops
->beneath
, object
, annex
,
1347 readbuf
, writebuf
, offset
, len
);
1352 /* Target vector read/write partial wrapper functions.
1354 NOTE: cagney/2003-10-21: I wonder if having "to_xfer_partial
1355 (inbuf, outbuf)", instead of separate read/write methods, make life
1359 target_read_partial (struct target_ops
*ops
,
1360 enum target_object object
,
1361 const char *annex
, gdb_byte
*buf
,
1362 ULONGEST offset
, LONGEST len
)
1364 return target_xfer_partial (ops
, object
, annex
, buf
, NULL
, offset
, len
);
1368 target_write_partial (struct target_ops
*ops
,
1369 enum target_object object
,
1370 const char *annex
, const gdb_byte
*buf
,
1371 ULONGEST offset
, LONGEST len
)
1373 return target_xfer_partial (ops
, object
, annex
, NULL
, buf
, offset
, len
);
1376 /* Wrappers to perform the full transfer. */
1378 target_read (struct target_ops
*ops
,
1379 enum target_object object
,
1380 const char *annex
, gdb_byte
*buf
,
1381 ULONGEST offset
, LONGEST len
)
1384 while (xfered
< len
)
1386 LONGEST xfer
= target_read_partial (ops
, object
, annex
,
1387 (gdb_byte
*) buf
+ xfered
,
1388 offset
+ xfered
, len
- xfered
);
1389 /* Call an observer, notifying them of the xfer progress? */
1400 /* An alternative to target_write with progress callbacks. */
1403 target_write_with_progress (struct target_ops
*ops
,
1404 enum target_object object
,
1405 const char *annex
, const gdb_byte
*buf
,
1406 ULONGEST offset
, LONGEST len
,
1407 void (*progress
) (ULONGEST
, void *), void *baton
)
1411 /* Give the progress callback a chance to set up. */
1413 (*progress
) (0, baton
);
1415 while (xfered
< len
)
1417 LONGEST xfer
= target_write_partial (ops
, object
, annex
,
1418 (gdb_byte
*) buf
+ xfered
,
1419 offset
+ xfered
, len
- xfered
);
1427 (*progress
) (xfer
, baton
);
1436 target_write (struct target_ops
*ops
,
1437 enum target_object object
,
1438 const char *annex
, const gdb_byte
*buf
,
1439 ULONGEST offset
, LONGEST len
)
1441 return target_write_with_progress (ops
, object
, annex
, buf
, offset
, len
,
1445 /* Read OBJECT/ANNEX using OPS. Store the result in *BUF_P and return
1446 the size of the transferred data. PADDING additional bytes are
1447 available in *BUF_P. This is a helper function for
1448 target_read_alloc; see the declaration of that function for more
1452 target_read_alloc_1 (struct target_ops
*ops
, enum target_object object
,
1453 const char *annex
, gdb_byte
**buf_p
, int padding
)
1455 size_t buf_alloc
, buf_pos
;
1459 /* This function does not have a length parameter; it reads the
1460 entire OBJECT). Also, it doesn't support objects fetched partly
1461 from one target and partly from another (in a different stratum,
1462 e.g. a core file and an executable). Both reasons make it
1463 unsuitable for reading memory. */
1464 gdb_assert (object
!= TARGET_OBJECT_MEMORY
);
1466 /* Start by reading up to 4K at a time. The target will throttle
1467 this number down if necessary. */
1469 buf
= xmalloc (buf_alloc
);
1473 n
= target_read_partial (ops
, object
, annex
, &buf
[buf_pos
],
1474 buf_pos
, buf_alloc
- buf_pos
- padding
);
1477 /* An error occurred. */
1483 /* Read all there was. */
1493 /* If the buffer is filling up, expand it. */
1494 if (buf_alloc
< buf_pos
* 2)
1497 buf
= xrealloc (buf
, buf_alloc
);
1504 /* Read OBJECT/ANNEX using OPS. Store the result in *BUF_P and return
1505 the size of the transferred data. See the declaration in "target.h"
1506 function for more information about the return value. */
1509 target_read_alloc (struct target_ops
*ops
, enum target_object object
,
1510 const char *annex
, gdb_byte
**buf_p
)
1512 return target_read_alloc_1 (ops
, object
, annex
, buf_p
, 0);
1515 /* Read OBJECT/ANNEX using OPS. The result is NUL-terminated and
1516 returned as a string, allocated using xmalloc. If an error occurs
1517 or the transfer is unsupported, NULL is returned. Empty objects
1518 are returned as allocated but empty strings. A warning is issued
1519 if the result contains any embedded NUL bytes. */
1522 target_read_stralloc (struct target_ops
*ops
, enum target_object object
,
1526 LONGEST transferred
;
1528 transferred
= target_read_alloc_1 (ops
, object
, annex
, &buffer
, 1);
1530 if (transferred
< 0)
1533 if (transferred
== 0)
1534 return xstrdup ("");
1536 buffer
[transferred
] = 0;
1537 if (strlen (buffer
) < transferred
)
1538 warning (_("target object %d, annex %s, "
1539 "contained unexpected null characters"),
1540 (int) object
, annex
? annex
: "(none)");
1542 return (char *) buffer
;
1545 /* Memory transfer methods. */
1548 get_target_memory (struct target_ops
*ops
, CORE_ADDR addr
, gdb_byte
*buf
,
1551 if (target_read (ops
, TARGET_OBJECT_MEMORY
, NULL
, buf
, addr
, len
)
1553 memory_error (EIO
, addr
);
1557 get_target_memory_unsigned (struct target_ops
*ops
,
1558 CORE_ADDR addr
, int len
)
1560 gdb_byte buf
[sizeof (ULONGEST
)];
1562 gdb_assert (len
<= sizeof (buf
));
1563 get_target_memory (ops
, addr
, buf
, len
);
1564 return extract_unsigned_integer (buf
, len
);
1568 target_info (char *args
, int from_tty
)
1570 struct target_ops
*t
;
1571 int has_all_mem
= 0;
1573 if (symfile_objfile
!= NULL
)
1574 printf_unfiltered (_("Symbols from \"%s\".\n"), symfile_objfile
->name
);
1576 for (t
= target_stack
; t
!= NULL
; t
= t
->beneath
)
1578 if (!t
->to_has_memory
)
1581 if ((int) (t
->to_stratum
) <= (int) dummy_stratum
)
1584 printf_unfiltered (_("\tWhile running this, GDB does not access memory from...\n"));
1585 printf_unfiltered ("%s:\n", t
->to_longname
);
1586 (t
->to_files_info
) (t
);
1587 has_all_mem
= t
->to_has_all_memory
;
1591 /* This function is called before any new inferior is created, e.g.
1592 by running a program, attaching, or connecting to a target.
1593 It cleans up any state from previous invocations which might
1594 change between runs. This is a subset of what target_preopen
1595 resets (things which might change between targets). */
1598 target_pre_inferior (int from_tty
)
1600 invalidate_target_mem_regions ();
1603 /* This is to be called by the open routine before it does
1607 target_preopen (int from_tty
)
1611 if (target_has_execution
)
1614 || query (_("A program is being debugged already. Kill it? ")))
1617 error (_("Program not killed."));
1620 /* Calling target_kill may remove the target from the stack. But if
1621 it doesn't (which seems like a win for UDI), remove it now. */
1623 if (target_has_execution
)
1626 target_pre_inferior (from_tty
);
1629 /* Detach a target after doing deferred register stores. */
1632 target_detach (char *args
, int from_tty
)
1634 (current_target
.to_detach
) (args
, from_tty
);
1638 target_disconnect (char *args
, int from_tty
)
1640 struct target_ops
*t
;
1642 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
1643 if (t
->to_disconnect
!= NULL
)
1646 fprintf_unfiltered (gdb_stdlog
, "target_disconnect (%s, %d)\n",
1648 t
->to_disconnect (t
, args
, from_tty
);
1656 target_async_mask (int mask
)
1658 int saved_async_masked_status
= target_async_mask_value
;
1659 target_async_mask_value
= mask
;
1660 return saved_async_masked_status
;
1663 /* Look through the list of possible targets for a target that can
1667 target_follow_fork (int follow_child
)
1669 struct target_ops
*t
;
1671 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
1673 if (t
->to_follow_fork
!= NULL
)
1675 int retval
= t
->to_follow_fork (t
, follow_child
);
1677 fprintf_unfiltered (gdb_stdlog
, "target_follow_fork (%d) = %d\n",
1678 follow_child
, retval
);
1683 /* Some target returned a fork event, but did not know how to follow it. */
1684 internal_error (__FILE__
, __LINE__
,
1685 "could not find a target to follow fork");
1688 /* Look through the list of possible targets for a target that can
1689 execute a run or attach command without any other data. This is
1690 used to locate the default process stratum.
1692 Result is always valid (error() is called for errors). */
1694 static struct target_ops
*
1695 find_default_run_target (char *do_mesg
)
1697 struct target_ops
**t
;
1698 struct target_ops
*runable
= NULL
;
1703 for (t
= target_structs
; t
< target_structs
+ target_struct_size
;
1706 if ((*t
)->to_can_run
&& target_can_run (*t
))
1714 error (_("Don't know how to %s. Try \"help target\"."), do_mesg
);
1720 find_default_attach (char *args
, int from_tty
)
1722 struct target_ops
*t
;
1724 t
= find_default_run_target ("attach");
1725 (t
->to_attach
) (args
, from_tty
);
1730 find_default_create_inferior (char *exec_file
, char *allargs
, char **env
,
1733 struct target_ops
*t
;
1735 t
= find_default_run_target ("run");
1736 (t
->to_create_inferior
) (exec_file
, allargs
, env
, from_tty
);
1741 default_region_ok_for_hw_watchpoint (CORE_ADDR addr
, int len
)
1743 return (len
<= TYPE_LENGTH (builtin_type_void_data_ptr
));
1759 return_minus_one (void)
1765 * Resize the to_sections pointer. Also make sure that anyone that
1766 * was holding on to an old value of it gets updated.
1767 * Returns the old size.
1771 target_resize_to_sections (struct target_ops
*target
, int num_added
)
1773 struct target_ops
**t
;
1774 struct section_table
*old_value
;
1777 old_value
= target
->to_sections
;
1779 if (target
->to_sections
)
1781 old_count
= target
->to_sections_end
- target
->to_sections
;
1782 target
->to_sections
= (struct section_table
*)
1783 xrealloc ((char *) target
->to_sections
,
1784 (sizeof (struct section_table
)) * (num_added
+ old_count
));
1789 target
->to_sections
= (struct section_table
*)
1790 xmalloc ((sizeof (struct section_table
)) * num_added
);
1792 target
->to_sections_end
= target
->to_sections
+ (num_added
+ old_count
);
1794 /* Check to see if anyone else was pointing to this structure.
1795 If old_value was null, then no one was. */
1799 for (t
= target_structs
; t
< target_structs
+ target_struct_size
;
1802 if ((*t
)->to_sections
== old_value
)
1804 (*t
)->to_sections
= target
->to_sections
;
1805 (*t
)->to_sections_end
= target
->to_sections_end
;
1808 /* There is a flattened view of the target stack in current_target,
1809 so its to_sections pointer might also need updating. */
1810 if (current_target
.to_sections
== old_value
)
1812 current_target
.to_sections
= target
->to_sections
;
1813 current_target
.to_sections_end
= target
->to_sections_end
;
1821 /* Remove all target sections taken from ABFD.
1823 Scan the current target stack for targets whose section tables
1824 refer to sections from BFD, and remove those sections. We use this
1825 when we notice that the inferior has unloaded a shared object, for
1828 remove_target_sections (bfd
*abfd
)
1830 struct target_ops
**t
;
1832 for (t
= target_structs
; t
< target_structs
+ target_struct_size
; t
++)
1834 struct section_table
*src
, *dest
;
1836 dest
= (*t
)->to_sections
;
1837 for (src
= (*t
)->to_sections
; src
< (*t
)->to_sections_end
; src
++)
1838 if (src
->bfd
!= abfd
)
1840 /* Keep this section. */
1841 if (dest
< src
) *dest
= *src
;
1845 /* If we've dropped any sections, resize the section table. */
1847 target_resize_to_sections (*t
, dest
- src
);
1854 /* Find a single runnable target in the stack and return it. If for
1855 some reason there is more than one, return NULL. */
1858 find_run_target (void)
1860 struct target_ops
**t
;
1861 struct target_ops
*runable
= NULL
;
1866 for (t
= target_structs
; t
< target_structs
+ target_struct_size
; ++t
)
1868 if ((*t
)->to_can_run
&& target_can_run (*t
))
1875 return (count
== 1 ? runable
: NULL
);
1878 /* Find a single core_stratum target in the list of targets and return it.
1879 If for some reason there is more than one, return NULL. */
1882 find_core_target (void)
1884 struct target_ops
**t
;
1885 struct target_ops
*runable
= NULL
;
1890 for (t
= target_structs
; t
< target_structs
+ target_struct_size
;
1893 if ((*t
)->to_stratum
== core_stratum
)
1900 return (count
== 1 ? runable
: NULL
);
1904 * Find the next target down the stack from the specified target.
1908 find_target_beneath (struct target_ops
*t
)
1914 /* The inferior process has died. Long live the inferior! */
1917 generic_mourn_inferior (void)
1919 extern int show_breakpoint_hit_counts
;
1921 inferior_ptid
= null_ptid
;
1923 breakpoint_init_inferior (inf_exited
);
1924 registers_changed ();
1926 reopen_exec_file ();
1927 reinit_frame_cache ();
1929 /* It is confusing to the user for ignore counts to stick around
1930 from previous runs of the inferior. So clear them. */
1931 /* However, it is more confusing for the ignore counts to disappear when
1932 using hit counts. So don't clear them if we're counting hits. */
1933 if (!show_breakpoint_hit_counts
)
1934 breakpoint_clear_ignore_counts ();
1936 if (deprecated_detach_hook
)
1937 deprecated_detach_hook ();
1940 /* Helper function for child_wait and the Lynx derivatives of child_wait.
1941 HOSTSTATUS is the waitstatus from wait() or the equivalent; store our
1942 translation of that in OURSTATUS. */
1944 store_waitstatus (struct target_waitstatus
*ourstatus
, int hoststatus
)
1946 #ifdef CHILD_SPECIAL_WAITSTATUS
1947 /* CHILD_SPECIAL_WAITSTATUS should return nonzero and set *OURSTATUS
1948 if it wants to deal with hoststatus. */
1949 if (CHILD_SPECIAL_WAITSTATUS (ourstatus
, hoststatus
))
1953 if (WIFEXITED (hoststatus
))
1955 ourstatus
->kind
= TARGET_WAITKIND_EXITED
;
1956 ourstatus
->value
.integer
= WEXITSTATUS (hoststatus
);
1958 else if (!WIFSTOPPED (hoststatus
))
1960 ourstatus
->kind
= TARGET_WAITKIND_SIGNALLED
;
1961 ourstatus
->value
.sig
= target_signal_from_host (WTERMSIG (hoststatus
));
1965 ourstatus
->kind
= TARGET_WAITKIND_STOPPED
;
1966 ourstatus
->value
.sig
= target_signal_from_host (WSTOPSIG (hoststatus
));
1970 /* Returns zero to leave the inferior alone, one to interrupt it. */
1971 int (*target_activity_function
) (void);
1972 int target_activity_fd
;
1974 /* Convert a normal process ID to a string. Returns the string in a
1978 normal_pid_to_str (ptid_t ptid
)
1980 static char buf
[32];
1982 xsnprintf (buf
, sizeof buf
, "process %d", ptid_get_pid (ptid
));
1986 /* Error-catcher for target_find_memory_regions */
1987 static int dummy_find_memory_regions (int (*ignore1
) (), void *ignore2
)
1989 error (_("No target."));
1993 /* Error-catcher for target_make_corefile_notes */
1994 static char * dummy_make_corefile_notes (bfd
*ignore1
, int *ignore2
)
1996 error (_("No target."));
2000 /* Set up the handful of non-empty slots needed by the dummy target
2004 init_dummy_target (void)
2006 dummy_target
.to_shortname
= "None";
2007 dummy_target
.to_longname
= "None";
2008 dummy_target
.to_doc
= "";
2009 dummy_target
.to_attach
= find_default_attach
;
2010 dummy_target
.to_create_inferior
= find_default_create_inferior
;
2011 dummy_target
.to_pid_to_str
= normal_pid_to_str
;
2012 dummy_target
.to_stratum
= dummy_stratum
;
2013 dummy_target
.to_find_memory_regions
= dummy_find_memory_regions
;
2014 dummy_target
.to_make_corefile_notes
= dummy_make_corefile_notes
;
2015 dummy_target
.to_xfer_partial
= default_xfer_partial
;
2016 dummy_target
.to_magic
= OPS_MAGIC
;
2020 debug_to_open (char *args
, int from_tty
)
2022 debug_target
.to_open (args
, from_tty
);
2024 fprintf_unfiltered (gdb_stdlog
, "target_open (%s, %d)\n", args
, from_tty
);
2028 debug_to_close (int quitting
)
2030 target_close (&debug_target
, quitting
);
2031 fprintf_unfiltered (gdb_stdlog
, "target_close (%d)\n", quitting
);
2035 target_close (struct target_ops
*targ
, int quitting
)
2037 if (targ
->to_xclose
!= NULL
)
2038 targ
->to_xclose (targ
, quitting
);
2039 else if (targ
->to_close
!= NULL
)
2040 targ
->to_close (quitting
);
2044 debug_to_attach (char *args
, int from_tty
)
2046 debug_target
.to_attach (args
, from_tty
);
2048 fprintf_unfiltered (gdb_stdlog
, "target_attach (%s, %d)\n", args
, from_tty
);
2053 debug_to_post_attach (int pid
)
2055 debug_target
.to_post_attach (pid
);
2057 fprintf_unfiltered (gdb_stdlog
, "target_post_attach (%d)\n", pid
);
2061 debug_to_detach (char *args
, int from_tty
)
2063 debug_target
.to_detach (args
, from_tty
);
2065 fprintf_unfiltered (gdb_stdlog
, "target_detach (%s, %d)\n", args
, from_tty
);
2069 debug_to_resume (ptid_t ptid
, int step
, enum target_signal siggnal
)
2071 debug_target
.to_resume (ptid
, step
, siggnal
);
2073 fprintf_unfiltered (gdb_stdlog
, "target_resume (%d, %s, %s)\n", PIDGET (ptid
),
2074 step
? "step" : "continue",
2075 target_signal_to_name (siggnal
));
2079 debug_to_wait (ptid_t ptid
, struct target_waitstatus
*status
)
2083 retval
= debug_target
.to_wait (ptid
, status
);
2085 fprintf_unfiltered (gdb_stdlog
,
2086 "target_wait (%d, status) = %d, ", PIDGET (ptid
),
2088 fprintf_unfiltered (gdb_stdlog
, "status->kind = ");
2089 switch (status
->kind
)
2091 case TARGET_WAITKIND_EXITED
:
2092 fprintf_unfiltered (gdb_stdlog
, "exited, status = %d\n",
2093 status
->value
.integer
);
2095 case TARGET_WAITKIND_STOPPED
:
2096 fprintf_unfiltered (gdb_stdlog
, "stopped, signal = %s\n",
2097 target_signal_to_name (status
->value
.sig
));
2099 case TARGET_WAITKIND_SIGNALLED
:
2100 fprintf_unfiltered (gdb_stdlog
, "signalled, signal = %s\n",
2101 target_signal_to_name (status
->value
.sig
));
2103 case TARGET_WAITKIND_LOADED
:
2104 fprintf_unfiltered (gdb_stdlog
, "loaded\n");
2106 case TARGET_WAITKIND_FORKED
:
2107 fprintf_unfiltered (gdb_stdlog
, "forked\n");
2109 case TARGET_WAITKIND_VFORKED
:
2110 fprintf_unfiltered (gdb_stdlog
, "vforked\n");
2112 case TARGET_WAITKIND_EXECD
:
2113 fprintf_unfiltered (gdb_stdlog
, "execd\n");
2115 case TARGET_WAITKIND_SPURIOUS
:
2116 fprintf_unfiltered (gdb_stdlog
, "spurious\n");
2119 fprintf_unfiltered (gdb_stdlog
, "unknown???\n");
2127 debug_print_register (const char * func
, int regno
)
2129 fprintf_unfiltered (gdb_stdlog
, "%s ", func
);
2130 if (regno
>= 0 && regno
< NUM_REGS
+ NUM_PSEUDO_REGS
2131 && REGISTER_NAME (regno
) != NULL
&& REGISTER_NAME (regno
)[0] != '\0')
2132 fprintf_unfiltered (gdb_stdlog
, "(%s)", REGISTER_NAME (regno
));
2134 fprintf_unfiltered (gdb_stdlog
, "(%d)", regno
);
2138 unsigned char buf
[MAX_REGISTER_SIZE
];
2139 deprecated_read_register_gen (regno
, buf
);
2140 fprintf_unfiltered (gdb_stdlog
, " = ");
2141 for (i
= 0; i
< register_size (current_gdbarch
, regno
); i
++)
2143 fprintf_unfiltered (gdb_stdlog
, "%02x", buf
[i
]);
2145 if (register_size (current_gdbarch
, regno
) <= sizeof (LONGEST
))
2147 fprintf_unfiltered (gdb_stdlog
, " 0x%s %s",
2148 paddr_nz (read_register (regno
)),
2149 paddr_d (read_register (regno
)));
2152 fprintf_unfiltered (gdb_stdlog
, "\n");
2156 debug_to_fetch_registers (int regno
)
2158 debug_target
.to_fetch_registers (regno
);
2159 debug_print_register ("target_fetch_registers", regno
);
2163 debug_to_store_registers (int regno
)
2165 debug_target
.to_store_registers (regno
);
2166 debug_print_register ("target_store_registers", regno
);
2167 fprintf_unfiltered (gdb_stdlog
, "\n");
2171 debug_to_prepare_to_store (void)
2173 debug_target
.to_prepare_to_store ();
2175 fprintf_unfiltered (gdb_stdlog
, "target_prepare_to_store ()\n");
2179 deprecated_debug_xfer_memory (CORE_ADDR memaddr
, bfd_byte
*myaddr
, int len
,
2180 int write
, struct mem_attrib
*attrib
,
2181 struct target_ops
*target
)
2185 retval
= debug_target
.deprecated_xfer_memory (memaddr
, myaddr
, len
, write
,
2188 fprintf_unfiltered (gdb_stdlog
,
2189 "target_xfer_memory (0x%x, xxx, %d, %s, xxx) = %d",
2190 (unsigned int) memaddr
, /* possable truncate long long */
2191 len
, write
? "write" : "read", retval
);
2197 fputs_unfiltered (", bytes =", gdb_stdlog
);
2198 for (i
= 0; i
< retval
; i
++)
2200 if ((((long) &(myaddr
[i
])) & 0xf) == 0)
2202 if (targetdebug
< 2 && i
> 0)
2204 fprintf_unfiltered (gdb_stdlog
, " ...");
2207 fprintf_unfiltered (gdb_stdlog
, "\n");
2210 fprintf_unfiltered (gdb_stdlog
, " %02x", myaddr
[i
] & 0xff);
2214 fputc_unfiltered ('\n', gdb_stdlog
);
2220 debug_to_files_info (struct target_ops
*target
)
2222 debug_target
.to_files_info (target
);
2224 fprintf_unfiltered (gdb_stdlog
, "target_files_info (xxx)\n");
2228 debug_to_insert_breakpoint (struct bp_target_info
*bp_tgt
)
2232 retval
= debug_target
.to_insert_breakpoint (bp_tgt
);
2234 fprintf_unfiltered (gdb_stdlog
,
2235 "target_insert_breakpoint (0x%lx, xxx) = %ld\n",
2236 (unsigned long) bp_tgt
->placed_address
,
2237 (unsigned long) retval
);
2242 debug_to_remove_breakpoint (struct bp_target_info
*bp_tgt
)
2246 retval
= debug_target
.to_remove_breakpoint (bp_tgt
);
2248 fprintf_unfiltered (gdb_stdlog
,
2249 "target_remove_breakpoint (0x%lx, xxx) = %ld\n",
2250 (unsigned long) bp_tgt
->placed_address
,
2251 (unsigned long) retval
);
2256 debug_to_can_use_hw_breakpoint (int type
, int cnt
, int from_tty
)
2260 retval
= debug_target
.to_can_use_hw_breakpoint (type
, cnt
, from_tty
);
2262 fprintf_unfiltered (gdb_stdlog
,
2263 "target_can_use_hw_breakpoint (%ld, %ld, %ld) = %ld\n",
2264 (unsigned long) type
,
2265 (unsigned long) cnt
,
2266 (unsigned long) from_tty
,
2267 (unsigned long) retval
);
2272 debug_to_region_ok_for_hw_watchpoint (CORE_ADDR addr
, int len
)
2276 retval
= debug_target
.to_region_ok_for_hw_watchpoint (addr
, len
);
2278 fprintf_unfiltered (gdb_stdlog
,
2279 "TARGET_REGION_OK_FOR_HW_WATCHPOINT (%ld, %ld) = 0x%lx\n",
2280 (unsigned long) addr
,
2281 (unsigned long) len
,
2282 (unsigned long) retval
);
2287 debug_to_stopped_by_watchpoint (void)
2291 retval
= debug_target
.to_stopped_by_watchpoint ();
2293 fprintf_unfiltered (gdb_stdlog
,
2294 "STOPPED_BY_WATCHPOINT () = %ld\n",
2295 (unsigned long) retval
);
2300 debug_to_stopped_data_address (struct target_ops
*target
, CORE_ADDR
*addr
)
2304 retval
= debug_target
.to_stopped_data_address (target
, addr
);
2306 fprintf_unfiltered (gdb_stdlog
,
2307 "target_stopped_data_address ([0x%lx]) = %ld\n",
2308 (unsigned long)*addr
,
2309 (unsigned long)retval
);
2314 debug_to_insert_hw_breakpoint (struct bp_target_info
*bp_tgt
)
2318 retval
= debug_target
.to_insert_hw_breakpoint (bp_tgt
);
2320 fprintf_unfiltered (gdb_stdlog
,
2321 "target_insert_hw_breakpoint (0x%lx, xxx) = %ld\n",
2322 (unsigned long) bp_tgt
->placed_address
,
2323 (unsigned long) retval
);
2328 debug_to_remove_hw_breakpoint (struct bp_target_info
*bp_tgt
)
2332 retval
= debug_target
.to_remove_hw_breakpoint (bp_tgt
);
2334 fprintf_unfiltered (gdb_stdlog
,
2335 "target_remove_hw_breakpoint (0x%lx, xxx) = %ld\n",
2336 (unsigned long) bp_tgt
->placed_address
,
2337 (unsigned long) retval
);
2342 debug_to_insert_watchpoint (CORE_ADDR addr
, int len
, int type
)
2346 retval
= debug_target
.to_insert_watchpoint (addr
, len
, type
);
2348 fprintf_unfiltered (gdb_stdlog
,
2349 "target_insert_watchpoint (0x%lx, %d, %d) = %ld\n",
2350 (unsigned long) addr
, len
, type
, (unsigned long) retval
);
2355 debug_to_remove_watchpoint (CORE_ADDR addr
, int len
, int type
)
2359 retval
= debug_target
.to_insert_watchpoint (addr
, len
, type
);
2361 fprintf_unfiltered (gdb_stdlog
,
2362 "target_insert_watchpoint (0x%lx, %d, %d) = %ld\n",
2363 (unsigned long) addr
, len
, type
, (unsigned long) retval
);
2368 debug_to_terminal_init (void)
2370 debug_target
.to_terminal_init ();
2372 fprintf_unfiltered (gdb_stdlog
, "target_terminal_init ()\n");
2376 debug_to_terminal_inferior (void)
2378 debug_target
.to_terminal_inferior ();
2380 fprintf_unfiltered (gdb_stdlog
, "target_terminal_inferior ()\n");
2384 debug_to_terminal_ours_for_output (void)
2386 debug_target
.to_terminal_ours_for_output ();
2388 fprintf_unfiltered (gdb_stdlog
, "target_terminal_ours_for_output ()\n");
2392 debug_to_terminal_ours (void)
2394 debug_target
.to_terminal_ours ();
2396 fprintf_unfiltered (gdb_stdlog
, "target_terminal_ours ()\n");
2400 debug_to_terminal_save_ours (void)
2402 debug_target
.to_terminal_save_ours ();
2404 fprintf_unfiltered (gdb_stdlog
, "target_terminal_save_ours ()\n");
2408 debug_to_terminal_info (char *arg
, int from_tty
)
2410 debug_target
.to_terminal_info (arg
, from_tty
);
2412 fprintf_unfiltered (gdb_stdlog
, "target_terminal_info (%s, %d)\n", arg
,
2417 debug_to_kill (void)
2419 debug_target
.to_kill ();
2421 fprintf_unfiltered (gdb_stdlog
, "target_kill ()\n");
2425 debug_to_load (char *args
, int from_tty
)
2427 debug_target
.to_load (args
, from_tty
);
2429 fprintf_unfiltered (gdb_stdlog
, "target_load (%s, %d)\n", args
, from_tty
);
2433 debug_to_lookup_symbol (char *name
, CORE_ADDR
*addrp
)
2437 retval
= debug_target
.to_lookup_symbol (name
, addrp
);
2439 fprintf_unfiltered (gdb_stdlog
, "target_lookup_symbol (%s, xxx)\n", name
);
2445 debug_to_create_inferior (char *exec_file
, char *args
, char **env
,
2448 debug_target
.to_create_inferior (exec_file
, args
, env
, from_tty
);
2450 fprintf_unfiltered (gdb_stdlog
, "target_create_inferior (%s, %s, xxx, %d)\n",
2451 exec_file
, args
, from_tty
);
2455 debug_to_post_startup_inferior (ptid_t ptid
)
2457 debug_target
.to_post_startup_inferior (ptid
);
2459 fprintf_unfiltered (gdb_stdlog
, "target_post_startup_inferior (%d)\n",
2464 debug_to_acknowledge_created_inferior (int pid
)
2466 debug_target
.to_acknowledge_created_inferior (pid
);
2468 fprintf_unfiltered (gdb_stdlog
, "target_acknowledge_created_inferior (%d)\n",
2473 debug_to_insert_fork_catchpoint (int pid
)
2475 debug_target
.to_insert_fork_catchpoint (pid
);
2477 fprintf_unfiltered (gdb_stdlog
, "target_insert_fork_catchpoint (%d)\n",
2482 debug_to_remove_fork_catchpoint (int pid
)
2486 retval
= debug_target
.to_remove_fork_catchpoint (pid
);
2488 fprintf_unfiltered (gdb_stdlog
, "target_remove_fork_catchpoint (%d) = %d\n",
2495 debug_to_insert_vfork_catchpoint (int pid
)
2497 debug_target
.to_insert_vfork_catchpoint (pid
);
2499 fprintf_unfiltered (gdb_stdlog
, "target_insert_vfork_catchpoint (%d)\n",
2504 debug_to_remove_vfork_catchpoint (int pid
)
2508 retval
= debug_target
.to_remove_vfork_catchpoint (pid
);
2510 fprintf_unfiltered (gdb_stdlog
, "target_remove_vfork_catchpoint (%d) = %d\n",
2517 debug_to_insert_exec_catchpoint (int pid
)
2519 debug_target
.to_insert_exec_catchpoint (pid
);
2521 fprintf_unfiltered (gdb_stdlog
, "target_insert_exec_catchpoint (%d)\n",
2526 debug_to_remove_exec_catchpoint (int pid
)
2530 retval
= debug_target
.to_remove_exec_catchpoint (pid
);
2532 fprintf_unfiltered (gdb_stdlog
, "target_remove_exec_catchpoint (%d) = %d\n",
2539 debug_to_reported_exec_events_per_exec_call (void)
2541 int reported_exec_events
;
2543 reported_exec_events
= debug_target
.to_reported_exec_events_per_exec_call ();
2545 fprintf_unfiltered (gdb_stdlog
,
2546 "target_reported_exec_events_per_exec_call () = %d\n",
2547 reported_exec_events
);
2549 return reported_exec_events
;
2553 debug_to_has_exited (int pid
, int wait_status
, int *exit_status
)
2557 has_exited
= debug_target
.to_has_exited (pid
, wait_status
, exit_status
);
2559 fprintf_unfiltered (gdb_stdlog
, "target_has_exited (%d, %d, %d) = %d\n",
2560 pid
, wait_status
, *exit_status
, has_exited
);
2566 debug_to_mourn_inferior (void)
2568 debug_target
.to_mourn_inferior ();
2570 fprintf_unfiltered (gdb_stdlog
, "target_mourn_inferior ()\n");
2574 debug_to_can_run (void)
2578 retval
= debug_target
.to_can_run ();
2580 fprintf_unfiltered (gdb_stdlog
, "target_can_run () = %d\n", retval
);
2586 debug_to_notice_signals (ptid_t ptid
)
2588 debug_target
.to_notice_signals (ptid
);
2590 fprintf_unfiltered (gdb_stdlog
, "target_notice_signals (%d)\n",
2595 debug_to_thread_alive (ptid_t ptid
)
2599 retval
= debug_target
.to_thread_alive (ptid
);
2601 fprintf_unfiltered (gdb_stdlog
, "target_thread_alive (%d) = %d\n",
2602 PIDGET (ptid
), retval
);
2608 debug_to_find_new_threads (void)
2610 debug_target
.to_find_new_threads ();
2612 fputs_unfiltered ("target_find_new_threads ()\n", gdb_stdlog
);
2616 debug_to_stop (void)
2618 debug_target
.to_stop ();
2620 fprintf_unfiltered (gdb_stdlog
, "target_stop ()\n");
2624 debug_to_rcmd (char *command
,
2625 struct ui_file
*outbuf
)
2627 debug_target
.to_rcmd (command
, outbuf
);
2628 fprintf_unfiltered (gdb_stdlog
, "target_rcmd (%s, ...)\n", command
);
2631 static struct symtab_and_line
*
2632 debug_to_enable_exception_callback (enum exception_event_kind kind
, int enable
)
2634 struct symtab_and_line
*result
;
2635 result
= debug_target
.to_enable_exception_callback (kind
, enable
);
2636 fprintf_unfiltered (gdb_stdlog
,
2637 "target get_exception_callback_sal (%d, %d)\n",
2642 static struct exception_event_record
*
2643 debug_to_get_current_exception_event (void)
2645 struct exception_event_record
*result
;
2646 result
= debug_target
.to_get_current_exception_event ();
2647 fprintf_unfiltered (gdb_stdlog
, "target get_current_exception_event ()\n");
2652 debug_to_pid_to_exec_file (int pid
)
2656 exec_file
= debug_target
.to_pid_to_exec_file (pid
);
2658 fprintf_unfiltered (gdb_stdlog
, "target_pid_to_exec_file (%d) = %s\n",
2665 setup_target_debug (void)
2667 memcpy (&debug_target
, ¤t_target
, sizeof debug_target
);
2669 current_target
.to_open
= debug_to_open
;
2670 current_target
.to_close
= debug_to_close
;
2671 current_target
.to_attach
= debug_to_attach
;
2672 current_target
.to_post_attach
= debug_to_post_attach
;
2673 current_target
.to_detach
= debug_to_detach
;
2674 current_target
.to_resume
= debug_to_resume
;
2675 current_target
.to_wait
= debug_to_wait
;
2676 current_target
.to_fetch_registers
= debug_to_fetch_registers
;
2677 current_target
.to_store_registers
= debug_to_store_registers
;
2678 current_target
.to_prepare_to_store
= debug_to_prepare_to_store
;
2679 current_target
.deprecated_xfer_memory
= deprecated_debug_xfer_memory
;
2680 current_target
.to_files_info
= debug_to_files_info
;
2681 current_target
.to_insert_breakpoint
= debug_to_insert_breakpoint
;
2682 current_target
.to_remove_breakpoint
= debug_to_remove_breakpoint
;
2683 current_target
.to_can_use_hw_breakpoint
= debug_to_can_use_hw_breakpoint
;
2684 current_target
.to_insert_hw_breakpoint
= debug_to_insert_hw_breakpoint
;
2685 current_target
.to_remove_hw_breakpoint
= debug_to_remove_hw_breakpoint
;
2686 current_target
.to_insert_watchpoint
= debug_to_insert_watchpoint
;
2687 current_target
.to_remove_watchpoint
= debug_to_remove_watchpoint
;
2688 current_target
.to_stopped_by_watchpoint
= debug_to_stopped_by_watchpoint
;
2689 current_target
.to_stopped_data_address
= debug_to_stopped_data_address
;
2690 current_target
.to_region_ok_for_hw_watchpoint
= debug_to_region_ok_for_hw_watchpoint
;
2691 current_target
.to_terminal_init
= debug_to_terminal_init
;
2692 current_target
.to_terminal_inferior
= debug_to_terminal_inferior
;
2693 current_target
.to_terminal_ours_for_output
= debug_to_terminal_ours_for_output
;
2694 current_target
.to_terminal_ours
= debug_to_terminal_ours
;
2695 current_target
.to_terminal_save_ours
= debug_to_terminal_save_ours
;
2696 current_target
.to_terminal_info
= debug_to_terminal_info
;
2697 current_target
.to_kill
= debug_to_kill
;
2698 current_target
.to_load
= debug_to_load
;
2699 current_target
.to_lookup_symbol
= debug_to_lookup_symbol
;
2700 current_target
.to_create_inferior
= debug_to_create_inferior
;
2701 current_target
.to_post_startup_inferior
= debug_to_post_startup_inferior
;
2702 current_target
.to_acknowledge_created_inferior
= debug_to_acknowledge_created_inferior
;
2703 current_target
.to_insert_fork_catchpoint
= debug_to_insert_fork_catchpoint
;
2704 current_target
.to_remove_fork_catchpoint
= debug_to_remove_fork_catchpoint
;
2705 current_target
.to_insert_vfork_catchpoint
= debug_to_insert_vfork_catchpoint
;
2706 current_target
.to_remove_vfork_catchpoint
= debug_to_remove_vfork_catchpoint
;
2707 current_target
.to_insert_exec_catchpoint
= debug_to_insert_exec_catchpoint
;
2708 current_target
.to_remove_exec_catchpoint
= debug_to_remove_exec_catchpoint
;
2709 current_target
.to_reported_exec_events_per_exec_call
= debug_to_reported_exec_events_per_exec_call
;
2710 current_target
.to_has_exited
= debug_to_has_exited
;
2711 current_target
.to_mourn_inferior
= debug_to_mourn_inferior
;
2712 current_target
.to_can_run
= debug_to_can_run
;
2713 current_target
.to_notice_signals
= debug_to_notice_signals
;
2714 current_target
.to_thread_alive
= debug_to_thread_alive
;
2715 current_target
.to_find_new_threads
= debug_to_find_new_threads
;
2716 current_target
.to_stop
= debug_to_stop
;
2717 current_target
.to_rcmd
= debug_to_rcmd
;
2718 current_target
.to_enable_exception_callback
= debug_to_enable_exception_callback
;
2719 current_target
.to_get_current_exception_event
= debug_to_get_current_exception_event
;
2720 current_target
.to_pid_to_exec_file
= debug_to_pid_to_exec_file
;
2724 static char targ_desc
[] =
2725 "Names of targets and files being debugged.\n\
2726 Shows the entire stack of targets currently in use (including the exec-file,\n\
2727 core-file, and process, if any), as well as the symbol file name.";
2730 do_monitor_command (char *cmd
,
2733 if ((current_target
.to_rcmd
2734 == (void (*) (char *, struct ui_file
*)) tcomplain
)
2735 || (current_target
.to_rcmd
== debug_to_rcmd
2736 && (debug_target
.to_rcmd
2737 == (void (*) (char *, struct ui_file
*)) tcomplain
)))
2738 error (_("\"monitor\" command not supported by this target."));
2739 target_rcmd (cmd
, gdb_stdtarg
);
2743 initialize_targets (void)
2745 init_dummy_target ();
2746 push_target (&dummy_target
);
2748 add_info ("target", target_info
, targ_desc
);
2749 add_info ("files", target_info
, targ_desc
);
2751 add_setshow_zinteger_cmd ("target", class_maintenance
, &targetdebug
, _("\
2752 Set target debugging."), _("\
2753 Show target debugging."), _("\
2754 When non-zero, target debugging is enabled. Higher numbers are more\n\
2755 verbose. Changes do not take effect until the next \"run\" or \"target\"\n\
2759 &setdebuglist
, &showdebuglist
);
2761 add_setshow_boolean_cmd ("trust-readonly-sections", class_support
,
2762 &trust_readonly
, _("\
2763 Set mode for reading from readonly sections."), _("\
2764 Show mode for reading from readonly sections."), _("\
2765 When this mode is on, memory reads from readonly sections (such as .text)\n\
2766 will be read from the object file instead of from the target. This will\n\
2767 result in significant performance improvement for remote targets."),
2769 show_trust_readonly
,
2770 &setlist
, &showlist
);
2772 add_com ("monitor", class_obscure
, do_monitor_command
,
2773 _("Send a command to the remote monitor (remote targets only)."));
2775 target_dcache
= dcache_init ();