1# Copyright 2011-2020 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/>. 15load_lib dwarf.exp 16 17# This test can only be run on targets which support DWARF-2 and use gas. 18if {![dwarf2_support]} { 19 return 0 20} 21 22standard_testfile main.c 23 24proc test { dwarf_version offset_size addr_size ref_addr_size two_cu } { 25 global testfile srcfile 26 27 set name "d${dwarf_version}o${offset_size}a${addr_size}r${ref_addr_size}t${two_cu}" 28 29 # Make some DWARF for the test. 30 set asm_file [standard_output_file ${testfile}-${name}.S] 31 Dwarf::assemble $asm_file { 32 upvar dwarf_version dwarf_version 33 upvar addr_size addr_size 34 upvar offset_size offset_size 35 upvar ref_addr_size ref_addr_size 36 upvar two_cu two_cu 37 38 set is_64 [expr { $offset_size == 4 ? 0 : 1 }] 39 40 cu { 41 version $dwarf_version 42 addr_size $addr_size 43 is_64 $is_64 44 } { 45 compile_unit { 46 { producer "GNU C 4.4.3" } 47 { language @DW_LANG_C89 } 48 { name 1.c } 49 } { 50 declare_labels struct_label variable_label int_label pointer_label 51 52 int_label: base_type { 53 { byte_size 4 DW_FORM_sdata } 54 { DW_AT_encoding @DW_ATE_signed } 55 { name int } 56 } 57 58 struct_label: structure_type { 59 { name s } 60 { byte_size 4 sdata } 61 } { 62 member { 63 { name f } 64 { type :$int_label } 65 { data_member_location 0 data1 } 66 } 67 } 68 69 pointer_label: pointer_type { 70 { byte_size $Dwarf::_cu_addr_size sdata } 71 { type :$struct_label } 72 } 73 74 variable_label: DW_TAG_variable { 75 { name v } 76 { location { 77 DW_OP_implicit_value 0x1 0x1 0x1 0x1 78 } SPECIAL_expr} 79 { type :$struct_label "DW_FORM_ref$ref_addr_size" } 80 } 81 82 if { !$two_cu } { 83 subprogram { 84 {MACRO_AT_func {main}} 85 { type :$int_label } 86 { external 1 flag } 87 } { 88 DW_TAG_variable { 89 { name p } 90 { location { 91 GNU_implicit_pointer $variable_label 0 92 } SPECIAL_expr } 93 { type :$pointer_label "DW_FORM_ref$ref_addr_size" } 94 } 95 } 96 } 97 } 98 } 99 100 if { $two_cu } { 101 cu { 102 version $dwarf_version 103 addr_size $addr_size 104 is_64 $is_64 105 } { 106 compile_unit { 107 { producer "GNU C 4.4.3" } 108 { language @DW_LANG_C89 } 109 { name 1.c } 110 } { 111 subprogram { 112 { MACRO_AT_func {main} } 113 { type %$int_label } 114 { external 1 flag } 115 } { 116 DW_TAG_variable { 117 { name p } 118 { location { 119 GNU_implicit_pointer $variable_label 0 120 } SPECIAL_expr } 121 { type %$pointer_label } 122 } 123 } 124 } 125 } 126 } 127 } 128 129 # 32-bit targets do not support any of the testcases; keep quiet there. 130 set opts {quiet} 131 set executable ${testfile}-${name} 132 if [prepare_for_testing "failed to prepare" $executable "${asm_file} ${srcfile}" $opts] { 133 return -1 134 } 135 136 if ![runto_main] { 137 return -1 138 } 139 140 gdb_test "p/x p->f" " = 0x1010101" $name 141} 142 143# DWARF_VERSION OFFSET_SIZE ADDR_SIZE REF_ADDR_SIZE TWO_CU 144test 2 8 4 4 0 145test 2 4 8 8 0 146test 3 8 4 8 0 147test 3 4 8 4 0 148test 2 8 4 4 1 149test 2 4 8 8 1 150test 3 8 4 8 1 151test 3 4 8 4 1 152