Skip to content

[libcudacxx] Add debugger pretty-printers for cuda::std::optional - #10843

Closed
theo-bermudez wants to merge 2 commits into
NVIDIA:mainfrom
theo-bermudez:feat/libcudacxx-optional-pretty-printers
Closed

theo-bermudez wants to merge 2 commits into
NVIDIA:mainfrom
theo-bermudez:feat/libcudacxx-optional-pretty-printers

Conversation

@theo-bermudez

Copy link
Copy Markdown
Contributor

Description

Closes #10093.

What

Adds GDB and LLDB pretty-printers for cuda::std::optional, following the pattern
established by the existing array (#10528), tuple (#10534), and span (#10699)
printers. New printers live at libcudacxx/share/libcudacxx/{gdb,lldb}/optional.py,
registered in each __init__.py, with a test scenario under
libcudacxx/test/debugging/optional/.

Correctness note

The disengaged state is rendered without dereferencing the payload storage: both
printers read only the engaged flag (__engaged_) before deciding whether to expose
the contained value. The optional<T&> specialization stores a pointer instead, so it
is detected via its __value_ member and reported disengaged when the pointer is null.
Coverage includes engaged, disengaged, nested optional (engaged and disengaged inner),
a non-trivially-destructible payload, an alias, both engaged and disengaged
optional<int&>, and re-inspection after reset().

Verification

The .expected fixtures were generated by running the real debuggers through the test
harness (run_pretty_printer_test.py --update-expected). Environment: aarch64 Linux
container, CUDA Toolkit 13.3, gdb 15.1, lldb 18.1.3 (no GPU; these scenarios are
host-only).

$ ctest -R 'debugging.*optional' --output-on-failure
Test project /work/build/spike/libcudacxx-cpp17
    Start 139: libcudacxx.test.debugging.optional.lldb
1/2 Test #139: libcudacxx.test.debugging.optional.lldb ...   Passed    0.57 sec
    Start 140: libcudacxx.test.debugging.optional.gdb
2/2 Test #140: libcudacxx.test.debugging.optional.gdb ....   Passed    0.14 sec

100% tests passed, 0 tests failed out of 2
  • The pre-existing array scenario still passes unchanged (ctest -R 'debugging.*array',
    2/2).
  • pre-commit passes on all changed files.
  • The optional.update.before/optional.update.after cases lock the reset() edge in
    regression: after reset() leaves stale payload bytes in __val_, both debuggers
    render the optional as empty rather than surfacing the stale value.

Checklist

  • New or existing tests cover these changes.
  • The documentation is up to date with these changes.

Adds GDB and LLDB pretty-printers for cuda::std::optional, following the
pattern of the existing array, tuple, and span printers (NVIDIA#10528, NVIDIA#10534,
NVIDIA#10699), plus a test scenario under test/debugging/optional.

The disengaged state is rendered without dereferencing the payload storage;
optional<T&> is handled through its pointer member.

Closes NVIDIA#10093.
@theo-bermudez
theo-bermudez requested review from a team as code owners August 16, 2026 06:30
@theo-bermudez
theo-bermudez requested a review from griwes August 16, 2026 06:30
@copy-pr-bot

copy-pr-bot Bot commented Aug 16, 2026

Copy link
Copy Markdown
Contributor

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@github-project-automation github-project-automation Bot moved this to Todo in CCCL Aug 16, 2026
@cccl-authenticator-app cccl-authenticator-app Bot moved this from Todo to In Review in CCCL Aug 16, 2026
@coderabbitai

coderabbitai Bot commented Aug 16, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 58fdc6b2-44ac-421f-a52b-ef0798805a1a

📥 Commits

Reviewing files that changed from the base of the PR and between 4803298 and 958dcd2.

📒 Files selected for processing (1)
  • libcudacxx/share/libcudacxx/gdb/optional.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • libcudacxx/share/libcudacxx/gdb/optional.py

Included review availability: Your plan includes up to 12 reviews per rolling hour; 11 remain after this review.


📝 Walkthrough

Summary by CodeRabbit

  • New Features

    • Added GDB and LLDB pretty-printing support for cuda::std::optional.
    • Debuggers now show whether an optional contains a value and display that value when available.
    • Added support for nested, reference, aliased, non-trivial, and state-updated optionals.
  • Tests

    • Added comprehensive debugging coverage for engaged, disengaged, nested, reference, alias, reset, and non-trivial optional values across GDB and LLDB.

Walkthrough

Changes

Debugger optional support

Layer / File(s) Summary
GDB optional printer
libcudacxx/share/libcudacxx/gdb/optional.py, libcudacxx/share/libcudacxx/gdb/__init__.py
GDB recognizes cuda::std::optional, reports engagement, exposes engaged payloads, and registers the printer.
LLDB optional formatter
libcudacxx/share/libcudacxx/lldb/optional.py, libcudacxx/share/libcudacxx/lldb/__init__.py
LLDB summarizes optional state, exposes engaged payloads, handles reference and union-backed storage, and registers the formatter.
Optional debugger tests
libcudacxx/test/debugging/optional/*, libcudacxx/test/debugging/CMakeLists.txt
The test target covers engaged, disengaged, nested, aliased, reference, non-trivial, and reset-state optionals for GDB and LLDB.

Assessment against linked issues

Objective Addressed Explanation
Create GDB and LLDB pretty printers under the specified paths [#10093] ✅
Add exhaustive tests under libcudacxx/test/debugging/optional [#10093] ✅

Suggested reviewers: griwes

Merge Risk: ⚪ Minimal · up to 958dc

This change adds debugger display support for cuda::std::optional without changing runtime behavior; no actionable merge-blocking risk remains after normal checks and review.


Comment @coderabbitai help to get the list of available commands.

@miscco miscco left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, just one nit regarding detection with our inline ABI namespaces

def _is_cuda_optional(value_type: gdb.Type) -> bool:
value_type = cccl_common.canonical_type(value_type)
template_name = cccl_common.template_name(cccl_common.public_type_name(value_type))
return template_name == "cuda::std::optional"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure whether this works with our inline namespaces

Suggested change
return template_name == "cuda::std::optional"
return (
public_name.startswith("cuda::std::")
and template_name.rsplit("::", 1)[-1] == "optional"
)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch — applied in 958dcd2, mirroring the array/tuple detection pattern. ctest -R 'debugging.*optional' still passes 2/2 and the .expected goldens are unchanged.

Match the array/tuple detection pattern: check the ABI-stripped name
prefix and the last template-name component instead of an exact match,
so detection survives namespace forms the strip pattern doesn't know.
@theo-bermudez

Copy link
Copy Markdown
Contributor Author

Superseded by #10847, which merged the same GDB/LLDB optional pretty-printer support and debugger test coverage. Closing this older duplicate to keep the review queue clear. Thanks for the review here.

@github-project-automation github-project-automation Bot moved this from In Review to Done in CCCL Sep 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

[FEA]: Debugger pretty-printers: cuda::std::optional

2 participants