From cf2b20752995e6f10d88afc49166e729c33beb48 Mon Sep 17 00:00:00 2001 From: Tom de Vries Date: Tue, 9 Feb 2021 23:28:16 +0100 Subject: [gdb/symtab] Fix element type modification in read_array_type When running test-case gdb.fortran/function-calls.exp with target board unix/gdb:debug_flags=-gdwarf-5, I run into: ... (gdb) PASS: gdb.fortran/function-calls.exp: \ p derived_types_and_module_calls::pass_cart(c) p derived_types_and_module_calls::pass_cart_nd(c_nd)^M ^M Program received signal SIGSEGV, Segmentation fault.^M 0x0000000000400f73 in derived_types_and_module_calls::pass_cart_nd \ (c=) at \ function-calls.f90:130^M 130 pass_cart_nd = ubound(c%d,1,4)^M The program being debugged was signaled while in a function called from GDB.^M GDB has restored the context to what it was before the call.^M To change this behavior use "set unwindonsignal off".^M Evaluation of the expression containing the function^M (derived_types_and_module_calls::pass_cart_nd) will be abandoned.^M (gdb) FAIL: gdb.fortran/function-calls.exp: p ... The problem originates in read_array_type, when reading a DW_TAG_array_type with a dwarf-5 DW_TAG_generic_subrange child. This is not supported, and the fallout of this is that rather than constructing a new array type, the code proceeds to modify the element type. Fix this conservatively by issuing a complaint and bailing out in read_array_type when not being able to construct an array type, such that we have: ... (gdb) maint expand-symtabs function-calls.f90^M During symbol reading: unable to find array range \ - DIE at 0xe1e [in module function-calls]^M During symbol reading: unable to find array range \ - DIE at 0xe1e [in module function-calls]^M (gdb) KFAIL: gdb.fortran/function-calls.exp: no complaints in srcfile \ (PRMS: symtab/27388) ... Tested on x86_64-linux. gdb/ChangeLog: 2021-02-09 Tom de Vries PR symtab/27341 * dwarf2/read.c (read_array_type): Return NULL when not being able to construct an array type. Add assert to ensure that element_type is not being modified. gdb/testsuite/ChangeLog: 2021-02-09 Tom de Vries PR symtab/27341 * lib/gdb.exp (with_complaints): New proc, factored out of ... (gdb_load_no_complaints): ... here. * gdb.fortran/function-calls.exp: Add test-case. --- gdb/testsuite/gdb.fortran/function-calls.exp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'gdb/testsuite/gdb.fortran') diff --git a/gdb/testsuite/gdb.fortran/function-calls.exp b/gdb/testsuite/gdb.fortran/function-calls.exp index a14cfae..00036d9 100644 --- a/gdb/testsuite/gdb.fortran/function-calls.exp +++ b/gdb/testsuite/gdb.fortran/function-calls.exp @@ -24,6 +24,21 @@ if {[prepare_for_testing ${testfile}.exp ${testfile} ${srcfile} {debug f90}]} { return -1 } +with_complaints 5 { + set cmd "maint expand-symtabs $srcfile" + set cmd_regexp [string_to_regexp $cmd] + set re_kfail [concat "During symbol reading:" \ + " unable to find array range"] + gdb_test_multiple $cmd "no complaints in srcfile" { + -re -wrap "$re_kfail.*" { + kfail symtab/27388 $gdb_test_name + } + -re "^$cmd_regexp\r\n$gdb_prompt $" { + pass $gdb_test_name + } + } +} + if {![runto [gdb_get_line_number "post_init"]]} then { perror "couldn't run to breakpoint post_init" continue -- cgit v1.1