* gdb.python/py-shared.exp: New file, factored out from
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.python / py-shared.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.
17
18 if {[skip_shlib_tests]} {
19 return 0
20 }
21
22 set testfile "py-shared"
23 set srcfile ${testfile}.c
24 set libfile "py-shared-sl"
25 set libsrc ${libfile}.c
26 set library ${objdir}/${subdir}/${libfile}.sl
27 set binfile ${objdir}/${subdir}/${testfile}
28
29 if { [gdb_compile_shlib ${srcdir}/${subdir}/${libsrc} ${library} "debug"] != "" } {
30 untested "Could not compile shared library."
31 return -1
32 }
33
34 set exec_opts [list debug shlib=${library}]
35
36 if { [gdb_compile ${srcdir}/${subdir}/${srcfile} ${binfile} executable $exec_opts] != "" } {
37 untested "Could not compile $binfile."
38 return -1
39 }
40
41 # Run a command in GDB, and report a failure if a Python exception is thrown.
42 # If report_pass is true, report a pass if no exception is thrown.
43 proc gdb_py_test_silent_cmd {cmd name report_pass} {
44 global gdb_prompt
45
46 gdb_test_multiple $cmd $name {
47 -re "Traceback.*$gdb_prompt $" { fail $name }
48 -re "$gdb_prompt $" { if $report_pass { pass $name } }
49 }
50 }
51
52 # Start with a fresh gdb.
53 gdb_exit
54 gdb_start
55 gdb_reinitialize_dir $srcdir/$subdir
56 gdb_load ${binfile}
57
58 # Skip all tests if Python scripting is not enabled.
59 if { [skip_python_tests] } { continue }
60
61 # The following tests require execution.
62
63 if ![runto_main] then {
64 fail "Can't run to main"
65 return 0
66 }
67
68 runto [gdb_get_line_number "Break to end."]
69
70 # Test gdb.solib_name
71 gdb_test "p &func1" "" "func1 address"
72 gdb_py_test_silent_cmd "python func1 = gdb.history(0)" "Aquire func1 address" 1
73 gdb_test "python print gdb.solib_name(long(func1))" "gdb/testsuite/gdb.python/py-shared-sl.sl" "test func1 solib location"
74
75 gdb_test "p &main" "" "main address"
76 gdb_py_test_silent_cmd "python main = gdb.history(0)" "Aquire main address" 1
77 gdb_test "python print gdb.solib_name(long(main))" "None" "test main solib location"
This page took 0.033296 seconds and 5 git commands to generate.