[gdb/testsuite] Fix gdb.base/async.exp with gcc-8
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / async.exp
1 # Copyright 1999-2020 Free Software Foundation, Inc.
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
17 #
18 # test running programs
19 #
20
21 standard_testfile
22
23 if {[prepare_for_testing "failed to prepare" $testfile $srcfile debug]} {
24 return -1
25 }
26
27 #
28 # set it up at a breakpoint so we can play with it
29 #
30 if ![runto_main] then {
31 perror "couldn't run to breakpoint"
32 continue
33 }
34
35 gdb_test "break baz" ".*" ""
36
37 #
38 # Make sure we get a 'completed' message when the target is done.
39 #
40 gdb_test_no_output "set exec-done-display on"
41
42 # Test a background execution command. COMMAND is the command to
43 # send. BEFORE_PROMPT is the pattern expected before the GDB prompt
44 # is output. AFTER_PROMPT is the pattern expected after the prompt
45 # and before "completed". MESSAGE is optional, and is the pass/fail
46 # message to br printed. If omitted, then the command string is used
47 # as message.
48 proc test_background {command before_prompt after_prompt {message ""}} {
49 global gdb_prompt
50
51 if {$message eq ""} {
52 set message $command
53 }
54
55 send_gdb "$command\n"
56 gdb_expect {
57 -re "^$command\r\n${before_prompt}${gdb_prompt}${after_prompt}completed\.\r\n" {
58 pass "$message"
59 return 0
60 }
61 -re "$gdb_prompt.*completed\.\r\n" {
62 fail "$message"
63 }
64 -re ".*Asynchronous execution not supported on this target\..*" {
65 unsupported "asynchronous execution not supported: $message"
66 }
67 timeout {
68 fail "$message (timeout)"
69 }
70 }
71 return -1
72 }
73
74 if {[test_background "next&" "" ".*z = 9.*"] < 0} {
75 return
76 }
77
78 test_background "step&" "" ".*y = foo \\(\\).*" "step& #1"
79
80 test_background "step&" "" " foo \\(\\) at .*async.c.*x = 5.*" "step& #2"
81
82 set is_stmt [list]
83 gdb_test_multiple "maint info line-table async.c" "" {
84 -re "\r\n$decimal\[ \t\]+$decimal\[ \t\]+($hex)\[ \t\]+Y\[^\r\n\]*" {
85 lappend is_stmt $expect_out(1,string)
86 exp_continue
87 }
88 -re -wrap "" {
89 pass $gdb_test_name
90 }
91 }
92
93 # Get the next instruction address.
94 set next_insn_addr ""
95 set test "get next insn"
96 gdb_test_multiple {x/2i $pc} "$test" {
97 -re "=> $hex .* 0x(\[0-9a-f\]*) .*$gdb_prompt $" {
98 set next_insn_addr $expect_out(1,string)
99 pass "$test"
100 }
101 }
102 set next_insn_is_stmt \
103 [expr [lsearch -regexp $is_stmt 0x0*$next_insn_addr] != -1]
104
105 if { $next_insn_is_stmt } {
106 set prefix ""
107 } else {
108 # The current PC is printed out.
109 set prefix "0x0*$next_insn_addr.*"
110 }
111 test_background "stepi&" "" ".*$prefix x = 5; .*"
112
113 # Get the next instruction address.
114 set next_insn_addr ""
115 set test "get next insn"
116 gdb_test_multiple {x/2i $pc} "$test" {
117 -re "=> $hex .* 0x(\[0-9a-f\]*) .*$gdb_prompt $" {
118 set next_insn_addr $expect_out(1,string)
119 pass "$test"
120 }
121 }
122 set next_insn_is_stmt \
123 [expr [lsearch -regexp $is_stmt 0x0*$next_insn_addr] != -1]
124
125 if { $next_insn_is_stmt } {
126 set prefix ""
127 } else {
128 # The current PC is printed out.
129 set prefix "0x0*$next_insn_addr.*"
130 }
131 # We nexti into the same source line.
132 test_background "nexti&" "" ".*$prefix x = 5; .*"
133
134 if { $next_insn_is_stmt } {
135 set prefix ""
136 } else {
137 # PC is in the middle of a source line, so the PC address is displayed.
138 set prefix "0x0*$next_insn_addr in "
139 }
140 test_background "finish&" \
141 "Run till exit from #0 ${prefix}foo \\(\\) at.*async.c.*\r\n" \
142 ".*$hex in main \\(\\) at.*async.c.*y = foo \\(\\).*Value returned is.*= 8.*"
143
144 set jump_here [gdb_get_line_number "jump here"]
145 test_background "jump $jump_here&" \
146 ".*Continuing at $hex.*" \
147 ".*Breakpoint 2, baz \\(\\) at.*async.c.*return 5.*" \
148 "jump&"
149
150 set until_here [gdb_get_line_number "until here"]
151 test_background "until $until_here&" \
152 ".*" \
153 ".*$hex in main \\(\\) at.*async.c.*y = baz \\(\\).*" \
154 "until&"
155
156 gdb_test_no_output "set exec-done-display off"
This page took 0.032847 seconds and 4 git commands to generate.