Index: dwarf2read.c =================================================================== RCS file: /cvs/src/src/gdb/dwarf2read.c,v retrieving revision 1.503 diff -u -p -r1.503 dwarf2read.c --- dwarf2read.c 1 Mar 2011 00:07:20 -0000 1.503 +++ dwarf2read.c 3 Mar 2011 17:31:31 -0000 @@ -4984,9 +4984,20 @@ dwarf2_compute_name (char *name, struct && (cu->language == language_cplus || cu->language == language_java)) { - struct type *type = read_type_die (die, cu); + struct type *type; + struct die_info *type_die; + struct dwarf2_cu *type_cu; + + /* If the subprogram has DW_AT_specification, use that + DIE for determining the type of the function. */ + type_cu = cu; + type_die = die_specification (die, &type_cu); + if (type_die == NULL) + type_die = die; - c_type_print_args (type, buf, 0, cu->language); + type = read_type_die (type_die, type_cu); + + c_type_print_args (type, buf, 0, type_cu->language); if (cu->language == language_java) { @@ -4996,7 +5007,7 @@ dwarf2_compute_name (char *name, struct java_print_type (TYPE_TARGET_TYPE (type), "", buf, 0, 0); } - else if (cu->language == language_cplus) + else if (type_cu->language == language_cplus) { /* Assume that an artificial first parameter is "this", but do not crash if it is not. RealView Index: testsuite/gdb.dwarf2/dw2-method-type-spec.S =================================================================== RCS file: testsuite/gdb.dwarf2/dw2-method-type-spec.S diff -N testsuite/gdb.dwarf2/dw2-method-type-spec.S --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ testsuite/gdb.dwarf2/dw2-method-type-spec.S 3 Mar 2011 17:31:31 -0000 @@ -0,0 +1,365 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 2011 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 exercises c++/12506. + + This test was derived from the following source code: + + template + class test + { + public: + void f1 (typename types::arg_type f) + { + } + + void f2 (void) + { + } + }; + + class my_types + { + public: + typedef int arg_type; + }; + +*/ + +#define OFFSET(LBL) .Ldie_ ## LBL - .Lcu1_begin + + .section .debug_info +.Lcu1_begin: + .4byte .Lcu1_end - .Lcu1_start # Length of Compilation Unit Info +.Lcu1_start: + .2byte 0x3 # DWARF version number + .long .Labbrev1_begin # Offset into abbrev section + .byte 0x4 # Pointer size (in bytes) + +.Ldie_b: + .uleb128 0x1 # (DIE (0xb) DW_TAG_compile_unit) + .ascii "GNU C++ 4.4.5 20101112 (Red Hat 4.4.5-2)\0" # DW_AT_producer + .byte 0x4 # DW_AT_language + .ascii "pr12506.cc\0" # DW_AT_name + .long .Ldebug_line0 # DW_AT_stmt_list + +.Ldie_31: + .uleb128 0x2 # (DIE (0x31) DW_TAG_class_type) + .ascii "my_types\0" # DW_AT_name + .byte 0x1 # DW_AT_byte_size + .long OFFSET (49) # DW_AT_sibling + +.Ldie_3d: + .uleb128 0x3 # (DIE (0x3d) DW_TAG_typedef) + .ascii "arg_type\0" # DW_AT_name + .long OFFSET (49) # DW_AT_type + .byte 0x0 # end of children of DIE 0x31 + +.Ldie_49: + .uleb128 0x4 # (DIE (0x49) DW_TAG_base_type) + .byte 0x4 # DW_AT_byte_size + .byte 0x5 # DW_AT_encoding + .ascii "int\0" # DW_AT_name + +.Ldie_50: + .uleb128 0x2 # (DIE (0x50) DW_TAG_class_type) + .ascii "test\0" # DW_at_name + .byte 0x1 # DW_AT_byte_size + .long OFFSET (8c) # DW_AT_sibling + +.Ldie_5c: + .uleb128 0x5 # (DIE (0x5c) DW_TAG_subprogram) + .byte 0x1 # DW_AT_external + .ascii "f1\0" # DW_AT_name + .byte 0x1 # DW_AT_declaration + .long OFFSET (78) # DW_AT_sibling + +.Ldie_6c: + .uleb128 0x6 # (DIE (0x6c) DW_TAG_formal_parameter) + .long OFFSET (8c) # DW_AT_type + .byte 0x1 # DW_AT_artificial + +.Ldie_72: + .uleb128 0x7 # (DIE (0x72) DW_TAG_formal_parameter) + .long OFFSET (49) # DW_AT_type + .byte 0x0 # end of children of DIE 0x5c + +.Ldie_78: + .uleb128 0x8 # (DIE (0x78) DW_TAG_subprogram) + .byte 0x1 # DW_AT_external + .ascii "f2\0" # DW_AT_name + .byte 0x1 # DW_AT_declaration + +.Ldie_84: + .uleb128 0x6 # (DIE (0x84) DW_TAG_formal_parameter) + .long OFFSET (8c) # DW_AT_type + .byte 0x1 # DW_AT_artificial + .byte 0x0 # end of children of DIE 0x78 + .byte 0x0 # end of children of DIE 0x50 + +.Ldie_8c: + .uleb128 0x9 # (DIE (0x8c) DW_TAG_pointer_type) + .byte 0x4 # DW_AT_byte_size + .long OFFSET (50) # DW_AT_type + +.Ldie_92: + .uleb128 0xa # (DIE (0x92) DW_TAG_subprogram) + .byte 0x1 # DW_AT_external + .ascii "main\0" # DW_AT_name + .long OFFSET (49) # DW_AT_type + .long OFFSET (d3) # DW_AT_sibling + +.Ldie_b4: + .uleb128 0xb # (DIE (0xb4) DW_TAG_lexical_block) + +.Ldie_c5: + .uleb128 0xc # (DIE (0xc5) DW_TAG_variable) + .ascii "t\0" # DW_AT_name + .long OFFSET (50) # DW_AT_type + .byte 0x0 # end of children of DIE 0xb4 + .byte 0x0 # end of children of DIE 0x92 + +.Ldie_d3: + .uleb128 0xd # (DIE (0xd3) DW_TAG_subprogram) + .long OFFSET (5c) # DW_AT_specification + .4byte cu_text_start # DW_AT_low_pc + .4byte cu_text_end # DW_AT_high_pc + .long OFFSET (108) # DW_AT_sibling + +.Ldie_ee: + .uleb128 0xe # (DIE (0xee) DW_TAG_formal_parameter) + .ascii "this\0" # DW_AT_name + .long OFFSET (108) # DW_AT_type + .byte 0x1 # DW_AT_artificial + +.Ldie_fb: + .uleb128 0xf # (DIE (0xfb) DW_TAG_formal_parameter) + .ascii "f\0" # DW_AT_name + .long OFFSET (3d) # DW_AT_type + .byte 0x0 # end of children of DIE 0xd3 + +.Ldie_108: + .uleb128 0x10 # (DIE (0x108) DW_TAG_const_type) + .long OFFSET (8c) # DW_AT_type + +.Ldie_10d: + .uleb128 0x11 # (DIE (0x10d) DW_TAG_subprogram) + .long OFFSET (78) # DW_AT_specification + .4byte cu_text_start # DW_AT_low_pc + .4byte cu_text_end # DW_AT_high_pc + +.Ldie_124: + .uleb128 0xe # (DIE (0x124) DW_TAG_formal_parameter) + .ascii "this\0" # DW_AT_name + .long OFFSET (108) # DW_AT_type + .byte 0x1 # DW_AT_artificial + .byte 0x0 # end of children of DIE 0x10d + .byte 0x0 # end of children of DIE 0xb +.Lcu1_end: + +/* Abbrev table */ + .section .debug_abbrev + .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 + .uleb128 0x10 # (DW_AT_stmt_list) + .uleb128 0x6 # (DW_FORM_data4) + .byte 0x0 + .byte 0x0 + + .uleb128 0x2 # (abbrev code) + .uleb128 0x2 # (DW_TAG_class_type) + .byte 0x1 # DW_children_yes + .uleb128 0x3 # (DW_AT_name) + .uleb128 0x8 # (DW_FORM_string) + .uleb128 0xb # (DW_AT_byte_size) + .uleb128 0xb # (DW_FORM_data1) + .uleb128 0x1 # (DW_AT_sibling) + .uleb128 0x13 # (DW_FORM_ref4) + .byte 0x0 + .byte 0x0 + + .uleb128 0x3 # (abbrev code) + .uleb128 0x16 # (DW_TAG_typedef) + .byte 0x0 # DW_children_no + .uleb128 0x3 # (DW_AT_name) + .uleb128 0x8 # (DW_FORM_string) + .uleb128 0x49 # (DW_AT_type) + .uleb128 0x13 # (DW_FORM_ref4) + .byte 0x0 + .byte 0x0 + + .uleb128 0x4 # (abbrev code) + .uleb128 0x24 # (DW_TAG_base_type) + .byte 0x0 # DW_children_no + .uleb128 0xb # (DW_AT_byte_size) + .uleb128 0xb # (DW_FORM_data1) + .uleb128 0x3e # (DW_AT_encoding) + .uleb128 0xb # (DW_FORM_data1) + .uleb128 0x3 # (DW_AT_name) + .uleb128 0x8 # (DW_FORM_string) + .byte 0x0 + .byte 0x0 + + .uleb128 0x5 # (abbrev code) + .uleb128 0x2e # (DW_TAG_subprogram) + .byte 0x1 # DW_children_yes + .uleb128 0x3f # (DW_AT_external) + .uleb128 0xc # (DW_FORM_flag) + .uleb128 0x3 # (DW_AT_name) + .uleb128 0x8 # (DW_FORM_string) + .uleb128 0x3c # (DW_AT_declaration) + .uleb128 0xc # (DW_FORM_flag) + .uleb128 0x1 # (DW_AT_sibling) + .uleb128 0x13 # (DW_FORM_ref4) + .byte 0x0 + .byte 0x0 + + .uleb128 0x6 # (abbrev code) + .uleb128 0x5 # (DW_TAG_formal_parameter) + .byte 0x0 # DW_children_no + .uleb128 0x49 # (DW_AT_type) + .uleb128 0x13 # (DW_FORM_ref4) + .uleb128 0x34 # (DW_AT_artificial) + .uleb128 0xc # (DW_FORM_flag) + .byte 0x0 + .byte 0x0 + + .uleb128 0x7 # (abbrev code) + .uleb128 0x5 # (DW_TAG_formal_parameter) + .byte 0x0 # DW_children_no + .uleb128 0x49 # (DW_AT_type) + .uleb128 0x13 # (DW_FORM_ref4) + .byte 0x0 + .byte 0x0 + + .uleb128 0x8 # (abbrev code) + .uleb128 0x2e # (DW_TAG_subprogram) + .byte 0x1 # DW_children_yes + .uleb128 0x3f # (DW_AT_external) + .uleb128 0xc # (DW_FORM_flag) + .uleb128 0x3 # (DW_AT_name) + .uleb128 0x8 # (DW_FORM_string) + .uleb128 0x3c # (DW_AT_declaration) + .uleb128 0xc # (DW_FORM_flag) + .byte 0x0 + .byte 0x0 + + .uleb128 0x9 # (abbrev code) + .uleb128 0xf # (DW_TAG_pointer_type) + .byte 0x0 # DW_children_no + .uleb128 0xb # (DW_AT_byte_size) + .uleb128 0xb # (DW_FORM_data1) + .uleb128 0x49 # (DW_AT_type) + .uleb128 0x13 # (DW_FORM_ref4) + .byte 0x0 + .byte 0x0 + + .uleb128 0xa # (abbrev code) + .uleb128 0x2e # (DW_TAG_subprogram) + .byte 0x1 # DW_children_yes + .uleb128 0x3f # (DW_AT_external) + .uleb128 0xc # (DW_FORM_flag) + .uleb128 0x3 # (DW_AT_name) + .uleb128 0x8 # (DW_FORM_string) + .uleb128 0x49 # (DW_AT_type) + .uleb128 0x13 # (DW_FORM_ref4) + .uleb128 0x1 # (DW_AT_sibling) + .uleb128 0x13 # (DW_FORM_ref4) + .byte 0x0 + .byte 0x0 + + .uleb128 0xb # (abbrev code) + .uleb128 0xb # (DW_TAG_lexical_block) + .byte 0x1 # DW_children_yes + .byte 0x0 + .byte 0x0 + + .uleb128 0xc # (abbrev code) + .uleb128 0x34 # (DW_TAG_variable) + .byte 0x0 # DW_children_no + .uleb128 0x3 # (DW_AT_name) + .uleb128 0x8 # (DW_FORM_string) + .uleb128 0x49 # (DW_AT_type) + .uleb128 0x13 # (DW_FORM_ref4) + .byte 0x0 + .byte 0x0 + + .uleb128 0xd # (abbrev code) + .uleb128 0x2e # (DW_TAG_subprogram) + .byte 0x1 # DW_children_yes + .uleb128 0x47 # (DW_AT_specification) + .uleb128 0x13 # (DW_FORM_ref4) + .uleb128 0x11 # (DW_AT_low_pc) + .uleb128 0x1 # (DW_FORM_addr) + .uleb128 0x12 # (DW_AT_high_pc) + .uleb128 0x1 # (DW_FORM_addr) + .uleb128 0x1 # (DW_AT_sibling) + .uleb128 0x13 # (DW_FORM_ref4) + .byte 0x0 + .byte 0x0 + + .uleb128 0xe # (abbrev code) + .uleb128 0x5 # (DW_TAG_formal_parameter) + .byte 0x0 # DW_children_no + .uleb128 0x3 # (DW_AT_name) + .uleb128 0x8 # (DW_FORM_string) + .uleb128 0x49 # (DW_AT_type) + .uleb128 0x13 # (DW_FORM_ref4) + .uleb128 0x34 # (DW_AT_artificial) + .uleb128 0xc # (DW_FORM_flag) + .byte 0x0 + .byte 0x0 + + .uleb128 0xf # (abbrev code) + .uleb128 0x5 # (DW_TAG_formal_parameter) + .byte 0x0 # DW_children_no + .uleb128 0x3 # (DW_AT_name) + .uleb128 0x8 # (DW_FORM_string) + .uleb128 0x49 # (DW_AT_type) + .uleb128 0x13 # (DW_FORM_ref4) + .byte 0x0 + .byte 0x0 + + .uleb128 0x10 # (abbrev code) + .uleb128 0x26 # (DW_TAG_const_type) + .byte 0x0 # DW_children_no + .uleb128 0x49 # (DW_AT_type) + .uleb128 0x13 # (DW_FORM_ref4) + .byte 0x0 + .byte 0x0 + + .uleb128 0x11 # (abbrev code) + .uleb128 0x2e # (DW_TAG_subprogram) + .byte 0x1 # DW_children_yes + .uleb128 0x47 # (DW_AT_specification) + .uleb128 0x13 # (DW_FORM_ref4) + .uleb128 0x11 # (DW_AT_low_pc) + .uleb128 0x1 # (DW_FORM_addr) + .uleb128 0x12 # (DW_AT_high_pc) + .uleb128 0x1 # (DW_FORM_addr) + .byte 0x0 + .byte 0x0 + + .byte 0x0 + .byte 0x0 Index: testsuite/gdb.dwarf2/dw2-method-type-spec.exp =================================================================== RCS file: testsuite/gdb.dwarf2/dw2-method-type-spec.exp diff -N testsuite/gdb.dwarf2/dw2-method-type-spec.exp --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ testsuite/gdb.dwarf2/dw2-method-type-spec.exp 3 Mar 2011 17:31:31 -0000 @@ -0,0 +1,37 @@ +# Copyright 2011 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 is a test for c++/12506. + +if {[skip_cplus_tests]} { continue } +load_lib dwarf.exp + +# This test can only be run on targets which support DWARF-2 and use gas. +if {![dwarf2_support]} { + return 0 +} + +set testfile "dw2-method-type-spec" +set srcfile $testfile.S +set executable $testfile.x + +if {[gdb_compile [file join $srcdir $subdir $srcfile] \ + [file join $objdir $subdir $executable] \ + object {nodebug}] != ""} { + return -1 +} + +clean_restart $executable +gdb_test "break test::f1"