1 # Copyright
2014-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 # Test that GDB isn
't silent if it fails to remove a breakpoint from
17 # the main program, independently of whether the program was loaded
18 # with "file PROGRAM" or directly from the command line with "gdb
23 if {[build_executable "failed to prepare" $testfile $srcfile debug]} {
27 # Run the test proper. INITIAL_LOAD determines whether the program is
28 # initially loaded by the "file" command or by passing it to GDB on
30 proc test_remove_bp { initial_load } {
31 with_test_prefix "$initial_load" {
32 global srcdir subdir binfile
38 save_vars { GDBFLAGS } {
40 # See "used to behave differently" further below.
41 if { $initial_load == "file" } {
45 global last_loaded_file
47 # gdb_file_cmd sets this. This is what gdb_reload
48 # implementations use as binary.
49 set last_loaded_file $binfile
51 set GDBFLAGS "$GDBFLAGS $binfile"
54 gdb_reinitialize_dir $srcdir/$subdir
64 # So we can easily control when are breakpoints removed.
65 gdb_test_no_output "set breakpoint always-inserted on"
70 gdb_test_multiple $test $test {
71 -re "Breakpoint .* at ($hex).*$gdb_prompt $" {
72 set bp_addr $expect_out(1,string)
78 unsupported "can't extract foo
's address"
82 gdb_test "info break" "y.*$hex.*in foo at.*" \
85 # Now unmap the page where the breakpoint is set. Trying to
86 # remove the memory breakpoint afterwards should fail, and GDB
87 # should warn the user about it.
88 set pagesize [get_integer_valueof "pg_size" 0]
89 set align_addr [expr $bp_addr - $bp_addr % $pagesize]
90 set munmap_prototype "int (*) (void *, size_t)"
91 set munmap_expr "(($munmap_prototype) munmap) ($align_addr, $pagesize)"
93 # Use gdb_test_multiple here rather than get_integer_valueof.
94 # Targets that use the AT_ENTRY_POINT strategy for inferior
95 # function calls will place a breakpoint near the entry point
96 # to catch the return from the inferior function call, and
97 # this is likely on the page we are about to unmap. As a
98 # consequence we will see the warning about being unable to
99 # remove the breakpoint here, which throws off
100 # get_integer_valueof.
102 gdb_test_multiple "print /d ${munmap_expr}" "get result of munmap call" {
103 -re -wrap "^(?:warning: error removing breakpoint $::decimal at $::hex\r\n)?\\$\[0-9\]* = (\[-\]*\[0-9\]*).*" {
104 set munmap $expect_out(1,string)
110 unsupported "can't munmap foo
's page"
114 gdb_test "delete \$bpnum" \
115 "^warning: error removing breakpoint $::decimal at $::hex" \
116 "failure to remove breakpoint warns"
120 foreach initial_load { "cmdline" "file" } {
121 test_remove_bp $initial_load