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

Improve MSVC debug info for f16 and f128 #121837

Open
tgross35 opened this issue Mar 1, 2024 · 3 comments
Open

Improve MSVC debug info for f16 and f128 #121837

tgross35 opened this issue Mar 1, 2024 · 3 comments
Labels
A-debuginfo Area: Debugging information in compiled programs (DWARF, PDB, etc.) E-hard Call for participation: Hard difficulty. Experience needed to fix: A lot. E-needs-investigation Call for partcipation: This issues needs some investigation to determine current status F-f16_and_f128 `#![feature(f16)]`, `#![feature(f128)]` O-windows-msvc Toolchain: MSVC, Operating system: Windows T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. WG-debugging Working group: Bad Rust debugging experiences

Comments

@tgross35
Copy link
Contributor

tgross35 commented Mar 1, 2024

The code at

impl MsvcBasicName for ty::FloatTy {
fn msvc_basic_name(self) -> &'static str {
// FIXME: f16 and f128 have no MSVE representation. We could improve the debuginfo.
// See: <https://github.com/rust-lang/rust/pull/114607/files#r1454683264>
match self {
ty::FloatTy::F16 => "half",
ty::FloatTy::F32 => "float",
ty::FloatTy::F64 => "double",
ty::FloatTy::F128 => "fp128",
}
}
}
produces a debug representation for MSVC, which could be improved. Quoting from @MaulingMonkey in https://github.com/rust-lang/rust/pull/114607/files#r1454683264:

Not sure if proper support is possible here without bugging Microsoft. Even if it is possible, Microsoft hasn't bothered for their own SDK types (e.g. _FLOAT128 can be found in the windows SDK, but it's just a struct around a couple of u64s and has no useful debug visualizers.)

If it were possible:

* Emit debug info for a `u16`/`u128`-wrapping structure (I'm fuzzy on the details here, I've only wrapped existing emitted types rather than emitting my own.  Merely defining an unused std type might not be enough as such types will get culled IME?)

