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 line number information in various configurations. 17 1.1 christos 18 1.1 christos load_lib dwarf.exp 19 1.1 christos 20 1.1 christos # This test can only be run on targets which support DWARF-2 and use gas. 21 1.1 christos require dwarf2_support 1 22 1.1 christos 23 1.1 christos standard_testfile .c 24 1.1 christos 25 1.1 christos with_shared_gdb { 26 1.1 christos set func_info_vars \ 27 1.1 christos [concat \ 28 1.1 christos [get_func_info main] \ 29 1.1 christos [get_func_info bar]] 30 1.1 christos } 31 1.1 christos 32 1.1 christos # Helper function. 33 1.1 christos proc line_for { l } { 34 1.1 christos global srcfile 35 1.1 christos set line [gdb_get_line_number "$l:" $srcfile] 36 1.1 christos return [expr $line + 1] 37 1.1 christos } 38 1.1 christos 39 1.1 christos # Execute test. 40 1.1 christos proc test_1 { _cv _cdw64 _lv _ldw64 {_string_form ""}} { 41 1.1 christos global srcfile srcfile2 testfile 42 1.1 christos global cv cdw64 lv ldw64 string_form 43 1.1 christos set cv $_cv 44 1.1 christos set cdw64 $_cdw64 45 1.1 christos set lv $_lv 46 1.1 christos set ldw64 $_ldw64 47 1.1 christos set string_form $_string_form 48 1.1 christos 49 1.1 christos standard_testfile .c [prefix_id]-dw.S 50 1.1 christos 51 1.1 christos set asm_file [standard_output_file $srcfile2] 52 1.1 christos Dwarf::assemble $asm_file { 53 1.1 christos declare_labels Llines 54 1.1 christos global srcdir subdir srcfile cv cdw64 lv ldw64 string_form 55 1.1 christos global func_info_vars 56 1.1 christos foreach var $func_info_vars { 57 1.1 christos global $var 58 1.1 christos } 59 1.1 christos 60 1.1 christos cu { version $cv is_64 $cdw64 } { 61 1.1 christos compile_unit { 62 1.1 christos {language @DW_LANG_C} 63 1.1 christos {name $srcfile} 64 1.1 christos {stmt_list $Llines DW_FORM_sec_offset} 65 1.1 christos } { 66 1.1 christos subprogram { 67 1.1 christos {external 1 flag} 68 1.1 christos {name main} 69 1.1 christos {low_pc $main_start addr} 70 1.1 christos {high_pc "$main_start + $main_len" addr} 71 1.1 christos } 72 1.1 christos subprogram { 73 1.1 christos {external 1 flag} 74 1.1 christos {name bar} 75 1.1 christos {low_pc $bar_start addr} 76 1.1 christos {high_pc "$bar_start + $bar_len" addr} 77 1.1 christos } 78 1.1 christos } 79 1.1 christos } 80 1.1 christos 81 1.1 christos lines [list version $lv is_64 $ldw64 string_form $string_form] Llines { 82 1.1 christos set diridx [include_dir "${srcdir}/${subdir}"] 83 1.1 christos file_name "$srcfile" $diridx 84 1.1 christos 85 1.1 christos program { 86 1.1 christos # If using DWARF 5, we want to refer to file 0, but the LNP 87 1.1 christos # state machine is still initialized with file 1. So we need 88 1.1 christos # to set the current file explicitly. 89 1.1 christos DW_LNS_set_file $diridx 90 1.1 christos 91 1.1 christos DW_LNE_set_address bar_label 92 1.1 christos line [line_for bar_label] 93 1.1 christos DW_LNS_copy 94 1.1 christos 95 1.1 christos DW_LNE_set_address bar_label_2 96 1.1 christos line [line_for bar_label_2] 97 1.1 christos DW_LNS_copy 98 1.1 christos 99 1.1 christos DW_LNE_set_address bar_label_3 100 1.1 christos line [line_for bar_label_3] 101 1.1 christos DW_LNS_copy 102 1.1 christos 103 1.1 christos DW_LNE_set_address bar_label_4 104 1.1 christos line [line_for bar_label_4] 105 1.1 christos DW_LNS_copy 106 1.1 christos 107 1.1 christos DW_LNE_set_address bar_label_5 108 1.1 christos DW_LNE_end_sequence 109 1.1 christos } 110 1.1 christos } 111 1.1 christos } 112 1.1 christos 113 1.1 christos if { [prepare_for_testing "failed to prepare" ${testfile}.[prefix_id] \ 114 1.1 christos [list $srcfile $asm_file] {nodebug}] } { 115 1.1 christos return -1 116 1.1 christos } 117 1.1 christos 118 1.1 christos if ![runto_main] { 119 1.1 christos return -1 120 1.1 christos } 121 1.1 christos 122 1.1 christos gdb_breakpoint "bar_label" 123 1.1 christos gdb_continue_to_breakpoint "foo \\(1\\)" 124 1.1 christos 125 1.1 christos gdb_test "next" "foo \\(2\\).*" "next to foo (2)" 126 1.1 christos gdb_test "next" "foo \\(3\\).*" "next to foo (3)" 127 1.1 christos gdb_test "next" "foo \\(4\\).*" "next to foo (4)" 128 1.1 christos } 129 1.1 christos 130 1.1 christos 131 1.1 christos # Add unique test prefix. 132 1.1 christos proc test { cv cdw64 lv ldw64 {string_form ""}} { 133 1.1 christos with_test_prefix cv=$cv { 134 1.1 christos with_test_prefix cdw=[expr $cdw64 ? 64 : 32] { 135 1.1 christos with_test_prefix lv=$lv { 136 1.1 christos with_test_prefix ldw=[expr $ldw64 ? 64 : 32] { 137 1.1 christos if { $string_form == "" } { 138 1.1 christos test_1 $cv $cdw64 $lv $ldw64 139 1.1 christos } else { 140 1.1 christos with_test_prefix string_form=$string_form { 141 1.1 christos test_1 $cv $cdw64 $lv $ldw64 $string_form 142 1.1 christos } 143 1.1 christos } 144 1.1 christos } 145 1.1 christos } 146 1.1 christos } 147 1.1 christos } 148 1.1 christos } 149 1.1 christos 150 1.1 christos set cv_low 2 151 1.1 christos set cv_high 4 152 1.1 christos 153 1.1 christos set lv_low 2 154 1.1 christos set lv_high 4 155 1.1 christos 156 1.1 christos for { set cv $cv_low } { $cv <= $cv_high } { incr cv } { 157 1.1 christos for { set lv $lv_low } { $lv <= $lv_high } { incr lv } { 158 1.1 christos # I'm not sure if it makes sense to have a dwarf vx CU with 159 1.1 christos # a dwarf vx+1 line unit. 160 1.1 christos if { $lv > $lv } { 161 1.1 christos continue 162 1.1 christos } 163 1.1 christos 164 1.1 christos foreach cdw64 { 0 1 } { 165 1.1 christos foreach ldw64 { 0 1 } { 166 1.1 christos test $cv $cdw64 $lv $ldw64 167 1.1 christos } 168 1.1 christos } 169 1.1 christos } 170 1.1 christos } 171 1.1 christos 172 1.1 christos foreach cdw64 { 0 1 } { 173 1.1 christos foreach ldw64 { 0 1 } { 174 1.1 christos test 5 $cdw64 5 $ldw64 string 175 1.1 christos test 5 $cdw64 5 $ldw64 line_strp 176 1.1 christos } 177 1.1 christos } 178