* linespec.c (decode_dollar): Avoid "may be used uninitialized" warning.
[deliverable/binutils-gdb.git] / gdb / target.c
index 35a29b7480a666a244fd033c22ef96cf3c8605af..6358b00f487e80f71ba7a9c1f8928d9516c8700a 100644 (file)
@@ -1,7 +1,7 @@
 /* Select target systems and architectures at runtime for GDB.
 
    Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
-   2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
+   2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
    Free Software Foundation, Inc.
 
    Contributed by Cygnus Support.
@@ -54,8 +54,6 @@ static int default_watchpoint_addr_within_range (struct target_ops *,
 
 static int default_region_ok_for_hw_watchpoint (CORE_ADDR, int);
 
-static int nosymbol (char *, CORE_ADDR *);
-
 static void tcomplain (void) ATTRIBUTE_NORETURN;
 
 static int nomemory (CORE_ADDR, char *, int, int, struct target_ops *);
@@ -117,9 +115,11 @@ static int debug_to_insert_hw_breakpoint (struct gdbarch *,
 static int debug_to_remove_hw_breakpoint (struct gdbarch *,
                                          struct bp_target_info *);
 
-static int debug_to_insert_watchpoint (CORE_ADDR, int, int);
+static int debug_to_insert_watchpoint (CORE_ADDR, int, int,
+                                      struct expression *);
 
-static int debug_to_remove_watchpoint (CORE_ADDR, int, int);
+static int debug_to_remove_watchpoint (CORE_ADDR, int, int,
+                                      struct expression *);
 
 static int debug_to_stopped_by_watchpoint (void);
 
@@ -130,6 +130,9 @@ static int debug_to_watchpoint_addr_within_range (struct target_ops *,
 
 static int debug_to_region_ok_for_hw_watchpoint (CORE_ADDR, int);
 
+static int debug_to_can_accel_watchpoint_condition (CORE_ADDR, int, int,
+                                                   struct expression *);
+
 static void debug_to_terminal_init (void);
 
 static void debug_to_terminal_inferior (void);
@@ -144,20 +147,10 @@ static void debug_to_terminal_info (char *, int);
 
 static void debug_to_load (char *, int);
 
-static int debug_to_lookup_symbol (char *, CORE_ADDR *);
-
 static int debug_to_can_run (void);
 
-static void debug_to_notice_signals (ptid_t);
-
 static void debug_to_stop (ptid_t);
 
-/* NOTE: cagney/2004-09-29: Many targets reference this variable in
-   wierd and mysterious ways.  Putting the variable here lets those
-   wierd and mysterious ways keep building while they are being
-   converted to the inferior inheritance structure.  */
-struct target_ops deprecated_child_ops;
-
 /* Pointer to array of target architecture structures; the size of the
    array; the current index into the array; the allocated size of the
    array.  */
@@ -195,6 +188,22 @@ static int trust_readonly = 0;
 
 static int show_memory_breakpoints = 0;
 
+/* These globals control whether GDB attempts to perform these
+   operations; they are useful for targets that need to prevent
+   inadvertant disruption, such as in non-stop mode.  */
+
+int may_write_registers = 1;
+
+int may_write_memory = 1;
+
+int may_insert_breakpoints = 1;
+
+int may_insert_tracepoints = 1;
+
+int may_insert_fast_tracepoints = 1;
+
+int may_stop = 1;
+
 /* Non-zero if we want to see trace of target level stuff.  */
 
 static int targetdebug = 0;
@@ -299,11 +308,11 @@ default_child_has_registers (struct target_ops *ops)
 }
 
 int
-default_child_has_execution (struct target_ops *ops)
+default_child_has_execution (struct target_ops *ops, ptid_t the_ptid)
 {
   /* If there's no thread selected, then we can't make it run through
      hoops.  */
-  if (ptid_equal (inferior_ptid, null_ptid))
+  if (ptid_equal (the_ptid, null_ptid))
     return 0;
 
   return 1;
@@ -359,17 +368,23 @@ target_has_registers_1 (void)
 }
 
 int
-target_has_execution_1 (void)
+target_has_execution_1 (ptid_t the_ptid)
 {
   struct target_ops *t;
 
   for (t = current_target.beneath; t != NULL; t = t->beneath)
-    if (t->to_has_execution (t))
+    if (t->to_has_execution (t, the_ptid))
       return 1;
 
   return 0;
 }
 
+int
+target_has_execution_current (void)
+{
+  return target_has_execution_1 (inferior_ptid);
+}
+
 /* Add a possible target architecture to the list.  */
 
 void
@@ -392,7 +407,7 @@ add_target (struct target_ops *t)
     t->to_has_registers = (int (*) (struct target_ops *)) return_zero;
 
   if (t->to_has_execution == NULL)
-    t->to_has_execution = (int (*) (struct target_ops *)) return_zero;
+    t->to_has_execution = (int (*) (struct target_ops *, ptid_t)) return_zero;
 
   if (!target_structs)
     {
@@ -472,14 +487,14 @@ target_create_inferior (char *exec_file, char *args,
     }
 
   internal_error (__FILE__, __LINE__,
-                 "could not find a target to create inferior");
+                 _("could not find a target to create inferior"));
 }
 
 void
 target_terminal_inferior (void)
 {
   /* A background resume (``run&'') should leave GDB in control of the
-     terminal. Use target_can_async_p, not target_is_async_p, since at
+     terminal.  Use target_can_async_p, not target_is_async_p, since at
      this point the target is not async yet.  However, if sync_execution
      is not set, we know it will become async prior to resume.  */
   if (target_can_async_p () && !sync_execution)
@@ -494,8 +509,8 @@ static int
 nomemory (CORE_ADDR memaddr, char *myaddr, int len, int write,
          struct target_ops *t)
 {
-  errno = EIO;                 /* Can't read/write this location */
-  return 0;                    /* No bytes handled */
+  errno = EIO;                 /* Can't read/write this location */
+  return 0;                    /* No bytes handled */
 }
 
 static void
@@ -511,12 +526,6 @@ noprocess (void)
   error (_("You can't do that without a process to debug."));
 }
 
-static int
-nosymbol (char *name, CORE_ADDR *addrp)
-{
-  return 1;                    /* Symbol does not exist in target env */
-}
-
 static void
 default_terminal_info (char *args, int from_tty)
 {
@@ -535,6 +544,18 @@ default_get_ada_task_ptid (long lwp, long tid)
   return ptid_build (ptid_get_pid (inferior_ptid), lwp, tid);
 }
 
+static enum exec_direction_kind
+default_execution_direction (void)
+{
+  if (!target_can_execute_reverse)
+    return EXEC_FORWARD;
+  else if (!target_can_async_p ())
+    return EXEC_FORWARD;
+  else
+    gdb_assert_not_reached ("\
+to_execution_direction must be implemented for reverse async");
+}
+
 /* Go through the target stack from top to bottom, copying over zero
    entries in current_target, then filling in still empty entries.  In
    effect, we are doing class inheritance through the pushed target
@@ -583,14 +604,19 @@ update_current_target (void)
       INHERIT (to_can_use_hw_breakpoint, t);
       INHERIT (to_insert_hw_breakpoint, t);
       INHERIT (to_remove_hw_breakpoint, t);
+      /* Do not inherit to_ranged_break_num_registers.  */
       INHERIT (to_insert_watchpoint, t);
       INHERIT (to_remove_watchpoint, t);
+      /* Do not inherit to_insert_mask_watchpoint.  */
+      /* Do not inherit to_remove_mask_watchpoint.  */
       INHERIT (to_stopped_data_address, t);
       INHERIT (to_have_steppable_watchpoint, t);
       INHERIT (to_have_continuable_watchpoint, t);
       INHERIT (to_stopped_by_watchpoint, t);
       INHERIT (to_watchpoint_addr_within_range, t);
       INHERIT (to_region_ok_for_hw_watchpoint, t);
+      INHERIT (to_can_accel_watchpoint_condition, t);
+      /* Do not inherit to_masked_watch_num_registers.  */
       INHERIT (to_terminal_init, t);
       INHERIT (to_terminal_inferior, t);
       INHERIT (to_terminal_ours_for_output, t);
@@ -599,10 +625,8 @@ update_current_target (void)
       INHERIT (to_terminal_info, t);
       /* Do not inherit to_kill.  */
       INHERIT (to_load, t);
-      INHERIT (to_lookup_symbol, t);
       /* Do no inherit to_create_inferior.  */
       INHERIT (to_post_startup_inferior, t);
-      INHERIT (to_acknowledge_created_inferior, t);
       INHERIT (to_insert_fork_catchpoint, t);
       INHERIT (to_remove_fork_catchpoint, t);
       INHERIT (to_insert_vfork_catchpoint, t);
@@ -612,46 +636,53 @@ update_current_target (void)
       INHERIT (to_remove_exec_catchpoint, t);
       INHERIT (to_set_syscall_catchpoint, t);
       INHERIT (to_has_exited, t);
-      /* Do not inherit to_mourn_inferiour.  */
+      /* Do not inherit to_mourn_inferior.  */
       INHERIT (to_can_run, t);