* Write/extend a `*.natvis` file (probably [rust/src/etc/natvis/intrinsics.natvis](https://github.com/rust-lang/rust/blob/6bf600bc98879bf1bf2ab0f3b3b37c965f5bdff6/src/etc/natvis/intrinsic.natvis)?) that unpacks the bits and reconstitutes them as an approximate double or float in it's `<DisplayString>`.
  
  * How do you transmute/type-pun from `u64` → `f64` in the subset of C++ allowed by the debugger (no pointer-to-temporary shenannigans)?  _Maybe_ abuse a union somehow...?
  * See [`natvis-pdbs` Recommended Reading](https://crates.io/crates/natvis-pdbs#recommended-reading)
  * If you added a new `*.nativs` file for some reason, make sure it's referenced properly (see e.g. [rust/src/bootstrap/src/core/build_steps/dist.rs](https://github.com/rust-lang/rust/blob/master/src/bootstrap/src/core/build_steps/dist.rs#L535-L538)
  * Consider unit tests like [tests/debuginfo/pretty-std-collections-hash.rs](https://github.com/rust-lang/rust/blob/6bf600bc98879bf1bf2ab0f3b3b37c965f5bdff6/tests/debuginfo/pretty-std-collections-hash.rs#L1)

(It's possible to call _CrtCheckMemory() from a watch window. I forget if this works in a *.natvis visualizer. If so, you could theoretically author F128toApproxF64(high: u64, low: u64) and stuff it in a DLL? Or better yet, let someone more foolish take the time to go down that rabbit hole and shave that yak...)

@rustbot label +F-f16_and_f128

@rustbot rustbot added needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. F-f16_and_f128 `#![feature(f16)]`, `#![feature(f128)]` labels Mar 1, 2024
@tgross35
Copy link
Contributor Author

tgross35 commented Mar 1, 2024

@rustbot label +A-debuginfo +O-windows-msvc +T-compiler -needs-triage +E-easy

@rustbot

This comment has been minimized.

@rustbot rustbot added A-debuginfo Area: Debugging information in compiled programs (DWARF, PDB, etc.) O-windows-msvc Toolchain: MSVC, Operating system: Windows T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Mar 1, 2024
@rustbot rustbot added the E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. label May 16, 2024
bors added a commit to rust-lang-ci/rust that referenced this issue Jul 5, 2024
…rister

Add Natvis visualiser and debuginfo tests for `f16`

To render `f16`s in debuggers on MSVC targets, this PR changes the compiler to output `f16`s as `struct f16 { bits: u16 }`, and includes a Natvis visualiser that manually converts the `f16`'s bits to a `float` which is can then be displayed by debuggers. `gdb`, `lldb` and `cdb` tests are also included for `f16` .

`f16`/`f128` MSVC debug info issue: rust-lang#121837
Tracking issue: rust-lang#116909
bors added a commit to rust-lang-ci/rust that referenced this issue Jul 8, 2024
…rister

Add Natvis visualiser and debuginfo tests for `f16`

To render `f16`s in debuggers on MSVC targets, this PR changes the compiler to output `f16`s as `struct f16 { bits: u16 }`, and includes a Natvis visualiser that manually converts the `f16`'s bits to a `float` which is can then be displayed by debuggers. `gdb`, `lldb` and `cdb` tests are also included for `f16` .

`f16`/`f128` MSVC debug info issue: rust-lang#121837
Tracking issue: rust-lang#116909
bors added a commit to rust-lang-ci/rust that referenced this issue Jul 8, 2024
…rister

Add Natvis visualiser and debuginfo tests for `f16`

To render `f16`s in debuggers on MSVC targets, this PR changes the compiler to output `f16`s as `struct f16 { bits: u16 }`, and includes a Natvis visualiser that manually converts the `f16`'s bits to a `float` which is can then be displayed by debuggers. `gdb`, `lldb` and `cdb` tests are also included for `f16` .

`f16`/`f128` MSVC debug info issue: rust-lang#121837
Tracking issue: rust-lang#116909
bors added a commit to rust-lang-ci/rust that referenced this issue Jul 9, 2024
…rister

Add Natvis visualiser and debuginfo tests for `f16`

To render `f16`s in debuggers on MSVC targets, this PR changes the compiler to output `f16`s as `struct f16 { bits: u16 }`, and includes a Natvis visualiser that manually converts the `f16`'s bits to a `float` which is can then be displayed by debuggers. `gdb`, `lldb` and `cdb` tests are also included for `f16` .

`f16`/`f128` MSVC debug info issue: rust-lang#121837
Tracking issue: rust-lang#116909
bors added a commit to rust-lang-ci/rust that referenced this issue Jul 9, 2024
…rister

Add Natvis visualiser and debuginfo tests for `f16`

To render `f16`s in debuggers on MSVC targets, this PR changes the compiler to output `f16`s as `struct f16 { bits: u16 }`, and includes a Natvis visualiser that manually converts the `f16`'s bits to a `float` which is can then be displayed by debuggers. `gdb`, `lldb` and `cdb` tests are also included for `f16` .

`f16`/`f128` MSVC debug info issue: rust-lang#121837
Tracking issue: rust-lang#116909
@ismailarilik
Copy link
Contributor

Or better yet, let someone more foolish take the time to go down that rabbit hole and shave that yak...

Well, how can that be easy? =)

I saw a few issues which seems not easy. I think we should define what is "easy".

@jieyouxu jieyouxu added E-hard Call for participation: Hard difficulty. Experience needed to fix: A lot. E-needs-investigation Call for partcipation: This issues needs some investigation to determine current status and removed E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. labels Oct 30, 2024
@jieyouxu jieyouxu added the WG-debugging Working group: Bad Rust debugging experiences label Dec 23, 2024
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.) E-hard Call for participation: Hard difficulty. Experience needed to fix: A lot. E-needs-investigation Call for partcipation: This issues needs some investigation to determine current status F-f16_and_f128 `#![feature(f16)]`, `#![feature(f128)]` O-windows-msvc Toolchain: MSVC, Operating system: Windows T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. WG-debugging Working group: Bad Rust debugging experiences
Projects
None yet
Development

No branches or pull requests

4 participants