From a20ee7a4a9d43404d9c566453ba6c9578adc3596 Mon Sep 17 00:00:00 2001 From: Siva Chandra Reddy Date: Thu, 3 May 2012 07:07:26 +0000 Subject: [PATCH] 2012-05-03 Siva Chandra Reddy Add two new methods global_block and static_block to gdb.Symtab objects. * NEWS (Python scripting): Add entry about the new methods. * python/py-symtab.c (stpy_global_block): New function which implements the gdb.Symtab.global_block() method. (stpy_static_block): New function which implements the gdb.Symtab.static_block() method. (symtab_object_methods): Add entries for the two new methods. * testsuite/gdb.python/py-symbol.exp: Add tests to test the new methods gdb.Symtab.global_block() and gdb.Symtab.static_block(). * tessuite/gdb.python/py-symbol.c: Add new struct to help test gdb.Symtab.static_block(). * doc/gdb.texinfo (Symbol Tables In Python): Add documentation about the new methods global_block and static_block on gdb.Symtab objects. --- gdb/ChangeLog | 11 ++++++++ gdb/NEWS | 4 +++ gdb/doc/ChangeLog | 6 ++++ gdb/doc/gdb.texinfo | 10 +++++++ gdb/python/py-symtab.c | 39 ++++++++++++++++++++++++++ gdb/testsuite/ChangeLog | 7 +++++ gdb/testsuite/gdb.python/py-symbol.c | 6 ++++ gdb/testsuite/gdb.python/py-symtab.exp | 11 ++++++++ 8 files changed, 94 insertions(+) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index a929237dde..9bc5af0f97 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,14 @@ +2012-05-03 Siva Chandra Reddy + + Add two new methods global_block and static_block to gdb.Symtab + objects. + * NEWS (Python scripting): Add entry about the new methods. + * python/py-symtab.c (stpy_global_block): New function which + implements the gdb.Symtab.global_block() method. + (stpy_static_block): New function which implements the + gdb.Symtab.static_block() method. + (symtab_object_methods): Add entries for the two new methods. + 2012-05-03 Doug Evans * dwarf2read.c (dw2_find_symbol_file): Don't crash if there are no diff --git a/gdb/NEWS b/gdb/NEWS index 2762c09038..8b620c1716 100644 --- a/gdb/NEWS +++ b/gdb/NEWS @@ -39,6 +39,10 @@ ** A new method 'referenced_value' on gdb.Value objects which can dereference pointer as well as C++ reference values. + ** New methods 'global_block' and 'static_block' on gdb.Symtab objects + which return the global and static blocks (as gdb.Block objects), + of the underlying symbol table, respectively. + * Go language support. GDB now supports debugging programs written in the Go programming language. diff --git a/gdb/doc/ChangeLog b/gdb/doc/ChangeLog index 385e919d80..8dd273c061 100644 --- a/gdb/doc/ChangeLog +++ b/gdb/doc/ChangeLog @@ -1,3 +1,9 @@ +2012-05-03 Siva Chandra Reddy + + * gdb.texinfo (Symbol Tables In Python): Add documentation about + the new methods global_block and static_block on gdb.Symtab + objects. + 2012-05-02 Siva Chandra Reddy * gdb.texinfo (Blocks In Python): Add a note saying that future diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo index e0b852939f..014b39b9d7 100644 --- a/gdb/doc/gdb.texinfo +++ b/gdb/doc/gdb.texinfo @@ -25038,6 +25038,16 @@ if it is invalid at the time the method is called. @defun Symtab.fullname () Return the symbol table's source absolute file name. @end defun + +@defun Symtab.global_block () +Return the global block of the underlying symbol table. +@xref{Blocks In Python}. +@end defun + +@defun Symtab.static_block () +Return the static block of the underlying symbol table. +@xref{Blocks In Python}. +@end defun @end table @node Breakpoints In Python diff --git a/gdb/python/py-symtab.c b/gdb/python/py-symtab.c index 09b760fc4d..e9e38b2f3c 100644 --- a/gdb/python/py-symtab.c +++ b/gdb/python/py-symtab.c @@ -23,6 +23,7 @@ #include "source.h" #include "python-internal.h" #include "objfiles.h" +#include "block.h" typedef struct stpy_symtab_object { PyObject_HEAD @@ -153,6 +154,38 @@ stpy_is_valid (PyObject *self, PyObject *args) Py_RETURN_TRUE; } +/* Return the GLOBAL_BLOCK of the underlying symtab. */ + +static PyObject * +stpy_global_block (PyObject *self, PyObject *args) +{ + struct symtab *symtab = NULL; + struct block *block = NULL; + struct blockvector *blockvector; + + STPY_REQUIRE_VALID (self, symtab); + + blockvector = BLOCKVECTOR (symtab); + block = BLOCKVECTOR_BLOCK (blockvector, GLOBAL_BLOCK); + return block_to_block_object (block, symtab->objfile); +} + +/* Return the STATIC_BLOCK of the underlying symtab. */ + +static PyObject * +stpy_static_block (PyObject *self, PyObject *args) +{ + struct symtab *symtab = NULL; + struct block *block = NULL; + struct blockvector *blockvector; + + STPY_REQUIRE_VALID (self, symtab); + + blockvector = BLOCKVECTOR (symtab); + block = BLOCKVECTOR_BLOCK (blockvector, STATIC_BLOCK); + return block_to_block_object (block, symtab->objfile); +} + static PyObject * salpy_str (PyObject *self) { @@ -477,6 +510,12 @@ Return true if this symbol table is valid, false if not." }, { "fullname", stpy_fullname, METH_NOARGS, "fullname () -> String.\n\ Return the symtab's full source filename." }, + { "global_block", stpy_global_block, METH_NOARGS, + "global_block () -> gdb.Block.\n\ +Return the global block of the symbol table." }, + { "static_block", stpy_static_block, METH_NOARGS, + "static_block () -> gdb.Block.\n\ +Return the static block of the symbol table." }, {NULL} /* Sentinel */ }; diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index 568b00e65c..c89e6b9b41 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,10 @@ +2012-05-03 Siva Chandra Reddy + + * gdb.python/py-symbol.exp: Add tests to test the new methods + gdb.Symtab.global_block() and gdb.Symtab.static_block(). + * gdb.python/py-symbol.c: Add new struct to help test + gdb.Symtab.static_block(). + 2012-05-03 Doug Evans * gdb.dwarf2/pr13961.S: Add file and source location, but leave diff --git a/gdb/testsuite/gdb.python/py-symbol.c b/gdb/testsuite/gdb.python/py-symbol.c index 4c1c26df58..8c6cdb1137 100644 --- a/gdb/testsuite/gdb.python/py-symbol.c +++ b/gdb/testsuite/gdb.python/py-symbol.c @@ -44,6 +44,11 @@ int func (int arg) return arg; /* Block break here. */ } +struct simple_struct +{ + int a; +}; + int main (int argc, char *argv[]) { #ifdef __cplusplus @@ -51,6 +56,7 @@ int main (int argc, char *argv[]) #endif int a = 0; int result; + struct simple_struct ss = { 10 }; enum tag {one, two, three}; enum tag t = one; diff --git a/gdb/testsuite/gdb.python/py-symtab.exp b/gdb/testsuite/gdb.python/py-symtab.exp index 490a891b79..6eec611677 100644 --- a/gdb/testsuite/gdb.python/py-symtab.exp +++ b/gdb/testsuite/gdb.python/py-symtab.exp @@ -49,6 +49,11 @@ gdb_continue_to_breakpoint "Block break here." gdb_py_test_silent_cmd "python frame = gdb.selected_frame()" "Get Frame" 0 gdb_py_test_silent_cmd "python sal = frame.find_sal()" "Get block" 0 gdb_py_test_silent_cmd "python symtab = sal.symtab" "Get block" 0 +gdb_py_test_silent_cmd "python global_block = symtab.global_block()" "Get global block" 0 +gdb_py_test_silent_cmd "python static_block = symtab.static_block()" "Get static block" 0 +gdb_py_test_silent_cmd "python global_symbols = \[\]; static_symbols = \[\]" "Set up symbol name lists" 0 +gdb_py_test_silent_cmd "python for sym in global_block: global_symbols.append(sym.name)" "Get global symbol names" 0 +gdb_py_test_silent_cmd "python for sym in static_block: static_symbols.append(sym.name)" "Get static symbol names" 0 # Test sal. gdb_test "python print sal.symtab" ".*gdb.python/py-symbol.c.*" "Test symtab" @@ -61,6 +66,12 @@ gdb_test "python print symtab.filename" ".*gdb.python/py-symbol.c.*" "Test symta gdb_test "python print symtab.objfile" "" "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()" +gdb_test "python print \"qq\" in global_symbols" "True" "Test qq in global symbols" +gdb_test "python print \"func\" in global_symbols" "True" "Test func in global symbols" +gdb_test "python print \"main\" in global_symbols" "True" "Test main in global symbols" +gdb_test "python print \"int\" in static_symbols" "True" "Test int in static symbols" +gdb_test "python print \"char\" in static_symbols" "True" "Test char in static symbols" +gdb_test "python print \"simple_struct\" in static_symbols" "True" "Test simple_struct in static symbols" # Test is_valid when the objfile is unloaded. This must be the last # test as it unloads the object file in GDB. -- 2.34.1