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