Skip to content

Fix debuginfo for unsized struct members #38543

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

Merged
merged 1 commit into from
Jan 2, 2017
Merged

Fix debuginfo for unsized struct members #38543

merged 1 commit into from
Jan 2, 2017

Conversation

philipc
Copy link
Contributor

@philipc philipc commented Dec 22, 2016

The member was given the size of a fat pointer, which caused
llvm to emit DWARF attributes for a 128-bit bitfield.

The member was given the size of a fat pointer, which caused
llvm to emit DWARF attributes for a 128-bit bitfield.
@rust-highfive
Copy link
Contributor

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @nrc (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see the contribution instructions for more information.

@michaelwoerister
Copy link
Member

Thanks for the PR!

The member was given the size of a fat pointer, which caused llvm to emit DWARF attributes for a 128-bit bitfield.

What does it emit after this change?

@philipc
Copy link
Contributor Author

philipc commented Dec 22, 2016

For the test case I added, it emitted this before:

< 2><0x000000e9>      DW_TAG_structure_type
                        DW_AT_name                  "Foo<unsized::Foo<[u8]>>"
                        DW_AT_byte_size             0x00000001
< 3><0x000000ef>        DW_TAG_member
                          DW_AT_name                  "value"
                          DW_AT_type                  <0x000000d8>
                          DW_AT_byte_size             0x00000001
                          DW_AT_bit_size              0x00000080
                          DW_AT_bit_offset            0xffffffffffffff80
                          DW_AT_data_member_location  2305843009213693951

and this after:

< 2><0x000000eb>      DW_TAG_structure_type
                        DW_AT_name                  "Foo<unsized::Foo<[u8]>>"
                        DW_AT_byte_size             0x00000001
< 3><0x000000f1>        DW_TAG_member
                          DW_AT_name                  "value"
                          DW_AT_type                  <0x000000da>
                          DW_AT_data_member_location  0

In both case, the DW_AT_byte_size of the member type is 1. For the before case, the problem is that we tell LLVM that the type size is 1 byte, but the member size is 128 bits. For the after case, we tell LLVM that both type and member size are 1 byte, so it doesn't need to add any size attributes.

I'm not sure that this is completely correct yet, but at least it is consistent. The reason I'm not sure it is correct is that in C the equivalent type is a flexible array, and I think these are given a size of 0 in DWARF, whereas rust unsized arrays are given the size of the first element.

Also note that this only caused a problem for gdb without rust support, because the rust support in gdb ignores bitfield attributes.

@michaelwoerister
Copy link
Member

Thanks for the additional info. It's still not really correct but it's definitely an improvement over what we have now.

@michaelwoerister
Copy link
Member

@bors r+

@bors
Copy link
Collaborator

bors commented Jan 2, 2017

📌 Commit af34f91 has been approved by michaelwoerister

@bors
Copy link
Collaborator

bors commented Jan 2, 2017

⌛ Testing commit af34f91 with merge d3a2efa...

bors added a commit that referenced this pull request Jan 2, 2017
Fix debuginfo for unsized struct members

The member was given the size of a fat pointer, which caused
llvm to emit DWARF attributes for a 128-bit bitfield.
@bors
Copy link
Collaborator

bors commented Jan 2, 2017

☀️ Test successful - status-appveyor, status-travis
Approved by: michaelwoerister
Pushing d3a2efa to master...

@bors bors merged commit af34f91 into rust-lang:master Jan 2, 2017
@michaelwoerister
Copy link
Member

Thanks again for the PR!

@philipc philipc deleted the unsized-debuginfo branch January 3, 2017 21:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants