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
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 "gdb_stdint.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 (struct regcache
*, int);
110 static void debug_to_store_registers (struct regcache
*, int);
112 static void debug_to_prepare_to_store (struct regcache
*);
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 /* Nonzero if we should show true memory content including
208 memory breakpoint inserted by gdb. */
210 static int show_memory_breakpoints
= 0;
212 /* Non-zero if we want to see trace of target level stuff. */
214 static int targetdebug
= 0;
216 show_targetdebug (struct ui_file
*file
, int from_tty
,
217 struct cmd_list_element
*c
, const char *value
)
219 fprintf_filtered (file
, _("Target debugging is %s.\n"), value
);
222 static void setup_target_debug (void);
224 DCACHE
*target_dcache
;
226 /* The user just typed 'target' without the name of a target. */
229 target_command (char *arg
, int from_tty
)
231 fputs_filtered ("Argument required (target name). Try `help target'\n",
235 /* Add a possible target architecture to the list. */
238 add_target (struct target_ops
*t
)
240 /* Provide default values for all "must have" methods. */
241 if (t
->to_xfer_partial
== NULL
)
242 t
->to_xfer_partial
= default_xfer_partial
;
246 target_struct_allocsize
= DEFAULT_ALLOCSIZE
;
247 target_structs
= (struct target_ops
**) xmalloc
248 (target_struct_allocsize
* sizeof (*target_structs
));
250 if (target_struct_size
>= target_struct_allocsize
)
252 target_struct_allocsize
*= 2;
253 target_structs
= (struct target_ops
**)
254 xrealloc ((char *) target_structs
,
255 target_struct_allocsize
* sizeof (*target_structs
));
257 target_structs
[target_struct_size
++] = t
;
259 if (targetlist
== NULL
)
260 add_prefix_cmd ("target", class_run
, target_command
, _("\
261 Connect to a target machine or process.\n\
262 The first argument is the type or protocol of the target machine.\n\
263 Remaining arguments are interpreted by the target protocol. For more\n\
264 information on the arguments for a particular protocol, type\n\
265 `help target ' followed by the protocol name."),
266 &targetlist
, "target ", 0, &cmdlist
);
267 add_cmd (t
->to_shortname
, no_class
, t
->to_open
, t
->to_doc
, &targetlist
);
278 target_load (char *arg
, int from_tty
)
280 dcache_invalidate (target_dcache
);
281 (*current_target
.to_load
) (arg
, from_tty
);
285 nomemory (CORE_ADDR memaddr
, char *myaddr
, int len
, int write
,
286 struct target_ops
*t
)
288 errno
= EIO
; /* Can't read/write this location */
289 return 0; /* No bytes handled */
295 error (_("You can't do that when your target is `%s'"),
296 current_target
.to_shortname
);
302 error (_("You can't do that without a process to debug."));
306 nosymbol (char *name
, CORE_ADDR
*addrp
)
308 return 1; /* Symbol does not exist in target env */
312 nosupport_runtime (void)
314 if (ptid_equal (inferior_ptid
, null_ptid
))
317 error (_("No run-time support for this"));
322 default_terminal_info (char *args
, int from_tty
)
324 printf_unfiltered (_("No saved terminal information.\n"));
327 /* This is the default target_create_inferior and target_attach function.
328 If the current target is executing, it asks whether to kill it off.
329 If this function returns without calling error(), it has killed off
330 the target, and the operation should be attempted. */
333 kill_or_be_killed (int from_tty
)
335 if (target_has_execution
)
337 printf_unfiltered (_("You are already running a program:\n"));
338 target_files_info ();
339 if (query ("Kill it? "))
342 if (target_has_execution
)
343 error (_("Killing the program did not help."));
348 error (_("Program not killed."));
355 maybe_kill_then_attach (char *args
, int from_tty
)
357 kill_or_be_killed (from_tty
);
358 target_attach (args
, from_tty
);
362 maybe_kill_then_create_inferior (char *exec
, char *args
, char **env
,
365 kill_or_be_killed (0);
366 target_create_inferior (exec
, args
, env
, from_tty
);
369 /* Go through the target stack from top to bottom, copying over zero
370 entries in current_target, then filling in still empty entries. In
371 effect, we are doing class inheritance through the pushed target
374 NOTE: cagney/2003-10-17: The problem with this inheritance, as it
375 is currently implemented, is that it discards any knowledge of
376 which target an inherited method originally belonged to.
377 Consequently, new new target methods should instead explicitly and
378 locally search the target stack for the target that can handle the
382 update_current_target (void)
384 struct target_ops
*t
;
386 /* First, reset current's contents. */
387 memset (¤t_target
, 0, sizeof (current_target
));
389 #define INHERIT(FIELD, TARGET) \
390 if (!current_target.FIELD) \
391 current_target.FIELD = (TARGET)->FIELD
393 for (t
= target_stack
; t
; t
= t
->beneath
)
395 INHERIT (to_shortname
, t
);
396 INHERIT (to_longname
, t
);
398 INHERIT (to_open
, t
);
399 INHERIT (to_close
, t
);
400 INHERIT (to_attach
, t
);
401 INHERIT (to_post_attach
, t
);
402 INHERIT (to_detach
, t
);
403 /* Do not inherit to_disconnect. */
404 INHERIT (to_resume
, t
);
405 INHERIT (to_wait
, t
);
406 INHERIT (to_fetch_registers
, t
);
407 INHERIT (to_store_registers
, t
);
408 INHERIT (to_prepare_to_store
, t
);
409 INHERIT (deprecated_xfer_memory
, t
);
410 INHERIT (to_files_info
, t
);
411 INHERIT (to_insert_breakpoint
, t
);
412 INHERIT (to_remove_breakpoint
, t
);
413 INHERIT (to_can_use_hw_breakpoint
, t
);
414 INHERIT (to_insert_hw_breakpoint
, t
);
415 INHERIT (to_remove_hw_breakpoint
, t
);
416 INHERIT (to_insert_watchpoint
, t
);
417 INHERIT (to_remove_watchpoint
, t
);
418 INHERIT (to_stopped_data_address
, t
);
419 INHERIT (to_stopped_by_watchpoint
, t
);
420 INHERIT (to_have_steppable_watchpoint
, t
);
421 INHERIT (to_have_continuable_watchpoint
, t
);
422 INHERIT (to_region_ok_for_hw_watchpoint
, t
);
423 INHERIT (to_terminal_init
, t
);
424 INHERIT (to_terminal_inferior
, t
);
425 INHERIT (to_terminal_ours_for_output
, t
);
426 INHERIT (to_terminal_ours
, t
);
427 INHERIT (to_terminal_save_ours
, t
);
428 INHERIT (to_terminal_info
, t
);
429 INHERIT (to_kill
, t
);
430 INHERIT (to_load
, t
);
431 INHERIT (to_lookup_symbol
, t
);
432 INHERIT (to_create_inferior
, t
);
433 INHERIT (to_post_startup_inferior
, t
);
434 INHERIT (to_acknowledge_created_inferior
, t
);
435 INHERIT (to_insert_fork_catchpoint
, t
);
436 INHERIT (to_remove_fork_catchpoint
, t
);
437 INHERIT (to_insert_vfork_catchpoint
, t
);
438 INHERIT (to_remove_vfork_catchpoint
, t
);
439 /* Do not inherit to_follow_fork. */
440 INHERIT (to_insert_exec_catchpoint
, t
);
441 INHERIT (to_remove_exec_catchpoint
, t
);
442 INHERIT (to_reported_exec_events_per_exec_call
, t
);
443 INHERIT (to_has_exited
, t
);
444 INHERIT (to_mourn_inferior
, t
);
445 INHERIT (to_can_run
, t
);
446 INHERIT (to_notice_signals
, t
);
447 INHERIT (to_thread_alive
, t
);
448 INHERIT (to_find_new_threads
, t
);
449 INHERIT (to_pid_to_str
, t
);
450 INHERIT (to_extra_thread_info
, t
);
451 INHERIT (to_stop
, t
);
452 /* Do not inherit to_xfer_partial. */
453 INHERIT (to_rcmd
, t
);
454 INHERIT (to_pid_to_exec_file
, t
);
455 INHERIT (to_log_command
, t
);
456 INHERIT (to_stratum
, t
);
457 INHERIT (to_has_all_memory
, t
);
458 INHERIT (to_has_memory
, t
);
459 INHERIT (to_has_stack
, t
);
460 INHERIT (to_has_registers
, t
);
461 INHERIT (to_has_execution
, t
);
462 INHERIT (to_has_thread_control
, t
);
463 INHERIT (to_sections
, t
);
464 INHERIT (to_sections_end
, t
);
465 INHERIT (to_can_async_p
, t
);
466 INHERIT (to_is_async_p
, t
);
467 INHERIT (to_async
, t
);
468 INHERIT (to_async_mask_value
, t
);
469 INHERIT (to_find_memory_regions
, t
);
470 INHERIT (to_make_corefile_notes
, t
);
471 INHERIT (to_get_thread_local_address
, t
);
472 /* Do not inherit to_read_description. */
473 INHERIT (to_magic
, t
);
474 /* Do not inherit to_memory_map. */
475 /* Do not inherit to_flash_erase. */
476 /* Do not inherit to_flash_done. */
480 /* Clean up a target struct so it no longer has any zero pointers in
481 it. Some entries are defaulted to a method that print an error,
482 others are hard-wired to a standard recursive default. */
484 #define de_fault(field, value) \
485 if (!current_target.field) \
486 current_target.field = value
489 (void (*) (char *, int))
495 maybe_kill_then_attach
);
496 de_fault (to_post_attach
,
500 (void (*) (char *, int))
503 (void (*) (ptid_t
, int, enum target_signal
))
506 (ptid_t (*) (ptid_t
, struct target_waitstatus
*))
508 de_fault (to_fetch_registers
,
509 (void (*) (struct regcache
*, int))
511 de_fault (to_store_registers
,
512 (void (*) (struct regcache
*, int))
514 de_fault (to_prepare_to_store
,
515 (void (*) (struct regcache
*))
517 de_fault (deprecated_xfer_memory
,
518 (int (*) (CORE_ADDR
, gdb_byte
*, int, int, struct mem_attrib
*, struct target_ops
*))
520 de_fault (to_files_info
,
521 (void (*) (struct target_ops
*))
523 de_fault (to_insert_breakpoint
,
524 memory_insert_breakpoint
);
525 de_fault (to_remove_breakpoint
,
526 memory_remove_breakpoint
);
527 de_fault (to_can_use_hw_breakpoint
,
528 (int (*) (int, int, int))
530 de_fault (to_insert_hw_breakpoint
,
531 (int (*) (struct bp_target_info
*))
533 de_fault (to_remove_hw_breakpoint
,
534 (int (*) (struct bp_target_info
*))
536 de_fault (to_insert_watchpoint
,
537 (int (*) (CORE_ADDR
, int, int))
539 de_fault (to_remove_watchpoint
,
540 (int (*) (CORE_ADDR
, int, int))
542 de_fault (to_stopped_by_watchpoint
,
545 de_fault (to_stopped_data_address
,
546 (int (*) (struct target_ops
*, CORE_ADDR
*))
548 de_fault (to_region_ok_for_hw_watchpoint
,
549 default_region_ok_for_hw_watchpoint
);
550 de_fault (to_terminal_init
,
553 de_fault (to_terminal_inferior
,
556 de_fault (to_terminal_ours_for_output
,
559 de_fault (to_terminal_ours
,
562 de_fault (to_terminal_save_ours
,
565 de_fault (to_terminal_info
,
566 default_terminal_info
);
571 (void (*) (char *, int))
573 de_fault (to_lookup_symbol
,
574 (int (*) (char *, CORE_ADDR
*))
576 de_fault (to_create_inferior
,
577 maybe_kill_then_create_inferior
);
578 de_fault (to_post_startup_inferior
,
581 de_fault (to_acknowledge_created_inferior
,
584 de_fault (to_insert_fork_catchpoint
,
587 de_fault (to_remove_fork_catchpoint
,
590 de_fault (to_insert_vfork_catchpoint
,
593 de_fault (to_remove_vfork_catchpoint
,
596 de_fault (to_insert_exec_catchpoint
,
599 de_fault (to_remove_exec_catchpoint
,
602 de_fault (to_reported_exec_events_per_exec_call
,
605 de_fault (to_has_exited
,
606 (int (*) (int, int, int *))
608 de_fault (to_mourn_inferior
,
611 de_fault (to_can_run
,
613 de_fault (to_notice_signals
,
616 de_fault (to_thread_alive
,
619 de_fault (to_find_new_threads
,
622 de_fault (to_extra_thread_info
,
623 (char *(*) (struct thread_info
*))
628 current_target
.to_xfer_partial
= current_xfer_partial
;
630 (void (*) (char *, struct ui_file
*))
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*))
644 current_target
.to_read_description
= NULL
;
647 /* Finally, position the target-stack beneath the squashed
648 "current_target". That way code looking for a non-inherited
649 target method can quickly and simply find it. */
650 current_target
.beneath
= target_stack
;
653 setup_target_debug ();
656 /* Mark OPS as a running target. This reverses the effect
657 of target_mark_exited. */
660 target_mark_running (struct target_ops
*ops
)
662 struct target_ops
*t
;
664 for (t
= target_stack
; t
!= NULL
; t
= t
->beneath
)
668 internal_error (__FILE__
, __LINE__
,
669 "Attempted to mark unpushed target \"%s\" as running",
672 ops
->to_has_execution
= 1;
673 ops
->to_has_all_memory
= 1;
674 ops
->to_has_memory
= 1;
675 ops
->to_has_stack
= 1;
676 ops
->to_has_registers
= 1;
678 update_current_target ();
681 /* Mark OPS as a non-running target. This reverses the effect
682 of target_mark_running. */
685 target_mark_exited (struct target_ops
*ops
)
687 struct target_ops
*t
;
689 for (t
= target_stack
; t
!= NULL
; t
= t
->beneath
)
693 internal_error (__FILE__
, __LINE__
,
694 "Attempted to mark unpushed target \"%s\" as running",
697 ops
->to_has_execution
= 0;
698 ops
->to_has_all_memory
= 0;
699 ops
->to_has_memory
= 0;
700 ops
->to_has_stack
= 0;
701 ops
->to_has_registers
= 0;
703 update_current_target ();
706 /* Push a new target type into the stack of the existing target accessors,
707 possibly superseding some of the existing accessors.
709 Result is zero if the pushed target ended up on top of the stack,
710 nonzero if at least one target is on top of it.
712 Rather than allow an empty stack, we always have the dummy target at
713 the bottom stratum, so we can call the function vectors without
717 push_target (struct target_ops
*t
)
719 struct target_ops
**cur
;
721 /* Check magic number. If wrong, it probably means someone changed
722 the struct definition, but not all the places that initialize one. */
723 if (t
->to_magic
!= OPS_MAGIC
)
725 fprintf_unfiltered (gdb_stderr
,
726 "Magic number of %s target struct wrong\n",
728 internal_error (__FILE__
, __LINE__
, _("failed internal consistency check"));
731 /* Find the proper stratum to install this target in. */
732 for (cur
= &target_stack
; (*cur
) != NULL
; cur
= &(*cur
)->beneath
)
734 if ((int) (t
->to_stratum
) >= (int) (*cur
)->to_stratum
)
738 /* If there's already targets at this stratum, remove them. */
739 /* FIXME: cagney/2003-10-15: I think this should be popping all
740 targets to CUR, and not just those at this stratum level. */
741 while ((*cur
) != NULL
&& t
->to_stratum
== (*cur
)->to_stratum
)
743 /* There's already something at this stratum level. Close it,
744 and un-hook it from the stack. */
745 struct target_ops
*tmp
= (*cur
);
746 (*cur
) = (*cur
)->beneath
;
748 target_close (tmp
, 0);
751 /* We have removed all targets in our stratum, now add the new one. */
755 update_current_target ();
758 return (t
!= target_stack
);
761 /* Remove a target_ops vector from the stack, wherever it may be.
762 Return how many times it was removed (0 or 1). */
765 unpush_target (struct target_ops
*t
)
767 struct target_ops
**cur
;
768 struct target_ops
*tmp
;
770 /* Look for the specified target. Note that we assume that a target
771 can only occur once in the target stack. */
773 for (cur
= &target_stack
; (*cur
) != NULL
; cur
= &(*cur
)->beneath
)
780 return 0; /* Didn't find target_ops, quit now */
782 /* NOTE: cagney/2003-12-06: In '94 the close call was made
783 unconditional by moving it to before the above check that the
784 target was in the target stack (something about "Change the way
785 pushing and popping of targets work to support target overlays
786 and inheritance"). This doesn't make much sense - only open
787 targets should be closed. */
790 /* Unchain the target */
792 (*cur
) = (*cur
)->beneath
;
795 update_current_target ();
803 target_close (¤t_target
, 0); /* Let it clean up */
804 if (unpush_target (target_stack
) == 1)
807 fprintf_unfiltered (gdb_stderr
,
808 "pop_target couldn't find target %s\n",
809 current_target
.to_shortname
);
810 internal_error (__FILE__
, __LINE__
, _("failed internal consistency check"));
813 /* Using the objfile specified in OBJFILE, find the address for the
814 current thread's thread-local storage with offset OFFSET. */
816 target_translate_tls_address (struct objfile
*objfile
, CORE_ADDR offset
)
818 volatile CORE_ADDR addr
= 0;
820 if (target_get_thread_local_address_p ()
821 && gdbarch_fetch_tls_load_module_address_p (current_gdbarch
))
823 ptid_t ptid
= inferior_ptid
;
824 volatile struct gdb_exception ex
;
826 TRY_CATCH (ex
, RETURN_MASK_ALL
)
830 /* Fetch the load module address for this objfile. */
831 lm_addr
= gdbarch_fetch_tls_load_module_address (current_gdbarch
,
833 /* If it's 0, throw the appropriate exception. */
835 throw_error (TLS_LOAD_MODULE_NOT_FOUND_ERROR
,
836 _("TLS load module not found"));
838 addr
= target_get_thread_local_address (ptid
, lm_addr
, offset
);
840 /* If an error occurred, print TLS related messages here. Otherwise,
841 throw the error to some higher catcher. */
844 int objfile_is_library
= (objfile
->flags
& OBJF_SHARED
);
848 case TLS_NO_LIBRARY_SUPPORT_ERROR
:
849 error (_("Cannot find thread-local variables in this thread library."));
851 case TLS_LOAD_MODULE_NOT_FOUND_ERROR
:
852 if (objfile_is_library
)
853 error (_("Cannot find shared library `%s' in dynamic"
854 " linker's load module list"), objfile
->name
);
856 error (_("Cannot find executable file `%s' in dynamic"
857 " linker's load module list"), objfile
->name
);
859 case TLS_NOT_ALLOCATED_YET_ERROR
:
860 if (objfile_is_library
)
861 error (_("The inferior has not yet allocated storage for"
862 " thread-local variables in\n"
863 "the shared library `%s'\n"
865 objfile
->name
, target_pid_to_str (ptid
));
867 error (_("The inferior has not yet allocated storage for"
868 " thread-local variables in\n"
869 "the executable `%s'\n"
871 objfile
->name
, target_pid_to_str (ptid
));
873 case TLS_GENERIC_ERROR
:
874 if (objfile_is_library
)
875 error (_("Cannot find thread-local storage for %s, "
876 "shared library %s:\n%s"),
877 target_pid_to_str (ptid
),
878 objfile
->name
, ex
.message
);
880 error (_("Cannot find thread-local storage for %s, "
881 "executable file %s:\n%s"),
882 target_pid_to_str (ptid
),
883 objfile
->name
, ex
.message
);
886 throw_exception (ex
);
891 /* It wouldn't be wrong here to try a gdbarch method, too; finding
892 TLS is an ABI-specific thing. But we don't do that yet. */
894 error (_("Cannot find thread-local variables on this target"));
900 #define MIN(A, B) (((A) <= (B)) ? (A) : (B))
902 /* target_read_string -- read a null terminated string, up to LEN bytes,
903 from MEMADDR in target. Set *ERRNOP to the errno code, or 0 if successful.
904 Set *STRING to a pointer to malloc'd memory containing the data; the caller
905 is responsible for freeing it. Return the number of bytes successfully
909 target_read_string (CORE_ADDR memaddr
, char **string
, int len
, int *errnop
)
911 int tlen
, origlen
, offset
, i
;
915 int buffer_allocated
;
917 unsigned int nbytes_read
= 0;
921 /* Small for testing. */
922 buffer_allocated
= 4;
923 buffer
= xmalloc (buffer_allocated
);
930 tlen
= MIN (len
, 4 - (memaddr
& 3));
931 offset
= memaddr
& 3;
933 errcode
= target_read_memory (memaddr
& ~3, buf
, sizeof buf
);
936 /* The transfer request might have crossed the boundary to an
937 unallocated region of memory. Retry the transfer, requesting
941 errcode
= target_read_memory (memaddr
, buf
, 1);
946 if (bufptr
- buffer
+ tlen
> buffer_allocated
)
949 bytes
= bufptr
- buffer
;
950 buffer_allocated
*= 2;
951 buffer
= xrealloc (buffer
, buffer_allocated
);
952 bufptr
= buffer
+ bytes
;
955 for (i
= 0; i
< tlen
; i
++)
957 *bufptr
++ = buf
[i
+ offset
];
958 if (buf
[i
+ offset
] == '\000')
960 nbytes_read
+= i
+ 1;
976 /* Find a section containing ADDR. */
977 struct section_table
*
978 target_section_by_addr (struct target_ops
*target
, CORE_ADDR addr
)
980 struct section_table
*secp
;
981 for (secp
= target
->to_sections
;
982 secp
< target
->to_sections_end
;
985 if (addr
>= secp
->addr
&& addr
< secp
->endaddr
)
991 /* Perform a partial memory transfer. The arguments and return
992 value are just as for target_xfer_partial. */
995 memory_xfer_partial (struct target_ops
*ops
, void *readbuf
, const void *writebuf
,
996 ULONGEST memaddr
, LONGEST len
)
1000 struct mem_region
*region
;
1002 /* Zero length requests are ok and require no work. */
1006 /* Try the executable file, if "trust-readonly-sections" is set. */
1007 if (readbuf
!= NULL
&& trust_readonly
)
1009 struct section_table
*secp
;
1011 secp
= target_section_by_addr (ops
, memaddr
);
1013 && (bfd_get_section_flags (secp
->bfd
, secp
->the_bfd_section
)
1015 return xfer_memory (memaddr
, readbuf
, len
, 0, NULL
, ops
);
1018 /* Likewise for accesses to unmapped overlay sections. */
1019 if (readbuf
!= NULL
&& overlay_debugging
)
1021 asection
*section
= find_pc_overlay (memaddr
);
1022 if (pc_in_unmapped_range (memaddr
, section
))
1023 return xfer_memory (memaddr
, readbuf
, len
, 0, NULL
, ops
);
1026 /* Try GDB's internal data cache. */
1027 region
= lookup_mem_region (memaddr
);
1028 /* region->hi == 0 means there's no upper bound. */
1029 if (memaddr
+ len
< region
->hi
|| region
->hi
== 0)
1032 reg_len
= region
->hi
- memaddr
;
1034 switch (region
->attrib
.mode
)
1037 if (writebuf
!= NULL
)
1042 if (readbuf
!= NULL
)
1047 /* We only support writing to flash during "load" for now. */
1048 if (writebuf
!= NULL
)
1049 error (_("Writing to flash memory forbidden in this context"));
1056 if (region
->attrib
.cache
)
1058 /* FIXME drow/2006-08-09: This call discards OPS, so the raw
1059 memory request will start back at current_target. */
1060 if (readbuf
!= NULL
)
1061 res
= dcache_xfer_memory (target_dcache
, memaddr
, readbuf
,
1064 /* FIXME drow/2006-08-09: If we're going to preserve const
1065 correctness dcache_xfer_memory should take readbuf and
1067 res
= dcache_xfer_memory (target_dcache
, memaddr
,
1074 if (readbuf
&& !show_memory_breakpoints
)
1075 breakpoint_restore_shadows (readbuf
, memaddr
, reg_len
);
1080 /* If none of those methods found the memory we wanted, fall back
1081 to a target partial transfer. Normally a single call to
1082 to_xfer_partial is enough; if it doesn't recognize an object
1083 it will call the to_xfer_partial of the next target down.
1084 But for memory this won't do. Memory is the only target
1085 object which can be read from more than one valid target.
1086 A core file, for instance, could have some of memory but
1087 delegate other bits to the target below it. So, we must
1088 manually try all targets. */
1092 res
= ops
->to_xfer_partial (ops
, TARGET_OBJECT_MEMORY
, NULL
,
1093 readbuf
, writebuf
, memaddr
, reg_len
);
1097 /* We want to continue past core files to executables, but not
1098 past a running target's memory. */
1099 if (ops
->to_has_all_memory
)
1104 while (ops
!= NULL
);
1106 if (readbuf
&& !show_memory_breakpoints
)
1107 breakpoint_restore_shadows (readbuf
, memaddr
, reg_len
);
1109 /* If we still haven't got anything, return the last error. We
1115 restore_show_memory_breakpoints (void *arg
)
1117 show_memory_breakpoints
= (uintptr_t) arg
;
1121 make_show_memory_breakpoints_cleanup (int show
)
1123 int current
= show_memory_breakpoints
;
1124 show_memory_breakpoints
= show
;
1126 return make_cleanup (restore_show_memory_breakpoints
,
1127 (void *) (uintptr_t) current
);
1131 target_xfer_partial (struct target_ops
*ops
,
1132 enum target_object object
, const char *annex
,
1133 void *readbuf
, const void *writebuf
,
1134 ULONGEST offset
, LONGEST len
)
1138 gdb_assert (ops
->to_xfer_partial
!= NULL
);
1140 /* If this is a memory transfer, let the memory-specific code
1141 have a look at it instead. Memory transfers are more
1143 if (object
== TARGET_OBJECT_MEMORY
)
1144 retval
= memory_xfer_partial (ops
, readbuf
, writebuf
, offset
, len
);
1147 enum target_object raw_object
= object
;
1149 /* If this is a raw memory transfer, request the normal
1150 memory object from other layers. */
1151 if (raw_object
== TARGET_OBJECT_RAW_MEMORY
)
1152 raw_object
= TARGET_OBJECT_MEMORY
;
1154 retval
= ops
->to_xfer_partial (ops
, raw_object
, annex
, readbuf
,
1155 writebuf
, offset
, len
);
1160 const unsigned char *myaddr
= NULL
;
1162 fprintf_unfiltered (gdb_stdlog
,
1163 "%s:target_xfer_partial (%d, %s, 0x%lx, 0x%lx, 0x%s, %s) = %s",
1166 (annex
? annex
: "(null)"),
1167 (long) readbuf
, (long) writebuf
,
1168 paddr_nz (offset
), paddr_d (len
), paddr_d (retval
));
1174 if (retval
> 0 && myaddr
!= NULL
)
1178 fputs_unfiltered (", bytes =", gdb_stdlog
);
1179 for (i
= 0; i
< retval
; i
++)
1181 if ((((long) &(myaddr
[i
])) & 0xf) == 0)
1183 if (targetdebug
< 2 && i
> 0)
1185 fprintf_unfiltered (gdb_stdlog
, " ...");
1188 fprintf_unfiltered (gdb_stdlog
, "\n");
1191 fprintf_unfiltered (gdb_stdlog
, " %02x", myaddr
[i
] & 0xff);
1195 fputc_unfiltered ('\n', gdb_stdlog
);
1200 /* Read LEN bytes of target memory at address MEMADDR, placing the results in
1201 GDB's memory at MYADDR. Returns either 0 for success or an errno value
1202 if any error occurs.
1204 If an error occurs, no guarantee is made about the contents of the data at
1205 MYADDR. In particular, the caller should not depend upon partial reads
1206 filling the buffer with good data. There is no way for the caller to know
1207 how much good data might have been transfered anyway. Callers that can
1208 deal with partial reads should call target_read (which will retry until
1209 it makes no progress, and then return how much was transferred). */
1212 target_read_memory (CORE_ADDR memaddr
, gdb_byte
*myaddr
, int len
)
1214 if (target_read (¤t_target
, TARGET_OBJECT_MEMORY
, NULL
,
1215 myaddr
, memaddr
, len
) == len
)
1222 target_write_memory (CORE_ADDR memaddr
, const gdb_byte
*myaddr
, int len
)
1224 if (target_write (¤t_target
, TARGET_OBJECT_MEMORY
, NULL
,
1225 myaddr
, memaddr
, len
) == len
)
1231 /* Fetch the target's memory map. */
1234 target_memory_map (void)
1236 VEC(mem_region_s
) *result
;
1237 struct mem_region
*last_one
, *this_one
;
1239 struct target_ops
*t
;
1242 fprintf_unfiltered (gdb_stdlog
, "target_memory_map ()\n");
1244 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
1245 if (t
->to_memory_map
!= NULL
)
1251 result
= t
->to_memory_map (t
);
1255 qsort (VEC_address (mem_region_s
, result
),
1256 VEC_length (mem_region_s
, result
),
1257 sizeof (struct mem_region
), mem_region_cmp
);
1259 /* Check that regions do not overlap. Simultaneously assign
1260 a numbering for the "mem" commands to use to refer to
1263 for (ix
= 0; VEC_iterate (mem_region_s
, result
, ix
, this_one
); ix
++)
1265 this_one
->number
= ix
;
1267 if (last_one
&& last_one
->hi
> this_one
->lo
)
1269 warning (_("Overlapping regions in memory map: ignoring"));
1270 VEC_free (mem_region_s
, result
);
1273 last_one
= this_one
;
1280 target_flash_erase (ULONGEST address
, LONGEST length
)
1282 struct target_ops
*t
;
1284 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
1285 if (t
->to_flash_erase
!= NULL
)
1288 fprintf_unfiltered (gdb_stdlog
, "target_flash_erase (%s, %s)\n",
1289 paddr (address
), phex (length
, 0));
1290 t
->to_flash_erase (t
, address
, length
);
1298 target_flash_done (void)
1300 struct target_ops
*t
;
1302 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
1303 if (t
->to_flash_done
!= NULL
)
1306 fprintf_unfiltered (gdb_stdlog
, "target_flash_done\n");
1307 t
->to_flash_done (t
);
1314 #ifndef target_stopped_data_address_p
1316 target_stopped_data_address_p (struct target_ops
*target
)
1318 if (target
->to_stopped_data_address
1319 == (int (*) (struct target_ops
*, CORE_ADDR
*)) return_zero
)
1321 if (target
->to_stopped_data_address
== debug_to_stopped_data_address
1322 && (debug_target
.to_stopped_data_address
1323 == (int (*) (struct target_ops
*, CORE_ADDR
*)) return_zero
))
1330 show_trust_readonly (struct ui_file
*file
, int from_tty
,
1331 struct cmd_list_element
*c
, const char *value
)
1333 fprintf_filtered (file
, _("\
1334 Mode for reading from readonly sections is %s.\n"),
1338 /* More generic transfers. */
1341 default_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 (object
== TARGET_OBJECT_MEMORY
1346 && ops
->deprecated_xfer_memory
!= NULL
)
1347 /* If available, fall back to the target's
1348 "deprecated_xfer_memory" method. */
1352 if (writebuf
!= NULL
)
1354 void *buffer
= xmalloc (len
);
1355 struct cleanup
*cleanup
= make_cleanup (xfree
, buffer
);
1356 memcpy (buffer
, writebuf
, len
);
1357 xfered
= ops
->deprecated_xfer_memory (offset
, buffer
, len
,
1358 1/*write*/, NULL
, ops
);
1359 do_cleanups (cleanup
);
1361 if (readbuf
!= NULL
)
1362 xfered
= ops
->deprecated_xfer_memory (offset
, readbuf
, len
,
1363 0/*read*/, NULL
, ops
);
1366 else if (xfered
== 0 && errno
== 0)
1367 /* "deprecated_xfer_memory" uses 0, cross checked against
1368 ERRNO as one indication of an error. */
1373 else if (ops
->beneath
!= NULL
)
1374 return ops
->beneath
->to_xfer_partial (ops
->beneath
, object
, annex
,
1375 readbuf
, writebuf
, offset
, len
);
1380 /* The xfer_partial handler for the topmost target. Unlike the default,
1381 it does not need to handle memory specially; it just passes all
1382 requests down the stack. */
1385 current_xfer_partial (struct target_ops
*ops
, enum target_object object
,
1386 const char *annex
, gdb_byte
*readbuf
,
1387 const gdb_byte
*writebuf
, ULONGEST offset
, LONGEST len
)
1389 if (ops
->beneath
!= NULL
)
1390 return ops
->beneath
->to_xfer_partial (ops
->beneath
, object
, annex
,
1391 readbuf
, writebuf
, offset
, len
);
1396 /* Target vector read/write partial wrapper functions.
1398 NOTE: cagney/2003-10-21: I wonder if having "to_xfer_partial
1399 (inbuf, outbuf)", instead of separate read/write methods, make life
1403 target_read_partial (struct target_ops
*ops
,
1404 enum target_object object
,
1405 const char *annex
, gdb_byte
*buf
,
1406 ULONGEST offset
, LONGEST len
)
1408 return target_xfer_partial (ops
, object
, annex
, buf
, NULL
, offset
, len
);
1412 target_write_partial (struct target_ops
*ops
,
1413 enum target_object object
,
1414 const char *annex
, const gdb_byte
*buf
,
1415 ULONGEST offset
, LONGEST len
)
1417 return target_xfer_partial (ops
, object
, annex
, NULL
, buf
, offset
, len
);
1420 /* Wrappers to perform the full transfer. */
1422 target_read (struct target_ops
*ops
,
1423 enum target_object object
,
1424 const char *annex
, gdb_byte
*buf
,
1425 ULONGEST offset
, LONGEST len
)
1428 while (xfered
< len
)
1430 LONGEST xfer
= target_read_partial (ops
, object
, annex
,
1431 (gdb_byte
*) buf
+ xfered
,
1432 offset
+ xfered
, len
- xfered
);
1433 /* Call an observer, notifying them of the xfer progress? */
1444 /* An alternative to target_write with progress callbacks. */
1447 target_write_with_progress (struct target_ops
*ops
,
1448 enum target_object object
,
1449 const char *annex
, const gdb_byte
*buf
,
1450 ULONGEST offset
, LONGEST len
,
1451 void (*progress
) (ULONGEST
, void *), void *baton
)
1455 /* Give the progress callback a chance to set up. */
1457 (*progress
) (0, baton
);
1459 while (xfered
< len
)
1461 LONGEST xfer
= target_write_partial (ops
, object
, annex
,
1462 (gdb_byte
*) buf
+ xfered
,
1463 offset
+ xfered
, len
- xfered
);
1471 (*progress
) (xfer
, baton
);
1480 target_write (struct target_ops
*ops
,
1481 enum target_object object
,
1482 const char *annex
, const gdb_byte
*buf
,
1483 ULONGEST offset
, LONGEST len
)
1485 return target_write_with_progress (ops
, object
, annex
, buf
, offset
, len
,
1489 /* Read OBJECT/ANNEX using OPS. Store the result in *BUF_P and return
1490 the size of the transferred data. PADDING additional bytes are
1491 available in *BUF_P. This is a helper function for
1492 target_read_alloc; see the declaration of that function for more
1496 target_read_alloc_1 (struct target_ops
*ops
, enum target_object object
,
1497 const char *annex
, gdb_byte
**buf_p
, int padding
)
1499 size_t buf_alloc
, buf_pos
;
1503 /* This function does not have a length parameter; it reads the
1504 entire OBJECT). Also, it doesn't support objects fetched partly
1505 from one target and partly from another (in a different stratum,
1506 e.g. a core file and an executable). Both reasons make it
1507 unsuitable for reading memory. */
1508 gdb_assert (object
!= TARGET_OBJECT_MEMORY
);
1510 /* Start by reading up to 4K at a time. The target will throttle
1511 this number down if necessary. */
1513 buf
= xmalloc (buf_alloc
);
1517 n
= target_read_partial (ops
, object
, annex
, &buf
[buf_pos
],
1518 buf_pos
, buf_alloc
- buf_pos
- padding
);
1521 /* An error occurred. */
1527 /* Read all there was. */
1537 /* If the buffer is filling up, expand it. */
1538 if (buf_alloc
< buf_pos
* 2)
1541 buf
= xrealloc (buf
, buf_alloc
);
1548 /* Read OBJECT/ANNEX using OPS. Store the result in *BUF_P and return
1549 the size of the transferred data. See the declaration in "target.h"
1550 function for more information about the return value. */
1553 target_read_alloc (struct target_ops
*ops
, enum target_object object
,
1554 const char *annex
, gdb_byte
**buf_p
)
1556 return target_read_alloc_1 (ops
, object
, annex
, buf_p
, 0);
1559 /* Read OBJECT/ANNEX using OPS. The result is NUL-terminated and
1560 returned as a string, allocated using xmalloc. If an error occurs
1561 or the transfer is unsupported, NULL is returned. Empty objects
1562 are returned as allocated but empty strings. A warning is issued
1563 if the result contains any embedded NUL bytes. */
1566 target_read_stralloc (struct target_ops
*ops
, enum target_object object
,
1570 LONGEST transferred
;
1572 transferred
= target_read_alloc_1 (ops
, object
, annex
, &buffer
, 1);
1574 if (transferred
< 0)
1577 if (transferred
== 0)
1578 return xstrdup ("");
1580 buffer
[transferred
] = 0;
1581 if (strlen (buffer
) < transferred
)
1582 warning (_("target object %d, annex %s, "
1583 "contained unexpected null characters"),
1584 (int) object
, annex
? annex
: "(none)");
1586 return (char *) buffer
;
1589 /* Memory transfer methods. */
1592 get_target_memory (struct target_ops
*ops
, CORE_ADDR addr
, gdb_byte
*buf
,
1595 if (target_read (ops
, TARGET_OBJECT_MEMORY
, NULL
, buf
, addr
, len
)
1597 memory_error (EIO
, addr
);
1601 get_target_memory_unsigned (struct target_ops
*ops
,
1602 CORE_ADDR addr
, int len
)
1604 gdb_byte buf
[sizeof (ULONGEST
)];
1606 gdb_assert (len
<= sizeof (buf
));
1607 get_target_memory (ops
, addr
, buf
, len
);
1608 return extract_unsigned_integer (buf
, len
);
1612 target_info (char *args
, int from_tty
)
1614 struct target_ops
*t
;
1615 int has_all_mem
= 0;
1617 if (symfile_objfile
!= NULL
)
1618 printf_unfiltered (_("Symbols from \"%s\".\n"), symfile_objfile
->name
);
1620 for (t
= target_stack
; t
!= NULL
; t
= t
->beneath
)
1622 if (!t
->to_has_memory
)
1625 if ((int) (t
->to_stratum
) <= (int) dummy_stratum
)
1628 printf_unfiltered (_("\tWhile running this, GDB does not access memory from...\n"));
1629 printf_unfiltered ("%s:\n", t
->to_longname
);
1630 (t
->to_files_info
) (t
);
1631 has_all_mem
= t
->to_has_all_memory
;
1635 /* This function is called before any new inferior is created, e.g.
1636 by running a program, attaching, or connecting to a target.
1637 It cleans up any state from previous invocations which might
1638 change between runs. This is a subset of what target_preopen
1639 resets (things which might change between targets). */
1642 target_pre_inferior (int from_tty
)
1644 invalidate_target_mem_regions ();
1646 target_clear_description ();
1649 /* This is to be called by the open routine before it does
1653 target_preopen (int from_tty
)
1657 if (target_has_execution
)
1660 || query (_("A program is being debugged already. Kill it? ")))
1663 error (_("Program not killed."));
1666 /* Calling target_kill may remove the target from the stack. But if
1667 it doesn't (which seems like a win for UDI), remove it now. */
1669 if (target_has_execution
)
1672 target_pre_inferior (from_tty
);
1675 /* Detach a target after doing deferred register stores. */
1678 target_detach (char *args
, int from_tty
)
1680 (current_target
.to_detach
) (args
, from_tty
);
1684 target_disconnect (char *args
, int from_tty
)
1686 struct target_ops
*t
;
1688 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
1689 if (t
->to_disconnect
!= NULL
)
1692 fprintf_unfiltered (gdb_stdlog
, "target_disconnect (%s, %d)\n",
1694 t
->to_disconnect (t
, args
, from_tty
);
1702 target_async_mask (int mask
)
1704 int saved_async_masked_status
= target_async_mask_value
;
1705 target_async_mask_value
= mask
;
1706 return saved_async_masked_status
;
1709 /* Look through the list of possible targets for a target that can
1713 target_follow_fork (int follow_child
)
1715 struct target_ops
*t
;
1717 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
1719 if (t
->to_follow_fork
!= NULL
)
1721 int retval
= t
->to_follow_fork (t
, follow_child
);
1723 fprintf_unfiltered (gdb_stdlog
, "target_follow_fork (%d) = %d\n",
1724 follow_child
, retval
);
1729 /* Some target returned a fork event, but did not know how to follow it. */
1730 internal_error (__FILE__
, __LINE__
,
1731 "could not find a target to follow fork");
1734 /* Look for a target which can describe architectural features, starting
1735 from TARGET. If we find one, return its description. */
1737 const struct target_desc
*
1738 target_read_description (struct target_ops
*target
)
1740 struct target_ops
*t
;
1742 for (t
= target
; t
!= NULL
; t
= t
->beneath
)
1743 if (t
->to_read_description
!= NULL
)
1745 const struct target_desc
*tdesc
;
1747 tdesc
= t
->to_read_description (t
);
1755 /* Look through the currently pushed targets. If none of them will
1756 be able to restart the currently running process, issue an error
1760 target_require_runnable (void)
1762 struct target_ops
*t
;
1764 for (t
= target_stack
; t
!= NULL
; t
= t
->beneath
)
1766 /* If this target knows how to create a new program, then
1767 assume we will still be able to after killing the current
1768 one. Either killing and mourning will not pop T, or else
1769 find_default_run_target will find it again. */
1770 if (t
->to_create_inferior
!= NULL
)
1773 /* Do not worry about thread_stratum targets that can not
1774 create inferiors. Assume they will be pushed again if
1775 necessary, and continue to the process_stratum. */
1776 if (t
->to_stratum
== thread_stratum
)
1780 The \"%s\" target does not support \"run\". Try \"help target\" or \"continue\"."),
1784 /* This function is only called if the target is running. In that
1785 case there should have been a process_stratum target and it
1786 should either know how to create inferiors, or not... */
1787 internal_error (__FILE__
, __LINE__
, "No targets found");
1790 /* Look through the list of possible targets for a target that can
1791 execute a run or attach command without any other data. This is
1792 used to locate the default process stratum.
1794 Result is always valid (error() is called for errors). */
1796 static struct target_ops
*
1797 find_default_run_target (char *do_mesg
)
1799 struct target_ops
**t
;
1800 struct target_ops
*runable
= NULL
;
1805 for (t
= target_structs
; t
< target_structs
+ target_struct_size
;
1808 if ((*t
)->to_can_run
&& target_can_run (*t
))
1816 error (_("Don't know how to %s. Try \"help target\"."), do_mesg
);
1822 find_default_attach (char *args
, int from_tty
)
1824 struct target_ops
*t
;
1826 t
= find_default_run_target ("attach");
1827 (t
->to_attach
) (args
, from_tty
);
1832 find_default_create_inferior (char *exec_file
, char *allargs
, char **env
,
1835 struct target_ops
*t
;
1837 t
= find_default_run_target ("run");
1838 (t
->to_create_inferior
) (exec_file
, allargs
, env
, from_tty
);
1843 default_region_ok_for_hw_watchpoint (CORE_ADDR addr
, int len
)
1845 return (len
<= TYPE_LENGTH (builtin_type_void_data_ptr
));
1861 return_minus_one (void)
1867 * Resize the to_sections pointer. Also make sure that anyone that
1868 * was holding on to an old value of it gets updated.
1869 * Returns the old size.
1873 target_resize_to_sections (struct target_ops
*target
, int num_added
)
1875 struct target_ops
**t
;
1876 struct section_table
*old_value
;
1879 old_value
= target
->to_sections
;
1881 if (target
->to_sections
)
1883 old_count
= target
->to_sections_end
- target
->to_sections
;
1884 target
->to_sections
= (struct section_table
*)
1885 xrealloc ((char *) target
->to_sections
,
1886 (sizeof (struct section_table
)) * (num_added
+ old_count
));
1891 target
->to_sections
= (struct section_table
*)
1892 xmalloc ((sizeof (struct section_table
)) * num_added
);
1894 target
->to_sections_end
= target
->to_sections
+ (num_added
+ old_count
);
1896 /* Check to see if anyone else was pointing to this structure.
1897 If old_value was null, then no one was. */
1901 for (t
= target_structs
; t
< target_structs
+ target_struct_size
;
1904 if ((*t
)->to_sections
== old_value
)
1906 (*t
)->to_sections
= target
->to_sections
;
1907 (*t
)->to_sections_end
= target
->to_sections_end
;
1910 /* There is a flattened view of the target stack in current_target,
1911 so its to_sections pointer might also need updating. */
1912 if (current_target
.to_sections
== old_value
)
1914 current_target
.to_sections
= target
->to_sections
;
1915 current_target
.to_sections_end
= target
->to_sections_end
;
1923 /* Remove all target sections taken from ABFD.
1925 Scan the current target stack for targets whose section tables
1926 refer to sections from BFD, and remove those sections. We use this
1927 when we notice that the inferior has unloaded a shared object, for
1930 remove_target_sections (bfd
*abfd
)
1932 struct target_ops
**t
;
1934 for (t
= target_structs
; t
< target_structs
+ target_struct_size
; t
++)
1936 struct section_table
*src
, *dest
;
1938 dest
= (*t
)->to_sections
;
1939 for (src
= (*t
)->to_sections
; src
< (*t
)->to_sections_end
; src
++)
1940 if (src
->bfd
!= abfd
)
1942 /* Keep this section. */
1943 if (dest
< src
) *dest
= *src
;
1947 /* If we've dropped any sections, resize the section table. */
1949 target_resize_to_sections (*t
, dest
- src
);
1956 /* Find a single runnable target in the stack and return it. If for
1957 some reason there is more than one, return NULL. */
1960 find_run_target (void)
1962 struct target_ops
**t
;
1963 struct target_ops
*runable
= NULL
;
1968 for (t
= target_structs
; t
< target_structs
+ target_struct_size
; ++t
)
1970 if ((*t
)->to_can_run
&& target_can_run (*t
))
1977 return (count
== 1 ? runable
: NULL
);
1980 /* Find a single core_stratum target in the list of targets and return it.
1981 If for some reason there is more than one, return NULL. */
1984 find_core_target (void)
1986 struct target_ops
**t
;
1987 struct target_ops
*runable
= NULL
;
1992 for (t
= target_structs
; t
< target_structs
+ target_struct_size
;
1995 if ((*t
)->to_stratum
== core_stratum
)
2002 return (count
== 1 ? runable
: NULL
);
2006 * Find the next target down the stack from the specified target.
2010 find_target_beneath (struct target_ops
*t
)
2016 /* The inferior process has died. Long live the inferior! */
2019 generic_mourn_inferior (void)
2021 extern int show_breakpoint_hit_counts
;
2023 inferior_ptid
= null_ptid
;
2025 breakpoint_init_inferior (inf_exited
);
2026 registers_changed ();
2028 reopen_exec_file ();
2029 reinit_frame_cache ();
2031 /* It is confusing to the user for ignore counts to stick around
2032 from previous runs of the inferior. So clear them. */
2033 /* However, it is more confusing for the ignore counts to disappear when
2034 using hit counts. So don't clear them if we're counting hits. */
2035 if (!show_breakpoint_hit_counts
)
2036 breakpoint_clear_ignore_counts ();
2038 if (deprecated_detach_hook
)
2039 deprecated_detach_hook ();
2042 /* Helper function for child_wait and the derivatives of child_wait.
2043 HOSTSTATUS is the waitstatus from wait() or the equivalent; store our
2044 translation of that in OURSTATUS. */
2046 store_waitstatus (struct target_waitstatus
*ourstatus
, int hoststatus
)
2048 if (WIFEXITED (hoststatus
))
2050 ourstatus
->kind
= TARGET_WAITKIND_EXITED
;
2051 ourstatus
->value
.integer
= WEXITSTATUS (hoststatus
);
2053 else if (!WIFSTOPPED (hoststatus
))
2055 ourstatus
->kind
= TARGET_WAITKIND_SIGNALLED
;
2056 ourstatus
->value
.sig
= target_signal_from_host (WTERMSIG (hoststatus
));
2060 ourstatus
->kind
= TARGET_WAITKIND_STOPPED
;
2061 ourstatus
->value
.sig
= target_signal_from_host (WSTOPSIG (hoststatus
));
2065 /* Returns zero to leave the inferior alone, one to interrupt it. */
2066 int (*target_activity_function
) (void);
2067 int target_activity_fd
;
2069 /* Convert a normal process ID to a string. Returns the string in a
2073 normal_pid_to_str (ptid_t ptid
)
2075 static char buf
[32];
2077 xsnprintf (buf
, sizeof buf
, "process %d", ptid_get_pid (ptid
));
2081 /* Error-catcher for target_find_memory_regions */
2082 static int dummy_find_memory_regions (int (*ignore1
) (), void *ignore2
)
2084 error (_("No target."));
2088 /* Error-catcher for target_make_corefile_notes */
2089 static char * dummy_make_corefile_notes (bfd
*ignore1
, int *ignore2
)
2091 error (_("No target."));
2095 /* Set up the handful of non-empty slots needed by the dummy target
2099 init_dummy_target (void)
2101 dummy_target
.to_shortname
= "None";
2102 dummy_target
.to_longname
= "None";
2103 dummy_target
.to_doc
= "";
2104 dummy_target
.to_attach
= find_default_attach
;
2105 dummy_target
.to_create_inferior
= find_default_create_inferior
;
2106 dummy_target
.to_pid_to_str
= normal_pid_to_str
;
2107 dummy_target
.to_stratum
= dummy_stratum
;
2108 dummy_target
.to_find_memory_regions
= dummy_find_memory_regions
;
2109 dummy_target
.to_make_corefile_notes
= dummy_make_corefile_notes
;
2110 dummy_target
.to_xfer_partial
= default_xfer_partial
;
2111 dummy_target
.to_magic
= OPS_MAGIC
;
2115 debug_to_open (char *args
, int from_tty
)
2117 debug_target
.to_open (args
, from_tty
);
2119 fprintf_unfiltered (gdb_stdlog
, "target_open (%s, %d)\n", args
, from_tty
);
2123 debug_to_close (int quitting
)
2125 target_close (&debug_target
, quitting
);
2126 fprintf_unfiltered (gdb_stdlog
, "target_close (%d)\n", quitting
);
2130 target_close (struct target_ops
*targ
, int quitting
)
2132 if (targ
->to_xclose
!= NULL
)
2133 targ
->to_xclose (targ
, quitting
);
2134 else if (targ
->to_close
!= NULL
)
2135 targ
->to_close (quitting
);
2139 debug_to_attach (char *args
, int from_tty
)
2141 debug_target
.to_attach (args
, from_tty
);
2143 fprintf_unfiltered (gdb_stdlog
, "target_attach (%s, %d)\n", args
, from_tty
);
2148 debug_to_post_attach (int pid
)
2150 debug_target
.to_post_attach (pid
);
2152 fprintf_unfiltered (gdb_stdlog
, "target_post_attach (%d)\n", pid
);
2156 debug_to_detach (char *args
, int from_tty
)
2158 debug_target
.to_detach (args
, from_tty
);
2160 fprintf_unfiltered (gdb_stdlog
, "target_detach (%s, %d)\n", args
, from_tty
);
2164 debug_to_resume (ptid_t ptid
, int step
, enum target_signal siggnal
)
2166 debug_target
.to_resume (ptid
, step
, siggnal
);
2168 fprintf_unfiltered (gdb_stdlog
, "target_resume (%d, %s, %s)\n", PIDGET (ptid
),
2169 step
? "step" : "continue",
2170 target_signal_to_name (siggnal
));
2174 debug_to_wait (ptid_t ptid
, struct target_waitstatus
*status
)
2178 retval
= debug_target
.to_wait (ptid
, status
);
2180 fprintf_unfiltered (gdb_stdlog
,
2181 "target_wait (%d, status) = %d, ", PIDGET (ptid
),
2183 fprintf_unfiltered (gdb_stdlog
, "status->kind = ");
2184 switch (status
->kind
)
2186 case TARGET_WAITKIND_EXITED
:
2187 fprintf_unfiltered (gdb_stdlog
, "exited, status = %d\n",
2188 status
->value
.integer
);
2190 case TARGET_WAITKIND_STOPPED
:
2191 fprintf_unfiltered (gdb_stdlog
, "stopped, signal = %s\n",
2192 target_signal_to_name (status
->value
.sig
));
2194 case TARGET_WAITKIND_SIGNALLED
:
2195 fprintf_unfiltered (gdb_stdlog
, "signalled, signal = %s\n",
2196 target_signal_to_name (status
->value
.sig
));
2198 case TARGET_WAITKIND_LOADED
:
2199 fprintf_unfiltered (gdb_stdlog
, "loaded\n");
2201 case TARGET_WAITKIND_FORKED
:
2202 fprintf_unfiltered (gdb_stdlog
, "forked\n");
2204 case TARGET_WAITKIND_VFORKED
:
2205 fprintf_unfiltered (gdb_stdlog
, "vforked\n");
2207 case TARGET_WAITKIND_EXECD
:
2208 fprintf_unfiltered (gdb_stdlog
, "execd\n");
2210 case TARGET_WAITKIND_SPURIOUS
:
2211 fprintf_unfiltered (gdb_stdlog
, "spurious\n");
2214 fprintf_unfiltered (gdb_stdlog
, "unknown???\n");
2222 debug_print_register (const char * func
,
2223 struct regcache
*regcache
, int regno
)
2225 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
2226 fprintf_unfiltered (gdb_stdlog
, "%s ", func
);
2227 if (regno
>= 0 && regno
< gdbarch_num_regs (gdbarch
)
2228 + gdbarch_num_pseudo_regs (gdbarch
)
2229 && gdbarch_register_name (gdbarch
, regno
) != NULL
2230 && gdbarch_register_name (gdbarch
, regno
)[0] != '\0')
2231 fprintf_unfiltered (gdb_stdlog
, "(%s)",
2232 gdbarch_register_name (gdbarch
, regno
));
2234 fprintf_unfiltered (gdb_stdlog
, "(%d)", regno
);
2237 int i
, size
= register_size (gdbarch
, regno
);
2238 unsigned char buf
[MAX_REGISTER_SIZE
];
2239 regcache_cooked_read (regcache
, regno
, buf
);
2240 fprintf_unfiltered (gdb_stdlog
, " = ");
2241 for (i
= 0; i
< size
; i
++)
2243 fprintf_unfiltered (gdb_stdlog
, "%02x", buf
[i
]);
2245 if (size
<= sizeof (LONGEST
))
2247 ULONGEST val
= extract_unsigned_integer (buf
, size
);
2248 fprintf_unfiltered (gdb_stdlog
, " 0x%s %s",
2249 paddr_nz (val
), paddr_d (val
));
2252 fprintf_unfiltered (gdb_stdlog
, "\n");
2256 debug_to_fetch_registers (struct regcache
*regcache
, int regno
)
2258 debug_target
.to_fetch_registers (regcache
, regno
);
2259 debug_print_register ("target_fetch_registers", regcache
, regno
);
2263 debug_to_store_registers (struct regcache
*regcache
, int regno
)
2265 debug_target
.to_store_registers (regcache
, regno
);
2266 debug_print_register ("target_store_registers", regcache
, regno
);
2267 fprintf_unfiltered (gdb_stdlog
, "\n");
2271 debug_to_prepare_to_store (struct regcache
*regcache
)
2273 debug_target
.to_prepare_to_store (regcache
);
2275 fprintf_unfiltered (gdb_stdlog
, "target_prepare_to_store ()\n");
2279 deprecated_debug_xfer_memory (CORE_ADDR memaddr
, bfd_byte
*myaddr
, int len
,
2280 int write
, struct mem_attrib
*attrib
,
2281 struct target_ops
*target
)
2285 retval
= debug_target
.deprecated_xfer_memory (memaddr
, myaddr
, len
, write
,
2288 fprintf_unfiltered (gdb_stdlog
,
2289 "target_xfer_memory (0x%x, xxx, %d, %s, xxx) = %d",
2290 (unsigned int) memaddr
, /* possable truncate long long */
2291 len
, write
? "write" : "read", retval
);
2297 fputs_unfiltered (", bytes =", gdb_stdlog
);
2298 for (i
= 0; i
< retval
; i
++)
2300 if ((((long) &(myaddr
[i
])) & 0xf) == 0)
2302 if (targetdebug
< 2 && i
> 0)
2304 fprintf_unfiltered (gdb_stdlog
, " ...");
2307 fprintf_unfiltered (gdb_stdlog
, "\n");
2310 fprintf_unfiltered (gdb_stdlog
, " %02x", myaddr
[i
] & 0xff);
2314 fputc_unfiltered ('\n', gdb_stdlog
);
2320 debug_to_files_info (struct target_ops
*target
)
2322 debug_target
.to_files_info (target
);
2324 fprintf_unfiltered (gdb_stdlog
, "target_files_info (xxx)\n");
2328 debug_to_insert_breakpoint (struct bp_target_info
*bp_tgt
)
2332 retval
= debug_target
.to_insert_breakpoint (bp_tgt
);
2334 fprintf_unfiltered (gdb_stdlog
,
2335 "target_insert_breakpoint (0x%lx, xxx) = %ld\n",
2336 (unsigned long) bp_tgt
->placed_address
,
2337 (unsigned long) retval
);
2342 debug_to_remove_breakpoint (struct bp_target_info
*bp_tgt
)
2346 retval
= debug_target
.to_remove_breakpoint (bp_tgt
);
2348 fprintf_unfiltered (gdb_stdlog
,
2349 "target_remove_breakpoint (0x%lx, xxx) = %ld\n",
2350 (unsigned long) bp_tgt
->placed_address
,
2351 (unsigned long) retval
);
2356 debug_to_can_use_hw_breakpoint (int type
, int cnt
, int from_tty
)
2360 retval
= debug_target
.to_can_use_hw_breakpoint (type
, cnt
, from_tty
);
2362 fprintf_unfiltered (gdb_stdlog
,
2363 "target_can_use_hw_breakpoint (%ld, %ld, %ld) = %ld\n",
2364 (unsigned long) type
,
2365 (unsigned long) cnt
,
2366 (unsigned long) from_tty
,
2367 (unsigned long) retval
);
2372 debug_to_region_ok_for_hw_watchpoint (CORE_ADDR addr
, int len
)
2376 retval
= debug_target
.to_region_ok_for_hw_watchpoint (addr
, len
);
2378 fprintf_unfiltered (gdb_stdlog
,
2379 "TARGET_REGION_OK_FOR_HW_WATCHPOINT (%ld, %ld) = 0x%lx\n",
2380 (unsigned long) addr
,
2381 (unsigned long) len
,
2382 (unsigned long) retval
);
2387 debug_to_stopped_by_watchpoint (void)
2391 retval
= debug_target
.to_stopped_by_watchpoint ();
2393 fprintf_unfiltered (gdb_stdlog
,
2394 "STOPPED_BY_WATCHPOINT () = %ld\n",
2395 (unsigned long) retval
);
2400 debug_to_stopped_data_address (struct target_ops
*target
, CORE_ADDR
*addr
)
2404 retval
= debug_target
.to_stopped_data_address (target
, addr
);
2406 fprintf_unfiltered (gdb_stdlog
,
2407 "target_stopped_data_address ([0x%lx]) = %ld\n",
2408 (unsigned long)*addr
,
2409 (unsigned long)retval
);
2414 debug_to_insert_hw_breakpoint (struct bp_target_info
*bp_tgt
)
2418 retval
= debug_target
.to_insert_hw_breakpoint (bp_tgt
);
2420 fprintf_unfiltered (gdb_stdlog
,
2421 "target_insert_hw_breakpoint (0x%lx, xxx) = %ld\n",
2422 (unsigned long) bp_tgt
->placed_address
,
2423 (unsigned long) retval
);
2428 debug_to_remove_hw_breakpoint (struct bp_target_info
*bp_tgt
)
2432 retval
= debug_target
.to_remove_hw_breakpoint (bp_tgt
);
2434 fprintf_unfiltered (gdb_stdlog
,
2435 "target_remove_hw_breakpoint (0x%lx, xxx) = %ld\n",
2436 (unsigned long) bp_tgt
->placed_address
,
2437 (unsigned long) retval
);
2442 debug_to_insert_watchpoint (CORE_ADDR addr
, int len
, int type
)
2446 retval
= debug_target
.to_insert_watchpoint (addr
, len
, type
);
2448 fprintf_unfiltered (gdb_stdlog
,
2449 "target_insert_watchpoint (0x%lx, %d, %d) = %ld\n",
2450 (unsigned long) addr
, len
, type
, (unsigned long) retval
);
2455 debug_to_remove_watchpoint (CORE_ADDR addr
, int len
, int type
)
2459 retval
= debug_target
.to_remove_watchpoint (addr
, len
, type
);
2461 fprintf_unfiltered (gdb_stdlog
,
2462 "target_remove_watchpoint (0x%lx, %d, %d) = %ld\n",
2463 (unsigned long) addr
, len
, type
, (unsigned long) retval
);
2468 debug_to_terminal_init (void)
2470 debug_target
.to_terminal_init ();
2472 fprintf_unfiltered (gdb_stdlog
, "target_terminal_init ()\n");
2476 debug_to_terminal_inferior (void)
2478 debug_target
.to_terminal_inferior ();
2480 fprintf_unfiltered (gdb_stdlog
, "target_terminal_inferior ()\n");
2484 debug_to_terminal_ours_for_output (void)
2486 debug_target
.to_terminal_ours_for_output ();
2488 fprintf_unfiltered (gdb_stdlog
, "target_terminal_ours_for_output ()\n");
2492 debug_to_terminal_ours (void)
2494 debug_target
.to_terminal_ours ();
2496 fprintf_unfiltered (gdb_stdlog
, "target_terminal_ours ()\n");
2500 debug_to_terminal_save_ours (void)
2502 debug_target
.to_terminal_save_ours ();
2504 fprintf_unfiltered (gdb_stdlog
, "target_terminal_save_ours ()\n");
2508 debug_to_terminal_info (char *arg
, int from_tty
)
2510 debug_target
.to_terminal_info (arg
, from_tty
);
2512 fprintf_unfiltered (gdb_stdlog
, "target_terminal_info (%s, %d)\n", arg
,
2517 debug_to_kill (void)
2519 debug_target
.to_kill ();
2521 fprintf_unfiltered (gdb_stdlog
, "target_kill ()\n");
2525 debug_to_load (char *args
, int from_tty
)
2527 debug_target
.to_load (args
, from_tty
);
2529 fprintf_unfiltered (gdb_stdlog
, "target_load (%s, %d)\n", args
, from_tty
);
2533 debug_to_lookup_symbol (char *name
, CORE_ADDR
*addrp
)
2537 retval
= debug_target
.to_lookup_symbol (name
, addrp
);
2539 fprintf_unfiltered (gdb_stdlog
, "target_lookup_symbol (%s, xxx)\n", name
);
2545 debug_to_create_inferior (char *exec_file
, char *args
, char **env
,
2548 debug_target
.to_create_inferior (exec_file
, args
, env
, from_tty
);
2550 fprintf_unfiltered (gdb_stdlog
, "target_create_inferior (%s, %s, xxx, %d)\n",
2551 exec_file
, args
, from_tty
);
2555 debug_to_post_startup_inferior (ptid_t ptid
)
2557 debug_target
.to_post_startup_inferior (ptid
);
2559 fprintf_unfiltered (gdb_stdlog
, "target_post_startup_inferior (%d)\n",
2564 debug_to_acknowledge_created_inferior (int pid
)
2566 debug_target
.to_acknowledge_created_inferior (pid
);
2568 fprintf_unfiltered (gdb_stdlog
, "target_acknowledge_created_inferior (%d)\n",
2573 debug_to_insert_fork_catchpoint (int pid
)
2575 debug_target
.to_insert_fork_catchpoint (pid
);
2577 fprintf_unfiltered (gdb_stdlog
, "target_insert_fork_catchpoint (%d)\n",
2582 debug_to_remove_fork_catchpoint (int pid
)
2586 retval
= debug_target
.to_remove_fork_catchpoint (pid
);
2588 fprintf_unfiltered (gdb_stdlog
, "target_remove_fork_catchpoint (%d) = %d\n",
2595 debug_to_insert_vfork_catchpoint (int pid
)
2597 debug_target
.to_insert_vfork_catchpoint (pid
);
2599 fprintf_unfiltered (gdb_stdlog
, "target_insert_vfork_catchpoint (%d)\n",
2604 debug_to_remove_vfork_catchpoint (int pid
)
2608 retval
= debug_target
.to_remove_vfork_catchpoint (pid
);
2610 fprintf_unfiltered (gdb_stdlog
, "target_remove_vfork_catchpoint (%d) = %d\n",
2617 debug_to_insert_exec_catchpoint (int pid
)
2619 debug_target
.to_insert_exec_catchpoint (pid
);
2621 fprintf_unfiltered (gdb_stdlog
, "target_insert_exec_catchpoint (%d)\n",
2626 debug_to_remove_exec_catchpoint (int pid
)
2630 retval
= debug_target
.to_remove_exec_catchpoint (pid
);
2632 fprintf_unfiltered (gdb_stdlog
, "target_remove_exec_catchpoint (%d) = %d\n",
2639 debug_to_reported_exec_events_per_exec_call (void)
2641 int reported_exec_events
;
2643 reported_exec_events
= debug_target
.to_reported_exec_events_per_exec_call ();
2645 fprintf_unfiltered (gdb_stdlog
,
2646 "target_reported_exec_events_per_exec_call () = %d\n",
2647 reported_exec_events
);
2649 return reported_exec_events
;
2653 debug_to_has_exited (int pid
, int wait_status
, int *exit_status
)
2657 has_exited
= debug_target
.to_has_exited (pid
, wait_status
, exit_status
);
2659 fprintf_unfiltered (gdb_stdlog
, "target_has_exited (%d, %d, %d) = %d\n",
2660 pid
, wait_status
, *exit_status
, has_exited
);
2666 debug_to_mourn_inferior (void)
2668 debug_target
.to_mourn_inferior ();
2670 fprintf_unfiltered (gdb_stdlog
, "target_mourn_inferior ()\n");
2674 debug_to_can_run (void)
2678 retval
= debug_target
.to_can_run ();
2680 fprintf_unfiltered (gdb_stdlog
, "target_can_run () = %d\n", retval
);
2686 debug_to_notice_signals (ptid_t ptid
)
2688 debug_target
.to_notice_signals (ptid
);
2690 fprintf_unfiltered (gdb_stdlog
, "target_notice_signals (%d)\n",
2695 debug_to_thread_alive (ptid_t ptid
)
2699 retval
= debug_target
.to_thread_alive (ptid
);
2701 fprintf_unfiltered (gdb_stdlog
, "target_thread_alive (%d) = %d\n",
2702 PIDGET (ptid
), retval
);
2708 debug_to_find_new_threads (void)
2710 debug_target
.to_find_new_threads ();
2712 fputs_unfiltered ("target_find_new_threads ()\n", gdb_stdlog
);
2716 debug_to_stop (void)
2718 debug_target
.to_stop ();
2720 fprintf_unfiltered (gdb_stdlog
, "target_stop ()\n");
2724 debug_to_rcmd (char *command
,
2725 struct ui_file
*outbuf
)
2727 debug_target
.to_rcmd (command
, outbuf
);
2728 fprintf_unfiltered (gdb_stdlog
, "target_rcmd (%s, ...)\n", command
);
2732 debug_to_pid_to_exec_file (int pid
)
2736 exec_file
= debug_target
.to_pid_to_exec_file (pid
);
2738 fprintf_unfiltered (gdb_stdlog
, "target_pid_to_exec_file (%d) = %s\n",
2745 setup_target_debug (void)
2747 memcpy (&debug_target
, ¤t_target
, sizeof debug_target
);
2749 current_target
.to_open
= debug_to_open
;
2750 current_target
.to_close
= debug_to_close
;
2751 current_target
.to_attach
= debug_to_attach
;
2752 current_target
.to_post_attach
= debug_to_post_attach
;
2753 current_target
.to_detach
= debug_to_detach
;
2754 current_target
.to_resume
= debug_to_resume
;
2755 current_target
.to_wait
= debug_to_wait
;
2756 current_target
.to_fetch_registers
= debug_to_fetch_registers
;
2757 current_target
.to_store_registers
= debug_to_store_registers
;
2758 current_target
.to_prepare_to_store
= debug_to_prepare_to_store
;
2759 current_target
.deprecated_xfer_memory
= deprecated_debug_xfer_memory
;
2760 current_target
.to_files_info
= debug_to_files_info
;
2761 current_target
.to_insert_breakpoint
= debug_to_insert_breakpoint
;
2762 current_target
.to_remove_breakpoint
= debug_to_remove_breakpoint
;
2763 current_target
.to_can_use_hw_breakpoint
= debug_to_can_use_hw_breakpoint
;
2764 current_target
.to_insert_hw_breakpoint
= debug_to_insert_hw_breakpoint
;
2765 current_target
.to_remove_hw_breakpoint
= debug_to_remove_hw_breakpoint
;
2766 current_target
.to_insert_watchpoint
= debug_to_insert_watchpoint
;
2767 current_target
.to_remove_watchpoint
= debug_to_remove_watchpoint
;
2768 current_target
.to_stopped_by_watchpoint
= debug_to_stopped_by_watchpoint
;
2769 current_target
.to_stopped_data_address
= debug_to_stopped_data_address
;
2770 current_target
.to_region_ok_for_hw_watchpoint
= debug_to_region_ok_for_hw_watchpoint
;
2771 current_target
.to_terminal_init
= debug_to_terminal_init
;
2772 current_target
.to_terminal_inferior
= debug_to_terminal_inferior
;
2773 current_target
.to_terminal_ours_for_output
= debug_to_terminal_ours_for_output
;
2774 current_target
.to_terminal_ours
= debug_to_terminal_ours
;
2775 current_target
.to_terminal_save_ours
= debug_to_terminal_save_ours
;
2776 current_target
.to_terminal_info
= debug_to_terminal_info
;
2777 current_target
.to_kill
= debug_to_kill
;
2778 current_target
.to_load
= debug_to_load
;
2779 current_target
.to_lookup_symbol
= debug_to_lookup_symbol
;
2780 current_target
.to_create_inferior
= debug_to_create_inferior
;
2781 current_target
.to_post_startup_inferior
= debug_to_post_startup_inferior
;
2782 current_target
.to_acknowledge_created_inferior
= debug_to_acknowledge_created_inferior
;
2783 current_target
.to_insert_fork_catchpoint
= debug_to_insert_fork_catchpoint
;
2784 current_target
.to_remove_fork_catchpoint
= debug_to_remove_fork_catchpoint
;
2785 current_target
.to_insert_vfork_catchpoint
= debug_to_insert_vfork_catchpoint
;
2786 current_target
.to_remove_vfork_catchpoint
= debug_to_remove_vfork_catchpoint
;
2787 current_target
.to_insert_exec_catchpoint
= debug_to_insert_exec_catchpoint
;
2788 current_target
.to_remove_exec_catchpoint
= debug_to_remove_exec_catchpoint
;
2789 current_target
.to_reported_exec_events_per_exec_call
= debug_to_reported_exec_events_per_exec_call
;
2790 current_target
.to_has_exited
= debug_to_has_exited
;
2791 current_target
.to_mourn_inferior
= debug_to_mourn_inferior
;
2792 current_target
.to_can_run
= debug_to_can_run
;
2793 current_target
.to_notice_signals
= debug_to_notice_signals
;
2794 current_target
.to_thread_alive
= debug_to_thread_alive
;
2795 current_target
.to_find_new_threads
= debug_to_find_new_threads
;
2796 current_target
.to_stop
= debug_to_stop
;
2797 current_target
.to_rcmd
= debug_to_rcmd
;
2798 current_target
.to_pid_to_exec_file
= debug_to_pid_to_exec_file
;
2802 static char targ_desc
[] =
2803 "Names of targets and files being debugged.\n\
2804 Shows the entire stack of targets currently in use (including the exec-file,\n\
2805 core-file, and process, if any), as well as the symbol file name.";
2808 do_monitor_command (char *cmd
,
2811 if ((current_target
.to_rcmd
2812 == (void (*) (char *, struct ui_file
*)) tcomplain
)
2813 || (current_target
.to_rcmd
== debug_to_rcmd
2814 && (debug_target
.to_rcmd
2815 == (void (*) (char *, struct ui_file
*)) tcomplain
)))
2816 error (_("\"monitor\" command not supported by this target."));
2817 target_rcmd (cmd
, gdb_stdtarg
);
2820 /* Print the name of each layers of our target stack. */
2823 maintenance_print_target_stack (char *cmd
, int from_tty
)
2825 struct target_ops
*t
;
2827 printf_filtered (_("The current target stack is:\n"));
2829 for (t
= target_stack
; t
!= NULL
; t
= t
->beneath
)
2831 printf_filtered (" - %s (%s)\n", t
->to_shortname
, t
->to_longname
);
2836 initialize_targets (void)
2838 init_dummy_target ();
2839 push_target (&dummy_target
);
2841 add_info ("target", target_info
, targ_desc
);
2842 add_info ("files", target_info
, targ_desc
);
2844 add_setshow_zinteger_cmd ("target", class_maintenance
, &targetdebug
, _("\
2845 Set target debugging."), _("\
2846 Show target debugging."), _("\
2847 When non-zero, target debugging is enabled. Higher numbers are more\n\
2848 verbose. Changes do not take effect until the next \"run\" or \"target\"\n\
2852 &setdebuglist
, &showdebuglist
);
2854 add_setshow_boolean_cmd ("trust-readonly-sections", class_support
,
2855 &trust_readonly
, _("\
2856 Set mode for reading from readonly sections."), _("\
2857 Show mode for reading from readonly sections."), _("\
2858 When this mode is on, memory reads from readonly sections (such as .text)\n\
2859 will be read from the object file instead of from the target. This will\n\
2860 result in significant performance improvement for remote targets."),
2862 show_trust_readonly
,
2863 &setlist
, &showlist
);
2865 add_com ("monitor", class_obscure
, do_monitor_command
,
2866 _("Send a command to the remote monitor (remote targets only)."));
2868 add_cmd ("target-stack", class_maintenance
, maintenance_print_target_stack
,
2869 _("Print the name of each layer of the internal target stack."),
2870 &maintenanceprintlist
);
2872 target_dcache
= dcache_init ();