Add block['var'] accessor

Currently we support iteration on blocks; this patch extends that to make
subscript access work as well.

gdb/ChangeLog:

2019-08-05  Christian Biesinger  <cbiesinger@google.com>

	* NEWS: Mention dictionary access on blocks.
	* python/py-block.c (blpy_getitem): New function.
	(block_object_as_mapping): New struct.
	(block_object_type): Use new struct for tp_as_mapping field.

gdb/doc/ChangeLog:

2019-08-05  Christian Biesinger  <cbiesinger@google.com>

	* python.texi (Blocks In Python): Document dictionary access on blocks.

gdb/testsuite/ChangeLog:

2019-08-05  Christian Biesinger  <cbiesinger@google.com>

	* gdb.python/py-block.exp: Test dictionary access on blocks.
This commit is contained in:
Christian Biesinger
2019-08-01 17:22:28 -05:00
parent 4ee94178af
commit 0b27c27d0d
7 changed files with 73 additions and 2 deletions

View File

@@ -4722,7 +4722,12 @@ A @code{gdb.Block} is iterable. The iterator returns the symbols
should not assume that a specific block object will always contain a
given symbol, since changes in @value{GDBN} features and
infrastructure may cause symbols move across blocks in a symbol
table.
table. You can also use Python's @dfn{dictionary syntax} to access
variables in this block, e.g.:
@smallexample
symbol = some_block['variable'] # symbol is of type gdb.Symbol
@end smallexample
The following block-related functions are available in the @code{gdb}
module: