]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Fix crash in dwarf2read.c with template parameters
authorTom Tromey <tromey@adacore.com>
Mon, 22 Apr 2019 17:46:47 +0000 (11:46 -0600)
committerTom Tromey <tromey@adacore.com>
Tue, 30 Apr 2019 13:16:56 +0000 (07:16 -0600)
PR c++/24470 concerns a crash in dwarf2read.c that occurs with a
particular test case.

The issue turns out to be that process_structure_scope will pass NULL
to symbol_symtab.  This happens because new_symbol decided not to
create a symbol for the particular DIE.

This patch fixes the problem by finding another reasonably-appropriate
symtab to use instead; issuing a complaint if one cannot be found for
some reason.

As mentioned in the bug, I think there are other bugs here.  For
example, when using "ptype" on the "l" object in the test case, I
think I would expect to see the template parameter.  I didn't research
this too closely, since it seemed more important to fix the crash.

Tested on x86-64 Fedora 29.

I'd like to check this in to the 8.3 branch as well.

gdb/ChangeLog
2019-04-30  Tom Tromey  <tromey@adacore.com>

PR c++/24470:
* dwarf2read.c (process_structure_scope): Handle case where type
has template parameters but no symbol was created.

gdb/testsuite/ChangeLog
2019-04-30  Tom Tromey  <tromey@adacore.com>

PR c++/24470:
* gdb.cp/temargs.cc: Add test code from PR.

gdb/ChangeLog
gdb/dwarf2read.c
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.cp/temargs.cc

index e59f067f8dd3845beb4640dae049832b095b90a2..f3579e2f36d8c883325d6229c4de85ca5b1be742 100644 (file)
@@ -1,3 +1,9 @@
+2019-04-30  Tom Tromey  <tromey@adacore.com>
+
+       PR c++/24470:
+       * dwarf2read.c (process_structure_scope): Handle case where type
+       has template parameters but no symbol was created.
+
 2019-04-19  Sergei Trofimovich <siarheit@google.com>
 
        * configure.ac: add --enable-source-highlight switch.
index 2d6cb353fbbd7cc7311a00ffb24b37eda35613b8..4251ed03b46d16120a04bcdda08112ed03706b1f 100644 (file)
@@ -16218,13 +16218,34 @@ process_structure_scope (struct die_info *die, struct dwarf2_cu *cu)
 
       if (has_template_parameters)
        {
-         /* Make sure that the symtab is set on the new symbols.
-            Even though they don't appear in this symtab directly,
-            other parts of gdb assume that symbols do, and this is
-            reasonably true.  */
-         for (int i = 0; i < TYPE_N_TEMPLATE_ARGUMENTS (type); ++i)
-           symbol_set_symtab (TYPE_TEMPLATE_ARGUMENT (type, i),
-                              symbol_symtab (sym));
+         struct symtab *symtab;
+         if (sym != nullptr)
+           symtab = symbol_symtab (sym);
+         else if (cu->line_header != nullptr)
+           {
+             /* Any related symtab will do.  */
+             symtab
+               = cu->line_header->file_name_at (file_name_index (1))->symtab;
+           }
+         else
+           {
+             symtab = nullptr;
+             complaint (_("could not find suitable "
+                          "symtab for template parameter"
+                          " - DIE at %s [in module %s]"),
+                        sect_offset_str (die->sect_off),
+                        objfile_name (objfile));
+           }
+
+         if (symtab != nullptr)
+           {
+             /* Make sure that the symtab is set on the new symbols.
+                Even though they don't appear in this symtab directly,
+                other parts of gdb assume that symbols do, and this is
+                reasonably true.  */
+             for (int i = 0; i < TYPE_N_TEMPLATE_ARGUMENTS (type); ++i)
+               symbol_set_symtab (TYPE_TEMPLATE_ARGUMENT (type, i), symtab);
+           }
        }
     }
 }
index 1ff05265941df94f1eb92f2a02707994468a8f1f..ea1f78cc4bce25e3f63fd4f8989b669638c806d6 100644 (file)
@@ -1,3 +1,8 @@
+2019-04-30  Tom Tromey  <tromey@adacore.com>
+
+       PR c++/24470:
+       * gdb.cp/temargs.cc: Add test code from PR.
+
 2019-04-19  Tom Tromey  <tromey@adacore.com>
 
        PR symtab/24423:
index dc061658d498ee7175b6a91f5b0ee219f37e0268..d2a85f95340b56d8620616dc55144bdf6d40f15f 100644 (file)
@@ -80,6 +80,29 @@ struct K3
   }
 };
 
+namespace pr24470
+{
+// From PR c++/24470
+// This caused a gdb crash during startup.
+
+template <int a> struct b {};
+template <typename, typename> struct c {
+  template <long d> using e = b<d>;
+  void k(e<0>);
+};
+template <typename, template <typename, typename> class, unsigned long...>
+struct m;
+template <typename g, template <typename, typename> class h, unsigned long i>
+struct m<g, h, i> {
+  using j = b<i>;
+};
+struct n {
+  template <typename g> using f = typename m<g, c, 0>::j;
+};
+
+n::f<int> l;
+}
+
 int main ()
 {
   Base<double, 23, &a_global, &S::f> base;