]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/gdb.python/py-prompt.exp
[gdb/testsuite] Add -q to INTERNAL_GDBFLAGS
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.python / py-prompt.exp
CommitLineData
213516ef 1# Copyright (C) 2011-2023 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
7d8e6458 21load_lib gdb-python.exp
22load_lib prompt.exp
23
d82e5429 24require allow_python_tests
7d8e6458 25
b4a58790 26if {[build_executable $testfile.exp $testfile $srcfile debug] == -1} {
7d8e6458 27 return -1
28}
29
31c50280
TV
30save_vars { INTERNAL_GDBFLAGS } {
31 set INTERNAL_GDBFLAGS [string map {"-q" ""} $INTERNAL_GDBFLAGS]
32
33 global GDBFLAGS
34 set saved_gdbflags $GDBFLAGS
35 set GDBFLAGS [concat $GDBFLAGS " -ex \"set height 0\""]
36 set GDBFLAGS [concat $GDBFLAGS " -ex \"set width 0\""]
37 set GDBFLAGS [concat $GDBFLAGS " -ex \"python p = list()\""]
38 set prompt_func "python def foo(x): global p; p.append(x); return \'(Foo) \'"
39 set GDBFLAGS [concat $GDBFLAGS " -ex \"$prompt_func\""]
40 set GDBFLAGS [concat $GDBFLAGS " -ex \"python gdb.prompt_hook=foo\""]
41
42 set tmp_gdbflags $GDBFLAGS
43 set gdb_prompt_fail $gdb_prompt
44
45 global gdb_prompt
46 # Does not include the space at the end of the prompt.
47 # gdb_test expects it not to be there.
48 set gdb_prompt "\[(\]Foo\[)\]"
49
50 with_test_prefix "set editing on" {
51 set GDBFLAGS [concat $tmp_gdbflags " -ex \"set editing on\""]
52 prompt_gdb_start
53 gdb_test "python x = len(p); print (gdb.execute(\"show prompt\", to_string = True))" \
54 ".*prompt is \"$gdb_prompt \".*" \
55 "show prompt gets the correct result"
56 gdb_test "python print ('%d %d' % (x, len(p)))" "1 2" \
57 "retrieving the prompt causes no extra prompt_hook calls"
58 gdb_test "python print (\"'\" + str(p\[0\]) + \"'\")" "'$gdb_prompt_fail '" \
59 "prompt_hook argument is default prompt."
60 gdb_exit
61 }
62
63 with_test_prefix "set editing off" {
64 set GDBFLAGS [concat $tmp_gdbflags " -ex \"set editing off\""]
65 prompt_gdb_start
66 gdb_test "python x = len(p); print (gdb.execute(\"show prompt\", to_string = True))" \
67 ".*prompt is \"$gdb_prompt \".*" \
68 "show prompt gets the correct result 2"
69 gdb_test "python print ('%d %d' % (x, len(p)))" "1 2" \
70 "retrieving the prompt causes no extra prompt_hook calls 2"
71 gdb_test "python print (\"'\" + str(p\[0\]) + \"'\")" "'$gdb_prompt_fail '" \
72 "prompt_hook argument is default prompt. 2"
73 gdb_exit
74 }
75
76 if {![can_spawn_for_attach]} {
77 set GDBFLAGS $saved_gdbflags
78 return 0
79 }
80
81 set test_spawn_id [spawn_wait_for_attach $binfile]
82 set testpid [spawn_id_get_pid $test_spawn_id]
83
84 set GDBFLAGS [concat $tmp_gdbflags " -ex \"set pagination off\""]
85 set GDBFLAGS [concat $GDBFLAGS " -ex \"set editing on\""]
86 set GDBFLAGS [concat $GDBFLAGS " -ex \"attach $testpid\""]
87 set GDBFLAGS [concat $GDBFLAGS " -ex \"continue&\""]
88
89 # sync_execution = 1 is_running = 1
90 with_test_prefix "sync_execution = 1, is_running = 1" {
91 prompt_gdb_start
92 gdb_test "python x = len(p); print (gdb.execute(\"show prompt\", to_string = True))" \
93 ".*prompt is \"$gdb_prompt \".*" \
94 "show prompt gets the correct result 3"
95 gdb_test "python print ('%d %d' % (x, len(p)))" "1 2" \
96 "retrieving the prompt causes no extra prompt_hook calls 3"
97 gdb_test "python print (\"'\" + str(p\[0\]) + \"'\")" "'$gdb_prompt_fail '" \
98 "prompt_hook argument is default prompt. 3"
99 gdb_exit
100 }
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 with_test_prefix "sync_execution = 1, is_running = 0" {
109 prompt_gdb_start
110 gdb_test "python x = len(p); print (gdb.execute(\"show prompt\", to_string = True))" \
111 ".*prompt is \"$gdb_prompt \".*" \
112 "show prompt gets the correct result 4"
113 gdb_test "python print ('%d %d' % (x, len(p)))" "1 2" \
114 "retrieving the prompt causes no extra prompt_hook calls 4"
115 gdb_test "python print (\"'\" + str(p\[0\]) + \"'\")" "'$gdb_prompt_fail '" \
116 "prompt_hook argument is default prompt. 4"
117 gdb_exit
118 }
7d8e6458 119
3d230f71 120 set GDBFLAGS $saved_gdbflags
31c50280 121 kill_wait_spawned_process $test_spawn_id
e3e48d8f 122}