From: Tom Tromey <tromey@redhat.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tromey@redhat.com>
Subject: [PATCH 3/4] add to_identity
Date: Fri, 18 Jul 2014 19:45:00 -0000 [thread overview]
Message-ID: <1405711635-1102-4-git-send-email-tromey@redhat.com> (raw)
In-Reply-To: <1405711635-1102-1-git-send-email-tromey@redhat.com>
Right now a target_ops has an odd sense of identity.
Most times some identity is needed, a pointer to a static object is
passed in. For example, calls to unpush_target generally work like
this:
unpush_target (&exec_ops);
Conceptually this is a kind of "instanceof" checking.
Now, consider this with "to_xclose" targets. In this case the
target_ops is allocated on the heap and there's no good way to talk
about the identity. Code could remember the pointer, of course, but
this usually just begs the question.
For example in a to_open implementation it is reasonably normal to
check target_is_pushed and then do nothing if the target is pushed.
However, there's no reasonable way way to do this with a to_xclose
target.
This patch introduces a to_identity field that just points to the
"prototype" implementation of a target_ops. This lets us convert
targets to to_xclose without difficulty.
2014-07-18 Tom Tromey <tromey@redhat.com>
* bfd-target.c (target_bfd_reopen): Set to_identity.
* target.c (complete_target_initialization): Set to_identity.
(unpush_target): Check to_identity. Call target_close on the real
target.
(target_is_pushed): Check to_identity.
* target.h (struct target_ops) <to_identity>: New field.
---
gdb/ChangeLog | 9 +++++++++
gdb/bfd-target.c | 1 +
gdb/target.c | 8 +++++---
gdb/target.h | 6 ++++++
4 files changed, 21 insertions(+), 3 deletions(-)
diff --git a/gdb/bfd-target.c b/gdb/bfd-target.c
index 519d5e7..d392762 100644
--- a/gdb/bfd-target.c
+++ b/gdb/bfd-target.c
@@ -98,6 +98,7 @@ target_bfd_reopen (struct bfd *abfd)
t->to_xclose = target_bfd_xclose;
t->to_data = data;
t->to_magic = OPS_MAGIC;
+ t->to_identity = t;
return t;
}
diff --git a/gdb/target.c b/gdb/target.c
index 3d28f85..6a10c04 100644
--- a/gdb/target.c
+++ b/gdb/target.c
@@ -342,6 +342,8 @@ complete_target_initialization (struct target_ops *t)
gdb_assert (t->to_can_run == NULL || (t->to_can_async_p != NULL
&& t->to_supports_non_stop != NULL));
+ t->to_identity = t;
+
install_delegators (t);
}
@@ -602,7 +604,7 @@ unpush_target (struct target_ops *t)
for (cur = &target_stack; (*cur) != NULL; cur = &(*cur)->beneath)
{
- if ((*cur) == t)
+ if ((*cur) == t || (*cur)->to_identity == t)
break;
}
@@ -621,7 +623,7 @@ unpush_target (struct target_ops *t)
/* Finally close the target. Note we do this after unchaining, so
any target method calls from within the target_close
implementation don't end up in T anymore. */
- target_close (t);
+ target_close (tmp);
return 1;
}
@@ -668,7 +670,7 @@ target_is_pushed (struct target_ops *t)
}
for (cur = target_stack; cur != NULL; cur = cur->beneath)
- if (cur == t)
+ if (cur == t || cur->to_identity == t)
return 1;
return 0;
diff --git a/gdb/target.h b/gdb/target.h
index 92572ff..58c7b30 100644
--- a/gdb/target.h
+++ b/gdb/target.h
@@ -1135,6 +1135,12 @@ struct target_ops
void (*to_done_generating_core) (struct target_ops *)
TARGET_DEFAULT_IGNORE ();
+ /* This points to an "original" target_ops from which a particular
+ instance may have been cloned. This is usedful if a to_xclose
+ target clones some other target_ops, but still wants to call
+ target_is_pushed or unpush_target. */
+ struct target_ops *to_identity;
+
int to_magic;
/* Need sub-structure for target machine related rather than comm related?
*/
--
1.9.3
next prev parent reply other threads:[~2014-07-18 19:27 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-07-18 19:27 [PATCH 0/4] baby step toward multi-target Tom Tromey
2014-07-18 19:27 ` [PATCH 1/4] move core_bfd to program space Tom Tromey
2014-07-18 19:27 ` [PATCH 2/4] simplify target_is_pushed Tom Tromey
2014-07-29 13:22 ` Joel Brobecker
2014-07-29 15:16 ` Tom Tromey
2014-07-18 19:45 ` Tom Tromey [this message]
2014-07-29 14:56 ` [PATCH 3/4] add to_identity Joel Brobecker
2014-07-29 15:11 ` Tom Tromey
2014-07-18 20:44 ` [PATCH 4/4] convert corelow to to_xclose Tom Tromey
2014-07-29 15:11 ` [PATCH 0/4] baby step toward multi-target Pedro Alves
2014-07-29 15:15 ` Tom Tromey
2014-07-29 16:32 ` Pedro Alves
2014-07-29 19:04 ` Tom Tromey
2014-07-29 21:32 ` Doug Evans
2014-08-11 5:54 ` Doug Evans
2014-07-29 15:40 ` Doug Evans
2014-08-10 20:02 ` Doug Evans
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1405711635-1102-4-git-send-email-tromey@redhat.com \
--to=tromey@redhat.com \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox