Add translations for various sub-directories
[binutils-gdb.git] / gdb / testsuite / gdb.dwarf2 / missing-line-table.exp
blob77618dea82436066ee3323713488a3b93ff881d4
1 # Copyright 2023-2024 Free Software Foundation, Inc.
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.
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.
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/>.
16 # Create a compilation unit containing two functions (the CU's
17 # low/high pc range will include both functions), but define a line
18 # table that only covers one of the functions.
20 # Use GDB to try and place a breakpoint in both functions.  GDB should
21 # correctly find some address within both functions at which to place
22 # a breakpoint.
24 load_lib dwarf.exp
26 # This test can only be run on targets which support the DWARF
27 # assembler.
28 require dwarf2_support
30 standard_testfile .c -dw.S
32 get_func_info main
33 get_func_info foo
35 set asm_file [standard_output_file $srcfile2]
36 Dwarf::assemble $asm_file {
37     declare_labels Llines
39     cu {} {
40         compile_unit {
41             {language @DW_LANG_C}
42             {name missing-line-table.c}
43             {stmt_list $Llines DW_FORM_sec_offset}
44             {DW_AT_low_pc $::foo_start DW_FORM_addr}
45             {DW_AT_high_pc $::main_end DW_FORM_addr}
46         } {
47             subprogram {
48                 {external 1 flag}
49                 {MACRO_AT_func {main}}
50             }
51             subprogram {
52                 {external 1 flag}
53                 {MACRO_AT_func {foo}}
54             }
55         }
56     }
58     lines {version 2} Llines {
59         include_dir "${::srcdir}/${::subdir}"
60         file_name "$::srcfile" 1
62         program {
63             DW_LNE_set_address main
64             line [gdb_get_line_number "L1"]
65             DW_LNS_copy
67             DW_LNE_set_address main_label
68             line [gdb_get_line_number "L2"]
69             DW_LNS_copy
71             DW_LNE_set_address main_label_2
72             line [gdb_get_line_number "L3"]
73             DW_LNS_copy
75             DW_LNE_set_address "$::main_start + $::main_len"
76             DW_LNE_end_sequence
77         }
78     }
81 if { [prepare_for_testing "failed to prepare" ${testfile} \
82           [list $srcfile $asm_file] {nodebug}] } {
83     return -1
86 # Place a breakpoint on FUNC.  Check that the address at which the
87 # breakpoint is placed lies within FUNC which is starts at address
88 # START, and address END is the first address after FUNC.
89 proc check_breakpoint { func start end } {
90     with_test_prefix "func=$func" {
91         set addr "*unknown*"
92         gdb_test_multiple "break $func" "place breakpoint" {
93             -re -wrap "Breakpoint $::decimal at ($::hex)(?:: \[^\r\n\]+)?" {
94                 set addr $expect_out(1,string)
95                 pass $gdb_test_name
96             }
97         }
99         verbose -log "breakpoint at: $addr"
100         verbose -log "$func start: $start, $func end: $end"
102         gdb_assert {$addr >= $start && $addr < $end} \
103             "check breakpoint address is within function"
104     }
107 # The get_func_info calls declare the function start/end in terms of a
108 # program label and offsets, but we now need these as actual
109 # addresses.  As the program is running, this can be done easily by
110 # asking GDB to evaluate each in turn.
111 foreach func {foo main} {
112     foreach part {start end} {
113         set ${func}_${part} \
114             [get_hexadecimal_valueof [set ${func}_${part}] "??" \
115                  "get value of ${func}_${part}"]
116     }
119 # Place breakpoints within 'foo' and 'main', and check that the
120 # breakpoint is actually placed within the function.
121 check_breakpoint "foo" $foo_start $foo_end
122 check_breakpoint "main" $main_start $main_end