[Dwarf-discuss] Idea/Question: Add DW_AT_LowerBound to DW_TAG_String
Martin
lists@mfriebe.de
Fri Apr 24 10:16:55 GMT 2026
Thanks for the reply.
I just double check something though... ZEROBASEDSTRINGS is actually not
part of the type, but only govern how data of the type is accessed,
while the directive is in use.
Then the question would be a flag for scopes (more at the end of the mail).
E.g. the compilation unit, since the inclusion of 3rd party code could
mix code with different settings.
However, this would be a really really minor issue. In most cases it
could be a global configuration of the debugger.
I answer your questions anyway, even though they may be mood. (sorry)
Btw, a 2nd question. Just to confirm.
DW_AT_string_length is in "elements" That is if the base type is a char
of size "2 bytes", then length is in "chars" and not in "bytes"?
This matters because FreePascal stores some length for 16bit string as
size in bytes (but DWARF can handle that as location expression doing
"div 2")
On 20/04/2026 21:29, Cary Coutant wrote:
> You mean DW_TAG_string_type, right?
Yes
> It may not be quite as obvious as it sounds, though: DW_AT_lower_bound
> is currently defined only for subrange types (DW_TAG_generic_subrange
> and DW_TAG_subrange_type), which are used to define the bounds of each
> dimension of an array. Since strings are inherently one-dimensional, the
> use of one or more subrange tags as children of DW_TAG_string_type seems
> unnecessary (unless anyone is thinking of proposing multi-dimensional
> strings!).
Well, a single dimension array also has ONE DW_AT_lower_bound. IMHO a
string is very similar to a single dimension array. The alternative
would have been a new attribute.
The advantage of DW_AT_lower_bound is that it could deal with any number
as base. I can't see anything but 0 or 1 to be ever happen, but never
say never.
> What about DW_AT_upper_bound? For string types, we have
> DW_AT_string_length, et al., but providing lower and upper bounds would
> be an alternate way to represent the string length. The argument for
> this is not as strong: if you replace DW_AT_string_length with
> DW_AT_upper_bound, you risk breaking some consumers.
I don't think it even needs DW_AT_upper_bound.
Arrays can have: DW_AT_lower_bound + DW_AT_count
Strings would have: DW_AT_lower_bound + DW_AT_string_length
Though of course (never say never), someone else may think it handy to
specify it as lower/upper.
> If you like, I'll file this as a new proposal (without upper bound).
Not sure if still needed.
Where would be you stance on having a flag in the compilation unit?
Though, the flag can actually change in the middle of a procedure.
However I see no need to flag that.
I am not even sure about the compilation unit.
Because for a user then must change their watched expressions, every
time the scope changes. (This isn't Dwarf related, rather an
implementation matter of debuggers)
i.e. watching the first char in a global variable, would need a
different expression depending on the settings of the current scope.
So for now, I would retract the request (for my own needs).
>
> With respect to ref counts, I'd like to see a more fleshed-out proposal
> with some background about how it could be useful to a consumer.
>
Will do.
More information about the Dwarf-discuss
mailing list