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

[Debuginfo] Add MSVC Synthetic and Summary providers to LLDB #135354

Open
wants to merge 12 commits into
base: master
Choose a base branch
from

Conversation

Walnut356
Copy link
Contributor

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

Sample code
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);

Before:

image

After:

image

@rustbot
Copy link
Collaborator

rustbot commented Jan 11, 2025

r? @Mark-Simulacrum

rustbot has assigned @Mark-Simulacrum.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jan 11, 2025
@jieyouxu jieyouxu 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. labels Jan 11, 2025
@Walnut356
Copy link
Contributor Author

Hmm, I was originally going to separate it out, but I think I can squeeze the HashMap and HashSet fix on here too. The fixes for those are much less involved than I thought they might be.

@Walnut356
Copy link
Contributor Author

There we go =D

image

Type-name output isn't perfect, but that's going to require a PR of its own since it's a can of worms.

@jieyouxu
Copy link
Member

(cc @wesleywiser: maybe you could take a look if you have the bandwidth and are willing?)

@@ -127,6 +131,25 @@ def has_children(self) -> bool:
return False


def get_template_args(type_name: str) -> List[str]:
Copy link
Member

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.

Copy link
Contributor Author

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().


# acquire the first generic parameter via its type name
_, _, end = self.valobj.GetTypeName().partition("<")
element_name, _, _ = end.partition(",")
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure why this can't use the get_template_args above. Is that because we're not getting a proper type here (e.g., other noise is mixed in)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Whoops, that's a remnant from when it was the only place that needed a template args replacement

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.) O-windows-msvc Toolchain: MSVC, Operating system: Windows S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants