commit 7d8bdfbdfd0e38fb314d70785b0516181b8d4e77 Author: Jan Kratochvil Date: Mon Mar 26 20:49:51 2012 +0200 https://bugzilla.redhat.com/show_bug.cgi?id=806920 gdb.dwarf2/dw2-subrange-no-type.exp --- a/gdb/dwarf2read.c +++ b/gdb/dwarf2read.c @@ -9014,6 +9014,44 @@ read_subrange_type (struct die_info *die, struct dwarf2_cu *cu) /* Preserve BASE_TYPE's original type, just set its LENGTH. */ check_typedef (base_type); + /* Dwarf-2 specifications explicitly allows to create subrange types + without specifying a base type. + In that case, the base type must be set to the type of + the lower bound, upper bound or count, in that order, if any of these + three attributes references an object that has a type. + If no base type is found, the Dwarf-2 specifications say that + a signed integer type of size equal to the size of an address should + be used. + For the following C code: `extern char gdb_int [];' + GCC produces an empty range DIE. + FIXME: muller/2010-05-28: Possible references to object for low bound, + high bound or count are not yet handled by this code. */ + if (TYPE_CODE (base_type) == TYPE_CODE_VOID) + { + struct objfile *objfile = cu->objfile; + struct gdbarch *gdbarch = get_objfile_arch (objfile); + int addr_size = gdbarch_addr_bit (gdbarch) /8; + struct type *int_type = objfile_type (objfile)->builtin_int; + + /* Test "int", "long int", and "long long int" objfile types, + and select the first one having a size above or equal to the + architecture address size. */ + if (int_type && TYPE_LENGTH (int_type) >= addr_size) + base_type = int_type; + else + { + int_type = objfile_type (objfile)->builtin_long; + if (int_type && TYPE_LENGTH (int_type) >= addr_size) + base_type = int_type; + else + { + int_type = objfile_type (objfile)->builtin_long_long; + if (int_type && TYPE_LENGTH (int_type) >= addr_size) + base_type = int_type; + } + } + } + /* The die_type call above may have already set the type for this DIE. */ range_type = get_die_type (die, cu); if (range_type) @@ -9141,44 +9179,6 @@ read_subrange_type (struct die_info *die, struct dwarf2_cu *cu) TYPE_HIGH_BOUND (range_type) = high; } - /* Dwarf-2 specifications explicitly allows to create subrange types - without specifying a base type. - In that case, the base type must be set to the type of - the lower bound, upper bound or count, in that order, if any of these - three attributes references an object that has a type. - If no base type is found, the Dwarf-2 specifications say that - a signed integer type of size equal to the size of an address should - be used. - For the following C code: `extern char gdb_int [];' - GCC produces an empty range DIE. - FIXME: muller/2010-05-28: Possible references to object for low bound, - high bound or count are not yet handled by this code. */ - if (TYPE_CODE (base_type) == TYPE_CODE_VOID) - { - struct objfile *objfile = cu->objfile; - struct gdbarch *gdbarch = get_objfile_arch (objfile); - int addr_size = gdbarch_addr_bit (gdbarch) /8; - struct type *int_type = objfile_type (objfile)->builtin_int; - - /* Test "int", "long int", and "long long int" objfile types, - and select the first one having a size above or equal to the - architecture address size. */ - if (int_type && TYPE_LENGTH (int_type) >= addr_size) - base_type = int_type; - else - { - int_type = objfile_type (objfile)->builtin_long; - if (int_type && TYPE_LENGTH (int_type) >= addr_size) - base_type = int_type; - else - { - int_type = objfile_type (objfile)->builtin_long_long; - if (int_type && TYPE_LENGTH (int_type) >= addr_size) - base_type = int_type; - } - } - } - /* DW_AT_bit_stride is currently unsupported as we count in bytes. */ attr = dwarf2_attr (die, DW_AT_byte_stride, cu); if (attr && attr_form_is_block (attr) && cu->language != language_ada) --- /dev/null +++ b/gdb/testsuite/gdb.dwarf2/dw2-subrange-no-type.S @@ -0,0 +1,121 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 2012 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 .data +vardata: + .rept 129 + .ascii "x" + .endr + .ascii "UNSEEN\0" + + .section .debug_info +.Lcu1_begin: + .4byte .Lcu1_end - .Lcu1_start /* Length of Compilation Unit */ +.Lcu1_start: + .2byte 2 /* DWARF version number */ + .4byte .Ldebug_abbrev0 /* Offset Into Abbrev. Section */ + .byte 4 /* Pointer Size (in bytes) */ + + /* CU die */ + .uleb128 1 /* Abbrev: DW_TAG_compile_unit */ + .ascii "GNU C 3.3.3\0" /* DW_AT_producer */ + .byte 2 /* DW_AT_language (C) - */ + +.Larray_type: + .uleb128 2 /* Abbrev: DW_TAG_array_type */ + .4byte .Lchar_type-.Lcu1_begin /* DW_AT_type */ + + .uleb128 8 /* Abbrev: DW_TAG_subrange_type without DW_AT_type */ + .byte 0 /* DW_AT_lower_bound */ + .byte 128 /* DW_AT_upper_bound */ + + .byte 0 /* End of children of die */ + +.Lchar_type: + .uleb128 4 /* Abbrev: DW_TAG_base_type */ + .ascii "char\0" /* DW_AT_name */ + .byte 1 /* DW_AT_byte_size */ + .byte 6 /* DW_AT_encoding */ + + .uleb128 6 /* Abbrev: DW_TAG_variable DW_FORM_string */ + .ascii "notype_string\0" /* DW_AT_name */ + .4byte .Larray_type-.Lcu1_begin /* DW_AT_type */ + .byte 2f - 1f /* DW_AT_location */ +1: .byte 3 /* DW_OP_addr */ + .4byte vardata /* */ +2: + + .byte 0 /* End of children of CU */ +.Lcu1_end: + + .section .debug_abbrev +.Ldebug_abbrev0: + .uleb128 1 /* Abbrev code */ + .uleb128 0x11 /* DW_TAG_compile_unit */ + .byte 0x1 /* has_children */ + .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 0x1 /* TAG: DW_TAG_array_type */ + .byte 0x1 /* DW_children_yes */ + .uleb128 0x49 /* DW_AT_type */ + .uleb128 0x13 /* DW_FORM_ref4 */ + .byte 0x0 /* Terminator */ + .byte 0x0 /* Terminator */ + + .uleb128 4 /* Abbrev code */ + .uleb128 0x24 /* DW_TAG_base_type */ + .byte 0x0 /* no_children */ + .uleb128 0x3 /* DW_AT_name */ + .uleb128 0x8 /* DW_FORM_string */ + .uleb128 0xb /* DW_AT_byte_size */ + .uleb128 0xb /* DW_FORM_data1 */ + .uleb128 0x3e /* DW_AT_encoding */ + .uleb128 0xb /* DW_FORM_data1 */ + .byte 0x0 /* Terminator */ + .byte 0x0 /* Terminator */ + + .uleb128 6 /* Abbrev code */ + .uleb128 0x34 /* DW_TAG_variable */ + .byte 0x0 /* no_children */ + .uleb128 0x3 /* DW_AT_name */ + .uleb128 0x8 /* DW_FORM_string */ + .uleb128 0x49 /* DW_AT_type */ + .uleb128 0x13 /* DW_FORM_ref4 */ + .uleb128 0x2 /* DW_AT_location */ + .uleb128 0xa /* DW_FORM_block1 */ + .byte 0x0 /* Terminator */ + .byte 0x0 /* Terminator */ + + .uleb128 8 /* Abbrev code */ + .uleb128 0x21 /* DW_TAG_subrange_type without DW_AT_type */ + .byte 0x0 /* no children */ + .uleb128 0x22 /* DW_AT_lower_bound */ + .uleb128 0xb /* DW_FORM_data1 */ + .uleb128 0x2f /* DW_AT_upper_bound */ + .uleb128 0xb /* DW_FORM_data1 */ + .byte 0x0 /* Terminator */ + .byte 0x0 /* Terminator */ + + .byte 0x0 /* Terminator */ --- /dev/null +++ b/gdb/testsuite/gdb.dwarf2/dw2-subrange-no-type.exp @@ -0,0 +1,39 @@ +# Copyright 2012 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 . +load_lib dwarf.exp + +# https://bugzilla.redhat.com/show_bug.cgi?id=806920 +# read_subrange_type reinitialization +# of BASE_TYPE was done too late, it affects DW_TAG_subrange_type without +# specified DW_AT_type, present only in XLF produced code. + +# This test can only be run on targets which support DWARF-2 and use gas. +if {![dwarf2_support]} { + return 0 +} + +set testfile dw2-subrange-no-type +set srcfile ${testfile}.S +set executable ${testfile}.x +set binfile ${objdir}/${subdir}/${executable} + +if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" object {}] != "" } { + return -1 +} + +clean_restart $executable + +gdb_test "ptype notype_string" {type = char \[129\]} +gdb_test "p notype_string" " = 'x' "