Commit | Line | Data |
---|---|---|
88b9d363 | 1 | # Copyright (C) 2008-2022 Free Software Foundation, Inc. |
d57a3c85 TJB |
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 | # exposing values to Python. | |
18 | ||
a2c09bd0 DE |
19 | load_lib gdb-python.exp |
20 | ||
b4a58790 TT |
21 | standard_testfile python.c python-1.c |
22 | ||
23 | if {[build_executable $testfile.exp $testfile \ | |
24 | [list $srcfile $srcfile2] debug] == -1} { | |
cb2e07a6 PM |
25 | return -1 |
26 | } | |
d57a3c85 | 27 | |
cb2e07a6 | 28 | # Start with a fresh gdb. |
d57a3c85 TJB |
29 | gdb_exit |
30 | gdb_start | |
31 | gdb_reinitialize_dir $srcdir/$subdir | |
32 | ||
7c343b48 YQ |
33 | set remote_source2_py [gdb_remote_download host \ |
34 | ${srcdir}/${subdir}/source2.py] | |
35 | ||
38a502a4 DE |
36 | # Do this instead of the skip_python_check. |
37 | # We want to do some tests when Python is not present. | |
9325cb04 | 38 | gdb_test_multiple "python print (23)" "verify python support" { |
d57a3c85 TJB |
39 | -re "not supported.*$gdb_prompt $" { |
40 | unsupported "python support is disabled" | |
9e14a9ba JB |
41 | |
42 | # If Python is not supported, verify that sourcing a python script | |
43 | # causes an error. | |
7c343b48 | 44 | gdb_test "source $remote_source2_py" \ |
4af31552 TT |
45 | "Error in sourced command file:.*" \ |
46 | "source source2.py when python disabled" | |
feef67ab DE |
47 | |
48 | # Verify multi-line python commands cause an error. | |
c0b3b3bd | 49 | gdb_test_multiline "multi-line python command" \ |
feef67ab DE |
50 | "python" "" \ |
51 | "print (23)" "" \ | |
52 | "end" "not supported.*" | |
53 | ||
d57a3c85 TJB |
54 | return -1 |
55 | } | |
56 | -re "$gdb_prompt $" {} | |
57 | } | |
58 | ||
c0b3b3bd | 59 | gdb_test_multiline "multi-line python command" \ |
d57a3c85 | 60 | "python" "" \ |
9325cb04 | 61 | "print (23)" "" \ |
d57a3c85 TJB |
62 | "end" "23" |
63 | ||
d3d4baed PA |
64 | # Spawn interactive Python help from a multi-line command, thus, after |
65 | # a secondary prompt. | |
66 | ||
67 | with_test_prefix "python interactive help" { | |
68 | set test "python; help(); end" | |
69 | gdb_test_multiple "python\nhelp()\nend" $test { | |
55cfb2c4 | 70 | -re ".*help utility.*help> $" { |
d3d4baed PA |
71 | pass $test |
72 | ||
73 | # The "quit" must be seen on the output. A buggy GDB | |
74 | # would not display it. | |
75 | gdb_test "quit" "^quit.*leaving help.*" "quit help" | |
76 | } | |
77 | } | |
78 | } | |
79 | ||
c0b3b3bd | 80 | gdb_test_multiline "show python command" \ |
d57a3c85 TJB |
81 | "define zzq" "Type commands for definition of .* just \"end\"\\.*" \ |
82 | "python" "" \ | |
9325cb04 | 83 | "print (23)" "" \ |
d57a3c85 TJB |
84 | "end" "" \ |
85 | "end" "" \ | |
9325cb04 | 86 | "show user zzq" "User command \"zzq\":.* python.*print \\(23\\).* end" |
311a4e6b | 87 | |
c0b3b3bd | 88 | gdb_test_multiline "indented multi-line python command" \ |
311a4e6b TJB |
89 | "python" "" \ |
90 | "def foo ():" "" \ | |
9325cb04 | 91 | " print ('hello, world!')" "" \ |
311a4e6b TJB |
92 | "foo ()" "" \ |
93 | "end" "hello, world!" | |
89c73ade | 94 | |
7c343b48 | 95 | gdb_test "source $remote_source2_py" "yes" "source source2.py" |
9e14a9ba | 96 | |
d1e36019 | 97 | gdb_test "source -s source2.py" "yes" |
d234ef5c | 98 | |
1a70ae97 DE |
99 | set remote_source2_symlink_notpy \ |
100 | [gdb_remote_download host ${srcdir}/${subdir}/source2.py \ | |
101 | [standard_output_file "source2-symlink.notpy"]] | |
102 | set remote_source2_symlink_py [standard_output_file "source2-symlink.py"] | |
103 | remote_file host delete $remote_source2_symlink_py | |
104 | set status [remote_exec host "ln -sf $remote_source2_symlink_notpy $remote_source2_symlink_py"] | |
105 | set test "source -s source2-symlink.py" | |
106 | if {[lindex $status 0] == 0} { | |
107 | gdb_test "source -s $remote_source2_symlink_py" "yes" $test | |
108 | } else { | |
109 | unsupported "$test (host does not support symbolic links)" | |
110 | } | |
111 | ||
9325cb04 PK |
112 | gdb_test "python print (gdb.current_objfile())" "None" |
113 | gdb_test "python print (gdb.objfiles())" "\\\[\\\]" | |
3bebe2f2 JK |
114 | |
115 | # Test http://bugs.python.org/issue4434 workaround in configure.ac | |
9325cb04 | 116 | gdb_test "python import itertools; print ('IMPOR'+'TED')" "IMPORTED" "pythonX.Y/lib-dynload/*.so" |
bc9f0842 TT |
117 | |
118 | gdb_test_no_output \ | |
119 | "python x = gdb.execute('printf \"%d\", 23', to_string = True)" | |
9325cb04 | 120 | gdb_test "python print (x)" "23" |
5da1313b | 121 | |
56bcdbea TT |
122 | gdb_test "python gdb.execute('echo 2\\necho 3\\\\n\\n')" "23" \ |
123 | "multi-line execute" | |
1c97054b | 124 | gdb_test " " "23" "gdb.execute does not affect repeat history" |
56bcdbea | 125 | |
ca5c20b6 | 126 | # Test post_event. |
c0b3b3bd | 127 | gdb_test_multiline "post event insertion" \ |
ca5c20b6 PM |
128 | "python" "" \ |
129 | "someVal = 0" "" \ | |
70ebf4ed | 130 | "class Foo(object):" "" \ |
ca5c20b6 PM |
131 | " def __call__(self):" "" \ |
132 | " global someVal" "" \ | |
133 | " someVal += 1" "" \ | |
134 | "gdb.post_event(Foo())" "" \ | |
135 | "end" "" | |
136 | ||
9325cb04 | 137 | gdb_test "python print (someVal)" "1" "test post event execution" |
39a24317 TT |
138 | gdb_test "python gdb.post_event(str(1))" "RuntimeError: Posted event is not callable.*" \ |
139 | "test non callable class" | |
140 | ||
141 | send_gdb "python gdb.post_event(lambda: invalid())\n" | |
142 | gdb_expect { | |
143 | -re "name 'invalid' is not defined" { | |
144 | pass "test post_event error on receipt" | |
145 | } | |
146 | default { | |
147 | fail "test post_event error on receipt" | |
148 | } | |
149 | } | |
ca5c20b6 | 150 | |
5da1313b JK |
151 | # Test (no) pagination of the executed command. |
152 | gdb_test "show height" {Number of lines gdb thinks are in a page is unlimited\.} | |
153 | set lines 10 | |
154 | gdb_test_no_output "set height $lines" | |
155 | ||
156 | set test "verify pagination beforehand" | |
9325cb04 | 157 | gdb_test_multiple "python print (\"\\n\" * $lines)" $test { |
eb6af809 | 158 | -re "--Type <RET>" { |
c5cb204f MP |
159 | exp_continue |
160 | } | |
eb6af809 | 161 | -re " for more, q to quit" { |
c5cb204f MP |
162 | exp_continue |
163 | } | |
eb6af809 | 164 | -re ", c to continue without paging--$" { |
5da1313b JK |
165 | pass $test |
166 | } | |
167 | } | |
5204774b | 168 | gdb_test "q" "Quit.*Error while executing Python.*" "verify pagination beforehand: q" |
5da1313b | 169 | |
9325cb04 | 170 | gdb_test "python if gdb.execute('python print (\"\\\\n\" * $lines)', to_string=True) == \"\\n\" * [expr $lines + 1]: print (\"yes\")" "yes" "gdb.execute does not page" |
5da1313b JK |
171 | |
172 | set test "verify pagination afterwards" | |
9325cb04 | 173 | gdb_test_multiple "python print (\"\\n\" * $lines)" $test { |
eb6af809 | 174 | -re "--Type <RET>" { |
c5cb204f MP |
175 | exp_continue |
176 | } | |
eb6af809 | 177 | -re " for more, q to quit" { |
c5cb204f MP |
178 | exp_continue |
179 | } | |
eb6af809 | 180 | -re ", c to continue without paging--$" { |
5da1313b JK |
181 | pass $test |
182 | } | |
183 | } | |
5204774b | 184 | gdb_test "q" "Quit.*Error while executing Python.*" "verify pagination afterwards: q" |
cb2e07a6 | 185 | |
8d4d924b JK |
186 | gdb_test_no_output "set height 0" |
187 | ||
188 | gdb_test_no_output "python a = gdb.execute('help', to_string=True)" "collect help from uiout" | |
189 | ||
746ebfe8 | 190 | gdb_test "python print (a)" ".*aliases -- User-defined aliases of other commands.*" "verify help to uiout" |
8d4d924b | 191 | |
ea976c60 PM |
192 | # Test PR 12212, using InfThread.selected_thread() when no inferior is |
193 | # loaded. | |
194 | gdb_py_test_silent_cmd "python nothread = gdb.selected_thread()" "Attempt to aquire thread with no inferior" 1 | |
f9e59d06 | 195 | gdb_test "python print (nothread is None)" "True" "ensure that no threads are returned" |
ea976c60 | 196 | |
c0b3b3bd | 197 | gdb_test_multiline "register atexit function" \ |
d7de8e3c TT |
198 | "python" "" \ |
199 | "import atexit" "" \ | |
200 | "def printit(arg):" "" \ | |
9325cb04 | 201 | " print (arg)" "" \ |
d7de8e3c TT |
202 | "atexit.register(printit, 'good bye world')" "" \ |
203 | "end" "" | |
204 | ||
205 | send_gdb "quit\n" | |
206 | gdb_expect { | |
207 | -re "good bye world" { | |
208 | pass "atexit handling" | |
209 | } | |
210 | default { | |
211 | fail "atexit handling" | |
212 | } | |
213 | } | |
214 | ||
cb2e07a6 PM |
215 | # Start with a fresh gdb. |
216 | clean_restart ${testfile} | |
217 | ||
218 | # The following tests require execution. | |
219 | ||
220 | if ![runto_main] then { | |
bc6c7af4 | 221 | fail "can't run to main" |
cb2e07a6 PM |
222 | return 0 |
223 | } | |
224 | ||
5166082f PA |
225 | set lineno [gdb_get_line_number "Break to end."] |
226 | runto $lineno | |
cb2e07a6 PM |
227 | |
228 | # Test gdb.decode_line. | |
229 | gdb_test "python gdb.decode_line(\"main.c:43\")" \ | |
621c8364 | 230 | "gdb.error: No source file named main.c.*" "test decode_line no source named main" |
cb2e07a6 | 231 | |
c0b3b3bd PW |
232 | with_test_prefix "test decode_line current location" { |
233 | gdb_py_test_silent_cmd "python symtab = gdb.decode_line()" "decode current line" 1 | |
234 | gdb_test "python print (len(symtab))" "2" "length of result" | |
235 | gdb_test "python print (symtab\[0\])" "None" "no unparsed text" | |
236 | gdb_test "python print (len(symtab\[1\]))" "1" "length of result locations" | |
237 | } | |
65d7b369 | 238 | |
ff47f4f0 TT |
239 | # Test that decode_line with an empty string argument does not crash. |
240 | gdb_py_test_silent_cmd "python symtab2 = gdb.decode_line('')" \ | |
241 | "test decode_line with empty string" 1 | |
242 | ||
65d7b369 YQ |
243 | if { [is_remote host] } { |
244 | set python_c [string_to_regexp "python.c"] | |
245 | } else { | |
246 | set python_c [string_to_regexp "gdb.python/python.c"] | |
247 | } | |
c0b3b3bd PW |
248 | with_test_prefix "test decode_line" { |
249 | gdb_test "python print (symtab\[1\]\[0\].symtab)" ".*${python_c}" "current location filename" | |
250 | gdb_test "python print (symtab\[1\]\[0\].line)" "$lineno" "current location line number" | |
251 | ||
252 | gdb_py_test_silent_cmd "python symtab = gdb.decode_line(\"python.c:26 if foo\")" "python.c:26 decode" 1 | |
253 | gdb_test "python print (len(symtab))" "2" "python.c:26 length 2" | |
254 | gdb_test "python print (symtab\[0\])" "if foo" "expression parse" | |
255 | gdb_test "python print (len(symtab\[1\]))" "1" "python.c:26 length 1" | |
256 | gdb_test "python print (symtab\[1\]\[0\].symtab)" ".*${python_c}" "python.c:26 filename" | |
257 | gdb_test "python print (symtab\[1\]\[0\].line)" "26" "python.c:26 line number" | |
258 | ||
259 | gdb_test "python gdb.decode_line(\"randomfunc\")" \ | |
260 | "gdb.error: Function \"randomfunc\" not defined.*" "randomfunc" | |
261 | gdb_py_test_silent_cmd "python symtab = gdb.decode_line(\"func1\")" "func1()" 1 | |
262 | gdb_test "python print (len(symtab))" "2" "func1 length 2" | |
263 | gdb_test "python print (len(symtab\[1\]))" "1" "func1 length 1" | |
264 | } | |
65d7b369 YQ |
265 | |
266 | if { [is_remote host] } { | |
267 | set python_1_c [string_to_regexp "python-1.c"] | |
268 | } else { | |
269 | set python_1_c [string_to_regexp "gdb.python/python-1.c"] | |
270 | } | |
cdc7edd7 | 271 | gdb_test "python print (symtab\[1\]\[0\].symtab)" ".*${python_1_c}" "test decode_line func1 filename" |
d334ae25 LM |
272 | |
273 | # Set a default value for func1_lineno in case we fail to fetch the line number | |
274 | # below. | |
275 | set func1_lineno "noline" | |
276 | ||
277 | # Fetch the line GDB thinks func1 starts at. This may change depending | |
278 | # on the architecture and on how GDB handles the prologue of the function. | |
279 | gdb_test_multiple "info line func1" "info line func1" { | |
280 | -re "Line ($decimal) of .* starts at address $hex <func1> and ends at $hex <func1\\+$decimal>\.\[\r\n\]+$gdb_prompt $" { | |
281 | # Fetch the line number. | |
282 | set func1_lineno $expect_out(1,string) | |
283 | } | |
284 | } | |
285 | ||
286 | gdb_test "python print (symtab\[1\]\[0\].line)" "$func1_lineno" "test decode_line func1 line number" | |
f87a3023 KS |
287 | gdb_py_test_silent_cmd {python symtab = gdb.decode_line ("func1,func2")} \ |
288 | "test decode_line func1,func2" 1 | |
9325cb04 | 289 | gdb_test {python print (symtab[0])} ",func2" "stop at comma in linespec" |
99c3dc11 | 290 | |
c0b3b3bd PW |
291 | with_test_prefix "test decode_line" { |
292 | gdb_py_test_silent_cmd "python symtab = gdb.decode_line(\"*0\")" "*0" 1 | |
293 | gdb_test "python print (len(symtab))" "2" "*0 result length" | |
294 | gdb_test "python print (symtab\[0\])" "None" "*0 unparsed" | |
295 | gdb_test "python print (len(symtab\[1\]))" "1" "*0 locations length" | |
296 | gdb_test "python print (symtab\[1\]\[0\].symtab)" "None" "*0 filename" | |
297 | gdb_test "python print (symtab\[1\]\[0\].pc)" "0" "*0 pc" | |
298 | } | |
68dadef5 | 299 | |
99c3dc11 | 300 | # gdb.write |
08235187 CB |
301 | gdb_test "python print (sys.stderr)" ".*gdb._GdbOutputErrorFile (instance|object) at.*" "test stderr location" |
302 | gdb_test "python print (sys.stdout)" ".*gdb._GdbOutputFile (instance|object) at.*" "test stdout location" | |
cdc7edd7 LM |
303 | gdb_test "python gdb.write(\"Foo\\n\")" "Foo" "test default write" |
304 | gdb_test "python gdb.write(\"Error stream\\n\", stream=gdb.STDERR)" "Error stream" "test stderr write" | |
305 | gdb_test "python gdb.write(\"Normal stream\\n\", stream=gdb.STDOUT)" "Normal stream" "test stdout write" | |
81f47ac2 AH |
306 | |
307 | if ![gdb_debug_enabled] { | |
308 | gdb_test "python gdb.write(\"Log stream\\n\", stream=gdb.STDLOG)" "Log stream" "test stdlog write" | |
309 | } | |
713389e0 | 310 | |
a49bed3a | 311 | # Turn on full stack printing for subsequent tests. |
80b6e756 | 312 | gdb_py_test_silent_cmd "set python print-stack full" \ |
a49bed3a | 313 | "Set print-stack full for prompt tests" 1 |
d17b6f81 PM |
314 | |
315 | # Test prompt substituion | |
316 | ||
c0b3b3bd | 317 | gdb_test_multiline "prompt substitution" \ |
d17b6f81 PM |
318 | "python" "" \ |
319 | "someCounter = 0" "" \ | |
320 | "def prompt(current):" "" \ | |
321 | " global someCounter" "" \ | |
322 | " if (current == \"testfake \"):" "" \ | |
323 | " return None" "" \ | |
324 | " someCounter = someCounter + 1" "" \ | |
325 | " return \"py prompt \" + str (someCounter) + \" \"" "" \ | |
326 | "end" "" | |
327 | ||
c0b3b3bd | 328 | gdb_test_multiline "prompt substitution readline" \ |
d17b6f81 PM |
329 | "python" "" \ |
330 | "pCounter = 0" "" \ | |
331 | "def program_prompt(current):" "" \ | |
332 | " global pCounter" "" \ | |
333 | " if (current == \">\"):" "" \ | |
334 | " pCounter = pCounter + 1" "" \ | |
335 | " return \"python line \" + str (pCounter) + \": \"" "" \ | |
336 | " return None" "" \ | |
337 | "end" "" | |
338 | ||
339 | set newprompt "py prompt 1" | |
340 | set newprompt2 "py prompt 2" | |
341 | set testfake "testfake" | |
342 | ||
c0b3b3bd | 343 | gdb_test_multiple "python gdb.prompt_hook = prompt" "set the hook = prompt" { |
d17b6f81 | 344 | -re "\[\r\n\]$newprompt $" { |
c0b3b3bd | 345 | pass $gdb_test_name |
d17b6f81 PM |
346 | } |
347 | } | |
348 | ||
349 | gdb_test_multiple "set prompt testfake " "set testfake prompt in GDB" { | |
350 | -re "\[\r\n\]$testfake $" { | |
c0b3b3bd | 351 | pass $gdb_test_name |
d17b6f81 PM |
352 | } |
353 | } | |
354 | ||
355 | gdb_test_multiple "show prompt" "show testfake prompt" { | |
356 | -re "Gdb's prompt is \"$testfake \"..* $" { | |
c0b3b3bd | 357 | pass $gdb_test_name |
d17b6f81 PM |
358 | } |
359 | } | |
360 | ||
361 | gdb_test_multiple "set prompt blah " "set blah in GDB" { | |
362 | -re "\[\r\n\]$newprompt2 $" { | |
c0b3b3bd | 363 | pass $gdb_test_name |
d17b6f81 PM |
364 | } |
365 | } | |
366 | ||
de97fdd4 | 367 | gdb_test_multiple "python gdb.prompt_hook = None" "delete hook" { |
d17b6f81 | 368 | -re "\[\r\n\]$newprompt2 $" { |
c0b3b3bd | 369 | pass $gdb_test_name |
d17b6f81 PM |
370 | } |
371 | } | |
372 | ||
373 | gdb_test_multiple "set prompt $gdb_prompt " "set default prompt" { | |
374 | -re "\[\r\n\]$gdb_prompt $" { | |
c0b3b3bd | 375 | pass $gdb_test_name |
d17b6f81 PM |
376 | } |
377 | } | |
378 | ||
6ce8c980 YQ |
379 | set working_dir "" |
380 | gdb_test_multiple "pwd" "pwd" { | |
381 | -re "Working directory (.*)\\.\[\r\n\]+$gdb_prompt $" { | |
382 | set working_dir $expect_out(1,string) | |
383 | } | |
384 | } | |
385 | ||
c0b3b3bd | 386 | gdb_test_multiple "python gdb.prompt_hook = program_prompt" "set the programming hook" { |
d17b6f81 | 387 | -re "\[\r\n\]$gdb_prompt $" { |
c0b3b3bd | 388 | pass $gdb_test_name |
d17b6f81 PM |
389 | } |
390 | } | |
391 | ||
c0b3b3bd | 392 | gdb_test_multiple "python" "test we ignore substitution for seconday prompts" { |
d17b6f81 | 393 | -re "\r\n>$" { |
c0b3b3bd | 394 | pass $gdb_test_name |
d17b6f81 PM |
395 | } |
396 | } | |
397 | ||
398 | gdb_test_multiple "end" "end programming" { | |
399 | -re "\[\r\n\]$gdb_prompt $" { | |
c0b3b3bd | 400 | pass $gdb_test_name |
d17b6f81 PM |
401 | } |
402 | } | |
fa3a4f15 | 403 | |
c0b3b3bd | 404 | gdb_test_multiline "prompt substitution readline import" \ |
fa3a4f15 PM |
405 | "python" "" \ |
406 | "import gdb.command.prompt" "" \ | |
407 | "end" "" | |
408 | ||
409 | gdb_test_multiple "set extended-prompt one two three " \ | |
410 | "set basic extended prompt" { | |
411 | -re "\[\r\n\]one two three $" { | |
c0b3b3bd | 412 | pass $gdb_test_name |
fa3a4f15 PM |
413 | } |
414 | } | |
415 | ||
416 | gdb_test_multiple "set extended-prompt \\w " \ | |
417 | "set extended prompt working directory" { | |
6ce8c980 | 418 | -re "\[\r\n\][string_to_regexp $working_dir] $" { |
c0b3b3bd | 419 | pass $gdb_test_name |
fa3a4f15 PM |
420 | } |
421 | } | |
422 | ||
423 | gdb_test_multiple "set extended-prompt some param \\p{python print-stack} " \ | |
424 | "set extended prompt parameter" { | |
80b6e756 | 425 | -re "\[\r\n\]some param full $" { |
c0b3b3bd | 426 | pass $gdb_test_name |
fa3a4f15 PM |
427 | } |
428 | } | |
80b6e756 PM |
429 | |
430 | # Start with a fresh gdb. | |
431 | clean_restart ${testfile} | |
432 | ||
433 | # The following tests require execution. | |
434 | ||
435 | if ![runto_main] then { | |
bc6c7af4 | 436 | fail "can't run to main" |
80b6e756 PM |
437 | return 0 |
438 | } | |
439 | ||
440 | # print-stack settings | |
441 | gdb_test "show python print-stack" \ | |
442 | "The mode of Python stack printing on error is \"message\".*" \ | |
a49bed3a | 443 | "Test print-stack show setting. Default is message." |
80b6e756 | 444 | gdb_py_test_silent_cmd "set python print-stack full" \ |
a49bed3a | 445 | "Test print-stack set setting to full" 1 |
80b6e756 PM |
446 | gdb_test "show python print-stack" \ |
447 | "The mode of Python stack printing on error is \"full\".*" \ | |
a49bed3a | 448 | "Test print-stack show setting to full" |
80b6e756 | 449 | gdb_py_test_silent_cmd "set python print-stack none" \ |
a49bed3a | 450 | "Test print-stack set setting to none" 1 |
80b6e756 PM |
451 | gdb_test "show python print-stack" \ |
452 | "The mode of Python stack printing on error is \"none\".*" \ | |
bb95117e | 453 | "test print-stack show setting to none" |
80b6e756 PM |
454 | |
455 | gdb_py_test_silent_cmd "set python print-stack message" \ | |
a49bed3a | 456 | "Test print-stack set setting to message" 1 |
80b6e756 | 457 | |
c0b3b3bd | 458 | gdb_test_multiline "prompt substitution readline error_prompt" \ |
80b6e756 PM |
459 | "python" "" \ |
460 | "pCounter = 0" "" \ | |
461 | "def error_prompt(current):" "" \ | |
462 | " raise RuntimeError(\"Python exception called\")" "" \ | |
463 | "end" "" | |
464 | ||
c0b3b3bd | 465 | gdb_test_multiple "python gdb.prompt_hook = error_prompt" "set the hook error_prompt" { |
2708dbbd | 466 | -re "Python Exception (exceptions.RuntimeError|<(type 'exceptions.|class ')RuntimeError'>): Python exception called\r\n$gdb_prompt $" { |
c0b3b3bd | 467 | pass $gdb_test_name |
80b6e756 PM |
468 | } |
469 | } | |
470 | ||
471 | gdb_py_test_silent_cmd "python gdb.prompt_hook = None" \ | |
c0b3b3bd | 472 | "set the hook to default 1" 1 |
80b6e756 PM |
473 | |
474 | gdb_py_test_silent_cmd "set python print-stack full" \ | |
a49bed3a | 475 | "set print-stack full for prompt error test" 1 |
80b6e756 | 476 | |
c0b3b3bd | 477 | gdb_test_multiple "python gdb.prompt_hook = error_prompt" "set the hook error_prompt traceback" { |
5beafce9 | 478 | -re "Traceback.*File.*line.*RuntimeError.*Python exception called.*$gdb_prompt $" { |
c0b3b3bd | 479 | pass $gdb_test_name |
80b6e756 PM |
480 | } |
481 | } | |
482 | ||
483 | gdb_py_test_silent_cmd "python gdb.prompt_hook = None" \ | |
c0b3b3bd | 484 | "set the hook to default 2" 1 |
7efc75aa SCR |
485 | |
486 | # Start with a fresh gdb. | |
487 | clean_restart ${testfile} | |
488 | ||
489 | # The following tests require execution. | |
490 | ||
491 | if ![runto_main] then { | |
bc6c7af4 | 492 | fail "can't run to main" |
7efc75aa SCR |
493 | return 0 |
494 | } | |
495 | ||
496 | runto [gdb_get_line_number "Break at func2 call site."] | |
497 | ||
498 | gdb_py_test_silent_cmd "python line = gdb.selected_frame().find_sal().line" "Get line number of func2 call site" 1 | |
cdc7edd7 | 499 | gdb_test "python print (gdb.find_pc_line(gdb.selected_frame().pc()).line == line)" "True" "test find_pc_line at func2 call site" |
7efc75aa SCR |
500 | |
501 | gdb_py_test_silent_cmd "step" "Step into func2" 1 | |
502 | gdb_py_test_silent_cmd "up" "Step out of func2" 1 | |
503 | ||
cdc7edd7 | 504 | gdb_test "python print (gdb.find_pc_line(gdb.selected_frame().pc()).line > line)" "True" "test find_pc_line with resume address" |
7729052b TT |
505 | |
506 | gdb_test_no_output "set variable \$cvar1 = 23" "set convenience variable" | |
507 | gdb_test "python print(gdb.convenience_variable('cvar1'))" "23" | |
508 | gdb_test "python print(gdb.convenience_variable('cvar2'))" "None" | |
509 | gdb_test_no_output "python gdb.set_convenience_variable('cvar1', 89)" \ | |
510 | "change convenience variable from python" | |
511 | gdb_test "python print(gdb.convenience_variable('cvar1'))" "89" \ | |
512 | "print new value of convenience variable from python" | |
513 | gdb_test "print \$cvar1" " = 89" \ | |
514 | "print new value of convenience variable from CLI" | |
515 | gdb_test_no_output "python gdb.set_convenience_variable('cvar3', -5)" \ | |
516 | "make convenience variable from python" | |
517 | gdb_test "python print(gdb.convenience_variable('cvar3'))" "-5" \ | |
518 | "print value of new convenience variable from python" | |
519 | gdb_test_no_output "python gdb.set_convenience_variable('cvar3', None)" \ | |
520 | "reset convenience variable from python" | |
521 | gdb_test "python print(gdb.convenience_variable('cvar3'))" "None" \ | |
522 | "print reset convenience variable from python" | |
523 | gdb_test "print \$cvar3" "= void" \ | |
524 | "print reset convenience variable from CLI" | |
8588b356 SM |
525 | |
526 | # Test PR 23669, the following would invoke the "commands" command instead of | |
527 | # "show commands". | |
528 | gdb_test "python gdb.execute(\"show commands\")" "$decimal print \\\$cvar3.*" | |
8f9929bb GR |
529 | |
530 | # Test that the from_tty argument to gdb.execute is effective. If | |
531 | # False, the user is not prompted for decisions such as restarting the | |
532 | # program, and "yes" is assumed. If True, the user is prompted. | |
533 | gdb_test "python gdb.execute('starti', from_tty=False)" \ | |
534 | "Program stopped.*" \ | |
535 | "starti via gdb.execute, not from tty" | |
536 | gdb_test_multiple "python gdb.execute('starti', from_tty=True)" \ | |
537 | "starti via gdb.execute, from tty" { | |
538 | -re {The program being debugged has been started already\.\r\nStart it from the beginning\? \(y or n\) $} { | |
539 | gdb_test "y" "Starting program:.*" "starti via interactive input" | |
540 | } | |
541 | } |