gdb/
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.python / python.exp
1 # Copyright (C) 2008, 2009, 2010 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 # exposing values to Python.
18
19 if $tracelevel then {
20 strace $tracelevel
21 }
22
23 # Start with a fresh gdb.
24
25 gdb_exit
26 gdb_start
27 gdb_reinitialize_dir $srcdir/$subdir
28
29 gdb_test_multiple "python print 23" "verify python support" {
30 -re "not supported.*$gdb_prompt $" {
31 unsupported "python support is disabled"
32
33 # If Python is not supported, verify that sourcing a python script
34 # causes an error.
35 gdb_test "source $srcdir/$subdir/source2.py" "Error in sourced command file:.*"
36 return -1
37 }
38 -re "$gdb_prompt $" {}
39 }
40
41 # Usage: gdb_py_test_multiple NAME INPUT RESULT {INPUT RESULT}...
42 # Run a test named NAME, consisting of multiple lines of input.
43 # After each input line INPUT, search for result line RESULT.
44 # Succeed if all results are seen; fail otherwise.
45 proc gdb_py_test_multiple {name args} {
46 global gdb_prompt
47 foreach {input result} $args {
48 if {[gdb_test_multiple $input "$name - $input" {
49 -re "\[\r\n\]*($result)\[\r\n\]+($gdb_prompt | *>)$" {
50 pass "$name - $input"
51 }
52 }]} {
53 return 1
54 }
55 }
56 return 0
57 }
58
59 gdb_py_test_multiple "multi-line python command" \
60 "python" "" \
61 "print 23" "" \
62 "end" "23"
63
64 gdb_py_test_multiple "show python command" \
65 "define zzq" "Type commands for definition of .* just \"end\"\\.*" \
66 "python" "" \
67 "print 23" "" \
68 "end" "" \
69 "end" "" \
70 "show user zzq" "User command \"zzq\":.* python.*print 23.* end"
71
72 gdb_py_test_multiple "indented multi-line python command" \
73 "python" "" \
74 "def foo ():" "" \
75 " print 'hello, world!'" "" \
76 "foo ()" "" \
77 "end" "hello, world!"
78
79 gdb_test "source $srcdir/$subdir/source2.py" "yes"
80
81 gdb_test "python print gdb.current_objfile()" "None"
82 gdb_test "python print gdb.objfiles()" "\\\[\\\]"
83
84 # Test http://bugs.python.org/issue4434 workaround in configure.ac
85 gdb_test "python import itertools; print 'IMPOR'+'TED'" "IMPORTED" "pythonX.Y/lib-dynload/*.so"
86
87 gdb_test_no_output \
88 "python x = gdb.execute('printf \"%d\", 23', to_string = True)"
89 gdb_test "python print x" "23"
90
91 # Test (no) pagination of the executed command.
92 gdb_test "show height" {Number of lines gdb thinks are in a page is unlimited\.}
93 set lines 10
94 gdb_test_no_output "set height $lines"
95
96 set test "verify pagination beforehand"
97 gdb_test_multiple "python print \"\\n\" * $lines" $test {
98 -re "---Type <return> to continue, or q <return> to quit---$" {
99 pass $test
100 }
101 }
102 gdb_test "q" "Quit" "verify pagination beforehand: q"
103
104 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"
105
106 set test "verify pagination afterwards"
107 gdb_test_multiple "python print \"\\n\" * $lines" $test {
108 -re "---Type <return> to continue, or q <return> to quit---$" {
109 pass $test
110 }
111 }
112 gdb_test "q" "Quit" "verify pagination afterwards: q"
This page took 0.039594 seconds and 4 git commands to generate.