> Hi all,
> Looks like there is a bug in docs:
> *"Function: gdb.block_for_pc (pc)*
> *Return the innermost gdb.Block containing the given pc value. If the
> cannot be found for the pc value specified, the function will return
> https://sourceware.org/gdb/current/onlinedocs/gdb/Blocks-In-Python.html#Blocks-In-Python >
> Instead of returning None it throws runtime exception:
>>> RuntimeError: Cannot locate object file for block.
1) We can't find a compilation unit for the given pc -> we throw an
2) We can find a compilation unit for the given pc, but can't find a
corresponding block -> we return None
It's easy to trigger 1), you just call block_for_pc with a bad random
address. I don't know how to trigger 2). You would have to pass a pc
covered by a compilation unit, but not covered by a block, not sure when
Now we have two choices, either we adapt the documentation to match the
reality, which easy. Or we change the code to match the documentation,
which is harder because we risk breaking user scripts.
I don't really like the current situation, because the exception thrown,
RuntimeError, is very generic. So if one uses "except RuntimeError" to
catch the case where block_for_pc fails, they risk catching other
things, like RecursionError, which derives from RuntimeError. Returning
None, as the documentation suggests, would make more sense to me...