Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lldb can not print Option<i32> #79530

Closed
Tracked by #84
jrmuizel opened this issue Nov 29, 2020 · 12 comments · Fixed by #124458 or #124781
Closed
Tracked by #84

lldb can not print Option<i32> #79530

jrmuizel opened this issue Nov 29, 2020 · 12 comments · Fixed by #124458 or #124781
Labels
A-debuginfo Area: Debugging information in compiled programs (DWARF, PDB, etc.) C-bug Category: This is a bug. O-macos Operating system: macOS T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@jrmuizel
Copy link
Contributor

I tried this code:

{
    let x = Some(4);
    println!("Hello, world! {:?}", x);
}

Trying to print the value of x gives:

(core::option::Option<i32>) $0 = {}

This is with:

lldb-1200.0.41
Apple Swift version 5.3.1 (swiftlang-1200.0.41 clang-1200.0.32.8)

and

rustc 1.49.0-nightly (adef9da30 2020-10-13)
@jrmuizel jrmuizel added the C-bug Category: This is a bug. label Nov 29, 2020
@jyn514 jyn514 added A-debuginfo Area: Debugging information in compiled programs (DWARF, PDB, etc.) O-macos Operating system: macOS labels Nov 30, 2020
@tromey
Copy link
Contributor

tromey commented Dec 16, 2020

This is not a bug in rustc. Instead, this case requires a patch to lldb. The issue is that Option is a discriminated union, so the resulting DWARF looks like:

 <3><ad9>: Abbrev Number: 5 (DW_TAG_structure_type)
    <ada>   DW_AT_name        : (indirect string, offset: 0x876): Option<i32>
    <ade>   DW_AT_byte_size   : 8
    <adf>   DW_AT_alignment   : 4
 <4><ae0>: Abbrev Number: 7 (DW_TAG_variant_part)
    <ae1>   DW_AT_discr       : <0xae5>
...

However, the variant part construct isn't used by C or C++ (I don't know about Swift) and so stock lldb ignores it.

IIRC the rust lldb patches handled this ok. So does gdb:

(gdb) n
4	    println!("Hello, world! {:?}", x);
(gdb) print x
$1 = core::option::Option<i32>::Some(4)

@jrmuizel
Copy link
Contributor Author

@tromey, how hard would it be get an upstreamable fix for lldb out of your rust lldb patches?

@tromey
Copy link
Contributor

tromey commented Jan 21, 2022

@tromey, how hard would it be get an upstreamable fix for lldb out of your rust lldb patches?

Sorry about the extreme delay on this response. I forgot about it. Anyway, it's hard to know the answer. I feel that my track record getting things into upstream lldb is poor, and I don't know if that's due to something I did, or what. Also, this is the kind of work I wouldn't want to do in my spare time.

@davxy
Copy link

davxy commented Oct 8, 2022

@tromey do you know if there has been any progress on this topic? I think that the vscode-lldb guys may propose their patch to the upstream maybe... wdyt?

@VladimirMakaev
Copy link
Contributor

Hi @tromey my employer is making contributions to upstream LLDB and we might be interested to get this fixed upstream as it'll improve our internal debugging experience. Would you be able to point me at the right place where this is fixed in a fork so I can engage with LLDB folks on this. I'm myself not familiar with LLDB codebase so would appreciate any ideas you have on this.

@tromey
Copy link
Contributor

tromey commented Feb 17, 2023

Sorry again for the delay. My changes were all in the rust lldb. I'm sure they are still there in the history somewhere, though I don't know exactly where. I'd imagine they would require some effort to update to the latest lldb. Luckily the patches were not really that large.

@Noratrieb Noratrieb added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Apr 5, 2023
@VladimirMakaev
Copy link
Contributor

I've recently submitted a patch to LLDB to fix Rust enums which has got accepted https://reviews.llvm.org/D149213. If anybody has any feedback on this let me know. I'm planning to do a follow up contribution to synthetic providers in rust-lang

@jgardona
Copy link

jgardona commented Mar 9, 2024

Tested here today with latest version, not working yet.

(lldb) p some
(core::option::Option<i32>)

@VladimirMakaev
Copy link
Contributor

@jgardona What version of LLDB do you have? The fix should be in lldb 18.1+. You won't see this pretty printed though as the synthetic provider was never merged to rust-project. What you should see is all enum variants and their discriminants but that should let you understand what the value is (or allow to write a synth provider to do so)

fmease added a commit to fmease/rust that referenced this issue May 5, 2024
…, r=Mark-Simulacrum

Implement lldb formattter for "clang encoded" enums (LLDB 18.1+)

## Summary:

fixes rust-lang#79530

