-
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+ |
💔 Test failed - checks-actions |
Okay, those DEFINITELY should have been caught by CI. I think the problem is that when just the debugger visualizer files are changed, it doesn't actually run the debug info tests with those new files. Other PRs that also made changes to |
Huh, weird... Based on the CI log I think this PR's lldb_commands is indeed used, did you mean lldb_providers from this PR wasn't used? |
I meant the PR - x86_64-gnu-llvm-18 CI run. The debuginfo suite ran, but it doesn't appear to be using the changes from this PR. If it had, it would have failed there cuz the errors are formatting ones that aren't arch or version specific. |
Since strings populate their characters as children directly now rather than having a single vec child, I had to update the tests. We might be in for some silly because if it uses the new test but doesn't use the new lldb_providers, it'll fail here but pass bors 🫠 |
@bors try |
[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:  After:  try-job: aarch64-apple
☀️ Try build successful - checks-actions |
@rustbot review |
Running a few more: @bors try |
[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:  After:  try-job: aarch64-apple try-job: x86_64-msvc-1 try-job: i686-msvc-1 try-job: x86_64-mingw-1 try-job: i686-mingw try-job: aarch64-gnu
☀️ Try build successful - checks-actions |
@@ -1,43 +1,80 @@ | |||
type synthetic add -l lldb_lookup.synthetic_lookup -x "^(alloc::([a-z_]+::)+)String$" --category Rust | |||
# Forces test-compliant formatting to all other types | |||
type synthetic add -l lldb_lookup.synthetic_lookup -x ".*" --category Rust |
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.
Just wanted to point out that LLDB 19 also added a hook for programmatic type matching: https://lldb.llvm.org/use/variable.html#callback-based-type-matching. This could help avoid attaching DefaultSyntheticProvider to types that don't need special formatting.
Type matches seem to be cached for the entire debug session, so there may be nice performance improvements as well.
@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:  After:  try-job: aarch64-apple try-job: x86_64-msvc-1 try-job: i686-msvc-1 try-job: x86_64-mingw-1 try-job: i686-mingw try-job: aarch64-gnu
Rollup of 12 pull requests Successful merges: - rust-lang#128080 (Specify scope in `out_of_scope_macro_calls` lint) - rust-lang#135354 ([Debuginfo] Add MSVC Synthetic and Summary providers to LLDB) - rust-lang#135630 (add more `s390x` target features) - rust-lang#136089 (Reduce `Box::default` stack copies in debug mode) - rust-lang#136148 (Optionally add type names to `TypeId`s.) - rust-lang#137192 (Remove obsolete Windows ThinLTO+TLS workaround) - rust-lang#137204 (Clarify MIR dialects and phases) - rust-lang#137299 (Simplify `Postorder` customization.) - rust-lang#137302 (Use a probe to avoid registering stray region obligations when re-checking drops in MIR typeck) - rust-lang#137305 (Tweaks in and around `rustc_middle`) - rust-lang#137313 (Some codegen_llvm cleanups) - rust-lang#137333 (Use `edition = "2024"` in the compiler (redux)) r? `@ghost` `@rustbot` modify labels: rollup try-job: test-various try-job: x86_64-msvc-1 try-job: x86_64-msvc-2 try-job: i686-msvc-1 try-job: i686-msvc-2 try-job: i686-mingw-1 try-job: i686-mingw-2 try-job: i686-mingw-3 try-job: x86_64-gnu-nopt
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:
try-job: aarch64-apple
try-job: x86_64-msvc-1
try-job: i686-msvc-1
try-job: x86_64-mingw-1
try-job: i686-mingw
try-job: aarch64-gnu