Avoid crash on single-field union in Rust
authorTom Tromey <tom@tromey.com>
Thu, 3 Oct 2019 23:21:52 +0000 (17:21 -0600)
committerTom Tromey <tom@tromey.com>
Fri, 4 Oct 2019 02:56:22 +0000 (20:56 -0600)
commit77c2dba3e843694fae090e237ccdf1b8f65b94e6
tree8076f2237aa8155c67f4adbad3c5e40317969d0d
parentf0e21cb80940c065dcc373c29dc33388cf948dbc
Avoid crash on single-field union in Rust

PR rust/24976 points out a crash in gdb when a single-field union is
used in Rust.

The immediate problem was a NULL pointer dereference in
quirk_rust_enum.  However, that code is also erroneously treating a
single-field union as if it were a univariant enum.  Looking at the
output of an older Rust compiler, it turns out that univariant enums
are distinguished by having a single *anonymous* field.  This patch
changes quirk_rust_enum to limit its fixup to this case.

Tested with a new-enough version of the Rust compiler to cause the
crash; plus by using an older executable that uses the old univariant
encoding.

gdb/ChangeLog
2019-10-03  Tom Tromey  <tom@tromey.com>

PR rust/24976:
* dwarf2read.c (quirk_rust_enum): Handle single-element unions.

gdb/testsuite/ChangeLog
2019-10-03  Tom Tromey  <tom@tromey.com>

PR rust/24976:
* gdb.rust/simple.rs (Union2): New type.
(main): Use Union2.
* gdb.rust/simple.exp: Add test.
gdb/ChangeLog
gdb/dwarf2read.c
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.rust/simple.exp
gdb/testsuite/gdb.rust/simple.rs
This page took 0.024304 seconds and 4 git commands to generate.