1# Copyright 2021-2023 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 DW_AT_location attribute referencing the .debug_loc section using 17# the DW_FORM_sec_offset form. 18 19load_lib dwarf.exp 20 21if {![dwarf2_support]} { 22 return 0 23} 24 25# Test with 32-bit and 64-bit DWARF. 26foreach_with_prefix is_64 {false true} { 27 if { $is_64 } { 28 standard_testfile .c -dw64.S 29 set testfile ${testfile}-dw64 30 } else { 31 standard_testfile .c -dw32.S 32 set testfile ${testfile}-dw32 33 } 34 35 lassign [function_range func1 $srcdir/$subdir/$srcfile] \ 36 func1_addr func1_len 37 lassign [function_range func2 $srcdir/$subdir/$srcfile] \ 38 func2_addr func2_len 39 40 set asm_file [standard_output_file $srcfile2] 41 Dwarf::assemble $asm_file { 42 global func1_addr func1_len 43 global func2_addr func2_len 44 global is_64 45 46 set cu_version 4 47 48 cu { 49 version $cu_version 50 is_64 $is_64 51 } { 52 declare_labels int_type1 53 declare_labels foo_location_list 54 55 DW_TAG_compile_unit { 56 } { 57 int_type1: DW_TAG_base_type { 58 {DW_AT_byte_size 4 DW_FORM_data1} 59 {DW_AT_encoding @DW_ATE_signed} 60 {DW_AT_name "int"} 61 } 62 63 DW_TAG_variable { 64 {DW_AT_name "foo"} 65 {DW_AT_location $foo_location_list DW_FORM_sec_offset} 66 {DW_AT_type :$int_type1} 67 } 68 69 DW_TAG_subprogram { 70 {DW_AT_name "func1"} 71 {DW_AT_low_pc $func1_addr} 72 {DW_AT_high_pc $func1_len DW_FORM_udata} 73 } 74 75 DW_TAG_subprogram { 76 {DW_AT_name "func2"} 77 {DW_AT_low_pc $func2_addr} 78 {DW_AT_high_pc $func2_len DW_FORM_udata} 79 } 80 } 81 } 82 83 # Generate a .debug_loc contribution. 84 loc { 85 cu_is_64 $is_64 86 cu_version $cu_version 87 } { 88 foo_location_list: 89 entry $func1_addr "$func1_addr + $func1_len" { 90 DW_OP_constu 0x123456 91 DW_OP_stack_value 92 } 93 entry $func2_addr "$func2_addr + $func2_len" { 94 DW_OP_constu 0x234567 95 DW_OP_stack_value 96 } 97 } 98 } 99 100 if { [prepare_for_testing "failed to prepare" ${testfile} \ 101 [list $srcfile $asm_file] {nodebug}] } { 102 return -1 103 } 104 105 if { ![runto_main] } { 106 return 107 } 108 109 gdb_breakpoint "func1" 110 gdb_breakpoint "func2" 111 112 gdb_continue_to_breakpoint "func1" 113 with_test_prefix "at func1" { 114 gdb_test "print /x foo" " = 0x123456" 115 } 116 117 gdb_continue_to_breakpoint "func2" 118 with_test_prefix "at func2" { 119 gdb_test "print /x foo" " = 0x234567" 120 } 121} 122