1 1.1 christos # Copyright 2021-2023 Free Software Foundation, Inc. 2 1.1 christos 3 1.1 christos # This program is free software; you can redistribute it and/or modify 4 1.1 christos # it under the terms of the GNU General Public License as published by 5 1.1 christos # the Free Software Foundation; either version 3 of the License, or 6 1.1 christos # (at your option) any later version. 7 1.1 christos # 8 1.1 christos # This program is distributed in the hope that it will be useful, 9 1.1 christos # but WITHOUT ANY WARRANTY; without even the implied warranty of 10 1.1 christos # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 1.1 christos # GNU General Public License for more details. 12 1.1 christos # 13 1.1 christos # You should have received a copy of the GNU General Public License 14 1.1 christos # along with this program. If not, see <http://www.gnu.org/licenses/>. 15 1.1 christos 16 1.1 christos # Test DW_AT_location attribute referencing the .debug_loc section using 17 1.1 christos # the DW_FORM_sec_offset form. 18 1.1 christos 19 1.1 christos load_lib dwarf.exp 20 1.1 christos 21 1.1 christos if {![dwarf2_support]} { 22 1.1 christos return 0 23 1.1 christos } 24 1.1 christos 25 1.1 christos # Test with 32-bit and 64-bit DWARF. 26 1.1 christos foreach_with_prefix is_64 {false true} { 27 1.1 christos if { $is_64 } { 28 1.1 christos standard_testfile .c -dw64.S 29 1.1 christos set testfile ${testfile}-dw64 30 1.1 christos } else { 31 1.1 christos standard_testfile .c -dw32.S 32 1.1 christos set testfile ${testfile}-dw32 33 1.1 christos } 34 1.1 christos 35 1.1 christos lassign [function_range func1 $srcdir/$subdir/$srcfile] \ 36 1.1 christos func1_addr func1_len 37 1.1 christos lassign [function_range func2 $srcdir/$subdir/$srcfile] \ 38 1.1 christos func2_addr func2_len 39 1.1 christos 40 1.1 christos set asm_file [standard_output_file $srcfile2] 41 1.1 christos Dwarf::assemble $asm_file { 42 1.1 christos global func1_addr func1_len 43 1.1 christos global func2_addr func2_len 44 1.1 christos global is_64 45 1.1 christos 46 1.1 christos set cu_version 4 47 1.1 christos 48 1.1 christos cu { 49 1.1 christos version $cu_version 50 1.1 christos is_64 $is_64 51 1.1 christos } { 52 1.1 christos declare_labels int_type1 53 1.1 christos declare_labels foo_location_list 54 1.1 christos 55 1.1 christos DW_TAG_compile_unit { 56 1.1 christos } { 57 1.1 christos int_type1: DW_TAG_base_type { 58 1.1 christos {DW_AT_byte_size 4 DW_FORM_data1} 59 1.1 christos {DW_AT_encoding @DW_ATE_signed} 60 1.1 christos {DW_AT_name "int"} 61 1.1 christos } 62 1.1 christos 63 1.1 christos DW_TAG_variable { 64 1.1 christos {DW_AT_name "foo"} 65 1.1 christos {DW_AT_location $foo_location_list DW_FORM_sec_offset} 66 1.1 christos {DW_AT_type :$int_type1} 67 1.1 christos } 68 1.1 christos 69 1.1 christos DW_TAG_subprogram { 70 1.1 christos {DW_AT_name "func1"} 71 1.1 christos {DW_AT_low_pc $func1_addr} 72 1.1 christos {DW_AT_high_pc $func1_len DW_FORM_udata} 73 1.1 christos } 74 1.1 christos 75 1.1 christos DW_TAG_subprogram { 76 1.1 christos {DW_AT_name "func2"} 77 1.1 christos {DW_AT_low_pc $func2_addr} 78 1.1 christos {DW_AT_high_pc $func2_len DW_FORM_udata} 79 1.1 christos } 80 1.1 christos } 81 1.1 christos } 82 1.1 christos 83 1.1 christos # Generate a .debug_loc contribution. 84 1.1 christos loc { 85 1.1 christos cu_is_64 $is_64 86 1.1 christos cu_version $cu_version 87 1.1 christos } { 88 1.1 christos foo_location_list: 89 1.1 christos entry $func1_addr "$func1_addr + $func1_len" { 90 1.1 christos DW_OP_constu 0x123456 91 1.1 christos DW_OP_stack_value 92 1.1 christos } 93 1.1 christos entry $func2_addr "$func2_addr + $func2_len" { 94 1.1 christos DW_OP_constu 0x234567 95 1.1 christos DW_OP_stack_value 96 1.1 christos } 97 1.1 christos } 98 1.1 christos } 99 1.1 christos 100 1.1 christos if { [prepare_for_testing "failed to prepare" ${testfile} \ 101 1.1 christos [list $srcfile $asm_file] {nodebug}] } { 102 1.1 christos return -1 103 1.1 christos } 104 1.1 christos 105 1.1 christos if { ![runto_main] } { 106 1.1 christos return 107 1.1 christos } 108 1.1 christos 109 1.1 christos gdb_breakpoint "func1" 110 1.1 christos gdb_breakpoint "func2" 111 1.1 christos 112 1.1 christos gdb_continue_to_breakpoint "func1" 113 1.1 christos with_test_prefix "at func1" { 114 1.1 christos gdb_test "print /x foo" " = 0x123456" 115 1.1 christos } 116 1.1 christos 117 1.1 christos gdb_continue_to_breakpoint "func2" 118 1.1 christos with_test_prefix "at func2" { 119 1.1 christos gdb_test "print /x foo" " = 0x234567" 120 1.1 christos } 121 1.1 christos } 122