]>
Commit | Line | Data |
---|---|---|
1d506c26 | 1 | # Copyright 2014-2024 Free Software Foundation, Inc. |
d03de421 PA |
2 | |
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. | |
7 | # | |
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. | |
12 | # | |
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/>. */ | |
15 | ||
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 | |
19 | # PROGRAM". | |
20 | ||
21 | standard_testfile | |
22 | ||
23 | if {[build_executable "failed to prepare" $testfile $srcfile debug]} { | |
24 | return -1 | |
25 | } | |
26 | ||
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 | |
29 | # the command line. | |
30 | proc test_remove_bp { initial_load } { | |
31 | with_test_prefix "$initial_load" { | |
32 | global srcdir subdir binfile | |
33 | global gdb_prompt hex | |
34 | global GDBFLAGS | |
35 | ||
36 | gdb_exit | |
37 | ||
9dd1e642 | 38 | save_vars { GDBFLAGS } { |
d03de421 | 39 | |
9dd1e642 TV |
40 | # See "used to behave differently" further below. |
41 | if { $initial_load == "file" } { | |
42 | gdb_start | |
43 | gdb_file_cmd $binfile | |
44 | } else { | |
45 | global last_loaded_file | |
d03de421 | 46 | |
9dd1e642 TV |
47 | # gdb_file_cmd sets this. This is what gdb_reload |
48 | # implementations use as binary. | |
49 | set last_loaded_file $binfile | |
d03de421 | 50 | |
9dd1e642 TV |
51 | set GDBFLAGS "$GDBFLAGS $binfile" |
52 | gdb_start | |
53 | } | |
54 | gdb_reinitialize_dir $srcdir/$subdir | |
55 | gdb_reload | |
d03de421 | 56 | } |
d03de421 PA |
57 | |
58 | if ![runto start] { | |
d03de421 PA |
59 | return |
60 | } | |
61 | ||
62 | delete_breakpoints | |
63 | ||
64 | # So we can easily control when are breakpoints removed. | |
65 | gdb_test_no_output "set breakpoint always-inserted on" | |
66 | ||
67 | set bp_addr "" | |
68 | ||
69 | set test "break foo" | |
70 | gdb_test_multiple $test $test { | |
71 | -re "Breakpoint .* at ($hex).*$gdb_prompt $" { | |
72 | set bp_addr $expect_out(1,string) | |
73 | pass $test | |
74 | } | |
75 | } | |
76 | ||
77 | if {$bp_addr == ""} { | |
78 | unsupported "can't extract foo's address" | |
79 | return | |
80 | } | |
81 | ||
82 | gdb_test "info break" "y.*$hex.*in foo at.*" \ | |
83 | "breakpoint is set" | |
84 | ||
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] | |
6d0aebbc TV |
90 | set munmap_prototype "int (*) (void *, size_t)" |
91 | set munmap_expr "(($munmap_prototype) munmap) ($align_addr, $pagesize)" | |
e2fe3cbd AB |
92 | |
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. | |
101 | set munmap -1 | |
102 | gdb_test_multiple "print /d ${munmap_expr}" "get result of munmap call" { | |
a500c3d8 | 103 | -re -wrap "^(?:warning: error removing breakpoint $::decimal at $::hex\r\n)?\\$\[0-9\]* = (\[-\]*\[0-9\]*).*" { |
e2fe3cbd AB |
104 | set munmap $expect_out(1,string) |
105 | pass $gdb_test_name | |
106 | } | |
107 | } | |
d03de421 PA |
108 | |
109 | if {$munmap != 0} { | |
110 | unsupported "can't munmap foo's page" | |
111 | return | |
112 | } | |
113 | ||
114 | gdb_test "delete \$bpnum" \ | |
a500c3d8 | 115 | "^warning: error removing breakpoint $::decimal at $::hex" \ |
d03de421 PA |
116 | "failure to remove breakpoint warns" |
117 | } | |
118 | } | |
119 | ||
120 | foreach initial_load { "cmdline" "file" } { | |
121 | test_remove_bp $initial_load | |
122 | } |