gdb/
authorJan Kratochvil <jan.kratochvil@redhat.com>
Wed, 31 Mar 2010 18:13:38 +0000 (18:13 +0000)
committerJan Kratochvil <jan.kratochvil@redhat.com>
Wed, 31 Mar 2010 18:13:38 +0000 (18:13 +0000)
Fix crash on reading wrong function declaration DWARF.
* dwarf2read.c (read_subroutine_type): New variable void_type.
Pre-fill all TYPE_FIELD_TYPEs.  Move nparams and iparams initialization
more close to their use.

gdb/testsuite/
* gdb.dwarf2/dw2-bad-parameter-type.exp,
gdb.dwarf2/dw2-bad-parameter-type.S: New.

gdb/ChangeLog
gdb/dwarf2read.c
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.dwarf2/dw2-bad-parameter-type.S [new file with mode: 0644]
gdb/testsuite/gdb.dwarf2/dw2-bad-parameter-type.exp [new file with mode: 0644]

index 7d5c47ee56bc56403350ce9265d5561e24a23fda..a83755e46a64052e913178ad7095c348e70e2271 100644 (file)
@@ -1,3 +1,10 @@
+2010-03-31  Jan Kratochvil  <jan.kratochvil@redhat.com>
+
+       Fix crash on reading wrong function declaration DWARF.
+       * dwarf2read.c (read_subroutine_type): New variable void_type.
+       Pre-fill all TYPE_FIELD_TYPEs.  Move nparams and iparams initialization
+       more close to their use.
+
 2010-03-31  Stan Shebs  <stan@codesourcery.com>
 
        * breakpoint.c (tracepoint_save_command): Include variables,
index ed25124579b7733715f1ebc15619644e998b603b..d16cea41afdf7e11eebfb2def2c4534e4b4b1c67 100644 (file)
@@ -5938,13 +5938,14 @@ read_subroutine_type (struct die_info *die, struct dwarf2_cu *cu)
   
   if (die->child != NULL)
     {
+      struct type *void_type = objfile_type (cu->objfile)->builtin_void;
       struct die_info *child_die;
-      int nparams = 0;
-      int iparams = 0;
+      int nparams, iparams;
 
       /* Count the number of parameters.
          FIXME: GDB currently ignores vararg functions, but knows about
          vararg member functions.  */
+      nparams = 0;
       child_die = die->child;
       while (child_die && child_die->tag)
        {
@@ -5960,6 +5961,12 @@ read_subroutine_type (struct die_info *die, struct dwarf2_cu *cu)
       TYPE_FIELDS (ftype) = (struct field *)
        TYPE_ZALLOC (ftype, nparams * sizeof (struct field));
 
+      /* TYPE_FIELD_TYPE must never be NULL.  Pre-fill the array to ensure it
+        even if we error out during the parameters reading below.  */
+      for (iparams = 0; iparams < nparams; iparams++)
+       TYPE_FIELD_TYPE (ftype, iparams) = void_type;
+
+      iparams = 0;
       child_die = die->child;
       while (child_die && child_die->tag)
        {
index 04c5e79d77b1d743bf9d52fe121070658e15ec10..a0c2f5dd8658adccfc3c3b28c5ba2b0857c8ba05 100644 (file)
@@ -1,3 +1,8 @@
+2010-03-31  Jan Kratochvil  <jan.kratochvil@redhat.com>
+
+       * gdb.dwarf2/dw2-bad-parameter-type.exp,
+       gdb.dwarf2/dw2-bad-parameter-type.S: New.
+
 2010-03-31  Stan Shebs  <stan@codesourcery.com>
 
        * gdb.trace/save-trace.exp: Test save/restore of default-collect
diff --git a/gdb/testsuite/gdb.dwarf2/dw2-bad-parameter-type.S b/gdb/testsuite/gdb.dwarf2/dw2-bad-parameter-type.S
new file mode 100644 (file)
index 0000000..e90ebbf
--- /dev/null
@@ -0,0 +1,73 @@
+/* Copyright 2010 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+       .section        .debug_info
+debug_start:
+       .long   debug_end - 1f  /* Length of Compilation Unit Info */
+1:
+       .2byte  0x3     /* DWARF version number */
+       .long   .Ldebug_abbrev0 /* Offset Into Abbrev. Section */
+       .byte   0x4     /* Pointer Size (in bytes) */
+       .uleb128 0x1    /* (DIE (0xb) DW_TAG_compile_unit) */
+       .ascii "GNU C 4.4.3\0"  /* DW_AT_producer */
+       .byte   0x1     /* DW_AT_language */
+       .ascii "1.c\0"  /* DW_AT_name */
+       .uleb128 0x4    /* (DIE (0x3c) DW_TAG_subprogram) */
+       .ascii "f\0"    /* DW_AT_name */
+/* Value 0 would require has_section_at_zero != 0 (which is true, though).  */
+       .long   1       /* DW_AT_low_pc */
+       .long   2       /* DW_AT_high_pc */
+       .byte   0x1     /* DW_AT_prototyped */
+       .uleb128 0x5    /* (DIE (0x42) DW_TAG_formal_parameter) */
+/* Invalid value.  */
+       .long   0x0     /* DW_AT_type */
+       .byte   0x0     /* end of children of DIE 0x3c */
+       .byte   0x0     /* end of children of DIE 0xb */
+debug_end:
+
+       .section        .debug_abbrev
+.Ldebug_abbrev0:
+       .uleb128 0x1    /* (abbrev code) */
+       .uleb128 0x11   /* (TAG: DW_TAG_compile_unit) */
+       .byte   0x1     /* DW_children_yes */
+       .uleb128 0x25   /* (DW_AT_producer) */
+       .uleb128 0x8    /* (DW_FORM_string) */
+       .uleb128 0x13   /* (DW_AT_language) */
+       .uleb128 0xb    /* (DW_FORM_data1) */
+       .uleb128 0x3    /* (DW_AT_name) */
+       .uleb128 0x8    /* (DW_FORM_string) */
+       .byte   0x0
+       .byte   0x0
+       .uleb128 0x4    /* (abbrev code) */
+       .uleb128 0x2e   /* (TAG: DW_TAG_subprogram) */
+       .byte   0x1     /* DW_children_yes */
+       .uleb128 0x3    /* (DW_AT_name) */
+       .uleb128 0x8    /* (DW_FORM_string) */
+       .uleb128 0x11   /* (DW_AT_low_pc) */
+       .uleb128 0x1    /* (DW_FORM_addr) */
+       .uleb128 0x12   /* (DW_AT_high_pc) */
+       .uleb128 0x1    /* (DW_FORM_addr) */
+       .uleb128 0x27   /* (DW_AT_prototyped) */
+       .uleb128 0xc    /* (DW_FORM_flag) */
+       .byte   0x0
+       .byte   0x0
+       .uleb128 0x5    /* (abbrev code) */
+       .uleb128 0x5    /* (TAG: DW_TAG_formal_parameter) */
+       .byte   0x0     /* DW_children_no */
+       .uleb128 0x49   /* (DW_AT_type) */
+       .uleb128 0x13   /* (DW_FORM_ref4) */
+       .byte   0x0
+       .byte   0x0
+       .byte   0x0
diff --git a/gdb/testsuite/gdb.dwarf2/dw2-bad-parameter-type.exp b/gdb/testsuite/gdb.dwarf2/dw2-bad-parameter-type.exp
new file mode 100644 (file)
index 0000000..fcfbb9a
--- /dev/null
@@ -0,0 +1,44 @@
+# Copyright 2010 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+# This test can only be run on targets which support DWARF-2 and use gas.
+# For now pick a sampling of likely targets.
+if {![istarget *-*-linux*]
+    && ![istarget *-*-gnu*]
+    && ![istarget *-*-elf*]
+    && ![istarget *-*-openbsd*]
+    && ![istarget arm-*-eabi*]
+    && ![istarget powerpc-*-eabi*]} {
+    return 0  
+}
+
+set testfile "dw2-bad-parameter-type"
+set srcfile ${testfile}.S
+set executable ${testfile}.x
+set binfile ${objdir}/${subdir}/${executable}
+
+# First try referencing DW_AT_frame_base which is not defined.
+if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" object {}] != "" } {
+    return -1
+}
+
+clean_restart $executable
+
+# The first access (as we do not use -readnow) prints some:
+# Dwarf Error: Cannot find DIE at 0x0 referenced from DIE at 0x29 [in module ...]
+gdb_test "ptype f"
+
+gdb_test "ptype f"
+gdb_test "p 5" " = 5" "is alive"
This page took 0.051181 seconds and 4 git commands to generate.