[PATCH v2 2/3] [gdb] Add gdbarch_dwarf2_reg_piece_offset hook

Andreas Arnez arnez@linux.ibm.com
Wed Jan 15 18:27:30 GMT 2025


On Tue, Jan 14 2025, Tom Tromey wrote:

>>>>>> "Andreas" == Andreas Arnez <arnez@linux.ibm.com> writes:
> Andreas> Do you know any technical reason to distinguish the two cases?
>
> I think it's just that DWARF explicitly says that one of them is ABI-defined.

OK, I appreciate that.  I wouldn't consider this a technical reason,
though.

> It seems kind of bad to me to ignore the language of the standard when
> it's more clear and follow it when it is less clear.  Normally we have
> the opposite problem, where specs and standards are vague and then
> compilers all do weird & different things... when the spec is clear it
> seems better to just accept it.

Generally I agree.  However, in this particular case the definition is
unclear and inconsistent, and it's causing trouble for the
implementation.

> For clarity the bit piece part says:
>
>     If the location is a register, the offset is from the least
>     significant bit end of the register.
>
> ... which doesn't really seem ambiguous at all.

Actually, yes it does.  Let's consider two aspects of the wording here:
bit significance, and "end".

Significance: The significance of bits is well-defined for integers, and
per extension, for any register that holds a fixed-size integer.  But
how would you define bit significance for a vector register?

"End": If the standard talks about an "end", it obviously refers to a
fixed bit position.  One that is shared among all instances of the
register, independent of the register's specific size at run-time.  The
architecture often implies such an "end", which could also be viewed as
the register being "left-aligned" or "right-aligned".  But that
architectural "end" doesn't necessarily qualify as "LSB" in any way.

Considering these aspects, I'd say that the term "LSB end" is
ill-defined.

> If DWARF is "bad" here, like it would work better some other way, then I
> think it would be better to fix this in DWARF somehow than to have
> compilers have a separate agreement to ignore the text.

I'd prefer that as well.  Thus I tried to convey the issue to the DWARF
committee several years ago, unsuccessfully.  If anyone else wants to
try again, I'm all for it.

The s390x ABI fills the current standardization gap for s390x and
defines the placement of DWARF register pieces on its own.  In
particular it replaces the ill-defined term "LSB end" with a rule that
depends on the register type and maintains consistency between bit and
byte pieces.  I'd prefer to follow this definition.

(P.S.: Tom, perhaps you remember that I talked about this topic at
FOSDEM'18.  There I explained the issues with the standard's wording and
mentioned that I had tried addressing them to the DWARF committee.  The
talk also covered the fact that DWARF bit piece handling had been broken
for the longest time due to lots of issues in GDB.  These issues had
gone fairly unnoticed because the compilers rarely emit bit pieces.
Which may explain why the issues with the DWARF definition went under
the radar for quite some time as well.)

-- 
Andreas


More information about the Gdb-patches mailing list