From 77c2dba3e843694fae090e237ccdf1b8f65b94e6 Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Thu, 3 Oct 2019 17:21:52 -0600 Subject: 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 PR rust/24976: * dwarf2read.c (quirk_rust_enum): Handle single-element unions. gdb/testsuite/ChangeLog 2019-10-03 Tom Tromey PR rust/24976: * gdb.rust/simple.rs (Union2): New type. (main): Use Union2. * gdb.rust/simple.exp: Add test. --- gdb/testsuite/gdb.rust/simple.rs | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'gdb/testsuite/gdb.rust/simple.rs') diff --git a/gdb/testsuite/gdb.rust/simple.rs b/gdb/testsuite/gdb.rust/simple.rs index e6e0efd..65b57f4 100644 --- a/gdb/testsuite/gdb.rust/simple.rs +++ b/gdb/testsuite/gdb.rust/simple.rs @@ -85,6 +85,10 @@ union Union { f2: u8, } +pub union Union2 { + pub name: [u8; 1], +} + struct StringAtOffset { pub field1: &'static str, pub field2: i32, @@ -180,6 +184,8 @@ fn main () { let empty_enum_value: EmptyEnum; + let u2 = Union2 { name: [1] }; + println!("{}, {}", x.0, x.1); // set breakpoint here println!("{}", diff2(92, 45)); empty(); -- cgit v1.1