Blame SOURCES/gdb-rhbz1713762-fortran-nameless-modules.patch

475228
From FEDORA_PATCHES Mon Sep 17 00:00:00 2001
475228
From: Keith Seitz <keiths@redhat.com>
475228
Date: Tue, 9 Jul 2019 13:51:39 -0700
475228
Subject: gdb-rhbz1713762-fortran-nameless-modules.patch
475228
475228
;; Fix segfault with nameless fortran modules.
475228
;; Bernhard Heckel, RH BZ 1713762
475228
475228
    Dwarf: Don't add nameless modules to partial symbol table
475228
475228
    A name for BLOCK DATA in Fortran is optional.  If no name has been
475228
    assigned, GDB crashes during read-in of DWARF when BLOCK DATA is
475228
    represented via DW_TAG_module.  BLOCK DATA is used for one-time
475228
    initialization of non-pointer variables in named common blocks.
475228
475228
    As of now there is no issue when gfortran is used as DW_TAG_module is
475228
    not emitted.  However, with Intel ifort the nameless DW_TAG_module is
475228
    present and has the following form:
475228
475228
     ...
475228
      <1>
: Abbrev Number: 7 (DW_TAG_module)
475228
         <de>   DW_AT_decl_line   : 46
475228
         <df>   DW_AT_decl_file   : 1
475228
         <e0>   DW_AT_description : (indirect string, offset: 0x110): block
475228
     data
475228
         <e4>   DW_AT_high_pc     : 0x402bb7
475228
         <ec>   DW_AT_low_pc      : 0x402bb7
475228
     ...
475228
475228
    The missing name leads to a crash in add_partial_symbol, during length
475228
    calculation.
475228
475228
    gdb/ChangeLog:
475228
    2019-06-11  Bernhard Heckel  <bernhard.heckel@intel.com>
475228
475228
            * dwarf2read.c (add_partial_symbol): Skip nameless modules.
475228
475228
    gdb/testsuite/Changelog:
475228
    2019-06-11  Bernhard Heckel  <bernhard.heckel@intel.com>
475228
475228
            * gdb.fortran/block-data.f: New.
475228
            * gdb.fortran/block-data.exp: New.
475228
475228
diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
475228
--- a/gdb/dwarf2read.c
475228
+++ b/gdb/dwarf2read.c
475228
@@ -9033,11 +9033,15 @@ add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu)
475228
 			   0, cu->language, objfile);
475228
       break;
475228
     case DW_TAG_module:
475228
-      add_psymbol_to_list (actual_name, strlen (actual_name),
475228
-			   built_actual_name != NULL,
475228
-			   MODULE_DOMAIN, LOC_TYPEDEF, -1,
475228
-			   psymbol_placement::GLOBAL,
475228
-			   0, cu->language, objfile);
475228
+      /* With Fortran 77 there might be a "BLOCK DATA" module
475228
+         available without any name.  If so, we skip the module as it
475228
+         doesn't bring any value.  */
475228
+      if (actual_name != nullptr)
475228
+	add_psymbol_to_list (actual_name, strlen (actual_name),
475228
+			     built_actual_name != NULL,
475228
+			     MODULE_DOMAIN, LOC_TYPEDEF, -1,
475228
+			     psymbol_placement::GLOBAL,
475228
+			     0, cu->language, objfile);
475228
       break;
475228
     case DW_TAG_class_type:
475228
     case DW_TAG_interface_type:
475228
@@ -16972,9 +16976,6 @@ read_module_type (struct die_info *die, struct dwarf2_cu *cu)
475228
   struct type *type;
475228
 
475228
   module_name = dwarf2_name (die, cu);
475228
-  if (!module_name)
475228
-    complaint (_("DW_TAG_module has no name, offset %s"),
475228
-               sect_offset_str (die->sect_off));
475228
   type = init_type (objfile, TYPE_CODE_MODULE, 0, module_name);
475228
 
475228
   return set_die_type (die, type, cu);
