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