Commit | Line | Data |
---|---|---|
b811d2c2 | 1 | # Copyright (C) 2011-2020 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 | 19 | standard_testfile |
7d8e6458 | 20 | |
7d8e6458 | 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 | ||
b4a58790 | 34 | if {[build_executable $testfile.exp $testfile $srcfile debug] == -1} { |
7d8e6458 | 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 | |
9325cb04 | 57 | gdb_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 | 60 | gdb_test "python print ('%d %d' % (x, len(p)))" "1 2" \ |
7d8e6458 | 61 | "retrieving the prompt causes no extra prompt_hook calls" |
9325cb04 | 62 | gdb_test "python print (\"'\" + str(p\[0\]) + \"'\")" "'$gdb_prompt_fail '" \ |
7d8e6458 | 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 | |
9325cb04 | 69 | gdb_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 | 72 | gdb_test "python print ('%d %d' % (x, len(p)))" "1 2" \ |
7d8e6458 | 73 | "retrieving the prompt causes no extra prompt_hook calls 2" |
9325cb04 | 74 | gdb_test "python print (\"'\" + str(p\[0\]) + \"'\")" "'$gdb_prompt_fail '" \ |
7d8e6458 | 75 | "prompt_hook argument is default prompt. 2" |
76 | gdb_exit | |
77 | ||
60b3033e | 78 | if {![can_spawn_for_attach]} { |
3d230f71 | 79 | set GDBFLAGS $saved_gdbflags |
60b3033e PA |
80 | return 0 |
81 | } | |
82 | ||
2c8c5d37 PA |
83 | set test_spawn_id [spawn_wait_for_attach $binfile] |
84 | set testpid [spawn_id_get_pid $test_spawn_id] | |
7d8e6458 | 85 | |
329ea579 | 86 | set GDBFLAGS [concat $tmp_gdbflags " -ex \"set pagination off\""] |
7d8e6458 | 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 | |
9325cb04 | 93 | gdb_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 | 96 | gdb_test "python print ('%d %d' % (x, len(p)))" "1 2" \ |
7d8e6458 | 97 | "retrieving the prompt causes no extra prompt_hook calls 3" |
9325cb04 | 98 | gdb_test "python print (\"'\" + str(p\[0\]) + \"'\")" "'$gdb_prompt_fail '" \ |
7d8e6458 | 99 | "prompt_hook argument is default prompt. 3" |
100 | gdb_exit | |
101 | ||
329ea579 | 102 | set GDBFLAGS [concat $tmp_gdbflags " -ex \"set pagination off\""] |
7d8e6458 | 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 | |
9325cb04 | 109 | gdb_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 | 112 | gdb_test "python print ('%d %d' % (x, len(p)))" "1 2" \ |
7d8e6458 | 113 | "retrieving the prompt causes no extra prompt_hook calls 4" |
9325cb04 | 114 | gdb_test "python print (\"'\" + str(p\[0\]) + \"'\")" "'$gdb_prompt_fail '" \ |
7d8e6458 | 115 | "prompt_hook argument is default prompt. 4" |
116 | gdb_exit | |
117 | ||
118 | set GDBFLAGS $saved_gdbflags | |
2c8c5d37 | 119 | kill_wait_spawned_process $test_spawn_id |
7d8e6458 | 120 | return 0 |