475228
diff --git a/gdb/testsuite/gdb.fortran/block-data.exp b/gdb/testsuite/gdb.fortran/block-data.exp
475228
new file mode 100644
475228
--- /dev/null
475228
+++ b/gdb/testsuite/gdb.fortran/block-data.exp
475228
@@ -0,0 +1,63 @@
475228
+# Copyright 2016-2019 Free Software Foundation, Inc.
475228
+#
475228
+# This program is free software; you can redistribute it and/or modify
475228
+# it under the terms of the GNU General Public License as published by
475228
+# the Free Software Foundation; either version 3 of the License, or
475228
+# (at your option) any later version.
475228
+#
475228
+# This program is distributed in the hope that it will be useful,
475228
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
475228
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
475228
+# GNU General Public License for more details.
475228
+#
475228
+# You should have received a copy of the GNU General Public License
475228
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
475228
+
475228
+# Test anonymous block-data statements.
475228
+
475228
+# A name for BLOCK DATA in Fortran is optional.  BLOCK DATA is used
475228
+# for one-time initialization of non-pointer variables in named common
475228
+# blocks.  GDB used to crash with 'Intel ifort'-generated code, which
475228
+# outputs nameless DW_TAG_module, unlike with gfortran which just
475228
+# doesn't emit DW_TAG_module in this case.
475228
+
475228
+if { [skip_fortran_tests] } { return -1 }
475228
+
475228
+standard_testfile .f
475228
+load_lib "fortran.exp"
475228
+
475228
+if {[prepare_for_testing $testfile.exp $testfile $srcfile {debug f90}]} {
475228
+    return -1
475228
+}
475228
+
475228
+if ![runto MAIN__] then {
475228
+    untested "couldn't run to breakpoint MAIN__"
475228
+    return -1
475228
+}
475228
+
475228
+with_test_prefix "default values" {
475228
+    gdb_test "print doub1" "= 1\.11\\d+"
475228
+    gdb_test "print doub2" "= 2\.22\\d+"
475228
+    gdb_test "print char1" "= 'abcdef'"
475228
+    gdb_test "print char2" "= 'ghijkl'"
475228
+}
475228
+
475228
+gdb_breakpoint [gdb_get_line_number "! BP_BEFORE_SUB"]
475228
+gdb_continue_to_breakpoint "! BP_BEFORE_SUB" ".*! BP_BEFORE_SUB.*"
475228
+
475228
+with_test_prefix "before sub" {
475228
+    gdb_test "print doub1" "= 11\.11\\d+"
475228
+    gdb_test "print doub2" "= 22\.22\\d+"
475228
+    gdb_test "print char1" "= 'ABCDEF'"
475228
+    gdb_test "print char2" "= 'GHIJKL'"
475228
+}
475228
+
475228
+gdb_breakpoint [gdb_get_line_number "! BP_SUB"]
475228
+gdb_continue_to_breakpoint "! BP_SUB" ".*! BP_SUB.*"
475228
+
475228
+with_test_prefix "in sub" {
475228
+    gdb_test "print doub1" "= 11\.11\\d+"
475228
+    gdb_test "print doub2" "= 22\.22\\d+"
475228
+    gdb_test "print char1" "= 'ABCDEF'"
475228
+    gdb_test "print char2" "= 'GHIJKL'"
475228
+}
475228
diff --git a/gdb/testsuite/gdb.fortran/block-data.f b/gdb/testsuite/gdb.fortran/block-data.f
475228
new file mode 100644
475228
--- /dev/null
475228
+++ b/gdb/testsuite/gdb.fortran/block-data.f
475228
@@ -0,0 +1,56 @@
475228
+! Copyright 2016-2019 Free Software Foundation, Inc.
475228
+!
475228
+! This program is free software; you can redistribute it and/or modify
475228
+! it under the terms of the GNU General Public License as published by
475228
+! the Free Software Foundation; either version 3 of the License, or
475228
+! (at your option) any later version.
475228
+!
475228
+! This program is distributed in the hope that it will be useful,
475228
+! but WITHOUT ANY WARRANTY; without even the implied warranty of
475228
+! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
475228
+! GNU General Public License for more details.
475228
+!
475228
+! You should have received a copy of the GNU General Public License
475228
+! along with this program.  If not, see <http://www.gnu.org/licenses/>.
475228
+!
475228
+! Check that GDB can handle block data with no global name.
475228
+!
475228
+! MAIN
475228
+        PROGRAM bdata
475228
+        DOUBLE PRECISION doub1, doub2
475228
+        CHARACTER*6 char1, char2
475228
+
475228
+        COMMON /BLK1/ doub1, char1
475228
+        COMMON /BLK2/ doub2, char2
475228
+
475228
+        doub1 = 11.111
475228
+        doub2 = 22.222
475228
+        char1 = 'ABCDEF'
475228
+        char2 = 'GHIJKL'
475228
+        CALL sub_block_data      ! BP_BEFORE_SUB
475228
+        STOP
475228
+        END
475228
+
475228
+! BLOCK DATA
475228
+        BLOCK DATA
475228
+
475228
+        DOUBLE PRECISION doub1, doub2
475228
+        CHARACTER*6 char1, char2
475228
+
475228
+        COMMON /BLK1/ doub1, char1
475228
+        COMMON /BLK2/ doub2, char2
475228
+        DATA doub1, doub2 /1.111, 2.222/
475228
+        DATA char1, char2 /'abcdef', 'ghijkl'/
475228
+        END
475228
+
475228
+! SUBROUTINE
475228
+        SUBROUTINE sub_block_data
475228
+
475228
+        DOUBLE PRECISION doub1, doub2
475228
+        CHARACTER*6 char1, char2
475228
+
475228
+        COMMON /BLK1/ doub1, char1
475228
+        COMMON /BLK2/ doub2, char2
475228
+
475228
+        char1 = char2;    ! BP_SUB
475228
+        END