1 # Copyright 2020-2024 Free Software Foundation, Inc. 2 3 # This program is free software; you can redistribute it and/or modify 4 # it under the terms of the GNU General Public License as published by 5 # the Free Software Foundation; either version 3 of the License, or 6 # (at your option) any later version. 7 # 8 # This program is distributed in the hope that it will be useful, 9 # but WITHOUT ANY WARRANTY; without even the implied warranty of 10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 # GNU General Public License for more details. 12 # 13 # You should have received a copy of the GNU General Public License 14 # along with this program. If not, see <http://www.gnu.org/licenses/>. 15 16 # Test to reproduce the crash described in PR 26693. The following DWARF was 17 # crashing GDB while loading partial symbols: a DW_TAG_subprogram with a 18 # DW_AT_specification (pointing to another subprogram), without a DW_AT_name 19 # and with a template parameter (DW_TAG_template_type_parameter). More 20 # precisely, the crash was happening when trying to compute the full name of the 21 # subprogram. 22 23 load_lib dwarf.exp 24 25 require dwarf2_support 26 27 standard_testfile main.c .S 28 29 lassign [function_range main ${srcdir}/${subdir}/${srcfile}] \ 30 main_start main_length 31 32 set asm_file [standard_output_file $srcfile2] 33 Dwarf::assemble $asm_file { 34 global main_start main_length 35 36 cu { label cu_start } { 37 DW_TAG_compile_unit { 38 {DW_AT_language @DW_LANG_C_plus_plus} 39 } { 40 declare_labels templated_subprogram int 41 42 int: DW_TAG_base_type { 43 {DW_AT_name "int"} 44 {DW_AT_byte_size 4 DW_FORM_data1} 45 {DW_AT_encoding @DW_ATE_signed} 46 } 47 48 # The templated subprogram. 49 templated_subprogram: DW_TAG_subprogram { 50 {DW_AT_name "apply"} 51 } 52 53 # The template specialization. 54 # 55 # The low and high PC are phony: we just need an address range that 56 # is valid in the program, so we use the main function's range. 57 DW_TAG_subprogram { 58 {DW_AT_specification :$templated_subprogram} 59 {MACRO_AT_range main} 60 } { 61 DW_TAG_template_type_param { 62 {DW_AT_name "T"} 63 {DW_AT_type :$int DW_FORM_ref4} 64 } 65 } 66 } 67 } 68 69 aranges {} cu_start { 70 arange {} "$main_start" "$main_length" 71 } 72 } 73 74 if { [prepare_for_testing "failed to prepare" ${testfile} \ 75 [list $srcfile $asm_file] {nodebug}] } { 76 return -1 77 } 78 79 if ![runto_main] { 80 return -1 81 } 82 83 # Just a sanity check to make sure GDB slurped the symbols correctly. 84 gdb_test "print apply<int>" " = {void \\(void\\)} $hex <apply<int>\\(\\)>" 85