-      INHERIT (to_notice_signals, t);
+      /* Do not inherit to_pass_signals.  */
       /* Do not inherit to_thread_alive.  */
       /* Do not inherit to_find_new_threads.  */
       /* Do not inherit to_pid_to_str.  */
       INHERIT (to_extra_thread_info, t);
+      INHERIT (to_thread_name, t);
       INHERIT (to_stop, t);
       /* Do not inherit to_xfer_partial.  */
       INHERIT (to_rcmd, t);
       INHERIT (to_pid_to_exec_file, t);
       INHERIT (to_log_command, t);
       INHERIT (to_stratum, t);
-      /* Do not inherit to_has_all_memory */
-      /* Do not inherit to_has_memory */
-      /* Do not inherit to_has_stack */
-      /* Do not inherit to_has_registers */
-      /* Do not inherit to_has_execution */
+      /* Do not inherit to_has_all_memory */
+      /* Do not inherit to_has_memory */
+      /* Do not inherit to_has_stack */
+      /* Do not inherit to_has_registers */
+      /* Do not inherit to_has_execution */
       INHERIT (to_has_thread_control, t);
       INHERIT (to_can_async_p, t);
       INHERIT (to_is_async_p, t);
       INHERIT (to_async, t);
-      INHERIT (to_async_mask, t);
       INHERIT (to_find_memory_regions, t);
       INHERIT (to_make_corefile_notes, t);
       INHERIT (to_get_bookmark, t);
       INHERIT (to_goto_bookmark, t);
       /* Do not inherit to_get_thread_local_address.  */
       INHERIT (to_can_execute_reverse, t);
+      INHERIT (to_execution_direction, t);
       INHERIT (to_thread_architecture, t);
       /* Do not inherit to_read_description.  */
       INHERIT (to_get_ada_task_ptid, t);
       /* Do not inherit to_search_memory.  */
       INHERIT (to_supports_multi_process, t);
+      INHERIT (to_supports_enable_disable_tracepoint, t);
+      INHERIT (to_supports_string_tracing, t);
       INHERIT (to_trace_init, t);
       INHERIT (to_download_tracepoint, t);
+      INHERIT (to_can_download_tracepoint, t);
       INHERIT (to_download_trace_state_variable, t);
+      INHERIT (to_enable_tracepoint, t);
+      INHERIT (to_disable_tracepoint, t);
       INHERIT (to_trace_set_readonly_regions, t);
       INHERIT (to_trace_start, t);
       INHERIT (to_get_trace_status, t);
+      INHERIT (to_get_tracepoint_status, t);
       INHERIT (to_trace_stop, t);
       INHERIT (to_trace_find, t);
       INHERIT (to_get_trace_state_variable_value, t);
@@ -659,9 +690,15 @@ update_current_target (void)
       INHERIT (to_upload_tracepoints, t);
       INHERIT (to_upload_trace_state_variables, t);
       INHERIT (to_get_raw_trace_data, t);
+      INHERIT (to_get_min_fast_tracepoint_insn_len, t);
       INHERIT (to_set_disconnected_tracing, t);
       INHERIT (to_set_circular_trace_buffer, t);
+      INHERIT (to_set_trace_notes, t);
       INHERIT (to_get_tib_address, t);
+      INHERIT (to_set_permissions, t);
+      INHERIT (to_static_tracepoint_marker_at, t);
+      INHERIT (to_static_tracepoint_markers_by_strid, t);
+      INHERIT (to_traceframe_info, t);
       INHERIT (to_magic, t);
       /* Do not inherit to_memory_map.  */
       /* Do not inherit to_flash_erase.  */
@@ -690,7 +727,8 @@ update_current_target (void)
            (void (*) (struct regcache *))
            noprocess);
   de_fault (deprecated_xfer_memory,
-           (int (*) (CORE_ADDR, gdb_byte *, int, int, struct mem_attrib *, struct target_ops *))
+           (int (*) (CORE_ADDR, gdb_byte *, int, int,
+                     struct mem_attrib *, struct target_ops *))
            nomemory);
   de_fault (to_files_info,
            (void (*) (struct target_ops *))
@@ -709,10 +747,10 @@ update_current_target (void)
            (int (*) (struct gdbarch *, struct bp_target_info *))
            return_minus_one);
   de_fault (to_insert_watchpoint,
-           (int (*) (CORE_ADDR, int, int))
+           (int (*) (CORE_ADDR, int, int, struct expression *))
            return_minus_one);
   de_fault (to_remove_watchpoint,
-           (int (*) (CORE_ADDR, int, int))
+           (int (*) (CORE_ADDR, int, int, struct expression *))
            return_minus_one);
   de_fault (to_stopped_by_watchpoint,
            (int (*) (void))
@@ -724,6 +762,9 @@ update_current_target (void)
            default_watchpoint_addr_within_range);
   de_fault (to_region_ok_for_hw_watchpoint,
            default_region_ok_for_hw_watchpoint);
+  de_fault (to_can_accel_watchpoint_condition,
+            (int (*) (CORE_ADDR, int, int, struct expression *))
+            return_zero);
   de_fault (to_terminal_init,
            (void (*) (void))
            target_ignore);
@@ -744,47 +785,41 @@ update_current_target (void)
   de_fault (to_load,
            (void (*) (char *, int))
            tcomplain);
-  de_fault (to_lookup_symbol,
-           (int (*) (char *, CORE_ADDR *))
-           nosymbol);
   de_fault (to_post_startup_inferior,
            (void (*) (ptid_t))
            target_ignore);
-  de_fault (to_acknowledge_created_inferior,
-           (void (*) (int))
-           target_ignore);
   de_fault (to_insert_fork_catchpoint,
-           (void (*) (int))
-           tcomplain);
+           (int (*) (int))
+           return_one);
   de_fault (to_remove_fork_catchpoint,
            (int (*) (int))
-           tcomplain);
+           return_one);
   de_fault (to_insert_vfork_catchpoint,
-           (void (*) (int))
-           tcomplain);
+           (int (*) (int))
+           return_one);
   de_fault (to_remove_vfork_catchpoint,
            (int (*) (int))
-           tcomplain);
+           return_one);
   de_fault (to_insert_exec_catchpoint,
-           (void (*) (int))
-           tcomplain);
+           (int (*) (int))
+           return_one);
   de_fault (to_remove_exec_catchpoint,
            (int (*) (int))
-           tcomplain);
+           return_one);
   de_fault (to_set_syscall_catchpoint,
            (int (*) (int, int, int, int, int *))
-           tcomplain);
+           return_one);
   de_fault (to_has_exited,
            (int (*) (int, int, int *))
            return_zero);
   de_fault (to_can_run,
            return_zero);
-  de_fault (to_notice_signals,
-           (void (*) (ptid_t))
-           target_ignore);
   de_fault (to_extra_thread_info,
            (char *(*) (struct thread_info *))
            return_zero);
+  de_fault (to_thread_name,
+           (char *(*) (struct thread_info *))
+           return_zero);
   de_fault (to_stop,
            (void (*) (ptid_t))
            target_ignore);
@@ -798,9 +833,6 @@ update_current_target (void)
   de_fault (to_async,
            (void (*) (void (*) (enum inferior_event_type, void*), void*))
            tcomplain);
-  de_fault (to_async_mask,
-           (int (*) (int))
-           return_one);
   de_fault (to_thread_architecture,
            default_thread_architecture);
   current_target.to_read_description = NULL;
@@ -810,15 +842,30 @@ update_current_target (void)
   de_fault (to_supports_multi_process,
            (int (*) (void))
            return_zero);
+  de_fault (to_supports_enable_disable_tracepoint,
+           (int (*) (void))
+           return_zero);
+  de_fault (to_supports_string_tracing,
+           (int (*) (void))
+           return_zero);
   de_fault (to_trace_init,
            (void (*) (void))
            tcomplain);
   de_fault (to_download_tracepoint,
-           (void (*) (struct breakpoint *))
+           (void (*) (struct bp_location *))
            tcomplain);
+  de_fault (to_can_download_tracepoint,
+           (int (*) (void))
+           return_zero);
   de_fault (to_download_trace_state_variable,
            (void (*) (struct trace_state_variable *))
            tcomplain);
+  de_fault (to_enable_tracepoint,
+           (void (*) (struct bp_location *))
+           tcomplain);
+  de_fault (to_disable_tracepoint,
+           (void (*) (struct bp_location *))
+           tcomplain);
   de_fault (to_trace_set_readonly_regions,
            (void (*) (void))
            tcomplain);
@@ -828,6 +875,9 @@ update_current_target (void)
   de_fault (to_get_trace_status,
            (int (*) (struct trace_status *))
            return_minus_one);
+  de_fault (to_get_tracepoint_status,
+           (void (*) (struct breakpoint *, struct uploaded_tp *))
+           tcomplain);
   de_fault (to_trace_stop,
            (void (*) (void))
            tcomplain);
@@ -849,15 +899,35 @@ update_current_target (void)
   de_fault (to_get_raw_trace_data,
            (LONGEST (*) (gdb_byte *, ULONGEST, LONGEST))
            tcomplain);
