xref: /netbsd-src/external/gpl3/gdb.old/dist/gdb/testsuite/gdb.base/async.exp (revision 8b657b0747480f8989760d71343d6dd33f8d4cf9)
1#   Copyright 1999-2023 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
21standard_testfile
22
23if {[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#
30if {![runto_main]} {
31    return
32}
33
34gdb_test "break baz" ".*" ""
35
36#
37# Make sure we get a 'completed' message when the target is done.
38#
39gdb_test_no_output "set exec-done-display on"
40
41# Test a background execution command.  COMMAND is the command to
42# send.  BEFORE_PROMPT is the pattern expected before the GDB prompt
43# is output.  AFTER_PROMPT is the pattern expected after the prompt
44# and before "completed".  MESSAGE is optional, and is the pass/fail
45# message to br printed.  If omitted, then the command string is used
46# as message.
47proc test_background {command before_prompt after_prompt {message ""}} {
48    global gdb_prompt
49
50    if {$message eq ""} {
51        set message $command
52    }
53
54    send_gdb "$command\n"
55    gdb_expect {
56	-re "^$command\r\n${before_prompt}${gdb_prompt}${after_prompt}completed\.\r\n" {
57	    pass "$message"
58	    return 0
59	}
60	-re "$gdb_prompt.*completed\.\r\n" {
61	    fail "$message"
62	}
63	-re ".*Asynchronous execution not supported on this target\..*" {
64	    unsupported "asynchronous execution not supported: $message"
65	}
66	timeout  {
67	    fail "$message (timeout)"
68	}
69    }
70    return -1
71}
72
73if {[test_background "next&" "" ".*z = 9.*"] < 0} {
74    return
75}
76
77test_background "step&" "" ".*y = foo \\(\\).*" "step& #1"
78
79test_background "step&" "" " foo \\(\\) at .*async.c.*x = 5.*" "step& #2"
80
81set is_stmt [is_stmt_addresses $srcfile]
82
83# Get the next instruction address.
84set next_insn_addr ""
85set test "get next insn"
86gdb_test_multiple {x/2i $pc} "$test" {
87    -re "=> $hex .* 0x(\[0-9a-f\]*) .*$gdb_prompt $" {
88	set next_insn_addr $expect_out(1,string)
89	pass $gdb_test_name
90    }
91}
92set next_insn_is_stmt [hex_in_list $next_insn_addr $is_stmt]
93
94if { $next_insn_is_stmt } {
95    set prefix ""
96} else {
97    # The current PC is printed out.
98    set prefix "0x0*$next_insn_addr.*"
99}
100test_background "stepi&" "" ".*$prefix x = 5; .*"
101
102# Get the next instruction address.
103set next_insn_addr ""
104set test "get next insn, 2nd"
105gdb_test_multiple {x/2i $pc} "$test" {
106    -re "=> $hex .* 0x(\[0-9a-f\]*) .*$gdb_prompt $" {
107	set next_insn_addr $expect_out(1,string)
108	pass $gdb_test_name
109    }
110}
111set next_insn_is_stmt \
112    [expr [lsearch -regexp $is_stmt 0x0*$next_insn_addr] != -1]
113
114if { $next_insn_is_stmt } {
115    set prefix ""
116} else {
117    # The current PC is printed out.
118    set prefix "0x0*$next_insn_addr.*"
119}
120# We nexti into the same source line.
121test_background "nexti&" "" ".*$prefix x = 5; .*"
122
123if { $next_insn_is_stmt } {
124    set prefix ""
125} else {
126    # PC is in the middle of a source line, so the PC address is displayed.
127    set prefix "0x0*$next_insn_addr in "
128}
129test_background "finish&" \
130    "Run till exit from #0  ${prefix}foo \\(\\) at.*async.c.*\r\n" \
131    ".*$hex in main \\(\\) at.*async.c.*y = foo \\(\\).*Value returned is.*= 8.*"
132
133set jump_here [gdb_get_line_number "jump here"]
134test_background "jump $jump_here&" \
135    ".*Continuing at $hex.*" \
136    ".*Breakpoint 2, baz \\(\\) at.*async.c.*return 5.*" \
137    "jump&"
138
139set until_here [gdb_get_line_number "until here"]
140test_background "until $until_here&" \
141    ".*" \
142    ".*$hex in main \\(\\) at.*async.c.*y = baz \\(\\).*" \
143    "until&"
144
145gdb_test_no_output "set exec-done-display off"
146