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