aboutsummaryrefslogtreecommitdiff
path: root/gdb/testsuite/gdb.python/python.exp
diff options
context:
space:
mode:
authorPhil Muldoon <pmuldoon@redhat.com>2010-08-11 12:48:24 +0000
committerPhil Muldoon <pmuldoon@redhat.com>2010-08-11 12:48:24 +0000
commitcb2e07a6f002d0b1b6e7339b0475e674955c03ef (patch)
tree165397cdd9807e469cb55c615aeaf72bb51af933 /gdb/testsuite/gdb.python/python.exp
parentbd69efceb48c29b8ca1f1c845fd9e8032a1fb778 (diff)
downloadgdb-cb2e07a6f002d0b1b6e7339b0475e674955c03ef.zip
gdb-cb2e07a6f002d0b1b6e7339b0475e674955c03ef.tar.gz
gdb-cb2e07a6f002d0b1b6e7339b0475e674955c03ef.tar.bz2
2010-08-11 Phil Muldoon <pmuldoon@redhat.com>
Thiago Jung Bauermann <bauerman@br.ibm.com> Tom Tromey <tromey@redhat.com> * python/python.c (gdbpy_solib_address): New function. (gdbpy_decode_line): Likewise. 2010-08-11 Phil Muldoon <pmuldoon@redhat.com> * gdb.texinfo (Basic Python): Describe solib_address and decode_line Python APIs 2010-08-11 Phil Muldoon <pmuldoon@redhat.com> * gdb.python/python.c: New File. * gdb.python/python-sl.c: New File. * gdb.python/python.exp: Test solib_address and decode_line * functions.
Diffstat (limited to 'gdb/testsuite/gdb.python/python.exp')
-rw-r--r--gdb/testsuite/gdb.python/python.exp81
1 files changed, 80 insertions, 1 deletions
diff --git a/gdb/testsuite/gdb.python/python.exp b/gdb/testsuite/gdb.python/python.exp
index 7aef888..e153ab8 100644
--- a/gdb/testsuite/gdb.python/python.exp
+++ b/gdb/testsuite/gdb.python/python.exp
@@ -20,12 +20,44 @@ if $tracelevel then {
strace $tracelevel
}
-# Start with a fresh gdb.
+set testfile "python"
+set srcfile ${testfile}.c
+set libfile "python-sl"
+set libsrc ${libfile}.c
+set library ${objdir}/${subdir}/${libfile}.sl
+set binfile ${objdir}/${subdir}/${testfile}
+
+if { [gdb_compile_shlib ${srcdir}/${subdir}/${libsrc} ${library} "debug"] != "" } {
+ untested "Could not compile shared library."
+ return -1
+}
+
+set exec_opts [list debug shlib=${library}]
+
+if { [gdb_compile ${srcdir}/${subdir}/${srcfile} ${binfile} executable $exec_opts] != "" } {
+ untested "Could not compile $binfile."
+ return -1
+}
+# Start with a fresh gdb.
gdb_exit
gdb_start
gdb_reinitialize_dir $srcdir/$subdir
+# Skip all tests if Python scripting is not enabled.
+if { [skip_python_tests] } { continue }
+
+# Run a command in GDB, and report a failure if a Python exception is thrown.
+# If report_pass is true, report a pass if no exception is thrown.
+proc gdb_py_test_silent_cmd {cmd name report_pass} {
+ global gdb_prompt
+
+ gdb_test_multiple $cmd $name {
+ -re "Traceback.*$gdb_prompt $" { fail $name }
+ -re "$gdb_prompt $" { if $report_pass { pass $name } }
+ }
+}
+
gdb_test_multiple "python print 23" "verify python support" {
-re "not supported.*$gdb_prompt $" {
unsupported "python support is disabled"
@@ -110,3 +142,50 @@ gdb_test_multiple "python print \"\\n\" * $lines" $test {
}
}
gdb_test "q" "Quit" "verify pagination afterwards: q"
+
+# Start with a fresh gdb.
+clean_restart ${testfile}
+
+# The following tests require execution.
+
+if ![runto_main] then {
+ fail "Can't run to main"
+ return 0
+}
+
+runto [gdb_get_line_number "Break to end."]
+
+# Test gdb.decode_line.
+gdb_test "python gdb.decode_line(\"main.c:43\")" \
+ "RuntimeError: No source file named main.c.*" "test decode_line no source named main"
+
+gdb_py_test_silent_cmd "python symtab = gdb.decode_line()" "test decode_line current location" 1
+gdb_test "python print len(symtab)" "2" "Test decode_line current location"
+gdb_test "python print symtab\[0\]" "None" "Test decode_line expression parse"
+gdb_test "python print len(symtab\[1\])" "1" "Test decode_line current location"
+gdb_test "python print symtab\[1\]\[0\].symtab" "gdb/testsuite/gdb.python/python.c.*" "Test decode_line current locationn filename"
+gdb_test "python print symtab\[1\]\[0\].line" "22" "Test decode_line current location line number"
+
+gdb_py_test_silent_cmd "python symtab = gdb.decode_line(\"python.c:26 if foo\")" "test decode_line python.c:26" 1
+gdb_test "python print len(symtab)" "2" "Test decode_line python.c:26 length"
+gdb_test "python print symtab\[0\]" "if foo" "Test decode_line expression parse"
+gdb_test "python print len(symtab\[1\])" "1" "Test decode_line python.c:26 length"
+gdb_test "python print symtab\[1\]\[0\].symtab" "gdb/testsuite/gdb.python/python.c.*" "Test decode_line python.c:26 filename"
+gdb_test "python print symtab\[1\]\[0\].line" "26" "Test decode_line python.c:26 line number"
+
+gdb_test "python gdb.decode_line(\"randomfunc\")" \
+ "RuntimeError: Function \"randomfunc\" not defined.*" "test decode_line randomfunc"
+gdb_py_test_silent_cmd "python symtab = gdb.decode_line(\"func1\")" "test decode_line func1()" 1
+gdb_test "python print len(symtab)" "2" "Test decode_line func1 length"
+gdb_test "python print len(symtab\[1\])" "1" "Test decode_line func1 length"
+gdb_test "python print symtab\[1\]\[0\].symtab" "gdb/testsuite/gdb.python/python-sl.c.*" "Test decode_line func1 filename"
+gdb_test "python print symtab\[1\]\[0\].line" "19" "Test decode_line func1 line number"
+
+# Test gdb.solib_name
+gdb_test "p &func1" "" "func1 address"
+gdb_py_test_silent_cmd "python func1 = gdb.history(0)" "Aquire func1 address" 1
+gdb_test "python print gdb.solib_name(long(func1))" "gdb/testsuite/gdb.python/python-sl.sl" "test func1 solib location"
+
+gdb_test "p &main" "" "main address"
+gdb_py_test_silent_cmd "python main = gdb.history(0)" "Aquire main address" 1
+gdb_test "python print gdb.solib_name(long(main))" "None" "test main solib location"