Update copyright year range in all GDB files.
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.python / py-prompt.exp
1 # Copyright (C) 2011-2019 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 standard_testfile
20
21 load_lib gdb-python.exp
22 load_lib prompt.exp
23
24 # Start with a fresh gdb.
25
26 gdb_exit
27 gdb_start
28 gdb_reinitialize_dir $srcdir/$subdir
29
30 # Skip all tests if Python scripting is not enabled.
31 if { [skip_python_tests] } { continue }
32 gdb_exit
33
34 if {[build_executable $testfile.exp $testfile $srcfile debug] == -1} {
35 return -1
36 }
37
38 global GDBFLAGS
39 set saved_gdbflags $GDBFLAGS
40 set GDBFLAGS [concat $GDBFLAGS " -ex \"set height 0\""]
41 set GDBFLAGS [concat $GDBFLAGS " -ex \"set width 0\""]
42 set GDBFLAGS [concat $GDBFLAGS " -ex \"python p = list()\""]
43 set prompt_func "python def foo(x): global p; p.append(x); return \'(Foo) \'"
44 set GDBFLAGS [concat $GDBFLAGS " -ex \"$prompt_func\""]
45 set GDBFLAGS [concat $GDBFLAGS " -ex \"python gdb.prompt_hook=foo\""]
46
47 set tmp_gdbflags $GDBFLAGS
48 set gdb_prompt_fail $gdb_prompt
49
50 global gdb_prompt
51 # Does not include the space at the end of the prompt.
52 # gdb_test expects it not to be there.
53 set gdb_prompt "\[(\]Foo\[)\]"
54
55 set GDBFLAGS [concat $tmp_gdbflags " -ex \"set editing on\""]
56 prompt_gdb_start
57 gdb_test "python x = len(p); print (gdb.execute(\"show prompt\", to_string = True))" \
58 ".*prompt is \"$gdb_prompt \".*" \
59 "show prompt gets the correct result"
60 gdb_test "python print ('%d %d' % (x, len(p)))" "1 2" \
61 "retrieving the prompt causes no extra prompt_hook calls"
62 gdb_test "python print (\"'\" + str(p\[0\]) + \"'\")" "'$gdb_prompt_fail '" \
63 "prompt_hook argument is default prompt."
64 gdb_exit
65
66
67 set GDBFLAGS [concat $tmp_gdbflags " -ex \"set editing off\""]
68 prompt_gdb_start
69 gdb_test "python x = len(p); print (gdb.execute(\"show prompt\", to_string = True))" \
70 ".*prompt is \"$gdb_prompt \".*" \
71 "show prompt gets the correct result 2"
72 gdb_test "python print ('%d %d' % (x, len(p)))" "1 2" \
73 "retrieving the prompt causes no extra prompt_hook calls 2"
74 gdb_test "python print (\"'\" + str(p\[0\]) + \"'\")" "'$gdb_prompt_fail '" \
75 "prompt_hook argument is default prompt. 2"
76 gdb_exit
77
78 if {![can_spawn_for_attach]} {
79 set GDBFLAGS $saved_gdbflags
80 return 0
81 }
82
83 set test_spawn_id [spawn_wait_for_attach $binfile]
84 set testpid [spawn_id_get_pid $test_spawn_id]
85
86 set GDBFLAGS [concat $tmp_gdbflags " -ex \"set pagination off\""]
87 set GDBFLAGS [concat $GDBFLAGS " -ex \"set editing on\""]
88 set GDBFLAGS [concat $GDBFLAGS " -ex \"attach $testpid\""]
89 set GDBFLAGS [concat $GDBFLAGS " -ex \"continue&\""]
90
91 # sync_execution = 1 is_running = 1
92 prompt_gdb_start
93 gdb_test "python x = len(p); print (gdb.execute(\"show prompt\", to_string = True))" \
94 ".*prompt is \"$gdb_prompt \".*" \
95 "show prompt gets the correct result 3"
96 gdb_test "python print ('%d %d' % (x, len(p)))" "1 2" \
97 "retrieving the prompt causes no extra prompt_hook calls 3"
98 gdb_test "python print (\"'\" + str(p\[0\]) + \"'\")" "'$gdb_prompt_fail '" \
99 "prompt_hook argument is default prompt. 3"
100 gdb_exit
101
102 set GDBFLAGS [concat $tmp_gdbflags " -ex \"set pagination off\""]
103 set GDBFLAGS [concat $GDBFLAGS " -ex \"set editing on\""]
104 set GDBFLAGS [concat $GDBFLAGS " -ex \"attach $testpid\""]
105 set GDBFLAGS [concat $GDBFLAGS " -ex \"interrupt\""]
106
107 # sync_execution = 1 is_running = 0
108 prompt_gdb_start
109 gdb_test "python x = len(p); print (gdb.execute(\"show prompt\", to_string = True))" \
110 ".*prompt is \"$gdb_prompt \".*" \
111 "show prompt gets the correct result 4"
112 gdb_test "python print ('%d %d' % (x, len(p)))" "1 2" \
113 "retrieving the prompt causes no extra prompt_hook calls 4"
114 gdb_test "python print (\"'\" + str(p\[0\]) + \"'\")" "'$gdb_prompt_fail '" \
115 "prompt_hook argument is default prompt. 4"
116 gdb_exit
117
118 set GDBFLAGS $saved_gdbflags
119 kill_wait_spawned_process $test_spawn_id
120 return 0
This page took 0.032739 seconds and 4 git commands to generate.