2011-03-17 Phil Muldoon <pmuldoon@redhat.com>

* python/py-symtab.c: Populate symtab_object_methods,
	    sal_object_methods.
	    (stpy_is_valid): New function.
	    (salpy_is_valid): Ditto.
	    * python/py-symbol.c: Declare symbol_object_methods.
	    Populate.
	    (sympy_is_valid): New function.
	    * python/py-objfile.c: Declare objfile_object_methods.
	    Populate.
	    (objfpy_is_valid): New function.
	    * python/py-inferior.c: Populate inferior_object_methods.
	    (infpy_is_valid): New function.
	    * python/py-infthread.c: Populate thread_object_methods.
	    (thpy_is_valid): New function.
	    * python/py-block.c: Declare block_object_methods.
	    Populate.  Declare
	    block_iterator_object_methods.  Populate.
	    (blpy_is_valid): New function.
	    (blpy_iter_is_valid): Ditto.

2010-03-17  Phil Muldoon  <pmuldoon@redhat.com>

	    * gdb.python/Makefile.in: Add py-objfile.
	    * gdb.python/py-objfile.exp: New file.
	    * gdb.python/py-objfile.c: New file.
	    * gdb.python/py-block.exp: Add is_valid tests.
	    * gdb.python/py-inferior.exp: Ditto.
	    * gdb.python/py-infthread.exp: Ditto.
	    * gdb.python/py-symbol.exp: Ditto.
	    * gdb.python/py-symtab.exp: Ditto.

2011-03-17  Phil Muldoon  <pmuldoon@redhat.com>

	    * gdb.texinfo (Blocks In Python): Add is_valid method
              description.
	      (Inferiors In Python): Likewise.
	      (Threads In Python): Likewise.
	      (Symbols In Python): Likewise.
	      (Objfiles In Python): Likewise.
	      (Symbol Tables In Python): Likewise.
This commit is contained in:
Phil Muldoon
2011-03-17 09:36:17 +00:00
parent a6363bfc38
commit 29703da4b1
19 changed files with 427 additions and 8 deletions

View File

@ -4,7 +4,7 @@ srcdir = @srcdir@
EXECUTABLES = py-type py-value py-prettyprint py-template py-block \
py-symbol py-mi py-breakpoint py-inferior py-infthread \
py-shared python lib-types py-events py-evthreads py-frame \
py-pp-maint py-progspace py-section-script
py-pp-maint py-progspace py-section-script py-objfile
MISCELLANEOUS = py-shared-sl.sl

View File

@ -62,3 +62,20 @@ gdb_py_test_silent_cmd "python block = frame.block()" "Get Frame 2's block" 0
gdb_test "python print block" "<gdb.Block object at $hex>" \
"Check Frame 2's block not None"
gdb_test "python print block.function" "main" "main block"
# Test Block is_valid. This must always be the last test in this
# testcase as it unloads the object file.
delete_breakpoints
gdb_py_test_silent_cmd "python frame = gdb.selected_frame()" "Get Frame" 0
gdb_py_test_silent_cmd "python block = frame.block()" "Get Frame block" 0
gdb_py_test_silent_cmd "python block_iter = iter (block)" "Get Frame block" 0
gdb_test "python print block.is_valid()" "True" \
"Check block validity"
gdb_test "python print block_iter.is_valid()" "True" \
"Check block validity"
gdb_unload
gdb_test "python print block.is_valid()" "False" \
"Check block validity"
gdb_test "python print block_iter.is_valid()" "False" \
"Check block validity"

View File

@ -191,3 +191,23 @@ if [isnative] {
gdb_test "py print gdb.inferiors()\[0\].search_memory (start_addr, end_addr - start_addr, pattern)" \
"${one_pattern_found}" "find pattern straddling chunk boundary"
}
# Test Inferior is_valid. This must always be the last test in
# this testcase as it kills the inferior.
gdb_py_test_silent_cmd "python inf_list = gdb.inferiors()" "get initial list" 1
gdb_test "python print len(inf_list)" "1" "Get inferior list length"
gdb_test "python print inf_list\[0\].is_valid()" "True" \
"Check inferior validity"
gdb_test "add-inferior" "Added inferior 2.*" "add empty inferior 2"
gdb_py_test_silent_cmd "python inf_list = gdb.inferiors()" "get new list" 1
gdb_test "python print len(inf_list)" "2" "Get inferior list length"
gdb_test "python print inf_list\[0\].is_valid()" "True" \
"Check inferior validity"
gdb_test "python print inf_list\[1\].is_valid()" "True" \
"Check inferior validity"
gdb_test_no_output "remove-inferiors 2" "remove-inferiors 2"
gdb_test "python print inf_list\[0\].is_valid()" "False" \
"Check inferior validity"
gdb_test "python print inf_list\[1\].is_valid()" "True" \
"Check inferior validity"

View File

@ -64,3 +64,10 @@ gdb_test "python print gdb.selected_thread().name == name" "True" \
gdb_test "python print 'result =', t0.is_stopped ()" " = True" "test InferiorThread.is_stopped"
gdb_test "python print 'result =', t0.is_running ()" " = False" "test InferiorThread.is_running"
gdb_test "python print 'result =', t0.is_exited ()" " = False" "test InferiorThread.is_exited"
# Test InferiorThread is_valid. This must always be the last test in
# this testcase as it kills the inferior.
gdb_test "python print 'result =', t0.is_valid ()" " = True" "test InferiorThread.is_valid"
gdb_test_no_output "kill inferior 1" "kill inferior 1"
gdb_test "python print 'result =', t0.is_valid ()" " = False" "test InferiorThread.is_valid"

View File

@ -0,0 +1,23 @@
/* This testcase is part of GDB, the GNU debugger.
Copyright 2011 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
int
main ()
{
int some_var = 0;
return 0;
}

View File

@ -0,0 +1,51 @@
# Copyright (C) 2011 Free Software Foundation, Inc.
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# This file is part of the GDB testsuite. It tests the program space
# support in Python.
if $tracelevel then {
strace $tracelevel
}
load_lib gdb-python.exp
set testfile "py-objfile"
set srcfile ${testfile}.c
if { [prepare_for_testing ${testfile}.exp ${testfile} ${srcfile}] } {
return -1
}
# Skip all tests if Python scripting is not enabled.
if { [skip_python_tests] } { continue }
if ![runto_main] then {
fail "Can't run to main"
return 0
}
gdb_py_test_silent_cmd "python sym = gdb.lookup_symbol(\"some_var\")" \
"Find a symbol in objfile" 1
gdb_py_test_silent_cmd "python objfile = sym\[0\].symtab.objfile" \
"Get backing object file" 1
gdb_test "python print objfile.filename" ".*py-objfile.*" \
"Get objfile validity"
gdb_test "python print objfile.is_valid()" "True" \
"Get objfile validity"
gdb_unload
gdb_test "python print objfile.is_valid()" "False" \
"Get objfile validity after unload"

View File

@ -128,3 +128,19 @@ gdb_test "python print cplusfunc.name" "SimpleClass::valueofi().*" "Test func.na
gdb_test "python print cplusfunc.print_name" "SimpleClass::valueofi().*" "Test func.print_name"
gdb_test "python print cplusfunc.linkage_name" "SimpleClass::valueofi().*" "Test func.linkage_name"
gdb_test "python print cplusfunc.addr_class == gdb.SYMBOL_LOC_BLOCK" "True" "Test func.addr_class"
# Test is_valid when the objfile is unloaded. This must be the last
# test as it unloads the object file in GDB.
# Start with a fresh gdb.
clean_restart ${testfile}
if ![runto_main] then {
fail "Cannot run to main."
return 0
}
gdb_breakpoint [gdb_get_line_number "Break at end."]
gdb_continue_to_breakpoint "Break at end."
gdb_py_test_silent_cmd "python a = gdb.lookup_symbol(\'a\')" "Get variable a" 0
gdb_test "python print a\[0\].is_valid()" "True" "Test symbol validity"
delete_breakpoints
gdb_unload
gdb_test "python print a\[0\].is_valid()" "False" "Test symbol validity"

View File

@ -57,8 +57,16 @@ gdb_py_test_silent_cmd "python symtab = sal.symtab" "Get block" 0
gdb_test "python print sal.symtab" "gdb/testsuite/gdb.python/py-symbol.c.*" "Test symtab"
gdb_test "python print sal.pc" "${decimal}" "Test sal.pc"
gdb_test "python print sal.line" "42" "Test sal.line"
gdb_test "python print sal.is_valid()" "True" "Test sal.is_valid"
# Test symbol table.
gdb_test "python print symtab.filename" "testsuite/gdb.python/py-symbol.c.*" "Test symtab.filename"
gdb_test "python print symtab.objfile" "<gdb.Objfile object at ${hex}>" "Test symtab.objfile"
gdb_test "python print symtab.fullname()" "testsuite/gdb.python/py-symbol.c.*" "Test symtab.fullname"
gdb_test "python print symtab.is_valid()" "True" "Test symtab.is_valid()"
# Test is_valid when the objfile is unloaded. This must be the last
# test as it unloads the object file in GDB.
gdb_unload
gdb_test "python print sal.is_valid()" "False" "Test sal.is_valid"
gdb_test "python print symtab.is_valid()" "False" "Test symtab.is_valid()"