From 93689ce91271bf88580a2d035a466479c16f4e71 Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Mon, 6 Apr 2020 12:13:24 -0600 Subject: [PATCH] Handle complex error type in read_base_type It turns out there was one more bug in the earlier complex series: read_base_type could cause an assertion failure on some platforms. I found this running the AdaCore internal test suite, but you can also see it by running gdb's "gdb.cp" tests for x86 (not x86-64). In particular, the DW_ATE_complex_float case calls dwarf2_init_complex_target_type, which calls dwarf2_init_float_type, which can return a type using TYPE_CODE_ERROR. This patch changes the DWARF reader to handle this case, the same way that the f-lang.c patch did. Perhaps init_complex_type really should be changed to allow TYPE_CODE_ERROR? I was not sure. Tested on x86-64 Fedora 30, using an x86 build. I'm checking this in. gdb/ChangeLog 2020-04-06 Tom Tromey * dwarf2/read.c (read_base_type) : Handle TYPE_CODE_ERROR. --- gdb/ChangeLog | 5 +++++ gdb/dwarf2/read.c | 14 +++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index b1a965304a4..cdf6d667872 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,8 @@ +2020-04-06 Tom Tromey + + * dwarf2/read.c (read_base_type) : Handle + TYPE_CODE_ERROR. + 2020-04-06 Kamil Rytarowski * nbsd-tdep.c: Include "gdbarch.h". diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index bcc3116071e..749acb3ba26 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -16910,7 +16910,19 @@ read_base_type (struct die_info *die, struct dwarf2_cu *cu) case DW_ATE_complex_float: type = dwarf2_init_complex_target_type (cu, objfile, bits / 2, name, byte_order); - type = init_complex_type (name, type); + if (TYPE_CODE (type) == TYPE_CODE_ERROR) + { + if (name == nullptr) + { + struct obstack *obstack + = &cu->per_cu->dwarf2_per_objfile->objfile->objfile_obstack; + name = obconcat (obstack, "_Complex ", TYPE_NAME (type), + nullptr); + } + type = init_type (objfile, TYPE_CODE_ERROR, bits, name); + } + else + type = init_complex_type (name, type); break; case DW_ATE_decimal_float: type = init_decfloat_type (objfile, bits, name); -- 2.30.2