+  de_fault (to_get_min_fast_tracepoint_insn_len,
+           (int (*) (void))
+           return_minus_one);
   de_fault (to_set_disconnected_tracing,
            (void (*) (int))
            target_ignore);
   de_fault (to_set_circular_trace_buffer,
            (void (*) (int))
            target_ignore);
+  de_fault (to_set_trace_notes,
+           (int (*) (char *, char *, char *))
+           return_zero);
   de_fault (to_get_tib_address,
            (int (*) (ptid_t, CORE_ADDR *))
            tcomplain);
+  de_fault (to_set_permissions,
+           (void (*) (void))
+           target_ignore);
+  de_fault (to_static_tracepoint_marker_at,
+           (int (*) (CORE_ADDR, struct static_tracepoint_marker *))
+           return_zero);
+  de_fault (to_static_tracepoint_markers_by_strid,
+           (VEC(static_tracepoint_marker_p) * (*) (const char *))
+           tcomplain);
+  de_fault (to_traceframe_info,
+           (struct traceframe_info * (*) (void))
+           tcomplain);
+  de_fault (to_execution_direction, default_execution_direction);
+
 #undef de_fault
 
   /* Finally, position the target-stack beneath the squashed
@@ -888,7 +958,8 @@ push_target (struct target_ops *t)
       fprintf_unfiltered (gdb_stderr,
                          "Magic number of %s target struct wrong\n",
                          t->to_shortname);
-      internal_error (__FILE__, __LINE__, _("failed internal consistency check"));
+      internal_error (__FILE__, __LINE__,
+                     _("failed internal consistency check"));
     }
 
   /* Find the proper stratum to install this target in.  */
@@ -930,10 +1001,10 @@ unpush_target (struct target_ops *t)
 
   if (t->to_stratum == dummy_stratum)
     internal_error (__FILE__, __LINE__,
-                   "Attempt to unpush the dummy target");
+                   _("Attempt to unpush the dummy target"));
 
   /* Look for the specified target.  Note that we assume that a target
-     can only occur once in the target stack. */
+     can only occur once in the target stack.  */
 
   for (cur = &target_stack; (*cur) != NULL; cur = &(*cur)->beneath)
     {
@@ -942,7 +1013,7 @@ unpush_target (struct target_ops *t)
     }
 
   if ((*cur) == NULL)
-    return 0;                  /* Didn't find target_ops, quit now */
+    return 0;                  /* Didn't find target_ops, quit now */
 
   /* NOTE: cagney/2003-12-06: In '94 the close call was made
      unconditional by moving it to before the above check that the
@@ -952,7 +1023,7 @@ unpush_target (struct target_ops *t)
      targets should be closed.  */
   target_close (t, 0);
 
-  /* Unchain the target */
+  /* Unchain the target */
   tmp = (*cur);
   (*cur) = (*cur)->beneath;
   tmp->beneath = NULL;
@@ -965,7 +1036,7 @@ unpush_target (struct target_ops *t)
 void
 pop_target (void)
 {
-  target_close (target_stack, 0);      /* Let it clean up */
+  target_close (target_stack, 0);      /* Let it clean up */
   if (unpush_target (target_stack) == 1)
     return;
 
@@ -1000,6 +1071,31 @@ pop_all_targets (int quitting)
   pop_all_targets_above (dummy_stratum, quitting);
 }
 
+/* Return 1 if T is now pushed in the target stack.  Return 0 otherwise.  */
+
+int
+target_is_pushed (struct target_ops *t)
+{
+  struct target_ops **cur;
+
+  /* Check magic number.  If wrong, it probably means someone changed
+     the struct definition, but not all the places that initialize one.  */
+  if (t->to_magic != OPS_MAGIC)
+    {
+      fprintf_unfiltered (gdb_stderr,
+                         "Magic number of %s target struct wrong\n",
+                         t->to_shortname);
+      internal_error (__FILE__, __LINE__,
+                     _("failed internal consistency check"));
+    }
+
+  for (cur = &target_stack; (*cur) != NULL; cur = &(*cur)->beneath)
+    if (*cur == t)
+      return 1;
+
+  return 0;
+}
+
 /* Using the objfile specified in OBJFILE, find the address for the
    current thread's thread-local storage with offset OFFSET.  */
 CORE_ADDR
@@ -1034,7 +1130,8 @@ target_translate_tls_address (struct objfile *objfile, CORE_ADDR offset)
            throw_error (TLS_LOAD_MODULE_NOT_FOUND_ERROR,
                         _("TLS load module not found"));
 
-         addr = target->to_get_thread_local_address (target, ptid, lm_addr, offset);
+         addr = target->to_get_thread_local_address (target, ptid,
+                                                     lm_addr, offset);
        }
       /* If an error occurred, print TLS related messages here.  Otherwise,
          throw the error to some higher catcher.  */
@@ -1045,7 +1142,8 @@ target_translate_tls_address (struct objfile *objfile, CORE_ADDR offset)
          switch (ex.error)
            {
            case TLS_NO_LIBRARY_SUPPORT_ERROR:
-             error (_("Cannot find thread-local variables in this thread library."));
+             error (_("Cannot find thread-local variables "
+                      "in this thread library."));
              break;
            case TLS_LOAD_MODULE_NOT_FOUND_ERROR:
              if (objfile_is_library)
@@ -1133,7 +1231,7 @@ target_read_string (CORE_ADDR memaddr, char **string, int len, int *errnop)
       if (errcode != 0)
        {
          /* The transfer request might have crossed the boundary to an
-            unallocated region of memory. Retry the transfer, requesting
+            unallocated region of memory.  Retry the transfer, requesting
             a single byte.  */
          tlen = 1;
          offset = 0;
@@ -1207,6 +1305,85 @@ target_section_by_addr (struct target_ops *target, CORE_ADDR addr)
   return NULL;
 }
 
+/* Read memory from the live target, even if currently inspecting a
+   traceframe.  The return is the same as that of target_read.  */
+
+static LONGEST
+target_read_live_memory (enum target_object object,
+                        ULONGEST memaddr, gdb_byte *myaddr, LONGEST len)
+{
+  int ret;
+  struct cleanup *cleanup;
+
+  /* Switch momentarily out of tfind mode so to access live memory.
+     Note that this must not clear global state, such as the frame
+     cache, which must still remain valid for the previous traceframe.
+     We may be _building_ the frame cache at this point.  */
+  cleanup = make_cleanup_restore_traceframe_number ();
+  set_traceframe_number (-1);
+
+  ret = target_read (current_target.beneath, object, NULL,
+                    myaddr, memaddr, len);
+
+  do_cleanups (cleanup);
+  return ret;
+}
+
+/* Using the set of read-only target sections of OPS, read live
+   read-only memory.  Note that the actual reads start from the
+   top-most target again.
+
+   For interface/parameters/return description see target.h,
+   to_xfer_partial.  */
+
+static LONGEST
+memory_xfer_live_readonly_partial (struct target_ops *ops,
+                                  enum target_object object,
+                                  gdb_byte *readbuf, ULONGEST memaddr,
+                                  LONGEST len)
+{
+  struct target_section *secp;
+  struct target_section_table *table;
+
+  secp = target_section_by_addr (ops, memaddr);
+  if (secp != NULL
+      && (bfd_get_section_flags (secp->bfd, secp->the_bfd_section)
+         & SEC_READONLY))
+    {
+      struct target_section *p;
+      ULONGEST memend = memaddr + len;
+
+      table = target_get_section_table (ops);
+
+      for (p = table->sections; p < table->sections_end; p++)
+       {
+         if (memaddr >= p->addr)
+           {
+             if (memend <= p->endaddr)
+               {
+                 /* Entire transfer is within this section.  */
+                 return target_read_live_memory (object, memaddr,
+                                                 readbuf, len);
+               }
+             else if (memaddr >= p->endaddr)
+               {
+                 /* This section ends before the transfer starts.  */
+                 continue;
+               }
+             else
+               {
+                 /* This section overlaps the transfer.  Just do half.  */
+                 len = p->endaddr - memaddr;
+                 return target_read_live_memory (object, memaddr,
+                                                 readbuf, len);
+               }
+           }
+       }
+    }
+
+  return 0;
+}
+
 /* Perform a partial memory transfer.
    For docs see target.h, to_xfer_partial.  */
 
@@ -1265,6 +1442,59 @@ memory_xfer_partial (struct target_ops *ops, enum target_object object,
        }
     }
 
