From 35f46ca676e8e766fe7e384a7d1be89842a713bd Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Fri, 13 Dec 2013 14:16:57 -0700 Subject: [PATCH 09/11] update to_attach --- gdb/target-delegates.c | 10 ++++++++++ gdb/target.c | 21 ++++----------------- gdb/target.h | 3 ++- 3 files changed, 16 insertions(+), 18 deletions(-) diff --git a/gdb/target-delegates.c b/gdb/target-delegates.c index 84429a4..0847d09 100644 --- a/gdb/target-delegates.c +++ b/gdb/target-delegates.c @@ -4,6 +4,13 @@ /* To regenerate this file, run:*/ /* make-target-delegates target.h > target-delegates.c */ static void +delegate_attach (struct target_ops *self, char *arg1, int arg2) +{ + self = self->beneath; + self->to_attach (self, arg1, arg2); +} + +static void delegate_detach (struct target_ops *self, const char *arg1, int arg2) { self = self->beneath; @@ -151,6 +158,8 @@ tdefault_supports_btrace (struct target_ops *self) static void install_delegators (struct target_ops *ops) { + if (ops->to_attach == NULL) + ops->to_attach = delegate_attach; if (ops->to_detach == NULL) ops->to_detach = delegate_detach; if (ops->to_resume == NULL) @@ -182,6 +191,7 @@ install_delegators (struct target_ops *ops) static void install_dummy_methods (struct target_ops *ops) { + ops->to_attach = find_default_attach; ops->to_detach = tdefault_detach; ops->to_resume = tdefault_resume; ops->to_wait = tdefault_wait; diff --git a/gdb/target.c b/gdb/target.c index b6d8c85..a5c5505 100644 --- a/gdb/target.c +++ b/gdb/target.c @@ -3708,7 +3708,6 @@ init_dummy_target (void) dummy_target.to_shortname = "None"; dummy_target.to_longname = "None"; dummy_target.to_doc = ""; - dummy_target.to_attach = find_default_attach; dummy_target.to_create_inferior = find_default_create_inferior; dummy_target.to_supports_non_stop = find_default_supports_non_stop; dummy_target.to_supports_disable_randomization @@ -3755,22 +3754,10 @@ target_close (struct target_ops *targ) 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")); + current_target.to_attach (¤t_target, args, from_tty); + if (targetdebug) + fprintf_unfiltered (gdb_stdlog, "target_attach (%s, %d)\n", + args, from_tty); } int diff --git a/gdb/target.h b/gdb/target.h index 20bb33a..fc53f56 100644 --- a/gdb/target.h +++ b/gdb/target.h @@ -374,7 +374,8 @@ struct target_ops to xfree everything (including the "struct target_ops"). */ void (*to_xclose) (struct target_ops *targ); void (*to_close) (void); - void (*to_attach) (struct target_ops *ops, char *, int); + void (*to_attach) (struct target_ops *ops, char *, int) + TARGET_DEFAULT (find_default_attach); void (*to_post_attach) (int); void (*to_detach) (struct target_ops *ops, const char *, int) TARGET_DEFAULT (target_ignore ()); -- 1.8.1.4