Fix variant part regressions with older Rust compiler
Older Rust compilers used special field names, rather than DWARF
features, to express the variant parts of Rust enums. This is handled
in gdb through a quirk recognizer that rewrites the types.
Tom de Vries pointed out in PR rust/26197 that the variant part
rewrite regressed this code. This patch fixes the problems:
* Univariant enums were not handled properly. Now we simply call
alloc_rust_variant for these as well.
* There was an off-by-one error in the handling of ordinary enums.
* Ordinary enums should have the size of their member types reset to
match the size of the enclosing enum. (It's not clear to me if this
is truly necessary, but it placates a test, and this is just legacy
handling in any case.)
Tested with Rust 1.12.0, 1.14.0, 1.19.0, 1.36.0, and 1.45.0 on x86-64
Fedora 32. There were some unrelated failures with 1.14.0 and 1.19,0;
but considering that these are fairly old releases, I don't plan to
look into them unless someone complains.
Note that this patch will not fix all the issues in the PR. In that
PR, Tom is using a somewhat unusual build of Rust -- in particular it
uses an older (pre-DWARF variant part) LLVM with a newer Rust. I
believe this compiler doesn't correctly implement the old-style name
fallback; the details are in the bug.
gdb/ChangeLog
2020-08-05 Tom Tromey <tromey@adacore.com>
PR rust/26197:
* dwarf2/read.c (alloc_rust_variant): Handle univariant case.
(quirk_rust_enum): Call alloc_rust_variant for univariant case.
Fix off-by-one and type size errors in ordinary case.