1 /* Select target systems and architectures at runtime for GDB.
3 Copyright (C) 1990-2014 Free Software Foundation, Inc.
5 Contributed by Cygnus Support.
7 This file is part of GDB.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
26 #include "target-dcache.h"
36 #include "gdb_assert.h"
38 #include "exceptions.h"
39 #include "target-descriptions.h"
40 #include "gdbthread.h"
43 #include "inline-frame.h"
44 #include "tracepoint.h"
45 #include "gdb/fileio.h"
49 static void target_info (char *, int);
51 static void default_terminal_info (struct target_ops
*, const char *, int);
53 static int default_watchpoint_addr_within_range (struct target_ops
*,
54 CORE_ADDR
, CORE_ADDR
, int);
56 static int default_region_ok_for_hw_watchpoint (struct target_ops
*,
59 static void default_rcmd (struct target_ops
*, char *, struct ui_file
*);
61 static ptid_t
default_get_ada_task_ptid (struct target_ops
*self
,
64 static int default_follow_fork (struct target_ops
*self
, int follow_child
,
67 static void default_mourn_inferior (struct target_ops
*self
);
69 static int default_search_memory (struct target_ops
*ops
,
71 ULONGEST search_space_len
,
72 const gdb_byte
*pattern
,
74 CORE_ADDR
*found_addrp
);
76 static void tcomplain (void) ATTRIBUTE_NORETURN
;
78 static int return_zero (struct target_ops
*);
80 static int return_zero_has_execution (struct target_ops
*, ptid_t
);
82 static void target_command (char *, int);
84 static struct target_ops
*find_default_run_target (char *);
86 static struct gdbarch
*default_thread_architecture (struct target_ops
*ops
,
89 static int dummy_find_memory_regions (struct target_ops
*self
,
90 find_memory_region_ftype ignore1
,
93 static char *dummy_make_corefile_notes (struct target_ops
*self
,
94 bfd
*ignore1
, int *ignore2
);
96 static char *default_pid_to_str (struct target_ops
*ops
, ptid_t ptid
);
98 static int find_default_can_async_p (struct target_ops
*ignore
);
100 static int find_default_is_async_p (struct target_ops
*ignore
);
102 static enum exec_direction_kind default_execution_direction
103 (struct target_ops
*self
);
105 static CORE_ADDR
default_target_decr_pc_after_break (struct target_ops
*ops
,
106 struct gdbarch
*gdbarch
);
108 #include "target-delegates.c"
110 static void init_dummy_target (void);
112 static struct target_ops debug_target
;
114 static void debug_to_open (char *, int);
116 static void debug_to_prepare_to_store (struct target_ops
*self
,
119 static void debug_to_files_info (struct target_ops
*);
121 static int debug_to_insert_breakpoint (struct target_ops
*, struct gdbarch
*,
122 struct bp_target_info
*);
124 static int debug_to_remove_breakpoint (struct target_ops
*, struct gdbarch
*,
125 struct bp_target_info
*);
127 static int debug_to_can_use_hw_breakpoint (struct target_ops
*self
,
130 static int debug_to_insert_hw_breakpoint (struct target_ops
*self
,
132 struct bp_target_info
*);
134 static int debug_to_remove_hw_breakpoint (struct target_ops
*self
,
136 struct bp_target_info
*);
138 static int debug_to_insert_watchpoint (struct target_ops
*self
,
140 struct expression
*);
142 static int debug_to_remove_watchpoint (struct target_ops
*self
,
144 struct expression
*);
146 static int debug_to_stopped_data_address (struct target_ops
*, CORE_ADDR
*);
148 static int debug_to_watchpoint_addr_within_range (struct target_ops
*,
149 CORE_ADDR
, CORE_ADDR
, int);
151 static int debug_to_region_ok_for_hw_watchpoint (struct target_ops
*self
,
154 static int debug_to_can_accel_watchpoint_condition (struct target_ops
*self
,
156 struct expression
*);
158 static void debug_to_terminal_init (struct target_ops
*self
);
160 static void debug_to_terminal_inferior (struct target_ops
*self
);
162 static void debug_to_terminal_ours_for_output (struct target_ops
*self
);
164 static void debug_to_terminal_save_ours (struct target_ops
*self
);
166 static void debug_to_terminal_ours (struct target_ops
*self
);
168 static void debug_to_load (struct target_ops
*self
, char *, int);
170 static int debug_to_can_run (struct target_ops
*self
);
172 static void debug_to_stop (struct target_ops
*self
, ptid_t
);
174 /* Pointer to array of target architecture structures; the size of the
175 array; the current index into the array; the allocated size of the
177 struct target_ops
**target_structs
;
178 unsigned target_struct_size
;
179 unsigned target_struct_allocsize
;
180 #define DEFAULT_ALLOCSIZE 10
182 /* The initial current target, so that there is always a semi-valid
185 static struct target_ops dummy_target
;
187 /* Top of target stack. */
189 static struct target_ops
*target_stack
;
191 /* The target structure we are currently using to talk to a process
192 or file or whatever "inferior" we have. */
194 struct target_ops current_target
;
196 /* Command list for target. */
198 static struct cmd_list_element
*targetlist
= NULL
;
200 /* Nonzero if we should trust readonly sections from the
201 executable when reading memory. */
203 static int trust_readonly
= 0;
205 /* Nonzero if we should show true memory content including
206 memory breakpoint inserted by gdb. */
208 static int show_memory_breakpoints
= 0;
210 /* These globals control whether GDB attempts to perform these
211 operations; they are useful for targets that need to prevent
212 inadvertant disruption, such as in non-stop mode. */
214 int may_write_registers
= 1;
216 int may_write_memory
= 1;
218 int may_insert_breakpoints
= 1;
220 int may_insert_tracepoints
= 1;
222 int may_insert_fast_tracepoints
= 1;
226 /* Non-zero if we want to see trace of target level stuff. */
228 static unsigned int targetdebug
= 0;
230 show_targetdebug (struct ui_file
*file
, int from_tty
,
231 struct cmd_list_element
*c
, const char *value
)
233 fprintf_filtered (file
, _("Target debugging is %s.\n"), value
);
236 static void setup_target_debug (void);
238 /* The user just typed 'target' without the name of a target. */
241 target_command (char *arg
, int from_tty
)
243 fputs_filtered ("Argument required (target name). Try `help target'\n",
247 /* Default target_has_* methods for process_stratum targets. */
250 default_child_has_all_memory (struct target_ops
*ops
)
252 /* If no inferior selected, then we can't read memory here. */
253 if (ptid_equal (inferior_ptid
, null_ptid
))
260 default_child_has_memory (struct target_ops
*ops
)
262 /* If no inferior selected, then we can't read memory here. */
263 if (ptid_equal (inferior_ptid
, null_ptid
))
270 default_child_has_stack (struct target_ops
*ops
)
272 /* If no inferior selected, there's no stack. */
273 if (ptid_equal (inferior_ptid
, null_ptid
))
280 default_child_has_registers (struct target_ops
*ops
)
282 /* Can't read registers from no inferior. */
283 if (ptid_equal (inferior_ptid
, null_ptid
))
290 default_child_has_execution (struct target_ops
*ops
, ptid_t the_ptid
)
292 /* If there's no thread selected, then we can't make it run through
294 if (ptid_equal (the_ptid
, null_ptid
))
302 target_has_all_memory_1 (void)
304 struct target_ops
*t
;
306 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
307 if (t
->to_has_all_memory (t
))
314 target_has_memory_1 (void)
316 struct target_ops
*t
;
318 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
319 if (t
->to_has_memory (t
))
326 target_has_stack_1 (void)
328 struct target_ops
*t
;
330 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
331 if (t
->to_has_stack (t
))
338 target_has_registers_1 (void)
340 struct target_ops
*t
;
342 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
343 if (t
->to_has_registers (t
))
350 target_has_execution_1 (ptid_t the_ptid
)
352 struct target_ops
*t
;
354 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
355 if (t
->to_has_execution (t
, the_ptid
))
362 target_has_execution_current (void)
364 return target_has_execution_1 (inferior_ptid
);
367 /* Complete initialization of T. This ensures that various fields in
368 T are set, if needed by the target implementation. */
371 complete_target_initialization (struct target_ops
*t
)
373 /* Provide default values for all "must have" methods. */
375 if (t
->to_has_all_memory
== NULL
)
376 t
->to_has_all_memory
= return_zero
;
378 if (t
->to_has_memory
== NULL
)
379 t
->to_has_memory
= return_zero
;
381 if (t
->to_has_stack
== NULL
)
382 t
->to_has_stack
= return_zero
;
384 if (t
->to_has_registers
== NULL
)
385 t
->to_has_registers
= return_zero
;
387 if (t
->to_has_execution
== NULL
)
388 t
->to_has_execution
= return_zero_has_execution
;
390 install_delegators (t
);
393 /* Add possible target architecture T to the list and add a new
394 command 'target T->to_shortname'. Set COMPLETER as the command's
395 completer if not NULL. */
398 add_target_with_completer (struct target_ops
*t
,
399 completer_ftype
*completer
)
401 struct cmd_list_element
*c
;
403 complete_target_initialization (t
);
407 target_struct_allocsize
= DEFAULT_ALLOCSIZE
;
408 target_structs
= (struct target_ops
**) xmalloc
409 (target_struct_allocsize
* sizeof (*target_structs
));
411 if (target_struct_size
>= target_struct_allocsize
)
413 target_struct_allocsize
*= 2;
414 target_structs
= (struct target_ops
**)
415 xrealloc ((char *) target_structs
,
416 target_struct_allocsize
* sizeof (*target_structs
));
418 target_structs
[target_struct_size
++] = t
;
420 if (targetlist
== NULL
)
421 add_prefix_cmd ("target", class_run
, target_command
, _("\
422 Connect to a target machine or process.\n\
423 The first argument is the type or protocol of the target machine.\n\
424 Remaining arguments are interpreted by the target protocol. For more\n\
425 information on the arguments for a particular protocol, type\n\
426 `help target ' followed by the protocol name."),
427 &targetlist
, "target ", 0, &cmdlist
);
428 c
= add_cmd (t
->to_shortname
, no_class
, t
->to_open
, t
->to_doc
,
430 if (completer
!= NULL
)
431 set_cmd_completer (c
, completer
);
434 /* Add a possible target architecture to the list. */
437 add_target (struct target_ops
*t
)
439 add_target_with_completer (t
, NULL
);
445 add_deprecated_target_alias (struct target_ops
*t
, char *alias
)
447 struct cmd_list_element
*c
;
450 /* If we use add_alias_cmd, here, we do not get the deprecated warning,
452 c
= add_cmd (alias
, no_class
, t
->to_open
, t
->to_doc
, &targetlist
);
453 alt
= xstrprintf ("target %s", t
->to_shortname
);
454 deprecate_cmd (c
, alt
);
463 fprintf_unfiltered (gdb_stdlog
, "target_kill ()\n");
465 current_target
.to_kill (¤t_target
);
469 target_load (char *arg
, int from_tty
)
471 target_dcache_invalidate ();
472 (*current_target
.to_load
) (¤t_target
, arg
, from_tty
);
476 target_create_inferior (char *exec_file
, char *args
,
477 char **env
, int from_tty
)
479 struct target_ops
*t
;
481 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
483 if (t
->to_create_inferior
!= NULL
)
485 t
->to_create_inferior (t
, exec_file
, args
, env
, from_tty
);
487 fprintf_unfiltered (gdb_stdlog
,
488 "target_create_inferior (%s, %s, xxx, %d)\n",
489 exec_file
, args
, from_tty
);
494 internal_error (__FILE__
, __LINE__
,
495 _("could not find a target to create inferior"));
499 target_terminal_inferior (void)
501 /* A background resume (``run&'') should leave GDB in control of the
502 terminal. Use target_can_async_p, not target_is_async_p, since at
503 this point the target is not async yet. However, if sync_execution
504 is not set, we know it will become async prior to resume. */
505 if (target_can_async_p () && !sync_execution
)
508 /* If GDB is resuming the inferior in the foreground, install
509 inferior's terminal modes. */
510 (*current_target
.to_terminal_inferior
) (¤t_target
);
516 error (_("You can't do that when your target is `%s'"),
517 current_target
.to_shortname
);
523 error (_("You can't do that without a process to debug."));
527 default_terminal_info (struct target_ops
*self
, const char *args
, int from_tty
)
529 printf_unfiltered (_("No saved terminal information.\n"));
532 /* A default implementation for the to_get_ada_task_ptid target method.
534 This function builds the PTID by using both LWP and TID as part of
535 the PTID lwp and tid elements. The pid used is the pid of the
539 default_get_ada_task_ptid (struct target_ops
*self
, long lwp
, long tid
)
541 return ptid_build (ptid_get_pid (inferior_ptid
), lwp
, tid
);
544 static enum exec_direction_kind
545 default_execution_direction (struct target_ops
*self
)
547 if (!target_can_execute_reverse
)
549 else if (!target_can_async_p ())
552 gdb_assert_not_reached ("\
553 to_execution_direction must be implemented for reverse async");
556 /* Go through the target stack from top to bottom, copying over zero
557 entries in current_target, then filling in still empty entries. In
558 effect, we are doing class inheritance through the pushed target
561 NOTE: cagney/2003-10-17: The problem with this inheritance, as it
562 is currently implemented, is that it discards any knowledge of
563 which target an inherited method originally belonged to.
564 Consequently, new new target methods should instead explicitly and
565 locally search the target stack for the target that can handle the
569 update_current_target (void)
571 struct target_ops
*t
;
573 /* First, reset current's contents. */
574 memset (¤t_target
, 0, sizeof (current_target
));
576 /* Install the delegators. */
577 install_delegators (¤t_target
);
579 current_target
.to_stratum
= target_stack
->to_stratum
;
581 #define INHERIT(FIELD, TARGET) \
582 if (!current_target.FIELD) \
583 current_target.FIELD = (TARGET)->FIELD
585 /* Do not add any new INHERITs here. Instead, use the delegation
586 mechanism provided by make-target-delegates. */
587 for (t
= target_stack
; t
; t
= t
->beneath
)
589 INHERIT (to_shortname
, t
);
590 INHERIT (to_longname
, t
);
591 INHERIT (to_attach_no_wait
, t
);
592 INHERIT (to_have_steppable_watchpoint
, t
);
593 INHERIT (to_have_continuable_watchpoint
, t
);
594 INHERIT (to_has_thread_control
, t
);
598 /* Finally, position the target-stack beneath the squashed
599 "current_target". That way code looking for a non-inherited
600 target method can quickly and simply find it. */
601 current_target
.beneath
= target_stack
;
604 setup_target_debug ();
607 /* Push a new target type into the stack of the existing target accessors,
608 possibly superseding some of the existing accessors.
610 Rather than allow an empty stack, we always have the dummy target at
611 the bottom stratum, so we can call the function vectors without
615 push_target (struct target_ops
*t
)
617 struct target_ops
**cur
;
619 /* Check magic number. If wrong, it probably means someone changed
620 the struct definition, but not all the places that initialize one. */
621 if (t
->to_magic
!= OPS_MAGIC
)
623 fprintf_unfiltered (gdb_stderr
,
624 "Magic number of %s target struct wrong\n",
626 internal_error (__FILE__
, __LINE__
,
627 _("failed internal consistency check"));
630 /* Find the proper stratum to install this target in. */
631 for (cur
= &target_stack
; (*cur
) != NULL
; cur
= &(*cur
)->beneath
)
633 if ((int) (t
->to_stratum
) >= (int) (*cur
)->to_stratum
)
637 /* If there's already targets at this stratum, remove them. */
638 /* FIXME: cagney/2003-10-15: I think this should be popping all
639 targets to CUR, and not just those at this stratum level. */
640 while ((*cur
) != NULL
&& t
->to_stratum
== (*cur
)->to_stratum
)
642 /* There's already something at this stratum level. Close it,
643 and un-hook it from the stack. */
644 struct target_ops
*tmp
= (*cur
);
646 (*cur
) = (*cur
)->beneath
;
651 /* We have removed all targets in our stratum, now add the new one. */
655 update_current_target ();
658 /* Remove a target_ops vector from the stack, wherever it may be.
659 Return how many times it was removed (0 or 1). */
662 unpush_target (struct target_ops
*t
)
664 struct target_ops
**cur
;
665 struct target_ops
*tmp
;
667 if (t
->to_stratum
== dummy_stratum
)
668 internal_error (__FILE__
, __LINE__
,
669 _("Attempt to unpush the dummy target"));
671 /* Look for the specified target. Note that we assume that a target
672 can only occur once in the target stack. */
674 for (cur
= &target_stack
; (*cur
) != NULL
; cur
= &(*cur
)->beneath
)
680 /* If we don't find target_ops, quit. Only open targets should be
685 /* Unchain the target. */
687 (*cur
) = (*cur
)->beneath
;
690 update_current_target ();
692 /* Finally close the target. Note we do this after unchaining, so
693 any target method calls from within the target_close
694 implementation don't end up in T anymore. */
701 pop_all_targets_above (enum strata above_stratum
)
703 while ((int) (current_target
.to_stratum
) > (int) above_stratum
)
705 if (!unpush_target (target_stack
))
707 fprintf_unfiltered (gdb_stderr
,
708 "pop_all_targets couldn't find target %s\n",
709 target_stack
->to_shortname
);
710 internal_error (__FILE__
, __LINE__
,
711 _("failed internal consistency check"));
718 pop_all_targets (void)
720 pop_all_targets_above (dummy_stratum
);
723 /* Return 1 if T is now pushed in the target stack. Return 0 otherwise. */
726 target_is_pushed (struct target_ops
*t
)
728 struct target_ops
**cur
;
730 /* Check magic number. If wrong, it probably means someone changed
731 the struct definition, but not all the places that initialize one. */
732 if (t
->to_magic
!= OPS_MAGIC
)
734 fprintf_unfiltered (gdb_stderr
,
735 "Magic number of %s target struct wrong\n",
737 internal_error (__FILE__
, __LINE__
,
738 _("failed internal consistency check"));
741 for (cur
= &target_stack
; (*cur
) != NULL
; cur
= &(*cur
)->beneath
)
748 /* Using the objfile specified in OBJFILE, find the address for the
749 current thread's thread-local storage with offset OFFSET. */
751 target_translate_tls_address (struct objfile
*objfile
, CORE_ADDR offset
)
753 volatile CORE_ADDR addr
= 0;
754 struct target_ops
*target
;
756 for (target
= current_target
.beneath
;
758 target
= target
->beneath
)
760 if (target
->to_get_thread_local_address
!= NULL
)
765 && gdbarch_fetch_tls_load_module_address_p (target_gdbarch ()))
767 ptid_t ptid
= inferior_ptid
;
768 volatile struct gdb_exception ex
;
770 TRY_CATCH (ex
, RETURN_MASK_ALL
)
774 /* Fetch the load module address for this objfile. */
775 lm_addr
= gdbarch_fetch_tls_load_module_address (target_gdbarch (),
777 /* If it's 0, throw the appropriate exception. */
779 throw_error (TLS_LOAD_MODULE_NOT_FOUND_ERROR
,
780 _("TLS load module not found"));
782 addr
= target
->to_get_thread_local_address (target
, ptid
,
785 /* If an error occurred, print TLS related messages here. Otherwise,
786 throw the error to some higher catcher. */
789 int objfile_is_library
= (objfile
->flags
& OBJF_SHARED
);
793 case TLS_NO_LIBRARY_SUPPORT_ERROR
:
794 error (_("Cannot find thread-local variables "
795 "in this thread library."));
797 case TLS_LOAD_MODULE_NOT_FOUND_ERROR
:
798 if (objfile_is_library
)
799 error (_("Cannot find shared library `%s' in dynamic"
800 " linker's load module list"), objfile_name (objfile
));
802 error (_("Cannot find executable file `%s' in dynamic"
803 " linker's load module list"), objfile_name (objfile
));
805 case TLS_NOT_ALLOCATED_YET_ERROR
:
806 if (objfile_is_library
)
807 error (_("The inferior has not yet allocated storage for"
808 " thread-local variables in\n"
809 "the shared library `%s'\n"
811 objfile_name (objfile
), target_pid_to_str (ptid
));
813 error (_("The inferior has not yet allocated storage for"
814 " thread-local variables in\n"
815 "the executable `%s'\n"
817 objfile_name (objfile
), target_pid_to_str (ptid
));
819 case TLS_GENERIC_ERROR
:
820 if (objfile_is_library
)
821 error (_("Cannot find thread-local storage for %s, "
822 "shared library %s:\n%s"),
823 target_pid_to_str (ptid
),
824 objfile_name (objfile
), ex
.message
);
826 error (_("Cannot find thread-local storage for %s, "
827 "executable file %s:\n%s"),
828 target_pid_to_str (ptid
),
829 objfile_name (objfile
), ex
.message
);
832 throw_exception (ex
);
837 /* It wouldn't be wrong here to try a gdbarch method, too; finding
838 TLS is an ABI-specific thing. But we don't do that yet. */
840 error (_("Cannot find thread-local variables on this target"));
846 target_xfer_status_to_string (enum target_xfer_status status
)
848 #define CASE(X) case X: return #X
851 CASE(TARGET_XFER_E_IO
);
852 CASE(TARGET_XFER_UNAVAILABLE
);
861 #define MIN(A, B) (((A) <= (B)) ? (A) : (B))
863 /* target_read_string -- read a null terminated string, up to LEN bytes,
864 from MEMADDR in target. Set *ERRNOP to the errno code, or 0 if successful.
865 Set *STRING to a pointer to malloc'd memory containing the data; the caller
866 is responsible for freeing it. Return the number of bytes successfully
870 target_read_string (CORE_ADDR memaddr
, char **string
, int len
, int *errnop
)
876 int buffer_allocated
;
878 unsigned int nbytes_read
= 0;
882 /* Small for testing. */
883 buffer_allocated
= 4;
884 buffer
= xmalloc (buffer_allocated
);
889 tlen
= MIN (len
, 4 - (memaddr
& 3));
890 offset
= memaddr
& 3;
892 errcode
= target_read_memory (memaddr
& ~3, buf
, sizeof buf
);
895 /* The transfer request might have crossed the boundary to an
896 unallocated region of memory. Retry the transfer, requesting
900 errcode
= target_read_memory (memaddr
, buf
, 1);
905 if (bufptr
- buffer
+ tlen
> buffer_allocated
)
909 bytes
= bufptr
- buffer
;
910 buffer_allocated
*= 2;
911 buffer
= xrealloc (buffer
, buffer_allocated
);
912 bufptr
= buffer
+ bytes
;
915 for (i
= 0; i
< tlen
; i
++)
917 *bufptr
++ = buf
[i
+ offset
];
918 if (buf
[i
+ offset
] == '\000')
920 nbytes_read
+= i
+ 1;
936 struct target_section_table
*
937 target_get_section_table (struct target_ops
*target
)
940 fprintf_unfiltered (gdb_stdlog
, "target_get_section_table ()\n");
942 return (*target
->to_get_section_table
) (target
);
945 /* Find a section containing ADDR. */
947 struct target_section
*
948 target_section_by_addr (struct target_ops
*target
, CORE_ADDR addr
)
950 struct target_section_table
*table
= target_get_section_table (target
);
951 struct target_section
*secp
;
956 for (secp
= table
->sections
; secp
< table
->sections_end
; secp
++)
958 if (addr
>= secp
->addr
&& addr
< secp
->endaddr
)
964 /* Read memory from the live target, even if currently inspecting a
965 traceframe. The return is the same as that of target_read. */
967 static enum target_xfer_status
968 target_read_live_memory (enum target_object object
,
969 ULONGEST memaddr
, gdb_byte
*myaddr
, ULONGEST len
,
970 ULONGEST
*xfered_len
)
972 enum target_xfer_status ret
;
973 struct cleanup
*cleanup
;
975 /* Switch momentarily out of tfind mode so to access live memory.
976 Note that this must not clear global state, such as the frame
977 cache, which must still remain valid for the previous traceframe.
978 We may be _building_ the frame cache at this point. */
979 cleanup
= make_cleanup_restore_traceframe_number ();
980 set_traceframe_number (-1);
982 ret
= target_xfer_partial (current_target
.beneath
, object
, NULL
,
983 myaddr
, NULL
, memaddr
, len
, xfered_len
);
985 do_cleanups (cleanup
);
989 /* Using the set of read-only target sections of OPS, read live
990 read-only memory. Note that the actual reads start from the
991 top-most target again.
993 For interface/parameters/return description see target.h,
996 static enum target_xfer_status
997 memory_xfer_live_readonly_partial (struct target_ops
*ops
,
998 enum target_object object
,
999 gdb_byte
*readbuf
, ULONGEST memaddr
,
1000 ULONGEST len
, ULONGEST
*xfered_len
)
1002 struct target_section
*secp
;
1003 struct target_section_table
*table
;
1005 secp
= target_section_by_addr (ops
, memaddr
);
1007 && (bfd_get_section_flags (secp
->the_bfd_section
->owner
,
1008 secp
->the_bfd_section
)
1011 struct target_section
*p
;
1012 ULONGEST memend
= memaddr
+ len
;
1014 table
= target_get_section_table (ops
);
1016 for (p
= table
->sections
; p
< table
->sections_end
; p
++)
1018 if (memaddr
>= p
->addr
)
1020 if (memend
<= p
->endaddr
)
1022 /* Entire transfer is within this section. */
1023 return target_read_live_memory (object
, memaddr
,
1024 readbuf
, len
, xfered_len
);
1026 else if (memaddr
>= p
->endaddr
)
1028 /* This section ends before the transfer starts. */
1033 /* This section overlaps the transfer. Just do half. */
1034 len
= p
->endaddr
- memaddr
;
1035 return target_read_live_memory (object
, memaddr
,
1036 readbuf
, len
, xfered_len
);
1042 return TARGET_XFER_EOF
;
1045 /* Read memory from more than one valid target. A core file, for
1046 instance, could have some of memory but delegate other bits to
1047 the target below it. So, we must manually try all targets. */
1049 static enum target_xfer_status
1050 raw_memory_xfer_partial (struct target_ops
*ops
, gdb_byte
*readbuf
,
1051 const gdb_byte
*writebuf
, ULONGEST memaddr
, LONGEST len
,
1052 ULONGEST
*xfered_len
)
1054 enum target_xfer_status res
;
1058 res
= ops
->to_xfer_partial (ops
, TARGET_OBJECT_MEMORY
, NULL
,
1059 readbuf
, writebuf
, memaddr
, len
,
1061 if (res
== TARGET_XFER_OK
)
1064 /* Stop if the target reports that the memory is not available. */
1065 if (res
== TARGET_XFER_UNAVAILABLE
)
1068 /* We want to continue past core files to executables, but not
1069 past a running target's memory. */
1070 if (ops
->to_has_all_memory (ops
))
1075 while (ops
!= NULL
);
1080 /* Perform a partial memory transfer.
1081 For docs see target.h, to_xfer_partial. */
1083 static enum target_xfer_status
1084 memory_xfer_partial_1 (struct target_ops
*ops
, enum target_object object
,
1085 gdb_byte
*readbuf
, const gdb_byte
*writebuf
, ULONGEST memaddr
,
1086 ULONGEST len
, ULONGEST
*xfered_len
)
1088 enum target_xfer_status res
;
1090 struct mem_region
*region
;
1091 struct inferior
*inf
;
1093 /* For accesses to unmapped overlay sections, read directly from
1094 files. Must do this first, as MEMADDR may need adjustment. */
1095 if (readbuf
!= NULL
&& overlay_debugging
)
1097 struct obj_section
*section
= find_pc_overlay (memaddr
);
1099 if (pc_in_unmapped_range (memaddr
, section
))
1101 struct target_section_table
*table
1102 = target_get_section_table (ops
);
1103 const char *section_name
= section
->the_bfd_section
->name
;
1105 memaddr
= overlay_mapped_address (memaddr
, section
);
1106 return section_table_xfer_memory_partial (readbuf
, writebuf
,
1107 memaddr
, len
, xfered_len
,
1109 table
->sections_end
,
1114 /* Try the executable files, if "trust-readonly-sections" is set. */
1115 if (readbuf
!= NULL
&& trust_readonly
)
1117 struct target_section
*secp
;
1118 struct target_section_table
*table
;
1120 secp
= target_section_by_addr (ops
, memaddr
);
1122 && (bfd_get_section_flags (secp
->the_bfd_section
->owner
,
1123 secp
->the_bfd_section
)
1126 table
= target_get_section_table (ops
);
1127 return section_table_xfer_memory_partial (readbuf
, writebuf
,
1128 memaddr
, len
, xfered_len
,
1130 table
->sections_end
,
1135 /* If reading unavailable memory in the context of traceframes, and
1136 this address falls within a read-only section, fallback to
1137 reading from live memory. */
1138 if (readbuf
!= NULL
&& get_traceframe_number () != -1)
1140 VEC(mem_range_s
) *available
;
1142 /* If we fail to get the set of available memory, then the
1143 target does not support querying traceframe info, and so we
1144 attempt reading from the traceframe anyway (assuming the
1145 target implements the old QTro packet then). */
1146 if (traceframe_available_memory (&available
, memaddr
, len
))
1148 struct cleanup
*old_chain
;
1150 old_chain
= make_cleanup (VEC_cleanup(mem_range_s
), &available
);
1152 if (VEC_empty (mem_range_s
, available
)
1153 || VEC_index (mem_range_s
, available
, 0)->start
!= memaddr
)
1155 /* Don't read into the traceframe's available
1157 if (!VEC_empty (mem_range_s
, available
))
1159 LONGEST oldlen
= len
;
1161 len
= VEC_index (mem_range_s
, available
, 0)->start
- memaddr
;
1162 gdb_assert (len
<= oldlen
);
1165 do_cleanups (old_chain
);
1167 /* This goes through the topmost target again. */
1168 res
= memory_xfer_live_readonly_partial (ops
, object
,
1171 if (res
== TARGET_XFER_OK
)
1172 return TARGET_XFER_OK
;
1175 /* No use trying further, we know some memory starting
1176 at MEMADDR isn't available. */
1178 return TARGET_XFER_UNAVAILABLE
;
1182 /* Don't try to read more than how much is available, in
1183 case the target implements the deprecated QTro packet to
1184 cater for older GDBs (the target's knowledge of read-only
1185 sections may be outdated by now). */
1186 len
= VEC_index (mem_range_s
, available
, 0)->length
;
1188 do_cleanups (old_chain
);
1192 /* Try GDB's internal data cache. */
1193 region
= lookup_mem_region (memaddr
);
1194 /* region->hi == 0 means there's no upper bound. */
1195 if (memaddr
+ len
< region
->hi
|| region
->hi
== 0)
1198 reg_len
= region
->hi
- memaddr
;
1200 switch (region
->attrib
.mode
)
1203 if (writebuf
!= NULL
)
1204 return TARGET_XFER_E_IO
;
1208 if (readbuf
!= NULL
)
1209 return TARGET_XFER_E_IO
;
1213 /* We only support writing to flash during "load" for now. */
1214 if (writebuf
!= NULL
)
1215 error (_("Writing to flash memory forbidden in this context"));
1219 return TARGET_XFER_E_IO
;
1222 if (!ptid_equal (inferior_ptid
, null_ptid
))
1223 inf
= find_inferior_pid (ptid_get_pid (inferior_ptid
));
1228 /* The dcache reads whole cache lines; that doesn't play well
1229 with reading from a trace buffer, because reading outside of
1230 the collected memory range fails. */
1231 && get_traceframe_number () == -1
1232 && (region
->attrib
.cache
1233 || (stack_cache_enabled_p () && object
== TARGET_OBJECT_STACK_MEMORY
)
1234 || (code_cache_enabled_p () && object
== TARGET_OBJECT_CODE_MEMORY
)))
1236 DCACHE
*dcache
= target_dcache_get_or_init ();
1239 if (readbuf
!= NULL
)
1240 l
= dcache_xfer_memory (ops
, dcache
, memaddr
, readbuf
, reg_len
, 0);
1242 /* FIXME drow/2006-08-09: If we're going to preserve const
1243 correctness dcache_xfer_memory should take readbuf and
1245 l
= dcache_xfer_memory (ops
, dcache
, memaddr
, (void *) writebuf
,
1248 return TARGET_XFER_E_IO
;
1251 *xfered_len
= (ULONGEST
) l
;
1252 return TARGET_XFER_OK
;
1256 /* If none of those methods found the memory we wanted, fall back
1257 to a target partial transfer. Normally a single call to
1258 to_xfer_partial is enough; if it doesn't recognize an object
1259 it will call the to_xfer_partial of the next target down.
1260 But for memory this won't do. Memory is the only target
1261 object which can be read from more than one valid target.
1262 A core file, for instance, could have some of memory but
1263 delegate other bits to the target below it. So, we must
1264 manually try all targets. */
1266 res
= raw_memory_xfer_partial (ops
, readbuf
, writebuf
, memaddr
, reg_len
,
1269 /* Make sure the cache gets updated no matter what - if we are writing
1270 to the stack. Even if this write is not tagged as such, we still need
1271 to update the cache. */
1273 if (res
== TARGET_XFER_OK
1276 && target_dcache_init_p ()
1277 && !region
->attrib
.cache
1278 && ((stack_cache_enabled_p () && object
!= TARGET_OBJECT_STACK_MEMORY
)
1279 || (code_cache_enabled_p () && object
!= TARGET_OBJECT_CODE_MEMORY
)))
1281 DCACHE
*dcache
= target_dcache_get ();
1283 dcache_update (dcache
, memaddr
, (void *) writebuf
, reg_len
);
1286 /* If we still haven't got anything, return the last error. We
1291 /* Perform a partial memory transfer. For docs see target.h,
1294 static enum target_xfer_status
1295 memory_xfer_partial (struct target_ops
*ops
, enum target_object object
,
1296 gdb_byte
*readbuf
, const gdb_byte
*writebuf
,
1297 ULONGEST memaddr
, ULONGEST len
, ULONGEST
*xfered_len
)
1299 enum target_xfer_status res
;
1301 /* Zero length requests are ok and require no work. */
1303 return TARGET_XFER_EOF
;
1305 /* Fill in READBUF with breakpoint shadows, or WRITEBUF with
1306 breakpoint insns, thus hiding out from higher layers whether
1307 there are software breakpoints inserted in the code stream. */
1308 if (readbuf
!= NULL
)
1310 res
= memory_xfer_partial_1 (ops
, object
, readbuf
, NULL
, memaddr
, len
,
1313 if (res
== TARGET_XFER_OK
&& !show_memory_breakpoints
)
1314 breakpoint_xfer_memory (readbuf
, NULL
, NULL
, memaddr
, *xfered_len
);
1319 struct cleanup
*old_chain
;
1321 /* A large write request is likely to be partially satisfied
1322 by memory_xfer_partial_1. We will continually malloc
1323 and free a copy of the entire write request for breakpoint
1324 shadow handling even though we only end up writing a small
1325 subset of it. Cap writes to 4KB to mitigate this. */
1326 len
= min (4096, len
);
1328 buf
= xmalloc (len
);
1329 old_chain
= make_cleanup (xfree
, buf
);
1330 memcpy (buf
, writebuf
, len
);
1332 breakpoint_xfer_memory (NULL
, buf
, writebuf
, memaddr
, len
);
1333 res
= memory_xfer_partial_1 (ops
, object
, NULL
, buf
, memaddr
, len
,
1336 do_cleanups (old_chain
);
1343 restore_show_memory_breakpoints (void *arg
)
1345 show_memory_breakpoints
= (uintptr_t) arg
;
1349 make_show_memory_breakpoints_cleanup (int show
)
1351 int current
= show_memory_breakpoints
;
1353 show_memory_breakpoints
= show
;
1354 return make_cleanup (restore_show_memory_breakpoints
,
1355 (void *) (uintptr_t) current
);
1358 /* For docs see target.h, to_xfer_partial. */
1360 enum target_xfer_status
1361 target_xfer_partial (struct target_ops
*ops
,
1362 enum target_object object
, const char *annex
,
1363 gdb_byte
*readbuf
, const gdb_byte
*writebuf
,
1364 ULONGEST offset
, ULONGEST len
,
1365 ULONGEST
*xfered_len
)
1367 enum target_xfer_status retval
;
1369 gdb_assert (ops
->to_xfer_partial
!= NULL
);
1371 /* Transfer is done when LEN is zero. */
1373 return TARGET_XFER_EOF
;
1375 if (writebuf
&& !may_write_memory
)
1376 error (_("Writing to memory is not allowed (addr %s, len %s)"),
1377 core_addr_to_string_nz (offset
), plongest (len
));
1381 /* If this is a memory transfer, let the memory-specific code
1382 have a look at it instead. Memory transfers are more
1384 if (object
== TARGET_OBJECT_MEMORY
|| object
== TARGET_OBJECT_STACK_MEMORY
1385 || object
== TARGET_OBJECT_CODE_MEMORY
)
1386 retval
= memory_xfer_partial (ops
, object
, readbuf
,
1387 writebuf
, offset
, len
, xfered_len
);
1388 else if (object
== TARGET_OBJECT_RAW_MEMORY
)
1390 /* Request the normal memory object from other layers. */
1391 retval
= raw_memory_xfer_partial (ops
, readbuf
, writebuf
, offset
, len
,
1395 retval
= ops
->to_xfer_partial (ops
, object
, annex
, readbuf
,
1396 writebuf
, offset
, len
, xfered_len
);
1400 const unsigned char *myaddr
= NULL
;
1402 fprintf_unfiltered (gdb_stdlog
,
1403 "%s:target_xfer_partial "
1404 "(%d, %s, %s, %s, %s, %s) = %d, %s",
1407 (annex
? annex
: "(null)"),
1408 host_address_to_string (readbuf
),
1409 host_address_to_string (writebuf
),
1410 core_addr_to_string_nz (offset
),
1411 pulongest (len
), retval
,
1412 pulongest (*xfered_len
));
1418 if (retval
== TARGET_XFER_OK
&& myaddr
!= NULL
)
1422 fputs_unfiltered (", bytes =", gdb_stdlog
);
1423 for (i
= 0; i
< *xfered_len
; i
++)
1425 if ((((intptr_t) &(myaddr
[i
])) & 0xf) == 0)
1427 if (targetdebug
< 2 && i
> 0)
1429 fprintf_unfiltered (gdb_stdlog
, " ...");
1432 fprintf_unfiltered (gdb_stdlog
, "\n");
1435 fprintf_unfiltered (gdb_stdlog
, " %02x", myaddr
[i
] & 0xff);
1439 fputc_unfiltered ('\n', gdb_stdlog
);
1442 /* Check implementations of to_xfer_partial update *XFERED_LEN
1443 properly. Do assertion after printing debug messages, so that we
1444 can find more clues on assertion failure from debugging messages. */
1445 if (retval
== TARGET_XFER_OK
|| retval
== TARGET_XFER_UNAVAILABLE
)
1446 gdb_assert (*xfered_len
> 0);
1451 /* Read LEN bytes of target memory at address MEMADDR, placing the
1452 results in GDB's memory at MYADDR. Returns either 0 for success or
1453 TARGET_XFER_E_IO if any error occurs.
1455 If an error occurs, no guarantee is made about the contents of the data at
1456 MYADDR. In particular, the caller should not depend upon partial reads
1457 filling the buffer with good data. There is no way for the caller to know
1458 how much good data might have been transfered anyway. Callers that can
1459 deal with partial reads should call target_read (which will retry until
1460 it makes no progress, and then return how much was transferred). */
1463 target_read_memory (CORE_ADDR memaddr
, gdb_byte
*myaddr
, ssize_t len
)
1465 /* Dispatch to the topmost target, not the flattened current_target.
1466 Memory accesses check target->to_has_(all_)memory, and the
1467 flattened target doesn't inherit those. */
1468 if (target_read (current_target
.beneath
, TARGET_OBJECT_MEMORY
, NULL
,
1469 myaddr
, memaddr
, len
) == len
)
1472 return TARGET_XFER_E_IO
;
1475 /* Like target_read_memory, but specify explicitly that this is a read
1476 from the target's raw memory. That is, this read bypasses the
1477 dcache, breakpoint shadowing, etc. */
1480 target_read_raw_memory (CORE_ADDR memaddr
, gdb_byte
*myaddr
, ssize_t len
)
1482 /* See comment in target_read_memory about why the request starts at
1483 current_target.beneath. */
1484 if (target_read (current_target
.beneath
, TARGET_OBJECT_RAW_MEMORY
, NULL
,
1485 myaddr
, memaddr
, len
) == len
)
1488 return TARGET_XFER_E_IO
;
1491 /* Like target_read_memory, but specify explicitly that this is a read from
1492 the target's stack. This may trigger different cache behavior. */
1495 target_read_stack (CORE_ADDR memaddr
, gdb_byte
*myaddr
, ssize_t len
)
1497 /* See comment in target_read_memory about why the request starts at
1498 current_target.beneath. */
1499 if (target_read (current_target
.beneath
, TARGET_OBJECT_STACK_MEMORY
, NULL
,
1500 myaddr
, memaddr
, len
) == len
)
1503 return TARGET_XFER_E_IO
;
1506 /* Like target_read_memory, but specify explicitly that this is a read from
1507 the target's code. This may trigger different cache behavior. */
1510 target_read_code (CORE_ADDR memaddr
, gdb_byte
*myaddr
, ssize_t len
)
1512 /* See comment in target_read_memory about why the request starts at
1513 current_target.beneath. */
1514 if (target_read (current_target
.beneath
, TARGET_OBJECT_CODE_MEMORY
, NULL
,
1515 myaddr
, memaddr
, len
) == len
)
1518 return TARGET_XFER_E_IO
;
1521 /* Write LEN bytes from MYADDR to target memory at address MEMADDR.
1522 Returns either 0 for success or TARGET_XFER_E_IO if any
1523 error occurs. If an error occurs, no guarantee is made about how
1524 much data got written. Callers that can deal with partial writes
1525 should call target_write. */
1528 target_write_memory (CORE_ADDR memaddr
, const gdb_byte
*myaddr
, ssize_t len
)
1530 /* See comment in target_read_memory about why the request starts at
1531 current_target.beneath. */
1532 if (target_write (current_target
.beneath
, TARGET_OBJECT_MEMORY
, NULL
,
1533 myaddr
, memaddr
, len
) == len
)
1536 return TARGET_XFER_E_IO
;
1539 /* Write LEN bytes from MYADDR to target raw memory at address
1540 MEMADDR. Returns either 0 for success or TARGET_XFER_E_IO
1541 if any error occurs. If an error occurs, no guarantee is made
1542 about how much data got written. Callers that can deal with
1543 partial writes should call target_write. */
1546 target_write_raw_memory (CORE_ADDR memaddr
, const gdb_byte
*myaddr
, ssize_t len
)
1548 /* See comment in target_read_memory about why the request starts at
1549 current_target.beneath. */
1550 if (target_write (current_target
.beneath
, TARGET_OBJECT_RAW_MEMORY
, NULL
,
1551 myaddr
, memaddr
, len
) == len
)
1554 return TARGET_XFER_E_IO
;
1557 /* Fetch the target's memory map. */
1560 target_memory_map (void)
1562 VEC(mem_region_s
) *result
;
1563 struct mem_region
*last_one
, *this_one
;
1565 struct target_ops
*t
;
1568 fprintf_unfiltered (gdb_stdlog
, "target_memory_map ()\n");
1570 result
= current_target
.to_memory_map (¤t_target
);
1574 qsort (VEC_address (mem_region_s
, result
),
1575 VEC_length (mem_region_s
, result
),
1576 sizeof (struct mem_region
), mem_region_cmp
);
1578 /* Check that regions do not overlap. Simultaneously assign
1579 a numbering for the "mem" commands to use to refer to
1582 for (ix
= 0; VEC_iterate (mem_region_s
, result
, ix
, this_one
); ix
++)
1584 this_one
->number
= ix
;
1586 if (last_one
&& last_one
->hi
> this_one
->lo
)
1588 warning (_("Overlapping regions in memory map: ignoring"));
1589 VEC_free (mem_region_s
, result
);
1592 last_one
= this_one
;
1599 target_flash_erase (ULONGEST address
, LONGEST length
)
1602 fprintf_unfiltered (gdb_stdlog
, "target_flash_erase (%s, %s)\n",
1603 hex_string (address
), phex (length
, 0));
1604 current_target
.to_flash_erase (¤t_target
, address
, length
);
1608 target_flash_done (void)
1611 fprintf_unfiltered (gdb_stdlog
, "target_flash_done\n");
1612 current_target
.to_flash_done (¤t_target
);
1616 show_trust_readonly (struct ui_file
*file
, int from_tty
,
1617 struct cmd_list_element
*c
, const char *value
)
1619 fprintf_filtered (file
,
1620 _("Mode for reading from readonly sections is %s.\n"),
1624 /* Target vector read/write partial wrapper functions. */
1626 static enum target_xfer_status
1627 target_read_partial (struct target_ops
*ops
,
1628 enum target_object object
,
1629 const char *annex
, gdb_byte
*buf
,
1630 ULONGEST offset
, ULONGEST len
,
1631 ULONGEST
*xfered_len
)
1633 return target_xfer_partial (ops
, object
, annex
, buf
, NULL
, offset
, len
,
1637 static enum target_xfer_status
1638 target_write_partial (struct target_ops
*ops
,
1639 enum target_object object
,
1640 const char *annex
, const gdb_byte
*buf
,
1641 ULONGEST offset
, LONGEST len
, ULONGEST
*xfered_len
)
1643 return target_xfer_partial (ops
, object
, annex
, NULL
, buf
, offset
, len
,
1647 /* Wrappers to perform the full transfer. */
1649 /* For docs on target_read see target.h. */
1652 target_read (struct target_ops
*ops
,
1653 enum target_object object
,
1654 const char *annex
, gdb_byte
*buf
,
1655 ULONGEST offset
, LONGEST len
)
1659 while (xfered
< len
)
1661 ULONGEST xfered_len
;
1662 enum target_xfer_status status
;
1664 status
= target_read_partial (ops
, object
, annex
,
1665 (gdb_byte
*) buf
+ xfered
,
1666 offset
+ xfered
, len
- xfered
,
1669 /* Call an observer, notifying them of the xfer progress? */
1670 if (status
== TARGET_XFER_EOF
)
1672 else if (status
== TARGET_XFER_OK
)
1674 xfered
+= xfered_len
;
1684 /* Assuming that the entire [begin, end) range of memory cannot be
1685 read, try to read whatever subrange is possible to read.
1687 The function returns, in RESULT, either zero or one memory block.
1688 If there's a readable subrange at the beginning, it is completely
1689 read and returned. Any further readable subrange will not be read.
1690 Otherwise, if there's a readable subrange at the end, it will be
1691 completely read and returned. Any readable subranges before it
1692 (obviously, not starting at the beginning), will be ignored. In
1693 other cases -- either no readable subrange, or readable subrange(s)
1694 that is neither at the beginning, or end, nothing is returned.
1696 The purpose of this function is to handle a read across a boundary
1697 of accessible memory in a case when memory map is not available.
1698 The above restrictions are fine for this case, but will give
1699 incorrect results if the memory is 'patchy'. However, supporting
1700 'patchy' memory would require trying to read every single byte,
1701 and it seems unacceptable solution. Explicit memory map is
1702 recommended for this case -- and target_read_memory_robust will
1703 take care of reading multiple ranges then. */
1706 read_whatever_is_readable (struct target_ops
*ops
,
1707 ULONGEST begin
, ULONGEST end
,
1708 VEC(memory_read_result_s
) **result
)
1710 gdb_byte
*buf
= xmalloc (end
- begin
);
1711 ULONGEST current_begin
= begin
;
1712 ULONGEST current_end
= end
;
1714 memory_read_result_s r
;
1715 ULONGEST xfered_len
;
1717 /* If we previously failed to read 1 byte, nothing can be done here. */
1718 if (end
- begin
<= 1)
1724 /* Check that either first or the last byte is readable, and give up
1725 if not. This heuristic is meant to permit reading accessible memory
1726 at the boundary of accessible region. */
1727 if (target_read_partial (ops
, TARGET_OBJECT_MEMORY
, NULL
,
1728 buf
, begin
, 1, &xfered_len
) == TARGET_XFER_OK
)
1733 else if (target_read_partial (ops
, TARGET_OBJECT_MEMORY
, NULL
,
1734 buf
+ (end
-begin
) - 1, end
- 1, 1,
1735 &xfered_len
) == TARGET_XFER_OK
)
1746 /* Loop invariant is that the [current_begin, current_end) was previously
1747 found to be not readable as a whole.
1749 Note loop condition -- if the range has 1 byte, we can't divide the range
1750 so there's no point trying further. */
1751 while (current_end
- current_begin
> 1)
1753 ULONGEST first_half_begin
, first_half_end
;
1754 ULONGEST second_half_begin
, second_half_end
;
1756 ULONGEST middle
= current_begin
+ (current_end
- current_begin
)/2;
1760 first_half_begin
= current_begin
;
1761 first_half_end
= middle
;
1762 second_half_begin
= middle
;
1763 second_half_end
= current_end
;
1767 first_half_begin
= middle
;
1768 first_half_end
= current_end
;
1769 second_half_begin
= current_begin
;
1770 second_half_end
= middle
;
1773 xfer
= target_read (ops
, TARGET_OBJECT_MEMORY
, NULL
,
1774 buf
+ (first_half_begin
- begin
),
1776 first_half_end
- first_half_begin
);
1778 if (xfer
== first_half_end
- first_half_begin
)
1780 /* This half reads up fine. So, the error must be in the
1782 current_begin
= second_half_begin
;
1783 current_end
= second_half_end
;
1787 /* This half is not readable. Because we've tried one byte, we
1788 know some part of this half if actually redable. Go to the next
1789 iteration to divide again and try to read.
1791 We don't handle the other half, because this function only tries
1792 to read a single readable subrange. */
1793 current_begin
= first_half_begin
;
1794 current_end
= first_half_end
;
1800 /* The [begin, current_begin) range has been read. */
1802 r
.end
= current_begin
;
1807 /* The [current_end, end) range has been read. */
1808 LONGEST rlen
= end
- current_end
;
1810 r
.data
= xmalloc (rlen
);
1811 memcpy (r
.data
, buf
+ current_end
- begin
, rlen
);
1812 r
.begin
= current_end
;
1816 VEC_safe_push(memory_read_result_s
, (*result
), &r
);
1820 free_memory_read_result_vector (void *x
)
1822 VEC(memory_read_result_s
) *v
= x
;
1823 memory_read_result_s
*current
;
1826 for (ix
= 0; VEC_iterate (memory_read_result_s
, v
, ix
, current
); ++ix
)
1828 xfree (current
->data
);
1830 VEC_free (memory_read_result_s
, v
);
1833 VEC(memory_read_result_s
) *
1834 read_memory_robust (struct target_ops
*ops
, ULONGEST offset
, LONGEST len
)
1836 VEC(memory_read_result_s
) *result
= 0;
1839 while (xfered
< len
)
1841 struct mem_region
*region
= lookup_mem_region (offset
+ xfered
);
1844 /* If there is no explicit region, a fake one should be created. */
1845 gdb_assert (region
);
1847 if (region
->hi
== 0)
1848 rlen
= len
- xfered
;
1850 rlen
= region
->hi
- offset
;
1852 if (region
->attrib
.mode
== MEM_NONE
|| region
->attrib
.mode
== MEM_WO
)
1854 /* Cannot read this region. Note that we can end up here only
1855 if the region is explicitly marked inaccessible, or
1856 'inaccessible-by-default' is in effect. */
1861 LONGEST to_read
= min (len
- xfered
, rlen
);
1862 gdb_byte
*buffer
= (gdb_byte
*)xmalloc (to_read
);
1864 LONGEST xfer
= target_read (ops
, TARGET_OBJECT_MEMORY
, NULL
,
1865 (gdb_byte
*) buffer
,
1866 offset
+ xfered
, to_read
);
1867 /* Call an observer, notifying them of the xfer progress? */
1870 /* Got an error reading full chunk. See if maybe we can read
1873 read_whatever_is_readable (ops
, offset
+ xfered
,
1874 offset
+ xfered
+ to_read
, &result
);
1879 struct memory_read_result r
;
1881 r
.begin
= offset
+ xfered
;
1882 r
.end
= r
.begin
+ xfer
;
1883 VEC_safe_push (memory_read_result_s
, result
, &r
);
1893 /* An alternative to target_write with progress callbacks. */
1896 target_write_with_progress (struct target_ops
*ops
,
1897 enum target_object object
,
1898 const char *annex
, const gdb_byte
*buf
,
1899 ULONGEST offset
, LONGEST len
,
1900 void (*progress
) (ULONGEST
, void *), void *baton
)
1904 /* Give the progress callback a chance to set up. */
1906 (*progress
) (0, baton
);
1908 while (xfered
< len
)
1910 ULONGEST xfered_len
;
1911 enum target_xfer_status status
;
1913 status
= target_write_partial (ops
, object
, annex
,
1914 (gdb_byte
*) buf
+ xfered
,
1915 offset
+ xfered
, len
- xfered
,
1918 if (status
!= TARGET_XFER_OK
)
1919 return status
== TARGET_XFER_EOF
? xfered
: -1;
1922 (*progress
) (xfered_len
, baton
);
1924 xfered
+= xfered_len
;
1930 /* For docs on target_write see target.h. */
1933 target_write (struct target_ops
*ops
,
1934 enum target_object object
,
1935 const char *annex
, const gdb_byte
*buf
,
1936 ULONGEST offset
, LONGEST len
)
1938 return target_write_with_progress (ops
, object
, annex
, buf
, offset
, len
,
1942 /* Read OBJECT/ANNEX using OPS. Store the result in *BUF_P and return
1943 the size of the transferred data. PADDING additional bytes are
1944 available in *BUF_P. This is a helper function for
1945 target_read_alloc; see the declaration of that function for more
1949 target_read_alloc_1 (struct target_ops
*ops
, enum target_object object
,
1950 const char *annex
, gdb_byte
**buf_p
, int padding
)
1952 size_t buf_alloc
, buf_pos
;
1955 /* This function does not have a length parameter; it reads the
1956 entire OBJECT). Also, it doesn't support objects fetched partly
1957 from one target and partly from another (in a different stratum,
1958 e.g. a core file and an executable). Both reasons make it
1959 unsuitable for reading memory. */
1960 gdb_assert (object
!= TARGET_OBJECT_MEMORY
);
1962 /* Start by reading up to 4K at a time. The target will throttle
1963 this number down if necessary. */
1965 buf
= xmalloc (buf_alloc
);
1969 ULONGEST xfered_len
;
1970 enum target_xfer_status status
;
1972 status
= target_read_partial (ops
, object
, annex
, &buf
[buf_pos
],
1973 buf_pos
, buf_alloc
- buf_pos
- padding
,
1976 if (status
== TARGET_XFER_EOF
)
1978 /* Read all there was. */
1985 else if (status
!= TARGET_XFER_OK
)
1987 /* An error occurred. */
1989 return TARGET_XFER_E_IO
;
1992 buf_pos
+= xfered_len
;
1994 /* If the buffer is filling up, expand it. */
1995 if (buf_alloc
< buf_pos
* 2)
1998 buf
= xrealloc (buf
, buf_alloc
);
2005 /* Read OBJECT/ANNEX using OPS. Store the result in *BUF_P and return
2006 the size of the transferred data. See the declaration in "target.h"
2007 function for more information about the return value. */
2010 target_read_alloc (struct target_ops
*ops
, enum target_object object
,
2011 const char *annex
, gdb_byte
**buf_p
)
2013 return target_read_alloc_1 (ops
, object
, annex
, buf_p
, 0);
2016 /* Read OBJECT/ANNEX using OPS. The result is NUL-terminated and
2017 returned as a string, allocated using xmalloc. If an error occurs
2018 or the transfer is unsupported, NULL is returned. Empty objects
2019 are returned as allocated but empty strings. A warning is issued
2020 if the result contains any embedded NUL bytes. */
2023 target_read_stralloc (struct target_ops
*ops
, enum target_object object
,
2028 LONGEST i
, transferred
;
2030 transferred
= target_read_alloc_1 (ops
, object
, annex
, &buffer
, 1);
2031 bufstr
= (char *) buffer
;
2033 if (transferred
< 0)
2036 if (transferred
== 0)
2037 return xstrdup ("");
2039 bufstr
[transferred
] = 0;
2041 /* Check for embedded NUL bytes; but allow trailing NULs. */
2042 for (i
= strlen (bufstr
); i
< transferred
; i
++)
2045 warning (_("target object %d, annex %s, "
2046 "contained unexpected null characters"),
2047 (int) object
, annex
? annex
: "(none)");
2054 /* Memory transfer methods. */
2057 get_target_memory (struct target_ops
*ops
, CORE_ADDR addr
, gdb_byte
*buf
,
2060 /* This method is used to read from an alternate, non-current
2061 target. This read must bypass the overlay support (as symbols
2062 don't match this target), and GDB's internal cache (wrong cache
2063 for this target). */
2064 if (target_read (ops
, TARGET_OBJECT_RAW_MEMORY
, NULL
, buf
, addr
, len
)
2066 memory_error (TARGET_XFER_E_IO
, addr
);
2070 get_target_memory_unsigned (struct target_ops
*ops
, CORE_ADDR addr
,
2071 int len
, enum bfd_endian byte_order
)
2073 gdb_byte buf
[sizeof (ULONGEST
)];
2075 gdb_assert (len
<= sizeof (buf
));
2076 get_target_memory (ops
, addr
, buf
, len
);
2077 return extract_unsigned_integer (buf
, len
, byte_order
);
2083 target_insert_breakpoint (struct gdbarch
*gdbarch
,
2084 struct bp_target_info
*bp_tgt
)
2086 if (!may_insert_breakpoints
)
2088 warning (_("May not insert breakpoints"));
2092 return current_target
.to_insert_breakpoint (¤t_target
,
2099 target_remove_breakpoint (struct gdbarch
*gdbarch
,
2100 struct bp_target_info
*bp_tgt
)
2102 /* This is kind of a weird case to handle, but the permission might
2103 have been changed after breakpoints were inserted - in which case
2104 we should just take the user literally and assume that any
2105 breakpoints should be left in place. */
2106 if (!may_insert_breakpoints
)
2108 warning (_("May not remove breakpoints"));
2112 return current_target
.to_remove_breakpoint (¤t_target
,
2117 target_info (char *args
, int from_tty
)
2119 struct target_ops
*t
;
2120 int has_all_mem
= 0;
2122 if (symfile_objfile
!= NULL
)
2123 printf_unfiltered (_("Symbols from \"%s\".\n"),
2124 objfile_name (symfile_objfile
));
2126 for (t
= target_stack
; t
!= NULL
; t
= t
->beneath
)
2128 if (!(*t
->to_has_memory
) (t
))
2131 if ((int) (t
->to_stratum
) <= (int) dummy_stratum
)
2134 printf_unfiltered (_("\tWhile running this, "
2135 "GDB does not access memory from...\n"));
2136 printf_unfiltered ("%s:\n", t
->to_longname
);
2137 (t
->to_files_info
) (t
);
2138 has_all_mem
= (*t
->to_has_all_memory
) (t
);
2142 /* This function is called before any new inferior is created, e.g.
2143 by running a program, attaching, or connecting to a target.
2144 It cleans up any state from previous invocations which might
2145 change between runs. This is a subset of what target_preopen
2146 resets (things which might change between targets). */
2149 target_pre_inferior (int from_tty
)
2151 /* Clear out solib state. Otherwise the solib state of the previous
2152 inferior might have survived and is entirely wrong for the new
2153 target. This has been observed on GNU/Linux using glibc 2.3. How
2165 Cannot access memory at address 0xdeadbeef
2168 /* In some OSs, the shared library list is the same/global/shared
2169 across inferiors. If code is shared between processes, so are
2170 memory regions and features. */
2171 if (!gdbarch_has_global_solist (target_gdbarch ()))
2173 no_shared_libraries (NULL
, from_tty
);
2175 invalidate_target_mem_regions ();
2177 target_clear_description ();
2180 agent_capability_invalidate ();
2183 /* Callback for iterate_over_inferiors. Gets rid of the given
2187 dispose_inferior (struct inferior
*inf
, void *args
)
2189 struct thread_info
*thread
;
2191 thread
= any_thread_of_process (inf
->pid
);
2194 switch_to_thread (thread
->ptid
);
2196 /* Core inferiors actually should be detached, not killed. */
2197 if (target_has_execution
)
2200 target_detach (NULL
, 0);
2206 /* This is to be called by the open routine before it does
2210 target_preopen (int from_tty
)
2214 if (have_inferiors ())
2217 || !have_live_inferiors ()
2218 || query (_("A program is being debugged already. Kill it? ")))
2219 iterate_over_inferiors (dispose_inferior
, NULL
);
2221 error (_("Program not killed."));
2224 /* Calling target_kill may remove the target from the stack. But if
2225 it doesn't (which seems like a win for UDI), remove it now. */
2226 /* Leave the exec target, though. The user may be switching from a
2227 live process to a core of the same program. */
2228 pop_all_targets_above (file_stratum
);
2230 target_pre_inferior (from_tty
);
2233 /* Detach a target after doing deferred register stores. */
2236 target_detach (const char *args
, int from_tty
)
2238 struct target_ops
* t
;
2240 if (gdbarch_has_global_breakpoints (target_gdbarch ()))
2241 /* Don't remove global breakpoints here. They're removed on
2242 disconnection from the target. */
2245 /* If we're in breakpoints-always-inserted mode, have to remove
2246 them before detaching. */
2247 remove_breakpoints_pid (ptid_get_pid (inferior_ptid
));
2249 prepare_for_detach ();
2251 current_target
.to_detach (¤t_target
, args
, from_tty
);
2253 fprintf_unfiltered (gdb_stdlog
, "target_detach (%s, %d)\n",
2258 target_disconnect (char *args
, int from_tty
)
2260 /* If we're in breakpoints-always-inserted mode or if breakpoints
2261 are global across processes, we have to remove them before
2263 remove_breakpoints ();
2266 fprintf_unfiltered (gdb_stdlog
, "target_disconnect (%s, %d)\n",
2268 current_target
.to_disconnect (¤t_target
, args
, from_tty
);
2272 target_wait (ptid_t ptid
, struct target_waitstatus
*status
, int options
)
2274 struct target_ops
*t
;
2275 ptid_t retval
= (current_target
.to_wait
) (¤t_target
, ptid
,
2280 char *status_string
;
2281 char *options_string
;
2283 status_string
= target_waitstatus_to_string (status
);
2284 options_string
= target_options_to_string (options
);
2285 fprintf_unfiltered (gdb_stdlog
,
2286 "target_wait (%d, status, options={%s})"
2288 ptid_get_pid (ptid
), options_string
,
2289 ptid_get_pid (retval
), status_string
);
2290 xfree (status_string
);
2291 xfree (options_string
);
2298 target_pid_to_str (ptid_t ptid
)
2300 return (*current_target
.to_pid_to_str
) (¤t_target
, ptid
);
2304 target_thread_name (struct thread_info
*info
)
2306 return current_target
.to_thread_name (¤t_target
, info
);
2310 target_resume (ptid_t ptid
, int step
, enum gdb_signal signal
)
2312 struct target_ops
*t
;
2314 target_dcache_invalidate ();
2316 current_target
.to_resume (¤t_target
, ptid
, step
, signal
);
2318 fprintf_unfiltered (gdb_stdlog
, "target_resume (%d, %s, %s)\n",
2319 ptid_get_pid (ptid
),
2320 step
? "step" : "continue",
2321 gdb_signal_to_name (signal
));
2323 registers_changed_ptid (ptid
);
2324 set_executing (ptid
, 1);
2325 set_running (ptid
, 1);
2326 clear_inline_frame_state (ptid
);
2330 target_pass_signals (int numsigs
, unsigned char *pass_signals
)
2336 fprintf_unfiltered (gdb_stdlog
, "target_pass_signals (%d, {",
2339 for (i
= 0; i
< numsigs
; i
++)
2340 if (pass_signals
[i
])
2341 fprintf_unfiltered (gdb_stdlog
, " %s",
2342 gdb_signal_to_name (i
));
2344 fprintf_unfiltered (gdb_stdlog
, " })\n");
2347 (*current_target
.to_pass_signals
) (¤t_target
, numsigs
, pass_signals
);
2351 target_program_signals (int numsigs
, unsigned char *program_signals
)
2357 fprintf_unfiltered (gdb_stdlog
, "target_program_signals (%d, {",
2360 for (i
= 0; i
< numsigs
; i
++)
2361 if (program_signals
[i
])
2362 fprintf_unfiltered (gdb_stdlog
, " %s",
2363 gdb_signal_to_name (i
));
2365 fprintf_unfiltered (gdb_stdlog
, " })\n");
2368 (*current_target
.to_program_signals
) (¤t_target
,
2369 numsigs
, program_signals
);
2373 default_follow_fork (struct target_ops
*self
, int follow_child
,
2376 /* Some target returned a fork event, but did not know how to follow it. */
2377 internal_error (__FILE__
, __LINE__
,
2378 _("could not find a target to follow fork"));
2381 /* Look through the list of possible targets for a target that can
2385 target_follow_fork (int follow_child
, int detach_fork
)
2387 int retval
= current_target
.to_follow_fork (¤t_target
,
2388 follow_child
, detach_fork
);
2391 fprintf_unfiltered (gdb_stdlog
,
2392 "target_follow_fork (%d, %d) = %d\n",
2393 follow_child
, detach_fork
, retval
);
2398 default_mourn_inferior (struct target_ops
*self
)
2400 internal_error (__FILE__
, __LINE__
,
2401 _("could not find a target to follow mourn inferior"));
2405 target_mourn_inferior (void)
2407 current_target
.to_mourn_inferior (¤t_target
);
2409 fprintf_unfiltered (gdb_stdlog
, "target_mourn_inferior ()\n");
2411 /* We no longer need to keep handles on any of the object files.
2412 Make sure to release them to avoid unnecessarily locking any
2413 of them while we're not actually debugging. */
2414 bfd_cache_close_all ();
2417 /* Look for a target which can describe architectural features, starting
2418 from TARGET. If we find one, return its description. */
2420 const struct target_desc
*
2421 target_read_description (struct target_ops
*target
)
2423 return target
->to_read_description (target
);
2426 /* This implements a basic search of memory, reading target memory and
2427 performing the search here (as opposed to performing the search in on the
2428 target side with, for example, gdbserver). */
2431 simple_search_memory (struct target_ops
*ops
,
2432 CORE_ADDR start_addr
, ULONGEST search_space_len
,
2433 const gdb_byte
*pattern
, ULONGEST pattern_len
,
2434 CORE_ADDR
*found_addrp
)
2436 /* NOTE: also defined in find.c testcase. */
2437 #define SEARCH_CHUNK_SIZE 16000
2438 const unsigned chunk_size
= SEARCH_CHUNK_SIZE
;
2439 /* Buffer to hold memory contents for searching. */
2440 gdb_byte
*search_buf
;
2441 unsigned search_buf_size
;
2442 struct cleanup
*old_cleanups
;
2444 search_buf_size
= chunk_size
+ pattern_len
- 1;
2446 /* No point in trying to allocate a buffer larger than the search space. */
2447 if (search_space_len
< search_buf_size
)
2448 search_buf_size
= search_space_len
;
2450 search_buf
= malloc (search_buf_size
);
2451 if (search_buf
== NULL
)
2452 error (_("Unable to allocate memory to perform the search."));
2453 old_cleanups
= make_cleanup (free_current_contents
, &search_buf
);
2455 /* Prime the search buffer. */
2457 if (target_read (ops
, TARGET_OBJECT_MEMORY
, NULL
,
2458 search_buf
, start_addr
, search_buf_size
) != search_buf_size
)
2460 warning (_("Unable to access %s bytes of target "
2461 "memory at %s, halting search."),
2462 pulongest (search_buf_size
), hex_string (start_addr
));
2463 do_cleanups (old_cleanups
);
2467 /* Perform the search.
2469 The loop is kept simple by allocating [N + pattern-length - 1] bytes.
2470 When we've scanned N bytes we copy the trailing bytes to the start and
2471 read in another N bytes. */
2473 while (search_space_len
>= pattern_len
)
2475 gdb_byte
*found_ptr
;
2476 unsigned nr_search_bytes
= min (search_space_len
, search_buf_size
);
2478 found_ptr
= memmem (search_buf
, nr_search_bytes
,
2479 pattern
, pattern_len
);
2481 if (found_ptr
!= NULL
)
2483 CORE_ADDR found_addr
= start_addr
+ (found_ptr
- search_buf
);
2485 *found_addrp
= found_addr
;
2486 do_cleanups (old_cleanups
);
2490 /* Not found in this chunk, skip to next chunk. */
2492 /* Don't let search_space_len wrap here, it's unsigned. */
2493 if (search_space_len
>= chunk_size
)
2494 search_space_len
-= chunk_size
;
2496 search_space_len
= 0;
2498 if (search_space_len
>= pattern_len
)
2500 unsigned keep_len
= search_buf_size
- chunk_size
;
2501 CORE_ADDR read_addr
= start_addr
+ chunk_size
+ keep_len
;
2504 /* Copy the trailing part of the previous iteration to the front
2505 of the buffer for the next iteration. */
2506 gdb_assert (keep_len
== pattern_len
- 1);
2507 memcpy (search_buf
, search_buf
+ chunk_size
, keep_len
);
2509 nr_to_read
= min (search_space_len
- keep_len
, chunk_size
);
2511 if (target_read (ops
, TARGET_OBJECT_MEMORY
, NULL
,
2512 search_buf
+ keep_len
, read_addr
,
2513 nr_to_read
) != nr_to_read
)
2515 warning (_("Unable to access %s bytes of target "
2516 "memory at %s, halting search."),
2517 plongest (nr_to_read
),
2518 hex_string (read_addr
));
2519 do_cleanups (old_cleanups
);
2523 start_addr
+= chunk_size
;
2529 do_cleanups (old_cleanups
);
2533 /* Default implementation of memory-searching. */
2536 default_search_memory (struct target_ops
*self
,
2537 CORE_ADDR start_addr
, ULONGEST search_space_len
,
2538 const gdb_byte
*pattern
, ULONGEST pattern_len
,
2539 CORE_ADDR
*found_addrp
)
2541 /* Start over from the top of the target stack. */
2542 return simple_search_memory (current_target
.beneath
,
2543 start_addr
, search_space_len
,
2544 pattern
, pattern_len
, found_addrp
);
2547 /* Search SEARCH_SPACE_LEN bytes beginning at START_ADDR for the
2548 sequence of bytes in PATTERN with length PATTERN_LEN.
2550 The result is 1 if found, 0 if not found, and -1 if there was an error
2551 requiring halting of the search (e.g. memory read error).
2552 If the pattern is found the address is recorded in FOUND_ADDRP. */
2555 target_search_memory (CORE_ADDR start_addr
, ULONGEST search_space_len
,
2556 const gdb_byte
*pattern
, ULONGEST pattern_len
,
2557 CORE_ADDR
*found_addrp
)
2562 fprintf_unfiltered (gdb_stdlog
, "target_search_memory (%s, ...)\n",
2563 hex_string (start_addr
));
2565 found
= current_target
.to_search_memory (¤t_target
, start_addr
,
2567 pattern
, pattern_len
, found_addrp
);
2570 fprintf_unfiltered (gdb_stdlog
, " = %d\n", found
);
2575 /* Look through the currently pushed targets. If none of them will
2576 be able to restart the currently running process, issue an error
2580 target_require_runnable (void)
2582 struct target_ops
*t
;
2584 for (t
= target_stack
; t
!= NULL
; t
= t
->beneath
)
2586 /* If this target knows how to create a new program, then
2587 assume we will still be able to after killing the current
2588 one. Either killing and mourning will not pop T, or else
2589 find_default_run_target will find it again. */
2590 if (t
->to_create_inferior
!= NULL
)
2593 /* Do not worry about thread_stratum targets that can not
2594 create inferiors. Assume they will be pushed again if
2595 necessary, and continue to the process_stratum. */
2596 if (t
->to_stratum
== thread_stratum
2597 || t
->to_stratum
== arch_stratum
)
2600 error (_("The \"%s\" target does not support \"run\". "
2601 "Try \"help target\" or \"continue\"."),
2605 /* This function is only called if the target is running. In that
2606 case there should have been a process_stratum target and it
2607 should either know how to create inferiors, or not... */
2608 internal_error (__FILE__
, __LINE__
, _("No targets found"));
2611 /* Look through the list of possible targets for a target that can
2612 execute a run or attach command without any other data. This is
2613 used to locate the default process stratum.
2615 If DO_MESG is not NULL, the result is always valid (error() is
2616 called for errors); else, return NULL on error. */
2618 static struct target_ops
*
2619 find_default_run_target (char *do_mesg
)
2621 struct target_ops
**t
;
2622 struct target_ops
*runable
= NULL
;
2627 for (t
= target_structs
; t
< target_structs
+ target_struct_size
;
2630 if ((*t
)->to_can_run
!= delegate_can_run
&& target_can_run (*t
))
2640 error (_("Don't know how to %s. Try \"help target\"."), do_mesg
);
2649 find_default_attach (struct target_ops
*ops
, char *args
, int from_tty
)
2651 struct target_ops
*t
;
2653 t
= find_default_run_target ("attach");
2654 (t
->to_attach
) (t
, args
, from_tty
);
2659 find_default_create_inferior (struct target_ops
*ops
,
2660 char *exec_file
, char *allargs
, char **env
,
2663 struct target_ops
*t
;
2665 t
= find_default_run_target ("run");
2666 (t
->to_create_inferior
) (t
, exec_file
, allargs
, env
, from_tty
);
2671 find_default_can_async_p (struct target_ops
*ignore
)
2673 struct target_ops
*t
;
2675 /* This may be called before the target is pushed on the stack;
2676 look for the default process stratum. If there's none, gdb isn't
2677 configured with a native debugger, and target remote isn't
2679 t
= find_default_run_target (NULL
);
2680 if (t
&& t
->to_can_async_p
!= delegate_can_async_p
)
2681 return (t
->to_can_async_p
) (t
);
2686 find_default_is_async_p (struct target_ops
*ignore
)
2688 struct target_ops
*t
;
2690 /* This may be called before the target is pushed on the stack;
2691 look for the default process stratum. If there's none, gdb isn't
2692 configured with a native debugger, and target remote isn't
2694 t
= find_default_run_target (NULL
);
2695 if (t
&& t
->to_is_async_p
!= delegate_is_async_p
)
2696 return (t
->to_is_async_p
) (t
);
2701 find_default_supports_non_stop (struct target_ops
*self
)
2703 struct target_ops
*t
;
2705 t
= find_default_run_target (NULL
);
2706 if (t
&& t
->to_supports_non_stop
)
2707 return (t
->to_supports_non_stop
) (t
);
2712 target_supports_non_stop (void)
2714 struct target_ops
*t
;
2716 for (t
= ¤t_target
; t
!= NULL
; t
= t
->beneath
)
2717 if (t
->to_supports_non_stop
)
2718 return t
->to_supports_non_stop (t
);
2723 /* Implement the "info proc" command. */
2726 target_info_proc (char *args
, enum info_proc_what what
)
2728 struct target_ops
*t
;
2730 /* If we're already connected to something that can get us OS
2731 related data, use it. Otherwise, try using the native
2733 if (current_target
.to_stratum
>= process_stratum
)
2734 t
= current_target
.beneath
;
2736 t
= find_default_run_target (NULL
);
2738 for (; t
!= NULL
; t
= t
->beneath
)
2740 if (t
->to_info_proc
!= NULL
)
2742 t
->to_info_proc (t
, args
, what
);
2745 fprintf_unfiltered (gdb_stdlog
,
2746 "target_info_proc (\"%s\", %d)\n", args
, what
);
2756 find_default_supports_disable_randomization (struct target_ops
*self
)
2758 struct target_ops
*t
;
2760 t
= find_default_run_target (NULL
);
2761 if (t
&& t
->to_supports_disable_randomization
)
2762 return (t
->to_supports_disable_randomization
) (t
);
2767 target_supports_disable_randomization (void)
2769 struct target_ops
*t
;
2771 for (t
= ¤t_target
; t
!= NULL
; t
= t
->beneath
)
2772 if (t
->to_supports_disable_randomization
)
2773 return t
->to_supports_disable_randomization (t
);
2779 target_get_osdata (const char *type
)
2781 struct target_ops
*t
;
2783 /* If we're already connected to something that can get us OS
2784 related data, use it. Otherwise, try using the native
2786 if (current_target
.to_stratum
>= process_stratum
)
2787 t
= current_target
.beneath
;
2789 t
= find_default_run_target ("get OS data");
2794 return target_read_stralloc (t
, TARGET_OBJECT_OSDATA
, type
);
2797 /* Determine the current address space of thread PTID. */
2799 struct address_space
*
2800 target_thread_address_space (ptid_t ptid
)
2802 struct address_space
*aspace
;
2803 struct inferior
*inf
;
2804 struct target_ops
*t
;
2806 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
2808 if (t
->to_thread_address_space
!= NULL
)
2810 aspace
= t
->to_thread_address_space (t
, ptid
);
2811 gdb_assert (aspace
);
2814 fprintf_unfiltered (gdb_stdlog
,
2815 "target_thread_address_space (%s) = %d\n",
2816 target_pid_to_str (ptid
),
2817 address_space_num (aspace
));
2822 /* Fall-back to the "main" address space of the inferior. */
2823 inf
= find_inferior_pid (ptid_get_pid (ptid
));
2825 if (inf
== NULL
|| inf
->aspace
== NULL
)
2826 internal_error (__FILE__
, __LINE__
,
2827 _("Can't determine the current "
2828 "address space of thread %s\n"),
2829 target_pid_to_str (ptid
));
2835 /* Target file operations. */
2837 static struct target_ops
*
2838 default_fileio_target (void)
2840 /* If we're already connected to something that can perform
2841 file I/O, use it. Otherwise, try using the native target. */
2842 if (current_target
.to_stratum
>= process_stratum
)
2843 return current_target
.beneath
;
2845 return find_default_run_target ("file I/O");
2848 /* Open FILENAME on the target, using FLAGS and MODE. Return a
2849 target file descriptor, or -1 if an error occurs (and set
2852 target_fileio_open (const char *filename
, int flags
, int mode
,
2855 struct target_ops
*t
;
2857 for (t
= default_fileio_target (); t
!= NULL
; t
= t
->beneath
)
2859 if (t
->to_fileio_open
!= NULL
)
2861 int fd
= t
->to_fileio_open (t
, filename
, flags
, mode
, target_errno
);
2864 fprintf_unfiltered (gdb_stdlog
,
2865 "target_fileio_open (%s,0x%x,0%o) = %d (%d)\n",
2866 filename
, flags
, mode
,
2867 fd
, fd
!= -1 ? 0 : *target_errno
);
2872 *target_errno
= FILEIO_ENOSYS
;
2876 /* Write up to LEN bytes from WRITE_BUF to FD on the target.
2877 Return the number of bytes written, or -1 if an error occurs
2878 (and set *TARGET_ERRNO). */
2880 target_fileio_pwrite (int fd
, const gdb_byte
*write_buf
, int len
,
2881 ULONGEST offset
, int *target_errno
)
2883 struct target_ops
*t
;
2885 for (t
= default_fileio_target (); t
!= NULL
; t
= t
->beneath
)
2887 if (t
->to_fileio_pwrite
!= NULL
)
2889 int ret
= t
->to_fileio_pwrite (t
, fd
, write_buf
, len
, offset
,
2893 fprintf_unfiltered (gdb_stdlog
,
2894 "target_fileio_pwrite (%d,...,%d,%s) "
2896 fd
, len
, pulongest (offset
),
2897 ret
, ret
!= -1 ? 0 : *target_errno
);
2902 *target_errno
= FILEIO_ENOSYS
;
2906 /* Read up to LEN bytes FD on the target into READ_BUF.
2907 Return the number of bytes read, or -1 if an error occurs
2908 (and set *TARGET_ERRNO). */
2910 target_fileio_pread (int fd
, gdb_byte
*read_buf
, int len
,
2911 ULONGEST offset
, int *target_errno
)
2913 struct target_ops
*t
;
2915 for (t
= default_fileio_target (); t
!= NULL
; t
= t
->beneath
)
2917 if (t
->to_fileio_pread
!= NULL
)
2919 int ret
= t
->to_fileio_pread (t
, fd
, read_buf
, len
, offset
,
2923 fprintf_unfiltered (gdb_stdlog
,
2924 "target_fileio_pread (%d,...,%d,%s) "
2926 fd
, len
, pulongest (offset
),
2927 ret
, ret
!= -1 ? 0 : *target_errno
);
2932 *target_errno
= FILEIO_ENOSYS
;
2936 /* Close FD on the target. Return 0, or -1 if an error occurs
2937 (and set *TARGET_ERRNO). */
2939 target_fileio_close (int fd
, int *target_errno
)
2941 struct target_ops
*t
;
2943 for (t
= default_fileio_target (); t
!= NULL
; t
= t
->beneath
)
2945 if (t
->to_fileio_close
!= NULL
)
2947 int ret
= t
->to_fileio_close (t
, fd
, target_errno
);
2950 fprintf_unfiltered (gdb_stdlog
,
2951 "target_fileio_close (%d) = %d (%d)\n",
2952 fd
, ret
, ret
!= -1 ? 0 : *target_errno
);
2957 *target_errno
= FILEIO_ENOSYS
;
2961 /* Unlink FILENAME on the target. Return 0, or -1 if an error
2962 occurs (and set *TARGET_ERRNO). */
2964 target_fileio_unlink (const char *filename
, int *target_errno
)
2966 struct target_ops
*t
;
2968 for (t
= default_fileio_target (); t
!= NULL
; t
= t
->beneath
)
2970 if (t
->to_fileio_unlink
!= NULL
)
2972 int ret
= t
->to_fileio_unlink (t
, filename
, target_errno
);
2975 fprintf_unfiltered (gdb_stdlog
,
2976 "target_fileio_unlink (%s) = %d (%d)\n",
2977 filename
, ret
, ret
!= -1 ? 0 : *target_errno
);
2982 *target_errno
= FILEIO_ENOSYS
;
2986 /* Read value of symbolic link FILENAME on the target. Return a
2987 null-terminated string allocated via xmalloc, or NULL if an error
2988 occurs (and set *TARGET_ERRNO). */
2990 target_fileio_readlink (const char *filename
, int *target_errno
)
2992 struct target_ops
*t
;
2994 for (t
= default_fileio_target (); t
!= NULL
; t
= t
->beneath
)
2996 if (t
->to_fileio_readlink
!= NULL
)
2998 char *ret
= t
->to_fileio_readlink (t
, filename
, target_errno
);
3001 fprintf_unfiltered (gdb_stdlog
,
3002 "target_fileio_readlink (%s) = %s (%d)\n",
3003 filename
, ret
? ret
: "(nil)",
3004 ret
? 0 : *target_errno
);
3009 *target_errno
= FILEIO_ENOSYS
;
3014 target_fileio_close_cleanup (void *opaque
)
3016 int fd
= *(int *) opaque
;
3019 target_fileio_close (fd
, &target_errno
);
3022 /* Read target file FILENAME. Store the result in *BUF_P and
3023 return the size of the transferred data. PADDING additional bytes are
3024 available in *BUF_P. This is a helper function for
3025 target_fileio_read_alloc; see the declaration of that function for more
3029 target_fileio_read_alloc_1 (const char *filename
,
3030 gdb_byte
**buf_p
, int padding
)
3032 struct cleanup
*close_cleanup
;
3033 size_t buf_alloc
, buf_pos
;
3039 fd
= target_fileio_open (filename
, FILEIO_O_RDONLY
, 0700, &target_errno
);
3043 close_cleanup
= make_cleanup (target_fileio_close_cleanup
, &fd
);
3045 /* Start by reading up to 4K at a time. The target will throttle
3046 this number down if necessary. */
3048 buf
= xmalloc (buf_alloc
);
3052 n
= target_fileio_pread (fd
, &buf
[buf_pos
],
3053 buf_alloc
- buf_pos
- padding
, buf_pos
,
3057 /* An error occurred. */
3058 do_cleanups (close_cleanup
);
3064 /* Read all there was. */
3065 do_cleanups (close_cleanup
);
3075 /* If the buffer is filling up, expand it. */
3076 if (buf_alloc
< buf_pos
* 2)
3079 buf
= xrealloc (buf
, buf_alloc
);
3086 /* Read target file FILENAME. Store the result in *BUF_P and return
3087 the size of the transferred data. See the declaration in "target.h"
3088 function for more information about the return value. */
3091 target_fileio_read_alloc (const char *filename
, gdb_byte
**buf_p
)
3093 return target_fileio_read_alloc_1 (filename
, buf_p
, 0);
3096 /* Read target file FILENAME. The result is NUL-terminated and
3097 returned as a string, allocated using xmalloc. If an error occurs
3098 or the transfer is unsupported, NULL is returned. Empty objects
3099 are returned as allocated but empty strings. A warning is issued
3100 if the result contains any embedded NUL bytes. */
3103 target_fileio_read_stralloc (const char *filename
)
3107 LONGEST i
, transferred
;
3109 transferred
= target_fileio_read_alloc_1 (filename
, &buffer
, 1);
3110 bufstr
= (char *) buffer
;
3112 if (transferred
< 0)
3115 if (transferred
== 0)
3116 return xstrdup ("");
3118 bufstr
[transferred
] = 0;
3120 /* Check for embedded NUL bytes; but allow trailing NULs. */
3121 for (i
= strlen (bufstr
); i
< transferred
; i
++)
3124 warning (_("target file %s "
3125 "contained unexpected null characters"),
3135 default_region_ok_for_hw_watchpoint (struct target_ops
*self
,
3136 CORE_ADDR addr
, int len
)
3138 return (len
<= gdbarch_ptr_bit (target_gdbarch ()) / TARGET_CHAR_BIT
);
3142 default_watchpoint_addr_within_range (struct target_ops
*target
,
3144 CORE_ADDR start
, int length
)
3146 return addr
>= start
&& addr
< start
+ length
;
3149 static struct gdbarch
*
3150 default_thread_architecture (struct target_ops
*ops
, ptid_t ptid
)
3152 return target_gdbarch ();
3156 return_zero (struct target_ops
*ignore
)
3162 return_zero_has_execution (struct target_ops
*ignore
, ptid_t ignore2
)
3168 * Find the next target down the stack from the specified target.
3172 find_target_beneath (struct target_ops
*t
)
3180 find_target_at (enum strata stratum
)
3182 struct target_ops
*t
;
3184 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
3185 if (t
->to_stratum
== stratum
)
3192 /* The inferior process has died. Long live the inferior! */
3195 generic_mourn_inferior (void)
3199 ptid
= inferior_ptid
;
3200 inferior_ptid
= null_ptid
;
3202 /* Mark breakpoints uninserted in case something tries to delete a
3203 breakpoint while we delete the inferior's threads (which would
3204 fail, since the inferior is long gone). */
3205 mark_breakpoints_out ();
3207 if (!ptid_equal (ptid
, null_ptid
))
3209 int pid
= ptid_get_pid (ptid
);
3210 exit_inferior (pid
);
3213 /* Note this wipes step-resume breakpoints, so needs to be done
3214 after exit_inferior, which ends up referencing the step-resume
3215 breakpoints through clear_thread_inferior_resources. */
3216 breakpoint_init_inferior (inf_exited
);
3218 registers_changed ();
3220 reopen_exec_file ();
3221 reinit_frame_cache ();
3223 if (deprecated_detach_hook
)
3224 deprecated_detach_hook ();
3227 /* Convert a normal process ID to a string. Returns the string in a
3231 normal_pid_to_str (ptid_t ptid
)
3233 static char buf
[32];
3235 xsnprintf (buf
, sizeof buf
, "process %d", ptid_get_pid (ptid
));
3240 default_pid_to_str (struct target_ops
*ops
, ptid_t ptid
)
3242 return normal_pid_to_str (ptid
);
3245 /* Error-catcher for target_find_memory_regions. */
3247 dummy_find_memory_regions (struct target_ops
*self
,
3248 find_memory_region_ftype ignore1
, void *ignore2
)
3250 error (_("Command not implemented for this target."));
3254 /* Error-catcher for target_make_corefile_notes. */
3256 dummy_make_corefile_notes (struct target_ops
*self
,
3257 bfd
*ignore1
, int *ignore2
)
3259 error (_("Command not implemented for this target."));
3263 /* Set up the handful of non-empty slots needed by the dummy target
3267 init_dummy_target (void)
3269 dummy_target
.to_shortname
= "None";
3270 dummy_target
.to_longname
= "None";
3271 dummy_target
.to_doc
= "";
3272 dummy_target
.to_create_inferior
= find_default_create_inferior
;
3273 dummy_target
.to_supports_non_stop
= find_default_supports_non_stop
;
3274 dummy_target
.to_supports_disable_randomization
3275 = find_default_supports_disable_randomization
;
3276 dummy_target
.to_stratum
= dummy_stratum
;
3277 dummy_target
.to_has_all_memory
= return_zero
;
3278 dummy_target
.to_has_memory
= return_zero
;
3279 dummy_target
.to_has_stack
= return_zero
;
3280 dummy_target
.to_has_registers
= return_zero
;
3281 dummy_target
.to_has_execution
= return_zero_has_execution
;
3282 dummy_target
.to_magic
= OPS_MAGIC
;
3284 install_dummy_methods (&dummy_target
);
3288 debug_to_open (char *args
, int from_tty
)
3290 debug_target
.to_open (args
, from_tty
);
3292 fprintf_unfiltered (gdb_stdlog
, "target_open (%s, %d)\n", args
, from_tty
);
3296 target_close (struct target_ops
*targ
)
3298 gdb_assert (!target_is_pushed (targ
));
3300 if (targ
->to_xclose
!= NULL
)
3301 targ
->to_xclose (targ
);
3302 else if (targ
->to_close
!= NULL
)
3303 targ
->to_close (targ
);
3306 fprintf_unfiltered (gdb_stdlog
, "target_close ()\n");
3310 target_attach (char *args
, int from_tty
)
3312 current_target
.to_attach (¤t_target
, args
, from_tty
);
3314 fprintf_unfiltered (gdb_stdlog
, "target_attach (%s, %d)\n",
3319 target_thread_alive (ptid_t ptid
)
3323 retval
= current_target
.to_thread_alive (¤t_target
, ptid
);
3325 fprintf_unfiltered (gdb_stdlog
, "target_thread_alive (%d) = %d\n",
3326 ptid_get_pid (ptid
), retval
);
3332 target_find_new_threads (void)
3334 current_target
.to_find_new_threads (¤t_target
);
3336 fprintf_unfiltered (gdb_stdlog
, "target_find_new_threads ()\n");
3340 target_stop (ptid_t ptid
)
3344 warning (_("May not interrupt or stop the target, ignoring attempt"));
3348 (*current_target
.to_stop
) (¤t_target
, ptid
);
3352 debug_to_post_attach (struct target_ops
*self
, int pid
)
3354 debug_target
.to_post_attach (&debug_target
, pid
);
3356 fprintf_unfiltered (gdb_stdlog
, "target_post_attach (%d)\n", pid
);
3359 /* Concatenate ELEM to LIST, a comma separate list, and return the
3360 result. The LIST incoming argument is released. */
3363 str_comma_list_concat_elem (char *list
, const char *elem
)
3366 return xstrdup (elem
);
3368 return reconcat (list
, list
, ", ", elem
, (char *) NULL
);
3371 /* Helper for target_options_to_string. If OPT is present in
3372 TARGET_OPTIONS, append the OPT_STR (string version of OPT) in RET.
3373 Returns the new resulting string. OPT is removed from
3377 do_option (int *target_options
, char *ret
,
3378 int opt
, char *opt_str
)
3380 if ((*target_options
& opt
) != 0)
3382 ret
= str_comma_list_concat_elem (ret
, opt_str
);
3383 *target_options
&= ~opt
;
3390 target_options_to_string (int target_options
)
3394 #define DO_TARG_OPTION(OPT) \
3395 ret = do_option (&target_options, ret, OPT, #OPT)
3397 DO_TARG_OPTION (TARGET_WNOHANG
);
3399 if (target_options
!= 0)
3400 ret
= str_comma_list_concat_elem (ret
, "unknown???");
3408 debug_print_register (const char * func
,
3409 struct regcache
*regcache
, int regno
)
3411 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
3413 fprintf_unfiltered (gdb_stdlog
, "%s ", func
);
3414 if (regno
>= 0 && regno
< gdbarch_num_regs (gdbarch
)
3415 && gdbarch_register_name (gdbarch
, regno
) != NULL
3416 && gdbarch_register_name (gdbarch
, regno
)[0] != '\0')
3417 fprintf_unfiltered (gdb_stdlog
, "(%s)",
3418 gdbarch_register_name (gdbarch
, regno
));
3420 fprintf_unfiltered (gdb_stdlog
, "(%d)", regno
);
3421 if (regno
>= 0 && regno
< gdbarch_num_regs (gdbarch
))
3423 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
3424 int i
, size
= register_size (gdbarch
, regno
);
3425 gdb_byte buf
[MAX_REGISTER_SIZE
];
3427 regcache_raw_collect (regcache
, regno
, buf
);
3428 fprintf_unfiltered (gdb_stdlog
, " = ");
3429 for (i
= 0; i
< size
; i
++)
3431 fprintf_unfiltered (gdb_stdlog
, "%02x", buf
[i
]);
3433 if (size
<= sizeof (LONGEST
))
3435 ULONGEST val
= extract_unsigned_integer (buf
, size
, byte_order
);
3437 fprintf_unfiltered (gdb_stdlog
, " %s %s",
3438 core_addr_to_string_nz (val
), plongest (val
));
3441 fprintf_unfiltered (gdb_stdlog
, "\n");
3445 target_fetch_registers (struct regcache
*regcache
, int regno
)
3447 current_target
.to_fetch_registers (¤t_target
, regcache
, regno
);
3449 debug_print_register ("target_fetch_registers", regcache
, regno
);
3453 target_store_registers (struct regcache
*regcache
, int regno
)
3455 struct target_ops
*t
;
3457 if (!may_write_registers
)
3458 error (_("Writing to registers is not allowed (regno %d)"), regno
);
3460 current_target
.to_store_registers (¤t_target
, regcache
, regno
);
3463 debug_print_register ("target_store_registers", regcache
, regno
);
3468 target_core_of_thread (ptid_t ptid
)
3470 int retval
= current_target
.to_core_of_thread (¤t_target
, ptid
);
3473 fprintf_unfiltered (gdb_stdlog
,
3474 "target_core_of_thread (%d) = %d\n",
3475 ptid_get_pid (ptid
), retval
);
3480 target_verify_memory (const gdb_byte
*data
, CORE_ADDR memaddr
, ULONGEST size
)
3482 int retval
= current_target
.to_verify_memory (¤t_target
,
3483 data
, memaddr
, size
);
3486 fprintf_unfiltered (gdb_stdlog
,
3487 "target_verify_memory (%s, %s) = %d\n",
3488 paddress (target_gdbarch (), memaddr
),
3494 /* The documentation for this function is in its prototype declaration in
3498 target_insert_mask_watchpoint (CORE_ADDR addr
, CORE_ADDR mask
, int rw
)
3502 ret
= current_target
.to_insert_mask_watchpoint (¤t_target
,
3506 fprintf_unfiltered (gdb_stdlog
, "\
3507 target_insert_mask_watchpoint (%s, %s, %d) = %d\n",
3508 core_addr_to_string (addr
),
3509 core_addr_to_string (mask
), rw
, ret
);
3514 /* The documentation for this function is in its prototype declaration in
3518 target_remove_mask_watchpoint (CORE_ADDR addr
, CORE_ADDR mask
, int rw
)
3522 ret
= current_target
.to_remove_mask_watchpoint (¤t_target
,
3526 fprintf_unfiltered (gdb_stdlog
, "\
3527 target_remove_mask_watchpoint (%s, %s, %d) = %d\n",
3528 core_addr_to_string (addr
),
3529 core_addr_to_string (mask
), rw
, ret
);
3534 /* The documentation for this function is in its prototype declaration
3538 target_masked_watch_num_registers (CORE_ADDR addr
, CORE_ADDR mask
)
3540 return current_target
.to_masked_watch_num_registers (¤t_target
,
3544 /* The documentation for this function is in its prototype declaration
3548 target_ranged_break_num_registers (void)
3550 return current_target
.to_ranged_break_num_registers (¤t_target
);
3555 struct btrace_target_info
*
3556 target_enable_btrace (ptid_t ptid
)
3558 return current_target
.to_enable_btrace (¤t_target
, ptid
);
3564 target_disable_btrace (struct btrace_target_info
*btinfo
)
3566 current_target
.to_disable_btrace (¤t_target
, btinfo
);
3572 target_teardown_btrace (struct btrace_target_info
*btinfo
)
3574 current_target
.to_teardown_btrace (¤t_target
, btinfo
);
3580 target_read_btrace (VEC (btrace_block_s
) **btrace
,
3581 struct btrace_target_info
*btinfo
,
3582 enum btrace_read_type type
)
3584 return current_target
.to_read_btrace (¤t_target
, btrace
, btinfo
, type
);
3590 target_stop_recording (void)
3592 current_target
.to_stop_recording (¤t_target
);
3598 target_info_record (void)
3600 struct target_ops
*t
;
3602 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
3603 if (t
->to_info_record
!= NULL
)
3605 t
->to_info_record (t
);
3615 target_save_record (const char *filename
)
3617 current_target
.to_save_record (¤t_target
, filename
);
3623 target_supports_delete_record (void)
3625 struct target_ops
*t
;
3627 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
3628 if (t
->to_delete_record
!= NULL
)
3637 target_delete_record (void)
3639 current_target
.to_delete_record (¤t_target
);
3645 target_record_is_replaying (void)
3647 return current_target
.to_record_is_replaying (¤t_target
);
3653 target_goto_record_begin (void)
3655 current_target
.to_goto_record_begin (¤t_target
);
3661 target_goto_record_end (void)
3663 current_target
.to_goto_record_end (¤t_target
);
3669 target_goto_record (ULONGEST insn
)
3671 current_target
.to_goto_record (¤t_target
, insn
);
3677 target_insn_history (int size
, int flags
)
3679 current_target
.to_insn_history (¤t_target
, size
, flags
);
3685 target_insn_history_from (ULONGEST from
, int size
, int flags
)
3687 current_target
.to_insn_history_from (¤t_target
, from
, size
, flags
);
3693 target_insn_history_range (ULONGEST begin
, ULONGEST end
, int flags
)
3695 current_target
.to_insn_history_range (¤t_target
, begin
, end
, flags
);
3701 target_call_history (int size
, int flags
)
3703 current_target
.to_call_history (¤t_target
, size
, flags
);
3709 target_call_history_from (ULONGEST begin
, int size
, int flags
)
3711 current_target
.to_call_history_from (¤t_target
, begin
, size
, flags
);
3717 target_call_history_range (ULONGEST begin
, ULONGEST end
, int flags
)
3719 current_target
.to_call_history_range (¤t_target
, begin
, end
, flags
);
3723 debug_to_prepare_to_store (struct target_ops
*self
, struct regcache
*regcache
)
3725 debug_target
.to_prepare_to_store (&debug_target
, regcache
);
3727 fprintf_unfiltered (gdb_stdlog
, "target_prepare_to_store ()\n");
3732 const struct frame_unwind
*
3733 target_get_unwinder (void)
3735 return current_target
.to_get_unwinder (¤t_target
);
3740 const struct frame_unwind
*
3741 target_get_tailcall_unwinder (void)
3743 return current_target
.to_get_tailcall_unwinder (¤t_target
);
3746 /* Default implementation of to_decr_pc_after_break. */
3749 default_target_decr_pc_after_break (struct target_ops
*ops
,
3750 struct gdbarch
*gdbarch
)
3752 return gdbarch_decr_pc_after_break (gdbarch
);
3758 target_decr_pc_after_break (struct gdbarch
*gdbarch
)
3760 return current_target
.to_decr_pc_after_break (¤t_target
, gdbarch
);
3764 debug_to_files_info (struct target_ops
*target
)
3766 debug_target
.to_files_info (target
);
3768 fprintf_unfiltered (gdb_stdlog
, "target_files_info (xxx)\n");
3772 debug_to_insert_breakpoint (struct target_ops
*ops
, struct gdbarch
*gdbarch
,
3773 struct bp_target_info
*bp_tgt
)
3777 retval
= debug_target
.to_insert_breakpoint (&debug_target
, gdbarch
, bp_tgt
);
3779 fprintf_unfiltered (gdb_stdlog
,
3780 "target_insert_breakpoint (%s, xxx) = %ld\n",
3781 core_addr_to_string (bp_tgt
->placed_address
),
3782 (unsigned long) retval
);
3787 debug_to_remove_breakpoint (struct target_ops
*ops
, struct gdbarch
*gdbarch
,
3788 struct bp_target_info
*bp_tgt
)
3792 retval
= debug_target
.to_remove_breakpoint (&debug_target
, gdbarch
, bp_tgt
);
3794 fprintf_unfiltered (gdb_stdlog
,
3795 "target_remove_breakpoint (%s, xxx) = %ld\n",
3796 core_addr_to_string (bp_tgt
->placed_address
),
3797 (unsigned long) retval
);
3802 debug_to_can_use_hw_breakpoint (struct target_ops
*self
,
3803 int type
, int cnt
, int from_tty
)
3807 retval
= debug_target
.to_can_use_hw_breakpoint (&debug_target
,
3808 type
, cnt
, from_tty
);
3810 fprintf_unfiltered (gdb_stdlog
,
3811 "target_can_use_hw_breakpoint (%ld, %ld, %ld) = %ld\n",
3812 (unsigned long) type
,
3813 (unsigned long) cnt
,
3814 (unsigned long) from_tty
,
3815 (unsigned long) retval
);
3820 debug_to_region_ok_for_hw_watchpoint (struct target_ops
*self
,
3821 CORE_ADDR addr
, int len
)
3825 retval
= debug_target
.to_region_ok_for_hw_watchpoint (&debug_target
,
3828 fprintf_unfiltered (gdb_stdlog
,
3829 "target_region_ok_for_hw_watchpoint (%s, %ld) = %s\n",
3830 core_addr_to_string (addr
), (unsigned long) len
,
3831 core_addr_to_string (retval
));
3836 debug_to_can_accel_watchpoint_condition (struct target_ops
*self
,
3837 CORE_ADDR addr
, int len
, int rw
,
3838 struct expression
*cond
)
3842 retval
= debug_target
.to_can_accel_watchpoint_condition (&debug_target
,
3846 fprintf_unfiltered (gdb_stdlog
,
3847 "target_can_accel_watchpoint_condition "
3848 "(%s, %d, %d, %s) = %ld\n",
3849 core_addr_to_string (addr
), len
, rw
,
3850 host_address_to_string (cond
), (unsigned long) retval
);
3855 debug_to_stopped_by_watchpoint (struct target_ops
*ops
)
3859 retval
= debug_target
.to_stopped_by_watchpoint (&debug_target
);
3861 fprintf_unfiltered (gdb_stdlog
,
3862 "target_stopped_by_watchpoint () = %ld\n",
3863 (unsigned long) retval
);
3868 debug_to_stopped_data_address (struct target_ops
*target
, CORE_ADDR
*addr
)
3872 retval
= debug_target
.to_stopped_data_address (target
, addr
);
3874 fprintf_unfiltered (gdb_stdlog
,
3875 "target_stopped_data_address ([%s]) = %ld\n",
3876 core_addr_to_string (*addr
),
3877 (unsigned long)retval
);
3882 debug_to_watchpoint_addr_within_range (struct target_ops
*target
,
3884 CORE_ADDR start
, int length
)
3888 retval
= debug_target
.to_watchpoint_addr_within_range (target
, addr
,
3891 fprintf_filtered (gdb_stdlog
,
3892 "target_watchpoint_addr_within_range (%s, %s, %d) = %d\n",
3893 core_addr_to_string (addr
), core_addr_to_string (start
),
3899 debug_to_insert_hw_breakpoint (struct target_ops
*self
,
3900 struct gdbarch
*gdbarch
,
3901 struct bp_target_info
*bp_tgt
)
3905 retval
= debug_target
.to_insert_hw_breakpoint (&debug_target
,
3908 fprintf_unfiltered (gdb_stdlog
,
3909 "target_insert_hw_breakpoint (%s, xxx) = %ld\n",
3910 core_addr_to_string (bp_tgt
->placed_address
),
3911 (unsigned long) retval
);
3916 debug_to_remove_hw_breakpoint (struct target_ops
*self
,
3917 struct gdbarch
*gdbarch
,
3918 struct bp_target_info
*bp_tgt
)
3922 retval
= debug_target
.to_remove_hw_breakpoint (&debug_target
,
3925 fprintf_unfiltered (gdb_stdlog
,
3926 "target_remove_hw_breakpoint (%s, xxx) = %ld\n",
3927 core_addr_to_string (bp_tgt
->placed_address
),
3928 (unsigned long) retval
);
3933 debug_to_insert_watchpoint (struct target_ops
*self
,
3934 CORE_ADDR addr
, int len
, int type
,
3935 struct expression
*cond
)
3939 retval
= debug_target
.to_insert_watchpoint (&debug_target
,
3940 addr
, len
, type
, cond
);
3942 fprintf_unfiltered (gdb_stdlog
,
3943 "target_insert_watchpoint (%s, %d, %d, %s) = %ld\n",
3944 core_addr_to_string (addr
), len
, type
,
3945 host_address_to_string (cond
), (unsigned long) retval
);
3950 debug_to_remove_watchpoint (struct target_ops
*self
,
3951 CORE_ADDR addr
, int len
, int type
,
3952 struct expression
*cond
)
3956 retval
= debug_target
.to_remove_watchpoint (&debug_target
,
3957 addr
, len
, type
, cond
);
3959 fprintf_unfiltered (gdb_stdlog
,
3960 "target_remove_watchpoint (%s, %d, %d, %s) = %ld\n",
3961 core_addr_to_string (addr
), len
, type
,
3962 host_address_to_string (cond
), (unsigned long) retval
);
3967 debug_to_terminal_init (struct target_ops
*self
)
3969 debug_target
.to_terminal_init (&debug_target
);
3971 fprintf_unfiltered (gdb_stdlog
, "target_terminal_init ()\n");
3975 debug_to_terminal_inferior (struct target_ops
*self
)
3977 debug_target
.to_terminal_inferior (&debug_target
);
3979 fprintf_unfiltered (gdb_stdlog
, "target_terminal_inferior ()\n");
3983 debug_to_terminal_ours_for_output (struct target_ops
*self
)
3985 debug_target
.to_terminal_ours_for_output (&debug_target
);
3987 fprintf_unfiltered (gdb_stdlog
, "target_terminal_ours_for_output ()\n");
3991 debug_to_terminal_ours (struct target_ops
*self
)
3993 debug_target
.to_terminal_ours (&debug_target
);
3995 fprintf_unfiltered (gdb_stdlog
, "target_terminal_ours ()\n");
3999 debug_to_terminal_save_ours (struct target_ops
*self
)
4001 debug_target
.to_terminal_save_ours (&debug_target
);
4003 fprintf_unfiltered (gdb_stdlog
, "target_terminal_save_ours ()\n");
4007 debug_to_terminal_info (struct target_ops
*self
,
4008 const char *arg
, int from_tty
)
4010 debug_target
.to_terminal_info (&debug_target
, arg
, from_tty
);
4012 fprintf_unfiltered (gdb_stdlog
, "target_terminal_info (%s, %d)\n", arg
,
4017 debug_to_load (struct target_ops
*self
, char *args
, int from_tty
)
4019 debug_target
.to_load (&debug_target
, args
, from_tty
);
4021 fprintf_unfiltered (gdb_stdlog
, "target_load (%s, %d)\n", args
, from_tty
);
4025 debug_to_post_startup_inferior (struct target_ops
*self
, ptid_t ptid
)
4027 debug_target
.to_post_startup_inferior (&debug_target
, ptid
);
4029 fprintf_unfiltered (gdb_stdlog
, "target_post_startup_inferior (%d)\n",
4030 ptid_get_pid (ptid
));
4034 debug_to_insert_fork_catchpoint (struct target_ops
*self
, int pid
)
4038 retval
= debug_target
.to_insert_fork_catchpoint (&debug_target
, pid
);
4040 fprintf_unfiltered (gdb_stdlog
, "target_insert_fork_catchpoint (%d) = %d\n",
4047 debug_to_remove_fork_catchpoint (struct target_ops
*self
, int pid
)
4051 retval
= debug_target
.to_remove_fork_catchpoint (&debug_target
, pid
);
4053 fprintf_unfiltered (gdb_stdlog
, "target_remove_fork_catchpoint (%d) = %d\n",
4060 debug_to_insert_vfork_catchpoint (struct target_ops
*self
, int pid
)
4064 retval
= debug_target
.to_insert_vfork_catchpoint (&debug_target
, pid
);
4066 fprintf_unfiltered (gdb_stdlog
, "target_insert_vfork_catchpoint (%d) = %d\n",
4073 debug_to_remove_vfork_catchpoint (struct target_ops
*self
, int pid
)
4077 retval
= debug_target
.to_remove_vfork_catchpoint (&debug_target
, pid
);
4079 fprintf_unfiltered (gdb_stdlog
, "target_remove_vfork_catchpoint (%d) = %d\n",
4086 debug_to_insert_exec_catchpoint (struct target_ops
*self
, int pid
)
4090 retval
= debug_target
.to_insert_exec_catchpoint (&debug_target
, pid
);
4092 fprintf_unfiltered (gdb_stdlog
, "target_insert_exec_catchpoint (%d) = %d\n",
4099 debug_to_remove_exec_catchpoint (struct target_ops
*self
, int pid
)
4103 retval
= debug_target
.to_remove_exec_catchpoint (&debug_target
, pid
);
4105 fprintf_unfiltered (gdb_stdlog
, "target_remove_exec_catchpoint (%d) = %d\n",
4112 debug_to_has_exited (struct target_ops
*self
,
4113 int pid
, int wait_status
, int *exit_status
)
4117 has_exited
= debug_target
.to_has_exited (&debug_target
,
4118 pid
, wait_status
, exit_status
);
4120 fprintf_unfiltered (gdb_stdlog
, "target_has_exited (%d, %d, %d) = %d\n",
4121 pid
, wait_status
, *exit_status
, has_exited
);
4127 debug_to_can_run (struct target_ops
*self
)
4131 retval
= debug_target
.to_can_run (&debug_target
);
4133 fprintf_unfiltered (gdb_stdlog
, "target_can_run () = %d\n", retval
);
4138 static struct gdbarch
*
4139 debug_to_thread_architecture (struct target_ops
*ops
, ptid_t ptid
)
4141 struct gdbarch
*retval
;
4143 retval
= debug_target
.to_thread_architecture (ops
, ptid
);
4145 fprintf_unfiltered (gdb_stdlog
,
4146 "target_thread_architecture (%s) = %s [%s]\n",
4147 target_pid_to_str (ptid
),
4148 host_address_to_string (retval
),
4149 gdbarch_bfd_arch_info (retval
)->printable_name
);
4154 debug_to_stop (struct target_ops
*self
, ptid_t ptid
)
4156 debug_target
.to_stop (&debug_target
, ptid
);
4158 fprintf_unfiltered (gdb_stdlog
, "target_stop (%s)\n",
4159 target_pid_to_str (ptid
));
4163 debug_to_rcmd (struct target_ops
*self
, char *command
,
4164 struct ui_file
*outbuf
)
4166 debug_target
.to_rcmd (&debug_target
, command
, outbuf
);
4167 fprintf_unfiltered (gdb_stdlog
, "target_rcmd (%s, ...)\n", command
);
4171 debug_to_pid_to_exec_file (struct target_ops
*self
, int pid
)
4175 exec_file
= debug_target
.to_pid_to_exec_file (&debug_target
, pid
);
4177 fprintf_unfiltered (gdb_stdlog
, "target_pid_to_exec_file (%d) = %s\n",
4184 setup_target_debug (void)
4186 memcpy (&debug_target
, ¤t_target
, sizeof debug_target
);
4188 current_target
.to_open
= debug_to_open
;
4189 current_target
.to_post_attach
= debug_to_post_attach
;
4190 current_target
.to_prepare_to_store
= debug_to_prepare_to_store
;
4191 current_target
.to_files_info
= debug_to_files_info
;
4192 current_target
.to_insert_breakpoint
= debug_to_insert_breakpoint
;
4193 current_target
.to_remove_breakpoint
= debug_to_remove_breakpoint
;
4194 current_target
.to_can_use_hw_breakpoint
= debug_to_can_use_hw_breakpoint
;
4195 current_target
.to_insert_hw_breakpoint
= debug_to_insert_hw_breakpoint
;
4196 current_target
.to_remove_hw_breakpoint
= debug_to_remove_hw_breakpoint
;
4197 current_target
.to_insert_watchpoint
= debug_to_insert_watchpoint
;
4198 current_target
.to_remove_watchpoint
= debug_to_remove_watchpoint
;
4199 current_target
.to_stopped_by_watchpoint
= debug_to_stopped_by_watchpoint
;
4200 current_target
.to_stopped_data_address
= debug_to_stopped_data_address
;
4201 current_target
.to_watchpoint_addr_within_range
4202 = debug_to_watchpoint_addr_within_range
;
4203 current_target
.to_region_ok_for_hw_watchpoint
4204 = debug_to_region_ok_for_hw_watchpoint
;
4205 current_target
.to_can_accel_watchpoint_condition
4206 = debug_to_can_accel_watchpoint_condition
;
4207 current_target
.to_terminal_init
= debug_to_terminal_init
;
4208 current_target
.to_terminal_inferior
= debug_to_terminal_inferior
;
4209 current_target
.to_terminal_ours_for_output
4210 = debug_to_terminal_ours_for_output
;
4211 current_target
.to_terminal_ours
= debug_to_terminal_ours
;
4212 current_target
.to_terminal_save_ours
= debug_to_terminal_save_ours
;
4213 current_target
.to_terminal_info
= debug_to_terminal_info
;
4214 current_target
.to_load
= debug_to_load
;
4215 current_target
.to_post_startup_inferior
= debug_to_post_startup_inferior
;
4216 current_target
.to_insert_fork_catchpoint
= debug_to_insert_fork_catchpoint
;
4217 current_target
.to_remove_fork_catchpoint
= debug_to_remove_fork_catchpoint
;
4218 current_target
.to_insert_vfork_catchpoint
= debug_to_insert_vfork_catchpoint
;
4219 current_target
.to_remove_vfork_catchpoint
= debug_to_remove_vfork_catchpoint
;
4220 current_target
.to_insert_exec_catchpoint
= debug_to_insert_exec_catchpoint
;
4221 current_target
.to_remove_exec_catchpoint
= debug_to_remove_exec_catchpoint
;
4222 current_target
.to_has_exited
= debug_to_has_exited
;
4223 current_target
.to_can_run
= debug_to_can_run
;
4224 current_target
.to_stop
= debug_to_stop
;
4225 current_target
.to_rcmd
= debug_to_rcmd
;
4226 current_target
.to_pid_to_exec_file
= debug_to_pid_to_exec_file
;
4227 current_target
.to_thread_architecture
= debug_to_thread_architecture
;
4231 static char targ_desc
[] =
4232 "Names of targets and files being debugged.\nShows the entire \
4233 stack of targets currently in use (including the exec-file,\n\
4234 core-file, and process, if any), as well as the symbol file name.";
4237 default_rcmd (struct target_ops
*self
, char *command
, struct ui_file
*output
)
4239 error (_("\"monitor\" command not supported by this target."));
4243 do_monitor_command (char *cmd
,
4246 target_rcmd (cmd
, gdb_stdtarg
);
4249 /* Print the name of each layers of our target stack. */
4252 maintenance_print_target_stack (char *cmd
, int from_tty
)
4254 struct target_ops
*t
;
4256 printf_filtered (_("The current target stack is:\n"));
4258 for (t
= target_stack
; t
!= NULL
; t
= t
->beneath
)
4260 printf_filtered (" - %s (%s)\n", t
->to_shortname
, t
->to_longname
);
4264 /* Controls if async mode is permitted. */
4265 int target_async_permitted
= 0;
4267 /* The set command writes to this variable. If the inferior is
4268 executing, target_async_permitted is *not* updated. */
4269 static int target_async_permitted_1
= 0;
4272 set_target_async_command (char *args
, int from_tty
,
4273 struct cmd_list_element
*c
)
4275 if (have_live_inferiors ())
4277 target_async_permitted_1
= target_async_permitted
;
4278 error (_("Cannot change this setting while the inferior is running."));
4281 target_async_permitted
= target_async_permitted_1
;
4285 show_target_async_command (struct ui_file
*file
, int from_tty
,
4286 struct cmd_list_element
*c
,
4289 fprintf_filtered (file
,
4290 _("Controlling the inferior in "
4291 "asynchronous mode is %s.\n"), value
);
4294 /* Temporary copies of permission settings. */
4296 static int may_write_registers_1
= 1;
4297 static int may_write_memory_1
= 1;
4298 static int may_insert_breakpoints_1
= 1;
4299 static int may_insert_tracepoints_1
= 1;
4300 static int may_insert_fast_tracepoints_1
= 1;
4301 static int may_stop_1
= 1;
4303 /* Make the user-set values match the real values again. */
4306 update_target_permissions (void)
4308 may_write_registers_1
= may_write_registers
;
4309 may_write_memory_1
= may_write_memory
;
4310 may_insert_breakpoints_1
= may_insert_breakpoints
;
4311 may_insert_tracepoints_1
= may_insert_tracepoints
;
4312 may_insert_fast_tracepoints_1
= may_insert_fast_tracepoints
;
4313 may_stop_1
= may_stop
;
4316 /* The one function handles (most of) the permission flags in the same
4320 set_target_permissions (char *args
, int from_tty
,
4321 struct cmd_list_element
*c
)
4323 if (target_has_execution
)
4325 update_target_permissions ();
4326 error (_("Cannot change this setting while the inferior is running."));
4329 /* Make the real values match the user-changed values. */
4330 may_write_registers
= may_write_registers_1
;
4331 may_insert_breakpoints
= may_insert_breakpoints_1
;
4332 may_insert_tracepoints
= may_insert_tracepoints_1
;
4333 may_insert_fast_tracepoints
= may_insert_fast_tracepoints_1
;
4334 may_stop
= may_stop_1
;
4335 update_observer_mode ();
4338 /* Set memory write permission independently of observer mode. */
4341 set_write_memory_permission (char *args
, int from_tty
,
4342 struct cmd_list_element
*c
)
4344 /* Make the real values match the user-changed values. */
4345 may_write_memory
= may_write_memory_1
;
4346 update_observer_mode ();
4351 initialize_targets (void)
4353 init_dummy_target ();
4354 push_target (&dummy_target
);
4356 add_info ("target", target_info
, targ_desc
);
4357 add_info ("files", target_info
, targ_desc
);
4359 add_setshow_zuinteger_cmd ("target", class_maintenance
, &targetdebug
, _("\
4360 Set target debugging."), _("\
4361 Show target debugging."), _("\
4362 When non-zero, target debugging is enabled. Higher numbers are more\n\
4363 verbose. Changes do not take effect until the next \"run\" or \"target\"\n\
4367 &setdebuglist
, &showdebuglist
);
4369 add_setshow_boolean_cmd ("trust-readonly-sections", class_support
,
4370 &trust_readonly
, _("\
4371 Set mode for reading from readonly sections."), _("\
4372 Show mode for reading from readonly sections."), _("\
4373 When this mode is on, memory reads from readonly sections (such as .text)\n\
4374 will be read from the object file instead of from the target. This will\n\
4375 result in significant performance improvement for remote targets."),
4377 show_trust_readonly
,
4378 &setlist
, &showlist
);
4380 add_com ("monitor", class_obscure
, do_monitor_command
,
4381 _("Send a command to the remote monitor (remote targets only)."));
4383 add_cmd ("target-stack", class_maintenance
, maintenance_print_target_stack
,
4384 _("Print the name of each layer of the internal target stack."),
4385 &maintenanceprintlist
);
4387 add_setshow_boolean_cmd ("target-async", no_class
,
4388 &target_async_permitted_1
, _("\
4389 Set whether gdb controls the inferior in asynchronous mode."), _("\
4390 Show whether gdb controls the inferior in asynchronous mode."), _("\
4391 Tells gdb whether to control the inferior in asynchronous mode."),
4392 set_target_async_command
,
4393 show_target_async_command
,
4397 add_setshow_boolean_cmd ("may-write-registers", class_support
,
4398 &may_write_registers_1
, _("\
4399 Set permission to write into registers."), _("\
4400 Show permission to write into registers."), _("\
4401 When this permission is on, GDB may write into the target's registers.\n\
4402 Otherwise, any sort of write attempt will result in an error."),
4403 set_target_permissions
, NULL
,
4404 &setlist
, &showlist
);
4406 add_setshow_boolean_cmd ("may-write-memory", class_support
,
4407 &may_write_memory_1
, _("\
4408 Set permission to write into target memory."), _("\
4409 Show permission to write into target memory."), _("\
4410 When this permission is on, GDB may write into the target's memory.\n\
4411 Otherwise, any sort of write attempt will result in an error."),
4412 set_write_memory_permission
, NULL
,
4413 &setlist
, &showlist
);
4415 add_setshow_boolean_cmd ("may-insert-breakpoints", class_support
,
4416 &may_insert_breakpoints_1
, _("\
4417 Set permission to insert breakpoints in the target."), _("\
4418 Show permission to insert breakpoints in the target."), _("\
4419 When this permission is on, GDB may insert breakpoints in the program.\n\
4420 Otherwise, any sort of insertion attempt will result in an error."),
4421 set_target_permissions
, NULL
,
4422 &setlist
, &showlist
);
4424 add_setshow_boolean_cmd ("may-insert-tracepoints", class_support
,
4425 &may_insert_tracepoints_1
, _("\
4426 Set permission to insert tracepoints in the target."), _("\
4427 Show permission to insert tracepoints in the target."), _("\
4428 When this permission is on, GDB may insert tracepoints in the program.\n\
4429 Otherwise, any sort of insertion attempt will result in an error."),
4430 set_target_permissions
, NULL
,
4431 &setlist
, &showlist
);
4433 add_setshow_boolean_cmd ("may-insert-fast-tracepoints", class_support
,
4434 &may_insert_fast_tracepoints_1
, _("\
4435 Set permission to insert fast tracepoints in the target."), _("\
4436 Show permission to insert fast tracepoints in the target."), _("\
4437 When this permission is on, GDB may insert fast tracepoints.\n\
4438 Otherwise, any sort of insertion attempt will result in an error."),
4439 set_target_permissions
, NULL
,
4440 &setlist
, &showlist
);
4442 add_setshow_boolean_cmd ("may-interrupt", class_support
,
4444 Set permission to interrupt or signal the target."), _("\
4445 Show permission to interrupt or signal the target."), _("\
4446 When this permission is on, GDB may interrupt/stop the target's execution.\n\
4447 Otherwise, any attempt to interrupt or stop will be ignored."),
4448 set_target_permissions
, NULL
,
4449 &setlist
, &showlist
);