Commit | Line | Data |
---|---|---|
e2882c85 | 1 | # Copyright (C) 2014-2018 Free Software Foundation, Inc. |
835c559f 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 doesn't get confused in the following scenario | |
17 | # (PR breakpoints/17000). Say, we have this program: | |
18 | # | |
19 | # => 0xff000001 INSN1 | |
20 | # 0xff000002 INSN2 | |
21 | # | |
22 | # The PC currently points at INSN1. | |
23 | # | |
24 | # 1 - User sets a breakpoint at 0xff000002 (INSN2). | |
25 | # | |
26 | # 2 - User steps. On software single-step archs, this sets a software | |
27 | # single-step breakpoint at 0xff000002 (INSN2) too. | |
28 | # | |
29 | # 3 - User deletes breakpoint (INSN2) before the single-step finishes. | |
30 | # | |
31 | # 4 - The single-step finishes, and GDB removes the single-step | |
32 | # breakpoint. | |
33 | ||
34 | standard_testfile | |
35 | ||
36 | if {[prepare_for_testing "failed to prepare" $testfile $srcfile debug]} { | |
37 | return -1 | |
38 | } | |
39 | ||
40 | if ![runto_main] { | |
bc6c7af4 | 41 | fail "can't run to main" |
835c559f PA |
42 | return 0 |
43 | } | |
44 | ||
c6ec5ab2 PA |
45 | delete_breakpoints |
46 | ||
47 | # With the all-stop RSP, we can't talk to the target while it's | |
48 | # running, until we get back the stop reply. If not using single-step | |
49 | # breakpoints, then the "del" in stepi_del_break below will try to | |
50 | # delete the user breakpoint from the target, which will fail, with | |
51 | # "Cannot execute this command while the target is running.". On | |
52 | # software single-step targets, that del shouldn't trigger any RSP | |
829155c9 PA |
53 | # traffic. Hardware-step targets that can't access memory while the |
54 | # target is running, either remote or native, are likewise affected. | |
55 | # So we just skip the test if not using software single-stepping. We | |
00b51ff5 | 56 | # detect that by looking for 'to_resume (..., step)' in "debug |
829155c9 | 57 | # target" output. |
c6ec5ab2 PA |
58 | |
59 | # Probe for software single-step breakpoint use. | |
829155c9 PA |
60 | |
61 | gdb_test_no_output "set debug target 1" | |
62 | set hardware_step 0 | |
63 | set test "probe target hardware step" | |
c6ec5ab2 | 64 | gdb_test_multiple "si" $test { |
f6ac5f3d | 65 | -re "resume \\(\[^\r\n\]+, step, .*$gdb_prompt $" { |
829155c9 | 66 | set hardware_step 1 |
c6ec5ab2 PA |
67 | pass $test |
68 | } | |
69 | -re "$gdb_prompt $" { | |
70 | pass $test | |
71 | } | |
72 | } | |
73 | ||
829155c9 PA |
74 | if { $hardware_step } { |
75 | unsupported "target doesn't use software single-stepping" | |
c6ec5ab2 PA |
76 | return |
77 | } | |
78 | ||
f6ac5f3d | 79 | gdb_test "set debug target 0" "->log_command.*\\)" |
c6ec5ab2 | 80 | |
835c559f PA |
81 | set line_re "\[^\r\n\]*" |
82 | ||
83 | gdb_test "b test:label" "Breakpoint .*" | |
84 | gdb_continue_to_breakpoint "run past setup" | |
85 | delete_breakpoints | |
86 | ||
87 | # So we can precisely control breakpoint insertion order. | |
88 | gdb_test_no_output "set breakpoint always-inserted on" | |
89 | ||
90 | # Capture disassembly output. PREFIX is used as test prefix. The | |
91 | # current instruction indicator (=>) is stripped away. | |
92 | proc disassemble { prefix } { | |
93 | with_test_prefix "$prefix" { | |
94 | set output [capture_command_output "disassemble test" ""] | |
95 | return [string map {"=>" " "} $output] | |
96 | } | |
97 | } | |
98 | ||
99 | # Issue a stepi and immediately delete the user breakpoint that is set | |
100 | # at the same address as the software single-step breakpoint. Do this | |
101 | # in a user defined command, so that the stepi's trap doesn't have a | |
102 | # chance to be handled before further input is processed. We then | |
103 | # compare before/after disassembly. GDB should be able to handle | |
104 | # deleting the user breakpoint before deleting the single-step | |
105 | # breakpoint. E.g., we shouldn't see breakpoint instructions in the | |
106 | # disassembly. | |
107 | ||
108 | set disasm_before [disassemble "before"] | |
109 | ||
110 | gdb_test "b test:label2" ".*" "set breakpoint where si will land" | |
111 | ||
112 | set test "define stepi_del_break" | |
113 | gdb_test_multiple $test $test { | |
114 | -re "Type commands for definition of \"stepi_del_break\".\r\nEnd with a line saying just \"end\".\r\n>$" { | |
115 | gdb_test "si&\ndel \$bpnum\nend" "" $test | |
116 | } | |
117 | } | |
118 | ||
119 | set command "stepi_del_break" | |
120 | set test $command | |
835c559f PA |
121 | gdb_test_multiple $command $test { |
122 | -re "^$command\r\n$gdb_prompt " { | |
123 | # Note no end anchor, because "si&" finishes and prints the | |
124 | # current frame/line after the prompt is printed. | |
125 | pass $test | |
126 | } | |
127 | } | |
128 | ||
129 | # Now consume the output of the finished "si&". | |
130 | set test "si& finished" | |
131 | gdb_test_multiple "" $test { | |
132 | -re "must be a single line \\\*/\r\n" { | |
133 | pass $test | |
134 | } | |
135 | } | |
136 | ||
137 | set disasm_after [disassemble "after"] | |
138 | ||
139 | set test "before/after disassembly matches" | |
140 | if ![string compare $disasm_before $disasm_after] { | |
141 | pass $test | |
142 | } else { | |
143 | fail $test | |
144 | } |