[PATCH] Make BLOCK_START and BLOCK_END into rvalues

Simon Marchi simark@simark.ca
Sun May 17 14:40:04 GMT 2020


On 2020-05-17 10:05 a.m., Tom Tromey wrote:
> Simon> This is similar to what I'm doing to struct type, so it would be nice to agree
> Simon> on the way forward for all these structures, and change them in a consistent
> Simon> manner.
> 
> Makes sense.
> 
> Simon> Since you are changing the places that modify the field values, I'd suggest
> Simon> adding the setter right away, it's a step in the right direction.
> 
> Simon> And I'd suggest adding the getter too, changing the BLOCK_START macro to use
> Simon> it, it shouldn't be much more work.  And it will achieve the goal of making
> Simon> the macro yield an rvalue.
> 
> I wasn't sure whether setters and getters would provide any real value.
> Aside from some maybe-future idea of changing the getter, in other
> situations they are just wrappers for the field.

It's true that simply wrapping a field with a getter / setter may not appear valuable.
I think it is somewhat valuable to be able to put a breakpoint on the setter.  If you
are wondering where some block with a given start address is created, you can put a
conditional breakpoint on the setter.  And to avoid the field being changed behind the
back of that setter, then that field must be private (ideally) and a getter becomes
necessary as well.

I also like getter / setters because they allow adding assertions to make sure things
are in a coherent state.

> For struct type, maybe it makes more sense, because one (very-)
> long-term idea there would be to split up struct main_type into an
> inheritance hierarchy, so that each type can be more obviously
> type-safe, and also carry just the data it needs.
> 
> I don't mind making the change -- it's easy enough to do.

As you wish :)

Simon



More information about the Gdb-patches mailing list