include/elf/
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.python / python.exp
CommitLineData
7b6bb8da 1# Copyright (C) 2008, 2009, 2010, 2011 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
19if $tracelevel then {
20 strace $tracelevel
21}
22
a2c09bd0
DE
23load_lib gdb-python.exp
24
cb2e07a6
PM
25set testfile "python"
26set srcfile ${testfile}.c
e7fbb131 27set srcfile1 ${testfile}-1.c
cb2e07a6
PM
28set binfile ${objdir}/${subdir}/${testfile}
29
e7fbb131
PA
30if { [gdb_compile "${srcdir}/${subdir}/${srcfile} ${srcdir}/${subdir}/${srcfile1}" \
31 ${binfile} executable {debug}] != "" } {
cb2e07a6
PM
32 untested "Could not compile $binfile."
33 return -1
34}
d57a3c85 35
cb2e07a6 36# Start with a fresh gdb.
d57a3c85
TJB
37gdb_exit
38gdb_start
39gdb_reinitialize_dir $srcdir/$subdir
40
cb2e07a6
PM
41# Skip all tests if Python scripting is not enabled.
42if { [skip_python_tests] } { continue }
43
d57a3c85
TJB
44gdb_test_multiple "python print 23" "verify python support" {
45 -re "not supported.*$gdb_prompt $" {
46 unsupported "python support is disabled"
9e14a9ba
JB
47
48 # If Python is not supported, verify that sourcing a python script
49 # causes an error.
50 gdb_test "source $srcdir/$subdir/source2.py" "Error in sourced command file:.*"
d57a3c85
TJB
51 return -1
52 }
53 -re "$gdb_prompt $" {}
54}
55
d57a3c85
TJB
56gdb_py_test_multiple "multi-line python command" \
57 "python" "" \
58 "print 23" "" \
59 "end" "23"
60
61gdb_py_test_multiple "show python command" \
62 "define zzq" "Type commands for definition of .* just \"end\"\\.*" \
63 "python" "" \
64 "print 23" "" \
65 "end" "" \
66 "end" "" \
adb483fe 67 "show user zzq" "User command \"zzq\":.* python.*print 23.* end"
311a4e6b
TJB
68
69gdb_py_test_multiple "indented multi-line python command" \
70 "python" "" \
71 "def foo ():" "" \
72 " print 'hello, world!'" "" \
73 "foo ()" "" \
74 "end" "hello, world!"
89c73ade 75
9e14a9ba
JB
76gdb_test "source $srcdir/$subdir/source2.py" "yes"
77
89c73ade
TT
78gdb_test "python print gdb.current_objfile()" "None"
79gdb_test "python print gdb.objfiles()" "\\\[\\\]"
3bebe2f2
JK
80
81# Test http://bugs.python.org/issue4434 workaround in configure.ac
82gdb_test "python import itertools; print 'IMPOR'+'TED'" "IMPORTED" "pythonX.Y/lib-dynload/*.so"
bc9f0842
TT
83
84gdb_test_no_output \
85 "python x = gdb.execute('printf \"%d\", 23', to_string = True)"
86gdb_test "python print x" "23"
5da1313b 87
ca5c20b6
PM
88# Test post_event.
89gdb_py_test_multiple "post event insertion" \
90 "python" "" \
91 "someVal = 0" "" \
70ebf4ed 92 "class Foo(object):" "" \
ca5c20b6
PM
93 " def __call__(self):" "" \
94 " global someVal" "" \
95 " someVal += 1" "" \
96 "gdb.post_event(Foo())" "" \
97 "end" ""
98
99gdb_test "python print someVal" "1" "test post event execution"
100gdb_test "python gdb.post_event(str(1))" "RuntimeError: Posted event is not callable.*" "Test non callable class"
101
5da1313b
JK
102# Test (no) pagination of the executed command.
103gdb_test "show height" {Number of lines gdb thinks are in a page is unlimited\.}
104set lines 10
105gdb_test_no_output "set height $lines"
106
107set test "verify pagination beforehand"
108gdb_test_multiple "python print \"\\n\" * $lines" $test {
109 -re "---Type <return> to continue, or q <return> to quit---$" {
110 pass $test
111 }
112}
113gdb_test "q" "Quit" "verify pagination beforehand: q"
114
115gdb_test "python if gdb.execute('python print \"\\\\n\" * $lines', to_string=True) == \"\\n\" * [expr $lines + 1]: print \"yes\"" "yes" "gdb.execute does not page"
116
117set test "verify pagination afterwards"
118gdb_test_multiple "python print \"\\n\" * $lines" $test {
119 -re "---Type <return> to continue, or q <return> to quit---$" {
120 pass $test
121 }
122}
123gdb_test "q" "Quit" "verify pagination afterwards: q"
cb2e07a6 124
8d4d924b
JK
125gdb_test_no_output "set height 0"
126
127gdb_test_no_output "python a = gdb.execute('help', to_string=True)" "collect help from uiout"
128
129gdb_test "python print a" ".*aliases -- Aliases of other commands.*" "verify help to uiout"
130
ea976c60
PM
131# Test PR 12212, using InfThread.selected_thread() when no inferior is
132# loaded.
133gdb_py_test_silent_cmd "python nothread = gdb.selected_thread()" "Attempt to aquire thread with no inferior" 1
134gdb_test "python print nothread == None" "True" "Ensure that no threads are returned"
135
cb2e07a6
PM
136# Start with a fresh gdb.
137clean_restart ${testfile}
138
139# The following tests require execution.
140
141if ![runto_main] then {
142 fail "Can't run to main"
143 return 0
144}
145
146runto [gdb_get_line_number "Break to end."]
147
148# Test gdb.decode_line.
149gdb_test "python gdb.decode_line(\"main.c:43\")" \
621c8364 150 "gdb.error: No source file named main.c.*" "test decode_line no source named main"
cb2e07a6
PM
151
152gdb_py_test_silent_cmd "python symtab = gdb.decode_line()" "test decode_line current location" 1
153gdb_test "python print len(symtab)" "2" "Test decode_line current location"
154gdb_test "python print symtab\[0\]" "None" "Test decode_line expression parse"
155gdb_test "python print len(symtab\[1\])" "1" "Test decode_line current location"
156gdb_test "python print symtab\[1\]\[0\].symtab" "gdb/testsuite/gdb.python/python.c.*" "Test decode_line current locationn filename"
157gdb_test "python print symtab\[1\]\[0\].line" "22" "Test decode_line current location line number"
158
159gdb_py_test_silent_cmd "python symtab = gdb.decode_line(\"python.c:26 if foo\")" "test decode_line python.c:26" 1
160gdb_test "python print len(symtab)" "2" "Test decode_line python.c:26 length"
161gdb_test "python print symtab\[0\]" "if foo" "Test decode_line expression parse"
162gdb_test "python print len(symtab\[1\])" "1" "Test decode_line python.c:26 length"
163gdb_test "python print symtab\[1\]\[0\].symtab" "gdb/testsuite/gdb.python/python.c.*" "Test decode_line python.c:26 filename"
164gdb_test "python print symtab\[1\]\[0\].line" "26" "Test decode_line python.c:26 line number"
165
166gdb_test "python gdb.decode_line(\"randomfunc\")" \
621c8364 167 "gdb.error: Function \"randomfunc\" not defined.*" "test decode_line randomfunc"
cb2e07a6
PM
168gdb_py_test_silent_cmd "python symtab = gdb.decode_line(\"func1\")" "test decode_line func1()" 1
169gdb_test "python print len(symtab)" "2" "Test decode_line func1 length"
170gdb_test "python print len(symtab\[1\])" "1" "Test decode_line func1 length"
e7fbb131 171gdb_test "python print symtab\[1\]\[0\].symtab" "gdb/testsuite/gdb.python/python-1.c.*" "Test decode_line func1 filename"
cb2e07a6 172gdb_test "python print symtab\[1\]\[0\].line" "19" "Test decode_line func1 line number"
This page took 0.307436 seconds and 4 git commands to generate.