-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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
[Debuginfo] Add MSVC Synthetic and Summary providers to LLDB #135354
base: master
Are you sure you want to change the base?
Conversation
rustbot has assigned @Mark-Simulacrum. Use |
Hmm, I was originally going to separate it out, but I think I can squeeze the |
(cc @wesleywiser: maybe you could take a look if you have the bandwidth and are willing?) |
src/etc/lldb_providers.py
Outdated
@@ -127,6 +131,25 @@ def has_children(self) -> bool: | |||
return False | |||
|
|||
|
|||
def get_template_args(type_name: str) -> List[str]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we add a comment on this function (or maybe we have unit tests for this code?) that could check that this is doing what it wants to?
Checking locally, it looks like this is specifically getting the top-level generic (nit: maybe rename the function? Templates aren't really what Rust calls this) arguments.
print(get_template_args("Foo<Bar>")) # = ['Bar']
print(get_template_args("Foo<Bar<A, B>>")) # = ['Bar<A, B>']
print(get_template_args("Foo<Bar<A<A1, A2>, B>>")) # = ['Bar<A<A1, A2>, B>']
print(get_template_args("Foo<Bar<A<A1, A2>, B>, Baz1, Baz2>")) # ['Bar<A<A1, A2>, B>', 'Baz1', 'Baz2']
I think that's probably reasonable for what we need this function for -- it looks like we actually only ever look at the 0th argument -- but it's also at least IMO not intuitive from glancing at the code that this is the result, so seems like a comment would be worthwhile.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For sure. The rationale for the name mostly comes down to "that's what LLDB calls it", as it's ~a replacement for SBType.template_args (which always fails on MSVC for whatever reason. IIRC the information does exist in the PDB, LLDB just doesn't care. I'm sure it's fixable on their end, but afaik that's gonna be a lot of effort).
Returning a list will be useful for fixing up the type name output (once i get around to that), since it'll need to recursively format the generic args. Grabbing only the first level should mean I can look up the full type via target.FindFirstType()
and call .GetDisplayTypeName()
to leverage any existing SyntheticProvider.get_type_name()
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is really nice work! Is it possible we can get some unit tests for the various providers in the PR so we can prevent them from breaking in the future?
These should be caught by the existing tests - e.g. the vec test expects lldb to output the elements, whereas without the synthetic it outputs a raw pointer to bytes. CI doesn't catch it right now because it only runs the tests for |
Gotcha! I won't hold up merging this improvement for that then. Thank you again! @bors r+ |
[Debuginfo] Add MSVC Synthetic and Summary providers to LLDB Adds handling for `tuple$<>`, `ref$<slice$2<>`, `ref$<str$>` and `enum2$<>`. Also fixes a bug in MSVC vec/string handling where the script was unable to determine the element's type due to LLDB ignoring template arg debug information <details> <summary>Sample code</summary> ```rust pub enum Number { One = 57, Two = 99, } #[repr(u8)] pub enum Container { First(u32), Second { val: u64, val2: i8 }, Third, } ... let u8_val = b'a'; let float = 42.78000000000001; let tuple = (u8_val, float); let str_val = "eef"; let mut string = "freef".to_owned(); let mut_str = string.as_mut_str(); let array: [u8; 4] = [1, 2, 3, 4]; let ref_array = array.as_slice(); let mut array2: [u32; 4] = [1, 2, 3, 4]; let mut_array = array2.as_mut_slice(); let enum_val = Number::One; let mut enum_val2 = Number::Two; let sum_val = Container::First(15); let sum_val_2 = Container::Second { val: 0, val2: 0 }; let sum_val_3 = Container::Third; let non_zero = NonZeroU128::new(100).unwrap(); let large_discr = NonZeroU128::new(255); ``` </details> Before: ![image](https://github.com/user-attachments/assets/19fd0881-a4c3-4c68-b28f-769a67d95e35) After: ![image](https://github.com/user-attachments/assets/d0479035-17ed-4584-8eb4-71d1314f8f7c)
…iaskrgr Rollup of 8 pull requests Successful merges: - rust-lang#134367 (Stabilize `feature(trait_upcasting)`) - rust-lang#135354 ([Debuginfo] Add MSVC Synthetic and Summary providers to LLDB) - rust-lang#135940 (Update toolstate maintainers) - rust-lang#135945 (Remove some unnecessary parens in `assert!` conditions) - rust-lang#136577 (Pattern Migration 2024: try to suggest eliding redundant binding modifiers) - rust-lang#136598 (Fix suggestion for `dependency_on_unit_never_type_fallback` involving closures + format args expansions) - rust-lang#136653 (Remove dead code from rustc_codegen_llvm and the LLVM wrapper) - rust-lang#136664 (replace one `.map_or(true, ...)` with `.is_none_or(...)`) Failed merges: - rust-lang#136193 (Implement pattern type ffi checks) r? `@ghost` `@rustbot` modify labels: rollup
@bors r- |
Ah, looks like on LLDB versions prior to 19.0(?),
In the future it might be worth using a static enum instead of a static u64 DI node to store the discriminant values, just like we do for the variant names. That way we can look up that enum type itself and use the |
@rustbot review |
Adds handling for
tuple$<>
,ref$<slice$2<>
,ref$<str$>
andenum2$<>
.Also fixes a bug in MSVC vec/string handling where the script was unable to determine the element's type due to LLDB ignoring template arg debug information
Sample code
Before:
After: