+ fprintf_unfiltered (gdb_stdlog, "target_open (%s, %d)\n", args, from_tty);
+}
+
+void
+target_close (struct target_ops *targ)
+{
+ gdb_assert (!target_is_pushed (targ));
+
+ if (targ->to_xclose != NULL)
+ targ->to_xclose (targ);
+ else if (targ->to_close != NULL)
+ targ->to_close ();
+
+ if (targetdebug)
+ fprintf_unfiltered (gdb_stdlog, "target_close ()\n");
+}
+
+void
+target_attach (char *args, int from_tty)
+{
+ struct target_ops *t;
+
+ for (t = current_target.beneath; t != NULL; t = t->beneath)
+ {
+ if (t->to_attach != NULL)
+ {
+ t->to_attach (t, args, from_tty);
+ if (targetdebug)
+ fprintf_unfiltered (gdb_stdlog, "target_attach (%s, %d)\n",
+ args, from_tty);
+ return;
+ }
+ }
+
+ internal_error (__FILE__, __LINE__,
+ _("could not find a target to attach"));
+}
+
+int
+target_thread_alive (ptid_t ptid)
+{
+ struct target_ops *t;
+
+ for (t = current_target.beneath; t != NULL; t = t->beneath)
+ {
+ if (t->to_thread_alive != NULL)
+ {
+ int retval;
+
+ retval = t->to_thread_alive (t, ptid);
+ if (targetdebug)
+ fprintf_unfiltered (gdb_stdlog, "target_thread_alive (%d) = %d\n",
+ PIDGET (ptid), retval);
+
+ return retval;
+ }
+ }
+
+ return 0;
+}
+
+void
+target_find_new_threads (void)
+{
+ struct target_ops *t;
+
+ for (t = current_target.beneath; t != NULL; t = t->beneath)
+ {
+ if (t->to_find_new_threads != NULL)
+ {
+ t->to_find_new_threads (t);
+ if (targetdebug)
+ fprintf_unfiltered (gdb_stdlog, "target_find_new_threads ()\n");
+
+ return;
+ }
+ }
+}
+
+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)
+{
+ debug_target.to_post_attach (pid);
+
+ fprintf_unfiltered (gdb_stdlog, "target_post_attach (%d)\n", pid);
+}
+
+/* Concatenate ELEM to LIST, a comma separate list, and return the
+ result. The LIST incoming argument is released. */
+
+static char *
+str_comma_list_concat_elem (char *list, const char *elem)
+{
+ if (list == NULL)
+ return xstrdup (elem);
+ else
+ return reconcat (list, list, ", ", elem, (char *) NULL);
+}
+
+/* Helper for target_options_to_string. If OPT is present in
+ TARGET_OPTIONS, append the OPT_STR (string version of OPT) in RET.
+ Returns the new resulting string. OPT is removed from
+ TARGET_OPTIONS. */
+
+static char *
+do_option (int *target_options, char *ret,
+ int opt, char *opt_str)
+{
+ if ((*target_options & opt) != 0)
+ {
+ ret = str_comma_list_concat_elem (ret, opt_str);
+ *target_options &= ~opt;
+ }
+
+ return ret;
+}
+
+char *
+target_options_to_string (int target_options)
+{
+ char *ret = NULL;
+
+#define DO_TARG_OPTION(OPT) \
+ ret = do_option (&target_options, ret, OPT, #OPT)
+
+ DO_TARG_OPTION (TARGET_WNOHANG);
+
+ if (target_options != 0)
+ ret = str_comma_list_concat_elem (ret, "unknown???");
+
+ if (ret == NULL)
+ ret = xstrdup ("");
+ return ret;
+}
+
+static void
+debug_print_register (const char * func,
+ struct regcache *regcache, int regno)
+{
+ struct gdbarch *gdbarch = get_regcache_arch (regcache);
+
+ fprintf_unfiltered (gdb_stdlog, "%s ", func);
+ if (regno >= 0 && regno < gdbarch_num_regs (gdbarch)
+ && gdbarch_register_name (gdbarch, regno) != NULL
+ && gdbarch_register_name (gdbarch, regno)[0] != '\0')
+ fprintf_unfiltered (gdb_stdlog, "(%s)",
+ gdbarch_register_name (gdbarch, regno));
+ else
+ fprintf_unfiltered (gdb_stdlog, "(%d)", regno);
+ if (regno >= 0 && regno < gdbarch_num_regs (gdbarch))
+ {
+ enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
+ int i, size = register_size (gdbarch, regno);
+ gdb_byte buf[MAX_REGISTER_SIZE];
+
+ regcache_raw_collect (regcache, regno, buf);
+ fprintf_unfiltered (gdb_stdlog, " = ");
+ for (i = 0; i < size; i++)
+ {
+ fprintf_unfiltered (gdb_stdlog, "%02x", buf[i]);
+ }
+ if (size <= sizeof (LONGEST))
+ {
+ ULONGEST val = extract_unsigned_integer (buf, size, byte_order);
+
+ fprintf_unfiltered (gdb_stdlog, " %s %s",
+ core_addr_to_string_nz (val), plongest (val));
+ }
+ }
+ fprintf_unfiltered (gdb_stdlog, "\n");
+}
+
+void
+target_fetch_registers (struct regcache *regcache, int regno)
+{
+ struct target_ops *t;
+
+ for (t = current_target.beneath; t != NULL; t = t->beneath)
+ {
+ if (t->to_fetch_registers != NULL)
+ {
+ t->to_fetch_registers (t, regcache, regno);
+ if (targetdebug)
+ debug_print_register ("target_fetch_registers", regcache, regno);
+ return;
+ }
+ }
+}
+
+void
+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)
+ {
+ t->to_store_registers (t, regcache, regno);
+ if (targetdebug)
+ {
+ debug_print_register ("target_store_registers", regcache, regno);
+ }
+ return;
+ }
+ }
+
+ noprocess ();
+}
+
+int
+target_core_of_thread (ptid_t ptid)
+{
+ struct target_ops *t;
+
+ for (t = current_target.beneath; t != NULL; t = t->beneath)
+ {
+ if (t->to_core_of_thread != NULL)
+ {
+ int retval = t->to_core_of_thread (t, ptid);
+
+ if (targetdebug)
+ fprintf_unfiltered (gdb_stdlog,
+ "target_core_of_thread (%d) = %d\n",
+ PIDGET (ptid), retval);
+ return retval;
+ }
+ }
+
+ return -1;
+}
+
+int
+target_verify_memory (const gdb_byte *data, CORE_ADDR memaddr, ULONGEST size)
+{
+ struct target_ops *t;
+
+ for (t = current_target.beneath; t != NULL; t = t->beneath)
+ {
+ if (t->to_verify_memory != NULL)
+ {
+ int retval = t->to_verify_memory (t, data, memaddr, size);
+
+ if (targetdebug)
+ fprintf_unfiltered (gdb_stdlog,
+ "target_verify_memory (%s, %s) = %d\n",
+ paddress (target_gdbarch (), memaddr),
+ pulongest (size),
+ retval);
+ return retval;
+ }
+ }
+
+ 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;
+}
+
+/* See target.h. */
+
+int
+target_supports_btrace (void)
+{
+ struct target_ops *t;
+
+ for (t = current_target.beneath; t != NULL; t = t->beneath)
+ if (t->to_supports_btrace != NULL)
+ return t->to_supports_btrace ();
+
+ return 0;
+}
+
+/* See target.h. */
+
+struct btrace_target_info *
+target_enable_btrace (ptid_t ptid)
+{
+ struct target_ops *t;
+
+ for (t = current_target.beneath; t != NULL; t = t->beneath)
+ if (t->to_enable_btrace != NULL)
+ return t->to_enable_btrace (ptid);
+
+ tcomplain ();
+ return NULL;
+}
+
+/* See target.h. */
+
+void
+target_disable_btrace (struct btrace_target_info *btinfo)
+{
+ struct target_ops *t;
+
+ for (t = current_target.beneath; t != NULL; t = t->beneath)
+ if (t->to_disable_btrace != NULL)
+ return t->to_disable_btrace (btinfo);
+
+ tcomplain ();
+}
+
+/* See target.h. */
+
+void
+target_teardown_btrace (struct btrace_target_info *btinfo)
+{
+ struct target_ops *t;
+
+ for (t = current_target.beneath; t != NULL; t = t->beneath)
+ if (t->to_teardown_btrace != NULL)
+ return t->to_teardown_btrace (btinfo);
+
+ tcomplain ();
+}
+
+/* See target.h. */
+
+VEC (btrace_block_s) *
+target_read_btrace (struct btrace_target_info *btinfo,
+ enum btrace_read_type type)
+{
+ struct target_ops *t;
+
+ for (t = current_target.beneath; t != NULL; t = t->beneath)
+ if (t->to_read_btrace != NULL)
+ return t->to_read_btrace (btinfo, type);
+
+ tcomplain ();
+ return NULL;
+}
+
+/* See target.h. */
+
+void
+target_stop_recording (void)
+{
+ struct target_ops *t;
+
+ for (t = current_target.beneath; t != NULL; t = t->beneath)
+ if (t->to_stop_recording != NULL)
+ {
+ t->to_stop_recording ();
+ return;
+ }
+
+ /* This is optional. */