* gdb.python/py-prompt.exp: Quit if the target is remote.
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.python / py-prompt.exp
1 # Copyright (C) 2011-2012 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 is part of the GDB testsuite. It tests the mechanism
17 # for defining the prompt in Python.
18
19 set testfile "py-prompt"
20 set srcfile ${testfile}.c
21 set binfile ${objdir}/${subdir}/${testfile}
22
23 # We need to use TCL's exec to get the pid.
24 if [is_remote target] then {
25 return 0
26 }
27
28 load_lib gdb-python.exp
29 load_lib prompt.exp
30
31 # Start with a fresh gdb.
32
33 gdb_exit
34 gdb_start
35 gdb_reinitialize_dir $srcdir/$subdir
36
37 # Skip all tests if Python scripting is not enabled.
38 if { [skip_python_tests] } { continue }
39 gdb_exit
40
41 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
42 untested py-prompt.exp
43 return -1
44 }
45
46 global GDBFLAGS
47 set saved_gdbflags $GDBFLAGS
48 set GDBFLAGS [concat $GDBFLAGS " -ex \"set height 0\""]
49 set GDBFLAGS [concat $GDBFLAGS " -ex \"set width 0\""]
50 set GDBFLAGS [concat $GDBFLAGS " -ex \"python p = list()\""]
51 set prompt_func "python def foo(x): global p; p.append(x); return \'(Foo) \'"
52 set GDBFLAGS [concat $GDBFLAGS " -ex \"$prompt_func\""]
53 set GDBFLAGS [concat $GDBFLAGS " -ex \"python gdb.prompt_hook=foo\""]
54
55 set tmp_gdbflags $GDBFLAGS
56 set gdb_prompt_fail $gdb_prompt
57
58 global gdb_prompt
59 # Does not include the space at the end of the prompt.
60 # gdb_test expects it not to be there.
61 set gdb_prompt "\[(\]Foo\[)\]"
62
63 set GDBFLAGS [concat $tmp_gdbflags " -ex \"set editing on\""]
64 prompt_gdb_start
65 gdb_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"
68 gdb_test "python print x, len(p)" "1 2" \
69 "retrieving the prompt causes no extra prompt_hook calls"
70 gdb_test "python print \"'\" + str(p\[0\]) + \"'\"" "'$gdb_prompt_fail '" \
71 "prompt_hook argument is default prompt."
72 gdb_exit
73
74
75 set GDBFLAGS [concat $tmp_gdbflags " -ex \"set editing off\""]
76 prompt_gdb_start
77 gdb_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"
80 gdb_test "python print x, len(p)" "1 2" \
81 "retrieving the prompt causes no extra prompt_hook calls 2"
82 gdb_test "python print \"'\" + str(p\[0\]) + \"'\"" "'$gdb_prompt_fail '" \
83 "prompt_hook argument is default prompt. 2"
84 gdb_exit
85
86 # Start the program running and then wait for a bit, to be sure
87 # that it can be attached to.
88 set testpid [eval exec $binfile &]
89 exec sleep 2
90 if { [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
96 set GDBFLAGS [concat $tmp_gdbflags " -ex \"set target-async on\""]
97 set GDBFLAGS [concat $GDBFLAGS " -ex \"set pagination off\""]
98 set GDBFLAGS [concat $GDBFLAGS " -ex \"set editing on\""]
99 set GDBFLAGS [concat $GDBFLAGS " -ex \"attach $testpid\""]
100 set GDBFLAGS [concat $GDBFLAGS " -ex \"continue&\""]
101
102 # sync_execution = 1 is_running = 1
103 prompt_gdb_start
104 gdb_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"
107 gdb_test "python print x, len(p)" "1 2" \
108 "retrieving the prompt causes no extra prompt_hook calls 3"
109 gdb_test "python print \"'\" + str(p\[0\]) + \"'\"" "'$gdb_prompt_fail '" \
110 "prompt_hook argument is default prompt. 3"
111 gdb_exit
112
113 set GDBFLAGS [concat $tmp_gdbflags " -ex \"set target-async on\""]
114 set GDBFLAGS [concat $GDBFLAGS " -ex \"set pagination off\""]
115 set GDBFLAGS [concat $GDBFLAGS " -ex \"set editing on\""]
116 set GDBFLAGS [concat $GDBFLAGS " -ex \"attach $testpid\""]
117 set GDBFLAGS [concat $GDBFLAGS " -ex \"interrupt\""]
118
119 # sync_execution = 1 is_running = 0
120 prompt_gdb_start
121 gdb_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"
124 gdb_test "python print x, len(p)" "1 2" \
125 "retrieving the prompt causes no extra prompt_hook calls 4"
126 gdb_test "python print \"'\" + str(p\[0\]) + \"'\"" "'$gdb_prompt_fail '" \
127 "prompt_hook argument is default prompt. 4"
128 gdb_exit
129
130 set GDBFLAGS $saved_gdbflags
131 return 0
This page took 0.033612 seconds and 5 git commands to generate.