This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [RFC - Python Scripting] New method gdb.Symtab.blocks_iterator - docs included


>>>>> "Siva" == Siva Chandra <sivachandra@google.com> writes:

Siva> I have picked Symtab.blocks.  I personally don't like making Symtab
Siva> iterable as blocks are just one of them.

Doug's note made me start wondering why iterating over all the blocks
made sense here -- and now I tend to think it doesn't.

I think it would be a bit more future-proof to just let the user access
the symtab's global and static blocks, then rely on iteration over
symbols within a block.  This would mean also adding a way to fetch a
block's subblocks.

The reason I see this as more future-proof is that I think the block
structure, including global and static blocks, is a feature of the
underlying problem.  So, it is much less likely to change if we need to
refactor symtabs or blocks.  (And, in fact, my lazy block-reading code
would have mild problems with your iterator, but no troubles at all in
this approach.)

Sorry about this change of mind...

Siva> + Â block_object = block_to_block_object (block, symtab->objfile);
Siva> + Â if (! block_object)
Siva> + Â Â {
Siva> + Â Â Â PyErr_SetString (PyExc_RuntimeError,
Siva> + Â Â Â Â Â Â Â Â Â Â Â Â_("Unable to get the next gdb.Block object."));

Tom> If block_to_block_object fails, then the error will already be set.
Tom> I think it is generally better to propagate the original exception in
Tom> cases like this. ÂOtherwise, the new exception may obscure some more
Tom> fundamental error.

Siva> block_to_block_object just returns NULL on failure.  Am I missing
Siva> something?

If it returns NULL then it has already set the Python exception.  This
is a Python coding convention that we follow in many places.  E.g., in
block_to_block_object, the NULL return can only happen if PyObject_New
fails; but if that fails and returns NULL, then it is guaranteed to have
set the exception; and therefore the same is true for
block_to_block_object.

Siva> + Â (iter->iter_index)++;

Tom> Also I'm curious if an error should invalidate the iterator in some way.

Siva> Since the iterator exists only in Python environment, my opinion is
Siva> that if the iterator gets invalidated, the execution should never
Siva> reach this place.   Do you see something else?

Can't the caller ignore the error and call iter.next again?
But I think it probably doesn't matter.
The best thing would be to see if there is some Python standard here;
if so, follow it; if not, do whatever is convenient.

Tom


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]