1# Copyright 2002-2017 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# This file tests that GDB's console can be accessed via the MI. 17# Specifically, we are testing the "interpreter-exec" command and that 18# the commands that are executed via this command are properly executed. 19# Console commands executed via MI should use MI output wrappers, MI event 20# handlers, etc. 21 22load_lib mi-support.exp 23set MIFLAGS "-i=mi" 24 25gdb_exit 26if [mi_gdb_start] { 27 continue 28} 29 30standard_testfile basics.c 31 32if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } { 33 untested "failed to compile" 34 return -1 35} 36 37mi_gdb_test "-interpreter-exec" \ 38 {\^error,msg="-interpreter-exec: Usage: -interpreter-exec interp command"} \ 39 "-interpreter-exec with no arguments" 40 41mi_gdb_test "-interpreter-exec console" \ 42 {\^error,msg="-interpreter-exec: Usage: -interpreter-exec interp command"} \ 43 "-interpreter-exec with one argument" 44 45mi_gdb_test "-interpreter-exec bogus command" \ 46 {\^error,msg="-interpreter-exec: could not find interpreter \\\"bogus\\\""} \ 47 "-interpreter-exec with bogus interpreter" 48 49set msg {Undefined command: \\\"bogus\\\"\. Try \\\"help\\\"\.} 50mi_gdb_test "-interpreter-exec console bogus" \ 51 "&\\\"$msg\\\\n\\\".*\\^error,msg=\\\"$msg\\\".*" \ 52 "-interpreter-exec console bogus" 53 54# NOTE: cagney/2003-02-03: Not yet. 55# mi_gdb_test "-interpreter-exec console \"file $binfile\"" \ 56# {(=.*)+\^done} \ 57# "-interpreter-exec console \"file \$binfile\"" 58mi_gdb_test "-interpreter-exec console \"file $binfile\"" \ 59 {~"Reading symbols from .*mi-cli...".*\^done} \ 60 "-interpreter-exec console \"file \$binfile\"" 61 62mi_run_to_main 63 64set line_main_head [gdb_get_line_number "main ("] 65set line_main_body [expr $line_main_head + 2] 66set line_main_hello [gdb_get_line_number "Hello, World!"] 67set line_main_return [expr $line_main_hello + 2] 68set line_main_callme_2 [expr $line_main_return + 1] 69set line_callee4_head [gdb_get_line_number "callee4 ("] 70set line_callee4_body [expr $line_callee4_head + 2] 71set line_callee4_next [expr $line_callee4_body + 1] 72set line_callee4_next_step [expr $line_callee4_next + 3] 73 74mi_gdb_test "-interpreter-exec console \"set args foobar\"" \ 75 ".*=cmd-param-changed,param=\"args\",value=\"foobar\".*\\^done" \ 76 "-interpreter-exec console \"set args foobar\"" 77 78mi_gdb_test "-interpreter-exec console \"show args\"" \ 79 {\~"Argument list to give program being debugged when it is started is \\\"foobar\\\"\.\\n".*\^done} \ 80 "-interpreter-exec console \"show args\"" 81 82mi_gdb_test "-interpreter-exec console \"break callee4\"" \ 83 {(&.*)*.*~"Breakpoint 2 at.*\\n".*=breakpoint-created,bkpt=\{number="2",type="breakpoint".*\}.*\n\^done} \ 84 "-interpreter-exec console \"break callee4\"" 85 86mi_gdb_test "-interpreter-exec console \"info break\"" \ 87 {\~"Num[ \t]*Type[ \t]*Disp[ \t]*Enb[ \t]*Address[ \t]*What\\n".*~"2[ \t]*breakpoint[ \t]*keep[ \t]*y[ \t]*0x[0-9A-Fa-f]+[ \t]*in callee4 at .*basics.c:[0-9]+\\n".*\^done} \ 88 "-interpreter-exec console \"info break\"" 89 90mi_gdb_test "-interpreter-exec console \"set listsize 1\"" \ 91 ".*=cmd-param-changed,param=\"listsize\",value=\"1\".*\\^done" \ 92 "-interpreter-exec console \"set listsize 1\"" 93 94# {.*\~"32[ \t(\\t)]*callee1.*\\n".*\^done } 95mi_gdb_test "-interpreter-exec console \"list\"" \ 96 ".*\~\"$line_main_body\[\\\\t \]*callee1.*;\\\\n\".*\\^done" \ 97 "-interpreter-exec console \"list\"" 98 99mi_execute_to "exec-continue" "breakpoint-hit" "callee4" "" ".*basics.c" $line_callee4_body \ 100 { "" "disp=\"keep\"" } \ 101 "continue to callee4" 102 103mi_gdb_test "100-interpreter-exec console \"delete 2\"" \ 104 {.*=breakpoint-deleted,id=\"2\".*\^done} \ 105 "-interpreter-exec console \"delete 2\"" 106 107# NOTE: cagney/2003-02-03: Not yet. 108# mi_gdb_test "200-interpreter-exec console \"up\"" \ 109# {.*=selected-frame-level-changed,level="1".*\^done} \ 110# "-interpreter-exec console \"up\"" 111mi_gdb_test "200-interpreter-exec console \"up\"" \ 112 {~"#.*".*200\^done} \ 113 "-interpreter-exec console \"up\"" 114 115# NOTE: cagney/2003-02-03: Not yet. 116# mi_gdb_test "300-interpreter-exec console \"down\"" \ 117# {.*=selected-frame-level-changed,level="0".*\^done} \ 118# "-interpreter-exec console \"down\"" 119mi_gdb_test "300-interpreter-exec console \"down\"" \ 120 {~"#.*".*300\^done} \ 121 "-interpreter-exec console \"down\"" 122 123# NOTE: cagney/2003-02-03: Not yet. 124# mi_gdb_test "-interpreter-exec console \"frame 2\"" \ 125# {.*=selected-frame-level-changed,level="2".*\^done} \ 126# "-interpreter-exec console \"frame 2\"" 127mi_gdb_test "400-interpreter-exec console \"frame 2\"" \ 128 {~"#.*".*400\^done} \ 129 "-interpreter-exec console \"frame 2\"" 130 131# NOTE: cagney/2003-02-03: Not yet. 132# mi_gdb_test "-stack-select-frame 0" \ 133# {.*=selected-frame-level-changed,level="0".*\^done} \ 134# "-stack-select-frame 0" 135mi_gdb_test "500-stack-select-frame 0" \ 136 {500\^done} \ 137 "-stack-select-frame 0" 138 139mi_execute_to "interpreter-exec console step" "end-stepping-range" "callee4" "" ".*basics.c" $line_callee4_next \ 140 "" "check *stopped from CLI command" 141 142mi_send_resuming_command "exec-step" "-exec-step to line \$line_callee4_next_step" 143 144# Test that the new current source line is _not_ output, given we 145# executed MI's -exec-next, not CLI's 'next' command. 146 147set output [mi_gdb_expect_cli_output "\\*stopped" "collect CLI output for -exec-step"] 148 149set test "-exec-step does not produce CLI step output" 150if {[regexp "A + B" "$output"]} { 151 fail $test 152} else { 153 pass $test 154} 155 156mi_expect_stop "end-stepping-range" "callee4" "" ".*basics.c" $line_callee4_next_step \ 157 "" "check *stopped from CLI command 2" 158 159# Test that CLI's "finish" command prints the function's return value 160# to both the CLI and MI streams, and that the same result variable is 161# printed to both streams. 162with_test_prefix "CLI finish" { 163 mi_send_resuming_command "interpreter-exec console finish" "send CLI command" 164 165 set output [mi_gdb_expect_cli_output "\\*stopped" "collect CLI output"] 166 gdb_assert {[regexp \ 167 "callee3 .* at .*basics.c:.*.*Value returned is .1 = 0\\\\n" \ 168 $output]} \ 169 "check CLI output" 170 171 mi_expect_stop "function-finished" "callee3" ".*" \ 172 ".*basics.c" ".*" \ 173 ",gdb-result-var=\".1\",return-value=\"0\"" \ 174 "check MI output" 175} 176 177mi_gdb_test "600-break-insert -t basics.c:$line_main_hello" \ 178 {600\^done,bkpt=.number="3",type="breakpoint".*\}} \ 179 "-break-insert -t basics.c:\$line_main_hello" 180 181# Test that breakpoint events are always mirrored to the CLI output 182# stream (both sync and async modes). 183mi_send_resuming_command "exec-continue" "-exec-continue to line \$line_main_hello" 184 185set output [mi_gdb_expect_cli_output "\\*stopped" "collect CLI output for breakpoint hit"] 186set test "breakpoint hit produces CLI output" 187set pattern "\\\\nTemporary breakpoint 3, main \\(\\) at \[^\n\]*basics.c:$line_main_hello\\\\n\[^\n\]+Hello" 188 189if {[regexp $pattern $output]} { 190 pass $test 191} else { 192 fail $test 193} 194 195# Test the MI output. 196mi_expect_stop "breakpoint-hit" "main" "" ".*basics.c" \ 197 $line_main_hello { "" "disp=\"del\"" } "temporary breakpoint output hit in MI" 198 199# Test that the token is output even for CLI commands 200# Also test that *stopped includes frame information. 201mi_gdb_test "34 next" \ 202 ".*34\\\^running.*\\*running,thread-id=\"all\"" \ 203 "34 next: run" 204 205# Test that the new current source line is output to the console 206# stream, given we executed the console 'next' command, not 207# -exec-next. 208set test "34 next: CLI output" 209gdb_expect { 210 -re "~\"$line_main_return\[^\r\n\]+\r\n" { 211 pass $test 212 } 213 timeout { 214 fail "$test (timeout)" 215 } 216} 217 218mi_expect_stop "end-stepping-range" "main" "" ".*basics.c" $line_main_return "" \ 219 "34 next: stop" 220 221mi_gdb_test "-interpreter-exec console \"list\"" \ 222 "\~\"$line_main_return\[\\\\t ]*callme \\(1\\);\\\\n\".*\\^done" \ 223 "-interpreter-exec console \"list\" at basics.c:\$line_main_return" 224 225mi_gdb_test "600-break-insert -t basics.c:$line_main_callme_2" \ 226 {600\^done,bkpt=.number="4",type="breakpoint".*\}} \ 227 "-break-insert -t basics.c:\$line_main_callme_2" 228 229mi_execute_to "exec-continue" "breakpoint-hit" "main" "" ".*basics.c" \ 230 $line_main_callme_2 { "" "disp=\"del\"" } \ 231 "-exec-continue to line \$line_main_callme_2" 232 233# Restore the listsize back to the default. 234mi_gdb_test "-interpreter-exec console \"set listsize 10\"" \ 235 ".*=cmd-param-changed,param=\"listsize\",value=\"10\".*\\^done" \ 236 "-interpreter-exec console \"set listsize 10\"" 237 238# "list" should show 10 lines centered on where the program stopped. 239set first_list_line [expr $line_main_callme_2 - 5] 240mi_gdb_test "-interpreter-exec console \"list\"" \ 241 ".*\~\"$first_list_line.*\\^done" \ 242 "-interpreter-exec console \"list\" at basics.c:\$line_main_callme_2" 243 244mi_gdb_test "-interpreter-exec console \"help set args\"" \ 245 {\~"Set argument list to give program being debugged when it is started\.\\nFollow this command with any number of args, to be passed to the program\.".*\^done} \ 246 "-interpreter-exec console \"help set args\"" 247 248# NOTE: cagney/2003-02-03: Not yet. 249# mi_gdb_test "-interpreter-exec console \"set \$pc=0x0\"" \ 250# {.*=target-changed.*\^done} \ 251# "-interpreter-exec console \"set \$pc=0x0\"" 252mi_gdb_test "888-interpreter-exec console \"set \$pc=0x0\"" \ 253 {888\^done} \ 254 "-interpreter-exec console \"set \$pc=0x0\"" 255 256#mi_gdb_test "-interpreter-exec console \"\"" \ 257 {} \ 258 "-interpreter-exec console \"\"" 259 260mi_gdb_exit 261return 0 262