| # Copyright 2011-2021 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 <http://www.gnu.org/licenses/>. |
| load_lib dwarf.exp |
| |
| # This test can only be run on targets which support DWARF-2 and use gas. |
| if {![dwarf2_support]} { |
| return 0 |
| } |
| |
| standard_testfile main.c |
| |
| proc test_1 { name dwarf_version offset_size addr_size ref_addr_size two_cu } { |
| global testfile srcfile |
| |
| # Make some DWARF for the test. |
| set asm_file [standard_output_file ${testfile}-${name}.S] |
| Dwarf::assemble $asm_file { |
| upvar dwarf_version dwarf_version |
| upvar addr_size addr_size |
| upvar offset_size offset_size |
| upvar ref_addr_size ref_addr_size |
| upvar two_cu two_cu |
| |
| set is_64 [expr { $offset_size == 4 ? 0 : 1 }] |
| |
| cu { |
| version $dwarf_version |
| addr_size $addr_size |
| is_64 $is_64 |
| } { |
| compile_unit { |
| { producer "GNU C 4.4.3" } |
| { language @DW_LANG_C89 } |
| { name 1.c } |
| } { |
| declare_labels struct_label variable_label int_label pointer_label |
| |
| int_label: base_type { |
| { byte_size 4 DW_FORM_sdata } |
| { DW_AT_encoding @DW_ATE_signed } |
| { name int } |
| } |
| |
| struct_label: structure_type { |
| { name s } |
| { byte_size 4 sdata } |
| } { |
| member { |
| { name f } |
| { type :$int_label } |
| { data_member_location 0 data1 } |
| } |
| } |
| |
| pointer_label: pointer_type { |
| { byte_size $Dwarf::_cu_addr_size sdata } |
| { type :$struct_label } |
| } |
| |
| variable_label: DW_TAG_variable { |
| { name v } |
| { location { |
| DW_OP_implicit_value 0x1 0x1 0x1 0x1 |
| } SPECIAL_expr} |
| { type :$struct_label "DW_FORM_ref$ref_addr_size" } |
| } |
| |
| if { !$two_cu } { |
| subprogram { |
| {MACRO_AT_func {main}} |
| { type :$int_label } |
| { external 1 flag } |
| } { |
| DW_TAG_variable { |
| { name p } |
| { location { |
| GNU_implicit_pointer $variable_label 0 |
| } SPECIAL_expr } |
| { type :$pointer_label "DW_FORM_ref$ref_addr_size" } |
| } |
| } |
| } |
| } |
| } |
| |
| if { $two_cu } { |
| cu { |
| version $dwarf_version |
| addr_size $addr_size |
| is_64 $is_64 |
| } { |
| compile_unit { |
| { producer "GNU C 4.4.3" } |
| { language @DW_LANG_C89 } |
| { name 1.c } |
| } { |
| subprogram { |
| { MACRO_AT_func {main} } |
| { type %$int_label } |
| { external 1 flag } |
| } { |
| DW_TAG_variable { |
| { name p } |
| { location { |
| GNU_implicit_pointer $variable_label 0 |
| } SPECIAL_expr } |
| { type %$pointer_label } |
| } |
| } |
| } |
| } |
| } |
| } |
| |
| # 32-bit targets do not support any of the testcases; keep quiet there. |
| set opts {quiet} |
| set executable ${testfile}-${name} |
| if [prepare_for_testing "failed to prepare" $executable "${asm_file} ${srcfile}" $opts] { |
| return -1 |
| } |
| |
| if ![runto_main] { |
| return -1 |
| } |
| |
| gdb_test "p/x p->f" " = 0x1010101" |
| } |
| |
| proc test { dwarf_version offset_size addr_size ref_addr_size two_cu } { |
| |
| set name \ |
| [list \ |
| "d${dwarf_version}" \ |
| "o${offset_size}" \ |
| "a${addr_size}" \ |
| "r${ref_addr_size}" \ |
| "t${two_cu}"] |
| set name [join $name "-"] |
| with_test_prefix $name { |
| test_1 $name \ |
| $dwarf_version $offset_size $addr_size $ref_addr_size $two_cu |
| } |
| } |
| |
| # DWARF_VERSION OFFSET_SIZE ADDR_SIZE REF_ADDR_SIZE TWO_CU |
| test 2 8 4 4 0 |
| test 2 4 8 8 0 |
| test 3 8 4 8 0 |
| test 3 4 8 4 0 |
| test 2 8 4 4 1 |
| test 2 4 8 8 1 |
| test 3 8 4 8 1 |
| test 3 4 8 4 1 |