+  /* If reading unavailable memory in the context of traceframes, and
+     this address falls within a read-only section, fallback to
+     reading from live memory.  */
+  if (readbuf != NULL && get_traceframe_number () != -1)
+    {
+      VEC(mem_range_s) *available;
+
+      /* If we fail to get the set of available memory, then the
+        target does not support querying traceframe info, and so we
+        attempt reading from the traceframe anyway (assuming the
+        target implements the old QTro packet then).  */
+      if (traceframe_available_memory (&available, memaddr, len))
+       {
+         struct cleanup *old_chain;
+
+         old_chain = make_cleanup (VEC_cleanup(mem_range_s), &available);
+
+         if (VEC_empty (mem_range_s, available)
+             || VEC_index (mem_range_s, available, 0)->start != memaddr)
+           {
+             /* Don't read into the traceframe's available
+                memory.  */
+             if (!VEC_empty (mem_range_s, available))
+               {
+                 LONGEST oldlen = len;
+
+                 len = VEC_index (mem_range_s, available, 0)->start - memaddr;
+                 gdb_assert (len <= oldlen);
+               }
+
+             do_cleanups (old_chain);
+
+             /* This goes through the topmost target again.  */
+             res = memory_xfer_live_readonly_partial (ops, object,
+                                                      readbuf, memaddr, len);
+             if (res > 0)
+               return res;
+
+             /* No use trying further, we know some memory starting
+                at MEMADDR isn't available.  */
+             return -1;
+           }
+
+         /* Don't try to read more than how much is available, in
+            case the target implements the deprecated QTro packet to
+            cater for older GDBs (the target's knowledge of read-only
+            sections may be outdated by now).  */
+         len = VEC_index (mem_range_s, available, 0)->length;
+
+         do_cleanups (old_chain);
+       }
+    }
+
   /* Try GDB's internal data cache.  */
   region = lookup_mem_region (memaddr);
   /* region->hi == 0 means there's no upper bound.  */
@@ -1354,7 +1584,7 @@ memory_xfer_partial (struct target_ops *ops, enum target_object object,
     }
   while (ops != NULL);
 
-  if (readbuf && !show_memory_breakpoints)
+  if (res > 0 && readbuf != NULL && !show_memory_breakpoints)
     breakpoint_restore_shadows (readbuf, memaddr, reg_len);
 
   /* Make sure the cache gets updated no matter what - if we are writing
@@ -1404,6 +1634,10 @@ target_xfer_partial (struct target_ops *ops,
 
   gdb_assert (ops->to_xfer_partial != NULL);
 
+  if (writebuf && !may_write_memory)
+    error (_("Writing to memory is not allowed (addr %s, len %s)"),
+          core_addr_to_string_nz (offset), plongest (len));
+
   /* If this is a memory transfer, let the memory-specific code
      have a look at it instead.  Memory transfers are more
      complicated.  */
@@ -1428,7 +1662,8 @@ target_xfer_partial (struct target_ops *ops,
       const unsigned char *myaddr = NULL;
 
       fprintf_unfiltered (gdb_stdlog,
-                         "%s:target_xfer_partial (%d, %s, %s, %s, %s, %s) = %s",
+                         "%s:target_xfer_partial "
+                         "(%d, %s, %s, %s, %s, %s) = %s",
                          ops->to_shortname,
                          (int) object,
                          (annex ? annex : "(null)"),
@@ -1476,7 +1711,7 @@ target_xfer_partial (struct target_ops *ops,
    filling the buffer with good data.  There is no way for the caller to know
    how much good data might have been transfered anyway.  Callers that can
    deal with partial reads should call target_read (which will retry until
-   it makes no progress, and then return how much was transferred). */
+   it makes no progress, and then return how much was transferred).  */
 
 int
 target_read_memory (CORE_ADDR memaddr, gdb_byte *myaddr, int len)
@@ -1613,8 +1848,8 @@ static void
 show_trust_readonly (struct ui_file *file, int from_tty,
                     struct cmd_list_element *c, const char *value)
 {
-  fprintf_filtered (file, _("\
-Mode for reading from readonly sections is %s.\n"),
+  fprintf_filtered (file,
+                   _("Mode for reading from readonly sections is %s.\n"),
                    value);
 }
 
@@ -1727,73 +1962,213 @@ target_read (struct target_ops *ops,
   return len;
 }
 
-LONGEST
-target_read_until_error (struct target_ops *ops,
-                        enum target_object object,
-                        const char *annex, gdb_byte *buf,
-                        ULONGEST offset, LONGEST len)
+/* Assuming that the entire [begin, end) range of memory cannot be
+   read, try to read whatever subrange is possible to read.
+
+   The function returns, in RESULT, either zero or one memory block.
+   If there's a readable subrange at the beginning, it is completely
+   read and returned.  Any further readable subrange will not be read.
+   Otherwise, if there's a readable subrange at the end, it will be
+   completely read and returned.  Any readable subranges before it
+   (obviously, not starting at the beginning), will be ignored.  In
+   other cases -- either no readable subrange, or readable subrange(s)
+   that is neither at the beginning, or end, nothing is returned.
+
+   The purpose of this function is to handle a read across a boundary
+   of accessible memory in a case when memory map is not available.
+   The above restrictions are fine for this case, but will give
+   incorrect results if the memory is 'patchy'.  However, supporting
+   'patchy' memory would require trying to read every single byte,
+   and it seems unacceptable solution.  Explicit memory map is
+   recommended for this case -- and target_read_memory_robust will
+   take care of reading multiple ranges then.  */
+
+static void
+read_whatever_is_readable (struct target_ops *ops,
+                          ULONGEST begin, ULONGEST end,
+                          VEC(memory_read_result_s) **result)
+{
+  gdb_byte *buf = xmalloc (end - begin);
+  ULONGEST current_begin = begin;
+  ULONGEST current_end = end;
+  int forward;
+  memory_read_result_s r;
+
+  /* If we previously failed to read 1 byte, nothing can be done here.  */
+  if (end - begin <= 1)
+    {
+      xfree (buf);
+      return;
+    }
+
+  /* Check that either first or the last byte is readable, and give up
+     if not.  This heuristic is meant to permit reading accessible memory
+     at the boundary of accessible region.  */
+  if (target_read_partial (ops, TARGET_OBJECT_MEMORY, NULL,
+                          buf, begin, 1) == 1)
+    {
+      forward = 1;
+      ++current_begin;
+    }
+  else if (target_read_partial (ops, TARGET_OBJECT_MEMORY, NULL,
+                               buf + (end-begin) - 1, end - 1, 1) == 1)
+    {
+      forward = 0;
+      --current_end;
+    }
+  else
+    {
+      xfree (buf);
+      return;
+    }
+
+  /* Loop invariant is that the [current_begin, current_end) was previously
+     found to be not readable as a whole.
+
+     Note loop condition -- if the range has 1 byte, we can't divide the range
+     so there's no point trying further.  */
+  while (current_end - current_begin > 1)
+    {
+      ULONGEST first_half_begin, first_half_end;
+      ULONGEST second_half_begin, second_half_end;
+      LONGEST xfer;
+      ULONGEST middle = current_begin + (current_end - current_begin)/2;
+
+      if (forward)
+       {
+         first_half_begin = current_begin;
+         first_half_end = middle;
+         second_half_begin = middle;
+         second_half_end = current_end;
+       }
+      else
+       {
+         first_half_begin = middle;
+         first_half_end = current_end;
+         second_half_begin = current_begin;
+         second_half_end = middle;
+       }
+
+      xfer = target_read (ops, TARGET_OBJECT_MEMORY, NULL,
+                         buf + (first_half_begin - begin),
+                         first_half_begin,
+                         first_half_end - first_half_begin);
+
+      if (xfer == first_half_end - first_half_begin)
+       {
+         /* This half reads up fine.  So, the error must be in the
+            other half.  */
+         current_begin = second_half_begin;
+         current_end = second_half_end;
+       }
+      else
+       {
+         /* This half is not readable.  Because we've tried one byte, we
+            know some part of this half if actually redable.  Go to the next
+            iteration to divide again and try to read.
+
+            We don't handle the other half, because this function only tries
+            to read a single readable subrange.  */
+         current_begin = first_half_begin;
+         current_end = first_half_end;
+       }
+    }
+
+  if (forward)
+    {
+      /* The [begin, current_begin) range has been read.  */
+      r.begin = begin;
+      r.end = current_begin;
+      r.data = buf;
+    }
+  else
+    {
+      /* The [current_end, end) range has been read.  */
+      LONGEST rlen = end - current_end;
+
+      r.data = xmalloc (rlen);
+      memcpy (r.data, buf + current_end - begin, rlen);
+      r.begin = current_end;
+      r.end = end;
+      xfree (buf);
+    }
+  VEC_safe_push(memory_read_result_s, (*result), &r);
+}
+
+void
+free_memory_read_result_vector (void *x)
 {
-  LONGEST xfered = 0;
+  VEC(memory_read_result_s) *v = x;
+  memory_read_result_s *current;
+  int ix;
+
+  for (ix = 0; VEC_iterate (memory_read_result_s, v, ix, current); ++ix)
+    {
+      xfree (current->data);
+    }
+  VEC_free (memory_read_result_s, v);
+}
+
+VEC(memory_read_result_s) *
+read_memory_robust (struct target_ops *ops, ULONGEST offset, LONGEST len)
+{
+  VEC(memory_read_result_s) *result = 0;
 
+  LONGEST xfered = 0;
   while (xfered < len)
     {
-      LONGEST xfer = target_read_partial (ops, object, annex,
-                                         (gdb_byte *) buf + xfered,
-                                         offset + xfered, len - xfered);
+      struct mem_region *region = lookup_mem_region (offset + xfered);
+      LONGEST rlen;
 
-      /* Call an observer, notifying them of the xfer progress?  */
-      if (xfer == 0)
-       return xfered;
-      if (xfer < 0)
+      /* If there is no explicit region, a fake one should be created.  */
+      gdb_assert (region);
+
+      if (region->hi == 0)
+       rlen = len - xfered;
+      else
+       rlen = region->hi - offset;
+
+      if (region->attrib.mode == MEM_NONE || region->attrib.mode == MEM_WO)
+       {
+         /* Cannot read this region.  Note that we can end up here only
+            if the region is explicitly marked inaccessible, or
+            'inaccessible-by-default' is in effect.  */
+         xfered += rlen;
+       }
+      else
        {
-         /* We've got an error.  Try to read in smaller blocks.  */
-         ULONGEST start = offset + xfered;
-         ULONGEST remaining = len - xfered;
-         ULONGEST half;
-
-         /* If an attempt was made to read a random memory address,
-            it's likely that the very first byte is not accessible.
-            Try reading the first byte, to avoid doing log N tries
-            below.  */
-         xfer = target_read_partial (ops, object, annex, 
-                                     (gdb_byte *) buf + xfered, start, 1);
+         LONGEST to_read = min (len - xfered, rlen);
+         gdb_byte *buffer = (gdb_byte *)xmalloc (to_read);
+
+         LONGEST xfer = target_read (ops, TARGET_OBJECT_MEMORY, NULL,
+                                     (gdb_byte *) buffer,
+                                     offset + xfered, to_read);
+         /* Call an observer, notifying them of the xfer progress?  */
          if (xfer <= 0)
-           return xfered;
-         start += 1;
-         remaining -= 1;
-         half = remaining/2;
-         
-         while (half > 0)
            {
-             xfer = target_read_partial (ops, object, annex,
-                                         (gdb_byte *) buf + xfered,
-                                         start, half);
-             if (xfer == 0)
-               return xfered;
-             if (xfer < 0)
-               {
-                 remaining = half;               
-               }
-             else
-               {
-                 /* We have successfully read the first half.  So, the
-                    error must be in the second half.  Adjust start and
-                    remaining to point at the second half.  */
-                 xfered += xfer;
-                 start += xfer;
-                 remaining -= xfer;
-               }
-             half = remaining/2;
+             /* Got an error reading full chunk.  See if maybe we can read
+                some subrange.  */
+             xfree (buffer);
+             read_whatever_is_readable (ops, offset + xfered,
+                                        offset + xfered + to_read, &result);
+             xfered += to_read;
            }
-
-         return xfered;
+         else
+           {
+             struct memory_read_result r;
+             r.data = buffer;
+             r.begin = offset + xfered;
+             r.end = r.begin + xfer;
+             VEC_safe_push (memory_read_result_s, result, &r);
+             xfered += xfer;
+           }
+         QUIT;
        }
-      xfered += xfer;
-      QUIT;
     }
-  return len;
+  return result;
 }
 
+
 /* An alternative to target_write with progress callbacks.  */
 
 LONGEST
@@ -1967,6 +2342,36 @@ get_target_memory_unsigned (struct target_ops *ops, CORE_ADDR addr,
   return extract_unsigned_integer (buf, len, byte_order);
 }
 
+int
+target_insert_breakpoint (struct gdbarch *gdbarch,
+                         struct bp_target_info *bp_tgt)
+{
+  if (!may_insert_breakpoints)
+    {
+      warning (_("May not insert breakpoints"));
+      return 1;
+    }
+
+  return (*current_target.to_insert_breakpoint) (gdbarch, bp_tgt);
+}
+
+int
+target_remove_breakpoint (struct gdbarch *gdbarch,
+                         struct bp_target_info *bp_tgt)
+{
+  /* This is kind of a weird case to handle, but the permission might
+     have been changed after breakpoints were inserted - in which case
+     we should just take the user literally and assume that any
+     breakpoints should be left in place.  */
+  if (!may_insert_breakpoints)
+    {
+      warning (_("May not remove breakpoints"));
+      return 1;
+    }
+
+  return (*current_target.to_remove_breakpoint) (gdbarch, bp_tgt);
+}
+
 static void
 target_info (char *args, int from_tty)
 {
@@ -1984,7 +2389,8 @@ target_info (char *args, int from_tty)
       if ((int) (t->to_stratum) <= (int) dummy_stratum)
        continue;
       if (has_all_mem)
-       printf_unfiltered (_("\tWhile running this, GDB does not access memory from...\n"));
+       printf_unfiltered (_("\tWhile running this, "
+                            "GDB does not access memory from...\n"));
       printf_unfiltered ("%s:\n", t->to_longname);
       (t->to_files_info) (t);
       has_all_mem = (*t->to_has_all_memory) (t);
@@ -2000,9 +2406,9 @@ target_info (char *args, int from_tty)
 void
 target_pre_inferior (int from_tty)
 {
-  /* Clear out solib state. Otherwise the solib state of the previous
+  /* Clear out solib state.  Otherwise the solib state of the previous
      inferior might have survived and is entirely wrong for the new
-     target.  This has been observed on GNU/Linux using glibc 2.3. How
+     target.  This has been observed on GNU/Linux using glibc 2.3.  How
      to reproduce:
 
      bash$ ./foo&
@@ -2110,7 +2516,7 @@ target_detach (char *args, int from_tty)
        }
     }
 
-  internal_error (__FILE__, __LINE__, "could not find a target to detach");
+  internal_error (__FILE__, __LINE__, _("could not find a target to detach"));
 }
 
 void
@@ -2180,6 +2586,20 @@ target_pid_to_str (ptid_t ptid)
   return normal_pid_to_str (ptid);
 }
 
+char *
+target_thread_name (struct thread_info *info)
+{
+  struct target_ops *t;
+
+  for (t = current_target.beneath; t != NULL; t = t->beneath)
+    {
+      if (t->to_thread_name != NULL)
+       return (*t->to_thread_name) (info);
+    }
+
+  return NULL;
+}
+
 void
 target_resume (ptid_t ptid, int step, enum target_signal signal)
 {
@@ -2208,6 +2628,37 @@ target_resume (ptid_t ptid, int step, enum target_signal signal)
 
   noprocess ();
 }
+
+void
+target_pass_signals (int numsigs, unsigned char *pass_signals)
+{
+  struct target_ops *t;
+
+  for (t = current_target.beneath; t != NULL; t = t->beneath)
+    {
+      if (t->to_pass_signals != NULL)
+       {
+         if (targetdebug)
+           {
+             int i;
+
+             fprintf_unfiltered (gdb_stdlog, "target_pass_signals (%d, {",
+                                 numsigs);
+
+             for (i = 0; i < numsigs; i++)
+               if (pass_signals[i])
+                 fprintf_unfiltered (gdb_stdlog, " %s",
+                                     target_signal_to_name (i));
+
+             fprintf_unfiltered (gdb_stdlog, " })\n");
+           }
+
+         (*t->to_pass_signals) (numsigs, pass_signals);
+         return;
+       }
+    }
+}
+
 /* Look through the list of possible targets for a target that can
    follow forks.  */
 
@@ -2231,7 +2682,7 @@ target_follow_fork (int follow_child)
 
   /* Some target returned a fork event, but did not know how to follow it.  */
   internal_error (__FILE__, __LINE__,
-                 "could not find a target to follow fork");
+                 _("could not find a target to follow fork"));
 }
 
 void
@@ -2257,7 +2708,7 @@ target_mourn_inferior (void)
     }
 
   internal_error (__FILE__, __LINE__,
-                 "could not find a target to follow mourn inferiour");
+                 _("could not find a target to follow mourn inferior"));
 }
 
 /* Look for a target which can describe architectural features, starting
@@ -2370,7 +2821,8 @@ simple_search_memory (struct target_ops *ops,
                           search_buf + keep_len, read_addr,
                           nr_to_read) != nr_to_read)
            {
-             warning (_("Unable to access target memory at %s, halting search."),
+             warning (_("Unable to access target "
+                        "memory at %s, halting search."),
                       hex_string (read_addr));
              do_cleanups (old_cleanups);
              return -1;
@@ -2458,15 +2910,15 @@ target_require_runnable (void)
          || t->to_stratum == arch_stratum)
        continue;
 
-      error (_("\
-The \"%s\" target does not support \"run\".  Try \"help target\" or \"continue\"."),
+      error (_("The \"%s\" target does not support \"run\".  "
+              "Try \"help target\" or \"continue\"."),
             t->to_shortname);
     }
 
   /* This function is only called if the target is running.  In that
      case there should have been a process_stratum target and it
-     should either know how to create inferiors, or not... */
-  internal_error (__FILE__, __LINE__, "No targets found");
+     should either know how to create inferiors, or not...  */
+  internal_error (__FILE__, __LINE__, _("No targets found"));
 }
 
 /* Look through the list of possible targets for a target that can
@@ -2581,6 +3033,28 @@ target_supports_non_stop (void)
   return 0;
 }
 
+static int
+find_default_supports_disable_randomization (void)
+{
+  struct target_ops *t;
+
+  t = find_default_run_target (NULL);
+  if (t && t->to_supports_disable_randomization)
+    return (t->to_supports_disable_randomization) ();
+  return 0;
+}
+
+int
+target_supports_disable_randomization (void)
+{
+  struct target_ops *t;
+
+  for (t = &current_target; t != NULL; t = t->beneath)
+    if (t->to_supports_disable_randomization)
+      return t->to_supports_disable_randomization ();
+
+  return 0;
+}
 
 char *
 target_get_osdata (const char *type)
@@ -2630,8 +3104,9 @@ target_thread_address_space (ptid_t ptid)
   inf = find_inferior_pid (ptid_get_pid (ptid));
 
   if (inf == NULL || inf->aspace == NULL)
-    internal_error (__FILE__, __LINE__, "\
-Can't determine the current address space of thread %s\n",
+    internal_error (__FILE__, __LINE__,
+                   _("Can't determine the current "
+                     "address space of thread %s\n"),
                    target_pid_to_str (ptid));
 
   return inf->aspace;
@@ -2699,31 +3174,6 @@ find_run_target (void)
   return (count == 1 ? runable : NULL);
 }
 
-/* Find a single core_stratum target in the list of targets and return it.
-   If for some reason there is more than one, return NULL.  */
-
-struct target_ops *
-find_core_target (void)
-{
-  struct target_ops **t;
-  struct target_ops *runable = NULL;
-  int count;
-
-  count = 0;
-
-  for (t = target_structs; t < target_structs + target_struct_size;
-       ++t)
-    {
-      if ((*t)->to_stratum == core_stratum)
-       {
-         runable = *t;
-         ++count;
-       }
-    }
-
-  return (count == 1 ? runable : NULL);
-}
-
 /*
  * Find the next target down the stack from the specified target.
  */
@@ -2804,7 +3254,7 @@ dummy_pid_to_str (struct target_ops *ops, ptid_t ptid)
 
 /* Error-catcher for target_find_memory_regions.  */
 static int
-dummy_find_memory_regions (int (*ignore1) (), void *ignore2)
+dummy_find_memory_regions (find_memory_region_ftype ignore1, void *ignore2)
 {
   error (_("Command not implemented for this target."));
   return 0;
@@ -2849,6 +3299,8 @@ init_dummy_target (void)
   dummy_target.to_can_async_p = find_default_can_async_p;
   dummy_target.to_is_async_p = find_default_is_async_p;
   dummy_target.to_supports_non_stop = find_default_supports_non_stop;
+  dummy_target.to_supports_disable_randomization
+    = find_default_supports_disable_randomization;
   dummy_target.to_pid_to_str = dummy_pid_to_str;
   dummy_target.to_stratum = dummy_stratum;
   dummy_target.to_find_memory_regions = dummy_find_memory_regions;
@@ -2860,7 +3312,8 @@ init_dummy_target (void)
   dummy_target.to_has_memory = (int (*) (struct target_ops *)) return_zero;
   dummy_target.to_has_stack = (int (*) (struct target_ops *)) return_zero;
   dummy_target.to_has_registers = (int (*) (struct target_ops *)) return_zero;
-  dummy_target.to_has_execution = (int (*) (struct target_ops *)) return_zero;
+  dummy_target.to_has_execution
+    = (int (*) (struct target_ops *, ptid_t)) return_zero;
   dummy_target.to_stopped_by_watchpoint = return_zero;
   dummy_target.to_stopped_data_address =
     (int (*) (struct target_ops *, CORE_ADDR *)) return_zero;
@@ -2905,7 +3358,7 @@ target_attach (char *args, int from_tty)
     }
 
   internal_error (__FILE__, __LINE__,
-                 "could not find a target to attach");
+                 _("could not find a target to attach"));
 }
 
 int
@@ -2949,6 +3402,18 @@ target_find_new_threads (void)
     }
 }
 
+void
+target_stop (ptid_t ptid)
+{
+  if (!may_stop)
+    {
+      warning (_("May not interrupt or stop the target, ignoring attempt"));
+      return;
+    }
+
+  (*current_target.to_stop) (ptid);
+}
+
 static void
 debug_to_post_attach (int pid)
 {
@@ -2994,6 +3459,8 @@ target_waitstatus_to_string (const struct target_waitstatus *ws)
       return xstrprintf ("%signore", kind_str);
     case TARGET_WAITKIND_NO_HISTORY:
       return xstrprintf ("%sno-history", kind_str);
+    case TARGET_WAITKIND_NO_RESUMED:
+      return xstrprintf ("%sno-resumed", kind_str);
     default:
       return xstrprintf ("%sunknown???", kind_str);
     }
@@ -3058,6 +3525,9 @@ target_store_registers (struct regcache *regcache, int regno)
 {
   struct target_ops *t;
 
+  if (!may_write_registers)
+    error (_("Writing to registers is not allowed (regno %d)"), regno);
+
   for (t = current_target.beneath; t != NULL; t = t->beneath)
     {
       if (t->to_store_registers != NULL)
@@ -3086,7 +3556,8 @@ target_core_of_thread (ptid_t ptid)
          int retval = t->to_core_of_thread (t, ptid);
 
          if (targetdebug)
-           fprintf_unfiltered (gdb_stdlog, "target_core_of_thread (%d) = %d\n",
+           fprintf_unfiltered (gdb_stdlog,
+                               "target_core_of_thread (%d) = %d\n",
                                PIDGET (ptid), retval);
          return retval;
        }
@@ -3107,7 +3578,8 @@ target_verify_memory (const gdb_byte *data, CORE_ADDR memaddr, ULONGEST size)
          int retval = t->to_verify_memory (t, data, memaddr, size);
 
          if (targetdebug)
-           fprintf_unfiltered (gdb_stdlog, "target_verify_memory (%s, %s) = %d\n",
+           fprintf_unfiltered (gdb_stdlog,
+                               "target_verify_memory (%s, %s) = %d\n",
                                paddress (target_gdbarch, memaddr),
                                pulongest (size),
                                retval);
@@ -3118,6 +3590,90 @@ target_verify_memory (const gdb_byte *data, CORE_ADDR memaddr, ULONGEST size)
   tcomplain ();
 }
 
+/* The documentation for this function is in its prototype declaration in
+   target.h.  */
+
+int
+target_insert_mask_watchpoint (CORE_ADDR addr, CORE_ADDR mask, int rw)
+{
+  struct target_ops *t;
+
+  for (t = current_target.beneath; t != NULL; t = t->beneath)
+    if (t->to_insert_mask_watchpoint != NULL)
+      {
+       int ret;
+
+       ret = t->to_insert_mask_watchpoint (t, addr, mask, rw);
+
+       if (targetdebug)
+         fprintf_unfiltered (gdb_stdlog, "\
+target_insert_mask_watchpoint (%s, %s, %d) = %d\n",
+                             core_addr_to_string (addr),
+                             core_addr_to_string (mask), rw, ret);
+
+       return ret;
+      }
+
+  return 1;
+}
+
+/* The documentation for this function is in its prototype declaration in
+   target.h.  */
+
+int
+target_remove_mask_watchpoint (CORE_ADDR addr, CORE_ADDR mask, int rw)
+{
+  struct target_ops *t;
+
+  for (t = current_target.beneath; t != NULL; t = t->beneath)
+    if (t->to_remove_mask_watchpoint != NULL)
+      {
+       int ret;
+
+       ret = t->to_remove_mask_watchpoint (t, addr, mask, rw);
+
+       if (targetdebug)
+         fprintf_unfiltered (gdb_stdlog, "\
+target_remove_mask_watchpoint (%s, %s, %d) = %d\n",
+                             core_addr_to_string (addr),
+                             core_addr_to_string (mask), rw, ret);
+
+       return ret;
+      }
+
+  return 1;
+}
+
+/* The documentation for this function is in its prototype declaration
+   in target.h.  */
+
+int
+target_masked_watch_num_registers (CORE_ADDR addr, CORE_ADDR mask)
+{
+  struct target_ops *t;
+
+  for (t = current_target.beneath; t != NULL; t = t->beneath)
+    if (t->to_masked_watch_num_registers != NULL)
+      return t->to_masked_watch_num_registers (t, addr, mask);
+
+  return -1;
+}
+
+/* The documentation for this function is in its prototype declaration
+   in target.h.  */
+
+int
+target_ranged_break_num_registers (void)
+{
+  struct target_ops *t;
+
+  for (t = current_target.beneath; t != NULL; t = t->beneath)
+    if (t->to_ranged_break_num_registers != NULL)
+      return t->to_ranged_break_num_registers (t);
+
+  return -1;
+}
+
 static void
 debug_to_prepare_to_store (struct regcache *regcache)
 {
@@ -3184,8 +3740,8 @@ debug_to_insert_breakpoint (struct gdbarch *gdbarch,
   retval = debug_target.to_insert_breakpoint (gdbarch, bp_tgt);
 
   fprintf_unfiltered (gdb_stdlog,
-                     "target_insert_breakpoint (0x%lx, xxx) = %ld\n",
-                     (unsigned long) bp_tgt->placed_address,
+                     "target_insert_breakpoint (%s, xxx) = %ld\n",
+                     core_addr_to_string (bp_tgt->placed_address),
                      (unsigned long) retval);
   return retval;
 }
@@ -3199,8 +3755,8 @@ debug_to_remove_breakpoint (struct gdbarch *gdbarch,
   retval = debug_target.to_remove_breakpoint (gdbarch, bp_tgt);
 
   fprintf_unfiltered (gdb_stdlog,
-                     "target_remove_breakpoint (0x%lx, xxx) = %ld\n",
-                     (unsigned long) bp_tgt->placed_address,
+                     "target_remove_breakpoint (%s, xxx) = %ld\n",
+                     core_addr_to_string (bp_tgt->placed_address),
                      (unsigned long) retval);
   return retval;
 }
@@ -3229,10 +3785,26 @@ debug_to_region_ok_for_hw_watchpoint (CORE_ADDR addr, int len)
   retval = debug_target.to_region_ok_for_hw_watchpoint (addr, len);
 
   fprintf_unfiltered (gdb_stdlog,
-                     "target_region_ok_for_hw_watchpoint (%ld, %ld) = 0x%lx\n",
-                     (unsigned long) addr,
-                     (unsigned long) len,
-                     (unsigned long) retval);
+                     "target_region_ok_for_hw_watchpoint (%s, %ld) = %s\n",
+                     core_addr_to_string (addr), (unsigned long) len,
+                     core_addr_to_string (retval));
+  return retval;
+}
+
+static int
+debug_to_can_accel_watchpoint_condition (CORE_ADDR addr, int len, int rw,
+                                        struct expression *cond)
+{
+  int retval;
+
+  retval = debug_target.to_can_accel_watchpoint_condition (addr, len,
+                                                          rw, cond);
+
+  fprintf_unfiltered (gdb_stdlog,
+                     "target_can_accel_watchpoint_condition "
+                     "(%s, %d, %d, %s) = %ld\n",
+                     core_addr_to_string (addr), len, rw,
+                     host_address_to_string (cond), (unsigned long) retval);
   return retval;
 }
 
@@ -3257,8 +3829,8 @@ debug_to_stopped_data_address (struct target_ops *target, CORE_ADDR *addr)
   retval = debug_target.to_stopped_data_address (target, addr);
 
   fprintf_unfiltered (gdb_stdlog,
-                     "target_stopped_data_address ([0x%lx]) = %ld\n",
-                     (unsigned long)*addr,
+                     "target_stopped_data_address ([%s]) = %ld\n",
+                     core_addr_to_string (*addr),
                      (unsigned long)retval);
   return retval;
 }
@@ -3274,9 +3846,9 @@ debug_to_watchpoint_addr_within_range (struct target_ops *target,
                                                         start, length);
 
   fprintf_filtered (gdb_stdlog,
-                   "target_watchpoint_addr_within_range (0x%lx, 0x%lx, %d) = %d\n",
-                   (unsigned long) addr, (unsigned long) start, length,
-                   retval);
+                   "target_watchpoint_addr_within_range (%s, %s, %d) = %d\n",
+                   core_addr_to_string (addr), core_addr_to_string (start),
+                   length, retval);
   return retval;
 }
 
@@ -3289,8 +3861,8 @@ debug_to_insert_hw_breakpoint (struct gdbarch *gdbarch,
   retval = debug_target.to_insert_hw_breakpoint (gdbarch, bp_tgt);
 
   fprintf_unfiltered (gdb_stdlog,
-                     "target_insert_hw_breakpoint (0x%lx, xxx) = %ld\n",
-                     (unsigned long) bp_tgt->placed_address,
+                     "target_insert_hw_breakpoint (%s, xxx) = %ld\n",
+                     core_addr_to_string (bp_tgt->placed_address),
                      (unsigned long) retval);
   return retval;
 }
@@ -3304,35 +3876,39 @@ debug_to_remove_hw_breakpoint (struct gdbarch *gdbarch,
   retval = debug_target.to_remove_hw_breakpoint (gdbarch, bp_tgt);
 
   fprintf_unfiltered (gdb_stdlog,
-                     "target_remove_hw_breakpoint (0x%lx, xxx) = %ld\n",
-                     (unsigned long) bp_tgt->placed_address,
+                     "target_remove_hw_breakpoint (%s, xxx) = %ld\n",
+                     core_addr_to_string (bp_tgt->placed_address),
                      (unsigned long) retval);
   return retval;
 }
 
 static int
-debug_to_insert_watchpoint (CORE_ADDR addr, int len, int type)
+debug_to_insert_watchpoint (CORE_ADDR addr, int len, int type,
+                           struct expression *cond)
 {
   int retval;
 
-  retval = debug_target.to_insert_watchpoint (addr, len, type);
+  retval = debug_target.to_insert_watchpoint (addr, len, type, cond);
 
   fprintf_unfiltered (gdb_stdlog,
-                     "target_insert_watchpoint (0x%lx, %d, %d) = %ld\n",
-                     (unsigned long) addr, len, type, (unsigned long) retval);
+                     "target_insert_watchpoint (%s, %d, %d, %s) = %ld\n",
+                     core_addr_to_string (addr), len, type,
+                     host_address_to_string (cond), (unsigned long) retval);
   return retval;
 }
 
 static int
-debug_to_remove_watchpoint (CORE_ADDR addr, int len, int type)
+debug_to_remove_watchpoint (CORE_ADDR addr, int len, int type,
+                           struct expression *cond)
 {
   int retval;
 
-  retval = debug_target.to_remove_watchpoint (addr, len, type);
+  retval = debug_target.to_remove_watchpoint (addr, len, type, cond);
 
   fprintf_unfiltered (gdb_stdlog,
-                     "target_remove_watchpoint (0x%lx, %d, %d) = %ld\n",
-                     (unsigned long) addr, len, type, (unsigned long) retval);
+                     "target_remove_watchpoint (%s, %d, %d, %s) = %ld\n",
+                     core_addr_to_string (addr), len, type,
+                     host_address_to_string (cond), (unsigned long) retval);
   return retval;
 }
 
@@ -3393,18 +3969,6 @@ debug_to_load (char *args, int from_tty)
   fprintf_unfiltered (gdb_stdlog, "target_load (%s, %d)\n", args, from_tty);
 }
 
-static int
-debug_to_lookup_symbol (char *name, CORE_ADDR *addrp)
-{
-  int retval;
-
-  retval = debug_target.to_lookup_symbol (name, addrp);
-
-  fprintf_unfiltered (gdb_stdlog, "target_lookup_symbol (%s, xxx)\n", name);
-
-  return retval;
-}
-
 static void
 debug_to_post_startup_inferior (ptid_t ptid)
 {
@@ -3414,22 +3978,17 @@ debug_to_post_startup_inferior (ptid_t ptid)
                      PIDGET (ptid));
 }
 
-static void
-debug_to_acknowledge_created_inferior (int pid)
+static int
+debug_to_insert_fork_catchpoint (int pid)
 {
-  debug_target.to_acknowledge_created_inferior (pid);
+  int retval;
 
-  fprintf_unfiltered (gdb_stdlog, "target_acknowledge_created_inferior (%d)\n",
-                     pid);
-}
+  retval = debug_target.to_insert_fork_catchpoint (pid);
 
-static void
-debug_to_insert_fork_catchpoint (int pid)
-{
-  debug_target.to_insert_fork_catchpoint (pid);
+  fprintf_unfiltered (gdb_stdlog, "target_insert_fork_catchpoint (%d) = %d\n",
+                     pid, retval);
 
-  fprintf_unfiltered (gdb_stdlog, "target_insert_fork_catchpoint (%d)\n",
-                     pid);
+  return retval;
 }
 
 static int
@@ -3445,13 +4004,17 @@ debug_to_remove_fork_catchpoint (int pid)
   return retval;
 }
 
-static void
+static int
 debug_to_insert_vfork_catchpoint (int pid)
 {
-  debug_target.to_insert_vfork_catchpoint (pid);
+  int retval;
+
+  retval = debug_target.to_insert_vfork_catchpoint (pid);
+
+  fprintf_unfiltered (gdb_stdlog, "target_insert_vfork_catchpoint (%d) = %d\n",
+                     pid, retval);
 
-  fprintf_unfiltered (gdb_stdlog, "target_insert_vfork_catchpoint (%d)\n",
-                     pid);
+  return retval;
 }
 
 static int
@@ -3467,13 +4030,17 @@ debug_to_remove_vfork_catchpoint (int pid)
   return retval;
 }
 
-static void
+static int
 debug_to_insert_exec_catchpoint (int pid)
 {
-  debug_target.to_insert_exec_catchpoint (pid);
+  int retval;
+
+  retval = debug_target.to_insert_exec_catchpoint (pid);
+
+  fprintf_unfiltered (gdb_stdlog, "target_insert_exec_catchpoint (%d) = %d\n",
+                     pid, retval);
 
-  fprintf_unfiltered (gdb_stdlog, "target_insert_exec_catchpoint (%d)\n",
-                     pid);
+  return retval;
 }
 
 static int
@@ -3514,15 +4081,6 @@ debug_to_can_run (void)
   return retval;
 }
 
-static void
-debug_to_notice_signals (ptid_t ptid)
-{
-  debug_target.to_notice_signals (ptid);
-
-  fprintf_unfiltered (gdb_stdlog, "target_notice_signals (%d)\n",
-                      PIDGET (ptid));
-}
-
 static struct gdbarch *
 debug_to_thread_architecture (struct target_ops *ops, ptid_t ptid)
 {
@@ -3530,8 +4088,10 @@ debug_to_thread_architecture (struct target_ops *ops, ptid_t ptid)
 
   retval = debug_target.to_thread_architecture (ops, ptid);
 
-  fprintf_unfiltered (gdb_stdlog, "target_thread_architecture (%s) = %s [%s]\n",
-                     target_pid_to_str (ptid), host_address_to_string (retval),
+  fprintf_unfiltered (gdb_stdlog, 
+                     "target_thread_architecture (%s) = %s [%s]\n",
+                     target_pid_to_str (ptid),
+                     host_address_to_string (retval),
                      gdbarch_bfd_arch_info (retval)->printable_name);
   return retval;
 }
@@ -3585,18 +4145,21 @@ setup_target_debug (void)
   current_target.to_remove_watchpoint = debug_to_remove_watchpoint;
   current_target.to_stopped_by_watchpoint = debug_to_stopped_by_watchpoint;
   current_target.to_stopped_data_address = debug_to_stopped_data_address;
-  current_target.to_watchpoint_addr_within_range = debug_to_watchpoint_addr_within_range;
-  current_target.to_region_ok_for_hw_watchpoint = debug_to_region_ok_for_hw_watchpoint;
+  current_target.to_watchpoint_addr_within_range
+    = debug_to_watchpoint_addr_within_range;
+  current_target.to_region_ok_for_hw_watchpoint
+    = debug_to_region_ok_for_hw_watchpoint;
+  current_target.to_can_accel_watchpoint_condition
+    = debug_to_can_accel_watchpoint_condition;
   current_target.to_terminal_init = debug_to_terminal_init;
   current_target.to_terminal_inferior = debug_to_terminal_inferior;
-  current_target.to_terminal_ours_for_output = debug_to_terminal_ours_for_output;
+  current_target.to_terminal_ours_for_output
+    = debug_to_terminal_ours_for_output;
   current_target.to_terminal_ours = debug_to_terminal_ours;
   current_target.to_terminal_save_ours = debug_to_terminal_save_ours;
   current_target.to_terminal_info = debug_to_terminal_info;
   current_target.to_load = debug_to_load;
-  current_target.to_lookup_symbol = debug_to_lookup_symbol;
   current_target.to_post_startup_inferior = debug_to_post_startup_inferior;
-  current_target.to_acknowledge_created_inferior = debug_to_acknowledge_created_inferior;
   current_target.to_insert_fork_catchpoint = debug_to_insert_fork_catchpoint;
   current_target.to_remove_fork_catchpoint = debug_to_remove_fork_catchpoint;
   current_target.to_insert_vfork_catchpoint = debug_to_insert_vfork_catchpoint;
@@ -3605,7 +4168,6 @@ setup_target_debug (void)
   current_target.to_remove_exec_catchpoint = debug_to_remove_exec_catchpoint;
   current_target.to_has_exited = debug_to_has_exited;
   current_target.to_can_run = debug_to_can_run;
-  current_target.to_notice_signals = debug_to_notice_signals;
   current_target.to_stop = debug_to_stop;
   current_target.to_rcmd = debug_to_rcmd;
   current_target.to_pid_to_exec_file = debug_to_pid_to_exec_file;
@@ -3614,8 +4176,8 @@ setup_target_debug (void)
 \f
 
 static char targ_desc[] =
-"Names of targets and files being debugged.\n\
-Shows the entire stack of targets currently in use (including the exec-file,\n\
+"Names of targets and files being debugged.\nShows the entire \
+stack of targets currently in use (including the exec-file,\n\
 core-file, and process, if any), as well as the symbol file name.";
 
 static void
@@ -3671,10 +4233,67 @@ show_maintenance_target_async_permitted (struct ui_file *file, int from_tty,
                                         struct cmd_list_element *c,
                                         const char *value)
 {
-  fprintf_filtered (file, _("\
-Controlling the inferior in asynchronous mode is %s.\n"), value);
+  fprintf_filtered (file,
+                   _("Controlling the inferior in "
+                     "asynchronous mode is %s.\n"), value);
+}
+
+/* Temporary copies of permission settings.  */
+
+static int may_write_registers_1 = 1;
+static int may_write_memory_1 = 1;
+static int may_insert_breakpoints_1 = 1;
+static int may_insert_tracepoints_1 = 1;
+static int may_insert_fast_tracepoints_1 = 1;
+static int may_stop_1 = 1;
+
+/* Make the user-set values match the real values again.  */
+
+void
+update_target_permissions (void)
+{
+  may_write_registers_1 = may_write_registers;
+  may_write_memory_1 = may_write_memory;
+  may_insert_breakpoints_1 = may_insert_breakpoints;
+  may_insert_tracepoints_1 = may_insert_tracepoints;
+  may_insert_fast_tracepoints_1 = may_insert_fast_tracepoints;
+  may_stop_1 = may_stop;
 }
 
+/* The one function handles (most of) the permission flags in the same
+   way.  */
+
+static void
+set_target_permissions (char *args, int from_tty,
+                       struct cmd_list_element *c)
+{
+  if (target_has_execution)
+    {
+      update_target_permissions ();
+      error (_("Cannot change this setting while the inferior is running."));
+    }
+
+  /* Make the real values match the user-changed values.  */
+  may_write_registers = may_write_registers_1;
+  may_insert_breakpoints = may_insert_breakpoints_1;
+  may_insert_tracepoints = may_insert_tracepoints_1;
+  may_insert_fast_tracepoints = may_insert_fast_tracepoints_1;
+  may_stop = may_stop_1;
+  update_observer_mode ();
+}
+
+/* Set memory write permission independently of observer mode.  */
+
+static void
+set_write_memory_permission (char *args, int from_tty,
+                       struct cmd_list_element *c)
+{
+  /* Make the real values match the user-changed values.  */
+  may_write_memory = may_write_memory_1;
+  update_observer_mode ();
+}
+
+
 void
 initialize_targets (void)
 {
@@ -3733,5 +4352,60 @@ By default, caching for stack access is on."),
                           show_stack_cache_enabled_p,
                           &setlist, &showlist);
 
+  add_setshow_boolean_cmd ("may-write-registers", class_support,
+                          &may_write_registers_1, _("\
+Set permission to write into registers."), _("\
+Show permission to write into registers."), _("\
+When this permission is on, GDB may write into the target's registers.\n\
+Otherwise, any sort of write attempt will result in an error."),
+                          set_target_permissions, NULL,
+                          &setlist, &showlist);
+
+  add_setshow_boolean_cmd ("may-write-memory", class_support,
+                          &may_write_memory_1, _("\
+Set permission to write into target memory."), _("\
+Show permission to write into target memory."), _("\
+When this permission is on, GDB may write into the target's memory.\n\
+Otherwise, any sort of write attempt will result in an error."),
+                          set_write_memory_permission, NULL,
+                          &setlist, &showlist);
+
+  add_setshow_boolean_cmd ("may-insert-breakpoints", class_support,
+                          &may_insert_breakpoints_1, _("\
+Set permission to insert breakpoints in the target."), _("\
+Show permission to insert breakpoints in the target."), _("\
+When this permission is on, GDB may insert breakpoints in the program.\n\
+Otherwise, any sort of insertion attempt will result in an error."),
+                          set_target_permissions, NULL,
+                          &setlist, &showlist);
+
+  add_setshow_boolean_cmd ("may-insert-tracepoints", class_support,
+                          &may_insert_tracepoints_1, _("\
+Set permission to insert tracepoints in the target."), _("\
+Show permission to insert tracepoints in the target."), _("\
+When this permission is on, GDB may insert tracepoints in the program.\n\
+Otherwise, any sort of insertion attempt will result in an error."),
+                          set_target_permissions, NULL,
+                          &setlist, &showlist);
+
+  add_setshow_boolean_cmd ("may-insert-fast-tracepoints", class_support,
+                          &may_insert_fast_tracepoints_1, _("\
+Set permission to insert fast tracepoints in the target."), _("\
+Show permission to insert fast tracepoints in the target."), _("\
+When this permission is on, GDB may insert fast tracepoints.\n\
+Otherwise, any sort of insertion attempt will result in an error."),
+                          set_target_permissions, NULL,
+                          &setlist, &showlist);
+
+  add_setshow_boolean_cmd ("may-interrupt", class_support,
+                          &may_stop_1, _("\
+Set permission to interrupt or signal the target."), _("\
+Show permission to interrupt or signal the target."), _("\
+When this permission is on, GDB may interrupt/stop the target's execution.\n\
+Otherwise, any attempt to interrupt or stop will be ignored."),
+                          set_target_permissions, NULL,
+                          &setlist, &showlist);
+
+
   target_dcache = dcache_init ();
 }
This page took 0.046942 seconds and 4 git commands to generate.