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