]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/gdb.python/py-prompt.exp
Update years in copyright notice for the GDB files.
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.python / py-prompt.exp
CommitLineData
8acc9f48 1# Copyright (C) 2011-2013 Free Software Foundation, Inc.
7d8e6458 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 is part of the GDB testsuite. It tests the mechanism
17# for defining the prompt in Python.
18
b4a58790 19standard_testfile
7d8e6458 20
d791e155
TJB
21# We need to use TCL's exec to get the pid.
22if [is_remote target] then {
23 return 0
24}
7d8e6458 25
26load_lib gdb-python.exp
27load_lib prompt.exp
28
29# Start with a fresh gdb.
30
31gdb_exit
32gdb_start
33gdb_reinitialize_dir $srcdir/$subdir
34
35# Skip all tests if Python scripting is not enabled.
36if { [skip_python_tests] } { continue }
37gdb_exit
38
b4a58790 39if {[build_executable $testfile.exp $testfile $srcfile debug] == -1} {
7d8e6458 40 return -1
41}
42
43global GDBFLAGS
44set saved_gdbflags $GDBFLAGS
45set GDBFLAGS [concat $GDBFLAGS " -ex \"set height 0\""]
46set GDBFLAGS [concat $GDBFLAGS " -ex \"set width 0\""]
47set GDBFLAGS [concat $GDBFLAGS " -ex \"python p = list()\""]
48set prompt_func "python def foo(x): global p; p.append(x); return \'(Foo) \'"
49set GDBFLAGS [concat $GDBFLAGS " -ex \"$prompt_func\""]
50set GDBFLAGS [concat $GDBFLAGS " -ex \"python gdb.prompt_hook=foo\""]
51
52set tmp_gdbflags $GDBFLAGS
53set gdb_prompt_fail $gdb_prompt
54
55global gdb_prompt
56# Does not include the space at the end of the prompt.
57# gdb_test expects it not to be there.
58set gdb_prompt "\[(\]Foo\[)\]"
59
60set GDBFLAGS [concat $tmp_gdbflags " -ex \"set editing on\""]
61prompt_gdb_start
9325cb04 62gdb_test "python x = len(p); print (gdb.execute(\"show prompt\", to_string = True))" \
7d8e6458 63 ".*prompt is \"$gdb_prompt \".*" \
64 "show prompt gets the correct result"
9325cb04 65gdb_test "python print ('%d %d' % (x, len(p)))" "1 2" \
7d8e6458 66 "retrieving the prompt causes no extra prompt_hook calls"
9325cb04 67gdb_test "python print (\"'\" + str(p\[0\]) + \"'\")" "'$gdb_prompt_fail '" \
7d8e6458 68 "prompt_hook argument is default prompt."
69gdb_exit
70
71
72set GDBFLAGS [concat $tmp_gdbflags " -ex \"set editing off\""]
73prompt_gdb_start
9325cb04 74gdb_test "python x = len(p); print (gdb.execute(\"show prompt\", to_string = True))" \
7d8e6458 75 ".*prompt is \"$gdb_prompt \".*" \
76 "show prompt gets the correct result 2"
9325cb04 77gdb_test "python print ('%d %d' % (x, len(p)))" "1 2" \
7d8e6458 78 "retrieving the prompt causes no extra prompt_hook calls 2"
9325cb04 79gdb_test "python print (\"'\" + str(p\[0\]) + \"'\")" "'$gdb_prompt_fail '" \
7d8e6458 80 "prompt_hook argument is default prompt. 2"
81gdb_exit
82
83# Start the program running and then wait for a bit, to be sure
84# that it can be attached to.
85set testpid [eval exec $binfile &]
86exec sleep 2
87if { [istarget "*-*-cygwin*"] } {
88 # testpid is the Cygwin PID, GDB uses the Windows PID, which might be
89 # different due to the way fork/exec works.
90 set testpid [ exec ps -e | gawk "{ if (\$1 == $testpid) print \$4; }" ]
91}
92
93set GDBFLAGS [concat $tmp_gdbflags " -ex \"set target-async on\""]
94set GDBFLAGS [concat $GDBFLAGS " -ex \"set pagination off\""]
95set GDBFLAGS [concat $GDBFLAGS " -ex \"set editing on\""]
96set GDBFLAGS [concat $GDBFLAGS " -ex \"attach $testpid\""]
97set GDBFLAGS [concat $GDBFLAGS " -ex \"continue&\""]
98
99# sync_execution = 1 is_running = 1
100prompt_gdb_start
9325cb04 101gdb_test "python x = len(p); print (gdb.execute(\"show prompt\", to_string = True))" \
7d8e6458 102 ".*prompt is \"$gdb_prompt \".*" \
103 "show prompt gets the correct result 3"
9325cb04 104gdb_test "python print ('%d %d' % (x, len(p)))" "1 2" \
7d8e6458 105 "retrieving the prompt causes no extra prompt_hook calls 3"
9325cb04 106gdb_test "python print (\"'\" + str(p\[0\]) + \"'\")" "'$gdb_prompt_fail '" \
7d8e6458 107 "prompt_hook argument is default prompt. 3"
108gdb_exit
109
110set GDBFLAGS [concat $tmp_gdbflags " -ex \"set target-async on\""]
111set GDBFLAGS [concat $GDBFLAGS " -ex \"set pagination off\""]
112set GDBFLAGS [concat $GDBFLAGS " -ex \"set editing on\""]
113set GDBFLAGS [concat $GDBFLAGS " -ex \"attach $testpid\""]
114set GDBFLAGS [concat $GDBFLAGS " -ex \"interrupt\""]
115
116# sync_execution = 1 is_running = 0
117prompt_gdb_start
9325cb04 118gdb_test "python x = len(p); print (gdb.execute(\"show prompt\", to_string = True))" \
7d8e6458 119 ".*prompt is \"$gdb_prompt \".*" \
120 "show prompt gets the correct result 4"
9325cb04 121gdb_test "python print ('%d %d' % (x, len(p)))" "1 2" \
7d8e6458 122 "retrieving the prompt causes no extra prompt_hook calls 4"
9325cb04 123gdb_test "python print (\"'\" + str(p\[0\]) + \"'\")" "'$gdb_prompt_fail '" \
7d8e6458 124 "prompt_hook argument is default prompt. 4"
125gdb_exit
126
127set GDBFLAGS $saved_gdbflags
128return 0