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