Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upFix DWARF generation for enums #54004
Conversation
rust-highfive
assigned
nikomatsakis
Sep 6, 2018
This comment has been minimized.
This comment has been minimized.
|
(rust_highfive has picked a reviewer for you, use r? to override) |
rust-highfive
added
the
S-waiting-on-review
label
Sep 6, 2018
eddyb
reviewed
Sep 6, 2018
eddyb
reviewed
Sep 6, 2018
|
|
||
| &layout::Variants::NicheFilling { ref niche, .. } => { | ||
| // Find the integer type of the correct size. | ||
| let discr_type = niche.value.to_ty(cx.tcx); |
This comment has been minimized.
This comment has been minimized.
eddyb
reviewed
Sep 6, 2018
| 16 => Integer::I16, | ||
| 32 => Integer::I32, | ||
| 64 => Integer::I64, | ||
| bits => bug!("prepare_enum_metadata: unknown niche bit size {}", bits), |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
tromey
Sep 7, 2018
Author
Contributor
Not directly (that I could find) but I can use Integer::fit_unsigned.
This comment has been minimized.
This comment has been minimized.
eddyb
Sep 7, 2018
Member
Oh, I think you should match on Primitive, convert floats to I32 / I64, and pointers to cx.data_layout().ptr_sized_integer(). That way you don't need to turn an integer back into itself by looking at its size.
This comment has been minimized.
This comment has been minimized.
|
This definitely wants a test or two. EDIT: though I won’t block this PR if they aren’t easy to write. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
rust-highfive
assigned
eddyb
and unassigned
nikomatsakis
Sep 6, 2018
This comment has been minimized.
This comment has been minimized.
|
I can write more tests but note that there are existing debuginfo tests that already cover the ordinary cases. The new test is testing the case that could not be made to work previously. |
This comment was marked as outdated.
This comment was marked as outdated.
|
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
This comment has been minimized.
This comment has been minimized.
|
Still investigating that failure. I'd tried things out with llvm 6 but not 5. I somewhat recall having to make a change here for 6; I will try all 3 ways again but if something has to regress, I think we should let it be 5. |
This comment has been minimized.
This comment has been minimized.
|
I built rust against LLVM 5, 6, and rust-llvm; and then I tested each one against gdb 7.11, 8.1, and 8.2. This found a crash in 8.2, filed: https://sourceware.org/bugzilla/show_bug.cgi?id=23626. I'll fix this before 8.2.1. I couldn't reproduce the bot's failure; but the bot is using 7.11, and my feeling is that a minor output regression there is nothing to worry about. So, if it persists and there are no objections, I'll just bump the minimum gdb version for the test. |
This comment has been minimized.
This comment has been minimized.
I rebased & tried again and now it failed. |
This comment has been minimized.
This comment has been minimized.
At some point I thought I needed to give the variants names, but reverting this and re-testing didn't show any problems. |
tromey
force-pushed the
tromey:enum-debuginfo
branch
from
8f6ce23
to
1bf986e
Sep 11, 2018
tromey
added a commit
to tromey/gdb
that referenced
this pull request
Sep 11, 2018
This comment has been minimized.
This comment has been minimized.
|
@eddyb can you re-review? I don't think I have sufficient permissions to mark it. Thanks. |
This comment has been minimized.
This comment has been minimized.
|
@tromey Is the compiler-builtins submodule change intentional? |
eddyb
reviewed
Sep 13, 2018
| None | ||
| } else { | ||
| Some((i.wrapping_sub(*niche_variants.start()) as u128) | ||
| .wrapping_add(niche_start) as u64) |
This comment has been minimized.
This comment has been minimized.
eddyb
Sep 13, 2018
Member
Hmm, I think if you do this then we're "insured" from weird 128-bit bugs:
let niche = (i as u128)
.wrapping_sub(*niche_variants.start() as u128)
.wrapping_add(niche_start);
assert_eq!(niche as u64 as u128, niche);
Some(niche as u64)Note that other than the assert, you also had an overflow bug: if niche_variants.start() is larger than i, subtracting u64s and casting the "negative" result to u128 puts you close to 1 << 64 (because it zero-extends), instead of being a "negative" 128-bit integer.
eddyb
reviewed
Sep 13, 2018
| file_metadata, | ||
| UNKNOWN_LINE_NUMBER, | ||
| enum_type_size.bits(), | ||
| enum_type_align.abi_bits() as u32, |
This comment has been minimized.
This comment has been minimized.
eddyb
Sep 13, 2018
Member
Hmm, do all variants use these size/alignment values? Because each variant has its own "sub-layout" that "fits" inside the enum's layout, and it might make more sense to use those individual ones. Also, instead of UNKNOWN_LINE_NUMBER, you can get each variant's declaration span.
This comment has been minimized.
This comment has been minimized.
tromey
Sep 13, 2018
Author
Contributor
This part is just a bit of DWARF formalism. This is emitting a DW_TAG_variant_part, which according to DWARF is the part of an enclosing structure that can vary. For Rust, the entire thing can vary, so we emit a structure wrapping a variant part, which wraps the variants. Since there can only be one variant part, it makes sense for it to fill the enclosing structure. And, the location of this thing is unimportant as it is basically entirely artificial -- a synthetic construct only necessary because this is how DWARF mandates it.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Nope. |
tromey
force-pushed the
tromey:enum-debuginfo
branch
from
1bf986e
to
8d0df1c
Sep 13, 2018
wallento
pushed a commit
to wallento/binutils-gdb
that referenced
this pull request
Sep 13, 2018
kraj
pushed a commit
to kraj/binutils-gdb
that referenced
this pull request
Sep 13, 2018
tromey
force-pushed the
tromey:enum-debuginfo
branch
from
09009d3
to
98b2688
Oct 30, 2018
This comment has been minimized.
This comment has been minimized.
|
@bors r+ |
This comment has been minimized.
This comment has been minimized.
|
|
bors
added
S-waiting-on-bors
and removed
S-waiting-on-author
labels
Oct 30, 2018
This comment has been minimized.
This comment has been minimized.
bors
added a commit
that referenced
this pull request
Oct 30, 2018
This comment has been minimized.
This comment has been minimized.
|
|
bors
merged commit 98b2688
into
rust-lang:master
Oct 31, 2018
bors
referenced this pull request
Oct 31, 2018
Merged
Add template parameter debuginfo to generic types #55010
This comment has been minimized.
This comment has been minimized.
|
|
tromey commentedSep 6, 2018
•
edited by killercup
The DWARF generated for Rust enums was always somewhat unusual.
Rather than using DWARF constructs directly, it would emit magic field
names like "RUST$ENCODED$ENUM$0$Name" and "RUST$ENUM$DISR". Since
PR #45225, though, even this has not worked -- the ad hoc scheme was
not updated to handle the wider variety of niche-filling layout
optimizations now available.
This patch changes the generated DWARF to use the standard tags meant
for this purpose; namely, DW_TAG_variant and DW_TAG_variant_part.
The patch to implement this went in to LLVM 7. In order to work with
older versions of LLVM, and because LLVM doesn't do anything here for
PDB, the existing code is kept as a fallback mode.
Support for this DWARF is in the Rust lldb and in gdb 8.2.
Closes #32920
Closes #32924
Closes #52762
Closes #53153