This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [PATCH v4 3/9] add target method delegation
- From: Tom Tromey <tromey at redhat dot com>
- To: Pedro Alves <palves at redhat dot com>
- Cc: gdb-patches at sourceware dot org
- Date: Wed, 11 Dec 2013 19:46:23 -0700
- Subject: Re: [PATCH v4 3/9] add target method delegation
- Authentication-results: sourceware.org; auth=none
- References: <1382464769-2465-1-git-send-email-tromey at redhat dot com> <1382464769-2465-4-git-send-email-tromey at redhat dot com> <526E8B54 dot 8040104 at redhat dot com> <87eh75cmig dot fsf at fleche dot redhat dot com> <87a9htcme3 dot fsf at fleche dot redhat dot com> <87habz7q6g dot fsf at fleche dot redhat dot com> <527D1A84 dot 9040106 at redhat dot com> <87lhzr11wz dot fsf at fleche dot redhat dot com>
Pedro> target_wait would then be:
Tom> [...]
Pedro> WDYT?
Tom> It seems good to me.
I tinkered with this a little and, not liking the result much, spent
some more time thinking about it. Specifically, I considered how I
would write this in C++.
There I think what I would do is have a pure-virtual target base class.
This corresponds to target_ops.
Then, I'd have a "delegator" subclass from which all ordinary targets
would derive. This class would implement each delegatable method by
unconditionally forwarding to "beneath":
struct target_delegator : public target_ops {
// e.g.
int has_all_memory () {
return beneath->has_all_memory();
}
};
I'd make the dummy target implement all methods using some baseline
behavior.
struct dummy_target : public target_ops {
int has_all_memory () {
return 0;
}
};
Finally, individual targets would derive from target_delegator and
override methods as appropriate.
Translating back to gdb, rather than implement target_delegate_*
functions that search through the target stack, what if we implement the
appropriate dummy fallback functions, and have delegation functions that
call via "beneath"? We can fill in the fields of target_ops in
complete_target_initialization.
Since this is very repetitive I would consider doing it via a ".defs"
file and then some macrology to reduce the amount of boilerplate.
Let me know what you think. I'll experiment with it a bit tomorrow.
Tom