]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
[gdb/symtab] Fix element type modification in read_array_type
authorTom de Vries <tdevries@suse.de>
Sun, 7 Mar 2021 16:58:28 +0000 (17:58 +0100)
committerTom de Vries <tdevries@suse.de>
Sun, 7 Mar 2021 16:58:28 +0000 (17:58 +0100)
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=<error reading variable: Cannot access memory at address 0xc>) 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-03-07  Tom de Vries  <tdevries@suse.de>

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-03-07  Tom de Vries  <tdevries@suse.de>

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/ChangeLog
gdb/dwarf2/read.c
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.fortran/function-calls.exp
gdb/testsuite/lib/gdb.exp

index 72e2d62c9fadc3cfae30464a9a00e94081c92b87..6170ccb702ca0dc2a5b2995dcd638223df5dee9b 100644 (file)
@@ -1,3 +1,10 @@
+2021-03-07  Tom de Vries  <tdevries@suse.de>
+
+       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.
+
 2021-03-06  Kevin Buettner  <kevinb@redhat.com>
 
        PR build/27536
index a025f04f48d0fe3edaa1664956844ca7979a2143..1dbeb1132171142841818857020aeea6c02af86e 100644 (file)
@@ -16854,6 +16854,14 @@ read_array_type (struct die_info *die, struct dwarf2_cu *cu)
       child_die = child_die->sibling;
     }
 
+  if (range_types.empty ())
+    {
+      complaint (_("unable to find array range - DIE at %s [in module %s]"),
+                sect_offset_str (die->sect_off),
+                objfile_name (cu->per_objfile->objfile));
+      return NULL;
+    }
+
   /* Dwarf2 dimensions are output from left to right, create the
      necessary array types in backwards order.  */
 
@@ -16875,6 +16883,8 @@ read_array_type (struct die_info *die, struct dwarf2_cu *cu)
                                              byte_stride_prop, bit_stride);
     }
 
+  gdb_assert (type != element_type);
+
   /* Understand Dwarf2 support for vector types (like they occur on
      the PowerPC w/ AltiVec).  Gcc just adds another attribute to the
      array type.  This is not part of the Dwarf2/3 standard yet, but a
index 032ff34b41041c6b0742d17cf8fe9920f8f76c33..d2057855af60ba7a54333f2f79868f71226a6481 100644 (file)
@@ -1,3 +1,10 @@
+2021-03-07  Tom de Vries  <tdevries@suse.de>
+
+       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.
+
 2021-02-02  Simon Marchi  <simon.marchi@efficios.com>
 
        * lib/dwarf.exp (rnglists): Add -no-offset-array option to
index a14cfaeb08abd55186954f136e6637222985cf51..00036d96c7cade132e0b0b671c9abd77f1e78c5f 100644 (file)
@@ -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
index 316d5ae137931a640e2892a029ffcddccd3b62d4..ff6e8c7e238144a8b6763a4cb02f52cf3355fe33 100644 (file)
@@ -4977,6 +4977,62 @@ proc gdb_load { arg } {
     return 0
 }
 
+#
+# with_complaints -- Execute BODY and set complaints temporary to N for the
+# duration.
+#
+proc with_complaints { n body } {
+    global decimal
+
+    # Save current setting of complaints.
+    set save ""
+    set show_complaints_re \
+       "Max number of complaints about incorrect symbols is ($decimal)\\."
+    gdb_test_multiple "show complaints" "" {
+       -re -wrap $show_complaints_re {
+           set save $expect_out(1,string)
+       }
+    }
+
+    if { $save == "" } {
+       perror "Did not manage to set complaints"
+    } else {
+       # Set complaints.
+       gdb_test_no_output "set complaints $n" ""
+    }
+
+    set code [catch {uplevel 1 $body} result]
+
+    # Restore saved setting of complaints.
+    if { $save != "" } {
+       gdb_test_no_output "set complaints $save" ""
+    }
+
+    if {$code == 1} {
+       global errorInfo errorCode
+       return -code $code -errorinfo $errorInfo -errorcode $errorCode $result
+    } else {
+       return -code $code $result
+    }
+}
+
+#
+# gdb_load_no_complaints -- As gdb_load, but in addition verifies that
+# loading caused no symbol reading complaints.
+#
+proc gdb_load_no_complaints { arg } {
+    global gdb_prompt gdb_file_cmd_msg decimal
+
+    # Temporarily set complaint to a small non-zero number.
+    with_complaints 5 {
+       gdb_load $arg
+    }
+
+    # Verify that there were no complaints.
+    set re "^Reading symbols from \[^\r\n\]*\r\n$gdb_prompt $"
+    gdb_assert {[regexp $re $gdb_file_cmd_msg]} "No complaints"
+}
+
 # gdb_reload -- load a file into the target.  Called before "running",
 # either the first time or after already starting the program once,
 # for remote targets.  Most files that override gdb_load should now