[Dwarf-discuss] Discussion: string encoding as part of the type (Pascal)
Cary Coutant
ccoutant@gmail.com
Mon Apr 27 17:59:27 GMT 2026
>
> In Pascal (free pascal) the string type (some of them) have an internal
> field (not accessible to user code) that stores the encoding.
>
> That can be an ASCII-page, or utf8, or raw (just bytes as they are)....
>
> For a debugger this info is useful to display the string correctly. A
> debugger would want to convert the string to the encoding used by the
> terminal before printing it).
>
> I am looking for ways how that could be encoded in DWARF?
>
> The first step would be e.g. some attributes to describe the location
> and size of that field.
>
For this, I'd look to the DW_AT_string_length,
DW_AT_string_length_byte_size/_bit_size attributes as a model. You could
add DW_AT_string_encoding which would take a location expression (with an
implicit push object address) that yields the location of the encoding
field, and DW_AT_string_encoding_{byte|bit}_size attributes that give the
size of that field in your internal string representation.
The 2nd part would be a mapping of the values in that field.
>
> That 2nd part may not need to be part of the encoded DWARF description.
> It could be just per language defaults (a debugger would have to know
> the values that each compiler may use).
> I.e. I am not sure, but this may be compiler rather than language
> dependent.
>
> Optional, compliers could add a global list of mapping to pre-defined
> DWARF constants.
> That would be some form of list with pairs of
> - "compiler encoding value"
> - DWARF constant
>
>
> This may affect the encoding used in the base type for the char.
>
If different compilers use different constants, you'd have a compatibility
problem. On the other hand, if this is a language extension, then maybe you
don't expect it to be interoperable across different compilers (and indeed
the internal structures of the string type may differ as well).
I'd be tempted to leave this as a job for the debugger, but if you wanted
to try to map the compiler's encoding values onto DWARF encoding constants
(DW_ATE_*), you could have a DW_TAG_string_encoding_map DIE in the
compilation unit. This could either take a single attribute with a
block-form value containing your list of pairs, or it could have multiple
children, each with two attributes that give the compiler's encoding value
and the equivalent DW_ATE_ constant, respectively.
The DW_TAG_string_type DIE has a DW_AT_type attribute that gives the type
and encoding of the characters in the string. For strings where the
encoding is dynamic, you might also want to invent a new DW_ATE_dynamic or
DW_ATE_none encoding value, or use DW_ATE_unsigned_char, or just omit the
DW_AT_type altogether.
If this is a compiler extension, I'd suggest you use DWARF extensions for
this information. If it's part of the language standard, feel free to
follow up with a proposal along these lines.
-cary
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.dwarfstd.org/pipermail/dwarf-discuss/attachments/20260427/eefeedba/attachment.htm>
More information about the Dwarf-discuss
mailing list