From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 20858 invoked by alias); 6 Jul 2009 14:51:10 -0000 Mailing-List: contact archer-help@sourceware.org; run by ezmlm Sender: Precedence: bulk List-Post: List-Help: List-Subscribe: List-Id: Received: (qmail 20845 invoked by uid 22791); 6 Jul 2009 14:51:08 -0000 X-SWARE-Spam-Status: No, hits=-2.4 required=5.0 tests=AWL,BAYES_00,SPF_HELO_PASS,SPF_PASS X-Spam-Check-By: sourceware.org Date: Mon, 06 Jul 2009 14:51:00 -0000 From: Jan Kratochvil To: archer@sourceware.org Cc: Mark Wielaard Subject: [vla] [commit] Fix VLA crash regression on constant DW_AT_data_member_location Message-ID: <20090706145052.GA27309@host0.dyn.jankratochvil.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.19 (2009-01-05) X-SW-Source: 2009-q3/txt/msg00018.txt.bz2 commit de9c5190034b84b0a5fb4b98b05b304cda187700 Bugreported by Mark Wielaard . gdb/ 2009-07-06 Jan Kratochvil Fix VLA crash regression on constant DW_AT_data_member_location for DW_TAG_member of DW_TAG_structure_type. * dwarf2read.c (enum dwarf2_get_attr_constant_value): Rename to ... (enum get_attr_constant_value): ... this type. (dwarf2_get_attr_constant_value): Rename to ... (get_attr_constant_value): ... this function. (dwarf2_add_field): Rename the called function to get_attr_constant_value, fix its passed parameters. (read_tag_string_type, read_subrange_type, attr_form_is_section_offset): Rename the called function to get_attr_constant_value. gdb/testsuite/ 2009-07-06 Jan Kratochvil * gdb.dwarf2/dw2-struct-member-data-location.exp, gdb.dwarf2/dw2-struct-member-data-location.S: New. --- gdb/dwarf2read.c | 31 ++++--- .../gdb.dwarf2/dw2-struct-member-data-location.S | 83 ++++++++++++++++++++ .../gdb.dwarf2/dw2-struct-member-data-location.exp | 37 +++++++++ 3 files changed, 138 insertions(+), 13 deletions(-) create mode 100644 gdb/testsuite/gdb.dwarf2/dw2-struct-member-data-location.S create mode 100644 gdb/testsuite/gdb.dwarf2/dw2-struct-member-data-location.exp diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c index e559d86..f6d20a8 100644 --- a/gdb/dwarf2read.c +++ b/gdb/dwarf2read.c @@ -1042,13 +1042,13 @@ static void store_in_ref_table (struct die_info *, static unsigned int dwarf2_get_ref_die_offset (struct attribute *); -enum dwarf2_get_attr_constant_value +enum get_attr_constant_value { dwarf2_attr_unknown, dwarf2_attr_const, dwarf2_attr_block }; -static enum dwarf2_get_attr_constant_value dwarf2_get_attr_constant_value +static enum get_attr_constant_value get_attr_constant_value (struct attribute *attr, int *val_return); static struct die_info *follow_die_ref (struct die_info *, @@ -3792,7 +3792,12 @@ dwarf2_add_field (struct field_info *fip, struct die_info *die, byte_offset = 0; } else if (attr_form_is_constant (attr)) - byte_offset = dwarf2_get_attr_constant_value (attr, 0); + { + enum get_attr_constant_value type; + + type = get_attr_constant_value (attr, &byte_offset); + gdb_assert (type == dwarf2_attr_const); + } else byte_offset = decode_locdesc (DW_BLOCK (attr), cu); @@ -5107,7 +5112,7 @@ read_tag_string_type (struct die_info *die, struct dwarf2_cu *cu) TYPE_LOW_BOUND (range_type) = 1; attr = dwarf2_attr (die, DW_AT_string_length, cu); - switch (dwarf2_get_attr_constant_value (attr, &length)) + switch (get_attr_constant_value (attr, &length)) { case dwarf2_attr_const: /* We currently do not support a constant address where the location @@ -5116,7 +5121,7 @@ read_tag_string_type (struct die_info *die, struct dwarf2_cu *cu) /* PASSTHRU */ case dwarf2_attr_unknown: attr = dwarf2_attr (die, DW_AT_byte_size, cu); - switch (dwarf2_get_attr_constant_value (attr, &length)) + switch (get_attr_constant_value (attr, &length)) { case dwarf2_attr_unknown: length = 1; @@ -5384,7 +5389,7 @@ read_subrange_type (struct die_info *die, struct dwarf2_cu *cu) struct type *range_type; struct attribute *attr; int low, high, byte_stride_int; - enum dwarf2_get_attr_constant_value high_type; + enum get_attr_constant_value high_type; char *name; base_type = die_type (die, cu); @@ -5401,7 +5406,7 @@ read_subrange_type (struct die_info *die, struct dwarf2_cu *cu) range_type = create_range_type (NULL, base_type, 0, -1); attr = dwarf2_attr (die, DW_AT_lower_bound, cu); - switch (dwarf2_get_attr_constant_value (attr, &low)) + switch (get_attr_constant_value (attr, &low)) { case dwarf2_attr_unknown: if (cu->language == language_fortran) @@ -5432,11 +5437,11 @@ read_subrange_type (struct die_info *die, struct dwarf2_cu *cu) } attr = dwarf2_attr (die, DW_AT_upper_bound, cu); - high_type = dwarf2_get_attr_constant_value (attr, &high); + high_type = get_attr_constant_value (attr, &high); if (high_type == dwarf2_attr_unknown) { attr = dwarf2_attr (die, DW_AT_count, cu); - high_type = dwarf2_get_attr_constant_value (attr, &high); + high_type = get_attr_constant_value (attr, &high); /* It does not hurt but it is needlessly ineffective in check_typedef. */ if (high_type != dwarf2_attr_unknown) { @@ -5464,7 +5469,7 @@ read_subrange_type (struct die_info *die, struct dwarf2_cu *cu) /* DW_AT_bit_stride is currently unsupported as we count in bytes. */ attr = dwarf2_attr (die, DW_AT_byte_stride, cu); - switch (dwarf2_get_attr_constant_value (attr, &byte_stride_int)) + switch (get_attr_constant_value (attr, &byte_stride_int)) { case dwarf2_attr_unknown: break; @@ -9686,8 +9691,8 @@ dwarf2_get_ref_die_offset (struct attribute *attr) /* (*val_return) is filled only if returning dwarf2_attr_const. */ -static enum dwarf2_get_attr_constant_value -dwarf2_get_attr_constant_value (struct attribute *attr, int *val_return) +static enum get_attr_constant_value +get_attr_constant_value (struct attribute *attr, int *val_return) { if (attr == NULL) return dwarf2_attr_unknown; @@ -10589,7 +10594,7 @@ attr_form_is_section_offset (struct attribute *attr) /* Return non-zero if ATTR's value falls in the 'constant' class, or zero otherwise. When this function returns true, you can apply - dwarf2_get_attr_constant_value to it. + get_attr_constant_value to it. However, note that for some attributes you must check attr_form_is_section_offset before using this test. DW_FORM_data4 diff --git a/gdb/testsuite/gdb.dwarf2/dw2-struct-member-data-location.S b/gdb/testsuite/gdb.dwarf2/dw2-struct-member-data-location.S new file mode 100644 index 0000000..5fcdd84 --- /dev/null +++ b/gdb/testsuite/gdb.dwarf2/dw2-struct-member-data-location.S @@ -0,0 +1,83 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 2009 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 . */ + +/* Debug information */ + + .section .debug_info +.Lcu1_begin: + /* CU header */ + .4byte .Lcu1_end - .Lcu1_start /* Length of Compilation Unit */ +.Lcu1_start: + .2byte 2 /* DWARF Version */ + .4byte .Labbrev1_begin /* Offset into abbrev section */ + .byte 4 /* Pointer size */ + + /* CU die */ + .uleb128 1 /* Abbrev: DW_TAG_compile_unit */ + .ascii "dw2-struct-member-data-location.c\0" /* DW_AT_name */ + .ascii "GNU C 4.3.2\0" /* DW_AT_producer */ + .byte 1 /* DW_AT_language (C) */ + +.Ltype_uchar: + .uleb128 2 /* Abbrev: DW_TAG_structure_type */ + .ascii "some_struct\0" /* DW_AT_name */ + + .uleb128 3 /* Abbrev: DW_TAG_member */ + .ascii "field\0" /* DW_AT_name */ + .byte 0 /* DW_AT_data_member_location */ + + .byte 0 /* End of children of some_struct */ + + .byte 0 /* End of children of CU */ + +.Lcu1_end: + +/* Abbrev table */ + .section .debug_abbrev +.Labbrev1_begin: + .uleb128 1 /* Abbrev code */ + .uleb128 0x11 /* DW_TAG_compile_unit */ + .byte 1 /* has_children */ + .uleb128 0x3 /* DW_AT_name */ + .uleb128 0x8 /* DW_FORM_string */ + .uleb128 0x25 /* DW_AT_producer */ + .uleb128 0x8 /* DW_FORM_string */ + .uleb128 0x13 /* DW_AT_language */ + .uleb128 0xb /* DW_FORM_data1 */ + .byte 0x0 /* Terminator */ + .byte 0x0 /* Terminator */ + + .uleb128 2 /* Abbrev code */ + .uleb128 0x13 /* DW_TAG_structure_type */ + .byte 1 /* has_children */ + .uleb128 0x3 /* DW_AT_name */ + .uleb128 0x8 /* DW_FORM_string */ + .byte 0x0 /* Terminator */ + .byte 0x0 /* Terminator */ + + .uleb128 3 /* Abbrev code */ + .uleb128 0x0d /* DW_TAG_member */ + .byte 0 /* has_children */ + .uleb128 0x3 /* DW_AT_name */ + .uleb128 0x8 /* DW_FORM_string */ + .uleb128 0x38 /* DW_AT_data_member_location */ + .uleb128 0x0b /* DW_FORM_data1 */ + .byte 0x0 /* Terminator */ + .byte 0x0 /* Terminator */ + + .byte 0x0 /* Terminator */ + .byte 0x0 /* Terminator */ diff --git a/gdb/testsuite/gdb.dwarf2/dw2-struct-member-data-location.exp b/gdb/testsuite/gdb.dwarf2/dw2-struct-member-data-location.exp new file mode 100644 index 0000000..c41151c --- /dev/null +++ b/gdb/testsuite/gdb.dwarf2/dw2-struct-member-data-location.exp @@ -0,0 +1,37 @@ +# Copyright 2009 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 . + +# 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-struct-member-data-location" +set srcfile ${testfile}.S +set binfile ${testfile}.x + +if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${objdir}/${subdir}/${binfile}" object {nodebug}] != "" } { + return -1 +} + +clean_restart $binfile + +gdb_test "ptype struct some_struct" "type = struct some_struct {\[\r\n \t\]*void field;\[\r\n \t\]*}" -- 1.6.2.5