Skip to content

Reliable cuda-gdb local/argument inspection: full-debug as a -G build + rich DWARF types - #241

Merged
nihalpasham merged 11 commits into
mainfrom
debug-info-local-inspection
Jun 17, 2026
Merged

nihalpasham merged 11 commits into
mainfrom
debug-info-local-inspection

Conversation

@nihalpasham

Copy link
Copy Markdown
Collaborator

What

Makes CUDA_OXIDE_DEBUG=full cargo oxide debug <example> give reliable
info locals / info args in cuda-gdb
. GPU-verified on an RTX 5090
(sm_120a, cuda-gdb 13.3):

break test_option ; run ; frame 1
info args   -> val = 0,  out = DisjointSlice {ptr: 0x..., len: 1}
info locals -> out_elem = 0x0,  idx = ThreadIndex {raw: 0}
ptype out   -> struct DisjointSlice { ptr: *mut (), len: usize }

Why full-debug is now a -G/-O0 build

dbg.value-based debug info is inherently lossy: a promoted value only has a
machine location while its register is live, which is narrower than the
variable's scope, so an in-scope local reads <optimized out> even at -O0
(confirmed on GPU). Every debug build solves this by keeping locals in memory:
gcc/clang -O0 -g, nvcc -G.

So full now follows that model: skip Pliron mem2reg, skip opt -O2, run
llc -O0, describe locals with llvm.dbg.declare. line-tables stays on the
optimized pipeline (line info survives optimization; locals do not).

The PromotableOpInterface / mir.dbg_value salvage (a port of LLVM's
ConvertDebugDeclareToDebugValue) is kept as groundwork for a future
optimized-debug tier (-O2 -g-style); it just isn't what full uses today.

What's in here

  • full = -G/-O0 tier (reliable in-memory locals)
  • Rich DWARF types: structs/tuples/arrays as DICompositeType with real
    layout offsets
    (honors repr(Rust) reordering); recursive type model
    serialized as one length-prefixed attr blob (unit-tested)
  • Robustness/audit fixes: scope-map cycle guards, dense-id assert,
    undef-salvage guard, combine moved to dev-dependencies
  • scripts/debug-smoketest.sh: GPU-gated cuda-gdb end-to-end test (breakpoint
    binds + info args/info locals show real values); skips cleanly w/o a GPU
  • Docs (book) rewritten to describe the -G model honestly

Deferred (documented)

enums (Option/Result), ABI-split bare &[T] args, closures, projections
(x.0), and the optimized-debug tier itself.

Validation

  • cargo test --workspace green (GPU present); cargo fmt/clippy/cargo doc
    clean
  • scripts/debug-smoketest.sh PASS on sm_120
  • non-debug vecadd unchanged (gating only touches full)

Baseline of the pairing-session work continued from debug-info-cross-file-spans:
- full-debug mode now always runs pliron mem2reg
- MirStoreOp/MirLoadOp PromotableOpInterface salvage promoted slots into
  mir.dbg_value (new dialect-mir op) -> llvm.dbg.value
- rustc source-scope sidecar threaded through so inlined helpers get the
  callee DISubprogram + inlinedAt; cross-file lexical blocks
- cargo oxide debug gains --arch / GPU auto-detect
dbg.value-based debug info is fundamentally lossy: a value is only
inspectable while its register is live, which is far narrower than the
variable's scope. GPU-verified that even at -O0 a plain scalar kernel arg
shows <optimized out> under the promote+dbg.value path.

Full-debug now follows the nvcc -G model so cuda-gdb can read every local
from a stable memory location for its whole scope:
- skip pliron mem2reg (keep source locals in their stack slots)
- skip opt -O2 (slot promotion would collapse live ranges)
- run llc at -O0 (its own mem2reg/SROA would do the same)
- locals/args described by llvm.dbg.declare

The promotion-aware mir.dbg_value salvage stays in place as the mechanism
for a future optimized-debug tier; it is just not what full-debug uses.

GPU-verified on RTX 5090 (sm_120): info args -> val=0, info locals ->
out_elem shown, correct cross-file inlined backtrace.
Audit follow-ups (all principled, no behavior change on the happy path):
- resolve_debug_source_scope / source_scope_depth: only follow strictly
  smaller parent ids, matching rustc's scope-tree invariant and guaranteeing
  termination on a malformed (cyclic) deserialized map instead of overflowing.
