2011-10-20 Phil Muldoon <pmuldoon@redhat.com>

PR python/12656

	* python/py-frame.c (frapy_read_var): Use const struct *block.
	* python/py-type.c (typy_lookup_typename): Likewise.
	(typy_lookup_type): Likewise.
	(typy_legacy_template_argument): Likewise.
	(typy_template_argument): Likewise.
	(gdbpy_lookup_type): Likewise.
	* python/py-symbol.c (gdbpy_lookup_symbol): Likewise.
	* python/py-block.c (blpy_block_object): Likewise.
	(blpy_iter): Likewise.
	(blpy_get_start): Likewise.
	(blpy_get_end): Likewise.
	(blpy_get_function): Likewise.
	(blpy_get_superblock): Likewise.
	(set_block):  Likewise.
	(block_to_block_object): Likewise.
	(block_object_to_block): Likewise.
	(blpy_is_valid): Likewise.
	(blpy_get_global_block): New function.
	(blpy_get_static_block): New function.
	(blpy_is_global): New function.
	(blpy_is_static): New function.
	* blockframe.c (block_innermost_frame): Likewise.
	* valops.c (value_of_variable): Likewise.
	* frame.h: Update prototypes.
	* python/python-internal.h: Likewise.
	* value.h: Likewise.

2011-10-20  Phil Muldoon  <pmuldoon@redhat.com>

	PR python/12656

	* gdb.texinfo (Blocks In Python): Document is_static, is_global,
	global_block, static_block function.

2011-10-20  Phil Muldoon  <pmuldoon@redhat.com>

	PR python/12656

	* gdb.python/py-block.exp: Add is_global, is_static, static_block,
	global_block tests.
This commit is contained in:
Phil Muldoon 2011-10-20 12:31:30 +00:00
parent 5468810dda
commit 9df2fbc4c1
15 changed files with 186 additions and 24 deletions

View File

@ -1,3 +1,34 @@
2011-10-20 Phil Muldoon <pmuldoon@redhat.com>
PR python/12656
* python/py-frame.c (frapy_read_var): Use const struct *block.
* python/py-type.c (typy_lookup_typename): Likewise.
(typy_lookup_type): Likewise.
(typy_legacy_template_argument): Likewise.
(typy_template_argument): Likewise.
(gdbpy_lookup_type): Likewise.
* python/py-symbol.c (gdbpy_lookup_symbol): Likewise.
* python/py-block.c (blpy_block_object): Likewise.
(blpy_iter): Likewise.
(blpy_get_start): Likewise.
(blpy_get_end): Likewise.
(blpy_get_function): Likewise.
(blpy_get_superblock): Likewise.
(set_block): Likewise.
(block_to_block_object): Likewise.
(block_object_to_block): Likewise.
(blpy_is_valid): Likewise.
(blpy_get_global_block): New function.
(blpy_get_static_block): New function.
(blpy_is_global): New function.
(blpy_is_static): New function.
* blockframe.c (block_innermost_frame): Likewise.
* valops.c (value_of_variable): Likewise.
* frame.h: Update prototypes.
* python/python-internal.h: Likewise.
* value.h: Likewise.
2011-10-19 Cary Coutant <ccoutant@google.com> 2011-10-19 Cary Coutant <ccoutant@google.com>
* dwarf2read.c (create_debug_types_hash_table): Fix size of * dwarf2read.c (create_debug_types_hash_table): Fix size of

View File

@ -40,6 +40,11 @@
'data-directory'/python/gdb/function are now automatically loaded 'data-directory'/python/gdb/function are now automatically loaded
on GDB start-up. on GDB start-up.
** Blocks now provide four new attributes. global_block and
static_block will return the global and static blocks
respectively. is_static and is_global are boolean attributes
that indicate if the block is one of those two types.
** Symbols now provide the "type" attribute, the type of the symbol. ** Symbols now provide the "type" attribute, the type of the symbol.
** The "gdb.breakpoint" function has been deprecated in favor of ** The "gdb.breakpoint" function has been deprecated in favor of

View File

@ -358,7 +358,7 @@ find_pc_partial_function (CORE_ADDR pc, char **name, CORE_ADDR *address,
if there is no such frame. If BLOCK is NULL, just return NULL. */ if there is no such frame. If BLOCK is NULL, just return NULL. */
struct frame_info * struct frame_info *
block_innermost_frame (struct block *block) block_innermost_frame (const struct block *block)
{ {
struct frame_info *frame; struct frame_info *frame;
CORE_ADDR start; CORE_ADDR start;

View File

@ -1,3 +1,10 @@
2011-10-20 Phil Muldoon <pmuldoon@redhat.com>
PR python/12656
* gdb.texinfo (Blocks In Python): Document is_static, is_global,
global_block, static_block function.
2011-10-19 Tom Tromey <tromey@redhat.com> 2011-10-19 Tom Tromey <tromey@redhat.com>
* gdb.texinfo (Commands In Python): Add missing "@"s. * gdb.texinfo (Commands In Python): Add missing "@"s.

View File

@ -23549,6 +23549,27 @@ attribute is not writable.
The block containing this block. If this parent block does not exist, The block containing this block. If this parent block does not exist,
this attribute holds @code{None}. This attribute is not writable. this attribute holds @code{None}. This attribute is not writable.
@end defvar @end defvar
@defvar Block.global_block
The global block associated with this block. This attribute is not
writable.
@end defvar
@defvar Block.static_block
The static block associated with this block. This attribute is not
writable.
@end defvar
@defvar Block.is_global
@code{True} if the @code{gdb.Block} object is a global block,
@code{False} if not. This attribute is not
writable.
@end defvar
@defvar Block.is_static
@code{True} if the @code{gdb.Block} object is a static block,
@code{False} if not. This attribute is not writable.
@end defvar
@end table @end table
@node Symbols In Python @node Symbols In Python

View File

@ -691,7 +691,7 @@ extern void print_stack_frame (struct frame_info *, int print_level,
extern void print_frame_info (struct frame_info *, int print_level, extern void print_frame_info (struct frame_info *, int print_level,
enum print_what print_what, int args); enum print_what print_what, int args);
extern struct frame_info *block_innermost_frame (struct block *); extern struct frame_info *block_innermost_frame (const struct block *);
extern int deprecated_pc_in_call_dummy (struct gdbarch *gdbarch, CORE_ADDR pc); extern int deprecated_pc_in_call_dummy (struct gdbarch *gdbarch, CORE_ADDR pc);

View File

@ -28,7 +28,7 @@
typedef struct blpy_block_object { typedef struct blpy_block_object {
PyObject_HEAD PyObject_HEAD
/* The GDB block structure that represents a frame's code block. */ /* The GDB block structure that represents a frame's code block. */
struct block *block; const struct block *block;
/* The backing object file. There is no direct relationship in GDB /* The backing object file. There is no direct relationship in GDB
between a block and an object file. When a block is created also between a block and an object file. When a block is created also
store a pointer to the object file for later use. */ store a pointer to the object file for later use. */
@ -85,7 +85,7 @@ static PyObject *
blpy_iter (PyObject *self) blpy_iter (PyObject *self)
{ {
block_syms_iterator_object *block_iter_obj; block_syms_iterator_object *block_iter_obj;
struct block *block = NULL; const struct block *block = NULL;
BLPY_REQUIRE_VALID (self, block); BLPY_REQUIRE_VALID (self, block);
@ -105,7 +105,7 @@ blpy_iter (PyObject *self)
static PyObject * static PyObject *
blpy_get_start (PyObject *self, void *closure) blpy_get_start (PyObject *self, void *closure)
{ {
struct block *block = NULL; const struct block *block = NULL;
BLPY_REQUIRE_VALID (self, block); BLPY_REQUIRE_VALID (self, block);
@ -115,7 +115,7 @@ blpy_get_start (PyObject *self, void *closure)
static PyObject * static PyObject *
blpy_get_end (PyObject *self, void *closure) blpy_get_end (PyObject *self, void *closure)
{ {
struct block *block = NULL; const struct block *block = NULL;
BLPY_REQUIRE_VALID (self, block); BLPY_REQUIRE_VALID (self, block);
@ -126,7 +126,7 @@ static PyObject *
blpy_get_function (PyObject *self, void *closure) blpy_get_function (PyObject *self, void *closure)
{ {
struct symbol *sym; struct symbol *sym;
struct block *block = NULL; const struct block *block;
BLPY_REQUIRE_VALID (self, block); BLPY_REQUIRE_VALID (self, block);
@ -140,8 +140,8 @@ blpy_get_function (PyObject *self, void *closure)
static PyObject * static PyObject *
blpy_get_superblock (PyObject *self, void *closure) blpy_get_superblock (PyObject *self, void *closure)
{ {
struct block *block = NULL; const struct block *block;
struct block *super_block = NULL; const struct block *super_block;
block_object *self_obj = (block_object *) self; block_object *self_obj = (block_object *) self;
BLPY_REQUIRE_VALID (self, block); BLPY_REQUIRE_VALID (self, block);
@ -153,6 +153,77 @@ blpy_get_superblock (PyObject *self, void *closure)
Py_RETURN_NONE; Py_RETURN_NONE;
} }
/* Return the global block associated to this block. */
static PyObject *
blpy_get_global_block (PyObject *self, void *closure)
{
const struct block *block;
const struct block *global_block;
block_object *self_obj = (block_object *) self;
BLPY_REQUIRE_VALID (self, block);
global_block = block_global_block (block);
return block_to_block_object (global_block,
self_obj->objfile);
}
/* Return the static block associated to this block. Return None
if we cannot get the static block (this is the global block). */
static PyObject *
blpy_get_static_block (PyObject *self, void *closure)
{
const struct block *block;
const struct block *static_block;
block_object *self_obj = (block_object *) self;
BLPY_REQUIRE_VALID (self, block);
if (BLOCK_SUPERBLOCK (block) == NULL)
Py_RETURN_NONE;
static_block = block_static_block (block);
return block_to_block_object (static_block, self_obj->objfile);
}
/* Implementation of gdb.Block.is_global (self) -> Boolean.
Returns True if this block object is a global block. */
static PyObject *
blpy_is_global (PyObject *self, void *closure)
{
const struct block *block;
BLPY_REQUIRE_VALID (self, block);
if (BLOCK_SUPERBLOCK (block))
Py_RETURN_FALSE;
Py_RETURN_TRUE;
}
/* Implementation of gdb.Block.is_static (self) -> Boolean.
Returns True if this block object is a static block. */
static PyObject *
blpy_is_static (PyObject *self, void *closure)
{
const struct block *block;
BLPY_REQUIRE_VALID (self, block);
if (BLOCK_SUPERBLOCK (block) != NULL
&& BLOCK_SUPERBLOCK (BLOCK_SUPERBLOCK (block)) == NULL)
Py_RETURN_TRUE;
Py_RETURN_FALSE;
}
static void static void
blpy_dealloc (PyObject *obj) blpy_dealloc (PyObject *obj)
{ {
@ -176,7 +247,7 @@ blpy_dealloc (PyObject *obj)
with the life-cycle of the object file associated with this with the life-cycle of the object file associated with this
block, if needed. */ block, if needed. */
static void static void
set_block (block_object *obj, struct block *block, set_block (block_object *obj, const struct block *block,
struct objfile *objfile) struct objfile *objfile)
{ {
obj->block = block; obj->block = block;
@ -196,7 +267,7 @@ set_block (block_object *obj, struct block *block,
/* Create a new block object (gdb.Block) that encapsulates the struct /* Create a new block object (gdb.Block) that encapsulates the struct
block object from GDB. */ block object from GDB. */
PyObject * PyObject *
block_to_block_object (struct block *block, struct objfile *objfile) block_to_block_object (const struct block *block, struct objfile *objfile)
{ {
block_object *block_obj; block_object *block_obj;
@ -208,7 +279,7 @@ block_to_block_object (struct block *block, struct objfile *objfile)
} }
/* Return struct block reference that is wrapped by this object. */ /* Return struct block reference that is wrapped by this object. */
struct block * const struct block *
block_object_to_block (PyObject *obj) block_object_to_block (PyObject *obj)
{ {
if (! PyObject_TypeCheck (obj, &block_object_type)) if (! PyObject_TypeCheck (obj, &block_object_type))
@ -269,7 +340,7 @@ blpy_block_syms_dealloc (PyObject *obj)
static PyObject * static PyObject *
blpy_is_valid (PyObject *self, PyObject *args) blpy_is_valid (PyObject *self, PyObject *args)
{ {
struct block *block; const struct block *block;
block = block_object_to_block (self); block = block_object_to_block (self);
if (block == NULL) if (block == NULL)
@ -386,6 +457,14 @@ static PyGetSetDef block_object_getset[] = {
"Symbol that names the block, or None.", NULL }, "Symbol that names the block, or None.", NULL },
{ "superblock", blpy_get_superblock, NULL, { "superblock", blpy_get_superblock, NULL,
"Block containing the block, or None.", NULL }, "Block containing the block, or None.", NULL },
{ "global_block", blpy_get_global_block, NULL,
"Block containing the global block.", NULL },
{ "static_block", blpy_get_static_block, NULL,
"Block containing the static block.", NULL },
{ "is_static", blpy_is_static, NULL,
"Whether this block is a static block.", NULL },
{ "is_global", blpy_is_global, NULL,
"Whether this block is a global block.", NULL },
{ NULL } /* Sentinel */ { NULL } /* Sentinel */
}; };

View File

@ -411,7 +411,7 @@ frapy_read_var (PyObject *self, PyObject *args)
else if (gdbpy_is_string (sym_obj)) else if (gdbpy_is_string (sym_obj))
{ {
char *var_name; char *var_name;
struct block *block = NULL; const struct block *block = NULL;
struct cleanup *cleanup; struct cleanup *cleanup;
volatile struct gdb_exception except; volatile struct gdb_exception except;

View File

@ -276,7 +276,7 @@ gdbpy_lookup_symbol (PyObject *self, PyObject *args, PyObject *kw)
static char *keywords[] = { "name", "block", "domain", NULL }; static char *keywords[] = { "name", "block", "domain", NULL };
struct symbol *symbol; struct symbol *symbol;
PyObject *block_obj = NULL, *ret_tuple, *sym_obj, *bool_obj; PyObject *block_obj = NULL, *ret_tuple, *sym_obj, *bool_obj;
struct block *block = NULL; const struct block *block = NULL;
if (! PyArg_ParseTupleAndKeywords (args, kw, "s|O!i", keywords, &name, if (! PyArg_ParseTupleAndKeywords (args, kw, "s|O!i", keywords, &name,
&block_object_type, &block_obj, &domain)) &block_object_type, &block_obj, &domain))

View File

@ -576,7 +576,7 @@ typy_get_sizeof (PyObject *self, void *closure)
} }
static struct type * static struct type *
typy_lookup_typename (const char *type_name, struct block *block) typy_lookup_typename (const char *type_name, const struct block *block)
{ {
struct type *type = NULL; struct type *type = NULL;
volatile struct gdb_exception except; volatile struct gdb_exception except;
@ -606,7 +606,7 @@ typy_lookup_typename (const char *type_name, struct block *block)
static struct type * static struct type *
typy_lookup_type (struct demangle_component *demangled, typy_lookup_type (struct demangle_component *demangled,
struct block *block) const struct block *block)
{ {
struct type *type; struct type *type;
char *type_name; char *type_name;
@ -651,7 +651,7 @@ typy_lookup_type (struct demangle_component *demangled,
versions of GCC, that do not emit DW_TAG_template_*. */ versions of GCC, that do not emit DW_TAG_template_*. */
static PyObject * static PyObject *
typy_legacy_template_argument (struct type *type, struct block *block, typy_legacy_template_argument (struct type *type, const struct block *block,
int argno) int argno)
{ {
int i; int i;
@ -716,7 +716,7 @@ typy_template_argument (PyObject *self, PyObject *args)
{ {
int argno; int argno;
struct type *type = ((type_object *) self)->type; struct type *type = ((type_object *) self)->type;
struct block *block = NULL; const struct block *block = NULL;
PyObject *block_obj = NULL; PyObject *block_obj = NULL;
struct symbol *sym; struct symbol *sym;
struct value *val = NULL; struct value *val = NULL;
@ -1328,7 +1328,7 @@ gdbpy_lookup_type (PyObject *self, PyObject *args, PyObject *kw)
const char *type_name = NULL; const char *type_name = NULL;
struct type *type = NULL; struct type *type = NULL;
PyObject *block_obj = NULL; PyObject *block_obj = NULL;
struct block *block = NULL; const struct block *block = NULL;
if (! PyArg_ParseTupleAndKeywords (args, kw, "s|O", keywords, if (! PyArg_ParseTupleAndKeywords (args, kw, "s|O", keywords,
&type_name, &block_obj)) &type_name, &block_obj))

View File

@ -164,7 +164,8 @@ char *gdbpy_parse_command_name (const char *name,
PyObject *symtab_and_line_to_sal_object (struct symtab_and_line sal); PyObject *symtab_and_line_to_sal_object (struct symtab_and_line sal);
PyObject *symtab_to_symtab_object (struct symtab *symtab); PyObject *symtab_to_symtab_object (struct symtab *symtab);
PyObject *symbol_to_symbol_object (struct symbol *sym); PyObject *symbol_to_symbol_object (struct symbol *sym);
PyObject *block_to_block_object (struct block *block, struct objfile *objfile); PyObject *block_to_block_object (const struct block *block,
struct objfile *objfile);
PyObject *value_to_value_object (struct value *v); PyObject *value_to_value_object (struct value *v);
PyObject *type_to_type_object (struct type *); PyObject *type_to_type_object (struct type *);
PyObject *frame_info_to_frame_object (struct frame_info *frame); PyObject *frame_info_to_frame_object (struct frame_info *frame);
@ -180,7 +181,7 @@ thread_object *find_thread_object (ptid_t ptid);
PyObject *find_inferior_object (int pid); PyObject *find_inferior_object (int pid);
PyObject *inferior_to_inferior_object (struct inferior *inferior); PyObject *inferior_to_inferior_object (struct inferior *inferior);
struct block *block_object_to_block (PyObject *obj); const struct block *block_object_to_block (PyObject *obj);
struct symbol *symbol_object_to_symbol (PyObject *obj); struct symbol *symbol_object_to_symbol (PyObject *obj);
struct value *value_object_to_value (PyObject *self); struct value *value_object_to_value (PyObject *self);
struct value *convert_value_from_python (PyObject *obj); struct value *convert_value_from_python (PyObject *obj);

View File

@ -1,3 +1,10 @@
2011-10-20 Phil Muldoon <pmuldoon@redhat.com>
PR python/12656
* gdb.python/py-block.exp: Add is_global, is_static, static_block,
global_block tests.
2011-10-18 Tom Tromey <tromey@redhat.com> 2011-10-18 Tom Tromey <tromey@redhat.com>
* gdb.base/jit-so.exp (one_jit_test): Remove spurious backslash. * gdb.base/jit-so.exp (one_jit_test): Remove spurious backslash.

View File

@ -48,6 +48,16 @@ gdb_test "python print block.function" "None" "First anonymous block"
gdb_test "python print block.start" "${decimal}" "Check start not None" gdb_test "python print block.start" "${decimal}" "Check start not None"
gdb_test "python print block.end" "${decimal}" "Check end not None" gdb_test "python print block.end" "${decimal}" "Check end not None"
# Test global/static blocks
gdb_py_test_silent_cmd "python frame = gdb.selected_frame()" "Get Frame" 0
gdb_py_test_silent_cmd "python block = frame.block()" "Get block" 0
gdb_test "python print block.is_global" "False" "Not a global block"
gdb_test "python print block.is_static" "False" "Not a static block"
gdb_py_test_silent_cmd "python gblock = block.global_block" "Get block" 1
gdb_py_test_silent_cmd "python sblock = block.static_block" "Get block" 1
gdb_test "python print gblock.is_global" "True" "Is the global block"
gdb_test "python print sblock.is_static" "True" "Is the static block"
# Move up superblock(s) until we reach function block_func. # Move up superblock(s) until we reach function block_func.
gdb_test_no_output "python block = block.superblock" "Get superblock" gdb_test_no_output "python block = block.superblock" "Get superblock"
gdb_test "python print block.function" "None" "Second anonymous block" gdb_test "python print block.function" "None" "Second anonymous block"

View File

@ -1491,7 +1491,7 @@ value_repeat (struct value *arg1, int count)
} }
struct value * struct value *
value_of_variable (struct symbol *var, struct block *b) value_of_variable (struct symbol *var, const struct block *b)
{ {
struct frame_info *frame; struct frame_info *frame;

View File

@ -508,7 +508,8 @@ extern struct value *value_from_register (struct type *type, int regnum,
extern CORE_ADDR address_from_register (struct type *type, int regnum, extern CORE_ADDR address_from_register (struct type *type, int regnum,
struct frame_info *frame); struct frame_info *frame);
extern struct value *value_of_variable (struct symbol *var, struct block *b); extern struct value *value_of_variable (struct symbol *var,
const struct block *b);
extern struct value *address_of_variable (struct symbol *var, struct block *b); extern struct value *address_of_variable (struct symbol *var, struct block *b);