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