Re: [PATCH v4 3/9] add target method delegation

Tom Tromey
2013-12-12T02:46:28Z

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