- set_debug_source_scope_map: debug_assert scope ids are dense 0..len, so a
  future sparse/reordered producer fails loudly rather than silently
  mislabeling parent/scope links the reader reconstructs by index.
- debug_value_for_promoted_slot: skip salvaging the synthesized undef
  default-def into dbg.value(undef) (keeps the optimized-tier salvage honest).
- mir-lower: move test-only combine dependency to [dev-dependencies].
Aggregate locals/args were previously invisible (only scalars and pointers
had DILocalVariables). Now full-debug describes composites so cuda-gdb can
show their fields.

- DebugLocalTypeKind gains Struct (with DebugTypeMember) and Array variants;
  the whole type tree is serialized into one length-prefixed, escape-safe
  attr blob (replaces the 4 flat type attrs) so nested/odd type names
  round-trip. Unit-tested incl. truncation rejection.
- ensure_debug_type recurses, emitting DICompositeType + DW_TAG_member
  (struct/tuple) and DW_TAG_array_type + DISubrange (arrays).
- The importer builds members from rustc's real layout offsets (honoring
  repr(Rust) field reordering), skipping zero-sized (PhantomData) and
  not-yet-describable members. Enums/unions remain deferred.

GPU-verified on RTX 5090: info args shows
  out = DisjointSlice {ptr: 0x..., len: 1}
info locals shows idx = ThreadIndex {raw: 0}; ptype prints field types.
Drives cuda-gdb in batch mode against a full-debug build and asserts that a
source breakpoint binds, the device PTX JITs, the backtrace is correct, and
info args/locals show real values (scalars, pointers, struct fields). This
validates debugger *consumption* of the emitted DWARF, closing the audit gap
where only IR emission was tested. Skips cleanly (exit 0) without a GPU.
Rewrite the debug-info sections to match the implementation:
- full = -G-style (mem2reg/opt off, locals in memory via dbg.declare); this
  is why locals stay inspectable instead of going <optimized out>.
- document rich-type support (structs/tuples/arrays show their fields) and the
  explicit not-yet list (enums, ABI-split bare slices, closures, projections).
- clarify the mir.dbg_value salvage is groundwork for a future optimized tier,
  not what full uses today.
- note end-to-end validation via scripts/debug-smoketest.sh.
@nihalpasham nihalpasham added debug info Debug information in generated PTX/IR (line/source maps) enhancement New feature or request llvm-export Textual LLVM/NVVM IR exporter (llvm-export crate) IR-lowering Lowering between dialects (dialect-mir to LLVM dialect) codegen Device code-generation pipeline (Rust MIR to IR to PTX) labels Jun 17, 2026
…ection

# Conflicts:
#	crates/llvm-export/src/lib.rs
#	crates/llvm-export/tests/export_test.rs
#	crates/mir-importer/src/pipeline.rs
#	crates/mir-importer/src/translator/body.rs
#	crates/mir-lower/src/convert/ops/memory.rs
#	crates/rustc-codegen-cuda/src/device_codegen.rs
@nihalpasham
nihalpasham merged commit ece628f into main Jun 17, 2026
24 checks passed
@nihalpasham
nihalpasham deleted the debug-info-local-inspection branch June 19, 2026 11:30
meefs pushed a commit to meefs/cuda-oxide that referenced this pull request Sep 30, 2026
* fix: version persisted tuning cache keys

Persist the L2 key encoding alongside each tuning-record digest so key-preimage migrations are distinguishable from workspace drift.

Keep legacy bare-string records wire-compatible and preserve strict verification whenever stored and current keys are comparable.

Signed-off-by: Sam, Joochul Chang <[email protected]>

* test: pin the l2 key preimage to L2_KEY_SCHEMA

The schema bump was enforced by convention only; nothing failed when
the preimage changed, which is exactly how NVIDIA#236 changed every key
without a test noticing. This asserts one exact digest from fixed
inputs, so any preimage change fails loudly with instructions: bump
L2_KEY_SCHEMA, update the digest, extend the schema history.

Signed-off-by: Melih Elibol <[email protected]>

---------

Signed-off-by: Sam, Joochul Chang <[email protected]>
Signed-off-by: Melih Elibol <[email protected]>
Co-authored-by: Melih Elibol <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

codegen Device code-generation pipeline (Rust MIR to IR to PTX) debug info Debug information in generated PTX/IR (line/source maps) enhancement New feature or request IR-lowering Lowering between dialects (dialect-mir to LLVM dialect) llvm-export Textual LLVM/NVVM IR exporter (llvm-export crate)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant