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
26 # This test can only be run on targets which support the DWARF
28 require dwarf2_support
30 standard_testfile .c -dw.S
35 set asm_file [standard_output_file $srcfile2]
36 Dwarf::assemble $asm_file {
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}
49 {MACRO_AT_func {main}}
58 lines {version 2} Llines {
59 include_dir "${::srcdir}/${::subdir}"
60 file_name "$::srcfile" 1
63 DW_LNE_set_address main
64 line [gdb_get_line_number "L1"]
67 DW_LNE_set_address main_label
68 line [gdb_get_line_number "L2"]
71 DW_LNE_set_address main_label_2
72 line [gdb_get_line_number "L3"]
75 DW_LNE_set_address "$::main_start + $::main_len"
81 if { [prepare_for_testing "failed to prepare" ${testfile} \
82 [list $srcfile $asm_file] {nodebug}] } {
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" {
92 gdb_test_multiple "break $func" "place breakpoint" {
93 -re -wrap "Breakpoint $::decimal at ($::hex)(?:: \[^\r\n\]+)?" {
94 set addr $expect_out(1,string)
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"
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}"]
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