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 11:02 -0800, Jim Blandy escribiÃ:
> On Fri, Jan 2, 2009 at 6:14 PM, Thiago Jung Bauermann
> <bauerman@br.ibm.com> wrote:
> > El jue, 01-01-2009 a las 09:47 -0700, Doug Evans escribiÃ:
> >> On Tue, Dec 30, 2008 at 2:57 PM, Jim Blandy <jimb@red-bean.com> wrote:
> >> > Is there a way to look up a variable in the scope specified by a frame? Saying
> >> >
> >> > gdb.lookup_symbol('argc',gdb.block_for_pc(gdb.current_frame().pc()),gdb.SYMBOL_VAR_DOMAIN)
> >> >
> >> > seems circuitous; perhaps lookup_symbol could default the domain to
> >> > SYMBOL_VAR_DOMAIN, and accept a frame to indicate scope, defaulting to
> >> > the current frame. Then one could simply say:
> >> >
> >> > gdb.lookup_symbol('argc')
> >> >
> >> > and get what one expects.
> >
> > Default to current_frame or to selected_frame? I tend to prefer the
> > later, but I don't know which one would be better as a default. Apart
> > from that, I think the defaults you mention are a good idea.
>
> You're right, selected_frame is better --- its whole reason for
> existence is to provide a default frame for things. :)
Ok, I committed the patch below which adds those defaults to lookup
symbol. Except that it continues expecting a Block object instead of a
Frame object. Since Frame now has a "block" method, it shouldn't be too
inconvenient. If no Block is provided, it gets one from selected_frame.
> Perhaps unfriendly primitives (implemented in C) would live in a
> separate module (gdb.primitives), and then friendly Python
> functions/classes based on them would live in the gdb module. The
> latter would be the only documented, supported interface.
That was one basic choice we face at the beginning of the work: expose
crude functions from C to Python and use them to build a Python API
using some Python glue, or directly provide Python classes implemented
in C without the Python glue? We opted for the latter, though no strong
argument was uttered supporting either option... At least for now, I
don't see a problem with the approach we took.
--
[]'s
Thiago Jung Bauermann
IBM Linux Technology Center
2009-01-29 Thiago Jung Bauermann <bauerman@br.ibm.com>
* python/python-symbol.c (gdbpy_lookup_symbol): Turn block and domain
into optional parameters.
* python/lib/gdb/command/backtrace.py (write_symbol): Don't explicitly
define domain in call to `gdb.lookup_symbol'.
diff --git a/gdb/python/lib/gdb/command/backtrace.py b/gdb/python/lib/gdb/command/backtrace.py
index 97c76d1..e01e2b6 100644
--- a/gdb/python/lib/gdb/command/backtrace.py
+++ b/gdb/python/lib/gdb/command/backtrace.py
@@ -27,7 +27,7 @@ class FrameWrapper:
def write_symbol (self, stream, sym, block):
if len (sym.linkage_name):
- nsym, is_field_of_this = gdb.lookup_symbol (sym.linkage_name, block, gdb.SYMBOL_VAR_DOMAIN)
+ nsym, is_field_of_this = gdb.lookup_symbol (sym.linkage_name, block)
if nsym.addr_class != gdb.SYMBOL_LOC_REGISTER:
sym = nsym
diff --git a/gdb/python/python-symbol.c b/gdb/python/python-symbol.c
index aaea04c..223e6d3 100644
--- a/gdb/python/python-symbol.c
+++ b/gdb/python/python-symbol.c
@@ -18,6 +18,9 @@
along with this program. If not, see <http://www.gnu.org/licenses/>. */
#include "defs.h"
+#include "block.h"
+#include "exceptions.h"
+#include "frame.h"
#include "symtab.h"
#include "python-internal.h"
@@ -170,21 +173,29 @@ symbol_object_to_symbol (PyObject *obj)
is_a_field_of_this. */
PyObject *gdbpy_lookup_symbol (PyObject *self, PyObject *args)
{
- int domain, is_a_field_of_this = 0;
+ int domain = VAR_DOMAIN, is_a_field_of_this = 0;
const char *name;
struct symbol *symbol;
- PyObject *block_obj, *ret_tuple, *sym_obj, *bool_obj;
- struct block *block;
+ PyObject *block_obj = NULL, *ret_tuple, *sym_obj, *bool_obj;
+ struct block *block = NULL;
- if (! PyArg_ParseTuple (args, "sO!i", &name, &block_object_type, &block_obj,
+ if (! PyArg_ParseTuple (args, "s|O!i", &name, &block_object_type, &block_obj,
&domain))
return NULL;
- block = block_object_to_block (block_obj);
- if (! block)
+ if (block_obj)
+ block = block_object_to_block (block_obj);
+ else
{
- PyErr_SetString (PyExc_RuntimeError, "second argument must be block");
- return NULL;
+ struct frame_info *selected_frame;
+ volatile struct gdb_exception except;
+
+ TRY_CATCH (except, RETURN_MASK_ALL)
+ {
+ selected_frame = get_selected_frame (_("No frame selected."));
+ block = block_for_pc (get_frame_address_in_block (selected_frame));
+ }
+ GDB_PY_HANDLE_EXCEPTION (except);
}
symbol = lookup_symbol (name, block, domain, &is_a_field_of_this);