* elf32-hppa.c (elf32_hppa_relocate_section): Skip relocation if
[deliverable/binutils-gdb.git] / gdb / target.c
index d5f205fda0f9333fc2775a35f2b7b413c0e385be..9559914b7757b4b52d27acd0f97db8c565c4b1a1 100644 (file)
@@ -1,7 +1,8 @@
 /* Select target systems and architectures at runtime for GDB.
-   Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
-   2000, 2001, 2002
-   Free Software Foundation, Inc.
+
+   Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
+   1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
+
    Contributed by Cygnus Support.
 
    This file is part of GDB.
@@ -40,18 +41,16 @@ extern int errno;
 
 static void target_info (char *, int);
 
-static void cleanup_target (struct target_ops *);
-
 static void maybe_kill_then_create_inferior (char *, char *, char **);
 
-static void default_clone_and_follow_inferior (int, int *);
-
 static void maybe_kill_then_attach (char *, int);
 
 static void kill_or_be_killed (int);
 
 static void default_terminal_info (char *, int);
 
+static int default_region_size_ok_for_hw_watchpoint (int);
+
 static int nosymbol (char *, CORE_ADDR *);
 
 static void tcomplain (void);
@@ -62,14 +61,14 @@ static int return_zero (void);
 
 static int return_one (void);
 
+static int return_minus_one (void);
+
 void target_ignore (void);
 
 static void target_command (char *, int);
 
 static struct target_ops *find_default_run_target (char *);
 
-static void update_current_target (void);
-
 static void nosupport_runtime (void);
 
 static void normal_target_post_startup_inferior (ptid_t ptid);
@@ -80,8 +79,8 @@ static void normal_target_post_startup_inferior (ptid_t ptid);
    partial transfers, try either target_read_memory_partial or
    target_write_memory_partial).  */
 
-static int
-target_xfer_memory (CORE_ADDR memaddr, char *myaddr, int len, int write);
+static int target_xfer_memory (CORE_ADDR memaddr, char *myaddr, int len,
+                              int write);
 
 static void init_dummy_target (void);
 
@@ -93,6 +92,8 @@ static void debug_to_attach (char *, int);
 
 static void debug_to_detach (char *, int);
 
+static void debug_to_disconnect (char *, int);
+
 static void debug_to_resume (ptid_t, int, enum target_signal);
 
 static ptid_t debug_to_wait (ptid_t, struct target_waitstatus *);
@@ -103,9 +104,8 @@ static void debug_to_store_registers (int);
 
 static void debug_to_prepare_to_store (void);
 
-static int
-debug_to_xfer_memory (CORE_ADDR, char *, int, int, struct mem_attrib *, 
-                     struct target_ops *);
+static int debug_to_xfer_memory (CORE_ADDR, char *, int, int,
+                                struct mem_attrib *, struct target_ops *);
 
 static void debug_to_files_info (struct target_ops *);
 
@@ -113,12 +113,30 @@ static int debug_to_insert_breakpoint (CORE_ADDR, char *);
 
 static int debug_to_remove_breakpoint (CORE_ADDR, char *);
 
+static int debug_to_can_use_hw_breakpoint (int, int, int);
+
+static int debug_to_insert_hw_breakpoint (CORE_ADDR, char *);
+
+static int debug_to_remove_hw_breakpoint (CORE_ADDR, char *);
+
+static int debug_to_insert_watchpoint (CORE_ADDR, int, int);
+
+static int debug_to_remove_watchpoint (CORE_ADDR, int, int);
+
+static int debug_to_stopped_by_watchpoint (void);
+
+static CORE_ADDR debug_to_stopped_data_address (void);
+
+static int debug_to_region_size_ok_for_hw_watchpoint (int);
+
 static void debug_to_terminal_init (void);
 
 static void debug_to_terminal_inferior (void);
 
 static void debug_to_terminal_ours_for_output (void);
 
+static void debug_to_terminal_save_ours (void);
+
 static void debug_to_terminal_ours (void);
 
 static void debug_to_terminal_info (char *, int);
@@ -159,7 +177,7 @@ static struct target_ops dummy_target;
 
 /* Top of target stack.  */
 
-struct target_stack_item *target_stack;
+static struct target_ops *target_stack;
 
 /* The target structure we are currently using to talk to a process
    or file or whatever "inferior" we have.  */
@@ -185,7 +203,6 @@ DCACHE *target_dcache;
 
 /* The user just typed 'target' without the name of a target.  */
 
-/* ARGSUSED */
 static void
 target_command (char *arg, int from_tty)
 {
@@ -212,7 +229,6 @@ add_target (struct target_ops *t)
                  target_struct_allocsize * sizeof (*target_structs));
     }
   target_structs[target_struct_size++] = t;
-/*  cleanup_target (t); */
 
   if (targetlist == NULL)
     add_prefix_cmd ("target", class_run, target_command,
@@ -239,7 +255,6 @@ target_load (char *arg, int from_tty)
   (*current_target.to_load) (arg, from_tty);
 }
 
-/* ARGSUSED */
 static int
 nomemory (CORE_ADDR memaddr, char *myaddr, int len, int write,
          struct target_ops *t)
@@ -261,14 +276,12 @@ noprocess (void)
   error ("You can't do that without a process to debug.");
 }
 
-/* ARGSUSED */
 static int
 nosymbol (char *name, CORE_ADDR *addrp)
 {
   return 1;                    /* Symbol does not exist in target env */
 }
 
-/* ARGSUSED */
 static void
 nosupport_runtime (void)
 {
@@ -279,7 +292,6 @@ nosupport_runtime (void)
 }
 
 
-/* ARGSUSED */
 static void
 default_terminal_info (char *args, int from_tty)
 {
@@ -327,22 +339,121 @@ maybe_kill_then_create_inferior (char *exec, char *args, char **env)
   target_create_inferior (exec, args, env);
 }
 
-static void
-default_clone_and_follow_inferior (int child_pid, int *followed_child)
-{
-  target_clone_and_follow_inferior (child_pid, followed_child);
-}
+/* 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
+   vectors.
 
-/* Clean up a target struct so it no longer has any zero pointers in it.
-   We default entries, at least to stubs that print error messages.  */
+   NOTE: cagney/2003-10-17: The problem with this inheritance, as it
+   is currently implemented, is that it discards any knowledge of
+   which target an inherited method originally belonged to.
+   Consequently, new new target methods should instead explicitly and
+   locally search the target stack for the target that can handle the
+   request.  */
 
 static void
-cleanup_target (struct target_ops *t)
+update_current_target (void)
 {
+  struct target_ops *t;
+
+  /* First, reset curren'ts contents.  */
+  memset (&current_target, 0, sizeof (current_target));
+
+#define INHERIT(FIELD, TARGET) \
+      if (!current_target.FIELD) \
+       current_target.FIELD = (TARGET)->FIELD
+
+  for (t = target_stack; t; t = t->beneath)
+    {
+      INHERIT (to_shortname, t);
+      INHERIT (to_longname, t);
+      INHERIT (to_doc, t);
+      INHERIT (to_open, t);
+      INHERIT (to_close, t);
+      INHERIT (to_attach, t);
+      INHERIT (to_post_attach, t);
+      INHERIT (to_detach, t);
+      INHERIT (to_disconnect, t);
+      INHERIT (to_resume, t);
+      INHERIT (to_wait, t);
+      INHERIT (to_post_wait, t);
+      INHERIT (to_fetch_registers, t);
+      INHERIT (to_store_registers, t);
+      INHERIT (to_prepare_to_store, t);
+      INHERIT (to_xfer_memory, t);
+      INHERIT (to_files_info, t);
+      INHERIT (to_insert_breakpoint, t);
+      INHERIT (to_remove_breakpoint, t);
+      INHERIT (to_can_use_hw_breakpoint, t);
+      INHERIT (to_insert_hw_breakpoint, t);
+      INHERIT (to_remove_hw_breakpoint, t);
+      INHERIT (to_insert_watchpoint, t);
+      INHERIT (to_remove_watchpoint, t);
+      INHERIT (to_stopped_data_address, t);
+      INHERIT (to_stopped_by_watchpoint, t);
+      INHERIT (to_have_continuable_watchpoint, t);
+      INHERIT (to_region_size_ok_for_hw_watchpoint, t);
+      INHERIT (to_terminal_init, t);
+      INHERIT (to_terminal_inferior, t);
+      INHERIT (to_terminal_ours_for_output, t);
+      INHERIT (to_terminal_ours, t);
+      INHERIT (to_terminal_save_ours, t);
+      INHERIT (to_terminal_info, t);
+      INHERIT (to_kill, t);
+      INHERIT (to_load, t);
+      INHERIT (to_lookup_symbol, t);
+      INHERIT (to_create_inferior, t);
+      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);
+      INHERIT (to_remove_vfork_catchpoint, t);
+      INHERIT (to_follow_fork, t);
+      INHERIT (to_insert_exec_catchpoint, t);
+      INHERIT (to_remove_exec_catchpoint, t);
+      INHERIT (to_reported_exec_events_per_exec_call, t);
+      INHERIT (to_has_exited, t);
+      INHERIT (to_mourn_inferior, t);
+      INHERIT (to_can_run, t);
+      INHERIT (to_notice_signals, t);
+      INHERIT (to_thread_alive, t);
+      INHERIT (to_find_new_threads, t);
+      INHERIT (to_pid_to_str, t);
+      INHERIT (to_extra_thread_info, t);
+      INHERIT (to_stop, t);
+      INHERIT (to_query, t);
+      INHERIT (to_rcmd, t);
+      INHERIT (to_enable_exception_callback, t);
+      INHERIT (to_get_current_exception_event, t);
+      INHERIT (to_pid_to_exec_file, t);
+      INHERIT (to_stratum, t);
+      INHERIT (to_has_all_memory, t);
+      INHERIT (to_has_memory, t);
+      INHERIT (to_has_stack, t);
+      INHERIT (to_has_registers, t);
+      INHERIT (to_has_execution, t);
+      INHERIT (to_has_thread_control, t);
+      INHERIT (to_sections, t);
+      INHERIT (to_sections_end, t);
+      INHERIT (to_can_async_p, t);
+      INHERIT (to_is_async_p, t);
+      INHERIT (to_async, t);
+      INHERIT (to_async_mask_value, t);
+      INHERIT (to_find_memory_regions, t);
+      INHERIT (to_make_corefile_notes, t);
+      INHERIT (to_get_thread_local_address, t);
+      INHERIT (to_magic, t);
+    }
+#undef INHERIT
+
+  /* Clean up a target struct so it no longer has any zero pointers in
+     it.  We default entries, at least to stubs that print error
+     messages.  */
 
 #define de_fault(field, value) \
-  if (!t->field)               \
-    t->field = value
+  if (!current_target.field)               \
+    current_target.field = value
 
   de_fault (to_open, 
            (void (*) (char *, int)) 
@@ -355,14 +466,12 @@ cleanup_target (struct target_ops *t)
   de_fault (to_post_attach, 
            (void (*) (int)) 
            target_ignore);
-  de_fault (to_require_attach, 
-           maybe_kill_then_attach);
   de_fault (to_detach, 
            (void (*) (char *, int)) 
            target_ignore);
-  de_fault (to_require_detach
-           (void (*) (int, char *, int)) 
-           target_ignore);
+  de_fault (to_disconnect
+           (void (*) (char *, int)) 
+           tcomplain);
   de_fault (to_resume, 
            (void (*) (ptid_t, int, enum target_signal)) 
            noprocess);
@@ -391,6 +500,29 @@ cleanup_target (struct target_ops *t)
            memory_insert_breakpoint);
   de_fault (to_remove_breakpoint, 
            memory_remove_breakpoint);
+  de_fault (to_can_use_hw_breakpoint,
+           (int (*) (int, int, int))
+           return_zero);
+  de_fault (to_insert_hw_breakpoint,
+           (int (*) (CORE_ADDR, char *))
+           return_minus_one);
+  de_fault (to_remove_hw_breakpoint,
+           (int (*) (CORE_ADDR, char *))
+           return_minus_one);
+  de_fault (to_insert_watchpoint,
+           (int (*) (CORE_ADDR, int, int))
+           return_minus_one);
+  de_fault (to_remove_watchpoint,
+           (int (*) (CORE_ADDR, int, int))
+           return_minus_one);
+  de_fault (to_stopped_by_watchpoint,
+           (int (*) (void))
+           return_zero);
+  de_fault (to_stopped_data_address,
+           (CORE_ADDR (*) (void))
+           return_zero);
+  de_fault (to_region_size_ok_for_hw_watchpoint,
+           default_region_size_ok_for_hw_watchpoint);
   de_fault (to_terminal_init, 
            (void (*) (void)) 
            target_ignore);
@@ -403,6 +535,9 @@ cleanup_target (struct target_ops *t)
   de_fault (to_terminal_ours, 
            (void (*) (void)) 
            target_ignore);
+  de_fault (to_terminal_save_ours, 
+           (void (*) (void)) 
+           target_ignore);
   de_fault (to_terminal_info, 
            default_terminal_info);
   de_fault (to_kill, 
@@ -422,11 +557,6 @@ cleanup_target (struct target_ops *t)
   de_fault (to_acknowledge_created_inferior, 
            (void (*) (int)) 
            target_ignore);
-  de_fault (to_clone_and_follow_inferior, 
-           default_clone_and_follow_inferior);
-  de_fault (to_post_follow_inferior_by_clone, 
-           (void (*) (void)) 
-           target_ignore);
   de_fault (to_insert_fork_catchpoint, 
            (int (*) (int)) 
            tcomplain);
@@ -439,17 +569,8 @@ cleanup_target (struct target_ops *t)
   de_fault (to_remove_vfork_catchpoint, 
            (int (*) (int)) 
            tcomplain);
-  de_fault (to_has_forked, 
-           (int (*) (int, int *)) 
-           return_zero);
-  de_fault (to_has_vforked, 
-           (int (*) (int, int *)) 
-           return_zero);
-  de_fault (to_can_follow_vfork_prior_to_exec, 
-           (int (*) (void)) 
-           return_zero);
-  de_fault (to_post_follow_vfork, 
-           (void (*) (int, int, int, int)) 
+  de_fault (to_follow_fork,
+           (int (*) (int)) 
            target_ignore);
   de_fault (to_insert_exec_catchpoint, 
            (int (*) (int)) 
@@ -457,15 +578,9 @@ cleanup_target (struct target_ops *t)
   de_fault (to_remove_exec_catchpoint, 
            (int (*) (int)) 
            tcomplain);
-  de_fault (to_has_execd, 
-           (int (*) (int, char **)) 
-           return_zero);
   de_fault (to_reported_exec_events_per_exec_call, 
            (int (*) (void)) 
            return_one);
-  de_fault (to_has_syscall_event, 
-           (int (*) (int, enum target_waitkind *, int *)) 
-           return_zero);
   de_fault (to_has_exited, 
            (int (*) (int, int, int *)) 
            return_zero);
@@ -511,109 +626,11 @@ cleanup_target (struct target_ops *t)
            (void (*) (void (*) (enum inferior_event_type, void*), void*)) 
            tcomplain);
 #undef de_fault
-}
-
-/* Go through the target stack from top to bottom, copying over zero entries in
-   current_target.  In effect, we are doing class inheritance through the
-   pushed target vectors.  */
-
-static void
-update_current_target (void)
-{
-  struct target_stack_item *item;
-  struct target_ops *t;
-
-  /* First, reset current_target */
-  memset (&current_target, 0, sizeof current_target);
-
-  for (item = target_stack; item; item = item->next)
-    {
-      t = item->target_ops;
-
-#define INHERIT(FIELD, TARGET) \
-      if (!current_target.FIELD) \
-       current_target.FIELD = TARGET->FIELD
 
-      INHERIT (to_shortname, t);
-      INHERIT (to_longname, t);
-      INHERIT (to_doc, t);
-      INHERIT (to_open, t);
-      INHERIT (to_close, t);
-      INHERIT (to_attach, t);
-      INHERIT (to_post_attach, t);
-      INHERIT (to_require_attach, t);
-      INHERIT (to_detach, t);
-      INHERIT (to_require_detach, t);
-      INHERIT (to_resume, t);
-      INHERIT (to_wait, t);
-      INHERIT (to_post_wait, t);
-      INHERIT (to_fetch_registers, t);
-      INHERIT (to_store_registers, t);
-      INHERIT (to_prepare_to_store, t);
-      INHERIT (to_xfer_memory, t);
-      INHERIT (to_files_info, t);
-      INHERIT (to_insert_breakpoint, t);
-      INHERIT (to_remove_breakpoint, t);
-      INHERIT (to_terminal_init, t);
-      INHERIT (to_terminal_inferior, t);
-      INHERIT (to_terminal_ours_for_output, t);
-      INHERIT (to_terminal_ours, t);
-      INHERIT (to_terminal_info, t);
-      INHERIT (to_kill, t);
-      INHERIT (to_load, t);
-      INHERIT (to_lookup_symbol, t);
-      INHERIT (to_create_inferior, t);
-      INHERIT (to_post_startup_inferior, t);
-      INHERIT (to_acknowledge_created_inferior, t);
-      INHERIT (to_clone_and_follow_inferior, t);
-      INHERIT (to_post_follow_inferior_by_clone, t);
-      INHERIT (to_insert_fork_catchpoint, t);
-      INHERIT (to_remove_fork_catchpoint, t);
-      INHERIT (to_insert_vfork_catchpoint, t);
-      INHERIT (to_remove_vfork_catchpoint, t);
-      INHERIT (to_has_forked, t);
-      INHERIT (to_has_vforked, t);
-      INHERIT (to_can_follow_vfork_prior_to_exec, t);
-      INHERIT (to_post_follow_vfork, t);
-      INHERIT (to_insert_exec_catchpoint, t);
-      INHERIT (to_remove_exec_catchpoint, t);
-      INHERIT (to_has_execd, t);
-      INHERIT (to_reported_exec_events_per_exec_call, t);
-      INHERIT (to_has_syscall_event, t);
-      INHERIT (to_has_exited, t);
-      INHERIT (to_mourn_inferior, t);
-      INHERIT (to_can_run, t);
-      INHERIT (to_notice_signals, t);
-      INHERIT (to_thread_alive, t);
-      INHERIT (to_find_new_threads, t);
-      INHERIT (to_pid_to_str, t);
-      INHERIT (to_extra_thread_info, t);
-      INHERIT (to_stop, t);
-      INHERIT (to_query, t);
-      INHERIT (to_rcmd, t);
-      INHERIT (to_enable_exception_callback, t);
-      INHERIT (to_get_current_exception_event, t);
-      INHERIT (to_pid_to_exec_file, t);
-      INHERIT (to_stratum, t);
-      INHERIT (DONT_USE, t);
-      INHERIT (to_has_all_memory, t);
-      INHERIT (to_has_memory, t);
-      INHERIT (to_has_stack, t);
-      INHERIT (to_has_registers, t);
-      INHERIT (to_has_execution, t);
-      INHERIT (to_has_thread_control, t);
-      INHERIT (to_sections, t);
-      INHERIT (to_sections_end, t);
-      INHERIT (to_can_async_p, t);
-      INHERIT (to_is_async_p, t);
-      INHERIT (to_async, t);
-      INHERIT (to_async_mask_value, t);
-      INHERIT (to_find_memory_regions, t);
-      INHERIT (to_make_corefile_notes, t);
-      INHERIT (to_magic, t);
-
-#undef INHERIT
-    }
+  /* Finally, position the target-stack beneath the squashed
+     "current_target".  That way code looking for a non-inherited
+     target method can quickly and simply find it.  */
+  current_target.beneath = target_stack;
 }
 
 /* Push a new target type into the stack of the existing target accessors,
@@ -629,7 +646,7 @@ update_current_target (void)
 int
 push_target (struct target_ops *t)
 {
-  struct target_stack_item *cur, *prev, *tmp;
+  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.  */
@@ -641,51 +658,38 @@ push_target (struct target_ops *t)
       internal_error (__FILE__, __LINE__, "failed internal consistency check");
     }
 
-  /* Find the proper stratum to install this target in. */
-
-  for (prev = NULL, cur = target_stack; cur; prev = cur, cur = cur->next)
+  /* Find the proper stratum to install this target in.  */
+  for (cur = &target_stack; (*cur) != NULL; cur = &(*cur)->beneath)
     {
-      if ((int) (t->to_stratum) >= (int) (cur->target_ops->to_stratum))
+      if ((int) (t->to_stratum) >= (int) (*cur)->to_stratum)
        break;
     }
 
-  /* If there's already targets at this stratum, remove them. */
-
-  if (cur)
-    while (t->to_stratum == cur->target_ops->to_stratum)
-      {
-       /* There's already something on this stratum.  Close it off.  */
-       if (cur->target_ops->to_close)
-         (cur->target_ops->to_close) (0);
-       if (prev)
-         prev->next = cur->next;       /* Unchain old target_ops */
-       else
-         target_stack = cur->next;     /* Unchain first on list */
-       tmp = cur->next;
-       xfree (cur);
-       cur = tmp;
-      }
+  /* If there's already targets at this stratum, remove them.  */
+  /* FIXME: cagney/2003-10-15: I think this should be poping all
+     targets to CUR, and not just those at this stratum level.  */
+  while ((*cur) != NULL && t->to_stratum == (*cur)->to_stratum)
+    {
+      /* There's already something at this stratum level.  Close it,
+         and un-hook it from the stack.  */
+      struct target_ops *tmp = (*cur);
+      (*cur) = (*cur)->beneath;
+      tmp->beneath = NULL;
+      if (tmp->to_close)
+       (tmp->to_close) (0);
+    }
 
   /* We have removed all targets in our stratum, now add the new one.  */
-
-  tmp = (struct target_stack_item *)
-    xmalloc (sizeof (struct target_stack_item));
-  tmp->next = cur;
-  tmp->target_ops = t;
-
-  if (prev)
-    prev->next = tmp;
-  else
-    target_stack = tmp;
+  t->beneath = (*cur);
+  (*cur) = t;
 
   update_current_target ();
 
-  cleanup_target (&current_target);    /* Fill in the gaps */
-
   if (targetdebug)
     setup_target_debug ();
 
-  return prev != 0;
+  /* Not on top?  */
+  return (t != target_stack);
 }
 
 /* Remove a target_ops vector from the stack, wherever it may be. 
@@ -694,7 +698,8 @@ push_target (struct target_ops *t)
 int
 unpush_target (struct target_ops *t)
 {
-  struct target_stack_item *cur, *prev;
+  struct target_ops **cur;
+  struct target_ops *tmp;
 
   if (t->to_close)
     t->to_close (0);           /* Let it clean up */
@@ -702,24 +707,21 @@ unpush_target (struct target_ops *t)
   /* Look for the specified target.  Note that we assume that a target
      can only occur once in the target stack. */
 
-  for (cur = target_stack, prev = NULL; cur; prev = cur, cur = cur->next)
-    if (cur->target_ops == t)
-      break;
+  for (cur = &target_stack; (*cur) != NULL; cur = &(*cur)->beneath)
+    {
+      if ((*cur) == t)
+       break;
+    }
 
-  if (!cur)
+  if ((*cur) == NULL)
     return 0;                  /* Didn't find target_ops, quit now */
 
   /* Unchain the target */
-
-  if (!prev)
-    target_stack = cur->next;
-  else
-    prev->next = cur->next;
-
-  xfree (cur);                 /* Release the target_stack_item */
+  tmp = (*cur);
+  (*cur) = (*cur)->beneath;
+  tmp->beneath = NULL;
 
   update_current_target ();
-  cleanup_target (&current_target);
 
   return 1;
 }
@@ -728,7 +730,7 @@ void
 pop_target (void)
 {
   (current_target.to_close) (0);       /* Let it clean up */
-  if (unpush_target (target_stack->target_ops) == 1)
+  if (unpush_target (target_stack) == 1)
     return;
 
   fprintf_unfiltered (gdb_stderr,
@@ -849,7 +851,6 @@ do_xfer_memory (CORE_ADDR memaddr, char *myaddr, int len, int write,
   int res;
   int done = 0;
   struct target_ops *t;
-  struct target_stack_item *item;
 
   /* Zero length requests are ok and require no work.  */
   if (len == 0)
@@ -861,9 +862,9 @@ do_xfer_memory (CORE_ADDR memaddr, char *myaddr, int len, int write,
 
   if (!write && trust_readonly)
     {
-      /* User-settable option, "trust-readonly".  If true, then
-        memory from any SEC_READONLY bfd section may be read
-        directly from the bfd file. */
+      /* User-settable option, "trust-readonly-sections".  If true,
+         then memory from any SEC_READONLY bfd section may be read
+         directly from the bfd file. */
 
       struct section_table *secp;
 
@@ -886,9 +887,8 @@ do_xfer_memory (CORE_ADDR memaddr, char *myaddr, int len, int write,
   /* If res <= 0 then we call it again in the loop.  Ah well. */
   if (res <= 0)
     {
-      for (item = target_stack; item; item = item->next)
+      for (t = target_stack; t != NULL; t = t->beneath)
        {
-         t = item->target_ops;
          if (!t->to_has_memory)
            continue;
 
@@ -1056,12 +1056,10 @@ target_write_memory_partial (CORE_ADDR memaddr, char *buf, int len, int *err)
   return target_xfer_memory_partial (memaddr, buf, len, 1, err);
 }
 
-/* ARGSUSED */
 static void
 target_info (char *args, int from_tty)
 {
   struct target_ops *t;
-  struct target_stack_item *item;
   int has_all_mem = 0;
 
   if (symfile_objfile != NULL)
@@ -1072,10 +1070,8 @@ target_info (char *args, int from_tty)
     return;
 #endif
 
-  for (item = target_stack; item; item = item->next)
+  for (t = target_stack; t != NULL; t = t->beneath)
     {
-      t = item->target_ops;
-
       if (!t->to_has_memory)
        continue;
 
@@ -1125,6 +1121,16 @@ target_detach (char *args, int from_tty)
   (current_target.to_detach) (args, from_tty);
 }
 
+void
+target_disconnect (char *args, int from_tty)
+{
+  /* Handle any optimized stores to the inferior.  */
+#ifdef DO_DEFERRED_STORES
+  DO_DEFERRED_STORES;
+#endif
+  (current_target.to_disconnect) (args, from_tty);
+}
+
 void
 target_link (char *modname, CORE_ADDR *t_reloc)
 {
@@ -1187,26 +1193,6 @@ find_default_attach (char *args, int from_tty)
   return;
 }
 
-void
-find_default_require_attach (char *args, int from_tty)
-{
-  struct target_ops *t;
-
-  t = find_default_run_target ("require_attach");
-  (t->to_require_attach) (args, from_tty);
-  return;
-}
-
-void
-find_default_require_detach (int pid, char *args, int from_tty)
-{
-  struct target_ops *t;
-
-  t = find_default_run_target ("require_detach");
-  (t->to_require_detach) (pid, args, from_tty);
-  return;
-}
-
 void
 find_default_create_inferior (char *exec_file, char *allargs, char **env)
 {
@@ -1217,14 +1203,10 @@ find_default_create_inferior (char *exec_file, char *allargs, char **env)
   return;
 }
 
-void
-find_default_clone_and_follow_inferior (int child_pid, int *followed_child)
+static int
+default_region_size_ok_for_hw_watchpoint (int byte_count)
 {
-  struct target_ops *t;
-
-  t = find_default_run_target ("run");
-  (t->to_clone_and_follow_inferior) (child_pid, followed_child);
-  return;
+  return (byte_count <= DEPRECATED_REGISTER_SIZE);
 }
 
 static int
@@ -1239,6 +1221,12 @@ return_one (void)
   return 1;
 }
 
+static int
+return_minus_one (void)
+{
+  return -1;
+}
+
 /*
  * Resize the to_sections pointer.  Also make sure that anyone that
  * was holding on to an old value of it gets updated.
@@ -1378,16 +1366,7 @@ find_core_target (void)
 struct target_ops *
 find_target_beneath (struct target_ops *t)
 {
-  struct target_stack_item *cur;
-
-  for (cur = target_stack; cur; cur = cur->next)
-    if (cur->target_ops == t)
-      break;
-
-  if (cur == NULL || cur->next == NULL)
-    return NULL;
-  else
-    return cur->next->target_ops;
+  return t->beneath;
 }
 
 \f
@@ -1487,7 +1466,6 @@ normal_target_post_startup_inferior (ptid_t ptid)
 }
 
 /* Error-catcher for target_find_memory_regions */
-/* ARGSUSED */
 static int dummy_find_memory_regions (int (*ignore1) (), void *ignore2)
 {
   error ("No target.");
@@ -1495,7 +1473,6 @@ static int dummy_find_memory_regions (int (*ignore1) (), void *ignore2)
 }
 
 /* Error-catcher for target_make_corefile_notes */
-/* ARGSUSED */
 static char * dummy_make_corefile_notes (bfd *ignore1, int *ignore2)
 {
   error ("No target.");
@@ -1512,10 +1489,7 @@ init_dummy_target (void)
   dummy_target.to_longname = "None";
   dummy_target.to_doc = "";
   dummy_target.to_attach = find_default_attach;
-  dummy_target.to_require_attach = find_default_require_attach;
-  dummy_target.to_require_detach = find_default_require_detach;
   dummy_target.to_create_inferior = find_default_create_inferior;
-  dummy_target.to_clone_and_follow_inferior = find_default_clone_and_follow_inferior;
   dummy_target.to_pid_to_str = normal_pid_to_str;
   dummy_target.to_stratum = dummy_stratum;
   dummy_target.to_find_memory_regions = dummy_find_memory_regions;
@@ -1559,15 +1533,6 @@ debug_to_post_attach (int pid)
   fprintf_unfiltered (gdb_stdlog, "target_post_attach (%d)\n", pid);
 }
 
-static void
-debug_to_require_attach (char *args, int from_tty)
-{
-  debug_target.to_require_attach (args, from_tty);
-
-  fprintf_unfiltered (gdb_stdlog,
-                     "target_require_attach (%s, %d)\n", args, from_tty);
-}
-
 static void
 debug_to_detach (char *args, int from_tty)
 {
@@ -1577,12 +1542,12 @@ debug_to_detach (char *args, int from_tty)
 }
 
 static void
-debug_to_require_detach (int pid, char *args, int from_tty)
+debug_to_disconnect (char *args, int from_tty)
 {
-  debug_target.to_require_detach (pid, args, from_tty);
+  debug_target.to_disconnect (args, from_tty);
 
-  fprintf_unfiltered (gdb_stdlog,
-              "target_require_detach (%d, %s, %d)\n", pid, args, from_tty);
+  fprintf_unfiltered (gdb_stdlog, "target_disconnect (%s, %d)\n",
+                     args, from_tty);
 }
 
 static void
@@ -1652,32 +1617,48 @@ debug_to_post_wait (ptid_t ptid, int status)
                      PIDGET (ptid), status);
 }
 
+static void
+debug_print_register (const char * func, int regno)
+{
+  fprintf_unfiltered (gdb_stdlog, "%s ", func);
+  if (regno >= 0 && regno < NUM_REGS + NUM_PSEUDO_REGS
+      && REGISTER_NAME (regno) != NULL && REGISTER_NAME (regno)[0] != '\0')
+    fprintf_unfiltered (gdb_stdlog, "(%s)", REGISTER_NAME (regno));
+  else
+    fprintf_unfiltered (gdb_stdlog, "(%d)", regno);
+  if (regno >= 0)
+    {
+      int i;
+      unsigned char buf[MAX_REGISTER_SIZE];
+      deprecated_read_register_gen (regno, buf);
+      fprintf_unfiltered (gdb_stdlog, " = ");
+      for (i = 0; i < DEPRECATED_REGISTER_RAW_SIZE (regno); i++)
+       {
+         fprintf_unfiltered (gdb_stdlog, "%02x", buf[i]);
+       }
+      if (DEPRECATED_REGISTER_RAW_SIZE (regno) <= sizeof (LONGEST))
+       {
+         fprintf_unfiltered (gdb_stdlog, " 0x%s %s",
+                             paddr_nz (read_register (regno)),
+                             paddr_d (read_register (regno)));
+       }
+    }
+  fprintf_unfiltered (gdb_stdlog, "\n");
+}
+
 static void
 debug_to_fetch_registers (int regno)
 {
   debug_target.to_fetch_registers (regno);
-
-  fprintf_unfiltered (gdb_stdlog, "target_fetch_registers (%s)",
-                     regno != -1 ? REGISTER_NAME (regno) : "-1");
-  if (regno != -1)
-    fprintf_unfiltered (gdb_stdlog, " = 0x%lx %ld",
-                       (unsigned long) read_register (regno),
-                       (unsigned long) read_register (regno));
-  fprintf_unfiltered (gdb_stdlog, "\n");
+  debug_print_register ("target_fetch_registers", regno);
 }
 
 static void
 debug_to_store_registers (int regno)
 {
   debug_target.to_store_registers (regno);
-
-  if (regno >= 0 && regno < NUM_REGS)
-    fprintf_unfiltered (gdb_stdlog, "target_store_registers (%s) = 0x%lx %ld\n",
-                       REGISTER_NAME (regno),
-                       (unsigned long) read_register (regno),
-                       (unsigned long) read_register (regno));
-  else
-    fprintf_unfiltered (gdb_stdlog, "target_store_registers (%d)\n", regno);
+  debug_print_register ("target_store_registers", regno);
+  fprintf_unfiltered (gdb_stdlog, "\n");
 }
 
 static void
@@ -1759,6 +1740,116 @@ debug_to_remove_breakpoint (CORE_ADDR addr, char *save)
   return retval;
 }
 
+static int
+debug_to_can_use_hw_breakpoint (int type, int cnt, int from_tty)
+{
+  int retval;
+
+  retval = debug_target.to_can_use_hw_breakpoint (type, cnt, from_tty);
+
+  fprintf_unfiltered (gdb_stdlog,
+                     "target_can_use_hw_breakpoint (%ld, %ld, %ld) = %ld\n",
+                     (unsigned long) type,
+                     (unsigned long) cnt,
+                     (unsigned long) from_tty,
+                     (unsigned long) retval);
+  return retval;
+}
+
+static int
+debug_to_region_size_ok_for_hw_watchpoint (int byte_count)
+{
+  CORE_ADDR retval;
+
+  retval = debug_target.to_region_size_ok_for_hw_watchpoint (byte_count);
+
+  fprintf_unfiltered (gdb_stdlog,
+                     "TARGET_REGION_SIZE_OK_FOR_HW_WATCHPOINT (%ld) = 0x%lx\n",
+                     (unsigned long) byte_count,
+                     (unsigned long) retval);
+  return retval;
+}
+
+static int
+debug_to_stopped_by_watchpoint (void)
+{
+  int retval;
+
+  retval = debug_target.to_stopped_by_watchpoint ();
+
+  fprintf_unfiltered (gdb_stdlog,
+                     "STOPPED_BY_WATCHPOINT () = %ld\n",
+                     (unsigned long) retval);
+  return retval;
+}
+
+static CORE_ADDR
+debug_to_stopped_data_address (void)
+{
+  CORE_ADDR retval;
+
+  retval = debug_target.to_stopped_data_address ();
+
+  fprintf_unfiltered (gdb_stdlog,
+                     "target_stopped_data_address () = 0x%lx\n",
+                     (unsigned long) retval);
+  return retval;
+}
+
+static int
+debug_to_insert_hw_breakpoint (CORE_ADDR addr, char *save)
+{
+  int retval;
+
+  retval = debug_target.to_insert_hw_breakpoint (addr, save);
+
+  fprintf_unfiltered (gdb_stdlog,
+                     "target_insert_hw_breakpoint (0x%lx, xxx) = %ld\n",
+                     (unsigned long) addr,
+                     (unsigned long) retval);
+  return retval;
+}
+
+static int
+debug_to_remove_hw_breakpoint (CORE_ADDR addr, char *save)
+{
+  int retval;
+
+  retval = debug_target.to_remove_hw_breakpoint (addr, save);
+
+  fprintf_unfiltered (gdb_stdlog,
+                     "target_remove_hw_breakpoint (0x%lx, xxx) = %ld\n",
+                     (unsigned long) addr,
+                     (unsigned long) retval);
+  return retval;
+}
+
+static int
+debug_to_insert_watchpoint (CORE_ADDR addr, int len, int type)
+{
+  int retval;
+
+  retval = debug_target.to_insert_watchpoint (addr, len, type);
+
+  fprintf_unfiltered (gdb_stdlog,
+                     "target_insert_watchpoint (0x%lx, %d, %d) = %ld\n",
+                     (unsigned long) addr, len, type, (unsigned long) retval);
+  return retval;
+}
+
+static int
+debug_to_remove_watchpoint (CORE_ADDR addr, int len, int type)
+{
+  int retval;
+
+  retval = debug_target.to_insert_watchpoint (addr, len, type);
+
+  fprintf_unfiltered (gdb_stdlog,
+                     "target_insert_watchpoint (0x%lx, %d, %d) = %ld\n",
+                     (unsigned long) addr, len, type, (unsigned long) retval);
+  return retval;
+}
+
 static void
 debug_to_terminal_init (void)
 {
@@ -1791,6 +1882,14 @@ debug_to_terminal_ours (void)
   fprintf_unfiltered (gdb_stdlog, "target_terminal_ours ()\n");
 }
 
+static void
+debug_to_terminal_save_ours (void)
+{
+  debug_target.to_terminal_save_ours ();
+
+  fprintf_unfiltered (gdb_stdlog, "target_terminal_save_ours ()\n");
+}
+
 static void
 debug_to_terminal_info (char *arg, int from_tty)
 {
@@ -1855,24 +1954,6 @@ debug_to_acknowledge_created_inferior (int pid)
                      pid);
 }
 
-static void
-debug_to_clone_and_follow_inferior (int child_pid, int *followed_child)
-{
-  debug_target.to_clone_and_follow_inferior (child_pid, followed_child);
-
-  fprintf_unfiltered (gdb_stdlog,
-                     "target_clone_and_follow_inferior (%d, %d)\n",
-                     child_pid, *followed_child);
-}
-
-static void
-debug_to_post_follow_inferior_by_clone (void)
-{
-  debug_target.to_post_follow_inferior_by_clone ();
-
-  fprintf_unfiltered (gdb_stdlog, "target_post_follow_inferior_by_clone ()\n");
-}
-
 static int
 debug_to_insert_fork_catchpoint (int pid)
 {
@@ -1926,53 +2007,14 @@ debug_to_remove_vfork_catchpoint (int pid)
 }
 
 static int
-debug_to_has_forked (int pid, int *child_pid)
-{
-  int has_forked;
-
-  has_forked = debug_target.to_has_forked (pid, child_pid);
-
-  fprintf_unfiltered (gdb_stdlog, "target_has_forked (%d, %d) = %d\n",
-                     pid, *child_pid, has_forked);
-
-  return has_forked;
-}
-
-static int
-debug_to_has_vforked (int pid, int *child_pid)
+debug_to_follow_fork (int follow_child)
 {
-  int has_vforked;
+  int retval =  debug_target.to_follow_fork (follow_child);
 
-  has_vforked = debug_target.to_has_vforked (pid, child_pid);
-
-  fprintf_unfiltered (gdb_stdlog, "target_has_vforked (%d, %d) = %d\n",
-                     pid, *child_pid, has_vforked);
-
-  return has_vforked;
-}
-
-static int
-debug_to_can_follow_vfork_prior_to_exec (void)
-{
-  int can_immediately_follow_vfork;
-
-  can_immediately_follow_vfork = debug_target.to_can_follow_vfork_prior_to_exec ();
-
-  fprintf_unfiltered (gdb_stdlog, "target_can_follow_vfork_prior_to_exec () = %d\n",
-                     can_immediately_follow_vfork);
-
-  return can_immediately_follow_vfork;
-}
-
-static void
-debug_to_post_follow_vfork (int parent_pid, int followed_parent, int child_pid,
-                           int followed_child)
-{
-  debug_target.to_post_follow_vfork (parent_pid, followed_parent, child_pid, followed_child);
+  fprintf_unfiltered (gdb_stdlog, "target_follow_fork (%d) = %d\n",
+                     follow_child, retval);
 
-  fprintf_unfiltered (gdb_stdlog,
-                     "target_post_follow_vfork (%d, %d, %d, %d)\n",
-                   parent_pid, followed_parent, child_pid, followed_child);
+  return retval;
 }
 
 static int
@@ -2001,20 +2043,6 @@ debug_to_remove_exec_catchpoint (int pid)
   return retval;
 }
 
-static int
-debug_to_has_execd (int pid, char **execd_pathname)
-{
-  int has_execd;
-
-  has_execd = debug_target.to_has_execd (pid, execd_pathname);
-
-  fprintf_unfiltered (gdb_stdlog, "target_has_execd (%d, %s) = %d\n",
-                     pid, (*execd_pathname ? *execd_pathname : "<NULL>"),
-                     has_execd);
-
-  return has_execd;
-}
-
 static int
 debug_to_reported_exec_events_per_exec_call (void)
 {
@@ -2029,36 +2057,6 @@ debug_to_reported_exec_events_per_exec_call (void)
   return reported_exec_events;
 }
 
-static int
-debug_to_has_syscall_event (int pid, enum target_waitkind *kind,
-                           int *syscall_id)
-{
-  int has_syscall_event;
-  char *kind_spelling = "??";
-
-  has_syscall_event = debug_target.to_has_syscall_event (pid, kind, syscall_id);
-  if (has_syscall_event)
-    {
-      switch (*kind)
-       {
-       case TARGET_WAITKIND_SYSCALL_ENTRY:
-         kind_spelling = "SYSCALL_ENTRY";
-         break;
-       case TARGET_WAITKIND_SYSCALL_RETURN:
-         kind_spelling = "SYSCALL_RETURN";
-         break;
-       default:
-         break;
-       }
-    }
-
-  fprintf_unfiltered (gdb_stdlog,
-                     "target_has_syscall_event (%d, %s, %d) = %d\n",
-                     pid, kind_spelling, *syscall_id, has_syscall_event);
-
-  return has_syscall_event;
-}
-
 static int
 debug_to_has_exited (int pid, int wait_status, int *exit_status)
 {
@@ -2192,9 +2190,8 @@ setup_target_debug (void)
   current_target.to_close = debug_to_close;
   current_target.to_attach = debug_to_attach;
   current_target.to_post_attach = debug_to_post_attach;
-  current_target.to_require_attach = debug_to_require_attach;
   current_target.to_detach = debug_to_detach;
-  current_target.to_require_detach = debug_to_require_detach;
+  current_target.to_disconnect = debug_to_disconnect;
   current_target.to_resume = debug_to_resume;
   current_target.to_wait = debug_to_wait;
   current_target.to_post_wait = debug_to_post_wait;
@@ -2205,10 +2202,19 @@ setup_target_debug (void)
   current_target.to_files_info = debug_to_files_info;
   current_target.to_insert_breakpoint = debug_to_insert_breakpoint;
   current_target.to_remove_breakpoint = debug_to_remove_breakpoint;
+  current_target.to_can_use_hw_breakpoint = debug_to_can_use_hw_breakpoint;
+  current_target.to_insert_hw_breakpoint = debug_to_insert_hw_breakpoint;
+  current_target.to_remove_hw_breakpoint = debug_to_remove_hw_breakpoint;
+  current_target.to_insert_watchpoint = debug_to_insert_watchpoint;
+  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_region_size_ok_for_hw_watchpoint = debug_to_region_size_ok_for_hw_watchpoint;
   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 = 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_kill = debug_to_kill;
   current_target.to_load = debug_to_load;
@@ -2216,21 +2222,14 @@ setup_target_debug (void)
   current_target.to_create_inferior = debug_to_create_inferior;
   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_clone_and_follow_inferior = debug_to_clone_and_follow_inferior;
-  current_target.to_post_follow_inferior_by_clone = debug_to_post_follow_inferior_by_clone;
   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;
   current_target.to_remove_vfork_catchpoint = debug_to_remove_vfork_catchpoint;
-  current_target.to_has_forked = debug_to_has_forked;
-  current_target.to_has_vforked = debug_to_has_vforked;
-  current_target.to_can_follow_vfork_prior_to_exec = debug_to_can_follow_vfork_prior_to_exec;
-  current_target.to_post_follow_vfork = debug_to_post_follow_vfork;
+  current_target.to_follow_fork = debug_to_follow_fork;
   current_target.to_insert_exec_catchpoint = debug_to_insert_exec_catchpoint;
   current_target.to_remove_exec_catchpoint = debug_to_remove_exec_catchpoint;
-  current_target.to_has_execd = debug_to_has_execd;
   current_target.to_reported_exec_events_per_exec_call = debug_to_reported_exec_events_per_exec_call;
-  current_target.to_has_syscall_event = debug_to_has_syscall_event;
   current_target.to_has_exited = debug_to_has_exited;
   current_target.to_mourn_inferior = debug_to_mourn_inferior;
   current_target.to_can_run = debug_to_can_run;
@@ -2283,16 +2282,15 @@ initialize_targets (void)
 When non-zero, target debugging is enabled.", &setdebuglist),
      &showdebuglist);
 
-  add_show_from_set 
-    (add_set_boolean_cmd 
-     ("trust-readonly-sections", class_support, 
-      &trust_readonly, 
-      "Set mode for reading from readonly sections.\n\
+  add_setshow_boolean_cmd ("trust-readonly-sections", class_support, 
+                          &trust_readonly, "\
+Set mode for reading from readonly sections.\n\
 When this mode is on, memory reads from readonly sections (such as .text)\n\
 will be read from the object file instead of from the target.  This will\n\
-result in significant performance improvement for remote targets.",
-      &setlist),
-     &showlist);
+result in significant performance improvement for remote targets.", "\
+Show mode for reading from readonly sections.\n",
+                          NULL, NULL,
+                          &setlist, &showlist);
 
   add_com ("monitor", class_obscure, do_monitor_command,
           "Send a command to the remote monitor (remote targets only).");
This page took 0.037122 seconds and 4 git commands to generate.