From: Siva Chandra <sivachandra@google.com>
To: Eli Zaretskii <eliz@gnu.org>
Cc: gdb-patches@sourceware.org
Subject: Re: [RFC - Python scripting] New methods Symtab.global_block and Symtab.static_block (docs included)
Date: Wed, 18 Apr 2012 09:15:00 -0000 [thread overview]
Message-ID: <CAGyQ6gy+i4Tdh4zWDi_+cR+kw3MiU23BvWXgBqu5-+E48rjssw@mail.gmail.com> (raw)
In-Reply-To: <CAGyQ6gxxEeYeCKw_iHXh74Gg223GHxMoW=gvt9kU+ax396kKBQ@mail.gmail.com>
[-- Attachment #1: Type: text/plain, Size: 2208 bytes --]
>> +@defun Symtab.global_block ()
>> +Return the global block of the underlying symbol table. Note that,
>> +though highly unlikely, the returned @code{gdb.Block} objects are not
>> +guaranteed to be identical across different @value{GDBN} releases.
>> +@end defun
>> +
>> +@defun Symtab.static_block ()
>> +Return the static block of the underlying symbol table. Note that,
>> +though highly unlikely, the returned @code{gdb.Block} objects are not
>> +guaranteed to be identical across different @value{GDBN} releases.
>> +@end defun
Eli> I think it would be a good idea to have here a cross-reference to
Eli> "Blocks in Python".
Eli>
Eli> Also, the 2 identical sentences about the objects not being preserved
Eli> across GDB releases should probably be replaced by just one sentence,
Eli> saying this for both types of blocks.
Thanks Eli, for taking a look. I have modified according to your
comments. I would like you to take a look at the doc changes again
since the suggestion wasn't objective for the second change.
ChangeLog correction pointed to by Phil, and the use of accessor
macros as suggested by Tom, are also in the attached patch.
Code:
2012-04-18 Siva Chandra Reddy <sivachandra@google.com>
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:
2012-04-18 Siva Chandra Reddy <sivachandra@google.com>
* 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().
Docs:
2012-04-18 Siva Chandra Reddy <sivachandra@google.com>
* gdb.texinfo (Symbol Tables In Python): Add documentation about
the new methods global_block and static_block on gdb.Symtab
objects.
Thanks,
Siva Chandra
[-- Attachment #2: symtab_blocks_patch_v2.txt --]
[-- Type: text/plain, Size: 6682 bytes --]
Index: NEWS
===================================================================
RCS file: /cvs/src/src/gdb/NEWS,v
retrieving revision 1.510
diff -u -p -r1.510 NEWS
--- NEWS 17 Apr 2012 15:56:21 -0000 1.510
+++ NEWS 18 Apr 2012 06:27:16 -0000
@@ -32,6 +32,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.
+
* GDBserver now supports stdio connections.
E.g. (gdb) target remote | ssh myhost gdbserver - hello
Index: doc/gdb.texinfo
===================================================================
RCS file: /cvs/src/src/gdb/doc/gdb.texinfo,v
retrieving revision 1.944
diff -u -p -r1.944 gdb.texinfo
--- doc/gdb.texinfo 17 Apr 2012 15:56:21 -0000 1.944
+++ doc/gdb.texinfo 18 Apr 2012 06:27:55 -0000
@@ -24920,8 +24920,23 @@ 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
+Note that, though highly unlikely, the @code{gdb.Block} objects returned
+by the methods @code{Symtab.global_block ()} and
+@code{Symtab.static_block ()} are not guaranteed to be identical across
+different @value{GDBN} releases.
+
@node Breakpoints In Python
@subsubsection Manipulating breakpoints using 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 18 Apr 2012 06:27:55 -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 18 Apr 2012 06:27:56 -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 18 Apr 2012 06:27:56 -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.
next prev parent reply other threads:[~2012-04-18 8:49 UTC|newest]
Thread overview: 44+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-04-17 8:39 Siva Chandra
2012-04-17 13:00 ` Phil Muldoon
2012-04-17 17:34 ` Siva Chandra
2012-04-17 17:44 ` Tom Tromey
2012-04-17 17:41 ` Tom Tromey
2012-04-17 17:05 ` Eli Zaretskii
[not found] ` <CAGyQ6gxxEeYeCKw_iHXh74Gg223GHxMoW=gvt9kU+ax396kKBQ@mail.gmail.com>
2012-04-18 9:15 ` Siva Chandra [this message]
2012-04-18 20:45 ` Phil Muldoon
2012-04-18 20:48 ` Tom Tromey
2012-04-19 17:33 ` Siva Chandra
2012-04-19 19:18 ` Doug Evans
2012-04-20 6:48 ` Siva Chandra
2012-04-20 12:12 ` Matt Rice
2012-04-20 14:16 ` Doug Evans
2012-04-20 15:21 ` Matt Rice
2012-04-20 19:12 ` Tom Tromey
2012-04-20 19:53 ` Doug Evans
2012-04-20 19:57 ` Siva Chandra
2012-04-23 13:21 ` Tom Tromey
2012-04-23 13:35 ` Phil Muldoon
2012-04-23 14:11 ` Eli Zaretskii
2012-04-23 14:45 ` Phil Muldoon
2012-04-23 16:00 ` Eli Zaretskii
2012-04-24 11:15 ` Siva Chandra
2012-04-24 17:40 ` Eli Zaretskii
2012-04-25 7:11 ` Tom Tromey
2012-04-25 8:19 ` Siva Chandra
2012-04-26 12:35 ` Siva Chandra
2012-04-26 15:21 ` Doug Evans
2012-05-02 17:41 ` Siva Chandra
2012-05-02 18:15 ` Doug Evans
2012-05-03 7:13 ` Siva Chandra
2012-05-04 18:05 ` FAILing new testcase for -fdebug-types-section [Re: [RFC - Python scripting] New methods Symtab.global_block and Symtab.static_block (docs included)] Jan Kratochvil
2012-05-05 7:01 ` Siva Chandra
2012-05-05 7:05 ` Jan Kratochvil
2012-05-05 7:11 ` Siva Chandra
2012-05-05 7:13 ` Jan Kratochvil
2012-05-23 21:38 ` [patch KFAIL] Re: FAILing new testcase for -fdebug-types-section (PR symtab/14148) Jan Kratochvil
2012-04-18 20:48 ` [RFC - Python scripting] New methods Symtab.global_block and Symtab.static_block (docs included) Tom Tromey
2012-04-20 8:13 ` Eli Zaretskii
2012-04-17 17:37 ` Tom Tromey
2012-04-18 18:41 ` Tom Tromey
2012-04-18 19:53 ` Siva Chandra
2012-04-18 20:49 ` Tom Tromey
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAGyQ6gy+i4Tdh4zWDi_+cR+kw3MiU23BvWXgBqu5-+E48rjssw@mail.gmail.com \
--to=sivachandra@google.com \
--cc=eliz@gnu.org \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox