[PATCH] Add block['var'] accessor

Tom Tromey tom@tromey.com
Fri Aug 2 13:36:00 GMT 2019


>>>>> "Christian" == Christian Biesinger via gdb-patches <gdb-patches@sourceware.org> writes:

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

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

Thank you for the patch.

Christian> +  struct symbol *sym = block_lookup_symbol (
Christian> +    block, name.get(), symbol_name_match_type::FULL, VAR_DOMAIN);

What about looking up things in other domains?  I wonder if it's
possible to, say, have a local type that can be found by iteration over
the block but not by dictionary access.  If so, that seems confusing.

Christian> +  if (!sym) {
Christian> +    PyErr_SetObject (PyExc_KeyError, key);
Christian> +    return nullptr;
Christian> +  }

The formatting here is incorrect.  The call to block_lookup_symbol looks
weird (gdb doesn't generally use trailing parens like that), and the
brace after the "if" is misplaced.

Tom



More information about the Gdb-patches mailing list