Skip to content

Support composite debug variable fragments #1086

Closed

Description

@uurl

Part of #226

Summary

Full device debug metadata currently supports whole variables and several statically projected variable locations, but rustc MIR composite debug information is still discarded.

Rustc may represent a source variable as multiple scalarized fragments. Each fragment corresponds to a bit range of the original source variable and must be associated with the same source-level DILocalVariable.

LLVM represents this using DW_OP_LLVM_fragment in the debug expression.

For example, a source aggregate scalarized into two SSA-backed pieces can be described as:

llvm.dbg.value(
    metadata <value0>,
    metadata !<variable>,
    metadata !DIExpression(DW_OP_LLVM_fragment, 0, 32)
)

llvm.dbg.value(
    metadata <value1>,
    metadata !<variable>,
    metadata !DIExpression(DW_OP_LLVM_fragment, 32, 32)
)

Motivation

The MIR importer currently skips VarDebugInfo entries with composite fragment metadata.

This prevents the debug pipeline from representing source variables that rustc has scalarized into multiple pieces and is one of the blockers for eventually removing the full-debug -Zmir-opt-level=0 workaround.

Supporting fragments requires preserving:

  • the identity of the complete source variable
  • the fragment bit offset
  • the fragment bit size
  • source scope and declaration information

through MIR import, lowering, mem2reg debug salvage, and LLVM export.

Proposed scope

  • import supported rustc MIR composite debug fragments
  • preserve fragment metadata on MIR debug-local storage
  • preserve fragment metadata through MIR-to-LLVM lowering
  • preserve fragment metadata when mem2reg converts storage-based debug info to mir.dbg_value
  • emit DW_OP_LLVM_fragment for fragment-aware llvm.dbg.declare
  • emit DW_OP_LLVM_fragment for fragment-aware llvm.dbg.value
  • ensure multiple fragments of the same source variable share one DILocalVariable
  • add focused LLVM-export and MIR-lowering coverage
  • validate emitted LLVM IR with llvm-as where available

Non-goals

This issue does not:

  • remove the full-debug -Zmir-opt-level=0 workaround
  • enable Pliron mem2reg in full-debug mode
  • enable LLVM opt -O2 in full-debug mode
  • add runtime ProjectionElem::Index debug locations
  • add slice, subslice, or fat-pointer fragment reconstruction
  • introduce a new optimized-debug mode

Those remain separate follow-up work.

Acceptance criteria

  • supported rustc composite debug entries are no longer discarded
  • fragment offset and size survive MIR import and lowering
  • mem2reg debug salvage preserves fragment metadata
  • LLVM export emits DW_OP_LLVM_fragment
  • fragment dbg.declare IR parses successfully with llvm-as
  • fragment-aware dbg.value remains supported by the existing debug pipeline
  • existing debug behavior remains unchanged for non-fragment variables
  • relevant tests, workspace check, formatting, and Clippy remain green
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions