[RFC - Python scripting] New methods Symtab.global_block and Symtab.static_block (docs included)
Siva Chandra
sivachandra@google.com
Thu May 3 07:13:00 GMT 2012
Siva> Now that the note to the user is in, is this patch ready to go in as
Siva> well? Tom and Eli have already OK-ed, but I am double checking as it
Siva> has been a while since then.
Doug> I think the patch is ok to go in (ref: Tom and Eli have OK'd it).
Committed. Attached the patch for reference.
Thanks,
Siva Chandra
-------------- next part --------------
Index: NEWS
===================================================================
RCS file: /cvs/src/src/gdb/NEWS,v
retrieving revision 1.513
diff -u -p -r1.513 NEWS
--- NEWS 27 Apr 2012 20:47:51 -0000 1.513
+++ NEWS 3 May 2012 06:47:15 -0000
@@ -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.
Index: doc/gdb.texinfo
===================================================================
RCS file: /cvs/src/src/gdb/doc/gdb.texinfo,v
retrieving revision 1.953
diff -u -p -r1.953 gdb.texinfo
--- doc/gdb.texinfo 2 May 2012 17:27:50 -0000 1.953
+++ doc/gdb.texinfo 3 May 2012 06:47:35 -0000
@@ -25038,6 +25038,16 @@ if it is invalid at the time the method
@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
Index: python/py-symtab.c
===================================================================
RCS file: /cvs/src/src/gdb/python/py-symtab.c,v
retrieving revision 1.8
diff -u -p -r1.8 py-symtab.c
--- python/py-symtab.c 4 Jan 2012 08:17:25 -0000 1.8
+++ python/py-symtab.c 3 May 2012 06:47:36 -0000
@@ -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
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 vali
{ "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 */
};
Index: testsuite/gdb.python/py-symbol.c
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/gdb.python/py-symbol.c,v
retrieving revision 1.5
diff -u -p -r1.5 py-symbol.c
--- testsuite/gdb.python/py-symbol.c 7 Feb 2012 19:47:16 -0000 1.5
+++ testsuite/gdb.python/py-symbol.c 3 May 2012 06:47:38 -0000
@@ -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;
Index: testsuite/gdb.python/py-symtab.exp
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/gdb.python/py-symtab.exp,v
retrieving revision 1.8
diff -u -p -r1.8 py-symtab.exp
--- testsuite/gdb.python/py-symtab.exp 7 Feb 2012 19:42:27 -0000 1.8
+++ testsuite/gdb.python/py-symtab.exp 3 May 2012 06:47:38 -0000
@@ -49,6 +49,11 @@ gdb_continue_to_breakpoint "Block break
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_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()"
+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.
More information about the Gdb-patches
mailing list