DWARF expression support for OxCaml LLDB#33
Open
spiessimon wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR lets the OxCaml formatter evaluate DWARF expressions at format time so the compiler can describe layout facts that depend on the value being formatted—most importantly variant payload sizes that vary by active constructor.
Motivation
OxCaml's static type model assumed constant member offsets, constant sizes, and constant strides. That assumption broke down for variants: the formatter previously worked around dynamic allocation sizes with a two-pass estimator that inferred a maximum member end offset from the active variant members. The workaround did not match the compiler's actual layout knowledge, and could not express anything that needed process memory (e.g. a size derived from the OCaml block header).
LLDB already has a fully capable DWARF expression evaluator. The right fix is to keep the relevant
DW_FORM_exprlocattributes around at parse time and evaluate them from the formatter with a live execution context.What changes
DW_AT_byte_size,DW_AT_bit_size,DW_AT_data_member_location, DW_AT_data_bit_offset,DW_AT_count,DW_AT_byte_stride`) are stored as either a constant or a DWARF expression, tagged with the kind of result they produce (scalar bits/bytes/elements, or a location) and the initial-stack convention (empty, or pre-loaded with the object pointer).ExecutionContext, register context, and module. Raw OCaml object addresses are passed alongside so location-valued expressions andDW_OP_push_object_addresswork.DW_FORM_exprlocfor tag-dependent payloads), the two-pass discriminator-sizing workaround is removed. The formatter trusts the size attribute.object_address - WORD_SIZEwhen needed.DW_AT_ocaml_offset_record_from_pointer(0x3106) is deleted along with the pointer-adjustment path. This is an intentional breaking change paired with the OxCaml compiler PR; old binaries that still emit the legacy attribute are not supported.DW_OP_stack_value, or a scalar attribute that returns a memory location) log under the OxCaml formatting category and fall back to the usual formatter error marker rather than fabricating an address.Compatibility
Intentionally breaking with binaries produced by older OxCaml compilers that emit
DW_AT_ocaml_offset_record_from_pointerand the header-relativeDW_AT_data_member_locationconvention. The matching compiler change ships in the OxCaml repo.