This is the mail archive of the
archer@sourceware.org
mailing list for the Archer project.
Re: Frames as scopes
El lun, 05-01-2009 a las 17:14 -0700, Tom Tromey escribiÃ:
> >>>>> "Thiago" == Thiago Jung Bauermann <bauerman@br.ibm.com> writes:
> Thiago> Also, the construction gdb.block_for_pc
> Thiago> (gdb.{current,selected}_frame().pc() occurs rather frequently. I have a
> Thiago> line like that in in_scope.py as well. A block() method to gdb.Frame
> Thiago> would be a good idea.
>
> I was thinking the same thing.
>
> Are you working on this?
I wasn't at the tie, but I just committed this.
--
[]'s
Thiago Jung Bauermann
IBM Linux Technology Center
gdb/
2009-01-28 Thiago Jung Bauermann <bauerman@br.ibm.com>
* python/lib/gdb/function/in_scope.py (invoke): Change to use `block' method
of the Frame object.
* python/python-frame.c (frapy_block): New function.
(frame_object_methods): Add `block' entry.
gdb/testsuite/
2009-01-28 Thiago Jung Bauermann <bauerman@br.ibm.com>
* gdb.python/python-frame.exp: Add test for `block' method.
diff --git a/gdb/python/lib/gdb/function/in_scope.py b/gdb/python/lib/gdb/function/in_scope.py
index 9d32ad4..debb3bb 100644
--- a/gdb/python/lib/gdb/function/in_scope.py
+++ b/gdb/python/lib/gdb/function/in_scope.py
@@ -32,7 +32,7 @@ Takes one argument for each variable name to be checked."""
# Convert to string first.
wanted = set (map (lambda x: x.string (), vars))
found = set ()
- block = gdb.block_for_pc (gdb.selected_frame ().pc ())
+ block = gdb.selected_frame ().block ()
while block:
for sym in block:
if (sym.is_argument or sym.is_constant
diff --git a/gdb/python/python-frame.c b/gdb/python/python-frame.c
index 8bc66cd..c2224cf 100644
--- a/gdb/python/python-frame.c
+++ b/gdb/python/python-frame.c
@@ -19,6 +19,7 @@
#include "defs.h"
#include "charset.h"
+#include "block.h"
#include "frame.h"
#include "exceptions.h"
#include "symtab.h"
@@ -204,6 +205,27 @@ frapy_pc (PyObject *self, PyObject *args)
}
static PyObject *
+frapy_block (PyObject *self, PyObject *args)
+{
+ struct frame_info *frame;
+ struct block *block = NULL;
+ volatile struct gdb_exception except;
+
+ TRY_CATCH (except, RETURN_MASK_ALL)
+ {
+ FRAPY_REQUIRE_VALID ((frame_object *) self, frame);
+
+ block = block_for_pc (get_frame_address_in_block (frame));
+ }
+ GDB_PY_HANDLE_EXCEPTION (except);
+
+ if (block)
+ return block_to_block_object (block);
+
+ Py_RETURN_NONE;
+}
+
+static PyObject *
frapy_addr_in_block (PyObject *self, PyObject *args)
{
CORE_ADDR pc = 0; /* Initialize to appease gcc warning. */
@@ -503,6 +525,7 @@ static PyMethodDef frame_object_methods[] = {
{ "unwind_stop_reason", frapy_unwind_stop_reason, METH_NOARGS,
"Return the function name of the frame." },
{ "pc", frapy_pc, METH_NOARGS, "Return the frame's resume address." },
+ { "block", frapy_block, METH_NOARGS, "Return the frame's code block." },
{ "addr_in_block", frapy_addr_in_block, METH_NOARGS,
"Return an address which falls within the frame's code block." },
{ "older", frapy_older, METH_NOARGS,
diff --git a/gdb/testsuite/gdb.python/python-frame.exp b/gdb/testsuite/gdb.python/python-frame.exp
index 11fb24b..cfa2226 100644
--- a/gdb/testsuite/gdb.python/python-frame.exp
+++ b/gdb/testsuite/gdb.python/python-frame.exp
@@ -79,3 +79,5 @@ gdb_test "python print 'result =', f0.pc ()" " = \[0-9\]+" "test Frame.pc"
gdb_test "python print 'result =', f0.addr_in_block ()" " = \[0-9\]+" "test Frame.addr_in_block"
gdb_test "python print 'result =', f0.older ().equals (f1)" " = True" "test Frame.older"
gdb_test "python print 'result =', f1.newer ().equals (f0)" " = True" "test Frame.newer"
+
+gdb_test "python print 'result =', f0.block ()" "<gdb.Block object at 0x\[\[:xdigit:\]\]+>" "test Frame.block"