Commit | Line | Data |
---|---|---|
b811d2c2 | 1 | # Copyright 1999-2020 Free Software Foundation, Inc. |
104c1213 JM |
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 | |
e22f8b7c | 5 | # the Free Software Foundation; either version 3 of the License, or |
104c1213 | 6 | # (at your option) any later version. |
e22f8b7c | 7 | # |
104c1213 JM |
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. | |
e22f8b7c | 12 | # |
104c1213 | 13 | # You should have received a copy of the GNU General Public License |
e22f8b7c | 14 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
104c1213 | 15 | |
104c1213 | 16 | |
104c1213 JM |
17 | # |
18 | # test running programs | |
19 | # | |
104c1213 | 20 | |
a64d2530 | 21 | standard_testfile |
104c1213 | 22 | |
5b362f04 | 23 | if {[prepare_for_testing "failed to prepare" $testfile $srcfile debug]} { |
148e57e2 PA |
24 | return -1 |
25 | } | |
104c1213 JM |
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 | ||
de7ff789 | 35 | gdb_test "break baz" ".*" "" |
104c1213 JM |
36 | |
37 | # | |
38 | # Make sure we get a 'completed' message when the target is done. | |
39 | # | |
0172b6a7 | 40 | gdb_test_no_output "set exec-done-display on" |
104c1213 | 41 | |
884e37dc PA |
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" | |
5fc2beac | 59 | return 0 |
884e37dc | 60 | } |
8bcfb00a | 61 | -re "$gdb_prompt.*completed\.\r\n" { |
884e37dc PA |
62 | fail "$message" |
63 | } | |
5fc2beac | 64 | -re ".*Asynchronous execution not supported on this target\..*" { |
bc6c7af4 | 65 | unsupported "asynchronous execution not supported: $message" |
5fc2beac | 66 | } |
884e37dc PA |
67 | timeout { |
68 | fail "$message (timeout)" | |
69 | } | |
70 | } | |
5fc2beac | 71 | return -1 |
104c1213 JM |
72 | } |
73 | ||
5fc2beac KB |
74 | if {[test_background "next&" "" ".*z = 9.*"] < 0} { |
75 | return | |
76 | } | |
104c1213 | 77 | |
6048b950 | 78 | test_background "step&" "" ".*y = foo \\(\\).*" "step& #1" |
104c1213 | 79 | |
6048b950 | 80 | test_background "step&" "" " foo \\(\\) at .*async.c.*x = 5.*" "step& #2" |
104c1213 | 81 | |
7c99e7e2 | 82 | set is_stmt [is_stmt_addresses $srcfile] |
104c1213 | 83 | |
e5e01dbf YQ |
84 | # Get the next instruction address. |
85 | set next_insn_addr "" | |
86 | set test "get next insn" | |
87 | gdb_test_multiple {x/2i $pc} "$test" { | |
88 | -re "=> $hex .* 0x(\[0-9a-f\]*) .*$gdb_prompt $" { | |
89 | set next_insn_addr $expect_out(1,string) | |
90 | pass "$test" | |
91 | } | |
92 | } | |
7c99e7e2 | 93 | set next_insn_is_stmt [hex_in_list $next_insn_addr $is_stmt] |
6015a067 TV |
94 | |
95 | if { $next_insn_is_stmt } { | |
96 | set prefix "" | |
97 | } else { | |
98 | # The current PC is printed out. | |
99 | set prefix "0x0*$next_insn_addr.*" | |
100 | } | |
101 | test_background "stepi&" "" ".*$prefix x = 5; .*" | |
e5e01dbf | 102 | |
6015a067 TV |
103 | # Get the next instruction address. |
104 | set next_insn_addr "" | |
105 | set test "get next insn" | |
106 | gdb_test_multiple {x/2i $pc} "$test" { | |
107 | -re "=> $hex .* 0x(\[0-9a-f\]*) .*$gdb_prompt $" { | |
108 | set next_insn_addr $expect_out(1,string) | |
109 | pass "$test" | |
110 | } | |
111 | } | |
112 | set next_insn_is_stmt \ | |
113 | [expr [lsearch -regexp $is_stmt 0x0*$next_insn_addr] != -1] | |
114 | ||
115 | if { $next_insn_is_stmt } { | |
116 | set prefix "" | |
117 | } else { | |
118 | # The current PC is printed out. | |
119 | set prefix "0x0*$next_insn_addr.*" | |
120 | } | |
121 | # We nexti into the same source line. | |
122 | test_background "nexti&" "" ".*$prefix x = 5; .*" | |
123 | ||
124 | if { $next_insn_is_stmt } { | |
125 | set prefix "" | |
126 | } else { | |
127 | # PC is in the middle of a source line, so the PC address is displayed. | |
128 | set prefix "0x0*$next_insn_addr in " | |
129 | } | |
884e37dc | 130 | test_background "finish&" \ |
6015a067 | 131 | "Run till exit from #0 ${prefix}foo \\(\\) at.*async.c.*\r\n" \ |
884e37dc | 132 | ".*$hex in main \\(\\) at.*async.c.*y = foo \\(\\).*Value returned is.*= 8.*" |
e2f6c966 | 133 | |
884e37dc PA |
134 | set jump_here [gdb_get_line_number "jump here"] |
135 | test_background "jump $jump_here&" \ | |
136 | ".*Continuing at $hex.*" \ | |
137 | ".*Breakpoint 2, baz \\(\\) at.*async.c.*return 5.*" \ | |
138 | "jump&" | |
104c1213 | 139 | |
e2f6c966 | 140 | set until_here [gdb_get_line_number "until here"] |
884e37dc PA |
141 | test_background "until $until_here&" \ |
142 | ".*" \ | |
143 | ".*$hex in main \\(\\) at.*async.c.*y = baz \\(\\).*" \ | |
144 | "until&" | |
104c1213 | 145 | |
0172b6a7 | 146 | gdb_test_no_output "set exec-done-display off" |