I landed a fix last year to enable `DW_TAG_variant_part` encoding in LLDBs (https://reviews.llvm.org/D149213). This PR is a corresponding fix in synthetic formatters to decode that information.

This is in no way perfect implementation but at least it improves the status quo. But most types of enums will be visible and debuggable in some way.

I've also updated most of the existing tests that touch enums and re-enabled test cases based on LLDB for enums.

## Test Plan:
ran tests `./x test tests/debuginfo/`. Also tested manually in LLDB CLI and LLDB VSCode

## Other Thoughs:
A better approach would probably be adopting [formatters from codelldb](https://github.com/vadimcn/codelldb/blob/master/formatters/rust.py). There is some neat hack that hooks up summary provider via synthetic provider which can ultimately fix more display issues for Rust types and enums too. But getting it to work well might take more time that I have right now.
@bors bors closed this as completed in 6e146c0 May 5, 2024
@jgardona
Copy link

jgardona commented May 5, 2024

@jgardona What version of LLDB do you have? The fix should be in lldb 18.1+. You won't see this pretty printed though as the synthetic provider was never merged to rust-project. What you should see is all enum variants and their discriminants but that should let you understand what the value is (or allow to write a synth provider to do so)

Hello. Sorry fro delay this message.
I'll install the lldb and do some tests again. I'll return as get it done.

@jgardona
Copy link

jgardona commented May 5, 2024

@jgardona What version of LLDB do you have? The fix should be in lldb 18.1+. You won't see this pretty printed though as the synthetic provider was never merged to rust-project. What you should see is all enum variants and their discriminants but that should let you understand what the value is (or allow to write a synth provider to do so)

It worked. This is way better as we can see data inside and understand what it is.
Thank you 👍

image

image

@VladimirMakaev
Copy link
Contributor

It’ll get nicer with the next release of rust compiler when you use ‘rust-lldb’ script. The new synthetic provider has just been merged in yesterday.

fmease added a commit to fmease/rust that referenced this issue May 5, 2024
…, r=Mark-Simulacrum

Implement lldb formattter for "clang encoded" enums (LLDB 18.1+) (v2)

This PR is identical to rust-lang#124458, which was approved and merged but then removed from master by a force-push due to a [CI bug](https://rust-lang.zulipchat.com/#narrow/stream/242791-t-infra/topic/ci.20broken.3F).

Original PR description:

---

## Summary:

fixes rust-lang#79530

I landed a fix last year to enable `DW_TAG_variant_part` encoding in LLDBs (https://reviews.llvm.org/D149213). This PR is a corresponding fix in synthetic formatters to decode that information.

This is in no way perfect implementation but at least it improves the status quo. But most types of enums will be visible and debuggable in some way.

I've also updated most of the existing tests that touch enums and re-enabled test cases based on LLDB for enums.

## Test Plan:
ran tests `./x test tests/debuginfo/`. Also tested manually in LLDB CLI and LLDB VSCode

## Other Thoughs:
A better approach would probably be adopting [formatters from codelldb](https://github.com/vadimcn/codelldb/blob/master/formatters/rust.py). There is some neat hack that hooks up summary provider via synthetic provider which can ultimately fix more display issues for Rust types and enums too. But getting it to work well might take more time that I have right now.
bors added a commit to rust-lang-ci/rust that referenced this issue May 7, 2024
…r=dtolnay

Implement lldb formatter for "clang encoded" enums (LLDB 18.1+) (V3)

This is a redo of PR (rust-lang#124458) which was approved previously but force-pushed out. Then a V2 (rust-lang#124745) failed `debuginfo\msvc-pretty-enums.rs` test during merge.

I've fixed the test and checked it to pass on Windows with `.\x.ps1 test .\tests\debuginfo\msvc-pretty-enums.rs`

Below is the original summary:

## Summary:

fixes rust-lang#79530

I landed a fix last year to enable `DW_TAG_variant_part` encoding in LLDBs (https://reviews.llvm.org/D149213). This PR is a corresponding fix in synthetic formatters to decode that information.

This is in no way perfect implementation but at least it improves the status quo. But most types of enums will be visible and debuggable in some way.

I've also updated most of the existing tests that touch enums and re-enabled test cases based on LLDB for enums.

## Test Plan:
ran tests `./x test tests/debuginfo/`. Also tested manually in LLDB CLI and LLDB VSCode

## Other Thoughs:
A better approach would probably be adopting [formatters from codelldb](https://github.com/vadimcn/codelldb/blob/master/formatters/rust.py). There is some neat hack that hooks up summary provider via synthetic provider which can ultimately fix more display issues for Rust types and enums too. But getting it to work well might take more time that I have right now.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-debuginfo Area: Debugging information in compiled programs (DWARF, PDB, etc.) C-bug Category: This is a bug. O-macos Operating system: macOS T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
7 participants