-
-
Notifications
You must be signed in to change notification settings - Fork 15k
debuginfo: slices are DW_TAG_array_type's #153238
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
Open
shua
wants to merge
2
commits into
rust-lang:main
Choose a base branch
from
shua:lldb-rcstr
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| //@ compile-flags:-g -Copt-level=0 -C panic=abort | ||
|
|
||
| // Check that debug information for structs with embedded str and [u8] slices is distinct from | ||
| // structs with embedded u8 | ||
|
|
||
| #![crate_type = "lib"] | ||
|
|
||
| // NOTE: regex for the CHECK directives, | ||
| // depending on the target, u8/usize are basic types or typedefs | ||
| // linux: !1 = !DIBasicType(name: "u8", | ||
| // win: !1 = !DIDerivedType(tag: .*, name: "u8", | ||
| // and references types are | ||
| // linux: name: "&debuginfo_unsize_field::Foo" | ||
| // win: name: "ref$<debuginfo_unsize_field::Foo>" | ||
|
|
||
| // CHECK: ![[U8:[0-9]+]] = !DI{{Basic|Derived}}Type({{.*}}name: "u8", | ||
|
|
||
| pub struct Foo { | ||
| a: u32, | ||
| b: str, | ||
| } | ||
| // CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "{{&|ref\$<}}{{[^"]+}}::Foo{{>?}}", {{.*}}elements: ![[FOO_REF_ELEMS:[0-9]+]] | ||
| // CHECK: ![[FOO_REF_ELEMS]] = !{![[FOO_REF_PTR:[0-9]+]], ![[FOO_REF_LEN:[0-9]+]]} | ||
| // CHECK: ![[FOO_REF_PTR]] = !DIDerivedType(tag: DW_TAG_member, name: "data_ptr", {{.*}}baseType: ![[FOO_PTR:[0-9]+]] | ||
| // CHECK: ![[FOO_PTR]] = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: ![[FOO:[0-9]+]] | ||
| // CHECK: ![[FOO]] = !DICompositeType(tag: DW_TAG_structure_type, name: "Foo", {{.*}}elements: ![[FOO_ELEMS:[0-9]+]] | ||
| // CHECK: ![[FOO_ELEMS]] = !{![[FOO_A:[0-9]+]], ![[FOO_B:[0-9]+]]} | ||
| // CHECK: ![[FOO_A]] = !DIDerivedType(tag: DW_TAG_member, name: "a" | ||
| // CHECK: ![[FOO_B]] = !DIDerivedType(tag: DW_TAG_member, name: "b", {{.*}}baseType: ![[U8_SLICE:[0-9]+]] | ||
| // | ||
| // CHECK: ![[U8_SLICE]] = !DICompositeType(tag: DW_TAG_array_type, baseType: ![[U8]], {{.*}}elements: ![[U8_SLICE_ELEMS:[0-9]+]] | ||
| // CHECK: ![[U8_SLICE_ELEMS]] = !{![[U8_SLICE_RANGE:[0-9]+]]} | ||
| // this is special to embedded slices, there is no upper bound on the number of elements, | ||
| // that info is stored in the length metadata for a reference to the parent struct | ||
| // CHECK: ![[U8_SLICE_RANGE]] = !DISubrange(count: -1, lowerBound: 0) | ||
| // | ||
| // CHECK: ![[FOO_REF_LEN]] = !DIDerivedType(tag: DW_TAG_member, name: "length", {{.*}}baseType: ![[USIZE:[0-9]+]] | ||
| // CHECK: ![[USIZE]] = !DI{{Basic|Derived}}Type({{.*}}name: "usize" | ||
| pub struct Bar { | ||
| a: u32, | ||
| b: [u8], | ||
| } | ||
| // CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "{{&|ref\$<}}{{[^"]+}}::Bar{{>?}}", {{.*}}elements: ![[BAR_REF_ELEMS:[0-9]+]] | ||
| // CHECK: ![[BAR_REF_ELEMS]] = !{![[BAR_REF_PTR:[0-9]+]], ![[BAR_REF_LEN:[0-9]+]]} | ||
| // CHECK: ![[BAR_REF_PTR]] = !DIDerivedType(tag: DW_TAG_member, name: "data_ptr", {{.*}}baseType: ![[BAR_PTR:[0-9]+]] | ||
| // CHECK: ![[BAR_PTR]] = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: ![[BAR:[0-9]+]] | ||
| // CHECK: ![[BAR]] = !DICompositeType(tag: DW_TAG_structure_type, name: "Bar", {{.*}}elements: ![[BAR_ELEMS:[0-9]+]] | ||
| // CHECK: ![[BAR_ELEMS]] = !{![[BAR_A:[0-9]+]], ![[BAR_B:[0-9]+]]} | ||
| // CHECK: ![[BAR_A]] = !DIDerivedType(tag: DW_TAG_member, name: "a" | ||
| // CHECK: ![[BAR_B]] = !DIDerivedType(tag: DW_TAG_member, name: "b", {{.*}}baseType: ![[U8_SLICE]] | ||
| // CHECK: ![[BAR_REF_LEN]] = !DIDerivedType(tag: DW_TAG_member, name: "length", {{.*}}baseType: ![[USIZE:[0-9]+]] | ||
| pub struct Baz { | ||
| a: u32, | ||
| b: u8, | ||
| } | ||
| // CHECK: !DIDerivedType(tag: DW_TAG_pointer_type, name: "{{&|ref\$<}}{{[^"]+}}::Baz{{>?}}", {{.*}}baseType: ![[BAZ:[0-9]+]] | ||
| // CHECK: ![[BAZ]] = !DICompositeType(tag: DW_TAG_structure_type, name: "Baz", {{.*}}elements: ![[BAZ_ELEMS:[0-9]+]] | ||
| // CHECK: ![[BAZ_ELEMS]] = !{![[BAZ_A:[0-9]+]], ![[BAZ_B:[0-9]+]]} | ||
| // CHECK: ![[BAZ_A]] = !DIDerivedType(tag: DW_TAG_member, name: "a" | ||
| // CHECK: ![[BAZ_B]] = !DIDerivedType(tag: DW_TAG_member, name: "b", {{.*}}baseType: ![[U8]] | ||
|
|
||
| #[no_mangle] | ||
| pub fn test<'a>(a: &'a Foo, b: &'a Bar, c: &'a Baz) -> &'a u8 { | ||
| // just use this somehow so the debuginfo isn't removed | ||
| &a.b.as_bytes()[0] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
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.
Oh, I think I get it. Basically, if you have a struct:
A pointer to that struct has the layout:
The length applies to the
bfield, not the whole struct. That applies recursively, so if you have some wrappers:the data layout would be
All that said, I'd still need to test this a bit to see if it's the case, but I think this match is making too many assumptions and isn't accurately representing Rust's
!Sizedtype layout, because{ data_ptr: *const T, length: usize }can meanTitself is the unsized part (i.e.[T]) or that a field ofTis unsized.It might be the case that the visualization won't work out of the box, but so long as a struct's
!Sizedfield can be differentiated from an "identically sized"Sizedfield, the visualizers can fix it before it reaches the user.i.e. if we can tell the difference between
&X(T)andfrom the field layout information alone, we're golden.
I have a full adversarial example here, where the align and padding mean there's no other way to tell them apart (with output from GDB failing to differentiate them for reference).
View changes since the review
Uh oh!
There was an error while loading. Please reload this page.
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.
Looked into this a bit more, I think this is due to GDB's printing behavior. The types are being output accurately:
I think the problem is GDB is hard-coded to treat structs with the shape of
{data_ptr, length}as slices and prints them "shallowly" as slices (see:val_print_sliceandvalue_print_inner).I'm not really familiar with GDB's value or type representations though, so I could be wrong. @tromey does the above sound about right?
I don't think we'll get a
disable-gdb-pretty-printerstest for this to pass until GDB gets updated. On the other hand, visualizers should be able to override this behavior and print properly. It'd need a check for the{data_ptr, length}shape inrust_types.classify_rust_type, and the provider would need to search the pointee's last field recursively to find the one with a[T]/strtype.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.
I'm not sure I understand your concerns in the first comment, but I think we have the same understanding from your second. Specifically, if gdb (or lldb, etc) sees a "fat pointer" type of
{data_ptr, length}it should recursively walk through the debuginfo definitions ofdata_ptr's type:DW_TAG_array_typewith a member fieldDW_AT_countof-1, then it is a dynamic array, and the fat pointer'slengthis for this value,DW_TAG_structure_type, check the type of the last field in this struct, starting from step 1. aboveI found similar confusion around how to handle this in https://sourceware.org/bugzilla/show_bug.cgi?id=30330
Uh oh!
There was an error while loading. Please reload this page.
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.
ah, I think I understand your comments better. I thought they were pointing out something wrong in my change, but it seems that the mingw version of gdb that we test with has some incorrect handling of these fat pointers which are now showing up in the tests.
Specifically, the test creates an
Rc<str>and prints it with gdb, we expect something likebut currently mingw is printing
This indicates that the debugger is incorrectly treating the
NonNullfield of*const RcInner<str>as if it is a pointer to some array ofRcInner<str>, when it should be treating it as simply a pointer to a singleRcInner<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.
Yup, exactly. Though I don't think this is an issue exclusive to mingw. If
aarch64-appletests fail, it's probably best to remove thedisable-gdb-pretty-printersdirective and make it pass from there (especially since the post-visualizer script output is what we care about most anyway).Uh oh!
There was an error while loading. Please reload this page.
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.
Would this issue only be on windows gnu targets? It seems to run and pass on my linux x86_64 machine using gdb.
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.
Huh, that's definitely weird. Afaik, there shouldnt be any difference between windows/nonwindows for
Rc<str>from the debuginfo side. Especially with disabled visualizers. Maybe a gdb version difference? Looks like the mingw test runner was on 14.2, iirc i was using 16.2 on my end. I can also try with WSL later today to see if there's something i'm forgettingUh oh!
There was an error while loading. Please reload this page.
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.
Alright, i'm pretty sure it's a versioning issue. Using
GNU gdb (Ubuntu 15.1-1ubuntu1~24.04.1) 15.1via WSL, the test passes. I think it's because of (sorry for the mirror link) this commit which appears to have been included in the 15.1 release. Prior to that commit, it looks like there was the "any{data_ptr, length}is treated as a[T]" logic. The commit added a heuristic that checks recursively for fields that don't contribute to the type's size.Some digging with lldb shows that
RcInner<unsigned char[]>reports a size of 16 bytes, withvaluebeing size 1, at offset 16script lldb.frame.var("rc_str").GetChildAtIndex(0).GetChildAtIndex(0).GetChildAtIndex(0).Dereference().GetType().fields [ +0: (template<> struct Cell<unsigned long long> {...) strong, +8: (template<> struct Cell<unsigned long long> {...) weak, +16: (unsigned char[]) value ]So it should be caught by that heuristic? I don't know why GDB doesn't print
valueas an array, but i don't have it in me to debug GDB at the moment and it's not really relevant anyway.I also tested with GDB 16.2 on
x86_64-pc-windows-gnuand the test passed just fine. It's probably worth replacingignore-x86_64-pc-windows-gnuwithmin-gdb-version: 15.1, but past that this patch should be good to go afaict 😄